@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
@@ -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,CA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N,CAAC;IAES,OAAO,CAAC,KAAoB;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,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,"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GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,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;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"]}