@haverstack/core 0.41.0 → 0.43.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/README.md +124 -64
- package/dist/access.d.ts +43 -47
- package/dist/access.d.ts.map +1 -1
- package/dist/access.js +66 -101
- package/dist/access.js.map +1 -1
- package/dist/{combine.d.ts → adapter/combine.d.ts} +8 -1
- package/dist/adapter/combine.d.ts.map +1 -0
- package/dist/{combine.js → adapter/combine.js} +18 -3
- package/dist/adapter/combine.js.map +1 -0
- package/dist/adapter/index.d.ts +19 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/index.js +16 -0
- package/dist/adapter/index.js.map +1 -0
- package/dist/adapter/reach.d.ts +14 -0
- package/dist/adapter/reach.d.ts.map +1 -0
- package/dist/adapter/reach.js +31 -0
- package/dist/adapter/reach.js.map +1 -0
- package/dist/{sort.d.ts → adapter/sort.d.ts} +20 -20
- package/dist/adapter/sort.d.ts.map +1 -0
- package/dist/{sort.js → adapter/sort.js} +37 -27
- package/dist/adapter/sort.js.map +1 -0
- package/dist/associations/identity.d.ts +69 -0
- package/dist/associations/identity.d.ts.map +1 -0
- package/dist/associations/identity.js +174 -0
- package/dist/associations/identity.js.map +1 -0
- package/dist/associations/validation.d.ts +83 -0
- package/dist/associations/validation.d.ts.map +1 -0
- package/dist/associations/validation.js +312 -0
- package/dist/associations/validation.js.map +1 -0
- package/dist/attachment-records.d.ts +48 -0
- package/dist/attachment-records.d.ts.map +1 -0
- package/dist/attachment-records.js +52 -0
- package/dist/attachment-records.js.map +1 -0
- package/dist/collection.d.ts +178 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/collection.js +397 -0
- package/dist/collection.js.map +1 -0
- package/dist/content-match.d.ts +25 -0
- package/dist/content-match.d.ts.map +1 -0
- package/dist/content-match.js +51 -0
- package/dist/content-match.js.map +1 -0
- package/dist/content-translation.d.ts +42 -0
- package/dist/content-translation.d.ts.map +1 -0
- package/dist/content-translation.js +108 -0
- package/dist/content-translation.js.map +1 -0
- package/dist/did/did.d.ts.map +1 -0
- package/dist/{did.js → did/did.js} +3 -4
- package/dist/did/did.js.map +1 -0
- package/dist/{did-entry.d.ts → did/index.d.ts} +1 -1
- package/dist/did/index.d.ts.map +1 -0
- package/dist/{did-entry.js → did/index.js} +3 -3
- package/dist/did/index.js.map +1 -0
- package/dist/errors.d.ts +54 -66
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +58 -62
- package/dist/errors.js.map +1 -1
- package/dist/grants.d.ts +20 -44
- package/dist/grants.d.ts.map +1 -1
- package/dist/grants.js +69 -151
- package/dist/grants.js.map +1 -1
- package/dist/id.d.ts +13 -31
- package/dist/id.d.ts.map +1 -1
- package/dist/id.js +13 -31
- package/dist/id.js.map +1 -1
- package/dist/index.d.ts +13 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +3 -6
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +6 -10
- package/dist/install.js.map +1 -1
- package/dist/lazy.d.ts +13 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js +27 -0
- package/dist/lazy.js.map +1 -0
- package/dist/merge.d.ts +1 -1
- package/dist/merge.d.ts.map +1 -1
- package/dist/merge.js +6 -12
- package/dist/merge.js.map +1 -1
- package/dist/migration-steps.d.ts +102 -0
- package/dist/migration-steps.d.ts.map +1 -0
- package/dist/migration-steps.js +293 -0
- package/dist/migration-steps.js.map +1 -0
- package/dist/query-validation.d.ts +68 -121
- package/dist/query-validation.d.ts.map +1 -1
- package/dist/query-validation.js +214 -380
- package/dist/query-validation.js.map +1 -1
- package/dist/record-changes.d.ts +11 -150
- package/dist/record-changes.d.ts.map +1 -1
- package/dist/record-changes.js +14 -305
- package/dist/record-changes.js.map +1 -1
- package/dist/schema.d.ts +18 -7
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +59 -30
- package/dist/schema.js.map +1 -1
- package/dist/scoped-stack/authority-snapshot.d.ts +37 -0
- package/dist/scoped-stack/authority-snapshot.d.ts.map +1 -0
- package/dist/scoped-stack/authority-snapshot.js +49 -0
- package/dist/scoped-stack/authority-snapshot.js.map +1 -0
- package/dist/scoped-stack/authority.d.ts +169 -0
- package/dist/scoped-stack/authority.d.ts.map +1 -0
- package/dist/scoped-stack/authority.js +408 -0
- package/dist/scoped-stack/authority.js.map +1 -0
- package/dist/scoped-stack/family-policy.d.ts +59 -0
- package/dist/scoped-stack/family-policy.d.ts.map +1 -0
- package/dist/scoped-stack/family-policy.js +68 -0
- package/dist/scoped-stack/family-policy.js.map +1 -0
- package/dist/scoped-stack/scoped-stack.d.ts +318 -0
- package/dist/scoped-stack/scoped-stack.d.ts.map +1 -0
- package/dist/scoped-stack/scoped-stack.js +695 -0
- package/dist/scoped-stack/scoped-stack.js.map +1 -0
- package/dist/scoped-stack/subscription.d.ts +36 -0
- package/dist/scoped-stack/subscription.d.ts.map +1 -0
- package/dist/scoped-stack/subscription.js +69 -0
- package/dist/scoped-stack/subscription.js.map +1 -0
- package/dist/stack/arguments.d.ts +27 -0
- package/dist/stack/arguments.d.ts.map +1 -0
- package/dist/stack/arguments.js +53 -0
- package/dist/stack/arguments.js.map +1 -0
- package/dist/stack/attachments.d.ts +24 -0
- package/dist/stack/attachments.d.ts.map +1 -0
- package/dist/stack/attachments.js +113 -0
- package/dist/stack/attachments.js.map +1 -0
- package/dist/{changes.d.ts → stack/changes.d.ts} +30 -72
- package/dist/stack/changes.d.ts.map +1 -0
- package/dist/{changes.js → stack/changes.js} +40 -74
- package/dist/stack/changes.js.map +1 -0
- package/dist/stack/client.d.ts +247 -0
- package/dist/stack/client.d.ts.map +1 -0
- package/dist/stack/client.js +9 -0
- package/dist/stack/client.js.map +1 -0
- package/dist/stack/identity-bindings.d.ts.map +1 -0
- package/dist/{identity-bindings.js → stack/identity-bindings.js} +5 -14
- package/dist/stack/identity-bindings.js.map +1 -0
- package/dist/stack/install-app.d.ts +22 -0
- package/dist/stack/install-app.d.ts.map +1 -0
- package/dist/stack/install-app.js +262 -0
- package/dist/stack/install-app.js.map +1 -0
- package/dist/stack/integrity.d.ts +94 -0
- package/dist/stack/integrity.d.ts.map +1 -0
- package/dist/stack/integrity.js +268 -0
- package/dist/stack/integrity.js.map +1 -0
- package/dist/{limits.d.ts → stack/limits.d.ts} +2 -5
- package/dist/stack/limits.d.ts.map +1 -0
- package/dist/{limits.js → stack/limits.js} +3 -6
- package/dist/stack/limits.js.map +1 -0
- package/dist/stack/migrations.d.ts +59 -0
- package/dist/stack/migrations.d.ts.map +1 -0
- package/dist/stack/migrations.js +141 -0
- package/dist/stack/migrations.js.map +1 -0
- package/dist/stack/reads.d.ts +69 -0
- package/dist/stack/reads.d.ts.map +1 -0
- package/dist/stack/reads.js +141 -0
- package/dist/stack/reads.js.map +1 -0
- package/dist/stack/record-id.d.ts +35 -0
- package/dist/stack/record-id.d.ts.map +1 -0
- package/dist/stack/record-id.js +82 -0
- package/dist/stack/record-id.js.map +1 -0
- package/dist/stack/stack.d.ts +444 -0
- package/dist/stack/stack.d.ts.map +1 -0
- package/dist/stack/stack.js +1339 -0
- package/dist/stack/stack.js.map +1 -0
- package/dist/stack/system-types.d.ts +16 -0
- package/dist/stack/system-types.d.ts.map +1 -0
- package/dist/stack/system-types.js +111 -0
- package/dist/stack/system-types.js.map +1 -0
- package/dist/stack/type-grants.d.ts +20 -0
- package/dist/stack/type-grants.d.ts.map +1 -0
- package/dist/stack/type-grants.js +69 -0
- package/dist/stack/type-grants.js.map +1 -0
- package/dist/stack/write-expectation.d.ts +79 -0
- package/dist/stack/write-expectation.d.ts.map +1 -0
- package/dist/stack/write-expectation.js +71 -0
- package/dist/stack/write-expectation.js.map +1 -0
- package/dist/stack/write-gate.d.ts +23 -0
- package/dist/stack/write-gate.d.ts.map +1 -0
- package/dist/stack/write-gate.js +17 -0
- package/dist/stack/write-gate.js.map +1 -0
- package/dist/testing.d.ts +44 -33
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +180 -176
- package/dist/testing.js.map +1 -1
- package/dist/type-handle.d.ts +67 -78
- package/dist/type-handle.d.ts.map +1 -1
- package/dist/type-handle.js +44 -111
- package/dist/type-handle.js.map +1 -1
- package/dist/types/adapter.d.ts +282 -0
- package/dist/types/adapter.d.ts.map +1 -0
- package/dist/types/adapter.js +5 -0
- package/dist/types/adapter.js.map +1 -0
- package/dist/types/associations.d.ts +140 -0
- package/dist/types/associations.d.ts.map +1 -0
- package/dist/types/associations.js +6 -0
- package/dist/types/associations.js.map +1 -0
- package/dist/types/capabilities.d.ts +89 -0
- package/dist/types/capabilities.d.ts.map +1 -0
- package/dist/types/capabilities.js +5 -0
- package/dist/types/capabilities.js.map +1 -0
- package/dist/types/events.d.ts +150 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +5 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/ids.d.ts +43 -0
- package/dist/types/ids.d.ts.map +1 -0
- package/dist/types/ids.js +5 -0
- package/dist/types/ids.js.map +1 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/journal.d.ts +47 -0
- package/dist/types/journal.d.ts.map +1 -0
- package/dist/types/journal.js +5 -0
- package/dist/types/journal.js.map +1 -0
- package/dist/types/query.d.ts +185 -0
- package/dist/types/query.d.ts.map +1 -0
- package/dist/types/query.js +10 -0
- package/dist/types/query.js.map +1 -0
- package/dist/types/records.d.ts +76 -0
- package/dist/types/records.d.ts.map +1 -0
- package/dist/types/records.js +5 -0
- package/dist/types/records.js.map +1 -0
- package/dist/types/schema.d.ts +74 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +5 -0
- package/dist/types/schema.js.map +1 -0
- package/dist/types/system.d.ts +161 -0
- package/dist/types/system.d.ts.map +1 -0
- package/dist/types/system.js +32 -0
- package/dist/types/system.js.map +1 -0
- package/dist/types/tokens.d.ts +39 -0
- package/dist/types/tokens.d.ts.map +1 -0
- package/dist/types/tokens.js +5 -0
- package/dist/types/tokens.js.map +1 -0
- package/dist/validate.d.ts +31 -70
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +52 -92
- package/dist/validate.js.map +1 -1
- package/dist/{attachment-download.d.ts → wire/attachment-download.d.ts} +0 -57
- package/dist/wire/attachment-download.d.ts.map +1 -0
- package/dist/{attachment-download.js → wire/attachment-download.js} +0 -61
- package/dist/wire/attachment-download.js.map +1 -0
- package/dist/{auth.d.ts → wire/auth.d.ts} +5 -8
- package/dist/wire/auth.d.ts.map +1 -0
- package/dist/{auth.js → wire/auth.js} +5 -8
- package/dist/wire/auth.js.map +1 -0
- package/dist/{wire-body.d.ts → wire/body.d.ts} +35 -12
- package/dist/wire/body.d.ts.map +1 -0
- package/dist/{wire-body.js → wire/body.js} +74 -13
- package/dist/wire/body.js.map +1 -0
- package/dist/{wire-entry.d.ts → wire/index.d.ts} +12 -12
- package/dist/wire/index.d.ts.map +1 -0
- package/dist/{wire-entry.js → wire/index.js} +13 -17
- package/dist/wire/index.js.map +1 -0
- package/dist/wire/record.d.ts +31 -0
- package/dist/wire/record.d.ts.map +1 -0
- package/dist/{wire-record.js → wire/record.js} +7 -67
- package/dist/wire/record.js.map +1 -0
- package/dist/{wire-request.d.ts → wire/request.d.ts} +32 -49
- package/dist/wire/request.d.ts.map +1 -0
- package/dist/{wire-request.js → wire/request.js} +113 -83
- package/dist/wire/request.js.map +1 -0
- package/package.json +7 -7
- package/dist/adapter-entry.d.ts +0 -16
- package/dist/adapter-entry.d.ts.map +0 -1
- package/dist/adapter-entry.js +0 -14
- package/dist/adapter-entry.js.map +0 -1
- package/dist/attachment-download.d.ts.map +0 -1
- package/dist/attachment-download.js.map +0 -1
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js.map +0 -1
- package/dist/changes.d.ts.map +0 -1
- package/dist/changes.js.map +0 -1
- package/dist/combine.d.ts.map +0 -1
- package/dist/combine.js.map +0 -1
- package/dist/did-entry.d.ts.map +0 -1
- package/dist/did-entry.js.map +0 -1
- package/dist/did.d.ts.map +0 -1
- package/dist/did.js.map +0 -1
- package/dist/identity-bindings.d.ts.map +0 -1
- package/dist/identity-bindings.js.map +0 -1
- package/dist/limits.d.ts.map +0 -1
- package/dist/limits.js.map +0 -1
- package/dist/record-id.d.ts +0 -70
- package/dist/record-id.d.ts.map +0 -1
- package/dist/record-id.js +0 -127
- package/dist/record-id.js.map +0 -1
- package/dist/scoped-stack.d.ts +0 -549
- package/dist/scoped-stack.d.ts.map +0 -1
- package/dist/scoped-stack.js +0 -1301
- package/dist/scoped-stack.js.map +0 -1
- package/dist/sort.d.ts.map +0 -1
- package/dist/sort.js.map +0 -1
- package/dist/stack-reads.d.ts +0 -38
- package/dist/stack-reads.d.ts.map +0 -1
- package/dist/stack-reads.js +0 -79
- package/dist/stack-reads.js.map +0 -1
- package/dist/stack.d.ts +0 -1032
- package/dist/stack.d.ts.map +0 -1
- package/dist/stack.js +0 -2337
- package/dist/stack.js.map +0 -1
- package/dist/types.d.ts +0 -1278
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -51
- package/dist/types.js.map +0 -1
- package/dist/wire-body.d.ts.map +0 -1
- package/dist/wire-body.js.map +0 -1
- package/dist/wire-entry.d.ts.map +0 -1
- package/dist/wire-entry.js.map +0 -1
- package/dist/wire-record.d.ts +0 -50
- package/dist/wire-record.d.ts.map +0 -1
- package/dist/wire-record.js.map +0 -1
- package/dist/wire-request.d.ts.map +0 -1
- package/dist/wire-request.js.map +0 -1
- /package/dist/{did.d.ts → did/did.d.ts} +0 -0
- /package/dist/{identity-bindings.d.ts → stack/identity-bindings.d.ts} +0 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collections — typed access to one type family
|
|
3
|
+
* -------------------------------------------------------
|
|
4
|
+
* `client.collection(handle)` returns a `Collection<C>`: every verb that
|
|
5
|
+
* addresses records of the handle's family, each taking and returning the
|
|
6
|
+
* handle's content type with one signature. Implemented once over the
|
|
7
|
+
* public `StackClient` verbs, so `Stack` and `ScopedStack` share it and a
|
|
8
|
+
* collection can do nothing its client could not.
|
|
9
|
+
*
|
|
10
|
+
* The collection's scope is the handle's whole family. Each record is read
|
|
11
|
+
* as stored and migrated in memory to the handle's version, one at a time,
|
|
12
|
+
* so a record the handle cannot represent — one stored at a newer version —
|
|
13
|
+
* is reported as a misfit rather than failing the page it sits on. A
|
|
14
|
+
* content write to a record at an older version commits its migration as a
|
|
15
|
+
* write of its own first. See docs/spec/data-model.md § Type handles.
|
|
16
|
+
*/
|
|
17
|
+
import type { MigrationRegistry } from './stack/migrations.js';
|
|
18
|
+
import type { CreateRecordOptions, DeleteRecordOptions, DeleteResult, StackClient } from './stack/client.js';
|
|
19
|
+
import type { ContentOf, ReadonlyTypeSchema, TypeHandle, UnlistedValue } from './type-handle.js';
|
|
20
|
+
import type { AssociationEdit, AuthorityAssociation, ChangeFilter, DataAssociation, IfVersionOptions, NativeSortField, RecordChange, RecordFilter, RecordId, StackQuery, StackType, StackRecord, SubscribeOptions, Unsubscribe } from './types/index.js';
|
|
21
|
+
/**
|
|
22
|
+
* Content `C` as a read returns it: an enum may hold a value the handle
|
|
23
|
+
* does not list, since an enum can widen in place. Never flattens `C`, so
|
|
24
|
+
* an app that names its content with an `interface` keeps that name.
|
|
25
|
+
*/
|
|
26
|
+
export type StoredContent<C> = C extends string ? string extends C ? C : C | UnlistedValue : C extends readonly (infer I)[] ? StoredContent<I>[] : C extends object ? {
|
|
27
|
+
[K in keyof C]: StoredContent<C[K]>;
|
|
28
|
+
} : C;
|
|
29
|
+
/**
|
|
30
|
+
* The `contentPatch` content `C` accepts: every field optional, and `null`
|
|
31
|
+
* (removal) only on a field that is optional in `C`.
|
|
32
|
+
*/
|
|
33
|
+
export type ContentPatch<C> = {
|
|
34
|
+
[K in keyof C]?: Pick<C, K> extends Required<Pick<C, K>> ? C[K] : Exclude<C[K], undefined> | null;
|
|
35
|
+
};
|
|
36
|
+
/** A record of the collection, migrated to the handle's version. */
|
|
37
|
+
export interface CollectionRecord<C> extends Omit<StackRecord, 'content'> {
|
|
38
|
+
content: StoredContent<C>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A record in the handle's family that the handle cannot represent. Stored
|
|
42
|
+
* at a version newer than the handle's, it cannot be migrated down.
|
|
43
|
+
*/
|
|
44
|
+
export type Misfit = {
|
|
45
|
+
id: RecordId;
|
|
46
|
+
reason: 'newer-version';
|
|
47
|
+
/** Untyped, as stored. */
|
|
48
|
+
record: StackRecord;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* A page of a collection. Misfits do not count as records, so a page can
|
|
52
|
+
* hold fewer than `limit` records with a cursor still set: the results end
|
|
53
|
+
* when `cursor` is `null`, not when a page comes back short.
|
|
54
|
+
*/
|
|
55
|
+
export type CollectionPage<C> = {
|
|
56
|
+
records: CollectionRecord<C>[];
|
|
57
|
+
misfits: Misfit[];
|
|
58
|
+
cursor: string | null;
|
|
59
|
+
/**
|
|
60
|
+
* Set when records at a version a content filter or sort could not reach
|
|
61
|
+
* match, or may match, the rest of the query. On the first page only,
|
|
62
|
+
* since it depends on the query rather than the page. See
|
|
63
|
+
* docs/spec/data-model.md § Content queries across versions.
|
|
64
|
+
*/
|
|
65
|
+
skipped?: {
|
|
66
|
+
older: boolean;
|
|
67
|
+
newer: boolean;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Path typing stops at this depth and accepts any suffix below it, since a
|
|
72
|
+
* recursive path type otherwise exceeds the compiler's instantiation limit.
|
|
73
|
+
* A typing limit, not a query limit: see docs/spec/data-model.md § Nested
|
|
74
|
+
* content paths.
|
|
75
|
+
*/
|
|
76
|
+
type PathDepth = [never, 0, 1, 2, 3, 4];
|
|
77
|
+
/** What a filter value can equal: an adapter compares the value a path reaches. */
|
|
78
|
+
type Leaf = string | number | boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Each content path of `V` reached at `P`, paired with the value a filter
|
|
81
|
+
* compares there. An array is matched element-wise, so it is its element.
|
|
82
|
+
* An object never equals a filter value, so its path takes only `null`.
|
|
83
|
+
*/
|
|
84
|
+
type PathEntry<P extends string, V, D extends number> = [D] extends [never] ? [P | `${P}.${string}`, Leaf] : V extends readonly (infer E)[] ? unknown extends E ? [P | `${P}.${string}`, Leaf] : PathEntry<P, E, PathDepth[D]> : V extends object ? string extends keyof V ? [P, null] | [`${P}.${string}`, Leaf] : [P, null] | FieldEntry<V, `${P}.`, PathDepth[D]> : [P, V];
|
|
85
|
+
/** `Required<C>[K]` rather than `NonNullable`, which would leak into errors. */
|
|
86
|
+
type FieldEntry<C, Prefix extends string, D extends number> = [D] extends [never] ? [`${Prefix}${string}`, Leaf] : {
|
|
87
|
+
[K in keyof C & string]-?: PathEntry<`${Prefix}${K}`, Required<C>[K], D>;
|
|
88
|
+
}[keyof C & string];
|
|
89
|
+
/**
|
|
90
|
+
* Every content path of `C`: its fields, and dotted paths through declared
|
|
91
|
+
* objects and arrays. Below an `open` object or array, or six segments
|
|
92
|
+
* deep, any suffix is a path.
|
|
93
|
+
*/
|
|
94
|
+
export type ContentPathOf<C> = FieldEntry<C, '', 5>[0];
|
|
95
|
+
/** The top-level scalar fields of `C`, the ones a content sort reaches. */
|
|
96
|
+
export type SortableFieldOf<C> = string extends keyof C ? string : {
|
|
97
|
+
[K in keyof C & string]-?: Required<C>[K] extends string | number | boolean ? K : never;
|
|
98
|
+
}[keyof C & string];
|
|
99
|
+
/**
|
|
100
|
+
* A collection reads live records of its own family only, as stored, so
|
|
101
|
+
* none of `typeId`, `baseId`, `includeDeleted`, `presentAt` or the per-Type
|
|
102
|
+
* shapes it generates itself is offered. Content filter keys and the sort
|
|
103
|
+
* field are checked against `C`, and carried to older versions through the
|
|
104
|
+
* migrations. See docs/spec/data-model.md § Type handles.
|
|
105
|
+
*/
|
|
106
|
+
export type CollectionQuery<C> = Omit<StackQuery, 'filter' | 'presentAt' | 'sort'> & {
|
|
107
|
+
filter?: Omit<RecordFilter, 'typeId' | 'baseId' | 'includeDeleted' | 'content' | 'contentPresent' | 'contentByType'> & {
|
|
108
|
+
content?: {
|
|
109
|
+
[E in FieldEntry<C, '', 5> as E[0]]?: E[1] | null;
|
|
110
|
+
};
|
|
111
|
+
contentPresent?: ContentPathOf<C>[];
|
|
112
|
+
};
|
|
113
|
+
sort?: {
|
|
114
|
+
field: NativeSortField;
|
|
115
|
+
contentField?: never;
|
|
116
|
+
direction?: 'asc' | 'desc';
|
|
117
|
+
} | {
|
|
118
|
+
field?: never;
|
|
119
|
+
contentField: SortableFieldOf<C>;
|
|
120
|
+
direction?: 'asc' | 'desc';
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
/** The family is the collection's, so neither `typeId` nor `baseId` is a filter key. */
|
|
124
|
+
export type CollectionSubscribeOptions = Omit<SubscribeOptions, 'filter'> & {
|
|
125
|
+
filter?: Omit<ChangeFilter, 'typeId' | 'baseId'>;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* A change to a record of the family. `record`, when present, is migrated
|
|
129
|
+
* to the handle's version; `typeId` stays the stored one. A change whose
|
|
130
|
+
* record does not fit carries `misfit` instead, and one whose record is a
|
|
131
|
+
* tombstone carries neither.
|
|
132
|
+
*/
|
|
133
|
+
export type CollectionChange<C> = Omit<RecordChange, 'record'> & {
|
|
134
|
+
record?: CollectionRecord<C>;
|
|
135
|
+
misfit?: Misfit;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Typed access to one type family. History (`getVersions`, `getVersion`,
|
|
139
|
+
* `getJournal`) spans versions by nature and stays on `StackClient`. See
|
|
140
|
+
* docs/spec/data-model.md § Type handles.
|
|
141
|
+
*/
|
|
142
|
+
export interface Collection<C> {
|
|
143
|
+
/** `null` for a missing record, a tombstone, or a record of another family. */
|
|
144
|
+
get(id: RecordId): Promise<CollectionRecord<C> | null>;
|
|
145
|
+
query(query?: CollectionQuery<C>): Promise<CollectionPage<C>>;
|
|
146
|
+
subscribe(handler: (change: CollectionChange<C>) => void, opts?: CollectionSubscribeOptions): Promise<Unsubscribe>;
|
|
147
|
+
create(content: C, opts?: CreateRecordOptions): Promise<CollectionRecord<C>>;
|
|
148
|
+
patchContent(id: RecordId, patch: ContentPatch<C>, opts?: IfVersionOptions): Promise<CollectionRecord<C>>;
|
|
149
|
+
setParent(id: RecordId, parentId: RecordId | null, opts?: IfVersionOptions): Promise<CollectionRecord<C>>;
|
|
150
|
+
setUnlisted(id: RecordId, unlisted: boolean, opts?: IfVersionOptions): Promise<CollectionRecord<C>>;
|
|
151
|
+
editAssociations(id: RecordId, edits: AssociationEdit[], opts?: IfVersionOptions): Promise<CollectionRecord<C>>;
|
|
152
|
+
setAssociations(id: RecordId, associations: DataAssociation[], opts?: IfVersionOptions): Promise<CollectionRecord<C>>;
|
|
153
|
+
editAccess(id: RecordId, edits: AssociationEdit[], opts?: IfVersionOptions): Promise<CollectionRecord<C>>;
|
|
154
|
+
setAccess(id: RecordId, permissions: AuthorityAssociation[], opts?: IfVersionOptions): Promise<CollectionRecord<C>>;
|
|
155
|
+
delete(id: RecordId, opts?: DeleteRecordOptions): Promise<DeleteResult>;
|
|
156
|
+
undelete(id: RecordId, opts?: IfVersionOptions): Promise<CollectionRecord<C>>;
|
|
157
|
+
restoreVersion(id: RecordId, version: number, opts?: IfVersionOptions): Promise<CollectionRecord<C>>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* A record the collection asked for does not fit the handle. Raised only
|
|
161
|
+
* in the app's own process and never on the wire, so it sits outside the
|
|
162
|
+
* `StackError` taxonomy. A write that raises it after writing says so.
|
|
163
|
+
* See docs/spec/wire-format.md § The taxonomy root.
|
|
164
|
+
*/
|
|
165
|
+
export declare class MisfitError extends Error {
|
|
166
|
+
readonly reason: Misfit['reason'];
|
|
167
|
+
readonly record: StackRecord;
|
|
168
|
+
constructor(misfit: Misfit, handle: TypeHandle, written?: boolean);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The collection over `handle`, shared by `Stack.collection()` and
|
|
172
|
+
* `ScopedStack.collection()`. `registry` is the opening `Stack`'s, which
|
|
173
|
+
* the app's own process filled. `listTypes` names the family's versions,
|
|
174
|
+
* which `StackClient` does not offer.
|
|
175
|
+
*/
|
|
176
|
+
export declare const createCollection: <S extends ReadonlyTypeSchema>(client: StackClient, registry: MigrationRegistry, handle: TypeHandle<S>, listTypes: () => Promise<StackType[]>) => Collection<ContentOf<S>>;
|
|
177
|
+
export {};
|
|
178
|
+
//# sourceMappingURL=collection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAOjG,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,YAAY,EAGZ,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,EAET,WAAW,EACX,gBAAgB,EAChB,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAM1B;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAC3C,MAAM,SAAS,CAAC,GACd,CAAC,GACD,CAAC,GAAG,aAAa,GACnB,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC5B,aAAa,CAAC,CAAC,CAAC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,CAAC,CAAC,CAAC,CAAC;CACjC;AAED;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;gBAEjB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,UAAQ;CAShE;AAuED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,kBAAkB,EAC3D,QAAQ,WAAW,EACnB,UAAU,iBAAiB,EAC3B,QAAQ,UAAU,CAAC,CAAC,CAAC,EACrB,WAAW,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC,KACpC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAiVzB,CAAC"}
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collections — typed access to one type family
|
|
3
|
+
* -------------------------------------------------------
|
|
4
|
+
* `client.collection(handle)` returns a `Collection<C>`: every verb that
|
|
5
|
+
* addresses records of the handle's family, each taking and returning the
|
|
6
|
+
* handle's content type with one signature. Implemented once over the
|
|
7
|
+
* public `StackClient` verbs, so `Stack` and `ScopedStack` share it and a
|
|
8
|
+
* collection can do nothing its client could not.
|
|
9
|
+
*
|
|
10
|
+
* The collection's scope is the handle's whole family. Each record is read
|
|
11
|
+
* as stored and migrated in memory to the handle's version, one at a time,
|
|
12
|
+
* so a record the handle cannot represent — one stored at a newer version —
|
|
13
|
+
* is reported as a misfit rather than failing the page it sits on. A
|
|
14
|
+
* content write to a record at an older version commits its migration as a
|
|
15
|
+
* write of its own first. See docs/spec/data-model.md § Type handles.
|
|
16
|
+
*/
|
|
17
|
+
import { StackBadRequestError, StackMigrationError, StackPermissionError } from './errors.js';
|
|
18
|
+
import { baseIdOf, parseTypeId } from './schema.js';
|
|
19
|
+
import { StoredVersionError, WRITE_EXPECTATION } from './stack/write-expectation.js';
|
|
20
|
+
import { translateArm, translateSortKey, UNMATCHABLE, UNTRANSLATABLE, } from './content-translation.js';
|
|
21
|
+
/**
|
|
22
|
+
* A record the collection asked for does not fit the handle. Raised only
|
|
23
|
+
* in the app's own process and never on the wire, so it sits outside the
|
|
24
|
+
* `StackError` taxonomy. A write that raises it after writing says so.
|
|
25
|
+
* See docs/spec/wire-format.md § The taxonomy root.
|
|
26
|
+
*/
|
|
27
|
+
export class MisfitError extends Error {
|
|
28
|
+
reason;
|
|
29
|
+
record;
|
|
30
|
+
constructor(misfit, handle, written = false) {
|
|
31
|
+
super(`Record "${misfit.id}" is stored at ${misfit.record.typeId}, newer than ${handle.id}` +
|
|
32
|
+
(written ? '; the write landed.' : '.'));
|
|
33
|
+
this.name = 'MisfitError';
|
|
34
|
+
this.reason = misfit.reason;
|
|
35
|
+
this.record = misfit.record;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// -------------------------------------------------------
|
|
39
|
+
// Implementation
|
|
40
|
+
// -------------------------------------------------------
|
|
41
|
+
const versionOf = (typeId) => parseTypeId(typeId).version;
|
|
42
|
+
/**
|
|
43
|
+
* A filter's `typeId` would narrow the family to one version, so an untyped
|
|
44
|
+
* caller passing one has it dropped rather than honoured.
|
|
45
|
+
*/
|
|
46
|
+
const withoutTypeId = (filter) => {
|
|
47
|
+
const { typeId: _typeId, ...rest } = (filter ?? {});
|
|
48
|
+
return rest;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* A filter's content predicate, or undefined when it names no key. Only
|
|
52
|
+
* records stored at the handle's version are guaranteed to hold content in
|
|
53
|
+
* the handle's shape, so a predicate is what has to be translated.
|
|
54
|
+
*/
|
|
55
|
+
const contentPredicate = (filter) => {
|
|
56
|
+
const content = Object.keys(filter.content ?? {}).length > 0 ? filter.content : undefined;
|
|
57
|
+
const present = filter.contentPresent?.length ? filter.contentPresent : undefined;
|
|
58
|
+
if (!content && !present)
|
|
59
|
+
return undefined;
|
|
60
|
+
return { ...(content && { content }), ...(present && { contentPresent: present }) };
|
|
61
|
+
};
|
|
62
|
+
/** `filter` without its content predicate, for a query that asks about the rest. */
|
|
63
|
+
const withoutContent = (filter) => {
|
|
64
|
+
const { content: _content, contentPresent: _present, ...rest } = filter;
|
|
65
|
+
return rest;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* A content query's cursor: the adapter's, with the versions the first page
|
|
69
|
+
* queried, so a version defined mid-pagination cannot change the arms or
|
|
70
|
+
* the sort a cursor resumes, and a later page lists no types.
|
|
71
|
+
*/
|
|
72
|
+
const encodeContentCursor = (versions, cursor) => {
|
|
73
|
+
const bytes = new TextEncoder().encode(JSON.stringify({ v: versions, c: cursor }));
|
|
74
|
+
let binary = '';
|
|
75
|
+
for (const byte of bytes)
|
|
76
|
+
binary += String.fromCharCode(byte);
|
|
77
|
+
return btoa(binary);
|
|
78
|
+
};
|
|
79
|
+
const decodeContentCursor = (raw, handle) => {
|
|
80
|
+
const malformed = () => new StackBadRequestError(`Invalid cursor: malformed "${raw}"`);
|
|
81
|
+
let parsed;
|
|
82
|
+
try {
|
|
83
|
+
const binary = atob(raw);
|
|
84
|
+
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
85
|
+
parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
throw malformed();
|
|
89
|
+
}
|
|
90
|
+
const { v, c } = (parsed ?? {});
|
|
91
|
+
if (typeof c !== 'string' ||
|
|
92
|
+
!Array.isArray(v) ||
|
|
93
|
+
!v.every((id) => typeof id === 'string' && parseTypeId(id)?.baseId === handle.baseId)) {
|
|
94
|
+
throw malformed();
|
|
95
|
+
}
|
|
96
|
+
return { versions: v, cursor: c };
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The collection over `handle`, shared by `Stack.collection()` and
|
|
100
|
+
* `ScopedStack.collection()`. `registry` is the opening `Stack`'s, which
|
|
101
|
+
* the app's own process filled. `listTypes` names the family's versions,
|
|
102
|
+
* which `StackClient` does not offer.
|
|
103
|
+
*/
|
|
104
|
+
export const createCollection = (client, registry, handle, listTypes) => {
|
|
105
|
+
if (handle.migratesFrom !== undefined && !registry.path(handle.migratesFrom, handle.id)) {
|
|
106
|
+
throw new StackMigrationError(`No migration from "${handle.migratesFrom}" to "${handle.id}" was passed to Stack.open().`);
|
|
107
|
+
}
|
|
108
|
+
const writer = client;
|
|
109
|
+
const family = { baseId: handle.baseId };
|
|
110
|
+
const expect = (expectation = family) => ({
|
|
111
|
+
[WRITE_EXPECTATION]: expectation,
|
|
112
|
+
});
|
|
113
|
+
const handleVersion = versionOf(handle.id);
|
|
114
|
+
/**
|
|
115
|
+
* One record of the family, migrated to the handle's version, or the
|
|
116
|
+
* misfit it is. An older record with no migration to bridge the gap is
|
|
117
|
+
* the app's setup, not the record's, and throws.
|
|
118
|
+
*/
|
|
119
|
+
const classify = (record) => {
|
|
120
|
+
if (record.typeId === handle.id)
|
|
121
|
+
return { record: record };
|
|
122
|
+
if (versionOf(record.typeId) > handleVersion) {
|
|
123
|
+
return { misfit: { id: record.id, reason: 'newer-version', record } };
|
|
124
|
+
}
|
|
125
|
+
const migrate = registry.path(record.typeId, handle.id);
|
|
126
|
+
if (!migrate) {
|
|
127
|
+
throw new StackMigrationError(`Record "${record.id}" is at "${record.typeId}", and no migration passed to ` +
|
|
128
|
+
`Stack.open() carries it to "${handle.id}".`);
|
|
129
|
+
}
|
|
130
|
+
const content = migrate(record.content);
|
|
131
|
+
return { record: { ...record, typeId: handle.id, content } };
|
|
132
|
+
};
|
|
133
|
+
/** A record a write returned, narrowed as `get()` narrows it. */
|
|
134
|
+
const narrow = (record, written) => {
|
|
135
|
+
const result = classify(record);
|
|
136
|
+
if ('misfit' in result)
|
|
137
|
+
throw new MisfitError(result.misfit, handle, written);
|
|
138
|
+
return result.record;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* A content write to a record stored at an older version: commit its
|
|
142
|
+
* migration as a write of its own, fenced to the state the caller read,
|
|
143
|
+
* then apply the write fenced to the version the migration produced. A
|
|
144
|
+
* patch never folds a migration in. See docs/spec/data-model.md § Type
|
|
145
|
+
* migrations.
|
|
146
|
+
*/
|
|
147
|
+
const migrateThenPatch = async (stored, patch, opts) => {
|
|
148
|
+
const migrated = classify(stored);
|
|
149
|
+
if ('misfit' in migrated)
|
|
150
|
+
throw new MisfitError(migrated.misfit, handle);
|
|
151
|
+
let committed;
|
|
152
|
+
try {
|
|
153
|
+
committed = await client.commitMigration(stored.id, handle.id, migrated.record.content, {
|
|
154
|
+
ifVersion: stored.version,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
if (!(err instanceof StackPermissionError))
|
|
159
|
+
throw err;
|
|
160
|
+
throw new StackPermissionError(`Record "${stored.id}" is stored at ${stored.typeId} and must be migrated to ` +
|
|
161
|
+
`${handle.id} before this write: ${err.message}`);
|
|
162
|
+
}
|
|
163
|
+
const written = await writer.patchContent(stored.id, patch, {
|
|
164
|
+
...opts,
|
|
165
|
+
ifVersion: committed.version,
|
|
166
|
+
...expect({ ...family, typeId: handle.id }),
|
|
167
|
+
});
|
|
168
|
+
return narrow(written, true);
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Whether any record matches, or may match, `filter`. A scoped page can
|
|
172
|
+
* be empty with a cursor set, and reading on is unbounded, so that page
|
|
173
|
+
* counts as a match.
|
|
174
|
+
*/
|
|
175
|
+
const anyMatch = async (filter) => {
|
|
176
|
+
const page = await client.query({ filter, limit: 1 });
|
|
177
|
+
return page.records.length > 0 || page.cursor !== null;
|
|
178
|
+
};
|
|
179
|
+
/** Whether a record stored at one of `typeIds` matches `filter` without its content keys. */
|
|
180
|
+
const anyAt = async (typeIds, filter) => {
|
|
181
|
+
if (typeIds.length === 0)
|
|
182
|
+
return false;
|
|
183
|
+
return anyMatch({ ...withoutContent(filter), typeId: typeIds });
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Whether records at an older version hold what its arm left out: each
|
|
187
|
+
* residual is that arm with another source value in place, at its typeId.
|
|
188
|
+
*/
|
|
189
|
+
const anyResidual = async (residuals, filter) => {
|
|
190
|
+
const rest = withoutContent(filter);
|
|
191
|
+
const found = await Promise.all(residuals.map((residual) => anyMatch({ ...rest, ...residual })));
|
|
192
|
+
return found.some(Boolean);
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* A content query as one arm per version it translates to, plus what the
|
|
196
|
+
* first page probes for `skipped`. `pinned` is the versions a first page
|
|
197
|
+
* chose, which a later page reuses. See docs/spec/data-model.md § Content
|
|
198
|
+
* queries across versions.
|
|
199
|
+
*/
|
|
200
|
+
const planContentQuery = async (filter, sort, pinned) => {
|
|
201
|
+
const predicate = contentPredicate(filter);
|
|
202
|
+
const sortField = sort?.contentField;
|
|
203
|
+
const { capabilities } = client;
|
|
204
|
+
// Spanning versions takes the per-Type shape of each content key the
|
|
205
|
+
// query carries; an adapter without one gets the handle's version alone.
|
|
206
|
+
const spans = (predicate === undefined || capabilities.filter.contentByType) &&
|
|
207
|
+
(sortField === undefined || capabilities.sort.contentFieldByType);
|
|
208
|
+
const sortKind = (() => {
|
|
209
|
+
const def = sortField === undefined ? undefined : handle.schema[sortField];
|
|
210
|
+
return def && def.kind !== 'array' && def.kind !== 'object' ? def.kind : undefined;
|
|
211
|
+
})();
|
|
212
|
+
const family = (pinned
|
|
213
|
+
? pinned.map((id) => ({ id, baseId: handle.baseId, version: versionOf(id) }))
|
|
214
|
+
: await listTypes()).filter((type) => type.baseId === handle.baseId && type.version !== handleVersion);
|
|
215
|
+
const arms = { [handle.id]: predicate ?? {} };
|
|
216
|
+
const keys = sortField
|
|
217
|
+
? { [handle.id]: { field: sortField } }
|
|
218
|
+
: {};
|
|
219
|
+
const narrowed = [];
|
|
220
|
+
const newer = [];
|
|
221
|
+
const residuals = [];
|
|
222
|
+
for (const type of family) {
|
|
223
|
+
if (type.version > handleVersion) {
|
|
224
|
+
newer.push(type.id);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const origins = registry.origins(type.id, handle.id);
|
|
228
|
+
const translated = !predicate
|
|
229
|
+
? { arm: {}, residuals: [] }
|
|
230
|
+
: origins
|
|
231
|
+
? translateArm(origins, predicate)
|
|
232
|
+
: UNTRANSLATABLE;
|
|
233
|
+
if (translated === UNMATCHABLE)
|
|
234
|
+
continue;
|
|
235
|
+
const key = sortField === undefined
|
|
236
|
+
? undefined
|
|
237
|
+
: origins
|
|
238
|
+
? translateSortKey(origins, sortField, sortKind)
|
|
239
|
+
: UNTRANSLATABLE;
|
|
240
|
+
if (translated === UNTRANSLATABLE || key === UNTRANSLATABLE || !spans) {
|
|
241
|
+
narrowed.push(type.id);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
arms[type.id] = translated.arm;
|
|
245
|
+
if (key)
|
|
246
|
+
keys[type.id] = key;
|
|
247
|
+
for (const arm of translated.residuals)
|
|
248
|
+
residuals.push({ ...arm, typeId: type.id });
|
|
249
|
+
}
|
|
250
|
+
const rest = withoutContent(filter);
|
|
251
|
+
const typeIds = Object.keys(arms);
|
|
252
|
+
if (typeIds.length === 1) {
|
|
253
|
+
return {
|
|
254
|
+
query: { filter: { ...filter, typeId: handle.id }, sort },
|
|
255
|
+
versions: typeIds,
|
|
256
|
+
narrowed,
|
|
257
|
+
newer,
|
|
258
|
+
residuals,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
query: {
|
|
263
|
+
filter: predicate ? { ...rest, contentByType: arms } : { ...rest, typeId: typeIds },
|
|
264
|
+
sort: sortField
|
|
265
|
+
? { contentFieldByType: keys, ...(sort?.direction && { direction: sort.direction }) }
|
|
266
|
+
: sort,
|
|
267
|
+
},
|
|
268
|
+
versions: typeIds,
|
|
269
|
+
narrowed,
|
|
270
|
+
newer,
|
|
271
|
+
residuals,
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
const patchContent = async (id, patch, opts = {}) => {
|
|
275
|
+
try {
|
|
276
|
+
const written = await writer.patchContent(id, patch, {
|
|
277
|
+
...opts,
|
|
278
|
+
...expect({ ...family, typeId: handle.id }),
|
|
279
|
+
});
|
|
280
|
+
return narrow(written, true);
|
|
281
|
+
}
|
|
282
|
+
catch (err) {
|
|
283
|
+
if (!(err instanceof StoredVersionError))
|
|
284
|
+
throw err;
|
|
285
|
+
return migrateThenPatch(err.record, patch, opts);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
async get(id) {
|
|
290
|
+
const record = await client.get(id);
|
|
291
|
+
if (!record || baseIdOf(record.typeId) !== handle.baseId)
|
|
292
|
+
return null;
|
|
293
|
+
return narrow(record, false);
|
|
294
|
+
},
|
|
295
|
+
async query(query = {}) {
|
|
296
|
+
if (query.filter?.includeDeleted) {
|
|
297
|
+
throw new StackBadRequestError('A collection reads live records only; use the untyped query() to include soft-deleted records.');
|
|
298
|
+
}
|
|
299
|
+
// Stripped as well as untyped: either would change which records a
|
|
300
|
+
// page holds, or the shape they arrive in.
|
|
301
|
+
const { presentAt: _presentAt, filter, ...rest } = query;
|
|
302
|
+
// A concrete typeId needs no family lookup; baseId does.
|
|
303
|
+
const { baseId: _baseId, contentByType: _byType, ...unversioned } = withoutTypeId(filter);
|
|
304
|
+
const firstPage = rest.cursor === undefined;
|
|
305
|
+
let records;
|
|
306
|
+
let cursor;
|
|
307
|
+
let skipped;
|
|
308
|
+
if (!contentPredicate(unversioned) && rest.sort?.contentField === undefined) {
|
|
309
|
+
({ records, cursor } = await client.query({
|
|
310
|
+
...rest,
|
|
311
|
+
filter: { ...unversioned, baseId: handle.baseId },
|
|
312
|
+
}));
|
|
313
|
+
if (firstPage)
|
|
314
|
+
skipped = { older: false, newer: false };
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
const resumed = firstPage ? undefined : decodeContentCursor(rest.cursor, handle);
|
|
318
|
+
const plan = await planContentQuery(unversioned, rest.sort, resumed?.versions);
|
|
319
|
+
const [page, narrowed, residual, newer] = await Promise.all([
|
|
320
|
+
client.query({ ...rest, cursor: resumed?.cursor, ...plan.query }),
|
|
321
|
+
firstPage && anyAt(plan.narrowed, unversioned),
|
|
322
|
+
firstPage && anyResidual(plan.residuals, unversioned),
|
|
323
|
+
firstPage && anyAt(plan.newer, unversioned),
|
|
324
|
+
]);
|
|
325
|
+
records = page.records;
|
|
326
|
+
cursor = page.cursor && encodeContentCursor(plan.versions, page.cursor);
|
|
327
|
+
if (firstPage)
|
|
328
|
+
skipped = { older: narrowed || residual, newer };
|
|
329
|
+
}
|
|
330
|
+
const page = {
|
|
331
|
+
records: [],
|
|
332
|
+
misfits: [],
|
|
333
|
+
cursor,
|
|
334
|
+
...(skipped && { skipped }),
|
|
335
|
+
};
|
|
336
|
+
for (const stored of records) {
|
|
337
|
+
const result = classify(stored);
|
|
338
|
+
if ('misfit' in result)
|
|
339
|
+
page.misfits.push(result.misfit);
|
|
340
|
+
else
|
|
341
|
+
page.records.push(result.record);
|
|
342
|
+
}
|
|
343
|
+
return page;
|
|
344
|
+
},
|
|
345
|
+
subscribe(handler, opts = {}) {
|
|
346
|
+
return client.subscribe((change) => {
|
|
347
|
+
const { record, ...rest } = change;
|
|
348
|
+
// A tombstone's content is `{}` under ScopedStack, so it is never
|
|
349
|
+
// typed as the handle's content on either surface. A record that
|
|
350
|
+
// migrated out of the family matches by its previous typeId.
|
|
351
|
+
if (!record || record.deletedAt || baseIdOf(record.typeId) !== handle.baseId) {
|
|
352
|
+
return handler(rest);
|
|
353
|
+
}
|
|
354
|
+
let result;
|
|
355
|
+
try {
|
|
356
|
+
result = classify(record);
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
// A missing or failing migration: delivered as wherever the
|
|
360
|
+
// emitter cannot supply the record, and get() says why.
|
|
361
|
+
return handler(rest);
|
|
362
|
+
}
|
|
363
|
+
handler({ ...rest, ...result });
|
|
364
|
+
}, { ...opts, filter: { ...withoutTypeId(opts.filter), baseId: handle.baseId } });
|
|
365
|
+
},
|
|
366
|
+
async create(content, opts) {
|
|
367
|
+
return (await client.create(handle.id, content, opts));
|
|
368
|
+
},
|
|
369
|
+
patchContent: (id, patch, opts) => patchContent(id, patch, opts),
|
|
370
|
+
async setParent(id, parentId, opts) {
|
|
371
|
+
return narrow(await writer.setParent(id, parentId, { ...opts, ...expect() }), true);
|
|
372
|
+
},
|
|
373
|
+
async setUnlisted(id, unlisted, opts) {
|
|
374
|
+
return narrow(await writer.setUnlisted(id, unlisted, { ...opts, ...expect() }), true);
|
|
375
|
+
},
|
|
376
|
+
async editAssociations(id, edits, opts) {
|
|
377
|
+
return narrow(await writer.editAssociations(id, edits, { ...opts, ...expect() }), true);
|
|
378
|
+
},
|
|
379
|
+
async setAssociations(id, associations, opts) {
|
|
380
|
+
return narrow(await writer.setAssociations(id, associations, { ...opts, ...expect() }), true);
|
|
381
|
+
},
|
|
382
|
+
async editAccess(id, edits, opts) {
|
|
383
|
+
return narrow(await writer.editAccess(id, edits, { ...opts, ...expect() }), true);
|
|
384
|
+
},
|
|
385
|
+
async setAccess(id, permissions, opts) {
|
|
386
|
+
return narrow(await writer.setAccess(id, permissions, { ...opts, ...expect() }), true);
|
|
387
|
+
},
|
|
388
|
+
delete: (id, opts) => writer.delete(id, { ...opts, ...expect() }),
|
|
389
|
+
async undelete(id, opts) {
|
|
390
|
+
return narrow(await writer.undelete(id, { ...opts, ...expect() }), true);
|
|
391
|
+
},
|
|
392
|
+
async restoreVersion(id, version, opts) {
|
|
393
|
+
return narrow(await writer.restoreVersion(id, version, { ...opts, ...expect() }), true);
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
//# sourceMappingURL=collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.js","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE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AC,EAAE,IAAI,CAAC,CAAC;QAC3E,CAAC;QACD,KAAK,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI;YACpC,OAAO,MAAM,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QAC1F,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content predicates, evaluated in memory
|
|
3
|
+
* -------------------------------------------------------
|
|
4
|
+
* How a `content` filter value and a `contentPresent` path are matched
|
|
5
|
+
* against one content object: element-wise through arrays, with `null`
|
|
6
|
+
* standing for "no value". MemoryAdapter answers queries with it, and a
|
|
7
|
+
* collection decides a constant a migration added the same way, so a key
|
|
8
|
+
* dropped in core matches exactly what an adapter would have matched. See
|
|
9
|
+
* docs/spec/data-model.md § Nested content paths.
|
|
10
|
+
*/
|
|
11
|
+
import type { ContentArm } from './types/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Every value reachable by walking `segments`, spreading arrays at each
|
|
14
|
+
* step — the walk sqlite-shared runs in SQL, so a filter answers the same
|
|
15
|
+
* against either. Empty means the path reaches nothing, which a `null`
|
|
16
|
+
* filter value matches.
|
|
17
|
+
*/
|
|
18
|
+
export declare const valuesAtContentPath: (content: Record<string, unknown>, segments: string[]) => unknown[];
|
|
19
|
+
/**
|
|
20
|
+
* Whether `content` satisfies a `content` and `contentPresent` predicate. A
|
|
21
|
+
* `null` filter value means "field absent or null", not "match nothing":
|
|
22
|
+
* plain `===` would miss an absent field (docs/spec/data-model.md § Filter).
|
|
23
|
+
*/
|
|
24
|
+
export declare const matchesContent: (content: Record<string, unknown>, predicate: ContentArm) => boolean;
|
|
25
|
+
//# sourceMappingURL=content-match.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-match.d.ts","sourceRoot":"","sources":["../src/content-match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAKnD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,UAAU,MAAM,EAAE,KACjB,OAAO,EAeT,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,UAAU,KAAG,OAYtF,CAAC"}
|