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.
Files changed (150) hide show
  1. package/package.json +3 -4
  2. package/src/admin/admin-data.test.ts +0 -348
  3. package/src/admin/http-proxy.ts +0 -252
  4. package/src/admin/log-store.ts +0 -192
  5. package/src/admin/server.ts +0 -471
  6. package/src/admin/ui.ts +0 -1322
  7. package/src/bench/proxy-throughput.bench.ts +0 -343
  8. package/src/bench/serial-mutations.bench.ts +0 -270
  9. package/src/browser.ts +0 -203
  10. package/src/cf-do/.wrangler/cache/cf.json +0 -1
  11. package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite +0 -0
  12. package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite-shm +0 -0
  13. package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite-wal +0 -0
  14. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/0ffaabee41a60e04dd0eb7db3073f0a40139e6a97ccd26823967acb652b89a7b.sqlite +0 -0
  15. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite +0 -0
  16. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite-shm +0 -0
  17. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite-wal +0 -0
  18. package/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-insertion-facade.js +0 -11
  19. package/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-loader.entry.ts +0 -134
  20. package/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js +0 -11
  21. package/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-loader.entry.ts +0 -134
  22. package/src/cf-do/.wrangler/tmp/dev-cbILNo/worker.js +0 -1059
  23. package/src/cf-do/.wrangler/tmp/dev-cbILNo/worker.js.map +0 -8
  24. package/src/cf-do/.wrangler/tmp/dev-qbho19/worker.js +0 -1059
  25. package/src/cf-do/.wrangler/tmp/dev-qbho19/worker.js.map +0 -8
  26. package/src/cf-do/ARCHITECTURE.md +0 -93
  27. package/src/cf-do/CHAT_E2E.md +0 -213
  28. package/src/cf-do/watermark.test.ts +0 -103
  29. package/src/cf-do/watermark.ts +0 -118
  30. package/src/cf-do/worker.ts +0 -1041
  31. package/src/cf-do/wrangler.toml +0 -11
  32. package/src/cf-pglite/README.md +0 -19
  33. package/src/change-tracking.ts +0 -25
  34. package/src/child-process.test.ts +0 -147
  35. package/src/child-process.ts +0 -90
  36. package/src/cli-entry.ts +0 -72
  37. package/src/cli.test.ts +0 -40
  38. package/src/cli.ts +0 -1214
  39. package/src/config.ts +0 -150
  40. package/src/do-sql-tracking.test.ts +0 -19
  41. package/src/do-sql-tracking.ts +0 -19
  42. package/src/index.ts +0 -1215
  43. package/src/integration/integration.test.ts +0 -517
  44. package/src/integration/native-binary.guard.test.ts +0 -13
  45. package/src/integration/native-startup.test.ts +0 -44
  46. package/src/integration/replication-latency.test.ts +0 -428
  47. package/src/integration/restore-live-stress.test.ts +0 -433
  48. package/src/integration/restore-reset.test.ts +0 -400
  49. package/src/integration/restore.test.ts +0 -274
  50. package/src/integration/test-permissions.ts +0 -147
  51. package/src/load-config.ts +0 -46
  52. package/src/log.ts +0 -96
  53. package/src/mutex.ts +0 -47
  54. package/src/pg-proxy-browser.singledb.test.ts +0 -233
  55. package/src/pg-proxy-browser.ts +0 -2022
  56. package/src/pg-proxy-do-backend.test.ts +0 -3890
  57. package/src/pg-proxy-do-backend.ts +0 -7191
  58. package/src/pg-proxy.ts +0 -1087
  59. package/src/pg-sqlite-compiler/README.md +0 -53
  60. package/src/pg-sqlite-compiler/catalog/seed.ts +0 -524
  61. package/src/pg-sqlite-compiler/fixtures/pgsqlite/arithmetic.json +0 -307
  62. package/src/pg-sqlite-compiler/fixtures/pgsqlite/array.json +0 -377
  63. package/src/pg-sqlite-compiler/fixtures/pgsqlite/cast.json +0 -12
  64. package/src/pg-sqlite-compiler/fixtures/pgsqlite/catalog.json +0 -447
  65. package/src/pg-sqlite-compiler/fixtures/pgsqlite/create-table.json +0 -32
  66. package/src/pg-sqlite-compiler/fixtures/pgsqlite/datetime.json +0 -397
  67. package/src/pg-sqlite-compiler/fixtures/pgsqlite/enum.json +0 -337
  68. package/src/pg-sqlite-compiler/fixtures/pgsqlite/insert.json +0 -337
  69. package/src/pg-sqlite-compiler/fixtures/pgsqlite/json.json +0 -537
  70. package/src/pg-sqlite-compiler/fixtures/pgsqlite/misc.json +0 -1837
  71. package/src/pg-sqlite-compiler/index.ts +0 -73
  72. package/src/pg-sqlite-compiler/integration.test.ts +0 -136
  73. package/src/pg-sqlite-compiler/passes/ast-utils.ts +0 -113
  74. package/src/pg-sqlite-compiler/passes/catalog.ts +0 -65
  75. package/src/pg-sqlite-compiler/passes/datetime.ts +0 -74
  76. package/src/pg-sqlite-compiler/passes/index.ts +0 -49
  77. package/src/pg-sqlite-compiler/passes/types.ts +0 -156
  78. package/src/pg-sqlite-compiler/smoke.test.ts +0 -69
  79. package/src/pg-sqlite-compiler/test/catalog.test.ts +0 -171
  80. package/src/pg-sqlite-compiler/test/corpus.test.ts +0 -161
  81. package/src/pg-sqlite-compiler/test/datetime.oracle.test.ts +0 -102
  82. package/src/pg-sqlite-compiler/test/oracle.ts +0 -237
  83. package/src/pg-sqlite-compiler/test/types.test.ts +0 -109
  84. package/src/pg-sqlite-compiler/types.ts +0 -63
  85. package/src/pglite-ipc.test.ts +0 -116
  86. package/src/pglite-ipc.ts +0 -266
  87. package/src/pglite-manager.ts +0 -557
  88. package/src/pglite-web-proxy.test.ts +0 -57
  89. package/src/pglite-web-proxy.ts +0 -221
  90. package/src/pglite-web-worker.ts +0 -152
  91. package/src/pglite-worker-thread.ts +0 -253
  92. package/src/port.ts +0 -25
  93. package/src/process-title.ts +0 -9
  94. package/src/recovery.ts +0 -155
  95. package/src/replication/change-tracker.test.ts +0 -357
  96. package/src/replication/change-tracker.ts +0 -279
  97. package/src/replication/handler.test.ts +0 -511
  98. package/src/replication/handler.ts +0 -1190
  99. package/src/replication/pgoutput-encoder.test.ts +0 -697
  100. package/src/replication/pgoutput-encoder.ts +0 -373
  101. package/src/replication/tcp-replication.test.ts +0 -876
  102. package/src/replication/zero-compat.test.ts +0 -1150
  103. package/src/restore-stress.test.ts +0 -188
  104. package/src/s3-local.ts +0 -203
  105. package/src/shim/hooks.mjs +0 -120
  106. package/src/shim/register.mjs +0 -4
  107. package/src/sqlite-mode/apply-mode.ts +0 -224
  108. package/src/sqlite-mode/index.ts +0 -15
  109. package/src/sqlite-mode/native-binary.ts +0 -89
  110. package/src/sqlite-mode/package-resolve.ts +0 -17
  111. package/src/sqlite-mode/resolve-mode.ts +0 -80
  112. package/src/sqlite-mode/shim-template.ts +0 -159
  113. package/src/sqlite-mode/sqlite-mode.test.ts +0 -427
  114. package/src/sqlite-mode/types.ts +0 -30
  115. package/src/vite-plugin.ts +0 -67
  116. package/src/wasm-sqlite.test.ts +0 -537
  117. package/src/worker/browser-admin.ts +0 -52
  118. package/src/worker/browser-build-config.test.ts +0 -71
  119. package/src/worker/browser-build-config.ts +0 -109
  120. package/src/worker/browser-embed-admin.test.ts +0 -75
  121. package/src/worker/browser-embed.ts +0 -345
  122. package/src/worker/cf-patches.ts +0 -384
  123. package/src/worker/embed-integration.test.ts +0 -321
  124. package/src/worker/index.ts +0 -138
  125. package/src/worker/shims/fastify.test.ts +0 -255
  126. package/src/worker/shims/fastify.ts +0 -306
  127. package/src/worker/shims/http-service.test.ts +0 -355
  128. package/src/worker/shims/http-service.ts +0 -293
  129. package/src/worker/shims/node-stub.ts +0 -290
  130. package/src/worker/shims/oxfmt.ts +0 -3
  131. package/src/worker/shims/postgres-browser.ts +0 -59
  132. package/src/worker/shims/postgres-socket.test.ts +0 -576
  133. package/src/worker/shims/postgres-socket.ts +0 -310
  134. package/src/worker/shims/postgres.test.ts +0 -364
  135. package/src/worker/shims/postgres.ts +0 -1454
  136. package/src/worker/shims/sqlite-browser.test.ts +0 -233
  137. package/src/worker/shims/sqlite-browser.ts +0 -175
  138. package/src/worker/shims/sqlite.test.ts +0 -786
  139. package/src/worker/shims/sqlite.ts +0 -978
  140. package/src/worker/shims/stream-browser.ts +0 -15
  141. package/src/worker/shims/ws-browser.test.ts +0 -205
  142. package/src/worker/shims/ws-browser.ts +0 -248
  143. package/src/worker/shims/ws.test.ts +0 -288
  144. package/src/worker/shims/ws.ts +0 -467
  145. package/src/worker/shims/zero-process-env.ts +0 -11
  146. package/src/worker/types.ts +0 -75
  147. package/src/worker/worker-integration.test.ts +0 -223
  148. package/src/worker/worker.test.ts +0 -136
  149. package/src/worker/zero-cache-embed-cf.ts +0 -463
  150. package/src/worker/zero-cache-embed.ts +0 -277
package/src/browser.ts DELETED
@@ -1,203 +0,0 @@
1
- /**
2
- * orez browser entry — aligned to orez-node architecture.
3
- *
4
- * mirrors index.ts startup sequence:
5
- * 1. create PGlite Web Workers (3 instances)
6
- * 2. install change tracking
7
- * 3. start pg-proxy-browser (wire protocol proxy)
8
- * 4. start zero-cache (SINGLE_PROCESS=1, connects to proxy)
9
- *
10
- * intended to run inside a Web Worker. PGlite instances run in
11
- * separate Web Workers (like orez-node's worker threads).
12
- */
13
-
14
- import { PGliteWebProxy } from './pglite-web-proxy.js'
15
- import { installChangeTracking } from './replication/change-tracker.js'
16
- import { resetReplicationState } from './replication/handler.js'
17
-
18
- import type { PGlite } from '@electric-sql/pglite'
19
-
20
- export interface OrezBrowserConfig {
21
- /** app ID for zero-cache (default: 'zero') */
22
- appId?: string
23
-
24
- /** publication names for replication */
25
- publications?: string[]
26
-
27
- /** URL for PGlite web worker script */
28
- pgliteWorkerUrl: string
29
-
30
- /** URL for bedrock-sqlite WASM */
31
- bedrockSqliteUrl?: string
32
-
33
- /** init SQL to run on postgres instance after creation */
34
- initSql?: string
35
-
36
- /** log level */
37
- logLevel?: string
38
-
39
- /**
40
- * intercept browser-mode orez admin routes before they reach zero-cache.
41
- * default: true.
42
- */
43
- disableAdminApi?: boolean
44
- }
45
-
46
- export interface OrezBrowserInstance {
47
- /** PGlite proxies (for direct queries from project-server) */
48
- instances: {
49
- postgres: PGliteWebProxy
50
- cvr: PGliteWebProxy
51
- cdb: PGliteWebProxy
52
- }
53
-
54
- /** signal the replication handler that changes are available */
55
- signalReplication(): void
56
-
57
- /** handle a WebSocket connection from a Zero client */
58
- handleWebSocket(ws: any, url?: string, headers?: Record<string, string>): void
59
-
60
- /** handle an HTTP request (push/pull) */
61
- handleHttp(request: {
62
- method: string
63
- url: string
64
- headers?: Record<string, string>
65
- body?: string | null
66
- }): Promise<{ status: number; headers: Record<string, string>; body: string }>
67
-
68
- /** stop everything */
69
- stop(): Promise<void>
70
- }
71
-
72
- export async function startOrezBrowser(
73
- config: OrezBrowserConfig
74
- ): Promise<OrezBrowserInstance> {
75
- const appId = config.appId || 'zero'
76
- const publications = config.publications?.join(',') || `orez_${appId}_public`
77
-
78
- // step 1: create PGlite Web Workers (3 instances, like orez-node)
79
- const pgPostgresWorker = new Worker(config.pgliteWorkerUrl, {
80
- type: 'module',
81
- name: 'pglite-postgres',
82
- })
83
- const pgCvrWorker = new Worker(config.pgliteWorkerUrl, {
84
- type: 'module',
85
- name: 'pglite-cvr',
86
- })
87
- const pgCdbWorker = new Worker(config.pgliteWorkerUrl, {
88
- type: 'module',
89
- name: 'pglite-cdb',
90
- })
91
-
92
- // init each PGlite worker
93
- pgPostgresWorker.postMessage({
94
- type: 'init',
95
- dataDir: 'idb://orez-postgres',
96
- name: 'postgres',
97
- })
98
- pgCvrWorker.postMessage({ type: 'init', dataDir: 'idb://orez-cvr', name: 'cvr' })
99
- pgCdbWorker.postMessage({ type: 'init', dataDir: 'idb://orez-cdb', name: 'cdb' })
100
-
101
- // create proxies (like orez-node's PGliteWorkerProxy)
102
- const pgPostgres = new PGliteWebProxy(pgPostgresWorker, 'postgres')
103
- const pgCvr = new PGliteWebProxy(pgCvrWorker, 'cvr')
104
- const pgCdb = new PGliteWebProxy(pgCdbWorker, 'cdb')
105
-
106
- await Promise.all([pgPostgres.waitReady, pgCvr.waitReady, pgCdb.waitReady])
107
- console.debug('[orez-browser] all 3 PGlite workers ready')
108
-
109
- // step 2: install change tracking (like orez-node)
110
- await installChangeTracking(pgPostgres as unknown as PGlite)
111
- console.debug('[orez-browser] change tracking installed')
112
-
113
- // run user init SQL if provided
114
- if (config.initSql) {
115
- await pgPostgres.exec(config.initSql)
116
- console.debug('[orez-browser] init SQL complete')
117
- }
118
-
119
- // create publication
120
- try {
121
- const pubs = await pgPostgres.query<{ count: string }>(
122
- `SELECT count(*) as count FROM pg_publication WHERE pubname = $1`,
123
- [publications]
124
- )
125
- if (Number(pubs.rows[0]?.count) === 0) {
126
- await pgPostgres.exec(`CREATE PUBLICATION "${publications}"`)
127
- }
128
- } catch {}
129
-
130
- // step 3: start pg-proxy-browser
131
- // the proxy handles wire protocol, replication, mutexes — like orez-node's pg-proxy.
132
- // zero-cache's postgres shim routes queries through this proxy.
133
- const { createBrowserProxy } = await import('./pg-proxy-browser.js')
134
- const proxy = await createBrowserProxy(
135
- {
136
- postgres: pgPostgres as unknown as PGlite,
137
- cvr: pgCvr as unknown as PGlite,
138
- cdb: pgCdb as unknown as PGlite,
139
- postgresReplicas: [],
140
- },
141
- { pgPassword: '', pgUser: 'user' }
142
- )
143
- console.debug('[orez-browser] pg-proxy-browser started')
144
-
145
- // step 4: start zero-cache (SINGLE_PROCESS=1)
146
- // zero-cache uses the real postgres package with a MessagePort socket
147
- // that connects to pg-proxy-browser. identical to orez-node where
148
- // zero-cache uses real postgres over TCP to pg-proxy.
149
- //
150
- // set up the proxy connect function for postgres-browser.ts shim
151
- ;(globalThis as any).__orez_proxy_connect = (port: MessagePort) => {
152
- proxy.handleConnection(port)
153
- }
154
- ;(globalThis as any).__orez_proxy_password = ''
155
- ;(globalThis as any).__orez_proxy_user = 'user'
156
-
157
- // PGlite global still needed for browser-embed's sqlite setup
158
- ;(globalThis as any).__orez_pglite = pgPostgres
159
-
160
- // start zero-cache via browser-embed's runWorker
161
- const { startZeroCacheEmbedBrowser } = await import('./worker/browser-embed.js')
162
- const zc = await startZeroCacheEmbedBrowser({
163
- pglite: pgPostgres as unknown as PGlite,
164
- appId,
165
- publications: config.publications,
166
- disableAdminApi: config.disableAdminApi ?? true,
167
- env: {
168
- ZERO_LOG_LEVEL: config.logLevel || 'info',
169
- },
170
- })
171
- console.debug('[orez-browser] zero-cache started')
172
-
173
- // step 5: expose API
174
- const { signalReplicationChange } = await import('./replication/handler.js')
175
-
176
- return {
177
- instances: { postgres: pgPostgres, cvr: pgCvr, cdb: pgCdb },
178
-
179
- signalReplication() {
180
- signalReplicationChange()
181
- },
182
-
183
- handleWebSocket(ws: any, url = '/', headers?: Record<string, string>) {
184
- zc.handleWebSocket(ws, url)
185
- },
186
-
187
- async handleHttp(request: {
188
- method: string
189
- url: string
190
- headers?: Record<string, string>
191
- body?: string | null
192
- }) {
193
- return zc.handleHttp(request)
194
- },
195
-
196
- async stop() {
197
- await zc.stop()
198
- proxy.close()
199
- resetReplicationState()
200
- await Promise.all([pgPostgres.close(), pgCvr.close(), pgCdb.close()])
201
- },
202
- }
203
- }
@@ -1 +0,0 @@
1
- {"httpProtocol":"HTTP/1.1","clientAcceptEncoding":"gzip, deflate, br","requestPriority":"","edgeRequestKeepAliveStatus":1,"requestHeaderNames":{},"clientTcpRtt":93,"clientQuicRtt":0,"colo":"LAX","asn":21928,"asOrganization":"T-Mobile USA, Inc.","country":"US","isEUCountry":false,"city":"Honolulu","continent":"NA","region":"Hawaii","regionCode":"HI","timezone":"Pacific/Honolulu","longitude":"-157.85833","latitude":"21.30694","postalCode":"96802","metroCode":"744","tlsVersion":"TLSv1.3","tlsCipher":"AEAD-AES256-GCM-SHA384","tlsClientRandom":"NOBIfk5ETeINfIoBd1DBYmD6uDRaF6acEMq+Zulpn5M=","tlsClientCiphersSha1":"JZtiTn8H/ntxORk+XXvU2EvNoz8=","tlsClientExtensionsSha1":"Y7DIC8A6G0/aXviZ8ie/xDbJb7g=","tlsClientExtensionsSha1Le":"6e+q3vPm88rSgMTN/h7WTTxQ2wQ=","tlsExportedAuthenticator":{"clientHandshake":"a85e53d9da621fd7034dc64d2dfb270254957262daef67d7d0d9154fe2122b1661659fb5de1b674d3de3b0c400895ad6","serverHandshake":"4bcb07df5d2694809a69b6e423f8f5ef0746be28acb143ace522036e43d345863814d80f6c874320d7d04a7ce2b8fd9d","clientFinished":"6837d9952d53a1b550e3a280c48e207d1cc58c72770940c06f9f7b9853abd5060bff06ca118d6c71d94ab26184e95116","serverFinished":"48e2c71fae5a91d7a2b4ed7ca480052da299ed950a8f908eba095d075c53270b82305d1d6bd4ead4d5550e943537b47e"},"tlsClientHelloLength":"386","tlsClientAuth":{"certPresented":"0","certVerified":"NONE","certRevoked":"0","certIssuerDN":"","certSubjectDN":"","certIssuerDNRFC2253":"","certSubjectDNRFC2253":"","certIssuerDNLegacy":"","certSubjectDNLegacy":"","certSerial":"","certIssuerSerial":"","certSKI":"","certIssuerSKI":"","certFingerprintSHA1":"","certFingerprintSHA256":"","certNotBefore":"","certNotAfter":"","certRFC9440":"","certRFC9440TooLarge":false,"certChainRFC9440":"","certChainRFC9440TooLarge":false},"verifiedBotCategory":"","edgeL4":{"deliveryRate":47048},"botManagement":{"corporateProxy":false,"verifiedBot":false,"jsDetection":{"passed":false},"staticResource":false,"detectionIds":{},"score":99}}
@@ -1,11 +0,0 @@
1
- import worker, * as OTHER_EXPORTS from "/Users/n8/orez/src/cf-do/worker.ts";
2
- import * as __MIDDLEWARE_0__ from "/Users/n8/soot/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
3
- import * as __MIDDLEWARE_1__ from "/Users/n8/soot/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
4
-
5
- export * from "/Users/n8/orez/src/cf-do/worker.ts";
6
- const MIDDLEWARE_TEST_INJECT = "__INJECT_FOR_TESTING_WRANGLER_MIDDLEWARE__";
7
- export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [
8
-
9
- __MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default
10
- ]
11
- export default worker;
@@ -1,134 +0,0 @@
1
- // This loads all middlewares exposed on the middleware object and then starts
2
- // the invocation chain. The big idea is that we can add these to the middleware
3
- // export dynamically through wrangler, or we can potentially let users directly
4
- // add them as a sort of "plugin" system.
5
-
6
- import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-insertion-facade.js";
7
- import { __facade_invoke__, __facade_register__, Dispatcher } from "/Users/n8/soot/node_modules/wrangler/templates/middleware/common.ts";
8
- import type { WorkerEntrypointConstructor } from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-insertion-facade.js";
9
-
10
- // Preserve all the exports from the worker
11
- export * from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-0z4CpE/middleware-insertion-facade.js";
12
-
13
- class __Facade_ScheduledController__ implements ScheduledController {
14
- readonly #noRetry: ScheduledController["noRetry"];
15
-
16
- constructor(
17
- readonly scheduledTime: number,
18
- readonly cron: string,
19
- noRetry: ScheduledController["noRetry"]
20
- ) {
21
- this.#noRetry = noRetry;
22
- }
23
-
24
- noRetry() {
25
- if (!(this instanceof __Facade_ScheduledController__)) {
26
- throw new TypeError("Illegal invocation");
27
- }
28
- // Need to call native method immediately in case uncaught error thrown
29
- this.#noRetry();
30
- }
31
- }
32
-
33
- function wrapExportedHandler(worker: ExportedHandler): ExportedHandler {
34
- // If we don't have any middleware defined, just return the handler as is
35
- if (
36
- __INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
37
- __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
38
- ) {
39
- return worker;
40
- }
41
- // Otherwise, register all middleware once
42
- for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
43
- __facade_register__(middleware);
44
- }
45
-
46
- const fetchDispatcher: ExportedHandlerFetchHandler = function (
47
- request,
48
- env,
49
- ctx
50
- ) {
51
- if (worker.fetch === undefined) {
52
- throw new Error("Handler does not export a fetch() function.");
53
- }
54
- return worker.fetch(request, env, ctx);
55
- };
56
-
57
- return {
58
- ...worker,
59
- fetch(request, env, ctx) {
60
- const dispatcher: Dispatcher = function (type, init) {
61
- if (type === "scheduled" && worker.scheduled !== undefined) {
62
- const controller = new __Facade_ScheduledController__(
63
- Date.now(),
64
- init.cron ?? "",
65
- () => {}
66
- );
67
- return worker.scheduled(controller, env, ctx);
68
- }
69
- };
70
- return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
71
- },
72
- };
73
- }
74
-
75
- function wrapWorkerEntrypoint(
76
- klass: WorkerEntrypointConstructor
77
- ): WorkerEntrypointConstructor {
78
- // If we don't have any middleware defined, just return the handler as is
79
- if (
80
- __INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
81
- __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
82
- ) {
83
- return klass;
84
- }
85
- // Otherwise, register all middleware once
86
- for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
87
- __facade_register__(middleware);
88
- }
89
-
90
- // `extend`ing `klass` here so other RPC methods remain callable
91
- return class extends klass {
92
- #fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
93
- request,
94
- env,
95
- ctx
96
- ) => {
97
- this.env = env;
98
- this.ctx = ctx;
99
- if (super.fetch === undefined) {
100
- throw new Error("Entrypoint class does not define a fetch() function.");
101
- }
102
- return super.fetch(request);
103
- };
104
-
105
- #dispatcher: Dispatcher = (type, init) => {
106
- if (type === "scheduled" && super.scheduled !== undefined) {
107
- const controller = new __Facade_ScheduledController__(
108
- Date.now(),
109
- init.cron ?? "",
110
- () => {}
111
- );
112
- return super.scheduled(controller);
113
- }
114
- };
115
-
116
- fetch(request: Request<unknown, IncomingRequestCfProperties>) {
117
- return __facade_invoke__(
118
- request,
119
- this.env,
120
- this.ctx,
121
- this.#dispatcher,
122
- this.#fetchDispatcher
123
- );
124
- }
125
- };
126
- }
127
-
128
- let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
129
- if (typeof ENTRY === "object") {
130
- WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
131
- } else if (typeof ENTRY === "function") {
132
- WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
133
- }
134
- export default WRAPPED_ENTRY;
@@ -1,11 +0,0 @@
1
- import worker, * as OTHER_EXPORTS from "/Users/n8/orez/src/cf-do/worker.ts";
2
- import * as __MIDDLEWARE_0__ from "/Users/n8/soot/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
3
- import * as __MIDDLEWARE_1__ from "/Users/n8/soot/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
4
-
5
- export * from "/Users/n8/orez/src/cf-do/worker.ts";
6
- const MIDDLEWARE_TEST_INJECT = "__INJECT_FOR_TESTING_WRANGLER_MIDDLEWARE__";
7
- export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [
8
-
9
- __MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default
10
- ]
11
- export default worker;
@@ -1,134 +0,0 @@
1
- // This loads all middlewares exposed on the middleware object and then starts
2
- // the invocation chain. The big idea is that we can add these to the middleware
3
- // export dynamically through wrangler, or we can potentially let users directly
4
- // add them as a sort of "plugin" system.
5
-
6
- import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js";
7
- import { __facade_invoke__, __facade_register__, Dispatcher } from "/Users/n8/soot/node_modules/wrangler/templates/middleware/common.ts";
8
- import type { WorkerEntrypointConstructor } from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js";
9
-
10
- // Preserve all the exports from the worker
11
- export * from "/Users/n8/orez/src/cf-do/.wrangler/tmp/bundle-vYmw0E/middleware-insertion-facade.js";
12
-
13
- class __Facade_ScheduledController__ implements ScheduledController {
14
- readonly #noRetry: ScheduledController["noRetry"];
15
-
16
- constructor(
17
- readonly scheduledTime: number,
18
- readonly cron: string,
19
- noRetry: ScheduledController["noRetry"]
20
- ) {
21
- this.#noRetry = noRetry;
22
- }
23
-
24
- noRetry() {
25
- if (!(this instanceof __Facade_ScheduledController__)) {
26
- throw new TypeError("Illegal invocation");
27
- }
28
- // Need to call native method immediately in case uncaught error thrown
29
- this.#noRetry();
30
- }
31
- }
32
-
33
- function wrapExportedHandler(worker: ExportedHandler): ExportedHandler {
34
- // If we don't have any middleware defined, just return the handler as is
35
- if (
36
- __INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
37
- __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
38
- ) {
39
- return worker;
40
- }
41
- // Otherwise, register all middleware once
42
- for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
43
- __facade_register__(middleware);
44
- }
45
-
46
- const fetchDispatcher: ExportedHandlerFetchHandler = function (
47
- request,
48
- env,
49
- ctx
50
- ) {
51
- if (worker.fetch === undefined) {
52
- throw new Error("Handler does not export a fetch() function.");
53
- }
54
- return worker.fetch(request, env, ctx);
55
- };
56
-
57
- return {
58
- ...worker,
59
- fetch(request, env, ctx) {
60
- const dispatcher: Dispatcher = function (type, init) {
61
- if (type === "scheduled" && worker.scheduled !== undefined) {
62
- const controller = new __Facade_ScheduledController__(
63
- Date.now(),
64
- init.cron ?? "",
65
- () => {}
66
- );
67
- return worker.scheduled(controller, env, ctx);
68
- }
69
- };
70
- return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
71
- },
72
- };
73
- }
74
-
75
- function wrapWorkerEntrypoint(
76
- klass: WorkerEntrypointConstructor
77
- ): WorkerEntrypointConstructor {
78
- // If we don't have any middleware defined, just return the handler as is
79
- if (
80
- __INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
81
- __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
82
- ) {
83
- return klass;
84
- }
85
- // Otherwise, register all middleware once
86
- for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
87
- __facade_register__(middleware);
88
- }
89
-
90
- // `extend`ing `klass` here so other RPC methods remain callable
91
- return class extends klass {
92
- #fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
93
- request,
94
- env,
95
- ctx
96
- ) => {
97
- this.env = env;
98
- this.ctx = ctx;
99
- if (super.fetch === undefined) {
100
- throw new Error("Entrypoint class does not define a fetch() function.");
101
- }
102
- return super.fetch(request);
103
- };
104
-
105
- #dispatcher: Dispatcher = (type, init) => {
106
- if (type === "scheduled" && super.scheduled !== undefined) {
107
- const controller = new __Facade_ScheduledController__(
108
- Date.now(),
109
- init.cron ?? "",
110
- () => {}
111
- );
112
- return super.scheduled(controller);
113
- }
114
- };
115
-
116
- fetch(request: Request<unknown, IncomingRequestCfProperties>) {
117
- return __facade_invoke__(
118
- request,
119
- this.env,
120
- this.ctx,
121
- this.#dispatcher,
122
- this.#fetchDispatcher
123
- );
124
- }
125
- };
126
- }
127
-
128
- let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
129
- if (typeof ENTRY === "object") {
130
- WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
131
- } else if (typeof ENTRY === "function") {
132
- WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
133
- }
134
- export default WRAPPED_ENTRY;