@etohq/link-modules-sdk 1.0.0

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.
Files changed (74) hide show
  1. package/dist/index.d.ts +6 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +22 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/initialize/index.d.ts +16 -0
  6. package/dist/initialize/index.d.ts.map +1 -0
  7. package/dist/initialize/index.js +127 -0
  8. package/dist/initialize/index.js.map +1 -0
  9. package/dist/initialize/module-definition.d.ts +3 -0
  10. package/dist/initialize/module-definition.d.ts.map +1 -0
  11. package/dist/initialize/module-definition.js +18 -0
  12. package/dist/initialize/module-definition.js.map +1 -0
  13. package/dist/loaders/connection.d.ts +4 -0
  14. package/dist/loaders/connection.d.ts.map +1 -0
  15. package/dist/loaders/connection.js +19 -0
  16. package/dist/loaders/connection.js.map +1 -0
  17. package/dist/loaders/container.d.ts +3 -0
  18. package/dist/loaders/container.d.ts.map +1 -0
  19. package/dist/loaders/container.js +32 -0
  20. package/dist/loaders/container.js.map +1 -0
  21. package/dist/loaders/index.d.ts +9 -0
  22. package/dist/loaders/index.d.ts.map +1 -0
  23. package/dist/loaders/index.js +16 -0
  24. package/dist/loaders/index.js.map +1 -0
  25. package/dist/migration/index.d.ts +103 -0
  26. package/dist/migration/index.d.ts.map +1 -0
  27. package/dist/migration/index.js +353 -0
  28. package/dist/migration/index.js.map +1 -0
  29. package/dist/repositories/index.d.ts +3 -0
  30. package/dist/repositories/index.d.ts.map +1 -0
  31. package/dist/repositories/index.js +8 -0
  32. package/dist/repositories/index.js.map +1 -0
  33. package/dist/repositories/link.d.ts +38 -0
  34. package/dist/repositories/link.d.ts.map +1 -0
  35. package/dist/repositories/link.js +34 -0
  36. package/dist/repositories/link.js.map +1 -0
  37. package/dist/services/dynamic-service-class.d.ts +8 -0
  38. package/dist/services/dynamic-service-class.d.ts.map +1 -0
  39. package/dist/services/dynamic-service-class.js +29 -0
  40. package/dist/services/dynamic-service-class.js.map +1 -0
  41. package/dist/services/index.d.ts +4 -0
  42. package/dist/services/index.d.ts.map +1 -0
  43. package/dist/services/index.js +26 -0
  44. package/dist/services/index.js.map +1 -0
  45. package/dist/services/link-module-service.d.ts +41 -0
  46. package/dist/services/link-module-service.d.ts.map +1 -0
  47. package/dist/services/link-module-service.js +271 -0
  48. package/dist/services/link-module-service.js.map +1 -0
  49. package/dist/services/link.d.ts +17 -0
  50. package/dist/services/link.d.ts.map +1 -0
  51. package/dist/services/link.js +139 -0
  52. package/dist/services/link.js.map +1 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -0
  54. package/dist/types/index.d.ts +5 -0
  55. package/dist/types/index.d.ts.map +1 -0
  56. package/dist/types/index.js +3 -0
  57. package/dist/types/index.js.map +1 -0
  58. package/dist/utils/compress-name.d.ts +2 -0
  59. package/dist/utils/compress-name.d.ts.map +1 -0
  60. package/dist/utils/compress-name.js +33 -0
  61. package/dist/utils/compress-name.js.map +1 -0
  62. package/dist/utils/generate-entity.d.ts +4 -0
  63. package/dist/utils/generate-entity.d.ts.map +1 -0
  64. package/dist/utils/generate-entity.js +93 -0
  65. package/dist/utils/generate-entity.js.map +1 -0
  66. package/dist/utils/generate-schema.d.ts +5 -0
  67. package/dist/utils/generate-schema.d.ts.map +1 -0
  68. package/dist/utils/generate-schema.js +156 -0
  69. package/dist/utils/generate-schema.js.map +1 -0
  70. package/dist/utils/index.d.ts +3 -0
  71. package/dist/utils/index.d.ts.map +1 -0
  72. package/dist/utils/index.js +19 -0
  73. package/dist/utils/index.js.map +1 -0
  74. package/package.json +57 -0
@@ -0,0 +1,353 @@
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("@etohq/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
+ // todo changee to MigrationsGeneratorFromPlannner https://chatgpt.com/c/67a77574-6290-8001-97b2-830becf2057f
25
+ class MigrationsExecutionPlanner {
26
+ constructor(joinerConfig, options) {
27
+ /**
28
+ * Database options for the module service
29
+ */
30
+ _MigrationsExecutionPlanner_dbConfig.set(this, void 0);
31
+ /**
32
+ * The set of commands that are unsafe to execute automatically when
33
+ * performing "alter table"
34
+ */
35
+ _MigrationsExecutionPlanner_unsafeSQLCommands.set(this, ["alter column", "drop column"]
36
+ /**
37
+ * On-the-fly computed set of entities for the user provided joinerConfig and the link it is coming from
38
+ */
39
+ );
40
+ /**
41
+ * On-the-fly computed set of entities for the user provided joinerConfig and the link it is coming from
42
+ */
43
+ _MigrationsExecutionPlanner_linksEntities.set(this, void 0);
44
+ /**
45
+ * The table that keeps a track of tables generated by the link
46
+ * module.
47
+ */
48
+ this.tableName = "link_module_migrations";
49
+ __classPrivateFieldSet(this, _MigrationsExecutionPlanner_dbConfig, utils_1.ModulesSdkUtils.loadDatabaseConfig("link_modules", options), "f");
50
+ __classPrivateFieldSet(this, _MigrationsExecutionPlanner_linksEntities, joinerConfig
51
+ .map((config) => {
52
+ if (config.isReadOnlyLink) {
53
+ return;
54
+ }
55
+ const [primary, foreign] = config.relationships ?? [];
56
+ const linkDescriptor = {
57
+ fromModule: primary.serviceName,
58
+ toModule: foreign.serviceName,
59
+ fromModel: primary.alias,
60
+ toModel: foreign.alias,
61
+ };
62
+ return {
63
+ entity: (0, utils_2.generateEntity)(config, primary, foreign),
64
+ linkDescriptor,
65
+ };
66
+ })
67
+ .filter((item) => !!item), "f");
68
+ }
69
+ /**
70
+ * Initializes the ORM using the normalized dbConfig and set
71
+ * of provided entities
72
+ */
73
+ async createORM(entities = []) {
74
+ return await utils_1.DALUtils.mikroOrmCreateConnection(__classPrivateFieldGet(this, _MigrationsExecutionPlanner_dbConfig, "f"), entities, "");
75
+ }
76
+ /**
77
+ * Ensure the table to track link modules migrations
78
+ * exists.
79
+ *
80
+ * @param orm MikroORM
81
+ */
82
+ async ensureMigrationsTable(orm) {
83
+ await orm.em.getDriver().getConnection().execute(`
84
+ CREATE TABLE IF NOT EXISTS "${this.tableName}" (
85
+ id SERIAL PRIMARY KEY,
86
+ table_name VARCHAR(255) NOT NULL UNIQUE,
87
+ link_descriptor JSONB NOT NULL DEFAULT '{}'::jsonb,
88
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
89
+ )
90
+ `);
91
+ }
92
+ /**
93
+ * Ensure the migrations table is in sync
94
+ *
95
+ * @param orm
96
+ * @protected
97
+ */
98
+ async ensureMigrationsTableUpToDate(orm) {
99
+ const existingTables = (await orm.em
100
+ .getDriver()
101
+ .getConnection()
102
+ .execute(`
103
+ SELECT table_name
104
+ FROM information_schema.tables;
105
+ `))
106
+ .map(({ table_name }) => table_name)
107
+ .filter((tableName) => __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f").some(({ entity }) => entity.meta.collection === tableName));
108
+ if (!existingTables.length) {
109
+ return;
110
+ }
111
+ const orderedDescriptors = existingTables.map((tableName) => {
112
+ return __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f").find(({ entity }) => entity.meta.collection === tableName).linkDescriptor;
113
+ });
114
+ const positionalArgs = new Array(existingTables.length)
115
+ .fill("(?, ?)")
116
+ .join(", ");
117
+ await orm.em
118
+ .getDriver()
119
+ .getConnection()
120
+ .execute(`
121
+ INSERT INTO ${this.tableName} (table_name, link_descriptor) VALUES ${positionalArgs} ON CONFLICT DO NOTHING;
122
+ `, existingTables.flatMap((tableName, index) => [
123
+ tableName,
124
+ JSON.stringify(orderedDescriptors[index]),
125
+ ]));
126
+ }
127
+ /**
128
+ * Insert tuple to the migrations table and create the link table
129
+ *
130
+ * @param orm
131
+ * @param action
132
+ * @protected
133
+ */
134
+ async createLinkTable(orm, action) {
135
+ const { tableName, linkDescriptor, sql } = action;
136
+ await orm.em
137
+ .getDriver()
138
+ .getConnection()
139
+ .execute(`
140
+ INSERT INTO "${this.tableName}" (table_name, link_descriptor) VALUES (?, ?);
141
+ ${sql}
142
+ `, [tableName, linkDescriptor]);
143
+ }
144
+ /**
145
+ * Drops the link table and untracks it from the "link_modules_migrations"
146
+ * table.
147
+ */
148
+ async dropLinkTable(orm, tableName) {
149
+ await orm.em.getDriver().getConnection().execute(`
150
+ DROP TABLE IF EXISTS "${tableName}";
151
+ DELETE FROM "${this.tableName}" WHERE table_name = '${tableName}';
152
+ `);
153
+ }
154
+ /**
155
+ * Returns an array of table names that have been tracked during
156
+ * the last run. In short, these tables were created by the
157
+ * link modules migrations runner.
158
+ *
159
+ * @param orm MikroORM
160
+ */
161
+ async getTrackedLinksTables(orm) {
162
+ const results = await orm.em.getDriver().getConnection().execute(`
163
+ SELECT table_name, link_descriptor from "${this.tableName}"
164
+ `);
165
+ return results.map((tuple) => ({
166
+ table_name: tuple.table_name,
167
+ link_descriptor: tuple.link_descriptor,
168
+ }));
169
+ }
170
+ /**
171
+ * Returns the migration plan for a specific link entity.
172
+ */
173
+ async getEntityMigrationPlan(linkDescriptor, entity, trackedLinksTables) {
174
+ const tableName = entity.meta.collection;
175
+ const orm = await this.createORM([entity]);
176
+ try {
177
+ const generator = orm.getSchemaGenerator();
178
+ const platform = orm.em.getPlatform();
179
+ const connection = orm.em.getConnection();
180
+ const schemaName = __classPrivateFieldGet(this, _MigrationsExecutionPlanner_dbConfig, "f").schema || "public";
181
+ /**
182
+ * If the table name for the entity has not been
183
+ * managed by us earlier, then we should create
184
+ * it.
185
+ */
186
+ if (!trackedLinksTables.includes(tableName)) {
187
+ return {
188
+ action: "create",
189
+ linkDescriptor,
190
+ tableName,
191
+ sql: (0, utils_1.normalizeMigrationSQL)(await generator.getCreateSchemaSQL()),
192
+ };
193
+ }
194
+ /**
195
+ * Pre-fetching information schema from the database and using that
196
+ * as the way to compute the update diff.
197
+ *
198
+ * @note
199
+ * The "loadInformationSchema" mutates the "dbSchema" argument provided
200
+ * to it as the first argument.
201
+ */
202
+ const dbSchema = new postgresql_1.DatabaseSchema(platform, schemaName);
203
+ await platform
204
+ .getSchemaHelper?.()
205
+ ?.loadInformationSchema(dbSchema, connection, [
206
+ {
207
+ table_name: tableName,
208
+ schema_name: schemaName,
209
+ },
210
+ ]);
211
+ const updateSQL = (0, utils_1.normalizeMigrationSQL)(await generator.getUpdateSchemaSQL({
212
+ fromSchema: dbSchema,
213
+ }));
214
+ /**
215
+ * Entity is upto-date and hence we do not have to perform
216
+ * any updates on it.
217
+ */
218
+ if (!updateSQL.length) {
219
+ return {
220
+ action: "noop",
221
+ linkDescriptor,
222
+ tableName,
223
+ };
224
+ }
225
+ const usesUnsafeCommands = __classPrivateFieldGet(this, _MigrationsExecutionPlanner_unsafeSQLCommands, "f").some((fragment) => {
226
+ return updateSQL.match(new RegExp(`${fragment}`, "ig"));
227
+ });
228
+ return {
229
+ action: usesUnsafeCommands ? "notify" : "update",
230
+ linkDescriptor,
231
+ tableName,
232
+ sql: updateSQL,
233
+ };
234
+ }
235
+ finally {
236
+ await orm.close(true);
237
+ }
238
+ }
239
+ /**
240
+ * This method loops over the tables we have fetched from the
241
+ * "link_module_migrations" tables and checks if their new
242
+ * name is different from the tracked name and in that
243
+ * case it will rename the actual table and also the
244
+ * tracked entry.
245
+ */
246
+ async migrateOldTables(orm, trackedTables) {
247
+ const migratedTables = [];
248
+ for (let trackedTable of trackedTables) {
249
+ const linkEntity = __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f").find((entity) => {
250
+ return (entity.linkDescriptor.fromModel ===
251
+ trackedTable.link_descriptor.fromModel &&
252
+ entity.linkDescriptor.toModel ===
253
+ trackedTable.link_descriptor.toModel &&
254
+ entity.linkDescriptor.fromModule.toLowerCase() ===
255
+ trackedTable.link_descriptor.fromModule.toLowerCase() &&
256
+ entity.linkDescriptor.toModule.toLowerCase() ===
257
+ trackedTable.link_descriptor.toModule.toLowerCase());
258
+ });
259
+ const newTableName = linkEntity?.entity.meta.collection;
260
+ /**
261
+ * Perform rename
262
+ */
263
+ if (newTableName && trackedTable.table_name !== newTableName) {
264
+ await this.renameOldTable(orm, trackedTable.table_name, newTableName, linkEntity.linkDescriptor);
265
+ migratedTables.push({
266
+ ...trackedTable,
267
+ table_name: newTableName,
268
+ });
269
+ }
270
+ else {
271
+ migratedTables.push({
272
+ ...trackedTable,
273
+ });
274
+ }
275
+ }
276
+ return migratedTables;
277
+ }
278
+ /**
279
+ * Renames existing table and also its tracked entry
280
+ */
281
+ async renameOldTable(orm, oldName, newName, descriptor) {
282
+ await orm.em.getDriver().getConnection().execute(`
283
+ ALTER TABLE "${oldName}" RENAME TO "${newName}";
284
+ UPDATE "${this.tableName}" SET table_name = '${newName}', link_descriptor = '${JSON.stringify(descriptor)}' WHERE table_name = '${oldName}';
285
+ `);
286
+ }
287
+ /**
288
+ * Creates a plan to executed in order to keep the database state in
289
+ * sync with the user-defined links.
290
+ *
291
+ * This method only creates a plan and does not change the database
292
+ * state. You must call the "executePlan" method for that.
293
+ */
294
+ async createPlan() {
295
+ const orm = await this.createORM();
296
+ try {
297
+ await this.ensureMigrationsTable(orm);
298
+ const executionActions = [];
299
+ await this.ensureMigrationsTableUpToDate(orm);
300
+ const trackedTables = await this.migrateOldTables(orm, await this.getTrackedLinksTables(orm));
301
+ const trackedTablesNames = trackedTables.map(({ table_name }) => table_name);
302
+ /**
303
+ * Looping through the new set of entities and generating
304
+ * execution plan for them
305
+ */
306
+ for (let { entity, linkDescriptor } of __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f")) {
307
+ executionActions.push(await this.getEntityMigrationPlan(linkDescriptor, entity, trackedTablesNames));
308
+ }
309
+ const linksTableNames = __classPrivateFieldGet(this, _MigrationsExecutionPlanner_linksEntities, "f").map(({ entity }) => entity.meta.collection);
310
+ /**
311
+ * Finding the tables to be removed
312
+ */
313
+ const tablesToRemove = (0, utils_1.arrayDifference)(trackedTablesNames, linksTableNames);
314
+ tablesToRemove.forEach((tableToRemove) => {
315
+ executionActions.push({
316
+ action: "delete",
317
+ tableName: tableToRemove,
318
+ linkDescriptor: trackedTables.find(({ table_name }) => tableToRemove === table_name).link_descriptor,
319
+ });
320
+ });
321
+ return executionActions;
322
+ }
323
+ finally {
324
+ await orm.close(true);
325
+ }
326
+ }
327
+ /**
328
+ * Executes the actionsPlan actions where the action is one of 'create' | 'update' | 'delete'.
329
+ * 'noop' and 'notify' actions are implicitly ignored. If a notify action needs to be
330
+ * executed, you can mutate its action to 'update', in that scenario it means that an unsafe
331
+ * update sql (from our point of view) will be executed and some data could be lost.
332
+ *
333
+ * @param actionPlan
334
+ */
335
+ async executePlan(actionPlan) {
336
+ const orm = await this.createORM();
337
+ await (0, utils_1.promiseAll)(actionPlan.map(async (action) => {
338
+ switch (action.action) {
339
+ case "delete":
340
+ return await this.dropLinkTable(orm, action.tableName);
341
+ case "create":
342
+ return await this.createLinkTable(orm, action);
343
+ case "update":
344
+ return await orm.em.getDriver().getConnection().execute(action.sql);
345
+ default:
346
+ return;
347
+ }
348
+ })).finally(() => orm.close(true));
349
+ }
350
+ }
351
+ exports.MigrationsExecutionPlanner = MigrationsExecutionPlanner;
352
+ _MigrationsExecutionPlanner_dbConfig = new WeakMap(), _MigrationsExecutionPlanner_unsafeSQLCommands = new WeakMap(), _MigrationsExecutionPlanner_linksEntities = new WeakMap();
353
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/migration/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAQA,wCAMqB;AAErB,sDAAwE;AACxE,oCAAyC;AAEzC;;;;GAIG;AAEH,6GAA6G;AAC7G,MAAa,0BAA0B;IA0BrC,YACE,YAAkC,EAClC,OAAwC;QA3B1C;;WAEG;QACH,uDAAgE;QAEhE;;;WAGG;QACH,wDAAqB,CAAC,cAAc,EAAE,aAAa,CAAC;QAEpD;;WAEG;UAJiD;QAEpD;;WAEG;QACH,4DAGG;QAEH;;;WAGG;QACO,cAAS,GAAG,wBAAwB,CAAA;QAM5C,uBAAA,IAAI,wCAAa,uBAAe,CAAC,kBAAkB,CAAC,cAAc,EAAE,OAAO,CAAC,MAAA,CAAA;QAC5E,uBAAA,IAAI,6CAAkB,YAAY;aAC/B,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACd,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;gBAC1B,OAAM;YACR,CAAC;YAED,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,aAAa,IAAI,EAAE,CAAA;YACrD,MAAM,cAAc,GAAgC;gBAClD,UAAU,EAAE,OAAO,CAAC,WAAW;gBAC/B,QAAQ,EAAE,OAAO,CAAC,WAAW;gBAC7B,SAAS,EAAE,OAAO,CAAC,KAAK;gBACxB,OAAO,EAAE,OAAO,CAAC,KAAK;aACvB,CAAA;YAED,OAAO;gBACL,MAAM,EAAE,IA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;;;;;OAOG;IACH,KAAK,CAAC,WAAW,CAAC,UAAyC;QACzD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAA;QAElC,MAAM,IAAA,kBAAU,EACd,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAC9B,QAAQ,MAAM,CAAC,MAAM,EAAE,CAAC;gBACtB,KAAK,QAAQ;oBACX,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,SAAS,CAAC,CAAA;gBACxD,KAAK,QAAQ;oBACX,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;gBAChD,KAAK,QAAQ;oBACX,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;gBACrE;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;AA9cD,gEA8cC"}
@@ -0,0 +1,3 @@
1
+ export { MikroOrmBaseRepository as BaseRepository } from "@etohq/utils";
2
+ export { getLinkRepository } from "./link";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,cAAc,CAAA;AACvE,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("@etohq/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,sCAAuE;AAA9D,uGAAA,sBAAsB,OAAkB;AACjD,+BAA0C;AAAjC,yGAAA,iBAAiB,OAAA"}
@@ -0,0 +1,38 @@
1
+ import { Context, ModuleJoinerConfig } from "@etohq/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<void>;
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("@etohq/framework/types").FindOptions<EntitySchema<any, never>> | undefined, context?: Context): Promise<any[]>;
16
+ findAndCount(options?: import("@etohq/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("@etohq/framework/types").UpsertWithReplaceConfig<any> | undefined, context?: Context): Promise<{
19
+ entities: any[];
20
+ performedActions: import("@etohq/framework/types").PerformedActions;
21
+ }>;
22
+ softDelete(filters: string | string[] | (import("@etohq/types/dist/dal/utils").FilterQueryProperties<EntitySchema<any, never>, 3> & import("@etohq/framework/types").BaseFilterable<import("@etohq/types/dist/dal/utils").FilterQueryProperties<EntitySchema<any, never>, 3>>) | (import("@etohq/types/dist/dal/utils").FilterQueryProperties<EntitySchema<any, never>, 3> & import("@etohq/framework/types").BaseFilterable<import("@etohq/types/dist/dal/utils").FilterQueryProperties<EntitySchema<any, never>, 3>>)[], sharedContext?: Context): Promise<[any[], Record<string, unknown[]>]>;
23
+ restore(idsOrFilter: string[] | import("@etohq/framework/types").FilterQuery, sharedContext?: Context): Promise<[any[], Record<string, unknown[]>]>;
24
+ applyFreeTextSearchFilters<T>(findOptions: import("@etohq/framework/types").FindOptions<T & {
25
+ q?: string;
26
+ }>, retrieveConstraintsToApply: (q: string) => any[]): void;
27
+ readonly manager_: any;
28
+ getFreshManager<TManager = unknown>(): TManager;
29
+ getActiveManager<TManager = unknown>({ transactionManager, manager, }?: Context): TManager;
30
+ transaction<TManager = unknown>(task: (transactionManager: TManager) => Promise<any>, options?: {
31
+ isolationLevel?: string;
32
+ enableNestedTransactions?: boolean;
33
+ transaction?: TManager;
34
+ }): Promise<any>;
35
+ serialize<TOutput extends object | object[]>(data: any, options?: any): Promise<TOutput>;
36
+ };
37
+ };
38
+ //# 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,wBAAwB,CAAA;AACpE,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,IAAI,CAAC;qBAY1C,MAAM,EAAE,YAAW,OAAO,GAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;;;;;;;;;;;;;;;;aAkB46D,CAAC;;;;;;0BA7Bl+D,CAAC;oCAEd,CAAC;uBACM,CAAC;;;;EAyBf"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLinkRepository = getLinkRepository;
4
+ const utils_1 = require("@etohq/utils");
5
+ function getLinkRepository(model) {
6
+ return class LinkRepository extends (0, utils_1.mikroOrmBaseRepositoryFactory)(model) {
7
+ constructor({ joinerConfig }) {
8
+ // @ts-ignore
9
+ super(...arguments);
10
+ this.joinerConfig_ = joinerConfig;
11
+ }
12
+ async delete(data, context = {}) {
13
+ const filter = {};
14
+ for (const key in data) {
15
+ filter[key] = {
16
+ $in: Array.isArray(data[key]) ? data[key] : [data[key]],
17
+ };
18
+ }
19
+ const manager = this.getActiveManager(context);
20
+ await manager.nativeDelete(model, data, {});
21
+ }
22
+ async create(data, context = {}) {
23
+ const manager = this.getActiveManager(context);
24
+ const links = data.map((link) => {
25
+ link.id = (0, utils_1.generateEntityId)(link.id, this.joinerConfig_.databaseConfig?.idPrefix ?? "link");
26
+ link.deleted_at = null;
27
+ return manager.create(model, link);
28
+ });
29
+ await manager.upsertMany(model, links);
30
+ return links;
31
+ }
32
+ };
33
+ }
34
+ //# sourceMappingURL=link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/repositories/link.ts"],"names":[],"mappings":";;AASA,8CAuCC;AA7CD,wCAGqB;AAGrB,SAAgB,iBAAiB,CAAC,KAAmB;IACnD,OAAO,MAAM,cAAe,SAAQ,IAAA,qCAA6B,EAAC,KAAK,CAAC;QAGtE,YAAY,EAAE,YAAY,EAAwC;YAChE,aAAa;YACb,KAAK,CAAC,GAAG,SAAS,CAAC,CAAA;YACnB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAA;QACnC,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,IAAS,EAAE,UAAmB,EAAE;YAC3C,MAAM,MAAM,GAAG,EAAE,CAAA;YACjB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,MAAM,CAAC,GAAG,CAAC,GAAG;oBACZ,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;iBACxD,CAAA;YACH,CAAC;YAED,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAmB,OAAO,CAAC,CAAA;YAChE,MAAM,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;QAC7C,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,IAAc,EAAE,UAAmB,EAAE;YAChD,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAmB,OAAO,CAAC,CAAA;YAEhE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE;gBACnC,IAAI,CAAC,EAAE,GAAG,IAAA,wBAAgB,EACxB,IAAI,CAAC,EAAE,EACP,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,QAAQ,IAAI,MAAM,CACtD,CAAA;gBACD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;gBACtB,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACpC,CAAC,CAAC,CAAA;YAEF,MAAM,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;YAEtC,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Constructor, ILinkModule, ModuleJoinerConfig } from "@etohq/framework/types";
2
+ export declare function getModuleService(joinerConfig: ModuleJoinerConfig): Constructor<ILinkModule>;
3
+ export declare function getReadOnlyModuleService(joinerConfig: ModuleJoinerConfig): {
4
+ new (): {
5
+ __joinerConfig(): ModuleJoinerConfig;
6
+ };
7
+ };
8
+ //# sourceMappingURL=dynamic-service-class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-service-class.d.ts","sourceRoot":"","sources":["../../src/services/dynamic-service-class.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,WAAW,EACX,kBAAkB,EACnB,MAAM,wBAAwB,CAAA;AAI/B,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,kBAAkB,GAC/B,WAAW,CAAC,WAAW,CAAC,CAmB1B;AAED,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,kBAAkB;;0BAEnD,kBAAkB;;EAIvC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModuleService = getModuleService;
4
+ exports.getReadOnlyModuleService = getReadOnlyModuleService;
5
+ const utils_1 = require("@etohq/utils");
6
+ const _1 = require(".");
7
+ function getModuleService(joinerConfig) {
8
+ const joinerConfig_ = JSON.parse(JSON.stringify(joinerConfig));
9
+ const databaseConfig = joinerConfig_.databaseConfig;
10
+ delete joinerConfig_.databaseConfig;
11
+ // If extraDataFields is not defined, pick the fields to populate and validate from the
12
+ // database config if any fields are provided.
13
+ if (!(0, utils_1.isDefined)(joinerConfig_.extraDataFields)) {
14
+ joinerConfig_.extraDataFields = Object.keys(databaseConfig?.extraFields || {});
15
+ }
16
+ return class LinkService extends _1.LinkModuleService {
17
+ __joinerConfig() {
18
+ return joinerConfig_;
19
+ }
20
+ };
21
+ }
22
+ function getReadOnlyModuleService(joinerConfig) {
23
+ return class ReadOnlyLinkService {
24
+ __joinerConfig() {
25
+ return joinerConfig;
26
+ }
27
+ };
28
+ }
29
+ //# sourceMappingURL=dynamic-service-class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-service-class.js","sourceRoot":"","sources":["../../src/services/dynamic-service-class.ts"],"names":[],"mappings":";;AAQA,4CAqBC;AAED,4DAMC;AAhCD,wCAAwC;AACxC,wBAAqC;AAErC,SAAgB,gBAAgB,CAC9B,YAAgC;IAEhC,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAA;IAC9D,MAAM,cAAc,GAAG,aAAa,CAAC,cAAc,CAAA;IAEnD,OAAO,aAAa,CAAC,cAAc,CAAA;IAEnC,uFAAuF;IACvF,8CAA8C;IAC9C,IAAI,CAAC,IAAA,iBAAS,EAAC,aAAa,CAAC,eAAe,CAAC,EAAE,CAAC;QAC9C,aAAa,CAAC,eAAe,GAAG,MAAM,CAAC,IAAI,CACzC,cAAc,EAAE,WAAW,IAAI,EAAE,CAClC,CAAA;IACH,CAAC;IAED,OAAO,MAAM,WAAY,SAAQ,oBAAiB;QACvC,cAAc;YACrB,OAAO,aAAmC,CAAA;QAC5C,CAAC;KACF,CAAA;AACH,CAAC;AAED,SAAgB,wBAAwB,CAAC,YAAgC;IACvE,OAAO,MAAM,mBAAmB;QAC9B,cAAc;YACZ,OAAO,YAAkC,CAAA;QAC3C,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./dynamic-service-class";
2
+ export { default as LinkService } from "./link";
3
+ export { default as LinkModuleService } from "./link-module-service";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAA"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.LinkModuleService = exports.LinkService = void 0;
21
+ __exportStar(require("./dynamic-service-class"), exports);
22
+ var link_1 = require("./link");
23
+ Object.defineProperty(exports, "LinkService", { enumerable: true, get: function () { return __importDefault(link_1).default; } });
24
+ var link_module_service_1 = require("./link-module-service");
25
+ Object.defineProperty(exports, "LinkModuleService", { enumerable: true, get: function () { return __importDefault(link_module_service_1).default; } });
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0DAAuC;AACvC,+BAA+C;AAAtC,oHAAA,OAAO,OAAe;AAC/B,6DAAoE;AAA3D,yIAAA,OAAO,OAAqB"}
@@ -0,0 +1,41 @@
1
+ import { Context, DAL, FindConfig, IEventBusModuleService, ILinkModule, InternalModuleDeclaration, ModuleJoinerConfig, RestoreReturn, SoftDeleteReturn } from "@etohq/types";
2
+ import { Modules } from "@etohq/utils";
3
+ import { LinkService } from ".";
4
+ type InjectedDependencies = {
5
+ baseRepository: DAL.RepositoryService;
6
+ linkService: LinkService<any>;
7
+ primaryKey: string | string[];
8
+ foreignKey: string;
9
+ extraFields: string[];
10
+ entityName: string;
11
+ serviceName: string;
12
+ [Modules.EVENT_BUS]?: IEventBusModuleService;
13
+ };
14
+ export default class LinkModuleService implements ILinkModule {
15
+ readonly moduleDeclaration: InternalModuleDeclaration;
16
+ protected baseRepository_: DAL.RepositoryService;
17
+ protected readonly linkService_: LinkService<any>;
18
+ protected readonly eventBusModuleService_?: IEventBusModuleService;
19
+ protected readonly entityName_: string;
20
+ protected readonly serviceName_: string;
21
+ protected primaryKey_: string[];
22
+ protected foreignKey_: string;
23
+ protected extraFields_: string[];
24
+ constructor({ baseRepository, linkService, primaryKey, foreignKey, extraFields, entityName, serviceName, [Modules.EVENT_BUS]: eventBusModuleService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
25
+ __joinerConfig(): ModuleJoinerConfig;
26
+ private buildData;
27
+ private isValidKeyName;
28
+ private validateFields;
29
+ retrieve(primaryKeyData: string | string[], foreignKeyData: string, sharedContext?: Context): Promise<unknown>;
30
+ list(filters?: Record<string, unknown>, config?: FindConfig<unknown>, sharedContext?: Context): Promise<unknown[]>;
31
+ listAndCount(filters?: Record<string, unknown>, config?: FindConfig<unknown>, sharedContext?: Context): Promise<[unknown[], number]>;
32
+ create(primaryKeyOrBulkData: string | string[] | [string | string[], string, Record<string, unknown>][], foreignKeyData?: string, extraFields?: Record<string, unknown>, sharedContext?: Context): Promise<any[]>;
33
+ dismiss(primaryKeyOrBulkData: string | string[] | [string | string[], string][], foreignKeyData?: string, sharedContext?: Context): Promise<any[]>;
34
+ delete(data: any, sharedContext?: Context): Promise<void>;
35
+ softDelete(data: any, { returnLinkableKeys }?: SoftDeleteReturn, sharedContext?: Context): Promise<Record<string, unknown[]> | void>;
36
+ protected softDelete_(data: any[], sharedContext?: Context): Promise<[object[], Record<string, string[]>]>;
37
+ restore(data: any, { returnLinkableKeys }?: RestoreReturn, sharedContext?: Context): Promise<Record<string, unknown[]> | void>;
38
+ restore_(data: any, sharedContext?: Context): Promise<[object[], Record<string, string[]>]>;
39
+ }
40
+ export {};
41
+ //# sourceMappingURL=link-module-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link-module-service.d.ts","sourceRoot":"","sources":["../../src/services/link-module-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,G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