@arcadia-eternity/content-sdk 4.5.3 → 4.6.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.
|
@@ -166,10 +166,19 @@ export interface EnvironmentMember {
|
|
|
166
166
|
}
|
|
167
167
|
export declare const ContentWorkspace: ContentWorkspaceConstructor;
|
|
168
168
|
/** Change desired roots only. Resolved material and all published installations remain immutable. */
|
|
169
|
-
export
|
|
169
|
+
export type AddEnvironmentPackageInput = {
|
|
170
|
+
environmentId: string;
|
|
171
|
+
expectedRevision: string;
|
|
172
|
+
name: string;
|
|
173
|
+
version?: string;
|
|
174
|
+
source?: boolean;
|
|
175
|
+
};
|
|
176
|
+
export type RemoveEnvironmentPackageInput = {
|
|
170
177
|
environmentId: string;
|
|
171
178
|
expectedRevision: string;
|
|
172
179
|
name: string;
|
|
173
|
-
enabled: boolean;
|
|
174
180
|
cascade?: boolean;
|
|
175
|
-
}
|
|
181
|
+
};
|
|
182
|
+
type PackageWorkspace = Pick<ContentWorkspace, 'listDrafts' | 'listInstallations' | 'saveDraft'>;
|
|
183
|
+
export declare function addEnvironmentPackage(workspace: PackageWorkspace, input: AddEnvironmentPackageInput): Promise<EnvironmentDraft>;
|
|
184
|
+
export declare function removeEnvironmentPackage(workspace: PackageWorkspace, input: RemoveEnvironmentPackageInput): Promise<EnvironmentDraft>;
|
|
@@ -4,7 +4,7 @@ import { join, resolve } from 'node:path';
|
|
|
4
4
|
import writeFileAtomic from 'write-file-atomic';
|
|
5
5
|
import semver from 'semver';
|
|
6
6
|
import { inspectNpmProject } from '@arcadia-eternity/pack-loader/node';
|
|
7
|
-
import { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
7
|
+
import { normalizeEnvironmentDocument, EnvironmentDocumentV2Schema, } from './debug-environments.js';
|
|
8
8
|
import { withSourceLock } from './source-lock.js';
|
|
9
9
|
import { contentError, materialFiles, writeMaterials } from './workspace-materials.js';
|
|
10
10
|
import { errorCode, isRecord } from './types.js';
|
|
@@ -168,6 +168,18 @@ class ContentWorkspaceImplementation {
|
|
|
168
168
|
#directory(id) {
|
|
169
169
|
return join(this.root, 'environments', checkId(id, envId));
|
|
170
170
|
}
|
|
171
|
+
async #archiveRemovedDeclarations(id) {
|
|
172
|
+
const text = await readFile(join(this.#directory(id), 'package.json'), 'utf8').catch(error => {
|
|
173
|
+
if (errorCode(error) !== 'ENOENT')
|
|
174
|
+
throw error;
|
|
175
|
+
return undefined;
|
|
176
|
+
});
|
|
177
|
+
if (!text || !Object.hasOwn(JSON.parse(text).arcadiaEnvironment ?? {}, 'disabled'))
|
|
178
|
+
return;
|
|
179
|
+
const archive = join(this.root, 'migration-backups');
|
|
180
|
+
await regularDirectory(archive);
|
|
181
|
+
await writeFileAtomic(join(archive, `${id}-${revision(text)}.json`), text);
|
|
182
|
+
}
|
|
171
183
|
#manifest(document, previous = {}) {
|
|
172
184
|
const { packages, ...metadata } = document;
|
|
173
185
|
const priorDependencies = isRecord(previous.dependencies) ? previous.dependencies : {};
|
|
@@ -231,6 +243,7 @@ class ContentWorkspaceImplementation {
|
|
|
231
243
|
if ((previous === null ? null : revision(previous)) !== input.expectedRevision)
|
|
232
244
|
throw contentError('REVISION_CONFLICT');
|
|
233
245
|
await regularDirectory(directory);
|
|
246
|
+
await this.#archiveRemovedDeclarations(document.id);
|
|
234
247
|
await writeFileAtomic(file, json(this.#manifest(document, previous ? JSON.parse(previous) : {})));
|
|
235
248
|
return this.#draft(document.id);
|
|
236
249
|
}, true);
|
|
@@ -368,6 +381,7 @@ class ContentWorkspaceImplementation {
|
|
|
368
381
|
}
|
|
369
382
|
await input.beforeCommit?.();
|
|
370
383
|
signal.throwIfAborted();
|
|
384
|
+
await this.#archiveRemovedDeclarations(document.id);
|
|
371
385
|
if (input.importId)
|
|
372
386
|
return this.#finishImport(input.importId);
|
|
373
387
|
try {
|
|
@@ -631,6 +645,7 @@ class ContentWorkspaceImplementation {
|
|
|
631
645
|
const prepared = await readJson(join(staging, '.arcadia-prepared.json'));
|
|
632
646
|
if (prepared.importId !== id || prepared.installationId !== environmentId)
|
|
633
647
|
throw contentError('IMPORT_INTENT_INVALID');
|
|
648
|
+
await this.#archiveRemovedDeclarations(environmentId);
|
|
634
649
|
const previous = join(this.root, 'staging', `replaced-${environmentId}`);
|
|
635
650
|
let moved = false;
|
|
636
651
|
try {
|
|
@@ -725,10 +740,21 @@ class ContentWorkspaceImplementation {
|
|
|
725
740
|
}
|
|
726
741
|
}
|
|
727
742
|
export const ContentWorkspace = ContentWorkspaceImplementation;
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
743
|
+
export function addEnvironmentPackage(workspace, input) {
|
|
744
|
+
return changeEnvironmentPackage(workspace, { ...input, action: 'add' });
|
|
745
|
+
}
|
|
746
|
+
export function removeEnvironmentPackage(workspace, input) {
|
|
747
|
+
return changeEnvironmentPackage(workspace, { ...input, action: 'remove' });
|
|
748
|
+
}
|
|
749
|
+
async function changeEnvironmentPackage(workspace, input) {
|
|
750
|
+
const { environmentId, expectedRevision, name } = input;
|
|
751
|
+
const cascade = input.action === 'remove' ? (input.cascade ?? false) : false;
|
|
752
|
+
if (!EnvironmentDocumentV2Schema.shape.sources.safeParse([name]).success || typeof cascade !== 'boolean')
|
|
753
|
+
throw contentError('ENVIRONMENT_PACKAGE_INVALID');
|
|
754
|
+
if (input.action === 'add' &&
|
|
755
|
+
((input.version !== undefined && (typeof input.version !== 'string' || !input.version.trim())) ||
|
|
756
|
+
(input.source !== undefined && typeof input.source !== 'boolean') ||
|
|
757
|
+
(input.version !== undefined && input.source === true)))
|
|
732
758
|
throw contentError('ENVIRONMENT_PACKAGE_INVALID');
|
|
733
759
|
const draft = (await workspace.listDrafts()).find(item => item.document.id === environmentId);
|
|
734
760
|
if (!draft)
|
|
@@ -736,33 +762,31 @@ export async function setEnvironmentPackageEnabled(workspace, input) {
|
|
|
736
762
|
if (draft.revision !== expectedRevision)
|
|
737
763
|
throw contentError('REVISION_CONFLICT');
|
|
738
764
|
const document = structuredClone(draft.document);
|
|
739
|
-
const disabled = document.disabled ?? { packages: {}, sources: [] };
|
|
740
|
-
document.disabled = disabled;
|
|
741
765
|
const active = new Set([...Object.keys(document.packages), ...document.sources]);
|
|
742
|
-
if (
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
document.
|
|
747
|
-
delete disabled.packages[name];
|
|
766
|
+
if (input.action === 'add') {
|
|
767
|
+
const version = input.version?.trim();
|
|
768
|
+
if (version !== undefined) {
|
|
769
|
+
document.packages[name] = version;
|
|
770
|
+
document.sources = document.sources.filter(value => value !== name);
|
|
748
771
|
}
|
|
749
|
-
else if (
|
|
750
|
-
document.
|
|
751
|
-
|
|
772
|
+
else if (input.source === true) {
|
|
773
|
+
delete document.packages[name];
|
|
774
|
+
if (!document.sources.includes(name))
|
|
775
|
+
document.sources.push(name);
|
|
752
776
|
}
|
|
753
777
|
else
|
|
754
|
-
throw contentError('
|
|
778
|
+
throw contentError('ENVIRONMENT_PACKAGE_DECLARATION_REQUIRED', '新增内容包需要指定版本或已登记来源');
|
|
755
779
|
}
|
|
756
780
|
else {
|
|
757
781
|
const version = (await workspace.listInstallations())
|
|
758
782
|
.filter((item) => item.status === 'ready')
|
|
759
783
|
.filter(item => item.environmentId === environmentId && item.members)
|
|
760
784
|
.sort((a, b) => b.createdAt - a.createdAt)[0];
|
|
761
|
-
// A graph captured for different roots/ranges cannot justify
|
|
785
|
+
// A graph captured for different roots/ranges cannot justify removing a shared dependency.
|
|
762
786
|
if (!version ||
|
|
763
787
|
Object.entries(document.packages).some(([key, range]) => version.document.packages[key] !== range) ||
|
|
764
788
|
document.sources.some(key => !version.document.sources.includes(key)))
|
|
765
|
-
throw contentError('ENVIRONMENT_DEPENDENCIES_UNRESOLVED', '
|
|
789
|
+
throw contentError('ENVIRONMENT_DEPENDENCIES_UNRESOLVED', '请先准备当前组合,再移出内容包');
|
|
766
790
|
const affected = new Set([name]);
|
|
767
791
|
for (let changed = true; changed;) {
|
|
768
792
|
changed = false;
|
|
@@ -778,15 +802,9 @@ export async function setEnvironmentPackageEnabled(workspace, input) {
|
|
|
778
802
|
if (!cascade && roots.some(key => key !== name))
|
|
779
803
|
throw contentError('ENVIRONMENT_PACKAGE_REQUIRED', `仍被这些资源包依赖:${roots.filter(key => key !== name).join('、')}`);
|
|
780
804
|
for (const key of roots) {
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
delete document.packages[key];
|
|
784
|
-
}
|
|
785
|
-
else {
|
|
786
|
-
disabled.sources.push(key);
|
|
787
|
-
document.sources = document.sources.filter(value => value !== key);
|
|
788
|
-
}
|
|
805
|
+
delete document.packages[key];
|
|
806
|
+
document.sources = document.sources.filter(value => value !== key);
|
|
789
807
|
}
|
|
790
808
|
}
|
|
791
|
-
return workspace.saveDraft({ document, expectedRevision });
|
|
809
|
+
return workspace.saveDraft({ document: normalizeEnvironmentDocument(document), expectedRevision });
|
|
792
810
|
}
|
|
@@ -27,10 +27,6 @@ export declare const EnvironmentDocumentV2Schema: z.ZodObject<{
|
|
|
27
27
|
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
28
28
|
sources: z.ZodArray<z.ZodString>;
|
|
29
29
|
schemaVersion: z.ZodLiteral<2>;
|
|
30
|
-
disabled: z.ZodOptional<z.ZodObject<{
|
|
31
|
-
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
32
|
-
sources: z.ZodArray<z.ZodString>;
|
|
33
|
-
}, z.core.$strict>>;
|
|
34
30
|
rules: z.ZodObject<{
|
|
35
31
|
schemaVersion: z.ZodLiteral<1>;
|
|
36
32
|
tier: z.ZodOptional<z.ZodString>;
|
|
@@ -68,10 +64,6 @@ export declare const EnvironmentDocumentSchema: z.ZodDiscriminatedUnion<[z.ZodOb
|
|
|
68
64
|
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
69
65
|
sources: z.ZodArray<z.ZodString>;
|
|
70
66
|
schemaVersion: z.ZodLiteral<2>;
|
|
71
|
-
disabled: z.ZodOptional<z.ZodObject<{
|
|
72
|
-
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
73
|
-
sources: z.ZodArray<z.ZodString>;
|
|
74
|
-
}, z.core.$strict>>;
|
|
75
67
|
rules: z.ZodObject<{
|
|
76
68
|
schemaVersion: z.ZodLiteral<1>;
|
|
77
69
|
tier: z.ZodOptional<z.ZodString>;
|
|
@@ -72,7 +72,6 @@ export const EnvironmentDocumentV2Schema = z
|
|
|
72
72
|
.object({
|
|
73
73
|
schemaVersion: z.literal(2),
|
|
74
74
|
...sharedFields,
|
|
75
|
-
disabled: z.object({ packages: sharedFields.packages, sources: sharedFields.sources }).strict().optional(),
|
|
76
75
|
rules: EnvironmentRulesSchema,
|
|
77
76
|
requires: EnvironmentRequirementsSchema,
|
|
78
77
|
})
|
|
@@ -82,16 +81,16 @@ export const EnvironmentDocumentSchema = z.discriminatedUnion('schemaVersion', [
|
|
|
82
81
|
EnvironmentDocumentV2Schema,
|
|
83
82
|
]);
|
|
84
83
|
export function environmentDocument(input) {
|
|
84
|
+
// Legacy removed declarations are not environment members. Keep old files readable;
|
|
85
|
+
// the workspace archives the original manifest before its next write.
|
|
86
|
+
if (input && typeof input === 'object' && !Array.isArray(input) && 'disabled' in input) {
|
|
87
|
+
const { disabled: _removed, ...current } = input;
|
|
88
|
+
input = current;
|
|
89
|
+
}
|
|
85
90
|
const parsed = EnvironmentDocumentSchema.safeParse(input);
|
|
86
91
|
if (!parsed.success)
|
|
87
92
|
fail(`环境配置无效:${parsed.error.issues[0]?.message ?? ''}`);
|
|
88
|
-
|
|
89
|
-
const disabled = value.schemaVersion === 2 ? value.disabled : undefined;
|
|
90
|
-
if (disabled &&
|
|
91
|
-
(Object.keys(disabled.packages).some(name => Object.hasOwn(value.packages, name) || value.sources.includes(name)) ||
|
|
92
|
-
disabled.sources.some(name => Object.hasOwn(value.packages, name) || value.sources.includes(name) || Object.hasOwn(disabled.packages, name))))
|
|
93
|
-
fail('启用和停用的资源包不能重复');
|
|
94
|
-
return value;
|
|
93
|
+
return parsed.data;
|
|
95
94
|
}
|
|
96
95
|
/** Read legacy documents into the shared domain model without rewriting source files. */
|
|
97
96
|
export function normalizeEnvironmentDocument(value) {
|
package/dist/mcp-contracts.d.ts
CHANGED
|
@@ -309,10 +309,6 @@ export declare const outputSchemas: {
|
|
|
309
309
|
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
310
310
|
sources: z.ZodArray<z.ZodString>;
|
|
311
311
|
schemaVersion: z.ZodLiteral<2>;
|
|
312
|
-
disabled: z.ZodOptional<z.ZodObject<{
|
|
313
|
-
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
314
|
-
sources: z.ZodArray<z.ZodString>;
|
|
315
|
-
}, z.core.$strict>>;
|
|
316
312
|
rules: z.ZodObject<{
|
|
317
313
|
schemaVersion: z.ZodLiteral<1>;
|
|
318
314
|
tier: z.ZodOptional<z.ZodString>;
|
|
@@ -353,10 +349,6 @@ export declare const outputSchemas: {
|
|
|
353
349
|
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
354
350
|
sources: z.ZodArray<z.ZodString>;
|
|
355
351
|
schemaVersion: z.ZodLiteral<2>;
|
|
356
|
-
disabled: z.ZodOptional<z.ZodObject<{
|
|
357
|
-
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
358
|
-
sources: z.ZodArray<z.ZodString>;
|
|
359
|
-
}, z.core.$strict>>;
|
|
360
352
|
rules: z.ZodObject<{
|
|
361
353
|
schemaVersion: z.ZodLiteral<1>;
|
|
362
354
|
tier: z.ZodOptional<z.ZodString>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcadia-eternity/content-sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"yaml": "2.9.1",
|
|
54
54
|
"yauzl": "3.4.0",
|
|
55
55
|
"zod": "4.6.7",
|
|
56
|
-
"@arcadia-eternity/battle": "4.
|
|
57
|
-
"@arcadia-eternity/pack-loader": "4.
|
|
58
|
-
"@arcadia-eternity/schema": "4.
|
|
56
|
+
"@arcadia-eternity/battle": "4.6.0",
|
|
57
|
+
"@arcadia-eternity/pack-loader": "4.6.0",
|
|
58
|
+
"@arcadia-eternity/schema": "4.6.0"
|
|
59
59
|
},
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|