@venizia/ignis-connectors 0.4.6 → 0.4.7-0
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/dist/esm/http/datasource.d.ts.map +1 -1
- package/dist/esm/http/datasource.js +6 -3
- package/dist/esm/http/datasource.js.map +1 -1
- package/dist/esm/relational/core/repositories/core/base.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/core/base.js +2 -1
- package/dist/esm/relational/core/repositories/core/base.js.map +1 -1
- package/dist/esm/relational/core/repositories/core/readable.d.ts.map +1 -1
- package/dist/esm/relational/core/repositories/core/readable.js +7 -3
- package/dist/esm/relational/core/repositories/core/readable.js.map +1 -1
- package/dist/esm/relational/postgres/drivers/pglite.d.ts.map +1 -1
- package/dist/esm/relational/postgres/drivers/pglite.js +2 -1
- package/dist/esm/relational/postgres/drivers/pglite.js.map +1 -1
- package/dist/esm/relational/postgres/repositories/executor.d.ts.map +1 -1
- package/dist/esm/relational/postgres/repositories/executor.js +6 -3
- package/dist/esm/relational/postgres/repositories/executor.js.map +1 -1
- package/dist/esm/relational/sqlite/drivers/libsql.d.ts.map +1 -1
- package/dist/esm/relational/sqlite/drivers/libsql.js +2 -1
- package/dist/esm/relational/sqlite/drivers/libsql.js.map +1 -1
- package/dist/esm/relational/sqlite/repositories/executor.d.ts.map +1 -1
- package/dist/esm/relational/sqlite/repositories/executor.js +6 -3
- package/dist/esm/relational/sqlite/repositories/executor.js.map +1 -1
- package/dist/esm/search/core/controllers/abstract.d.ts.map +1 -1
- package/dist/esm/search/core/controllers/abstract.js +5 -3
- package/dist/esm/search/core/controllers/abstract.js.map +1 -1
- package/dist/esm/search/core/controllers/scope.d.ts.map +1 -1
- package/dist/esm/search/core/controllers/scope.js +2 -1
- package/dist/esm/search/core/controllers/scope.js.map +1 -1
- package/dist/esm/search/core/repositories/core/persistable.d.ts.map +1 -1
- package/dist/esm/search/core/repositories/core/persistable.js +2 -1
- package/dist/esm/search/core/repositories/core/persistable.js.map +1 -1
- package/dist/esm/search/core/repositories/core/readable.d.ts.map +1 -1
- package/dist/esm/search/core/repositories/core/readable.js +8 -5
- package/dist/esm/search/core/repositories/core/readable.js.map +1 -1
- package/dist/esm/search/meilisearch/connector.d.ts.map +1 -1
- package/dist/esm/search/meilisearch/connector.js +10 -3
- package/dist/esm/search/meilisearch/connector.js.map +1 -1
- package/dist/esm/search/typesense/connector.d.ts.map +1 -1
- package/dist/esm/search/typesense/connector.js +25 -26
- package/dist/esm/search/typesense/connector.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pglite.js","sourceRoot":"","sources":["../../../../../src/relational/postgres/drivers/pglite.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAM7C;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IAavB;;;;OAIG;aACa,+BAA0B,GAAG,MAAM,CAAC;IAEpD;;;;;;;;OAQG;aACqB,0BAAqB,GAAG,EAAE,CAAC;IAEnD,YAAY,IAA0B;QACpC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEpE,6FAA6F;QAC7F,0FAA0F;QAC1F,MAAM,QAAQ,GACZ,OAAQ,MAAkB,EAAE,KAAK,KAAK,UAAU;YAChD,OAAQ,MAAkB,EAAE,IAAI,KAAK,UAAU;YAC/C,OAAQ,MAAkB,EAAE,KAAK,KAAK,UAAU,CAAC;QAEnD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,IAAI,YAAY,CAAC,IAAI,iLAAiL;aAChN,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,gFAAgF;Q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C,KAAK,CAAC,+CAA+C,EAAE,KAAK,CAAC,CAAC;gBAC3F,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;;;;OASG;IACK,uBAAuB;QAC7B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC;QAEhC,IAAI,IAAI,EAAE,QAAQ,KAAK,YAAY,CAAC,qBAAqB,EAAE,CAAC;YAC1D,OAAO;QACT,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;aAClB,KAAK,CACJ,yEAAyE,EACzE,YAAY,CAAC,qBAAqB,CACnC,CAAC;IACN,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,YAAY,CAAC,IAA0B;QACnD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;iBAC3B,IAAI,CAAC,gDAAgD,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC;IACH,CAAC","sourcesContent":["import type { TAnyDataSourceSchema } from '@venizia/ignis-kernel';\nimport type { TRelationalConnector } from '@/relational/postgres/datasources/common';\nimport type { PGlite } from '@electric-sql/pglite';\nimport type { ILogger, IPoolControlOptions } from '@venizia/ignis-helpers/core';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, BasePoolHelper, getError } from '@venizia/ignis-helpers/core';\nimport { drizzle } from 'drizzle-orm/pglite';\nimport type { TRelationalConnection, TRelationalDriver } from './driver';\n\n/** Pool knobs the driver forwards, minus `size`: one slot IS the mutual exclusion PGlite lacks. */\nexport type TPGliteDriverOptions = Omit<IPoolControlOptions, 'size'> & { client: PGlite };\n\n/**\n * Postgres compiled to WASM, in-process. Reports PostgreSQL 18.x, so the dialect works unchanged.\n *\n * One session only, and a second `BEGIN` neither nests nor errors - it joins the open transaction,\n * so the outer COMMIT commits the inner writer's rows. Hence the 1-slot pool behind `acquire()`.\n *\n * Consequence: a `createConnector()` write - the path all repositories take - runs INSIDE any open\n * transaction and dies with its ROLLBACK. Under concurrency, write through `acquire()`.\n */\nexport class PGliteDriver<\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n> implements TRelationalDriver<Schema, PGlite> {\n private readonly client: PGlite;\n\n /**\n * The pooled resource IS the single client, so `create()` always hands back the same instance.\n * The pool contributes the mutual exclusion PGlite lacks, not connection multiplicity.\n */\n private readonly slot: BasePoolHelper<PGlite>;\n\n private readonly logger: ILogger;\n\n /**\n * A leaked transaction never releases the one slot, so without a timeout every later `acquire()`\n * in the process hangs forever and silently. 30s outlasts any honest transaction on an in-process\n * database with no network in it, and turns a leak into a named error instead of a dead process.\n */\n static readonly DEFAULT_ACQUIRE_TIMEOUT_MS = 30_000;\n\n /**\n * PGlite's Emscripten runtime plants this status on the HOST process during ordinary operation -\n * measured on `@electric-sql/pglite` 0.5.5, `process.exitCode` is `undefined` before the first\n * query and 99 after it, and every later query re-arms it. A server that shuts down cleanly then\n * exits 99, which Docker, systemd and CI all read as a crash.\n *\n * Named rather than inlined so a future PGlite using a different status stops matching and makes\n * the problem visible again, instead of {@link end} silently forcing a zero it did not verify.\n */\n private static readonly WASM_HOST_EXIT_STATUS = 99;\n\n constructor(opts: TPGliteDriverOptions) {\n const { client, acquireTimeoutMs, maxWaitingClients, scope } = opts;\n\n // PGlite is not a connection pool: it has no connect()/totalCount, which is what a `pg.Pool`\n // leads with. Probing its own verbs names the mistake here instead of at the first query.\n const isPGlite =\n typeof (client as AnyType)?.query === 'function' &&\n typeof (client as AnyType)?.exec === 'function' &&\n typeof (client as AnyType)?.close === 'function';\n\n if (!isPGlite) {\n throw getError({\n message: `[${PGliteDriver.name}] Expected an \\`@electric-sql/pglite\\` PGlite | Got a client without exec()/close() - a \\`pg.Pool\\`? | Construct \\`new PGlite('./pgdata')\\`, or name NodePostgresDriver instead`,\n });\n }\n\n this.client = client;\n // `LoggerFactory` cannot be imported here: this is the browser driver, and that\n // import reaches `node:module`. `BaseHelper` resolves the same logger through\n // the swappable resolver without pulling in the node-only provider loader.\n this.logger = new BaseHelper({ scope: PGliteDriver.name }).getLogger();\n\n this.slot = new BasePoolHelper<PGlite>({\n size: 1,\n acquireTimeoutMs: acquireTimeoutMs ?? PGliteDriver.DEFAULT_ACQUIRE_TIMEOUT_MS,\n maxWaitingClients,\n scope: scope ?? PGliteDriver.name,\n create: async () => {\n await this.client.waitReady;\n return this.client;\n },\n destroy: (resource) => this.scrubSession({ resource }),\n });\n }\n\n createConnector(opts: { schema: Schema }): TRelationalConnector<Schema> {\n return drizzle({ client: this.client, schema: opts.schema }) as TRelationalConnector<Schema>;\n }\n\n async acquire(opts: { schema: Schema }): Promise<TRelationalConnection<Schema>> {\n let client: PGlite;\n\n // The bare pool error names only a timeout; on one session the cause is almost always an\n // unreleased transaction, so say so where the caller reads it.\n try {\n client = await this.slot.acquire();\n } catch (error) {\n throw getError({\n message: `[${PGliteDriver.name}][acquire] Could not borrow the single PGlite session | ${(error as Error)?.message ?? String(error)} | An unreleased transaction still holds it - commit/rollback it, or raise \\`acquireTimeoutMs\\``,\n });\n }\n\n let connector: TRelationalConnector<Schema>;\n try {\n connector = drizzle({ client, schema: opts.schema }) as TRelationalConnector<Schema>;\n } catch (error) {\n this.slot.release({ resource: client });\n throw error;\n }\n\n // Every borrower gets the SAME object, so a stale handle releasing twice would hand the\n // slot away underneath whoever holds it now. The latch makes the second release a no-op.\n let isReleased = false;\n\n return {\n connector,\n\n execute: async (executeOpts: { statement: string }) => {\n const result = await client.query(executeOpts.statement);\n return { count: result.affectedRows ?? 0 };\n },\n\n query: async <R>(queryOpts: { statement: string }) => {\n const result = await client.query<R>(queryOpts.statement);\n return result.rows ?? [];\n },\n\n release: (releaseOpts?: { destroy?: boolean }) => {\n if (isReleased) {\n return;\n }\n isReleased = true;\n\n if (releaseOpts?.destroy !== true) {\n this.slot.release({ resource: client });\n return;\n }\n\n // Discard cannot throw the session away - there is one and no replacement.\n // The slot is re-created from the same instance after the destroy hook\n // scrubs it, so the next waiter never inherits an unknown transaction.\n this.slot.discard({ resource: client }).catch((error) => {\n this.logger.for('release').error('Failed to discard the PGlite slot | Error: %s', error);\n });\n },\n };\n }\n\n getClient(): PGlite {\n return this.client;\n }\n\n async end(): Promise<void> {\n await this.slot.destroy();\n await this.client.close();\n this.clearWasmHostExitStatus();\n }\n\n /**\n * Clears the exit status PGlite planted on the host - see {@link WASM_HOST_EXIT_STATUS} - and\n * only while it still holds exactly that value, so an exit code the application set itself\n * survives untouched.\n *\n * `globalThis.process` is bound to a local and never member-accessed as `globalThis.process.x`:\n * this driver has to bundle clean for a browser target, where the property read yields\n * `undefined` and the optional chain short-circuits, while the member-access spelling is what the\n * purity gate treats as fatal.\n */\n private clearWasmHostExitStatus(): void {\n const host = globalThis.process;\n\n if (host?.exitCode !== PGliteDriver.WASM_HOST_EXIT_STATUS) {\n return;\n }\n\n host.exitCode = 0;\n this.logger\n .for(this.end.name)\n .debug(\n 'Cleared the exit status PGlite planted on the host process | status: %s',\n PGliteDriver.WASM_HOST_EXIT_STATUS,\n );\n }\n\n /**\n * The pool's destroy hook. A failed COMMIT/ROLLBACK may leave the session inside a transaction,\n * and the next borrower would inherit it. `ROLLBACK` outside a transaction is a no-op, so this is\n * safe whichever state the session is actually in.\n */\n private async scrubSession(opts: { resource: PGlite }): Promise<void> {\n const { resource } = opts;\n\n if (resource.closed) {\n return;\n }\n\n try {\n await resource.query('ROLLBACK');\n } catch (error) {\n this.logger\n .for(this.scrubSession.name)\n .warn('Failed to scrub the PGlite session | Error: %s', error);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pglite.js","sourceRoot":"","sources":["../../../../../src/relational/postgres/drivers/pglite.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAM7C;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IAavB;;;;OAIG;aACa,+BAA0B,GAAG,MAAM,CAAC;IAEpD;;;;;;;;OAQG;aACqB,0BAAqB,GAAG,EAAE,CAAC;IAEnD,YAAY,IAA0B;QACpC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEpE,6FAA6F;QAC7F,0FAA0F;QAC1F,MAAM,QAAQ,GACZ,OAAQ,MAAkB,EAAE,KAAK,KAAK,UAAU;YAChD,OAAQ,MAAkB,EAAE,IAAI,KAAK,UAAU;YAC/C,OAAQ,MAAkB,EAAE,KAAK,KAAK,UAAU,CAAC;QAEnD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,IAAI,YAAY,CAAC,IAAI,iLAAiL;aAChN,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,gFAAgF;QAChF,8EAA8E;QAC9E,2EAA2E;QAC3E,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,YAA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AAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;;;;OASG;IACK,uBAAuB;QAC7B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC;QAEhC,IAAI,IAAI,EAAE,QAAQ,KAAK,YAAY,CAAC,qBAAqB,EAAE,CAAC;YAC1D,OAAO;QACT,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;aAClB,KAAK,CACJ,yEAAyE,EACzE,YAAY,CAAC,qBAAqB,CACnC,CAAC;IACN,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,YAAY,CAAC,IAA0B;QACnD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;iBAC3B,IAAI,CAAC,gDAAgD,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC;IACH,CAAC","sourcesContent":["import type { TAnyDataSourceSchema } from '@venizia/ignis-kernel';\nimport type { TRelationalConnector } from '@/relational/postgres/datasources/common';\nimport type { PGlite } from '@electric-sql/pglite';\nimport type { ILogger, IPoolControlOptions } from '@venizia/ignis-helpers/core';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, BasePoolHelper, getError } from '@venizia/ignis-helpers/core';\nimport { drizzle } from 'drizzle-orm/pglite';\nimport type { TRelationalConnection, TRelationalDriver } from './driver';\n\n/** Pool knobs the driver forwards, minus `size`: one slot IS the mutual exclusion PGlite lacks. */\nexport type TPGliteDriverOptions = Omit<IPoolControlOptions, 'size'> & { client: PGlite };\n\n/**\n * Postgres compiled to WASM, in-process. Reports PostgreSQL 18.x, so the dialect works unchanged.\n *\n * One session only, and a second `BEGIN` neither nests nor errors - it joins the open transaction,\n * so the outer COMMIT commits the inner writer's rows. Hence the 1-slot pool behind `acquire()`.\n *\n * Consequence: a `createConnector()` write - the path all repositories take - runs INSIDE any open\n * transaction and dies with its ROLLBACK. Under concurrency, write through `acquire()`.\n */\nexport class PGliteDriver<\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n> implements TRelationalDriver<Schema, PGlite> {\n private readonly client: PGlite;\n\n /**\n * The pooled resource IS the single client, so `create()` always hands back the same instance.\n * The pool contributes the mutual exclusion PGlite lacks, not connection multiplicity.\n */\n private readonly slot: BasePoolHelper<PGlite>;\n\n private readonly logger: ILogger;\n\n /**\n * A leaked transaction never releases the one slot, so without a timeout every later `acquire()`\n * in the process hangs forever and silently. 30s outlasts any honest transaction on an in-process\n * database with no network in it, and turns a leak into a named error instead of a dead process.\n */\n static readonly DEFAULT_ACQUIRE_TIMEOUT_MS = 30_000;\n\n /**\n * PGlite's Emscripten runtime plants this status on the HOST process during ordinary operation -\n * measured on `@electric-sql/pglite` 0.5.5, `process.exitCode` is `undefined` before the first\n * query and 99 after it, and every later query re-arms it. A server that shuts down cleanly then\n * exits 99, which Docker, systemd and CI all read as a crash.\n *\n * Named rather than inlined so a future PGlite using a different status stops matching and makes\n * the problem visible again, instead of {@link end} silently forcing a zero it did not verify.\n */\n private static readonly WASM_HOST_EXIT_STATUS = 99;\n\n constructor(opts: TPGliteDriverOptions) {\n const { client, acquireTimeoutMs, maxWaitingClients, scope } = opts;\n\n // PGlite is not a connection pool: it has no connect()/totalCount, which is what a `pg.Pool`\n // leads with. Probing its own verbs names the mistake here instead of at the first query.\n const isPGlite =\n typeof (client as AnyType)?.query === 'function' &&\n typeof (client as AnyType)?.exec === 'function' &&\n typeof (client as AnyType)?.close === 'function';\n\n if (!isPGlite) {\n throw getError({\n message: `[${PGliteDriver.name}] Expected an \\`@electric-sql/pglite\\` PGlite | Got a client without exec()/close() - a \\`pg.Pool\\`? | Construct \\`new PGlite('./pgdata')\\`, or name NodePostgresDriver instead`,\n });\n }\n\n this.client = client;\n // `LoggerFactory` cannot be imported here: this is the browser driver, and that\n // import reaches `node:module`. `BaseHelper` resolves the same logger through\n // the swappable resolver without pulling in the node-only provider loader.\n this.logger = new BaseHelper({ scope: PGliteDriver.name }).getLogger();\n\n this.slot = new BasePoolHelper<PGlite>({\n size: 1,\n acquireTimeoutMs: acquireTimeoutMs ?? PGliteDriver.DEFAULT_ACQUIRE_TIMEOUT_MS,\n maxWaitingClients,\n scope: scope ?? PGliteDriver.name,\n create: async () => {\n await this.client.waitReady;\n return this.client;\n },\n destroy: (resource) => this.scrubSession({ resource }),\n });\n }\n\n createConnector(opts: { schema: Schema }): TRelationalConnector<Schema> {\n return drizzle({ client: this.client, schema: opts.schema }) as TRelationalConnector<Schema>;\n }\n\n async acquire(opts: { schema: Schema }): Promise<TRelationalConnection<Schema>> {\n let client: PGlite;\n\n // The bare pool error names only a timeout; on one session the cause is almost always an\n // unreleased transaction, so say so where the caller reads it.\n try {\n const result2 = await this.slot.acquire();\n client = result2;\n } catch (error) {\n throw getError({\n message: `[${PGliteDriver.name}][acquire] Could not borrow the single PGlite session | ${(error as Error)?.message ?? String(error)} | An unreleased transaction still holds it - commit/rollback it, or raise \\`acquireTimeoutMs\\``,\n });\n }\n\n let connector: TRelationalConnector<Schema>;\n try {\n connector = drizzle({ client, schema: opts.schema }) as TRelationalConnector<Schema>;\n } catch (error) {\n this.slot.release({ resource: client });\n throw error;\n }\n\n // Every borrower gets the SAME object, so a stale handle releasing twice would hand the\n // slot away underneath whoever holds it now. The latch makes the second release a no-op.\n let isReleased = false;\n\n return {\n connector,\n\n execute: async (executeOpts: { statement: string }) => {\n const result = await client.query(executeOpts.statement);\n return { count: result.affectedRows ?? 0 };\n },\n\n query: async <R>(queryOpts: { statement: string }) => {\n const result = await client.query<R>(queryOpts.statement);\n return result.rows ?? [];\n },\n\n release: (releaseOpts?: { destroy?: boolean }) => {\n if (isReleased) {\n return;\n }\n isReleased = true;\n\n if (releaseOpts?.destroy !== true) {\n this.slot.release({ resource: client });\n return;\n }\n\n // Discard cannot throw the session away - there is one and no replacement.\n // The slot is re-created from the same instance after the destroy hook\n // scrubs it, so the next waiter never inherits an unknown transaction.\n this.slot.discard({ resource: client }).catch((error) => {\n this.logger.for('release').error('Failed to discard the PGlite slot | Error: %s', error);\n });\n },\n };\n }\n\n getClient(): PGlite {\n return this.client;\n }\n\n async end(): Promise<void> {\n await this.slot.destroy();\n await this.client.close();\n this.clearWasmHostExitStatus();\n }\n\n /**\n * Clears the exit status PGlite planted on the host - see {@link WASM_HOST_EXIT_STATUS} - and\n * only while it still holds exactly that value, so an exit code the application set itself\n * survives untouched.\n *\n * `globalThis.process` is bound to a local and never member-accessed as `globalThis.process.x`:\n * this driver has to bundle clean for a browser target, where the property read yields\n * `undefined` and the optional chain short-circuits, while the member-access spelling is what the\n * purity gate treats as fatal.\n */\n private clearWasmHostExitStatus(): void {\n const host = globalThis.process;\n\n if (host?.exitCode !== PGliteDriver.WASM_HOST_EXIT_STATUS) {\n return;\n }\n\n host.exitCode = 0;\n this.logger\n .for(this.end.name)\n .debug(\n 'Cleared the exit status PGlite planted on the host process | status: %s',\n PGliteDriver.WASM_HOST_EXIT_STATUS,\n );\n }\n\n /**\n * The pool's destroy hook. A failed COMMIT/ROLLBACK may leave the session inside a transaction,\n * and the next borrower would inherit it. `ROLLBACK` outside a transaction is a no-op, so this is\n * safe whichever state the session is actually in.\n */\n private async scrubSession(opts: { resource: PGlite }): Promise<void> {\n const { resource } = opts;\n\n if (resource.closed) {\n return;\n }\n\n try {\n await resource.query('ROLLBACK');\n } catch (error) {\n this.logger\n .for(this.scrubSession.name)\n .warn('Failed to scrub the PGlite session | Error: %s', error);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../../../src/relational/postgres/repositories/executor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACb,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,KAAK,EAAW,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAIxE;;;;;;GAMG;AACH,qBAAa,qBAAsB,YAAW,wBAAwB,CAAC,oBAAoB,CAAC;IACpF,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAqCxE,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjE,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,uBAAuB,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAQnF,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,uBAAuB,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAYxF,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;
|
|
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G;IACH,OAAO,CAAC,iBAAiB;IAqBzB;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;CA6C7B"}
|
|
@@ -62,7 +62,8 @@ export class PostgresQueryExecutor {
|
|
|
62
62
|
const result = await query;
|
|
63
63
|
return { count: this.readAffectedRowCount({ result }), rows: [] };
|
|
64
64
|
}
|
|
65
|
-
const
|
|
65
|
+
const pending = returning ? query.returning(returning) : query.returning();
|
|
66
|
+
const rows = await pending;
|
|
66
67
|
return { count: rows.length, rows: rows };
|
|
67
68
|
}
|
|
68
69
|
async update(opts) {
|
|
@@ -75,7 +76,8 @@ export class PostgresQueryExecutor {
|
|
|
75
76
|
const result = await query;
|
|
76
77
|
return { count: this.readAffectedRowCount({ result }), rows: [] };
|
|
77
78
|
}
|
|
78
|
-
const
|
|
79
|
+
const pending = returning ? query.returning(returning) : query.returning();
|
|
80
|
+
const rows = await pending;
|
|
79
81
|
return { count: rows.length, rows: rows };
|
|
80
82
|
}
|
|
81
83
|
async remove(opts) {
|
|
@@ -85,7 +87,8 @@ export class PostgresQueryExecutor {
|
|
|
85
87
|
const result = await query;
|
|
86
88
|
return { count: this.readAffectedRowCount({ result }), rows: [] };
|
|
87
89
|
}
|
|
88
|
-
const
|
|
90
|
+
const pending = returning ? query.returning(returning) : query.returning();
|
|
91
|
+
const rows = await pending;
|
|
89
92
|
return { count: rows.length, rows: rows };
|
|
90
93
|
}
|
|
91
94
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../src/relational/postgres/repositories/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAarD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD;;;;;;GAMG;AACH,MAAM,OAAO,qBAAqB;IAChC,KAAK,CAAC,MAAM,CAAI,IAA0C;QACxD,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,K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OAAO,MAAM,EAAE;aACxJ,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAIzC,CAAC;QAEF,mDAAmD;QACnD,gDAAgD;QAChD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,eAAe;QACf,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,4DAA4D;QAC5D,wDAAwD;QACxD,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,yJAAyJ,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;SACnM,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { omit } from '@venizia/ignis-helpers/common';\nimport type {\n ICountOptions,\n IInsertOptions,\n IRelationalQueryExecutor,\n IRelationalQueryOptions,\n IRemoveOptions,\n ISelectOptions,\n IUpdateOptions,\n IWriteResult,\n} from '@/relational/core/repositories/common';\nimport type { TRelationalConnector } from '@/relational/postgres/datasources';\nimport type { AnyType, TNullable } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { PgTable } from 'drizzle-orm/pg-core';\n\n/**\n * Translates already-built SQL fragments (`where`, `orderBy`, projections) to Drizzle Core calls.\n * Filter-to-SQL compilation is dialect work and stays in the repository tier.\n *\n * The `rows as Array<R>` every write verb ends in is convention, not proof: Drizzle infers\n * `returning()`'s row type from the table schema, not from the caller-chosen R.\n */\nexport class PostgresQueryExecutor implements IRelationalQueryExecutor<TRelationalConnector> {\n async select<R>(opts: ISelectOptions<TRelationalConnector>): Promise<Array<R>> {\n const { connector, table, columns, where, orderBy, limit, offset, lock } = opts;\n\n // Drizzle's `.from()` needs the concrete `PgTable` type, not the generic bound.\n const pgTable = table as PgTable;\n\n let query = columns\n ? connector\n .select(columns as AnyType)\n .from(pgTable)\n .$dynamic()\n : connector.select().from(pgTable).$dynamic();\n\n if (where) {\n query = query.where(where);\n }\n\n if (orderBy && orderBy.length > 0) {\n query = query.orderBy(...orderBy);\n }\n\n if (limit !== undefined) {\n query = query.limit(limit);\n }\n\n if (offset !== undefined) {\n query = query.offset(offset);\n }\n\n // `$dynamic()` infers its row type from the table schema, not from the caller-chosen R.\n if (lock) {\n return query.for(lock.strength, lock.config) as Promise<Array<R>>;\n }\n\n return query as Promise<Array<R>>;\n }\n\n async count(opts: ICountOptions<TRelationalConnector>): Promise<number> {\n const { connector, table, where } = opts;\n return connector.$count(table as PgTable, where);\n }\n\n async findMany<R>(opts: IRelationalQueryOptions<TRelationalConnector>): Promise<Array<R>> {\n const queryInterface = this.getQueryInterface(opts);\n\n // Drizzle's relational result (`PgRelationalQuery<{[x: string]: any}[]>`) does not overlap the\n // caller-chosen R enough for a direct assertion.\n return queryInterface.findMany(opts.query) as AnyType;\n }\n\n async findFirst<R>(opts: IRelationalQueryOptions<TRelationalConnector>): Promise<TNullable<R>> {\n const queryInterface = this.getQueryInterface(opts);\n\n // Drizzle's `findFirst` config type structurally forbids `limit` - it always fetches one row.\n // This is the only place that knows that, so the strip happens here whatever the caller passed.\n const queryOptions = omit({ source: opts.query, keys: ['limit'] });\n const result = await queryInterface.findFirst(queryOptions);\n\n // Same drizzle-relational-query-versus-caller-generic boundary as `findMany` above.\n return (result ?? null) as TNullable<R>;\n }\n\n async insert<R>(opts: IInsertOptions<TRelationalConnector>): Promise<IWriteResult<R>> {\n const { connector, table, values, returning, shouldReturn } = opts;\n const query = connector.insert(table as PgTable).values(values as AnyType);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const rows = returning ? await query.returning(returning as AnyType) : await query.returning();\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n async update<R>(opts: IUpdateOptions<TRelationalConnector>): Promise<IWriteResult<R>> {\n const { connector, table, data, where, returning, shouldReturn } = opts;\n const query = connector\n .update(table as PgTable)\n .set(data as AnyType)\n .where(where);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const rows = returning ? await query.returning(returning as AnyType) : await query.returning();\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n async remove<R>(opts: IRemoveOptions<TRelationalConnector>): Promise<IWriteResult<R>> {\n const { connector, table, where, returning, shouldReturn } = opts;\n const query = connector.delete(table as PgTable).where(where);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const rows = returning ? await query.returning(returning as AnyType) : await query.returning();\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n /**\n * Gets the Drizzle relational-query interface, validating schema registration. The error wording\n * names the entity and lists the available keys, and a test asserts it word for word.\n */\n private getQueryInterface(opts: IRelationalQueryOptions<TRelationalConnector>) {\n const { connector, entityName } = opts;\n const scope = opts.scope ?? this.constructor.name;\n\n if (!connector.query) {\n throw getError({\n message: `[${scope}] Connector query interface not available | Ensure datasource is properly configured with schema`,\n });\n }\n\n const queryInterface = connector.query[entityName];\n if (!queryInterface) {\n const availableKeys = Object.keys(connector.query);\n throw getError({\n message: `[${scope}] Schema key mismatch | Entity name '${entityName}' not found in connector.query | Available keys: [${availableKeys.join(', ')}] | Ensure the model's TABLE_NAME matches the schema registration key`,\n });\n }\n\n return queryInterface;\n }\n\n /**\n * Rows affected by a write executed without RETURNING. Reads `pg`'s `rowCount`, postgres-js's\n * `count` or PGlite's `affectedRows` off the raw driver result - engine knowledge the shared\n * repository tier must not hold.\n */\n private readAffectedRowCount(opts: { result: unknown }): number {\n const { result } = opts;\n\n // Drizzle resolves some statements to nothing at all; that counts as zero rows.\n if (result === null || result === undefined) {\n return 0;\n }\n\n if (typeof result !== 'object') {\n throw getError({\n message: `[readAffectedRowCount] Unrecognized driver result | expected pg.QueryResult, postgres-js RowList or a PGlite Results | got: ${typeof result}`,\n });\n }\n\n const { rowCount, count, affectedRows } = result as {\n rowCount?: unknown;\n count?: unknown;\n affectedRows?: unknown;\n };\n\n // node-postgres. `rowCount` is null for statements\n // that affect no rows by definition (e.g. DDL).\n if (typeof rowCount === 'number') {\n return rowCount;\n }\n\n if (rowCount === null) {\n return 0;\n }\n\n // postgres-js.\n if (typeof count === 'number') {\n return count;\n }\n\n // PGlite - it carries no `rowCount` at all, so without this\n // branch every write with `shouldReturn: false` throws.\n if (typeof affectedRows === 'number') {\n return affectedRows;\n }\n\n throw getError({\n message: `[readAffectedRowCount] Unrecognized driver result | expected 'rowCount' (node-postgres), 'count' (postgres-js) or 'affectedRows' (PGlite) | got keys: ${Object.keys(result).join(', ')}`,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../src/relational/postgres/repositories/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAarD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD;;;;;;GAMG;AACH,MAAM,OAAO,qBAAqB;IAChC,KAAK,CAAC,MAAM,CAAI,IAA0C;QACxD,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAEhF,gFAAgF;QAChF,MAAM,OAAO,GAAG,KAAgB,CAAC;QAEjC,IAAI,KAAK,GAAG,OAAO;YACjB,CAAC,CAAC,SAAS;iBACN,MAAM,CAAC,OAAkB,CAAC;iBAC1B,IAAI,CAAC,OAAO,CAAC;iBACb,QAAQ,EAAE;YACf,CAAC,CAAC,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CAAC;YACjC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,eAAe;QACf,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,4DAA4D;QAC5D,wDAAwD;QACxD,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,yJAAyJ,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;SACnM,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { omit } from '@venizia/ignis-helpers/common';\nimport type {\n ICountOptions,\n IInsertOptions,\n IRelationalQueryExecutor,\n IRelationalQueryOptions,\n IRemoveOptions,\n ISelectOptions,\n IUpdateOptions,\n IWriteResult,\n} from '@/relational/core/repositories/common';\nimport type { TRelationalConnector } from '@/relational/postgres/datasources';\nimport type { AnyType, TNullable } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { PgTable } from 'drizzle-orm/pg-core';\n\n/**\n * Translates already-built SQL fragments (`where`, `orderBy`, projections) to Drizzle Core calls.\n * Filter-to-SQL compilation is dialect work and stays in the repository tier.\n *\n * The `rows as Array<R>` every write verb ends in is convention, not proof: Drizzle infers\n * `returning()`'s row type from the table schema, not from the caller-chosen R.\n */\nexport class PostgresQueryExecutor implements IRelationalQueryExecutor<TRelationalConnector> {\n async select<R>(opts: ISelectOptions<TRelationalConnector>): Promise<Array<R>> {\n const { connector, table, columns, where, orderBy, limit, offset, lock } = opts;\n\n // Drizzle's `.from()` needs the concrete `PgTable` type, not the generic bound.\n const pgTable = table as PgTable;\n\n let query = columns\n ? connector\n .select(columns as AnyType)\n .from(pgTable)\n .$dynamic()\n : connector.select().from(pgTable).$dynamic();\n\n if (where) {\n query = query.where(where);\n }\n\n if (orderBy && orderBy.length > 0) {\n query = query.orderBy(...orderBy);\n }\n\n if (limit !== undefined) {\n query = query.limit(limit);\n }\n\n if (offset !== undefined) {\n query = query.offset(offset);\n }\n\n // `$dynamic()` infers its row type from the table schema, not from the caller-chosen R.\n if (lock) {\n return query.for(lock.strength, lock.config) as Promise<Array<R>>;\n }\n\n return query as Promise<Array<R>>;\n }\n\n async count(opts: ICountOptions<TRelationalConnector>): Promise<number> {\n const { connector, table, where } = opts;\n return connector.$count(table as PgTable, where);\n }\n\n async findMany<R>(opts: IRelationalQueryOptions<TRelationalConnector>): Promise<Array<R>> {\n const queryInterface = this.getQueryInterface(opts);\n\n // Drizzle's relational result (`PgRelationalQuery<{[x: string]: any}[]>`) does not overlap the\n // caller-chosen R enough for a direct assertion.\n return queryInterface.findMany(opts.query) as AnyType;\n }\n\n async findFirst<R>(opts: IRelationalQueryOptions<TRelationalConnector>): Promise<TNullable<R>> {\n const queryInterface = this.getQueryInterface(opts);\n\n // Drizzle's `findFirst` config type structurally forbids `limit` - it always fetches one row.\n // This is the only place that knows that, so the strip happens here whatever the caller passed.\n const queryOptions = omit({ source: opts.query, keys: ['limit'] });\n const result = await queryInterface.findFirst(queryOptions);\n\n // Same drizzle-relational-query-versus-caller-generic boundary as `findMany` above.\n return (result ?? null) as TNullable<R>;\n }\n\n async insert<R>(opts: IInsertOptions<TRelationalConnector>): Promise<IWriteResult<R>> {\n const { connector, table, values, returning, shouldReturn } = opts;\n const query = connector.insert(table as PgTable).values(values as AnyType);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const pending = returning ? query.returning(returning as AnyType) : query.returning();\n const rows = await pending;\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n async update<R>(opts: IUpdateOptions<TRelationalConnector>): Promise<IWriteResult<R>> {\n const { connector, table, data, where, returning, shouldReturn } = opts;\n const query = connector\n .update(table as PgTable)\n .set(data as AnyType)\n .where(where);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const pending = returning ? query.returning(returning as AnyType) : query.returning();\n const rows = await pending;\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n async remove<R>(opts: IRemoveOptions<TRelationalConnector>): Promise<IWriteResult<R>> {\n const { connector, table, where, returning, shouldReturn } = opts;\n const query = connector.delete(table as PgTable).where(where);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const pending = returning ? query.returning(returning as AnyType) : query.returning();\n const rows = await pending;\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n /**\n * Gets the Drizzle relational-query interface, validating schema registration. The error wording\n * names the entity and lists the available keys, and a test asserts it word for word.\n */\n private getQueryInterface(opts: IRelationalQueryOptions<TRelationalConnector>) {\n const { connector, entityName } = opts;\n const scope = opts.scope ?? this.constructor.name;\n\n if (!connector.query) {\n throw getError({\n message: `[${scope}] Connector query interface not available | Ensure datasource is properly configured with schema`,\n });\n }\n\n const queryInterface = connector.query[entityName];\n if (!queryInterface) {\n const availableKeys = Object.keys(connector.query);\n throw getError({\n message: `[${scope}] Schema key mismatch | Entity name '${entityName}' not found in connector.query | Available keys: [${availableKeys.join(', ')}] | Ensure the model's TABLE_NAME matches the schema registration key`,\n });\n }\n\n return queryInterface;\n }\n\n /**\n * Rows affected by a write executed without RETURNING. Reads `pg`'s `rowCount`, postgres-js's\n * `count` or PGlite's `affectedRows` off the raw driver result - engine knowledge the shared\n * repository tier must not hold.\n */\n private readAffectedRowCount(opts: { result: unknown }): number {\n const { result } = opts;\n\n // Drizzle resolves some statements to nothing at all; that counts as zero rows.\n if (result === null || result === undefined) {\n return 0;\n }\n\n if (typeof result !== 'object') {\n throw getError({\n message: `[readAffectedRowCount] Unrecognized driver result | expected pg.QueryResult, postgres-js RowList or a PGlite Results | got: ${typeof result}`,\n });\n }\n\n const { rowCount, count, affectedRows } = result as {\n rowCount?: unknown;\n count?: unknown;\n affectedRows?: unknown;\n };\n\n // node-postgres. `rowCount` is null for statements\n // that affect no rows by definition (e.g. DDL).\n if (typeof rowCount === 'number') {\n return rowCount;\n }\n\n if (rowCount === null) {\n return 0;\n }\n\n // postgres-js.\n if (typeof count === 'number') {\n return count;\n }\n\n // PGlite - it carries no `rowCount` at all, so without this\n // branch every write with `shouldReturn: false` throws.\n if (typeof affectedRows === 'number') {\n return affectedRows;\n }\n\n throw getError({\n message: `[readAffectedRowCount] Unrecognized driver result | expected 'rowCount' (node-postgres), 'count' (postgres-js) or 'affectedRows' (PGlite) | got keys: ${Object.keys(result).join(', ')}`,\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libsql.d.ts","sourceRoot":"","sources":["../../../../../src/relational/sqlite/drivers/libsql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAW,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAIhF,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAcnF;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1F;;;;;;;;;;GAUG;AACH,qBAAa,YAAY,CACvB,MAAM,SAAS,oBAAoB,GAAG,oBAAoB,CAC1D,YAAW,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyB;IAE9C,OAAO,CAAC,QAAQ,CAAC,M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M,CAAA;KAAE,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAI7D,OAAO,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAsE3E,SAAS,IAAI,MAAM;IAIb,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAK1B;;;;OAIG;YACW,YAAY;CAsB3B"}
|
|
@@ -72,7 +72,8 @@ export class LibSqlDriver {
|
|
|
72
72
|
// The bare pool error names only a timeout; on one connection the cause is almost always an
|
|
73
73
|
// unreleased transaction, so say so where the caller reads it.
|
|
74
74
|
try {
|
|
75
|
-
|
|
75
|
+
const result2 = await this.slot.acquire();
|
|
76
|
+
client = result2;
|
|
76
77
|
}
|
|
77
78
|
catch (error) {
|
|
78
79
|
throw getError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libsql.js","sourceRoot":"","sources":["../../../../../src/relational/sqlite/drivers/libsql.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI1D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C;;;GAGG;AACH,MAAM,aAAa,GAAG,MAAM,CAAC;AAE7B;;;GAGG;AACH,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAQzD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YAAY;IAavB;;;;OAIG;aACa,+BAA0B,GAAG,MAAM,CAAC;IAEpD,YAAY,IAA0B;QACpC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEpE,oFAAoF;QACpF,iFAAiF;QACjF,MAAM,cAAc,GAClB,OAAQ,MAAkB,EAAE,OAAO,KAAK,UAAU;YAClD,OAA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CAAC,CAAC;YAEvE,IAAI,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;gBAC5C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;gBAChF,OAAO;YACT,CAAC;YAED,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;iBAC3B,IAAI,CAAC,gDAAgD,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC;IACH,CAAC","sourcesContent":["import type { TAnyDataSourceSchema } from '@venizia/ignis-kernel';\nimport { throwNotSupported } from '@venizia/ignis-kernel';\nimport type { Client } from '@libsql/client';\nimport type { ILogger, IPoolControlOptions } from '@venizia/ignis-helpers/core';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, BasePoolHelper, getError } from '@venizia/ignis-helpers/core';\nimport { drizzle } from 'drizzle-orm/libsql';\nimport type { TSqliteConnection, TSqliteConnector, TSqliteDriver } from './driver';\n\n/**\n * libsql's own name for a local database file, the\n * only protocol whose statements share a connection.\n */\nconst FILE_PROTOCOL = 'file';\n\n/**\n * SQLite rejects ROLLBACK outside a transaction rather\n * than treating it as a no-op the way Postgres does.\n */\nconst NO_ACTIVE_TRANSACTION = 'no transaction is active';\n\n/**\n * Pool knobs the driver forwards, minus `size`: one slot\n * IS the mutual exclusion a single connection lacks.\n */\nexport type TLibSqlDriverOptions = Omit<IPoolControlOptions, 'size'> & { client: Client };\n\n/**\n * Covers `:memory:`, a local file, remote Turso and embedded replicas. Chosen over `better-sqlite3`\n * and `bun:sqlite` for its async result kind - those block the event loop.\n *\n * `acquire()` takes a 1-slot pool, not a second connection: `drizzle()` binds to a `Client`, never\n * to libsql's `Transaction`, and `client.transaction()` swaps the connection out - against\n * `:memory:` that is a DIFFERENT empty database.\n *\n * Consequence: a query on the `createConnector()` connector while a transaction is open runs INSIDE\n * it. Route work that must stay outside one through `acquire()`.\n */\nexport class LibSqlDriver<\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n> implements TSqliteDriver<Schema, Client> {\n private readonly client: Client;\n\n /**\n * The pooled resource IS the single client, so `create()` always hands back the same instance.\n * The pool contributes mutual exclusion, not connection multiplicity.\n */\n private readonly slot: BasePoolHelper<Client>;\n\n private readonly logger: ILogger;\n\n /**\n * A leaked transaction never releases the one slot, so without a timeout every later `acquire()`\n * in the process hangs forever and silently. 30s outlasts any honest SQLite write transaction -\n * one writer at a time is the engine's own limit - and turns a leak into a named error.\n */\n static readonly DEFAULT_ACQUIRE_TIMEOUT_MS = 30_000;\n\n constructor(opts: TLibSqlDriverOptions) {\n const { client, acquireTimeoutMs, maxWaitingClients, scope } = opts;\n\n // A `bun:sqlite` / better-sqlite3 Database leads with prepare()/exec() and has none\n // of these, so the wrong driver class fails here rather than at the first query.\n const isLibSqlClient =\n typeof (client as AnyType)?.execute === 'function' &&\n typeof (client as AnyType)?.batch === 'function' &&\n typeof (client as AnyType)?.transaction === 'function' &&\n typeof (client as AnyType)?.protocol === 'string';\n\n if (!isLibSqlClient) {\n throw getError({\n message: `[${LibSqlDriver.name}] Expected an \\`@libsql/client\\` Client | Got a client without execute()/batch()/transaction() - a \\`bun:sqlite\\` Database? | Construct \\`createClient({ url: 'file:./data.db' })\\``,\n });\n }\n\n this.client = client;\n // Not `LoggerFactory`: it reaches the helpers root barrel, which pulls `ioredis` and fails a\n // browser bundle on `tls`.\n this.logger = new BaseHelper({ scope: LibSqlDriver.name }).getLogger();\n\n this.slot = new BasePoolHelper<Client>({\n size: 1,\n acquireTimeoutMs: acquireTimeoutMs ?? LibSqlDriver.DEFAULT_ACQUIRE_TIMEOUT_MS,\n maxWaitingClients,\n scope: scope ?? LibSqlDriver.name,\n create: () => this.client,\n destroy: (resource) => this.scrubSession({ resource }),\n });\n }\n\n createConnector(opts: { schema: Schema }): TSqliteConnector<Schema> {\n return drizzle({ client: this.client, schema: opts.schema });\n }\n\n async acquire(opts: { schema: Schema }): Promise<TSqliteConnection<Schema>> {\n // A remote client opens a stream per statement and closes it, so BEGIN would neither hold nor\n // error - the transaction would silently not exist.\n if (this.client.protocol !== FILE_PROTOCOL) {\n throwNotSupported({\n scope: LibSqlDriver.name,\n feature: `Explicit transactions over a '${this.client.protocol}' libsql client - every statement runs on its own connection, so BEGIN cannot hold; use a \\`file:\\` or \\`:memory:\\` url, or an embedded replica`,\n logger: this.logger,\n });\n }\n\n let client: Client;\n\n // The bare pool error names only a timeout; on one connection the cause is almost always an\n // unreleased transaction, so say so where the caller reads it.\n try {\n client = await this.slot.acquire();\n } catch (error) {\n throw getError({\n message: `[${LibSqlDriver.name}][acquire] Could not borrow the single libsql connection | ${(error as Error)?.message ?? String(error)} | An unreleased transaction still holds it - commit/rollback it, or raise \\`acquireTimeoutMs\\``,\n });\n }\n\n let connector: TSqliteConnector<Schema>;\n try {\n connector = drizzle({ client, schema: opts.schema });\n } catch (error) {\n this.slot.release({ resource: client });\n throw error;\n }\n\n // Every borrower gets the SAME object, so a stale handle releasing twice would hand the\n // slot away underneath whoever holds it now. The latch makes the second release a no-op.\n let isReleased = false;\n\n return {\n connector,\n\n execute: async (executeOpts: { statement: string }) => {\n const result = await client.execute(executeOpts.statement);\n return { count: result.rowsAffected ?? 0 };\n },\n\n query: async <R>(queryOpts: { statement: string }) => {\n const result = await client.execute(queryOpts.statement);\n return (result.rows ?? []) as Array<R>;\n },\n\n release: (releaseOpts?: { destroy?: boolean }) => {\n if (isReleased) {\n return;\n }\n isReleased = true;\n\n if (releaseOpts?.destroy !== true) {\n this.slot.release({ resource: client });\n return;\n }\n\n // Discard cannot throw the connection away - there is one client and no\n // replacement. The slot is re-created from the same instance after the destroy\n // hook scrubs it, so the next waiter never inherits an unknown transaction.\n this.slot.discard({ resource: client }).catch((error) => {\n this.logger.for('release').error('Failed to discard the libsql slot | Error: %s', error);\n });\n },\n };\n }\n\n getClient(): Client {\n return this.client;\n }\n\n async end(): Promise<void> {\n await this.slot.destroy();\n this.client.close();\n }\n\n /**\n * The pool's destroy hook. A failed COMMIT/ROLLBACK may leave the connection inside a transaction\n * and the next borrower would inherit it. The client offers no way to ask whether one is open, so\n * the ROLLBACK is issued blind and its rejection is the ordinary answer of a clean connection.\n */\n private async scrubSession(opts: { resource: Client }): Promise<void> {\n const { resource } = opts;\n\n if (resource.closed) {\n return;\n }\n\n try {\n await resource.execute('ROLLBACK');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n\n if (message.includes(NO_ACTIVE_TRANSACTION)) {\n this.logger.for(this.scrubSession.name).debug('Nothing to scrub | %s', message);\n return;\n }\n\n this.logger\n .for(this.scrubSession.name)\n .warn('Failed to scrub the libsql session | Error: %s', error);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"libsql.js","sourceRoot":"","sources":["../../../../../src/relational/sqlite/drivers/libsql.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI1D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C;;;GAGG;AACH,MAAM,aAAa,GAAG,MAAM,CAAC;AAE7B;;;GAGG;AACH,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAQzD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YAAY;IAavB;;;;OAIG;aACa,+BAA0B,GAAG,MAAM,CAAC;IAEpD,YAAY,IAA0B;QACpC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEpE,oFAAoF;QACpF,iFAAiF;QACjF,MAAM,cAAc,GAClB,OAAQ,MAAkB,EAAE,OAAO,KAAK,UAAU;YAClD,OAAQ,MAAkB,EAAE,KAAK,KAAK,UAAU;YAChD,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C,CAAC;YAEvE,IAAI,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;gBAC5C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;gBAChF,OAAO;YACT,CAAC;YAED,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;iBAC3B,IAAI,CAAC,gDAAgD,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC;IACH,CAAC","sourcesContent":["import type { TAnyDataSourceSchema } from '@venizia/ignis-kernel';\nimport { throwNotSupported } from '@venizia/ignis-kernel';\nimport type { Client } from '@libsql/client';\nimport type { ILogger, IPoolControlOptions } from '@venizia/ignis-helpers/core';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, BasePoolHelper, getError } from '@venizia/ignis-helpers/core';\nimport { drizzle } from 'drizzle-orm/libsql';\nimport type { TSqliteConnection, TSqliteConnector, TSqliteDriver } from './driver';\n\n/**\n * libsql's own name for a local database file, the\n * only protocol whose statements share a connection.\n */\nconst FILE_PROTOCOL = 'file';\n\n/**\n * SQLite rejects ROLLBACK outside a transaction rather\n * than treating it as a no-op the way Postgres does.\n */\nconst NO_ACTIVE_TRANSACTION = 'no transaction is active';\n\n/**\n * Pool knobs the driver forwards, minus `size`: one slot\n * IS the mutual exclusion a single connection lacks.\n */\nexport type TLibSqlDriverOptions = Omit<IPoolControlOptions, 'size'> & { client: Client };\n\n/**\n * Covers `:memory:`, a local file, remote Turso and embedded replicas. Chosen over `better-sqlite3`\n * and `bun:sqlite` for its async result kind - those block the event loop.\n *\n * `acquire()` takes a 1-slot pool, not a second connection: `drizzle()` binds to a `Client`, never\n * to libsql's `Transaction`, and `client.transaction()` swaps the connection out - against\n * `:memory:` that is a DIFFERENT empty database.\n *\n * Consequence: a query on the `createConnector()` connector while a transaction is open runs INSIDE\n * it. Route work that must stay outside one through `acquire()`.\n */\nexport class LibSqlDriver<\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n> implements TSqliteDriver<Schema, Client> {\n private readonly client: Client;\n\n /**\n * The pooled resource IS the single client, so `create()` always hands back the same instance.\n * The pool contributes mutual exclusion, not connection multiplicity.\n */\n private readonly slot: BasePoolHelper<Client>;\n\n private readonly logger: ILogger;\n\n /**\n * A leaked transaction never releases the one slot, so without a timeout every later `acquire()`\n * in the process hangs forever and silently. 30s outlasts any honest SQLite write transaction -\n * one writer at a time is the engine's own limit - and turns a leak into a named error.\n */\n static readonly DEFAULT_ACQUIRE_TIMEOUT_MS = 30_000;\n\n constructor(opts: TLibSqlDriverOptions) {\n const { client, acquireTimeoutMs, maxWaitingClients, scope } = opts;\n\n // A `bun:sqlite` / better-sqlite3 Database leads with prepare()/exec() and has none\n // of these, so the wrong driver class fails here rather than at the first query.\n const isLibSqlClient =\n typeof (client as AnyType)?.execute === 'function' &&\n typeof (client as AnyType)?.batch === 'function' &&\n typeof (client as AnyType)?.transaction === 'function' &&\n typeof (client as AnyType)?.protocol === 'string';\n\n if (!isLibSqlClient) {\n throw getError({\n message: `[${LibSqlDriver.name}] Expected an \\`@libsql/client\\` Client | Got a client without execute()/batch()/transaction() - a \\`bun:sqlite\\` Database? | Construct \\`createClient({ url: 'file:./data.db' })\\``,\n });\n }\n\n this.client = client;\n // Not `LoggerFactory`: it reaches the helpers root barrel, which pulls `ioredis` and fails a\n // browser bundle on `tls`.\n this.logger = new BaseHelper({ scope: LibSqlDriver.name }).getLogger();\n\n this.slot = new BasePoolHelper<Client>({\n size: 1,\n acquireTimeoutMs: acquireTimeoutMs ?? LibSqlDriver.DEFAULT_ACQUIRE_TIMEOUT_MS,\n maxWaitingClients,\n scope: scope ?? LibSqlDriver.name,\n create: () => this.client,\n destroy: (resource) => this.scrubSession({ resource }),\n });\n }\n\n createConnector(opts: { schema: Schema }): TSqliteConnector<Schema> {\n return drizzle({ client: this.client, schema: opts.schema });\n }\n\n async acquire(opts: { schema: Schema }): Promise<TSqliteConnection<Schema>> {\n // A remote client opens a stream per statement and closes it, so BEGIN would neither hold nor\n // error - the transaction would silently not exist.\n if (this.client.protocol !== FILE_PROTOCOL) {\n throwNotSupported({\n scope: LibSqlDriver.name,\n feature: `Explicit transactions over a '${this.client.protocol}' libsql client - every statement runs on its own connection, so BEGIN cannot hold; use a \\`file:\\` or \\`:memory:\\` url, or an embedded replica`,\n logger: this.logger,\n });\n }\n\n let client: Client;\n\n // The bare pool error names only a timeout; on one connection the cause is almost always an\n // unreleased transaction, so say so where the caller reads it.\n try {\n const result2 = await this.slot.acquire();\n client = result2;\n } catch (error) {\n throw getError({\n message: `[${LibSqlDriver.name}][acquire] Could not borrow the single libsql connection | ${(error as Error)?.message ?? String(error)} | An unreleased transaction still holds it - commit/rollback it, or raise \\`acquireTimeoutMs\\``,\n });\n }\n\n let connector: TSqliteConnector<Schema>;\n try {\n connector = drizzle({ client, schema: opts.schema });\n } catch (error) {\n this.slot.release({ resource: client });\n throw error;\n }\n\n // Every borrower gets the SAME object, so a stale handle releasing twice would hand the\n // slot away underneath whoever holds it now. The latch makes the second release a no-op.\n let isReleased = false;\n\n return {\n connector,\n\n execute: async (executeOpts: { statement: string }) => {\n const result = await client.execute(executeOpts.statement);\n return { count: result.rowsAffected ?? 0 };\n },\n\n query: async <R>(queryOpts: { statement: string }) => {\n const result = await client.execute(queryOpts.statement);\n return (result.rows ?? []) as Array<R>;\n },\n\n release: (releaseOpts?: { destroy?: boolean }) => {\n if (isReleased) {\n return;\n }\n isReleased = true;\n\n if (releaseOpts?.destroy !== true) {\n this.slot.release({ resource: client });\n return;\n }\n\n // Discard cannot throw the connection away - there is one client and no\n // replacement. The slot is re-created from the same instance after the destroy\n // hook scrubs it, so the next waiter never inherits an unknown transaction.\n this.slot.discard({ resource: client }).catch((error) => {\n this.logger.for('release').error('Failed to discard the libsql slot | Error: %s', error);\n });\n },\n };\n }\n\n getClient(): Client {\n return this.client;\n }\n\n async end(): Promise<void> {\n await this.slot.destroy();\n this.client.close();\n }\n\n /**\n * The pool's destroy hook. A failed COMMIT/ROLLBACK may leave the connection inside a transaction\n * and the next borrower would inherit it. The client offers no way to ask whether one is open, so\n * the ROLLBACK is issued blind and its rejection is the ordinary answer of a clean connection.\n */\n private async scrubSession(opts: { resource: Client }): Promise<void> {\n const { resource } = opts;\n\n if (resource.closed) {\n return;\n }\n\n try {\n await resource.execute('ROLLBACK');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n\n if (message.includes(NO_ACTIVE_TRANSACTION)) {\n this.logger.for(this.scrubSession.name).debug('Nothing to scrub | %s', message);\n return;\n }\n\n this.logger\n .for(this.scrubSession.name)\n .warn('Failed to scrub the libsql session | Error: %s', error);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../../../src/relational/sqlite/repositories/executor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACb,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGpE,OAAO,KAAK,EAAW,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAIxE;;;;;;GAMG;AACH,qBAAa,mBAAoB,YAAW,wBAAwB,CAAC,gBAAgB,CAAC;IACpF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;;IAQ3B,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IA0CpE,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAK7D,QAAQ,CAA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,SAAS,CAAC,CAAC,CAAC,CAAC;IAYpF,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAc3E,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAiB3E,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAcjF;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAIf;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAqBzB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;CAwB7B"}
|
|
@@ -73,7 +73,8 @@ export class SqliteQueryExecutor {
|
|
|
73
73
|
const result = await query;
|
|
74
74
|
return { count: this.readAffectedRowCount({ result }), rows: [] };
|
|
75
75
|
}
|
|
76
|
-
const
|
|
76
|
+
const pending = returning ? query.returning(returning) : query.returning();
|
|
77
|
+
const rows = await pending;
|
|
77
78
|
return { count: rows.length, rows: rows };
|
|
78
79
|
}
|
|
79
80
|
async update(opts) {
|
|
@@ -86,7 +87,8 @@ export class SqliteQueryExecutor {
|
|
|
86
87
|
const result = await query;
|
|
87
88
|
return { count: this.readAffectedRowCount({ result }), rows: [] };
|
|
88
89
|
}
|
|
89
|
-
const
|
|
90
|
+
const pending = returning ? query.returning(returning) : query.returning();
|
|
91
|
+
const rows = await pending;
|
|
90
92
|
return { count: rows.length, rows: rows };
|
|
91
93
|
}
|
|
92
94
|
async remove(opts) {
|
|
@@ -96,7 +98,8 @@ export class SqliteQueryExecutor {
|
|
|
96
98
|
const result = await query;
|
|
97
99
|
return { count: this.readAffectedRowCount({ result }), rows: [] };
|
|
98
100
|
}
|
|
99
|
-
const
|
|
101
|
+
const pending = returning ? query.returning(returning) : query.returning();
|
|
102
|
+
const rows = await pending;
|
|
100
103
|
return { count: rows.length, rows: rows };
|
|
101
104
|
}
|
|
102
105
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../src/relational/sqlite/repositories/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAarD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGnE;;;;;;GAMG;AACH,MAAM,OAAO,mBAAmB;IAG9B;QACE,6FAA6F;QAC7F,2BAA2B;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;IAChF,CAAC;IAED,KAAK,CAAC,MAAM,CAAI,IAAsC;QACpD,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAEhF,oFAAoF;QACpF,qFAAqF;QACrF,IAAI,IAAI,EAAE,CAAC;YACT,iBAAiB,CAAC;gBAChB,KAAK,EAAE,mBAAmB,CAAC,IAAI;gBAC/B,OAAO,EAAE,2CAA2C;gBACpD,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAC;QACL,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAE5C,IAAI,KAAK,GAAG,OAAO;YACjB,CAAC,CAAC,SAAS;iBACN,MAAM,CAAC,OAAkB,CAAC;iBAC1B,IAAI,CAAC,WAAW,CAAC;iBACjB,QAAQ,EAAE;YACf,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,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G,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;aAC9I,CAAC,CAAC;QACL,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CACF","sourcesContent":["import { omit } from '@venizia/ignis-helpers/common';\nimport type { TTableSchemaWithId } from '@/relational/core/models/common';\nimport type {\n ICountOptions,\n IInsertOptions,\n IRelationalQueryExecutor,\n IRelationalQueryOptions,\n IRemoveOptions,\n ISelectOptions,\n IUpdateOptions,\n IWriteResult,\n} from '@/relational/core/repositories/common';\nimport type { TSqliteConnector } from '@/relational/sqlite/drivers';\nimport { throwNotSupported } from '@venizia/ignis-kernel';\nimport type { ILogger } from '@venizia/ignis-helpers/core';\nimport type { AnyType, TNullable } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport type { SQLiteTable } from 'drizzle-orm/sqlite-core';\n\n/**\n * Translates already-built SQL fragments (`where`, `orderBy`, projections) to Drizzle Core calls.\n * Filter-to-SQL compilation is dialect work and stays in the repository tier.\n *\n * The `rows as Array<R>` every write verb ends in is convention, not proof: Drizzle infers\n * `returning()`'s row type from the table schema, not from the caller-chosen R.\n */\nexport class SqliteQueryExecutor implements IRelationalQueryExecutor<TSqliteConnector> {\n private readonly logger: ILogger;\n\n constructor() {\n // Not `LoggerFactory`: it reaches the helpers root barrel, which pulls `ioredis` and fails a\n // browser bundle on `tls`.\n this.logger = new BaseHelper({ scope: SqliteQueryExecutor.name }).getLogger();\n }\n\n async select<R>(opts: ISelectOptions<TSqliteConnector>): Promise<Array<R>> {\n const { connector, table, columns, where, orderBy, limit, offset, lock } = opts;\n\n // SQLite locks the whole database file, never a row, so there is no `FOR UPDATE` to\n // emit. A write transaction (`BEGIN IMMEDIATE`) already excludes every other writer.\n if (lock) {\n throwNotSupported({\n scope: SqliteQueryExecutor.name,\n feature: 'Row-level locking (SELECT ... FOR UPDATE)',\n logger: this.logger,\n });\n }\n\n const sqliteTable = this.asTable({ table });\n\n let query = columns\n ? connector\n .select(columns as AnyType)\n .from(sqliteTable)\n .$dynamic()\n : connector.select().from(sqliteTable).$dynamic();\n\n if (where) {\n query = query.where(where);\n }\n\n if (orderBy && orderBy.length > 0) {\n query = query.orderBy(...orderBy);\n }\n\n if (limit !== undefined) {\n query = query.limit(limit);\n }\n\n if (offset !== undefined) {\n query = query.offset(offset);\n }\n\n // `$dynamic()` infers its row type from the table schema, not from the caller-chosen R.\n return query as Promise<Array<R>>;\n }\n\n async count(opts: ICountOptions<TSqliteConnector>): Promise<number> {\n const { connector, table, where } = opts;\n return connector.$count(this.asTable({ table }), where);\n }\n\n async findMany<R>(opts: IRelationalQueryOptions<TSqliteConnector>): Promise<Array<R>> {\n const queryInterface = this.getQueryInterface(opts);\n\n // Drizzle's relational result does not overlap the\n // caller-chosen R enough for a direct assertion.\n return queryInterface.findMany(opts.query) as AnyType;\n }\n\n async findFirst<R>(opts: IRelationalQueryOptions<TSqliteConnector>): Promise<TNullable<R>> {\n const queryInterface = this.getQueryInterface(opts);\n\n // Drizzle's `findFirst` config type structurally forbids `limit` - it always fetches one row.\n // This is the only place that knows that, so the strip happens here whatever the caller passed.\n const queryOptions = omit({ source: opts.query, keys: ['limit'] });\n const result = await queryInterface.findFirst(queryOptions);\n\n // Same drizzle-relational-query-versus-caller-generic boundary as `findMany` above.\n return (result ?? null) as TNullable<R>;\n }\n\n async insert<R>(opts: IInsertOptions<TSqliteConnector>): Promise<IWriteResult<R>> {\n const { connector, table, values, returning, shouldReturn } = opts;\n const query = connector.insert(this.asTable({ table })).values(values as AnyType);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const rows = returning ? await query.returning(returning as AnyType) : await query.returning();\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n async update<R>(opts: IUpdateOptions<TSqliteConnector>): Promise<IWriteResult<R>> {\n const { connector, table, data, where, returning, shouldReturn } = opts;\n const query = connector\n .update(this.asTable({ table }))\n .set(data as AnyType)\n .where(where);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const rows = returning ? await query.returning(returning as AnyType) : await query.returning();\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n async remove<R>(opts: IRemoveOptions<TSqliteConnector>): Promise<IWriteResult<R>> {\n const { connector, table, where, returning, shouldReturn } = opts;\n const query = connector.delete(this.asTable({ table })).where(where);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const rows = returning ? await query.returning(returning as AnyType) : await query.returning();\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n /**\n * The neutral options carry the dialect-free `Table` bound; every Drizzle SQLite verb wants the\n * concrete `SQLiteTable`. Knowing your own input belongs in the engine adapter, so the whole\n * boundary is this one cast.\n */\n private asTable(opts: { table: TTableSchemaWithId }): SQLiteTable {\n return opts.table as SQLiteTable;\n }\n\n /**\n * Gets the Drizzle relational-query interface, validating schema registration. The error wording\n * names the entity and lists the available keys, and a test asserts it word for word.\n */\n private getQueryInterface(opts: IRelationalQueryOptions<TSqliteConnector>) {\n const { connector, entityName } = opts;\n const scope = opts.scope ?? this.constructor.name;\n\n if (!connector.query) {\n throw getError({\n message: `[${scope}] Connector query interface not available | Ensure datasource is properly configured with schema`,\n });\n }\n\n const queryInterface = connector.query[entityName];\n if (!queryInterface) {\n const availableKeys = Object.keys(connector.query);\n throw getError({\n message: `[${scope}] Schema key mismatch | Entity name '${entityName}' not found in connector.query | Available keys: [${availableKeys.join(', ')}] | Ensure the model's TABLE_NAME matches the schema registration key`,\n });\n }\n\n return queryInterface;\n }\n\n /**\n * Rows affected by a write with no RETURNING. Reads libsql's `ResultSet.rowsAffected`\n * off the raw result - engine knowledge the shared repository tier must not hold.\n * Drivers reporting `changes` instead are synchronous, and `TSqliteConnector` is\n * pinned to `'async'`, so none can arrive here.\n */\n private readAffectedRowCount(opts: { result: unknown }): number {\n const { result } = opts;\n\n // A driver whose Drizzle run-result resolves to nothing carries no count to read.\n if (result === null || result === undefined) {\n return 0;\n }\n\n if (typeof result !== 'object') {\n throw getError({\n message: `[readAffectedRowCount] Unrecognized driver result | expected a libsql ResultSet | got: ${typeof result}`,\n });\n }\n\n const { rowsAffected } = result as { rowsAffected?: unknown };\n\n if (typeof rowsAffected !== 'number') {\n throw getError({\n message: `[readAffectedRowCount] Unrecognized driver result | expected 'rowsAffected' (libsql) | got keys: ${Object.keys(result).join(', ')}`,\n });\n }\n\n return rowsAffected;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../src/relational/sqlite/repositories/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAarD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGnE;;;;;;GAMG;AACH,MAAM,OAAO,mBAAmB;IAG9B;QACE,6FAA6F;QAC7F,2BAA2B;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;IAChF,CAAC;IAED,KAAK,CAAC,MAAM,CAAI,IAAsC;QACpD,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAEhF,oFAAoF;QACpF,qFAAqF;QACrF,IAAI,IAAI,EAAE,CAAC;YACT,iBAAiB,CAAC;gBAChB,KAAK,EAAE,mBAAmB,CAAC,IAAI;gBAC/B,OAAO,EAAE,2CAA2C;gBACpD,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAC;QACL,CAAC;QAED,MAAM,W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AE,CAAC;YAC5C,OAAO,CAAC,CAAC;QACX,CAAC;QAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,0FAA0F,OAAO,MAAM,EAAE;aACnH,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE,YAAY,EAAE,GAAG,MAAoC,CAAC;QAE9D,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,oGAAoG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;aAC9I,CAAC,CAAC;QACL,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CACF","sourcesContent":["import { omit } from '@venizia/ignis-helpers/common';\nimport type { TTableSchemaWithId } from '@/relational/core/models/common';\nimport type {\n ICountOptions,\n IInsertOptions,\n IRelationalQueryExecutor,\n IRelationalQueryOptions,\n IRemoveOptions,\n ISelectOptions,\n IUpdateOptions,\n IWriteResult,\n} from '@/relational/core/repositories/common';\nimport type { TSqliteConnector } from '@/relational/sqlite/drivers';\nimport { throwNotSupported } from '@venizia/ignis-kernel';\nimport type { ILogger } from '@venizia/ignis-helpers/core';\nimport type { AnyType, TNullable } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport type { SQLiteTable } from 'drizzle-orm/sqlite-core';\n\n/**\n * Translates already-built SQL fragments (`where`, `orderBy`, projections) to Drizzle Core calls.\n * Filter-to-SQL compilation is dialect work and stays in the repository tier.\n *\n * The `rows as Array<R>` every write verb ends in is convention, not proof: Drizzle infers\n * `returning()`'s row type from the table schema, not from the caller-chosen R.\n */\nexport class SqliteQueryExecutor implements IRelationalQueryExecutor<TSqliteConnector> {\n private readonly logger: ILogger;\n\n constructor() {\n // Not `LoggerFactory`: it reaches the helpers root barrel, which pulls `ioredis` and fails a\n // browser bundle on `tls`.\n this.logger = new BaseHelper({ scope: SqliteQueryExecutor.name }).getLogger();\n }\n\n async select<R>(opts: ISelectOptions<TSqliteConnector>): Promise<Array<R>> {\n const { connector, table, columns, where, orderBy, limit, offset, lock } = opts;\n\n // SQLite locks the whole database file, never a row, so there is no `FOR UPDATE` to\n // emit. A write transaction (`BEGIN IMMEDIATE`) already excludes every other writer.\n if (lock) {\n throwNotSupported({\n scope: SqliteQueryExecutor.name,\n feature: 'Row-level locking (SELECT ... FOR UPDATE)',\n logger: this.logger,\n });\n }\n\n const sqliteTable = this.asTable({ table });\n\n let query = columns\n ? connector\n .select(columns as AnyType)\n .from(sqliteTable)\n .$dynamic()\n : connector.select().from(sqliteTable).$dynamic();\n\n if (where) {\n query = query.where(where);\n }\n\n if (orderBy && orderBy.length > 0) {\n query = query.orderBy(...orderBy);\n }\n\n if (limit !== undefined) {\n query = query.limit(limit);\n }\n\n if (offset !== undefined) {\n query = query.offset(offset);\n }\n\n // `$dynamic()` infers its row type from the table schema, not from the caller-chosen R.\n return query as Promise<Array<R>>;\n }\n\n async count(opts: ICountOptions<TSqliteConnector>): Promise<number> {\n const { connector, table, where } = opts;\n return connector.$count(this.asTable({ table }), where);\n }\n\n async findMany<R>(opts: IRelationalQueryOptions<TSqliteConnector>): Promise<Array<R>> {\n const queryInterface = this.getQueryInterface(opts);\n\n // Drizzle's relational result does not overlap the\n // caller-chosen R enough for a direct assertion.\n return queryInterface.findMany(opts.query) as AnyType;\n }\n\n async findFirst<R>(opts: IRelationalQueryOptions<TSqliteConnector>): Promise<TNullable<R>> {\n const queryInterface = this.getQueryInterface(opts);\n\n // Drizzle's `findFirst` config type structurally forbids `limit` - it always fetches one row.\n // This is the only place that knows that, so the strip happens here whatever the caller passed.\n const queryOptions = omit({ source: opts.query, keys: ['limit'] });\n const result = await queryInterface.findFirst(queryOptions);\n\n // Same drizzle-relational-query-versus-caller-generic boundary as `findMany` above.\n return (result ?? null) as TNullable<R>;\n }\n\n async insert<R>(opts: IInsertOptions<TSqliteConnector>): Promise<IWriteResult<R>> {\n const { connector, table, values, returning, shouldReturn } = opts;\n const query = connector.insert(this.asTable({ table })).values(values as AnyType);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const pending = returning ? query.returning(returning as AnyType) : query.returning();\n const rows = await pending;\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n async update<R>(opts: IUpdateOptions<TSqliteConnector>): Promise<IWriteResult<R>> {\n const { connector, table, data, where, returning, shouldReturn } = opts;\n const query = connector\n .update(this.asTable({ table }))\n .set(data as AnyType)\n .where(where);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const pending = returning ? query.returning(returning as AnyType) : query.returning();\n const rows = await pending;\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n async remove<R>(opts: IRemoveOptions<TSqliteConnector>): Promise<IWriteResult<R>> {\n const { connector, table, where, returning, shouldReturn } = opts;\n const query = connector.delete(this.asTable({ table })).where(where);\n\n if (!shouldReturn) {\n const result = await query;\n return { count: this.readAffectedRowCount({ result }), rows: [] };\n }\n\n const pending = returning ? query.returning(returning as AnyType) : query.returning();\n const rows = await pending;\n return { count: rows.length, rows: rows as Array<R> };\n }\n\n /**\n * The neutral options carry the dialect-free `Table` bound; every Drizzle SQLite verb wants the\n * concrete `SQLiteTable`. Knowing your own input belongs in the engine adapter, so the whole\n * boundary is this one cast.\n */\n private asTable(opts: { table: TTableSchemaWithId }): SQLiteTable {\n return opts.table as SQLiteTable;\n }\n\n /**\n * Gets the Drizzle relational-query interface, validating schema registration. The error wording\n * names the entity and lists the available keys, and a test asserts it word for word.\n */\n private getQueryInterface(opts: IRelationalQueryOptions<TSqliteConnector>) {\n const { connector, entityName } = opts;\n const scope = opts.scope ?? this.constructor.name;\n\n if (!connector.query) {\n throw getError({\n message: `[${scope}] Connector query interface not available | Ensure datasource is properly configured with schema`,\n });\n }\n\n const queryInterface = connector.query[entityName];\n if (!queryInterface) {\n const availableKeys = Object.keys(connector.query);\n throw getError({\n message: `[${scope}] Schema key mismatch | Entity name '${entityName}' not found in connector.query | Available keys: [${availableKeys.join(', ')}] | Ensure the model's TABLE_NAME matches the schema registration key`,\n });\n }\n\n return queryInterface;\n }\n\n /**\n * Rows affected by a write with no RETURNING. Reads libsql's `ResultSet.rowsAffected`\n * off the raw result - engine knowledge the shared repository tier must not hold.\n * Drivers reporting `changes` instead are synchronous, and `TSqliteConnector` is\n * pinned to `'async'`, so none can arrive here.\n */\n private readAffectedRowCount(opts: { result: unknown }): number {\n const { result } = opts;\n\n // A driver whose Drizzle run-result resolves to nothing carries no count to read.\n if (result === null || result === undefined) {\n return 0;\n }\n\n if (typeof result !== 'object') {\n throw getError({\n message: `[readAffectedRowCount] Unrecognized driver result | expected a libsql ResultSet | got: ${typeof result}`,\n });\n }\n\n const { rowsAffected } = result as { rowsAffected?: unknown };\n\n if (typeof rowsAffected !== 'number') {\n throw getError({\n message: `[readAffectedRowCount] Unrecognized driver result | expected 'rowsAffected' (libsql) | got keys: ${Object.keys(result).join(', ')}`,\n });\n }\n\n return rowsAffected;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract.d.ts","sourceRoot":"","sources":["../../../../../src/search/core/controllers/abstract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAkB,MAAM,uBAAuB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGxC,OAAO,KAA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E;IA6BvD,sFAAsF;IAChF,WAAW,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;KAAE;CAqB7D"}
|
|
@@ -35,9 +35,11 @@ export class AbstractSearchController extends BaseRestController {
|
|
|
35
35
|
async search(opts) {
|
|
36
36
|
const { context } = opts;
|
|
37
37
|
const body = context.req.valid('json');
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
: body;
|
|
38
|
+
let input = body;
|
|
39
|
+
if (this.searchScope) {
|
|
40
|
+
const scoped = await applySearchScope({ resolve: this.searchScope, context, input: body });
|
|
41
|
+
input = scoped;
|
|
42
|
+
}
|
|
41
43
|
const rs = await this.measure({
|
|
42
44
|
scope: 'search',
|
|
43
45
|
args: input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/abstract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI3E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG3C,kUAAkU;AAClU,MAAM,kBAAkB,GAAG,CAAC,IAA+C,EAAU,EAAE;IACrF,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAEjC,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,GAAG,EAAE,CAAC;QACnC,mFAAmF;QACnF,OAAO,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,2FAA2F;IAC3F,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CA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ildDataRange } from '@venizia/ignis-kernel';\nimport type { AbstractEntity } from '@venizia/ignis-kernel';\nimport type { TAnyObjectSchema } from '@venizia/ignis-kernel';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TMultiSearchInput, TSearchInput } from '@/search/core/repositories/common';\nimport { SearchModes } from '@/search/core/repositories/common';\nimport type { ReadableSearchRepository } from '../repositories/core/readable';\nimport { applySearchScope } from './scope';\nimport type { TSearchScopeResolver } from './scope';\n\n/** Where the page starts, for `Content-Range`. Friendly modes carry `filter.skip` or `filter.offset`; raw mode carries the engine's own `offset`, or a 1-based `page` with `per_page`/`perPage`. A raw request that names a page but no page size is measured against this page's hit count, so only its last page can be off. */\nconst resolveSearchStart = (opts: { input: TSearchInput; hitCount: number }): number => {\n const { input, hitCount } = opts;\n\n if (input.mode !== SearchModes.RAW) {\n // Same precedence as buildDataRange: the repository filter carries skip or offset.\n return input.filter?.skip ?? input.filter?.offset ?? 0;\n }\n\n // Engine wire names are read through string keys only; `params` is an untyped passthrough.\n const params = input.params;\n const offset = params['offset'];\n if (typeof offset === 'number') {\n return offset;\n }\n\n const page = params['page'];\n if (typeof page !== 'number' || page < 1) {\n return 0;\n }\n\n const pageSize = params['per_page'] ?? params['perPage'];\n return (page - 1) * (typeof pageSize === 'number' ? pageSize : hitCount);\n};\n\n/** Base tier of a generated search controller: the repository handle plus the search / multi-search verbs; SearchControllerFactory returns a thin subclass that only builds route configs and wires them. */\nexport abstract class AbstractSearchController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n> extends BaseRestController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions> {\n repository: ReadableSearchRepository<TDataObject>;\n searchScope?: TSearchScopeResolver<RouteEnv>;\n\n constructor(opts: {\n scope: string;\n path: string;\n isStrict?: boolean;\n repository: ReadableSearchRepository<TDataObject>;\n definitions: AnyType;\n /** Per-request search scope; see {@link TSearchScopeResolver}. */\n searchScope?: TSearchScopeResolver<RouteEnv>;\n }) {\n super({ scope: opts.scope, path: opts.path, isStrict: opts.isStrict });\n this.repository = opts.repository;\n this.searchScope = opts.searchScope;\n this.definitions = opts.definitions;\n }\n\n /** POST /search - single-collection keyword/semantic/hybrid/raw search. Carries the list headers of every IGNIS list endpoint; the body keeps `{ found, isFoundExact, hits }` because `isFoundExact` has no place in a `{ count, data }` envelope, and it is the only carrier of \"found is an estimate\". */\n async search(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const body = context.req.valid<TSearchInput>('json');\n let input = body;\n if (this.searchScope) {\n const scoped = await applySearchScope({ resolve: this.searchScope, context, input: body });\n input = scoped;\n }\n\n const rs = await this.measure({\n scope: 'search',\n args: input,\n task: async () => {\n // `isFoundExact` travels to the caller so an engine whose `found` is an estimate never looks exhaustive across the HTTP boundary.\n const { found, isFoundExact, hits } = await this.repository.search(input);\n return { found, isFoundExact, hits: hits ?? [] };\n },\n });\n\n const start = resolveSearchStart({ input, hitCount: rs.hits.length });\n this.setListHeaders({\n context,\n range: buildDataRange({ offset: start, dataLength: rs.hits.length, total: rs.found }),\n count: rs.hits.length,\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** POST /multi-search - cross-collection search, forwarded verbatim to the engine. */\n async multiSearch(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n\n // A multi-search entry carries the engine's own `filterBy` string, which a `where` scope cannot\n // be ANDed into: a scoped controller does not serve it.\n if (this.searchScope) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: '[multiSearch] multi-search is not available on a scoped search controller',\n });\n }\n const input = context.req.valid<TMultiSearchInput>('json');\n\n const rs = await this.measure({\n scope: 'multiSearch',\n args: input,\n task: () => this.repository.multiSearch(input),\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../../../src/search/core/controllers/scope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAGtE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE;IACpE,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;CAClC,KAAK,cAAc,CAAC,MAAM,GAAG,OAAO,YAAY,CAAC,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAUnF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAU,QAAQ,SAAS,GAAG,GAAG,GAAG,EAAE,MAAM;IACvE,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjC,KAAK,EAAE,YAAY,CAAC;CACrB,KAAG,OAAO,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../../../src/search/core/controllers/scope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAGtE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE;IACpE,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;CAClC,KAAK,cAAc,CAAC,MAAM,GAAG,OAAO,YAAY,CAAC,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAUnF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAU,QAAQ,SAAS,GAAG,GAAG,GAAG,EAAE,MAAM;IACvE,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjC,KAAK,EAAE,YAAY,CAAC;CACrB,KAAG,OAAO,CAAC,YAAY,CAiDvB,CAAC"}
|
|
@@ -22,7 +22,8 @@ export const applySearchScope = async (opts) => {
|
|
|
22
22
|
const { resolve, context, input } = opts;
|
|
23
23
|
let scope;
|
|
24
24
|
try {
|
|
25
|
-
|
|
25
|
+
const result = await resolve({ context });
|
|
26
|
+
scope = result;
|
|
26
27
|
}
|
|
27
28
|
catch (error) {
|
|
28
29
|
throw refuse({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../../../src/search/core/controllers/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAWhE,MAAM,MAA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\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { ScopeFilters } from '@venizia/ignis-kernel';\nimport type { TRouteContext, TWhere } from '@venizia/ignis-kernel';\nimport type { Env } from 'hono';\nimport type { TSearchInput } from '@/search/core/repositories/common';\nimport { SearchModes } from '@/search/core/repositories/common';\n\n/**\n * A per-request search scope: the filter the caller is allowed to search within (a merchant, a\n * sharing rule). Return a `where`, `ScopeFilters.UNRESTRICTED` to apply none for this call, or\n * null/undefined when the caller's scope is unknown - which refuses the request.\n */\nexport type TSearchScopeResolver<RouteEnv extends Env = Env> = (opts: {\n context: TRouteContext<RouteEnv>;\n}) => ValueOrPromise<TWhere | typeof ScopeFilters.UNRESTRICTED | null | undefined>;\n\nconst refuse = (opts: { statusCode: number; message: string; cause?: unknown }) => {\n return getError({\n statusCode: opts.statusCode,\n message: opts.message,\n cause: opts.cause,\n });\n};\n\n/**\n * ANDs the resolved scope into `input.filter.where`, on the server, after the body was validated.\n * The client's own `where` is kept inside the AND, so it can narrow the scope and never widen it.\n *\n * Fails closed:\n * - a scope that is null, undefined, or throws refuses the request (403);\n * - `raw` mode and `engineParams` hand the engine its own wire parameters (`filter_by` among them),\n * which a `where` cannot be ANDed into, so a scoped controller refuses them (400).\n */\nexport const applySearchScope = async <RouteEnv extends Env = Env>(opts: {\n resolve: TSearchScopeResolver<RouteEnv>;\n context: TRouteContext<RouteEnv>;\n input: TSearchInput;\n}): Promise<TSearchInput> => {\n const { resolve, context, input } = opts;\n\n let scope: Awaited<ReturnType<TSearchScopeResolver<RouteEnv>>>;\n try {\n const result = await resolve({ context });\n scope = result;\n } catch (error) {\n throw refuse({\n statusCode: HTTP.ResultCodes.RS_4.Forbidden,\n message: '[search] the search scope could not be resolved for this request',\n cause: error,\n });\n }\n\n if (scope === ScopeFilters.UNRESTRICTED) {\n return input;\n }\n\n if (scope === null || scope === undefined) {\n throw refuse({\n statusCode: HTTP.ResultCodes.RS_4.Forbidden,\n message: '[search] no search scope for this request',\n });\n }\n\n if (input.mode === SearchModes.RAW) {\n throw refuse({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: \"[search] mode 'raw' is not available on a scoped search controller\",\n });\n }\n\n if (input.engineParams !== undefined) {\n throw refuse({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: '[search] engineParams is not available on a scoped search controller',\n });\n }\n\n const clientWhere = input.filter?.where;\n\n return {\n ...input,\n filter: {\n ...input.filter,\n where: clientWhere ? { and: [scope, clientWhere] } : scope,\n },\n } as TSearchInput;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistable.d.ts","sourceRoot":"","sources":["../../../../../../src/search/core/repositories/core/persistable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE3E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAa,MAAM,+BAA+B,CAAC;AAEvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD,iHAAiH;AACjH,qBAAa,2BAA2B,CACtC,SAAS,SAAS,MAAM,GAAG,MAAM,EACjC,WAAW,SAAS,wBAAwB,GAAG,wBAAwB,CACvE,SAAQ,wBAAwB,CAAC,SAAS,EAAE,WAAW,CAAC;gBAC5C,EAAE,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAA;KAAE;IAKt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,+LAA+L;IAC/L,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE;QAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,uBAAuB,CAAC,EAAE,OAAO,CAAC;KACnC,GAAG,MAAM,GAAG,SAAS;IAItB;;;;;;OAMG;IACH,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,uBAAuB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG;QACxF,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,OAAO,CAAC;KACpB;CAUF"}
|
|
@@ -94,7 +94,8 @@ export class PersistableSearchRepository extends ReadableSearchRepository {
|
|
|
94
94
|
const { id, options } = opts;
|
|
95
95
|
let found = null;
|
|
96
96
|
if (this.defaultWhere && !options?.shouldSkipDefaultFilter) {
|
|
97
|
-
|
|
97
|
+
const result = await this.findById({ id, options });
|
|
98
|
+
found = result;
|
|
98
99
|
if (!found) {
|
|
99
100
|
return { count: 0, data: null };
|
|
100
101
|
}
|