@astrale-os/kernel-dsl 1.0.0-beta.17 → 1.0.0-beta.18
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,9 +1,9 @@
|
|
|
1
|
-
import type { Value as PortableValue } from '@astrale-os/kernel-dsl/value';
|
|
1
|
+
import type { Array as PortableArray, Object as PortableObject, Value as PortableValue } from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { ClassRef } from '../../addressing/index.js';
|
|
4
4
|
import type { ResolvedClass, ResolvedProperty } from '../../language/class/resolved.js';
|
|
5
5
|
import type { StateTopologyOf } from '../../language/state/topology.js';
|
|
6
|
-
import type { BlobReceipt, BlobRef, BlobSchema } from '../../language/value/model/blob.js';
|
|
6
|
+
import type { BLOB_VALUE_KIND, BlobReceipt, BlobRef, BlobSchema } from '../../language/value/model/blob.js';
|
|
7
7
|
import type { Method, ProjectionOfCallable } from '../callable/authoring.js';
|
|
8
8
|
import type { ClassProjectionOfResolved } from '../schema/projection.js';
|
|
9
9
|
import type { TypedValueSchema } from '../value/schema.js';
|
|
@@ -14,8 +14,44 @@ import type { AutoProperty, Property, PropertyOptions, PropertyStateMachineOf, V
|
|
|
14
14
|
type ExactEndpointInput<Input, Shape> = Input & Record<Exclude<keyof Input, keyof Shape>, never>;
|
|
15
15
|
type PropertySchemaOf<Field> = Field extends AutoProperty<infer Value> ? PropertySchemaOf<Value> : Field extends Property<infer Schema, PropertyOptions, unknown> ? Schema : Field;
|
|
16
16
|
type PropertyOptionsOf<Field> = Field extends AutoProperty<infer Value> ? PropertyOptionsOf<Value> : Field extends Property<ValueSchemaInput, infer Options, unknown> ? Options : Record<never, never>;
|
|
17
|
-
type
|
|
18
|
-
|
|
17
|
+
type JsonSchemaValueOf<Schema> = 0 extends 1 & Schema ? PortableValue : Schema extends {
|
|
18
|
+
readonly const: infer Value;
|
|
19
|
+
} ? JsonKnownOf<Value> : Schema extends {
|
|
20
|
+
readonly enum: readonly (infer Value)[];
|
|
21
|
+
} ? JsonKnownOf<Value> : Schema extends {
|
|
22
|
+
readonly anyOf: readonly (infer Branch)[];
|
|
23
|
+
} ? JsonSchemaValueOf<Branch> : Schema extends {
|
|
24
|
+
readonly oneOf: readonly (infer Branch)[];
|
|
25
|
+
} ? JsonSchemaValueOf<Branch> : Schema extends {
|
|
26
|
+
readonly type: infer Type;
|
|
27
|
+
} ? JsonTypeValueOf<Type, Schema> : PortableValue;
|
|
28
|
+
type JsonKnownOf<Value> = 0 extends 1 & Value ? PortableValue : Value;
|
|
29
|
+
type JsonTypeValueOf<Type, Schema> = Type extends readonly (infer Each)[] ? JsonTypeValueOf<Each, Schema> : Type extends 'string' ? string : Type extends 'number' | 'integer' ? number : Type extends 'boolean' ? boolean : Type extends 'null' ? null : Type extends 'array' ? JsonArrayValueOf<Schema> : Type extends 'object' ? JsonObjectValueOf<Schema> : PortableValue;
|
|
30
|
+
type JsonArrayValueOf<Schema> = 'prefixItems' extends keyof Schema ? PortableArray : Schema extends {
|
|
31
|
+
readonly items: infer Items;
|
|
32
|
+
} ? readonly JsonSchemaValueOf<Items>[] : PortableArray;
|
|
33
|
+
type JsonObjectValueOf<Schema> = 'patternProperties' extends keyof Schema ? PortableObject : Schema extends {
|
|
34
|
+
readonly properties: infer Properties extends Readonly<Record<string, unknown>>;
|
|
35
|
+
readonly additionalProperties: false;
|
|
36
|
+
} ? JsonClosedObjectOf<Properties, Schema extends {
|
|
37
|
+
readonly required: infer Names;
|
|
38
|
+
} ? Names : readonly []> : PortableObject;
|
|
39
|
+
type JsonListsName<Names, Name> = [Names] extends [never] ? false : Names extends readonly unknown[] ? number extends Names['length'] ? false : true extends {
|
|
40
|
+
[At in keyof Names]: JsonNamesExactly<Names[At], Name>;
|
|
41
|
+
}[number] ? true : false : false;
|
|
42
|
+
type JsonNamesExactly<Element, Name> = [Element] extends [never] ? false : 0 extends 1 & Element ? false : [Element] extends [Name] ? true : false;
|
|
43
|
+
type JsonClosedObjectOf<Properties, Names> = [keyof Properties] extends [never] ? Readonly<Record<string, never>> : {
|
|
44
|
+
readonly [Name in keyof Properties as JsonListsName<Names, Name> extends true ? Name : never]: JsonSchemaValueOf<Properties[Name]>;
|
|
45
|
+
} & {
|
|
46
|
+
readonly [Name in keyof Properties as JsonListsName<Names, Name> extends true ? never : Name]?: JsonSchemaValueOf<Properties[Name]>;
|
|
47
|
+
} extends infer Value ? {
|
|
48
|
+
[Name in keyof Value]: Value[Name];
|
|
49
|
+
} : never;
|
|
50
|
+
type BlobMarkedSchema = BlobSchema | {
|
|
51
|
+
readonly 'x-astrale-value-kind': typeof BLOB_VALUE_KIND;
|
|
52
|
+
};
|
|
53
|
+
type ValueInputOf<Schema> = Schema extends BlobMarkedSchema ? BlobReceipt : Schema extends TypedValueSchema<infer Value> ? Value : Schema extends z.ZodType ? z.input<Schema> : JsonSchemaValueOf<Schema>;
|
|
54
|
+
type ValueOutputOf<Schema> = Schema extends BlobMarkedSchema ? BlobRef : Schema extends TypedValueSchema<infer Value> ? Value : Schema extends z.ZodType ? z.output<Schema> : JsonSchemaValueOf<Schema>;
|
|
19
55
|
type PropertyRequiredOf<Field> = PropertyOptionsOf<Field> extends {
|
|
20
56
|
readonly required: infer Required extends boolean;
|
|
21
57
|
} ? Required : undefined extends ValueInputOf<PropertySchemaOf<Field>> ? false : true;
|