@relyio/sdk 0.6.0 → 0.8.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +400 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/{chunk-DY2XT7OF.cjs → chunk-72UK5U7T.cjs} +70 -60
  4. package/dist/{chunk-I3ESNANB.js → chunk-H6IBQSMM.js} +2 -2
  5. package/dist/{chunk-7ABNXVWL.js → chunk-QFHVF3YF.js} +1617 -404
  6. package/dist/{chunk-HT6NFRM2.cjs → chunk-TZL374LS.cjs} +2 -2
  7. package/dist/{chunk-GCMQUM6N.cjs → chunk-XIE7WJV3.cjs} +1621 -407
  8. package/dist/{chunk-XJVY2CLY.js → chunk-YEJUMW4X.js} +70 -60
  9. package/dist/client/index.cjs +4 -3
  10. package/dist/client/index.d.cts +5 -4
  11. package/dist/client/index.d.ts +5 -4
  12. package/dist/client/index.js +2 -1
  13. package/dist/{index-d1Kz1e19.d.cts → define-content-type-cEGjIwT5.d.cts} +1859 -733
  14. package/dist/{index-yPbhZc6q.d.ts → define-content-type-cEGjIwT5.d.ts} +1859 -733
  15. package/dist/{define-schema-1kr2HIzN.d.cts → define-schema-BPj2srgh.d.ts} +189 -85
  16. package/dist/{define-schema-ChvAzY8H.d.ts → define-schema-DgbJ5Kwn.d.cts} +189 -85
  17. package/dist/index-B_rIWO_l.d.cts +860 -0
  18. package/dist/index-Cv4tmcrw.d.ts +860 -0
  19. package/dist/{index-Df1VsfJR.d.cts → index-DBoPPlT1.d.cts} +684 -277
  20. package/dist/{index-XqoGUaAY.d.ts → index-yRJ2IqM_.d.ts} +684 -277
  21. package/dist/index.cjs +148 -124
  22. package/dist/index.d.cts +174 -64
  23. package/dist/index.d.ts +174 -64
  24. package/dist/index.js +43 -18
  25. package/dist/schema/index.cjs +35 -35
  26. package/dist/schema/index.d.cts +13 -11
  27. package/dist/schema/index.d.ts +13 -11
  28. package/dist/schema/index.js +1 -1
  29. package/dist/types/index.d.cts +2 -2
  30. package/dist/types/index.d.ts +2 -2
  31. package/dist/utils/index.cjs +19 -19
  32. package/dist/utils/index.d.cts +10 -1
  33. package/dist/utils/index.d.ts +10 -1
  34. package/dist/utils/index.js +1 -1
  35. package/package.json +2 -1
  36. package/dist/define-content-type-CDB3kyeA.d.cts +0 -1173
  37. package/dist/define-content-type-CDB3kyeA.d.ts +0 -1173
package/dist/index.d.cts CHANGED
@@ -1,11 +1,13 @@
1
- import { C as ChangesExpiredError, a as Change, b as ChangesExpiredReason } from './index-Df1VsfJR.cjs';
2
- export { A as ActiveSandbox, a1 as AdhocAggregateBlock, a0 as AdhocFetchBlock, $ as AdhocQueryBuilder, _ as AdhocQueryClient, a7 as AdhocQueryDefinition, a8 as AdhocQueryOptions, aa as AdhocQueryResult, a3 as AdhocSearchBlock, a4 as AdhocSimilarBlock, a2 as AggregateMetric, ab as AssetClient, al as AssetEntryResponse, ai as AssetFileBlock, ac as AssetFileBuilder, aj as AssetFileExtracted, ad as AssetUploadBuilder, ak as AssetUrls, af as AssetVisibility, w as AutocompleteBuilder, F as AutocompleteResponse, D as AutocompleteSuggestion, Q as BatchBuilder, O as BatchClient, U as BatchMethod, V as BatchOperation, X as BatchOperationResult, W as BatchOptions, Z as BatchResponse, Y as BatchSummary, k as ChangesHeadOptions, l as ChangesOptions, r as ChildrenOptions, e as ClientSchema, i as ConditionalWriteOptions, ap as ConfirmInput, aq as ConfirmResult, q as ContentByIdBuilder, m as ContentClient, p as ContentQueryBuilder, at as CreateAssetOptions, E as ExtendedQueryResult, ah as FileBackend, aD as FileErrorCode, ag as FileStatus, aE as FileUploadError, aG as FileValidationConstraints, aF as FileValidationError, a5 as FilterValue, a6 as FullTextConfig, H as HttpClient, av as MultipartCreateResult, aw as MultipartPart, ax as MultipartTarget, am as PopulatedAssetReference, an as PresignInput, ao as PresignResult, P as Project, a9 as QueryMetadata, R as Register, f as RegisteredSchema, ar as ResolveUrlInput, as as ResolveUrlResult, aA as ResourceConflictError, aB as ResourceExpiredError, az as ResourceNotFoundError, j as RetryableWriteOptions, S as SandboxState, v as SearchBuilder, u as SearchClient, N as SearchEntry, K as SearchFields, J as SearchFilter, y as SearchMode, B as SearchResponse, z as SearchResultItem, L as SearchSort, M as SearchTypeName, g as SendOptions, o as SettingsClient, t as SettingsFetchOptions, x as SimilarBuilder, I as SimilarResponse, G as SimilarResult, n as SingletonClient, s as SingletonFetchOptions, d as TypedClientConfig, T as TypedRelyIOClient, ay as UploadProgress, au as WaitUntilReadyOptions, c as createClient, c as default, h as entityTagOf, ae as isAssetEntry, aC as isResourceNotFound, aH as validateFile } from './index-Df1VsfJR.cjs';
1
+ import { C as Change, a as ChangesExpiredError, b as ChangesExpiredReason } from './index-DBoPPlT1.cjs';
2
+ export { A as ActiveSandbox, a5 as AdhocAggregateBlock, a4 as AdhocFetchBlock, a3 as AdhocQueryBuilder, a2 as AdhocQueryClient, aa as AdhocQueryDefinition, ab as AdhocQueryOptions, ad as AdhocQueryResult, a7 as AdhocSearchBlock, a6 as AggregateMetric, ae as AssetClient, ap as AssetEntryResponse, al as AssetFileBlock, af as AssetFileBuilder, am as AssetFileExtracted, ag as AssetUploadBuilder, ao as AssetUrls, ai as AssetVisibility, x as AutocompleteBuilder, J as AutocompleteResponse, I as AutocompleteSuggestion, X as BatchBuilder, W as BatchClient, Y as BatchMethod, Z as BatchOperation, $ as BatchOperationResult, _ as BatchOptions, a1 as BatchResponse, a0 as BatchSummary, k as ChangesHeadOptions, l as ChangesOptions, s as ChildrenOptions, e as ClientSchema, i as ConditionalWriteOptions, at as ConfirmInput, au as ConfirmResult, r as ContentByIdBuilder, n as ContentClient, q as ContentQueryBuilder, ax as CreateAssetOptions, E as ExtendedQueryResult, F as FeedChange, ak as FileBackend, aH as FileErrorCode, aj as FileStatus, an as FileStatusResult, aJ as FileUploadError, aI as FileUploadErrorCode, aL as FileValidationConstraints, aK as FileValidationError, a8 as FilterValue, a9 as FullTextConfig, H as HttpClient, L as LIVE_KEEPALIVE_INTERVAL_MS, m as LiveChangesOptions, az as MultipartCreateResult, aA as MultipartPart, aB as MultipartTarget, aq as PopulatedAssetReference, ar as PresignInput, as as PresignResult, P as Project, ac as QueryMetadata, R as Register, f as RegisteredSchema, av as ResolveUrlInput, aw as ResolveUrlResult, aE as ResourceConflictError, aF as ResourceExpiredError, aD as ResourceNotFoundError, j as RetryableWriteOptions, S as SandboxState, w as SearchBuilder, v as SearchClient, V as SearchEntry, O as SearchFields, N as SearchFilter, D as SearchHitMetadata, z as SearchMode, G as SearchResponse, B as SearchResultItem, Q as SearchSort, U as SearchTypeName, g as SendOptions, p as SettingsClient, u as SettingsFetchOptions, y as SimilarBuilder, M as SimilarResponse, K as SimilarResult, o as SingletonClient, t as SingletonFetchOptions, d as TypedClientConfig, T as TypedRelyIOClient, aC as UploadProgress, ay as WaitUntilReadyOptions, c as createClient, c as default, h as entityTagOf, ah as isAssetEntry, aG as isResourceNotFound, aM as validateFile } from './index-DBoPPlT1.cjs';
3
3
  export { fields } from './schema/index.cjs';
4
- import { S as SDKError, B as BaseContent } from './index-d1Kz1e19.cjs';
5
- export { a as ApiMethod, A as ApiPath, v as ApiResponse, b as ApiSuccessBody, z as BaseValidationError, s as CacheConfig, x as CacheStrategy, i as ContentQueryResult, n as ContentTypeSchema, C as CreateInput, l as CustomQuery, D as DebugConfig, E as Environment, o as FieldOptions, F as FieldTypeName, K as InvalidFieldTypeError, I as InvalidPayloadError, L as LogLevel, M as MatchRouteOptions, P as PerformanceMetrics, Q as QueryOptions, t as RealtimeConfig, q as RealtimeEvent, p as RealtimeEventType, R as RelyIOConfig, u as RequestConfig, J as RequiredFieldError, w as RetryConfig, c as RouteMatch, H as SchemaValidationError, k as SettingsGroup, j as SingletonContent, h as SortOptions, r as SubscriptionOptions, U as UpdateInput, G as ValidationError, V as ValidationRule, y as ValidationViolation, f as WhereClause, e as WhereFieldCondition, g as WhereOperator, d as WhereScalar, W as Wire, m as matchRoute } from './index-d1Kz1e19.cjs';
4
+ import { S as SDKError, B as BaseContent } from './index-B_rIWO_l.cjs';
5
+ export { c as ApiMethod, A as ApiPath, w as ApiResponse, d as ApiSuccessBody, H as BaseValidationError, t as CacheConfig, y as CacheStrategy, k as ContentQueryResult, o as ContentTypeSchema, C as CreateInput, n as CustomQuery, D as DebugConfig, E as Environment, p as FieldOptions, F as FieldTypeName, J as InvalidPayloadError, L as LiveWebSocket, b as LiveWebSocketConstructor, z as LogLevel, M as MatchRouteOptions, P as PerformanceMetrics, Q as QueryOptions, u as RealtimeConfig, r as RealtimeEvent, q as RealtimeEventType, R as RelyIOConfig, a as RelyIOConfigUpdate, v as RequestConfig, x as RetryConfig, e as RouteMatch, l as SingletonContent, j as SortOptions, s as SubscriptionOptions, U as UpdateInput, I as ValidationError, V as ValidationRule, G as ValidationViolation, h as WhereClause, g as WhereFieldCondition, i as WhereOperator, f as WhereScalar, W as Wire, m as matchRoute } from './index-B_rIWO_l.cjs';
6
+ import { VisitorRetry } from './live-visitor.js';
6
7
  export { camelToSnake, createDeferred, debounce, deepClone, generateId, isBrowser, isNode, isPlainObject, isValidEmail, isValidUrl, mergeDeep, omit, pick, retry, sleep, snakeToCamel, throttle, toSafeString } from './utils/index.cjs';
7
- export { a6 as AggregateBlock, C as ComponentConfig, s as ComponentDefinition, t as ComponentMetadata, a5 as FetchBlock, ag as FilterDefinition, ae as IncludeDefinition, aq as InferQueryParams, ap as InferQueryResponse, a3 as QueryConfig, a4 as QueryDefinition, h as SchemaAssetTypeNames, S as SchemaConfig, b as SchemaContentTypeNames, a as SchemaDefinition, i as SchemaEntry, j as SchemaEntryOf, f as SchemaLocaleCodes, e as SchemaQueryNames, g as SchemaSettingsGroupNames, c as SchemaSingletonNames, a7 as SearchBlock, af as SelectMapping, x as SettingsGroupConfig, y as SettingsGroupDefinition, a8 as SimilarBlock, ac as SortCondition, a9 as WhereCondition, r as defineComponent, a2 as defineQuery, d as defineSchema, w as defineSettingsGroup } from './define-schema-1kr2HIzN.cjs';
8
- export { a2 as AssetTypeConfig, a5 as AssetTypeDefinition, n as BaseFieldConfig, K as ContentTypeConfig, M as ContentTypeConfigWithFields, N as ContentTypeConfigWithFieldsets, O as ContentTypeDefinition, P as EntryMetadata, c as FieldDefinition, b as FieldRule, u as FieldSchemaContext, o as FieldType, F as FieldUIConfig, v as FieldValue, w as FieldValues, J as Fieldset, a9 as FileKindConfig, an as FileScanConfig, am as FileUploadConfig, af as ImageExifConfig, a7 as ImageKindConfig, ae as ImageSourceConfig, ad as ImageUploadConfig, a6 as InferAssetType, Q as InferContentType, a0 as InferSingleton, $ as InferSingletonContentType, W as LocalePublicationFields, L as LocalizationConfig, Z as SingletonContentTypeDefinition, _ as SingletonMetadata, z as UnresolvedComponent, y as UnresolvedEntry, ag as VariantDefinition, aj as VideoCaptionsConfig, ak as VideoDownloadConfig, a8 as VideoKindConfig, ai as VideoPosterConfig, ah as VideoUploadConfig, al as VideoWatermarkConfig, a1 as defineAssetType, G as defineContentType, Y as defineSingleton, X as defineSingletonContentType, H as fieldset } from './define-content-type-CDB3kyeA.cjs';
8
+ import { Q as EntryMetadata } from './define-content-type-cEGjIwT5.cjs';
9
+ export { a5 as AssetTypeConfig, a9 as AssetTypeDefinition, n as BaseFieldConfig, M as ContentTypeConfig, N as ContentTypeConfigWithFields, O as ContentTypeConfigWithFieldsets, P as ContentTypeDefinition, c as FieldDefinition, b as FieldRule, v as FieldSchemaContext, p as FieldType, F as FieldUIConfig, w as FieldValue, x as FieldValues, K as Fieldset, ad as FileKindConfig, ar as FileScanConfig, aq as FileUploadConfig, aj as ImageExifConfig, ab as ImageKindConfig, ai as ImageSourceConfig, ah as ImageUploadConfig, aa as InferAssetType, W as InferContentType, a3 as InferSingleton, a2 as InferSingletonContentType, X as LocalePublicationFields, L as LocalizationConfig, a0 as SingletonContentTypeDefinition, a1 as SingletonMetadata, G as UnresolvedComponent, z as UnresolvedEntry, ak as VariantDefinition, an as VideoCaptionsConfig, ao as VideoDownloadConfig, ac as VideoKindConfig, am as VideoPosterConfig, al as VideoUploadConfig, ap as VideoWatermarkConfig, a4 as defineAssetType, H as defineContentType, Z as defineSingleton, Y as defineSingletonContentType, J as fieldset } from './define-content-type-cEGjIwT5.cjs';
10
+ export { aa as AggregateBlock, C as ComponentConfig, s as ComponentDefinition, t as ComponentMetadata, a9 as FetchBlock, an as FilterDefinition, aj as IncludeDefinition, ax as InferQueryParams, aw as InferQueryResponse, a5 as QueryConfig, a6 as QueryDefinition, h as SchemaAssetTypeNames, S as SchemaConfig, b as SchemaContentTypeNames, a as SchemaDefinition, i as SchemaEntry, j as SchemaEntryOf, f as SchemaLocaleCodes, e as SchemaQueryNames, g as SchemaSettingsGroupNames, c as SchemaSingletonNames, ab as SearchBlock, am as SelectMapping, x as SettingsGroupConfig, y as SettingsGroupDefinition, ah as SortCondition, ac as WhereCondition, r as defineComponent, a4 as defineQuery, d as defineSchema, w as defineSettingsGroup } from './define-schema-DgbJ5Kwn.cjs';
9
11
  import './dev-handshake/index.cjs';
10
12
 
11
13
  /**
@@ -43,25 +45,35 @@ declare const isPublishableKey: (apiKey: string | undefined) => boolean;
43
45
  * state mean to it.
44
46
  *
45
47
  * **The transport is a parameter.** A source opens from a cursor and yields
46
- * changes. Today that is `relyio.changes()`, the long-poll, with whatever filter
47
- * the caller binds in. LV5.2 (REL-1158, `live-layer-spec.md` LV5) adds a
48
- * second — a WebSocket to the live edge, falling back to polling the edge when a
49
- * socket cannot open — and hands it to this loop, with a classifier for its
50
- * refusal close codes. That source calls `opened()` on the socket's `open`: a
51
- * Worker deploy drops every socket, and a quiet dataset delivers no change, so
52
- * without it each deploy would double the next reconnect's wait up to thirty
53
- * seconds. With it, every drop after a healthy connection waits the base
54
- * ceiling. The loop, and every handler a surface passes it, stay as they are.
55
- *
56
- * The long-poll does not call `opened()`: `relyio.changes()` takes the public
57
- * `ChangesOptions`, which does not carry it, so its back-off resets only on a
58
- * delivered change — as it did before this loop existed.
48
+ * changes. There are two: `relyio.changes()`, the long-poll over `/v1/changes`,
49
+ * and `relyio.liveChanges()` (LV5.2, REL-1158), a WebSocket to the live edge that
50
+ * polls the edge when a socket cannot open — each with whatever filter the caller
51
+ * binds in. The edge's refusals are `LiveEdgeError`s, which the default
52
+ * classifier reads, so neither needs a classifier of its own.
53
+ *
54
+ * The edge source calls `opened()` on the feed's `feed.opened` frame — not the
55
+ * socket's `open` event, which a refusal fires too, because the edge accepts a
56
+ * socket to close it with a code — and on each answered poll. A Worker deploy
57
+ * drops every socket, and a quiet dataset delivers no change, so without it each
58
+ * deploy would double the next reconnect's wait up to thirty seconds. It calls
59
+ * `reached()` with the cursor `feed.opened` names, so a socket dropped before its
60
+ * first change reconnects from that cursor instead of re-reading everything.
61
+ *
62
+ * The long-poll calls neither: `relyio.changes()` takes the public
63
+ * `ChangesOptions`, which carries neither, so its back-off resets only on a
64
+ * delivered change and a failure before its first change resyncs — as before
65
+ * this loop existed.
59
66
  */
60
67
 
61
68
  /** The ceiling of the first wait after a failure worth retrying; doubled per consecutive failure. */
62
69
  declare const FOLLOW_RETRY_BASE_MS = 1000;
63
70
  /** The ceiling never doubles past this. A server's hint is not capped by it. */
64
71
  declare const FOLLOW_RETRY_MAX_MS = 30000;
72
+ /**
73
+ * A failure that backs off (a verdict's `backOffMs`) never waits longer than this, however often it
74
+ * repeats. A server's hint is not capped by it.
75
+ */
76
+ declare const FOLLOW_BACK_OFF_MAX_MS: number;
65
77
  /** What the loop hands a source each time it opens one. */
66
78
  interface ChangeSourceOptions {
67
79
  /**
@@ -90,11 +102,29 @@ interface ChangeSourceOptions {
90
102
  * already failed changes nothing.
91
103
  */
92
104
  readonly opened: () => void;
105
+ /**
106
+ * Call with a position the transport has reached without a change to carry
107
+ * it — the cursor a socket's `feed.opened` names, or a poll's answer with no
108
+ * changes. The loop reopens from it after a failure, as it would from a
109
+ * delivered change's cursor, so a connection dropped before its first change
110
+ * replays from there rather than re-reading everything.
111
+ *
112
+ * Call it only between changes, once every change before that position has
113
+ * been yielded and the loop has asked for the next — a position ahead of a
114
+ * change still being applied would skip that change on the next open. A call
115
+ * from an open that has already failed changes nothing.
116
+ */
117
+ readonly reached: (cursor: string) => void;
93
118
  }
94
119
  /**
95
120
  * A transport for the changes feed: open from a position and yield each change,
96
121
  * in feed order, as ids (`INV-SS-CHANGE-IS-IDS`).
97
122
  *
123
+ * `C` is what it yields. `relyio.changes()` and `relyio.liveChanges()` yield a
124
+ * `FeedChange` — a `Change` with the position a refetch for it names
125
+ * (`fresh`) — and the loop hands `onChange` exactly that. A source of plain
126
+ * `Change`s is followed alike and hands plain `Change`s on.
127
+ *
98
128
  * A source ends **only** when its signal aborts. Every other end — a dropped
99
129
  * connection, a refusal, a socket closed by a deploy — is thrown, so the loop's
100
130
  * classifier can decide between reconnecting and stopping. `relyio.changes()` is
@@ -104,7 +134,7 @@ interface ChangeSourceOptions {
104
134
  * const source: ChangeSource = from => relyio.changes({ ...from, types: ['post'] })
105
135
  * ```
106
136
  */
107
- type ChangeSource = (options: ChangeSourceOptions) => AsyncIterable<Change>;
137
+ type ChangeSource<C extends Change = Change> = (options: ChangeSourceOptions) => AsyncIterable<C>;
108
138
  /**
109
139
  * Why everything derived from the feed may be stale, so the consumer re-reads
110
140
  * what it holds:
@@ -112,9 +142,10 @@ type ChangeSource = (options: ChangeSourceOptions) => AsyncIterable<Change>;
112
142
  * - `expired` — the cursor could no longer be replayed. The source has resynced
113
143
  * to the current position and yields nothing after it until the handler
114
144
  * settles.
115
- * - `no-cursor` — the source failed before any change arrived, so there is no
116
- * cursor to reopen from and whatever happened meanwhile cannot be replayed. The
117
- * loop reopens from the current position once the handler settles.
145
+ * - `no-cursor` — the source failed before any change arrived or any position
146
+ * was `reached()`, so there is no cursor to reopen from and whatever happened
147
+ * meanwhile cannot be replayed. The loop reopens from the current position once
148
+ * the handler settles.
118
149
  */
119
150
  type FollowResync = {
120
151
  readonly cause: 'expired';
@@ -147,19 +178,14 @@ type FollowState = {
147
178
  readonly kind: 'stopped';
148
179
  readonly error: unknown;
149
180
  };
150
- /**
151
- * A classifier's answer for one failure. `afterMs` is the server's hint — HTTP's
152
- * `Retry-After`, a socket's close code — and a floor under the loop's own
153
- * back-off: the wait is never shorter than it, and a hint longer than
154
- * {@link FOLLOW_RETRY_MAX_MS} is waited out in full.
155
- */
156
181
  type FollowVerdict = {
157
182
  readonly retry: false;
158
183
  } | {
159
184
  readonly retry: true;
160
185
  readonly afterMs?: number;
186
+ readonly backOffMs?: number;
161
187
  };
162
- interface FollowOptions {
188
+ interface FollowOptions<C extends Change = Change> {
163
189
  /** Where to start: a change's cursor from an earlier follow. Omitted, the current position. */
164
190
  readonly since?: string;
165
191
  /** Ends the loop, which then resolves; a wait in progress ends at once. */
@@ -169,9 +195,16 @@ interface FollowOptions {
169
195
  * cursor counts as reached — a change whose handler has not settled is
170
196
  * replayed by the next open, never skipped. A throw is a failure like the
171
197
  * source's own, and the classifier sees it.
198
+ *
199
+ * It is handed what the source yields: from `relyio.changes()` or
200
+ * `relyio.liveChanges()`, a `FeedChange`, whose `fresh` a refetch names.
201
+ */
202
+ readonly onChange: (change: C) => void | Promise<void>;
203
+ /**
204
+ * Re-read everything derived from the feed. Awaited; see {@link FollowResync}.
205
+ * An `expired` resync's error carries the position it resynced to as `fresh`,
206
+ * which the re-reads name as a change's refetch does.
172
207
  */
173
- readonly onChange: (change: Change) => void | Promise<void>;
174
- /** Re-read everything derived from the feed. Awaited; see {@link FollowResync}. */
175
208
  readonly onResync: (resync: FollowResync) => void | Promise<void>;
176
209
  /** Observes each transition; see {@link FollowState}. It must not throw. */
177
210
  readonly onState?: (state: FollowState) => void;
@@ -209,6 +242,11 @@ type FollowEnd = {
209
242
  * service asked for: `Retry-After`, or a rate limit's `resetAt`. Anything else —
210
243
  * a refused key, a malformed request, a defect — stops the loop, because
211
244
  * retrying would meet the same refusal forever.
245
+ *
246
+ * A `LiveEdgeError` says what to do itself, from the edge's own tables: `stop`,
247
+ * `retry` (carrying a refused poll's `Retry-After`), or `back-off` — at least
248
+ * `VISITOR_ADMISSION_RETRY_AFTER_SECONDS` on the doubling schedule `backOffMs`
249
+ * describes.
212
250
  */
213
251
  declare function classifyFollowFailure(error: unknown): FollowVerdict;
214
252
  /**
@@ -220,12 +258,13 @@ declare function classifyFollowFailure(error: unknown): FollowVerdict;
220
258
  * - **A failure worth retrying** (`classify`) reopens the source after a
221
259
  * jittered, doubling wait — a ceiling of {@link FOLLOW_RETRY_BASE_MS} doubled
222
260
  * per consecutive failure up to {@link FOLLOW_RETRY_MAX_MS}, shortened by the
223
- * jitter to no less than half of it, and never below the server's hint. A
261
+ * jitter to no less than half of it, and never below the server's hint; a
262
+ * verdict's `backOffMs` puts it on the longer schedule that field describes. A
224
263
  * delivered change resets the doubling, and so does the source calling
225
264
  * `opened()` once its transport is up. The source reopens from the last
226
- * change's cursor so nothing is skipped; with no change seen yet there is none,
227
- * so `onResync({ cause: 'no-cursor' })` runs first and the source reopens from
228
- * the current position.
265
+ * change's cursor — or the last position it `reached()` — so nothing is
266
+ * skipped; with neither there is none, so `onResync({ cause: 'no-cursor' })`
267
+ * runs first and the source reopens from the current position.
229
268
  * - **Anything else** stops the loop: reported once as `stopped`, and returned.
230
269
  *
231
270
  * It never rejects. An abort — in the source, in a handler, or during a wait —
@@ -236,13 +275,14 @@ declare function classifyFollowFailure(error: unknown): FollowVerdict;
236
275
  * const controller = new AbortController()
237
276
  * const end = await followChanges(from => relyio.changes({ ...from, types: ['post'] }), {
238
277
  * signal: controller.signal,
239
- * onChange: change => refetch(change.contentType, change.entryId),
240
- * onResync: () => refetchEverything(),
278
+ * onChange: change => refetch(change.contentType, change.entryId, change.fresh),
279
+ * onResync: resync =>
280
+ * refetchEverything(resync.cause === 'expired' ? resync.expired.fresh : undefined),
241
281
  * })
242
282
  * if (end.kind === 'stopped') console.error(end.error)
243
283
  * ```
244
284
  */
245
- declare function followChanges(source: ChangeSource, options: FollowOptions): Promise<FollowEnd>;
285
+ declare function followChanges<C extends Change>(source: ChangeSource<C>, options: FollowOptions<C>): Promise<FollowEnd>;
246
286
 
247
287
  /**
248
288
  * Network-related errors
@@ -279,13 +319,13 @@ declare class ConnectionError extends SDKError {
279
319
  * (`INV-API-CODES-ARE-A-CLOSED-UNION`: a code no route declares is deleted, not
280
320
  * retained). An API key that has expired arrives as `INVALID_API_KEY` with
281
321
  * `details.reason: 'expired'`.
322
+ *
323
+ * `AuthenticationError` was deleted by REL-1471 for the same reason. The
324
+ * vocabulary's two 401 codes are `MISSING_API_KEY` and `INVALID_API_KEY`, and
325
+ * the mapper throws `MissingApiKeyError` and `InvalidApiKeyError` for them —
326
+ * so a generic 401 class had no refusal left to stand for, and nothing
327
+ * constructed it.
282
328
  */
283
- declare class AuthenticationError extends SDKError {
284
- readonly code = "AUTHENTICATION_ERROR";
285
- readonly retryable = false;
286
- constructor(message?: string, statusCode?: number, cause?: Error, context?: Record<string, unknown>);
287
- getUserMessage(): string;
288
- }
289
329
  declare class AuthorizationError extends SDKError {
290
330
  readonly code = "AUTHORIZATION_ERROR";
291
331
  readonly retryable = false;
@@ -446,6 +486,77 @@ declare class UnknownContractError extends SDKError {
446
486
  getUserMessage(): string;
447
487
  }
448
488
 
489
+ /**
490
+ * What ended a subscription at RelyIO's live edge (`relyio.liveChanges()`):
491
+ *
492
+ * - `closed` — the edge closed the socket, or it dropped. `code` and `reason` are the close's. A
493
+ * refusal is a socket accepted and closed at once, because a browser cannot read a refused
494
+ * handshake's status (`@relyio/api-contract`'s `VISITOR_CLOSE_CODES`); a Worker deploy drops every
495
+ * socket with a code of its own.
496
+ * - `refused` — a poll was refused with this contract code (`VISITOR_POLL_ROUTE`). The mapped error
497
+ * is the `cause`.
498
+ * - `lost` — the socket stopped answering its keepalive, so the connection is presumed dead.
499
+ * - `unreadable` — the edge sent a frame or a poll answer the wire does not declare.
500
+ * - `needs-publishable-key` — the client holds no publishable key (`rly_pub_…`), so nothing was
501
+ * sent: a secret or preview key never travels to the edge in a URL.
502
+ * - `needs-live-url` — the client cannot name the edge: `liveUrl` is not set and cannot be derived
503
+ * from `baseUrl`, or it is not a URL. Nothing was sent.
504
+ */
505
+ type LiveEdgeEnd = {
506
+ readonly kind: 'closed';
507
+ readonly code: number;
508
+ readonly reason: string;
509
+ } | {
510
+ readonly kind: 'refused';
511
+ readonly code: string;
512
+ } | {
513
+ readonly kind: 'lost';
514
+ } | {
515
+ readonly kind: 'unreadable';
516
+ readonly what: string;
517
+ } | {
518
+ readonly kind: 'needs-publishable-key';
519
+ } | {
520
+ readonly kind: 'needs-live-url';
521
+ };
522
+ /**
523
+ * Every end of a live-edge subscription other than its signal aborting, and what to do about it.
524
+ *
525
+ * `retry` is the wire's own answer, read from `@relyio/api-contract`'s tables rather than restated
526
+ * here — `VISITOR_CLOSE_RETRY` for a close, `VISITOR_POLL_RETRY` for a refused poll:
527
+ *
528
+ * - `stop` — the same request meets the same answer (a refused key, origin or dataset, a malformed
529
+ * query, a configuration the client lacks). `retryable` is `false`.
530
+ * - `retry` — a dropped connection, or the edge could not decide just now: reconnect with back-off
531
+ * and jitter, from the last cursor.
532
+ * - `back-off` — the project, or this address, holds as many connections as it may (REL-1159). Wait
533
+ * at least `VISITOR_ADMISSION_RETRY_AFTER_SECONDS`, with jitter, doubling while it repeats — and do
534
+ * not fall back to polling, which the same admission refuses.
535
+ *
536
+ * `followChanges()`'s default classifier reads it, so a loop over `liveChanges()` needs no
537
+ * classifier of its own.
538
+ */
539
+ declare class LiveEdgeError extends SDKError {
540
+ readonly code = "LIVE_EDGE_ENDED";
541
+ readonly retryable: boolean;
542
+ readonly end: LiveEdgeEnd;
543
+ readonly retry: VisitorRetry;
544
+ /** A refused poll's `Retry-After`, in milliseconds, where it carried a readable one. */
545
+ readonly retryAfterMs: number | undefined;
546
+ constructor(message: string, end: LiveEdgeEnd, retry: VisitorRetry, options?: {
547
+ readonly statusCode?: number;
548
+ readonly cause?: Error;
549
+ readonly retryAfterMs?: number;
550
+ readonly context?: Record<string, unknown>;
551
+ });
552
+ /**
553
+ * The base class rebuilds an error through its own four-argument constructor, which this class
554
+ * does not have; rebuilt that way, `end` would be a string and `retry` a number.
555
+ */
556
+ withContext(context: Record<string, unknown>): this;
557
+ getUserMessage(): string;
558
+ }
559
+
449
560
  /**
450
561
  * Map a RelyIO refusal onto an SDK error class.
451
562
  *
@@ -508,28 +619,27 @@ declare class ErrorMapper {
508
619
  * })
509
620
  * ```
510
621
  */
622
+
511
623
  /**
512
- * Locale status information from entry metadata
624
+ * One locale an entry has content in, as `_metadata.availableLocales` lists it: the document's
625
+ * `EntryLocale`. `version` is that locale's own counter and is always sent.
513
626
  */
514
- interface LocaleStatus {
515
- code: string;
516
- status: 'published' | 'draft' | 'archived';
517
- version?: number;
518
- publishedAt?: string;
519
- }
627
+ type LocaleStatus = EntryMetadata['availableLocales'][number];
520
628
  /**
521
- * Entry metadata with locale information
629
+ * The locale facts of an entry's `_metadata` that these helpers read — a `Pick` of the document's
630
+ * `EntryMetadata`, so what they read is what a read declares, not a second, looser copy of it.
631
+ * `locale`, `defaultLocale` and `availableLocales` are always sent; `requestedLocale`,
632
+ * `localeFallbacksApplied` and `localizations` only when the request asked for them.
522
633
  */
523
- interface LocaleMetadata {
524
- locale?: string;
525
- requestedLocale?: string;
526
- defaultLocale?: string;
527
- localeFallbacksApplied?: Record<string, string>;
528
- availableLocales?: LocaleStatus[];
529
- localizations?: Record<string, unknown>;
530
- }
634
+ type LocaleMetadata = Pick<EntryMetadata, 'locale' | 'requestedLocale' | 'defaultLocale' | 'localeFallbacksApplied' | 'availableLocales' | 'localizations'>;
531
635
  /**
532
- * Entry with locale metadata
636
+ * Entry with locale metadata: an entry read — single, listed, a child or an expanded reference.
637
+ *
638
+ * Not a search or similar hit: a hit's `_metadata` is the document's `SearchHitMetadata`, which
639
+ * carries no `defaultLocale` or `availableLocales`, so passing one here is a compile error rather
640
+ * than an empty answer. That is what let the helpers below read `availableLocales` without an
641
+ * optional chain (REL-1413); the one on `_metadata` stays because a schema-defined query's row
642
+ * carries `_metadata` only when the query selects it.
533
643
  */
534
644
  interface LocalizedEntry {
535
645
  _metadata?: LocaleMetadata;
@@ -541,7 +651,7 @@ interface LocalizedEntry {
541
651
  interface LanguageSwitcherOption {
542
652
  code: string;
543
653
  label: string;
544
- status: 'published' | 'draft' | 'archived';
654
+ status: LocaleStatus['status'];
545
655
  isCurrent: boolean;
546
656
  isDefault: boolean;
547
657
  hasContent: boolean;
@@ -895,4 +1005,4 @@ declare function snapToLadder(value: number): number;
895
1005
 
896
1006
  declare const VERSION = "__VERSION__";
897
1007
 
898
- export { AuthenticationError, AuthorizationError, BaseContent, Change, type ChangeSource, type ChangeSourceOptions, ChangesExpiredError, ChangesExpiredReason, ConnectionError, ErrorMapper, FOLLOW_RETRY_BASE_MS, FOLLOW_RETRY_MAX_MS, type FollowEnd, type FollowOptions, type FollowResync, type FollowState, type FollowVerdict, IMAGE_LADDER, InvalidApiKeyError, type LanguageSwitcherOption, type LanguageSwitcherOptions, type LocaleMetadata, type LocaleStatus, type LocalizedEntry, MethodNotAllowedError, MissingApiKeyError, NetworkError, PUBLISHABLE_KEY_PREFIX, PayloadTooLargeError, PlanFeatureUnavailableError, RELYIO_CHANGE_EVENT, RELYIO_RESYNC_EVENT, RateLimitError, ReadOnlyKeyError, type RelyIOChangeDetail, type RelyIOFieldAttributes, type RelyIOFieldName, type RelyIOResyncDetail, SDKError, ServerError, ServiceIndeterminateError, TimeoutError, TransactionRolledBackError, type TranslationCompleteness, UnknownContractError, UsageQuotaExceededError, VERSION, buildLanguageSwitcher, classifyFollowFailure, estimateTranslationCompleteness, followChanges, getAllLocalizedValues, getAvailableLocaleCodes, getDefaultLocale, getFallbackFields, getFieldFallbackLocale, getLocalizedField, getPublishedLocaleCodes, getRequestedLocale, hasLocale, isFieldFallback, isPublishableKey, isPublishedInLocale, localeHelpers, needsTranslation, relyioField, snapToLadder };
1008
+ export { AuthorizationError, BaseContent, Change, type ChangeSource, type ChangeSourceOptions, ChangesExpiredError, ChangesExpiredReason, ConnectionError, EntryMetadata, ErrorMapper, FOLLOW_BACK_OFF_MAX_MS, FOLLOW_RETRY_BASE_MS, FOLLOW_RETRY_MAX_MS, type FollowEnd, type FollowOptions, type FollowResync, type FollowState, type FollowVerdict, IMAGE_LADDER, InvalidApiKeyError, type LanguageSwitcherOption, type LanguageSwitcherOptions, type LiveEdgeEnd, LiveEdgeError, type LocaleMetadata, type LocaleStatus, type LocalizedEntry, MethodNotAllowedError, MissingApiKeyError, NetworkError, PUBLISHABLE_KEY_PREFIX, PayloadTooLargeError, PlanFeatureUnavailableError, RELYIO_CHANGE_EVENT, RELYIO_RESYNC_EVENT, RateLimitError, ReadOnlyKeyError, type RelyIOChangeDetail, type RelyIOFieldAttributes, type RelyIOFieldName, type RelyIOResyncDetail, SDKError, ServerError, ServiceIndeterminateError, TimeoutError, TransactionRolledBackError, type TranslationCompleteness, UnknownContractError, UsageQuotaExceededError, VERSION, buildLanguageSwitcher, classifyFollowFailure, estimateTranslationCompleteness, followChanges, getAllLocalizedValues, getAvailableLocaleCodes, getDefaultLocale, getFallbackFields, getFieldFallbackLocale, getLocalizedField, getPublishedLocaleCodes, getRequestedLocale, hasLocale, isFieldFallback, isPublishableKey, isPublishedInLocale, localeHelpers, needsTranslation, relyioField, snapToLadder };