@astrale-os/kernel-dsl 1.0.0-beta.21 → 1.0.0-beta.23

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.
Files changed (35) hide show
  1. package/dist/v1/builder/index.d.ts +2 -0
  2. package/dist/v1/builder/index.js +1 -0
  3. package/dist/v1/builder/lowering/value/compile.js +5 -1
  4. package/dist/v1/builder/lowering/value/file.d.ts +7 -0
  5. package/dist/v1/builder/lowering/value/file.js +14 -0
  6. package/dist/v1/builder/lowering/value/zod.js +30 -0
  7. package/dist/v1/builder/schema/diagnostic.d.ts +1 -1
  8. package/dist/v1/builder/value/file.d.ts +34 -0
  9. package/dist/v1/builder/value/file.js +77 -0
  10. package/dist/v1/index.d.ts +2 -2
  11. package/dist/v1/index.js +1 -1
  12. package/dist/v1/language/.spec/schemas/value-schema.schema.json +2 -1
  13. package/dist/v1/language/validation/rule.js +2 -2
  14. package/dist/v1/language/value/files.d.ts +44 -0
  15. package/dist/v1/language/value/files.js +150 -0
  16. package/dist/v1/language/value/inclusion/evidence.js +2 -0
  17. package/dist/v1/language/value/inclusion/types.js +23 -0
  18. package/dist/v1/language/value/model/file.d.ts +41 -0
  19. package/dist/v1/language/value/model/file.js +122 -0
  20. package/dist/v1/language/value/profile/meta-schema.compiled.d.ts +1 -0
  21. package/dist/v1/language/value/profile/meta-schema.compiled.js +18 -5
  22. package/dist/v1/language/value/profile/rules.js +10 -1
  23. package/dist/v1/language/value/profile/vocabulary.d.ts +7 -6
  24. package/dist/v1/language/value/profile/vocabulary.js +7 -1
  25. package/dist/v1/language/value/regexp/unicode.d.ts +1 -1
  26. package/dist/v1/language/value/regexp/unicode.js +1 -1
  27. package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +48 -7
  28. package/dist/v1/schema/validation/domain.json-schema.js +27 -2
  29. package/dist/v1/schema/validation/domain.structure.d.ts +49 -46
  30. package/dist/v1/schema/validation/domain.structure.js +140 -50
  31. package/dist/v1/schema/validation/value-api.d.ts +4 -0
  32. package/dist/v1/schema/validation/value-api.js +2 -0
  33. package/dist/v1/schema/validation/value.json-schema.d.ts +5 -0
  34. package/dist/v1/schema/validation/value.json-schema.js +30 -4
  35. package/package.json +3 -3
@@ -0,0 +1,122 @@
1
+ import { json } from '@astrale-os/kernel-dsl/value';
2
+ import { canonicalMediaType, isBlobValueSchema } from './blob.js';
3
+ import { isValueObject as isJsonObject } from './object.js';
4
+ export const FILE_VALUE_KIND = 'file';
5
+ /** The keyword that carries a file field's constraints, beside `x-astrale-value-kind: file`. */
6
+ export const FILE_KEYWORD = 'x-astrale-file';
7
+ /** Annotation keywords a file field may carry beside its canonical shape. */
8
+ const FILE_ANNOTATIONS = new Set([
9
+ '$comment',
10
+ 'deprecated',
11
+ 'description',
12
+ 'title',
13
+ ]);
14
+ /**
15
+ * The one canonical V1 schema of a file field: an upload receipt on the wire, with the constraints
16
+ * of the file it names under `x-astrale-file` when there are any.
17
+ */
18
+ export function file(options = {}) {
19
+ const constraints = acceptFileOptions(options);
20
+ return Object.freeze({
21
+ type: 'string',
22
+ 'x-astrale-value-kind': FILE_VALUE_KIND,
23
+ ...(Object.keys(constraints).length === 0 ? {} : { [FILE_KEYWORD]: constraints }),
24
+ });
25
+ }
26
+ /** Marker recognition on an already admitted V1 value schema. */
27
+ export function isFileValueSchema(input) {
28
+ return isJsonObject(input) && input['x-astrale-value-kind'] === FILE_VALUE_KIND;
29
+ }
30
+ /** The constraints a file field states. */
31
+ export function fileOptionsOf(schema) {
32
+ const constraints = schema[FILE_KEYWORD];
33
+ if (!isJsonObject(constraints))
34
+ return Object.freeze({});
35
+ return Object.freeze({
36
+ ...(typeof constraints.maxBytes === 'number' ? { maxBytes: constraints.maxBytes } : {}),
37
+ ...(Array.isArray(constraints.mediaTypes)
38
+ ? { mediaTypes: Object.freeze(constraints.mediaTypes.filter(isString)) }
39
+ : {}),
40
+ });
41
+ }
42
+ /** The constraints of a blob Property, as a file field that feeds it states them. */
43
+ export function blobFileOptions(schema) {
44
+ if (!isBlobValueSchema(schema))
45
+ throw new TypeError('File source is not a blob schema.');
46
+ const properties = isJsonObject(schema.properties) ? schema.properties : {};
47
+ const size = isJsonObject(properties.size) ? properties.size : {};
48
+ const mediaType = isJsonObject(properties.mediaType) ? properties.mediaType : {};
49
+ return acceptFileOptions({
50
+ ...(typeof size.maximum === 'number' ? { maxBytes: size.maximum } : {}),
51
+ ...(Array.isArray(mediaType.enum) ? { mediaTypes: mediaType.enum.filter(isString) } : {}),
52
+ });
53
+ }
54
+ /**
55
+ * `base` tightened by `tighter`: a lower `maxBytes`, a subset of `mediaTypes`. A constraint
56
+ * `tighter` would loosen is refused.
57
+ */
58
+ export function tightenFileOptions(base, tighter) {
59
+ const from = acceptFileOptions(base);
60
+ const next = acceptFileOptions(tighter);
61
+ if (next.maxBytes !== undefined && from.maxBytes !== undefined && next.maxBytes > from.maxBytes) {
62
+ throw new TypeError('A file field cannot raise the maxBytes of its source.');
63
+ }
64
+ if (next.mediaTypes !== undefined &&
65
+ from.mediaTypes !== undefined &&
66
+ !next.mediaTypes.every((mediaType) => from.mediaTypes.includes(mediaType))) {
67
+ throw new TypeError('A file field cannot admit a media type its source refuses.');
68
+ }
69
+ const maxBytes = next.maxBytes ?? from.maxBytes;
70
+ const mediaTypes = next.mediaTypes ?? from.mediaTypes;
71
+ return Object.freeze({
72
+ ...(maxBytes === undefined ? {} : { maxBytes }),
73
+ ...(mediaTypes === undefined ? {} : { mediaTypes }),
74
+ });
75
+ }
76
+ /** Whether `schema` is exactly one `file(...)` output, plus annotation keywords. */
77
+ export function isCanonicalFileSchema(schema) {
78
+ const shape = {};
79
+ for (const [keyword, value] of Object.entries(schema)) {
80
+ if (!FILE_ANNOTATIONS.has(keyword))
81
+ shape[keyword] = value;
82
+ }
83
+ const constraints = shape[FILE_KEYWORD];
84
+ if (constraints !== undefined && !isJsonObject(constraints))
85
+ return false;
86
+ try {
87
+ const options = constraints === undefined ? {} : constraints;
88
+ return json.serialize(shape) === json.serialize(file(options));
89
+ }
90
+ catch {
91
+ return false;
92
+ }
93
+ }
94
+ /** Canonical file options: positive safe-integer bound, sorted unique canonical media types. */
95
+ export function acceptFileOptions(options) {
96
+ if (options === null || typeof options !== 'object' || Array.isArray(options)) {
97
+ throw new TypeError('File options are invalid.');
98
+ }
99
+ for (const key of Object.keys(options)) {
100
+ if (key !== 'maxBytes' && key !== 'mediaTypes') {
101
+ throw new TypeError(`File option ${key} is unknown.`);
102
+ }
103
+ }
104
+ const { maxBytes, mediaTypes } = options;
105
+ if (maxBytes !== undefined && (!Number.isSafeInteger(maxBytes) || maxBytes < 1)) {
106
+ throw new TypeError('File maxBytes must be a positive safe integer.');
107
+ }
108
+ let canonical;
109
+ if (mediaTypes !== undefined) {
110
+ if (!Array.isArray(mediaTypes) || mediaTypes.length === 0) {
111
+ throw new TypeError('File mediaTypes must be a non-empty list.');
112
+ }
113
+ canonical = Object.freeze([...new Set(mediaTypes.map(canonicalMediaType))].sort());
114
+ }
115
+ return Object.freeze({
116
+ ...(maxBytes === undefined ? {} : { maxBytes }),
117
+ ...(canonical === undefined ? {} : { mediaTypes: canonical }),
118
+ });
119
+ }
120
+ function isString(input) {
121
+ return typeof input === 'string';
122
+ }
@@ -9,6 +9,7 @@ declare namespace validate20 {
9
9
  var evaluated: {
10
10
  props: {
11
11
  fullMatch: boolean;
12
+ "x-astrale-file": boolean;
12
13
  "x-astrale-path": boolean;
13
14
  definitions: boolean;
14
15
  dependencies: boolean;
@@ -4,7 +4,7 @@
4
4
  "use strict";
5
5
  export const validate = validate20;
6
6
  export default validate20;
7
- const schema31 = { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://schemas.astrale.ai/dsl/v1/value-schema", "$dynamicAnchor": "meta", "$vocabulary": { "https://json-schema.org/draft/2020-12/vocab/core": true, "https://json-schema.org/draft/2020-12/vocab/applicator": true, "https://json-schema.org/draft/2020-12/vocab/unevaluated": true, "https://json-schema.org/draft/2020-12/vocab/validation": true, "https://json-schema.org/draft/2020-12/vocab/meta-data": true, "https://json-schema.org/draft/2020-12/vocab/format-annotation": true, "https://json-schema.org/draft/2020-12/vocab/content": true, "https://schemas.astrale.ai/dsl/v1/value-schema/vocabulary": true }, "title": "Astrale V1 value schema", "$comment": "The meta-schema of the V1 value-schema dialect: Draft 2020-12 and the required Astrale vocabulary (fullMatch, x-astrale-path, x-astrale-value-kind). Its $dynamicAnchor extends Draft 2020-12 at every subschema, not only the root. The rules of the profile beyond it are published as schema.values.RULES.", "allOf": [{ "$ref": "https://json-schema.org/draft/2020-12/schema" }], "properties": { "fullMatch": { "type": "string" }, "x-astrale-path": { "type": "object" } } };
7
+ const schema31 = { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://schemas.astrale.ai/dsl/v1/value-schema", "$dynamicAnchor": "meta", "$vocabulary": { "https://json-schema.org/draft/2020-12/vocab/core": true, "https://json-schema.org/draft/2020-12/vocab/applicator": true, "https://json-schema.org/draft/2020-12/vocab/unevaluated": true, "https://json-schema.org/draft/2020-12/vocab/validation": true, "https://json-schema.org/draft/2020-12/vocab/meta-data": true, "https://json-schema.org/draft/2020-12/vocab/format-annotation": true, "https://json-schema.org/draft/2020-12/vocab/content": true, "https://schemas.astrale.ai/dsl/v1/value-schema/vocabulary": true }, "title": "Astrale V1 value schema", "$comment": "The meta-schema of the V1 value-schema dialect: Draft 2020-12 and the required Astrale vocabulary (fullMatch, x-astrale-file, x-astrale-path, x-astrale-value-kind). Its $dynamicAnchor extends Draft 2020-12 at every subschema, not only the root. The rules of the profile beyond it are published as schema.values.RULES.", "allOf": [{ "$ref": "https://json-schema.org/draft/2020-12/schema" }], "properties": { "fullMatch": { "type": "string" }, "x-astrale-file": { "type": "object" }, "x-astrale-path": { "type": "object" } } };
8
8
  const schema0 = { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://json-schema.org/draft/2020-12/schema", "$vocabulary": { "https://json-schema.org/draft/2020-12/vocab/core": true, "https://json-schema.org/draft/2020-12/vocab/applicator": true, "https://json-schema.org/draft/2020-12/vocab/unevaluated": true, "https://json-schema.org/draft/2020-12/vocab/validation": true, "https://json-schema.org/draft/2020-12/vocab/meta-data": true, "https://json-schema.org/draft/2020-12/vocab/format-annotation": true, "https://json-schema.org/draft/2020-12/vocab/content": true }, "$dynamicAnchor": "meta", "title": "Core and Validation specifications meta-schema", "allOf": [{ "$ref": "meta/core" }, { "$ref": "meta/applicator" }, { "$ref": "meta/unevaluated" }, { "$ref": "meta/validation" }, { "$ref": "meta/meta-data" }, { "$ref": "meta/format-annotation" }, { "$ref": "meta/content" }], "type": ["object", "boolean"], "$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.", "properties": { "definitions": { "$comment": "\"definitions\" has been replaced by \"$defs\".", "type": "object", "additionalProperties": { "$dynamicRef": "#meta" }, "deprecated": true, "default": {} }, "dependencies": { "$comment": "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.", "type": "object", "additionalProperties": { "anyOf": [{ "$dynamicRef": "#meta" }, { "$ref": "meta/validation#/$defs/stringArray" }] }, "deprecated": true, "default": {} }, "$recursiveAnchor": { "$comment": "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".", "$ref": "meta/core#/$defs/anchorString", "deprecated": true }, "$recursiveRef": { "$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".", "$ref": "meta/core#/$defs/uriReferenceString", "deprecated": true } } };
9
9
  const schema23 = { "type": "array", "items": { "type": "string" }, "uniqueItems": true, "default": [] };
10
10
  const schema5 = { "type": "string", "pattern": "^[A-Za-z_][-A-Za-z0-9._]*$" };
@@ -2062,10 +2062,10 @@ function validate20(data, { instancePath = "", parentData, parentDataProperty, r
2062
2062
  errors++;
2063
2063
  }
2064
2064
  }
2065
- if (data["x-astrale-path"] !== undefined) {
2066
- let data1 = data["x-astrale-path"];
2065
+ if (data["x-astrale-file"] !== undefined) {
2066
+ let data1 = data["x-astrale-file"];
2067
2067
  if (!(data1 && typeof data1 == "object" && !Array.isArray(data1))) {
2068
- const err1 = { instancePath: instancePath + "/x-astrale-path", schemaPath: "#/properties/x-astrale-path/type", keyword: "type", params: { type: "object" }, message: "must be object" };
2068
+ const err1 = { instancePath: instancePath + "/x-astrale-file", schemaPath: "#/properties/x-astrale-file/type", keyword: "type", params: { type: "object" }, message: "must be object" };
2069
2069
  if (vErrors === null) {
2070
2070
  vErrors = [err1];
2071
2071
  }
@@ -2075,8 +2075,21 @@ function validate20(data, { instancePath = "", parentData, parentDataProperty, r
2075
2075
  errors++;
2076
2076
  }
2077
2077
  }
2078
+ if (data["x-astrale-path"] !== undefined) {
2079
+ let data2 = data["x-astrale-path"];
2080
+ if (!(data2 && typeof data2 == "object" && !Array.isArray(data2))) {
2081
+ const err2 = { instancePath: instancePath + "/x-astrale-path", schemaPath: "#/properties/x-astrale-path/type", keyword: "type", params: { type: "object" }, message: "must be object" };
2082
+ if (vErrors === null) {
2083
+ vErrors = [err2];
2084
+ }
2085
+ else {
2086
+ vErrors.push(err2);
2087
+ }
2088
+ errors++;
2089
+ }
2090
+ }
2078
2091
  }
2079
2092
  validate20.errors = vErrors;
2080
2093
  return errors === 0;
2081
2094
  }
2082
- validate20.evaluated = { "props": { "fullMatch": true, "x-astrale-path": true, "definitions": true, "dependencies": true, "$recursiveAnchor": true, "$recursiveRef": true, "contentEncoding": true, "contentMediaType": true, "contentSchema": true, "format": true, "title": true, "description": true, "default": true, "deprecated": true, "readOnly": true, "writeOnly": true, "examples": true, "type": true, "const": true, "enum": true, "multipleOf": true, "maximum": true, "exclusiveMaximum": true, "minimum": true, "exclusiveMinimum": true, "maxLength": true, "minLength": true, "pattern": true, "maxItems": true, "minItems": true, "uniqueItems": true, "maxContains": true, "minContains": true, "maxProperties": true, "minProperties": true, "required": true, "dependentRequired": true, "unevaluatedItems": true, "unevaluatedProperties": true, "prefixItems": true, "items": true, "contains": true, "additionalProperties": true, "properties": true, "patternProperties": true, "dependentSchemas": true, "propertyNames": true, "if": true, "then": true, "else": true, "allOf": true, "anyOf": true, "oneOf": true, "not": true, "$id": true, "$schema": true, "$ref": true, "$anchor": true, "$dynamicRef": true, "$dynamicAnchor": true, "$vocabulary": true, "$comment": true, "$defs": true }, "dynamicProps": false, "dynamicItems": false };
2095
+ validate20.evaluated = { "props": { "fullMatch": true, "x-astrale-file": true, "x-astrale-path": true, "definitions": true, "dependencies": true, "$recursiveAnchor": true, "$recursiveRef": true, "contentEncoding": true, "contentMediaType": true, "contentSchema": true, "format": true, "title": true, "description": true, "default": true, "deprecated": true, "readOnly": true, "writeOnly": true, "examples": true, "type": true, "const": true, "enum": true, "multipleOf": true, "maximum": true, "exclusiveMaximum": true, "minimum": true, "exclusiveMinimum": true, "maxLength": true, "minLength": true, "pattern": true, "maxItems": true, "minItems": true, "uniqueItems": true, "maxContains": true, "minContains": true, "maxProperties": true, "minProperties": true, "required": true, "dependentRequired": true, "unevaluatedItems": true, "unevaluatedProperties": true, "prefixItems": true, "items": true, "contains": true, "additionalProperties": true, "properties": true, "patternProperties": true, "dependentSchemas": true, "propertyNames": true, "if": true, "then": true, "else": true, "allOf": true, "anyOf": true, "oneOf": true, "not": true, "$id": true, "$schema": true, "$ref": true, "$anchor": true, "$dynamicRef": true, "$dynamicAnchor": true, "$vocabulary": true, "$comment": true, "$defs": true }, "dynamicProps": false, "dynamicItems": false };
@@ -1,6 +1,7 @@
1
1
  import { json } from '@astrale-os/kernel-dsl/value';
2
2
  import { diagnostic } from '../../validation/diagnostic.js';
3
3
  import { blob, BLOB_VALUE_KIND } from '../model/blob.js';
4
+ import { FILE_KEYWORD, FILE_VALUE_KIND, isCanonicalFileSchema } from '../model/file.js';
4
5
  import { isValueObject as isJsonObject } from '../model/object.js';
5
6
  import { VALUE_SCHEMA_DIALECT } from '../model/schema.js';
6
7
  import { refuseIRegexp, stateBudgetMessage } from '../regexp/syntax.js';
@@ -42,9 +43,17 @@ export function validateSchemaProfile(schema, context, pointer) {
42
43
  return diagnostics;
43
44
  }
44
45
  function validateValueKind(schema, context, depth, pointer, diagnostics) {
46
+ if (Object.hasOwn(schema, FILE_KEYWORD) && schema['x-astrale-value-kind'] !== FILE_VALUE_KIND) {
47
+ diagnostics.push(diagnostic('VS_VALUE_KIND', `${pointer}/${FILE_KEYWORD}`, 'x-astrale-file states the constraints of a file field only, beside x-astrale-value-kind file.'));
48
+ }
45
49
  if (!Object.hasOwn(schema, 'x-astrale-value-kind'))
46
50
  return;
47
- if (schema['x-astrale-value-kind'] === BLOB_VALUE_KIND) {
51
+ if (schema['x-astrale-value-kind'] === FILE_VALUE_KIND) {
52
+ if (context !== 'callable-input' || !isCanonicalFileSchema(schema)) {
53
+ diagnostics.push(diagnostic('VS_VALUE_KIND', `${pointer}/x-astrale-value-kind`, 'file must be exactly a schema.values.file output, inside a callable input.'));
54
+ }
55
+ }
56
+ else if (schema['x-astrale-value-kind'] === BLOB_VALUE_KIND) {
48
57
  if (context !== 'property-facet' || depth !== 0 || !isCanonicalBlobSchema(schema)) {
49
58
  diagnostics.push(diagnostic('VS_VALUE_KIND', `${pointer}/x-astrale-value-kind`, 'blob must be the exact schema.values.blob output at the root of a Node property.'));
50
59
  }
@@ -1,8 +1,8 @@
1
- declare const keywords: readonly ['$anchor', '$comment', '$defs', '$dynamicAnchor', '$dynamicRef', '$id', '$ref', '$schema', '$vocabulary', 'additionalProperties', 'allOf', 'anyOf', 'const', 'contains', 'contentEncoding', 'contentMediaType', 'contentSchema', 'default', 'dependentRequired', 'dependentSchemas', 'deprecated', 'description', 'else', 'enum', 'examples', 'exclusiveMaximum', 'exclusiveMinimum', 'format', 'fullMatch', 'if', 'items', 'maxContains', 'maxItems', 'maxLength', 'maxProperties', 'maximum', 'minContains', 'minItems', 'minLength', 'minProperties', 'minimum', 'multipleOf', 'not', 'oneOf', 'pattern', 'patternProperties', 'prefixItems', 'properties', 'propertyNames', 'readOnly', 'required', 'then', 'title', 'type', 'unevaluatedItems', 'unevaluatedProperties', 'uniqueItems', 'writeOnly', 'x-astrale-path', 'x-astrale-value-kind'];
1
+ declare const keywords: readonly ['$anchor', '$comment', '$defs', '$dynamicAnchor', '$dynamicRef', '$id', '$ref', '$schema', '$vocabulary', 'additionalProperties', 'allOf', 'anyOf', 'const', 'contains', 'contentEncoding', 'contentMediaType', 'contentSchema', 'default', 'dependentRequired', 'dependentSchemas', 'deprecated', 'description', 'else', 'enum', 'examples', 'exclusiveMaximum', 'exclusiveMinimum', 'format', 'fullMatch', 'if', 'items', 'maxContains', 'maxItems', 'maxLength', 'maxProperties', 'maximum', 'minContains', 'minItems', 'minLength', 'minProperties', 'minimum', 'multipleOf', 'not', 'oneOf', 'pattern', 'patternProperties', 'prefixItems', 'properties', 'propertyNames', 'readOnly', 'required', 'then', 'title', 'type', 'unevaluatedItems', 'unevaluatedProperties', 'uniqueItems', 'writeOnly', 'x-astrale-file', 'x-astrale-path', 'x-astrale-value-kind'];
2
2
  export type ValueKeyword = (typeof keywords)[number];
3
3
  /**
4
4
  * The closed V1 vocabulary: every keyword a value schema may name, the Astrale profile's included
5
- * (`fullMatch`, `x-astrale-path`, `x-astrale-value-kind`). Any other keyword is refused
5
+ * (`fullMatch`, `x-astrale-file`, `x-astrale-path`, `x-astrale-value-kind`). Any other keyword is refused
6
6
  * (`VS_KEYWORD_CLOSED`). Other rules restrict some of these: the forbidden keywords never appear,
7
7
  * `$id` never, `$schema` only at the root. Frozen and Unicode-ordered.
8
8
  */
@@ -23,13 +23,14 @@ export interface DeclaredValueKind {
23
23
  /** The JSON type of its values, which the schema states beside the declaration. */
24
24
  readonly type: 'string' | 'object';
25
25
  /**
26
- * Where a schema may declare it: at any location of any value schema, or only as the whole
27
- * schema of a Node Property that is neither automatic nor a State Property.
26
+ * Where a schema may declare it: at any location of any value schema, only as the whole schema
27
+ * of a Node Property that is neither automatic nor a State Property, or at any location of a
28
+ * callable input.
28
29
  */
29
- readonly placement: 'any' | 'node-property';
30
+ readonly placement: 'any' | 'node-property' | 'callable-input';
30
31
  /** The kind, in one plain sentence. */
31
32
  readonly statement: string;
32
33
  }
33
34
  /** The value kinds `x-astrale-value-kind` declares; it admits no other value. */
34
- export declare const DECLARED_VALUE_KINDS: Readonly<Record<'instant' | 'blob', DeclaredValueKind>>;
35
+ export declare const DECLARED_VALUE_KINDS: Readonly<Record<'instant' | 'blob' | 'file', DeclaredValueKind>>;
35
36
  export {};
@@ -57,12 +57,13 @@ const keywords = [
57
57
  'unevaluatedProperties',
58
58
  'uniqueItems',
59
59
  'writeOnly',
60
+ 'x-astrale-file',
60
61
  'x-astrale-path',
61
62
  'x-astrale-value-kind',
62
63
  ];
63
64
  /**
64
65
  * The closed V1 vocabulary: every keyword a value schema may name, the Astrale profile's included
65
- * (`fullMatch`, `x-astrale-path`, `x-astrale-value-kind`). Any other keyword is refused
66
+ * (`fullMatch`, `x-astrale-file`, `x-astrale-path`, `x-astrale-value-kind`). Any other keyword is refused
66
67
  * (`VS_KEYWORD_CLOSED`). Other rules restrict some of these: the forbidden keywords never appear,
67
68
  * `$id` never, `$schema` only at the root. Frozen and Unicode-ordered.
68
69
  */
@@ -112,4 +113,9 @@ export const DECLARED_VALUE_KINDS = Object.freeze({
112
113
  placement: 'node-property',
113
114
  statement: 'The Ref of stored contents, its digest, media type and size: the schema is exactly a values.blob output, and the Property is written with an upload receipt.',
114
115
  }),
116
+ file: Object.freeze({
117
+ type: 'string',
118
+ placement: 'callable-input',
119
+ statement: 'An upload receipt of the caller, naming one file the callable receives: the schema is exactly a values.file output, whose x-astrale-file states the maxBytes and mediaTypes a client checks before it uploads.',
120
+ }),
115
121
  });
@@ -2,7 +2,7 @@
2
2
  * Unicode scalar sets for the I-Regexp compiler: the scalar space, unions and complements of ordered
3
3
  * ranges, and the General_Category table that `\p{..}` and `\P{..}` denote.
4
4
  *
5
- * The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (26.7.0 in
5
+ * The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (Node 26 in
6
6
  * `.nvmrc`, ICU 78.3), so a category denotes the same scalars on every host whatever Unicode data
7
7
  * its own `RegExp` engine carries (Node, Bun/JavaScriptCore, workerd). It was generated under that
8
8
  * Node by testing every scalar against `new RegExp('^\\p{<name>}$', 'u')` and keeping the maximal
@@ -2,7 +2,7 @@
2
2
  * Unicode scalar sets for the I-Regexp compiler: the scalar space, unions and complements of ordered
3
3
  * ranges, and the General_Category table that `\p{..}` and `\P{..}` denote.
4
4
  *
5
- * The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (26.7.0 in
5
+ * The table is pinned to Unicode 17.0, the version of the Node runtime the Kernel pins (Node 26 in
6
6
  * `.nvmrc`, ICU 78.3), so a category denotes the same scalars on every host whatever Unicode data
7
7
  * its own `RegExp` engine carries (Node, Bun/JavaScriptCore, workerd). It was generated under that
8
8
  * Node by testing every scalar against `new RegExp('^\\p{<name>}$', 'u')` and keeping the maximal
@@ -42,6 +42,17 @@
42
42
  "#/$defs/value-schema/allOf/2/anyOf/1/properties/x-astrale-value-kind"
43
43
  ]
44
44
  },
45
+ "value-file": {
46
+ "code": "DV_VALUE_SCHEMA",
47
+ "valueCode": "VS_VALUE_KIND",
48
+ "stage": "rule",
49
+ "statement": "A file is declared only inside a callable input, exactly as values.file writes it, and x-astrale-file only beside it.",
50
+ "positions": [
51
+ "#/$defs/value-location/anyOf/1/properties/x-astrale-file",
52
+ "#/$defs/value-schema/allOf/2/anyOf/1/properties/x-astrale-value-kind",
53
+ "#/$defs/value-subschema/allOf/1/anyOf/1/properties/x-astrale-value-kind"
54
+ ]
55
+ },
45
56
  "value-path": {
46
57
  "code": "DV_VALUE_SCHEMA",
47
58
  "valueCode": "VS_PATH_EXTENSION",
@@ -572,9 +583,9 @@
572
583
  },
573
584
  "core-slug": {
574
585
  "type": "string",
586
+ "pattern": "^(?=.{1,100}$)[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)*$",
575
587
  "minLength": 1,
576
- "maxLength": 100,
577
- "pattern": "^(?=.{1,100}$)[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)*$"
588
+ "maxLength": 100
578
589
  },
579
590
  "create-policy": {
580
591
  "anyOf": [
@@ -1068,6 +1079,24 @@
1068
1079
  }
1069
1080
  ]
1070
1081
  },
1082
+ "file-annotation": {
1083
+ "type": "object",
1084
+ "properties": {
1085
+ "maxBytes": {
1086
+ "type": "integer",
1087
+ "minimum": 1
1088
+ },
1089
+ "mediaTypes": {
1090
+ "type": "array",
1091
+ "minItems": 1,
1092
+ "uniqueItems": true,
1093
+ "items": {
1094
+ "type": "string"
1095
+ }
1096
+ }
1097
+ },
1098
+ "additionalProperties": false
1099
+ },
1071
1100
  "function-definition": {
1072
1101
  "type": "object",
1073
1102
  "properties": {
@@ -1522,9 +1551,9 @@
1522
1551
  },
1523
1552
  "origin": {
1524
1553
  "type": "string",
1554
+ "pattern": "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$",
1525
1555
  "minLength": 3,
1526
- "maxLength": 253,
1527
- "pattern": "^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$"
1556
+ "maxLength": 253
1528
1557
  },
1529
1558
  "path-annotation": {
1530
1559
  "type": "object",
@@ -2183,6 +2212,7 @@
2183
2212
  "$ref": "#/$defs/incident-endpoint"
2184
2213
  }
2185
2214
  ],
2215
+ "items": false,
2186
2216
  "minItems": 2,
2187
2217
  "maxItems": 2
2188
2218
  },
@@ -2249,6 +2279,7 @@
2249
2279
  "unevaluatedProperties",
2250
2280
  "uniqueItems",
2251
2281
  "writeOnly",
2282
+ "x-astrale-file",
2252
2283
  "x-astrale-path",
2253
2284
  "x-astrale-value-kind"
2254
2285
  ]
@@ -2268,6 +2299,9 @@
2268
2299
  "pattern": {
2269
2300
  "type": "string"
2270
2301
  },
2302
+ "x-astrale-file": {
2303
+ "$ref": "#/$defs/file-annotation"
2304
+ },
2271
2305
  "x-astrale-path": {
2272
2306
  "$ref": "#/$defs/path-annotation"
2273
2307
  },
@@ -2359,7 +2393,10 @@
2359
2393
  ],
2360
2394
  "properties": {
2361
2395
  "x-astrale-value-kind": {
2362
- "const": "instant"
2396
+ "enum": [
2397
+ "instant",
2398
+ "file"
2399
+ ]
2363
2400
  }
2364
2401
  }
2365
2402
  },
@@ -2415,7 +2452,8 @@
2415
2452
  "x-astrale-value-kind": {
2416
2453
  "enum": [
2417
2454
  "instant",
2418
- "blob"
2455
+ "blob",
2456
+ "file"
2419
2457
  ]
2420
2458
  }
2421
2459
  }
@@ -2439,7 +2477,10 @@
2439
2477
  "properties": {
2440
2478
  "$schema": false,
2441
2479
  "x-astrale-value-kind": {
2442
- "const": "instant"
2480
+ "enum": [
2481
+ "instant",
2482
+ "file"
2483
+ ]
2443
2484
  }
2444
2485
  }
2445
2486
  }
@@ -2,7 +2,7 @@ import { toJSONSchema } from 'zod';
2
2
  import { VALUE_RULES } from '../../language/validation/rule.js';
3
3
  import { escapePointerToken } from '../../language/value/syntax/pointer.js';
4
4
  import { RULES } from '../rule.js';
5
- import { domainSchemaStructure, documentJsonSchema, structureRules, } from './domain.structure.js';
5
+ import { domainSchemaStructure, documentJsonSchema, structureRules, VARIANTS, } from './domain.structure.js';
6
6
  import { jsonValueJsonSchema, jsonValueRules, } from './json.json-schema.js';
7
7
  import { valueSchemaJsonSchema, valueSchemaRules, } from './value.json-schema.js';
8
8
  /** The checks the published document names, each with its stage and the positions it constrains. */
@@ -37,6 +37,8 @@ export function domainSchemaJsonSchema() {
37
37
  rendered.maxItems = def.items.length;
38
38
  },
39
39
  });
40
+ stateVariantsByAnyOf(root);
41
+ stateVariantsByAnyOf($defs);
40
42
  const unnamed = Object.keys($defs).filter((name) => name.startsWith('__schema'));
41
43
  if (unnamed.length > 0) {
42
44
  throw new Error(`Every shared part of the structure is named: ${unnamed.join(', ')} is not.`);
@@ -153,9 +155,32 @@ function isStated(schema, check) {
153
155
  }
154
156
  /** The keywords or rule registered on this very schema, which `get` would inherit from a parent. */
155
157
  function statementOf(schema) {
156
- const { id: _id, description: _description, ...statement } = documentJsonSchema._map.get(schema) ?? {};
158
+ const { id: _id, description: _description, [VARIANTS]: _variants, ...statement } = documentJsonSchema._map.get(schema) ?? {};
157
159
  return Object.keys(statement).length > 0 ? statement : undefined;
158
160
  }
161
+ /**
162
+ * Zod renders an exclusive union by `oneOf`. The structure's `variants` are exclusive only for their
163
+ * diagnostics: they never overlap, so the document states them by `anyOf`, in place, as any union.
164
+ */
165
+ function stateVariantsByAnyOf(value) {
166
+ if (Array.isArray(value)) {
167
+ for (const item of value)
168
+ stateVariantsByAnyOf(item);
169
+ return;
170
+ }
171
+ if (value === null || typeof value !== 'object')
172
+ return;
173
+ const schema = value;
174
+ if (schema[VARIANTS] !== undefined) {
175
+ const entries = Object.entries(schema).filter(([key]) => key !== VARIANTS);
176
+ for (const key of Object.keys(schema))
177
+ delete schema[key];
178
+ for (const [key, entry] of entries)
179
+ schema[key === 'oneOf' ? 'anyOf' : key] = entry;
180
+ }
181
+ for (const entry of Object.values(schema))
182
+ stateVariantsByAnyOf(entry);
183
+ }
159
184
  /**
160
185
  * Where each rule applies, as JSON Pointers into the document. The marker a named check leaves is
161
186
  * removed; every `maxLength` counts UTF-16 code units, the length the structure measures.