@aiminaabeejs/link-modules 0.0.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/dist/definitions/index.d.ts +4 -0
- package/dist/definitions/index.d.ts.map +1 -0
- package/dist/definitions/index.js +20 -0
- package/dist/definitions/index.js.map +1 -0
- package/dist/definitions/order-cart.d.ts +3 -0
- package/dist/definitions/order-cart.d.ts.map +1 -0
- package/dist/definitions/order-cart.js +71 -0
- package/dist/definitions/order-cart.js.map +1 -0
- package/dist/definitions/product-sales-channel.d.ts +3 -0
- package/dist/definitions/product-sales-channel.d.ts.map +1 -0
- package/dist/definitions/product-sales-channel.js +76 -0
- package/dist/definitions/product-sales-channel.js.map +1 -0
- package/dist/definitions/product-variant-price-set.d.ts +3 -0
- package/dist/definitions/product-variant-price-set.d.ts.map +1 -0
- package/dist/definitions/product-variant-price-set.js +80 -0
- package/dist/definitions/product-variant-price-set.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/initialize/index.d.ts +16 -0
- package/dist/initialize/index.d.ts.map +1 -0
- package/dist/initialize/index.js +159 -0
- package/dist/initialize/index.js.map +1 -0
- package/dist/initialize/module-definition.d.ts +3 -0
- package/dist/initialize/module-definition.d.ts.map +1 -0
- package/dist/initialize/module-definition.js +18 -0
- package/dist/initialize/module-definition.js.map +1 -0
- package/dist/loaders/connection.d.ts +4 -0
- package/dist/loaders/connection.d.ts.map +1 -0
- package/dist/loaders/connection.js +19 -0
- package/dist/loaders/connection.js.map +1 -0
- package/dist/loaders/container.d.ts +3 -0
- package/dist/loaders/container.d.ts.map +1 -0
- package/dist/loaders/container.js +32 -0
- package/dist/loaders/container.js.map +1 -0
- package/dist/loaders/index.d.ts +7 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +14 -0
- package/dist/loaders/index.js.map +1 -0
- package/dist/migration/index.d.ts +104 -0
- package/dist/migration/index.d.ts.map +1 -0
- package/dist/migration/index.js +371 -0
- package/dist/migration/index.js.map +1 -0
- package/dist/repositories/index.d.ts +3 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +8 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/repositories/link.d.ts +35 -0
- package/dist/repositories/link.d.ts.map +1 -0
- package/dist/repositories/link.js +33 -0
- package/dist/repositories/link.js.map +1 -0
- package/dist/services/dynamic-service-class.d.ts +8 -0
- package/dist/services/dynamic-service-class.d.ts.map +1 -0
- package/dist/services/dynamic-service-class.js +32 -0
- package/dist/services/dynamic-service-class.js.map +1 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +26 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/link-module-service.d.ts +42 -0
- package/dist/services/link-module-service.d.ts.map +1 -0
- package/dist/services/link-module-service.js +286 -0
- package/dist/services/link-module-service.js.map +1 -0
- package/dist/services/link.d.ts +18 -0
- package/dist/services/link.d.ts.map +1 -0
- package/dist/services/link.js +139 -0
- package/dist/services/link.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/generate-entity.d.ts +4 -0
- package/dist/utils/generate-entity.d.ts.map +1 -0
- package/dist/utils/generate-entity.js +98 -0
- package/dist/utils/generate-entity.js.map +1 -0
- package/dist/utils/generate-schema.d.ts +5 -0
- package/dist/utils/generate-schema.d.ts.map +1 -0
- package/dist/utils/generate-schema.js +156 -0
- package/dist/utils/generate-schema.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.containerLoader = containerLoader;
|
|
4
|
+
const repositories_1 = require("../repositories");
|
|
5
|
+
const services_1 = require("../services");
|
|
6
|
+
const utils_1 = require("@aiminaabeejs/framework/utils");
|
|
7
|
+
const awilix_1 = require("awilix");
|
|
8
|
+
function containerLoader(entity, joinerConfig) {
|
|
9
|
+
return async ({ options, container, }, moduleDeclaration) => {
|
|
10
|
+
const [primary, foreign] = joinerConfig.relationships;
|
|
11
|
+
const serviceName = !joinerConfig.isReadOnlyLink
|
|
12
|
+
? joinerConfig.serviceName ??
|
|
13
|
+
(0, utils_1.composeLinkName)(primary.serviceName, primary.foreignKey, foreign.serviceName, foreign.foreignKey)
|
|
14
|
+
: (0, utils_1.simpleHash)(JSON.stringify(joinerConfig.extends));
|
|
15
|
+
const entityName = (0, utils_1.toPascalCase)("Link_" +
|
|
16
|
+
(joinerConfig.databaseConfig?.tableName ??
|
|
17
|
+
(0, utils_1.composeTableName)(primary.serviceName, primary.foreignKey, foreign.serviceName, foreign.foreignKey)));
|
|
18
|
+
container.register({
|
|
19
|
+
joinerConfig: (0, awilix_1.asValue)(joinerConfig),
|
|
20
|
+
primaryKey: (0, awilix_1.asValue)(primary.foreignKey.split(",")),
|
|
21
|
+
foreignKey: (0, awilix_1.asValue)(foreign.foreignKey),
|
|
22
|
+
extraFields: (0, awilix_1.asValue)(Object.keys(joinerConfig.databaseConfig?.extraFields || {})),
|
|
23
|
+
linkModuleService: (0, awilix_1.asClass)((0, services_1.getModuleService)(joinerConfig)).singleton(),
|
|
24
|
+
linkService: (0, awilix_1.asClass)(services_1.LinkService).singleton(),
|
|
25
|
+
baseRepository: (0, awilix_1.asClass)(repositories_1.BaseRepository).singleton(),
|
|
26
|
+
linkRepository: (0, awilix_1.asClass)((0, repositories_1.getLinkRepository)(entity)).singleton(),
|
|
27
|
+
entityName: (0, awilix_1.asValue)(entityName),
|
|
28
|
+
serviceName: (0, awilix_1.asValue)(serviceName),
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/loaders/container.ts"],"names":[],"mappings":";;AAgBA,0CAmDC;AAnED,kDAAmE;AACnE,0CAA2D;AAQ3D,yDAKsC;AACtC,mCAAyC;AACzC,SAAgB,eAAe,CAAC,MAAM,EAAE,YAAgC;IACtE,OAAO,KAAK,EACV,EACE,OAAO,EACP,SAAS,GAIV,EACD,iBAA6C,EAC9B,EAAE;QACjB,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC,aAAc,CAAA;QAEtD,MAAM,WAAW,GAAG,CAAC,YAAY,CAAC,cAAc;YAC9C,CAAC,CAAC,YAAY,CAAC,WAAW;gBACxB,IAAA,uBAAe,EACb,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,UAAU,CACnB;YACH,CAAC,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;QAEpD,MAAM,UAAU,GAAG,IAAA,oBAAY,EAC7B,OAAO;YACL,CAAC,YAAY,CAAC,cAAc,EAAE,SAAS;gBACrC,IAAA,wBAAgB,EACd,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,UAAU,CACnB,CAAC,CACP,CAAA;QAED,SAAS,CAAC,QAAQ,CAAC;YACjB,YAAY,EAAE,IAAA,gBAAO,EAAC,YAAY,CAAC;YACnC,UAAU,EAAE,IAAA,gBAAO,EAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClD,UAAU,EAAE,IAAA,gBAAO,EAAC,OAAO,CAAC,UAAU,CAAC;YACvC,WAAW,EAAE,IAAA,gBAAO,EAClB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,WAAW,IAAI,EAAE,CAAC,CAC5D;YAED,iBAAiB,EAAE,IAAA,gBAAO,EAAC,IAAA,2BAAgB,EAAC,YAAY,CAAC,CAAC,CAAC,SAAS,EAAE;YACtE,WAAW,EAAE,IAAA,gBAAO,EAAC,sBAAW,CAAC,CAAC,SAAS,EAAE;YAE7C,cAAc,EAAE,IAAA,gBAAO,EAAC,6BAAc,CAAC,CAAC,SAAS,EAAE;YACnD,cAAc,EAAE,IAAA,gBAAO,EAAC,IAAA,gCAAiB,EAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE;YAC9D,UAAU,EAAE,IAAA,gBAAO,EAAC,UAAU,CAAC;YAC/B,WAAW,EAAE,IAAA,gBAAO,EAAC,WAAW,CAAC;SAClC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JoinerRelationship, ModuleJoinerConfig, ModuleLoaderFunction } from "@aiminaabeejs/framework/types";
|
|
2
|
+
export declare function getLoaders({ joinerConfig, primary, foreign, }: {
|
|
3
|
+
joinerConfig: ModuleJoinerConfig;
|
|
4
|
+
primary: JoinerRelationship;
|
|
5
|
+
foreign: JoinerRelationship;
|
|
6
|
+
}): ModuleLoaderFunction[];
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,+BAA+B,CAAA;AAMtC,wBAAgB,UAAU,CAAC,EACzB,YAAY,EACZ,OAAO,EACP,OAAO,GACR,EAAE;IACD,YAAY,EAAE,kBAAkB,CAAA;IAChC,OAAO,EAAE,kBAAkB,CAAA;IAC3B,OAAO,EAAE,kBAAkB,CAAA;CAC5B,GAAG,oBAAoB,EAAE,CAOzB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLoaders = getLoaders;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const connection_1 = require("./connection");
|
|
6
|
+
const container_1 = require("./container");
|
|
7
|
+
function getLoaders({ joinerConfig, primary, foreign, }) {
|
|
8
|
+
if (joinerConfig.isReadOnlyLink) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const entity = (0, utils_1.generateEntity)(joinerConfig, primary, foreign);
|
|
12
|
+
return [(0, connection_1.connectionLoader)(entity), (0, container_1.containerLoader)(entity, joinerConfig)];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":";;AAUA,gCAeC;AAnBD,oCAAyC;AACzC,6CAA+C;AAC/C,2CAA6C;AAE7C,SAAgB,UAAU,CAAC,EACzB,YAAY,EACZ,OAAO,EACP,OAAO,GAKR;IACC,IAAI,YAAY,CAAC,cAAc,EAAE,CAAC;QAChC,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,MAAM,GAAG,IAAA,sBAAc,EAAC,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7D,OAAO,CAAC,IAAA,6BAAgB,EAAC,MAAM,CAAC,EAAE,IAAA,2BAAe,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAA;AAC1E,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ILinkMigrationsPlanner, LinkMigrationsPlannerAction, ModuleJoinerConfig, ModuleServiceInitializeOptions, PlannerActionLinkDescriptor } from "@aiminaabeejs/framework/types";
|
|
2
|
+
import { EntitySchema, MikroORM } from "@mikro-orm/core";
|
|
3
|
+
import { PostgreSqlDriver } from "@mikro-orm/postgresql";
|
|
4
|
+
/**
|
|
5
|
+
* The migrations execution planner creates a plan of SQL queries
|
|
6
|
+
* to be executed to keep link modules database state in sync
|
|
7
|
+
* with the links defined inside the user application.
|
|
8
|
+
*/
|
|
9
|
+
export declare class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* The table that keeps a track of tables generated by the link
|
|
13
|
+
* module.
|
|
14
|
+
*/
|
|
15
|
+
protected tableName: string;
|
|
16
|
+
constructor(joinerConfig: ModuleJoinerConfig[], options?: ModuleServiceInitializeOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Initializes the ORM using the normalized dbConfig and set
|
|
19
|
+
* of provided entities
|
|
20
|
+
*/
|
|
21
|
+
protected createORM(entities?: EntitySchema[]): Promise<MikroORM<PostgreSqlDriver, import("@mikro-orm/postgresql").EntityManager<PostgreSqlDriver> & import("@mikro-orm/core").EntityManager<import("@mikro-orm/core").IDatabaseDriver<import("@mikro-orm/core").Connection>>>>;
|
|
22
|
+
/**
|
|
23
|
+
* Ensure the table to track link modules migrations
|
|
24
|
+
* exists.
|
|
25
|
+
*
|
|
26
|
+
* @param orm MikroORM
|
|
27
|
+
*/
|
|
28
|
+
protected ensureMigrationsTable(orm: MikroORM<PostgreSqlDriver>): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Ensure the migrations table is in sync
|
|
31
|
+
*
|
|
32
|
+
* @param orm
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
35
|
+
protected ensureMigrationsTableUpToDate(orm: MikroORM<PostgreSqlDriver>): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Insert tuple to the migrations table and create the link table
|
|
38
|
+
*
|
|
39
|
+
* @param orm
|
|
40
|
+
* @param action
|
|
41
|
+
* @protected
|
|
42
|
+
*/
|
|
43
|
+
protected createLinkTable(orm: MikroORM<PostgreSqlDriver>, action: LinkMigrationsPlannerAction & {
|
|
44
|
+
linkDescriptor: PlannerActionLinkDescriptor;
|
|
45
|
+
sql: string;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Drops the link table and untracks it from the "link_modules_migrations"
|
|
49
|
+
* table.
|
|
50
|
+
*/
|
|
51
|
+
protected dropLinkTable(orm: MikroORM<PostgreSqlDriver>, tableName: string): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Returns an array of table names that have been tracked during
|
|
54
|
+
* the last run. In short, these tables were created by the
|
|
55
|
+
* link modules migrations runner.
|
|
56
|
+
*
|
|
57
|
+
* @param orm MikroORM
|
|
58
|
+
*/
|
|
59
|
+
protected getTrackedLinksTables(orm: MikroORM<PostgreSqlDriver>): Promise<{
|
|
60
|
+
table_name: string;
|
|
61
|
+
link_descriptor: PlannerActionLinkDescriptor;
|
|
62
|
+
}[]>;
|
|
63
|
+
private pickTableRelatedCommands;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the migration plan for a specific link entity.
|
|
66
|
+
*/
|
|
67
|
+
protected getEntityMigrationPlan(linkDescriptor: PlannerActionLinkDescriptor, entity: EntitySchema, trackedLinksTables: string[]): Promise<LinkMigrationsPlannerAction>;
|
|
68
|
+
/**
|
|
69
|
+
* This method loops over the tables we have fetched from the
|
|
70
|
+
* "link_module_migrations" tables and checks if their new
|
|
71
|
+
* name is different from the tracked name and in that
|
|
72
|
+
* case it will rename the actual table and also the
|
|
73
|
+
* tracked entry.
|
|
74
|
+
*/
|
|
75
|
+
protected migrateOldTables(orm: MikroORM<PostgreSqlDriver>, trackedTables: {
|
|
76
|
+
table_name: string;
|
|
77
|
+
link_descriptor: PlannerActionLinkDescriptor;
|
|
78
|
+
}[]): Promise<{
|
|
79
|
+
table_name: string;
|
|
80
|
+
link_descriptor: PlannerActionLinkDescriptor;
|
|
81
|
+
}[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Renames existing table and also its tracked entry
|
|
84
|
+
*/
|
|
85
|
+
protected renameOldTable(orm: MikroORM<PostgreSqlDriver>, oldName: string, newName: string, descriptor: PlannerActionLinkDescriptor): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a plan to executed in order to keep the database state in
|
|
88
|
+
* sync with the user-defined links.
|
|
89
|
+
*
|
|
90
|
+
* This method only creates a plan and does not change the database
|
|
91
|
+
* state. You must call the "executePlan" method for that.
|
|
92
|
+
*/
|
|
93
|
+
createPlan(): Promise<LinkMigrationsPlannerAction[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Executes the actionsPlan actions where the action is one of 'create' | 'update' | 'delete'.
|
|
96
|
+
* 'noop' and 'notify' actions are implicitly ignored. If a notify action needs to be
|
|
97
|
+
* executed, you can mutate its action to 'update', in that scenario it means that an unsafe
|
|
98
|
+
* update sql (from our point of view) will be executed and some data could be lost.
|
|
99
|
+
*
|
|
100
|
+
* @param actionPlan
|
|
101
|
+
*/
|
|
102
|
+
executePlan(actionPlan: LinkMigrationsPlannerAction[]): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migration/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,8BAA8B,EAC9B,2BAA2B,EAC5B,MAAM,+BAA+B,CAAA;AAStC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAkB,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxE;;;;GAIG;AACH,qBAAa,0BAA2B,YAAW,sBAAsB;;IAoBvE;;;OAGG;IACH,SAAS,CAAC,SAAS,SAA2B;gBAG5C,YAAY,EAAE,kBAAkB,EAAE,EAClC,OAAO,CAAC,EAAE,8BAA8B;IAyB1C;;;OAGG;cACa,SAAS,CA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hB;;;;;;;OAOG;IACG,WAAW,CAAC,UAAU,EAAE,2BAA2B,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAkB5E"}
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _MigrationsExecutionPlanner_dbConfig, _MigrationsExecutionPlanner_unsafeSQLCommands, _MigrationsExecutionPlanner_linksEntities;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MigrationsExecutionPlanner = void 0;
|
|
16
|
+
const utils_1 = require("@aiminaabeejs/framework/utils");
|
|
17
|
+
const postgresql_1 = require("@mikro-orm/postgresql");
|
|
18
|
+
const utils_2 = require("../utils");
|
|
19
|
+
/**
|
|
20
|
+
* The migrations execution planner creates a plan of SQL queries
|
|
21
|
+
* to be executed to keep link modules database state in sync
|
|
22
|
+
* with the links defined inside the user application.
|
|
23
|
+
*/
|
|
24
|
+
class MigrationsExecutionPlanner {
|
|
25
|
+
constructor(joinerConfig, options) {
|
|
26
|
+
/**
|
|
27
|
+
* Database options for the module service
|
|
28
|
+
*/
|
|
29
|
+
_MigrationsExecutionPlanner_dbConfig.set(this, void 0);
|
|
30
|
+
/**
|
|
31
|
+
* The set of commands that are unsafe to execute automatically when
|
|
32
|
+
* performing "alter table"
|
|
33
|
+
*/
|
|
34
|
+
_MigrationsExecutionPlanner_unsafeSQLCommands.set(this, ["alter column", "drop column"]
|
|
35
|
+
/**
|
|
36
|
+
* On-the-fly computed set of entities for the user provided joinerConfig and the link it is coming from
|
|
37
|
+
*/
|
|
38
|
+
);
|
|
39
|
+
/**
|
|
40
|
+
* On-the-fly computed set of entities for the user provided joinerConfig and the link it is coming from
|
|
41
|
+
*/
|
|
42
|
+
_MigrationsExecutionPlanner_linksEntities.set(this, void 0);
|
|
43
|
+
/**
|
|
44
|
+
* The table that keeps a track of tables generated by the link
|
|
45
|
+
* module.
|
|
46
|
+
*/
|
|
47
|
+
this.tableName = "link_module_migrations";
|
|
48
|
+
__classPrivateFieldSet(this, _MigrationsExecutionPlanner_dbConfig, utils_1.ModulesSdkUtils.loadDatabaseConfig("link_modules", options), "f");
|
|
49
|
+
__classPrivateFieldSet(this, _MigrationsExecutionPlanner_linksEntities, joinerConfig
|
|
50
|
+
.map((config) => {
|
|
51
|
+
if (config.isReadOnlyLink) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const [primary, foreign] = config.relationships ?? [];
|
|
55
|
+
const linkDescriptor = {
|
|
56
|
+
fromModule: primary.serviceName,
|
|
57
|
+
toModule: foreign.serviceName,
|
|
58
|
+
fromModel: primary.alias,
|
|
59
|
+
toModel: foreign.alias,
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
entity: (0, utils_2.generateEntity)(config, primary, foreign),
|
|
63
|
+
linkDescriptor,
|
|
64
|
+
};
|
|
65
|
+
})
|
|
66
|
+
.filter((item) => !!item), "f");
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Initializes the ORM using the normalized dbConfig and set
|
|
70
|
+
* of provided entities
|
|
71
|
+
*/
|
|
72
|
+
async createORM(entities = []) {
|
|
73
|
+
return await utils_1.DALUtils.mikroOrmCreateConnection(__classPrivateFieldGet(this, _MigrationsExecutionPlanner_dbConfig, "f"), entities, "");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Ensure the table to track link modules migrations
|
|
77
|
+
* exists.
|
|
78
|
+
*
|
|
79
|
+
* @param orm MikroORM
|
|
80
|
+
*/
|
|
81
|
+
async ensureMigrationsTable(orm) {
|
|
82
|
+
await orm.em.getDriver().getConnection().execute(`
|
|
83
|
+
CREATE TABLE IF NOT EXISTS "${this.tableName}" (
|
|
84
|
+
id SERIAL PRIMARY KEY,
|
|
85
|
+
table_name VARCHAR(255) NOT NULL UNIQUE,
|
|
86
|
+
link_descriptor JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
87
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
88
|
+
)
|
|
89
|
+
`);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Ensure the migrations table is in sync
|
|
93
|
+
*
|
|
94
|
+
* @param orm
|
|
95
|
+
* @protected
|
|
96
|
+
*/
|
|
97
|
+
async ensureMigrationsTableUpToDate(orm) {
|
|
98
|
+
const existingTables = (await orm.em
|
|
99
|
+
.getDriver()
|
|
100
|
+
.getConnection()
|
|
101
|
+
.execute(`
|
|
102
|
+
SELECT table_name
|
|
103
|
+
FROM information_schema.tables;
|
|
104
|
+
`))
|
|
105
|
+
.map(({ table_name }) => table_name)
|
|
106
|
+
.filter((tableName) => __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f").some(({ entity }) => entity.meta.collection === tableName));
|
|
107
|
+
if (!existingTables.length) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const orderedDescriptors = existingTables.map((tableName) => {
|
|
111
|
+
return __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f").find(({ entity }) => entity.meta.collection === tableName).linkDescriptor;
|
|
112
|
+
});
|
|
113
|
+
const positionalArgs = new Array(existingTables.length)
|
|
114
|
+
.fill("(?, ?)")
|
|
115
|
+
.join(", ");
|
|
116
|
+
await orm.em
|
|
117
|
+
.getDriver()
|
|
118
|
+
.getConnection()
|
|
119
|
+
.execute(`
|
|
120
|
+
INSERT INTO ${this.tableName} (table_name, link_descriptor) VALUES ${positionalArgs} ON CONFLICT DO NOTHING;
|
|
121
|
+
`, existingTables.flatMap((tableName, index) => [
|
|
122
|
+
tableName,
|
|
123
|
+
JSON.stringify(orderedDescriptors[index]),
|
|
124
|
+
]));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Insert tuple to the migrations table and create the link table
|
|
128
|
+
*
|
|
129
|
+
* @param orm
|
|
130
|
+
* @param action
|
|
131
|
+
* @protected
|
|
132
|
+
*/
|
|
133
|
+
async createLinkTable(orm, action) {
|
|
134
|
+
const { tableName, linkDescriptor, sql } = action;
|
|
135
|
+
await orm.em
|
|
136
|
+
.getDriver()
|
|
137
|
+
.getConnection()
|
|
138
|
+
.execute(`
|
|
139
|
+
INSERT INTO "${this.tableName}" (table_name, link_descriptor) VALUES (?, ?);
|
|
140
|
+
${sql}
|
|
141
|
+
`, [tableName, linkDescriptor]);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Drops the link table and untracks it from the "link_modules_migrations"
|
|
145
|
+
* table.
|
|
146
|
+
*/
|
|
147
|
+
async dropLinkTable(orm, tableName) {
|
|
148
|
+
await orm.em.getDriver().getConnection().execute(`
|
|
149
|
+
DROP TABLE IF EXISTS "${tableName}";
|
|
150
|
+
DELETE FROM "${this.tableName}" WHERE table_name = '${tableName}';
|
|
151
|
+
`);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns an array of table names that have been tracked during
|
|
155
|
+
* the last run. In short, these tables were created by the
|
|
156
|
+
* link modules migrations runner.
|
|
157
|
+
*
|
|
158
|
+
* @param orm MikroORM
|
|
159
|
+
*/
|
|
160
|
+
async getTrackedLinksTables(orm) {
|
|
161
|
+
const results = await orm.em.getDriver().getConnection().execute(`
|
|
162
|
+
SELECT table_name, link_descriptor from "${this.tableName}"
|
|
163
|
+
`);
|
|
164
|
+
return results.map((tuple) => ({
|
|
165
|
+
table_name: tuple.table_name,
|
|
166
|
+
link_descriptor: tuple.link_descriptor,
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
pickTableRelatedCommands(tableName, sqlCommand) {
|
|
170
|
+
const ignoreColumns = ["created_at", "updated_at", "deleted_at"];
|
|
171
|
+
const commands = sqlCommand.split(";");
|
|
172
|
+
const returnedCommands = commands
|
|
173
|
+
.filter((command) => {
|
|
174
|
+
const cmd = command.trim();
|
|
175
|
+
return (cmd.length &&
|
|
176
|
+
cmd !== "set names 'utf8'" &&
|
|
177
|
+
cmd.includes(`"${tableName}"`) &&
|
|
178
|
+
!ignoreColumns.some((column) => cmd.includes(`column "${column}"`)));
|
|
179
|
+
})
|
|
180
|
+
.map((cmd) => cmd.trim());
|
|
181
|
+
if (returnedCommands.length > 0) {
|
|
182
|
+
// adds ; at the end of each command
|
|
183
|
+
returnedCommands.push("");
|
|
184
|
+
}
|
|
185
|
+
return returnedCommands.join(";");
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns the migration plan for a specific link entity.
|
|
189
|
+
*/
|
|
190
|
+
async getEntityMigrationPlan(linkDescriptor, entity, trackedLinksTables) {
|
|
191
|
+
const tableName = entity.meta.collection;
|
|
192
|
+
const orm = await this.createORM([entity]);
|
|
193
|
+
try {
|
|
194
|
+
const generator = orm.getSchemaGenerator();
|
|
195
|
+
const platform = orm.em.getPlatform();
|
|
196
|
+
const connection = orm.em.getConnection();
|
|
197
|
+
const schemaName = __classPrivateFieldGet(this, _MigrationsExecutionPlanner_dbConfig, "f").schema || "public";
|
|
198
|
+
/**
|
|
199
|
+
* If the table name for the entity has not been
|
|
200
|
+
* managed by us earlier, then we should create
|
|
201
|
+
* it.
|
|
202
|
+
*/
|
|
203
|
+
if (!trackedLinksTables.includes(tableName)) {
|
|
204
|
+
return {
|
|
205
|
+
action: "create",
|
|
206
|
+
linkDescriptor,
|
|
207
|
+
tableName,
|
|
208
|
+
sql: (0, utils_1.normalizeMigrationSQL)(await generator.getCreateSchemaSQL()),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Pre-fetching information schema from the database and using that
|
|
213
|
+
* as the way to compute the update diff.
|
|
214
|
+
*
|
|
215
|
+
* @note
|
|
216
|
+
* The "loadInformationSchema" mutates the "dbSchema" argument provided
|
|
217
|
+
* to it as the first argument.
|
|
218
|
+
*/
|
|
219
|
+
const dbSchema = new postgresql_1.DatabaseSchema(platform, schemaName);
|
|
220
|
+
await platform
|
|
221
|
+
.getSchemaHelper?.()
|
|
222
|
+
?.loadInformationSchema(dbSchema, connection, [
|
|
223
|
+
{
|
|
224
|
+
table_name: tableName,
|
|
225
|
+
schema_name: schemaName,
|
|
226
|
+
},
|
|
227
|
+
]);
|
|
228
|
+
let updateSQL = (0, utils_1.normalizeMigrationSQL)(await generator.getUpdateSchemaSQL({
|
|
229
|
+
fromSchema: dbSchema,
|
|
230
|
+
}));
|
|
231
|
+
updateSQL = this.pickTableRelatedCommands(tableName, updateSQL);
|
|
232
|
+
/**
|
|
233
|
+
* Entity is upto-date and hence we do not have to perform
|
|
234
|
+
* any updates on it.
|
|
235
|
+
*/
|
|
236
|
+
if (!updateSQL.length) {
|
|
237
|
+
return {
|
|
238
|
+
action: "noop",
|
|
239
|
+
linkDescriptor,
|
|
240
|
+
tableName,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const usesUnsafeCommands = __classPrivateFieldGet(this, _MigrationsExecutionPlanner_unsafeSQLCommands, "f").some((fragment) => {
|
|
244
|
+
return updateSQL.match(new RegExp(`${fragment}`, "ig"));
|
|
245
|
+
});
|
|
246
|
+
return {
|
|
247
|
+
action: usesUnsafeCommands ? "notify" : "update",
|
|
248
|
+
linkDescriptor,
|
|
249
|
+
tableName,
|
|
250
|
+
sql: updateSQL,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
finally {
|
|
254
|
+
await orm.close(true);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* This method loops over the tables we have fetched from the
|
|
259
|
+
* "link_module_migrations" tables and checks if their new
|
|
260
|
+
* name is different from the tracked name and in that
|
|
261
|
+
* case it will rename the actual table and also the
|
|
262
|
+
* tracked entry.
|
|
263
|
+
*/
|
|
264
|
+
async migrateOldTables(orm, trackedTables) {
|
|
265
|
+
const migratedTables = [];
|
|
266
|
+
for (let trackedTable of trackedTables) {
|
|
267
|
+
const linkEntity = __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f").find((entity) => {
|
|
268
|
+
return (entity.linkDescriptor.fromModel ===
|
|
269
|
+
trackedTable.link_descriptor.fromModel &&
|
|
270
|
+
entity.linkDescriptor.toModel ===
|
|
271
|
+
trackedTable.link_descriptor.toModel &&
|
|
272
|
+
entity.linkDescriptor.fromModule.toLowerCase() ===
|
|
273
|
+
trackedTable.link_descriptor.fromModule.toLowerCase() &&
|
|
274
|
+
entity.linkDescriptor.toModule.toLowerCase() ===
|
|
275
|
+
trackedTable.link_descriptor.toModule.toLowerCase());
|
|
276
|
+
});
|
|
277
|
+
const newTableName = linkEntity?.entity.meta.collection;
|
|
278
|
+
/**
|
|
279
|
+
* Perform rename
|
|
280
|
+
*/
|
|
281
|
+
if (newTableName && trackedTable.table_name !== newTableName) {
|
|
282
|
+
await this.renameOldTable(orm, trackedTable.table_name, newTableName, linkEntity.linkDescriptor);
|
|
283
|
+
migratedTables.push({
|
|
284
|
+
...trackedTable,
|
|
285
|
+
table_name: newTableName,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
migratedTables.push({
|
|
290
|
+
...trackedTable,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return migratedTables;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Renames existing table and also its tracked entry
|
|
298
|
+
*/
|
|
299
|
+
async renameOldTable(orm, oldName, newName, descriptor) {
|
|
300
|
+
await orm.em.getDriver().getConnection().execute(`
|
|
301
|
+
ALTER TABLE "${oldName}" RENAME TO "${newName}";
|
|
302
|
+
UPDATE "${this.tableName}" SET table_name = '${newName}', link_descriptor = '${JSON.stringify(descriptor)}' WHERE table_name = '${oldName}';
|
|
303
|
+
`);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Creates a plan to executed in order to keep the database state in
|
|
307
|
+
* sync with the user-defined links.
|
|
308
|
+
*
|
|
309
|
+
* This method only creates a plan and does not change the database
|
|
310
|
+
* state. You must call the "executePlan" method for that.
|
|
311
|
+
*/
|
|
312
|
+
async createPlan() {
|
|
313
|
+
const orm = await this.createORM();
|
|
314
|
+
try {
|
|
315
|
+
await this.ensureMigrationsTable(orm);
|
|
316
|
+
const executionActions = [];
|
|
317
|
+
await this.ensureMigrationsTableUpToDate(orm);
|
|
318
|
+
const trackedTables = await this.migrateOldTables(orm, await this.getTrackedLinksTables(orm));
|
|
319
|
+
const trackedTablesNames = trackedTables.map(({ table_name }) => table_name);
|
|
320
|
+
/**
|
|
321
|
+
* Looping through the new set of entities and generating
|
|
322
|
+
* execution plan for them
|
|
323
|
+
*/
|
|
324
|
+
for (let { entity, linkDescriptor } of __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f")) {
|
|
325
|
+
executionActions.push(await this.getEntityMigrationPlan(linkDescriptor, entity, trackedTablesNames));
|
|
326
|
+
}
|
|
327
|
+
const linksTableNames = __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f").map(({ entity }) => entity.meta.collection);
|
|
328
|
+
/**
|
|
329
|
+
* Finding the tables to be removed
|
|
330
|
+
*/
|
|
331
|
+
const tablesToRemove = (0, utils_1.arrayDifference)(trackedTablesNames, linksTableNames);
|
|
332
|
+
tablesToRemove.forEach((tableToRemove) => {
|
|
333
|
+
executionActions.push({
|
|
334
|
+
action: "delete",
|
|
335
|
+
tableName: tableToRemove,
|
|
336
|
+
linkDescriptor: trackedTables.find(({ table_name }) => tableToRemove === table_name).link_descriptor,
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
return executionActions;
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
await orm.close(true);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Executes the actionsPlan actions where the action is one of 'create' | 'update' | 'delete'.
|
|
347
|
+
* 'noop' and 'notify' actions are implicitly ignored. If a notify action needs to be
|
|
348
|
+
* executed, you can mutate its action to 'update', in that scenario it means that an unsafe
|
|
349
|
+
* update sql (from our point of view) will be executed and some data could be lost.
|
|
350
|
+
*
|
|
351
|
+
* @param actionPlan
|
|
352
|
+
*/
|
|
353
|
+
async executePlan(actionPlan) {
|
|
354
|
+
const orm = await this.createORM();
|
|
355
|
+
await (0, utils_1.promiseAll)(actionPlan.map(async (action) => {
|
|
356
|
+
switch (action.action) {
|
|
357
|
+
case "delete":
|
|
358
|
+
return await this.dropLinkTable(orm, action.tableName);
|
|
359
|
+
case "create":
|
|
360
|
+
return await this.createLinkTable(orm, action);
|
|
361
|
+
case "update":
|
|
362
|
+
return await orm.em.getDriver().getConnection().execute(action.sql);
|
|
363
|
+
default:
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
})).finally(() => orm.close(true));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
exports.MigrationsExecutionPlanner = MigrationsExecutionPlanner;
|
|
370
|
+
_MigrationsExecutionPlanner_dbConfig = new WeakMap(), _MigrationsExecutionPlanner_unsafeSQLCommands = new WeakMap(), _MigrationsExecutionPlanner_linksEntities = new WeakMap();
|
|
371
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0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ACrE;oBACE,OAAM;YACV,CAAC;QACH,CAAC,CAAC,CACH,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IAClC,CAAC;CACF;AAteD,gEAseC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLinkRepository = exports.BaseRepository = void 0;
|
|
4
|
+
var utils_1 = require("@aiminaabeejs/framework/utils");
|
|
5
|
+
Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return utils_1.MikroOrmBaseRepository; } });
|
|
6
|
+
var link_1 = require("./link");
|
|
7
|
+
Object.defineProperty(exports, "getLinkRepository", { enumerable: true, get: function () { return link_1.getLinkRepository; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":";;;AAAA,uDAAwF;AAA/E,uGAAA,sBAAsB,OAAkB;AACjD,+BAA0C;AAAjC,yGAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Context, ModuleJoinerConfig } from "@aiminaabeejs/framework/types";
|
|
2
|
+
import { EntitySchema } from "@mikro-orm/core";
|
|
3
|
+
export declare function getLinkRepository(model: EntitySchema): {
|
|
4
|
+
new ({ joinerConfig }: {
|
|
5
|
+
joinerConfig: ModuleJoinerConfig;
|
|
6
|
+
}): {
|
|
7
|
+
readonly joinerConfig_: ModuleJoinerConfig;
|
|
8
|
+
delete(data: any, context?: Context): Promise<string[]>;
|
|
9
|
+
create(data: object[], context?: Context): Promise<object[]>;
|
|
10
|
+
entity: import("@mikro-orm/core").EntityClass<EntitySchema<any, never>>;
|
|
11
|
+
update(data: {
|
|
12
|
+
entity: any;
|
|
13
|
+
update: any;
|
|
14
|
+
}[], context?: Context): Promise<any[]>;
|
|
15
|
+
find(options?: import("@aiminaabeejs/framework/types").FindOptions<EntitySchema<any, never>> | undefined, context?: Context): Promise<any[]>;
|
|
16
|
+
findAndCount(options?: import("@aiminaabeejs/framework/types").FindOptions<EntitySchema<any, never>> | undefined, context?: Context): Promise<[any[], number]>;
|
|
17
|
+
upsert(data: unknown[], context?: Context): Promise<any[]>;
|
|
18
|
+
upsertWithReplace(data: unknown[], config?: import("@aiminaabeejs/framework/types").UpsertWithReplaceConfig<any> | undefined, context?: Context): Promise<{
|
|
19
|
+
entities: any[];
|
|
20
|
+
performedActions: import("@aiminaabeejs/framework/types").PerformedActions;
|
|
21
|
+
}>;
|
|
22
|
+
softDelete(filters: string | string[] | (import("@aiminaabeejs/types/dist/dal/utils").FilterQueryProperties<EntitySchema<any, never>, 3> & import("@aiminaabeejs/framework/types").BaseFilterable<import("@aiminaabeejs/types/dist/dal/utils").FilterQueryProperties<EntitySchema<any, never>, 3>>) | (import("@aiminaabeejs/types/dist/dal/utils").FilterQueryProperties<EntitySchema<any, never>, 3> & import("@aiminaabeejs/framework/types").BaseFilterable<import("@aiminaabeejs/types/dist/dal/utils").FilterQueryProperties<EntitySchema<any, never>, 3>>)[], sharedContext?: Context): Promise<[any[], Record<string, unknown[]>]>;
|
|
23
|
+
restore(idsOrFilter: string[] | import("@aiminaabeejs/framework/types").FilterQuery, sharedContext?: Context): Promise<[any[], Record<string, unknown[]>]>;
|
|
24
|
+
readonly manager_: any;
|
|
25
|
+
getFreshManager<TManager = unknown>(): TManager;
|
|
26
|
+
getActiveManager<TManager = unknown>({ transactionManager, manager, }?: Context): TManager;
|
|
27
|
+
transaction<TManager = unknown>(task: (transactionManager: TManager) => Promise<any>, options?: {
|
|
28
|
+
isolationLevel?: string;
|
|
29
|
+
enableNestedTransactions?: boolean;
|
|
30
|
+
transaction?: TManager;
|
|
31
|
+
}): Promise<any>;
|
|
32
|
+
serialize<TOutput extends object | object[]>(data: any, options?: any): Promise<TOutput>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/repositories/link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAQ9C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY;2BAInB;QAAE,YAAY,EAAE,kBAAkB,CAAA;KAAE;gCAF1C,kBAAkB;qBAQvB,GAAG,YAAW,OAAO,GAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;qBAW9C,MAAM,EAAE,YAAW,OAAO,GAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;;;;;;;;;;;;;;;;;;;0BAVpE,CAAL;oCACkB,CAAC;uBACF,CAAC;;;;EAyBlB"}
|