@squiz/dx-json-schema-lib 1.76.1 → 1.76.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,12 @@ export type DxComponentInputSchema = CoreSchemaMetaSchema & {
14
14
  export type CoreSchemaMetaSchema = CoreSchemaMetaSchema1 & CoreSchemaMetaSchema2;
15
15
  export type CoreSchemaMetaSchema2 = {
16
16
  $id?: string;
17
+ 'ui:metadata'?: {
18
+ collapsedByDefault?: boolean;
19
+ } | {
20
+ inlineEditable?: boolean;
21
+ quickOption?: boolean;
22
+ };
17
23
  $schema?: string;
18
24
  $ref?: string;
19
25
  $comment?: string;
@@ -262,6 +268,12 @@ export interface ComponentFunction {
262
268
  }
263
269
  export interface CoreSchemaMetaSchema1 {
264
270
  $id?: string;
271
+ 'ui:metadata'?: {
272
+ collapsedByDefault?: boolean;
273
+ } | {
274
+ inlineEditable?: boolean;
275
+ quickOption?: boolean;
276
+ };
265
277
  $schema?: string;
266
278
  $ref?: string;
267
279
  $comment?: string;
@@ -108,5 +108,234 @@ describe('manifest/v1', () => {
108
108
  }, 'v1');
109
109
  }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Invalid property name `Bad-@@@Preview` at `#/previews`');
110
110
  });
111
+ it('should allow ui:metadata property object on input', async () => {
112
+ const manifest = await fetchTestManifest('validComponent.json');
113
+ expect(validationService.validateManifest({
114
+ ...manifest,
115
+ functions: [
116
+ {
117
+ name: 'main',
118
+ entry: 'main.js',
119
+ output: {
120
+ responseType: 'html',
121
+ },
122
+ input: {
123
+ type: 'object',
124
+ properties: {
125
+ 'users-contact': {
126
+ type: 'object',
127
+ description: 'A description of group can be provided if needed',
128
+ required: ['fist-name', 'last-name', 'phone-number', 'email'],
129
+ 'ui:metadata': {
130
+ collapsedByDefault: true,
131
+ },
132
+ properties: {
133
+ 'fist-name': {
134
+ type: 'string',
135
+ 'ui:metadata': {
136
+ inlineEditable: true,
137
+ quickOption: false,
138
+ },
139
+ },
140
+ 'last-name': {
141
+ type: 'string',
142
+ 'ui:metadata': {
143
+ inlineEditable: true,
144
+ quickOption: false,
145
+ },
146
+ },
147
+ 'phone-number': {
148
+ type: 'number',
149
+ 'ui:metadata': {
150
+ inlineEditable: true,
151
+ quickOption: false,
152
+ },
153
+ },
154
+ email: {
155
+ type: 'string',
156
+ 'ui:metadata': {
157
+ inlineEditable: true,
158
+ quickOption: false,
159
+ },
160
+ },
161
+ },
162
+ },
163
+ 'next-of-kin': {
164
+ type: 'object',
165
+ 'ui:metadata': {
166
+ collapsedByDefault: true,
167
+ },
168
+ required: ['fist-name', 'last-name', 'phone-number', 'email'],
169
+ properties: {
170
+ 'fist-name': {
171
+ type: 'string',
172
+ 'ui:metadata': {
173
+ inlineEditable: true,
174
+ quickOption: false,
175
+ },
176
+ },
177
+ 'last-name': {
178
+ type: 'string',
179
+ 'ui:metadata': {
180
+ inlineEditable: true,
181
+ quickOption: false,
182
+ },
183
+ },
184
+ 'phone-number': {
185
+ type: 'number',
186
+ 'ui:metadata': {
187
+ inlineEditable: true,
188
+ quickOption: false,
189
+ },
190
+ },
191
+ email: {
192
+ type: 'string',
193
+ 'ui:metadata': {
194
+ inlineEditable: true,
195
+ quickOption: false,
196
+ },
197
+ },
198
+ },
199
+ },
200
+ 'text-position': {
201
+ type: 'string',
202
+ enum: ['left', 'right'],
203
+ 'ui:metadata': {
204
+ inlineEditable: false,
205
+ quickOption: true,
206
+ },
207
+ },
208
+ },
209
+ required: ['users-contact', 'next-of-kin'],
210
+ },
211
+ },
212
+ ],
213
+ }, 'v1')).toEqual(true);
214
+ });
215
+ it('should fail if ui:metadata property object on object input group has flags other than collapsedByDefault', async () => {
216
+ const manifest = await fetchTestManifest('validComponent.json');
217
+ expectToThrowErrorMatchingTypeAndMessage(() => {
218
+ validationService.validateManifest({
219
+ ...manifest,
220
+ functions: [
221
+ {
222
+ name: 'main',
223
+ entry: 'main.js',
224
+ output: {
225
+ responseType: 'html',
226
+ },
227
+ input: {
228
+ type: 'object',
229
+ properties: {
230
+ 'users-contact': {
231
+ type: 'object',
232
+ description: 'A description of group can be provided if needed',
233
+ required: ['fist-name', 'last-name', 'phone-number', 'email'],
234
+ 'ui:metadata': {
235
+ collapsedByDefault: true,
236
+ quickOption: false,
237
+ inlineEditable: true,
238
+ },
239
+ properties: {
240
+ 'fist-name': {
241
+ type: 'string',
242
+ 'ui:metadata': {
243
+ inlineEditable: true,
244
+ quickOption: false,
245
+ },
246
+ },
247
+ 'last-name': {
248
+ type: 'string',
249
+ 'ui:metadata': {
250
+ inlineEditable: true,
251
+ quickOption: false,
252
+ },
253
+ },
254
+ 'phone-number': {
255
+ type: 'number',
256
+ 'ui:metadata': {
257
+ inlineEditable: true,
258
+ quickOption: false,
259
+ },
260
+ },
261
+ email: {
262
+ type: 'string',
263
+ 'ui:metadata': {
264
+ inlineEditable: true,
265
+ quickOption: false,
266
+ },
267
+ },
268
+ },
269
+ },
270
+ },
271
+ required: ['users-contact'],
272
+ },
273
+ },
274
+ ],
275
+ }, 'v1');
276
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `{"collapsedByDefault":true,"quickOption":false,"inlineEditable":true}` in `#/functions/0/input/properties/users-contact/ui:metadata` does not match any given oneof schema');
277
+ });
278
+ it('should fail if ui:metadata property on object with type string has collapsedByDefault flag', async () => {
279
+ const manifest = await fetchTestManifest('validComponent.json');
280
+ expectToThrowErrorMatchingTypeAndMessage(() => {
281
+ validationService.validateManifest({
282
+ ...manifest,
283
+ functions: [
284
+ {
285
+ name: 'main',
286
+ entry: 'main.js',
287
+ output: {
288
+ responseType: 'html',
289
+ },
290
+ input: {
291
+ type: 'object',
292
+ properties: {
293
+ 'users-contact': {
294
+ type: 'object',
295
+ description: 'A description of group can be provided if needed',
296
+ required: ['fist-name', 'last-name', 'phone-number', 'email'],
297
+ 'ui:metadata': {
298
+ collapsedByDefault: true,
299
+ },
300
+ properties: {
301
+ 'fist-name': {
302
+ type: 'string',
303
+ 'ui:metadata': {
304
+ inlineEditable: true,
305
+ quickOption: false,
306
+ collapsedByDefault: true,
307
+ },
308
+ },
309
+ 'last-name': {
310
+ type: 'string',
311
+ 'ui:metadata': {
312
+ inlineEditable: true,
313
+ quickOption: false,
314
+ },
315
+ },
316
+ 'phone-number': {
317
+ type: 'number',
318
+ 'ui:metadata': {
319
+ inlineEditable: true,
320
+ quickOption: false,
321
+ },
322
+ },
323
+ email: {
324
+ type: 'string',
325
+ 'ui:metadata': {
326
+ inlineEditable: true,
327
+ quickOption: false,
328
+ },
329
+ },
330
+ },
331
+ },
332
+ },
333
+ required: ['users-contact'],
334
+ },
335
+ },
336
+ ],
337
+ }, 'v1');
338
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `{"inlineEditable":true,"quickOption":false,"collapsedByDefault":true}` in `#/functions/0/input/properties/users-contact/properties/fist-name/ui:metadata` does not match any given oneof schema');
339
+ });
111
340
  });
112
341
  //# sourceMappingURL=v1.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"v1.spec.js","sourceRoot":"","sources":["../../../src/manifest/v1/v1.spec.ts"],"names":[],"mappings":";;AAAA,0CAAuC;AACvC,+BAA+B;AAC/B,8EAA2E;AAC3E,uEAAoE;AAEpE,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAE5C,KAAK,UAAU,iBAAiB,CAAC,QAAgB;IAC/C,MAAM,QAAQ,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAA,cAAO,EAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE;QACnF,QAAQ,EAAE,OAAO;KAClB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AACD,wDAAwD;AACxD,SAAS,wCAAwC,CAAC,QAAkB,EAAE,SAAmB,EAAE,OAAe;IACxG,IAAI,KAAK,GAAiB,IAAI,CAAC;IAE/B,IAAI;QACF,QAAQ,EAAE,CAAC;KACZ;IAAC,OAAO,CAAM,EAAE;QACf,KAAK,GAAG,CAAC,CAA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,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dx-json-schema-lib",
3
- "version": "1.76.1",
3
+ "version": "1.76.3",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
@@ -31,7 +31,7 @@
31
31
  "typescript": "4.9.4"
32
32
  },
33
33
  "dependencies": {
34
- "@sagold/json-query": "6.0.0",
34
+ "@sagold/json-query": "^6.2.0",
35
35
  "@squiz/json-schema-library": "^7.4.7",
36
36
  "ts-brand": "0.0.2"
37
37
  }
@@ -2183,4 +2183,148 @@ describe('JSONSchemaService - validation', () => {
2183
2183
  },
2184
2184
  });
2185
2185
  });
2186
+
2187
+ it('should not use the resolver for primitive items in a resolvable array', async () => {
2188
+ const mockMatrixAssetResolver = jest.fn((input: MatrixAssetType['__shape__']) => {
2189
+ return {
2190
+ name: input.matrixAssetId,
2191
+ imageVariations: {
2192
+ original: {
2193
+ width: 0,
2194
+ height: 0,
2195
+ url: '',
2196
+ mimeType: '',
2197
+ byteSize: 0,
2198
+ sha1Hash: '',
2199
+ aspectRatio: '',
2200
+ },
2201
+ },
2202
+ };
2203
+ });
2204
+ const mockMatrixLinkResolver = jest.fn((input: MatrixAssetLinkType['__shape__']): SquizLinkType['__shape__'] => {
2205
+ return {
2206
+ text: input.matrixAssetId,
2207
+ url: 'www.test.com',
2208
+ target: '_self',
2209
+ };
2210
+ });
2211
+ const typeResolver = TypeResolverBuilder.new()
2212
+ .addPrimitive(SquizImageType)
2213
+ .addPrimitive(SquizLinkType)
2214
+ .addPrimitive(FormattedTextType)
2215
+ .addResolver(SquizImageType, MatrixAssetType, mockMatrixAssetResolver)
2216
+ .addResolver(SquizLinkType, MatrixAssetLinkType, mockMatrixLinkResolver)
2217
+ .build();
2218
+
2219
+ const jsonSchemaService = new JSONSchemaService(typeResolver, ComponentInputMetaSchema);
2220
+
2221
+ const schema = {
2222
+ type: 'object',
2223
+ properties: {
2224
+ images: {
2225
+ description: 'Gallery images',
2226
+ type: 'array',
2227
+ items: {
2228
+ type: 'SquizImage',
2229
+ },
2230
+ },
2231
+ squizLink: {
2232
+ title: 'Squiz link',
2233
+ type: 'array',
2234
+ items: {
2235
+ type: 'SquizLink',
2236
+ },
2237
+ },
2238
+ //custom format
2239
+ multiLine: {
2240
+ title: 'Multi-line (textarea)',
2241
+ type: 'array',
2242
+ items: {
2243
+ type: 'string',
2244
+ format: 'multi-line',
2245
+ },
2246
+ },
2247
+ //string array
2248
+ listOfStrings: {
2249
+ type: 'array',
2250
+ title: 'A list of strings',
2251
+ items: {
2252
+ type: 'string',
2253
+ default: 'Holy smokes',
2254
+ },
2255
+ },
2256
+ },
2257
+ required: ['images', 'links'],
2258
+ };
2259
+
2260
+ const input: {
2261
+ images: Array<MatrixAssetType['__shape__'] | SquizImageType['__shape__']>;
2262
+ squizLink: Array<MatrixAssetLinkType['__shape__'] | SquizLinkType['__shape__']>;
2263
+ multiline: Array<string>;
2264
+ listOfStrings: Array<string>;
2265
+ } = {
2266
+ images: [
2267
+ {
2268
+ matrixDomain: 'https://feaas-page-render-us.dev.matrix.squiz.cloud/59',
2269
+ matrixAssetId: '160',
2270
+ matrixIdentifier: 'feaas-matrix-us',
2271
+ },
2272
+ {
2273
+ imageVariations: {
2274
+ original: { aspectRatio: '', byteSize: 0, height: 0, mimeType: '', sha1Hash: '', url: '', width: 0 },
2275
+ },
2276
+ name: '',
2277
+ },
2278
+ ],
2279
+ squizLink: [
2280
+ {
2281
+ matrixDomain: 'https://feaas-page-render-us.dev.matrix.squiz.cloud/59',
2282
+ matrixAssetId: '160',
2283
+ matrixIdentifier: 'feaas-matrix-us',
2284
+ target: '_self',
2285
+ },
2286
+ {
2287
+ text: 'link text',
2288
+ url: 'www.test.com',
2289
+ target: '_self',
2290
+ },
2291
+ ],
2292
+ multiline: ['wow', 'much', 'multiline'],
2293
+ listOfStrings: ['very', 'string'],
2294
+ };
2295
+ const result = await jsonSchemaService.resolveInput(input, schema);
2296
+ expect(result).toEqual({
2297
+ images: [
2298
+ {
2299
+ imageVariations: {
2300
+ original: { aspectRatio: '', byteSize: 0, height: 0, mimeType: '', sha1Hash: '', url: '', width: 0 },
2301
+ },
2302
+ name: (input.images[0] as MatrixAssetType['__shape__']).matrixAssetId,
2303
+ },
2304
+ {
2305
+ imageVariations: {
2306
+ original: { aspectRatio: '', byteSize: 0, height: 0, mimeType: '', sha1Hash: '', url: '', width: 0 },
2307
+ },
2308
+ name: '',
2309
+ },
2310
+ ],
2311
+ squizLink: [
2312
+ {
2313
+ text: (input.squizLink[0] as MatrixAssetLinkType['__shape__']).matrixAssetId,
2314
+ url: 'www.test.com',
2315
+ target: '_self',
2316
+ },
2317
+ {
2318
+ text: 'link text',
2319
+ url: 'www.test.com',
2320
+ target: '_self',
2321
+ },
2322
+ ],
2323
+ multiline: ['wow', 'much', 'multiline'],
2324
+ listOfStrings: ['very', 'string'],
2325
+ });
2326
+
2327
+ expect(mockMatrixAssetResolver).toHaveBeenCalledTimes(1);
2328
+ expect(mockMatrixLinkResolver).toHaveBeenCalledTimes(1);
2329
+ });
2186
2330
  });
@@ -178,11 +178,6 @@ export const ManifestV1MetaSchema: MetaSchemaInput = {
178
178
  },
179
179
  };
180
180
 
181
- const titleMap: Record<'SquizLink' | 'SquizImage', string[]> = {
182
- ['SquizLink']: ['MatrixAssetLink'],
183
- ['SquizImage']: ['MatrixAsset', 'DAMObject'],
184
- };
185
-
186
181
  interface MetaSchemaInput {
187
182
  root: JSONSchema;
188
183
  remotes?: Record<string, JSONSchema>;
@@ -249,8 +244,11 @@ export class JSONSchemaService<P extends AnyPrimitiveType, R extends AnyResolvab
249
244
  this.schema.each(
250
245
  input,
251
246
  async (schema, value, pointer) => {
252
- if (this.typeResolver.isResolvableArraySchema(schema)) {
253
- return await this.resolveInputArray(input, setters, schema, value, pointer);
247
+ // Bug in library for Array item schemas which won't resolve the oneOf schema
248
+ if (Array.isArray(schema?.oneOf)) {
249
+ const oldSchema = schema;
250
+ schema = this.schema.resolveOneOf(value, schema);
251
+ schema.oneOfSchema = oldSchema;
254
252
  }
255
253
  if (!this.typeResolver.isResolvableSchema(schema)) return;
256
254
  // If its a resolvable schema, it should exist in a oneOf array with other schemas
@@ -264,7 +262,7 @@ export class JSONSchemaService<P extends AnyPrimitiveType, R extends AnyResolvab
264
262
  if (!resolver) return;
265
263
  const setResolvedData = Promise.resolve()
266
264
  .then(() => resolver(value))
267
- .then((resolvedData) => (item: typeof input) => JSONQuery.set(item, pointer, resolvedData))
265
+ .then((resolvedData) => (item: typeof input) => JSONQuery.set(item, pointer, resolvedData, 'replace' as any))
268
266
  .catch((e) => Promise.reject(new JsonResolutionError(e, pointer, value)));
269
267
  setters.push(setResolvedData);
270
268
  },
@@ -304,48 +302,6 @@ export class JSONSchemaService<P extends AnyPrimitiveType, R extends AnyResolvab
304
302
 
305
303
  return input;
306
304
  }
307
-
308
- protected async resolveInputArray(
309
- input: Input,
310
- setters: Promise<(input: Input) => Input>[],
311
- schema: JSONSchema,
312
- value: unknown,
313
- pointer: string,
314
- ) {
315
- const allPossibleSchemaTitles: string[] = schema.oneOf.map((o: JSONSchema) => {
316
- return o.$ref.replace('.json', '');
317
- });
318
- const primitiveSchema = allPossibleSchemaTitles.find((title) => this.typeResolver.isPrimitiveType(title));
319
- if (!this.isPrimitiveSchema(primitiveSchema)) return;
320
-
321
- const primitiveSchemaKey: keyof typeof titleMap = primitiveSchema;
322
- const mappedValues = titleMap[primitiveSchemaKey];
323
-
324
- let matchedMappedValue: string | null = mappedValues[0];
325
-
326
- if (this.isDamObject(value, schema)) {
327
- matchedMappedValue = mappedValues.find((mappedValue) => mappedValue === 'DAMObject') || matchedMappedValue;
328
- }
329
- const resolver = this.typeResolver.tryGetResolver(primitiveSchema, { title: matchedMappedValue } as R);
330
- if (!resolver) return;
331
- const setResolvedData = Promise.resolve()
332
- .then(() => resolver(value))
333
- .then((resolvedData) => (item: typeof input) => this.assignResolvedData(item, pointer, resolvedData))
334
- .catch((e) => Promise.reject(new JsonResolutionError(e, pointer, value)));
335
- setters.push(setResolvedData);
336
- }
337
-
338
- private isDamObject(value: any, schema: JSONSchema): boolean {
339
- const damObjectSchema = schema.oneOf.find((s: JSONSchema) => s.$ref === 'DAMObject.json');
340
- if (!damObjectSchema) return false;
341
-
342
- return typeof value === 'object' && value.damObjectId !== undefined;
343
- }
344
-
345
- private isPrimitiveSchema(value: string | undefined): value is keyof typeof titleMap {
346
- if (!value) false;
347
- return value === 'SquizLink' || value === 'SquizImage';
348
- }
349
305
  }
350
306
 
351
307
  export class JsonValidationService {
@@ -82,17 +82,6 @@ export class TypeResolver<P extends AnyPrimitiveType, R extends AnyResolvableTyp
82
82
  return this.resolvables.has(schema.title);
83
83
  }
84
84
 
85
- isResolvableArraySchema(schema: JSONSchema): schema is R {
86
- if (Array.isArray(schema.oneOf) && schema.title === undefined) {
87
- const hasResolvable = schema.oneOf.some((schema: JSONSchema) => {
88
- const title = schema.$ref.replace('.json', '');
89
- return this.resolvables.has(title);
90
- });
91
- return hasResolvable;
92
- }
93
- return false;
94
- }
95
-
96
85
  getValidationSchemaForPrimitive(type: P['title']) {
97
86
  const primitiveSchema = this.primitives.get(type) as JsonResolutionSchema<string>;
98
87
  return [primitiveSchema, ...this.fetchResolvableSchemasForPrimitive(type)];
@@ -34,6 +34,40 @@
34
34
  "items": { "type": "string" },
35
35
  "uniqueItems": true,
36
36
  "default": []
37
+ },
38
+ "ui:metadata": {
39
+ "oneOf": [
40
+ {
41
+ "type": "object",
42
+ "additionalProperties": false,
43
+ "properties": {
44
+ "collapsedByDefault": {
45
+ "type": "boolean",
46
+ "default": false
47
+ }
48
+ },
49
+ "if": {
50
+ "type": "object"
51
+ }
52
+ },
53
+ {
54
+ "type": "object",
55
+ "additionalProperties": false,
56
+ "properties": {
57
+ "inlineEditable": {
58
+ "type": "boolean",
59
+ "default": false
60
+ },
61
+ "quickOption": {
62
+ "type": "boolean",
63
+ "default": false
64
+ }
65
+ },
66
+ "if": {
67
+ "type": ["number", "integer", "array", "boolean", "string"]
68
+ }
69
+ }
70
+ ]
37
71
  }
38
72
  },
39
73
  "type": ["object", "boolean"],
@@ -42,6 +76,7 @@
42
76
  "type": "string",
43
77
  "format": "uri-reference"
44
78
  },
79
+ "ui:metadata": { "$ref": "#/definitions/ui:metadata" },
45
80
  "$schema": {
46
81
  "type": "string",
47
82
  "format": "uri"
@@ -17,6 +17,14 @@ export type CoreSchemaMetaSchema = CoreSchemaMetaSchema1 & CoreSchemaMetaSchema2
17
17
  export type CoreSchemaMetaSchema2 =
18
18
  | {
19
19
  $id?: string;
20
+ 'ui:metadata'?:
21
+ | {
22
+ collapsedByDefault?: boolean;
23
+ }
24
+ | {
25
+ inlineEditable?: boolean;
26
+ quickOption?: boolean;
27
+ };
20
28
  $schema?: string;
21
29
  $ref?: string;
22
30
  $comment?: string;
@@ -262,6 +270,14 @@ export interface JobFunction {
262
270
  }
263
271
  export interface CoreSchemaMetaSchema1 {
264
272
  $id?: string;
273
+ 'ui:metadata'?:
274
+ | {
275
+ collapsedByDefault?: boolean;
276
+ }
277
+ | {
278
+ inlineEditable?: boolean;
279
+ quickOption?: boolean;
280
+ };
265
281
  $schema?: string;
266
282
  $ref?: string;
267
283
  $comment?: string;