@storacha/clawracha 0.3.14 → 0.3.15
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/handlers/process.d.ts +2 -1
- package/dist/handlers/process.d.ts.map +1 -1
- package/dist/handlers/process.js +2 -2
- package/dist/mdsync/index.d.ts +1 -1
- package/dist/mdsync/index.d.ts.map +1 -1
- package/dist/mdsync/index.js +11 -5
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +4 -1
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* When encryptionConfig is provided (private spaces), content is encrypted
|
|
8
8
|
* before upload via encryptToBlockStream.
|
|
9
9
|
*/
|
|
10
|
+
import { CID } from "multiformats/cid";
|
|
10
11
|
import type { BlockFetcher, ValueView } from "@storacha/ucn/pail/api";
|
|
11
12
|
import type { Block } from "multiformats";
|
|
12
13
|
import type { FileChange, PailOp } from "../types/index.js";
|
|
@@ -15,5 +16,5 @@ import type { EncryptionConfig } from "@storacha/encrypt-upload-client/types";
|
|
|
15
16
|
export type BlockSink = (block: Block) => Promise<void>;
|
|
16
17
|
/** Callback to persist a block to the local blockstore for future reads. */
|
|
17
18
|
export type BlockStore = (block: Block) => Promise<void>;
|
|
18
|
-
export declare function processChanges(changes: FileChange[], workspace: string, current: ValueView | null, blocks: BlockFetcher, sink: BlockSink, store?: BlockStore, encryptionConfig?: EncryptionConfig): Promise<PailOp[]>;
|
|
19
|
+
export declare function processChanges(changes: FileChange[], workspace: string, current: ValueView | null, blocks: BlockFetcher, sink: BlockSink, store?: BlockStore, encryptionConfig?: EncryptionConfig, decrypt?: (cid: CID) => Promise<Uint8Array>): Promise<PailOp[]>;
|
|
19
20
|
//# sourceMappingURL=process.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/handlers/process.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/handlers/process.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvC,OAAO,KAAK,EACV,YAAY,EAEZ,SAAS,EACV,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAO9E,8DAA8D;AAC9D,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAExD,4EAA4E;AAC5E,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAqBzD,wBAAsB,cAAc,CAClC,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,SAAS,GAAG,IAAI,EACzB,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,SAAS,EACf,KAAK,CAAC,EAAE,UAAU,EAClB,gBAAgB,CAAC,EAAE,gBAAgB,EACnC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,CAAC,GAC1C,OAAO,CAAC,MAAM,EAAE,CAAC,CA6GnB"}
|
package/dist/handlers/process.js
CHANGED
|
@@ -29,7 +29,7 @@ async function drainBlockStream(stream, sink) {
|
|
|
29
29
|
throw new Error("Empty block stream");
|
|
30
30
|
return root;
|
|
31
31
|
}
|
|
32
|
-
export async function processChanges(changes, workspace, current, blocks, sink, store, encryptionConfig) {
|
|
32
|
+
export async function processChanges(changes, workspace, current, blocks, sink, store, encryptionConfig, decrypt) {
|
|
33
33
|
const pendingOps = [];
|
|
34
34
|
const mdChanges = changes.filter((c) => isMarkdown(c.path));
|
|
35
35
|
const regularChanges = changes.filter((c) => !isMarkdown(c.path));
|
|
@@ -81,7 +81,7 @@ export async function processChanges(changes, workspace, current, blocks, sink,
|
|
|
81
81
|
for (const change of mdPuts) {
|
|
82
82
|
const content = await fs.readFile(path.join(workspace, change.path), "utf-8");
|
|
83
83
|
const block = current
|
|
84
|
-
? await mdsync.put(blocks, current, change.path, content)
|
|
84
|
+
? await mdsync.put(blocks, current, change.path, content, decrypt)
|
|
85
85
|
: await mdsync.v0Put(content);
|
|
86
86
|
if (!block) {
|
|
87
87
|
continue; // No change detected, skip writing a new entry.
|
package/dist/mdsync/index.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ export declare const v0Put: (newMarkdown: string) => Promise<Block>;
|
|
|
78
78
|
* Returns a single block to store, or null if no changes detected.
|
|
79
79
|
* Caller is responsible for creating the Pail revision via Revision.put.
|
|
80
80
|
*/
|
|
81
|
-
export declare const put: (blocks: BlockFetcher, current: ValueView, key: string, newMarkdown: string) => Promise<Block | null>;
|
|
81
|
+
export declare const put: (blocks: BlockFetcher, current: ValueView, key: string, newMarkdown: string, decrypt?: (cid: CID) => Promise<Uint8Array>) => Promise<Block | null>;
|
|
82
82
|
/**
|
|
83
83
|
* Get the current markdown string for a key, resolving concurrent heads.
|
|
84
84
|
* Returns undefined if the key doesn't exist.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mdsync/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EACL,YAAY,EACZ,SAAS,EAET,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAEL,GAAG,EAGH,WAAW,EACX,YAAY,EAUb,MAAM,oBAAoB,CAAC;AAQ5B;;;;;;;;GAQG;AACH,cAAM,aAAa;IAC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AC1E,SAAS,EAAE,YAAY,CAAC,aAAa,CAAC,CAAC;CACxC;AAED,KAAK,yBAAyB,GAC1B,gCAAgC,GAChC,+BAA+B,CAAC;AA8BpC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,yBAAyB,KAC/B,OAAO,CAAC,KAAK,CAcf,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAU,OAAO;IAC/C,KAAK,EAAE,UAAU,CAAC;CACnB,KAAG,OAAO,CAAC,yBAAyB,CA+BpC,CAAC;AA0BF;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,KAAK,CAG9D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,GAAG,GACd,QAAQ,YAAY,EACpB,SAAS,SAAS,EAClB,KAAK,MAAM,EACX,aAAa,MAAM,EACnB,UAAU,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,CAAC,KAC1C,OAAO,CAAC,KAAK,GAAG,IAAI,CAiCtB,CAAC;AAsJF;;;GAGG;AACH,eAAO,MAAM,GAAG,GACd,QAAQ,YAAY,EACpB,SAAS,SAAS,EAClB,KAAK,MAAM,EACX,UAAU,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,CAAC,KAC1C,OAAO,CAAC,MAAM,GAAG,SAAS,CAM5B,CAAC"}
|
package/dist/mdsync/index.js
CHANGED
|
@@ -152,8 +152,8 @@ export const v0Put = async (newMarkdown) => {
|
|
|
152
152
|
* Returns a single block to store, or null if no changes detected.
|
|
153
153
|
* Caller is responsible for creating the Pail revision via Revision.put.
|
|
154
154
|
*/
|
|
155
|
-
export const put = async (blocks, current, key, newMarkdown) => {
|
|
156
|
-
const mdEntry = await resolveValue(blocks, current, key);
|
|
155
|
+
export const put = async (blocks, current, key, newMarkdown, decrypt) => {
|
|
156
|
+
const mdEntry = await resolveValue(blocks, current, key, decrypt);
|
|
157
157
|
if (!mdEntry) {
|
|
158
158
|
// Key doesn't exist yet — bootstrap with firstPut.
|
|
159
159
|
const entry = firstPut(newMarkdown, current.revision.map((r) => r.event.cid));
|
|
@@ -207,7 +207,9 @@ const resolveValue = async (blocks, current, key, decrypt) => {
|
|
|
207
207
|
};
|
|
208
208
|
// Fast path: single head, no merge needed.
|
|
209
209
|
if (current.revision.length === 1) {
|
|
210
|
-
return decodeMarkdownEntry({
|
|
210
|
+
return decodeMarkdownEntry({
|
|
211
|
+
bytes: await getEntryBytes(mdEntryBlockCid),
|
|
212
|
+
});
|
|
211
213
|
}
|
|
212
214
|
// Multi-head: find common ancestor and replay events in causal order.
|
|
213
215
|
const ancestor = await CRDT.findCommonAncestor(events, current.revision.map((r) => r.event.cid));
|
|
@@ -220,7 +222,9 @@ const resolveValue = async (blocks, current, key, decrypt) => {
|
|
|
220
222
|
const rootMDEntryCid = await Pail.get(blocks, root, key);
|
|
221
223
|
let mdEntry;
|
|
222
224
|
if (rootMDEntryCid) {
|
|
223
|
-
mdEntry = await decodeMarkdownEntry({
|
|
225
|
+
mdEntry = await decodeMarkdownEntry({
|
|
226
|
+
bytes: await getEntryBytes(rootMDEntryCid),
|
|
227
|
+
});
|
|
224
228
|
}
|
|
225
229
|
// Get all events from ancestor → heads, sorted in deterministic causal order.
|
|
226
230
|
const sorted = await CRDT.findSortedEvents(events, current.revision.map((r) => r.event.cid), ancestor);
|
|
@@ -254,7 +258,9 @@ const resolveValue = async (blocks, current, key, decrypt) => {
|
|
|
254
258
|
if (!mdEntryCid) {
|
|
255
259
|
throw new Error(`Could not find markdown entry for CID ${data.root} and key ${key}`);
|
|
256
260
|
}
|
|
257
|
-
const newMDEntry = await decodeMarkdownEntry({
|
|
261
|
+
const newMDEntry = await decodeMarkdownEntry({
|
|
262
|
+
bytes: await getEntryBytes(mdEntryCid),
|
|
263
|
+
});
|
|
258
264
|
if (newMDEntry.type === "initial") {
|
|
259
265
|
if (mdEntry) {
|
|
260
266
|
// Concurrent initial — merge event histories and RGA trees.
|
package/dist/sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAEV,YAAY,EACb,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA6BxE,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,KAAK,CAAiD;IAC9D,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,gBAAgB,CAAC,CAAmB;IAC5C,OAAO,CAAC,gBAAgB,CAAC,CAAmB;IAC5C,OAAO,CAAC,eAAe,CAAC,CAAkB;gBAE9B,SAAS,EAAE,MAAM;IAK7B;;;OAGG;IACG,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAoE/C;;OAEG;IACH,OAAO,CAAC,cAAc;IAOtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;;OAGG;IACG,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAEV,YAAY,EACb,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA6BxE,qBAAa,UAAU;IACrB,OAAO,CAAC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QAC5D,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IAkBI,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC;IAW5B,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;YAM5B,WAAW;CAK1B"}
|
package/dist/sync.js
CHANGED
|
@@ -118,10 +118,13 @@ export class SyncEngine {
|
|
|
118
118
|
* Can be called even when not running (accumulates pending ops).
|
|
119
119
|
*/
|
|
120
120
|
async processChanges(changes) {
|
|
121
|
+
const { name } = this.requireInitialized();
|
|
121
122
|
if (!this.carFile) {
|
|
122
123
|
this.carFile = await makeTempCar();
|
|
123
124
|
}
|
|
124
|
-
const pendingOps = await processChanges(changes, this.workspace, this.current, this.blocks, (block) => this.carFile.put(block), (block) => this.blocks.put(block), this.encryptionConfig
|
|
125
|
+
const pendingOps = await processChanges(changes, this.workspace, this.current, this.blocks, (block) => this.carFile.put(block), (block) => this.blocks.put(block), this.encryptionConfig, this.decryptionConfig && this.encryptedClient
|
|
126
|
+
? makeDecryptFn(this.encryptedClient, this.decryptionConfig, name.agent)
|
|
127
|
+
: undefined);
|
|
125
128
|
this.pendingOps.push(...pendingOps);
|
|
126
129
|
}
|
|
127
130
|
/**
|