@adobe/data 0.1.2 → 0.1.3
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/cache/blob-store.d.ts +1 -1
- package/cache/managed-array.d.ts +1 -1
- package/core/functions/deep-merge.d.ts +3 -2
- package/core/functions/deep-merge.js +10 -7
- package/core/functions/deep-merge.js.map +1 -1
- package/core/functions/index.d.ts +0 -1
- package/core/functions/index.js +0 -1
- package/core/functions/index.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/schema/dynamic/dynamic-schema.d.ts +27 -0
- package/core/schema/dynamic/dynamic-schema.js +2 -0
- package/core/schema/dynamic/dynamic-schema.js.map +1 -0
- package/core/schema/dynamic/enumerate-patches.d.ts +9 -0
- package/core/schema/dynamic/enumerate-patches.js +50 -0
- package/core/schema/dynamic/enumerate-patches.js.map +1 -0
- package/core/schema/dynamic/enumerate-patches.test.d.ts +134 -0
- package/core/schema/dynamic/enumerate-patches.test.js +209 -0
- package/core/schema/dynamic/enumerate-patches.test.js.map +1 -0
- package/core/schema/dynamic/get-dynamic-schema.d.ts +5 -0
- package/core/schema/dynamic/get-dynamic-schema.js +26 -0
- package/core/schema/dynamic/get-dynamic-schema.js.map +1 -0
- package/core/schema/dynamic/get-dynamic-schema.test.d.ts +1 -0
- package/core/schema/dynamic/get-dynamic-schema.test.js +94 -0
- package/core/schema/dynamic/get-dynamic-schema.test.js.map +1 -0
- package/core/schema/dynamic/index.d.ts +1 -0
- package/core/schema/dynamic/index.js +2 -0
- package/core/schema/dynamic/index.js.map +1 -0
- package/core/schema/dynamic/schema-path-value-path.d.ts +5 -0
- package/core/schema/dynamic/schema-path-value-path.js +12 -0
- package/core/schema/dynamic/schema-path-value-path.js.map +1 -0
- package/core/schema/dynamic-schema.d.ts +27 -0
- package/core/schema/dynamic-schema.js +2 -0
- package/core/schema/dynamic-schema.js.map +1 -0
- package/core/schema/index.d.ts +4 -0
- package/core/schema/index.js +26 -0
- package/core/schema/index.js.map +1 -0
- package/core/schema/schema.d.ts +122 -0
- package/core/schema/schema.js +34 -0
- package/core/schema/schema.js.map +1 -0
- package/core/schema/schemas.d.ts +45 -0
- package/core/schema/schemas.js +39 -0
- package/core/schema/schemas.js.map +1 -0
- package/core/schema/ui-schema.d.ts +25 -0
- package/core/schema/ui-schema.js +2 -0
- package/core/schema/ui-schema.js.map +1 -0
- package/core/schema/validation/is-valid.d.ts +2 -0
- package/core/schema/validation/is-valid.js +14 -0
- package/core/schema/validation/is-valid.js.map +1 -0
- package/core/schema/validation/is-valid.test.d.ts +1 -0
- package/core/schema/validation/is-valid.test.js +40 -0
- package/core/schema/validation/is-valid.test.js.map +1 -0
- package/core/schema/validation/validate.d.ts +2 -0
- package/core/schema/validation/validate.js +38 -0
- package/core/schema/validation/validate.js.map +1 -0
- package/core/schema/validation/validate.test.d.ts +1 -0
- package/core/schema/validation/validate.test.js +106 -0
- package/core/schema/validation/validate.test.js.map +1 -0
- package/core/schema/validation/with-validation.d.ts +5 -0
- package/core/schema/validation/with-validation.js +16 -0
- package/core/schema/validation/with-validation.js.map +1 -0
- package/core/schema/validation/with-validation.test.d.ts +1 -0
- package/core/schema/validation/with-validation.test.js +96 -0
- package/core/schema/validation/with-validation.test.js.map +1 -0
- package/core/schemas.d.ts +45 -0
- package/core/schemas.js +39 -0
- package/core/schemas.js.map +1 -0
- package/ecs/action-ecs/action-ecs.test.js +1 -1
- package/ecs/action-ecs/action-ecs.test.js.map +1 -1
- package/ecs/core-ecs/core-ecs.js +3 -3
- package/ecs/core-ecs/core-ecs.js.map +1 -1
- package/ecs/core-ecs/core-ecs.test.js +22 -1
- package/ecs/core-ecs/core-ecs.test.js.map +1 -1
- package/ecs/ecs/ecs.test.js +1 -1
- package/ecs/ecs/ecs.test.js.map +1 -1
- package/package.json +3 -2
- package/perftest/ecs-perf.js +1 -1
- package/perftest/ecs-perf.js.map +1 -1
- package/schemas/index.d.ts +1 -1
- package/schemas/index.js +1 -1
- package/schemas/index.js.map +1 -1
- package/service/progressive-result.d.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { getDynamicSchema } from './get-dynamic-schema.js';
|
|
3
|
+
import { PersonSchema, PersonSchemaWithOneOf, PersonSchemaRootConditions } from './enumerate-patches.test.js';
|
|
4
|
+
describe('getDynamicSchema', () => {
|
|
5
|
+
it('should not modify schema when local condition is not met', () => {
|
|
6
|
+
const dynamicSchema = getDynamicSchema(PersonSchema, {
|
|
7
|
+
name: "John Doe",
|
|
8
|
+
age: 20,
|
|
9
|
+
});
|
|
10
|
+
// Email UI should remain unchanged
|
|
11
|
+
expect(dynamicSchema.properties?.email?.ui).toEqual({
|
|
12
|
+
name: "Email",
|
|
13
|
+
placeholder: "john.doe@example.com",
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
it('should modify schema when local condition is met', () => {
|
|
17
|
+
const dynamicSchema = getDynamicSchema(PersonSchema, {
|
|
18
|
+
name: "John Doe",
|
|
19
|
+
age: 10,
|
|
20
|
+
});
|
|
21
|
+
// Email UI should be hidden
|
|
22
|
+
expect(dynamicSchema.properties?.email?.ui).toEqual({
|
|
23
|
+
name: "Email",
|
|
24
|
+
placeholder: "john.doe@example.com",
|
|
25
|
+
visible: false,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
it('should apply oneOf conditions for human', () => {
|
|
29
|
+
const dynamicSchema = getDynamicSchema(PersonSchemaWithOneOf, {
|
|
30
|
+
name: "John Doe",
|
|
31
|
+
species: "human",
|
|
32
|
+
});
|
|
33
|
+
// Email UI should be visible
|
|
34
|
+
expect(dynamicSchema.properties?.email?.ui).toEqual({
|
|
35
|
+
name: "Email",
|
|
36
|
+
placeholder: "john.doe@example.com",
|
|
37
|
+
visible: true,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
it('should apply oneOf conditions for robot', () => {
|
|
41
|
+
const dynamicSchema = getDynamicSchema(PersonSchemaWithOneOf, {
|
|
42
|
+
name: "John Doe",
|
|
43
|
+
species: "robot",
|
|
44
|
+
});
|
|
45
|
+
// Email UI should be disabled
|
|
46
|
+
expect(dynamicSchema.properties?.email?.ui).toEqual({
|
|
47
|
+
name: "Email",
|
|
48
|
+
placeholder: "john.doe@example.com",
|
|
49
|
+
enabled: false,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it('should apply complex root conditions', () => {
|
|
53
|
+
const dynamicSchema = getDynamicSchema(PersonSchemaRootConditions, {
|
|
54
|
+
name: "John Doe",
|
|
55
|
+
species: "human",
|
|
56
|
+
});
|
|
57
|
+
// Email UI should be visible due to name length > 3 and species being human
|
|
58
|
+
expect(dynamicSchema.properties?.email?.ui).toEqual({
|
|
59
|
+
name: "Email",
|
|
60
|
+
placeholder: "john.doe@example.com",
|
|
61
|
+
visible: true,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it('should apply simple root conditions', () => {
|
|
65
|
+
const dynamicSchema = getDynamicSchema(PersonSchemaRootConditions, {
|
|
66
|
+
name: "ab",
|
|
67
|
+
species: "human",
|
|
68
|
+
});
|
|
69
|
+
// Email UI should be hidden due to name length <= 2
|
|
70
|
+
expect(dynamicSchema.properties?.email?.ui).toEqual({
|
|
71
|
+
name: "Email",
|
|
72
|
+
placeholder: "john.doe@example.com",
|
|
73
|
+
visible: false,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
it('should throw error when target node is not an object', () => {
|
|
77
|
+
const invalidSchema = {
|
|
78
|
+
type: "object",
|
|
79
|
+
properties: {
|
|
80
|
+
name: {
|
|
81
|
+
type: "string",
|
|
82
|
+
conditionals: [{
|
|
83
|
+
path: "$.type", // targeting a string, not an object
|
|
84
|
+
value: { visible: false }
|
|
85
|
+
}]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
expect(() => getDynamicSchema(invalidSchema, {
|
|
90
|
+
name: "John Doe"
|
|
91
|
+
})).toThrow('Target node MUST be an object');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=get-dynamic-schema.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-dynamic-schema.test.js","sourceRoot":"","sources":["../../../../src/core/schema/dynamic/get-dynamic-schema.test.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './get-dynamic-schema.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/schema/dynamic/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a JSPON path into a schema, return the JSON path to find the corresponding value in the value object.
|
|
3
|
+
*/
|
|
4
|
+
export function schemaPathValuePath(schemaPath) {
|
|
5
|
+
return schemaPath.filter((p) => {
|
|
6
|
+
if (p === "properties" || p === "items" || p === "oneOf") {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=schema-path-value-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-path-value-path.js","sourceRoot":"","sources":["../../../../src/core/schema/dynamic/schema-path-value-path.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA2B;IAC3D,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAgB,EAAE,EAAE;QAC1C,IAAI,CAAC,KAAK,YAAY,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;YACvD,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Data } from "../../index.js";
|
|
2
|
+
import { Schema } from "./schema.js";
|
|
3
|
+
type JSONPath = string;
|
|
4
|
+
type JSONMergePatch = Data;
|
|
5
|
+
/**
|
|
6
|
+
* Conditional patch applied to the path when the enclosing schema branch is active
|
|
7
|
+
* and `match` is not present or validates against the root.
|
|
8
|
+
*/
|
|
9
|
+
export interface Conditional {
|
|
10
|
+
readonly match?: Schema;
|
|
11
|
+
readonly path: JSONPath;
|
|
12
|
+
readonly value: JSONMergePatch;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A Dynamic Schema extends a base schema with conditional behaviour
|
|
16
|
+
* based upon the current state of the data the schema describes.
|
|
17
|
+
*/
|
|
18
|
+
export type DynamicSchema<B extends Schema> = B & {
|
|
19
|
+
readonly conditionals?: readonly Conditional[];
|
|
20
|
+
readonly items?: DynamicSchema<B>;
|
|
21
|
+
readonly properties?: {
|
|
22
|
+
readonly [key: string]: DynamicSchema<B>;
|
|
23
|
+
};
|
|
24
|
+
readonly additionalProperties?: boolean | DynamicSchema<B>;
|
|
25
|
+
readonly oneOf?: readonly DynamicSchema<B>[];
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-schema.js","sourceRoot":"","sources":["../../../src/core/schema/dynamic-schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
export * from "./schema.js";
|
|
23
|
+
export * from "./schemas.js";
|
|
24
|
+
export * from "./dynamic/index.js";
|
|
25
|
+
export * from "./validation/with-validation.js";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/schema/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAEX,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { DeepReadonly } from "../../types/types.js";
|
|
2
|
+
type JSONPath = string;
|
|
3
|
+
type JSONMergePatch = unknown;
|
|
4
|
+
/**
|
|
5
|
+
* Conditional patch applied to the path when the enclosing schema branch is active
|
|
6
|
+
* and `match` is not present or validates against the root.
|
|
7
|
+
* This is used for dynamic schemas which change in response to the value of the data.
|
|
8
|
+
*/
|
|
9
|
+
export type Conditional = {
|
|
10
|
+
match?: Schema;
|
|
11
|
+
path: JSONPath;
|
|
12
|
+
value: JSONMergePatch;
|
|
13
|
+
};
|
|
14
|
+
export interface UIProperties {
|
|
15
|
+
name?: string;
|
|
16
|
+
icon?: string;
|
|
17
|
+
summary?: string;
|
|
18
|
+
premium?: boolean;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
details?: string;
|
|
21
|
+
visible?: boolean;
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
infoUrl?: string;
|
|
24
|
+
group?: string;
|
|
25
|
+
order?: number;
|
|
26
|
+
groups?: {
|
|
27
|
+
readonly [key: string]: UIProperties;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface Schema {
|
|
31
|
+
type?: 'number' | 'integer' | 'string' | 'boolean' | 'null' | 'array' | 'object';
|
|
32
|
+
conditionals?: readonly Conditional[];
|
|
33
|
+
ui?: UIProperties;
|
|
34
|
+
default?: any;
|
|
35
|
+
precision?: 1 | 2;
|
|
36
|
+
multipleOf?: number;
|
|
37
|
+
mediaType?: string;
|
|
38
|
+
minimum?: number;
|
|
39
|
+
maximum?: number;
|
|
40
|
+
minLength?: number;
|
|
41
|
+
maxLength?: number;
|
|
42
|
+
exclusiveMinimum?: number;
|
|
43
|
+
exclusiveMaximum?: number;
|
|
44
|
+
pattern?: string;
|
|
45
|
+
minItems?: number;
|
|
46
|
+
maxItems?: number;
|
|
47
|
+
items?: Schema;
|
|
48
|
+
properties?: {
|
|
49
|
+
readonly [key: string]: Schema;
|
|
50
|
+
};
|
|
51
|
+
required?: readonly string[];
|
|
52
|
+
additionalProperties?: boolean | Schema;
|
|
53
|
+
oneOf?: readonly Schema[];
|
|
54
|
+
const?: any;
|
|
55
|
+
enum?: readonly any[];
|
|
56
|
+
}
|
|
57
|
+
export type FromSchema<T, Depth extends number = 5> = DeepReadonly<Depth extends 0 ? any : T extends {
|
|
58
|
+
const: infer Const;
|
|
59
|
+
} ? Const : T extends {
|
|
60
|
+
enum: infer Enum;
|
|
61
|
+
} ? Enum extends ReadonlyArray<any> ? Enum[number] : never : T extends {
|
|
62
|
+
oneOf: infer Schemas;
|
|
63
|
+
} ? Schemas extends ReadonlyArray<Schema> ? FromOneOfSchema<Schemas, Decrement<Depth>> : never : T extends {
|
|
64
|
+
type: 'number' | 'integer';
|
|
65
|
+
} ? number : T extends {
|
|
66
|
+
type: 'string';
|
|
67
|
+
} ? string : T extends {
|
|
68
|
+
type: 'boolean';
|
|
69
|
+
} ? boolean : T extends {
|
|
70
|
+
type: 'null';
|
|
71
|
+
} ? null : T extends {
|
|
72
|
+
type: 'array';
|
|
73
|
+
} | {
|
|
74
|
+
items: any;
|
|
75
|
+
} ? FromSchemaArray<T, Decrement<Depth>> : T extends {
|
|
76
|
+
type: 'object';
|
|
77
|
+
} | {
|
|
78
|
+
properties: any;
|
|
79
|
+
} ? FromSchemaObject<T, Decrement<Depth>> : any>;
|
|
80
|
+
type Decrement<N extends number> = ((...x: any[]) => void) extends (arg: any, ...rest: infer R) => void ? R['length'] : never;
|
|
81
|
+
type FromSchemaArray<T, Depth extends number> = T extends {
|
|
82
|
+
items: infer Items;
|
|
83
|
+
} ? T extends {
|
|
84
|
+
minItems: infer Min;
|
|
85
|
+
maxItems: infer Max;
|
|
86
|
+
} ? Equal<Min, Max> extends true ? BuildTuple<FromSchema<Items, Depth>, Min> : FromSchema<Items, Depth>[] : FromSchema<Items, Depth>[] : any[];
|
|
87
|
+
type BuildTuple<T, N, R extends unknown[] = []> = R['length'] extends N ? R : BuildTuple<T, N, [...R, T]>;
|
|
88
|
+
type FromSchemaObject<T extends Schema, Depth extends number> = T extends {
|
|
89
|
+
properties: infer P;
|
|
90
|
+
} ? Simplify<{
|
|
91
|
+
[K in RequiredKeys<T>]: FromSchema<P[K], Depth>;
|
|
92
|
+
} & {
|
|
93
|
+
[K in OptionalKeys<T>]?: FromSchema<P[K], Depth>;
|
|
94
|
+
} & (T extends {
|
|
95
|
+
additionalProperties: infer AP;
|
|
96
|
+
} ? AP extends false ? {} : AP extends Schema ? {
|
|
97
|
+
[key: string]: FromSchema<AP, Depth>;
|
|
98
|
+
} : {
|
|
99
|
+
[key: string]: any;
|
|
100
|
+
} : {
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
})> : T extends {
|
|
103
|
+
additionalProperties: infer AP;
|
|
104
|
+
} ? AP extends Schema ? {
|
|
105
|
+
[key: string]: FromSchema<AP, Depth>;
|
|
106
|
+
} : {
|
|
107
|
+
[key: string]: any;
|
|
108
|
+
} : {
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
};
|
|
111
|
+
type RequiredKeys<T> = T extends {
|
|
112
|
+
required: infer R;
|
|
113
|
+
} ? R extends readonly (infer K)[] ? K extends string ? K : never : never : never;
|
|
114
|
+
type OptionalKeys<T> = T extends {
|
|
115
|
+
properties: infer P;
|
|
116
|
+
} ? Exclude<keyof P, RequiredKeys<T>> : never;
|
|
117
|
+
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
|
|
118
|
+
type Simplify<T> = T extends infer O ? {
|
|
119
|
+
[K in keyof O]: O[K];
|
|
120
|
+
} : never;
|
|
121
|
+
type FromOneOfSchema<Schemas extends ReadonlyArray<Schema>, Depth extends number> = Schemas[number] extends infer S ? S extends Schema ? FromSchema<S, Depth> : never : never;
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
;
|
|
23
|
+
const mySchema = {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
a: { type: 'number' },
|
|
27
|
+
b: { type: 'string' },
|
|
28
|
+
c: { enum: [1, 2, 3] }
|
|
29
|
+
},
|
|
30
|
+
required: ['a', 'c'],
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/core/schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AA6DV,CAAC;AAiIF,MAAM,QAAQ,GAAG;IACf,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrB,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrB,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE;KACvB;IACD,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IACpB,oBAAoB,EAAE,KAAK;CACF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Schema } from "../index.js";
|
|
2
|
+
export declare function Nullable<T extends Schema>(schema: T): {
|
|
3
|
+
oneOf: [T, {
|
|
4
|
+
type: "null";
|
|
5
|
+
}];
|
|
6
|
+
};
|
|
7
|
+
export declare function Tuple<T extends Schema, N extends number>(items: T, length: N): {
|
|
8
|
+
readonly type: "array";
|
|
9
|
+
readonly items: T;
|
|
10
|
+
readonly minItems: N;
|
|
11
|
+
readonly maxItems: N;
|
|
12
|
+
};
|
|
13
|
+
export declare const TrueSchema: {
|
|
14
|
+
readonly const: true;
|
|
15
|
+
};
|
|
16
|
+
export declare const BooleanSchema: {
|
|
17
|
+
readonly type: "boolean";
|
|
18
|
+
};
|
|
19
|
+
export declare const Float32Schema: {
|
|
20
|
+
readonly type: "number";
|
|
21
|
+
readonly precision: 1;
|
|
22
|
+
};
|
|
23
|
+
export declare const Float64Schema: {
|
|
24
|
+
readonly type: "number";
|
|
25
|
+
readonly precision: 2;
|
|
26
|
+
};
|
|
27
|
+
export declare const TimeSchema: {
|
|
28
|
+
readonly type: "number";
|
|
29
|
+
readonly precision: 2;
|
|
30
|
+
};
|
|
31
|
+
export declare const Uint8Schema: {
|
|
32
|
+
readonly type: "integer";
|
|
33
|
+
readonly minimum: 0;
|
|
34
|
+
readonly maximum: 255;
|
|
35
|
+
};
|
|
36
|
+
export declare const Uint16Schema: {
|
|
37
|
+
readonly type: "integer";
|
|
38
|
+
readonly minimum: 0;
|
|
39
|
+
readonly maximum: 65535;
|
|
40
|
+
};
|
|
41
|
+
export declare const Uint32Schema: {
|
|
42
|
+
readonly type: "integer";
|
|
43
|
+
readonly minimum: 0;
|
|
44
|
+
readonly maximum: 4294967295;
|
|
45
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function Nullable(schema) {
|
|
2
|
+
return {
|
|
3
|
+
oneOf: [schema, { type: "null" }],
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
export function Tuple(items, length) {
|
|
7
|
+
return { type: "array", items, minItems: length, maxItems: length };
|
|
8
|
+
}
|
|
9
|
+
export const TrueSchema = {
|
|
10
|
+
const: true,
|
|
11
|
+
};
|
|
12
|
+
export const BooleanSchema = {
|
|
13
|
+
type: "boolean",
|
|
14
|
+
};
|
|
15
|
+
export const Float32Schema = {
|
|
16
|
+
type: "number",
|
|
17
|
+
precision: 1,
|
|
18
|
+
};
|
|
19
|
+
export const Float64Schema = {
|
|
20
|
+
type: "number",
|
|
21
|
+
precision: 2,
|
|
22
|
+
};
|
|
23
|
+
export const TimeSchema = Float64Schema;
|
|
24
|
+
export const Uint8Schema = {
|
|
25
|
+
type: "integer",
|
|
26
|
+
minimum: 0,
|
|
27
|
+
maximum: 0xff,
|
|
28
|
+
};
|
|
29
|
+
export const Uint16Schema = {
|
|
30
|
+
type: "integer",
|
|
31
|
+
minimum: 0,
|
|
32
|
+
maximum: 0xffff,
|
|
33
|
+
};
|
|
34
|
+
export const Uint32Schema = {
|
|
35
|
+
type: "integer",
|
|
36
|
+
minimum: 0,
|
|
37
|
+
maximum: 0xffffffff,
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/core/schema/schemas.ts"],"names":[],"mappings":"AAuBA,MAAM,UAAU,QAAQ,CACtB,MAAS;IAET,OAAO;QACL,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,KAAK,CAAqC,KAAQ,EAAE,MAAS;IAC3E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAA4B,CAAC;AAChG,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,KAAK,EAAE,IAAI;CACc,CAAC;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,SAAS;CACU,CAAC;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,CAAC;CACa,CAAC;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,CAAC;CACa,CAAC;AAE5B,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AAExC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,IAAI;CACY,CAAC;AAE5B,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,MAAM;CACU,CAAC;AAE5B,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,UAAU;CACM,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Schema } from "./schema.js";
|
|
2
|
+
export type UIProperties = {
|
|
3
|
+
name?: string;
|
|
4
|
+
icon?: string;
|
|
5
|
+
summary?: string;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
details?: string;
|
|
8
|
+
visible?: boolean;
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
infoUrl?: string;
|
|
11
|
+
group?: string;
|
|
12
|
+
order?: number;
|
|
13
|
+
groups?: {
|
|
14
|
+
readonly [key: string]: UIProperties;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type UISchema = Schema & {
|
|
18
|
+
items?: UISchema;
|
|
19
|
+
ui?: UIProperties;
|
|
20
|
+
properties?: {
|
|
21
|
+
readonly [key: string]: UISchema;
|
|
22
|
+
};
|
|
23
|
+
additionalProperties?: boolean | UISchema;
|
|
24
|
+
oneOf?: readonly UISchema[];
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-schema.js","sourceRoot":"","sources":["../../../src/core/schema/ui-schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { validate } from "./validate.js";
|
|
2
|
+
export function isValid(schema, data) {
|
|
3
|
+
if (data === undefined) {
|
|
4
|
+
debugger;
|
|
5
|
+
}
|
|
6
|
+
try {
|
|
7
|
+
return validate(schema, data ?? null).length === 0;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
console.error(`Error during validation:`, error);
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=is-valid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-valid.js","sourceRoot":"","sources":["../../../../src/core/schema/validation/is-valid.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,IAAS;IAC7C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACrB,QAAQ,CAAC;IACb,CAAC;IACD,IAAI,CAAC;QACD,OAAO,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;QACjD,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
import { describe, it, expect } from 'vitest';
|
|
23
|
+
import { isValid } from './is-valid.js';
|
|
24
|
+
describe('isValid', () => {
|
|
25
|
+
const schema = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
foo: { type: 'string' }
|
|
29
|
+
},
|
|
30
|
+
required: ['foo']
|
|
31
|
+
};
|
|
32
|
+
it('returns true for valid data', () => {
|
|
33
|
+
expect(isValid(schema, { foo: 'bar' })).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('returns false for invalid data', () => {
|
|
36
|
+
expect(isValid(schema, { foo: 123 })).toBe(false);
|
|
37
|
+
expect(isValid(schema, {})).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=is-valid.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-valid.test.js","sourceRoot":"","sources":["../../../../src/core/schema/validation/is-valid.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AACX,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACrB,MAAM,MAAM,GAAW;QACnB,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACR,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC1B;QACD,QAAQ,EAAE,CAAC,KAAK,CAAC;KACpB,CAAC;IAEF,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACnC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACtC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClD,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
import { Validator } from '@cfworker/json-schema';
|
|
23
|
+
// Cache of validators using WeakMap to avoid memory leaks
|
|
24
|
+
const validatorCache = new WeakMap();
|
|
25
|
+
export function validate(schema, data) {
|
|
26
|
+
// Get or create validator from cache
|
|
27
|
+
let validator = validatorCache.get(schema);
|
|
28
|
+
if (!validator) {
|
|
29
|
+
validator = new Validator(schema);
|
|
30
|
+
validatorCache.set(schema, validator);
|
|
31
|
+
}
|
|
32
|
+
const result = validator.validate(data);
|
|
33
|
+
if (result.valid) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
return result.errors.map((error) => error.error);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/core/schema/validation/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AACX,OAAO,EAAE,SAAS,EAAwB,MAAM,uBAAuB,CAAC;AAGxE,0DAA0D;AAC1D,MAAM,cAAc,GAAG,IAAI,OAAO,EAAqB,CAAC;AAExD,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,IAAS;IAC9C,qCAAqC;IACrC,IAAI,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,SAAS,GAAG,IAAI,SAAS,CAAC,MAAoB,CAAC,CAAC;QAChD,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|