halfcode-compiler.xnl 0.2.1 → 0.2.2
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 +39 -0
- package/dist/application-assembly.d.ts +2 -2
- package/dist/application-assembly.js +1 -1
- package/dist/index-96qHPZj2.d.ts +126 -0
- package/dist/{index-FdimP_SL.d.ts → index-Cqh9pEBa.d.ts} +10 -1
- package/dist/{index-DKwcVwK6.d.ts → index-D2mpux6L.d.ts} +1 -1
- package/dist/index-DdRHFKSQ.d.ts +192 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +12 -3
- package/dist/kind-definition.d.ts +1 -1
- package/dist/resource-core-Byhqyadq.d.ts +20 -0
- package/dist/resource-core.d.ts +3 -2
- package/dist/resource-core.js +432 -2
- package/dist/resource-mapping.d.ts +14 -1
- package/dist/resource-mapping.js +2 -2
- package/dist/resource-projection.d.ts +1 -1
- package/dist/skill-capsule.d.ts +3 -2
- package/dist/skill-capsule.js +2 -2
- package/dist/src-25wZPUyX.js +305 -0
- package/dist/src-D1Bmq7Lo.js +1205 -0
- package/dist/src-DCRih45n.js +947 -0
- package/dist/{src-4m42imop.js → src-DRIws6tY.js} +43 -3
- package/dist/system-skills/sys-halfcode-resource-dsl.plan.js +267 -0
- package/package.json +2 -2
- package/dist/index-DqYap2u_.d.ts +0 -81
- package/dist/index-wU-iKJnW.d.ts +0 -38
- package/dist/src-BlKlpg0J.js +0 -180
- package/dist/src-D8xlMdXx.js +0 -561
- package/dist/src-DKkIFGWH.js +0 -507
package/dist/src-BlKlpg0J.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
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 };
|