@xnetjs/data 0.0.2 → 0.1.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 (139) hide show
  1. package/README.md +112 -0
  2. package/dist/account-MWNCH4GJ.js +12 -0
  3. package/dist/account-ledger-R2GAFJL6.js +38 -0
  4. package/dist/auth/index.d.ts +420 -0
  5. package/dist/auth/index.js +102 -0
  6. package/dist/budget-NN7P35XP.js +12 -0
  7. package/dist/canvas-6WYBNH53.js +10 -0
  8. package/dist/channel-AT3LQF4A.js +12 -0
  9. package/dist/chat-message-DSVO72B3.js +10 -0
  10. package/dist/chunk-2ZNJWIQG.js +84 -0
  11. package/dist/chunk-3J3HILXO.js +46 -0
  12. package/dist/chunk-3RUDVTMH.js +5543 -0
  13. package/dist/chunk-4EYKGTSQ.js +49 -0
  14. package/dist/chunk-53F4PRNC.js +32 -0
  15. package/dist/chunk-5EXHNXPL.js +48 -0
  16. package/dist/{chunk-BQBPA5HS.js → chunk-5HC5NO57.js} +16 -2
  17. package/dist/chunk-6KLGA6IR.js +47 -0
  18. package/dist/chunk-6OMG4I7M.js +41 -0
  19. package/dist/chunk-7PDRDSFH.js +69 -0
  20. package/dist/chunk-BQLQSWKZ.js +232 -0
  21. package/dist/chunk-BY5O6LNC.js +380 -0
  22. package/dist/chunk-DCTRX6II.js +40 -0
  23. package/dist/{chunk-VYR5GPJP.js → chunk-DWEXKD6E.js} +9 -3
  24. package/dist/chunk-EBNMV2VO.js +896 -0
  25. package/dist/chunk-FVEACSKE.js +102 -0
  26. package/dist/chunk-GU6THOAB.js +45 -0
  27. package/dist/chunk-H4GA4BBK.js +75 -0
  28. package/dist/chunk-IJ44LR7N.js +76 -0
  29. package/dist/chunk-J4ANIXIV.js +402 -0
  30. package/dist/chunk-JDFNMFOZ.js +45 -0
  31. package/dist/chunk-K7DOZWWT.js +1811 -0
  32. package/dist/chunk-KQAT4XBL.js +49 -0
  33. package/dist/chunk-KQUALW4O.js +183 -0
  34. package/dist/chunk-LYSWLCOI.js +47 -0
  35. package/dist/chunk-MBTUO3ZL.js +65 -0
  36. package/dist/chunk-NI4FHG2K.js +52 -0
  37. package/dist/chunk-OCMSAKWV.js +78 -0
  38. package/dist/chunk-OGJCRNGE.js +57 -0
  39. package/dist/chunk-OPPHF3TF.js +143 -0
  40. package/dist/{chunk-IDMBCRUC.js → chunk-OSAWNZVM.js} +1 -1
  41. package/dist/chunk-PMUQACPY.js +33 -0
  42. package/dist/chunk-PNESGUH5.js +63 -0
  43. package/dist/chunk-Q3IEGH4B.js +51 -0
  44. package/dist/chunk-QJW5LDP4.js +52 -0
  45. package/dist/chunk-QWFTRZQT.js +142 -0
  46. package/dist/{chunk-SZC345Z2.js → chunk-RL64OJJ5.js} +1025 -1110
  47. package/dist/chunk-S5RP5RKY.js +416 -0
  48. package/dist/chunk-S6U6TCMN.js +722 -0
  49. package/dist/chunk-SVNGSZZA.js +69 -0
  50. package/dist/chunk-T5AZAOG5.js +54 -0
  51. package/dist/chunk-TCTZW4A6.js +42 -0
  52. package/dist/chunk-U64CW73O.js +109 -0
  53. package/dist/chunk-UDWKWTAX.js +6526 -0
  54. package/dist/chunk-UQM3G5A2.js +148 -0
  55. package/dist/chunk-VQ7JHB67.js +57 -0
  56. package/dist/chunk-W7EBL7ZU.js +73 -0
  57. package/dist/chunk-WEPK7SZF.js +65 -0
  58. package/dist/chunk-XHEA5UER.js +75 -0
  59. package/dist/chunk-XMSKJ5PV.js +66 -0
  60. package/dist/chunk-XROI44ZP.js +64 -0
  61. package/dist/chunk-Y3S5SRVM.js +45 -0
  62. package/dist/chunk-YEFKQYKA.js +43 -0
  63. package/dist/chunk-YSUIXD2Y.js +105 -0
  64. package/dist/chunk-ZCOFZY5M.js +70 -0
  65. package/dist/chunk-ZLU4Y3O2.js +50 -0
  66. package/dist/chunk-ZPZ7XDA6.js +54 -0
  67. package/dist/chunk-ZZ6TWKGS.js +40 -0
  68. package/dist/clone-C0Jhk2UN.d.ts +2205 -0
  69. package/dist/comment-QSWYAQVS.js +10 -0
  70. package/dist/crm-L5RYAAF3.js +68 -0
  71. package/dist/dashboard-JMKTTRA7.js +10 -0
  72. package/dist/database/index.d.ts +882 -0
  73. package/dist/database/index.js +523 -0
  74. package/dist/database-GIXSPZJW.js +10 -0
  75. package/dist/database-field-3EPAMZUR.js +10 -0
  76. package/dist/database-row-6Q6TRVE4.js +10 -0
  77. package/dist/database-select-option-BBBJFLLH.js +10 -0
  78. package/dist/database-view-5PLSOBI2.js +10 -0
  79. package/dist/experiment-DOVOZ34Y.js +10 -0
  80. package/dist/external-item-P2E5X7BZ.js +14 -0
  81. package/dist/external-reference-7BSFF6SA.js +8 -0
  82. package/dist/feed-2IXHHP6O.js +12 -0
  83. package/dist/feed-item-DPE6LN7I.js +12 -0
  84. package/dist/folder-6KM3KYD5.js +21 -0
  85. package/dist/game-5AK5XWBR.js +50 -0
  86. package/dist/grant-WTQSNT5A.js +8 -0
  87. package/dist/grant-expiration-cleaner-CY6BcmlR.d.ts +249 -0
  88. package/dist/import-batch-IXBJLQPJ.js +12 -0
  89. package/dist/inbox-state-E5NSVOGP.js +12 -0
  90. package/dist/index.d.ts +224 -4548
  91. package/dist/index.js +2252 -4754
  92. package/dist/map-RG5Y3CPC.js +10 -0
  93. package/dist/media-asset-QTCGLIZA.js +8 -0
  94. package/dist/memory-PNRTMBZO.js +12 -0
  95. package/dist/metric-65SVOX5C.js +10 -0
  96. package/dist/milestone-XEO6ZGDG.js +12 -0
  97. package/dist/moderation-FFHETMRB.js +30 -0
  98. package/dist/observation-2Y3QKUXM.js +10 -0
  99. package/dist/page-2V27JGKJ.js +10 -0
  100. package/dist/posting-GBOSZCMZ.js +12 -0
  101. package/dist/profile-BLLDWIDK.js +8 -0
  102. package/dist/project-CQL5LN26.js +10 -0
  103. package/dist/query-ast-C3m6kZYv.d.ts +226 -0
  104. package/dist/reaction-T2DTJBBV.js +10 -0
  105. package/dist/registry-DunPv__d.d.ts +99 -0
  106. package/dist/saved-view-4R2DBCL3.js +10 -0
  107. package/dist/schema/index.d.ts +6489 -0
  108. package/dist/schema/index.js +677 -0
  109. package/dist/schema-extension-LNRF2YRD.js +18 -0
  110. package/dist/space-IJU24PBH.js +42 -0
  111. package/dist/space-membership-DEUMM7NV.js +14 -0
  112. package/dist/store/index.d.ts +518 -0
  113. package/dist/store/index.js +135 -0
  114. package/dist/store-DtIDjk7c.d.ts +355 -0
  115. package/dist/sync/awareness.d.ts +69 -0
  116. package/dist/sync/awareness.js +20 -0
  117. package/dist/system-ILHCZOVO.js +38 -0
  118. package/dist/tag-SKCHM3U5.js +16 -0
  119. package/dist/task-7AOBP7WC.js +16 -0
  120. package/dist/task-view-NUGKELJP.js +10 -0
  121. package/dist/transaction-ZDSEGDIR.js +12 -0
  122. package/dist/transcription-PSCLDAGX.js +12 -0
  123. package/dist/types-S-BJAKyK.d.ts +1576 -0
  124. package/dist/updates.d.ts +44 -0
  125. package/dist/updates.js +16 -0
  126. package/dist/user-widget-RLY2N46A.js +8 -0
  127. package/dist/view-types-DSde-uT_.d.ts +316 -0
  128. package/package.json +32 -9
  129. package/dist/canvas-HSIKIQFK.js +0 -7
  130. package/dist/chunk-2L5ZUGG5.js +0 -53
  131. package/dist/chunk-4MTS5KAQ.js +0 -22
  132. package/dist/chunk-GZHARFKC.js +0 -25
  133. package/dist/chunk-WKIKJTI2.js +0 -45
  134. package/dist/comment-277JD7DV.js +0 -7
  135. package/dist/database-W3KEHLI3.js +0 -7
  136. package/dist/database-row-3O2QSNZN.js +0 -7
  137. package/dist/grant-QVZ454YC.js +0 -7
  138. package/dist/page-O4WTOIEO.js +0 -7
  139. package/dist/task-SEKAYJH7.js +0 -7
@@ -0,0 +1,14 @@
1
+ import {
2
+ SPACE_MEMBERSHIP_SCHEMA_IRI,
3
+ SpaceMembershipSchema,
4
+ isSpaceRole,
5
+ spaceMembershipId
6
+ } from "./chunk-T5AZAOG5.js";
7
+ import "./chunk-EBNMV2VO.js";
8
+ import "./chunk-RL64OJJ5.js";
9
+ export {
10
+ SPACE_MEMBERSHIP_SCHEMA_IRI,
11
+ SpaceMembershipSchema,
12
+ isSpaceRole,
13
+ spaceMembershipId
14
+ };
@@ -0,0 +1,518 @@
1
+ import { g as NodeStorageAdapter, r as NodeChange, i as NodeId, h as NodeState, aa as NodeBatchPreflightResult, a3 as ImportNodesOptions, a5 as ApplyNodeBatchInput, a6 as ApplyNodeBatchResult, L as ListNodesOptions, ae as CountNodesOptions, a2 as SetNodeOptions, j as NodeQueryDescriptor, k as NodeQueryResult, S as SchemaIRI, a4 as RebuildNodeIndexesOptions, bi as NodeReadAuthorizer, bj as AuthorizationStateVersion } from '../types-S-BJAKyK.js';
2
+ export { av as ConflictResult, ay as ContentKeyCache, C as CreateNodeOptions, ab as DeterministicNodeBatchWriteInput, m as DeterministicNodeImportDraft, G as GetWithMigrationOptions, n as ImportDeterministicNodesOptions, o as ImportDeterministicNodesResult, s as MergeConflict, M as MigratedNodeState, az as MigrationInfo, aw as NodeBatchChangeEvent, u as NodeBatchChangeListener, a7 as NodeBatchIndexMode, a8 as NodeBatchNotificationMode, a9 as NodeBatchSyncMode, p as NodeBatchWriteInput, ac as NodeBatchWritePolicy, q as NodeBatchWriteResult, ad as NodeBatchWriteTimings, v as NodeChangeEvent, t as NodeChangeListener, ax as NodeContentCipher, a0 as NodePayload, ar as NodeQueryCursor, aq as NodeQueryCursorOrderEntry, ao as NodeQueryMaterializedViewOptions, as as NodeQueryOptions, N as NodeQueryPageCountMode, ap as NodeQueryPageOptions, au as NodeQueryParityCheckMetadata, at as NodeQueryPlanMetadata, am as NodeQuerySearchField, an as NodeQuerySearchFilter, al as NodeQuerySpatialFilter, af as NodeQuerySpatialPoint, ah as NodeQuerySpatialPointFields, ak as NodeQuerySpatialRadius, ag as NodeQuerySpatialRect, ai as NodeQuerySpatialRectFields, aj as NodeQuerySpatialWindow, f as NodeStoreOptions, bk as OperationNodeBatchWriteInput, $ as PropertyKey, bl as PropertyLookup, a1 as PropertyTimestamp, aR as SchemaLookup, c as SortDirection, d as SystemOrderField, aO as TEMP_ID_PREFIX, aS as TempIdResolution, T as TransactionOperation, l as TransactionResult, U as UpdateNodeOptions, aI as applyNodeQueryDescriptor, aA as createNodeQueryDescriptor, bm as createPropertyLookup, aQ as createSchemaLookup, aC as decodeNodeQueryCursor, aB as encodeNodeQueryCursor, aG as filterNodeQueryResults, aJ as getNodeQuerySearchTokens, aN as isTempId, aF as matchesNodeQueryDescriptor, aK as nodeQueryDescriptorNeedsBoundedReload, aD as nodeQueryDescriptorToOptions, aP as resolveTempIds, aE as serializeNodeQueryDescriptor, aH as sortNodeQueryResults, aM as withoutNodeQueryMaterializedView, aL as withoutNodeQueryPagination } from '../types-S-BJAKyK.js';
3
+ export { G as QUERY_AST_VERSION, r as QueryAST, n as QueryASTAggregate, A as QueryASTAggregateExecution, m as QueryASTAggregateFunction, y as QueryASTAggregateGroup, x as QueryASTAggregatePlan, z as QueryASTAggregateResult, d as QueryASTComparisonPredicate, e as QueryASTCompoundPredicate, a as QueryASTField, l as QueryASTIncludes, p as QueryASTNodeQuery, s as QueryASTNodeQueryOptions, f as QueryASTNotPredicate, c as QueryASTOperator, h as QueryASTOrderBy, i as QueryASTPage, B as QueryASTPlannerGate, g as QueryASTPredicate, q as QueryASTQuerySet, o as QueryASTQuerySetAggregate, j as QueryASTRelationDirection, k as QueryASTRelationInclude, t as QueryASTRelationIncludeOptions, w as QueryASTRelationIndexRequirement, b as QueryASTSchemaInput, u as QueryASTValidationError, v as QueryASTValidationResult, Q as QueryASTVersion, S as SavedViewDescriptor, F as SavedViewFeedDensity, E as SavedViewFeedLayout, C as SavedViewPresentationHint, D as SavedViewPresentationHintMode, V as and, a3 as avg, N as between, P as contains, a0 as count, a1 as countDistinct, a9 as dashboardQuerySet, Z as defineNodeQueryAST, a8 as defineQuerySetAST, ab as defineSavedViewDescriptor, H as eq, aj as evaluateQueryASTPlannerGate, af as executeQueryASTLoadedAggregates, ag as filterQueryASTLoadedRows, _ as follow, $ as from, ah as getQueryASTRelationIndexRequirements, a6 as groupBy, J as gt, K as gte, a7 as having, O as includesAny, U as isNotNull, T as isNull, L as lt, M as lte, ai as matchesQueryASTLoadedRow, a5 as max, a4 as min, I as neq, X as not, W as or, ae as planQueryASTAggregates, Y as queryOperators, aa as querySetCount, R as startsWith, a2 as sum, ac as validateQueryAST, ad as validateSavedViewDescriptor } from '../query-ast-C3m6kZYv.js';
4
+ export { N as NodeStore } from '../store-DtIDjk7c.js';
5
+ import { AuthAction, DID, AuthDenyReason, AuthDecision, ContentId } from '@xnetjs/core';
6
+ import { SQLiteAdapter, SQLiteOperationStats } from '@xnetjs/sqlite';
7
+ import '@xnetjs/crypto';
8
+ import '@xnetjs/sync';
9
+
10
+ /**
11
+ * Error thrown when a local mutation fails authorization checks.
12
+ */
13
+ declare class PermissionError extends Error {
14
+ readonly code = "PERMISSION_DENIED";
15
+ readonly action: AuthAction;
16
+ readonly nodeId: string;
17
+ readonly subject: DID;
18
+ readonly reasons: AuthDenyReason[];
19
+ readonly roles: string[];
20
+ readonly decision: AuthDecision;
21
+ constructor(decision: AuthDecision);
22
+ }
23
+
24
+ /**
25
+ * In-memory storage adapter for NodeStore.
26
+ *
27
+ * Useful for testing and ephemeral data.
28
+ */
29
+
30
+ /**
31
+ * In-memory implementation of NodeStorageAdapter.
32
+ */
33
+ declare class MemoryNodeStorageAdapter implements NodeStorageAdapter {
34
+ private changes;
35
+ private changesByHash;
36
+ private nodes;
37
+ private documentContentStore;
38
+ private yjsSnapshotStore;
39
+ private lastLamportTime;
40
+ private syncCursors;
41
+ withTransaction<T>(fn: (storage: NodeStorageAdapter) => Promise<T>): Promise<T>;
42
+ appendChange(change: NodeChange): Promise<void>;
43
+ appendChanges(changes: readonly NodeChange[]): Promise<void>;
44
+ getChanges(nodeId: NodeId): Promise<NodeChange[]>;
45
+ getAllChanges(): Promise<NodeChange[]>;
46
+ getChangesSince(sinceLamport: number): Promise<NodeChange[]>;
47
+ getChangeByHash(hash: ContentId): Promise<NodeChange | null>;
48
+ getLastChange(nodeId: NodeId): Promise<NodeChange | null>;
49
+ getLastChangesByNodeId(nodeIds: readonly NodeId[]): Promise<Map<NodeId, NodeChange>>;
50
+ getNode(id: NodeId): Promise<NodeState | null>;
51
+ getNodes(ids: readonly NodeId[]): Promise<NodeState[]>;
52
+ getExistingNodeIds(ids: readonly NodeId[]): Promise<NodeId[]>;
53
+ getBatchPreflight(ids: readonly NodeId[]): Promise<NodeBatchPreflightResult>;
54
+ setNode(node: NodeState): Promise<void>;
55
+ importNodes(nodes: readonly NodeState[], _options?: ImportNodesOptions): Promise<void>;
56
+ applyNodeBatch(input: ApplyNodeBatchInput): Promise<ApplyNodeBatchResult>;
57
+ deleteNode(id: NodeId): Promise<void>;
58
+ listNodes(options?: ListNodesOptions): Promise<NodeState[]>;
59
+ countNodes(options?: CountNodesOptions): Promise<number>;
60
+ getLastLamportTime(): Promise<number>;
61
+ setLastLamportTime(time: number): Promise<void>;
62
+ getSyncCursor(room: string): Promise<number>;
63
+ setSyncCursor(room: string, lamport: number): Promise<void>;
64
+ getDocumentContent(nodeId: NodeId): Promise<Uint8Array | null>;
65
+ setDocumentContent(nodeId: NodeId, content: Uint8Array): Promise<void>;
66
+ saveYjsSnapshot(snapshot: {
67
+ nodeId: NodeId;
68
+ timestamp: number;
69
+ snapshot: Uint8Array;
70
+ docState: Uint8Array;
71
+ byteSize: number;
72
+ }): Promise<void>;
73
+ getYjsSnapshots(nodeId: NodeId): Promise<{
74
+ nodeId: NodeId;
75
+ timestamp: number;
76
+ snapshot: Uint8Array;
77
+ docState: Uint8Array;
78
+ byteSize: number;
79
+ }[]>;
80
+ deleteYjsSnapshots(nodeId: NodeId): Promise<void>;
81
+ /**
82
+ * Clear all data (for testing).
83
+ */
84
+ clear(): void;
85
+ /**
86
+ * Get total change count (for testing).
87
+ */
88
+ getChangeCount(): number;
89
+ /**
90
+ * Get total node count (for testing).
91
+ */
92
+ getNodeCount(): number;
93
+ private createSnapshot;
94
+ private restoreSnapshot;
95
+ }
96
+
97
+ /**
98
+ * SQLite storage adapter for NodeStore.
99
+ *
100
+ * Provides high-performance storage for nodes and changes using SQLite.
101
+ * Works with any SQLiteAdapter implementation (Electron, Web, Expo).
102
+ */
103
+
104
+ interface SQLiteAdaptiveIndexingOptions {
105
+ enabled?: boolean;
106
+ minHits?: number;
107
+ minDurationMs?: number;
108
+ minCandidates?: number;
109
+ maxIndexesPerSchema?: number;
110
+ maxEstimatedBytesPerSchema?: number;
111
+ maxIndexedRowsPerSchema?: number;
112
+ dropUnusedAfterMs?: number;
113
+ }
114
+ interface SQLiteQueryVerificationOptions {
115
+ enabled?: boolean;
116
+ maxNodes?: number;
117
+ logFailures?: boolean;
118
+ }
119
+ interface SQLiteNodeStorageAdapterOptions {
120
+ adaptiveIndexing?: SQLiteAdaptiveIndexingOptions;
121
+ queryVerification?: SQLiteQueryVerificationOptions;
122
+ /**
123
+ * Collect EXPLAIN QUERY PLAN + index inventory per query. Costs extra
124
+ * round trips per query, so it is off unless explicitly enabled or the
125
+ * `xnet:query:debug` localStorage flag is set.
126
+ */
127
+ queryDiagnostics?: boolean;
128
+ /**
129
+ * Hydrate via SQL-side `json_group_object` aggregation — ONE row per node
130
+ * instead of one row per (node × property) — collapsing the boundary
131
+ * payload before it leaves SQLite (exploration 0264, Wave 2). Off by
132
+ * default while the mode is benchmarked; correctness is verified equal by
133
+ * the hydration test suite in both modes.
134
+ */
135
+ aggregatedHydration?: boolean;
136
+ /**
137
+ * Defer maintenance work (adaptive index creation) to an idle scheduler
138
+ * instead of running it inline on the query path. The web app passes a
139
+ * bootSettled-gated scheduler — no background work is free on the single
140
+ * serial SQLite worker (exploration 0260/0264). Default: run inline.
141
+ */
142
+ scheduleMaintenance?: (task: () => Promise<void> | void) => void;
143
+ }
144
+ /**
145
+ * SQLite-backed storage adapter for NodeStore.
146
+ *
147
+ * This adapter provides high-performance storage for nodes and changes
148
+ * using the platform-appropriate SQLite implementation.
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * import { createMemorySQLiteAdapter } from '@xnetjs/sqlite/memory'
153
+ *
154
+ * const sqliteAdapter = await createMemorySQLiteAdapter()
155
+ * const nodeStorage = new SQLiteNodeStorageAdapter(sqliteAdapter)
156
+ *
157
+ * const store = new NodeStore({
158
+ * storage: nodeStorage,
159
+ * authorDID: identity.did,
160
+ * signingKey: identity.signingKey
161
+ * })
162
+ * ```
163
+ */
164
+ declare class SQLiteNodeStorageAdapter implements NodeStorageAdapter {
165
+ private db;
166
+ private stmtCache;
167
+ private adaptiveIndexing;
168
+ private queryVerification;
169
+ private queryDiagnostics;
170
+ /** Hydrate one row per node via json_group_object (0264 Wave 2 flag). */
171
+ private aggregatedHydration;
172
+ /** Idle scheduler for maintenance work (adaptive index creation, 0264). */
173
+ private scheduleMaintenance?;
174
+ private pendingQueryTelemetry;
175
+ private pendingQueryTelemetryHits;
176
+ private adaptiveIndexBudgetColumnsReady;
177
+ private storageCapabilitiesPromise?;
178
+ private spatialTablesState;
179
+ private fullTextSearchTablesState;
180
+ private writeQueue;
181
+ /**
182
+ * Read-authorization filter applied before persisting a materialized view's
183
+ * id list (exploration 0226). Wired by `NodeStore` when an auth evaluator is
184
+ * present; `undefined` means materialized views are computed unauthorized
185
+ * (the trusted single-user case).
186
+ */
187
+ private nodeReadAuthorizer?;
188
+ /** One-time guard: ensure the `auth_fingerprint` column exists on upgraded DBs. */
189
+ private materializationColumnsReady;
190
+ constructor(db: SQLiteAdapter, options?: SQLiteNodeStorageAdapterOptions);
191
+ getSQLiteAdapter(): SQLiteAdapter;
192
+ open(): Promise<void>;
193
+ close(): Promise<void>;
194
+ /**
195
+ * Get or create a prepared statement.
196
+ * Cached statements are reused for better performance.
197
+ */
198
+ private getStatement;
199
+ private enqueueWrite;
200
+ withTransaction<T>(fn: (storage: NodeStorageAdapter) => Promise<T>): Promise<T>;
201
+ private createTransactionStorageAdapter;
202
+ appendChange(change: NodeChange): Promise<void>;
203
+ private appendChangeInternal;
204
+ appendChanges(changes: readonly NodeChange[]): Promise<void>;
205
+ private appendChangesInternal;
206
+ getChanges(nodeId: NodeId): Promise<NodeChange[]>;
207
+ getAllChanges(): Promise<NodeChange[]>;
208
+ getChangesSince(sinceLamport: number): Promise<NodeChange[]>;
209
+ /**
210
+ * Compact the local change log (exploration 0254 / F3): delete only
211
+ * *superseded* history so the OPFS file shrinks (fast cold open) and the
212
+ * outbound-resync slice shrinks (cheap first sync), without affecting reads,
213
+ * outbound sync, hash-chain chaining, or convergence with peers that never
214
+ * compacted.
215
+ *
216
+ * A row is deleted iff ALL of:
217
+ * - `lamport_time < wsafe` — below the confirmed-durable floor, so the hub
218
+ * holds it and it is not part of the unconfirmed outbound tail (K1);
219
+ * - it is NOT a node's hash-chain tip — we keep every row at a node's
220
+ * `MAX(lamport_time)` (the whole tie group), so `getLastChange()` still
221
+ * returns a real tip and the next write's `parentHash`/hash/signature are
222
+ * byte-identical to an uncompacted peer's (K2);
223
+ * - it backs NO currently-winning LWW value — its `(node_id, lamport_time,
224
+ * author)` is not the provenance of any live `node_properties` row (K3).
225
+ *
226
+ * K3 is the load-bearing safety net: because every live projection value keeps
227
+ * its backing row, the retained log still materialises to — and can re-push —
228
+ * the exact current state, so a stranded/rolled-back peer never loses live
229
+ * data. Reads are unaffected (they read the materialized `nodes`/
230
+ * `node_properties`, never the log). Only rows are deleted, never rewritten
231
+ * (the hash + signature are immutable and unforgeable). Runs chunked inside
232
+ * the write lane, yields between chunks, and never throws.
233
+ */
234
+ pruneSupersededChanges(wsafe: number, options?: {
235
+ chunk?: number;
236
+ maxRows?: number;
237
+ }): Promise<{
238
+ deleted: number;
239
+ }>;
240
+ getChangeByHash(hash: ContentId): Promise<NodeChange | null>;
241
+ getLastChange(nodeId: NodeId): Promise<NodeChange | null>;
242
+ getLastChangesByNodeId(nodeIds: readonly NodeId[]): Promise<Map<NodeId, NodeChange>>;
243
+ getNode(id: NodeId): Promise<NodeState | null>;
244
+ getNodes(ids: readonly NodeId[]): Promise<NodeState[]>;
245
+ getExistingNodeIds(ids: readonly NodeId[]): Promise<NodeId[]>;
246
+ getBatchPreflight(ids: readonly NodeId[]): Promise<NodeBatchPreflightResult>;
247
+ setNode(node: NodeState, options?: SetNodeOptions): Promise<void>;
248
+ /**
249
+ * Internal method for setting a node without starting a new transaction.
250
+ * Used by importNodes to avoid nested transactions.
251
+ */
252
+ private _setNodeInternal;
253
+ deleteNode(id: NodeId): Promise<void>;
254
+ private deleteNodeInternal;
255
+ listNodes(options?: ListNodesOptions): Promise<NodeState[]>;
256
+ /**
257
+ * Optimized listNodes using a single JOIN query.
258
+ * Fetches nodes and properties in one query for better performance with large datasets.
259
+ */
260
+ listNodesOptimized(options?: ListNodesOptions): Promise<NodeState[]>;
261
+ countNodes(options?: CountNodesOptions): Promise<number>;
262
+ queryNodes(descriptor: NodeQueryDescriptor): Promise<NodeQueryResult>;
263
+ getLastLamportTime(): Promise<number>;
264
+ setLastLamportTime(time: number): Promise<void>;
265
+ private setLastLamportTimeInternal;
266
+ private syncCursorKey;
267
+ getSyncCursor(room: string): Promise<number>;
268
+ /**
269
+ * The lowest confirmed-durable sync cursor across every node-change room
270
+ * (`MIN` over the persisted `nodeSync:hwm:*` marks), or `null` when no room has
271
+ * ever confirmed. This is the safe compaction floor (exploration 0254): the
272
+ * hub durably holds every change at or below it. Returns `null` — never 0 — so
273
+ * a workspace that has never synced is left untouched.
274
+ */
275
+ getMinConfirmedSyncCursor(): Promise<number | null>;
276
+ setSyncCursor(room: string, lamport: number): Promise<void>;
277
+ /** Namespace app-state keys so they can't collide with sync cursors. */
278
+ private appStateKey;
279
+ getAppState(key: string): Promise<string | null>;
280
+ setAppState(key: string, value: string): Promise<void>;
281
+ getDocumentContent(nodeId: NodeId): Promise<Uint8Array | null>;
282
+ setDocumentContent(nodeId: NodeId, content: Uint8Array): Promise<void>;
283
+ private setDocumentContentInternal;
284
+ /**
285
+ * Save a Yjs snapshot for time travel.
286
+ */
287
+ saveYjsSnapshot(snapshot: {
288
+ nodeId: NodeId;
289
+ timestamp: number;
290
+ snapshot: Uint8Array;
291
+ docState: Uint8Array;
292
+ byteSize: number;
293
+ }): Promise<void>;
294
+ /**
295
+ * Get Yjs snapshots for a node.
296
+ */
297
+ getYjsSnapshots(nodeId: NodeId): Promise<Array<{
298
+ nodeId: NodeId;
299
+ timestamp: number;
300
+ snapshot: Uint8Array;
301
+ docState: Uint8Array;
302
+ byteSize: number;
303
+ }>>;
304
+ /**
305
+ * Delete Yjs snapshots for a node.
306
+ */
307
+ deleteYjsSnapshots(nodeId: NodeId): Promise<void>;
308
+ /**
309
+ * Import multiple nodes in a single transaction.
310
+ * Used for sync and restore operations.
311
+ */
312
+ importNodes(nodes: readonly NodeState[], options?: ImportNodesOptions): Promise<void>;
313
+ applyNodeBatch(input: ApplyNodeBatchInput): Promise<ApplyNodeBatchResult>;
314
+ getOperationStats(): Promise<SQLiteOperationStats | null> | SQLiteOperationStats | null;
315
+ resetOperationStats(): Promise<void> | void;
316
+ private resolveApplyNodeBatchInput;
317
+ private canApplyNodeBatchWithTransactionBatch;
318
+ private canApplyNodeBatchWithTypedAdapterCommand;
319
+ private applyNodeBatchWithTypedAdapterCommand;
320
+ private createSQLiteNodeBatchApplyInput;
321
+ private applyNodeBatchWithTransactionBatch;
322
+ private applyNodeBatchInternal;
323
+ private importNodesInternal;
324
+ private canImportNodesWithTransactionBatch;
325
+ private importNodesWithTransactionBatch;
326
+ private createImportNodeOperations;
327
+ private createImportNodeOperationsForIndexMode;
328
+ private createAppendChangeOperation;
329
+ private createSetLastLamportTimeOperation;
330
+ private createInvalidateMaterializedViewsOperation;
331
+ private createDeleteRemovedPropertiesOperation;
332
+ private createScalarIndexOperations;
333
+ private createFullTextIndexOperations;
334
+ private countScalarIndexRowsForNode;
335
+ private hasSearchableNodeContent;
336
+ private syncTouchedIndexesForNodes;
337
+ /**
338
+ * Refresh the full query-planner statistics (`ANALYZE`). Call after a bulk
339
+ * import: SQLite does not auto-maintain stats, so a large insert leaves the
340
+ * planner "out of sync" and reads can pick full scans over indexes
341
+ * (exploration 0184). Best-effort — never throws into the caller.
342
+ */
343
+ analyze(): Promise<void>;
344
+ /**
345
+ * Incremental planner maintenance (`PRAGMA optimize`) — only ANALYZEs tables
346
+ * whose row counts have drifted. Cheap; safe to call at idle / before close.
347
+ */
348
+ optimize(): Promise<void>;
349
+ rebuildIndexesForSchemas(schemaIds: readonly SchemaIRI[], options?: RebuildNodeIndexesOptions): Promise<void>;
350
+ private rebuildIndexesForSchemasInternal;
351
+ private rebuildScalarIndexesForSchemas;
352
+ private rebuildSpatialIndexesForSchemas;
353
+ private rebuildFullTextIndexesForSchemas;
354
+ /**
355
+ * Rebuild the scalar sidecar from materialized node_properties.
356
+ */
357
+ rebuildScalarIndex(): Promise<{
358
+ nodesScanned: number;
359
+ scalarRowsWritten: number;
360
+ }>;
361
+ /**
362
+ * Import multiple changes in a single transaction.
363
+ */
364
+ importChanges(changes: readonly NodeChange[]): Promise<void>;
365
+ /**
366
+ * Clear all data (for testing or reset).
367
+ */
368
+ clear(): Promise<void>;
369
+ private hydrateJoinedRows;
370
+ private buildHydrateChunkQuery;
371
+ private hydrateNodesByIds;
372
+ /**
373
+ * Aggregated hydrate (exploration 0264, Wave 2): collapse the EAV rows to
374
+ * ONE row per node inside SQL via `json_group_object`, so the boundary
375
+ * ships N rows instead of N × properties. `value` is stored as JSON text
376
+ * in a BLOB — `json(CAST(… AS TEXT))` re-emits it as real JSON inside the
377
+ * aggregate (without the cast/wrap it would double-encode as a string).
378
+ */
379
+ private buildAggregatedHydrateChunkQuery;
380
+ /** Parse one-row-per-node aggregated hydrate results into NodeStates. */
381
+ private hydrateAggregatedRows;
382
+ /**
383
+ * Read (or refresh) a materialized view.
384
+ *
385
+ * A materialized view is a purely LOCAL, DERIVED cache: an ordered list of
386
+ * node ids (membership + order) plus bookkeeping. It is NEVER part of the
387
+ * change log and is NEVER synced — peers each derive their own. It therefore
388
+ * carries no authority and can be rebuilt or dropped at any time (a wiped
389
+ * cache only costs a recompute, never data). Content is re-hydrated from the
390
+ * live `nodes`/`node_properties` tables on every read, so the cache exposes
391
+ * nothing the underlying tables don't already, and a write to the schema
392
+ * (`invalidated_at`) or a grant change (`auth_fingerprint`) forces a
393
+ * re-materialization. See exploration 0226.
394
+ */
395
+ private queryMaterializedView;
396
+ private getMaterializedView;
397
+ /**
398
+ * Ensure the `auth_fingerprint` column exists. Fresh databases get it from
399
+ * the DDL; databases upgraded in place (the runtime applies the full DDL with
400
+ * `CREATE TABLE IF NOT EXISTS`, which cannot add a column) need this guard.
401
+ * Idempotent and memoized (exploration 0226).
402
+ */
403
+ private ensureMaterializationColumns;
404
+ setNodeReadAuthorizer(authorizer: NodeReadAuthorizer | undefined): void;
405
+ /**
406
+ * Reload-stable version of the authorization-relevant control-plane state:
407
+ * grants (`Grant` schema) and per-subject `/sys/authz/` resources. Ordinary
408
+ * data writes do not touch these, so a database's materialized views survive
409
+ * reloads and edits, but any grant change shifts `count`/`maxUpdatedAt` and
410
+ * forces an `'authz-changed'` refresh (exploration 0226).
411
+ */
412
+ getAuthorizationStateVersion(): Promise<AuthorizationStateVersion>;
413
+ private refreshMaterializedView;
414
+ private readMaterializedViewPage;
415
+ private invalidateMaterializedViewsForSchema;
416
+ private clearMaterializedViewRows;
417
+ private deleteRemovedProperties;
418
+ private syncScalarRowsForNode;
419
+ private prepareFullTextSearchQueryPlan;
420
+ private hasFullTextSearchTable;
421
+ private prepareSpatialQueryPlan;
422
+ private ensureSpatialTables;
423
+ private hasSpatialTables;
424
+ private createSpatialIndexConfig;
425
+ private syncSpatialRowsForNode;
426
+ private replaceSpatialRowForConfig;
427
+ private deleteSpatialRowsForNode;
428
+ private deleteSpatialRow;
429
+ private clearSpatialRowsForConfig;
430
+ private clearSpatialRows;
431
+ private buildSpatialIndexKey;
432
+ private getSpatialFieldConfig;
433
+ private getSpatialSearchBounds;
434
+ private getNodeSpatialBounds;
435
+ private getFiniteNumberProperty;
436
+ private toScalarIndexValue;
437
+ private hashScalarValue;
438
+ private stringifyStable;
439
+ private quoteSqlLiteral;
440
+ private quoteSqlIdentifier;
441
+ private recordQueryTelemetry;
442
+ /**
443
+ * Flush buffered query telemetry aggregates into
444
+ * `query_descriptor_stats`. Runs automatically every
445
+ * {@link QUERY_TELEMETRY_FLUSH_THRESHOLD} queries and on close; callers
446
+ * that need durable stats immediately (tests, diagnostics tooling) can
447
+ * invoke it directly.
448
+ */
449
+ flushQueryTelemetry(): Promise<void>;
450
+ private writeQueryTelemetryRow;
451
+ private isQueryDiagnosticsEnabled;
452
+ private collectCompiledQueryDiagnostics;
453
+ private getStorageCapabilities;
454
+ private debugQueryPlan;
455
+ private isQueryDebugEnabled;
456
+ private auditQueryParity;
457
+ private getNodeParityCandidates;
458
+ private compareQueryResults;
459
+ private shouldCreateAdaptiveIndexes;
460
+ private ensureAdaptiveIndexes;
461
+ private ensureAdaptiveIndexBudgetColumns;
462
+ private estimateAdaptiveIndexBudget;
463
+ private getAdaptiveIndexValueBytesExpression;
464
+ private makeAdaptiveIndexBudgetRoom;
465
+ private pruneAdaptiveIndexes;
466
+ private getAdaptiveIndexBudgetUsage;
467
+ private dropLeastUsefulAdaptiveIndex;
468
+ private dropAdaptiveIndex;
469
+ private debugAdaptiveIndex;
470
+ private buildProtectedIndexFilter;
471
+ private buildAdaptiveIndexName;
472
+ private buildAdaptiveIndexDDL;
473
+ private getAdaptiveIndexColumns;
474
+ private countCompiledNodeQuery;
475
+ private compileNodeQuery;
476
+ /**
477
+ * A custom-property sort can push down when it is the descriptor's ONLY
478
+ * order key and no cursor/spatial/search accelerator is in play. Gated on
479
+ * the adaptive-indexing flag: the typed partial indexes on
480
+ * `node_property_scalars` make the join+order cheap, and the flag keeps
481
+ * the behavioural change opt-in while it soaks (exploration 0264).
482
+ */
483
+ private resolvePropertySortPushdown;
484
+ private compileSqlQuery;
485
+ private getCompiledPostFilterReason;
486
+ private appendScalarPredicate;
487
+ /**
488
+ * ORDER BY for a pushed-down custom-property sort (0264). Mirrors the JS
489
+ * comparator in `applyNodeQueryDescriptor`: missing properties sort last
490
+ * ascending / first descending; typed value columns carry the order (for a
491
+ * homogeneous property exactly one is non-NULL). `n.id` breaks ties so the
492
+ * page boundary is a total order.
493
+ */
494
+ private buildPropertySortOrderBy;
495
+ private buildSqlOrderBy;
496
+ private hasOnlySystemOrdering;
497
+ private serializePayload;
498
+ private deserializePayload;
499
+ private serializeValue;
500
+ private deserializeValue;
501
+ private deserializeChange;
502
+ }
503
+ /**
504
+ * Create a SQLiteNodeStorageAdapter from an existing SQLiteAdapter.
505
+ * Use this when you want to share the SQLite connection with other services.
506
+ *
507
+ * @example
508
+ * ```typescript
509
+ * import { createMemorySQLiteAdapter } from '@xnetjs/sqlite/memory'
510
+ * import { createNodeStorageAdapter } from '@xnetjs/data'
511
+ *
512
+ * const db = await createMemorySQLiteAdapter()
513
+ * const storage = createNodeStorageAdapter(db)
514
+ * ```
515
+ */
516
+ declare function createNodeStorageAdapter(db: SQLiteAdapter, options?: SQLiteNodeStorageAdapterOptions): SQLiteNodeStorageAdapter;
517
+
518
+ export { ApplyNodeBatchInput, ApplyNodeBatchResult, CountNodesOptions, ImportNodesOptions, ListNodesOptions, MemoryNodeStorageAdapter, NodeBatchPreflightResult, NodeChange, NodeId, NodeQueryDescriptor, NodeQueryResult, NodeState, NodeStorageAdapter, PermissionError, RebuildNodeIndexesOptions, type SQLiteAdaptiveIndexingOptions, SQLiteNodeStorageAdapter, type SQLiteNodeStorageAdapterOptions, type SQLiteQueryVerificationOptions, SetNodeOptions, createNodeStorageAdapter };
@@ -0,0 +1,135 @@
1
+ import {
2
+ MemoryNodeStorageAdapter,
3
+ NodeStore,
4
+ PermissionError,
5
+ QUERY_AST_VERSION,
6
+ SQLiteNodeStorageAdapter,
7
+ TEMP_ID_PREFIX,
8
+ and,
9
+ avg,
10
+ between,
11
+ contains,
12
+ count,
13
+ countDistinct,
14
+ createNodeStorageAdapter,
15
+ createPropertyLookup,
16
+ createSchemaLookup,
17
+ dashboardQuerySet,
18
+ defineNodeQueryAST,
19
+ defineQuerySetAST,
20
+ defineSavedViewDescriptor,
21
+ eq,
22
+ evaluateQueryASTPlannerGate,
23
+ executeQueryASTLoadedAggregates,
24
+ filterQueryASTLoadedRows,
25
+ follow,
26
+ from,
27
+ getQueryASTRelationIndexRequirements,
28
+ groupBy,
29
+ gt,
30
+ gte,
31
+ having,
32
+ includesAny,
33
+ isNotNull,
34
+ isNull,
35
+ isTempId,
36
+ lt,
37
+ lte,
38
+ matchesQueryASTLoadedRow,
39
+ max,
40
+ min,
41
+ neq,
42
+ not,
43
+ or,
44
+ planQueryASTAggregates,
45
+ queryOperators,
46
+ querySetCount,
47
+ resolveTempIds,
48
+ startsWith,
49
+ sum,
50
+ validateQueryAST,
51
+ validateSavedViewDescriptor
52
+ } from "../chunk-UDWKWTAX.js";
53
+ import {
54
+ applyNodeQueryDescriptor,
55
+ createNodeQueryDescriptor,
56
+ decodeNodeQueryCursor,
57
+ encodeNodeQueryCursor,
58
+ filterNodeQueryResults,
59
+ getNodeQuerySearchTokens,
60
+ matchesNodeQueryDescriptor,
61
+ nodeQueryDescriptorNeedsBoundedReload,
62
+ nodeQueryDescriptorToOptions,
63
+ serializeNodeQueryDescriptor,
64
+ sortNodeQueryResults,
65
+ withoutNodeQueryMaterializedView,
66
+ withoutNodeQueryPagination
67
+ } from "../chunk-S5RP5RKY.js";
68
+ import "../chunk-BY5O6LNC.js";
69
+ import "../chunk-EBNMV2VO.js";
70
+ import "../chunk-RL64OJJ5.js";
71
+ export {
72
+ MemoryNodeStorageAdapter,
73
+ NodeStore,
74
+ PermissionError,
75
+ QUERY_AST_VERSION,
76
+ SQLiteNodeStorageAdapter,
77
+ TEMP_ID_PREFIX,
78
+ and,
79
+ applyNodeQueryDescriptor,
80
+ avg,
81
+ between,
82
+ contains,
83
+ count,
84
+ countDistinct,
85
+ createNodeQueryDescriptor,
86
+ createNodeStorageAdapter,
87
+ createPropertyLookup,
88
+ createSchemaLookup,
89
+ dashboardQuerySet,
90
+ decodeNodeQueryCursor,
91
+ defineNodeQueryAST,
92
+ defineQuerySetAST,
93
+ defineSavedViewDescriptor,
94
+ encodeNodeQueryCursor,
95
+ eq,
96
+ evaluateQueryASTPlannerGate,
97
+ executeQueryASTLoadedAggregates,
98
+ filterNodeQueryResults,
99
+ filterQueryASTLoadedRows,
100
+ follow,
101
+ from,
102
+ getNodeQuerySearchTokens,
103
+ getQueryASTRelationIndexRequirements,
104
+ groupBy,
105
+ gt,
106
+ gte,
107
+ having,
108
+ includesAny,
109
+ isNotNull,
110
+ isNull,
111
+ isTempId,
112
+ lt,
113
+ lte,
114
+ matchesNodeQueryDescriptor,
115
+ matchesQueryASTLoadedRow,
116
+ max,
117
+ min,
118
+ neq,
119
+ nodeQueryDescriptorNeedsBoundedReload,
120
+ nodeQueryDescriptorToOptions,
121
+ not,
122
+ or,
123
+ planQueryASTAggregates,
124
+ queryOperators,
125
+ querySetCount,
126
+ resolveTempIds,
127
+ serializeNodeQueryDescriptor,
128
+ sortNodeQueryResults,
129
+ startsWith,
130
+ sum,
131
+ validateQueryAST,
132
+ validateSavedViewDescriptor,
133
+ withoutNodeQueryMaterializedView,
134
+ withoutNodeQueryPagination
135
+ };