@squiz/dx-json-schema-lib 1.21.1-alpha.13 → 1.21.1-alpha.19
Sign up to get free protection for your applications and to get access to all the features.
- package/.npm/_logs/2023-03-15T23_51_00_701Z-debug-0.log +37 -0
- package/lib/JsonValidationService.d.ts +1 -1
- package/lib/JsonValidationService.js +15 -5
- package/lib/JsonValidationService.js.map +1 -1
- package/lib/JsonValidationService.spec.js +444 -445
- package/lib/JsonValidationService.spec.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/jsonTypeResolution/{arbitraryTypeResolution.d.ts → TypeResolver.d.ts} +7 -12
- package/lib/jsonTypeResolution/{arbitraryTypeResolution.js → TypeResolver.js} +17 -17
- package/lib/jsonTypeResolution/TypeResolver.js.map +1 -0
- package/lib/jsonTypeResolution/{arbitraryTypeResolution.spec.js → TypeResolver.spec.js} +12 -39
- package/lib/jsonTypeResolution/TypeResolver.spec.js.map +1 -0
- package/lib/jsonTypeResolution/TypeResolverBuilder.d.ts +12 -0
- package/lib/jsonTypeResolution/TypeResolverBuilder.js +32 -0
- package/lib/jsonTypeResolution/TypeResolverBuilder.js.map +1 -0
- package/lib/manifest/v1/DxContentMetaSchema.json +1 -1
- package/lib/manifest/v1/MatrixAssetSchema.json +28 -8
- package/lib/manifest/v1/v1.d.ts +10 -7
- package/lib/primitiveTypes/FormattedText.d.ts +8 -0
- package/lib/primitiveTypes/FormattedText.js +21 -0
- package/lib/primitiveTypes/FormattedText.js.map +1 -0
- package/lib/primitiveTypes/SquizImage.d.ts +26 -0
- package/lib/primitiveTypes/SquizImage.js +105 -0
- package/lib/primitiveTypes/SquizImage.js.map +1 -0
- package/lib/primitiveTypes/index.d.ts +2 -0
- package/lib/primitiveTypes/index.js +19 -0
- package/lib/primitiveTypes/index.js.map +1 -0
- package/lib/resolvableTypes/MatrixAsset.d.ts +9 -0
- package/lib/resolvableTypes/MatrixAsset.js +21 -0
- package/lib/resolvableTypes/MatrixAsset.js.map +1 -0
- package/lib/resolvableTypes/index.d.ts +1 -0
- package/lib/resolvableTypes/index.js +18 -0
- package/lib/resolvableTypes/index.js.map +1 -0
- package/package.json +5 -4
- package/src/JsonValidationService.spec.ts +585 -584
- package/src/JsonValidationService.ts +19 -9
- package/src/index.ts +6 -1
- package/src/jsonTypeResolution/{arbitraryTypeResolution.spec.ts → TypeResolver.spec.ts} +23 -70
- package/src/jsonTypeResolution/{arbitraryTypeResolution.ts → TypeResolver.ts} +27 -23
- package/src/jsonTypeResolution/TypeResolverBuilder.ts +43 -0
- package/src/manifest/v1/DxContentMetaSchema.json +1 -1
- package/src/manifest/v1/MatrixAssetSchema.json +28 -8
- package/src/manifest/v1/v1.ts +22 -9
- package/src/primitiveTypes/FormattedText.ts +24 -0
- package/src/primitiveTypes/SquizImage.ts +128 -0
- package/src/primitiveTypes/index.ts +2 -0
- package/src/resolvableTypes/MatrixAsset.ts +24 -0
- package/src/resolvableTypes/index.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/.npm/_logs/2023-03-14T06_15_33_115Z-debug-0.log +0 -39
- package/lib/jsonTypeResolution/arbitraryTypeResolution.js.map +0 -1
- package/lib/jsonTypeResolution/arbitraryTypeResolution.spec.js.map +0 -1
- package/lib/jsonTypeResolution/index.d.ts +0 -76
- package/lib/jsonTypeResolution/index.js +0 -35
- package/lib/jsonTypeResolution/index.js.map +0 -1
- package/lib/jsonTypeResolution/primitiveTypes.d.ts +0 -10
- package/lib/jsonTypeResolution/primitiveTypes.js +0 -27
- package/lib/jsonTypeResolution/primitiveTypes.js.map +0 -1
- package/lib/jsonTypeResolution/resolvableTypes.d.ts +0 -12
- package/lib/jsonTypeResolution/resolvableTypes.js +0 -30
- package/lib/jsonTypeResolution/resolvableTypes.js.map +0 -1
- package/src/jsonTypeResolution/index.ts +0 -16
- package/src/jsonTypeResolution/primitiveTypes.ts +0 -32
- package/src/jsonTypeResolution/resolvableTypes.ts +0 -37
- /package/lib/jsonTypeResolution/{arbitraryTypeResolution.spec.d.ts → TypeResolver.spec.d.ts} +0 -0
@@ -11,12 +11,12 @@ import FormattedText from './formatted-text/v1/formattedText.json';
|
|
11
11
|
|
12
12
|
import v1 from './manifest/v1/v1.json';
|
13
13
|
import { SchemaValidationError } from './errors/SchemaValidationError';
|
14
|
-
import { Draft07, JSONError, JSONSchema, Draft, DraftConfig
|
14
|
+
import { Draft07, JSONError, JSONSchema, Draft, DraftConfig } from 'json-schema-library';
|
15
15
|
|
16
16
|
import { draft07Config } from 'json-schema-library';
|
17
17
|
import { MANIFEST_MODELS } from '.';
|
18
18
|
import { customFormatValidators } from './validators/customFormatValidators';
|
19
|
-
import { AnyPrimitiveType, AnyResolvableType, TypeResolver } from './jsonTypeResolution/
|
19
|
+
import { AnyPrimitiveType, AnyResolvableType, TypeResolver } from './jsonTypeResolution/TypeResolver';
|
20
20
|
import { JsonResolutionError } from './errors/JsonResolutionError';
|
21
21
|
|
22
22
|
const defaultConfig: DraftConfig = {
|
@@ -166,6 +166,8 @@ export class JSONSchemaService<P extends AnyPrimitiveType, R extends AnyResolvab
|
|
166
166
|
{
|
167
167
|
...defaultConfig,
|
168
168
|
resolveRef: (schema, rootSchema) => this.doResolveRef(schema, rootSchema),
|
169
|
+
validate: (core, data, schema, pointer) => defaultConfig.validate(core, data, schema, pointer),
|
170
|
+
resolveOneOf: (core, data, schema, pointer) => defaultConfig.resolveOneOf(core, data, schema, pointer),
|
169
171
|
},
|
170
172
|
metaSchema.root,
|
171
173
|
);
|
@@ -173,15 +175,25 @@ export class JSONSchemaService<P extends AnyPrimitiveType, R extends AnyResolvab
|
|
173
175
|
for (const [key, value] of Object.entries(metaSchema.remotes || {})) {
|
174
176
|
this.schema.addRemoteSchema(key, value);
|
175
177
|
}
|
178
|
+
|
179
|
+
for (const schema of this.typeResolver.validationSchemaDefinitions) {
|
180
|
+
// Please find a better way of doing this.
|
181
|
+
this.schema.addRemoteSchema(`/${schema.title}.json`, schema as JSONSchema);
|
182
|
+
this.schema.addRemoteSchema(`#/${schema.title}.json`, schema as JSONSchema);
|
183
|
+
}
|
176
184
|
}
|
177
185
|
|
178
186
|
private doResolveRef(schema: JSONSchema, rootSchema: JSONSchema): JSONSchema {
|
179
187
|
const initialRef = draft07Config.resolveRef(schema, rootSchema);
|
180
|
-
|
181
188
|
if (!initialRef) return initialRef;
|
182
189
|
if (!this.typeResolver.isPrimitiveType(initialRef.type)) return initialRef;
|
183
190
|
|
184
|
-
|
191
|
+
const validationSchemas = this.typeResolver.getValidationSchemaForPrimitive(initialRef.type);
|
192
|
+
// All validation schemas are pre-compiled as remote schemas and are referenced below
|
193
|
+
const fullValidationSchema = {
|
194
|
+
oneOf: validationSchemas.map((schema) => ({ $ref: `${schema.title}.json` })),
|
195
|
+
};
|
196
|
+
return this.schema.compileSchema(fullValidationSchema);
|
185
197
|
}
|
186
198
|
|
187
199
|
/**
|
@@ -218,12 +230,10 @@ export class JSONSchemaService<P extends AnyPrimitiveType, R extends AnyResolvab
|
|
218
230
|
if (!this.typeResolver.isResolvableSchema(schema)) return;
|
219
231
|
// If its a resolvable schema, it should exist in a oneOf array with other schemas
|
220
232
|
// Including a primitive schema
|
221
|
-
const
|
222
|
-
|
223
|
-
|
224
|
-
const primitiveSchema = allPossibleSchemas.find((schema): schema is P =>
|
225
|
-
this.typeResolver.isPrimitiveSchema(schema),
|
233
|
+
const allPossibleSchemaTitles: Array<string> = schema.oneOfSchema.oneOf.map((o: JSONSchema) =>
|
234
|
+
o.$ref.replace('.json', ''),
|
226
235
|
);
|
236
|
+
const primitiveSchema = allPossibleSchemaTitles.find((title) => this.typeResolver.isPrimitiveType(title));
|
227
237
|
if (!primitiveSchema) return;
|
228
238
|
|
229
239
|
const resolver = this.typeResolver.tryGetResolver(primitiveSchema, schema);
|
package/src/index.ts
CHANGED
@@ -13,4 +13,9 @@ export * from './errors/JsonResolutionError';
|
|
13
13
|
|
14
14
|
export * from './validators/utils/matrixAssetValidator';
|
15
15
|
|
16
|
-
export * from './
|
16
|
+
export * from './validators/utils/matrixAssetValidator';
|
17
|
+
|
18
|
+
export * from './jsonTypeResolution/TypeResolver';
|
19
|
+
export * from './jsonTypeResolution/TypeResolverBuilder';
|
20
|
+
export * from './primitiveTypes';
|
21
|
+
export * from './resolvableTypes';
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { JSONSchema } from 'json-schema-library';
|
2
|
-
import { PrimitiveType, ResolvableType, TypeResolver } from './
|
2
|
+
import { PrimitiveType, ResolvableType, TypeResolver } from './TypeResolver';
|
3
3
|
|
4
4
|
const defaultSchema: JSONSchema = {
|
5
5
|
type: 'object',
|
@@ -28,64 +28,33 @@ describe('getValidationSchemaForPrimitive', () => {
|
|
28
28
|
it('should return only the primitive schema when no resolvers are defined', () => {
|
29
29
|
const primitiveType = primitiveTypeFixture('MyPrimitive');
|
30
30
|
const resolvableType = resolvableTypeFixture('MyResolvable');
|
31
|
-
const resolver = new TypeResolver(
|
32
|
-
{
|
33
|
-
MyPrimitive: primitiveType,
|
34
|
-
},
|
35
|
-
{
|
36
|
-
MyResolvable: resolvableType,
|
37
|
-
},
|
38
|
-
{},
|
39
|
-
);
|
31
|
+
const resolver = new TypeResolver([primitiveType], [resolvableType], {});
|
40
32
|
|
41
|
-
expect(resolver.getValidationSchemaForPrimitive('MyPrimitive')).toEqual(
|
42
|
-
oneOf: [primitiveType],
|
43
|
-
});
|
33
|
+
expect(resolver.getValidationSchemaForPrimitive('MyPrimitive')).toEqual([primitiveType]);
|
44
34
|
});
|
45
35
|
|
46
36
|
it('should return the primitive schema and the resolvable schema when a resolver is defined', () => {
|
47
37
|
const primitiveType = primitiveTypeFixture('MyPrimitive');
|
48
38
|
const resolvableType = resolvableTypeFixture('MyResolvable');
|
49
|
-
const resolver = new TypeResolver(
|
50
|
-
{
|
51
|
-
|
52
|
-
},
|
53
|
-
{
|
54
|
-
MyResolvable: resolvableType,
|
39
|
+
const resolver = new TypeResolver([primitiveType], [resolvableType], {
|
40
|
+
MyPrimitive: {
|
41
|
+
MyResolvable: () => null,
|
55
42
|
},
|
56
|
-
{
|
57
|
-
MyPrimitive: {
|
58
|
-
MyResolvable: () => null,
|
59
|
-
},
|
60
|
-
},
|
61
|
-
);
|
62
|
-
|
63
|
-
expect(resolver.getValidationSchemaForPrimitive('MyPrimitive')).toEqual({
|
64
|
-
oneOf: [primitiveType, resolvableType],
|
65
43
|
});
|
44
|
+
|
45
|
+
expect(resolver.getValidationSchemaForPrimitive('MyPrimitive')).toEqual([primitiveType, resolvableType]);
|
66
46
|
});
|
67
47
|
|
68
48
|
it('should return the primitive schema and the resolvable schema when a resolver is defined for a different primitive', () => {
|
69
49
|
const primitiveType = primitiveTypeFixture('MyPrimitive');
|
70
50
|
const resolvableType = resolvableTypeFixture('MyResolvable');
|
71
|
-
const resolver = new TypeResolver(
|
72
|
-
{
|
73
|
-
|
74
|
-
MyOtherPrimitive: primitiveTypeFixture('MyOtherPrimitive'),
|
75
|
-
},
|
76
|
-
{
|
77
|
-
MyResolvable: resolvableType,
|
51
|
+
const resolver = new TypeResolver([primitiveType, primitiveTypeFixture('MyOtherPrimitive')], [resolvableType], {
|
52
|
+
MyOtherPrimitive: {
|
53
|
+
MyResolvable: () => null,
|
78
54
|
},
|
79
|
-
{
|
80
|
-
MyOtherPrimitive: {
|
81
|
-
MyResolvable: () => null,
|
82
|
-
},
|
83
|
-
},
|
84
|
-
);
|
85
|
-
|
86
|
-
expect(resolver.getValidationSchemaForPrimitive('MyPrimitive')).toEqual({
|
87
|
-
oneOf: [primitiveType],
|
88
55
|
});
|
56
|
+
|
57
|
+
expect(resolver.getValidationSchemaForPrimitive('MyPrimitive')).toEqual([primitiveType]);
|
89
58
|
});
|
90
59
|
|
91
60
|
it('should error when resolver map contains a key not listed in resolver schemas', () => {
|
@@ -93,20 +62,12 @@ describe('getValidationSchemaForPrimitive', () => {
|
|
93
62
|
const resolvableType = resolvableTypeFixture('MyResolvable');
|
94
63
|
expect(
|
95
64
|
() =>
|
96
|
-
new TypeResolver<typeof primitiveType, typeof resolvableType>(
|
97
|
-
{
|
98
|
-
|
99
|
-
|
100
|
-
{
|
101
|
-
MyResolvable: resolvableType,
|
65
|
+
new TypeResolver<typeof primitiveType, typeof resolvableType>([primitiveType], [resolvableType], {
|
66
|
+
MyPrimitive: {
|
67
|
+
// @ts-expect-error - this is not a valid resolvable type
|
68
|
+
MyOtherResolvable: () => null,
|
102
69
|
},
|
103
|
-
|
104
|
-
MyPrimitive: {
|
105
|
-
// @ts-expect-error - this is not a valid resolvable type
|
106
|
-
MyOtherResolvable: () => null,
|
107
|
-
},
|
108
|
-
},
|
109
|
-
),
|
70
|
+
}),
|
110
71
|
).toThrowError();
|
111
72
|
});
|
112
73
|
|
@@ -115,20 +76,12 @@ describe('getValidationSchemaForPrimitive', () => {
|
|
115
76
|
const resolvableType = resolvableTypeFixture('MyResolvable');
|
116
77
|
expect(
|
117
78
|
() =>
|
118
|
-
new TypeResolver<typeof primitiveType, typeof resolvableType>(
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
{
|
123
|
-
MyResolvable: resolvableType,
|
124
|
-
},
|
125
|
-
{
|
126
|
-
// @ts-expect-error - this is not a valid primitive type
|
127
|
-
MyOtherPrimitive: {
|
128
|
-
MyResolvable: () => null,
|
129
|
-
},
|
79
|
+
new TypeResolver<typeof primitiveType, typeof resolvableType>([primitiveType], [resolvableType], {
|
80
|
+
// @ts-expect-error - this is not a valid primitive type
|
81
|
+
MyOtherPrimitive: {
|
82
|
+
MyResolvable: () => null,
|
130
83
|
},
|
131
|
-
),
|
84
|
+
}),
|
132
85
|
).toThrowError();
|
133
86
|
});
|
134
87
|
});
|
@@ -35,7 +35,7 @@ export function ResolvableType<SHAPE, TITLE extends string>(
|
|
35
35
|
}
|
36
36
|
export type AnyResolvableType = ResolvableType<string, any>;
|
37
37
|
|
38
|
-
type Resolver<INPUT, OUTPUT> = (input: INPUT) => MaybePromise<OUTPUT>;
|
38
|
+
export type Resolver<INPUT, OUTPUT> = (input: INPUT) => MaybePromise<OUTPUT>;
|
39
39
|
|
40
40
|
/**
|
41
41
|
* A JSON Type Resolver class which stores the primitive and resolvable JSON Schema types and their resolvers
|
@@ -43,27 +43,35 @@ type Resolver<INPUT, OUTPUT> = (input: INPUT) => MaybePromise<OUTPUT>;
|
|
43
43
|
* No serious logic is required here. The class should only provide data access methods and type safety
|
44
44
|
*/
|
45
45
|
export class TypeResolver<P extends AnyPrimitiveType, R extends AnyResolvableType> {
|
46
|
+
private primitives: Map<P['title'], P>;
|
47
|
+
private resolvables: Map<R['title'], R>;
|
46
48
|
constructor(
|
47
|
-
|
48
|
-
|
49
|
+
primitives: P[],
|
50
|
+
resolvables: R[] = [],
|
49
51
|
public resolvers: {
|
50
52
|
[PT in P as PT['title']]?: {
|
51
53
|
[RT in R as RT['title']]?: Resolver<RT['__shape__'], PT['__shape__']>;
|
52
54
|
};
|
53
|
-
},
|
55
|
+
} = {},
|
54
56
|
) {
|
57
|
+
this.primitives = new Map(primitives.map((p) => [p.title, p]));
|
58
|
+
this.resolvables = new Map(resolvables.map((r) => [r.title, r]));
|
55
59
|
for (const [primitiveKey, primitiveResolvers] of Object.entries(resolvers) as [string, Record<string, any>][]) {
|
56
|
-
if (!(primitiveKey
|
60
|
+
if (!this.primitives.has(primitiveKey)) {
|
57
61
|
throw new Error('Resolver keys must match a primitive schema');
|
58
62
|
}
|
59
|
-
if (!Object.keys(primitiveResolvers).every((k) => k
|
63
|
+
if (!Object.keys(primitiveResolvers).every((k) => this.resolvables.has(k))) {
|
60
64
|
throw new Error('Primitive resolvers keys must match a resolvable schema');
|
61
65
|
}
|
62
66
|
}
|
63
67
|
}
|
64
68
|
|
69
|
+
get validationSchemaDefinitions() {
|
70
|
+
return [...this.primitives.values(), ...this.resolvables.values()];
|
71
|
+
}
|
72
|
+
|
65
73
|
isPrimitiveType(type: string): type is P['title'] {
|
66
|
-
return
|
74
|
+
return this.primitives.has(type);
|
67
75
|
}
|
68
76
|
|
69
77
|
isPrimitiveSchema(schema: JSONSchema): schema is P {
|
@@ -71,30 +79,26 @@ export class TypeResolver<P extends AnyPrimitiveType, R extends AnyResolvableTyp
|
|
71
79
|
}
|
72
80
|
|
73
81
|
isResolvableSchema(schema: JSONSchema): schema is R {
|
74
|
-
return schema.title
|
82
|
+
return this.resolvables.has(schema.title);
|
75
83
|
}
|
76
84
|
|
77
|
-
getValidationSchemaForPrimitive(type:
|
78
|
-
const primitiveSchema = this.primitives
|
79
|
-
|
80
|
-
|
81
|
-
return {
|
82
|
-
oneOf: validSchemas,
|
83
|
-
};
|
85
|
+
getValidationSchemaForPrimitive(type: P['title']) {
|
86
|
+
const primitiveSchema = this.primitives.get(type) as JsonResolutionSchema<string>;
|
87
|
+
return [primitiveSchema, ...this.fetchResolvableSchemasForPrimitive(type)];
|
84
88
|
}
|
85
89
|
|
86
|
-
private *fetchResolvableSchemasForPrimitive(type:
|
90
|
+
private *fetchResolvableSchemasForPrimitive(type: P['title']) {
|
87
91
|
for (const resolverKey in this.resolvers[type]) {
|
88
|
-
yield this.resolvables
|
92
|
+
yield this.resolvables.get(resolverKey) as JsonResolutionSchema<string>;
|
89
93
|
}
|
90
94
|
}
|
91
95
|
|
92
|
-
tryGetResolver
|
93
|
-
|
94
|
-
resolvableSchema:
|
95
|
-
): Resolver<
|
96
|
-
if (!(
|
96
|
+
tryGetResolver(
|
97
|
+
primitiveSchemaTitle: string,
|
98
|
+
resolvableSchema: R,
|
99
|
+
): Resolver<R['__shape__'], P['__shape__']> | undefined {
|
100
|
+
if (!(primitiveSchemaTitle in this.resolvers)) return;
|
97
101
|
// Sometimes typescript can be insanely annoying
|
98
|
-
return (this.resolvers[
|
102
|
+
return (this.resolvers[primitiveSchemaTitle as keyof typeof this.resolvers] as any)?.[resolvableSchema.title];
|
99
103
|
}
|
100
104
|
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { AnyPrimitiveType, AnyResolvableType, Resolver, TypeResolver } from './TypeResolver';
|
2
|
+
|
3
|
+
type TypeResolverFunction<P extends AnyPrimitiveType, R extends AnyResolvableType> = Resolver<
|
4
|
+
R['__shape__'],
|
5
|
+
P['__shape__']
|
6
|
+
>;
|
7
|
+
|
8
|
+
export class TypeResolverBuilder {
|
9
|
+
private primitives = new Set<AnyPrimitiveType>();
|
10
|
+
private resolvables = new Set<AnyResolvableType>();
|
11
|
+
private resolverMap: Record<string, Record<string, TypeResolverFunction<AnyPrimitiveType, AnyResolvableType>>> = {};
|
12
|
+
static new() {
|
13
|
+
return new TypeResolverBuilder();
|
14
|
+
}
|
15
|
+
|
16
|
+
addPrimitive<P extends AnyPrimitiveType>(primitive: P) {
|
17
|
+
this.primitives.add(primitive);
|
18
|
+
return this;
|
19
|
+
}
|
20
|
+
|
21
|
+
addResolver<P extends AnyPrimitiveType, R extends AnyResolvableType>(
|
22
|
+
primitive: P,
|
23
|
+
resolvable: R,
|
24
|
+
resolver: TypeResolverFunction<P, R>,
|
25
|
+
) {
|
26
|
+
this.primitives.add(primitive);
|
27
|
+
this.resolvables.add(resolvable);
|
28
|
+
this.resolverMap[primitive.title] ??= {};
|
29
|
+
this.resolverMap[primitive.title][resolvable.title] = resolver as TypeResolverFunction<
|
30
|
+
AnyPrimitiveType,
|
31
|
+
AnyResolvableType
|
32
|
+
>;
|
33
|
+
return this;
|
34
|
+
}
|
35
|
+
|
36
|
+
build() {
|
37
|
+
return new TypeResolver(
|
38
|
+
Array.from(this.primitives.values()),
|
39
|
+
Array.from(this.resolvables.values()),
|
40
|
+
this.resolverMap,
|
41
|
+
);
|
42
|
+
}
|
43
|
+
}
|
@@ -16,7 +16,7 @@
|
|
16
16
|
"allOf": [{ "$ref": "#/definitions/nonNegativeInteger" }, { "default": 0 }]
|
17
17
|
},
|
18
18
|
"simpleTypes": {
|
19
|
-
"enum": ["array", "boolean", "integer", "null", "number", "object", "string", "FormattedText"]
|
19
|
+
"enum": ["array", "boolean", "integer", "null", "number", "object", "string", "FormattedText", "SquizImage"]
|
20
20
|
},
|
21
21
|
"stringArray": {
|
22
22
|
"type": "array",
|
@@ -244,7 +244,7 @@
|
|
244
244
|
},
|
245
245
|
"additional": {
|
246
246
|
"description": "Additional data of an arbitrary nature related to the requested asset, which may include derived information or special child asset information.",
|
247
|
-
"
|
247
|
+
"anyOf": [
|
248
248
|
{
|
249
249
|
"$ref": "#/definitions/AssetAdditional"
|
250
250
|
},
|
@@ -260,6 +260,27 @@
|
|
260
260
|
]
|
261
261
|
}
|
262
262
|
},
|
263
|
+
"if": {
|
264
|
+
"properties": {
|
265
|
+
"type": {
|
266
|
+
"const": "image"
|
267
|
+
}
|
268
|
+
}
|
269
|
+
},
|
270
|
+
"then": {
|
271
|
+
"properties": {
|
272
|
+
"additional": {
|
273
|
+
"allOf": [
|
274
|
+
{
|
275
|
+
"$ref": "#/definitions/AssetFileAdditional"
|
276
|
+
},
|
277
|
+
{
|
278
|
+
"$ref": "#/definitions/AssetImageAdditional"
|
279
|
+
}
|
280
|
+
]
|
281
|
+
}
|
282
|
+
}
|
283
|
+
},
|
263
284
|
"required": [
|
264
285
|
"id",
|
265
286
|
"type",
|
@@ -273,7 +294,8 @@
|
|
273
294
|
"published",
|
274
295
|
"url",
|
275
296
|
"urls",
|
276
|
-
"attributes"
|
297
|
+
"attributes",
|
298
|
+
"additional"
|
277
299
|
],
|
278
300
|
|
279
301
|
"definitions": {
|
@@ -325,7 +347,8 @@
|
|
325
347
|
"modified_readable": "Feb 3, 2023 12:26 PM",
|
326
348
|
"modified_unix": 1675387561
|
327
349
|
}
|
328
|
-
}
|
350
|
+
},
|
351
|
+
"required": ["file_info"]
|
329
352
|
},
|
330
353
|
"AssetImageAdditional": {
|
331
354
|
"title": "Image additional info",
|
@@ -337,11 +360,7 @@
|
|
337
360
|
}
|
338
361
|
}
|
339
362
|
},
|
340
|
-
"
|
341
|
-
{
|
342
|
-
"$ref": "#/definitions/AssetFileAdditional"
|
343
|
-
}
|
344
|
-
]
|
363
|
+
"required": ["varieties"]
|
345
364
|
},
|
346
365
|
"AssetCalendarEventAdditional": {
|
347
366
|
"title": "Calendar Event additional info",
|
@@ -360,6 +379,7 @@
|
|
360
379
|
}
|
361
380
|
}
|
362
381
|
},
|
382
|
+
"required": ["event_info"],
|
363
383
|
"example": {
|
364
384
|
"event_info": {
|
365
385
|
"duration": 1800,
|
package/src/manifest/v1/v1.ts
CHANGED
@@ -63,8 +63,18 @@ export type CoreSchemaMetaSchema2 =
|
|
63
63
|
*/
|
64
64
|
enum?: true[];
|
65
65
|
type?:
|
66
|
-
| ('array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string' | 'FormattedText')
|
67
|
-
| (
|
66
|
+
| ('array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string' | 'FormattedText' | 'SquizImage')
|
67
|
+
| (
|
68
|
+
| 'array'
|
69
|
+
| 'boolean'
|
70
|
+
| 'integer'
|
71
|
+
| 'null'
|
72
|
+
| 'number'
|
73
|
+
| 'object'
|
74
|
+
| 'string'
|
75
|
+
| 'FormattedText'
|
76
|
+
| 'SquizImage'
|
77
|
+
)[];
|
68
78
|
format?:
|
69
79
|
| 'date-time'
|
70
80
|
| 'email'
|
@@ -254,7 +264,6 @@ export type CoreSchemaMetaSchema5 =
|
|
254
264
|
*/
|
255
265
|
export type SchemaArray1 = CoreSchemaMetaSchema5[];
|
256
266
|
export type StringArray1 = string[];
|
257
|
-
export type ImageAdditionalInfo = FileAdditionalInfo;
|
258
267
|
|
259
268
|
export interface ComponentManifest {
|
260
269
|
/**
|
@@ -2654,8 +2663,8 @@ export interface CoreSchemaMetaSchema1 {
|
|
2654
2663
|
*/
|
2655
2664
|
enum?: true[];
|
2656
2665
|
type?:
|
2657
|
-
| ('array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string' | 'FormattedText')
|
2658
|
-
| ('array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string' | 'FormattedText')[];
|
2666
|
+
| ('array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string' | 'FormattedText' | 'SquizImage')
|
2667
|
+
| ('array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string' | 'FormattedText' | 'SquizImage')[];
|
2659
2668
|
format?:
|
2660
2669
|
| 'date-time'
|
2661
2670
|
| 'email'
|
@@ -3147,7 +3156,7 @@ export interface MatrixAssetSchema {
|
|
3147
3156
|
/**
|
3148
3157
|
* Additional data of an arbitrary nature related to the requested asset, which may include derived information or special child asset information.
|
3149
3158
|
*/
|
3150
|
-
additional
|
3159
|
+
additional: AssetAdditionalInfo | FileAdditionalInfo | ImageAdditionalInfo | CalendarEventAdditionalInfo;
|
3151
3160
|
[k: string]: unknown;
|
3152
3161
|
}
|
3153
3162
|
export interface MatrixAssetSchema1 {
|
@@ -3339,14 +3348,14 @@ export interface MatrixAssetSchema1 {
|
|
3339
3348
|
/**
|
3340
3349
|
* Additional data of an arbitrary nature related to the requested asset, which may include derived information or special child asset information.
|
3341
3350
|
*/
|
3342
|
-
additional
|
3351
|
+
additional: AssetAdditionalInfo | FileAdditionalInfo | ImageAdditionalInfo | CalendarEventAdditionalInfo;
|
3343
3352
|
[k: string]: unknown;
|
3344
3353
|
}
|
3345
3354
|
export interface AssetAdditionalInfo {
|
3346
3355
|
[k: string]: unknown;
|
3347
3356
|
}
|
3348
3357
|
export interface FileAdditionalInfo {
|
3349
|
-
file_info
|
3358
|
+
file_info: {
|
3350
3359
|
file_name?: string;
|
3351
3360
|
size_readable?: string;
|
3352
3361
|
size_bytes?: number;
|
@@ -3358,8 +3367,12 @@ export interface FileAdditionalInfo {
|
|
3358
3367
|
};
|
3359
3368
|
[k: string]: unknown;
|
3360
3369
|
}
|
3370
|
+
export interface ImageAdditionalInfo {
|
3371
|
+
varieties: MatrixAssetSchema1[];
|
3372
|
+
[k: string]: unknown;
|
3373
|
+
}
|
3361
3374
|
export interface CalendarEventAdditionalInfo {
|
3362
|
-
event_info
|
3375
|
+
event_info: {
|
3363
3376
|
duration?: number;
|
3364
3377
|
frequency?: string;
|
3365
3378
|
[k: string]: unknown;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { FORMATTED_TEXT_SCHEMAS } from '..';
|
2
|
+
import { BaseFormattedNodes, FormattedText } from '../formatted-text/v1/formattedText';
|
3
|
+
import { PrimitiveType } from '../jsonTypeResolution/TypeResolver';
|
4
|
+
|
5
|
+
export const FormattedTextType = PrimitiveType<FormattedText, 'FormattedText'>({
|
6
|
+
...FORMATTED_TEXT_SCHEMAS.v1,
|
7
|
+
title: 'FormattedText',
|
8
|
+
});
|
9
|
+
export type FormattedTextType = typeof FormattedTextType;
|
10
|
+
|
11
|
+
export const BaseFormattedTextType = PrimitiveType<BaseFormattedNodes[], 'FormattedText'>({
|
12
|
+
...FORMATTED_TEXT_SCHEMAS.v1,
|
13
|
+
items: {
|
14
|
+
$ref: '#/definitions/BaseFormattedNodes',
|
15
|
+
},
|
16
|
+
title: 'FormattedText',
|
17
|
+
});
|
18
|
+
export type BaseFormattedTextType = typeof BaseFormattedTextType;
|
19
|
+
|
20
|
+
export const ComponentInputFormattedTextType = PrimitiveType<string, 'FormattedText'>({
|
21
|
+
type: 'string',
|
22
|
+
title: 'FormattedText',
|
23
|
+
});
|
24
|
+
export type ComponentInputFormattedTextType = typeof ComponentInputFormattedTextType;
|
@@ -0,0 +1,128 @@
|
|
1
|
+
import { PrimitiveType } from '../jsonTypeResolution/TypeResolver';
|
2
|
+
|
3
|
+
interface SquizImageData {
|
4
|
+
width: number;
|
5
|
+
height: number;
|
6
|
+
url: string;
|
7
|
+
mimeType: string;
|
8
|
+
byteSize: number;
|
9
|
+
sha1Hash: string;
|
10
|
+
aspectRatio: string; // Enforced validation of something like /\d+:\d+/
|
11
|
+
}
|
12
|
+
|
13
|
+
interface SquizImageShape {
|
14
|
+
name: string;
|
15
|
+
alt?: string;
|
16
|
+
caption?: string;
|
17
|
+
|
18
|
+
exif?: import('exif').ExifData;
|
19
|
+
|
20
|
+
imageVariations: {
|
21
|
+
original: SquizImageData;
|
22
|
+
small?: SquizImageData[];
|
23
|
+
medium?: SquizImageData[];
|
24
|
+
large?: SquizImageData[];
|
25
|
+
aspectRatios?: SquizImageData[];
|
26
|
+
};
|
27
|
+
}
|
28
|
+
export const SquizImageType = PrimitiveType<SquizImageShape, 'SquizImage'>({
|
29
|
+
title: 'SquizImage',
|
30
|
+
type: 'object',
|
31
|
+
properties: {
|
32
|
+
name: {
|
33
|
+
type: 'string',
|
34
|
+
},
|
35
|
+
alt: {
|
36
|
+
type: 'string',
|
37
|
+
},
|
38
|
+
caption: {
|
39
|
+
type: 'string',
|
40
|
+
},
|
41
|
+
exif: {
|
42
|
+
type: 'object',
|
43
|
+
properties: {
|
44
|
+
image: {
|
45
|
+
type: 'object',
|
46
|
+
},
|
47
|
+
thumbnail: {
|
48
|
+
type: 'object',
|
49
|
+
},
|
50
|
+
exif: {
|
51
|
+
type: 'object',
|
52
|
+
},
|
53
|
+
gps: {
|
54
|
+
type: 'object',
|
55
|
+
},
|
56
|
+
interoperability: {
|
57
|
+
type: 'object',
|
58
|
+
},
|
59
|
+
makernote: {
|
60
|
+
type: 'object',
|
61
|
+
},
|
62
|
+
},
|
63
|
+
required: ['image', 'thumbnail', 'exif', 'gps', 'interoperability', 'makernote'],
|
64
|
+
},
|
65
|
+
imageVariations: {
|
66
|
+
type: 'object',
|
67
|
+
properties: {
|
68
|
+
original: { $ref: '#/definitions/SquizImageData' },
|
69
|
+
small: {
|
70
|
+
type: 'array',
|
71
|
+
items: {
|
72
|
+
$ref: '#/definitions/SquizImageData',
|
73
|
+
},
|
74
|
+
},
|
75
|
+
medium: {
|
76
|
+
type: 'array',
|
77
|
+
items: {
|
78
|
+
$ref: '#/definitions/SquizImageData',
|
79
|
+
},
|
80
|
+
},
|
81
|
+
large: {
|
82
|
+
type: 'array',
|
83
|
+
items: {
|
84
|
+
$ref: '#/definitions/SquizImageData',
|
85
|
+
},
|
86
|
+
},
|
87
|
+
aspectRatios: {
|
88
|
+
type: 'array',
|
89
|
+
items: {
|
90
|
+
$ref: '#/definitions/SquizImageData',
|
91
|
+
},
|
92
|
+
},
|
93
|
+
},
|
94
|
+
required: ['original'],
|
95
|
+
},
|
96
|
+
},
|
97
|
+
required: ['name', 'imageVariations'],
|
98
|
+
definitions: {
|
99
|
+
SquizImageData: {
|
100
|
+
type: 'object',
|
101
|
+
properties: {
|
102
|
+
width: {
|
103
|
+
type: 'number',
|
104
|
+
},
|
105
|
+
height: {
|
106
|
+
type: 'number',
|
107
|
+
},
|
108
|
+
url: {
|
109
|
+
type: 'string',
|
110
|
+
},
|
111
|
+
mimeType: {
|
112
|
+
type: 'string',
|
113
|
+
},
|
114
|
+
byteSize: {
|
115
|
+
type: 'number',
|
116
|
+
},
|
117
|
+
sha1Hash: {
|
118
|
+
type: 'string',
|
119
|
+
},
|
120
|
+
aspectRatio: {
|
121
|
+
type: 'string',
|
122
|
+
},
|
123
|
+
},
|
124
|
+
required: ['width', 'height', 'url', 'mimeType', 'byteSize', 'sha1Hash', 'aspectRatio'],
|
125
|
+
},
|
126
|
+
},
|
127
|
+
});
|
128
|
+
export type SquizImageType = typeof SquizImageType;
|