@hyper-fetch/db 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/README.md +180 -2
  2. package/__tests__/e2e/db.e2e.spec.ts +269 -0
  3. package/__tests__/features/connection/connection.spec.ts +23 -0
  4. package/__tests__/features/model/live-query.model.spec.ts +320 -0
  5. package/__tests__/features/operators/operators.spec.ts +113 -0
  6. package/__tests__/features/runtime/runtime.spec.ts +185 -0
  7. package/__tests__/features/serializer/serializer.spec.ts +73 -0
  8. package/__tests__/features/store/store.spec.ts +147 -0
  9. package/__tests__/features/types/db.types.spec.ts +337 -0
  10. package/__tests__/integration/audit.spec.ts +639 -0
  11. package/__tests__/integration/competitors.spec.ts +393 -0
  12. package/__tests__/integration/convergence.model.spec.ts +162 -0
  13. package/__tests__/integration/edge-cases.spec.ts +465 -0
  14. package/__tests__/integration/errors.spec.ts +178 -0
  15. package/__tests__/integration/infinite.model.spec.ts +142 -0
  16. package/__tests__/integration/infinite.spec.ts +290 -0
  17. package/__tests__/integration/inspect.spec.ts +103 -0
  18. package/__tests__/integration/joins-many.spec.ts +177 -0
  19. package/__tests__/integration/joins.spec.ts +179 -0
  20. package/__tests__/integration/key-loaders.spec.ts +196 -0
  21. package/__tests__/integration/links.spec.ts +105 -0
  22. package/__tests__/integration/mutations.spec.ts +337 -0
  23. package/__tests__/integration/normalize.spec.ts +80 -0
  24. package/__tests__/integration/offline.spec.ts +479 -0
  25. package/__tests__/integration/queries.spec.ts +513 -0
  26. package/__tests__/integration/races.spec.ts +127 -0
  27. package/__tests__/integration/server-operators.spec.ts +123 -0
  28. package/__tests__/integration/ssr.spec.ts +111 -0
  29. package/__tests__/integration/syncs.spec.ts +564 -0
  30. package/__tests__/integration/transactions.spec.ts +344 -0
  31. package/__tests__/integration/windows.spec.ts +192 -0
  32. package/__tests__/tsconfig.json +11 -0
  33. package/__tests__/type-budget/budget.fixture.ts +2476 -0
  34. package/__tests__/type-budget/tsconfig.json +4 -0
  35. package/__tests__/utils/fixtures.ts +225 -0
  36. package/__tests__/utils/random.ts +19 -0
  37. package/__tests__/vitest.setup.ts +11 -0
  38. package/dist/collection/collection.d.ts +111 -0
  39. package/dist/collection/collection.d.ts.map +1 -0
  40. package/dist/collection/collection.types.d.ts +316 -0
  41. package/dist/collection/collection.types.d.ts.map +1 -0
  42. package/dist/collection/resource.types.d.ts +77 -0
  43. package/dist/collection/resource.types.d.ts.map +1 -0
  44. package/dist/db/collection.runtime.d.ts +98 -0
  45. package/dist/db/collection.runtime.d.ts.map +1 -0
  46. package/dist/db/db.d.ts +154 -0
  47. package/dist/db/db.d.ts.map +1 -0
  48. package/dist/db/db.runtime.d.ts +114 -0
  49. package/dist/db/db.runtime.d.ts.map +1 -0
  50. package/dist/db/db.types.d.ts +162 -0
  51. package/dist/db/db.types.d.ts.map +1 -0
  52. package/dist/graphql/connection.d.ts +25 -0
  53. package/dist/graphql/connection.d.ts.map +1 -0
  54. package/dist/index.d.ts +17 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.mjs +4220 -0
  57. package/dist/index.mjs.map +1 -0
  58. package/dist/mutation/mutation.d.ts +136 -0
  59. package/dist/mutation/mutation.d.ts.map +1 -0
  60. package/dist/mutation/mutation.errors.d.ts +6 -0
  61. package/dist/mutation/mutation.errors.d.ts.map +1 -0
  62. package/dist/mutation/mutation.utils.d.ts +35 -0
  63. package/dist/mutation/mutation.utils.d.ts.map +1 -0
  64. package/dist/operators/operators.d.ts +33 -0
  65. package/dist/operators/operators.d.ts.map +1 -0
  66. package/dist/operators/operators.types.d.ts +68 -0
  67. package/dist/operators/operators.types.d.ts.map +1 -0
  68. package/dist/operators/operators.utils.d.ts +19 -0
  69. package/dist/operators/operators.utils.d.ts.map +1 -0
  70. package/dist/persistence/persistence.d.ts +42 -0
  71. package/dist/persistence/persistence.d.ts.map +1 -0
  72. package/dist/persistence/serializer.d.ts +23 -0
  73. package/dist/persistence/serializer.d.ts.map +1 -0
  74. package/dist/persistence/snapshot.d.ts +29 -0
  75. package/dist/persistence/snapshot.d.ts.map +1 -0
  76. package/dist/persistence/tabs.d.ts +53 -0
  77. package/dist/persistence/tabs.d.ts.map +1 -0
  78. package/dist/query/infinite-query.d.ts +59 -0
  79. package/dist/query/infinite-query.d.ts.map +1 -0
  80. package/dist/query/live-query.d.ts +85 -0
  81. package/dist/query/live-query.d.ts.map +1 -0
  82. package/dist/query/planner.d.ts +57 -0
  83. package/dist/query/planner.d.ts.map +1 -0
  84. package/dist/query/query.d.ts +155 -0
  85. package/dist/query/query.d.ts.map +1 -0
  86. package/dist/query/query.types.d.ts +71 -0
  87. package/dist/query/query.types.d.ts.map +1 -0
  88. package/dist/schema/schema.types.d.ts +33 -0
  89. package/dist/schema/schema.types.d.ts.map +1 -0
  90. package/dist/store/store.d.ts +76 -0
  91. package/dist/store/store.d.ts.map +1 -0
  92. package/dist/store/store.types.d.ts +27 -0
  93. package/dist/store/store.types.d.ts.map +1 -0
  94. package/dist/subset/base-subset.d.ts +66 -0
  95. package/dist/subset/base-subset.d.ts.map +1 -0
  96. package/dist/subset/key-subset.d.ts +23 -0
  97. package/dist/subset/key-subset.d.ts.map +1 -0
  98. package/dist/subset/list-subset.d.ts +63 -0
  99. package/dist/subset/list-subset.d.ts.map +1 -0
  100. package/dist/sync/sync.d.ts +42 -0
  101. package/dist/sync/sync.d.ts.map +1 -0
  102. package/dist/utils/request.utils.d.ts +11 -0
  103. package/dist/utils/request.utils.d.ts.map +1 -0
  104. package/package.json +71 -4
  105. package/project.json +4 -0
  106. package/scripts/docs-typescript.mjs +24 -0
  107. package/scripts/type-budget.mjs +37 -0
  108. package/src/collection/collection.ts +330 -0
  109. package/src/collection/collection.types.ts +383 -0
  110. package/src/collection/resource.types.ts +114 -0
  111. package/src/db/collection.runtime.ts +572 -0
  112. package/src/db/db.runtime.ts +537 -0
  113. package/src/db/db.ts +451 -0
  114. package/src/db/db.types.ts +157 -0
  115. package/src/graphql/connection.ts +23 -0
  116. package/src/index.ts +16 -0
  117. package/src/mutation/mutation.errors.ts +7 -0
  118. package/src/mutation/mutation.ts +776 -0
  119. package/src/mutation/mutation.utils.ts +58 -0
  120. package/src/operators/operators.ts +90 -0
  121. package/src/operators/operators.types.ts +67 -0
  122. package/src/operators/operators.utils.ts +169 -0
  123. package/src/persistence/persistence.ts +168 -0
  124. package/src/persistence/serializer.ts +123 -0
  125. package/src/persistence/snapshot.ts +76 -0
  126. package/src/persistence/tabs.ts +86 -0
  127. package/src/query/infinite-query.ts +206 -0
  128. package/src/query/live-query.ts +552 -0
  129. package/src/query/planner.ts +199 -0
  130. package/src/query/query.ts +319 -0
  131. package/src/query/query.types.ts +90 -0
  132. package/src/schema/schema.types.ts +29 -0
  133. package/src/store/store.ts +300 -0
  134. package/src/store/store.types.ts +17 -0
  135. package/src/subset/base-subset.ts +169 -0
  136. package/src/subset/key-subset.ts +44 -0
  137. package/src/subset/list-subset.ts +328 -0
  138. package/src/sync/sync.ts +99 -0
  139. package/src/utils/request.utils.ts +67 -0
  140. package/tsconfig.json +12 -0
  141. package/vite.config.ts +71 -0
@@ -0,0 +1,316 @@
1
+ import { ExtractParamsType, ExtractPayloadType, ExtractQueryParamsType, ExtractResponseType, RequestInstance } from '@hyper-fetch/core';
2
+ import { ExtractListenerDeliveredType, ListenerInstance } from '@hyper-fetch/sockets';
3
+ import { ComparisonNode, ComparisonOperator } from '../operators/operators.types';
4
+ import { StandardSchemaV1 } from '../schema/schema.types';
5
+ export type SortDirection = "asc" | "desc";
6
+ /** Fields whose values can be a key: strings and numbers */
7
+ export type KeyFieldOf<Row> = {
8
+ [Field in keyof Row]-?: NonNullable<Row[Field]> extends string | number ? Field : never;
9
+ }[keyof Row] & string;
10
+ export type RowKey = string | number;
11
+ type PartialIfObject<T> = T extends Record<string, unknown> ? Partial<T> : T;
12
+ /**
13
+ * What a loader, mapping or mutation adds to a request: path params, query params and payload, each checked against
14
+ * the request's own types. Objects are merged into what the request already has.
15
+ */
16
+ export type RequestPatch<Req> = {
17
+ params?: PartialIfObject<NonNullable<ExtractParamsType<Req>>>;
18
+ queryParams?: PartialIfObject<NonNullable<ExtractQueryParamsType<Req>>>;
19
+ payload?: PartialIfObject<NonNullable<ExtractPayloadType<Req>>>;
20
+ };
21
+ /** A patch without request types, used by the db-wide default notation */
22
+ export type AnyRequestPatch = {
23
+ params?: Record<string, unknown>;
24
+ queryParams?: Record<string, unknown> | string | readonly unknown[];
25
+ payload?: unknown;
26
+ };
27
+ /** What a sync adds to a listener: topic params, a subscription payload or listener query params */
28
+ export type ListenerPatch = {
29
+ params?: Record<string, unknown>;
30
+ payload?: unknown;
31
+ queryParams?: unknown;
32
+ };
33
+ /** How one field's operators reach the backend. `true` uses the db-wide default notation. */
34
+ export type FieldWhereDeclaration<Value, Req> = {
35
+ eq?: ((value: Value) => RequestPatch<Req>) | true;
36
+ gt?: ((value: NonNullable<Value>) => RequestPatch<Req>) | true;
37
+ gte?: ((value: NonNullable<Value>) => RequestPatch<Req>) | true;
38
+ lt?: ((value: NonNullable<Value>) => RequestPatch<Req>) | true;
39
+ lte?: ((value: NonNullable<Value>) => RequestPatch<Req>) | true;
40
+ inArray?: ((values: Value[]) => RequestPatch<Req>) | true;
41
+ /** The endpoint cannot work without this filter, such as `teamId` in `/teams/:teamId/posts` */
42
+ required?: true;
43
+ } & {
44
+ /** Server-only operators by name, such as `search`, which queries use through `op("search", field, value)` */
45
+ [operator: string]: ((value: never) => RequestPatch<Req>) | true | undefined;
46
+ };
47
+ export type WhereDeclaration<Row, Req> = {
48
+ [Field in keyof Row & string]?: FieldWhereDeclaration<Row[Field], Req>;
49
+ };
50
+ export type OrderDeclaration<Row, Req> = {
51
+ [Field in keyof Row & string]?: ((direction: SortDirection) => RequestPatch<Req>) | true;
52
+ };
53
+ type ResponseItem<Response> = Response extends readonly (infer Item)[] ? Item : Response;
54
+ /** A type argument that was not inferred is `unknown`: then use the fallback */
55
+ export type Inferred<T, Fallback> = unknown extends T ? Fallback : T;
56
+ /** Whether an optional option was given, judged by whether its type argument was inferred */
57
+ type IsGiven<T> = unknown extends T ? false : true;
58
+ /** The rows a loader writes when it has no `rows` mapping: the elements of a list, or the response itself */
59
+ export type DefaultRows<Req> = ResponseItem<ExtractResponseType<Req>>;
60
+ /** Whether mapped rows are exactly the collection's rows: nothing missing, nothing extra */
61
+ export type IsExactRow<Mapped, Row> = [Mapped] extends [Row] ? [Exclude<keyof Mapped, keyof Row>] extends [never] ? true : false : false;
62
+ /** Whether a partial write carries the key and only row fields of the same types */
63
+ export type IsPartialRow<Mapped, Row, KeyField extends keyof Row> = [Mapped] extends [
64
+ Partial<Row> & Required<Pick<Row, KeyField>>
65
+ ] ? [Exclude<keyof Mapped, keyof Row>] extends [never] ? true : false : false;
66
+ /**
67
+ * What a collection method returns when its rows do not match the collection's row type. It has no collection
68
+ * methods, so chaining on it and passing it to `createDb` do not compile.
69
+ */
70
+ export type RowMismatch<Received, Expected> = {
71
+ readonly rowMismatch: {
72
+ readonly received: Received;
73
+ readonly expected: Expected;
74
+ };
75
+ };
76
+ /**
77
+ * How a backend writes every operator and order, shipped by an adapter preset such as `firestoreCollection`. A loader
78
+ * with a notation can send any condition and order on any field.
79
+ */
80
+ export type Notation = {
81
+ where?: Partial<Record<ComparisonOperator, (field: string, value: unknown) => AnyRequestPatch>>;
82
+ orderBy?: (field: string, direction: SortDirection) => AnyRequestPatch;
83
+ };
84
+ export type LoaderOptions<Row, Key, Req, Mapped, Where, Order, Cursor, Limit, ByKey, ByKeys, LoaderNotation> = {
85
+ /** How the backend writes every operator and order, so the loader sends conditions on any field */
86
+ notation?: LoaderNotation & Notation;
87
+ /**
88
+ * Reads complete rows from a response, for example from a wrapped list such as `{ data: { items }, meta }` or by
89
+ * reshaping each item. Without it, the response is the list of rows, or the row.
90
+ */
91
+ rows?: (response: ExtractResponseType<Req>) => readonly Mapped[];
92
+ /** The operators the endpoint can serve for each field */
93
+ where?: Where & WhereDeclaration<Row, Req>;
94
+ /** The fields the endpoint can sort by */
95
+ orderBy?: Order & OrderDeclaration<Row, Req>;
96
+ /** Reads the next page's cursor from a response. Declaring it makes the loader paginated. */
97
+ cursor?: (response: ExtractResponseType<Req>) => Cursor | null | undefined;
98
+ /** Sends a cursor to load the page after it */
99
+ page?: (cursor: Cursor) => RequestPatch<Req>;
100
+ /** Sends a query's limit. Declaring it makes the loader paginated. */
101
+ limit?: Limit & ((limit: number) => RequestPatch<Req>);
102
+ /** Conditions the endpoint applies on its own, such as `{ archived: false }` */
103
+ fixed?: Partial<Row>;
104
+ /** Fields the backend compares differently from the client, so queries on them are never answered locally */
105
+ serverOnly?: readonly (keyof Row & string)[];
106
+ /** Reads one row by key. A loader with it serves `findOne`. */
107
+ byKey?: ByKey & ((key: Key) => RequestPatch<Req>);
108
+ /** Reads several rows by key in one request. A loader with it serves `findOne`, batched. */
109
+ byKeys?: ByKeys & ((keys: Key[]) => RequestPatch<Req>);
110
+ };
111
+ /** What the types know about a loader that lists rows */
112
+ export type ListLoaderDescriptor<Required extends string = string, Tokens extends string = string, Order extends string = string, Paginated extends boolean = boolean> = {
113
+ kind: "list";
114
+ required: Required;
115
+ tokens: Tokens;
116
+ order: Order;
117
+ paginated: Paginated;
118
+ };
119
+ /** What the types know about a loader that reads rows by key */
120
+ export type KeyLoaderDescriptor = {
121
+ kind: "key";
122
+ };
123
+ export type LoaderDescriptor = ListLoaderDescriptor | KeyLoaderDescriptor;
124
+ type RequiredFields<Where> = {
125
+ [Field in keyof Where & string]: Where[Field] extends {
126
+ required: true;
127
+ } ? Field : never;
128
+ }[keyof Where & string];
129
+ type WhereTokens<Where> = {
130
+ [Field in keyof Where & string]: `${Field}:${Exclude<keyof Where[Field], "required"> & string}`;
131
+ }[keyof Where & string];
132
+ export type DescribeLoader<Row, Where, Order, Cursor, Limit, ByKey, ByKeys, LoaderNotation> = IsGiven<ByKey> extends true ? KeyLoaderDescriptor : IsGiven<ByKeys> extends true ? KeyLoaderDescriptor : ListLoaderDescriptor<RequiredFields<Inferred<Where, {}>>, WhereTokens<Inferred<Where, {}>> | (IsGiven<LoaderNotation> extends true ? `${keyof Row & string}:${ComparisonOperator}` : never), (keyof Inferred<Order, {}> & string) | (IsGiven<LoaderNotation> extends true ? keyof Row & string : never), IsGiven<Cursor> extends true ? true : IsGiven<Limit>>;
133
+ export type SyncType = "insert" | "update" | "delete";
134
+ export type SyncMessage<Listener> = ExtractListenerDeliveredType<Listener>;
135
+ export type SyncOptions<Row, KeyField extends keyof Row, Listener, Type extends SyncType, Mapped> = {
136
+ type: Type;
137
+ /** Maps a query's filters to listener params or a subscription payload */
138
+ where?: {
139
+ [Field in keyof Row & string]?: {
140
+ eq: (value: Row[Field]) => ListenerPatch;
141
+ };
142
+ };
143
+ /** Listener params that keep one row read by key live, such as a channel per record */
144
+ byKey?: (key: NonNullable<Row[KeyField]>) => ListenerPatch;
145
+ /** Reshapes a message into a row, or into the key and changed fields for `update` */
146
+ row?: (message: SyncMessage<Listener>) => Mapped;
147
+ /** Reads the key of a deleted row from a message */
148
+ key?: (message: SyncMessage<Listener>) => NonNullable<Row[KeyField]>;
149
+ /** Loads the row by key when an `update` arrives for a row the collection does not hold */
150
+ incomplete?: "refetch";
151
+ /** The adapter resumes the subscription from its last event id after a reconnect, so nothing is missed */
152
+ resumes?: boolean;
153
+ };
154
+ export type IsSyncRow<Row, KeyField extends keyof Row, Type extends SyncType, Mapped> = Type extends "insert" ? IsExactRow<Mapped, Row> : Type extends "update" ? IsPartialRow<Mapped, Row, KeyField> : true;
155
+ /** The event a listener callback receives: `data` plus adapter details such as Firestore's grouped changes */
156
+ export type SyncEvent<Listener> = Listener extends {
157
+ listen: (callback: infer Callback, ...rest: any[]) => any;
158
+ } ? Callback extends (event: infer Event) => any ? Event : never : never;
159
+ export type SyncChangesOptions<Row, KeyField extends keyof Row, Listener, Mapped> = {
160
+ /** Reads the complete rows to write and the keys to delete from one event */
161
+ changes: (event: SyncEvent<Listener>) => {
162
+ upsert: readonly Mapped[];
163
+ delete: readonly NonNullable<Row[KeyField]>[];
164
+ /** Rows to load again by key, such as documents that left a filtered query and may have changed or gone */
165
+ refetch?: readonly NonNullable<Row[KeyField]>[];
166
+ };
167
+ /** Turns a subset's sent conditions into listener params, so the sync covers every subset */
168
+ notation?: (conditions: readonly ComparisonNode[]) => ListenerPatch;
169
+ /** Listener params that keep one row read by key live, such as a listener on one document */
170
+ byKey?: (key: NonNullable<Row[KeyField]>) => ListenerPatch;
171
+ /** The adapter resumes the subscription from its last event id after a reconnect, so nothing is missed */
172
+ resumes?: boolean;
173
+ };
174
+ export type IngestType = "insert" | "update";
175
+ export type IngestOptions<Req, Mapped, Type> = {
176
+ /** Reads rows from the response, as a loader's `rows` does */
177
+ rows?: (response: ExtractResponseType<Req>) => readonly Mapped[];
178
+ /** `insert` writes complete rows, `update` changes only rows the collection holds */
179
+ type?: Type & IngestType;
180
+ };
181
+ export type IsIngestRow<Row, KeyField extends keyof Row, Type extends IngestType, Mapped> = Type extends "update" ? IsPartialRow<Mapped, Row, KeyField> : IsExactRow<Mapped, Row>;
182
+ /** What happens after a mutation request succeeds with a response that is not the row */
183
+ export type MutationSuccessMode = "keep" | "refetch" | "sync";
184
+ export type MutationContext = {
185
+ /** The transaction id. Send it as an idempotency key, so a request sent twice is applied once. */
186
+ id: string;
187
+ };
188
+ export type InsertMutation<Row, Req, Mapped, Success> = {
189
+ /** `false` when the backend applies writes locally on its own, such as Firestore, so the db adds no optimistic layer */
190
+ optimistic?: boolean;
191
+ /** `false` when the backend queues writes offline on its own, such as Firestore, so they skip the outbox */
192
+ outbox?: boolean;
193
+ request: Req;
194
+ map: (row: Row, context: MutationContext) => RequestPatch<Req>;
195
+ /** Reads the inserted row from the response */
196
+ row?: (response: ExtractResponseType<Req>) => Mapped;
197
+ /** Needed when the response is not the row */
198
+ onSuccess?: Success & MutationSuccessMode;
199
+ };
200
+ export type UpdateMutation<Row, KeyField extends keyof Row, Req, Mapped, Success> = {
201
+ /** `false` when the backend applies writes locally on its own, such as Firestore, so the db adds no optimistic layer */
202
+ optimistic?: boolean;
203
+ /** `false` when the backend queues writes offline on its own, such as Firestore, so they skip the outbox */
204
+ outbox?: boolean;
205
+ request: Req;
206
+ map: (key: NonNullable<Row[KeyField]>, changes: Partial<Row>, context: MutationContext) => RequestPatch<Req>;
207
+ /** Reads the key and changed fields from the response */
208
+ row?: (response: ExtractResponseType<Req>) => Mapped;
209
+ /** Needed when the response is not the row or its changed fields with the key */
210
+ onSuccess?: Success & MutationSuccessMode;
211
+ };
212
+ export type DeleteMutation<Row, KeyField extends keyof Row, Req> = {
213
+ /** `false` when the backend applies writes locally on its own, such as Firestore, so the db adds no optimistic layer */
214
+ optimistic?: boolean;
215
+ /** `false` when the backend queues writes offline on its own, such as Firestore, so they skip the outbox */
216
+ outbox?: boolean;
217
+ request: Req;
218
+ map: (key: NonNullable<Row[KeyField]>, context: MutationContext) => RequestPatch<Req>;
219
+ onSuccess?: MutationSuccessMode;
220
+ };
221
+ /** Whether a write's success is handled: it is not declared, its response fits, or `onSuccess` says what to do */
222
+ export type IsWriteHandled<Req, Fits, Success> = IsGiven<Req> extends true ? (IsGiven<Success> extends true ? true : Fits) : true;
223
+ /** The writes a collection can make, and the changes `update` accepts */
224
+ export type MutationDescriptor<Input = unknown, Changes = unknown> = {
225
+ insert?: Input;
226
+ update?: Changes;
227
+ delete?: true;
228
+ };
229
+ type PayloadChanges<Row, Req> = NonNullable<ExtractPayloadType<Req>> extends Record<string, unknown> ? Partial<Pick<Row, Extract<keyof Row, keyof NonNullable<ExtractPayloadType<Req>>>>> : Partial<Row>;
230
+ export type DescribeMutations<Input, Row, InsertReq, UpdateReq, DeleteReq> = (IsGiven<InsertReq> extends true ? {
231
+ insert: Input;
232
+ } : {}) & (IsGiven<UpdateReq> extends true ? {
233
+ update: PayloadChanges<Row, UpdateReq>;
234
+ } : {}) & (IsGiven<DeleteReq> extends true ? {
235
+ delete: true;
236
+ } : {});
237
+ export type LoaderConfig = {
238
+ kind: "list" | "byKey" | "byKeys";
239
+ request: RequestInstance;
240
+ rows?: (response: unknown) => readonly unknown[];
241
+ where?: Record<string, Partial<Record<ComparisonOperator, unknown>> & {
242
+ required?: true;
243
+ }>;
244
+ notation?: Notation;
245
+ orderBy?: Record<string, unknown>;
246
+ cursor?: (response: unknown) => unknown;
247
+ page?: (cursor: unknown) => AnyRequestPatch;
248
+ limit?: (limit: number) => AnyRequestPatch;
249
+ fixed?: Record<string, unknown>;
250
+ serverOnly?: readonly string[];
251
+ byKey?: (key: RowKey) => AnyRequestPatch;
252
+ byKeys?: (keys: RowKey[]) => AnyRequestPatch;
253
+ };
254
+ export type SyncConfig = {
255
+ listener: ListenerInstance;
256
+ /** `changes` syncs read inserts and deletes from one event, such as a Firestore snapshot */
257
+ type: SyncType | "changes";
258
+ changes?: (event: unknown) => {
259
+ upsert: readonly unknown[];
260
+ delete: readonly RowKey[];
261
+ refetch?: readonly RowKey[];
262
+ };
263
+ /** Covers every subset by turning its sent conditions into listener params, as adapter presets do */
264
+ notation?: (conditions: readonly ComparisonNode[]) => ListenerPatch;
265
+ where?: Record<string, {
266
+ eq: (value: unknown) => ListenerPatch;
267
+ }>;
268
+ byKey?: (key: RowKey) => ListenerPatch;
269
+ row?: (message: unknown) => unknown;
270
+ key?: (message: unknown) => RowKey;
271
+ incomplete?: "refetch";
272
+ resumes?: boolean;
273
+ };
274
+ export type IngestConfig = {
275
+ request: RequestInstance;
276
+ rows?: (response: unknown) => readonly unknown[];
277
+ type: IngestType;
278
+ };
279
+ export type NormalizeConfig = {
280
+ target: CollectionConfig;
281
+ extract: (row: unknown) => readonly unknown[];
282
+ };
283
+ export type MutationConfig = {
284
+ request: RequestInstance;
285
+ map: (...args: any[]) => AnyRequestPatch;
286
+ row?: (response: unknown) => unknown;
287
+ onSuccess?: MutationSuccessMode;
288
+ optimistic?: boolean;
289
+ outbox?: boolean;
290
+ };
291
+ export type CollectionConfig = {
292
+ schema?: StandardSchemaV1;
293
+ key: string;
294
+ version?: string;
295
+ validate: "client" | "all";
296
+ loaders: readonly LoaderConfig[];
297
+ syncs: readonly SyncConfig[];
298
+ ingests: readonly IngestConfig[];
299
+ mutations: {
300
+ insert?: MutationConfig;
301
+ update?: MutationConfig;
302
+ delete?: MutationConfig;
303
+ };
304
+ /** Nested rows that complete writes carry into other collections */
305
+ normalize?: readonly NormalizeConfig[];
306
+ };
307
+ export type CollectionOptions<Row, KeyField extends string> = {
308
+ /** The field that identifies a row */
309
+ key: KeyField;
310
+ /** A field that grows with every change on the server. Writes never replace fields with a newer version. */
311
+ version?: Exclude<keyof Row & string, KeyField>;
312
+ /** `client` validates client writes only, `all` validates data from the server too */
313
+ validate?: "client" | "all";
314
+ };
315
+ export {};
316
+ //# sourceMappingURL=collection.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.types.d.ts","sourceRoot":"","sources":["../../src/collection/collection.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE3F,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAC;AAE3C,4DAA4D;AAC5D,MAAM,MAAM,UAAU,CAAC,GAAG,IAAI;KAC3B,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK;CACxF,CAAC,MAAM,GAAG,CAAC,GACV,MAAM,CAAC;AAET,MAAM,MAAM,MAA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escriptor, ListLoaderDescriptor, MutationSuccessMode, RequestPatch } from './collection.types';
3
+ type MethodKey = "$get" | "$post" | "$put" | "$patch" | "$delete";
4
+ /** The `$param` segment of an SDK resource that reads one row, such as `$postId` */
5
+ export type SdkItemKey<Node> = {
6
+ [Key in keyof Node & `$${string}`]: Key extends MethodKey ? never : Node[Key] extends {
7
+ $get: RequestInstance;
8
+ } ? Key : never;
9
+ }[keyof Node & `$${string}`];
10
+ type ListRequest<Node> = Node extends {
11
+ $get: infer Req;
12
+ } ? Req : never;
13
+ type EndpointOf<Req> = Req extends {
14
+ endpoint: infer Endpoint extends string;
15
+ } ? Endpoint : string;
16
+ /** Path params of the list endpoint that are row fields. They become required `eq` filters. */
17
+ export type ResourcePathFilters<Row, Node> = Extract<keyof NonNullable<ExtractUrlParams<EndpointOf<ListRequest<Node>>>>, keyof Row> & string;
18
+ /** Query params of the list endpoint that are row fields, which `.resource()` can send as `eq` filters */
19
+ export type ResourceQueryFilters<Row, Node> = Extract<keyof NonNullable<ExtractQueryParamsType<ListRequest<Node>>>, keyof Row> & string;
20
+ export type ResourceListOptions<Row, Node, Mapped, Filters, Cursor> = {
21
+ /** Reads complete rows from the list response */
22
+ rows?: (response: ExtractResponseType<ListRequest<Node>>) => readonly Mapped[];
23
+ /** Query params sent as `eq` filters. Only query params that are row fields of the same name are offered. */
24
+ where?: readonly (Filters & ResourceQueryFilters<Row, Node>)[];
25
+ /** Reads the next page's cursor, which makes the list paginated */
26
+ cursor?: (response: ExtractResponseType<ListRequest<Node>>) => Cursor | null | undefined;
27
+ /** Sends a cursor to load the page after it */
28
+ page?: (cursor: Cursor) => RequestPatch<ListRequest<Node>>;
29
+ };
30
+ export type ResourceOptions<Row, Node, Item, Mapped, Filters, Cursor, InsertSuccess, UpdateSuccess> = {
31
+ /** The segment that reads one row, such as `"$postId"` for `/posts/:postId` */
32
+ item: Item & SdkItemKey<Node>;
33
+ /** The list loader, or `false` when the list returns another shape and belongs to its own collection */
34
+ list?: false | ResourceListOptions<Row, Node, Mapped, Filters, Cursor>;
35
+ insert?: {
36
+ onSuccess?: InsertSuccess & MutationSuccessMode;
37
+ };
38
+ update?: {
39
+ method?: "$patch" | "$put";
40
+ onSuccess?: UpdateSuccess & MutationSuccessMode;
41
+ };
42
+ };
43
+ type ItemNode<Node, Item> = Item extends keyof Node ? Node[Item] : never;
44
+ type UpdateRequestOf<Node, Item> = ItemNode<Node, Item> extends {
45
+ $patch: infer Req;
46
+ } ? Req : ItemNode<Node, Item> extends {
47
+ $put: infer Req;
48
+ } ? Req : never;
49
+ export type ResourceLoaders<Row, Node, Item, Filters, Cursor, ListGiven> = (ListGiven extends true ? ListLoaderDescriptor<ResourcePathFilters<Row, Node>, `${ResourcePathFilters<Row, Node> | (Filters & string)}:eq`, never, unknown extends Cursor ? false : true> : never) | (ItemNode<Node, Item> extends {
50
+ $get: RequestInstance;
51
+ } ? KeyLoaderDescriptor : never);
52
+ /** Whether every derived loader and mutation reads rows that fit the collection */
53
+ export type IsResourceValid<Row, KeyField extends keyof Row, Node, Item, Mapped, ListGiven, InsertSuccess, UpdateSuccess> = [
54
+ ListGiven extends true ? IsExactRow<Inferred<Mapped, DefaultRows<ListRequest<Node>>>, Row> : true,
55
+ ItemNode<Node, Item> extends {
56
+ $get: infer Req;
57
+ } ? IsExactRow<DefaultRows<Req>, Row> : true,
58
+ Node extends {
59
+ $post: infer Req;
60
+ } ? unknown extends InsertSuccess ? IsExactRow<ExtractResponseType<Req>, Row> : true : true,
61
+ [
62
+ UpdateRequestOf<Node, Item>
63
+ ] extends [never] ? true : unknown extends UpdateSuccess ? IsPartialRow<ExtractResponseType<UpdateRequestOf<Node, Item>>, Row, KeyField> : true
64
+ ] extends [true, true, true, true] ? true : false;
65
+ export type ResourceMutations<Input, Row, Node, Item> = (Node extends {
66
+ $post: RequestInstance;
67
+ } ? {
68
+ insert: Input;
69
+ } : {}) & ([UpdateRequestOf<Node, Item>] extends [never] ? {} : {
70
+ update: Partial<Row>;
71
+ }) & (ItemNode<Node, Item> extends {
72
+ $delete: RequestInstance;
73
+ } ? {
74
+ delete: true;
75
+ } : {});
76
+ export {};
77
+ //# sourceMappingURL=resource.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.types.d.ts","sourceRoot":"","sources":["../../src/collection/resource.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAExH,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACb,MAAM,oBAAoB,CAAC;AAE5B,KAAK,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAElE,oFAAoF;AACpF,MAAM,MAAM,UAAU,CAAC,IAAI,IAAI;KAC5B,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,EAAE,GAAG,GAAG,SAAS,SAAS,GACrD,KAAK,GACL,IAAI,CAAC,GAAG,CAAC,SAAS;QAAE,IAAI,EAAE,eAAe,CAAA;KAAE,GACzC,GAAG,GACH,KAAK;CACZ,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,EAAE,CAAC,CAAC;AAE7B,KAAK,WAAW,CAAC,IAAI,IAAI,IAAI,SAAS;IAAE,IAAI,EAAE,MAAM,GAAG,CAAA;CAAE,GAAG,GAAG,GAAG,KAAK,CAAC;AAExE,KAAK,UAAU,CAAC,GAAG,IAAI,GAAG,SAAS;IAAE,QAAQ,EAAE,MAAM,QAAQ,SAAS,MAAM,CAAA;CAAE,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEnG,+FAA+F;AAC/F,MAAM,MAAM,mBAAmB,CAAC,GAAG,EAAE,IAAI,IAAI,OAAO,CAClD,MAAM,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAC,W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AC,IAAI,EAAE,IAAI,CAAC,SAAS;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,GAAG,EAAE,CAAC,CAAC"}
@@ -0,0 +1,98 @@
1
+ import { CollectionConfig, LoaderConfig, RowKey, SortDirection, SyncConfig } from '../collection/collection.types';
2
+ import { ListPlan } from '../query/planner';
3
+ import { QueryDefinition } from '../query/query.types';
4
+ import { Store } from '../store/store';
5
+ import { Row, Stamp } from '../store/store.types';
6
+ import { BaseSubset } from '../subset/base-subset';
7
+ import { KeySubset } from '../subset/key-subset';
8
+ import { ListSubset } from '../subset/list-subset';
9
+ import { SyncSubscription } from '../sync/sync';
10
+ import { DbRuntime } from './db.runtime';
11
+ /** Everything the db keeps for one collection: its rows, loaded subsets, sync subscriptions and ingested requests */
12
+ export declare class CollectionRuntime {
13
+ readonly db: DbRuntime;
14
+ readonly name: string;
15
+ readonly config: CollectionConfig;
16
+ readonly store: Store;
17
+ readonly listSubsets: Map<string, ListSubset>;
18
+ readonly keySubsets: Map<RowKey, KeySubset>;
19
+ readonly subscriptions: Map<string, SyncSubscription>;
20
+ /** Server keys that replaced temporary keys of inserts */
21
+ readonly aliases: Map<RowKey, RowKey>;
22
+ private renderKeys;
23
+ private keyRequests;
24
+ private cleanups;
25
+ constructor(db: DbRuntime, name: string, config: CollectionConfig);
26
+ /** The stable key for rendering a row, which survives swapping a temporary key for the server's */
27
+ getRenderKey: (key: RowKey) => string;
28
+ setRenderKey: (key: RowKey, renderKey: string) => void;
29
+ /** Resolves a temporary insert key to the key the server assigned, when it has */
30
+ resolveKey: (key: RowKey) => RowKey;
31
+ getListSubset: (plan: ListPlan, definition: QueryDefinition) => ListSubset;
32
+ getKeySubset: (key: RowKey, loaderIndex: number) => KeySubset;
33
+ /**
34
+ * Finds a fresh subset whose rows contain every row a query can return, so the query is answered locally. The
35
+ * subset must not be paginated, its sent conditions must all be part of the query's, and its loader's fixed filters
36
+ * must be part of the query loader's.
37
+ */
38
+ findContainingSubset: (plan: ListPlan) => ListSubset | undefined;
39
+ removeSubset: (subset: BaseSubset) => void;
40
+ /** Every subset, list and key */
41
+ getSubsets: () => BaseSubset[];
42
+ /** Whether a subset other than `except`, or a pending write, holds the row */
43
+ isHeldByOthers: (key: RowKey, except?: BaseSubset) => boolean;
44
+ /** The subsets whose rows include the key, which a refetch after a write reloads */
45
+ getSubsetsHolding: (key: RowKey) => BaseSubset[];
46
+ /** Removes rows that no subset and no pending write holds */
47
+ sweep: () => void;
48
+ /** Tells the queries of a subset that its rows or status changed */
49
+ markSubsetChanged: (subset: BaseSubset) => void;
50
+ /** Orders keys by the query's orders, then by the order the loader returned, then by arrival and key */
51
+ createComparator: (orderBy: readonly {
52
+ field: string;
53
+ direction: SortDirection;
54
+ }[], source: ListSubset | undefined) => (left: RowKey, right: RowKey) => number;
55
+ /** Reads the items of a response: the `rows` mapping, or the response itself */
56
+ readItems: (source: Pick<LoaderConfig, "rows">, data: unknown) => unknown[];
57
+ /** Validates rows when the collection validates server data */
58
+ prepareServerRows: (items: unknown[]) => Row[] | Promise<Row[]>;
59
+ /** Writes server rows and returns their keys in order */
60
+ writeServerRows: (rows: Row[], complete: boolean, stamp: Stamp) => RowKey[];
61
+ /** Writes the rows nested in a complete row into the collections that hold them */
62
+ normalize: (row: Row, stamp: Stamp) => void;
63
+ /** Rows of this collection were written: key subsets move to the sync subscriptions their rows' values pick */
64
+ refreshKeySyncs: (keys: Iterable<RowKey>) => void;
65
+ /** Tells paginated subsets about an inserted row, so it can join their loaded range */
66
+ noteInsert: (key: RowKey) => void;
67
+ /** Starts or joins the sync subscriptions that cover a subset */
68
+ subscribeSyncs: (subset: BaseSubset) => SyncSubscription[];
69
+ /**
70
+ * Which subscription of a sync covers a subset, and the listener params it needs.
71
+ *
72
+ * - A sync with `byKey` covers a row read by key with a listener of its own, and with a notation it also covers every
73
+ * list subset with its sent conditions. Without `byKey`, a sync with a notation covers list subsets only, because
74
+ * a listener on the whole collection for one row is wasteful and, on Firestore, billed.
75
+ * - A sync with `where` covers subsets whose values fill every field it declares: the sent `eq` conditions of a list,
76
+ * or the fields of the row a key subset holds, so a post read by key joins its team's subscription.
77
+ */
78
+ private getSyncTarget;
79
+ /** Applies a `changes` event: complete rows to write and keys to delete */
80
+ private applyChanges;
81
+ /** Applies one sync event */
82
+ /** Applies a sync event. A mapping that throws on one event is reported, and the next events still apply. */
83
+ applySyncMessage: (sync: SyncConfig, message: unknown, stamp: Stamp) => void;
84
+ private applySyncEvent;
85
+ /** Loads one row by key without a query, for example for an incomplete sync event */
86
+ fetchByKey: (key: RowKey) => Promise<void>;
87
+ /** Loads a key subset's row, batched with the other keys requested in the same tick */
88
+ loadKey: (subset: KeySubset, waitForWrites?: boolean) => Promise<void>;
89
+ /** Resolves once no write of this collection is in flight */
90
+ mutationsSettled: () => Promise<void>;
91
+ /** Removes every row and resets the loaded subsets, for example on sign-out */
92
+ clear: () => void;
93
+ destroy: () => void;
94
+ private flushKeyRequests;
95
+ private sendKeyRequest;
96
+ private listenToIngest;
97
+ }
98
+ //# sourceMappingURL=collection.runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.runtime.d.ts","sourceRoot":"","sources":["../../src/db/collection.runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAGhB,YAAY,EACZ,MAAM,EACN,aAAa,EACb,UAAU,EACX,MAAM,gCAAgC,CAAC;AAGxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM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