orez 0.2.25 → 0.2.27
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/cf-do/watermark.d.ts +21 -0
- package/dist/cf-do/watermark.d.ts.map +1 -0
- package/dist/cf-do/watermark.js +93 -0
- package/dist/cf-do/watermark.js.map +1 -0
- package/dist/cf-do/worker.d.ts +48 -22
- package/dist/cf-do/worker.d.ts.map +1 -1
- package/dist/cf-do/worker.js +650 -269
- package/dist/cf-do/worker.js.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/do-sql-tracking.d.ts +6 -0
- package/dist/do-sql-tracking.d.ts.map +1 -0
- package/dist/do-sql-tracking.js +14 -0
- package/dist/do-sql-tracking.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -14
- package/dist/index.js.map +1 -1
- package/dist/pg-proxy-browser.js +6 -6
- package/dist/pg-proxy-browser.js.map +1 -1
- package/dist/pg-proxy-do-backend.d.ts +98 -17
- package/dist/pg-proxy-do-backend.d.ts.map +1 -1
- package/dist/pg-proxy-do-backend.js +6075 -454
- package/dist/pg-proxy-do-backend.js.map +1 -1
- package/dist/pg-sqlite-compiler/catalog/seed.d.ts +67 -0
- package/dist/pg-sqlite-compiler/catalog/seed.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/catalog/seed.js +436 -0
- package/dist/pg-sqlite-compiler/catalog/seed.js.map +1 -0
- package/dist/pg-sqlite-compiler/index.d.ts +12 -0
- package/dist/pg-sqlite-compiler/index.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/index.js +59 -0
- package/dist/pg-sqlite-compiler/index.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/ast-utils.d.ts +48 -0
- package/dist/pg-sqlite-compiler/passes/ast-utils.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/ast-utils.js +93 -0
- package/dist/pg-sqlite-compiler/passes/ast-utils.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/catalog.d.ts +34 -0
- package/dist/pg-sqlite-compiler/passes/catalog.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/catalog.js +30 -0
- package/dist/pg-sqlite-compiler/passes/catalog.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/datetime.d.ts +21 -0
- package/dist/pg-sqlite-compiler/passes/datetime.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/datetime.js +53 -0
- package/dist/pg-sqlite-compiler/passes/datetime.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/index.d.ts +21 -0
- package/dist/pg-sqlite-compiler/passes/index.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/index.js +39 -0
- package/dist/pg-sqlite-compiler/passes/index.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/types.d.ts +41 -0
- package/dist/pg-sqlite-compiler/passes/types.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/types.js +103 -0
- package/dist/pg-sqlite-compiler/passes/types.js.map +1 -0
- package/dist/pg-sqlite-compiler/test/oracle.d.ts +34 -0
- package/dist/pg-sqlite-compiler/test/oracle.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/test/oracle.js +204 -0
- package/dist/pg-sqlite-compiler/test/oracle.js.map +1 -0
- package/dist/pg-sqlite-compiler/types.d.ts +55 -0
- package/dist/pg-sqlite-compiler/types.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/types.js +2 -0
- package/dist/pg-sqlite-compiler/types.js.map +1 -0
- package/dist/replication/change-tracker.d.ts.map +1 -1
- package/dist/replication/change-tracker.js +18 -1
- package/dist/replication/change-tracker.js.map +1 -1
- package/dist/replication/handler.d.ts.map +1 -1
- package/dist/replication/handler.js +7 -2
- package/dist/replication/handler.js.map +1 -1
- package/dist/replication/pgoutput-encoder.d.ts.map +1 -1
- package/dist/replication/pgoutput-encoder.js +72 -30
- package/dist/replication/pgoutput-encoder.js.map +1 -1
- package/dist/worker/browser-build-config.d.ts.map +1 -1
- package/dist/worker/browser-build-config.js +2 -1
- package/dist/worker/browser-build-config.js.map +1 -1
- package/dist/worker/cf-patches.d.ts +5 -2
- package/dist/worker/cf-patches.d.ts.map +1 -1
- package/dist/worker/cf-patches.js +238 -4
- package/dist/worker/cf-patches.js.map +1 -1
- package/dist/worker/shims/node-stub.d.ts +35 -0
- package/dist/worker/shims/node-stub.d.ts.map +1 -1
- package/dist/worker/shims/node-stub.js +53 -1
- package/dist/worker/shims/node-stub.js.map +1 -1
- package/dist/worker/shims/oxfmt.d.ts +4 -0
- package/dist/worker/shims/oxfmt.d.ts.map +1 -0
- package/dist/worker/shims/oxfmt.js +4 -0
- package/dist/worker/shims/oxfmt.js.map +1 -0
- package/dist/worker/shims/postgres-socket.js +1 -1
- package/dist/worker/shims/postgres-socket.js.map +1 -1
- package/dist/worker/shims/sqlite.d.ts +1 -0
- package/dist/worker/shims/sqlite.d.ts.map +1 -1
- package/dist/worker/shims/sqlite.js +229 -9
- package/dist/worker/shims/sqlite.js.map +1 -1
- package/dist/worker/shims/ws.d.ts.map +1 -1
- package/dist/worker/shims/ws.js +45 -0
- package/dist/worker/shims/ws.js.map +1 -1
- package/dist/worker/shims/zero-process-env.d.ts +2 -0
- package/dist/worker/shims/zero-process-env.d.ts.map +1 -0
- package/dist/worker/shims/zero-process-env.js +9 -0
- package/dist/worker/shims/zero-process-env.js.map +1 -0
- package/dist/worker/zero-cache-embed-cf.d.ts +29 -12
- package/dist/worker/zero-cache-embed-cf.d.ts.map +1 -1
- package/dist/worker/zero-cache-embed-cf.js +83 -14
- package/dist/worker/zero-cache-embed-cf.js.map +1 -1
- package/package.json +11 -2
- package/src/cf-do/.wrangler/cache/cf.json +1 -0
- package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite +0 -0
- package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite-shm +0 -0
- package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite-wal +0 -0
- package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/0ffaabee41a60e04dd0eb7db3073f0a40139e6a97ccd26823967acb652b89a7b.sqlite +0 -0
- package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite +0 -0
- package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite-shm +0 -0
- package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite-wal +0 -0
- package/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-insertion-facade.js +11 -0
- package/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-loader.entry.ts +134 -0
- package/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js +11 -0
- package/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-loader.entry.ts +134 -0
- package/src/cf-do/.wrangler/tmp/dev-cbILNo/worker.js +1059 -0
- package/src/cf-do/.wrangler/tmp/dev-cbILNo/worker.js.map +8 -0
- package/src/cf-do/.wrangler/tmp/dev-qbho19/worker.js +1059 -0
- package/src/cf-do/.wrangler/tmp/dev-qbho19/worker.js.map +8 -0
- package/src/cf-do/ARCHITECTURE.md +93 -0
- package/src/cf-do/CHAT_E2E.md +213 -0
- package/src/cf-do/watermark.test.ts +103 -0
- package/src/cf-do/watermark.ts +118 -0
- package/src/cf-do/worker.ts +1041 -0
- package/src/cf-do/wrangler.toml +11 -0
- package/src/cli.test.ts +3 -1
- package/src/config.ts +1 -1
- package/src/do-sql-tracking.test.ts +19 -0
- package/src/do-sql-tracking.ts +19 -0
- package/src/index.ts +29 -14
- package/src/pg-proxy-browser.ts +6 -6
- package/src/pg-proxy-do-backend.test.ts +3890 -0
- package/src/pg-proxy-do-backend.ts +6833 -482
- package/src/pg-sqlite-compiler/README.md +53 -0
- package/src/pg-sqlite-compiler/catalog/seed.ts +524 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/arithmetic.json +307 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/array.json +377 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/cast.json +12 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/catalog.json +447 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/create-table.json +32 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/datetime.json +397 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/enum.json +337 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/insert.json +337 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/json.json +537 -0
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/misc.json +1837 -0
- package/src/pg-sqlite-compiler/index.ts +73 -0
- package/src/pg-sqlite-compiler/integration.test.ts +136 -0
- package/src/pg-sqlite-compiler/passes/ast-utils.ts +113 -0
- package/src/pg-sqlite-compiler/passes/catalog.ts +65 -0
- package/src/pg-sqlite-compiler/passes/datetime.ts +74 -0
- package/src/pg-sqlite-compiler/passes/index.ts +49 -0
- package/src/pg-sqlite-compiler/passes/types.ts +156 -0
- package/src/pg-sqlite-compiler/smoke.test.ts +69 -0
- package/src/pg-sqlite-compiler/test/catalog.test.ts +171 -0
- package/src/pg-sqlite-compiler/test/corpus.test.ts +161 -0
- package/src/pg-sqlite-compiler/test/datetime.oracle.test.ts +102 -0
- package/src/pg-sqlite-compiler/test/oracle.ts +237 -0
- package/src/pg-sqlite-compiler/test/types.test.ts +109 -0
- package/src/pg-sqlite-compiler/types.ts +63 -0
- package/src/replication/change-tracker.ts +16 -1
- package/src/replication/handler.test.ts +35 -0
- package/src/replication/handler.ts +7 -2
- package/src/replication/pgoutput-encoder.test.ts +71 -2
- package/src/replication/pgoutput-encoder.ts +65 -30
- package/src/worker/browser-build-config.test.ts +12 -0
- package/src/worker/browser-build-config.ts +2 -1
- package/src/worker/cf-patches.ts +274 -4
- package/src/worker/shims/node-stub.ts +53 -1
- package/src/worker/shims/oxfmt.ts +3 -0
- package/src/worker/shims/postgres-socket.ts +1 -1
- package/src/worker/shims/sqlite.test.ts +145 -0
- package/src/worker/shims/sqlite.ts +256 -9
- package/src/worker/shims/ws.ts +45 -0
- package/src/worker/shims/zero-process-env.ts +11 -0
- package/src/worker/zero-cache-embed-cf.ts +114 -18
- package/src/query-rewrites.test.ts +0 -30
- package/src/query-rewrites.ts +0 -152
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AST traversal helpers tailored to the libpg_query output.
|
|
3
|
+
*
|
|
4
|
+
* The official @pgsql/traverse offers two APIs:
|
|
5
|
+
*
|
|
6
|
+
* walk() — uses a runtime schema; recurses into both tag-wrapped nodes
|
|
7
|
+
* ({SelectStmt:...}) AND unwrapped sub-fields (ColumnDef.typeName
|
|
8
|
+
* is *not* tag-wrapped — it's a plain object). Good for traversal,
|
|
9
|
+
* but mutation requires keyPath bookkeeping.
|
|
10
|
+
*
|
|
11
|
+
* visit() — only recurses into tag-wrapped objects with exactly one key.
|
|
12
|
+
* Misses non-wrapped sub-fields like typeName.
|
|
13
|
+
*
|
|
14
|
+
* For our compiler passes we want: "visit every node of a given tag, AND
|
|
15
|
+
* also visit unwrapped sub-objects that have a known tag-like field set."
|
|
16
|
+
* The simplest reliable approach is a hand-rolled walk: recurse over every
|
|
17
|
+
* object/array, fire callbacks keyed by either (a) the tag wrapper key, or
|
|
18
|
+
* (b) the parent field-name for in-place node types we want to visit
|
|
19
|
+
* (typeName etc.).
|
|
20
|
+
*
|
|
21
|
+
* Each callback gets `(node, parent, key)` so mutation is local: just
|
|
22
|
+
* reassign `parent[key]` (for tag-wrapped) or mutate `node` in place (for
|
|
23
|
+
* unwrapped sub-fields).
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Unwrapped fields: child-key → semantic tag name. When a node has a child
|
|
27
|
+
* field with one of these names whose value is a plain object (no tag wrapper),
|
|
28
|
+
* we fire the corresponding visitor against that value.
|
|
29
|
+
*/
|
|
30
|
+
const UNWRAPPED_FIELDS = {
|
|
31
|
+
// ColumnDef.typeName, TypeCast.typeName, etc. are TypeName nodes, not wrapped
|
|
32
|
+
typeName: 'TypeName',
|
|
33
|
+
// SelectStmt.fromClause[i] is sometimes a wrapped RangeVar but in some
|
|
34
|
+
// sub-positions (FROM-list with single table) it appears unwrapped.
|
|
35
|
+
relation: 'RangeVar',
|
|
36
|
+
};
|
|
37
|
+
function fireForChild(visitors, childKey, childValue, parent) {
|
|
38
|
+
const tag = UNWRAPPED_FIELDS[childKey];
|
|
39
|
+
if (!tag)
|
|
40
|
+
return;
|
|
41
|
+
if (!childValue || typeof childValue !== 'object' || Array.isArray(childValue))
|
|
42
|
+
return;
|
|
43
|
+
const cb = visitors[tag];
|
|
44
|
+
if (cb)
|
|
45
|
+
cb(childValue, parent, childKey);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Walk a node tree firing callbacks. For tag-wrapped nodes ({Tag: data}),
|
|
49
|
+
* the callback fires on `data` (inner) with parent=the wrapper's parent,
|
|
50
|
+
* key=where the wrapper sits. For unwrapped sub-fields (typeName etc.),
|
|
51
|
+
* fires on the object directly with parent=its container, key=field name.
|
|
52
|
+
*
|
|
53
|
+
* Mutation rules:
|
|
54
|
+
* - tag-wrapped: assign `parent[key] = newWrapper` to replace the node
|
|
55
|
+
* - unwrapped: mutate `node` in place (it's already the live object)
|
|
56
|
+
*/
|
|
57
|
+
export function walkAst(root, visitors) {
|
|
58
|
+
function recurse(node, parent, key) {
|
|
59
|
+
if (node == null || typeof node !== 'object')
|
|
60
|
+
return;
|
|
61
|
+
if (Array.isArray(node)) {
|
|
62
|
+
for (let i = 0; i < node.length; i++)
|
|
63
|
+
recurse(node[i], node, i);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const keys = Object.keys(node);
|
|
67
|
+
// Tag-wrapper case: {Tag: data}
|
|
68
|
+
if (keys.length === 1 && /^[A-Z]/.test(keys[0])) {
|
|
69
|
+
const tag = keys[0];
|
|
70
|
+
const data = node[tag];
|
|
71
|
+
const cb = visitors[tag];
|
|
72
|
+
if (cb)
|
|
73
|
+
cb(data, parent, key);
|
|
74
|
+
// recurse into the inner data
|
|
75
|
+
if (data && typeof data === 'object') {
|
|
76
|
+
for (const childKey of Object.keys(data)) {
|
|
77
|
+
// fire unwrapped-field visitors BEFORE recursing into the field
|
|
78
|
+
fireForChild(visitors, childKey, data[childKey], data);
|
|
79
|
+
recurse(data[childKey], data, childKey);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Non-wrapper object case (already an unwrapped sub-tree). Recurse,
|
|
85
|
+
// firing unwrapped-field visitors as we encounter named child fields.
|
|
86
|
+
for (const childKey of keys) {
|
|
87
|
+
fireForChild(visitors, childKey, node[childKey], node);
|
|
88
|
+
recurse(node[childKey], node, childKey);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
recurse(root, null, '');
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=ast-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/ast-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAgBH;;;;GAIG;AACH,MAAM,gBAAgB,GAA2B;IAC/C,8EAA8E;IAC9E,QAAQ,EAAE,UAAU;IACpB,uEAAuE;IACvE,oEAAoE;IACpE,QAAQ,EAAE,UAAU;CACrB,CAAA;AAED,SAAS,YAAY,CACnB,QAAoB,EACpB,QAAgB,EAChB,UAAe,EACf,MAAW;IAEX,MAAM,GAAG,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IACtC,IAAI,CAAC,GAAG;QAAE,OAAM;IAChB,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QAAE,OAAM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C,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAA;oBACtD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;gBACzC,CAAC;YACH,CAAC;YACD,OAAM;QACR,CAAC;QAED,oEAAoE;QACpE,sEAAsE;QACtE,KAAK,MAAM,QAAQ,IAAI,IAAI,EAAE,CAAC;YAC5B,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAA;YACtD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAI,EAAE,IAAW,EAAE,EAAS,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Catalog pass.
|
|
3
|
+
*
|
|
4
|
+
* Rewrites schema-qualified PG catalog references to the
|
|
5
|
+
* `_orez_catalog__*` namespace (seeded by `catalog/seed.ts` at DO init):
|
|
6
|
+
*
|
|
7
|
+
* pg_catalog.pg_class → _orez_catalog__pg_class
|
|
8
|
+
* information_schema.columns → _orez_catalog__information_schema_columns
|
|
9
|
+
*
|
|
10
|
+
* Why this matters:
|
|
11
|
+
* zero-cache (and most PG client libraries) probes the PG system catalog
|
|
12
|
+
* on startup. They always qualify these references with `pg_catalog.` or
|
|
13
|
+
* `information_schema.` — that's how `search_path` resolution works in PG
|
|
14
|
+
* and how every generated catalog query (libpq, psql, postgres.js) emits
|
|
15
|
+
* them.
|
|
16
|
+
*
|
|
17
|
+
* Why we DON'T rewrite bare `pg_class` (no schema):
|
|
18
|
+
* - it's user-table-namespace ambiguous (an app could legitimately call
|
|
19
|
+
* a table `pg_user`, `pg_views`, etc.)
|
|
20
|
+
* - bare catalog refs only resolve in PG via search_path; clients
|
|
21
|
+
* emitting catalog queries qualify them explicitly. Bare references in
|
|
22
|
+
* real apps are essentially always user tables.
|
|
23
|
+
* - silently hijacking them caused WRITE-path bugs (DML against a user
|
|
24
|
+
* table got routed to a synthetic catalog table) in earlier iterations
|
|
25
|
+
*
|
|
26
|
+
* If a future workload sends bare catalog refs we'll add a per-statement
|
|
27
|
+
* opt-in (e.g. `WHERE rewrite_unqualified_catalog`) rather than a
|
|
28
|
+
* footgun-prone global toggle.
|
|
29
|
+
*
|
|
30
|
+
* Companion module: `catalog/seed.ts` creates the target tables on DO init.
|
|
31
|
+
*/
|
|
32
|
+
import type { Pass } from '../types.js';
|
|
33
|
+
export declare const catalogPass: Pass;
|
|
34
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/catalog.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAqBvC,eAAO,MAAM,WAAW,EAAE,IAUzB,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { walkAst } from './ast-utils.js';
|
|
2
|
+
const CATALOG_PREFIX = '_orez_catalog__';
|
|
3
|
+
const FLATTENED_SCHEMAS = new Set(['information_schema']);
|
|
4
|
+
function rewriteRangeVar(node) {
|
|
5
|
+
// pg_catalog.X — strip schema, prefix relname
|
|
6
|
+
if (node.schemaname === 'pg_catalog') {
|
|
7
|
+
node.relname = `${CATALOG_PREFIX}${node.relname}`;
|
|
8
|
+
delete node.schemaname;
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
// information_schema.X — flatten to _orez_catalog__information_schema_X
|
|
12
|
+
if (FLATTENED_SCHEMAS.has(node.schemaname)) {
|
|
13
|
+
node.relname = `${CATALOG_PREFIX}${node.schemaname}_${node.relname}`;
|
|
14
|
+
delete node.schemaname;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const catalogPass = {
|
|
19
|
+
name: 'catalog',
|
|
20
|
+
run(rawStmt, _ctx) {
|
|
21
|
+
walkAst(rawStmt, {
|
|
22
|
+
RangeVar: (node) => {
|
|
23
|
+
if (!node || typeof node !== 'object')
|
|
24
|
+
return;
|
|
25
|
+
rewriteRangeVar(node);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAmCxC,MAAM,cAAc,GAAG,iBAAiB,CAAA;AACxC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAA;AAEzD,SAAS,eAAe,CAAC,IAAS;IAChC,8CAA8C;IAC9C,IAAI,IAAI,CAAC,UAAU,KAAK,YAAY,EAAE,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,GAAG,cAAc,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QACjD,OAAO,IAAI,CAAC,UAAU,CAAA;QACtB,OAAM;IACR,CAAC;IAED,wEAAwE;IACxE,IAAI,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC,OAAO,GAAG,GAAG,cAAc,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,EAAE,CAAA;QACpE,OAAO,IAAI,CAAC,UAAU,CAAA;QACtB,OAAM;IACR,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAS;IAC/B,IAAI,EAAE,SAAS;IACf,GAAG,CAAC,OAAO,EAAE,IAAI;QACf,OAAO,CAAC,OAAO,EAAE;YACf,QAAQ,EAAE,CAAC,IAAS,EAAE,EAAE;gBACtB,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;oBAAE,OAAM;gBAC7C,eAAe,CAAC,IAAI,CAAC,CAAA;YACvB,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* datetime pass.
|
|
3
|
+
*
|
|
4
|
+
* Rewrites PG datetime functions to SQLite-native equivalents:
|
|
5
|
+
* NOW() → CURRENT_TIMESTAMP (function call → keyword)
|
|
6
|
+
* CURRENT_TIMESTAMP() → CURRENT_TIMESTAMP (if it ever parses as a FuncCall)
|
|
7
|
+
* CURRENT_DATE() → CURRENT_DATE
|
|
8
|
+
* CURRENT_TIME() → CURRENT_TIME
|
|
9
|
+
* pg_catalog.now() → CURRENT_TIMESTAMP
|
|
10
|
+
*
|
|
11
|
+
* Why it matters: in SQLite, `DEFAULT NOW()` is rejected because column
|
|
12
|
+
* defaults only accept a small expression grammar. `DEFAULT CURRENT_TIMESTAMP`
|
|
13
|
+
* is accepted everywhere (and is what every "I want NOW() in a default" PG
|
|
14
|
+
* user actually wants).
|
|
15
|
+
*
|
|
16
|
+
* For richer datetime work (EXTRACT, DATE_TRUNC, INTERVAL arithmetic) we'll
|
|
17
|
+
* extend this pass in follow-ups. v1 covers the high-frequency cases.
|
|
18
|
+
*/
|
|
19
|
+
import type { Pass } from '../types.js';
|
|
20
|
+
export declare const datetimePass: Pass;
|
|
21
|
+
//# sourceMappingURL=datetime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/datetime.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAuBvC,eAAO,MAAM,YAAY,EAAE,IA8B1B,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { walkAst } from './ast-utils.js';
|
|
2
|
+
function lowerFuncName(funcname) {
|
|
3
|
+
if (!funcname || funcname.length === 0)
|
|
4
|
+
return undefined;
|
|
5
|
+
const last = funcname[funcname.length - 1];
|
|
6
|
+
const str = last?.String?.sval ?? last?.String?.str;
|
|
7
|
+
return typeof str === 'string' ? str.toLowerCase() : undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Build a PG `SQLValueFunction` node — this is the canonical AST representation
|
|
11
|
+
* of bareword time keywords like CURRENT_TIMESTAMP / CURRENT_DATE / CURRENT_TIME.
|
|
12
|
+
* The deparser emits these as bareword keywords (no quotes, no parens), and
|
|
13
|
+
* SQLite accepts CURRENT_TIMESTAMP/CURRENT_DATE/CURRENT_TIME as keywords too.
|
|
14
|
+
*/
|
|
15
|
+
function svfWrapper(op) {
|
|
16
|
+
return {
|
|
17
|
+
SQLValueFunction: { op, typmod: -1, location: 0 },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export const datetimePass = {
|
|
21
|
+
name: 'datetime',
|
|
22
|
+
run(rawStmt, _ctx) {
|
|
23
|
+
walkAst(rawStmt, {
|
|
24
|
+
FuncCall: (node, parent, key) => {
|
|
25
|
+
if (parent == null)
|
|
26
|
+
return; // can't replace a root-positioned FuncCall
|
|
27
|
+
const name = lowerFuncName(node.funcname);
|
|
28
|
+
if (!name)
|
|
29
|
+
return;
|
|
30
|
+
const argless = !node.args || (Array.isArray(node.args) && node.args.length === 0);
|
|
31
|
+
if (!argless)
|
|
32
|
+
return;
|
|
33
|
+
// Map PG datetime function calls → SQL bareword time keywords. The PG
|
|
34
|
+
// AST distinguishes function-form (`now()`) from keyword-form
|
|
35
|
+
// (`CURRENT_TIMESTAMP`) at the parse level; SQLite only accepts the
|
|
36
|
+
// keyword form in DEFAULT clauses and uniformly elsewhere.
|
|
37
|
+
if (name === 'now' || name === 'current_timestamp') {
|
|
38
|
+
parent[key] = svfWrapper('SVFOP_CURRENT_TIMESTAMP');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (name === 'current_date') {
|
|
42
|
+
parent[key] = svfWrapper('SVFOP_CURRENT_DATE');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (name === 'current_time') {
|
|
46
|
+
parent[key] = svfWrapper('SVFOP_CURRENT_TIME');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=datetime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datetime.js","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/datetime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAsBxC,SAAS,aAAa,CAAC,QAA2B;IAChD,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IACxD,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC1C,MAAM,GAAG,GAAG,IAAI,EAAE,MAAM,EAAE,IAAI,IAAI,IAAI,EAAE,MAAM,EAAE,GAAG,CAAA;IACnD,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AAChE,CAAC;AAED;;;;;GAKG;AACH,SAAS,UAAU,CAAC,EAAU;IAG5B,OAAO;QACL,gBAAgB,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE;KAClD,CAAA;AACH,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAA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+
* to make the tree SQLite-emittable. Order matters: type normalization runs
|
|
6
|
+
* first (so other passes see SQLite-native type names), datetime runs after
|
|
7
|
+
* (function-form → SQLValueFunction), catalog rewrites last (after every
|
|
8
|
+
* other pass has stabilized).
|
|
9
|
+
*/
|
|
10
|
+
import type { Pass, PassContext } from '../types.js';
|
|
11
|
+
export declare const DEFAULT_PASSES: Pass[];
|
|
12
|
+
/**
|
|
13
|
+
* Run all passes on a single top-level RawStmt entry.
|
|
14
|
+
*
|
|
15
|
+
* Input shape: `{ stmt: { TagName: data } }` (a libpg_query RawStmt).
|
|
16
|
+
* Passes use `walkAst()` (in passes/ast-utils.ts) which expects a tag-wrapped
|
|
17
|
+
* node — so we hand them `rawStmt.stmt`, the inner `{ TagName: data }`.
|
|
18
|
+
* Callbacks receive (data, parent, key) and mutate via `parent[key] = ...`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function runPasses(rawStmt: any, ctx: PassContext): void;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEpD,eAAO,MAAM,cAAc,EAAE,IAAI,EAShC,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAc9D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { catalogPass } from './catalog.js';
|
|
2
|
+
import { datetimePass } from './datetime.js';
|
|
3
|
+
import { typesPass } from './types.js';
|
|
4
|
+
export const DEFAULT_PASSES = [
|
|
5
|
+
typesPass,
|
|
6
|
+
datetimePass,
|
|
7
|
+
catalogPass,
|
|
8
|
+
// future:
|
|
9
|
+
// castPass,
|
|
10
|
+
// arrayPass,
|
|
11
|
+
// jsonPass,
|
|
12
|
+
// insertPass,
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Run all passes on a single top-level RawStmt entry.
|
|
16
|
+
*
|
|
17
|
+
* Input shape: `{ stmt: { TagName: data } }` (a libpg_query RawStmt).
|
|
18
|
+
* Passes use `walkAst()` (in passes/ast-utils.ts) which expects a tag-wrapped
|
|
19
|
+
* node — so we hand them `rawStmt.stmt`, the inner `{ TagName: data }`.
|
|
20
|
+
* Callbacks receive (data, parent, key) and mutate via `parent[key] = ...`.
|
|
21
|
+
*/
|
|
22
|
+
export function runPasses(rawStmt, ctx) {
|
|
23
|
+
const stmt = rawStmt?.stmt ?? rawStmt;
|
|
24
|
+
if (!stmt || typeof stmt !== 'object')
|
|
25
|
+
return;
|
|
26
|
+
const passes = ctx.passes ?? DEFAULT_PASSES;
|
|
27
|
+
for (const pass of passes) {
|
|
28
|
+
try {
|
|
29
|
+
pass.run(stmt, ctx);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
ctx.warnings.push({
|
|
33
|
+
kind: 'pass-error',
|
|
34
|
+
message: `pass ${pass.name} threw: ${err.message}`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAatC,MAAM,CAAC,MAAM,cAAc,GAAW;IACpC,SAAS;IACT,YAAY;IACZ,WAAW;IACX,UAAU;IACV,cAAc;IACd,eAAe;IACf,cAAc;IACd,gBAAgB;CACjB,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,OAAY,EAAE,GAAgB;IACtD,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,OAAO,CAAA;IACrC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAM;IAC7C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,cAAc,CAAA;IAC3C,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QACrB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,QAAQ,IAAI,CAAC,IAAI,WAAW,GAAG,CAAC,OAAO,EAAE;aACnD,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types pass.
|
|
3
|
+
*
|
|
4
|
+
* Normalizes PG type names in CREATE TABLE / ALTER TABLE / CAST / column
|
|
5
|
+
* defs to SQLite-compatible equivalents:
|
|
6
|
+
*
|
|
7
|
+
* bigserial / serial → INTEGER (and PRIMARY KEY on INTEGER becomes
|
|
8
|
+
* SQLite's rowid alias, equivalent to
|
|
9
|
+
* AUTOINCREMENT for our purposes)
|
|
10
|
+
* smallserial → INTEGER
|
|
11
|
+
* jsonb / json → TEXT (stored as JSON text; SQLite json
|
|
12
|
+
* functions operate on TEXT directly)
|
|
13
|
+
* uuid → TEXT
|
|
14
|
+
* bytea → BLOB
|
|
15
|
+
* varchar / character varying → TEXT (drop length typmods)
|
|
16
|
+
* char(N) / character(N)→ TEXT (drop length typmods)
|
|
17
|
+
* text → TEXT
|
|
18
|
+
* timestamp / timestamptz / timestamp with time zone → TEXT
|
|
19
|
+
* (stored as ISO; SQLite datetime fns
|
|
20
|
+
* accept ISO text)
|
|
21
|
+
* date / time / timetz → TEXT
|
|
22
|
+
* interval → TEXT
|
|
23
|
+
* numeric / decimal → NUMERIC (SQLite native affinity; precision/
|
|
24
|
+
* scale typmods dropped)
|
|
25
|
+
* real / float4 → REAL
|
|
26
|
+
* double precision / float8 → REAL
|
|
27
|
+
* integer / int / int4 → INTEGER
|
|
28
|
+
* bigint / int8 → INTEGER
|
|
29
|
+
* smallint / int2 → INTEGER
|
|
30
|
+
* boolean → INTEGER (0/1; SQLite has no BOOLEAN type but
|
|
31
|
+
* the BOOLEAN keyword is accepted as
|
|
32
|
+
* affinity)
|
|
33
|
+
*
|
|
34
|
+
* Array types (any T[] with arrayBounds) become TEXT (stored as JSON arrays).
|
|
35
|
+
*
|
|
36
|
+
* pg_catalog.* prefix is stripped (libpg-query adds it canonically; SQLite
|
|
37
|
+
* doesn't know about pg_catalog).
|
|
38
|
+
*/
|
|
39
|
+
import type { Pass } from '../types.js';
|
|
40
|
+
export declare const typesPass: Pass;
|
|
41
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/types.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AA0FvC,eAAO,MAAM,SAAS,EAAE,IAyBvB,CAAA"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { walkAst } from './ast-utils.js';
|
|
2
|
+
const TYPE_MAP = {
|
|
3
|
+
// serial → integer (PRIMARY KEY on INTEGER is rowid alias in SQLite)
|
|
4
|
+
bigserial: 'INTEGER',
|
|
5
|
+
serial: 'INTEGER',
|
|
6
|
+
serial4: 'INTEGER',
|
|
7
|
+
serial8: 'INTEGER',
|
|
8
|
+
smallserial: 'INTEGER',
|
|
9
|
+
serial2: 'INTEGER',
|
|
10
|
+
// integer
|
|
11
|
+
int: 'INTEGER',
|
|
12
|
+
integer: 'INTEGER',
|
|
13
|
+
int2: 'INTEGER',
|
|
14
|
+
int4: 'INTEGER',
|
|
15
|
+
int8: 'INTEGER',
|
|
16
|
+
bigint: 'INTEGER',
|
|
17
|
+
smallint: 'INTEGER',
|
|
18
|
+
// floats
|
|
19
|
+
real: 'REAL',
|
|
20
|
+
float4: 'REAL',
|
|
21
|
+
float8: 'REAL',
|
|
22
|
+
'double precision': 'REAL',
|
|
23
|
+
double: 'REAL',
|
|
24
|
+
// numerics — keep affinity name; SQLite parses but ignores precision
|
|
25
|
+
numeric: 'NUMERIC',
|
|
26
|
+
decimal: 'NUMERIC',
|
|
27
|
+
// text-ish
|
|
28
|
+
text: 'TEXT',
|
|
29
|
+
varchar: 'TEXT',
|
|
30
|
+
'character varying': 'TEXT',
|
|
31
|
+
bpchar: 'TEXT',
|
|
32
|
+
character: 'TEXT',
|
|
33
|
+
char: 'TEXT',
|
|
34
|
+
name: 'TEXT',
|
|
35
|
+
citext: 'TEXT',
|
|
36
|
+
// json / structured
|
|
37
|
+
json: 'TEXT',
|
|
38
|
+
jsonb: 'TEXT',
|
|
39
|
+
uuid: 'TEXT',
|
|
40
|
+
xml: 'TEXT',
|
|
41
|
+
// bin
|
|
42
|
+
bytea: 'BLOB',
|
|
43
|
+
// bools
|
|
44
|
+
bool: 'INTEGER',
|
|
45
|
+
boolean: 'INTEGER',
|
|
46
|
+
// time
|
|
47
|
+
timestamp: 'TEXT',
|
|
48
|
+
timestamptz: 'TEXT',
|
|
49
|
+
'timestamp with time zone': 'TEXT',
|
|
50
|
+
'timestamp without time zone': 'TEXT',
|
|
51
|
+
date: 'TEXT',
|
|
52
|
+
time: 'TEXT',
|
|
53
|
+
timetz: 'TEXT',
|
|
54
|
+
'time with time zone': 'TEXT',
|
|
55
|
+
'time without time zone': 'TEXT',
|
|
56
|
+
interval: 'TEXT',
|
|
57
|
+
// network / ranges → TEXT for storage compatibility
|
|
58
|
+
inet: 'TEXT',
|
|
59
|
+
cidr: 'TEXT',
|
|
60
|
+
macaddr: 'TEXT',
|
|
61
|
+
macaddr8: 'TEXT',
|
|
62
|
+
money: 'NUMERIC',
|
|
63
|
+
};
|
|
64
|
+
function extractName(names) {
|
|
65
|
+
if (!Array.isArray(names) || names.length === 0)
|
|
66
|
+
return undefined;
|
|
67
|
+
// strip pg_catalog. prefix if present
|
|
68
|
+
const last = names[names.length - 1];
|
|
69
|
+
const sval = last?.String?.sval ?? last?.String?.str;
|
|
70
|
+
return typeof sval === 'string' ? sval.toLowerCase() : undefined;
|
|
71
|
+
}
|
|
72
|
+
function setTypeName(typeName, sqliteName) {
|
|
73
|
+
typeName.names = [{ String: { sval: sqliteName } }];
|
|
74
|
+
// drop length/precision typmods
|
|
75
|
+
delete typeName.typmods;
|
|
76
|
+
// drop array bounds (SQLite has no array type; we store as JSON text)
|
|
77
|
+
delete typeName.arrayBounds;
|
|
78
|
+
}
|
|
79
|
+
export const typesPass = {
|
|
80
|
+
name: 'types',
|
|
81
|
+
run(rawStmt, _ctx) {
|
|
82
|
+
walkAst(rawStmt, {
|
|
83
|
+
TypeName: (node) => {
|
|
84
|
+
const pgName = extractName(node.names);
|
|
85
|
+
if (!pgName)
|
|
86
|
+
return;
|
|
87
|
+
const hasArrayBounds = Array.isArray(node.arrayBounds) && node.arrayBounds.length > 0;
|
|
88
|
+
// Array of anything → TEXT
|
|
89
|
+
if (hasArrayBounds) {
|
|
90
|
+
setTypeName(node, 'TEXT');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const sqliteName = TYPE_MAP[pgName];
|
|
94
|
+
if (sqliteName) {
|
|
95
|
+
setTypeName(node, sqliteName);
|
|
96
|
+
}
|
|
97
|
+
// Unknown types we leave alone — let SQLite reject loudly so we know
|
|
98
|
+
// to add a mapping.
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AA0CxC,MAAM,QAAQ,GAA2B;IACvC,qEAAqE;IACrE,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,SAAS;IACtB,OAAO,EAAE,SAAS;IAElB,UAAU;IACV,GAAG,EAAE,SAAS;IACd,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,SAAS;IAEnB,SAAS;IACT,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;IACd,kBAAkB,EAAE,MAAM;IAC1B,MAAM,EAAE,MAAM;IAEd,qEAAqE;IACrE,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAElB,WAAW;IACX,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,MAAM;IACf,mBAAmB,EAAE,MAAM;IAC3B,MAAM,EAAE,MAAM;IACd,SAAS,EAAE,MAAM;IACjB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;IAEd,oBAAoB;IACpB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,MAAM;IAEX,MAAM;IACN,KAAK,EAAE,MAAM;IAEb,QAAQ;IACR,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAElB,OAAO;IACP,SAAS,EAAE,MAAM;IACjB,WAAW,EAAE,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AE,EAAE;gBACtB,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACtC,IAAI,CAAC,MAAM;oBAAE,OAAM;gBACnB,MAAM,cAAc,GAClB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAA;gBAEhE,2BAA2B;gBAC3B,IAAI,cAAc,EAAE,CAAC;oBACnB,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;oBACzB,OAAM;gBACR,CAAC;gBAED,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAA;gBACnC,IAAI,UAAU,EAAE,CAAC;oBACf,WAAW,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;gBAC/B,CAAC;gBACD,qEAAqE;gBACrE,oBAAoB;YACtB,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare function pgsqliteBinPath(): string | null;
|
|
2
|
+
export declare const ORACLE_AVAILABLE: boolean;
|
|
3
|
+
export interface OracleServer {
|
|
4
|
+
port: number;
|
|
5
|
+
dbPath: string;
|
|
6
|
+
stop(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Start a pgsqlite server on an OS-assigned ephemeral port with an ephemeral
|
|
10
|
+
* database. Throws on probe timeout. Caller is responsible for calling
|
|
11
|
+
* `stop()` in a `finally` / `afterAll` hook — `stop()` awaits child exit
|
|
12
|
+
* and cleans up the tempdir.
|
|
13
|
+
*/
|
|
14
|
+
export declare function startPgsqliteServer(): Promise<OracleServer>;
|
|
15
|
+
/**
|
|
16
|
+
* Helper: open a postgres.js client to a running pgsqlite server.
|
|
17
|
+
* Requires `postgres` to be available (we already ship it via @rocicorp/zero).
|
|
18
|
+
*/
|
|
19
|
+
export declare function connectOracle(server: OracleServer): Promise<{
|
|
20
|
+
exec: (sql: string, params?: any[]) => Promise<any[]>;
|
|
21
|
+
end: () => Promise<void>;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Run the same query against pgsqlite (oracle) and our compiler+SQLite (under
|
|
25
|
+
* test). Return both result sets so the test can diff them however it wants.
|
|
26
|
+
*
|
|
27
|
+
* Uses freshly-spawned servers/dbs for each call — slow but isolated. For
|
|
28
|
+
* batches use the lower-level helpers above.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runOracleAndCompiler(setupSql: string[], pgSql: string, params?: any[]): Promise<{
|
|
31
|
+
oracle: any[];
|
|
32
|
+
ours: any[];
|
|
33
|
+
}>;
|
|
34
|
+
//# sourceMappingURL=oracle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oracle.d.ts","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/test/oracle.ts"],"names":[],"mappings":"AA8BA,wBAAgB,eAAe,IAAI,MAAM,GAAG,IAAI,CAI/C;AAED,eAAO,MAAM,gBAAgB,SAA6B,CAAA;AAE1D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAgDD;;;;;GAKG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,YAAY,CAAC,CA8DjE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC;IACjE,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IACrD,GAAG,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB,CAAC,CAsBD;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAAE,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,GAAG,EAAO,GACjB,OAAO,CAAC;IACT,MAAM,EAAE,GAAG,EAAE,CAAA;IACb,IAAI,EAAE,GAAG,EAAE,CAAA;CACZ,CAAC,CA+BD"}
|