@arcadia-eternity/content-sdk 0.0.0-stage → 4.3.0
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/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/asset-inspect.mjs +67 -0
- package/dist/author-api.mjs +112 -0
- package/dist/author-reference.mjs +121 -0
- package/dist/build-content.mjs +30 -0
- package/dist/cli.mjs +74 -0
- package/dist/content-query.mjs +283 -0
- package/dist/content-workspace.d.mts +161 -0
- package/dist/content-workspace.mjs +936 -0
- package/dist/debug-environments.mjs +154 -0
- package/dist/demo.mjs +22 -0
- package/dist/environment-rules.d.mts +5 -0
- package/dist/environment-rules.mjs +92 -0
- package/dist/environment.mjs +183 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/job-journal.mjs +94 -0
- package/dist/jobs.mjs +579 -0
- package/dist/lib/content.mjs +95 -0
- package/dist/lib/presentation.mjs +240 -0
- package/dist/lib/yaml-sharing.mjs +101 -0
- package/dist/managed-projects.d.mts +35 -0
- package/dist/managed-projects.mjs +303 -0
- package/dist/managed-sources.d.mts +19 -0
- package/dist/managed-sources.mjs +503 -0
- package/dist/mcp-contracts.mjs +153 -0
- package/dist/mcp.mjs +369 -0
- package/dist/pack-project.mjs +156 -0
- package/dist/preview-control.mjs +260 -0
- package/dist/preview.mjs +313 -0
- package/dist/project-teams.mjs +98 -0
- package/dist/project.mjs +140 -0
- package/dist/rename.mjs +112 -0
- package/dist/setup.mjs +134 -0
- package/dist/source-lock.mjs +103 -0
- package/dist/template/LICENSE +21 -0
- package/dist/template/README.md +17 -0
- package/dist/template/arcadia.config.mjs +2 -0
- package/dist/template/assets/marks/slow.png +0 -0
- package/dist/template/assets/pets/frostling-battle.png +0 -0
- package/dist/template/assets/pets/frostling-icon.png +0 -0
- package/dist/template/assets/pets/frostling-portrait.png +0 -0
- package/dist/template/data/marks/slow.yaml +18 -0
- package/dist/template/data/presentations/main.yaml +34 -0
- package/dist/template/data/resources/main.yaml +21 -0
- package/dist/template/data/skills/rest.yaml +6 -0
- package/dist/template/data/skills/strike.yaml +14 -0
- package/dist/template/data/species/pet-swf.yaml +36 -0
- package/dist/template/data/species/pet.yaml +34 -0
- package/dist/template/debug/teams/blue.yaml +25 -0
- package/dist/template/debug/teams/orange.yaml +25 -0
- package/dist/template/docs/presentation.md +21 -0
- package/dist/template/locales/en/mark.yaml +5 -0
- package/dist/template/locales/en/skill.yaml +12 -0
- package/dist/template/locales/en/species.yaml +6 -0
- package/dist/template/locales/zh-CN/mark.yaml +4 -0
- package/dist/template/locales/zh-CN/skill.yaml +10 -0
- package/dist/template/locales/zh-CN/species.yaml +6 -0
- package/dist/template/package.json +44 -0
- package/dist/template/skills/arcadia-content-authoring/SKILL.md +23 -0
- package/dist/template/skills/arcadia-content-authoring/references/project-sources.md +15 -0
- package/dist/template/skills/arcadia-content-authoring/references/tool-workflows.md +37 -0
- package/dist/template/skills/seer2-recreate-pet/SKILL.md +82 -0
- package/dist/template/skills/seer2-recreate-pet/references/mechanics-and-validation.md +47 -0
- package/dist/template/skills/seer2-recreate-pet/references/project-conventions.md +32 -0
- package/dist/template/skills/seer2-recreate-pet/references/testing.md +50 -0
- package/dist/template/src/effects.ts +44 -0
- package/dist/template/test/pack.test.mjs +178 -0
- package/dist/template/tsconfig.json +15 -0
- package/dist/testing.mjs +204 -0
- package/dist/workbench-context.mjs +18 -0
- package/dist/workspace-cli.mjs +60 -0
- package/dist/workspace-materials.mjs +153 -0
- package/dist/workspace.mjs +684 -0
- package/package.json +68 -3
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { lstat, readFile, realpath } from 'node:fs/promises'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
3
|
+
import { AuthorWorkspace, WorkspaceError, diagnostic } from './workspace.mjs'
|
|
4
|
+
import { recordSharing } from './lib/yaml-sharing.mjs'
|
|
5
|
+
|
|
6
|
+
const kinds = ['content', 'presentations', 'resources', 'assets', 'files', 'locales', 'diagnostics']
|
|
7
|
+
const contentKinds = ['species', 'skills', 'marks', 'behaviors', 'presentations', 'resources']
|
|
8
|
+
const localeKinds = {
|
|
9
|
+
species: 'species',
|
|
10
|
+
skill: 'skills',
|
|
11
|
+
mark: 'marks',
|
|
12
|
+
mark_ability: 'marks',
|
|
13
|
+
mark_emblem: 'marks',
|
|
14
|
+
mark_global: 'marks',
|
|
15
|
+
}
|
|
16
|
+
const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0)
|
|
17
|
+
const invalid = message => {
|
|
18
|
+
throw new WorkspaceError('QUERY_INVALID', message)
|
|
19
|
+
}
|
|
20
|
+
const pageBytes = 2 * 1024 * 1024
|
|
21
|
+
const packageLimit = 256
|
|
22
|
+
const packageNamePattern = /^(?:@[a-z0-9_.-]+\/)?[a-z0-9][a-z0-9_.-]*$/i
|
|
23
|
+
|
|
24
|
+
function options(input) {
|
|
25
|
+
const value = { kind: 'content', scope: 'project', detail: 'summary', search: '', offset: 0, limit: 50, ...input }
|
|
26
|
+
if (!kinds.includes(value.kind)) invalid('查询类型无效')
|
|
27
|
+
if (!['project', 'dependencies', 'all'].includes(value.scope)) invalid('查询范围无效')
|
|
28
|
+
if (!['summary', 'full'].includes(value.detail)) invalid('查询详情级别无效')
|
|
29
|
+
if (value.contentKind !== undefined && !contentKinds.includes(value.contentKind)) invalid('内容类型无效')
|
|
30
|
+
for (const key of ['search', 'id', 'locale', 'namespace', 'packageName'])
|
|
31
|
+
if (value[key] !== undefined && (typeof value[key] !== 'string' || value[key].length > 200))
|
|
32
|
+
invalid(`${key} 需要不超过 200 字符的文本`)
|
|
33
|
+
if (!Number.isInteger(value.offset) || value.offset < 0) invalid('offset 需要非负整数')
|
|
34
|
+
if (!Number.isInteger(value.limit) || value.limit < 1 || value.limit > 100) invalid('limit 需要 1–100 的整数')
|
|
35
|
+
return value
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function runtimeDependencies(manifest) {
|
|
39
|
+
const entries = new Map()
|
|
40
|
+
for (const field of ['dependencies', 'peerDependencies', 'optionalDependencies'])
|
|
41
|
+
for (const name of Object.keys(manifest[field] ?? {}).sort(compare)) {
|
|
42
|
+
if (!packageNamePattern.test(name)) throw new WorkspaceError('DEPENDENCY_INVALID', '依赖包名无效', 'package.json')
|
|
43
|
+
entries.set(name, field === 'optionalDependencies' || manifest.peerDependenciesMeta?.[name]?.optional === true)
|
|
44
|
+
}
|
|
45
|
+
return [...entries].sort(([a], [b]) => compare(a, b))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Resolve declared packages without executing package exports or consulting global module paths.
|
|
49
|
+
async function installedPackage(from, name) {
|
|
50
|
+
for (let directory = from; ; directory = dirname(directory)) {
|
|
51
|
+
const candidate = join(directory, 'node_modules', name)
|
|
52
|
+
try {
|
|
53
|
+
const root = await realpath(candidate)
|
|
54
|
+
const file = join(root, 'package.json')
|
|
55
|
+
const info = await lstat(file)
|
|
56
|
+
if (!info.isFile() || info.size > pageBytes)
|
|
57
|
+
throw new WorkspaceError('DEPENDENCY_INVALID', '依赖清单需要不超过 2 MiB 的普通文件', file)
|
|
58
|
+
return { root, manifest: JSON.parse(await readFile(file, 'utf8')) }
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error.code !== 'ENOENT') throw error
|
|
61
|
+
}
|
|
62
|
+
if (dirname(directory) === directory) throw new WorkspaceError('DEPENDENCY_MISSING', `未安装声明的依赖:${name}`)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function provenance(snapshot, scope, manifest) {
|
|
67
|
+
return {
|
|
68
|
+
namespace: snapshot.project.namespace,
|
|
69
|
+
packageName: manifest.name,
|
|
70
|
+
packageVersion: manifest.version,
|
|
71
|
+
projectId: snapshot.project.projectId,
|
|
72
|
+
scope,
|
|
73
|
+
readOnly: scope === 'dependencies' || !snapshot.capabilities.sourceEditing,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function catalogs(workspace, scope) {
|
|
78
|
+
const manifest = JSON.parse((await workspace.read('package.json')).text)
|
|
79
|
+
const project = await workspace.snapshot()
|
|
80
|
+
const own = { snapshot: project, owner: provenance(project, 'project', manifest) }
|
|
81
|
+
const result = scope === 'dependencies' ? [] : [own]
|
|
82
|
+
const diagnostics = []
|
|
83
|
+
if (scope === 'project') return { catalogs: result, diagnostics }
|
|
84
|
+
const queue = runtimeDependencies(manifest).map(([name, optional]) => ({ from: workspace.root, name, optional }))
|
|
85
|
+
const visited = new Set([workspace.root])
|
|
86
|
+
const identities = new Map([[project.project.namespace, manifest.name]])
|
|
87
|
+
let inspected = 0
|
|
88
|
+
while (queue.length) {
|
|
89
|
+
if (++inspected > packageLimit) {
|
|
90
|
+
diagnostics.push({
|
|
91
|
+
code: 'DEPENDENCY_QUERY_LIMIT',
|
|
92
|
+
severity: 'warning',
|
|
93
|
+
message: '依赖查询超过 256 项,请缩小依赖树;结果不完整',
|
|
94
|
+
})
|
|
95
|
+
break
|
|
96
|
+
}
|
|
97
|
+
const { from, name, optional } = queue.shift()
|
|
98
|
+
let dependency
|
|
99
|
+
try {
|
|
100
|
+
const { root, manifest: metadata } = await installedPackage(from, name)
|
|
101
|
+
if (visited.has(root)) continue
|
|
102
|
+
visited.add(root)
|
|
103
|
+
if (metadata.arcadia || metadata.name === '@arcadia-eternity/data-pack-base') {
|
|
104
|
+
dependency = await AuthorWorkspace.open(root, { watch: false, readOnly: true, published: !!metadata.arcadia })
|
|
105
|
+
const snapshot = await dependency.snapshot()
|
|
106
|
+
const owner = provenance(snapshot, 'dependencies', metadata)
|
|
107
|
+
const previous = identities.get(owner.namespace)
|
|
108
|
+
if (previous !== undefined)
|
|
109
|
+
diagnostics.push({
|
|
110
|
+
...owner,
|
|
111
|
+
code: 'NAMESPACE_CONFLICT',
|
|
112
|
+
severity: 'error',
|
|
113
|
+
message: `命名空间 ${owner.namespace} 同时用于 ${previous} 和 ${metadata.name}`,
|
|
114
|
+
})
|
|
115
|
+
identities.set(owner.namespace, metadata.name)
|
|
116
|
+
result.push({ snapshot, owner })
|
|
117
|
+
// Match the loader's visible content dependencies: stop at each content package.
|
|
118
|
+
} else {
|
|
119
|
+
queue.push(
|
|
120
|
+
...runtimeDependencies(metadata).map(([child, absentAllowed]) => ({
|
|
121
|
+
from: root,
|
|
122
|
+
name: child,
|
|
123
|
+
optional: absentAllowed,
|
|
124
|
+
})),
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (!(optional && error.code === 'DEPENDENCY_MISSING'))
|
|
129
|
+
diagnostics.push({ ...diagnostic(error), packageName: name, scope: 'dependencies', readOnly: true })
|
|
130
|
+
} finally {
|
|
131
|
+
await dependency?.close()
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { catalogs: result, diagnostics }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function translations(snapshot, row, locale) {
|
|
138
|
+
return snapshot.localeSources
|
|
139
|
+
.flatMap(source =>
|
|
140
|
+
localeKinds[source.namespace] === row.kind &&
|
|
141
|
+
(!locale || source.language === locale) &&
|
|
142
|
+
source.entries[row.record.id]
|
|
143
|
+
? [{ locale: source.language, localeNamespace: source.namespace, ...source.entries[row.record.id] }]
|
|
144
|
+
: [],
|
|
145
|
+
)
|
|
146
|
+
.sort((a, b) => compare(a.locale, b.locale) || compare(a.localeNamespace, b.localeNamespace))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function nameFields(localizations, requested, fallback) {
|
|
150
|
+
const locale = requested ?? localizations.find(entry => entry.locale === 'zh-CN')?.locale ?? localizations[0]?.locale
|
|
151
|
+
const names = [
|
|
152
|
+
...new Set(
|
|
153
|
+
localizations
|
|
154
|
+
.filter(entry => entry.locale === locale)
|
|
155
|
+
.map(entry => entry.name)
|
|
156
|
+
.filter(Boolean),
|
|
157
|
+
),
|
|
158
|
+
]
|
|
159
|
+
return {
|
|
160
|
+
...(locale ? { locale } : {}),
|
|
161
|
+
...(names.length === 1
|
|
162
|
+
? { name: names[0].slice(0, 200) }
|
|
163
|
+
: !names.length && typeof fallback === 'string'
|
|
164
|
+
? { name: fallback.slice(0, 200) }
|
|
165
|
+
: {}),
|
|
166
|
+
...(names.length > 1 ? { ambiguousName: true } : {}),
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function rowsFor({ snapshot, owner }, query) {
|
|
171
|
+
const identify = (id, kind, source = {}) => ({
|
|
172
|
+
...owner,
|
|
173
|
+
kind,
|
|
174
|
+
id,
|
|
175
|
+
qualifiedId: `${owner.namespace}:${id}`,
|
|
176
|
+
...source,
|
|
177
|
+
})
|
|
178
|
+
if (query.kind === 'locales')
|
|
179
|
+
return snapshot.localeSources.flatMap(source =>
|
|
180
|
+
Object.entries(source.entries).map(([id, record]) => {
|
|
181
|
+
const row = identify(id, 'locales', {
|
|
182
|
+
contentKind: localeKinds[source.namespace],
|
|
183
|
+
file: source.file,
|
|
184
|
+
version: source.version,
|
|
185
|
+
locale: source.language,
|
|
186
|
+
localeNamespace: source.namespace,
|
|
187
|
+
...(source.locations?.[id] ?? {}),
|
|
188
|
+
})
|
|
189
|
+
return {
|
|
190
|
+
row,
|
|
191
|
+
text: JSON.stringify({ ...row, ...record }),
|
|
192
|
+
full: { ...row, record, sharedFields: recordSharing(source.sharedFields, id) },
|
|
193
|
+
summary: {
|
|
194
|
+
...row,
|
|
195
|
+
...(record.name ? { name: record.name.slice(0, 200) } : {}),
|
|
196
|
+
...(record.description ? { descriptionPreview: record.description.slice(0, 240) } : {}),
|
|
197
|
+
},
|
|
198
|
+
}
|
|
199
|
+
}),
|
|
200
|
+
)
|
|
201
|
+
if (query.kind === 'files' || query.kind === 'diagnostics')
|
|
202
|
+
return (query.kind === 'files' ? snapshot.files : snapshot.diagnostics).map(entry => {
|
|
203
|
+
const row = { ...owner, kind: query.kind, ...entry }
|
|
204
|
+
return { row, text: JSON.stringify(row), full: row, summary: row }
|
|
205
|
+
})
|
|
206
|
+
if (query.kind === 'assets')
|
|
207
|
+
return snapshot.assets.map(asset => {
|
|
208
|
+
const definition = snapshot.records.find(
|
|
209
|
+
row => row.kind === 'resources' && row.record.id === asset.id && row.file === asset.definition,
|
|
210
|
+
)
|
|
211
|
+
const { kind: resourceKind, ...metadata } = asset
|
|
212
|
+
const row = identify(asset.id, 'assets', {
|
|
213
|
+
contentKind: 'resources',
|
|
214
|
+
resourceKind,
|
|
215
|
+
...metadata,
|
|
216
|
+
...(definition ? { version: definition.version, index: definition.index } : {}),
|
|
217
|
+
})
|
|
218
|
+
const { references, ...summary } = row
|
|
219
|
+
return { row, text: JSON.stringify(row), full: row, summary: { ...summary, referenceCount: references.length } }
|
|
220
|
+
})
|
|
221
|
+
return snapshot.records
|
|
222
|
+
.filter(row => !['presentations', 'resources'].includes(query.kind) || row.kind === query.kind)
|
|
223
|
+
.map(source => {
|
|
224
|
+
const localizations = translations(snapshot, source, query.locale)
|
|
225
|
+
const row = identify(source.record.id, source.kind, {
|
|
226
|
+
contentKind: source.kind,
|
|
227
|
+
file: source.file,
|
|
228
|
+
version: source.version,
|
|
229
|
+
index: source.index,
|
|
230
|
+
...(source.line ? { line: source.line, column: source.column } : {}),
|
|
231
|
+
...nameFields(localizations, query.locale, source.record.name),
|
|
232
|
+
})
|
|
233
|
+
return {
|
|
234
|
+
row,
|
|
235
|
+
text: JSON.stringify({ ...row, record: source.record, localizations }),
|
|
236
|
+
summary: row,
|
|
237
|
+
full: { ...row, record: source.record, sharedFields: source.sharedFields, localizations },
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Read-only discovery over disk data. Never loads effects or changes workbench selection/drafts. */
|
|
243
|
+
export async function queryContent(workspace, input = {}) {
|
|
244
|
+
const query = options(input)
|
|
245
|
+
const { catalogs: sources, diagnostics } = await catalogs(workspace, query.scope)
|
|
246
|
+
const needle = query.search.toLowerCase()
|
|
247
|
+
const rows = sources
|
|
248
|
+
.flatMap(source => rowsFor(source, query))
|
|
249
|
+
.filter(
|
|
250
|
+
({ row, text }) =>
|
|
251
|
+
(query.id === undefined || row.id === query.id || row.qualifiedId === query.id) &&
|
|
252
|
+
(query.contentKind === undefined || row.contentKind === query.contentKind) &&
|
|
253
|
+
(query.namespace === undefined || row.namespace === query.namespace) &&
|
|
254
|
+
(query.packageName === undefined || row.packageName === query.packageName) &&
|
|
255
|
+
(query.kind !== 'locales' || query.locale === undefined || row.locale === query.locale) &&
|
|
256
|
+
text.toLowerCase().includes(needle),
|
|
257
|
+
)
|
|
258
|
+
if (
|
|
259
|
+
query.id !== undefined &&
|
|
260
|
+
['content', 'presentations', 'resources', 'assets'].includes(query.kind) &&
|
|
261
|
+
rows.length > 1
|
|
262
|
+
)
|
|
263
|
+
diagnostics.push({
|
|
264
|
+
code: 'CONTENT_AMBIGUOUS',
|
|
265
|
+
severity: 'warning',
|
|
266
|
+
message: '此 ID 对应多个对象;请使用 contentKind、namespace 或 packageName 明确目标',
|
|
267
|
+
})
|
|
268
|
+
const items = []
|
|
269
|
+
let bytes = 0
|
|
270
|
+
for (const candidate of rows.slice(query.offset, query.offset + query.limit)) {
|
|
271
|
+
const item = candidate[query.detail === 'full' ? 'full' : 'summary']
|
|
272
|
+
const size = Buffer.byteLength(JSON.stringify(item))
|
|
273
|
+
if (bytes + size > pageBytes) {
|
|
274
|
+
if (!items.length)
|
|
275
|
+
throw new WorkspaceError('QUERY_ITEM_TOO_LARGE', '此详情超过 2 MiB,请查询摘要并读取对应源码文件')
|
|
276
|
+
break
|
|
277
|
+
}
|
|
278
|
+
bytes += size
|
|
279
|
+
items.push(item)
|
|
280
|
+
}
|
|
281
|
+
const next = query.offset + items.length
|
|
282
|
+
return { total: rows.length, offset: query.offset, nextOffset: next < rows.length ? next : null, items, diagnostics }
|
|
283
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
export interface EnvironmentRules {
|
|
2
|
+
schemaVersion: 1
|
|
3
|
+
tier?: string
|
|
4
|
+
allow?: { species?: string[]; skills?: string[]; marks?: string[] }
|
|
5
|
+
deny?: { species?: string[]; skills?: string[]; marks?: string[] }
|
|
6
|
+
team?: { minSize?: number; maxSize?: number; uniqueSpecies?: boolean }
|
|
7
|
+
}
|
|
8
|
+
export interface EnvironmentDocument {
|
|
9
|
+
schemaVersion: 2
|
|
10
|
+
id: string
|
|
11
|
+
name: string
|
|
12
|
+
packages: Record<string, string>
|
|
13
|
+
sources: string[]
|
|
14
|
+
disabled?: { packages: Record<string, string>; sources: string[] }
|
|
15
|
+
rules: EnvironmentRules
|
|
16
|
+
requires: { engine?: string; sdk?: string; capabilities?: string[] }
|
|
17
|
+
}
|
|
18
|
+
export interface EnvironmentDraft {
|
|
19
|
+
document: EnvironmentDocument
|
|
20
|
+
revision: string
|
|
21
|
+
}
|
|
22
|
+
export interface EnvironmentVersion {
|
|
23
|
+
format: 'arcadia.environment-version/1'
|
|
24
|
+
versionId: string
|
|
25
|
+
workspaceId: string
|
|
26
|
+
environmentId: string
|
|
27
|
+
document: EnvironmentDocument
|
|
28
|
+
draftRevision: string
|
|
29
|
+
contentRevision: string
|
|
30
|
+
members?: {
|
|
31
|
+
name: string
|
|
32
|
+
version: string
|
|
33
|
+
projectId: string
|
|
34
|
+
namespace: string
|
|
35
|
+
direct: boolean
|
|
36
|
+
dependencies: string[]
|
|
37
|
+
requiredBy: string[]
|
|
38
|
+
}[]
|
|
39
|
+
packages: unknown[]
|
|
40
|
+
createdAt: number
|
|
41
|
+
adopted: boolean
|
|
42
|
+
materialDirectory: string
|
|
43
|
+
directory: string
|
|
44
|
+
status: 'ready'
|
|
45
|
+
}
|
|
46
|
+
export interface UnavailableVersion {
|
|
47
|
+
versionId: string
|
|
48
|
+
workspaceId: string
|
|
49
|
+
environmentId?: string
|
|
50
|
+
status: 'unavailable'
|
|
51
|
+
reason: string
|
|
52
|
+
}
|
|
53
|
+
export interface PrepareVersionInput {
|
|
54
|
+
onProgress?: (progress: { stage: string; completed?: number; total?: number }) => void | Promise<void>
|
|
55
|
+
environmentId: string
|
|
56
|
+
expectedRevision: string
|
|
57
|
+
projectDirectory?: string
|
|
58
|
+
directory?: string
|
|
59
|
+
signal?: AbortSignal
|
|
60
|
+
beforeCommit?: () => Promise<void>
|
|
61
|
+
}
|
|
62
|
+
export type StaticPreparer = (input: {
|
|
63
|
+
directory: string
|
|
64
|
+
draft: EnvironmentDocument
|
|
65
|
+
signal?: AbortSignal
|
|
66
|
+
}) => Promise<{
|
|
67
|
+
contentRevision: string
|
|
68
|
+
packages?: unknown[]
|
|
69
|
+
}>
|
|
70
|
+
export interface ContentWorkspaceOptions {
|
|
71
|
+
maxBytes?: number
|
|
72
|
+
maxFiles?: number
|
|
73
|
+
stagingRetentionMs?: number
|
|
74
|
+
resolveProject?: (environmentId: string) => string | undefined | Promise<string | undefined>
|
|
75
|
+
acquireMaterials?: (directory: string, versionId: string) => Promise<() => void | Promise<void>>
|
|
76
|
+
retentions?: {
|
|
77
|
+
list(versionId: string): Promise<Record<string, unknown>[]>
|
|
78
|
+
put?(versionId: string, retentionId: string): Promise<void>
|
|
79
|
+
remove?(retentionId: string): Promise<void>
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export interface EnvironmentExport {
|
|
83
|
+
format: 'arcadia.environment-export/1'
|
|
84
|
+
document: EnvironmentDocument
|
|
85
|
+
contentRevision: string
|
|
86
|
+
files: { path: string; data: string }[]
|
|
87
|
+
}
|
|
88
|
+
export interface WorkspaceSnapshot {
|
|
89
|
+
format: 'arcadia.workspace-snapshot/1'
|
|
90
|
+
workspaceId: string
|
|
91
|
+
drafts: EnvironmentDraft[]
|
|
92
|
+
versions: {
|
|
93
|
+
version: Pick<
|
|
94
|
+
EnvironmentVersion,
|
|
95
|
+
'versionId' | 'environmentId' | 'document' | 'draftRevision' | 'contentRevision' | 'packages' | 'createdAt'
|
|
96
|
+
>
|
|
97
|
+
files: { path: string; data: string }[]
|
|
98
|
+
}[]
|
|
99
|
+
}
|
|
100
|
+
export interface WorkspaceSnapshotStamp {
|
|
101
|
+
workspaceId: string
|
|
102
|
+
bootId: string
|
|
103
|
+
generation: number
|
|
104
|
+
}
|
|
105
|
+
export interface WorkspaceSnapshotCapture {
|
|
106
|
+
snapshot: WorkspaceSnapshot
|
|
107
|
+
stamp: WorkspaceSnapshotStamp
|
|
108
|
+
}
|
|
109
|
+
export class ContentWorkspace {
|
|
110
|
+
readonly root: string
|
|
111
|
+
readonly workspaceId: string
|
|
112
|
+
readonly bootId: string
|
|
113
|
+
static open(directory: string, options?: ContentWorkspaceOptions): Promise<ContentWorkspace>
|
|
114
|
+
listDrafts(): Promise<EnvironmentDraft[]>
|
|
115
|
+
getDraft(environmentId: string): Promise<EnvironmentDraft>
|
|
116
|
+
saveDraft(input: { document: unknown; expectedRevision: string | null }): Promise<EnvironmentDraft>
|
|
117
|
+
deleteDraft(input: { environmentId: string; expectedRevision: string }): Promise<void>
|
|
118
|
+
prepareVersion(input: PrepareVersionInput, preparer: StaticPreparer): Promise<EnvironmentVersion>
|
|
119
|
+
adoptVersion(input: PrepareVersionInput, preparer: StaticPreparer): Promise<EnvironmentVersion>
|
|
120
|
+
getVersion(versionId: string): Promise<EnvironmentVersion>
|
|
121
|
+
listVersions(environmentId?: string): Promise<(EnvironmentVersion | UnavailableVersion)[]>
|
|
122
|
+
acquire(versionId: string, owner?: string): Promise<EnvironmentVersion & { release(): Promise<void> }>
|
|
123
|
+
retain(versionId: string, retentionId: string): Promise<void>
|
|
124
|
+
releaseRetention(retentionId: string): Promise<void>
|
|
125
|
+
references(versionId: string): Promise<Record<string, unknown>[]>
|
|
126
|
+
deleteVersion(versionId: string): Promise<void>
|
|
127
|
+
exportVersion(versionId: string): Promise<EnvironmentExport>
|
|
128
|
+
exportSnapshot(): Promise<WorkspaceSnapshot>
|
|
129
|
+
captureSnapshot(): Promise<WorkspaceSnapshotCapture>
|
|
130
|
+
isSnapshotCurrent(stamp: WorkspaceSnapshotStamp): Promise<boolean>
|
|
131
|
+
restoreSnapshot(
|
|
132
|
+
snapshot: WorkspaceSnapshot,
|
|
133
|
+
input: { mode: 'restore' | 'clone' },
|
|
134
|
+
preparer: StaticPreparer,
|
|
135
|
+
): Promise<{ workspaceId: string; versionIds: Record<string, string> }>
|
|
136
|
+
importVersion(
|
|
137
|
+
bundle: EnvironmentExport,
|
|
138
|
+
input: {
|
|
139
|
+
environmentId?: string
|
|
140
|
+
expectedRevision?: string | null
|
|
141
|
+
signal?: AbortSignal
|
|
142
|
+
beforeCommit?: () => Promise<void>
|
|
143
|
+
importId?: string
|
|
144
|
+
},
|
|
145
|
+
preparer: StaticPreparer,
|
|
146
|
+
): Promise<EnvironmentVersion>
|
|
147
|
+
recoverImport(importId: string): Promise<EnvironmentVersion>
|
|
148
|
+
forgetImport(importId: string, input?: { discard?: boolean }): Promise<void>
|
|
149
|
+
reconcile(): Promise<{
|
|
150
|
+
workspaceId: string
|
|
151
|
+
versions: (EnvironmentVersion | UnavailableVersion)[]
|
|
152
|
+
abandoned: string[]
|
|
153
|
+
}>
|
|
154
|
+
close(input?: { force?: boolean }): Promise<void>
|
|
155
|
+
cleanupStaging(): Promise<string[]>
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function setEnvironmentPackageEnabled(
|
|
159
|
+
workspace: Pick<ContentWorkspace, 'listDrafts' | 'listVersions' | 'saveDraft'>,
|
|
160
|
+
input: { environmentId: string; expectedRevision: string; name: string; enabled: boolean; cascade?: boolean },
|
|
161
|
+
): Promise<EnvironmentDraft>
|