@lincyaw/workspace 1.0.0-rc.120 → 1.0.0-rc.121
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workspace",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.121",
|
|
4
4
|
"description": "Presmium's workspace service (presmium serve): documents, their history, reviews and the workspace site",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"mime-types": "3.0.2",
|
|
35
35
|
"playwright-chromium": "1.64.1",
|
|
36
36
|
"yaml": "^2.9.1",
|
|
37
|
-
"@lincyaw/
|
|
38
|
-
"@lincyaw/
|
|
39
|
-
"@lincyaw/
|
|
40
|
-
"@lincyaw/
|
|
37
|
+
"@lincyaw/server": "1.0.0-rc.121",
|
|
38
|
+
"@lincyaw/design": "1.0.0-rc.121",
|
|
39
|
+
"@lincyaw/compiler": "1.0.0-rc.121",
|
|
40
|
+
"@lincyaw/kernel": "1.0.0-rc.121"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/mime-types": "^3.0.1",
|
|
44
|
-
"@lincyaw/mcp": "1.0.0-rc.
|
|
44
|
+
"@lincyaw/mcp": "1.0.0-rc.121"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
|
-
import { DOCUMENT_ENTRY, DOCUMENT_HISTORY_MAX_FILE_BYTES, DOCUMENT_HISTORY_MAX_REQUEST_CHARS, DOCUMENT_HISTORY_MAX_RESPONSE_CHARS, DOCUMENT_HISTORY_PAGE_SIZE, fnv1a64, hasRole, jsonResponse, problemResponse } from '@lincyaw/kernel'
|
|
2
|
+
import { DOCUMENT_ENTRY, DOCUMENT_HISTORY_MAX_FILE_BYTES, DOCUMENT_SCHEMA_VERSION, DOCUMENT_HISTORY_MAX_REQUEST_CHARS, DOCUMENT_HISTORY_MAX_RESPONSE_CHARS, DOCUMENT_HISTORY_PAGE_SIZE, fnv1a64, hasRole, jsonResponse, problemResponse } from '@lincyaw/kernel'
|
|
3
3
|
import type { DocumentHistory, DocumentHistoryAnswer, DocumentHistoryBinding, DocumentHistoryChange, DocumentHistoryChanged, DocumentHistoryFile, DocumentHistorySource, HistoryRevision, Member, Route } from '@lincyaw/kernel'
|
|
4
4
|
import { validateDocumentHistoryChange, validateDocumentHistoryQuery, validateDocumentHistoryRead } from '@lincyaw/kernel/node'
|
|
5
5
|
import { listDocuments } from './config.ts'
|
|
@@ -74,9 +74,25 @@ export function createDocumentHistory(options: DocumentHistoryOptions): { servic
|
|
|
74
74
|
if (origin === 'agent' && options.reviewRequired) throw new RequestError(409, 'authoring-review-required')
|
|
75
75
|
return { key: JSON.stringify([document, member.id, request.id]), signature: digest(JSON.stringify([which, request.id, request.snapshot, request.source.version, request.source.fingerprint, request.expect])) }
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
// A format upgrade (and a document's creation) is a boundary of its history: taking it back would leave the document
|
|
78
|
+
// without its entry file, or in a format this version no longer opens.
|
|
79
|
+
const supportedAt = async (revision: string, document: string): Promise<boolean> => {
|
|
80
|
+
try {
|
|
81
|
+
const bytes = await history().readFile(revision, entryOf(document), DOCUMENT_HISTORY_MAX_FILE_BYTES)
|
|
82
|
+
const value = JSON.parse(new TextDecoder().decode(bytes)) as { schemaVersion?: unknown }
|
|
83
|
+
return value.schemaVersion === DOCUMENT_SCHEMA_VERSION
|
|
84
|
+
} catch { return false }
|
|
85
|
+
}
|
|
86
|
+
const crossesBoundary = async (document: string, revision: string, paths?: string[]): Promise<boolean> => {
|
|
87
|
+
const files = paths ?? await history().filesOf(revision)
|
|
88
|
+
if (!files.includes(entryOf(document))) return false
|
|
89
|
+
const parent = await history().parentOf(revision)
|
|
90
|
+
return !parent || !await supportedAt(parent, document)
|
|
91
|
+
}
|
|
92
|
+
const targetPaths = async (document: string, request: DocumentHistoryChange, member: Member, which: 'undo' | 'redo' | 'revert') => {
|
|
78
93
|
const paths = await history().filesOf(request.expect)
|
|
79
94
|
if (!paths.length) throw new RequestError(404, 'history-revision-not-found')
|
|
95
|
+
if (which !== 'redo' && await crossesBoundary(document, request.expect, paths)) throw new RequestError(409, 'history-format-boundary')
|
|
80
96
|
for (const path of paths) {
|
|
81
97
|
pathAllowed(document, path, member)
|
|
82
98
|
const owners = await Promise.all([history().ownerAt(request.expect, path), history().ownerAt(`${request.expect}^1`, path)])
|
|
@@ -100,6 +116,10 @@ export function createDocumentHistory(options: DocumentHistoryOptions): { servic
|
|
|
100
116
|
if ((query.offset ?? 0) > 0 && !query.snapshot) throw new RequestError(400, 'history-snapshot-required')
|
|
101
117
|
if (query.snapshot !== undefined && query.snapshot !== before.snapshot) throw new RequestError(409, 'history-snapshot-changed')
|
|
102
118
|
const full = await revisions.historyWithUndo({ document }), changes = full.revisions.filter(entry => !entry.reverts), offset = query.offset ?? 0
|
|
119
|
+
// The upgrade from the earlier format is not offered as a step to undo or revert.
|
|
120
|
+
if (full.undo && await crossesBoundary(document, full.undo)) delete full.undo
|
|
121
|
+
const legacy = `${document ? `${document}/` : ''}lecture.json`
|
|
122
|
+
for (const entry of changes) if (entry.files.includes(legacy) && entry.files.includes(entryOf(document))) entry.revertible = false
|
|
103
123
|
if (offset > changes.length) throw new RequestError(400, 'history-offset-invalid')
|
|
104
124
|
const answer: DocumentHistoryAnswer = { document, available: true, historyBinding: before, revisions: [], ...full.undo ? { undo: full.undo } : {}, ...full.redo ? { redo: full.redo } : {} }
|
|
105
125
|
let index = offset
|
|
@@ -141,7 +161,7 @@ export function createDocumentHistory(options: DocumentHistoryOptions): { servic
|
|
|
141
161
|
if (known && !flight && !sameBinding(await binding(document, member), { source: known.answer.source, snapshot: known.answer.snapshot })) throw new RequestError(409, 'history-result-no-longer-current')
|
|
142
162
|
return
|
|
143
163
|
}
|
|
144
|
-
const paths = await targetPaths(document, request, member)
|
|
164
|
+
const paths = await targetPaths(document, request, member, which)
|
|
145
165
|
if (!sameBinding(await binding(document, member), { source: request.source, snapshot: request.snapshot })) throw new RequestError(409, 'history-source-changed')
|
|
146
166
|
const claimed = locks.claimAll(paths.map(path => documentDirOf(config, path)!), 'revision:revert')
|
|
147
167
|
if ('holder' in claimed) throw lockedError(claimed.document, claimed.holder)
|
|
@@ -161,7 +181,7 @@ export function createDocumentHistory(options: DocumentHistoryOptions): { servic
|
|
|
161
181
|
}
|
|
162
182
|
if (pending.size >= MAX_RECEIPTS) throw new RequestError(429, 'history-busy')
|
|
163
183
|
const work = Promise.resolve().then(async () => {
|
|
164
|
-
const paths = await targetPaths(document, request, member)
|
|
184
|
+
const paths = await targetPaths(document, request, member, which)
|
|
165
185
|
const claimed = locks.claimAll(paths.map(path => documentDirOf(config, path)!), 'revision:revert')
|
|
166
186
|
if ('holder' in claimed) throw lockedError(claimed.document, claimed.holder)
|
|
167
187
|
try {
|
package/src/node/revisions.ts
CHANGED
|
@@ -438,6 +438,13 @@ export class Revisions implements RevisionService {
|
|
|
438
438
|
return this.#git.exclusive(async () => undoTargets(await this.#entries(document))[which])
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
/** The first parent of a revision in the current history; none for the root. */
|
|
442
|
+
async parentOf(id: string): Promise<string | undefined> {
|
|
443
|
+
if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(id)) throw new RequestError(400, 'history-file-invalid')
|
|
444
|
+
const result = await this.#git.tryOutput(['rev-parse', '--verify', '--quiet', `${id}^1`])
|
|
445
|
+
return result.ok ? result.output.trim() || undefined : undefined
|
|
446
|
+
}
|
|
447
|
+
|
|
441
448
|
async head(): Promise<string | undefined> {
|
|
442
449
|
const result = await this.#git.tryOutput(['rev-parse', '--verify', 'HEAD'])
|
|
443
450
|
return result.ok ? result.output.trim() : undefined
|