@undefineds.co/xpod 0.3.18 → 0.3.23
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/config/bun.json +57 -11
- package/config/cloud.json +14 -12
- package/config/local.json +16 -14
- package/config/xpod.json +47 -9
- package/dist/api/matrix/PodMatrixStore.d.ts +4 -7
- package/dist/api/matrix/PodMatrixStore.js +116 -148
- package/dist/api/matrix/PodMatrixStore.js.map +1 -1
- package/dist/api/matrix/types.d.ts +2 -0
- package/dist/api/matrix/types.js.map +1 -1
- package/dist/api/runs/PiAgentRuntimeDriver.d.ts +1 -0
- package/dist/api/runs/PiAgentRuntimeDriver.js +4 -1
- package/dist/api/runs/PiAgentRuntimeDriver.js.map +1 -1
- package/dist/components/components.jsonld +3 -0
- package/dist/components/context.jsonld +71 -32
- package/dist/http/SubgraphSparqlHttpHandler.d.ts +1 -0
- package/dist/http/SubgraphSparqlHttpHandler.js +27 -4
- package/dist/http/SubgraphSparqlHttpHandler.js.map +1 -1
- package/dist/http/SubgraphSparqlHttpHandler.jsonld +4 -0
- package/dist/http/vector/VectorHttpHandler.d.ts +5 -1
- package/dist/http/vector/VectorHttpHandler.js +5 -5
- package/dist/http/vector/VectorHttpHandler.js.map +1 -1
- package/dist/http/vector/VectorHttpHandler.jsonld +40 -28
- package/dist/index.d.ts +5 -2
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/runtime/Proxy.d.ts +3 -0
- package/dist/runtime/Proxy.js +31 -7
- package/dist/runtime/Proxy.js.map +1 -1
- package/dist/solidfs/LocalSolidFS.js +31 -124
- package/dist/solidfs/LocalSolidFS.js.map +1 -1
- package/dist/solidfs/SolidFsPathUtils.d.ts +13 -0
- package/dist/solidfs/SolidFsPathUtils.js +114 -0
- package/dist/solidfs/SolidFsPathUtils.js.map +1 -0
- package/dist/solidfs/SolidFsSyncJournal.d.ts +117 -0
- package/dist/solidfs/SolidFsSyncJournal.js +553 -0
- package/dist/solidfs/SolidFsSyncJournal.js.map +1 -0
- package/dist/solidfs/index.d.ts +1 -0
- package/dist/solidfs/index.js +1 -0
- package/dist/solidfs/index.js.map +1 -1
- package/dist/solidfs/types.d.ts +1 -0
- package/dist/solidfs/types.js.map +1 -1
- package/dist/storage/SparqlUpdateResourceStore.js +94 -33
- package/dist/storage/SparqlUpdateResourceStore.js.map +1 -1
- package/dist/storage/accessors/MixDataAccessor.d.ts +22 -5
- package/dist/storage/accessors/MixDataAccessor.js +376 -61
- package/dist/storage/accessors/MixDataAccessor.js.map +1 -1
- package/dist/storage/accessors/MixDataAccessor.jsonld +73 -5
- package/dist/storage/accessors/QuadstoreSparqlDataAccessor.js +32 -10
- package/dist/storage/accessors/QuadstoreSparqlDataAccessor.js.map +1 -1
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.js +28 -6
- package/dist/storage/accessors/QuintStoreSparqlDataAccessor.js.map +1 -1
- package/dist/storage/accessors/SolidRdfDataAccessor.d.ts +45 -0
- package/dist/storage/accessors/SolidRdfDataAccessor.js +277 -0
- package/dist/storage/accessors/SolidRdfDataAccessor.js.map +1 -0
- package/dist/storage/accessors/SolidRdfDataAccessor.jsonld +161 -0
- package/dist/storage/rdf/Rdf3xIndex.d.ts +122 -0
- package/dist/storage/rdf/Rdf3xIndex.js +2695 -0
- package/dist/storage/rdf/Rdf3xIndex.js.map +1 -0
- package/dist/storage/rdf/Rdf3xIndex.jsonld +528 -0
- package/dist/storage/rdf/Rdf3xSchema.d.ts +20 -0
- package/dist/storage/rdf/Rdf3xSchema.js +65 -0
- package/dist/storage/rdf/Rdf3xSchema.js.map +1 -0
- package/dist/storage/rdf/RdfLocalQueryEngine.d.ts +10 -4
- package/dist/storage/rdf/RdfLocalQueryEngine.js +607 -127
- package/dist/storage/rdf/RdfLocalQueryEngine.js.map +1 -1
- package/dist/storage/rdf/RdfQuadIndex.d.ts +12 -1
- package/dist/storage/rdf/RdfQuadIndex.js +152 -22
- package/dist/storage/rdf/RdfQuadIndex.js.map +1 -1
- package/dist/storage/rdf/RdfQuadIndex.jsonld +36 -4
- package/dist/storage/rdf/RdfSparqlAdapter.d.ts +20 -2
- package/dist/storage/rdf/RdfSparqlAdapter.js +364 -40
- package/dist/storage/rdf/RdfSparqlAdapter.js.map +1 -1
- package/dist/storage/rdf/RdfSparqlAdapter.jsonld +60 -0
- package/dist/storage/rdf/RdfTermDictionary.d.ts +8 -0
- package/dist/storage/rdf/RdfTermDictionary.js +141 -70
- package/dist/storage/rdf/RdfTermDictionary.js.map +1 -1
- package/dist/storage/rdf/RdfTermDictionary.jsonld +24 -0
- package/dist/storage/rdf/RdfTextIndex.js +10 -3
- package/dist/storage/rdf/RdfTextIndex.js.map +1 -1
- package/dist/storage/rdf/SolidRdfEngine.d.ts +15 -6
- package/dist/storage/rdf/SolidRdfEngine.js +218 -25
- package/dist/storage/rdf/SolidRdfEngine.js.map +1 -1
- package/dist/storage/rdf/SolidRdfEngine.jsonld +70 -7
- package/dist/storage/rdf/SolidRdfSparqlEngine.d.ts +11 -7
- package/dist/storage/rdf/SolidRdfSparqlEngine.js +60 -47
- package/dist/storage/rdf/SolidRdfSparqlEngine.js.map +1 -1
- package/dist/storage/rdf/SolidRdfSparqlEngine.jsonld +9 -5
- package/dist/storage/rdf/index.d.ts +2 -2
- package/dist/storage/rdf/index.js +3 -3
- package/dist/storage/rdf/index.js.map +1 -1
- package/dist/storage/rdf/models-benchmark.d.ts +12 -1
- package/dist/storage/rdf/models-benchmark.js +549 -32
- package/dist/storage/rdf/models-benchmark.js.map +1 -1
- package/dist/storage/rdf/types.d.ts +81 -7
- package/dist/storage/rdf/types.js.map +1 -1
- package/dist/storage/sparql/CompatibilitySparqlEngine.d.ts +36 -0
- package/dist/storage/sparql/CompatibilitySparqlEngine.js +96 -0
- package/dist/storage/sparql/CompatibilitySparqlEngine.js.map +1 -0
- package/dist/storage/sparql/CompatibilitySparqlEngine.jsonld +123 -0
- package/dist/storage/sparql/CompatibilitySparqlEngineImpl.d.ts +35 -0
- package/dist/storage/sparql/CompatibilitySparqlEngineImpl.js +112 -0
- package/dist/storage/sparql/CompatibilitySparqlEngineImpl.js.map +1 -0
- package/dist/storage/sparql/SubgraphQueryEngine.d.ts +1 -36
- package/dist/storage/sparql/SubgraphQueryEngine.js +2 -115
- package/dist/storage/sparql/SubgraphQueryEngine.js.map +1 -1
- package/dist/storage/sparql/SubgraphQueryEngine.jsonld +1 -124
- package/dist/terminal/AclPermissionService.d.ts +2 -1
- package/dist/terminal/AclPermissionService.js +26 -3
- package/dist/terminal/AclPermissionService.js.map +1 -1
- package/dist/terminal/TerminalSessionManager.js +25 -3
- package/dist/terminal/TerminalSessionManager.js.map +1 -1
- package/package.json +1 -1
- package/dist/storage/rdf/Rdf3xTripleIndex.d.ts +0 -55
- package/dist/storage/rdf/Rdf3xTripleIndex.js +0 -1235
- package/dist/storage/rdf/Rdf3xTripleIndex.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SolidFsPathUtils.js","sourceRoot":"","sources":["../../src/solidfs/SolidFsPathUtils.ts"],"names":[],"mappings":";;;;;AAqBA,gDAaC;AAED,kDAQC;AAED,4DAYC;AAED,4CAMC;AAED,4CAMC;AAED,kCAUC;AAED,8CAqCC;AA7HD,6CAAyC;AACzC,qCAA2C;AAC3C,+CAG0B;AAC1B,0DAA6B;AAC7B,uCAAyC;AAMzC,oEAAuE;AAQvE,SAAgB,kBAAkB,CAAC,QAAgB;IACjD,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACrC,MAAM,cAAc,GAAG,IAAA,uCAAqB,EAAC,KAAK,CAAC,CAAC;IACpD,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAA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C,CAAC;AAC9F,CAAC","sourcesContent":["import { createHash } from 'node:crypto';\nimport { createReadStream } from 'node:fs';\nimport {\n readdir,\n stat,\n} from 'node:fs/promises';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type {\n SolidFsEntrySource,\n SolidFsProjection,\n} from './types';\nimport { rdfContentTypeForPath } from '../storage/rdf/RdfContentTypes';\n\nexport interface SolidFsFileSnapshot {\n relativePath: string;\n absolutePath: string;\n version: string;\n}\n\nexport function contentTypeForPath(filePath: string): string | undefined {\n const lower = filePath.toLowerCase();\n const rdfContentType = rdfContentTypeForPath(lower);\n if (rdfContentType) {\n return rdfContentType;\n }\n if (lower.endsWith('.md') || lower.endsWith('.markdown') || lower.endsWith('.mdown')) {\n return 'text/markdown';\n }\n if (lower.endsWith('.txt') || lower.endsWith('.log')) {\n return 'text/plain';\n }\n return undefined;\n}\n\nexport function sourceForProjection(projection: SolidFsProjection, workspace: string): SolidFsEntrySource {\n if (projection === 'hydrated-object') {\n return 'object';\n }\n if (/^https?:/u.test(workspace)) {\n return 'pod-http';\n }\n return 'filesystem';\n}\n\nexport function resolveWorkspaceResource(workspace: string, relativePath: string): string | undefined {\n if (path.isAbsolute(workspace)) {\n return pathToFileURL(path.join(workspace, relativePath)).href;\n }\n\n try {\n const base = new URL(workspace.endsWith('/') ? workspace : `${workspace}/`);\n const normalized = relativePath.split(path.sep).join('/');\n return new URL(normalized, base).href;\n } catch {\n return undefined;\n }\n}\n\nexport function safeRelativePath(input: string): string {\n const normalized = input.split(/[\\\\/]+/u).filter((part) => part.length > 0).join(path.sep);\n if (!normalized || path.isAbsolute(input) || normalized.split(path.sep).includes('..')) {\n throw new Error(`Invalid SolidFS relative path: ${input}`);\n }\n return normalized;\n}\n\nexport async function maybeFileVersion(filePath: string): Promise<string | undefined> {\n try {\n return await fileVersion(filePath);\n } catch {\n return undefined;\n }\n}\n\nexport async function fileVersion(filePath: string): Promise<string> {\n const fileStat = await stat(filePath);\n const hash = createHash('sha256');\n await new Promise<void>((resolve, reject) => {\n const stream = createReadStream(filePath);\n stream.on('data', (chunk) => hash.update(chunk));\n stream.on('error', reject);\n stream.on('end', resolve);\n });\n return `${fileStat.size}:${fileStat.mtimeMs}:${hash.digest('hex')}`;\n}\n\nexport async function snapshotDirectory(\n root: string,\n filter?: (relativePath: string) => boolean,\n): Promise<SolidFsFileSnapshot[]> {\n const snapshots: SolidFsFileSnapshot[] = [];\n\n async function walk(current: string): Promise<void> {\n let entries;\n try {\n entries = await readdir(current, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n const absolute = path.join(current, entry.name);\n const relative = path.relative(root, absolute);\n if (entry.isDirectory()) {\n await walk(absolute);\n continue;\n }\n if (!entry.isFile()) {\n continue;\n }\n if (filter && !filter(relative)) {\n continue;\n }\n snapshots.push({\n relativePath: relative,\n absolutePath: absolute,\n version: await fileVersion(absolute),\n });\n }\n }\n\n await walk(root);\n return snapshots.sort((left, right) => left.relativePath.localeCompare(right.relativePath));\n}\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { SolidFsChange, SolidFsEntrySource, SolidFsManifest, SolidFsPrepareInput, SolidFsProjection, SolidFsSyncer } from './types';
|
|
2
|
+
export type SolidFsSyncJournalStage = 'local_committed' | 'failed_retryable' | 'failed_permanent' | 'reconcile_required' | 'done';
|
|
3
|
+
export interface SolidFsSyncJournalOptions {
|
|
4
|
+
path: string;
|
|
5
|
+
now?: () => number;
|
|
6
|
+
doneRetentionMs?: number;
|
|
7
|
+
tombstoneRetentionMs?: number;
|
|
8
|
+
failedPermanentRetentionMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SolidFsSyncJournalOperation {
|
|
11
|
+
id: string;
|
|
12
|
+
txId?: string;
|
|
13
|
+
workspace: SolidFsManifest;
|
|
14
|
+
change: SolidFsChange;
|
|
15
|
+
stage: SolidFsSyncJournalStage;
|
|
16
|
+
afterHash?: string;
|
|
17
|
+
retryCount: number;
|
|
18
|
+
lastError?: string;
|
|
19
|
+
createdAt: number;
|
|
20
|
+
updatedAt: number;
|
|
21
|
+
doneAt?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface SolidFsJournalBootstrapInput {
|
|
24
|
+
workspace: string;
|
|
25
|
+
cwd: string;
|
|
26
|
+
projection?: SolidFsProjection;
|
|
27
|
+
source?: SolidFsEntrySource;
|
|
28
|
+
shouldTrackPath?: (relativePath: string) => boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface SolidFsJournalBootstrapResult {
|
|
31
|
+
scanned: number;
|
|
32
|
+
enqueued: number;
|
|
33
|
+
skipped: number;
|
|
34
|
+
}
|
|
35
|
+
export interface SolidFsJournalReplayResult {
|
|
36
|
+
attempted: number;
|
|
37
|
+
completed: number;
|
|
38
|
+
failed: number;
|
|
39
|
+
reconcileRequired: number;
|
|
40
|
+
}
|
|
41
|
+
export interface SolidFsJournalCompactResult {
|
|
42
|
+
deletedOps: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Per-Pod SolidFS recovery journal.
|
|
46
|
+
*
|
|
47
|
+
* This is an outbox for derived work after the authority file is already
|
|
48
|
+
* committed. It stores enough metadata to replay index/remote refreshes, but
|
|
49
|
+
* never stores file bodies.
|
|
50
|
+
*/
|
|
51
|
+
export declare class SqliteSolidFsSyncJournal {
|
|
52
|
+
private readonly db;
|
|
53
|
+
private readonly now;
|
|
54
|
+
private readonly doneRetentionMs;
|
|
55
|
+
private readonly tombstoneRetentionMs;
|
|
56
|
+
private readonly failedPermanentRetentionMs;
|
|
57
|
+
constructor(options: SolidFsSyncJournalOptions);
|
|
58
|
+
close(): void;
|
|
59
|
+
recordLocalCommitted(change: SolidFsChange, workspace: SolidFsManifest, txId?: string): Promise<SolidFsSyncJournalOperation>;
|
|
60
|
+
getOperation(id: string): SolidFsSyncJournalOperation | undefined;
|
|
61
|
+
listOperations(stages?: SolidFsSyncJournalStage[]): SolidFsSyncJournalOperation[];
|
|
62
|
+
listPending(): SolidFsSyncJournalOperation[];
|
|
63
|
+
markDone(id: string): Promise<void>;
|
|
64
|
+
markRetryableFailure(id: string, error: unknown): Promise<void>;
|
|
65
|
+
markReconcileRequired(id: string, reason: string): Promise<void>;
|
|
66
|
+
markFailedPermanent(id: string, error: unknown): Promise<void>;
|
|
67
|
+
replayPending(syncer: SolidFsSyncer, context?: unknown): Promise<SolidFsJournalReplayResult>;
|
|
68
|
+
bootstrapWorkspace(input: SolidFsJournalBootstrapInput): Promise<SolidFsJournalBootstrapResult>;
|
|
69
|
+
compact(): Promise<SolidFsJournalCompactResult>;
|
|
70
|
+
private validateOperationForReplay;
|
|
71
|
+
private getCheckpoint;
|
|
72
|
+
private listCheckpoints;
|
|
73
|
+
private upsertCheckpoint;
|
|
74
|
+
private initializeSchema;
|
|
75
|
+
}
|
|
76
|
+
export interface JournaledSolidFsSyncerOptions {
|
|
77
|
+
syncer: SolidFsSyncer;
|
|
78
|
+
journal: SqliteSolidFsSyncJournal;
|
|
79
|
+
}
|
|
80
|
+
export interface WorkspaceJournaledSolidFsSyncerOptions {
|
|
81
|
+
syncer: SolidFsSyncer;
|
|
82
|
+
journalRoot?: string;
|
|
83
|
+
resolveJournalPath?: (workspace: SolidFsManifest) => string;
|
|
84
|
+
now?: () => number;
|
|
85
|
+
doneRetentionMs?: number;
|
|
86
|
+
tombstoneRetentionMs?: number;
|
|
87
|
+
failedPermanentRetentionMs?: number;
|
|
88
|
+
}
|
|
89
|
+
export declare class JournaledSolidFsSyncer implements SolidFsSyncer {
|
|
90
|
+
private readonly syncer;
|
|
91
|
+
private readonly journal;
|
|
92
|
+
constructor(options: JournaledSolidFsSyncerOptions);
|
|
93
|
+
shouldTrack(input: SolidFsPrepareInput): boolean;
|
|
94
|
+
shouldTrackPath(relativePath: string): boolean;
|
|
95
|
+
sync(change: SolidFsChange, workspace: SolidFsManifest, context?: unknown): Promise<void>;
|
|
96
|
+
replayPending(context?: unknown): Promise<SolidFsJournalReplayResult>;
|
|
97
|
+
compact(): Promise<SolidFsJournalCompactResult>;
|
|
98
|
+
bootstrapWorkspace(input: Omit<SolidFsJournalBootstrapInput, 'shouldTrackPath'> & {
|
|
99
|
+
shouldTrackPath?: (relativePath: string) => boolean;
|
|
100
|
+
}): Promise<SolidFsJournalBootstrapResult>;
|
|
101
|
+
}
|
|
102
|
+
export declare class WorkspaceJournaledSolidFsSyncer implements SolidFsSyncer {
|
|
103
|
+
private readonly options;
|
|
104
|
+
private readonly syncer;
|
|
105
|
+
private readonly journals;
|
|
106
|
+
constructor(options: WorkspaceJournaledSolidFsSyncerOptions);
|
|
107
|
+
shouldTrack(input: SolidFsPrepareInput): boolean;
|
|
108
|
+
shouldTrackPath(relativePath: string): boolean;
|
|
109
|
+
initializeWorkspace(workspace: SolidFsManifest, context?: unknown): Promise<void>;
|
|
110
|
+
sync(change: SolidFsChange, workspace: SolidFsManifest, context?: unknown): Promise<void>;
|
|
111
|
+
replayPending(workspace: SolidFsManifest, context?: unknown): Promise<SolidFsJournalReplayResult>;
|
|
112
|
+
compact(workspace: SolidFsManifest): Promise<SolidFsJournalCompactResult>;
|
|
113
|
+
journalPathFor(workspace: SolidFsManifest): string;
|
|
114
|
+
close(): void;
|
|
115
|
+
private journalFor;
|
|
116
|
+
}
|
|
117
|
+
export declare function resolveSolidFsJournalPath(workspace: SolidFsManifest, journalRoot?: string): string;
|
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WorkspaceJournaledSolidFsSyncer = exports.JournaledSolidFsSyncer = exports.SqliteSolidFsSyncJournal = void 0;
|
|
7
|
+
exports.resolveSolidFsJournalPath = resolveSolidFsJournalPath;
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const SqliteRuntime_1 = require("../storage/SqliteRuntime");
|
|
11
|
+
const RdfContentTypes_1 = require("../storage/rdf/RdfContentTypes");
|
|
12
|
+
const SolidFsPathUtils_1 = require("./SolidFsPathUtils");
|
|
13
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
14
|
+
const DEFAULT_DONE_RETENTION_MS = 7 * DAY_MS;
|
|
15
|
+
const DEFAULT_TOMBSTONE_RETENTION_MS = 30 * DAY_MS;
|
|
16
|
+
const DEFAULT_FAILED_PERMANENT_RETENTION_MS = 30 * DAY_MS;
|
|
17
|
+
/**
|
|
18
|
+
* Per-Pod SolidFS recovery journal.
|
|
19
|
+
*
|
|
20
|
+
* This is an outbox for derived work after the authority file is already
|
|
21
|
+
* committed. It stores enough metadata to replay index/remote refreshes, but
|
|
22
|
+
* never stores file bodies.
|
|
23
|
+
*/
|
|
24
|
+
class SqliteSolidFsSyncJournal {
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.now = options.now ?? Date.now;
|
|
27
|
+
this.doneRetentionMs = options.doneRetentionMs ?? DEFAULT_DONE_RETENTION_MS;
|
|
28
|
+
this.tombstoneRetentionMs = options.tombstoneRetentionMs ?? DEFAULT_TOMBSTONE_RETENTION_MS;
|
|
29
|
+
this.failedPermanentRetentionMs = options.failedPermanentRetentionMs ?? DEFAULT_FAILED_PERMANENT_RETENTION_MS;
|
|
30
|
+
this.db = (0, SqliteRuntime_1.getSqliteRuntime)().openDatabase(options.path);
|
|
31
|
+
this.db.pragma('journal_mode = WAL');
|
|
32
|
+
this.db.pragma('busy_timeout = 5000');
|
|
33
|
+
this.initializeSchema();
|
|
34
|
+
}
|
|
35
|
+
close() {
|
|
36
|
+
this.db.close();
|
|
37
|
+
}
|
|
38
|
+
async recordLocalCommitted(change, workspace, txId) {
|
|
39
|
+
const normalizedChange = normalizeChange(change);
|
|
40
|
+
const afterHash = normalizedChange.type === 'deleted'
|
|
41
|
+
? undefined
|
|
42
|
+
: await (0, SolidFsPathUtils_1.maybeFileVersion)(normalizedChange.sourcePath);
|
|
43
|
+
const opId = operationId(workspace.workspace, normalizedChange, afterHash);
|
|
44
|
+
const now = this.now();
|
|
45
|
+
const existing = this.getOperation(opId);
|
|
46
|
+
if (existing) {
|
|
47
|
+
return existing;
|
|
48
|
+
}
|
|
49
|
+
const journalWorkspace = journalWorkspaceSnapshot(workspace);
|
|
50
|
+
this.db.prepare(`
|
|
51
|
+
INSERT INTO sync_ops (
|
|
52
|
+
id,
|
|
53
|
+
tx_id,
|
|
54
|
+
workspace,
|
|
55
|
+
path,
|
|
56
|
+
op_type,
|
|
57
|
+
stage,
|
|
58
|
+
source_path,
|
|
59
|
+
resource,
|
|
60
|
+
content_type,
|
|
61
|
+
source,
|
|
62
|
+
projection,
|
|
63
|
+
source_version,
|
|
64
|
+
after_hash,
|
|
65
|
+
workspace_json,
|
|
66
|
+
change_json,
|
|
67
|
+
retry_count,
|
|
68
|
+
created_at,
|
|
69
|
+
updated_at
|
|
70
|
+
)
|
|
71
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?)
|
|
72
|
+
`).run(opId, txId ?? null, workspace.workspace, normalizedChange.path, normalizedChange.type, 'local_committed', normalizedChange.sourcePath, normalizedChange.resource ?? null, normalizedChange.contentType ?? null, normalizedChange.source, normalizedChange.projection, normalizedChange.sourceVersion ?? null, afterHash ?? null, JSON.stringify(journalWorkspace), JSON.stringify(normalizedChange), now, now);
|
|
73
|
+
return this.getOperation(opId);
|
|
74
|
+
}
|
|
75
|
+
getOperation(id) {
|
|
76
|
+
const row = this.db.prepare(`
|
|
77
|
+
SELECT id, tx_id, workspace_json, change_json, stage, after_hash, retry_count,
|
|
78
|
+
last_error, created_at, updated_at, done_at
|
|
79
|
+
FROM sync_ops
|
|
80
|
+
WHERE id = ?
|
|
81
|
+
`).get(id);
|
|
82
|
+
return row ? rowToOperation(row) : undefined;
|
|
83
|
+
}
|
|
84
|
+
listOperations(stages) {
|
|
85
|
+
const rows = stages && stages.length > 0
|
|
86
|
+
? this.db.prepare(`
|
|
87
|
+
SELECT id, tx_id, workspace_json, change_json, stage, after_hash, retry_count,
|
|
88
|
+
last_error, created_at, updated_at, done_at
|
|
89
|
+
FROM sync_ops
|
|
90
|
+
WHERE stage IN (${stages.map(() => '?').join(', ')})
|
|
91
|
+
ORDER BY created_at ASC, id ASC
|
|
92
|
+
`).all(...stages)
|
|
93
|
+
: this.db.prepare(`
|
|
94
|
+
SELECT id, tx_id, workspace_json, change_json, stage, after_hash, retry_count,
|
|
95
|
+
last_error, created_at, updated_at, done_at
|
|
96
|
+
FROM sync_ops
|
|
97
|
+
ORDER BY created_at ASC, id ASC
|
|
98
|
+
`).all();
|
|
99
|
+
return rows.map(rowToOperation);
|
|
100
|
+
}
|
|
101
|
+
listPending() {
|
|
102
|
+
return this.listOperations(['local_committed', 'failed_retryable']);
|
|
103
|
+
}
|
|
104
|
+
async markDone(id) {
|
|
105
|
+
const op = this.getOperation(id);
|
|
106
|
+
if (!op) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const now = this.now();
|
|
110
|
+
this.db.transaction(() => {
|
|
111
|
+
this.db.prepare(`
|
|
112
|
+
UPDATE sync_ops
|
|
113
|
+
SET stage = 'done',
|
|
114
|
+
last_error = NULL,
|
|
115
|
+
done_at = ?,
|
|
116
|
+
updated_at = ?,
|
|
117
|
+
tombstone_confirmed_at = CASE WHEN op_type = 'deleted' THEN ? ELSE tombstone_confirmed_at END
|
|
118
|
+
WHERE id = ?
|
|
119
|
+
`).run(now, now, now, id);
|
|
120
|
+
this.upsertCheckpoint(op, now);
|
|
121
|
+
})();
|
|
122
|
+
}
|
|
123
|
+
async markRetryableFailure(id, error) {
|
|
124
|
+
const now = this.now();
|
|
125
|
+
this.db.prepare(`
|
|
126
|
+
UPDATE sync_ops
|
|
127
|
+
SET stage = 'failed_retryable',
|
|
128
|
+
retry_count = retry_count + 1,
|
|
129
|
+
last_error = ?,
|
|
130
|
+
updated_at = ?
|
|
131
|
+
WHERE id = ?
|
|
132
|
+
`).run(errorMessage(error), now, id);
|
|
133
|
+
}
|
|
134
|
+
async markReconcileRequired(id, reason) {
|
|
135
|
+
const now = this.now();
|
|
136
|
+
this.db.prepare(`
|
|
137
|
+
UPDATE sync_ops
|
|
138
|
+
SET stage = 'reconcile_required',
|
|
139
|
+
last_error = ?,
|
|
140
|
+
updated_at = ?
|
|
141
|
+
WHERE id = ?
|
|
142
|
+
`).run(reason, now, id);
|
|
143
|
+
}
|
|
144
|
+
async markFailedPermanent(id, error) {
|
|
145
|
+
const now = this.now();
|
|
146
|
+
this.db.prepare(`
|
|
147
|
+
UPDATE sync_ops
|
|
148
|
+
SET stage = 'failed_permanent',
|
|
149
|
+
last_error = ?,
|
|
150
|
+
updated_at = ?
|
|
151
|
+
WHERE id = ?
|
|
152
|
+
`).run(errorMessage(error), now, id);
|
|
153
|
+
}
|
|
154
|
+
async replayPending(syncer, context) {
|
|
155
|
+
const result = {
|
|
156
|
+
attempted: 0,
|
|
157
|
+
completed: 0,
|
|
158
|
+
failed: 0,
|
|
159
|
+
reconcileRequired: 0,
|
|
160
|
+
};
|
|
161
|
+
for (const op of this.listPending()) {
|
|
162
|
+
result.attempted += 1;
|
|
163
|
+
const validation = await this.validateOperationForReplay(op);
|
|
164
|
+
if (validation) {
|
|
165
|
+
await this.markReconcileRequired(op.id, validation);
|
|
166
|
+
result.reconcileRequired += 1;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
await syncer.sync(op.change, op.workspace, context);
|
|
171
|
+
await this.markDone(op.id);
|
|
172
|
+
result.completed += 1;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
await this.markRetryableFailure(op.id, error);
|
|
176
|
+
result.failed += 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
async bootstrapWorkspace(input) {
|
|
182
|
+
const projection = input.projection ?? 'direct';
|
|
183
|
+
const source = input.source ?? (0, SolidFsPathUtils_1.sourceForProjection)(projection, input.workspace);
|
|
184
|
+
const manifest = {
|
|
185
|
+
workspace: input.workspace,
|
|
186
|
+
cwd: input.cwd,
|
|
187
|
+
projection,
|
|
188
|
+
entries: [],
|
|
189
|
+
};
|
|
190
|
+
const snapshots = await (0, SolidFsPathUtils_1.snapshotDirectory)(input.cwd, input.shouldTrackPath);
|
|
191
|
+
const currentPaths = new Set(snapshots.map((snapshot) => snapshot.relativePath));
|
|
192
|
+
const result = {
|
|
193
|
+
scanned: snapshots.length,
|
|
194
|
+
enqueued: 0,
|
|
195
|
+
skipped: 0,
|
|
196
|
+
};
|
|
197
|
+
for (const snapshot of snapshots) {
|
|
198
|
+
const checkpoint = this.getCheckpoint(input.workspace, snapshot.relativePath);
|
|
199
|
+
if (checkpoint?.source_version === snapshot.version && !checkpoint.deleted_at) {
|
|
200
|
+
result.skipped += 1;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const op = await this.recordLocalCommitted({
|
|
204
|
+
path: snapshot.relativePath,
|
|
205
|
+
resource: (0, SolidFsPathUtils_1.resolveWorkspaceResource)(input.workspace, snapshot.relativePath),
|
|
206
|
+
source,
|
|
207
|
+
sourcePath: snapshot.absolutePath,
|
|
208
|
+
contentType: (0, SolidFsPathUtils_1.contentTypeForPath)(snapshot.relativePath),
|
|
209
|
+
projection,
|
|
210
|
+
type: 'created',
|
|
211
|
+
}, manifest);
|
|
212
|
+
result.enqueued += op.stage === 'done' ? 0 : 1;
|
|
213
|
+
}
|
|
214
|
+
const checkpoints = this.listCheckpoints(input.workspace);
|
|
215
|
+
for (const checkpoint of checkpoints) {
|
|
216
|
+
if (currentPaths.has(checkpoint.path) || checkpoint.deleted_at) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const op = await this.recordLocalCommitted({
|
|
220
|
+
path: checkpoint.path,
|
|
221
|
+
resource: (0, SolidFsPathUtils_1.resolveWorkspaceResource)(input.workspace, checkpoint.path),
|
|
222
|
+
source,
|
|
223
|
+
sourcePath: node_path_1.default.join(input.cwd, checkpoint.path),
|
|
224
|
+
contentType: (0, SolidFsPathUtils_1.contentTypeForPath)(checkpoint.path),
|
|
225
|
+
projection,
|
|
226
|
+
type: 'deleted',
|
|
227
|
+
sourceVersion: checkpoint.source_version ?? undefined,
|
|
228
|
+
}, manifest);
|
|
229
|
+
result.enqueued += op.stage === 'done' ? 0 : 1;
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
async compact() {
|
|
234
|
+
const now = this.now();
|
|
235
|
+
const rows = this.db.prepare(`
|
|
236
|
+
SELECT id, workspace, path, op_type, after_hash, stage, done_at, updated_at, tombstone_confirmed_at
|
|
237
|
+
FROM sync_ops
|
|
238
|
+
WHERE stage IN ('done', 'failed_permanent')
|
|
239
|
+
ORDER BY created_at ASC
|
|
240
|
+
`).all();
|
|
241
|
+
const deletable = [];
|
|
242
|
+
for (const row of rows) {
|
|
243
|
+
if (row.stage === 'failed_permanent') {
|
|
244
|
+
if (row.updated_at <= now - this.failedPermanentRetentionMs) {
|
|
245
|
+
deletable.push(row.id);
|
|
246
|
+
}
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (!row.done_at) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const checkpoint = this.getCheckpoint(row.workspace, row.path);
|
|
253
|
+
if (!checkpoint) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (row.op_type === 'deleted') {
|
|
257
|
+
if (row.done_at <= now - this.tombstoneRetentionMs &&
|
|
258
|
+
row.tombstone_confirmed_at &&
|
|
259
|
+
checkpoint.deleted_at) {
|
|
260
|
+
deletable.push(row.id);
|
|
261
|
+
}
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (row.done_at <= now - this.doneRetentionMs && checkpoint.source_version === row.after_hash) {
|
|
265
|
+
deletable.push(row.id);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (deletable.length === 0) {
|
|
269
|
+
return { deletedOps: 0 };
|
|
270
|
+
}
|
|
271
|
+
this.db.transaction(() => {
|
|
272
|
+
const deleteStatement = this.db.prepare('DELETE FROM sync_ops WHERE id = ?');
|
|
273
|
+
for (const id of deletable) {
|
|
274
|
+
deleteStatement.run(id);
|
|
275
|
+
}
|
|
276
|
+
})();
|
|
277
|
+
return { deletedOps: deletable.length };
|
|
278
|
+
}
|
|
279
|
+
async validateOperationForReplay(op) {
|
|
280
|
+
if (op.change.type === 'deleted') {
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
const currentHash = await (0, SolidFsPathUtils_1.maybeFileVersion)(op.change.sourcePath);
|
|
284
|
+
if (!currentHash) {
|
|
285
|
+
return `SolidFS journal source is missing: ${op.change.sourcePath}`;
|
|
286
|
+
}
|
|
287
|
+
if (op.afterHash && currentHash !== op.afterHash) {
|
|
288
|
+
return `SolidFS journal source changed before replay: ${op.change.path}`;
|
|
289
|
+
}
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
getCheckpoint(workspace, relativePath) {
|
|
293
|
+
return this.db.prepare(`
|
|
294
|
+
SELECT source_version, deleted_at
|
|
295
|
+
FROM sync_checkpoints
|
|
296
|
+
WHERE workspace = ? AND path = ?
|
|
297
|
+
`).get(workspace, relativePath);
|
|
298
|
+
}
|
|
299
|
+
listCheckpoints(workspace) {
|
|
300
|
+
return this.db.prepare(`
|
|
301
|
+
SELECT path, source_version, deleted_at
|
|
302
|
+
FROM sync_checkpoints
|
|
303
|
+
WHERE workspace = ?
|
|
304
|
+
ORDER BY path ASC
|
|
305
|
+
`).all(workspace);
|
|
306
|
+
}
|
|
307
|
+
upsertCheckpoint(op, now) {
|
|
308
|
+
if (op.change.type === 'deleted') {
|
|
309
|
+
this.db.prepare(`
|
|
310
|
+
INSERT INTO sync_checkpoints (workspace, path, source_version, deleted_at, updated_at, last_op_id)
|
|
311
|
+
VALUES (?, ?, NULL, ?, ?, ?)
|
|
312
|
+
ON CONFLICT(workspace, path) DO UPDATE SET
|
|
313
|
+
source_version = NULL,
|
|
314
|
+
deleted_at = excluded.deleted_at,
|
|
315
|
+
updated_at = excluded.updated_at,
|
|
316
|
+
last_op_id = excluded.last_op_id
|
|
317
|
+
`).run(op.workspace.workspace, op.change.path, now, now, op.id);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
this.db.prepare(`
|
|
321
|
+
INSERT INTO sync_checkpoints (workspace, path, source_version, deleted_at, updated_at, last_op_id)
|
|
322
|
+
VALUES (?, ?, ?, NULL, ?, ?)
|
|
323
|
+
ON CONFLICT(workspace, path) DO UPDATE SET
|
|
324
|
+
source_version = excluded.source_version,
|
|
325
|
+
deleted_at = NULL,
|
|
326
|
+
updated_at = excluded.updated_at,
|
|
327
|
+
last_op_id = excluded.last_op_id
|
|
328
|
+
`).run(op.workspace.workspace, op.change.path, op.afterHash ?? null, now, op.id);
|
|
329
|
+
}
|
|
330
|
+
initializeSchema() {
|
|
331
|
+
this.db.exec(`
|
|
332
|
+
CREATE TABLE IF NOT EXISTS sync_ops (
|
|
333
|
+
id TEXT PRIMARY KEY,
|
|
334
|
+
tx_id TEXT,
|
|
335
|
+
workspace TEXT NOT NULL,
|
|
336
|
+
path TEXT NOT NULL,
|
|
337
|
+
op_type TEXT NOT NULL,
|
|
338
|
+
stage TEXT NOT NULL,
|
|
339
|
+
source_path TEXT NOT NULL,
|
|
340
|
+
resource TEXT,
|
|
341
|
+
content_type TEXT,
|
|
342
|
+
source TEXT NOT NULL,
|
|
343
|
+
projection TEXT NOT NULL,
|
|
344
|
+
source_version TEXT,
|
|
345
|
+
after_hash TEXT,
|
|
346
|
+
workspace_json TEXT NOT NULL,
|
|
347
|
+
change_json TEXT NOT NULL,
|
|
348
|
+
retry_count INTEGER NOT NULL DEFAULT 0,
|
|
349
|
+
last_error TEXT,
|
|
350
|
+
created_at INTEGER NOT NULL,
|
|
351
|
+
updated_at INTEGER NOT NULL,
|
|
352
|
+
done_at INTEGER,
|
|
353
|
+
tombstone_confirmed_at INTEGER
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
CREATE INDEX IF NOT EXISTS sync_ops_stage_created_idx
|
|
357
|
+
ON sync_ops(stage, created_at);
|
|
358
|
+
CREATE INDEX IF NOT EXISTS sync_ops_workspace_path_idx
|
|
359
|
+
ON sync_ops(workspace, path);
|
|
360
|
+
|
|
361
|
+
CREATE TABLE IF NOT EXISTS sync_checkpoints (
|
|
362
|
+
workspace TEXT NOT NULL,
|
|
363
|
+
path TEXT NOT NULL,
|
|
364
|
+
source_version TEXT,
|
|
365
|
+
deleted_at INTEGER,
|
|
366
|
+
updated_at INTEGER NOT NULL,
|
|
367
|
+
last_op_id TEXT,
|
|
368
|
+
PRIMARY KEY (workspace, path)
|
|
369
|
+
);
|
|
370
|
+
`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
exports.SqliteSolidFsSyncJournal = SqliteSolidFsSyncJournal;
|
|
374
|
+
class JournaledSolidFsSyncer {
|
|
375
|
+
constructor(options) {
|
|
376
|
+
this.syncer = options.syncer;
|
|
377
|
+
this.journal = options.journal;
|
|
378
|
+
}
|
|
379
|
+
shouldTrack(input) {
|
|
380
|
+
return this.syncer.shouldTrack?.(input) ?? true;
|
|
381
|
+
}
|
|
382
|
+
shouldTrackPath(relativePath) {
|
|
383
|
+
return this.syncer.shouldTrackPath?.(relativePath) ?? (0, RdfContentTypes_1.isLineAddressableRdfPath)(relativePath);
|
|
384
|
+
}
|
|
385
|
+
async sync(change, workspace, context) {
|
|
386
|
+
const op = await this.journal.recordLocalCommitted(change, workspace);
|
|
387
|
+
if (op.stage === 'done') {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
try {
|
|
391
|
+
await this.syncer.sync(change, workspace, context);
|
|
392
|
+
await this.journal.markDone(op.id);
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
await this.journal.markRetryableFailure(op.id, error);
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
async replayPending(context) {
|
|
400
|
+
return this.journal.replayPending(this.syncer, context);
|
|
401
|
+
}
|
|
402
|
+
async compact() {
|
|
403
|
+
return this.journal.compact();
|
|
404
|
+
}
|
|
405
|
+
async bootstrapWorkspace(input) {
|
|
406
|
+
return this.journal.bootstrapWorkspace({
|
|
407
|
+
...input,
|
|
408
|
+
shouldTrackPath: input.shouldTrackPath ?? this.shouldTrackPath.bind(this),
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
exports.JournaledSolidFsSyncer = JournaledSolidFsSyncer;
|
|
413
|
+
class WorkspaceJournaledSolidFsSyncer {
|
|
414
|
+
constructor(options) {
|
|
415
|
+
this.options = options;
|
|
416
|
+
this.journals = new Map();
|
|
417
|
+
this.syncer = options.syncer;
|
|
418
|
+
}
|
|
419
|
+
shouldTrack(input) {
|
|
420
|
+
return this.syncer.shouldTrack?.(input) ?? true;
|
|
421
|
+
}
|
|
422
|
+
shouldTrackPath(relativePath) {
|
|
423
|
+
return this.syncer.shouldTrackPath?.(relativePath) ?? (0, RdfContentTypes_1.isLineAddressableRdfPath)(relativePath);
|
|
424
|
+
}
|
|
425
|
+
async initializeWorkspace(workspace, context) {
|
|
426
|
+
const journal = this.journalFor(workspace);
|
|
427
|
+
await journal.bootstrapWorkspace({
|
|
428
|
+
workspace: workspace.workspace,
|
|
429
|
+
cwd: workspace.cwd,
|
|
430
|
+
projection: workspace.projection,
|
|
431
|
+
source: (0, SolidFsPathUtils_1.sourceForProjection)(workspace.projection, workspace.workspace),
|
|
432
|
+
shouldTrackPath: this.shouldTrackPath.bind(this),
|
|
433
|
+
});
|
|
434
|
+
await journal.replayPending(this.syncer, context);
|
|
435
|
+
await journal.compact();
|
|
436
|
+
}
|
|
437
|
+
async sync(change, workspace, context) {
|
|
438
|
+
const journal = this.journalFor(workspace);
|
|
439
|
+
const op = await journal.recordLocalCommitted(change, workspace);
|
|
440
|
+
if (op.stage === 'done') {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
try {
|
|
444
|
+
await this.syncer.sync(change, workspace, context);
|
|
445
|
+
await journal.markDone(op.id);
|
|
446
|
+
}
|
|
447
|
+
catch (error) {
|
|
448
|
+
await journal.markRetryableFailure(op.id, error);
|
|
449
|
+
throw error;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
async replayPending(workspace, context) {
|
|
453
|
+
return this.journalFor(workspace).replayPending(this.syncer, context);
|
|
454
|
+
}
|
|
455
|
+
async compact(workspace) {
|
|
456
|
+
return this.journalFor(workspace).compact();
|
|
457
|
+
}
|
|
458
|
+
journalPathFor(workspace) {
|
|
459
|
+
return this.options.resolveJournalPath?.(workspace)
|
|
460
|
+
?? resolveSolidFsJournalPath(workspace, this.options.journalRoot ?? process.env.XPOD_SOLIDFS_JOURNAL_ROOT);
|
|
461
|
+
}
|
|
462
|
+
close() {
|
|
463
|
+
for (const journal of this.journals.values()) {
|
|
464
|
+
journal.close();
|
|
465
|
+
}
|
|
466
|
+
this.journals.clear();
|
|
467
|
+
}
|
|
468
|
+
journalFor(workspace) {
|
|
469
|
+
const journalPath = this.journalPathFor(workspace);
|
|
470
|
+
const existing = this.journals.get(journalPath);
|
|
471
|
+
if (existing) {
|
|
472
|
+
return existing;
|
|
473
|
+
}
|
|
474
|
+
const journal = new SqliteSolidFsSyncJournal({
|
|
475
|
+
path: journalPath,
|
|
476
|
+
now: this.options.now,
|
|
477
|
+
doneRetentionMs: this.options.doneRetentionMs,
|
|
478
|
+
tombstoneRetentionMs: this.options.tombstoneRetentionMs,
|
|
479
|
+
failedPermanentRetentionMs: this.options.failedPermanentRetentionMs,
|
|
480
|
+
});
|
|
481
|
+
this.journals.set(journalPath, journal);
|
|
482
|
+
return journal;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
exports.WorkspaceJournaledSolidFsSyncer = WorkspaceJournaledSolidFsSyncer;
|
|
486
|
+
function resolveSolidFsJournalPath(workspace, journalRoot) {
|
|
487
|
+
const root = journalRoot
|
|
488
|
+
? node_path_1.default.resolve(journalRoot)
|
|
489
|
+
: node_path_1.default.join(node_path_1.default.dirname(node_path_1.default.resolve(workspace.cwd)), '.xpod-control', 'solidfs-journals');
|
|
490
|
+
const basename = safeJournalSegment(node_path_1.default.basename(workspace.cwd) || 'workspace');
|
|
491
|
+
const key = (0, node_crypto_1.createHash)('sha256')
|
|
492
|
+
.update(workspace.workspace)
|
|
493
|
+
.digest('hex')
|
|
494
|
+
.slice(0, 16);
|
|
495
|
+
return node_path_1.default.join(root, `${basename}-${key}`, 'sync-journal.sqlite');
|
|
496
|
+
}
|
|
497
|
+
function rowToOperation(row) {
|
|
498
|
+
return {
|
|
499
|
+
id: row.id,
|
|
500
|
+
txId: row.tx_id ?? undefined,
|
|
501
|
+
workspace: JSON.parse(row.workspace_json),
|
|
502
|
+
change: JSON.parse(row.change_json),
|
|
503
|
+
stage: row.stage,
|
|
504
|
+
afterHash: row.after_hash ?? undefined,
|
|
505
|
+
retryCount: row.retry_count,
|
|
506
|
+
lastError: row.last_error ?? undefined,
|
|
507
|
+
createdAt: row.created_at,
|
|
508
|
+
updatedAt: row.updated_at,
|
|
509
|
+
doneAt: row.done_at ?? undefined,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function journalWorkspaceSnapshot(workspace) {
|
|
513
|
+
return {
|
|
514
|
+
workspace: workspace.workspace,
|
|
515
|
+
cwd: workspace.cwd,
|
|
516
|
+
projection: workspace.projection,
|
|
517
|
+
entries: [],
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function normalizeChange(change) {
|
|
521
|
+
return {
|
|
522
|
+
...change,
|
|
523
|
+
path: change.path.split(/[\\/]+/u).join(node_path_1.default.sep),
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
function operationId(workspace, change, afterHash) {
|
|
527
|
+
const digest = (0, node_crypto_1.createHash)('sha256')
|
|
528
|
+
.update(JSON.stringify({
|
|
529
|
+
workspace,
|
|
530
|
+
path: change.path,
|
|
531
|
+
type: change.type,
|
|
532
|
+
resource: change.resource,
|
|
533
|
+
source: change.source,
|
|
534
|
+
sourcePath: change.sourcePath,
|
|
535
|
+
projection: change.projection,
|
|
536
|
+
sourceVersion: change.sourceVersion,
|
|
537
|
+
afterHash,
|
|
538
|
+
}))
|
|
539
|
+
.digest('hex')
|
|
540
|
+
.slice(0, 32);
|
|
541
|
+
return `sync_${digest}`;
|
|
542
|
+
}
|
|
543
|
+
function safeJournalSegment(value) {
|
|
544
|
+
const safe = value.replace(/[^a-zA-Z0-9._-]+/gu, '_').slice(0, 64);
|
|
545
|
+
return safe || 'workspace';
|
|
546
|
+
}
|
|
547
|
+
function errorMessage(error) {
|
|
548
|
+
if (error instanceof Error) {
|
|
549
|
+
return error.message;
|
|
550
|
+
}
|
|
551
|
+
return String(error);
|
|
552
|
+
}
|
|
553
|
+
//# sourceMappingURL=SolidFsSyncJournal.js.map
|