@arcadia-eternity/content-sdk 4.9.0 → 4.9.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.
|
@@ -493,6 +493,7 @@ export interface EnvironmentExport {
|
|
|
493
493
|
}
|
|
494
494
|
export interface WorkspaceSnapshot {
|
|
495
495
|
format: 'arcadia.workspace-snapshot/2';
|
|
496
|
+
builtinEnvironmentAliases?: Readonly<Record<string, string>>;
|
|
496
497
|
builtinEnvironmentIds?: Readonly<Record<string, string>>;
|
|
497
498
|
workspaceId: string;
|
|
498
499
|
drafts: (EnvironmentDraft & {
|
|
@@ -522,6 +523,7 @@ export interface ContentWorkspace {
|
|
|
522
523
|
readonly root: string;
|
|
523
524
|
readonly workspaceId: string;
|
|
524
525
|
readonly bootId: string;
|
|
526
|
+
readonly builtinEnvironmentAliases?: Readonly<Record<string, string>>;
|
|
525
527
|
readonly builtinEnvironmentIds?: Readonly<Record<string, string>>;
|
|
526
528
|
listDrafts(): Promise<EnvironmentDraft[]>;
|
|
527
529
|
getDraft(environmentId: string): Promise<EnvironmentDraft>;
|
|
@@ -69,6 +69,13 @@ function readBuiltinEnvironmentIds(value) {
|
|
|
69
69
|
? { 'training-120': checkId(value.builtin120EnvironmentId, new RegExp('^builtin-120-' + uuid.source.slice(1))) }
|
|
70
70
|
: {};
|
|
71
71
|
}
|
|
72
|
+
function readBuiltinEnvironmentAliases(value) {
|
|
73
|
+
if (!('builtinEnvironmentAliases' in value))
|
|
74
|
+
return {};
|
|
75
|
+
if (!isRecord(value.builtinEnvironmentAliases))
|
|
76
|
+
throw contentError('WORKSPACE_FORMAT_INVALID');
|
|
77
|
+
return Object.fromEntries(Object.entries(value.builtinEnvironmentAliases).map(([oldId, id]) => [checkId(oldId, envId), checkId(id, envId)]));
|
|
78
|
+
}
|
|
72
79
|
async function regularDirectory(path) {
|
|
73
80
|
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
74
81
|
const info = await lstat(path);
|
|
@@ -131,6 +138,7 @@ class ContentWorkspaceImplementation {
|
|
|
131
138
|
root;
|
|
132
139
|
bootId = randomUUID();
|
|
133
140
|
workspaceId;
|
|
141
|
+
builtinEnvironmentAliases = {};
|
|
134
142
|
builtinEnvironmentIds = {};
|
|
135
143
|
#queue = Promise.resolve();
|
|
136
144
|
#closed = false;
|
|
@@ -175,6 +183,7 @@ class ContentWorkspaceImplementation {
|
|
|
175
183
|
else {
|
|
176
184
|
workspace.workspaceId = randomUUID();
|
|
177
185
|
}
|
|
186
|
+
workspace.builtinEnvironmentAliases = readBuiltinEnvironmentAliases(metadata ?? {});
|
|
178
187
|
workspace.builtinEnvironmentIds = readBuiltinEnvironmentIds(metadata ?? {});
|
|
179
188
|
if (!metadata || 'builtin120EnvironmentId' in metadata)
|
|
180
189
|
await workspace.#saveMetadata();
|
|
@@ -203,26 +212,55 @@ class ContentWorkspaceImplementation {
|
|
|
203
212
|
}
|
|
204
213
|
registerBuiltinEnvironments(keys, adopted) {
|
|
205
214
|
return this.#exclusive(async () => {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
215
|
+
const ids = readBuiltinEnvironmentIds({ builtinEnvironmentIds: Object.fromEntries(keys.map(key => [key, key])) });
|
|
216
|
+
const aliases = { ...this.builtinEnvironmentAliases };
|
|
217
|
+
const retiring = new Map();
|
|
218
|
+
for (const key of keys) {
|
|
219
|
+
const previous = Object.hasOwn(this.builtinEnvironmentIds, key)
|
|
220
|
+
? this.builtinEnvironmentIds[key]
|
|
221
|
+
: Object.hasOwn(adopted, key)
|
|
222
|
+
? adopted[key]
|
|
223
|
+
: undefined;
|
|
224
|
+
if (previous === key)
|
|
225
|
+
continue;
|
|
226
|
+
// An unregistered custom draft may already own the requested ID.
|
|
227
|
+
if (await lstat(this.#directory(key)).catch(error => {
|
|
228
|
+
if (errorCode(error) !== 'ENOENT')
|
|
229
|
+
throw error;
|
|
230
|
+
return undefined;
|
|
231
|
+
}))
|
|
232
|
+
throw contentError('BUILTIN_ENVIRONMENT_ID_CONFLICT', key);
|
|
233
|
+
if (previous !== undefined) {
|
|
234
|
+
checkId(previous, envId);
|
|
235
|
+
if (Object.hasOwn(ids, previous))
|
|
236
|
+
throw contentError('BUILTIN_ENVIRONMENT_ID_CONFLICT', previous);
|
|
237
|
+
retiring.set(previous, key);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
for (const [oldId, id] of retiring) {
|
|
241
|
+
// Preserve the previous installation intact. A restart can repeat this step before the metadata commits.
|
|
242
|
+
const archive = join(this.root, 'migration-backups');
|
|
243
|
+
await regularDirectory(archive);
|
|
244
|
+
await rename(this.#directory(oldId), join(archive, oldId)).catch(error => {
|
|
245
|
+
if (errorCode(error) !== 'ENOENT')
|
|
246
|
+
throw error;
|
|
247
|
+
});
|
|
248
|
+
aliases[oldId] = id;
|
|
249
|
+
}
|
|
250
|
+
if (!isDeepStrictEqual(ids, this.builtinEnvironmentIds) || retiring.size) {
|
|
251
|
+
await this.#saveMetadata(ids, aliases);
|
|
216
252
|
this.builtinEnvironmentIds = ids;
|
|
253
|
+
this.builtinEnvironmentAliases = aliases;
|
|
217
254
|
}
|
|
218
255
|
return ids;
|
|
219
256
|
}, true);
|
|
220
257
|
}
|
|
221
|
-
async #saveMetadata(ids = this.builtinEnvironmentIds) {
|
|
258
|
+
async #saveMetadata(ids = this.builtinEnvironmentIds, aliases = this.builtinEnvironmentAliases) {
|
|
222
259
|
await writeFileAtomic(join(this.root, 'workspace.json'), json({
|
|
223
260
|
format: 'arcadia.content-workspace/2',
|
|
224
261
|
workspaceId: this.workspaceId,
|
|
225
262
|
builtinEnvironmentIds: ids,
|
|
263
|
+
...(Object.keys(aliases).length && { builtinEnvironmentAliases: aliases }),
|
|
226
264
|
}));
|
|
227
265
|
}
|
|
228
266
|
async #assertOwner() {
|
|
@@ -664,6 +702,9 @@ class ContentWorkspaceImplementation {
|
|
|
664
702
|
format: 'arcadia.workspace-snapshot/2',
|
|
665
703
|
workspaceId: this.workspaceId,
|
|
666
704
|
builtinEnvironmentIds: this.builtinEnvironmentIds,
|
|
705
|
+
...(Object.keys(this.builtinEnvironmentAliases).length && {
|
|
706
|
+
builtinEnvironmentAliases: this.builtinEnvironmentAliases,
|
|
707
|
+
}),
|
|
667
708
|
drafts,
|
|
668
709
|
installations,
|
|
669
710
|
};
|
|
@@ -699,6 +740,7 @@ class ContentWorkspaceImplementation {
|
|
|
699
740
|
!Array.isArray(snapshot.installations))
|
|
700
741
|
throw contentError('WORKSPACE_SNAPSHOT_INVALID');
|
|
701
742
|
const builtinEnvironmentIds = readBuiltinEnvironmentIds(snapshot);
|
|
743
|
+
const builtinEnvironmentAliases = readBuiltinEnvironmentAliases(snapshot);
|
|
702
744
|
if ((await this.#listDrafts()).length)
|
|
703
745
|
throw contentError('WORKSPACE_NOT_EMPTY');
|
|
704
746
|
const drafts = new Map(snapshot.drafts.map(draft => {
|
|
@@ -756,6 +798,7 @@ class ContentWorkspaceImplementation {
|
|
|
756
798
|
throw contentError('WORKSPACE_SNAPSHOT_INVALID');
|
|
757
799
|
}
|
|
758
800
|
this.workspaceId = mode === 'restore' ? checkId(snapshot.workspaceId, uuid) : this.workspaceId;
|
|
801
|
+
this.builtinEnvironmentAliases = builtinEnvironmentAliases;
|
|
759
802
|
this.builtinEnvironmentIds = builtinEnvironmentIds;
|
|
760
803
|
await this.#saveMetadata();
|
|
761
804
|
return { workspaceId: this.workspaceId, installationIds: Object.fromEntries([...ids].map(id => [id, id])) };
|
|
@@ -1024,11 +1067,10 @@ export async function readShippedEnvironments(file, bundledVersions) {
|
|
|
1024
1067
|
return catalog;
|
|
1025
1068
|
}
|
|
1026
1069
|
export async function synchronizeShippedEnvironments(workspace, catalog, adopted, prepare) {
|
|
1027
|
-
|
|
1070
|
+
await workspace.registerBuiltinEnvironments(catalog.environments.map(doc => doc.id), adopted);
|
|
1028
1071
|
const drafts = await workspace.listDrafts();
|
|
1029
|
-
for (const
|
|
1030
|
-
const id =
|
|
1031
|
-
const document = { ...definition, id };
|
|
1072
|
+
for (const document of catalog.environments) {
|
|
1073
|
+
const id = document.id;
|
|
1032
1074
|
const current = drafts.find(item => item.document.id === id);
|
|
1033
1075
|
if (current && isDeepStrictEqual(current.document, document)) {
|
|
1034
1076
|
const [installed] = await workspace.listInstallations(id);
|
|
@@ -1037,5 +1079,5 @@ export async function synchronizeShippedEnvironments(workspace, catalog, adopted
|
|
|
1037
1079
|
}
|
|
1038
1080
|
await prepare(document, current?.revision ?? null);
|
|
1039
1081
|
}
|
|
1040
|
-
return
|
|
1082
|
+
return catalog.defaultEnvironment;
|
|
1041
1083
|
}
|
|
@@ -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.9.
|
|
24
|
+
"@arcadia-eternity/content-sdk": "4.9.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.9.
|
|
41
|
+
"arcadia": "^4.9.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.9.
|
|
3
|
+
"version": "4.9.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.9.
|
|
67
|
-
"@arcadia-eternity/
|
|
68
|
-
"@arcadia-eternity/
|
|
69
|
-
"@arcadia-eternity/
|
|
66
|
+
"@arcadia-eternity/battle": "4.9.1",
|
|
67
|
+
"@arcadia-eternity/pack-loader": "4.9.1",
|
|
68
|
+
"@arcadia-eternity/schema": "4.9.1",
|
|
69
|
+
"@arcadia-eternity/const": "4.9.1"
|
|
70
70
|
},
|
|
71
71
|
"repository": {
|
|
72
72
|
"type": "git",
|