lakutata 2.0.75 → 2.0.77

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 (69) hide show
  1. package/com/database.cjs +2 -0
  2. package/com/database.d.ts +1 -0
  3. package/com/database.mjs +2 -0
  4. package/helper.d.ts +1 -1
  5. package/lakutata.cjs +48 -24
  6. package/lakutata.mjs +24 -0
  7. package/orm.mjs +216 -216
  8. package/package.json +1 -1
  9. package/provider/database.cjs +2 -0
  10. package/provider/database.d.ts +1 -0
  11. package/provider/database.mjs +2 -0
  12. package/src/components/Database.cjs +11 -6
  13. package/src/components/Database.mjs +11 -6
  14. package/src/decorators/orm/AfterInsert.mjs +1 -1
  15. package/src/decorators/orm/AfterLoad.mjs +3 -3
  16. package/src/decorators/orm/AfterRecover.mjs +1 -1
  17. package/src/decorators/orm/AfterRemove.mjs +1 -1
  18. package/src/decorators/orm/AfterSoftRemove.mjs +1 -1
  19. package/src/decorators/orm/AfterUpdate.mjs +3 -3
  20. package/src/decorators/orm/BeforeInsert.mjs +1 -1
  21. package/src/decorators/orm/BeforeRecover.mjs +1 -1
  22. package/src/decorators/orm/BeforeRemove.mjs +1 -1
  23. package/src/decorators/orm/BeforeSoftRemove.mjs +1 -1
  24. package/src/decorators/orm/BeforeUpdate.mjs +3 -3
  25. package/src/decorators/orm/Check.mjs +1 -1
  26. package/src/decorators/orm/ChildEntity.mjs +1 -1
  27. package/src/decorators/orm/Column.mjs +1 -1
  28. package/src/decorators/orm/CreateDateColumn.mjs +1 -1
  29. package/src/decorators/orm/DeleteDateColumn.mjs +1 -1
  30. package/src/decorators/orm/Entity.mjs +1 -1
  31. package/src/decorators/orm/EventSubscriber.mjs +1 -1
  32. package/src/decorators/orm/Exclusion.mjs +1 -1
  33. package/src/decorators/orm/Generated.mjs +1 -1
  34. package/src/decorators/orm/Index.mjs +1 -1
  35. package/src/decorators/orm/JoinColumn.mjs +1 -1
  36. package/src/decorators/orm/JoinTable.mjs +1 -1
  37. package/src/decorators/orm/ManyToMany.mjs +1 -1
  38. package/src/decorators/orm/ManyToOne.mjs +1 -1
  39. package/src/decorators/orm/ObjectIdColumn.mjs +1 -1
  40. package/src/decorators/orm/OneToMany.mjs +1 -1
  41. package/src/decorators/orm/OneToOne.mjs +8 -8
  42. package/src/decorators/orm/PrimaryColumn.mjs +1 -1
  43. package/src/decorators/orm/PrimaryGeneratedColumn.mjs +1 -1
  44. package/src/decorators/orm/RelationId.mjs +1 -1
  45. package/src/decorators/orm/TableInheritance.mjs +1 -1
  46. package/src/decorators/orm/Tree.mjs +1 -1
  47. package/src/decorators/orm/TreeChildren.mjs +6 -6
  48. package/src/decorators/orm/TreeLevelColumn.mjs +1 -1
  49. package/src/decorators/orm/TreeParent.mjs +1 -1
  50. package/src/decorators/orm/Unique.mjs +1 -1
  51. package/src/decorators/orm/UpdateDateColumn.mjs +1 -1
  52. package/src/decorators/orm/VersionColumn.mjs +1 -1
  53. package/src/decorators/orm/ViewColumn.mjs +1 -1
  54. package/src/decorators/orm/ViewEntity.mjs +1 -1
  55. package/src/decorators/orm/VirtualColumn.mjs +1 -1
  56. package/src/lib/base/internal/DatabaseSymbol.cjs +9 -0
  57. package/src/lib/base/internal/DatabaseSymbol.mjs +3 -0
  58. package/src/lib/core/Application.cjs +87 -26
  59. package/src/lib/core/Application.mjs +83 -22
  60. package/src/lib/helpers/Paginator.cjs +1 -1
  61. package/src/lib/helpers/Paginator.mjs +1 -1
  62. package/src/providers/Database.cjs +7 -2
  63. package/src/providers/Database.mjs +12 -7
  64. package/src/providers/migration/GenerateMigration.cjs +426 -0
  65. package/src/providers/migration/GenerateMigration.mjs +414 -0
  66. package/vendor/Package.102.cjs +4689 -4747
  67. package/vendor/Package.102.mjs +4506 -4576
  68. package/vendor/Package.17.cjs +195 -184
  69. package/vendor/Package.17.mjs +1 -1
@@ -0,0 +1,426 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, {
4
+ value: "Module"
5
+ });
6
+
7
+ const e = require("../../../vendor/Package.1.cjs");
8
+
9
+ const r = require("../../lib/core/Provider.cjs");
10
+
11
+ const t = require("../../decorators/di/Configurable.cjs");
12
+
13
+ const i = require("../../../vendor/Package.2.cjs");
14
+
15
+ const a = require("path");
16
+
17
+ const n = require("../../../vendor/Package.10.cjs");
18
+
19
+ const o = require("../../../vendor/Package.102.cjs");
20
+
21
+ const s = require("../../../vendor/Package.5.cjs");
22
+
23
+ const c = require("../../../vendor/Package.12.cjs");
24
+
25
+ require("../../../vendor/Package.8.cjs");
26
+
27
+ const u = require("fs/promises");
28
+
29
+ const l = require("../../decorators/di/Lifetime.cjs");
30
+
31
+ require("../../../vendor/Package.3.cjs");
32
+
33
+ require("../../lib/base/async-constructor/AsyncConstructor.cjs");
34
+
35
+ require("../../lib/base/async-constructor/Append.cjs");
36
+
37
+ require("../../lib/helpers/IsPromiseLike.cjs");
38
+
39
+ require("../../lib/helpers/IsPromise.cjs");
40
+
41
+ require("util/types");
42
+
43
+ require("../../exceptions/MethodNotFoundException.cjs");
44
+
45
+ require("../../lib/base/abstracts/Exception.cjs");
46
+
47
+ require("../../lib/base/internal/BasicInfo.cjs");
48
+
49
+ require("../../lib/helpers/As.cjs");
50
+
51
+ require("../../../vendor/Package.6.cjs");
52
+
53
+ require("../../../vendor/Package.7.cjs");
54
+
55
+ require("../../lib/base/internal/ThrowWarning.cjs");
56
+
57
+ require("../../lib/helpers/Templating.cjs");
58
+
59
+ require("../../lib/base/internal/CamelCase.cjs");
60
+
61
+ require("../../lib/helpers/NoCase.cjs");
62
+
63
+ require("../../lib/ioc/DependencyInjectionContainer.cjs");
64
+
65
+ require("util");
66
+
67
+ require("../../lib/ioc/Errors.cjs");
68
+
69
+ require("../../exceptions/di/DependencyInjectionException.cjs");
70
+
71
+ require("../../lib/base/internal/ConstructorSymbol.cjs");
72
+
73
+ require("../../constants/DIMetadataKey.cjs");
74
+
75
+ require("../../../vendor/Package.4.cjs");
76
+
77
+ require("node:crypto");
78
+
79
+ require("../../lib/base/internal/DataValidator.cjs");
80
+
81
+ require("node:util/types");
82
+
83
+ require("../../lib/validation/VLD.cjs");
84
+
85
+ require("url");
86
+
87
+ require("../../exceptions/dto/InvalidValueException.cjs");
88
+
89
+ require("../../../vendor/Package.9.cjs");
90
+
91
+ require("../../lib/helpers/IsHtml.cjs");
92
+
93
+ require("../../lib/helpers/IsXML.cjs");
94
+
95
+ require("../../constants/DTOMetadataKey.cjs");
96
+
97
+ require("../../lib/helpers/ObjectConstructor.cjs");
98
+
99
+ require("../../lib/helpers/ObjectParentConstructors.cjs");
100
+
101
+ require("../../lib/helpers/ObjectParentConstructor.cjs");
102
+
103
+ require("../../lib/helpers/ObjectPrototype.cjs");
104
+
105
+ require("../../lib/ioc/InjectionMode.cjs");
106
+
107
+ require("../../lib/ioc/Lifetime.cjs");
108
+
109
+ require("../../lib/ioc/ListModules.cjs");
110
+
111
+ require("os");
112
+
113
+ require("stream");
114
+
115
+ require("fs");
116
+
117
+ require("events");
118
+
119
+ require("../../lib/ioc/Utils.cjs");
120
+
121
+ require("../../lib/ioc/FunctionTokenizer.cjs");
122
+
123
+ require("../../lib/ioc/LoadModules.cjs");
124
+
125
+ require("../../lib/ioc/Resolvers.cjs");
126
+
127
+ require("../../lib/ioc/ParamParser.cjs");
128
+
129
+ require("../../lib/base/internal/ObjectLifetime.cjs");
130
+
131
+ require("../../exceptions/di/LifetimeLockedException.cjs");
132
+
133
+ require("../../lib/base/internal/ObjectWeakRefs.cjs");
134
+
135
+ require("../../lib/base/internal/ConfigurableRecordsInjection.cjs");
136
+
137
+ require("../../lib/base/internal/ObjectConfiguration.cjs");
138
+
139
+ require("../../lib/base/internal/ObjectInjection.cjs");
140
+
141
+ require("../../lib/base/internal/ObjectContainer.cjs");
142
+
143
+ require("../../lib/helpers/DevNull.cjs");
144
+
145
+ require("../../decorators/dto/Expect.cjs");
146
+
147
+ require("../../decorators/dto/IndexSignature.cjs");
148
+
149
+ require("../../decorators/dto/Accept.cjs");
150
+
151
+ require("../../lib/base/internal/MethodValidation.cjs");
152
+
153
+ require("../../exceptions/dto/InvalidMethodAcceptException.cjs");
154
+
155
+ require("../../exceptions/dto/InvalidMethodReturnException.cjs");
156
+
157
+ require("../../lib/helpers/IsEmptyObject.cjs");
158
+
159
+ require("../../../vendor/Package.62.cjs");
160
+
161
+ require("../../../vendor/Package.11.cjs");
162
+
163
+ require("../../../vendor/Package.122.cjs");
164
+
165
+ require("buffer");
166
+
167
+ require("module");
168
+
169
+ require("tty");
170
+
171
+ require("../../../vendor/Package.13.cjs");
172
+
173
+ require("crypto");
174
+
175
+ require("../../../vendor/Package.63.cjs");
176
+
177
+ require("node:url");
178
+
179
+ require("node:path");
180
+
181
+ require("node:fs");
182
+
183
+ require("node:fs/promises");
184
+
185
+ require("node:events");
186
+
187
+ require("node:stream");
188
+
189
+ require("node:string_decoder");
190
+
191
+ const d = e => e && e.__esModule ? e : {
192
+ default: e
193
+ };
194
+
195
+ const p = d(a);
196
+
197
+ const g = d(u);
198
+
199
+ var b = {};
200
+
201
+ "use strict";
202
+
203
+ Object.defineProperty(b, "__esModule", {
204
+ value: true
205
+ });
206
+
207
+ var h = b.CommandUtils = void 0;
208
+
209
+ const m = c.require$$0;
210
+
211
+ const f = m.__importDefault(g.default);
212
+
213
+ const q = m.__importDefault(p.default);
214
+
215
+ const y = o.error;
216
+
217
+ const j = o.InstanceChecker;
218
+
219
+ const v = o.requireImportUtils();
220
+
221
+ class CommandUtils {
222
+ static async loadDataSource(e) {
223
+ let r;
224
+ try {
225
+ [r] = await (0, v.importOrRequireFile)(e);
226
+ } catch (r) {
227
+ throw new Error(`Unable to open file: "${e}". ${r.message}`);
228
+ }
229
+ if (!r || typeof r !== "object") {
230
+ throw new Error(`Given data source file must contain export of a DataSource instance`);
231
+ }
232
+ if (j.InstanceChecker.isDataSource(r)) {
233
+ return r;
234
+ }
235
+ const t = [];
236
+ for (const e in r) {
237
+ const i = r[e];
238
+ const a = await i;
239
+ if (j.InstanceChecker.isDataSource(a)) {
240
+ t.push(a);
241
+ }
242
+ }
243
+ if (t.length === 0) {
244
+ throw new Error(`Given data source file must contain export of a DataSource instance`);
245
+ }
246
+ if (t.length > 1) {
247
+ throw new Error(`Given data source file must contain only one export of DataSource instance`);
248
+ }
249
+ return t[0];
250
+ }
251
+ static async createDirectories(e) {
252
+ await f.default.mkdir(e, {
253
+ recursive: true
254
+ });
255
+ }
256
+ static async createFile(e, r, t = true) {
257
+ await CommandUtils.createDirectories(q.default.dirname(e));
258
+ if (t === false && await CommandUtils.fileExists(e)) {
259
+ return;
260
+ }
261
+ await f.default.writeFile(e, r);
262
+ }
263
+ static async readFile(e) {
264
+ const r = await f.default.readFile(e);
265
+ return r.toString();
266
+ }
267
+ static async fileExists(e) {
268
+ try {
269
+ await f.default.access(e, f.default.constants.F_OK);
270
+ return true;
271
+ } catch {
272
+ return false;
273
+ }
274
+ }
275
+ static getTimestamp(e) {
276
+ if (e && (isNaN(e) || e < 0)) {
277
+ throw new y.TypeORMError(`timestamp option should be a non-negative number. received: ${e}`);
278
+ }
279
+ return e ? new Date(Number(e)).getTime() : Date.now();
280
+ }
281
+ }
282
+
283
+ h = b.CommandUtils = CommandUtils;
284
+
285
+ var x = o.requireAnsis();
286
+
287
+ const _ = s.getDefaultExportFromCjs(x);
288
+
289
+ const {Ansis: w, ansi256: P, fg: k, bgAnsi256: C, bg: M, rgb: B, bgRgb: S, hex: D, bgHex: O, reset: R, inverse: E, hidden: I, visible: T, bold: $, dim: G, italic: N, underline: Q, strikethrough: A, strike: F, black: L, red: U, green: J, yellow: V, blue: W, magenta: z, cyan: K, white: H, grey: Y, gray: X, blackBright: Z, redBright: ee, greenBright: re, yellowBright: te, blueBright: ie, magentaBright: ae, cyanBright: ne, whiteBright: oe, bgBlack: se, bgRed: ce, bgGreen: ue, bgYellow: le, bgBlue: de, bgMagenta: pe, bgCyan: ge, bgWhite: be, bgGrey: he, bgGray: me, bgBlackBright: fe, bgRedBright: qe, bgGreenBright: ye, bgYellowBright: je, bgBlueBright: ve, bgMagentaBright: xe, bgCyanBright: _e, bgWhiteBright: we} = _;
290
+
291
+ var Pe;
292
+
293
+ exports.GenerateMigration = Pe = class GenerateMigration extends r.Provider {
294
+ get extension() {
295
+ return this.outputJs ? ".js" : ".ts";
296
+ }
297
+ get filename() {
298
+ return this.timestamp + "-" + (this.dataSourceName ? this.dataSourceName : p.default.basename(this.path)) + this.extension;
299
+ }
300
+ #e;
301
+ async init() {
302
+ this.#e = new n.DataSourceExports.DataSource(this.dataSource);
303
+ this.#e.setOptions({
304
+ synchronize: false,
305
+ migrationsRun: false,
306
+ dropSchema: false,
307
+ logging: false
308
+ });
309
+ this.#e = await this.#e.initialize();
310
+ await this.handle();
311
+ }
312
+ async destroy() {
313
+ await (this.#e?.destroy());
314
+ }
315
+ async handle() {
316
+ try {
317
+ const e = [], r = [];
318
+ try {
319
+ const t = await this.#e.driver.createSchemaBuilder().log();
320
+ if (this.pretty) {
321
+ t.upQueries.forEach((e => {
322
+ e.query = Pe.prettifyQuery(e.query);
323
+ }));
324
+ t.downQueries.forEach((e => {
325
+ e.query = Pe.prettifyQuery(e.query);
326
+ }));
327
+ }
328
+ t.upQueries.forEach((r => {
329
+ e.push(" await queryRunner.query(`" + r.query.replaceAll("`", "\\`") + "`" + Pe.queryParams(r.parameters) + ");");
330
+ }));
331
+ t.downQueries.forEach((e => {
332
+ r.push(" await queryRunner.query(`" + e.query.replaceAll("`", "\\`") + "`" + Pe.queryParams(e.parameters) + ");");
333
+ }));
334
+ } finally {
335
+ await this.#e.destroy();
336
+ }
337
+ if (!e.length) {
338
+ if (this.check) {
339
+ console.log(_.green`No changes in database schema were found`);
340
+ if (this.exitProcess) {
341
+ process.exit(0);
342
+ } else {
343
+ return;
344
+ }
345
+ } else {
346
+ console.log(_.yellow`No changes in database schema were found`);
347
+ if (this.exitProcess) {
348
+ process.exit(1);
349
+ } else {
350
+ return;
351
+ }
352
+ }
353
+ } else if (!this.path) {
354
+ console.log(_.yellow`Please specify a migration path`);
355
+ process.exit(1);
356
+ }
357
+ const t = this.outputJs ? Pe.getJavascriptTemplate(p.default.basename(this.path), this.timestamp, e, r.reverse(), this.esm) : Pe.getTemplate(p.default.basename(this.path), this.timestamp, e, r.reverse());
358
+ if (this.check) {
359
+ console.log(_.yellow`Unexpected changes in database schema were found in check mode:\n\n${_.white(t)}`);
360
+ if (this.exitProcess) {
361
+ process.exit(0);
362
+ } else {
363
+ return;
364
+ }
365
+ }
366
+ if (this.dryRun) {
367
+ console.log(_.green(`Migration ${_.blue(this.path + this.extension)} has content:\n\n${_.white(t)}`));
368
+ } else {
369
+ const e = p.default.isAbsolute(this.path) ? p.default.join(this.path, this.filename) : p.default.join(process.cwd(), this.path, this.filename);
370
+ await h.createFile(e, t);
371
+ console.log(_.green`Migration ${_.blue(e)} has been generated successfully.`);
372
+ if (this.exitProcess) {
373
+ process.exit(0);
374
+ } else {
375
+ return;
376
+ }
377
+ }
378
+ } catch (e) {
379
+ o.PlatformTools.PlatformTools.logCmdErr("Error during migration generation:", e);
380
+ process.exit(1);
381
+ }
382
+ }
383
+ static queryParams(e) {
384
+ if (!e || !e.length) {
385
+ return "";
386
+ }
387
+ return `, ${JSON.stringify(e)}`;
388
+ }
389
+ static getTemplate(e, r, t, i) {
390
+ const a = `${o.camelCase_1(e, true)}${r}`;
391
+ return `import { MigrationInterface, QueryRunner } from "lakutata/orm";\n\nexport class ${a} implements MigrationInterface {\n name = '${a}'\n\n public async up(queryRunner: QueryRunner): Promise<void> {\n${t.join(`\n`)}\n }\n\n public async down(queryRunner: QueryRunner): Promise<void> {\n${i.join(`\n`)}\n }\n\n}\n`;
392
+ }
393
+ static getJavascriptTemplate(e, r, t, i, a) {
394
+ const n = `${o.camelCase_1(e, true)}${r}`;
395
+ const s = a ? "export" : "module.exports =";
396
+ return `/**\n * @typedef {import('lakutata/orm').MigrationInterface} MigrationInterface\n * @typedef {import('lakutata/orm').QueryRunner} QueryRunner\n */\n\n/**\n * @class\n * @implements {MigrationInterface}\n */\n${s} class ${n} {\n name = '${n}'\n\n /**\n * @param {QueryRunner} queryRunner\n */\n async up(queryRunner) {\n${t.join(`\n`)}\n }\n\n /**\n * @param {QueryRunner} queryRunner\n */\n async down(queryRunner) {\n${i.join(`\n`)}\n }\n}\n`;
397
+ }
398
+ static prettifyQuery(e) {
399
+ const r = o.sqlFormatter.format(e, {
400
+ indent: " "
401
+ });
402
+ return "\n" + r.replace(/^/gm, " ") + "\n ";
403
+ }
404
+ };
405
+
406
+ e.__decorate([ t.Configurable(i.DTO.String().required()), e.__metadata("design:type", String) ], exports.GenerateMigration.prototype, "path", void 0);
407
+
408
+ e.__decorate([ t.Configurable(i.DTO.String().allow("").optional().default("")), e.__metadata("design:type", String) ], exports.GenerateMigration.prototype, "dataSourceName", void 0);
409
+
410
+ e.__decorate([ t.Configurable(), e.__metadata("design:type", Object) ], exports.GenerateMigration.prototype, "dataSource", void 0);
411
+
412
+ e.__decorate([ t.Configurable(i.DTO.Boolean().optional().default(true)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "pretty", void 0);
413
+
414
+ e.__decorate([ t.Configurable(i.DTO.Boolean().optional().default(false)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "outputJs", void 0);
415
+
416
+ e.__decorate([ t.Configurable(i.DTO.Boolean().optional().default(false)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "esm", void 0);
417
+
418
+ e.__decorate([ t.Configurable(i.DTO.Boolean().optional().default(false)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "dryRun", void 0);
419
+
420
+ e.__decorate([ t.Configurable(i.DTO.Boolean().optional().default(false)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "check", void 0);
421
+
422
+ e.__decorate([ t.Configurable(i.DTO.Number().optional().default((() => Date.now()))), e.__metadata("design:type", Number) ], exports.GenerateMigration.prototype, "timestamp", void 0);
423
+
424
+ e.__decorate([ t.Configurable(i.DTO.Boolean().optional().default(true)), e.__metadata("design:type", Boolean) ], exports.GenerateMigration.prototype, "exitProcess", void 0);
425
+
426
+ exports.GenerateMigration = Pe = e.__decorate([ l.Transient() ], exports.GenerateMigration);