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
package/src/cli.test.ts
CHANGED
|
@@ -7,7 +7,9 @@ function runCli(
|
|
|
7
7
|
args: string[]
|
|
8
8
|
): Promise<{ stdout: string; stderr: string; code: number }> {
|
|
9
9
|
return new Promise((res) => {
|
|
10
|
-
|
|
10
|
+
// cli-entry.js is the actual entry (cli.js only exports `main`; runMain
|
|
11
|
+
// is invoked from cli-entry).
|
|
12
|
+
const child = spawn('bun', [resolve('dist/cli-entry.js'), ...args], {
|
|
11
13
|
timeout: 10_000,
|
|
12
14
|
env: { ...process.env, NODE_ENV: 'test' },
|
|
13
15
|
})
|
package/src/config.ts
CHANGED
|
@@ -139,7 +139,7 @@ export function getConfig(overrides: Partial<ZeroLiteConfig> = {}): ZeroLiteConf
|
|
|
139
139
|
checkpointIntervalMs: overrides.checkpointIntervalMs ?? 5 * 60 * 1000,
|
|
140
140
|
maxLogFileSize: overrides.maxLogFileSize ?? 2 * 1024 * 1024,
|
|
141
141
|
disableDiskLogs: overrides.disableDiskLogs ?? false,
|
|
142
|
-
doBackendUrl: overrides.doBackendUrl,
|
|
142
|
+
doBackendUrl: overrides.doBackendUrl ?? process.env.DO_BACKEND_URL,
|
|
143
143
|
onDbReady: overrides.onDbReady,
|
|
144
144
|
onHealthy: overrides.onHealthy,
|
|
145
145
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { trackedChangeRow } from './do-sql-tracking.js'
|
|
4
|
+
|
|
5
|
+
describe('trackedChangeRow', () => {
|
|
6
|
+
it('keeps only table columns and strips internal returning expressions', () => {
|
|
7
|
+
expect(
|
|
8
|
+
trackedChangeRow(
|
|
9
|
+
{
|
|
10
|
+
id: 't1',
|
|
11
|
+
body: 'hello',
|
|
12
|
+
__orez_returning_1: 'HELLO',
|
|
13
|
+
extra: 'client-visible only',
|
|
14
|
+
},
|
|
15
|
+
{ rowColumns: ['id', 'body'] }
|
|
16
|
+
)
|
|
17
|
+
).toEqual({ id: 't1', body: 'hello' })
|
|
18
|
+
})
|
|
19
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const RETURNING_INTERNAL_PREFIX = '__orez_returning_'
|
|
2
|
+
|
|
3
|
+
export interface TrackedRowFilter {
|
|
4
|
+
rowColumns?: string[]
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function trackedChangeRow(
|
|
8
|
+
row: Record<string, unknown>,
|
|
9
|
+
track: TrackedRowFilter
|
|
10
|
+
): Record<string, unknown> {
|
|
11
|
+
const allowed = track.rowColumns ? new Set(track.rowColumns) : null
|
|
12
|
+
const out: Record<string, unknown> = {}
|
|
13
|
+
for (const [key, value] of Object.entries(row)) {
|
|
14
|
+
if (key.startsWith(RETURNING_INTERNAL_PREFIX)) continue
|
|
15
|
+
if (allowed && !allowed.has(key)) continue
|
|
16
|
+
out[key] = value
|
|
17
|
+
}
|
|
18
|
+
return out
|
|
19
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { spawn, spawnSync, type ChildProcess } from 'node:child_process'
|
|
10
|
+
import { randomUUID } from 'node:crypto'
|
|
10
11
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
11
12
|
import { resolve } from 'node:path'
|
|
12
13
|
|
|
@@ -61,6 +62,17 @@ import type { PGlite } from '@electric-sql/pglite'
|
|
|
61
62
|
|
|
62
63
|
type ZeroChildProcess = ChildProcess & { __orezTail?: string[] }
|
|
63
64
|
|
|
65
|
+
function ensureDoBackendNamespace(dataDir: string): string {
|
|
66
|
+
const marker = resolve(dataDir, 'do-backend-namespace')
|
|
67
|
+
if (existsSync(marker)) {
|
|
68
|
+
const existing = readFileSync(marker, 'utf8').trim()
|
|
69
|
+
if (existing) return existing
|
|
70
|
+
}
|
|
71
|
+
const next = randomUUID()
|
|
72
|
+
writeFileSync(marker, `${next}\n`)
|
|
73
|
+
return next
|
|
74
|
+
}
|
|
75
|
+
|
|
64
76
|
function resolveNodeBinary(): string {
|
|
65
77
|
const explicitNode = process.env.NODE
|
|
66
78
|
if (explicitNode && existsSync(explicitNode)) {
|
|
@@ -330,10 +342,11 @@ export async function startZeroLite(overrides: Partial<ZeroLiteConfig> = {}) {
|
|
|
330
342
|
isDoBackend = true
|
|
331
343
|
log.orez(`using DO backend: ${config.doBackendUrl}`)
|
|
332
344
|
const backendUrl = config.doBackendUrl.replace(/\/+$/, '')
|
|
345
|
+
const doNamespace = ensureDoBackendNamespace(config.dataDir)
|
|
333
346
|
const doInstances = {
|
|
334
|
-
postgres: new DoBackend(backendUrl, 'postgres'),
|
|
335
|
-
cvr: new DoBackend(backendUrl, 'zero_cvr'),
|
|
336
|
-
cdb: new DoBackend(backendUrl, 'zero_cdb'),
|
|
347
|
+
postgres: new DoBackend(backendUrl, 'postgres', doNamespace),
|
|
348
|
+
cvr: new DoBackend(backendUrl, 'zero_cvr', doNamespace),
|
|
349
|
+
cdb: new DoBackend(backendUrl, 'zero_cdb', doNamespace),
|
|
337
350
|
postgresReplicas: [],
|
|
338
351
|
}
|
|
339
352
|
await Promise.all([
|
|
@@ -381,10 +394,10 @@ export async function startZeroLite(overrides: Partial<ZeroLiteConfig> = {}) {
|
|
|
381
394
|
log.debug.orez(`using managed publication: ${managedPub.names.join(', ')}`)
|
|
382
395
|
}
|
|
383
396
|
|
|
384
|
-
//
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
397
|
+
// sync publications. for DO backend this goes through the TCP proxy, which
|
|
398
|
+
// rewrites the catalog queries and forwards CREATE PUBLICATION / ALTER PUBLICATION
|
|
399
|
+
// as no-ops or DO-native equivalents (PGlite still owns the real path).
|
|
400
|
+
await syncManagedPublications(db, managedPub.names, managedPub.managedByOrez)
|
|
388
401
|
|
|
389
402
|
// start tcp proxy (routes connections to correct instance by database name)
|
|
390
403
|
const pgServer = await startPgProxy(instances, config)
|
|
@@ -410,13 +423,15 @@ export async function startZeroLite(overrides: Partial<ZeroLiteConfig> = {}) {
|
|
|
410
423
|
OREZ_PG_PORT: String(config.pgPort),
|
|
411
424
|
})
|
|
412
425
|
|
|
413
|
-
// re-sync publication membership
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
426
|
+
// re-sync publication membership
|
|
427
|
+
await syncManagedPublications(db, managedPub.names, managedPub.managedByOrez)
|
|
428
|
+
await ensurePublicationHasTables(db, managedPub.names)
|
|
429
|
+
log.debug.orez('re-installing change tracking after on-db-ready')
|
|
430
|
+
await installChangeTracking(db)
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (isDoBackend) {
|
|
434
|
+
await installChangeTracking(db)
|
|
420
435
|
}
|
|
421
436
|
|
|
422
437
|
// write the ready marker so external orchestrators (e.g. CI scripts that
|
package/src/pg-proxy-browser.ts
CHANGED
|
@@ -656,7 +656,7 @@ function messagePortToDuplexWithInject(port: MessagePort): {
|
|
|
656
656
|
chunk.byteOffset,
|
|
657
657
|
chunk.byteOffset + chunk.byteLength
|
|
658
658
|
) as ArrayBuffer
|
|
659
|
-
port.postMessage(buf
|
|
659
|
+
port.postMessage(buf)
|
|
660
660
|
},
|
|
661
661
|
close() {
|
|
662
662
|
port.close()
|
|
@@ -668,7 +668,7 @@ function messagePortToDuplexWithInject(port: MessagePort): {
|
|
|
668
668
|
data.byteOffset,
|
|
669
669
|
data.byteOffset + data.byteLength
|
|
670
670
|
) as ArrayBuffer
|
|
671
|
-
port.postMessage(buf
|
|
671
|
+
port.postMessage(buf)
|
|
672
672
|
}
|
|
673
673
|
|
|
674
674
|
const injectMessage = (data: Uint8Array) => {
|
|
@@ -714,12 +714,12 @@ function messagePortToDuplex(port: MessagePort): {
|
|
|
714
714
|
if (isDebugWire() && _globalWriteCount <= 200) {
|
|
715
715
|
console.debug(`[pg-proxy-ws-write] #${_globalWriteCount} len=${chunk.byteLength}`)
|
|
716
716
|
}
|
|
717
|
-
//
|
|
717
|
+
// CF workerd MessagePort does not support transfer lists.
|
|
718
718
|
const buf = chunk.buffer.slice(
|
|
719
719
|
chunk.byteOffset,
|
|
720
720
|
chunk.byteOffset + chunk.byteLength
|
|
721
721
|
) as ArrayBuffer
|
|
722
|
-
port.postMessage(buf
|
|
722
|
+
port.postMessage(buf)
|
|
723
723
|
},
|
|
724
724
|
close() {
|
|
725
725
|
port.close()
|
|
@@ -733,7 +733,7 @@ function messagePortToDuplex(port: MessagePort): {
|
|
|
733
733
|
data.byteOffset,
|
|
734
734
|
data.byteOffset + data.byteLength
|
|
735
735
|
) as ArrayBuffer
|
|
736
|
-
port.postMessage(buf
|
|
736
|
+
port.postMessage(buf)
|
|
737
737
|
}
|
|
738
738
|
|
|
739
739
|
return { duplex: { readable, writable }, rawWrite }
|
|
@@ -1020,7 +1020,7 @@ export async function createBrowserProxy(
|
|
|
1020
1020
|
// cause issues if the caller still references the original data
|
|
1021
1021
|
const copy = new Uint8Array(data.length)
|
|
1022
1022
|
copy.set(data)
|
|
1023
|
-
port.postMessage(copy.buffer
|
|
1023
|
+
port.postMessage(copy.buffer)
|
|
1024
1024
|
}
|
|
1025
1025
|
|
|
1026
1026
|
// step 1: send AuthenticationClearTextPassword (R, type=3) — ask for password
|