@storacha/clawracha 0.0.1 → 0.0.2
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/apply.d.ts +18 -0
- package/dist/handlers/apply.d.ts.map +1 -0
- package/dist/handlers/apply.js +50 -0
- package/dist/handlers/process.d.ts +15 -0
- package/dist/handlers/process.d.ts.map +1 -0
- package/dist/handlers/process.js +82 -0
- package/dist/handlers/remote.d.ts +15 -0
- package/dist/handlers/remote.d.ts.map +1 -0
- package/dist/handlers/remote.js +48 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/mdsync/index.d.ts +45 -0
- package/dist/mdsync/index.d.ts.map +1 -0
- package/dist/mdsync/index.js +365 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +224 -26
- package/dist/sync.d.ts +12 -5
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +82 -157
- package/dist/types/index.d.ts +58 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/utils/client.d.ts +14 -0
- package/dist/utils/client.d.ts.map +1 -0
- package/dist/utils/client.js +38 -0
- package/dist/utils/differ.d.ts +29 -0
- package/dist/utils/differ.d.ts.map +1 -0
- package/dist/utils/differ.js +47 -0
- package/dist/utils/encoder.d.ts +16 -0
- package/dist/utils/encoder.d.ts.map +1 -0
- package/dist/utils/encoder.js +51 -0
- package/dist/utils/tempcar.d.ts +22 -0
- package/dist/utils/tempcar.d.ts.map +1 -0
- package/dist/utils/tempcar.js +44 -0
- package/dist/watcher.d.ts +1 -1
- package/dist/watcher.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import { createReadStream, createWriteStream } from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import * as stream from "node:stream";
|
|
6
|
+
import { CarWriter } from "@ipld/car/writer";
|
|
7
|
+
export const makeTempCar = async () => {
|
|
8
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "sync-clawracha-"));
|
|
9
|
+
const cleanup = async () => await fs.rm(dir, { recursive: true });
|
|
10
|
+
const file = path.join(dir, "blocks.car");
|
|
11
|
+
// CarWriter.createAppender() creates a headerless/rootless CAR
|
|
12
|
+
// which is fine for uploadCAR (the client handles it)
|
|
13
|
+
const { writer, out } = CarWriter.createAppender();
|
|
14
|
+
// Pipe the output to a file
|
|
15
|
+
const fsWriteStream = createWriteStream(file);
|
|
16
|
+
const pipePromise = stream.promises.pipeline(stream.Readable.from(out), fsWriteStream);
|
|
17
|
+
let didWrite = false;
|
|
18
|
+
const put = async (block) => {
|
|
19
|
+
didWrite = true;
|
|
20
|
+
await writer.put({ cid: block.cid, bytes: block.bytes });
|
|
21
|
+
};
|
|
22
|
+
const switchToReadable = async () => {
|
|
23
|
+
try {
|
|
24
|
+
await writer.close();
|
|
25
|
+
await pipePromise;
|
|
26
|
+
if (!didWrite) {
|
|
27
|
+
await cleanup();
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
readable: {
|
|
32
|
+
stream: () => stream.Readable.toWeb(createReadStream(file)),
|
|
33
|
+
},
|
|
34
|
+
cleanup,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
console.error("Error switching to readable:", err);
|
|
39
|
+
await cleanup();
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return { put, switchToReadable, cleanup };
|
|
44
|
+
};
|
package/dist/watcher.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Uses chokidar to watch for file changes and batches them
|
|
5
5
|
* before triggering sync.
|
|
6
6
|
*/
|
|
7
|
-
import type { FileChange, SyncPluginConfig } from "./types.js";
|
|
7
|
+
import type { FileChange, SyncPluginConfig } from "./types/index.js";
|
|
8
8
|
export interface WatcherOptions {
|
|
9
9
|
workspace: string;
|
|
10
10
|
config: SyncPluginConfig;
|
package/dist/watcher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAErE,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAmC;IAClD,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,aAAa,CAA+B;IACpD,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,EAAE,cAAc;IAKnC;;OAEG;IACH,KAAK,IAAI,IAAI;IA+Bb;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B;;OAEG;IACH,OAAO,CAAC,YAAY;IAmBpB;;OAEG;YACW,KAAK;IAanB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAOlC"}
|