@xnetjs/data 1.0.0 → 2.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.
@@ -1,4 +1,4 @@
1
- import { e as StoreAuthAPI, f as NodeStoreOptions, g as NodeStorageAdapter, C as CreateNodeOptions, h as NodeState, i as NodeId, G as GetWithMigrationOptions, M as MigratedNodeState, U as UpdateNodeOptions, L as ListNodesOptions, j as NodeQueryDescriptor, k as NodeQueryResult, T as TransactionOperation, l as TransactionResult, m as DeterministicNodeImportDraft, n as ImportDeterministicNodesOptions, o as ImportDeterministicNodesResult, p as NodeBatchWriteInput, q as NodeBatchWriteResult, S as SchemaIRI, r as NodeChange, s as MergeConflict, t as NodeChangeListener, u as NodeBatchChangeListener } from './types-B5rrBwRI.js';
1
+ import { e as StoreAuthAPI, f as NodeStoreOptions, g as NodeStorageAdapter, C as CreateNodeOptions, h as NodeState, i as NodeId, j as CheckedOutDraftOverlay, G as GetWithMigrationOptions, M as MigratedNodeState, U as UpdateNodeOptions, L as ListNodesOptions, k as NodeQueryDescriptor, l as NodeQueryResult, T as TransactionOperation, m as TransactionResult, n as DeterministicNodeImportDraft, o as ImportDeterministicNodesOptions, p as ImportDeterministicNodesResult, q as NodeBatchWriteInput, r as NodeBatchWriteResult, S as SchemaIRI, s as NodeChange, t as MergeConflict, u as NodeChangeListener, v as NodeBatchChangeListener } from './types-C64g-IXg.js';
2
2
 
3
3
  /**
4
4
  * NodeStore - Event-sourced storage for Nodes
@@ -26,6 +26,13 @@ declare class NodeStore {
26
26
  private listeners;
27
27
  private nodeListeners;
28
28
  private batchListeners;
29
+ private checkedOutDraft;
30
+ private cloneToOriginal;
31
+ private draftMemberSet;
32
+ private draftDynamicMembers;
33
+ /** null = conservative "all schemas" (memberSchemaIds omitted). */
34
+ private draftMemberSchemaSet;
35
+ private draftOverlayListeners;
29
36
  private schemaLookup?;
30
37
  private propertyLookup?;
31
38
  private lensRegistry?;
@@ -62,6 +69,54 @@ declare class NodeStore {
62
69
  * Get a Node by ID.
63
70
  */
64
71
  get(id: NodeId): Promise<NodeState | null>;
72
+ /**
73
+ * Read a node WITHOUT the draft overlay (exploration 0329) — merge review
74
+ * and diff surfaces use this to see main's true state while checked out.
75
+ */
76
+ getRaw(id: NodeId): Promise<NodeState | null>;
77
+ /**
78
+ * Check a draft out (or pass null to return to main). While checked out,
79
+ * member reads swap to clone content under original ids, member writes
80
+ * redirect to clones (lazily forking via `onMissingMember`), and clone
81
+ * change events mirror to original-id subscribers.
82
+ */
83
+ setCheckedOutDraft(overlay: CheckedOutDraftOverlay | null): void;
84
+ /** Report a locally-created node to the checkout's draft-born hook (0329 P4). */
85
+ private notifyDraftNodeCreated;
86
+ private notifyDraftOverlayListeners;
87
+ getCheckedOutDraft(): CheckedOutDraftOverlay | null;
88
+ /**
89
+ * Device-local draft privacy (exploration 0329): ids marked here (draft
90
+ * bookkeeping nodes, clones, draft-born nodes) are excluded from outbound
91
+ * sync publication by the personal node-sync room's `shouldPublish`
92
+ * predicate. In-memory only — the draft module rehydrates it from open
93
+ * Draft nodes at boot, BEFORE sync starts.
94
+ */
95
+ private draftPrivateNodeIds;
96
+ markDraftPrivate(ids: readonly NodeId[]): void;
97
+ unmarkDraftPrivate(ids: readonly NodeId[]): void;
98
+ isDraftPrivate(id: NodeId): boolean;
99
+ /** Notified on every checkout change (including clone-map refreshes). */
100
+ subscribeToDraftOverlay(listener: () => void): () => void;
101
+ /**
102
+ * Swap checked-out members' content to their clones (original ids kept, so
103
+ * MV id lists and grid ordering are untouched). No-op without a checkout.
104
+ */
105
+ private overlayStates;
106
+ /**
107
+ * Draft-aware query path (0329 P5): candidates from storage WITHOUT
108
+ * pagination, unioned with checked-out members the predicate may have
109
+ * missed (their clone values can change membership), content-swapped,
110
+ * clone rows hidden, then the full descriptor re-applied in JS so
111
+ * filter/sort/pagination reflect draft values.
112
+ */
113
+ private draftAwareQuery;
114
+ /**
115
+ * Resolve where a write to `id` lands under the checkout: an existing
116
+ * clone, a lazily-forked one (`onMissingMember`), or — for non-members,
117
+ * clone ids, and declined forks — the id itself.
118
+ */
119
+ private resolveDraftWriteTarget;
65
120
  /**
66
121
  * Return the subset of IDs that already exist in materialized storage.
67
122
  *
@@ -231,7 +231,7 @@ interface NodeQueryDescriptor {
231
231
  authFingerprint?: string;
232
232
  }
233
233
  interface NodeQueryPlanMetadata {
234
- strategy: 'storage-query' | 'list-fallback' | 'auth-pushdown-candidates';
234
+ strategy: 'storage-query' | 'list-fallback' | 'auth-pushdown-candidates' | 'draft-overlay';
235
235
  candidateNodeCount: number;
236
236
  hydratedNodeCount: number;
237
237
  returnedNodeCount: number;
@@ -959,6 +959,74 @@ interface NodeStorageAdapter {
959
959
  setAppState?(key: string, value: string): Promise<void>;
960
960
  getDocumentContent(nodeId: NodeId): Promise<Uint8Array | null>;
961
961
  setDocumentContent(nodeId: NodeId, content: Uint8Array): Promise<void>;
962
+ /**
963
+ * Pin registry (exploration 0329): keys pinned here are exempt from history
964
+ * pruning and Yjs snapshot eviction. A key is either a change hash or a
965
+ * `yjs:<nodeId>@<timestamp>` snapshot ref; owners (checkpoints, drafts)
966
+ * release all their pins in one call when they are deleted. Blobs are NOT
967
+ * pinned — referenced blobs past retention are an explicit blob horizon.
968
+ * Optional: without it, pruning behaves as before (nothing is protected).
969
+ */
970
+ pins?: PinRegistry;
971
+ }
972
+ /**
973
+ * Checked-out draft overlay (exploration 0329): while set on a NodeStore,
974
+ * reads of an original member id return its clone's content (under the
975
+ * original id — MV id lists and grid ordering never see clone ids), writes
976
+ * to members redirect to their clones, and the first write to a not-yet-
977
+ * forked member triggers `onMissingMember` (lazy copy-on-write, wired to
978
+ * `forkNodeIntoDraft`). Only ids in `members` are overlay-managed — all
979
+ * other reads/writes pass through untouched, so bookkeeping writes (the
980
+ * draft node itself, profiles, unrelated content) never fork.
981
+ */
982
+ interface CheckedOutDraftOverlay {
983
+ /** The Draft node that owns this checkout. */
984
+ draftId: NodeId;
985
+ /**
986
+ * The draft's declared scope: ids eligible for overlay + lazy COW.
987
+ * `'dynamic'` (agent-PR sessions, 0329 P4) makes EVERY written id a
988
+ * candidate — `onMissingMember` decides per id (never-fork schemas and
989
+ * bookkeeping decline by returning null).
990
+ */
991
+ members: readonly NodeId[] | 'dynamic';
992
+ /** originalId -> cloneId for members already forked. */
993
+ clones: Record<NodeId, NodeId>;
994
+ /**
995
+ * Schema IRIs the members span. Queries against OTHER schemas keep their
996
+ * indexed fast path (nothing to overlay); queries against these take the
997
+ * draft-aware path (clone values drive filter/sort — a JS re-apply over
998
+ * unpaginated candidates, the accepted transient-session cost). Omitted =
999
+ * conservative: every query takes the draft-aware path.
1000
+ */
1001
+ memberSchemaIds?: readonly string[];
1002
+ /**
1003
+ * Lazy copy-on-write: fork `originalId` into the draft and return the
1004
+ * clone id (or null to decline — the write then targets the original).
1005
+ */
1006
+ onMissingMember?: (originalId: NodeId) => Promise<NodeId | null>;
1007
+ /**
1008
+ * Fired when a NEW node is created while this draft is checked out
1009
+ * (draft-born; promoted to a fresh main node on merge). Agent-PR sessions
1010
+ * wire this to `markCreatedInDraft`.
1011
+ */
1012
+ onNodeCreated?: (nodeId: NodeId, schemaId: string) => void;
1013
+ }
1014
+ /** One pinned key: a change hash or a `yjs:`-prefixed snapshot ref. */
1015
+ interface PinEntry {
1016
+ key: string;
1017
+ ownerId: string;
1018
+ reason: string;
1019
+ }
1020
+ /** Pin registry capability on a storage adapter (exploration 0329). */
1021
+ interface PinRegistry {
1022
+ /** Add pins (idempotent per (key, ownerId)). */
1023
+ addPins(pins: readonly PinEntry[]): Promise<void>;
1024
+ /** Release every pin held by an owner (checkpoint/draft deletion). */
1025
+ removePinsByOwner(ownerId: string): Promise<void>;
1026
+ /** Of the given keys, return the subset pinned by any owner. */
1027
+ getPinnedKeysAmong(keys: readonly string[]): Promise<Set<string>>;
1028
+ /** Total number of pins (diagnostics). */
1029
+ countPins(): Promise<number>;
962
1030
  }
963
1031
  interface SetNodeOptions {
964
1032
  /**
@@ -1605,4 +1673,4 @@ type InferNode<P extends Record<string, PropertyBuilder>> = {
1605
1673
  createdBy: DID;
1606
1674
  } & InferProperties<P>;
1607
1675
 
1608
- export { type PropertyKey as $, createNodeId as A, type PropertyType as B, type CreateNodeOptions$1 as C, type DefinedSchema as D, type PropertyDefinition as E, type ValidationError as F, type GetWithMigrationOptions as G, type CreateNodeOptions as H, type InferCreateProps as I, type InferPropertyType as J, type InferProperties as K, type ListNodesOptions as L, type MigratedNodeState as M, type NodeQueryPageCountMode as N, type OfflineAuthPolicy as O, type PropertyBuilder as P, type InferNode as Q, type SchemaLens as R, type SchemaIRI as S, type TransactionOperation as T, type UpdateNodeOptions as U, type ValidationResult as V, type LensOperation as W, type MigrationResult as X, MigrationError as Y, LensRegistry as Z, lensRegistry as _, type Schema as a, type StoreAuthKeyManager as a$, type NodePayload as a0, type PropertyTimestamp as a1, type SetNodeOptions as a2, type ImportNodesOptions as a3, type RebuildNodeIndexesOptions as a4, type ApplyNodeBatchInput as a5, type ApplyNodeBatchResult as a6, type NodeBatchIndexMode as a7, type NodeBatchNotificationMode as a8, type NodeBatchSyncMode as a9, createNodeQueryDescriptor as aA, encodeNodeQueryCursor as aB, decodeNodeQueryCursor as aC, nodeQueryDescriptorToOptions as aD, serializeNodeQueryDescriptor as aE, matchesNodeQueryDescriptor as aF, filterNodeQueryResults as aG, sortNodeQueryResults as aH, applyNodeQueryDescriptor as aI, getNodeQuerySearchTokens as aJ, nodeQueryDescriptorNeedsBoundedReload as aK, withoutNodeQueryPagination as aL, withoutNodeQueryMaterializedView as aM, isTempId as aN, TEMP_ID_PREFIX as aO, resolveTempIds as aP, createSchemaLookup as aQ, type SchemaLookup as aR, type TempIdResolution as aS, StoreAuth as aT, GrantRateLimiter as aU, GRANT_SCHEMA_IRI as aV, isGrantActive as aW, DEFAULT_OFFLINE_POLICY as aX, mergeOfflinePolicy as aY, type StoreAuthOptions as aZ, type StoreAuthStore as a_, type NodeBatchPreflightResult as aa, type DeterministicNodeBatchWriteInput as ab, type NodeBatchWritePolicy as ac, type NodeBatchWriteTimings as ad, type CountNodesOptions as ae, type NodeQuerySpatialPoint as af, type NodeQuerySpatialRect as ag, type NodeQuerySpatialPointFields as ah, type NodeQuerySpatialRectFields as ai, type NodeQuerySpatialWindow as aj, type NodeQuerySpatialRadius as ak, type NodeQuerySpatialFilter as al, type NodeQuerySearchField as am, type NodeQuerySearchFilter as an, type NodeQueryMaterializedViewOptions as ao, type NodeQueryPageOptions as ap, type NodeQueryCursorOrderEntry as aq, type NodeQueryCursor as ar, type NodeQueryOptions as as, type NodeQueryPlanMetadata as at, type NodeQueryParityCheckMetadata as au, type ConflictResult as av, type NodeBatchChangeEvent as aw, type NodeContentCipher as ax, type ContentKeyCache as ay, type MigrationInfo as az, type ParsedSchemaIRI as b, type GrantInput as b0, type Grant as b1, StoreAuthError as b2, type StoreAuthErrorCode as b3, type GrantNode as b4, type GrantIndexStore as b5, type GrantIndexOptions as b6, type RevocationConsistency as b7, type RevocationConfig as b8, type GrantRateLimiterOptions as b9, type DocumentType as ba, DEFAULT_SCHEMA_VERSION as bb, parseSchemaIRI as bc, buildSchemaIRI as bd, normalizeSchemaIRI as be, getBaseSchemaIRI as bf, isSameSchema as bg, getSchemaVersion as bh, type NodeReadAuthorizer as bi, type AuthorizationStateVersion as bj, type OperationNodeBatchWriteInput as bk, type PropertyLookup as bl, createPropertyLookup as bm, type SortDirection as c, type SystemOrderField as d, type StoreAuthAPI as e, type NodeStoreOptions as f, type NodeStorageAdapter as g, type NodeState as h, type NodeId as i, type NodeQueryDescriptor as j, type NodeQueryResult as k, type TransactionResult as l, type DeterministicNodeImportDraft as m, type ImportDeterministicNodesOptions as n, type ImportDeterministicNodesResult as o, type NodeBatchWriteInput as p, type NodeBatchWriteResult as q, type NodeChange as r, type MergeConflict as s, type NodeChangeListener as t, type NodeBatchChangeListener as u, type NodeChangeEvent as v, GrantIndex as w, type Node as x, type DID as y, isNode as z };
1676
+ export { lensRegistry as $, isNode as A, createNodeId as B, type CreateNodeOptions$1 as C, type DefinedSchema as D, type PropertyType as E, type PropertyDefinition as F, type GetWithMigrationOptions as G, type ValidationError as H, type InferCreateProps as I, type CreateNodeOptions as J, type InferPropertyType as K, type ListNodesOptions as L, type MigratedNodeState as M, type NodeQueryPageCountMode as N, type OfflineAuthPolicy as O, type PropertyBuilder as P, type InferProperties as Q, type InferNode as R, type SchemaIRI as S, type TransactionOperation as T, type UpdateNodeOptions as U, type ValidationResult as V, type SchemaLens as W, type LensOperation as X, type MigrationResult as Y, MigrationError as Z, LensRegistry as _, type Schema as a, mergeOfflinePolicy as a$, type PropertyKey as a0, type NodePayload as a1, type PropertyTimestamp as a2, type PinEntry as a3, type PinRegistry as a4, type SetNodeOptions as a5, type ImportNodesOptions as a6, type RebuildNodeIndexesOptions as a7, type ApplyNodeBatchInput as a8, type ApplyNodeBatchResult as a9, type NodeContentCipher as aA, type ContentKeyCache as aB, type MigrationInfo as aC, createNodeQueryDescriptor as aD, encodeNodeQueryCursor as aE, decodeNodeQueryCursor as aF, nodeQueryDescriptorToOptions as aG, serializeNodeQueryDescriptor as aH, matchesNodeQueryDescriptor as aI, filterNodeQueryResults as aJ, sortNodeQueryResults as aK, applyNodeQueryDescriptor as aL, getNodeQuerySearchTokens as aM, nodeQueryDescriptorNeedsBoundedReload as aN, withoutNodeQueryPagination as aO, withoutNodeQueryMaterializedView as aP, isTempId as aQ, TEMP_ID_PREFIX as aR, resolveTempIds as aS, createSchemaLookup as aT, type SchemaLookup as aU, type TempIdResolution as aV, StoreAuth as aW, GrantRateLimiter as aX, GRANT_SCHEMA_IRI as aY, isGrantActive as aZ, DEFAULT_OFFLINE_POLICY as a_, type NodeBatchIndexMode as aa, type NodeBatchNotificationMode as ab, type NodeBatchSyncMode as ac, type NodeBatchPreflightResult as ad, type DeterministicNodeBatchWriteInput as ae, type NodeBatchWritePolicy as af, type NodeBatchWriteTimings as ag, type CountNodesOptions as ah, type NodeQuerySpatialPoint as ai, type NodeQuerySpatialRect as aj, type NodeQuerySpatialPointFields as ak, type NodeQuerySpatialRectFields as al, type NodeQuerySpatialWindow as am, type NodeQuerySpatialRadius as an, type NodeQuerySpatialFilter as ao, type NodeQuerySearchField as ap, type NodeQuerySearchFilter as aq, type NodeQueryMaterializedViewOptions as ar, type NodeQueryPageOptions as as, type NodeQueryCursorOrderEntry as at, type NodeQueryCursor as au, type NodeQueryOptions as av, type NodeQueryPlanMetadata as aw, type NodeQueryParityCheckMetadata as ax, type ConflictResult as ay, type NodeBatchChangeEvent as az, type ParsedSchemaIRI as b, type StoreAuthOptions as b0, type StoreAuthStore as b1, type StoreAuthKeyManager as b2, type GrantInput as b3, type Grant as b4, StoreAuthError as b5, type StoreAuthErrorCode as b6, type GrantNode as b7, type GrantIndexStore as b8, type GrantIndexOptions as b9, type RevocationConsistency as ba, type RevocationConfig as bb, type GrantRateLimiterOptions as bc, type NodeReadAuthorizer as bd, type AuthorizationStateVersion as be, type OperationNodeBatchWriteInput as bf, type PropertyLookup as bg, createPropertyLookup as bh, type DocumentType as bi, DEFAULT_SCHEMA_VERSION as bj, parseSchemaIRI as bk, buildSchemaIRI as bl, normalizeSchemaIRI as bm, getBaseSchemaIRI as bn, isSameSchema as bo, getSchemaVersion as bp, type SortDirection as c, type SystemOrderField as d, type StoreAuthAPI as e, type NodeStoreOptions as f, type NodeStorageAdapter as g, type NodeState as h, type NodeId as i, type CheckedOutDraftOverlay as j, type NodeQueryDescriptor as k, type NodeQueryResult as l, type TransactionResult as m, type DeterministicNodeImportDraft as n, type ImportDeterministicNodesOptions as o, type ImportDeterministicNodesResult as p, type NodeBatchWriteInput as q, type NodeBatchWriteResult as r, type NodeChange as s, type MergeConflict as t, type NodeChangeListener as u, type NodeBatchChangeListener as v, type NodeChangeEvent as w, GrantIndex as x, type Node as y, type DID as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnetjs/data",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,12 +57,12 @@
57
57
  "nanoid": "^5.1.6",
58
58
  "y-protocols": "^1.0.6",
59
59
  "yjs": "^13.6.24",
60
- "@xnetjs/core": "1.0.0",
61
- "@xnetjs/crypto": "1.0.0",
62
- "@xnetjs/identity": "1.0.0",
63
- "@xnetjs/sqlite": "1.0.0",
64
- "@xnetjs/storage": "1.0.0",
65
- "@xnetjs/sync": "1.0.0"
60
+ "@xnetjs/core": "2.0.0",
61
+ "@xnetjs/crypto": "2.0.0",
62
+ "@xnetjs/identity": "2.0.0",
63
+ "@xnetjs/sqlite": "2.0.0",
64
+ "@xnetjs/storage": "2.0.0",
65
+ "@xnetjs/sync": "2.0.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "tsup": "^8.0.0",