@cynodia/axiom-compiler 0.3.1-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AskTech AS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Axiom Compiler
2
+
3
+ Part of [Axiom](https://github.com/cynodia/axiom), an AI-native semantic web application
4
+ framework.
5
+
6
+ **Status: experimental / alpha.** The API may change between alpha releases.
7
+
8
+ Validates an Application Graph, normalizes it into a runtime-ready IR, and emits a
9
+ self-contained HTML page with the runtime inlined.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @cynodia/axiom-compiler@alpha
15
+ ```
16
+
17
+ Most applications should install the facade package instead, which re-exports this one:
18
+
19
+ ```bash
20
+ npm install @cynodia/axiom@alpha
21
+ ```
22
+
23
+ ## License
24
+
25
+ MIT
26
+
27
+ Copyright (c) 2026 AskTech AS.
@@ -0,0 +1,12 @@
1
+ import type { ApplicationGraph, ApplicationIR } from '@cynodia/axiom-core';
2
+ import type { CompileOptions } from './normalize.js';
3
+ export interface HtmlOptions extends CompileOptions {
4
+ title?: string;
5
+ }
6
+ /**
7
+ * Emits a self-contained page: the normalized IR as data, plus the generic runtime. No
8
+ * part of this output is derived from what the application is about.
9
+ */
10
+ export declare function compileIRToHtml(ir: ApplicationIR, options?: HtmlOptions): string;
11
+ export declare function compileToHtml(graph: ApplicationGraph, options?: HtmlOptions): string;
12
+ //# sourceMappingURL=codegen.d.ts.map
@@ -0,0 +1,77 @@
1
+ import { createRuntimeModuleSource } from '@cynodia/axiom-runtime';
2
+ import { compileToIR } from './normalize.js';
3
+ function escapeHtml(value) {
4
+ return value
5
+ .replace(/&/g, '&')
6
+ .replace(/</g, '&lt;')
7
+ .replace(/>/g, '&gt;')
8
+ .replace(/"/g, '&quot;');
9
+ }
10
+ function escapeForScript(value) {
11
+ return value.replace(/<\/script/gi, '<\\/script');
12
+ }
13
+ /** Domain-neutral styling for the semantic UI vocabulary. */
14
+ const STYLESHEET = `
15
+ :root { color-scheme: light; font-family: Inter, system-ui, sans-serif; }
16
+ body { margin: 0; background: #f4f7fb; color: #1f2937; }
17
+ #app { padding: 24px; max-width: 1100px; margin: 0 auto; }
18
+ .axiom-view { display: grid; gap: 16px; }
19
+ .axiom-container { display: flex; gap: 12px; }
20
+ .axiom-layout-vertical { flex-direction: column; align-items: stretch; }
21
+ .axiom-layout-horizontal { flex-direction: row; align-items: center; flex-wrap: wrap; }
22
+ .axiom-layout-stack { flex-direction: column; gap: 4px; }
23
+ .axiom-view > .axiom-container,
24
+ .axiom-view > .axiom-form { background: #ffffff; border-radius: 16px; padding: 20px; box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08); }
25
+ .axiom-repeat { display: grid; gap: 10px; }
26
+ .axiom-field { display: flex; gap: 8px; align-items: baseline; }
27
+ .axiom-field-label { color: #64748b; font-size: 13px; }
28
+ .axiom-field-value { font-weight: 500; }
29
+ .axiom-form { display: grid; gap: 12px; }
30
+ .axiom-input { display: grid; gap: 6px; }
31
+ .axiom-input-label { font-size: 13px; color: #475569; }
32
+ .axiom-control { font: inherit; border: 1px solid #cbd5e1; border-radius: 10px; padding: 10px 12px; width: 100%; box-sizing: border-box; }
33
+ textarea.axiom-control { min-height: 120px; resize: vertical; }
34
+ input[type="checkbox"].axiom-control { width: auto; }
35
+ .axiom-button { font: inherit; border: none; border-radius: 10px; padding: 10px 14px; background: #2563eb; color: #ffffff; cursor: pointer; }
36
+ .axiom-button.axiom-destructive, .axiom-role-danger { background: #dc2626; }
37
+ .axiom-role-secondary { background: #64748b; }
38
+ .axiom-emphasis-strong { font-weight: 700; font-size: 18px; }
39
+ .axiom-density-compact { padding: 6px 10px; }
40
+ .axiom-no-route { padding: 20px; background: #ffffff; border-radius: 12px; }
41
+ `.trim();
42
+ /**
43
+ * Emits a self-contained page: the normalized IR as data, plus the generic runtime. No
44
+ * part of this output is derived from what the application is about.
45
+ */
46
+ export function compileIRToHtml(ir, options = {}) {
47
+ const runtimeSource = createRuntimeModuleSource();
48
+ const payload = escapeForScript(JSON.stringify(ir));
49
+ const title = options.title ?? ir.name;
50
+ return [
51
+ '<!DOCTYPE html>',
52
+ '<html lang="en">',
53
+ '<head>',
54
+ ' <meta charset="utf-8" />',
55
+ ' <meta name="viewport" content="width=device-width, initial-scale=1" />',
56
+ ` <title>${escapeHtml(title)}</title>`,
57
+ ' <style>',
58
+ STYLESHEET,
59
+ ' </style>',
60
+ '</head>',
61
+ '<body>',
62
+ ' <div id="app"></div>',
63
+ ' <script type="module">',
64
+ runtimeSource,
65
+ `const __AXIOM_IR__ = ${payload};`,
66
+ 'const __axiomRoot = document.getElementById("app");',
67
+ 'const __axiomApp = createAxiomRuntime({ ir: __AXIOM_IR__, rootElement: __axiomRoot, host: createBrowserHost() });',
68
+ 'globalThis.__AXIOM_APP__ = __axiomApp;',
69
+ '__axiomApp.start();',
70
+ ' </script>',
71
+ '</body>',
72
+ '</html>',
73
+ ].join('\n');
74
+ }
75
+ export function compileToHtml(graph, options = {}) {
76
+ return compileIRToHtml(compileToIR(graph, options), options);
77
+ }
@@ -0,0 +1,3 @@
1
+ export * from './normalize.js';
2
+ export * from './codegen.js';
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './normalize.js';
2
+ export * from './codegen.js';
@@ -0,0 +1,16 @@
1
+ import type { ApplicationGraph, ApplicationIR, ValidationIssue, ValidationResult } from '@cynodia/axiom-core';
2
+ export declare class GraphValidationError extends Error {
3
+ readonly problems: ValidationIssue[];
4
+ constructor(result: ValidationResult);
5
+ }
6
+ export interface CompileOptions {
7
+ /** Compilation refuses invalid graphs by default; disable only for diagnostics. */
8
+ validate?: boolean;
9
+ }
10
+ /**
11
+ * Validates a graph and normalizes it into the runtime-ready IR: references resolved,
12
+ * lookups indexed, routes pre-compiled and ordered most-specific-first.
13
+ */
14
+ export declare function compileToIR(graph: ApplicationGraph, options?: CompileOptions): ApplicationIR;
15
+ export declare function serializeIR(ir: ApplicationIR): string;
16
+ //# sourceMappingURL=normalize.d.ts.map
@@ -0,0 +1,116 @@
1
+ import { inferLocationType, locationRootStateId, semanticContextFromGraph, validateGraph, } from '@cynodia/axiom-core';
2
+ import { isUINode } from '@cynodia/axiom-core';
3
+ export class GraphValidationError extends Error {
4
+ problems;
5
+ constructor(result) {
6
+ super(`Application graph is invalid:\n${result.errors
7
+ .map((problem) => ` [${problem.code}] ${problem.message}`)
8
+ .join('\n')}`);
9
+ this.name = 'GraphValidationError';
10
+ this.problems = result.errors;
11
+ }
12
+ }
13
+ function compileRoute(route) {
14
+ const parameters = route.parameters ?? [];
15
+ const segments = route.path
16
+ .split('/')
17
+ .filter(Boolean)
18
+ .map((segment) => {
19
+ if (!segment.startsWith(':')) {
20
+ return { kind: 'static', value: segment };
21
+ }
22
+ const name = segment.slice(1);
23
+ const parameter = parameters.find((candidate) => candidate.name === name);
24
+ return { kind: 'parameter', value: name, ...(parameter ? { parameterId: parameter.id } : {}) };
25
+ });
26
+ return {
27
+ id: route.id,
28
+ path: route.path,
29
+ viewId: route.viewId,
30
+ segments,
31
+ parameters,
32
+ specificity: segments.filter((segment) => segment.kind === 'parameter').length,
33
+ };
34
+ }
35
+ /**
36
+ * Validates a graph and normalizes it into the runtime-ready IR: references resolved,
37
+ * lookups indexed, routes pre-compiled and ordered most-specific-first.
38
+ */
39
+ export function compileToIR(graph, options = {}) {
40
+ if (options.validate !== false) {
41
+ const result = validateGraph(graph);
42
+ if (!result.valid) {
43
+ throw new GraphValidationError(result);
44
+ }
45
+ }
46
+ const nodes = {};
47
+ const actions = {};
48
+ const uiNodes = {};
49
+ const entities = [];
50
+ const states = [];
51
+ const constraints = [];
52
+ const routes = [];
53
+ for (const node of graph.listNodes()) {
54
+ nodes[node.id] = node;
55
+ if (isUINode(node)) {
56
+ uiNodes[node.id] = node;
57
+ continue;
58
+ }
59
+ switch (node.kind) {
60
+ case 'entity':
61
+ entities.push(node);
62
+ break;
63
+ case 'state':
64
+ states.push(node);
65
+ break;
66
+ case 'action':
67
+ actions[node.id] = node;
68
+ break;
69
+ case 'constraint':
70
+ constraints.push(node);
71
+ break;
72
+ case 'route':
73
+ routes.push(compileRoute(node));
74
+ break;
75
+ default:
76
+ }
77
+ }
78
+ routes.sort((left, right) => left.specificity - right.specificity || left.path.localeCompare(right.path));
79
+ const fields = {};
80
+ for (const entry of graph.listFields()) {
81
+ fields[entry.field.id] = entry;
82
+ }
83
+ // Resolve what each input writes to, so the runtime carries no type inference itself.
84
+ const semantics = semanticContextFromGraph(graph);
85
+ const locationTypes = {};
86
+ const locationRoots = {};
87
+ for (const node of Object.values(uiNodes)) {
88
+ if (node.kind !== 'input') {
89
+ continue;
90
+ }
91
+ const resolved = inferLocationType(node.binding.location, semantics);
92
+ if (resolved) {
93
+ locationTypes[node.id] = resolved;
94
+ }
95
+ locationRoots[node.id] = locationRootStateId(node.binding.location);
96
+ }
97
+ return {
98
+ id: graph.id,
99
+ name: graph.name,
100
+ version: graph.version,
101
+ nodes,
102
+ fields,
103
+ entities,
104
+ states,
105
+ actions,
106
+ uiNodes,
107
+ constraints,
108
+ routes,
109
+ edges: graph.listEdges(),
110
+ locationTypes,
111
+ locationRoots,
112
+ };
113
+ }
114
+ export function serializeIR(ir) {
115
+ return JSON.stringify(ir);
116
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@cynodia/axiom-compiler",
3
+ "version": "0.3.1-alpha.1",
4
+ "description": "Normalizes an Axiom application graph and emits a self-contained page.",
5
+ "license": "MIT",
6
+ "author": "AskTech AS",
7
+ "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/cynodia/axiom.git"
11
+ },
12
+ "homepage": "https://github.com/cynodia/axiom",
13
+ "bugs": {
14
+ "url": "https://github.com/cynodia/axiom/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "dist/**/*.js",
21
+ "dist/**/*.d.ts",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ }
32
+ },
33
+ "dependencies": {
34
+ "@cynodia/axiom-core": "0.3.1-alpha.1",
35
+ "@cynodia/axiom-runtime": "0.3.1-alpha.1"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -b tsconfig.json tsconfig.test.json",
39
+ "test": "node --test dist-test/**/*.test.js"
40
+ }
41
+ }