@byearlybird/starling 0.9.2 → 0.9.3

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.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as StoreAddOptions, c as Collection, d as EncodedRecord, f as EncodedValue, i as Store, l as EncodedDocument, n as Query, o as StoreConfig, r as QueryConfig, s as StoreSetTransaction, t as Plugin, u as processDocument } from "./store-F8qPSj_p.js";
2
- export { type Collection, type EncodedDocument, type EncodedRecord, type EncodedValue, Plugin, Query, QueryConfig, Store, StoreAddOptions, StoreConfig, StoreSetTransaction, processDocument };
1
+ import { a as StoreAddOptions, c as Collection, d as processDocument, f as EncodedRecord, i as Store, l as mergeCollections, n as Query, o as StoreConfig, p as EncodedValue, r as QueryConfig, s as StoreSetTransaction, t as Plugin, u as EncodedDocument } from "./store-bS1Nb57l.js";
2
+ export { type Collection, type EncodedDocument, type EncodedRecord, type EncodedValue, Plugin, Query, QueryConfig, Store, StoreAddOptions, StoreConfig, StoreSetTransaction, mergeCollections, processDocument };
package/dist/index.js CHANGED
@@ -634,4 +634,4 @@ var Store = class {
634
634
  };
635
635
 
636
636
  //#endregion
637
- export { Store, processDocument };
637
+ export { Store, mergeCollections, processDocument };
@@ -1,4 +1,4 @@
1
- import { c as Collection, t as Plugin } from "../../store-F8qPSj_p.js";
1
+ import { c as Collection, t as Plugin } from "../../store-bS1Nb57l.js";
2
2
  import { Storage } from "unstorage";
3
3
 
4
4
  //#region src/plugins/unstorage/plugin.d.ts
@@ -75,6 +75,65 @@ type Collection = {
75
75
  /** Latest eventstamp observed by this collection for clock synchronization */
76
76
  "~eventstamp": string;
77
77
  };
78
+ /**
79
+ * Change tracking information returned by mergeCollections.
80
+ * Categorizes documents by mutation type for hook notifications.
81
+ */
82
+ type CollectionChanges = {
83
+ /** Documents that were newly added (didn't exist before or were previously deleted) */
84
+ added: Map<string, EncodedDocument>;
85
+ /** Documents that were modified (existed before and changed) */
86
+ updated: Map<string, EncodedDocument>;
87
+ /** Documents that were deleted (newly marked with ~deletedAt) */
88
+ deleted: Set<string>;
89
+ };
90
+ /**
91
+ * Result of merging two collections.
92
+ */
93
+ type MergeCollectionsResult = {
94
+ /** The merged collection with updated documents and forwarded clock */
95
+ collection: Collection;
96
+ /** Change tracking for plugin hook notifications */
97
+ changes: CollectionChanges;
98
+ };
99
+ /**
100
+ * Merges two collections using field-level Last-Write-Wins semantics.
101
+ *
102
+ * The merge operation:
103
+ * 1. Forwards the clock to the newest eventstamp from either collection
104
+ * 2. Merges each document pair using field-level LWW (via mergeDocs)
105
+ * 3. Tracks what changed for hook notifications (added/updated/deleted)
106
+ *
107
+ * Deletion is final: once a document is deleted, updates to it are merged into
108
+ * the document's data but don't restore visibility. Only new documents or
109
+ * transitions into the deleted state are tracked.
110
+ *
111
+ * @param into - The base collection to merge into
112
+ * @param from - The source collection to merge from
113
+ * @returns Merged collection and categorized changes
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const into = {
118
+ * "~docs": [{ "~id": "doc1", "~data": {...}, "~deletedAt": null }],
119
+ * "~eventstamp": "2025-01-01T00:00:00.000Z|0001|a1b2"
120
+ * };
121
+ *
122
+ * const from = {
123
+ * "~docs": [
124
+ * { "~id": "doc1", "~data": {...}, "~deletedAt": null }, // updated
125
+ * { "~id": "doc2", "~data": {...}, "~deletedAt": null } // new
126
+ * ],
127
+ * "~eventstamp": "2025-01-01T00:05:00.000Z|0001|c3d4"
128
+ * };
129
+ *
130
+ * const result = mergeCollections(into, from);
131
+ * // result.collection.~eventstamp === "2025-01-01T00:05:00.000Z|0001|c3d4"
132
+ * // result.changes.added has "doc2"
133
+ * // result.changes.updated has "doc1"
134
+ * ```
135
+ */
136
+ declare function mergeCollections(into: Collection, from: Collection): MergeCollectionsResult;
78
137
  //#endregion
79
138
  //#region src/store.d.ts
80
139
  type NotPromise<T> = T extends Promise<any> ? never : T;
@@ -303,4 +362,4 @@ declare class Store<T> {
303
362
  query<U = T>(config: QueryConfig<T, U>): Query<U>;
304
363
  }
305
364
  //#endregion
306
- export { StoreAddOptions as a, Collection as c, EncodedRecord as d, EncodedValue as f, Store as i, EncodedDocument as l, Query as n, StoreConfig as o, QueryConfig as r, StoreSetTransaction as s, Plugin as t, processDocument as u };
365
+ export { StoreAddOptions as a, Collection as c, processDocument as d, EncodedRecord as f, Store as i, mergeCollections as l, Query as n, StoreConfig as o, EncodedValue as p, QueryConfig as r, StoreSetTransaction as s, Plugin as t, EncodedDocument as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byearlybird/starling",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",