expo-server 0.0.0 → 0.0.1
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/README.md +1 -0
- package/build/cjs/ImmutableRequest.d.ts +60 -0
- package/build/cjs/ImmutableRequest.js +160 -0
- package/build/cjs/ImmutableRequest.js.map +1 -0
- package/build/cjs/global.types.d.ts +13 -0
- package/build/cjs/global.types.js +3 -0
- package/build/cjs/global.types.js.map +1 -0
- package/build/cjs/index.d.ts +2 -0
- package/build/cjs/index.js +18 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/manifest.d.ts +27 -0
- package/build/cjs/manifest.js +3 -0
- package/build/cjs/manifest.js.map +1 -0
- package/build/cjs/middleware/rsc.d.ts +36 -0
- package/build/cjs/middleware/rsc.js +124 -0
- package/build/cjs/middleware/rsc.js.map +1 -0
- package/build/cjs/private.d.ts +2 -0
- package/build/cjs/private.js +6 -0
- package/build/cjs/private.js.map +1 -0
- package/build/cjs/runtime/api.d.ts +36 -0
- package/build/cjs/runtime/api.js +64 -0
- package/build/cjs/runtime/api.js.map +1 -0
- package/build/cjs/runtime/error.d.ts +19 -0
- package/build/cjs/runtime/error.js +69 -0
- package/build/cjs/runtime/error.js.map +1 -0
- package/build/cjs/runtime/index.d.ts +11 -0
- package/build/cjs/runtime/index.js +77 -0
- package/build/cjs/runtime/index.js.map +1 -0
- package/build/cjs/runtime/scope.d.ts +10 -0
- package/build/cjs/runtime/scope.js +12 -0
- package/build/cjs/runtime/scope.js.map +1 -0
- package/build/cjs/types.d.ts +43 -0
- package/build/cjs/types.js +3 -0
- package/build/cjs/types.js.map +1 -0
- package/build/cjs/utils/createReadableStreamFromReadable.d.ts +15 -0
- package/build/cjs/utils/createReadableStreamFromReadable.js +97 -0
- package/build/cjs/utils/createReadableStreamFromReadable.js.map +1 -0
- package/build/cjs/utils/importMetaRegistry.d.ts +3 -0
- package/build/cjs/utils/importMetaRegistry.js +30 -0
- package/build/cjs/utils/importMetaRegistry.js.map +1 -0
- package/build/cjs/utils/matchers.d.ts +12 -0
- package/build/cjs/utils/matchers.js +76 -0
- package/build/cjs/utils/matchers.js.map +1 -0
- package/build/cjs/utils/middleware.d.ts +9 -0
- package/build/cjs/utils/middleware.js +82 -0
- package/build/cjs/utils/middleware.js.map +1 -0
- package/build/cjs/vendor/abstract.d.ts +40 -0
- package/build/cjs/vendor/abstract.js +245 -0
- package/build/cjs/vendor/abstract.js.map +1 -0
- package/build/cjs/vendor/bun.d.ts +10 -0
- package/build/cjs/vendor/bun.js +22 -0
- package/build/cjs/vendor/bun.js.map +1 -0
- package/build/cjs/vendor/eas.d.ts +10 -0
- package/build/cjs/vendor/eas.js +28 -0
- package/build/cjs/vendor/eas.js.map +1 -0
- package/build/cjs/vendor/environment/common.d.ts +14 -0
- package/build/cjs/vendor/environment/common.js +66 -0
- package/build/cjs/vendor/environment/common.js.map +1 -0
- package/build/cjs/vendor/environment/node.d.ts +14 -0
- package/build/cjs/vendor/environment/node.js +55 -0
- package/build/cjs/vendor/environment/node.js.map +1 -0
- package/build/cjs/vendor/environment/workerd.d.ts +18 -0
- package/build/cjs/vendor/environment/workerd.js +72 -0
- package/build/cjs/vendor/environment/workerd.js.map +1 -0
- package/build/cjs/vendor/express.d.ts +14 -0
- package/build/cjs/vendor/express.js +100 -0
- package/build/cjs/vendor/express.js.map +1 -0
- package/build/cjs/vendor/http.d.ts +15 -0
- package/build/cjs/vendor/http.js +103 -0
- package/build/cjs/vendor/http.js.map +1 -0
- package/build/cjs/vendor/netlify.d.ts +15 -0
- package/build/cjs/vendor/netlify.js +46 -0
- package/build/cjs/vendor/netlify.js.map +1 -0
- package/build/cjs/vendor/vercel.d.ts +13 -0
- package/build/cjs/vendor/vercel.js +109 -0
- package/build/cjs/vendor/vercel.js.map +1 -0
- package/build/cjs/vendor/workerd.d.ts +11 -0
- package/build/cjs/vendor/workerd.js +22 -0
- package/build/cjs/vendor/workerd.js.map +1 -0
- package/build/mjs/ImmutableRequest.d.ts +60 -0
- package/build/mjs/ImmutableRequest.js +155 -0
- package/build/mjs/ImmutableRequest.js.map +1 -0
- package/build/mjs/global.types.d.ts +13 -0
- package/build/mjs/global.types.js +2 -0
- package/build/mjs/global.types.js.map +1 -0
- package/build/mjs/index.d.ts +2 -0
- package/build/mjs/index.js +2 -0
- package/build/mjs/index.js.map +1 -0
- package/build/mjs/manifest.d.ts +27 -0
- package/build/mjs/manifest.js +2 -0
- package/build/mjs/manifest.js.map +1 -0
- package/build/mjs/middleware/rsc.d.ts +36 -0
- package/build/mjs/middleware/rsc.js +119 -0
- package/build/mjs/middleware/rsc.js.map +1 -0
- package/build/mjs/private.d.ts +2 -0
- package/build/mjs/private.js +2 -0
- package/build/mjs/private.js.map +1 -0
- package/build/mjs/runtime/api.d.ts +36 -0
- package/build/mjs/runtime/api.js +56 -0
- package/build/mjs/runtime/api.js.map +1 -0
- package/build/mjs/runtime/error.d.ts +19 -0
- package/build/mjs/runtime/error.js +64 -0
- package/build/mjs/runtime/error.js.map +1 -0
- package/build/mjs/runtime/index.d.ts +11 -0
- package/build/mjs/runtime/index.js +74 -0
- package/build/mjs/runtime/index.js.map +1 -0
- package/build/mjs/runtime/scope.d.ts +10 -0
- package/build/mjs/runtime/scope.js +9 -0
- package/build/mjs/runtime/scope.js.map +1 -0
- package/build/mjs/types.d.ts +43 -0
- package/build/mjs/types.js +2 -0
- package/build/mjs/types.js.map +1 -0
- package/build/mjs/utils/createReadableStreamFromReadable.d.ts +15 -0
- package/build/mjs/utils/createReadableStreamFromReadable.js +93 -0
- package/build/mjs/utils/createReadableStreamFromReadable.js.map +1 -0
- package/build/mjs/utils/importMetaRegistry.d.ts +3 -0
- package/build/mjs/utils/importMetaRegistry.js +27 -0
- package/build/mjs/utils/importMetaRegistry.js.map +1 -0
- package/build/mjs/utils/matchers.d.ts +12 -0
- package/build/mjs/utils/matchers.js +69 -0
- package/build/mjs/utils/matchers.js.map +1 -0
- package/build/mjs/utils/middleware.d.ts +9 -0
- package/build/mjs/utils/middleware.js +79 -0
- package/build/mjs/utils/middleware.js.map +1 -0
- package/build/mjs/vendor/abstract.d.ts +40 -0
- package/build/mjs/vendor/abstract.js +240 -0
- package/build/mjs/vendor/abstract.js.map +1 -0
- package/build/mjs/vendor/bun.d.ts +10 -0
- package/build/mjs/vendor/bun.js +17 -0
- package/build/mjs/vendor/bun.js.map +1 -0
- package/build/mjs/vendor/eas.d.ts +10 -0
- package/build/mjs/vendor/eas.js +23 -0
- package/build/mjs/vendor/eas.js.map +1 -0
- package/build/mjs/vendor/environment/common.d.ts +14 -0
- package/build/mjs/vendor/environment/common.js +63 -0
- package/build/mjs/vendor/environment/common.js.map +1 -0
- package/build/mjs/vendor/environment/node.d.ts +14 -0
- package/build/mjs/vendor/environment/node.js +48 -0
- package/build/mjs/vendor/environment/node.js.map +1 -0
- package/build/mjs/vendor/environment/workerd.d.ts +18 -0
- package/build/mjs/vendor/environment/workerd.js +68 -0
- package/build/mjs/vendor/environment/workerd.js.map +1 -0
- package/build/mjs/vendor/express.d.ts +14 -0
- package/build/mjs/vendor/express.js +92 -0
- package/build/mjs/vendor/express.js.map +1 -0
- package/build/mjs/vendor/http.d.ts +15 -0
- package/build/mjs/vendor/http.js +95 -0
- package/build/mjs/vendor/http.js.map +1 -0
- package/build/mjs/vendor/netlify.d.ts +15 -0
- package/build/mjs/vendor/netlify.js +41 -0
- package/build/mjs/vendor/netlify.js.map +1 -0
- package/build/mjs/vendor/vercel.d.ts +13 -0
- package/build/mjs/vendor/vercel.js +101 -0
- package/build/mjs/vendor/vercel.js.map +1 -0
- package/build/mjs/vendor/workerd.d.ts +11 -0
- package/build/mjs/vendor/workerd.js +17 -0
- package/build/mjs/vendor/workerd.js.map +1 -0
- package/package.json +58 -7
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { errorToResponse } from './error';
|
|
2
|
+
import { scopeRef } from './scope';
|
|
3
|
+
import { importMetaRegistry } from '../utils/importMetaRegistry';
|
|
4
|
+
function setupRuntime() {
|
|
5
|
+
try {
|
|
6
|
+
Object.defineProperty(globalThis, 'origin', {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
get() {
|
|
10
|
+
return scopeRef.current?.getStore()?.origin || 'null';
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
catch { }
|
|
15
|
+
try {
|
|
16
|
+
Object.defineProperty(globalThis, '__ExpoImportMetaRegistry', {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
get() {
|
|
20
|
+
return importMetaRegistry;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch { }
|
|
25
|
+
}
|
|
26
|
+
export function createRequestScope(scopeDefinition, makeRequestAPISetup) {
|
|
27
|
+
setupRuntime();
|
|
28
|
+
// NOTE(@kitten): For long-running servers, this will always be a noop. It therefore
|
|
29
|
+
// makes sense for us to provide a default that doesn't do anything.
|
|
30
|
+
function defaultWaitUntil(promise) {
|
|
31
|
+
promise.finally(() => { });
|
|
32
|
+
}
|
|
33
|
+
return async (run, ...args) => {
|
|
34
|
+
// Initialize the scope definition which is used to isolate the runtime API between
|
|
35
|
+
// requests. The implementation of scopes differs per runtime, and is only initialized
|
|
36
|
+
// once the first request is received
|
|
37
|
+
scopeRef.current = scopeDefinition;
|
|
38
|
+
const setup = makeRequestAPISetup(...args);
|
|
39
|
+
const { waitUntil = defaultWaitUntil } = setup;
|
|
40
|
+
const scope = {
|
|
41
|
+
...setup,
|
|
42
|
+
origin: setup.origin,
|
|
43
|
+
environment: setup.environment,
|
|
44
|
+
waitUntil,
|
|
45
|
+
deferTask: setup.deferTask,
|
|
46
|
+
};
|
|
47
|
+
const deferredTasks = [];
|
|
48
|
+
if (!scope.deferTask) {
|
|
49
|
+
scope.deferTask = function deferTask(fn) {
|
|
50
|
+
deferredTasks.push(fn);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
let result;
|
|
54
|
+
try {
|
|
55
|
+
result =
|
|
56
|
+
scopeRef.current != null
|
|
57
|
+
? await scopeRef.current.run(scope, () => run(...args))
|
|
58
|
+
: await run(...args);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error != null && error instanceof Error && 'status' in error) {
|
|
62
|
+
return errorToResponse(error);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (deferredTasks.length) {
|
|
69
|
+
deferredTasks.forEach((fn) => waitUntil(fn()));
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAwB,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAQjE,SAAS,YAAY;IACnB,IAAI,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE;YAC1C,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;YAClB,GAAG;gBACD,OAAO,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,MAAM,IAAI,MAAM,CAAC;YACxD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IACV,IAAI,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,0BAA0B,EAAE;YAC5D,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;YAClB,GAAG;gBACD,OAAO,kBAAkB,CAAC;YAC5B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC,CAAA,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ACf,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,YAAY,KAAK,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;gBACjE,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;YACzB,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RequestAPI } from './api';
|
|
2
|
+
export interface ScopeDefinition<Scope extends RequestAPI = any> {
|
|
3
|
+
getStore(): Scope | undefined;
|
|
4
|
+
run<R>(scope: Scope, runner: () => R): R;
|
|
5
|
+
run<R, TArgs extends any[]>(scope: Scope, runner: (...args: TArgs) => R, ...args: TArgs): R;
|
|
6
|
+
}
|
|
7
|
+
declare const scopeRef: {
|
|
8
|
+
current: ScopeDefinition<RequestAPI> | null;
|
|
9
|
+
};
|
|
10
|
+
export { scopeRef };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// NOTE(@kitten): When multiple versions of `@expo/server` are bundled, we still want to reuse the same scope definition
|
|
2
|
+
const scopeSymbol = Symbol.for('expoServerRuntime');
|
|
3
|
+
const sharedScope = globalThis;
|
|
4
|
+
const scopeRef = sharedScope[scopeSymbol] ||
|
|
5
|
+
(sharedScope[scopeSymbol] = {
|
|
6
|
+
current: null,
|
|
7
|
+
});
|
|
8
|
+
export { scopeRef };
|
|
9
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/runtime/scope.ts"],"names":[],"mappings":"AAQA,wHAAwH;AACxH,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AACpD,MAAM,WAAW,GACf,UAAU,CAAC;AAEb,MAAM,QAAQ,GACZ,WAAW,CAAC,WAAW,CAAC;IACxB,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG;QAC1B,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;AAEL,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { _ImmutableRequest } from './ImmutableRequest';
|
|
2
|
+
/**
|
|
3
|
+
* An immutable version of the Fetch API's [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object which prevents mutations to the request body and headers.
|
|
4
|
+
*/
|
|
5
|
+
export interface ImmutableRequest extends _ImmutableRequest {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Middleware pattern type that can be a string (including named params) or a regular expression.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Exact match
|
|
12
|
+
* '/api'
|
|
13
|
+
* @example
|
|
14
|
+
* // Named parameters
|
|
15
|
+
* '/posts/[postId]' // Single dynamic segment
|
|
16
|
+
* '/blog/[...slug]' // Catch-all segments
|
|
17
|
+
* '/users/[userId]/posts/[postId]' // Multiple parameters
|
|
18
|
+
* @example
|
|
19
|
+
* // Regular expression
|
|
20
|
+
* /^\/api\/v\d+\/users$/
|
|
21
|
+
*/
|
|
22
|
+
export type MiddlewarePattern = string | RegExp;
|
|
23
|
+
export type MiddlewareMatcher = {
|
|
24
|
+
/**
|
|
25
|
+
* Array of path patterns to match against. Supports exact paths, paths with named parameters, and regex patterns.
|
|
26
|
+
*/
|
|
27
|
+
patterns?: MiddlewarePattern[];
|
|
28
|
+
/**
|
|
29
|
+
* HTTP methods to match (undefined = all methods)
|
|
30
|
+
* @example ['POST', 'PUT', 'DELETE']
|
|
31
|
+
*/
|
|
32
|
+
methods?: string[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Middleware function type that runs before route matching.
|
|
36
|
+
* Can return a Response to short-circuit the request, or void/undefined to continue.
|
|
37
|
+
*
|
|
38
|
+
* @param request - An `ImmutableRequest` with read-only headers and no body access
|
|
39
|
+
*/
|
|
40
|
+
export type MiddlewareFunction = (request: ImmutableRequest) => Promise<Response | void> | Response | void;
|
|
41
|
+
export interface MiddlewareSettings {
|
|
42
|
+
matcher?: MiddlewareMatcher;
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright © 2025 650 Industries.
|
|
3
|
+
* Copyright (c) Remix Software Inc. 2020-2021
|
|
4
|
+
* Copyright (c) Shopify Inc. 2022-2024
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* Original license https://github.com/remix-run/remix/blob/6d6caaed5dfc436242962dcb2ff9617757a11e17/LICENSE.md
|
|
10
|
+
* Code from https://github.com/remix-run/remix/blob/6d6caaed5dfc436242962dcb2ff9617757a11e17/packages/remix-node/stream.ts#L66
|
|
11
|
+
*/
|
|
12
|
+
import type { Readable } from 'node:stream';
|
|
13
|
+
export declare const createReadableStreamFromReadable: (source: Readable & {
|
|
14
|
+
readableHighWaterMark?: number;
|
|
15
|
+
}) => ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright © 2025 650 Industries.
|
|
3
|
+
* Copyright (c) Remix Software Inc. 2020-2021
|
|
4
|
+
* Copyright (c) Shopify Inc. 2022-2024
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* Original license https://github.com/remix-run/remix/blob/6d6caaed5dfc436242962dcb2ff9617757a11e17/LICENSE.md
|
|
10
|
+
* Code from https://github.com/remix-run/remix/blob/6d6caaed5dfc436242962dcb2ff9617757a11e17/packages/remix-node/stream.ts#L66
|
|
11
|
+
*/
|
|
12
|
+
import { Stream } from 'node:stream';
|
|
13
|
+
export const createReadableStreamFromReadable = (source) => {
|
|
14
|
+
const pump = new StreamPump(source);
|
|
15
|
+
const stream = new ReadableStream(pump, pump);
|
|
16
|
+
return stream;
|
|
17
|
+
};
|
|
18
|
+
class StreamPump {
|
|
19
|
+
highWaterMark;
|
|
20
|
+
accumalatedSize;
|
|
21
|
+
stream;
|
|
22
|
+
controller;
|
|
23
|
+
constructor(stream) {
|
|
24
|
+
this.highWaterMark =
|
|
25
|
+
stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
|
|
26
|
+
this.accumalatedSize = 0;
|
|
27
|
+
this.stream = stream;
|
|
28
|
+
this.enqueue = this.enqueue.bind(this);
|
|
29
|
+
this.error = this.error.bind(this);
|
|
30
|
+
this.close = this.close.bind(this);
|
|
31
|
+
}
|
|
32
|
+
size(chunk) {
|
|
33
|
+
return chunk?.byteLength || 0;
|
|
34
|
+
}
|
|
35
|
+
start(controller) {
|
|
36
|
+
this.controller = controller;
|
|
37
|
+
this.stream.on('data', this.enqueue);
|
|
38
|
+
this.stream.once('error', this.error);
|
|
39
|
+
this.stream.once('end', this.close);
|
|
40
|
+
this.stream.once('close', this.close);
|
|
41
|
+
}
|
|
42
|
+
pull() {
|
|
43
|
+
this.resume();
|
|
44
|
+
}
|
|
45
|
+
cancel(reason) {
|
|
46
|
+
if (this.stream.destroy) {
|
|
47
|
+
this.stream.destroy(reason);
|
|
48
|
+
}
|
|
49
|
+
this.stream.off('data', this.enqueue);
|
|
50
|
+
this.stream.off('error', this.error);
|
|
51
|
+
this.stream.off('end', this.close);
|
|
52
|
+
this.stream.off('close', this.close);
|
|
53
|
+
}
|
|
54
|
+
enqueue(chunk) {
|
|
55
|
+
if (this.controller) {
|
|
56
|
+
try {
|
|
57
|
+
const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
58
|
+
const available = (this.controller.desiredSize || 0) - bytes.byteLength;
|
|
59
|
+
this.controller.enqueue(bytes);
|
|
60
|
+
if (available <= 0) {
|
|
61
|
+
this.pause();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
this.controller.error(new Error('Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object'));
|
|
66
|
+
this.cancel();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
pause() {
|
|
71
|
+
if (this.stream.pause) {
|
|
72
|
+
this.stream.pause();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
resume() {
|
|
76
|
+
if (this.stream.readable && this.stream.resume) {
|
|
77
|
+
this.stream.resume();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
close() {
|
|
81
|
+
if (this.controller) {
|
|
82
|
+
this.controller.close();
|
|
83
|
+
delete this.controller;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
error(error) {
|
|
87
|
+
if (this.controller) {
|
|
88
|
+
this.controller.error(error);
|
|
89
|
+
delete this.controller;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=createReadableStreamFromReadable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createReadableStreamFromReadable.js","sourceRoot":"","sources":["../../../src/utils/createReadableStreamFromReadable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,MAAqD,EACrD,EAAE;IACF,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACpC,MAA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CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;IACH,CAAC;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YAC/C,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAY;QAChB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const DEFAULT_SCRIPT_NAME = 'file:///__main.js';
|
|
2
|
+
// - ./runtime/importMetaRegistry.ts (this file) -> importMetaRegistry.url
|
|
3
|
+
// - ./runtime/index.ts -> globalThis.__ExpoImportMetaRegistry
|
|
4
|
+
// - <source>
|
|
5
|
+
const CALL_DEPTH = 3;
|
|
6
|
+
function getFileName(offset = 0) {
|
|
7
|
+
const originalStackFormatter = Error.prepareStackTrace;
|
|
8
|
+
const originalStackTraceLimit = Error.stackTraceLimit;
|
|
9
|
+
try {
|
|
10
|
+
Error.stackTraceLimit = offset;
|
|
11
|
+
Error.prepareStackTrace = (_err, stack) => stack[offset - 1]?.getFileName();
|
|
12
|
+
return new Error().stack;
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
Error.prepareStackTrace = originalStackFormatter;
|
|
16
|
+
Error.stackTraceLimit = originalStackTraceLimit;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const importMetaRegistry = {
|
|
20
|
+
get url() {
|
|
21
|
+
let scriptName = getFileName(CALL_DEPTH);
|
|
22
|
+
if (scriptName?.[0] === '/')
|
|
23
|
+
scriptName = `file://${scriptName}`;
|
|
24
|
+
return scriptName || DEFAULT_SCRIPT_NAME;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=importMetaRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importMetaRegistry.js","sourceRoot":"","sources":["../../../src/utils/importMetaRegistry.ts"],"names":[],"mappings":"AAAA,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAEhD,0EAA0E;AAC1E,8DAA8D;AAC9D,aAAa;AACb,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,SAAS,WAAW,CAAC,MAAM,GAAG,CAAC;IAC7B,MAAM,sBAAsB,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACvD,MAAM,uBAAuB,GAAG,KAAK,CAAC,eAAe,CAAC;IACtD,IAAI,CAAC;QACH,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC;QAC/B,KAAK,CAAC,iBAAiB,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;QAC5E,OAAO,IAAI,KAAK,EAAE,CAAC,KAAY,CAAC;IAClC,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,iBAAiB,GAAG,sBAAsB,CAAC;QACjD,KAAK,CAAC,eAAe,GAAG,uBAAuB,CAAC;IAClD,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,GAAG;QACL,IAAI,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;QACzC,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,UAAU,GAAG,UAAU,UAAU,EAAE,CAAC;QACjE,OAAO,UAAU,IAAI,mBAAmB,CAAC;IAC3C,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Route } from '../manifest';
|
|
2
|
+
export declare function isResponse(input: unknown): input is Response;
|
|
3
|
+
export declare function parseParams(request: Request, route: Route): Record<string, string>;
|
|
4
|
+
export declare function getRedirectRewriteLocation(url: URL, request: Request, route: Route): URL;
|
|
5
|
+
/** Match `[page]` -> `page`
|
|
6
|
+
* @privateRemarks Ported from `expo-router/src/matchers.tsx`
|
|
7
|
+
*/
|
|
8
|
+
export declare function matchDynamicName(name: string): string | undefined;
|
|
9
|
+
/** Match `[...page]` -> `page`
|
|
10
|
+
* @privateRemarks Ported from `expo-router/src/matchers.tsx`
|
|
11
|
+
*/
|
|
12
|
+
export declare function matchDeepDynamicRouteName(name: string): string | undefined;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export function isResponse(input) {
|
|
2
|
+
return !!input && typeof input === 'object' && input instanceof Response;
|
|
3
|
+
}
|
|
4
|
+
export function parseParams(request, route) {
|
|
5
|
+
const params = {};
|
|
6
|
+
const { pathname } = new URL(request.url);
|
|
7
|
+
const match = route.namedRegex.exec(pathname);
|
|
8
|
+
if (match?.groups) {
|
|
9
|
+
for (const [key, value] of Object.entries(match.groups)) {
|
|
10
|
+
const namedKey = route.routeKeys[key];
|
|
11
|
+
params[namedKey] = value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return params;
|
|
15
|
+
}
|
|
16
|
+
export function getRedirectRewriteLocation(url, request, route) {
|
|
17
|
+
const originalQueryParams = url.searchParams.entries();
|
|
18
|
+
const params = parseParams(request, route);
|
|
19
|
+
const target = route.page
|
|
20
|
+
.split('/')
|
|
21
|
+
.map((segment) => {
|
|
22
|
+
let match;
|
|
23
|
+
if ((match = matchDynamicName(segment))) {
|
|
24
|
+
const value = params[match];
|
|
25
|
+
delete params[match];
|
|
26
|
+
return typeof value === 'string'
|
|
27
|
+
? value.split('/')[0] /* If we are redirecting from a catch-all route, we need to remove the extra segments */
|
|
28
|
+
: (value ?? segment);
|
|
29
|
+
}
|
|
30
|
+
else if ((match = matchDeepDynamicRouteName(segment))) {
|
|
31
|
+
const value = params[match];
|
|
32
|
+
delete params[match];
|
|
33
|
+
return value ?? segment;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return segment;
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
.join('/');
|
|
40
|
+
const targetUrl = new URL(target, url.origin);
|
|
41
|
+
// NOTE: React Navigation doesn't differentiate between a path parameter
|
|
42
|
+
// and a search parameter. We have to preserve leftover search parameters
|
|
43
|
+
// to ensure we don't lose any intentional parameters with special meaning
|
|
44
|
+
for (const key in params)
|
|
45
|
+
targetUrl.searchParams.append(key, params[key]);
|
|
46
|
+
// NOTE(@krystofwoldrich): Query matching is not supported at the moment.
|
|
47
|
+
// Copy original query parameters to the target URL
|
|
48
|
+
for (const [key, value] of originalQueryParams) {
|
|
49
|
+
// NOTE(@krystofwoldrich): Params created from route overwrite existing (might be unexpected to the user)
|
|
50
|
+
if (!targetUrl.searchParams.has(key)) {
|
|
51
|
+
targetUrl.searchParams.append(key, value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return targetUrl;
|
|
55
|
+
}
|
|
56
|
+
/** Match `[page]` -> `page`
|
|
57
|
+
* @privateRemarks Ported from `expo-router/src/matchers.tsx`
|
|
58
|
+
*/
|
|
59
|
+
export function matchDynamicName(name) {
|
|
60
|
+
// Don't match `...` or `[` or `]` inside the brackets
|
|
61
|
+
return name.match(/^\[([^[\](?:\.\.\.)]+?)\]$/)?.[1]; // eslint-disable-line no-useless-escape
|
|
62
|
+
}
|
|
63
|
+
/** Match `[...page]` -> `page`
|
|
64
|
+
* @privateRemarks Ported from `expo-router/src/matchers.tsx`
|
|
65
|
+
*/
|
|
66
|
+
export function matchDeepDynamicRouteName(name) {
|
|
67
|
+
return name.match(/^\[\.\.\.([^/]+?)\]$/)?.[1];
|
|
68
|
+
}
|
|
69
|
+
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AED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,sDAAsD;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,4BAA4B,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,wCAAwC;AAChG,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MiddlewareFunction, MiddlewareSettings } from '../types';
|
|
2
|
+
export interface MiddlewareModule {
|
|
3
|
+
default: MiddlewareFunction;
|
|
4
|
+
unstable_settings?: MiddlewareSettings;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Determines whether middleware should run for a given request based on matcher configuration.
|
|
8
|
+
*/
|
|
9
|
+
export declare function shouldRunMiddleware(request: Request, middleware: MiddlewareModule): boolean;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { matchDynamicName, matchDeepDynamicRouteName } from './matchers';
|
|
2
|
+
/**
|
|
3
|
+
* Determines whether middleware should run for a given request based on matcher configuration.
|
|
4
|
+
*/
|
|
5
|
+
export function shouldRunMiddleware(request, middleware) {
|
|
6
|
+
const matcher = middleware.unstable_settings?.matcher;
|
|
7
|
+
// No matcher means middleware runs on all requests
|
|
8
|
+
if (!matcher) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
const url = new URL(request.url);
|
|
12
|
+
const pathname = url.pathname;
|
|
13
|
+
// Check HTTP methods, if specified
|
|
14
|
+
if (matcher.methods) {
|
|
15
|
+
const methods = matcher.methods.map((method) => method.toUpperCase());
|
|
16
|
+
if (methods.length === 0 || !methods.includes(request.method)) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Check path patterns, if specified
|
|
21
|
+
if (matcher.patterns) {
|
|
22
|
+
const patterns = Array.isArray(matcher.patterns) ? matcher.patterns : [matcher.patterns];
|
|
23
|
+
if (patterns.length === 0) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return patterns.some((pattern) => matchesPattern(pathname, pattern));
|
|
27
|
+
}
|
|
28
|
+
// If neither methods nor patterns are specified, run middleware on all requests
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Tests if a pathname matches a given pattern. The matching order is as follows:
|
|
33
|
+
*
|
|
34
|
+
* - Exact string
|
|
35
|
+
* - Named parameters (supports `[param]` and `[...param]`)
|
|
36
|
+
* - Regular expression
|
|
37
|
+
*/
|
|
38
|
+
function matchesPattern(pathname, pattern) {
|
|
39
|
+
if (typeof pattern === 'string') {
|
|
40
|
+
if (pattern === pathname) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (hasNamedParameters(pattern)) {
|
|
44
|
+
return namedParamToRegex(pattern).test(pathname);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (pattern instanceof RegExp) {
|
|
48
|
+
return pattern.test(pathname);
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if a pattern contains named parameters like `[postId]` or `[...slug]`
|
|
54
|
+
*/
|
|
55
|
+
function hasNamedParameters(pattern) {
|
|
56
|
+
return pattern.split('/').some((segment) => {
|
|
57
|
+
return matchDynamicName(segment) || matchDeepDynamicRouteName(segment);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Convert a pattern with named parameters to regex
|
|
62
|
+
*/
|
|
63
|
+
function namedParamToRegex(pattern) {
|
|
64
|
+
const normalizedPattern = pattern.replace(/\/$/, '') || '/';
|
|
65
|
+
const segments = normalizedPattern.split('/');
|
|
66
|
+
const regexSegments = segments.map((segment) => {
|
|
67
|
+
if (!segment)
|
|
68
|
+
return '';
|
|
69
|
+
if (matchDeepDynamicRouteName(segment)) {
|
|
70
|
+
return '.+';
|
|
71
|
+
}
|
|
72
|
+
if (matchDynamicName(segment)) {
|
|
73
|
+
return '[^/]+';
|
|
74
|
+
}
|
|
75
|
+
return segment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
76
|
+
});
|
|
77
|
+
return new RegExp(`^${regexSegments.join('/')}(?:/)?$`);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/utils/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAOzE;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgB,EAAE,UAA4B;IAChF,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,EAAE,OAAO,CAAC;IAEtD,mDAAmD;IACnD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IAE9B,mCAAmC;IACnC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;QACtE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9D,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,oCAAoC;IACpC,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,OAA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AC,IAAI,GAAG,CAAC;IAC5D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7C,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,CAAC;QAExB,IAAI,yBAAyB,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9B,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,OAAO,OAAO,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,MAAM,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Manifest, MiddlewareInfo, Route } from '../manifest';
|
|
2
|
+
import { MiddlewareModule } from '../utils/middleware';
|
|
3
|
+
/** Internal errors class to indicate that the server has failed
|
|
4
|
+
* @remarks
|
|
5
|
+
* This should be thrown for unexpected errors, so they show up as crashes.
|
|
6
|
+
* Typically malformed project structure, missing manifest, html or other files.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ExpoError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
static isExpoError(error: unknown): error is ExpoError;
|
|
11
|
+
}
|
|
12
|
+
type ResponseInitLike = Omit<ResponseInit, 'headers'> & {
|
|
13
|
+
headers: Headers;
|
|
14
|
+
cf?: unknown;
|
|
15
|
+
webSocket?: unknown;
|
|
16
|
+
};
|
|
17
|
+
type CallbackRouteType = 'html' | 'api' | 'notFoundHtml' | 'notAllowedApi';
|
|
18
|
+
type CallbackRoute = (Route & {
|
|
19
|
+
type: CallbackRouteType;
|
|
20
|
+
}) | {
|
|
21
|
+
type: null;
|
|
22
|
+
};
|
|
23
|
+
type BeforeResponseCallback = (responseInit: ResponseInitLike, route: CallbackRoute) => ResponseInitLike;
|
|
24
|
+
export interface RequestHandlerParams {
|
|
25
|
+
getHtml: (request: Request, route: Route) => Promise<string | Response | null>;
|
|
26
|
+
getRoutesManifest: () => Promise<Manifest | null>;
|
|
27
|
+
getApiRoute: (route: Route) => Promise<any>;
|
|
28
|
+
getMiddleware: (route: MiddlewareInfo) => Promise<MiddlewareModule>;
|
|
29
|
+
handleRouteError: (error: Error) => Promise<Response>;
|
|
30
|
+
/** Before handler response 4XX, not before unhandled error */
|
|
31
|
+
beforeErrorResponse?: BeforeResponseCallback;
|
|
32
|
+
/** Before handler responses */
|
|
33
|
+
beforeResponse?: BeforeResponseCallback;
|
|
34
|
+
/** Before handler HTML responses, not before 404 HTML */
|
|
35
|
+
beforeHTMLResponse?: BeforeResponseCallback;
|
|
36
|
+
/** Before handler API responses */
|
|
37
|
+
beforeAPIResponse?: BeforeResponseCallback;
|
|
38
|
+
}
|
|
39
|
+
export declare function createRequestHandler({ getRoutesManifest, getHtml, getApiRoute, handleRouteError, getMiddleware, beforeErrorResponse, beforeResponse, beforeHTMLResponse, beforeAPIResponse, }: RequestHandlerParams): (request: Request) => Promise<Response>;
|
|
40
|
+
export {};
|