spiceflow 1.0.0 → 1.0.1

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.
Files changed (42) hide show
  1. package/dist/client/index.d.ts +4 -3
  2. package/dist/client/index.d.ts.map +1 -1
  3. package/dist/client/index.js +5 -5
  4. package/dist/client/index.js.map +1 -1
  5. package/dist/client/types.d.ts +4 -4
  6. package/dist/client/types.d.ts.map +1 -1
  7. package/dist/client/ws.d.ts +4 -4
  8. package/dist/client/ws.d.ts.map +1 -1
  9. package/dist/client/ws.js.map +1 -1
  10. package/dist/client.test.js +3 -3
  11. package/dist/client.test.js.map +1 -1
  12. package/dist/elysia-fork/error.d.ts +1 -1
  13. package/dist/elysia-fork/error.d.ts.map +1 -1
  14. package/dist/elysia-fork/error.js +2 -2
  15. package/dist/elysia-fork/error.js.map +1 -1
  16. package/dist/elysia-fork/types.d.ts +14 -96
  17. package/dist/elysia-fork/types.d.ts.map +1 -1
  18. package/dist/elysia-fork/types.js.map +1 -1
  19. package/dist/index.d.ts +3 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +2 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/spiceflow.d.ts +22 -38
  24. package/dist/spiceflow.d.ts.map +1 -1
  25. package/dist/spiceflow.js +6 -22
  26. package/dist/spiceflow.js.map +1 -1
  27. package/dist/spiceflow.test.js +21 -21
  28. package/dist/spiceflow.test.js.map +1 -1
  29. package/dist/stream.test.js +14 -14
  30. package/dist/stream.test.js.map +1 -1
  31. package/package.json +1 -2
  32. package/src/client/index.ts +10 -8
  33. package/src/client/types.ts +4 -4
  34. package/src/client/ws.ts +4 -4
  35. package/src/client.test.ts +3 -3
  36. package/src/elysia-fork/context.ts +2 -2
  37. package/src/elysia-fork/error.ts +3 -3
  38. package/src/elysia-fork/types.ts +23 -124
  39. package/src/index.ts +2 -0
  40. package/src/spiceflow.test.ts +22 -22
  41. package/src/spiceflow.ts +40 -55
  42. package/src/stream.test.ts +14 -14
package/src/spiceflow.ts CHANGED
@@ -5,7 +5,7 @@ import { Type } from '@sinclair/typebox'
5
5
  export { Type as t }
6
6
 
7
7
  import {
8
- ComposeElysiaResponse,
8
+ ComposeSpiceflowResponse,
9
9
  CreateEden,
10
10
  DefinitionBase,
11
11
  EphemeralType,
@@ -65,7 +65,7 @@ type InternalRouterState = {
65
65
  /**
66
66
  * Router class
67
67
  */
68
- export class Elysia<
68
+ export class Spiceflow<
69
69
  const in out BasePath extends string = '',
70
70
  const in out Scoped extends boolean = true,
71
71
  const in out Singleton extends SingletonBase = {
@@ -159,7 +159,7 @@ export class Elysia<
159
159
  state<const Name extends string | number | symbol, Value>(
160
160
  name: Name,
161
161
  value: Value
162
- ): Elysia<
162
+ ): Spiceflow<
163
163
  BasePath,
164
164
  Scoped,
165
165
  {
@@ -230,22 +230,7 @@ export class Elysia<
230
230
  _ephemeral = {} as Ephemeral
231
231
  _volatile = {} as Volatile
232
232
 
233
- /**
234
- * ### post
235
- * Register handler for path with method [POST]
236
- *
237
- * ---
238
- * @example
239
- * ```typescript
240
- * import { Elysia, t } from 'elysia'
241
- *
242
- * new Elysia()
243
- * .post('/', () => 'hi')
244
- * .post('/with-hook', () => 'hi', {
245
- * response: t.String()
246
- * })
247
- * ```
248
- */
233
+
249
234
  post<
250
235
  const Path extends string,
251
236
  const LocalSchema extends InputSchema<
@@ -280,7 +265,7 @@ export class Elysia<
280
265
  Metadata['macro'],
281
266
  JoinPath<BasePath, Path>
282
267
  >
283
- ): Elysia<
268
+ ): Spiceflow<
284
269
  BasePath,
285
270
  Scoped,
286
271
  Singleton,
@@ -297,7 +282,7 @@ export class Elysia<
297
282
  : Schema['params']
298
283
  query: Schema['query']
299
284
  headers: Schema['headers']
300
- response: ComposeElysiaResponse<
285
+ response: ComposeSpiceflowResponse<
301
286
  Schema['response'],
302
287
  Handle
303
288
  >
@@ -347,7 +332,7 @@ export class Elysia<
347
332
  Macro,
348
333
  JoinPath<BasePath, Path>
349
334
  >
350
- ): Elysia<
335
+ ): Spiceflow<
351
336
  BasePath,
352
337
  Scoped,
353
338
  Singleton,
@@ -364,7 +349,7 @@ export class Elysia<
364
349
  : Schema['params']
365
350
  query: Schema['query']
366
351
  headers: Schema['headers']
367
- response: ComposeElysiaResponse<
352
+ response: ComposeSpiceflowResponse<
368
353
  Schema['response'],
369
354
  Handle
370
355
  >
@@ -412,7 +397,7 @@ export class Elysia<
412
397
  Metadata['macro'],
413
398
  JoinPath<BasePath, Path>
414
399
  >
415
- ): Elysia<
400
+ ): Spiceflow<
416
401
  BasePath,
417
402
  Scoped,
418
403
  Singleton,
@@ -429,7 +414,7 @@ export class Elysia<
429
414
  : Schema['params']
430
415
  query: Schema['query']
431
416
  headers: Schema['headers']
432
- response: ComposeElysiaResponse<
417
+ response: ComposeSpiceflowResponse<
433
418
  Schema['response'],
434
419
  Handle
435
420
  >
@@ -478,7 +463,7 @@ export class Elysia<
478
463
  Metadata['macro'],
479
464
  JoinPath<BasePath, Path>
480
465
  >
481
- ): Elysia<
466
+ ): Spiceflow<
482
467
  BasePath,
483
468
  Scoped,
484
469
  Singleton,
@@ -495,7 +480,7 @@ export class Elysia<
495
480
  : Schema['params']
496
481
  query: Schema['query']
497
482
  headers: Schema['headers']
498
- response: ComposeElysiaResponse<
483
+ response: ComposeSpiceflowResponse<
499
484
  Schema['response'],
500
485
  Handle
501
486
  >
@@ -544,7 +529,7 @@ export class Elysia<
544
529
  Metadata['macro'],
545
530
  JoinPath<BasePath, Path>
546
531
  >
547
- ): Elysia<
532
+ ): Spiceflow<
548
533
  BasePath,
549
534
  Scoped,
550
535
  Singleton,
@@ -561,7 +546,7 @@ export class Elysia<
561
546
  : Schema['params']
562
547
  query: Schema['query']
563
548
  headers: Schema['headers']
564
- response: ComposeElysiaResponse<
549
+ response: ComposeSpiceflowResponse<
565
550
  Schema['response'],
566
551
  Handle
567
552
  >
@@ -610,7 +595,7 @@ export class Elysia<
610
595
  Metadata['macro'],
611
596
  JoinPath<BasePath, Path>
612
597
  >
613
- ): Elysia<
598
+ ): Spiceflow<
614
599
  BasePath,
615
600
  Scoped,
616
601
  Singleton,
@@ -627,7 +612,7 @@ export class Elysia<
627
612
  : Schema['params']
628
613
  query: Schema['query']
629
614
  headers: Schema['headers']
630
- response: ComposeElysiaResponse<
615
+ response: ComposeSpiceflowResponse<
631
616
  Schema['response'],
632
617
  Handle
633
618
  >
@@ -676,7 +661,7 @@ export class Elysia<
676
661
  Metadata['macro'],
677
662
  JoinPath<BasePath, Path>
678
663
  >
679
- ): Elysia<
664
+ ): Spiceflow<
680
665
  BasePath,
681
666
  Scoped,
682
667
  Singleton,
@@ -693,7 +678,7 @@ export class Elysia<
693
678
  : Schema['params']
694
679
  query: Schema['query']
695
680
  headers: Schema['headers']
696
- response: ComposeElysiaResponse<
681
+ response: ComposeSpiceflowResponse<
697
682
  Schema['response'],
698
683
  Handle
699
684
  >
@@ -744,7 +729,7 @@ export class Elysia<
744
729
  Metadata['macro'],
745
730
  JoinPath<BasePath, Path>
746
731
  >
747
- ): Elysia<
732
+ ): Spiceflow<
748
733
  BasePath,
749
734
  Scoped,
750
735
  Singleton,
@@ -761,7 +746,7 @@ export class Elysia<
761
746
  : Schema['params']
762
747
  query: Schema['query']
763
748
  headers: Schema['headers']
764
- response: ComposeElysiaResponse<
749
+ response: ComposeSpiceflowResponse<
765
750
  Schema['response'],
766
751
  Handle
767
752
  >
@@ -777,7 +762,7 @@ export class Elysia<
777
762
  }
778
763
 
779
764
  /**
780
- * If set to true, other Elysia handler will not inherits global life-cycle, store, decorators from the current instance
765
+ * If set to true, other Spiceflow handler will not inherits global life-cycle, store, decorators from the current instance
781
766
  *
782
767
  * @default false
783
768
  */
@@ -789,11 +774,11 @@ export class Elysia<
789
774
  // group is not needed, you can add another prefixed app instead
790
775
  // group<
791
776
  // const Prefix extends string,
792
- // const NewElysia extends Elysia<any, any, any, any, any, any, any, any>
777
+ // const NewSpiceflow extends Spiceflow<any, any, any, any, any, any, any, any>
793
778
  // >(
794
779
  // prefix: Prefix,
795
780
  // run: (
796
- // group: Elysia<
781
+ // group: Spiceflow<
797
782
  // `${BasePath}${Prefix}`,
798
783
  // Scoped,
799
784
  // Singleton,
@@ -803,14 +788,14 @@ export class Elysia<
803
788
  // Ephemeral,
804
789
  // Volatile
805
790
  // >
806
- // ) => NewElysia
807
- // ): Elysia<
791
+ // ) => NewSpiceflow
792
+ // ): Spiceflow<
808
793
  // BasePath,
809
794
  // Scoped,
810
795
  // Singleton,
811
796
  // Definitions,
812
797
  // Metadata,
813
- // Prettify<Routes & NewElysia['_routes']>,
798
+ // Prettify<Routes & NewSpiceflow['_routes']>,
814
799
  // Ephemeral,
815
800
  // Volatile
816
801
  // > {
@@ -825,31 +810,31 @@ export class Elysia<
825
810
  // return this
826
811
  // }
827
812
 
828
- use<const NewElysia extends AnyElysia>(
829
- instance: NewElysia
830
- ): NewElysia['_scoped'] extends false
831
- ? Elysia<
813
+ use<const NewSpiceflow extends AnySpiceflow>(
814
+ instance: NewSpiceflow
815
+ ): NewSpiceflow['_scoped'] extends false
816
+ ? Spiceflow<
832
817
  BasePath,
833
818
  Scoped,
834
819
  // @ts-expect-error - This is truly ideal
835
- Prettify2<Singleton & NewElysia['_types']['Singleton']>,
836
- Prettify2<Definitions & NewElysia['_types']['Definitions']>,
837
- Prettify2<Metadata & NewElysia['_types']['Metadata']>,
820
+ Prettify2<Singleton & NewSpiceflow['_types']['Singleton']>,
821
+ Prettify2<Definitions & NewSpiceflow['_types']['Definitions']>,
822
+ Prettify2<Metadata & NewSpiceflow['_types']['Metadata']>,
838
823
  BasePath extends ``
839
- ? Routes & NewElysia['_routes']
840
- : Routes & CreateEden<BasePath, NewElysia['_routes']>,
824
+ ? Routes & NewSpiceflow['_routes']
825
+ : Routes & CreateEden<BasePath, NewSpiceflow['_routes']>,
841
826
  Ephemeral,
842
- Prettify2<Volatile & NewElysia['_ephemeral']>
827
+ Prettify2<Volatile & NewSpiceflow['_ephemeral']>
843
828
  >
844
- : Elysia<
829
+ : Spiceflow<
845
830
  BasePath,
846
831
  Scoped,
847
832
  Singleton,
848
833
  Definitions,
849
834
  Metadata,
850
835
  BasePath extends ``
851
- ? Routes & NewElysia['_routes']
852
- : Routes & CreateEden<BasePath, NewElysia['_routes']>,
836
+ ? Routes & NewSpiceflow['_routes']
837
+ : Routes & CreateEden<BasePath, NewSpiceflow['_routes']>,
853
838
  Ephemeral,
854
839
  Volatile
855
840
  > {
@@ -1263,4 +1248,4 @@ export async function turnHandlerResultIntoResponse(result: any) {
1263
1248
  return new Response(JSON.stringify(result))
1264
1249
  }
1265
1250
 
1266
- export type AnyElysia = Elysia<any, any, any, any, any, any, any, any>
1251
+ export type AnySpiceflow = Spiceflow<any, any, any, any, any, any, any, any>
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'
2
2
 
3
3
  import { createParser } from 'eventsource-parser'
4
4
 
5
- import { Elysia } from './spiceflow'
5
+ import { Spiceflow } from './spiceflow'
6
6
 
7
7
  import { req, sleep } from './utils'
8
8
 
@@ -21,7 +21,7 @@ describe('Stream', () => {
21
21
  it('handle stream', async () => {
22
22
  const expected = ['a', 'b', 'c']
23
23
 
24
- const app = new Elysia().get('/', async function* () {
24
+ const app = new Spiceflow().get('/', async function* () {
25
25
  yield 'a'
26
26
  await sleep(10)
27
27
 
@@ -60,7 +60,7 @@ describe('Stream', () => {
60
60
  expect(response).toBe(textEventStream(['a', 'b', 'c']))
61
61
  })
62
62
  it('handle errors after yield', async () => {
63
- const app = new Elysia().get('/', async function* () {
63
+ const app = new Spiceflow().get('/', async function* () {
64
64
  yield 'a'
65
65
  await sleep(10)
66
66
 
@@ -75,7 +75,7 @@ describe('Stream', () => {
75
75
  })
76
76
 
77
77
  it('handle errors before yield when aot is false', async () => {
78
- const app = new Elysia()
78
+ const app = new Spiceflow()
79
79
  .onError(({ error }) => {
80
80
  return new Response(error.message)
81
81
  })
@@ -89,7 +89,7 @@ describe('Stream', () => {
89
89
  })
90
90
 
91
91
  it.todo('handle errors before yield when aot is true', async () => {
92
- const app = new Elysia()
92
+ const app = new Spiceflow()
93
93
  .onError(({ error }) => {
94
94
  return new Response(error.message)
95
95
  })
@@ -104,7 +104,7 @@ describe('Stream', () => {
104
104
 
105
105
  it.todo('handle errors before yield with onError', async () => {
106
106
  const expected = 'error expected'
107
- const app = new Elysia()
107
+ const app = new Spiceflow()
108
108
  .onError(({}) => {
109
109
  return new Response(expected)
110
110
  })
@@ -120,7 +120,7 @@ describe('Stream', () => {
120
120
  it('stop stream on canceled request', async () => {
121
121
  const expected = ['a', 'b']
122
122
 
123
- const app = new Elysia().get('/', async function* () {
123
+ const app = new Spiceflow().get('/', async function* () {
124
124
  yield 'a'
125
125
  await sleep(10)
126
126
 
@@ -174,7 +174,7 @@ describe('Stream', () => {
174
174
  // it('mutate set before yield is called', async () => {
175
175
  // const expected = ['a', 'b', 'c']
176
176
 
177
- // const app = new Elysia().get('/', function* () {
177
+ // const app = new Spiceflow().get('/', function* () {
178
178
  // set.headers['access-control-allow-origin'] = 'http://saltyaom.com'
179
179
 
180
180
  // yield 'a'
@@ -195,7 +195,7 @@ describe('Stream', () => {
195
195
  { data: [1, 2, 3] },
196
196
  { result: [4, 5, 6] }
197
197
  ]
198
- const app = new Elysia().get('/', async function* ({}) {
198
+ const app = new Spiceflow().get('/', async function* ({}) {
199
199
  for (const obj of objects) {
200
200
  yield obj
201
201
  }
@@ -228,7 +228,7 @@ describe('Stream', () => {
228
228
  // it('mutate set before yield is called', async () => {
229
229
  // const expected = ['a', 'b', 'c']
230
230
 
231
- // const app = new Elysia().get('/', function* () {
231
+ // const app = new Spiceflow().get('/', function* () {
232
232
  // set.headers['access-control-allow-origin'] = 'http://saltyaom.com'
233
233
 
234
234
  // yield 'a'
@@ -246,7 +246,7 @@ describe('Stream', () => {
246
246
  // it('async mutate set before yield is called', async () => {
247
247
  // const expected = ['a', 'b', 'c']
248
248
 
249
- // const app = new Elysia().get('/', async function* () {
249
+ // const app = new Spiceflow().get('/', async function* () {
250
250
  // set.headers['access-control-allow-origin'] = 'http://saltyaom.com'
251
251
 
252
252
  // yield 'a'
@@ -262,7 +262,7 @@ describe('Stream', () => {
262
262
  // })
263
263
 
264
264
  it('return value if not yield', async () => {
265
- const app = new Elysia()
265
+ const app = new Spiceflow()
266
266
  .get('/', function* () {
267
267
  return 'hello'
268
268
  })
@@ -282,7 +282,7 @@ describe('Stream', () => {
282
282
  })
283
283
 
284
284
  it('return async value if not yield', async () => {
285
- const app = new Elysia()
285
+ const app = new Spiceflow()
286
286
  .get('/', function* () {
287
287
  return 'hello'
288
288
  })
@@ -306,7 +306,7 @@ describe('Stream', () => {
306
306
  const expectedResponse = JSON.stringify([...expected])
307
307
  let i = 0
308
308
 
309
- const app = new Elysia().get('/', async function* () {
309
+ const app = new Spiceflow().get('/', async function* () {
310
310
  yield expected[0]
311
311
  await sleep(10)
312
312