@decaf-ts/core 0.6.0 → 0.7.1
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.js +6 -5
- package/lib/esm/identity/decorators.js.map +1 -1
- package/lib/esm/identity/utils.d.ts +3 -2
- package/lib/esm/identity/utils.js +7 -7
- package/lib/esm/identity/utils.js.map +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/model/construction.d.ts +2 -11
- package/lib/esm/model/construction.js +21 -33
- package/lib/esm/model/construction.js.map +1 -1
- package/lib/esm/model/decorators.d.ts +11 -2
- package/lib/esm/model/decorators.js +91 -69
- package/lib/esm/model/decorators.js.map +1 -1
- package/lib/esm/model/types.d.ts +6 -2
- package/lib/esm/overrides/Metadata.d.ts +14 -2
- package/lib/esm/overrides/overrides.js +31 -0
- package/lib/esm/overrides/overrides.js.map +1 -1
- package/lib/esm/persistence/Adapter.d.ts +3 -9
- package/lib/esm/persistence/Adapter.js +27 -46
- package/lib/esm/persistence/Adapter.js.map +1 -1
- package/lib/esm/persistence/Sequence.d.ts +2 -1
- package/lib/esm/persistence/Sequence.js.map +1 -1
- package/lib/esm/persistence/index.d.ts +0 -1
- package/lib/esm/persistence/index.js +0 -1
- package/lib/esm/persistence/index.js.map +1 -1
- package/lib/esm/persistence/migrations.js +1 -2
- package/lib/esm/persistence/migrations.js.map +1 -1
- package/lib/esm/query/Paginator.d.ts +4 -2
- package/lib/esm/query/Paginator.js +3 -1
- package/lib/esm/query/Paginator.js.map +1 -1
- package/lib/esm/query/Statement.d.ts +2 -1
- package/lib/esm/query/Statement.js +2 -2
- package/lib/esm/query/Statement.js.map +1 -1
- package/lib/esm/query/options.d.ts +2 -1
- package/lib/esm/query/selectors.d.ts +2 -1
- package/lib/esm/ram/RamAdapter.d.ts +2 -1
- package/lib/esm/ram/RamAdapter.js +7 -5
- package/lib/esm/ram/RamAdapter.js.map +1 -1
- package/lib/esm/ram/RamPaginator.d.ts +2 -1
- package/lib/esm/ram/RamPaginator.js +1 -1
- package/lib/esm/ram/RamPaginator.js.map +1 -1
- package/lib/esm/ram/RamStatement.js +3 -3
- package/lib/esm/ram/RamStatement.js.map +1 -1
- package/lib/esm/ram/types.d.ts +2 -1
- package/lib/esm/repository/Repository.d.ts +2 -1
- package/lib/esm/repository/Repository.js +30 -40
- package/lib/esm/repository/Repository.js.map +1 -1
- package/lib/esm/repository/decorators.d.ts +2 -1
- package/lib/esm/repository/decorators.js +7 -8
- package/lib/esm/repository/decorators.js.map +1 -1
- package/lib/esm/repository/injectables.d.ts +1 -2
- package/lib/esm/repository/injectables.js +6 -6
- package/lib/esm/repository/injectables.js.map +1 -1
- package/lib/esm/repository/utils.d.ts +2 -2
- package/lib/esm/repository/utils.js +4 -5
- package/lib/esm/repository/utils.js.map +1 -1
- package/lib/identity/decorators.cjs +6 -5
- package/lib/identity/decorators.js.map +1 -1
- package/lib/identity/utils.cjs +5 -5
- package/lib/identity/utils.d.ts +3 -2
- package/lib/identity/utils.js.map +1 -1
- package/lib/index.cjs +2 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js.map +1 -1
- package/lib/model/construction.cjs +19 -31
- package/lib/model/construction.d.ts +2 -11
- package/lib/model/construction.js.map +1 -1
- package/lib/model/decorators.cjs +99 -76
- package/lib/model/decorators.d.ts +11 -2
- package/lib/model/decorators.js.map +1 -1
- package/lib/model/types.d.ts +6 -2
- package/lib/overrides/Metadata.d.ts +14 -2
- package/lib/overrides/overrides.cjs +31 -0
- package/lib/overrides/overrides.js.map +1 -1
- package/lib/persistence/Adapter.cjs +25 -44
- package/lib/persistence/Adapter.d.ts +3 -9
- package/lib/persistence/Adapter.js.map +1 -1
- package/lib/persistence/Sequence.d.ts +2 -1
- package/lib/persistence/Sequence.js.map +1 -1
- package/lib/persistence/index.cjs +0 -1
- package/lib/persistence/index.d.ts +0 -1
- package/lib/persistence/index.js.map +1 -1
- package/lib/persistence/migrations.cjs +1 -2
- package/lib/persistence/migrations.js.map +1 -1
- package/lib/query/Paginator.cjs +3 -1
- package/lib/query/Paginator.d.ts +4 -2
- package/lib/query/Paginator.js.map +1 -1
- package/lib/query/Statement.cjs +1 -1
- package/lib/query/Statement.d.ts +2 -1
- package/lib/query/Statement.js.map +1 -1
- package/lib/query/options.d.ts +2 -1
- package/lib/query/selectors.d.ts +2 -1
- package/lib/ram/RamAdapter.cjs +9 -7
- package/lib/ram/RamAdapter.d.ts +2 -1
- package/lib/ram/RamAdapter.js.map +1 -1
- package/lib/ram/RamPaginator.cjs +1 -1
- package/lib/ram/RamPaginator.d.ts +2 -1
- package/lib/ram/RamPaginator.js.map +1 -1
- package/lib/ram/RamStatement.cjs +3 -3
- package/lib/ram/RamStatement.js.map +1 -1
- package/lib/ram/types.d.ts +2 -1
- package/lib/repository/Repository.cjs +29 -39
- package/lib/repository/Repository.d.ts +2 -1
- package/lib/repository/Repository.js.map +1 -1
- package/lib/repository/decorators.cjs +5 -6
- package/lib/repository/decorators.d.ts +2 -1
- package/lib/repository/decorators.js.map +1 -1
- package/lib/repository/injectables.cjs +5 -5
- package/lib/repository/injectables.d.ts +1 -2
- package/lib/repository/injectables.js.map +1 -1
- package/lib/repository/utils.cjs +4 -5
- package/lib/repository/utils.d.ts +2 -2
- package/lib/repository/utils.js.map +1 -1
- package/package.json +2 -4
- package/lib/esm/persistence/decorators.d.ts +0 -11
- package/lib/esm/persistence/decorators.js +0 -19
- package/lib/esm/persistence/decorators.js.map +0 -1
- package/lib/persistence/decorators.cjs +0 -22
- package/lib/persistence/decorators.d.ts +0 -11
- package/lib/persistence/decorators.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
3
|
/**
|
|
3
4
|
* @description Gets the table name for a model
|
|
4
5
|
* @summary Retrieves the table name associated with a model by checking metadata or falling back to the constructor name
|
|
@@ -9,7 +10,7 @@ import { Constructor, Model } from "@decaf-ts/decorator-validation";
|
|
|
9
10
|
* @memberOf module:core
|
|
10
11
|
*/
|
|
11
12
|
export declare function getTableName<M extends Model>(model: M | Constructor<M>): string;
|
|
12
|
-
export declare function getColumnName<M extends Model>(model: M
|
|
13
|
+
export declare function getColumnName<M extends Model>(model: M | Constructor<M>, attribute: string): string;
|
|
13
14
|
/**
|
|
14
15
|
* @description Generates a sequence name for a model
|
|
15
16
|
* @summary Creates a standardized sequence name by combining the table name with additional arguments
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Model
|
|
2
|
-
import { InternalError
|
|
1
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { InternalError } from "@decaf-ts/db-decorators";
|
|
3
3
|
import { PersistenceKeys } from "./../persistence/constants.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Metadata } from "@decaf-ts/decoration";
|
|
5
5
|
/**
|
|
6
6
|
* @description Gets the table name for a model
|
|
7
7
|
* @summary Retrieves the table name associated with a model by checking metadata or falling back to the constructor name
|
|
@@ -15,9 +15,9 @@ export function getTableName(model) {
|
|
|
15
15
|
const obj = model instanceof Model ? Model.get(model.constructor.name) : model;
|
|
16
16
|
if (!obj)
|
|
17
17
|
throw new InternalError(`Unable to find model ${model}`);
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
18
|
+
const meta = Metadata.get(model instanceof Model ? model.constructor : model, PersistenceKeys.TABLE);
|
|
19
|
+
if (meta) {
|
|
20
|
+
return meta;
|
|
21
21
|
}
|
|
22
22
|
if (model instanceof Model) {
|
|
23
23
|
return model.constructor.name;
|
|
@@ -25,7 +25,7 @@ export function getTableName(model) {
|
|
|
25
25
|
return model.name;
|
|
26
26
|
}
|
|
27
27
|
export function getColumnName(model, attribute) {
|
|
28
|
-
const metadata =
|
|
28
|
+
const metadata = Metadata.get(model instanceof Model ? model.constructor : model, Metadata.key(PersistenceKeys.COLUMN, attribute));
|
|
29
29
|
return metadata ? metadata : attribute;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/identity/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/identity/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,sCAAiC;AAC3D,OAAO,EAAe,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAyB;IAEzB,MAAM,GAAG,GACP,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAErE,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,aAAa,CAAC,wBAAwB,KAAK,EAAE,CAAC,CAAC;IAEnE,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CACvB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAE,KAAa,EAC3D,eAAe,CAAC,KAAK,CACtB,CAAC;IAEF,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;IAChC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,KAAyB,EACzB,SAAiB;IAEjB,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAC3B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAE,KAAa,EAC3D,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,CAChD,CAAC;IACF,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACzC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAyB,EACzB,GAAG,IAAc;IAEjB,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -13,13 +13,14 @@ export * from "./model";
|
|
|
13
13
|
export * from "./query";
|
|
14
14
|
export * from "./utils";
|
|
15
15
|
export * from "./persistence";
|
|
16
|
+
export * from "./ram";
|
|
16
17
|
/**
|
|
17
18
|
* @description Stores the current package version
|
|
18
19
|
* @summary A constant representing the version of the core package
|
|
19
20
|
* @const VERSION
|
|
20
21
|
* @memberOf module:core
|
|
21
22
|
*/
|
|
22
|
-
export declare const VERSION = "0.
|
|
23
|
+
export declare const VERSION = "0.7.0";
|
|
23
24
|
/**
|
|
24
25
|
* @description Stores the current package version
|
|
25
26
|
* @summary A constant representing the version of the core package
|
package/lib/esm/index.js
CHANGED
|
@@ -20,13 +20,14 @@ export * from "./query/index.js";
|
|
|
20
20
|
export * from "./utils/index.js";
|
|
21
21
|
//left to last on purpose
|
|
22
22
|
export * from "./persistence/index.js";
|
|
23
|
+
export * from "./ram/index.js";
|
|
23
24
|
/**
|
|
24
25
|
* @description Stores the current package version
|
|
25
26
|
* @summary A constant representing the version of the core package
|
|
26
27
|
* @const VERSION
|
|
27
28
|
* @memberOf module:core
|
|
28
29
|
*/
|
|
29
|
-
export const VERSION = "0.
|
|
30
|
+
export const VERSION = "0.7.0";
|
|
30
31
|
/**
|
|
31
32
|
* @description Stores the current package version
|
|
32
33
|
* @summary A constant representing the version of the core package
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,oCAAiC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,kFAAkF;AAClF,WAAW,CAAC,WAAW,CAAC,IAAI,mBAAmB,EAAE,CAAC,CAAC;AAEnD,4BAA4B;AAC5B,qCAA4B;AAC5B,sCAA6B;AAE7B,oCAA2B;AAC3B,sCAA6B;AAC7B,iCAAwB;AACxB,iCAAwB;AACxB,iCAAwB;AACxB,yBAAyB;AACzB,uCAA8B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,oCAAiC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,kFAAkF;AAClF,WAAW,CAAC,WAAW,CAAC,IAAI,mBAAmB,EAAE,CAAC,CAAC;AAEnD,4BAA4B;AAC5B,qCAA4B;AAC5B,sCAA6B;AAE7B,oCAA2B;AAC3B,sCAA6B;AAC7B,iCAAwB;AACxB,iCAAwB;AACxB,iCAAwB;AACxB,yBAAyB;AACzB,uCAA8B;AAC9B,+BAAsB;AAEtB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;AAE1C,QAAQ,CAAC,eAAe,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -426,16 +426,7 @@ export declare function populate<M extends Model, R extends Repo<M, F, C>, V ext
|
|
|
426
426
|
*
|
|
427
427
|
* Caller->>repositoryFromTypeMetadata: model, propertyKey
|
|
428
428
|
*
|
|
429
|
-
* repositoryFromTypeMetadata->>
|
|
430
|
-
* Validation-->>repositoryFromTypeMetadata: validationKey
|
|
431
|
-
*
|
|
432
|
-
* repositoryFromTypeMetadata->>Reflect: getMetadata(validationKey, model, propertyKey)
|
|
433
|
-
* Reflect-->>repositoryFromTypeMetadata: types
|
|
434
|
-
*
|
|
435
|
-
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: determine customTypes based on property type
|
|
436
|
-
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if types and customTypes exist
|
|
437
|
-
*
|
|
438
|
-
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: create allowedTypes array
|
|
429
|
+
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: Get allowedTypes array
|
|
439
430
|
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: find constructorName not in commomTypes
|
|
440
431
|
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if constructorName exists
|
|
441
432
|
*
|
|
@@ -448,4 +439,4 @@ export declare function populate<M extends Model, R extends Repo<M, F, C>, V ext
|
|
|
448
439
|
*
|
|
449
440
|
* repositoryFromTypeMetadata-->>Caller: repo
|
|
450
441
|
*/
|
|
451
|
-
export declare function repositoryFromTypeMetadata<M extends Model>(model:
|
|
442
|
+
export declare function repositoryFromTypeMetadata<M extends Model>(model: M, propertyKey: keyof M, alias?: string): Repo<M>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Model,
|
|
1
|
+
import { Model, ValidationKeys, } from "@decaf-ts/decorator-validation";
|
|
2
2
|
import { Repository } from "./../repository/Repository.js";
|
|
3
|
-
import {
|
|
3
|
+
import { InternalError, NotFoundError, } from "@decaf-ts/db-decorators";
|
|
4
4
|
import { PersistenceKeys } from "./../persistence/constants.js";
|
|
5
5
|
import { Cascade } from "./../repository/constants.js";
|
|
6
|
+
import { Metadata } from "@decaf-ts/decoration";
|
|
7
|
+
import { isClass } from "@decaf-ts/logging";
|
|
6
8
|
/**
|
|
7
9
|
* @description Creates or updates a model instance
|
|
8
10
|
* @summary Determines whether to create a new model or update an existing one based on the presence of a primary key
|
|
@@ -125,14 +127,12 @@ export async function oneToOneOnCreate(context, data, key, model) {
|
|
|
125
127
|
model[key] = propertyValue;
|
|
126
128
|
return;
|
|
127
129
|
}
|
|
128
|
-
data.class
|
|
129
|
-
typeof data.class === "string" ? data.class : data.class().name;
|
|
130
|
-
const constructor = Model.get(data.class);
|
|
130
|
+
const constructor = isClass(data.class) ? data.class : data.class();
|
|
131
131
|
if (!constructor)
|
|
132
132
|
throw new InternalError(`Could not find model ${data.class}`);
|
|
133
133
|
const repo = Repository.forModel(constructor, this.adapter.alias);
|
|
134
134
|
const created = await repo.create(propertyValue);
|
|
135
|
-
const pk =
|
|
135
|
+
const pk = Model.pk(created);
|
|
136
136
|
await cacheModelForPopulate(context, model, key, created[pk], created);
|
|
137
137
|
model[key] = created[pk];
|
|
138
138
|
}
|
|
@@ -197,7 +197,7 @@ export async function oneToOneOnUpdate(context, data, key, model) {
|
|
|
197
197
|
return;
|
|
198
198
|
}
|
|
199
199
|
const updated = await createOrUpdate(model[key], context, this.adapter.alias);
|
|
200
|
-
const pk =
|
|
200
|
+
const pk = Model.pk(updated);
|
|
201
201
|
await cacheModelForPopulate(context, model, key, updated[pk], updated);
|
|
202
202
|
model[key] = updated[pk];
|
|
203
203
|
}
|
|
@@ -327,7 +327,7 @@ export async function oneToManyOnCreate(context, data, key, model) {
|
|
|
327
327
|
model[key] = [...uniqueValues];
|
|
328
328
|
return;
|
|
329
329
|
}
|
|
330
|
-
const pkName =
|
|
330
|
+
const pkName = Model.pk(propertyValues[0]);
|
|
331
331
|
const result = new Set();
|
|
332
332
|
for (const m of propertyValues) {
|
|
333
333
|
const record = await createOrUpdate(m, context, this.adapter.alias);
|
|
@@ -605,16 +605,7 @@ const commomTypes = [
|
|
|
605
605
|
*
|
|
606
606
|
* Caller->>repositoryFromTypeMetadata: model, propertyKey
|
|
607
607
|
*
|
|
608
|
-
* repositoryFromTypeMetadata->>
|
|
609
|
-
* Validation-->>repositoryFromTypeMetadata: validationKey
|
|
610
|
-
*
|
|
611
|
-
* repositoryFromTypeMetadata->>Reflect: getMetadata(validationKey, model, propertyKey)
|
|
612
|
-
* Reflect-->>repositoryFromTypeMetadata: types
|
|
613
|
-
*
|
|
614
|
-
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: determine customTypes based on property type
|
|
615
|
-
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if types and customTypes exist
|
|
616
|
-
*
|
|
617
|
-
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: create allowedTypes array
|
|
608
|
+
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: Get allowedTypes array
|
|
618
609
|
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: find constructorName not in commomTypes
|
|
619
610
|
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if constructorName exists
|
|
620
611
|
*
|
|
@@ -628,21 +619,18 @@ const commomTypes = [
|
|
|
628
619
|
* repositoryFromTypeMetadata-->>Caller: repo
|
|
629
620
|
*/
|
|
630
621
|
export function repositoryFromTypeMetadata(model, propertyKey, alias) {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
?
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
const constructor = Model.get(constructorName);
|
|
644
|
-
if (!constructor)
|
|
645
|
-
throw new InternalError(`No registered model found for ${constructorName}`);
|
|
622
|
+
if (!model)
|
|
623
|
+
throw new Error("No model was provided to get repository");
|
|
624
|
+
let allowedTypes;
|
|
625
|
+
if (Array.isArray(model[propertyKey]) || model[propertyKey] instanceof Set) {
|
|
626
|
+
const customTypes = Metadata.get(model instanceof Model ? model.constructor : model, Metadata.key(ValidationKeys.REFLECT, propertyKey, ValidationKeys.LIST))?.clazz;
|
|
627
|
+
if (!customTypes)
|
|
628
|
+
throw new InternalError(`Failed to find types decorators for property ${propertyKey}`);
|
|
629
|
+
allowedTypes = (Array.isArray(customTypes) ? [...customTypes] : [customTypes]).map((t) => (typeof t === "function" && !t.name ? t() : t));
|
|
630
|
+
}
|
|
631
|
+
else
|
|
632
|
+
allowedTypes = Metadata.getPropDesignTypes(model instanceof Model ? model.constructor : model, propertyKey)?.designTypes;
|
|
633
|
+
const constructor = allowedTypes?.find((t) => !commomTypes.includes(`${t.name}`.toLowerCase()));
|
|
646
634
|
return Repository.forModel(constructor, alias);
|
|
647
635
|
}
|
|
648
636
|
//# sourceMappingURL=construction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"construction.js","sourceRoot":"","sources":["../../../src/model/construction.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"construction.js","sourceRoot":"","sources":["../../../src/model/construction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,cAAc,GACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAQ,UAAU,EAAE,sCAAiC;AAE5D,OAAO,EACL,aAAa,EACb,aAAa,GAEd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,sCAAiC;AAC3D,OAAO,EAAE,OAAO,EAAE,qCAAgC;AAElD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;G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CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CACxD,CAAC;IAEF,OAAO,UAAU,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAQ,CAAC;AACxD,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Context, OperationKeys, RepositoryFlags } from "@decaf-ts/db-decorators";
|
|
2
|
+
import { propMetadata, Constructor } from "@decaf-ts/decoration";
|
|
2
3
|
import { CascadeMetadata } from "../repository/types";
|
|
3
4
|
import { OrderDirection } from "../repository/constants";
|
|
4
|
-
import {
|
|
5
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
5
6
|
import { Repo } from "../repository/Repository";
|
|
6
7
|
import { JoinColumnOptions, JoinTableMultipleColumnsOptions, JoinTableOptions, RelationsMetadata } from "./types";
|
|
7
8
|
/**
|
|
@@ -12,7 +13,7 @@ import { JoinColumnOptions, JoinTableMultipleColumnsOptions, JoinTableOptions, R
|
|
|
12
13
|
* @function table
|
|
13
14
|
* @category Class Decorators
|
|
14
15
|
*/
|
|
15
|
-
export declare function table<OPTS = string>(opts?: OPTS): (target: any) => any;
|
|
16
|
+
export declare function table<OPTS = string>(opts?: OPTS): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
16
17
|
/**
|
|
17
18
|
* @description Specifies the database column name for a model property
|
|
18
19
|
* @summary Decorator that maps a model property to a specific column name in the database
|
|
@@ -238,3 +239,11 @@ export declare function noValidateOn(...ops: OperationKeys[]): (target: any, pro
|
|
|
238
239
|
export declare function noValidateOnCreate(): (target: any, propertyKey?: any) => void;
|
|
239
240
|
export declare function noValidateOnUpdate(): (target: any, propertyKey?: any) => void;
|
|
240
241
|
export declare function noValidateOnCreateUpdate(): (target: any, propertyKey?: any) => void;
|
|
242
|
+
/**
|
|
243
|
+
* @description Specifies the model property as a relation
|
|
244
|
+
* @summary Decorator that specifies the model property as a relation in the database
|
|
245
|
+
* @return {Function} A decorator function that can be applied to a class property
|
|
246
|
+
* @function relation
|
|
247
|
+
* @category Property Decorators
|
|
248
|
+
*/
|
|
249
|
+
export declare function relation(relationKey: string, meta: RelationsMetadata): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { afterAny, ConflictError, onCreate, onCreateUpdate, onDelete, onUpdate, OperationKeys, timestamp, } from "@decaf-ts/db-decorators";
|
|
2
|
-
import { apply, metadata } from "@decaf-ts/
|
|
3
|
-
import { apply as newApply, Metadata, metadata as newMetadata, } from "@decaf-ts/decoration";
|
|
2
|
+
import { apply as newApply, Metadata, metadata as newMetadata, Decoration, propMetadata, prop, metadata, apply, } from "@decaf-ts/decoration";
|
|
4
3
|
import { PersistenceKeys } from "./../persistence/constants.js";
|
|
5
4
|
import { DefaultCascade, OrderDirection } from "./../repository/constants.js";
|
|
6
|
-
import {
|
|
7
|
-
import { Adapter } from "./../persistence/index.js";
|
|
8
|
-
import { Repository } from "./../repository/Repository.js";
|
|
5
|
+
import { list, type } from "@decaf-ts/decorator-validation";
|
|
9
6
|
import { Condition } from "./../query/Condition.js";
|
|
10
7
|
import { oneToManyOnCreate, oneToManyOnDelete, oneToManyOnUpdate, oneToOneOnCreate, oneToOneOnDelete, oneToOneOnUpdate, populate as pop, } from "./construction.js";
|
|
11
8
|
import { AuthorizationError } from "./../utils/index.js";
|
|
@@ -18,15 +15,16 @@ import { AuthorizationError } from "./../utils/index.js";
|
|
|
18
15
|
* @category Class Decorators
|
|
19
16
|
*/
|
|
20
17
|
export function table(opts) {
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
18
|
+
return Decoration.for(PersistenceKeys.TABLE)
|
|
19
|
+
.define({
|
|
20
|
+
decorator: function table(opts) {
|
|
21
|
+
return function table(target) {
|
|
22
|
+
return metadata(PersistenceKeys.TABLE, opts || target.name.toLowerCase())(target);
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
args: [opts],
|
|
26
|
+
})
|
|
27
|
+
.apply();
|
|
30
28
|
}
|
|
31
29
|
/**
|
|
32
30
|
* @description Specifies the database column name for a model property
|
|
@@ -37,40 +35,41 @@ export function table(opts) {
|
|
|
37
35
|
* @category Property Decorators
|
|
38
36
|
*/
|
|
39
37
|
export function column(columnName) {
|
|
40
|
-
|
|
41
|
-
return Decoration.for(key)
|
|
38
|
+
return Decoration.for(PersistenceKeys.COLUMN)
|
|
42
39
|
.define({
|
|
43
|
-
decorator: function column(
|
|
40
|
+
decorator: function column(c) {
|
|
44
41
|
return function column(obj, attr) {
|
|
45
|
-
return propMetadata(
|
|
42
|
+
return propMetadata(Metadata.key(PersistenceKeys.COLUMN, attr), c || attr)(obj, attr);
|
|
46
43
|
};
|
|
47
44
|
},
|
|
48
|
-
args: [
|
|
45
|
+
args: [columnName],
|
|
49
46
|
})
|
|
50
47
|
.apply();
|
|
51
48
|
}
|
|
52
49
|
export function index(directions, compositions, name) {
|
|
53
50
|
function index(directions, compositions, name) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
compositions = undefined;
|
|
58
|
-
}
|
|
59
|
-
if (typeof compositions === "string") {
|
|
60
|
-
name = compositions;
|
|
61
|
-
compositions = undefined;
|
|
62
|
-
}
|
|
63
|
-
if (!compositions && directions) {
|
|
64
|
-
if (directions.find((d) => ![OrderDirection.ASC, OrderDirection.DSC].includes(d))) {
|
|
65
|
-
compositions = directions;
|
|
51
|
+
return function index(obj, attr) {
|
|
52
|
+
if (typeof directions === "string") {
|
|
53
|
+
name = directions;
|
|
66
54
|
directions = undefined;
|
|
55
|
+
compositions = undefined;
|
|
67
56
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
if (typeof compositions === "string") {
|
|
58
|
+
name = compositions;
|
|
59
|
+
compositions = undefined;
|
|
60
|
+
}
|
|
61
|
+
if (!compositions && directions) {
|
|
62
|
+
if (directions.find((d) => ![OrderDirection.ASC, OrderDirection.DSC].includes(d))) {
|
|
63
|
+
compositions = directions;
|
|
64
|
+
directions = undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return propMetadata(Metadata.key(`${PersistenceKeys.INDEX}${compositions && compositions?.length ? `.${compositions.join(".")}` : ""}`, attr), {
|
|
68
|
+
directions: directions,
|
|
69
|
+
compositions: compositions,
|
|
70
|
+
name: name,
|
|
71
|
+
})(obj, attr);
|
|
72
|
+
};
|
|
74
73
|
}
|
|
75
74
|
return Decoration.for(PersistenceKeys.INDEX)
|
|
76
75
|
.define({
|
|
@@ -121,7 +120,7 @@ export async function uniqueOnCreateUpdate(context, data, key, model) {
|
|
|
121
120
|
* ```
|
|
122
121
|
*/
|
|
123
122
|
export function unique() {
|
|
124
|
-
const key =
|
|
123
|
+
const key = PersistenceKeys.UNIQUE;
|
|
125
124
|
return Decoration.for(key)
|
|
126
125
|
.define(onCreateUpdate(uniqueOnCreateUpdate), propMetadata(key, {}))
|
|
127
126
|
.apply();
|
|
@@ -169,9 +168,15 @@ model) {
|
|
|
169
168
|
* ```
|
|
170
169
|
*/
|
|
171
170
|
export function createdBy() {
|
|
172
|
-
const key =
|
|
171
|
+
const key = PersistenceKeys.CREATED_BY;
|
|
172
|
+
function createdBy() {
|
|
173
|
+
return apply(onCreate(createdByOnCreateUpdate), propMetadata(key, {}));
|
|
174
|
+
}
|
|
173
175
|
return Decoration.for(key)
|
|
174
|
-
.define(
|
|
176
|
+
.define({
|
|
177
|
+
decorator: createdBy,
|
|
178
|
+
args: [],
|
|
179
|
+
})
|
|
175
180
|
.apply();
|
|
176
181
|
}
|
|
177
182
|
/**
|
|
@@ -189,9 +194,15 @@ export function createdBy() {
|
|
|
189
194
|
* ```
|
|
190
195
|
*/
|
|
191
196
|
export function updatedBy() {
|
|
192
|
-
const key =
|
|
197
|
+
const key = PersistenceKeys.UPDATED_BY;
|
|
198
|
+
function updatedBy() {
|
|
199
|
+
return apply(onUpdate(createdByOnCreateUpdate), propMetadata(key, {}));
|
|
200
|
+
}
|
|
193
201
|
return Decoration.for(key)
|
|
194
|
-
.define(
|
|
202
|
+
.define({
|
|
203
|
+
decorator: updatedBy,
|
|
204
|
+
args: [],
|
|
205
|
+
})
|
|
195
206
|
.apply();
|
|
196
207
|
}
|
|
197
208
|
export function createdAt() {
|
|
@@ -226,11 +237,10 @@ export function updatedAt() {
|
|
|
226
237
|
* @see manyToOne
|
|
227
238
|
*/
|
|
228
239
|
export function oneToOne(clazz, cascadeOptions = DefaultCascade, populate = true, joinColumnOpts, fk) {
|
|
229
|
-
const key =
|
|
230
|
-
// Model.register(clazz as Constructor<M>);
|
|
240
|
+
const key = PersistenceKeys.ONE_TO_ONE;
|
|
231
241
|
function oneToOneDec(clazz, cascade, populate, joinColumnOpts, fk) {
|
|
232
242
|
const meta = {
|
|
233
|
-
class: clazz
|
|
243
|
+
class: clazz,
|
|
234
244
|
cascade: cascade,
|
|
235
245
|
populate: populate,
|
|
236
246
|
};
|
|
@@ -238,12 +248,7 @@ export function oneToOne(clazz, cascadeOptions = DefaultCascade, populate = true
|
|
|
238
248
|
meta.joinTable = joinColumnOpts;
|
|
239
249
|
if (fk)
|
|
240
250
|
meta.name = fk;
|
|
241
|
-
return apply(prop(
|
|
242
|
-
clazz.name ? clazz.name : clazz,
|
|
243
|
-
String.name,
|
|
244
|
-
Number.name,
|
|
245
|
-
BigInt.name,
|
|
246
|
-
]), onCreate(oneToOneOnCreate, meta), onUpdate(oneToOneOnUpdate, meta), onDelete(oneToOneOnDelete, meta), afterAny(pop, meta), propMetadata(key, meta));
|
|
251
|
+
return apply(prop(), relation(key, meta), type([clazz, String, Number, BigInt]), onCreate(oneToOneOnCreate, meta), onUpdate(oneToOneOnUpdate, meta), onDelete(oneToOneOnDelete, meta), afterAny(pop, meta));
|
|
247
252
|
}
|
|
248
253
|
return Decoration.for(key)
|
|
249
254
|
.define({
|
|
@@ -281,10 +286,10 @@ export function oneToOne(clazz, cascadeOptions = DefaultCascade, populate = true
|
|
|
281
286
|
* @see manyToOne
|
|
282
287
|
*/
|
|
283
288
|
export function oneToMany(clazz, cascadeOptions = DefaultCascade, populate = true, joinTableOpts, fk) {
|
|
284
|
-
const key =
|
|
289
|
+
const key = PersistenceKeys.ONE_TO_MANY;
|
|
285
290
|
function oneToManyDec(clazz, cascade, populate, joinTableOpts, fk) {
|
|
286
291
|
const metadata = {
|
|
287
|
-
class: clazz
|
|
292
|
+
class: clazz,
|
|
288
293
|
cascade: cascade,
|
|
289
294
|
populate: populate,
|
|
290
295
|
};
|
|
@@ -292,13 +297,13 @@ export function oneToMany(clazz, cascadeOptions = DefaultCascade, populate = tru
|
|
|
292
297
|
metadata.joinTable = joinTableOpts;
|
|
293
298
|
if (fk)
|
|
294
299
|
metadata.name = fk;
|
|
295
|
-
return apply(prop(
|
|
300
|
+
return apply(prop(), relation(key, metadata), list([
|
|
296
301
|
clazz,
|
|
297
302
|
String,
|
|
298
303
|
Number,
|
|
299
304
|
// @ts-expect-error Bigint is not a constructor
|
|
300
305
|
BigInt,
|
|
301
|
-
]), onCreate(oneToManyOnCreate, metadata), onUpdate(oneToManyOnUpdate, metadata), onDelete(oneToManyOnDelete, metadata), afterAny(pop, metadata)
|
|
306
|
+
]), onCreate(oneToManyOnCreate, metadata), onUpdate(oneToManyOnUpdate, metadata), onDelete(oneToManyOnDelete, metadata), afterAny(pop, metadata));
|
|
302
307
|
}
|
|
303
308
|
return Decoration.for(key)
|
|
304
309
|
.define({
|
|
@@ -337,11 +342,10 @@ export function oneToMany(clazz, cascadeOptions = DefaultCascade, populate = tru
|
|
|
337
342
|
*/
|
|
338
343
|
export function manyToOne(clazz, cascadeOptions = DefaultCascade, populate = true, joinTableOpts, fk) {
|
|
339
344
|
// Model.register(clazz as Constructor<M>);
|
|
340
|
-
const key =
|
|
345
|
+
const key = PersistenceKeys.MANY_TO_ONE;
|
|
341
346
|
function manyToOneDec(clazz, cascade, populate, joinTableOpts, fk) {
|
|
342
|
-
const clazzName = () => (clazz?.name ? clazz : clazz()).name;
|
|
343
347
|
const metadata = {
|
|
344
|
-
class: clazz
|
|
348
|
+
class: clazz,
|
|
345
349
|
cascade: cascade,
|
|
346
350
|
populate: populate,
|
|
347
351
|
};
|
|
@@ -349,12 +353,12 @@ export function manyToOne(clazz, cascadeOptions = DefaultCascade, populate = tru
|
|
|
349
353
|
metadata.joinTable = joinTableOpts;
|
|
350
354
|
if (fk)
|
|
351
355
|
metadata.name = fk;
|
|
352
|
-
return apply(prop(
|
|
356
|
+
return apply(prop(), relation(key, metadata), type([clazz, String, Number, BigInt])
|
|
353
357
|
// onCreate(oneToManyOnCreate, metadata),
|
|
354
358
|
// onUpdate(oneToManyOnUpdate, metadata),
|
|
355
359
|
// onDelete(oneToManyOnDelete, metadata),
|
|
356
360
|
// afterAny(pop, metadata),
|
|
357
|
-
|
|
361
|
+
);
|
|
358
362
|
}
|
|
359
363
|
return Decoration.for(key)
|
|
360
364
|
.define({
|
|
@@ -393,10 +397,10 @@ export function manyToOne(clazz, cascadeOptions = DefaultCascade, populate = tru
|
|
|
393
397
|
*/
|
|
394
398
|
export function manyToMany(clazz, cascadeOptions = DefaultCascade, populate = true, joinTableOpts, fk) {
|
|
395
399
|
// Model.register(clazz as Constructor<M>);
|
|
396
|
-
const key =
|
|
400
|
+
const key = PersistenceKeys.MANY_TO_MANY;
|
|
397
401
|
function manyToManyDec(clazz, cascade, populate, joinTableOpts, fk) {
|
|
398
402
|
const metadata = {
|
|
399
|
-
class: clazz
|
|
403
|
+
class: clazz,
|
|
400
404
|
cascade: cascade,
|
|
401
405
|
populate: populate,
|
|
402
406
|
};
|
|
@@ -404,17 +408,12 @@ export function manyToMany(clazz, cascadeOptions = DefaultCascade, populate = tr
|
|
|
404
408
|
metadata.joinTable = joinTableOpts;
|
|
405
409
|
if (fk)
|
|
406
410
|
metadata.name = fk;
|
|
407
|
-
return apply(prop(
|
|
408
|
-
clazz.name ? clazz.name : clazz,
|
|
409
|
-
String.name,
|
|
410
|
-
Number.name,
|
|
411
|
-
BigInt.name,
|
|
412
|
-
]),
|
|
411
|
+
return apply(prop(), relation(key, metadata), list([clazz, String, Number, BigInt])
|
|
413
412
|
// onCreate(oneToManyOnCreate, metadata),
|
|
414
413
|
// onUpdate(oneToManyOnUpdate, metadata),
|
|
415
414
|
// onDelete(oneToManyOnDelete, metadata),
|
|
416
415
|
// afterAll(populate, metadata),
|
|
417
|
-
|
|
416
|
+
);
|
|
418
417
|
}
|
|
419
418
|
return Decoration.for(key)
|
|
420
419
|
.define({
|
|
@@ -439,4 +438,27 @@ export function noValidateOnUpdate() {
|
|
|
439
438
|
export function noValidateOnCreateUpdate() {
|
|
440
439
|
return noValidateOn(OperationKeys.UPDATE, OperationKeys.CREATE);
|
|
441
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* @description Specifies the model property as a relation
|
|
443
|
+
* @summary Decorator that specifies the model property as a relation in the database
|
|
444
|
+
* @return {Function} A decorator function that can be applied to a class property
|
|
445
|
+
* @function relation
|
|
446
|
+
* @category Property Decorators
|
|
447
|
+
*/
|
|
448
|
+
export function relation(relationKey, meta) {
|
|
449
|
+
function relation(relationKey, meta) {
|
|
450
|
+
return function relation(obj, attr) {
|
|
451
|
+
propMetadata(relationKey, meta)(obj, attr);
|
|
452
|
+
return propMetadata(Metadata.key(PersistenceKeys.RELATIONS, attr), Object.assign({}, meta, {
|
|
453
|
+
key: relationKey,
|
|
454
|
+
}))(obj, attr);
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
return Decoration.for(PersistenceKeys.RELATIONS)
|
|
458
|
+
.define({
|
|
459
|
+
decorator: relation,
|
|
460
|
+
args: [relationKey, meta],
|
|
461
|
+
})
|
|
462
|
+
.apply();
|
|
463
|
+
}
|
|
442
464
|
//# sourceMappingURL=decorators.js.map
|