@arcadia-eternity/content-sdk 4.3.4 → 4.4.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 +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 +204 -0
- package/dist/content-workspace.js +981 -0
- package/dist/debug-environments.d.ts +96 -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 +10 -0
- package/dist/pack-project.js +178 -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,96 @@
|
|
|
1
|
+
import { type AuthorWorkspace } from './workspace.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const EnvironmentDocumentV2Schema: z.ZodObject<{
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
7
|
+
sources: z.ZodArray<z.ZodString>;
|
|
8
|
+
schemaVersion: z.ZodLiteral<2>;
|
|
9
|
+
disabled: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
11
|
+
sources: z.ZodArray<z.ZodString>;
|
|
12
|
+
}, z.core.$strict>>;
|
|
13
|
+
rules: z.ZodObject<{
|
|
14
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
15
|
+
tier: z.ZodOptional<z.ZodString>;
|
|
16
|
+
allow: z.ZodOptional<z.ZodObject<{
|
|
17
|
+
species: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
18
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
|
+
marks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
|
+
}, z.core.$strict>>;
|
|
21
|
+
deny: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
species: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
|
+
marks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
}, z.core.$strict>>;
|
|
26
|
+
team: z.ZodOptional<z.ZodObject<{
|
|
27
|
+
minSize: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
maxSize: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
uniqueSpecies: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
}, z.core.$strict>>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
requires: z.ZodObject<{
|
|
33
|
+
engine: z.ZodOptional<z.ZodString>;
|
|
34
|
+
sdk: z.ZodOptional<z.ZodString>;
|
|
35
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
export declare const EnvironmentDocumentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
39
|
+
id: z.ZodString;
|
|
40
|
+
name: z.ZodString;
|
|
41
|
+
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
42
|
+
sources: z.ZodArray<z.ZodString>;
|
|
43
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
44
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
name: z.ZodString;
|
|
47
|
+
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
48
|
+
sources: z.ZodArray<z.ZodString>;
|
|
49
|
+
schemaVersion: z.ZodLiteral<2>;
|
|
50
|
+
disabled: z.ZodOptional<z.ZodObject<{
|
|
51
|
+
packages: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
52
|
+
sources: z.ZodArray<z.ZodString>;
|
|
53
|
+
}, z.core.$strict>>;
|
|
54
|
+
rules: z.ZodObject<{
|
|
55
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
56
|
+
tier: z.ZodOptional<z.ZodString>;
|
|
57
|
+
allow: z.ZodOptional<z.ZodObject<{
|
|
58
|
+
species: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
59
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
60
|
+
marks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
61
|
+
}, z.core.$strict>>;
|
|
62
|
+
deny: z.ZodOptional<z.ZodObject<{
|
|
63
|
+
species: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
64
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
65
|
+
marks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
66
|
+
}, z.core.$strict>>;
|
|
67
|
+
team: z.ZodOptional<z.ZodObject<{
|
|
68
|
+
minSize: z.ZodOptional<z.ZodNumber>;
|
|
69
|
+
maxSize: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
uniqueSpecies: z.ZodOptional<z.ZodBoolean>;
|
|
71
|
+
}, z.core.$strict>>;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
requires: z.ZodObject<{
|
|
74
|
+
engine: z.ZodOptional<z.ZodString>;
|
|
75
|
+
sdk: z.ZodOptional<z.ZodString>;
|
|
76
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
}, z.core.$strict>], "schemaVersion">;
|
|
79
|
+
export type EnvironmentDocument = z.infer<typeof EnvironmentDocumentSchema>;
|
|
80
|
+
export type EnvironmentDocumentV2 = z.infer<typeof EnvironmentDocumentV2Schema>;
|
|
81
|
+
export type ListedEnvironment = EnvironmentDocument & {
|
|
82
|
+
version: string | null;
|
|
83
|
+
};
|
|
84
|
+
export declare function environmentDocument(input: unknown): EnvironmentDocument;
|
|
85
|
+
/** Read legacy documents into the shared domain model without rewriting source files. */
|
|
86
|
+
export declare function normalizeEnvironmentDocument(value: unknown): EnvironmentDocumentV2;
|
|
87
|
+
export declare class DebugEnvironments {
|
|
88
|
+
workspace: AuthorWorkspace;
|
|
89
|
+
constructor(workspace: AuthorWorkspace);
|
|
90
|
+
file(id: string): string;
|
|
91
|
+
list(): Promise<ListedEnvironment[]>;
|
|
92
|
+
save({ document, expectedVersion, }: {
|
|
93
|
+
document: unknown;
|
|
94
|
+
expectedVersion: string | null;
|
|
95
|
+
}): Promise<ListedEnvironment>;
|
|
96
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { WorkspaceError } from './workspace.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const idPattern = /^[a-z0-9][a-z0-9_-]{0,79}$/;
|
|
4
|
+
const packagePattern = /^(?:@[a-z0-9_.-]+\/)?[a-z0-9][a-z0-9_.-]*$/;
|
|
5
|
+
function fail(message) {
|
|
6
|
+
throw new WorkspaceError('ENVIRONMENT_INVALID', message);
|
|
7
|
+
}
|
|
8
|
+
const sharedFields = {
|
|
9
|
+
id: z
|
|
10
|
+
.string()
|
|
11
|
+
.regex(idPattern)
|
|
12
|
+
.refine(value => value !== 'default', 'default 是内置环境'),
|
|
13
|
+
name: z
|
|
14
|
+
.string()
|
|
15
|
+
.min(1)
|
|
16
|
+
.max(80)
|
|
17
|
+
.refine(value => !!value.trim())
|
|
18
|
+
.overwrite(value => value.trim()),
|
|
19
|
+
packages: z.record(z.string().regex(packagePattern), z
|
|
20
|
+
.string()
|
|
21
|
+
.min(1)
|
|
22
|
+
.refine(value => !!value.trim() && !/(?:file:|link:|workspace:|\/|\\)/.test(value), '额外 npm 包需要可共享的注册表版本约束')),
|
|
23
|
+
sources: z
|
|
24
|
+
.array(z.string().regex(packagePattern))
|
|
25
|
+
.max(20)
|
|
26
|
+
.refine(value => new Set(value).size === value.length, '源码包标识不能重复'),
|
|
27
|
+
};
|
|
28
|
+
const reference = z
|
|
29
|
+
.string()
|
|
30
|
+
.min(1)
|
|
31
|
+
.max(256)
|
|
32
|
+
.regex(/^[a-zA-Z0-9_./:-]+$/);
|
|
33
|
+
const uniqueList = (schema) => z
|
|
34
|
+
.array(schema)
|
|
35
|
+
.max(10000)
|
|
36
|
+
.refine(value => new Set(value).size === value.length, '引用不能重复');
|
|
37
|
+
const contentSelection = z
|
|
38
|
+
.object({
|
|
39
|
+
species: uniqueList(reference).optional(),
|
|
40
|
+
skills: uniqueList(reference).optional(),
|
|
41
|
+
marks: uniqueList(reference).optional(),
|
|
42
|
+
})
|
|
43
|
+
.strict();
|
|
44
|
+
/** Portable rule data. Runtime consumers must explicitly support every declared capability. */
|
|
45
|
+
const EnvironmentRulesSchema = z
|
|
46
|
+
.object({
|
|
47
|
+
schemaVersion: z.literal(1),
|
|
48
|
+
tier: z.string().regex(idPattern).optional(),
|
|
49
|
+
allow: contentSelection.optional(),
|
|
50
|
+
deny: contentSelection.optional(),
|
|
51
|
+
team: z
|
|
52
|
+
.object({
|
|
53
|
+
minSize: z.number().int().min(1).max(100).optional(),
|
|
54
|
+
maxSize: z.number().int().min(1).max(100).optional(),
|
|
55
|
+
uniqueSpecies: z.boolean().optional(),
|
|
56
|
+
})
|
|
57
|
+
.strict()
|
|
58
|
+
.refine(value => value.minSize === undefined || value.maxSize === undefined || value.minSize <= value.maxSize, '队伍最小数量不能大于最大数量')
|
|
59
|
+
.optional(),
|
|
60
|
+
})
|
|
61
|
+
.strict();
|
|
62
|
+
const EnvironmentRequirementsSchema = z
|
|
63
|
+
.object({
|
|
64
|
+
engine: z.string().trim().min(1).max(128).optional(),
|
|
65
|
+
sdk: z.string().trim().min(1).max(128).optional(),
|
|
66
|
+
capabilities: uniqueList(z.string().regex(/^[a-zA-Z0-9_.:-]{1,128}$/)).optional(),
|
|
67
|
+
})
|
|
68
|
+
.strict();
|
|
69
|
+
const EnvironmentDocumentV1Schema = z.object({ schemaVersion: z.literal(1), ...sharedFields }).strict();
|
|
70
|
+
export const EnvironmentDocumentV2Schema = z
|
|
71
|
+
.object({
|
|
72
|
+
schemaVersion: z.literal(2),
|
|
73
|
+
...sharedFields,
|
|
74
|
+
disabled: z.object({ packages: sharedFields.packages, sources: sharedFields.sources }).strict().optional(),
|
|
75
|
+
rules: EnvironmentRulesSchema,
|
|
76
|
+
requires: EnvironmentRequirementsSchema,
|
|
77
|
+
})
|
|
78
|
+
.strict();
|
|
79
|
+
export const EnvironmentDocumentSchema = z.discriminatedUnion('schemaVersion', [
|
|
80
|
+
EnvironmentDocumentV1Schema,
|
|
81
|
+
EnvironmentDocumentV2Schema,
|
|
82
|
+
]);
|
|
83
|
+
export function environmentDocument(input) {
|
|
84
|
+
const parsed = EnvironmentDocumentSchema.safeParse(input);
|
|
85
|
+
if (!parsed.success)
|
|
86
|
+
fail(`环境配置无效:${parsed.error.issues[0]?.message ?? ''}`);
|
|
87
|
+
const value = parsed.data;
|
|
88
|
+
const disabled = value.schemaVersion === 2 ? value.disabled : undefined;
|
|
89
|
+
if (disabled &&
|
|
90
|
+
(Object.keys(disabled.packages).some(name => Object.hasOwn(value.packages, name) || value.sources.includes(name)) ||
|
|
91
|
+
disabled.sources.some(name => Object.hasOwn(value.packages, name) || value.sources.includes(name) || Object.hasOwn(disabled.packages, name))))
|
|
92
|
+
fail('启用和停用的资源包不能重复');
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
/** Read legacy documents into the shared domain model without rewriting source files. */
|
|
96
|
+
export function normalizeEnvironmentDocument(value) {
|
|
97
|
+
const document = environmentDocument(value);
|
|
98
|
+
if (document.schemaVersion === 2)
|
|
99
|
+
return document;
|
|
100
|
+
return { ...document, schemaVersion: 2, rules: { schemaVersion: 1 }, requires: {} };
|
|
101
|
+
}
|
|
102
|
+
export class DebugEnvironments {
|
|
103
|
+
workspace;
|
|
104
|
+
constructor(workspace) {
|
|
105
|
+
this.workspace = workspace;
|
|
106
|
+
}
|
|
107
|
+
file(id) {
|
|
108
|
+
if (typeof id !== 'string' || !idPattern.test(id) || id === 'default')
|
|
109
|
+
fail('环境标识无效');
|
|
110
|
+
return `debug/environments/${id}.json`;
|
|
111
|
+
}
|
|
112
|
+
async list() {
|
|
113
|
+
const environments = [
|
|
114
|
+
{ schemaVersion: 1, id: 'default', name: '当前包与正式依赖', packages: {}, sources: [], version: null },
|
|
115
|
+
];
|
|
116
|
+
for (const { file } of await this.workspace.files()) {
|
|
117
|
+
if (!/^debug\/environments\/[^/]+\.json$/.test(file) || file.endsWith('.package-lock.json'))
|
|
118
|
+
continue;
|
|
119
|
+
const source = await this.workspace.read(file), value = environmentDocument(JSON.parse(source.text));
|
|
120
|
+
if (this.file(value.id) !== file)
|
|
121
|
+
fail('环境文件名与标识不一致');
|
|
122
|
+
environments.push({ ...value, version: source.version });
|
|
123
|
+
}
|
|
124
|
+
return environments;
|
|
125
|
+
}
|
|
126
|
+
async save({ document, expectedVersion, }) {
|
|
127
|
+
const value = environmentDocument(document);
|
|
128
|
+
const result = await this.workspace.write({
|
|
129
|
+
file: this.file(value.id),
|
|
130
|
+
expectedVersion,
|
|
131
|
+
text: JSON.stringify(value, null, 2) + '\n',
|
|
132
|
+
});
|
|
133
|
+
return { ...value, version: result.version };
|
|
134
|
+
}
|
|
135
|
+
}
|
package/dist/demo.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/demo.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { prepareContentPack, runBattle } from './testing.js';
|
|
2
|
+
import { setGlobalLogger } from '@arcadia-eternity/battle/engine';
|
|
3
|
+
setGlobalLogger({ debug() { }, info() { }, warn() { }, error() { } });
|
|
4
|
+
const example = await prepareContentPack();
|
|
5
|
+
try {
|
|
6
|
+
console.log(`Package: ${example.manifest.name}`);
|
|
7
|
+
console.log(`Namespace: ${example.manifest.arcadia.namespace}`);
|
|
8
|
+
console.log(`Environment: ${example.environment.revision}`);
|
|
9
|
+
const result = await runBattle(await example.createBattle(), battle => {
|
|
10
|
+
const pets = [battle.playerA, battle.playerB].map(player => `${player.name}: HP ${player.activePet.currentHp}, speed ${player.activePet.stat.spe}, marks ${player.activePet.marks.length}`);
|
|
11
|
+
console.log(`Turn ${battle.currentTurn}: ${pets.join(' | ')}`);
|
|
12
|
+
});
|
|
13
|
+
console.log(`Winner: ${result.winner}; finished in ${result.turns} turns.`);
|
|
14
|
+
console.log(`ARCADIA_RESULT=${JSON.stringify({ ...result, candidate: example.candidate, environmentRevision: example.environment.revision, packageName: example.manifest.name, files: example.files })}`);
|
|
15
|
+
}
|
|
16
|
+
finally {
|
|
17
|
+
await example.dispose();
|
|
18
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Build closed effect text without evaluating author code. The installed artifact is consumed by environment preparation. */
|
|
2
|
+
export declare function buildEffects(root: string): Promise<void>;
|
|
3
|
+
export { effectDiscoveryPlugin } from '@arcadia-eternity/pack-loader/effect-build';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir, rename, realpath, lstat, rm } from 'node:fs/promises';
|
|
2
|
+
import { resolve, relative, isAbsolute, dirname, sep } from 'node:path';
|
|
3
|
+
import { compileEffectModule } from '@arcadia-eternity/pack-loader/effect-build';
|
|
4
|
+
/** Build closed effect text without evaluating author code. The installed artifact is consumed by environment preparation. */
|
|
5
|
+
export async function buildEffects(root) {
|
|
6
|
+
root = await realpath(root);
|
|
7
|
+
const pkg = JSON.parse(await readFile(resolve(root, 'package.json'), 'utf8'));
|
|
8
|
+
const directory = pkg.arcadia?.effectSources;
|
|
9
|
+
if (directory === undefined)
|
|
10
|
+
return;
|
|
11
|
+
if (typeof directory !== 'string' ||
|
|
12
|
+
!directory ||
|
|
13
|
+
typeof pkg.arcadia.effectArtifact !== 'string' ||
|
|
14
|
+
pkg.arcadia.effects)
|
|
15
|
+
throw new Error('effectSources requires an effectArtifact destination and no effects entry');
|
|
16
|
+
const source = resolve(root, directory), destination = resolve(root, pkg.arcadia.effectArtifact);
|
|
17
|
+
for (const path of [source, destination]) {
|
|
18
|
+
const rel = relative(resolve(root), path);
|
|
19
|
+
if (rel === '..' || rel.startsWith('../') || isAbsolute(rel))
|
|
20
|
+
throw new Error('Effect path escapes project');
|
|
21
|
+
}
|
|
22
|
+
const canonicalSource = await realpath(source);
|
|
23
|
+
const sourceLocation = relative(root, canonicalSource);
|
|
24
|
+
if (sourceLocation === '..' || sourceLocation.startsWith(`..${sep}`) || isAbsolute(sourceLocation))
|
|
25
|
+
throw new Error('Effect source escapes project');
|
|
26
|
+
let parent = root;
|
|
27
|
+
for (const segment of relative(root, dirname(destination)).split(sep).filter(Boolean)) {
|
|
28
|
+
parent = resolve(parent, segment);
|
|
29
|
+
await mkdir(parent, { recursive: true });
|
|
30
|
+
const info = await lstat(parent);
|
|
31
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
32
|
+
throw new Error('Effect output must use regular project directories');
|
|
33
|
+
}
|
|
34
|
+
const artifact = await compileEffectModule(source, root, pkg.name);
|
|
35
|
+
const temporary = `${destination}.${process.pid}.tmp`;
|
|
36
|
+
await writeFile(temporary, JSON.stringify(artifact) + '\n', { flag: 'wx' });
|
|
37
|
+
try {
|
|
38
|
+
await rename(temporary, destination);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
await rm(temporary, { force: true });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export { effectDiscoveryPlugin } from '@arcadia-eternity/pack-loader/effect-build';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EnvironmentRules } from './content-workspace.js';
|
|
2
|
+
/** Validate the currently implemented rule vocabulary before admitting an environment. */
|
|
3
|
+
export declare function validateEnvironmentRules(input?: unknown): EnvironmentRules;
|
|
4
|
+
/** Version requirements fail closed until a host implements capability negotiation. */
|
|
5
|
+
export declare function assertEnvironmentRequirements(input?: unknown): void;
|
|
6
|
+
/** Admission checks apply to normalized team definitions, before creating any battle. */
|
|
7
|
+
export declare function assertEnvironmentTeam(input: unknown, team: unknown): void;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { isRecord } from './types.js';
|
|
2
|
+
function fail(code) {
|
|
3
|
+
throw Object.assign(new Error(code), { code });
|
|
4
|
+
}
|
|
5
|
+
const record = (value) => isRecord(value);
|
|
6
|
+
const keysAllowed = (value, names) => Object.keys(value).every(name => names.includes(name));
|
|
7
|
+
const identifier = (value) => typeof value === 'string' && value.length > 0 && value.length <= 256 && !/\p{Cc}/u.test(value);
|
|
8
|
+
/** Validate the currently implemented rule vocabulary before admitting an environment. */
|
|
9
|
+
export function validateEnvironmentRules(input) {
|
|
10
|
+
const rules = input === undefined ? { schemaVersion: 1 } : input;
|
|
11
|
+
if (!record(rules) || !keysAllowed(rules, ['schemaVersion', 'tier', 'allow', 'deny', 'team']))
|
|
12
|
+
fail('ENVIRONMENT_RULES_INVALID');
|
|
13
|
+
if (rules.schemaVersion !== 1 || (rules.tier !== undefined && rules.tier !== 'standard'))
|
|
14
|
+
fail('ENVIRONMENT_RULES_UNSUPPORTED');
|
|
15
|
+
for (const group of [rules.allow, rules.deny]) {
|
|
16
|
+
if (group === undefined)
|
|
17
|
+
continue;
|
|
18
|
+
if (!record(group) || !keysAllowed(group, ['species', 'skills', 'marks']))
|
|
19
|
+
fail('ENVIRONMENT_RULES_INVALID');
|
|
20
|
+
for (const values of Object.values(group)) {
|
|
21
|
+
if (!Array.isArray(values) ||
|
|
22
|
+
values.length > 10000 ||
|
|
23
|
+
values.some(value => !identifier(value)) ||
|
|
24
|
+
new Set(values).size !== values.length)
|
|
25
|
+
fail('ENVIRONMENT_RULES_INVALID');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (rules.team !== undefined &&
|
|
29
|
+
(!record(rules.team) || !keysAllowed(rules.team, ['minSize', 'maxSize', 'uniqueSpecies'])))
|
|
30
|
+
fail('ENVIRONMENT_RULES_INVALID');
|
|
31
|
+
const team = record(rules.team) ? rules.team : {};
|
|
32
|
+
const minSize = team.minSize === undefined ? 1 : team.minSize;
|
|
33
|
+
const maxSize = team.maxSize === undefined ? 6 : team.maxSize;
|
|
34
|
+
const uniqueSpecies = team.uniqueSpecies;
|
|
35
|
+
if (typeof minSize !== 'number' ||
|
|
36
|
+
typeof maxSize !== 'number' ||
|
|
37
|
+
!Number.isInteger(minSize) ||
|
|
38
|
+
!Number.isInteger(maxSize) ||
|
|
39
|
+
minSize < 1 ||
|
|
40
|
+
maxSize > 6 ||
|
|
41
|
+
minSize > maxSize ||
|
|
42
|
+
(uniqueSpecies !== undefined && typeof uniqueSpecies !== 'boolean'))
|
|
43
|
+
fail('ENVIRONMENT_RULES_INVALID');
|
|
44
|
+
return structuredClone(rules);
|
|
45
|
+
}
|
|
46
|
+
/** Version requirements fail closed until a host implements capability negotiation. */
|
|
47
|
+
export function assertEnvironmentRequirements(input) {
|
|
48
|
+
const requires = input === undefined ? {} : input;
|
|
49
|
+
if (!record(requires) || !keysAllowed(requires, ['engine', 'sdk', 'capabilities']))
|
|
50
|
+
fail('ENVIRONMENT_REQUIREMENT_INVALID');
|
|
51
|
+
for (const key of ['engine', 'sdk']) {
|
|
52
|
+
const value = requires[key];
|
|
53
|
+
if (value !== undefined && (typeof value !== 'string' || !value.trim()))
|
|
54
|
+
fail('ENVIRONMENT_REQUIREMENT_INVALID');
|
|
55
|
+
}
|
|
56
|
+
if (requires.capabilities !== undefined &&
|
|
57
|
+
(!Array.isArray(requires.capabilities) || requires.capabilities.some(value => !identifier(value))))
|
|
58
|
+
fail('ENVIRONMENT_REQUIREMENT_INVALID');
|
|
59
|
+
if (Array.isArray(requires.capabilities) && requires.capabilities.length)
|
|
60
|
+
fail('ENVIRONMENT_CAPABILITY_UNSUPPORTED');
|
|
61
|
+
if (requires.engine !== undefined || requires.sdk !== undefined)
|
|
62
|
+
fail('ENVIRONMENT_REQUIREMENT_UNSUPPORTED');
|
|
63
|
+
}
|
|
64
|
+
/** Admission checks apply to normalized team definitions, before creating any battle. */
|
|
65
|
+
export function assertEnvironmentTeam(input, team) {
|
|
66
|
+
const rules = validateEnvironmentRules(input);
|
|
67
|
+
const { minSize = 1, maxSize = 6, uniqueSpecies = false } = rules.team ?? {};
|
|
68
|
+
if (!Array.isArray(team) || team.length < minSize || team.length > maxSize)
|
|
69
|
+
fail('ENVIRONMENT_TEAM_REJECTED');
|
|
70
|
+
const players = team;
|
|
71
|
+
for (const pet of players) {
|
|
72
|
+
if (!record(pet))
|
|
73
|
+
fail('ENVIRONMENT_TEAM_REJECTED');
|
|
74
|
+
const petRecord = pet;
|
|
75
|
+
if (!identifier(petRecord.species) ||
|
|
76
|
+
!Array.isArray(petRecord.skills) ||
|
|
77
|
+
petRecord.skills.some(skill => !identifier(skill)))
|
|
78
|
+
fail('ENVIRONMENT_TEAM_REJECTED');
|
|
79
|
+
if ([petRecord.ability, petRecord.emblem].some(mark => mark !== undefined && mark !== '' && !identifier(mark)))
|
|
80
|
+
fail('ENVIRONMENT_TEAM_REJECTED');
|
|
81
|
+
const selected = {
|
|
82
|
+
species: [petRecord.species],
|
|
83
|
+
skills: petRecord.skills,
|
|
84
|
+
marks: [petRecord.ability, petRecord.emblem].filter(value => !!value),
|
|
85
|
+
};
|
|
86
|
+
for (const kind of ['species', 'skills', 'marks']) {
|
|
87
|
+
const allow = rules.allow?.[kind], deny = rules.deny?.[kind];
|
|
88
|
+
if (selected[kind].some(id => !identifier(id) || (allow !== undefined && !allow.includes(id)) || deny?.includes(id)))
|
|
89
|
+
fail('ENVIRONMENT_TEAM_REJECTED');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (uniqueSpecies && new Set(players.map(pet => pet.species)).size !== players.length)
|
|
93
|
+
fail('ENVIRONMENT_TEAM_REJECTED');
|
|
94
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { prepareNpmProject } from '@arcadia-eternity/pack-loader/node';
|
|
2
|
+
import { type ManifestArcadia, type PackageManifest } from './workspace.js';
|
|
3
|
+
import { playersFromTeams, type ProjectTeam } from './project-teams.js';
|
|
4
|
+
import { type EnvironmentDocumentV2 } from './debug-environments.js';
|
|
5
|
+
type PreparedNpmEnvironment = Awaited<ReturnType<typeof prepareNpmProject>>;
|
|
6
|
+
export interface BattleLike {
|
|
7
|
+
cleanup(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface ContentCandidate {
|
|
10
|
+
packageName: string | undefined;
|
|
11
|
+
version: string | undefined;
|
|
12
|
+
integrity: string;
|
|
13
|
+
shasum: string;
|
|
14
|
+
sdkApi: unknown;
|
|
15
|
+
build: unknown;
|
|
16
|
+
environmentRevision: string;
|
|
17
|
+
environmentId: string;
|
|
18
|
+
environmentConfigVersion: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface PreparedBattleEnvironment {
|
|
21
|
+
environment: PreparedNpmEnvironment;
|
|
22
|
+
environmentDocument: EnvironmentDocumentV2;
|
|
23
|
+
candidate: ContentCandidate;
|
|
24
|
+
environmentLock: {
|
|
25
|
+
file: string;
|
|
26
|
+
version: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
sourceRevisions: Record<string, string>;
|
|
29
|
+
loadTeams(ids: string[]): ReturnType<typeof playersFromTeams>;
|
|
30
|
+
teams: ProjectTeam[];
|
|
31
|
+
teamVersions: Record<string, string | null>;
|
|
32
|
+
manifest: PackageManifest & {
|
|
33
|
+
arcadia: ManifestArcadia;
|
|
34
|
+
};
|
|
35
|
+
files: string[];
|
|
36
|
+
dispose(): Promise<void>;
|
|
37
|
+
track(battle: BattleLike): void;
|
|
38
|
+
untrack(battle: BattleLike): void;
|
|
39
|
+
}
|
|
40
|
+
/** Pack and install exactly what a consuming server receives. Approval is limited to this local demo. */
|
|
41
|
+
export declare function prepareBattleEnvironment(root?: string, { offline, cache, environmentId, sources, lockRoot, }?: {
|
|
42
|
+
offline?: boolean;
|
|
43
|
+
cache?: string;
|
|
44
|
+
environmentId?: string;
|
|
45
|
+
sources?: Record<string, string | undefined>;
|
|
46
|
+
lockRoot?: string;
|
|
47
|
+
}): Promise<PreparedBattleEnvironment>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile, cp, symlink } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join, resolve, dirname } from 'node:path';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
import { emptyNpmContentHost, prepareNpmProject, resolveNpmInvocation } from '@arcadia-eternity/pack-loader/node';
|
|
8
|
+
import { AuthorWorkspace } from './workspace.js';
|
|
9
|
+
import { ProjectTeams, playersFromTeams } from './project-teams.js';
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
import { DebugEnvironments, normalizeEnvironmentDocument } from './debug-environments.js';
|
|
12
|
+
import { assertEnvironmentRequirements, validateEnvironmentRules } from './environment-rules.js';
|
|
13
|
+
import { siblingModulePath } from './module-path.js';
|
|
14
|
+
import { errorCode } from './types.js';
|
|
15
|
+
const exec = promisify(execFile);
|
|
16
|
+
async function npm(args, options) {
|
|
17
|
+
const invocation = await resolveNpmInvocation(args);
|
|
18
|
+
return exec(invocation.file, invocation.args, options);
|
|
19
|
+
}
|
|
20
|
+
/** Pack and install exactly what a consuming server receives. Approval is limited to this local demo. */
|
|
21
|
+
export async function prepareBattleEnvironment(root = process.cwd(), { offline = true, cache, environmentId = 'default', sources = {}, lockRoot, } = {}) {
|
|
22
|
+
root = resolve(root);
|
|
23
|
+
const temporary = await mkdtemp(join(tmpdir(), 'arcadia-pack-template-'));
|
|
24
|
+
const manifest = JSON.parse(await readFile(join(root, 'package.json'), 'utf8'));
|
|
25
|
+
const cacheArgs = cache ? ['--cache', resolve(cache)] : [];
|
|
26
|
+
const battles = new Set();
|
|
27
|
+
const sourceRevisions = {};
|
|
28
|
+
let environment, workspace, lockWorkspace;
|
|
29
|
+
async function dispose() {
|
|
30
|
+
for (const battle of battles)
|
|
31
|
+
await battle.cleanup();
|
|
32
|
+
await environment?.dispose();
|
|
33
|
+
await workspace?.close();
|
|
34
|
+
await lockWorkspace?.close();
|
|
35
|
+
await rm(temporary, { recursive: true, force: true });
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
workspace = await AuthorWorkspace.open(root, { watch: false });
|
|
39
|
+
const selected = (await new DebugEnvironments(workspace).list()).find(entry => entry.id === environmentId);
|
|
40
|
+
if (!selected)
|
|
41
|
+
throw new Error(`ENVIRONMENT_MISSING: ${environmentId}`);
|
|
42
|
+
const { version: _version, ...selectedDocument } = selected;
|
|
43
|
+
const environmentDocument = environmentId === 'default'
|
|
44
|
+
? {
|
|
45
|
+
...selectedDocument,
|
|
46
|
+
schemaVersion: 2,
|
|
47
|
+
rules: { schemaVersion: 1 },
|
|
48
|
+
requires: {},
|
|
49
|
+
}
|
|
50
|
+
: normalizeEnvironmentDocument(selectedDocument);
|
|
51
|
+
assertEnvironmentRequirements(environmentDocument.requires);
|
|
52
|
+
validateEnvironmentRules(environmentDocument.rules);
|
|
53
|
+
const lockFile = environmentId === 'default' ? undefined : `debug/environments/${environmentId}.package-lock.json`;
|
|
54
|
+
let oldLock;
|
|
55
|
+
if (lockFile) {
|
|
56
|
+
try {
|
|
57
|
+
oldLock = await workspace.read(lockFile);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (errorCode(error) !== 'ENOENT')
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const result = await npm(['pack', '--json', '--ignore-scripts', '--pack-destination', temporary, ...cacheArgs], {
|
|
65
|
+
cwd: root,
|
|
66
|
+
});
|
|
67
|
+
const packed = JSON.parse(String(result.stdout))[0];
|
|
68
|
+
const files = packed.files.map(file => file.path);
|
|
69
|
+
assert.ok(files.includes(manifest.arcadia.content));
|
|
70
|
+
if (manifest.arcadia.effects)
|
|
71
|
+
assert.ok(files.includes(manifest.arcadia.effects));
|
|
72
|
+
assert.ok(!files.some(file => /^(?:\.arcadia|\.github|node_modules|test|scripts|debug)\//.test(file)), 'the package must contain content, not a developer workspace');
|
|
73
|
+
const installation = join(temporary, 'server-project');
|
|
74
|
+
await mkdir(join(installation, 'candidates'), { recursive: true });
|
|
75
|
+
const dependencies = { ...selected.packages };
|
|
76
|
+
async function addCandidate(directory, metadata, packedInfo) {
|
|
77
|
+
if (Object.hasOwn(dependencies, metadata.name))
|
|
78
|
+
throw new Error(`ENVIRONMENT_DUPLICATE: ${metadata.name}`);
|
|
79
|
+
const filename = `candidates/${packedInfo.shasum}.tgz`;
|
|
80
|
+
await cp(join(directory, packedInfo.filename), join(installation, filename));
|
|
81
|
+
dependencies[metadata.name] = `file:${filename}`;
|
|
82
|
+
}
|
|
83
|
+
await addCandidate(temporary, manifest, packed);
|
|
84
|
+
for (const name of selected.sources) {
|
|
85
|
+
const source = sources[name];
|
|
86
|
+
if (typeof source !== 'string')
|
|
87
|
+
throw new Error(`ENVIRONMENT_SOURCE_MISSING: ${name},请设置本机源码映射`);
|
|
88
|
+
const sourceWorkspace = await AuthorWorkspace.open(resolve(source), { watch: false });
|
|
89
|
+
try {
|
|
90
|
+
const before = await sourceWorkspace.revision({ contentOnly: true });
|
|
91
|
+
sourceRevisions[name] = before;
|
|
92
|
+
const captured = join(temporary, `source-${Object.keys(dependencies).length}`);
|
|
93
|
+
await mkdir(captured);
|
|
94
|
+
for (const entry of await sourceWorkspace.files()) {
|
|
95
|
+
if (entry.error)
|
|
96
|
+
throw new Error(entry.error);
|
|
97
|
+
await mkdir(dirname(join(captured, entry.file)), { recursive: true });
|
|
98
|
+
await cp(await sourceWorkspace.path(entry.file), join(captured, entry.file));
|
|
99
|
+
}
|
|
100
|
+
if (before !== (await sourceWorkspace.revision({ contentOnly: true })))
|
|
101
|
+
throw new Error('ENVIRONMENT_SOURCE_CHANGED');
|
|
102
|
+
await symlink(join(sourceWorkspace.root, 'node_modules'), join(captured, 'node_modules'), process.platform === 'win32' ? 'junction' : 'dir');
|
|
103
|
+
const metadata = JSON.parse(await readFile(join(captured, 'package.json'), 'utf8'));
|
|
104
|
+
if (metadata.name !== name)
|
|
105
|
+
throw new Error(`ENVIRONMENT_SOURCE_IDENTITY: ${name}`);
|
|
106
|
+
await exec(process.execPath, [siblingModulePath('cli'), 'build'], { cwd: captured });
|
|
107
|
+
const info = JSON.parse(String((await npm(['pack', '--json', '--ignore-scripts', ...cacheArgs], { cwd: captured })).stdout))[0];
|
|
108
|
+
if (info.files.some(file => /^(?:debug|test|scripts|node_modules|\.arcadia|\.github)\//.test(file.path)))
|
|
109
|
+
throw new Error('ENVIRONMENT_PACKAGE_FILES');
|
|
110
|
+
await addCandidate(captured, metadata, info);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
await sourceWorkspace.close();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (oldLock)
|
|
117
|
+
await writeFile(join(installation, 'package-lock.json'), oldLock.text);
|
|
118
|
+
await writeFile(join(installation, 'package.json'), JSON.stringify({
|
|
119
|
+
name: 'arcadia-template-demo-server',
|
|
120
|
+
version: '1.0.0',
|
|
121
|
+
private: true,
|
|
122
|
+
dependencies,
|
|
123
|
+
}));
|
|
124
|
+
await npm([
|
|
125
|
+
'install',
|
|
126
|
+
...(offline ? ['--offline'] : []),
|
|
127
|
+
'--ignore-scripts',
|
|
128
|
+
'--omit=dev',
|
|
129
|
+
'--no-audit',
|
|
130
|
+
'--no-fund',
|
|
131
|
+
...cacheArgs,
|
|
132
|
+
], { cwd: installation });
|
|
133
|
+
environment = await prepareNpmProject(installation, emptyNpmContentHost, {
|
|
134
|
+
policy: { profile: 'local-development' },
|
|
135
|
+
});
|
|
136
|
+
let environmentLock;
|
|
137
|
+
if (lockFile) {
|
|
138
|
+
const text = await readFile(join(installation, 'package-lock.json'), 'utf8');
|
|
139
|
+
if (lockRoot) {
|
|
140
|
+
lockWorkspace = await AuthorWorkspace.open(resolve(lockRoot), { watch: false });
|
|
141
|
+
const saved = await lockWorkspace.write({ file: lockFile, expectedVersion: oldLock?.version ?? null, text });
|
|
142
|
+
environmentLock = { file: lockFile, version: saved.version };
|
|
143
|
+
}
|
|
144
|
+
else
|
|
145
|
+
environmentLock = { file: lockFile, version: createHash('sha256').update(text).digest('hex') };
|
|
146
|
+
}
|
|
147
|
+
const teamLibrary = await new ProjectTeams(workspace).list();
|
|
148
|
+
function loadTeams(ids) {
|
|
149
|
+
return playersFromTeams(teamLibrary, ids);
|
|
150
|
+
}
|
|
151
|
+
const candidate = {
|
|
152
|
+
packageName: manifest.name,
|
|
153
|
+
version: manifest.version,
|
|
154
|
+
integrity: packed.integrity ?? '',
|
|
155
|
+
shasum: packed.shasum,
|
|
156
|
+
sdkApi: manifest.arcadia.sdkApi,
|
|
157
|
+
build: environment.build,
|
|
158
|
+
environmentRevision: environment.revision,
|
|
159
|
+
environmentId,
|
|
160
|
+
environmentConfigVersion: selected.version,
|
|
161
|
+
};
|
|
162
|
+
if (process.env.ARCADIA_AUTHOR_RESULT === '1')
|
|
163
|
+
console.log(`ARCADIA_RESULT=${JSON.stringify({ candidate, environmentLock, sourceRevisions })}`);
|
|
164
|
+
return {
|
|
165
|
+
environment,
|
|
166
|
+
environmentDocument,
|
|
167
|
+
candidate,
|
|
168
|
+
environmentLock,
|
|
169
|
+
sourceRevisions,
|
|
170
|
+
loadTeams,
|
|
171
|
+
teams: teamLibrary,
|
|
172
|
+
teamVersions: Object.fromEntries(teamLibrary.map(team => [team.id, team.version])),
|
|
173
|
+
manifest,
|
|
174
|
+
files,
|
|
175
|
+
dispose,
|
|
176
|
+
track: battle => battles.add(battle),
|
|
177
|
+
untrack: battle => battles.delete(battle),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
await dispose();
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Job } from './jobs.js';
|
|
2
|
+
export type JournalJob = Job;
|
|
3
|
+
export interface JobReceipt {
|
|
4
|
+
pid: number;
|
|
5
|
+
live: boolean;
|
|
6
|
+
job: JournalJob;
|
|
7
|
+
}
|
|
8
|
+
/** Local task receipts and cancellation requests are never part of a content package. */
|
|
9
|
+
export declare class JobJournal {
|
|
10
|
+
#private;
|
|
11
|
+
directory: string;
|
|
12
|
+
constructor(root: string);
|
|
13
|
+
file(id: string, suffix?: string): string;
|
|
14
|
+
save(job: JournalJob, live: boolean): Promise<void>;
|
|
15
|
+
read(): Promise<JobReceipt[]>;
|
|
16
|
+
requestCancel(id: string): Promise<void>;
|
|
17
|
+
cancelled(id: string): Promise<boolean>;
|
|
18
|
+
remove(id: string): Promise<void>;
|
|
19
|
+
}
|