@tsed/objection 7.0.0-rc.4 → 7.0.0-rc.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/lib/cjs/decorators/belongsToOne.js +16 -0
- package/lib/cjs/decorators/belongsToOne.js.map +1 -0
- package/lib/cjs/decorators/entity.js +4 -1
- package/lib/cjs/decorators/entity.js.map +1 -1
- package/lib/cjs/decorators/hasMany.js +16 -0
- package/lib/cjs/decorators/hasMany.js.map +1 -0
- package/lib/cjs/decorators/hasOne.js +16 -0
- package/lib/cjs/decorators/hasOne.js.map +1 -0
- package/lib/cjs/decorators/hasOneThroughRelation.js +16 -0
- package/lib/cjs/decorators/hasOneThroughRelation.js.map +1 -0
- package/lib/cjs/decorators/manyToMany.js +16 -0
- package/lib/cjs/decorators/manyToMany.js.map +1 -0
- package/lib/cjs/decorators/relatesTo.js +25 -0
- package/lib/cjs/decorators/relatesTo.js.map +1 -0
- package/lib/cjs/domain/RelationshipOpts.js +9 -0
- package/lib/cjs/domain/RelationshipOpts.js.map +1 -0
- package/lib/cjs/index.js +10 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/utils/createJoinKeys.js +40 -0
- package/lib/cjs/utils/createJoinKeys.js.map +1 -0
- package/lib/cjs/utils/createRelationshipMapping.js +22 -0
- package/lib/cjs/utils/createRelationshipMapping.js.map +1 -0
- package/lib/cjs/utils/getJsonEntityRelationships.js +19 -0
- package/lib/cjs/utils/getJsonEntityRelationships.js.map +1 -0
- package/lib/esm/decorators/belongsToOne.js +12 -0
- package/lib/esm/decorators/belongsToOne.js.map +1 -0
- package/lib/esm/decorators/entity.js +4 -1
- package/lib/esm/decorators/entity.js.map +1 -1
- package/lib/esm/decorators/hasMany.js +12 -0
- package/lib/esm/decorators/hasMany.js.map +1 -0
- package/lib/esm/decorators/hasOne.js +12 -0
- package/lib/esm/decorators/hasOne.js.map +1 -0
- package/lib/esm/decorators/hasOneThroughRelation.js +12 -0
- package/lib/esm/decorators/hasOneThroughRelation.js.map +1 -0
- package/lib/esm/decorators/manyToMany.js +12 -0
- package/lib/esm/decorators/manyToMany.js.map +1 -0
- package/lib/esm/decorators/relatesTo.js +21 -0
- package/lib/esm/decorators/relatesTo.js.map +1 -0
- package/lib/esm/domain/RelationshipOpts.js +4 -0
- package/lib/esm/domain/RelationshipOpts.js.map +1 -0
- package/lib/esm/index.js +10 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/utils/createJoinKeys.js +36 -0
- package/lib/esm/utils/createJoinKeys.js.map +1 -0
- package/lib/esm/utils/createRelationshipMapping.js +18 -0
- package/lib/esm/utils/createRelationshipMapping.js.map +1 -0
- package/lib/esm/utils/getJsonEntityRelationships.js +15 -0
- package/lib/esm/utils/getJsonEntityRelationships.js.map +1 -0
- package/lib/types/decorators/belongsToOne.d.ts +8 -0
- package/lib/types/decorators/hasMany.d.ts +9 -0
- package/lib/types/decorators/hasOne.d.ts +8 -0
- package/lib/types/decorators/hasOneThroughRelation.d.ts +8 -0
- package/lib/types/decorators/manyToMany.d.ts +9 -0
- package/lib/types/decorators/relatesTo.d.ts +10 -0
- package/lib/types/domain/RelationshipOpts.d.ts +8 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/utils/createJoinKeys.d.ts +14 -0
- package/lib/types/utils/createRelationshipMapping.d.ts +24 -0
- package/lib/types/utils/getJsonEntityRelationships.d.ts +8 -0
- package/package.json +11 -11
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BelongsToOne = void 0;
|
|
4
|
+
const objection_1 = require("objection");
|
|
5
|
+
const relatesTo_1 = require("./relatesTo");
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param opts
|
|
9
|
+
* @decorator
|
|
10
|
+
* @objection
|
|
11
|
+
*/
|
|
12
|
+
function BelongsToOne(opts) {
|
|
13
|
+
return (0, relatesTo_1.RelatesTo)(objection_1.Model.BelongsToOneRelation, opts);
|
|
14
|
+
}
|
|
15
|
+
exports.BelongsToOne = BelongsToOne;
|
|
16
|
+
//# sourceMappingURL=belongsToOne.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"belongsToOne.js","sourceRoot":"","sources":["../../../src/decorators/belongsToOne.ts"],"names":[],"mappings":";;;AAAA,yCAAgC;AAChC,2CAAsC;AAGtC;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,IAAqC;IAChE,OAAO,IAAA,qBAAS,EAAC,iBAAK,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC;AAFD,oCAEC","sourcesContent":["import {Model} from \"objection\";\nimport {RelatesTo} from \"./relatesTo\";\nimport {RelationshipOptsWithoutThrough} from \"../domain/RelationshipOpts\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function BelongsToOne(opts?: RelationshipOptsWithoutThrough): PropertyDecorator {\n return RelatesTo(Model.BelongsToOneRelation, opts);\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Entity = void 0;
|
|
4
|
-
const schema_1 = require("@tsed/schema");
|
|
5
4
|
const defineStaticGetter_1 = require("../utils/defineStaticGetter");
|
|
5
|
+
const getJsonEntityRelationships_1 = require("../utils/getJsonEntityRelationships");
|
|
6
|
+
const schema_1 = require("@tsed/schema");
|
|
6
7
|
/**
|
|
7
8
|
*
|
|
8
9
|
* @param tableName
|
|
@@ -14,8 +15,10 @@ function Entity(tableName) {
|
|
|
14
15
|
throw new Error("Please provide a table name");
|
|
15
16
|
}
|
|
16
17
|
return (target) => {
|
|
18
|
+
const originalRelationMappings = target["relationMappings"];
|
|
17
19
|
(0, defineStaticGetter_1.defineStaticGetter)(target, "tableName", () => tableName);
|
|
18
20
|
(0, defineStaticGetter_1.defineStaticGetter)(target, "jsonSchema", () => (0, schema_1.getJsonSchema)(target));
|
|
21
|
+
(0, defineStaticGetter_1.defineStaticGetter)(target, "relationMappings", () => originalRelationMappings || (0, getJsonEntityRelationships_1.getJsonEntityRelationships)(target));
|
|
19
22
|
return target;
|
|
20
23
|
};
|
|
21
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../src/decorators/entity.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../src/decorators/entity.ts"],"names":[],"mappings":";;;AACA,oEAA+D;AAC/D,oFAA+E;AAC/E,yCAA2C;AAE3C;;;;;GAKG;AACH,SAAgB,MAAM,CAAC,SAAiB;IACtC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;KAChD;IAED,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,wBAAwB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAC5D,IAAA,uCAAkB,EAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACzD,IAAA,uCAAkB,EAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,IAAA,sBAAa,EAAC,MAAM,CAAC,CAAC,CAAC;QACtE,IAAA,uCAAkB,EAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,CAAC,wBAAwB,IAAI,IAAA,uDAA0B,EAAC,MAAM,CAAC,CAAC,CAAC;QACrH,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAZD,wBAYC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {defineStaticGetter} from \"../utils/defineStaticGetter\";\nimport {getJsonEntityRelationships} from \"../utils/getJsonEntityRelationships\";\nimport {getJsonSchema} from \"@tsed/schema\";\n\n/**\n *\n * @param tableName\n * @decorator\n * @objection\n */\nexport function Entity(tableName: string): ClassDecorator {\n if (!tableName) {\n throw new Error(\"Please provide a table name\");\n }\n\n return (target: any) => {\n const originalRelationMappings = target[\"relationMappings\"];\n defineStaticGetter(target, \"tableName\", () => tableName);\n defineStaticGetter(target, \"jsonSchema\", () => getJsonSchema(target));\n defineStaticGetter(target, \"relationMappings\", () => originalRelationMappings || getJsonEntityRelationships(target));\n return target;\n };\n}\n\nexport interface EntityMethods<T> extends Type<T> {\n readonly tableName: string;\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HasMany = void 0;
|
|
4
|
+
const objection_1 = require("objection");
|
|
5
|
+
const relatesTo_1 = require("./relatesTo");
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param opts
|
|
9
|
+
* @decorator
|
|
10
|
+
* @objection
|
|
11
|
+
*/
|
|
12
|
+
function HasMany(type, opts) {
|
|
13
|
+
return (0, relatesTo_1.RelatesTo)(objection_1.Model.HasManyRelation, { ...opts, type });
|
|
14
|
+
}
|
|
15
|
+
exports.HasMany = HasMany;
|
|
16
|
+
//# sourceMappingURL=hasMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasMany.js","sourceRoot":"","sources":["../../../src/decorators/hasMany.ts"],"names":[],"mappings":";;;AAAA,yCAAqD;AAErD,2CAAsC;AAGtC;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,IAAyB,EAAE,IAAkC;IACnF,OAAO,IAAA,qBAAS,EAAC,iBAAK,CAAC,eAAe,EAAE,EAAC,GAAG,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;AAC3D,CAAC;AAFD,0BAEC","sourcesContent":["import {Model, ModelClassSpecifier} from \"objection\";\n\nimport {RelatesTo} from \"./relatesTo\";\nimport {RelationshipOptsWithThrough} from \"../domain/RelationshipOpts\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function HasMany(type: ModelClassSpecifier, opts?: RelationshipOptsWithThrough): PropertyDecorator {\n return RelatesTo(Model.HasManyRelation, {...opts, type});\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HasOne = void 0;
|
|
4
|
+
const objection_1 = require("objection");
|
|
5
|
+
const relatesTo_1 = require("./relatesTo");
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param opts
|
|
9
|
+
* @decorator
|
|
10
|
+
* @objection
|
|
11
|
+
*/
|
|
12
|
+
function HasOne(opts) {
|
|
13
|
+
return (0, relatesTo_1.RelatesTo)(objection_1.Model.HasOneRelation, opts);
|
|
14
|
+
}
|
|
15
|
+
exports.HasOne = HasOne;
|
|
16
|
+
//# sourceMappingURL=hasOne.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasOne.js","sourceRoot":"","sources":["../../../src/decorators/hasOne.ts"],"names":[],"mappings":";;;AAAA,yCAAgC;AAChC,2CAAsC;AAGtC;;;;;GAKG;AACH,SAAgB,MAAM,CAAC,IAAqC;IAC1D,OAAO,IAAA,qBAAS,EAAC,iBAAK,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC;AAFD,wBAEC","sourcesContent":["import {Model} from \"objection\";\nimport {RelatesTo} from \"./relatesTo\";\nimport {RelationshipOptsWithoutThrough} from \"../domain/RelationshipOpts\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function HasOne(opts?: RelationshipOptsWithoutThrough): PropertyDecorator {\n return RelatesTo(Model.HasOneRelation, opts);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HasOneThroughRelation = void 0;
|
|
4
|
+
const objection_1 = require("objection");
|
|
5
|
+
const relatesTo_1 = require("./relatesTo");
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param opts
|
|
9
|
+
* @decorator
|
|
10
|
+
* @objection
|
|
11
|
+
*/
|
|
12
|
+
function HasOneThroughRelation(opts) {
|
|
13
|
+
return (0, relatesTo_1.RelatesTo)(objection_1.Model.HasOneThroughRelation, opts);
|
|
14
|
+
}
|
|
15
|
+
exports.HasOneThroughRelation = HasOneThroughRelation;
|
|
16
|
+
//# sourceMappingURL=hasOneThroughRelation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasOneThroughRelation.js","sourceRoot":"","sources":["../../../src/decorators/hasOneThroughRelation.ts"],"names":[],"mappings":";;;AAEA,yCAAgC;AAChC,2CAAsC;AAEtC;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,IAAkC;IACtE,OAAO,IAAA,qBAAS,EAAC,iBAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC;AAFD,sDAEC","sourcesContent":["import {RelationshipOptsWithThrough, RelationshipOptsWithoutThrough} from \"../domain/RelationshipOpts\";\n\nimport {Model} from \"objection\";\nimport {RelatesTo} from \"./relatesTo\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function HasOneThroughRelation(opts?: RelationshipOptsWithThrough): PropertyDecorator {\n return RelatesTo(Model.HasOneThroughRelation, opts);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ManyToMany = void 0;
|
|
4
|
+
const objection_1 = require("objection");
|
|
5
|
+
const relatesTo_1 = require("./relatesTo");
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param opts
|
|
9
|
+
* @decorator
|
|
10
|
+
* @objection
|
|
11
|
+
*/
|
|
12
|
+
function ManyToMany(type, opts) {
|
|
13
|
+
return (0, relatesTo_1.RelatesTo)(objection_1.Model.ManyToManyRelation, { ...opts, type });
|
|
14
|
+
}
|
|
15
|
+
exports.ManyToMany = ManyToMany;
|
|
16
|
+
//# sourceMappingURL=manyToMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manyToMany.js","sourceRoot":"","sources":["../../../src/decorators/manyToMany.ts"],"names":[],"mappings":";;;AAAA,yCAAqD;AAErD,2CAAsC;AAGtC;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,IAAyB,EAAE,IAAkC;IACtF,OAAO,IAAA,qBAAS,EAAC,iBAAK,CAAC,kBAAkB,EAAE,EAAC,GAAG,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;AAC9D,CAAC;AAFD,gCAEC","sourcesContent":["import {Model, ModelClassSpecifier} from \"objection\";\n\nimport {RelatesTo} from \"./relatesTo\";\nimport {RelationshipOptsWithThrough} from \"../domain/RelationshipOpts\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function ManyToMany(type: ModelClassSpecifier, opts?: RelationshipOptsWithThrough): PropertyDecorator {\n return RelatesTo(Model.ManyToManyRelation, {...opts, type});\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelatesTo = void 0;
|
|
4
|
+
const schema_1 = require("@tsed/schema");
|
|
5
|
+
const RelationshipOpts_1 = require("../domain/RelationshipOpts");
|
|
6
|
+
const core_1 = require("@tsed/core");
|
|
7
|
+
const getJsonEntityRelationships_1 = require("../utils/getJsonEntityRelationships");
|
|
8
|
+
const createRelationshipMapping_1 = require("../utils/createRelationshipMapping");
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param relation
|
|
12
|
+
* @param opts
|
|
13
|
+
* @decorator
|
|
14
|
+
* @objection
|
|
15
|
+
*/
|
|
16
|
+
function RelatesTo(relation, opts) {
|
|
17
|
+
return (0, core_1.useDecorators)(opts?.type ? (0, schema_1.CollectionOf)(opts.type) : (0, schema_1.Property)(), (0, core_1.StoreFn)((store, params) => {
|
|
18
|
+
if (opts && (0, RelationshipOpts_1.isModelClassFactory)(opts.type)) {
|
|
19
|
+
opts.type = opts.type();
|
|
20
|
+
}
|
|
21
|
+
store.set(getJsonEntityRelationships_1.OBJECTION_RELATIONSHIP_KEY, (0, createRelationshipMapping_1.createRelationshipMapping)(params, relation, opts));
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
exports.RelatesTo = RelatesTo;
|
|
25
|
+
//# sourceMappingURL=relatesTo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relatesTo.js","sourceRoot":"","sources":["../../../src/decorators/relatesTo.ts"],"names":[],"mappings":";;;AAAA,yCAAoD;AACpD,iEAAiF;AACjF,qCAAkD;AAElD,oFAA+E;AAE/E,kFAA6E;AAE7E;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,QAAsB,EAAE,IAAuB;IACvE,OAAO,IAAA,oBAAa,EAClB,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAA,qBAAY,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAQ,GAAE,EACjD,IAAA,cAAO,EAAC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACxB,IAAI,IAAI,IAAI,IAAA,sCAAmB,EAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;SACzB;QACD,KAAK,CAAC,GAAG,CAAC,uDAA0B,EAAE,IAAA,qDAAyB,EAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3F,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAVD,8BAUC","sourcesContent":["import {CollectionOf, Property} from \"@tsed/schema\";\nimport {RelationshipOpts, isModelClassFactory} from \"../domain/RelationshipOpts\";\nimport {StoreFn, useDecorators} from \"@tsed/core\";\n\nimport {OBJECTION_RELATIONSHIP_KEY} from \"../utils/getJsonEntityRelationships\";\nimport {RelationType} from \"objection\";\nimport {createRelationshipMapping} from \"../utils/createRelationshipMapping\";\n\n/**\n *\n * @param relation\n * @param opts\n * @decorator\n * @objection\n */\nexport function RelatesTo(relation: RelationType, opts?: RelationshipOpts): PropertyDecorator {\n return useDecorators(\n opts?.type ? CollectionOf(opts.type) : Property(),\n StoreFn((store, params) => {\n if (opts && isModelClassFactory(opts.type)) {\n opts.type = opts.type();\n }\n store.set(OBJECTION_RELATIONSHIP_KEY, createRelationshipMapping(params, relation, opts));\n })\n );\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isModelClassFactory = exports.isRelationshipOptsWithThrough = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const isRelationshipOptsWithThrough = (opts) => opts !== undefined && opts.through !== undefined;
|
|
6
|
+
exports.isRelationshipOptsWithThrough = isRelationshipOptsWithThrough;
|
|
7
|
+
const isModelClassFactory = (type) => type !== undefined && !(0, core_1.isString)(type) && (0, core_1.isFunction)(type) && !("prototype" in type);
|
|
8
|
+
exports.isModelClassFactory = isModelClassFactory;
|
|
9
|
+
//# sourceMappingURL=RelationshipOpts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelationshipOpts.js","sourceRoot":"","sources":["../../../src/domain/RelationshipOpts.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AASzC,MAAM,6BAA6B,GAAG,CAAC,IAAuB,EAAuC,EAAE,CAC5G,IAAI,KAAK,SAAS,IAAkC,IAAK,CAAC,OAAO,KAAK,SAAS,CAAC;AADrE,QAAA,6BAA6B,iCACwC;AAE3E,MAAM,mBAAmB,GAAG,CAAC,IAA0B,EAA6B,EAAE,CAC3F,IAAI,KAAK,SAAS,IAAI,CAAC,IAAA,eAAQ,EAAC,IAAI,CAAC,IAAI,IAAA,iBAAU,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC;AADzE,QAAA,mBAAmB,uBACsD","sourcesContent":["import {isFunction, isString} from \"@tsed/core\";\nimport {ModelClassFactory, ModelClassSpecifier, RelationJoin, RelationMapping} from \"objection\";\n\nexport type RelationshipOptsWithThrough = Partial<RelationJoin> & Omit<RelationMapping<any>, \"relation\" | \"join\" | \"modelClass\">;\n\nexport type RelationshipOptsWithoutThrough = Omit<RelationshipOptsWithThrough, \"through\">;\n\nexport type RelationshipOpts = (RelationshipOptsWithThrough | RelationshipOptsWithoutThrough) & {type?: ModelClassSpecifier};\n\nexport const isRelationshipOptsWithThrough = (opts?: RelationshipOpts): opts is RelationshipOptsWithThrough =>\n opts !== undefined && (<RelationshipOptsWithThrough>opts).through !== undefined;\n\nexport const isModelClassFactory = (type?: ModelClassSpecifier): type is ModelClassFactory =>\n type !== undefined && !isString(type) && isFunction(type) && !(\"prototype\" in type);\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -8,16 +8,26 @@ tslib_1.__exportStar(require("./components/createBooleanColumn"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./components/createIdColumn"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./components/createNumberColumn"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./components/createStringColumn"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./decorators/belongsToOne"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./decorators/columnOptions"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./decorators/decimal"), exports);
|
|
13
14
|
tslib_1.__exportStar(require("./decorators/entity"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./decorators/hasMany"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./decorators/hasOne"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./decorators/hasOneThroughRelation"), exports);
|
|
14
18
|
tslib_1.__exportStar(require("./decorators/idColumn"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./decorators/manyToMany"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./decorators/relatesTo"), exports);
|
|
15
21
|
tslib_1.__exportStar(require("./domain/ColumnOpts"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./domain/RelationshipOpts"), exports);
|
|
16
23
|
tslib_1.__exportStar(require("./domain/interfaces"), exports);
|
|
17
24
|
tslib_1.__exportStar(require("./services/ColumnTypesContainer"), exports);
|
|
18
25
|
tslib_1.__exportStar(require("./services/ObjectionConnection"), exports);
|
|
19
26
|
tslib_1.__exportStar(require("./utils/connect"), exports);
|
|
20
27
|
tslib_1.__exportStar(require("./utils/createColumns"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./utils/createJoinKeys"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./utils/createRelationshipMapping"), exports);
|
|
21
30
|
tslib_1.__exportStar(require("./utils/defineStaticGetter"), exports);
|
|
22
31
|
tslib_1.__exportStar(require("./utils/getColumnCtx"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./utils/getJsonEntityRelationships"), exports);
|
|
23
33
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2EAAiD;AACjD,sEAA4C;AAC5C,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,+DAAqC;AACrC,8DAAoC;AACpC,gEAAsC;AACtC,8DAAoC;AACpC,8DAAoC;AACpC,0EAAgD;AAChD,yEAA+C;AAC/C,0DAAgC;AAChC,gEAAsC;AACtC,qEAA2C;AAC3C,+DAAqC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/createBooleanColumn\";\nexport * from \"./components/createIdColumn\";\nexport * from \"./components/createNumberColumn\";\nexport * from \"./components/createStringColumn\";\nexport * from \"./decorators/columnOptions\";\nexport * from \"./decorators/decimal\";\nexport * from \"./decorators/entity\";\nexport * from \"./decorators/idColumn\";\nexport * from \"./domain/ColumnOpts\";\nexport * from \"./domain/interfaces\";\nexport * from \"./services/ColumnTypesContainer\";\nexport * from \"./services/ObjectionConnection\";\nexport * from \"./utils/connect\";\nexport * from \"./utils/createColumns\";\nexport * from \"./utils/defineStaticGetter\";\nexport * from \"./utils/getColumnCtx\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2EAAiD;AACjD,sEAA4C;AAC5C,0EAAgD;AAChD,0EAAgD;AAChD,oEAA0C;AAC1C,qEAA2C;AAC3C,+DAAqC;AACrC,8DAAoC;AACpC,+DAAqC;AACrC,8DAAoC;AACpC,6EAAmD;AACnD,gEAAsC;AACtC,kEAAwC;AACxC,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,8DAAoC;AACpC,0EAAgD;AAChD,yEAA+C;AAC/C,0DAAgC;AAChC,gEAAsC;AACtC,iEAAuC;AACvC,4EAAkD;AAClD,qEAA2C;AAC3C,+DAAqC;AACrC,6EAAmD","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/createBooleanColumn\";\nexport * from \"./components/createIdColumn\";\nexport * from \"./components/createNumberColumn\";\nexport * from \"./components/createStringColumn\";\nexport * from \"./decorators/belongsToOne\";\nexport * from \"./decorators/columnOptions\";\nexport * from \"./decorators/decimal\";\nexport * from \"./decorators/entity\";\nexport * from \"./decorators/hasMany\";\nexport * from \"./decorators/hasOne\";\nexport * from \"./decorators/hasOneThroughRelation\";\nexport * from \"./decorators/idColumn\";\nexport * from \"./decorators/manyToMany\";\nexport * from \"./decorators/relatesTo\";\nexport * from \"./domain/ColumnOpts\";\nexport * from \"./domain/RelationshipOpts\";\nexport * from \"./domain/interfaces\";\nexport * from \"./services/ColumnTypesContainer\";\nexport * from \"./services/ObjectionConnection\";\nexport * from \"./utils/connect\";\nexport * from \"./utils/createColumns\";\nexport * from \"./utils/createJoinKeys\";\nexport * from \"./utils/createRelationshipMapping\";\nexport * from \"./utils/defineStaticGetter\";\nexport * from \"./utils/getColumnCtx\";\nexport * from \"./utils/getJsonEntityRelationships\";\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createJoinKeys = void 0;
|
|
4
|
+
const objection_1 = require("objection");
|
|
5
|
+
const RelationshipOpts_1 = require("../domain/RelationshipOpts");
|
|
6
|
+
const core_1 = require("@tsed/core");
|
|
7
|
+
/**
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
function createJoinKeys(targetClass, targetSuper, propertyKey, relation, opts) {
|
|
11
|
+
const FOREIGN_MODEL = opts?.type || core_1.Metadata.getType(targetSuper, propertyKey);
|
|
12
|
+
const SOURCE_MODEL_KEY = `${targetClass.tableName}.${opts?.from || targetClass.idColumn}`;
|
|
13
|
+
const FOREIGN_MODEL_KEY = `${FOREIGN_MODEL.tableName}.${opts?.to || FOREIGN_MODEL.idColumn}`;
|
|
14
|
+
switch (relation) {
|
|
15
|
+
case objection_1.Model.HasManyRelation:
|
|
16
|
+
case objection_1.Model.HasOneRelation:
|
|
17
|
+
return {
|
|
18
|
+
from: SOURCE_MODEL_KEY,
|
|
19
|
+
to: `${FOREIGN_MODEL.tableName}.${opts?.to || targetClass.tableName + "Id"}`
|
|
20
|
+
};
|
|
21
|
+
case objection_1.Model.ManyToManyRelation:
|
|
22
|
+
case objection_1.Model.HasOneThroughRelation:
|
|
23
|
+
return {
|
|
24
|
+
from: SOURCE_MODEL_KEY,
|
|
25
|
+
through: ((0, RelationshipOpts_1.isRelationshipOptsWithThrough)(opts) && opts.through) || {
|
|
26
|
+
from: `${targetClass.tableName}_${FOREIGN_MODEL.tableName}.${targetClass.tableName}Id`,
|
|
27
|
+
to: `${targetClass.tableName}_${FOREIGN_MODEL.tableName}.${FOREIGN_MODEL.tableName}Id`
|
|
28
|
+
},
|
|
29
|
+
to: FOREIGN_MODEL_KEY
|
|
30
|
+
};
|
|
31
|
+
case objection_1.Model.BelongsToOneRelation:
|
|
32
|
+
default:
|
|
33
|
+
return {
|
|
34
|
+
from: `${targetClass.tableName}.${opts?.from || propertyKey + "Id"}`,
|
|
35
|
+
to: FOREIGN_MODEL_KEY
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.createJoinKeys = createJoinKeys;
|
|
40
|
+
//# sourceMappingURL=createJoinKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createJoinKeys.js","sourceRoot":"","sources":["../../../src/utils/createJoinKeys.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;AAC9C,iEAA2F;AAE3F,qCAAoC;AAEpC;;GAEG;AACH,SAAgB,cAAc,CAAC,WAAgB,EAAE,WAAgB,EAAE,WAAmB,EAAE,QAAsB,EAAE,IAAuB;IACrI,MAAM,aAAa,GAAG,IAAI,EAAE,IAAI,IAAI,eAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAC/E,MAAM,gBAAgB,GAAG,GAAG,WAAW,CAAC,SAAS,IAAI,IAAI,EAAE,IAAI,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC1F,MAAM,iBAAiB,GAAG,GAAG,aAAa,CAAC,SAAS,IAAI,IAAI,EAAE,EAAE,IAAI,aAAa,CAAC,QAAQ,EAAE,CAAC;IAE7F,QAAQ,QAAQ,EAAE;QAChB,KAAK,iBAAK,CAAC,eAAe,CAAC;QAC3B,KAAK,iBAAK,CAAC,cAAc;YACvB,OAAO;gBACL,IAAI,EAAE,gBAAgB;gBACtB,EAAE,EAAE,GAAG,aAAa,CAAC,SAAS,IAAI,IAAI,EAAE,EAAE,IAAI,WAAW,CAAC,SAAS,GAAG,IAAI,EAAE;aAC7E,CAAC;QACJ,KAAK,iBAAK,CAAC,kBAAkB,CAAC;QAC9B,KAAK,iBAAK,CAAC,qBAAqB;YAC9B,OAAO;gBACL,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,CAAC,IAAA,gDAA6B,EAAC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI;oBAChE,IAAI,EAAE,GAAG,WAAW,CAAC,SAAS,IAAI,aAAa,CAAC,SAAS,IAAI,WAAW,CAAC,SAAS,IAAI;oBACtF,EAAE,EAAE,GAAG,WAAW,CAAC,SAAS,IAAI,aAAa,CAAC,SAAS,IAAI,aAAa,CAAC,SAAS,IAAI;iBACvF;gBACD,EAAE,EAAE,iBAAiB;aACtB,CAAC;QACJ,KAAK,iBAAK,CAAC,oBAAoB,CAAC;QAChC;YACE,OAAO;gBACL,IAAI,EAAE,GAAG,WAAW,CAAC,SAAS,IAAI,IAAI,EAAE,IAAI,IAAI,WAAW,GAAG,IAAI,EAAE;gBACpE,EAAE,EAAE,iBAAiB;aACtB,CAAC;KACL;AACH,CAAC;AA7BD,wCA6BC","sourcesContent":["import {Model, RelationType} from \"objection\";\nimport {RelationshipOpts, isRelationshipOptsWithThrough} from \"../domain/RelationshipOpts\";\n\nimport {Metadata} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nexport function createJoinKeys(targetClass: any, targetSuper: any, propertyKey: string, relation: RelationType, opts?: RelationshipOpts) {\n const FOREIGN_MODEL = opts?.type || Metadata.getType(targetSuper, propertyKey);\n const SOURCE_MODEL_KEY = `${targetClass.tableName}.${opts?.from || targetClass.idColumn}`;\n const FOREIGN_MODEL_KEY = `${FOREIGN_MODEL.tableName}.${opts?.to || FOREIGN_MODEL.idColumn}`;\n\n switch (relation) {\n case Model.HasManyRelation:\n case Model.HasOneRelation:\n return {\n from: SOURCE_MODEL_KEY,\n to: `${FOREIGN_MODEL.tableName}.${opts?.to || targetClass.tableName + \"Id\"}`\n };\n case Model.ManyToManyRelation:\n case Model.HasOneThroughRelation:\n return {\n from: SOURCE_MODEL_KEY,\n through: (isRelationshipOptsWithThrough(opts) && opts.through) || {\n from: `${targetClass.tableName}_${FOREIGN_MODEL.tableName}.${targetClass.tableName}Id`,\n to: `${targetClass.tableName}_${FOREIGN_MODEL.tableName}.${FOREIGN_MODEL.tableName}Id`\n },\n to: FOREIGN_MODEL_KEY\n };\n case Model.BelongsToOneRelation:\n default:\n return {\n from: `${targetClass.tableName}.${opts?.from || propertyKey + \"Id\"}`,\n to: FOREIGN_MODEL_KEY\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRelationshipMapping = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const createJoinKeys_1 = require("./createJoinKeys");
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
function createRelationshipMapping([target, propertyKey], relation, opts) {
|
|
10
|
+
return (targetClass) => ({
|
|
11
|
+
[propertyKey]: {
|
|
12
|
+
relation,
|
|
13
|
+
modelClass: opts?.type || core_1.Metadata.getType(target, propertyKey),
|
|
14
|
+
join: (0, createJoinKeys_1.createJoinKeys)(targetClass, target, String(propertyKey), relation, opts),
|
|
15
|
+
modify: opts?.modify,
|
|
16
|
+
filter: opts?.filter,
|
|
17
|
+
beforeInsert: opts?.beforeInsert
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.createRelationshipMapping = createRelationshipMapping;
|
|
22
|
+
//# sourceMappingURL=createRelationshipMapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRelationshipMapping.js","sourceRoot":"","sources":["../../../src/utils/createRelationshipMapping.ts"],"names":[],"mappings":";;;AAAA,qCAAmE;AAInE,qDAAgD;AAEhD;;GAEG;AACH,SAAgB,yBAAyB,CAAC,CAAC,MAAM,EAAE,WAAW,CAAsB,EAAE,QAAsB,EAAE,IAAuB;IACnI,OAAO,CAAC,WAAgB,EAAE,EAAE,CAAC,CAAC;QAC5B,CAAC,WAAW,CAAC,EAAE;YACb,QAAQ;YACR,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,eAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC;YAC/D,IAAI,EAAE,IAAA,+BAAc,EAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC;YAC9E,MAAM,EAAE,IAAI,EAAE,MAAM;YACpB,MAAM,EAAE,IAAI,EAAE,MAAM;YACpB,YAAY,EAAE,IAAI,EAAE,YAAY;SACjC;KACF,CAAC,CAAC;AACL,CAAC;AAXD,8DAWC","sourcesContent":["import {DecoratorParameters, Metadata, getClass} from \"@tsed/core\";\n\nimport {RelationType} from \"objection\";\nimport {RelationshipOpts} from \"../domain/RelationshipOpts\";\nimport {createJoinKeys} from \"./createJoinKeys\";\n\n/**\n * @ignore\n */\nexport function createRelationshipMapping([target, propertyKey]: DecoratorParameters, relation: RelationType, opts?: RelationshipOpts) {\n return (targetClass: any) => ({\n [propertyKey]: {\n relation,\n modelClass: opts?.type || Metadata.getType(target, propertyKey),\n join: createJoinKeys(targetClass, target, String(propertyKey), relation, opts),\n modify: opts?.modify,\n filter: opts?.filter,\n beforeInsert: opts?.beforeInsert\n }\n });\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJsonEntityRelationships = exports.OBJECTION_RELATIONSHIP_KEY = void 0;
|
|
4
|
+
const createColumns_1 = require("./createColumns");
|
|
5
|
+
/**
|
|
6
|
+
* @ignore
|
|
7
|
+
*/
|
|
8
|
+
exports.OBJECTION_RELATIONSHIP_KEY = "objectionRelationship";
|
|
9
|
+
/**
|
|
10
|
+
* @ignore
|
|
11
|
+
*/
|
|
12
|
+
function getJsonEntityRelationships(target) {
|
|
13
|
+
return (0, createColumns_1.getColumns)(target)
|
|
14
|
+
.filter((col) => col.store.get(exports.OBJECTION_RELATIONSHIP_KEY))
|
|
15
|
+
.map((col) => col.store.get(exports.OBJECTION_RELATIONSHIP_KEY)(target))
|
|
16
|
+
.reduce((dict, col) => ({ ...dict, ...col }), {});
|
|
17
|
+
}
|
|
18
|
+
exports.getJsonEntityRelationships = getJsonEntityRelationships;
|
|
19
|
+
//# sourceMappingURL=getJsonEntityRelationships.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getJsonEntityRelationships.js","sourceRoot":"","sources":["../../../src/utils/getJsonEntityRelationships.ts"],"names":[],"mappings":";;;AAAA,mDAA2C;AAE3C;;GAEG;AACU,QAAA,0BAA0B,GAAG,uBAAuB,CAAC;AAElE;;GAEG;AACH,SAAgB,0BAA0B,CAAC,MAAW;IACpD,OAAO,IAAA,0BAAU,EAAC,MAAM,CAAC;SACtB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,kCAA0B,CAAC,CAAC;SAC1D,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,kCAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;SAC/D,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,IAAI,EAAE,GAAG,GAAG,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACpD,CAAC;AALD,gEAKC","sourcesContent":["import {getColumns} from \"./createColumns\";\n\n/**\n * @ignore\n */\nexport const OBJECTION_RELATIONSHIP_KEY = \"objectionRelationship\";\n\n/**\n * @ignore\n */\nexport function getJsonEntityRelationships(target: any) {\n return getColumns(target)\n .filter((col) => col.store.get(OBJECTION_RELATIONSHIP_KEY))\n .map((col) => col.store.get(OBJECTION_RELATIONSHIP_KEY)(target))\n .reduce((dict, col) => ({...dict, ...col}), {});\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Model } from "objection";
|
|
2
|
+
import { RelatesTo } from "./relatesTo.js";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param opts
|
|
6
|
+
* @decorator
|
|
7
|
+
* @objection
|
|
8
|
+
*/
|
|
9
|
+
export function BelongsToOne(opts) {
|
|
10
|
+
return RelatesTo(Model.BelongsToOneRelation, opts);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=belongsToOne.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"belongsToOne.js","sourceRoot":"","sources":["../../../src/decorators/belongsToOne.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,WAAW,CAAC;AAChC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAGtC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAqC;IAChE,OAAO,SAAS,CAAC,KAAK,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import {Model} from \"objection\";\nimport {RelatesTo} from \"./relatesTo\";\nimport {RelationshipOptsWithoutThrough} from \"../domain/RelationshipOpts\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function BelongsToOne(opts?: RelationshipOptsWithoutThrough): PropertyDecorator {\n return RelatesTo(Model.BelongsToOneRelation, opts);\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { getJsonSchema } from "@tsed/schema";
|
|
2
1
|
import { defineStaticGetter } from "../utils/defineStaticGetter.js";
|
|
2
|
+
import { getJsonEntityRelationships } from "../utils/getJsonEntityRelationships.js";
|
|
3
|
+
import { getJsonSchema } from "@tsed/schema";
|
|
3
4
|
/**
|
|
4
5
|
*
|
|
5
6
|
* @param tableName
|
|
@@ -11,8 +12,10 @@ export function Entity(tableName) {
|
|
|
11
12
|
throw new Error("Please provide a table name");
|
|
12
13
|
}
|
|
13
14
|
return (target) => {
|
|
15
|
+
const originalRelationMappings = target["relationMappings"];
|
|
14
16
|
defineStaticGetter(target, "tableName", () => tableName);
|
|
15
17
|
defineStaticGetter(target, "jsonSchema", () => getJsonSchema(target));
|
|
18
|
+
defineStaticGetter(target, "relationMappings", () => originalRelationMappings || getJsonEntityRelationships(target));
|
|
16
19
|
return target;
|
|
17
20
|
};
|
|
18
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../src/decorators/entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../src/decorators/entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAC,0BAA0B,EAAC,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,SAAiB;IACtC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;KAChD;IAED,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,wBAAwB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAC5D,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACzD,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QACtE,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,CAAC,wBAAwB,IAAI,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC;QACrH,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {defineStaticGetter} from \"../utils/defineStaticGetter\";\nimport {getJsonEntityRelationships} from \"../utils/getJsonEntityRelationships\";\nimport {getJsonSchema} from \"@tsed/schema\";\n\n/**\n *\n * @param tableName\n * @decorator\n * @objection\n */\nexport function Entity(tableName: string): ClassDecorator {\n if (!tableName) {\n throw new Error(\"Please provide a table name\");\n }\n\n return (target: any) => {\n const originalRelationMappings = target[\"relationMappings\"];\n defineStaticGetter(target, \"tableName\", () => tableName);\n defineStaticGetter(target, \"jsonSchema\", () => getJsonSchema(target));\n defineStaticGetter(target, \"relationMappings\", () => originalRelationMappings || getJsonEntityRelationships(target));\n return target;\n };\n}\n\nexport interface EntityMethods<T> extends Type<T> {\n readonly tableName: string;\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Model } from "objection";
|
|
2
|
+
import { RelatesTo } from "./relatesTo.js";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param opts
|
|
6
|
+
* @decorator
|
|
7
|
+
* @objection
|
|
8
|
+
*/
|
|
9
|
+
export function HasMany(type, opts) {
|
|
10
|
+
return RelatesTo(Model.HasManyRelation, { ...opts, type });
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=hasMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasMany.js","sourceRoot":"","sources":["../../../src/decorators/hasMany.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAsB,MAAM,WAAW,CAAC;AAErD,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAGtC;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,IAAyB,EAAE,IAAkC;IACnF,OAAO,SAAS,CAAC,KAAK,CAAC,eAAe,EAAE,EAAC,GAAG,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import {Model, ModelClassSpecifier} from \"objection\";\n\nimport {RelatesTo} from \"./relatesTo\";\nimport {RelationshipOptsWithThrough} from \"../domain/RelationshipOpts\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function HasMany(type: ModelClassSpecifier, opts?: RelationshipOptsWithThrough): PropertyDecorator {\n return RelatesTo(Model.HasManyRelation, {...opts, type});\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Model } from "objection";
|
|
2
|
+
import { RelatesTo } from "./relatesTo.js";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param opts
|
|
6
|
+
* @decorator
|
|
7
|
+
* @objection
|
|
8
|
+
*/
|
|
9
|
+
export function HasOne(opts) {
|
|
10
|
+
return RelatesTo(Model.HasOneRelation, opts);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=hasOne.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasOne.js","sourceRoot":"","sources":["../../../src/decorators/hasOne.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,WAAW,CAAC;AAChC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAGtC;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,IAAqC;IAC1D,OAAO,SAAS,CAAC,KAAK,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import {Model} from \"objection\";\nimport {RelatesTo} from \"./relatesTo\";\nimport {RelationshipOptsWithoutThrough} from \"../domain/RelationshipOpts\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function HasOne(opts?: RelationshipOptsWithoutThrough): PropertyDecorator {\n return RelatesTo(Model.HasOneRelation, opts);\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Model } from "objection";
|
|
2
|
+
import { RelatesTo } from "./relatesTo.js";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param opts
|
|
6
|
+
* @decorator
|
|
7
|
+
* @objection
|
|
8
|
+
*/
|
|
9
|
+
export function HasOneThroughRelation(opts) {
|
|
10
|
+
return RelatesTo(Model.HasOneThroughRelation, opts);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=hasOneThroughRelation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasOneThroughRelation.js","sourceRoot":"","sources":["../../../src/decorators/hasOneThroughRelation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,KAAK,EAAC,MAAM,WAAW,CAAC;AAChC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAkC;IACtE,OAAO,SAAS,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import {RelationshipOptsWithThrough, RelationshipOptsWithoutThrough} from \"../domain/RelationshipOpts\";\n\nimport {Model} from \"objection\";\nimport {RelatesTo} from \"./relatesTo\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function HasOneThroughRelation(opts?: RelationshipOptsWithThrough): PropertyDecorator {\n return RelatesTo(Model.HasOneThroughRelation, opts);\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Model } from "objection";
|
|
2
|
+
import { RelatesTo } from "./relatesTo.js";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param opts
|
|
6
|
+
* @decorator
|
|
7
|
+
* @objection
|
|
8
|
+
*/
|
|
9
|
+
export function ManyToMany(type, opts) {
|
|
10
|
+
return RelatesTo(Model.ManyToManyRelation, { ...opts, type });
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=manyToMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manyToMany.js","sourceRoot":"","sources":["../../../src/decorators/manyToMany.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAsB,MAAM,WAAW,CAAC;AAErD,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAGtC;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,IAAyB,EAAE,IAAkC;IACtF,OAAO,SAAS,CAAC,KAAK,CAAC,kBAAkB,EAAE,EAAC,GAAG,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import {Model, ModelClassSpecifier} from \"objection\";\n\nimport {RelatesTo} from \"./relatesTo\";\nimport {RelationshipOptsWithThrough} from \"../domain/RelationshipOpts\";\n\n/**\n *\n * @param opts\n * @decorator\n * @objection\n */\nexport function ManyToMany(type: ModelClassSpecifier, opts?: RelationshipOptsWithThrough): PropertyDecorator {\n return RelatesTo(Model.ManyToManyRelation, {...opts, type});\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CollectionOf, Property } from "@tsed/schema";
|
|
2
|
+
import { isModelClassFactory } from "../domain/RelationshipOpts.js";
|
|
3
|
+
import { StoreFn, useDecorators } from "@tsed/core";
|
|
4
|
+
import { OBJECTION_RELATIONSHIP_KEY } from "../utils/getJsonEntityRelationships.js";
|
|
5
|
+
import { createRelationshipMapping } from "../utils/createRelationshipMapping.js";
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param relation
|
|
9
|
+
* @param opts
|
|
10
|
+
* @decorator
|
|
11
|
+
* @objection
|
|
12
|
+
*/
|
|
13
|
+
export function RelatesTo(relation, opts) {
|
|
14
|
+
return useDecorators(opts?.type ? CollectionOf(opts.type) : Property(), StoreFn((store, params) => {
|
|
15
|
+
if (opts && isModelClassFactory(opts.type)) {
|
|
16
|
+
opts.type = opts.type();
|
|
17
|
+
}
|
|
18
|
+
store.set(OBJECTION_RELATIONSHIP_KEY, createRelationshipMapping(params, relation, opts));
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=relatesTo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relatesTo.js","sourceRoot":"","sources":["../../../src/decorators/relatesTo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AACpD,OAAO,EAAmB,mBAAmB,EAAC,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAC,OAAO,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAElD,OAAO,EAAC,0BAA0B,EAAC,MAAM,qCAAqC,CAAC;AAE/E,OAAO,EAAC,yBAAyB,EAAC,MAAM,oCAAoC,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,QAAsB,EAAE,IAAuB;IACvE,OAAO,aAAa,CAClB,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EACjD,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACxB,IAAI,IAAI,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;SACzB;QACD,KAAK,CAAC,GAAG,CAAC,0BAA0B,EAAE,yBAAyB,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3F,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {CollectionOf, Property} from \"@tsed/schema\";\nimport {RelationshipOpts, isModelClassFactory} from \"../domain/RelationshipOpts\";\nimport {StoreFn, useDecorators} from \"@tsed/core\";\n\nimport {OBJECTION_RELATIONSHIP_KEY} from \"../utils/getJsonEntityRelationships\";\nimport {RelationType} from \"objection\";\nimport {createRelationshipMapping} from \"../utils/createRelationshipMapping\";\n\n/**\n *\n * @param relation\n * @param opts\n * @decorator\n * @objection\n */\nexport function RelatesTo(relation: RelationType, opts?: RelationshipOpts): PropertyDecorator {\n return useDecorators(\n opts?.type ? CollectionOf(opts.type) : Property(),\n StoreFn((store, params) => {\n if (opts && isModelClassFactory(opts.type)) {\n opts.type = opts.type();\n }\n store.set(OBJECTION_RELATIONSHIP_KEY, createRelationshipMapping(params, relation, opts));\n })\n );\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { isFunction, isString } from "@tsed/core";
|
|
2
|
+
export const isRelationshipOptsWithThrough = (opts) => opts !== undefined && opts.through !== undefined;
|
|
3
|
+
export const isModelClassFactory = (type) => type !== undefined && !isString(type) && isFunction(type) && !("prototype" in type);
|
|
4
|
+
//# sourceMappingURL=RelationshipOpts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelationshipOpts.js","sourceRoot":"","sources":["../../../src/domain/RelationshipOpts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAShD,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,IAAuB,EAAuC,EAAE,CAC5G,IAAI,KAAK,SAAS,IAAkC,IAAK,CAAC,OAAO,KAAK,SAAS,CAAC;AAElF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAA0B,EAA6B,EAAE,CAC3F,IAAI,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC","sourcesContent":["import {isFunction, isString} from \"@tsed/core\";\nimport {ModelClassFactory, ModelClassSpecifier, RelationJoin, RelationMapping} from \"objection\";\n\nexport type RelationshipOptsWithThrough = Partial<RelationJoin> & Omit<RelationMapping<any>, \"relation\" | \"join\" | \"modelClass\">;\n\nexport type RelationshipOptsWithoutThrough = Omit<RelationshipOptsWithThrough, \"through\">;\n\nexport type RelationshipOpts = (RelationshipOptsWithThrough | RelationshipOptsWithoutThrough) & {type?: ModelClassSpecifier};\n\nexport const isRelationshipOptsWithThrough = (opts?: RelationshipOpts): opts is RelationshipOptsWithThrough =>\n opts !== undefined && (<RelationshipOptsWithThrough>opts).through !== undefined;\n\nexport const isModelClassFactory = (type?: ModelClassSpecifier): type is ModelClassFactory =>\n type !== undefined && !isString(type) && isFunction(type) && !(\"prototype\" in type);\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -5,16 +5,26 @@ export * from "./components/createBooleanColumn.js";
|
|
|
5
5
|
export * from "./components/createIdColumn.js";
|
|
6
6
|
export * from "./components/createNumberColumn.js";
|
|
7
7
|
export * from "./components/createStringColumn.js";
|
|
8
|
+
export * from "./decorators/belongsToOne.js";
|
|
8
9
|
export * from "./decorators/columnOptions.js";
|
|
9
10
|
export * from "./decorators/decimal.js";
|
|
10
11
|
export * from "./decorators/entity.js";
|
|
12
|
+
export * from "./decorators/hasMany.js";
|
|
13
|
+
export * from "./decorators/hasOne.js";
|
|
14
|
+
export * from "./decorators/hasOneThroughRelation.js";
|
|
11
15
|
export * from "./decorators/idColumn.js";
|
|
16
|
+
export * from "./decorators/manyToMany.js";
|
|
17
|
+
export * from "./decorators/relatesTo.js";
|
|
12
18
|
export * from "./domain/ColumnOpts.js";
|
|
19
|
+
export * from "./domain/RelationshipOpts.js";
|
|
13
20
|
export * from "./domain/interfaces.js";
|
|
14
21
|
export * from "./services/ColumnTypesContainer.js";
|
|
15
22
|
export * from "./services/ObjectionConnection.js";
|
|
16
23
|
export * from "./utils/connect.js";
|
|
17
24
|
export * from "./utils/createColumns.js";
|
|
25
|
+
export * from "./utils/createJoinKeys.js";
|
|
26
|
+
export * from "./utils/createRelationshipMapping.js";
|
|
18
27
|
export * from "./utils/defineStaticGetter.js";
|
|
19
28
|
export * from "./utils/getColumnCtx.js";
|
|
29
|
+
export * from "./utils/getJsonEntityRelationships.js";
|
|
20
30
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/createBooleanColumn\";\nexport * from \"./components/createIdColumn\";\nexport * from \"./components/createNumberColumn\";\nexport * from \"./components/createStringColumn\";\nexport * from \"./decorators/columnOptions\";\nexport * from \"./decorators/decimal\";\nexport * from \"./decorators/entity\";\nexport * from \"./decorators/idColumn\";\nexport * from \"./domain/ColumnOpts\";\nexport * from \"./domain/interfaces\";\nexport * from \"./services/ColumnTypesContainer\";\nexport * from \"./services/ObjectionConnection\";\nexport * from \"./utils/connect\";\nexport * from \"./utils/createColumns\";\nexport * from \"./utils/defineStaticGetter\";\nexport * from \"./utils/getColumnCtx\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oCAAoC,CAAC;AACnD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/createBooleanColumn\";\nexport * from \"./components/createIdColumn\";\nexport * from \"./components/createNumberColumn\";\nexport * from \"./components/createStringColumn\";\nexport * from \"./decorators/belongsToOne\";\nexport * from \"./decorators/columnOptions\";\nexport * from \"./decorators/decimal\";\nexport * from \"./decorators/entity\";\nexport * from \"./decorators/hasMany\";\nexport * from \"./decorators/hasOne\";\nexport * from \"./decorators/hasOneThroughRelation\";\nexport * from \"./decorators/idColumn\";\nexport * from \"./decorators/manyToMany\";\nexport * from \"./decorators/relatesTo\";\nexport * from \"./domain/ColumnOpts\";\nexport * from \"./domain/RelationshipOpts\";\nexport * from \"./domain/interfaces\";\nexport * from \"./services/ColumnTypesContainer\";\nexport * from \"./services/ObjectionConnection\";\nexport * from \"./utils/connect\";\nexport * from \"./utils/createColumns\";\nexport * from \"./utils/createJoinKeys\";\nexport * from \"./utils/createRelationshipMapping\";\nexport * from \"./utils/defineStaticGetter\";\nexport * from \"./utils/getColumnCtx\";\nexport * from \"./utils/getJsonEntityRelationships\";\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Model } from "objection";
|
|
2
|
+
import { isRelationshipOptsWithThrough } from "../domain/RelationshipOpts.js";
|
|
3
|
+
import { Metadata } from "@tsed/core";
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export function createJoinKeys(targetClass, targetSuper, propertyKey, relation, opts) {
|
|
8
|
+
const FOREIGN_MODEL = opts?.type || Metadata.getType(targetSuper, propertyKey);
|
|
9
|
+
const SOURCE_MODEL_KEY = `${targetClass.tableName}.${opts?.from || targetClass.idColumn}`;
|
|
10
|
+
const FOREIGN_MODEL_KEY = `${FOREIGN_MODEL.tableName}.${opts?.to || FOREIGN_MODEL.idColumn}`;
|
|
11
|
+
switch (relation) {
|
|
12
|
+
case Model.HasManyRelation:
|
|
13
|
+
case Model.HasOneRelation:
|
|
14
|
+
return {
|
|
15
|
+
from: SOURCE_MODEL_KEY,
|
|
16
|
+
to: `${FOREIGN_MODEL.tableName}.${opts?.to || targetClass.tableName + "Id"}`
|
|
17
|
+
};
|
|
18
|
+
case Model.ManyToManyRelation:
|
|
19
|
+
case Model.HasOneThroughRelation:
|
|
20
|
+
return {
|
|
21
|
+
from: SOURCE_MODEL_KEY,
|
|
22
|
+
through: (isRelationshipOptsWithThrough(opts) && opts.through) || {
|
|
23
|
+
from: `${targetClass.tableName}_${FOREIGN_MODEL.tableName}.${targetClass.tableName}Id`,
|
|
24
|
+
to: `${targetClass.tableName}_${FOREIGN_MODEL.tableName}.${FOREIGN_MODEL.tableName}Id`
|
|
25
|
+
},
|
|
26
|
+
to: FOREIGN_MODEL_KEY
|
|
27
|
+
};
|
|
28
|
+
case Model.BelongsToOneRelation:
|
|
29
|
+
default:
|
|
30
|
+
return {
|
|
31
|
+
from: `${targetClass.tableName}.${opts?.from || propertyKey + "Id"}`,
|
|
32
|
+
to: FOREIGN_MODEL_KEY
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=createJoinKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createJoinKeys.js","sourceRoot":"","sources":["../../../src/utils/createJoinKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAe,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAmB,6BAA6B,EAAC,MAAM,4BAA4B,CAAC;AAE3F,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,WAAgB,EAAE,WAAgB,EAAE,WAAmB,EAAE,QAAsB,EAAE,IAAuB;IACrI,MAAM,aAAa,GAAG,IAAI,EAAE,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAC/E,MAAM,gBAAgB,GAAG,GAAG,WAAW,CAAC,SAAS,IAAI,IAAI,EAAE,IAAI,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC1F,MAAM,iBAAiB,GAAG,GAAG,aAAa,CAAC,SAAS,IAAI,IAAI,EAAE,EAAE,IAAI,aAAa,CAAC,QAAQ,EAAE,CAAC;IAE7F,QAAQ,QAAQ,EAAE;QAChB,KAAK,KAAK,CAAC,eAAe,CAAC;QAC3B,KAAK,KAAK,CAAC,cAAc;YACvB,OAAO;gBACL,IAAI,EAAE,gBAAgB;gBACtB,EAAE,EAAE,GAAG,aAAa,CAAC,SAAS,IAAI,IAAI,EAAE,EAAE,IAAI,WAAW,CAAC,SAAS,GAAG,IAAI,EAAE;aAC7E,CAAC;QACJ,KAAK,KAAK,CAAC,kBAAkB,CAAC;QAC9B,KAAK,KAAK,CAAC,qBAAqB;YAC9B,OAAO;gBACL,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,CAAC,6BAA6B,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI;oBAChE,IAAI,EAAE,GAAG,WAAW,CAAC,SAAS,IAAI,aAAa,CAAC,SAAS,IAAI,WAAW,CAAC,SAAS,IAAI;oBACtF,EAAE,EAAE,GAAG,WAAW,CAAC,SAAS,IAAI,aAAa,CAAC,SAAS,IAAI,aAAa,CAAC,SAAS,IAAI;iBACvF;gBACD,EAAE,EAAE,iBAAiB;aACtB,CAAC;QACJ,KAAK,KAAK,CAAC,oBAAoB,CAAC;QAChC;YACE,OAAO;gBACL,IAAI,EAAE,GAAG,WAAW,CAAC,SAAS,IAAI,IAAI,EAAE,IAAI,IAAI,WAAW,GAAG,IAAI,EAAE;gBACpE,EAAE,EAAE,iBAAiB;aACtB,CAAC;KACL;AACH,CAAC","sourcesContent":["import {Model, RelationType} from \"objection\";\nimport {RelationshipOpts, isRelationshipOptsWithThrough} from \"../domain/RelationshipOpts\";\n\nimport {Metadata} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nexport function createJoinKeys(targetClass: any, targetSuper: any, propertyKey: string, relation: RelationType, opts?: RelationshipOpts) {\n const FOREIGN_MODEL = opts?.type || Metadata.getType(targetSuper, propertyKey);\n const SOURCE_MODEL_KEY = `${targetClass.tableName}.${opts?.from || targetClass.idColumn}`;\n const FOREIGN_MODEL_KEY = `${FOREIGN_MODEL.tableName}.${opts?.to || FOREIGN_MODEL.idColumn}`;\n\n switch (relation) {\n case Model.HasManyRelation:\n case Model.HasOneRelation:\n return {\n from: SOURCE_MODEL_KEY,\n to: `${FOREIGN_MODEL.tableName}.${opts?.to || targetClass.tableName + \"Id\"}`\n };\n case Model.ManyToManyRelation:\n case Model.HasOneThroughRelation:\n return {\n from: SOURCE_MODEL_KEY,\n through: (isRelationshipOptsWithThrough(opts) && opts.through) || {\n from: `${targetClass.tableName}_${FOREIGN_MODEL.tableName}.${targetClass.tableName}Id`,\n to: `${targetClass.tableName}_${FOREIGN_MODEL.tableName}.${FOREIGN_MODEL.tableName}Id`\n },\n to: FOREIGN_MODEL_KEY\n };\n case Model.BelongsToOneRelation:\n default:\n return {\n from: `${targetClass.tableName}.${opts?.from || propertyKey + \"Id\"}`,\n to: FOREIGN_MODEL_KEY\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Metadata } from "@tsed/core";
|
|
2
|
+
import { createJoinKeys } from "./createJoinKeys.js";
|
|
3
|
+
/**
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export function createRelationshipMapping([target, propertyKey], relation, opts) {
|
|
7
|
+
return (targetClass) => ({
|
|
8
|
+
[propertyKey]: {
|
|
9
|
+
relation,
|
|
10
|
+
modelClass: opts?.type || Metadata.getType(target, propertyKey),
|
|
11
|
+
join: createJoinKeys(targetClass, target, String(propertyKey), relation, opts),
|
|
12
|
+
modify: opts?.modify,
|
|
13
|
+
filter: opts?.filter,
|
|
14
|
+
beforeInsert: opts?.beforeInsert
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=createRelationshipMapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRelationshipMapping.js","sourceRoot":"","sources":["../../../src/utils/createRelationshipMapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,QAAQ,EAAW,MAAM,YAAY,CAAC;AAInE,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,CAAC,MAAM,EAAE,WAAW,CAAsB,EAAE,QAAsB,EAAE,IAAuB;IACnI,OAAO,CAAC,WAAgB,EAAE,EAAE,CAAC,CAAC;QAC5B,CAAC,WAAW,CAAC,EAAE;YACb,QAAQ;YACR,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC;YAC/D,IAAI,EAAE,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC;YAC9E,MAAM,EAAE,IAAI,EAAE,MAAM;YACpB,MAAM,EAAE,IAAI,EAAE,MAAM;YACpB,YAAY,EAAE,IAAI,EAAE,YAAY;SACjC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {DecoratorParameters, Metadata, getClass} from \"@tsed/core\";\n\nimport {RelationType} from \"objection\";\nimport {RelationshipOpts} from \"../domain/RelationshipOpts\";\nimport {createJoinKeys} from \"./createJoinKeys\";\n\n/**\n * @ignore\n */\nexport function createRelationshipMapping([target, propertyKey]: DecoratorParameters, relation: RelationType, opts?: RelationshipOpts) {\n return (targetClass: any) => ({\n [propertyKey]: {\n relation,\n modelClass: opts?.type || Metadata.getType(target, propertyKey),\n join: createJoinKeys(targetClass, target, String(propertyKey), relation, opts),\n modify: opts?.modify,\n filter: opts?.filter,\n beforeInsert: opts?.beforeInsert\n }\n });\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getColumns } from "./createColumns.js";
|
|
2
|
+
/**
|
|
3
|
+
* @ignore
|
|
4
|
+
*/
|
|
5
|
+
export const OBJECTION_RELATIONSHIP_KEY = "objectionRelationship";
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
export function getJsonEntityRelationships(target) {
|
|
10
|
+
return getColumns(target)
|
|
11
|
+
.filter((col) => col.store.get(OBJECTION_RELATIONSHIP_KEY))
|
|
12
|
+
.map((col) => col.store.get(OBJECTION_RELATIONSHIP_KEY)(target))
|
|
13
|
+
.reduce((dict, col) => ({ ...dict, ...col }), {});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=getJsonEntityRelationships.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getJsonEntityRelationships.js","sourceRoot":"","sources":["../../../src/utils/getJsonEntityRelationships.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,uBAAuB,CAAC;AAElE;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAW;IACpD,OAAO,UAAU,CAAC,MAAM,CAAC;SACtB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;SAC1D,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;SAC/D,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,IAAI,EAAE,GAAG,GAAG,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import {getColumns} from \"./createColumns\";\n\n/**\n * @ignore\n */\nexport const OBJECTION_RELATIONSHIP_KEY = \"objectionRelationship\";\n\n/**\n * @ignore\n */\nexport function getJsonEntityRelationships(target: any) {\n return getColumns(target)\n .filter((col) => col.store.get(OBJECTION_RELATIONSHIP_KEY))\n .map((col) => col.store.get(OBJECTION_RELATIONSHIP_KEY)(target))\n .reduce((dict, col) => ({...dict, ...col}), {});\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModelClassSpecifier } from "objection";
|
|
2
|
+
import { RelationshipOptsWithThrough } from "../domain/RelationshipOpts";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param opts
|
|
6
|
+
* @decorator
|
|
7
|
+
* @objection
|
|
8
|
+
*/
|
|
9
|
+
export declare function HasMany(type: ModelClassSpecifier, opts?: RelationshipOptsWithThrough): PropertyDecorator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModelClassSpecifier } from "objection";
|
|
2
|
+
import { RelationshipOptsWithThrough } from "../domain/RelationshipOpts";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param opts
|
|
6
|
+
* @decorator
|
|
7
|
+
* @objection
|
|
8
|
+
*/
|
|
9
|
+
export declare function ManyToMany(type: ModelClassSpecifier, opts?: RelationshipOptsWithThrough): PropertyDecorator;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RelationshipOpts } from "../domain/RelationshipOpts";
|
|
2
|
+
import { RelationType } from "objection";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param relation
|
|
6
|
+
* @param opts
|
|
7
|
+
* @decorator
|
|
8
|
+
* @objection
|
|
9
|
+
*/
|
|
10
|
+
export declare function RelatesTo(relation: RelationType, opts?: RelationshipOpts): PropertyDecorator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModelClassFactory, ModelClassSpecifier, RelationJoin, RelationMapping } from "objection";
|
|
2
|
+
export declare type RelationshipOptsWithThrough = Partial<RelationJoin> & Omit<RelationMapping<any>, "relation" | "join" | "modelClass">;
|
|
3
|
+
export declare type RelationshipOptsWithoutThrough = Omit<RelationshipOptsWithThrough, "through">;
|
|
4
|
+
export declare type RelationshipOpts = (RelationshipOptsWithThrough | RelationshipOptsWithoutThrough) & {
|
|
5
|
+
type?: ModelClassSpecifier;
|
|
6
|
+
};
|
|
7
|
+
export declare const isRelationshipOptsWithThrough: (opts?: RelationshipOpts) => opts is RelationshipOptsWithThrough;
|
|
8
|
+
export declare const isModelClassFactory: (type?: ModelClassSpecifier) => type is ModelClassFactory;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -5,15 +5,25 @@ export * from "./components/createBooleanColumn";
|
|
|
5
5
|
export * from "./components/createIdColumn";
|
|
6
6
|
export * from "./components/createNumberColumn";
|
|
7
7
|
export * from "./components/createStringColumn";
|
|
8
|
+
export * from "./decorators/belongsToOne";
|
|
8
9
|
export * from "./decorators/columnOptions";
|
|
9
10
|
export * from "./decorators/decimal";
|
|
10
11
|
export * from "./decorators/entity";
|
|
12
|
+
export * from "./decorators/hasMany";
|
|
13
|
+
export * from "./decorators/hasOne";
|
|
14
|
+
export * from "./decorators/hasOneThroughRelation";
|
|
11
15
|
export * from "./decorators/idColumn";
|
|
16
|
+
export * from "./decorators/manyToMany";
|
|
17
|
+
export * from "./decorators/relatesTo";
|
|
12
18
|
export * from "./domain/ColumnOpts";
|
|
19
|
+
export * from "./domain/RelationshipOpts";
|
|
13
20
|
export * from "./domain/interfaces";
|
|
14
21
|
export * from "./services/ColumnTypesContainer";
|
|
15
22
|
export * from "./services/ObjectionConnection";
|
|
16
23
|
export * from "./utils/connect";
|
|
17
24
|
export * from "./utils/createColumns";
|
|
25
|
+
export * from "./utils/createJoinKeys";
|
|
26
|
+
export * from "./utils/createRelationshipMapping";
|
|
18
27
|
export * from "./utils/defineStaticGetter";
|
|
19
28
|
export * from "./utils/getColumnCtx";
|
|
29
|
+
export * from "./utils/getJsonEntityRelationships";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RelationType } from "objection";
|
|
2
|
+
import { RelationshipOpts } from "../domain/RelationshipOpts";
|
|
3
|
+
/**
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export declare function createJoinKeys(targetClass: any, targetSuper: any, propertyKey: string, relation: RelationType, opts?: RelationshipOpts): {
|
|
7
|
+
from: string;
|
|
8
|
+
to: string;
|
|
9
|
+
through?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
from: string;
|
|
12
|
+
through: import("objection").RelationThrough<any>;
|
|
13
|
+
to: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DecoratorParameters } from "@tsed/core";
|
|
2
|
+
import { RelationType } from "objection";
|
|
3
|
+
import { RelationshipOpts } from "../domain/RelationshipOpts";
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export declare function createRelationshipMapping([target, propertyKey]: DecoratorParameters, relation: RelationType, opts?: RelationshipOpts): (targetClass: any) => {
|
|
8
|
+
[x: string]: {
|
|
9
|
+
relation: RelationType;
|
|
10
|
+
modelClass: any;
|
|
11
|
+
join: {
|
|
12
|
+
from: string;
|
|
13
|
+
to: string;
|
|
14
|
+
through?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
from: string;
|
|
17
|
+
through: import("objection").RelationThrough<any>;
|
|
18
|
+
to: string;
|
|
19
|
+
};
|
|
20
|
+
modify: import("objection").Modifier<any> | undefined;
|
|
21
|
+
filter: import("objection").Modifier<any> | undefined;
|
|
22
|
+
beforeInsert: import("objection").RelationMappingHook<any> | undefined;
|
|
23
|
+
};
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/objection",
|
|
3
|
-
"version": "7.0.0-rc.
|
|
3
|
+
"version": "7.0.0-rc.6",
|
|
4
4
|
"description": "Objection.js package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -24,21 +24,21 @@
|
|
|
24
24
|
"tslib": "2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/ajv": "7.0.0-rc.
|
|
28
|
-
"@tsed/core": "7.0.0-rc.
|
|
29
|
-
"@tsed/di": "7.0.0-rc.
|
|
30
|
-
"@tsed/json-mapper": "7.0.0-rc.
|
|
31
|
-
"@tsed/schema": "7.0.0-rc.
|
|
27
|
+
"@tsed/ajv": "7.0.0-rc.6",
|
|
28
|
+
"@tsed/core": "7.0.0-rc.6",
|
|
29
|
+
"@tsed/di": "7.0.0-rc.6",
|
|
30
|
+
"@tsed/json-mapper": "7.0.0-rc.6",
|
|
31
|
+
"@tsed/schema": "7.0.0-rc.6",
|
|
32
32
|
"knex": "^0.95.11",
|
|
33
33
|
"objection": "^2.2.15",
|
|
34
34
|
"sqlite3": "^5.0.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@tsed/ajv": "^7.0.0-rc.
|
|
38
|
-
"@tsed/core": "^7.0.0-rc.
|
|
39
|
-
"@tsed/di": "^7.0.0-rc.
|
|
40
|
-
"@tsed/json-mapper": "^7.0.0-rc.
|
|
41
|
-
"@tsed/schema": "^7.0.0-rc.
|
|
37
|
+
"@tsed/ajv": "^7.0.0-rc.6",
|
|
38
|
+
"@tsed/core": "^7.0.0-rc.6",
|
|
39
|
+
"@tsed/di": "^7.0.0-rc.6",
|
|
40
|
+
"@tsed/json-mapper": "^7.0.0-rc.6",
|
|
41
|
+
"@tsed/schema": "^7.0.0-rc.6",
|
|
42
42
|
"knex": ">=0.94.0",
|
|
43
43
|
"objection": ">=2.0.0"
|
|
44
44
|
},
|