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,1059 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// worker.ts
|
|
5
|
+
import { DurableObject } from "cloudflare:workers";
|
|
6
|
+
|
|
7
|
+
// ../do-sql-tracking.ts
|
|
8
|
+
var RETURNING_INTERNAL_PREFIX = "__orez_returning_";
|
|
9
|
+
function trackedChangeRow(row, track) {
|
|
10
|
+
const allowed = track.rowColumns ? new Set(track.rowColumns) : null;
|
|
11
|
+
const out = {};
|
|
12
|
+
for (const [key, value] of Object.entries(row)) {
|
|
13
|
+
if (key.startsWith(RETURNING_INTERNAL_PREFIX)) continue;
|
|
14
|
+
if (allowed && !allowed.has(key)) continue;
|
|
15
|
+
out[key] = value;
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
__name(trackedChangeRow, "trackedChangeRow");
|
|
20
|
+
|
|
21
|
+
// watermark.ts
|
|
22
|
+
var WATERMARK_STATE_TABLE = "_zero_change_state";
|
|
23
|
+
function quoteIdent(name) {
|
|
24
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
25
|
+
}
|
|
26
|
+
__name(quoteIdent, "quoteIdent");
|
|
27
|
+
function finitePositiveNumber(value) {
|
|
28
|
+
const number = Number(value ?? 0);
|
|
29
|
+
return Number.isFinite(number) && number > 0 ? number : 0;
|
|
30
|
+
}
|
|
31
|
+
__name(finitePositiveNumber, "finitePositiveNumber");
|
|
32
|
+
var DurableWatermarkState = class {
|
|
33
|
+
constructor(sql) {
|
|
34
|
+
this.sql = sql;
|
|
35
|
+
}
|
|
36
|
+
static {
|
|
37
|
+
__name(this, "DurableWatermarkState");
|
|
38
|
+
}
|
|
39
|
+
ensureTables() {
|
|
40
|
+
this.sql.exec(
|
|
41
|
+
"CREATE TABLE IF NOT EXISTS _zero_changes (watermark INTEGER PRIMARY KEY AUTOINCREMENT, table_name TEXT NOT NULL, op TEXT NOT NULL CHECK (op IN ('INSERT', 'UPDATE', 'DELETE')), row_data TEXT, old_data TEXT, created_at INTEGER NOT NULL DEFAULT (unixepoch()))"
|
|
42
|
+
);
|
|
43
|
+
this.sql.exec(
|
|
44
|
+
`CREATE TABLE IF NOT EXISTS ${quoteIdent(WATERMARK_STATE_TABLE)} (id INTEGER PRIMARY KEY CHECK (id = 1), last_value INTEGER NOT NULL DEFAULT 0)`
|
|
45
|
+
);
|
|
46
|
+
this.setWatermarkState(this.watermarkState());
|
|
47
|
+
}
|
|
48
|
+
next() {
|
|
49
|
+
return this.current() + 1;
|
|
50
|
+
}
|
|
51
|
+
mark(watermark) {
|
|
52
|
+
this.setWatermarkState(watermark);
|
|
53
|
+
this.updateWatermarkSequences(watermark);
|
|
54
|
+
}
|
|
55
|
+
current() {
|
|
56
|
+
this.ensureTables();
|
|
57
|
+
const state = this.watermarkState();
|
|
58
|
+
const row = this.sql.exec("SELECT COALESCE(MAX(watermark), 0) AS watermark FROM _zero_changes").one();
|
|
59
|
+
const tableWatermark = finitePositiveNumber(row?.watermark);
|
|
60
|
+
const sequenceWatermark = this.watermarkSequenceValue();
|
|
61
|
+
const watermark = Math.max(state, tableWatermark, sequenceWatermark);
|
|
62
|
+
if (watermark > state) this.setWatermarkState(watermark);
|
|
63
|
+
if (watermark > sequenceWatermark) this.updateWatermarkSequences(watermark);
|
|
64
|
+
return watermark;
|
|
65
|
+
}
|
|
66
|
+
watermarkState() {
|
|
67
|
+
try {
|
|
68
|
+
const table = quoteIdent(WATERMARK_STATE_TABLE);
|
|
69
|
+
const row = this.sql.exec(`SELECT last_value FROM ${table} WHERE id = 1`).one();
|
|
70
|
+
return finitePositiveNumber(row?.last_value);
|
|
71
|
+
} catch {
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
setWatermarkState(watermark) {
|
|
76
|
+
const table = quoteIdent(WATERMARK_STATE_TABLE);
|
|
77
|
+
this.sql.exec(`INSERT OR IGNORE INTO ${table} (id, last_value) VALUES (1, 0)`);
|
|
78
|
+
this.sql.exec(`UPDATE ${table} SET last_value = ? WHERE id = 1`, watermark);
|
|
79
|
+
}
|
|
80
|
+
watermarkSequenceValue() {
|
|
81
|
+
let watermark = 0;
|
|
82
|
+
for (const name of this.watermarkSequenceTables()) {
|
|
83
|
+
try {
|
|
84
|
+
const row = this.sql.exec(`SELECT last_value, is_called FROM ${quoteIdent(name)} WHERE dummy = 1`).one();
|
|
85
|
+
if (!row || !row.is_called) continue;
|
|
86
|
+
watermark = Math.max(watermark, finitePositiveNumber(row.last_value));
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return watermark;
|
|
91
|
+
}
|
|
92
|
+
watermarkSequenceTables() {
|
|
93
|
+
return this.sql.exec(
|
|
94
|
+
"SELECT name FROM sqlite_master WHERE type='table' AND name LIKE '%zero_watermark%'"
|
|
95
|
+
).toArray().map((row) => String(row.name || "")).filter(Boolean);
|
|
96
|
+
}
|
|
97
|
+
updateWatermarkSequences(watermark) {
|
|
98
|
+
for (const name of this.watermarkSequenceTables()) {
|
|
99
|
+
const table = quoteIdent(name);
|
|
100
|
+
try {
|
|
101
|
+
this.sql.exec(
|
|
102
|
+
`INSERT OR IGNORE INTO ${table} (dummy, last_value, is_called) VALUES (1, ?, 1)`,
|
|
103
|
+
watermark
|
|
104
|
+
);
|
|
105
|
+
this.sql.exec(
|
|
106
|
+
`UPDATE ${table} SET last_value = ?, is_called = 1 WHERE dummy = 1`,
|
|
107
|
+
watermark
|
|
108
|
+
);
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// worker.ts
|
|
116
|
+
var SCHEMA_VERSION = 1;
|
|
117
|
+
var SQL_ERROR_SNIPPET_RADIUS = 1600;
|
|
118
|
+
var SQL_ERROR_FALLBACK_LIMIT = 4e3;
|
|
119
|
+
function quoteIdent2(name) {
|
|
120
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
121
|
+
}
|
|
122
|
+
__name(quoteIdent2, "quoteIdent");
|
|
123
|
+
function sqliteErrorOffset(message) {
|
|
124
|
+
const marker = "offset ";
|
|
125
|
+
const start = message.indexOf(marker);
|
|
126
|
+
if (start < 0) return null;
|
|
127
|
+
let index = start + marker.length;
|
|
128
|
+
let digits = "";
|
|
129
|
+
while (index < message.length) {
|
|
130
|
+
const code = message.charCodeAt(index);
|
|
131
|
+
if (code < 48 || code > 57) break;
|
|
132
|
+
digits += message[index];
|
|
133
|
+
index++;
|
|
134
|
+
}
|
|
135
|
+
if (!digits) return null;
|
|
136
|
+
const offset = Number(digits);
|
|
137
|
+
return Number.isFinite(offset) ? offset : null;
|
|
138
|
+
}
|
|
139
|
+
__name(sqliteErrorOffset, "sqliteErrorOffset");
|
|
140
|
+
function sqlErrorSnippet(sql, message) {
|
|
141
|
+
const offset = sqliteErrorOffset(message);
|
|
142
|
+
if (offset !== null) {
|
|
143
|
+
const start = Math.max(0, offset - SQL_ERROR_SNIPPET_RADIUS);
|
|
144
|
+
const end = Math.min(sql.length, offset + SQL_ERROR_SNIPPET_RADIUS);
|
|
145
|
+
return `${start > 0 ? "..." : ""}${sql.slice(start, end)}${end < sql.length ? "..." : ""}`;
|
|
146
|
+
}
|
|
147
|
+
if (sql.length <= SQL_ERROR_FALLBACK_LIMIT) return sql;
|
|
148
|
+
return `${sql.slice(0, SQL_ERROR_FALLBACK_LIMIT)}...`;
|
|
149
|
+
}
|
|
150
|
+
__name(sqlErrorSnippet, "sqlErrorSnippet");
|
|
151
|
+
var ZeroDO = class extends DurableObject {
|
|
152
|
+
static {
|
|
153
|
+
__name(this, "ZeroDO");
|
|
154
|
+
}
|
|
155
|
+
sql;
|
|
156
|
+
watermarks;
|
|
157
|
+
schemaTables = /* @__PURE__ */ new Set();
|
|
158
|
+
tableSchemas = /* @__PURE__ */ new Map();
|
|
159
|
+
constructor(ctx, env) {
|
|
160
|
+
super(ctx, env);
|
|
161
|
+
this.sql = ctx.storage.sql;
|
|
162
|
+
this.watermarks = new DurableWatermarkState(this.sql);
|
|
163
|
+
}
|
|
164
|
+
async fetch(request) {
|
|
165
|
+
const url = new URL(request.url);
|
|
166
|
+
if (request.method === "OPTIONS") {
|
|
167
|
+
return new Response(null, {
|
|
168
|
+
headers: {
|
|
169
|
+
"Access-Control-Allow-Origin": "*",
|
|
170
|
+
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
171
|
+
"Access-Control-Allow-Headers": "*"
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (url.pathname.startsWith("/sync/v") && url.pathname.endsWith("/connect"))
|
|
176
|
+
return this.handleSyncConnect(request, url);
|
|
177
|
+
if ((url.pathname === "/zero/push" || url.pathname === "/api/zero/push") && request.method === "POST")
|
|
178
|
+
return this.handleHttpPush(request);
|
|
179
|
+
if (url.pathname === "/exec" && request.method === "POST")
|
|
180
|
+
return this.handleExec(request);
|
|
181
|
+
if (url.pathname === "/batch" && request.method === "POST")
|
|
182
|
+
return this.handleBatch(request);
|
|
183
|
+
if (url.pathname === "/changes" && (request.method === "GET" || request.method === "POST"))
|
|
184
|
+
return this.handleChanges(request, url);
|
|
185
|
+
if (url.pathname === "/notify" && request.method === "POST")
|
|
186
|
+
return Response.json({ ok: true, cookie: this.cookie() });
|
|
187
|
+
return new Response("not found", { status: 404 });
|
|
188
|
+
}
|
|
189
|
+
// ── Zero sync protocol ──────────────────────────────────────────────────
|
|
190
|
+
handleSyncConnect(request, url) {
|
|
191
|
+
if (request.headers.get("upgrade")?.toLowerCase() !== "websocket") {
|
|
192
|
+
return new Response("expected websocket upgrade", { status: 426 });
|
|
193
|
+
}
|
|
194
|
+
const pair = new WebSocketPair();
|
|
195
|
+
const client = pair[0];
|
|
196
|
+
const server = pair[1];
|
|
197
|
+
const clientID = url.searchParams.get("clientID") || "anon";
|
|
198
|
+
const clientGroupID = url.searchParams.get("clientGroupID") || "default";
|
|
199
|
+
const userID = url.searchParams.get("userID") || "anon";
|
|
200
|
+
const wsid = url.searchParams.get("wsid") || crypto.randomUUID();
|
|
201
|
+
const baseCookie = url.searchParams.get("baseCookie");
|
|
202
|
+
this.ctx.acceptWebSocket(server);
|
|
203
|
+
server.serializeAttachment({
|
|
204
|
+
clientID,
|
|
205
|
+
clientGroupID,
|
|
206
|
+
userID,
|
|
207
|
+
cookie: baseCookie ? baseCookie : null,
|
|
208
|
+
initialized: false,
|
|
209
|
+
desiredTableNames: [],
|
|
210
|
+
desiredQueries: []
|
|
211
|
+
});
|
|
212
|
+
this.sendJSON(server, ["connected", { wsid, timestamp: Date.now() }]);
|
|
213
|
+
const secProtocol = request.headers.get("sec-websocket-protocol");
|
|
214
|
+
if (secProtocol) {
|
|
215
|
+
const initData = decodeInitConnection(secProtocol);
|
|
216
|
+
if (initData) {
|
|
217
|
+
const clientSchema = initData[1]?.clientSchema;
|
|
218
|
+
const patch = initData[1]?.desiredQueriesPatch || [];
|
|
219
|
+
this.applyDesiredQueries(server, patch, clientSchema);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return new Response(null, {
|
|
223
|
+
status: 101,
|
|
224
|
+
headers: secProtocol ? { "Sec-WebSocket-Protocol": secProtocol } : void 0,
|
|
225
|
+
webSocket: client
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
async webSocketMessage(socket, messageData) {
|
|
229
|
+
this.watermarks.ensureTables();
|
|
230
|
+
const ws = socket;
|
|
231
|
+
const attachment = this.readSocketAttachment(ws);
|
|
232
|
+
if (!attachment) return;
|
|
233
|
+
const message = this.parseMessage(messageData);
|
|
234
|
+
if (!message) return;
|
|
235
|
+
const body = message[1] || {};
|
|
236
|
+
switch (message[0]) {
|
|
237
|
+
case "initConnection":
|
|
238
|
+
case "changeDesiredQueries":
|
|
239
|
+
this.applyDesiredQueries(
|
|
240
|
+
ws,
|
|
241
|
+
body.desiredQueriesPatch || [],
|
|
242
|
+
body.clientSchema
|
|
243
|
+
);
|
|
244
|
+
break;
|
|
245
|
+
case "push":
|
|
246
|
+
this.handlePush(ws, attachment, message[1]);
|
|
247
|
+
break;
|
|
248
|
+
case "pull":
|
|
249
|
+
this.handlePull(ws, message[1]);
|
|
250
|
+
break;
|
|
251
|
+
case "ping":
|
|
252
|
+
this.sendJSON(ws, ["pong", {}]);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
webSocketClose(_socket, _code, _reason, _wasClean) {
|
|
257
|
+
}
|
|
258
|
+
applyDesiredQueries(socket, patch, clientSchema) {
|
|
259
|
+
const attachment = this.readSocketAttachment(socket);
|
|
260
|
+
if (!attachment) return;
|
|
261
|
+
if (clientSchema) this.ensureSchemaTables(clientSchema);
|
|
262
|
+
let nextAttachment = this.applyDesiredQueryPatch(attachment, patch);
|
|
263
|
+
socket.serializeAttachment(nextAttachment);
|
|
264
|
+
if (!nextAttachment.initialized) {
|
|
265
|
+
nextAttachment = this.sendSyncPoke(
|
|
266
|
+
socket,
|
|
267
|
+
{ ...nextAttachment, initialized: true },
|
|
268
|
+
{ lastMutationIDChanges: {}, rowsPatch: [] }
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
if (patch.length === 0) return;
|
|
272
|
+
const rowsPatch = [
|
|
273
|
+
{ op: "clear" },
|
|
274
|
+
...this.rowsPatchForTables(nextAttachment.desiredTableNames)
|
|
275
|
+
];
|
|
276
|
+
this.sendSyncPoke(socket, nextAttachment, {
|
|
277
|
+
gotQueriesPatch: this.gotQueriesPatch(patch),
|
|
278
|
+
rowsPatch
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
applyDesiredQueryPatch(attachment, patch) {
|
|
282
|
+
const desiredQueries = /* @__PURE__ */ new Map();
|
|
283
|
+
for (const query of attachment.desiredQueries || [])
|
|
284
|
+
desiredQueries.set(query.hash, query.tableNames);
|
|
285
|
+
for (const op of patch) {
|
|
286
|
+
if (op.op === "clear") {
|
|
287
|
+
desiredQueries.clear();
|
|
288
|
+
} else if (op.op === "put" && op.hash) {
|
|
289
|
+
desiredQueries.set(op.hash, this.resolveTablesFromPatch([op]));
|
|
290
|
+
} else if (op.op === "del" && op.hash) {
|
|
291
|
+
desiredQueries.delete(op.hash);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const queries = [...desiredQueries.entries()].map(([hash, tableNames]) => ({
|
|
295
|
+
hash,
|
|
296
|
+
tableNames
|
|
297
|
+
}));
|
|
298
|
+
return {
|
|
299
|
+
...attachment,
|
|
300
|
+
desiredQueries: queries,
|
|
301
|
+
desiredTableNames: [...new Set(queries.flatMap((query) => query.tableNames))]
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
gotQueriesPatch(patch) {
|
|
305
|
+
const got = [];
|
|
306
|
+
for (const op of patch) {
|
|
307
|
+
if (op.op === "clear") got.push({ op: "clear" });
|
|
308
|
+
else if (op.hash) got.push({ op: op.op, hash: op.hash });
|
|
309
|
+
}
|
|
310
|
+
return got;
|
|
311
|
+
}
|
|
312
|
+
rowsPatchForTables(tableNames) {
|
|
313
|
+
const rowsPatch = [];
|
|
314
|
+
for (const tn of tableNames) {
|
|
315
|
+
if (!this.tableExists(tn)) continue;
|
|
316
|
+
for (const row of this.readAllRows(tn))
|
|
317
|
+
rowsPatch.push({ op: "put", tableName: tn, value: row });
|
|
318
|
+
}
|
|
319
|
+
return rowsPatch;
|
|
320
|
+
}
|
|
321
|
+
resolveTablesFromPatch(patch) {
|
|
322
|
+
const tables = [];
|
|
323
|
+
for (const op of patch) {
|
|
324
|
+
const tableFromName = this.tableNameFromOperationName(op.name);
|
|
325
|
+
if (tableFromName) tables.push(tableFromName);
|
|
326
|
+
if (op.ast) this.extractTableFromAST(op.ast, tables);
|
|
327
|
+
}
|
|
328
|
+
return tables;
|
|
329
|
+
}
|
|
330
|
+
extractTableFromAST(ast, tables) {
|
|
331
|
+
if (ast?.table) tables.push(ast.table);
|
|
332
|
+
if (ast?.related)
|
|
333
|
+
for (const rel of ast.related) {
|
|
334
|
+
if (rel?.subquery?.table) tables.push(rel.subquery.table);
|
|
335
|
+
if (rel?.subquery?.related) this.extractTableFromAST(rel.subquery, tables);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
handlePush(socket, attachment, body) {
|
|
339
|
+
const mutations = Array.isArray(body?.mutations) ? body.mutations : [];
|
|
340
|
+
const before = this.watermark();
|
|
341
|
+
const mutationResults = [];
|
|
342
|
+
const lastMutationIDChanges = {};
|
|
343
|
+
for (const m of mutations) {
|
|
344
|
+
const result = this.applyMutation(m);
|
|
345
|
+
mutationResults.push({ id: { clientID: m.clientID, id: m.id }, result });
|
|
346
|
+
lastMutationIDChanges[m.clientID] = m.id;
|
|
347
|
+
}
|
|
348
|
+
this.sendJSON(socket, ["pushResponse", { mutations: mutationResults }]);
|
|
349
|
+
const after = this.watermark();
|
|
350
|
+
const changes = after > before ? this.readChangesSince(before) : [];
|
|
351
|
+
const rowsPatch = changes.map((c) => this.syncRowPatchFromChange(c));
|
|
352
|
+
if (Object.keys(lastMutationIDChanges).length > 0 || rowsPatch.length > 0)
|
|
353
|
+
this.broadcastMutationPoke(attachment, {
|
|
354
|
+
lastMutationIDChanges,
|
|
355
|
+
rowsPatch
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
async handleHttpPush(request) {
|
|
359
|
+
try {
|
|
360
|
+
const body = await request.json();
|
|
361
|
+
const before = this.watermark();
|
|
362
|
+
const mutations = Array.isArray(body?.mutations) ? body.mutations : [];
|
|
363
|
+
const mutationResults = [];
|
|
364
|
+
const lastMutationIDChanges = {};
|
|
365
|
+
for (const m of mutations) {
|
|
366
|
+
const result = this.applyMutation(m);
|
|
367
|
+
mutationResults.push({ id: { clientID: m.clientID, id: m.id }, result });
|
|
368
|
+
lastMutationIDChanges[m.clientID] = m.id;
|
|
369
|
+
}
|
|
370
|
+
const after = this.watermark();
|
|
371
|
+
const changes = after > before ? this.readChangesSince(before) : [];
|
|
372
|
+
const rowsPatch = changes.map((c) => this.syncRowPatchFromChange(c));
|
|
373
|
+
if (Object.keys(lastMutationIDChanges).length > 0 || rowsPatch.length > 0)
|
|
374
|
+
this.broadcastPoke(body?.clientGroupID || "default", {
|
|
375
|
+
lastMutationIDChanges,
|
|
376
|
+
rowsPatch
|
|
377
|
+
});
|
|
378
|
+
return Response.json({ mutations: mutationResults });
|
|
379
|
+
} catch (err) {
|
|
380
|
+
return Response.json({ error: err.message }, { status: 500 });
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
handlePull(socket, body) {
|
|
384
|
+
this.sendJSON(socket, [
|
|
385
|
+
"pull",
|
|
386
|
+
{
|
|
387
|
+
requestID: body?.requestID || crypto.randomUUID(),
|
|
388
|
+
cookie: this.cookie(),
|
|
389
|
+
lastMutationIDChanges: {},
|
|
390
|
+
patch: []
|
|
391
|
+
}
|
|
392
|
+
]);
|
|
393
|
+
}
|
|
394
|
+
// ── SQL execution endpoints ─────────────────────────────────────────────
|
|
395
|
+
async handleExec(request) {
|
|
396
|
+
let sql = "";
|
|
397
|
+
try {
|
|
398
|
+
const body = await request.json();
|
|
399
|
+
sql = body.sql;
|
|
400
|
+
const params = Array.isArray(body.params) ? body.params : [];
|
|
401
|
+
const result = body.track ? await this.ctx.storage.transaction(
|
|
402
|
+
() => this.executeSQL(sql, params, body.track)
|
|
403
|
+
) : this.executeSQL(sql, params);
|
|
404
|
+
return Response.json(result);
|
|
405
|
+
} catch (err) {
|
|
406
|
+
const suffix = sql ? ` while executing: ${sqlErrorSnippet(sql, err.message)}` : "";
|
|
407
|
+
console.error(`[exec-500] ${err.message} :: SQL=${sql.slice(0, 800)}`);
|
|
408
|
+
return Response.json({ error: `${err.message}${suffix}` }, { status: 500 });
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/** Execute multiple statements atomically via ctx.storage.transaction() */
|
|
412
|
+
async handleBatch(request) {
|
|
413
|
+
try {
|
|
414
|
+
const { statements } = await request.json();
|
|
415
|
+
const allRows = await this.ctx.storage.transaction(() => {
|
|
416
|
+
const results = [];
|
|
417
|
+
for (const statement of statements) {
|
|
418
|
+
const item = typeof statement === "string" ? { sql: statement } : statement;
|
|
419
|
+
if (!item?.sql?.trim()) continue;
|
|
420
|
+
try {
|
|
421
|
+
results.push(
|
|
422
|
+
this.executeSQL(
|
|
423
|
+
item.sql,
|
|
424
|
+
Array.isArray(item.params) ? item.params : [],
|
|
425
|
+
item.track
|
|
426
|
+
)
|
|
427
|
+
);
|
|
428
|
+
} catch (err) {
|
|
429
|
+
throw new Error(
|
|
430
|
+
`${err.message} while executing: ${sqlErrorSnippet(item.sql, err.message)}`
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return results;
|
|
435
|
+
});
|
|
436
|
+
return Response.json({ results: allRows });
|
|
437
|
+
} catch (err) {
|
|
438
|
+
return Response.json({ error: err.message }, { status: 500 });
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
async handleChanges(request, url) {
|
|
442
|
+
try {
|
|
443
|
+
let watermark = Number(
|
|
444
|
+
url.searchParams.get("watermark") ?? url.searchParams.get("since") ?? 0
|
|
445
|
+
);
|
|
446
|
+
let limit = Number(url.searchParams.get("limit") ?? 1e3);
|
|
447
|
+
if (request.method === "POST") {
|
|
448
|
+
const body = await request.json().catch(() => ({}));
|
|
449
|
+
watermark = Number(body.watermark ?? body.since ?? watermark);
|
|
450
|
+
limit = Number(body.limit ?? limit);
|
|
451
|
+
}
|
|
452
|
+
if (!Number.isFinite(watermark) || watermark < 0) watermark = 0;
|
|
453
|
+
if (!Number.isFinite(limit) || limit <= 0) limit = 1e3;
|
|
454
|
+
return Response.json({
|
|
455
|
+
watermark: this.watermark(),
|
|
456
|
+
changes: this.readChangesSince(watermark).slice(0, Math.min(limit, 1e4))
|
|
457
|
+
});
|
|
458
|
+
} catch (err) {
|
|
459
|
+
return Response.json({ error: err.message }, { status: 500 });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
executeSQL(sql, params = [], track) {
|
|
463
|
+
const cursor = this.sql.exec(sql, ...params);
|
|
464
|
+
const columns = Array.isArray(cursor.columnNames) ? cursor.columnNames : [];
|
|
465
|
+
const rows = this.cursorRows(cursor);
|
|
466
|
+
if (!track) return { rows, columns };
|
|
467
|
+
for (const row of rows) {
|
|
468
|
+
const trackedRow = trackedChangeRow(row, track);
|
|
469
|
+
if (track.operation === "DELETE")
|
|
470
|
+
this.appendTrackedChange(track.tableName, "DELETE", null, trackedRow);
|
|
471
|
+
else this.appendTrackedChange(track.tableName, track.operation, trackedRow, null);
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
rows: track.returnRows ? rows : [],
|
|
475
|
+
columns: track.returnRows ? columns : [],
|
|
476
|
+
affectedRows: rows.length
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
cursorRows(cursor) {
|
|
480
|
+
return cursor.toArray().map((row) => {
|
|
481
|
+
const obj = {};
|
|
482
|
+
for (const k of Object.keys(row)) obj[k] = row[k];
|
|
483
|
+
return obj;
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
// ── CRUD operations ──────────────────────────────────────────────────────
|
|
487
|
+
applyMutation(mutation) {
|
|
488
|
+
if (mutation.type === "crud" && mutation.name === "_zero_crud") {
|
|
489
|
+
return this.applyCrudMutation(mutation);
|
|
490
|
+
}
|
|
491
|
+
if (mutation.name === "_zero_cleanupResults") return {};
|
|
492
|
+
if (mutation.type === "custom") return this.applyTableMutation(mutation);
|
|
493
|
+
return {
|
|
494
|
+
error: "app",
|
|
495
|
+
message: `unsupported mutation ${mutation.type}:${mutation.name}`
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
applyTableMutation(mutation) {
|
|
499
|
+
const [tableName, action] = this.tableActionFromMutationName(mutation.name);
|
|
500
|
+
if (!tableName || !action)
|
|
501
|
+
return { error: "app", message: `invalid mutation name ${mutation.name}` };
|
|
502
|
+
if (!this.tableExists(tableName))
|
|
503
|
+
return { error: "app", message: `unknown table ${tableName}` };
|
|
504
|
+
const value = mutation.args[0] || {};
|
|
505
|
+
const primaryKey = this.primaryKeyForTable(tableName, []);
|
|
506
|
+
if (action === "insert") this.insertRow(tableName, value, primaryKey);
|
|
507
|
+
else if (action === "upsert") this.upsertRow(tableName, value, primaryKey);
|
|
508
|
+
else if (action === "delete") this.deleteRow(tableName, value, primaryKey);
|
|
509
|
+
else this.updateRow(tableName, value, primaryKey);
|
|
510
|
+
return {};
|
|
511
|
+
}
|
|
512
|
+
tableActionFromMutationName(name) {
|
|
513
|
+
if (name.includes("|")) return name.split("|", 2);
|
|
514
|
+
return name.split(".", 2);
|
|
515
|
+
}
|
|
516
|
+
tableNameFromOperationName(name) {
|
|
517
|
+
if (!name) return null;
|
|
518
|
+
return name.split(/[.|]/, 1)[0] || null;
|
|
519
|
+
}
|
|
520
|
+
applyCrudMutation(mutation) {
|
|
521
|
+
const arg = mutation.args[0];
|
|
522
|
+
const ops = Array.isArray(arg?.ops) ? arg.ops : [];
|
|
523
|
+
for (const crud of ops) {
|
|
524
|
+
if (!crud?.tableName) return { error: "app", message: "invalid crud mutation" };
|
|
525
|
+
if (!this.tableExists(crud.tableName))
|
|
526
|
+
return { error: "app", message: `unknown table ${crud.tableName}` };
|
|
527
|
+
const value = crud.value || {};
|
|
528
|
+
const primaryKey = this.primaryKeyForTable(crud.tableName, crud.primaryKey || []);
|
|
529
|
+
if (crud.op === "insert") this.insertRow(crud.tableName, value, primaryKey);
|
|
530
|
+
else if (crud.op === "upsert") this.upsertRow(crud.tableName, value, primaryKey);
|
|
531
|
+
else if (crud.op === "update") this.updateRow(crud.tableName, value, primaryKey);
|
|
532
|
+
else if (crud.op === "delete") this.deleteRow(crud.tableName, value, primaryKey);
|
|
533
|
+
}
|
|
534
|
+
return {};
|
|
535
|
+
}
|
|
536
|
+
insertRow(tn, value, pk) {
|
|
537
|
+
if (this.readRowByPrimaryKey(tn, value, pk)) return;
|
|
538
|
+
const row = this.storageRow(tn, value, true);
|
|
539
|
+
const cols = Object.keys(row);
|
|
540
|
+
if (!cols.length) return;
|
|
541
|
+
const qc = cols.map((c) => quoteIdent2(c)).join(", ");
|
|
542
|
+
const ph = cols.map(() => "?").join(", ");
|
|
543
|
+
this.sql.exec(
|
|
544
|
+
`INSERT INTO ${quoteIdent2(tn)} (${qc}) VALUES (${ph})`,
|
|
545
|
+
...cols.map((c) => row[c])
|
|
546
|
+
);
|
|
547
|
+
const next = this.readRowByPrimaryKey(tn, value, pk) || this.normalizeRow(tn, row);
|
|
548
|
+
this.appendChange(tn, "INSERT", next, null);
|
|
549
|
+
}
|
|
550
|
+
upsertRow(tn, value, pk) {
|
|
551
|
+
const existing = this.readRowByPrimaryKey(tn, value, pk);
|
|
552
|
+
if (existing) {
|
|
553
|
+
this.updateRow(tn, value, pk);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
this.insertRow(tn, value, pk);
|
|
557
|
+
}
|
|
558
|
+
updateRow(tn, value, pk) {
|
|
559
|
+
if (!pk.length) return;
|
|
560
|
+
const existing = this.readRowByPrimaryKey(tn, value, pk);
|
|
561
|
+
if (!existing) return;
|
|
562
|
+
const nk = Object.keys(value).filter((c) => !pk.includes(c));
|
|
563
|
+
if (!nk.length) return;
|
|
564
|
+
const storage = this.storageRow(tn, value, false);
|
|
565
|
+
this.sql.exec(
|
|
566
|
+
`UPDATE ${quoteIdent2(tn)} SET ${nk.map((c) => `${quoteIdent2(c)} = ?`).join(", ")} WHERE ${this.primaryKeyWhere(pk)}`,
|
|
567
|
+
...nk.map((c) => storage[c]),
|
|
568
|
+
...pk.map((c) => this.storageColumnValue(tn, c, value[c]))
|
|
569
|
+
);
|
|
570
|
+
const next = this.readRowByPrimaryKey(tn, value, pk);
|
|
571
|
+
if (next) this.appendChange(tn, "UPDATE", next, existing);
|
|
572
|
+
}
|
|
573
|
+
deleteRow(tn, value, pk) {
|
|
574
|
+
if (!pk.length) return;
|
|
575
|
+
const existing = this.readRowByPrimaryKey(tn, value, pk);
|
|
576
|
+
if (!existing) return;
|
|
577
|
+
this.sql.exec(
|
|
578
|
+
`DELETE FROM ${quoteIdent2(tn)} WHERE ${this.primaryKeyWhere(pk)}`,
|
|
579
|
+
...pk.map((c) => this.storageColumnValue(tn, c, value[c]))
|
|
580
|
+
);
|
|
581
|
+
this.appendChange(tn, "DELETE", null, existing);
|
|
582
|
+
}
|
|
583
|
+
appendChange(tn, op, rowData, oldData) {
|
|
584
|
+
this.appendTrackedChange(tn, op, rowData, oldData);
|
|
585
|
+
}
|
|
586
|
+
appendTrackedChange(tableName, op, rowData, oldData) {
|
|
587
|
+
this.watermarks.ensureTables();
|
|
588
|
+
const watermark = this.watermarks.next();
|
|
589
|
+
this.sql.exec(
|
|
590
|
+
"INSERT INTO _zero_changes (watermark, table_name, op, row_data, old_data) VALUES (?, ?, ?, ?, ?)",
|
|
591
|
+
watermark,
|
|
592
|
+
tableName,
|
|
593
|
+
op,
|
|
594
|
+
rowData ? JSON.stringify(rowData) : null,
|
|
595
|
+
oldData ? JSON.stringify(oldData) : null
|
|
596
|
+
);
|
|
597
|
+
this.watermarks.mark(watermark);
|
|
598
|
+
}
|
|
599
|
+
readChangesSince(watermark) {
|
|
600
|
+
this.watermarks.ensureTables();
|
|
601
|
+
return this.sql.exec(
|
|
602
|
+
"SELECT watermark, table_name, op, row_data, old_data FROM _zero_changes WHERE watermark > ? ORDER BY watermark",
|
|
603
|
+
watermark
|
|
604
|
+
).toArray().map((row) => ({
|
|
605
|
+
watermark: Number(row.watermark),
|
|
606
|
+
tableName: String(row.table_name),
|
|
607
|
+
op: String(row.op),
|
|
608
|
+
rowData: row.row_data ? JSON.parse(String(row.row_data)) : null,
|
|
609
|
+
oldData: row.old_data ? JSON.parse(String(row.old_data)) : null
|
|
610
|
+
}));
|
|
611
|
+
}
|
|
612
|
+
watermark() {
|
|
613
|
+
return this.watermarks.current();
|
|
614
|
+
}
|
|
615
|
+
ensureSchemaTables(clientSchema) {
|
|
616
|
+
this.ensureSchemaMetadataTable();
|
|
617
|
+
for (const [name, def] of Object.entries(clientSchema.tables)) {
|
|
618
|
+
this.tableSchemas.set(name, def);
|
|
619
|
+
this.sql.exec(
|
|
620
|
+
"INSERT OR REPLACE INTO _zero_schema_tables (name, schema_json) VALUES (?, ?)",
|
|
621
|
+
name,
|
|
622
|
+
JSON.stringify(def)
|
|
623
|
+
);
|
|
624
|
+
if (this.schemaTables.has(name)) continue;
|
|
625
|
+
const pk = def.primaryKey.map((c) => quoteIdent2(c));
|
|
626
|
+
const pkClause = pk.length ? `, PRIMARY KEY (${pk.join(", ")})` : "";
|
|
627
|
+
const colDefs = Object.entries(def.columns).map(([cn, cd]) => {
|
|
628
|
+
const t = {
|
|
629
|
+
string: "TEXT",
|
|
630
|
+
number: "REAL",
|
|
631
|
+
boolean: "INTEGER",
|
|
632
|
+
json: "TEXT",
|
|
633
|
+
bigint: "TEXT"
|
|
634
|
+
};
|
|
635
|
+
return `${quoteIdent2(cn)} ${t[cd.type] || "TEXT"}`;
|
|
636
|
+
});
|
|
637
|
+
this.sql.exec(
|
|
638
|
+
`CREATE TABLE IF NOT EXISTS ${quoteIdent2(name)} (${colDefs.join(", ")}${pkClause})`
|
|
639
|
+
);
|
|
640
|
+
this.schemaTables.add(name);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
ensureSchemaMetadataTable() {
|
|
644
|
+
this.sql.exec(
|
|
645
|
+
"CREATE TABLE IF NOT EXISTS _zero_schema_tables (name TEXT PRIMARY KEY, schema_json TEXT NOT NULL)"
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
schemaForTable(tableName) {
|
|
649
|
+
const cached = this.tableSchemas.get(tableName);
|
|
650
|
+
if (cached) return cached;
|
|
651
|
+
try {
|
|
652
|
+
this.ensureSchemaMetadataTable();
|
|
653
|
+
const row = this.sql.exec("SELECT schema_json FROM _zero_schema_tables WHERE name = ?", tableName).one();
|
|
654
|
+
if (!row?.schema_json) return void 0;
|
|
655
|
+
const schema = JSON.parse(String(row.schema_json));
|
|
656
|
+
this.tableSchemas.set(tableName, schema);
|
|
657
|
+
return schema;
|
|
658
|
+
} catch {
|
|
659
|
+
return void 0;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
tableExists(n) {
|
|
663
|
+
try {
|
|
664
|
+
return !!this.sql.exec("SELECT name FROM sqlite_master WHERE type='table' AND name=?", n).one();
|
|
665
|
+
} catch {
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
readAllRows(tn) {
|
|
670
|
+
try {
|
|
671
|
+
return this.sql.exec(`SELECT * FROM ${quoteIdent2(tn)}`).toArray().map((row) => this.normalizeRow(tn, row));
|
|
672
|
+
} catch {
|
|
673
|
+
return [];
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
readRowByPrimaryKey(tn, value, pk) {
|
|
677
|
+
if (!pk.length) return null;
|
|
678
|
+
try {
|
|
679
|
+
const row = this.sql.exec(
|
|
680
|
+
`SELECT * FROM ${quoteIdent2(tn)} WHERE ${this.primaryKeyWhere(pk)}`,
|
|
681
|
+
...pk.map((c) => this.storageColumnValue(tn, c, value[c]))
|
|
682
|
+
).one();
|
|
683
|
+
return row ? this.normalizeRow(tn, row) : null;
|
|
684
|
+
} catch {
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
primaryKeyWhere(pk) {
|
|
689
|
+
return pk.map((c) => `${quoteIdent2(c)} = ?`).join(" AND ");
|
|
690
|
+
}
|
|
691
|
+
primaryKeyForTable(tn, fallback) {
|
|
692
|
+
const schema = this.schemaForTable(tn);
|
|
693
|
+
if (schema?.primaryKey?.length) return schema.primaryKey;
|
|
694
|
+
return fallback;
|
|
695
|
+
}
|
|
696
|
+
storageRow(tn, value, includeMissingSchemaColumns) {
|
|
697
|
+
const schema = this.schemaForTable(tn);
|
|
698
|
+
const row = {};
|
|
699
|
+
if (schema && includeMissingSchemaColumns) {
|
|
700
|
+
for (const column of Object.keys(schema.columns))
|
|
701
|
+
row[column] = this.storageColumnValue(tn, column, value[column] ?? null);
|
|
702
|
+
}
|
|
703
|
+
for (const column of Object.keys(value)) {
|
|
704
|
+
if (value[column] !== void 0)
|
|
705
|
+
row[column] = this.storageColumnValue(tn, column, value[column]);
|
|
706
|
+
}
|
|
707
|
+
return row;
|
|
708
|
+
}
|
|
709
|
+
storageColumnValue(tn, column, value) {
|
|
710
|
+
if (value === void 0 || value === null) return null;
|
|
711
|
+
const type = this.schemaForTable(tn)?.columns?.[column]?.type;
|
|
712
|
+
if (type === "boolean") return value ? 1 : 0;
|
|
713
|
+
if (type === "json") return typeof value === "string" ? value : JSON.stringify(value);
|
|
714
|
+
if (type === "number") return Number(value);
|
|
715
|
+
if (type === "bigint") return String(value);
|
|
716
|
+
return value;
|
|
717
|
+
}
|
|
718
|
+
normalizeRow(tn, row) {
|
|
719
|
+
const schema = this.schemaForTable(tn);
|
|
720
|
+
const normalized = {};
|
|
721
|
+
for (const key of Object.keys(row)) {
|
|
722
|
+
const type = schema?.columns?.[key]?.type;
|
|
723
|
+
const value = row[key];
|
|
724
|
+
if (value === null || value === void 0) {
|
|
725
|
+
normalized[key] = null;
|
|
726
|
+
} else if (type === "boolean") {
|
|
727
|
+
normalized[key] = value === true || value === 1 || value === "1" || value === "true";
|
|
728
|
+
} else if (type === "number") {
|
|
729
|
+
normalized[key] = Number(value);
|
|
730
|
+
} else if (type === "json" && typeof value === "string") {
|
|
731
|
+
try {
|
|
732
|
+
normalized[key] = JSON.parse(value);
|
|
733
|
+
} catch {
|
|
734
|
+
normalized[key] = value;
|
|
735
|
+
}
|
|
736
|
+
} else {
|
|
737
|
+
normalized[key] = value;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return normalized;
|
|
741
|
+
}
|
|
742
|
+
sendSyncPoke(socket, attachment, part) {
|
|
743
|
+
const cookie = this.nextCookie();
|
|
744
|
+
const pokeID = crypto.randomUUID();
|
|
745
|
+
this.sendJSON(socket, [
|
|
746
|
+
"pokeStart",
|
|
747
|
+
{
|
|
748
|
+
pokeID,
|
|
749
|
+
baseCookie: attachment.cookie,
|
|
750
|
+
schemaVersions: {
|
|
751
|
+
minSupportedVersion: SCHEMA_VERSION,
|
|
752
|
+
maxSupportedVersion: SCHEMA_VERSION
|
|
753
|
+
},
|
|
754
|
+
timestamp: Date.now()
|
|
755
|
+
}
|
|
756
|
+
]);
|
|
757
|
+
this.sendJSON(socket, ["pokePart", { pokeID, ...part }]);
|
|
758
|
+
this.sendJSON(socket, ["pokeEnd", { pokeID, cookie }]);
|
|
759
|
+
const nextAttachment = { ...attachment, cookie };
|
|
760
|
+
socket.serializeAttachment(nextAttachment);
|
|
761
|
+
return nextAttachment;
|
|
762
|
+
}
|
|
763
|
+
broadcastPoke(clientGroupID, part) {
|
|
764
|
+
for (const socket of this.ctx.getWebSockets()) {
|
|
765
|
+
const ws = socket;
|
|
766
|
+
const attachment = this.readSocketAttachment(ws);
|
|
767
|
+
if (!attachment) continue;
|
|
768
|
+
if (attachment.clientGroupID !== clientGroupID) continue;
|
|
769
|
+
this.sendSyncPoke(ws, attachment, part);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
broadcastMutationPoke(sourceAttachment, part) {
|
|
773
|
+
const rowsPatch = part.rowsPatch || [];
|
|
774
|
+
const changedTables = new Set(
|
|
775
|
+
rowsPatch.map((op) => op?.tableName).filter((tableName) => !!tableName)
|
|
776
|
+
);
|
|
777
|
+
const hasLastMutationIDChanges = Object.keys(part.lastMutationIDChanges || {}).length > 0;
|
|
778
|
+
for (const socket of this.ctx.getWebSockets()) {
|
|
779
|
+
const ws = socket;
|
|
780
|
+
const attachment = this.readSocketAttachment(ws);
|
|
781
|
+
if (!attachment) continue;
|
|
782
|
+
if (attachment.userID !== sourceAttachment.userID) continue;
|
|
783
|
+
const isSourceClientGroup = attachment.clientGroupID === sourceAttachment.clientGroupID;
|
|
784
|
+
const wantsChangedRows = changedTables.size > 0 && attachment.desiredTableNames.some((tableName) => changedTables.has(tableName));
|
|
785
|
+
const nextPart = {};
|
|
786
|
+
if (wantsChangedRows) nextPart.rowsPatch = rowsPatch;
|
|
787
|
+
if (isSourceClientGroup && hasLastMutationIDChanges)
|
|
788
|
+
nextPart.lastMutationIDChanges = part.lastMutationIDChanges;
|
|
789
|
+
if (!nextPart.rowsPatch && !nextPart.lastMutationIDChanges) continue;
|
|
790
|
+
this.sendSyncPoke(ws, attachment, nextPart);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
syncRowPatchFromChange(change) {
|
|
794
|
+
if (change.op === "DELETE")
|
|
795
|
+
return {
|
|
796
|
+
op: "del",
|
|
797
|
+
tableName: change.tableName,
|
|
798
|
+
id: this.primaryKeyValue(change.tableName, change.oldData || {})
|
|
799
|
+
};
|
|
800
|
+
return {
|
|
801
|
+
op: "put",
|
|
802
|
+
tableName: change.tableName,
|
|
803
|
+
value: this.normalizeRow(change.tableName, change.rowData || {})
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
primaryKeyValue(tableName, row) {
|
|
807
|
+
const pk = this.primaryKeyForTable(tableName, []);
|
|
808
|
+
if (pk.length) return Object.fromEntries(pk.map((column) => [column, row[column]]));
|
|
809
|
+
if ("id" in row) return { id: row.id };
|
|
810
|
+
return row;
|
|
811
|
+
}
|
|
812
|
+
cookie() {
|
|
813
|
+
return String(this.watermark()).padStart(20, "0");
|
|
814
|
+
}
|
|
815
|
+
nextCookie() {
|
|
816
|
+
const watermark = this.watermarks.next();
|
|
817
|
+
this.watermarks.mark(watermark);
|
|
818
|
+
return String(watermark).padStart(20, "0");
|
|
819
|
+
}
|
|
820
|
+
readSocketAttachment(socket) {
|
|
821
|
+
const attachment = socket.deserializeAttachment();
|
|
822
|
+
if (!attachment) return null;
|
|
823
|
+
return {
|
|
824
|
+
...attachment,
|
|
825
|
+
initialized: attachment.initialized === true,
|
|
826
|
+
desiredTableNames: attachment.desiredTableNames || [],
|
|
827
|
+
desiredQueries: attachment.desiredQueries || []
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
sendJSON(socket, msg) {
|
|
831
|
+
try {
|
|
832
|
+
socket.send(JSON.stringify(msg));
|
|
833
|
+
} catch {
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
parseMessage(data) {
|
|
837
|
+
try {
|
|
838
|
+
return JSON.parse(typeof data === "string" ? data : new TextDecoder().decode(data));
|
|
839
|
+
} catch {
|
|
840
|
+
return null;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
var worker_default = {
|
|
845
|
+
async fetch(request, env) {
|
|
846
|
+
const url = new URL(request.url);
|
|
847
|
+
const id = env.ZERO_DO.idFromName("singleton");
|
|
848
|
+
if (url.pathname.startsWith("/sync/v") && url.pathname.endsWith("/connect")) {
|
|
849
|
+
return env.ZERO_DO.get(id).fetch(request);
|
|
850
|
+
}
|
|
851
|
+
if ((url.pathname === "/zero/push" || url.pathname === "/api/zero/push") && request.method === "POST") {
|
|
852
|
+
return env.ZERO_DO.get(id).fetch(request);
|
|
853
|
+
}
|
|
854
|
+
if (url.pathname === "/exec" && request.method === "POST") {
|
|
855
|
+
return env.ZERO_DO.get(id).fetch(request);
|
|
856
|
+
}
|
|
857
|
+
if (url.pathname === "/batch" && request.method === "POST") {
|
|
858
|
+
return env.ZERO_DO.get(id).fetch(request);
|
|
859
|
+
}
|
|
860
|
+
if (url.pathname === "/changes" && (request.method === "GET" || request.method === "POST")) {
|
|
861
|
+
return env.ZERO_DO.get(id).fetch(request);
|
|
862
|
+
}
|
|
863
|
+
if (url.pathname === "/notify" && request.method === "POST") {
|
|
864
|
+
return env.ZERO_DO.get(id).fetch(request);
|
|
865
|
+
}
|
|
866
|
+
return new Response("not found", { status: 404 });
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
function decodeInitConnection(secProtocol) {
|
|
870
|
+
try {
|
|
871
|
+
const decoded = decodeURIComponent(secProtocol);
|
|
872
|
+
const bytes = Uint8Array.from(atob(decoded), (char) => char.charCodeAt(0));
|
|
873
|
+
const protocols = JSON.parse(new TextDecoder().decode(bytes));
|
|
874
|
+
const message = protocols.initConnectionMessage;
|
|
875
|
+
if (Array.isArray(message) && message[0] === "initConnection") {
|
|
876
|
+
return message;
|
|
877
|
+
}
|
|
878
|
+
return null;
|
|
879
|
+
} catch {
|
|
880
|
+
return null;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
__name(decodeInitConnection, "decodeInitConnection");
|
|
884
|
+
|
|
885
|
+
// ../../../soot/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts
|
|
886
|
+
var drainBody = /* @__PURE__ */ __name(async (request, env, _ctx, middlewareCtx) => {
|
|
887
|
+
try {
|
|
888
|
+
return await middlewareCtx.next(request, env);
|
|
889
|
+
} finally {
|
|
890
|
+
try {
|
|
891
|
+
if (request.body !== null && !request.bodyUsed) {
|
|
892
|
+
const reader = request.body.getReader();
|
|
893
|
+
while (!(await reader.read()).done) {
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
} catch (e) {
|
|
897
|
+
console.error("Failed to drain the unused request body.", e);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}, "drainBody");
|
|
901
|
+
var middleware_ensure_req_body_drained_default = drainBody;
|
|
902
|
+
|
|
903
|
+
// ../../../soot/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts
|
|
904
|
+
function reduceError(e) {
|
|
905
|
+
return {
|
|
906
|
+
name: e?.name,
|
|
907
|
+
message: e?.message ?? String(e),
|
|
908
|
+
stack: e?.stack,
|
|
909
|
+
cause: e?.cause === void 0 ? void 0 : reduceError(e.cause)
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
__name(reduceError, "reduceError");
|
|
913
|
+
var jsonError = /* @__PURE__ */ __name(async (request, env, _ctx, middlewareCtx) => {
|
|
914
|
+
try {
|
|
915
|
+
return await middlewareCtx.next(request, env);
|
|
916
|
+
} catch (e) {
|
|
917
|
+
const error = reduceError(e);
|
|
918
|
+
return Response.json(error, {
|
|
919
|
+
status: 500,
|
|
920
|
+
headers: { "MF-Experimental-Error-Stack": "true" }
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
}, "jsonError");
|
|
924
|
+
var middleware_miniflare3_json_error_default = jsonError;
|
|
925
|
+
|
|
926
|
+
// .wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js
|
|
927
|
+
var __INTERNAL_WRANGLER_MIDDLEWARE__ = [
|
|
928
|
+
middleware_ensure_req_body_drained_default,
|
|
929
|
+
middleware_miniflare3_json_error_default
|
|
930
|
+
];
|
|
931
|
+
var middleware_insertion_facade_default = worker_default;
|
|
932
|
+
|
|
933
|
+
// ../../../soot/node_modules/wrangler/templates/middleware/common.ts
|
|
934
|
+
var __facade_middleware__ = [];
|
|
935
|
+
function __facade_register__(...args) {
|
|
936
|
+
__facade_middleware__.push(...args.flat());
|
|
937
|
+
}
|
|
938
|
+
__name(__facade_register__, "__facade_register__");
|
|
939
|
+
function __facade_invokeChain__(request, env, ctx, dispatch, middlewareChain) {
|
|
940
|
+
const [head, ...tail] = middlewareChain;
|
|
941
|
+
const middlewareCtx = {
|
|
942
|
+
dispatch,
|
|
943
|
+
next(newRequest, newEnv) {
|
|
944
|
+
return __facade_invokeChain__(newRequest, newEnv, ctx, dispatch, tail);
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
return head(request, env, ctx, middlewareCtx);
|
|
948
|
+
}
|
|
949
|
+
__name(__facade_invokeChain__, "__facade_invokeChain__");
|
|
950
|
+
function __facade_invoke__(request, env, ctx, dispatch, finalMiddleware) {
|
|
951
|
+
return __facade_invokeChain__(request, env, ctx, dispatch, [
|
|
952
|
+
...__facade_middleware__,
|
|
953
|
+
finalMiddleware
|
|
954
|
+
]);
|
|
955
|
+
}
|
|
956
|
+
__name(__facade_invoke__, "__facade_invoke__");
|
|
957
|
+
|
|
958
|
+
// .wrangler/tmp/bundle-vYmw0E/middleware-loader.entry.ts
|
|
959
|
+
var __Facade_ScheduledController__ = class ___Facade_ScheduledController__ {
|
|
960
|
+
constructor(scheduledTime, cron, noRetry) {
|
|
961
|
+
this.scheduledTime = scheduledTime;
|
|
962
|
+
this.cron = cron;
|
|
963
|
+
this.#noRetry = noRetry;
|
|
964
|
+
}
|
|
965
|
+
static {
|
|
966
|
+
__name(this, "__Facade_ScheduledController__");
|
|
967
|
+
}
|
|
968
|
+
#noRetry;
|
|
969
|
+
noRetry() {
|
|
970
|
+
if (!(this instanceof ___Facade_ScheduledController__)) {
|
|
971
|
+
throw new TypeError("Illegal invocation");
|
|
972
|
+
}
|
|
973
|
+
this.#noRetry();
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
function wrapExportedHandler(worker) {
|
|
977
|
+
if (__INTERNAL_WRANGLER_MIDDLEWARE__ === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0) {
|
|
978
|
+
return worker;
|
|
979
|
+
}
|
|
980
|
+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
|
981
|
+
__facade_register__(middleware);
|
|
982
|
+
}
|
|
983
|
+
const fetchDispatcher = /* @__PURE__ */ __name(function(request, env, ctx) {
|
|
984
|
+
if (worker.fetch === void 0) {
|
|
985
|
+
throw new Error("Handler does not export a fetch() function.");
|
|
986
|
+
}
|
|
987
|
+
return worker.fetch(request, env, ctx);
|
|
988
|
+
}, "fetchDispatcher");
|
|
989
|
+
return {
|
|
990
|
+
...worker,
|
|
991
|
+
fetch(request, env, ctx) {
|
|
992
|
+
const dispatcher = /* @__PURE__ */ __name(function(type, init) {
|
|
993
|
+
if (type === "scheduled" && worker.scheduled !== void 0) {
|
|
994
|
+
const controller = new __Facade_ScheduledController__(
|
|
995
|
+
Date.now(),
|
|
996
|
+
init.cron ?? "",
|
|
997
|
+
() => {
|
|
998
|
+
}
|
|
999
|
+
);
|
|
1000
|
+
return worker.scheduled(controller, env, ctx);
|
|
1001
|
+
}
|
|
1002
|
+
}, "dispatcher");
|
|
1003
|
+
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
__name(wrapExportedHandler, "wrapExportedHandler");
|
|
1008
|
+
function wrapWorkerEntrypoint(klass) {
|
|
1009
|
+
if (__INTERNAL_WRANGLER_MIDDLEWARE__ === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0) {
|
|
1010
|
+
return klass;
|
|
1011
|
+
}
|
|
1012
|
+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
|
1013
|
+
__facade_register__(middleware);
|
|
1014
|
+
}
|
|
1015
|
+
return class extends klass {
|
|
1016
|
+
#fetchDispatcher = /* @__PURE__ */ __name((request, env, ctx) => {
|
|
1017
|
+
this.env = env;
|
|
1018
|
+
this.ctx = ctx;
|
|
1019
|
+
if (super.fetch === void 0) {
|
|
1020
|
+
throw new Error("Entrypoint class does not define a fetch() function.");
|
|
1021
|
+
}
|
|
1022
|
+
return super.fetch(request);
|
|
1023
|
+
}, "#fetchDispatcher");
|
|
1024
|
+
#dispatcher = /* @__PURE__ */ __name((type, init) => {
|
|
1025
|
+
if (type === "scheduled" && super.scheduled !== void 0) {
|
|
1026
|
+
const controller = new __Facade_ScheduledController__(
|
|
1027
|
+
Date.now(),
|
|
1028
|
+
init.cron ?? "",
|
|
1029
|
+
() => {
|
|
1030
|
+
}
|
|
1031
|
+
);
|
|
1032
|
+
return super.scheduled(controller);
|
|
1033
|
+
}
|
|
1034
|
+
}, "#dispatcher");
|
|
1035
|
+
fetch(request) {
|
|
1036
|
+
return __facade_invoke__(
|
|
1037
|
+
request,
|
|
1038
|
+
this.env,
|
|
1039
|
+
this.ctx,
|
|
1040
|
+
this.#dispatcher,
|
|
1041
|
+
this.#fetchDispatcher
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
__name(wrapWorkerEntrypoint, "wrapWorkerEntrypoint");
|
|
1047
|
+
var WRAPPED_ENTRY;
|
|
1048
|
+
if (typeof middleware_insertion_facade_default === "object") {
|
|
1049
|
+
WRAPPED_ENTRY = wrapExportedHandler(middleware_insertion_facade_default);
|
|
1050
|
+
} else if (typeof middleware_insertion_facade_default === "function") {
|
|
1051
|
+
WRAPPED_ENTRY = wrapWorkerEntrypoint(middleware_insertion_facade_default);
|
|
1052
|
+
}
|
|
1053
|
+
var middleware_loader_entry_default = WRAPPED_ENTRY;
|
|
1054
|
+
export {
|
|
1055
|
+
ZeroDO,
|
|
1056
|
+
__INTERNAL_WRANGLER_MIDDLEWARE__,
|
|
1057
|
+
middleware_loader_entry_default as default
|
|
1058
|
+
};
|
|
1059
|
+
//# sourceMappingURL=worker.js.map
|