spiceflow 1.0.0 → 1.0.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 +147 -0
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +5 -5
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +4 -5
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/ws.d.ts +4 -4
- package/dist/client/ws.d.ts.map +1 -1
- package/dist/client/ws.js.map +1 -1
- package/dist/client.test.js +9 -8
- package/dist/client.test.js.map +1 -1
- package/dist/elysia-fork/error.d.ts +5 -65
- package/dist/elysia-fork/error.d.ts.map +1 -1
- package/dist/elysia-fork/error.js +2 -2
- package/dist/elysia-fork/error.js.map +1 -1
- package/dist/elysia-fork/types.d.ts +27 -116
- package/dist/elysia-fork/types.d.ts.map +1 -1
- package/dist/elysia-fork/types.js +1 -2
- package/dist/elysia-fork/types.js.map +1 -1
- package/dist/elysia-fork/utils.d.ts +1 -62
- package/dist/elysia-fork/utils.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi.d.ts +68 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +250 -0
- package/dist/openapi.js.map +1 -0
- package/dist/spiceflow.d.ts +48 -52
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +148 -87
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js +80 -43
- package/dist/spiceflow.test.js.map +1 -1
- package/dist/stream.test.js +14 -14
- package/dist/stream.test.js.map +1 -1
- package/dist/zod.test.d.ts +2 -0
- package/dist/zod.test.d.ts.map +1 -0
- package/dist/zod.test.js +59 -0
- package/dist/zod.test.js.map +1 -0
- package/package.json +7 -4
- package/src/client/index.ts +10 -8
- package/src/client/types.ts +4 -4
- package/src/client/ws.ts +4 -4
- package/src/client.test.ts +9 -8
- package/src/elysia-fork/context.ts +2 -2
- package/src/elysia-fork/error.ts +3 -3
- package/src/elysia-fork/types.ts +108 -284
- package/src/index.ts +2 -0
- package/src/openapi.ts +426 -0
- package/src/spiceflow.test.ts +117 -64
- package/src/spiceflow.ts +261 -179
- package/src/stream.test.ts +14 -14
- package/src/zod.test.ts +71 -0
package/src/client/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/* eslint-disable no-extra-semi */
|
|
2
2
|
/* eslint-disable no-case-declarations */
|
|
3
3
|
/* eslint-disable prefer-const */
|
|
4
|
-
import type {
|
|
4
|
+
import type { Spiceflow } from '../spiceflow'
|
|
5
5
|
import { EventSourceParserStream } from 'eventsource-parser/stream'
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type { SpiceflowClient } from './types'
|
|
8
|
+
|
|
9
|
+
export { SpiceflowClient }
|
|
8
10
|
|
|
9
11
|
import { EdenFetchError } from './errors'
|
|
10
12
|
// import { EdenWS } from './ws'
|
|
@@ -181,7 +183,7 @@ const createProxy = (
|
|
|
181
183
|
domain: string,
|
|
182
184
|
config: SpiceflowClient.Config,
|
|
183
185
|
paths: string[] = [],
|
|
184
|
-
|
|
186
|
+
instance?: Spiceflow<any, any, any, any, any, any>
|
|
185
187
|
): any =>
|
|
186
188
|
new Proxy(() => {}, {
|
|
187
189
|
get(_, param: string): any {
|
|
@@ -189,7 +191,7 @@ const createProxy = (
|
|
|
189
191
|
domain,
|
|
190
192
|
config,
|
|
191
193
|
param === 'index' ? paths : [...paths, param],
|
|
192
|
-
|
|
194
|
+
instance
|
|
193
195
|
)
|
|
194
196
|
},
|
|
195
197
|
apply(_, __, [body, options]) {
|
|
@@ -413,7 +415,7 @@ const createProxy = (
|
|
|
413
415
|
}
|
|
414
416
|
|
|
415
417
|
const url = domain + path + q
|
|
416
|
-
const response = await (
|
|
418
|
+
const response = await (instance?.handle(
|
|
417
419
|
new Request(url, fetchInit)
|
|
418
420
|
) ?? fetcher!(url, fetchInit))
|
|
419
421
|
|
|
@@ -501,7 +503,7 @@ const createProxy = (
|
|
|
501
503
|
domain,
|
|
502
504
|
config,
|
|
503
505
|
[...paths, Object.values(body)[0] as string],
|
|
504
|
-
|
|
506
|
+
instance
|
|
505
507
|
)
|
|
506
508
|
|
|
507
509
|
return createProxy(domain, config, paths)
|
|
@@ -509,7 +511,7 @@ const createProxy = (
|
|
|
509
511
|
}) as any
|
|
510
512
|
|
|
511
513
|
export const createSpiceflowClient = <
|
|
512
|
-
const App extends
|
|
514
|
+
const App extends Spiceflow<any, any, any, any, any, any, any, any>
|
|
513
515
|
>(
|
|
514
516
|
domain: string | App,
|
|
515
517
|
config: SpiceflowClient.Config = {}
|
|
@@ -530,7 +532,7 @@ export const createSpiceflowClient = <
|
|
|
530
532
|
|
|
531
533
|
if (typeof window !== 'undefined')
|
|
532
534
|
console.warn(
|
|
533
|
-
'
|
|
535
|
+
'Spiceflow instance server found on client side, this is not recommended for security reason. Use generic type instead.'
|
|
534
536
|
)
|
|
535
537
|
|
|
536
538
|
return createProxy('http://e.ly', config, [], domain)
|
package/src/client/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { Spiceflow } from '../spiceflow'
|
|
3
3
|
// import { EdenWS } from './ws'
|
|
4
4
|
// import type { IsNever, Not, Prettify } from '../types'
|
|
5
5
|
import { EdenFetchError } from './errors'
|
|
@@ -56,18 +56,18 @@ type ReplaceGeneratorWithAsyncGenerator<
|
|
|
56
56
|
type MaybeArray<T> = T | T[]
|
|
57
57
|
type MaybePromise<T> = T | Promise<T>
|
|
58
58
|
|
|
59
|
-
export namespace
|
|
59
|
+
export namespace SpiceflowClient {
|
|
60
60
|
interface TreatyParam {
|
|
61
61
|
fetch?: RequestInit
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export type Create<
|
|
65
|
-
App extends
|
|
65
|
+
App extends Spiceflow<any, any, any, any, any, any, any, any>
|
|
66
66
|
> = App extends {
|
|
67
67
|
_routes: infer Schema extends Record<string, any>
|
|
68
68
|
}
|
|
69
69
|
? Prettify<Sign<Schema>>
|
|
70
|
-
: 'Please install
|
|
70
|
+
: 'Please install Spiceflow before using Eden'
|
|
71
71
|
|
|
72
72
|
export type Sign<in out Route extends Record<string, any>> = {
|
|
73
73
|
[K in keyof Route as K extends `:${string}`
|
package/src/client/ws.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { InputSchema } from '../elysia-fork/types'
|
|
2
|
-
import type {
|
|
2
|
+
import type { SpiceflowClient } from './types'
|
|
3
3
|
import { parseStringifiedValue } from './utils'
|
|
4
4
|
|
|
5
5
|
export class EdenWS<in out Schema extends InputSchema<any> = {}> {
|
|
@@ -25,7 +25,7 @@ export class EdenWS<in out Schema extends InputSchema<any> = {}> {
|
|
|
25
25
|
|
|
26
26
|
on<K extends keyof WebSocketEventMap>(
|
|
27
27
|
type: K,
|
|
28
|
-
listener: (event:
|
|
28
|
+
listener: (event: SpiceflowClient.WSEvent<K, Schema['response']>) => void,
|
|
29
29
|
options?: boolean | AddEventListenerOptions
|
|
30
30
|
) {
|
|
31
31
|
return this.addEventListener(type, listener, options)
|
|
@@ -43,7 +43,7 @@ export class EdenWS<in out Schema extends InputSchema<any> = {}> {
|
|
|
43
43
|
|
|
44
44
|
subscribe(
|
|
45
45
|
onMessage: (
|
|
46
|
-
event:
|
|
46
|
+
event: SpiceflowClient.WSEvent<'message', Schema['response']>
|
|
47
47
|
) => void,
|
|
48
48
|
options?: boolean | AddEventListenerOptions
|
|
49
49
|
) {
|
|
@@ -52,7 +52,7 @@ export class EdenWS<in out Schema extends InputSchema<any> = {}> {
|
|
|
52
52
|
|
|
53
53
|
addEventListener<K extends keyof WebSocketEventMap>(
|
|
54
54
|
type: K,
|
|
55
|
-
listener: (event:
|
|
55
|
+
listener: (event: SpiceflowClient.WSEvent<K, Schema['response']>) => void,
|
|
56
56
|
options?: boolean | AddEventListenerOptions
|
|
57
57
|
) {
|
|
58
58
|
this.ws.addEventListener(
|
package/src/client.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSpiceflowClient } from './client'
|
|
2
|
-
import {
|
|
2
|
+
import { Spiceflow, t } from './spiceflow'
|
|
3
3
|
|
|
4
4
|
import { describe, expect, it } from 'vitest'
|
|
5
5
|
|
|
@@ -21,7 +21,7 @@ const randomArray = [
|
|
|
21
21
|
{ a: 'a', b: 2, c: true, d: false, e: null, f: new Date(0) }
|
|
22
22
|
]
|
|
23
23
|
|
|
24
|
-
const app = new
|
|
24
|
+
const app = new Spiceflow()
|
|
25
25
|
.get('/', () => 'a')
|
|
26
26
|
.post('/', () => 'a')
|
|
27
27
|
.get('/number', () => 1)
|
|
@@ -42,7 +42,7 @@ const app = new Elysia()
|
|
|
42
42
|
})
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
.use(new
|
|
45
|
+
.use(new Spiceflow({ basePath: '/nested' }).get('/data', ({ params }) => 'hi'))
|
|
46
46
|
// .get('/error', ({ error }) => error("I'm a teapot", 'Kirifuji Nagisa'), {
|
|
47
47
|
// response: {
|
|
48
48
|
// 200: t.Void(),
|
|
@@ -65,11 +65,12 @@ const app = new Elysia()
|
|
|
65
65
|
}
|
|
66
66
|
)
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
})
|
|
68
|
+
// TODO ajv does not accept dates for some reason
|
|
69
|
+
// .post('/date', ({ body: { date } }) => date, {
|
|
70
|
+
// body: t.Object({
|
|
71
|
+
// date: t.Date()
|
|
72
|
+
// })
|
|
73
|
+
// })
|
|
73
74
|
.get('/dateObject', () => ({ date: new Date() }))
|
|
74
75
|
.get('/redirect', ({ redirect }) => redirect('http://localhost:8083/true'))
|
|
75
76
|
.post(
|
|
@@ -99,7 +99,7 @@ export type Context<
|
|
|
99
99
|
// *
|
|
100
100
|
// * @example Migration example
|
|
101
101
|
// * ```ts
|
|
102
|
-
// * new
|
|
102
|
+
// * new Spiceflow()
|
|
103
103
|
// * .get(({ redirect }) => redirect('/'))
|
|
104
104
|
// * ```
|
|
105
105
|
// */
|
|
@@ -109,7 +109,7 @@ export type Context<
|
|
|
109
109
|
// *
|
|
110
110
|
// * Use `Context.cookie` instead
|
|
111
111
|
// */
|
|
112
|
-
// cookie?: Record<string,
|
|
112
|
+
// cookie?: Record<string, SpiceflowCookie>
|
|
113
113
|
// }
|
|
114
114
|
|
|
115
115
|
/**
|
package/src/elysia-fork/error.ts
CHANGED
|
@@ -14,15 +14,15 @@ const env =
|
|
|
14
14
|
? process?.env
|
|
15
15
|
: undefined
|
|
16
16
|
|
|
17
|
-
export const ERROR_CODE = Symbol('
|
|
17
|
+
export const ERROR_CODE = Symbol('SpiceflowErrorCode')
|
|
18
18
|
export type ERROR_CODE = typeof ERROR_CODE
|
|
19
19
|
|
|
20
|
-
export const ELYSIA_RESPONSE = Symbol('
|
|
20
|
+
export const ELYSIA_RESPONSE = Symbol('SpiceflowResponse')
|
|
21
21
|
export type ELYSIA_RESPONSE = typeof ELYSIA_RESPONSE
|
|
22
22
|
|
|
23
23
|
export const isProduction = (env?.NODE_ENV ?? env?.ENV) === 'production'
|
|
24
24
|
|
|
25
|
-
export type
|
|
25
|
+
export type SpiceflowErrors =
|
|
26
26
|
| InternalServerError
|
|
27
27
|
| NotFoundError
|
|
28
28
|
| ParseError
|