stitchkit 0.123.0 → 0.123.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/CHANGELOG.md +34 -0
- package/dist/browser/client-bound.d.ts +19 -0
- package/dist/browser/client-bound.d.ts.map +1 -0
- package/dist/browser/client-url.d.ts +2 -0
- package/dist/browser/client-url.d.ts.map +1 -1
- package/dist/browser/client.d.ts +20 -10
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/contract/client-types.d.ts +13 -8
- package/dist/contract/client-types.d.ts.map +1 -1
- package/dist/entrypoints/application/diagnostic-journal.js +2 -2
- package/dist/entrypoints/application/directory-inbox.js +4 -4
- package/dist/entrypoints/cli/publish.js +3 -3
- package/dist/entrypoints/files.js +3 -3
- package/dist/entrypoints/http.js +1 -1
- package/dist/entrypoints/index.js +1 -1
- package/dist/entrypoints/process.js +1 -1
- package/dist/entrypoints/remote.js +1 -1
- package/dist/entrypoints/server.js +4 -4
- package/dist/entrypoints/telegram.js +2 -2
- package/dist/entrypoints/testing.js +1 -1
- package/dist/{index-64b2dxqz.js → index-73dappvg.js} +1 -1
- package/dist/{index-n90tkkcv.js → index-bqzgaj57.js} +101 -14
- package/dist/{index-dv7pa9w6.js → index-chz7c830.js} +12 -8
- package/dist/{index-wzqd6pen.js → index-d9cg0gen.js} +1 -1
- package/dist/{index-mdyhr36s.js → index-zbzagr9k.js} +127 -61
- package/dist/internal/bun-command.d.ts +14 -0
- package/dist/internal/bun-command.d.ts.map +1 -0
- package/dist/internal/exclusive-lock-owner.d.ts +1 -1
- package/dist/internal/exclusive-lock-owner.d.ts.map +1 -1
- package/dist/internal/exclusive-lock.d.ts +1 -1
- package/dist/internal/exclusive-lock.d.ts.map +1 -1
- package/dist/internal/process-identity.d.ts +24 -5
- package/dist/internal/process-identity.d.ts.map +1 -1
- package/llms/stitchkit.2.txt +36 -174
- package/llms/stitchkit.3.txt +186 -0
- package/llms/stitchkit.txt +3 -2
- package/llms-full.txt +33 -1
- package/llms.txt +1 -1
- package/package.json +1 -1
package/llms/stitchkit.2.txt
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
# stitchkit — stitchkit docs slice, part 2 of
|
|
1
|
+
# stitchkit — stitchkit docs slice, part 2 of 3
|
|
2
2
|
|
|
3
3
|
> Generated from the `docs/` tree by `bun run gen:llms`. The index of all slices is
|
|
4
4
|
> `llms.txt` in this package.
|
|
5
|
+
> Continues in `llms/stitchkit.3.txt`.
|
|
5
6
|
|
|
6
7
|
Parts of this slice:
|
|
7
8
|
- `llms/stitchkit.txt`: Guide: Getting started (docs/guide/getting-started.md) · Guide: Typed client (docs/guide/client.md)
|
|
8
|
-
- `llms/stitchkit.2.txt`: Guide: Typed client (docs/guide/client.md)
|
|
9
|
+
- `llms/stitchkit.2.txt`: Guide: Typed client (docs/guide/client.md)
|
|
10
|
+
- `llms/stitchkit.3.txt`: API reference: `stitchkit` (docs/api/reference.md)
|
|
9
11
|
|
|
10
12
|
Also read:
|
|
11
13
|
- see `llms/contract.txt` for the Contracts guide
|
|
@@ -366,6 +368,8 @@ interface ContractClientConfig {
|
|
|
366
368
|
* they are not also sent there (the endpoint's own path `:params` are
|
|
367
369
|
* stripped automatically; list any *extra* keys here). */
|
|
368
370
|
stripPrefixKeys?: string[]
|
|
371
|
+
/** Arguments given once for every call — see "Bound arguments" below. */
|
|
372
|
+
bound?: Record<string, unknown>
|
|
369
373
|
}
|
|
370
374
|
```
|
|
371
375
|
|
|
@@ -386,6 +390,36 @@ List it in `stripPrefixKeys` so it lands in the URL **and is removed from the
|
|
|
386
390
|
query/body** — otherwise it would be sent twice. Endpoint path `:params` are
|
|
387
391
|
stripped for you; only extra prefix keys need listing.
|
|
388
392
|
|
|
393
|
+
### Bound arguments
|
|
394
|
+
|
|
395
|
+
A client that always calls with the same value — a site that knows its `slug` for the whole page
|
|
396
|
+
load, a tenant-scoped service — states the value once in `bound`. The key leaves the arguments of
|
|
397
|
+
every method, in the type and at the call, and a method whose every argument is bound is called
|
|
398
|
+
with none:
|
|
399
|
+
|
|
400
|
+
```ts
|
|
401
|
+
// site contract: GET /:slug/session, GET /:slug/courses/:courseSlug, POST /:slug/orders { item }
|
|
402
|
+
const site = createClient(siteContract, http, { bound: { slug } })
|
|
403
|
+
|
|
404
|
+
site.session() // GET /api/site/acme/session
|
|
405
|
+
site.course({ courseSlug }) // GET /api/site/acme/courses/intro
|
|
406
|
+
site.order({ item: 'book' }) // POST /api/site/acme/orders body: { item }
|
|
407
|
+
site.session.withOptions({ signal })
|
|
408
|
+
site.course({ slug, courseSlug }) // type error: `slug` is not an argument any more
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
- The value travels where the caller's argument would: a path parameter, a key `pathPrefix`
|
|
412
|
+
consumes, a query parameter of a `GET` / `DELETE`, a body or multipart field.
|
|
413
|
+
- An endpoint receives a bound key only if it declares it — as a path parameter, a prefix key, or a
|
|
414
|
+
field of its `params` / `input` object schema. A bound `lang` reaches the operations whose input
|
|
415
|
+
has `lang` and is not added to the others.
|
|
416
|
+
- A bound value wins over the same key passed by an untyped caller.
|
|
417
|
+
- `createClients`, `createScopedClients` (per scope), `createUrlBuilder`, `createUrlBuilders` and
|
|
418
|
+
`createScopedUrlBuilders` take the same option. A URL builder binds what a URL carries: path and
|
|
419
|
+
prefix keys, and the input of a `GET` / `DELETE`.
|
|
420
|
+
- Write the object in place (`{ bound: { slug } }`): the keys are read from its type, so a value
|
|
421
|
+
typed `Record<string, string>` names no key and binds nothing in the types.
|
|
422
|
+
|
|
389
423
|
## React data layer
|
|
390
424
|
|
|
391
425
|
stitchkit does not ship a hook engine. Pair the typed client with
|
|
@@ -695,175 +729,3 @@ may be retried once; do not replay a multi-step callback or treat any `403` as e
|
|
|
695
729
|
This is per-instance coordination. Route all writes through it; shared tabs/processes
|
|
696
730
|
need storage-level locking. Replace the local session counter and refresh queue when
|
|
697
731
|
adopting these primitives instead of retaining two independent lifetimes.
|
|
698
|
-
|
|
699
|
-
==============================================================================
|
|
700
|
-
# API reference: `stitchkit` (docs/api/reference.md)
|
|
701
|
-
==============================================================================
|
|
702
|
-
|
|
703
|
-
## `stitchkit`
|
|
704
|
-
|
|
705
|
-
The browser-and-server entrypoint. Re-exports everything from
|
|
706
|
-
[`stitchkit/contract`](#stitchkitcontract), plus the client and browser realtime.
|
|
707
|
-
|
|
708
|
-
### Client
|
|
709
|
-
|
|
710
|
-
| Export | Kind | Summary |
|
|
711
|
-
|--------|------|---------|
|
|
712
|
-
| `createClient` | function | build a typed client from a contract — [guide](../guide/client.md#createclient) |
|
|
713
|
-
| `createClients` | function | build one exact typed client per contract from a registry; accepts the same scoped config and transports as `createClient` |
|
|
714
|
-
| `createScopedClients` | function | build one registry routed by contract scope; arrays compose contracts into one namespace |
|
|
715
|
-
| `createScopedUrlBuilders` | function | build one URL registry routed by contract scope; arrays compose contracts into one namespace |
|
|
716
|
-
| `ScopeClientConfigs` | _type_ | per-scope routing configuration consumed by scoped clients and URL builders |
|
|
717
|
-
| `ScopedClientRegistry` | _type_ | exact composed registry returned by `createScopedClients` |
|
|
718
|
-
| `ScopedUrlBuilderRegistry` | _type_ | exact composed registry returned by `createScopedUrlBuilders` |
|
|
719
|
-
| `ClientRegistryValue` | _type_ | one contract or a contract array composing one client namespace |
|
|
720
|
-
| `ClientContract` | _type_ | HTTP-client-compatible contract value used by scoped registries |
|
|
721
|
-
| `RegistryScope` | _type_ | contract-scope union inferred from a scoped client registry value |
|
|
722
|
-
| `createUrlBuilder` | function | build synchronous browser-native URLs for all HTTP endpoints; body methods accept URL-bound args only — [guide](../guide/client.md#contract-url-builders) |
|
|
723
|
-
| `createUrlBuilders` | function | build one exact URL builder per contract in a registry |
|
|
724
|
-
| `readContractIdentity` | function | read the server's contract fingerprint in one call and return it beside the client's own — [guide](../guide/client.md#which-contract-does-the-server-speak) |
|
|
725
|
-
| `ContractIdentity` | _type_ | `{ client, server }` fingerprints; `server` is `undefined` when the server answers no identity |
|
|
726
|
-
| `UrlBuilderConfig` | _type_ | explicit `{ baseUrl }` source for a URL builder |
|
|
727
|
-
| `ClientConfig` | _type_ | config for `createClient`'s bare-fetch mode (2nd arg, no `HttpClient`) |
|
|
728
|
-
| `ClientFetch` | _type_ | injectable Fetch-compatible transport used by framework and application-owned adapters |
|
|
729
|
-
| `ClientRequestOptions` | _type_ | per-call `{ signal?, onUploadProgress? }` passed through an endpoint callable's `.withOptions(...)`; caller abort is distinct from timeout — [guide](../guide/client.md#per-call-cancellation) |
|
|
730
|
-
| `UploadProgress` | _type_ | `{ sentBytes, totalBytes, attempt }` heard by `onUploadProgress`: bytes of the encoded body handed to the network, first `0`, last `totalBytes`, counted again on each transport retry — [guide](../guide/client.md#upload-progress) |
|
|
731
|
-
| `uploadInChunks` | function | send a file larger than one request as `init` → parts → `finalize` through three calls the app owns; client-minted id, repeats of a part on a failure that may pass, `finalize` never repeated, cancel checked between parts, progress in file bytes — [guide](../guide/client.md#chunked-uploads) |
|
|
732
|
-
| `ChunkedUploadConfig` / `ChunkedUploadStart` / `ChunkedUploadPart` / `ChunkedUploadProgress` | _type_ | the driver's file, part size, retries and three calls; what `init` declares; one part; progress `{ sentBytes, totalBytes, index, chunkCount, attempt }` |
|
|
733
|
-
| `ChunkSource` | _type_ | what the driver reads a file through — `size` and `slice(start, end)`; a `Blob` is one, so is a platform file that is not (an Expo `File`), and a part's `bytes` is what its `slice` returns |
|
|
734
|
-
| `ContractClientConfig` | _type_ | per-tenant / resource-scoped client config — dynamic `pathPrefix` + `stripPrefixKeys` ([guide](../guide/client.md#contractclientconfig--per-tenant--resource-scoped-clients)) |
|
|
735
|
-
| `contractEndpointMatchers` | function | compile exact pathname matchers for selected HTTP contract operations and expected-401 policy |
|
|
736
|
-
| `PathPrefixArgs` | _type_ | required string-valued keys exposed to a typed dynamic `pathPrefix` callback |
|
|
737
|
-
| `createHttpClient` | function | the Ky-based HTTP transport; on Next.js SSR its first attempt stays request-memoizable while every retry is a distinct transport attempt — [guide](../guide/client.md#createhttpclient) |
|
|
738
|
-
| `ApiError` | class | a non-2xx or client failure, with `code` / `status` / `details` / `hint`, optional readonly `traceId` from `x-request-id`, and standard `cause` preserving an injected transport failure |
|
|
739
|
-
| `zodIssues` | function | a `ZodError` → structured `{ path, code, message }[]` — the exact projection a `VALIDATION_ERROR` carries in `ApiError.details.issues`, so a caller renders one shape. Also on `stitchkit/server`; same name, one definition |
|
|
740
|
-
| `ZodIssueSummary` | _type_ | one structured validation issue (`{ path, code, message }`) — the element type of `details.issues`. Also on `stitchkit/server` |
|
|
741
|
-
| `formatZodError` | function | a `ZodError` → a readable, field-summarised string. Also on `stitchkit/server` |
|
|
742
|
-
| `HttpClient` | _type_ | the transport interface `createClient` builds on |
|
|
743
|
-
| `ConfiguredHttpClient` | _type_ | a framework-created `HttpClient` carrying its readonly `baseUrl` for URL builders |
|
|
744
|
-
| `HttpClientConfig` | _type_ | config for `createHttpClient`; retry `limit` counts retries after the initial attempt (default 2 = at most 3 GET attempts), with `statusCodes: []` by default; `fetch` installs an explicit transport and is mutually exclusive with the legacy Bun-only `unix` option — [details](../guide/client.md#createhttpclient) |
|
|
745
|
-
| `UnauthorizedMatcher` | _type_ | exact `(pathname) => boolean` policy accepted by `suppressUnauthorizedFor` |
|
|
746
|
-
| `RequestOptions` | _type_ | per-call options — params, timeout, response type, `onUploadProgress` |
|
|
747
|
-
| `HeaderProvider` | _type_ | static or per-request headers |
|
|
748
|
-
| `ApiEvent` | _type_ | a client event — `unauthorized` / `network_error` / `logout` |
|
|
749
|
-
| `ApiEventListener` | _type_ | an `ApiEvent` handler |
|
|
750
|
-
|
|
751
|
-
### Realtime (client) & streaming
|
|
752
|
-
|
|
753
|
-
| Export | Kind | Summary |
|
|
754
|
-
|--------|------|---------|
|
|
755
|
-
| `createSocketIOClient` | function | low-level typed Socket.IO transport primitive — [guide](../guide/realtime.md#low-level-transport) |
|
|
756
|
-
| `defineRealtimeContract` | function | Zod-first shared Socket.IO event contract — [guide](../guide/realtime.md#zod-first-event-contract) |
|
|
757
|
-
| `createRealtimeClient` | function | inferred, runtime-validated Socket.IO client — [guide](../guide/realtime.md#client--createrealtimeclient) |
|
|
758
|
-
| `bindRealtimeClient` | function | bind contract validation and typed acknowledgements to an existing Stitchkit client transport without owning its lifecycle |
|
|
759
|
-
| `createLiveStateController` | function | keep typed application state current across one source-owned snapshot/event generation with finite pre-snapshot buffering, generation fencing and explicit resync — [guide](../guide/realtime.md#snapshot--event-state-synchronization) |
|
|
760
|
-
| `LiveStateController` | _type_ | renderer-neutral `start` / `resync` / `getSnapshot` / `subscribe` / `close` handle |
|
|
761
|
-
| `LiveStateControllerConfig` | _type_ | typed source, reducer, explicit event/byte bounds, event sizing and isolated error hooks |
|
|
762
|
-
| `LiveStateControllerSnapshot` / `LiveStateControllerStatus` | _types_ | current value plus phase, generation, buffer and application/duplicate/gap/refusal counters |
|
|
763
|
-
| `LiveStateControllerStatusSchema` | schema | strict runtime validation for controller status metadata |
|
|
764
|
-
| `LiveStatePhaseSchema` / `LiveStatePhase` | schema / _type_ | `idle`, `opening`, `live`, `resync-required`, `unavailable` or `closed` |
|
|
765
|
-
| `LiveStateStopReasonSchema` / `LiveStateStopReason` | schema / _type_ | explicit gap, overflow, source loss, controller failure and bounded `controller-capacity` reasons |
|
|
766
|
-
| `LiveStateEventDecision` | _type_ | provider-owned reducer result: applied state, duplicate or gap |
|
|
767
|
-
| `LiveStateSource` / `LiveStateSourceOpenInput` / `LiveStateSourceOpenResult` | _types_ | host binding for one continuous snapshot/event boundary; transport retry and cursor semantics remain host-owned |
|
|
768
|
-
| `LiveStateControllerError` / `LiveStateSubscriberError` | _types_ | isolated observer failure payloads that do not change source or subscriber truth |
|
|
769
|
-
| `createRetainedTopics` | function | retained last-value store for sticky events — [guide](../guide/realtime.md#sticky-events) |
|
|
770
|
-
| `parseSSE` | function | parse SSE from a `Response`, a web stream or an async byte iterable into an async generator — [guide](../guide/client.md#sse) |
|
|
771
|
-
| `parseNDJSON` | function | parse bounded fatal-UTF-8 NDJSON from a `Response`, a `ReadableStream<Uint8Array>` or an `AsyncIterable<Uint8Array>` (a child's stdout); blank keep-alives are skipped, `finalLine: 'require-newline'` makes the delimiter mandatory and `signal` cancels the source — [guide](../guide/client.md#any-byte-source) |
|
|
772
|
-
| `createNDJSONDecoder` / `NDJSONDecoder` | function / _type_ | the same bounded NDJSON reading driven by `push(chunk)` / `end()`, for a socket `data` callback |
|
|
773
|
-
| `readBoundedBody` / `BoundedBodyOptions` | function / _type_ | the whole body of a `ReadableStream<Uint8Array>` or async byte iterable as bytes, never reading past `maxBytes` plus one chunk; `limitError(observedBytes)` and `abortError(reason)` choose the two errors, the source is cancelled on both, a `null` body is empty — [guide](../guide/client.md#reading-a-body-up-to-a-byte-limit) |
|
|
774
|
-
| `StreamByteSource` | _type_ | `Response \| ReadableStream<Uint8Array> \| AsyncIterable<Uint8Array>`, what the NDJSON and SSE readers accept |
|
|
775
|
-
| `StreamLineLimitError` / `StreamTruncatedLineError` | class | a line past `maxLineBytes` (`limitBytes`, `lineBytes`; a `RangeError`) and a source ended inside a line under `require-newline` (`lineBytes`; a `SyntaxError`) |
|
|
776
|
-
| `resumableIterator` | function | re-open a long-lived stream from the last delivered cursor, with jittered backoff, a caller-owned terminal item and prompt abort — [guide](../guide/client.md#resumable-streams) |
|
|
777
|
-
| `createBackoff` | function | exponential backoff with subtractive jitter as a value: `next()` / `reset()` |
|
|
778
|
-
| `contractFingerprint` | function | synchronous digest of the operations HTTP carries, whole and per `prefix.key` — [guide](../guide/client.md#which-contract-does-the-server-speak) |
|
|
779
|
-
| `ContractFingerprintSchema` / `ContractFingerprint` | schema / _type_ | `{ fingerprint, operations }` — one digest for the set and one per operation |
|
|
780
|
-
| `contractIdentityContract` | contract | the operation a server answers its fingerprint with; mount it with `withContractIdentity` |
|
|
781
|
-
| `ContractStreamFrameSchema` / `ContractStreamFrame` | schema / _type_ | default on-the-wire `data` / safe `error` / `end` envelope of a contract-first stream |
|
|
782
|
-
| `ContractStreamFraming` / `ContractStreamCompletion` | _types_ | opt-in item-vs-envelope framing and terminal-vs-stream-end completion policies |
|
|
783
|
-
| `StreamFinalLinePolicy` | _type_ | permissive or newline-required final NDJSON line policy |
|
|
784
|
-
| `DEFAULT_CONTRACT_STREAM_FRAME_BYTES` | const | default maximum encoded contract-stream frame: 256 KiB |
|
|
785
|
-
| `SocketIOClient` | _type_ | low-level client handle; `emit` reports disconnected drops and `emitWithAck` exposes the native Promise primitive used by validated `request()` |
|
|
786
|
-
| `SocketIOClientPeerLoaders` | _type_ | inject `socket.io-client` so a bundler can put it in a self-contained artifact |
|
|
787
|
-
| `SocketIOClientConfig` | _type_ | config for `createSocketIOClient` (incl. `retain`, `onConnectError`, `onDroppedEmit`) |
|
|
788
|
-
| `SocketEventMap` | _type_ | the shape of an event map |
|
|
789
|
-
| `RealtimeClient` | _type_ | validated client inferred from a realtime contract |
|
|
790
|
-
| `RealtimeClientOptions` | _type_ | transport options plus rejected-event and metadata-only acknowledged-request phase hooks for `createRealtimeClient` |
|
|
791
|
-
| `BoundRealtimeClient` | _type_ | validated non-owning `on`/`emit`/`request` client with no `connect`/`disconnect` |
|
|
792
|
-
| `RealtimeClientTransport` | _type_ | minimal existing transport capability accepted by `bindRealtimeClient` |
|
|
793
|
-
| `BindRealtimeClientOptions` | _type_ | rejection/logger options for a bound existing transport |
|
|
794
|
-
| `RealtimeAcknowledgedEvent` | _type_ | event-name union restricted to definitions with an `ack` schema |
|
|
795
|
-
| `RealtimeAcknowledgement` | _type_ | validated acknowledgement output inferred from an event definition |
|
|
796
|
-
| `RealtimeRequestArguments` | _type_ | request arguments inferred from an acknowledged event tuple |
|
|
797
|
-
| `RealtimeRequestOptions` | _type_ | finite positive native acknowledgement `timeoutMs` plus an optional invocation-scoped `onPhase` observer |
|
|
798
|
-
| `RealtimeRequestPhaseSchema` / `RealtimeRequestPhase` | schema / _type_ | closed `engine-handoff` / `engine-ack-received` / `settled` / `timeout` / `disconnected` lifecycle |
|
|
799
|
-
| `RealtimeRequestPhaseEventSchema` / `RealtimeRequestPhaseEvent` | schema / _type_ | strict metadata-only `{ requestId, event, phase, elapsedMs }` observation |
|
|
800
|
-
| `RealtimeRequestPhaseHook` | _type_ | isolated sync/async observer accepted globally by `RealtimeClientOptions.onRequestPhase` or per invocation by `RealtimeRequestOptions.onPhase` |
|
|
801
|
-
| `RealtimeRequestTimeoutError` | class | stable `REALTIME_REQUEST_TIMEOUT` rejection |
|
|
802
|
-
| `RealtimeRequestDisconnectedError` | class | stable `REALTIME_REQUEST_DISCONNECTED` rejection, including an immediate disconnected call |
|
|
803
|
-
| `RealtimeRequestInvalidAcknowledgementError` | class | invalid ack was reported through `onRejected` and the request rejected |
|
|
804
|
-
| `RealtimeRequestRejectedError` | class | the peer refused the frame against its own contract and said so — `reason`, `issues` — instead of leaving the sender to time out ([ADR 0106](../decisions/0106-a-refused-frame-answers-its-sender.md)) |
|
|
805
|
-
| `REALTIME_REJECTION_KEY` | const | the reserved acknowledgement key a refusal travels under |
|
|
806
|
-
| `RealtimeRejectionEnvelope` | _type_ | the wire shape of a refusal |
|
|
807
|
-
| `RealtimeRejectionReport` | _type_ | what the sender is told: event, reason, message, issues |
|
|
808
|
-
| `RealtimeRejectionIssue` | _type_ | one refused field, already flattened (`path: '0.v'`) |
|
|
809
|
-
| `asRealtimeRejection` | function | recognise a refusal in an acknowledgement value, validating it |
|
|
810
|
-
| `RealtimeContract` | _type_ | shared server-to-client and client-to-server event registries |
|
|
811
|
-
| `RealtimeEventRegistry` | _type_ | string-keyed registry of event definitions |
|
|
812
|
-
| `RealtimeEventDefinition` | _type_ | one tuple-shaped event and optional acknowledgement schema |
|
|
813
|
-
| `RealtimeEventArguments` | _type_ | tuple inferred from an event definition |
|
|
814
|
-
| `RealtimeEmitArguments` | _type_ | emit arguments including an inferred acknowledgement callback |
|
|
815
|
-
| `RealtimeEventHandler` | _type_ | handler inferred from an event definition |
|
|
816
|
-
| `InferRealtimeEventMap` | _type_ | inferred Socket.IO-compatible event map |
|
|
817
|
-
| `RealtimeRejectDirection` / `RealtimeRejectPhase` / `RealtimeRejectReason` / `RealtimeRejectFault` | _types_ | canonical inferred rejection direction, validation phase, reason and fault classification |
|
|
818
|
-
| `RealtimeRejectedEvent` | _type_ | structured rejected event with event, direction, phase, reason and fault |
|
|
819
|
-
| `RealtimeRejectedEventHook` | _type_ | sync/async observer for structured realtime rejections |
|
|
820
|
-
| `ValidatedRealtimeSocket` | _type_ | runtime-validating `on`/`emit` surface inferred from registries; `emit` returns "accepted by the transport" (`false` only for a client-side disconnected drop) |
|
|
821
|
-
| `RetainedTopics` | _type_ | the `createRetainedTopics` handle |
|
|
822
|
-
| `ParseSSEOptions` | _type_ | options for `parseSSE` |
|
|
823
|
-
| `ParseNDJSONOptions` | _type_ | options for `parseNDJSON` |
|
|
824
|
-
| `BackoffPolicySchema` / `BackoffPolicy` | schema / _type_ | `minDelayMs`, `maxDelayMs` and a `0`–`1` jitter fraction; a ceiling below the floor is refused |
|
|
825
|
-
| `Backoff` | _type_ | the backoff handle returned by `createBackoff` |
|
|
826
|
-
| `ResumableIteratorConfig` | _type_ | caller-owned `open` / `advance` / `isTerminal`, retry policy, abort signal and `onAttempt` observer |
|
|
827
|
-
| `ResumableAttempt` | _type_ | attempt number, the delay about to be waited and the error that caused it |
|
|
828
|
-
|
|
829
|
-
### Trace (client)
|
|
830
|
-
|
|
831
|
-
Browser-safe W3C trace helpers — the same functions as on
|
|
832
|
-
[`stitchkit/observability`](#stitchkitobservability), re-exported so a client
|
|
833
|
-
can emit / propagate a `traceparent` (see `HttpClientConfig.trace`).
|
|
834
|
-
|
|
835
|
-
| Export | Kind | Summary |
|
|
836
|
-
|--------|------|---------|
|
|
837
|
-
| `createTraceContext` | function | a fresh root trace |
|
|
838
|
-
| `formatTraceparent` | function | render a `traceparent` header value |
|
|
839
|
-
| `parseTraceparent` | function | parse a `traceparent` header |
|
|
840
|
-
| `childSpan` | function | a child span of a parent trace |
|
|
841
|
-
| `TraceContext` | _type_ | `{ traceId, spanId, parentSpanId?, tracestate?, baggage? }` |
|
|
842
|
-
|
|
843
|
-
---
|
|
844
|
-
|
|
845
|
-
### Session lifetime and credential coordination
|
|
846
|
-
|
|
847
|
-
`createSessionScope` (`stitchkit`) returns the generic `SessionScope`: `replace(context)`
|
|
848
|
-
creates a new login lifetime (including same-account relogin), `capture()` returns
|
|
849
|
-
its `SessionOperation<T>`, `clear()` invalidates it, `stop()` permanently closes
|
|
850
|
-
the host, and `owns(operation)` answers whether an operation is this scope's current
|
|
851
|
-
one — `current()` alone cannot tell an operation of another scope. Operations expose `id`, `generation`, `context`, `signal`, `current()` and
|
|
852
|
-
`assertCurrent()`. `run(callback)` checks both success and failure across an await;
|
|
853
|
-
`deliver(callback)` admits a synchronous final send/state change or returns false.
|
|
854
|
-
`bindFetch(fetch, headers?)` guards every attempt and scopes its abort signal. Wrap
|
|
855
|
-
the complete client call in `run` too: headers are not the response body boundary.
|
|
856
|
-
Expired work throws `SessionExpiredError`, not a refresh instruction; when the work
|
|
857
|
-
itself failed, that failure is its `cause`.
|
|
858
|
-
|
|
859
|
-
`createSessionCredentials` accepts `SessionCredentialsConfig`:
|
|
860
|
-
`scope`, `refresh(credentials, signal)`, `storage.write(session, credentials)`,
|
|
861
|
-
`storage.clear()`, `maxPendingWrites` (128), `refreshTimeoutMs` (30000, at most one
|
|
862
|
-
hour) and `storageTimeoutMs` (30000, at most one hour): a storage call past it
|
|
863
|
-
rejects and frees the queue, so `logout()` still clears; when the late call settles,
|
|
864
|
-
storage is written again from memory, or cleared when nobody is logged in. `SessionCredentials` provides `login`, `logout`, `read(operation)` and
|
|
865
|
-
`refresh(operation)`. Concurrent refresh calls in one generation share the same
|
|
866
|
-
promise. Logout invalidates memory before its returned persistence promise settles.
|
|
867
|
-
Storage errors and queue-capacity refusals reject; callers must handle them. All
|
|
868
|
-
writes must pass through the same instance. There is no cross-process/tab lock,
|
|
869
|
-
provider error classifier or automatic retry of arbitrary application callbacks.
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# stitchkit — stitchkit docs slice, part 3 of 3
|
|
2
|
+
|
|
3
|
+
> Generated from the `docs/` tree by `bun run gen:llms`. The index of all slices is
|
|
4
|
+
> `llms.txt` in this package.
|
|
5
|
+
|
|
6
|
+
Parts of this slice:
|
|
7
|
+
- `llms/stitchkit.txt`: Guide: Getting started (docs/guide/getting-started.md) · Guide: Typed client (docs/guide/client.md)
|
|
8
|
+
- `llms/stitchkit.2.txt`: Guide: Typed client (docs/guide/client.md)
|
|
9
|
+
- `llms/stitchkit.3.txt`: API reference: `stitchkit` (docs/api/reference.md)
|
|
10
|
+
|
|
11
|
+
Also read:
|
|
12
|
+
- see `llms/contract.txt` for the Contracts guide
|
|
13
|
+
- see `llms/server.txt` for the Realtime guide
|
|
14
|
+
- see `llms/server.txt` for the Auth & errors guide
|
|
15
|
+
|
|
16
|
+
==============================================================================
|
|
17
|
+
# API reference: `stitchkit` (docs/api/reference.md)
|
|
18
|
+
==============================================================================
|
|
19
|
+
|
|
20
|
+
## `stitchkit`
|
|
21
|
+
|
|
22
|
+
The browser-and-server entrypoint. Re-exports everything from
|
|
23
|
+
[`stitchkit/contract`](#stitchkitcontract), plus the client and browser realtime.
|
|
24
|
+
|
|
25
|
+
### Client
|
|
26
|
+
|
|
27
|
+
| Export | Kind | Summary |
|
|
28
|
+
|--------|------|---------|
|
|
29
|
+
| `createClient` | function | build a typed client from a contract — [guide](../guide/client.md#createclient) |
|
|
30
|
+
| `createClients` | function | build one exact typed client per contract from a registry; accepts the same scoped config and transports as `createClient` |
|
|
31
|
+
| `createScopedClients` | function | build one registry routed by contract scope; arrays compose contracts into one namespace |
|
|
32
|
+
| `createScopedUrlBuilders` | function | build one URL registry routed by contract scope; arrays compose contracts into one namespace |
|
|
33
|
+
| `ScopeClientConfigs` | _type_ | per-scope routing configuration consumed by scoped clients and URL builders |
|
|
34
|
+
| `ScopedClientRegistry` | _type_ | exact composed registry returned by `createScopedClients` |
|
|
35
|
+
| `ScopedUrlBuilderRegistry` | _type_ | exact composed registry returned by `createScopedUrlBuilders` |
|
|
36
|
+
| `ClientRegistryValue` | _type_ | one contract or a contract array composing one client namespace |
|
|
37
|
+
| `ClientContract` | _type_ | HTTP-client-compatible contract value used by scoped registries |
|
|
38
|
+
| `RegistryScope` | _type_ | contract-scope union inferred from a scoped client registry value |
|
|
39
|
+
| `createUrlBuilder` | function | build synchronous browser-native URLs for all HTTP endpoints; body methods accept URL-bound args only — [guide](../guide/client.md#contract-url-builders) |
|
|
40
|
+
| `createUrlBuilders` | function | build one exact URL builder per contract in a registry |
|
|
41
|
+
| `readContractIdentity` | function | read the server's contract fingerprint in one call and return it beside the client's own — [guide](../guide/client.md#which-contract-does-the-server-speak) |
|
|
42
|
+
| `ContractIdentity` | _type_ | `{ client, server }` fingerprints; `server` is `undefined` when the server answers no identity |
|
|
43
|
+
| `UrlBuilderConfig` | _type_ | explicit `{ baseUrl }` source for a URL builder |
|
|
44
|
+
| `ClientConfig` | _type_ | config for `createClient`'s bare-fetch mode (2nd arg, no `HttpClient`) |
|
|
45
|
+
| `ClientFetch` | _type_ | injectable Fetch-compatible transport used by framework and application-owned adapters |
|
|
46
|
+
| `ClientRequestOptions` | _type_ | per-call `{ signal?, onUploadProgress? }` passed through an endpoint callable's `.withOptions(...)`; caller abort is distinct from timeout — [guide](../guide/client.md#per-call-cancellation) |
|
|
47
|
+
| `UploadProgress` | _type_ | `{ sentBytes, totalBytes, attempt }` heard by `onUploadProgress`: bytes of the encoded body handed to the network, first `0`, last `totalBytes`, counted again on each transport retry — [guide](../guide/client.md#upload-progress) |
|
|
48
|
+
| `uploadInChunks` | function | send a file larger than one request as `init` → parts → `finalize` through three calls the app owns; client-minted id, repeats of a part on a failure that may pass, `finalize` never repeated, cancel checked between parts, progress in file bytes — [guide](../guide/client.md#chunked-uploads) |
|
|
49
|
+
| `ChunkedUploadConfig` / `ChunkedUploadStart` / `ChunkedUploadPart` / `ChunkedUploadProgress` | _type_ | the driver's file, part size, retries and three calls; what `init` declares; one part; progress `{ sentBytes, totalBytes, index, chunkCount, attempt }` |
|
|
50
|
+
| `ChunkSource` | _type_ | what the driver reads a file through — `size` and `slice(start, end)`; a `Blob` is one, so is a platform file that is not (an Expo `File`), and a part's `bytes` is what its `slice` returns |
|
|
51
|
+
| `ContractClientConfig` | _type_ | per-tenant / resource-scoped client config — dynamic `pathPrefix` + `stripPrefixKeys`, and `bound` arguments given once for every call ([guide](../guide/client.md#contractclientconfig--per-tenant--resource-scoped-clients)) |
|
|
52
|
+
| `contractEndpointMatchers` | function | compile exact pathname matchers for selected HTTP contract operations and expected-401 policy |
|
|
53
|
+
| `PathPrefixArgs` | _type_ | required string-valued keys exposed to a typed dynamic `pathPrefix` callback |
|
|
54
|
+
| `createHttpClient` | function | the Ky-based HTTP transport; on Next.js SSR its first attempt stays request-memoizable while every retry is a distinct transport attempt — [guide](../guide/client.md#createhttpclient) |
|
|
55
|
+
| `ApiError` | class | a non-2xx or client failure, with `code` / `status` / `details` / `hint`, optional readonly `traceId` from `x-request-id`, and standard `cause` preserving an injected transport failure |
|
|
56
|
+
| `zodIssues` | function | a `ZodError` → structured `{ path, code, message }[]` — the exact projection a `VALIDATION_ERROR` carries in `ApiError.details.issues`, so a caller renders one shape. Also on `stitchkit/server`; same name, one definition |
|
|
57
|
+
| `ZodIssueSummary` | _type_ | one structured validation issue (`{ path, code, message }`) — the element type of `details.issues`. Also on `stitchkit/server` |
|
|
58
|
+
| `formatZodError` | function | a `ZodError` → a readable, field-summarised string. Also on `stitchkit/server` |
|
|
59
|
+
| `HttpClient` | _type_ | the transport interface `createClient` builds on |
|
|
60
|
+
| `ConfiguredHttpClient` | _type_ | a framework-created `HttpClient` carrying its readonly `baseUrl` for URL builders |
|
|
61
|
+
| `HttpClientConfig` | _type_ | config for `createHttpClient`; retry `limit` counts retries after the initial attempt (default 2 = at most 3 GET attempts), with `statusCodes: []` by default; `fetch` installs an explicit transport and is mutually exclusive with the legacy Bun-only `unix` option — [details](../guide/client.md#createhttpclient) |
|
|
62
|
+
| `UnauthorizedMatcher` | _type_ | exact `(pathname) => boolean` policy accepted by `suppressUnauthorizedFor` |
|
|
63
|
+
| `RequestOptions` | _type_ | per-call options — params, timeout, response type, `onUploadProgress` |
|
|
64
|
+
| `HeaderProvider` | _type_ | static or per-request headers |
|
|
65
|
+
| `ApiEvent` | _type_ | a client event — `unauthorized` / `network_error` / `logout` |
|
|
66
|
+
| `ApiEventListener` | _type_ | an `ApiEvent` handler |
|
|
67
|
+
|
|
68
|
+
### Realtime (client) & streaming
|
|
69
|
+
|
|
70
|
+
| Export | Kind | Summary |
|
|
71
|
+
|--------|------|---------|
|
|
72
|
+
| `createSocketIOClient` | function | low-level typed Socket.IO transport primitive — [guide](../guide/realtime.md#low-level-transport) |
|
|
73
|
+
| `defineRealtimeContract` | function | Zod-first shared Socket.IO event contract — [guide](../guide/realtime.md#zod-first-event-contract) |
|
|
74
|
+
| `createRealtimeClient` | function | inferred, runtime-validated Socket.IO client — [guide](../guide/realtime.md#client--createrealtimeclient) |
|
|
75
|
+
| `bindRealtimeClient` | function | bind contract validation and typed acknowledgements to an existing Stitchkit client transport without owning its lifecycle |
|
|
76
|
+
| `createLiveStateController` | function | keep typed application state current across one source-owned snapshot/event generation with finite pre-snapshot buffering, generation fencing and explicit resync — [guide](../guide/realtime.md#snapshot--event-state-synchronization) |
|
|
77
|
+
| `LiveStateController` | _type_ | renderer-neutral `start` / `resync` / `getSnapshot` / `subscribe` / `close` handle |
|
|
78
|
+
| `LiveStateControllerConfig` | _type_ | typed source, reducer, explicit event/byte bounds, event sizing and isolated error hooks |
|
|
79
|
+
| `LiveStateControllerSnapshot` / `LiveStateControllerStatus` | _types_ | current value plus phase, generation, buffer and application/duplicate/gap/refusal counters |
|
|
80
|
+
| `LiveStateControllerStatusSchema` | schema | strict runtime validation for controller status metadata |
|
|
81
|
+
| `LiveStatePhaseSchema` / `LiveStatePhase` | schema / _type_ | `idle`, `opening`, `live`, `resync-required`, `unavailable` or `closed` |
|
|
82
|
+
| `LiveStateStopReasonSchema` / `LiveStateStopReason` | schema / _type_ | explicit gap, overflow, source loss, controller failure and bounded `controller-capacity` reasons |
|
|
83
|
+
| `LiveStateEventDecision` | _type_ | provider-owned reducer result: applied state, duplicate or gap |
|
|
84
|
+
| `LiveStateSource` / `LiveStateSourceOpenInput` / `LiveStateSourceOpenResult` | _types_ | host binding for one continuous snapshot/event boundary; transport retry and cursor semantics remain host-owned |
|
|
85
|
+
| `LiveStateControllerError` / `LiveStateSubscriberError` | _types_ | isolated observer failure payloads that do not change source or subscriber truth |
|
|
86
|
+
| `createRetainedTopics` | function | retained last-value store for sticky events — [guide](../guide/realtime.md#sticky-events) |
|
|
87
|
+
| `parseSSE` | function | parse SSE from a `Response`, a web stream or an async byte iterable into an async generator — [guide](../guide/client.md#sse) |
|
|
88
|
+
| `parseNDJSON` | function | parse bounded fatal-UTF-8 NDJSON from a `Response`, a `ReadableStream<Uint8Array>` or an `AsyncIterable<Uint8Array>` (a child's stdout); blank keep-alives are skipped, `finalLine: 'require-newline'` makes the delimiter mandatory and `signal` cancels the source — [guide](../guide/client.md#any-byte-source) |
|
|
89
|
+
| `createNDJSONDecoder` / `NDJSONDecoder` | function / _type_ | the same bounded NDJSON reading driven by `push(chunk)` / `end()`, for a socket `data` callback |
|
|
90
|
+
| `readBoundedBody` / `BoundedBodyOptions` | function / _type_ | the whole body of a `ReadableStream<Uint8Array>` or async byte iterable as bytes, never reading past `maxBytes` plus one chunk; `limitError(observedBytes)` and `abortError(reason)` choose the two errors, the source is cancelled on both, a `null` body is empty — [guide](../guide/client.md#reading-a-body-up-to-a-byte-limit) |
|
|
91
|
+
| `StreamByteSource` | _type_ | `Response \| ReadableStream<Uint8Array> \| AsyncIterable<Uint8Array>`, what the NDJSON and SSE readers accept |
|
|
92
|
+
| `StreamLineLimitError` / `StreamTruncatedLineError` | class | a line past `maxLineBytes` (`limitBytes`, `lineBytes`; a `RangeError`) and a source ended inside a line under `require-newline` (`lineBytes`; a `SyntaxError`) |
|
|
93
|
+
| `resumableIterator` | function | re-open a long-lived stream from the last delivered cursor, with jittered backoff, a caller-owned terminal item and prompt abort — [guide](../guide/client.md#resumable-streams) |
|
|
94
|
+
| `createBackoff` | function | exponential backoff with subtractive jitter as a value: `next()` / `reset()` |
|
|
95
|
+
| `contractFingerprint` | function | synchronous digest of the operations HTTP carries, whole and per `prefix.key` — [guide](../guide/client.md#which-contract-does-the-server-speak) |
|
|
96
|
+
| `ContractFingerprintSchema` / `ContractFingerprint` | schema / _type_ | `{ fingerprint, operations }` — one digest for the set and one per operation |
|
|
97
|
+
| `contractIdentityContract` | contract | the operation a server answers its fingerprint with; mount it with `withContractIdentity` |
|
|
98
|
+
| `ContractStreamFrameSchema` / `ContractStreamFrame` | schema / _type_ | default on-the-wire `data` / safe `error` / `end` envelope of a contract-first stream |
|
|
99
|
+
| `ContractStreamFraming` / `ContractStreamCompletion` | _types_ | opt-in item-vs-envelope framing and terminal-vs-stream-end completion policies |
|
|
100
|
+
| `StreamFinalLinePolicy` | _type_ | permissive or newline-required final NDJSON line policy |
|
|
101
|
+
| `DEFAULT_CONTRACT_STREAM_FRAME_BYTES` | const | default maximum encoded contract-stream frame: 256 KiB |
|
|
102
|
+
| `SocketIOClient` | _type_ | low-level client handle; `emit` reports disconnected drops and `emitWithAck` exposes the native Promise primitive used by validated `request()` |
|
|
103
|
+
| `SocketIOClientPeerLoaders` | _type_ | inject `socket.io-client` so a bundler can put it in a self-contained artifact |
|
|
104
|
+
| `SocketIOClientConfig` | _type_ | config for `createSocketIOClient` (incl. `retain`, `onConnectError`, `onDroppedEmit`) |
|
|
105
|
+
| `SocketEventMap` | _type_ | the shape of an event map |
|
|
106
|
+
| `RealtimeClient` | _type_ | validated client inferred from a realtime contract |
|
|
107
|
+
| `RealtimeClientOptions` | _type_ | transport options plus rejected-event and metadata-only acknowledged-request phase hooks for `createRealtimeClient` |
|
|
108
|
+
| `BoundRealtimeClient` | _type_ | validated non-owning `on`/`emit`/`request` client with no `connect`/`disconnect` |
|
|
109
|
+
| `RealtimeClientTransport` | _type_ | minimal existing transport capability accepted by `bindRealtimeClient` |
|
|
110
|
+
| `BindRealtimeClientOptions` | _type_ | rejection/logger options for a bound existing transport |
|
|
111
|
+
| `RealtimeAcknowledgedEvent` | _type_ | event-name union restricted to definitions with an `ack` schema |
|
|
112
|
+
| `RealtimeAcknowledgement` | _type_ | validated acknowledgement output inferred from an event definition |
|
|
113
|
+
| `RealtimeRequestArguments` | _type_ | request arguments inferred from an acknowledged event tuple |
|
|
114
|
+
| `RealtimeRequestOptions` | _type_ | finite positive native acknowledgement `timeoutMs` plus an optional invocation-scoped `onPhase` observer |
|
|
115
|
+
| `RealtimeRequestPhaseSchema` / `RealtimeRequestPhase` | schema / _type_ | closed `engine-handoff` / `engine-ack-received` / `settled` / `timeout` / `disconnected` lifecycle |
|
|
116
|
+
| `RealtimeRequestPhaseEventSchema` / `RealtimeRequestPhaseEvent` | schema / _type_ | strict metadata-only `{ requestId, event, phase, elapsedMs }` observation |
|
|
117
|
+
| `RealtimeRequestPhaseHook` | _type_ | isolated sync/async observer accepted globally by `RealtimeClientOptions.onRequestPhase` or per invocation by `RealtimeRequestOptions.onPhase` |
|
|
118
|
+
| `RealtimeRequestTimeoutError` | class | stable `REALTIME_REQUEST_TIMEOUT` rejection |
|
|
119
|
+
| `RealtimeRequestDisconnectedError` | class | stable `REALTIME_REQUEST_DISCONNECTED` rejection, including an immediate disconnected call |
|
|
120
|
+
| `RealtimeRequestInvalidAcknowledgementError` | class | invalid ack was reported through `onRejected` and the request rejected |
|
|
121
|
+
| `RealtimeRequestRejectedError` | class | the peer refused the frame against its own contract and said so — `reason`, `issues` — instead of leaving the sender to time out ([ADR 0106](../decisions/0106-a-refused-frame-answers-its-sender.md)) |
|
|
122
|
+
| `REALTIME_REJECTION_KEY` | const | the reserved acknowledgement key a refusal travels under |
|
|
123
|
+
| `RealtimeRejectionEnvelope` | _type_ | the wire shape of a refusal |
|
|
124
|
+
| `RealtimeRejectionReport` | _type_ | what the sender is told: event, reason, message, issues |
|
|
125
|
+
| `RealtimeRejectionIssue` | _type_ | one refused field, already flattened (`path: '0.v'`) |
|
|
126
|
+
| `asRealtimeRejection` | function | recognise a refusal in an acknowledgement value, validating it |
|
|
127
|
+
| `RealtimeContract` | _type_ | shared server-to-client and client-to-server event registries |
|
|
128
|
+
| `RealtimeEventRegistry` | _type_ | string-keyed registry of event definitions |
|
|
129
|
+
| `RealtimeEventDefinition` | _type_ | one tuple-shaped event and optional acknowledgement schema |
|
|
130
|
+
| `RealtimeEventArguments` | _type_ | tuple inferred from an event definition |
|
|
131
|
+
| `RealtimeEmitArguments` | _type_ | emit arguments including an inferred acknowledgement callback |
|
|
132
|
+
| `RealtimeEventHandler` | _type_ | handler inferred from an event definition |
|
|
133
|
+
| `InferRealtimeEventMap` | _type_ | inferred Socket.IO-compatible event map |
|
|
134
|
+
| `RealtimeRejectDirection` / `RealtimeRejectPhase` / `RealtimeRejectReason` / `RealtimeRejectFault` | _types_ | canonical inferred rejection direction, validation phase, reason and fault classification |
|
|
135
|
+
| `RealtimeRejectedEvent` | _type_ | structured rejected event with event, direction, phase, reason and fault |
|
|
136
|
+
| `RealtimeRejectedEventHook` | _type_ | sync/async observer for structured realtime rejections |
|
|
137
|
+
| `ValidatedRealtimeSocket` | _type_ | runtime-validating `on`/`emit` surface inferred from registries; `emit` returns "accepted by the transport" (`false` only for a client-side disconnected drop) |
|
|
138
|
+
| `RetainedTopics` | _type_ | the `createRetainedTopics` handle |
|
|
139
|
+
| `ParseSSEOptions` | _type_ | options for `parseSSE` |
|
|
140
|
+
| `ParseNDJSONOptions` | _type_ | options for `parseNDJSON` |
|
|
141
|
+
| `BackoffPolicySchema` / `BackoffPolicy` | schema / _type_ | `minDelayMs`, `maxDelayMs` and a `0`–`1` jitter fraction; a ceiling below the floor is refused |
|
|
142
|
+
| `Backoff` | _type_ | the backoff handle returned by `createBackoff` |
|
|
143
|
+
| `ResumableIteratorConfig` | _type_ | caller-owned `open` / `advance` / `isTerminal`, retry policy, abort signal and `onAttempt` observer |
|
|
144
|
+
| `ResumableAttempt` | _type_ | attempt number, the delay about to be waited and the error that caused it |
|
|
145
|
+
|
|
146
|
+
### Trace (client)
|
|
147
|
+
|
|
148
|
+
Browser-safe W3C trace helpers — the same functions as on
|
|
149
|
+
[`stitchkit/observability`](#stitchkitobservability), re-exported so a client
|
|
150
|
+
can emit / propagate a `traceparent` (see `HttpClientConfig.trace`).
|
|
151
|
+
|
|
152
|
+
| Export | Kind | Summary |
|
|
153
|
+
|--------|------|---------|
|
|
154
|
+
| `createTraceContext` | function | a fresh root trace |
|
|
155
|
+
| `formatTraceparent` | function | render a `traceparent` header value |
|
|
156
|
+
| `parseTraceparent` | function | parse a `traceparent` header |
|
|
157
|
+
| `childSpan` | function | a child span of a parent trace |
|
|
158
|
+
| `TraceContext` | _type_ | `{ traceId, spanId, parentSpanId?, tracestate?, baggage? }` |
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### Session lifetime and credential coordination
|
|
163
|
+
|
|
164
|
+
`createSessionScope` (`stitchkit`) returns the generic `SessionScope`: `replace(context)`
|
|
165
|
+
creates a new login lifetime (including same-account relogin), `capture()` returns
|
|
166
|
+
its `SessionOperation<T>`, `clear()` invalidates it, `stop()` permanently closes
|
|
167
|
+
the host, and `owns(operation)` answers whether an operation is this scope's current
|
|
168
|
+
one — `current()` alone cannot tell an operation of another scope. Operations expose `id`, `generation`, `context`, `signal`, `current()` and
|
|
169
|
+
`assertCurrent()`. `run(callback)` checks both success and failure across an await;
|
|
170
|
+
`deliver(callback)` admits a synchronous final send/state change or returns false.
|
|
171
|
+
`bindFetch(fetch, headers?)` guards every attempt and scopes its abort signal. Wrap
|
|
172
|
+
the complete client call in `run` too: headers are not the response body boundary.
|
|
173
|
+
Expired work throws `SessionExpiredError`, not a refresh instruction; when the work
|
|
174
|
+
itself failed, that failure is its `cause`.
|
|
175
|
+
|
|
176
|
+
`createSessionCredentials` accepts `SessionCredentialsConfig`:
|
|
177
|
+
`scope`, `refresh(credentials, signal)`, `storage.write(session, credentials)`,
|
|
178
|
+
`storage.clear()`, `maxPendingWrites` (128), `refreshTimeoutMs` (30000, at most one
|
|
179
|
+
hour) and `storageTimeoutMs` (30000, at most one hour): a storage call past it
|
|
180
|
+
rejects and frees the queue, so `logout()` still clears; when the late call settles,
|
|
181
|
+
storage is written again from memory, or cleared when nobody is logged in. `SessionCredentials` provides `login`, `logout`, `read(operation)` and
|
|
182
|
+
`refresh(operation)`. Concurrent refresh calls in one generation share the same
|
|
183
|
+
promise. Logout invalidates memory before its returned persistence promise settles.
|
|
184
|
+
Storage errors and queue-capacity refusals reject; callers must handle them. All
|
|
185
|
+
writes must pass through the same instance. There is no cross-process/tab lock,
|
|
186
|
+
provider error classifier or automatic retry of arbitrary application callbacks.
|
package/llms/stitchkit.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# stitchkit — stitchkit docs slice, part 1 of
|
|
1
|
+
# stitchkit — stitchkit docs slice, part 1 of 3
|
|
2
2
|
|
|
3
3
|
> Generated from the `docs/` tree by `bun run gen:llms`. The index of all slices is
|
|
4
4
|
> `llms.txt` in this package.
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
Parts of this slice:
|
|
8
8
|
- `llms/stitchkit.txt`: Guide: Getting started (docs/guide/getting-started.md) · Guide: Typed client (docs/guide/client.md)
|
|
9
|
-
- `llms/stitchkit.2.txt`: Guide: Typed client (docs/guide/client.md)
|
|
9
|
+
- `llms/stitchkit.2.txt`: Guide: Typed client (docs/guide/client.md)
|
|
10
|
+
- `llms/stitchkit.3.txt`: API reference: `stitchkit` (docs/api/reference.md)
|
|
10
11
|
|
|
11
12
|
Also read:
|
|
12
13
|
- see `llms/contract.txt` for the Contracts guide
|
package/llms-full.txt
CHANGED
|
@@ -3615,6 +3615,8 @@ interface ContractClientConfig {
|
|
|
3615
3615
|
* they are not also sent there (the endpoint's own path `:params` are
|
|
3616
3616
|
* stripped automatically; list any *extra* keys here). */
|
|
3617
3617
|
stripPrefixKeys?: string[]
|
|
3618
|
+
/** Arguments given once for every call — see "Bound arguments" below. */
|
|
3619
|
+
bound?: Record<string, unknown>
|
|
3618
3620
|
}
|
|
3619
3621
|
```
|
|
3620
3622
|
|
|
@@ -3635,6 +3637,36 @@ List it in `stripPrefixKeys` so it lands in the URL **and is removed from the
|
|
|
3635
3637
|
query/body** — otherwise it would be sent twice. Endpoint path `:params` are
|
|
3636
3638
|
stripped for you; only extra prefix keys need listing.
|
|
3637
3639
|
|
|
3640
|
+
### Bound arguments
|
|
3641
|
+
|
|
3642
|
+
A client that always calls with the same value — a site that knows its `slug` for the whole page
|
|
3643
|
+
load, a tenant-scoped service — states the value once in `bound`. The key leaves the arguments of
|
|
3644
|
+
every method, in the type and at the call, and a method whose every argument is bound is called
|
|
3645
|
+
with none:
|
|
3646
|
+
|
|
3647
|
+
```ts
|
|
3648
|
+
// site contract: GET /:slug/session, GET /:slug/courses/:courseSlug, POST /:slug/orders { item }
|
|
3649
|
+
const site = createClient(siteContract, http, { bound: { slug } })
|
|
3650
|
+
|
|
3651
|
+
site.session() // GET /api/site/acme/session
|
|
3652
|
+
site.course({ courseSlug }) // GET /api/site/acme/courses/intro
|
|
3653
|
+
site.order({ item: 'book' }) // POST /api/site/acme/orders body: { item }
|
|
3654
|
+
site.session.withOptions({ signal })
|
|
3655
|
+
site.course({ slug, courseSlug }) // type error: `slug` is not an argument any more
|
|
3656
|
+
```
|
|
3657
|
+
|
|
3658
|
+
- The value travels where the caller's argument would: a path parameter, a key `pathPrefix`
|
|
3659
|
+
consumes, a query parameter of a `GET` / `DELETE`, a body or multipart field.
|
|
3660
|
+
- An endpoint receives a bound key only if it declares it — as a path parameter, a prefix key, or a
|
|
3661
|
+
field of its `params` / `input` object schema. A bound `lang` reaches the operations whose input
|
|
3662
|
+
has `lang` and is not added to the others.
|
|
3663
|
+
- A bound value wins over the same key passed by an untyped caller.
|
|
3664
|
+
- `createClients`, `createScopedClients` (per scope), `createUrlBuilder`, `createUrlBuilders` and
|
|
3665
|
+
`createScopedUrlBuilders` take the same option. A URL builder binds what a URL carries: path and
|
|
3666
|
+
prefix keys, and the input of a `GET` / `DELETE`.
|
|
3667
|
+
- Write the object in place (`{ bound: { slug } }`): the keys are read from its type, so a value
|
|
3668
|
+
typed `Record<string, string>` names no key and binds nothing in the types.
|
|
3669
|
+
|
|
3638
3670
|
## React data layer
|
|
3639
3671
|
|
|
3640
3672
|
stitchkit does not ship a hook engine. Pair the typed client with
|
|
@@ -23034,7 +23066,7 @@ The browser-and-server entrypoint. Re-exports everything from
|
|
|
23034
23066
|
| `uploadInChunks` | function | send a file larger than one request as `init` → parts → `finalize` through three calls the app owns; client-minted id, repeats of a part on a failure that may pass, `finalize` never repeated, cancel checked between parts, progress in file bytes — [guide](../guide/client.md#chunked-uploads) |
|
|
23035
23067
|
| `ChunkedUploadConfig` / `ChunkedUploadStart` / `ChunkedUploadPart` / `ChunkedUploadProgress` | _type_ | the driver's file, part size, retries and three calls; what `init` declares; one part; progress `{ sentBytes, totalBytes, index, chunkCount, attempt }` |
|
|
23036
23068
|
| `ChunkSource` | _type_ | what the driver reads a file through — `size` and `slice(start, end)`; a `Blob` is one, so is a platform file that is not (an Expo `File`), and a part's `bytes` is what its `slice` returns |
|
|
23037
|
-
| `ContractClientConfig` | _type_ | per-tenant / resource-scoped client config — dynamic `pathPrefix` + `stripPrefixKeys` ([guide](../guide/client.md#contractclientconfig--per-tenant--resource-scoped-clients)) |
|
|
23069
|
+
| `ContractClientConfig` | _type_ | per-tenant / resource-scoped client config — dynamic `pathPrefix` + `stripPrefixKeys`, and `bound` arguments given once for every call ([guide](../guide/client.md#contractclientconfig--per-tenant--resource-scoped-clients)) |
|
|
23038
23070
|
| `contractEndpointMatchers` | function | compile exact pathname matchers for selected HTTP contract operations and expected-401 policy |
|
|
23039
23071
|
| `PathPrefixArgs` | _type_ | required string-valued keys exposed to a typed dynamic `pathPrefix` callback |
|
|
23040
23072
|
| `createHttpClient` | function | the Ky-based HTTP transport; on Next.js SSR its first attempt stays request-memoizable while every retry is a distinct transport attempt — [guide](../guide/client.md#createhttpclient) |
|
package/llms.txt
CHANGED
|
@@ -9,7 +9,7 @@ Build with stitchkit: define a contract once, then `implement` it and serve it (
|
|
|
9
9
|
Load the slice for each entrypoint your code imports — `import … from 'stitchkit/server'` → `llms/server.txt`; the root `stitchkit` import → `llms/stitchkit.txt`. A slice holds that entrypoint's API reference section and the guide pages whose home it is; every guide lives in exactly one slice, and a slice that needs another's guide names it under "Also read". Each file is at most 50.0 KB; a longer one continues in numbered parts, each naming the next at its top. Moving across versions: load `llms/upgrading.txt` and the range slices it lists between your version and the target. `llms-full.txt` inlines everything; it is far larger than a context window, so do not read it whole.
|
|
10
10
|
|
|
11
11
|
## Entrypoint slices
|
|
12
|
-
- **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt) 44.8 KB → [llms/stitchkit.2.txt](llms/stitchkit.2.txt)
|
|
12
|
+
- **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt) 44.8 KB → [llms/stitchkit.2.txt](llms/stitchkit.2.txt) 30.9 KB → [llms/stitchkit.3.txt](llms/stitchkit.3.txt) 19.1 KB
|
|
13
13
|
- **stitchkit/live**: [llms/live.txt](llms/live.txt) 21.2 KB
|
|
14
14
|
- **stitchkit/react**: [llms/react.txt](llms/react.txt) 8.7 KB
|
|
15
15
|
- **stitchkit/react/keyboard**: [llms/react-keyboard.txt](llms/react-keyboard.txt) 22.7 KB
|
package/package.json
CHANGED