@arcadia-eternity/content-sdk 4.7.1 → 4.8.1
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.
|
@@ -489,6 +489,7 @@ export interface EnvironmentExport {
|
|
|
489
489
|
}
|
|
490
490
|
export interface WorkspaceSnapshot {
|
|
491
491
|
format: 'arcadia.workspace-snapshot/2';
|
|
492
|
+
builtinEnvironmentIds?: Readonly<Record<string, string>>;
|
|
492
493
|
workspaceId: string;
|
|
493
494
|
drafts: (EnvironmentDraft & {
|
|
494
495
|
files?: {
|
|
@@ -517,6 +518,7 @@ export interface ContentWorkspace {
|
|
|
517
518
|
readonly root: string;
|
|
518
519
|
readonly workspaceId: string;
|
|
519
520
|
readonly bootId: string;
|
|
521
|
+
readonly builtinEnvironmentIds?: Readonly<Record<string, string>>;
|
|
520
522
|
listDrafts(): Promise<EnvironmentDraft[]>;
|
|
521
523
|
getDraft(environmentId: string): Promise<EnvironmentDraft>;
|
|
522
524
|
saveDraft(input: {
|
|
@@ -570,9 +572,12 @@ export interface ContentWorkspace {
|
|
|
570
572
|
}): Promise<void>;
|
|
571
573
|
cleanupStaging(): Promise<string[]>;
|
|
572
574
|
}
|
|
575
|
+
export interface OwnedContentWorkspace extends ContentWorkspace {
|
|
576
|
+
registerBuiltinEnvironments(keys: string[], adopted: Record<string, string>): Promise<Readonly<Record<string, string>>>;
|
|
577
|
+
}
|
|
573
578
|
export interface ContentWorkspaceConstructor {
|
|
574
579
|
new (root: string, options?: ContentWorkspaceOptions): ContentWorkspace;
|
|
575
|
-
open(directory: string, options?: ContentWorkspaceOptions): Promise<
|
|
580
|
+
open(directory: string, options?: ContentWorkspaceOptions): Promise<OwnedContentWorkspace>;
|
|
576
581
|
}
|
|
577
582
|
export interface EnvironmentMember {
|
|
578
583
|
archiveIntegrity?: string;
|
|
@@ -602,3 +607,165 @@ export type RemoveEnvironmentPackageInput = {
|
|
|
602
607
|
type PackageWorkspace = Pick<ContentWorkspace, 'listDrafts' | 'listInstallations' | 'saveDraft'>;
|
|
603
608
|
export declare function addEnvironmentPackage(workspace: PackageWorkspace, input: AddEnvironmentPackageInput): Promise<EnvironmentDraft>;
|
|
604
609
|
export declare function removeEnvironmentPackage(workspace: PackageWorkspace, input: RemoveEnvironmentPackageInput): Promise<EnvironmentDraft>;
|
|
610
|
+
/** The host supplies this catalog from the application distribution. */
|
|
611
|
+
export declare function readShippedEnvironments(file: string | URL, bundledVersions: Record<string, string>): Promise<{
|
|
612
|
+
defaultEnvironment: string;
|
|
613
|
+
environments: {
|
|
614
|
+
id: string;
|
|
615
|
+
name: string;
|
|
616
|
+
packages: Record<string, string>;
|
|
617
|
+
sources: string[];
|
|
618
|
+
schemaVersion: 2;
|
|
619
|
+
rules: {
|
|
620
|
+
schemaVersion: 1 | 2;
|
|
621
|
+
mechanics?: {
|
|
622
|
+
skillSlots?: {
|
|
623
|
+
normalMax: number;
|
|
624
|
+
climaxMax: number;
|
|
625
|
+
climaxMin?: number | undefined;
|
|
626
|
+
} | undefined;
|
|
627
|
+
individualValueDefault?: number | undefined;
|
|
628
|
+
individualValues?: {
|
|
629
|
+
max: number;
|
|
630
|
+
} | undefined;
|
|
631
|
+
allowFaintSwitch?: boolean | undefined;
|
|
632
|
+
inheritance?: {
|
|
633
|
+
eligible: "all" | "off" | "species" | string[];
|
|
634
|
+
pool?: {
|
|
635
|
+
mode: "append" | "fallback" | "replace";
|
|
636
|
+
skills: string[];
|
|
637
|
+
} | undefined;
|
|
638
|
+
} | undefined;
|
|
639
|
+
enhancement?: {
|
|
640
|
+
mode: "active" | "forbidden" | "suppressed";
|
|
641
|
+
stages?: string[] | undefined;
|
|
642
|
+
species?: string[] | undefined;
|
|
643
|
+
} | undefined;
|
|
644
|
+
secondGenerationNatures?: "all" | "off" | "species" | string[] | undefined;
|
|
645
|
+
} | undefined;
|
|
646
|
+
skillParameters?: {
|
|
647
|
+
profile?: string | undefined;
|
|
648
|
+
groups?: Record<string, number> | undefined;
|
|
649
|
+
overrides?: {
|
|
650
|
+
skill: string;
|
|
651
|
+
useId: string;
|
|
652
|
+
parameter: string;
|
|
653
|
+
value: number;
|
|
654
|
+
}[] | undefined;
|
|
655
|
+
} | undefined;
|
|
656
|
+
matchups?: {
|
|
657
|
+
table?: string | undefined;
|
|
658
|
+
adjustments?: {
|
|
659
|
+
attack: string;
|
|
660
|
+
defense: string;
|
|
661
|
+
multiplier: number;
|
|
662
|
+
}[] | undefined;
|
|
663
|
+
} | undefined;
|
|
664
|
+
learnsetAdjustments?: {
|
|
665
|
+
species: string;
|
|
666
|
+
source: "inherited" | "normal";
|
|
667
|
+
skill: string;
|
|
668
|
+
action: "add" | "remove";
|
|
669
|
+
level?: number | undefined;
|
|
670
|
+
}[] | undefined;
|
|
671
|
+
tier?: "standard" | undefined;
|
|
672
|
+
allow?: {
|
|
673
|
+
species?: string[] | undefined;
|
|
674
|
+
skills?: string[] | undefined;
|
|
675
|
+
marks?: string[] | undefined;
|
|
676
|
+
} | undefined;
|
|
677
|
+
deny?: {
|
|
678
|
+
species?: string[] | undefined;
|
|
679
|
+
skills?: string[] | undefined;
|
|
680
|
+
marks?: string[] | undefined;
|
|
681
|
+
} | undefined;
|
|
682
|
+
team?: {
|
|
683
|
+
minSize?: number | undefined;
|
|
684
|
+
maxSize?: number | undefined;
|
|
685
|
+
uniqueSpecies?: boolean | undefined;
|
|
686
|
+
} | undefined;
|
|
687
|
+
constraints?: ({
|
|
688
|
+
id: string;
|
|
689
|
+
allOf: {
|
|
690
|
+
kind: "mark" | "skill" | "species";
|
|
691
|
+
ids: string[];
|
|
692
|
+
fromCollections?: string[] | undefined;
|
|
693
|
+
}[];
|
|
694
|
+
kind: "ban";
|
|
695
|
+
scope: "pet" | "team";
|
|
696
|
+
exceptWhen?: {
|
|
697
|
+
kind: "mark" | "skill" | "species";
|
|
698
|
+
ids: string[];
|
|
699
|
+
fromCollections?: string[] | undefined;
|
|
700
|
+
}[] | undefined;
|
|
701
|
+
exceptAny?: {
|
|
702
|
+
kind: "mark" | "skill" | "species";
|
|
703
|
+
ids: string[];
|
|
704
|
+
fromCollections?: string[] | undefined;
|
|
705
|
+
}[][] | undefined;
|
|
706
|
+
} | {
|
|
707
|
+
id: string;
|
|
708
|
+
allOf: {
|
|
709
|
+
kind: "mark" | "skill" | "species";
|
|
710
|
+
ids: string[];
|
|
711
|
+
fromCollections?: string[] | undefined;
|
|
712
|
+
}[];
|
|
713
|
+
kind: "memberLimit";
|
|
714
|
+
max: number;
|
|
715
|
+
})[] | undefined;
|
|
716
|
+
collections?: {
|
|
717
|
+
id: string;
|
|
718
|
+
kind: "mark" | "skill" | "species";
|
|
719
|
+
ids: string[];
|
|
720
|
+
}[] | undefined;
|
|
721
|
+
include?: string[] | undefined;
|
|
722
|
+
constraintEdits?: {
|
|
723
|
+
remove?: string[] | undefined;
|
|
724
|
+
replace?: ({
|
|
725
|
+
id: string;
|
|
726
|
+
allOf: {
|
|
727
|
+
kind: "mark" | "skill" | "species";
|
|
728
|
+
ids: string[];
|
|
729
|
+
fromCollections?: string[] | undefined;
|
|
730
|
+
}[];
|
|
731
|
+
kind: "ban";
|
|
732
|
+
scope: "pet" | "team";
|
|
733
|
+
exceptWhen?: {
|
|
734
|
+
kind: "mark" | "skill" | "species";
|
|
735
|
+
ids: string[];
|
|
736
|
+
fromCollections?: string[] | undefined;
|
|
737
|
+
}[] | undefined;
|
|
738
|
+
exceptAny?: {
|
|
739
|
+
kind: "mark" | "skill" | "species";
|
|
740
|
+
ids: string[];
|
|
741
|
+
fromCollections?: string[] | undefined;
|
|
742
|
+
}[][] | undefined;
|
|
743
|
+
} | {
|
|
744
|
+
id: string;
|
|
745
|
+
allOf: {
|
|
746
|
+
kind: "mark" | "skill" | "species";
|
|
747
|
+
ids: string[];
|
|
748
|
+
fromCollections?: string[] | undefined;
|
|
749
|
+
}[];
|
|
750
|
+
kind: "memberLimit";
|
|
751
|
+
max: number;
|
|
752
|
+
})[] | undefined;
|
|
753
|
+
clearExceptions?: string[] | undefined;
|
|
754
|
+
exceptions?: {
|
|
755
|
+
target: string;
|
|
756
|
+
allOf: {
|
|
757
|
+
kind: "mark" | "skill" | "species";
|
|
758
|
+
ids: string[];
|
|
759
|
+
fromCollections?: string[] | undefined;
|
|
760
|
+
}[];
|
|
761
|
+
}[] | undefined;
|
|
762
|
+
} | undefined;
|
|
763
|
+
};
|
|
764
|
+
requires: {
|
|
765
|
+
engine?: string | undefined;
|
|
766
|
+
sdk?: string | undefined;
|
|
767
|
+
capabilities?: string[] | undefined;
|
|
768
|
+
};
|
|
769
|
+
}[];
|
|
770
|
+
}>;
|
|
771
|
+
export declare function synchronizeShippedEnvironments(workspace: OwnedContentWorkspace, catalog: Awaited<ReturnType<typeof readShippedEnvironments>>, adopted: Record<string, string>, prepare: (document: EnvironmentDocument, expectedRevision: string | null) => Promise<unknown>): Promise<string>;
|
|
@@ -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';
|
|
@@ -53,6 +54,21 @@ const checkId = (id, pattern = uuid) => {
|
|
|
53
54
|
throw contentError('RESOURCE_ID_INVALID');
|
|
54
55
|
return id;
|
|
55
56
|
};
|
|
57
|
+
// 4.8.0 wrote a single slot in both workspace metadata and backups.
|
|
58
|
+
function readBuiltinEnvironmentIds(value) {
|
|
59
|
+
if ('builtinEnvironmentIds' in value && value.builtinEnvironmentIds !== undefined) {
|
|
60
|
+
const entries = value.builtinEnvironmentIds;
|
|
61
|
+
if (!isRecord(entries))
|
|
62
|
+
throw contentError('WORKSPACE_FORMAT_INVALID');
|
|
63
|
+
const ids = Object.entries(entries).map(([key, id]) => [checkId(key, envId), checkId(id, envId)]);
|
|
64
|
+
if (new Set(ids.map(([, id]) => id)).size !== ids.length)
|
|
65
|
+
throw contentError('WORKSPACE_FORMAT_INVALID');
|
|
66
|
+
return Object.fromEntries(ids);
|
|
67
|
+
}
|
|
68
|
+
return 'builtin120EnvironmentId' in value && value.builtin120EnvironmentId !== undefined
|
|
69
|
+
? { 'training-120': checkId(value.builtin120EnvironmentId, new RegExp('^builtin-120-' + uuid.source.slice(1))) }
|
|
70
|
+
: {};
|
|
71
|
+
}
|
|
56
72
|
async function regularDirectory(path) {
|
|
57
73
|
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
58
74
|
const info = await lstat(path);
|
|
@@ -115,6 +131,7 @@ class ContentWorkspaceImplementation {
|
|
|
115
131
|
root;
|
|
116
132
|
bootId = randomUUID();
|
|
117
133
|
workspaceId;
|
|
134
|
+
builtinEnvironmentIds = {};
|
|
118
135
|
#queue = Promise.resolve();
|
|
119
136
|
#closed = false;
|
|
120
137
|
#controller = new AbortController();
|
|
@@ -157,8 +174,10 @@ class ContentWorkspaceImplementation {
|
|
|
157
174
|
}
|
|
158
175
|
else {
|
|
159
176
|
workspace.workspaceId = randomUUID();
|
|
160
|
-
await writeFileAtomic(file, json({ format: 'arcadia.content-workspace/2', workspaceId: workspace.workspaceId }));
|
|
161
177
|
}
|
|
178
|
+
workspace.builtinEnvironmentIds = readBuiltinEnvironmentIds(metadata ?? {});
|
|
179
|
+
if (!metadata || 'builtin120EnvironmentId' in metadata)
|
|
180
|
+
await workspace.#saveMetadata();
|
|
162
181
|
// Recover an interrupted directory replacement before exposing projects.
|
|
163
182
|
for (const name of await readdir(join(root, 'staging'))) {
|
|
164
183
|
if (!name.startsWith('replaced-') || !envId.test(name.slice(9)))
|
|
@@ -182,6 +201,30 @@ class ContentWorkspaceImplementation {
|
|
|
182
201
|
throw error;
|
|
183
202
|
}
|
|
184
203
|
}
|
|
204
|
+
registerBuiltinEnvironments(keys, adopted) {
|
|
205
|
+
return this.#exclusive(async () => {
|
|
206
|
+
const entries = keys.map(key => {
|
|
207
|
+
checkId(key, envId);
|
|
208
|
+
const previous = Object.hasOwn(this.builtinEnvironmentIds, key) ? this.builtinEnvironmentIds[key] : undefined;
|
|
209
|
+
const legacy = Object.hasOwn(adopted, key) ? checkId(adopted[key], envId) : undefined;
|
|
210
|
+
const id = previous ?? legacy ?? 'builtin-' + randomUUID();
|
|
211
|
+
return [key, id];
|
|
212
|
+
});
|
|
213
|
+
const ids = readBuiltinEnvironmentIds({ builtinEnvironmentIds: Object.fromEntries(entries) });
|
|
214
|
+
if (!isDeepStrictEqual(ids, this.builtinEnvironmentIds)) {
|
|
215
|
+
await this.#saveMetadata(ids);
|
|
216
|
+
this.builtinEnvironmentIds = ids;
|
|
217
|
+
}
|
|
218
|
+
return ids;
|
|
219
|
+
}, true);
|
|
220
|
+
}
|
|
221
|
+
async #saveMetadata(ids = this.builtinEnvironmentIds) {
|
|
222
|
+
await writeFileAtomic(join(this.root, 'workspace.json'), json({
|
|
223
|
+
format: 'arcadia.content-workspace/2',
|
|
224
|
+
workspaceId: this.workspaceId,
|
|
225
|
+
builtinEnvironmentIds: ids,
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
185
228
|
async #assertOwner() {
|
|
186
229
|
if (this.#closed)
|
|
187
230
|
throw contentError('WORKSPACE_CLOSED');
|
|
@@ -617,7 +660,13 @@ class ContentWorkspaceImplementation {
|
|
|
617
660
|
const files = await materialFiles(this.#directory(draft.document.id), this.#options);
|
|
618
661
|
installations.push({ version, files: files.map(({ path, bytes }) => ({ path, data: bytes.toString('base64') })) });
|
|
619
662
|
}
|
|
620
|
-
return {
|
|
663
|
+
return {
|
|
664
|
+
format: 'arcadia.workspace-snapshot/2',
|
|
665
|
+
workspaceId: this.workspaceId,
|
|
666
|
+
builtinEnvironmentIds: this.builtinEnvironmentIds,
|
|
667
|
+
drafts,
|
|
668
|
+
installations,
|
|
669
|
+
};
|
|
621
670
|
}
|
|
622
671
|
exportSnapshot() {
|
|
623
672
|
return this.#exclusive(() => this.#snapshot());
|
|
@@ -649,6 +698,7 @@ class ContentWorkspaceImplementation {
|
|
|
649
698
|
!Array.isArray(snapshot.drafts) ||
|
|
650
699
|
!Array.isArray(snapshot.installations))
|
|
651
700
|
throw contentError('WORKSPACE_SNAPSHOT_INVALID');
|
|
701
|
+
const builtinEnvironmentIds = readBuiltinEnvironmentIds(snapshot);
|
|
652
702
|
if ((await this.#listDrafts()).length)
|
|
653
703
|
throw contentError('WORKSPACE_NOT_EMPTY');
|
|
654
704
|
const drafts = new Map(snapshot.drafts.map(draft => {
|
|
@@ -706,7 +756,8 @@ class ContentWorkspaceImplementation {
|
|
|
706
756
|
throw contentError('WORKSPACE_SNAPSHOT_INVALID');
|
|
707
757
|
}
|
|
708
758
|
this.workspaceId = mode === 'restore' ? checkId(snapshot.workspaceId, uuid) : this.workspaceId;
|
|
709
|
-
|
|
759
|
+
this.builtinEnvironmentIds = builtinEnvironmentIds;
|
|
760
|
+
await this.#saveMetadata();
|
|
710
761
|
return { workspaceId: this.workspaceId, installationIds: Object.fromEntries([...ids].map(id => [id, id])) };
|
|
711
762
|
}, true);
|
|
712
763
|
}
|
|
@@ -951,3 +1002,40 @@ async function changeEnvironmentPackage(workspace, input) {
|
|
|
951
1002
|
}
|
|
952
1003
|
return workspace.saveDraft({ document: normalizeEnvironmentDocument(document), expectedRevision });
|
|
953
1004
|
}
|
|
1005
|
+
/** The host supplies this catalog from the application distribution. */
|
|
1006
|
+
export async function readShippedEnvironments(file, bundledVersions) {
|
|
1007
|
+
const schema = z
|
|
1008
|
+
.object({
|
|
1009
|
+
defaultEnvironment: z.string(),
|
|
1010
|
+
environments: z.array(EnvironmentDocumentV2Schema).min(1),
|
|
1011
|
+
})
|
|
1012
|
+
.strict();
|
|
1013
|
+
const catalog = schema.parse(JSON.parse(await readFile(file, 'utf8')));
|
|
1014
|
+
const keys = new Set(catalog.environments.map(doc => doc.id));
|
|
1015
|
+
if (keys.size !== catalog.environments.length || !keys.has(catalog.defaultEnvironment))
|
|
1016
|
+
throw contentError('SHIPPED_ENVIRONMENT_CATALOG_INVALID');
|
|
1017
|
+
for (const { packages } of catalog.environments)
|
|
1018
|
+
for (const [name, version] of Object.entries(bundledVersions))
|
|
1019
|
+
if (Object.hasOwn(packages, name)) {
|
|
1020
|
+
if (!semver.satisfies(version, packages[name]))
|
|
1021
|
+
throw contentError('SHIPPED_PACKAGE_VERSION_MISMATCH');
|
|
1022
|
+
packages[name] = version;
|
|
1023
|
+
}
|
|
1024
|
+
return catalog;
|
|
1025
|
+
}
|
|
1026
|
+
export async function synchronizeShippedEnvironments(workspace, catalog, adopted, prepare) {
|
|
1027
|
+
const ids = await workspace.registerBuiltinEnvironments(catalog.environments.map(doc => doc.id), adopted);
|
|
1028
|
+
const drafts = await workspace.listDrafts();
|
|
1029
|
+
for (const definition of catalog.environments) {
|
|
1030
|
+
const id = ids[definition.id];
|
|
1031
|
+
const document = { ...definition, id };
|
|
1032
|
+
const current = drafts.find(item => item.document.id === id);
|
|
1033
|
+
if (current && isDeepStrictEqual(current.document, document)) {
|
|
1034
|
+
const [installed] = await workspace.listInstallations(id);
|
|
1035
|
+
if (installed?.status === 'ready' && installed.draftRevision === current.revision)
|
|
1036
|
+
continue;
|
|
1037
|
+
}
|
|
1038
|
+
await prepare(document, current?.revision ?? null);
|
|
1039
|
+
}
|
|
1040
|
+
return ids[catalog.defaultEnvironment];
|
|
1041
|
+
}
|
|
@@ -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.8.1",
|
|
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.8.1"
|
|
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.8.1",
|
|
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/
|
|
68
|
-
"@arcadia-eternity/pack-loader": "4.
|
|
69
|
-
"@arcadia-eternity/
|
|
66
|
+
"@arcadia-eternity/battle": "4.8.1",
|
|
67
|
+
"@arcadia-eternity/schema": "4.8.1",
|
|
68
|
+
"@arcadia-eternity/pack-loader": "4.8.1",
|
|
69
|
+
"@arcadia-eternity/const": "4.8.1"
|
|
70
70
|
},
|
|
71
71
|
"repository": {
|
|
72
72
|
"type": "git",
|