@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":"SolidFsSyncJournal.js","sourceRoot":"","sources":["../../src/solidfs/SolidFsSyncJournal.ts"],"names":[],"mappings":";;;;;;AA8qBA,8DAUC;AAxrBD,6CAAyC;AACzC,0DAA6B;AAE7B,4DAAiF;AASjF,oEAEwC;AACxC,yDAM4B;AAE5B,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,MAAM,yBAAyB,GAAG,CAAC,GAAG,MAAM,CAAC;AAC7C,MAAM,8BAA8B,GAAG,EAAE,GAAG,MAAM,CAAC;AACnD,MAAM,qCAAqC,GAAG,EAAE,GAAG,MAAM,CAAC;AA2E1D;;;;;;GAMG;AACH,MAAa,wBAAwB;IAOnC,YAAmB,OAAkC;QACnD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,yBAAyB,CAAC;QAC5E,IAA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E,CAAC,CAAC;IAChB,OAAO,QAAQ,MAAM,EAAE,CAAC;AAC1B,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa;IACvC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACnE,OAAO,IAAI,IAAI,WAAW,CAAC;AAC7B,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { createHash } from 'node:crypto';\nimport path from 'node:path';\n\nimport { getSqliteRuntime, type SqliteDatabase } from '../storage/SqliteRuntime';\nimport type {\n SolidFsChange,\n SolidFsEntrySource,\n SolidFsManifest,\n SolidFsPrepareInput,\n SolidFsProjection,\n SolidFsSyncer,\n} from './types';\nimport {\n isLineAddressableRdfPath,\n} from '../storage/rdf/RdfContentTypes';\nimport {\n contentTypeForPath,\n maybeFileVersion,\n resolveWorkspaceResource,\n snapshotDirectory,\n sourceForProjection,\n} from './SolidFsPathUtils';\n\nconst DAY_MS = 24 * 60 * 60 * 1000;\nconst DEFAULT_DONE_RETENTION_MS = 7 * DAY_MS;\nconst DEFAULT_TOMBSTONE_RETENTION_MS = 30 * DAY_MS;\nconst DEFAULT_FAILED_PERMANENT_RETENTION_MS = 30 * DAY_MS;\n\nexport type SolidFsSyncJournalStage =\n | 'local_committed'\n | 'failed_retryable'\n | 'failed_permanent'\n | 'reconcile_required'\n | 'done';\n\nexport interface SolidFsSyncJournalOptions {\n path: string;\n now?: () => number;\n doneRetentionMs?: number;\n tombstoneRetentionMs?: number;\n failedPermanentRetentionMs?: number;\n}\n\nexport interface SolidFsSyncJournalOperation {\n id: string;\n txId?: string;\n workspace: SolidFsManifest;\n change: SolidFsChange;\n stage: SolidFsSyncJournalStage;\n afterHash?: string;\n retryCount: number;\n lastError?: string;\n createdAt: number;\n updatedAt: number;\n doneAt?: number;\n}\n\nexport interface SolidFsJournalBootstrapInput {\n workspace: string;\n cwd: string;\n projection?: SolidFsProjection;\n source?: SolidFsEntrySource;\n shouldTrackPath?: (relativePath: string) => boolean;\n}\n\nexport interface SolidFsJournalBootstrapResult {\n scanned: number;\n enqueued: number;\n skipped: number;\n}\n\nexport interface SolidFsJournalReplayResult {\n attempted: number;\n completed: number;\n failed: number;\n reconcileRequired: number;\n}\n\nexport interface SolidFsJournalCompactResult {\n deletedOps: number;\n}\n\ninterface SyncOpRow {\n id: string;\n tx_id: string | null;\n workspace_json: string;\n change_json: string;\n stage: SolidFsSyncJournalStage;\n after_hash: string | null;\n retry_count: number;\n last_error: string | null;\n created_at: number;\n updated_at: number;\n done_at: number | null;\n}\n\ninterface CheckpointRow {\n source_version: string | null;\n deleted_at: number | null;\n}\n\n/**\n * Per-Pod SolidFS recovery journal.\n *\n * This is an outbox for derived work after the authority file is already\n * committed. It stores enough metadata to replay index/remote refreshes, but\n * never stores file bodies.\n */\nexport class SqliteSolidFsSyncJournal {\n private readonly db: SqliteDatabase;\n private readonly now: () => number;\n private readonly doneRetentionMs: number;\n private readonly tombstoneRetentionMs: number;\n private readonly failedPermanentRetentionMs: number;\n\n public constructor(options: SolidFsSyncJournalOptions) {\n this.now = options.now ?? Date.now;\n this.doneRetentionMs = options.doneRetentionMs ?? DEFAULT_DONE_RETENTION_MS;\n this.tombstoneRetentionMs = options.tombstoneRetentionMs ?? DEFAULT_TOMBSTONE_RETENTION_MS;\n this.failedPermanentRetentionMs = options.failedPermanentRetentionMs ?? DEFAULT_FAILED_PERMANENT_RETENTION_MS;\n this.db = getSqliteRuntime().openDatabase(options.path);\n this.db.pragma('journal_mode = WAL');\n this.db.pragma('busy_timeout = 5000');\n this.initializeSchema();\n }\n\n public close(): void {\n this.db.close();\n }\n\n public async recordLocalCommitted(\n change: SolidFsChange,\n workspace: SolidFsManifest,\n txId?: string,\n ): Promise<SolidFsSyncJournalOperation> {\n const normalizedChange = normalizeChange(change);\n const afterHash = normalizedChange.type === 'deleted'\n ? undefined\n : await maybeFileVersion(normalizedChange.sourcePath);\n const opId = operationId(workspace.workspace, normalizedChange, afterHash);\n const now = this.now();\n\n const existing = this.getOperation(opId);\n if (existing) {\n return existing;\n }\n\n const journalWorkspace = journalWorkspaceSnapshot(workspace);\n this.db.prepare(`\n INSERT INTO sync_ops (\n id,\n tx_id,\n workspace,\n path,\n op_type,\n stage,\n source_path,\n resource,\n content_type,\n source,\n projection,\n source_version,\n after_hash,\n workspace_json,\n change_json,\n retry_count,\n created_at,\n updated_at\n )\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?)\n `).run(\n opId,\n txId ?? null,\n workspace.workspace,\n normalizedChange.path,\n normalizedChange.type,\n 'local_committed',\n normalizedChange.sourcePath,\n normalizedChange.resource ?? null,\n normalizedChange.contentType ?? null,\n normalizedChange.source,\n normalizedChange.projection,\n normalizedChange.sourceVersion ?? null,\n afterHash ?? null,\n JSON.stringify(journalWorkspace),\n JSON.stringify(normalizedChange),\n now,\n now,\n );\n\n return this.getOperation(opId)!;\n }\n\n public getOperation(id: string): SolidFsSyncJournalOperation | undefined {\n const row = this.db.prepare<SyncOpRow>(`\n SELECT id, tx_id, workspace_json, change_json, stage, after_hash, retry_count,\n last_error, created_at, updated_at, done_at\n FROM sync_ops\n WHERE id = ?\n `).get(id);\n return row ? rowToOperation(row) : undefined;\n }\n\n public listOperations(stages?: SolidFsSyncJournalStage[]): SolidFsSyncJournalOperation[] {\n const rows = stages && stages.length > 0\n ? this.db.prepare<SyncOpRow>(`\n SELECT id, tx_id, workspace_json, change_json, stage, after_hash, retry_count,\n last_error, created_at, updated_at, done_at\n FROM sync_ops\n WHERE stage IN (${stages.map(() => '?').join(', ')})\n ORDER BY created_at ASC, id ASC\n `).all(...stages)\n : this.db.prepare<SyncOpRow>(`\n SELECT id, tx_id, workspace_json, change_json, stage, after_hash, retry_count,\n last_error, created_at, updated_at, done_at\n FROM sync_ops\n ORDER BY created_at ASC, id ASC\n `).all();\n return rows.map(rowToOperation);\n }\n\n public listPending(): SolidFsSyncJournalOperation[] {\n return this.listOperations(['local_committed', 'failed_retryable']);\n }\n\n public async markDone(id: string): Promise<void> {\n const op = this.getOperation(id);\n if (!op) {\n return;\n }\n\n const now = this.now();\n this.db.transaction(() => {\n this.db.prepare(`\n UPDATE sync_ops\n SET stage = 'done',\n last_error = NULL,\n done_at = ?,\n updated_at = ?,\n tombstone_confirmed_at = CASE WHEN op_type = 'deleted' THEN ? ELSE tombstone_confirmed_at END\n WHERE id = ?\n `).run(now, now, now, id);\n\n this.upsertCheckpoint(op, now);\n })();\n }\n\n public async markRetryableFailure(id: string, error: unknown): Promise<void> {\n const now = this.now();\n this.db.prepare(`\n UPDATE sync_ops\n SET stage = 'failed_retryable',\n retry_count = retry_count + 1,\n last_error = ?,\n updated_at = ?\n WHERE id = ?\n `).run(errorMessage(error), now, id);\n }\n\n public async markReconcileRequired(id: string, reason: string): Promise<void> {\n const now = this.now();\n this.db.prepare(`\n UPDATE sync_ops\n SET stage = 'reconcile_required',\n last_error = ?,\n updated_at = ?\n WHERE id = ?\n `).run(reason, now, id);\n }\n\n public async markFailedPermanent(id: string, error: unknown): Promise<void> {\n const now = this.now();\n this.db.prepare(`\n UPDATE sync_ops\n SET stage = 'failed_permanent',\n last_error = ?,\n updated_at = ?\n WHERE id = ?\n `).run(errorMessage(error), now, id);\n }\n\n public async replayPending(syncer: SolidFsSyncer, context?: unknown): Promise<SolidFsJournalReplayResult> {\n const result: SolidFsJournalReplayResult = {\n attempted: 0,\n completed: 0,\n failed: 0,\n reconcileRequired: 0,\n };\n\n for (const op of this.listPending()) {\n result.attempted += 1;\n const validation = await this.validateOperationForReplay(op);\n if (validation) {\n await this.markReconcileRequired(op.id, validation);\n result.reconcileRequired += 1;\n continue;\n }\n\n try {\n await syncer.sync(op.change, op.workspace, context);\n await this.markDone(op.id);\n result.completed += 1;\n } catch (error) {\n await this.markRetryableFailure(op.id, error);\n result.failed += 1;\n }\n }\n\n return result;\n }\n\n public async bootstrapWorkspace(input: SolidFsJournalBootstrapInput): Promise<SolidFsJournalBootstrapResult> {\n const projection = input.projection ?? 'direct';\n const source = input.source ?? sourceForProjection(projection, input.workspace);\n const manifest: SolidFsManifest = {\n workspace: input.workspace,\n cwd: input.cwd,\n projection,\n entries: [],\n };\n\n const snapshots = await snapshotDirectory(input.cwd, input.shouldTrackPath);\n const currentPaths = new Set(snapshots.map((snapshot) => snapshot.relativePath));\n const result: SolidFsJournalBootstrapResult = {\n scanned: snapshots.length,\n enqueued: 0,\n skipped: 0,\n };\n\n for (const snapshot of snapshots) {\n const checkpoint = this.getCheckpoint(input.workspace, snapshot.relativePath);\n if (checkpoint?.source_version === snapshot.version && !checkpoint.deleted_at) {\n result.skipped += 1;\n continue;\n }\n\n const op = await this.recordLocalCommitted({\n path: snapshot.relativePath,\n resource: resolveWorkspaceResource(input.workspace, snapshot.relativePath),\n source,\n sourcePath: snapshot.absolutePath,\n contentType: contentTypeForPath(snapshot.relativePath),\n projection,\n type: 'created',\n }, manifest);\n result.enqueued += op.stage === 'done' ? 0 : 1;\n }\n\n const checkpoints = this.listCheckpoints(input.workspace);\n for (const checkpoint of checkpoints) {\n if (currentPaths.has(checkpoint.path) || checkpoint.deleted_at) {\n continue;\n }\n const op = await this.recordLocalCommitted({\n path: checkpoint.path,\n resource: resolveWorkspaceResource(input.workspace, checkpoint.path),\n source,\n sourcePath: path.join(input.cwd, checkpoint.path),\n contentType: contentTypeForPath(checkpoint.path),\n projection,\n type: 'deleted',\n sourceVersion: checkpoint.source_version ?? undefined,\n }, manifest);\n result.enqueued += op.stage === 'done' ? 0 : 1;\n }\n\n return result;\n }\n\n public async compact(): Promise<SolidFsJournalCompactResult> {\n const now = this.now();\n const rows = this.db.prepare<{\n id: string;\n workspace: string;\n path: string;\n op_type: SolidFsChange['type'];\n after_hash: string | null;\n stage: SolidFsSyncJournalStage;\n done_at: number | null;\n updated_at: number;\n tombstone_confirmed_at: number | null;\n }>(`\n SELECT id, workspace, path, op_type, after_hash, stage, done_at, updated_at, tombstone_confirmed_at\n FROM sync_ops\n WHERE stage IN ('done', 'failed_permanent')\n ORDER BY created_at ASC\n `).all();\n\n const deletable: string[] = [];\n for (const row of rows) {\n if (row.stage === 'failed_permanent') {\n if (row.updated_at <= now - this.failedPermanentRetentionMs) {\n deletable.push(row.id);\n }\n continue;\n }\n\n if (!row.done_at) {\n continue;\n }\n const checkpoint = this.getCheckpoint(row.workspace, row.path);\n if (!checkpoint) {\n continue;\n }\n if (row.op_type === 'deleted') {\n if (\n row.done_at <= now - this.tombstoneRetentionMs &&\n row.tombstone_confirmed_at &&\n checkpoint.deleted_at\n ) {\n deletable.push(row.id);\n }\n continue;\n }\n\n if (row.done_at <= now - this.doneRetentionMs && checkpoint.source_version === row.after_hash) {\n deletable.push(row.id);\n }\n }\n\n if (deletable.length === 0) {\n return { deletedOps: 0 };\n }\n\n this.db.transaction(() => {\n const deleteStatement = this.db.prepare('DELETE FROM sync_ops WHERE id = ?');\n for (const id of deletable) {\n deleteStatement.run(id);\n }\n })();\n\n return { deletedOps: deletable.length };\n }\n\n private async validateOperationForReplay(op: SolidFsSyncJournalOperation): Promise<string | undefined> {\n if (op.change.type === 'deleted') {\n return undefined;\n }\n\n const currentHash = await maybeFileVersion(op.change.sourcePath);\n if (!currentHash) {\n return `SolidFS journal source is missing: ${op.change.sourcePath}`;\n }\n if (op.afterHash && currentHash !== op.afterHash) {\n return `SolidFS journal source changed before replay: ${op.change.path}`;\n }\n return undefined;\n }\n\n private getCheckpoint(workspace: string, relativePath: string): CheckpointRow | undefined {\n return this.db.prepare<CheckpointRow>(`\n SELECT source_version, deleted_at\n FROM sync_checkpoints\n WHERE workspace = ? AND path = ?\n `).get(workspace, relativePath);\n }\n\n private listCheckpoints(workspace: string): Array<CheckpointRow & { path: string }> {\n return this.db.prepare<CheckpointRow & { path: string }>(`\n SELECT path, source_version, deleted_at\n FROM sync_checkpoints\n WHERE workspace = ?\n ORDER BY path ASC\n `).all(workspace);\n }\n\n private upsertCheckpoint(op: SolidFsSyncJournalOperation, now: number): void {\n if (op.change.type === 'deleted') {\n this.db.prepare(`\n INSERT INTO sync_checkpoints (workspace, path, source_version, deleted_at, updated_at, last_op_id)\n VALUES (?, ?, NULL, ?, ?, ?)\n ON CONFLICT(workspace, path) DO UPDATE SET\n source_version = NULL,\n deleted_at = excluded.deleted_at,\n updated_at = excluded.updated_at,\n last_op_id = excluded.last_op_id\n `).run(op.workspace.workspace, op.change.path, now, now, op.id);\n return;\n }\n\n this.db.prepare(`\n INSERT INTO sync_checkpoints (workspace, path, source_version, deleted_at, updated_at, last_op_id)\n VALUES (?, ?, ?, NULL, ?, ?)\n ON CONFLICT(workspace, path) DO UPDATE SET\n source_version = excluded.source_version,\n deleted_at = NULL,\n updated_at = excluded.updated_at,\n last_op_id = excluded.last_op_id\n `).run(op.workspace.workspace, op.change.path, op.afterHash ?? null, now, op.id);\n }\n\n private initializeSchema(): void {\n this.db.exec(`\n CREATE TABLE IF NOT EXISTS sync_ops (\n id TEXT PRIMARY KEY,\n tx_id TEXT,\n workspace TEXT NOT NULL,\n path TEXT NOT NULL,\n op_type TEXT NOT NULL,\n stage TEXT NOT NULL,\n source_path TEXT NOT NULL,\n resource TEXT,\n content_type TEXT,\n source TEXT NOT NULL,\n projection TEXT NOT NULL,\n source_version TEXT,\n after_hash TEXT,\n workspace_json TEXT NOT NULL,\n change_json TEXT NOT NULL,\n retry_count INTEGER NOT NULL DEFAULT 0,\n last_error TEXT,\n created_at INTEGER NOT NULL,\n updated_at INTEGER NOT NULL,\n done_at INTEGER,\n tombstone_confirmed_at INTEGER\n );\n\n CREATE INDEX IF NOT EXISTS sync_ops_stage_created_idx\n ON sync_ops(stage, created_at);\n CREATE INDEX IF NOT EXISTS sync_ops_workspace_path_idx\n ON sync_ops(workspace, path);\n\n CREATE TABLE IF NOT EXISTS sync_checkpoints (\n workspace TEXT NOT NULL,\n path TEXT NOT NULL,\n source_version TEXT,\n deleted_at INTEGER,\n updated_at INTEGER NOT NULL,\n last_op_id TEXT,\n PRIMARY KEY (workspace, path)\n );\n `);\n }\n}\n\nexport interface JournaledSolidFsSyncerOptions {\n syncer: SolidFsSyncer;\n journal: SqliteSolidFsSyncJournal;\n}\n\nexport interface WorkspaceJournaledSolidFsSyncerOptions {\n syncer: SolidFsSyncer;\n journalRoot?: string;\n resolveJournalPath?: (workspace: SolidFsManifest) => string;\n now?: () => number;\n doneRetentionMs?: number;\n tombstoneRetentionMs?: number;\n failedPermanentRetentionMs?: number;\n}\n\nexport class JournaledSolidFsSyncer implements SolidFsSyncer {\n private readonly syncer: SolidFsSyncer;\n private readonly journal: SqliteSolidFsSyncJournal;\n\n public constructor(options: JournaledSolidFsSyncerOptions) {\n this.syncer = options.syncer;\n this.journal = options.journal;\n }\n\n public shouldTrack(input: SolidFsPrepareInput): boolean {\n return this.syncer.shouldTrack?.(input) ?? true;\n }\n\n public shouldTrackPath(relativePath: string): boolean {\n return this.syncer.shouldTrackPath?.(relativePath) ?? isLineAddressableRdfPath(relativePath);\n }\n\n public async sync(change: SolidFsChange, workspace: SolidFsManifest, context?: unknown): Promise<void> {\n const op = await this.journal.recordLocalCommitted(change, workspace);\n if (op.stage === 'done') {\n return;\n }\n\n try {\n await this.syncer.sync(change, workspace, context);\n await this.journal.markDone(op.id);\n } catch (error) {\n await this.journal.markRetryableFailure(op.id, error);\n throw error;\n }\n }\n\n public async replayPending(context?: unknown): Promise<SolidFsJournalReplayResult> {\n return this.journal.replayPending(this.syncer, context);\n }\n\n public async compact(): Promise<SolidFsJournalCompactResult> {\n return this.journal.compact();\n }\n\n public async bootstrapWorkspace(\n input: Omit<SolidFsJournalBootstrapInput, 'shouldTrackPath'> & {\n shouldTrackPath?: (relativePath: string) => boolean;\n },\n ): Promise<SolidFsJournalBootstrapResult> {\n return this.journal.bootstrapWorkspace({\n ...input,\n shouldTrackPath: input.shouldTrackPath ?? this.shouldTrackPath.bind(this),\n });\n }\n}\n\nexport class WorkspaceJournaledSolidFsSyncer implements SolidFsSyncer {\n private readonly syncer: SolidFsSyncer;\n private readonly journals = new Map<string, SqliteSolidFsSyncJournal>();\n\n public constructor(private readonly options: WorkspaceJournaledSolidFsSyncerOptions) {\n this.syncer = options.syncer;\n }\n\n public shouldTrack(input: SolidFsPrepareInput): boolean {\n return this.syncer.shouldTrack?.(input) ?? true;\n }\n\n public shouldTrackPath(relativePath: string): boolean {\n return this.syncer.shouldTrackPath?.(relativePath) ?? isLineAddressableRdfPath(relativePath);\n }\n\n public async initializeWorkspace(workspace: SolidFsManifest, context?: unknown): Promise<void> {\n const journal = this.journalFor(workspace);\n await journal.bootstrapWorkspace({\n workspace: workspace.workspace,\n cwd: workspace.cwd,\n projection: workspace.projection,\n source: sourceForProjection(workspace.projection, workspace.workspace),\n shouldTrackPath: this.shouldTrackPath.bind(this),\n });\n await journal.replayPending(this.syncer, context);\n await journal.compact();\n }\n\n public async sync(change: SolidFsChange, workspace: SolidFsManifest, context?: unknown): Promise<void> {\n const journal = this.journalFor(workspace);\n const op = await journal.recordLocalCommitted(change, workspace);\n if (op.stage === 'done') {\n return;\n }\n\n try {\n await this.syncer.sync(change, workspace, context);\n await journal.markDone(op.id);\n } catch (error) {\n await journal.markRetryableFailure(op.id, error);\n throw error;\n }\n }\n\n public async replayPending(workspace: SolidFsManifest, context?: unknown): Promise<SolidFsJournalReplayResult> {\n return this.journalFor(workspace).replayPending(this.syncer, context);\n }\n\n public async compact(workspace: SolidFsManifest): Promise<SolidFsJournalCompactResult> {\n return this.journalFor(workspace).compact();\n }\n\n public journalPathFor(workspace: SolidFsManifest): string {\n return this.options.resolveJournalPath?.(workspace)\n ?? resolveSolidFsJournalPath(workspace, this.options.journalRoot ?? process.env.XPOD_SOLIDFS_JOURNAL_ROOT);\n }\n\n public close(): void {\n for (const journal of this.journals.values()) {\n journal.close();\n }\n this.journals.clear();\n }\n\n private journalFor(workspace: SolidFsManifest): SqliteSolidFsSyncJournal {\n const journalPath = this.journalPathFor(workspace);\n const existing = this.journals.get(journalPath);\n if (existing) {\n return existing;\n }\n\n const journal = new SqliteSolidFsSyncJournal({\n path: journalPath,\n now: this.options.now,\n doneRetentionMs: this.options.doneRetentionMs,\n tombstoneRetentionMs: this.options.tombstoneRetentionMs,\n failedPermanentRetentionMs: this.options.failedPermanentRetentionMs,\n });\n this.journals.set(journalPath, journal);\n return journal;\n }\n}\n\nexport function resolveSolidFsJournalPath(workspace: SolidFsManifest, journalRoot?: string): string {\n const root = journalRoot\n ? path.resolve(journalRoot)\n : path.join(path.dirname(path.resolve(workspace.cwd)), '.xpod-control', 'solidfs-journals');\n const basename = safeJournalSegment(path.basename(workspace.cwd) || 'workspace');\n const key = createHash('sha256')\n .update(workspace.workspace)\n .digest('hex')\n .slice(0, 16);\n return path.join(root, `${basename}-${key}`, 'sync-journal.sqlite');\n}\n\nfunction rowToOperation(row: SyncOpRow): SolidFsSyncJournalOperation {\n return {\n id: row.id,\n txId: row.tx_id ?? undefined,\n workspace: JSON.parse(row.workspace_json) as SolidFsManifest,\n change: JSON.parse(row.change_json) as SolidFsChange,\n stage: row.stage,\n afterHash: row.after_hash ?? undefined,\n retryCount: row.retry_count,\n lastError: row.last_error ?? undefined,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n doneAt: row.done_at ?? undefined,\n };\n}\n\nfunction journalWorkspaceSnapshot(workspace: SolidFsManifest): SolidFsManifest {\n return {\n workspace: workspace.workspace,\n cwd: workspace.cwd,\n projection: workspace.projection,\n entries: [],\n };\n}\n\nfunction normalizeChange(change: SolidFsChange): SolidFsChange {\n return {\n ...change,\n path: change.path.split(/[\\\\/]+/u).join(path.sep),\n };\n}\n\nfunction operationId(workspace: string, change: SolidFsChange, afterHash?: string): string {\n const digest = createHash('sha256')\n .update(JSON.stringify({\n workspace,\n path: change.path,\n type: change.type,\n resource: change.resource,\n source: change.source,\n sourcePath: change.sourcePath,\n projection: change.projection,\n sourceVersion: change.sourceVersion,\n afterHash,\n }))\n .digest('hex')\n .slice(0, 32);\n return `sync_${digest}`;\n}\n\nfunction safeJournalSegment(value: string): string {\n const safe = value.replace(/[^a-zA-Z0-9._-]+/gu, '_').slice(0, 64);\n return safe || 'workspace';\n}\n\nfunction errorMessage(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n}\n"]}
|
package/dist/solidfs/index.d.ts
CHANGED
package/dist/solidfs/index.js
CHANGED
|
@@ -21,4 +21,5 @@ __exportStar(require("./PodSolidFsHydrator"), exports);
|
|
|
21
21
|
__exportStar(require("./RdfIndexSolidFsSyncer"), exports);
|
|
22
22
|
__exportStar(require("./PodSolidFsSyncer"), exports);
|
|
23
23
|
__exportStar(require("./LocalFirstRdfRepresentationResolver"), exports);
|
|
24
|
+
__exportStar(require("./SolidFsSyncJournal"), exports);
|
|
24
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/solidfs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,iDAA+B;AAC/B,yDAAuC;AACvC,uDAAqC;AACrC,0DAAwC;AACxC,qDAAmC;AACnC,wEAAsD","sourcesContent":["export * from './types';\nexport * from './LocalSolidFS';\nexport * from './PodSolidFsHttpClient';\nexport * from './PodSolidFsHydrator';\nexport * from './RdfIndexSolidFsSyncer';\nexport * from './PodSolidFsSyncer';\nexport * from './LocalFirstRdfRepresentationResolver';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/solidfs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,iDAA+B;AAC/B,yDAAuC;AACvC,uDAAqC;AACrC,0DAAwC;AACxC,qDAAmC;AACnC,wEAAsD;AACtD,uDAAqC","sourcesContent":["export * from './types';\nexport * from './LocalSolidFS';\nexport * from './PodSolidFsHttpClient';\nexport * from './PodSolidFsHydrator';\nexport * from './RdfIndexSolidFsSyncer';\nexport * from './PodSolidFsSyncer';\nexport * from './LocalFirstRdfRepresentationResolver';\nexport * from './SolidFsSyncJournal';\n"]}
|
package/dist/solidfs/types.d.ts
CHANGED
|
@@ -96,6 +96,7 @@ export interface SolidFS {
|
|
|
96
96
|
export interface SolidFsSyncer {
|
|
97
97
|
shouldTrack?(input: SolidFsPrepareInput): boolean;
|
|
98
98
|
shouldTrackPath?(relativePath: string): boolean;
|
|
99
|
+
initializeWorkspace?(workspace: SolidFsManifest, context?: unknown): Promise<void>;
|
|
99
100
|
sync(change: SolidFsChange, workspace: SolidFsManifest, context?: unknown): Promise<void>;
|
|
100
101
|
}
|
|
101
102
|
export interface SolidFsHydrateInput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/solidfs/types.ts"],"names":[],"mappings":";;;AA6EA,MAAa,oBAAqB,SAAQ,KAAK;IAG7C,YAAmB,SAA4B;QAC7C,KAAK,CAAC,4BAA4B,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AARD,oDAQC;AAED,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC","sourcesContent":["export type SolidFsProjection = 'direct' | 'copy' | 'hydrated-object';\nexport type SolidFsEntrySource = 'filesystem' | 'pod-http' | 'object';\n\nexport type SolidFsEntryState = 'clean' | 'dirty' | 'committed' | 'conflict';\nexport type SolidFsChangeType = 'created' | 'updated' | 'deleted';\n\nexport interface SolidFsRunRef {\n id?: string;\n workspace?: string;\n}\n\nexport interface SolidFsPrepareInput {\n run?: SolidFsRunRef;\n workspace: string;\n /**\n * Adapter-provided local source path for workspaces that are resolved by\n * the runner before SolidFS materializes them, such as Pod HTTPS containers.\n */\n sourcePath?: string;\n projection?: SolidFsProjection;\n /**\n * Opaque request/runtime context used by adapter syncers. SolidFS itself must\n * not inspect or persist this value because it can contain credentials.\n */\n context?: unknown;\n}\n\nexport interface SolidFsManifestEntry {\n path: string;\n resource?: string;\n source: SolidFsEntrySource;\n sourcePath: string;\n contentType?: string;\n projection: SolidFsProjection;\n /**\n * Opaque authority-side version token, such as an ETag, object version, RDF\n * revision, or filesystem hash. For local filesystem projections this can be\n * the same value used for dirty detection.\n */\n sourceVersion?: string;\n /**\n * Local working-copy version captured when the entry was materialized. This\n * lets hydrated objects keep an authority ETag in sourceVersion while still\n * detecting local edits by hashing the working file.\n */\n workingVersion?: string;\n lastAccessedAt?: number;\n state: SolidFsEntryState;\n}\n\nexport interface SolidFsChange {\n path: string;\n resource?: string;\n source: SolidFsEntrySource;\n sourcePath: string;\n contentType?: string;\n projection: SolidFsProjection;\n type: SolidFsChangeType;\n sourceVersion?: string;\n}\n\nexport interface SolidFsManifest {\n workspace: string;\n cwd: string;\n projection: SolidFsProjection;\n entries: SolidFsManifestEntry[];\n changes?: SolidFsChange[];\n}\n\nexport interface SolidFsConflict {\n path: string;\n sourcePath: string;\n expectedVersion?: string;\n actualVersion?: string;\n message: string;\n}\n\nexport class SolidFsConflictError extends Error {\n public readonly conflicts: SolidFsConflict[];\n\n public constructor(conflicts: SolidFsConflict[]) {\n super(`SolidFS commit conflict: ${conflicts.map((conflict) => conflict.path).join(', ')}`);\n this.name = 'SolidFsConflictError';\n this.conflicts = conflicts;\n }\n}\n\nexport class SolidFsNotFoundError extends Error {\n public constructor(message: string) {\n super(message);\n this.name = 'SolidFsNotFoundError';\n }\n}\n\nexport interface MaterializedWorkspace {\n cwd: string;\n manifest: SolidFsManifest;\n /**\n * Materialize one object-backed resource into the real cwd. Implementations\n * without object hydration support can leave this undefined.\n */\n hydrate?(relativePath: string): Promise<SolidFsManifestEntry>;\n /**\n * Remove clean hydrated working copies that are no longer needed. Dirty files\n * must never be pruned.\n */\n prune?(options?: SolidFsPruneOptions): Promise<SolidFsManifest>;\n commit(): Promise<SolidFsManifest>;\n rollback(): Promise<void>;\n}\n\nexport interface SolidFS {\n prepare(input: SolidFsPrepareInput): Promise<MaterializedWorkspace>;\n}\n\nexport interface SolidFsSyncer {\n shouldTrack?(input: SolidFsPrepareInput): boolean;\n shouldTrackPath?(relativePath: string): boolean;\n sync(change: SolidFsChange, workspace: SolidFsManifest, context?: unknown): Promise<void>;\n}\n\nexport interface SolidFsHydrateInput {\n path: string;\n targetPath: string;\n workspace: SolidFsManifest;\n context?: unknown;\n}\n\nexport interface SolidFsHydrateResult {\n contentType?: string;\n sourceVersion?: string;\n}\n\nexport interface SolidFsCommitHydratedInput {\n change: SolidFsChange;\n workspace: SolidFsManifest;\n context?: unknown;\n}\n\nexport interface SolidFsCommitHydratedResult {\n sourceVersion?: string;\n}\n\nexport interface SolidFsHydrator {\n hydrate(input: SolidFsHydrateInput): Promise<SolidFsHydrateResult | void>;\n commit(input: SolidFsCommitHydratedInput): Promise<SolidFsCommitHydratedResult | void>;\n delete?(input: SolidFsCommitHydratedInput): Promise<void>;\n}\n\nexport interface SolidFsPruneOptions {\n /**\n * Prune clean hydrated files not accessed for at least this many ms.\n * Defaults to 0, meaning any clean hydrated file is eligible.\n */\n olderThanMs?: number;\n now?: number;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/solidfs/types.ts"],"names":[],"mappings":";;;AA6EA,MAAa,oBAAqB,SAAQ,KAAK;IAG7C,YAAmB,SAA4B;QAC7C,KAAK,CAAC,4BAA4B,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AARD,oDAQC;AAED,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC","sourcesContent":["export type SolidFsProjection = 'direct' | 'copy' | 'hydrated-object';\nexport type SolidFsEntrySource = 'filesystem' | 'pod-http' | 'object';\n\nexport type SolidFsEntryState = 'clean' | 'dirty' | 'committed' | 'conflict';\nexport type SolidFsChangeType = 'created' | 'updated' | 'deleted';\n\nexport interface SolidFsRunRef {\n id?: string;\n workspace?: string;\n}\n\nexport interface SolidFsPrepareInput {\n run?: SolidFsRunRef;\n workspace: string;\n /**\n * Adapter-provided local source path for workspaces that are resolved by\n * the runner before SolidFS materializes them, such as Pod HTTPS containers.\n */\n sourcePath?: string;\n projection?: SolidFsProjection;\n /**\n * Opaque request/runtime context used by adapter syncers. SolidFS itself must\n * not inspect or persist this value because it can contain credentials.\n */\n context?: unknown;\n}\n\nexport interface SolidFsManifestEntry {\n path: string;\n resource?: string;\n source: SolidFsEntrySource;\n sourcePath: string;\n contentType?: string;\n projection: SolidFsProjection;\n /**\n * Opaque authority-side version token, such as an ETag, object version, RDF\n * revision, or filesystem hash. For local filesystem projections this can be\n * the same value used for dirty detection.\n */\n sourceVersion?: string;\n /**\n * Local working-copy version captured when the entry was materialized. This\n * lets hydrated objects keep an authority ETag in sourceVersion while still\n * detecting local edits by hashing the working file.\n */\n workingVersion?: string;\n lastAccessedAt?: number;\n state: SolidFsEntryState;\n}\n\nexport interface SolidFsChange {\n path: string;\n resource?: string;\n source: SolidFsEntrySource;\n sourcePath: string;\n contentType?: string;\n projection: SolidFsProjection;\n type: SolidFsChangeType;\n sourceVersion?: string;\n}\n\nexport interface SolidFsManifest {\n workspace: string;\n cwd: string;\n projection: SolidFsProjection;\n entries: SolidFsManifestEntry[];\n changes?: SolidFsChange[];\n}\n\nexport interface SolidFsConflict {\n path: string;\n sourcePath: string;\n expectedVersion?: string;\n actualVersion?: string;\n message: string;\n}\n\nexport class SolidFsConflictError extends Error {\n public readonly conflicts: SolidFsConflict[];\n\n public constructor(conflicts: SolidFsConflict[]) {\n super(`SolidFS commit conflict: ${conflicts.map((conflict) => conflict.path).join(', ')}`);\n this.name = 'SolidFsConflictError';\n this.conflicts = conflicts;\n }\n}\n\nexport class SolidFsNotFoundError extends Error {\n public constructor(message: string) {\n super(message);\n this.name = 'SolidFsNotFoundError';\n }\n}\n\nexport interface MaterializedWorkspace {\n cwd: string;\n manifest: SolidFsManifest;\n /**\n * Materialize one object-backed resource into the real cwd. Implementations\n * without object hydration support can leave this undefined.\n */\n hydrate?(relativePath: string): Promise<SolidFsManifestEntry>;\n /**\n * Remove clean hydrated working copies that are no longer needed. Dirty files\n * must never be pruned.\n */\n prune?(options?: SolidFsPruneOptions): Promise<SolidFsManifest>;\n commit(): Promise<SolidFsManifest>;\n rollback(): Promise<void>;\n}\n\nexport interface SolidFS {\n prepare(input: SolidFsPrepareInput): Promise<MaterializedWorkspace>;\n}\n\nexport interface SolidFsSyncer {\n shouldTrack?(input: SolidFsPrepareInput): boolean;\n shouldTrackPath?(relativePath: string): boolean;\n initializeWorkspace?(workspace: SolidFsManifest, context?: unknown): Promise<void>;\n sync(change: SolidFsChange, workspace: SolidFsManifest, context?: unknown): Promise<void>;\n}\n\nexport interface SolidFsHydrateInput {\n path: string;\n targetPath: string;\n workspace: SolidFsManifest;\n context?: unknown;\n}\n\nexport interface SolidFsHydrateResult {\n contentType?: string;\n sourceVersion?: string;\n}\n\nexport interface SolidFsCommitHydratedInput {\n change: SolidFsChange;\n workspace: SolidFsManifest;\n context?: unknown;\n}\n\nexport interface SolidFsCommitHydratedResult {\n sourceVersion?: string;\n}\n\nexport interface SolidFsHydrator {\n hydrate(input: SolidFsHydrateInput): Promise<SolidFsHydrateResult | void>;\n commit(input: SolidFsCommitHydratedInput): Promise<SolidFsCommitHydratedResult | void>;\n delete?(input: SolidFsCommitHydratedInput): Promise<void>;\n}\n\nexport interface SolidFsPruneOptions {\n /**\n * Prune clean hydrated files not accessed for at least this many ms.\n * Defaults to 0, meaning any clean hydrated file is eligible.\n */\n olderThanMs?: number;\n now?: number;\n}\n"]}
|
|
@@ -7,6 +7,7 @@ const community_server_1 = require("@solid/community-server");
|
|
|
7
7
|
const StreamUtil_1 = require("@solid/community-server/dist/util/StreamUtil");
|
|
8
8
|
const global_logger_factory_1 = require("global-logger-factory");
|
|
9
9
|
const LocalFirstRdfRepresentationResolver_1 = require("../solidfs/LocalFirstRdfRepresentationResolver");
|
|
10
|
+
const RdfSparqlAdapter_1 = require("./rdf/RdfSparqlAdapter");
|
|
10
11
|
/**
|
|
11
12
|
* ResourceStore that short-circuits PATCH into direct SPARQL UPDATE
|
|
12
13
|
* when the underlying DataAccessor supports it.
|
|
@@ -61,7 +62,18 @@ class SparqlUpdateResourceStore extends community_server_1.DataAccessorBasedStor
|
|
|
61
62
|
throw new community_server_1.NotImplementedHttpError('Unsupported PATCH payload for SPARQL conversion');
|
|
62
63
|
}
|
|
63
64
|
this.logger.debug(`Applying SPARQL PATCH to ${identifier.path}: ${sparqlUpdate}`);
|
|
64
|
-
|
|
65
|
+
try {
|
|
66
|
+
await accessor.executeSparqlUpdate(sparqlUpdate, identifier.path);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof RdfSparqlAdapter_1.DisabledSparqlFeatureError) {
|
|
70
|
+
throw new community_server_1.ForbiddenHttpError(error.message, { cause: error });
|
|
71
|
+
}
|
|
72
|
+
if (error instanceof RdfSparqlAdapter_1.UnsupportedSparqlQueryError) {
|
|
73
|
+
throw new community_server_1.BadRequestHttpError(error.message, { cause: error });
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
65
77
|
// PATCH does not affect containment; mark the target resource as updated.
|
|
66
78
|
const changes = new Map();
|
|
67
79
|
changes.set(identifier, new community_server_1.RepresentationMetadata(identifier, { [community_server_1.SOLID_AS.activity]: community_server_1.AS.terms.Update }));
|
|
@@ -115,12 +127,54 @@ class SparqlUpdateResourceStore extends community_server_1.DataAccessorBasedStor
|
|
|
115
127
|
graph: (!triple.graph || triple.graph.termType === 'DefaultGraph') ? targetGraph : triple.graph,
|
|
116
128
|
}));
|
|
117
129
|
};
|
|
130
|
+
const triplesFromTemplateBlock = (item) => {
|
|
131
|
+
if (Array.isArray(item?.triples)) {
|
|
132
|
+
return item.triples;
|
|
133
|
+
}
|
|
134
|
+
if (!Array.isArray(item?.patterns)) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
return item.patterns.flatMap((pattern) => pattern?.type === 'bgp' && Array.isArray(pattern.triples) ? pattern.triples : []);
|
|
138
|
+
};
|
|
139
|
+
const rewriteQuadBlocks = (items) => {
|
|
140
|
+
if (!items)
|
|
141
|
+
return items;
|
|
142
|
+
return items.flatMap((item) => {
|
|
143
|
+
if (item?.type === 'graph') {
|
|
144
|
+
assertGraphAllowed(item.name);
|
|
145
|
+
const targetGraph = item.name ?? graph;
|
|
146
|
+
return [{
|
|
147
|
+
...item,
|
|
148
|
+
name: targetGraph,
|
|
149
|
+
triples: rewriteTriples(triplesFromTemplateBlock(item), targetGraph),
|
|
150
|
+
patterns: undefined,
|
|
151
|
+
}];
|
|
152
|
+
}
|
|
153
|
+
if (item?.type === 'bgp') {
|
|
154
|
+
return [{
|
|
155
|
+
type: 'graph',
|
|
156
|
+
name: graph,
|
|
157
|
+
triples: rewriteTriples(item.triples, graph),
|
|
158
|
+
}];
|
|
159
|
+
}
|
|
160
|
+
return [{
|
|
161
|
+
type: 'graph',
|
|
162
|
+
name: graph,
|
|
163
|
+
triples: rewriteTriples([item], graph),
|
|
164
|
+
}];
|
|
165
|
+
});
|
|
166
|
+
};
|
|
118
167
|
const rewritePattern = (pattern) => {
|
|
119
168
|
if (pattern.type === 'bgp') {
|
|
120
|
-
return { ...pattern, triples: rewriteTriples(pattern.triples) };
|
|
169
|
+
return { ...pattern, triples: rewriteTriples(pattern.triples, graph) };
|
|
121
170
|
}
|
|
122
171
|
if (pattern.type === 'graph') {
|
|
123
|
-
|
|
172
|
+
assertGraphAllowed(pattern.name);
|
|
173
|
+
return {
|
|
174
|
+
...pattern,
|
|
175
|
+
name: pattern.name ?? graph,
|
|
176
|
+
patterns: pattern.patterns?.map(rewritePattern) ?? [],
|
|
177
|
+
};
|
|
124
178
|
}
|
|
125
179
|
if (pattern.type === 'group') {
|
|
126
180
|
return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };
|
|
@@ -148,28 +202,21 @@ class SparqlUpdateResourceStore extends community_server_1.DataAccessorBasedStor
|
|
|
148
202
|
}
|
|
149
203
|
return pattern;
|
|
150
204
|
};
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
153
|
-
return items;
|
|
154
|
-
return items.map((item) => {
|
|
155
|
-
if (item?.type === 'graph') {
|
|
156
|
-
assertGraphAllowed(item.name);
|
|
157
|
-
return {
|
|
158
|
-
...item,
|
|
159
|
-
name: item.name ?? graph,
|
|
160
|
-
triples: rewriteTriples(item.triples, item.name ?? graph),
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
// Treat as plain quad
|
|
205
|
+
const rewriteWherePatterns = (patterns) => (patterns ?? []).map((pattern) => {
|
|
206
|
+
if (pattern?.type === 'bgp') {
|
|
164
207
|
return {
|
|
165
208
|
type: 'graph',
|
|
166
209
|
name: graph,
|
|
167
|
-
|
|
210
|
+
patterns: [{
|
|
211
|
+
...pattern,
|
|
212
|
+
triples: rewriteTriples(pattern.triples, graph),
|
|
213
|
+
}],
|
|
168
214
|
};
|
|
169
|
-
}
|
|
170
|
-
|
|
215
|
+
}
|
|
216
|
+
return rewritePattern(pattern);
|
|
217
|
+
});
|
|
218
|
+
const toGraphQuads = (items) => rewriteQuadBlocks(items);
|
|
171
219
|
try {
|
|
172
|
-
console.log(`[normalizeGraphs] Input SPARQL (first 500 chars): ${updateText.slice(0, 500)}`);
|
|
173
220
|
const parsed = this.parser.parse(updateText);
|
|
174
221
|
// Explicitly reject SPARQL Queries (SELECT, ASK, CONSTRUCT) in PATCH
|
|
175
222
|
if (parsed.type === 'query') {
|
|
@@ -181,7 +228,16 @@ class SparqlUpdateResourceStore extends community_server_1.DataAccessorBasedStor
|
|
|
181
228
|
if (!entries)
|
|
182
229
|
return [];
|
|
183
230
|
if (Array.isArray(entries)) {
|
|
184
|
-
return entries.flatMap((entry) =>
|
|
231
|
+
return entries.flatMap((entry) => {
|
|
232
|
+
if (entry?.type === 'graph') {
|
|
233
|
+
assertGraphAllowed(entry.name);
|
|
234
|
+
return (entry.triples ?? []).map((triple) => ({
|
|
235
|
+
...triple,
|
|
236
|
+
graph: entry.name ?? graph,
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
return entry.triples ? entry.triples : (entry.quads ?? []);
|
|
240
|
+
});
|
|
185
241
|
}
|
|
186
242
|
return [];
|
|
187
243
|
});
|
|
@@ -253,25 +309,29 @@ class SparqlUpdateResourceStore extends community_server_1.DataAccessorBasedStor
|
|
|
253
309
|
}
|
|
254
310
|
parsed.updates = parsed.updates.map((op) => {
|
|
255
311
|
switch (op.updateType) {
|
|
312
|
+
case 'deletewhere':
|
|
313
|
+
return {
|
|
314
|
+
...op,
|
|
315
|
+
delete: toGraphQuads(op.delete),
|
|
316
|
+
};
|
|
256
317
|
case 'deleteinsert':
|
|
257
318
|
case 'insertdelete':
|
|
258
319
|
return {
|
|
259
320
|
...op,
|
|
260
321
|
delete: toGraphQuads(op.delete),
|
|
261
322
|
insert: toGraphQuads(op.insert),
|
|
262
|
-
where: op.where
|
|
323
|
+
where: rewriteWherePatterns(op.where),
|
|
263
324
|
};
|
|
264
325
|
case 'delete':
|
|
265
|
-
case 'insert': {
|
|
266
|
-
const deleteQuads = toGraphQuads(op.delete) ?? [];
|
|
267
|
-
const insertQuads = toGraphQuads(op.insert) ?? [];
|
|
268
326
|
return {
|
|
269
|
-
|
|
270
|
-
delete:
|
|
271
|
-
|
|
272
|
-
|
|
327
|
+
...op,
|
|
328
|
+
delete: toGraphQuads(op.delete),
|
|
329
|
+
};
|
|
330
|
+
case 'insert':
|
|
331
|
+
return {
|
|
332
|
+
...op,
|
|
333
|
+
insert: toGraphQuads(op.insert),
|
|
273
334
|
};
|
|
274
|
-
}
|
|
275
335
|
default:
|
|
276
336
|
return op;
|
|
277
337
|
}
|
|
@@ -281,10 +341,11 @@ class SparqlUpdateResourceStore extends community_server_1.DataAccessorBasedStor
|
|
|
281
341
|
return normalized;
|
|
282
342
|
}
|
|
283
343
|
catch (error) {
|
|
284
|
-
|
|
285
|
-
|
|
344
|
+
if (community_server_1.HttpError.isInstance(error)) {
|
|
345
|
+
throw error;
|
|
346
|
+
}
|
|
347
|
+
this.logger.debug(`Could not parse SPARQL UPDATE for ${identifier.path}; applying default graph text fallback: ${error}`);
|
|
286
348
|
const fallbackResult = wrapDefaultGraph(updateText);
|
|
287
|
-
console.log(`[normalizeGraphs] Fallback result: ${fallbackResult.slice(0, 300)}`);
|
|
288
349
|
return fallbackResult;
|
|
289
350
|
}
|
|
290
351
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SparqlUpdateResourceStore.js","sourceRoot":"","sources":["../../src/storage/SparqlUpdateResourceStore.ts"],"names":[],"mappings":";;;AAAA,2BAAiC;AACjC,uCAAoJ;AACpJ,8DAgBiC;AAEjC,6EAAgF;AAChF,iEAAqD;AACrD,wGAGwD;AAUxD;;;GAGG;AACH,MAAa,yBAA0B,SAAQ,yCAAsB;IAMnE,YAAm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SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACpD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,gCAAgC,UAAU,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC,CAAC;YACtF,OAAO,UAAU,CAAC;QACpB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,sCAAsC,UAAU,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;YAC/E,OAAO,CAAC,GAAG,CAAC,gCAAgC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YACxE,MAAM,cAAc,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;YACpD,OAAO,CAAC,GAAG,CAAC,sCAAsC,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YAClF,OAAO,cAAc,CAAC;QACxB,CAAC;IACH,CAAC;IAEO,mBAAmB,CAAC,KAAY;QACtC,OAAO,OAAQ,KAA2B,CAAC,OAAO,KAAK,QAAQ,CAAC;IAClE,CAAC;IAEO,eAAe,CAAC,QAAiB;QAIvC,OAAO,OAAO,QAAQ,KAAK,QAAQ;YACjC,QAAQ,KAAK,IAAI;YACjB,OAAQ,QAA8C,CAAC,mBAAmB,KAAK,UAAU;YACzF,OAAQ,QAAsC,CAAC,WAAW,KAAK,UAAU,CAAC;IAC9E,CAAC;IAEe,KAAK,CAAC,iBAAiB,CAAC,UAA8B,EAAE,cAA8B,EAAE,UAAuB;QAC7H,OAAO,KAAK,CAAC,iBAAiB,CAAC,UAAU,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;IACzE,CAAC;CACF;AAnUD,8DAmUC","sourcesContent":["import { DataFactory } from 'n3';\nimport { Generator as SparqlGenerator, Parser as SparqlParser, type GraphQuads, type UpdateOperation, type Update as SparqlUpdate } from 'sparqljs';\nimport {\n DataAccessorBasedStore,\n type ChangeMap,\n type ResourceIdentifier,\n type Patch,\n NotImplementedHttpError,\n type Conditions,\n NotFoundHttpError,\n RepresentationMetadata,\n AS,\n SOLID_AS,\n BadRequestHttpError,\n type DataAccessor,\n type IdentifierStrategy,\n type AuxiliaryStrategy,\n type Representation,\n} from '@solid/community-server';\nimport type { SparqlUpdatePatch } from '@solid/community-server';\nimport { readableToString } from '@solid/community-server/dist/util/StreamUtil';\nimport { getLoggerFor } from 'global-logger-factory';\nimport {\n LocalFirstRdfRepresentationResolver,\n type LocalFirstRdfRepresentationResolverLike,\n} from '../solidfs/LocalFirstRdfRepresentationResolver';\n\nexport interface SparqlUpdateResourceStoreOptions {\n accessor: DataAccessor;\n identifierStrategy: IdentifierStrategy;\n auxiliaryStrategy: AuxiliaryStrategy;\n metadataStrategy: AuxiliaryStrategy;\n localFirstRdfRepresentationResolver?: LocalFirstRdfRepresentationResolverLike;\n}\n\n/**\n * ResourceStore that short-circuits PATCH into direct SPARQL UPDATE\n * when the underlying DataAccessor supports it.\n */\nexport class SparqlUpdateResourceStore extends DataAccessorBasedStore {\n private readonly generator = new SparqlGenerator();\n private readonly parser = new SparqlParser();\n private readonly localFirstRdfRepresentationResolver: LocalFirstRdfRepresentationResolverLike;\n protected override readonly logger = getLoggerFor(this);\n\n public constructor(options: SparqlUpdateResourceStoreOptions) {\n super(options.accessor, options.identifierStrategy, options.auxiliaryStrategy, options.metadataStrategy);\n this.localFirstRdfRepresentationResolver = options.localFirstRdfRepresentationResolver ??\n new LocalFirstRdfRepresentationResolver({\n accessor: options.accessor,\n metadataStrategy: options.metadataStrategy,\n });\n // Check if identifierStrategy has baseUrl property (SingleRootIdentifierStrategy)\n const strategy = options.identifierStrategy as unknown as { baseUrl?: string };\n this.logger.info(`SparqlUpdateResourceStore initialized with identifierStrategy: ${options.identifierStrategy.constructor.name}, baseUrl: ${strategy.baseUrl ?? 'N/A'}`);\n }\n\n public override async getRepresentation(identifier: ResourceIdentifier): Promise<Representation> {\n const localRepresentation = await this.localFirstRdfRepresentationResolver.resolve(identifier);\n if (localRepresentation) {\n return localRepresentation;\n }\n\n return super.getRepresentation(identifier);\n }\n\n // @ts-expect-error Upstream signature returns never; we return ChangeMap for successful PATCH.\n public override async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<ChangeMap> {\n this.logger.debug(`SparqlUpdateResourceStore.modifyResource called for ${identifier.path}`);\n this.logger.debug(`Patch has algebra: ${typeof (patch as SparqlUpdatePatch).algebra === 'object'}, metadata.contentType: ${patch.metadata?.contentType}`);\n\n const accessor = (this as unknown as { accessor: unknown }).accessor as unknown;\n if (!this.isSparqlCapable(accessor)) {\n this.logger.debug('Accessor is not SPARQL capable');\n throw new NotImplementedHttpError('SPARQL UPDATE not supported by this accessor');\n }\n\n // Keep the default condition validation semantics\n if (conditions) {\n let metadata: RepresentationMetadata | undefined;\n try {\n metadata = await accessor.getMetadata(identifier);\n } catch (error: unknown) {\n if (!NotFoundHttpError.isInstance(error)) {\n throw error;\n }\n }\n this.validateConditions(conditions, metadata);\n }\n\n const sparqlUpdate = await this.toSparqlUpdate(patch, identifier);\n if (!sparqlUpdate) {\n this.logger.debug(`toSparqlUpdate returned undefined for ${identifier.path}, falling back to CSS handler`);\n throw new NotImplementedHttpError('Unsupported PATCH payload for SPARQL conversion');\n }\n\n this.logger.debug(`Applying SPARQL PATCH to ${identifier.path}: ${sparqlUpdate}`);\n await accessor.executeSparqlUpdate(sparqlUpdate, identifier.path);\n\n // PATCH does not affect containment; mark the target resource as updated.\n const changes = new Map() as ChangeMap;\n changes.set(identifier, new RepresentationMetadata(identifier, { [SOLID_AS.activity]: AS.terms.Update }));\n return changes;\n }\n\n /**\n * 只处理 SPARQL UPDATE (application/sparql-update)。\n * N3 Patch 和其他类型返回 undefined,让 CSS PatchingStore 回退到 get-patch-set 逻辑。\n */\n private async toSparqlUpdate(patch: Patch, identifier: ResourceIdentifier): Promise<string | undefined> {\n // 只处理 SPARQL UPDATE,其他类型(包括 N3 Patch)回退到 CSS 默认处理\n if (!this.isSparqlUpdatePatch(patch)) {\n return undefined;\n }\n\n const updateText = await readableToString(patch.data);\n return this.normalizeGraphs(updateText, identifier);\n }\n\n /**\n * Ensure SPARQL UPDATE targets the resource graph (CSS stores documents in named graphs).\n */\n private normalizeGraphs(updateText: string, identifier: ResourceIdentifier): string | undefined {\n const graph = DataFactory.namedNode(identifier.path);\n const identifierStrategy = (this as unknown as { identifierStrategy: { supportsIdentifier: (id: ResourceIdentifier) => boolean }}).identifierStrategy;\n\n const assertGraphAllowed = (value: unknown): void => {\n if (!value || typeof value !== 'object') {\n return;\n }\n const term = value as { termType?: string; value?: string };\n if (term.termType === 'NamedNode' && term.value && !identifierStrategy.supportsIdentifier({ path: term.value })) {\n throw new BadRequestHttpError(`GRAPH ${term.value} is outside the configured identifier space.`);\n }\n };\n const wrapDefaultGraph = (text: string): string => {\n const insert = /INSERT\\s+DATA\\s*{\\s*([^}]*)}/is;\n const del = /DELETE\\s+DATA\\s*{\\s*([^}]*)}/is;\n const rewrite = (regex: RegExp, label: string, input: string): string =>\n input.replace(regex, (_match, body) => `${label} { GRAPH <${graph.value}> { ${body} } }`);\n let out = text;\n if (insert.test(out)) {\n out = rewrite(insert, 'INSERT DATA', out);\n }\n if (del.test(out)) {\n out = rewrite(del, 'DELETE DATA', out);\n }\n return out;\n };\n\n const rewriteTriples = (triples?: any[], targetGraph = graph): any[] => {\n if (!triples) return [];\n return triples.map((triple: any): any => ({\n ...triple,\n graph: (!triple.graph || triple.graph.termType === 'DefaultGraph') ? targetGraph : triple.graph,\n }));\n };\n\n const rewritePattern = (pattern: any): any => {\n if (pattern.type === 'bgp') {\n return { ...pattern, triples: rewriteTriples(pattern.triples) };\n }\n if (pattern.type === 'graph') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n if (pattern.type === 'group') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n if (pattern.type === 'optional') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n if (pattern.type === 'union') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n if (pattern.type === 'minus') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n if (pattern.type === 'filter') {\n return pattern; // FILTER doesn't contain triples, pass through\n }\n if (pattern.type === 'bind') {\n return pattern; // BIND doesn't contain triples, pass through\n }\n if (pattern.type === 'values') {\n return pattern; // VALUES doesn't contain triples, pass through\n }\n if (pattern.type === 'service') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n return pattern;\n };\n\n const toGraphQuads = (items?: any[]): GraphQuads[] | undefined => {\n if (!items) return items;\n return items.map((item: any): GraphQuads => {\n if (item?.type === 'graph') {\n assertGraphAllowed(item.name);\n return {\n ...item,\n name: item.name ?? graph,\n triples: rewriteTriples(item.triples, item.name ?? graph),\n };\n }\n // Treat as plain quad\n return {\n type: 'graph',\n name: graph,\n triples: rewriteTriples([ item ], graph),\n };\n });\n };\n\n try {\n console.log(`[normalizeGraphs] Input SPARQL (first 500 chars): ${updateText.slice(0, 500)}`);\n const parsed = this.parser.parse(updateText) as unknown as SparqlUpdate;\n\n // Explicitly reject SPARQL Queries (SELECT, ASK, CONSTRUCT) in PATCH\n if ((parsed as any).type === 'query') {\n this.logger.warn(`Received SPARQL Query in PATCH request for ${identifier.path}. SPARQL PATCH only supports UPDATE operations.`);\n return undefined;\n }\n\n const collect = (ops: any[], key: 'delete' | 'insert'): any[] =>\n ops.flatMap((op): any[] => {\n const entries = op[key];\n if (!entries) return [];\n if (Array.isArray(entries)) {\n return entries.flatMap((entry: any): any[] =>\n entry.triples ? entry.triples : (entry.quads ?? []));\n }\n return [];\n });\n const deleteTriples = collect(parsed.updates as any[], 'delete');\n const insertTriples = collect(parsed.updates as any[], 'insert');\n const hasVariables = [...deleteTriples, ...insertTriples].some((t: any): boolean =>\n t.subject?.termType === 'Variable' || t.predicate?.termType === 'Variable' || t.object?.termType === 'Variable');\n\n const simpleOps = parsed.updates.every((op: any): boolean =>\n [ 'delete', 'insert', 'insertdelete', 'deleteinsert' ].includes(op.updateType) &&\n (!op.where || op.where.length === 0) &&\n !hasVariables);\n\n this.logger.debug(`[normalizeGraphs] simpleOps=${simpleOps}, hasVariables=${hasVariables}, deleteTriples=${deleteTriples.length}, insertTriples=${insertTriples.length}`);\n this.logger.debug(`[normalizeGraphs] updateTypes: ${parsed.updates.map((op: any) => op.updateType).join(', ')}`);\n\n if (simpleOps && deleteTriples.length + insertTriples.length > 0) {\n const termToString = (term: any): string => {\n if (term.termType === 'NamedNode') {\n return `<${term.value}>`;\n }\n if (term.termType === 'Literal') {\n // Escape special characters in literal values\n const hasQuotes = term.value.includes('\"');\n const hasNewlines = term.value.includes('\\n') || term.value.includes('\\r');\n\n let escaped: string;\n let useTripleQuotes = false;\n\n if (hasQuotes || hasNewlines) {\n // Use triple-quoted strings for values with quotes or newlines\n useTripleQuotes = true;\n escaped = term.value;\n // Escape triple-quote sequences\n escaped = escaped.replace(/\"\"\"/g, '\"\\\\\"\\\\\"\"');\n // Escape trailing quotes to avoid \"\"\"content\"\"\"\" sequences\n if (escaped.endsWith('\"')) {\n const match = escaped.match(/\"*$/);\n const trailingQuotes = match ? match[0].length : 0;\n if (trailingQuotes > 0) {\n escaped = escaped.slice(0, -trailingQuotes) + '\\\\\"'.repeat(trailingQuotes);\n }\n }\n } else {\n // Regular escaping for simple strings\n escaped = term.value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n }\n\n const quote = useTripleQuotes ? '\"\"\"' : '\"';\n\n // Handle language tags and datatypes\n if (term.language) {\n return `${quote}${escaped}${quote}@${term.language}`;\n }\n if (term.datatype && term.datatype.value !== 'http://www.w3.org/2001/XMLSchema#string') {\n return `${quote}${escaped}${quote}^^<${term.datatype.value}>`;\n }\n return `${quote}${escaped}${quote}`;\n }\n if (term.termType === 'BlankNode') {\n return `_:${term.value}`;\n }\n // Fallback for unknown term types\n return `<${term.value}>`;\n };\n const toTripleStr = (triples: any[]): string =>\n triples.map((t): string => `${termToString(t.subject)} ${termToString(t.predicate)} ${termToString(t.object)} .`).join(' ');\n let parts: string[] = [];\n if (deleteTriples.length > 0) {\n parts.push(`DELETE DATA { GRAPH <${graph.value}> { ${toTripleStr(deleteTriples)} } }`);\n }\n if (insertTriples.length > 0) {\n parts.push(`INSERT DATA { GRAPH <${graph.value}> { ${toTripleStr(insertTriples)} } }`);\n }\n const normalizedSimple = parts.join(';\\n');\n this.logger.verbose(`Normalized SPARQL UPDATE for ${identifier.path}: ${normalizedSimple}`);\n return normalizedSimple;\n }\n\n parsed.updates = parsed.updates.map((op: any): UpdateOperation => {\n switch (op.updateType) {\n case 'deleteinsert':\n case 'insertdelete':\n return {\n ...op,\n delete: toGraphQuads(op.delete),\n insert: toGraphQuads(op.insert),\n where: op.where && op.where.length > 0 ? [ { type: 'graph', name: graph, patterns: op.where.map(rewritePattern) } ] : [],\n };\n case 'delete':\n case 'insert': {\n const deleteQuads = toGraphQuads(op.delete) ?? [];\n const insertQuads = toGraphQuads(op.insert) ?? [];\n return {\n updateType: 'insertdelete',\n delete: deleteQuads,\n insert: insertQuads,\n where: op.where && op.where.length > 0 ? [ { type: 'graph', name: graph, patterns: op.where.map(rewritePattern) } ] : [],\n };\n }\n default:\n return op;\n }\n });\n const normalized = this.generator.stringify(parsed);\n this.logger.verbose(`Normalized SPARQL UPDATE for ${identifier.path}: ${normalized}`);\n return normalized;\n } catch (error: unknown) {\n console.log(`[normalizeGraphs] Parse FAILED for ${identifier.path}: ${error}`);\n console.log(`[normalizeGraphs] Input was: ${updateText.slice(0, 300)}`);\n const fallbackResult = wrapDefaultGraph(updateText);\n console.log(`[normalizeGraphs] Fallback result: ${fallbackResult.slice(0, 300)}`);\n return fallbackResult;\n }\n }\n\n private isSparqlUpdatePatch(patch: Patch): patch is SparqlUpdatePatch {\n return typeof (patch as SparqlUpdatePatch).algebra === 'object';\n }\n\n private isSparqlCapable(accessor: unknown): accessor is {\n executeSparqlUpdate: (query: string, baseIri?: string) => Promise<void>;\n getMetadata: (identifier: ResourceIdentifier) => Promise<RepresentationMetadata>;\n } {\n return typeof accessor === 'object' &&\n accessor !== null &&\n typeof (accessor as { executeSparqlUpdate?: unknown }).executeSparqlUpdate === 'function' &&\n typeof (accessor as { getMetadata?: unknown }).getMetadata === 'function';\n }\n\n public override async setRepresentation(identifier: ResourceIdentifier, representation: Representation, conditions?: Conditions): Promise<ChangeMap> {\n return super.setRepresentation(identifier, representation, conditions);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SparqlUpdateResourceStore.js","sourceRoot":"","sources":["../../src/storage/SparqlUpdateResourceStore.ts"],"names":[],"mappings":";;;AAAA,2BAAiC;AACjC,uCAAoJ;AACpJ,8DAkBiC;AAEjC,6EAAgF;AAChF,iEAAqD;AACrD,wGAGwD;AACxD,6DAAiG;AAUjG;;;GAGG;AACH,MAAa,yBAA0B,SAAQ,yCAAsB;IAMnE,YAAmB,OAAyC;QAC1D,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAN1F,cAAS,GAAG,IAAI,oBAAe,EAAE,CAAC;QAClC,WAAM,GAAG,IAAI,iBAAY,EAAE,CAAC;QAEjB,WAAM,GAAG,IAAA,oCAAY,EAAC,IAAI,CAAC,CAAC;QAItD,IAAI,CAAC,mCAAmC,GAAG,OAAO,CAAC,mCAAmC;YACpF,IAAI,yEAAmC,CAAC;gBACtC,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;aAC3C,CAAC,CAAC;QACL,kFAAkF;QAClF,MAAM,QAAQ,GAAG,OAAO,CAAC,kBAAqD,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kEAAkE,OAAO,CAAC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tF,OAAO,UAAU,CAAC;QACpB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,4BAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;gBAChC,MAAM,KAAK,CAAC;YACd,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qCAAqC,UAAU,CAAC,IAAI,2CAA2C,KAAK,EAAE,CAAC,CAAC;YAC1H,MAAM,cAAc,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;YACpD,OAAO,cAAc,CAAC;QACxB,CAAC;IACH,CAAC;IAEO,mBAAmB,CAAC,KAAY;QACtC,OAAO,OAAQ,KAA2B,CAAC,OAAO,KAAK,QAAQ,CAAC;IAClE,CAAC;IAEO,eAAe,CAAC,QAAiB;QAIvC,OAAO,OAAO,QAAQ,KAAK,QAAQ;YACjC,QAAQ,KAAK,IAAI;YACjB,OAAQ,QAA8C,CAAC,mBAAmB,KAAK,UAAU;YACzF,OAAQ,QAAsC,CAAC,WAAW,KAAK,UAAU,CAAC;IAC9E,CAAC;IAEe,KAAK,CAAC,iBAAiB,CAAC,UAA8B,EAAE,cAA8B,EAAE,UAAuB;QAC7H,OAAO,KAAK,CAAC,iBAAiB,CAAC,UAAU,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;IACzE,CAAC;CACF;AAnYD,8DAmYC","sourcesContent":["import { DataFactory } from 'n3';\nimport { Generator as SparqlGenerator, Parser as SparqlParser, type GraphQuads, type UpdateOperation, type Update as SparqlUpdate } from 'sparqljs';\nimport {\n DataAccessorBasedStore,\n type ChangeMap,\n type ResourceIdentifier,\n type Patch,\n NotImplementedHttpError,\n type Conditions,\n NotFoundHttpError,\n RepresentationMetadata,\n AS,\n SOLID_AS,\n BadRequestHttpError,\n ForbiddenHttpError,\n HttpError,\n type DataAccessor,\n type IdentifierStrategy,\n type AuxiliaryStrategy,\n type Representation,\n} from '@solid/community-server';\nimport type { SparqlUpdatePatch } from '@solid/community-server';\nimport { readableToString } from '@solid/community-server/dist/util/StreamUtil';\nimport { getLoggerFor } from 'global-logger-factory';\nimport {\n LocalFirstRdfRepresentationResolver,\n type LocalFirstRdfRepresentationResolverLike,\n} from '../solidfs/LocalFirstRdfRepresentationResolver';\nimport { DisabledSparqlFeatureError, UnsupportedSparqlQueryError } from './rdf/RdfSparqlAdapter';\n\nexport interface SparqlUpdateResourceStoreOptions {\n accessor: DataAccessor;\n identifierStrategy: IdentifierStrategy;\n auxiliaryStrategy: AuxiliaryStrategy;\n metadataStrategy: AuxiliaryStrategy;\n localFirstRdfRepresentationResolver?: LocalFirstRdfRepresentationResolverLike;\n}\n\n/**\n * ResourceStore that short-circuits PATCH into direct SPARQL UPDATE\n * when the underlying DataAccessor supports it.\n */\nexport class SparqlUpdateResourceStore extends DataAccessorBasedStore {\n private readonly generator = new SparqlGenerator();\n private readonly parser = new SparqlParser();\n private readonly localFirstRdfRepresentationResolver: LocalFirstRdfRepresentationResolverLike;\n protected override readonly logger = getLoggerFor(this);\n\n public constructor(options: SparqlUpdateResourceStoreOptions) {\n super(options.accessor, options.identifierStrategy, options.auxiliaryStrategy, options.metadataStrategy);\n this.localFirstRdfRepresentationResolver = options.localFirstRdfRepresentationResolver ??\n new LocalFirstRdfRepresentationResolver({\n accessor: options.accessor,\n metadataStrategy: options.metadataStrategy,\n });\n // Check if identifierStrategy has baseUrl property (SingleRootIdentifierStrategy)\n const strategy = options.identifierStrategy as unknown as { baseUrl?: string };\n this.logger.info(`SparqlUpdateResourceStore initialized with identifierStrategy: ${options.identifierStrategy.constructor.name}, baseUrl: ${strategy.baseUrl ?? 'N/A'}`);\n }\n\n public override async getRepresentation(identifier: ResourceIdentifier): Promise<Representation> {\n const localRepresentation = await this.localFirstRdfRepresentationResolver.resolve(identifier);\n if (localRepresentation) {\n return localRepresentation;\n }\n\n return super.getRepresentation(identifier);\n }\n\n // @ts-expect-error Upstream signature returns never; we return ChangeMap for successful PATCH.\n public override async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<ChangeMap> {\n this.logger.debug(`SparqlUpdateResourceStore.modifyResource called for ${identifier.path}`);\n this.logger.debug(`Patch has algebra: ${typeof (patch as SparqlUpdatePatch).algebra === 'object'}, metadata.contentType: ${patch.metadata?.contentType}`);\n\n const accessor = (this as unknown as { accessor: unknown }).accessor as unknown;\n if (!this.isSparqlCapable(accessor)) {\n this.logger.debug('Accessor is not SPARQL capable');\n throw new NotImplementedHttpError('SPARQL UPDATE not supported by this accessor');\n }\n\n // Keep the default condition validation semantics\n if (conditions) {\n let metadata: RepresentationMetadata | undefined;\n try {\n metadata = await accessor.getMetadata(identifier);\n } catch (error: unknown) {\n if (!NotFoundHttpError.isInstance(error)) {\n throw error;\n }\n }\n this.validateConditions(conditions, metadata);\n }\n\n const sparqlUpdate = await this.toSparqlUpdate(patch, identifier);\n if (!sparqlUpdate) {\n this.logger.debug(`toSparqlUpdate returned undefined for ${identifier.path}, falling back to CSS handler`);\n throw new NotImplementedHttpError('Unsupported PATCH payload for SPARQL conversion');\n }\n\n this.logger.debug(`Applying SPARQL PATCH to ${identifier.path}: ${sparqlUpdate}`);\n try {\n await accessor.executeSparqlUpdate(sparqlUpdate, identifier.path);\n } catch (error: unknown) {\n if (error instanceof DisabledSparqlFeatureError) {\n throw new ForbiddenHttpError(error.message, { cause: error });\n }\n if (error instanceof UnsupportedSparqlQueryError) {\n throw new BadRequestHttpError(error.message, { cause: error });\n }\n throw error;\n }\n\n // PATCH does not affect containment; mark the target resource as updated.\n const changes = new Map() as ChangeMap;\n changes.set(identifier, new RepresentationMetadata(identifier, { [SOLID_AS.activity]: AS.terms.Update }));\n return changes;\n }\n\n /**\n * 只处理 SPARQL UPDATE (application/sparql-update)。\n * N3 Patch 和其他类型返回 undefined,让 CSS PatchingStore 回退到 get-patch-set 逻辑。\n */\n private async toSparqlUpdate(patch: Patch, identifier: ResourceIdentifier): Promise<string | undefined> {\n // 只处理 SPARQL UPDATE,其他类型(包括 N3 Patch)回退到 CSS 默认处理\n if (!this.isSparqlUpdatePatch(patch)) {\n return undefined;\n }\n\n const updateText = await readableToString(patch.data);\n return this.normalizeGraphs(updateText, identifier);\n }\n\n /**\n * Ensure SPARQL UPDATE targets the resource graph (CSS stores documents in named graphs).\n */\n private normalizeGraphs(updateText: string, identifier: ResourceIdentifier): string | undefined {\n const graph = DataFactory.namedNode(identifier.path);\n const identifierStrategy = (this as unknown as { identifierStrategy: { supportsIdentifier: (id: ResourceIdentifier) => boolean }}).identifierStrategy;\n\n const assertGraphAllowed = (value: unknown): void => {\n if (!value || typeof value !== 'object') {\n return;\n }\n const term = value as { termType?: string; value?: string };\n if (term.termType === 'NamedNode' && term.value && !identifierStrategy.supportsIdentifier({ path: term.value })) {\n throw new BadRequestHttpError(`GRAPH ${term.value} is outside the configured identifier space.`);\n }\n };\n const wrapDefaultGraph = (text: string): string => {\n const insert = /INSERT\\s+DATA\\s*{\\s*([^}]*)}/is;\n const del = /DELETE\\s+DATA\\s*{\\s*([^}]*)}/is;\n const rewrite = (regex: RegExp, label: string, input: string): string =>\n input.replace(regex, (_match, body) => `${label} { GRAPH <${graph.value}> { ${body} } }`);\n let out = text;\n if (insert.test(out)) {\n out = rewrite(insert, 'INSERT DATA', out);\n }\n if (del.test(out)) {\n out = rewrite(del, 'DELETE DATA', out);\n }\n return out;\n };\n\n const rewriteTriples = (triples?: any[], targetGraph = graph): any[] => {\n if (!triples) return [];\n return triples.map((triple: any): any => ({\n ...triple,\n graph: (!triple.graph || triple.graph.termType === 'DefaultGraph') ? targetGraph : triple.graph,\n }));\n };\n\n const triplesFromTemplateBlock = (item: any): any[] => {\n if (Array.isArray(item?.triples)) {\n return item.triples;\n }\n if (!Array.isArray(item?.patterns)) {\n return [];\n }\n return item.patterns.flatMap((pattern: any): any[] =>\n pattern?.type === 'bgp' && Array.isArray(pattern.triples) ? pattern.triples : []);\n };\n\n const rewriteQuadBlocks = (items?: any[]): any[] | undefined => {\n if (!items) return items;\n return items.flatMap((item: any): any[] => {\n if (item?.type === 'graph') {\n assertGraphAllowed(item.name);\n const targetGraph = item.name ?? graph;\n return [{\n ...item,\n name: targetGraph,\n triples: rewriteTriples(triplesFromTemplateBlock(item), targetGraph),\n patterns: undefined,\n }];\n }\n if (item?.type === 'bgp') {\n return [{\n type: 'graph',\n name: graph,\n triples: rewriteTriples(item.triples, graph),\n }];\n }\n return [{\n type: 'graph',\n name: graph,\n triples: rewriteTriples([ item ], graph),\n }];\n });\n };\n\n const rewritePattern = (pattern: any): any => {\n if (pattern.type === 'bgp') {\n return { ...pattern, triples: rewriteTriples(pattern.triples, graph) };\n }\n if (pattern.type === 'graph') {\n assertGraphAllowed(pattern.name);\n return {\n ...pattern,\n name: pattern.name ?? graph,\n patterns: pattern.patterns?.map(rewritePattern) ?? [],\n };\n }\n if (pattern.type === 'group') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n if (pattern.type === 'optional') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n if (pattern.type === 'union') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n if (pattern.type === 'minus') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n if (pattern.type === 'filter') {\n return pattern; // FILTER doesn't contain triples, pass through\n }\n if (pattern.type === 'bind') {\n return pattern; // BIND doesn't contain triples, pass through\n }\n if (pattern.type === 'values') {\n return pattern; // VALUES doesn't contain triples, pass through\n }\n if (pattern.type === 'service') {\n return { ...pattern, patterns: pattern.patterns?.map(rewritePattern) ?? [] };\n }\n return pattern;\n };\n\n const rewriteWherePatterns = (patterns?: any[]): any[] =>\n (patterns ?? []).map((pattern: any): any => {\n if (pattern?.type === 'bgp') {\n return {\n type: 'graph',\n name: graph,\n patterns: [{\n ...pattern,\n triples: rewriteTriples(pattern.triples, graph),\n }],\n };\n }\n return rewritePattern(pattern);\n });\n\n const toGraphQuads = (items?: any[]): GraphQuads[] | undefined =>\n rewriteQuadBlocks(items) as GraphQuads[] | undefined;\n\n try {\n const parsed = this.parser.parse(updateText) as unknown as SparqlUpdate;\n\n // Explicitly reject SPARQL Queries (SELECT, ASK, CONSTRUCT) in PATCH\n if ((parsed as any).type === 'query') {\n this.logger.warn(`Received SPARQL Query in PATCH request for ${identifier.path}. SPARQL PATCH only supports UPDATE operations.`);\n return undefined;\n }\n\n const collect = (ops: any[], key: 'delete' | 'insert'): any[] =>\n ops.flatMap((op): any[] => {\n const entries = op[key];\n if (!entries) return [];\n if (Array.isArray(entries)) {\n return entries.flatMap((entry: any): any[] => {\n if (entry?.type === 'graph') {\n assertGraphAllowed(entry.name);\n return (entry.triples ?? []).map((triple: any): any => ({\n ...triple,\n graph: entry.name ?? graph,\n }));\n }\n return entry.triples ? entry.triples : (entry.quads ?? []);\n });\n }\n return [];\n });\n const deleteTriples = collect(parsed.updates as any[], 'delete');\n const insertTriples = collect(parsed.updates as any[], 'insert');\n const hasVariables = [...deleteTriples, ...insertTriples].some((t: any): boolean =>\n t.subject?.termType === 'Variable' || t.predicate?.termType === 'Variable' || t.object?.termType === 'Variable');\n\n const simpleOps = parsed.updates.every((op: any): boolean =>\n [ 'delete', 'insert', 'insertdelete', 'deleteinsert' ].includes(op.updateType) &&\n (!op.where || op.where.length === 0) &&\n !hasVariables);\n\n this.logger.debug(`[normalizeGraphs] simpleOps=${simpleOps}, hasVariables=${hasVariables}, deleteTriples=${deleteTriples.length}, insertTriples=${insertTriples.length}`);\n this.logger.debug(`[normalizeGraphs] updateTypes: ${parsed.updates.map((op: any) => op.updateType).join(', ')}`);\n\n if (simpleOps && deleteTriples.length + insertTriples.length > 0) {\n const termToString = (term: any): string => {\n if (term.termType === 'NamedNode') {\n return `<${term.value}>`;\n }\n if (term.termType === 'Literal') {\n // Escape special characters in literal values\n const hasQuotes = term.value.includes('\"');\n const hasNewlines = term.value.includes('\\n') || term.value.includes('\\r');\n\n let escaped: string;\n let useTripleQuotes = false;\n\n if (hasQuotes || hasNewlines) {\n // Use triple-quoted strings for values with quotes or newlines\n useTripleQuotes = true;\n escaped = term.value;\n // Escape triple-quote sequences\n escaped = escaped.replace(/\"\"\"/g, '\"\\\\\"\\\\\"\"');\n // Escape trailing quotes to avoid \"\"\"content\"\"\"\" sequences\n if (escaped.endsWith('\"')) {\n const match = escaped.match(/\"*$/);\n const trailingQuotes = match ? match[0].length : 0;\n if (trailingQuotes > 0) {\n escaped = escaped.slice(0, -trailingQuotes) + '\\\\\"'.repeat(trailingQuotes);\n }\n }\n } else {\n // Regular escaping for simple strings\n escaped = term.value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n }\n\n const quote = useTripleQuotes ? '\"\"\"' : '\"';\n\n // Handle language tags and datatypes\n if (term.language) {\n return `${quote}${escaped}${quote}@${term.language}`;\n }\n if (term.datatype && term.datatype.value !== 'http://www.w3.org/2001/XMLSchema#string') {\n return `${quote}${escaped}${quote}^^<${term.datatype.value}>`;\n }\n return `${quote}${escaped}${quote}`;\n }\n if (term.termType === 'BlankNode') {\n return `_:${term.value}`;\n }\n // Fallback for unknown term types\n return `<${term.value}>`;\n };\n const toTripleStr = (triples: any[]): string =>\n triples.map((t): string => `${termToString(t.subject)} ${termToString(t.predicate)} ${termToString(t.object)} .`).join(' ');\n let parts: string[] = [];\n if (deleteTriples.length > 0) {\n parts.push(`DELETE DATA { GRAPH <${graph.value}> { ${toTripleStr(deleteTriples)} } }`);\n }\n if (insertTriples.length > 0) {\n parts.push(`INSERT DATA { GRAPH <${graph.value}> { ${toTripleStr(insertTriples)} } }`);\n }\n const normalizedSimple = parts.join(';\\n');\n this.logger.verbose(`Normalized SPARQL UPDATE for ${identifier.path}: ${normalizedSimple}`);\n return normalizedSimple;\n }\n\n parsed.updates = parsed.updates.map((op: any): UpdateOperation => {\n switch (op.updateType) {\n case 'deletewhere':\n return {\n ...op,\n delete: toGraphQuads(op.delete),\n };\n case 'deleteinsert':\n case 'insertdelete':\n return {\n ...op,\n delete: toGraphQuads(op.delete),\n insert: toGraphQuads(op.insert),\n where: rewriteWherePatterns(op.where),\n };\n case 'delete':\n return {\n ...op,\n delete: toGraphQuads(op.delete),\n };\n case 'insert':\n return {\n ...op,\n insert: toGraphQuads(op.insert),\n };\n default:\n return op;\n }\n });\n const normalized = this.generator.stringify(parsed);\n this.logger.verbose(`Normalized SPARQL UPDATE for ${identifier.path}: ${normalized}`);\n return normalized;\n } catch (error: unknown) {\n if (HttpError.isInstance(error)) {\n throw error;\n }\n this.logger.debug(`Could not parse SPARQL UPDATE for ${identifier.path}; applying default graph text fallback: ${error}`);\n const fallbackResult = wrapDefaultGraph(updateText);\n return fallbackResult;\n }\n }\n\n private isSparqlUpdatePatch(patch: Patch): patch is SparqlUpdatePatch {\n return typeof (patch as SparqlUpdatePatch).algebra === 'object';\n }\n\n private isSparqlCapable(accessor: unknown): accessor is {\n executeSparqlUpdate: (query: string, baseIri?: string) => Promise<void>;\n getMetadata: (identifier: ResourceIdentifier) => Promise<RepresentationMetadata>;\n } {\n return typeof accessor === 'object' &&\n accessor !== null &&\n typeof (accessor as { executeSparqlUpdate?: unknown }).executeSparqlUpdate === 'function' &&\n typeof (accessor as { getMetadata?: unknown }).getMetadata === 'function';\n }\n\n public override async setRepresentation(identifier: ResourceIdentifier, representation: Representation, conditions?: Conditions): Promise<ChangeMap> {\n return super.setRepresentation(identifier, representation, conditions);\n }\n}\n"]}
|
|
@@ -27,7 +27,7 @@ export interface SourceScopedStructuredRdfAccessor {
|
|
|
27
27
|
/**
|
|
28
28
|
* MixDataAccessor - Routes data to appropriate storage based on content type
|
|
29
29
|
*
|
|
30
|
-
* - RDF data (internal/quads) -> structuredDataAccessor (
|
|
30
|
+
* - RDF data (internal/quads) -> structuredDataAccessor (Solid RDF engine by default)
|
|
31
31
|
* - RDF file mirrors (.ttl/.jsonld) -> rdfFileDataAccessor (local FileSystem)
|
|
32
32
|
* - Other data (binary, text, etc.) -> unstructuredDataAccessor (FileSystem, Minio, etc.)
|
|
33
33
|
*
|
|
@@ -70,17 +70,34 @@ export declare class MixDataAccessor implements DataAccessor {
|
|
|
70
70
|
* Execute SPARQL UPDATE.
|
|
71
71
|
*
|
|
72
72
|
* Supported embedded deltas patch the local RDF authority file first and then
|
|
73
|
-
* rebuild the structured RDF index.
|
|
74
|
-
*
|
|
73
|
+
* rebuild the structured RDF index. The structured accessor decides whether
|
|
74
|
+
* unsupported shapes have an explicitly configured compatibility path.
|
|
75
75
|
*/
|
|
76
76
|
executeSparqlUpdate(query: string, baseIri?: string): Promise<void>;
|
|
77
77
|
private executeLocalRdfSparqlUpdate;
|
|
78
78
|
private applyLocalRdfDelta;
|
|
79
|
-
private
|
|
79
|
+
private loadLocalRdfDeltaGraphs;
|
|
80
|
+
private localRdfDeltaGraphIris;
|
|
81
|
+
private localRdfDeltaWriteGraphIris;
|
|
82
|
+
private addWritableTemplateGraphIris;
|
|
83
|
+
private addWritableGraphVariableIris;
|
|
84
|
+
private localRdfWriteGraphIri;
|
|
80
85
|
private queryLocalUpdateBindings;
|
|
81
86
|
private queryGraphTerms;
|
|
82
|
-
private
|
|
87
|
+
private collectQueryGraphTerms;
|
|
88
|
+
private collectGraphVariableFilterTerms;
|
|
89
|
+
private collectGraphVariableFilterIris;
|
|
90
|
+
private collectGraphVariableValueTerms;
|
|
91
|
+
private collectGraphVariableValueIris;
|
|
92
|
+
private addGraphFilterValueIri;
|
|
93
|
+
private addNamedGraphIris;
|
|
94
|
+
private addWritableNamedGraphIri;
|
|
95
|
+
private isQueryVariable;
|
|
96
|
+
private isRdfTerm;
|
|
97
|
+
private readLocalRdfState;
|
|
83
98
|
private writeLocalRdfAuthority;
|
|
99
|
+
private writeLocalRdfAuthorityPatches;
|
|
100
|
+
private rollbackLocalRdfAuthorityPatches;
|
|
84
101
|
private toDefaultGraphQuad;
|
|
85
102
|
private toGraphQuad;
|
|
86
103
|
private quadKey;
|