@lakutata/orm 3.1.4 → 3.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/README.md +2 -1
  2. package/README.zh-CN.md +1 -1
  3. package/dist/cjs/lib/ConnectionOptions.d.ts +3 -1
  4. package/dist/cjs/lib/ConnectionOptions.js +44 -1
  5. package/dist/cjs/providers/migration/GenerateMigration.d.ts +1 -5
  6. package/dist/cjs/providers/migration/GenerateMigration.js +4 -10
  7. package/dist/esm/lib/ConnectionOptions.js +41 -1
  8. package/dist/esm/providers/migration/GenerateMigration.js +4 -10
  9. package/dist/types/lib/ConnectionOptions.d.ts +3 -1
  10. package/dist/types/providers/migration/GenerateMigration.d.ts +1 -5
  11. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedCollectionStore.js +4 -4
  12. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedCollectionStore.js.map +1 -1
  13. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedCrc32.d.ts +15 -0
  14. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedCrc32.js +44 -0
  15. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedCrc32.js.map +1 -0
  16. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedLog.js +2 -3
  17. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedLog.js.map +1 -1
  18. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedWorkerClient.js +4 -0
  19. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedWorkerClient.js.map +1 -1
  20. package/dist/vendor/typeorm/driver/mongo-embedded/EmbeddedWorkerCode.js +1 -1
  21. package/dist/vendor/typeorm/driver/mongodb/MongoDriver.js +4 -0
  22. package/dist/vendor/typeorm/driver/mongodb/MongoDriver.js.map +1 -1
  23. package/dist/vendor/typeorm/driver/mongodb/MongoWebCrypto.d.ts +6 -0
  24. package/dist/vendor/typeorm/driver/mongodb/MongoWebCrypto.js +19 -0
  25. package/dist/vendor/typeorm/driver/mongodb/MongoWebCrypto.js.map +1 -0
  26. package/package.json +5 -5
package/README.md CHANGED
@@ -500,7 +500,8 @@ The generated file follows TypeORM's style (double quotes, semicolons): format i
500
500
  linter. The process exits with code 0 once the command is done, and with code 1 when it fails: an invalid
501
501
  `MIGRATION_TRANSACTION`, an unknown `MIGRATION_DATABASE`, no database (except with `MIGRATION_GENERATE`, which then
502
502
  exits with 0), `MIGRATION_REVERT` with several databases and no `MIGRATION_DATABASE`, a database that does not connect,
503
- a migration that fails (the databases after it are skipped), or `MIGRATION_GENERATE` finding no change in any database.
503
+ or a migration that fails (the databases after it are skipped). When `MIGRATION_GENERATE` finds no change in any
504
+ database, the process exits with 0.
504
505
 
505
506
  The entities of a database are those of its connection options, plus, for a `Database` provider, those of its
506
507
  `entities` option.
package/README.zh-CN.md CHANGED
@@ -410,7 +410,7 @@ MIGRATION_RUN=1 node build/App.js
410
410
  MIGRATION_REVERT=1 MIGRATION_DATABASE=db node build/App.js
411
411
  ```
412
412
 
413
- 生成的文件遵循 TypeORM 的代码风格(双引号、分号):请格式化它,或者让 linter 跳过迁移文件。命令完成后,进程以退出码 0 退出;失败时以退出码 1 退出,失败的情况包括:无效的 `MIGRATION_TRANSACTION`、未知的 `MIGRATION_DATABASE`、没有数据库(`MIGRATION_GENERATE` 除外,这时以 0 退出)、有多个数据库时使用 `MIGRATION_REVERT` 却没有指定 `MIGRATION_DATABASE`、数据库连接不上、迁移失败(之后的数据库会被跳过),或者 `MIGRATION_GENERATE` 在所有数据库中都没有发现变化。
413
+ 生成的文件遵循 TypeORM 的代码风格(双引号、分号):请格式化它,或者让 linter 跳过迁移文件。命令完成后,进程以退出码 0 退出;失败时以退出码 1 退出,失败的情况包括:无效的 `MIGRATION_TRANSACTION`、未知的 `MIGRATION_DATABASE`、没有数据库(`MIGRATION_GENERATE` 除外,这时以 0 退出)、有多个数据库时使用 `MIGRATION_REVERT` 却没有指定 `MIGRATION_DATABASE`、数据库连接不上,或者迁移失败(之后的数据库会被跳过)。`MIGRATION_GENERATE` 在所有数据库中都没有发现变化时,以 0 退出。
414
414
 
415
415
  数据库的实体就是它连接选项中的实体;对于 `Database` 提供者,还要加上它 `entities` 选项中的实体。
416
416
 
@@ -3,7 +3,9 @@ import { type DataSourceOptions } from '../../vendor/typeorm/data-source/DataSou
3
3
  * The connection options with the defaults of the framework: the null and undefined values of the where conditions
4
4
  * ignored (the condition on the property left out), as TypeORM 0.3 did, where TypeORM 1 throws by default. Each key of
5
5
  * the `invalidWhereValuesBehavior` of the options replaces its default (`{undefined: 'throw'}` throws on the undefined
6
- * values and still ignores the null values).
6
+ * values and still ignores the null values). The paths given with an alias of the application (`@data/app.sqlite`) are
7
+ * resolved: the file of the database (`database`, `location` of sql.js) and the globs of the entities, the migrations
8
+ * and the subscribers.
7
9
  * @param options The connection options.
8
10
  * @returns The connection options with the defaults.
9
11
  */
@@ -1,17 +1,60 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.connectionOptionsOf = connectionOptionsOf;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ /**
9
+ * The option of the file (or the directory) of each driver keeping its database in the file system
10
+ */
11
+ const FILE_OPTIONS = {
12
+ 'better-sqlite3': 'database',
13
+ 'mongo-embedded': 'database',
14
+ 'sqljs': 'location'
15
+ };
16
+ /**
17
+ * A path given with an alias of the application (`@data/app.sqlite`) resolved as `path.resolve()` resolves it once the
18
+ * application declared its aliases; any other value as it is
19
+ * @param value
20
+ */
21
+ function resolveAlias(value) {
22
+ return (typeof value === 'string' && value.startsWith('@') ? node_path_1.default.resolve(value) : value);
23
+ }
24
+ /**
25
+ * The paths of a list of the options (the globs of the entities, the migrations, the subscribers) resolved
26
+ * @param list
27
+ */
28
+ function resolveAliases(list) {
29
+ if (Array.isArray(list))
30
+ return list.map(resolveAlias);
31
+ if (list && typeof list === 'object')
32
+ return Object.fromEntries(Object.entries(list).map(([name, value]) => [name, resolveAlias(value)]));
33
+ return list;
34
+ }
4
35
  /**
5
36
  * The connection options with the defaults of the framework: the null and undefined values of the where conditions
6
37
  * ignored (the condition on the property left out), as TypeORM 0.3 did, where TypeORM 1 throws by default. Each key of
7
38
  * the `invalidWhereValuesBehavior` of the options replaces its default (`{undefined: 'throw'}` throws on the undefined
8
- * values and still ignores the null values).
39
+ * values and still ignores the null values). The paths given with an alias of the application (`@data/app.sqlite`) are
40
+ * resolved: the file of the database (`database`, `location` of sql.js) and the globs of the entities, the migrations
41
+ * and the subscribers.
9
42
  * @param options The connection options.
10
43
  * @returns The connection options with the defaults.
11
44
  */
12
45
  function connectionOptionsOf(options) {
46
+ const given = options;
47
+ //The options given only: an option left out stays out
48
+ const paths = {};
49
+ const file = FILE_OPTIONS[options.type];
50
+ if (file && given[file] !== undefined)
51
+ paths[file] = resolveAlias(given[file]);
52
+ for (const list of ['entities', 'migrations', 'subscribers'])
53
+ if (given[list] !== undefined)
54
+ paths[list] = resolveAliases(given[list]);
13
55
  return {
14
56
  ...options,
57
+ ...paths,
15
58
  invalidWhereValuesBehavior: { null: 'ignore', undefined: 'ignore', ...options.invalidWhereValuesBehavior }
16
59
  };
17
60
  }
@@ -4,7 +4,7 @@ import { type DataSourceOptions } from '../../../vendor/typeorm/data-source/Data
4
4
  * Generate the migration of the changes of the schema of a database of the application (MIGRATION_GENERATE): its
5
5
  * entities compared with the schema of the database, the queries of the changes written to a migration file of the
6
6
  * directory path. Each database has its provider, in the order of the run; the last one exits the application (with
7
- * the code 1 when no database had a change, or on a failure)
7
+ * the code 0 when no database had a change, 1 on a failure)
8
8
  */
9
9
  export declare class GenerateMigration extends Provider {
10
10
  #private;
@@ -38,10 +38,6 @@ export declare class GenerateMigration extends Provider {
38
38
  * directory
39
39
  */
40
40
  protected get filename(): string;
41
- /**
42
- * The migrations generated by the run (its databases share the process)
43
- */
44
- protected static generated: number;
45
41
  /**
46
42
  * Initializer: the database connected without its synchronization nor its migrations, then the migration generated
47
43
  * @protected
@@ -33,10 +33,9 @@ const ConnectionOptions_js_1 = require("../../lib/ConnectionOptions.js");
33
33
  * Generate the migration of the changes of the schema of a database of the application (MIGRATION_GENERATE): its
34
34
  * entities compared with the schema of the database, the queries of the changes written to a migration file of the
35
35
  * directory path. Each database has its provider, in the order of the run; the last one exits the application (with
36
- * the code 1 when no database had a change, or on a failure)
36
+ * the code 0 when no database had a change, 1 on a failure)
37
37
  */
38
- let GenerateMigration = class GenerateMigration extends core_1.Provider {
39
- static { GenerateMigration_1 = this; }
38
+ let GenerateMigration = GenerateMigration_1 = class GenerateMigration extends core_1.Provider {
40
39
  /**
41
40
  * The extension of the migration file
42
41
  */
@@ -52,10 +51,6 @@ let GenerateMigration = class GenerateMigration extends core_1.Provider {
52
51
  }
53
52
  #app;
54
53
  #dataSource;
55
- /**
56
- * The migrations generated by the run (its databases share the process)
57
- */
58
- static { this.generated = 0; }
59
54
  /**
60
55
  * Initializer: the database connected without its synchronization nor its migrations, then the migration generated
61
56
  * @protected
@@ -133,8 +128,8 @@ let GenerateMigration = class GenerateMigration extends core_1.Provider {
133
128
  else {
134
129
  console.log(ansis_1.default.yellow `No changes in database schema were found`);
135
130
  if (this.exitProcess) {
136
- //The code 1 when no database of the run had a change
137
- return this.#app.exit(GenerateMigration_1.generated ? 0 : 1);
131
+ //Nothing to generate is not a failure: the tools running the command go on
132
+ return this.#app.exit(0);
138
133
  }
139
134
  else {
140
135
  return;
@@ -153,7 +148,6 @@ let GenerateMigration = class GenerateMigration extends core_1.Provider {
153
148
  //Changes found in check mode: the code 1, as the check of TypeORM
154
149
  return this.#app.exit(1);
155
150
  }
156
- GenerateMigration_1.generated++;
157
151
  if (this.dryRun) {
158
152
  console.log(ansis_1.default.green(`Migration ${ansis_1.default.blue(this.path + this.extension)} has content:\n\n${ansis_1.default.white(fileContent)}`));
159
153
  if (this.exitProcess)
@@ -1,14 +1,54 @@
1
+ import path from 'node:path';
2
+ /**
3
+ * The option of the file (or the directory) of each driver keeping its database in the file system
4
+ */
5
+ const FILE_OPTIONS = {
6
+ 'better-sqlite3': 'database',
7
+ 'mongo-embedded': 'database',
8
+ 'sqljs': 'location'
9
+ };
10
+ /**
11
+ * A path given with an alias of the application (`@data/app.sqlite`) resolved as `path.resolve()` resolves it once the
12
+ * application declared its aliases; any other value as it is
13
+ * @param value
14
+ */
15
+ function resolveAlias(value) {
16
+ return (typeof value === 'string' && value.startsWith('@') ? path.resolve(value) : value);
17
+ }
18
+ /**
19
+ * The paths of a list of the options (the globs of the entities, the migrations, the subscribers) resolved
20
+ * @param list
21
+ */
22
+ function resolveAliases(list) {
23
+ if (Array.isArray(list))
24
+ return list.map(resolveAlias);
25
+ if (list && typeof list === 'object')
26
+ return Object.fromEntries(Object.entries(list).map(([name, value]) => [name, resolveAlias(value)]));
27
+ return list;
28
+ }
1
29
  /**
2
30
  * The connection options with the defaults of the framework: the null and undefined values of the where conditions
3
31
  * ignored (the condition on the property left out), as TypeORM 0.3 did, where TypeORM 1 throws by default. Each key of
4
32
  * the `invalidWhereValuesBehavior` of the options replaces its default (`{undefined: 'throw'}` throws on the undefined
5
- * values and still ignores the null values).
33
+ * values and still ignores the null values). The paths given with an alias of the application (`@data/app.sqlite`) are
34
+ * resolved: the file of the database (`database`, `location` of sql.js) and the globs of the entities, the migrations
35
+ * and the subscribers.
6
36
  * @param options The connection options.
7
37
  * @returns The connection options with the defaults.
8
38
  */
9
39
  export function connectionOptionsOf(options) {
40
+ const given = options;
41
+ //The options given only: an option left out stays out
42
+ const paths = {};
43
+ const file = FILE_OPTIONS[options.type];
44
+ if (file && given[file] !== undefined)
45
+ paths[file] = resolveAlias(given[file]);
46
+ for (const list of ['entities', 'migrations', 'subscribers'])
47
+ if (given[list] !== undefined)
48
+ paths[list] = resolveAliases(given[list]);
10
49
  return {
11
50
  ...options,
51
+ ...paths,
12
52
  invalidWhereValuesBehavior: { null: 'ignore', undefined: 'ignore', ...options.invalidWhereValuesBehavior }
13
53
  };
14
54
  }
@@ -27,10 +27,9 @@ import { connectionOptionsOf } from '../../lib/ConnectionOptions.js';
27
27
  * Generate the migration of the changes of the schema of a database of the application (MIGRATION_GENERATE): its
28
28
  * entities compared with the schema of the database, the queries of the changes written to a migration file of the
29
29
  * directory path. Each database has its provider, in the order of the run; the last one exits the application (with
30
- * the code 1 when no database had a change, or on a failure)
30
+ * the code 0 when no database had a change, 1 on a failure)
31
31
  */
32
- let GenerateMigration = class GenerateMigration extends Provider {
33
- static { GenerateMigration_1 = this; }
32
+ let GenerateMigration = GenerateMigration_1 = class GenerateMigration extends Provider {
34
33
  /**
35
34
  * The extension of the migration file
36
35
  */
@@ -46,10 +45,6 @@ let GenerateMigration = class GenerateMigration extends Provider {
46
45
  }
47
46
  #app;
48
47
  #dataSource;
49
- /**
50
- * The migrations generated by the run (its databases share the process)
51
- */
52
- static { this.generated = 0; }
53
48
  /**
54
49
  * Initializer: the database connected without its synchronization nor its migrations, then the migration generated
55
50
  * @protected
@@ -127,8 +122,8 @@ let GenerateMigration = class GenerateMigration extends Provider {
127
122
  else {
128
123
  console.log(ansi.yellow `No changes in database schema were found`);
129
124
  if (this.exitProcess) {
130
- //The code 1 when no database of the run had a change
131
- return this.#app.exit(GenerateMigration_1.generated ? 0 : 1);
125
+ //Nothing to generate is not a failure: the tools running the command go on
126
+ return this.#app.exit(0);
132
127
  }
133
128
  else {
134
129
  return;
@@ -147,7 +142,6 @@ let GenerateMigration = class GenerateMigration extends Provider {
147
142
  //Changes found in check mode: the code 1, as the check of TypeORM
148
143
  return this.#app.exit(1);
149
144
  }
150
- GenerateMigration_1.generated++;
151
145
  if (this.dryRun) {
152
146
  console.log(ansi.green(`Migration ${ansi.blue(this.path + this.extension)} has content:\n\n${ansi.white(fileContent)}`));
153
147
  if (this.exitProcess)
@@ -3,7 +3,9 @@ import { type DataSourceOptions } from '#typeorm/data-source/DataSourceOptions.j
3
3
  * The connection options with the defaults of the framework: the null and undefined values of the where conditions
4
4
  * ignored (the condition on the property left out), as TypeORM 0.3 did, where TypeORM 1 throws by default. Each key of
5
5
  * the `invalidWhereValuesBehavior` of the options replaces its default (`{undefined: 'throw'}` throws on the undefined
6
- * values and still ignores the null values).
6
+ * values and still ignores the null values). The paths given with an alias of the application (`@data/app.sqlite`) are
7
+ * resolved: the file of the database (`database`, `location` of sql.js) and the globs of the entities, the migrations
8
+ * and the subscribers.
7
9
  * @param options The connection options.
8
10
  * @returns The connection options with the defaults.
9
11
  */
@@ -4,7 +4,7 @@ import { type DataSourceOptions } from '#typeorm/data-source/DataSourceOptions.j
4
4
  * Generate the migration of the changes of the schema of a database of the application (MIGRATION_GENERATE): its
5
5
  * entities compared with the schema of the database, the queries of the changes written to a migration file of the
6
6
  * directory path. Each database has its provider, in the order of the run; the last one exits the application (with
7
- * the code 1 when no database had a change, or on a failure)
7
+ * the code 0 when no database had a change, 1 on a failure)
8
8
  */
9
9
  export declare class GenerateMigration extends Provider {
10
10
  #private;
@@ -38,10 +38,6 @@ export declare class GenerateMigration extends Provider {
38
38
  * directory
39
39
  */
40
40
  protected get filename(): string;
41
- /**
42
- * The migrations generated by the run (its databases share the process)
43
- */
44
- protected static generated: number;
45
41
  /**
46
42
  * Initializer: the database connected without its synchronization nor its migrations, then the migration generated
47
43
  * @protected
@@ -4,10 +4,10 @@ exports.EmbeddedCollectionStore = exports.SCAN_TIMEOUT = exports.EmbeddedBulkWri
4
4
  const tslib_1 = require("tslib");
5
5
  const crypto_1 = require("crypto");
6
6
  const fs = tslib_1.__importStar(require("fs"));
7
- const zlib = tslib_1.__importStar(require("zlib"));
8
7
  const TypeORMError_1 = require("../../error/TypeORMError");
9
8
  const EmbeddedBTree_1 = require("./EmbeddedBTree");
10
9
  const EmbeddedCache_1 = require("./EmbeddedCache");
10
+ const EmbeddedCrc32_1 = require("./EmbeddedCrc32");
11
11
  const EmbeddedKeyEncoding_1 = require("./EmbeddedKeyEncoding");
12
12
  const EmbeddedKeydir_1 = require("./EmbeddedKeydir");
13
13
  const EmbeddedLog_1 = require("./EmbeddedLog");
@@ -298,7 +298,7 @@ class EmbeddedCollectionStore {
298
298
  }
299
299
  let checksum = 0;
300
300
  for (const part of parts)
301
- checksum = zlib.crc32(part, checksum);
301
+ checksum = (0, EmbeddedCrc32_1.crc32)(part, checksum);
302
302
  const crc = Buffer.allocUnsafe(4);
303
303
  crc.writeUInt32LE(checksum);
304
304
  const temporary = `${path}.tmp`;
@@ -346,7 +346,7 @@ class EmbeddedCollectionStore {
346
346
  }
347
347
  position += size;
348
348
  if (checked)
349
- checksum = zlib.crc32(bytes, checksum);
349
+ checksum = (0, EmbeddedCrc32_1.crc32)(bytes, checksum);
350
350
  return bytes;
351
351
  };
352
352
  const skipPadding = () => {
@@ -443,7 +443,7 @@ class EmbeddedCollectionStore {
443
443
  const record = Buffer.allocUnsafe(length);
444
444
  this.fileOf(this.keydir.fileAt(slot)).readInto(record, 0, length, offset);
445
445
  const payload = record.subarray(EmbeddedLog_1.RECORD_HEADER);
446
- if (zlib.crc32(payload, zlib.crc32(record.subarray(8, 9))) !==
446
+ if ((0, EmbeddedCrc32_1.crc32)(payload, (0, EmbeddedCrc32_1.crc32)(record.subarray(8, 9))) !==
447
447
  record.readUInt32LE(4))
448
448
  throw this.corrupted(offset);
449
449
  const document = this.values.deserialize(payload);