@decaf-ts/db-decorators 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- import { OrderDirection } from "../validation/constants";
2
1
  import { DBModel } from "./DBModel";
3
2
  import { IRepository } from "../interfaces/IRepository";
4
3
  /**
@@ -7,17 +6,6 @@ import { IRepository } from "../interfaces/IRepository";
7
6
  * @memberOf db-decorators.model
8
7
  */
9
8
  export declare function getDBKey(str: string): string;
10
- /**
11
- * @summary Index Decorator
12
- * @description properties decorated will the index in the
13
- * DB for performance in queries
14
- *
15
- * @param {OrderDirection[]} [directions]
16
- * @param {string[]} [compositions]
17
- *
18
- * @function index
19
- */
20
- export declare function index(compositions?: string[], directions?: OrderDirection[]): import("@decaf-ts/reflection").CustomDecorator<V>;
21
9
  export declare function hashOnCreateUpdate<T extends DBModel, V extends IRepository<T>, Y = any>(this: V, data: Y, key: string, model: T, oldModel?: T): void;
22
10
  export declare function hash(): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void;
23
11
  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;
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&("get"in i?r.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./BaseRepository.cjs"),exports),__exportStar(require("./constants.cjs"),exports),__exportStar(require("./DataCache.cjs"),exports),__exportStar(require("./decorators.cjs"),exports),__exportStar(require("./errors.cjs"),exports),__exportStar(require("./Repository.cjs"),exports),__exportStar(require("./types.cjs"),exports),__exportStar(require("./utils.cjs"),exports),__exportStar(require("./wrappers.cjs"),exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&("get"in i?r.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./BaseRepository.cjs"),exports),__exportStar(require("./DataCache.cjs"),exports),__exportStar(require("./decorators.cjs"),exports),__exportStar(require("./errors.cjs"),exports),__exportStar(require("./Repository.cjs"),exports),__exportStar(require("./utils.cjs"),exports),__exportStar(require("./wrappers.cjs"),exports);
@@ -1,9 +1,7 @@
1
1
  export * from "./BaseRepository";
2
- export * from "./constants";
3
2
  export * from "./DataCache";
4
3
  export * from "./decorators";
5
4
  export * from "./errors";
6
5
  export * from "./Repository";
7
- export * from "./types";
8
6
  export * from "./utils";
9
7
  export * from "./wrappers";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OrderDirection=exports.UpdateValidationKeys=exports.DEFAULT_ERROR_MESSAGES=void 0;const constants_1=require("../model/constants.cjs");var OrderDirection;exports.DEFAULT_ERROR_MESSAGES={ID:{INVALID:"This Id is invalid",REQUIRED:"The Id is mandatory"},READONLY:{INVALID:"This cannot be updated"},TIMESTAMP:{REQUIRED:"Timestamp is Mandatory",DATE:"The Timestamp must the a valid date",INVALID:"This value must always increase"}},exports.UpdateValidationKeys={REFLECT:"db.update.validation.",TIMESTAMP:constants_1.DBKeys.TIMESTAMP,READONLY:constants_1.DBKeys.READONLY},function(e){e.ASC="asc",e.DSC="desc"}(OrderDirection||(exports.OrderDirection=OrderDirection={}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UpdateValidationKeys=exports.DEFAULT_ERROR_MESSAGES=void 0;const constants_1=require("../model/constants.cjs");exports.DEFAULT_ERROR_MESSAGES={ID:{INVALID:"This Id is invalid",REQUIRED:"The Id is mandatory"},READONLY:{INVALID:"This cannot be updated"},TIMESTAMP:{REQUIRED:"Timestamp is Mandatory",DATE:"The Timestamp must the a valid date",INVALID:"This value must always increase"}},exports.UpdateValidationKeys={REFLECT:"db.update.validation.",TIMESTAMP:constants_1.DBKeys.TIMESTAMP,READONLY:constants_1.DBKeys.READONLY};
@@ -28,22 +28,3 @@ export declare const UpdateValidationKeys: {
28
28
  TIMESTAMP: string;
29
29
  READONLY: string;
30
30
  };
31
- /**
32
- * @summary defines order directions when sorting
33
- *
34
- * @constant OrderDirection
35
- *
36
- * @category Query
37
- */
38
- export declare enum OrderDirection {
39
- /**
40
- * @summary Defines the sort order as ascending
41
- * @prop ASC
42
- */
43
- ASC = "asc",
44
- /**
45
- * @summary Defines the sort order as descending
46
- * @property {string} DSC
47
- */
48
- DSC = "desc"
49
- }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.serialize=exports.serializeAfterAll=exports.serializeOnCreateUpdate=exports.unique=exports.uniqueOnCreateUpdate=exports.timestamp=exports.timestampHandler=exports.readonly=exports.getDBUpdateKey=void 0;const decorator_validation_1=require("@decaf-ts/decorator-validation"),constants_1=require("../model/constants.cjs"),constants_2=require("./constants.cjs"),constants_3=require("../operations/constants.cjs"),decorators_1=require("../operations/decorators.cjs"),errors_1=require("../repository/errors.cjs"),reflection_1=require("@decaf-ts/reflection"),decorators_2=require("../model/decorators.cjs");function getDBUpdateKey(e){return constants_2.UpdateValidationKeys.REFLECT+e}function readonly(e=constants_2.DEFAULT_ERROR_MESSAGES.READONLY.INVALID){return(0,reflection_1.metadata)(getDBUpdateKey(constants_1.DBKeys.READONLY),{message:e})}function timestampHandler(e,t,r){r[t]=new Date}function timestamp(e=constants_3.DBOperations.CREATE_UPDATE,t=constants_1.DEFAULT_TIMESTAMP_FORMAT){t=[(0,decorator_validation_1.date)(t,constants_2.DEFAULT_ERROR_MESSAGES.TIMESTAMP.DATE),(0,decorator_validation_1.required)(constants_2.DEFAULT_ERROR_MESSAGES.TIMESTAMP.REQUIRED),(0,decorators_1.on)(e,timestampHandler)];return-1!==e.indexOf(constants_3.OperationKeys.UPDATE)&&t.push((0,reflection_1.metadata)(getDBUpdateKey(constants_1.DBKeys.TIMESTAMP),{message:constants_2.DEFAULT_ERROR_MESSAGES.TIMESTAMP.INVALID})),(0,reflection_1.apply)(...t)}async function uniqueOnCreateUpdate(e,t,r){if(r[t]){try{await this.read(r[t])}catch(e){if(e instanceof errors_1.NotFoundError)return}throw new errors_1.ConflictError(`model already exists with ${t} equal to `+JSON.stringify(r[t],void 0,2))}}function unique(){return(0,reflection_1.apply)((0,decorators_1.onCreateUpdate)(uniqueOnCreateUpdate),(0,reflection_1.metadata)((0,decorators_2.getDBKey)(constants_1.DBKeys.UNIQUE),{}))}async function serializeOnCreateUpdate(e,t,r,a){if(r[t])try{r[t]=JSON.stringify(r[t])}catch(e){throw new errors_1.SerializationError((0,decorator_validation_1.sf)("Failed to serialize {0} property on {0} model",t,r.constructor.name))}}async function serializeAfterAll(e,t,r){if(r[t]&&"string"==typeof r[t])try{r[t]=JSON.parse(r[t])}catch(e){throw new errors_1.SerializationError((0,decorator_validation_1.sf)("Failed to deserialize {0} property on {0} model",t,r.constructor.name))}}function serialize(){return(0,reflection_1.apply)((0,decorators_1.onCreateUpdate)(serializeOnCreateUpdate),(0,decorators_1.after)(constants_3.DBOperations.ALL,serializeAfterAll),(0,decorator_validation_1.type)([String.name,Object.name]),(0,reflection_1.metadata)((0,decorators_2.getDBKey)(constants_1.DBKeys.SERIALIZE),{}))}exports.getDBUpdateKey=getDBUpdateKey,exports.readonly=readonly,exports.timestampHandler=timestampHandler,exports.timestamp=timestamp,exports.uniqueOnCreateUpdate=uniqueOnCreateUpdate,exports.unique=unique,exports.serializeOnCreateUpdate=serializeOnCreateUpdate,exports.serializeAfterAll=serializeAfterAll,exports.serialize=serialize;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.serialize=exports.serializeAfterAll=exports.serializeOnCreateUpdate=exports.timestamp=exports.timestampHandler=exports.readonly=exports.getDBUpdateKey=void 0;const decorator_validation_1=require("@decaf-ts/decorator-validation"),constants_1=require("../model/constants.cjs"),constants_2=require("./constants.cjs"),constants_3=require("../operations/constants.cjs"),decorators_1=require("../operations/decorators.cjs"),errors_1=require("../repository/errors.cjs"),reflection_1=require("@decaf-ts/reflection"),decorators_2=require("../model/decorators.cjs");function getDBUpdateKey(e){return constants_2.UpdateValidationKeys.REFLECT+e}function readonly(e=constants_2.DEFAULT_ERROR_MESSAGES.READONLY.INVALID){return(0,reflection_1.metadata)(getDBUpdateKey(constants_1.DBKeys.READONLY),{message:e})}function timestampHandler(e,t,r){r[t]=new Date}function timestamp(e=constants_3.DBOperations.CREATE_UPDATE,t=constants_1.DEFAULT_TIMESTAMP_FORMAT){t=[(0,decorator_validation_1.date)(t,constants_2.DEFAULT_ERROR_MESSAGES.TIMESTAMP.DATE),(0,decorator_validation_1.required)(constants_2.DEFAULT_ERROR_MESSAGES.TIMESTAMP.REQUIRED),(0,decorators_1.on)(e,timestampHandler)];return-1!==e.indexOf(constants_3.OperationKeys.UPDATE)&&t.push((0,reflection_1.metadata)(getDBUpdateKey(constants_1.DBKeys.TIMESTAMP),{message:constants_2.DEFAULT_ERROR_MESSAGES.TIMESTAMP.INVALID})),(0,reflection_1.apply)(...t)}async function serializeOnCreateUpdate(e,t,r,a){if(r[t])try{r[t]=JSON.stringify(r[t])}catch(e){throw new errors_1.SerializationError((0,decorator_validation_1.sf)("Failed to serialize {0} property on {0} model",t,r.constructor.name))}}async function serializeAfterAll(e,t,r){if(r[t]&&"string"==typeof r[t])try{r[t]=JSON.parse(r[t])}catch(e){throw new errors_1.SerializationError((0,decorator_validation_1.sf)("Failed to deserialize {0} property on {0} model",t,r.constructor.name))}}function serialize(){return(0,reflection_1.apply)((0,decorators_1.onCreateUpdate)(serializeOnCreateUpdate),(0,decorators_1.after)(constants_3.DBOperations.ALL,serializeAfterAll),(0,decorator_validation_1.type)([String.name,Object.name]),(0,reflection_1.metadata)((0,decorators_2.getDBKey)(constants_1.DBKeys.SERIALIZE),{}))}exports.getDBUpdateKey=getDBUpdateKey,exports.readonly=readonly,exports.timestampHandler=timestampHandler,exports.timestamp=timestamp,exports.serializeOnCreateUpdate=serializeOnCreateUpdate,exports.serializeAfterAll=serializeAfterAll,exports.serialize=serialize;
@@ -46,17 +46,6 @@ export declare function timestampHandler<T extends DBModel, V extends IRepositor
46
46
  * @category Decorators
47
47
  */
48
48
  export declare function timestamp(operation?: OperationKeys[], format?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void;
49
- export declare function uniqueOnCreateUpdate<T extends DBModel, V extends IRepository<T>, Y = any>(this: V, data: Y, key: string, model: T): Promise<void>;
50
- /**
51
- * @summary Unique Decorator
52
- * @description Tags a property as unique.
53
- * No other elements in that table can have the same property value
54
- *
55
- * @function unique
56
- *
57
- * @memberOf module:wallet-db.Decorators
58
- */
59
- export declare function unique(): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void;
60
49
  export declare function serializeOnCreateUpdate<T extends DBModel, V extends IRepository<T>, Y = any>(this: V, data: Y, key: string, model: T, oldModel: T): Promise<void>;
61
50
  export declare function serializeAfterAll<T extends DBModel, V extends IRepository<T>, Y = any>(this: V, data: Y, key: string, model: T): Promise<void>;
62
51
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decaf-ts/db-decorators",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Agnostic database decorators and repository",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,7 +19,7 @@
19
19
  "test:integration": "jest --coverage --testPathPattern=\"/tests/(integration)\" --passWithNoTests --detectOpenHandles",
20
20
  "test:all": "jest --coverage --testPathPattern=\"/tests/(unit|integration)\" --passWithNoTests --detectOpenHandles",
21
21
  "lint": "eslint .",
22
- "lint-fix": "eslint . && eslint --fix ./src/*",
22
+ "lint-fix": "eslint --fix ./src/*",
23
23
  "test:circular": "dpdm -T --no-warning --no-tree ./src/index.ts",
24
24
  "prepare-release": "npm run lint-fix && npm run build:prod && npm run test && npm run docs",
25
25
  "release": "./bin/tag-release.sh",
@@ -1,6 +0,0 @@
1
- import { CascadeMetadata } from "./types";
2
- export declare enum Cascade {
3
- CASCADE = "cascade",
4
- NONE = "none"
5
- }
6
- export declare const DefaultCascade: CascadeMetadata;
@@ -1 +0,0 @@
1
- var Cascade;!function(a){a.CASCADE="cascade",a.NONE="none"}(Cascade=Cascade||{});const DefaultCascade={update:Cascade.CASCADE,delete:Cascade.NONE};export{Cascade,DefaultCascade};
@@ -1,13 +0,0 @@
1
- import { Cascade } from "./constants";
2
- import { OrderDirection } from "../validation/constants";
3
- /**
4
- * @summary defines the cascading behaviour
5
- */
6
- export type CascadeMetadata = {
7
- update: Cascade;
8
- delete: Cascade;
9
- };
10
- export type IndexMetadata = {
11
- directions?: OrderDirection[2];
12
- compositions?: string[];
13
- };
File without changes
@@ -1 +0,0 @@
1
- "use strict";var Cascade;Object.defineProperty(exports,"__esModule",{value:!0}),exports.DefaultCascade=exports.Cascade=void 0,function(e){e.CASCADE="cascade",e.NONE="none"}(Cascade||(exports.Cascade=Cascade={})),exports.DefaultCascade={update:Cascade.CASCADE,delete:Cascade.NONE};
@@ -1,6 +0,0 @@
1
- import { CascadeMetadata } from "./types";
2
- export declare enum Cascade {
3
- CASCADE = "cascade",
4
- NONE = "none"
5
- }
6
- export declare const DefaultCascade: CascadeMetadata;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -1,13 +0,0 @@
1
- import { Cascade } from "./constants";
2
- import { OrderDirection } from "../validation/constants";
3
- /**
4
- * @summary defines the cascading behaviour
5
- */
6
- export type CascadeMetadata = {
7
- update: Cascade;
8
- delete: Cascade;
9
- };
10
- export type IndexMetadata = {
11
- directions?: OrderDirection[2];
12
- compositions?: string[];
13
- };