pushwork 2.0.0-preview.6 → 2.0.0-preview.8
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/branches.d.ts +1 -2
- package/dist/branches.d.ts.map +1 -1
- package/dist/branches.js +4 -23
- package/dist/branches.js.map +1 -1
- package/dist/cli/commands.d.ts +71 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +794 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +19 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli.js +56 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands.d.ts +58 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +975 -0
- package/dist/commands.js.map +1 -0
- package/dist/config/index.d.ts +71 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +314 -0
- package/dist/config/index.js.map +1 -0
- package/dist/core/change-detection.d.ts +80 -0
- package/dist/core/change-detection.d.ts.map +1 -0
- package/dist/core/change-detection.js +560 -0
- package/dist/core/change-detection.js.map +1 -0
- package/dist/core/config.d.ts +81 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +304 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +22 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/move-detection.d.ts +34 -0
- package/dist/core/move-detection.d.ts.map +1 -0
- package/dist/core/move-detection.js +128 -0
- package/dist/core/move-detection.js.map +1 -0
- package/dist/core/snapshot.d.ts +105 -0
- package/dist/core/snapshot.d.ts.map +1 -0
- package/dist/core/snapshot.js +254 -0
- package/dist/core/snapshot.js.map +1 -0
- package/dist/core/sync-engine.d.ts +177 -0
- package/dist/core/sync-engine.d.ts.map +1 -0
- package/dist/core/sync-engine.js +1471 -0
- package/dist/core/sync-engine.js.map +1 -0
- package/dist/pushwork.d.ts +4 -0
- package/dist/pushwork.d.ts.map +1 -1
- package/dist/pushwork.js +74 -2
- package/dist/pushwork.js.map +1 -1
- package/dist/stash.d.ts +0 -2
- package/dist/stash.d.ts.map +1 -1
- package/dist/stash.js +0 -1
- package/dist/stash.js.map +1 -1
- package/dist/types/config.d.ts +102 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +10 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/documents.d.ts +88 -0
- package/dist/types/documents.d.ts.map +1 -0
- package/dist/types/documents.js +23 -0
- package/dist/types/documents.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +20 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/snapshot.d.ts +64 -0
- package/dist/types/snapshot.d.ts.map +1 -0
- package/dist/types/snapshot.js +3 -0
- package/dist/types/snapshot.js.map +1 -0
- package/dist/utils/content-similarity.d.ts +53 -0
- package/dist/utils/content-similarity.d.ts.map +1 -0
- package/dist/utils/content-similarity.js +155 -0
- package/dist/utils/content-similarity.js.map +1 -0
- package/dist/utils/content.d.ts +10 -0
- package/dist/utils/content.d.ts.map +1 -0
- package/dist/utils/content.js +35 -0
- package/dist/utils/content.js.map +1 -0
- package/dist/utils/directory.d.ts +24 -0
- package/dist/utils/directory.d.ts.map +1 -0
- package/dist/utils/directory.js +56 -0
- package/dist/utils/directory.js.map +1 -0
- package/dist/utils/fs.d.ts +74 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +298 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/mime-types.d.ts +13 -0
- package/dist/utils/mime-types.d.ts.map +1 -0
- package/dist/utils/mime-types.js +247 -0
- package/dist/utils/mime-types.js.map +1 -0
- package/dist/utils/network-sync.d.ts +30 -0
- package/dist/utils/network-sync.d.ts.map +1 -0
- package/dist/utils/network-sync.js +391 -0
- package/dist/utils/network-sync.js.map +1 -0
- package/dist/utils/node-polyfills.d.ts +9 -0
- package/dist/utils/node-polyfills.d.ts.map +1 -0
- package/dist/utils/node-polyfills.js +9 -0
- package/dist/utils/node-polyfills.js.map +1 -0
- package/dist/utils/output.d.ts +129 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +375 -0
- package/dist/utils/output.js.map +1 -0
- package/dist/utils/repo-factory.d.ts +15 -0
- package/dist/utils/repo-factory.d.ts.map +1 -0
- package/dist/utils/repo-factory.js +156 -0
- package/dist/utils/repo-factory.js.map +1 -0
- package/dist/utils/string-similarity.d.ts +14 -0
- package/dist/utils/string-similarity.d.ts.map +1 -0
- package/dist/utils/string-similarity.js +43 -0
- package/dist/utils/string-similarity.js.map +1 -0
- package/dist/utils/text-diff.d.ts +37 -0
- package/dist/utils/text-diff.d.ts.map +1 -0
- package/dist/utils/text-diff.js +131 -0
- package/dist/utils/text-diff.js.map +1 -0
- package/dist/utils/trace.d.ts +19 -0
- package/dist/utils/trace.d.ts.map +1 -0
- package/dist/utils/trace.js +68 -0
- package/dist/utils/trace.js.map +1 -0
- package/package.json +5 -5
- package/dist/checkpoints.d.ts +0 -41
- package/dist/checkpoints.d.ts.map +0 -1
- package/dist/checkpoints.js +0 -210
- package/dist/checkpoints.js.map +0 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createRepo = createRepo;
|
|
37
|
+
const automerge_repo_storage_nodefs_1 = require("@automerge/automerge-repo-storage-nodefs");
|
|
38
|
+
const fs = __importStar(require("fs/promises"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
/**
|
|
41
|
+
* Perform a real ESM dynamic import that tsc won't rewrite to require().
|
|
42
|
+
*
|
|
43
|
+
* TypeScript with `"module": "commonjs"` compiles `await import("x")` to
|
|
44
|
+
* `require("x")`, which resolves CJS entries instead of ESM entries. The
|
|
45
|
+
* Wasm module instance is different between the CJS and ESM module graphs,
|
|
46
|
+
* so initializing via CJS require() doesn't help the ESM /slim imports
|
|
47
|
+
* inside automerge-repo.
|
|
48
|
+
*
|
|
49
|
+
* This helper uses `new Function` to create a real `import()` expression
|
|
50
|
+
* that Node.js evaluates as ESM, sharing the same module graph as the
|
|
51
|
+
* Repo's internal imports.
|
|
52
|
+
*/
|
|
53
|
+
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
54
|
+
/**
|
|
55
|
+
* Initialize the Subduction Wasm module and return the Repo constructor.
|
|
56
|
+
*
|
|
57
|
+
* The Repo constructor calls set_subduction_logger() and new MemorySigner()
|
|
58
|
+
* from @automerge/automerge-subduction/slim, which require the Wasm module
|
|
59
|
+
* to be initialized first. automerge-repo exports initSubduction() to
|
|
60
|
+
* handle this — it dynamically imports the non-/slim entry (which
|
|
61
|
+
* auto-initializes the Wasm as a side effect).
|
|
62
|
+
*
|
|
63
|
+
* Both the Repo and initSubduction must be loaded via ESM dynamic import()
|
|
64
|
+
* so they share the same module graph as the Repo's internal /slim imports.
|
|
65
|
+
*/
|
|
66
|
+
let cachedRepoClass;
|
|
67
|
+
async function getRepoClass() {
|
|
68
|
+
if (cachedRepoClass)
|
|
69
|
+
return cachedRepoClass;
|
|
70
|
+
// Import Repo and initialize Subduction Wasm via automerge-repo's
|
|
71
|
+
// initSubduction() helper. This must happen before new Repo() because
|
|
72
|
+
// the constructor calls set_subduction_logger() and new MemorySigner()
|
|
73
|
+
// which require the Wasm module to be ready.
|
|
74
|
+
//
|
|
75
|
+
// Both imports use the ESM dynamic import wrapper so they share the
|
|
76
|
+
// same module graph as the Repo's internal /slim imports.
|
|
77
|
+
const repoMod = await dynamicImport("@automerge/automerge-repo");
|
|
78
|
+
await repoMod.initSubduction();
|
|
79
|
+
cachedRepoClass = repoMod.Repo;
|
|
80
|
+
return cachedRepoClass;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Scan a directory tree for 0-byte files, which indicate incomplete writes
|
|
84
|
+
* from a previous run (process exited before storage flushed). Returns true
|
|
85
|
+
* if any are found.
|
|
86
|
+
*/
|
|
87
|
+
async function hasCorruptStorage(dir) {
|
|
88
|
+
try {
|
|
89
|
+
await fs.access(dir);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
95
|
+
for (const entry of entries) {
|
|
96
|
+
const fullPath = path.join(dir, entry.name);
|
|
97
|
+
if (entry.isDirectory()) {
|
|
98
|
+
if (await hasCorruptStorage(fullPath))
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
else if (entry.isFile()) {
|
|
102
|
+
const stat = await fs.stat(fullPath);
|
|
103
|
+
if (stat.size === 0)
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create an Automerge repository with configuration-based setup.
|
|
111
|
+
*
|
|
112
|
+
* When `sub` is true, uses the Subduction sync backend built into
|
|
113
|
+
* automerge-repo. The Repo manages its own SubductionSource internally —
|
|
114
|
+
* we just pass `subductionWebsocketEndpoints` and the Repo handles
|
|
115
|
+
* connection management, sync, and retries.
|
|
116
|
+
*
|
|
117
|
+
* When `sub` is false (default), uses the traditional WebSocket network
|
|
118
|
+
* adapter for sync via the automerge sync server.
|
|
119
|
+
*/
|
|
120
|
+
async function createRepo(workingDir, config, sub = false) {
|
|
121
|
+
const RepoClass = await getRepoClass();
|
|
122
|
+
const syncToolDir = path.join(workingDir, ".pushwork");
|
|
123
|
+
const automergeDir = path.join(syncToolDir, "automerge");
|
|
124
|
+
// Detect and recover from corrupt local storage (0-byte files left by
|
|
125
|
+
// incomplete writes from a previous run). Wipe the cache so the Repo
|
|
126
|
+
// hydrates cleanly from the sync server.
|
|
127
|
+
if (await hasCorruptStorage(automergeDir)) {
|
|
128
|
+
console.warn("[pushwork] Corrupt local storage detected, clearing cache...");
|
|
129
|
+
await fs.rm(automergeDir, { recursive: true, force: true });
|
|
130
|
+
await fs.mkdir(automergeDir, { recursive: true });
|
|
131
|
+
}
|
|
132
|
+
const storage = new automerge_repo_storage_nodefs_1.NodeFSStorageAdapter(automergeDir);
|
|
133
|
+
if (sub) {
|
|
134
|
+
const endpoints = [];
|
|
135
|
+
if (config.sync_enabled && config.sync_server) {
|
|
136
|
+
endpoints.push(config.sync_server);
|
|
137
|
+
}
|
|
138
|
+
return new RepoClass({ storage, subductionWebsocketEndpoints: endpoints });
|
|
139
|
+
}
|
|
140
|
+
// Default: WebSocket sync adapter
|
|
141
|
+
const repoConfig = { storage };
|
|
142
|
+
if (config.sync_enabled && config.sync_server) {
|
|
143
|
+
// Load the WebSocket adapter via ESM dynamic import to stay in the
|
|
144
|
+
// same module graph as the Repo.
|
|
145
|
+
const wsMod = await dynamicImport("@automerge/automerge-repo-network-websocket");
|
|
146
|
+
// The websocket adapter package (subduction.8) hasn't updated its
|
|
147
|
+
// NetworkAdapter base-class types to match the repo's new
|
|
148
|
+
// NetworkAdapterInterface (which added state() and stricter
|
|
149
|
+
// EventEmitter generics). At runtime the adapter has all required
|
|
150
|
+
// methods; this is purely a declaration mismatch.
|
|
151
|
+
const networkAdapter = new wsMod.BrowserWebSocketClientAdapter(config.sync_server);
|
|
152
|
+
repoConfig.network = [networkAdapter];
|
|
153
|
+
}
|
|
154
|
+
return new RepoClass(repoConfig);
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=repo-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-factory.js","sourceRoot":"","sources":["../../src/utils/repo-factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,gCAmDC;AA3ID,4FAA6E;AAC7E,gDAAiC;AACjC,2CAA4B;AAG5B;;;;;;;;;;;;GAYG;AACH,MAAM,aAAa,GAAG,IAAI,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAEzD,CAAA;AAEjB;;;;;;;;;;;G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AkE;QAClE,0DAA0D;QAC1D,4DAA4D;QAC5D,kEAAkE;QAClE,kDAAkD;QAClD,MAAM,cAAc,GAAG,IAAI,KAAK,CAAC,6BAA6B,CAC7D,MAAM,CAAC,WAAW,CACoB,CAAA;QACvC,UAAU,CAAC,OAAO,GAAG,CAAC,cAAc,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
|
|
3
|
+
* Calculate similarity between two strings
|
|
4
|
+
|
|
5
|
+
* @param {string} str1 First string to match
|
|
6
|
+
* @param {string} str2 Second string to match
|
|
7
|
+
* @param {number} [substringLength=2] Optional. Length of substring to be used in calculating similarity. Default 2.
|
|
8
|
+
* @param {boolean} [caseSensitive=false] Optional. Whether you want to consider case in string matching. Default false;
|
|
9
|
+
|
|
10
|
+
* @returns Number between 0 and 1, with 0 being a low match score.
|
|
11
|
+
|
|
12
|
+
*/
|
|
13
|
+
export declare const stringSimilarity: (str1: string, str2: string, substringLength?: number, caseSensitive?: boolean) => number;
|
|
14
|
+
//# sourceMappingURL=string-similarity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-similarity.d.ts","sourceRoot":"","sources":["../../src/utils/string-similarity.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,MAAM,EACZ,MAAM,MAAM,EACZ,kBAAiB,MAAU,EAC3B,gBAAe,OAAe,WAkC/B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Based on the Sørensen–Dice coefficient, code from https://github.com/stephenjjbrown/string-similarity-js */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.stringSimilarity = void 0;
|
|
5
|
+
/**
|
|
6
|
+
|
|
7
|
+
* Calculate similarity between two strings
|
|
8
|
+
|
|
9
|
+
* @param {string} str1 First string to match
|
|
10
|
+
* @param {string} str2 Second string to match
|
|
11
|
+
* @param {number} [substringLength=2] Optional. Length of substring to be used in calculating similarity. Default 2.
|
|
12
|
+
* @param {boolean} [caseSensitive=false] Optional. Whether you want to consider case in string matching. Default false;
|
|
13
|
+
|
|
14
|
+
* @returns Number between 0 and 1, with 0 being a low match score.
|
|
15
|
+
|
|
16
|
+
*/
|
|
17
|
+
const stringSimilarity = (str1, str2, substringLength = 2, caseSensitive = false) => {
|
|
18
|
+
if (str1 === str2)
|
|
19
|
+
return 1;
|
|
20
|
+
if (!caseSensitive) {
|
|
21
|
+
str1 = str1.toLowerCase();
|
|
22
|
+
str2 = str2.toLowerCase();
|
|
23
|
+
}
|
|
24
|
+
if (str1.length < substringLength || str2.length < substringLength)
|
|
25
|
+
return 0;
|
|
26
|
+
const map = new Map();
|
|
27
|
+
for (let i = 0; i < str1.length - (substringLength - 1); i++) {
|
|
28
|
+
const substr1 = str1.substring(i, i + substringLength);
|
|
29
|
+
map.set(substr1, map.has(substr1) ? map.get(substr1) + 1 : 1);
|
|
30
|
+
}
|
|
31
|
+
let match = 0;
|
|
32
|
+
for (let j = 0; j < str2.length - (substringLength - 1); j++) {
|
|
33
|
+
const substr2 = str2.substring(j, j + substringLength);
|
|
34
|
+
const count = map.has(substr2) ? map.get(substr2) : 0;
|
|
35
|
+
if (count > 0) {
|
|
36
|
+
map.set(substr2, count - 1);
|
|
37
|
+
match++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return (match * 2) / (str1.length + str2.length - (substringLength - 1) * 2);
|
|
41
|
+
};
|
|
42
|
+
exports.stringSimilarity = stringSimilarity;
|
|
43
|
+
//# sourceMappingURL=string-similarity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-similarity.js","sourceRoot":"","sources":["../../src/utils/string-similarity.ts"],"names":[],"mappings":";AAAA,8GAA8G;;;AAE9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AC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtD,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACd,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YAE5B,KAAK,EAAE,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,eAAe,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/E,CAAC,CAAC;AAtCW,QAAA,gBAAgB,oBAsC3B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as A from "@automerge/automerge";
|
|
2
|
+
/**
|
|
3
|
+
* Read content from an Automerge document, normalizing legacy ImmutableString
|
|
4
|
+
* values to plain strings for backwards compatibility.
|
|
5
|
+
*
|
|
6
|
+
* Old documents may store text as ImmutableString. This helper ensures callers
|
|
7
|
+
* always get back `string | Uint8Array | null`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readDocContent(content: unknown): string | Uint8Array | null;
|
|
10
|
+
/**
|
|
11
|
+
* Update text content on an Automerge document property inside a change
|
|
12
|
+
* callback.
|
|
13
|
+
*
|
|
14
|
+
* If the existing value is already a collaborative text string, we diff and
|
|
15
|
+
* splice for minimal CRDT operations. If the existing value is a legacy
|
|
16
|
+
* ImmutableString we can't splice into it, so we assign the whole string
|
|
17
|
+
* which converts the field to a collaborative text CRDT going forward.
|
|
18
|
+
*
|
|
19
|
+
* @param doc - The mutable Automerge document (inside a change callback)
|
|
20
|
+
* @param path - Property path to the text field, e.g. ["content"]
|
|
21
|
+
* @param newContent - The desired new text value
|
|
22
|
+
*/
|
|
23
|
+
export declare function updateTextContent(doc: any, path: A.Prop[], newContent: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Apply a text diff between oldContent and newContent as Automerge splice
|
|
26
|
+
* operations on the given document property path.
|
|
27
|
+
*
|
|
28
|
+
* This preserves the collaborative text CRDT structure by making minimal
|
|
29
|
+
* character-level edits rather than replacing the entire string.
|
|
30
|
+
*
|
|
31
|
+
* @param doc - The Automerge document (inside a change callback)
|
|
32
|
+
* @param path - The property path to the text field, e.g. ["content"]
|
|
33
|
+
* @param oldContent - The previous text content
|
|
34
|
+
* @param newContent - The desired new text content
|
|
35
|
+
*/
|
|
36
|
+
export declare function spliceText(doc: any, path: A.Prop[], oldContent: string, newContent: string): void;
|
|
37
|
+
//# sourceMappingURL=text-diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-diff.d.ts","sourceRoot":"","sources":["../../src/utils/text-diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,sBAAsB,CAAA;AAGzC;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,CAO3E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EACd,UAAU,EAAE,MAAM,GAChB,IAAI,CAeN;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACzB,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EACd,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GAChB,IAAI,CA8BN"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.readDocContent = readDocContent;
|
|
37
|
+
exports.updateTextContent = updateTextContent;
|
|
38
|
+
exports.spliceText = spliceText;
|
|
39
|
+
const A = __importStar(require("@automerge/automerge"));
|
|
40
|
+
const diffLib = __importStar(require("diff"));
|
|
41
|
+
/**
|
|
42
|
+
* Read content from an Automerge document, normalizing legacy ImmutableString
|
|
43
|
+
* values to plain strings for backwards compatibility.
|
|
44
|
+
*
|
|
45
|
+
* Old documents may store text as ImmutableString. This helper ensures callers
|
|
46
|
+
* always get back `string | Uint8Array | null`.
|
|
47
|
+
*/
|
|
48
|
+
function readDocContent(content) {
|
|
49
|
+
if (content == null)
|
|
50
|
+
return null;
|
|
51
|
+
if (typeof content === "string")
|
|
52
|
+
return content;
|
|
53
|
+
if (content instanceof Uint8Array)
|
|
54
|
+
return content;
|
|
55
|
+
// Legacy ImmutableString — convert to plain string
|
|
56
|
+
if (A.isImmutableString(content))
|
|
57
|
+
return content.toString();
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Update text content on an Automerge document property inside a change
|
|
62
|
+
* callback.
|
|
63
|
+
*
|
|
64
|
+
* If the existing value is already a collaborative text string, we diff and
|
|
65
|
+
* splice for minimal CRDT operations. If the existing value is a legacy
|
|
66
|
+
* ImmutableString we can't splice into it, so we assign the whole string
|
|
67
|
+
* which converts the field to a collaborative text CRDT going forward.
|
|
68
|
+
*
|
|
69
|
+
* @param doc - The mutable Automerge document (inside a change callback)
|
|
70
|
+
* @param path - Property path to the text field, e.g. ["content"]
|
|
71
|
+
* @param newContent - The desired new text value
|
|
72
|
+
*/
|
|
73
|
+
function updateTextContent(doc, path, newContent) {
|
|
74
|
+
const target = path.reduce((obj, key) => obj?.[key], doc);
|
|
75
|
+
if (typeof target === "string") {
|
|
76
|
+
// Already a collaborative text string — diff and splice
|
|
77
|
+
spliceText(doc, path, target, newContent);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Legacy ImmutableString, undefined, or other — assign directly.
|
|
81
|
+
// This converts the field to a collaborative text CRDT.
|
|
82
|
+
let obj = doc;
|
|
83
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
84
|
+
obj = obj[path[i]];
|
|
85
|
+
}
|
|
86
|
+
obj[path[path.length - 1]] = newContent;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Apply a text diff between oldContent and newContent as Automerge splice
|
|
91
|
+
* operations on the given document property path.
|
|
92
|
+
*
|
|
93
|
+
* This preserves the collaborative text CRDT structure by making minimal
|
|
94
|
+
* character-level edits rather than replacing the entire string.
|
|
95
|
+
*
|
|
96
|
+
* @param doc - The Automerge document (inside a change callback)
|
|
97
|
+
* @param path - The property path to the text field, e.g. ["content"]
|
|
98
|
+
* @param oldContent - The previous text content
|
|
99
|
+
* @param newContent - The desired new text content
|
|
100
|
+
*/
|
|
101
|
+
function spliceText(doc, path, oldContent, newContent) {
|
|
102
|
+
if (oldContent === newContent)
|
|
103
|
+
return;
|
|
104
|
+
// Fast path: if old is empty, just insert everything
|
|
105
|
+
if (oldContent === "") {
|
|
106
|
+
A.splice(doc, path, 0, 0, newContent);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// Fast path: if new is empty, just delete everything
|
|
110
|
+
if (newContent === "") {
|
|
111
|
+
A.splice(doc, path, 0, oldContent.length);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const changes = diffLib.diffChars(oldContent, newContent);
|
|
115
|
+
let pos = 0;
|
|
116
|
+
for (const part of changes) {
|
|
117
|
+
if (part.removed) {
|
|
118
|
+
A.splice(doc, path, pos, part.value.length);
|
|
119
|
+
// Don't advance pos — text shifted left after deletion
|
|
120
|
+
}
|
|
121
|
+
else if (part.added) {
|
|
122
|
+
A.splice(doc, path, pos, 0, part.value);
|
|
123
|
+
pos += part.value.length;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// Unchanged text — just advance the cursor
|
|
127
|
+
pos += part.value.length;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=text-diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-diff.js","sourceRoot":"","sources":["../../src/utils/text-diff.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,wCAOC;AAeD,8CAmBC;AAcD,gCAmCC;AApGD,wDAAyC;AACzC,8CAA+B;AAE/B;;;;;;GAMG;AACH,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AM;IAErC,qDAAqD;IACrD,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;QACvB,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,CAAA;QACrC,OAAM;IACP,CAAC;IAED,qDAAqD;IACrD,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;QACvB,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;QACzC,OAAM;IACP,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;IAEzD,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YAC3C,uDAAuD;QACxD,CAAC;aAAM,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACvB,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;YACvC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;QACzB,CAAC;aAAM,CAAC;YACP,2CAA2C;YAC3C,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;QACzB,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enable or disable tracing
|
|
3
|
+
*/
|
|
4
|
+
export declare function setTracingEnabled(enabled: boolean): void;
|
|
5
|
+
/**
|
|
6
|
+
* Check if tracing is enabled
|
|
7
|
+
*/
|
|
8
|
+
export declare function isTracingEnabled(): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Trace a span of work by outputting to console
|
|
11
|
+
* Works for both sync and async functions
|
|
12
|
+
* Only outputs if tracing is enabled
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* await span("operation", async () => { ... })
|
|
16
|
+
* span("operation", () => { ... })
|
|
17
|
+
*/
|
|
18
|
+
export declare function span<T>(name: string, fn: () => T | Promise<T>): T | Promise<T>;
|
|
19
|
+
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/utils/trace.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAExD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACpB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAqBhB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setTracingEnabled = setTracingEnabled;
|
|
4
|
+
exports.isTracingEnabled = isTracingEnabled;
|
|
5
|
+
exports.span = span;
|
|
6
|
+
const output_1 = require("./output");
|
|
7
|
+
/**
|
|
8
|
+
* Global tracing state
|
|
9
|
+
*/
|
|
10
|
+
let tracingEnabled = false;
|
|
11
|
+
/**
|
|
12
|
+
* Enable or disable tracing
|
|
13
|
+
*/
|
|
14
|
+
function setTracingEnabled(enabled) {
|
|
15
|
+
tracingEnabled = enabled;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if tracing is enabled
|
|
19
|
+
*/
|
|
20
|
+
function isTracingEnabled() {
|
|
21
|
+
return tracingEnabled;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Trace a span of work by outputting to console
|
|
25
|
+
* Works for both sync and async functions
|
|
26
|
+
* Only outputs if tracing is enabled
|
|
27
|
+
*
|
|
28
|
+
* Usage:
|
|
29
|
+
* await span("operation", async () => { ... })
|
|
30
|
+
* span("operation", () => { ... })
|
|
31
|
+
*/
|
|
32
|
+
function span(name, fn) {
|
|
33
|
+
if (!tracingEnabled) {
|
|
34
|
+
return fn();
|
|
35
|
+
}
|
|
36
|
+
const start = performance.now();
|
|
37
|
+
const result = fn();
|
|
38
|
+
// Check if it's a promise (async)
|
|
39
|
+
if (result instanceof Promise) {
|
|
40
|
+
return result.then((value) => {
|
|
41
|
+
const duration = performance.now() - start;
|
|
42
|
+
output_1.out.taskLine(`${name} (${formatDuration(duration)})`, true);
|
|
43
|
+
return value;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// Sync case
|
|
47
|
+
const duration = performance.now() - start;
|
|
48
|
+
output_1.out.taskLine(`${name} (${formatDuration(duration)})`, true);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Format duration for display
|
|
53
|
+
*/
|
|
54
|
+
function formatDuration(ms) {
|
|
55
|
+
if (ms < 1) {
|
|
56
|
+
return `${ms.toFixed(2)}ms`;
|
|
57
|
+
}
|
|
58
|
+
else if (ms < 1000) {
|
|
59
|
+
return `${Math.round(ms)}ms`;
|
|
60
|
+
}
|
|
61
|
+
else if (ms < 2000) {
|
|
62
|
+
return `${(ms / 1000).toFixed(2)}s`;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../src/utils/trace.ts"],"names":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C;IAC9B,CAAC;SAAM,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;QACrB,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC;IAC/B,CAAC;SAAM,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;QACrB,OAAO,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IACtC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pushwork",
|
|
3
|
-
"version": "2.0.0-preview.
|
|
3
|
+
"version": "2.0.0-preview.8",
|
|
4
4
|
"description": "Bidirectional directory synchronization using Automerge CRDTs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@automerge/automerge": "^3.2.6",
|
|
31
|
-
"@automerge/automerge-repo": "2.6.0-subduction.
|
|
32
|
-
"@automerge/automerge-repo-network-websocket": "2.6.0-subduction.
|
|
33
|
-
"@automerge/automerge-repo-storage-nodefs": "2.6.0-subduction.
|
|
34
|
-
"@automerge/automerge-subduction": "0.
|
|
31
|
+
"@automerge/automerge-repo": "2.6.0-subduction.29",
|
|
32
|
+
"@automerge/automerge-repo-network-websocket": "2.6.0-subduction.29",
|
|
33
|
+
"@automerge/automerge-repo-storage-nodefs": "2.6.0-subduction.29",
|
|
34
|
+
"@automerge/automerge-subduction": "0.15.0",
|
|
35
35
|
"@commander-js/extra-typings": "^14.0.0",
|
|
36
36
|
"chalk": "^5.3.0",
|
|
37
37
|
"commander": "^14.0.2",
|
package/dist/checkpoints.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type AutomergeUrl, type DocHandle, type Repo } from "@automerge/automerge-repo";
|
|
2
|
-
export type CheckpointKind = "save" | "merge";
|
|
3
|
-
export type CheckpointSource = {
|
|
4
|
-
name: string;
|
|
5
|
-
url: AutomergeUrl;
|
|
6
|
-
heads: string[];
|
|
7
|
-
};
|
|
8
|
-
export type Checkpoint = {
|
|
9
|
-
id: string;
|
|
10
|
-
ts: number;
|
|
11
|
-
kind: CheckpointKind;
|
|
12
|
-
headsBefore: string[];
|
|
13
|
-
headsAfter: string[];
|
|
14
|
-
message?: string;
|
|
15
|
-
source?: CheckpointSource;
|
|
16
|
-
};
|
|
17
|
-
export type CheckpointsDoc = {
|
|
18
|
-
"@patchwork": {
|
|
19
|
-
type: "checkpoints";
|
|
20
|
-
};
|
|
21
|
-
entries: {
|
|
22
|
-
[id: string]: Checkpoint;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export declare const isCheckpointsDoc: (doc: unknown) => doc is CheckpointsDoc;
|
|
26
|
-
export declare function makeCheckpointId(ts?: number): string;
|
|
27
|
-
export declare function findOrCreateCheckpoints(repo: Repo, folderHandle: DocHandle<unknown>): Promise<DocHandle<CheckpointsDoc>>;
|
|
28
|
-
export declare function cloneCheckpointsTo(repo: Repo, sourceFolder: DocHandle<unknown>, targetFolder: DocHandle<unknown>): Promise<AutomergeUrl | null>;
|
|
29
|
-
export type AppendArgs = {
|
|
30
|
-
kind: CheckpointKind;
|
|
31
|
-
headsBefore: string[];
|
|
32
|
-
headsAfter: string[];
|
|
33
|
-
message?: string;
|
|
34
|
-
source?: CheckpointSource;
|
|
35
|
-
force?: boolean;
|
|
36
|
-
};
|
|
37
|
-
export declare function appendCheckpointTo(checkpoints: DocHandle<CheckpointsDoc>, args: AppendArgs): Checkpoint | null;
|
|
38
|
-
export declare function listCheckpoints(doc: CheckpointsDoc): Checkpoint[];
|
|
39
|
-
export declare function topoSort(entries: Checkpoint[]): Checkpoint[];
|
|
40
|
-
export declare function getFolderHeads(folderHandle: DocHandle<unknown>): string[];
|
|
41
|
-
//# sourceMappingURL=checkpoints.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoints.d.ts","sourceRoot":"","sources":["../src/checkpoints.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,IAAI,EACT,MAAM,2BAA2B,CAAC;AAQnC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC;AAE9C,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,YAAY,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,cAAc,CAAC;IACrB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B,YAAY,EAAE;QAAE,IAAI,EAAE,aAAa,CAAA;KAAE,CAAC;IACtC,OAAO,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAC;CACtC,CAAC;AAKF,eAAO,MAAM,gBAAgB,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,cAQtD,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAAE,SAAa,GAAG,MAAM,CAMxD;AAED,wBAAsB,uBAAuB,CAC5C,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,SAAS,CAAC,OAAO,CAAC,GAC9B,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAuBpC;AAED,wBAA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