halfcode-compiler.xnl 0.1.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.
@@ -0,0 +1,236 @@
1
+ //#region ../application-assembly/src/index.d.ts
2
+ type JsonPrimitive = string | number | boolean | null;
3
+ type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];
4
+ interface JsonObject {
5
+ readonly [key: string]: JsonValue;
6
+ }
7
+ type ObjectOperationOwnerKind = "PageObject" | "BusinessObject";
8
+ type ObjectOperationBehavior = "action" | "mutation";
9
+ type ObjectInvocationMode = "single" | "batch";
10
+ type ObjectOperationEffect = "read-only" | "write" | "mixed";
11
+ interface ObjectTargetRef {
12
+ readonly kindFqn: string;
13
+ readonly key: JsonObject;
14
+ }
15
+ type ObjectTargets = {
16
+ readonly kind: "none";
17
+ } | {
18
+ readonly kind: "single";
19
+ readonly ref: ObjectTargetRef;
20
+ } | {
21
+ readonly kind: "selection";
22
+ readonly kindFqn: string;
23
+ readonly selector: {
24
+ readonly kind: "all";
25
+ } | {
26
+ readonly kind: "filter";
27
+ readonly where: JsonObject;
28
+ } | {
29
+ readonly kind: "refs";
30
+ readonly refs: readonly ObjectTargetRef[];
31
+ };
32
+ };
33
+ type ObjectOperationTargetDeclaration = {
34
+ readonly kind: "none";
35
+ } | {
36
+ readonly kind: "single";
37
+ readonly kindFqn: string;
38
+ } | {
39
+ readonly kind: "selection";
40
+ readonly kindFqn: string;
41
+ };
42
+ interface ObjectOperationDefinition {
43
+ readonly ref: string;
44
+ readonly id: string;
45
+ readonly ownerKindFqn: string;
46
+ readonly ownerResourceKind: ObjectOperationOwnerKind;
47
+ readonly behavior: ObjectOperationBehavior;
48
+ readonly targets: ObjectOperationTargetDeclaration;
49
+ readonly invocationModes: readonly ObjectInvocationMode[];
50
+ readonly effect: ObjectOperationEffect;
51
+ }
52
+ interface ObjectTargetKindDefinition {
53
+ readonly kindFqn: string;
54
+ readonly ownerKindFqn: string;
55
+ readonly role: "object" | "nested-subject";
56
+ }
57
+ interface ObjectOperationCatalog {
58
+ readonly targetKinds: readonly ObjectTargetKindDefinition[];
59
+ readonly operations: readonly ObjectOperationDefinition[];
60
+ }
61
+ type ObjectInvocation = {
62
+ readonly kind: "action";
63
+ readonly operationRef: string;
64
+ readonly input?: JsonValue;
65
+ } | {
66
+ readonly kind: "mutation";
67
+ readonly operationRef: string;
68
+ readonly desired: JsonValue;
69
+ };
70
+ type ObjectOperationConfig = JsonObject;
71
+ interface ObjectOperationCall {
72
+ readonly targets: ObjectTargets;
73
+ readonly invocation: ObjectInvocation;
74
+ readonly config?: ObjectOperationConfig;
75
+ }
76
+ type ExecuteObjectOperationRequest = {
77
+ readonly mode: "single";
78
+ readonly call: ObjectOperationCall;
79
+ } | {
80
+ readonly mode: "batch";
81
+ readonly items: readonly {
82
+ readonly key: string;
83
+ readonly call: ObjectOperationCall;
84
+ }[];
85
+ readonly config: {
86
+ readonly atomicity: "atomic" | "best-effort";
87
+ };
88
+ };
89
+ type ObjectOperationHandler<TRuntime = unknown, TResult = unknown> = (runtime: TRuntime, targets: ObjectTargets, invocation: ObjectInvocation, config: ObjectOperationConfig | undefined) => TResult | Promise<TResult>;
90
+ declare class ObjectOperationContractError extends TypeError {
91
+ readonly code: string;
92
+ readonly path?: string | undefined;
93
+ constructor(code: string, message: string, path?: string | undefined);
94
+ }
95
+ declare function assertObjectOperationCatalog(catalog: ObjectOperationCatalog): void;
96
+ declare function assertObjectOperationDefinition(definition: ObjectOperationDefinition): void;
97
+ declare function assertObjectOperationCall(call: ObjectOperationCall, definition: ObjectOperationDefinition, mode?: ObjectInvocationMode): void;
98
+ declare function assertExecuteObjectOperationRequest(request: ExecuteObjectOperationRequest, resolveDefinition: (operationRef: string) => ObjectOperationDefinition | undefined): void;
99
+ interface LoadApplicationAssemblyOptions {
100
+ resourceRootDir: string;
101
+ manifestPath?: string;
102
+ packageName?: string;
103
+ }
104
+ type ApplicationScope = "shared" | "domain";
105
+ interface AuthoringModuleDescriptor {
106
+ id: string;
107
+ packageName: string;
108
+ family: string;
109
+ scope: ApplicationScope;
110
+ resourceRootDir: string;
111
+ manifestPath?: string;
112
+ ports?: readonly AssemblyPort[];
113
+ }
114
+ interface AssemblyPort {
115
+ fqn: string;
116
+ description: string;
117
+ resourceKind: AssemblyResource["kind"];
118
+ contractRef?: string;
119
+ optional?: boolean;
120
+ }
121
+ interface AssemblyPortBinding {
122
+ portFqn: string;
123
+ resourceRef: string;
124
+ }
125
+ interface ResolveApplicationAssemblyOptions {
126
+ modules: readonly AuthoringModuleDescriptor[];
127
+ portBindings?: readonly AssemblyPortBinding[];
128
+ }
129
+ interface ResolvedAssemblyPortBinding extends AssemblyPortBinding {
130
+ port: AssemblyPort;
131
+ resource: AssemblyResource;
132
+ }
133
+ interface ContractedCallableResource {
134
+ kind: "Function" | "ComposedFunction";
135
+ fqn: string;
136
+ description: string;
137
+ instruction?: TextMaterial;
138
+ inputContractRef: string;
139
+ outputContractRef: string;
140
+ codeBinding: CodeBinding;
141
+ mutationRefs: readonly string[];
142
+ source: ResourceSource;
143
+ }
144
+ interface BusinessObjectResource {
145
+ kind: "BusinessObject";
146
+ fqn: string;
147
+ description: string;
148
+ instruction?: TextMaterial;
149
+ sopRefs: readonly string[];
150
+ relatedRefs: readonly string[];
151
+ targetKinds: readonly ObjectTargetKindDefinition[];
152
+ operations: readonly ObjectOperationDefinition[];
153
+ source: ResourceSource;
154
+ }
155
+ interface BusinessObjectSopResource {
156
+ kind: "BusinessObjectSOP";
157
+ fqn: string;
158
+ description: string;
159
+ instruction?: TextMaterial;
160
+ source: ResourceSource;
161
+ }
162
+ interface TextResource {
163
+ kind: "ApplicationSOP" | "PromptFragment" | "WikiPage";
164
+ fqn: string;
165
+ description: string;
166
+ instruction?: TextMaterial;
167
+ source: ResourceSource;
168
+ }
169
+ interface SkillCapsuleResource {
170
+ kind: "SkillCapsule";
171
+ fqn: string;
172
+ description: string;
173
+ metadata: Record<string, unknown>;
174
+ template: TextMaterial;
175
+ resourceMappings?: TextMaterial;
176
+ includes: readonly ResourceInclude[];
177
+ source: ResourceSource;
178
+ }
179
+ interface PageObjectResource {
180
+ kind: "PageObject";
181
+ fqn: string;
182
+ id: string;
183
+ description: string;
184
+ targetKinds: readonly ObjectTargetKindDefinition[];
185
+ operations: readonly ObjectOperationDefinition[];
186
+ source: ResourceSource;
187
+ }
188
+ interface TextMaterial {
189
+ href: string;
190
+ format?: string;
191
+ absolutePath: string;
192
+ content: string;
193
+ }
194
+ interface CodeBinding {
195
+ packageName: string;
196
+ module: string;
197
+ exportName: string;
198
+ moduleSpecifier: string;
199
+ }
200
+ interface ResourceInclude {
201
+ kind: string;
202
+ ref: string;
203
+ }
204
+ interface ResourceSource {
205
+ logicalPath: string;
206
+ directory: string;
207
+ moduleId: string;
208
+ packageName: string;
209
+ resourceRootDir: string;
210
+ }
211
+ interface ApplicationAssembly {
212
+ rootDir: string;
213
+ modules: readonly AuthoringModuleDescriptor[];
214
+ portBindings: readonly ResolvedAssemblyPortBinding[];
215
+ functions: readonly ContractedCallableResource[];
216
+ composedFunctions: readonly ContractedCallableResource[];
217
+ businessObjects: readonly BusinessObjectResource[];
218
+ businessObjectSops: readonly BusinessObjectSopResource[];
219
+ applicationSops: readonly TextResource[];
220
+ promptFragments: readonly TextResource[];
221
+ wikiPages: readonly TextResource[];
222
+ skillCapsules: readonly SkillCapsuleResource[];
223
+ pageObjects: readonly PageObjectResource[];
224
+ byFqn: ReadonlyMap<string, AssemblyResource>;
225
+ }
226
+ type AssemblyResource = ContractedCallableResource | BusinessObjectResource | BusinessObjectSopResource | TextResource | SkillCapsuleResource | PageObjectResource;
227
+ declare function loadApplicationAssembly(options: LoadApplicationAssemblyOptions): Promise<ApplicationAssembly>;
228
+ declare function resolveApplicationAssembly(options: ResolveApplicationAssemblyOptions): Promise<ApplicationAssembly>;
229
+ declare function resourceRefToFqn(ref: string): string;
230
+ declare const applicationAssemblyPackage: {
231
+ readonly role: "framework";
232
+ readonly area: "application-assembly";
233
+ readonly owns: "resource registry facts normalized for target-neutral compiler projections";
234
+ };
235
+ //#endregion
236
+ export { ObjectTargets as A, assertExecuteObjectOperationRequest as B, ObjectOperationDefinition as C, ObjectOperationTargetDeclaration as D, ObjectOperationOwnerKind as E, ResourceSource as F, resolveApplicationAssembly as G, assertObjectOperationCatalog as H, SkillCapsuleResource as I, resourceRefToFqn as K, TextMaterial as L, ResolveApplicationAssemblyOptions as M, ResolvedAssemblyPortBinding as N, ObjectTargetKindDefinition as O, ResourceInclude as P, TextResource as R, ObjectOperationContractError as S, ObjectOperationHandler as T, assertObjectOperationDefinition as U, assertObjectOperationCall as V, loadApplicationAssembly as W, ObjectInvocationMode as _, AssemblyResource as a, ObjectOperationCatalog as b, BusinessObjectSopResource as c, ExecuteObjectOperationRequest as d, JsonObject as f, ObjectInvocation as g, LoadApplicationAssemblyOptions as h, AssemblyPortBinding as i, PageObjectResource as j, ObjectTargetRef as k, CodeBinding as l, JsonValue as m, ApplicationScope as n, AuthoringModuleDescriptor as o, JsonPrimitive as p, AssemblyPort as r, BusinessObjectResource as s, ApplicationAssembly as t, ContractedCallableResource as u, ObjectOperationBehavior as v, ObjectOperationEffect as w, ObjectOperationConfig as x, ObjectOperationCall as y, applicationAssemblyPackage as z };
@@ -0,0 +1,3 @@
1
+ import { A as ObjectTargets, B as assertExecuteObjectOperationRequest, C as ObjectOperationDefinition, D as ObjectOperationTargetDeclaration, E as ObjectOperationOwnerKind, F as ResourceSource, G as resolveApplicationAssembly, H as assertObjectOperationCatalog, I as SkillCapsuleResource, K as resourceRefToFqn, L as TextMaterial, M as ResolveApplicationAssemblyOptions, N as ResolvedAssemblyPortBinding, O as ObjectTargetKindDefinition, P as ResourceInclude, R as TextResource, S as ObjectOperationContractError, T as ObjectOperationHandler, U as assertObjectOperationDefinition, V as assertObjectOperationCall, W as loadApplicationAssembly, _ as ObjectInvocationMode, a as AssemblyResource, b as ObjectOperationCatalog, c as BusinessObjectSopResource, d as ExecuteObjectOperationRequest, f as JsonObject, g as ObjectInvocation, h as LoadApplicationAssemblyOptions, i as AssemblyPortBinding, j as PageObjectResource, k as ObjectTargetRef, l as CodeBinding, m as JsonValue, n as ApplicationScope, o as AuthoringModuleDescriptor, p as JsonPrimitive, r as AssemblyPort, s as BusinessObjectResource, t as ApplicationAssembly, u as ContractedCallableResource, v as ObjectOperationBehavior, w as ObjectOperationEffect, x as ObjectOperationConfig, y as ObjectOperationCall, z as applicationAssemblyPackage } from "./index-FdimP_SL.js";
2
+ import { a as SkillReference, c as compilerSkillPackage, i as SkillDescriptor, n as CompileSkillCapsuleInput, o as compileResourceSkillCapsule, r as SkillCapsulePlan, s as compileSkillCapsule, t as CompileResourceSkillCapsuleInput } from "./index-D-cBhQVw.js";
3
+ export { type ApplicationAssembly, type ApplicationScope, type AssemblyPort, type AssemblyPortBinding, type AssemblyResource, type AuthoringModuleDescriptor, type BusinessObjectResource, type BusinessObjectSopResource, type CodeBinding, CompileResourceSkillCapsuleInput, CompileSkillCapsuleInput, type ContractedCallableResource, type ExecuteObjectOperationRequest, type JsonObject, type JsonPrimitive, type JsonValue, type LoadApplicationAssemblyOptions, type ObjectInvocation, type ObjectInvocationMode, type ObjectOperationBehavior, type ObjectOperationCall, type ObjectOperationCatalog, type ObjectOperationConfig, ObjectOperationContractError, type ObjectOperationDefinition, type ObjectOperationEffect, type ObjectOperationHandler, type ObjectOperationOwnerKind, type ObjectOperationTargetDeclaration, type ObjectTargetKindDefinition, type ObjectTargetRef, type ObjectTargets, type PageObjectResource, type ResolveApplicationAssemblyOptions, type ResolvedAssemblyPortBinding, type ResourceInclude, type ResourceSource, SkillCapsulePlan, type SkillCapsuleResource, SkillDescriptor, SkillReference, type TextMaterial, type TextResource, applicationAssemblyPackage, assertExecuteObjectOperationRequest, assertObjectOperationCall, assertObjectOperationCatalog, assertObjectOperationDefinition, compileResourceSkillCapsule, compileSkillCapsule, compilerSkillPackage, loadApplicationAssembly, resolveApplicationAssembly, resourceRefToFqn };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { a as assertObjectOperationCatalog, c as resolveApplicationAssembly, i as assertObjectOperationCall, l as resourceRefToFqn, n as applicationAssemblyPackage, o as assertObjectOperationDefinition, r as assertExecuteObjectOperationRequest, s as loadApplicationAssembly, t as ObjectOperationContractError } from "./src-Dv8bfFUo.js";
2
+ import "./application-assembly.js";
3
+ import { n as compileSkillCapsule, r as compilerSkillPackage, t as compileResourceSkillCapsule } from "./src-DEuFHizY.js";
4
+ export { ObjectOperationContractError, applicationAssemblyPackage, assertExecuteObjectOperationRequest, assertObjectOperationCall, assertObjectOperationCatalog, assertObjectOperationDefinition, compileResourceSkillCapsule, compileSkillCapsule, compilerSkillPackage, loadApplicationAssembly, resolveApplicationAssembly, resourceRefToFqn };
@@ -0,0 +1,14 @@
1
+ import { n as ResourceDescriptor } from "./index-Ba5Gt9iW.js";
2
+ //#region ../kind-definition/src/index.d.ts
3
+ interface KindDefinition extends ResourceDescriptor {
4
+ kind: "KindDefinition";
5
+ resourceKind: string;
6
+ sourceShapes: readonly ("file" | "directory" | "manifest")[];
7
+ }
8
+ declare const kindDefinitionPackage: {
9
+ readonly role: "framework";
10
+ readonly area: "kind-definition";
11
+ readonly owns: "resource kind validation authority";
12
+ };
13
+ //#endregion
14
+ export { KindDefinition, kindDefinitionPackage };
@@ -0,0 +1,8 @@
1
+ //#region ../kind-definition/src/index.ts
2
+ const kindDefinitionPackage = {
3
+ role: "framework",
4
+ area: "kind-definition",
5
+ owns: "resource kind validation authority"
6
+ };
7
+ //#endregion
8
+ export { kindDefinitionPackage };
@@ -0,0 +1,2 @@
1
+ import { _ as loadResourceTree, a as ResourceMetadata, c as ResourceRegistry, d as ResourceTreeBuildResult, f as ResourceValidationError, g as SourceShape, h as ResourceValueMap, i as ResourceIdentity, l as ResourceScalar, m as ResourceValueList, n as ResourceDescriptor, o as ResourceNode, p as ResourceValue, r as ResourceDiagnostic, s as ResourceRecord, t as LoadResourceTreeOptions, u as ResourceTree, v as validateResourceTree } from "./index-Ba5Gt9iW.js";
2
+ export { LoadResourceTreeOptions, ResourceDescriptor, ResourceDiagnostic, ResourceIdentity, ResourceMetadata, ResourceNode, ResourceRecord, ResourceRegistry, ResourceScalar, ResourceTree, ResourceTreeBuildResult, ResourceValidationError, ResourceValue, ResourceValueList, ResourceValueMap, SourceShape, loadResourceTree, validateResourceTree };
@@ -0,0 +1,2 @@
1
+ import { n as loadResourceTree, r as validateResourceTree, t as ResourceValidationError } from "./src-COEMEqZw.js";
2
+ export { ResourceValidationError, loadResourceTree, validateResourceTree };
@@ -0,0 +1,43 @@
1
+ //#region ../resource-mapping/src/index.d.ts
2
+ type ResourceMappingOperationKind = "CopyDirectory" | "CopyFile";
3
+ interface ResourceMappingOperation {
4
+ kind: ResourceMappingOperationKind;
5
+ from: string;
6
+ to: string;
7
+ }
8
+ interface NamedResourceMapping {
9
+ id: string;
10
+ sourceRoot: string;
11
+ operations: readonly ResourceMappingOperation[];
12
+ }
13
+ interface ResourceMappings {
14
+ referenceTargets: ReadonlyMap<string, string>;
15
+ callableArtifactsTarget: string;
16
+ sources: readonly NamedResourceMapping[];
17
+ source: {
18
+ uri: string;
19
+ };
20
+ }
21
+ interface PlannedResourceCopy {
22
+ sourcePath: string;
23
+ targetRelativePath: string;
24
+ mappingId: string;
25
+ }
26
+ interface ResourceMappingPlan {
27
+ entries: readonly PlannedResourceCopy[];
28
+ }
29
+ interface PlanResourceMappingsOptions {
30
+ moduleRoots: ReadonlyMap<string, string> | Readonly<Record<string, string>>;
31
+ defaultSourceRoot?: string;
32
+ reservedTargetPaths?: readonly string[];
33
+ }
34
+ declare function parseResourceMappings(source: string, uri?: string): ResourceMappings;
35
+ declare function planResourceMappings(mappings: ResourceMappings, options: PlanResourceMappingsOptions): Promise<ResourceMappingPlan>;
36
+ declare function applyResourceMappingPlan(plan: ResourceMappingPlan, outputRoot: string): Promise<string[]>;
37
+ declare const resourceMappingPackage: {
38
+ readonly role: "framework";
39
+ readonly area: "resource-mapping";
40
+ readonly owns: "declarative multi-root resource copy planning and collision preflight";
41
+ };
42
+ //#endregion
43
+ export { NamedResourceMapping, PlanResourceMappingsOptions, PlannedResourceCopy, ResourceMappingOperation, ResourceMappingOperationKind, ResourceMappingPlan, ResourceMappings, applyResourceMappingPlan, parseResourceMappings, planResourceMappings, resourceMappingPackage };
@@ -0,0 +1,2 @@
1
+ import { i as resourceMappingPackage, n as parseResourceMappings, r as planResourceMappings, t as applyResourceMappingPlan } from "./src-BlKlpg0J.js";
2
+ export { applyResourceMappingPlan, parseResourceMappings, planResourceMappings, resourceMappingPackage };
@@ -0,0 +1,2 @@
1
+ import { n as resourceProjectionPackage, t as ResourceRegistry } from "./index-DuRG4TQo.js";
2
+ export { ResourceRegistry, resourceProjectionPackage };
@@ -0,0 +1,8 @@
1
+ //#region ../resource-projection/src/index.ts
2
+ const resourceProjectionPackage = {
3
+ role: "framework",
4
+ area: "resource-projection",
5
+ owns: "validated registry facts and target projection inputs"
6
+ };
7
+ //#endregion
8
+ export { resourceProjectionPackage };
@@ -0,0 +1,2 @@
1
+ import { a as SkillReference, c as compilerSkillPackage, i as SkillDescriptor, n as CompileSkillCapsuleInput, o as compileResourceSkillCapsule, r as SkillCapsulePlan, s as compileSkillCapsule, t as CompileResourceSkillCapsuleInput } from "./index-D-cBhQVw.js";
2
+ export { CompileResourceSkillCapsuleInput, CompileSkillCapsuleInput, SkillCapsulePlan, SkillDescriptor, SkillReference, compileResourceSkillCapsule, compileSkillCapsule, compilerSkillPackage };
@@ -0,0 +1,2 @@
1
+ import { n as compileSkillCapsule, r as compilerSkillPackage, t as compileResourceSkillCapsule } from "./src-DEuFHizY.js";
2
+ export { compileResourceSkillCapsule, compileSkillCapsule, compilerSkillPackage };
@@ -0,0 +1,39 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ //#region ../runtime-authoring/src/index.ts
3
+ const runtimeScope = new AsyncLocalStorage();
4
+ function runWithRuntime(runtime, callback) {
5
+ return runtimeScope.run(runtime, callback);
6
+ }
7
+ function currentRuntime() {
8
+ const runtime = runtimeScope.getStore();
9
+ if (!runtime) throw new Error("No authoring runtime is active in the current async scope");
10
+ return runtime;
11
+ }
12
+ function createAuthoringBindings(runtime = currentRuntime()) {
13
+ return {
14
+ runtime,
15
+ logger: runtime.effects.logger,
16
+ invokeEffect: (effectFqn, input) => runtime.effects.invoke(effectFqn, input)
17
+ };
18
+ }
19
+ const logger = {
20
+ info(message, fields) {
21
+ currentRuntime().effects.logger.info(message, fields);
22
+ },
23
+ warn(message, fields) {
24
+ currentRuntime().effects.logger.warn(message, fields);
25
+ },
26
+ error(message, fields) {
27
+ currentRuntime().effects.logger.error(message, fields);
28
+ }
29
+ };
30
+ function invokeEffect(effectFqn, input) {
31
+ return currentRuntime().effects.invoke(effectFqn, input);
32
+ }
33
+ const runtimeAuthoringPackage = {
34
+ role: "framework",
35
+ area: "runtime-authoring",
36
+ owns: "target-neutral deterministic-code runtime and effect boundary"
37
+ };
38
+ //#endregion
39
+ export { runWithRuntime as a, logger as i, currentRuntime as n, runtimeAuthoringPackage as o, invokeEffect as r, createAuthoringBindings as t };
@@ -0,0 +1,180 @@
1
+ import { n as wordToString, t as parseXnl } from "./dist-Bkv7YeVi.js";
2
+ import { copyFile, lstat, mkdir, readdir } from "node:fs/promises";
3
+ import { dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
4
+ //#region ../resource-mapping/src/index.ts
5
+ function parseResourceMappings(source, uri = "vfs://./resource-mappings.xnl") {
6
+ let root;
7
+ try {
8
+ const document = parseXnl(source);
9
+ if (document.warnings?.length || document.nodes.length !== 1 || !isDataElement(document.nodes[0])) throw new Error("expected exactly one ResourceMappings data root without warnings");
10
+ root = document.nodes[0];
11
+ } catch (error) {
12
+ throw new Error(`Invalid ResourceMappings at ${uri}: ${error instanceof Error ? error.message : String(error)}`);
13
+ }
14
+ if (root.tag !== "ResourceMappings") throw new Error(`Invalid ResourceMappings at ${uri}: root must be ResourceMappings`);
15
+ const referenceTargets = /* @__PURE__ */ new Map();
16
+ for (const entry of bodyElements(extension(root, "ReferenceTargets"), "ReferenceTarget")) {
17
+ const kind = requiredXnlProperty(entry, "kind", uri);
18
+ if (referenceTargets.has(kind)) throw new Error(`Invalid ResourceMappings at ${uri}: duplicate ReferenceTarget kind ${kind}`);
19
+ referenceTargets.set(kind, normalizeOutputDirectory(requiredXnlProperty(entry, "target", uri), uri));
20
+ }
21
+ const callable = extension(root, "CallableArtifacts");
22
+ const callableArtifactsTarget = normalizeOutputDirectory(callable ? requiredXnlProperty(callable, "target", uri) : "functions/", uri);
23
+ const sources = bodyElements(extension(root, "SourceRoots"), "SourceRoot").map((entry) => {
24
+ const id = wordToString(entry.id);
25
+ if (!id || !/^[A-Z][A-Za-z0-9]*$/.test(id)) throw new Error(`Invalid ResourceMappings at ${uri}: SourceRoot #id must be a PascalCase segment`);
26
+ const operations = (entry.body ?? []).filter(isDataElement).filter((operation) => operation.tag === "CopyDirectory" || operation.tag === "CopyFile").map((operation) => ({
27
+ kind: operation.tag,
28
+ from: normalizeRelativePath(requiredXnlProperty(operation, "from", uri), uri, "from"),
29
+ to: normalizeRelativePath(requiredXnlProperty(operation, "to", uri), uri, "to")
30
+ }));
31
+ return {
32
+ id,
33
+ sourceRoot: requiredXnlProperty(entry, "sourceRoot", uri),
34
+ operations
35
+ };
36
+ });
37
+ if (new Set(sources.map((item) => item.id)).size !== sources.length) throw new Error(`Invalid ResourceMappings at ${uri}: SourceRoot ids must be unique`);
38
+ return {
39
+ referenceTargets,
40
+ callableArtifactsTarget,
41
+ sources,
42
+ source: { uri }
43
+ };
44
+ }
45
+ function extension(node, name) {
46
+ const child = node.extend?.children[name];
47
+ return child?.kind === "DataElement" ? child : void 0;
48
+ }
49
+ function bodyElements(node, tag) {
50
+ return (node?.body ?? []).filter(isDataElement).filter((entry) => entry.tag === tag);
51
+ }
52
+ function requiredXnlProperty(node, name, uri) {
53
+ const value = node.attributes?.[name];
54
+ if (typeof value !== "string" || !value.trim()) throw new Error(`Invalid ResourceMappings at ${uri}: <${node.tag}> requires ${name}`);
55
+ return value;
56
+ }
57
+ function isDataElement(value) {
58
+ return typeof value === "object" && value !== null && !Array.isArray(value) && "kind" in value && value.kind === "DataElement";
59
+ }
60
+ async function planResourceMappings(mappings, options) {
61
+ const roots = asRootMap(options.moduleRoots);
62
+ const claims = [];
63
+ const entries = [];
64
+ const reserved = (options.reservedTargetPaths ?? []).map((path) => normalizeRelativePath(path, mappings.source.uri, "to"));
65
+ for (const mapping of mappings.sources) {
66
+ const sourceRootPath = resolveSourceRoot(mapping.sourceRoot, roots, options.defaultSourceRoot, mappings.source.uri);
67
+ await assertDirectory(sourceRootPath, mappings.source.uri, mapping.sourceRoot);
68
+ for (const operation of mapping.operations) {
69
+ for (const prior of claims) if (pathsOverlap(prior.target, operation.to)) throw new Error(`ResourceMappings target collision between ${prior.mappingId}:${prior.from} -> ${prior.target} and ${mapping.id}:${operation.from} -> ${operation.to}`);
70
+ claims.push({
71
+ target: operation.to,
72
+ mappingId: mapping.id,
73
+ from: operation.from
74
+ });
75
+ const sourcePath = safeResolve(sourceRootPath, operation.from, mappings.source.uri);
76
+ if (operation.kind === "CopyFile") {
77
+ await assertFile(sourcePath, mappings.source.uri, operation.from);
78
+ assertNotReserved(operation.to, reserved, mappings.source.uri);
79
+ entries.push({
80
+ sourcePath,
81
+ targetRelativePath: operation.to,
82
+ mappingId: mapping.id
83
+ });
84
+ continue;
85
+ }
86
+ await assertDirectory(sourcePath, mappings.source.uri, operation.from);
87
+ for (const filePath of await listFiles(sourcePath, mappings.source.uri)) {
88
+ const child = relative(sourcePath, filePath).split(sep).join("/");
89
+ const targetRelativePath = posix.join(operation.to, child);
90
+ assertNotReserved(targetRelativePath, reserved, mappings.source.uri);
91
+ entries.push({
92
+ sourcePath: filePath,
93
+ targetRelativePath,
94
+ mappingId: mapping.id
95
+ });
96
+ }
97
+ }
98
+ }
99
+ const seenTargets = /* @__PURE__ */ new Map();
100
+ for (const entry of entries) {
101
+ const prior = seenTargets.get(entry.targetRelativePath);
102
+ if (prior) throw new Error(`ResourceMappings duplicate target ${entry.targetRelativePath} from ${prior.sourcePath} and ${entry.sourcePath}`);
103
+ seenTargets.set(entry.targetRelativePath, entry);
104
+ }
105
+ return { entries: entries.sort((a, b) => a.targetRelativePath.localeCompare(b.targetRelativePath)) };
106
+ }
107
+ async function applyResourceMappingPlan(plan, outputRoot) {
108
+ const files = [];
109
+ for (const entry of plan.entries) {
110
+ const target = resolve(outputRoot, entry.targetRelativePath);
111
+ if (!isWithinRoot(resolve(outputRoot), target)) throw new Error(`ResourceMappings output escapes target root: ${entry.targetRelativePath}`);
112
+ await mkdir(dirname(target), { recursive: true });
113
+ await copyFile(entry.sourcePath, target);
114
+ files.push(entry.targetRelativePath);
115
+ }
116
+ return files;
117
+ }
118
+ function resolveSourceRoot(uri, roots, defaultSourceRoot, mappingUri) {
119
+ const moduleMatch = /^vfs:\/\/module\/([A-Z][A-Za-z0-9]*)\/(.*)$/.exec(uri);
120
+ if (moduleMatch) {
121
+ const base = roots.get(moduleMatch[1]);
122
+ if (!base) throw new Error(`Invalid ResourceMappings at ${mappingUri}: unknown module root ${moduleMatch[1]}`);
123
+ return safeResolve(resolve(base), moduleMatch[2], mappingUri);
124
+ }
125
+ const localMatch = /^vfs:\/\/@\/(.*)$/.exec(uri);
126
+ if (localMatch && defaultSourceRoot) return safeResolve(resolve(defaultSourceRoot), localMatch[1], mappingUri);
127
+ throw new Error(`Invalid ResourceMappings at ${mappingUri}: unsupported sourceRoot ${uri}`);
128
+ }
129
+ async function listFiles(root, uri) {
130
+ const files = [];
131
+ for (const entry of (await readdir(root, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
132
+ const path = join(root, entry.name);
133
+ if (entry.isSymbolicLink()) throw new Error(`Invalid ResourceMappings at ${uri}: symbolic links are not supported: ${path}`);
134
+ if (entry.isDirectory()) files.push(...await listFiles(path, uri));
135
+ else if (entry.isFile()) files.push(path);
136
+ else throw new Error(`Invalid ResourceMappings at ${uri}: unsupported source entry ${path}`);
137
+ }
138
+ return files;
139
+ }
140
+ async function assertDirectory(path, uri, label) {
141
+ const info = await lstat(path).catch(() => void 0);
142
+ if (!info || info.isSymbolicLink() || !info.isDirectory()) throw new Error(`Invalid ResourceMappings at ${uri}: directory source does not exist: ${label}`);
143
+ }
144
+ async function assertFile(path, uri, label) {
145
+ const info = await lstat(path).catch(() => void 0);
146
+ if (!info || info.isSymbolicLink() || !info.isFile()) throw new Error(`Invalid ResourceMappings at ${uri}: file source does not exist: ${label}`);
147
+ }
148
+ function safeResolve(root, path, uri) {
149
+ const target = resolve(root, path);
150
+ if (!isWithinRoot(root, target)) throw new Error(`Invalid ResourceMappings at ${uri}: path escapes source root: ${path}`);
151
+ return target;
152
+ }
153
+ function isWithinRoot(root, target) {
154
+ return target === root || target.startsWith(`${root}${sep}`);
155
+ }
156
+ function assertNotReserved(path, reserved, uri) {
157
+ for (const item of reserved) if (pathsOverlap(path, item)) throw new Error(`Invalid ResourceMappings at ${uri}: target ${path} conflicts with generated target ${item}`);
158
+ }
159
+ function pathsOverlap(left, right) {
160
+ return left === right || left.startsWith(`${right}/`) || right.startsWith(`${left}/`);
161
+ }
162
+ function normalizeRelativePath(value, uri, attribute) {
163
+ if (!value.trim() || value.includes("\\") || value.startsWith("/") || isAbsolute(value) || value.split("/").includes("..")) throw new Error(`Invalid ResourceMappings at ${uri}: ${attribute} must be a safe relative path: ${value}`);
164
+ const normalized = posix.normalize(value).replace(/^\.\//, "").replace(/\/$/, "");
165
+ if (!normalized || normalized === "." || normalized.startsWith("../")) throw new Error(`Invalid ResourceMappings at ${uri}: ${attribute} must identify a non-root path: ${value}`);
166
+ return normalized;
167
+ }
168
+ function normalizeOutputDirectory(value, uri) {
169
+ return `${normalizeRelativePath(value, uri, "to")}/`;
170
+ }
171
+ function asRootMap(value) {
172
+ return typeof value.get === "function" ? value : new Map(Object.entries(value));
173
+ }
174
+ const resourceMappingPackage = {
175
+ role: "framework",
176
+ area: "resource-mapping",
177
+ owns: "declarative multi-root resource copy planning and collision preflight"
178
+ };
179
+ //#endregion
180
+ export { resourceMappingPackage as i, parseResourceMappings as n, planResourceMappings as r, applyResourceMappingPlan as t };