@astrale-os/kernel-dsl 1.0.0-beta.22 → 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.
- package/dist/v1/builder/index.d.ts +2 -0
- package/dist/v1/builder/index.js +1 -0
- package/dist/v1/builder/lowering/value/compile.js +5 -1
- package/dist/v1/builder/lowering/value/file.d.ts +7 -0
- package/dist/v1/builder/lowering/value/file.js +14 -0
- package/dist/v1/builder/schema/diagnostic.d.ts +1 -1
- package/dist/v1/builder/value/file.d.ts +34 -0
- package/dist/v1/builder/value/file.js +77 -0
- package/dist/v1/index.d.ts +2 -2
- package/dist/v1/index.js +1 -1
- package/dist/v1/language/.spec/schemas/value-schema.schema.json +2 -1
- package/dist/v1/language/validation/rule.js +2 -2
- package/dist/v1/language/value/files.d.ts +44 -0
- package/dist/v1/language/value/files.js +150 -0
- package/dist/v1/language/value/inclusion/evidence.js +2 -0
- package/dist/v1/language/value/inclusion/types.js +23 -0
- package/dist/v1/language/value/model/file.d.ts +41 -0
- package/dist/v1/language/value/model/file.js +122 -0
- package/dist/v1/language/value/profile/meta-schema.compiled.d.ts +1 -0
- package/dist/v1/language/value/profile/meta-schema.compiled.js +18 -5
- package/dist/v1/language/value/profile/rules.js +10 -1
- package/dist/v1/language/value/profile/vocabulary.d.ts +7 -6
- package/dist/v1/language/value/profile/vocabulary.js +7 -1
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +43 -3
- package/dist/v1/schema/validation/value-api.d.ts +4 -0
- package/dist/v1/schema/validation/value-api.js +2 -0
- package/dist/v1/schema/validation/value.json-schema.d.ts +5 -0
- package/dist/v1/schema/validation/value.json-schema.js +30 -4
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ export { func, input, method, output } from './callable/authoring.js';
|
|
|
2
2
|
export { core } from './core/authoring.js';
|
|
3
3
|
export { defineClass, edgeClass, nodeClass } from './class/authoring.js';
|
|
4
4
|
export { fullMatch } from './value/full-match.js';
|
|
5
|
+
export { file } from './value/file.js';
|
|
5
6
|
export { path } from './value/path.js';
|
|
6
7
|
export { policy } from './policy/authoring.js';
|
|
7
8
|
export { auto, property, stateProperty } from './class/property.js';
|
|
@@ -18,6 +19,7 @@ export type { Class, DirectedEdgeClass, EdgeClass, NodeClass, UndirectedEdgeClas
|
|
|
18
19
|
export type { ClassReferenceInput as ClassReference, ClassRuleBuilder, ClassRuleContext, CreateRuleBuilder, CreateRuleContext, DirectedEdgeInput, DirectedSourceInput, DirectedTargetInput, EdgeClassCommon, EdgeClassInput, EdgeClassPoliciesInput, EdgeClassPolicyInput, EdgeClassReferenceInput as EdgeClassReference, EdgeRuleBuilder, EdgeRuleContext, EdgeUniqueFieldInput, EdgeUniqueTupleInput, IncidentEndpointInput, NodeClassCreatePolicyInput, NodeClassInput, NodeClassPoliciesInput, NodeClassPolicyInput, NodeClassReferenceInput as NodeClassReference, NodeUniqueTupleInput, UndirectedEdgeInput, } from './class/input.js';
|
|
19
20
|
export type { ClassRuleChecks, CreateRuleChecks, EdgeRuleChecks, } from '../language/policy/model/policy.js';
|
|
20
21
|
export type { AuthoredPropertyProjection, AuthoredMethodProjection, ClassIdentityProjection, ClassOwnerProjection, ClassReferenceProjection, } from './class/projection.js';
|
|
22
|
+
export type { FileAuthoring, FileSource } from './value/file.js';
|
|
21
23
|
export type { PathAuthoring } from './value/path.js';
|
|
22
24
|
export type { Lazy } from './schema/lazy.js';
|
|
23
25
|
export type { EdgeRolesOf, MatchPolicyInput, Policy, PolicyBuilder as PolicyFactory, PolicyEdgeClassInput, PolicyEdgeEnds, PolicyEdgeOptions, PolicyEdgeRepeat, PolicyExistsContext, PolicyInput, PolicyNodeBinder, PolicyPatternContext, } from './policy/authoring.js';
|
package/dist/v1/builder/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { func, input, method, output } from './callable/authoring.js';
|
|
|
2
2
|
export { core } from './core/authoring.js';
|
|
3
3
|
export { defineClass, edgeClass, nodeClass } from './class/authoring.js';
|
|
4
4
|
export { fullMatch } from './value/full-match.js';
|
|
5
|
+
export { file } from './value/file.js';
|
|
5
6
|
export { path } from './value/path.js';
|
|
6
7
|
export { policy } from './policy/authoring.js';
|
|
7
8
|
export { auto, property, stateProperty } from './class/property.js';
|
|
@@ -7,6 +7,7 @@ import { autoPropertyAuthoringInput, propertyAuthoringInput } from '../../class/
|
|
|
7
7
|
import { BuilderError } from '../../schema/diagnostic.js';
|
|
8
8
|
import { escapeToken, fail } from '../../schema/diagnostic.js';
|
|
9
9
|
import { isAuthoringValue } from '../../schema/handle.js';
|
|
10
|
+
import { lowerFileSchema } from './file.js';
|
|
10
11
|
import { lowerPathSchema } from './path.js';
|
|
11
12
|
import { convertZodToValueSchema, zodObjectPropertyIsOptional } from './zod.js';
|
|
12
13
|
export class BuilderValueSchemas {
|
|
@@ -61,7 +62,10 @@ export class BuilderValueSchemas {
|
|
|
61
62
|
const converted = convertZodToValueSchema(input, conversionContext, this.registry, pointer, {
|
|
62
63
|
position: zodPosition,
|
|
63
64
|
validate: false,
|
|
64
|
-
override: (context) =>
|
|
65
|
+
override: (context) => {
|
|
66
|
+
lowerFileSchema(context);
|
|
67
|
+
lowerPathSchema(context, (accepts, markerPointer) => this.resolvePathAccepts(accepts, markerPointer), pointer);
|
|
68
|
+
},
|
|
65
69
|
});
|
|
66
70
|
if (!converted.ok)
|
|
67
71
|
throw new BuilderError(converted.diagnostics);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ZodValueSchemaOverrideContext } from './zod.js';
|
|
2
|
+
/**
|
|
3
|
+
* Lower an authored `file(...)` field to its `schema.values.file` shape. Every other keyword the
|
|
4
|
+
* Zod schema wrote stays: an annotation is kept, and a constraint makes the field non-canonical,
|
|
5
|
+
* which admission refuses.
|
|
6
|
+
*/
|
|
7
|
+
export declare function lowerFileSchema(context: ZodValueSchemaOverrideContext): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { file } from '../../../language/value/model/file.js';
|
|
2
|
+
import { fileOptionsOfAuthoring } from '../../value/file.js';
|
|
3
|
+
/**
|
|
4
|
+
* Lower an authored `file(...)` field to its `schema.values.file` shape. Every other keyword the
|
|
5
|
+
* Zod schema wrote stays: an annotation is kept, and a constraint makes the field non-canonical,
|
|
6
|
+
* which admission refuses.
|
|
7
|
+
*/
|
|
8
|
+
export function lowerFileSchema(context) {
|
|
9
|
+
const options = fileOptionsOfAuthoring(context.zodSchema);
|
|
10
|
+
if (options === undefined)
|
|
11
|
+
return;
|
|
12
|
+
delete context.jsonSchema.type;
|
|
13
|
+
Object.assign(context.jsonSchema, file(options));
|
|
14
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DiagnosticCode as LanguageDiagnosticCode } from '../../language/validation/diagnostic.js';
|
|
2
2
|
import { escapePointerToken as escapeToken } from '../../language/value/syntax/pointer.js';
|
|
3
3
|
export { escapeToken };
|
|
4
|
-
export type BuilderDiagnosticCode = LanguageDiagnosticCode | 'BUILDER_ABSTRACT_POLICY' | 'BUILDER_AMBIGUOUS_OWNERSHIP' | 'BUILDER_AUTO_EVENT_INVALID' | 'BUILDER_AUTO_IMMUTABLE' | 'BUILDER_AUTO_NESTED' | 'BUILDER_AUTO_SET_INVALID' | 'BUILDER_CALLABLE_AUTH' | 'BUILDER_CALLABLE_PLACEMENT' | 'BUILDER_CALLABLE_POLICY_AUTH' | 'BUILDER_CLASS_INHERITANCE' | 'BUILDER_CORE_CLASS' | 'BUILDER_CORE_EDGE' | 'BUILDER_CORE_NODE' | 'BUILDER_CORE_PROPERTY' | 'BUILDER_CORE_REF' | 'BUILDER_DEFINITION' | 'BUILDER_DEPENDENCY_CONFLICT' | 'BUILDER_DEPENDENCY_ALIAS' | 'BUILDER_DEPENDENCY_DIRECT' | 'BUILDER_DUPLICATE_MEMBER' | 'BUILDER_EDGE_LIFETIME' | 'BUILDER_FOREIGN_POLICY' | 'BUILDER_FULL_MATCH_INVALID' | 'BUILDER_FUNCTION' | 'BUILDER_METHOD' | 'BUILDER_PATH_DUPLICATE' | 'BUILDER_PATH_EMPTY' | 'BUILDER_POLICY' | 'BUILDER_POLICY_COMPOSITION' | 'BUILDER_POLICY_CYCLE' | 'BUILDER_POLICY_EMPTY_COMPOSITION' | 'BUILDER_POLICY_EMPTY_EXISTS' | 'BUILDER_POLICY_INPUT' | 'BUILDER_POLICY_REF' | 'BUILDER_POLICY_SELF' | 'BUILDER_PROPERTY_IMMUTABLE_INVALID' | 'BUILDER_REFERENCE_CYCLE' | 'BUILDER_REFERENCE_KIND' | 'BUILDER_REFERENCE_MISSING' | 'BUILDER_UNIQUE_PROPERTY' | 'BUILDER_UNKNOWN_FIELD' | 'BUILDER_UNOWNED_REFERENCE' | 'BUILDER_VIEW' | 'ZOD_SCHEMA_NOT_LOSSLESS';
|
|
4
|
+
export type BuilderDiagnosticCode = LanguageDiagnosticCode | 'BUILDER_ABSTRACT_POLICY' | 'BUILDER_AMBIGUOUS_OWNERSHIP' | 'BUILDER_AUTO_EVENT_INVALID' | 'BUILDER_AUTO_IMMUTABLE' | 'BUILDER_AUTO_NESTED' | 'BUILDER_AUTO_SET_INVALID' | 'BUILDER_CALLABLE_AUTH' | 'BUILDER_CALLABLE_PLACEMENT' | 'BUILDER_CALLABLE_POLICY_AUTH' | 'BUILDER_CLASS_INHERITANCE' | 'BUILDER_CORE_CLASS' | 'BUILDER_CORE_EDGE' | 'BUILDER_CORE_NODE' | 'BUILDER_CORE_PROPERTY' | 'BUILDER_CORE_REF' | 'BUILDER_DEFINITION' | 'BUILDER_DEPENDENCY_CONFLICT' | 'BUILDER_DEPENDENCY_ALIAS' | 'BUILDER_DEPENDENCY_DIRECT' | 'BUILDER_DUPLICATE_MEMBER' | 'BUILDER_EDGE_LIFETIME' | 'BUILDER_FILE_INVALID' | 'BUILDER_FOREIGN_POLICY' | 'BUILDER_FULL_MATCH_INVALID' | 'BUILDER_FUNCTION' | 'BUILDER_METHOD' | 'BUILDER_PATH_DUPLICATE' | 'BUILDER_PATH_EMPTY' | 'BUILDER_POLICY' | 'BUILDER_POLICY_COMPOSITION' | 'BUILDER_POLICY_CYCLE' | 'BUILDER_POLICY_EMPTY_COMPOSITION' | 'BUILDER_POLICY_EMPTY_EXISTS' | 'BUILDER_POLICY_INPUT' | 'BUILDER_POLICY_REF' | 'BUILDER_POLICY_SELF' | 'BUILDER_PROPERTY_IMMUTABLE_INVALID' | 'BUILDER_REFERENCE_CYCLE' | 'BUILDER_REFERENCE_KIND' | 'BUILDER_REFERENCE_MISSING' | 'BUILDER_UNIQUE_PROPERTY' | 'BUILDER_UNKNOWN_FIELD' | 'BUILDER_UNOWNED_REFERENCE' | 'BUILDER_VIEW' | 'ZOD_SCHEMA_NOT_LOSSLESS';
|
|
5
5
|
export interface BuilderDiagnostic<out Code extends BuilderDiagnosticCode = BuilderDiagnosticCode> {
|
|
6
6
|
readonly code: Code;
|
|
7
7
|
readonly pointer: string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type z } from 'zod';
|
|
2
|
+
import type { BlobReceipt } from '../../language/value/model/blob.js';
|
|
3
|
+
import type { FileOptions } from '../../language/value/model/file.js';
|
|
4
|
+
declare const FILE_AUTHORING: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* A file field of a callable input: an upload receipt on the wire, typed as the receipt an upload
|
|
7
|
+
* returns. Its schema is `schema.values.file(...)`.
|
|
8
|
+
*/
|
|
9
|
+
export type FileAuthoring = z.ZodType<BlobReceipt, BlobReceipt> & {
|
|
10
|
+
readonly [FILE_AUTHORING]: true;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The blob Property whose constraints a file field copies: its schema (`schema.values.blob(...)`),
|
|
14
|
+
* the authored `property(...)`, any value carrying that schema as `schema`, as a DomainSchema
|
|
15
|
+
* Property definition does, or a function returning one, read when the schema is built.
|
|
16
|
+
*/
|
|
17
|
+
export type FileSource = {
|
|
18
|
+
readonly 'x-astrale-value-kind': 'blob';
|
|
19
|
+
} | {
|
|
20
|
+
readonly schema: unknown;
|
|
21
|
+
} | object | (() => unknown);
|
|
22
|
+
/** A file field with no constraint, or with its own `maxBytes` and `mediaTypes`. */
|
|
23
|
+
export declare function file(options?: FileOptions): FileAuthoring;
|
|
24
|
+
/**
|
|
25
|
+
* A file field stating the constraints of one blob Property, copied when the schema is built;
|
|
26
|
+
* `tighten` may lower its `maxBytes` and narrow its `mediaTypes`, never loosen them.
|
|
27
|
+
*/
|
|
28
|
+
export declare function file(source: FileSource, tighten?: FileOptions): FileAuthoring;
|
|
29
|
+
/**
|
|
30
|
+
* The constraints of an authored file field, resolved now; undefined for any other schema. A Zod
|
|
31
|
+
* clone of a file field, as `.describe()` or `.optional()` inner schemas make, is still one.
|
|
32
|
+
*/
|
|
33
|
+
export declare function fileOptionsOfAuthoring(schema: z.ZodType): FileOptions | undefined;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { string } from 'zod';
|
|
2
|
+
import { isBlobValueSchema } from '../../language/value/model/blob.js';
|
|
3
|
+
import { acceptFileOptions, blobFileOptions, tightenFileOptions, } from '../../language/value/model/file.js';
|
|
4
|
+
import { propertyAuthoringInput } from '../class/property.js';
|
|
5
|
+
import { fail } from '../schema/diagnostic.js';
|
|
6
|
+
import { isAuthoringValue } from '../schema/handle.js';
|
|
7
|
+
const fileInputs = new WeakMap();
|
|
8
|
+
export function file(input, tighten) {
|
|
9
|
+
const schema = string();
|
|
10
|
+
if (input === undefined || isFileOptions(input)) {
|
|
11
|
+
if (tighten !== undefined) {
|
|
12
|
+
fail('BUILDER_FILE_INVALID', '', 'file(options) takes no second argument.');
|
|
13
|
+
}
|
|
14
|
+
const options = admit(() => acceptFileOptions(input ?? {}));
|
|
15
|
+
fileInputs.set(schema, () => options);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const narrowed = tighten === undefined ? undefined : admit(() => acceptFileOptions(tighten));
|
|
19
|
+
let resolved;
|
|
20
|
+
fileInputs.set(schema, () => {
|
|
21
|
+
resolved ??= admit(() => {
|
|
22
|
+
const base = blobFileOptions(blobSchemaOf(input));
|
|
23
|
+
return narrowed === undefined ? base : tightenFileOptions(base, narrowed);
|
|
24
|
+
});
|
|
25
|
+
return resolved;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The constraints of an authored file field, resolved now; undefined for any other schema. A Zod
|
|
32
|
+
* clone of a file field, as `.describe()` or `.optional()` inner schemas make, is still one.
|
|
33
|
+
*/
|
|
34
|
+
export function fileOptionsOfAuthoring(schema) {
|
|
35
|
+
for (let current = schema; current !== undefined; current = current._zod?.parent) {
|
|
36
|
+
const options = fileInputs.get(current);
|
|
37
|
+
if (options !== undefined)
|
|
38
|
+
return options();
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
function blobSchemaOf(input, depth = 0) {
|
|
43
|
+
if (typeof input === 'function' && depth === 0) {
|
|
44
|
+
return blobSchemaOf(input(), depth + 1);
|
|
45
|
+
}
|
|
46
|
+
if (isBlobValueSchema(input))
|
|
47
|
+
return input;
|
|
48
|
+
if (isAuthoringValue(input, 'property')) {
|
|
49
|
+
const authored = propertyAuthoringInput(input).schema;
|
|
50
|
+
if (isBlobValueSchema(authored))
|
|
51
|
+
return authored;
|
|
52
|
+
}
|
|
53
|
+
else if (input !== null && typeof input === 'object' && 'schema' in input) {
|
|
54
|
+
const schema = input.schema;
|
|
55
|
+
if (isBlobValueSchema(schema))
|
|
56
|
+
return schema;
|
|
57
|
+
}
|
|
58
|
+
throw new TypeError('file(source) requires a blob Property or its schema.');
|
|
59
|
+
}
|
|
60
|
+
function isFileOptions(input) {
|
|
61
|
+
return (typeof input === 'object' &&
|
|
62
|
+
input !== null &&
|
|
63
|
+
!isAuthoringValue(input, 'property') &&
|
|
64
|
+
!isBlobValueSchema(input) &&
|
|
65
|
+
!Object.hasOwn(input, 'schema') &&
|
|
66
|
+
Object.keys(input).every((key) => key === 'maxBytes' || key === 'mediaTypes'));
|
|
67
|
+
}
|
|
68
|
+
function admit(read) {
|
|
69
|
+
try {
|
|
70
|
+
return read();
|
|
71
|
+
}
|
|
72
|
+
catch (cause) {
|
|
73
|
+
if (!(cause instanceof TypeError))
|
|
74
|
+
throw cause;
|
|
75
|
+
fail('BUILDER_FILE_INVALID', '', `file(...): ${cause.message}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist/v1/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Stable aggregate facade for the V1 language. */
|
|
2
|
-
export { auto, core, defineClass, defineSchema, edgeClass, func, fullMatch, input, method, nodeClass, output, path, policy, property, stateProperty, valueSchema, view, } from './builder/index.js';
|
|
2
|
+
export { auto, core, defineClass, defineSchema, edgeClass, file, func, fullMatch, input, method, nodeClass, output, path, policy, property, stateProperty, valueSchema, view, } from './builder/index.js';
|
|
3
3
|
export { stateMachine } from './language/state/index.js';
|
|
4
4
|
export { isBinaryInput } from './language/callable/model/callable.js';
|
|
5
5
|
export type { EventOf, StateMachine, StateOf } from './language/state/index.js';
|
|
@@ -12,7 +12,7 @@ export type { Definition } from './language/index.js';
|
|
|
12
12
|
export type { Domain, MethodOwnerOf, SourceDomain } from './domain/index.js';
|
|
13
13
|
export { isDomain } from './domain/index.js';
|
|
14
14
|
export type * as builder from './builder/index.js';
|
|
15
|
-
export type { PathAuthoring, TypedValueSchema } from './builder/index.js';
|
|
15
|
+
export type { FileAuthoring, PathAuthoring, TypedValueSchema } from './builder/index.js';
|
|
16
16
|
export type { PropertyValues as PropertyValuesValue } from './language/index.js';
|
|
17
17
|
export type { BlobReceipt, BlobRef } from './language/value/model/blob.js';
|
|
18
18
|
export type { CompiledSchema } from './compiled/index.js';
|
package/dist/v1/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Stable aggregate facade for the V1 language. */
|
|
2
|
-
export { auto, core, defineClass, defineSchema, edgeClass, func, fullMatch, input, method, nodeClass, output, path, policy, property, stateProperty, valueSchema, view, } from './builder/index.js';
|
|
2
|
+
export { auto, core, defineClass, defineSchema, edgeClass, file, func, fullMatch, input, method, nodeClass, output, path, policy, property, stateProperty, valueSchema, view, } from './builder/index.js';
|
|
3
3
|
export { stateMachine } from './language/state/index.js';
|
|
4
4
|
export { isBinaryInput } from './language/callable/model/callable.js';
|
|
5
5
|
export { PropertyValues } from './language/index.js';
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
"https://schemas.astrale.ai/dsl/v1/value-schema/vocabulary": true
|
|
14
14
|
},
|
|
15
15
|
"title": "Astrale V1 value schema",
|
|
16
|
-
"$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.",
|
|
16
|
+
"$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.",
|
|
17
17
|
"allOf": [{ "$ref": "https://json-schema.org/draft/2020-12/schema" }],
|
|
18
18
|
"properties": {
|
|
19
19
|
"fullMatch": { "type": "string" },
|
|
20
|
+
"x-astrale-file": { "type": "object" },
|
|
20
21
|
"x-astrale-path": { "type": "object" }
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -97,8 +97,8 @@ export const VALUE_RULES = deepFreeze({
|
|
|
97
97
|
},
|
|
98
98
|
VS_VALUE_KIND: {
|
|
99
99
|
stage: 'schema',
|
|
100
|
-
positions: ['{/path*}/x-astrale-value-kind'],
|
|
101
|
-
statement: 'x-astrale-value-kind declares instant beside type string at any location,
|
|
100
|
+
positions: ['{/path*}/x-astrale-value-kind', '{/path*}/x-astrale-file'],
|
|
101
|
+
statement: 'x-astrale-value-kind declares instant beside type string at any location, blob as the whole schema of a Property, exactly as values.blob writes it, or file at any location of a callable input, exactly as values.file writes it, the only place x-astrale-file stands.',
|
|
102
102
|
conditions: ['#/$defs/value-location/anyOf/1/if'],
|
|
103
103
|
},
|
|
104
104
|
VS_VALUE_KIND_JSON: {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { FileOptions } from './model/file.js';
|
|
2
|
+
import type { JsonSchema } from './model/schema.js';
|
|
3
|
+
/**
|
|
4
|
+
* One step from a value to a value it holds: a named member, an item of an array (every item, or
|
|
5
|
+
* the one at `index`), or an entry of an object that its declared members do not name (every such
|
|
6
|
+
* entry, or those whose name `pattern` matches as a JSON Schema `patternProperties` name does).
|
|
7
|
+
*/
|
|
8
|
+
export type FileSegment = {
|
|
9
|
+
readonly kind: 'property';
|
|
10
|
+
readonly name: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: 'item';
|
|
13
|
+
readonly index?: number;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'entry';
|
|
16
|
+
/** Member names the entry is not: the declared members beside it. */
|
|
17
|
+
readonly except?: readonly string[];
|
|
18
|
+
/** For an additional member: the `patternProperties` names it does not match. */
|
|
19
|
+
readonly exceptPatterns?: readonly string[];
|
|
20
|
+
/** For a pattern member: the `patternProperties` name it matches. */
|
|
21
|
+
readonly pattern?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Where a callable input holds a file field, and what that field states about its file. */
|
|
24
|
+
export interface FilePosition extends FileOptions {
|
|
25
|
+
readonly path: readonly FileSegment[];
|
|
26
|
+
}
|
|
27
|
+
/** One file field of a concrete input value: where it is, which position it fills, its value. */
|
|
28
|
+
export interface LocatedFile {
|
|
29
|
+
/** RFC 6901 JSON Pointer of the value inside the input. */
|
|
30
|
+
readonly pointer: string;
|
|
31
|
+
readonly position: FilePosition;
|
|
32
|
+
readonly value: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Every position at which a value admitted by `schema` may hold a file field, in schema order and
|
|
36
|
+
* without duplicates. Local `$ref`s are followed once per path: a file below a recursive reference
|
|
37
|
+
* is listed where the recursion first reaches it. Pure and total on an admitted value schema.
|
|
38
|
+
*/
|
|
39
|
+
export declare function filePositions(schema: JsonSchema): readonly FilePosition[];
|
|
40
|
+
/**
|
|
41
|
+
* The values of `input` that fill one of `positions`, in position order, each with its JSON
|
|
42
|
+
* Pointer. A position the input does not reach yields nothing; nothing is validated.
|
|
43
|
+
*/
|
|
44
|
+
export declare function locateFiles(positions: readonly FilePosition[], input: unknown): readonly LocatedFile[];
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { fileOptionsOf, isFileValueSchema } from './model/file.js';
|
|
2
|
+
import { isValueObject as isJsonObject } from './model/object.js';
|
|
3
|
+
import { escapePointerToken, parseJsonPointerFragment, resolvePointer } from './syntax/pointer.js';
|
|
4
|
+
const SAME_VALUE = ['allOf', 'anyOf', 'oneOf'];
|
|
5
|
+
// `not` admits no value through its subschema, so no file field lies below it.
|
|
6
|
+
const SAME_VALUE_SINGLE = ['if', 'then', 'else'];
|
|
7
|
+
/**
|
|
8
|
+
* Every position at which a value admitted by `schema` may hold a file field, in schema order and
|
|
9
|
+
* without duplicates. Local `$ref`s are followed once per path: a file below a recursive reference
|
|
10
|
+
* is listed where the recursion first reaches it. Pure and total on an admitted value schema.
|
|
11
|
+
*/
|
|
12
|
+
export function filePositions(schema) {
|
|
13
|
+
const positions = [];
|
|
14
|
+
const seen = new Set();
|
|
15
|
+
const visit = (location, path, references) => {
|
|
16
|
+
if (!isJsonObject(location))
|
|
17
|
+
return;
|
|
18
|
+
if (isFileValueSchema(location)) {
|
|
19
|
+
const position = Object.freeze({ path: Object.freeze([...path]), ...fileOptionsOf(location) });
|
|
20
|
+
const key = JSON.stringify(position);
|
|
21
|
+
if (!seen.has(key)) {
|
|
22
|
+
seen.add(key);
|
|
23
|
+
positions.push(position);
|
|
24
|
+
}
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const reference = location.$ref;
|
|
28
|
+
if (typeof reference === 'string' && reference.startsWith('#') && !references.has(reference)) {
|
|
29
|
+
const target = resolveLocal(schema, reference);
|
|
30
|
+
if (target !== undefined)
|
|
31
|
+
visit(target, path, new Set([...references, reference]));
|
|
32
|
+
}
|
|
33
|
+
for (const keyword of SAME_VALUE) {
|
|
34
|
+
const branches = location[keyword];
|
|
35
|
+
if (Array.isArray(branches)) {
|
|
36
|
+
for (const branch of branches)
|
|
37
|
+
visit(branch, path, references);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (const keyword of SAME_VALUE_SINGLE) {
|
|
41
|
+
if (Object.hasOwn(location, keyword)) {
|
|
42
|
+
visit(location[keyword], path, references);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (isJsonObject(location.dependentSchemas)) {
|
|
46
|
+
for (const entry of Object.values(location.dependentSchemas)) {
|
|
47
|
+
visit(entry, path, references);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const declared = isJsonObject(location.properties) ? Object.keys(location.properties) : [];
|
|
51
|
+
if (isJsonObject(location.properties)) {
|
|
52
|
+
for (const [name, member] of Object.entries(location.properties)) {
|
|
53
|
+
visit(member, [...path, { kind: 'property', name }], references);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const patterns = isJsonObject(location.patternProperties)
|
|
57
|
+
? Object.keys(location.patternProperties)
|
|
58
|
+
: [];
|
|
59
|
+
if (isJsonObject(location.patternProperties)) {
|
|
60
|
+
for (const [pattern, member] of Object.entries(location.patternProperties)) {
|
|
61
|
+
visit(member, [
|
|
62
|
+
...path,
|
|
63
|
+
{ kind: 'entry', ...(declared.length === 0 ? {} : { except: declared }), pattern },
|
|
64
|
+
], references);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const keyword of ['additionalProperties', 'unevaluatedProperties']) {
|
|
68
|
+
if (!Object.hasOwn(location, keyword))
|
|
69
|
+
continue;
|
|
70
|
+
// An additional member is named neither by a declared member nor by a pattern.
|
|
71
|
+
const entry = {
|
|
72
|
+
kind: 'entry',
|
|
73
|
+
...(declared.length === 0 ? {} : { except: declared }),
|
|
74
|
+
...(patterns.length === 0 ? {} : { exceptPatterns: patterns }),
|
|
75
|
+
};
|
|
76
|
+
visit(location[keyword], [...path, entry], references);
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(location.prefixItems)) {
|
|
79
|
+
location.prefixItems.forEach((item, index) => visit(item, [...path, { kind: 'item', index }], references));
|
|
80
|
+
}
|
|
81
|
+
for (const keyword of ['items', 'unevaluatedItems', 'contains']) {
|
|
82
|
+
if (Object.hasOwn(location, keyword)) {
|
|
83
|
+
visit(location[keyword], [...path, { kind: 'item' }], references);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
visit(schema, [], new Set());
|
|
88
|
+
return Object.freeze(positions);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The values of `input` that fill one of `positions`, in position order, each with its JSON
|
|
92
|
+
* Pointer. A position the input does not reach yields nothing; nothing is validated.
|
|
93
|
+
*/
|
|
94
|
+
export function locateFiles(positions, input) {
|
|
95
|
+
const located = [];
|
|
96
|
+
const seen = new Set();
|
|
97
|
+
for (const position of positions) {
|
|
98
|
+
const walk = (value, depth, pointer) => {
|
|
99
|
+
if (depth === position.path.length) {
|
|
100
|
+
if (!seen.has(pointer)) {
|
|
101
|
+
seen.add(pointer);
|
|
102
|
+
located.push(Object.freeze({ pointer, position, value }));
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const segment = position.path[depth];
|
|
107
|
+
if (segment.kind === 'property') {
|
|
108
|
+
if (isPlainObject(value) && Object.hasOwn(value, segment.name)) {
|
|
109
|
+
walk(value[segment.name], depth + 1, `${pointer}/${escapePointerToken(segment.name)}`);
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (segment.kind === 'item') {
|
|
114
|
+
if (!Array.isArray(value))
|
|
115
|
+
return;
|
|
116
|
+
if (segment.index !== undefined) {
|
|
117
|
+
if (segment.index < value.length) {
|
|
118
|
+
walk(value[segment.index], depth + 1, `${pointer}/${segment.index}`);
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
value.forEach((item, index) => walk(item, depth + 1, `${pointer}/${index}`));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!isPlainObject(value))
|
|
126
|
+
return;
|
|
127
|
+
const matcher = segment.pattern === undefined ? undefined : new RegExp(segment.pattern, 'u');
|
|
128
|
+
const excluded = (segment.exceptPatterns ?? []).map((pattern) => new RegExp(pattern, 'u'));
|
|
129
|
+
for (const [name, member] of Object.entries(value)) {
|
|
130
|
+
if (segment.except?.includes(name))
|
|
131
|
+
continue;
|
|
132
|
+
if (matcher !== undefined && !matcher.test(name))
|
|
133
|
+
continue;
|
|
134
|
+
if (excluded.some((pattern) => pattern.test(name)))
|
|
135
|
+
continue;
|
|
136
|
+
walk(member, depth + 1, `${pointer}/${escapePointerToken(name)}`);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
walk(input, 0, '');
|
|
140
|
+
}
|
|
141
|
+
return Object.freeze(located);
|
|
142
|
+
}
|
|
143
|
+
function resolveLocal(root, reference) {
|
|
144
|
+
const tokens = parseJsonPointerFragment(reference);
|
|
145
|
+
const target = tokens === undefined ? undefined : resolvePointer(root, tokens);
|
|
146
|
+
return typeof target === 'boolean' || isJsonObject(target) ? target : undefined;
|
|
147
|
+
}
|
|
148
|
+
function isPlainObject(value) {
|
|
149
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
150
|
+
}
|
|
@@ -54,6 +54,8 @@ export function evidenceOf(location) {
|
|
|
54
54
|
kinds &= STRING;
|
|
55
55
|
if (valueKind === 'blob')
|
|
56
56
|
kinds &= OBJECT;
|
|
57
|
+
if (valueKind === 'file')
|
|
58
|
+
kinds &= STRING;
|
|
57
59
|
}
|
|
58
60
|
upper = tighter(upper, schema.maximum, false, (a, b) => a < b);
|
|
59
61
|
upper = tighter(upper, schema.exclusiveMaximum, true, (a, b) => a < b);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { fileOptionsOf } from '../model/file.js';
|
|
2
|
+
import { isValueObject as isJsonObject } from '../model/object.js';
|
|
1
3
|
import { typeMask } from './kinds.js';
|
|
4
|
+
import { schemaOf } from './location.js';
|
|
2
5
|
/** Rules for the keywords that restrict the kind or the exact value. */
|
|
3
6
|
export const typeRules = new Map([
|
|
4
7
|
['type', ({ value, evidence }) => (evidence.kinds & ~typeMask(value)) === 0],
|
|
@@ -8,4 +11,24 @@ export const typeRules = new Map([
|
|
|
8
11
|
'x-astrale-value-kind',
|
|
9
12
|
({ value, evidence }) => typeof value === 'string' && evidence.valueKinds.has(value),
|
|
10
13
|
],
|
|
14
|
+
// A file field admits the files of another whose constraints are at least as tight.
|
|
15
|
+
[
|
|
16
|
+
'x-astrale-file',
|
|
17
|
+
({ value, evidence }) => {
|
|
18
|
+
if (!isJsonObject(value))
|
|
19
|
+
return false;
|
|
20
|
+
const outer = fileOptionsOf({ 'x-astrale-file': value });
|
|
21
|
+
return evidence.conjuncts.some((conjunct) => {
|
|
22
|
+
const schema = schemaOf(conjunct);
|
|
23
|
+
if (!isJsonObject(schema) || !isJsonObject(schema['x-astrale-file']))
|
|
24
|
+
return false;
|
|
25
|
+
const inner = fileOptionsOf(schema);
|
|
26
|
+
return ((outer.maxBytes === undefined ||
|
|
27
|
+
(inner.maxBytes !== undefined && inner.maxBytes <= outer.maxBytes)) &&
|
|
28
|
+
(outer.mediaTypes === undefined ||
|
|
29
|
+
(inner.mediaTypes !== undefined &&
|
|
30
|
+
inner.mediaTypes.every((mediaType) => outer.mediaTypes.includes(mediaType)))));
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
],
|
|
11
34
|
]);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { JsonSchemaObject } from './schema.js';
|
|
2
|
+
declare const FILE_SCHEMA: unique symbol;
|
|
3
|
+
/** Type-only marker; the serialized schema remains ordinary JSON. */
|
|
4
|
+
export interface FileSchema extends JsonSchemaObject {
|
|
5
|
+
readonly [FILE_SCHEMA]: true;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* What a file field states about the file its receipt names. The Kernel never checks it against a
|
|
9
|
+
* receipt: a client and the SDK check a file before they upload it, and a blob Property the Domain
|
|
10
|
+
* attaches it to applies its own constraints.
|
|
11
|
+
*/
|
|
12
|
+
export interface FileOptions {
|
|
13
|
+
/** Upper bound in bytes, 1 or more. */
|
|
14
|
+
readonly maxBytes?: number;
|
|
15
|
+
/** Non-empty canonical media types; omission admits any. */
|
|
16
|
+
readonly mediaTypes?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
export declare const FILE_VALUE_KIND: 'file';
|
|
19
|
+
/** The keyword that carries a file field's constraints, beside `x-astrale-value-kind: file`. */
|
|
20
|
+
export declare const FILE_KEYWORD: 'x-astrale-file';
|
|
21
|
+
/**
|
|
22
|
+
* The one canonical V1 schema of a file field: an upload receipt on the wire, with the constraints
|
|
23
|
+
* of the file it names under `x-astrale-file` when there are any.
|
|
24
|
+
*/
|
|
25
|
+
export declare function file(options?: FileOptions): FileSchema;
|
|
26
|
+
/** Marker recognition on an already admitted V1 value schema. */
|
|
27
|
+
export declare function isFileValueSchema(input: unknown): input is FileSchema;
|
|
28
|
+
/** The constraints a file field states. */
|
|
29
|
+
export declare function fileOptionsOf(schema: FileSchema | JsonSchemaObject): FileOptions;
|
|
30
|
+
/** The constraints of a blob Property, as a file field that feeds it states them. */
|
|
31
|
+
export declare function blobFileOptions(schema: JsonSchemaObject): FileOptions;
|
|
32
|
+
/**
|
|
33
|
+
* `base` tightened by `tighter`: a lower `maxBytes`, a subset of `mediaTypes`. A constraint
|
|
34
|
+
* `tighter` would loosen is refused.
|
|
35
|
+
*/
|
|
36
|
+
export declare function tightenFileOptions(base: FileOptions, tighter: FileOptions): FileOptions;
|
|
37
|
+
/** Whether `schema` is exactly one `file(...)` output, plus annotation keywords. */
|
|
38
|
+
export declare function isCanonicalFileSchema(schema: Readonly<Record<string, unknown>>): boolean;
|
|
39
|
+
/** Canonical file options: positive safe-integer bound, sorted unique canonical media types. */
|
|
40
|
+
export declare function acceptFileOptions(options: FileOptions): FileOptions;
|
|
41
|
+
export {};
|
|
@@ -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
|
+
}
|
|
@@ -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-
|
|
2066
|
-
let data1 = data["x-astrale-
|
|
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-
|
|
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'] ===
|
|
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,
|
|
27
|
-
*
|
|
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
|
});
|
|
@@ -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",
|
|
@@ -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": {
|
|
@@ -2250,6 +2279,7 @@
|
|
|
2250
2279
|
"unevaluatedProperties",
|
|
2251
2280
|
"uniqueItems",
|
|
2252
2281
|
"writeOnly",
|
|
2282
|
+
"x-astrale-file",
|
|
2253
2283
|
"x-astrale-path",
|
|
2254
2284
|
"x-astrale-value-kind"
|
|
2255
2285
|
]
|
|
@@ -2269,6 +2299,9 @@
|
|
|
2269
2299
|
"pattern": {
|
|
2270
2300
|
"type": "string"
|
|
2271
2301
|
},
|
|
2302
|
+
"x-astrale-file": {
|
|
2303
|
+
"$ref": "#/$defs/file-annotation"
|
|
2304
|
+
},
|
|
2272
2305
|
"x-astrale-path": {
|
|
2273
2306
|
"$ref": "#/$defs/path-annotation"
|
|
2274
2307
|
},
|
|
@@ -2360,7 +2393,10 @@
|
|
|
2360
2393
|
],
|
|
2361
2394
|
"properties": {
|
|
2362
2395
|
"x-astrale-value-kind": {
|
|
2363
|
-
"
|
|
2396
|
+
"enum": [
|
|
2397
|
+
"instant",
|
|
2398
|
+
"file"
|
|
2399
|
+
]
|
|
2364
2400
|
}
|
|
2365
2401
|
}
|
|
2366
2402
|
},
|
|
@@ -2416,7 +2452,8 @@
|
|
|
2416
2452
|
"x-astrale-value-kind": {
|
|
2417
2453
|
"enum": [
|
|
2418
2454
|
"instant",
|
|
2419
|
-
"blob"
|
|
2455
|
+
"blob",
|
|
2456
|
+
"file"
|
|
2420
2457
|
]
|
|
2421
2458
|
}
|
|
2422
2459
|
}
|
|
@@ -2440,7 +2477,10 @@
|
|
|
2440
2477
|
"properties": {
|
|
2441
2478
|
"$schema": false,
|
|
2442
2479
|
"x-astrale-value-kind": {
|
|
2443
|
-
"
|
|
2480
|
+
"enum": [
|
|
2481
|
+
"instant",
|
|
2482
|
+
"file"
|
|
2483
|
+
]
|
|
2444
2484
|
}
|
|
2445
2485
|
}
|
|
2446
2486
|
}
|
|
@@ -7,6 +7,10 @@ import type { DomainSchema } from '../model/schema.js';
|
|
|
7
7
|
export { VALUE_SCHEMA_DIALECT as DIALECT, VALUE_SCHEMA_VOCABULARY as VOCABULARY, } from '../../language/value/model/schema.js';
|
|
8
8
|
export { blob, isBlobValueSchema as isBlob } from '../../language/value/model/blob.js';
|
|
9
9
|
export type { BlobOptions, BlobReceipt, BlobRef, BlobSchema, } from '../../language/value/model/blob.js';
|
|
10
|
+
export { file, isFileValueSchema as isFile } from '../../language/value/model/file.js';
|
|
11
|
+
export type { FileOptions, FileSchema } from '../../language/value/model/file.js';
|
|
12
|
+
export { filePositions, locateFiles } from '../../language/value/files.js';
|
|
13
|
+
export type { FilePosition, FileSegment, LocatedFile } from '../../language/value/files.js';
|
|
10
14
|
export type { JsonSchema as Schema, JsonSchemaObject as SchemaObject, PathAnnotation, PropertyObjectSchema as PropertySchema, ValueSchemaContext as Context, } from '../../language/value/model/schema.js';
|
|
11
15
|
export { instant } from '../../language/value/model/instant.js';
|
|
12
16
|
export type { OrderingKind } from '../../language/value/ordering.js';
|
|
@@ -7,6 +7,8 @@ import { createDomainValueSchemaRegistry } from '../resolution/value.registry.js
|
|
|
7
7
|
const registries = new WeakMap();
|
|
8
8
|
export { VALUE_SCHEMA_DIALECT as DIALECT, VALUE_SCHEMA_VOCABULARY as VOCABULARY, } from '../../language/value/model/schema.js';
|
|
9
9
|
export { blob, isBlobValueSchema as isBlob } from '../../language/value/model/blob.js';
|
|
10
|
+
export { file, isFileValueSchema as isFile } from '../../language/value/model/file.js';
|
|
11
|
+
export { filePositions, locateFiles } from '../../language/value/files.js';
|
|
10
12
|
export { instant } from '../../language/value/model/instant.js';
|
|
11
13
|
export { VALUE_KINDS } from '../../language/value/ordering.js';
|
|
12
14
|
export { GRAPH_NODE_PATH_SCHEMA_ID as NODE_PATH } from '../../language/value/syntax/node-path/schema.js';
|
|
@@ -9,6 +9,11 @@ export declare const valueSchemaRules: {
|
|
|
9
9
|
readonly valueCode: 'VS_VALUE_KIND';
|
|
10
10
|
readonly statement: 'A blob is declared only by the whole schema of a Property, exactly as values.blob writes it.';
|
|
11
11
|
};
|
|
12
|
+
readonly 'value-file': {
|
|
13
|
+
readonly code: 'DV_VALUE_SCHEMA';
|
|
14
|
+
readonly valueCode: 'VS_VALUE_KIND';
|
|
15
|
+
readonly statement: 'A file is declared only inside a callable input, exactly as values.file writes it, and x-astrale-file only beside it.';
|
|
16
|
+
};
|
|
12
17
|
readonly 'value-path': {
|
|
13
18
|
readonly code: 'DV_VALUE_SCHEMA';
|
|
14
19
|
readonly valueCode: 'VS_PATH_EXTENSION';
|
|
@@ -12,6 +12,11 @@ export const valueSchemaRules = {
|
|
|
12
12
|
valueCode: 'VS_VALUE_KIND',
|
|
13
13
|
statement: 'A blob is declared only by the whole schema of a Property, exactly as values.blob writes it.',
|
|
14
14
|
},
|
|
15
|
+
'value-file': {
|
|
16
|
+
code: 'DV_VALUE_SCHEMA',
|
|
17
|
+
valueCode: 'VS_VALUE_KIND',
|
|
18
|
+
statement: 'A file is declared only inside a callable input, exactly as values.file writes it, and x-astrale-file only beside it.',
|
|
19
|
+
},
|
|
15
20
|
// Its members are stated (`path-annotation`); where it stands is named.
|
|
16
21
|
'value-path': {
|
|
17
22
|
code: 'DV_VALUE_SCHEMA',
|
|
@@ -43,6 +48,7 @@ const KIND = 'x-astrale-value-kind';
|
|
|
43
48
|
const LOCATION = '#/$defs/value-location';
|
|
44
49
|
const SUBSCHEMA = '#/$defs/value-subschema';
|
|
45
50
|
const PATH = '#/$defs/path-annotation';
|
|
51
|
+
const FILE = '#/$defs/file-annotation';
|
|
46
52
|
/**
|
|
47
53
|
* The value language in JSON Schema, for the document that embeds value schemas: `root` constrains
|
|
48
54
|
* the `value-schema` definition with the published dialect and what the profile adds to it,
|
|
@@ -57,7 +63,7 @@ export function valueSchemaJsonSchema() {
|
|
|
57
63
|
objectOrBoolean({
|
|
58
64
|
properties: {
|
|
59
65
|
$schema: { const: VALUE_SCHEMA_DIALECT },
|
|
60
|
-
[KIND]: named({ enum: ['instant', 'blob'] }, 'value-blob'),
|
|
66
|
+
[KIND]: named({ enum: ['instant', 'blob', 'file'] }, 'value-blob', 'value-file'),
|
|
61
67
|
},
|
|
62
68
|
}),
|
|
63
69
|
],
|
|
@@ -73,6 +79,7 @@ export function valueSchemaJsonSchema() {
|
|
|
73
79
|
enum: { type: 'array', uniqueItems: true },
|
|
74
80
|
fullMatch: named({ type: 'string' }, 'value-regexp'),
|
|
75
81
|
pattern: named({ type: 'string' }, 'value-regexp'),
|
|
82
|
+
'x-astrale-file': named({ $ref: FILE }, 'value-file'),
|
|
76
83
|
'x-astrale-path': named({ $ref: PATH }, 'value-path'),
|
|
77
84
|
...Object.fromEntries(SUBSCHEMA_KEYWORDS.single.map((keyword) => [keyword, { $ref: SUBSCHEMA }])),
|
|
78
85
|
...Object.fromEntries(SUBSCHEMA_KEYWORDS.array.map((keyword) => [
|
|
@@ -89,8 +96,8 @@ export function valueSchemaJsonSchema() {
|
|
|
89
96
|
return [keyword, named(members, 'value-regexp')];
|
|
90
97
|
})),
|
|
91
98
|
},
|
|
92
|
-
// An instant
|
|
93
|
-
if: { required: [KIND], properties: { [KIND]: {
|
|
99
|
+
// An instant and a file are strings.
|
|
100
|
+
if: { required: [KIND], properties: { [KIND]: { enum: ['instant', 'file'] } } },
|
|
94
101
|
// oxlint-disable-next-line unicorn/no-thenable -- the JSON Schema keyword
|
|
95
102
|
then: { required: ['type'], properties: { type: { const: 'string' } } },
|
|
96
103
|
}),
|
|
@@ -110,11 +117,30 @@ export function valueSchemaJsonSchema() {
|
|
|
110
117
|
required: ['target', 'cardinality', 'accepts'],
|
|
111
118
|
additionalProperties: false,
|
|
112
119
|
},
|
|
120
|
+
// The constraints of a file field, which a client checks before it uploads.
|
|
121
|
+
'file-annotation': {
|
|
122
|
+
type: 'object',
|
|
123
|
+
properties: {
|
|
124
|
+
maxBytes: { type: 'integer', minimum: 1 },
|
|
125
|
+
mediaTypes: {
|
|
126
|
+
type: 'array',
|
|
127
|
+
minItems: 1,
|
|
128
|
+
uniqueItems: true,
|
|
129
|
+
items: { type: 'string' },
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
additionalProperties: false,
|
|
133
|
+
},
|
|
113
134
|
// A location below the root: no $schema, and no blob.
|
|
114
135
|
'value-subschema': {
|
|
115
136
|
allOf: [
|
|
116
137
|
{ $ref: LOCATION },
|
|
117
|
-
objectOrBoolean({
|
|
138
|
+
objectOrBoolean({
|
|
139
|
+
properties: {
|
|
140
|
+
$schema: false,
|
|
141
|
+
[KIND]: named({ enum: ['instant', 'file'] }, 'value-file'),
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
118
144
|
],
|
|
119
145
|
},
|
|
120
146
|
},
|