@relyio/sdk 0.3.0 → 0.4.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/CHANGELOG.md +86 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-QIZOBT5F.js → chunk-43VPZT2G.js} +283 -9
- package/dist/{chunk-HMVGXUGR.cjs → chunk-HAQELDZN.cjs} +2 -2
- package/dist/{chunk-54WP2PWG.cjs → chunk-XS32U2UP.cjs} +284 -8
- package/dist/{chunk-LYRYCIX5.js → chunk-XY5KFEFY.js} +2 -2
- package/dist/client/index.cjs +3 -3
- package/dist/client/index.d.cts +3 -3
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +1 -1
- package/dist/{define-schema-BfXeR6K8.d.cts → define-schema-2xbHgtK-.d.cts} +8 -4
- package/dist/{define-schema-BD6HSPnG.d.ts → define-schema-DzYXk4HL.d.ts} +8 -4
- package/dist/{index-BDpar3FO.d.cts → index-BvO6HDtY.d.cts} +217 -8
- package/dist/{index-Dx01iwaf.d.ts → index-BzOFJJKS.d.ts} +217 -8
- package/dist/{index-ulOrcfPa.d.cts → index-DFehx5sI.d.cts} +239 -11
- package/dist/{index-DuEhsGdE.d.ts → index-FDak5ofk.d.ts} +239 -11
- package/dist/index.cjs +119 -66
- package/dist/index.d.cts +112 -46
- package/dist/index.d.ts +112 -46
- package/dist/index.js +44 -3
- package/dist/schema/index.cjs +35 -35
- package/dist/schema/index.d.cts +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +5 -15
- package/dist/react/index.cjs +0 -4
- package/dist/react/index.d.cts +0 -2
- package/dist/react/index.d.ts +0 -2
- package/dist/react/index.js +0 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as SchemaDefinition, b as SchemaContentTypeNames, h as SchemaAssetTypeNames, M as InferAssetType, c as SchemaSingletonNames, t as InferSingleton, g as SchemaSettingsGroupNames, E as InferSettingsGroup, e as SchemaQueryNames, f as SchemaLocaleCodes } from './define-schema-
|
|
1
|
+
import { J as MergedRelyIOConfig, A as ApiPath, a as ApiMethod, K as PathParamsOf, t as ApiResponse, W as Wire, s as RequestConfig, B as BaseContent, d as WhereClause, f as SortOptions, g as ContentQueryResult, Q as QueryOptions, C as CreateInput, U as UpdateInput, S as SDKError, x as BaseValidationError, w as ValidationViolation, N as components, O as paths, R as RelyIOConfig } from './index-DFehx5sI.cjs';
|
|
2
|
+
import { a as SchemaDefinition, b as SchemaContentTypeNames, h as SchemaAssetTypeNames, M as InferAssetType, c as SchemaSingletonNames, t as InferSingleton, g as SchemaSettingsGroupNames, E as InferSettingsGroup, e as SchemaQueryNames, f as SchemaLocaleCodes } from './define-schema-2xbHgtK-.cjs';
|
|
3
3
|
import { J as InferContentType } from './define-content-type-CBfnTWSS.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -109,6 +109,16 @@ declare class HttpClient {
|
|
|
109
109
|
* Get current base URL
|
|
110
110
|
*/
|
|
111
111
|
getBaseUrl(): string;
|
|
112
|
+
/**
|
|
113
|
+
* One attempt.
|
|
114
|
+
*
|
|
115
|
+
* The caller's `signal` and the timeout both end it, through one controller.
|
|
116
|
+
* The incumbent handed `fetch` the caller's signal **instead of** its own, so a
|
|
117
|
+
* request that passed a signal had no timeout at all — and a caller abort then
|
|
118
|
+
* surfaced as `Request timed out`. `timedOut` is what tells the two apart: a
|
|
119
|
+
* timeout is a `TimeoutError`, a caller abort is the platform's `AbortError`,
|
|
120
|
+
* rethrown as it came.
|
|
121
|
+
*/
|
|
112
122
|
private makeRequest;
|
|
113
123
|
/**
|
|
114
124
|
* Filter headers that browsers don't allow to be set manually
|
|
@@ -123,6 +133,7 @@ declare class HttpClient {
|
|
|
123
133
|
private mergeRequestConfig;
|
|
124
134
|
private buildQueryString;
|
|
125
135
|
private headersToObject;
|
|
136
|
+
/** A backoff the caller's abort cuts short; the next attempt then refuses to send. */
|
|
126
137
|
private sleep;
|
|
127
138
|
private log;
|
|
128
139
|
}
|
|
@@ -2386,11 +2397,166 @@ declare class AdhocQueryClient {
|
|
|
2386
2397
|
}
|
|
2387
2398
|
|
|
2388
2399
|
/**
|
|
2389
|
-
*
|
|
2390
|
-
*
|
|
2391
|
-
*
|
|
2400
|
+
* Content and resource errors.
|
|
2401
|
+
*
|
|
2402
|
+
* `ContentTypeNotFoundError` and `ContentNotFoundError` were deleted at API5.
|
|
2403
|
+
* The mapper reached them by sniffing `CONTENT_TYPE_NOT_FOUND` and
|
|
2404
|
+
* `CONTENT_NOT_FOUND`, neither of which is in the closed vocabulary, so neither
|
|
2405
|
+
* class was reachable. Both cases are `RESOURCE_NOT_FOUND`, whose declared
|
|
2406
|
+
* `details` are `{ kind, id? }` — the same two facts, from the one code a route
|
|
2407
|
+
* can actually declare.
|
|
2408
|
+
*/
|
|
2409
|
+
declare class ResourceNotFoundError extends SDKError {
|
|
2410
|
+
readonly code = "RESOURCE_NOT_FOUND";
|
|
2411
|
+
readonly retryable = false;
|
|
2412
|
+
constructor(message?: string, statusCode?: number, cause?: Error, context?: Record<string, unknown>);
|
|
2413
|
+
getUserMessage(): string;
|
|
2414
|
+
}
|
|
2415
|
+
declare class ResourceConflictError extends SDKError {
|
|
2416
|
+
readonly code = "RESOURCE_CONFLICT";
|
|
2417
|
+
readonly retryable = false;
|
|
2418
|
+
constructor(message?: string, statusCode?: number, cause?: Error, context?: Record<string, unknown>);
|
|
2419
|
+
getUserMessage(): string;
|
|
2420
|
+
}
|
|
2421
|
+
declare class ResourceExpiredError extends SDKError {
|
|
2422
|
+
readonly code = "RESOURCE_EXPIRED";
|
|
2423
|
+
readonly retryable = false;
|
|
2424
|
+
constructor(message?: string, statusCode?: number, cause?: Error, context?: Record<string, unknown>);
|
|
2425
|
+
getUserMessage(): string;
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* "Did the service say this resource does not exist?"
|
|
2429
|
+
*
|
|
2430
|
+
* Reads the **code**, not the status. Four contract codes are 4xx on a read and
|
|
2431
|
+
* only one of them means "not there"; the incumbent checked `statusCode === 404`
|
|
2432
|
+
* on the thrown value, and a second arm duck-typed a plain object for the same
|
|
2433
|
+
* number so a hand-written test double would pass. Both are the branch
|
|
2434
|
+
* `INV-API-CLIENT-IS-DERIVED` forbids where a code exists — and the second one
|
|
2435
|
+
* only existed because the tests faked the boundary (rule 20). They now stub
|
|
2436
|
+
* `fetch`, so the double is gone with the branch.
|
|
2437
|
+
*/
|
|
2438
|
+
declare function isResourceNotFound(error: unknown): boolean;
|
|
2439
|
+
|
|
2440
|
+
/**
|
|
2441
|
+
* `relyio.changes()` — the changes feed as a typed long-poll iterator
|
|
2442
|
+
* (`sdk-surfaces-spec.md` decisions 16–18).
|
|
2443
|
+
*
|
|
2444
|
+
* Long-poll only, on purpose. `GET /v1/changes` is an ordinary cursor-paged
|
|
2445
|
+
* collection the committed document declares, so each poll is one `send` over
|
|
2446
|
+
* the one HTTP client (`INV-SS-ONE-CORE`, `INV-API-CLIENT-IS-DERIVED`). The SSE
|
|
2447
|
+
* branch the route also serves would be a second transport path inside that
|
|
2448
|
+
* client, and `parseResponse` buffers a whole body; it stays for `EventSource`
|
|
2449
|
+
* and curl consumers.
|
|
2450
|
+
*/
|
|
2451
|
+
|
|
2452
|
+
type PollChanges = paths['/v1/changes']['get'];
|
|
2453
|
+
/**
|
|
2454
|
+
* The 200 body the document declares, read from its `application/json` content
|
|
2455
|
+
* **by name**. The route also negotiates `text/event-stream`; naming the JSON
|
|
2456
|
+
* content is what keeps that alternate from changing this type when the
|
|
2457
|
+
* document gains it.
|
|
2458
|
+
*/
|
|
2459
|
+
type ChangesPageBody = PollChanges['responses'][200]['content']['application/json'];
|
|
2460
|
+
/**
|
|
2461
|
+
* One change, as the committed document describes an item of the feed's `data`
|
|
2462
|
+
* (`INV-SS-CHANGE-IS-IDS`: ids, content type, locale, kind and cursor — never a
|
|
2463
|
+
* document).
|
|
2464
|
+
*
|
|
2465
|
+
* Read from the document, never written here: the api's route row names the
|
|
2466
|
+
* `Change` component schema, and a change to it reaches this type when the
|
|
2467
|
+
* document is regenerated. `changes.types.ts` holds it equal to the document's
|
|
2468
|
+
* item, and fails if it is ever `unknown` again.
|
|
2469
|
+
*/
|
|
2470
|
+
type Change = ChangesPageBody['data'][number];
|
|
2471
|
+
/** Why a cursor could no longer be replayed. `unknown` when the message named neither. */
|
|
2472
|
+
type ChangesExpiredReason = 'retention' | 'dataset-replaced' | 'unknown';
|
|
2473
|
+
/**
|
|
2474
|
+
* `RESOURCE_EXPIRED` from the changes feed: the cursor names a position the
|
|
2475
|
+
* ledger can no longer replay from (`INV-SS-CURSOR-REPLAYS`). The consumer
|
|
2476
|
+
* resyncs from the read path and starts again without a cursor.
|
|
2477
|
+
*
|
|
2478
|
+
* A `ResourceExpiredError`, so code that already catches that still does. The
|
|
2479
|
+
* refusal declares no details, so `reason` is read from the message the api
|
|
2480
|
+
* writes (`apps/services/api/src/changes/changes-request.ts` `refusalOf`).
|
|
2481
|
+
*/
|
|
2482
|
+
declare class ChangesExpiredError extends ResourceExpiredError {
|
|
2483
|
+
readonly reason: ChangesExpiredReason;
|
|
2484
|
+
/** The base class's signature, so `withContext` can rebuild one. */
|
|
2485
|
+
constructor(message: string, statusCode?: number, cause?: Error, context?: Record<string, unknown>);
|
|
2486
|
+
static of(expired: ResourceExpiredError): ChangesExpiredError;
|
|
2487
|
+
}
|
|
2488
|
+
interface ChangesOptions {
|
|
2489
|
+
/**
|
|
2490
|
+
* A `page.nextCursor` — or a change's `cursor` — from an earlier poll. Omitted,
|
|
2491
|
+
* the first poll answers the dataset's current position and no changes, at
|
|
2492
|
+
* once, and the feed starts from there.
|
|
2493
|
+
*/
|
|
2494
|
+
since?: string;
|
|
2495
|
+
/** Content types to keep. Omitted keeps every type; an empty list is refused (400). */
|
|
2496
|
+
types?: readonly string[];
|
|
2497
|
+
/**
|
|
2498
|
+
* Entry ids to keep. Omitted keeps every entry. The api refuses more than it
|
|
2499
|
+
* allows (100 today) as `REQUEST_INVALID`, thrown from the iterator as an
|
|
2500
|
+
* `InvalidPayloadError` on the first poll; the SDK does not restate the
|
|
2501
|
+
* cap, so it cannot drift from the service's.
|
|
2502
|
+
*/
|
|
2503
|
+
ids?: readonly string[];
|
|
2504
|
+
/** Ledger rows one poll scans, 1 to 500; the api defaults to 100. */
|
|
2505
|
+
limit?: number;
|
|
2506
|
+
/**
|
|
2507
|
+
* Ends the iteration. An abort — in flight, between polls, or while waiting
|
|
2508
|
+
* out a `Retry-After` — makes the `for await` **complete**, with no further
|
|
2509
|
+
* request and no `AbortError` thrown into the loop.
|
|
2510
|
+
*/
|
|
2511
|
+
signal?: AbortSignal;
|
|
2512
|
+
/**
|
|
2513
|
+
* What to do when the cursor has expired.
|
|
2514
|
+
*
|
|
2515
|
+
* - `'throw'` (default) — the iterator throws {@link ChangesExpiredError}.
|
|
2516
|
+
* - `'resync'` — restart from the dataset's current position and keep going.
|
|
2517
|
+
* - a function — resync, and call it with the error once the new position is
|
|
2518
|
+
* taken and before any change after it is yielded. This is the observable
|
|
2519
|
+
* form: whatever the consumer derived from the feed may be stale, so the
|
|
2520
|
+
* function is where it invalidates everything. The iterator waits for it.
|
|
2521
|
+
*/
|
|
2522
|
+
onExpired?: 'throw' | 'resync' | ((expired: ChangesExpiredError) => void | Promise<void>);
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
/**
|
|
2526
|
+
* Any schema the client can be typed by. `any` is deliberate: the client accepts whatever content
|
|
2527
|
+
* types, components, singletons, queries and settings groups a customer declares.
|
|
2528
|
+
*
|
|
2529
|
+
* This is the constraint `TypedRelyIOClient`'s `TSchema` carries, so `RegisteredSchema` is inferred
|
|
2530
|
+
* against the same one — `createClient` returns `TypedRelyIOClient<RegisteredSchema>`, and a schema
|
|
2531
|
+
* inferred against any wider alias would not be provably inside the client's bound.
|
|
2392
2532
|
*/
|
|
2393
2533
|
type AnySchemaDefinition = SchemaDefinition<any, any, any, any, any>;
|
|
2534
|
+
/**
|
|
2535
|
+
* The seam `relyio generate-types` fills (`INV-SS-TYPES-INFERRED`).
|
|
2536
|
+
*
|
|
2537
|
+
* Empty here on purpose. The generated `schema.ts` augments it —
|
|
2538
|
+
*
|
|
2539
|
+
* ```ts
|
|
2540
|
+
* declare module '@relyio/sdk' {
|
|
2541
|
+
* interface Register {
|
|
2542
|
+
* schema: typeof schema
|
|
2543
|
+
* }
|
|
2544
|
+
* }
|
|
2545
|
+
* ```
|
|
2546
|
+
*
|
|
2547
|
+
* — and from then on `createClient({ apiKey })`, with no generic and no `schema:`, is typed by that
|
|
2548
|
+
* schema. The pattern is TanStack Router's. It is type-level only: nothing at runtime reads it.
|
|
2549
|
+
*/
|
|
2550
|
+
interface Register {
|
|
2551
|
+
}
|
|
2552
|
+
/**
|
|
2553
|
+
* The schema the project registered through `Register`, or `undefined` when nothing did — which is
|
|
2554
|
+
* the untyped client, exactly as before the generator ran.
|
|
2555
|
+
*/
|
|
2556
|
+
type RegisteredSchema = Register extends {
|
|
2557
|
+
schema: infer S extends AnySchemaDefinition;
|
|
2558
|
+
} ? S : undefined;
|
|
2559
|
+
|
|
2394
2560
|
/**
|
|
2395
2561
|
* Client configuration with optional schema
|
|
2396
2562
|
*/
|
|
@@ -2555,6 +2721,32 @@ declare class TypedRelyIOClient<TSchema extends AnySchemaDefinition | undefined
|
|
|
2555
2721
|
* ```
|
|
2556
2722
|
*/
|
|
2557
2723
|
batch(): BatchBuilder<NonNullable<TSchema>>;
|
|
2724
|
+
/**
|
|
2725
|
+
* Follow the dataset's changes feed: each write this key can see, as ids, in
|
|
2726
|
+
* order, long-polled from `GET /v1/changes`.
|
|
2727
|
+
*
|
|
2728
|
+
* Lazy — nothing is requested until the first `next()`. It runs until
|
|
2729
|
+
* `signal` aborts, which ends the `for await` cleanly rather than throwing.
|
|
2730
|
+
* A change names what changed; refetch it through the ordinary read path
|
|
2731
|
+
* (`INV-SS-CHANGE-IS-IDS`).
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* ```typescript
|
|
2735
|
+
* const controller = new AbortController()
|
|
2736
|
+
* for await (const change of relyio.changes({ since: cursor, types: ['post'], signal: controller.signal })) {
|
|
2737
|
+
* // { entryId, contentType, locale, kind, cursor }
|
|
2738
|
+
* }
|
|
2739
|
+
* ```
|
|
2740
|
+
*
|
|
2741
|
+
* @example Resync when the cursor has expired
|
|
2742
|
+
* ```typescript
|
|
2743
|
+
* for await (const change of relyio.changes({
|
|
2744
|
+
* since: cursor,
|
|
2745
|
+
* onExpired: async () => invalidateEverything(),
|
|
2746
|
+
* })) { … }
|
|
2747
|
+
* ```
|
|
2748
|
+
*/
|
|
2749
|
+
changes(options?: ChangesOptions): AsyncIterable<Change>;
|
|
2558
2750
|
/**
|
|
2559
2751
|
* Build and execute an ad-hoc query dynamically
|
|
2560
2752
|
*
|
|
@@ -2713,12 +2905,29 @@ declare class TypedRelyIOClient<TSchema extends AnySchemaDefinition | undefined
|
|
|
2713
2905
|
* // Content type names autocomplete!
|
|
2714
2906
|
* const products = await relyio.content('product').fetchAll()
|
|
2715
2907
|
* ```
|
|
2716
|
-
|
|
2908
|
+
*
|
|
2909
|
+
* @example After `relyio generate-types` (inferred, `INV-SS-TYPES-INFERRED`)
|
|
2910
|
+
* ```typescript
|
|
2911
|
+
* import { createClient } from '@relyio/sdk'
|
|
2912
|
+
*
|
|
2913
|
+
* // The generated `schema.ts` augments `Register`, so no generic and no `schema:` are needed
|
|
2914
|
+
* const relyio = createClient({ apiKey: process.env.RELYIO_API_KEY! })
|
|
2915
|
+
* ```
|
|
2916
|
+
*
|
|
2917
|
+
* The overload without a schema comes first on purpose. Behind the generic one it was never
|
|
2918
|
+
* chosen: with no `schema` to infer from, `TSchema` fell back to its constraint and the call
|
|
2919
|
+
* resolved to `TypedRelyIOClient<AnySchemaDefinition>`. First, it takes every call that passes no
|
|
2920
|
+
* schema, and returns the registered schema's client — or the untyped one when nothing registered.
|
|
2921
|
+
* A `schema:` value fails its `schema?: undefined`, and an explicit generic skips it because it has
|
|
2922
|
+
* no type parameter, so both reach the generic overload unchanged.
|
|
2923
|
+
*/
|
|
2924
|
+
declare function createClient(config: RelyIOConfig & {
|
|
2925
|
+
schema?: undefined;
|
|
2926
|
+
}): TypedRelyIOClient<RegisteredSchema>;
|
|
2717
2927
|
declare function createClient<TSchema extends AnySchemaDefinition>(config: TypedClientConfig<TSchema>): TypedRelyIOClient<TSchema>;
|
|
2718
|
-
declare function createClient(config: RelyIOConfig): TypedRelyIOClient<undefined>;
|
|
2719
2928
|
/**
|
|
2720
2929
|
* Helper type to extract schema from client
|
|
2721
2930
|
*/
|
|
2722
2931
|
type ClientSchema<T extends TypedRelyIOClient<AnySchemaDefinition>> = T extends TypedRelyIOClient<infer TSchema> ? TSchema : never;
|
|
2723
2932
|
|
|
2724
|
-
export {
|
|
2933
|
+
export { type FullTextConfig as $, AutocompleteBuilder as A, type SimilarResult as B, type ClientSchema as C, type SimilarResponse as D, type ExtendedQueryResult as E, type SearchFilter as F, type SearchFields as G, HttpClient as H, BatchClient as I, BatchBuilder as J, type BatchMethod as K, type BatchOperation as L, type BatchOptions as M, type BatchOperationResult as N, type BatchSummary as O, type BatchResponse as P, AdhocQueryClient as Q, type Register as R, type SendOptions as S, TypedRelyIOClient as T, AdhocQueryBuilder as U, type FetchBlock as V, type AggregateBlock as W, type AggregateMetric as X, type SearchBlock as Y, type SimilarBlock as Z, type FilterValue as _, type TypedClientConfig as a, type AdhocQueryDefinition as a0, type AdhocQueryOptions as a1, type QueryMetadata as a2, type AdhocQueryResult as a3, AssetClient as a4, AssetFileBuilder as a5, AssetUploadBuilder as a6, isAssetEntry as a7, type AssetVisibility as a8, type FileStatus as a9, validateFile as aA, type FileBackend as aa, type AssetFileBlock as ab, type AssetFileExtracted as ac, type AssetUrls as ad, type AssetEntryResponse as ae, type PopulatedAssetReference as af, type PresignInput as ag, type PresignResult as ah, type ConfirmInput as ai, type ConfirmResult as aj, type ResolveUrlInput as ak, type ResolveUrlResult as al, type CreateAssetOptions as am, type WaitUntilReadyOptions as an, type MultipartCreateResult as ao, type MultipartPart as ap, type MultipartTarget as aq, type UploadProgress as ar, ResourceNotFoundError as as, ResourceConflictError as at, ResourceExpiredError as au, isResourceNotFound as av, type FileErrorCode as aw, FileUploadError as ax, FileValidationError as ay, type FileValidationConstraints as az, type RegisteredSchema as b, createClient as c, type ConditionalWriteOptions as d, entityTagOf as e, type RetryableWriteOptions as f, ChangesExpiredError as g, type Change as h, type ChangesOptions as i, type ChangesExpiredReason as j, ContentClient as k, SingletonClient as l, SettingsClient as m, ContentQueryBuilder as n, ContentByIdBuilder as o, type ChildrenOptions as p, type SingletonFetchOptions as q, type SettingsFetchOptions as r, SearchClient as s, SearchBuilder as t, SimilarBuilder as u, type SearchMode as v, type SearchResultItem as w, type SearchResponse as x, type AutocompleteSuggestion as y, type AutocompleteResponse as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as SchemaDefinition, b as SchemaContentTypeNames, h as SchemaAssetTypeNames, M as InferAssetType, c as SchemaSingletonNames, t as InferSingleton, g as SchemaSettingsGroupNames, E as InferSettingsGroup, e as SchemaQueryNames, f as SchemaLocaleCodes } from './define-schema-
|
|
1
|
+
import { J as MergedRelyIOConfig, A as ApiPath, a as ApiMethod, K as PathParamsOf, t as ApiResponse, W as Wire, s as RequestConfig, B as BaseContent, d as WhereClause, f as SortOptions, g as ContentQueryResult, Q as QueryOptions, C as CreateInput, U as UpdateInput, S as SDKError, x as BaseValidationError, w as ValidationViolation, N as components, O as paths, R as RelyIOConfig } from './index-FDak5ofk.js';
|
|
2
|
+
import { a as SchemaDefinition, b as SchemaContentTypeNames, h as SchemaAssetTypeNames, M as InferAssetType, c as SchemaSingletonNames, t as InferSingleton, g as SchemaSettingsGroupNames, E as InferSettingsGroup, e as SchemaQueryNames, f as SchemaLocaleCodes } from './define-schema-DzYXk4HL.js';
|
|
3
3
|
import { J as InferContentType } from './define-content-type-CBfnTWSS.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -109,6 +109,16 @@ declare class HttpClient {
|
|
|
109
109
|
* Get current base URL
|
|
110
110
|
*/
|
|
111
111
|
getBaseUrl(): string;
|
|
112
|
+
/**
|
|
113
|
+
* One attempt.
|
|
114
|
+
*
|
|
115
|
+
* The caller's `signal` and the timeout both end it, through one controller.
|
|
116
|
+
* The incumbent handed `fetch` the caller's signal **instead of** its own, so a
|
|
117
|
+
* request that passed a signal had no timeout at all — and a caller abort then
|
|
118
|
+
* surfaced as `Request timed out`. `timedOut` is what tells the two apart: a
|
|
119
|
+
* timeout is a `TimeoutError`, a caller abort is the platform's `AbortError`,
|
|
120
|
+
* rethrown as it came.
|
|
121
|
+
*/
|
|
112
122
|
private makeRequest;
|
|
113
123
|
/**
|
|
114
124
|
* Filter headers that browsers don't allow to be set manually
|
|
@@ -123,6 +133,7 @@ declare class HttpClient {
|
|
|
123
133
|
private mergeRequestConfig;
|
|
124
134
|
private buildQueryString;
|
|
125
135
|
private headersToObject;
|
|
136
|
+
/** A backoff the caller's abort cuts short; the next attempt then refuses to send. */
|
|
126
137
|
private sleep;
|
|
127
138
|
private log;
|
|
128
139
|
}
|
|
@@ -2386,11 +2397,166 @@ declare class AdhocQueryClient {
|
|
|
2386
2397
|
}
|
|
2387
2398
|
|
|
2388
2399
|
/**
|
|
2389
|
-
*
|
|
2390
|
-
*
|
|
2391
|
-
*
|
|
2400
|
+
* Content and resource errors.
|
|
2401
|
+
*
|
|
2402
|
+
* `ContentTypeNotFoundError` and `ContentNotFoundError` were deleted at API5.
|
|
2403
|
+
* The mapper reached them by sniffing `CONTENT_TYPE_NOT_FOUND` and
|
|
2404
|
+
* `CONTENT_NOT_FOUND`, neither of which is in the closed vocabulary, so neither
|
|
2405
|
+
* class was reachable. Both cases are `RESOURCE_NOT_FOUND`, whose declared
|
|
2406
|
+
* `details` are `{ kind, id? }` — the same two facts, from the one code a route
|
|
2407
|
+
* can actually declare.
|
|
2408
|
+
*/
|
|
2409
|
+
declare class ResourceNotFoundError extends SDKError {
|
|
2410
|
+
readonly code = "RESOURCE_NOT_FOUND";
|
|
2411
|
+
readonly retryable = false;
|
|
2412
|
+
constructor(message?: string, statusCode?: number, cause?: Error, context?: Record<string, unknown>);
|
|
2413
|
+
getUserMessage(): string;
|
|
2414
|
+
}
|
|
2415
|
+
declare class ResourceConflictError extends SDKError {
|
|
2416
|
+
readonly code = "RESOURCE_CONFLICT";
|
|
2417
|
+
readonly retryable = false;
|
|
2418
|
+
constructor(message?: string, statusCode?: number, cause?: Error, context?: Record<string, unknown>);
|
|
2419
|
+
getUserMessage(): string;
|
|
2420
|
+
}
|
|
2421
|
+
declare class ResourceExpiredError extends SDKError {
|
|
2422
|
+
readonly code = "RESOURCE_EXPIRED";
|
|
2423
|
+
readonly retryable = false;
|
|
2424
|
+
constructor(message?: string, statusCode?: number, cause?: Error, context?: Record<string, unknown>);
|
|
2425
|
+
getUserMessage(): string;
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* "Did the service say this resource does not exist?"
|
|
2429
|
+
*
|
|
2430
|
+
* Reads the **code**, not the status. Four contract codes are 4xx on a read and
|
|
2431
|
+
* only one of them means "not there"; the incumbent checked `statusCode === 404`
|
|
2432
|
+
* on the thrown value, and a second arm duck-typed a plain object for the same
|
|
2433
|
+
* number so a hand-written test double would pass. Both are the branch
|
|
2434
|
+
* `INV-API-CLIENT-IS-DERIVED` forbids where a code exists — and the second one
|
|
2435
|
+
* only existed because the tests faked the boundary (rule 20). They now stub
|
|
2436
|
+
* `fetch`, so the double is gone with the branch.
|
|
2437
|
+
*/
|
|
2438
|
+
declare function isResourceNotFound(error: unknown): boolean;
|
|
2439
|
+
|
|
2440
|
+
/**
|
|
2441
|
+
* `relyio.changes()` — the changes feed as a typed long-poll iterator
|
|
2442
|
+
* (`sdk-surfaces-spec.md` decisions 16–18).
|
|
2443
|
+
*
|
|
2444
|
+
* Long-poll only, on purpose. `GET /v1/changes` is an ordinary cursor-paged
|
|
2445
|
+
* collection the committed document declares, so each poll is one `send` over
|
|
2446
|
+
* the one HTTP client (`INV-SS-ONE-CORE`, `INV-API-CLIENT-IS-DERIVED`). The SSE
|
|
2447
|
+
* branch the route also serves would be a second transport path inside that
|
|
2448
|
+
* client, and `parseResponse` buffers a whole body; it stays for `EventSource`
|
|
2449
|
+
* and curl consumers.
|
|
2450
|
+
*/
|
|
2451
|
+
|
|
2452
|
+
type PollChanges = paths['/v1/changes']['get'];
|
|
2453
|
+
/**
|
|
2454
|
+
* The 200 body the document declares, read from its `application/json` content
|
|
2455
|
+
* **by name**. The route also negotiates `text/event-stream`; naming the JSON
|
|
2456
|
+
* content is what keeps that alternate from changing this type when the
|
|
2457
|
+
* document gains it.
|
|
2458
|
+
*/
|
|
2459
|
+
type ChangesPageBody = PollChanges['responses'][200]['content']['application/json'];
|
|
2460
|
+
/**
|
|
2461
|
+
* One change, as the committed document describes an item of the feed's `data`
|
|
2462
|
+
* (`INV-SS-CHANGE-IS-IDS`: ids, content type, locale, kind and cursor — never a
|
|
2463
|
+
* document).
|
|
2464
|
+
*
|
|
2465
|
+
* Read from the document, never written here: the api's route row names the
|
|
2466
|
+
* `Change` component schema, and a change to it reaches this type when the
|
|
2467
|
+
* document is regenerated. `changes.types.ts` holds it equal to the document's
|
|
2468
|
+
* item, and fails if it is ever `unknown` again.
|
|
2469
|
+
*/
|
|
2470
|
+
type Change = ChangesPageBody['data'][number];
|
|
2471
|
+
/** Why a cursor could no longer be replayed. `unknown` when the message named neither. */
|
|
2472
|
+
type ChangesExpiredReason = 'retention' | 'dataset-replaced' | 'unknown';
|
|
2473
|
+
/**
|
|
2474
|
+
* `RESOURCE_EXPIRED` from the changes feed: the cursor names a position the
|
|
2475
|
+
* ledger can no longer replay from (`INV-SS-CURSOR-REPLAYS`). The consumer
|
|
2476
|
+
* resyncs from the read path and starts again without a cursor.
|
|
2477
|
+
*
|
|
2478
|
+
* A `ResourceExpiredError`, so code that already catches that still does. The
|
|
2479
|
+
* refusal declares no details, so `reason` is read from the message the api
|
|
2480
|
+
* writes (`apps/services/api/src/changes/changes-request.ts` `refusalOf`).
|
|
2481
|
+
*/
|
|
2482
|
+
declare class ChangesExpiredError extends ResourceExpiredError {
|
|
2483
|
+
readonly reason: ChangesExpiredReason;
|
|
2484
|
+
/** The base class's signature, so `withContext` can rebuild one. */
|
|
2485
|
+
constructor(message: string, statusCode?: number, cause?: Error, context?: Record<string, unknown>);
|
|
2486
|
+
static of(expired: ResourceExpiredError): ChangesExpiredError;
|
|
2487
|
+
}
|
|
2488
|
+
interface ChangesOptions {
|
|
2489
|
+
/**
|
|
2490
|
+
* A `page.nextCursor` — or a change's `cursor` — from an earlier poll. Omitted,
|
|
2491
|
+
* the first poll answers the dataset's current position and no changes, at
|
|
2492
|
+
* once, and the feed starts from there.
|
|
2493
|
+
*/
|
|
2494
|
+
since?: string;
|
|
2495
|
+
/** Content types to keep. Omitted keeps every type; an empty list is refused (400). */
|
|
2496
|
+
types?: readonly string[];
|
|
2497
|
+
/**
|
|
2498
|
+
* Entry ids to keep. Omitted keeps every entry. The api refuses more than it
|
|
2499
|
+
* allows (100 today) as `REQUEST_INVALID`, thrown from the iterator as an
|
|
2500
|
+
* `InvalidPayloadError` on the first poll; the SDK does not restate the
|
|
2501
|
+
* cap, so it cannot drift from the service's.
|
|
2502
|
+
*/
|
|
2503
|
+
ids?: readonly string[];
|
|
2504
|
+
/** Ledger rows one poll scans, 1 to 500; the api defaults to 100. */
|
|
2505
|
+
limit?: number;
|
|
2506
|
+
/**
|
|
2507
|
+
* Ends the iteration. An abort — in flight, between polls, or while waiting
|
|
2508
|
+
* out a `Retry-After` — makes the `for await` **complete**, with no further
|
|
2509
|
+
* request and no `AbortError` thrown into the loop.
|
|
2510
|
+
*/
|
|
2511
|
+
signal?: AbortSignal;
|
|
2512
|
+
/**
|
|
2513
|
+
* What to do when the cursor has expired.
|
|
2514
|
+
*
|
|
2515
|
+
* - `'throw'` (default) — the iterator throws {@link ChangesExpiredError}.
|
|
2516
|
+
* - `'resync'` — restart from the dataset's current position and keep going.
|
|
2517
|
+
* - a function — resync, and call it with the error once the new position is
|
|
2518
|
+
* taken and before any change after it is yielded. This is the observable
|
|
2519
|
+
* form: whatever the consumer derived from the feed may be stale, so the
|
|
2520
|
+
* function is where it invalidates everything. The iterator waits for it.
|
|
2521
|
+
*/
|
|
2522
|
+
onExpired?: 'throw' | 'resync' | ((expired: ChangesExpiredError) => void | Promise<void>);
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
/**
|
|
2526
|
+
* Any schema the client can be typed by. `any` is deliberate: the client accepts whatever content
|
|
2527
|
+
* types, components, singletons, queries and settings groups a customer declares.
|
|
2528
|
+
*
|
|
2529
|
+
* This is the constraint `TypedRelyIOClient`'s `TSchema` carries, so `RegisteredSchema` is inferred
|
|
2530
|
+
* against the same one — `createClient` returns `TypedRelyIOClient<RegisteredSchema>`, and a schema
|
|
2531
|
+
* inferred against any wider alias would not be provably inside the client's bound.
|
|
2392
2532
|
*/
|
|
2393
2533
|
type AnySchemaDefinition = SchemaDefinition<any, any, any, any, any>;
|
|
2534
|
+
/**
|
|
2535
|
+
* The seam `relyio generate-types` fills (`INV-SS-TYPES-INFERRED`).
|
|
2536
|
+
*
|
|
2537
|
+
* Empty here on purpose. The generated `schema.ts` augments it —
|
|
2538
|
+
*
|
|
2539
|
+
* ```ts
|
|
2540
|
+
* declare module '@relyio/sdk' {
|
|
2541
|
+
* interface Register {
|
|
2542
|
+
* schema: typeof schema
|
|
2543
|
+
* }
|
|
2544
|
+
* }
|
|
2545
|
+
* ```
|
|
2546
|
+
*
|
|
2547
|
+
* — and from then on `createClient({ apiKey })`, with no generic and no `schema:`, is typed by that
|
|
2548
|
+
* schema. The pattern is TanStack Router's. It is type-level only: nothing at runtime reads it.
|
|
2549
|
+
*/
|
|
2550
|
+
interface Register {
|
|
2551
|
+
}
|
|
2552
|
+
/**
|
|
2553
|
+
* The schema the project registered through `Register`, or `undefined` when nothing did — which is
|
|
2554
|
+
* the untyped client, exactly as before the generator ran.
|
|
2555
|
+
*/
|
|
2556
|
+
type RegisteredSchema = Register extends {
|
|
2557
|
+
schema: infer S extends AnySchemaDefinition;
|
|
2558
|
+
} ? S : undefined;
|
|
2559
|
+
|
|
2394
2560
|
/**
|
|
2395
2561
|
* Client configuration with optional schema
|
|
2396
2562
|
*/
|
|
@@ -2555,6 +2721,32 @@ declare class TypedRelyIOClient<TSchema extends AnySchemaDefinition | undefined
|
|
|
2555
2721
|
* ```
|
|
2556
2722
|
*/
|
|
2557
2723
|
batch(): BatchBuilder<NonNullable<TSchema>>;
|
|
2724
|
+
/**
|
|
2725
|
+
* Follow the dataset's changes feed: each write this key can see, as ids, in
|
|
2726
|
+
* order, long-polled from `GET /v1/changes`.
|
|
2727
|
+
*
|
|
2728
|
+
* Lazy — nothing is requested until the first `next()`. It runs until
|
|
2729
|
+
* `signal` aborts, which ends the `for await` cleanly rather than throwing.
|
|
2730
|
+
* A change names what changed; refetch it through the ordinary read path
|
|
2731
|
+
* (`INV-SS-CHANGE-IS-IDS`).
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* ```typescript
|
|
2735
|
+
* const controller = new AbortController()
|
|
2736
|
+
* for await (const change of relyio.changes({ since: cursor, types: ['post'], signal: controller.signal })) {
|
|
2737
|
+
* // { entryId, contentType, locale, kind, cursor }
|
|
2738
|
+
* }
|
|
2739
|
+
* ```
|
|
2740
|
+
*
|
|
2741
|
+
* @example Resync when the cursor has expired
|
|
2742
|
+
* ```typescript
|
|
2743
|
+
* for await (const change of relyio.changes({
|
|
2744
|
+
* since: cursor,
|
|
2745
|
+
* onExpired: async () => invalidateEverything(),
|
|
2746
|
+
* })) { … }
|
|
2747
|
+
* ```
|
|
2748
|
+
*/
|
|
2749
|
+
changes(options?: ChangesOptions): AsyncIterable<Change>;
|
|
2558
2750
|
/**
|
|
2559
2751
|
* Build and execute an ad-hoc query dynamically
|
|
2560
2752
|
*
|
|
@@ -2713,12 +2905,29 @@ declare class TypedRelyIOClient<TSchema extends AnySchemaDefinition | undefined
|
|
|
2713
2905
|
* // Content type names autocomplete!
|
|
2714
2906
|
* const products = await relyio.content('product').fetchAll()
|
|
2715
2907
|
* ```
|
|
2716
|
-
|
|
2908
|
+
*
|
|
2909
|
+
* @example After `relyio generate-types` (inferred, `INV-SS-TYPES-INFERRED`)
|
|
2910
|
+
* ```typescript
|
|
2911
|
+
* import { createClient } from '@relyio/sdk'
|
|
2912
|
+
*
|
|
2913
|
+
* // The generated `schema.ts` augments `Register`, so no generic and no `schema:` are needed
|
|
2914
|
+
* const relyio = createClient({ apiKey: process.env.RELYIO_API_KEY! })
|
|
2915
|
+
* ```
|
|
2916
|
+
*
|
|
2917
|
+
* The overload without a schema comes first on purpose. Behind the generic one it was never
|
|
2918
|
+
* chosen: with no `schema` to infer from, `TSchema` fell back to its constraint and the call
|
|
2919
|
+
* resolved to `TypedRelyIOClient<AnySchemaDefinition>`. First, it takes every call that passes no
|
|
2920
|
+
* schema, and returns the registered schema's client — or the untyped one when nothing registered.
|
|
2921
|
+
* A `schema:` value fails its `schema?: undefined`, and an explicit generic skips it because it has
|
|
2922
|
+
* no type parameter, so both reach the generic overload unchanged.
|
|
2923
|
+
*/
|
|
2924
|
+
declare function createClient(config: RelyIOConfig & {
|
|
2925
|
+
schema?: undefined;
|
|
2926
|
+
}): TypedRelyIOClient<RegisteredSchema>;
|
|
2717
2927
|
declare function createClient<TSchema extends AnySchemaDefinition>(config: TypedClientConfig<TSchema>): TypedRelyIOClient<TSchema>;
|
|
2718
|
-
declare function createClient(config: RelyIOConfig): TypedRelyIOClient<undefined>;
|
|
2719
2928
|
/**
|
|
2720
2929
|
* Helper type to extract schema from client
|
|
2721
2930
|
*/
|
|
2722
2931
|
type ClientSchema<T extends TypedRelyIOClient<AnySchemaDefinition>> = T extends TypedRelyIOClient<infer TSchema> ? TSchema : never;
|
|
2723
2932
|
|
|
2724
|
-
export {
|
|
2933
|
+
export { type FullTextConfig as $, AutocompleteBuilder as A, type SimilarResult as B, type ClientSchema as C, type SimilarResponse as D, type ExtendedQueryResult as E, type SearchFilter as F, type SearchFields as G, HttpClient as H, BatchClient as I, BatchBuilder as J, type BatchMethod as K, type BatchOperation as L, type BatchOptions as M, type BatchOperationResult as N, type BatchSummary as O, type BatchResponse as P, AdhocQueryClient as Q, type Register as R, type SendOptions as S, TypedRelyIOClient as T, AdhocQueryBuilder as U, type FetchBlock as V, type AggregateBlock as W, type AggregateMetric as X, type SearchBlock as Y, type SimilarBlock as Z, type FilterValue as _, type TypedClientConfig as a, type AdhocQueryDefinition as a0, type AdhocQueryOptions as a1, type QueryMetadata as a2, type AdhocQueryResult as a3, AssetClient as a4, AssetFileBuilder as a5, AssetUploadBuilder as a6, isAssetEntry as a7, type AssetVisibility as a8, type FileStatus as a9, validateFile as aA, type FileBackend as aa, type AssetFileBlock as ab, type AssetFileExtracted as ac, type AssetUrls as ad, type AssetEntryResponse as ae, type PopulatedAssetReference as af, type PresignInput as ag, type PresignResult as ah, type ConfirmInput as ai, type ConfirmResult as aj, type ResolveUrlInput as ak, type ResolveUrlResult as al, type CreateAssetOptions as am, type WaitUntilReadyOptions as an, type MultipartCreateResult as ao, type MultipartPart as ap, type MultipartTarget as aq, type UploadProgress as ar, ResourceNotFoundError as as, ResourceConflictError as at, ResourceExpiredError as au, isResourceNotFound as av, type FileErrorCode as aw, FileUploadError as ax, FileValidationError as ay, type FileValidationConstraints as az, type RegisteredSchema as b, createClient as c, type ConditionalWriteOptions as d, entityTagOf as e, type RetryableWriteOptions as f, ChangesExpiredError as g, type Change as h, type ChangesOptions as i, type ChangesExpiredReason as j, ContentClient as k, SingletonClient as l, SettingsClient as m, ContentQueryBuilder as n, ContentByIdBuilder as o, type ChildrenOptions as p, type SingletonFetchOptions as q, type SettingsFetchOptions as r, SearchClient as s, SearchBuilder as t, SimilarBuilder as u, type SearchMode as v, type SearchResultItem as w, type SearchResponse as x, type AutocompleteSuggestion as y, type AutocompleteResponse as z };
|