orez 0.2.26 → 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.
Files changed (103) hide show
  1. package/dist/cf-do/worker.d.ts.map +1 -1
  2. package/dist/cf-do/worker.js +9 -1
  3. package/dist/cf-do/worker.js.map +1 -1
  4. package/dist/pg-proxy-do-backend.d.ts +2 -0
  5. package/dist/pg-proxy-do-backend.d.ts.map +1 -1
  6. package/dist/pg-proxy-do-backend.js +49 -7
  7. package/dist/pg-proxy-do-backend.js.map +1 -1
  8. package/dist/pg-sqlite-compiler/catalog/seed.d.ts +67 -0
  9. package/dist/pg-sqlite-compiler/catalog/seed.d.ts.map +1 -0
  10. package/dist/pg-sqlite-compiler/catalog/seed.js +436 -0
  11. package/dist/pg-sqlite-compiler/catalog/seed.js.map +1 -0
  12. package/dist/pg-sqlite-compiler/index.d.ts +12 -0
  13. package/dist/pg-sqlite-compiler/index.d.ts.map +1 -0
  14. package/dist/pg-sqlite-compiler/index.js +59 -0
  15. package/dist/pg-sqlite-compiler/index.js.map +1 -0
  16. package/dist/pg-sqlite-compiler/passes/ast-utils.d.ts +48 -0
  17. package/dist/pg-sqlite-compiler/passes/ast-utils.d.ts.map +1 -0
  18. package/dist/pg-sqlite-compiler/passes/ast-utils.js +93 -0
  19. package/dist/pg-sqlite-compiler/passes/ast-utils.js.map +1 -0
  20. package/dist/pg-sqlite-compiler/passes/catalog.d.ts +34 -0
  21. package/dist/pg-sqlite-compiler/passes/catalog.d.ts.map +1 -0
  22. package/dist/pg-sqlite-compiler/passes/catalog.js +30 -0
  23. package/dist/pg-sqlite-compiler/passes/catalog.js.map +1 -0
  24. package/dist/pg-sqlite-compiler/passes/datetime.d.ts +21 -0
  25. package/dist/pg-sqlite-compiler/passes/datetime.d.ts.map +1 -0
  26. package/dist/pg-sqlite-compiler/passes/datetime.js +53 -0
  27. package/dist/pg-sqlite-compiler/passes/datetime.js.map +1 -0
  28. package/dist/pg-sqlite-compiler/passes/index.d.ts +21 -0
  29. package/dist/pg-sqlite-compiler/passes/index.d.ts.map +1 -0
  30. package/dist/pg-sqlite-compiler/passes/index.js +39 -0
  31. package/dist/pg-sqlite-compiler/passes/index.js.map +1 -0
  32. package/dist/pg-sqlite-compiler/passes/types.d.ts +41 -0
  33. package/dist/pg-sqlite-compiler/passes/types.d.ts.map +1 -0
  34. package/dist/pg-sqlite-compiler/passes/types.js +103 -0
  35. package/dist/pg-sqlite-compiler/passes/types.js.map +1 -0
  36. package/dist/pg-sqlite-compiler/test/oracle.d.ts +34 -0
  37. package/dist/pg-sqlite-compiler/test/oracle.d.ts.map +1 -0
  38. package/dist/pg-sqlite-compiler/test/oracle.js +204 -0
  39. package/dist/pg-sqlite-compiler/test/oracle.js.map +1 -0
  40. package/dist/pg-sqlite-compiler/types.d.ts +55 -0
  41. package/dist/pg-sqlite-compiler/types.d.ts.map +1 -0
  42. package/dist/pg-sqlite-compiler/types.js +2 -0
  43. package/dist/pg-sqlite-compiler/types.js.map +1 -0
  44. package/package.json +7 -2
  45. package/src/cf-do/.wrangler/cache/cf.json +1 -1
  46. package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite-shm +0 -0
  47. package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite-wal +0 -0
  48. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite-shm +0 -0
  49. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite-wal +0 -0
  50. package/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-insertion-facade.js +11 -0
  51. package/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-loader.entry.ts +134 -0
  52. package/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js +11 -0
  53. package/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-loader.entry.ts +134 -0
  54. package/src/cf-do/.wrangler/tmp/dev-cbILNo/worker.js +1059 -0
  55. package/src/cf-do/.wrangler/tmp/dev-cbILNo/worker.js.map +8 -0
  56. package/src/cf-do/.wrangler/tmp/dev-qbho19/worker.js +1059 -0
  57. package/src/cf-do/.wrangler/tmp/dev-qbho19/worker.js.map +8 -0
  58. package/src/cf-do/ARCHITECTURE.md +10 -0
  59. package/src/cf-do/CHAT_E2E.md +213 -0
  60. package/src/cf-do/worker.ts +11 -3
  61. package/src/cli.test.ts +3 -1
  62. package/src/pg-proxy-do-backend.ts +44 -10
  63. package/src/pg-sqlite-compiler/README.md +53 -0
  64. package/src/pg-sqlite-compiler/catalog/seed.ts +524 -0
  65. package/src/pg-sqlite-compiler/fixtures/pgsqlite/arithmetic.json +307 -0
  66. package/src/pg-sqlite-compiler/fixtures/pgsqlite/array.json +377 -0
  67. package/src/pg-sqlite-compiler/fixtures/pgsqlite/cast.json +12 -0
  68. package/src/pg-sqlite-compiler/fixtures/pgsqlite/catalog.json +447 -0
  69. package/src/pg-sqlite-compiler/fixtures/pgsqlite/create-table.json +32 -0
  70. package/src/pg-sqlite-compiler/fixtures/pgsqlite/datetime.json +397 -0
  71. package/src/pg-sqlite-compiler/fixtures/pgsqlite/enum.json +337 -0
  72. package/src/pg-sqlite-compiler/fixtures/pgsqlite/insert.json +337 -0
  73. package/src/pg-sqlite-compiler/fixtures/pgsqlite/json.json +537 -0
  74. package/src/pg-sqlite-compiler/fixtures/pgsqlite/misc.json +1837 -0
  75. package/src/pg-sqlite-compiler/index.ts +73 -0
  76. package/src/pg-sqlite-compiler/integration.test.ts +136 -0
  77. package/src/pg-sqlite-compiler/passes/ast-utils.ts +113 -0
  78. package/src/pg-sqlite-compiler/passes/catalog.ts +65 -0
  79. package/src/pg-sqlite-compiler/passes/datetime.ts +74 -0
  80. package/src/pg-sqlite-compiler/passes/index.ts +49 -0
  81. package/src/pg-sqlite-compiler/passes/types.ts +156 -0
  82. package/src/pg-sqlite-compiler/smoke.test.ts +69 -0
  83. package/src/pg-sqlite-compiler/test/catalog.test.ts +171 -0
  84. package/src/pg-sqlite-compiler/test/corpus.test.ts +161 -0
  85. package/src/pg-sqlite-compiler/test/datetime.oracle.test.ts +102 -0
  86. package/src/pg-sqlite-compiler/test/oracle.ts +237 -0
  87. package/src/pg-sqlite-compiler/test/types.test.ts +109 -0
  88. package/src/pg-sqlite-compiler/types.ts +63 -0
  89. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/0f0f3bdf0abda097eb6f1246db4657d9fc622081362d894d82c1a1ce067b05b6.sqlite +0 -0
  90. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/1ddd3a4a48a11b51658444f5458a1fb175194b1d5b6a5bda20ef3fe3205b900c.sqlite +0 -0
  91. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/3835f242df9728adba3d127a238793fd054ed3e51df3f60749ee744c469bf2a2.sqlite +0 -0
  92. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/4aa9c80eb716cf55b8995ccf7afab0b36c683e6da07d7c37a3f9c570136036df.sqlite +0 -0
  93. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/533e2fd1d6ea46e7a9a0017916ef341802d438d72583462755f2c1f8225e9bf2.sqlite +0 -0
  94. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/5ffa1aced1225ecaeac6366f7586aa3de92761cdff8711d81fbd81f248076abd.sqlite +0 -0
  95. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/686c3a9f0d7e59ed2ab607efd4b76d779c97cafeb3818380033bf7c7eb86c819.sqlite +0 -0
  96. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/6e8214e8dcfadd0deb52d64e5e9ca85c6b329ace11193909845995396914c473.sqlite +0 -0
  97. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/78d9ec9ff873d3fe3507ff53c2a6f6dfc408b4268eb0db3f2a146c0678965366.sqlite +0 -0
  98. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/7eff9f0ed7e27ad0d3f9d923de0682fab1928591172c1ba336c5f79a134a5d85.sqlite +0 -0
  99. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/836cda5b995b25867d722ed4f4c2292167e80351a3c6038db626648eb247dd8b.sqlite +0 -0
  100. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/91ef63b112209ab30172763acd8a0935106c248f7f1bcae5545ce37a9f201551.sqlite +0 -0
  101. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/a66ea4293a5f5938bc6d116edfa2522bb85bc37aea3541fbc09c3b613b9b32c0.sqlite +0 -0
  102. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/ceb2ab26b80590840b65651deb6e948d3bf81565c6751f3a58752cf4bf4aecae.sqlite +0 -0
  103. /package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/{204a39120310d37e972c5914cfd71ad55c151bdb9e8ed289a5f8c5b052dd60e4.sqlite → 0ffaabee41a60e04dd0eb7db3073f0a40139e6a97ccd26823967acb652b89a7b.sqlite} +0 -0
@@ -0,0 +1,204 @@
1
+ /**
2
+ * pgsqlite-backed oracle for compiler quality.
3
+ *
4
+ * Spawns a real pgsqlite server, sends PG SQL via the PG wire protocol,
5
+ * captures the result set. Compares against running the same query through
6
+ * our compiler + bun:sqlite. Equivalence at the result-set level is what we
7
+ * actually care about — pgsqlite is the oracle, not the spec.
8
+ *
9
+ * The pgsqlite binary path comes from `vendor/pgsqlite/.resolved-path`,
10
+ * populated by `scripts/pgsqlite/ensure.ts`. If empty, oracle tests should
11
+ * be marked `it.skip` so the suite still runs without pgsqlite installed.
12
+ */
13
+ import { spawn } from 'node:child_process';
14
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
15
+ import { createConnection, createServer } from 'node:net';
16
+ import { tmpdir } from 'node:os';
17
+ import { resolve } from 'node:path';
18
+ import Database from '@rocicorp/zero-sqlite3';
19
+ const VENDOR_PATH_FILE = resolve(import.meta.dirname, '..', '..', '..', 'vendor', 'pgsqlite', '.resolved-path');
20
+ export function pgsqliteBinPath() {
21
+ if (!existsSync(VENDOR_PATH_FILE))
22
+ return null;
23
+ const path = readFileSync(VENDOR_PATH_FILE, 'utf-8').trim();
24
+ return path && existsSync(path) ? path : null;
25
+ }
26
+ export const ORACLE_AVAILABLE = pgsqliteBinPath() !== null;
27
+ /**
28
+ * Pick a free TCP port by binding ephemeral and reading what we got.
29
+ * Then close immediately and hand the port to pgsqlite. There's a tiny TOCTOU
30
+ * window where another process could grab it before pgsqlite binds, but
31
+ * vitest's parallel test files all go through this helper, so the only races
32
+ * are against unrelated processes on the host — vanishingly unlikely in CI.
33
+ */
34
+ async function getFreePort() {
35
+ return new Promise((resolveFn, reject) => {
36
+ const server = createServer();
37
+ server.unref();
38
+ server.on('error', reject);
39
+ server.listen(0, '127.0.0.1', () => {
40
+ const addr = server.address();
41
+ if (!addr || typeof addr === 'string') {
42
+ server.close();
43
+ reject(new Error('failed to get free port'));
44
+ return;
45
+ }
46
+ const port = addr.port;
47
+ server.close(() => resolveFn(port));
48
+ });
49
+ });
50
+ }
51
+ async function probePort(port, timeoutMs) {
52
+ return new Promise((resolveFn) => {
53
+ const sock = createConnection({ host: '127.0.0.1', port });
54
+ const cleanup = (val) => {
55
+ try {
56
+ sock.destroy();
57
+ }
58
+ catch { }
59
+ resolveFn(val);
60
+ };
61
+ const timer = setTimeout(() => cleanup(false), timeoutMs);
62
+ sock.once('connect', () => {
63
+ clearTimeout(timer);
64
+ cleanup(true);
65
+ });
66
+ sock.once('error', () => {
67
+ clearTimeout(timer);
68
+ cleanup(false);
69
+ });
70
+ });
71
+ }
72
+ /**
73
+ * Start a pgsqlite server on an OS-assigned ephemeral port with an ephemeral
74
+ * database. Throws on probe timeout. Caller is responsible for calling
75
+ * `stop()` in a `finally` / `afterAll` hook — `stop()` awaits child exit
76
+ * and cleans up the tempdir.
77
+ */
78
+ export async function startPgsqliteServer() {
79
+ const bin = pgsqliteBinPath();
80
+ if (!bin)
81
+ throw new Error('pgsqlite binary not available');
82
+ const port = await getFreePort();
83
+ const tmpDir = mkdtempSync(resolve(tmpdir(), 'orez-oracle-'));
84
+ const dbPath = resolve(tmpDir, 'pg.db');
85
+ const proc = spawn(bin, ['--port', String(port), '--database', dbPath, '--log-level', 'error'], { stdio: ['ignore', 'pipe', 'pipe'] });
86
+ const exited = new Promise((res) => proc.once('exit', () => res()));
87
+ // wait for "ready" — poll until the server accepts a connection or we time out
88
+ let ready = false;
89
+ const start = Date.now();
90
+ while (Date.now() - start < 10_000) {
91
+ if (await probePort(port, 250)) {
92
+ ready = true;
93
+ break;
94
+ }
95
+ if (proc.exitCode !== null) {
96
+ throw new Error(`pgsqlite exited before becoming ready (code=${proc.exitCode})`);
97
+ }
98
+ await new Promise((r) => setTimeout(r, 50));
99
+ }
100
+ if (!ready) {
101
+ try {
102
+ proc.kill('SIGKILL');
103
+ }
104
+ catch { }
105
+ try {
106
+ rmSync(tmpDir, { recursive: true, force: true });
107
+ }
108
+ catch { }
109
+ throw new Error(`pgsqlite did not become ready on port ${port} within 10s`);
110
+ }
111
+ return {
112
+ port,
113
+ dbPath,
114
+ async stop() {
115
+ try {
116
+ proc.kill('SIGTERM');
117
+ }
118
+ catch { }
119
+ // wait up to 2s for graceful exit, then SIGKILL
120
+ const killTimer = setTimeout(() => {
121
+ try {
122
+ proc.kill('SIGKILL');
123
+ }
124
+ catch { }
125
+ }, 2_000);
126
+ try {
127
+ await exited;
128
+ }
129
+ finally {
130
+ clearTimeout(killTimer);
131
+ }
132
+ try {
133
+ rmSync(tmpDir, { recursive: true, force: true });
134
+ }
135
+ catch { }
136
+ },
137
+ };
138
+ }
139
+ /**
140
+ * Helper: open a postgres.js client to a running pgsqlite server.
141
+ * Requires `postgres` to be available (we already ship it via @rocicorp/zero).
142
+ */
143
+ export async function connectOracle(server) {
144
+ const { default: postgres } = await import('postgres');
145
+ const sql = postgres({
146
+ host: '127.0.0.1',
147
+ port: server.port,
148
+ user: 'oracle',
149
+ password: '',
150
+ database: 'main',
151
+ ssl: false,
152
+ max: 1,
153
+ idle_timeout: 5,
154
+ connect_timeout: 5,
155
+ fetch_types: false,
156
+ prepare: false,
157
+ });
158
+ return {
159
+ exec: async (s, params = []) => {
160
+ const rows = await sql.unsafe(s, params);
161
+ return rows;
162
+ },
163
+ end: () => sql.end({ timeout: 2 }).then(() => undefined),
164
+ };
165
+ }
166
+ /**
167
+ * Run the same query against pgsqlite (oracle) and our compiler+SQLite (under
168
+ * test). Return both result sets so the test can diff them however it wants.
169
+ *
170
+ * Uses freshly-spawned servers/dbs for each call — slow but isolated. For
171
+ * batches use the lower-level helpers above.
172
+ */
173
+ export async function runOracleAndCompiler(setupSql, pgSql, params = []) {
174
+ const server = await startPgsqliteServer();
175
+ try {
176
+ const conn = await connectOracle(server);
177
+ try {
178
+ for (const s of setupSql)
179
+ await conn.exec(s);
180
+ const oracle = await conn.exec(pgSql, params);
181
+ // ours: setup + query against fresh in-memory sqlite (after compile())
182
+ const { compile } = await import('../index.js');
183
+ const db = new Database(':memory:');
184
+ for (const s of setupSql) {
185
+ const { sql: translated } = compile(s);
186
+ db.exec(translated);
187
+ }
188
+ const { sql: translatedQuery } = compile(pgSql);
189
+ // postgres.js uses $1 params; sqlite uses ?
190
+ const sqliteSql = translatedQuery.replace(/\$(\d+)/g, '?');
191
+ const stmt = db.prepare(sqliteSql);
192
+ const ours = (params.length > 0 ? stmt.all(...params) : stmt.all());
193
+ db.close();
194
+ return { oracle, ours };
195
+ }
196
+ finally {
197
+ await conn.end();
198
+ }
199
+ }
200
+ finally {
201
+ await server.stop();
202
+ }
203
+ }
204
+ //# sourceMappingURL=oracle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oracle.js","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/test/oracle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAA;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,UAAU,CAAC,CAAA;YACnC,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;gBACzB,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;gBACtC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YACrB,CAAC;YACD,MAAM,EAAE,GAAG,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;YAC/C,4CAA4C;YAC5C,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;YAC1D,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;YAClC,MAAM,IAAI,GAAG,CACX,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAI,MAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACvD,CAAA;YACV,EAAE,CAAC,KAAK,EAAE,CAAA;YAEV,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;QACzB,CAAC;gBAAS,CAAC;YACT,MAAM,IAAI,CAAC,GAAG,EAAE,CAAA;QAClB,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Schema metadata available to passes for type-aware translation.
3
+ *
4
+ * Implementations are caller-provided. The default NOOP_SCHEMA returns nothing
5
+ * and passes degrade gracefully (regex/AST-shape fallbacks).
6
+ *
7
+ * For orez, the eventual implementation will read from `ctx.storage.sql`
8
+ * PRAGMA + the `_orez_pg_metadata` catalog table.
9
+ */
10
+ export interface SchemaInfo {
11
+ /** PG type name (e.g. "jsonb", "text[]") for a column, or undefined. */
12
+ getColumnType(schema: string, table: string, column: string): string | undefined;
13
+ /** ENUM definition lookup by PG type name. */
14
+ getEnum(typeName: string): EnumInfo | undefined;
15
+ /** Validate an ENUM literal value. */
16
+ isEnumValue(typeOid: number, label: string): boolean;
17
+ /** Column list for a table (for SELECT * expansion, RETURNING * etc.). */
18
+ getTableColumns(schema: string, table: string): readonly string[] | undefined;
19
+ }
20
+ export interface EnumInfo {
21
+ typeOid: number;
22
+ values: readonly string[];
23
+ }
24
+ export interface CompileWarning {
25
+ kind: string;
26
+ message: string;
27
+ /** PG AST node tag where the warning was raised. */
28
+ near?: string;
29
+ }
30
+ export interface CompileResult {
31
+ sql: string;
32
+ warnings: CompileWarning[];
33
+ }
34
+ export interface CompileOptions {
35
+ schema?: SchemaInfo;
36
+ pgVersion?: number;
37
+ /** Override pass list (mainly for testing individual passes). */
38
+ passes?: Pass[];
39
+ }
40
+ /** Context passed to every pass. */
41
+ export interface PassContext {
42
+ schema: SchemaInfo;
43
+ warnings: CompileWarning[];
44
+ /**
45
+ * Optional pass list — if set, runPasses uses these instead of the default
46
+ * pipeline. Otherwise the full default pipeline runs.
47
+ */
48
+ passes?: Pass[];
49
+ }
50
+ /** A pass is a function that mutates a RawStmt in place. */
51
+ export interface Pass {
52
+ name: string;
53
+ run(rawStmt: any, ctx: PassContext): void;
54
+ }
55
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pg-sqlite-compiler/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,wEAAwE;IACxE,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAEhF,8CAA8C;IAC9C,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;IAE/C,sCAAsC;IACtC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;IAEpD,0EAA0E;IAC1E,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;CAC9E;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,cAAc,EAAE,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,iEAAiE;IACjE,MAAM,CAAC,EAAE,IAAI,EAAE,CAAA;CAChB;AAED,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,UAAU,CAAA;IAClB,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B;;;OAGG;IACH,MAAM,CAAC,EAAE,IAAI,EAAE,CAAA;CAChB;AAED,4DAA4D;AAC5D,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAAA;CAC1C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pg-sqlite-compiler/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orez",
3
- "version": "0.2.26",
3
+ "version": "0.2.27",
4
4
  "description": "PGlite-powered zero-sync development backend. No Docker required.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,6 +58,10 @@
58
58
  "test:wasm": "vitest run src/wasm-sqlite.test.ts",
59
59
  "test:all": "vitest run",
60
60
  "test:watch": "vitest",
61
+ "test:compiler": "vitest run src/pg-sqlite-compiler/",
62
+ "test:compiler:oracle": "bun scripts/pgsqlite/ensure.ts && vitest run src/pg-sqlite-compiler/test/",
63
+ "compiler:harvest-fixtures": "bun scripts/pgsqlite/harvest-fixtures.ts",
64
+ "compiler:ensure-pgsqlite": "bun scripts/pgsqlite/ensure.ts",
61
65
  "lint": "oxlint --import-plugin --ignore-pattern sqlite-wasm/",
62
66
  "format": "oxfmt .",
63
67
  "format:check": "oxfmt --check .",
@@ -83,7 +87,8 @@
83
87
  "dependencies": {
84
88
  "@electric-sql/pglite": "0.4.1",
85
89
  "@electric-sql/pglite-tools": "^0.3.1",
86
- "bedrock-sqlite": "0.2.26",
90
+ "@pgsql/traverse": "17.2.6",
91
+ "bedrock-sqlite": "0.2.27",
87
92
  "citty": "^0.2.0",
88
93
  "pg-gateway": "0.3.0-beta.4",
89
94
  "pgsql-parser": "^17.9.11",
@@ -1 +1 @@
1
- {"httpProtocol":"HTTP/1.1","clientAcceptEncoding":"gzip, deflate, br","requestPriority":"","edgeRequestKeepAliveStatus":1,"requestHeaderNames":{},"clientTcpRtt":74,"clientQuicRtt":0,"colo":"LAX","asn":21928,"asOrganization":"T-Mobile USA, Inc.","country":"US","isEUCountry":false,"city":"Honolulu","continent":"NA","region":"Hawaii","regionCode":"HI","timezone":"Pacific/Honolulu","longitude":"-157.85833","latitude":"21.30694","postalCode":"96802","metroCode":"744","tlsVersion":"TLSv1.3","tlsCipher":"AEAD-AES256-GCM-SHA384","tlsClientRandom":"8lAacoE+Gg3H5AKn8BQNpAGr3fgr0OV1txs9E+GEKXk=","tlsClientCiphersSha1":"JZtiTn8H/ntxORk+XXvU2EvNoz8=","tlsClientExtensionsSha1":"Y7DIC8A6G0/aXviZ8ie/xDbJb7g=","tlsClientExtensionsSha1Le":"6e+q3vPm88rSgMTN/h7WTTxQ2wQ=","tlsExportedAuthenticator":{"clientHandshake":"88b6a0bf9d7b4c6bc26b9f11255fe3f55b2bae485c86026892687913505e6a337a54221c8ec52b88741035fde8e80b91","serverHandshake":"a611a55711347da40c0167874992b47d75a4de9ed1c0bc731dd1f80051efde3b73a8baff4e484f30b284d662cd503dcb","clientFinished":"81b77db43ca14e8934ebd5f4c6d3656a1ccc726f04a10164cf7d599128d7dfbd3fa15f932068a583f288a0327d69a5f5","serverFinished":"68efa1737e629e56c92cbb680f96730052e8269e6248b62dd26a62d3ea7be55991e9f0ea85e6bebf95dbc6adbb41334e"},"tlsClientHelloLength":"386","tlsClientAuth":{"certPresented":"0","certVerified":"NONE","certRevoked":"0","certIssuerDN":"","certSubjectDN":"","certIssuerDNRFC2253":"","certSubjectDNRFC2253":"","certIssuerDNLegacy":"","certSubjectDNLegacy":"","certSerial":"","certIssuerSerial":"","certSKI":"","certIssuerSKI":"","certFingerprintSHA1":"","certFingerprintSHA256":"","certNotBefore":"","certNotAfter":"","certRFC9440":"","certRFC9440TooLarge":false,"certChainRFC9440":"","certChainRFC9440TooLarge":false},"verifiedBotCategory":"","edgeL4":{"deliveryRate":52536},"botManagement":{"corporateProxy":false,"verifiedBot":false,"jsDetection":{"passed":false},"staticResource":false,"detectionIds":{},"score":99}}
1
+ {"httpProtocol":"HTTP/1.1","clientAcceptEncoding":"gzip, deflate, br","requestPriority":"","edgeRequestKeepAliveStatus":1,"requestHeaderNames":{},"clientTcpRtt":93,"clientQuicRtt":0,"colo":"LAX","asn":21928,"asOrganization":"T-Mobile USA, Inc.","country":"US","isEUCountry":false,"city":"Honolulu","continent":"NA","region":"Hawaii","regionCode":"HI","timezone":"Pacific/Honolulu","longitude":"-157.85833","latitude":"21.30694","postalCode":"96802","metroCode":"744","tlsVersion":"TLSv1.3","tlsCipher":"AEAD-AES256-GCM-SHA384","tlsClientRandom":"NOBIfk5ETeINfIoBd1DBYmD6uDRaF6acEMq+Zulpn5M=","tlsClientCiphersSha1":"JZtiTn8H/ntxORk+XXvU2EvNoz8=","tlsClientExtensionsSha1":"Y7DIC8A6G0/aXviZ8ie/xDbJb7g=","tlsClientExtensionsSha1Le":"6e+q3vPm88rSgMTN/h7WTTxQ2wQ=","tlsExportedAuthenticator":{"clientHandshake":"a85e53d9da621fd7034dc64d2dfb270254957262daef67d7d0d9154fe2122b1661659fb5de1b674d3de3b0c400895ad6","serverHandshake":"4bcb07df5d2694809a69b6e423f8f5ef0746be28acb143ace522036e43d345863814d80f6c874320d7d04a7ce2b8fd9d","clientFinished":"6837d9952d53a1b550e3a280c48e207d1cc58c72770940c06f9f7b9853abd5060bff06ca118d6c71d94ab26184e95116","serverFinished":"48e2c71fae5a91d7a2b4ed7ca480052da299ed950a8f908eba095d075c53270b82305d1d6bd4ead4d5550e943537b47e"},"tlsClientHelloLength":"386","tlsClientAuth":{"certPresented":"0","certVerified":"NONE","certRevoked":"0","certIssuerDN":"","certSubjectDN":"","certIssuerDNRFC2253":"","certSubjectDNRFC2253":"","certIssuerDNLegacy":"","certSubjectDNLegacy":"","certSerial":"","certIssuerSerial":"","certSKI":"","certIssuerSKI":"","certFingerprintSHA1":"","certFingerprintSHA256":"","certNotBefore":"","certNotAfter":"","certRFC9440":"","certRFC9440TooLarge":false,"certChainRFC9440":"","certChainRFC9440TooLarge":false},"verifiedBotCategory":"","edgeL4":{"deliveryRate":47048},"botManagement":{"corporateProxy":false,"verifiedBot":false,"jsDetection":{"passed":false},"staticResource":false,"detectionIds":{},"score":99}}
@@ -0,0 +1,11 @@
1
+ import worker, * as OTHER_EXPORTS from "/Users/n8/orez/src/cf-do/worker.ts";
2
+ import * as __MIDDLEWARE_0__ from "/Users/n8/soot/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
3
+ import * as __MIDDLEWARE_1__ from "/Users/n8/soot/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
4
+
5
+ export * from "/Users/n8/orez/src/cf-do/worker.ts";
6
+ const MIDDLEWARE_TEST_INJECT = "__INJECT_FOR_TESTING_WRANGLER_MIDDLEWARE__";
7
+ export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [
8
+
9
+ __MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default
10
+ ]
11
+ export default worker;
@@ -0,0 +1,134 @@
1
+ // This loads all middlewares exposed on the middleware object and then starts
2
+ // the invocation chain. The big idea is that we can add these to the middleware
3
+ // export dynamically through wrangler, or we can potentially let users directly
4
+ // add them as a sort of "plugin" system.
5
+
6
+ import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-insertion-facade.js";
7
+ import { __facade_invoke__, __facade_register__, Dispatcher } from "/Users/n8/soot/node_modules/wrangler/templates/middleware/common.ts";
8
+ import type { WorkerEntrypointConstructor } from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-insertion-facade.js";
9
+
10
+ // Preserve all the exports from the worker
11
+ export * from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-insertion-facade.js";
12
+
13
+ class __Facade_ScheduledController__ implements ScheduledController {
14
+ readonly #noRetry: ScheduledController["noRetry"];
15
+
16
+ constructor(
17
+ readonly scheduledTime: number,
18
+ readonly cron: string,
19
+ noRetry: ScheduledController["noRetry"]
20
+ ) {
21
+ this.#noRetry = noRetry;
22
+ }
23
+
24
+ noRetry() {
25
+ if (!(this instanceof __Facade_ScheduledController__)) {
26
+ throw new TypeError("Illegal invocation");
27
+ }
28
+ // Need to call native method immediately in case uncaught error thrown
29
+ this.#noRetry();
30
+ }
31
+ }
32
+
33
+ function wrapExportedHandler(worker: ExportedHandler): ExportedHandler {
34
+ // If we don't have any middleware defined, just return the handler as is
35
+ if (
36
+ __INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
37
+ __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
38
+ ) {
39
+ return worker;
40
+ }
41
+ // Otherwise, register all middleware once
42
+ for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
43
+ __facade_register__(middleware);
44
+ }
45
+
46
+ const fetchDispatcher: ExportedHandlerFetchHandler = function (
47
+ request,
48
+ env,
49
+ ctx
50
+ ) {
51
+ if (worker.fetch === undefined) {
52
+ throw new Error("Handler does not export a fetch() function.");
53
+ }
54
+ return worker.fetch(request, env, ctx);
55
+ };
56
+
57
+ return {
58
+ ...worker,
59
+ fetch(request, env, ctx) {
60
+ const dispatcher: Dispatcher = function (type, init) {
61
+ if (type === "scheduled" && worker.scheduled !== undefined) {
62
+ const controller = new __Facade_ScheduledController__(
63
+ Date.now(),
64
+ init.cron ?? "",
65
+ () => {}
66
+ );
67
+ return worker.scheduled(controller, env, ctx);
68
+ }
69
+ };
70
+ return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
71
+ },
72
+ };
73
+ }
74
+
75
+ function wrapWorkerEntrypoint(
76
+ klass: WorkerEntrypointConstructor
77
+ ): WorkerEntrypointConstructor {
78
+ // If we don't have any middleware defined, just return the handler as is
79
+ if (
80
+ __INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
81
+ __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
82
+ ) {
83
+ return klass;
84
+ }
85
+ // Otherwise, register all middleware once
86
+ for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
87
+ __facade_register__(middleware);
88
+ }
89
+
90
+ // `extend`ing `klass` here so other RPC methods remain callable
91
+ return class extends klass {
92
+ #fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
93
+ request,
94
+ env,
95
+ ctx
96
+ ) => {
97
+ this.env = env;
98
+ this.ctx = ctx;
99
+ if (super.fetch === undefined) {
100
+ throw new Error("Entrypoint class does not define a fetch() function.");
101
+ }
102
+ return super.fetch(request);
103
+ };
104
+
105
+ #dispatcher: Dispatcher = (type, init) => {
106
+ if (type === "scheduled" && super.scheduled !== undefined) {
107
+ const controller = new __Facade_ScheduledController__(
108
+ Date.now(),
109
+ init.cron ?? "",
110
+ () => {}
111
+ );
112
+ return super.scheduled(controller);
113
+ }
114
+ };
115
+
116
+ fetch(request: Request<unknown, IncomingRequestCfProperties>) {
117
+ return __facade_invoke__(
118
+ request,
119
+ this.env,
120
+ this.ctx,
121
+ this.#dispatcher,
122
+ this.#fetchDispatcher
123
+ );
124
+ }
125
+ };
126
+ }
127
+
128
+ let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
129
+ if (typeof ENTRY === "object") {
130
+ WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
131
+ } else if (typeof ENTRY === "function") {
132
+ WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
133
+ }
134
+ export default WRAPPED_ENTRY;
@@ -0,0 +1,11 @@
1
+ import worker, * as OTHER_EXPORTS from "/Users/n8/orez/src/cf-do/worker.ts";
2
+ import * as __MIDDLEWARE_0__ from "/Users/n8/soot/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
3
+ import * as __MIDDLEWARE_1__ from "/Users/n8/soot/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
4
+
5
+ export * from "/Users/n8/orez/src/cf-do/worker.ts";
6
+ const MIDDLEWARE_TEST_INJECT = "__INJECT_FOR_TESTING_WRANGLER_MIDDLEWARE__";
7
+ export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [
8
+
9
+ __MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default
10
+ ]
11
+ export default worker;
@@ -0,0 +1,134 @@
1
+ // This loads all middlewares exposed on the middleware object and then starts
2
+ // the invocation chain. The big idea is that we can add these to the middleware
3
+ // export dynamically through wrangler, or we can potentially let users directly
4
+ // add them as a sort of "plugin" system.
5
+
6
+ import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js";
7
+ import { __facade_invoke__, __facade_register__, Dispatcher } from "/Users/n8/soot/node_modules/wrangler/templates/middleware/common.ts";
8
+ import type { WorkerEntrypointConstructor } from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js";
9
+
10
+ // Preserve all the exports from the worker
11
+ export * from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js";
12
+
13
+ class __Facade_ScheduledController__ implements ScheduledController {
14
+ readonly #noRetry: ScheduledController["noRetry"];
15
+
16
+ constructor(
17
+ readonly scheduledTime: number,
18
+ readonly cron: string,
19
+ noRetry: ScheduledController["noRetry"]
20
+ ) {
21
+ this.#noRetry = noRetry;
22
+ }
23
+
24
+ noRetry() {
25
+ if (!(this instanceof __Facade_ScheduledController__)) {
26
+ throw new TypeError("Illegal invocation");
27
+ }
28
+ // Need to call native method immediately in case uncaught error thrown
29
+ this.#noRetry();
30
+ }
31
+ }
32
+
33
+ function wrapExportedHandler(worker: ExportedHandler): ExportedHandler {
34
+ // If we don't have any middleware defined, just return the handler as is
35
+ if (
36
+ __INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
37
+ __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
38
+ ) {
39
+ return worker;
40
+ }
41
+ // Otherwise, register all middleware once
42
+ for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
43
+ __facade_register__(middleware);
44
+ }
45
+
46
+ const fetchDispatcher: ExportedHandlerFetchHandler = function (
47
+ request,
48
+ env,
49
+ ctx
50
+ ) {
51
+ if (worker.fetch === undefined) {
52
+ throw new Error("Handler does not export a fetch() function.");
53
+ }
54
+ return worker.fetch(request, env, ctx);
55
+ };
56
+
57
+ return {
58
+ ...worker,
59
+ fetch(request, env, ctx) {
60
+ const dispatcher: Dispatcher = function (type, init) {
61
+ if (type === "scheduled" && worker.scheduled !== undefined) {
62
+ const controller = new __Facade_ScheduledController__(
63
+ Date.now(),
64
+ init.cron ?? "",
65
+ () => {}
66
+ );
67
+ return worker.scheduled(controller, env, ctx);
68
+ }
69
+ };
70
+ return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
71
+ },
72
+ };
73
+ }
74
+
75
+ function wrapWorkerEntrypoint(
76
+ klass: WorkerEntrypointConstructor
77
+ ): WorkerEntrypointConstructor {
78
+ // If we don't have any middleware defined, just return the handler as is
79
+ if (
80
+ __INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
81
+ __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
82
+ ) {
83
+ return klass;
84
+ }
85
+ // Otherwise, register all middleware once
86
+ for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
87
+ __facade_register__(middleware);
88
+ }
89
+
90
+ // `extend`ing `klass` here so other RPC methods remain callable
91
+ return class extends klass {
92
+ #fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
93
+ request,
94
+ env,
95
+ ctx
96
+ ) => {
97
+ this.env = env;
98
+ this.ctx = ctx;
99
+ if (super.fetch === undefined) {
100
+ throw new Error("Entrypoint class does not define a fetch() function.");
101
+ }
102
+ return super.fetch(request);
103
+ };
104
+
105
+ #dispatcher: Dispatcher = (type, init) => {
106
+ if (type === "scheduled" && super.scheduled !== undefined) {
107
+ const controller = new __Facade_ScheduledController__(
108
+ Date.now(),
109
+ init.cron ?? "",
110
+ () => {}
111
+ );
112
+ return super.scheduled(controller);
113
+ }
114
+ };
115
+
116
+ fetch(request: Request<unknown, IncomingRequestCfProperties>) {
117
+ return __facade_invoke__(
118
+ request,
119
+ this.env,
120
+ this.ctx,
121
+ this.#dispatcher,
122
+ this.#fetchDispatcher
123
+ );
124
+ }
125
+ };
126
+ }
127
+
128
+ let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
129
+ if (typeof ENTRY === "object") {
130
+ WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
131
+ } else if (typeof ENTRY === "function") {
132
+ WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
133
+ }
134
+ export default WRAPPED_ENTRY;