@lakutata/orm 3.1.5 → 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.
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
@@ -368,6 +368,10 @@ class EmbeddedWorkerClient {
368
368
  };
369
369
  const worker = new worker_threads_1.Worker(EmbeddedWorkerCode_1.embeddedWorkerCode, {
370
370
  eval: true,
371
+ // lakutata: none of the options of the command line of the process, which the worker would inherit: with
372
+ // --input-type=module, its code (CommonJS) would run as an ES module; a list of its own refuses the
373
+ // options of V8 (--max-old-space-size) that the process may have
374
+ execArgv: [],
371
375
  workerData: { [EmbeddedWorkerProtocol_1.WORKER_DATA_KEY]: data },
372
376
  ...(resourceLimits ? { resourceLimits: resourceLimits } : {}),
373
377
  });
@@ -1 +1 @@
1
- {"version":3,"file":"EmbeddedWorkerClient.js","sourceRoot":"","sources":["../../../../../vendor/typeorm/driver/mongo-embedded/EmbeddedWorkerClient.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC,mDAAuC;AACvC,2DAAuD;AACvD,qDAIyB;AAEzB,uEAAkE;AAElE,mDAAiD;AAEjD,6DAAyD;AAMzD,qEAMiC;AAEjC;;GAEG;AACH,SAAS,SAAS;IACd,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,MAAc;IAChC,OAAO,IAAI,2BAAY,CAAC,GAAG,MAAM,qCAAqC,CAAC,CAAA;AAC3E,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,KAAU;IAChC,IAAI,OAAO,KAAK,KAAK,UAAU;QAC3B,MAAM,IAAI,2BAAY,CAClB,mIAAmI,CACtI,CAAA;IACL,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAM;IACvD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,gBAAgB,CAAC,IAAI,CAAC,CAAA;QAChD,OAAM;IACV,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAC9C,IAAI,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI;QAAE,OAAM;IAChE,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,kBAAkB,GAAiC;IACrD,SAAS,EAAE,CAAC;IACZ,UAAU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C,KAAK,CAAC,EAAE,CAAC,CAAA;QACxC,IAAI,CAAC,OAAO;YAAE,OAAM;QACpB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC3B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI;YAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACzC,OAAO,CAAC,KAAK,CAAC,CAAA;IAClB,CAAC;IAED;;;;OAIG;IACO,IAAI,CAAC,OAAqB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACrC,OAAO,CAAC;gBACJ,EAAE,EAAE,CAAC;gBACL,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;aAC5D,CAAC,CAAA;QACN,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;IAED;;;;;OAKG;IACO,MAAM,CAAC,OAAqB;QAClC,IAAI,IAAI,CAAC,OAAO;YAAE,OAAM;QACxB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClB,IAAI,IAAI,CAAC,SAAS;YAAE,IAAA,+BAAe,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IACnE,CAAC;CACJ;AA9RD,oDA8RC","sourcesContent":["import { randomBytes } from \"crypto\"\nimport type { ResourceLimits } from \"worker_threads\"\nimport { Worker } from \"worker_threads\"\nimport { TypeORMError } from \"../../error/TypeORMError\"\nimport {\n EmbeddedArrayCursor,\n EmbeddedResults,\n isStreamed,\n} from \"./EmbeddedClient\"\nimport type { EmbeddedWriteError } from \"./EmbeddedCollectionStore\"\nimport { EmbeddedBulkWriteError } from \"./EmbeddedCollectionStore\"\nimport type { EmbeddedStoreOptions } from \"./EmbeddedStore\"\nimport { unlockDirectory } from \"./EmbeddedStore\"\nimport type { EmbeddedDocument } from \"./EmbeddedValues\"\nimport { embeddedWorkerCode } from \"./EmbeddedWorkerCode\"\nimport type {\n EmbeddedReply,\n EmbeddedRequest,\n EmbeddedWorkerData,\n} from \"./EmbeddedWorkerProtocol\"\nimport {\n decodeDocuments,\n encode,\n encodeDocuments,\n errorOf,\n WORKER_DATA_KEY,\n} from \"./EmbeddedWorkerProtocol\"\n\n/**\n * lakutata: yields the event loop.\n */\nfunction yieldLoop(): Promise<void> {\n return new Promise((resolve) => setImmediate(resolve))\n}\n\n/**\n * lakutata: the error of a method of the client of MongoDB that the embedded client does not have.\n *\n * @param method\n */\nfunction notSupported(method: string): TypeORMError {\n return new TypeORMError(`${method} is not supported by mongo-embedded`)\n}\n\n/**\n * lakutata: throws when a value of a query holds a function: BSON does not send it to the worker thread (the\n * functions of JavaScript of $where, $function and $accumulator run in the client of the option worker false).\n *\n * @param value\n */\nfunction assertNoFunction(value: any): void {\n if (typeof value === \"function\")\n throw new TypeORMError(\n \"The functions of JavaScript of a query are not sent to the worker thread of mongo-embedded: they run with its option worker false\",\n )\n if (value === null || typeof value !== \"object\") return\n if (Array.isArray(value)) {\n for (const item of value) assertNoFunction(item)\n return\n }\n const prototype = Object.getPrototypeOf(value)\n if (prototype !== Object.prototype && prototype !== null) return\n for (const key of Object.keys(value)) assertNoFunction(value[key])\n}\n\n/**\n * lakutata: the arguments of the methods of the collections that are documents, not queries: a function of a document\n * is not stored, in both clients.\n */\nconst DOCUMENT_ARGUMENTS: { [method: string]: number } = {\n insertOne: 0,\n insertMany: 0,\n replaceOne: 1,\n}\n\n/**\n * lakutata: the documents of an insertMany sent to the worker thread in a call (their encoding a stall of about 10 ms\n * of this thread, the event loop yielded between the calls).\n */\nconst SENT_DOCUMENTS = 10000\n\n/**\n * lakutata: the cursor of a find of a collection of the worker thread: its filter, projection, order, skip and limit\n * sent with the call reading it.\n */\nexport class EmbeddedWorkerFindCursor extends EmbeddedResults {\n protected projection?: EmbeddedDocument\n\n protected order?: EmbeddedDocument\n\n protected skipped?: number\n\n protected limited?: number\n\n constructor(\n protected readonly collection: EmbeddedWorkerCollection,\n protected query: EmbeddedDocument,\n ) {\n super()\n }\n\n filter(query: EmbeddedDocument): this {\n this.query = query\n return this\n }\n\n project(projection: EmbeddedDocument): this {\n this.projection = projection\n return this\n }\n\n sort(order: EmbeddedDocument): this {\n this.order = order\n return this\n }\n\n skip(count: number): this {\n this.skipped = count\n return this\n }\n\n limit(count: number): this {\n this.limited = count\n return this\n }\n\n protected documents(): Promise<EmbeddedDocument[]> {\n return this.collection.client.documents(\"find\", this.call())\n }\n\n protected batches(): AsyncIterator<EmbeddedDocument[]> | undefined {\n return isStreamed(this.order, this.skipped, this.limited)\n ? this.collection.client.streamed(this.call())\n : undefined\n }\n\n protected call(): EmbeddedDocument {\n return {\n collection: this.collection.collectionName,\n query: this.query,\n projection: this.projection,\n sort: this.order,\n skip: this.skipped,\n limit: this.limited,\n }\n }\n}\n\n/**\n * lakutata: a collection of the worker thread, with the methods of the collections of MongoDB that TypeORM calls:\n * each of them a call of the worker thread.\n */\nexport class EmbeddedWorkerCollection {\n constructor(\n readonly collectionName: string,\n readonly client: EmbeddedWorkerClient,\n ) {}\n\n find(query?: EmbeddedDocument, options?: EmbeddedDocument) {\n const cursor = new EmbeddedWorkerFindCursor(this, query ?? {})\n if (options?.projection) cursor.project(options.projection)\n if (options?.sort) cursor.sort(options.sort)\n if (options?.skip) cursor.skip(options.skip)\n if (options?.limit) cursor.limit(options.limit)\n return cursor\n }\n\n async findOne(query?: EmbeddedDocument, options?: EmbeddedDocument) {\n return this.find(query, options).limit(1).next()\n }\n\n aggregate(pipeline: EmbeddedDocument[], options?: EmbeddedDocument) {\n return new EmbeddedArrayCursor(() =>\n this.client.documents(\"aggregate\", {\n collection: this.collectionName,\n pipeline: pipeline,\n options: options,\n }),\n )\n }\n\n listIndexes() {\n return new EmbeddedArrayCursor(() => this.indexes())\n }\n\n /**\n * Inserts a document, its _id added when missing (to the document given, as MongoDB does).\n *\n * @param document\n */\n async insertOne(document: EmbeddedDocument) {\n document._id ??= new this.client.bson.ObjectId()\n return this.call(\"insertOne\", [document])\n }\n\n /**\n * Inserts documents, their _id added when missing (to the documents given, as MongoDB does).\n *\n * @param documents\n */\n async insertMany(\n documents: EmbeddedDocument[],\n options?: EmbeddedDocument,\n ) {\n for (const document of documents)\n document._id ??= new this.client.bson.ObjectId()\n const ordered = options?.ordered !== false\n const insertedIds: { [index: number]: any } = {}\n const writeErrors: EmbeddedWriteError[] = []\n let insertedCount = 0\n // Sent in parts (each one encoded a document at a time, smaller than the internal buffer of bson), their\n // results and their errors combined as the ones of one insertMany\n for (let start = 0; start < documents.length; start += SENT_DOCUMENTS) {\n let result: EmbeddedDocument\n try {\n result = await this.client.call(\n \"collection\",\n {\n collection: this.collectionName,\n method: \"insertMany\",\n args: [options],\n },\n encodeDocuments(\n this.client.bson,\n documents.slice(start, start + SENT_DOCUMENTS),\n ),\n )\n } catch (error) {\n if (!Array.isArray(error.writeErrors)) throw error\n result = error\n for (const writeError of error.writeErrors as EmbeddedWriteError[])\n writeErrors.push({\n ...writeError,\n index: start + writeError.index,\n })\n }\n insertedCount += result.insertedCount\n for (const index of Object.keys(result.insertedIds))\n insertedIds[start + Number(index)] = result.insertedIds[index]\n if (ordered && writeErrors.length) break\n }\n if (writeErrors.length)\n throw new EmbeddedBulkWriteError(\n writeErrors,\n insertedCount,\n insertedIds,\n )\n return {\n acknowledged: true,\n insertedCount: insertedCount,\n insertedIds: insertedIds,\n }\n }\n\n async countDocuments(...args: any[]) {\n return this.call(\"countDocuments\", args)\n }\n\n async count(...args: any[]) {\n return this.call(\"count\", args)\n }\n\n async estimatedDocumentCount(...args: any[]) {\n return this.call(\"estimatedDocumentCount\", args)\n }\n\n async distinct(...args: any[]) {\n return this.call(\"distinct\", args)\n }\n\n async updateOne(...args: any[]) {\n return this.call(\"updateOne\", args)\n }\n\n async updateMany(...args: any[]) {\n return this.call(\"updateMany\", args)\n }\n\n async replaceOne(...args: any[]) {\n return this.call(\"replaceOne\", args)\n }\n\n async deleteOne(...args: any[]) {\n return this.call(\"deleteOne\", args)\n }\n\n async deleteMany(...args: any[]) {\n return this.call(\"deleteMany\", args)\n }\n\n async createIndex(...args: any[]) {\n return this.call(\"createIndex\", args)\n }\n\n async createIndexes(...args: any[]) {\n return this.call(\"createIndexes\", args)\n }\n\n async indexes(...args: any[]) {\n return this.call(\"indexes\", args)\n }\n\n async indexExists(...args: any[]) {\n return this.call(\"indexExists\", args)\n }\n\n async indexInformation(...args: any[]) {\n return this.call(\"indexInformation\", args)\n }\n\n async dropIndex(...args: any[]) {\n return this.call(\"dropIndex\", args)\n }\n\n async dropIndexes(...args: any[]) {\n return this.call(\"dropIndexes\", args)\n }\n\n async isCapped(...args: any[]) {\n return this.call(\"isCapped\", args)\n }\n\n async bulkWrite(...args: any[]) {\n return this.call(\"bulkWrite\", args)\n }\n\n async findOneAndDelete(...args: any[]) {\n return this.call(\"findOneAndDelete\", args)\n }\n\n async findOneAndReplace(...args: any[]) {\n return this.call(\"findOneAndReplace\", args)\n }\n\n async findOneAndUpdate(...args: any[]) {\n return this.call(\"findOneAndUpdate\", args)\n }\n\n async rename(...args: any[]) {\n return this.call(\"rename\", args)\n }\n\n initializeOrderedBulkOp(): never {\n throw notSupported(\"initializeOrderedBulkOp\")\n }\n\n initializeUnorderedBulkOp(): never {\n throw notSupported(\"initializeUnorderedBulkOp\")\n }\n\n watch(): never {\n throw notSupported(\"watch\")\n }\n\n /**\n * Calls a method of the collection in the worker thread.\n *\n * @param method\n * @param args\n */\n protected call(method: string, args: any[]): Promise<any> {\n args.forEach((arg, position) => {\n if (DOCUMENT_ARGUMENTS[method] !== position) assertNoFunction(arg)\n })\n return this.client.call(\"collection\", {\n collection: this.collectionName,\n method: method,\n args: args,\n })\n }\n}\n\n/**\n * lakutata: the database of the worker thread.\n */\nexport class EmbeddedWorkerDb {\n protected readonly collections = new Map<string, EmbeddedWorkerCollection>()\n\n constructor(\n readonly databaseName: string,\n protected readonly client: EmbeddedWorkerClient,\n ) {}\n\n collection(name: string): EmbeddedWorkerCollection {\n let collection = this.collections.get(name)\n if (!collection) {\n collection = new EmbeddedWorkerCollection(name, this.client)\n this.collections.set(name, collection)\n }\n return collection\n }\n\n async dropDatabase(): Promise<boolean> {\n return this.client.call(\"db\", { method: \"dropDatabase\", args: [] })\n }\n\n async dropCollection(name: string): Promise<boolean> {\n return this.client.call(\"db\", { method: \"dropCollection\", args: [name] })\n }\n}\n\n/**\n * lakutata: the client of an embedded MongoDB run in a worker thread (the option worker), with the API of the client\n * of MongoDB that TypeORM calls: its calls and their results sent in BSON (the documents of a find decoded in\n * batches, the event loop yielded between them). The worker thread does not keep the process running while no call\n * waits for it. When it exits (its heap out of memory...), the calls waiting fail, and the directory it locked is\n * unlocked.\n */\nexport class EmbeddedWorkerClient {\n /**\n * The calls waiting for their reply, by their ids.\n */\n protected readonly calls = new Map<number, (reply: EmbeddedReply) => void>()\n\n protected nextId = 1\n\n /**\n * Why the calls fail: the worker thread exited, or the database is closed.\n */\n protected failure?: TypeORMError\n\n protected database?: EmbeddedWorkerDb\n\n /**\n * Its closing (the calls of close() share it).\n */\n protected closing?: Promise<void>\n\n /**\n * @param worker\n * @param bson\n * @param directory\n * @param token the token of the connection in the file LOCK of the directory\n */\n protected constructor(\n protected readonly worker: Worker,\n readonly bson: any,\n readonly directory: string | undefined,\n protected readonly token: string,\n ) {\n worker.on(\"message\", (reply: EmbeddedReply) => this.replied(reply))\n worker.on(\"error\", (error) =>\n this.exited(\n new TypeORMError(\n `The worker thread of mongo-embedded failed: ${error.message}`,\n ),\n ),\n )\n worker.on(\"exit\", (code) =>\n this.exited(\n new TypeORMError(\n `The worker thread of mongo-embedded exited (${code})`,\n ),\n ),\n )\n worker.unref()\n }\n\n /**\n * Opens a database in a worker thread: resolved once the worker thread opened it (its directory locked, the files\n * of its collections read).\n *\n * @param directory the directory of the database, or \":memory:\"\n * @param options\n * @param bson\n * @param resourceLimits the limits of the worker thread, if any (the ones of this thread otherwise)\n */\n static async connect(\n directory: string | undefined,\n options: EmbeddedStoreOptions,\n bson: any,\n resourceLimits?: ResourceLimits,\n ): Promise<EmbeddedWorkerClient> {\n if (!embeddedWorkerCode)\n throw new TypeORMError(\n \"The code of the worker thread of mongo-embedded is not built (the build of @lakutata/orm writes it): open it with the option worker false\",\n )\n const onDisk =\n directory && directory !== \":memory:\" ? directory : undefined\n const token = randomBytes(8).toString(\"hex\")\n const data: EmbeddedWorkerData = {\n directory: onDisk,\n options: options,\n token: token,\n }\n const worker = new Worker(embeddedWorkerCode, {\n eval: true,\n workerData: { [WORKER_DATA_KEY]: data },\n ...(resourceLimits ? { resourceLimits: resourceLimits } : {}),\n })\n const opened = await new Promise<EmbeddedReply>((resolve) => {\n const done = (reply: EmbeddedReply) => {\n worker.off(\"message\", done)\n worker.off(\"error\", failed)\n worker.off(\"exit\", exited)\n resolve(reply)\n }\n const failed = (error: Error) =>\n done({ id: 0, error: { name: error.name, message: error.message } })\n const exited = (code: number) =>\n done({\n id: 0,\n error: {\n name: \"TypeORMError\",\n message: `The worker thread of mongo-embedded exited (${code}) before it opened the database`,\n },\n })\n worker.on(\"message\", done)\n worker.on(\"error\", failed)\n worker.on(\"exit\", exited)\n })\n if (opened.error) {\n await worker.terminate()\n // Its directory locked by the worker thread exited before it opened it (out of memory while it read its\n // files): unlocked (a failure replied by the worker thread unlocked it already)\n if (onDisk) unlockDirectory(onDisk, token)\n throw errorOf(bson, opened.error)\n }\n return new EmbeddedWorkerClient(worker, bson, onDisk, token)\n }\n\n db(name = \"embedded\"): EmbeddedWorkerDb {\n this.database ??= new EmbeddedWorkerDb(name, this)\n return this.database\n }\n\n /**\n * Calls the worker thread: its result.\n *\n * @param op\n * @param call the arguments of the call\n * @param documents the documents of an insertMany (encodeDocuments)\n */\n async call(\n op: EmbeddedRequest[\"op\"],\n call: EmbeddedDocument,\n documents?: Uint8Array,\n ): Promise<any> {\n const reply = await this.request(op, encode(this.bson, call), documents)\n if (reply.error) throw errorOf(this.bson, reply.error)\n return reply.payload\n ? this.bson.deserialize(reply.payload).result\n : undefined\n }\n\n /**\n * The documents of a find or an aggregation of the worker thread, decoded a batch at a time, the event loop yielded\n * between them.\n *\n * @param op\n * @param call the arguments of the call\n */\n async documents(\n op: \"find\" | \"aggregate\",\n call: EmbeddedDocument,\n ): Promise<EmbeddedDocument[]> {\n assertNoFunction(op === \"find\" ? [call.query, call.projection, call.sort] : [call.pipeline, call.options])\n const reply = await this.request(op, encode(this.bson, call))\n if (reply.error) throw errorOf(this.bson, reply.error)\n const documents: EmbeddedDocument[] = []\n for (const [position, batch] of (reply.batches ?? []).entries()) {\n if (position) await yieldLoop()\n for (const document of decodeDocuments(this.bson, batch))\n documents.push(document)\n }\n return documents\n }\n\n /**\n * The documents of a find read a batch at a time: a cursor of the worker thread, read as they are asked (closed\n * at its end, or when the stream is closed before it).\n *\n * @param call the arguments of the find\n */\n async *streamed(call: EmbeddedDocument): AsyncGenerator<EmbeddedDocument[]> {\n assertNoFunction([call.query, call.projection, call.sort])\n let reply = await this.request(\"open\", encode(this.bson, call))\n let ended = false\n try {\n for (;;) {\n if (reply.error) throw errorOf(this.bson, reply.error)\n for (const batch of reply.batches ?? [])\n yield decodeDocuments(this.bson, batch)\n // No cursor: the find does not stream (isStreamed), all its documents replied at once\n if (reply.done || reply.cursor === undefined) {\n ended = true\n return\n }\n reply = await this.request(\n \"more\",\n this.bson.serialize({ cursor: reply.cursor }),\n )\n }\n } finally {\n // Closed before its end (a cursor the worker thread did not close yet): killed, not awaited\n if (!ended && reply.cursor !== undefined)\n void this.request(\n \"kill\",\n this.bson.serialize({ cursor: reply.cursor }),\n )\n }\n }\n\n /**\n * Closes the database (its files written to the disk, its snapshots), then the worker thread: the calls still\n * waiting then fail.\n */\n close(): Promise<void> {\n this.closing ??= this.closeWorker()\n return this.closing\n }\n\n /**\n * Closes the database, then ends the worker thread. Closed after the worker thread exited, it resolves (the\n * database is closed). The calls fail before the thread is ended: its exit is not taken for a failure (exited),\n * the database unlocked its directory.\n */\n protected async closeWorker(): Promise<void> {\n if (this.failure) return\n const reply = await this.request(\"close\")\n this.fail(new TypeORMError(\"The database of mongo-embedded is closed\"))\n await this.worker.terminate()\n if (reply.error) throw errorOf(this.bson, reply.error)\n }\n\n /**\n * Sends a call to the worker thread: its reply (the failure of the worker thread replies to the calls waiting).\n *\n * @param op\n * @param payload\n * @param documents the documents of an insertMany (encodeDocuments)\n */\n protected request(\n op: EmbeddedRequest[\"op\"],\n payload?: Uint8Array,\n documents?: Uint8Array,\n ): Promise<EmbeddedReply> {\n if (this.failure)\n return Promise.resolve({\n id: 0,\n error: {\n name: \"TypeORMError\",\n message: this.failure.message,\n },\n })\n const id = this.nextId++\n return new Promise((resolve) => {\n this.calls.set(id, resolve)\n // The worker thread keeps the process running while a call waits for it\n if (this.calls.size === 1) this.worker.ref()\n const request: EmbeddedRequest = {\n id: id,\n op: op,\n payload: payload,\n documents: documents,\n }\n this.worker.postMessage(request)\n })\n }\n\n protected replied(reply: EmbeddedReply): void {\n const resolve = this.calls.get(reply.id)\n if (!resolve) return\n this.calls.delete(reply.id)\n if (!this.calls.size) this.worker.unref()\n resolve(reply)\n }\n\n /**\n * Fails the calls waiting, and the calls made after them.\n *\n * @param failure\n */\n protected fail(failure: TypeORMError): void {\n this.failure = failure\n for (const resolve of this.calls.values())\n resolve({\n id: 0,\n error: { name: \"TypeORMError\", message: failure.message },\n })\n this.calls.clear()\n }\n\n /**\n * After the worker thread exited, not closed: the calls waiting fail, and the directory it locked (its file LOCK\n * holding the token of the connection) is unlocked.\n *\n * @param failure\n */\n protected exited(failure: TypeORMError): void {\n if (this.failure) return\n this.fail(failure)\n if (this.directory) unlockDirectory(this.directory, this.token)\n }\n}\n"]}
1
+ {"version":3,"file":"EmbeddedWorkerClient.js","sourceRoot":"","sources":["../../../../../vendor/typeorm/driver/mongo-embedded/EmbeddedWorkerClient.ts"],"names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OAAO;YAAE,OAAM;QACpB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC3B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI;YAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACzC,OAAO,CAAC,KAAK,CAAC,CAAA;IAClB,CAAC;IAED;;;;OAIG;IACO,IAAI,CAAC,OAAqB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACrC,OAAO,CAAC;gBACJ,EAAE,EAAE,CAAC;gBACL,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;aAC5D,CAAC,CAAA;QACN,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;IAED;;;;;OAKG;IACO,MAAM,CAAC,OAAqB;QAClC,IAAI,IAAI,CAAC,OAAO;YAAE,OAAM;QACxB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClB,IAAI,IAAI,CAAC,SAAS;YAAE,IAAA,+BAAe,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IACnE,CAAC;CACJ;AAlSD,oDAkSC","sourcesContent":["import { randomBytes } from \"crypto\"\nimport type { ResourceLimits } from \"worker_threads\"\nimport { Worker } from \"worker_threads\"\nimport { TypeORMError } from \"../../error/TypeORMError\"\nimport {\n EmbeddedArrayCursor,\n EmbeddedResults,\n isStreamed,\n} from \"./EmbeddedClient\"\nimport type { EmbeddedWriteError } from \"./EmbeddedCollectionStore\"\nimport { EmbeddedBulkWriteError } from \"./EmbeddedCollectionStore\"\nimport type { EmbeddedStoreOptions } from \"./EmbeddedStore\"\nimport { unlockDirectory } from \"./EmbeddedStore\"\nimport type { EmbeddedDocument } from \"./EmbeddedValues\"\nimport { embeddedWorkerCode } from \"./EmbeddedWorkerCode\"\nimport type {\n EmbeddedReply,\n EmbeddedRequest,\n EmbeddedWorkerData,\n} from \"./EmbeddedWorkerProtocol\"\nimport {\n decodeDocuments,\n encode,\n encodeDocuments,\n errorOf,\n WORKER_DATA_KEY,\n} from \"./EmbeddedWorkerProtocol\"\n\n/**\n * lakutata: yields the event loop.\n */\nfunction yieldLoop(): Promise<void> {\n return new Promise((resolve) => setImmediate(resolve))\n}\n\n/**\n * lakutata: the error of a method of the client of MongoDB that the embedded client does not have.\n *\n * @param method\n */\nfunction notSupported(method: string): TypeORMError {\n return new TypeORMError(`${method} is not supported by mongo-embedded`)\n}\n\n/**\n * lakutata: throws when a value of a query holds a function: BSON does not send it to the worker thread (the\n * functions of JavaScript of $where, $function and $accumulator run in the client of the option worker false).\n *\n * @param value\n */\nfunction assertNoFunction(value: any): void {\n if (typeof value === \"function\")\n throw new TypeORMError(\n \"The functions of JavaScript of a query are not sent to the worker thread of mongo-embedded: they run with its option worker false\",\n )\n if (value === null || typeof value !== \"object\") return\n if (Array.isArray(value)) {\n for (const item of value) assertNoFunction(item)\n return\n }\n const prototype = Object.getPrototypeOf(value)\n if (prototype !== Object.prototype && prototype !== null) return\n for (const key of Object.keys(value)) assertNoFunction(value[key])\n}\n\n/**\n * lakutata: the arguments of the methods of the collections that are documents, not queries: a function of a document\n * is not stored, in both clients.\n */\nconst DOCUMENT_ARGUMENTS: { [method: string]: number } = {\n insertOne: 0,\n insertMany: 0,\n replaceOne: 1,\n}\n\n/**\n * lakutata: the documents of an insertMany sent to the worker thread in a call (their encoding a stall of about 10 ms\n * of this thread, the event loop yielded between the calls).\n */\nconst SENT_DOCUMENTS = 10000\n\n/**\n * lakutata: the cursor of a find of a collection of the worker thread: its filter, projection, order, skip and limit\n * sent with the call reading it.\n */\nexport class EmbeddedWorkerFindCursor extends EmbeddedResults {\n protected projection?: EmbeddedDocument\n\n protected order?: EmbeddedDocument\n\n protected skipped?: number\n\n protected limited?: number\n\n constructor(\n protected readonly collection: EmbeddedWorkerCollection,\n protected query: EmbeddedDocument,\n ) {\n super()\n }\n\n filter(query: EmbeddedDocument): this {\n this.query = query\n return this\n }\n\n project(projection: EmbeddedDocument): this {\n this.projection = projection\n return this\n }\n\n sort(order: EmbeddedDocument): this {\n this.order = order\n return this\n }\n\n skip(count: number): this {\n this.skipped = count\n return this\n }\n\n limit(count: number): this {\n this.limited = count\n return this\n }\n\n protected documents(): Promise<EmbeddedDocument[]> {\n return this.collection.client.documents(\"find\", this.call())\n }\n\n protected batches(): AsyncIterator<EmbeddedDocument[]> | undefined {\n return isStreamed(this.order, this.skipped, this.limited)\n ? this.collection.client.streamed(this.call())\n : undefined\n }\n\n protected call(): EmbeddedDocument {\n return {\n collection: this.collection.collectionName,\n query: this.query,\n projection: this.projection,\n sort: this.order,\n skip: this.skipped,\n limit: this.limited,\n }\n }\n}\n\n/**\n * lakutata: a collection of the worker thread, with the methods of the collections of MongoDB that TypeORM calls:\n * each of them a call of the worker thread.\n */\nexport class EmbeddedWorkerCollection {\n constructor(\n readonly collectionName: string,\n readonly client: EmbeddedWorkerClient,\n ) {}\n\n find(query?: EmbeddedDocument, options?: EmbeddedDocument) {\n const cursor = new EmbeddedWorkerFindCursor(this, query ?? {})\n if (options?.projection) cursor.project(options.projection)\n if (options?.sort) cursor.sort(options.sort)\n if (options?.skip) cursor.skip(options.skip)\n if (options?.limit) cursor.limit(options.limit)\n return cursor\n }\n\n async findOne(query?: EmbeddedDocument, options?: EmbeddedDocument) {\n return this.find(query, options).limit(1).next()\n }\n\n aggregate(pipeline: EmbeddedDocument[], options?: EmbeddedDocument) {\n return new EmbeddedArrayCursor(() =>\n this.client.documents(\"aggregate\", {\n collection: this.collectionName,\n pipeline: pipeline,\n options: options,\n }),\n )\n }\n\n listIndexes() {\n return new EmbeddedArrayCursor(() => this.indexes())\n }\n\n /**\n * Inserts a document, its _id added when missing (to the document given, as MongoDB does).\n *\n * @param document\n */\n async insertOne(document: EmbeddedDocument) {\n document._id ??= new this.client.bson.ObjectId()\n return this.call(\"insertOne\", [document])\n }\n\n /**\n * Inserts documents, their _id added when missing (to the documents given, as MongoDB does).\n *\n * @param documents\n */\n async insertMany(\n documents: EmbeddedDocument[],\n options?: EmbeddedDocument,\n ) {\n for (const document of documents)\n document._id ??= new this.client.bson.ObjectId()\n const ordered = options?.ordered !== false\n const insertedIds: { [index: number]: any } = {}\n const writeErrors: EmbeddedWriteError[] = []\n let insertedCount = 0\n // Sent in parts (each one encoded a document at a time, smaller than the internal buffer of bson), their\n // results and their errors combined as the ones of one insertMany\n for (let start = 0; start < documents.length; start += SENT_DOCUMENTS) {\n let result: EmbeddedDocument\n try {\n result = await this.client.call(\n \"collection\",\n {\n collection: this.collectionName,\n method: \"insertMany\",\n args: [options],\n },\n encodeDocuments(\n this.client.bson,\n documents.slice(start, start + SENT_DOCUMENTS),\n ),\n )\n } catch (error) {\n if (!Array.isArray(error.writeErrors)) throw error\n result = error\n for (const writeError of error.writeErrors as EmbeddedWriteError[])\n writeErrors.push({\n ...writeError,\n index: start + writeError.index,\n })\n }\n insertedCount += result.insertedCount\n for (const index of Object.keys(result.insertedIds))\n insertedIds[start + Number(index)] = result.insertedIds[index]\n if (ordered && writeErrors.length) break\n }\n if (writeErrors.length)\n throw new EmbeddedBulkWriteError(\n writeErrors,\n insertedCount,\n insertedIds,\n )\n return {\n acknowledged: true,\n insertedCount: insertedCount,\n insertedIds: insertedIds,\n }\n }\n\n async countDocuments(...args: any[]) {\n return this.call(\"countDocuments\", args)\n }\n\n async count(...args: any[]) {\n return this.call(\"count\", args)\n }\n\n async estimatedDocumentCount(...args: any[]) {\n return this.call(\"estimatedDocumentCount\", args)\n }\n\n async distinct(...args: any[]) {\n return this.call(\"distinct\", args)\n }\n\n async updateOne(...args: any[]) {\n return this.call(\"updateOne\", args)\n }\n\n async updateMany(...args: any[]) {\n return this.call(\"updateMany\", args)\n }\n\n async replaceOne(...args: any[]) {\n return this.call(\"replaceOne\", args)\n }\n\n async deleteOne(...args: any[]) {\n return this.call(\"deleteOne\", args)\n }\n\n async deleteMany(...args: any[]) {\n return this.call(\"deleteMany\", args)\n }\n\n async createIndex(...args: any[]) {\n return this.call(\"createIndex\", args)\n }\n\n async createIndexes(...args: any[]) {\n return this.call(\"createIndexes\", args)\n }\n\n async indexes(...args: any[]) {\n return this.call(\"indexes\", args)\n }\n\n async indexExists(...args: any[]) {\n return this.call(\"indexExists\", args)\n }\n\n async indexInformation(...args: any[]) {\n return this.call(\"indexInformation\", args)\n }\n\n async dropIndex(...args: any[]) {\n return this.call(\"dropIndex\", args)\n }\n\n async dropIndexes(...args: any[]) {\n return this.call(\"dropIndexes\", args)\n }\n\n async isCapped(...args: any[]) {\n return this.call(\"isCapped\", args)\n }\n\n async bulkWrite(...args: any[]) {\n return this.call(\"bulkWrite\", args)\n }\n\n async findOneAndDelete(...args: any[]) {\n return this.call(\"findOneAndDelete\", args)\n }\n\n async findOneAndReplace(...args: any[]) {\n return this.call(\"findOneAndReplace\", args)\n }\n\n async findOneAndUpdate(...args: any[]) {\n return this.call(\"findOneAndUpdate\", args)\n }\n\n async rename(...args: any[]) {\n return this.call(\"rename\", args)\n }\n\n initializeOrderedBulkOp(): never {\n throw notSupported(\"initializeOrderedBulkOp\")\n }\n\n initializeUnorderedBulkOp(): never {\n throw notSupported(\"initializeUnorderedBulkOp\")\n }\n\n watch(): never {\n throw notSupported(\"watch\")\n }\n\n /**\n * Calls a method of the collection in the worker thread.\n *\n * @param method\n * @param args\n */\n protected call(method: string, args: any[]): Promise<any> {\n args.forEach((arg, position) => {\n if (DOCUMENT_ARGUMENTS[method] !== position) assertNoFunction(arg)\n })\n return this.client.call(\"collection\", {\n collection: this.collectionName,\n method: method,\n args: args,\n })\n }\n}\n\n/**\n * lakutata: the database of the worker thread.\n */\nexport class EmbeddedWorkerDb {\n protected readonly collections = new Map<string, EmbeddedWorkerCollection>()\n\n constructor(\n readonly databaseName: string,\n protected readonly client: EmbeddedWorkerClient,\n ) {}\n\n collection(name: string): EmbeddedWorkerCollection {\n let collection = this.collections.get(name)\n if (!collection) {\n collection = new EmbeddedWorkerCollection(name, this.client)\n this.collections.set(name, collection)\n }\n return collection\n }\n\n async dropDatabase(): Promise<boolean> {\n return this.client.call(\"db\", { method: \"dropDatabase\", args: [] })\n }\n\n async dropCollection(name: string): Promise<boolean> {\n return this.client.call(\"db\", { method: \"dropCollection\", args: [name] })\n }\n}\n\n/**\n * lakutata: the client of an embedded MongoDB run in a worker thread (the option worker), with the API of the client\n * of MongoDB that TypeORM calls: its calls and their results sent in BSON (the documents of a find decoded in\n * batches, the event loop yielded between them). The worker thread does not keep the process running while no call\n * waits for it. When it exits (its heap out of memory...), the calls waiting fail, and the directory it locked is\n * unlocked.\n */\nexport class EmbeddedWorkerClient {\n /**\n * The calls waiting for their reply, by their ids.\n */\n protected readonly calls = new Map<number, (reply: EmbeddedReply) => void>()\n\n protected nextId = 1\n\n /**\n * Why the calls fail: the worker thread exited, or the database is closed.\n */\n protected failure?: TypeORMError\n\n protected database?: EmbeddedWorkerDb\n\n /**\n * Its closing (the calls of close() share it).\n */\n protected closing?: Promise<void>\n\n /**\n * @param worker\n * @param bson\n * @param directory\n * @param token the token of the connection in the file LOCK of the directory\n */\n protected constructor(\n protected readonly worker: Worker,\n readonly bson: any,\n readonly directory: string | undefined,\n protected readonly token: string,\n ) {\n worker.on(\"message\", (reply: EmbeddedReply) => this.replied(reply))\n worker.on(\"error\", (error) =>\n this.exited(\n new TypeORMError(\n `The worker thread of mongo-embedded failed: ${error.message}`,\n ),\n ),\n )\n worker.on(\"exit\", (code) =>\n this.exited(\n new TypeORMError(\n `The worker thread of mongo-embedded exited (${code})`,\n ),\n ),\n )\n worker.unref()\n }\n\n /**\n * Opens a database in a worker thread: resolved once the worker thread opened it (its directory locked, the files\n * of its collections read).\n *\n * @param directory the directory of the database, or \":memory:\"\n * @param options\n * @param bson\n * @param resourceLimits the limits of the worker thread, if any (the ones of this thread otherwise)\n */\n static async connect(\n directory: string | undefined,\n options: EmbeddedStoreOptions,\n bson: any,\n resourceLimits?: ResourceLimits,\n ): Promise<EmbeddedWorkerClient> {\n if (!embeddedWorkerCode)\n throw new TypeORMError(\n \"The code of the worker thread of mongo-embedded is not built (the build of @lakutata/orm writes it): open it with the option worker false\",\n )\n const onDisk =\n directory && directory !== \":memory:\" ? directory : undefined\n const token = randomBytes(8).toString(\"hex\")\n const data: EmbeddedWorkerData = {\n directory: onDisk,\n options: options,\n token: token,\n }\n const worker = new Worker(embeddedWorkerCode, {\n eval: true,\n // lakutata: none of the options of the command line of the process, which the worker would inherit: with\n // --input-type=module, its code (CommonJS) would run as an ES module; a list of its own refuses the\n // options of V8 (--max-old-space-size) that the process may have\n execArgv: [],\n workerData: { [WORKER_DATA_KEY]: data },\n ...(resourceLimits ? { resourceLimits: resourceLimits } : {}),\n })\n const opened = await new Promise<EmbeddedReply>((resolve) => {\n const done = (reply: EmbeddedReply) => {\n worker.off(\"message\", done)\n worker.off(\"error\", failed)\n worker.off(\"exit\", exited)\n resolve(reply)\n }\n const failed = (error: Error) =>\n done({ id: 0, error: { name: error.name, message: error.message } })\n const exited = (code: number) =>\n done({\n id: 0,\n error: {\n name: \"TypeORMError\",\n message: `The worker thread of mongo-embedded exited (${code}) before it opened the database`,\n },\n })\n worker.on(\"message\", done)\n worker.on(\"error\", failed)\n worker.on(\"exit\", exited)\n })\n if (opened.error) {\n await worker.terminate()\n // Its directory locked by the worker thread exited before it opened it (out of memory while it read its\n // files): unlocked (a failure replied by the worker thread unlocked it already)\n if (onDisk) unlockDirectory(onDisk, token)\n throw errorOf(bson, opened.error)\n }\n return new EmbeddedWorkerClient(worker, bson, onDisk, token)\n }\n\n db(name = \"embedded\"): EmbeddedWorkerDb {\n this.database ??= new EmbeddedWorkerDb(name, this)\n return this.database\n }\n\n /**\n * Calls the worker thread: its result.\n *\n * @param op\n * @param call the arguments of the call\n * @param documents the documents of an insertMany (encodeDocuments)\n */\n async call(\n op: EmbeddedRequest[\"op\"],\n call: EmbeddedDocument,\n documents?: Uint8Array,\n ): Promise<any> {\n const reply = await this.request(op, encode(this.bson, call), documents)\n if (reply.error) throw errorOf(this.bson, reply.error)\n return reply.payload\n ? this.bson.deserialize(reply.payload).result\n : undefined\n }\n\n /**\n * The documents of a find or an aggregation of the worker thread, decoded a batch at a time, the event loop yielded\n * between them.\n *\n * @param op\n * @param call the arguments of the call\n */\n async documents(\n op: \"find\" | \"aggregate\",\n call: EmbeddedDocument,\n ): Promise<EmbeddedDocument[]> {\n assertNoFunction(op === \"find\" ? [call.query, call.projection, call.sort] : [call.pipeline, call.options])\n const reply = await this.request(op, encode(this.bson, call))\n if (reply.error) throw errorOf(this.bson, reply.error)\n const documents: EmbeddedDocument[] = []\n for (const [position, batch] of (reply.batches ?? []).entries()) {\n if (position) await yieldLoop()\n for (const document of decodeDocuments(this.bson, batch))\n documents.push(document)\n }\n return documents\n }\n\n /**\n * The documents of a find read a batch at a time: a cursor of the worker thread, read as they are asked (closed\n * at its end, or when the stream is closed before it).\n *\n * @param call the arguments of the find\n */\n async *streamed(call: EmbeddedDocument): AsyncGenerator<EmbeddedDocument[]> {\n assertNoFunction([call.query, call.projection, call.sort])\n let reply = await this.request(\"open\", encode(this.bson, call))\n let ended = false\n try {\n for (;;) {\n if (reply.error) throw errorOf(this.bson, reply.error)\n for (const batch of reply.batches ?? [])\n yield decodeDocuments(this.bson, batch)\n // No cursor: the find does not stream (isStreamed), all its documents replied at once\n if (reply.done || reply.cursor === undefined) {\n ended = true\n return\n }\n reply = await this.request(\n \"more\",\n this.bson.serialize({ cursor: reply.cursor }),\n )\n }\n } finally {\n // Closed before its end (a cursor the worker thread did not close yet): killed, not awaited\n if (!ended && reply.cursor !== undefined)\n void this.request(\n \"kill\",\n this.bson.serialize({ cursor: reply.cursor }),\n )\n }\n }\n\n /**\n * Closes the database (its files written to the disk, its snapshots), then the worker thread: the calls still\n * waiting then fail.\n */\n close(): Promise<void> {\n this.closing ??= this.closeWorker()\n return this.closing\n }\n\n /**\n * Closes the database, then ends the worker thread. Closed after the worker thread exited, it resolves (the\n * database is closed). The calls fail before the thread is ended: its exit is not taken for a failure (exited),\n * the database unlocked its directory.\n */\n protected async closeWorker(): Promise<void> {\n if (this.failure) return\n const reply = await this.request(\"close\")\n this.fail(new TypeORMError(\"The database of mongo-embedded is closed\"))\n await this.worker.terminate()\n if (reply.error) throw errorOf(this.bson, reply.error)\n }\n\n /**\n * Sends a call to the worker thread: its reply (the failure of the worker thread replies to the calls waiting).\n *\n * @param op\n * @param payload\n * @param documents the documents of an insertMany (encodeDocuments)\n */\n protected request(\n op: EmbeddedRequest[\"op\"],\n payload?: Uint8Array,\n documents?: Uint8Array,\n ): Promise<EmbeddedReply> {\n if (this.failure)\n return Promise.resolve({\n id: 0,\n error: {\n name: \"TypeORMError\",\n message: this.failure.message,\n },\n })\n const id = this.nextId++\n return new Promise((resolve) => {\n this.calls.set(id, resolve)\n // The worker thread keeps the process running while a call waits for it\n if (this.calls.size === 1) this.worker.ref()\n const request: EmbeddedRequest = {\n id: id,\n op: op,\n payload: payload,\n documents: documents,\n }\n this.worker.postMessage(request)\n })\n }\n\n protected replied(reply: EmbeddedReply): void {\n const resolve = this.calls.get(reply.id)\n if (!resolve) return\n this.calls.delete(reply.id)\n if (!this.calls.size) this.worker.unref()\n resolve(reply)\n }\n\n /**\n * Fails the calls waiting, and the calls made after them.\n *\n * @param failure\n */\n protected fail(failure: TypeORMError): void {\n this.failure = failure\n for (const resolve of this.calls.values())\n resolve({\n id: 0,\n error: { name: \"TypeORMError\", message: failure.message },\n })\n this.calls.clear()\n }\n\n /**\n * After the worker thread exited, not closed: the calls waiting fail, and the directory it locked (its file LOCK\n * holding the token of the connection) is unlocked.\n *\n * @param failure\n */\n protected exited(failure: TypeORMError): void {\n if (this.failure) return\n this.fail(failure)\n if (this.directory) unlockDirectory(this.directory, this.token)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lakutata/orm",
3
- "version": "3.1.5",
3
+ "version": "3.1.6",
4
4
  "description": "The ORM of the lakutata framework, on TypeORM: the Database component and provider, the entity decorators and the generation of the migrations.",
5
5
  "keywords": [
6
6
  "lakutata",
@@ -102,7 +102,7 @@
102
102
  },
103
103
  "peerDependencies": {
104
104
  "@google-cloud/spanner": "^8.0.0",
105
- "@lakutata/core": "~3.1.5",
105
+ "@lakutata/core": "~3.1.6",
106
106
  "@lakutata/utils": "~3.1.5",
107
107
  "@sap/hana-client": "^2.14.22",
108
108
  "better-sqlite3": "^11.0.0 || ^12.0.0",