spiceflow 1.9.1 → 1.10.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/LICENSE +21 -0
- package/README.md +1 -2
- package/dist/_node-server-unsupported.d.ts +5 -0
- package/dist/_node-server-unsupported.d.ts.map +1 -0
- package/dist/_node-server-unsupported.js +6 -0
- package/dist/_node-server.d.ts +7 -0
- package/dist/_node-server.d.ts.map +1 -0
- package/dist/_node-server.js +77 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/types.d.ts +2 -2
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client.test.js +2 -2
- package/dist/context.d.ts +3 -3
- package/dist/cors.d.ts +2 -2
- package/dist/cors.d.ts.map +1 -1
- package/dist/cors.js +5 -2
- package/dist/cors.test.js +2 -2
- package/dist/error.d.ts +0 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +0 -10
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/mcp-transport.d.ts +2 -2
- package/dist/mcp-transport.d.ts.map +1 -1
- package/dist/mcp-transport.js +1 -6
- package/dist/mcp.d.ts +3 -3
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +3 -3
- package/dist/middleware.test.js +8 -3
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +15 -2
- package/dist/openapi.test.js +8 -8
- package/dist/serialize.d.ts +2 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +9 -0
- package/dist/simple.benchmark.js +1 -1
- package/dist/spiceflow.d.ts +15 -8
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +27 -86
- package/dist/spiceflow.test.js +6 -4
- package/dist/static-node.d.ts +2 -2
- package/dist/static-node.d.ts.map +1 -1
- package/dist/static-node.js +1 -1
- package/dist/static.benchmark.js +2 -2
- package/dist/static.d.ts +1 -1
- package/dist/static.d.ts.map +1 -1
- package/dist/static.js +1 -1
- package/dist/stream.test.js +2 -2
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.test.js +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/zod.test.js +2 -2
- package/package.json +13 -12
- package/src/_node-server-unsupported.ts +20 -0
- package/src/_node-server.ts +115 -0
- package/src/client/index.ts +4 -4
- package/src/client/types.ts +47 -49
- package/src/client.test.ts +2 -3
- package/src/context.ts +3 -3
- package/src/cors.test.ts +11 -9
- package/src/cors.ts +7 -5
- package/src/error.ts +0 -12
- package/src/index.ts +3 -3
- package/src/mcp-transport.ts +2 -11
- package/src/mcp.ts +3 -4
- package/src/middleware.test.ts +19 -12
- package/src/openapi.test.ts +8 -8
- package/src/openapi.ts +20 -5
- package/src/serialize.ts +10 -0
- package/src/simple.benchmark.ts +1 -1
- package/src/spiceflow.test.ts +12 -10
- package/src/spiceflow.ts +67 -137
- package/src/static-node.ts +2 -2
- package/src/static.benchmark.ts +2 -2
- package/src/static.ts +2 -2
- package/src/stream.test.ts +2 -3
- package/src/types.test.ts +3 -3
- package/src/types.ts +18 -18
- package/src/zod.test.ts +2 -2
- package/dist/_node_utils.d.ts +0 -3
- package/dist/_node_utils.d.ts.map +0 -1
- package/dist/_node_utils.js +0 -2
- package/dist/_node_utils_browser.d.ts +0 -2
- package/dist/_node_utils_browser.d.ts.map +0 -1
- package/dist/_node_utils_browser.js +0 -3
- package/dist/mcp.test.d.ts +0 -2
- package/dist/mcp.test.d.ts.map +0 -1
- package/dist/mcp.test.js +0 -217
- package/src/_node_utils.ts +0 -2
- package/src/_node_utils_browser.ts +0 -3
- package/src/mcp.test.ts +0 -267
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tommy D. Rossi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -720,7 +720,6 @@ You can use bindings type safely using a .state method and then passing the stat
|
|
|
720
720
|
import { Spiceflow } from 'spiceflow'
|
|
721
721
|
import { z } from 'zod'
|
|
722
722
|
|
|
723
|
-
|
|
724
723
|
interface Env {
|
|
725
724
|
KV: KVNamespace
|
|
726
725
|
QUEUE: Queue
|
|
@@ -743,7 +742,7 @@ export default {
|
|
|
743
742
|
fetch(request: Request, env: Env, ctx: ExecutionContext) {
|
|
744
743
|
// Pass the env bindings to the app
|
|
745
744
|
return app.handle(request, { env })
|
|
746
|
-
}
|
|
745
|
+
},
|
|
747
746
|
}
|
|
748
747
|
```
|
|
749
748
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function listenForNode(app: unknown, port: number, hostname?: string): Promise<void>;
|
|
2
|
+
export declare function handleForNode(app: unknown, req: unknown, res: unknown, context?: {
|
|
3
|
+
state?: {} | undefined;
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=_node-server-unsupported.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_node-server-unsupported.d.ts","sourceRoot":"","sources":["../src/_node-server-unsupported.ts"],"names":[],"mappings":"AAAA,wBAAsB,aAAa,CACjC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAAkB,iBAK7B;AAED,wBAAsB,aAAa,CACjC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,EAAE,GAAG,SAAS,CAAA;CAAO,GACvC,OAAO,CAAC,IAAI,CAAC,CAIf"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export async function listenForNode(app, port, hostname = '0.0.0.0') {
|
|
2
|
+
throw new Error("Current runtime does not support the method 'listenForNode'. Consider using the method 'listen' or the method 'handle' with your runtime's server primitive.");
|
|
3
|
+
}
|
|
4
|
+
export async function handleForNode(app, req, res, context = {}) {
|
|
5
|
+
throw new Error("Current runtime does not support the method 'handleForNode'. Consider using the method 'handle' instead.");
|
|
6
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Server, type IncomingMessage, type ServerResponse } from 'node:http';
|
|
2
|
+
import { type Spiceflow } from './spiceflow.ts';
|
|
3
|
+
export declare function listenForNode(app: Spiceflow<any, any, any, any, any, any>, port: number, hostname?: string): Promise<Server<typeof IncomingMessage, typeof ServerResponse>>;
|
|
4
|
+
export declare function handleForNode(app: Spiceflow<any, any, any, any, any, any>, req: IncomingMessage, res: ServerResponse, context?: {
|
|
5
|
+
state?: {} | undefined;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=_node-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_node-server.d.ts","sourceRoot":"","sources":["../src/_node-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,cAAc,EAEpB,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,gBAAgB,CAAA;AAGjE,wBAAsB,aAAa,CACjC,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC5C,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,OAAO,eAAe,EAAE,OAAO,cAAc,CAAC,CAAC,CAkBhE;AAED,wBAAsB,aAAa,CACjC,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC5C,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,EAAE,GAAG,SAAS,CAAA;CAAO,GACvC,OAAO,CAAC,IAAI,CAAC,CA2Ef"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createServer, } from 'node:http';
|
|
2
|
+
import { SpiceflowRequest } from "./spiceflow.js";
|
|
3
|
+
import { superjsonSerialize } from "./serialize.js";
|
|
4
|
+
export async function listenForNode(app, port, hostname = '0.0.0.0') {
|
|
5
|
+
const server = createServer((req, res) => {
|
|
6
|
+
return app.handleForNode(req, res);
|
|
7
|
+
});
|
|
8
|
+
await new Promise((resolve) => {
|
|
9
|
+
server.listen(port, hostname, () => {
|
|
10
|
+
// We could print from what we take as arguments of `serve`, but by reading
|
|
11
|
+
// the `server` object, we can ensure that they are properly set.
|
|
12
|
+
const addressInfo = server.address();
|
|
13
|
+
const displayedHost = addressInfo.address === '0.0.0.0' ? 'localhost' : addressInfo.address;
|
|
14
|
+
console.log(`Listening on http://${displayedHost}:${addressInfo.port}`);
|
|
15
|
+
resolve(null);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
return server;
|
|
19
|
+
}
|
|
20
|
+
export async function handleForNode(app, req, res, context = {}) {
|
|
21
|
+
if (req?.['body']) {
|
|
22
|
+
throw new Error('req.body is defined, you should disable your framework body parser to be able to use the request in Spiceflow');
|
|
23
|
+
}
|
|
24
|
+
const abortController = new AbortController();
|
|
25
|
+
const { signal } = abortController;
|
|
26
|
+
req.on('error', (err) => {
|
|
27
|
+
abortController.abort();
|
|
28
|
+
});
|
|
29
|
+
req.on('aborted', (err) => {
|
|
30
|
+
abortController.abort();
|
|
31
|
+
});
|
|
32
|
+
res.on('close', function () {
|
|
33
|
+
let aborted = !res.writableFinished;
|
|
34
|
+
if (aborted) {
|
|
35
|
+
abortController.abort();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const url = new URL(req.url || '', `http://${req.headers.host || 'localhost'}`);
|
|
39
|
+
const typedRequest = new SpiceflowRequest(url.toString(), {
|
|
40
|
+
method: req.method,
|
|
41
|
+
headers: req.headers,
|
|
42
|
+
body: req.method !== 'GET' && req.method !== 'HEAD'
|
|
43
|
+
? new ReadableStream({
|
|
44
|
+
start(controller) {
|
|
45
|
+
req.on('data', (chunk) => {
|
|
46
|
+
controller.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
47
|
+
});
|
|
48
|
+
req.on('end', () => {
|
|
49
|
+
controller.close();
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
: null,
|
|
54
|
+
signal,
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
duplex: 'half',
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
const response = await app.handle(typedRequest, context);
|
|
60
|
+
res.writeHead(response.status, Object.fromEntries(response.headers.entries()));
|
|
61
|
+
if (response.body) {
|
|
62
|
+
const reader = response.body.getReader();
|
|
63
|
+
while (true) {
|
|
64
|
+
const { done, value } = await reader.read();
|
|
65
|
+
if (done)
|
|
66
|
+
break;
|
|
67
|
+
res.write(value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
res.end();
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error('Error handling request:', error);
|
|
74
|
+
res.statusCode = 500;
|
|
75
|
+
res.end(superjsonSerialize({ message: 'Internal Server Error' }));
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Spiceflow } from '../spiceflow.
|
|
2
|
-
import type { SpiceflowClient } from './types.
|
|
1
|
+
import type { Spiceflow } from '../spiceflow.ts';
|
|
2
|
+
import type { SpiceflowClient } from './types.ts';
|
|
3
3
|
export { SpiceflowClient };
|
|
4
4
|
interface SSEEvent {
|
|
5
5
|
event: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAIhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,CAAA;AA4G1B,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,GAAG,CAAA;IACT,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAED,qBAAa,iBAAkB,SAAQ,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC;;CAwBzE;AAED,wBAAuB,iBAAiB,CACtC,QAAQ,EAAE,QAAQ,GACjB,cAAc,CAAC,QAAQ,CAAC,CAmB1B;AAqSD,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAIhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,CAAA;AA4G1B,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,GAAG,CAAA;IACT,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAED,qBAAa,iBAAkB,SAAQ,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC;;CAwBzE;AAED,wBAAuB,iBAAiB,CACtC,QAAQ,EAAE,QAAQ,GACjB,cAAc,CAAC,QAAQ,CAAC,CAmB1B;AAqSD,eAAO,MAAM,qBAAqB,GAChC,KAAK,CAAC,GAAG,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAEzD,QAAQ,MAAM,GAAG,GAAG,EACpB,SAAQ,eAAe,CAAC,MAAW,KAClC,eAAe,CAAC,MAAM,CAAC,GAAG,CAa5B,CAAA"}
|
package/dist/client/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import superjson from 'superjson';
|
|
2
2
|
import { EventSourceParserStream } from 'eventsource-parser/stream';
|
|
3
|
-
import { SpiceflowFetchError } from
|
|
4
|
-
import { parseStringifiedValue } from
|
|
3
|
+
import { SpiceflowFetchError } from "./errors.js";
|
|
4
|
+
import { parseStringifiedValue } from "./utils.js";
|
|
5
5
|
const method = [
|
|
6
6
|
'get',
|
|
7
7
|
'post',
|
package/dist/client/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Spiceflow } from '../spiceflow.
|
|
2
|
-
import { SpiceflowFetchError } from './errors.
|
|
1
|
+
import type { Spiceflow } from '../spiceflow.ts';
|
|
2
|
+
import { SpiceflowFetchError } from './errors.ts';
|
|
3
3
|
export type Prettify<T> = {
|
|
4
4
|
[K in keyof T]: T[K];
|
|
5
5
|
} & {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,GAAG,EAAE,CAAA;AAEN,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAE3D,KAAK,KAAK,GAAG,IAAI,GAAG,QAAQ,CAAA;AAE5B,KAAK,oBAAoB,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAC5E,CAAC,IAAI,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,GAAG,GAC9C,UAAU,CAAC,CAAC,CAAC,GACb,UAAU,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,GAAG,EAAE,CAAA;AAEN,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GA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,GAAG,OAAO,CAAE,SAAQ,YAAY;QAC7D,IAAI,EAAE,IAAI,CAAA;QACV,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;KAC9B;IAED,MAAM,MAAM,OAAO,CACjB,CAAC,SAAS,MAAM,iBAAiB,EACjC,IAAI,GAAG,OAAO,IACZ,CAAC,SAAS,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAA;;CACjE;AAED,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,CAAA"}
|
package/dist/client.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { createSpiceflowClient } from
|
|
3
|
-
import { Spiceflow } from
|
|
2
|
+
import { createSpiceflowClient } from "./client/index.js";
|
|
3
|
+
import { Spiceflow } from "./spiceflow.js";
|
|
4
4
|
import { describe, expect, it } from 'vitest';
|
|
5
5
|
const app = new Spiceflow()
|
|
6
6
|
.get('/', () => 'a')
|
package/dist/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { redirect as Redirect } from './utils.
|
|
2
|
-
import type { RouteSchema, Prettify, ResolvePath, SingletonBase } from './types.
|
|
3
|
-
import { SpiceflowRequest } from './spiceflow.
|
|
1
|
+
import type { redirect as Redirect } from './utils.ts';
|
|
2
|
+
import type { RouteSchema, Prettify, ResolvePath, SingletonBase } from './types.ts';
|
|
3
|
+
import { SpiceflowRequest } from './spiceflow.ts';
|
|
4
4
|
export type ErrorContext<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
5
5
|
state: {};
|
|
6
6
|
derive: {};
|
package/dist/cors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MiddlewareHandler } from './types.
|
|
1
|
+
import { MiddlewareHandler } from './types.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Options for configuring CORS (Cross-Origin Resource Sharing) middleware.
|
|
4
4
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS MDN CORS documentation}
|
|
@@ -15,7 +15,7 @@ type CORSOptions = {
|
|
|
15
15
|
/** Configures the Access-Control-Allow-Credentials CORS header */
|
|
16
16
|
credentials?: boolean;
|
|
17
17
|
/** Configures the Access-Control-Expose-Headers CORS header */
|
|
18
|
-
exposeHeaders?: string[];
|
|
18
|
+
exposeHeaders?: string[] | boolean;
|
|
19
19
|
/** Configures browser and CDN caching duration for CORS preflight requests in seconds. Set to 0 to disable. */
|
|
20
20
|
cacheAge?: number;
|
|
21
21
|
};
|
package/dist/cors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C;;;GAGG;AACH,KAAK,WAAW,GAAG;IACjB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACzB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kEAAkE;IAClE,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C;;;GAGG;AACH,KAAK,WAAW,GAAG;IACjB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACzB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kEAAkE;IAClE,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAClC,+GAA+G;IAC/G,QAAQ,CAAC,EAAE,MAAM,CAAA;CAElB,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,UAAU,WAAW,KAAG,iBAiH5C,CAAA"}
|
package/dist/cors.js
CHANGED
|
@@ -3,8 +3,8 @@ export const cors = (options) => {
|
|
|
3
3
|
origin: '*',
|
|
4
4
|
allowMethods: ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH'],
|
|
5
5
|
allowHeaders: [],
|
|
6
|
-
exposeHeaders: [],
|
|
7
6
|
credentials: true,
|
|
7
|
+
exposeHeaders: true,
|
|
8
8
|
cacheAge: 21600, // 6 hours default
|
|
9
9
|
};
|
|
10
10
|
const opts = {
|
|
@@ -56,7 +56,10 @@ export const cors = (options) => {
|
|
|
56
56
|
if (opts.credentials) {
|
|
57
57
|
set('Access-Control-Allow-Credentials', 'true');
|
|
58
58
|
}
|
|
59
|
-
if (opts.exposeHeaders
|
|
59
|
+
if (opts.exposeHeaders === true) {
|
|
60
|
+
set('Access-Control-Expose-Headers', '*');
|
|
61
|
+
}
|
|
62
|
+
else if (opts.exposeHeaders && opts.exposeHeaders?.length) {
|
|
60
63
|
set('Access-Control-Expose-Headers', opts.exposeHeaders.join(','));
|
|
61
64
|
}
|
|
62
65
|
if (c.request.method === 'OPTIONS') {
|
package/dist/cors.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from 'vitest';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { cors } from
|
|
4
|
-
import { Spiceflow } from
|
|
3
|
+
import { cors } from "./cors.js";
|
|
4
|
+
import { Spiceflow } from "./spiceflow.js";
|
|
5
5
|
function request(path, method = 'GET') {
|
|
6
6
|
return new Request(`http://localhost/${path}`, {
|
|
7
7
|
method,
|
package/dist/error.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export declare const ERROR_CODE: unique symbol;
|
|
|
2
2
|
export type ERROR_CODE = typeof ERROR_CODE;
|
|
3
3
|
export declare const SPICEFLOW_RESPONSE: unique symbol;
|
|
4
4
|
export type SPICEFLOW_RESPONSE = typeof SPICEFLOW_RESPONSE;
|
|
5
|
-
export declare const isProduction: boolean;
|
|
6
5
|
export declare class ValidationError extends Error {
|
|
7
6
|
code: string;
|
|
8
7
|
status: number;
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,eAA+B,CAAA;AACtD,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAA;AAE1C,eAAO,MAAM,kBAAkB,eAA8B,CAAA;AAC7D,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAA;AAE1D,qBAAa,eAAgB,SAAQ,KAAK;IACxC,IAAI,SAAe;IACnB,MAAM,SAAM;CACb;AAED,qBAAa,UAAW,SAAQ,KAAK;IACnC,IAAI,SAAU;IACd,MAAM,SAAM;CACb;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,IAAI,SAA0B;IAC9B,MAAM,SAAM;CACb"}
|
package/dist/error.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
// ? Cloudflare worker support
|
|
2
|
-
const env =
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
typeof Bun !== 'undefined'
|
|
5
|
-
? // @ts-ignore
|
|
6
|
-
Bun.env
|
|
7
|
-
: typeof process !== 'undefined'
|
|
8
|
-
? process?.env
|
|
9
|
-
: undefined;
|
|
10
1
|
export const ERROR_CODE = Symbol('SpiceflowErrorCode');
|
|
11
2
|
export const SPICEFLOW_RESPONSE = Symbol('SpiceflowResponse');
|
|
12
|
-
export const isProduction = (env?.NODE_ENV ?? env?.ENV) === 'production';
|
|
13
3
|
export class ValidationError extends Error {
|
|
14
4
|
code = 'VALIDATION';
|
|
15
5
|
status = 422;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Spiceflow } from './spiceflow.
|
|
2
|
-
export type { AnySpiceflow } from './spiceflow.
|
|
3
|
-
export { InternalServerError, ParseError, ValidationError } from './error.
|
|
1
|
+
export { Spiceflow } from './spiceflow.ts';
|
|
2
|
+
export type { AnySpiceflow } from './spiceflow.ts';
|
|
3
|
+
export { InternalServerError, ParseError, ValidationError } from './error.ts';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Spiceflow } from
|
|
2
|
-
export { InternalServerError, ParseError, ValidationError } from
|
|
1
|
+
export { Spiceflow } from "./spiceflow.js";
|
|
2
|
+
export { InternalServerError, ParseError, ValidationError } from "./error.js";
|
package/dist/mcp-transport.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.
|
|
1
|
+
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.ts';
|
|
2
2
|
import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests.
|
|
@@ -28,7 +28,7 @@ export declare class SSEServerTransportSpiceflow implements Transport {
|
|
|
28
28
|
*
|
|
29
29
|
* This should be called when a POST request is made to send a message to the server.
|
|
30
30
|
*/
|
|
31
|
-
handlePostMessage(req: Request
|
|
31
|
+
handlePostMessage(req: Request): Promise<Response>;
|
|
32
32
|
/**
|
|
33
33
|
* Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.
|
|
34
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-transport.d.ts","sourceRoot":"","sources":["../src/mcp-transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAA;AAC9E,OAAO,EACL,cAAc,EAEf,MAAM,oCAAoC,CAAA;AAE3C;;;;GAIG;AAEH,qBAAa,2BAA4B,YAAW,SAAS;IAC3D,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,eAAe,CAAC,CAAyC;IACjE,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAEnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAChC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAA;IAE7C;;OAEG;gBACS,QAAQ,EAAE,MAAM;IAK5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-transport.d.ts","sourceRoot":"","sources":["../src/mcp-transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAA;AAC9E,OAAO,EACL,cAAc,EAEf,MAAM,oCAAoC,CAAA;AAE3C;;;;GAIG;AAEH,qBAAa,2BAA4B,YAAW,SAAS;IAC3D,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,eAAe,CAAC,CAAyC;IACjE,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAEnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAChC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAA;IAE7C;;OAEG;gBACS,QAAQ,EAAE,MAAM;IAK5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAiC5B;;;;OAIG;IACG,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAmBxD;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAY9C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAalD;;;;OAIG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;CACF"}
|
package/dist/mcp-transport.js
CHANGED
|
@@ -43,18 +43,13 @@ export class SSEServerTransportSpiceflow {
|
|
|
43
43
|
// Obtain a writer from the writable end
|
|
44
44
|
this._writableStream = writable.getWriter();
|
|
45
45
|
this._writableStream?.write(new TextEncoder().encode(`event: endpoint\ndata: ${encodeURI(this._endpoint)}?sessionId=${this._sessionId}\n\n`));
|
|
46
|
-
// readable.getReader().closed.then(() => {
|
|
47
|
-
// this.response = undefined
|
|
48
|
-
// this._writableStream = undefined
|
|
49
|
-
// this.onclose?.()
|
|
50
|
-
// })
|
|
51
46
|
}
|
|
52
47
|
/**
|
|
53
48
|
* Handles incoming POST messages.
|
|
54
49
|
*
|
|
55
50
|
* This should be called when a POST request is made to send a message to the server.
|
|
56
51
|
*/
|
|
57
|
-
async handlePostMessage(req
|
|
52
|
+
async handlePostMessage(req) {
|
|
58
53
|
if (!this.response) {
|
|
59
54
|
const message = 'SSE connection not established';
|
|
60
55
|
throw new Error(message);
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Spiceflow } from './spiceflow.
|
|
1
|
+
import { Spiceflow } from './spiceflow.ts';
|
|
2
2
|
export declare const mcp: <Path extends string = "/mcp">({ path, name, version, }?: {
|
|
3
3
|
path?: Path | undefined;
|
|
4
4
|
name?: string | undefined;
|
|
@@ -35,10 +35,10 @@ export declare const mcp: <Path extends string = "/mcp">({ path, name, version,
|
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
|
-
} & import("./types.
|
|
38
|
+
} & import("./types.ts").CreateClient<`${Path extends "/" ? "/index" : Path extends "" ? Path : Path extends `/${string}` ? Path : Path}`, {
|
|
39
39
|
get: {
|
|
40
40
|
body: unknown;
|
|
41
|
-
params: { [Param in import("./types.
|
|
41
|
+
params: { [Param in import("./types.ts").GetPathParameter<Path> as Param extends `${string}?` ? never : Param]: string; } & { [Param_1 in import("./types.ts").GetPathParameter<Path> as Param_1 extends `${infer OptionalParam}?` ? OptionalParam : never]?: string | undefined; } extends infer T ? { [K in keyof T]: ({ [Param in import("./types.ts").GetPathParameter<Path> as Param extends `${string}?` ? never : Param]: string; } & { [Param_1 in import("./types.ts").GetPathParameter<Path> as Param_1 extends `${infer OptionalParam}?` ? OptionalParam : never]?: string | undefined; })[K]; } : never;
|
|
42
42
|
query: unknown;
|
|
43
43
|
response: {
|
|
44
44
|
[x: number]: any;
|
package/dist/mcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AA2Q1C,eAAO,MAAM,GAAG,GAAI,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE;;;;CAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDL,CAAA"}
|
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
2
|
import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
-
import { SSEServerTransportSpiceflow } from
|
|
4
|
-
import { openapi } from
|
|
5
|
-
import { Spiceflow } from
|
|
3
|
+
import { SSEServerTransportSpiceflow } from "./mcp-transport.js";
|
|
4
|
+
import { openapi } from "./openapi.js";
|
|
5
|
+
import { Spiceflow } from "./spiceflow.js";
|
|
6
6
|
const transports = new Map();
|
|
7
7
|
function getOperationRequestBody(operation) {
|
|
8
8
|
if (!operation.requestBody)
|
package/dist/middleware.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect, test } from 'vitest';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { Spiceflow } from
|
|
3
|
+
import { Spiceflow } from "./spiceflow.js";
|
|
4
4
|
test('middleware with next changes the response', async () => {
|
|
5
5
|
const res = await new Spiceflow()
|
|
6
6
|
.use(async ({ request }, next) => {
|
|
@@ -321,7 +321,12 @@ test('each middleware and route is called exactly once if an error is thrown', a
|
|
|
321
321
|
const res = await app.handle(new Request('http://localhost/test'));
|
|
322
322
|
expect(res.status).toBe(500);
|
|
323
323
|
expect(await res.text()).toMatchInlineSnapshot(`"{"message":"Route response"}"`);
|
|
324
|
-
expect(callOrder).toEqual([
|
|
324
|
+
expect(callOrder).toEqual([
|
|
325
|
+
'middleware1',
|
|
326
|
+
'middleware2',
|
|
327
|
+
'middleware3',
|
|
328
|
+
'route',
|
|
329
|
+
]);
|
|
325
330
|
// Check that each middleware and route is called exactly once
|
|
326
331
|
const counts = callOrder.reduce((acc, item) => {
|
|
327
332
|
acc[item] = (acc[item] || 0) + 1;
|
|
@@ -331,6 +336,6 @@ test('each middleware and route is called exactly once if an error is thrown', a
|
|
|
331
336
|
middleware1: 1,
|
|
332
337
|
middleware2: 1,
|
|
333
338
|
middleware3: 1,
|
|
334
|
-
route: 1
|
|
339
|
+
route: 1,
|
|
335
340
|
});
|
|
336
341
|
});
|
package/dist/openapi.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Spiceflow } from './spiceflow.
|
|
1
|
+
import { Spiceflow } from './spiceflow.ts';
|
|
2
2
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
3
3
|
export declare const openapi: <Path extends string = "/openapi">({ path, ...additional }?: {
|
|
4
4
|
path?: Path;
|
|
@@ -24,10 +24,10 @@ export declare const openapi: <Path extends string = "/openapi">({ path, ...addi
|
|
|
24
24
|
schema: {};
|
|
25
25
|
macro: {};
|
|
26
26
|
macroFn: {};
|
|
27
|
-
}, {} & import("./types.
|
|
27
|
+
}, {} & import("./types.ts").CreateClient<`${Path extends "/" ? "/index" : Path extends "" ? Path : Path extends `/${string}` ? Path : Path}`, {
|
|
28
28
|
get: {
|
|
29
29
|
body: unknown;
|
|
30
|
-
params: { [Param in import("./types.
|
|
30
|
+
params: { [Param in import("./types.ts").GetPathParameter<Path> as Param extends `${string}?` ? never : Param]: string; } & { [Param_1 in import("./types.ts").GetPathParameter<Path> as Param_1 extends `${infer OptionalParam}?` ? OptionalParam : never]?: string | undefined; } extends infer T ? { [K in keyof T]: ({ [Param in import("./types.ts").GetPathParameter<Path> as Param extends `${string}?` ? never : Param]: string; } & { [Param_1 in import("./types.ts").GetPathParameter<Path> as Param_1 extends `${infer OptionalParam}?` ? OptionalParam : never]?: string | undefined; })[K]; } : never;
|
|
31
31
|
query: unknown;
|
|
32
32
|
response: {
|
|
33
33
|
[x: number]: any;
|
package/dist/openapi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AA4V9C,eAAO,MAAM,OAAO,GAAI,IAAI,SAAS,MAAM,GAAG,UAAU,EAAE,0BAGvD;IACD,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,GAAG,IAAI,CACN,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,EACzB,yCAAyC,GACzC,qCAAqC,CACxC,GAAG;IACA,uBAAuB,CAAC,EAAE,KAAK,CAAC;QAC9B,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CAAC,CAAA;IACF,gBAAgB,CAAC,EAAE;QACjB,OAAO,EAAE;YACP,MAAM,EAAE,MAAM,CAAA;YACd,OAAO,EAAE,MAAM,CAAA;YACf,MAAM,EAAE,MAAM,EAAE,CAAA;SACjB,CAAA;KACF,CAAA;CACG;;;;;;;;;;;;;;;;;;;GAkFP,CAAA"}
|
package/dist/openapi.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isZodSchema, Spiceflow } from
|
|
1
|
+
import { isZod4, isZodSchema, Spiceflow } from "./spiceflow.js";
|
|
2
2
|
let excludeMethods = ['OPTIONS'];
|
|
3
|
-
import { z } from 'zod';
|
|
4
3
|
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
4
|
+
import { z } from 'zod/v4';
|
|
5
5
|
const extractParamNames = (path) => {
|
|
6
6
|
return path.split('/').reduce((params, segment) => {
|
|
7
7
|
if (segment.startsWith(':')) {
|
|
@@ -326,6 +326,19 @@ export const openapi = ({ path = '/openapi', ...additional } = {}) => {
|
|
|
326
326
|
function getJsonSchema(schema) {
|
|
327
327
|
if (!schema)
|
|
328
328
|
return undefined;
|
|
329
|
+
if (isZod4(schema)) {
|
|
330
|
+
let jsonSchema = z.toJSONSchema(schema, {
|
|
331
|
+
override(ctx) {
|
|
332
|
+
const schema = ctx.zodSchema;
|
|
333
|
+
if (schema instanceof z.core.$ZodObject &&
|
|
334
|
+
schema._zod.def.catchall === undefined) {
|
|
335
|
+
delete ctx.jsonSchema.additionalProperties;
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
const { $schema, ...rest } = jsonSchema;
|
|
340
|
+
return rest;
|
|
341
|
+
}
|
|
329
342
|
if (isZodSchema(schema)) {
|
|
330
343
|
let jsonSchema = zodToJsonSchema(schema, {
|
|
331
344
|
removeAdditionalStrategy: 'strict',
|
package/dist/openapi.test.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { expect, test } from 'vitest';
|
|
2
|
-
import { Spiceflow } from './spiceflow.js';
|
|
3
|
-
import { openapi } from './openapi.js';
|
|
4
2
|
import { z } from 'zod';
|
|
3
|
+
import { z as z4 } from 'zod/v4';
|
|
4
|
+
import { openapi } from "./openapi.js";
|
|
5
|
+
import { Spiceflow } from "./spiceflow.js";
|
|
5
6
|
test('openapi response', async () => {
|
|
6
|
-
const app =
|
|
7
|
+
const app = new Spiceflow()
|
|
7
8
|
.use(openapi({
|
|
8
9
|
info: {
|
|
9
10
|
title: 'Spiceflow Docs',
|
|
@@ -30,8 +31,8 @@ test('openapi response', async () => {
|
|
|
30
31
|
let body = await c.request.json();
|
|
31
32
|
return body;
|
|
32
33
|
}, {
|
|
33
|
-
body:
|
|
34
|
-
name:
|
|
34
|
+
body: z4.object({
|
|
35
|
+
name: z4.string(),
|
|
35
36
|
}),
|
|
36
37
|
response: z.object({
|
|
37
38
|
name: z.string().optional(),
|
|
@@ -109,8 +110,8 @@ test('openapi response', async () => {
|
|
|
109
110
|
type: 'multipart/form-data',
|
|
110
111
|
})
|
|
111
112
|
.use(new Spiceflow({ basePath: '/two' }).get('/ids/:id', ({ params }) => params.id, {
|
|
112
|
-
params:
|
|
113
|
-
id:
|
|
113
|
+
params: z4.object({
|
|
114
|
+
id: z4.string(),
|
|
114
115
|
}),
|
|
115
116
|
}));
|
|
116
117
|
const openapiSchema = await app
|
|
@@ -202,7 +203,6 @@ test('openapi response', async () => {
|
|
|
202
203
|
"content": {
|
|
203
204
|
"application/json": {
|
|
204
205
|
"schema": {
|
|
205
|
-
"additionalProperties": true,
|
|
206
206
|
"properties": {
|
|
207
207
|
"name": {
|
|
208
208
|
"type": "string",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,UAAQ,UAO5D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import superjson from 'superjson';
|
|
2
|
+
export function superjsonSerialize(value, indent = false) {
|
|
3
|
+
// return JSON.stringify(value)
|
|
4
|
+
const { json, meta } = superjson.serialize(value);
|
|
5
|
+
if (json && meta) {
|
|
6
|
+
json['__superjsonMeta'] = meta;
|
|
7
|
+
}
|
|
8
|
+
return JSON.stringify(json ?? null, null, indent ? 2 : undefined);
|
|
9
|
+
}
|
package/dist/simple.benchmark.js
CHANGED