orez 0.2.27 → 0.2.29
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/package.json +3 -4
- package/src/admin/admin-data.test.ts +0 -348
- package/src/admin/http-proxy.ts +0 -252
- package/src/admin/log-store.ts +0 -192
- package/src/admin/server.ts +0 -471
- package/src/admin/ui.ts +0 -1322
- package/src/bench/proxy-throughput.bench.ts +0 -343
- package/src/bench/serial-mutations.bench.ts +0 -270
- package/src/browser.ts +0 -203
- package/src/cf-do/.wrangler/cache/cf.json +0 -1
- 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 +0 -11
- package/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-loader.entry.ts +0 -134
- package/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js +0 -11
- package/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-loader.entry.ts +0 -134
- package/src/cf-do/.wrangler/tmp/dev-cbILNo/worker.js +0 -1059
- package/src/cf-do/.wrangler/tmp/dev-cbILNo/worker.js.map +0 -8
- package/src/cf-do/.wrangler/tmp/dev-qbho19/worker.js +0 -1059
- package/src/cf-do/.wrangler/tmp/dev-qbho19/worker.js.map +0 -8
- package/src/cf-do/ARCHITECTURE.md +0 -93
- package/src/cf-do/CHAT_E2E.md +0 -213
- package/src/cf-do/watermark.test.ts +0 -103
- package/src/cf-do/watermark.ts +0 -118
- package/src/cf-do/worker.ts +0 -1041
- package/src/cf-do/wrangler.toml +0 -11
- package/src/cf-pglite/README.md +0 -19
- package/src/change-tracking.ts +0 -25
- package/src/child-process.test.ts +0 -147
- package/src/child-process.ts +0 -90
- package/src/cli-entry.ts +0 -72
- package/src/cli.test.ts +0 -40
- package/src/cli.ts +0 -1214
- package/src/config.ts +0 -150
- package/src/do-sql-tracking.test.ts +0 -19
- package/src/do-sql-tracking.ts +0 -19
- package/src/index.ts +0 -1215
- package/src/integration/integration.test.ts +0 -517
- package/src/integration/native-binary.guard.test.ts +0 -13
- package/src/integration/native-startup.test.ts +0 -44
- package/src/integration/replication-latency.test.ts +0 -428
- package/src/integration/restore-live-stress.test.ts +0 -433
- package/src/integration/restore-reset.test.ts +0 -400
- package/src/integration/restore.test.ts +0 -274
- package/src/integration/test-permissions.ts +0 -147
- package/src/load-config.ts +0 -46
- package/src/log.ts +0 -96
- package/src/mutex.ts +0 -47
- package/src/pg-proxy-browser.singledb.test.ts +0 -233
- package/src/pg-proxy-browser.ts +0 -2022
- package/src/pg-proxy-do-backend.test.ts +0 -3890
- package/src/pg-proxy-do-backend.ts +0 -7191
- package/src/pg-proxy.ts +0 -1087
- package/src/pg-sqlite-compiler/README.md +0 -53
- package/src/pg-sqlite-compiler/catalog/seed.ts +0 -524
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/arithmetic.json +0 -307
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/array.json +0 -377
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/cast.json +0 -12
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/catalog.json +0 -447
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/create-table.json +0 -32
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/datetime.json +0 -397
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/enum.json +0 -337
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/insert.json +0 -337
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/json.json +0 -537
- package/src/pg-sqlite-compiler/fixtures/pgsqlite/misc.json +0 -1837
- package/src/pg-sqlite-compiler/index.ts +0 -73
- package/src/pg-sqlite-compiler/integration.test.ts +0 -136
- package/src/pg-sqlite-compiler/passes/ast-utils.ts +0 -113
- package/src/pg-sqlite-compiler/passes/catalog.ts +0 -65
- package/src/pg-sqlite-compiler/passes/datetime.ts +0 -74
- package/src/pg-sqlite-compiler/passes/index.ts +0 -49
- package/src/pg-sqlite-compiler/passes/types.ts +0 -156
- package/src/pg-sqlite-compiler/smoke.test.ts +0 -69
- package/src/pg-sqlite-compiler/test/catalog.test.ts +0 -171
- package/src/pg-sqlite-compiler/test/corpus.test.ts +0 -161
- package/src/pg-sqlite-compiler/test/datetime.oracle.test.ts +0 -102
- package/src/pg-sqlite-compiler/test/oracle.ts +0 -237
- package/src/pg-sqlite-compiler/test/types.test.ts +0 -109
- package/src/pg-sqlite-compiler/types.ts +0 -63
- package/src/pglite-ipc.test.ts +0 -116
- package/src/pglite-ipc.ts +0 -266
- package/src/pglite-manager.ts +0 -557
- package/src/pglite-web-proxy.test.ts +0 -57
- package/src/pglite-web-proxy.ts +0 -221
- package/src/pglite-web-worker.ts +0 -152
- package/src/pglite-worker-thread.ts +0 -253
- package/src/port.ts +0 -25
- package/src/process-title.ts +0 -9
- package/src/recovery.ts +0 -155
- package/src/replication/change-tracker.test.ts +0 -357
- package/src/replication/change-tracker.ts +0 -279
- package/src/replication/handler.test.ts +0 -511
- package/src/replication/handler.ts +0 -1190
- package/src/replication/pgoutput-encoder.test.ts +0 -697
- package/src/replication/pgoutput-encoder.ts +0 -373
- package/src/replication/tcp-replication.test.ts +0 -876
- package/src/replication/zero-compat.test.ts +0 -1150
- package/src/restore-stress.test.ts +0 -188
- package/src/s3-local.ts +0 -203
- package/src/shim/hooks.mjs +0 -120
- package/src/shim/register.mjs +0 -4
- package/src/sqlite-mode/apply-mode.ts +0 -224
- package/src/sqlite-mode/index.ts +0 -15
- package/src/sqlite-mode/native-binary.ts +0 -89
- package/src/sqlite-mode/package-resolve.ts +0 -17
- package/src/sqlite-mode/resolve-mode.ts +0 -80
- package/src/sqlite-mode/shim-template.ts +0 -159
- package/src/sqlite-mode/sqlite-mode.test.ts +0 -427
- package/src/sqlite-mode/types.ts +0 -30
- package/src/vite-plugin.ts +0 -67
- package/src/wasm-sqlite.test.ts +0 -537
- package/src/worker/browser-admin.ts +0 -52
- package/src/worker/browser-build-config.test.ts +0 -71
- package/src/worker/browser-build-config.ts +0 -109
- package/src/worker/browser-embed-admin.test.ts +0 -75
- package/src/worker/browser-embed.ts +0 -345
- package/src/worker/cf-patches.ts +0 -384
- package/src/worker/embed-integration.test.ts +0 -321
- package/src/worker/index.ts +0 -138
- package/src/worker/shims/fastify.test.ts +0 -255
- package/src/worker/shims/fastify.ts +0 -306
- package/src/worker/shims/http-service.test.ts +0 -355
- package/src/worker/shims/http-service.ts +0 -293
- package/src/worker/shims/node-stub.ts +0 -290
- package/src/worker/shims/oxfmt.ts +0 -3
- package/src/worker/shims/postgres-browser.ts +0 -59
- package/src/worker/shims/postgres-socket.test.ts +0 -576
- package/src/worker/shims/postgres-socket.ts +0 -310
- package/src/worker/shims/postgres.test.ts +0 -364
- package/src/worker/shims/postgres.ts +0 -1454
- package/src/worker/shims/sqlite-browser.test.ts +0 -233
- package/src/worker/shims/sqlite-browser.ts +0 -175
- package/src/worker/shims/sqlite.test.ts +0 -786
- package/src/worker/shims/sqlite.ts +0 -978
- package/src/worker/shims/stream-browser.ts +0 -15
- package/src/worker/shims/ws-browser.test.ts +0 -205
- package/src/worker/shims/ws-browser.ts +0 -248
- package/src/worker/shims/ws.test.ts +0 -288
- package/src/worker/shims/ws.ts +0 -467
- package/src/worker/shims/zero-process-env.ts +0 -11
- package/src/worker/types.ts +0 -75
- package/src/worker/worker-integration.test.ts +0 -223
- package/src/worker/worker.test.ts +0 -136
- package/src/worker/zero-cache-embed-cf.ts +0 -463
- package/src/worker/zero-cache-embed.ts +0 -277
package/src/pglite-ipc.ts
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PGlite worker proxy — runs in the main thread, proxies calls to a
|
|
3
|
-
* worker thread running the actual PGlite instance.
|
|
4
|
-
*
|
|
5
|
-
* implements the PGlite interface surface used throughout orez:
|
|
6
|
-
* execProtocolRaw, query, exec, listen, close.
|
|
7
|
-
*
|
|
8
|
-
* ArrayBuffers are transferred (not copied) for execProtocolRaw to
|
|
9
|
-
* keep IPC overhead near-zero for wire protocol data.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { existsSync } from 'node:fs'
|
|
13
|
-
import { resolve } from 'node:path'
|
|
14
|
-
import { Worker } from 'node:worker_threads'
|
|
15
|
-
|
|
16
|
-
import { log } from './log.js'
|
|
17
|
-
import { signalReplicationChange } from './replication/handler.js'
|
|
18
|
-
|
|
19
|
-
import type { WorkerInitConfig } from './pglite-worker-thread.js'
|
|
20
|
-
|
|
21
|
-
interface PendingRequest {
|
|
22
|
-
resolve: (value: any) => void
|
|
23
|
-
reject: (error: Error) => void
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const WRITE_PREFIXES = ['insert', 'update', 'delete', 'copy', 'truncate']
|
|
27
|
-
// shard-internal tables that the replication handler filters out.
|
|
28
|
-
// signaling for these just causes spurious wakeups + mutex contention.
|
|
29
|
-
// pre-lowercased so we don't call toLowerCase() per iteration
|
|
30
|
-
const SHARD_INTERNAL_TABLES = ['"replicas"', '"mutations"', '"replicationstate"']
|
|
31
|
-
function isReplicatedWrite(sql: string): boolean {
|
|
32
|
-
const q = sql.trimStart().toLowerCase()
|
|
33
|
-
if (!WRITE_PREFIXES.some((p) => q.startsWith(p))) return false
|
|
34
|
-
// skip shard-internal writes (zero-cache manages these, not replicated)
|
|
35
|
-
for (const t of SHARD_INTERNAL_TABLES) {
|
|
36
|
-
if (q.includes(t)) return false
|
|
37
|
-
}
|
|
38
|
-
return true
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// resolve worker file path — .ts in dev/test (vitest), .js when compiled
|
|
42
|
-
function resolveWorkerPath(): string {
|
|
43
|
-
const dir = import.meta.dirname
|
|
44
|
-
const tsPath = resolve(dir, 'pglite-worker-thread.ts')
|
|
45
|
-
if (existsSync(tsPath)) return tsPath
|
|
46
|
-
return resolve(dir, 'pglite-worker-thread.js')
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export class PGliteWorkerProxy {
|
|
50
|
-
private worker: Worker
|
|
51
|
-
private pending = new Map<number, PendingRequest>()
|
|
52
|
-
private nextId = 1
|
|
53
|
-
private notificationCallbacks = new Map<string, Set<(payload: string) => void>>()
|
|
54
|
-
private closed = false
|
|
55
|
-
private failure: Error | null = null
|
|
56
|
-
readonly name: string
|
|
57
|
-
|
|
58
|
-
/** resolves when the worker's PGlite instance is ready */
|
|
59
|
-
readonly waitReady: Promise<void>
|
|
60
|
-
|
|
61
|
-
constructor(config: WorkerInitConfig) {
|
|
62
|
-
this.name = config.name
|
|
63
|
-
const workerPath = resolveWorkerPath()
|
|
64
|
-
|
|
65
|
-
this.worker = new Worker(workerPath, {
|
|
66
|
-
workerData: config,
|
|
67
|
-
name: `pglite-${config.name}`,
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
// set up waitReady promise, then install message handler once ready
|
|
71
|
-
let onReady: () => void
|
|
72
|
-
this.waitReady = new Promise<void>((resolveReady, rejectReady) => {
|
|
73
|
-
onReady = () => {
|
|
74
|
-
log.debug.pglite(`worker ${config.name} ready`)
|
|
75
|
-
resolveReady()
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const onMessage = (msg: { type: string; id?: number; message?: string }) => {
|
|
79
|
-
if (msg.type === 'ready') {
|
|
80
|
-
this.worker.off('message', onMessage)
|
|
81
|
-
this.installMessageHandler()
|
|
82
|
-
onReady()
|
|
83
|
-
} else if (msg.type === 'error' && msg.id === 0) {
|
|
84
|
-
rejectReady(new Error(msg.message))
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.worker.on('message', onMessage)
|
|
89
|
-
this.worker.once('error', rejectReady)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
// handle unexpected worker crashes
|
|
93
|
-
this.worker.on('error', (err) => {
|
|
94
|
-
const failure = new Error(`worker crashed: ${err.message}`)
|
|
95
|
-
log.pglite(`worker ${config.name} error: ${err.message}`)
|
|
96
|
-
this.failPending(failure)
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
this.worker.on('exit', (code) => {
|
|
100
|
-
if (this.closed) return
|
|
101
|
-
if (code !== 0) {
|
|
102
|
-
const failure = new Error(`worker exited with code ${code}`)
|
|
103
|
-
log.pglite(`worker ${config.name} exited with code ${code}`)
|
|
104
|
-
this.failPending(failure)
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
this.failPending(new Error('worker exited unexpectedly'))
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private failPending(error: Error) {
|
|
112
|
-
if (!this.failure) this.failure = error
|
|
113
|
-
for (const [, req] of this.pending) {
|
|
114
|
-
req.reject(error)
|
|
115
|
-
}
|
|
116
|
-
this.pending.clear()
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private installMessageHandler() {
|
|
120
|
-
this.worker.on(
|
|
121
|
-
'message',
|
|
122
|
-
(msg: { type: string; id?: number; [key: string]: any }) => {
|
|
123
|
-
if (msg.type === 'notification') {
|
|
124
|
-
const callbacks = this.notificationCallbacks.get(msg.channel)
|
|
125
|
-
if (callbacks) {
|
|
126
|
-
for (const cb of callbacks) {
|
|
127
|
-
try {
|
|
128
|
-
cb(msg.payload)
|
|
129
|
-
} catch {}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const req = this.pending.get(msg.id!)
|
|
136
|
-
if (!req) return
|
|
137
|
-
this.pending.delete(msg.id!)
|
|
138
|
-
|
|
139
|
-
if (msg.type === 'error') {
|
|
140
|
-
const err = new Error(msg.message) as Error & { code?: string }
|
|
141
|
-
if (msg.code) err.code = msg.code
|
|
142
|
-
req.reject(err)
|
|
143
|
-
} else {
|
|
144
|
-
req.resolve(msg)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private send(msg: Record<string, unknown>, transfer?: ArrayBuffer[]): Promise<any> {
|
|
151
|
-
if (this.failure) return Promise.reject(this.failure)
|
|
152
|
-
if (this.closed) return Promise.reject(new Error('worker is closed'))
|
|
153
|
-
|
|
154
|
-
const id = this.nextId++
|
|
155
|
-
msg.id = id
|
|
156
|
-
return new Promise((resolve, reject) => {
|
|
157
|
-
this.pending.set(id, { resolve, reject })
|
|
158
|
-
try {
|
|
159
|
-
if (transfer?.length) {
|
|
160
|
-
this.worker.postMessage(msg, transfer)
|
|
161
|
-
} else {
|
|
162
|
-
this.worker.postMessage(msg)
|
|
163
|
-
}
|
|
164
|
-
} catch (err) {
|
|
165
|
-
this.pending.delete(id)
|
|
166
|
-
reject(err instanceof Error ? err : new Error(String(err)))
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async execProtocolRaw(
|
|
172
|
-
data: Uint8Array,
|
|
173
|
-
options?: { syncToFs?: boolean; throwOnError?: boolean }
|
|
174
|
-
): Promise<Uint8Array> {
|
|
175
|
-
// copy to a transferable buffer then transfer (avoids copying in the worker)
|
|
176
|
-
const buf = new ArrayBuffer(data.byteLength)
|
|
177
|
-
new Uint8Array(buf).set(data)
|
|
178
|
-
const result = await this.send({ type: 'execProtocolRaw', data: buf, options }, [buf])
|
|
179
|
-
return new Uint8Array(result.data)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* execute multiple wire protocol messages in a single IPC round-trip.
|
|
184
|
-
* each message is executed sequentially in the worker, and all results
|
|
185
|
-
* are concatenated and returned. eliminates N-1 postMessage round-trips
|
|
186
|
-
* for extended protocol pipelines (Parse→Bind→Execute→Sync).
|
|
187
|
-
*/
|
|
188
|
-
async execProtocolRawBatch(
|
|
189
|
-
messages: Uint8Array[],
|
|
190
|
-
options?: { syncToFs?: boolean; throwOnError?: boolean }
|
|
191
|
-
): Promise<Uint8Array> {
|
|
192
|
-
const buffers: ArrayBuffer[] = []
|
|
193
|
-
for (const msg of messages) {
|
|
194
|
-
const buf = new ArrayBuffer(msg.byteLength)
|
|
195
|
-
new Uint8Array(buf).set(msg)
|
|
196
|
-
buffers.push(buf)
|
|
197
|
-
}
|
|
198
|
-
const result = await this.send(
|
|
199
|
-
{ type: 'execProtocolRawBatch', buffers, options },
|
|
200
|
-
buffers
|
|
201
|
-
)
|
|
202
|
-
return new Uint8Array(result.data)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
async query<T = any>(
|
|
206
|
-
sql: string,
|
|
207
|
-
params?: any[]
|
|
208
|
-
): Promise<{ rows: T[]; affectedRows?: number }> {
|
|
209
|
-
const result = await this.send({ type: 'query', sql, params })
|
|
210
|
-
if (this.name === 'postgres' && isReplicatedWrite(sql)) {
|
|
211
|
-
signalReplicationChange()
|
|
212
|
-
}
|
|
213
|
-
return { rows: result.rows ?? [], affectedRows: result.affectedRows }
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
async exec(sql: string): Promise<{ affectedRows?: number }[]> {
|
|
217
|
-
const result = await this.send({ type: 'exec', sql })
|
|
218
|
-
if (this.name === 'postgres' && isReplicatedWrite(sql)) {
|
|
219
|
-
signalReplicationChange()
|
|
220
|
-
}
|
|
221
|
-
return result.results ?? []
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
async listen(
|
|
225
|
-
channel: string,
|
|
226
|
-
callback: (payload: string) => void
|
|
227
|
-
): Promise<() => Promise<void>> {
|
|
228
|
-
let callbacks = this.notificationCallbacks.get(channel)
|
|
229
|
-
if (!callbacks) {
|
|
230
|
-
callbacks = new Set()
|
|
231
|
-
this.notificationCallbacks.set(channel, callbacks)
|
|
232
|
-
}
|
|
233
|
-
callbacks.add(callback)
|
|
234
|
-
|
|
235
|
-
const result = await this.send({ type: 'listen', channel })
|
|
236
|
-
const listenId = result.id
|
|
237
|
-
|
|
238
|
-
return async () => {
|
|
239
|
-
callbacks!.delete(callback)
|
|
240
|
-
if (callbacks!.size === 0) {
|
|
241
|
-
this.notificationCallbacks.delete(channel)
|
|
242
|
-
}
|
|
243
|
-
await this.send({ type: 'unlisten', listenId }).catch(() => {})
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* dump the PGlite data directory as a tar blob.
|
|
249
|
-
* used to create read replicas from an existing instance.
|
|
250
|
-
*/
|
|
251
|
-
async dumpDataDir(): Promise<ArrayBuffer> {
|
|
252
|
-
const result = await this.send({ type: 'dumpDataDir' })
|
|
253
|
-
return result.data as ArrayBuffer
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async close(): Promise<void> {
|
|
257
|
-
try {
|
|
258
|
-
await this.send({ type: 'close' })
|
|
259
|
-
} catch {
|
|
260
|
-
// worker may already be gone
|
|
261
|
-
}
|
|
262
|
-
this.closed = true
|
|
263
|
-
this.failPending(new Error('worker is closed'))
|
|
264
|
-
await this.worker.terminate()
|
|
265
|
-
}
|
|
266
|
-
}
|