expo-server 0.0.0 → 1.0.0

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 (158) hide show
  1. package/README.md +1 -0
  2. package/build/cjs/ImmutableRequest.d.ts +61 -0
  3. package/build/cjs/ImmutableRequest.js +160 -0
  4. package/build/cjs/ImmutableRequest.js.map +1 -0
  5. package/build/cjs/global.types.d.ts +13 -0
  6. package/build/cjs/global.types.js +3 -0
  7. package/build/cjs/global.types.js.map +1 -0
  8. package/build/cjs/index.d.ts +2 -0
  9. package/build/cjs/index.js +18 -0
  10. package/build/cjs/index.js.map +1 -0
  11. package/build/cjs/manifest.d.ts +27 -0
  12. package/build/cjs/manifest.js +3 -0
  13. package/build/cjs/manifest.js.map +1 -0
  14. package/build/cjs/middleware/rsc.d.ts +36 -0
  15. package/build/cjs/middleware/rsc.js +124 -0
  16. package/build/cjs/middleware/rsc.js.map +1 -0
  17. package/build/cjs/private.d.ts +2 -0
  18. package/build/cjs/private.js +6 -0
  19. package/build/cjs/private.js.map +1 -0
  20. package/build/cjs/runtime/api.d.ts +39 -0
  21. package/build/cjs/runtime/api.js +73 -0
  22. package/build/cjs/runtime/api.js.map +1 -0
  23. package/build/cjs/runtime/error.d.ts +36 -0
  24. package/build/cjs/runtime/error.js +86 -0
  25. package/build/cjs/runtime/error.js.map +1 -0
  26. package/build/cjs/runtime/index.d.ts +10 -0
  27. package/build/cjs/runtime/index.js +77 -0
  28. package/build/cjs/runtime/index.js.map +1 -0
  29. package/build/cjs/runtime/scope.d.ts +15 -0
  30. package/build/cjs/runtime/scope.js +12 -0
  31. package/build/cjs/runtime/scope.js.map +1 -0
  32. package/build/cjs/types.d.ts +57 -0
  33. package/build/cjs/types.js +3 -0
  34. package/build/cjs/types.js.map +1 -0
  35. package/build/cjs/utils/createReadableStreamFromReadable.d.ts +15 -0
  36. package/build/cjs/utils/createReadableStreamFromReadable.js +97 -0
  37. package/build/cjs/utils/createReadableStreamFromReadable.js.map +1 -0
  38. package/build/cjs/utils/importMetaRegistry.d.ts +3 -0
  39. package/build/cjs/utils/importMetaRegistry.js +30 -0
  40. package/build/cjs/utils/importMetaRegistry.js.map +1 -0
  41. package/build/cjs/utils/matchers.d.ts +12 -0
  42. package/build/cjs/utils/matchers.js +76 -0
  43. package/build/cjs/utils/matchers.js.map +1 -0
  44. package/build/cjs/utils/middleware.d.ts +9 -0
  45. package/build/cjs/utils/middleware.js +82 -0
  46. package/build/cjs/utils/middleware.js.map +1 -0
  47. package/build/cjs/vendor/abstract.d.ts +40 -0
  48. package/build/cjs/vendor/abstract.js +245 -0
  49. package/build/cjs/vendor/abstract.js.map +1 -0
  50. package/build/cjs/vendor/bun.d.ts +10 -0
  51. package/build/cjs/vendor/bun.js +22 -0
  52. package/build/cjs/vendor/bun.js.map +1 -0
  53. package/build/cjs/vendor/eas.d.ts +10 -0
  54. package/build/cjs/vendor/eas.js +28 -0
  55. package/build/cjs/vendor/eas.js.map +1 -0
  56. package/build/cjs/vendor/environment/common.d.ts +14 -0
  57. package/build/cjs/vendor/environment/common.js +66 -0
  58. package/build/cjs/vendor/environment/common.js.map +1 -0
  59. package/build/cjs/vendor/environment/node.d.ts +14 -0
  60. package/build/cjs/vendor/environment/node.js +55 -0
  61. package/build/cjs/vendor/environment/node.js.map +1 -0
  62. package/build/cjs/vendor/environment/workerd.d.ts +18 -0
  63. package/build/cjs/vendor/environment/workerd.js +72 -0
  64. package/build/cjs/vendor/environment/workerd.js.map +1 -0
  65. package/build/cjs/vendor/express.d.ts +14 -0
  66. package/build/cjs/vendor/express.js +100 -0
  67. package/build/cjs/vendor/express.js.map +1 -0
  68. package/build/cjs/vendor/http.d.ts +15 -0
  69. package/build/cjs/vendor/http.js +103 -0
  70. package/build/cjs/vendor/http.js.map +1 -0
  71. package/build/cjs/vendor/netlify.d.ts +15 -0
  72. package/build/cjs/vendor/netlify.js +46 -0
  73. package/build/cjs/vendor/netlify.js.map +1 -0
  74. package/build/cjs/vendor/vercel.d.ts +13 -0
  75. package/build/cjs/vendor/vercel.js +109 -0
  76. package/build/cjs/vendor/vercel.js.map +1 -0
  77. package/build/cjs/vendor/workerd.d.ts +11 -0
  78. package/build/cjs/vendor/workerd.js +22 -0
  79. package/build/cjs/vendor/workerd.js.map +1 -0
  80. package/build/mjs/ImmutableRequest.d.ts +61 -0
  81. package/build/mjs/ImmutableRequest.js +155 -0
  82. package/build/mjs/ImmutableRequest.js.map +1 -0
  83. package/build/mjs/global.types.d.ts +13 -0
  84. package/build/mjs/global.types.js +2 -0
  85. package/build/mjs/global.types.js.map +1 -0
  86. package/build/mjs/index.d.ts +2 -0
  87. package/build/mjs/index.js +2 -0
  88. package/build/mjs/index.js.map +1 -0
  89. package/build/mjs/manifest.d.ts +27 -0
  90. package/build/mjs/manifest.js +2 -0
  91. package/build/mjs/manifest.js.map +1 -0
  92. package/build/mjs/middleware/rsc.d.ts +36 -0
  93. package/build/mjs/middleware/rsc.js +119 -0
  94. package/build/mjs/middleware/rsc.js.map +1 -0
  95. package/build/mjs/private.d.ts +2 -0
  96. package/build/mjs/private.js +2 -0
  97. package/build/mjs/private.js.map +1 -0
  98. package/build/mjs/runtime/api.d.ts +39 -0
  99. package/build/mjs/runtime/api.js +65 -0
  100. package/build/mjs/runtime/api.js.map +1 -0
  101. package/build/mjs/runtime/error.d.ts +36 -0
  102. package/build/mjs/runtime/error.js +81 -0
  103. package/build/mjs/runtime/error.js.map +1 -0
  104. package/build/mjs/runtime/index.d.ts +10 -0
  105. package/build/mjs/runtime/index.js +74 -0
  106. package/build/mjs/runtime/index.js.map +1 -0
  107. package/build/mjs/runtime/scope.d.ts +15 -0
  108. package/build/mjs/runtime/scope.js +9 -0
  109. package/build/mjs/runtime/scope.js.map +1 -0
  110. package/build/mjs/types.d.ts +57 -0
  111. package/build/mjs/types.js +2 -0
  112. package/build/mjs/types.js.map +1 -0
  113. package/build/mjs/utils/createReadableStreamFromReadable.d.ts +15 -0
  114. package/build/mjs/utils/createReadableStreamFromReadable.js +93 -0
  115. package/build/mjs/utils/createReadableStreamFromReadable.js.map +1 -0
  116. package/build/mjs/utils/importMetaRegistry.d.ts +3 -0
  117. package/build/mjs/utils/importMetaRegistry.js +27 -0
  118. package/build/mjs/utils/importMetaRegistry.js.map +1 -0
  119. package/build/mjs/utils/matchers.d.ts +12 -0
  120. package/build/mjs/utils/matchers.js +69 -0
  121. package/build/mjs/utils/matchers.js.map +1 -0
  122. package/build/mjs/utils/middleware.d.ts +9 -0
  123. package/build/mjs/utils/middleware.js +79 -0
  124. package/build/mjs/utils/middleware.js.map +1 -0
  125. package/build/mjs/vendor/abstract.d.ts +40 -0
  126. package/build/mjs/vendor/abstract.js +240 -0
  127. package/build/mjs/vendor/abstract.js.map +1 -0
  128. package/build/mjs/vendor/bun.d.ts +10 -0
  129. package/build/mjs/vendor/bun.js +17 -0
  130. package/build/mjs/vendor/bun.js.map +1 -0
  131. package/build/mjs/vendor/eas.d.ts +10 -0
  132. package/build/mjs/vendor/eas.js +23 -0
  133. package/build/mjs/vendor/eas.js.map +1 -0
  134. package/build/mjs/vendor/environment/common.d.ts +14 -0
  135. package/build/mjs/vendor/environment/common.js +63 -0
  136. package/build/mjs/vendor/environment/common.js.map +1 -0
  137. package/build/mjs/vendor/environment/node.d.ts +14 -0
  138. package/build/mjs/vendor/environment/node.js +48 -0
  139. package/build/mjs/vendor/environment/node.js.map +1 -0
  140. package/build/mjs/vendor/environment/workerd.d.ts +18 -0
  141. package/build/mjs/vendor/environment/workerd.js +68 -0
  142. package/build/mjs/vendor/environment/workerd.js.map +1 -0
  143. package/build/mjs/vendor/express.d.ts +14 -0
  144. package/build/mjs/vendor/express.js +92 -0
  145. package/build/mjs/vendor/express.js.map +1 -0
  146. package/build/mjs/vendor/http.d.ts +15 -0
  147. package/build/mjs/vendor/http.js +95 -0
  148. package/build/mjs/vendor/http.js.map +1 -0
  149. package/build/mjs/vendor/netlify.d.ts +15 -0
  150. package/build/mjs/vendor/netlify.js +41 -0
  151. package/build/mjs/vendor/netlify.js.map +1 -0
  152. package/build/mjs/vendor/vercel.d.ts +13 -0
  153. package/build/mjs/vendor/vercel.js +101 -0
  154. package/build/mjs/vendor/vercel.js.map +1 -0
  155. package/build/mjs/vendor/workerd.d.ts +11 -0
  156. package/build/mjs/vendor/workerd.js +17 -0
  157. package/build/mjs/vendor/workerd.js.map +1 -0
  158. package/package.json +68 -7
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StatusError = void 0;
4
+ exports.errorToResponse = errorToResponse;
5
+ /** An error response representation which can be thrown anywhere in server-side code.
6
+ *
7
+ * A `StatusError` can be thrown by a request handler and will be caught by the `expo-server`
8
+ * runtime and replaced by a `Response` with the `status` and `body` that's been passed to
9
+ * the `StatusError`.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { StatusError } from 'expo-server';
14
+ *
15
+ * export function GET(request, { postId }) {
16
+ * if (!postId) {
17
+ * throw new StatusError(400, 'postId parameter is required');
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ class StatusError extends Error {
23
+ status;
24
+ body;
25
+ constructor(status = 500, body, errorOptions) {
26
+ const cause = (errorOptions != null && errorOptions.cause) ??
27
+ (body != null && typeof body === 'object' && body.cause != null ? body.cause : undefined);
28
+ let message = typeof body === 'object' ? (body instanceof Error ? body.message : body.error) : body;
29
+ if (message == null) {
30
+ switch (status) {
31
+ case 400:
32
+ message = 'Bad Request';
33
+ break;
34
+ case 401:
35
+ message = 'Unauthorized';
36
+ break;
37
+ case 403:
38
+ message = 'Forbidden';
39
+ break;
40
+ case 404:
41
+ message = 'Not Found';
42
+ break;
43
+ case 500:
44
+ message = 'Internal Server Error';
45
+ break;
46
+ default:
47
+ message = 'Unknown Error';
48
+ }
49
+ }
50
+ super(message, cause ? { cause } : undefined);
51
+ this.name = 'StatusError';
52
+ this.status = status;
53
+ if (body instanceof Error) {
54
+ this.body = JSON.stringify({ error: body.message }, null, 2);
55
+ }
56
+ else {
57
+ this.body =
58
+ typeof body === 'object'
59
+ ? JSON.stringify(body, null, 2)
60
+ : (body ?? JSON.stringify({ error: message }, null, 2));
61
+ }
62
+ }
63
+ }
64
+ exports.StatusError = StatusError;
65
+ function errorToResponse(error) {
66
+ if (error instanceof StatusError) {
67
+ return new Response(error.body, {
68
+ status: error.status,
69
+ headers: {
70
+ 'Content-Type': 'application/json; charset=utf-8',
71
+ },
72
+ });
73
+ }
74
+ else if ('status' in error && typeof error.status === 'number') {
75
+ const body = 'body' in error && typeof error.body === 'string'
76
+ ? error.body
77
+ : JSON.stringify({ error: error.message }, null, 2);
78
+ return new Response(body, {
79
+ status: error.status,
80
+ });
81
+ }
82
+ else {
83
+ return new Response(`${error}`, { status: 500 });
84
+ }
85
+ }
86
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/runtime/error.ts"],"names":[],"mappings":";;;AAyEA,0CAmBC;AA5FD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,WAAY,SAAQ,KAAK;IACpC,MAAM,CAAS;IACf,IAAI,CAAS;IASb,YACE,MAAM,GAAG,GAAG,EACZ,IAA+E,EAC/E,YAAkC;QAElC,MAAM,KAAK,GACT,CAAC,YAAY,IAAI,IAAI,IAAI,YAAY,CAAC,KAAK,CAAC;YAC5C,CAAC,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC5F,IAAI,OAAO,GACT,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACxF,IAAI,OA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,CAAC,KAAK,CAAC,IAAI,EAAE;YAC9B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,OAAO,EAAE;gBACP,cAAc,EAAE,iCAAiC;aAClD;SACF,CAAC,CAAC;IACL,CAAC;SAAM,IAAI,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACjE,MAAM,IAAI,GACR,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;YAC/C,CAAC,CAAC,KAAK,CAAC,IAAI;YACZ,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACxD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;YACxB,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,QAAQ,CAAC,GAAG,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type ScopeDefinition, type RequestAPI } from './scope';
2
+ export interface RequestAPISetup extends RequestAPI {
3
+ origin?: string;
4
+ environment?: string | null;
5
+ waitUntil?(promise: Promise<unknown>): void;
6
+ }
7
+ type RequestContextFactory = (...args: any[]) => Partial<RequestAPISetup>;
8
+ type RequestScopeRunner<F extends RequestContextFactory> = (fn: (...args: Parameters<F>) => Promise<Response>, ...args: Parameters<F>) => Promise<Response>;
9
+ export declare function createRequestScope<F extends RequestContextFactory>(scopeDefinition: ScopeDefinition, makeRequestAPISetup: F): RequestScopeRunner<F>;
10
+ export {};
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRequestScope = createRequestScope;
4
+ const error_1 = require("./error");
5
+ const scope_1 = require("./scope");
6
+ const importMetaRegistry_1 = require("../utils/importMetaRegistry");
7
+ function setupRuntime() {
8
+ try {
9
+ Object.defineProperty(globalThis, 'origin', {
10
+ enumerable: true,
11
+ configurable: true,
12
+ get() {
13
+ return scope_1.scopeRef.current?.getStore()?.origin || 'null';
14
+ },
15
+ });
16
+ }
17
+ catch { }
18
+ try {
19
+ Object.defineProperty(globalThis, '__ExpoImportMetaRegistry', {
20
+ enumerable: true,
21
+ configurable: true,
22
+ get() {
23
+ return importMetaRegistry_1.importMetaRegistry;
24
+ },
25
+ });
26
+ }
27
+ catch { }
28
+ }
29
+ function createRequestScope(scopeDefinition, makeRequestAPISetup) {
30
+ setupRuntime();
31
+ // NOTE(@kitten): For long-running servers, this will always be a noop. It therefore
32
+ // makes sense for us to provide a default that doesn't do anything.
33
+ function defaultWaitUntil(promise) {
34
+ promise.finally(() => { });
35
+ }
36
+ return async (run, ...args) => {
37
+ // Initialize the scope definition which is used to isolate the runtime API between
38
+ // requests. The implementation of scopes differs per runtime, and is only initialized
39
+ // once the first request is received
40
+ scope_1.scopeRef.current = scopeDefinition;
41
+ const setup = makeRequestAPISetup(...args);
42
+ const { waitUntil = defaultWaitUntil } = setup;
43
+ const scope = {
44
+ ...setup,
45
+ origin: setup.origin,
46
+ environment: setup.environment,
47
+ waitUntil,
48
+ deferTask: setup.deferTask,
49
+ };
50
+ const deferredTasks = [];
51
+ if (!scope.deferTask) {
52
+ scope.deferTask = function deferTask(fn) {
53
+ deferredTasks.push(fn);
54
+ };
55
+ }
56
+ let result;
57
+ try {
58
+ result =
59
+ scope_1.scopeRef.current != null
60
+ ? await scope_1.scopeRef.current.run(scope, () => run(...args))
61
+ : await run(...args);
62
+ }
63
+ catch (error) {
64
+ if (error != null && error instanceof Error && 'status' in error) {
65
+ return (0, error_1.errorToResponse)(error);
66
+ }
67
+ else {
68
+ throw error;
69
+ }
70
+ }
71
+ if (deferredTasks.length) {
72
+ deferredTasks.forEach((fn) => waitUntil(fn()));
73
+ }
74
+ return result;
75
+ };
76
+ }
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":";;AAsCA,gDAwDC;AA9FD,mCAA0C;AAC1C,mCAA0E;AAC1E,oEAAiE;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,gBAAQ,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,uCAAkB,CAAC;YAC5B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;AACZ,CAAC;AASD,SAAgB,kBAAkB,CAChC,eAAgC,EAChC,mBAAsB;IAEtB,YAAY,EAAE,CAAC;IAEf,oFAAoF;IACpF,oEAAoE;IACpE,SAAS,gBAAgB,CAAC,OAAyB;QACjD,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE;QAC5B,mFAAmF;QACnF,sFAAsF;QACtF,qCAAqC;QACrC,gBAAQ,CAAC,OAAO,GAAG,eAAe,CAAC;QAEnC,MAAM,KAAK,GAAG,mBAAmB,CAAC,GAAG,IAAI,CAAC,CAAC;QAC3C,MAAM,EAAE,SAAS,GAAG,gBAAgB,EAAE,GAAG,KAAK,CAA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<unknown>): void;
5
+ deferTask?(fn: () => Promise<unknown>): void;
6
+ }
7
+ export interface ScopeDefinition<Scope extends RequestAPI = any> {
8
+ getStore(): Scope | undefined;
9
+ run<R>(scope: Scope, runner: () => R): R;
10
+ run<R, TArgs extends any[]>(scope: Scope, runner: (...args: TArgs) => R, ...args: TArgs): R;
11
+ }
12
+ declare const scopeRef: {
13
+ current: ScopeDefinition<RequestAPI> | null;
14
+ };
15
+ export { scopeRef };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scopeRef = void 0;
4
+ // NOTE(@kitten): When multiple versions of `@expo/server` are bundled, we still want to reuse the same scope definition
5
+ const scopeSymbol = Symbol.for('expoServerRuntime');
6
+ const sharedScope = globalThis;
7
+ const scopeRef = sharedScope[scopeSymbol] ||
8
+ (sharedScope[scopeSymbol] = {
9
+ current: null,
10
+ });
11
+ exports.scopeRef = scopeRef;
12
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/runtime/scope.ts"],"names":[],"mappings":";;;AAaA,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;AAEI,4BAAQ"}
@@ -0,0 +1,57 @@
1
+ import type { _ImmutableRequest } from './ImmutableRequest';
2
+ /** An immutable version of the Fetch API's `Request` as received by middleware functions.
3
+ * It cannot be mutated or modified, its headers are immutable, and you won't have access to the request body.
4
+ */
5
+ export interface ImmutableRequest extends _ImmutableRequest {
6
+ readonly url: string;
7
+ readonly method: string;
8
+ }
9
+ /**
10
+ * Middleware function type. Middleware run for every request in your app, or on
11
+ * specified conditonally matched methods and path patterns, as per {@link MiddlewareMatcher}.
12
+ * @param request - An `ImmutableRequest` with read-only headers and no body access
13
+ * @example
14
+ * ```ts
15
+ * import type { MiddlewareFunction } from 'expo-server';
16
+ *
17
+ * const middleware: MiddlewareFunction = async (request) => {
18
+ * console.log(`Middleware executed for: ${request.url}`);
19
+ * };
20
+ *
21
+ * export default middleware;
22
+ * ```
23
+ * @see https://docs.expo.dev/router/reference/middleware/
24
+ */
25
+ export type MiddlewareFunction = (request: ImmutableRequest) => Promise<Response | void> | Response | void;
26
+ /** Middleware matcher settings that restricts the middleware to run conditionally. */
27
+ export interface MiddlewareMatcher {
28
+ /** Set this to a list of path patterns to conditionally run middleware on. This may be exact paths,
29
+ * paths containing parameter or catch-all segments (`'/posts/[postId]'` or `'/blog/[...slug]'`), or
30
+ * regular expressions matching paths.
31
+ * @example ['/api', '/posts/[id]', '/blog/[...slug]']
32
+ */
33
+ patterns?: (string | RegExp)[];
34
+ /** Set this to a list of HTTP methods to conditionally run middleware on. By default, middleware will
35
+ * match all HTTP methods.
36
+ * @example ['POST', 'PUT', 'DELETE']
37
+ */
38
+ methods?: string[];
39
+ }
40
+ /** Exported from a `+middleware.ts` file to configure the server-side middleware function.
41
+ * @example
42
+ * ```ts
43
+ * import type { MiddlewareSettings } from 'expo-server';
44
+ *
45
+ * export const unstable_settings: MiddlewareSettings = {
46
+ * matcher: {
47
+ * methods: ['GET'],
48
+ * patterns: ['/api', '/admin/[...path]'],
49
+ * },
50
+ * };
51
+ * ```
52
+ * @see https://docs.expo.dev/router/reference/middleware/
53
+ */
54
+ export interface MiddlewareSettings {
55
+ /** Matcher definition that restricts the middleware to run conditionally. */
56
+ matcher?: MiddlewareMatcher;
57
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -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,97 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright © 2025 650 Industries.
4
+ * Copyright (c) Remix Software Inc. 2020-2021
5
+ * Copyright (c) Shopify Inc. 2022-2024
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ *
10
+ * Original license https://github.com/remix-run/remix/blob/6d6caaed5dfc436242962dcb2ff9617757a11e17/LICENSE.md
11
+ * Code from https://github.com/remix-run/remix/blob/6d6caaed5dfc436242962dcb2ff9617757a11e17/packages/remix-node/stream.ts#L66
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.createReadableStreamFromReadable = void 0;
15
+ const node_stream_1 = require("node:stream");
16
+ const createReadableStreamFromReadable = (source) => {
17
+ const pump = new StreamPump(source);
18
+ const stream = new ReadableStream(pump, pump);
19
+ return stream;
20
+ };
21
+ exports.createReadableStreamFromReadable = createReadableStreamFromReadable;
22
+ class StreamPump {
23
+ highWaterMark;
24
+ accumalatedSize;
25
+ stream;
26
+ controller;
27
+ constructor(stream) {
28
+ this.highWaterMark =
29
+ stream.readableHighWaterMark || new node_stream_1.Stream.Readable().readableHighWaterMark;
30
+ this.accumalatedSize = 0;
31
+ this.stream = stream;
32
+ this.enqueue = this.enqueue.bind(this);
33
+ this.error = this.error.bind(this);
34
+ this.close = this.close.bind(this);
35
+ }
36
+ size(chunk) {
37
+ return chunk?.byteLength || 0;
38
+ }
39
+ start(controller) {
40
+ this.controller = controller;
41
+ this.stream.on('data', this.enqueue);
42
+ this.stream.once('error', this.error);
43
+ this.stream.once('end', this.close);
44
+ this.stream.once('close', this.close);
45
+ }
46
+ pull() {
47
+ this.resume();
48
+ }
49
+ cancel(reason) {
50
+ if (this.stream.destroy) {
51
+ this.stream.destroy(reason);
52
+ }
53
+ this.stream.off('data', this.enqueue);
54
+ this.stream.off('error', this.error);
55
+ this.stream.off('end', this.close);
56
+ this.stream.off('close', this.close);
57
+ }
58
+ enqueue(chunk) {
59
+ if (this.controller) {
60
+ try {
61
+ const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
62
+ const available = (this.controller.desiredSize || 0) - bytes.byteLength;
63
+ this.controller.enqueue(bytes);
64
+ if (available <= 0) {
65
+ this.pause();
66
+ }
67
+ }
68
+ catch {
69
+ 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'));
70
+ this.cancel();
71
+ }
72
+ }
73
+ }
74
+ pause() {
75
+ if (this.stream.pause) {
76
+ this.stream.pause();
77
+ }
78
+ }
79
+ resume() {
80
+ if (this.stream.readable && this.stream.resume) {
81
+ this.stream.resume();
82
+ }
83
+ }
84
+ close() {
85
+ if (this.controller) {
86
+ this.controller.close();
87
+ delete this.controller;
88
+ }
89
+ }
90
+ error(error) {
91
+ if (this.controller) {
92
+ this.controller.error(error);
93
+ delete this.controller;
94
+ }
95
+ }
96
+ }
97
+ //# sourceMappingURL=createReadableStreamFromReadable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createReadableStreamFromReadable.js","sourceRoot":"","sources":["../../../src/utils/createReadableStreamFromReadable.ts"],"names":[],"mappings":";AAAA;;;;;;;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K,CACP,+HAA+H,CAChI,CACF,CAAC;gBACF,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACtB,IAAI,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,3 @@
1
+ export declare const importMetaRegistry: {
2
+ readonly url: any;
3
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.importMetaRegistry = void 0;
4
+ const DEFAULT_SCRIPT_NAME = 'file:///__main.js';
5
+ // - ./runtime/importMetaRegistry.ts (this file) -> importMetaRegistry.url
6
+ // - ./runtime/index.ts -> globalThis.__ExpoImportMetaRegistry
7
+ // - <source>
8
+ const CALL_DEPTH = 3;
9
+ function getFileName(offset = 0) {
10
+ const originalStackFormatter = Error.prepareStackTrace;
11
+ const originalStackTraceLimit = Error.stackTraceLimit;
12
+ try {
13
+ Error.stackTraceLimit = offset;
14
+ Error.prepareStackTrace = (_err, stack) => stack[offset - 1]?.getFileName();
15
+ return new Error().stack;
16
+ }
17
+ finally {
18
+ Error.prepareStackTrace = originalStackFormatter;
19
+ Error.stackTraceLimit = originalStackTraceLimit;
20
+ }
21
+ }
22
+ exports.importMetaRegistry = {
23
+ get url() {
24
+ let scriptName = getFileName(CALL_DEPTH);
25
+ if (scriptName?.[0] === '/')
26
+ scriptName = `file://${scriptName}`;
27
+ return scriptName || DEFAULT_SCRIPT_NAME;
28
+ },
29
+ };
30
+ //# 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;AAEY,QAAA,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,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isResponse = isResponse;
4
+ exports.parseParams = parseParams;
5
+ exports.getRedirectRewriteLocation = getRedirectRewriteLocation;
6
+ exports.matchDynamicName = matchDynamicName;
7
+ exports.matchDeepDynamicRouteName = matchDeepDynamicRouteName;
8
+ function isResponse(input) {
9
+ return !!input && typeof input === 'object' && input instanceof Response;
10
+ }
11
+ function parseParams(request, route) {
12
+ const params = {};
13
+ const { pathname } = new URL(request.url);
14
+ const match = route.namedRegex.exec(pathname);
15
+ if (match?.groups) {
16
+ for (const [key, value] of Object.entries(match.groups)) {
17
+ const namedKey = route.routeKeys[key];
18
+ params[namedKey] = value;
19
+ }
20
+ }
21
+ return params;
22
+ }
23
+ function getRedirectRewriteLocation(url, request, route) {
24
+ const originalQueryParams = url.searchParams.entries();
25
+ const params = parseParams(request, route);
26
+ const target = route.page
27
+ .split('/')
28
+ .map((segment) => {
29
+ let match;
30
+ if ((match = matchDynamicName(segment))) {
31
+ const value = params[match];
32
+ delete params[match];
33
+ return typeof value === 'string'
34
+ ? value.split('/')[0] /* If we are redirecting from a catch-all route, we need to remove the extra segments */
35
+ : (value ?? segment);
36
+ }
37
+ else if ((match = matchDeepDynamicRouteName(segment))) {
38
+ const value = params[match];
39
+ delete params[match];
40
+ return value ?? segment;
41
+ }
42
+ else {
43
+ return segment;
44
+ }
45
+ })
46
+ .join('/');
47
+ const targetUrl = new URL(target, url.origin);
48
+ // NOTE: React Navigation doesn't differentiate between a path parameter
49
+ // and a search parameter. We have to preserve leftover search parameters
50
+ // to ensure we don't lose any intentional parameters with special meaning
51
+ for (const key in params)
52
+ targetUrl.searchParams.append(key, params[key]);
53
+ // NOTE(@krystofwoldrich): Query matching is not supported at the moment.
54
+ // Copy original query parameters to the target URL
55
+ for (const [key, value] of originalQueryParams) {
56
+ // NOTE(@krystofwoldrich): Params created from route overwrite existing (might be unexpected to the user)
57
+ if (!targetUrl.searchParams.has(key)) {
58
+ targetUrl.searchParams.append(key, value);
59
+ }
60
+ }
61
+ return targetUrl;
62
+ }
63
+ /** Match `[page]` -> `page`
64
+ * @privateRemarks Ported from `expo-router/src/matchers.tsx`
65
+ */
66
+ function matchDynamicName(name) {
67
+ // Don't match `...` or `[` or `]` inside the brackets
68
+ return name.match(/^\[([^[\](?:\.\.\.)]+?)\]$/)?.[1]; // eslint-disable-line no-useless-escape
69
+ }
70
+ /** Match `[...page]` -> `page`
71
+ * @privateRemarks Ported from `expo-router/src/matchers.tsx`
72
+ */
73
+ function matchDeepDynamicRouteName(name) {
74
+ return name.match(/^\[\.\.\.([^/]+?)\]$/)?.[1];
75
+ }
76
+ //# sourceMappingURL=matchers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchers.js","sourceRoot":"","sources":["../../../src/utils/matchers.ts"],"names":[],"mappings":";;AAEA,gCAEC;AAED,kCAWC;AAED,gEAyCC;AAKD,4CAGC;AAKD,8DAEC;AAzED,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,QAAQ,CAAC;AAC3E,CAAC;AA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AAC,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,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shouldRunMiddleware = shouldRunMiddleware;
4
+ const matchers_1 = require("./matchers");
5
+ /**
6
+ * Determines whether middleware should run for a given request based on matcher configuration.
7
+ */
8
+ function shouldRunMiddleware(request, middleware) {
9
+ const matcher = middleware.unstable_settings?.matcher;
10
+ // No matcher means middleware runs on all requests
11
+ if (!matcher) {
12
+ return true;
13
+ }
14
+ const url = new URL(request.url);
15
+ const pathname = url.pathname;
16
+ // Check HTTP methods, if specified
17
+ if (matcher.methods) {
18
+ const methods = matcher.methods.map((method) => method.toUpperCase());
19
+ if (methods.length === 0 || !methods.includes(request.method)) {
20
+ return false;
21
+ }
22
+ }
23
+ // Check path patterns, if specified
24
+ if (matcher.patterns) {
25
+ const patterns = Array.isArray(matcher.patterns) ? matcher.patterns : [matcher.patterns];
26
+ if (patterns.length === 0) {
27
+ return false;
28
+ }
29
+ return patterns.some((pattern) => matchesPattern(pathname, pattern));
30
+ }
31
+ // If neither methods nor patterns are specified, run middleware on all requests
32
+ return true;
33
+ }
34
+ /**
35
+ * Tests if a pathname matches a given pattern. The matching order is as follows:
36
+ *
37
+ * - Exact string
38
+ * - Named parameters (supports `[param]` and `[...param]`)
39
+ * - Regular expression
40
+ */
41
+ function matchesPattern(pathname, pattern) {
42
+ if (typeof pattern === 'string') {
43
+ if (pattern === pathname) {
44
+ return true;
45
+ }
46
+ if (hasNamedParameters(pattern)) {
47
+ return namedParamToRegex(pattern).test(pathname);
48
+ }
49
+ }
50
+ else if (pattern != null) {
51
+ return pattern.test(pathname);
52
+ }
53
+ return false;
54
+ }
55
+ /**
56
+ * Check if a pattern contains named parameters like `[postId]` or `[...slug]`
57
+ */
58
+ function hasNamedParameters(pattern) {
59
+ return pattern.split('/').some((segment) => {
60
+ return (0, matchers_1.matchDynamicName)(segment) || (0, matchers_1.matchDeepDynamicRouteName)(segment);
61
+ });
62
+ }
63
+ /**
64
+ * Convert a pattern with named parameters to regex
65
+ */
66
+ function namedParamToRegex(pattern) {
67
+ const normalizedPattern = pattern.replace(/\/$/, '') || '/';
68
+ const segments = normalizedPattern.split('/');
69
+ const regexSegments = segments.map((segment) => {
70
+ if (!segment)
71
+ return '';
72
+ if ((0, matchers_1.matchDeepDynamicRouteName)(segment)) {
73
+ return '.+';
74
+ }
75
+ if ((0, matchers_1.matchDynamicName)(segment)) {
76
+ return '[^/]+';
77
+ }
78
+ return segment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
79
+ });
80
+ return new RegExp(`^${regexSegments.join('/')}(?:/)?$`);
81
+ }
82
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/utils/middleware.ts"],"names":[],"mappings":";;AAWA,kDA8BC;AAxCD,yCAAyE;AAOzE;;GAEG;AACH,SAAgB,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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