@danxbot/ui 7.5.0 → 7.6.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/index.js +9231 -9190
- package/dist/index.js.map +1 -1
- package/dist/types/lib/reads/optimistic.d.ts +20 -1
- package/dist/types/lib/records/store.d.ts +19 -1
- package/package.json +1 -1
|
@@ -7,6 +7,19 @@ export type OptimisticWriteSpec<T> = {
|
|
|
7
7
|
readonly id: string | number;
|
|
8
8
|
/** Only the fields that change. A present `null` clears; an `undefined` value is ignored. */
|
|
9
9
|
readonly patch: Partial<T>;
|
|
10
|
+
readonly at?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "update";
|
|
13
|
+
readonly type: RecordTypeToken<T>;
|
|
14
|
+
readonly id: string | number;
|
|
15
|
+
/**
|
|
16
|
+
* A field holding a keyed map (`data_points`, `attributes`): `patch` then names KEYS OF
|
|
17
|
+
* THAT MAP, merged over whatever it holds. Use it whenever a write changes one entry of a
|
|
18
|
+
* map — patching the whole field instead would pin every other entry at its value as of
|
|
19
|
+
* the click, and undoing one of two concurrent writes would undo both.
|
|
20
|
+
*/
|
|
21
|
+
readonly at: Extract<keyof T, string>;
|
|
22
|
+
readonly patch: Readonly<Record<string, unknown>>;
|
|
10
23
|
} | {
|
|
11
24
|
readonly kind: "create";
|
|
12
25
|
readonly type: RecordTypeToken<T>;
|
|
@@ -38,6 +51,12 @@ export interface OptimisticWriteOptions<A = unknown> {
|
|
|
38
51
|
* record itself. Default: the result, if it carries `__type` and `id`.
|
|
39
52
|
*/
|
|
40
53
|
readonly answer?: (result: A) => unknown;
|
|
54
|
+
/**
|
|
55
|
+
* The request stores its own answer — an API layer that writes every response into the store,
|
|
56
|
+
* or a caller that normalizes the answer before storing it. Commit then only retires the belief:
|
|
57
|
+
* nothing is written, so the stored answer is exactly what shows.
|
|
58
|
+
*/
|
|
59
|
+
readonly answerStored?: boolean;
|
|
41
60
|
}
|
|
42
61
|
/** An applied write whose request the caller runs itself — `beginOptimisticWrite`'s handle. */
|
|
43
62
|
export interface OptimisticHandle {
|
|
@@ -63,6 +82,6 @@ export declare function optimisticWrite<T, A>(spec: OptimisticWriteSpec<T>, requ
|
|
|
63
82
|
* The same write, for a caller that owns its request lifecycle — apply now, and call `commit`
|
|
64
83
|
* or `rollback` on the handle when the request settles.
|
|
65
84
|
*/
|
|
66
|
-
export declare function beginOptimisticWrite<T>(spec: OptimisticWriteSpec<T>, options?: Pick<OptimisticWriteOptions, "tag" | "tenant">): OptimisticHandle;
|
|
85
|
+
export declare function beginOptimisticWrite<T>(spec: OptimisticWriteSpec<T>, options?: Pick<OptimisticWriteOptions, "tag" | "tenant" | "answerStored">): OptimisticHandle;
|
|
67
86
|
/** Test seam. Nothing in the library calls this. */
|
|
68
87
|
export declare function resetOptimisticWrites(): void;
|
|
@@ -57,6 +57,14 @@ export interface OptimisticLayer {
|
|
|
57
57
|
readonly id: number;
|
|
58
58
|
/** Data fields, stored as given — never normalized, so a patch cannot mint records. */
|
|
59
59
|
fields: Record<string, unknown>;
|
|
60
|
+
/**
|
|
61
|
+
* When set, `fields` are KEYS OF THE MAP held in this one field (a record's `data_points`,
|
|
62
|
+
* say), merged over whatever that map holds beneath — never a replacement of the whole field.
|
|
63
|
+
* Two beliefs about two different keys of one map then stay independent: undoing one leaves the
|
|
64
|
+
* other standing, and a read that rewrites the map underneath still shows through every key no
|
|
65
|
+
* belief is about.
|
|
66
|
+
*/
|
|
67
|
+
readonly at: string | undefined;
|
|
60
68
|
/** An ISO time when this layer is a delete. */
|
|
61
69
|
readonly tombstone: string | undefined;
|
|
62
70
|
/** True when this layer IS the record — an optimistic create with no server row yet. */
|
|
@@ -73,6 +81,7 @@ export interface OptimisticLayer {
|
|
|
73
81
|
*/
|
|
74
82
|
export declare function pushOptimisticLayer(type: string, id: string | number, layer: {
|
|
75
83
|
fields?: Record<string, unknown>;
|
|
84
|
+
at?: string;
|
|
76
85
|
tombstone?: string;
|
|
77
86
|
created?: boolean;
|
|
78
87
|
}): number;
|
|
@@ -86,14 +95,23 @@ export declare function removeOptimisticLayer(key: string, layerId: number): voi
|
|
|
86
95
|
* superseded, whether or not that older request has answered yet. A layer left with nothing to
|
|
87
96
|
* say is dropped. Without this, a set whose answer is still out would keep overlaying a field
|
|
88
97
|
* the server has already confirmed was cleared after it.
|
|
98
|
+
*
|
|
99
|
+
* `at` scopes the trim to beliefs about keys of that one map field — the same granularity the
|
|
100
|
+
* committing write had.
|
|
89
101
|
*/
|
|
90
|
-
export declare function trimOptimisticLayers(key: string, beforeLayerId: number, fields: readonly string[]): void;
|
|
102
|
+
export declare function trimOptimisticLayers(key: string, beforeLayerId: number, fields: readonly string[], at?: string): void;
|
|
91
103
|
/**
|
|
92
104
|
* Whether the BASE is tombstoned — what a list slot prunes on. An optimistic delete hides the
|
|
93
105
|
* row from every read but must not cost the slot its key, or a rollback would bring the record
|
|
94
106
|
* back with no list left holding it.
|
|
95
107
|
*/
|
|
96
108
|
export declare function isBaseTombstoned(key: string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* One field of the BASE, as stored (normalized: a nested record is a `{__ref}`). What a keyed
|
|
111
|
+
* belief is folded into when its write succeeds without an answer to replace it — writing it back
|
|
112
|
+
* through `write()` round-trips the refs untouched.
|
|
113
|
+
*/
|
|
114
|
+
export declare function readBaseField(key: string, field: string): unknown;
|
|
97
115
|
/** Does `key` carry any optimistic layer right now? */
|
|
98
116
|
export declare function hasOptimisticLayers(key: string): boolean;
|
|
99
117
|
/**
|