Skip to content

Commit b3f79cb

Browse files
Merge pull request #4 from Anurup-R-Krishnan/v2-redesign
v2-redesign merge with main
2 parents ad4fc6e + cfedb94 commit b3f79cb

140 files changed

Lines changed: 32618 additions & 8315 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: V2 Mirror Guard
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
mirror-guard:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Setup Node
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 20
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Run V2 mirror guard
25+
env:
26+
MIRROR_BASE_REF: origin/${{ github.base_ref }}
27+
run: npm run v2:mirror:check

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ dist-ssr
2424
*.sw?
2525
.env.local
2626
.env
27+
28+
# V2 workspaces
29+
apps/mobile/.expo
30+
apps/mobile/.expo-shared
31+
apps/mobile/web-build
32+
apps/desktop/src-tauri/target
33+
apps/desktop/src-tauri/gen
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const urls = new Set();
2+
3+
function checkURL(request, init) {
4+
const url =
5+
request instanceof URL
6+
? request
7+
: new URL(
8+
(typeof request === "string"
9+
? new Request(request, init)
10+
: request
11+
).url
12+
);
13+
if (url.port && url.port !== "443" && url.protocol === "https:") {
14+
if (!urls.has(url.toString())) {
15+
urls.add(url.toString());
16+
console.warn(
17+
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:\n` +
18+
` - ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.\n`
19+
);
20+
}
21+
}
22+
}
23+
24+
globalThis.fetch = new Proxy(globalThis.fetch, {
25+
apply(target, thisArg, argArray) {
26+
const [request, init] = argArray;
27+
checkURL(request, init);
28+
return Reflect.apply(target, thisArg, argArray);
29+
},
30+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import worker, * as OTHER_EXPORTS from "/home/anuruprkris/Project/sanctuary-book-reader/.wrangler/tmp/pages-NZEO3F/functionsWorker-0.45083409233887484.mjs";
2+
import * as __MIDDLEWARE_0__ from "/home/anuruprkris/Project/sanctuary-book-reader/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
3+
import * as __MIDDLEWARE_1__ from "/home/anuruprkris/Project/sanctuary-book-reader/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
4+
5+
export * from "/home/anuruprkris/Project/sanctuary-book-reader/.wrangler/tmp/pages-NZEO3F/functionsWorker-0.45083409233887484.mjs";
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;
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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 "/home/anuruprkris/Project/sanctuary-book-reader/.wrangler/tmp/bundle-P5KUeC/middleware-insertion-facade.js";
7+
import { __facade_invoke__, __facade_register__, Dispatcher } from "/home/anuruprkris/Project/sanctuary-book-reader/node_modules/wrangler/templates/middleware/common.ts";
8+
import type { WorkerEntrypointConstructor } from "/home/anuruprkris/Project/sanctuary-book-reader/.wrangler/tmp/bundle-P5KUeC/middleware-insertion-facade.js";
9+
10+
// Preserve all the exports from the worker
11+
export * from "/home/anuruprkris/Project/sanctuary-book-reader/.wrangler/tmp/bundle-P5KUeC/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;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const urls = new Set();
2+
3+
function checkURL(request, init) {
4+
const url =
5+
request instanceof URL
6+
? request
7+
: new URL(
8+
(typeof request === "string"
9+
? new Request(request, init)
10+
: request
11+
).url
12+
);
13+
if (url.port && url.port !== "443" && url.protocol === "https:") {
14+
if (!urls.has(url.toString())) {
15+
urls.add(url.toString());
16+
console.warn(
17+
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:\n` +
18+
` - ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.\n`
19+
);
20+
}
21+
}
22+
}
23+
24+
globalThis.fetch = new Proxy(globalThis.fetch, {
25+
apply(target, thisArg, argArray) {
26+
const [request, init] = argArray;
27+
checkURL(request, init);
28+
return Reflect.apply(target, thisArg, argArray);
29+
},
30+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import worker, * as OTHER_EXPORTS from "/home/anuruprkris/Project/sanctuary-book-reader/node_modules/wrangler/templates/pages-template-worker.ts";
2+
import * as __MIDDLEWARE_0__ from "/home/anuruprkris/Project/sanctuary-book-reader/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
3+
import * as __MIDDLEWARE_1__ from "/home/anuruprkris/Project/sanctuary-book-reader/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
4+
5+
export * from "/home/anuruprkris/Project/sanctuary-book-reader/node_modules/wrangler/templates/pages-template-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;
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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 "/home/anuruprkris/Project/sanctuary-book-reader/.wrangler/tmp/bundle-Pnd8L3/middleware-insertion-facade.js";
7+
import { __facade_invoke__, __facade_register__, Dispatcher } from "/home/anuruprkris/Project/sanctuary-book-reader/node_modules/wrangler/templates/middleware/common.ts";
8+
import type { WorkerEntrypointConstructor } from "/home/anuruprkris/Project/sanctuary-book-reader/.wrangler/tmp/bundle-Pnd8L3/middleware-insertion-facade.js";
9+
10+
// Preserve all the exports from the worker
11+
export * from "/home/anuruprkris/Project/sanctuary-book-reader/.wrangler/tmp/bundle-Pnd8L3/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;

0 commit comments

Comments
 (0)