@arcadia-eternity/content-sdk 4.7.1 → 4.8.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.
@@ -446,6 +446,7 @@ export type StaticPreparer = (input: {
446
446
  elementCatalog?: ReturnType<typeof readElementCatalog>;
447
447
  }>;
448
448
  export interface ContentWorkspaceOptions {
449
+ includeBuiltin120?: boolean;
449
450
  allowShareDownloads?: boolean;
450
451
  bundledPackageRoot?: string;
451
452
  npmCache?: string;
@@ -489,6 +490,7 @@ export interface EnvironmentExport {
489
490
  }
490
491
  export interface WorkspaceSnapshot {
491
492
  format: 'arcadia.workspace-snapshot/2';
493
+ builtin120EnvironmentId?: string;
492
494
  workspaceId: string;
493
495
  drafts: (EnvironmentDraft & {
494
496
  files?: {
@@ -517,6 +519,7 @@ export interface ContentWorkspace {
517
519
  readonly root: string;
518
520
  readonly workspaceId: string;
519
521
  readonly bootId: string;
522
+ readonly builtin120EnvironmentId?: string;
520
523
  listDrafts(): Promise<EnvironmentDraft[]>;
521
524
  getDraft(environmentId: string): Promise<EnvironmentDraft>;
522
525
  saveDraft(input: {
@@ -602,3 +605,5 @@ export type RemoveEnvironmentPackageInput = {
602
605
  type PackageWorkspace = Pick<ContentWorkspace, 'listDrafts' | 'listInstallations' | 'saveDraft'>;
603
606
  export declare function addEnvironmentPackage(workspace: PackageWorkspace, input: AddEnvironmentPackageInput): Promise<EnvironmentDraft>;
604
607
  export declare function removeEnvironmentPackage(workspace: PackageWorkspace, input: RemoveEnvironmentPackageInput): Promise<EnvironmentDraft>;
608
+ /** Materialize the shipped preset with the host's own ID and bundled base project. */
609
+ export declare function prepareBuiltin120Environment(workspace: ContentWorkspace, projectDirectory: string, rules: unknown, validate: StaticPreparer): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  import { sha256Hex, skillParameterCatalogSchema, readElementCatalog, } from '@arcadia-eternity/const';
2
2
  import { randomUUID } from 'node:crypto';
3
+ import { isDeepStrictEqual } from 'node:util';
3
4
  import { lstat, mkdir, readFile, readdir, realpath, rename, rm, writeFile } from 'node:fs/promises';
4
5
  import { join, resolve } from 'node:path';
5
6
  import writeFileAtomic from 'write-file-atomic';
@@ -46,6 +47,7 @@ function exportRevision(draft, content, dependencies) {
46
47
  return sha256Hex(JSON.stringify([draft, content, dependencies]));
47
48
  }
48
49
  const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
50
+ const builtin120IdPattern = new RegExp('^builtin-120-' + uuid.source.slice(1));
49
51
  const envId = /^[a-z0-9][a-z0-9_-]{0,79}$/;
50
52
  const json = (value) => JSON.stringify(value, null, 2) + '\n';
51
53
  const checkId = (id, pattern = uuid) => {
@@ -115,6 +117,7 @@ class ContentWorkspaceImplementation {
115
117
  root;
116
118
  bootId = randomUUID();
117
119
  workspaceId;
120
+ builtin120EnvironmentId;
118
121
  #queue = Promise.resolve();
119
122
  #closed = false;
120
123
  #controller = new AbortController();
@@ -157,8 +160,13 @@ class ContentWorkspaceImplementation {
157
160
  }
158
161
  else {
159
162
  workspace.workspaceId = randomUUID();
160
- await writeFileAtomic(file, json({ format: 'arcadia.content-workspace/2', workspaceId: workspace.workspaceId }));
161
163
  }
164
+ if (metadata?.builtin120EnvironmentId !== undefined)
165
+ workspace.builtin120EnvironmentId = checkId(metadata.builtin120EnvironmentId, builtin120IdPattern);
166
+ else if (options.includeBuiltin120)
167
+ workspace.builtin120EnvironmentId = 'builtin-120-' + randomUUID();
168
+ if (!metadata || workspace.builtin120EnvironmentId !== metadata.builtin120EnvironmentId)
169
+ await workspace.#saveMetadata();
162
170
  // Recover an interrupted directory replacement before exposing projects.
163
171
  for (const name of await readdir(join(root, 'staging'))) {
164
172
  if (!name.startsWith('replaced-') || !envId.test(name.slice(9)))
@@ -182,6 +190,13 @@ class ContentWorkspaceImplementation {
182
190
  throw error;
183
191
  }
184
192
  }
193
+ async #saveMetadata() {
194
+ await writeFileAtomic(join(this.root, 'workspace.json'), json({
195
+ format: 'arcadia.content-workspace/2',
196
+ workspaceId: this.workspaceId,
197
+ builtin120EnvironmentId: this.builtin120EnvironmentId,
198
+ }));
199
+ }
185
200
  async #assertOwner() {
186
201
  if (this.#closed)
187
202
  throw contentError('WORKSPACE_CLOSED');
@@ -617,7 +632,13 @@ class ContentWorkspaceImplementation {
617
632
  const files = await materialFiles(this.#directory(draft.document.id), this.#options);
618
633
  installations.push({ version, files: files.map(({ path, bytes }) => ({ path, data: bytes.toString('base64') })) });
619
634
  }
620
- return { format: 'arcadia.workspace-snapshot/2', workspaceId: this.workspaceId, drafts, installations };
635
+ return {
636
+ format: 'arcadia.workspace-snapshot/2',
637
+ workspaceId: this.workspaceId,
638
+ builtin120EnvironmentId: this.builtin120EnvironmentId,
639
+ drafts,
640
+ installations,
641
+ };
621
642
  }
622
643
  exportSnapshot() {
623
644
  return this.#exclusive(() => this.#snapshot());
@@ -649,6 +670,9 @@ class ContentWorkspaceImplementation {
649
670
  !Array.isArray(snapshot.drafts) ||
650
671
  !Array.isArray(snapshot.installations))
651
672
  throw contentError('WORKSPACE_SNAPSHOT_INVALID');
673
+ const builtin120EnvironmentId = snapshot.builtin120EnvironmentId === undefined
674
+ ? this.builtin120EnvironmentId
675
+ : checkId(snapshot.builtin120EnvironmentId, builtin120IdPattern);
652
676
  if ((await this.#listDrafts()).length)
653
677
  throw contentError('WORKSPACE_NOT_EMPTY');
654
678
  const drafts = new Map(snapshot.drafts.map(draft => {
@@ -706,7 +730,8 @@ class ContentWorkspaceImplementation {
706
730
  throw contentError('WORKSPACE_SNAPSHOT_INVALID');
707
731
  }
708
732
  this.workspaceId = mode === 'restore' ? checkId(snapshot.workspaceId, uuid) : this.workspaceId;
709
- await writeFileAtomic(join(this.root, 'workspace.json'), json({ format: 'arcadia.content-workspace/2', workspaceId: this.workspaceId }));
733
+ this.builtin120EnvironmentId = builtin120EnvironmentId;
734
+ await this.#saveMetadata();
710
735
  return { workspaceId: this.workspaceId, installationIds: Object.fromEntries([...ids].map(id => [id, id])) };
711
736
  }, true);
712
737
  }
@@ -951,3 +976,30 @@ async function changeEnvironmentPackage(workspace, input) {
951
976
  }
952
977
  return workspace.saveDraft({ document: normalizeEnvironmentDocument(document), expectedRevision });
953
978
  }
979
+ /** Materialize the shipped preset with the host's own ID and bundled base project. */
980
+ export async function prepareBuiltin120Environment(workspace, projectDirectory, rules, validate) {
981
+ const id = workspace.builtin120EnvironmentId;
982
+ if (!id)
983
+ throw contentError('BUILTIN_ENVIRONMENT_ID_MISSING');
984
+ const base = '@arcadia-eternity/data-pack-base';
985
+ const { version } = await readJson(join(projectDirectory, 'node_modules', base, 'package.json'));
986
+ const document = normalizeEnvironmentDocument({
987
+ schemaVersion: 2,
988
+ id,
989
+ name: '120 资质 · 神魔化与二代',
990
+ packages: { [base]: version },
991
+ sources: [],
992
+ rules,
993
+ requires: {},
994
+ });
995
+ const current = await workspace.getDraft(id).catch(error => {
996
+ if (errorCode(error) !== 'ENOENT')
997
+ throw error;
998
+ });
999
+ if (current && isDeepStrictEqual(current.document, document)) {
1000
+ const [installed] = await workspace.listInstallations(id);
1001
+ if (installed?.status === 'ready' && installed.draftRevision === current.revision)
1002
+ return;
1003
+ }
1004
+ await workspace.prepareEnvironment({ environmentId: id, document, expectedRevision: current?.revision ?? null, projectDirectory }, validate);
1005
+ }
@@ -21,7 +21,7 @@
21
21
  "devDependencies": {
22
22
  "@types/node": "26.6.6",
23
23
  "typescript": "6.0.3",
24
- "@arcadia-eternity/content-sdk": "4.7.1",
24
+ "@arcadia-eternity/content-sdk": "4.8.0",
25
25
  "fflate": "0.8.3"
26
26
  },
27
27
  "arcadia": {
@@ -38,6 +38,6 @@
38
38
  "license": "MIT",
39
39
  "engines": {
40
40
  "node": ">=24 <25",
41
- "arcadia": "^4.7.1"
41
+ "arcadia": "^4.8.0"
42
42
  }
43
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcadia-eternity/content-sdk",
3
- "version": "4.7.1",
3
+ "version": "4.8.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -63,10 +63,10 @@
63
63
  "zod": "4.6.7",
64
64
  "fflate": "0.8.3",
65
65
  "simple-git": "4.1.0",
66
- "@arcadia-eternity/battle": "4.7.1",
67
- "@arcadia-eternity/const": "4.7.1",
68
- "@arcadia-eternity/pack-loader": "4.7.1",
69
- "@arcadia-eternity/schema": "4.7.1"
66
+ "@arcadia-eternity/battle": "4.8.0",
67
+ "@arcadia-eternity/const": "4.8.0",
68
+ "@arcadia-eternity/pack-loader": "4.8.0",
69
+ "@arcadia-eternity/schema": "4.8.0"
70
70
  },
71
71
  "repository": {
72
72
  "type": "git",