gemi 0.4.18 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/App.d.ts +0 -1
- package/dist/app/App.d.ts.map +1 -1
- package/dist/app/App.test.d.ts +20 -0
- package/dist/app/App.test.d.ts.map +1 -0
- package/dist/app/createComponentTree.test.d.ts +2 -0
- package/dist/app/createComponentTree.test.d.ts.map +1 -0
- package/dist/app/createFlatApiRoutes.d.ts.map +1 -1
- package/dist/app/createFlatApiRoutes.test.d.ts +2 -0
- package/dist/app/createFlatApiRoutes.test.d.ts.map +1 -0
- package/dist/app/createFlatViewRoutes.test.d.ts +2 -0
- package/dist/app/createFlatViewRoutes.test.d.ts.map +1 -0
- package/dist/app/createRouteManifest.test.d.ts +2 -0
- package/dist/app/createRouteManifest.test.d.ts.map +1 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +1 -504
- package/dist/chunk-0d0f764773c0f6b8.js +2 -0
- package/dist/chunk-0e3473f7e43f4876.js +2 -0
- package/dist/chunk-847629c9a7550cc3.js +2 -0
- package/dist/email/index.js +1 -68
- package/dist/facades/index.js +1 -59
- package/dist/http/index.js +1 -454
- package/dist/kernel/index.js +2 -13352
- package/dist/server/index.js +5 -6479
- package/dist/vite/index.js +1 -17
- package/package.json +1 -1
package/dist/app/App.d.ts
CHANGED
|
@@ -39,7 +39,6 @@ export declare class App {
|
|
|
39
39
|
private prepare;
|
|
40
40
|
getComponentTree(): ComponentTree;
|
|
41
41
|
setRenderParams(params: RenderParams): void;
|
|
42
|
-
private resolvePageData;
|
|
43
42
|
private runMiddleware;
|
|
44
43
|
handleApiRequest(req: Request): Promise<Response>;
|
|
45
44
|
handleViewRequest(req: Request): Promise<Response>;
|
package/dist/app/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../app/App.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAsB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../app/App.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAsB,MAAM,oBAAoB,CAAC;AAIpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAU3C,OAAO,EAAE,aAAa,EAA2B,MAAM,OAAO,CAAC;AAI/D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAInC,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,UAAU,SAAS;IACjB,UAAU,EAAE,UAAU,UAAU,CAAC;IACjC,SAAS,EAAE,UAAU,SAAS,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,EAAE,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,UAAU,CAAC,CAAC;IACzD,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,UAAU,MAAM,CAAC;CAC1B;AAED,qBAAa,GAAG;IACd,OAAO,CAAC,YAAY,CAKlB;IACF,OAAO,CAAC,cAAc,CAGf;IACP,OAAO,CAAC,aAAa,CASd;IACP,OAAO,CAAC,aAAa,CAAgC;IAC9C,IAAI,SAAS;IACpB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,aAAa,CAAgB;IAC9B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,UAAU,CAAC,CAAM;IAC7D,UAAU,SAAK;IACtB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,SAAS;IAW7B,OAAO,CAAC,OAAO;IAyCR,gBAAgB;IAIhB,eAAe,CAAC,MAAM,EAAE,YAAY;IAI3C,OAAO,CAAC,aAAa;IAsCf,gBAAgB,CAAC,GAAG,EAAE,OAAO;IAsF7B,iBAAiB,CAAC,GAAG,EAAE,OAAO;IA6L9B,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAc5C,OAAO,CAAC,sBAAsB,CAGtB;IACR,OAAO,CAAC,mBAAmB,CAEzB;IACF,OAAO,CAAC,oBAAoB,CAM1B;IAEF,SAAS;sBAdH,eAAe,WACV,MAAM,GAAG,MAAM;mBAES,eAAe;oBAI5C,eAAe,QACb,MAAM,UACJ,MAAM;MASd;CACH"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RequestBreakerError } from "../http";
|
|
2
|
+
export declare class AuthenticationError extends RequestBreakerError {
|
|
3
|
+
constructor();
|
|
4
|
+
payload: {
|
|
5
|
+
api: {
|
|
6
|
+
status: number;
|
|
7
|
+
data: {
|
|
8
|
+
error: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
view: {
|
|
12
|
+
status: number;
|
|
13
|
+
headers: {
|
|
14
|
+
"Cache-Control": string;
|
|
15
|
+
Location: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=App.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"App.test.d.ts","sourceRoot":"","sources":["../../app/App.test.ts"],"names":[],"mappings":"AAUA,OAAO,EAAc,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAyD1D,qBAAa,mBAAoB,SAAQ,mBAAmB;;IAM1D,OAAO;;;;;;;;;;;;;;MAaL;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createComponentTree.test.d.ts","sourceRoot":"","sources":["../../app/createComponentTree.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFlatApiRoutes.d.ts","sourceRoot":"","sources":["../../app/createFlatApiRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,
|
|
1
|
+
{"version":3,"file":"createFlatApiRoutes.d.ts","sourceRoot":"","sources":["../../app/createFlatApiRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,SAAS,EAA4B,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,KAAK,YAAY,GAAG,GAAG,CAAC;AAQxB,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS;UAMvC,YAAY;gBACN,CAAC,MAAM,GAAG,CAAC,UAAU,UAAU,CAAC,GAAG,gBAAgB,CAAC,EAAE;IAyDzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFlatApiRoutes.test.d.ts","sourceRoot":"","sources":["../../app/createFlatApiRoutes.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFlatViewRoutes.test.d.ts","sourceRoot":"","sources":["../../app/createFlatViewRoutes.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRouteManifest.test.d.ts","sourceRoot":"","sources":["../../app/createRouteManifest.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/app/index.js
CHANGED
|
@@ -1,505 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import {
|
|
3
|
-
HttpRequest,
|
|
4
|
-
isConstructor
|
|
5
|
-
} from "../http/index.js";
|
|
6
|
-
import {
|
|
7
|
-
generateETag,
|
|
8
|
-
me
|
|
9
|
-
} from "../chunk-21e105fb2b3d36d7.js";
|
|
10
|
-
import {
|
|
11
|
-
GEMI_REQUEST_BREAKER_ERROR,
|
|
12
|
-
RequestContext
|
|
13
|
-
} from "../chunk-fa40971555060604.js";
|
|
14
|
-
import"../chunk-970e033f764e29fc.js";
|
|
15
|
-
|
|
16
|
-
// client/helpers/flattenComponentTree.ts
|
|
17
|
-
function flattenComponentTree(componentTree) {
|
|
18
|
-
let out = [];
|
|
19
|
-
for (const [root, branches] of componentTree) {
|
|
20
|
-
out.push(root, ...flattenComponentTree(branches).flat());
|
|
21
|
-
}
|
|
22
|
-
return Array.from(new Set(out));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// app/createComponentTree.ts
|
|
26
|
-
function createComponentTree(routes) {
|
|
27
|
-
const componentTree = [];
|
|
28
|
-
for (const [_, routeHandler] of Object.entries(routes)) {
|
|
29
|
-
if ("prepare" in routeHandler) {
|
|
30
|
-
const { viewPath, children } = routeHandler.prepare();
|
|
31
|
-
if (Object.entries(children).length > 0) {
|
|
32
|
-
const branch = createComponentTree(children);
|
|
33
|
-
componentTree.push([viewPath, branch]);
|
|
34
|
-
} else {
|
|
35
|
-
componentTree.push([viewPath, []]);
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
const router = new routeHandler;
|
|
39
|
-
const branch = createComponentTree(router.routes);
|
|
40
|
-
componentTree.push(...branch);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return componentTree;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// app/createFlatViewRoutes.ts
|
|
47
|
-
function createFlatViewRoutes(routes) {
|
|
48
|
-
const flatRoutes = {};
|
|
49
|
-
for (const [routePath, viewConfigOrViewRouter] of Object.entries(routes)) {
|
|
50
|
-
if ("prepare" in viewConfigOrViewRouter) {
|
|
51
|
-
const route = viewConfigOrViewRouter.prepare();
|
|
52
|
-
if (Object.entries(route.children).length > 0) {
|
|
53
|
-
const result = createFlatViewRoutes(route.children);
|
|
54
|
-
if (route.kind === "view") {
|
|
55
|
-
flatRoutes[routePath] = {
|
|
56
|
-
exec: [route.exec],
|
|
57
|
-
middleware: route.middlewares
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
for (const [path, { exec, middleware }] of Object.entries(result)) {
|
|
61
|
-
const key = routePath === "/" ? path : `${routePath}${path}`;
|
|
62
|
-
const _key = path === "/" && routePath !== "/" ? routePath : key;
|
|
63
|
-
flatRoutes[_key] = {
|
|
64
|
-
exec,
|
|
65
|
-
middleware: [...route.middlewares, ...middleware]
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
flatRoutes[routePath] = {
|
|
70
|
-
exec: [route.exec],
|
|
71
|
-
middleware: route.middlewares
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
const router = new viewConfigOrViewRouter;
|
|
76
|
-
const result = createFlatViewRoutes(router.routes);
|
|
77
|
-
for (const [path, { exec, middleware }] of Object.entries(result)) {
|
|
78
|
-
const key = routePath === "/" ? path : `${routePath}${path}`;
|
|
79
|
-
const _key = path === "/" && routePath !== "/" ? routePath : key;
|
|
80
|
-
flatRoutes[_key] = {
|
|
81
|
-
exec,
|
|
82
|
-
middleware: [...router.middlewares, ...middleware]
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return flatRoutes;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// app/createRouteManifest.ts
|
|
91
|
-
function createRouteManifest(routes) {
|
|
92
|
-
const routeManifest = {};
|
|
93
|
-
for (const [routePath, routeHandler] of Object.entries(routes)) {
|
|
94
|
-
if ("prepare" in routeHandler) {
|
|
95
|
-
const { viewPath, children, kind } = routeHandler.prepare();
|
|
96
|
-
if (kind === "view") {
|
|
97
|
-
routeManifest[routePath] = [viewPath];
|
|
98
|
-
}
|
|
99
|
-
if (Object.entries(children).length > 0) {
|
|
100
|
-
const manifest = createRouteManifest(children);
|
|
101
|
-
for (const [path, viewPaths] of Object.entries(manifest)) {
|
|
102
|
-
const key = routePath === "/" ? path : `${routePath}${path}`;
|
|
103
|
-
const _key = path === "/" && routePath !== "/" ? routePath : key;
|
|
104
|
-
routeManifest[_key] = [viewPath, ...viewPaths];
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
routeManifest[routePath] = [viewPath];
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
const router = new routeHandler;
|
|
111
|
-
const manifest = createRouteManifest(router.routes);
|
|
112
|
-
for (const [path, viewPaths] of Object.entries(manifest)) {
|
|
113
|
-
const key = routePath === "/" ? path : `${routePath}${path}`;
|
|
114
|
-
const _key = path === "/" && routePath !== "/" ? routePath : key;
|
|
115
|
-
routeManifest[_key] = viewPaths;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return routeManifest;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// app/createFlatApiRoutes.ts
|
|
123
|
-
var isRouter = function(routeHandlers) {
|
|
124
|
-
return isConstructor(routeHandlers);
|
|
125
|
-
};
|
|
126
|
-
function createFlatApiRoutes(routes) {
|
|
127
|
-
const flatApiRoutes = {};
|
|
128
|
-
for (const [rootPath, apiRouteHandlerOrApiRouter] of Object.entries(routes)) {
|
|
129
|
-
if ("run" in apiRouteHandlerOrApiRouter) {
|
|
130
|
-
const routeHandler = apiRouteHandlerOrApiRouter;
|
|
131
|
-
if (!flatApiRoutes[rootPath]) {
|
|
132
|
-
flatApiRoutes[rootPath] = {};
|
|
133
|
-
}
|
|
134
|
-
const method = routeHandler.method;
|
|
135
|
-
const middleware = routeHandler.middlewares;
|
|
136
|
-
const exec = routeHandler.run.bind(routeHandler);
|
|
137
|
-
flatApiRoutes[rootPath][method] = {
|
|
138
|
-
exec,
|
|
139
|
-
middleware: [...middleware]
|
|
140
|
-
};
|
|
141
|
-
} else if (isRouter(apiRouteHandlerOrApiRouter)) {
|
|
142
|
-
const router = new apiRouteHandlerOrApiRouter;
|
|
143
|
-
const result = createFlatApiRoutes(router.routes);
|
|
144
|
-
for (const [path, handlers] of Object.entries(result)) {
|
|
145
|
-
const subPath = path === "/" ? "" : path;
|
|
146
|
-
const _rootPath = rootPath === "/" ? "" : rootPath;
|
|
147
|
-
const finalPath = `${_rootPath}${subPath}` === "" ? "/" : `${_rootPath}${subPath}`;
|
|
148
|
-
if (!flatApiRoutes[finalPath]) {
|
|
149
|
-
flatApiRoutes[finalPath] = {};
|
|
150
|
-
}
|
|
151
|
-
for (const [method, handler] of Object.entries(handlers)) {
|
|
152
|
-
flatApiRoutes[finalPath][method] = {
|
|
153
|
-
exec: handler.exec,
|
|
154
|
-
middleware: [
|
|
155
|
-
router.middleware,
|
|
156
|
-
...router.middlewares,
|
|
157
|
-
...handler.middleware
|
|
158
|
-
]
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
for (const routeHandler of Object.values(apiRouteHandlerOrApiRouter)) {
|
|
164
|
-
if (!flatApiRoutes[rootPath]) {
|
|
165
|
-
flatApiRoutes[rootPath] = {};
|
|
166
|
-
}
|
|
167
|
-
const method = routeHandler.method;
|
|
168
|
-
const middleware = routeHandler.middlewares;
|
|
169
|
-
const exec = routeHandler.run.bind(routeHandler);
|
|
170
|
-
flatApiRoutes[rootPath][method] = {
|
|
171
|
-
exec,
|
|
172
|
-
middleware
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return flatApiRoutes;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// app/App.ts
|
|
181
|
-
import {renderToReadableStream} from "react-dom/server.browser";
|
|
182
|
-
import {createElement, Fragment} from "react";
|
|
183
|
-
class App {
|
|
184
|
-
renderParams = {
|
|
185
|
-
styles: [],
|
|
186
|
-
manifest: {},
|
|
187
|
-
serverManifest: {},
|
|
188
|
-
bootstrapModules: []
|
|
189
|
-
};
|
|
190
|
-
flatViewRoutes = {};
|
|
191
|
-
flatApiRoutes = {};
|
|
192
|
-
routeManifest = {};
|
|
193
|
-
name = "APP";
|
|
194
|
-
appId;
|
|
195
|
-
componentTree;
|
|
196
|
-
middlewareAliases = {};
|
|
197
|
-
devVersion = 0;
|
|
198
|
-
params;
|
|
199
|
-
apiRouter;
|
|
200
|
-
viewRouter;
|
|
201
|
-
Root;
|
|
202
|
-
kernel;
|
|
203
|
-
constructor(params) {
|
|
204
|
-
this.params = params;
|
|
205
|
-
this.apiRouter = params.apiRouter;
|
|
206
|
-
this.viewRouter = params.viewRouter;
|
|
207
|
-
this.Root = params.root;
|
|
208
|
-
this.kernel = new params.kernel;
|
|
209
|
-
this.prepare();
|
|
210
|
-
this.appId = generateETag(Date.now());
|
|
211
|
-
}
|
|
212
|
-
prepare() {
|
|
213
|
-
const params = this.params;
|
|
214
|
-
this.middlewareAliases = params.middlewareAliases ?? {};
|
|
215
|
-
const kernelServices = this.kernel.getServices.call(this.kernel);
|
|
216
|
-
const authBasePath = kernelServices.authenticationServiceProvider.basePath;
|
|
217
|
-
let viewRouters = {
|
|
218
|
-
"/": this.viewRouter,
|
|
219
|
-
[authBasePath]: kernelServices.authenticationServiceProvider.routers.view
|
|
220
|
-
};
|
|
221
|
-
let apiRouters = {
|
|
222
|
-
"/": this.apiRouter,
|
|
223
|
-
[authBasePath]: kernelServices.authenticationServiceProvider.routers.api
|
|
224
|
-
};
|
|
225
|
-
for (const Plugin of params.plugins ?? []) {
|
|
226
|
-
const plugin = new Plugin;
|
|
227
|
-
if (plugin.viewRouter) {
|
|
228
|
-
viewRouters = {
|
|
229
|
-
...viewRouters,
|
|
230
|
-
[plugin.viewRoutesBasePath]: plugin.viewRouter
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
if (plugin.apiRouter) {
|
|
234
|
-
apiRouters = {
|
|
235
|
-
...apiRouters,
|
|
236
|
-
[plugin.apiRoutesBasePath]: plugin.apiRouter
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
this.flatViewRoutes = createFlatViewRoutes(viewRouters);
|
|
241
|
-
this.componentTree = createComponentTree(viewRouters);
|
|
242
|
-
this.routeManifest = createRouteManifest(viewRouters);
|
|
243
|
-
this.flatApiRoutes = createFlatApiRoutes(apiRouters);
|
|
244
|
-
}
|
|
245
|
-
getComponentTree() {
|
|
246
|
-
return this.componentTree;
|
|
247
|
-
}
|
|
248
|
-
setRenderParams(params) {
|
|
249
|
-
this.renderParams = params;
|
|
250
|
-
}
|
|
251
|
-
runMiddleware(middleware) {
|
|
252
|
-
return middleware.map((aliasOrTest) => {
|
|
253
|
-
if (typeof aliasOrTest === "string") {
|
|
254
|
-
const alias = aliasOrTest;
|
|
255
|
-
const kernelServices = this.kernel.getServices.call(this.kernel);
|
|
256
|
-
const Middleware = kernelServices.middlewareServiceProvider.aliases[alias];
|
|
257
|
-
if (Middleware) {
|
|
258
|
-
const middleware2 = new Middleware;
|
|
259
|
-
return middleware2.run;
|
|
260
|
-
}
|
|
261
|
-
} else {
|
|
262
|
-
if (isConstructor(aliasOrTest)) {
|
|
263
|
-
const middleware2 = new aliasOrTest;
|
|
264
|
-
return middleware2.run;
|
|
265
|
-
}
|
|
266
|
-
return aliasOrTest;
|
|
267
|
-
}
|
|
268
|
-
}).filter(Boolean).reduce((acc, middleware2) => {
|
|
269
|
-
return async (req, ctx) => {
|
|
270
|
-
return {
|
|
271
|
-
...await acc(req, ctx),
|
|
272
|
-
...await middleware2(req, ctx)
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
}, (_req) => Promise.resolve({}));
|
|
276
|
-
}
|
|
277
|
-
async handleApiRequest(req) {
|
|
278
|
-
const url = new URL(req.url);
|
|
279
|
-
const apiPath = url.pathname.replace("/api", "");
|
|
280
|
-
for (const [path, handler] of Object.entries(this.flatApiRoutes)) {
|
|
281
|
-
const pattern = new me({ pathname: path });
|
|
282
|
-
if (pattern.test({ pathname: apiPath })) {
|
|
283
|
-
const params = pattern.exec({ pathname: apiPath })?.pathname.groups;
|
|
284
|
-
if (!handler[req.method]) {
|
|
285
|
-
return new Response(JSON.stringify({ error: { message: "Not found" } }));
|
|
286
|
-
}
|
|
287
|
-
const exec = handler[req.method].exec;
|
|
288
|
-
const middlewares = handler[req.method].middleware;
|
|
289
|
-
const reqWithMiddlewares = this.runMiddleware(middlewares);
|
|
290
|
-
return await RequestContext.run(async () => {
|
|
291
|
-
const httpRequest = new HttpRequest(req, params);
|
|
292
|
-
const ctx = RequestContext.getStore();
|
|
293
|
-
ctx.setRequest(httpRequest);
|
|
294
|
-
let handler2 = exec ? () => exec(httpRequest, params) : () => Promise.resolve({});
|
|
295
|
-
try {
|
|
296
|
-
await reqWithMiddlewares(httpRequest);
|
|
297
|
-
} catch (err) {
|
|
298
|
-
if (err.kind === GEMI_REQUEST_BREAKER_ERROR) {
|
|
299
|
-
const { status = 400, data: data2, headers: headers2 } = err.payload.api;
|
|
300
|
-
return new Response(JSON.stringify(data2), {
|
|
301
|
-
status,
|
|
302
|
-
headers: {
|
|
303
|
-
"Content-Type": "application/json",
|
|
304
|
-
...headers2
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
} else {
|
|
308
|
-
console.error(err);
|
|
309
|
-
throw err;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
let data = {};
|
|
313
|
-
try {
|
|
314
|
-
data = await handler2();
|
|
315
|
-
} catch (err) {
|
|
316
|
-
if (err.kind === GEMI_REQUEST_BREAKER_ERROR) {
|
|
317
|
-
const { status = 400, data: data2, headers: headers2 } = err.payload.api;
|
|
318
|
-
return new Response(JSON.stringify(data2), {
|
|
319
|
-
status,
|
|
320
|
-
headers: {
|
|
321
|
-
"Content-Type": "application/json",
|
|
322
|
-
...headers2
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
} else {
|
|
326
|
-
console.error(err);
|
|
327
|
-
throw err;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
const headers = new Headers;
|
|
331
|
-
headers.append("Content-Type", "application/json");
|
|
332
|
-
ctx.cookies.forEach((cookie) => headers.append("Set-Cookie", cookie.toString()));
|
|
333
|
-
return new Response(JSON.stringify(data), {
|
|
334
|
-
headers
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return new Response(JSON.stringify({ error: { message: "Not found" } }), {
|
|
340
|
-
status: 404
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
async handleViewRequest(req) {
|
|
344
|
-
const url = new URL(req.url);
|
|
345
|
-
let pageData = null;
|
|
346
|
-
try {
|
|
347
|
-
let handlers = [];
|
|
348
|
-
let middlewares = [];
|
|
349
|
-
let currentPathName2 = null;
|
|
350
|
-
let params2 = {};
|
|
351
|
-
const sortedEntries = Object.entries(this.flatViewRoutes).sort(([pathA], [pathB]) => pathB.length - pathA.length);
|
|
352
|
-
for (const [pathname, handler] of sortedEntries) {
|
|
353
|
-
const pattern = new me({ pathname });
|
|
354
|
-
if (pattern.test({ pathname: url.pathname })) {
|
|
355
|
-
currentPathName2 = pathname;
|
|
356
|
-
params2 = pattern.exec({ pathname: url.pathname })?.pathname.groups;
|
|
357
|
-
handlers = handler.exec;
|
|
358
|
-
middlewares = handler.middleware;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
const reqWithMiddlewares = this.runMiddleware(middlewares);
|
|
362
|
-
const { data: data2, cookies: cookies2, user: user2 } = await RequestContext.run(async () => {
|
|
363
|
-
const httpRequest = new HttpRequest(req, params2);
|
|
364
|
-
const ctx = RequestContext.getStore();
|
|
365
|
-
ctx.setRequest(httpRequest);
|
|
366
|
-
await reqWithMiddlewares(httpRequest);
|
|
367
|
-
const data3 = await Promise.all(handlers.map((fn) => fn(httpRequest)));
|
|
368
|
-
return {
|
|
369
|
-
data: data3,
|
|
370
|
-
cookies: ctx.cookies,
|
|
371
|
-
user: ctx.user
|
|
372
|
-
};
|
|
373
|
-
});
|
|
374
|
-
pageData = {
|
|
375
|
-
data: data2,
|
|
376
|
-
currentPathName: currentPathName2,
|
|
377
|
-
user: user2,
|
|
378
|
-
params: params2,
|
|
379
|
-
cookies: cookies2
|
|
380
|
-
};
|
|
381
|
-
} catch (err) {
|
|
382
|
-
if (err.kind === GEMI_REQUEST_BREAKER_ERROR) {
|
|
383
|
-
return new Response(null, {
|
|
384
|
-
...err.payload.view
|
|
385
|
-
});
|
|
386
|
-
} else {
|
|
387
|
-
throw err;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
const { data, params, currentPathName, user, cookies } = pageData;
|
|
391
|
-
const viewData = data.reduce((acc, data2) => {
|
|
392
|
-
return {
|
|
393
|
-
...acc,
|
|
394
|
-
...data2
|
|
395
|
-
};
|
|
396
|
-
}, {});
|
|
397
|
-
if (url.searchParams.get("json")) {
|
|
398
|
-
const headers2 = new Headers;
|
|
399
|
-
headers2.set("Content-Type", "application/json");
|
|
400
|
-
cookies.forEach((cookie) => headers2.append("Set-Cookie", cookie.toString()));
|
|
401
|
-
return new Response(JSON.stringify({
|
|
402
|
-
data: {
|
|
403
|
-
[url.pathname]: viewData
|
|
404
|
-
},
|
|
405
|
-
is404: !currentPathName
|
|
406
|
-
}), {
|
|
407
|
-
headers: headers2
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
const { styles, manifest, serverManifest, bootstrapModules } = this.renderParams;
|
|
411
|
-
const viewImportMap = {};
|
|
412
|
-
let appDir = null;
|
|
413
|
-
const template = (viewName, path) => `"${viewName}": () => import("${path}")`;
|
|
414
|
-
const templates = [];
|
|
415
|
-
for (const fileName of [
|
|
416
|
-
"404",
|
|
417
|
-
...flattenComponentTree(this.componentTree)
|
|
418
|
-
]) {
|
|
419
|
-
if (false) {
|
|
420
|
-
}
|
|
421
|
-
if (!manifest) {
|
|
422
|
-
appDir = `${process.env.APP_DIR}`;
|
|
423
|
-
const mod = await import(`${appDir}/views/${fileName}.tsx`);
|
|
424
|
-
viewImportMap[fileName] = mod.default;
|
|
425
|
-
templates.push(template(fileName, `${appDir}/views/${fileName}.tsx`));
|
|
426
|
-
} else {
|
|
427
|
-
const serverFile = serverManifest[`app/views/${fileName}.tsx`];
|
|
428
|
-
const mod = await import(`${process.env.DIST_DIR}/server/${serverFile?.file}`);
|
|
429
|
-
viewImportMap[fileName] = mod.default;
|
|
430
|
-
const clientFile = manifest[`app/views/${fileName}.tsx`];
|
|
431
|
-
if (clientFile) {
|
|
432
|
-
templates.push(template(fileName, `/${clientFile?.file}`));
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
const loaders = `{${templates.join(",")}}`;
|
|
437
|
-
const headers = new Headers;
|
|
438
|
-
headers.set("Content-Type", "text/html");
|
|
439
|
-
headers.set("Cache-Control", user ? "private, no-cache, no-store, max-age=0, must-revalidate" : "public, max-age=864000, must-revalidate");
|
|
440
|
-
headers.set("ETag", this.appId);
|
|
441
|
-
pageData.cookies.forEach((cookie) => headers.append("Set-Cookie", cookie.toString()));
|
|
442
|
-
const result = {
|
|
443
|
-
kind: "view",
|
|
444
|
-
data: {
|
|
445
|
-
pageData: {
|
|
446
|
-
[url.pathname]: viewData
|
|
447
|
-
},
|
|
448
|
-
auth: { user },
|
|
449
|
-
routeManifest: this.routeManifest,
|
|
450
|
-
router: {
|
|
451
|
-
pathname: currentPathName,
|
|
452
|
-
params,
|
|
453
|
-
currentPath: url.pathname,
|
|
454
|
-
searchParams: url.search,
|
|
455
|
-
is404: !currentPathName ? true : false
|
|
456
|
-
},
|
|
457
|
-
componentTree: [["404", []], ...this.componentTree]
|
|
458
|
-
},
|
|
459
|
-
head: {}
|
|
460
|
-
};
|
|
461
|
-
const stream = await renderToReadableStream(createElement(Fragment, {
|
|
462
|
-
children: [
|
|
463
|
-
styles,
|
|
464
|
-
createElement(this.Root, {
|
|
465
|
-
data: result.data,
|
|
466
|
-
viewImportMap
|
|
467
|
-
})
|
|
468
|
-
]
|
|
469
|
-
}), {
|
|
470
|
-
bootstrapScriptContent: `window.__GEMI_DATA__ = ${JSON.stringify(result.data)}; window.loaders=${loaders}`,
|
|
471
|
-
bootstrapModules
|
|
472
|
-
});
|
|
473
|
-
return new Response(stream, {
|
|
474
|
-
status: !currentPathName ? 404 : 200,
|
|
475
|
-
headers
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
async fetch(req) {
|
|
479
|
-
const url = new URL(req.url);
|
|
480
|
-
const kernelRun = this.kernel.run.bind(this.kernel);
|
|
481
|
-
return kernelRun(async () => {
|
|
482
|
-
if (url.pathname.startsWith("/api")) {
|
|
483
|
-
return await this.handleApiRequest(req);
|
|
484
|
-
} else {
|
|
485
|
-
return await this.handleViewRequest(req);
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
handleWebSocketMessage = (ws, message) => {
|
|
490
|
-
};
|
|
491
|
-
handleWebSocketOpen = (ws) => {
|
|
492
|
-
console.log("socket opened");
|
|
493
|
-
};
|
|
494
|
-
handleWebSocketClose = (ws, code, reason) => {
|
|
495
|
-
console.log("socket closed");
|
|
496
|
-
};
|
|
497
|
-
websocket = {
|
|
498
|
-
message: this.handleWebSocketMessage,
|
|
499
|
-
open: this.handleWebSocketOpen,
|
|
500
|
-
close: this.handleWebSocketClose
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
export {
|
|
504
|
-
App
|
|
505
|
-
};
|
|
2
|
+
import{b as K,e as s} from"../http/index.js";import{j as F,k as B} from"../chunk-0e3473f7e43f4876.js";import{l as P,n as Z} from"../chunk-847629c9a7550cc3.js";import"../chunk-0d0f764773c0f6b8.js";function _(f){let o=[];for(let[c,d]of f)o.push(c,..._(d).flat());return Array.from(new Set(o))}function L(f){const o=[];for(let[c,d]of Object.entries(f))if("prepare"in d){const{viewPath:n,children:w}=d.prepare();if(Object.entries(w).length>0){const i=L(w);o.push([n,i])}else o.push([n,[]])}else{const n=new d,w=L(n.routes);o.push(...w)}return o}function W(f){const o={};for(let[c,d]of Object.entries(f))if("prepare"in d){const n=d.prepare();if(Object.entries(n.children).length>0){const w=W(n.children);if(n.kind==="view")o[c]={exec:[n.exec],middleware:n.middlewares};for(let[i,{exec:b,middleware:j}]of Object.entries(w)){const $=c==="/"?i:`${c}${i}`,y=i==="/"&&c!=="/"?c:$;o[y]={exec:b,middleware:[...n.middlewares,...j]}}}else o[c]={exec:[n.exec],middleware:n.middlewares}}else{const n=new d,w=W(n.routes);for(let[i,{exec:b,middleware:j}]of Object.entries(w)){const $=c==="/"?i:`${c}${i}`,y=i==="/"&&c!=="/"?c:$;o[y]={exec:b,middleware:[...n.middlewares,...j]}}}return o}function G(f){const o={};for(let[c,d]of Object.entries(f))if("prepare"in d){const{viewPath:n,children:w,kind:i}=d.prepare();if(i==="view")o[c]=[n];if(Object.entries(w).length>0){const b=G(w);for(let[j,$]of Object.entries(b)){const y=c==="/"?j:`${c}${j}`,H=j==="/"&&c!=="/"?c:y;o[H]=[n,...$]}}else o[c]=[n]}else{const n=new d,w=G(n.routes);for(let[i,b]of Object.entries(w)){const j=c==="/"?i:`${c}${i}`,$=i==="/"&&c!=="/"?c:j;o[$]=b}}return o}var l=function(f){return K(f)};function U(f){const o={};for(let[c,d]of Object.entries(f))if("run"in d){const n=d;if(!o[c])o[c]={};const{method:w,middlewares:i}=n,b=n.run.bind(n);o[c][w]={exec:b,middleware:[...i]}}else if(l(d)){const n=new d,w=U(n.routes);for(let[i,b]of Object.entries(w)){const j=i==="/"?"":i,$=c==="/"?"":c,y=`${$}${j}`===""?"/":`${$}${j}`;if(!o[y])o[y]={};for(let[H,z]of Object.entries(b))o[y][H]={exec:z.exec,middleware:[n.middleware,...n.middlewares,...z.middleware]}}}else for(let n of Object.values(d)){if(!o[c])o[c]={};const{method:w,middlewares:i}=n,b=n.run.bind(n);o[c][w]={exec:b,middleware:i}}return o}import{renderToReadableStream as N} from"react-dom/server.browser";import{createElement as S,Fragment as E} from"react";class D{renderParams={styles:[],manifest:{},serverManifest:{},bootstrapModules:[]};flatViewRoutes={};flatApiRoutes={};routeManifest={};name="APP";appId;componentTree;middlewareAliases={};devVersion=0;params;apiRouter;viewRouter;Root;kernel;constructor(f){this.params=f,this.apiRouter=f.apiRouter,this.viewRouter=f.viewRouter,this.Root=f.root,this.kernel=new f.kernel,this.prepare(),this.appId=B(Date.now())}prepare(){const f=this.params;this.middlewareAliases=f.middlewareAliases??{};const o=this.kernel.getServices.call(this.kernel),c=o.authenticationServiceProvider.basePath;let d={"/":this.viewRouter,[c]:o.authenticationServiceProvider.routers.view},n={"/":this.apiRouter,[c]:o.authenticationServiceProvider.routers.api};for(let w of f.plugins??[]){const i=new w;if(i.viewRouter)d={...d,[i.viewRoutesBasePath]:i.viewRouter};if(i.apiRouter)n={...n,[i.apiRoutesBasePath]:i.apiRouter}}this.flatViewRoutes=W(d),this.componentTree=L(d),this.routeManifest=G(d),this.flatApiRoutes=U(n)}getComponentTree(){return this.componentTree}setRenderParams(f){this.renderParams=f}runMiddleware(f){return f.map((o)=>{if(typeof o==="string"){const c=o,n=this.kernel.getServices.call(this.kernel).middlewareServiceProvider.aliases[c];if(n)return new n().run}else{if(K(o))return new o().run;return o}}).filter(Boolean).reduce((o,c)=>{return async(d,n)=>{return{...await o(d,n),...await c(d,n)}}},(o)=>Promise.resolve({}))}async handleApiRequest(f){const c=new URL(f.url).pathname.replace("/api","");for(let[d,n]of Object.entries(this.flatApiRoutes)){const w=new F({pathname:d});if(w.test({pathname:c})){const i=w.exec({pathname:c})?.pathname.groups;if(!n[f.method])return new Response(JSON.stringify({error:{message:"Not found"}}));const b=n[f.method].exec,j=n[f.method].middleware,$=this.runMiddleware(j);return await Z.run(async()=>{const y=new s(f,i),H=Z.getStore();H.setRequest(y);let z=b?()=>b(y,i):()=>Promise.resolve({});try{await $(y)}catch(V){if(V.kind===P){const{status:g=400,data:Y,headers:u}=V.payload.api;return new Response(JSON.stringify(Y),{status:g,headers:{"Content-Type":"application/json",...u}})}else throw console.error(V),V}let J={};try{J=await z()}catch(V){if(V.kind===P){const{status:g=400,data:Y,headers:u}=V.payload.api;return new Response(JSON.stringify(Y),{status:g,headers:{"Content-Type":"application/json",...u}})}else throw console.error(V),V}const O=new Headers;return O.append("Content-Type","application/json"),H.cookies.forEach((V)=>O.append("Set-Cookie",V.toString())),new Response(JSON.stringify(J),{headers:O})})}}return new Response(JSON.stringify({error:{message:"Not found"}}),{status:404})}async handleViewRequest(f){const o=new URL(f.url);let c=null;try{let t=[],x=[],k=null,X={};const e=Object.entries(this.flatViewRoutes).sort(([A],[C])=>C.length-A.length);for(let[A,C]of e){const Q=new F({pathname:A});if(Q.test({pathname:o.pathname}))k=A,X=Q.exec({pathname:o.pathname})?.pathname.groups,t=C.exec,x=C.middleware}const h=this.runMiddleware(x),{data:r,cookies:v,user:m}=await Z.run(async()=>{const A=new s(f,X),C=Z.getStore();return C.setRequest(A),await h(A),{data:await Promise.all(t.map((T)=>T(A))),cookies:C.cookies,user:C.user}});c={data:r,currentPathName:k,user:m,params:X,cookies:v}}catch(t){if(t.kind===P)return new Response(null,{...t.payload.view});else throw t}const{data:d,params:n,currentPathName:w,user:i,cookies:b}=c,j=d.reduce((t,x)=>{return{...t,...x}},{});if(o.searchParams.get("json")){const t=new Headers;return t.set("Content-Type","application/json"),b.forEach((x)=>t.append("Set-Cookie",x.toString())),new Response(JSON.stringify({data:{[o.pathname]:j},is404:!w}),{headers:t})}const{styles:$,manifest:y,serverManifest:H,bootstrapModules:z}=this.renderParams,J={};let O=null;const V=(t,x)=>`"${t}": () => import("${x}")`,g=[];for(let t of["404",..._(this.componentTree)])if(!y){O=`${process.env.APP_DIR}`;const x=await import(`${O}/views/${t}.tsx`);J[t]=x.default,g.push(V(t,`${O}/views/${t}.tsx`))}else{const x=H[`app/views/${t}.tsx`],k=await import(`${process.env.DIST_DIR}/server/${x?.file}`);J[t]=k.default;const X=y[`app/views/${t}.tsx`];if(X)g.push(V(t,`/${X?.file}`))}const Y=`{${g.join(",")}}`,u=new Headers;u.set("Content-Type","text/html"),u.set("Cache-Control",i?"private, no-cache, no-store, max-age=0, must-revalidate":"public, max-age=864000, must-revalidate"),u.set("ETag",this.appId),c.cookies.forEach((t)=>u.append("Set-Cookie",t.toString()));const I={kind:"view",data:{pageData:{[o.pathname]:j},auth:{user:i},routeManifest:this.routeManifest,router:{pathname:w,params:n,currentPath:o.pathname,searchParams:o.search,is404:!w?!0:!1},componentTree:[["404",[]],...this.componentTree]},head:{}},M=await N(S(E,{children:[$,S(this.Root,{data:I.data,viewImportMap:J})]}),{bootstrapScriptContent:`window.__GEMI_DATA__ = ${JSON.stringify(I.data)}; window.loaders=${Y}`,bootstrapModules:z});return new Response(M,{status:!w?404:200,headers:u})}async fetch(f){const o=new URL(f.url);return this.kernel.run.bind(this.kernel)(async()=>{if(o.pathname.startsWith("/api"))return await this.handleApiRequest(f);else return await this.handleViewRequest(f)})}handleWebSocketMessage=(f,o)=>{};handleWebSocketOpen=(f)=>{console.log("socket opened")};handleWebSocketClose=(f,o,c)=>{console.log("socket closed")};websocket={message:this.handleWebSocketMessage,open:this.handleWebSocketOpen,close:this.handleWebSocketClose}}export{D as App};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var g=Object.create;var{defineProperty:f,getPrototypeOf:h,getOwnPropertyNames:i}=Object;var j=Object.prototype.hasOwnProperty;var k=(a,b,c)=>{c=a!=null?g(h(a)):{};const d=b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c;for(let e of i(a))if(!j.call(d,e))f(d,e,{get:()=>a[e],enumerable:!0});return d};var l=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);
|
|
2
|
+
export{k as q,l as r};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var et=function(t,e){return(e?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(t)},F=function(t,e=!1){let s=[],i=0;for(;i<t.length;){let a=t[i],u=function(o){if(!e)throw new TypeError(o);s.push({type:"INVALID_CHAR",index:i,value:t[i++]})};if(a==="*"){s.push({type:"ASTERISK",index:i,value:t[i++]});continue}if(a==="+"||a==="?"){s.push({type:"OTHER_MODIFIER",index:i,value:t[i++]});continue}if(a==="\\"){s.push({type:"ESCAPED_CHAR",index:i++,value:t[i++]});continue}if(a==="{"){s.push({type:"OPEN",index:i,value:t[i++]});continue}if(a==="}"){s.push({type:"CLOSE",index:i,value:t[i++]});continue}if(a===":"){let o="",r=i+1;for(;r<t.length;){let h=t.substr(r,1);if(r===i+1&&Y.test(h)||r!==i+1&&tt.test(h)){o+=t[r++];continue}break}if(!o){u(`Missing parameter name at ${i}`);continue}s.push({type:"NAME",index:i,value:o}),i=r;continue}if(a==="("){let o=1,r="",h=i+1,n=!1;if(t[h]==="?"){u(`Pattern cannot start with "?" at ${h}`);continue}for(;h<t.length;){if(!et(t[h],!1)){u(`Invalid character '${t[h]}' at ${h}.`),n=!0;break}if(t[h]==="\\"){r+=t[h++]+t[h++];continue}if(t[h]===")"){if(o--,o===0){h++;break}}else if(t[h]==="("&&(o++,t[h+1]!=="?")){u(`Capturing groups are not allowed at ${h}`),n=!0;break}r+=t[h++]}if(n)continue;if(o){u(`Unbalanced pattern at ${i}`);continue}if(!r){u(`Missing pattern at ${i}`);continue}s.push({type:"REGEX",index:i,value:r}),i=h;continue}s.push({type:"CHAR",index:i,value:t[i++]})}return s.push({type:"END",index:i,value:""}),s},M=function(t,e={}){let s=F(t);e.delimiter??="/#?",e.prefixes??="./";let i=`[^${d(e.delimiter)}]+?`,a=[],u=0,o=0,r="",h=new Set,n=(p)=>{if(o<s.length&&s[o].type===p)return s[o++].value},f=()=>n("OTHER_MODIFIER")??n("ASTERISK"),w=(p)=>{let c=n(p);if(c!==void 0)return c;let{type:l,index:R}=s[o];throw new TypeError(`Unexpected ${l} at ${R}, expected ${p}`)},E=()=>{let p="",c;for(;c=n("CHAR")??n("ESCAPED_CHAR");)p+=c;return p},Q=(p)=>p,T=e.encodePart||Q,U="",O=(p)=>{U+=p},I=()=>{U.length&&(a.push(new P(3,"","",T(U),"",3)),U="")},_=(p,c,l,R,v)=>{let g=3;switch(v){case"?":g=1;break;case"*":g=0;break;case"+":g=2;break}if(!c&&!l&&g===3){O(p);return}if(I(),!c&&!l){if(!p)return;a.push(new P(3,"","",T(p),"",g));return}let m;l?l==="*"?m=D:m=l:m=i;let C=2;m===i?(C=1,m=""):m===D&&(C=0,m="");let b;if(c?b=c:l&&(b=u++),h.has(b))throw new TypeError(`Duplicate name '${b}'.`);h.add(b),a.push(new P(C,b,T(p),m,T(R),g))};for(;o<s.length;){let p=n("CHAR"),c=n("NAME"),l=n("REGEX");if(!c&&!l&&(l=n("ASTERISK")),c||l){let v=p??"";e.prefixes.indexOf(v)===-1&&(O(v),v=""),I();let g=f();_(v,c,l,"",g);continue}let R=p??n("ESCAPED_CHAR");if(R){O(R);continue}if(n("OPEN")){let v=E(),g=n("NAME"),m=n("REGEX");!g&&!m&&(m=n("ASTERISK"));let C=E();w("CLOSE");let b=f();_(v,g,m,C,b);continue}I(),w("END")}return a},d=function(t){return t.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")},j=function(t){return t&&t.ignoreCase?"ui":"u"},st=function(t,e,s){return W(M(t,s),e,s)},k=function(t){switch(t){case 0:return"*";case 1:return"?";case 2:return"+";case 3:return""}},W=function(t,e,s={}){s.delimiter??="/#?",s.prefixes??="./",s.sensitive??=!1,s.strict??=!1,s.end??=!0,s.start??=!0,s.endsWith="";let i=s.start?"^":"";for(let r of t){if(r.type===3){r.modifier===3?i+=d(r.value):i+=`(?:${d(r.value)})${k(r.modifier)}`;continue}e&&e.push(r.name);let h=`[^${d(s.delimiter)}]+?`,n=r.value;if(r.type===1?n=h:r.type===0&&(n=D),!r.prefix.length&&!r.suffix.length){r.modifier===3||r.modifier===1?i+=`(${n})${k(r.modifier)}`:i+=`((?:${n})${k(r.modifier)})`;continue}if(r.modifier===3||r.modifier===1){i+=`(?:${d(r.prefix)}(${n})${d(r.suffix)})`,i+=k(r.modifier);continue}i+=`(?:${d(r.prefix)}`,i+=`((?:${n})(?:`,i+=d(r.suffix),i+=d(r.prefix),i+=`(?:${n}))*)${d(r.suffix)})`,r.modifier===0&&(i+="?")}let a=`[${d(s.endsWith)}]|\$`,u=`[${d(s.delimiter)}]`;if(s.end)return s.strict||(i+=`${u}?`),s.endsWith.length?i+=`(?=${a})`:i+="$",new RegExp(i,j(s));s.strict||(i+=`(?:${u}(?=${a}))?`);let o=!1;if(t.length){let r=t[t.length-1];r.type===3&&r.modifier===3&&(o=s.delimiter.indexOf(r)>-1)}return o||(i+=`(?=${u}|${a})`),new RegExp(i,j(s))},nt=function(t,e){return t.length?t[0]==="/"?!0:!e||t.length<2?!1:(t[0]=="\\"||t[0]=="{")&&t[1]=="/":!1},G=function(t,e){return t.startsWith(e)?t.substring(e.length,t.length):t},ot=function(t,e){return t.endsWith(e)?t.substr(0,t.length-e.length):t},K=function(t){return!t||t.length<2?!1:t[0]==="["||(t[0]==="\\"||t[0]==="{")&&t[1]==="["},V=function(t){if(!t)return!0;for(let e of X)if(t.test(e))return!0;return!1},ht=function(t,e){if(t=G(t,"#"),e||t==="")return t;let s=new URL("https://example.com");return s.hash=t,s.hash?s.hash.substring(1,s.hash.length):""},at=function(t,e){if(t=G(t,"?"),e||t==="")return t;let s=new URL("https://example.com");return s.search=t,s.search?s.search.substring(1,s.search.length):""},ut=function(t,e){return e||t===""?t:K(t)?q(t):Z(t)},pt=function(t,e){if(e||t==="")return t;let s=new URL("https://example.com");return s.password=t,s.password},ct=function(t,e){if(e||t==="")return t;let s=new URL("https://example.com");return s.username=t,s.username},ft=function(t,e,s){if(s||t==="")return t;if(e&&!X.includes(e))return new URL(`${e}:${t}`).pathname;let i=t[0]=="/";return t=new URL(i?t:"/-"+t,"https://example.com").pathname,i||(t=t.substring(2,t.length)),t},lt=function(t,e,s){return z(e)===t&&(t=""),s||t===""?t:B(t)},mt=function(t,e){return t=ot(t,":"),e||t===""?t:N(t)},z=function(t){switch(t){case"ws":case"http":return"80";case"wws":case"https":return"443";case"ftp":return"21";default:return""}},N=function(t){if(t==="")return t;if(/^[-+.A-Za-z0-9]*$/.test(t))return t.toLowerCase();throw new TypeError(`Invalid protocol '${t}'.`)},dt=function(t){if(t==="")return t;let e=new URL("https://example.com");return e.username=t,e.username},gt=function(t){if(t==="")return t;let e=new URL("https://example.com");return e.password=t,e.password},Z=function(t){if(t==="")return t;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(t))throw new TypeError(`Invalid hostname '${t}'`);let e=new URL("https://example.com");return e.hostname=t,e.hostname},q=function(t){if(t==="")return t;if(/[^0-9a-fA-F[\]:]/g.test(t))throw new TypeError(`Invalid IPv6 hostname '${t}'`);return t.toLowerCase()},B=function(t){if(t===""||/^[0-9]*$/.test(t)&&parseInt(t)<=65535)return t;throw new TypeError(`Invalid port '${t}'.`)},wt=function(t){if(t==="")return t;let e=new URL("https://example.com");return e.pathname=t[0]!=="/"?"/-"+t:t,t[0]!=="/"?e.pathname.substring(2,e.pathname.length):e.pathname},yt=function(t){return t===""?t:new URL(`data:${t}`).pathname},vt=function(t){if(t==="")return t;let e=new URL("https://example.com");return e.search=t,e.search.substring(1,e.search.length)},bt=function(t){if(t==="")return t;let e=new URL("https://example.com");return e.hash=t,e.hash.substring(1,e.hash.length)},H=function(t,e){if(typeof t!="string")throw new TypeError("parameter 1 is not of type 'string'.");let s=new URL(t,e);return{protocol:s.protocol.substring(0,s.protocol.length-1),username:s.username,password:s.password,hostname:s.hostname,port:s.port,pathname:s.pathname,search:s.search!==""?s.search.substring(1,s.search.length):void 0,hash:s.hash!==""?s.hash.substring(1,s.hash.length):void 0}},y=function(t,e){return e?A(t):t},L=function(t,e,s){let i;if(typeof e.baseURL=="string")try{i=new URL(e.baseURL),e.protocol===void 0&&(t.protocol=y(i.protocol.substring(0,i.protocol.length-1),s)),!s&&e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.username===void 0&&(t.username=y(i.username,s)),!s&&e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.username===void 0&&e.password===void 0&&(t.password=y(i.password,s)),e.protocol===void 0&&e.hostname===void 0&&(t.hostname=y(i.hostname,s)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&(t.port=y(i.port,s)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.pathname===void 0&&(t.pathname=y(i.pathname,s)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.pathname===void 0&&e.search===void 0&&(t.search=y(i.search.substring(1,i.search.length),s)),e.protocol===void 0&&e.hostname===void 0&&e.port===void 0&&e.pathname===void 0&&e.search===void 0&&e.hash===void 0&&(t.hash=y(i.hash.substring(1,i.hash.length),s))}catch{throw new TypeError(`invalid baseURL '${e.baseURL}'.`)}if(typeof e.protocol=="string"&&(t.protocol=mt(e.protocol,s)),typeof e.username=="string"&&(t.username=ct(e.username,s)),typeof e.password=="string"&&(t.password=pt(e.password,s)),typeof e.hostname=="string"&&(t.hostname=ut(e.hostname,s)),typeof e.port=="string"&&(t.port=lt(e.port,t.protocol,s)),typeof e.pathname=="string"){if(t.pathname=e.pathname,i&&!nt(t.pathname,s)){let a=i.pathname.lastIndexOf("/");a>=0&&(t.pathname=y(i.pathname.substring(0,a+1),s)+t.pathname)}t.pathname=ft(t.pathname,t.protocol,s)}return typeof e.search=="string"&&(t.search=at(e.search,s)),typeof e.hash=="string"&&(t.hash=ht(e.hash,s)),t},A=function(t){return t.replace(/([+*?:{}()\\])/g,"\\$1")},$t=function(t){return t.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")},Et=function(t,e){e.delimiter??="/#?",e.prefixes??="./",e.sensitive??=!1,e.strict??=!1,e.end??=!0,e.start??=!0,e.endsWith="";let s=".*",i=`[^${$t(e.delimiter)}]+?`,a=/[$_\u200C\u200D\p{ID_Continue}]/u,u="";for(let o=0;o<t.length;++o){let r=t[o];if(r.type===3){if(r.modifier===3){u+=A(r.value);continue}u+=`{${A(r.value)}}${k(r.modifier)}`;continue}let h=r.hasCustomName(),n=!!r.suffix.length||!!r.prefix.length&&(r.prefix.length!==1||!e.prefixes.includes(r.prefix)),f=o>0?t[o-1]:null,w=o<t.length-1?t[o+1]:null;if(!n&&h&&r.type===1&&r.modifier===3&&w&&!w.prefix.length&&!w.suffix.length)if(w.type===3){let E=w.value.length>0?w.value[0]:"";n=a.test(E)}else n=!w.hasCustomName();if(!n&&!r.prefix.length&&f&&f.type===3){let E=f.value[f.value.length-1];n=e.prefixes.includes(E)}n&&(u+="{"),u+=A(r.prefix),h&&(u+=`:${r.name}`),r.type===2?u+=`(${r.value})`:r.type===1?h||(u+=`(${i})`):r.type===0&&(!h&&(!f||f.type===3||f.modifier!==3||n||r.prefix!=="")?u+="*":u+=`(${s})`),r.type===1&&h&&r.suffix.length&&a.test(r.suffix[0])&&(u+="\\"),u+=A(r.suffix),n&&(u+="}"),r.modifier!==3&&(u+=k(r.modifier))}return u},P=class{type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(t,e,s,i,a,u){this.type=t,this.name=e,this.prefix=s,this.value=i,this.suffix=a,this.modifier=u}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},Y=/[$_\p{ID_Start}]/u,tt=/[$_\u200C\u200D\p{ID_Continue}]/u,D=".*",$={delimiter:"",prefixes:"",sensitive:!0,strict:!0},rt={delimiter:".",prefixes:"",sensitive:!0,strict:!0},it={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0},X=["ftp","file","http","https","ws","wss"],xt=class{#n;#r=[];#e={};#t=0;#i=1;#u=0;#h=0;#l=0;#m=0;#d=!1;constructor(t){this.#n=t}get result(){return this.#e}parse(){for(this.#r=F(this.#n,!0);this.#t<this.#r.length;this.#t+=this.#i){if(this.#i=1,this.#r[this.#t].type==="END"){if(this.#h===0){this.#v(),this.#p()?this.#s(9,1):this.#c()?this.#s(8,1):this.#s(7,0);continue}else if(this.#h===2){this.#f(5);continue}this.#s(10,0);break}if(this.#l>0)if(this.#C())this.#l-=1;else continue;if(this.#k()){this.#l+=1;continue}switch(this.#h){case 0:this.#b()&&this.#f(1);break;case 1:if(this.#b()){this.#P();let t=7,e=1;this.#$()?(t=2,e=3):this.#d&&(t=2),this.#s(t,e)}break;case 2:this.#w()?this.#f(3):(this.#y()||this.#c()||this.#p())&&this.#f(5);break;case 3:this.#E()?this.#s(4,1):this.#w()&&this.#s(5,1);break;case 4:this.#w()&&this.#s(5,1);break;case 5:this.#L()?this.#m+=1:this.#A()&&(this.#m-=1),this.#R()&&!this.#m?this.#s(6,1):this.#y()?this.#s(7,0):this.#c()?this.#s(8,1):this.#p()&&this.#s(9,1);break;case 6:this.#y()?this.#s(7,0):this.#c()?this.#s(8,1):this.#p()&&this.#s(9,1);break;case 7:this.#c()?this.#s(8,1):this.#p()&&this.#s(9,1);break;case 8:this.#p()&&this.#s(9,1);break;case 9:break;case 10:break}}this.#e.hostname!==void 0&&this.#e.port===void 0&&(this.#e.port="")}#s(t,e){switch(this.#h){case 0:break;case 1:this.#e.protocol=this.#a();break;case 2:break;case 3:this.#e.username=this.#a();break;case 4:this.#e.password=this.#a();break;case 5:this.#e.hostname=this.#a();break;case 6:this.#e.port=this.#a();break;case 7:this.#e.pathname=this.#a();break;case 8:this.#e.search=this.#a();break;case 9:this.#e.hash=this.#a();break;case 10:break}this.#h!==0&&t!==10&&([1,2,3,4].includes(this.#h)&&[6,7,8,9].includes(t)&&(this.#e.hostname??=""),[1,2,3,4,5,6].includes(this.#h)&&[8,9].includes(t)&&(this.#e.pathname??=this.#d?"/":""),[1,2,3,4,5,6,7].includes(this.#h)&&t===9&&(this.#e.search??="")),this.#x(t,e)}#x(t,e){this.#h=t,this.#u=this.#t+e,this.#t+=e,this.#i=0}#v(){this.#t=this.#u,this.#i=0}#f(t){this.#v(),this.#h=t}#g(t){return t<0&&(t=this.#r.length-t),t<this.#r.length?this.#r[t]:this.#r[this.#r.length-1]}#o(t,e){let s=this.#g(t);return s.value===e&&(s.type==="CHAR"||s.type==="ESCAPED_CHAR"||s.type==="INVALID_CHAR")}#b(){return this.#o(this.#t,":")}#$(){return this.#o(this.#t+1,"/")&&this.#o(this.#t+2,"/")}#w(){return this.#o(this.#t,"@")}#E(){return this.#o(this.#t,":")}#R(){return this.#o(this.#t,":")}#y(){return this.#o(this.#t,"/")}#c(){if(this.#o(this.#t,"?"))return!0;if(this.#r[this.#t].value!=="?")return!1;let t=this.#g(this.#t-1);return t.type!=="NAME"&&t.type!=="REGEX"&&t.type!=="CLOSE"&&t.type!=="ASTERISK"}#p(){return this.#o(this.#t,"#")}#k(){return this.#r[this.#t].type=="OPEN"}#C(){return this.#r[this.#t].type=="CLOSE"}#L(){return this.#o(this.#t,"[")}#A(){return this.#o(this.#t,"]")}#a(){let t=this.#r[this.#t],e=this.#g(this.#u).index;return this.#n.substring(e,t.index)}#P(){let t={};Object.assign(t,$),t.encodePart=N;let e=st(this.#a(),void 0,t);this.#d=V(e)}},S=["protocol","username","password","hostname","port","pathname","search","hash"],x="*",J=class{#n;#r={};#e={};#t={};#i={};#u=!1;constructor(t={},e,s){try{let i;if(typeof e=="string"?i=e:s=e,typeof t=="string"){let r=new xt(t);if(r.parse(),t=r.result,i===void 0&&typeof t.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");t.baseURL=i}else{if(!t||typeof t!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(i)throw new TypeError("parameter 1 is not of type 'string'.")}typeof s>"u"&&(s={ignoreCase:!1});let a={ignoreCase:s.ignoreCase===!0},u={pathname:x,protocol:x,username:x,password:x,hostname:x,port:x,search:x,hash:x};this.#n=L(u,t,!0),z(this.#n.protocol)===this.#n.port&&(this.#n.port="");let o;for(o of S){if(!(o in this.#n))continue;let r={},h=this.#n[o];switch(this.#e[o]=[],o){case"protocol":Object.assign(r,$),r.encodePart=N;break;case"username":Object.assign(r,$),r.encodePart=dt;break;case"password":Object.assign(r,$),r.encodePart=gt;break;case"hostname":Object.assign(r,rt),K(h)?r.encodePart=q:r.encodePart=Z;break;case"port":Object.assign(r,$),r.encodePart=B;break;case"pathname":V(this.#r.protocol)?(Object.assign(r,it,a),r.encodePart=wt):(Object.assign(r,$,a),r.encodePart=yt);break;case"search":Object.assign(r,$,a),r.encodePart=vt;break;case"hash":Object.assign(r,$,a),r.encodePart=bt;break}try{this.#i[o]=M(h,r),this.#r[o]=W(this.#i[o],this.#e[o],r),this.#t[o]=Et(this.#i[o],r),this.#u=this.#u||this.#i[o].some((n)=>n.type===2)}catch{throw new TypeError(`invalid ${o} pattern '${this.#n[o]}'.`)}}}catch(i){throw new TypeError(`Failed to construct 'URLPattern': ${i.message}`)}}test(t={},e){let s={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof t!="string"&&e)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof t>"u")return!1;try{typeof t=="object"?s=L(s,t,!1):s=L(s,H(t,e),!1)}catch{return!1}let i;for(i of S)if(!this.#r[i].exec(s[i]))return!1;return!0}exec(t={},e){let s={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof t!="string"&&e)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof t>"u")return;try{typeof t=="object"?s=L(s,t,!1):s=L(s,H(t,e),!1)}catch{return null}let i={};e?i.inputs=[t,e]:i.inputs=[t];let a;for(a of S){let u=this.#r[a].exec(s[a]);if(!u)return null;let o={};for(let[r,h]of this.#e[a].entries())if(typeof h=="string"||typeof h=="number"){let n=u[r+1];o[h]=n}i[a]={input:s[a]??"",groups:o}}return i}static compareComponent(t,e,s){let i=(r,h)=>{for(let n of["type","modifier","prefix","value","suffix"]){if(r[n]<h[n])return-1;if(r[n]===h[n])continue;return 1}return 0},a=new P(3,"","","","",3),u=new P(0,"","","","",3),o=(r,h)=>{let n=0;for(;n<Math.min(r.length,h.length);++n){let f=i(r[n],h[n]);if(f)return f}return r.length===h.length?0:i(r[n]??a,h[n]??a)};return!e.#t[t]&&!s.#t[t]?0:e.#t[t]&&!s.#t[t]?o(e.#i[t],[u]):!e.#t[t]&&s.#t[t]?o([u],s.#i[t]):o(e.#i[t],s.#i[t])}get protocol(){return this.#t.protocol}get username(){return this.#t.username}get password(){return this.#t.password}get hostname(){return this.#t.hostname}get port(){return this.#t.port}get pathname(){return this.#t.pathname}get search(){return this.#t.search}get hash(){return this.#t.hash}get hasRegExpGroups(){return this.#u}};if(!globalThis.URLPattern)globalThis.URLPattern=J;function Tt(t){const e=t.toString(),s=new Bun.CryptoHasher("sha1");return s.update(e),s.digest("hex")}
|
|
2
|
+
export{J as j,Tt as k};
|