@astrale-os/kernel-dsl 0.2.0-beta.12 → 0.2.0-beta.13

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.
@@ -106,7 +106,7 @@ type ValueOutputOf<Schema> = Schema extends TypedValueSchema<infer Value> ? Valu
106
106
  type PropertyRequiredOf<Field> = PropertyOptionsOf<Field> extends {
107
107
  readonly required: infer Required extends boolean;
108
108
  } ? Required : undefined extends ValueInputOf<PropertySchemaOf<Field>> ? false : true;
109
- type PropertyProjectionOf<Name extends string, Field> = AuthoredPropertyProjection<ValueInputOf<PropertySchemaOf<Field>>, ValueOutputOf<PropertySchemaOf<Field>>, PropertyRequiredOf<Field>, Name>;
109
+ type PropertyProjectionOf<Name extends string, Field> = AuthoredPropertyProjection<Field extends AutoProperty ? never : ValueInputOf<PropertySchemaOf<Field>>, ValueOutputOf<PropertySchemaOf<Field>>, PropertyRequiredOf<Field>, Name>;
110
110
  type PropertyProjectionsOf<Input> = Input extends Readonly<Record<string, unknown>> ? {
111
111
  readonly [Name in keyof Input]: PropertyProjectionOf<Extract<Name, string>, Input[Name]>;
112
112
  } : Readonly<Record<never, never>>;
@@ -214,16 +214,20 @@ type AuthoredProjectionRequired<Entry> = Entry extends AuthoredPropertyProjectio
214
214
  type UniqueAuthoredProjections<Entries> = Entries extends unknown ? IsMultiple<Extract<Entries, {
215
215
  readonly name: AuthoredProjectionName<Entries>;
216
216
  }>> extends true ? never : Entries : never;
217
- type RequiredAuthoredPropertyNames<Entries> = UniqueAuthoredProjections<Entries> extends infer Entry ? Entry extends unknown ? AuthoredProjectionRequired<Entry> extends true ? AuthoredProjectionName<Entry> : never : never : never;
218
- type OptionalAuthoredPropertyNames<Entries> = Exclude<AuthoredProjectionName<UniqueAuthoredProjections<Entries>>, RequiredAuthoredPropertyNames<Entries>>;
217
+ type CoreAuthoredProjections<Entries> = UniqueAuthoredProjections<Entries> extends infer Entry ? Entry extends unknown ? [AuthoredProjectionInput<Entry>] extends [never] ? never : Entry : never : never;
218
+ type RequiredAuthoredPropertyNames<Entries> = CoreAuthoredProjections<Entries> extends infer Entry ? Entry extends unknown ? AuthoredProjectionRequired<Entry> extends true ? AuthoredProjectionName<Entry> : never : never : never;
219
+ type OptionalAuthoredPropertyNames<Entries> = Exclude<AuthoredProjectionName<CoreAuthoredProjections<Entries>>, RequiredAuthoredPropertyNames<Entries>>;
220
+ type AutomaticAuthoredPropertyNames<Entries> = UniqueAuthoredProjections<Entries> extends infer Entry ? Entry extends unknown ? [AuthoredProjectionInput<Entry>] extends [never] ? AuthoredProjectionName<Entry> : never : never : never;
219
221
  type CorePropertyInputFromAuthoredProjections<Entries> = Readonly<{
220
- [Name in RequiredAuthoredPropertyNames<Entries>]: AuthoredProjectionInput<Extract<UniqueAuthoredProjections<Entries>, {
222
+ [Name in RequiredAuthoredPropertyNames<Entries>]: AuthoredProjectionInput<Extract<CoreAuthoredProjections<Entries>, {
221
223
  readonly name: Name;
222
224
  }>>;
223
225
  } & {
224
- [Name in OptionalAuthoredPropertyNames<Entries>]?: AuthoredProjectionInput<Extract<UniqueAuthoredProjections<Entries>, {
226
+ [Name in OptionalAuthoredPropertyNames<Entries>]?: AuthoredProjectionInput<Extract<CoreAuthoredProjections<Entries>, {
225
227
  readonly name: Name;
226
228
  }>>;
229
+ } & {
230
+ [Name in AutomaticAuthoredPropertyNames<Entries>]?: never;
227
231
  }>;
228
232
  type UnionIsMultiple<Value, Whole = Value> = Value extends unknown ? [Whole] extends [Value] ? false : true : never;
229
233
  type IsMultiple<Value> = true extends UnionIsMultiple<Value> ? true : false;
@@ -973,10 +973,12 @@ function validateCoreProperties(values, analysis, path) {
973
973
  fail(`${path}/${escapePointer(key)}`, 'Core properties contain an unknown Property key.');
974
974
  for (const property of analysis.properties.values()) {
975
975
  if (!Object.hasOwn(values, property.key)) {
976
- if (property.declaration.required)
976
+ if (property.declaration.required && property.declaration.auto === undefined)
977
977
  fail(`${path}/${escapePointer(property.key)}`, 'Core properties omit a required Property.');
978
978
  continue;
979
979
  }
980
+ if (property.declaration.auto !== undefined)
981
+ fail(`${path}/${escapePointer(property.key)}`, 'Core properties cannot author an automatic Property.');
980
982
  if (validateValueProgram(property.entry.values[property.declaration.value], values[property.key])
981
983
  .length > 0)
982
984
  fail(`${path}/${escapePointer(property.key)}`, 'Core Property value does not satisfy its exact contract.');
@@ -0,0 +1,10 @@
1
+ import type { Domain } from '../domain/model/domain.js';
2
+ import type { CompiledSchema, DomainOfCompiled } from './model/schema.js';
3
+ declare const GENERATED_COMPILED_SCHEMA: unique symbol;
4
+ /** Exact compiled material embedded by an Astrale build generator. */
5
+ export interface GeneratedCompiledSchema<Resolved = Domain> extends CompiledSchema<Resolved> {
6
+ readonly [GENERATED_COMPILED_SCHEMA]: 'generated-compiled-schema';
7
+ }
8
+ /** Realize immutable, build-owned compiled material without repeating external admission. */
9
+ export declare function load<const Input extends GeneratedCompiledSchema>(input: Input): DomainOfCompiled<Input>;
10
+ export {};
@@ -0,0 +1,15 @@
1
+ import { realize } from './loader/load.js';
2
+ /** Realize immutable, build-owned compiled material without repeating external admission. */
3
+ export function load(input) {
4
+ return realize(deepFreeze(input));
5
+ }
6
+ function deepFreeze(input, seen = new WeakSet()) {
7
+ if (input === null || typeof input !== 'object' || seen.has(input))
8
+ return input;
9
+ seen.add(input);
10
+ for (const value of Object.values(input))
11
+ deepFreeze(value, seen);
12
+ if (!Object.isFrozen(input))
13
+ Object.freeze(input);
14
+ return input;
15
+ }
@@ -2,3 +2,8 @@ import type { CompiledSchema, DomainOfCompiled } from '../model/schema.js';
2
2
  /** Load admitted compiled data through the one resolved Domain constructor. */
3
3
  export declare function load<const Input extends CompiledSchema>(input: Input): DomainOfCompiled<Input>;
4
4
  export declare function load(input: unknown): import('../../domain/model/domain.js').Domain;
5
+ /**
6
+ * Realize compiled material whose exact embedded bytes were already proven by generated build code.
7
+ * External bytes and caller-provided values must continue through {@link load}.
8
+ */
9
+ export declare function realize(compiled: CompiledSchema): import('../../domain/model/domain.js').Domain;
@@ -5,7 +5,13 @@ import { combineDomainValidation, createDomainValidation, unknownInputField, } f
5
5
  import { validateValueProgram } from '../../language/value/evaluate/program.js';
6
6
  import { acceptCompiledSchema } from '../admission/accept.js';
7
7
  export function load(input) {
8
- const compiled = acceptCompiledSchema(input);
8
+ return realize(acceptCompiledSchema(input));
9
+ }
10
+ /**
11
+ * Realize compiled material whose exact embedded bytes were already proven by generated build code.
12
+ * External bytes and caller-provided values must continue through {@link load}.
13
+ */
14
+ export function realize(compiled) {
9
15
  const entries = new Map(compiled.closure.map((entry) => [entry.origin, loadEntry(entry)]));
10
16
  const root = entries.get(compiled.root.origin);
11
17
  if (root === undefined || root.entry.revision !== compiled.root.revision) {
@@ -68,6 +68,6 @@ export interface CompiledSchema<Resolved = Domain> {
68
68
  readonly version: 1;
69
69
  readonly root: DomainDependency;
70
70
  readonly closure: readonly CompiledSchemaEntry[];
71
- readonly [COMPILED_DOMAIN]?: Resolved;
71
+ readonly [COMPILED_DOMAIN]: Resolved;
72
72
  }
73
73
  export type DomainOfCompiled<Value extends CompiledSchema> = Value extends CompiledSchema<infer Resolved> ? Resolved : Domain;
@@ -92,9 +92,11 @@ function endpointSatisfies(environment, endpoint, accepts) {
92
92
  function validateCreationProperties(definition, properties, registry, code, pointer, diagnostics) {
93
93
  const schema = {
94
94
  type: 'object',
95
- properties: Object.fromEntries([...definition.properties].map(([name, field]) => [name, field.schema])),
95
+ properties: Object.fromEntries([...definition.properties]
96
+ .filter(([, field]) => field.auto === undefined)
97
+ .map(([name, field]) => [name, field.schema])),
96
98
  required: [...definition.properties]
97
- .filter(([, field]) => field.required)
99
+ .filter(([, field]) => field.required && field.auto === undefined)
98
100
  .map(([name]) => name)
99
101
  .sort(compareUnicode),
100
102
  additionalProperties: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-dsl",
3
- "version": "0.2.0-beta.12",
3
+ "version": "0.2.0-beta.13",
4
4
  "description": "Astrale Kernel DSL - Schema authoring, inference, and IR serialization",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -43,6 +43,10 @@
43
43
  "types": "./dist/v1/compiled/index.d.ts",
44
44
  "import": "./dist/v1/compiled/index.js"
45
45
  },
46
+ "./v1/compiled/generated": {
47
+ "types": "./dist/v1/compiled/generated.d.ts",
48
+ "import": "./dist/v1/compiled/generated.js"
49
+ },
46
50
  "./v1/compiled/loader": {
47
51
  "types": "./dist/v1/compiled/loader/index.d.ts",
48
52
  "import": "./dist/v1/compiled/loader/index.js"