stitchkit 0.36.1 → 0.38.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.
- package/README.md +4 -2
- package/dist/browser/client-url.d.ts +11 -0
- package/dist/browser/client-url.d.ts.map +1 -0
- package/dist/browser/client.d.ts +16 -4
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/http.d.ts +7 -3
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/contract/define.d.ts +102 -2
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.d.ts.map +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/{index-bx49hskg.js → index-bgdd42pt.js} +1 -1
- package/dist/{index-0ed3bx43.js → index-frfyw9fa.js} +2 -2
- package/dist/{index-82gncajj.js → index-n5t4gnfz.js} +557 -337
- package/dist/{index-dvrn81q4.js → index-p3kwf73n.js} +165 -55
- package/dist/{index-pmftwk2a.js → index-x4wbc8sz.js} +54 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +147 -114
- package/dist/node.d.ts +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +7 -3
- package/dist/observability/index.js +3 -3
- package/dist/server/bun.d.ts +32 -0
- package/dist/server/bun.d.ts.map +1 -0
- package/dist/server/context.d.ts +1 -1
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/create.d.ts +2 -3
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/index.d.ts +3 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +41 -7
- package/dist/server/logger.d.ts +5 -5
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/logging.d.ts +4 -1
- package/dist/server/logging.d.ts.map +1 -1
- package/dist/server/middleware/auth.d.ts +2 -2
- package/dist/server/middleware/auth.d.ts.map +1 -1
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/request-body.d.ts +4 -0
- package/dist/server/request-body.d.ts.map +1 -0
- package/dist/server/response-metadata.d.ts +9 -0
- package/dist/server/response-metadata.d.ts.map +1 -0
- package/dist/server/router.d.ts +3 -3
- package/dist/server/router.d.ts.map +1 -1
- package/dist/server/socket-io-config.d.ts +20 -0
- package/dist/server/socket-io-config.d.ts.map +1 -0
- package/dist/server/socket-io-node.d.ts +14 -0
- package/dist/server/socket-io-node.d.ts.map +1 -0
- package/dist/server/socket-io.d.ts +5 -32
- package/dist/server/socket-io.d.ts.map +1 -1
- package/dist/server/types.d.ts +63 -50
- package/dist/server/types.d.ts.map +1 -1
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/execute.d.ts +46 -16
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/flatten-join.d.ts +8 -0
- package/dist/tools/flatten-join.d.ts.map +1 -0
- package/dist/tools/flatten.d.ts +7 -44
- package/dist/tools/flatten.d.ts.map +1 -1
- package/dist/tools/json-schema.d.ts +1 -1
- package/dist/tools/json-schema.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp-handler.d.ts +7 -13
- package/dist/tools/mcp-handler.d.ts.map +1 -1
- package/dist/tools/mcp.d.ts +61 -24
- package/dist/tools/mcp.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +9 -6
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/names.d.ts +1 -1
- package/dist/tools/native-mcp.d.ts +57 -0
- package/dist/tools/native-mcp.d.ts.map +1 -0
- package/dist/tools/portable-formats.d.ts +15 -0
- package/dist/tools/portable-formats.d.ts.map +1 -0
- package/dist/tools/presentation.d.ts +15 -0
- package/dist/tools/presentation.d.ts.map +1 -0
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/schema.d.ts +3 -8
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/tool-logger.d.ts.map +1 -1
- package/dist/tools/view-file.d.ts +5 -3
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools.d.ts +7 -4
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +481 -205
- package/llms-full.txt +536 -87
- package/package.json +14 -11
- /package/dist/{index-17rdjw68.js → index-mzx0an0s.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -16,18 +16,13 @@ import {
|
|
|
16
16
|
paginatedSchema,
|
|
17
17
|
rateLimited,
|
|
18
18
|
unauthorized
|
|
19
|
-
} from "./index-
|
|
19
|
+
} from "./index-x4wbc8sz.js";
|
|
20
20
|
import {
|
|
21
21
|
isRecord,
|
|
22
22
|
mapObject,
|
|
23
23
|
typedEntries
|
|
24
24
|
} from "./index-809wc1tt.js";
|
|
25
25
|
|
|
26
|
-
// src/internal/http-input.ts
|
|
27
|
-
function inputIsQuery(method) {
|
|
28
|
-
return method === "GET" || method === "DELETE";
|
|
29
|
-
}
|
|
30
|
-
|
|
31
26
|
// src/browser/client-multipart.ts
|
|
32
27
|
function isFileDescriptor(value) {
|
|
33
28
|
return typeof value === "object" && value !== null && !(value instanceof Blob) && "uri" in value && typeof value.uri === "string" && "name" in value && typeof value.name === "string" && "type" in value && typeof value.type === "string";
|
|
@@ -47,6 +42,122 @@ function appendFormFields(formData, values, skipKeys) {
|
|
|
47
42
|
}
|
|
48
43
|
}
|
|
49
44
|
|
|
45
|
+
// src/internal/http-input.ts
|
|
46
|
+
function inputIsQuery(method) {
|
|
47
|
+
return method === "GET" || method === "DELETE";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/browser/client-url.ts
|
|
51
|
+
function isParamArray(value) {
|
|
52
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string" || typeof item === "number");
|
|
53
|
+
}
|
|
54
|
+
function collectQueryParams(args, endpoint) {
|
|
55
|
+
const params = {};
|
|
56
|
+
let hasParams = false;
|
|
57
|
+
for (const [key, value] of Object.entries(args)) {
|
|
58
|
+
if (value === undefined || value === null)
|
|
59
|
+
continue;
|
|
60
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || isParamArray(value)) {
|
|
61
|
+
params[key] = value;
|
|
62
|
+
hasParams = true;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const what = Array.isArray(value) ? "an array with non-primitive items" : typeof value === "object" ? "a nested object" : `a ${typeof value}`;
|
|
66
|
+
throw new Error(`${endpoint.method} ${endpoint.path}: input field "${key}" is ${what} — it cannot ` + "travel as a query parameter. GET / DELETE input must be flat (string / number / " + "boolean, or an array of string / number); flatten the field or move the " + "operation to a body verb (POST).");
|
|
67
|
+
}
|
|
68
|
+
return hasParams ? params : undefined;
|
|
69
|
+
}
|
|
70
|
+
function hasStringKeys(args, keys) {
|
|
71
|
+
for (const key of keys) {
|
|
72
|
+
if (typeof args[key] !== "string")
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
function resolvePathPrefix(config, args) {
|
|
78
|
+
if (!config?.pathPrefix)
|
|
79
|
+
return "";
|
|
80
|
+
if (typeof config.pathPrefix === "string")
|
|
81
|
+
return config.pathPrefix;
|
|
82
|
+
const keys = config.stripPrefixKeys ?? [];
|
|
83
|
+
if (!hasStringKeys(args, keys)) {
|
|
84
|
+
const missing = keys.find((key) => typeof args[key] !== "string");
|
|
85
|
+
throw new Error(`Missing path prefix key: ${missing}`);
|
|
86
|
+
}
|
|
87
|
+
return config.pathPrefix(args);
|
|
88
|
+
}
|
|
89
|
+
function extractParamNames(path) {
|
|
90
|
+
const matches = path.match(/:(\w+)/g);
|
|
91
|
+
const names = matches ? matches.map((match) => match.slice(1)) : [];
|
|
92
|
+
if (path.endsWith("/*"))
|
|
93
|
+
names.push("*");
|
|
94
|
+
return names;
|
|
95
|
+
}
|
|
96
|
+
function fillPathParams(path, args) {
|
|
97
|
+
let filled = path.replace(/:(\w+)/g, (_, key) => {
|
|
98
|
+
const value = args[key];
|
|
99
|
+
if (value === undefined || value === null) {
|
|
100
|
+
throw new Error(`Missing path param: ${key}`);
|
|
101
|
+
}
|
|
102
|
+
return encodeURIComponent(String(value));
|
|
103
|
+
});
|
|
104
|
+
if (!filled.endsWith("/*"))
|
|
105
|
+
return filled;
|
|
106
|
+
const wildcard = args["*"];
|
|
107
|
+
if (wildcard === undefined || wildcard === null) {
|
|
108
|
+
throw new Error("Missing path param: *");
|
|
109
|
+
}
|
|
110
|
+
const remainder = String(wildcard).split("/").map((segment) => encodeURIComponent(segment)).join("/");
|
|
111
|
+
filled = `${filled.slice(0, -1)}${remainder}`;
|
|
112
|
+
return filled;
|
|
113
|
+
}
|
|
114
|
+
function stripConsumedArgs(args, path, scopeKeys) {
|
|
115
|
+
const consumed = new Set(scopeKeys);
|
|
116
|
+
for (const name of extractParamNames(path))
|
|
117
|
+
consumed.add(name);
|
|
118
|
+
const remaining = {};
|
|
119
|
+
for (const [key, value] of Object.entries(args)) {
|
|
120
|
+
if (!consumed.has(key) && value !== undefined)
|
|
121
|
+
remaining[key] = value;
|
|
122
|
+
}
|
|
123
|
+
return remaining;
|
|
124
|
+
}
|
|
125
|
+
function appendQuery(relativeUrl, params) {
|
|
126
|
+
if (!params)
|
|
127
|
+
return relativeUrl;
|
|
128
|
+
const search = new URLSearchParams;
|
|
129
|
+
for (const [key, value] of Object.entries(params)) {
|
|
130
|
+
if (Array.isArray(value)) {
|
|
131
|
+
for (const item of value)
|
|
132
|
+
search.append(key, String(item));
|
|
133
|
+
} else {
|
|
134
|
+
search.set(key, String(value));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return search.size > 0 ? `${relativeUrl}?${search}` : relativeUrl;
|
|
138
|
+
}
|
|
139
|
+
function planClientRequest(endpoint, contractPrefix, args, config) {
|
|
140
|
+
let pathPrefix = resolvePathPrefix(config, args);
|
|
141
|
+
if (pathPrefix && !pathPrefix.endsWith("/"))
|
|
142
|
+
pathPrefix += "/";
|
|
143
|
+
if (pathPrefix.startsWith("/"))
|
|
144
|
+
pathPrefix = pathPrefix.slice(1);
|
|
145
|
+
const endpointPath = endpoint.path === "/" ? "" : endpoint.path;
|
|
146
|
+
let relativeUrl = fillPathParams(`${pathPrefix}${contractPrefix}${endpointPath}`, args);
|
|
147
|
+
if (relativeUrl.endsWith("/"))
|
|
148
|
+
relativeUrl = relativeUrl.slice(0, -1);
|
|
149
|
+
const remainingArgs = stripConsumedArgs(args, endpoint.path, config?.stripPrefixKeys ?? []);
|
|
150
|
+
if (inputIsQuery(endpoint.method)) {
|
|
151
|
+
relativeUrl = appendQuery(relativeUrl, collectQueryParams(remainingArgs, endpoint));
|
|
152
|
+
}
|
|
153
|
+
return { relativeUrl, remainingArgs };
|
|
154
|
+
}
|
|
155
|
+
function joinClientBaseUrl(baseUrl, relativeUrl) {
|
|
156
|
+
const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
157
|
+
const path = relativeUrl.startsWith("/") ? relativeUrl : `/${relativeUrl}`;
|
|
158
|
+
return `${base}${path}`;
|
|
159
|
+
}
|
|
160
|
+
|
|
50
161
|
// src/browser/http.ts
|
|
51
162
|
import ky, { isHTTPError } from "ky";
|
|
52
163
|
|
|
@@ -228,6 +339,7 @@ function createHttpClient(config) {
|
|
|
228
339
|
}
|
|
229
340
|
}
|
|
230
341
|
return {
|
|
342
|
+
baseUrl: config.baseUrl,
|
|
231
343
|
get: (url, options) => request("get", url, undefined, options),
|
|
232
344
|
post: (url, data, options) => request("post", url, data, options),
|
|
233
345
|
put: (url, data, options) => request("put", url, data, options),
|
|
@@ -267,25 +379,6 @@ function withOutput(endpoint, result) {
|
|
|
267
379
|
return result;
|
|
268
380
|
return result.then((value) => value === undefined ? undefined : schema.parse(value));
|
|
269
381
|
}
|
|
270
|
-
function isParamArray(value) {
|
|
271
|
-
return Array.isArray(value) && value.every((v) => typeof v === "string" || typeof v === "number");
|
|
272
|
-
}
|
|
273
|
-
function collectQueryParams(args, skipKeys, endpoint) {
|
|
274
|
-
const params = {};
|
|
275
|
-
let hasParams = false;
|
|
276
|
-
for (const [key, value] of Object.entries(args)) {
|
|
277
|
-
if (skipKeys.has(key) || value === undefined || value === null)
|
|
278
|
-
continue;
|
|
279
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || isParamArray(value)) {
|
|
280
|
-
params[key] = value;
|
|
281
|
-
hasParams = true;
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
const what = Array.isArray(value) ? "an array with non-primitive items" : typeof value === "object" ? "a nested object" : `a ${typeof value}`;
|
|
285
|
-
throw new Error(`${endpoint.method} ${endpoint.path}: input field "${key}" is ${what} — it cannot ` + "travel as a query parameter. GET / DELETE input must be flat (string / number / " + "boolean, or an array of string / number); flatten the field or move the " + "operation to a body verb (POST).");
|
|
286
|
-
}
|
|
287
|
-
return hasParams ? params : undefined;
|
|
288
|
-
}
|
|
289
382
|
function createClient(contract, configOrClient, contractConfig) {
|
|
290
383
|
const client = {};
|
|
291
384
|
const makeMethod = isHttpAdapter(configOrClient) ? (endpoint) => createHttpMethod(endpoint, contract.meta.prefix, configOrClient, contractConfig) : (endpoint) => createFetchMethod(endpoint, contract.meta.prefix, configOrClient, contractConfig);
|
|
@@ -296,8 +389,8 @@ function createClient(contract, configOrClient, contractConfig) {
|
|
|
296
389
|
}
|
|
297
390
|
return client;
|
|
298
391
|
}
|
|
299
|
-
function createClients(contracts,
|
|
300
|
-
return mapObject(contracts, (_key, contract) => createClient(contract,
|
|
392
|
+
function createClients(contracts, configOrClient, contractConfig) {
|
|
393
|
+
return mapObject(contracts, (_key, contract) => createClient(contract, configOrClient, contractConfig));
|
|
301
394
|
}
|
|
302
395
|
function isHttpAdapter(value) {
|
|
303
396
|
return typeof value === "object" && "get" in value && typeof value.get === "function";
|
|
@@ -307,27 +400,9 @@ function setClientMethod(target, key, method) {
|
|
|
307
400
|
}
|
|
308
401
|
function createHttpMethod(endpoint, prefix, client, config) {
|
|
309
402
|
const httpMethod = endpoint.method.toLowerCase();
|
|
310
|
-
const isGet = httpMethod === "get";
|
|
311
|
-
const paramNames = extractParamNames(endpoint.path);
|
|
312
|
-
const prefixKeys = new Set([...config?.stripPrefixKeys ?? [], ...paramNames]);
|
|
313
403
|
return (...args) => {
|
|
314
404
|
const firstArg = args[0] ?? {};
|
|
315
|
-
|
|
316
|
-
if (config?.pathPrefix) {
|
|
317
|
-
pathPrefixStr = typeof config.pathPrefix === "function" ? config.pathPrefix(firstArg) : config.pathPrefix;
|
|
318
|
-
if (pathPrefixStr && !pathPrefixStr.endsWith("/"))
|
|
319
|
-
pathPrefixStr += "/";
|
|
320
|
-
}
|
|
321
|
-
let url = `${pathPrefixStr}${prefix}${endpoint.path}`;
|
|
322
|
-
for (const name of paramNames) {
|
|
323
|
-
const value = firstArg[name];
|
|
324
|
-
if (value === undefined || value === null) {
|
|
325
|
-
throw new Error(`Missing path param: ${name}`);
|
|
326
|
-
}
|
|
327
|
-
url = url.replace(`:${name}`, encodeURIComponent(String(value)));
|
|
328
|
-
}
|
|
329
|
-
if (url.endsWith("/"))
|
|
330
|
-
url = url.slice(0, -1);
|
|
405
|
+
const plan = planClientRequest(endpoint, prefix, firstArg, config);
|
|
331
406
|
if (endpoint.multipart) {
|
|
332
407
|
const file = firstArg[endpoint.multipart];
|
|
333
408
|
if (!isMultipartFile(file)) {
|
|
@@ -338,59 +413,28 @@ function createHttpMethod(endpoint, prefix, client, config) {
|
|
|
338
413
|
}
|
|
339
414
|
const formData = new FormData;
|
|
340
415
|
appendMultipartFile(formData, endpoint.multipart, file);
|
|
341
|
-
appendFormFields(formData,
|
|
342
|
-
return withOutput(endpoint, client[httpMethod](
|
|
416
|
+
appendFormFields(formData, plan.remainingArgs, new Set([endpoint.multipart]));
|
|
417
|
+
return withOutput(endpoint, client[httpMethod](plan.relativeUrl, formData, withTimeout(undefined, endpoint)));
|
|
343
418
|
}
|
|
344
|
-
if (
|
|
345
|
-
|
|
346
|
-
return withOutput(endpoint, client.get(url, withTimeout(params ? { params } : undefined, endpoint)));
|
|
419
|
+
if (httpMethod === "get") {
|
|
420
|
+
return withOutput(endpoint, client.get(plan.relativeUrl, withTimeout(undefined, endpoint)));
|
|
347
421
|
}
|
|
348
422
|
if (httpMethod === "delete") {
|
|
349
|
-
|
|
350
|
-
return withOutput(endpoint, client.delete(url, withTimeout(params ? { params } : undefined, endpoint)));
|
|
351
|
-
}
|
|
352
|
-
const payload = {};
|
|
353
|
-
for (const [key, value] of Object.entries(firstArg)) {
|
|
354
|
-
if (!prefixKeys.has(key) && value !== undefined) {
|
|
355
|
-
payload[key] = value;
|
|
356
|
-
}
|
|
423
|
+
return withOutput(endpoint, client.delete(plan.relativeUrl, withTimeout(undefined, endpoint)));
|
|
357
424
|
}
|
|
358
|
-
return withOutput(endpoint, client[httpMethod](
|
|
425
|
+
return withOutput(endpoint, client[httpMethod](plan.relativeUrl, Object.keys(plan.remainingArgs).length > 0 ? plan.remainingArgs : undefined, withTimeout(undefined, endpoint)));
|
|
359
426
|
};
|
|
360
427
|
}
|
|
361
428
|
function createFetchMethod(endpoint, prefix, config, contractConfig) {
|
|
362
|
-
const prefixKeys = new Set(contractConfig?.stripPrefixKeys ?? []);
|
|
363
429
|
return async (args) => {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
pathPrefixStr = typeof contractConfig.pathPrefix === "function" ? contractConfig.pathPrefix(args ?? {}) : contractConfig.pathPrefix;
|
|
367
|
-
if (pathPrefixStr && !pathPrefixStr.endsWith("/"))
|
|
368
|
-
pathPrefixStr += "/";
|
|
369
|
-
}
|
|
370
|
-
let url = buildFetchUrl(config.baseUrl, prefix, endpoint.path, args, pathPrefixStr);
|
|
430
|
+
const plan = planClientRequest(endpoint, prefix, args ?? {}, contractConfig);
|
|
431
|
+
const url = joinClientBaseUrl(config.baseUrl, plan.relativeUrl);
|
|
371
432
|
const headers = {
|
|
372
433
|
Accept: "application/json",
|
|
373
434
|
...typeof config.headers === "function" ? config.headers() : config.headers
|
|
374
435
|
};
|
|
375
436
|
const signal = endpoint.timeout !== undefined ? AbortSignal.timeout(endpoint.timeout) : undefined;
|
|
376
|
-
const
|
|
377
|
-
const hasBody = !isQuery && !endpoint.multipart && endpoint.input && args;
|
|
378
|
-
if (isQuery && args) {
|
|
379
|
-
const remaining = stripParams(args, endpoint.path, prefixKeys);
|
|
380
|
-
const params = collectQueryParams(remaining, new Set, endpoint);
|
|
381
|
-
if (params) {
|
|
382
|
-
const searchParams = new URLSearchParams;
|
|
383
|
-
for (const [k, v] of Object.entries(params)) {
|
|
384
|
-
if (Array.isArray(v)) {
|
|
385
|
-
for (const item of v)
|
|
386
|
-
searchParams.append(k, String(item));
|
|
387
|
-
} else {
|
|
388
|
-
searchParams.set(k, String(v));
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
url += `?${searchParams}`;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
437
|
+
const hasBody = endpoint.method !== "GET" && endpoint.method !== "DELETE" && !endpoint.multipart && endpoint.input && args;
|
|
394
438
|
if (hasBody)
|
|
395
439
|
headers["Content-Type"] = "application/json";
|
|
396
440
|
if (endpoint.multipart && args) {
|
|
@@ -400,7 +444,7 @@ function createFetchMethod(endpoint, prefix, config, contractConfig) {
|
|
|
400
444
|
}
|
|
401
445
|
const formData = new FormData;
|
|
402
446
|
appendMultipartFile(formData, endpoint.multipart, file);
|
|
403
|
-
appendFormFields(formData,
|
|
447
|
+
appendFormFields(formData, plan.remainingArgs, new Set([endpoint.multipart]));
|
|
404
448
|
const res2 = await fetch(url, {
|
|
405
449
|
method: endpoint.method,
|
|
406
450
|
headers,
|
|
@@ -424,7 +468,7 @@ function createFetchMethod(endpoint, prefix, config, contractConfig) {
|
|
|
424
468
|
credentials: config.credentials,
|
|
425
469
|
signal,
|
|
426
470
|
...hasBody && {
|
|
427
|
-
body: JSON.stringify(
|
|
471
|
+
body: JSON.stringify(plan.remainingArgs)
|
|
428
472
|
}
|
|
429
473
|
});
|
|
430
474
|
if (!res.ok) {
|
|
@@ -447,35 +491,22 @@ async function throwForErrorResponse(res, config, fallbackBody) {
|
|
|
447
491
|
}
|
|
448
492
|
throw new ApiError("HTTP_ERROR", res.status, { body });
|
|
449
493
|
}
|
|
450
|
-
function
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
throw new Error(`Missing path param: ${key}`);
|
|
461
|
-
}
|
|
462
|
-
return encodeURIComponent(String(val));
|
|
494
|
+
function createUrlBuilder(contract, source, contractConfig) {
|
|
495
|
+
const builder = {};
|
|
496
|
+
for (const [key, endpoint] of typedEntries(contract.endpoints)) {
|
|
497
|
+
if (endpoint.method !== "GET" || endpoint.multipart)
|
|
498
|
+
continue;
|
|
499
|
+
if (endpoint.expose && !endpoint.expose.includes("HTTP"))
|
|
500
|
+
continue;
|
|
501
|
+
setClientMethod(builder, key, (args) => {
|
|
502
|
+
const plan = planClientRequest(endpoint, contract.meta.prefix, args ?? {}, contractConfig);
|
|
503
|
+
return joinClientBaseUrl(source.baseUrl, plan.relativeUrl);
|
|
463
504
|
});
|
|
464
505
|
}
|
|
465
|
-
return
|
|
506
|
+
return builder;
|
|
466
507
|
}
|
|
467
|
-
function
|
|
468
|
-
|
|
469
|
-
for (const match of path.matchAll(/:(\w+)/g)) {
|
|
470
|
-
if (match[1])
|
|
471
|
-
skip.add(match[1]);
|
|
472
|
-
}
|
|
473
|
-
const result = {};
|
|
474
|
-
for (const [k, v] of Object.entries(args)) {
|
|
475
|
-
if (!skip.has(k))
|
|
476
|
-
result[k] = v;
|
|
477
|
-
}
|
|
478
|
-
return result;
|
|
508
|
+
function createUrlBuilders(contracts, source, contractConfig) {
|
|
509
|
+
return mapObject(contracts, (_key, contract) => createUrlBuilder(contract, source, contractConfig));
|
|
479
510
|
}
|
|
480
511
|
// src/retained.ts
|
|
481
512
|
function createRetainedTopics() {
|
|
@@ -683,6 +714,8 @@ export {
|
|
|
683
714
|
defineErrors,
|
|
684
715
|
defineContract,
|
|
685
716
|
decodeCursor,
|
|
717
|
+
createUrlBuilders,
|
|
718
|
+
createUrlBuilder,
|
|
686
719
|
createTraceContext,
|
|
687
720
|
createSocketIOClient,
|
|
688
721
|
createRetainedTopics,
|
package/dist/node.d.ts
CHANGED
|
@@ -9,6 +9,6 @@ export { createHandler } from './server/create';
|
|
|
9
9
|
export { createImplement, implement } from './server/implement';
|
|
10
10
|
export type { LogFormat } from './server/logger';
|
|
11
11
|
export { type NodeServerConfig, type NodeServerHandle, serveNode } from './server/node';
|
|
12
|
-
export { createSocketIOServer, type
|
|
12
|
+
export { createNodeSocketIOServer as createSocketIOServer, type NodeSocketIOServerHandle as SocketIOServerHandle, type SocketIOServerConfig, } from './server/socket-io-node';
|
|
13
13
|
export type { FetchComposition, FetchHandler, HandlerConfig, LoggingConfig, LogOutcome, RawRoute, RawRouteContext, ServiceDef, } from './server/types';
|
|
14
14
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EACL,oBAAoB,
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EACL,wBAAwB,IAAI,oBAAoB,EAChD,KAAK,wBAAwB,IAAI,oBAAoB,EACrD,KAAK,oBAAoB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,UAAU,EACV,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,gBAAgB,CAAC"}
|
package/dist/node.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
createImplement,
|
|
4
4
|
createSocketIOServer,
|
|
5
5
|
implement
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-p3kwf73n.js";
|
|
7
7
|
import"./index-czmqks7r.js";
|
|
8
8
|
import"./index-x3fcszf8.js";
|
|
9
9
|
import {
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
notFound,
|
|
16
16
|
rateLimited,
|
|
17
17
|
unauthorized
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-mzx0an0s.js";
|
|
19
19
|
// src/server/node.ts
|
|
20
20
|
import { serve } from "srvx";
|
|
21
21
|
async function serveNode(config) {
|
|
@@ -40,6 +40,10 @@ async function serveNode(config) {
|
|
|
40
40
|
close: (closeActive) => server.close(closeActive)
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
// src/server/socket-io-node.ts
|
|
44
|
+
async function createNodeSocketIOServer(config) {
|
|
45
|
+
return createSocketIOServer(config);
|
|
46
|
+
}
|
|
43
47
|
export {
|
|
44
48
|
unauthorized,
|
|
45
49
|
serveNode,
|
|
@@ -47,7 +51,7 @@ export {
|
|
|
47
51
|
notFound,
|
|
48
52
|
implement,
|
|
49
53
|
forbidden,
|
|
50
|
-
createSocketIOServer,
|
|
54
|
+
createNodeSocketIOServer as createSocketIOServer,
|
|
51
55
|
createImplement,
|
|
52
56
|
createHandler,
|
|
53
57
|
conflict,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
setRequestError,
|
|
17
17
|
setRequestUser,
|
|
18
18
|
wrapInRequestContext
|
|
19
|
-
} from "../index-
|
|
19
|
+
} from "../index-mzx0an0s.js";
|
|
20
20
|
|
|
21
21
|
// src/observability/sanitize.ts
|
|
22
22
|
var DEFAULT_SENSITIVE_KEYS = /(password|passwd|pwd|secret|token|apikey|api[-_ ]?key|auth|authorization|bearer|session|cookie|init[-_ ]?data|credential|private[-_ ]?key)/i;
|
|
@@ -171,7 +171,7 @@ function createAuditHook(config) {
|
|
|
171
171
|
};
|
|
172
172
|
};
|
|
173
173
|
const toolCall = {
|
|
174
|
-
afterToolCall: (toolName, args, result, durationMs, context, endpoint,
|
|
174
|
+
afterToolCall: ({ toolName, args, result, durationMs, context, endpoint, error }) => {
|
|
175
175
|
const requestCtx = getRequestContext();
|
|
176
176
|
const span = requestCtx ? childSpan(requestCtx.trace) : createTraceContext();
|
|
177
177
|
const measure = result.ok ? measureSize(result.data) : { resultSize: null, responseBytes: 0 };
|
|
@@ -191,7 +191,7 @@ function createAuditHook(config) {
|
|
|
191
191
|
statusCode: result.ok ? 200 : 400,
|
|
192
192
|
durationMs,
|
|
193
193
|
errorCode: result.ok ? undefined : result.code,
|
|
194
|
-
errorMessage: result.ok ? undefined : auditErrorMessage(result,
|
|
194
|
+
errorMessage: result.ok ? undefined : auditErrorMessage(result, error),
|
|
195
195
|
...!result.ok && result.details !== undefined && {
|
|
196
196
|
errorDetail: sanitizePayload(result.details, sanitize)
|
|
197
197
|
},
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { FetchComposition, FetchHandler, HandlerConfig, RawRoute, RawRouteContext } from './types';
|
|
2
|
+
/** The concrete `Bun.serve` server instance passed to Bun raw routes. */
|
|
3
|
+
export type BunServer = ReturnType<typeof Bun.serve>;
|
|
4
|
+
export type BunRawRoute = RawRoute<BunServer>;
|
|
5
|
+
export type BunRawRouteContext = RawRouteContext<BunServer>;
|
|
6
|
+
export type BunFetchHandler = FetchHandler<BunServer>;
|
|
7
|
+
export type BunFetchComposition = FetchComposition<BunServer>;
|
|
8
|
+
export type BunHandlerConfig = HandlerConfig<BunServer>;
|
|
9
|
+
type BunServeOptions = Parameters<typeof Bun.serve>[0];
|
|
10
|
+
type BunWebSocketHandlers = BunServeOptions extends {
|
|
11
|
+
websocket?: infer T;
|
|
12
|
+
} ? T : never;
|
|
13
|
+
type BunRoutes = BunServeOptions extends {
|
|
14
|
+
routes?: infer T;
|
|
15
|
+
} ? T : never;
|
|
16
|
+
type BunDevelopmentOptions = BunServeOptions extends {
|
|
17
|
+
development?: infer T;
|
|
18
|
+
} ? T : never;
|
|
19
|
+
export type ServerPassthrough = Omit<BunServeOptions, 'fetch' | 'port' | 'hostname' | 'unix' | 'routes' | 'websocket' | 'development'>;
|
|
20
|
+
/** Bun-specific server config layered over the Fetch-clean handler config. */
|
|
21
|
+
export interface BunServerConfig extends BunHandlerConfig, BunFetchComposition {
|
|
22
|
+
port?: number;
|
|
23
|
+
hostname?: string;
|
|
24
|
+
routes?: BunRoutes;
|
|
25
|
+
websocket?: BunWebSocketHandlers;
|
|
26
|
+
development?: BunDevelopmentOptions;
|
|
27
|
+
bun?: ServerPassthrough;
|
|
28
|
+
}
|
|
29
|
+
/** Start the contract router through `Bun.serve`. */
|
|
30
|
+
export declare function createServer(config: BunServerConfig): BunServer;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=bun.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.d.ts","sourceRoot":"","sources":["../../src/server/bun.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,yEAAyE;AACzE,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;AACrD,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC9C,MAAM,MAAM,kBAAkB,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;AAC5D,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;AACtD,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAExD,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,KAAK,oBAAoB,GAAG,eAAe,SAAS;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AACxF,KAAK,SAAS,GAAG,eAAe,SAAS;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAC1E,KAAK,qBAAqB,GAAG,eAAe,SAAS;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAE3F,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAClC,eAAe,EACf,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,CAChF,CAAC;AAEF,8EAA8E;AAC9E,MAAM,WAAW,eAAgB,SAAQ,gBAAgB,EAAE,mBAAmB;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,GAAG,CAAC,EAAE,iBAAiB,CAAC;CACzB;AAED,qDAAqD;AACrD,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAuB/D"}
|
package/dist/server/context.d.ts
CHANGED
|
@@ -22,6 +22,6 @@ export declare function buildBaseContext(req: Request, url: URL, pathParams: Rec
|
|
|
22
22
|
* already-assembled base context. A validation failure throws a `ZodError`
|
|
23
23
|
* here — the base context (path params, request) is preserved for `onError`.
|
|
24
24
|
*/
|
|
25
|
-
export declare function parseRequestInto(ctx: RuntimeContext, req: Request, url: URL, method: MethodDef, maxUploadBytes?: number): Promise<void>;
|
|
25
|
+
export declare function parseRequestInto(ctx: RuntimeContext, req: Request, url: URL, method: MethodDef, maxUploadBytes?: number, maxJsonBodyBytes?: number): Promise<void>;
|
|
26
26
|
export declare function buildErrorContext(req: Request, url: URL, traceId: string, clientIp: ClientIpOptions): RuntimeContext;
|
|
27
27
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/server/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAG9D,OAAO,EAAE,KAAK,eAAe,EAAmC,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/server/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAG9D,OAAO,EAAE,KAAK,eAAe,EAAmC,MAAM,WAAW,CAAC;AAElF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAmCzC;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,eAAe,GACxB,cAAc,CAmBhB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,SAAS,EACjB,cAAc,CAAC,EAAE,MAAM,EACvB,gBAAgB,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,eAAe,GACxB,cAAc,CAWhB"}
|
package/dist/server/create.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createHandler(config: HandlerConfig): FetchHandler
|
|
3
|
-
export declare function createServer(config: BunServerConfig): Bun.Server<unknown>;
|
|
1
|
+
import type { FetchHandler, HandlerConfig } from './types';
|
|
2
|
+
export declare function createHandler<TServer = unknown>(config: HandlerConfig<TServer>): FetchHandler<TServer>;
|
|
4
3
|
//# sourceMappingURL=create.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.ts"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAA2B,MAAM,SAAS,CAAC;AAEpF,wBAAgB,aAAa,CAAC,OAAO,GAAG,OAAO,EAC7C,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,GAC7B,YAAY,CAAC,OAAO,CAAC,CA0cvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"implement.d.ts","sourceRoot":"","sources":["../../src/server/implement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG5E,OAAO,KAAK,EAAE,QAAQ,EAAa,UAAU,EAAE,MAAM,SAAS,CAAC;AAK/D;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACrC,IAAI,SAAS,cAAc,GAAG,cAAc,EAC5C,QAAQ,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"implement.d.ts","sourceRoot":"","sources":["../../src/server/implement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG5E,OAAO,KAAK,EAAE,QAAQ,EAAa,UAAU,EAAE,MAAM,SAAS,CAAC;AAK/D;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACrC,IAAI,SAAS,cAAc,GAAG,cAAc,EAC5C,QAAQ,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,UAAU,CA+D3E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,SAAS,cAAc,MACjD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,YACjC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,YACtB,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,KAC1B,UAAU,CACd"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { AppError, appError, badRequest, conflict, forbidden, isStitchErrorCode, notFound, rateLimited, STITCH_ERROR_STATUS, type StitchErrorCode, unauthorized, } from '../contract';
|
|
2
2
|
export { errorCode, formatZodError, normalizeError, type ZodIssueSummary, zodIssues, } from '../internal/errors';
|
|
3
3
|
export { isWithinDir } from '../internal/within-dir';
|
|
4
|
+
export { type BunFetchComposition as FetchComposition, type BunFetchHandler as FetchHandler, type BunHandlerConfig as HandlerConfig, type BunRawRoute as RawRoute, type BunRawRouteContext as RawRouteContext, type BunServer, type BunServerConfig, createServer, type ServerPassthrough, } from './bun';
|
|
4
5
|
export { cacheHeaders, createCache } from './cache';
|
|
5
|
-
export { createHandler
|
|
6
|
+
export { createHandler } from './create';
|
|
6
7
|
export { createErrorHook, type ErrorHookConfig, type ResolvedError, } from './error-hook';
|
|
7
8
|
export { createEventBus, type DefaultEventMap, type EventBus, type EventBusOptions, type EventHandler, } from './event-bus';
|
|
8
9
|
export { type ByteRange, parseByteRange, type ServeFileOptions, serveFile, weakETag, } from './file';
|
|
@@ -21,6 +22,6 @@ export { staticRoute } from './router';
|
|
|
21
22
|
export type { SocketIOServerConfig, SocketIOServerHandle } from './socket-io';
|
|
22
23
|
export { createSocketIOServer, socketIoLane } from './socket-io';
|
|
23
24
|
export { type ParseSSEOptions, parseSSE, streamSSE } from './stream';
|
|
24
|
-
export type {
|
|
25
|
+
export type { Handlers, LifecycleHooks, LoggingConfig, LogOutcome, MethodDef, OperationIdentity, RouteGroup, ServiceDef, StitchLogger, } from './types';
|
|
25
26
|
export { type ComposedLane, composeWebSocketHandlers, type WebSocketComposeConfig, type WebSocketLane, webSocketLane, } from './websocket';
|
|
26
27
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,KAAK,eAAe,EACpB,YAAY,GACb,MAAM,aAAa,CAAC;AAIrB,OAAO,EACL,SAAS,EACT,cAAc,EACd,cAAc,EACd,KAAK,eAAe,EACpB,SAAS,GACV,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"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"}
|
package/dist/server/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
composeWebSocketHandlers,
|
|
3
3
|
createHandler,
|
|
4
4
|
createImplement,
|
|
5
|
-
createServer,
|
|
6
5
|
createSocketIOServer,
|
|
7
6
|
implement,
|
|
8
7
|
mimeForPath,
|
|
@@ -10,7 +9,7 @@ import {
|
|
|
10
9
|
socketIoLane,
|
|
11
10
|
staticRoute,
|
|
12
11
|
webSocketLane
|
|
13
|
-
} from "../index-
|
|
12
|
+
} from "../index-p3kwf73n.js";
|
|
14
13
|
import {
|
|
15
14
|
createAuthHook,
|
|
16
15
|
createBearerResolver,
|
|
@@ -23,7 +22,7 @@ import {
|
|
|
23
22
|
signJwt,
|
|
24
23
|
verifyJwt,
|
|
25
24
|
verifyPkce
|
|
26
|
-
} from "../index-
|
|
25
|
+
} from "../index-bgdd42pt.js";
|
|
27
26
|
import {
|
|
28
27
|
DEFAULT_CORS_ALLOW_HEADERS,
|
|
29
28
|
DEFAULT_CORS_EXPOSE_HEADERS,
|
|
@@ -33,7 +32,7 @@ import {
|
|
|
33
32
|
import {
|
|
34
33
|
jsonSchemaFields,
|
|
35
34
|
toJsonSchema
|
|
36
|
-
} from "../index-
|
|
35
|
+
} from "../index-frfyw9fa.js";
|
|
37
36
|
import {
|
|
38
37
|
isWithinDir
|
|
39
38
|
} from "../index-x3fcszf8.js";
|
|
@@ -59,7 +58,28 @@ import {
|
|
|
59
58
|
resolveTraceId,
|
|
60
59
|
unauthorized,
|
|
61
60
|
zodIssues
|
|
62
|
-
} from "../index-
|
|
61
|
+
} from "../index-mzx0an0s.js";
|
|
62
|
+
// src/server/bun.ts
|
|
63
|
+
function createServer(config) {
|
|
64
|
+
const { routes, websocket, development, bun: bunExtra, port = 3000, hostname } = config;
|
|
65
|
+
const handler = createHandler(config);
|
|
66
|
+
const fetch = config.wrapFetch ? config.wrapFetch(handler) : handler;
|
|
67
|
+
return websocket ? Bun.serve({
|
|
68
|
+
...bunExtra,
|
|
69
|
+
...routes && { routes },
|
|
70
|
+
...development && { development },
|
|
71
|
+
port,
|
|
72
|
+
hostname,
|
|
73
|
+
websocket,
|
|
74
|
+
fetch
|
|
75
|
+
}) : Bun.serve({
|
|
76
|
+
...bunExtra,
|
|
77
|
+
...development && { development },
|
|
78
|
+
port,
|
|
79
|
+
hostname,
|
|
80
|
+
fetch
|
|
81
|
+
});
|
|
82
|
+
}
|
|
63
83
|
// src/server/swept-map.ts
|
|
64
84
|
function createSweptMap(options) {
|
|
65
85
|
const store = new Map;
|
|
@@ -402,7 +422,13 @@ function generateOpenApiDocument(config) {
|
|
|
402
422
|
const servicePath = joinPath("/", service.prefix, method.path === "/" ? "" : method.path);
|
|
403
423
|
const fullPath = toOpenApiPath(pathPrefix ? joinPath(pathPrefix, servicePath) : servicePath);
|
|
404
424
|
const parameters = [];
|
|
425
|
+
const trailingWildcard = fullPath.endsWith("/*");
|
|
426
|
+
let wildcardSchema = { type: "string" };
|
|
405
427
|
for (const field of jsonSchemaFields(safeJson(method.paramsSchema, "input"))) {
|
|
428
|
+
if (trailingWildcard && field.name === "*") {
|
|
429
|
+
wildcardSchema = field.schema;
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
406
432
|
parameters.push({
|
|
407
433
|
name: field.name,
|
|
408
434
|
in: "path",
|
|
@@ -434,12 +460,12 @@ function generateOpenApiDocument(config) {
|
|
|
434
460
|
}
|
|
435
461
|
};
|
|
436
462
|
} else if (method.outputSchema) {
|
|
437
|
-
responses[
|
|
463
|
+
responses[String(method.responseMeta?.status ?? 200)] = {
|
|
438
464
|
description: "Success",
|
|
439
465
|
content: { "application/json": { schema: safeJson(method.outputSchema, "output") } }
|
|
440
466
|
};
|
|
441
467
|
} else {
|
|
442
|
-
responses[
|
|
468
|
+
responses[String(method.responseMeta?.status ?? 204)] = { description: "No content" };
|
|
443
469
|
}
|
|
444
470
|
const operation = {
|
|
445
471
|
summary: method.desc,
|
|
@@ -447,6 +473,14 @@ function generateOpenApiDocument(config) {
|
|
|
447
473
|
...parameters.length > 0 && { parameters },
|
|
448
474
|
responses
|
|
449
475
|
};
|
|
476
|
+
if (trailingWildcard) {
|
|
477
|
+
operation["x-stitchkit-trailing-wildcard"] = {
|
|
478
|
+
parameter: "*",
|
|
479
|
+
required: true,
|
|
480
|
+
schema: wildcardSchema,
|
|
481
|
+
description: "Matches zero or more trailing path segments and exposes their '/'-joined remainder as params['*']."
|
|
482
|
+
};
|
|
483
|
+
}
|
|
450
484
|
if (!inputInQuery && (method.inputSchema || method.multipart)) {
|
|
451
485
|
if (method.multipart) {
|
|
452
486
|
const inputJson = safeJson(method.inputSchema, "input");
|