@decaf-ts/core 0.7.7 → 0.7.9
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 +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/lib/esm/identity/decorators.d.ts +2 -0
- package/lib/esm/identity/decorators.js +50 -15
- package/lib/esm/identity/decorators.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/interfaces/Paginatable.d.ts +1 -1
- package/lib/esm/interfaces/SequenceOptions.d.ts +8 -1
- package/lib/esm/interfaces/SequenceOptions.js.map +1 -1
- package/lib/esm/persistence/Sequence.d.ts +2 -2
- package/lib/esm/persistence/Sequence.js +22 -9
- package/lib/esm/persistence/Sequence.js.map +1 -1
- package/lib/esm/persistence/constants.d.ts +3 -1
- package/lib/esm/persistence/constants.js +2 -0
- package/lib/esm/persistence/constants.js.map +1 -1
- package/lib/esm/query/decorators.d.ts +2 -1
- package/lib/esm/query/decorators.js +70 -38
- package/lib/esm/query/decorators.js.map +1 -1
- package/lib/esm/repository/Repository.d.ts +11 -4
- package/lib/esm/repository/Repository.js +65 -0
- package/lib/esm/repository/Repository.js.map +1 -1
- package/lib/esm/utils/Services.js +1 -0
- package/lib/esm/utils/Services.js.map +1 -1
- package/lib/identity/decorators.cjs +50 -14
- package/lib/identity/decorators.d.ts +2 -0
- package/lib/identity/decorators.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/interfaces/Paginatable.d.ts +1 -1
- package/lib/interfaces/SequenceOptions.d.ts +8 -1
- package/lib/interfaces/SequenceOptions.js.map +1 -1
- package/lib/persistence/Sequence.cjs +22 -9
- package/lib/persistence/Sequence.d.ts +2 -2
- package/lib/persistence/Sequence.js.map +1 -1
- package/lib/persistence/constants.cjs +2 -0
- package/lib/persistence/constants.d.ts +3 -1
- package/lib/persistence/constants.js.map +1 -1
- package/lib/query/decorators.cjs +71 -38
- package/lib/query/decorators.d.ts +2 -1
- package/lib/query/decorators.js.map +1 -1
- package/lib/repository/Repository.cjs +65 -0
- package/lib/repository/Repository.d.ts +11 -4
- package/lib/repository/Repository.js.map +1 -1
- package/lib/utils/Services.cjs +1 -0
- package/lib/utils/Services.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pkOnCreate = pkOnCreate;
|
|
4
|
+
exports.pkDec = pkDec;
|
|
4
5
|
exports.pk = pk;
|
|
5
6
|
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
6
7
|
const SequenceOptions_1 = require("./../interfaces/SequenceOptions.cjs");
|
|
@@ -64,6 +65,53 @@ async function pkOnCreate(context, data, key, model) {
|
|
|
64
65
|
const next = await sequence.next(context);
|
|
65
66
|
setPrimaryKeyValue(model, key, next);
|
|
66
67
|
}
|
|
68
|
+
function pkDec(options, groupsort) {
|
|
69
|
+
return function pkDec(obj, attr) {
|
|
70
|
+
(0, decoration_1.prop)()(obj, attr);
|
|
71
|
+
switch (options.type) {
|
|
72
|
+
case undefined: {
|
|
73
|
+
const metaType = decoration_1.Metadata.type(obj.constructor, attr);
|
|
74
|
+
if (![Number.name, String.name, BigInt.name].includes(metaType?.name || metaType))
|
|
75
|
+
throw new Error("Incorrrect option type");
|
|
76
|
+
options.type = metaType;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case String.name || String.name.toLowerCase():
|
|
80
|
+
console.warn(`Deprecated "${options.type}" type in options`);
|
|
81
|
+
// eslint-disable-next-line no-fallthrough
|
|
82
|
+
case String:
|
|
83
|
+
options.generated = false;
|
|
84
|
+
options.type = String;
|
|
85
|
+
break;
|
|
86
|
+
case Number.name || String.name.toLowerCase():
|
|
87
|
+
console.warn(`Deprecated "${options.type}" type in options`);
|
|
88
|
+
// eslint-disable-next-line no-fallthrough
|
|
89
|
+
case Number:
|
|
90
|
+
options.generated = true;
|
|
91
|
+
options.type = Number;
|
|
92
|
+
break;
|
|
93
|
+
case BigInt.name || BigInt.name.toLowerCase():
|
|
94
|
+
console.warn(`Deprecated "${options.type}" type in options`);
|
|
95
|
+
// eslint-disable-next-line no-fallthrough
|
|
96
|
+
case BigInt:
|
|
97
|
+
options.type = BigInt;
|
|
98
|
+
options.generated = true;
|
|
99
|
+
break;
|
|
100
|
+
case "uuid":
|
|
101
|
+
case "serial":
|
|
102
|
+
options.generated = true;
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
throw new Error("Unsupported type");
|
|
106
|
+
}
|
|
107
|
+
if (typeof options.generated === "undefined") {
|
|
108
|
+
options.generated = true;
|
|
109
|
+
}
|
|
110
|
+
return (0, decoration_1.apply)((0, decorators_1.index)([constants_1.OrderDirection.ASC, constants_1.OrderDirection.DSC]), (0, decorator_validation_1.required)(), (0, db_decorators_1.readonly)(),
|
|
111
|
+
// Model.pk neeeds to get the pk property name from the first property of Metatada[DBKeys.ID] ---> { [DBKeys.ID]: { [attr]:options }}
|
|
112
|
+
(0, decoration_1.propMetadata)(decoration_1.Metadata.key(db_decorators_1.DBKeys.ID, attr), options), (0, db_decorators_1.onCreate)(pkOnCreate, options, groupsort))(obj, attr);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
67
115
|
/**
|
|
68
116
|
* @description Primary Key Decorator
|
|
69
117
|
* @summary Marks a property as the model's primary key with automatic sequence generation
|
|
@@ -85,20 +133,8 @@ async function pkOnCreate(context, data, key, model) {
|
|
|
85
133
|
* ```
|
|
86
134
|
*/
|
|
87
135
|
function pk(opts = SequenceOptions_1.DefaultSequenceOptions) {
|
|
88
|
-
opts = Object.assign({}, SequenceOptions_1.DefaultSequenceOptions, opts
|
|
89
|
-
|
|
90
|
-
? true
|
|
91
|
-
: opts.generated || SequenceOptions_1.DefaultSequenceOptions.generated,
|
|
92
|
-
});
|
|
93
|
-
const key = db_decorators_1.DBKeys.ID;
|
|
94
|
-
function pkDec(options, groupsort) {
|
|
95
|
-
return function pkDec(obj, attr) {
|
|
96
|
-
return (0, decoration_1.apply)((0, decorators_1.index)([constants_1.OrderDirection.ASC, constants_1.OrderDirection.DSC]), (0, decorator_validation_1.required)(), (0, db_decorators_1.readonly)(),
|
|
97
|
-
// Model.pk neeeds to get the pk property name from the first property of Metatada[DBKeys.ID] ---> { [DBKeys.ID]: { [attr]:options }}
|
|
98
|
-
(0, decoration_1.propMetadata)(decoration_1.Metadata.key(db_decorators_1.DBKeys.ID, attr), options), (0, db_decorators_1.onCreate)(pkOnCreate, options, groupsort))(obj, attr);
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return decoration_1.Decoration.for(key)
|
|
136
|
+
opts = Object.assign({}, SequenceOptions_1.DefaultSequenceOptions, opts);
|
|
137
|
+
return decoration_1.Decoration.for(db_decorators_1.DBKeys.ID)
|
|
102
138
|
.define({
|
|
103
139
|
decorator: pkDec,
|
|
104
140
|
args: [opts, { priority: defaultPkPriority }],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
2
|
import { SequenceOptions } from "../interfaces/SequenceOptions";
|
|
3
|
+
import { GroupSort } from "@decaf-ts/db-decorators";
|
|
3
4
|
import { ContextOf } from "../persistence/types";
|
|
4
5
|
import { Repository } from "../repository/Repository";
|
|
5
6
|
/**
|
|
@@ -39,6 +40,7 @@ import { Repository } from "../repository/Repository";
|
|
|
39
40
|
* end
|
|
40
41
|
*/
|
|
41
42
|
export declare function pkOnCreate<M extends Model, R extends Repository<M, any>, V extends SequenceOptions>(this: R, context: ContextOf<R>, data: V, key: keyof M, model: M): Promise<void>;
|
|
43
|
+
export declare function pkDec(options: SequenceOptions, groupsort?: GroupSort): (obj: any, attr: any) => void;
|
|
42
44
|
/**
|
|
43
45
|
* @description Primary Key Decorator
|
|
44
46
|
* @summary Marks a property as the model's primary key with automatic sequence generation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/identity/decorators.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/identity/decorators.ts"],"names":[],"mappings":";;AA8DA,gCAmCC;AAED,sBAyDC;AAsBD,gBAaC;AA/LD,yEAAiE;AACjE,yEAGuC;AACvC,2DAMiC;AACjC,0DAA4C;AAE5C,6DAAyD;AACzD,qDAM8B;AAG9B,MAAM,iBAAiB,GAAG,EAAE,CAAC,CAAC,uEAAuE;AAErG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACI,KAAK,UAAU,UAAU,CAM9B,OAAqB,EACrB,IAAO,EACP,GAAY,EACZ,KAAQ;IAER,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAChD,OAAO;IACT,CAAC;IAED,MAAM,kBAAkB,GAAG,UACzB,MAAS,EACT,WAAmB,EACnB,KAA+B;QAE/B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC;IAEF,IAAI,CAAC,IAAI,CAAC,IAAI;QAAE,IAAI,CAAC,IAAI,GAAG,4BAAK,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5D,IAAI,QAAkB,CAAC;IACvB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,MAAM,IAAI,6BAAa,CACrB,kCAAkC,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CACpD,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,QAA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sBAAM,CAAC,EAAE,CAAC;SAC7B,MAAM,CAAC;QACN,SAAS,EAAE,KAAK;QAChB,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAC;KAC9C,CAAC;SACD,KAAK,EAAE,CAAC;AACb,CAAC"}
|
package/lib/index.cjs
CHANGED
|
@@ -44,7 +44,7 @@ __exportStar(require("./ram/index.cjs"), exports);
|
|
|
44
44
|
* @const VERSION
|
|
45
45
|
* @memberOf module:core
|
|
46
46
|
*/
|
|
47
|
-
exports.VERSION = "0.7.
|
|
47
|
+
exports.VERSION = "0.7.9";
|
|
48
48
|
/**
|
|
49
49
|
* @description Stores the current package version
|
|
50
50
|
* @summary A constant representing the version of the core package
|
package/lib/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export * from "./ram";
|
|
|
20
20
|
* @const VERSION
|
|
21
21
|
* @memberOf module:core
|
|
22
22
|
*/
|
|
23
|
-
export declare const VERSION = "0.7.
|
|
23
|
+
export declare const VERSION = "0.7.9";
|
|
24
24
|
/**
|
|
25
25
|
* @description Stores the current package version
|
|
26
26
|
* @summary A constant representing the version of the core package
|
|
@@ -16,5 +16,5 @@ export interface Paginatable<M extends Model, R, Q> {
|
|
|
16
16
|
* @param {number} size - The number of items per page
|
|
17
17
|
* @return {Promise<Paginator>} A promise that resolves to a paginator for the specified model, result, and query types
|
|
18
18
|
*/
|
|
19
|
-
paginate(size: number): Promise<Paginator<M, R, Q>>;
|
|
19
|
+
paginate(size: number, ...args: any[]): Promise<Paginator<M, R, Q>>;
|
|
20
20
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Type of the sequence configuration options type property
|
|
3
|
+
* @summary Type of the sequence configuration options type property
|
|
4
|
+
* @interface SequenceOptionsType
|
|
5
|
+
* @memberOf module:core
|
|
6
|
+
*/
|
|
7
|
+
export type SequenceOptionsType = "Number" | "BigInt" | "String" | string | "serial" | "uuid" | StringConstructor | NumberConstructor | BigIntConstructor | undefined;
|
|
1
8
|
/**
|
|
2
9
|
* @description Interface for sequence configuration options
|
|
3
10
|
* @summary Defines the configuration options for creating and managing sequences
|
|
4
11
|
* @interface SequenceOptions
|
|
5
12
|
* @memberOf module:core
|
|
6
13
|
*/
|
|
7
|
-
export interface SequenceOptions<TYPE =
|
|
14
|
+
export interface SequenceOptions<TYPE = SequenceOptionsType> {
|
|
8
15
|
/**
|
|
9
16
|
* @description Optional name for the sequence
|
|
10
17
|
* @summary A unique identifier for the sequence
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SequenceOptions.js","sourceRoot":"","sources":["../../src/interfaces/SequenceOptions.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SequenceOptions.js","sourceRoot":"","sources":["../../src/interfaces/SequenceOptions.ts"],"names":[],"mappings":";;;AAsEA;;;;;GAKG;AACU,QAAA,mBAAmB,GAAoB;IAClD,IAAI,EAAE,SAAS;IACf,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,CAAC;IACZ,WAAW,EAAE,CAAC;IACd,KAAK,EAAE,KAAK;CACb,CAAC;AAEF;;;;;GAKG;AACU,QAAA,sBAAsB,GAAoB,2BAAmB,CAAC;AAE3E;;;;;GAKG;AACU,QAAA,eAAe,GAAoB;IAC9C,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,CAAC;IACZ,WAAW,EAAE,CAAC;IACd,KAAK,EAAE,KAAK;CACb,CAAC;AAEF;;;;;GAKG;AACU,QAAA,cAAc,GAAoB,MAAM,CAAC,MAAM,CAC1D,EAAE,EACF,uBAAe,EACf;IACE,IAAI,EAAE,QAAQ;CACf,CACF,CAAC"}
|
|
@@ -108,14 +108,17 @@ class Sequence extends ContextualLoggedClass_1.ContextualLoggedClass {
|
|
|
108
108
|
const toIncrementBy = count || incrementBy;
|
|
109
109
|
if (toIncrementBy % incrementBy !== 0)
|
|
110
110
|
throw new db_decorators_1.InternalError(`Value to increment does not consider the incrementBy setting: ${incrementBy}`);
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const typeName = typeof type === "function" && type?.name
|
|
112
|
+
? type.name
|
|
113
|
+
: type;
|
|
114
|
+
switch (typeName) {
|
|
115
|
+
case Number.name:
|
|
113
116
|
next = this.parse(current) + toIncrementBy;
|
|
114
117
|
break;
|
|
115
|
-
case
|
|
118
|
+
case BigInt.name:
|
|
116
119
|
next = this.parse(current) + BigInt(toIncrementBy);
|
|
117
120
|
break;
|
|
118
|
-
case
|
|
121
|
+
case String.name:
|
|
119
122
|
next = this.parse(current);
|
|
120
123
|
break;
|
|
121
124
|
case "serial":
|
|
@@ -179,7 +182,13 @@ class Sequence extends ContextualLoggedClass_1.ContextualLoggedClass {
|
|
|
179
182
|
for (let i = 1; i <= count; i++) {
|
|
180
183
|
range.push(current + incrementBy * this.parse(i));
|
|
181
184
|
}
|
|
182
|
-
if (
|
|
185
|
+
if (this.options.type === "uuid" || this.options.type === "serial")
|
|
186
|
+
throw new errors_1.UnsupportedError(`type ${this.options.type} is currently not suppported for this adapter`);
|
|
187
|
+
const typeName = typeof this.options.type === "function" &&
|
|
188
|
+
this.options.type?.name
|
|
189
|
+
? this.options.type.name
|
|
190
|
+
: this.options.type;
|
|
191
|
+
if (range[range.length - 1] !== next && typeName !== "String")
|
|
183
192
|
throw new db_decorators_1.InternalError("Miscalculation of range");
|
|
184
193
|
return range;
|
|
185
194
|
}
|
|
@@ -204,17 +213,21 @@ class Sequence extends ContextualLoggedClass_1.ContextualLoggedClass {
|
|
|
204
213
|
* @return {string|number|bigint} The converted value
|
|
205
214
|
*/
|
|
206
215
|
static parseValue(type, value) {
|
|
207
|
-
|
|
208
|
-
|
|
216
|
+
const typeName = typeof type === "function" && type?.name
|
|
217
|
+
? type.name
|
|
218
|
+
: type;
|
|
219
|
+
switch (typeName) {
|
|
220
|
+
case Number.name || Number.name.toLowerCase():
|
|
209
221
|
return typeof value === "string"
|
|
210
222
|
? parseInt(value)
|
|
211
223
|
: typeof value === "number"
|
|
212
224
|
? value
|
|
213
225
|
: BigInt(value);
|
|
214
|
-
case
|
|
226
|
+
case BigInt.name || BigInt.name.toLowerCase():
|
|
215
227
|
return BigInt(value);
|
|
228
|
+
case String.name || String.name.toLowerCase():
|
|
229
|
+
return value.toString();
|
|
216
230
|
case undefined:
|
|
217
|
-
case "String":
|
|
218
231
|
case "uuid":
|
|
219
232
|
case "serial":
|
|
220
233
|
return value;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
import { SequenceOptions } from "../interfaces/SequenceOptions";
|
|
2
|
+
import { SequenceOptions, SequenceOptionsType } from "../interfaces/SequenceOptions";
|
|
3
3
|
import { Constructor } from "@decaf-ts/decoration";
|
|
4
4
|
import { Context } from "@decaf-ts/db-decorators";
|
|
5
5
|
import { ContextualLoggedClass, MaybeContextualArg } from "../utils/ContextualLoggedClass";
|
|
@@ -109,5 +109,5 @@ export declare class Sequence extends ContextualLoggedClass<any> {
|
|
|
109
109
|
* @param {string|number|bigint} value - The value to convert
|
|
110
110
|
* @return {string|number|bigint} The converted value
|
|
111
111
|
*/
|
|
112
|
-
static parseValue(type:
|
|
112
|
+
static parseValue(type: SequenceOptionsType, value: string | number | bigint): string | number | bigint;
|
|
113
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sequence.js","sourceRoot":"","sources":["../../src/persistence/Sequence.ts"],"names":[],"mappings":";;;AAAA,yEAAuD;
|
|
1
|
+
{"version":3,"file":"Sequence.js","sourceRoot":"","sources":["../../src/persistence/Sequence.ts"],"names":[],"mappings":";;;AAAA,yEAAuD;AAKvD,yCAA4C;AAE5C,2DAMiC;AACjC,gFAGwC;AACxC,2CAAoC;AACpC,+DAA4D;AAC5D,gEAAuD;AACvD,iDAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAC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Q,EAAE,CAAC;YAC1B,KAAK,SAAS,CAAC;YACf,KAAK,MAAM,CAAC;YACZ,KAAK,QAAQ;gBACX,OAAO,KAAK,CAAC;YACf;gBACE,MAAM,IAAI,yBAAgB,CACxB,8BAA8B,IAAI,gBAAgB,IAAI,EAAE,CACzD,CAAC;QACN,CAAC;IACH,CAAC;CACF;AApPD,4BAoPC;AAED,iBAAO,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC"}
|
|
@@ -51,5 +51,7 @@ var PersistenceKeys;
|
|
|
51
51
|
PersistenceKeys["NO_VALIDATE"] = "no-validate";
|
|
52
52
|
/** @description Key for migration classes */
|
|
53
53
|
PersistenceKeys["MIGRATION"] = "migration";
|
|
54
|
+
PersistenceKeys["STATEMENT"] = "statement";
|
|
55
|
+
PersistenceKeys["QUERY"] = "query";
|
|
54
56
|
})(PersistenceKeys || (exports.PersistenceKeys = PersistenceKeys = {}));
|
|
55
57
|
//# sourceMappingURL=constants.js.map
|
|
@@ -44,5 +44,7 @@ export declare enum PersistenceKeys {
|
|
|
44
44
|
/** @description Key for populate metadata */
|
|
45
45
|
NO_VALIDATE = "no-validate",
|
|
46
46
|
/** @description Key for migration classes */
|
|
47
|
-
MIGRATION = "migration"
|
|
47
|
+
MIGRATION = "migration",
|
|
48
|
+
STATEMENT = "statement",
|
|
49
|
+
QUERY = "query"
|
|
48
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/persistence/constants.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,IAAY,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/persistence/constants.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,IAAY,eA8DX;AA9DD,WAAY,eAAe;IACzB,0CAA0C;IAC1C,kCAAe,CAAA;IAEf,sDAAsD;IACtD,oCAAiB,CAAA;IAEjB,4CAA4C;IAC5C,sCAAmB,CAAA;IAEnB,yDAAyD;IACzD,2DAAwC,CAAA;IAExC,sCAAmB,CAAA;IACnB,+CAA+C;IAC/C,kCAAe,CAAA;IAEf,gDAAgD;IAChD,oCAAiB,CAAA;IAEjB,oDAAoD;IACpD,0CAAuB,CAAA;IAEvB,YAAY;IACZ,yDAAyD;IACzD,0CAAuB,CAAA;IAEvB,yDAAyD;IACzD,sDAAsC,CAAA;IAEtC,yDAAyD;IACzD,sDAAsC,CAAA;IAEtC,YAAY;IAEZ,sDAAsD;IACtD,4CAAyB,CAAA;IAEzB,sDAAsD;IACtD,wCAAqB,CAAA;IAErB,wDAAwD;IACxD,qDAAqC,CAAA;IAErC,yDAAyD;IACzD,uDAAuC,CAAA;IAEvC,yDAAyD;IACzD,uDAAuC,CAAA;IACvC,yDAAyD;IACzD,yDAAyC,CAAA;IAEzC,6CAA6C;IAC7C,wCAAqB,CAAA;IACrB,6CAA6C;IAC7C,8CAA2B,CAAA;IAC3B,6CAA6C;IAC7C,0CAAuB,CAAA;IAEvB,0CAAuB,CAAA;IAEvB,kCAAe,CAAA;AACjB,CAAC,EA9DW,eAAe,+BAAf,eAAe,QA8D1B"}
|
package/lib/query/decorators.cjs
CHANGED
|
@@ -1,48 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepared = prepared;
|
|
3
4
|
exports.query = query;
|
|
4
5
|
const MethodQueryBuilder_1 = require("./MethodQueryBuilder.cjs");
|
|
5
6
|
const errors_1 = require("./errors.cjs");
|
|
7
|
+
const decoration_1 = require("@decaf-ts/decoration");
|
|
8
|
+
const constants_1 = require("./../persistence/constants.cjs");
|
|
9
|
+
function prepared() {
|
|
10
|
+
function prepared() {
|
|
11
|
+
return function prepared(obj, prop, descriptor) {
|
|
12
|
+
return (0, decoration_1.apply)((0, decoration_1.methodMetadata)(decoration_1.Metadata.key(constants_1.PersistenceKeys.STATEMENT, prop), true))(obj, prop, descriptor);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return decoration_1.Decoration.for(constants_1.PersistenceKeys.STATEMENT)
|
|
16
|
+
.define({
|
|
17
|
+
decorator: prepared,
|
|
18
|
+
args: [],
|
|
19
|
+
})
|
|
20
|
+
.apply();
|
|
21
|
+
}
|
|
6
22
|
function query(options = {}) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
function query(options) {
|
|
24
|
+
return function query(obj, prop, descriptor) {
|
|
25
|
+
function innerQuery(options) {
|
|
26
|
+
return function innerQuery(obj, propertyKey, descriptor) {
|
|
27
|
+
descriptor.value = new Proxy(descriptor.value, {
|
|
28
|
+
apply(target, thisArg, args) {
|
|
29
|
+
const { select, where, groupBy, orderBy, limit, offset } = MethodQueryBuilder_1.MethodQueryBuilder.build(target.name, ...args);
|
|
30
|
+
let stmt = thisArg.select(select);
|
|
31
|
+
if (where)
|
|
32
|
+
stmt = stmt.where(where);
|
|
33
|
+
// if (orderBy) stmt = stmt.orderBy(orderBy[0]);
|
|
34
|
+
if (groupBy) {
|
|
35
|
+
// group by not implemented yet
|
|
36
|
+
/* stmt = stmt.groupBy(groupBy); */
|
|
37
|
+
}
|
|
38
|
+
// allow limit and offset by default
|
|
39
|
+
const { allowLimit, allowOffset, allowOrderBy, throws } = {
|
|
40
|
+
allowLimit: true,
|
|
41
|
+
allowOrderBy: true,
|
|
42
|
+
allowOffset: true,
|
|
43
|
+
throws: true,
|
|
44
|
+
...options,
|
|
45
|
+
};
|
|
46
|
+
const params = [
|
|
47
|
+
// keep the order to ensure the expected behavior
|
|
48
|
+
{
|
|
49
|
+
key: "orderBy",
|
|
50
|
+
value: (orderBy || [])[0],
|
|
51
|
+
allowed: allowOrderBy,
|
|
52
|
+
}, // orderBy only supports one sentence
|
|
53
|
+
{ key: "limit", value: limit, allowed: allowLimit },
|
|
54
|
+
{ key: "offset", value: offset, allowed: allowOffset },
|
|
55
|
+
];
|
|
56
|
+
for (const param of params) {
|
|
57
|
+
if (param.value !== undefined) {
|
|
58
|
+
if (!param.allowed && throws) {
|
|
59
|
+
throw new errors_1.QueryError(`${param.key[0].toUpperCase() + param.key.slice(1)} is not allowed for this query`);
|
|
60
|
+
}
|
|
61
|
+
else if (param.allowed) {
|
|
62
|
+
stmt = stmt[param.key](param.value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return stmt.execute();
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
};
|
|
43
70
|
}
|
|
44
|
-
return
|
|
71
|
+
return (0, decoration_1.apply)((0, decoration_1.methodMetadata)(decoration_1.Metadata.key(constants_1.PersistenceKeys.QUERY, prop), options), prepared(), innerQuery(options))(obj, prop, descriptor);
|
|
45
72
|
};
|
|
46
|
-
}
|
|
73
|
+
}
|
|
74
|
+
return decoration_1.Decoration.for(constants_1.PersistenceKeys.QUERY)
|
|
75
|
+
.define({
|
|
76
|
+
decorator: query,
|
|
77
|
+
args: [options],
|
|
78
|
+
})
|
|
79
|
+
.apply();
|
|
47
80
|
}
|
|
48
81
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { QueryOptions } from "./types";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function prepared(): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
3
|
+
export declare function query(options?: QueryOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/query/decorators.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/query/decorators.ts"],"names":[],"mappings":";;AAWA,4BAcC;AAED,sBA6EC;AAvGD,iEAA0D;AAC1D,yCAAsC;AACtC,qDAK8B;AAC9B,8DAA2D;AAE3D,SAAgB,QAAQ;IACtB,SAAS,QAAQ;QACf,OAAO,SAAS,QAAQ,CAAC,GAAW,EAAE,IAAU,EAAE,UAAgB;YAChE,OAAO,IAAA,kBAAK,EACV,IAAA,2BAAc,EAAC,qBAAQ,CAAC,GAAG,CAAC,2BAAe,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CACpE,CAAC,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,uBAAU,CAAC,GAAG,CAAC,2BAAe,CAAC,SAAS,CAAC;SAC7C,MAAM,CAAC;QACN,SAAS,EAAE,QAAQ;QACnB,IAAI,EAAE,EAAE;KACT,CAAC;SACD,KAAK,EAAE,CAAC;AACb,CAAC;AAED,SAAgB,KAAK,CAAC,UAAwB,EAAE;IAC9C,SAAS,KAAK,CAAC,OAAqB;QAClC,OAAO,SAAS,KAAK,CAAC,GAAW,EAAE,IAAU,EAAE,UAAgB;YAC7D,SAAS,UAAU,CAAC,OAAqB;gBACvC,OAAO,SAAS,UAAU,CACxB,GAAQ,EACR,WAAiB,EACjB,UAAgB;oBAEf,UAA2C,CAAC,KAAK,GAAG,IAAI,KAAK,CAC3D,UAA2C,CAAC,KAAK,EAClD;wBACE,KAAK,CAAC,MAAW,EAAE,OAAY,EAAE,IAAW;4BAC1C,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EA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,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,gCAAgC,CACnF,CAAC;oCACJ,CAAC;yCAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;wCACzB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oCACtC,CAAC;gCACH,CAAC;4BACH,CAAC;4BAED,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;wBACxB,CAAC;qBACF,CACF,CAAC;gBACJ,CAAC,CAAC;YACJ,CAAC;YAED,OAAO,IAAA,kBAAK,EACV,IAAA,2BAAc,EAAC,qBAAQ,CAAC,GAAG,CAAC,2BAAe,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,EAClE,QAAQ,EAAE,EACV,UAAU,CAAC,OAAO,CAAC,CACpB,CAAC,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,uBAAU,CAAC,GAAG,CAAC,2BAAe,CAAC,KAAK,CAAC;SACzC,MAAM,CAAC;QACN,SAAS,EAAE,KAAK;QAChB,IAAI,EAAE,CAAC,OAAO,CAAC;KAChB,CAAC;SACD,KAAK,EAAE,CAAC;AACb,CAAC"}
|
|
@@ -19,6 +19,8 @@ const Condition_1 = require("./../query/Condition.cjs");
|
|
|
19
19
|
const ObserverHandler_1 = require("./../persistence/ObserverHandler.cjs");
|
|
20
20
|
const logging_1 = require("@decaf-ts/logging");
|
|
21
21
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
22
|
+
const errors_1 = require("./../query/errors.cjs");
|
|
23
|
+
const decorators_1 = require("./../query/decorators.cjs");
|
|
22
24
|
/**
|
|
23
25
|
* @description Core repository implementation for database operations on models on a table by table way.
|
|
24
26
|
* @summary Provides CRUD operations, querying capabilities, and observer pattern implementation for model persistence.
|
|
@@ -534,6 +536,38 @@ class Repository extends db_decorators_1.Repository {
|
|
|
534
536
|
query.offset(skip);
|
|
535
537
|
return query.execute();
|
|
536
538
|
}
|
|
539
|
+
async listBy(key, order, ...args) {
|
|
540
|
+
const contextArgs = await db_decorators_1.Context.args("list", this.class, args, this.adapter, this._overrides || {});
|
|
541
|
+
const { log, ctxArgs } = this.logCtx(contextArgs.args, this.listBy);
|
|
542
|
+
log.verbose(`listing ${decorator_validation_1.Model.tableName(this.class)} by ${key} ${order}`);
|
|
543
|
+
return this.select()
|
|
544
|
+
.orderBy([key, order])
|
|
545
|
+
.execute(...ctxArgs);
|
|
546
|
+
}
|
|
547
|
+
async paginateBy(key, order, size, ...args) {
|
|
548
|
+
const contextArgs = await db_decorators_1.Context.args("paginateBy", this.class, args, this.adapter, this._overrides || {});
|
|
549
|
+
const { log, ctxArgs } = this.logCtx(contextArgs.args, this.paginateBy);
|
|
550
|
+
log.verbose(`paginating ${decorator_validation_1.Model.tableName(this.class)} with page size ${size}`);
|
|
551
|
+
return this.select()
|
|
552
|
+
.orderBy([key, order])
|
|
553
|
+
.paginate(size, ...ctxArgs);
|
|
554
|
+
}
|
|
555
|
+
async findOneBy(key, value, ...args) {
|
|
556
|
+
const contextArgs = await db_decorators_1.Context.args("findOneBy", this.class, args, this.adapter, this._overrides || {});
|
|
557
|
+
const { log, ctxArgs } = this.logCtx(contextArgs.args, this.findOneBy);
|
|
558
|
+
log.verbose(`finding ${decorator_validation_1.Model.tableName(this.class)} with ${key} ${value}`);
|
|
559
|
+
return this.select()
|
|
560
|
+
.where(this.attr(key).eq(value))
|
|
561
|
+
.execute(...ctxArgs);
|
|
562
|
+
}
|
|
563
|
+
async statement(name, ...args) {
|
|
564
|
+
if (!Repository.statements(this, name))
|
|
565
|
+
throw new errors_1.QueryError(`Invalid prepared statement requested ${name}`);
|
|
566
|
+
const contextArgs = await db_decorators_1.Context.args("statement", this.class, args, this.adapter, this._overrides || {});
|
|
567
|
+
const { log, ctxArgs } = this.logCtx(contextArgs.args, this.statement);
|
|
568
|
+
log.verbose(`Executing prepared statement ${name}`);
|
|
569
|
+
return this[name](...ctxArgs);
|
|
570
|
+
}
|
|
537
571
|
attr(prop) {
|
|
538
572
|
return Condition_1.Condition.attr(prop);
|
|
539
573
|
}
|
|
@@ -696,8 +730,39 @@ class Repository extends db_decorators_1.Repository {
|
|
|
696
730
|
}
|
|
697
731
|
this._cache[name] = repo;
|
|
698
732
|
}
|
|
733
|
+
static statements(repo, method) {
|
|
734
|
+
const contr = repo instanceof Repository ? repo.constructor : repo;
|
|
735
|
+
const meta = decoration_1.Metadata.get(contr, method
|
|
736
|
+
? decoration_1.Metadata.key(constants_1.PersistenceKeys.STATEMENT, method)
|
|
737
|
+
: constants_1.PersistenceKeys.STATEMENT);
|
|
738
|
+
return (method ? meta : Object.keys(meta)) || false;
|
|
739
|
+
}
|
|
740
|
+
static queries(repo, method) {
|
|
741
|
+
const contr = repo instanceof Repository ? repo.constructor : repo;
|
|
742
|
+
return decoration_1.Metadata.get(contr, method
|
|
743
|
+
? decoration_1.Metadata.key(constants_1.PersistenceKeys.QUERY, method)
|
|
744
|
+
: constants_1.PersistenceKeys.QUERY);
|
|
745
|
+
}
|
|
699
746
|
}
|
|
700
747
|
exports.Repository = Repository;
|
|
748
|
+
__decorate([
|
|
749
|
+
(0, decorators_1.prepared)(),
|
|
750
|
+
__metadata("design:type", Function),
|
|
751
|
+
__metadata("design:paramtypes", [Object, String, void 0]),
|
|
752
|
+
__metadata("design:returntype", Promise)
|
|
753
|
+
], Repository.prototype, "listBy", null);
|
|
754
|
+
__decorate([
|
|
755
|
+
(0, decorators_1.prepared)(),
|
|
756
|
+
__metadata("design:type", Function),
|
|
757
|
+
__metadata("design:paramtypes", [Object, String, Number, void 0]),
|
|
758
|
+
__metadata("design:returntype", Promise)
|
|
759
|
+
], Repository.prototype, "paginateBy", null);
|
|
760
|
+
__decorate([
|
|
761
|
+
(0, decorators_1.prepared)(),
|
|
762
|
+
__metadata("design:type", Function),
|
|
763
|
+
__metadata("design:paramtypes", [Object, Object, void 0]),
|
|
764
|
+
__metadata("design:returntype", Promise)
|
|
765
|
+
], Repository.prototype, "findOneBy", null);
|
|
701
766
|
__decorate([
|
|
702
767
|
(0, logging_1.final)(),
|
|
703
768
|
__metadata("design:type", Function),
|
|
@@ -3,16 +3,17 @@ import { type Observer } from "../interfaces/Observer";
|
|
|
3
3
|
import { Adapter } from "../persistence/Adapter";
|
|
4
4
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
5
5
|
import { OrderDirection } from "./constants";
|
|
6
|
-
import { SequenceOptions } from "../interfaces/SequenceOptions";
|
|
6
|
+
import { type SequenceOptions } from "../interfaces/SequenceOptions";
|
|
7
7
|
import { Queriable } from "../interfaces/Queriable";
|
|
8
8
|
import { Condition } from "../query/Condition";
|
|
9
9
|
import { WhereOption } from "../query/options";
|
|
10
10
|
import { SelectSelector } from "../query/selectors";
|
|
11
11
|
import { ObserverHandler } from "../persistence/ObserverHandler";
|
|
12
|
-
import { ContextOf, EventIds, FlagsOf, InferredAdapterConfig, type ObserverFilter, PersistenceObservable, PersistenceObserver } from "../persistence/types";
|
|
12
|
+
import { type ContextOf, EventIds, type FlagsOf, type InferredAdapterConfig, type ObserverFilter, PersistenceObservable, PersistenceObserver } from "../persistence/types";
|
|
13
13
|
import { Constructor } from "@decaf-ts/decoration";
|
|
14
|
-
import { Logger } from "@decaf-ts/logging";
|
|
15
|
-
import { ContextualizedArgs, MaybeContextualArg } from "../utils/ContextualLoggedClass";
|
|
14
|
+
import type { Logger } from "@decaf-ts/logging";
|
|
15
|
+
import type { ContextualizedArgs, MaybeContextualArg } from "../utils/ContextualLoggedClass";
|
|
16
|
+
import { type QueryOptions } from "../query/types";
|
|
16
17
|
/**
|
|
17
18
|
* @description Type alias for Repository class with simplified generic parameters.
|
|
18
19
|
* @summary Provides a more concise way to reference the Repository class with its generic parameters.
|
|
@@ -311,6 +312,10 @@ export declare class Repository<M extends Model<boolean>, A extends Adapter<any,
|
|
|
311
312
|
* @return {Promise<M[]>} The query results as model instances.
|
|
312
313
|
*/
|
|
313
314
|
query(condition: Condition<M>, orderBy: keyof M, order?: OrderDirection, limit?: number, skip?: number): Promise<M[]>;
|
|
315
|
+
listBy(key: keyof M, order: OrderDirection, ...args: MaybeContextualArg<ContextOf<A>>): Promise<M[]>;
|
|
316
|
+
paginateBy(key: keyof M, order: OrderDirection, size: number, ...args: MaybeContextualArg<ContextOf<A>>): Promise<import("..").Paginator<M, M[], any>>;
|
|
317
|
+
findOneBy(key: keyof M, value: any, ...args: MaybeContextualArg<ContextOf<A>>): Promise<M[]>;
|
|
318
|
+
statement(name: string, ...args: MaybeContextualArg<ContextOf<A>>): Promise<any>;
|
|
314
319
|
attr(prop: keyof M): import("../query/options").AttributeOption<M>;
|
|
315
320
|
/**
|
|
316
321
|
* @description Registers an observer for this repository.
|
|
@@ -383,4 +388,6 @@ export declare class Repository<M extends Model<boolean>, A extends Adapter<any,
|
|
|
383
388
|
* @throws {InternalError} If a repository is already registered for the model.
|
|
384
389
|
*/
|
|
385
390
|
static register<M extends Model>(model: Constructor<M>, repo: Constructor<Repo<M>> | Repo<M>, alias?: string): void;
|
|
391
|
+
static statements<R extends Repository<any, any>, K extends keyof R>(repo: Constructor<R> | R, method?: K): undefined | (K extends keyof R ? boolean : (keyof R)[]);
|
|
392
|
+
static queries<R extends Repository<any, any>, K extends keyof R>(repo: Constructor<R> | R, method?: K): undefined | (K extends keyof R ? QueryOptions : Record<keyof R, QueryOptions>);
|
|
386
393
|
}
|