@kubun/store-graph 0.10.2 → 0.12.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/lib/api.d.ts +83 -3
- package/lib/api.js +1209 -1
- package/lib/cursor.d.ts +1 -0
- package/lib/cursor.js +7 -1
- package/lib/definition.js +7 -1
- package/lib/errors.d.ts +34 -0
- package/lib/errors.js +45 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +7 -1
- package/lib/migrations.d.ts +13 -0
- package/lib/migrations.js +100 -1
- package/lib/query-builder.d.ts +9 -3
- package/lib/query-builder.js +370 -1
- package/lib/tables.d.ts +43 -0
- package/lib/tables.js +1 -1
- package/package.json +18 -18
package/lib/api.d.ts
CHANGED
|
@@ -12,8 +12,36 @@ export type StoredAccessRule = {
|
|
|
12
12
|
allowedCircles: Array<string> | null;
|
|
13
13
|
allowedGroups: Array<string> | null;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* A single stored access-default row, tagged with the model and permission
|
|
17
|
+
* type it belongs to. Returned by `listUserModelAccessDefaults`, which -
|
|
18
|
+
* unlike `getUserModelAccessDefault` - is not scoped to one (model,
|
|
19
|
+
* permissionType) pair.
|
|
20
|
+
*/
|
|
21
|
+
export type StoredAccessDefaultRow = StoredAccessRule & {
|
|
22
|
+
modelID: string;
|
|
23
|
+
permissionType: 'read' | 'write';
|
|
24
|
+
/**
|
|
25
|
+
* The row's LWW anchor, or null when written without a stamp. Carried here so
|
|
26
|
+
* a caller needing rule + anchor for several models reads one list rather than
|
|
27
|
+
* a `getUserModelAccessDefault` / `getUserModelAccessDefaultHLC` pair each.
|
|
28
|
+
*/
|
|
29
|
+
hlc: string | null;
|
|
30
|
+
};
|
|
15
31
|
export type GraphStoreAPI = {
|
|
16
32
|
getDocument(id: DocumentID | string): Promise<DocumentNode | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Batch fetch documents, returning a Map keyed by the document ID string. A
|
|
35
|
+
* missing id is absent from the map, exactly as `getDocument` returning `null`.
|
|
36
|
+
*
|
|
37
|
+
* Documents live in a per-model table, so the reads are grouped by model and
|
|
38
|
+
* cost one query per DISTINCT model rather than one per id. A model with no
|
|
39
|
+
* table contributes nothing, matching `getDocument`'s behaviour for an id whose
|
|
40
|
+
* model was never deployed. Empty input short-circuits with no SQL.
|
|
41
|
+
*
|
|
42
|
+
* Caller is responsible for deduplicating ids.
|
|
43
|
+
*/
|
|
44
|
+
getDocuments(ids: Array<DocumentID | string>): Promise<Map<string, DocumentNode>>;
|
|
17
45
|
getDocumentModel(id: DocumentModelID | string): Promise<DocumentModel>;
|
|
18
46
|
/**
|
|
19
47
|
* Return the interface model IDs declared by `modelID` from the
|
|
@@ -45,7 +73,8 @@ export type GraphStoreAPI = {
|
|
|
45
73
|
*/
|
|
46
74
|
getMaxMutationHLC(): Promise<string | null>;
|
|
47
75
|
getFieldHLCs(documentID: string): Promise<Record<string, string> | null>;
|
|
48
|
-
|
|
76
|
+
getFieldValues(documentID: string): Promise<Record<string, unknown> | null>;
|
|
77
|
+
updateFieldHLCs(docID: DocumentID, fieldHLCs: Record<string, string>, fieldValues: Record<string, unknown>): Promise<void>;
|
|
49
78
|
listGraphs(): Promise<Array<GraphModel>>;
|
|
50
79
|
createGraph(params: CreateGraphParams): Promise<string>;
|
|
51
80
|
getGraph(id: string): Promise<GraphModelWithRecord | null>;
|
|
@@ -60,7 +89,30 @@ export type GraphStoreAPI = {
|
|
|
60
89
|
updateSearchEntry(modelID: string, documentID: string, data: Record<string, unknown>, fields: Array<string>): Promise<void>;
|
|
61
90
|
removeSearchEntry(modelID: string, documentID: string): Promise<void>;
|
|
62
91
|
searchDocuments(params: SearchDocumentsParams): Promise<Array<SearchDocumentResult>>;
|
|
92
|
+
/** Create an own catalog: stored active (scopes sync) with null provenance. */
|
|
63
93
|
createCatalog(catalog: InsertCatalog): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Insert a discovered catalog as known (not active) with first-discovery
|
|
96
|
+
* provenance. Idempotent on the id: an already-stored catalog is left
|
|
97
|
+
* untouched, so its local `active` flag and first-discovery source columns
|
|
98
|
+
* are never overwritten by a later re-discovery.
|
|
99
|
+
*/
|
|
100
|
+
upsertDiscoveredCatalog(params: {
|
|
101
|
+
catalog: InsertCatalog;
|
|
102
|
+
sourceGroupID: string | null;
|
|
103
|
+
sourceCircleID: string | null;
|
|
104
|
+
}): Promise<void>;
|
|
105
|
+
/** Toggle a catalog's local sync activation. */
|
|
106
|
+
setCatalogActive(id: string, active: boolean): Promise<void>;
|
|
107
|
+
/** Flip several catalogs together — one statement, not one per id. */
|
|
108
|
+
setCatalogsActive(ids: Array<string>, active: boolean): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* All locally-stored catalog rows regardless of owner, optionally filtered by
|
|
111
|
+
* activation state. Backs the viewer's known-catalogs surface.
|
|
112
|
+
*/
|
|
113
|
+
listStoredCatalogs(filter?: {
|
|
114
|
+
active?: boolean;
|
|
115
|
+
}): Promise<Array<Catalog>>;
|
|
64
116
|
getCatalog(id: string): Promise<Catalog | undefined>;
|
|
65
117
|
/**
|
|
66
118
|
* Batch fetch catalogs by ID. Returns a Map keyed by ID; missing IDs are
|
|
@@ -70,7 +122,7 @@ export type GraphStoreAPI = {
|
|
|
70
122
|
* Caller is responsible for deduplicating IDs (e.g. via `Array.from(new Set(...))`).
|
|
71
123
|
*/
|
|
72
124
|
getCatalogs(ids: Array<string>): Promise<Map<string, Catalog>>;
|
|
73
|
-
updateCatalog(id: string, update: Partial<Pick<InsertCatalog, 'name' | 'description' | 'filter_criteria' | 'hlc'>>): Promise<void>;
|
|
125
|
+
updateCatalog(id: string, update: Partial<Pick<InsertCatalog, 'name' | 'description' | 'filter_criteria' | 'hlc' | 'signed_token'>>): Promise<void>;
|
|
74
126
|
deleteCatalog(id: string): Promise<void>;
|
|
75
127
|
listCatalogs(ownerDID: string): Promise<Array<Catalog>>;
|
|
76
128
|
resolveCatalogScope(catalogID: string): Promise<{
|
|
@@ -78,7 +130,22 @@ export type GraphStoreAPI = {
|
|
|
78
130
|
owners: Array<string> | undefined;
|
|
79
131
|
}>;
|
|
80
132
|
registerClusterModels(clusterID: string, entries: Array<InsertClusterModel>): Promise<void>;
|
|
133
|
+
/** A tombstoned (removed) rule reads as absent. */
|
|
81
134
|
getUserModelAccessDefault(ownerDID: string, modelID: string, permissionType: 'read' | 'write'): Promise<StoredAccessRule | null>;
|
|
135
|
+
/**
|
|
136
|
+
* All active stored access-default rows for `ownerDID`, across every model and
|
|
137
|
+
* permission type. Tombstoned (removed) rows are excluded. Bounded by the
|
|
138
|
+
* owner's model count, no pagination.
|
|
139
|
+
*/
|
|
140
|
+
listUserModelAccessDefaults(ownerDID: string): Promise<Array<StoredAccessDefaultRow>>;
|
|
141
|
+
/**
|
|
142
|
+
* The LWW anchor (`hlc`) stamped on a stored rule, or null when the rule is
|
|
143
|
+
* absent or was written without a stamp (a legacy or unsynced local policy).
|
|
144
|
+
* A caller applying a replicated rule reads this to reject an older write.
|
|
145
|
+
* A tombstoned row keeps its anchor: this returns the removal's `hlc` so a
|
|
146
|
+
* stale set arriving after the remove is still rejected.
|
|
147
|
+
*/
|
|
148
|
+
getUserModelAccessDefaultHLC(ownerDID: string, modelID: string, permissionType: 'read' | 'write'): Promise<string | null>;
|
|
82
149
|
setUserModelAccessDefault(params: {
|
|
83
150
|
ownerDID: string;
|
|
84
151
|
modelID: string;
|
|
@@ -87,8 +154,21 @@ export type GraphStoreAPI = {
|
|
|
87
154
|
allowedDIDs: Array<string> | null;
|
|
88
155
|
allowedCircles: Array<string> | null;
|
|
89
156
|
allowedGroups: Array<string> | null;
|
|
157
|
+
/** LWW anchor. Omitted by callers that do not participate in replication. */
|
|
158
|
+
hlc?: string;
|
|
90
159
|
}): Promise<void>;
|
|
91
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Tombstone the given permission types: retain each row with its rule fields
|
|
162
|
+
* nulled, `removed` set, and `hlc` stamped as the LWW anchor. The row is kept
|
|
163
|
+
* (not deleted) so a stale set arriving after the removal is rejected by HLC.
|
|
164
|
+
* A type with no existing row is skipped (nothing to tombstone).
|
|
165
|
+
*/
|
|
166
|
+
removeUserModelAccessDefaults(ownerDID: string, modelID: string, permissionTypes: Array<string>, hlc: string): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Document IDs across every scope, one query per distinct model. Repeating a
|
|
169
|
+
* (model, owner) pair yields its documents once — the result is a set, and the
|
|
170
|
+
* caller builds a Merkle tree from it, where a duplicate would be a defect.
|
|
171
|
+
*/
|
|
92
172
|
getDocumentIDsForScope(scopes: Array<{
|
|
93
173
|
modelID: string;
|
|
94
174
|
ownerDID: string;
|