@haddowg/json-api-client 1.30.0 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ajv.cjs +1 -1
- package/dist/ajv.d.cts +1 -1
- package/dist/ajv.d.mts +1 -1
- package/dist/ajv.mjs +1 -1
- package/dist/index.cjs +338 -28
- package/dist/index.d.cts +109 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +109 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +330 -29
- package/dist/index.mjs.map +1 -1
- package/dist/{validate-B2Dtn9dI.cjs → validate-B9cyfO3p.cjs} +20 -4
- package/dist/{validate-CtXB1MGk.mjs → validate-BuPAPJMi.mjs} +16 -6
- package/dist/validate-BuPAPJMi.mjs.map +1 -0
- package/dist/{validate-ugcQVpb0.d.mts → validate-DyNfTJ52.d.cts} +334 -50
- package/dist/validate-DyNfTJ52.d.cts.map +1 -0
- package/dist/{validate-ugcQVpb0.d.cts → validate-DyNfTJ52.d.mts} +334 -50
- package/dist/validate-DyNfTJ52.d.mts.map +1 -0
- package/package.json +1 -1
- package/dist/validate-CtXB1MGk.mjs.map +0 -1
- package/dist/validate-ugcQVpb0.d.cts.map +0 -1
- package/dist/validate-ugcQVpb0.d.mts.map +0 -1
|
@@ -117,6 +117,13 @@ interface RelationDescriptor {
|
|
|
117
117
|
pivotFields?: Readonly<Record<string, string>>;
|
|
118
118
|
/** The `meta.pivot` a response renders on each member (`<Type><Rel>Pivot`). */
|
|
119
119
|
readPivot?: PivotDescriptor;
|
|
120
|
+
/**
|
|
121
|
+
* `true` when a response renders `meta.pivot` on every member of the relation's linkage, as its
|
|
122
|
+
* response identifiers require `meta` and its `pivot`. A linkage member's `$pivot` and `$edge`
|
|
123
|
+
* are then always present. Absent means a member may come without them. A request never has to
|
|
124
|
+
* send a pivot.
|
|
125
|
+
*/
|
|
126
|
+
pivotRendered?: boolean;
|
|
120
127
|
/**
|
|
121
128
|
* The `meta.pivot` a request may send on each member (`<Type><Rel>WritePivot`): a create,
|
|
122
129
|
* update or atomic body, or a relationship mutation.
|
|
@@ -1221,6 +1228,19 @@ declare function materialise(doc: Document, ctx: MaterialiseContext, linkage?: b
|
|
|
1221
1228
|
* answers `false`, which is how a hydrated cache entry is told from a fresh read.
|
|
1222
1229
|
*/
|
|
1223
1230
|
declare function isMaterialised(value: unknown): value is object;
|
|
1231
|
+
/**
|
|
1232
|
+
* The relations of `view` that read through to its node as linkage (a back-reference a relation
|
|
1233
|
+
* cycle built before the node's later relations were set), or `undefined`. A cache layer leaves
|
|
1234
|
+
* these slots alone: they follow the node.
|
|
1235
|
+
* @internal
|
|
1236
|
+
*/
|
|
1237
|
+
declare function lateRelationsOf(view: object): ReadonlySet<string> | undefined;
|
|
1238
|
+
/**
|
|
1239
|
+
* Tell the client a cache layer wrote relation `name` of the cached copy `copy`: a node that
|
|
1240
|
+
* back-references read the relation through to takes the value too, so they read it.
|
|
1241
|
+
* @internal
|
|
1242
|
+
*/
|
|
1243
|
+
declare function relationWritten(copy: object, name: string, value: unknown): void;
|
|
1224
1244
|
/** The linkage member a per-edge or identifier view is built for: its identity and its meta. */
|
|
1225
1245
|
interface EdgeMember {
|
|
1226
1246
|
type: string;
|
|
@@ -1259,6 +1279,76 @@ declare function relatedPaginator(relation: RelationDescriptor | undefined, ctx:
|
|
|
1259
1279
|
/** The kind a relation's related read answers with when it sends no `page`. See {@link relatedPaginator}. */
|
|
1260
1280
|
declare function relatedPaginatorKind(relation: RelationDescriptor | undefined, ctx: MaterialiseContext): PaginatorKind;
|
|
1261
1281
|
//#endregion
|
|
1282
|
+
//#region src/input-validation.d.ts
|
|
1283
|
+
/**
|
|
1284
|
+
* The parts of the Standard Schema interface (standardschema.dev) the client calls. Zod, Valibot
|
|
1285
|
+
* and ArkType schemas implement it.
|
|
1286
|
+
*/
|
|
1287
|
+
interface StandardSchema<Input = unknown> {
|
|
1288
|
+
readonly '~standard': {
|
|
1289
|
+
readonly version: 1;
|
|
1290
|
+
readonly vendor: string;
|
|
1291
|
+
readonly validate: (value: unknown) => StandardSchemaResult | Promise<StandardSchemaResult>;
|
|
1292
|
+
readonly types?: {
|
|
1293
|
+
readonly input: Input;
|
|
1294
|
+
} | undefined;
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
/** What a Standard Schema's `validate` returns. */
|
|
1298
|
+
type StandardSchemaResult = {
|
|
1299
|
+
readonly value: unknown;
|
|
1300
|
+
readonly issues?: undefined;
|
|
1301
|
+
} | {
|
|
1302
|
+
readonly issues: readonly StandardSchemaIssue[];
|
|
1303
|
+
};
|
|
1304
|
+
/** One problem a Standard Schema found. */
|
|
1305
|
+
interface StandardSchemaIssue {
|
|
1306
|
+
readonly message: string;
|
|
1307
|
+
readonly path?: readonly (PropertyKey | {
|
|
1308
|
+
readonly key: PropertyKey;
|
|
1309
|
+
})[] | undefined;
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* The schemas `createClient({ validateInput })` checks a write's input against before sending it,
|
|
1313
|
+
* by wire type: `{ albums: { create: albumsCreateSchema, update: albumsUpdateSchema } }`. A type or
|
|
1314
|
+
* a write with no schema is sent unchecked. `json-api-codegen --zod` generates this map.
|
|
1315
|
+
*/
|
|
1316
|
+
type InputSchemas = Readonly<Record<string, {
|
|
1317
|
+
readonly create?: StandardSchema;
|
|
1318
|
+
readonly update?: StandardSchema;
|
|
1319
|
+
}>>;
|
|
1320
|
+
/**
|
|
1321
|
+
* Thrown by a create or update whose input fails the schema `validateInput` holds for it, before
|
|
1322
|
+
* any request is sent. `fieldErrors(error)` takes it as it takes a server's 422.
|
|
1323
|
+
*/
|
|
1324
|
+
declare class InputValidationError extends Error {
|
|
1325
|
+
readonly type: string;
|
|
1326
|
+
readonly operation: 'create' | 'update';
|
|
1327
|
+
readonly issues: readonly StandardSchemaIssue[];
|
|
1328
|
+
/** The failing operation's index in an atomic batch. */
|
|
1329
|
+
readonly opIndex?: number;
|
|
1330
|
+
constructor(type: string, operation: 'create' | 'update', issues: readonly StandardSchemaIssue[], opIndex?: number);
|
|
1331
|
+
}
|
|
1332
|
+
/** One write's input, as `validateInput` checks it. */
|
|
1333
|
+
interface InputCheck {
|
|
1334
|
+
readonly type: string;
|
|
1335
|
+
readonly operation: 'create' | 'update';
|
|
1336
|
+
readonly input: unknown;
|
|
1337
|
+
readonly opIndex?: number;
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* The {@link InputValidationError} `check`'s input fails its schema in `schemas` with, or
|
|
1341
|
+
* `undefined` when it passes or has no schema. A Promise only for a schema that validates
|
|
1342
|
+
* asynchronously.
|
|
1343
|
+
*/
|
|
1344
|
+
declare function inputFailure(schemas: InputSchemas | undefined, check: InputCheck): InputValidationError | undefined | Promise<InputValidationError | undefined>;
|
|
1345
|
+
/**
|
|
1346
|
+
* Run `write` once `check`'s input passes its schema, else reject with the
|
|
1347
|
+
* {@link InputValidationError}. A write with no schema, or a schema that validates synchronously,
|
|
1348
|
+
* starts in this tick.
|
|
1349
|
+
*/
|
|
1350
|
+
declare function withInputCheck<T>(schemas: InputSchemas | undefined, check: InputCheck, write: () => Promise<T>): Promise<T>;
|
|
1351
|
+
//#endregion
|
|
1262
1352
|
//#region src/atomic.d.ts
|
|
1263
1353
|
/**
|
|
1264
1354
|
* A reference to a resource for an `update`/`remove` op: a bare identifier (or a materialised
|
|
@@ -1436,7 +1526,7 @@ type AtomicResults<D extends ApiDescriptor, A, Ops extends readonly AtomicHandle
|
|
|
1436
1526
|
* A thrown {@link JsonApiError} has each error's pointer remapped to `(opIndex, flatPath)` (the
|
|
1437
1527
|
* failing op's type drives the flat-path inversion) before it propagates.
|
|
1438
1528
|
*/
|
|
1439
|
-
declare function runAtomic<D extends ApiDescriptor, A, W, const Ops>(request: JsonApiContext, materialiseCtx: MaterialiseContext, descriptor: D, path: string, build: (tx: AtomicRecorder<D, W>) => Ops): Promise<Ops extends readonly AtomicHandle[] ? AtomicResults<D, A, Ops> : AtomicResult[]>;
|
|
1529
|
+
declare function runAtomic<D extends ApiDescriptor, A, W, const Ops>(request: JsonApiContext, materialiseCtx: MaterialiseContext, descriptor: D, path: string, build: (tx: AtomicRecorder<D, W>) => Ops, inputSchemas?: InputSchemas): Promise<Ops extends readonly AtomicHandle[] ? AtomicResults<D, A, Ops> : AtomicResult[]>;
|
|
1440
1530
|
//#endregion
|
|
1441
1531
|
//#region src/location.d.ts
|
|
1442
1532
|
/**
|
|
@@ -1496,22 +1586,61 @@ type MemberTypeOf<T> = T extends {
|
|
|
1496
1586
|
* A to-many relationship value: a {@link Collection} that also carries `$count`, the
|
|
1497
1587
|
* relationship's `meta.total` when the read counted it.
|
|
1498
1588
|
*/
|
|
1499
|
-
type RelationCollection<T, P = Page> =
|
|
1589
|
+
type RelationCollection<T, P = Page> = [T] extends [infer Member] ? // Built inline, not as `Collection<…>`, so an editor shows the members' fields.
|
|
1590
|
+
ReadonlyArray<Member> & ListMethods<P, MemberTypeOf<Member>> : never;
|
|
1591
|
+
/** The `$`-accessors of a to-many relationship value, beside its members. */
|
|
1592
|
+
interface ListMethods<P = Page, TType extends string = string> extends Omit<ArrayEnvelope, '$page' | '$next' | '$prev'>, RelationArrayEnvelope {
|
|
1593
|
+
readonly $page: P;
|
|
1594
|
+
$next(options?: NavigateOptions): Promise<this | undefined>;
|
|
1595
|
+
$prev(options?: NavigateOptions): Promise<this | undefined>;
|
|
1596
|
+
/**
|
|
1597
|
+
* The creates a cache layer (an optimistic draft in `@haddowg/json-api-query`) placed in this
|
|
1598
|
+
* list but couldn't show as members yet. Empty when there are none.
|
|
1599
|
+
*/
|
|
1600
|
+
$pending?(): readonly PendingCreate<Readonly<Record<string, unknown>>, TType>[];
|
|
1601
|
+
}
|
|
1500
1602
|
/**
|
|
1501
1603
|
* The edge-local accessors carried by a materialised related VALUE (a per-edge view):
|
|
1502
1604
|
* `$edge` (this membership's edge meta/links) and `$pivot` (typed sugar over
|
|
1503
1605
|
* `$edge.meta.pivot`). `$pivot` is graceful: present iff the endpoint rendered
|
|
1504
1606
|
* `meta.pivot` (relationship/related endpoints), `undefined` otherwise. `Meta` types
|
|
1505
|
-
* `$edge.meta` where the linkage renders the relation's declared identifier meta.
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1607
|
+
* `$edge.meta` where the linkage renders the relation's declared identifier meta. `Rendered` is
|
|
1608
|
+
* `true` for a member of a linkage that renders `meta.pivot` on every member, whose `$edge`,
|
|
1609
|
+
* `$edge.meta` and `$pivot` are then always present.
|
|
1610
|
+
*
|
|
1611
|
+
* `Pending` is the pivot and edge meta a pending optimistic member carries, when they differ from
|
|
1612
|
+
* a confirmed one's: such a member holds only the pivot values its write sent, so every field the
|
|
1613
|
+
* write pivot doesn't require is optional. The type is then a union on `$optimistic`, and checking that it
|
|
1614
|
+
* isn't `'pending'` gives the confirmed member's types.
|
|
1615
|
+
*/
|
|
1616
|
+
type EdgeMembers<Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown>, Rendered extends boolean = false, Pending extends PendingEdge = never> = [Pending] extends [never] ? EdgeAccessors<Pivot, Meta, Rendered, 'pending' | undefined> : EdgeAccessors<Pivot, Meta, Rendered, undefined> | EdgeAccessors<Pending['pivot'], Pending['meta'], Rendered, 'pending'>;
|
|
1617
|
+
/** The pivot and edge meta of a pending optimistic member, as {@link EdgeMembers} takes them. */
|
|
1618
|
+
interface PendingEdge {
|
|
1619
|
+
readonly pivot: unknown;
|
|
1620
|
+
readonly meta: Record<string, unknown>;
|
|
1621
|
+
}
|
|
1622
|
+
/** The accessors {@link EdgeMembers} describes, for one value of `$optimistic`. */
|
|
1623
|
+
type EdgeAccessors<Pivot, Meta extends Record<string, unknown>, Rendered extends boolean, Optimistic extends 'pending' | undefined> = [Optimistic] extends ['pending'] ? PendingEdgeMethods<Pivot, Meta, Rendered> : EdgeMethods<Pivot, Meta, Rendered, Optimistic>;
|
|
1624
|
+
/** The `$`-accessors of one membership of a relation: its edge meta and links, and its pivot. */
|
|
1625
|
+
interface EdgeMethods<Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown>, Rendered extends boolean = false, Optimistic extends 'pending' | undefined = 'pending' | undefined> {
|
|
1626
|
+
readonly $edge: Rendered extends true ? Edge<Meta> & {
|
|
1627
|
+
readonly meta: Meta;
|
|
1628
|
+
} : Edge<Meta> | undefined;
|
|
1629
|
+
readonly $pivot: Rendered extends true ? Pivot : Pivot | undefined;
|
|
1510
1630
|
/**
|
|
1511
1631
|
* `'pending'` while a cache layer (an optimistic draft in `@haddowg/json-api-query`) holds an
|
|
1512
1632
|
* unconfirmed change to this member, else `undefined`.
|
|
1513
1633
|
*/
|
|
1514
|
-
readonly $optimistic?:
|
|
1634
|
+
readonly $optimistic?: Optimistic;
|
|
1635
|
+
}
|
|
1636
|
+
/** The {@link EdgeMethods} of a member a pending write holds, with only the pivot that write sent. */
|
|
1637
|
+
interface PendingEdgeMethods<Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown>, Rendered extends boolean = false> {
|
|
1638
|
+
readonly $edge: Rendered extends true ? Edge<Meta> & {
|
|
1639
|
+
readonly meta: Meta;
|
|
1640
|
+
} : Edge<Meta> | undefined;
|
|
1641
|
+
readonly $pivot: Rendered extends true ? Pivot : Pivot | undefined;
|
|
1642
|
+
/** `'pending'`: a cache layer holds an unconfirmed change to this member. */
|
|
1643
|
+
readonly $optimistic: 'pending';
|
|
1515
1644
|
}
|
|
1516
1645
|
/**
|
|
1517
1646
|
* The resource-level `$`-accessors on a materialised resource object. `Links` types `$links`: the
|
|
@@ -1656,25 +1785,53 @@ type RelationPage<D extends ApiDescriptor, T extends TypeName<D>, R extends Rela
|
|
|
1656
1785
|
/**
|
|
1657
1786
|
* The bare resource-identifier shape a non-included (but linked) relation takes,
|
|
1658
1787
|
* carrying the per-edge `$edge`/`$pivot` accessors the runtime attaches to every
|
|
1659
|
-
* materialised related value.
|
|
1788
|
+
* materialised related value. `Rendered` marks them always present, as {@link EdgeMembers} says.
|
|
1660
1789
|
*/
|
|
1661
|
-
type IdentifierMember<TType extends string, Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown
|
|
1790
|
+
type IdentifierMember<TType extends string, Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown>, Rendered extends boolean = false, Pending extends PendingEdge = never> = [EdgeMembers<Pivot, Meta, Rendered, Pending>] extends [infer EdgeM] ? // Built inline, not through an alias, so an editor shows the identifier and not this name.
|
|
1791
|
+
ResourceIdentifier<TType> & EdgeM : never;
|
|
1662
1792
|
/**
|
|
1663
1793
|
* A hydrated related resource: a per-edge VIEW — the full `ResourceObjectView` of the
|
|
1664
|
-
* related node plus this membership's `$edge`/`$pivot`.
|
|
1665
|
-
*
|
|
1794
|
+
* related node plus this membership's `$edge`/`$pivot`. `Inc` holds the rest of the read's
|
|
1795
|
+
* include paths below this relation (`album` for `tracks.album`), which hydrate its own
|
|
1796
|
+
* relations in turn; the others stay identifiers. The fieldset map `F`
|
|
1666
1797
|
* threads through so a sparse fieldset on the included type narrows its attributes/relations.
|
|
1667
1798
|
* `Pivot` types the per-edge `$pivot` (a `belongsToMany` relation's `meta.pivot`), and `Meta` the
|
|
1668
|
-
* per-edge `$edge.meta`.
|
|
1799
|
+
* per-edge `$edge.meta`. `Rendered` marks them always present, as {@link EdgeMembers} says.
|
|
1669
1800
|
*/
|
|
1670
|
-
type HydratedMember<D extends ApiDescriptor, A, TType extends TypeName<D>, F = unknown, Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown
|
|
1801
|
+
type HydratedMember<D extends ApiDescriptor, A, TType extends TypeName<D>, F = unknown, Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown>, Rendered extends boolean = false, Pending extends PendingEdge = never, Inc = never> = TType extends unknown ? Flat<ResourceFields<D, A, TType, Inc, F>> & ResourceMethods<D, A, TType> & EdgeMembers<Pivot, Meta, Rendered, Pending> : never;
|
|
1671
1802
|
/** A hydrated related value distributes over a polymorphic union of related types. */
|
|
1672
|
-
type Hydrated<D extends ApiDescriptor, A, TType extends TypeName<D>, F = unknown, Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown
|
|
1803
|
+
type Hydrated<D extends ApiDescriptor, A, TType extends TypeName<D>, F = unknown, Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown>, Rendered extends boolean = false, Pending extends PendingEdge = never, Inc = never> = TType extends TypeName<D> ? HydratedMember<D, A, TType, F, Pivot, Meta, Rendered, Pending, Inc> : never;
|
|
1804
|
+
/** The relation an include path starts with: `tracks` for `tracks.album`. */
|
|
1805
|
+
type IncludeHead<P> = P extends `${infer Head}.${string}` ? Head : P;
|
|
1806
|
+
/** The include paths below relation `R`, with its name taken off: `album` for `tracks.album`. */
|
|
1807
|
+
type IncludeTail<P, R extends string> = P extends `${R}.${infer Rest}` ? Rest : never;
|
|
1808
|
+
/**
|
|
1809
|
+
* The pivot interface the read-types map `A` names for relation `R` of `T` on side `Side`
|
|
1810
|
+
* (`read`, `pending` or `write`), under its `$declaredPivots` key, else `Fallback`. A generated
|
|
1811
|
+
* client names each one, so an editor shows `PlaylistsOrderedTracksPivot` instead of its fields.
|
|
1812
|
+
*/
|
|
1813
|
+
type NamedPivot<A, T, R, Side extends 'read' | 'pending' | 'write', Fallback> = A extends {
|
|
1814
|
+
readonly $declaredPivots: infer Pivots;
|
|
1815
|
+
} ? T extends keyof Pivots ? R extends keyof Pivots[T] ? Pivots[T][R] extends { readonly [K in Side]: infer Named } ? Named : Fallback : Fallback : Fallback : Fallback;
|
|
1816
|
+
/** The pivot a response renders on each member of relation `R`, by its generated name where it has one. */
|
|
1817
|
+
type ReadPivot<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>> = NamedPivot<A, T, R, 'read', PivotFieldsOf<D, T, R>>;
|
|
1818
|
+
/** The {@link PendingEdge} of relation `R`'s members, its pivot by its generated name where it has one. */
|
|
1819
|
+
type NamedPendingEdge<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, Pivot = NamedPivot<A, T, R, 'pending', PendingPivotOf<D, T, R>>> = [PendingEdgeOf<D, T, R>] extends [never] ? never : {
|
|
1820
|
+
readonly pivot: Pivot;
|
|
1821
|
+
readonly meta: EdgeMetaOf<D, T, R, Pivot>;
|
|
1822
|
+
};
|
|
1673
1823
|
/** An identifier related value distributes over a polymorphic union of related types. */
|
|
1674
|
-
type Identifier<TType extends string, Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown
|
|
1824
|
+
type Identifier<TType extends string, Pivot = Record<string, unknown>, Meta extends Record<string, unknown> = Record<string, unknown>, Rendered extends boolean = false, Pending extends PendingEdge = never> = TType extends string ? IdentifierMember<TType, Pivot, Meta, Rendered, Pending> : never;
|
|
1825
|
+
/**
|
|
1826
|
+
* `true` when relation `R` renders `meta.pivot` on every member of its linkage, as the
|
|
1827
|
+
* descriptor's `pivotRendered` says.
|
|
1828
|
+
*/
|
|
1829
|
+
type PivotRendered<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
1830
|
+
pivotRendered: true;
|
|
1831
|
+
} ? true : false;
|
|
1675
1832
|
/**
|
|
1676
|
-
* The static value of one relation slot, resolved by cardinality and whether the
|
|
1677
|
-
*
|
|
1833
|
+
* The static value of one relation slot, resolved by cardinality and whether one of the read's
|
|
1834
|
+
* include paths `Inc` starts with the relation's name:
|
|
1678
1835
|
*
|
|
1679
1836
|
* - to-one, included -> the hydrated related resource, or `null` (an empty to-one with
|
|
1680
1837
|
* `data: null` materialises to `null` even when included);
|
|
@@ -1684,8 +1841,11 @@ type Identifier<TType extends string, Pivot = Record<string, unknown>, Meta exte
|
|
|
1684
1841
|
*
|
|
1685
1842
|
* (Excluded to-many stays a `Collection`: linkage may still be present, and a lazy
|
|
1686
1843
|
* to-many materialises as an augmented array regardless — only its members differ.)
|
|
1844
|
+
*
|
|
1845
|
+
* An included member's own relations hydrate where a longer path names them (`tracks.album`).
|
|
1846
|
+
* Each member's `$pivot` is typed from the relation's `readPivot`, as on the relationship endpoint.
|
|
1687
1847
|
*/
|
|
1688
|
-
type RelationValue<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, Inc, F = unknown> = R extends Inc ? IsMany<D, T, R> extends true ? RelationCollection<Hydrated<D, A, RelatedType<D, T, R>, F,
|
|
1848
|
+
type RelationValue<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, Inc, F = unknown> = R extends IncludeHead<Inc> ? IsMany<D, T, R> extends true ? RelationCollection<Hydrated<D, A, RelatedType<D, T, R>, F, ReadPivot<D, A, T, R>, EdgeMetaOf<D, T, R, ReadPivot<D, A, T, R>>, PivotRendered<D, T, R>, NamedPendingEdge<D, A, T, R>, IncludeTail<Inc, R>>, RelationPage<D, T, R>> : Hydrated<D, A, RelatedType<D, T, R>, F, ReadPivot<D, A, T, R>, EdgeMetaOf<D, T, R, ReadPivot<D, A, T, R>>, PivotRendered<D, T, R>, NamedPendingEdge<D, A, T, R>, IncludeTail<Inc, R>> | null : IsMany<D, T, R> extends true ? RelationCollection<Identifier<RelatedType<D, T, R>, ReadPivot<D, A, T, R>, EdgeMetaOf<D, T, R, ReadPivot<D, A, T, R>>, PivotRendered<D, T, R>, NamedPendingEdge<D, A, T, R>>, RelationPage<D, T, R>> : Identifier<RelatedType<D, T, R>, ReadPivot<D, A, T, R>, EdgeMetaOf<D, T, R, ReadPivot<D, A, T, R>>, PivotRendered<D, T, R>, NamedPendingEdge<D, A, T, R>> | null | undefined;
|
|
1689
1849
|
/**
|
|
1690
1850
|
* The relation slots of type `T`, each typed by cardinality and include-presence, then
|
|
1691
1851
|
* narrowed to the fieldset selection for `T` (relations are sparse-fieldset members too — an
|
|
@@ -1710,22 +1870,31 @@ interface CountAccessor<D extends ApiDescriptor, T extends TypeName<D>, Counted
|
|
|
1710
1870
|
/**
|
|
1711
1871
|
* A materialised resource object: flattened `type` + `id` + attributes + relation slots
|
|
1712
1872
|
* as own enumerable props, intersected with the resource-level `$`-accessors. `Inc` is
|
|
1713
|
-
* the union of
|
|
1873
|
+
* the union of the read's include paths (each relation a path starts with is hydrated, and the
|
|
1874
|
+
* rest of the path hydrates that relation's own relations); `F` is
|
|
1714
1875
|
* the sparse-fieldset selection map (narrows attributes/relations to the requested members —
|
|
1715
1876
|
* `type`/`id`/the `$`-accessors are always present). The default `F = unknown` keeps every
|
|
1716
1877
|
* member (no fieldset narrowing). `Counted` names the relations the read counted, whose `$count`
|
|
1717
1878
|
* is then a `number`.
|
|
1718
1879
|
*/
|
|
1719
|
-
type ResourceObjectView<D extends ApiDescriptor, A, T extends TypeName<D>, Inc = never, F = unknown, Counted = never> =
|
|
1880
|
+
type ResourceObjectView<D extends ApiDescriptor, A, T extends TypeName<D>, Inc = never, F = unknown, Counted = never> = T extends unknown ? // A conditional on `T`, so an editor lists the fields instead of printing this alias's name.
|
|
1881
|
+
Flat<ResourceFields<D, A, T, Inc, F>> & ResourceMethods<D, A, T, Counted> : never;
|
|
1882
|
+
/** One object type for an intersection, keeping each member's modifiers. */
|
|
1883
|
+
type Flat<T> = { [K in keyof T]: T[K] } & {};
|
|
1884
|
+
/** The data members of a resource object: `type`, `id`, its attributes and its relation slots. */
|
|
1885
|
+
type ResourceFields<D extends ApiDescriptor, A, T extends TypeName<D>, Inc, F> = {
|
|
1720
1886
|
type: T;
|
|
1721
1887
|
id: string;
|
|
1722
|
-
} & PickSelectedAttributes<AttributesOf<A, T>, SelectedFields<F, T>> & Relations<D, A, T, Inc, F
|
|
1888
|
+
} & PickSelectedAttributes<AttributesOf<A, T>, SelectedFields<F, T>> & Relations<D, A, T, Inc, F>;
|
|
1889
|
+
/** The resource-level `$`-accessors of a type `T` resource object, `$count` among them. */
|
|
1890
|
+
interface ResourceMethods<D extends ApiDescriptor, A, T extends TypeName<D>, Counted = never> extends ResourceAccessors<LinksOf<A, T>, ResourceMetaOf<D, T>>, CountAccessor<D, T, Counted> {}
|
|
1723
1891
|
/**
|
|
1724
1892
|
* The element type of the `include` array for type `T`: a path from the descriptor's
|
|
1725
1893
|
* `includable` enum — the exact set the server advertises, including nested dotted paths
|
|
1726
1894
|
* (`tracks.album`). `never` when the type advertises nothing includable (so `include` is a
|
|
1727
|
-
* compile error, matching the server's `400 INCLUSION_NOT_ALLOWED`).
|
|
1728
|
-
* relation
|
|
1895
|
+
* compile error, matching the server's `400 INCLUSION_NOT_ALLOWED`). Each path hydrates
|
|
1896
|
+
* every relation it names on the way down, so `tracks.album` types `tracks` and each track's
|
|
1897
|
+
* `album` as hydrated.
|
|
1729
1898
|
*/
|
|
1730
1899
|
type IncludePath<D extends ApiDescriptor, T extends TypeName<D>> = D[T] extends {
|
|
1731
1900
|
includable: infer I;
|
|
@@ -2043,7 +2212,42 @@ interface SingleReadQuery<D extends ApiDescriptor, T extends TypeName<D>, Inc ex
|
|
|
2043
2212
|
* `F` — the resource object with the named relations narrowed to hydrated and its members
|
|
2044
2213
|
* narrowed to the requested sparse fieldset. `Counted` names the relations the read counted.
|
|
2045
2214
|
*/
|
|
2046
|
-
type ReadResult<D extends ApiDescriptor, A, T extends TypeName<D>, Inc extends readonly IncludePath<D, T>[] = [], F = unknown, Counted = never> = ResourceObjectView<D, A, T,
|
|
2215
|
+
type ReadResult<D extends ApiDescriptor, A, T extends TypeName<D>, Inc extends readonly IncludePath<D, T>[] = [], F = unknown, Counted = never> = ResourceObjectView<D, A, T, WideInclude<Inc> extends true ? never : Inc[number], F, Counted>;
|
|
2216
|
+
/**
|
|
2217
|
+
* The plain data of a type `T` resource as a read with include paths `Inc` returns it, without the
|
|
2218
|
+
* `$`-accessors: `type`, `id`, its attributes, and its relations, each one a path names nested as
|
|
2219
|
+
* plain data and the rest as identifiers. A member of a relation carrying `meta.pivot` takes it as
|
|
2220
|
+
* `$pivot`, the key a write ref sends it under. For a mock, a fixture, or another library's input.
|
|
2221
|
+
*
|
|
2222
|
+
* The relations a path names are required; the rest are optional.
|
|
2223
|
+
*/
|
|
2224
|
+
type ResourceDataOf<D extends ApiDescriptor, A, T extends TypeName<D>, Inc = never> = {
|
|
2225
|
+
type: T;
|
|
2226
|
+
id: string;
|
|
2227
|
+
} & AttributesOf<A, T> & { [R in ReadableRelationName<D, T> as R extends IncludeHead<Inc> ? R : never]: RelationData<D, A, T, R, Inc> } & { [R in ReadableRelationName<D, T> as R extends IncludeHead<Inc> ? never : R]?: RelationData<D, A, T, R, Inc> | undefined };
|
|
2228
|
+
/** The plain data of relation `R`: a list of members for a to-many, one or `null` for a to-one. */
|
|
2229
|
+
type RelationData<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, Inc> = IsMany<D, T, R> extends true ? readonly MemberData<D, A, T, R, Inc>[] : MemberData<D, A, T, R, Inc> | null;
|
|
2230
|
+
/** One member of relation `R` as plain data, with its `$pivot` where the relation carries one. */
|
|
2231
|
+
type MemberData<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, Inc> = (R extends IncludeHead<Inc> ? IncludedData<D, A, RelatedType<D, T, R>, IncludeTail<Inc, R>> : ResourceIdentifier<D[T]['relations'][R]['types'][number] & string>) & PivotData<D, A, T, R>;
|
|
2232
|
+
/** Distributes {@link ResourceDataOf} over a polymorphic relation's related types. */
|
|
2233
|
+
type IncludedData<D extends ApiDescriptor, A, U extends TypeName<D>, Inc> = U extends TypeName<D> ? ResourceDataOf<D, A, U, Inc> : never;
|
|
2234
|
+
/** A member's `$pivot`: required where every response renders it, optional elsewhere. */
|
|
2235
|
+
type PivotData<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
2236
|
+
readPivot: unknown;
|
|
2237
|
+
} | {
|
|
2238
|
+
pivotFields: unknown;
|
|
2239
|
+
} ? PivotRendered<D, T, R> extends true ? {
|
|
2240
|
+
readonly $pivot: ReadPivot<D, A, T, R>;
|
|
2241
|
+
} : {
|
|
2242
|
+
readonly $pivot?: ReadPivot<D, A, T, R> | undefined;
|
|
2243
|
+
} : unknown;
|
|
2244
|
+
/**
|
|
2245
|
+
* Whether `Inc` says nothing about which paths a read includes: `any`, `unknown`, or an array
|
|
2246
|
+
* rather than a tuple. `ReturnType` of a generic read reads its result with the include's
|
|
2247
|
+
* constraint and checks it with its default `[]`, so the two must agree, and an include that
|
|
2248
|
+
* names no paths includes none.
|
|
2249
|
+
*/
|
|
2250
|
+
type WideInclude<Inc> = 0 extends 1 & Inc ? true : unknown extends Inc ? true : Inc extends readonly unknown[] ? number extends Inc['length'] ? true : false : true;
|
|
2047
2251
|
/** A `relatedQuery` whose relations and vocabularies the types don't know. */
|
|
2048
2252
|
type LooseRelatedQuery = Readonly<Record<string, {
|
|
2049
2253
|
filter?: Record<string, unknown>;
|
|
@@ -2109,7 +2313,7 @@ type PivotFieldNames<P> = P extends {
|
|
|
2109
2313
|
fields: infer Fl;
|
|
2110
2314
|
} ? keyof Fl : never;
|
|
2111
2315
|
/** The `meta.pivot` object a {@link PivotDescriptor} describes. */
|
|
2112
|
-
type PivotObject<P> = { readonly [K in PivotFieldNames<P> as K extends RequiredPivotField<P> ? K : never]: PivotValue<P, K> } & { readonly [K in PivotFieldNames<P> as K extends RequiredPivotField<P> ? never : K]?: PivotValue<P, K> }
|
|
2316
|
+
type PivotObject<P> = Flatten<{ readonly [K in PivotFieldNames<P> as K extends RequiredPivotField<P> ? K : never]: PivotValue<P, K> } & { readonly [K in PivotFieldNames<P> as K extends RequiredPivotField<P> ? never : K]?: PivotValue<P, K> }>;
|
|
2113
2317
|
/** The value an open {@link PivotDescriptor} takes for each member beside its fields. */
|
|
2114
2318
|
type AdditionalValue<P> = P extends {
|
|
2115
2319
|
additional: infer X;
|
|
@@ -2154,21 +2358,62 @@ type PivotFieldsOf<D extends ApiDescriptor, T extends TypeName<D>, R extends Rel
|
|
|
2154
2358
|
* `identifierMeta` declares, typed like a pivot, with the relation's `pivot` beside them. An
|
|
2155
2359
|
* identifier meta that says whether it is open takes only those, and the undeclared members it
|
|
2156
2360
|
* opens to; one that doesn't say is an open record. A relation declaring none keeps the open
|
|
2157
|
-
* record.
|
|
2361
|
+
* record, with its typed `pivot` where it renders one on every member.
|
|
2158
2362
|
*/
|
|
2159
|
-
type EdgeMetaOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
2363
|
+
type EdgeMetaOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, Pivot = PivotFieldsOf<D, T, R>> = D[T]['relations'][R] extends {
|
|
2160
2364
|
identifierMeta: infer P;
|
|
2161
2365
|
} ? P extends {
|
|
2162
2366
|
additional: false | {
|
|
2163
2367
|
format: unknown;
|
|
2164
2368
|
};
|
|
2165
|
-
} ? PivotObject<P> & EdgePivot<D, T, R> & AdditionalMembers<P,
|
|
2166
|
-
|
|
2167
|
-
|
|
2369
|
+
} ? PivotObject<P> & EdgePivot<D, T, R, Pivot> & AdditionalMembers<P, Pivot> : PivotObject<P> & Record<string, unknown> : D[T]['relations'][R] extends {
|
|
2370
|
+
pivotRendered: true;
|
|
2371
|
+
} ? Record<string, unknown> & EdgePivot<D, T, R, Pivot> : Record<string, unknown>;
|
|
2372
|
+
/**
|
|
2373
|
+
* The `pivot` a pivot relation's identifier meta carries beside its declared members, always
|
|
2374
|
+
* present where the relation renders it on every member.
|
|
2375
|
+
*/
|
|
2376
|
+
type EdgePivot<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, Pivot = PivotFieldsOf<D, T, R>> = D[T]['relations'][R] extends {
|
|
2377
|
+
pivotRendered: true;
|
|
2378
|
+
} ? {
|
|
2379
|
+
readonly pivot: Pivot;
|
|
2380
|
+
} : D[T]['relations'][R] extends {
|
|
2168
2381
|
pivot: true;
|
|
2169
2382
|
} ? {
|
|
2170
|
-
readonly pivot?:
|
|
2383
|
+
readonly pivot?: Pivot;
|
|
2171
2384
|
} : unknown;
|
|
2385
|
+
/** The fields relation `R`'s `writePivot` requires every write to send. */
|
|
2386
|
+
type WriteRequiredPivotField<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
2387
|
+
writePivot: infer W;
|
|
2388
|
+
} ? RequiredPivotField<W> : never;
|
|
2389
|
+
/**
|
|
2390
|
+
* The fields of relation `R`'s read pivot that every response renders but a write needn't send:
|
|
2391
|
+
* the ones only the server sets, such as a timestamp it stamps on attach, and the ones a write
|
|
2392
|
+
* may leave out.
|
|
2393
|
+
*/
|
|
2394
|
+
type UnsentPivotField<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
2395
|
+
readPivot: infer P;
|
|
2396
|
+
} ? Exclude<RequiredPivotField<P>, WriteRequiredPivotField<D, T, R>> : never;
|
|
2397
|
+
/**
|
|
2398
|
+
* The typed `meta.pivot` a pending optimistic member of relation `R` carries. It holds only what
|
|
2399
|
+
* the write sent, so a field is required only where the read renders it and the write pivot
|
|
2400
|
+
* requires it, and every other field is optional. Equal to {@link PivotFieldsOf} where the write
|
|
2401
|
+
* pivot requires every field the read requires.
|
|
2402
|
+
*/
|
|
2403
|
+
type PendingPivotOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
2404
|
+
readPivot: infer P;
|
|
2405
|
+
} ? { readonly [K in PivotFieldNames<P> as K extends UnsentPivotField<D, T, R> ? never : K extends RequiredPivotField<P> ? K : never]: PivotValue<P, K> } & { readonly [K in PivotFieldNames<P> as K extends UnsentPivotField<D, T, R> ? K : K extends RequiredPivotField<P> ? never : K]?: PivotValue<P, K> } & AdditionalMembers<P> : PivotFieldsOf<D, T, R>;
|
|
2406
|
+
/**
|
|
2407
|
+
* The {@link PendingEdge} of the linkage members of relation `R`, where the relation renders its
|
|
2408
|
+
* pivot on every member and requires a field of it that the write pivot doesn't. `never` otherwise:
|
|
2409
|
+
* a pending member then types like a confirmed one.
|
|
2410
|
+
*/
|
|
2411
|
+
type PendingEdgeOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
2412
|
+
pivotRendered: true;
|
|
2413
|
+
} ? [UnsentPivotField<D, T, R>] extends [never] ? never : {
|
|
2414
|
+
readonly pivot: PendingPivotOf<D, T, R>;
|
|
2415
|
+
readonly meta: EdgeMetaOf<D, T, R, PendingPivotOf<D, T, R>>;
|
|
2416
|
+
} : never;
|
|
2172
2417
|
/**
|
|
2173
2418
|
* The typed `meta.pivot` a request may send on each member of relation `R`, from the descriptor's
|
|
2174
2419
|
* `writePivot` (only writable fields, optional unless required). Falls back like
|
|
@@ -2321,14 +2566,15 @@ type DeleteResult<D extends ApiDescriptor, T extends TypeName<D>> = [OperationMe
|
|
|
2321
2566
|
* the hydrated member (or `null`) for to-one. Each member's `$pivot` is typed from the
|
|
2322
2567
|
* relation's `readPivot`.
|
|
2323
2568
|
*/
|
|
2324
|
-
type RelatedValue<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, Q = undefined> = IsMany<D, T, R> extends true ? Collection<Hydrated<D, A, RelatedType<D, T, R>, unknown,
|
|
2569
|
+
type RelatedValue<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, Q = undefined> = IsMany<D, T, R> extends true ? Collection<Hydrated<D, A, RelatedType<D, T, R>, unknown, ReadPivot<D, A, T, R>>, RelationPage<D, T, R, Q>, MetaOrLoose<RelatedMeta<D, T, R>>> : WithDocumentMeta<Hydrated<D, A, RelatedType<D, T, R>, unknown, ReadPivot<D, A, T, R>>, RelatedMeta<D, T, R>> | null;
|
|
2325
2570
|
/**
|
|
2326
2571
|
* A linkage VALUE for relation `R` (the `/relationships/{rel}` endpoint, identifiers only):
|
|
2327
2572
|
* a `Collection` of identifier members for to-many, a single identifier (or `null`) for to-one.
|
|
2328
2573
|
* Each member's `$pivot` is typed from the relation's `readPivot`, and its `$edge.meta` from its
|
|
2329
|
-
* `identifierMeta`.
|
|
2574
|
+
* `identifierMeta`. `Settled` is `true` for linkage no cache layer can hold pending, such as an
|
|
2575
|
+
* atomic result, whose members are typed only as confirmed.
|
|
2330
2576
|
*/
|
|
2331
|
-
type LinkageValue<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, Q = undefined> = IsMany<D, T, R> extends true ? Collection<Identifier<RelatedType<D, T, R>,
|
|
2577
|
+
type LinkageValue<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, Q = undefined, Settled extends boolean = false> = IsMany<D, T, R> extends true ? Collection<Identifier<RelatedType<D, T, R>, ReadPivot<D, A, T, R>, EdgeMetaOf<D, T, R, ReadPivot<D, A, T, R>>, PivotRendered<D, T, R>, Settled extends true ? never : NamedPendingEdge<D, A, T, R>>, RelationPage<D, T, R, Q>> : Identifier<RelatedType<D, T, R>, ReadPivot<D, A, T, R>, EdgeMetaOf<D, T, R, ReadPivot<D, A, T, R>>, PivotRendered<D, T, R>, Settled extends true ? never : NamedPendingEdge<D, A, T, R>> | null;
|
|
2332
2578
|
/**
|
|
2333
2579
|
* The query relation `R`'s relationship read takes, its `sort` and `filter` narrowed to what the
|
|
2334
2580
|
* relation declares and its `page` of type `Pg`. It takes no `relatedQuery`.
|
|
@@ -2354,12 +2600,12 @@ type RelationPageParams<D extends ApiDescriptor, T extends TypeName<D>, R extend
|
|
|
2354
2600
|
* linkage, or `void` when the server replies `204`.
|
|
2355
2601
|
*/
|
|
2356
2602
|
interface RelationshipAccessor<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>> {
|
|
2357
|
-
get: ReadsRelationship<D, T, R> extends true ? <const Pg extends RelationPageParams<D, T, R> | undefined = undefined>(query?: TypedRelationReadQuery<D, T, R, ExactPageParams<Pg, RelationPageParams<D, T, R>>>) => Promise<LinkageValue<D, T, R, Pg>> : never;
|
|
2603
|
+
get: ReadsRelationship<D, T, R> extends true ? <const Pg extends RelationPageParams<D, T, R> | undefined = undefined>(query?: TypedRelationReadQuery<D, T, R, ExactPageParams<Pg, RelationPageParams<D, T, R>>>) => Promise<LinkageValue<D, A, T, R, Pg>> : never;
|
|
2358
2604
|
related: ExposesRelated<D, T, R> extends true ? <const Pg extends RelationPageParams<D, T, R> | undefined = undefined>(query?: TypedRelatedReadQuery<D, T, R, ExactPageParams<Pg, RelationPageParams<D, T, R>>>) => Promise<RelatedValue<D, A, T, R, Pg>> : never;
|
|
2359
|
-
add: RelationMutation<D, T, R, 'add', readonly WriteRef<D, T, R>[]>;
|
|
2360
|
-
remove: RelationMutation<D, T, R, 'remove', readonly LinkageRefOf<RelatedType<D, T, R>>[]>;
|
|
2361
|
-
replace: RelationMutation<D, T, R, 'replace', readonly WriteRef<D, T, R>[]>;
|
|
2362
|
-
set: RelationMutation<D, T, R, 'set', LinkageRefOf<RelatedType<D, T, R>> | null>;
|
|
2605
|
+
add: RelationMutation<D, A, T, R, 'add', readonly WriteRef<D, T, R>[]>;
|
|
2606
|
+
remove: RelationMutation<D, A, T, R, 'remove', readonly LinkageRefOf<RelatedType<D, T, R>>[]>;
|
|
2607
|
+
replace: RelationMutation<D, A, T, R, 'replace', readonly WriteRef<D, T, R>[]>;
|
|
2608
|
+
set: RelationMutation<D, A, T, R, 'set', LinkageRefOf<RelatedType<D, T, R>> | null>;
|
|
2363
2609
|
}
|
|
2364
2610
|
/**
|
|
2365
2611
|
* True when relation `R` of type `T` takes verb `V`: it has the verb's cardinality, a to-one for
|
|
@@ -2429,12 +2675,12 @@ type AdvertisesVerb<D extends ApiDescriptor, T extends TypeName<D>, R extends Re
|
|
|
2429
2675
|
* — or a verb the relation forbids (e.g. a to-many lacking `replace`) — is a compile error.
|
|
2430
2676
|
* The result is the materialised linkage value or `void` (a `204` response).
|
|
2431
2677
|
*/
|
|
2432
|
-
type RelationMutation<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb, Refs> = D[T]['relations'][R]['cardinality'] extends VerbCardinality<V> ? AdvertisesVerb<D, T, R, V> extends true ? (refs: Refs, ...opts: OptionsArg<RequiresRequestMeta<RelationRequestMetaOf<D, T, R, V>>, MetaOption<RelationRequestMetaOf<D, T, R, V>>>) => Promise<MutationResult<D, T, R, V>> : never : never;
|
|
2678
|
+
type RelationMutation<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb, Refs> = D[T]['relations'][R]['cardinality'] extends VerbCardinality<V> ? AdvertisesVerb<D, T, R, V> extends true ? (refs: Refs, ...opts: OptionsArg<RequiresRequestMeta<RelationRequestMetaOf<D, T, R, V>>, MetaOption<RelationRequestMetaOf<D, T, R, V>>>) => Promise<MutationResult<D, A, T, R, V>> : never : never;
|
|
2433
2679
|
/**
|
|
2434
2680
|
* What relation `R`'s write with verb `V` resolves to: the `meta` of the meta-only `200` it
|
|
2435
2681
|
* declares, else the materialised linkage, or `void` for a `204`.
|
|
2436
2682
|
*/
|
|
2437
|
-
type MutationResult<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb> = [MutationMetaOf<D, T, R, V>] extends [never] ? LinkageValue<D, T, R> | void : NonNullable<MutationMetaOf<D, T, R, V>>;
|
|
2683
|
+
type MutationResult<D extends ApiDescriptor, A, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb> = [MutationMetaOf<D, T, R, V>] extends [never] ? LinkageValue<D, A, T, R> | void : NonNullable<MutationMetaOf<D, T, R, V>>;
|
|
2438
2684
|
/** The relationship accessors of type `T`, keyed by relation name. */
|
|
2439
2685
|
type RelationshipAccessors<D extends ApiDescriptor, A, T extends TypeName<D>> = { -readonly [R in keyof D[T]['relations'] as Extract<R, string>]: RelationshipAccessor<D, A, T, Extract<R, string>> };
|
|
2440
2686
|
/**
|
|
@@ -2625,13 +2871,14 @@ type UpdateMethod<D extends ApiDescriptor, A, W, T extends TypeName<D>, I = Upda
|
|
|
2625
2871
|
* `meta`);
|
|
2626
2872
|
* - an {@link AtomicDeleteHandle} -> `undefined` (a remove carries no data);
|
|
2627
2873
|
* - an {@link AtomicRelationshipHandle} for relation `R` of `T` -> the `AtomicResult` wrapping the
|
|
2628
|
-
* linkage the server answered with, as the relationship
|
|
2629
|
-
* `undefined` data when it answered with an empty
|
|
2874
|
+
* linkage the server answered with, typed as the relationship endpoint's (a pivot the relation
|
|
2875
|
+
* renders on every member is present), or `undefined` data when it answered with an empty
|
|
2876
|
+
* result. A result comes straight from the server, so no member of it is pending.
|
|
2630
2877
|
*
|
|
2631
2878
|
* Drives the per-op positional typing of {@link AtomicResults} (the callback's returned tuple of
|
|
2632
2879
|
* handles maps to a tuple of these).
|
|
2633
2880
|
*/
|
|
2634
|
-
type AtomicResultOf<D extends ApiDescriptor, A, Handle> = Handle extends AtomicDeleteHandle ? undefined : Handle extends AtomicRelationshipHandle<infer T, infer R> ? T extends TypeName<D> ? R extends RelationName<D, T> ? AtomicResult<LinkageValue<D, T, R> | undefined> : never : never : Handle extends AtomicCreateHandle<infer T> ? T extends TypeName<D> ? AtomicResult<ResourceObjectView<D, A, T>> : never : Handle extends AtomicUpdateHandle<infer T> ? T extends TypeName<D> ? AtomicResult<ResourceObjectView<D, A, T>> : never : never;
|
|
2881
|
+
type AtomicResultOf<D extends ApiDescriptor, A, Handle> = Handle extends AtomicDeleteHandle ? undefined : Handle extends AtomicRelationshipHandle<infer T, infer R> ? T extends TypeName<D> ? R extends RelationName<D, T> ? AtomicResult<LinkageValue<D, A, T, R, undefined, true> | undefined> : never : never : Handle extends AtomicCreateHandle<infer T> ? T extends TypeName<D> ? AtomicResult<ResourceObjectView<D, A, T>> : never : Handle extends AtomicUpdateHandle<infer T> ? T extends TypeName<D> ? AtomicResult<ResourceObjectView<D, A, T>> : never : never;
|
|
2635
2882
|
/** The custom actions declared on type `T` (the descriptor's `actions` block, or `{}`). */
|
|
2636
2883
|
type ActionsOf<D extends ApiDescriptor, T extends TypeName<D>> = D[T] extends {
|
|
2637
2884
|
actions: infer Acts;
|
|
@@ -3016,9 +3263,10 @@ interface TypeAccessor<D extends ApiDescriptor, A, W, T extends TypeName<D>, Act
|
|
|
3016
3263
|
* generated `WriteAttributes` map (per-type `{ create; update }` attribute pairs) and `Act`
|
|
3017
3264
|
* the generated per-action body-type map; both thread through to the write/action surfaces and
|
|
3018
3265
|
* default so read-only / codegen-less callers compile. `E` is the server's documented
|
|
3019
|
-
* error-code union
|
|
3266
|
+
* error-code union and `O` the codes each operation raises, keyed by operation id, both carried
|
|
3267
|
+
* at the type level only (read them back with `ErrorCodeOf` and `OperationErrorCodeOf`).
|
|
3020
3268
|
*/
|
|
3021
|
-
type Client<D extends ApiDescriptor, A = DefaultAttributes<D>, W = DefaultWriteAttributes<D>, Act = DefaultActionTypes, E extends string = string, L = Record<never, never>> = { -readonly [T in keyof D as Extract<T, string>]: D[T] extends {
|
|
3269
|
+
type Client<D extends ApiDescriptor, A = DefaultAttributes<D>, W = DefaultWriteAttributes<D>, Act = DefaultActionTypes, E extends string = string, L = Record<never, never>, O = Record<never, never>> = { -readonly [T in keyof D as Extract<T, string>]: D[T] extends {
|
|
3022
3270
|
singleton: true;
|
|
3023
3271
|
} ? SingletonAccessor<D, WithLinks<A, L>, W, Extract<T, string>, Act> : TypeAccessor<D, WithLinks<A, L>, W, Extract<T, string>, Act> } & {
|
|
3024
3272
|
/**
|
|
@@ -3039,12 +3287,42 @@ type Client<D extends ApiDescriptor, A = DefaultAttributes<D>, W = DefaultWriteA
|
|
|
3039
3287
|
*/
|
|
3040
3288
|
atomic<const Ops>(build: (tx: AtomicRecorder<D, W>) => Ops): Promise<Ops extends readonly AtomicHandle[] ? AtomicResults<D, WithLinks<A, L>, Ops> : AtomicResult[]>;
|
|
3041
3289
|
readonly [errorCodes]?: E;
|
|
3290
|
+
readonly '~errorCodesByOperation'?: O;
|
|
3291
|
+
readonly '~types'?: ClientTypes<D, WithLinks<A, L>, W>;
|
|
3042
3292
|
};
|
|
3293
|
+
/**
|
|
3294
|
+
* The type arguments a client was built with, which bindings such as json-api-query read off its
|
|
3295
|
+
* type-only `~types` member instead of matching every method's signature. Never set at runtime.
|
|
3296
|
+
*/
|
|
3297
|
+
interface ClientTypes<D extends ApiDescriptor = ApiDescriptor, A = unknown, W = unknown> {
|
|
3298
|
+
readonly descriptor: D;
|
|
3299
|
+
/** The read-types map its results are typed by: attributes, declared links and named pivots. */
|
|
3300
|
+
readonly read: A;
|
|
3301
|
+
/** The write attributes its creates and updates take. */
|
|
3302
|
+
readonly write: W;
|
|
3303
|
+
}
|
|
3043
3304
|
declare const errorCodes: unique symbol;
|
|
3305
|
+
/**
|
|
3306
|
+
* The type-only members a client carries its error codes in: `E`, every documented code, and
|
|
3307
|
+
* `O`, the codes each operation raises. Intersect it into a type that stands in for a client.
|
|
3308
|
+
*/
|
|
3309
|
+
interface ErrorCodeCarrier<E extends string = string, O = Record<never, never>> {
|
|
3310
|
+
readonly [errorCodes]?: E;
|
|
3311
|
+
readonly '~errorCodesByOperation'?: O;
|
|
3312
|
+
}
|
|
3044
3313
|
/** The error-code union a client type carries, or `string` for one that carries none. */
|
|
3045
3314
|
type ErrorCodeOf<T> = T extends {
|
|
3046
3315
|
readonly [errorCodes]?: infer C extends string;
|
|
3047
3316
|
} ? C : string;
|
|
3317
|
+
/**
|
|
3318
|
+
* The codes operation `Op` raises on a client type, such as `'create.albums'`. Every code the
|
|
3319
|
+
* client carries when it lists none for `Op`.
|
|
3320
|
+
*/
|
|
3321
|
+
type OperationErrorCodeOf<T, Op extends string> = T extends {
|
|
3322
|
+
readonly '~errorCodesByOperation'?: infer O;
|
|
3323
|
+
} ? OperationCodes<ErrorCodeOf<T>, O, Op> : ErrorCodeOf<T>;
|
|
3324
|
+
/** The codes operation `Op` raises per `O`, a generated `ErrorCodeByOperation`, else `C`. */
|
|
3325
|
+
type OperationCodes<C extends string, O, Op extends string> = Op extends keyof O ? Extract<O[Op], string> : C;
|
|
3048
3326
|
/**
|
|
3049
3327
|
* The fallback attribute map when a caller doesn't supply the generated `Attributes`
|
|
3050
3328
|
* (direct `createClient` users without codegen): every type's attributes are an open
|
|
@@ -3146,6 +3424,12 @@ interface ClientOptions {
|
|
|
3146
3424
|
* validation engine (e.g. ajv) is brought by the caller; the client never depends on one.
|
|
3147
3425
|
*/
|
|
3148
3426
|
validate?: ValidationOption;
|
|
3427
|
+
/**
|
|
3428
|
+
* Schemas to check each create's and update's input against before sending it, by wire type.
|
|
3429
|
+
* An input that fails rejects with an {@link InputValidationError} and sends nothing. Pass the
|
|
3430
|
+
* `inputSchemas` that `json-api-codegen --zod` generates, or your own Standard Schemas.
|
|
3431
|
+
*/
|
|
3432
|
+
validateInput?: InputSchemas;
|
|
3149
3433
|
}
|
|
3150
3434
|
/**
|
|
3151
3435
|
* The reserved members on a {@link ResourceHandle} — names the Proxy resolves itself, so a
|
|
@@ -3162,7 +3446,7 @@ declare const HANDLE_RESERVED: ReadonlySet<string>;
|
|
|
3162
3446
|
* (`$next()`/`$prev()`, related links) is wired through `materialise`'s `navigate` seam,
|
|
3163
3447
|
* which resolves the server's link against `baseUrl`, executes it and re-materialises.
|
|
3164
3448
|
*/
|
|
3165
|
-
declare function createClient<D extends ApiDescriptor, A = DefaultAttributes<D>, W = DefaultWriteAttributes<D>, Act = DefaultActionTypes, E extends string = string, L = Record<never, never>>(descriptor: D, options: ClientOptions): Client<D, A, W, Act, E, L>;
|
|
3449
|
+
declare function createClient<D extends ApiDescriptor, A = DefaultAttributes<D>, W = DefaultWriteAttributes<D>, Act = DefaultActionTypes, E extends string = string, L = Record<never, never>, O = Record<never, never>>(descriptor: D, options: ClientOptions): Client<D, A, W, Act, E, L, O>;
|
|
3166
3450
|
//#endregion
|
|
3167
3451
|
//#region src/request.d.ts
|
|
3168
3452
|
/**
|
|
@@ -3401,5 +3685,5 @@ declare function assertJsonApiDocument(body: unknown): asserts body is Document;
|
|
|
3401
3685
|
*/
|
|
3402
3686
|
declare function validateDocument(body: Document, validator: ResolvedValidator, fields?: Readonly<Record<string, readonly string[]>>): void;
|
|
3403
3687
|
//#endregion
|
|
3404
|
-
export {
|
|
3405
|
-
//# sourceMappingURL=validate-
|
|
3688
|
+
export { DeleteArgs as $, AtomicResults as $n, PageParams as $r, RelationPageParams as $t, TransportResponse as A, MediaExamples as Ai, WaitOptions as An, isMaterialised as Ar, OperationCodes as At, Client as B, RawOutputMedia as Bi, isActionLocation as Bn, LocalIdentifier as Br, ReadResult as Bt, ClientOptions as C, ClientIdPolicy as Ci, TypeAccessor as Cn, PendingPlacement as Cr, MemberName as Ct, JsonApiTransport as D, FilterFamilyDescriptor as Di, TypedRelationReadQuery as Dn, ResourceLinks as Dr, MutationMetaOf as Dt, createClient as E, DocumentMetaOperation as Ei, TypedRelatedReadQuery as En, ResourceEnvelope as Er, MetaOption as Et, ActionCallOptions as F, PaginatorKind as Fi, WritableRelationName as Fn, relationWritten as Fr, PendingEdgeMethods as Ft, CountToken as G, RequestMetaOperation as Gi, AtomicHandle as Gn, nestedFieldset as Gr, RelatedQuery as Gt, Collection as H, RelatedQueryOperation as Hi, AtomicCreateHandle as Hn, ResourceIdentifier as Hr, RelatedIncludedResource as Ht, ActionsAccessor as I, PaginatorRole as Ii, WriteOptions as In, setMaterialisedOverlay as Ir, PendingPivotOf as It, CreateInput as J, ResourceExamples as Ji, AtomicRef as Jn, Page as Jr, RelatedQueryRelation as Jt, CountedRelationName as K, ResourceCountOperation as Ki, AtomicOperationArgs as Kn, CANONICAL_PAGE_KEYS as Kr, RelatedQueryEntry as Kt, AtomicResultOf as L, PaginatorStrategy as Li, WritePivotOf as Ln, ATOMIC_EXT as Lr, PivotFieldsOf as Lt, AcceptedJob as M, MetaLiteral as Mi, WaitedWriteResult as Mn, materialise as Mr, OperationMeta as Mt, AcceptedMeta as N, OperationExamples as Ni, WithDocumentMeta as Nn, relatedPaginator as Nr, OptionsArg as Nt, TransportRawBody as O, InputMedia as Oi, UpdateInput as On, edgeViewOf as Or, MutationVerb as Ot, AcceptedOf as P, PaginatorDescriptor as Pi, WithLinks as Pn, relatedPaginatorKind as Pr, PendingEdge as Pt, DefaultWriteAttributes as Q, isPolymorphic as Qi, AtomicResult as Qn, PageOf as Qr, RelationName as Qt, BinaryBody as R, PivotDescriptor as Ri, WriteResult as Rn, ATOMIC_MEDIA_TYPE as Rr, PivotInput as Rt, serializeQuery as S, Cardinality as Si, TakesVerb as Sn, PendingMember as Sr, LooseRelatedQueryEntry as St, HeadersInit as T, DocumentMetaDescriptor as Ti, TypedReadQuery as Tn, RelationView as Tr, MetaObject as Tt, CollectionMeta as U, RelationDescriptor as Ui, AtomicCreateInput as Un, mediaType as Ur, RelatedIncludedType as Ut, ClientTypes as V, RelatedQueryDescriptor as Vi, readActionLocation as Vn, MediaTypeParams as Vr, ReadableRelationName as Vt, CountAccessor as W, RelationMutations as Wi, AtomicDeleteHandle as Wn, NestedFieldset as Wr, RelatedMeta as Wt, DefaultActionTypes as X, SortFamilyDescriptor as Xi, AtomicRelationshipHandle as Xn, PageLinks as Xr, RelationCollection as Xt, CreateMethod as Y, ResourceMetaDescriptor as Yi, AtomicRelationshipArgs as Yn, PageKeys as Yr, RelatedReadRelatedQuery as Yt, DefaultAttributes as Z, StrategyDescriptor as Zi, AtomicRelationshipRecorder as Zn, PageMeta as Zr, RelationFilterQuery as Zt, RawResponseType as _, ActionScope as _i, SingleReadQuery as _n, LinkObject as _r, LinkageRef as _t, ValidationOption as a, resolvePaginator as ai, RelationshipMembers as an, InputValidationError as ar, ErrorCodeOf as at, executeRaw as b, ApiExamples as bi, SortQuery as bn, NavigateOptions as br, ListPageParams as bt, assertJsonApiDocument as c, PollTimeoutError as ci, ResourceAccessors as cn, StandardSchemaResult as cr, FilterKey as ct, sparseSchemas as d, AcceptedDescriptor as di, ResourceHandle as dn, ArrayEnvelope as dr, IdentifierMember as dt, PageParamsOf as ei, RelationPaginator as en, AtomicUpdateHandle as er, DeleteResult as et, validateDocument as f, AcceptedOperation as fi, ResourceMetaOf as fn, DocumentEnvelope as fr, IncludePath as ft, JsonApiRequest as g, ActionOutput as gi, ResourceWriteOperation as gn, Link as gr, IsSingleton as gt, JsonApiContext as h, ActionLocationDescriptor as hi, ResourceWriteMeta as hn, EdgeMember as hr, IncludedType as ht, ValidationContext as i, prevPageParams as ii, RelationshipAccessor as in, InputSchemas as ir, ErrorCodeCarrier as it, fetchTransport as j, MenuDescriptor as ji, WaitValue as jn, lateRelationsOf as jr, OperationErrorCodeOf as jt, TransportRequest as k, InputMediaKind as ki, UpdateMethod as kn, identifierViewOf as kr, NestedFieldsetMember as kt, resolveValidator as l, isAccepted as li, ResourceCountToken as ln, inputFailure as lr, FilterQuery as lt, ExecutedResponse as m, ActionInput as mi, ResourceObjectView as mn, EdgeEnvelope as mr, IncludedResource as mt, SchemaMap as n, TypedPage as ni, RelationRequestMetaOf as nn, runAtomic as nr, EdgeMembers as nt, Validator as o, Accepted as oi, RequestMetaOf as on, StandardSchema as or, FieldSelectionMap as ot, Document as p, ActionDescriptor as pi, ResourceMethods as pn, Edge as pr, IncludedRelations as pt, CreateAttributesOf as q, ResourceDescriptor as qi, AtomicRecorder as qn, ExactPageParams as qr, RelatedQueryParam as qt, ValidationConfig as r, nextPageParams as ri, RelationSortQuery as rn, InputCheck as rr, EdgeMethods as rt, WireResource as s, PollOptions as si, RequiresRequestMeta as sn, StandardSchemaIssue as sr, FieldsMap as st, ResolvedValidator as t, ResolvedPaginator as ti, RelationReadQuery as tn, AtomicUpdateInput as tr, DocumentMeta as tt, sparseSchema as u, parseRetryAfter as ui, ResourceDataOf as un, withInputCheck as ur, HydratedMember as ut, ReadQuery as v, AdditionalMembersDescriptor as vi, SingletonAccessor as vn, MaterialiseContext as vr, ListFilterMember as vt, HANDLE_RESERVED as w, CountableDescriptor as wi, TypeName as wn, RelationArrayEnvelope as wr, MemberTypeOf as wt, executeResponse as x, AtomicDescriptor as xi, SortToken as xn, PendingCreate as xr, LooseRelatedQuery as xt, execute as y, ApiDescriptor as yi, SingletonUpdateInput as yn, MaterialisedOverlay as yr, ListMethods as yt, BinaryResponseType as z, RawMediaKind as zi, ActionLocation as zn, JSON_API_MEDIA_TYPE as zr, ReadAttributesOf as zt };
|
|
3689
|
+
//# sourceMappingURL=validate-DyNfTJ52.d.mts.map
|