@arcadia-eternity/content-sdk 4.3.4 → 4.4.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.
- package/README.md +3 -3
- package/bin/arcadia-content-mcp.mjs +2 -0
- package/bin/arcadia-content.mjs +2 -0
- package/dist/asset-inspect.d.ts +30 -0
- package/dist/asset-inspect.js +84 -0
- package/dist/author-api.d.ts +48 -0
- package/dist/author-api.js +128 -0
- package/dist/author-reference.d.ts +61 -0
- package/dist/author-reference.js +130 -0
- package/dist/build-content.d.ts +2 -0
- package/dist/build-content.js +29 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +81 -0
- package/dist/content-query.d.ts +30 -0
- package/dist/content-query.js +326 -0
- package/dist/content-workspace.d.ts +171 -0
- package/dist/content-workspace.js +981 -0
- package/dist/debug-environments.d.ts +117 -0
- package/dist/debug-environments.js +135 -0
- package/dist/demo.d.ts +1 -0
- package/dist/demo.js +18 -0
- package/dist/effect-build.d.ts +3 -0
- package/dist/effect-build.js +44 -0
- package/dist/environment-rules.d.ts +7 -0
- package/dist/environment-rules.js +94 -0
- package/dist/environment.d.ts +48 -0
- package/dist/environment.js +184 -0
- package/dist/job-journal.d.ts +19 -0
- package/dist/job-journal.js +110 -0
- package/dist/jobs.d.ts +103 -0
- package/dist/jobs.js +626 -0
- package/dist/lib/content.d.ts +24 -0
- package/dist/lib/content.js +106 -0
- package/dist/lib/presentation.d.ts +26 -0
- package/dist/lib/presentation.js +252 -0
- package/dist/lib/yaml-sharing.d.ts +16 -0
- package/dist/lib/yaml-sharing.js +130 -0
- package/dist/managed-projects.d.ts +37 -0
- package/dist/managed-projects.js +305 -0
- package/dist/managed-sources.d.ts +28 -0
- package/dist/managed-sources.js +541 -0
- package/dist/mcp-contracts.d.ts +420 -0
- package/dist/mcp-contracts.js +146 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +228 -0
- package/dist/module-path.d.ts +1 -0
- package/dist/module-path.js +8 -0
- package/dist/pack-project.d.ts +13 -0
- package/dist/pack-project.js +179 -0
- package/dist/preview-control.d.ts +17 -0
- package/dist/preview-control.js +273 -0
- package/dist/preview.d.ts +24 -0
- package/dist/preview.js +332 -0
- package/dist/project-teams.d.ts +51 -0
- package/dist/project-teams.js +106 -0
- package/dist/project.d.ts +18 -0
- package/dist/project.js +146 -0
- package/dist/rename.d.ts +2 -0
- package/dist/rename.js +128 -0
- package/dist/setup.d.ts +2 -0
- package/dist/setup.js +117 -0
- package/dist/source-lock.d.ts +9 -0
- package/dist/source-lock.js +117 -0
- package/dist/template/README.md +2 -0
- package/dist/template/docs/presentation.md +3 -3
- package/dist/template/package.json +3 -7
- package/dist/template/test/pack.test.mjs +10 -7
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +205 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.js +14 -0
- package/dist/workbench-context.d.ts +10 -0
- package/dist/workbench-context.js +27 -0
- package/dist/workspace-cli.d.ts +1 -0
- package/dist/workspace-cli.js +66 -0
- package/dist/workspace-materials.d.ts +19 -0
- package/dist/workspace-materials.js +165 -0
- package/dist/workspace.d.ts +190 -0
- package/dist/workspace.js +726 -0
- package/package.json +34 -27
- package/dist/asset-inspect.mjs +0 -67
- package/dist/author-api.mjs +0 -112
- package/dist/author-reference.mjs +0 -121
- package/dist/build-content.mjs +0 -30
- package/dist/cli.mjs +0 -76
- package/dist/content-query.mjs +0 -283
- package/dist/content-workspace.d.mts +0 -161
- package/dist/content-workspace.mjs +0 -936
- package/dist/debug-environments.mjs +0 -154
- package/dist/demo.mjs +0 -22
- package/dist/effect-build.d.mts +0 -2
- package/dist/effect-build.mjs +0 -46
- package/dist/environment-rules.d.mts +0 -5
- package/dist/environment-rules.mjs +0 -92
- package/dist/environment.mjs +0 -183
- package/dist/job-journal.mjs +0 -94
- package/dist/jobs.mjs +0 -579
- package/dist/lib/content.mjs +0 -95
- package/dist/lib/presentation.mjs +0 -240
- package/dist/lib/yaml-sharing.mjs +0 -101
- package/dist/managed-projects.d.mts +0 -35
- package/dist/managed-projects.mjs +0 -303
- package/dist/managed-sources.d.mts +0 -19
- package/dist/managed-sources.mjs +0 -503
- package/dist/mcp-contracts.mjs +0 -153
- package/dist/mcp.mjs +0 -369
- package/dist/pack-project.mjs +0 -157
- package/dist/preview-control.mjs +0 -260
- package/dist/preview.mjs +0 -313
- package/dist/project-teams.mjs +0 -98
- package/dist/project.mjs +0 -140
- package/dist/rename.mjs +0 -112
- package/dist/setup.mjs +0 -134
- package/dist/source-lock.mjs +0 -103
- package/dist/testing.mjs +0 -204
- package/dist/workbench-context.mjs +0 -18
- package/dist/workspace-cli.mjs +0 -60
- package/dist/workspace-materials.mjs +0 -153
- package/dist/workspace.mjs +0 -684
- /package/dist/{index.d.mts → index.d.ts} +0 -0
- /package/dist/{index.mjs → index.js} +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
2
|
+
import { extname, join, relative } from 'node:path';
|
|
3
|
+
import YAML from 'yaml';
|
|
4
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
5
|
+
import { errorCode, errorMessage, isRecord } from '../types.js';
|
|
6
|
+
const contentKinds = ['species', 'skills', 'marks', 'behaviors'];
|
|
7
|
+
const sourceKinds = [...contentKinds, 'presentations', 'resources'];
|
|
8
|
+
async function filesIn(directory) {
|
|
9
|
+
let entries;
|
|
10
|
+
try {
|
|
11
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (errorCode(error) === 'ENOENT')
|
|
15
|
+
return [];
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
const files = [];
|
|
19
|
+
for (const entry of entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
|
|
20
|
+
if (entry.name.startsWith('.'))
|
|
21
|
+
continue;
|
|
22
|
+
const file = join(directory, entry.name);
|
|
23
|
+
if (entry.isDirectory())
|
|
24
|
+
files.push(...(await filesIn(file)));
|
|
25
|
+
else if (entry.isSymbolicLink())
|
|
26
|
+
throw new Error(`Content sources must be ordinary files: ${file}`);
|
|
27
|
+
else if (['.json', '.yaml', '.yml'].includes(extname(entry.name)))
|
|
28
|
+
files.push(file);
|
|
29
|
+
}
|
|
30
|
+
return files;
|
|
31
|
+
}
|
|
32
|
+
/** Editable source files; each file may hold one record or an array of records. */
|
|
33
|
+
export async function readContentSources(root) {
|
|
34
|
+
const directory = join(root, 'data');
|
|
35
|
+
const base = await readFile(join(root, 'pack.json'), 'utf8')
|
|
36
|
+
.then(JSON.parse)
|
|
37
|
+
.catch((error) => {
|
|
38
|
+
if (errorCode(error) === 'ENOENT')
|
|
39
|
+
return undefined;
|
|
40
|
+
throw error;
|
|
41
|
+
});
|
|
42
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (!base &&
|
|
45
|
+
entry.isDirectory() &&
|
|
46
|
+
!entry.name.startsWith('.') &&
|
|
47
|
+
!sourceKinds.includes(entry.name))
|
|
48
|
+
throw new Error(`Unknown content directory: data/${entry.name}`);
|
|
49
|
+
}
|
|
50
|
+
const sources = [];
|
|
51
|
+
for (const kind of sourceKinds) {
|
|
52
|
+
const ids = new Map();
|
|
53
|
+
const baseFiles = base && contentKinds.includes(kind)
|
|
54
|
+
? (base.data?.[kind] ?? []).map(file => join(directory, file))
|
|
55
|
+
: undefined;
|
|
56
|
+
for (const file of baseFiles ?? (await filesIn(join(directory, kind)))) {
|
|
57
|
+
const name = relative(root, file);
|
|
58
|
+
const text = await readFile(file, 'utf8');
|
|
59
|
+
let document, value;
|
|
60
|
+
try {
|
|
61
|
+
if (extname(file) === '.json')
|
|
62
|
+
value = JSON.parse(text);
|
|
63
|
+
else {
|
|
64
|
+
document = YAML.parseDocument(text, { merge: true });
|
|
65
|
+
if (document.errors.length)
|
|
66
|
+
throw document.errors[0];
|
|
67
|
+
value = document.toJS();
|
|
68
|
+
}
|
|
69
|
+
if (!isDeepStrictEqual(JSON.parse(JSON.stringify(value)), value))
|
|
70
|
+
throw new Error('Content values must be finite JSON-compatible data');
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new Error(`Invalid content in ${name}: ${errorMessage(error)}`, { cause: error });
|
|
74
|
+
}
|
|
75
|
+
const records = Array.isArray(value) ? value : [value];
|
|
76
|
+
for (const record of records) {
|
|
77
|
+
if (!isRecord(record) || typeof record.id !== 'string' || !record.id)
|
|
78
|
+
throw new Error(`Each record needs an id: ${name}`);
|
|
79
|
+
if (ids.has(record.id))
|
|
80
|
+
throw new Error(`Duplicate ${kind} id ${record.id}: ${ids.get(record.id)} and ${name}`);
|
|
81
|
+
ids.set(record.id, name);
|
|
82
|
+
}
|
|
83
|
+
sources.push({
|
|
84
|
+
kind,
|
|
85
|
+
file,
|
|
86
|
+
text,
|
|
87
|
+
document,
|
|
88
|
+
value,
|
|
89
|
+
records: records,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return sources;
|
|
94
|
+
}
|
|
95
|
+
/** File names and grouping do not enter runtime IDs or record ordering. */
|
|
96
|
+
export function assembleContent(sources) {
|
|
97
|
+
return {
|
|
98
|
+
data: Object.fromEntries(contentKinds.map(kind => [
|
|
99
|
+
kind,
|
|
100
|
+
sources
|
|
101
|
+
.filter(source => source.kind === kind)
|
|
102
|
+
.flatMap(source => source.records)
|
|
103
|
+
.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)),
|
|
104
|
+
])),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type UnknownRecord } from '../types.js';
|
|
2
|
+
import type { ContentSource } from './content.js';
|
|
3
|
+
export declare function resourceReferences(presentation: unknown): unknown[];
|
|
4
|
+
export declare const validResourceId: (value: unknown) => value is string;
|
|
5
|
+
export declare function validAssetPath(value: unknown): boolean;
|
|
6
|
+
export declare function bindingPresentation(binding: unknown): UnknownRecord;
|
|
7
|
+
/** Read only declared files. References are IDs; locations never become resource identities. */
|
|
8
|
+
export declare function buildPresentation(root: string, sources: ContentSource[], { includeLocales }?: {
|
|
9
|
+
includeLocales?: boolean;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
version: number;
|
|
12
|
+
bindings: ({
|
|
13
|
+
id: string;
|
|
14
|
+
} & Record<string, unknown>)[];
|
|
15
|
+
defaultLocale: string;
|
|
16
|
+
resources: {
|
|
17
|
+
kind: 'http' | 'file';
|
|
18
|
+
id: string;
|
|
19
|
+
source: string;
|
|
20
|
+
sha256?: string;
|
|
21
|
+
bytes?: number;
|
|
22
|
+
mime?: string;
|
|
23
|
+
tags?: unknown;
|
|
24
|
+
}[];
|
|
25
|
+
locales: Record<string, Record<string, unknown>>;
|
|
26
|
+
}>;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstat, readdir, readFile } from 'node:fs/promises';
|
|
3
|
+
import { join, relative, extname } from 'node:path';
|
|
4
|
+
import YAML from 'yaml';
|
|
5
|
+
import { errorCode, errorMessage, isRecord } from '../types.js';
|
|
6
|
+
const maximumBytes = 64 * 1024 * 1024;
|
|
7
|
+
const mimeTypes = {
|
|
8
|
+
'.png': 'image/png',
|
|
9
|
+
'.jpg': 'image/jpeg',
|
|
10
|
+
'.jpeg': 'image/jpeg',
|
|
11
|
+
'.webp': 'image/webp',
|
|
12
|
+
'.ogg': 'audio/ogg',
|
|
13
|
+
'.mp3': 'audio/mpeg',
|
|
14
|
+
'.swf': 'application/x-shockwave-flash',
|
|
15
|
+
};
|
|
16
|
+
const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
17
|
+
const remote = (value) => /^https?:\/\//.test(value);
|
|
18
|
+
export function resourceReferences(presentation) {
|
|
19
|
+
if (!presentation)
|
|
20
|
+
return [];
|
|
21
|
+
if (!isRecord(presentation))
|
|
22
|
+
throw new Error('presentation must be an object');
|
|
23
|
+
const keys = ['icon', 'portrait', 'cry', 'sfx', 'background', 'music', 'battle'];
|
|
24
|
+
for (const key of Object.keys(presentation))
|
|
25
|
+
if (!keys.includes(key))
|
|
26
|
+
throw new Error(`Unknown presentation field: ${key}`);
|
|
27
|
+
const refs = keys
|
|
28
|
+
.filter(key => key !== 'battle')
|
|
29
|
+
.flatMap(key => (presentation[key] === undefined ? [] : [presentation[key]]));
|
|
30
|
+
if (presentation.battle) {
|
|
31
|
+
const battle = presentation.battle;
|
|
32
|
+
if (!isRecord(battle) ||
|
|
33
|
+
typeof battle.renderer !== 'string' ||
|
|
34
|
+
!['image', 'seer2-swf'].includes(battle.renderer) ||
|
|
35
|
+
!battle.source ||
|
|
36
|
+
Object.keys(battle).some(key => !['renderer', 'source', 'fallback'].includes(key)))
|
|
37
|
+
throw new Error('Invalid battle presentation');
|
|
38
|
+
refs.push(battle.source);
|
|
39
|
+
if (battle.fallback !== undefined)
|
|
40
|
+
refs.push(battle.fallback);
|
|
41
|
+
}
|
|
42
|
+
for (const ref of refs) {
|
|
43
|
+
if (typeof ref === 'string' && validResourceId(ref))
|
|
44
|
+
continue;
|
|
45
|
+
if (isRecord(ref) &&
|
|
46
|
+
typeof ref.namespace === 'string' &&
|
|
47
|
+
ref.namespace &&
|
|
48
|
+
typeof ref.id === 'string' &&
|
|
49
|
+
validResourceId(ref.id) &&
|
|
50
|
+
Object.keys(ref).every(key => ['namespace', 'id'].includes(key)))
|
|
51
|
+
continue;
|
|
52
|
+
throw new Error(`Invalid presentation resource: ${JSON.stringify(ref)}`);
|
|
53
|
+
}
|
|
54
|
+
return refs;
|
|
55
|
+
}
|
|
56
|
+
export const validResourceId = (value) => typeof value === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/.test(value);
|
|
57
|
+
export function validAssetPath(value) {
|
|
58
|
+
return (typeof value === 'string' &&
|
|
59
|
+
!value.startsWith('/') &&
|
|
60
|
+
!value.includes(':') &&
|
|
61
|
+
!value.split('/').some(part => ['node_modules', '.git', '.arcadia', 'dist'].includes(part)) &&
|
|
62
|
+
!value.includes('\\') &&
|
|
63
|
+
!value.includes('\0') &&
|
|
64
|
+
value.split('/').every(part => part && part !== '.' && part !== '..'));
|
|
65
|
+
}
|
|
66
|
+
async function files(root, directory) {
|
|
67
|
+
let entries;
|
|
68
|
+
try {
|
|
69
|
+
const info = await lstat(directory);
|
|
70
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
71
|
+
throw new Error(`Presentation directory must be an ordinary directory: ${relative(root, directory)}`);
|
|
72
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (errorCode(error) === 'ENOENT')
|
|
76
|
+
return [];
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
const output = [];
|
|
80
|
+
for (const entry of entries.sort((a, b) => compare(a.name, b.name))) {
|
|
81
|
+
if (entry.name.startsWith('.'))
|
|
82
|
+
continue;
|
|
83
|
+
const path = join(directory, entry.name);
|
|
84
|
+
if (entry.isSymbolicLink())
|
|
85
|
+
throw new Error(`Presentation sources must be ordinary files: ${relative(root, path)}`);
|
|
86
|
+
if (entry.isDirectory())
|
|
87
|
+
output.push(...(await files(root, path)));
|
|
88
|
+
else if (entry.isFile())
|
|
89
|
+
output.push(path);
|
|
90
|
+
}
|
|
91
|
+
return output;
|
|
92
|
+
}
|
|
93
|
+
export function bindingPresentation(binding) {
|
|
94
|
+
if (!isRecord(binding))
|
|
95
|
+
throw new Error('presentation binding must be an object');
|
|
96
|
+
const { id: _id, target: _target, ...presentation } = binding;
|
|
97
|
+
return presentation;
|
|
98
|
+
}
|
|
99
|
+
function validateBinding(binding, sources) {
|
|
100
|
+
if (!isRecord(binding) || !isRecord(binding.target))
|
|
101
|
+
throw new Error('Invalid presentation target');
|
|
102
|
+
const target = binding.target;
|
|
103
|
+
if (typeof target.kind !== 'string' ||
|
|
104
|
+
!['species', 'skills', 'marks'].includes(target.kind) ||
|
|
105
|
+
typeof target.id !== 'string' ||
|
|
106
|
+
Object.keys(target).some(key => !['kind', 'id'].includes(key)))
|
|
107
|
+
throw new Error(`Invalid presentation target: ${typeof binding.id === 'string' ? binding.id : JSON.stringify(binding.id)}`);
|
|
108
|
+
if (!sources.some(source => source.kind === target.kind && source.records.some(row => row.id === target.id)))
|
|
109
|
+
throw new Error(`Missing presentation target: ${target.kind}/${target.id}`);
|
|
110
|
+
return resourceReferences(bindingPresentation(binding));
|
|
111
|
+
}
|
|
112
|
+
/** Read only declared files. References are IDs; locations never become resource identities. */
|
|
113
|
+
export async function buildPresentation(root, sources, { includeLocales = true } = {}) {
|
|
114
|
+
const resources = [];
|
|
115
|
+
const definitions = sources.filter(source => source.kind === 'resources');
|
|
116
|
+
for (const source of definitions)
|
|
117
|
+
for (const record of source.records) {
|
|
118
|
+
const { id, source: location, kind, name: _name } = record;
|
|
119
|
+
if (!validResourceId(id) ||
|
|
120
|
+
typeof kind !== 'string' ||
|
|
121
|
+
!['image', 'audio', 'swf'].includes(kind) ||
|
|
122
|
+
typeof location !== 'string' ||
|
|
123
|
+
Object.keys(record).some(key => !['id', 'source', 'kind', 'name', 'tags'].includes(key)) ||
|
|
124
|
+
(record.name !== undefined && typeof record.name !== 'string') ||
|
|
125
|
+
(record.tags !== undefined &&
|
|
126
|
+
(!Array.isArray(record.tags) || record.tags.some((tag) => typeof tag !== 'string'))))
|
|
127
|
+
throw new Error(`${relative(root, source.file)}: Invalid resource definition ${id}`);
|
|
128
|
+
const url = remote(location) ? new URL(location) : undefined;
|
|
129
|
+
if (url && (url.username || url.password))
|
|
130
|
+
throw new Error(`Resource URL must not contain credentials: ${id}`);
|
|
131
|
+
const mime = mimeTypes[extname(url ? url.pathname : location).toLowerCase()];
|
|
132
|
+
if (!mime ||
|
|
133
|
+
(kind === 'image'
|
|
134
|
+
? !mime.startsWith('image/')
|
|
135
|
+
: kind === 'audio'
|
|
136
|
+
? !mime.startsWith('audio/')
|
|
137
|
+
: mime !== 'application/x-shockwave-flash'))
|
|
138
|
+
throw new Error(`Resource type does not match source: ${id}`);
|
|
139
|
+
if (url) {
|
|
140
|
+
resources.push({ kind: 'http', id, source: location, mime, ...(record.tags ? { tags: record.tags } : {}) });
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!validAssetPath(location))
|
|
144
|
+
throw new Error(`Invalid resource path: ${id}`);
|
|
145
|
+
let path = root;
|
|
146
|
+
for (const part of location.split('/')) {
|
|
147
|
+
path = join(path, part);
|
|
148
|
+
if ((await lstat(path)).isSymbolicLink())
|
|
149
|
+
throw new Error(`Resource must not use symbolic links: ${id}`);
|
|
150
|
+
}
|
|
151
|
+
const info = await lstat(path);
|
|
152
|
+
if (!info.isFile() || !info.size || info.size > maximumBytes)
|
|
153
|
+
throw new Error(`Resource size invalid: ${id}`);
|
|
154
|
+
const bytes = await readFile(path);
|
|
155
|
+
if (!bytes.length || bytes.length > maximumBytes)
|
|
156
|
+
throw new Error(`Resource size invalid: ${id}`);
|
|
157
|
+
resources.push({
|
|
158
|
+
kind: 'file',
|
|
159
|
+
id,
|
|
160
|
+
source: location,
|
|
161
|
+
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
162
|
+
bytes: bytes.length,
|
|
163
|
+
mime,
|
|
164
|
+
...(record.tags ? { tags: record.tags } : {}),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const ids = new Set(resources.map(row => row.id));
|
|
168
|
+
const kinds = new Map(definitions.flatMap(source => source.records).map(row => [row.id, row.kind]));
|
|
169
|
+
const bindings = [];
|
|
170
|
+
const targets = new Set();
|
|
171
|
+
for (const source of sources)
|
|
172
|
+
for (const record of source.records) {
|
|
173
|
+
if (!['presentations', 'resources'].includes(source.kind) &&
|
|
174
|
+
['presentation', 'assetRef', 'iconRef', 'sfxRef'].some(key => key in record))
|
|
175
|
+
throw new Error(`${relative(root, source.file)}: Move presentation into data/presentations and resources into data/resources`);
|
|
176
|
+
if (source.kind !== 'presentations')
|
|
177
|
+
continue;
|
|
178
|
+
try {
|
|
179
|
+
const refs = validateBinding(record, sources);
|
|
180
|
+
const targetFields = isRecord(record.target) ? record.target : {};
|
|
181
|
+
const target = JSON.stringify([targetFields.kind, targetFields.id]);
|
|
182
|
+
if (targets.has(target))
|
|
183
|
+
throw new Error(`Duplicate presentation target: ${target}`);
|
|
184
|
+
targets.add(target);
|
|
185
|
+
for (const ref of refs)
|
|
186
|
+
if (typeof ref === 'string' && !ids.has(ref))
|
|
187
|
+
throw new Error(`Missing resource ${ref}`);
|
|
188
|
+
const kindOf = (ref) => (typeof ref === 'string' ? kinds.get(ref) : undefined);
|
|
189
|
+
const presentation = bindingPresentation(record);
|
|
190
|
+
for (const [slot, ref] of Object.entries(presentation)) {
|
|
191
|
+
if (slot === 'battle') {
|
|
192
|
+
if (!isRecord(ref))
|
|
193
|
+
continue;
|
|
194
|
+
if (kindOf(ref.source) && kindOf(ref.source) !== (ref.renderer === 'image' ? 'image' : 'swf'))
|
|
195
|
+
throw new Error('Battle resource type mismatch');
|
|
196
|
+
if (kindOf(ref.fallback) && kindOf(ref.fallback) !== 'image')
|
|
197
|
+
throw new Error('Fallback must be an image');
|
|
198
|
+
}
|
|
199
|
+
else if (kindOf(ref) && kindOf(ref) !== (['sfx', 'cry', 'music'].includes(slot) ? 'audio' : 'image'))
|
|
200
|
+
throw new Error(`Resource type mismatch: ${slot}`);
|
|
201
|
+
}
|
|
202
|
+
bindings.push(record);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
throw new Error(`${relative(root, source.file)}: ${errorMessage(error)}`, { cause: error });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const locales = {};
|
|
209
|
+
for (const file of includeLocales ? await files(root, join(root, 'locales')) : []) {
|
|
210
|
+
const path = relative(join(root, 'locales'), file).split('\\').join('/');
|
|
211
|
+
const match = /^([A-Za-z0-9-]+)\/([A-Za-z0-9_-]+)\.(json|ya?ml)$/.exec(path);
|
|
212
|
+
if (!match)
|
|
213
|
+
throw new Error(`Expected locales/<language>/<namespace>.json|yaml: ${path}`);
|
|
214
|
+
const [, language, namespace] = match;
|
|
215
|
+
const canonicalLanguage = Intl.getCanonicalLocales(language)[0];
|
|
216
|
+
const text = await readFile(file, 'utf8');
|
|
217
|
+
const value = match[3] === 'json' ? JSON.parse(text) : YAML.parse(text, { uniqueKeys: true, merge: true });
|
|
218
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
219
|
+
throw new Error(`Expected locale object: ${path}`);
|
|
220
|
+
const records = {
|
|
221
|
+
species: 'species',
|
|
222
|
+
skill: 'skills',
|
|
223
|
+
mark: 'marks',
|
|
224
|
+
mark_ability: 'marks',
|
|
225
|
+
mark_emblem: 'marks',
|
|
226
|
+
mark_global: 'marks',
|
|
227
|
+
}[namespace];
|
|
228
|
+
if (!records)
|
|
229
|
+
throw new Error(`Unsupported content locale namespace: ${path}`);
|
|
230
|
+
const ids = new Set(sources.filter(source => source.kind === records).flatMap(source => source.records.map(record => record.id)));
|
|
231
|
+
for (const [id, entry] of Object.entries(value)) {
|
|
232
|
+
if (!ids.has(id))
|
|
233
|
+
throw new Error(`${path}: Unknown content ID ${id}`);
|
|
234
|
+
if (!entry ||
|
|
235
|
+
typeof entry !== 'object' ||
|
|
236
|
+
Array.isArray(entry) ||
|
|
237
|
+
Object.entries(entry).some(([field, text]) => !['name', 'description'].includes(field) || typeof text !== 'string'))
|
|
238
|
+
throw new Error(`${path}: Expected name/description strings for ${id}`);
|
|
239
|
+
}
|
|
240
|
+
const target = (locales[canonicalLanguage] ??= {});
|
|
241
|
+
if (Object.hasOwn(target, namespace))
|
|
242
|
+
throw new Error(`Duplicate locale namespace: ${path}`);
|
|
243
|
+
target[namespace] = value;
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
version: 2,
|
|
247
|
+
bindings: bindings.sort((a, b) => compare(a.id, b.id)),
|
|
248
|
+
defaultLocale: 'zh-CN',
|
|
249
|
+
resources: resources.sort((a, b) => compare(a.id, b.id)),
|
|
250
|
+
locales,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Document, LineCounter } from 'yaml';
|
|
2
|
+
export type NodePath = Array<string | number>;
|
|
3
|
+
export interface SharedField {
|
|
4
|
+
path: NodePath;
|
|
5
|
+
reason: string;
|
|
6
|
+
anchor: string;
|
|
7
|
+
sourcePath: NodePath;
|
|
8
|
+
line?: number;
|
|
9
|
+
column?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Source-level sharing, before conversion to plain values loses provenance. */
|
|
12
|
+
export declare function yamlSharing(doc: Document | undefined, lineCounter: LineCounter | undefined): SharedField[];
|
|
13
|
+
export declare function recordSharing(fields: SharedField[], index: string | number | null): SharedField[];
|
|
14
|
+
export declare function changedSharedField(fields: SharedField[], before: unknown, after: unknown): SharedField | undefined;
|
|
15
|
+
/** Detect accidental alias expansion or anchor loss during structural updates. */
|
|
16
|
+
export declare function sharingSignature(doc: Document): Array<[string, string]>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import YAML from 'yaml';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
const mergeKey = (pair) => YAML.isScalar(pair.key) && typeof pair.key.value === 'symbol' && pair.key.value.description === '<<';
|
|
4
|
+
const prefix = (parent, child) => parent.every((part, index) => part === child[index]);
|
|
5
|
+
/** Source-level sharing, before conversion to plain values loses provenance. */
|
|
6
|
+
export function yamlSharing(doc, lineCounter) {
|
|
7
|
+
if (!doc)
|
|
8
|
+
return [];
|
|
9
|
+
const sourceDoc = doc;
|
|
10
|
+
const paths = new Map(), referenced = new Set(), fields = [];
|
|
11
|
+
function index(node, path) {
|
|
12
|
+
if (!YAML.isNode(node))
|
|
13
|
+
return;
|
|
14
|
+
paths.set(node, path);
|
|
15
|
+
if (YAML.isAlias(node)) {
|
|
16
|
+
const target = node.resolve(sourceDoc);
|
|
17
|
+
if (target)
|
|
18
|
+
referenced.add(target);
|
|
19
|
+
}
|
|
20
|
+
if (YAML.isSeq(node))
|
|
21
|
+
node.items.forEach((item, i) => index(item, [...path, i]));
|
|
22
|
+
if (YAML.isMap(node))
|
|
23
|
+
for (const pair of node.items)
|
|
24
|
+
index(pair.value, [...path, pairKey(pair)]);
|
|
25
|
+
}
|
|
26
|
+
index(doc.contents, []);
|
|
27
|
+
function add(path, reason, source) {
|
|
28
|
+
const location = lineCounter && source.range ? lineCounter.linePos(source.range[0]) : undefined;
|
|
29
|
+
fields.push({
|
|
30
|
+
path,
|
|
31
|
+
reason,
|
|
32
|
+
anchor: source.anchor ?? '',
|
|
33
|
+
sourcePath: paths.get(source) ?? [],
|
|
34
|
+
...(location ? { line: location.line, column: location.col } : {}),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// Merge sequences use the first mapping that supplies a key; local keys win.
|
|
38
|
+
function effective(node, seen = new Set(), origin = node) {
|
|
39
|
+
if (YAML.isAlias(node)) {
|
|
40
|
+
const target = node.resolve(sourceDoc);
|
|
41
|
+
return effective(target, seen, target);
|
|
42
|
+
}
|
|
43
|
+
if (YAML.isSeq(node) && !seen.has(node)) {
|
|
44
|
+
const result = new Map();
|
|
45
|
+
for (const item of node.items)
|
|
46
|
+
for (const [key, from] of effective(item, new Set([...seen, node])))
|
|
47
|
+
if (!result.has(key))
|
|
48
|
+
result.set(key, from);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
if (!YAML.isMap(node) || seen.has(node))
|
|
52
|
+
return new Map();
|
|
53
|
+
seen = new Set([...seen, node]);
|
|
54
|
+
const result = new Map();
|
|
55
|
+
for (const pair of node.items.filter(mergeKey)) {
|
|
56
|
+
const sources = YAML.isSeq(pair.value) ? pair.value.items : [pair.value];
|
|
57
|
+
for (const source of sources)
|
|
58
|
+
for (const [key, from] of effective(source, seen))
|
|
59
|
+
if (!result.has(key))
|
|
60
|
+
result.set(key, from);
|
|
61
|
+
}
|
|
62
|
+
for (const pair of node.items.filter(pair => !mergeKey(pair)))
|
|
63
|
+
result.set(String(pairKey(pair)), origin);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function walk(node, path) {
|
|
67
|
+
if (YAML.isAlias(node)) {
|
|
68
|
+
add(path, 'alias', node.resolve(sourceDoc));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!YAML.isNode(node))
|
|
72
|
+
return;
|
|
73
|
+
if (node.anchor && referenced.has(node)) {
|
|
74
|
+
add(path, 'anchor', node);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (YAML.isSeq(node))
|
|
78
|
+
node.items.forEach((item, i) => walk(item, [...path, i]));
|
|
79
|
+
if (YAML.isMap(node)) {
|
|
80
|
+
const local = new Set(node.items.filter(pair => !mergeKey(pair)).map(pair => String(pairKey(pair))));
|
|
81
|
+
for (const [key, source] of effective(node))
|
|
82
|
+
if (!local.has(key))
|
|
83
|
+
add([...path, key], 'merge', source);
|
|
84
|
+
for (const pair of node.items.filter(pair => !mergeKey(pair)))
|
|
85
|
+
walk(pair.value, [...path, pairKey(pair)]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
walk(doc.contents, []);
|
|
89
|
+
return fields;
|
|
90
|
+
}
|
|
91
|
+
function pairKey(pair) {
|
|
92
|
+
const key = pair.key;
|
|
93
|
+
if (YAML.isScalar(key)) {
|
|
94
|
+
if (typeof key.value === 'string')
|
|
95
|
+
return key.value;
|
|
96
|
+
if (key.value == null || typeof key.value === 'number' || typeof key.value === 'boolean')
|
|
97
|
+
return String(key.value);
|
|
98
|
+
}
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
export function recordSharing(fields, index) {
|
|
102
|
+
const root = index === null ? [] : [index];
|
|
103
|
+
return fields
|
|
104
|
+
.filter(field => prefix(root, field.path) || prefix(field.path, root))
|
|
105
|
+
.map(field => ({
|
|
106
|
+
...field,
|
|
107
|
+
path: field.path.slice(root.length),
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
export function changedSharedField(fields, before, after) {
|
|
111
|
+
const at = (value, path) => path.reduce((current, key) => {
|
|
112
|
+
if (current === null || typeof current !== 'object')
|
|
113
|
+
return undefined;
|
|
114
|
+
return current[key];
|
|
115
|
+
}, value);
|
|
116
|
+
return fields.find(field => !isDeepStrictEqual(at(before, field.path), at(after, field.path)));
|
|
117
|
+
}
|
|
118
|
+
/** Detect accidental alias expansion or anchor loss during structural updates. */
|
|
119
|
+
export function sharingSignature(doc) {
|
|
120
|
+
const result = [];
|
|
121
|
+
YAML.visit(doc, {
|
|
122
|
+
Node(_key, node) {
|
|
123
|
+
if (node.anchor)
|
|
124
|
+
result.push(['anchor', node.anchor]);
|
|
125
|
+
if (YAML.isAlias(node))
|
|
126
|
+
result.push(['alias', node.source]);
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ContentWorkspace, EnvironmentVersion, PrepareVersionInput, StaticPreparer } from './content-workspace.js';
|
|
2
|
+
import type { ManagedSource } from './managed-sources.js';
|
|
3
|
+
export interface ManagedProjectsOptions {
|
|
4
|
+
registry?: string;
|
|
5
|
+
offline?: boolean;
|
|
6
|
+
/** Host permission to acquire metadata/materials; never grants authority to execute them. */
|
|
7
|
+
allowThirdPartyContent?: boolean;
|
|
8
|
+
sources?: Record<string, ManagedSource>;
|
|
9
|
+
npmUserConfig?: string;
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
maxBytes?: number;
|
|
12
|
+
maxFiles?: number;
|
|
13
|
+
maxConcurrent?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolves a captured draft into a standard installed npm project. Construction and
|
|
17
|
+
* source registration belong to the host, while requests contain only environment IDs.
|
|
18
|
+
* The ContentWorkspace still owns immutable versions, leases, and publication.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ManagedProjects {
|
|
21
|
+
#private;
|
|
22
|
+
readonly root: string;
|
|
23
|
+
constructor(root: string, options?: ManagedProjectsOptions);
|
|
24
|
+
prepareVersion(workspace: ContentWorkspace, input: {
|
|
25
|
+
onProgress?: PrepareVersionInput['onProgress'];
|
|
26
|
+
environmentId: string;
|
|
27
|
+
expectedRevision: string;
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
beforeCommit?: () => Promise<void>;
|
|
30
|
+
}, validate: StaticPreparer): Promise<EnvironmentVersion>;
|
|
31
|
+
/** Transfer an installed project to the host's existing library without a second copy. */
|
|
32
|
+
prepareProject<T>(document: unknown, input: {
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
onProgress?: PrepareVersionInput['onProgress'];
|
|
35
|
+
}, consume: (directory: string, signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
36
|
+
close(): Promise<void>;
|
|
37
|
+
}
|