@niscorp/vex 0.1.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/DESIGN.md +881 -0
- package/DOCS.md +1295 -0
- package/LICENSE +202 -0
- package/README.md +97 -0
- package/dist/adapters/express/index.cjs +1406 -0
- package/dist/adapters/express/index.cjs.map +1 -0
- package/dist/adapters/express/index.d.cts +25 -0
- package/dist/adapters/express/index.d.ts +25 -0
- package/dist/adapters/express/index.js +60 -0
- package/dist/adapters/express/index.js.map +1 -0
- package/dist/adapters/hono/index.cjs +1426 -0
- package/dist/adapters/hono/index.cjs.map +1 -0
- package/dist/adapters/hono/index.d.cts +25 -0
- package/dist/adapters/hono/index.d.ts +25 -0
- package/dist/adapters/hono/index.js +78 -0
- package/dist/adapters/hono/index.js.map +1 -0
- package/dist/adapters/pglite/index.cjs +17 -0
- package/dist/adapters/pglite/index.cjs.map +1 -0
- package/dist/adapters/pglite/index.d.cts +21 -0
- package/dist/adapters/pglite/index.d.ts +21 -0
- package/dist/adapters/pglite/index.js +14 -0
- package/dist/adapters/pglite/index.js.map +1 -0
- package/dist/agent/index.cjs +478 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +29 -0
- package/dist/agent/index.d.ts +29 -0
- package/dist/agent/index.js +313 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/chunk-FPKW4TRX.js +1528 -0
- package/dist/chunk-FPKW4TRX.js.map +1 -0
- package/dist/chunk-HF25Q53I.js +165 -0
- package/dist/chunk-HF25Q53I.js.map +1 -0
- package/dist/handler-Cql8SJ3F.d.cts +133 -0
- package/dist/handler-mICf9ins.d.ts +133 -0
- package/dist/index.cjs +4078 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +199 -0
- package/dist/index.d.ts +199 -0
- package/dist/index.js +2340 -0
- package/dist/index.js.map +1 -0
- package/dist/introspect-D3OaXHBc.d.cts +16 -0
- package/dist/introspect-D3OaXHBc.d.ts +16 -0
- package/dist/types-BRvMB6IM.d.cts +1491 -0
- package/dist/types-BRvMB6IM.d.ts +1491 -0
- package/package.json +125 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Env, Context, Hono } from 'hono';
|
|
2
|
+
import { a as QueryEngine, ak as ScopeValues, S as ScopePolicy } from '../../types-BRvMB6IM.cjs';
|
|
3
|
+
import { M as MutationClient, W as WriteEvent, E as ExecuteRecord } from '../../handler-Cql8SJ3F.cjs';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import '@niscorp/prism';
|
|
6
|
+
import '@niscorp/strata';
|
|
7
|
+
|
|
8
|
+
declare const VEX_LIVE_ENV = "vexLive";
|
|
9
|
+
type VexHonoConfig<E extends Env = Env> = {
|
|
10
|
+
engine: QueryEngine;
|
|
11
|
+
entities?: string[];
|
|
12
|
+
locked?: boolean;
|
|
13
|
+
getScope?: (c: Context<E>) => Promise<ScopeValues> | ScopeValues;
|
|
14
|
+
getPolicy?: (c: Context<E>) => Promise<ScopePolicy | undefined> | ScopePolicy | undefined;
|
|
15
|
+
getPolicyForReach?: (c: Context<E>, reach: string) => Promise<ScopePolicy | undefined> | ScopePolicy | undefined;
|
|
16
|
+
mutations?: {
|
|
17
|
+
client: MutationClient;
|
|
18
|
+
policy?: ScopePolicy;
|
|
19
|
+
onWrite?: (event: WriteEvent) => void;
|
|
20
|
+
};
|
|
21
|
+
onExecute?: (record: ExecuteRecord) => void;
|
|
22
|
+
};
|
|
23
|
+
declare const vex: <E extends Env = Env>(config: VexHonoConfig<E>) => Hono<E>;
|
|
24
|
+
|
|
25
|
+
export { VEX_LIVE_ENV, type VexHonoConfig, vex };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Env, Context, Hono } from 'hono';
|
|
2
|
+
import { a as QueryEngine, ak as ScopeValues, S as ScopePolicy } from '../../types-BRvMB6IM.js';
|
|
3
|
+
import { M as MutationClient, W as WriteEvent, E as ExecuteRecord } from '../../handler-mICf9ins.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import '@niscorp/prism';
|
|
6
|
+
import '@niscorp/strata';
|
|
7
|
+
|
|
8
|
+
declare const VEX_LIVE_ENV = "vexLive";
|
|
9
|
+
type VexHonoConfig<E extends Env = Env> = {
|
|
10
|
+
engine: QueryEngine;
|
|
11
|
+
entities?: string[];
|
|
12
|
+
locked?: boolean;
|
|
13
|
+
getScope?: (c: Context<E>) => Promise<ScopeValues> | ScopeValues;
|
|
14
|
+
getPolicy?: (c: Context<E>) => Promise<ScopePolicy | undefined> | ScopePolicy | undefined;
|
|
15
|
+
getPolicyForReach?: (c: Context<E>, reach: string) => Promise<ScopePolicy | undefined> | ScopePolicy | undefined;
|
|
16
|
+
mutations?: {
|
|
17
|
+
client: MutationClient;
|
|
18
|
+
policy?: ScopePolicy;
|
|
19
|
+
onWrite?: (event: WriteEvent) => void;
|
|
20
|
+
};
|
|
21
|
+
onExecute?: (record: ExecuteRecord) => void;
|
|
22
|
+
};
|
|
23
|
+
declare const vex: <E extends Env = Env>(config: VexHonoConfig<E>) => Hono<E>;
|
|
24
|
+
|
|
25
|
+
export { VEX_LIVE_ENV, type VexHonoConfig, vex };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { handleDiscovery, handleQuery, handleFingerprintPatch, handleFingerprintDelete } from '../../chunk-FPKW4TRX.js';
|
|
2
|
+
import '../../chunk-HF25Q53I.js';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
|
|
5
|
+
var VEX_LIVE_ENV = "vexLive";
|
|
6
|
+
var liveOf = (env) => {
|
|
7
|
+
if (env === null || typeof env !== "object" || !(VEX_LIVE_ENV in env)) return void 0;
|
|
8
|
+
const live = Reflect.get(env, VEX_LIVE_ENV);
|
|
9
|
+
if (live === null || typeof live !== "object" || !("signal" in live) || !("onChange" in live)) return void 0;
|
|
10
|
+
const { signal, onChange } = live;
|
|
11
|
+
if (!(signal instanceof AbortSignal) || typeof onChange !== "function") return void 0;
|
|
12
|
+
return { signal, onChange: (response) => void Reflect.apply(onChange, void 0, [response]) };
|
|
13
|
+
};
|
|
14
|
+
var fingerprintFromBody = (body) => {
|
|
15
|
+
if (body === null || typeof body !== "object") return void 0;
|
|
16
|
+
const fp = body["fingerprint"];
|
|
17
|
+
return typeof fp === "string" && fp.length > 0 ? fp : void 0;
|
|
18
|
+
};
|
|
19
|
+
var vex = (config) => {
|
|
20
|
+
const app = new Hono();
|
|
21
|
+
const requestConfig = async (c) => {
|
|
22
|
+
const policy = config.getPolicy ? await config.getPolicy(c) : void 0;
|
|
23
|
+
const mutationPolicy = policy ?? config.mutations?.policy;
|
|
24
|
+
return {
|
|
25
|
+
engine: config.engine,
|
|
26
|
+
entities: config.entities,
|
|
27
|
+
...config.locked === true ? { locked: true } : {},
|
|
28
|
+
...policy !== void 0 ? { scopePolicy: policy } : {},
|
|
29
|
+
...config.getPolicyForReach !== void 0 ? { policyForReach: (reach) => config.getPolicyForReach?.(c, reach) } : {},
|
|
30
|
+
...config.onExecute !== void 0 ? { onExecute: config.onExecute } : {},
|
|
31
|
+
...config.mutations !== void 0 && mutationPolicy !== void 0 ? {
|
|
32
|
+
mutations: {
|
|
33
|
+
client: config.mutations.client,
|
|
34
|
+
policy: mutationPolicy,
|
|
35
|
+
...config.mutations.onWrite !== void 0 ? { onWrite: config.mutations.onWrite } : {}
|
|
36
|
+
}
|
|
37
|
+
} : {}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const handlerConfig = {
|
|
41
|
+
engine: config.engine,
|
|
42
|
+
entities: config.entities,
|
|
43
|
+
...config.locked === true ? { locked: true } : {}
|
|
44
|
+
};
|
|
45
|
+
app.get("/", async (c) => c.json(await handleDiscovery(await requestConfig(c))));
|
|
46
|
+
app.post("/", async (c) => {
|
|
47
|
+
const scope = config.getScope ? await config.getScope(c) : {};
|
|
48
|
+
const body = await c.req.json();
|
|
49
|
+
const result = await handleQuery(await requestConfig(c), body, scope, liveOf(c.env));
|
|
50
|
+
return c.json(result.body, result.status);
|
|
51
|
+
});
|
|
52
|
+
app.patch("/", async (c) => {
|
|
53
|
+
const body = await c.req.json();
|
|
54
|
+
const fingerprint = fingerprintFromBody(body);
|
|
55
|
+
if (fingerprint === void 0) {
|
|
56
|
+
return c.json({ error: "invalid_request", message: "Body must include { fingerprint }" }, 400);
|
|
57
|
+
}
|
|
58
|
+
const wanted = body["protected"];
|
|
59
|
+
const result = await handleFingerprintPatch(handlerConfig, fingerprint, {
|
|
60
|
+
...typeof wanted === "boolean" ? { protected: wanted } : {}
|
|
61
|
+
});
|
|
62
|
+
return c.json(result.body, result.status);
|
|
63
|
+
});
|
|
64
|
+
app.delete("/", async (c) => {
|
|
65
|
+
const body = await c.req.json();
|
|
66
|
+
const fingerprint = fingerprintFromBody(body);
|
|
67
|
+
if (fingerprint === void 0) {
|
|
68
|
+
return c.json({ error: "invalid_request", message: "Body must include { fingerprint }" }, 400);
|
|
69
|
+
}
|
|
70
|
+
const result = await handleFingerprintDelete(handlerConfig, fingerprint);
|
|
71
|
+
return c.json(result.body, result.status);
|
|
72
|
+
});
|
|
73
|
+
return app;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { VEX_LIVE_ENV, vex };
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/hono/index.ts"],"names":[],"mappings":";;;;AAaO,IAAM,YAAA,GAAe;AAE5B,IAAM,MAAA,GAAS,CAAC,GAAA,KAAsC;AACpD,EAAA,IAAI,GAAA,KAAQ,QAAQ,OAAO,GAAA,KAAQ,YAAY,EAAE,YAAA,IAAgB,MAAM,OAAO,MAAA;AAC9E,EAAA,MAAM,IAAA,GAAgB,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,YAAY,CAAA;AACnD,EAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,IAAY,EAAE,QAAA,IA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,IAAuC,GAAG,CAAA;AAAA,IAC/F;AACA,IAAA,MAAM,MAAA,GAAS,MAAM,uBAAA,CAAwB,aAAA,EAAe,WAAW,CAAA;AACvE,IAAA,OAAO,CAAA,CAAE,IAAA,CAAK,MAAA,CAAO,IAAA,EAAM,OAAO,MAAa,CAAA;AAAA,EACjD,CAAC,CAAA;AAED,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["import { Hono } from 'hono';\nimport type { Context, Env } from 'hono';\nimport type { QueryEngine } from '../../types.js';\nimport type { ScopePolicy, ScopeValues } from '../../scope/scope.types.js';\nimport type { MutationClient } from '../../mutations/engine.js';\nimport { handleDiscovery, handleQuery, handleFingerprintPatch, handleFingerprintDelete } from '../../handler.js';\nimport type { WriteEvent, ExecuteRecord, VexLive } from '../../handler.js';\nimport type { QueryResponse } from '../../schemas/request.schema.js';\n\n// A request made IN-PROCESS may carry a follower in hono's env — the third\n// argument of `app.request(url, init, env)` — under this key. A request off\n// the network never can: its env is the runtime's (node's sockets, a\n// worker's bindings), so nothing a client sends reaches it. See `VexLive`.\nexport const VEX_LIVE_ENV = 'vexLive';\n\nconst liveOf = (env: unknown): VexLive | undefined => {\n if (env === null || typeof env !== 'object' || !(VEX_LIVE_ENV in env)) return undefined;\n const live: unknown = Reflect.get(env, VEX_LIVE_ENV);\n if (live === null || typeof live !== 'object' || !('signal' in live) || !('onChange' in live)) return undefined;\n const { signal, onChange } = live;\n if (!(signal instanceof AbortSignal) || typeof onChange !== 'function') return undefined;\n return { signal, onChange: (response: QueryResponse) => void Reflect.apply(onChange, undefined, [response]) };\n};\n\n// Generic over the hono Env so a host that mounts this under its own app\n// (with typed context variables — e.g. the resolved principal) reads them\n// in `getScope`/`getPolicy` without casts.\nexport type VexHonoConfig<E extends Env = Env> = {\n engine: QueryEngine;\n entities?: string[];\n // Replay-only posture: no generation, no fingerprint management.\n // (Writes are unaffected — mutation replay is always replay-only.)\n locked?: boolean;\n getScope?: (c: Context<E>) => Promise<ScopeValues> | ScopeValues;\n // Per-request ScopePolicy — a host that resolves policy per principal\n // (e.g. compiled from an ACL layer at login) returns it here; it governs\n // reads, mutation replay AND discovery on this endpoint. Absent (or\n // returning undefined), the engine default and `mutations.policy` apply.\n getPolicy?: (c: Context<E>) => Promise<ScopePolicy | undefined> | ScopePolicy | undefined;\n // The same principal's policy at a reach an entry demands — see\n // `OkCacheEntry.reach`. Bound per request, because the principal is.\n getPolicyForReach?: (c: Context<E>, reach: string) => Promise<ScopePolicy | undefined> | ScopePolicy | undefined;\n // Enables replay of `kind: 'mutation'` cache entries on this endpoint.\n // `policy` is the static fallback when `getPolicy` is absent; at least\n // one of the two must supply a policy for writes to run.\n // `onWrite` is the handler's write observer, passed through verbatim —\n // fired after a successful commit with per-statement writes and scope.\n mutations?: {\n client: MutationClient;\n policy?: ScopePolicy;\n onWrite?: (event: WriteEvent) => void;\n };\n // The execution observer, passed through verbatim — fired once per query or\n // mutation with vex-vocabulary facts. See `VexHandlerConfig.onExecute`.\n onExecute?: (record: ExecuteRecord) => void;\n};\n\n// Fingerprints may contain '/' (named slots like \"deals/table\"), so\n// management rides the request BODY, not the path.\nconst fingerprintFromBody = (body: unknown): string | undefined => {\n if (body === null || typeof body !== 'object') return undefined;\n const fp = (body as Record<string, unknown>)['fingerprint'];\n return typeof fp === 'string' && fp.length > 0 ? fp : undefined;\n};\n\nexport const vex = <E extends Env = Env>(config: VexHonoConfig<E>): Hono<E> => {\n const app = new Hono<E>();\n // The per-request policy (when configured) overrides everything policy-\n // shaped: reads (scopePolicy), writes (mutations.policy) and discovery.\n const requestConfig = async (c: Context<E>) => {\n const policy = config.getPolicy ? await config.getPolicy(c) : undefined;\n const mutationPolicy = policy ?? config.mutations?.policy;\n return {\n engine: config.engine,\n entities: config.entities,\n ...(config.locked === true ? { locked: true } : {}),\n ...(policy !== undefined ? { scopePolicy: policy } : {}),\n ...(config.getPolicyForReach !== undefined\n ? { policyForReach: (reach: string) => config.getPolicyForReach?.(c, reach) }\n : {}),\n ...(config.onExecute !== undefined ? { onExecute: config.onExecute } : {}),\n ...(config.mutations !== undefined && mutationPolicy !== undefined\n ? {\n mutations: {\n client: config.mutations.client,\n policy: mutationPolicy,\n ...(config.mutations.onWrite !== undefined ? { onWrite: config.mutations.onWrite } : {}),\n },\n }\n : {}),\n };\n };\n // Fingerprint management carries no per-request policy — it is refused\n // under `locked` and is an operator surface, not a principal one.\n const handlerConfig = {\n engine: config.engine,\n entities: config.entities,\n ...(config.locked === true ? { locked: true } : {}),\n };\n\n app.get('/', async (c) => c.json(await handleDiscovery(await requestConfig(c))));\n\n app.post('/', async (c) => {\n const scope = config.getScope ? await config.getScope(c) : {};\n const body: unknown = await c.req.json();\n const result = await handleQuery(await requestConfig(c), body, scope, liveOf(c.env));\n return c.json(result.body, result.status as 200);\n });\n\n app.patch('/', async (c) => {\n const body: unknown = await c.req.json();\n const fingerprint = fingerprintFromBody(body);\n if (fingerprint === undefined) {\n return c.json({ error: 'invalid_request', message: 'Body must include { fingerprint }' }, 400);\n }\n const wanted = (body as Record<string, unknown>)['protected'];\n const result = await handleFingerprintPatch(handlerConfig, fingerprint, {\n ...(typeof wanted === 'boolean' ? { protected: wanted } : {}),\n });\n return c.json(result.body, result.status as 200);\n });\n\n app.delete('/', async (c) => {\n const body: unknown = await c.req.json();\n const fingerprint = fingerprintFromBody(body);\n if (fingerprint === undefined) {\n return c.json({ error: 'invalid_request', message: 'Body must include { fingerprint }' }, 400);\n }\n const result = await handleFingerprintDelete(handlerConfig, fingerprint);\n return c.json(result.body, result.status as 200);\n });\n\n return app;\n};\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/adapters/pglite/index.ts
|
|
4
|
+
var RAW = (value) => value;
|
|
5
|
+
var RAW_DATE_PARSERS = { 1082: RAW, 1184: RAW };
|
|
6
|
+
var createPglitePool = (db, parsers) => {
|
|
7
|
+
const options = parsers !== void 0 ? { parsers } : void 0;
|
|
8
|
+
const pool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };
|
|
9
|
+
if (db.transaction !== void 0)
|
|
10
|
+
pool.transaction = (fn) => db.transaction((tx) => fn({ query: (text, values) => tx.query(text, values, options) }));
|
|
11
|
+
return pool;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.RAW_DATE_PARSERS = RAW_DATE_PARSERS;
|
|
15
|
+
exports.createPglitePool = createPglitePool;
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
17
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/pglite/index.ts"],"names":[],"mappings":";;;AA+BA,IAAM,GAAA,GAAM,CAAC,KAAA,KAA0B,KAAA;AAGhC,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;AAW1G,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\n// ═══════════════════════════════════════════════════════════════\n// PGlite → PgPool — the two-line shim every PGlite-backed app was\n// hand-rolling. Structurally typed: anything with PGlite's query\n// signature works, so this package takes NO dependency on\n// @electric-sql/pglite.\n//\n// Date handling is the one real decision here. PGlite parses date/time\n// columns into JS `Date`s, which stringify to locale noise AND can't be\n// formatted by Prism's `$date` (it wants a string/number). So app/adapter\n// pools pass RAW_DATE_PARSERS to get the raw wire strings back — while the\n// vex cache calls `.getTime()` on its own timestamp columns, so it MUST\n// keep `Date`s. Hence two pools over the same db: parsers for the adapter\n// pool, none for the cache pool.\n// ═══════════════════════════════════════════════════════════════\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 // PGlite has this natively. Optional here only so the shim still accepts a\n // narrower object — a `db` that cannot transact yields a pool that says so\n // rather than one that pretends.\n transaction?: <T>(fn: (tx: { query: PgliteQuery }) => Promise<T>) => Promise<T>;\n};\n\nconst RAW = (value: string): string => value;\n\n// DATE (OID 1082) and TIMESTAMPTZ (1184) come back as raw wire strings.\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 (a 2s sleep ran its 2.9s under a 200ms limit).\n const pool: PgPool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };\n\n // PASSED THROUGH, not reimplemented. Wrapping BEGIN/COMMIT by hand over a\n // single `query` would be wrong on a real pool — the statements could land\n // on different connections — and PGlite already pins the right one.\n //\n // Without this, every batch mutation in every app on this adapter threw.\n // Called ON `db`, not destructured off it. PGlite's `transaction` is a\n // class method that reaches for `this`; pulling it out of the object hands\n // it an undefined receiver and it dies inside the library on a property\n // nobody here has heard of.\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,21 @@
|
|
|
1
|
+
import { P as PgPool } from '../../introspect-D3OaXHBc.cjs';
|
|
2
|
+
|
|
3
|
+
type PgliteQuery = (text: string, values?: unknown[], options?: {
|
|
4
|
+
parsers?: Record<number, (value: string) => unknown>;
|
|
5
|
+
}) => Promise<{
|
|
6
|
+
rows: Record<string, unknown>[];
|
|
7
|
+
fields?: Array<{
|
|
8
|
+
name: string;
|
|
9
|
+
dataTypeID: number;
|
|
10
|
+
}>;
|
|
11
|
+
}>;
|
|
12
|
+
type PgliteLike = {
|
|
13
|
+
query: PgliteQuery;
|
|
14
|
+
transaction?: <T>(fn: (tx: {
|
|
15
|
+
query: PgliteQuery;
|
|
16
|
+
}) => Promise<T>) => Promise<T>;
|
|
17
|
+
};
|
|
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
|
+
|
|
21
|
+
export { RAW_DATE_PARSERS, createPglitePool };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { P as PgPool } from '../../introspect-D3OaXHBc.js';
|
|
2
|
+
|
|
3
|
+
type PgliteQuery = (text: string, values?: unknown[], options?: {
|
|
4
|
+
parsers?: Record<number, (value: string) => unknown>;
|
|
5
|
+
}) => Promise<{
|
|
6
|
+
rows: Record<string, unknown>[];
|
|
7
|
+
fields?: Array<{
|
|
8
|
+
name: string;
|
|
9
|
+
dataTypeID: number;
|
|
10
|
+
}>;
|
|
11
|
+
}>;
|
|
12
|
+
type PgliteLike = {
|
|
13
|
+
query: PgliteQuery;
|
|
14
|
+
transaction?: <T>(fn: (tx: {
|
|
15
|
+
query: PgliteQuery;
|
|
16
|
+
}) => Promise<T>) => Promise<T>;
|
|
17
|
+
};
|
|
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
|
+
|
|
21
|
+
export { RAW_DATE_PARSERS, createPglitePool };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/adapters/pglite/index.ts
|
|
2
|
+
var RAW = (value) => value;
|
|
3
|
+
var RAW_DATE_PARSERS = { 1082: RAW, 1184: RAW };
|
|
4
|
+
var createPglitePool = (db, parsers) => {
|
|
5
|
+
const options = parsers !== void 0 ? { parsers } : void 0;
|
|
6
|
+
const pool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };
|
|
7
|
+
if (db.transaction !== void 0)
|
|
8
|
+
pool.transaction = (fn) => db.transaction((tx) => fn({ query: (text, values) => tx.query(text, values, options) }));
|
|
9
|
+
return pool;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { RAW_DATE_PARSERS, createPglitePool };
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/pglite/index.ts"],"names":[],"mappings":";AA+BA,IAAM,GAAA,GAAM,CAAC,KAAA,KAA0B,KAAA;AAGhC,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;AAW1G,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\n// ═══════════════════════════════════════════════════════════════\n// PGlite → PgPool — the two-line shim every PGlite-backed app was\n// hand-rolling. Structurally typed: anything with PGlite's query\n// signature works, so this package takes NO dependency on\n// @electric-sql/pglite.\n//\n// Date handling is the one real decision here. PGlite parses date/time\n// columns into JS `Date`s, which stringify to locale noise AND can't be\n// formatted by Prism's `$date` (it wants a string/number). So app/adapter\n// pools pass RAW_DATE_PARSERS to get the raw wire strings back — while the\n// vex cache calls `.getTime()` on its own timestamp columns, so it MUST\n// keep `Date`s. Hence two pools over the same db: parsers for the adapter\n// pool, none for the cache pool.\n// ═══════════════════════════════════════════════════════════════\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 // PGlite has this natively. Optional here only so the shim still accepts a\n // narrower object — a `db` that cannot transact yields a pool that says so\n // rather than one that pretends.\n transaction?: <T>(fn: (tx: { query: PgliteQuery }) => Promise<T>) => Promise<T>;\n};\n\nconst RAW = (value: string): string => value;\n\n// DATE (OID 1082) and TIMESTAMPTZ (1184) come back as raw wire strings.\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 (a 2s sleep ran its 2.9s under a 200ms limit).\n const pool: PgPool = { query: (text, values) => db.query(text, values, options), statementTimeouts: false };\n\n // PASSED THROUGH, not reimplemented. Wrapping BEGIN/COMMIT by hand over a\n // single `query` would be wrong on a real pool — the statements could land\n // on different connections — and PGlite already pins the right one.\n //\n // Without this, every batch mutation in every app on this adapter threw.\n // Called ON `db`, not destructured off it. PGlite's `transaction` is a\n // class method that reaches for `this`; pulling it out of the object hands\n // it an undefined receiver and it dies inside the library on a property\n // nobody here has heard of.\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"]}
|