@atscript/db-client 0.1.194 → 0.1.196
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/dist/client-CNTDhOXn.d.cts +1117 -0
- package/dist/client-DIymxYkx.d.mts +1117 -0
- package/dist/{client-error-Dn4WeNft.mjs → client-error-Dy1bhtlh.mjs} +4 -1
- package/dist/{client-error-C9Q5xCuW.cjs → client-error-YjY_SOaf.cjs} +4 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -476
- package/dist/index.d.mts +5 -476
- package/dist/index.mjs +1 -1
- package/dist/validator.cjs +7 -3
- package/dist/validator.d.cts +1 -1
- package/dist/validator.d.mts +1 -1
- package/dist/validator.mjs +7 -3
- package/package.json +7 -7
- package/dist/validator-D9QYeBWO.d.cts +0 -627
- package/dist/validator-FC3SyLqE.d.mts +0 -627
|
@@ -0,0 +1,1117 @@
|
|
|
1
|
+
import { AggregateQuery, AggregateQuery as AggregateQuery$1, AggregateResult, AggregateResult as AggregateResult$1, AggregateStage, BucketExpr, BucketUnit, CalendarBucketLabel, ComputedExpr, FilterExpr, NestedAggregateQuery, NestedAggregateQuery as NestedAggregateQuery$1, NestedAggregateResult, NestedAggregateResult as NestedAggregateResult$1, SelectExpr, StageRow, TypedWithRelation, Uniquery, Uniquery as Uniquery$1, UniqueryControls, ValidGroupBy, ValidGroupBy as ValidGroupBy$1, ValidNested, ValidNested as ValidNested$1, WeekStart } from "@uniqu/core";
|
|
2
|
+
import { TAtscriptAnnotatedType, TAtscriptTypeObject } from "@atscript/typescript/utils";
|
|
3
|
+
import { DbInsert, DbPatch, DbResponse, DbRow, TDbActionInfo, TDbActionTargetSummary, TDbAvailableActions, TDbDeleteResult, TDbDeleteResult as TDbDeleteResult$1, TDbInsertIgnoreResult, TDbInsertIgnoreResult as TDbInsertIgnoreResult$1, TDbInsertManyIgnoreResult, TDbInsertManyIgnoreResult as TDbInsertManyIgnoreResult$1, TDbInsertManyResult, TDbInsertManyResult as TDbInsertManyResult$1, TDbInsertResult, TDbInsertResult as TDbInsertResult$1, TDbUpdateResult, TDbUpdateResult as TDbUpdateResult$1, TDbVersion, TFieldMeta, TMetaResponse, TRelationInfo, TSearchIndexInfo } from "@atscript/db";
|
|
4
|
+
import { DbValidationContext, ValidatorMode, ValidatorMode as ValidatorMode$1 } from "@atscript/db/validator";
|
|
5
|
+
|
|
6
|
+
//#region src/meta-store.d.ts
|
|
7
|
+
/** Options for {@link MetaStore}. */
|
|
8
|
+
interface MetaStoreOptions {
|
|
9
|
+
/**
|
|
10
|
+
* How many `/meta` bodies the store keeps (least recently used are dropped
|
|
11
|
+
* first). Default `50`.
|
|
12
|
+
*/
|
|
13
|
+
maxEntries?: number;
|
|
14
|
+
/**
|
|
15
|
+
* After a conditional `/meta` request fails at the transport level (e.g. a
|
|
16
|
+
* CORS preflight refusing `If-None-Match`) while the plain retry succeeds,
|
|
17
|
+
* how long (ms) that store key is loaded without `If-None-Match` before a
|
|
18
|
+
* conditional request is tried again. Default `300000` (5 minutes).
|
|
19
|
+
*/
|
|
20
|
+
unconditionalMs?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Content-addressed cache of `GET /meta` responses, keyed by the server's
|
|
24
|
+
* `ETag`, used by {@link Client.meta} to revalidate instead of downloading.
|
|
25
|
+
*
|
|
26
|
+
* For each store key (the meta URL, or `ClientOptions.metaKey`) the store
|
|
27
|
+
* remembers the ETags it has seen. `meta()` sends them as `If-None-Match`;
|
|
28
|
+
* when the server answers `304 Not Modified` the client reuses the body
|
|
29
|
+
* stored under the returned `ETag`. Several keys that serve the same bytes
|
|
30
|
+
* — e.g. one parametric controller mounted at `/api/tenant/:id/todos` —
|
|
31
|
+
* therefore share one stored body, and the first visit to a new key costs a
|
|
32
|
+
* `304` instead of the full `/meta`.
|
|
33
|
+
*
|
|
34
|
+
* It is a pure cache: the server decides on every request whether the body
|
|
35
|
+
* is still valid. Failures are never stored.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.1.153
|
|
38
|
+
*/
|
|
39
|
+
declare class MetaStore {
|
|
40
|
+
private readonly _maxEntries;
|
|
41
|
+
private readonly _unconditionalMs;
|
|
42
|
+
/** Raw JSON body by opaque ETag (`W/` stripped — `If-None-Match` compares weakly). */
|
|
43
|
+
private readonly _bodies;
|
|
44
|
+
private readonly _keys;
|
|
45
|
+
constructor(options?: MetaStoreOptions);
|
|
46
|
+
/** Number of stored `/meta` bodies. */
|
|
47
|
+
get size(): number;
|
|
48
|
+
/**
|
|
49
|
+
* The ETags this store would send as `If-None-Match` for `key` — those seen
|
|
50
|
+
* for it whose body is still stored, most recent first.
|
|
51
|
+
*/
|
|
52
|
+
candidates(key: string): string[];
|
|
53
|
+
/** Drops every stored body and remembered ETag. */
|
|
54
|
+
clear(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Stored body for `etag` (weak comparison), marking it — and `etag` as the
|
|
57
|
+
* latest candidate for `key` — as recently used.
|
|
58
|
+
*
|
|
59
|
+
* @internal used by `Client`
|
|
60
|
+
*/
|
|
61
|
+
_reuse(key: string, etag: string): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Stores a `200` body under its ETag and remembers the ETag for `key`.
|
|
64
|
+
*
|
|
65
|
+
* @internal used by `Client`
|
|
66
|
+
*/
|
|
67
|
+
_put(key: string, etag: string, text: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Whether `key` is in its no-`If-None-Match` window; an expired window is
|
|
70
|
+
* cleared, so the next request is conditional again.
|
|
71
|
+
*
|
|
72
|
+
* @internal used by `Client`
|
|
73
|
+
*/
|
|
74
|
+
_isUnconditional(key: string): boolean;
|
|
75
|
+
/** @internal used by `Client` */
|
|
76
|
+
_markUnconditional(key: string): void;
|
|
77
|
+
private _remember;
|
|
78
|
+
/** The entry for `key`, created if needed and moved to most recently used. */
|
|
79
|
+
private _touchKey;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The store every {@link Client} uses unless `ClientOptions.metaStore` says
|
|
83
|
+
* otherwise, so all clients in a page share revalidated `/meta` bodies.
|
|
84
|
+
* Exported since 0.1.155: `client.metaStore === defaultMetaStore` tells a
|
|
85
|
+
* client on the shared store from one with its own.
|
|
86
|
+
*/
|
|
87
|
+
declare const defaultMetaStore: MetaStore;
|
|
88
|
+
/**
|
|
89
|
+
* Clears the shared default {@link MetaStore}. Call it on sign-out or any
|
|
90
|
+
* identity change (together with `Client.invalidateMeta()` on live clients).
|
|
91
|
+
*
|
|
92
|
+
* @since 0.1.153
|
|
93
|
+
*/
|
|
94
|
+
declare function clearMetaStore(): void;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/types.d.ts
|
|
97
|
+
/**
|
|
98
|
+
* Write payload for `insert()` (since 0.1.168): every key optional, optional
|
|
99
|
+
* columns additionally accept `null` (explicit NULL). A value of the model's
|
|
100
|
+
* interface type fits; on an untyped client any object does.
|
|
101
|
+
*/
|
|
102
|
+
type InsertOf<T> = DbInsert<ResponseDataOf<T>>;
|
|
103
|
+
/**
|
|
104
|
+
* Write payload for `update()`: every key optional, optional columns
|
|
105
|
+
* additionally accept `null` (explicit NULL). Number fields also take
|
|
106
|
+
* `{ $inc | $dec | $mul: n }`, top-level arrays the array operators
|
|
107
|
+
* (`$insert`, `$remove`, …) and the payload a `$cas` version check (since
|
|
108
|
+
* 0.1.168). A value of the model's interface type fits; on an untyped client
|
|
109
|
+
* any object does.
|
|
110
|
+
*/
|
|
111
|
+
type PatchOf<T> = DbPatch<ResponseDataOf<T>>;
|
|
112
|
+
/**
|
|
113
|
+
* Write payload for `replace()`: full row; optional columns additionally
|
|
114
|
+
* accept `null`, `$cas` checks the version. On an untyped client any object fits.
|
|
115
|
+
*/
|
|
116
|
+
type RowOf<T> = DbRow<ResponseDataOf<T>>;
|
|
117
|
+
/** Options for creating a Client instance. */
|
|
118
|
+
interface ClientOptions {
|
|
119
|
+
/**
|
|
120
|
+
* Custom fetch implementation. Defaults to `globalThis.fetch`.
|
|
121
|
+
* Use this to inject auth headers, interceptors, or a custom HTTP client.
|
|
122
|
+
*/
|
|
123
|
+
fetch?: typeof globalThis.fetch;
|
|
124
|
+
/**
|
|
125
|
+
* Default headers to include with every request.
|
|
126
|
+
* Can be a static object or an async factory (e.g. for refreshing auth tokens).
|
|
127
|
+
*/
|
|
128
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
129
|
+
/**
|
|
130
|
+
* Base URL prefix. Prepended to the client path for full URL construction.
|
|
131
|
+
* @example "https://api.example.com"
|
|
132
|
+
*/
|
|
133
|
+
baseUrl?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Override for `processor: 'navigate'` action dispatch. When `Client.action()`
|
|
136
|
+
* resolves a navigate action, this hook is invoked with the interpolated
|
|
137
|
+
* URL. Default behaviour (browser only) calls `window.location.assign(url)`.
|
|
138
|
+
*
|
|
139
|
+
* Provide a custom navigator to integrate with a SPA router:
|
|
140
|
+
* ```typescript
|
|
141
|
+
* new Client('/api/users', { navigate: (url) => router.push(url) })
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
navigate?: (url: string) => void | Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Tolerate unknown properties in write payloads during client preflight
|
|
147
|
+
* validation. Enable when the served `/meta` type is a projection of the
|
|
148
|
+
* full server-side type (e.g. an ARBAC read overlay strips write-only
|
|
149
|
+
* fields) — the server stays authoritative. Off by default: strict
|
|
150
|
+
* preflight catches typos.
|
|
151
|
+
*/
|
|
152
|
+
lenientWrites?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Where `meta()` keeps revalidatable `/meta` bodies (since 0.1.153).
|
|
155
|
+
* Defaults to one store shared by every client in the page, so clients for
|
|
156
|
+
* the same controller — or for one parametric controller under different
|
|
157
|
+
* route params — revalidate with `If-None-Match` and reuse the body on a
|
|
158
|
+
* `304`. Pass your own `new MetaStore()` to isolate a group of clients, or
|
|
159
|
+
* `false` to always download `/meta`.
|
|
160
|
+
*/
|
|
161
|
+
metaStore?: MetaStore | false;
|
|
162
|
+
/**
|
|
163
|
+
* Key under which `metaStore` remembers this client's ETags (since
|
|
164
|
+
* 0.1.153). Defaults to the `/meta` URL. Give clients of a parametric
|
|
165
|
+
* mount one shared key (e.g. the route template
|
|
166
|
+
* `"/api/tenant/:tenantId/todos"`) so a new route param revalidates against
|
|
167
|
+
* the body already loaded for another one.
|
|
168
|
+
*/
|
|
169
|
+
metaKey?: string;
|
|
170
|
+
/**
|
|
171
|
+
* The locale to ask the server for (since 0.1.170): sent as
|
|
172
|
+
* `Accept-Language` on every request (unless `headers` carries one), so a
|
|
173
|
+
* server with a translator answers in that language — `/meta` texts, error
|
|
174
|
+
* messages and the templates (`/meta` `type.$i18n`) the preflight
|
|
175
|
+
* validator translates its errors with. A function is read per request.
|
|
176
|
+
*
|
|
177
|
+
* The cached `/meta`, the validator built from it and the loaded action
|
|
178
|
+
* forms belong to the locale they were loaded in: after a switch, the next
|
|
179
|
+
* call loads them again (revalidated through `metaStore`, which keeps one
|
|
180
|
+
* entry per locale — a switch back costs a `304`). Already-held results
|
|
181
|
+
* stay as they are: re-read them (in a UI, remount on a locale change).
|
|
182
|
+
*/
|
|
183
|
+
locale?: string | (() => string | undefined);
|
|
184
|
+
}
|
|
185
|
+
/** Search index metadata from the server. */
|
|
186
|
+
type SearchIndexInfo = TSearchIndexInfo;
|
|
187
|
+
/** Relation summary in meta response. */
|
|
188
|
+
type RelationInfo = TRelationInfo;
|
|
189
|
+
/** Per-field capability flags. */
|
|
190
|
+
type FieldMeta = TFieldMeta;
|
|
191
|
+
/** Enhanced meta response from the server (`GET /meta`). */
|
|
192
|
+
type MetaResponse = TMetaResponse;
|
|
193
|
+
/** Paginated response shape from `GET /pages`. */
|
|
194
|
+
interface PageResult<T> {
|
|
195
|
+
data: T[];
|
|
196
|
+
page: number;
|
|
197
|
+
itemsPerPage: number;
|
|
198
|
+
pages: number;
|
|
199
|
+
count: number;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Per-call options of the `Client` read / write methods (since 0.1.165).
|
|
203
|
+
*/
|
|
204
|
+
interface TClientCallOptions {
|
|
205
|
+
/**
|
|
206
|
+
* Cancels the request. An aborted request rejects with a `TransportError`
|
|
207
|
+
* whose `aborted` is `true` (the `AbortError` is its `cause`).
|
|
208
|
+
*/
|
|
209
|
+
signal?: AbortSignal;
|
|
210
|
+
}
|
|
211
|
+
/** One entry of a server error's `errors` list. */
|
|
212
|
+
interface ServerErrorEntry {
|
|
213
|
+
path: string;
|
|
214
|
+
message: string;
|
|
215
|
+
/** Machine-readable reason (`UNIQUE`, `FK_MISSING`, `FK_RESTRICT`, …). @since 0.1.165 */
|
|
216
|
+
code?: string;
|
|
217
|
+
/** Values the message names, for translating it. @since 0.1.165 */
|
|
218
|
+
params?: Record<string, unknown>;
|
|
219
|
+
details?: unknown[];
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Server error response shape (matches moost-db error transform). Open to
|
|
223
|
+
* extra fields (since 0.1.165): a handler's own error body (`quota`, `tier`,
|
|
224
|
+
* …) reads without a cast — type it with `ClientError<B>`.
|
|
225
|
+
*/
|
|
226
|
+
interface ServerError {
|
|
227
|
+
message: string;
|
|
228
|
+
statusCode: number;
|
|
229
|
+
/**
|
|
230
|
+
* The `DbError` code (`CONFLICT`, `FK_VIOLATION`, …), moost-db's own
|
|
231
|
+
* (`UNKNOWN_FIELD`, `INVALID_QUERY`, `VERSION_MISMATCH`, … — every 400 /
|
|
232
|
+
* 403 / 409 is coded since 0.1.175) or a handler's own. @since 0.1.165
|
|
233
|
+
*/
|
|
234
|
+
code?: string;
|
|
235
|
+
/** Values the top-level message names, for translating it. @since 0.1.175 */
|
|
236
|
+
params?: Record<string, unknown>;
|
|
237
|
+
errors?: ServerErrorEntry[];
|
|
238
|
+
[key: string]: unknown;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Minimal brand shape every `Client<T>` generic must satisfy. All fields are
|
|
242
|
+
* optional — plain interfaces and `Record<string, unknown>` satisfy this
|
|
243
|
+
* constraint, so `new Client('/path')` (no generic) keeps working with
|
|
244
|
+
* `unknown` / `Record<string, unknown>` fallbacks. Atscript-generated types
|
|
245
|
+
* fill these brand fields and unlock per-method inference.
|
|
246
|
+
*/
|
|
247
|
+
type AtscriptClientShape = {
|
|
248
|
+
__pk?: unknown;
|
|
249
|
+
__ownProps?: Record<string, unknown>;
|
|
250
|
+
__navProps?: Record<string, unknown>;
|
|
251
|
+
type?: {
|
|
252
|
+
__dataType?: unknown;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
/** Extract the data type from an Atscript annotated type `T`. */
|
|
256
|
+
type DataOf<T> = T extends {
|
|
257
|
+
type: {
|
|
258
|
+
__dataType?: infer D;
|
|
259
|
+
};
|
|
260
|
+
} ? unknown extends D ? T extends (new (...a: any[]) => infer I) ? I : Record<string, unknown> : D & Record<string, unknown> : Record<string, unknown>;
|
|
261
|
+
/**
|
|
262
|
+
* The row type a read answers with: {@link DataOf} without its
|
|
263
|
+
* `Record<string, unknown>` widening, which would make `DbResponse`'s
|
|
264
|
+
* `Omit` collapse every field to `unknown` (since 0.1.165).
|
|
265
|
+
*/
|
|
266
|
+
type ResponseDataOf<T> = T extends {
|
|
267
|
+
type: {
|
|
268
|
+
__dataType?: infer D;
|
|
269
|
+
};
|
|
270
|
+
} ? unknown extends D ? T extends (new (...a: any[]) => infer I) ? I : Record<string, unknown> : D : Record<string, unknown>;
|
|
271
|
+
/**
|
|
272
|
+
* `$select` controls of a read over `T` whose controller declares the display-only
|
|
273
|
+
* fields `D` (`@DbDecorations`): `$select` also accepts `keyof D`; filter, sort
|
|
274
|
+
* and every other control stay over the own fields. Since 0.1.148.
|
|
275
|
+
*/
|
|
276
|
+
type DecoratedControls<T, D> = Omit<UniqueryControls<OwnOf<T>, NavOf<T>>, "$select"> & {
|
|
277
|
+
$select?: SelectExpr<OwnOf<T> & D>;
|
|
278
|
+
/**
|
|
279
|
+
* `false` — a `$search` read computes no relevance score: rows come in
|
|
280
|
+
* `$sort` order, or primary-key order without one. A `$vector` read refuses
|
|
281
|
+
* it (400). Default `true`. Since 0.1.175.
|
|
282
|
+
*/
|
|
283
|
+
$rank?: boolean;
|
|
284
|
+
};
|
|
285
|
+
/** A read query over `T` — {@link DecoratedControls} for the controls. Since 0.1.148. */
|
|
286
|
+
type DecoratedQuery<T, D> = Omit<Uniquery$1<OwnOf<T>, NavOf<T>>, "controls"> & {
|
|
287
|
+
controls?: DecoratedControls<T, D>;
|
|
288
|
+
};
|
|
289
|
+
/** Extract own (non-nav) properties from an Atscript annotated type. */
|
|
290
|
+
type OwnOf<T> = T extends {
|
|
291
|
+
__ownProps: infer O;
|
|
292
|
+
} ? O : DataOf<T>;
|
|
293
|
+
/** Extract nav properties from an Atscript annotated type. */
|
|
294
|
+
type NavOf<T> = T extends {
|
|
295
|
+
__navProps: infer N extends Record<string, unknown>;
|
|
296
|
+
} ? N : Record<string, never>;
|
|
297
|
+
/** Extract primary key type from an Atscript annotated type. */
|
|
298
|
+
type IdOf<T> = T extends {
|
|
299
|
+
__pk: infer PK;
|
|
300
|
+
} ? PK : unknown;
|
|
301
|
+
/**
|
|
302
|
+
* Narrow a read-method response type by the literal `$with` array in the
|
|
303
|
+
* query, mirroring the backend's `DbResponse<Data, Nav, Q>` algebra. Nav
|
|
304
|
+
* properties are stripped by default and re-added only for relations the
|
|
305
|
+
* caller listed in `$with`. When `T` carries no nav-prop brand, `DbResponse`
|
|
306
|
+
* short-circuits to the data type. `$actions` / `$disabledReasons` are always
|
|
307
|
+
* optional — the server emits them only when the request set `?$actions=true`.
|
|
308
|
+
*/
|
|
309
|
+
type ClientResponse<T, Q> = DbResponse<ResponseDataOf<T>, NavOf<T>, Q> & {
|
|
310
|
+
/**
|
|
311
|
+
* Server-evaluated per-row availability for `'row'` and `'rows'`-level
|
|
312
|
+
* actions. Each entry is the `name` of an action that is NOT disabled for
|
|
313
|
+
* this row.
|
|
314
|
+
*/
|
|
315
|
+
$actions?: string[];
|
|
316
|
+
/**
|
|
317
|
+
* Action name → human-readable reason, for actions disabled on this row
|
|
318
|
+
* whose `disabled` predicate returned a reason string. Present only on
|
|
319
|
+
* rows with at least one such reason; keys never appear in `$actions`.
|
|
320
|
+
*
|
|
321
|
+
* @since 0.1.141
|
|
322
|
+
*/
|
|
323
|
+
$disabledReasons?: Record<string, string>;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* "Every row matching this query" — the target of
|
|
327
|
+
* `Client.actionOnQuery()` / `countActionTarget()`, for a `'rows'` action
|
|
328
|
+
* whose `/meta` entry carries `queryTarget`. The same filter / search /
|
|
329
|
+
* index the user's `/query` used; the server resolves it under the caller's
|
|
330
|
+
* read scope and the action's own gate.
|
|
331
|
+
*
|
|
332
|
+
* @since 0.1.147
|
|
333
|
+
*/
|
|
334
|
+
interface TDbQueryTarget<T = AtscriptClientShape> {
|
|
335
|
+
filter?: Uniquery$1<OwnOf<T>, NavOf<T>>["filter"];
|
|
336
|
+
/** `$search` term. */
|
|
337
|
+
search?: string;
|
|
338
|
+
/** `$index` — the search index `search` uses. */
|
|
339
|
+
index?: string;
|
|
340
|
+
/** Identifiers to leave out (any identification of the controller the request goes to). */
|
|
341
|
+
exclude?: Record<string, unknown>[];
|
|
342
|
+
/** Fail with 409 `TARGET_CHANGED` when the target no longer matches exactly this many rows. */
|
|
343
|
+
expectCount?: number;
|
|
344
|
+
/** Client-side cap (never above the action's `queryTarget.maxRows`). */
|
|
345
|
+
maxRows?: number;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* The public surface of `Client`: what atscript-ui and applications call. Any object with these
|
|
349
|
+
* members stands in for a `Client`; it need not extend the class. Every member is required.
|
|
350
|
+
* An implementation that cannot perform an operation rejects with a `ClientError` of status 400
|
|
351
|
+
* and `body.code: "NOT_SUPPORTED"`, as moost-db answers, and leaves the operation out of its
|
|
352
|
+
* `/meta` (`crud`, `actions`, `aggregateFns`, `geoSearchable`). A read-only implementation needs
|
|
353
|
+
* working `meta`, `query`, `pages`, `one`, `count`, `getValidator`
|
|
354
|
+
* (`createClientValidator(await this.meta())`), `invalidateMeta`, `metaEtag` (may return
|
|
355
|
+
* `undefined`) and `metaStore` (may be `undefined`); answers "none" from `availableActions`,
|
|
356
|
+
* `getActionForm` (`null`) and `getActionFormTexts` (`undefined`); and rejects the rest.
|
|
357
|
+
* @since 0.1.196
|
|
358
|
+
*/
|
|
359
|
+
type ClientLike<T extends AtscriptClientShape = AtscriptClientShape, D extends object = Record<never, never>> = Pick<Client<T, D>, keyof Client<T, D>>;
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/client-error.d.ts
|
|
362
|
+
/**
|
|
363
|
+
* Error thrown by `Client` when the server responds with a non-2xx status code.
|
|
364
|
+
* Captures the HTTP status and the structured error body from moost-db.
|
|
365
|
+
*/
|
|
366
|
+
declare class ClientError<B extends ServerError = ServerError> extends Error {
|
|
367
|
+
/** HTTP status code (e.g. 400, 404, 409, 500). */
|
|
368
|
+
readonly status: number;
|
|
369
|
+
/**
|
|
370
|
+
* Structured error response from the server. `B` (since 0.1.165) types a
|
|
371
|
+
* body that carries fields of its own: `new ClientError<QuotaBody>(…)`,
|
|
372
|
+
* `(e as ClientError<QuotaBody>).body.quota`.
|
|
373
|
+
*/
|
|
374
|
+
readonly body: B;
|
|
375
|
+
name: string;
|
|
376
|
+
constructor(/** HTTP status code (e.g. 400, 404, 409, 500). */
|
|
377
|
+
|
|
378
|
+
status: number,
|
|
379
|
+
/**
|
|
380
|
+
* Structured error response from the server. `B` (since 0.1.165) types a
|
|
381
|
+
* body that carries fields of its own: `new ClientError<QuotaBody>(…)`,
|
|
382
|
+
* `(e as ClientError<QuotaBody>).body.quota`.
|
|
383
|
+
*/
|
|
384
|
+
|
|
385
|
+
body: B);
|
|
386
|
+
/** Shortcut to structured validation/DB errors from the server. */
|
|
387
|
+
get errors(): ServerErrorEntry[];
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Thrown before the request is sent when the client-side preflight
|
|
391
|
+
* (`validator` option, `ClientValidator`) rejects a write. A
|
|
392
|
+
* {@link ClientError} since 0.1.165 — status `400`, `body` shaped like the
|
|
393
|
+
* server's validation envelope (`{ message, statusCode: 400, errors }`) — so
|
|
394
|
+
* one `instanceof ClientError` branch handles a preflight failure and the
|
|
395
|
+
* server's 400 alike; `preflight` (`true`) tells them apart. The same class
|
|
396
|
+
* is exported from `@atscript/db-client` and `@atscript/db-client/validator`.
|
|
397
|
+
*/
|
|
398
|
+
declare class ClientValidationError extends ClientError {
|
|
399
|
+
name: string;
|
|
400
|
+
/** `true`: the request never left the client. */
|
|
401
|
+
readonly preflight: true;
|
|
402
|
+
constructor(errors: ServerErrorEntry[]);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Wire-body shape for `ActionDisabledError` responses (HTTP 409). Extends
|
|
406
|
+
* the base `ServerError` envelope with a `name` discriminator, the action
|
|
407
|
+
* name, and the offending identifier(s). The bridge between `@atscript/moost-db`'s
|
|
408
|
+
* server-side error and this typed client-side subclass is the wire JSON
|
|
409
|
+
* body — neither package depends on the other.
|
|
410
|
+
*/
|
|
411
|
+
interface ActionDisabledErrorBody extends ServerError {
|
|
412
|
+
name: "ActionDisabledError";
|
|
413
|
+
action: string;
|
|
414
|
+
id?: Record<string, unknown>;
|
|
415
|
+
ids?: Record<string, unknown>[];
|
|
416
|
+
/** Reason shared by every rejected row, when the server's predicate gave one. @since 0.1.141 */
|
|
417
|
+
reason?: string;
|
|
418
|
+
/** `'rows'` level: index-aligned with `ids`, `null` = no reason for that row. @since 0.1.141 */
|
|
419
|
+
reasons?: (string | null)[];
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Typed marker thrown by `Client._send` when the server response body's
|
|
423
|
+
* `name === 'ActionDisabledError'`. The transport / status / base body are
|
|
424
|
+
* identical to a generic `ClientError`; this subclass adds typed accessors
|
|
425
|
+
* so consumers can write `catch (e) { if (e instanceof ActionDisabledError) … }`
|
|
426
|
+
* to access `action` / `id` / `ids` / `reason` / `reasons` without indexing
|
|
427
|
+
* into `body`.
|
|
428
|
+
*/
|
|
429
|
+
declare class ActionDisabledError extends ClientError {
|
|
430
|
+
name: string;
|
|
431
|
+
/** The `@DbAction` name that rejected the request. */
|
|
432
|
+
get action(): string;
|
|
433
|
+
/** Present only for `'row'`-level rejections. */
|
|
434
|
+
get id(): Record<string, unknown> | undefined;
|
|
435
|
+
/** Present only for `'rows'`-level rejections (full list of failing IDs). */
|
|
436
|
+
get ids(): Record<string, unknown>[] | undefined;
|
|
437
|
+
/**
|
|
438
|
+
* Human-readable reason shared by every rejected row — present only when
|
|
439
|
+
* the server's `disabled` predicate returned one. `message` already
|
|
440
|
+
* carries it.
|
|
441
|
+
*
|
|
442
|
+
* @since 0.1.141
|
|
443
|
+
*/
|
|
444
|
+
get reason(): string | undefined;
|
|
445
|
+
/**
|
|
446
|
+
* `'rows'`-level only: per-row reasons index-aligned with {@link ids}
|
|
447
|
+
* (`null` where that row has none). Present only when at least one
|
|
448
|
+
* rejected row carries a reason.
|
|
449
|
+
*
|
|
450
|
+
* @since 0.1.141
|
|
451
|
+
*/
|
|
452
|
+
get reasons(): (string | null)[] | undefined;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Wire-body shape for `ActionTargetError` responses (since 0.1.147): a
|
|
456
|
+
* query target the server refused — `code` says why.
|
|
457
|
+
*/
|
|
458
|
+
interface ActionTargetErrorBody extends ServerError {
|
|
459
|
+
name: "ActionTargetError";
|
|
460
|
+
code: "TARGET_INVALID" | "TARGET_TOO_LARGE" | "TARGET_CHANGED";
|
|
461
|
+
action: string;
|
|
462
|
+
/** `TARGET_CHANGED`: the current match count. */
|
|
463
|
+
matched?: number;
|
|
464
|
+
/** `TARGET_TOO_LARGE`: the most rows one request may target. */
|
|
465
|
+
cap?: number;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Typed marker thrown by `Client` when a query-targeted action request is
|
|
469
|
+
* refused (body `name === 'ActionTargetError'`): `TARGET_INVALID` (400),
|
|
470
|
+
* `TARGET_TOO_LARGE` (400, `cap`) or `TARGET_CHANGED` (409, `matched` — the
|
|
471
|
+
* rows the query matches now; re-confirm and retry with that count).
|
|
472
|
+
*
|
|
473
|
+
* @since 0.1.147
|
|
474
|
+
*/
|
|
475
|
+
declare class ActionTargetError extends ClientError {
|
|
476
|
+
name: string;
|
|
477
|
+
get code(): ActionTargetErrorBody["code"];
|
|
478
|
+
get action(): string;
|
|
479
|
+
get matched(): number | undefined;
|
|
480
|
+
get cap(): number | undefined;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Wire-body shape for 409 OCC `version_mismatch` responses. Extends the base
|
|
484
|
+
* `ServerError` envelope with a `kind` discriminator and the row's current
|
|
485
|
+
* server-side version. The bridge between `@atscript/moost-db`'s server-side
|
|
486
|
+
* `_disambiguateMismatch` and this typed client-side subclass is the wire
|
|
487
|
+
* JSON body — neither package depends on the other.
|
|
488
|
+
*/
|
|
489
|
+
interface VersionMismatchErrorBody extends ServerError {
|
|
490
|
+
kind: "version_mismatch";
|
|
491
|
+
/** A string on a `@db.column.version.token` table (since 0.1.196). */
|
|
492
|
+
currentVersion: TDbVersion;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Typed marker thrown by `Client._send` when the server response body's
|
|
496
|
+
* `kind === 'version_mismatch'`. The transport / status / base body are
|
|
497
|
+
* identical to a generic `ClientError`; this subclass adds a typed
|
|
498
|
+
* `currentVersion` accessor so consumers can write
|
|
499
|
+
* `catch (e) { if (e instanceof VersionMismatchError) … }` without casting.
|
|
500
|
+
*/
|
|
501
|
+
declare class VersionMismatchError extends ClientError {
|
|
502
|
+
name: string;
|
|
503
|
+
/**
|
|
504
|
+
* Row's current server-side version — clients refresh + retry against it.
|
|
505
|
+
* A string on a `@db.column.version.token` table (since 0.1.196).
|
|
506
|
+
*/
|
|
507
|
+
get currentVersion(): TDbVersion;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Thrown by `Client` when NO server verdict was obtained: `fetch` itself
|
|
511
|
+
* rejected (network down, DNS, CORS, `AbortError`, …) or a 2xx response
|
|
512
|
+
* carried a body that is not JSON. Unlike {@link ClientError} — where the
|
|
513
|
+
* server answered and rejected — the request's outcome is unknown: a write
|
|
514
|
+
* may have committed. Reload before retrying a non-idempotent write.
|
|
515
|
+
* The underlying error is the standard `cause`.
|
|
516
|
+
*/
|
|
517
|
+
declare class TransportError extends Error {
|
|
518
|
+
/** HTTP method of the failed request. */
|
|
519
|
+
readonly method: string;
|
|
520
|
+
/** Full request URL. */
|
|
521
|
+
readonly url: string;
|
|
522
|
+
name: string;
|
|
523
|
+
constructor(/** HTTP method of the failed request. */
|
|
524
|
+
|
|
525
|
+
method: string, /** Full request URL. */
|
|
526
|
+
|
|
527
|
+
url: string, /** What went wrong; the message is `<method> <url>: <detail>`. */
|
|
528
|
+
|
|
529
|
+
detail: string, cause?: unknown);
|
|
530
|
+
/**
|
|
531
|
+
* `true` when the request was cancelled — its `cause` is an `AbortError`
|
|
532
|
+
* (an aborted `signal`) or a `TimeoutError` (`AbortSignal.timeout`) —
|
|
533
|
+
* rather than a network failure. @since 0.1.165
|
|
534
|
+
*/
|
|
535
|
+
get aborted(): boolean;
|
|
536
|
+
}
|
|
537
|
+
/** Thrown by `Client.action()` when the action name is not present in `/meta`. */
|
|
538
|
+
declare class ActionNotFoundError extends Error {
|
|
539
|
+
readonly action: string;
|
|
540
|
+
name: string;
|
|
541
|
+
constructor(action: string);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Thrown by `Client.action()` for actions that cannot be invoked through
|
|
545
|
+
* the client — currently `processor: 'custom'` (UI-dispatched events,
|
|
546
|
+
* which the application is responsible for handling) and `processor: 'navigate'`
|
|
547
|
+
* when no browser environment and no `navigate` option are configured.
|
|
548
|
+
*/
|
|
549
|
+
declare class ActionUnsupportedError extends Error {
|
|
550
|
+
readonly action: string;
|
|
551
|
+
readonly processor: string;
|
|
552
|
+
name: string;
|
|
553
|
+
constructor(action: string, processor: string, message: string);
|
|
554
|
+
}
|
|
555
|
+
//#endregion
|
|
556
|
+
//#region src/validator.d.ts
|
|
557
|
+
/** Options for {@link ClientValidator} / {@link createClientValidator}. */
|
|
558
|
+
interface ClientValidatorOptions {
|
|
559
|
+
/**
|
|
560
|
+
* The table's `@db.column.version` column (from `/meta`'s `versionColumn`).
|
|
561
|
+
* Enables the `$cas` lift in {@link ClientValidator.liftCas}; without it a
|
|
562
|
+
* `$cas` payload is rejected (the table is not versioned).
|
|
563
|
+
*/
|
|
564
|
+
versionColumn?: string;
|
|
565
|
+
/**
|
|
566
|
+
* Tolerate unknown properties in write payloads. Enable when the served
|
|
567
|
+
* `/meta` type is a PROJECTION of the full server-side type (e.g. an ARBAC
|
|
568
|
+
* read overlay that strips write-only fields such as sealed credentials) —
|
|
569
|
+
* otherwise a legitimate write carrying such a field is rejected client-side
|
|
570
|
+
* while the server would accept it. The server stays authoritative; this
|
|
571
|
+
* only relaxes the client preflight, so leave it off unless you need it
|
|
572
|
+
* (strict preflight catches typos).
|
|
573
|
+
*/
|
|
574
|
+
lenientWrites?: boolean;
|
|
575
|
+
/**
|
|
576
|
+
* Message templates and texts to translate the preflight's errors with
|
|
577
|
+
* (since 0.1.170) — the served type's `$i18n` (`/meta` `type.$i18n`), which
|
|
578
|
+
* {@link createClientValidator} passes by default. Errors keep their
|
|
579
|
+
* `code` / `params`; ids missing from it keep the English message.
|
|
580
|
+
*/
|
|
581
|
+
messages?: Readonly<Record<string, string>>;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Client-side validator backed by an Atscript type from the `/meta` endpoint.
|
|
585
|
+
*
|
|
586
|
+
* Caches validators per mode. Lazily initializes from a meta response promise.
|
|
587
|
+
*/
|
|
588
|
+
declare class ClientValidator {
|
|
589
|
+
private _type;
|
|
590
|
+
private _validators;
|
|
591
|
+
private _options;
|
|
592
|
+
private _lenientWrites;
|
|
593
|
+
private _translate?;
|
|
594
|
+
/** Flat map of dotted field paths to their annotated types. */
|
|
595
|
+
readonly flatMap: Map<string, TAtscriptAnnotatedType>;
|
|
596
|
+
/** Set of field paths that are navigation relations (TO/FROM/VIA). */
|
|
597
|
+
readonly navFields: ReadonlySet<string>;
|
|
598
|
+
/** The table's version column when it opts into OCC (from `/meta`). */
|
|
599
|
+
readonly versionColumn?: string;
|
|
600
|
+
/** The version column is a `@db.column.version.token` in the served type (since 0.1.196). */
|
|
601
|
+
private readonly _versionToken?;
|
|
602
|
+
constructor(type: TAtscriptAnnotatedType<TAtscriptTypeObject>, opts?: ClientValidatorOptions);
|
|
603
|
+
/**
|
|
604
|
+
* Normalises the SDK `$cas` shape to the wire shape (since 0.1.128):
|
|
605
|
+
* `{ id, $cas: { version: 4 } }` → `{ id, version: 4 }` (the server lifts
|
|
606
|
+
* `version` back to `$cas`). On a `@db.column.version.token` column (read
|
|
607
|
+
* from the served type, since 0.1.196) the version is a string. Returns a shallow clone per item; items
|
|
608
|
+
* without `$cas` (a `$cas: undefined` counts as absent) are returned
|
|
609
|
+
* as-is. Throws `ClientValidationError` when the table is not versioned,
|
|
610
|
+
* the `$cas` shape is invalid, or `version` and `$cas` disagree — the same
|
|
611
|
+
* messages the server produces, from the shared `reconcileCas` — or when
|
|
612
|
+
* `$cas` appears on an insert.
|
|
613
|
+
*/
|
|
614
|
+
liftCas(data: unknown, mode: ValidatorMode): unknown;
|
|
615
|
+
private _liftCasItem;
|
|
616
|
+
/**
|
|
617
|
+
* Applies the type's `@normalize.*` to write data (one item or an array)
|
|
618
|
+
* the way the server's write in `mode` does — patch operators and nested
|
|
619
|
+
* relation data included. Run it before {@link validate} and send its
|
|
620
|
+
* result. Pure and copy-on-change; never validates.
|
|
621
|
+
*
|
|
622
|
+
* @since 0.1.170
|
|
623
|
+
*/
|
|
624
|
+
normalize(data: unknown, mode: ValidatorMode): unknown;
|
|
625
|
+
/**
|
|
626
|
+
* Validate data for a given write mode.
|
|
627
|
+
* Throws `ClientValidationError` if validation fails. Validates `data` as
|
|
628
|
+
* given — run {@link normalize} first.
|
|
629
|
+
*/
|
|
630
|
+
validate(data: unknown, mode: ValidatorMode): void;
|
|
631
|
+
private _getValidator;
|
|
632
|
+
/** The options of `mode`'s validator — one object per mode (normalization judges with it too). */
|
|
633
|
+
private _getOptions;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Create a {@link ClientValidator} from a meta response (or promise).
|
|
637
|
+
*
|
|
638
|
+
* @example
|
|
639
|
+
* ```typescript
|
|
640
|
+
* const client = new Client<typeof User>('/db/tables/users')
|
|
641
|
+
* const validator = createClientValidator(await client.meta())
|
|
642
|
+
* validator.validate({ name: 'foo' }, 'insert')
|
|
643
|
+
* ```
|
|
644
|
+
*/
|
|
645
|
+
declare function createClientValidator(meta: MetaResponse, opts?: ClientValidatorOptions): ClientValidator;
|
|
646
|
+
//#endregion
|
|
647
|
+
//#region src/client.d.ts
|
|
648
|
+
type Own<T> = OwnOf<T>;
|
|
649
|
+
type Nav<T> = NavOf<T>;
|
|
650
|
+
type Id<T> = IdOf<T>;
|
|
651
|
+
type Response<T, Q> = ClientResponse<T, Q>;
|
|
652
|
+
/** A read row: the response over the own fields plus the declared decorations `D`, each optional. */
|
|
653
|
+
type DecoratedRow<T, Q, D> = Response<T, Q> & Partial<D>;
|
|
654
|
+
/**
|
|
655
|
+
* A `query()` / `pages()` row: {@link DecoratedRow}, plus `$score` on a vector read
|
|
656
|
+
* (`$search` with `$vector`, since 0.1.183): higher = closer, on the scale of `$threshold`.
|
|
657
|
+
*/
|
|
658
|
+
type ReadRow<T, Q, D> = DecoratedRow<T, Q, D> & (Q extends {
|
|
659
|
+
controls: {
|
|
660
|
+
$search: string;
|
|
661
|
+
$vector: string;
|
|
662
|
+
};
|
|
663
|
+
} ? {
|
|
664
|
+
$score: number;
|
|
665
|
+
} : unknown);
|
|
666
|
+
/**
|
|
667
|
+
* One insert row for `returning`: an untyped client's row is any `object`,
|
|
668
|
+
* which an array would match too — there it is any non-array object.
|
|
669
|
+
*/
|
|
670
|
+
type SingleInsertOf<T> = [keyof InsertOf<T>] extends [never] ? Record<string, any> & {
|
|
671
|
+
readonly [Symbol.iterator]?: never;
|
|
672
|
+
} : InsertOf<T>;
|
|
673
|
+
/** The stored row `insert(row, { returning: true })` answers: the `one()` row shape. */
|
|
674
|
+
type InsertedRow<T, D> = DecoratedRow<T, Record<never, never>, D>;
|
|
675
|
+
/** A two-level aggregate query: one with `controls.$from`. */
|
|
676
|
+
type NestedShape = {
|
|
677
|
+
controls: {
|
|
678
|
+
$from: object;
|
|
679
|
+
};
|
|
680
|
+
};
|
|
681
|
+
/** The compile-time check an aggregate query must pass: two-level or flat. */
|
|
682
|
+
type AggregateCheck<T, Q> = Q extends NestedShape ? ValidNested<T, Q> : ValidGroupBy<T, Q>;
|
|
683
|
+
/** The rows `aggregate()` answers for query `Q`. */
|
|
684
|
+
type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q extends NestedShape ? NestedAggregateResult<T, Q>[] : Q["controls"]["$select"] extends readonly (string | ComputedExpr)[] ? AggregateResult<T, Q["controls"]["$select"]>[] : Record<string, unknown>[];
|
|
685
|
+
/**
|
|
686
|
+
* HTTP client for moost-db REST endpoints.
|
|
687
|
+
*
|
|
688
|
+
* Each method maps 1:1 to a controller endpoint:
|
|
689
|
+
* - `query()` → `GET /query`
|
|
690
|
+
* - `count()` → `GET /query` with `$count`
|
|
691
|
+
* - `aggregate()` → `GET /query` with `$groupBy`
|
|
692
|
+
* - `pages()` → `GET /pages`
|
|
693
|
+
* - `one()` → `GET /one/:id` or `GET /one?compositeKeys`
|
|
694
|
+
* - `insert()` → `POST /`
|
|
695
|
+
* - `update()` → `PATCH /`
|
|
696
|
+
* - `replace()` → `PUT /`
|
|
697
|
+
* - `remove()` → `DELETE /:id` or `DELETE /?compositeKeys`
|
|
698
|
+
* - `meta()` → `GET /meta`
|
|
699
|
+
*
|
|
700
|
+
* ```typescript
|
|
701
|
+
* const users = new Client<typeof User>('/api/users')
|
|
702
|
+
* const all = await users.query()
|
|
703
|
+
* const page = await users.pages({ filter: { active: true } }, 1, 20)
|
|
704
|
+
* ```
|
|
705
|
+
*
|
|
706
|
+
* `D` (since 0.1.148) types the display-only fields the controller declares
|
|
707
|
+
* with `@DbDecorations`: `$select` of the read methods accepts their keys and
|
|
708
|
+
* rows carry them as optional properties. Filter and sort stay over `T`'s own
|
|
709
|
+
* fields — a decoration is never filterable or sortable.
|
|
710
|
+
*
|
|
711
|
+
* ```typescript
|
|
712
|
+
* const tickets = new Client<typeof Ticket, TicketDecorations>('/api/tickets')
|
|
713
|
+
* const rows = await tickets.query({ controls: { $select: ['title', 'ownerName'] } })
|
|
714
|
+
* rows[0].ownerName // string | undefined
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
717
|
+
declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D extends object = Record<never, never>> {
|
|
718
|
+
private readonly _path;
|
|
719
|
+
private readonly _baseUrl;
|
|
720
|
+
private readonly _fetch;
|
|
721
|
+
private readonly _headers?;
|
|
722
|
+
private readonly _navigate?;
|
|
723
|
+
private readonly _lenientWrites?;
|
|
724
|
+
private readonly _metaStore;
|
|
725
|
+
private readonly _metaKey?;
|
|
726
|
+
private readonly _locale?;
|
|
727
|
+
/** The locale {@link _metaPromise} (and the validator, forms) were loaded in. */
|
|
728
|
+
private _metaLocale?;
|
|
729
|
+
private _metaPromise?;
|
|
730
|
+
/** The `ETag` of the `/meta` body {@link _metaPromise} resolved to. */
|
|
731
|
+
private _metaEtag?;
|
|
732
|
+
private _validatorPromise?;
|
|
733
|
+
/** Loaded action forms (type + served `$i18n`) keyed by resolved URL. */
|
|
734
|
+
private _formCache;
|
|
735
|
+
constructor(path: string, opts?: ClientOptions);
|
|
736
|
+
/**
|
|
737
|
+
* `GET /query` — query records with typed filter, sort, select, and relations.
|
|
738
|
+
*
|
|
739
|
+
* The response type narrows by the literal `$with` array in `query` —
|
|
740
|
+
* relations not listed in `$with` are stripped from the row type. A vector
|
|
741
|
+
* read (`controls: { $search, $vector }`) types `$score` on every row.
|
|
742
|
+
*/
|
|
743
|
+
query<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(query?: Q, opts?: TClientCallOptions): Promise<ReadRow<T, Q, D>[]>;
|
|
744
|
+
/**
|
|
745
|
+
* `GET /query` with `$count: true` — returns record count.
|
|
746
|
+
*/
|
|
747
|
+
count(query?: {
|
|
748
|
+
filter?: Uniquery<Own<T>, Nav<T>>["filter"];
|
|
749
|
+
}, opts?: TClientCallOptions): Promise<number>;
|
|
750
|
+
/**
|
|
751
|
+
* `GET /query` with `$groupBy` — aggregate query with typed dimension/measure fields.
|
|
752
|
+
* `$groupBy: []` is the ungrouped aggregate: one row over the filtered set (served
|
|
753
|
+
* by moost-db since 0.1.155 — the URL carries the aggregate `$select` and no `$groupBy`).
|
|
754
|
+
*
|
|
755
|
+
* `$select` may carry calendar buckets (`{ $bucket, $field, $tz?, $weekStart?, $as? }`);
|
|
756
|
+
* a `$groupBy` entry must be a dimension or a bucket alias (`ValidGroupBy`), and a
|
|
757
|
+
* bucket's value is typed as its `YYYY-MM-DD` (hour: `YYYY-MM-DDTHH:00`) label
|
|
758
|
+
* (`| null` for an optional source).
|
|
759
|
+
* Gap-fill between labels with `nextBucketLabel` (re-exported here).
|
|
760
|
+
*
|
|
761
|
+
* Arithmetic (since 0.1.148): `{ $fn: 'sum', $expr, $as }` aggregates a per-row
|
|
762
|
+
* expression over numeric fields; `{ $expr, $as }` computes over aliases of other
|
|
763
|
+
* numeric entries or numeric `$groupBy` fields (`number | null`). `first` / `last`
|
|
764
|
+
* read a representative row ordered by `$rowOrder`. The URL forms are `expr(a/b):x`,
|
|
765
|
+
* `sum(a*b):x`, `first(f):x` and `$rowOrder=f,-id`.
|
|
766
|
+
*
|
|
767
|
+
* Since 0.1.168 (server: `/meta` `distinctFieldLists`, `conditionalAggregates`,
|
|
768
|
+
* `nestedAggregates`):
|
|
769
|
+
* - `{ $fn: 'countDistinct', $field: ['a', 'b'] }` counts distinct combinations (a row
|
|
770
|
+
* with any NULL field is not counted); URL `countDistinct(a,b)`;
|
|
771
|
+
* - `{ $fn, $field, $where, $as }` aggregates only the rows matching `$where` (a typed
|
|
772
|
+
* filter); URL `sum(amount|status=paid):paid`;
|
|
773
|
+
* - a query with `controls.$from` is a two-level aggregate: `$from` groups the filtered
|
|
774
|
+
* rows, the root controls aggregate its rows and name its columns (its `$groupBy`
|
|
775
|
+
* keys and aliases) — typed by `ValidNested`, rows by `NestedAggregateResult`.
|
|
776
|
+
*/
|
|
777
|
+
aggregate<const Q extends AggregateQuery<Own<T>> | NestedAggregateQuery<Own<T>>>(query: Q & AggregateCheck<Own<T>, Q>, opts?: TClientCallOptions): Promise<AggregateRows<Own<T>, Q>>;
|
|
778
|
+
/**
|
|
779
|
+
* `GET /pages` — paginated query with typed filter and relations.
|
|
780
|
+
*
|
|
781
|
+
* Response rows narrow by the literal `$with` array — same algebra as
|
|
782
|
+
* {@link query}, `$score` on a vector read included.
|
|
783
|
+
*/
|
|
784
|
+
pages<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(query?: Q, page?: number, size?: number, opts?: TClientCallOptions): Promise<PageResult<ReadRow<T, Q, D>>>;
|
|
785
|
+
/**
|
|
786
|
+
* `GET /geo` — distance-ranked geospatial search (tables with `@db.index.geo`).
|
|
787
|
+
*
|
|
788
|
+
* `point` is `[lng, lat]` (GeoJSON order). Rows come back ordered by distance
|
|
789
|
+
* ascending, each carrying a computed `$distance` (meters from `point`).
|
|
790
|
+
* `$maxDistance` / `$minDistance` (meters) and `$index` (geo index name) ride
|
|
791
|
+
* in `query.controls`; filter / `$select` / `$with` / `$skip` / `$limit`
|
|
792
|
+
* compose as usual.
|
|
793
|
+
*/
|
|
794
|
+
geoSearch<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(point: [number, number], query?: Q, opts?: TClientCallOptions): Promise<Array<DecoratedRow<T, Q, D> & {
|
|
795
|
+
$distance: number;
|
|
796
|
+
}>>;
|
|
797
|
+
/**
|
|
798
|
+
* `GET /geo` with `$page` / `$size` — paginated distance-ranked search.
|
|
799
|
+
*/
|
|
800
|
+
geoPages<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(point: [number, number], query?: Q, page?: number, size?: number, opts?: TClientCallOptions): Promise<PageResult<DecoratedRow<T, Q, D> & {
|
|
801
|
+
$distance: number;
|
|
802
|
+
}>>;
|
|
803
|
+
/**
|
|
804
|
+
* `GET /one/:id` or `GET /one?k1=v1&k2=v2` — single record by primary key.
|
|
805
|
+
*
|
|
806
|
+
* Returns `null` on 404. Response narrows by the literal `$with` array in
|
|
807
|
+
* `query.controls` — same algebra as {@link query}.
|
|
808
|
+
*/
|
|
809
|
+
one<const Q extends {
|
|
810
|
+
controls?: DecoratedControls<T, D>;
|
|
811
|
+
} = {
|
|
812
|
+
controls?: DecoratedControls<T, D>;
|
|
813
|
+
}>(id: Id<T>, query?: Q, opts?: TClientCallOptions): Promise<DecoratedRow<T, Q, D> | null>;
|
|
814
|
+
/**
|
|
815
|
+
* `POST /` — insert many records.
|
|
816
|
+
*/
|
|
817
|
+
insert(data: InsertOf<T>[], opts?: TClientCallOptions): Promise<TDbInsertManyResult>;
|
|
818
|
+
/**
|
|
819
|
+
* `POST /?$onConflict=ignore` — insert many records, skipping the ones that
|
|
820
|
+
* collide; the result reports inserted and skipped input indices (since 0.1.148).
|
|
821
|
+
*/
|
|
822
|
+
insert(data: InsertOf<T>[], opts: TClientCallOptions & {
|
|
823
|
+
onConflict: "ignore";
|
|
824
|
+
}): Promise<TDbInsertManyIgnoreResult>;
|
|
825
|
+
/**
|
|
826
|
+
* `POST /` with `Prefer: return=representation` — insert one record and
|
|
827
|
+
* get the stored row back as `row` (since 0.1.168): server defaults and
|
|
828
|
+
* stamps included, shaped as `one()` would answer it. `row` is absent when
|
|
829
|
+
* the server could not apply the preference (the caller may not read the
|
|
830
|
+
* row, or a skipped conflict).
|
|
831
|
+
*/
|
|
832
|
+
insert(data: SingleInsertOf<T>, opts: TClientCallOptions & {
|
|
833
|
+
returning: true;
|
|
834
|
+
}): Promise<TDbInsertResult & {
|
|
835
|
+
row?: InsertedRow<T, D>;
|
|
836
|
+
}>;
|
|
837
|
+
/**
|
|
838
|
+
* `POST /?$onConflict=ignore` with `Prefer: return=representation` — as
|
|
839
|
+
* above; a skipped row answers `{ conflict: true }` without `row`.
|
|
840
|
+
*/
|
|
841
|
+
insert(data: SingleInsertOf<T>, opts: TClientCallOptions & {
|
|
842
|
+
returning: true;
|
|
843
|
+
onConflict: "ignore";
|
|
844
|
+
}): Promise<TDbInsertIgnoreResult & {
|
|
845
|
+
row?: InsertedRow<T, D>;
|
|
846
|
+
}>;
|
|
847
|
+
/**
|
|
848
|
+
* `POST /` — insert one record. The version column (if any) is optional —
|
|
849
|
+
* the server initialises it; `$cas` is rejected (no meaning on insert).
|
|
850
|
+
*/
|
|
851
|
+
insert(data: InsertOf<T>, opts?: TClientCallOptions): Promise<TDbInsertResult>;
|
|
852
|
+
/**
|
|
853
|
+
* `POST /?$onConflict=ignore` — insert one record, skipping it when it
|
|
854
|
+
* collides on the primary key or a unique index (since 0.1.148).
|
|
855
|
+
*/
|
|
856
|
+
insert(data: InsertOf<T>, opts: TClientCallOptions & {
|
|
857
|
+
onConflict: "ignore";
|
|
858
|
+
}): Promise<TDbInsertIgnoreResult>;
|
|
859
|
+
/**
|
|
860
|
+
* `PATCH /` — partial update one or many records by primary key.
|
|
861
|
+
*
|
|
862
|
+
* Accepts both OCC shapes (since 0.1.128): a bare `version: N` (the wire
|
|
863
|
+
* contract) or the SDK `$cas: { version: N }`, which is lifted to `version`
|
|
864
|
+
* before preflight and sending. A stale version surfaces as
|
|
865
|
+
* {@link VersionMismatchError}; a PK-only body with a version is a real
|
|
866
|
+
* write (the server bumps the version).
|
|
867
|
+
*/
|
|
868
|
+
update(data: PatchOf<T> | PatchOf<T>[], opts?: TClientCallOptions): Promise<TDbUpdateResult>;
|
|
869
|
+
/**
|
|
870
|
+
* `PUT /` — full replace one or many records by primary key. Same OCC
|
|
871
|
+
* shapes as {@link update}; the version column itself is optional.
|
|
872
|
+
*/
|
|
873
|
+
replace(data: RowOf<T> | RowOf<T>[], opts?: TClientCallOptions): Promise<TDbUpdateResult>;
|
|
874
|
+
/**
|
|
875
|
+
* `DELETE /:id` or `DELETE /?k1=v1&k2=v2` — remove a record by primary key.
|
|
876
|
+
*/
|
|
877
|
+
remove(id: Id<T>, opts?: TClientCallOptions): Promise<TDbDeleteResult>;
|
|
878
|
+
/**
|
|
879
|
+
* `GET /meta` — table/view metadata (cached after first call).
|
|
880
|
+
*
|
|
881
|
+
* The response is revalidated through the client's meta store
|
|
882
|
+
* (`ClientOptions.metaStore`): ETags seen before for this store key go out
|
|
883
|
+
* as `If-None-Match`, and a `304 Not Modified` reuses the stored body.
|
|
884
|
+
*/
|
|
885
|
+
meta(): Promise<MetaResponse>;
|
|
886
|
+
/**
|
|
887
|
+
* The `ETag` of the `/meta` body {@link meta} resolved to — `undefined`
|
|
888
|
+
* before it resolves, after {@link invalidateMeta}, or when the server sent
|
|
889
|
+
* no readable `ETag` (cross-origin without `Access-Control-Expose-Headers:
|
|
890
|
+
* ETag`). Equal ETags mean byte-identical `/meta` bodies, so it can key
|
|
891
|
+
* anything derived from them (deserialized types, validators, column
|
|
892
|
+
* definitions) across clients and route params.
|
|
893
|
+
*
|
|
894
|
+
* @since 0.1.153
|
|
895
|
+
*/
|
|
896
|
+
metaEtag(): string | undefined;
|
|
897
|
+
/**
|
|
898
|
+
* The {@link MetaStore} {@link meta} revalidates through — the shared
|
|
899
|
+
* default store, the one passed as `ClientOptions.metaStore`, or
|
|
900
|
+
* `undefined` when that option was `false`. Read-only: clear it on an
|
|
901
|
+
* identity change (`client.metaStore?.clear()`) together with
|
|
902
|
+
* {@link invalidateMeta}.
|
|
903
|
+
*
|
|
904
|
+
* @since 0.1.155
|
|
905
|
+
*/
|
|
906
|
+
get metaStore(): MetaStore | undefined;
|
|
907
|
+
/**
|
|
908
|
+
* Drops everything this client cached from the server's metadata — the
|
|
909
|
+
* `/meta` response, the validator built from it and the loaded action
|
|
910
|
+
* forms — so the next call fetches them again. Call it when the viewer's
|
|
911
|
+
* identity changes (login, logout, role change): `/meta` is projected per
|
|
912
|
+
* user, and a client reused across identities would otherwise keep serving
|
|
913
|
+
* the previous user's columns, actions and write rules.
|
|
914
|
+
*
|
|
915
|
+
* The next `meta()` still revalidates through the meta store, so an
|
|
916
|
+
* unchanged `/meta` costs a `304`, not a download. On an identity change
|
|
917
|
+
* also clear the store (`clearMetaStore()` / `metaStore.clear()`).
|
|
918
|
+
*
|
|
919
|
+
* @since 0.1.151
|
|
920
|
+
*/
|
|
921
|
+
invalidateMeta(): void;
|
|
922
|
+
/**
|
|
923
|
+
* Invoke a declared action by name. Resolves the action descriptor from the
|
|
924
|
+
* cached `/meta` response, then dispatches based on `processor`:
|
|
925
|
+
*
|
|
926
|
+
* - `'backend'` → POST the identifier as a JSON body to the action's path
|
|
927
|
+
* and return the parsed server response. The HTTP method is always POST.
|
|
928
|
+
* - `'navigate'` → for `level: 'row'`, substitute `$1` in `value` with the
|
|
929
|
+
* identifier values, walking `meta.preferredId` field order (each value
|
|
930
|
+
* URL-encoded, compound IDs joined with `/`); for `level: 'rows'` or
|
|
931
|
+
* `'table'`, navigate to `value` verbatim. The default navigator (browser
|
|
932
|
+
* only) calls `window.location.assign(url)`. Provide
|
|
933
|
+
* `ClientOptions.navigate` to integrate with a SPA router.
|
|
934
|
+
* - `'custom'` → throw {@link ActionUnsupportedError}; UI-dispatched events
|
|
935
|
+
* are the application's responsibility, not the client's.
|
|
936
|
+
*
|
|
937
|
+
* Throws {@link ActionNotFoundError} when the action is not present in `/meta`.
|
|
938
|
+
*
|
|
939
|
+
* **Identifier shape (server contract).** `id` is always an object (single)
|
|
940
|
+
* or array of objects (multi) — never a scalar. Each object's field set
|
|
941
|
+
* must exactly match one legitimate identification on the table (PK or any
|
|
942
|
+
* `@db.index.unique` group). Even single-field PK tables send `{ id: 'abc' }`,
|
|
943
|
+
* not `'abc'`. `level: 'table'` actions take no identifier (`undefined`).
|
|
944
|
+
*
|
|
945
|
+
* The TypeScript signature widens to `Partial<Own<T>>` because the server's
|
|
946
|
+
* exact-match validation cannot be expressed at the type level. Mismatched
|
|
947
|
+
* field sets produce HTTP 400; obvious type errors (scalars, `null`) are
|
|
948
|
+
* caught at compile time when `T` is typed.
|
|
949
|
+
*
|
|
950
|
+
* **Form input.** When the action's `inputForm` field is set, the server
|
|
951
|
+
* expects a structured payload in the envelope's `input` field. Pass it as
|
|
952
|
+
* the third argument; the schema can be fetched ahead of time via
|
|
953
|
+
* {@link getActionForm} to drive a UI form. Body shape on the wire is
|
|
954
|
+
* `{ ids?, input? }` — `ids` carries `id` (object or array per level),
|
|
955
|
+
* `input` carries the form payload.
|
|
956
|
+
*
|
|
957
|
+
* **Delegated actions** (since 0.1.147). An action another controller owns
|
|
958
|
+
* (`owner`, e.g. a view listing its source table's actions) may carry
|
|
959
|
+
* `idMap`: each `id` is then a row (or identifier) of THIS controller and
|
|
960
|
+
* is mapped to the owner's identification — `{ [ownerField]:
|
|
961
|
+
* row[path] }` — before it is sent to `value` (the owner's route). A
|
|
962
|
+
* missing path throws `TypeError`. See {@link actionIdentifier}.
|
|
963
|
+
*
|
|
964
|
+
* @typeParam R Caller-asserted return shape from the action handler. The
|
|
965
|
+
* server returns whatever the handler emits (commonly
|
|
966
|
+
* `{ message?: string, ... }`); the client cannot validate.
|
|
967
|
+
*/
|
|
968
|
+
action<R = unknown>(name: string, id?: Partial<Own<T>> | Partial<Own<T>>[], input?: unknown): Promise<R>;
|
|
969
|
+
/**
|
|
970
|
+
* Runs a `'rows'` action on every row matching a query (since 0.1.147) —
|
|
971
|
+
* the action's `/meta` entry must carry `queryTarget`. POSTs
|
|
972
|
+
* `{ query: { q, exclude?, expectCount?, maxRows? }, input? }` to
|
|
973
|
+
* `queryTarget.url` (a delegated action: the view resolves the rows and
|
|
974
|
+
* runs the owner's action in batches) or `value`. `q` is the `/query`
|
|
975
|
+
* string of `target.filter` / `search` / `index`.
|
|
976
|
+
*
|
|
977
|
+
* The server answers what the handler returns — for a delegated action
|
|
978
|
+
* (and a handler returning `target.summary()`) a
|
|
979
|
+
* {@link TDbActionTargetSummary}. Refusals arrive as
|
|
980
|
+
* {@link ActionTargetError}: `TARGET_TOO_LARGE` (`cap`), `TARGET_CHANGED`
|
|
981
|
+
* (`matched` differs from `expectCount`), `TARGET_INVALID`. Throws
|
|
982
|
+
* {@link ActionUnsupportedError} when the action takes no query target.
|
|
983
|
+
*
|
|
984
|
+
* @since 0.1.147
|
|
985
|
+
*/
|
|
986
|
+
actionOnQuery<R = TDbActionTargetSummary>(name: string, target: TDbQueryTarget<T>, input?: unknown): Promise<R>;
|
|
987
|
+
/**
|
|
988
|
+
* How many rows {@link actionOnQuery} would target right now (a dry run:
|
|
989
|
+
* the handler does not run) — pass the answer as `expectCount` to make the
|
|
990
|
+
* real run fail with `TARGET_CHANGED` if the set changed in between.
|
|
991
|
+
*
|
|
992
|
+
* @since 0.1.147
|
|
993
|
+
*/
|
|
994
|
+
countActionTarget(name: string, target: TDbQueryTarget<T>): Promise<{
|
|
995
|
+
matched: number;
|
|
996
|
+
}>;
|
|
997
|
+
private _queryTargetAction;
|
|
998
|
+
private _postQueryTarget;
|
|
999
|
+
/**
|
|
1000
|
+
* `GET /meta/actions/:id` or `GET /meta/actions?k1=v1&k2=v2` — the
|
|
1001
|
+
* row-level actions the caller may run on one row right now, and the
|
|
1002
|
+
* reasons of those disabled with one: `{ actions, disabledReasons? }`.
|
|
1003
|
+
* Works for rows the caller cannot read; an unknown or out-of-scope id
|
|
1004
|
+
* resolves to `{ actions: [] }`. Id forms as {@link one}.
|
|
1005
|
+
*
|
|
1006
|
+
* @since 0.1.145
|
|
1007
|
+
*/
|
|
1008
|
+
availableActions(id: Id<T>): Promise<TDbAvailableActions>;
|
|
1009
|
+
/**
|
|
1010
|
+
* Fetches and caches the deserialized form schema for an action's
|
|
1011
|
+
* `@InputForm()` parameter. Returns `null` when the action has no form
|
|
1012
|
+
* declared, or doesn't exist on `/meta`. Callers typically pass the
|
|
1013
|
+
* returned annotated type to a form-renderer (e.g. `@atscript/ui` form
|
|
1014
|
+
* components) and then submit the collected payload through
|
|
1015
|
+
* {@link action}'s `input` argument.
|
|
1016
|
+
*
|
|
1017
|
+
* The schema comes from this controller's `meta/form/:name`, or — when the
|
|
1018
|
+
* action carries `formUrl` — from `baseUrl + formUrl`.
|
|
1019
|
+
* Cached per resolved URL.
|
|
1020
|
+
*/
|
|
1021
|
+
getActionForm(actionName: string): Promise<TAtscriptAnnotatedType | null>;
|
|
1022
|
+
/**
|
|
1023
|
+
* The texts the action's form schema was served with in this client's
|
|
1024
|
+
* locale (its `$i18n`: registered message templates and the translated
|
|
1025
|
+
* literals of its expressions), or `undefined` when the server sent none
|
|
1026
|
+
* or the action has no form. Read from the same cached response as
|
|
1027
|
+
* {@link getActionForm}; merge them into your UI texts to show the form's
|
|
1028
|
+
* expression results in the user's language.
|
|
1029
|
+
*
|
|
1030
|
+
* @since 0.1.170
|
|
1031
|
+
*/
|
|
1032
|
+
getActionFormTexts(actionName: string): Promise<Record<string, string> | undefined>;
|
|
1033
|
+
private _actionForm;
|
|
1034
|
+
private _loadActionForm;
|
|
1035
|
+
/**
|
|
1036
|
+
* Returns a lazily-initialized {@link ClientValidator} backed by the `/meta` type.
|
|
1037
|
+
* Useful for accessing `flatMap` and `navFields` (e.g. for form generation).
|
|
1038
|
+
*/
|
|
1039
|
+
getValidator(): Promise<ClientValidator>;
|
|
1040
|
+
/** Lifts `$cas` to the wire shape, normalizes, then validates the result — which is what gets sent. */
|
|
1041
|
+
private _prepareWrite;
|
|
1042
|
+
private _getValidator;
|
|
1043
|
+
private _buildActionBody;
|
|
1044
|
+
private _interpolateNavigateUrl;
|
|
1045
|
+
private _dispatchNavigate;
|
|
1046
|
+
private _postAction;
|
|
1047
|
+
private _idToParams;
|
|
1048
|
+
/**
|
|
1049
|
+
* The endpoint addressing one row under `base`: `base/<id>` for a scalar
|
|
1050
|
+
* id, `base?k1=v1&k2=v2` for an object id; `query` (a query string) is
|
|
1051
|
+
* appended.
|
|
1052
|
+
*/
|
|
1053
|
+
private _idUrl;
|
|
1054
|
+
private _getOrNull;
|
|
1055
|
+
private _get;
|
|
1056
|
+
private _resolveHeaders;
|
|
1057
|
+
/** `ClientOptions.locale` now. */
|
|
1058
|
+
private _currentLocale;
|
|
1059
|
+
/** {@link _currentLocale}, after dropping the `/meta`, validator and forms loaded in another one. */
|
|
1060
|
+
private _syncLocale;
|
|
1061
|
+
/**
|
|
1062
|
+
* `GET /meta` through the meta store: conditional when the store holds
|
|
1063
|
+
* bodies for this key, falling back to a plain request whenever the
|
|
1064
|
+
* conditional one cannot be answered from the store.
|
|
1065
|
+
*/
|
|
1066
|
+
private _loadMeta;
|
|
1067
|
+
/** Reads a `/meta` response; a `2xx` carrying a readable `ETag` goes into the store. */
|
|
1068
|
+
private _storeMeta;
|
|
1069
|
+
private _request;
|
|
1070
|
+
/** `baseUrl + path` joined with an endpoint relative to this controller (`""`, `meta`, `?q`…). */
|
|
1071
|
+
private _endpointUrl;
|
|
1072
|
+
/** Sends one request to an absolute URL with the client's headers and a JSON body. */
|
|
1073
|
+
private _requestUrl;
|
|
1074
|
+
private _send;
|
|
1075
|
+
/** `fetch` with a network failure surfaced as {@link TransportError}. */
|
|
1076
|
+
private _fetchUrl;
|
|
1077
|
+
/** A response's JSON body, or the matching error for a non-2xx status. */
|
|
1078
|
+
private _readResponse;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* The identifier `action` takes for one row (or identifier) of the
|
|
1082
|
+
* controller whose `/meta` listed it (since 0.1.147):
|
|
1083
|
+
*
|
|
1084
|
+
* - a delegated action with `idMap` → the owner's identification,
|
|
1085
|
+
* `{ [ownerField]: rowOrId[path] }` (dot paths allowed); a missing value
|
|
1086
|
+
* throws `TypeError` naming the action and the path;
|
|
1087
|
+
* - any other action → `rowOrId`'s `preferredId` fields when it carries them
|
|
1088
|
+
* all, else `rowOrId` itself (already an identifier).
|
|
1089
|
+
*
|
|
1090
|
+
* UIs build `ids` from loaded rows with it; `Client.action()` applies the
|
|
1091
|
+
* `idMap` mapping itself.
|
|
1092
|
+
*
|
|
1093
|
+
* @since 0.1.147
|
|
1094
|
+
*/
|
|
1095
|
+
declare function actionIdentifier(action: Pick<TDbActionInfo, "name" | "idMap">, rowOrId: Record<string, unknown>, preferredId: readonly string[]): Record<string, unknown>;
|
|
1096
|
+
/**
|
|
1097
|
+
* Render a single identifier field for substitution into a navigate-URL
|
|
1098
|
+
* template or human-readable string. `null` / `undefined` collapse to `""`
|
|
1099
|
+
* (NOT the literal `"undefined"` / `"null"` that `String()` would produce).
|
|
1100
|
+
*/
|
|
1101
|
+
declare function formatIdentifierField(v: unknown): string;
|
|
1102
|
+
/**
|
|
1103
|
+
* Render a row identifier as a `/`-joined string in `preferredId`
|
|
1104
|
+
* declaration order — NOT object-key insertion order (which is unstable
|
|
1105
|
+
* across callers). Raw form, no URL-encoding; for prompt text, error
|
|
1106
|
+
* messages, log lines, etc.
|
|
1107
|
+
*/
|
|
1108
|
+
declare function formatIdentifier(id: Record<string, unknown> | undefined, preferredId: readonly string[]): string;
|
|
1109
|
+
/**
|
|
1110
|
+
* URL-encoded form of `formatIdentifier` — for `processor: 'navigate'`
|
|
1111
|
+
* `$1` substitution. Each field is `encodeURIComponent`'d, then joined
|
|
1112
|
+
* with a literal `/`. Missing fields render as empty segments (e.g.
|
|
1113
|
+
* `acme//jane`), not the literal `"undefined"`.
|
|
1114
|
+
*/
|
|
1115
|
+
declare function encodeNavigateId(id: Record<string, unknown>, preferredId: readonly string[]): string;
|
|
1116
|
+
//#endregion
|
|
1117
|
+
export { RelationInfo as $, AggregateStage as A, DbPatch as B, ClientError as C, VersionMismatchErrorBody as D, VersionMismatchError as E, ClientLike as F, InsertOf as G, FieldMeta as H, ClientOptions as I, NestedAggregateQuery$1 as J, MetaResponse as K, ClientResponse as L, BucketExpr as M, BucketUnit as N, AggregateQuery$1 as O, CalendarBucketLabel as P, PatchOf as Q, DataOf as R, ActionUnsupportedError as S, defaultMetaStore as St, TransportError as T, FilterExpr as U, DbRow as V, IdOf as W, OwnOf as X, NestedAggregateResult$1 as Y, PageResult as Z, ActionDisabledError as _, ValidNested$1 as _t, InsertedRow as a, TClientCallOptions as at, ActionTargetError as b, MetaStoreOptions as bt, actionIdentifier as c, TDbInsertManyIgnoreResult$1 as ct, formatIdentifierField as d, TDbQueryTarget as dt, ResponseDataOf as et, ClientValidator as f, TDbUpdateResult$1 as ft, createClientValidator as g, ValidGroupBy$1 as gt, ValidatorMode$1 as h, UniqueryControls as ht, DecoratedRow as i, StageRow as it, AtscriptClientShape as j, AggregateResult$1 as k, encodeNavigateId as l, TDbInsertManyResult$1 as lt, DbValidationContext as m, Uniquery$1 as mt, AggregateRows as n, SearchIndexInfo as nt, ReadRow as o, TDbDeleteResult$1 as ot, ClientValidatorOptions as p, TypedWithRelation as pt, NavOf as q, Client as r, ServerError as rt, SingleInsertOf as s, TDbInsertIgnoreResult$1 as st, AggregateCheck as t, RowOf as tt, formatIdentifier as u, TDbInsertResult$1 as ut, ActionDisabledErrorBody as v, WeekStart as vt, ClientValidationError as w, ActionTargetErrorBody as x, clearMetaStore as xt, ActionNotFoundError as y, MetaStore as yt, DbInsert as z };
|