@cynodia/axiom-compiler 0.6.0-alpha.1 → 0.6.2-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/README.md CHANGED
@@ -20,13 +20,13 @@ Main exports: `compileToIR`, `compileToHtml`, `createThemeStylesheet`,
20
20
  ## Installation
21
21
 
22
22
  ```bash
23
- npm install @cynodia/axiom-compiler@alpha
23
+ npm install @cynodia/axiom-compiler
24
24
  ```
25
25
 
26
26
  Most applications should install the facade package instead, which re-exports this one:
27
27
 
28
28
  ```bash
29
- npm install @cynodia/axiom@alpha
29
+ npm install @cynodia/axiom
30
30
  ```
31
31
 
32
32
 
package/dist/codegen.d.ts CHANGED
@@ -1,7 +1,23 @@
1
1
  import type { ApplicationGraph, ApplicationIR, Appearance } from '@cynodia/axiom-core';
2
2
  import type { CompileOptions } from './normalize.js';
3
+ /**
4
+ * How a generated page reaches its authority.
5
+ *
6
+ * `true` means the standard semantic endpoint on the current origin, which is what the
7
+ * reference host serves — so an application with server-authoritative state needs no
8
+ * endpoint string and no gateway code of its own.
9
+ */
10
+ export type RemoteOption = boolean | {
11
+ endpoint?: string;
12
+ timeoutMs?: number;
13
+ };
3
14
  export interface HtmlOptions extends CompileOptions {
4
15
  title?: string;
16
+ /**
17
+ * Configure the page to talk to an authority. Omitted, it defaults to `true` whenever the
18
+ * IR contains a remote action, because such a page cannot work without one.
19
+ */
20
+ remote?: RemoteOption;
5
21
  /**
6
22
  * Pins the appearance of the emitted page. Omitted, the theme decides — and a theme set
7
23
  * to `system` follows the reader's own preference.
package/dist/codegen.js CHANGED
@@ -21,6 +21,24 @@ export function compileIRToHtml(ir, options = {}) {
21
21
  const title = options.title ?? ir.name;
22
22
  const stylesheet = createThemeStylesheet(ir.theme);
23
23
  const appearance = options.appearance ?? (ir.theme.appearance === 'system' ? undefined : ir.theme.appearance);
24
+ // A page with remote actions is not usable without a gateway, so one is configured by
25
+ // default rather than left for an author to discover.
26
+ const needsRemote = (ir.remoteActionIds ?? []).length > 0;
27
+ const remote = options.remote ?? needsRemote;
28
+ const remoteConfig = remote === false
29
+ ? null
30
+ : {
31
+ endpoint: (remote === true ? undefined : remote.endpoint) ?? '/axiom',
32
+ ...(remote !== true && remote.timeoutMs !== undefined ? { timeoutMs: remote.timeoutMs } : {}),
33
+ };
34
+ const bootstrap = remoteConfig
35
+ ? [
36
+ `const __axiomRemote = createHttpRemoteGateway(${JSON.stringify(remoteConfig)});`,
37
+ 'const __axiomApp = createAxiomRuntime({ ir: __AXIOM_IR__, rootElement: __axiomRoot, host: createBrowserHost(), remote: __axiomRemote });',
38
+ ]
39
+ : [
40
+ 'const __axiomApp = createAxiomRuntime({ ir: __AXIOM_IR__, rootElement: __axiomRoot, host: createBrowserHost() });',
41
+ ];
24
42
  return [
25
43
  '<!DOCTYPE html>',
26
44
  `<html lang="en"${appearance ? ` data-axiom-appearance="${appearance}"` : ''}>`,
@@ -38,8 +56,10 @@ export function compileIRToHtml(ir, options = {}) {
38
56
  runtimeSource,
39
57
  `const __AXIOM_IR__ = ${payload};`,
40
58
  'const __axiomRoot = document.getElementById("app");',
41
- 'const __axiomApp = createAxiomRuntime({ ir: __AXIOM_IR__, rootElement: __axiomRoot, host: createBrowserHost() });',
59
+ ...bootstrap,
42
60
  'globalThis.__AXIOM_APP__ = __axiomApp;',
61
+ // `start()` is the whole startup sequence: it renders synchronously and then loads
62
+ // authoritative state when a gateway is configured.
43
63
  '__axiomApp.start();',
44
64
  ' </script>',
45
65
  '</body>',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cynodia/axiom-compiler",
3
- "version": "0.6.0-alpha.1",
3
+ "version": "0.6.2-alpha.1",
4
4
  "description": "Normalizes an Axiom application graph and emits a self-contained page.",
5
5
  "license": "MIT",
6
6
  "author": "AskTech AS",
@@ -31,8 +31,8 @@
31
31
  }
32
32
  },
33
33
  "dependencies": {
34
- "@cynodia/axiom-core": "0.6.0-alpha.1",
35
- "@cynodia/axiom-runtime": "0.6.0-alpha.1"
34
+ "@cynodia/axiom-core": "0.6.2-alpha.1",
35
+ "@cynodia/axiom-runtime": "0.6.2-alpha.1"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "tsc -b tsconfig.json tsconfig.test.json",