@arcadia-eternity/content-sdk 4.11.1 → 4.12.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/README.md +1 -1
- package/dist/content-workspace.d.ts +139 -1
- package/dist/content-workspace.js +20 -4
- package/dist/managed-projects.d.ts +5 -0
- package/dist/managed-projects.js +41 -3
- package/dist/pack-project.js +3 -1
- package/dist/package-updates.d.ts +18 -0
- package/dist/package-updates.js +185 -0
- package/dist/prepared-document.d.ts +1 -1
- package/dist/prepared-document.js +32 -5
- package/dist/template/.github/scripts/release-payload.mjs +7 -0
- package/dist/template/package.json +2 -2
- package/package.json +5 -5
- package/release-payload.mjs +7 -0
package/README.md
CHANGED
|
@@ -98,4 +98,4 @@ Workspace files own persistent environment projects and their current installati
|
|
|
98
98
|
|
|
99
99
|
`pnpm --filter @arcadia-eternity/content-sdk watch` builds once, then rebuilds when `src`, `template`, or either bundled skill directory under `docs/guides` changes. Rebuilds are serialized, include deletions, and recover after a failed build. The root `pnpm watch` includes this watcher. `pnpm --filter @arcadia-eternity/content-sdk clear` removes `dist`; root `pnpm clear` includes it as well. The package `typecheck` validates the TypeScript implementation and generated declarations; Node tests exercise the source modules directly.
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
At startup, `synchronizeShippedEnvironments` refreshes the official presets and compares their compiled base materials when the version is unchanged. User environments and explicit startup npm projects keep their locks. Preparing a rule edit reuses the installed base when it satisfies the request. An unavailable exact pin fails preparation. `ManagedProjects.synchronizeProject` and `synchronizeBundledBase` remain explicit migration APIs.
|
|
@@ -664,6 +664,144 @@ export type RemoveEnvironmentPackageInput = {
|
|
|
664
664
|
type PackageWorkspace = Pick<ContentWorkspace, 'listDrafts' | 'listInstallations' | 'saveDraft'>;
|
|
665
665
|
export declare function addEnvironmentPackage(workspace: PackageWorkspace, input: AddEnvironmentPackageInput): Promise<EnvironmentDraft>;
|
|
666
666
|
export declare function removeEnvironmentPackage(workspace: PackageWorkspace, input: RemoveEnvironmentPackageInput): Promise<EnvironmentDraft>;
|
|
667
|
+
/** Resolve presets from the same selected base installation as the battle materials. */
|
|
668
|
+
export declare function readOfficialEnvironments(root: string, legacyCatalog: string | URL): Promise<{
|
|
669
|
+
defaultEnvironment: string;
|
|
670
|
+
environments: {
|
|
671
|
+
id: string;
|
|
672
|
+
name: string;
|
|
673
|
+
packages: Record<string, string>;
|
|
674
|
+
sources: string[];
|
|
675
|
+
schemaVersion: 2;
|
|
676
|
+
rules: {
|
|
677
|
+
schemaVersion: 1 | 2;
|
|
678
|
+
mechanics?: {
|
|
679
|
+
skillSlots?: {
|
|
680
|
+
normalMax: number;
|
|
681
|
+
climaxMax: number;
|
|
682
|
+
climaxMin?: number | undefined;
|
|
683
|
+
} | undefined;
|
|
684
|
+
individualValueDefault?: number | undefined;
|
|
685
|
+
individualValues?: {
|
|
686
|
+
max: number;
|
|
687
|
+
} | undefined;
|
|
688
|
+
allowFaintSwitch?: boolean | undefined;
|
|
689
|
+
timer?: {
|
|
690
|
+
enabled: boolean;
|
|
691
|
+
turnTimeLimit?: number | undefined;
|
|
692
|
+
totalTimeLimit?: number | undefined;
|
|
693
|
+
animationPauseEnabled?: boolean | undefined;
|
|
694
|
+
maxAnimationDuration?: number | undefined;
|
|
695
|
+
} | undefined;
|
|
696
|
+
teamSelection?: {
|
|
697
|
+
enabled: boolean;
|
|
698
|
+
mode?: "FULL_TEAM" | "TEAM_SELECTION" | "VIEW_ONLY" | undefined;
|
|
699
|
+
minTeamSize?: number | undefined;
|
|
700
|
+
maxTeamSize?: number | undefined;
|
|
701
|
+
allowStarterSelection?: boolean | undefined;
|
|
702
|
+
showOpponentTeam?: boolean | undefined;
|
|
703
|
+
teamInfoVisibility?: "BASIC" | "FULL" | "HIDDEN" | undefined;
|
|
704
|
+
timeLimit?: number | undefined;
|
|
705
|
+
} | undefined;
|
|
706
|
+
inheritance?: {
|
|
707
|
+
eligible: "all" | "off" | "species" | string[];
|
|
708
|
+
pool?: {
|
|
709
|
+
mode: "append" | "fallback" | "replace";
|
|
710
|
+
skills: string[];
|
|
711
|
+
} | undefined;
|
|
712
|
+
} | undefined;
|
|
713
|
+
enhancement?: {
|
|
714
|
+
mode: "active" | "forbidden" | "suppressed";
|
|
715
|
+
minLevel?: number | undefined;
|
|
716
|
+
defaultBranches?: string[] | undefined;
|
|
717
|
+
stages?: string[] | undefined;
|
|
718
|
+
species?: string[] | undefined;
|
|
719
|
+
} | undefined;
|
|
720
|
+
secondGenerationNatures?: "all" | "off" | "species" | string[] | undefined;
|
|
721
|
+
} | undefined;
|
|
722
|
+
skillParameters?: {
|
|
723
|
+
profile?: string | undefined;
|
|
724
|
+
groups?: Record<string, number> | undefined;
|
|
725
|
+
overrides?: {
|
|
726
|
+
skill: string;
|
|
727
|
+
useId: string;
|
|
728
|
+
parameter: string;
|
|
729
|
+
value: number;
|
|
730
|
+
}[] | undefined;
|
|
731
|
+
} | undefined;
|
|
732
|
+
matchups?: {
|
|
733
|
+
table?: string | undefined;
|
|
734
|
+
adjustments?: {
|
|
735
|
+
attack: string;
|
|
736
|
+
defense: string;
|
|
737
|
+
multiplier: number;
|
|
738
|
+
}[] | undefined;
|
|
739
|
+
} | undefined;
|
|
740
|
+
learnsetAdjustments?: {
|
|
741
|
+
species: string;
|
|
742
|
+
source: "inherited" | "normal";
|
|
743
|
+
skill: string;
|
|
744
|
+
action: "add" | "remove";
|
|
745
|
+
level?: number | undefined;
|
|
746
|
+
}[] | undefined;
|
|
747
|
+
tier?: "standard" | undefined;
|
|
748
|
+
allow?: {
|
|
749
|
+
species?: string[] | undefined;
|
|
750
|
+
skills?: string[] | undefined;
|
|
751
|
+
marks?: string[] | undefined;
|
|
752
|
+
} | undefined;
|
|
753
|
+
deny?: {
|
|
754
|
+
species?: string[] | undefined;
|
|
755
|
+
skills?: string[] | undefined;
|
|
756
|
+
marks?: string[] | undefined;
|
|
757
|
+
} | undefined;
|
|
758
|
+
team?: {
|
|
759
|
+
minSize?: number | undefined;
|
|
760
|
+
maxSize?: number | undefined;
|
|
761
|
+
uniqueSpecies?: boolean | undefined;
|
|
762
|
+
} | undefined;
|
|
763
|
+
constraints?: ({
|
|
764
|
+
id: string;
|
|
765
|
+
allOf: {
|
|
766
|
+
kind: "mark" | "skill" | "species";
|
|
767
|
+
ids: string[];
|
|
768
|
+
fromCollections?: string[] | undefined;
|
|
769
|
+
}[];
|
|
770
|
+
kind: "ban";
|
|
771
|
+
scope: "pet" | "team";
|
|
772
|
+
exceptWhen?: {
|
|
773
|
+
kind: "mark" | "skill" | "species";
|
|
774
|
+
ids: string[];
|
|
775
|
+
fromCollections?: string[] | undefined;
|
|
776
|
+
}[] | undefined;
|
|
777
|
+
exceptAny?: {
|
|
778
|
+
kind: "mark" | "skill" | "species";
|
|
779
|
+
ids: string[];
|
|
780
|
+
fromCollections?: string[] | undefined;
|
|
781
|
+
}[][] | undefined;
|
|
782
|
+
} | {
|
|
783
|
+
id: string;
|
|
784
|
+
allOf: {
|
|
785
|
+
kind: "mark" | "skill" | "species";
|
|
786
|
+
ids: string[];
|
|
787
|
+
fromCollections?: string[] | undefined;
|
|
788
|
+
}[];
|
|
789
|
+
kind: "memberLimit";
|
|
790
|
+
max: number;
|
|
791
|
+
})[] | undefined;
|
|
792
|
+
collections?: {
|
|
793
|
+
id: string;
|
|
794
|
+
kind: "mark" | "skill" | "species";
|
|
795
|
+
ids: string[];
|
|
796
|
+
}[] | undefined;
|
|
797
|
+
};
|
|
798
|
+
requires: {
|
|
799
|
+
engine?: string | undefined;
|
|
800
|
+
sdk?: string | undefined;
|
|
801
|
+
capabilities?: string[] | undefined;
|
|
802
|
+
};
|
|
803
|
+
}[];
|
|
804
|
+
}>;
|
|
667
805
|
/** The host supplies this catalog from the application distribution. */
|
|
668
806
|
export declare function readShippedEnvironments(file: string | URL, bundledVersions: Record<string, string>): Promise<{
|
|
669
807
|
defaultEnvironment: string;
|
|
@@ -802,4 +940,4 @@ export declare function readShippedEnvironments(file: string | URL, bundledVersi
|
|
|
802
940
|
};
|
|
803
941
|
}[];
|
|
804
942
|
}>;
|
|
805
|
-
export declare function synchronizeShippedEnvironments(workspace: OwnedContentWorkspace, catalog: Awaited<ReturnType<typeof readShippedEnvironments>>, adopted: Record<string, string>, prepare: (document: EnvironmentDocument, expectedRevision: string | null) => Promise<unknown
|
|
943
|
+
export declare function synchronizeShippedEnvironments(workspace: OwnedContentWorkspace, catalog: Awaited<ReturnType<typeof readShippedEnvironments>>, adopted: Record<string, string>, prepare: (document: EnvironmentDocument, expectedRevision: string | null) => Promise<unknown>, officialBaseRoot?: string): Promise<string>;
|
|
@@ -5,7 +5,7 @@ import { lstat, mkdir, readFile, readdir, realpath, rename, rm, writeFile } from
|
|
|
5
5
|
import { join, resolve } from 'node:path';
|
|
6
6
|
import writeFileAtomic from 'write-file-atomic';
|
|
7
7
|
import semver from 'semver';
|
|
8
|
-
import { inspectNpmProject } from '@arcadia-eternity/pack-loader/node';
|
|
8
|
+
import { catalogMaterialDigest, inspectNpmProject } from '@arcadia-eternity/pack-loader/node';
|
|
9
9
|
import { normalizeEnvironmentDocument, EnvironmentDocumentV2Schema, EnvironmentRulesSchema, EnvironmentRuleDeclarationSchema, } from './debug-environments.js';
|
|
10
10
|
import { z } from 'zod';
|
|
11
11
|
import { withSourceLock } from './source-lock.js';
|
|
@@ -1085,6 +1085,16 @@ async function changeEnvironmentPackage(workspace, input) {
|
|
|
1085
1085
|
}
|
|
1086
1086
|
return workspace.saveDraft({ document: normalizeEnvironmentDocument(document), expectedRevision });
|
|
1087
1087
|
}
|
|
1088
|
+
/** Resolve presets from the same selected base installation as the battle materials. */
|
|
1089
|
+
export async function readOfficialEnvironments(root, legacyCatalog) {
|
|
1090
|
+
const manifest = await readJson(join(root, 'package.json'));
|
|
1091
|
+
if (manifest.name !== hostBaseName || typeof manifest.version !== 'string' || !semver.valid(manifest.version))
|
|
1092
|
+
throw contentError('BUNDLED_PACKAGE_INVALID');
|
|
1093
|
+
const file = isRecord(manifest.arcadia) ? manifest.arcadia.environments : undefined;
|
|
1094
|
+
if (file !== undefined && file !== 'dist/environment/presets.json')
|
|
1095
|
+
throw contentError('SHIPPED_ENVIRONMENT_CATALOG_INVALID');
|
|
1096
|
+
return readShippedEnvironments(file ? join(root, file) : legacyCatalog, { [hostBaseName]: manifest.version });
|
|
1097
|
+
}
|
|
1088
1098
|
/** The host supplies this catalog from the application distribution. */
|
|
1089
1099
|
export async function readShippedEnvironments(file, bundledVersions) {
|
|
1090
1100
|
const schema = z
|
|
@@ -1106,16 +1116,22 @@ export async function readShippedEnvironments(file, bundledVersions) {
|
|
|
1106
1116
|
}
|
|
1107
1117
|
return catalog;
|
|
1108
1118
|
}
|
|
1109
|
-
export async function synchronizeShippedEnvironments(workspace, catalog, adopted, prepare) {
|
|
1119
|
+
export async function synchronizeShippedEnvironments(workspace, catalog, adopted, prepare, officialBaseRoot) {
|
|
1110
1120
|
await workspace.registerBuiltinEnvironments(catalog.environments.map(doc => doc.id), adopted);
|
|
1121
|
+
const selectedDigest = officialBaseRoot && (await catalogMaterialDigest(officialBaseRoot));
|
|
1111
1122
|
const drafts = await workspace.listDrafts();
|
|
1112
1123
|
for (const document of catalog.environments) {
|
|
1113
1124
|
const id = document.id;
|
|
1114
1125
|
const current = drafts.find(item => item.document.id === id);
|
|
1115
1126
|
if (current && isDeepStrictEqual(current.document, document)) {
|
|
1116
1127
|
const [installed] = await workspace.listInstallations(id);
|
|
1117
|
-
if (installed?.status === 'ready' && installed.draftRevision === current.revision)
|
|
1118
|
-
|
|
1128
|
+
if (installed?.status === 'ready' && installed.draftRevision === current.revision) {
|
|
1129
|
+
if (!selectedDigest || !Object.hasOwn(document.packages, hostBaseName))
|
|
1130
|
+
continue;
|
|
1131
|
+
const digest = await catalogMaterialDigest(join(installed.directory, 'node_modules', hostBaseName)).catch(() => null);
|
|
1132
|
+
if (digest === selectedDigest)
|
|
1133
|
+
continue;
|
|
1134
|
+
}
|
|
1119
1135
|
}
|
|
1120
1136
|
await prepare(document, current?.revision ?? null);
|
|
1121
1137
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { type PackageUpdate } from './package-updates.js';
|
|
2
|
+
export { officialPackage, findPackageUpdate, selectPackageUpdate, selectServerBase, installServerBaseUpdate, } from './package-updates.js';
|
|
1
3
|
import type { ContentWorkspace, EnvironmentInstallation, PrepareEnvironmentInput, StaticPreparer } from './content-workspace.js';
|
|
2
4
|
import type { ManagedSource } from './managed-sources.js';
|
|
3
5
|
import { type UnknownRecord } from './types.js';
|
|
4
6
|
export interface ManagedProjectsOptions {
|
|
5
7
|
bundledPackageRoot?: string;
|
|
8
|
+
resolveBaseVersion?: (version: string) => Promise<string | undefined>;
|
|
6
9
|
registry?: string;
|
|
7
10
|
offline?: boolean;
|
|
8
11
|
/** Host permission to acquire metadata/materials; never grants authority to execute them. */
|
|
@@ -31,6 +34,7 @@ export declare class ManagedProjects {
|
|
|
31
34
|
onProgress?: PrepareEnvironmentInput['onProgress'];
|
|
32
35
|
environmentId: string;
|
|
33
36
|
seedDirectory?: string;
|
|
37
|
+
useSelectedBase?: boolean;
|
|
34
38
|
expectedRevision: string | null;
|
|
35
39
|
document?: PrepareEnvironmentInput['document'];
|
|
36
40
|
signal?: AbortSignal;
|
|
@@ -47,3 +51,4 @@ export declare class ManagedProjects {
|
|
|
47
51
|
}, consume: (directory: string, signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
48
52
|
close(): Promise<void>;
|
|
49
53
|
}
|
|
54
|
+
export declare function withOfficialUpdateArchive<T>(candidate: PackageUpdate, npmCli: string | undefined, signal: AbortSignal, use: (file: string) => Promise<T>): Promise<T>;
|
package/dist/managed-projects.js
CHANGED
|
@@ -2,8 +2,10 @@ import { sha256Hex } from '@arcadia-eternity/const';
|
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
3
|
import { mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
|
+
import { withOfficialUpdateDirectory } from './package-updates.js';
|
|
6
|
+
export { officialPackage, findPackageUpdate, selectPackageUpdate, selectServerBase, installServerBaseUpdate, } from './package-updates.js';
|
|
5
7
|
import { isDeepStrictEqual, promisify } from 'node:util';
|
|
6
|
-
import { valid, validRange } from 'semver';
|
|
8
|
+
import { satisfies, valid, validRange } from 'semver';
|
|
7
9
|
import { inspectNpmProject, resolveNpmInvocation, withShippedEnvironmentProject, withShippedCatalogArchive, } from '@arcadia-eternity/pack-loader/node';
|
|
8
10
|
import { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
9
11
|
import { acquireSource } from './managed-sources.js';
|
|
@@ -362,11 +364,42 @@ export class ManagedProjects {
|
|
|
362
364
|
const includesBase = Object.hasOwn(dependencies, baseName) || document.sources.includes(baseName);
|
|
363
365
|
if (Object.hasOwn(dependencies, baseName) && document.sources.includes(baseName))
|
|
364
366
|
throw contentError('INSTALL_DUPLICATE_PACKAGE');
|
|
365
|
-
|
|
367
|
+
let baseRoot = this.#options.bundledPackageRoot;
|
|
366
368
|
if (includesBase && !baseRoot)
|
|
367
369
|
throw contentError('BUNDLED_PACKAGE_UNAVAILABLE');
|
|
368
370
|
if (includesBase) {
|
|
369
|
-
|
|
371
|
+
let range = dependencies[baseName];
|
|
372
|
+
if (!input.useSelectedBase && input.projectDirectory && range) {
|
|
373
|
+
const seed = join(input.projectDirectory, 'node_modules', baseName);
|
|
374
|
+
const resolved = await realpath(seed).catch(error => {
|
|
375
|
+
if (errorCode(error) !== 'ENOENT')
|
|
376
|
+
throw error;
|
|
377
|
+
});
|
|
378
|
+
if (resolved) {
|
|
379
|
+
if (resolved !== join(await realpath(input.projectDirectory), 'node_modules', baseName))
|
|
380
|
+
throw contentError('MATERIAL_PATH_ESCAPE');
|
|
381
|
+
const pinned = JSON.parse(await readFile(join(seed, 'package.json'), 'utf8'));
|
|
382
|
+
if (range.startsWith('file:')) {
|
|
383
|
+
const lock = JSON.parse(await readFile(join(input.projectDirectory, 'package-lock.json'), 'utf8'));
|
|
384
|
+
const member = lock.packages?.['node_modules/' + baseName];
|
|
385
|
+
if (member?.resolved !== range || member.version !== pinned.version)
|
|
386
|
+
throw contentError('BASE_PACK_VERSION_UNAVAILABLE');
|
|
387
|
+
range = member.version;
|
|
388
|
+
}
|
|
389
|
+
if (pinned.name === baseName && satisfies(pinned.version, range))
|
|
390
|
+
baseRoot = resolved;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
let baseManifest = JSON.parse(await readFile(join(baseRoot, 'package.json'), 'utf8'));
|
|
394
|
+
if (range && !satisfies(baseManifest.version, range)) {
|
|
395
|
+
const cached = valid(range) && (await this.#options.resolveBaseVersion?.(range));
|
|
396
|
+
if (!cached)
|
|
397
|
+
throw contentError('BASE_PACK_VERSION_UNAVAILABLE', '本机缺少环境所需的基础包 ' + range);
|
|
398
|
+
baseRoot = cached;
|
|
399
|
+
baseManifest = JSON.parse(await readFile(join(cached, 'package.json'), 'utf8'));
|
|
400
|
+
if (!satisfies(baseManifest.version, range))
|
|
401
|
+
throw contentError('BASE_PACK_VERSION_UNAVAILABLE');
|
|
402
|
+
}
|
|
370
403
|
if (baseManifest.name !== baseName)
|
|
371
404
|
throw contentError('BUNDLED_PACKAGE_INVALID');
|
|
372
405
|
dependencies[baseName] = baseManifest.version;
|
|
@@ -568,3 +601,8 @@ export class ManagedProjects {
|
|
|
568
601
|
await Promise.allSettled([...this.#pending]);
|
|
569
602
|
}
|
|
570
603
|
}
|
|
604
|
+
// Discard the npm development/runtime dependencies before passing the official catalog
|
|
605
|
+
// to the same offline installer used for the application's bundled copy.
|
|
606
|
+
export async function withOfficialUpdateArchive(candidate, npmCli, signal, use) {
|
|
607
|
+
return withOfficialUpdateDirectory(candidate, signal, directory => withShippedCatalogArchive(directory, npmCli, use));
|
|
608
|
+
}
|
package/dist/pack-project.js
CHANGED
|
@@ -4,7 +4,7 @@ import { copyFile, lstat, mkdir, mkdtemp, readFile, realpath, rename, rm, writeF
|
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
5
5
|
import { promisify } from 'node:util';
|
|
6
6
|
import { compileEffectModule, emptyNpmContentHost, parseNpmPackOutput, prepareNpmProject, resolveNpmInvocation, } from '@arcadia-eternity/pack-loader/node';
|
|
7
|
-
import { releasePayload, normalizeReleaseArchive } from '../release-payload.mjs';
|
|
7
|
+
import { releasePayload, normalizeReleaseArchive, requireClientRange } from '../release-payload.mjs';
|
|
8
8
|
import { ManagedProjects } from './managed-projects.js';
|
|
9
9
|
import { errorCode } from './types.js';
|
|
10
10
|
const exec = promisify(execFile);
|
|
@@ -89,6 +89,8 @@ export async function packBuiltProject(directory = process.cwd(), { cache, relea
|
|
|
89
89
|
const root = await realpath(resolve(directory));
|
|
90
90
|
const manifestText = await readFile(join(root, 'package.json'), 'utf8');
|
|
91
91
|
const manifest = JSON.parse(manifestText);
|
|
92
|
+
if (!release && manifest.arcadia)
|
|
93
|
+
requireClientRange(manifest);
|
|
92
94
|
const preview = parseNpmPackOutput(String((await npm(root, ['pack', '--dry-run', '--ignore-scripts', '--json'], cache)).stdout))[0];
|
|
93
95
|
if (!preview || preview.files.length > 50000)
|
|
94
96
|
fail('npm returned an invalid package file list');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const officialPackage = "@arcadia-eternity/data-pack-base";
|
|
2
|
+
export interface PackageUpdate {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
range: string;
|
|
6
|
+
url: string;
|
|
7
|
+
integrity: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function selectPackageUpdate(metadata: unknown, name: string, current: string, client: string): PackageUpdate | null;
|
|
10
|
+
export declare function findPackageUpdate(name: string, current: string, client: string): Promise<PackageUpdate | null>;
|
|
11
|
+
export declare function withOfficialUpdateDirectory<T>(candidate: PackageUpdate, signal: AbortSignal, use: (directory: string) => Promise<T>): Promise<T>;
|
|
12
|
+
/** Only completed version directories are eligible. Offline startup never contacts the registry. */
|
|
13
|
+
export declare function selectServerBase(store: string, shipped: string, host: string, pin?: string, validate?: (directory: string) => Promise<void>): Promise<{
|
|
14
|
+
directory: string;
|
|
15
|
+
version: string;
|
|
16
|
+
cached: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function installServerBaseUpdate(store: string, candidate: PackageUpdate, host: string, validate: (directory: string) => Promise<void>): Promise<void>;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { catalogMaterialDigest } from '@arcadia-eternity/pack-loader/node';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { acquireSource } from './managed-sources.js';
|
|
7
|
+
import { errorCode, isRecord } from './types.js';
|
|
8
|
+
export const officialPackage = '@arcadia-eternity/data-pack-base';
|
|
9
|
+
export function selectPackageUpdate(metadata, name, current, client) {
|
|
10
|
+
if (!isRecord(metadata) ||
|
|
11
|
+
metadata.name !== name ||
|
|
12
|
+
!isRecord(metadata.versions) ||
|
|
13
|
+
!isRecord(metadata['dist-tags']) ||
|
|
14
|
+
typeof metadata['dist-tags'].latest !== 'string' ||
|
|
15
|
+
!semver.valid(metadata['dist-tags'].latest))
|
|
16
|
+
throw new Error('npm 返回了无效的包版本清单');
|
|
17
|
+
const latest = metadata['dist-tags'].latest;
|
|
18
|
+
const candidates = Object.keys(metadata.versions)
|
|
19
|
+
.filter(version => semver.valid(version) &&
|
|
20
|
+
!semver.prerelease(version) &&
|
|
21
|
+
semver.gt(version, current) &&
|
|
22
|
+
semver.lte(version, latest))
|
|
23
|
+
.sort(semver.rcompare);
|
|
24
|
+
for (const version of candidates) {
|
|
25
|
+
const pkg = metadata.versions[version];
|
|
26
|
+
if (!isRecord(pkg))
|
|
27
|
+
throw new Error('npm 返回了无效的包版本清单');
|
|
28
|
+
const range = isRecord(pkg.engines) && pkg.engines.arcadia;
|
|
29
|
+
if (pkg.deprecated ||
|
|
30
|
+
typeof range !== 'string' ||
|
|
31
|
+
!range.trim() ||
|
|
32
|
+
range.length > 256 ||
|
|
33
|
+
!semver.satisfies(client, range))
|
|
34
|
+
continue;
|
|
35
|
+
const expected = `https://registry.npmjs.org/${name}/-/${name.split('/').at(-1)}-${version}.tgz`;
|
|
36
|
+
if (pkg.version !== version ||
|
|
37
|
+
!isRecord(pkg.dist) ||
|
|
38
|
+
pkg.dist.tarball !== expected ||
|
|
39
|
+
typeof pkg.dist.integrity !== 'string' ||
|
|
40
|
+
!/^sha512-[A-Za-z0-9+/]{86}==$/.test(pkg.dist.integrity))
|
|
41
|
+
throw new Error('npm 返回了无效的发行归档');
|
|
42
|
+
return { name, version, range, url: expected, integrity: pkg.dist.integrity };
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
export async function findPackageUpdate(name, current, client) {
|
|
47
|
+
const response = await fetch('https://registry.npmjs.org/' + encodeURIComponent(name), {
|
|
48
|
+
headers: { Accept: 'application/vnd.npm.install-v1+json' },
|
|
49
|
+
redirect: 'error',
|
|
50
|
+
signal: AbortSignal.timeout(20000),
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok)
|
|
53
|
+
throw new Error('无法检查 npm 包更新(HTTP ' + response.status + ')');
|
|
54
|
+
// The full version history is needed to find a compatible release below latest.
|
|
55
|
+
const limit = 8 * 1024 * 1024;
|
|
56
|
+
if (!response.body || Number(response.headers.get('content-length')) > limit) {
|
|
57
|
+
await response.body?.cancel();
|
|
58
|
+
throw new Error('npm 版本清单过大或为空');
|
|
59
|
+
}
|
|
60
|
+
const chunks = [];
|
|
61
|
+
let size = 0;
|
|
62
|
+
for await (const chunk of response.body) {
|
|
63
|
+
size += chunk.length;
|
|
64
|
+
if (size > limit)
|
|
65
|
+
throw new Error('npm 版本清单过大');
|
|
66
|
+
chunks.push(chunk);
|
|
67
|
+
}
|
|
68
|
+
return selectPackageUpdate(JSON.parse(Buffer.concat(chunks).toString('utf8')), name, current, client);
|
|
69
|
+
}
|
|
70
|
+
async function acquireOfficial(candidate, destination, signal) {
|
|
71
|
+
if (candidate.name !== officialPackage ||
|
|
72
|
+
!semver.valid(candidate.version) ||
|
|
73
|
+
typeof candidate.range !== 'string' ||
|
|
74
|
+
!candidate.range.trim() ||
|
|
75
|
+
candidate.range.length > 256 ||
|
|
76
|
+
!semver.validRange(candidate.range) ||
|
|
77
|
+
candidate.url !== `https://registry.npmjs.org/${officialPackage}/-/data-pack-base-${candidate.version}.tgz` ||
|
|
78
|
+
!/^sha512-[A-Za-z0-9+/]{86}==$/.test(candidate.integrity))
|
|
79
|
+
throw new Error('INVALID_OFFICIAL_PACKAGE');
|
|
80
|
+
const { directory } = await acquireSource({ kind: 'url', url: candidate.url, integrity: candidate.integrity }, { destination, signal });
|
|
81
|
+
const manifest = JSON.parse(await readFile(join(directory, 'package.json'), 'utf8'));
|
|
82
|
+
if (manifest.name !== officialPackage ||
|
|
83
|
+
manifest.version !== candidate.version ||
|
|
84
|
+
manifest.engines?.arcadia !== candidate.range ||
|
|
85
|
+
manifest.arcadia?.projectId !== 'base' ||
|
|
86
|
+
manifest.arcadia?.namespace !== 'base')
|
|
87
|
+
throw new Error('INVALID_OFFICIAL_PACKAGE');
|
|
88
|
+
return directory;
|
|
89
|
+
}
|
|
90
|
+
export async function withOfficialUpdateDirectory(candidate, signal, use) {
|
|
91
|
+
const stage = await mkdtemp(join(tmpdir(), 'arcadia-official-update-'));
|
|
92
|
+
try {
|
|
93
|
+
return await use(await acquireOfficial(candidate, join(stage, 'source'), signal));
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
await rm(stage, { recursive: true, force: true });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Only completed version directories are eligible. Offline startup never contacts the registry. */
|
|
100
|
+
export async function selectServerBase(store, shipped, host, pin, validate) {
|
|
101
|
+
const bundled = JSON.parse(await readFile(join(shipped, 'package.json'), 'utf8'));
|
|
102
|
+
const fallback = { directory: shipped, version: bundled.version, cached: false };
|
|
103
|
+
const bundledCompatible = bundled.engines?.arcadia === undefined || semver.satisfies(host, bundled.engines.arcadia);
|
|
104
|
+
if (pin === 'bundled') {
|
|
105
|
+
if (!bundledCompatible)
|
|
106
|
+
throw new Error('INCOMPATIBLE_OFFICIAL_PACKAGE');
|
|
107
|
+
await validate?.(shipped);
|
|
108
|
+
return fallback;
|
|
109
|
+
}
|
|
110
|
+
if (pin && semver.valid(pin) !== pin)
|
|
111
|
+
throw new Error('Invalid base pack version: ' + pin);
|
|
112
|
+
const entries = await readdir(store, { withFileTypes: true }).catch(error => {
|
|
113
|
+
if (errorCode(error) === 'ENOENT')
|
|
114
|
+
return [];
|
|
115
|
+
throw error;
|
|
116
|
+
});
|
|
117
|
+
const candidates = entries
|
|
118
|
+
.filter(entry => entry.isDirectory() && semver.valid(entry.name) === entry.name)
|
|
119
|
+
.map(entry => ({ directory: join(store, entry.name), version: entry.name, cached: true }));
|
|
120
|
+
if (bundledCompatible)
|
|
121
|
+
candidates.push(fallback);
|
|
122
|
+
// Inspect cached ties first to detect an ambiguous release while retaining the shipped reference.
|
|
123
|
+
candidates.sort((a, b) => semver.rcompare(a.version, b.version));
|
|
124
|
+
let lastError;
|
|
125
|
+
for (const candidate of candidates) {
|
|
126
|
+
const { directory, version, cached } = candidate;
|
|
127
|
+
if (pin && version !== pin)
|
|
128
|
+
continue;
|
|
129
|
+
try {
|
|
130
|
+
if (cached) {
|
|
131
|
+
const manifest = JSON.parse(await readFile(join(directory, 'package.json'), 'utf8'));
|
|
132
|
+
if (manifest.name !== officialPackage || manifest.version !== version)
|
|
133
|
+
throw new Error('INVALID_OFFICIAL_PACKAGE');
|
|
134
|
+
if (!manifest.engines?.arcadia?.trim() || !semver.satisfies(host, manifest.engines.arcadia))
|
|
135
|
+
continue;
|
|
136
|
+
const digest = await catalogMaterialDigest(directory);
|
|
137
|
+
const recorded = await readFile(join(directory, '.arcadia-material-digest'), 'utf8').catch(error => {
|
|
138
|
+
if (errorCode(error) !== 'ENOENT')
|
|
139
|
+
throw error;
|
|
140
|
+
});
|
|
141
|
+
if (recorded !== undefined && digest !== recorded)
|
|
142
|
+
throw new Error('OFFICIAL_MATERIAL_DIGEST_MISMATCH');
|
|
143
|
+
if (version === bundled.version && bundledCompatible) {
|
|
144
|
+
if (digest !== (await catalogMaterialDigest(shipped)))
|
|
145
|
+
console.warn('OFFICIAL_BASE_VERSION_CONFLICT', version, 'using bundled materials');
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
await validate?.(directory);
|
|
150
|
+
return candidate;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
lastError = error;
|
|
154
|
+
console.warn('Skipping unusable official base', version, directory, error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
throw new Error('No compatible installed base pack ' + (pin ? 'at version ' + pin : 'for Arcadia ' + host), {
|
|
158
|
+
cause: lastError,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
export async function installServerBaseUpdate(store, candidate, host, validate) {
|
|
162
|
+
if (!semver.satisfies(host, candidate.range))
|
|
163
|
+
throw new Error('INCOMPATIBLE_OFFICIAL_PACKAGE');
|
|
164
|
+
await mkdir(store, { recursive: true, mode: 0o700 });
|
|
165
|
+
const stage = await mkdtemp(join(store, '.install-'));
|
|
166
|
+
try {
|
|
167
|
+
const directory = await acquireOfficial(candidate, join(stage, 'source'), AbortSignal.timeout(120000));
|
|
168
|
+
await validate(directory);
|
|
169
|
+
const digest = await catalogMaterialDigest(directory);
|
|
170
|
+
await writeFile(join(directory, '.arcadia-material-digest'), digest);
|
|
171
|
+
try {
|
|
172
|
+
await rename(directory, join(store, candidate.version));
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
// Concurrent installers can only publish a complete, verified directory at this version.
|
|
176
|
+
if (!['EEXIST', 'ENOTEMPTY'].includes(errorCode(error) ?? ''))
|
|
177
|
+
throw error;
|
|
178
|
+
if ((await catalogMaterialDigest(join(store, candidate.version))) !== digest)
|
|
179
|
+
throw new Error('OFFICIAL_BASE_VERSION_CONFLICT: ' + candidate.version, { cause: error });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
await rm(stage, { recursive: true, force: true });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -270,7 +270,7 @@ export declare function preparedDocument(metadata: UnknownRecord, legacyManifest
|
|
|
270
270
|
capabilities?: string[] | undefined;
|
|
271
271
|
};
|
|
272
272
|
};
|
|
273
|
-
/**
|
|
273
|
+
/** Managed projects read their applied rules. Plain npm projects may install one rules recipe. */
|
|
274
274
|
export declare function readInstalledEnvironmentDocument(directory: string, contentRevision?: string): Promise<{
|
|
275
275
|
id: string;
|
|
276
276
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sha256Hex } from '@arcadia-eternity/const';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
2
|
+
import { readFile, realpath } from 'node:fs/promises';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
4
|
import { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
5
5
|
import { contentError, readJson } from './workspace-materials.js';
|
|
6
6
|
import { errorCode, isRecord } from './types.js';
|
|
@@ -31,17 +31,44 @@ export function preparedDocument(metadata, legacyManifest) {
|
|
|
31
31
|
throw contentError('ENVIRONMENT_PREPARATION_REQUIRED');
|
|
32
32
|
return draft.document;
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
34
|
+
/** Managed projects read their applied rules. Plain npm projects may install one rules recipe. */
|
|
35
35
|
export async function readInstalledEnvironmentDocument(directory, contentRevision) {
|
|
36
36
|
const manifest = await readFile(join(directory, 'package.json'), 'utf8');
|
|
37
|
+
const project = JSON.parse(manifest);
|
|
37
38
|
const receipt = await readJson(join(directory, '.arcadia-prepared.json')).catch(error => {
|
|
38
39
|
if (errorCode(error) !== 'ENOENT')
|
|
39
40
|
throw error;
|
|
40
|
-
if (
|
|
41
|
+
if (project.arcadiaEnvironment)
|
|
41
42
|
throw contentError('ENVIRONMENT_PREPARATION_REQUIRED');
|
|
42
43
|
return undefined;
|
|
43
44
|
});
|
|
44
45
|
if (receipt && contentRevision !== undefined && receipt.contentRevision !== contentRevision)
|
|
45
46
|
throw contentError('ENVIRONMENT_PREPARATION_REQUIRED');
|
|
46
|
-
|
|
47
|
+
if (receipt)
|
|
48
|
+
return preparedDocument(receipt, manifest);
|
|
49
|
+
// An ordinary npm project can select a rules recipe as a direct dependency.
|
|
50
|
+
const root = await realpath(directory);
|
|
51
|
+
let selected;
|
|
52
|
+
for (const name of Object.keys(project.dependencies ?? {})) {
|
|
53
|
+
if (!/^(?:@[a-z0-9._-]+\/)?[a-z0-9][a-z0-9._-]*$/.test(name))
|
|
54
|
+
continue;
|
|
55
|
+
const file = resolve(root, 'node_modules', name, 'package.json');
|
|
56
|
+
const installed = await realpath(file).catch(error => {
|
|
57
|
+
if (errorCode(error) !== 'ENOENT')
|
|
58
|
+
throw error;
|
|
59
|
+
});
|
|
60
|
+
if (!installed)
|
|
61
|
+
continue;
|
|
62
|
+
if (installed !== file)
|
|
63
|
+
throw contentError('MATERIAL_PATH_ESCAPE');
|
|
64
|
+
const pkg = await readJson(file);
|
|
65
|
+
if (!pkg.arcadiaEnvironment)
|
|
66
|
+
continue;
|
|
67
|
+
if (pkg.name !== name)
|
|
68
|
+
throw contentError('ENVIRONMENT_MANIFEST_INVALID');
|
|
69
|
+
if (selected)
|
|
70
|
+
throw contentError('ENVIRONMENT_PRESET_AMBIGUOUS', '项目依赖多个环境包,请显式选择环境声明。');
|
|
71
|
+
selected = parseManifestDraft(JSON.stringify(pkg)).document;
|
|
72
|
+
}
|
|
73
|
+
return selected;
|
|
47
74
|
}
|
|
@@ -8,10 +8,17 @@ const require = createRequire(import.meta.url)
|
|
|
8
8
|
const sdkRequire = createRequire(require.resolve('@arcadia-eternity/content-sdk'))
|
|
9
9
|
const { valid, validRange } = sdkRequire('semver')
|
|
10
10
|
|
|
11
|
+
export function requireClientRange(source) {
|
|
12
|
+
const range = source.engines?.arcadia
|
|
13
|
+
if (typeof range !== 'string' || !range.trim() || range.length > 256 || !validRange(range))
|
|
14
|
+
throw Error('发行内容包必须在 package.json 的 engines.arcadia 声明有效的客户端版本范围')
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
export function releasePayload(source, included, presentation) {
|
|
12
18
|
if (!source.arcadia?.projectId || !source.arcadia.namespace || !source.arcadia.content || !valid(source.version))
|
|
13
19
|
throw Error('发行包需要有效版本、projectId、namespace 和内容入口')
|
|
14
20
|
if (typeof source.license !== 'string' || !source.license.trim()) throw Error('请先设置 package.json 的 license')
|
|
21
|
+
requireClientRange(source)
|
|
15
22
|
const fields = [
|
|
16
23
|
'name',
|
|
17
24
|
'version',
|
|
@@ -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.
|
|
24
|
+
"@arcadia-eternity/content-sdk": "4.12.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.
|
|
41
|
+
"arcadia": "^4.12.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.
|
|
3
|
+
"version": "4.12.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.
|
|
67
|
-
"@arcadia-eternity/const": "4.
|
|
68
|
-
"@arcadia-eternity/pack-loader": "4.
|
|
69
|
-
"@arcadia-eternity/schema": "4.
|
|
66
|
+
"@arcadia-eternity/battle": "4.12.0",
|
|
67
|
+
"@arcadia-eternity/const": "4.12.0",
|
|
68
|
+
"@arcadia-eternity/pack-loader": "4.12.0",
|
|
69
|
+
"@arcadia-eternity/schema": "4.12.0"
|
|
70
70
|
},
|
|
71
71
|
"repository": {
|
|
72
72
|
"type": "git",
|
package/release-payload.mjs
CHANGED
|
@@ -8,10 +8,17 @@ const require = createRequire(import.meta.url)
|
|
|
8
8
|
const sdkRequire = createRequire(require.resolve('@arcadia-eternity/content-sdk'))
|
|
9
9
|
const { valid, validRange } = sdkRequire('semver')
|
|
10
10
|
|
|
11
|
+
export function requireClientRange(source) {
|
|
12
|
+
const range = source.engines?.arcadia
|
|
13
|
+
if (typeof range !== 'string' || !range.trim() || range.length > 256 || !validRange(range))
|
|
14
|
+
throw Error('发行内容包必须在 package.json 的 engines.arcadia 声明有效的客户端版本范围')
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
export function releasePayload(source, included, presentation) {
|
|
12
18
|
if (!source.arcadia?.projectId || !source.arcadia.namespace || !source.arcadia.content || !valid(source.version))
|
|
13
19
|
throw Error('发行包需要有效版本、projectId、namespace 和内容入口')
|
|
14
20
|
if (typeof source.license !== 'string' || !source.license.trim()) throw Error('请先设置 package.json 的 license')
|
|
21
|
+
requireClientRange(source)
|
|
15
22
|
const fields = [
|
|
16
23
|
'name',
|
|
17
24
|
'version',
|