@decaf-ts/db-decorators
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -11,4 +11,12 @@ import { DBModel } from "./DBModel"; | ||
export declare function hash(): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; | ||
export declare function composedFromCreateUpdate(args: string[], separator?: string, type?: "keys" | "values", prefix?: string, suffix?: string): <T extends DBModel, V extends IRepository<T>>(this: V, key: string, model: T) => void; | ||
export declare function composedFromKeys(args: string[], hash?: boolean, prefix?: string, suffix?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; | ||
export declare function composed(args: string[], hash?: boolean, prefix?: string, suffix?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; | ||
export type ComposedFromMetadata = { | ||
args: string[]; | ||
separator: string; | ||
hashResult: boolean; | ||
type: "keys" | "values"; | ||
prefix?: string; | ||
suffix?: string; | ||
}; | ||
export declare function composedFromCreateUpdate<T extends DBModel, V extends IRepository<T>>(this: V, data: ComposedFromMetadata, key: string, model: T): void; | ||
export declare function composedFromKeys(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; | ||
export declare function composed(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; |
@@ -1,1 +0,1 @@ | ||
import{DBKeys,DefaultSeparator}from"./constants";import{apply,metadata}from"@decaf-ts/reflection";import{Hashing,sf}from"@decaf-ts/decorator-validation";import{onCreateUpdate}from"../operations/decorators";import{InternalError}from"../repository/errors";function getDBKey(e){return DBKeys.REFLECT+e}function hashOnCreateUpdate(e,r,o,t){var a;o[r]&&(a=Hashing.hash(o[r]),t&&o[r]===a||(o[r]=a))}function hash(){return apply(onCreateUpdate(hashOnCreateUpdate),metadata(getDBKey(DBKeys.HASH),{}))}function composedFromCreateUpdate(t,a=DefaultSeparator,n="values",s="",p=""){return function(e,r){try{var o=t.map(e=>{if(!(e in r))throw new InternalError(sf("Property {0} not found to compose from",e));if("keys"===n)return e;if(void 0===r[e])throw new InternalError(sf("Property {0} does not contain a value to compose from",e));return r[e].toString()});s&&o.unshift(s),p&&o.push(p),r[e]=o.join(a)}catch(e){throw new InternalError("Failed to compose value: "+e)}}}function composedFrom(e,r=!1,o=DefaultSeparator,t="values",a="",n=""){var s={args:e,hashResult:r,separator:o,type:t,prefix:a,suffix:n},e=[onCreateUpdate(composedFromCreateUpdate(e,o,t,a,n)),metadata(getDBKey(DBKeys.COMPOSED),s)];return r&&e.push(hash()),apply(...e)}function composedFromKeys(e,r=!1,o="",t=""){return composedFrom(e,r,DefaultSeparator,"keys",o,t)}function composed(e,r=!1,o="",t=""){return composedFrom(e,r,DefaultSeparator,"values",o,t)}export{getDBKey,hashOnCreateUpdate,hash,composedFromCreateUpdate,composedFromKeys,composed}; | ||
import{DBKeys,DefaultSeparator}from"./constants";import{apply,metadata}from"@decaf-ts/reflection";import{Hashing,sf}from"@decaf-ts/decorator-validation";import{onCreateUpdate}from"../operations/decorators";import{InternalError}from"../repository/errors";function getDBKey(e){return DBKeys.REFLECT+e}function hashOnCreateUpdate(e,r,o,t){var a;o[r]&&(a=Hashing.hash(o[r]),t&&o[r]===a||(o[r]=a))}function hash(){return apply(onCreateUpdate(hashOnCreateUpdate),metadata(getDBKey(DBKeys.HASH),{}))}function composedFromCreateUpdate(e,r,o){try{const{args:a,type:s,prefix:n,suffix:p,separator:m}=e;var t=a.map(e=>{if(!(e in o))throw new InternalError(sf("Property {0} not found to compose from",e));if("keys"===s)return e;if(void 0===o[e])throw new InternalError(sf("Property {0} does not contain a value to compose from",e));return o[e].toString()});n&&t.unshift(n),p&&t.push(p),o[r]=t.join(m)}catch(e){throw new InternalError("Failed to compose value: "+e)}}function composedFrom(e,r=!1,o=DefaultSeparator,t="values",a="",s=""){e={args:e,hashResult:r,separator:o,type:t,prefix:a,suffix:s},o=[onCreateUpdate(composedFromCreateUpdate,e),metadata(getDBKey(DBKeys.COMPOSED),e)];return r&&o.push(hash()),apply(...o)}function composedFromKeys(e,r=DefaultSeparator,o=!1,t="",a=""){return composedFrom(e,o,r,"keys",t,a)}function composed(e,r=DefaultSeparator,o=!1,t="",a=""){return composedFrom(e,o,r,"values",t,a)}export{getDBKey,hashOnCreateUpdate,hash,composedFromCreateUpdate,composedFromKeys,composed}; |
@@ -1,1 +0,1 @@ | ||
import{sf}from"@decaf-ts/decorator-validation";import{enforceDBDecorators}from"./utils";import{OperationKeys}from"../operations/constants";import{ConflictError,NotFoundError,ValidationError}from"./errors";import{BaseRepository}from"./BaseRepository";import{findModelId}from"../identity";class Repository extends BaseRepository{constructor(r){super(r)}async create(r){throw new Error("Child classes must implement this.")}async createPrefix(t,...e){t=new this.class(t),await enforceDBDecorators(this,t,OperationKeys.CREATE,OperationKeys.ON);var r=t.hasErrors();if(r)throw new ValidationError(r.toString());let o;try{if(!(o=findModelId(t,!0)))return[t,...e];o&&await this.read(o.toString())}catch(r){if(r instanceof NotFoundError)return[t,...e];throw r}throw new ConflictError(sf("Model with id {0} already exists",o))}async delete(r){throw new Error("Child classes must implement this.")}async deletePrefix(r,...t){var e=new this.class;return await enforceDBDecorators(this,e,OperationKeys.DELETE,OperationKeys.ON),await this.read(r),[r,...t]}async read(r){throw new Error("Child classes must implement this.")}async update(r){throw new Error("Child classes must implement this.")}async updatePrefix(r,...t){r=new this.class(r);var e=findModelId(r),e=await this.read(e),e=(await enforceDBDecorators(this,r,OperationKeys.UPDATE,OperationKeys.ON,e),r.hasErrors(e));if(e)throw new ValidationError(e.toString());return[r,...t]}}export{Repository}; | ||
import{enforceDBDecorators}from"./utils";import{OperationKeys}from"../operations/constants";import{ConflictError,NotFoundError,ValidationError}from"./errors";import{BaseRepository}from"./BaseRepository";import{findModelId}from"../identity";import{sf}from"@decaf-ts/decorator-validation";class Repository extends BaseRepository{constructor(r){super(r)}async create(r){throw new Error("Child classes must implement this.")}async createPrefix(t,...e){t=new this.class(t),await enforceDBDecorators(this,t,OperationKeys.CREATE,OperationKeys.ON);var r=t.hasErrors();if(r)throw new ValidationError(r.toString());let o;try{if(!(o=findModelId(t,!0)))return[t,...e];o&&await this.read(o.toString())}catch(r){if(r instanceof NotFoundError)return[t,...e];throw r}throw new ConflictError(sf("Model with id {0} already exists",o))}async delete(r){throw new Error("Child classes must implement this.")}async deletePrefix(r,...t){var e=new this.class;return await enforceDBDecorators(this,e,OperationKeys.DELETE,OperationKeys.ON),[r,...t]}async read(r){throw new Error("Child classes must implement this.")}async update(r){throw new Error("Child classes must implement this.")}async updatePrefix(r,...t){r=new this.class(r);var e=findModelId(r),e=await this.read(e),e=(await enforceDBDecorators(this,r,OperationKeys.UPDATE,OperationKeys.ON,e),r.hasErrors(e));if(e)throw new ValidationError(e.toString());return[r,...t]}}export{Repository}; |
@@ -11,4 +11,12 @@ import { DBModel } from "./DBModel"; | ||
export declare function hash(): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; | ||
export declare function composedFromCreateUpdate(args: string[], separator?: string, type?: "keys" | "values", prefix?: string, suffix?: string): <T extends DBModel, V extends IRepository<T>>(this: V, key: string, model: T) => void; | ||
export declare function composedFromKeys(args: string[], hash?: boolean, prefix?: string, suffix?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; | ||
export declare function composed(args: string[], hash?: boolean, prefix?: string, suffix?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; | ||
export type ComposedFromMetadata = { | ||
args: string[]; | ||
separator: string; | ||
hashResult: boolean; | ||
type: "keys" | "values"; | ||
prefix?: string; | ||
suffix?: string; | ||
}; | ||
export declare function composedFromCreateUpdate<T extends DBModel, V extends IRepository<T>>(this: V, data: ComposedFromMetadata, key: string, model: T): void; | ||
export declare function composedFromKeys(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; | ||
export declare function composed(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void; |
{ | ||
"name": "@decaf-ts/db-decorators", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Agnostic database decorators and repository", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1752
309541