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