@niscorp/vex 0.4.1 → 0.4.3

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.
@@ -1,4 +1,4 @@
1
- import { handleDiscovery, handleQuery, handleFingerprintPatch, handleFingerprintDelete } from '../../chunk-AKR6HU34.js';
1
+ import { handleDiscovery, handleQuery, handleFingerprintPatch, handleFingerprintDelete } from '../../chunk-W5MYFJKT.js';
2
2
  import '../../chunk-XTOK7YOR.js';
3
3
  import '../../chunk-UPQMKAAX.js';
4
4
  import { Hono } from 'hono';
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ var pg = require('pg');
4
+
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
+
7
+ var pg__default = /*#__PURE__*/_interopDefault(pg);
8
+
9
+ // src/adapters/pg/index.ts
10
+
11
+ // src/adapters/postgres/date-parsers.ts
12
+ var RAW = (value) => value;
13
+ var RAW_DATE_PARSERS = { 1082: RAW, 1184: RAW };
14
+
15
+ // src/adapters/pg/index.ts
16
+ var queryOn = (target, parsers) => {
17
+ const types = parsers === void 0 ? void 0 : { getTypeParser: (oid, format) => parsers[oid] ?? pg__default.default.types.getTypeParser(oid, format) };
18
+ return async (text, values) => {
19
+ const { rows, fields } = await target.query({ text, ...values === void 0 ? {} : { values }, ...types === void 0 ? {} : { types } });
20
+ return { rows, fields: fields.map(({ name, dataTypeID }) => ({ name, dataTypeID })) };
21
+ };
22
+ };
23
+ var createPgPool = (pool, parsers) => ({
24
+ query: queryOn(pool, parsers),
25
+ transaction: async (fn) => {
26
+ const client = await pool.connect();
27
+ try {
28
+ await client.query({ text: "BEGIN" });
29
+ const result = await fn({ query: queryOn(client, parsers) });
30
+ await client.query({ text: "COMMIT" });
31
+ return result;
32
+ } catch (error) {
33
+ await client.query({ text: "ROLLBACK" });
34
+ throw error;
35
+ } finally {
36
+ client.release();
37
+ }
38
+ }
39
+ });
40
+
41
+ exports.RAW_DATE_PARSERS = RAW_DATE_PARSERS;
42
+ exports.createPgPool = createPgPool;
43
+ //# sourceMappingURL=index.cjs.map
44
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapters/postgres/date-parsers.ts","../../../src/adapters/pg/index.ts"],"names":["pg"],"mappings":";;;;;;;;;;;AAEA,IAAM,GAAA,GAAM,CAAC,KAAA,KAA0B,KAAA;AAIhC,IAAM,gBAAA,GAAgC,EAAE,IAAA,EAAM,GAAA,EAAK,MAAM,GAAA;;;ACYhE,IAAM,OAAA,GAAU,CAAC,MAAA,EAAmB,OAAA,KAA8C;AAGhF,EAAA,MAAM,QACJ,OAAA,KAAY,MAAA,GACR,MAAA,GACA,EAAE,eAAe,CAAC,GAAA,EAAa,MAAA,KAA+B,OAAA,CAAQ,GAAG,CAAA,IAAKA,mBAAA,CAAG,MAAM,aAAA,CAAc,GAAA,EAAK,MAAM,CAAA,EAAE;AACxH,EAAA,OAAO,OAAO,MAAM,MAAA,KAAW;AAC7B,IAAA,MAAM,EAAE,IAAA,EAAM,MAAA,EAAO,GAAI,MAAM,OAAO,KAAA,CAAM,EAAE,IAAA,EAAM,GAAI,MAAA,KAAW,MAAA,GAAY,EAAC,GAAI,EAAE,MAAA,EAAO,EAAI,GAAI,KAAA,KAAU,MAAA,GAAY,EAAC,GAAI,EAAE,KAAA,EAAM,EAAI,CAAA;AAC5I,IAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,CAAO,IAAI,CAAC,EAAE,IAAA,EAAM,UAAA,EAAW,MAAO,EAAE,IAAA,EAAM,UAAA,GAAa,CAAA,EAAE;AAAA,EACtF,CAAA;AACF,CAAA;AAEO,IAAM,YAAA,GAAe,CAAC,IAAA,EAAwB,OAAA,MAAmC;AAAA,EACtF,KAAA,EAAO,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA;AAAA,EAC5B,WAAA,EAAa,OAAO,EAAA,KAAO;AACzB,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,OAAA,EAAQ;AAClC,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,CAAO,KAAA,CAAM,EAAE,IAAA,EAAM,SAAS,CAAA;AACpC,MAAA,MAAM,MAAA,GAAS,MAAM,EAAA,CAAG,EAAE,OAAO,OAAA,CAAQ,MAAA,EAAQ,OAAO,CAAA,EAAG,CAAA;AAC3D,MAAA,MAAM,MAAA,CAAO,KAAA,CAAM,EAAE,IAAA,EAAM,UAAU,CAAA;AACrC,MAAA,OAAO,MAAA;AAAA,IACT,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,MAAA,CAAO,KAAA,CAAM,EAAE,IAAA,EAAM,YAAY,CAAA;AACvC,MAAA,MAAM,KAAA;AAAA,IACR,CAAA,SAAE;AACA,MAAA,MAAA,CAAO,OAAA,EAAQ;AAAA,IACjB;AAAA,EACF;AACF,CAAA","file":"index.cjs","sourcesContent":["export type TypeParsers = Record<number, (value: string) => unknown>;\n\nconst RAW = (value: string): string => value;\n\n// OIDs: DATE is 1082, TIMESTAMPTZ is 1184. Not for a pool handed to the vex\n// cache, which reads its timestamp columns as Dates.\nexport const RAW_DATE_PARSERS: TypeParsers = { 1082: RAW, 1184: RAW };\n","import pg from 'pg';\nimport type { PgPool, PgQuery } from '../postgres/introspect.js';\nimport type { TypeParsers } from '../postgres/date-parsers.js';\n\nexport { RAW_DATE_PARSERS } from '../postgres/date-parsers.js';\n\ntype QueryConfig = {\n text: string;\n values?: unknown[];\n types?: { getTypeParser: (oid: number, format?: 'text' | 'binary') => (value: string) => unknown };\n};\n\ntype Queryable = {\n query: (config: QueryConfig) => Promise<{ rows: Record<string, unknown>[]; fields: Array<{ name: string; dataTypeID: number }> }>;\n};\n\ntype NodePostgresPool = Queryable & { connect: () => Promise<Queryable & { release: () => void }> };\n\nconst queryOn = (target: Queryable, parsers: TypeParsers | undefined): PgQuery => {\n // A query's own `types` replaces pg's lookup entirely, so every OID the\n // parsers leave out falls back to pg's.\n const types =\n parsers === undefined\n ? undefined\n : { getTypeParser: (oid: number, format?: 'text' | 'binary') => parsers[oid] ?? pg.types.getTypeParser(oid, format) };\n return async (text, values) => {\n const { rows, fields } = await target.query({ text, ...(values === undefined ? {} : { values }), ...(types === undefined ? {} : { types }) });\n return { rows, fields: fields.map(({ name, dataTypeID }) => ({ name, dataTypeID })) };\n };\n};\n\nexport const createPgPool = (pool: NodePostgresPool, parsers?: TypeParsers): PgPool => ({\n query: queryOn(pool, parsers),\n transaction: async (fn) => {\n const client = await pool.connect();\n try {\n await client.query({ text: 'BEGIN' });\n const result = await fn({ query: queryOn(client, parsers) });\n await client.query({ text: 'COMMIT' });\n return result;\n } catch (error) {\n await client.query({ text: 'ROLLBACK' });\n throw error;\n } finally {\n client.release();\n }\n },\n});\n"]}
@@ -0,0 +1,28 @@
1
+ import { P as PgPool } from '../../introspect-D3OaXHBc.cjs';
2
+ import { T as TypeParsers } from '../../date-parsers-BaUuE_ax.cjs';
3
+ export { R as RAW_DATE_PARSERS } from '../../date-parsers-BaUuE_ax.cjs';
4
+
5
+ type QueryConfig = {
6
+ text: string;
7
+ values?: unknown[];
8
+ types?: {
9
+ getTypeParser: (oid: number, format?: 'text' | 'binary') => (value: string) => unknown;
10
+ };
11
+ };
12
+ type Queryable = {
13
+ query: (config: QueryConfig) => Promise<{
14
+ rows: Record<string, unknown>[];
15
+ fields: Array<{
16
+ name: string;
17
+ dataTypeID: number;
18
+ }>;
19
+ }>;
20
+ };
21
+ type NodePostgresPool = Queryable & {
22
+ connect: () => Promise<Queryable & {
23
+ release: () => void;
24
+ }>;
25
+ };
26
+ declare const createPgPool: (pool: NodePostgresPool, parsers?: TypeParsers) => PgPool;
27
+
28
+ export { createPgPool };
@@ -0,0 +1,28 @@
1
+ import { P as PgPool } from '../../introspect-D3OaXHBc.js';
2
+ import { T as TypeParsers } from '../../date-parsers-BaUuE_ax.js';
3
+ export { R as RAW_DATE_PARSERS } from '../../date-parsers-BaUuE_ax.js';
4
+
5
+ type QueryConfig = {
6
+ text: string;
7
+ values?: unknown[];
8
+ types?: {
9
+ getTypeParser: (oid: number, format?: 'text' | 'binary') => (value: string) => unknown;
10
+ };
11
+ };
12
+ type Queryable = {
13
+ query: (config: QueryConfig) => Promise<{
14
+ rows: Record<string, unknown>[];
15
+ fields: Array<{
16
+ name: string;
17
+ dataTypeID: number;
18
+ }>;
19
+ }>;
20
+ };
21
+ type NodePostgresPool = Queryable & {
22
+ connect: () => Promise<Queryable & {
23
+ release: () => void;
24
+ }>;
25
+ };
26
+ declare const createPgPool: (pool: NodePostgresPool, parsers?: TypeParsers) => PgPool;
27
+
28
+ export { createPgPool };
@@ -0,0 +1,31 @@
1
+ export { RAW_DATE_PARSERS } from '../../chunk-DFWYYBJU.js';
2
+ import pg from 'pg';
3
+
4
+ var queryOn = (target, parsers) => {
5
+ const types = parsers === void 0 ? void 0 : { getTypeParser: (oid, format) => parsers[oid] ?? pg.types.getTypeParser(oid, format) };
6
+ return async (text, values) => {
7
+ const { rows, fields } = await target.query({ text, ...values === void 0 ? {} : { values }, ...types === void 0 ? {} : { types } });
8
+ return { rows, fields: fields.map(({ name, dataTypeID }) => ({ name, dataTypeID })) };
9
+ };
10
+ };
11
+ var createPgPool = (pool, parsers) => ({
12
+ query: queryOn(pool, parsers),
13
+ transaction: async (fn) => {
14
+ const client = await pool.connect();
15
+ try {
16
+ await client.query({ text: "BEGIN" });
17
+ const result = await fn({ query: queryOn(client, parsers) });
18
+ await client.query({ text: "COMMIT" });
19
+ return result;
20
+ } catch (error) {
21
+ await client.query({ text: "ROLLBACK" });
22
+ throw error;
23
+ } finally {
24
+ client.release();
25
+ }
26
+ }
27
+ });
28
+
29
+ export { createPgPool };
30
+ //# sourceMappingURL=index.js.map
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapters/pg/index.ts"],"names":[],"mappings":";;;AAkBA,IAAM,OAAA,GAAU,CAAC,MAAA,EAAmB,OAAA,KAA8C;AAGhF,EAAA,MAAM,QACJ,OAAA,KAAY,MAAA,GACR,MAAA,GACA,EAAE,eAAe,CAAC,GAAA,EAAa,MAAA,KAA+B,OAAA,CAAQ,GAAG,CAAA,IAAK,EAAA,CAAG,MAAM,aAAA,CAAc,GAAA,EAAK,MAAM,CAAA,EAAE;AACxH,EAAA,OAAO,OAAO,MAAM,MAAA,KAAW;AAC7B,IAAA,MAAM,EAAE,IAAA,EAAM,MAAA,EAAO,GAAI,MAAM,OAAO,KAAA,CAAM,EAAE,IAAA,EAAM,GAAI,MAAA,KAAW,MAAA,GAAY,EAAC,GAAI,EAAE,MAAA,EAAO,EAAI,GAAI,KAAA,KAAU,MAAA,GAAY,EAAC,GAAI,EAAE,KAAA,EAAM,EAAI,CAAA;AAC5I,IAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,CAAO,IAAI,CAAC,EAAE,IAAA,EAAM,UAAA,EAAW,MAAO,EAAE,IAAA,EAAM,UAAA,GAAa,CAAA,EAAE;AAAA,EACtF,CAAA;AACF,CAAA;AAEO,IAAM,YAAA,GAAe,CAAC,IAAA,EAAwB,OAAA,MAAmC;AAAA,EACtF,KAAA,EAAO,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA;AAAA,EAC5B,WAAA,EAAa,OAAO,EAAA,KAAO;AACzB,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,OAAA,EAAQ;AAClC,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,CAAO,KAAA,CAAM,EAAE,IAAA,EAAM,SAAS,CAAA;AACpC,MAAA,MAAM,MAAA,GAAS,MAAM,EAAA,CAAG,EAAE,OAAO,OAAA,CAAQ,MAAA,EAAQ,OAAO,CAAA,EAAG,CAAA;AAC3D,MAAA,MAAM,MAAA,CAAO,KAAA,CAAM,EAAE,IAAA,EAAM,UAAU,CAAA;AACrC,MAAA,OAAO,MAAA;AAAA,IACT,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,MAAA,CAAO,KAAA,CAAM,EAAE,IAAA,EAAM,YAAY,CAAA;AACvC,MAAA,MAAM,KAAA;AAAA,IACR,CAAA,SAAE;AACA,MAAA,MAAA,CAAO,OAAA,EAAQ;AAAA,IACjB;AAAA,EACF;AACF,CAAA","file":"index.js","sourcesContent":["import pg from 'pg';\nimport type { PgPool, PgQuery } from '../postgres/introspect.js';\nimport type { TypeParsers } from '../postgres/date-parsers.js';\n\nexport { RAW_DATE_PARSERS } from '../postgres/date-parsers.js';\n\ntype QueryConfig = {\n text: string;\n values?: unknown[];\n types?: { getTypeParser: (oid: number, format?: 'text' | 'binary') => (value: string) => unknown };\n};\n\ntype Queryable = {\n query: (config: QueryConfig) => Promise<{ rows: Record<string, unknown>[]; fields: Array<{ name: string; dataTypeID: number }> }>;\n};\n\ntype NodePostgresPool = Queryable & { connect: () => Promise<Queryable & { release: () => void }> };\n\nconst queryOn = (target: Queryable, parsers: TypeParsers | undefined): PgQuery => {\n // A query's own `types` replaces pg's lookup entirely, so every OID the\n // parsers leave out falls back to pg's.\n const types =\n parsers === undefined\n ? undefined\n : { getTypeParser: (oid: number, format?: 'text' | 'binary') => parsers[oid] ?? pg.types.getTypeParser(oid, format) };\n return async (text, values) => {\n const { rows, fields } = await target.query({ text, ...(values === undefined ? {} : { values }), ...(types === undefined ? {} : { types }) });\n return { rows, fields: fields.map(({ name, dataTypeID }) => ({ name, dataTypeID })) };\n };\n};\n\nexport const createPgPool = (pool: NodePostgresPool, parsers?: TypeParsers): PgPool => ({\n query: queryOn(pool, parsers),\n transaction: async (fn) => {\n const client = await pool.connect();\n try {\n await client.query({ text: 'BEGIN' });\n const result = await fn({ query: queryOn(client, parsers) });\n await client.query({ text: 'COMMIT' });\n return result;\n } catch (error) {\n await client.query({ text: 'ROLLBACK' });\n throw error;\n } finally {\n client.release();\n }\n },\n});\n"]}
@@ -1,8 +1,10 @@
1
1
  'use strict';
2
2
 
3
- // src/adapters/pglite/index.ts
3
+ // src/adapters/postgres/date-parsers.ts
4
4
  var RAW = (value) => value;
5
5
  var RAW_DATE_PARSERS = { 1082: RAW, 1184: RAW };
6
+
7
+ // src/adapters/pglite/index.ts
6
8
  var createPglitePool = (db, parsers) => {
7
9
  const options = parsers !== void 0 ? { parsers } : void 0;
8
10
  const pool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapters/pglite/index.ts"],"names":[],"mappings":";;;AAaA,IAAM,GAAA,GAAM,CAAC,KAAA,KAA0B,KAAA;AAIhC,IAAM,gBAAA,GAA+D,EAAE,IAAA,EAAM,GAAA,EAAK,MAAM,GAAA;AAExF,IAAM,gBAAA,GAAmB,CAAC,EAAA,EAAgB,OAAA,KAAiE;AAChH,EAAA,MAAM,OAAA,GAAU,OAAA,KAAY,MAAA,GAAY,EAAE,SAAQ,GAAI,MAAA;AAGtD,EAAA,MAAM,IAAA,GAAe,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,MAAA,KAAW,EAAA,CAAG,KAAA,CAAM,IAAA,EAAM,MAAA,EAAQ,OAAO,CAAA,EAAG,mBAAmB,KAAA,EAAM;AAI1G,EAAA,IAAI,GAAG,WAAA,KAAgB,MAAA;AACrB,IAAA,IAAA,CAAK,WAAA,GAAc,CAAC,EAAA,KAAO,EAAA,CAAG,YAAa,CAAC,EAAA,KAAO,GAAG,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,MAAA,KAAW,GAAG,KAAA,CAAM,IAAA,EAAM,QAAQ,OAAO,CAAA,EAAG,CAAC,CAAA;AAErH,EAAA,OAAO,IAAA;AACT","file":"index.cjs","sourcesContent":["import type { PgPool } from '../postgres/introspect.js';\n\ntype PgliteQuery = (\n text: string,\n values?: unknown[],\n options?: { parsers?: Record<number, (value: string) => unknown> },\n) => Promise<{ rows: Record<string, unknown>[]; fields?: Array<{ name: string; dataTypeID: number }> }>;\n\ntype PgliteLike = {\n query: PgliteQuery;\n transaction?: <T>(fn: (tx: { query: PgliteQuery }) => Promise<T>) => Promise<T>;\n};\n\nconst RAW = (value: string): string => value;\n\n// OIDs: DATE is 1082, TIMESTAMPTZ is 1184. Not for a pool handed to the vex\n// cache, which reads its timestamp columns as Dates.\nexport const RAW_DATE_PARSERS: Record<number, (value: string) => unknown> = { 1082: RAW, 1184: RAW };\n\nexport const createPglitePool = (db: PgliteLike, parsers?: Record<number, (value: string) => unknown>): PgPool => {\n const options = parsers !== undefined ? { parsers } : undefined;\n // PGlite runs Postgres on one thread, where `statement_timeout`'s timer\n // never fires.\n const pool: PgPool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };\n\n // Called on `db`, not destructured off it: PGlite's `transaction` is a class\n // method that needs its receiver.\n if (db.transaction !== undefined)\n pool.transaction = (fn) => db.transaction!((tx) => fn({ query: (text, values) => tx.query(text, values, options) }));\n\n return pool;\n};\n"]}
1
+ {"version":3,"sources":["../../../src/adapters/postgres/date-parsers.ts","../../../src/adapters/pglite/index.ts"],"names":[],"mappings":";;;AAEA,IAAM,GAAA,GAAM,CAAC,KAAA,KAA0B,KAAA;AAIhC,IAAM,gBAAA,GAAgC,EAAE,IAAA,EAAM,GAAA,EAAK,MAAM,GAAA;;;ACUzD,IAAM,gBAAA,GAAmB,CAAC,EAAA,EAAgB,OAAA,KAAkC;AACjF,EAAA,MAAM,OAAA,GAAU,OAAA,KAAY,MAAA,GAAY,EAAE,SAAQ,GAAI,MAAA;AAGtD,EAAA,MAAM,IAAA,GAAe,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,MAAA,KAAW,EAAA,CAAG,KAAA,CAAM,IAAA,EAAM,MAAA,EAAQ,OAAO,CAAA,EAAG,mBAAmB,KAAA,EAAM;AAI1G,EAAA,IAAI,GAAG,WAAA,KAAgB,MAAA;AACrB,IAAA,IAAA,CAAK,WAAA,GAAc,CAAC,EAAA,KAAO,EAAA,CAAG,YAAa,CAAC,EAAA,KAAO,GAAG,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,MAAA,KAAW,GAAG,KAAA,CAAM,IAAA,EAAM,QAAQ,OAAO,CAAA,EAAG,CAAC,CAAA;AAErH,EAAA,OAAO,IAAA;AACT","file":"index.cjs","sourcesContent":["export type TypeParsers = Record<number, (value: string) => unknown>;\n\nconst RAW = (value: string): string => value;\n\n// OIDs: DATE is 1082, TIMESTAMPTZ is 1184. Not for a pool handed to the vex\n// cache, which reads its timestamp columns as Dates.\nexport const RAW_DATE_PARSERS: TypeParsers = { 1082: RAW, 1184: RAW };\n","import type { PgPool } from '../postgres/introspect.js';\nimport type { TypeParsers } from '../postgres/date-parsers.js';\n\nexport { RAW_DATE_PARSERS } from '../postgres/date-parsers.js';\n\ntype PgliteQuery = (\n text: string,\n values?: unknown[],\n options?: { parsers?: TypeParsers },\n) => Promise<{ rows: Record<string, unknown>[]; fields?: Array<{ name: string; dataTypeID: number }> }>;\n\ntype PgliteLike = {\n query: PgliteQuery;\n transaction?: <T>(fn: (tx: { query: PgliteQuery }) => Promise<T>) => Promise<T>;\n};\n\nexport const createPglitePool = (db: PgliteLike, parsers?: TypeParsers): PgPool => {\n const options = parsers !== undefined ? { parsers } : undefined;\n // PGlite runs Postgres on one thread, where `statement_timeout`'s timer\n // never fires.\n const pool: PgPool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };\n\n // Called on `db`, not destructured off it: PGlite's `transaction` is a class\n // method that needs its receiver.\n if (db.transaction !== undefined)\n pool.transaction = (fn) => db.transaction!((tx) => fn({ query: (text, values) => tx.query(text, values, options) }));\n\n return pool;\n};\n"]}
@@ -1,7 +1,9 @@
1
1
  import { P as PgPool } from '../../introspect-D3OaXHBc.cjs';
2
+ import { T as TypeParsers } from '../../date-parsers-BaUuE_ax.cjs';
3
+ export { R as RAW_DATE_PARSERS } from '../../date-parsers-BaUuE_ax.cjs';
2
4
 
3
5
  type PgliteQuery = (text: string, values?: unknown[], options?: {
4
- parsers?: Record<number, (value: string) => unknown>;
6
+ parsers?: TypeParsers;
5
7
  }) => Promise<{
6
8
  rows: Record<string, unknown>[];
7
9
  fields?: Array<{
@@ -15,7 +17,6 @@ type PgliteLike = {
15
17
  query: PgliteQuery;
16
18
  }) => Promise<T>) => Promise<T>;
17
19
  };
18
- declare const RAW_DATE_PARSERS: Record<number, (value: string) => unknown>;
19
- declare const createPglitePool: (db: PgliteLike, parsers?: Record<number, (value: string) => unknown>) => PgPool;
20
+ declare const createPglitePool: (db: PgliteLike, parsers?: TypeParsers) => PgPool;
20
21
 
21
- export { RAW_DATE_PARSERS, createPglitePool };
22
+ export { createPglitePool };
@@ -1,7 +1,9 @@
1
1
  import { P as PgPool } from '../../introspect-D3OaXHBc.js';
2
+ import { T as TypeParsers } from '../../date-parsers-BaUuE_ax.js';
3
+ export { R as RAW_DATE_PARSERS } from '../../date-parsers-BaUuE_ax.js';
2
4
 
3
5
  type PgliteQuery = (text: string, values?: unknown[], options?: {
4
- parsers?: Record<number, (value: string) => unknown>;
6
+ parsers?: TypeParsers;
5
7
  }) => Promise<{
6
8
  rows: Record<string, unknown>[];
7
9
  fields?: Array<{
@@ -15,7 +17,6 @@ type PgliteLike = {
15
17
  query: PgliteQuery;
16
18
  }) => Promise<T>) => Promise<T>;
17
19
  };
18
- declare const RAW_DATE_PARSERS: Record<number, (value: string) => unknown>;
19
- declare const createPglitePool: (db: PgliteLike, parsers?: Record<number, (value: string) => unknown>) => PgPool;
20
+ declare const createPglitePool: (db: PgliteLike, parsers?: TypeParsers) => PgPool;
20
21
 
21
- export { RAW_DATE_PARSERS, createPglitePool };
22
+ export { createPglitePool };
@@ -1,6 +1,6 @@
1
+ export { RAW_DATE_PARSERS } from '../../chunk-DFWYYBJU.js';
2
+
1
3
  // src/adapters/pglite/index.ts
2
- var RAW = (value) => value;
3
- var RAW_DATE_PARSERS = { 1082: RAW, 1184: RAW };
4
4
  var createPglitePool = (db, parsers) => {
5
5
  const options = parsers !== void 0 ? { parsers } : void 0;
6
6
  const pool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };
@@ -9,6 +9,6 @@ var createPglitePool = (db, parsers) => {
9
9
  return pool;
10
10
  };
11
11
 
12
- export { RAW_DATE_PARSERS, createPglitePool };
12
+ export { createPglitePool };
13
13
  //# sourceMappingURL=index.js.map
14
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapters/pglite/index.ts"],"names":[],"mappings":";AAaA,IAAM,GAAA,GAAM,CAAC,KAAA,KAA0B,KAAA;AAIhC,IAAM,gBAAA,GAA+D,EAAE,IAAA,EAAM,GAAA,EAAK,MAAM,GAAA;AAExF,IAAM,gBAAA,GAAmB,CAAC,EAAA,EAAgB,OAAA,KAAiE;AAChH,EAAA,MAAM,OAAA,GAAU,OAAA,KAAY,MAAA,GAAY,EAAE,SAAQ,GAAI,MAAA;AAGtD,EAAA,MAAM,IAAA,GAAe,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,MAAA,KAAW,EAAA,CAAG,KAAA,CAAM,IAAA,EAAM,MAAA,EAAQ,OAAO,CAAA,EAAG,mBAAmB,KAAA,EAAM;AAI1G,EAAA,IAAI,GAAG,WAAA,KAAgB,MAAA;AACrB,IAAA,IAAA,CAAK,WAAA,GAAc,CAAC,EAAA,KAAO,EAAA,CAAG,YAAa,CAAC,EAAA,KAAO,GAAG,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,MAAA,KAAW,GAAG,KAAA,CAAM,IAAA,EAAM,QAAQ,OAAO,CAAA,EAAG,CAAC,CAAA;AAErH,EAAA,OAAO,IAAA;AACT","file":"index.js","sourcesContent":["import type { PgPool } from '../postgres/introspect.js';\n\ntype PgliteQuery = (\n text: string,\n values?: unknown[],\n options?: { parsers?: Record<number, (value: string) => unknown> },\n) => Promise<{ rows: Record<string, unknown>[]; fields?: Array<{ name: string; dataTypeID: number }> }>;\n\ntype PgliteLike = {\n query: PgliteQuery;\n transaction?: <T>(fn: (tx: { query: PgliteQuery }) => Promise<T>) => Promise<T>;\n};\n\nconst RAW = (value: string): string => value;\n\n// OIDs: DATE is 1082, TIMESTAMPTZ is 1184. Not for a pool handed to the vex\n// cache, which reads its timestamp columns as Dates.\nexport const RAW_DATE_PARSERS: Record<number, (value: string) => unknown> = { 1082: RAW, 1184: RAW };\n\nexport const createPglitePool = (db: PgliteLike, parsers?: Record<number, (value: string) => unknown>): PgPool => {\n const options = parsers !== undefined ? { parsers } : undefined;\n // PGlite runs Postgres on one thread, where `statement_timeout`'s timer\n // never fires.\n const pool: PgPool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };\n\n // Called on `db`, not destructured off it: PGlite's `transaction` is a class\n // method that needs its receiver.\n if (db.transaction !== undefined)\n pool.transaction = (fn) => db.transaction!((tx) => fn({ query: (text, values) => tx.query(text, values, options) }));\n\n return pool;\n};\n"]}
1
+ {"version":3,"sources":["../../../src/adapters/pglite/index.ts"],"names":[],"mappings":";;;AAgBO,IAAM,gBAAA,GAAmB,CAAC,EAAA,EAAgB,OAAA,KAAkC;AACjF,EAAA,MAAM,OAAA,GAAU,OAAA,KAAY,MAAA,GAAY,EAAE,SAAQ,GAAI,MAAA;AAGtD,EAAA,MAAM,IAAA,GAAe,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,MAAA,KAAW,EAAA,CAAG,KAAA,CAAM,IAAA,EAAM,MAAA,EAAQ,OAAO,CAAA,EAAG,mBAAmB,KAAA,EAAM;AAI1G,EAAA,IAAI,GAAG,WAAA,KAAgB,MAAA;AACrB,IAAA,IAAA,CAAK,WAAA,GAAc,CAAC,EAAA,KAAO,EAAA,CAAG,YAAa,CAAC,EAAA,KAAO,GAAG,EAAE,KAAA,EAAO,CAAC,IAAA,EAAM,MAAA,KAAW,GAAG,KAAA,CAAM,IAAA,EAAM,QAAQ,OAAO,CAAA,EAAG,CAAC,CAAA;AAErH,EAAA,OAAO,IAAA;AACT","file":"index.js","sourcesContent":["import type { PgPool } from '../postgres/introspect.js';\nimport type { TypeParsers } from '../postgres/date-parsers.js';\n\nexport { RAW_DATE_PARSERS } from '../postgres/date-parsers.js';\n\ntype PgliteQuery = (\n text: string,\n values?: unknown[],\n options?: { parsers?: TypeParsers },\n) => Promise<{ rows: Record<string, unknown>[]; fields?: Array<{ name: string; dataTypeID: number }> }>;\n\ntype PgliteLike = {\n query: PgliteQuery;\n transaction?: <T>(fn: (tx: { query: PgliteQuery }) => Promise<T>) => Promise<T>;\n};\n\nexport const createPglitePool = (db: PgliteLike, parsers?: TypeParsers): PgPool => {\n const options = parsers !== undefined ? { parsers } : undefined;\n // PGlite runs Postgres on one thread, where `statement_timeout`'s timer\n // never fires.\n const pool: PgPool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };\n\n // Called on `db`, not destructured off it: PGlite's `transaction` is a class\n // method that needs its receiver.\n if (db.transaction !== undefined)\n pool.transaction = (fn) => db.transaction!((tx) => fn({ query: (text, values) => tx.query(text, values, options) }));\n\n return pool;\n};\n"]}
@@ -0,0 +1,7 @@
1
+ // src/adapters/postgres/date-parsers.ts
2
+ var RAW = (value) => value;
3
+ var RAW_DATE_PARSERS = { 1082: RAW, 1184: RAW };
4
+
5
+ export { RAW_DATE_PARSERS };
6
+ //# sourceMappingURL=chunk-DFWYYBJU.js.map
7
+ //# sourceMappingURL=chunk-DFWYYBJU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/adapters/postgres/date-parsers.ts"],"names":[],"mappings":";AAEA,IAAM,GAAA,GAAM,CAAC,KAAA,KAA0B,KAAA;AAIhC,IAAM,gBAAA,GAAgC,EAAE,IAAA,EAAM,GAAA,EAAK,MAAM,GAAA","file":"chunk-DFWYYBJU.js","sourcesContent":["export type TypeParsers = Record<number, (value: string) => unknown>;\n\nconst RAW = (value: string): string => value;\n\n// OIDs: DATE is 1082, TIMESTAMPTZ is 1184. Not for a pool handed to the vex\n// cache, which reads its timestamp columns as Dates.\nexport const RAW_DATE_PARSERS: TypeParsers = { 1082: RAW, 1184: RAW };\n"]}
@@ -1208,7 +1208,7 @@ var scopeInsertParts = (table, rawValues, rawConflict, policy) => {
1208
1208
  for (const r of [...gate.rule.write ?? [], ...gate.rule.update ?? []]) {
1209
1209
  if ("set" in r) {
1210
1210
  conflict = { ...conflict, set: { ...conflict.set ?? {}, [r.set]: { $scope: r.to } } };
1211
- } else if (!conflict.target.includes(r.match)) {
1211
+ } else {
1212
1212
  const boundary = boundaryOf(table, r);
1213
1213
  conflict = { ...conflict, where: conflict.where === void 0 ? boundary : { and: [conflict.where, boundary] } };
1214
1214
  }
@@ -1246,6 +1246,10 @@ var scopeMutation = (m, policy) => {
1246
1246
  }
1247
1247
  return { op: "delete", table: m.table, where };
1248
1248
  };
1249
+ var itemRow = (element, itemKeys) => {
1250
+ const fields = element !== null && typeof element === "object" && !Array.isArray(element) ? element : {};
1251
+ return Object.fromEntries(Object.entries(itemKeys).map(([column, key]) => [column, fields[key]]));
1252
+ };
1249
1253
  var newCtx = () => ({
1250
1254
  resolvedPaths: /* @__PURE__ */ new Map(),
1251
1255
  aliasMap: /* @__PURE__ */ new Map(),
@@ -1292,13 +1296,6 @@ var compileConflict = (m, ctx, schema) => {
1292
1296
  }
1293
1297
  return ` ON CONFLICT (${c.target.join(", ")}) DO UPDATE SET ${sets.join(", ")}${where}`;
1294
1298
  };
1295
- var ITEM_CAST = {
1296
- number: "numeric",
1297
- boolean: "boolean",
1298
- date: "date",
1299
- timestamp: "timestamptz",
1300
- uuid: "uuid"
1301
- };
1302
1299
  var compileMutation = (m, schema) => {
1303
1300
  const ctx = newCtx();
1304
1301
  if (m.op === "insert") {
@@ -1308,26 +1305,28 @@ var compileMutation = (m, schema) => {
1308
1305
  return { sql: `INSERT INTO ${m.table} (${cols.join(", ")}) VALUES (${vals.join(", ")})${compileConflict(m, ctx, schema)} RETURNING *`, slots: ctx.paramSlots, returned: ctx.returned };
1309
1306
  }
1310
1307
  if (m.op === "insertEach") {
1311
- const entity = findEntity(m.table, schema);
1308
+ const types = new Map(findEntity(m.table, schema)?.fields.map((f) => [f.name, f.type]));
1312
1309
  const entries = Object.entries(m.values);
1313
1310
  const cols = entries.map(([c]) => c);
1311
+ const itemKeys = {};
1312
+ const itemColumns = [];
1314
1313
  const exprs = entries.map(([col, v]) => {
1315
1314
  if (isItemRef(v)) {
1316
- const nt = entity?.fields.find((f) => f.name === col)?.normalizedType ?? "string";
1317
- if (nt === "json") return `(item.value->${quoteLiteral(v.$item)})`;
1318
- const cast = ITEM_CAST[nt];
1319
- const raw = `(item.value->>${quoteLiteral(v.$item)})`;
1320
- return cast === void 0 ? raw : `${raw}::${cast}`;
1315
+ itemKeys[col] = v.$item;
1316
+ itemColumns.push(`${col} ${String(types.get(col))}`);
1317
+ return `item.${col}`;
1321
1318
  }
1322
1319
  return isReturned(v) ? compileColumnValue(m.table, col, v, ctx, schema) : compileValue(v, ctx);
1323
1320
  });
1324
1321
  ctx.paramCounter.value += 1;
1325
1322
  ctx.paramSlots.push({ key: m.items.$context, kind: "context", type: "json" });
1326
- const source = `jsonb_array_elements($${ctx.paramCounter.value}::jsonb) AS item`;
1323
+ const items = `$${ctx.paramCounter.value}::jsonb`;
1324
+ const source = itemColumns.length === 0 ? `jsonb_array_elements(${items}) AS item` : `jsonb_to_recordset(${items}) AS item(${itemColumns.join(", ")})`;
1327
1325
  return {
1328
1326
  sql: `INSERT INTO ${m.table} (${cols.join(", ")}) SELECT ${exprs.join(", ")} FROM ${source}${compileConflict(m, ctx, schema)} RETURNING *`,
1329
1327
  slots: ctx.paramSlots,
1330
- returned: ctx.returned
1328
+ returned: ctx.returned,
1329
+ itemKeys
1331
1330
  };
1332
1331
  }
1333
1332
  if (m.op === "update") {
@@ -1419,7 +1418,8 @@ var executeWrites = async (client, def, mctx) => {
1419
1418
  if (!Array.isArray(value)) {
1420
1419
  throw new VexError("invalid_request", `"${c.slots[i]?.key ?? ""}" must be an array of objects (one inserted row per element).`);
1421
1420
  }
1422
- return JSON.stringify(value);
1421
+ const { itemKeys } = c;
1422
+ return JSON.stringify(itemKeys === void 0 ? value : value.map((element) => itemRow(element, itemKeys)));
1423
1423
  });
1424
1424
  const res = await q.query(c.sql, bound);
1425
1425
  results.push({ table: c.table, op: c.op, rows: res.rows });
@@ -1763,5 +1763,5 @@ var handleFingerprintDelete = async (config, fingerprint) => {
1763
1763
  };
1764
1764
 
1765
1765
  export { MutationDefinitionSchema, MutationSchema, QueryRequestSchema, VexScopeError, applyScope, buildContextContract, buildValidationContext, canReadTable, canonicalHash, canonicalText, checkScope, collectMutationContext, collectQueryContext, compileAggregate, compileCompute, compileFieldOrValue, compileFilter, compileJoinPairs, computePolicyKey, computeRequestHash, computeSchemaFingerprint, executeMutation, executeQuery, executeWrites, findMissingContext, fireAndForget, handleDiscovery, handleFingerprintDelete, handleFingerprintPatch, handleQuery, hashText, isEntryFresh, isSetMatch, isTouchDue, lintMutation, mintFingerprint, mutationEffect, mutationMisfits, normalizeShape, optionalKeysOf, presenceOf, presenceSignature, pruneOptional, quoteIdent, refuseOptional, requireScope, requiredContextKeys, resolveParams, scopeResolved, sweepCache, tablesChangedBy };
1766
- //# sourceMappingURL=chunk-AKR6HU34.js.map
1767
- //# sourceMappingURL=chunk-AKR6HU34.js.map
1766
+ //# sourceMappingURL=chunk-W5MYFJKT.js.map
1767
+ //# sourceMappingURL=chunk-W5MYFJKT.js.map