@epoch32/visage 1.1.3 → 1.1.5
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/api/index.js +55 -4085
- package/dist/charts/index.js +48 -2806
- package/dist/devtools/index.js +18 -4771
- package/dist/dom/index.js +32 -1639
- package/dist/form/index.js +13 -1498
- package/dist/index-061jf06a.js +848 -0
- package/dist/index-0madxn60.js +442 -0
- package/dist/index-1xtrtz1t.js +256 -0
- package/dist/index-2zz0g2n2.js +212 -0
- package/dist/index-5s255b3w.js +303 -0
- package/dist/index-6kfe1nr4.js +1179 -0
- package/dist/index-8czhpea8.js +338 -0
- package/dist/index-8x8xz80v.js +727 -0
- package/dist/index-921pn75b.js +0 -0
- package/dist/index-965ryh36.js +537 -0
- package/dist/index-9fvarkrx.js +98 -0
- package/dist/index-a4xns6cc.js +219 -0
- package/dist/index-b5wc752a.js +1696 -0
- package/dist/index-df5e614s.js +334 -0
- package/dist/index-dyvgtp43.js +1094 -0
- package/dist/index-grhdtcb5.js +234 -0
- package/dist/index-h6tjqk6e.js +158 -0
- package/dist/index-js199er4.js +101 -0
- package/dist/index-x2rs3vab.js +124 -0
- package/dist/index-y9bq7h9g.js +1162 -0
- package/dist/index-zr6cvset.js +2092 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +458 -11920
- package/dist/jsx-runtime/index.js +13 -1719
- package/dist/query/index.js +47 -2505
- package/dist/router/index.js +25 -1945
- package/dist/rpc/index.js +39 -3567
- package/dist/server/index.js +11 -1256
- package/dist/signals/index.js +52 -1160
- package/dist/style/index.js +77 -2429
- package/dist/template/index.js +7 -1232
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +150 -4249
- package/dist/ui/tabs.d.ts +23 -1
- package/dist/virtual/index.js +12 -2044
- package/dist/vite/index.js +27 -746
- package/package.json +2 -2
- package/src/dom/render.ts +20 -7
- package/src/index.ts +2 -0
- package/src/signals/computed.ts +19 -12
- package/src/signals/effect.ts +7 -7
- package/src/signals/signal.ts +16 -12
- package/src/signals/system.ts +50 -21
- package/src/ui/index.ts +2 -0
- package/src/ui/tabs.tsx +211 -10
- package/src/ui/utils.ts +1 -3
- package/src/vite/lucide.ts +22 -2
|
File without changes
|
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateWithSchema2
|
|
3
|
+
} from "./index-2zz0g2n2.js";
|
|
4
|
+
|
|
5
|
+
// src/rpc/error.ts
|
|
6
|
+
var ERROR_CODE_TO_STATUS2 = {
|
|
7
|
+
BAD_REQUEST: 400,
|
|
8
|
+
UNAUTHORIZED: 401,
|
|
9
|
+
FORBIDDEN: 403,
|
|
10
|
+
NOT_FOUND: 404,
|
|
11
|
+
METHOD_NOT_ALLOWED: 405,
|
|
12
|
+
TIMEOUT: 408,
|
|
13
|
+
CONFLICT: 409,
|
|
14
|
+
UNPROCESSABLE_CONTENT: 422,
|
|
15
|
+
INTERNAL_SERVER_ERROR: 500
|
|
16
|
+
};
|
|
17
|
+
var STATUS_TO_ERROR_CODE2 = {
|
|
18
|
+
400: "BAD_REQUEST",
|
|
19
|
+
401: "UNAUTHORIZED",
|
|
20
|
+
403: "FORBIDDEN",
|
|
21
|
+
404: "NOT_FOUND",
|
|
22
|
+
405: "METHOD_NOT_ALLOWED",
|
|
23
|
+
408: "TIMEOUT",
|
|
24
|
+
409: "CONFLICT",
|
|
25
|
+
422: "UNPROCESSABLE_CONTENT",
|
|
26
|
+
500: "INTERNAL_SERVER_ERROR"
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
class RPCError2 extends Error {
|
|
30
|
+
code;
|
|
31
|
+
status;
|
|
32
|
+
issues;
|
|
33
|
+
constructor(codeOrStatusOrOptions, message) {
|
|
34
|
+
if (typeof codeOrStatusOrOptions === "number") {
|
|
35
|
+
const code = STATUS_TO_ERROR_CODE2[codeOrStatusOrOptions] || "INTERNAL_SERVER_ERROR";
|
|
36
|
+
super(message || code);
|
|
37
|
+
this.name = "RPCError";
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.status = codeOrStatusOrOptions;
|
|
40
|
+
} else if (typeof codeOrStatusOrOptions === "string") {
|
|
41
|
+
super(message || codeOrStatusOrOptions);
|
|
42
|
+
this.name = "RPCError";
|
|
43
|
+
this.code = codeOrStatusOrOptions;
|
|
44
|
+
this.status = ERROR_CODE_TO_STATUS2[codeOrStatusOrOptions] || 500;
|
|
45
|
+
} else {
|
|
46
|
+
super(codeOrStatusOrOptions.message ?? codeOrStatusOrOptions.code, {
|
|
47
|
+
cause: codeOrStatusOrOptions.cause
|
|
48
|
+
});
|
|
49
|
+
this.name = "RPCError";
|
|
50
|
+
this.code = codeOrStatusOrOptions.code;
|
|
51
|
+
this.status = ERROR_CODE_TO_STATUS2[codeOrStatusOrOptions.code] ?? 500;
|
|
52
|
+
this.issues = codeOrStatusOrOptions.issues;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
get statusCode() {
|
|
56
|
+
return this.status;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/rpc/procedure.ts
|
|
61
|
+
function createProcedure2(type, options, middlewares = []) {
|
|
62
|
+
return {
|
|
63
|
+
type,
|
|
64
|
+
inputSchema: options.input,
|
|
65
|
+
outputSchema: options.output,
|
|
66
|
+
middlewares: [...middlewares],
|
|
67
|
+
resolve: options.resolve
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async function executeProcedure2(procedure, opts) {
|
|
71
|
+
let input = opts.rawInput;
|
|
72
|
+
if (procedure.inputSchema) {
|
|
73
|
+
const res = validateWithSchema2(procedure.inputSchema, opts.rawInput);
|
|
74
|
+
if (!res.success) {
|
|
75
|
+
throw new RPCError2({
|
|
76
|
+
code: "BAD_REQUEST",
|
|
77
|
+
message: "Invalid procedure input",
|
|
78
|
+
issues: res.issues
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
input = res.data;
|
|
82
|
+
}
|
|
83
|
+
let currentIndex = 0;
|
|
84
|
+
let currentContext = opts.ctx;
|
|
85
|
+
const runPipeline = async (ctx) => {
|
|
86
|
+
currentContext = ctx;
|
|
87
|
+
if (currentIndex < procedure.middlewares.length) {
|
|
88
|
+
const mw = procedure.middlewares[currentIndex++];
|
|
89
|
+
return mw({
|
|
90
|
+
ctx: currentContext,
|
|
91
|
+
req: opts.req,
|
|
92
|
+
signal: opts.signal,
|
|
93
|
+
next: async (nextOpts) => {
|
|
94
|
+
return runPipeline(nextOpts?.ctx ?? currentContext);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return procedure.resolve({
|
|
99
|
+
input,
|
|
100
|
+
ctx: currentContext,
|
|
101
|
+
req: opts.req,
|
|
102
|
+
signal: opts.signal
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
const output = await runPipeline(currentContext);
|
|
106
|
+
if (procedure.outputSchema && procedure.type !== "subscription") {
|
|
107
|
+
const res = validateWithSchema2(procedure.outputSchema, output);
|
|
108
|
+
if (!res.success) {
|
|
109
|
+
throw new RPCError2({
|
|
110
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
111
|
+
message: "Invalid procedure output",
|
|
112
|
+
issues: res.issues
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return res.data;
|
|
116
|
+
}
|
|
117
|
+
return output;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/rpc/server.ts
|
|
121
|
+
function getCORSHeaders(cors, req) {
|
|
122
|
+
const headers = new Headers;
|
|
123
|
+
if (!cors)
|
|
124
|
+
return headers;
|
|
125
|
+
const opts = typeof cors === "object" ? cors : {};
|
|
126
|
+
const originHeader = req.headers.get("origin") ?? "*";
|
|
127
|
+
let allowOrigin = "*";
|
|
128
|
+
if (typeof opts.origin === "function") {
|
|
129
|
+
const res = opts.origin(originHeader);
|
|
130
|
+
if (typeof res === "string")
|
|
131
|
+
allowOrigin = res;
|
|
132
|
+
else if (res)
|
|
133
|
+
allowOrigin = originHeader;
|
|
134
|
+
} else if (typeof opts.origin === "string") {
|
|
135
|
+
allowOrigin = opts.origin;
|
|
136
|
+
} else if (Array.isArray(opts.origin)) {
|
|
137
|
+
if (opts.origin.includes(originHeader))
|
|
138
|
+
allowOrigin = originHeader;
|
|
139
|
+
} else {
|
|
140
|
+
allowOrigin = originHeader || "*";
|
|
141
|
+
}
|
|
142
|
+
headers.set("Access-Control-Allow-Origin", allowOrigin);
|
|
143
|
+
headers.set("Access-Control-Allow-Methods", (opts.methods ?? ["GET", "POST", "OPTIONS", "HEAD"]).join(", "));
|
|
144
|
+
headers.set("Access-Control-Allow-Headers", (opts.allowedHeaders ?? ["Content-Type", "Authorization", "X-Requested-With"]).join(", "));
|
|
145
|
+
if (opts.exposedHeaders) {
|
|
146
|
+
headers.set("Access-Control-Expose-Headers", opts.exposedHeaders.join(", "));
|
|
147
|
+
}
|
|
148
|
+
if (opts.credentials) {
|
|
149
|
+
headers.set("Access-Control-Allow-Credentials", "true");
|
|
150
|
+
}
|
|
151
|
+
if (opts.maxAge !== undefined) {
|
|
152
|
+
headers.set("Access-Control-Max-Age", opts.maxAge.toString());
|
|
153
|
+
}
|
|
154
|
+
return headers;
|
|
155
|
+
}
|
|
156
|
+
function resolveProcedureFromPath(router, path) {
|
|
157
|
+
const parts = path.split(/[./]/).filter(Boolean);
|
|
158
|
+
let current = router._def.record;
|
|
159
|
+
for (let i = 0;i < parts.length; i++) {
|
|
160
|
+
const part = parts[i];
|
|
161
|
+
if (!current || typeof current !== "object") {
|
|
162
|
+
throw new RPCError2({
|
|
163
|
+
code: "NOT_FOUND",
|
|
164
|
+
message: `Procedure '${path}' not found`
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (i === parts.length - 1) {
|
|
168
|
+
if (part in current && "type" in current[part]) {
|
|
169
|
+
return current[part];
|
|
170
|
+
}
|
|
171
|
+
throw new RPCError2({
|
|
172
|
+
code: "NOT_FOUND",
|
|
173
|
+
message: `Procedure '${path}' not found`
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (part in current && "_def" in current[part]) {
|
|
177
|
+
current = current[part]._def.record;
|
|
178
|
+
} else if (part in current && typeof current[part] === "object") {
|
|
179
|
+
current = current[part];
|
|
180
|
+
} else {
|
|
181
|
+
throw new RPCError2({
|
|
182
|
+
code: "NOT_FOUND",
|
|
183
|
+
message: `Procedure '${path}' not found`
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
throw new RPCError2({
|
|
188
|
+
code: "NOT_FOUND",
|
|
189
|
+
message: `Procedure '${path}' not found`
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function matchesRulePattern(pattern, urlPath, procedurePath) {
|
|
193
|
+
if (pattern === "*")
|
|
194
|
+
return true;
|
|
195
|
+
const cleanUrl = urlPath.replace(/^\/+|\/+$/g, "");
|
|
196
|
+
const cleanPattern = pattern.replace(/^\/+|\/+$/g, "");
|
|
197
|
+
const cleanProc = procedurePath.replace(/^\/+|\/+$/g, "");
|
|
198
|
+
if (cleanUrl === cleanPattern || cleanProc === cleanPattern || cleanProc === cleanPattern.replace(/\//g, ".")) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
if (cleanPattern.endsWith("*")) {
|
|
202
|
+
const prefix = cleanPattern.slice(0, -1);
|
|
203
|
+
if (cleanUrl.startsWith(prefix) || cleanProc.startsWith(prefix)) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
const dotPrefix = prefix.replace(/\//g, ".");
|
|
207
|
+
if (cleanProc.startsWith(dotPrefix)) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
const regexStr = cleanPattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
213
|
+
const regex = new RegExp(`^${regexStr}$`);
|
|
214
|
+
return regex.test(cleanUrl) || regex.test(cleanProc);
|
|
215
|
+
} catch {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function createFetchHandler2(options) {
|
|
220
|
+
const {
|
|
221
|
+
router,
|
|
222
|
+
endpoint = "",
|
|
223
|
+
createContext,
|
|
224
|
+
onError,
|
|
225
|
+
cors = true,
|
|
226
|
+
securityHeaders = true,
|
|
227
|
+
rules
|
|
228
|
+
} = options;
|
|
229
|
+
return async (request, ...extra) => {
|
|
230
|
+
const corsHeaders = getCORSHeaders(cors, request);
|
|
231
|
+
if (request.method === "OPTIONS") {
|
|
232
|
+
return new Response(null, {
|
|
233
|
+
status: 204,
|
|
234
|
+
headers: corsHeaders
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const baseHeaders = new Headers(corsHeaders);
|
|
238
|
+
if (securityHeaders) {
|
|
239
|
+
if (typeof securityHeaders === "object") {
|
|
240
|
+
for (const [k, v] of Object.entries(securityHeaders)) {
|
|
241
|
+
baseHeaders.set(k, v);
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
baseHeaders.set("X-Content-Type-Options", "nosniff");
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const url = new URL(request.url);
|
|
248
|
+
let pathname = url.pathname;
|
|
249
|
+
if (endpoint && pathname.startsWith(endpoint)) {
|
|
250
|
+
pathname = pathname.slice(endpoint.length);
|
|
251
|
+
}
|
|
252
|
+
pathname = pathname.replace(/^\/+|\/+$/g, "");
|
|
253
|
+
const procedurePath = pathname || url.searchParams.get("procedure") || "";
|
|
254
|
+
let ctx = {};
|
|
255
|
+
try {
|
|
256
|
+
if (createContext) {
|
|
257
|
+
ctx = await createContext({ req: request, extra });
|
|
258
|
+
}
|
|
259
|
+
} catch (err) {
|
|
260
|
+
const error = err instanceof RPCError2 ? err : new RPCError2({
|
|
261
|
+
code: "UNAUTHORIZED",
|
|
262
|
+
message: err.message ?? "Context initialization failed",
|
|
263
|
+
cause: err
|
|
264
|
+
});
|
|
265
|
+
onError?.({ error, req: request });
|
|
266
|
+
baseHeaders.set("Content-Type", "application/json");
|
|
267
|
+
return new Response(JSON.stringify({
|
|
268
|
+
error: {
|
|
269
|
+
code: error.code,
|
|
270
|
+
message: error.message,
|
|
271
|
+
issues: error.issues
|
|
272
|
+
}
|
|
273
|
+
}), {
|
|
274
|
+
status: error.status,
|
|
275
|
+
headers: baseHeaders
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
const rulesList = [];
|
|
279
|
+
if (rules) {
|
|
280
|
+
if (Array.isArray(rules)) {
|
|
281
|
+
rulesList.push(...rules);
|
|
282
|
+
} else {
|
|
283
|
+
for (const [match, rule] of Object.entries(rules)) {
|
|
284
|
+
rulesList.push({ match, ...rule });
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const matchingRules = rulesList.filter((r) => matchesRulePattern(r.match, url.pathname, procedurePath));
|
|
289
|
+
for (const rule of matchingRules) {
|
|
290
|
+
if (rule.requireHeaders) {
|
|
291
|
+
for (const headerName of rule.requireHeaders) {
|
|
292
|
+
if (!request.headers.get(headerName)) {
|
|
293
|
+
const error = new RPCError2({
|
|
294
|
+
code: "UNAUTHORIZED",
|
|
295
|
+
message: `Missing required header '${headerName}' for rule '${rule.match}'`
|
|
296
|
+
});
|
|
297
|
+
onError?.({ error, path: procedurePath, req: request });
|
|
298
|
+
baseHeaders.set("Content-Type", "application/json");
|
|
299
|
+
return new Response(JSON.stringify({
|
|
300
|
+
error: {
|
|
301
|
+
code: error.code,
|
|
302
|
+
message: error.message
|
|
303
|
+
}
|
|
304
|
+
}), {
|
|
305
|
+
status: 401,
|
|
306
|
+
headers: baseHeaders
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (rule.requireParams) {
|
|
312
|
+
for (const paramName of rule.requireParams) {
|
|
313
|
+
if (!url.searchParams.has(paramName)) {
|
|
314
|
+
const error = new RPCError2({
|
|
315
|
+
code: "BAD_REQUEST",
|
|
316
|
+
message: `Missing required query parameter '${paramName}' for rule '${rule.match}'`
|
|
317
|
+
});
|
|
318
|
+
onError?.({ error, path: procedurePath, req: request });
|
|
319
|
+
baseHeaders.set("Content-Type", "application/json");
|
|
320
|
+
return new Response(JSON.stringify({
|
|
321
|
+
error: {
|
|
322
|
+
code: error.code,
|
|
323
|
+
message: error.message
|
|
324
|
+
}
|
|
325
|
+
}), {
|
|
326
|
+
status: 400,
|
|
327
|
+
headers: baseHeaders
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (rule.guard) {
|
|
333
|
+
try {
|
|
334
|
+
const guardResult = await rule.guard({ req: request, ctx, path: procedurePath });
|
|
335
|
+
if (guardResult === false) {
|
|
336
|
+
throw new RPCError2({
|
|
337
|
+
code: "UNAUTHORIZED",
|
|
338
|
+
message: `Access denied by route rule guard for '${rule.match}'`
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
} catch (err) {
|
|
342
|
+
const error = err instanceof RPCError2 ? err : new RPCError2({
|
|
343
|
+
code: "UNAUTHORIZED",
|
|
344
|
+
message: err.message ?? "Unauthorized",
|
|
345
|
+
cause: err
|
|
346
|
+
});
|
|
347
|
+
onError?.({ error, path: procedurePath, req: request });
|
|
348
|
+
baseHeaders.set("Content-Type", "application/json");
|
|
349
|
+
return new Response(JSON.stringify({
|
|
350
|
+
error: {
|
|
351
|
+
code: error.code,
|
|
352
|
+
message: error.message
|
|
353
|
+
}
|
|
354
|
+
}), {
|
|
355
|
+
status: error.status,
|
|
356
|
+
headers: baseHeaders
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (rule.headers) {
|
|
361
|
+
const resHeaders = typeof rule.headers === "function" ? await rule.headers(request, ctx) : rule.headers;
|
|
362
|
+
for (const [k, v] of Object.entries(resHeaders)) {
|
|
363
|
+
baseHeaders.set(k, v);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (request.method === "POST" && (!pathname || pathname === "batch")) {
|
|
368
|
+
try {
|
|
369
|
+
const body = await request.json();
|
|
370
|
+
if (Array.isArray(body)) {
|
|
371
|
+
const batchResults = await Promise.all(body.map(async (item) => {
|
|
372
|
+
try {
|
|
373
|
+
const proc = resolveProcedureFromPath(router, item.path);
|
|
374
|
+
const data = await executeProcedure2(proc, {
|
|
375
|
+
rawInput: item.input,
|
|
376
|
+
ctx,
|
|
377
|
+
req: request,
|
|
378
|
+
signal: request.signal
|
|
379
|
+
});
|
|
380
|
+
return {
|
|
381
|
+
id: item.id,
|
|
382
|
+
result: { data }
|
|
383
|
+
};
|
|
384
|
+
} catch (err) {
|
|
385
|
+
const error = err instanceof RPCError2 ? err : new RPCError2({
|
|
386
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
387
|
+
message: err.message ?? "Internal Server Error",
|
|
388
|
+
cause: err
|
|
389
|
+
});
|
|
390
|
+
onError?.({ error, path: item.path, req: request });
|
|
391
|
+
return {
|
|
392
|
+
id: item.id,
|
|
393
|
+
error: {
|
|
394
|
+
code: error.code,
|
|
395
|
+
message: error.message,
|
|
396
|
+
issues: error.issues
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
}));
|
|
401
|
+
baseHeaders.set("Content-Type", "application/json");
|
|
402
|
+
return new Response(JSON.stringify(batchResults), {
|
|
403
|
+
status: 200,
|
|
404
|
+
headers: baseHeaders
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
} catch (err) {
|
|
408
|
+
const error = new RPCError2({
|
|
409
|
+
code: "BAD_REQUEST",
|
|
410
|
+
message: "Malformed batch request body",
|
|
411
|
+
cause: err
|
|
412
|
+
});
|
|
413
|
+
baseHeaders.set("Content-Type", "application/json");
|
|
414
|
+
return new Response(JSON.stringify({
|
|
415
|
+
error: {
|
|
416
|
+
code: error.code,
|
|
417
|
+
message: error.message
|
|
418
|
+
}
|
|
419
|
+
}), {
|
|
420
|
+
status: 400,
|
|
421
|
+
headers: baseHeaders
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
const procedure = resolveProcedureFromPath(router, procedurePath);
|
|
427
|
+
if (procedure.type === "mutation" && request.method !== "POST") {
|
|
428
|
+
throw new RPCError2({
|
|
429
|
+
code: "METHOD_NOT_ALLOWED",
|
|
430
|
+
message: "Mutations must use POST method"
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
let rawInput;
|
|
434
|
+
if (request.method === "GET") {
|
|
435
|
+
const inputParam = url.searchParams.get("input");
|
|
436
|
+
if (inputParam !== null) {
|
|
437
|
+
try {
|
|
438
|
+
rawInput = JSON.parse(inputParam);
|
|
439
|
+
} catch {
|
|
440
|
+
rawInput = inputParam;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
} else if (request.method === "POST") {
|
|
444
|
+
try {
|
|
445
|
+
const body = await request.json();
|
|
446
|
+
rawInput = body && typeof body === "object" && "input" in body ? body.input : body;
|
|
447
|
+
} catch {
|
|
448
|
+
rawInput = undefined;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (procedure.type === "subscription") {
|
|
452
|
+
const iterable = await executeProcedure2(procedure, {
|
|
453
|
+
rawInput,
|
|
454
|
+
ctx,
|
|
455
|
+
req: request,
|
|
456
|
+
signal: request.signal
|
|
457
|
+
});
|
|
458
|
+
if (!iterable || typeof iterable[Symbol.asyncIterator] !== "function") {
|
|
459
|
+
throw new RPCError2({
|
|
460
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
461
|
+
message: "Subscription procedure must return an AsyncIterable"
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const encoder = new TextEncoder;
|
|
465
|
+
const stream = new ReadableStream({
|
|
466
|
+
async start(controller) {
|
|
467
|
+
try {
|
|
468
|
+
for await (const chunk of iterable) {
|
|
469
|
+
if (request.signal.aborted)
|
|
470
|
+
break;
|
|
471
|
+
const message = `data: ${JSON.stringify(chunk)}
|
|
472
|
+
|
|
473
|
+
`;
|
|
474
|
+
controller.enqueue(encoder.encode(message));
|
|
475
|
+
}
|
|
476
|
+
controller.close();
|
|
477
|
+
} catch (err) {
|
|
478
|
+
const errorMessage = `event: error
|
|
479
|
+
data: ${JSON.stringify({ message: err.message ?? "Stream error" })}
|
|
480
|
+
|
|
481
|
+
`;
|
|
482
|
+
controller.enqueue(encoder.encode(errorMessage));
|
|
483
|
+
controller.close();
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
cancel() {
|
|
487
|
+
if (typeof iterable.return === "function") {
|
|
488
|
+
iterable.return();
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
baseHeaders.set("Content-Type", "text/event-stream; charset=utf-8");
|
|
493
|
+
baseHeaders.set("Cache-Control", "no-cache, no-transform");
|
|
494
|
+
baseHeaders.set("Connection", "keep-alive");
|
|
495
|
+
return new Response(stream, {
|
|
496
|
+
status: 200,
|
|
497
|
+
headers: baseHeaders
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
const data = await executeProcedure2(procedure, {
|
|
501
|
+
rawInput,
|
|
502
|
+
ctx,
|
|
503
|
+
req: request,
|
|
504
|
+
signal: request.signal
|
|
505
|
+
});
|
|
506
|
+
const responsePayload = {
|
|
507
|
+
result: { data }
|
|
508
|
+
};
|
|
509
|
+
baseHeaders.set("Content-Type", "application/json");
|
|
510
|
+
return new Response(JSON.stringify(responsePayload), {
|
|
511
|
+
status: 200,
|
|
512
|
+
headers: baseHeaders
|
|
513
|
+
});
|
|
514
|
+
} catch (err) {
|
|
515
|
+
const error = err instanceof RPCError2 ? err : new RPCError2({
|
|
516
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
517
|
+
message: err.message ?? "Internal Server Error",
|
|
518
|
+
cause: err
|
|
519
|
+
});
|
|
520
|
+
onError?.({ error, path: procedurePath, req: request });
|
|
521
|
+
const responsePayload = {
|
|
522
|
+
error: {
|
|
523
|
+
code: error.code,
|
|
524
|
+
message: error.message,
|
|
525
|
+
issues: error.issues
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
baseHeaders.set("Content-Type", "application/json");
|
|
529
|
+
return new Response(JSON.stringify(responsePayload), {
|
|
530
|
+
status: ERROR_CODE_TO_STATUS2[error.code] ?? 500,
|
|
531
|
+
headers: baseHeaders
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
export { ERROR_CODE_TO_STATUS2, STATUS_TO_ERROR_CODE2, RPCError2, createProcedure2, executeProcedure2, matchesRulePattern, createFetchHandler2 };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatStyleProp2,
|
|
3
|
+
resolveValue2,
|
|
4
|
+
setAttribute2,
|
|
5
|
+
insertChild2
|
|
6
|
+
} from "./index-6kfe1nr4.js";
|
|
7
|
+
|
|
8
|
+
// src/jsx-runtime/index.ts
|
|
9
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
10
|
+
var SVG_TAGS = new Set([
|
|
11
|
+
"svg",
|
|
12
|
+
"path",
|
|
13
|
+
"circle",
|
|
14
|
+
"rect",
|
|
15
|
+
"g",
|
|
16
|
+
"line",
|
|
17
|
+
"polyline",
|
|
18
|
+
"polygon",
|
|
19
|
+
"text",
|
|
20
|
+
"defs",
|
|
21
|
+
"clipPath",
|
|
22
|
+
"linearGradient",
|
|
23
|
+
"radialGradient",
|
|
24
|
+
"stop"
|
|
25
|
+
]);
|
|
26
|
+
function Fragment2(props) {
|
|
27
|
+
if (typeof document === "undefined") {
|
|
28
|
+
return props.children !== undefined ? props.children : [];
|
|
29
|
+
}
|
|
30
|
+
const fragment = document.createDocumentFragment();
|
|
31
|
+
if (props.children !== undefined) {
|
|
32
|
+
insertChild2(fragment, props.children);
|
|
33
|
+
}
|
|
34
|
+
return fragment;
|
|
35
|
+
}
|
|
36
|
+
function jsx2(type, props = {}, key) {
|
|
37
|
+
if (typeof type === "function") {
|
|
38
|
+
return type(props, key);
|
|
39
|
+
}
|
|
40
|
+
if (typeof type === "string") {
|
|
41
|
+
const { children, ...restProps } = props;
|
|
42
|
+
if (typeof document === "undefined") {
|
|
43
|
+
const attributes = new Map;
|
|
44
|
+
for (const propName in restProps) {
|
|
45
|
+
const val = restProps[propName];
|
|
46
|
+
if (propName === "className" || propName === "class") {
|
|
47
|
+
const resolved = typeof val === "function" ? val() : val;
|
|
48
|
+
if (resolved)
|
|
49
|
+
attributes.set("class", resolved);
|
|
50
|
+
} else if (propName === "style") {
|
|
51
|
+
const val = restProps[propName];
|
|
52
|
+
const resolved = resolveValue2(val);
|
|
53
|
+
if (typeof resolved === "string") {
|
|
54
|
+
attributes.set("style", resolved);
|
|
55
|
+
} else if (typeof resolved === "object" && resolved !== null) {
|
|
56
|
+
const styleStr = Object.entries(resolved).map(([k, v]) => {
|
|
57
|
+
const finalVal = resolveValue2(v);
|
|
58
|
+
const formatted = formatStyleProp2(k, finalVal);
|
|
59
|
+
if (!formatted)
|
|
60
|
+
return "";
|
|
61
|
+
const kebab = k.startsWith("--") ? k : k.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
62
|
+
return `${kebab}: ${formatted}`;
|
|
63
|
+
}).filter(Boolean).join("; ");
|
|
64
|
+
if (styleStr)
|
|
65
|
+
attributes.set("style", styleStr);
|
|
66
|
+
}
|
|
67
|
+
} else if (!propName.startsWith("on")) {
|
|
68
|
+
const resolved = typeof val === "function" ? val() : val;
|
|
69
|
+
if (resolved === true) {
|
|
70
|
+
attributes.set(propName, propName);
|
|
71
|
+
} else if (resolved !== false && resolved !== null && resolved !== undefined) {
|
|
72
|
+
attributes.set(propName, resolved);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const childNodes = children !== undefined ? Array.isArray(children) ? children : [children] : [];
|
|
77
|
+
return {
|
|
78
|
+
tagName: type,
|
|
79
|
+
attributes,
|
|
80
|
+
childNodes
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const isSvg = SVG_TAGS.has(type);
|
|
84
|
+
const element = isSvg ? document.createElementNS(SVG_NS, type) : document.createElement(type);
|
|
85
|
+
for (const propName in restProps) {
|
|
86
|
+
setAttribute2(element, propName, restProps[propName]);
|
|
87
|
+
}
|
|
88
|
+
if (children !== undefined) {
|
|
89
|
+
insertChild2(element, children);
|
|
90
|
+
}
|
|
91
|
+
return element;
|
|
92
|
+
}
|
|
93
|
+
return type;
|
|
94
|
+
}
|
|
95
|
+
var jsxs2 = jsx2;
|
|
96
|
+
var jsxDEV2 = jsx2;
|
|
97
|
+
|
|
98
|
+
export { Fragment2, jsx2, jsxs2, jsxDEV2 };
|