@arcadia-eternity/content-sdk 4.6.0 → 4.7.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 +2 -2
- package/dist/author-api.d.ts +12 -2
- package/dist/author-api.js +11 -2
- package/dist/author-git.d.ts +63 -0
- package/dist/author-git.js +324 -0
- package/dist/author-reference.d.ts +15 -1
- package/dist/author-reference.js +20 -1
- package/dist/cli.js +5 -4
- package/dist/content-query.d.ts +15 -1
- package/dist/content-query.js +53 -11
- package/dist/content-workspace.d.ts +423 -3
- package/dist/content-workspace.js +194 -51
- package/dist/debug-environments.d.ts +393 -25
- package/dist/debug-environments.js +3 -42
- package/dist/demo.js +1 -1
- package/dist/effect-declarations.d.ts +14 -0
- package/dist/effect-declarations.js +103 -0
- package/dist/environment-host-base.d.ts +175 -0
- package/dist/environment-host-base.js +86 -0
- package/dist/environment-member-transfer.d.ts +5 -0
- package/dist/environment-member-transfer.js +95 -0
- package/dist/environment-rules.d.ts +728 -3
- package/dist/environment-rules.js +158 -74
- package/dist/environment-sharing.d.ts +51 -0
- package/dist/environment-sharing.js +321 -0
- package/dist/environment.d.ts +2 -0
- package/dist/environment.js +32 -9
- package/dist/jobs.d.ts +5 -0
- package/dist/jobs.js +59 -10
- package/dist/learnsets.d.ts +47 -0
- package/dist/learnsets.js +124 -0
- package/dist/lib/content.d.ts +1 -1
- package/dist/lib/content.js +26 -2
- package/dist/lib/presentation.js +5 -11
- package/dist/managed-projects.d.ts +6 -0
- package/dist/managed-projects.js +137 -45
- package/dist/managed-sources.d.ts +17 -0
- package/dist/managed-sources.js +28 -10
- package/dist/mcp-contracts.d.ts +405 -4
- package/dist/mcp-contracts.js +3 -1
- package/dist/mcp.js +23 -1
- package/dist/pack-project.d.ts +2 -1
- package/dist/pack-project.js +40 -5
- package/dist/prepared-document.d.ts +476 -0
- package/dist/prepared-document.js +47 -0
- package/dist/preview.js +5 -5
- package/dist/project.d.ts +3 -1
- package/dist/project.js +47 -4
- package/dist/rule-composition.d.ts +290 -0
- package/dist/rule-composition.js +267 -0
- package/dist/template/.github/scripts/release-payload.mjs +91 -0
- package/dist/template/.github/scripts/release-test-npm.mjs +27 -0
- package/dist/template/.github/scripts/verify-release.mjs +138 -0
- package/dist/template/.github/workflows/release-pack.yml +77 -0
- package/dist/template/README.md +15 -2
- package/dist/template/gitignore-template +7 -0
- package/dist/template/npm-lock-template.json +2319 -0
- package/dist/template/package.json +4 -2
- package/dist/template/skills/arcadia-content-authoring/references/tool-workflows.md +1 -1
- package/dist/template/skills/arcadia-content-git/SKILL.md +14 -0
- package/dist/template/skills/arcadia-content-release/SKILL.md +29 -0
- package/dist/template/test/pack.test.mjs +24 -5
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +26 -7
- package/dist/workspace-cli.js +2 -2
- package/dist/workspace-materials.d.ts +4 -1
- package/dist/workspace-materials.js +8 -2
- package/dist/workspace.d.ts +11 -0
- package/dist/workspace.js +191 -31
- package/package.json +16 -4
- package/release-payload.mjs +91 -0
- package/release-test-npm.mjs +27 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import type { EnvironmentRules } from './debug-environments.js';
|
|
2
|
+
type ValidateRules = (raw: unknown) => EnvironmentRules;
|
|
3
|
+
export declare function composeRuleSets(input: unknown, definitions: readonly unknown[], validate: ValidateRules): {
|
|
4
|
+
rules: {
|
|
5
|
+
schemaVersion: 1 | 2;
|
|
6
|
+
constraints?: ({
|
|
7
|
+
id: string;
|
|
8
|
+
allOf: {
|
|
9
|
+
kind: "mark" | "skill" | "species";
|
|
10
|
+
ids: string[];
|
|
11
|
+
}[];
|
|
12
|
+
kind: "ban";
|
|
13
|
+
scope: "pet" | "team";
|
|
14
|
+
exceptWhen?: {
|
|
15
|
+
kind: "mark" | "skill" | "species";
|
|
16
|
+
ids: string[];
|
|
17
|
+
}[] | undefined;
|
|
18
|
+
exceptAny?: {
|
|
19
|
+
kind: "mark" | "skill" | "species";
|
|
20
|
+
ids: string[];
|
|
21
|
+
}[][] | undefined;
|
|
22
|
+
} | {
|
|
23
|
+
id: string;
|
|
24
|
+
allOf: {
|
|
25
|
+
kind: "mark" | "skill" | "species";
|
|
26
|
+
ids: string[];
|
|
27
|
+
}[];
|
|
28
|
+
kind: "memberLimit";
|
|
29
|
+
max: number;
|
|
30
|
+
})[] | undefined;
|
|
31
|
+
mechanics?: {
|
|
32
|
+
skillSlots?: {
|
|
33
|
+
normalMax: number;
|
|
34
|
+
climaxMax: number;
|
|
35
|
+
climaxMin?: number | undefined;
|
|
36
|
+
} | undefined;
|
|
37
|
+
individualValueDefault?: number | undefined;
|
|
38
|
+
individualValues?: {
|
|
39
|
+
max: number;
|
|
40
|
+
} | undefined;
|
|
41
|
+
allowFaintSwitch?: boolean | undefined;
|
|
42
|
+
inheritance?: {
|
|
43
|
+
eligible: "all" | "off" | "species" | string[];
|
|
44
|
+
pool?: {
|
|
45
|
+
mode: "append" | "fallback" | "replace";
|
|
46
|
+
skills: string[];
|
|
47
|
+
} | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
enhancement?: {
|
|
50
|
+
mode: "active" | "forbidden" | "suppressed";
|
|
51
|
+
stages?: string[] | undefined;
|
|
52
|
+
species?: string[] | undefined;
|
|
53
|
+
} | undefined;
|
|
54
|
+
secondGenerationNatures?: "all" | "off" | "species" | string[] | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
skillParameters?: {
|
|
57
|
+
profile?: string | undefined;
|
|
58
|
+
groups?: Record<string, number> | undefined;
|
|
59
|
+
overrides?: {
|
|
60
|
+
skill: string;
|
|
61
|
+
useId: string;
|
|
62
|
+
parameter: string;
|
|
63
|
+
value: number;
|
|
64
|
+
}[] | undefined;
|
|
65
|
+
} | undefined;
|
|
66
|
+
matchups?: {
|
|
67
|
+
table?: string | undefined;
|
|
68
|
+
adjustments?: {
|
|
69
|
+
attack: string;
|
|
70
|
+
defense: string;
|
|
71
|
+
multiplier: number;
|
|
72
|
+
}[] | undefined;
|
|
73
|
+
} | undefined;
|
|
74
|
+
learnsetAdjustments?: {
|
|
75
|
+
species: string;
|
|
76
|
+
source: "inherited" | "normal";
|
|
77
|
+
skill: string;
|
|
78
|
+
action: "add" | "remove";
|
|
79
|
+
level?: number | undefined;
|
|
80
|
+
}[] | undefined;
|
|
81
|
+
tier?: "standard" | undefined;
|
|
82
|
+
allow?: {
|
|
83
|
+
species?: string[] | undefined;
|
|
84
|
+
skills?: string[] | undefined;
|
|
85
|
+
marks?: string[] | undefined;
|
|
86
|
+
} | undefined;
|
|
87
|
+
deny?: {
|
|
88
|
+
species?: string[] | undefined;
|
|
89
|
+
skills?: string[] | undefined;
|
|
90
|
+
marks?: string[] | undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
team?: {
|
|
93
|
+
minSize?: number | undefined;
|
|
94
|
+
maxSize?: number | undefined;
|
|
95
|
+
uniqueSpecies?: boolean | undefined;
|
|
96
|
+
} | undefined;
|
|
97
|
+
};
|
|
98
|
+
declarations: {
|
|
99
|
+
constraints: ({
|
|
100
|
+
id: string;
|
|
101
|
+
allOf: {
|
|
102
|
+
kind: "mark" | "skill" | "species";
|
|
103
|
+
ids: string[];
|
|
104
|
+
fromCollections?: string[] | undefined;
|
|
105
|
+
}[];
|
|
106
|
+
kind: "ban";
|
|
107
|
+
scope: "pet" | "team";
|
|
108
|
+
exceptWhen?: {
|
|
109
|
+
kind: "mark" | "skill" | "species";
|
|
110
|
+
ids: string[];
|
|
111
|
+
fromCollections?: string[] | undefined;
|
|
112
|
+
}[] | undefined;
|
|
113
|
+
exceptAny?: {
|
|
114
|
+
kind: "mark" | "skill" | "species";
|
|
115
|
+
ids: string[];
|
|
116
|
+
fromCollections?: string[] | undefined;
|
|
117
|
+
}[][] | undefined;
|
|
118
|
+
} | {
|
|
119
|
+
id: string;
|
|
120
|
+
allOf: {
|
|
121
|
+
kind: "mark" | "skill" | "species";
|
|
122
|
+
ids: string[];
|
|
123
|
+
fromCollections?: string[] | undefined;
|
|
124
|
+
}[];
|
|
125
|
+
kind: "memberLimit";
|
|
126
|
+
max: number;
|
|
127
|
+
})[];
|
|
128
|
+
collections: {
|
|
129
|
+
id: string;
|
|
130
|
+
kind: "mark" | "skill" | "species";
|
|
131
|
+
ids: string[];
|
|
132
|
+
}[];
|
|
133
|
+
};
|
|
134
|
+
fields: {
|
|
135
|
+
path: string[];
|
|
136
|
+
value: unknown;
|
|
137
|
+
sources: string[];
|
|
138
|
+
effectiveSources: string[];
|
|
139
|
+
}[];
|
|
140
|
+
ruleSets: {
|
|
141
|
+
id: string;
|
|
142
|
+
name: string;
|
|
143
|
+
rules: {
|
|
144
|
+
schemaVersion: 1 | 2;
|
|
145
|
+
mechanics?: {
|
|
146
|
+
skillSlots?: {
|
|
147
|
+
normalMax: number;
|
|
148
|
+
climaxMax: number;
|
|
149
|
+
climaxMin?: number | undefined;
|
|
150
|
+
} | undefined;
|
|
151
|
+
individualValueDefault?: number | undefined;
|
|
152
|
+
individualValues?: {
|
|
153
|
+
max: number;
|
|
154
|
+
} | undefined;
|
|
155
|
+
allowFaintSwitch?: boolean | undefined;
|
|
156
|
+
inheritance?: {
|
|
157
|
+
eligible: "all" | "off" | "species" | string[];
|
|
158
|
+
pool?: {
|
|
159
|
+
mode: "append" | "fallback" | "replace";
|
|
160
|
+
skills: string[];
|
|
161
|
+
} | undefined;
|
|
162
|
+
} | undefined;
|
|
163
|
+
enhancement?: {
|
|
164
|
+
mode: "active" | "forbidden" | "suppressed";
|
|
165
|
+
stages?: string[] | undefined;
|
|
166
|
+
species?: string[] | undefined;
|
|
167
|
+
} | undefined;
|
|
168
|
+
secondGenerationNatures?: "all" | "off" | "species" | string[] | undefined;
|
|
169
|
+
} | undefined;
|
|
170
|
+
skillParameters?: {
|
|
171
|
+
profile?: string | undefined;
|
|
172
|
+
groups?: Record<string, number> | undefined;
|
|
173
|
+
overrides?: {
|
|
174
|
+
skill: string;
|
|
175
|
+
useId: string;
|
|
176
|
+
parameter: string;
|
|
177
|
+
value: number;
|
|
178
|
+
}[] | undefined;
|
|
179
|
+
} | undefined;
|
|
180
|
+
matchups?: {
|
|
181
|
+
table?: string | undefined;
|
|
182
|
+
adjustments?: {
|
|
183
|
+
attack: string;
|
|
184
|
+
defense: string;
|
|
185
|
+
multiplier: number;
|
|
186
|
+
}[] | undefined;
|
|
187
|
+
} | undefined;
|
|
188
|
+
learnsetAdjustments?: {
|
|
189
|
+
species: string;
|
|
190
|
+
source: "inherited" | "normal";
|
|
191
|
+
skill: string;
|
|
192
|
+
action: "add" | "remove";
|
|
193
|
+
level?: number | undefined;
|
|
194
|
+
}[] | undefined;
|
|
195
|
+
tier?: "standard" | undefined;
|
|
196
|
+
allow?: {
|
|
197
|
+
species?: string[] | undefined;
|
|
198
|
+
skills?: string[] | undefined;
|
|
199
|
+
marks?: string[] | undefined;
|
|
200
|
+
} | undefined;
|
|
201
|
+
deny?: {
|
|
202
|
+
species?: string[] | undefined;
|
|
203
|
+
skills?: string[] | undefined;
|
|
204
|
+
marks?: string[] | undefined;
|
|
205
|
+
} | undefined;
|
|
206
|
+
team?: {
|
|
207
|
+
minSize?: number | undefined;
|
|
208
|
+
maxSize?: number | undefined;
|
|
209
|
+
uniqueSpecies?: boolean | undefined;
|
|
210
|
+
} | undefined;
|
|
211
|
+
constraints?: ({
|
|
212
|
+
id: string;
|
|
213
|
+
allOf: {
|
|
214
|
+
kind: "mark" | "skill" | "species";
|
|
215
|
+
ids: string[];
|
|
216
|
+
fromCollections?: string[] | undefined;
|
|
217
|
+
}[];
|
|
218
|
+
kind: "ban";
|
|
219
|
+
scope: "pet" | "team";
|
|
220
|
+
exceptWhen?: {
|
|
221
|
+
kind: "mark" | "skill" | "species";
|
|
222
|
+
ids: string[];
|
|
223
|
+
fromCollections?: string[] | undefined;
|
|
224
|
+
}[] | undefined;
|
|
225
|
+
exceptAny?: {
|
|
226
|
+
kind: "mark" | "skill" | "species";
|
|
227
|
+
ids: string[];
|
|
228
|
+
fromCollections?: string[] | undefined;
|
|
229
|
+
}[][] | undefined;
|
|
230
|
+
} | {
|
|
231
|
+
id: string;
|
|
232
|
+
allOf: {
|
|
233
|
+
kind: "mark" | "skill" | "species";
|
|
234
|
+
ids: string[];
|
|
235
|
+
fromCollections?: string[] | undefined;
|
|
236
|
+
}[];
|
|
237
|
+
kind: "memberLimit";
|
|
238
|
+
max: number;
|
|
239
|
+
})[] | undefined;
|
|
240
|
+
collections?: {
|
|
241
|
+
id: string;
|
|
242
|
+
kind: "mark" | "skill" | "species";
|
|
243
|
+
ids: string[];
|
|
244
|
+
}[] | undefined;
|
|
245
|
+
include?: string[] | undefined;
|
|
246
|
+
constraintEdits?: {
|
|
247
|
+
remove?: string[] | undefined;
|
|
248
|
+
replace?: ({
|
|
249
|
+
id: string;
|
|
250
|
+
allOf: {
|
|
251
|
+
kind: "mark" | "skill" | "species";
|
|
252
|
+
ids: string[];
|
|
253
|
+
fromCollections?: string[] | undefined;
|
|
254
|
+
}[];
|
|
255
|
+
kind: "ban";
|
|
256
|
+
scope: "pet" | "team";
|
|
257
|
+
exceptWhen?: {
|
|
258
|
+
kind: "mark" | "skill" | "species";
|
|
259
|
+
ids: string[];
|
|
260
|
+
fromCollections?: string[] | undefined;
|
|
261
|
+
}[] | undefined;
|
|
262
|
+
exceptAny?: {
|
|
263
|
+
kind: "mark" | "skill" | "species";
|
|
264
|
+
ids: string[];
|
|
265
|
+
fromCollections?: string[] | undefined;
|
|
266
|
+
}[][] | undefined;
|
|
267
|
+
} | {
|
|
268
|
+
id: string;
|
|
269
|
+
allOf: {
|
|
270
|
+
kind: "mark" | "skill" | "species";
|
|
271
|
+
ids: string[];
|
|
272
|
+
fromCollections?: string[] | undefined;
|
|
273
|
+
}[];
|
|
274
|
+
kind: "memberLimit";
|
|
275
|
+
max: number;
|
|
276
|
+
})[] | undefined;
|
|
277
|
+
clearExceptions?: string[] | undefined;
|
|
278
|
+
exceptions?: {
|
|
279
|
+
target: string;
|
|
280
|
+
allOf: {
|
|
281
|
+
kind: "mark" | "skill" | "species";
|
|
282
|
+
ids: string[];
|
|
283
|
+
fromCollections?: string[] | undefined;
|
|
284
|
+
}[];
|
|
285
|
+
}[] | undefined;
|
|
286
|
+
} | undefined;
|
|
287
|
+
};
|
|
288
|
+
}[];
|
|
289
|
+
};
|
|
290
|
+
export {};
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { readEnvironmentRuleSets, resolveEnhancement, splitRuleDeclaration, RuleCompositionError, } from '@arcadia-eternity/const';
|
|
2
|
+
import { isRecord } from './types.js';
|
|
3
|
+
function issue(code, detail) {
|
|
4
|
+
throw new RuleCompositionError(code, detail);
|
|
5
|
+
}
|
|
6
|
+
// Arrays that describe eligibility or a selector are sets. Domain records with several
|
|
7
|
+
// independently editable entries (matchups, bindings, learnsets) get one address per entry.
|
|
8
|
+
function canonical(value) {
|
|
9
|
+
if (Array.isArray(value))
|
|
10
|
+
return '[' + value.map(canonical).sort().join(',') + ']';
|
|
11
|
+
if (!isRecord(value))
|
|
12
|
+
return JSON.stringify(value);
|
|
13
|
+
return ('{' +
|
|
14
|
+
Object.keys(value)
|
|
15
|
+
.sort()
|
|
16
|
+
.map(key => JSON.stringify(key) + ':' + canonical(value[key]))
|
|
17
|
+
.join(',') +
|
|
18
|
+
'}');
|
|
19
|
+
}
|
|
20
|
+
function entries(rules) {
|
|
21
|
+
const out = [];
|
|
22
|
+
const add = (path, value) => out.push({ path, value });
|
|
23
|
+
for (const section of ['mechanics', 'allow', 'deny', 'team'])
|
|
24
|
+
for (const [key, value] of Object.entries(rules[section] ?? {}))
|
|
25
|
+
add([section, key], section === 'mechanics' && key === 'enhancement' ? resolveEnhancement(rules.mechanics?.enhancement) : value);
|
|
26
|
+
if (rules.tier !== undefined)
|
|
27
|
+
add(['tier'], rules.tier);
|
|
28
|
+
for (const row of rules.constraints ?? [])
|
|
29
|
+
add(['constraints', row.id], row);
|
|
30
|
+
for (const row of rules.learnsetAdjustments ?? [])
|
|
31
|
+
add(['learnsetAdjustments', row.species, row.source, row.skill], row);
|
|
32
|
+
const matchups = rules.matchups;
|
|
33
|
+
if (matchups?.table !== undefined)
|
|
34
|
+
add(['matchups', 'table'], matchups.table);
|
|
35
|
+
for (const row of matchups?.adjustments ?? [])
|
|
36
|
+
add(['matchups', 'adjustments', row.attack, row.defense], row);
|
|
37
|
+
const parameters = rules.skillParameters;
|
|
38
|
+
if (parameters?.profile !== undefined)
|
|
39
|
+
add(['skillParameters', 'profile'], parameters.profile);
|
|
40
|
+
for (const [key, value] of Object.entries(parameters?.groups ?? {}))
|
|
41
|
+
add(['skillParameters', 'groups', key], value);
|
|
42
|
+
for (const row of parameters?.overrides ?? [])
|
|
43
|
+
add(['skillParameters', 'overrides', row.skill, row.useId, row.parameter], row);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
function merge(fields, path, choice, sources, replace = false) {
|
|
47
|
+
const key = JSON.stringify(path);
|
|
48
|
+
let field = fields.get(key);
|
|
49
|
+
if (!field) {
|
|
50
|
+
field = { path, choices: new Map(), sources: new Set() };
|
|
51
|
+
fields.set(key, field);
|
|
52
|
+
}
|
|
53
|
+
if (replace)
|
|
54
|
+
field.choices.clear();
|
|
55
|
+
for (const source of sources)
|
|
56
|
+
field.sources.add(source);
|
|
57
|
+
const identity = canonical(choice.value);
|
|
58
|
+
const previous = field.choices.get(identity);
|
|
59
|
+
if (previous) {
|
|
60
|
+
for (const source of choice.sources)
|
|
61
|
+
previous.sources.add(source);
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
field.choices.set(identity, { value: choice.value, sources: new Set(choice.sources) });
|
|
65
|
+
}
|
|
66
|
+
function effective(field) {
|
|
67
|
+
const [section, key] = field.path;
|
|
68
|
+
const values = Array.from(field.choices.values(), choice => choice.value);
|
|
69
|
+
if (section === 'allow' || section === 'deny') {
|
|
70
|
+
const sets = values.map(list => new Set(list));
|
|
71
|
+
const result = section === 'allow'
|
|
72
|
+
? [...sets[0]].filter(id => sets.every(set => set.has(id)))
|
|
73
|
+
: Array.from(new Set(sets.flatMap(set => [...set])));
|
|
74
|
+
return result.sort();
|
|
75
|
+
}
|
|
76
|
+
if (section === 'team') {
|
|
77
|
+
if (key === 'uniqueSpecies')
|
|
78
|
+
return values.includes(true);
|
|
79
|
+
return key === 'minSize' ? Math.max(...values) : Math.min(...values);
|
|
80
|
+
}
|
|
81
|
+
if (values.length === 1)
|
|
82
|
+
return values[0];
|
|
83
|
+
if (section === 'mechanics' &&
|
|
84
|
+
key === 'enhancement' &&
|
|
85
|
+
values.every(value => isRecord(value) && value.mode === 'suppressed'))
|
|
86
|
+
return { mode: 'suppressed' };
|
|
87
|
+
const contenders = [...field.choices.values()].map(choice => [...choice.sources].sort().join(', ') + ' = ' + canonical(choice.value));
|
|
88
|
+
issue('ENVIRONMENT_RULE_CONFLICT', field.path.join(' / ') + ' (' + contenders.sort().join(' | ') + ')');
|
|
89
|
+
}
|
|
90
|
+
function writeField(result, path, value) {
|
|
91
|
+
const [section, key] = path;
|
|
92
|
+
if (path.length === 1) {
|
|
93
|
+
result[section] = value;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (section === 'constraints' || section === 'learnsetAdjustments') {
|
|
97
|
+
const rows = (result[section] ??= []);
|
|
98
|
+
rows.push(value);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const group = (result[section] ??= Object.create(null));
|
|
102
|
+
if (path.length === 2)
|
|
103
|
+
group[key] = value;
|
|
104
|
+
else if (key === 'groups') {
|
|
105
|
+
const groups = (group.groups ??= Object.create(null));
|
|
106
|
+
groups[path[2]] = value;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const rows = (group[key] ??= []);
|
|
110
|
+
rows.push(value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function applyConstraintEdits(fields, source, edits, local = []) {
|
|
114
|
+
const put = (id, value) => merge(fields, ['constraints', id], { value, sources: new Set([source]) }, [source], true);
|
|
115
|
+
const lookup = (id) => fields.get(JSON.stringify(['constraints', id]));
|
|
116
|
+
const requireField = (id) => {
|
|
117
|
+
const field = lookup(id);
|
|
118
|
+
if (!field || [...field.choices.values()].every(choice => choice.value === null))
|
|
119
|
+
issue('ENVIRONMENT_RULE_TARGET_MISSING', source + ' / ' + id);
|
|
120
|
+
return field;
|
|
121
|
+
};
|
|
122
|
+
const clears = new Set(edits.clearExceptions);
|
|
123
|
+
const changed = new Set();
|
|
124
|
+
for (const { id, value } of [
|
|
125
|
+
...(edits.remove ?? []).map(id => ({ id, value: null })),
|
|
126
|
+
...(edits.replace ?? []).map(value => ({ id: value.id, value })),
|
|
127
|
+
]) {
|
|
128
|
+
if (changed.has(id))
|
|
129
|
+
issue('ENVIRONMENT_RULE_EDIT_CONFLICT', source + ' / ' + id);
|
|
130
|
+
changed.add(id);
|
|
131
|
+
const field = requireField(id);
|
|
132
|
+
const hasExceptions = [...field.choices.values()].some(choice => {
|
|
133
|
+
const rule = choice.value;
|
|
134
|
+
return rule?.kind === 'ban' && (rule.exceptWhen?.length || rule.exceptAny?.length);
|
|
135
|
+
});
|
|
136
|
+
if (hasExceptions && !clears.has(id))
|
|
137
|
+
issue('ENVIRONMENT_RULE_EXCEPTION_DANGLING', source + ' / ' + id);
|
|
138
|
+
put(id, value);
|
|
139
|
+
}
|
|
140
|
+
for (const id of clears) {
|
|
141
|
+
if (changed.has(id))
|
|
142
|
+
continue;
|
|
143
|
+
const row = effective(requireField(id));
|
|
144
|
+
if (row.kind !== 'ban' || (!row.exceptWhen && !row.exceptAny))
|
|
145
|
+
issue('ENVIRONMENT_RULE_TARGET_MISSING', source + ' / ' + id);
|
|
146
|
+
const { exceptWhen: _old, exceptAny: _others, ...clean } = row;
|
|
147
|
+
put(id, clean);
|
|
148
|
+
}
|
|
149
|
+
for (const row of local) {
|
|
150
|
+
const prior = lookup(row.id);
|
|
151
|
+
if (prior && [...prior.choices.values()].some(choice => choice.value !== null))
|
|
152
|
+
issue('ENVIRONMENT_RULE_ALREADY_EXISTS', source + ' / ' + row.id);
|
|
153
|
+
put(row.id, row);
|
|
154
|
+
}
|
|
155
|
+
for (const exception of edits.exceptions ?? []) {
|
|
156
|
+
const field = requireField(exception.target);
|
|
157
|
+
const row = effective(field);
|
|
158
|
+
if (row.kind !== 'ban')
|
|
159
|
+
issue('ENVIRONMENT_RULE_EXCEPTION_INVALID', source + ' / ' + row.id);
|
|
160
|
+
const clauses = row.exceptAny ?? [];
|
|
161
|
+
if (!clauses.some(clause => canonical(clause) === canonical(exception.allOf)))
|
|
162
|
+
put(row.id, { ...row, exceptAny: [...clauses, exception.allOf] });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export function composeRuleSets(input, definitions, validate) {
|
|
166
|
+
const root = splitRuleDeclaration(input);
|
|
167
|
+
const ruleSets = readEnvironmentRuleSets(definitions);
|
|
168
|
+
const catalog = new Map(ruleSets.map(row => [row.id, row.rules]));
|
|
169
|
+
const done = new Map();
|
|
170
|
+
const stack = new Set();
|
|
171
|
+
function visit(id) {
|
|
172
|
+
if (stack.has(id))
|
|
173
|
+
issue('ENVIRONMENT_RULE_CYCLE', [...stack, id].join(' → '));
|
|
174
|
+
const cached = done.get(id);
|
|
175
|
+
if (cached)
|
|
176
|
+
return cached;
|
|
177
|
+
if (!catalog.has(id))
|
|
178
|
+
issue('ENVIRONMENT_RULE_SET_MISSING', [...stack, id].join(' → '));
|
|
179
|
+
if (stack.size >= 128)
|
|
180
|
+
issue('ENVIRONMENT_RULES_INVALID', '规则集引用超过 128 层');
|
|
181
|
+
stack.add(id);
|
|
182
|
+
const fields = combine(id, splitRuleDeclaration(catalog.get(id)));
|
|
183
|
+
stack.delete(id);
|
|
184
|
+
done.set(id, fields);
|
|
185
|
+
return fields;
|
|
186
|
+
}
|
|
187
|
+
function combine(source, declaration) {
|
|
188
|
+
const fields = new Map();
|
|
189
|
+
for (const id of [...declaration.include].sort())
|
|
190
|
+
for (const field of visit(id).values())
|
|
191
|
+
for (const choice of field.choices.values())
|
|
192
|
+
merge(fields, field.path, choice, field.sources);
|
|
193
|
+
for (const collection of declaration.collections)
|
|
194
|
+
merge(fields, ['collections', collection.id], { value: collection, sources: new Set([source]) }, [source], true);
|
|
195
|
+
applyConstraintEdits(fields, source, declaration.edits, declaration.rules.constraints);
|
|
196
|
+
const own = new Set();
|
|
197
|
+
for (const { path, value } of entries(declaration.rules)) {
|
|
198
|
+
if (path[0] === 'constraints')
|
|
199
|
+
continue;
|
|
200
|
+
const key = JSON.stringify(path);
|
|
201
|
+
if (own.has(key))
|
|
202
|
+
issue('ENVIRONMENT_RULES_INVALID', source + ' / ' + path.join(' / '));
|
|
203
|
+
own.add(key);
|
|
204
|
+
merge(fields, path, { value, sources: new Set([source]) }, [source], true);
|
|
205
|
+
}
|
|
206
|
+
return fields;
|
|
207
|
+
}
|
|
208
|
+
const fields = combine('$environment', root);
|
|
209
|
+
const collections = new Map();
|
|
210
|
+
for (const field of fields.values())
|
|
211
|
+
if (field.path[0] === 'collections')
|
|
212
|
+
collections.set(field.path[1], effective(field));
|
|
213
|
+
function expandConstraint(row) {
|
|
214
|
+
const expand = (selector) => {
|
|
215
|
+
const ids = new Set(selector.ids);
|
|
216
|
+
for (const id of selector.fromCollections ?? []) {
|
|
217
|
+
const collection = collections.get(id);
|
|
218
|
+
if (!collection)
|
|
219
|
+
issue('ENVIRONMENT_COLLECTION_MISSING', row.id + ' / ' + id);
|
|
220
|
+
if (collection.kind !== selector.kind)
|
|
221
|
+
issue('ENVIRONMENT_COLLECTION_KIND', row.id + ' / ' + id);
|
|
222
|
+
for (const member of collection.ids)
|
|
223
|
+
ids.add(member);
|
|
224
|
+
}
|
|
225
|
+
return { kind: selector.kind, ids: [...ids].sort() };
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
...row,
|
|
229
|
+
allOf: row.allOf.map(expand),
|
|
230
|
+
...(row.kind === 'ban' && {
|
|
231
|
+
...(row.exceptWhen && { exceptWhen: row.exceptWhen.map(expand) }),
|
|
232
|
+
...(row.exceptAny && { exceptAny: row.exceptAny.map(clause => clause.map(expand)) }),
|
|
233
|
+
}),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const constraintDeclarations = [];
|
|
237
|
+
const fieldsWithSources = [];
|
|
238
|
+
const result = { schemaVersion: root.rules.schemaVersion };
|
|
239
|
+
for (const key of [...fields.keys()].sort()) {
|
|
240
|
+
const field = fields.get(key);
|
|
241
|
+
const raw = effective(field);
|
|
242
|
+
let value = raw;
|
|
243
|
+
if (raw && field.path[0] === 'constraints') {
|
|
244
|
+
const declaration = raw;
|
|
245
|
+
constraintDeclarations.push(declaration);
|
|
246
|
+
value = expandConstraint(declaration);
|
|
247
|
+
}
|
|
248
|
+
if (field.path[0] !== 'collections' && !(field.path[0] === 'constraints' && value === null))
|
|
249
|
+
writeField(result, field.path, value);
|
|
250
|
+
const effectiveSources = new Set([...field.choices.values()].flatMap(choice => [...choice.sources]));
|
|
251
|
+
fieldsWithSources.push({
|
|
252
|
+
path: [...field.path],
|
|
253
|
+
value,
|
|
254
|
+
sources: [...field.sources].sort(),
|
|
255
|
+
effectiveSources: [...effectiveSources].sort(),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
// Existing documents retain their original representation and revision.
|
|
259
|
+
return {
|
|
260
|
+
rules: root.include.length || root.collections.length || root.rules.constraints?.length || Object.keys(root.edits).length
|
|
261
|
+
? validate(result)
|
|
262
|
+
: root.rules,
|
|
263
|
+
declarations: { constraints: constraintDeclarations, collections: [...collections.values()] },
|
|
264
|
+
fields: fieldsWithSources,
|
|
265
|
+
ruleSets,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Shared by the desktop packer and the content template's Actions workflow.
|
|
2
|
+
import { createHash } from 'node:crypto'
|
|
3
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { gunzipSync } from 'node:zlib'
|
|
5
|
+
import { gzipSync } from 'fflate'
|
|
6
|
+
import { createRequire } from 'node:module'
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
const sdkRequire = createRequire(require.resolve('@arcadia-eternity/content-sdk'))
|
|
9
|
+
const { valid, validRange } = sdkRequire('semver')
|
|
10
|
+
|
|
11
|
+
export function releasePayload(source, included, presentation) {
|
|
12
|
+
if (!source.arcadia?.projectId || !source.arcadia.namespace || !source.arcadia.content || !valid(source.version))
|
|
13
|
+
throw Error('发行包需要有效版本、projectId、namespace 和内容入口')
|
|
14
|
+
if (typeof source.license !== 'string' || !source.license.trim()) throw Error('请先设置 package.json 的 license')
|
|
15
|
+
const fields = [
|
|
16
|
+
'name',
|
|
17
|
+
'version',
|
|
18
|
+
'description',
|
|
19
|
+
'license',
|
|
20
|
+
'type',
|
|
21
|
+
'engines',
|
|
22
|
+
'arcadia',
|
|
23
|
+
'dependencies',
|
|
24
|
+
'optionalDependencies',
|
|
25
|
+
'peerDependencies',
|
|
26
|
+
'peerDependenciesMeta',
|
|
27
|
+
]
|
|
28
|
+
for (const key of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
29
|
+
const ranges = source[key]
|
|
30
|
+
if (
|
|
31
|
+
ranges !== undefined &&
|
|
32
|
+
(!ranges ||
|
|
33
|
+
typeof ranges !== 'object' ||
|
|
34
|
+
Array.isArray(ranges) ||
|
|
35
|
+
Object.values(ranges).some(range => typeof range !== 'string' || !range.trim() || !validRange(range)))
|
|
36
|
+
)
|
|
37
|
+
throw Error('发行包的 ' + key + ' 必须使用 npm 版本或范围')
|
|
38
|
+
}
|
|
39
|
+
const manifest = Object.fromEntries(
|
|
40
|
+
fields.filter(key => Object.hasOwn(source, key)).map(key => [key, structuredClone(source[key])]),
|
|
41
|
+
)
|
|
42
|
+
const repository = typeof source.repository === 'object' ? source.repository?.url : source.repository
|
|
43
|
+
if (typeof repository === 'string' && /^(?:git\+)?https:\/\//.test(repository)) {
|
|
44
|
+
const url = new URL(repository.replace(/^git\+/, ''))
|
|
45
|
+
if (url.username || url.password || url.search || url.hash) throw Error('发行仓库地址不能包含凭据、查询参数或片段')
|
|
46
|
+
manifest.repository = { type: 'git', url: 'git+' + url.href }
|
|
47
|
+
}
|
|
48
|
+
const { arcadia } = manifest
|
|
49
|
+
if (arcadia.effects) arcadia.effectArtifact = 'dist/arcadia-effects.json'
|
|
50
|
+
delete arcadia.effects
|
|
51
|
+
delete arcadia.effectSources
|
|
52
|
+
const files = new Set(
|
|
53
|
+
[...included].filter(file => /^(?:package\.json|readme(?:\..+)?|licen[cs]e(?:\..+)?|notice(?:\..+)?)$/i.test(file)),
|
|
54
|
+
)
|
|
55
|
+
for (const file of [
|
|
56
|
+
arcadia.content,
|
|
57
|
+
arcadia.presentation,
|
|
58
|
+
arcadia.catalog,
|
|
59
|
+
arcadia.effectArtifact,
|
|
60
|
+
...Object.values(arcadia.assets ?? {}),
|
|
61
|
+
...(presentation?.resources ?? []).filter(resource => resource.kind === 'file').map(resource => resource.source),
|
|
62
|
+
])
|
|
63
|
+
if (typeof file === 'string') files.add(file)
|
|
64
|
+
if (![...files].some(file => /^licen[cs]e(?:\.(?:md|txt))?$/i.test(file))) throw Error('发行包缺少 LICENSE 文件')
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
if (
|
|
67
|
+
!file ||
|
|
68
|
+
/[\\:\p{Cc}]/u.test(file) ||
|
|
69
|
+
file
|
|
70
|
+
.split('/')
|
|
71
|
+
.some(part => !part || part.startsWith('.') || /^(?:src|tests?|scripts|debug|node_modules)$/i.test(part)) ||
|
|
72
|
+
/(?:\.(?:[cm]?[jt]sx?|map|pem|key|p12|pfx)|(?:^|\/)tsconfig[^/]*\.json)$/i.test(file)
|
|
73
|
+
)
|
|
74
|
+
throw Error('发行清单含开发文件或私密文件: ' + file)
|
|
75
|
+
}
|
|
76
|
+
manifest.files = [...files].sort()
|
|
77
|
+
return manifest
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// npm creates a portable tar stream, but native zlib versions can encode it
|
|
81
|
+
// differently. Use the same pinned compressor for desktop and hosted builds.
|
|
82
|
+
export async function normalizeReleaseArchive(path) {
|
|
83
|
+
const tar = gunzipSync(await readFile(path), { maxOutputLength: 256 * 1024 * 1024 })
|
|
84
|
+
const bytes = gzipSync(tar, { level: 9, mtime: 0 })
|
|
85
|
+
await writeFile(path, bytes)
|
|
86
|
+
return {
|
|
87
|
+
integrity: 'sha512-' + createHash('sha512').update(bytes).digest('base64'),
|
|
88
|
+
shasum: createHash('sha1').update(bytes).digest('hex'),
|
|
89
|
+
size: bytes.length,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SDK 4.6 requests "npm pack" in the scenario directory. Give npm the verified
|
|
2
|
+
// archive as its explicit input. All installs and dependency packs still use npm.
|
|
3
|
+
import { spawnSync } from 'node:child_process'
|
|
4
|
+
import { realpathSync } from 'node:fs'
|
|
5
|
+
import { createRequire } from 'node:module'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { pathToFileURL } from 'node:url'
|
|
8
|
+
|
|
9
|
+
const args = process.argv.slice(2)
|
|
10
|
+
const filename = process.env.ARCADIA_TEST_RELEASE_ARCHIVE
|
|
11
|
+
if (
|
|
12
|
+
args[0] === 'pack' &&
|
|
13
|
+
args[1] === '--json' &&
|
|
14
|
+
filename &&
|
|
15
|
+
/^[a-z0-9][a-z0-9._-]*\.tgz$/.test(filename) &&
|
|
16
|
+
realpathSync(process.cwd()) === realpathSync(process.env.ARCADIA_TEST_RELEASE_ROOT)
|
|
17
|
+
)
|
|
18
|
+
args.splice(1, 0, join(process.cwd(), filename))
|
|
19
|
+
if (process.env.ARCADIA_TEST_BASE_NPM) process.env.ARCADIA_NPM_CLI = process.env.ARCADIA_TEST_BASE_NPM
|
|
20
|
+
else delete process.env.ARCADIA_NPM_CLI
|
|
21
|
+
const require = createRequire(import.meta.url)
|
|
22
|
+
const sdk = createRequire(require.resolve('@arcadia-eternity/content-sdk'))
|
|
23
|
+
const { resolveNpmInvocation } = await import(pathToFileURL(sdk.resolve('@arcadia-eternity/pack-loader/node')).href)
|
|
24
|
+
const command = await resolveNpmInvocation(args)
|
|
25
|
+
const result = spawnSync(command.file, command.args, { stdio: 'inherit', windowsHide: true })
|
|
26
|
+
if (result.error) throw result.error
|
|
27
|
+
process.exitCode = result.status ?? 1
|