spiceflow 1.17.12 → 1.18.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 +167 -2
- package/dist/client/errors.d.ts +2 -1
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +3 -1
- package/dist/client/errors.js.map +1 -1
- package/dist/client/fetch.d.ts +86 -0
- package/dist/client/fetch.d.ts.map +1 -0
- package/dist/client/fetch.js +143 -0
- package/dist/client/fetch.js.map +1 -0
- package/dist/client/index.d.ts +4 -14
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -176
- package/dist/client/index.js.map +1 -1
- package/dist/client/shared.d.ts +47 -0
- package/dist/client/shared.d.ts.map +1 -0
- package/dist/client/shared.js +314 -0
- package/dist/client/shared.js.map +1 -0
- package/dist/client/types.d.ts +2 -1
- package/dist/client/types.d.ts.map +1 -1
- package/dist/fetch-client.test.d.ts +2 -0
- package/dist/fetch-client.test.d.ts.map +1 -0
- package/dist/fetch-client.test.js +362 -0
- package/dist/fetch-client.test.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/openapi.d.ts +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/spiceflow.d.ts +36 -14
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +49 -16
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js +205 -1
- package/dist/spiceflow.test.js.map +1 -1
- package/package.json +3 -3
- package/src/client/errors.ts +3 -0
- package/src/client/fetch.ts +447 -0
- package/src/client/index.ts +19 -229
- package/src/client/shared.ts +406 -0
- package/src/client/types.ts +2 -1
- package/src/fetch-client.test.ts +411 -0
- package/src/index.ts +1 -1
- package/src/spiceflow.test.ts +315 -1
- package/src/spiceflow.ts +106 -32
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<br/>
|
|
11
11
|
</div>
|
|
12
12
|
|
|
13
|
-
Spiceflow is a lightweight, type-safe API framework for building web services using modern web standards.
|
|
13
|
+
Spiceflow is a lightweight, type-safe API framework for building web services using modern web standards. Read the source code on [GitHub](https://github.com/remorses/spiceflow).
|
|
14
14
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
@@ -134,7 +134,7 @@ const app = new Spiceflow()
|
|
|
134
134
|
path: '/users/:id',
|
|
135
135
|
params: z.object({
|
|
136
136
|
id: z.string(),
|
|
137
|
-
}),
|
|
137
|
+
}),w
|
|
138
138
|
response: z.object({
|
|
139
139
|
id: z.string(),
|
|
140
140
|
name: z.string(),
|
|
@@ -362,6 +362,119 @@ async function exampleUsage() {
|
|
|
362
362
|
}
|
|
363
363
|
```
|
|
364
364
|
|
|
365
|
+
## Fetch Client (Recommended)
|
|
366
|
+
|
|
367
|
+
`createSpiceflowFetch` is the recommended way to interact with a Spiceflow app. It uses a familiar `fetch(path, options)` interface instead of the proxy-based chainable API of `createSpiceflowClient`. It provides the same type safety for paths, params, query, body, and responses, but with a simpler and more predictable API.
|
|
368
|
+
|
|
369
|
+
Export the app type from your server code:
|
|
370
|
+
|
|
371
|
+
```ts
|
|
372
|
+
// server.ts
|
|
373
|
+
import { Spiceflow } from 'spiceflow'
|
|
374
|
+
import { z } from 'zod'
|
|
375
|
+
|
|
376
|
+
const app = new Spiceflow()
|
|
377
|
+
.route({
|
|
378
|
+
method: 'GET',
|
|
379
|
+
path: '/hello',
|
|
380
|
+
handler() {
|
|
381
|
+
return 'Hello, World!'
|
|
382
|
+
},
|
|
383
|
+
})
|
|
384
|
+
.route({
|
|
385
|
+
method: 'POST',
|
|
386
|
+
path: '/users',
|
|
387
|
+
request: z.object({
|
|
388
|
+
name: z.string(),
|
|
389
|
+
email: z.string().email(),
|
|
390
|
+
}),
|
|
391
|
+
async handler({ request }) {
|
|
392
|
+
const body = await request.json()
|
|
393
|
+
return { id: '1', name: body.name, email: body.email }
|
|
394
|
+
},
|
|
395
|
+
})
|
|
396
|
+
.route({
|
|
397
|
+
method: 'GET',
|
|
398
|
+
path: '/users/:id',
|
|
399
|
+
handler({ params }) {
|
|
400
|
+
return { id: params.id }
|
|
401
|
+
},
|
|
402
|
+
})
|
|
403
|
+
.route({
|
|
404
|
+
method: 'GET',
|
|
405
|
+
path: '/search',
|
|
406
|
+
query: z.object({ q: z.string(), page: z.coerce.number().optional() }),
|
|
407
|
+
handler({ query }) {
|
|
408
|
+
return { results: [], query: query.q, page: query.page }
|
|
409
|
+
},
|
|
410
|
+
})
|
|
411
|
+
.route({
|
|
412
|
+
method: 'GET',
|
|
413
|
+
path: '/stream',
|
|
414
|
+
async *handler() {
|
|
415
|
+
yield 'Start'
|
|
416
|
+
yield 'Middle'
|
|
417
|
+
yield 'End'
|
|
418
|
+
},
|
|
419
|
+
})
|
|
420
|
+
|
|
421
|
+
export type App = typeof app
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
Then use the `App` type on the client side without importing server code:
|
|
425
|
+
|
|
426
|
+
```ts
|
|
427
|
+
// client.ts
|
|
428
|
+
import { createSpiceflowFetch } from 'spiceflow/client'
|
|
429
|
+
import type { App } from './server'
|
|
430
|
+
|
|
431
|
+
const f = createSpiceflowFetch<App>('http://localhost:3000')
|
|
432
|
+
|
|
433
|
+
// Returns Error | Data — check with instanceof Error
|
|
434
|
+
const greeting = await f('/hello')
|
|
435
|
+
if (greeting instanceof Error) return greeting // early return on error
|
|
436
|
+
console.log(greeting) // 'Hello, World!' — TypeScript knows the type
|
|
437
|
+
|
|
438
|
+
// POST with typed body
|
|
439
|
+
const user = await f('/users', {
|
|
440
|
+
method: 'POST',
|
|
441
|
+
body: { name: 'John', email: 'john@example.com' },
|
|
442
|
+
})
|
|
443
|
+
if (user instanceof Error) return user
|
|
444
|
+
console.log(user.id, user.name) // fully typed
|
|
445
|
+
|
|
446
|
+
// Path params — type-safe, required when path has :params
|
|
447
|
+
const foundUser = await f('/users/:id', {
|
|
448
|
+
params: { id: '123' },
|
|
449
|
+
})
|
|
450
|
+
if (foundUser instanceof Error) return foundUser
|
|
451
|
+
|
|
452
|
+
// Query params — typed from route schema
|
|
453
|
+
const searchResults = await f('/search', {
|
|
454
|
+
query: { q: 'hello', page: 1 },
|
|
455
|
+
})
|
|
456
|
+
if (searchResults instanceof Error) return searchResults
|
|
457
|
+
|
|
458
|
+
// Streaming — returns AsyncGenerator for async generator routes
|
|
459
|
+
const stream = await f('/stream')
|
|
460
|
+
if (stream instanceof Error) return stream
|
|
461
|
+
for await (const chunk of stream) {
|
|
462
|
+
console.log(chunk) // 'Start', 'Middle', 'End'
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
The fetch client returns `Error | Data` directly following the [errore](https://errore.org) convention — use `instanceof Error` to check for errors with Go-style early returns, then the happy path continues with the narrowed data type. No `{ data, error }` destructuring, no null checks. On error, the returned `SpiceflowFetchError` has `status`, `value` (the parsed error body), and `response` (the raw Response object) properties.
|
|
467
|
+
|
|
468
|
+
The fetch client supports configuration options like headers, retries, onRequest/onResponse hooks, and custom fetch.
|
|
469
|
+
|
|
470
|
+
You can also pass a Spiceflow app instance directly for server-side usage without network requests:
|
|
471
|
+
|
|
472
|
+
```ts
|
|
473
|
+
const f = createSpiceflowFetch(app)
|
|
474
|
+
const greeting = await f('/hello')
|
|
475
|
+
if (greeting instanceof Error) throw greeting
|
|
476
|
+
```
|
|
477
|
+
|
|
365
478
|
### Path Matching - Supported Features
|
|
366
479
|
|
|
367
480
|
- **Named parameters**: `:param` - Captures dynamic segments like `/users/:id` or `/api/:version/users/:userId`
|
|
@@ -506,6 +619,58 @@ const userPostPath = app.safePath('/users/:id/posts/:postId', {
|
|
|
506
619
|
// Result: '/users/456/posts/abc'
|
|
507
620
|
```
|
|
508
621
|
|
|
622
|
+
### Query Parameters
|
|
623
|
+
|
|
624
|
+
When a route has a `query` schema, `safePath` accepts query parameters alongside path parameters in the same flat object. Query parameters are appended as a query string, and unknown keys are rejected at the type level:
|
|
625
|
+
|
|
626
|
+
```ts
|
|
627
|
+
const app = new Spiceflow()
|
|
628
|
+
.route({
|
|
629
|
+
method: 'GET',
|
|
630
|
+
path: '/search',
|
|
631
|
+
query: z.object({ q: z.string(), page: z.coerce.number() }),
|
|
632
|
+
handler({ query }) {
|
|
633
|
+
return { results: [], q: query.q }
|
|
634
|
+
},
|
|
635
|
+
})
|
|
636
|
+
.route({
|
|
637
|
+
method: 'GET',
|
|
638
|
+
path: '/users/:id',
|
|
639
|
+
query: z.object({ fields: z.string() }),
|
|
640
|
+
handler({ params, query }) {
|
|
641
|
+
return { id: params.id, fields: query.fields }
|
|
642
|
+
},
|
|
643
|
+
})
|
|
644
|
+
|
|
645
|
+
app.safePath('/search', { q: 'hello', page: 1 })
|
|
646
|
+
// Result: '/search?q=hello&page=1'
|
|
647
|
+
|
|
648
|
+
app.safePath('/users/:id', { id: '42', fields: 'name' })
|
|
649
|
+
// Result: '/users/42?fields=name'
|
|
650
|
+
|
|
651
|
+
// @ts-expect-error - 'invalid' is not a known query key
|
|
652
|
+
app.safePath('/search', { invalid: 'x' })
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
### Standalone `createSafePath`
|
|
656
|
+
|
|
657
|
+
If you need a path builder on the client side where you can't import server app code, use `createSafePath` with the `typeof app` generic:
|
|
658
|
+
|
|
659
|
+
```ts
|
|
660
|
+
import { createSafePath } from 'spiceflow'
|
|
661
|
+
import type { App } from './server' // import only the type, not the runtime app
|
|
662
|
+
|
|
663
|
+
const safePath = createSafePath<App>()
|
|
664
|
+
|
|
665
|
+
safePath('/users/:id', { id: '123' })
|
|
666
|
+
// Result: '/users/123'
|
|
667
|
+
|
|
668
|
+
safePath('/search', { q: 'hello', page: 1 })
|
|
669
|
+
// Result: '/search?q=hello&page=1'
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
The returned function has the same type safety as `app.safePath` — it infers paths, params, and query schemas from the app type. The app argument is optional and not used at runtime, so you can call `createSafePath<App>()` without passing any value.
|
|
673
|
+
|
|
509
674
|
### OAuth Callback Example
|
|
510
675
|
|
|
511
676
|
The `safePath` method is particularly useful when building callback URLs for OAuth flows, where you need to construct URLs dynamically based on user data or session information:
|
package/dist/client/errors.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare class SpiceflowFetchError<Status = number, Value extends any = an
|
|
|
2
2
|
status: Status;
|
|
3
3
|
passedValue: Value;
|
|
4
4
|
value: Value;
|
|
5
|
-
|
|
5
|
+
response?: Response;
|
|
6
|
+
constructor(status: Status, passedValue: Value, response?: Response);
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAmB,CAC9B,MAAM,GAAG,MAAM,EACf,KAAK,SAAS,GAAG,GAAG,GAAG,CACvB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAmB,CAC9B,MAAM,GAAG,MAAM,EACf,KAAK,SAAS,GAAG,GAAG,GAAG,CACvB,SAAQ,KAAK;IAIJ,MAAM,EAAE,MAAM;IACd,WAAW,EAAE,KAAK;IAJ3B,KAAK,EAAE,KAAK,CAAA;IACZ,QAAQ,CAAC,EAAE,QAAQ,CAAA;gBAEV,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,KAAK,EACzB,QAAQ,CAAC,EAAE,QAAQ;CActB"}
|
package/dist/client/errors.js
CHANGED
|
@@ -2,7 +2,8 @@ export class SpiceflowFetchError extends Error {
|
|
|
2
2
|
status;
|
|
3
3
|
passedValue;
|
|
4
4
|
value;
|
|
5
|
-
|
|
5
|
+
response;
|
|
6
|
+
constructor(status, passedValue, response) {
|
|
6
7
|
let message = String(passedValue?.message || '');
|
|
7
8
|
if (!message) {
|
|
8
9
|
if (typeof passedValue === 'object') {
|
|
@@ -16,6 +17,7 @@ export class SpiceflowFetchError extends Error {
|
|
|
16
17
|
this.status = status;
|
|
17
18
|
this.passedValue = passedValue;
|
|
18
19
|
this.value = passedValue;
|
|
20
|
+
this.response = response;
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAGX,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAGX,SAAQ,KAAK;IAIJ;IACA;IAJT,KAAK,CAAO;IACZ,QAAQ,CAAW;IACnB,YACS,MAAc,EACd,WAAkB,EACzB,QAAmB;QAEnB,IAAI,OAAO,GAAG,MAAM,CAAE,WAAmB,EAAE,OAAO,IAAI,EAAE,CAAC,CAAA;QACzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;gBACpC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;YACvC,CAAC;iBAAM,CAAC;gBACN,OAAO,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAA;YACrC,CAAC;QACH,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,CAAA;QAZP,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAO;QAYzB,IAAI,CAAC,KAAK,GAAG,WAAW,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { AnySpiceflow, Spiceflow } from '../spiceflow.ts';
|
|
2
|
+
import type { ExtractParamsFromPath } from '../types.ts';
|
|
3
|
+
import type { SpiceflowClient } from './types.ts';
|
|
4
|
+
import type { ReplaceGeneratorWithAsyncGenerator } from './types.ts';
|
|
5
|
+
import { SpiceflowFetchError } from './errors.ts';
|
|
6
|
+
type NavigateRoutes<Routes, Path extends string> = Path extends `/${infer Rest}` ? Rest extends '' ? 'index' extends keyof Routes ? Routes['index'] : never : _NavigateRoutes<Routes, Rest> : _NavigateRoutes<Routes, Path>;
|
|
7
|
+
type _NavigateRoutes<Routes, Path extends string> = Path extends `${infer Segment}/${infer Rest}` ? Segment extends keyof Routes ? _NavigateRoutes<Routes[Segment], Rest> : never : Path extends keyof Routes ? Routes[Path] : never;
|
|
8
|
+
type RouteAtPath<Routes extends Record<string, any>, Path extends string> = NavigateRoutes<Routes, Path>;
|
|
9
|
+
type RouteInfoForMethod<Routes extends Record<string, any>, Path extends string, Method extends string> = Lowercase<Method> extends keyof RouteAtPath<Routes, Path> ? RouteAtPath<Routes, Path>[Lowercase<Method>] : never;
|
|
10
|
+
type ParamsOption<Path extends string> = ExtractParamsFromPath<Path> extends undefined ? {
|
|
11
|
+
params?: Record<string, string>;
|
|
12
|
+
} : {
|
|
13
|
+
params: ExtractParamsFromPath<Path>;
|
|
14
|
+
};
|
|
15
|
+
type QueryOption<Routes extends Record<string, any>, Path extends string, Method extends string> = RouteInfoForMethod<Routes, Path, Method> extends {
|
|
16
|
+
query: infer Q;
|
|
17
|
+
} ? undefined extends Q ? {
|
|
18
|
+
query?: Record<string, unknown>;
|
|
19
|
+
} : {
|
|
20
|
+
query: Q;
|
|
21
|
+
} : {
|
|
22
|
+
query?: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
type BodyOption<Routes extends Record<string, any>, Path extends string, Method extends string> = Lowercase<Method> extends 'get' | 'head' | 'subscribe' ? {} : RouteInfoForMethod<Routes, Path, Method> extends {
|
|
25
|
+
request: infer Body;
|
|
26
|
+
} ? undefined extends Body ? {
|
|
27
|
+
body?: unknown;
|
|
28
|
+
} : {
|
|
29
|
+
body: Body;
|
|
30
|
+
} : {
|
|
31
|
+
body?: unknown;
|
|
32
|
+
};
|
|
33
|
+
type HasRequiredFields<Routes extends Record<string, any>, Path extends string, Method extends string> = ExtractParamsFromPath<Path> extends undefined ? RouteInfoForMethod<Routes, Path, Method> extends {
|
|
34
|
+
query: infer Q;
|
|
35
|
+
} ? undefined extends Q ? Lowercase<Method> extends 'get' | 'head' | 'subscribe' ? false : RouteInfoForMethod<Routes, Path, Method> extends {
|
|
36
|
+
request: infer Body;
|
|
37
|
+
} ? undefined extends Body ? false : true : false : true : Lowercase<Method> extends 'get' | 'head' | 'subscribe' ? false : RouteInfoForMethod<Routes, Path, Method> extends {
|
|
38
|
+
request: infer Body;
|
|
39
|
+
} ? undefined extends Body ? false : true : false : true;
|
|
40
|
+
type FetchOptionsTyped<Routes extends Record<string, any>, Path extends string, Method extends string> = {
|
|
41
|
+
method?: Method;
|
|
42
|
+
headers?: RequestInit['headers'];
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
} & ParamsOption<Path> & QueryOption<Routes, Path, Method> & BodyOption<Routes, Path, Method>;
|
|
45
|
+
type FetchOptionsFallback = {
|
|
46
|
+
method?: string;
|
|
47
|
+
body?: BodyInit | Record<string, unknown> | null;
|
|
48
|
+
query?: Record<string, unknown>;
|
|
49
|
+
params?: Record<string, string>;
|
|
50
|
+
headers?: RequestInit['headers'];
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
};
|
|
54
|
+
type FetchOptions<Routes extends Record<string, any>, Path extends string, Method extends string> = [RouteAtPath<Routes, Path>] extends [never] ? FetchOptionsFallback : FetchOptionsTyped<Routes, Path, Method>;
|
|
55
|
+
type FetchResultData<Routes extends Record<string, any>, Path extends string, Method extends string> = [RouteAtPath<Routes, Path>] extends [never] ? any : RouteInfoForMethod<Routes, Path, Method> extends {
|
|
56
|
+
response: infer Res extends Record<number, unknown>;
|
|
57
|
+
} ? ReplaceGeneratorWithAsyncGenerator<Res>[200] : any;
|
|
58
|
+
type FetchResultError<Routes extends Record<string, any>, Path extends string, Method extends string> = [RouteAtPath<Routes, Path>] extends [never] ? SpiceflowFetchError<number, any> : RouteInfoForMethod<Routes, Path, Method> extends {
|
|
59
|
+
response: infer Res extends Record<number, unknown>;
|
|
60
|
+
} ? Exclude<keyof Res, 200> extends never ? SpiceflowFetchError<number, any> : {
|
|
61
|
+
[Status in keyof Res]: SpiceflowFetchError<Status, Res[Status]>;
|
|
62
|
+
}[Exclude<keyof Res, 200>] : SpiceflowFetchError<number, any>;
|
|
63
|
+
type FetchResult<Routes extends Record<string, any>, Path extends string, Method extends string> = FetchResultError<Routes, Path, Method> | FetchResultData<Routes, Path, Method>;
|
|
64
|
+
type ResolveOptions<App extends AnySpiceflow, Path extends string, Method extends string> = App extends {
|
|
65
|
+
_types: {
|
|
66
|
+
ClientRoutes: infer Routes extends Record<string, any>;
|
|
67
|
+
};
|
|
68
|
+
} ? FetchOptions<Routes, Path, Method> : FetchOptionsFallback;
|
|
69
|
+
type ResolveResult<App extends AnySpiceflow, Path extends string, Method extends string> = App extends {
|
|
70
|
+
_types: {
|
|
71
|
+
ClientRoutes: infer Routes extends Record<string, any>;
|
|
72
|
+
};
|
|
73
|
+
} ? FetchResult<Routes, Path, Method> : SpiceflowFetchError<number, any> | any;
|
|
74
|
+
type IsOptionsRequired<App extends AnySpiceflow, Path extends string, Method extends string> = App extends {
|
|
75
|
+
_types: {
|
|
76
|
+
ClientRoutes: infer Routes extends Record<string, any>;
|
|
77
|
+
};
|
|
78
|
+
} ? [RouteAtPath<Routes, Path>] extends [never] ? false : HasRequiredFields<Routes, Path, Method> : false;
|
|
79
|
+
export interface SpiceflowFetch<App extends AnySpiceflow> {
|
|
80
|
+
<const Path extends string, const Method extends string = 'GET'>(...args: IsOptionsRequired<App, Path, Method> extends true ? [path: Path, options: ResolveOptions<App, Path, Method>] : [path: Path, options?: ResolveOptions<App, Path, Method>]): Promise<ResolveResult<App, Path, Method>>;
|
|
81
|
+
}
|
|
82
|
+
export declare function createSpiceflowFetch<const App extends AnySpiceflow>(domain: App | string, config?: SpiceflowClient.Config & (App extends Spiceflow<any, any, infer Singleton, any, any, any, any> ? {
|
|
83
|
+
state?: Singleton['state'];
|
|
84
|
+
} : {})): SpiceflowFetch<App>;
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/client/fetch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAA;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAyBjD,KAAK,cAAc,CAAC,MAAM,EAAE,IAAI,SAAS,MAAM,IAC7C,IAAI,SAAS,IAAI,MAAM,IAAI,EAAE,GACzB,IAAI,SAAS,EAAE,GACb,OAAO,SAAS,MAAM,MAAM,GAC1B,MAAM,CAAC,OAAO,CAAC,GACf,KAAK,GACP,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,GAC/B,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAEnC,KAAK,eAAe,CAAC,MAAM,EAAE,IAAI,SAAS,MAAM,IAC9C,IAAI,SAAS,GAAG,MAAM,OAAO,IAAI,MAAM,IAAI,EAAE,GACzC,OAAO,SAAS,MAAM,MAAM,GAC1B,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,GACtC,KAAK,GACP,IAAI,SAAS,MAAM,MAAM,GACvB,MAAM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,CAAC,SAAS,IAAI,GACtD,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,GACxD,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,GAC5D,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAA;CAC7C;AAID,wBAAgB,oBAAoB,CAAC,KAAK,CAAC,GAAG,SAAS,YAAY,EACjE,MAAM,EAAE,GAAG,GAAG,MAAM,EACpB,MAAM,GAAE,eAAe,CAAC,MAAM,GAC5B,CAAC,GAAG,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GACjE;IAAE,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;CAAE,GAC9B,EAAE,CAAa,GACpB,cAAc,CAAC,GAAG,CAAC,CAsLrB"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { processHeaders, buildQueryString, serializeBody, parseResponseData, executeWithRetries, } from "./shared.js";
|
|
2
|
+
// ─── Factory ─────────────────────────────────────────────────────────────────
|
|
3
|
+
export function createSpiceflowFetch(domain, config = {}) {
|
|
4
|
+
let baseUrl;
|
|
5
|
+
let instance;
|
|
6
|
+
if (typeof domain === 'string') {
|
|
7
|
+
baseUrl = domain.endsWith('/') ? domain.slice(0, -1) : domain;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
baseUrl = 'http://e.ly';
|
|
11
|
+
instance = domain;
|
|
12
|
+
if (typeof window !== 'undefined') {
|
|
13
|
+
console.warn('Spiceflow instance server found on client side, this is not recommended for security reason. Use generic type instead.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (config.state && !instance) {
|
|
17
|
+
throw new Error('State is only available when using a Spiceflow instance');
|
|
18
|
+
}
|
|
19
|
+
const spiceflowFetch = async (path, options = {}) => {
|
|
20
|
+
let { fetch: fetcher = fetch, headers: configHeaders, onRequest, onResponse, retries = 0, } = config;
|
|
21
|
+
const { method: rawMethod = 'GET', body, query, params, headers: optionHeaders, signal, ...restInit } = options;
|
|
22
|
+
const methodUpper = rawMethod.toUpperCase();
|
|
23
|
+
const isGetOrHead = methodUpper === 'GET' ||
|
|
24
|
+
methodUpper === 'HEAD' ||
|
|
25
|
+
methodUpper === 'SUBSCRIBE';
|
|
26
|
+
// Resolve path params (replace :param with values)
|
|
27
|
+
// Sort by key length descending to avoid :id replacing inside :id2
|
|
28
|
+
let resolvedPath = path;
|
|
29
|
+
if (params && typeof params === 'object') {
|
|
30
|
+
const entries = Object.entries(params).sort(([a], [b]) => b.length - a.length);
|
|
31
|
+
for (const [key, value] of entries) {
|
|
32
|
+
if (key === '*') {
|
|
33
|
+
resolvedPath = resolvedPath.split('*').join(String(value));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
resolvedPath = resolvedPath.split(`:${key}`).join(String(value));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const queryString = buildQueryString(query);
|
|
41
|
+
// Support absolute URLs — skip baseUrl concatenation
|
|
42
|
+
const isAbsoluteUrl = /^https?:\/\//i.test(resolvedPath);
|
|
43
|
+
const url = isAbsoluteUrl
|
|
44
|
+
? resolvedPath + queryString
|
|
45
|
+
: baseUrl + resolvedPath + queryString;
|
|
46
|
+
let headers = processHeaders(configHeaders, resolvedPath, {
|
|
47
|
+
method: methodUpper,
|
|
48
|
+
signal,
|
|
49
|
+
});
|
|
50
|
+
headers = {
|
|
51
|
+
...headers,
|
|
52
|
+
...processHeaders(optionHeaders, resolvedPath, {
|
|
53
|
+
method: methodUpper,
|
|
54
|
+
signal,
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
let fetchInit = {
|
|
58
|
+
method: methodUpper,
|
|
59
|
+
headers,
|
|
60
|
+
signal,
|
|
61
|
+
...restInit,
|
|
62
|
+
};
|
|
63
|
+
// Apply onRequest hooks (first pass, before body serialization)
|
|
64
|
+
if (onRequest) {
|
|
65
|
+
const hooks = Array.isArray(onRequest) ? onRequest : [onRequest];
|
|
66
|
+
for (const hook of hooks) {
|
|
67
|
+
const temp = await hook(resolvedPath, fetchInit);
|
|
68
|
+
if (typeof temp === 'object') {
|
|
69
|
+
fetchInit = {
|
|
70
|
+
...fetchInit,
|
|
71
|
+
...temp,
|
|
72
|
+
headers: {
|
|
73
|
+
...fetchInit.headers,
|
|
74
|
+
...processHeaders(temp.headers, resolvedPath, fetchInit),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Ensure GET/HEAD has no body before serialization
|
|
81
|
+
if (isGetOrHead)
|
|
82
|
+
delete fetchInit.body;
|
|
83
|
+
// Serialize body
|
|
84
|
+
if (!isGetOrHead && body !== undefined) {
|
|
85
|
+
fetchInit.body = body;
|
|
86
|
+
await serializeBody({ body, fetchInit, isGetOrHead });
|
|
87
|
+
}
|
|
88
|
+
if (isGetOrHead) {
|
|
89
|
+
delete fetchInit.body;
|
|
90
|
+
}
|
|
91
|
+
// Add x-spiceflow-agent header
|
|
92
|
+
;
|
|
93
|
+
fetchInit.headers['x-spiceflow-agent'] =
|
|
94
|
+
'spiceflow-client';
|
|
95
|
+
// Apply onRequest hooks (second pass, after body serialization — matches proxy client behavior)
|
|
96
|
+
if (onRequest) {
|
|
97
|
+
const hooks = Array.isArray(onRequest) ? onRequest : [onRequest];
|
|
98
|
+
for (const hook of hooks) {
|
|
99
|
+
const temp = await hook(resolvedPath, fetchInit);
|
|
100
|
+
if (typeof temp === 'object') {
|
|
101
|
+
fetchInit = {
|
|
102
|
+
...fetchInit,
|
|
103
|
+
...temp,
|
|
104
|
+
headers: {
|
|
105
|
+
...fetchInit.headers,
|
|
106
|
+
...processHeaders(temp.headers, resolvedPath, fetchInit),
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Execute request with retries
|
|
113
|
+
const executeRequest = () => executeWithRetries({
|
|
114
|
+
url,
|
|
115
|
+
fetchInit,
|
|
116
|
+
fetcher: fetcher || fetch,
|
|
117
|
+
instance,
|
|
118
|
+
state: config.state,
|
|
119
|
+
retries,
|
|
120
|
+
});
|
|
121
|
+
const response = await executeRequest();
|
|
122
|
+
// Process onResponse hooks
|
|
123
|
+
if (onResponse) {
|
|
124
|
+
const hooks = Array.isArray(onResponse) ? onResponse : [onResponse];
|
|
125
|
+
for (const hook of hooks) {
|
|
126
|
+
await hook(response.clone());
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Parse response
|
|
130
|
+
const { data, error } = await parseResponseData({
|
|
131
|
+
response,
|
|
132
|
+
executeRequest,
|
|
133
|
+
retries,
|
|
134
|
+
});
|
|
135
|
+
if (error) {
|
|
136
|
+
error.response = response;
|
|
137
|
+
return error;
|
|
138
|
+
}
|
|
139
|
+
return data;
|
|
140
|
+
};
|
|
141
|
+
return spiceflowFetch;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/client/fetch.ts"],"names":[],"mappings":"AASA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAA;AAiPpB,gFAAgF;AAEhF,MAAM,UAAU,oBAAoB,CAClC,MAAoB,EACpB,SAGY,EAAS;IAErB,IAAI,OAAe,CAAA;IACnB,IAAI,QAAkC,CAAA;IAEtC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,G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from './types.ts';
|
|
3
3
|
export { SpiceflowClient };
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export declare class TextDecoderStream extends TransformStream<Uint8Array, string> {
|
|
10
|
-
constructor();
|
|
11
|
-
}
|
|
12
|
-
export declare function streamSSEResponse({ response, map, executeRequest, maxRetries, }: {
|
|
13
|
-
response: Response;
|
|
14
|
-
map: (x: SSEEvent) => any;
|
|
15
|
-
executeRequest?: () => Promise<Response>;
|
|
16
|
-
maxRetries?: number;
|
|
17
|
-
}): AsyncGenerator<SSEEvent>;
|
|
4
|
+
import { streamSSEResponse, TextDecoderStream } from './shared.ts';
|
|
5
|
+
export { streamSSEResponse, TextDecoderStream };
|
|
6
|
+
export { createSpiceflowFetch } from './fetch.ts';
|
|
7
|
+
export type { SpiceflowFetch } from './fetch.ts';
|
|
18
8
|
export declare const createSpiceflowClient: <const App extends AnySpiceflow>(domain: App | string, config?: SpiceflowClient.Config & (App extends Spiceflow<any, any, infer Singleton, any, any, any, any> ? {
|
|
19
9
|
state?: Singleton["state"];
|
|
20
10
|
} : {})) => SpiceflowClient.Create<App>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,CAAA;AAM1B,OAAO,EAML,iBAAiB,EAGjB,iBAAiB,EAGlB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAA;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAsWhD,eAAO,MAAM,qBAAqB,GAAI,KAAK,CAAC,GAAG,SAAS,YAAY,EAClE,QAAQ,GAAG,GAAG,MAAM,EACpB,SAAS,eAAe,CAAC,MAAM,GAC7B,CAAC,GAAG,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GACjE;IAAE,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;CAAE,GAC9B,EAAE,CAAC,KACR,eAAe,CAAC,MAAM,CAAC,GAAG,CAc5B,CAAA"}
|