@astrale-os/sdk 0.5.0-beta.50 → 0.5.0-beta.51

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.
@@ -1,6 +1,6 @@
1
1
  export { isBuild } from './admission.js';
2
2
  export { compile } from './compile.js';
3
- export { material, restoreBuild, type BuildMaterial } from './material.js';
3
+ export { material, generatedMaterial, restoreBuild, restoreGeneratedBuild, type BuildMaterial, type GeneratedBuildMaterial, } from './material.js';
4
4
  export type { Build } from './build.js';
5
5
  export * as frontend from './frontend/index.js';
6
6
  export type { BuildBundle, BuildSchema } from './schema.js';
@@ -1,4 +1,4 @@
1
1
  export { isBuild } from './admission.js';
2
2
  export { compile } from './compile.js';
3
- export { material, restoreBuild } from './material.js';
3
+ export { material, generatedMaterial, restoreBuild, restoreGeneratedBuild, } from './material.js';
4
4
  export * as frontend from './frontend/index.js';
@@ -17,7 +17,26 @@ export interface BuildMaterial {
17
17
  readonly routes: Build['routes'];
18
18
  readonly frontend?: FrontendCompilation;
19
19
  }
20
+ declare const GENERATED_BUILD_MATERIAL: unique symbol;
21
+ /** Exact Build material embedded by an Astrale execution-code generator. */
22
+ export interface GeneratedBuildMaterial {
23
+ readonly format: 'astrale.sdk.generated-build-material';
24
+ readonly version: 1;
25
+ readonly material: BuildMaterial;
26
+ readonly digest: Build['schema']['bundle']['ref']['digest'];
27
+ readonly [GENERATED_BUILD_MATERIAL]: 'generated-build-material';
28
+ }
20
29
  /** Detach the provider-neutral, runtime-free material embedded into generated execution code. */
21
30
  export declare function material(build: Build): BuildMaterial;
31
+ /** Produce opaque material for execution code from one admitted Build. */
32
+ export declare function generatedMaterial(build: Build): GeneratedBuildMaterial;
22
33
  /** Re-admit generated Build material and bind it to the exact imported Runtime value. */
23
34
  export declare function restoreBuild<RuntimeValue extends Runtime>(input: BuildMaterial, runtime: RuntimeValue): Build<DomainSchema, RuntimeValue>;
35
+ /**
36
+ * Bind material embedded by generated release code without repeating its external admission.
37
+ * Build generators must call {@link generatedMaterial} before embedding the exact envelope;
38
+ * decoded files, network values, and caller-provided JSON must continue through
39
+ * {@link restoreBuild}.
40
+ */
41
+ export declare function restoreGeneratedBuild<RuntimeValue extends Runtime>(input: GeneratedBuildMaterial, runtime: RuntimeValue): Build<DomainSchema, RuntimeValue>;
42
+ export {};
@@ -1,4 +1,5 @@
1
1
  import * as bundle from '@astrale-os/kernel-dsl/v1/bundle/transport';
2
+ import { load as loadGeneratedSchema } from '@astrale-os/kernel-dsl/v1/compiled/generated';
2
3
  import { load as loadCompiledSchema } from '@astrale-os/kernel-dsl/v1/compiled/loader';
3
4
  import { revision } from '@astrale-os/kernel-dsl/v1/schema/revision';
4
5
  import { equal } from '@astrale-os/kernel-dsl/value';
@@ -28,24 +29,19 @@ export function material(build) {
28
29
  ...(build.frontend === undefined ? {} : { frontend: build.frontend }),
29
30
  });
30
31
  }
32
+ /** Produce opaque material for execution code from one admitted Build. */
33
+ export function generatedMaterial(build) {
34
+ const value = deepFreeze(material(build));
35
+ return Object.freeze({
36
+ format: 'astrale.sdk.generated-build-material',
37
+ version: 1,
38
+ material: value,
39
+ digest: digestOf(value),
40
+ });
41
+ }
31
42
  /** Re-admit generated Build material and bind it to the exact imported Runtime value. */
32
43
  export function restoreBuild(input, runtime) {
33
- if (!isRuntime(runtime))
34
- throw new TypeError('Generated Runtime is not admitted.');
35
- if (input === null ||
36
- typeof input !== 'object' ||
37
- Array.isArray(input) ||
38
- input.format !== 'astrale.sdk.build-material' ||
39
- input.version !== 1 ||
40
- Reflect.ownKeys(input).some((key) => key !== 'format' &&
41
- key !== 'version' &&
42
- key !== 'schema' &&
43
- key !== 'callables' &&
44
- key !== 'requirements' &&
45
- key !== 'routes' &&
46
- key !== 'frontend')) {
47
- invalid();
48
- }
44
+ assertMaterialEnvelope(input, runtime);
49
45
  const domain = loadCompiledSchema(input.schema.compiled);
50
46
  const bytes = Uint8Array.from(input.schema.bundle.bytes);
51
47
  const decoded = bundle.decode(bytes);
@@ -57,12 +53,7 @@ export function restoreBuild(input, runtime) {
57
53
  revision(decoded.root) !== input.schema.compiled.root.revision) {
58
54
  invalid();
59
55
  }
60
- const registry = admitRuntimeRegistry(domain, runtime);
61
- const callables = registry.implementations.map(({ callable }) => callable.key).sort();
62
- if (callables.length !== input.callables.length ||
63
- callables.some((key, index) => key !== input.callables[index])) {
64
- throw new TypeError('Generated Runtime differs from Build material.');
65
- }
56
+ const registry = bindRuntime(domain, runtime, input.callables);
66
57
  const requirements = admitRequirements(input.requirements);
67
58
  validateRequirements(decoded.root, decoded.closure, requirements);
68
59
  const plan = admitRoutePlan(input.routes, domain);
@@ -87,6 +78,82 @@ export function restoreBuild(input, runtime) {
87
78
  });
88
79
  return admitBuild(build, { domain, registry });
89
80
  }
81
+ /**
82
+ * Bind material embedded by generated release code without repeating its external admission.
83
+ * Build generators must call {@link generatedMaterial} before embedding the exact envelope;
84
+ * decoded files, network values, and caller-provided JSON must continue through
85
+ * {@link restoreBuild}.
86
+ */
87
+ export function restoreGeneratedBuild(input, runtime) {
88
+ const generated = acceptGeneratedMaterial(input, runtime);
89
+ const domain = loadGeneratedSchema(generated.schema.compiled);
90
+ const registry = bindRuntime(domain, runtime, generated.callables);
91
+ const detached = Uint8Array.from(generated.schema.bundle.bytes);
92
+ const build = Object.freeze({
93
+ kind: 'build',
94
+ schema: Object.freeze({
95
+ compiled: generated.schema.compiled,
96
+ bundle: Object.freeze({
97
+ ref: generated.schema.bundle.ref,
98
+ bytes: () => new Uint8Array(detached),
99
+ }),
100
+ }),
101
+ runtime,
102
+ callables: Object.freeze([...generated.callables]),
103
+ requirements: generated.requirements,
104
+ routes: generated.routes,
105
+ ...(generated.frontend === undefined ? {} : { frontend: generated.frontend }),
106
+ });
107
+ return admitBuild(build, { domain, registry });
108
+ }
109
+ function acceptGeneratedMaterial(input, runtime) {
110
+ if (input === null ||
111
+ typeof input !== 'object' ||
112
+ Array.isArray(input) ||
113
+ input.format !== 'astrale.sdk.generated-build-material' ||
114
+ input.version !== 1 ||
115
+ Reflect.ownKeys(input).some((key) => key !== 'format' && key !== 'version' && key !== 'material' && key !== 'digest') ||
116
+ digestOf(input.material) !== input.digest) {
117
+ invalid();
118
+ }
119
+ assertMaterialEnvelope(input.material, runtime);
120
+ return deepFreeze(input).material;
121
+ }
122
+ function digestOf(input) {
123
+ try {
124
+ return artifact.identify(new TextEncoder().encode(JSON.stringify(input)), 'application/vnd.astrale.sdk.build-material+json').digest;
125
+ }
126
+ catch {
127
+ invalid();
128
+ }
129
+ }
130
+ function assertMaterialEnvelope(input, runtime) {
131
+ if (!isRuntime(runtime))
132
+ throw new TypeError('Generated Runtime is not admitted.');
133
+ if (input === null ||
134
+ typeof input !== 'object' ||
135
+ Array.isArray(input) ||
136
+ input.format !== 'astrale.sdk.build-material' ||
137
+ input.version !== 1 ||
138
+ Reflect.ownKeys(input).some((key) => key !== 'format' &&
139
+ key !== 'version' &&
140
+ key !== 'schema' &&
141
+ key !== 'callables' &&
142
+ key !== 'requirements' &&
143
+ key !== 'routes' &&
144
+ key !== 'frontend')) {
145
+ invalid();
146
+ }
147
+ }
148
+ function bindRuntime(domain, runtime, expected) {
149
+ const registry = admitRuntimeRegistry(domain, runtime);
150
+ const callables = registry.implementations.map(({ callable }) => callable.key).sort();
151
+ if (callables.length !== expected.length ||
152
+ callables.some((key, index) => key !== expected[index])) {
153
+ throw new TypeError('Generated Runtime differs from Build material.');
154
+ }
155
+ return registry;
156
+ }
90
157
  function admitRoutePlan(input, domain) {
91
158
  if (input.origin !== domain.origin ||
92
159
  input.revision !== domain.revision ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/sdk",
3
- "version": "0.5.0-beta.50",
3
+ "version": "0.5.0-beta.51",
4
4
  "description": "Schema-first SDK for defining, composing, and deploying Astrale domains",
5
5
  "keywords": [
6
6
  "astrale",
@@ -210,11 +210,11 @@
210
210
  "./package.json": "./package.json"
211
211
  },
212
212
  "dependencies": {
213
- "@astrale-os/kernel-client": "0.6.0-beta.19",
214
- "@astrale-os/kernel-core": "0.9.0-beta.15",
215
- "@astrale-os/kernel-dsl": "0.2.0-beta.12",
216
- "@astrale-os/kernel-protocol": "0.5.0-beta.15",
217
- "@astrale-os/kernel-server": "0.5.0-beta.16",
213
+ "@astrale-os/kernel-client": "0.6.0-beta.20",
214
+ "@astrale-os/kernel-core": "0.9.0-beta.16",
215
+ "@astrale-os/kernel-dsl": "0.2.0-beta.13",
216
+ "@astrale-os/kernel-protocol": "0.5.0-beta.16",
217
+ "@astrale-os/kernel-server": "0.5.0-beta.17",
218
218
  "@typescript/native-preview": "7.0.0-dev.20260707.2",
219
219
  "hono": "^4.13.2",
220
220
  "jose": "^6.2.9",