spiceflow 1.6.1 → 1.6.2
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 +73 -7
- package/dist/client.test.js +11 -4
- package/dist/client.test.js.map +1 -1
- package/dist/cors.d.ts.map +1 -1
- package/dist/cors.js +13 -2
- package/dist/cors.js.map +1 -1
- package/dist/error.d.ts +2 -2
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +1 -1
- package/dist/error.js.map +1 -1
- package/dist/mcp.d.ts +12 -0
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +204 -147
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.test.js +4 -13
- package/dist/mcp.test.js.map +1 -1
- package/dist/openapi.d.ts +0 -5
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +0 -5
- package/dist/openapi.js.map +1 -1
- package/dist/openapi.test.js +2 -2
- package/dist/spiceflow.d.ts +2 -1
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +14 -2
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js +17 -1
- package/dist/spiceflow.test.js.map +1 -1
- package/dist/stream.test.js +20 -8
- package/dist/stream.test.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -2
- package/src/client.test.ts +11 -4
- package/src/cors.ts +17 -5
- package/src/error.ts +2 -2
- package/src/mcp.test.ts +4 -13
- package/src/mcp.ts +263 -178
- package/src/openapi.test.ts +2 -2
- package/src/openapi.ts +0 -5
- package/src/spiceflow.test.ts +20 -1
- package/src/spiceflow.ts +20 -4
- package/src/stream.test.ts +21 -8
- package/src/types.ts +4 -4
package/src/openapi.test.ts
CHANGED
|
@@ -243,7 +243,7 @@ test('openapi response', async () => {
|
|
|
243
243
|
"content": {
|
|
244
244
|
"application/json": {
|
|
245
245
|
"schema": {
|
|
246
|
-
"additionalProperties":
|
|
246
|
+
"additionalProperties": true,
|
|
247
247
|
"properties": {
|
|
248
248
|
"name": {
|
|
249
249
|
"type": "string",
|
|
@@ -456,7 +456,7 @@ test('openapi response', async () => {
|
|
|
456
456
|
"content": {
|
|
457
457
|
"application/json": {
|
|
458
458
|
"schema": {
|
|
459
|
-
"additionalProperties":
|
|
459
|
+
"additionalProperties": true,
|
|
460
460
|
"properties": {
|
|
461
461
|
"name": {
|
|
462
462
|
"type": "string",
|
package/src/openapi.ts
CHANGED
|
@@ -351,11 +351,6 @@ const registerSchemaPath = ({
|
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
/**
|
|
355
|
-
* Plugin for [elysia](https://github.com/elysiajs/elysia) that auto-generate Swagger page.
|
|
356
|
-
*
|
|
357
|
-
* @see https://github.com/elysiajs/elysia-swagger
|
|
358
|
-
*/
|
|
359
354
|
export const openapi = <Path extends string = '/openapi'>({
|
|
360
355
|
path = '/openapi' as Path,
|
|
361
356
|
...additional
|
package/src/spiceflow.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test, describe, expect } from 'vitest'
|
|
2
2
|
import { Type } from '@sinclair/typebox'
|
|
3
|
-
import { bfs, Spiceflow } from './spiceflow.js'
|
|
3
|
+
import { bfs, cloneDeep, Spiceflow } from './spiceflow.js'
|
|
4
4
|
import { z } from 'zod'
|
|
5
5
|
import { createSpiceflowClient } from './client/index.js'
|
|
6
6
|
|
|
@@ -11,6 +11,25 @@ test('works', async () => {
|
|
|
11
11
|
expect(res.status).toBe(200)
|
|
12
12
|
expect(await res.json()).toEqual('hi')
|
|
13
13
|
})
|
|
14
|
+
|
|
15
|
+
describe('cloneDeep', () => {
|
|
16
|
+
test('works on promises', async () => {
|
|
17
|
+
const obj = {
|
|
18
|
+
promise: Promise.resolve({ value: 'hi' }),
|
|
19
|
+
}
|
|
20
|
+
const res = cloneDeep(obj)
|
|
21
|
+
expect(res.promise).toBeInstanceOf(Promise)
|
|
22
|
+
expect(await res.promise).toEqual({ value: 'hi' })
|
|
23
|
+
// expect(await res.promise).not.toBe(await obj.promise)
|
|
24
|
+
expect(res).toMatchInlineSnapshot(`
|
|
25
|
+
{
|
|
26
|
+
"promise": Promise {},
|
|
27
|
+
}
|
|
28
|
+
`)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
|
|
14
33
|
test('can encode superjson types', async () => {
|
|
15
34
|
const app = new Spiceflow().post('/superjson', () => {
|
|
16
35
|
const item = {
|
package/src/spiceflow.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import addFormats from 'ajv-formats'
|
|
2
|
+
import lodashCloneDeep from 'lodash.clonedeep'
|
|
3
|
+
|
|
2
4
|
import superjson from 'superjson'
|
|
3
5
|
import {
|
|
4
6
|
ComposeSpiceflowResponse,
|
|
@@ -249,7 +251,7 @@ export class Spiceflow<
|
|
|
249
251
|
|
|
250
252
|
state<const Name extends string | number | symbol, Value>(
|
|
251
253
|
name: Name,
|
|
252
|
-
value
|
|
254
|
+
value?: Value,
|
|
253
255
|
): Spiceflow<
|
|
254
256
|
BasePath,
|
|
255
257
|
Scoped,
|
|
@@ -739,7 +741,7 @@ export class Spiceflow<
|
|
|
739
741
|
} = route
|
|
740
742
|
const middlewares = appsInScope.flatMap((x) => x.middlewares)
|
|
741
743
|
|
|
742
|
-
let state =
|
|
744
|
+
let state = cloneDeep(defaultState)
|
|
743
745
|
|
|
744
746
|
let content = route?.internalRoute?.hooks?.content
|
|
745
747
|
|
|
@@ -1031,7 +1033,18 @@ export class Spiceflow<
|
|
|
1031
1033
|
if (init instanceof Promise) init = await init
|
|
1032
1034
|
|
|
1033
1035
|
if (init?.done) {
|
|
1034
|
-
return
|
|
1036
|
+
return new Response(
|
|
1037
|
+
'event: message\ndata: ' +
|
|
1038
|
+
superjsonSerialize(init.value, false) +
|
|
1039
|
+
'\n\n' +
|
|
1040
|
+
'event: done\n\n',
|
|
1041
|
+
{
|
|
1042
|
+
headers: {
|
|
1043
|
+
'Content-Type': 'text/event-stream',
|
|
1044
|
+
'Cache-Control': 'no-cache',
|
|
1045
|
+
},
|
|
1046
|
+
},
|
|
1047
|
+
)
|
|
1035
1048
|
}
|
|
1036
1049
|
|
|
1037
1050
|
let self = this
|
|
@@ -1339,7 +1352,6 @@ function getValidateFunction(schema: TypeSchema) {
|
|
|
1339
1352
|
if (isZodSchema(schema)) {
|
|
1340
1353
|
let jsonSchema = zodToJsonSchema(schema, {
|
|
1341
1354
|
removeAdditionalStrategy: 'strict',
|
|
1342
|
-
|
|
1343
1355
|
})
|
|
1344
1356
|
return ajv.compile(jsonSchema)
|
|
1345
1357
|
}
|
|
@@ -1379,3 +1391,7 @@ function parseQuery(queryString: string) {
|
|
|
1379
1391
|
}
|
|
1380
1392
|
return paramsObject
|
|
1381
1393
|
}
|
|
1394
|
+
|
|
1395
|
+
export function cloneDeep(x) {
|
|
1396
|
+
return lodashCloneDeep(x)
|
|
1397
|
+
}
|
package/src/stream.test.ts
CHANGED
|
@@ -285,10 +285,16 @@ describe('Stream', () => {
|
|
|
285
285
|
app.handle(req('/json')),
|
|
286
286
|
])
|
|
287
287
|
|
|
288
|
-
|
|
289
|
-
expect(
|
|
290
|
-
|
|
291
|
-
|
|
288
|
+
const text = await response[0].text()
|
|
289
|
+
expect(text).toMatchInlineSnapshot(`
|
|
290
|
+
"event: message
|
|
291
|
+
data: "hello"
|
|
292
|
+
|
|
293
|
+
event: done
|
|
294
|
+
|
|
295
|
+
"
|
|
296
|
+
`)
|
|
297
|
+
expect(parseTextEventStreamItem(text)).toMatchInlineSnapshot(`"hello"`)
|
|
292
298
|
})
|
|
293
299
|
|
|
294
300
|
it('return async value if not yield', async () => {
|
|
@@ -305,10 +311,17 @@ describe('Stream', () => {
|
|
|
305
311
|
app.handle(req('/json')),
|
|
306
312
|
])
|
|
307
313
|
|
|
308
|
-
|
|
309
|
-
expect(
|
|
310
|
-
|
|
311
|
-
|
|
314
|
+
const text = await response[0].text()
|
|
315
|
+
expect(text).toMatchInlineSnapshot(`
|
|
316
|
+
"event: message
|
|
317
|
+
data: "hello"
|
|
318
|
+
|
|
319
|
+
event: done
|
|
320
|
+
|
|
321
|
+
"
|
|
322
|
+
`)
|
|
323
|
+
expect(parseTextEventStreamItem(text)).toMatchInlineSnapshot(`"hello"`)
|
|
324
|
+
|
|
312
325
|
})
|
|
313
326
|
|
|
314
327
|
it('handle object and array', async () => {
|
package/src/types.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { OpenAPIV3 } from 'openapi-types'
|
|
|
15
15
|
import { ZodObject, ZodTypeAny } from 'zod'
|
|
16
16
|
import type { Context, ErrorContext, MiddlewareContext } from './context.js'
|
|
17
17
|
import {
|
|
18
|
-
|
|
18
|
+
SPICEFLOW_RESPONSE,
|
|
19
19
|
InternalServerError,
|
|
20
20
|
ParseError,
|
|
21
21
|
ValidationError,
|
|
@@ -363,7 +363,7 @@ export type InlineHandler<
|
|
|
363
363
|
| {
|
|
364
364
|
[Status in keyof Route['response']]: {
|
|
365
365
|
_type: Record<Status, Route['response'][Status]>
|
|
366
|
-
[
|
|
366
|
+
[SPICEFLOW_RESPONSE]: Status
|
|
367
367
|
}
|
|
368
368
|
}[keyof Route['response']]
|
|
369
369
|
>
|
|
@@ -645,13 +645,13 @@ export type ComposeSpiceflowResponse<Response, Handle> = Handle extends (
|
|
|
645
645
|
type _ComposeSpiceflowResponse<Response, Handle> = Prettify<
|
|
646
646
|
{} extends Response
|
|
647
647
|
? {
|
|
648
|
-
200: Exclude<Handle, { [
|
|
648
|
+
200: Exclude<Handle, { [SPICEFLOW_RESPONSE]: any }>
|
|
649
649
|
} & {
|
|
650
650
|
[ErrorResponse in Extract<
|
|
651
651
|
Handle,
|
|
652
652
|
{ response: any }
|
|
653
653
|
> as ErrorResponse extends {
|
|
654
|
-
[
|
|
654
|
+
[SPICEFLOW_RESPONSE]: infer Status extends number
|
|
655
655
|
}
|
|
656
656
|
? Status
|
|
657
657
|
: never]: ErrorResponse['response']
|