orez 0.2.24 → 0.2.25
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/test-protocol.d.ts +11 -0
- package/dist/cf-do/test-protocol.d.ts.map +1 -0
- package/dist/cf-do/test-protocol.js +137 -0
- package/dist/cf-do/test-protocol.js.map +1 -0
- package/dist/cf-do/worker.d.ts +65 -0
- package/dist/cf-do/worker.d.ts.map +1 -0
- package/dist/cf-do/worker.js +440 -0
- package/dist/cf-do/worker.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -28
- package/dist/index.js.map +1 -1
- package/dist/pg-proxy-do-backend.d.ts +49 -0
- package/dist/pg-proxy-do-backend.d.ts.map +1 -0
- package/dist/pg-proxy-do-backend.js +713 -0
- package/dist/pg-proxy-do-backend.js.map +1 -0
- package/dist/pglite-ipc.d.ts +3 -0
- package/dist/pglite-ipc.d.ts.map +1 -1
- package/dist/pglite-ipc.js +34 -12
- package/dist/pglite-ipc.js.map +1 -1
- package/dist/pglite-web-proxy.d.ts +3 -0
- package/dist/pglite-web-proxy.d.ts.map +1 -1
- package/dist/pglite-web-proxy.js +50 -7
- package/dist/pglite-web-proxy.js.map +1 -1
- package/dist/query-rewrites.d.ts +2 -0
- package/dist/query-rewrites.d.ts.map +1 -0
- package/dist/query-rewrites.js +140 -0
- package/dist/query-rewrites.js.map +1 -0
- package/package.json +2 -2
- package/src/config.ts +5 -0
- package/src/index.ts +66 -33
- package/src/pg-proxy-do-backend.ts +840 -0
- package/src/pglite-ipc.test.ts +17 -0
- package/src/pglite-ipc.ts +31 -12
- package/src/pglite-web-proxy.test.ts +57 -0
- package/src/pglite-web-proxy.ts +48 -7
- package/src/query-rewrites.test.ts +30 -0
- package/src/query-rewrites.ts +152 -0
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from './child-process.js'
|
|
25
25
|
import { getConfig, getConnectionString } from './config.js'
|
|
26
26
|
import { log, port, setLogLevel, setLogStore } from './log.js'
|
|
27
|
+
import { DoBackend } from './pg-proxy-do-backend.js'
|
|
27
28
|
import { startPgProxy } from './pg-proxy.js'
|
|
28
29
|
import {
|
|
29
30
|
createPGliteInstances,
|
|
@@ -319,22 +320,59 @@ export async function startZeroLite(overrides: Partial<ZeroLiteConfig> = {}) {
|
|
|
319
320
|
// single-db mode uses one instance for all databases (lighter for constrained envs).
|
|
320
321
|
// otherwise, separate instances for postgres, zero_cvr, zero_cdb with optional
|
|
321
322
|
// worker threads for non-blocking WASM execution.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
: ()
|
|
336
|
-
|
|
337
|
-
|
|
323
|
+
|
|
324
|
+
// ── DO backend path (replaces PGlite) ──────────────────────────────
|
|
325
|
+
let instances: any, db: any, stopCheckpoint: any
|
|
326
|
+
let migrationsApplied = 0
|
|
327
|
+
let isDoBackend = false
|
|
328
|
+
|
|
329
|
+
if (config.doBackendUrl) {
|
|
330
|
+
isDoBackend = true
|
|
331
|
+
log.orez(`using DO backend: ${config.doBackendUrl}`)
|
|
332
|
+
const backendUrl = config.doBackendUrl.replace(/\/+$/, '')
|
|
333
|
+
const doInstances = {
|
|
334
|
+
postgres: new DoBackend(backendUrl, 'postgres'),
|
|
335
|
+
cvr: new DoBackend(backendUrl, 'zero_cvr'),
|
|
336
|
+
cdb: new DoBackend(backendUrl, 'zero_cdb'),
|
|
337
|
+
postgresReplicas: [],
|
|
338
|
+
}
|
|
339
|
+
await Promise.all([
|
|
340
|
+
doInstances.postgres.waitReady,
|
|
341
|
+
doInstances.cvr.waitReady,
|
|
342
|
+
doInstances.cdb.waitReady,
|
|
343
|
+
])
|
|
344
|
+
instances = doInstances
|
|
345
|
+
db = doInstances.postgres
|
|
346
|
+
stopCheckpoint = () => {}
|
|
347
|
+
} else {
|
|
348
|
+
// ── PGlite backend (default) ────────────────────────────────────────────
|
|
349
|
+
instances = config.singleDb
|
|
350
|
+
? config.useWorkerThreads
|
|
351
|
+
? await createSinglePGliteWorkerInstance(config)
|
|
352
|
+
: await createSinglePGliteInstance(config)
|
|
353
|
+
: config.useWorkerThreads
|
|
354
|
+
? await createPGliteWorkerInstances(config)
|
|
355
|
+
: await createPGliteInstances(config)
|
|
356
|
+
db = instances.postgres
|
|
357
|
+
|
|
358
|
+
// periodic WAL checkpoint
|
|
359
|
+
stopCheckpoint =
|
|
360
|
+
config.checkpointIntervalMs > 0
|
|
361
|
+
? startPeriodicCheckpoint(instances, config.checkpointIntervalMs)
|
|
362
|
+
: () => {}
|
|
363
|
+
|
|
364
|
+
// config-based publications
|
|
365
|
+
if (config.zeroPublications && !process.env.ZERO_APP_PUBLICATIONS) {
|
|
366
|
+
process.env.ZERO_APP_PUBLICATIONS = config.zeroPublications
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// run migrations & change tracking
|
|
370
|
+
migrationsApplied = await runMigrations(db, config)
|
|
371
|
+
log.debug.orez('installing change tracking')
|
|
372
|
+
await installChangeTracking(db)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// shared: publications config
|
|
338
376
|
if (config.zeroPublications && !process.env.ZERO_APP_PUBLICATIONS) {
|
|
339
377
|
process.env.ZERO_APP_PUBLICATIONS = config.zeroPublications
|
|
340
378
|
}
|
|
@@ -343,13 +381,10 @@ export async function startZeroLite(overrides: Partial<ZeroLiteConfig> = {}) {
|
|
|
343
381
|
log.debug.orez(`using managed publication: ${managedPub.names.join(', ')}`)
|
|
344
382
|
}
|
|
345
383
|
|
|
346
|
-
//
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
// install change tracking (on postgres instance only)
|
|
351
|
-
log.debug.orez('installing change tracking')
|
|
352
|
-
await installChangeTracking(db)
|
|
384
|
+
// PGlite-only: sync publications
|
|
385
|
+
if (!isDoBackend) {
|
|
386
|
+
await syncManagedPublications(db, managedPub.names, managedPub.managedByOrez)
|
|
387
|
+
}
|
|
353
388
|
|
|
354
389
|
// start tcp proxy (routes connections to correct instance by database name)
|
|
355
390
|
const pgServer = await startPgProxy(instances, config)
|
|
@@ -375,15 +410,13 @@ export async function startZeroLite(overrides: Partial<ZeroLiteConfig> = {}) {
|
|
|
375
410
|
OREZ_PG_PORT: String(config.pgPort),
|
|
376
411
|
})
|
|
377
412
|
|
|
378
|
-
// re-sync publication membership
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
log.debug.orez('re-installing change tracking after on-db-ready')
|
|
386
|
-
await installChangeTracking(db)
|
|
413
|
+
// re-sync publication membership (PGlite-only)
|
|
414
|
+
if (!isDoBackend) {
|
|
415
|
+
await syncManagedPublications(db, managedPub.names, managedPub.managedByOrez)
|
|
416
|
+
await ensurePublicationHasTables(db, managedPub.names)
|
|
417
|
+
log.debug.orez('re-installing change tracking after on-db-ready')
|
|
418
|
+
await installChangeTracking(db)
|
|
419
|
+
}
|
|
387
420
|
}
|
|
388
421
|
|
|
389
422
|
// write the ready marker so external orchestrators (e.g. CI scripts that
|
|
@@ -624,7 +657,7 @@ export async function startZeroLite(overrides: Partial<ZeroLiteConfig> = {}) {
|
|
|
624
657
|
|
|
625
658
|
// remove stale zero shard schemas from upstream; these can outlive CVR/CDB
|
|
626
659
|
// and cause dispatcher errors after full reset.
|
|
627
|
-
const shardSchemas = await db.query
|
|
660
|
+
const shardSchemas = await db.query(
|
|
628
661
|
`SELECT DISTINCT schemaname
|
|
629
662
|
FROM pg_tables
|
|
630
663
|
WHERE tablename IN ('clients', 'replicas', 'mutations')
|