@decaf-ts/db-decorators 0.7.4 → 0.7.6
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.
- package/README.md +5 -1
- package/dist/db-decorators.cjs +1 -1
- package/dist/db-decorators.cjs.map +1 -1
- package/dist/db-decorators.js +1 -1
- package/dist/db-decorators.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/interfaces/BulkCrudOperator.d.ts +5 -4
- package/lib/esm/interfaces/Contextual.d.ts +3 -3
- package/lib/esm/interfaces/CrudOperator.d.ts +5 -4
- package/lib/esm/interfaces/IRepository.d.ts +2 -4
- package/lib/esm/model/decorators.d.ts +6 -7
- package/lib/esm/model/decorators.js +16 -14
- package/lib/esm/model/decorators.js.map +1 -1
- package/lib/esm/operations/Operations.d.ts +3 -7
- package/lib/esm/operations/Operations.js +1 -3
- package/lib/esm/operations/Operations.js.map +1 -1
- package/lib/esm/operations/OperationsRegistry.d.ts +2 -6
- package/lib/esm/operations/OperationsRegistry.js +0 -2
- package/lib/esm/operations/OperationsRegistry.js.map +1 -1
- package/lib/esm/operations/decorators.d.ts +42 -28
- package/lib/esm/operations/decorators.js +34 -11
- package/lib/esm/operations/decorators.js.map +1 -1
- package/lib/esm/operations/types.d.ts +9 -10
- package/lib/esm/overrides/Model.d.ts +16 -4
- package/lib/esm/overrides/overrides.js +21 -0
- package/lib/esm/overrides/overrides.js.map +1 -1
- package/lib/esm/repository/BaseRepository.d.ts +16 -27
- package/lib/esm/repository/BaseRepository.js +2 -28
- package/lib/esm/repository/BaseRepository.js.map +1 -1
- package/lib/esm/repository/Context.d.ts +9 -8
- package/lib/esm/repository/Context.js +9 -1
- package/lib/esm/repository/Context.js.map +1 -1
- package/lib/esm/repository/Repository.d.ts +9 -6
- package/lib/esm/repository/Repository.js +52 -38
- package/lib/esm/repository/Repository.js.map +1 -1
- package/lib/esm/repository/constants.d.ts +1 -1
- package/lib/esm/repository/constants.js +2 -0
- package/lib/esm/repository/constants.js.map +1 -1
- package/lib/esm/repository/types.d.ts +16 -2
- package/lib/esm/repository/utils.d.ts +6 -32
- package/lib/esm/repository/utils.js +9 -106
- package/lib/esm/repository/utils.js.map +1 -1
- package/lib/esm/validation/decorators.d.ts +4 -5
- package/lib/esm/validation/decorators.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/interfaces/BulkCrudOperator.d.ts +5 -4
- package/lib/interfaces/Contextual.d.ts +3 -3
- package/lib/interfaces/CrudOperator.d.ts +5 -4
- package/lib/interfaces/IRepository.d.ts +2 -4
- package/lib/model/decorators.cjs +16 -14
- package/lib/model/decorators.d.ts +6 -7
- package/lib/model/decorators.js.map +1 -1
- package/lib/operations/Operations.cjs +1 -3
- package/lib/operations/Operations.d.ts +3 -7
- package/lib/operations/Operations.js.map +1 -1
- package/lib/operations/OperationsRegistry.cjs +0 -2
- package/lib/operations/OperationsRegistry.d.ts +2 -6
- package/lib/operations/OperationsRegistry.js.map +1 -1
- package/lib/operations/decorators.cjs +36 -12
- package/lib/operations/decorators.d.ts +42 -28
- package/lib/operations/decorators.js.map +1 -1
- package/lib/operations/types.d.ts +9 -10
- package/lib/overrides/Model.d.ts +16 -4
- package/lib/overrides/overrides.cjs +21 -0
- package/lib/overrides/overrides.js.map +1 -1
- package/lib/repository/BaseRepository.cjs +2 -28
- package/lib/repository/BaseRepository.d.ts +16 -27
- package/lib/repository/BaseRepository.js.map +1 -1
- package/lib/repository/Context.cjs +9 -1
- package/lib/repository/Context.d.ts +9 -8
- package/lib/repository/Context.js.map +1 -1
- package/lib/repository/Repository.cjs +51 -37
- package/lib/repository/Repository.d.ts +9 -6
- package/lib/repository/Repository.js.map +1 -1
- package/lib/repository/constants.cjs +2 -0
- package/lib/repository/constants.d.ts +1 -1
- package/lib/repository/constants.js.map +1 -1
- package/lib/repository/types.d.ts +16 -2
- package/lib/repository/utils.cjs +10 -108
- package/lib/repository/utils.d.ts +6 -32
- package/lib/repository/utils.js.map +1 -1
- package/lib/validation/decorators.d.ts +4 -5
- package/lib/validation/decorators.js.map +1 -1
- package/package.json +11 -10
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Context } from "./Context";
|
|
2
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { ExtendedMetadata, Model } from "@decaf-ts/decorator-validation";
|
|
3
3
|
import { OperationKeys } from "../operations";
|
|
4
4
|
import { Constructor } from "@decaf-ts/decoration";
|
|
5
|
+
import { Logger } from "@decaf-ts/logging";
|
|
6
|
+
import { IRepository } from "../interfaces/index";
|
|
5
7
|
/**
|
|
6
8
|
* @description Type utility for ensuring model extension.
|
|
7
9
|
* @summary A conditional type that ensures a type extends the Model class.
|
|
@@ -28,7 +30,7 @@ export type ModelExtension<M extends Model = Model> = M extends Model ? M : neve
|
|
|
28
30
|
* @property {boolean} rebuildWithTransient - Whether to include transient properties when rebuilding models
|
|
29
31
|
* @memberOf module:db-decorators
|
|
30
32
|
*/
|
|
31
|
-
export interface RepositoryFlags {
|
|
33
|
+
export interface RepositoryFlags<LOG extends Logger = Logger> {
|
|
32
34
|
parentContext?: Context<any>;
|
|
33
35
|
childContexts?: Context<any>[];
|
|
34
36
|
callArgs?: any[];
|
|
@@ -39,4 +41,16 @@ export interface RepositoryFlags {
|
|
|
39
41
|
operation?: OperationKeys;
|
|
40
42
|
breakOnHandlerError: boolean;
|
|
41
43
|
rebuildWithTransient: boolean;
|
|
44
|
+
ignoreValidation: boolean;
|
|
45
|
+
ignoreHandlers: boolean | string | RegExp;
|
|
46
|
+
logger: LOG;
|
|
47
|
+
correlationId?: string;
|
|
42
48
|
}
|
|
49
|
+
export type LoggerOfFlags<R extends RepositoryFlags<any>> = R extends RepositoryFlags<infer L> ? L : never;
|
|
50
|
+
export type FlagsOfContext<C extends Context<any>> = C extends Context<infer F> ? F : never;
|
|
51
|
+
export type LoggerOfContext<C extends Context<any>> = LoggerOfFlags<FlagsOfContext<C>>;
|
|
52
|
+
export type ContextOfRepository<R extends IRepository<any, any>> = R extends IRepository<any, infer C> ? C : never;
|
|
53
|
+
export type LoggerOfRepository<R extends IRepository<any, any>> = LoggerOfContext<ContextOfRepository<R>>;
|
|
54
|
+
export type FlagsOfRepository<R extends IRepository<any, any>> = R extends IRepository<any, infer C> ? FlagsOfContext<C> : never;
|
|
55
|
+
export type PrimaryKeyType = string | number | bigint;
|
|
56
|
+
export type InferredPrimaryKeyType<M extends Model> = ExtendedMetadata<M>;
|
|
@@ -1,38 +1,12 @@
|
|
|
1
1
|
import { IRepository } from "../interfaces/IRepository";
|
|
2
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { Model, ModelErrorDefinition } from "@decaf-ts/decorator-validation";
|
|
3
3
|
import { Context } from "./Context";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @description Context arguments for repository operations.
|
|
8
|
-
* @summary Represents the context and arguments for repository operations.
|
|
9
|
-
* This type is used to pass context and arguments between repository methods.
|
|
10
|
-
* @template F - The repository flags type, defaults to RepositoryFlags
|
|
11
|
-
* @template C - The context type, defaults to Context<F>
|
|
12
|
-
* @typedef {Object} ContextArgs
|
|
13
|
-
* @property {C} context - The operation context
|
|
14
|
-
* @property {any[]} args - The operation arguments
|
|
15
|
-
* @memberOf module:db-decorators
|
|
16
|
-
*/
|
|
17
|
-
export type ContextArgs<F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>> = {
|
|
4
|
+
import { ContextOfRepository } from "./types";
|
|
5
|
+
export type ContextArgs<C extends Context<any>> = {
|
|
18
6
|
context: C;
|
|
19
|
-
args: any[];
|
|
7
|
+
args: [...any[], C];
|
|
20
8
|
};
|
|
21
|
-
|
|
22
|
-
* @summary retrieves the arguments for the handler
|
|
23
|
-
* @param {any} dec the decorator
|
|
24
|
-
* @param {string} prop the property name
|
|
25
|
-
* @param {{}} m the model
|
|
26
|
-
* @param {{}} [accum] accumulator used for internal recursiveness
|
|
27
|
-
*
|
|
28
|
-
* @function getHandlerArgs
|
|
29
|
-
* @memberOf module:db-decorators.Repository
|
|
30
|
-
*/
|
|
31
|
-
export declare const getHandlerArgs: (dec: any, prop: string, m: Constructor<any>, accum?: Record<string, {
|
|
32
|
-
args: string[];
|
|
33
|
-
}>) => Record<string, {
|
|
34
|
-
args: string[];
|
|
35
|
-
}> | void;
|
|
9
|
+
export declare function reduceErrorsToPrint(errors: (ModelErrorDefinition | undefined)[]): string | undefined;
|
|
36
10
|
/**
|
|
37
11
|
*
|
|
38
12
|
* @param {IRepository<T>} repo
|
|
@@ -46,7 +20,7 @@ export declare const getHandlerArgs: (dec: any, prop: string, m: Constructor<any
|
|
|
46
20
|
*
|
|
47
21
|
* @memberOf db-decorators.utils
|
|
48
22
|
*/
|
|
49
|
-
export declare function enforceDBDecorators<M extends Model<true | false>, R extends IRepository<M,
|
|
23
|
+
export declare function enforceDBDecorators<M extends Model<true | false>, R extends IRepository<M, any>, V extends object = object>(repo: R, context: ContextOfRepository<R>, model: M, operation: string, prefix: string, oldModel?: M): Promise<void>;
|
|
50
24
|
/**
|
|
51
25
|
* Specific for DB Decorators
|
|
52
26
|
* @param {T} model
|
|
@@ -2,30 +2,16 @@ import { ModelOperations, OperationKeys } from "./../operations/constants.js";
|
|
|
2
2
|
import { InternalError } from "./errors.js";
|
|
3
3
|
import { getHandlersDecorators, groupDecorators, sortDecorators, } from "./../operations/decorators.js";
|
|
4
4
|
import { Metadata } from "@decaf-ts/decoration";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @function getHandlerArgs
|
|
13
|
-
* @memberOf module:db-decorators.Repository
|
|
14
|
-
*/
|
|
15
|
-
export const getHandlerArgs = function (dec, prop, m, accum) {
|
|
16
|
-
const name = m.constructor.name;
|
|
17
|
-
if (!name)
|
|
18
|
-
throw new InternalError("Could not determine model class");
|
|
19
|
-
accum = accum || {};
|
|
20
|
-
if (dec.props.handlers[name] && dec.props.handlers[name][prop])
|
|
21
|
-
accum = { ...dec.props.handlers[name][prop], ...accum };
|
|
22
|
-
let proto = Object.getPrototypeOf(m);
|
|
23
|
-
if (proto === Object.prototype)
|
|
5
|
+
export function reduceErrorsToPrint(errors) {
|
|
6
|
+
return errors.reduce((accum, e, i) => {
|
|
7
|
+
if (e)
|
|
8
|
+
accum =
|
|
9
|
+
typeof accum === "string"
|
|
10
|
+
? accum + `\n - ${i}: ${e.toString()}`
|
|
11
|
+
: ` - ${i}: ${e.toString()}`;
|
|
24
12
|
return accum;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return getHandlerArgs(dec, prop, proto, accum);
|
|
28
|
-
};
|
|
13
|
+
}, undefined);
|
|
14
|
+
}
|
|
29
15
|
/**
|
|
30
16
|
*
|
|
31
17
|
* @param {IRepository<T>} repo
|
|
@@ -100,87 +86,4 @@ export function getDbDecorators(model, operation, extraPrefix) {
|
|
|
100
86
|
return accum;
|
|
101
87
|
}, undefined);
|
|
102
88
|
}
|
|
103
|
-
// /**
|
|
104
|
-
// * @summary Retrieves the decorators for an object's properties prefixed by {@param prefixes} recursively
|
|
105
|
-
// * @param model
|
|
106
|
-
// * @param accum
|
|
107
|
-
// * @param prefixes
|
|
108
|
-
// *
|
|
109
|
-
// * @function getAllPropertyDecoratorsRecursive
|
|
110
|
-
// * @memberOf module:db-decorators.Repository
|
|
111
|
-
// */
|
|
112
|
-
// export const getAllPropertyDecoratorsRecursive = function <T extends Model>(
|
|
113
|
-
// model: T,
|
|
114
|
-
// accum: { [indexer: string]: any[] } | undefined,
|
|
115
|
-
// ...prefixes: string[]
|
|
116
|
-
// ): { [indexer: string]: any[] } | undefined {
|
|
117
|
-
// const accumulator = accum || {};
|
|
118
|
-
// const mergeDecorators = function (decs: { [indexer: string]: any[] }) {
|
|
119
|
-
// const pushOrSquash = (key: string, ...values: any[]) => {
|
|
120
|
-
// values.forEach((val) => {
|
|
121
|
-
// let match: any;
|
|
122
|
-
// if (
|
|
123
|
-
// !(match = accumulator[key].find((e) => e.key === val.key)) ||
|
|
124
|
-
// match.props.operation !== val.props.operation
|
|
125
|
-
// ) {
|
|
126
|
-
// accumulator[key].push(val);
|
|
127
|
-
// return;
|
|
128
|
-
// }
|
|
129
|
-
// if (val.key === ModelKeys.TYPE) return;
|
|
130
|
-
// const { handlers, operation } = val.props;
|
|
131
|
-
// if (
|
|
132
|
-
// !operation ||
|
|
133
|
-
// !operation.match(
|
|
134
|
-
// new RegExp(
|
|
135
|
-
// `^(:?${OperationKeys.ON}|${OperationKeys.AFTER})(:?${OperationKeys.CREATE}|${OperationKeys.READ}|${OperationKeys.UPDATE}|${OperationKeys.DELETE})$`
|
|
136
|
-
// )
|
|
137
|
-
// )
|
|
138
|
-
// ) {
|
|
139
|
-
// accumulator[key].push(val);
|
|
140
|
-
// return;
|
|
141
|
-
// }
|
|
142
|
-
// const accumHandlers = match.props.handlers;
|
|
143
|
-
// Object.entries(handlers).forEach(([clazz, handlerDef]) => {
|
|
144
|
-
// if (!(clazz in accumHandlers)) {
|
|
145
|
-
// accumHandlers[clazz] = handlerDef;
|
|
146
|
-
// return;
|
|
147
|
-
// }
|
|
148
|
-
// Object.entries(handlerDef as object).forEach(
|
|
149
|
-
// ([handlerProp, handler]) => {
|
|
150
|
-
// if (!(handlerProp in accumHandlers[clazz])) {
|
|
151
|
-
// accumHandlers[clazz][handlerProp] = handler;
|
|
152
|
-
// return;
|
|
153
|
-
// }
|
|
154
|
-
// Object.entries(handler as object).forEach(
|
|
155
|
-
// ([handlerKey, argsObj]) => {
|
|
156
|
-
// if (!(handlerKey in accumHandlers[clazz][handlerProp])) {
|
|
157
|
-
// accumHandlers[clazz][handlerProp][handlerKey] = argsObj;
|
|
158
|
-
// return;
|
|
159
|
-
// }
|
|
160
|
-
// console.warn(
|
|
161
|
-
// `Skipping handler registration for ${clazz} under prop ${handlerProp} because handler is the same`
|
|
162
|
-
// );
|
|
163
|
-
// }
|
|
164
|
-
// );
|
|
165
|
-
// }
|
|
166
|
-
// );
|
|
167
|
-
// });
|
|
168
|
-
// });
|
|
169
|
-
// };
|
|
170
|
-
// Object.entries(decs).forEach(([key, value]) => {
|
|
171
|
-
// accumulator[key] = accumulator[key] || [];
|
|
172
|
-
// pushOrSquash(key, ...value);
|
|
173
|
-
// });
|
|
174
|
-
// };
|
|
175
|
-
// const decs: { [indexer: string]: any[] } | undefined =
|
|
176
|
-
// Reflection.getAllPropertyDecorators(model, ...prefixes);
|
|
177
|
-
// if (decs) mergeDecorators(decs);
|
|
178
|
-
// if (Object.getPrototypeOf(model) === Object.prototype) return accumulator;
|
|
179
|
-
// // const name = model.constructor.name;
|
|
180
|
-
// const proto = Object.getPrototypeOf(model);
|
|
181
|
-
// if (!proto) return accumulator;
|
|
182
|
-
// // if (proto.constructor && proto.constructor.name === name)
|
|
183
|
-
// // proto = Object.getPrototypeOf(proto)
|
|
184
|
-
// return getAllPropertyDecoratorsRecursive(proto, accumulator, ...prefixes);
|
|
185
|
-
// };
|
|
186
89
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/repository/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,qCAAgC;AACzE,OAAO,EAAE,aAAa,EAAE,oBAAiB;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/repository/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,qCAAgC;AACzE,OAAO,EAAE,aAAa,EAAE,oBAAiB;AAGzC,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,cAAc,GACf,sCAAiC;AAElC,OAAO,EAAe,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQ7D,MAAM,UAAU,mBAAmB,CACjC,MAA4C;IAE5C,OAAO,MAAM,CAAC,MAAM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G,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;QACjE,MAAM,IAAI,GAAG,EAAE,CAAC;QAChB,KAAK,MAAM,CAAC,IAAI,GAAG;YAAE,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAE1D,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK;gBAAE,KAAK,GAAG,EAAE,CAAC;YACvB,KAAK,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;QAC1B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,EACD,SAAS,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -2,8 +2,7 @@ import "./validation";
|
|
|
2
2
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
3
|
import { OperationKeys } from "../operations/constants";
|
|
4
4
|
import { IRepository } from "../interfaces/IRepository";
|
|
5
|
-
import {
|
|
6
|
-
import { RepositoryFlags } from "../repository/types";
|
|
5
|
+
import { ContextOfRepository } from "../repository/index";
|
|
7
6
|
/**
|
|
8
7
|
* @description Prevents a property from being modified after initial creation.
|
|
9
8
|
* @summary Marks the property as readonly, causing validation errors if attempts are made to modify it during updates.
|
|
@@ -28,7 +27,7 @@ export declare function readonly(message?: string): (target: any, propertyKey?:
|
|
|
28
27
|
* @return {Promise<void>} A promise that resolves when the timestamp has been set
|
|
29
28
|
* @function timestampHandler
|
|
30
29
|
*/
|
|
31
|
-
export declare function timestampHandler<M extends Model, R extends IRepository<M,
|
|
30
|
+
export declare function timestampHandler<M extends Model, R extends IRepository<M, any>, V>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M): Promise<void>;
|
|
32
31
|
/**
|
|
33
32
|
* @description Automatically manages timestamp properties for tracking creation and update times.
|
|
34
33
|
* @summary Marks the property as a timestamp, making it required and ensuring it's a valid date. The property will be automatically updated with the current timestamp during specified operations.
|
|
@@ -92,7 +91,7 @@ export declare function timestamp(operation?: OperationKeys[], format?: string):
|
|
|
92
91
|
* @return {Promise<void>} A promise that resolves when the property has been serialized
|
|
93
92
|
* @function serializeOnCreateUpdate
|
|
94
93
|
*/
|
|
95
|
-
export declare function serializeOnCreateUpdate<M extends Model, R extends IRepository<M,
|
|
94
|
+
export declare function serializeOnCreateUpdate<M extends Model, R extends IRepository<M, any>, V>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M): Promise<void>;
|
|
96
95
|
/**
|
|
97
96
|
* @description Handler function that deserializes a property from JSON string after database operations.
|
|
98
97
|
* @summary Converts a JSON string property back to its original complex object form after retrieving it from the database.
|
|
@@ -108,7 +107,7 @@ export declare function serializeOnCreateUpdate<M extends Model, R extends IRepo
|
|
|
108
107
|
* @return {Promise<void>} A promise that resolves when the property has been deserialized
|
|
109
108
|
* @function serializeAfterAll
|
|
110
109
|
*/
|
|
111
|
-
export declare function serializeAfterAll<M extends Model, R extends IRepository<M,
|
|
110
|
+
export declare function serializeAfterAll<M extends Model, R extends IRepository<M, any>, V>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M): Promise<void>;
|
|
112
111
|
/**
|
|
113
112
|
* @description Enables automatic JSON serialization and deserialization for complex object properties.
|
|
114
113
|
* @summary Decorator that automatically converts complex objects to JSON strings before storing in the database and back to objects when retrieving them.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/validation/decorators.ts"],"names":[],"mappings":"AAAA,yBAAsB;AACtB,OAAO,EACL,IAAI,EACJ,wBAAwB,EAExB,QAAQ,EACR,IAAI,EACJ,UAAU,GACX,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,gCAA2B;AACtE,OAAO,EAAE,sBAAsB,EAAE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C,CAAC,EACtB,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC,CAC/B,CAAC;AACJ,CAAC"}
|
package/lib/index.cjs
CHANGED
|
@@ -34,7 +34,7 @@ __exportStar(require("./validation/index.cjs"), exports);
|
|
|
34
34
|
* @const VERSION
|
|
35
35
|
* @memberOf module:db-decorators
|
|
36
36
|
*/
|
|
37
|
-
exports.VERSION = "0.7.
|
|
37
|
+
exports.VERSION = "0.7.5";
|
|
38
38
|
exports.PACKAGE_NAME = "@decaf-ts/db-decorators";
|
|
39
39
|
decoration_1.Metadata.registerLibrary(exports.PACKAGE_NAME, exports.VERSION);
|
|
40
40
|
//# sourceMappingURL=index.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CrudOperator } from "./CrudOperator";
|
|
2
|
+
import { PrimaryKeyType } from "../repository/index";
|
|
2
3
|
/**
|
|
3
4
|
* @description Interface for bulk CRUD operations
|
|
4
5
|
* @summary Extends the basic CRUD operations to support bulk operations on multiple models at once
|
|
@@ -20,11 +21,11 @@ export interface BulkCrudOperator<M> extends CrudOperator<M> {
|
|
|
20
21
|
* @description Retrieves multiple model instances from the database by their keys
|
|
21
22
|
* @summary Bulk operation to read multiple models at once
|
|
22
23
|
* @template M - The model type
|
|
23
|
-
* @param {(
|
|
24
|
+
* @param {(PrimaryKeyType[])} keys - Array of primary keys to retrieve
|
|
24
25
|
* @param {...any[]} args - Additional arguments
|
|
25
26
|
* @return {Promise<M[]>} Promise resolving to the retrieved model instances
|
|
26
27
|
*/
|
|
27
|
-
readAll(keys:
|
|
28
|
+
readAll(keys: PrimaryKeyType[], ...args: any[]): Promise<M[]>;
|
|
28
29
|
/**
|
|
29
30
|
* @description Updates multiple model instances in the database
|
|
30
31
|
* @summary Bulk operation to update multiple models at once
|
|
@@ -38,9 +39,9 @@ export interface BulkCrudOperator<M> extends CrudOperator<M> {
|
|
|
38
39
|
* @description Deletes multiple model instances from the database by their keys
|
|
39
40
|
* @summary Bulk operation to delete multiple models at once
|
|
40
41
|
* @template M - The model type
|
|
41
|
-
* @param {(
|
|
42
|
+
* @param {(PrimaryKeyType[])} keys - Array of primary keys to delete
|
|
42
43
|
* @param {...any[]} args - Additional arguments
|
|
43
44
|
* @return {Promise<M[]>} Promise resolving to the deleted model instances
|
|
44
45
|
*/
|
|
45
|
-
deleteAll(keys:
|
|
46
|
+
deleteAll(keys: PrimaryKeyType[], ...args: any[]): Promise<M[]>;
|
|
46
47
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OperationKeys } from "../operations";
|
|
2
2
|
import { Context } from "../repository";
|
|
3
|
-
|
|
3
|
+
export type FlagsOf<C extends Context<any>> = C extends Context<infer T> ? T : never;
|
|
4
4
|
/**
|
|
5
5
|
* @description Interface for context-aware operations
|
|
6
6
|
* @summary Provides context management for database operations
|
|
@@ -9,7 +9,7 @@ import { RepositoryFlags } from "../repository/types";
|
|
|
9
9
|
* @interface Contextual
|
|
10
10
|
* @memberOf module:db-decorators
|
|
11
11
|
*/
|
|
12
|
-
export interface Contextual<
|
|
12
|
+
export interface Contextual<C extends Context<any> = Context<any>> {
|
|
13
13
|
/**
|
|
14
14
|
* @description Creates a context for a specific operation
|
|
15
15
|
* @summary Generates an operation-specific context with custom flags
|
|
@@ -19,5 +19,5 @@ export interface Contextual<F extends RepositoryFlags = RepositoryFlags, C exten
|
|
|
19
19
|
* @param {...any[]} args - Additional arguments
|
|
20
20
|
* @return {Promise<C>} Promise resolving to the created context
|
|
21
21
|
*/
|
|
22
|
-
context(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE, overrides: Partial<
|
|
22
|
+
context(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE | string, overrides: Partial<FlagsOf<C>>, ...args: any[]): Promise<C>;
|
|
23
23
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PrimaryKeyType } from "../repository/index";
|
|
1
2
|
/**
|
|
2
3
|
* @description Basic CRUD operations interface
|
|
3
4
|
* @summary Exposes a standard Create, Read, Update, Delete API for database operations
|
|
@@ -19,11 +20,11 @@ export interface CrudOperator<M> {
|
|
|
19
20
|
* @description Retrieves a model instance from the database by its key
|
|
20
21
|
* @summary Read a model
|
|
21
22
|
* @template M - The model type
|
|
22
|
-
* @param {
|
|
23
|
+
* @param {PrimaryKeyType} key - The primary key of the model to retrieve
|
|
23
24
|
* @param {...any[]} args - Additional arguments
|
|
24
25
|
* @return {Promise<M>} Promise resolving to the retrieved model instance
|
|
25
26
|
*/
|
|
26
|
-
read(key:
|
|
27
|
+
read(key: PrimaryKeyType, ...args: any[]): Promise<M>;
|
|
27
28
|
/**
|
|
28
29
|
* @description Updates a model instance in the database
|
|
29
30
|
* @summary Update a model
|
|
@@ -37,9 +38,9 @@ export interface CrudOperator<M> {
|
|
|
37
38
|
* @description Deletes a model instance from the database by its key
|
|
38
39
|
* @summary Delete a model
|
|
39
40
|
* @template M - The model type
|
|
40
|
-
* @param {
|
|
41
|
+
* @param {PrimaryKeyType} key - The primary key of the model to delete
|
|
41
42
|
* @param {...any[]} args - Additional arguments
|
|
42
43
|
* @return {Promise<M>} Promise resolving to the deleted model instance
|
|
43
44
|
*/
|
|
44
|
-
delete(key:
|
|
45
|
+
delete(key: PrimaryKeyType, ...args: any[]): Promise<M>;
|
|
45
46
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
2
2
|
import { BulkCrudOperator } from "./BulkCrudOperator";
|
|
3
|
-
import { RepositoryFlags } from "../repository
|
|
4
|
-
import { Context } from "../repository";
|
|
3
|
+
import { Context, RepositoryFlags } from "../repository";
|
|
5
4
|
/**
|
|
6
5
|
* @description Repository interface for database operations
|
|
7
6
|
* @summary Interface holding basic CRUD APIs for database models, providing standard operations and metadata
|
|
@@ -11,11 +10,10 @@ import { Context } from "../repository";
|
|
|
11
10
|
* @interface IRepository
|
|
12
11
|
* @memberOf module:db-decorators
|
|
13
12
|
*/
|
|
14
|
-
export interface IRepository<M extends Model<
|
|
13
|
+
export interface IRepository<M extends Model<boolean>, C extends Context<any> = Context<RepositoryFlags>> extends BulkCrudOperator<M> {
|
|
15
14
|
/**
|
|
16
15
|
* @description The constructor of the model class
|
|
17
16
|
* @summary Reference to the model class constructor used to create new instances
|
|
18
17
|
*/
|
|
19
18
|
readonly class: ModelConstructor<M>;
|
|
20
|
-
readonly pk: keyof M;
|
|
21
19
|
}
|
package/lib/model/decorators.cjs
CHANGED
|
@@ -102,21 +102,23 @@ function composedFromCreateUpdate(context, data, key, model) {
|
|
|
102
102
|
* @category PropertyDecorators
|
|
103
103
|
*/
|
|
104
104
|
function composedFrom(args, hashResult = false, separator = constants_1.DefaultSeparator, type = "values", prefix = "", suffix = "", groupsort = { priority: 55 }) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
return function composeFrom(target, property) {
|
|
106
|
+
const data = {
|
|
107
|
+
args: args,
|
|
108
|
+
hashResult: hashResult,
|
|
109
|
+
separator: separator,
|
|
110
|
+
type: type,
|
|
111
|
+
prefix: prefix,
|
|
112
|
+
suffix: suffix,
|
|
113
|
+
};
|
|
114
|
+
const decorators = [
|
|
115
|
+
(0, decorators_1.onCreateUpdate)(composedFromCreateUpdate, data, groupsort),
|
|
116
|
+
(0, decoration_1.propMetadata)(decoration_1.Metadata.key(constants_1.DBKeys.COMPOSED, property), data),
|
|
117
|
+
];
|
|
118
|
+
if (hashResult)
|
|
119
|
+
decorators.push(hash());
|
|
120
|
+
return (0, decoration_1.apply)(...decorators)(target, property);
|
|
112
121
|
};
|
|
113
|
-
const decorators = [
|
|
114
|
-
(0, decorators_1.onCreateUpdate)(composedFromCreateUpdate, data, groupsort),
|
|
115
|
-
(0, decoration_1.propMetadata)(constants_1.DBKeys.COMPOSED, data),
|
|
116
|
-
];
|
|
117
|
-
if (hashResult)
|
|
118
|
-
decorators.push(hash());
|
|
119
|
-
return (0, decoration_1.apply)(...decorators);
|
|
120
122
|
}
|
|
121
123
|
/**
|
|
122
124
|
* @description Creates a decorator that composes a property value from property keys
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
2
|
import { IRepository } from "../interfaces/IRepository";
|
|
3
|
-
import { Context } from "../repository/Context";
|
|
4
3
|
import { CrudOperations, GroupSort } from "../operations";
|
|
5
|
-
import {
|
|
4
|
+
import { ContextOfRepository } from "../repository/index";
|
|
6
5
|
/**
|
|
7
6
|
* @description Hashes a property value during create or update operations
|
|
8
7
|
* @summary Callback function used by the hash decorator to apply hashing to a property value
|
|
@@ -20,7 +19,7 @@ import { RepositoryFlags } from "../repository/types";
|
|
|
20
19
|
* @function hashOnCreateUpdate
|
|
21
20
|
* @memberOf module:db-decorators
|
|
22
21
|
*/
|
|
23
|
-
export declare function hashOnCreateUpdate<M extends Model, R extends IRepository<M,
|
|
22
|
+
export declare function hashOnCreateUpdate<M extends Model, R extends IRepository<M, any>, V extends object>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M, oldModel?: M): void;
|
|
24
23
|
/**
|
|
25
24
|
* @description Creates a decorator that hashes a property value
|
|
26
25
|
* @summary Decorator that automatically hashes a property value during create and update operations
|
|
@@ -65,7 +64,7 @@ export type ComposedFromMetadata = {
|
|
|
65
64
|
* @function composedFromCreateUpdate
|
|
66
65
|
* @memberOf module:db-decorators
|
|
67
66
|
*/
|
|
68
|
-
export declare function composedFromCreateUpdate<M extends Model, R extends IRepository<M,
|
|
67
|
+
export declare function composedFromCreateUpdate<M extends Model, R extends IRepository<M, any>, V extends ComposedFromMetadata>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M): void;
|
|
69
68
|
/**
|
|
70
69
|
* @description Creates a decorator that composes a property value from property keys
|
|
71
70
|
* @summary Decorator that generates a property value by joining the names of other properties
|
|
@@ -79,7 +78,7 @@ export declare function composedFromCreateUpdate<M extends Model, R extends IRep
|
|
|
79
78
|
* @function composedFromKeys
|
|
80
79
|
* @category PropertyDecorators
|
|
81
80
|
*/
|
|
82
|
-
export declare function composedFromKeys(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string, groupsort?: GroupSort): (target: object,
|
|
81
|
+
export declare function composedFromKeys(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string, groupsort?: GroupSort): (target: object, property?: any) => void;
|
|
83
82
|
/**
|
|
84
83
|
* @description Creates a decorator that composes a property value from property values
|
|
85
84
|
* @summary Decorator that generates a property value by joining the values of other properties
|
|
@@ -93,7 +92,7 @@ export declare function composedFromKeys(args: string[], separator?: string, has
|
|
|
93
92
|
* @function composed
|
|
94
93
|
* @category PropertyDecorators
|
|
95
94
|
*/
|
|
96
|
-
export declare function composed(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string, groupsort?: GroupSort): (target: object,
|
|
95
|
+
export declare function composed(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string, groupsort?: GroupSort): (target: object, property?: any) => void;
|
|
97
96
|
/**
|
|
98
97
|
* @description Creates a function that updates a version property during operations
|
|
99
98
|
* @summary Factory function that generates a callback for incrementing version numbers
|
|
@@ -124,7 +123,7 @@ export declare function composed(args: string[], separator?: string, hash?: bool
|
|
|
124
123
|
* end
|
|
125
124
|
* versionCreateUpdate-->>Caller: void
|
|
126
125
|
*/
|
|
127
|
-
export declare function versionCreateUpdate(operation: CrudOperations): <M extends Model, R extends IRepository<M
|
|
126
|
+
export declare function versionCreateUpdate(operation: CrudOperations): <M extends Model, R extends IRepository<M>, V extends object>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M) => void;
|
|
128
127
|
/**
|
|
129
128
|
* @description Creates a decorator for versioning a property in a model
|
|
130
129
|
* @summary This decorator applies multiple sub-decorators to handle version management during create and update operations
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/model/decorators.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/model/decorators.ts"],"names":[],"mappings":";;AA+BA,gDAgBC;AASD,oBAKC;AAuCD,4DAyBC;AAyDD,4CASC;AAeD,4BAiBC;AAgCD,kDAqBC;AASD,0BAUC;AASD,8BAUC;AA1TD,+CAAuD;AACvD,yEAAsE;AACtE,+DAA8E;AAE9E,uDAAqD;AACrD,0DAAyE;AACzE,qDAK8B;AAG9B;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,kBAAkB,CAMhC,OAA+B,EAC/B,IAAO,EACP,GAAY,EACZ,KAAQ,EACR,QAAY;IAEZ,IAAI,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,WAAW;QAAE,OAAO;IAC9C,MAAM,IAAI,GAAG,8BAAO,CAAC,IAAI,CAAE,KAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/C,IAAI,QAAQ,IAAK,KAAa,CAAC,GAAG,CAAC,KAAK,IAAI;QAAE,OAAO;IACrD,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,IAAI;IAClB,OAAO,IAAA,kBAAK,EACV,IAAA,2BAAc,EAAC,kBAAkB,CAAC,EAClC,IAAA,yBAAY,EAAC,kBAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAC9B,CAAC;AACJ,CAAC;AAuBD;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,wBAAwB,CAI7B,OAA+B,EAAE,IAAO,EAAE,GAAY,EAAE,KAAQ;IACzE,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAW,EAAE,E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./constants.cjs");
|
|
|
11
11
|
* @template M - Model type
|
|
12
12
|
* @template R - Repository type
|
|
13
13
|
* @template V - Metadata type
|
|
14
|
-
* @template F - Repository flags
|
|
15
|
-
* @template C - Context type
|
|
16
14
|
* @example
|
|
17
15
|
* // Register a handler for a create operation
|
|
18
16
|
* Operations.register(myHandler, OperationKeys.CREATE, targetModel, 'propertyName');
|
|
@@ -37,7 +35,7 @@ class Operations {
|
|
|
37
35
|
/**
|
|
38
36
|
* @description Gets a unique name for an operation handler
|
|
39
37
|
* @summary Returns the name of the handler function or generates a hash if name is not available
|
|
40
|
-
* @param {OperationHandler<any, any, any
|
|
38
|
+
* @param {OperationHandler<any, any, any>} handler - The handler function to get the name for
|
|
41
39
|
* @return {string} The name of the handler or a generated hash
|
|
42
40
|
*/
|
|
43
41
|
static getHandlerName(handler) {
|
|
@@ -2,8 +2,6 @@ import { Model } from "@decaf-ts/decorator-validation";
|
|
|
2
2
|
import { OperationHandler } from "./types";
|
|
3
3
|
import { OperationKeys } from "./constants";
|
|
4
4
|
import { IRepository } from "../interfaces";
|
|
5
|
-
import { Context } from "../repository";
|
|
6
|
-
import { RepositoryFlags } from "../repository/types";
|
|
7
5
|
/**
|
|
8
6
|
* @description Static utility class for database operation management
|
|
9
7
|
* @summary Provides functionality for registering, retrieving, and managing database operation handlers
|
|
@@ -11,8 +9,6 @@ import { RepositoryFlags } from "../repository/types";
|
|
|
11
9
|
* @template M - Model type
|
|
12
10
|
* @template R - Repository type
|
|
13
11
|
* @template V - Metadata type
|
|
14
|
-
* @template F - Repository flags
|
|
15
|
-
* @template C - Context type
|
|
16
12
|
* @example
|
|
17
13
|
* // Register a handler for a create operation
|
|
18
14
|
* Operations.register(myHandler, OperationKeys.CREATE, targetModel, 'propertyName');
|
|
@@ -38,10 +34,10 @@ export declare class Operations {
|
|
|
38
34
|
/**
|
|
39
35
|
* @description Gets a unique name for an operation handler
|
|
40
36
|
* @summary Returns the name of the handler function or generates a hash if name is not available
|
|
41
|
-
* @param {OperationHandler<any, any, any
|
|
37
|
+
* @param {OperationHandler<any, any, any>} handler - The handler function to get the name for
|
|
42
38
|
* @return {string} The name of the handler or a generated hash
|
|
43
39
|
*/
|
|
44
|
-
static getHandlerName(handler: OperationHandler<any, any, any
|
|
40
|
+
static getHandlerName(handler: OperationHandler<any, any, any>): any;
|
|
45
41
|
/**
|
|
46
42
|
* @description Generates a reflection metadata key
|
|
47
43
|
* @summary Creates a fully qualified metadata key by prefixing with the reflection namespace
|
|
@@ -62,7 +58,7 @@ export declare class Operations {
|
|
|
62
58
|
* @param {string} operation - The operation key to get handlers for
|
|
63
59
|
* @return {any} The registered handlers for the specified target, property, and operation
|
|
64
60
|
*/
|
|
65
|
-
static get<M extends Model, R extends IRepository<M,
|
|
61
|
+
static get<M extends Model, R extends IRepository<M, any>, V = object>(targetName: string | Record<string, any>, propKey: string, operation: string): OperationHandler<M, R, V>[] | undefined;
|
|
66
62
|
/**
|
|
67
63
|
* @description Gets or initializes the operations registry
|
|
68
64
|
* @summary Returns the existing registry or creates a new one if it doesn't exist
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Operations.js","sourceRoot":"","sources":["../../src/operations/Operations.ts"],"names":[],"mappings":";;;AAAA,yEAAgE;AAEhE,iEAA0D;AAC1D,+CAA4C;
|
|
1
|
+
{"version":3,"file":"Operations.js","sourceRoot":"","sources":["../../src/operations/Operations.ts"],"names":[],"mappings":";;;AAAA,yEAAgE;AAEhE,iEAA0D;AAC1D,+CAA4C;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,UAAU;IAGrB,gBAAuB,CAAC;IAExB;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,OAAwC;QAC5D,IAAI,OAAO,CAAC,IAAI;YAAE,OAAO,OAAO,CAAC,IAAI,CAAC;QAEtC,OAAO,CAAC,IAAI,CACV,uHAAuH,CACxH,CAAC;QACF,OAAO,8BAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,GAAG,CAAC,GAAW;QACpB,OAAO,yBAAa,CAAC,OAAO,GAAG,GAAG,CAAC;IACrC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,GAAG,CACR,UAAwC,EACxC,OAAe,EACf,SAAiB;QAEjB,OAAO,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAU,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAC1E,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,aAAa;QAC1B,IAAI,CAAC,UAAU,CAAC,QAAQ;YAAE,UAAU,CAAC,QAAQ,GAAG,IAAI,uCAAkB,EAAE,CAAC;QACzE,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,QAAQ,CACb,OAAsC,EACtC,SAAwB,EACxB,MAAS,EACT,OAAwB;QAExB,UAAU,CAAC,aAAa,EAAE,CAAC,QAAQ,CACjC,OAAc,EACd,SAAS,EACT,MAAM,EACN,OAAO,CACR,CAAC;IACJ,CAAC;CACF;AArFD,gCAqFC"}
|
|
@@ -37,8 +37,6 @@ class OperationsRegistry {
|
|
|
37
37
|
* @template M - Model type extending Model
|
|
38
38
|
* @template R - Repository type extending IRepository
|
|
39
39
|
* @template V - Metadata type
|
|
40
|
-
* @template F - Repository flags extending RepositoryFlags
|
|
41
|
-
* @template C - Context type extending Context<F>
|
|
42
40
|
* @param {string | Record<string, any>} target - The target class name or object
|
|
43
41
|
* @param {string} propKey - The property key to get handlers for
|
|
44
42
|
* @param {string} operation - The operation key to get handlers for
|