@apify/input_schema 3.16.1 → 3.18.0

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/cjs/index.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/index.ts
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
+ ensureAjvSupportsDraft2019: () => ensureAjvSupportsDraft2019,
24
25
  inputSchema: () => schema_default,
25
26
  m: () => m,
26
27
  makeInputJsFieldsReadable: () => makeInputJsFieldsReadable,
@@ -120,13 +121,12 @@ var schema_default = {
120
121
  stringEnumProperty: {
121
122
  title: "Enum property",
122
123
  type: "object",
123
- additionalProperties: false,
124
+ unevaluatedProperties: false,
124
125
  properties: {
125
126
  type: { enum: ["string"] },
126
127
  editor: { enum: ["select"] },
127
128
  title: { type: "string" },
128
129
  description: { type: "string" },
129
- default: { type: "string" },
130
130
  prefill: { type: "string" },
131
131
  example: { type: "string" },
132
132
  nullable: { type: "boolean" },
@@ -144,7 +144,16 @@ var schema_default = {
144
144
  minItems: 1
145
145
  }
146
146
  },
147
- required: ["type", "title", "description", "enum"]
147
+ required: ["type", "title", "description", "enum"],
148
+ if: {
149
+ properties: { nullable: { const: false } }
150
+ },
151
+ then: {
152
+ properties: { default: { type: "string" } }
153
+ },
154
+ else: {
155
+ properties: { default: { type: ["string", "null"] } }
156
+ }
148
157
  },
149
158
  stringProperty: {
150
159
  title: "String property",
@@ -169,49 +178,52 @@ var schema_default = {
169
178
  }
170
179
  },
171
180
  then: {
172
- if: {
173
- properties: {
174
- editor: { const: "datepicker" }
175
- }
176
- },
177
- then: {
178
- additionalProperties: false,
179
- properties: {
180
- type: { enum: ["string"] },
181
- title: { type: "string" },
182
- description: { type: "string" },
183
- default: { type: "string" },
184
- prefill: { type: "string" },
185
- example: { type: "string" },
186
- pattern: { type: "string" },
187
- nullable: { type: "boolean" },
188
- minLength: { type: "integer" },
189
- maxLength: { type: "integer" },
190
- editor: { enum: ["datepicker"] },
191
- sectionCaption: { type: "string" },
192
- sectionDescription: { type: "string" },
193
- dateType: { enum: ["absolute", "relative", "absoluteOrRelative"] }
194
- }
181
+ properties: {
182
+ type: { enum: ["string"] },
183
+ title: { type: "string" },
184
+ description: { type: "string" },
185
+ prefill: { type: "string" },
186
+ example: { type: "string" },
187
+ pattern: { type: "string" },
188
+ nullable: { type: "boolean" },
189
+ minLength: { type: "integer" },
190
+ maxLength: { type: "integer" },
191
+ sectionCaption: { type: "string" },
192
+ sectionDescription: { type: "string" },
193
+ isSecret: { enum: [false] }
195
194
  },
196
- else: {
197
- additionalProperties: false,
198
- properties: {
199
- type: { enum: ["string"] },
200
- title: { type: "string" },
201
- description: { type: "string" },
202
- default: { type: "string" },
203
- prefill: { type: "string" },
204
- example: { type: "string" },
205
- pattern: { type: "string" },
206
- nullable: { type: "boolean" },
207
- minLength: { type: "integer" },
208
- maxLength: { type: "integer" },
209
- editor: { enum: ["javascript", "python", "textfield", "textarea", "hidden", "fileupload"] },
210
- isSecret: { enum: [false] },
211
- sectionCaption: { type: "string" },
212
- sectionDescription: { type: "string" }
195
+ unevaluatedProperties: false,
196
+ allOf: [
197
+ {
198
+ if: {
199
+ properties: {
200
+ editor: { const: "datepicker" }
201
+ }
202
+ },
203
+ then: {
204
+ properties: {
205
+ editor: { enum: ["datepicker"] },
206
+ dateType: { enum: ["absolute", "relative", "absoluteOrRelative"] }
207
+ }
208
+ },
209
+ else: {
210
+ properties: {
211
+ editor: { enum: ["javascript", "python", "textfield", "textarea", "hidden", "fileupload"] }
212
+ }
213
+ }
214
+ },
215
+ {
216
+ if: {
217
+ properties: { nullable: { const: false } }
218
+ },
219
+ then: {
220
+ properties: { default: { type: "string" } }
221
+ },
222
+ else: {
223
+ properties: { default: { type: ["string", "null"] } }
224
+ }
213
225
  }
214
- }
226
+ ]
215
227
  },
216
228
  else: {
217
229
  additionalProperties: false,
@@ -234,86 +246,105 @@ var schema_default = {
234
246
  type: "object",
235
247
  properties: {
236
248
  type: { enum: ["array"] },
237
- editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "select", "hidden"] },
249
+ editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "select", "schemaBased", "hidden"] },
238
250
  isSecret: { type: "boolean" }
239
251
  },
240
- additionalProperties: true,
241
252
  required: ["type", "title", "description", "editor"],
242
253
  if: {
243
254
  properties: {
244
- isSecret: {
245
- not: {
246
- const: true
247
- }
248
- }
255
+ isSecret: { not: { const: true } }
249
256
  }
250
257
  },
251
258
  then: {
252
- if: {
253
- properties: {
254
- editor: { const: "select" }
255
- }
259
+ properties: {
260
+ type: { enum: ["array"] },
261
+ title: { type: "string" },
262
+ description: { type: "string" },
263
+ prefill: { type: "array" },
264
+ example: { type: "array" },
265
+ nullable: { type: "boolean" },
266
+ minItems: { type: "integer" },
267
+ maxItems: { type: "integer" },
268
+ uniqueItems: { type: "boolean" },
269
+ sectionCaption: { type: "string" },
270
+ sectionDescription: { type: "string" },
271
+ placeholderKey: { type: "string" },
272
+ placeholderValue: { type: "string" },
273
+ patternKey: { type: "string" },
274
+ patternValue: { type: "string" },
275
+ isSecret: { enum: [false] }
256
276
  },
257
- then: {
258
- additionalProperties: false,
259
- required: ["items"],
260
- properties: {
261
- type: { enum: ["array"] },
262
- editor: { enum: ["select"] },
263
- title: { type: "string" },
264
- description: { type: "string" },
265
- default: { type: "array" },
266
- prefill: { type: "array" },
267
- example: { type: "array" },
268
- nullable: { type: "boolean" },
269
- minItems: { type: "integer" },
270
- maxItems: { type: "integer" },
271
- uniqueItems: { type: "boolean" },
272
- sectionCaption: { type: "string" },
273
- sectionDescription: { type: "string" },
274
- items: {
275
- type: "object",
276
- additionalProperties: false,
277
- properties: {
278
- type: { enum: ["string"] },
279
- enum: {
280
- type: "array",
281
- items: { type: "string" },
282
- uniqueItems: true
283
- },
284
- enumTitles: {
285
- type: "array",
286
- items: { type: "string" }
277
+ unevaluatedProperties: false,
278
+ allOf: [
279
+ {
280
+ oneOf: [
281
+ {
282
+ required: ["editor"],
283
+ properties: {
284
+ editor: { enum: ["select"] },
285
+ items: { $ref: "#/definitions/arrayItemsSelect" }
286
+ }
287
+ },
288
+ {
289
+ required: ["editor"],
290
+ properties: {
291
+ editor: { enum: ["keyValue"] },
292
+ items: { $ref: "#/definitions/arrayItemsKeyValue" }
293
+ }
294
+ },
295
+ {
296
+ required: ["editor"],
297
+ properties: {
298
+ editor: { enum: ["stringList"] },
299
+ items: { $ref: "#/definitions/arrayItemsStringList" }
300
+ }
301
+ },
302
+ {
303
+ required: ["editor"],
304
+ properties: {
305
+ editor: { enum: ["globs"] },
306
+ items: { $ref: "#/definitions/arrayItemsGlobs" }
307
+ }
308
+ },
309
+ {
310
+ required: ["editor"],
311
+ properties: {
312
+ editor: { enum: ["pseudoUrls"] },
313
+ items: { $ref: "#/definitions/arrayItemsPseudoUrls" }
314
+ }
315
+ },
316
+ {
317
+ required: ["editor"],
318
+ properties: {
319
+ editor: { enum: ["requestListSources"] },
320
+ items: { $ref: "#/definitions/arrayItemsRequestListSources" }
321
+ }
322
+ },
323
+ {
324
+ required: ["editor"],
325
+ properties: {
326
+ editor: { enum: ["json", "schemaBased", "hidden"] },
327
+ items: { $ref: "#/definitions/arrayItems" }
287
328
  }
288
329
  },
289
- required: ["type", "enum"]
330
+ {
331
+ not: { required: ["editor"] },
332
+ properties: { items: { $ref: "#/definitions/arrayItems" } }
333
+ }
334
+ ]
335
+ },
336
+ {
337
+ if: {
338
+ properties: { nullable: { const: false } }
290
339
  },
291
- isSecret: { enum: [false] }
292
- }
293
- },
294
- else: {
295
- additionalProperties: false,
296
- properties: {
297
- type: { enum: ["array"] },
298
- editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "hidden"] },
299
- title: { type: "string" },
300
- description: { type: "string" },
301
- default: { type: "array" },
302
- prefill: { type: "array" },
303
- example: { type: "array" },
304
- nullable: { type: "boolean" },
305
- minItems: { type: "integer" },
306
- maxItems: { type: "integer" },
307
- uniqueItems: { type: "boolean" },
308
- sectionCaption: { type: "string" },
309
- sectionDescription: { type: "string" },
310
- placeholderKey: { type: "string" },
311
- placeholderValue: { type: "string" },
312
- patternKey: { type: "string" },
313
- patternValue: { type: "string" },
314
- isSecret: { enum: [false] }
340
+ then: {
341
+ properties: { default: { type: "array" } }
342
+ },
343
+ else: {
344
+ properties: { default: { type: ["array", "null"] } }
345
+ }
315
346
  }
316
- }
347
+ ]
317
348
  },
318
349
  else: {
319
350
  additionalProperties: false,
@@ -330,6 +361,7 @@ var schema_default = {
330
361
  uniqueItems: { type: "boolean" },
331
362
  sectionCaption: { type: "string" },
332
363
  sectionDescription: { type: "string" },
364
+ items: { $ref: "#/definitions/arrayItems" },
333
365
  isSecret: { enum: [true] }
334
366
  }
335
367
  }
@@ -337,31 +369,24 @@ var schema_default = {
337
369
  objectProperty: {
338
370
  title: "Object property",
339
371
  type: "object",
340
- additionalProperties: true,
341
372
  properties: {
342
373
  type: { enum: ["object"] },
343
374
  title: { type: "string" },
344
375
  description: { type: "string" },
345
- editor: { enum: ["json", "proxy", "hidden"] },
376
+ editor: { enum: ["json", "proxy", "schemaBased", "hidden"] },
346
377
  isSecret: { type: "boolean" }
347
378
  },
348
379
  required: ["type", "title", "description", "editor"],
349
380
  if: {
350
381
  properties: {
351
- isSecret: {
352
- not: {
353
- const: true
354
- }
355
- }
382
+ isSecret: { not: { const: true } }
356
383
  }
357
384
  },
358
385
  then: {
359
- additionalProperties: false,
360
386
  properties: {
361
387
  type: { enum: ["object"] },
362
388
  title: { type: "string" },
363
389
  description: { type: "string" },
364
- default: { type: "object" },
365
390
  prefill: { type: "object" },
366
391
  example: { type: "object" },
367
392
  patternKey: { type: "string" },
@@ -369,11 +394,46 @@ var schema_default = {
369
394
  nullable: { type: "boolean" },
370
395
  minProperties: { type: "integer" },
371
396
  maxProperties: { type: "integer" },
372
- editor: { enum: ["json", "proxy", "hidden"] },
397
+ editor: { enum: ["json", "proxy", "schemaBased", "hidden"] },
373
398
  sectionCaption: { type: "string" },
374
399
  sectionDescription: { type: "string" },
375
- isSecret: { enum: [false] }
376
- }
400
+ isSecret: { enum: [false] },
401
+ required: {
402
+ type: "array",
403
+ minItems: 0,
404
+ items: { type: "string" },
405
+ uniqueItems: true
406
+ },
407
+ additionalProperties: {
408
+ type: "boolean"
409
+ }
410
+ },
411
+ unevaluatedProperties: false,
412
+ allOf: [
413
+ {
414
+ oneOf: [
415
+ { properties: {
416
+ editor: { enum: ["proxy"] },
417
+ properties: { $ref: "#/definitions/subObjectPropertiesProxy" }
418
+ } },
419
+ { properties: {
420
+ editor: { enum: ["json", "schemaBased", "hidden"] },
421
+ properties: { $ref: "#/definitions/subObjectProperties" }
422
+ } }
423
+ ]
424
+ },
425
+ {
426
+ if: {
427
+ properties: { nullable: { const: false } }
428
+ },
429
+ then: {
430
+ properties: { default: { type: "object" } }
431
+ },
432
+ else: {
433
+ properties: { default: { type: ["object", "null"] } }
434
+ }
435
+ }
436
+ ]
377
437
  },
378
438
  else: {
379
439
  additionalProperties: false,
@@ -391,19 +451,28 @@ var schema_default = {
391
451
  editor: { enum: ["json", "hidden"] },
392
452
  sectionCaption: { type: "string" },
393
453
  sectionDescription: { type: "string" },
394
- isSecret: { enum: [true] }
454
+ properties: { $ref: "#/definitions/subObjectProperties" },
455
+ isSecret: { enum: [true] },
456
+ required: {
457
+ type: "array",
458
+ minItems: 0,
459
+ items: { type: "string" },
460
+ uniqueItems: true
461
+ },
462
+ additionalProperties: {
463
+ type: "boolean"
464
+ }
395
465
  }
396
466
  }
397
467
  },
398
468
  integerProperty: {
399
469
  title: "Integer property",
400
470
  type: "object",
401
- additionalProperties: false,
471
+ unevaluatedProperties: false,
402
472
  properties: {
403
473
  type: { enum: ["integer"] },
404
474
  title: { type: "string" },
405
475
  description: { type: "string" },
406
- default: { type: "integer" },
407
476
  prefill: { type: "integer" },
408
477
  example: { type: "integer" },
409
478
  nullable: { type: "boolean" },
@@ -414,17 +483,25 @@ var schema_default = {
414
483
  sectionCaption: { type: "string" },
415
484
  sectionDescription: { type: "string" }
416
485
  },
417
- required: ["type", "title", "description"]
486
+ required: ["type", "title", "description"],
487
+ if: {
488
+ properties: { nullable: { const: false } }
489
+ },
490
+ then: {
491
+ properties: { default: { type: "integer" } }
492
+ },
493
+ else: {
494
+ properties: { default: { type: ["integer", "null"] } }
495
+ }
418
496
  },
419
497
  booleanProperty: {
420
498
  title: "Boolean property",
421
499
  type: "object",
422
- additionalProperties: false,
500
+ unevaluatedProperties: false,
423
501
  properties: {
424
502
  type: { enum: ["boolean"] },
425
503
  title: { type: "string" },
426
504
  description: { type: "string" },
427
- default: { type: "boolean" },
428
505
  prefill: { type: "boolean" },
429
506
  example: { type: "boolean" },
430
507
  nullable: { type: "boolean" },
@@ -434,12 +511,21 @@ var schema_default = {
434
511
  sectionCaption: { type: "string" },
435
512
  sectionDescription: { type: "string" }
436
513
  },
437
- required: ["type", "title", "description"]
514
+ required: ["type", "title", "description"],
515
+ if: {
516
+ properties: { nullable: { const: false } }
517
+ },
518
+ then: {
519
+ properties: { default: { type: "boolean" } }
520
+ },
521
+ else: {
522
+ properties: { default: { type: ["boolean", "null"] } }
523
+ }
438
524
  },
439
525
  resourceProperty: {
440
526
  title: "Resource property",
441
527
  type: "object",
442
- additionalProperties: false,
528
+ unevaluatedProperties: false,
443
529
  properties: {
444
530
  type: { enum: ["string"] },
445
531
  title: { type: "string" },
@@ -458,7 +544,6 @@ var schema_default = {
458
544
  const: "READ"
459
545
  }
460
546
  },
461
- default: { type: "string" },
462
547
  prefill: { type: "string" },
463
548
  example: { type: "string" },
464
549
  nullable: { type: "boolean" },
@@ -479,13 +564,24 @@ var schema_default = {
479
564
  ]
480
565
  }
481
566
  }
567
+ },
568
+ {
569
+ if: {
570
+ properties: { nullable: { const: false } }
571
+ },
572
+ then: {
573
+ properties: { default: { type: "string" } }
574
+ },
575
+ else: {
576
+ properties: { default: { type: ["string", "null"] } }
577
+ }
482
578
  }
483
579
  ]
484
580
  },
485
581
  resourceArrayProperty: {
486
582
  title: "Resource array property",
487
583
  type: "object",
488
- additionalProperties: false,
584
+ unevaluatedProperties: false,
489
585
  properties: {
490
586
  type: { enum: ["array"] },
491
587
  title: { type: "string" },
@@ -503,7 +599,6 @@ var schema_default = {
503
599
  const: "READ"
504
600
  }
505
601
  },
506
- default: { type: "array" },
507
602
  prefill: { type: "array" },
508
603
  example: { type: "array" },
509
604
  nullable: { type: "boolean" },
@@ -528,13 +623,24 @@ var schema_default = {
528
623
  ]
529
624
  }
530
625
  }
626
+ },
627
+ {
628
+ if: {
629
+ properties: { nullable: { const: false } }
630
+ },
631
+ then: {
632
+ properties: { default: { type: "array" } }
633
+ },
634
+ else: {
635
+ properties: { default: { type: ["array", "null"] } }
636
+ }
531
637
  }
532
638
  ]
533
639
  },
534
640
  anyProperty: {
535
641
  title: "Any property",
536
642
  type: "object",
537
- additionalProperties: false,
643
+ unevaluatedProperties: false,
538
644
  properties: {
539
645
  type: {
540
646
  type: ["array"],
@@ -548,7 +654,6 @@ var schema_default = {
548
654
  },
549
655
  title: { type: "string" },
550
656
  description: { type: "string" },
551
- default: { type: ["object", "array", "string", "integer", "boolean"] },
552
657
  prefill: { type: ["object", "array", "string", "integer", "boolean"] },
553
658
  example: { type: ["object", "array", "string", "integer", "boolean"] },
554
659
  nullable: { type: "boolean" },
@@ -556,108 +661,758 @@ var schema_default = {
556
661
  sectionCaption: { type: "string" },
557
662
  sectionDescription: { type: "string" }
558
663
  },
559
- required: ["type", "title", "description", "editor"]
560
- }
561
- }
562
- };
563
-
564
- // src/input_schema.ts
565
- var { definitions } = schema_default;
566
- function parseAjvError(error, rootName, properties = {}, input = {}) {
567
- let fieldKey;
568
- let message;
569
- if (error.keyword === "type") {
570
- fieldKey = error.instancePath.split("/").pop();
571
- if (properties[fieldKey] && properties[fieldKey].nullable && input[fieldKey] === null) {
572
- return null;
573
- }
574
- message = m("inputSchema.validation.generic", { rootName, fieldKey, message: error.message });
575
- } else if (error.keyword === "required") {
576
- fieldKey = error.params.missingProperty;
577
- message = m("inputSchema.validation.required", { rootName, fieldKey });
578
- } else if (error.keyword === "additionalProperties") {
579
- fieldKey = error.params.additionalProperty;
580
- message = m("inputSchema.validation.additionalProperty", { rootName, fieldKey });
581
- } else if (error.keyword === "enum") {
582
- fieldKey = error.instancePath.split("/").pop();
583
- const errorMessage = `${error.message}: "${error.params.allowedValues.join('", "')}"`;
584
- message = m("inputSchema.validation.generic", { rootName, fieldKey, message: errorMessage });
585
- } else if (error.keyword === "const") {
586
- fieldKey = error.instancePath.split("/").pop();
587
- message = m("inputSchema.validation.generic", { rootName, fieldKey, message: error.message });
588
- } else {
589
- fieldKey = error.instancePath.split("/").pop();
590
- message = m("inputSchema.validation.generic", { rootName, fieldKey, message: error.message });
591
- }
592
- return { fieldKey, message };
593
- }
594
- __name(parseAjvError, "parseAjvError");
595
- var validateAgainstSchemaOrThrow = /* @__PURE__ */ __name((validator, obj, inputSchema, rootName) => {
596
- if (validator.validate(inputSchema, obj)) return;
597
- const errorMessage = parseAjvError(validator.errors[0], rootName)?.message;
598
- throw new Error(`Input schema is not valid (${errorMessage})`);
599
- }, "validateAgainstSchemaOrThrow");
600
- function validateBasicStructure(validator, obj) {
601
- const schemaWithoutProperties = {
602
- ...schema_default,
603
- properties: { ...schema_default.properties, properties: { type: "object" } }
604
- };
605
- validateAgainstSchemaOrThrow(validator, obj, schemaWithoutProperties, "schema");
606
- }
607
- __name(validateBasicStructure, "validateBasicStructure");
608
- function validateField(validator, fieldSchema, fieldKey) {
609
- const matchingDefinitions = Object.values(definitions).filter((definition2) => {
610
- return definition2.properties.type.enum ? definition2.properties.type.enum[0] === fieldSchema.type : Array.isArray(fieldSchema.type);
611
- });
612
- if (matchingDefinitions.length === 0) {
613
- const errorMessage = m("inputSchema.validation.noMatchingDefinition", { fieldKey });
614
- throw new Error(`Input schema is not valid (${errorMessage})`);
615
- }
616
- if (matchingDefinitions.length === 1) {
617
- validateAgainstSchemaOrThrow(validator, fieldSchema, matchingDefinitions[0], `schema.properties.${fieldKey}`);
618
- return;
619
- }
620
- if (fieldSchema.enum) {
621
- const definition2 = matchingDefinitions.filter((item) => !!item.properties.enum).pop();
622
- if (!definition2) throw new Error('Input schema validation failed to find "enum property" definition');
623
- validateAgainstSchemaOrThrow(validator, fieldSchema, definition2, `schema.properties.${fieldKey}.enum`);
624
- return;
625
- }
626
- if (fieldSchema.resourceType) {
627
- const definition2 = matchingDefinitions.filter((item) => !!item.properties.resourceType).pop();
628
- if (!definition2) throw new Error('Input schema validation failed to find "resource property" definition');
629
- validateAgainstSchemaOrThrow(validator, fieldSchema, definition2, `schema.properties.${fieldKey}`);
630
- return;
631
- }
632
- const definition = matchingDefinitions.filter((item) => !item.properties.enum && !item.properties.resourceType).pop();
633
- if (!definition) throw new Error('Input schema validation failed to find other than "enum property" definition');
634
- validateAgainstSchemaOrThrow(validator, fieldSchema, definition, `schema.properties.${fieldKey}`);
635
- }
636
- __name(validateField, "validateField");
637
- function validateProperties(inputSchema, validator) {
638
- Object.entries(inputSchema.properties).forEach(
639
- ([fieldKey, fieldSchema]) => validateField(validator, fieldSchema, fieldKey)
640
- );
641
- }
642
- __name(validateProperties, "validateProperties");
643
- function validateExistenceOfRequiredFields(inputSchema) {
644
- if (!inputSchema?.required?.length) return;
645
- Object.values(inputSchema?.required).forEach((fieldKey) => {
646
- if (inputSchema?.properties[fieldKey]) return;
647
- throw new Error(m("inputSchema.validation.missingRequiredField", { fieldKey }));
648
- });
649
- }
650
- __name(validateExistenceOfRequiredFields, "validateExistenceOfRequiredFields");
651
- function validateInputSchema(validator, inputSchema) {
652
- validateBasicStructure(validator, inputSchema);
653
- validateProperties(inputSchema, validator);
654
- validateExistenceOfRequiredFields(inputSchema);
655
- validateAgainstSchemaOrThrow(validator, inputSchema, schema_default, "schema");
656
- }
657
- __name(validateInputSchema, "validateInputSchema");
658
-
659
- // src/utilities.ts
660
- var import_acorn_loose = require("acorn-loose");
664
+ required: ["type", "title", "description", "editor"],
665
+ if: {
666
+ properties: { nullable: { const: false } }
667
+ },
668
+ then: {
669
+ properties: { default: { type: ["object", "array", "string", "integer", "boolean"] } }
670
+ },
671
+ else: {
672
+ properties: { default: { type: ["object", "array", "string", "integer", "boolean", "null"] } }
673
+ }
674
+ },
675
+ subSchemaStringEnumProperty: {
676
+ title: "Sub-schema: Enum property",
677
+ type: "object",
678
+ additionalProperties: false,
679
+ properties: {
680
+ type: { enum: ["string"] },
681
+ editor: { enum: ["select"] },
682
+ title: { type: "string" },
683
+ description: { type: "string" },
684
+ nullable: { type: "boolean" },
685
+ enum: {
686
+ type: "array",
687
+ items: { type: "string" },
688
+ minItems: 1,
689
+ uniqueItems: true
690
+ },
691
+ enumTitles: {
692
+ type: "array",
693
+ items: { type: "string" },
694
+ minItems: 1
695
+ }
696
+ },
697
+ required: ["type", "title", "description", "enum"]
698
+ },
699
+ subSchemaStringProperty: {
700
+ title: "Sub-schema: String property",
701
+ type: "object",
702
+ additionalProperties: true,
703
+ properties: {
704
+ type: { enum: ["string"] },
705
+ title: { type: "string" },
706
+ description: { type: "string" },
707
+ nullable: { type: "boolean" },
708
+ editor: { enum: ["javascript", "python", "textfield", "textarea", "datepicker", "hidden", "fileupload"] }
709
+ },
710
+ required: ["type", "title", "description"],
711
+ if: {
712
+ properties: {
713
+ editor: { const: "datepicker" }
714
+ }
715
+ },
716
+ then: {
717
+ additionalProperties: false,
718
+ properties: {
719
+ type: { enum: ["string"] },
720
+ title: { type: "string" },
721
+ description: { type: "string" },
722
+ pattern: { type: "string" },
723
+ nullable: { type: "boolean" },
724
+ minLength: { type: "integer" },
725
+ maxLength: { type: "integer" },
726
+ editor: { enum: ["datepicker"] },
727
+ dateType: { enum: ["absolute", "relative", "absoluteOrRelative"] }
728
+ }
729
+ },
730
+ else: {
731
+ additionalProperties: false,
732
+ properties: {
733
+ type: { enum: ["string"] },
734
+ title: { type: "string" },
735
+ description: { type: "string" },
736
+ pattern: { type: "string" },
737
+ nullable: { type: "boolean" },
738
+ minLength: { type: "integer" },
739
+ maxLength: { type: "integer" },
740
+ editor: { enum: ["javascript", "python", "textfield", "textarea", "hidden", "fileupload"] }
741
+ }
742
+ }
743
+ },
744
+ subSchemaArrayProperty: {
745
+ title: "Sub-schema: Array property",
746
+ type: "object",
747
+ properties: {
748
+ type: { enum: ["array"] },
749
+ editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "select", "hidden"] },
750
+ title: { type: "string" },
751
+ description: { type: "string" },
752
+ nullable: { type: "boolean" },
753
+ minItems: { type: "integer" },
754
+ maxItems: { type: "integer" },
755
+ uniqueItems: { type: "boolean" },
756
+ placeholderKey: { type: "string" },
757
+ placeholderValue: { type: "string" },
758
+ patternKey: { type: "string" },
759
+ patternValue: { type: "string" }
760
+ },
761
+ required: ["type", "title", "description"],
762
+ unevaluatedProperties: false,
763
+ oneOf: [
764
+ {
765
+ required: ["editor"],
766
+ properties: {
767
+ editor: { enum: ["select"] },
768
+ items: { $ref: "#/definitions/arrayItemsSelect" }
769
+ }
770
+ },
771
+ {
772
+ required: ["editor"],
773
+ properties: {
774
+ editor: { enum: ["keyValue"] },
775
+ items: { $ref: "#/definitions/arrayItemsKeyValue" }
776
+ }
777
+ },
778
+ {
779
+ required: ["editor"],
780
+ properties: {
781
+ editor: { enum: ["stringList"] },
782
+ items: { $ref: "#/definitions/arrayItemsStringList" }
783
+ }
784
+ },
785
+ {
786
+ required: ["editor"],
787
+ properties: {
788
+ editor: { enum: ["globs"] },
789
+ items: { $ref: "#/definitions/arrayItemsGlobs" }
790
+ }
791
+ },
792
+ {
793
+ required: ["editor"],
794
+ properties: {
795
+ editor: { enum: ["pseudoUrls"] },
796
+ items: { $ref: "#/definitions/arrayItemsPseudoUrls" }
797
+ }
798
+ },
799
+ {
800
+ required: ["editor"],
801
+ properties: {
802
+ editor: { enum: ["requestListSources"] },
803
+ items: { $ref: "#/definitions/arrayItemsRequestListSources" }
804
+ }
805
+ },
806
+ {
807
+ required: ["editor"],
808
+ properties: {
809
+ editor: { enum: ["json", "schemaBased", "hidden"] },
810
+ items: { $ref: "#/definitions/arrayItems" }
811
+ }
812
+ },
813
+ {
814
+ not: { required: ["editor"] },
815
+ properties: { items: { $ref: "#/definitions/arrayItems" } }
816
+ }
817
+ ]
818
+ },
819
+ subSchemaIntegerProperty: {
820
+ title: "Sub-schema: Integer property",
821
+ type: "object",
822
+ additionalProperties: false,
823
+ properties: {
824
+ type: { enum: ["integer"] },
825
+ title: { type: "string" },
826
+ description: { type: "string" },
827
+ nullable: { type: "boolean" },
828
+ minimum: { type: "integer" },
829
+ maximum: { type: "integer" },
830
+ unit: { type: "string" },
831
+ editor: { enum: ["number", "hidden"] }
832
+ },
833
+ required: ["type", "title", "description"]
834
+ },
835
+ subSchemaBooleanProperty: {
836
+ title: "Sub-schema: Boolean property",
837
+ type: "object",
838
+ additionalProperties: false,
839
+ properties: {
840
+ type: { enum: ["boolean"] },
841
+ title: { type: "string" },
842
+ description: { type: "string" },
843
+ nullable: { type: "boolean" },
844
+ groupCaption: { type: "string" },
845
+ groupDescription: { type: "string" },
846
+ editor: { enum: ["checkbox", "hidden"] }
847
+ },
848
+ required: ["type", "title", "description"]
849
+ },
850
+ subSchemaObjectProperty: {
851
+ title: "Sub-schema: Object property",
852
+ type: "object",
853
+ additionalProperties: false,
854
+ properties: {
855
+ type: { enum: ["object"] },
856
+ title: { type: "string" },
857
+ description: { type: "string" },
858
+ patternKey: { type: "string" },
859
+ patternValue: { type: "string" },
860
+ nullable: { type: "boolean" },
861
+ minProperties: { type: "integer" },
862
+ maxProperties: { type: "integer" },
863
+ editor: { enum: ["json", "proxy", "hidden"] },
864
+ properties: { $ref: "#/definitions/subObjectProperties" },
865
+ required: {
866
+ type: "array",
867
+ minItems: 0,
868
+ items: { type: "string" },
869
+ uniqueItems: true
870
+ },
871
+ additionalProperties: {
872
+ type: "boolean"
873
+ }
874
+ },
875
+ required: ["type", "title", "description"]
876
+ },
877
+ subSchemaResourceProperty: {
878
+ title: "Sub-schema: Resource property",
879
+ type: "object",
880
+ additionalProperties: false,
881
+ properties: {
882
+ type: { enum: ["string"] },
883
+ title: { type: "string" },
884
+ description: { type: "string" },
885
+ editor: { enum: ["resourcePicker", "hidden"] },
886
+ resourceType: { enum: ["dataset", "keyValueStore", "requestQueue"] },
887
+ resourcePermissions: {
888
+ type: "array",
889
+ items: {
890
+ type: "string",
891
+ enum: ["READ", "WRITE"]
892
+ },
893
+ minItems: 1,
894
+ uniqueItems: true,
895
+ contains: {
896
+ const: "READ"
897
+ }
898
+ },
899
+ nullable: { type: "boolean" }
900
+ },
901
+ required: ["type", "title", "description", "resourceType"]
902
+ },
903
+ subSchemaResourceArrayProperty: {
904
+ title: "Sub-schema: Resource array property",
905
+ type: "object",
906
+ additionalProperties: false,
907
+ properties: {
908
+ type: { enum: ["array"] },
909
+ title: { type: "string" },
910
+ description: { type: "string" },
911
+ editor: { enum: ["resourcePicker", "hidden"] },
912
+ resourcePermissions: {
913
+ type: "array",
914
+ items: {
915
+ type: "string",
916
+ enum: ["READ", "WRITE"]
917
+ },
918
+ minItems: 1,
919
+ uniqueItems: true,
920
+ contains: {
921
+ const: "READ"
922
+ }
923
+ },
924
+ nullable: { type: "boolean" },
925
+ minItems: { type: "integer" },
926
+ maxItems: { type: "integer" },
927
+ uniqueItems: { type: "boolean" },
928
+ resourceType: { enum: ["dataset", "keyValueStore", "requestQueue"] }
929
+ },
930
+ required: ["type", "title", "description", "resourceType"]
931
+ },
932
+ arrayItems: {
933
+ title: "Utils: Array items definition",
934
+ type: "object",
935
+ properties: {
936
+ type: { enum: ["string", "integer", "boolean", "object", "array"] }
937
+ },
938
+ required: ["type"],
939
+ if: {
940
+ properties: {
941
+ type: { enum: ["object"] }
942
+ }
943
+ },
944
+ then: {
945
+ additionalProperties: false,
946
+ properties: {
947
+ type: { enum: ["object"] },
948
+ properties: {
949
+ type: "object",
950
+ patternProperties: {
951
+ "^": {
952
+ oneOf: [
953
+ { $ref: "#/definitions/subSchemaStringProperty" },
954
+ { $ref: "#/definitions/subSchemaStringEnumProperty" },
955
+ { $ref: "#/definitions/subSchemaArrayProperty" },
956
+ { $ref: "#/definitions/subSchemaObjectProperty" },
957
+ { $ref: "#/definitions/subSchemaIntegerProperty" },
958
+ { $ref: "#/definitions/subSchemaBooleanProperty" },
959
+ { $ref: "#/definitions/subSchemaResourceProperty" },
960
+ { $ref: "#/definitions/subSchemaResourceArrayProperty" }
961
+ ]
962
+ }
963
+ },
964
+ additionalProperties: false
965
+ },
966
+ required: {
967
+ type: "array",
968
+ minItems: 0,
969
+ items: { type: "string" },
970
+ uniqueItems: true
971
+ },
972
+ additionalProperties: {
973
+ type: "boolean"
974
+ }
975
+ }
976
+ },
977
+ else: {
978
+ if: {
979
+ properties: { type: { const: "array" } }
980
+ },
981
+ then: {
982
+ additionalProperties: false,
983
+ properties: {
984
+ type: { enum: ["array"] },
985
+ items: {
986
+ $ref: "#/definitions/arrayItems"
987
+ }
988
+ }
989
+ },
990
+ else: {
991
+ additionalProperties: false,
992
+ properties: {
993
+ type: { enum: ["string", "integer", "boolean"] }
994
+ }
995
+ }
996
+ }
997
+ },
998
+ arrayItemsSelect: {
999
+ title: "Utils: Array items select definition",
1000
+ type: "object",
1001
+ additionalProperties: false,
1002
+ properties: {
1003
+ type: { enum: ["string"] },
1004
+ enum: {
1005
+ type: "array",
1006
+ items: { type: "string" },
1007
+ uniqueItems: true
1008
+ },
1009
+ enumTitles: {
1010
+ type: "array",
1011
+ items: { type: "string" }
1012
+ }
1013
+ },
1014
+ required: ["type", "enum"]
1015
+ },
1016
+ arrayItemsKeyValue: {
1017
+ title: "Utils: Array items keyValue definition",
1018
+ type: "object",
1019
+ additionalProperties: false,
1020
+ properties: {
1021
+ type: { enum: ["object"] },
1022
+ properties: {
1023
+ type: "object",
1024
+ properties: {
1025
+ key: {
1026
+ type: "object",
1027
+ additionalProperties: false,
1028
+ properties: {
1029
+ type: { enum: ["string"] },
1030
+ title: { type: "string" },
1031
+ description: { type: "string" },
1032
+ pattern: { type: "string" },
1033
+ minLength: { type: "integer" },
1034
+ maxLength: { type: "integer" }
1035
+ },
1036
+ required: ["type"]
1037
+ },
1038
+ value: {
1039
+ type: "object",
1040
+ additionalProperties: false,
1041
+ properties: {
1042
+ type: { enum: ["string"] },
1043
+ title: { type: "string" },
1044
+ description: { type: "string" },
1045
+ pattern: { type: "string" },
1046
+ minLength: { type: "integer" },
1047
+ maxLength: { type: "integer" }
1048
+ },
1049
+ required: ["type"]
1050
+ }
1051
+ },
1052
+ required: ["key", "value"],
1053
+ additionalProperties: false
1054
+ },
1055
+ required: {
1056
+ type: "array",
1057
+ minItems: 0,
1058
+ items: { type: "string" },
1059
+ uniqueItems: true
1060
+ },
1061
+ additionalProperties: { type: "boolean" }
1062
+ },
1063
+ required: ["type", "properties"]
1064
+ },
1065
+ arrayItemsStringList: {
1066
+ title: "Utils: Array items stringList definition",
1067
+ type: "object",
1068
+ additionalProperties: false,
1069
+ properties: {
1070
+ type: { enum: ["string"] },
1071
+ pattern: { type: "string" },
1072
+ minLength: { type: "integer" },
1073
+ maxLength: { type: "integer" }
1074
+ },
1075
+ required: ["type"]
1076
+ },
1077
+ arrayItemsGlobs: {
1078
+ title: "Utils: Array items globs definition",
1079
+ type: "object",
1080
+ additionalProperties: false,
1081
+ properties: {
1082
+ type: { enum: ["object"] },
1083
+ properties: {
1084
+ type: "object",
1085
+ additionalProperties: false,
1086
+ properties: {
1087
+ glob: {
1088
+ type: "object",
1089
+ additionalProperties: false,
1090
+ properties: {
1091
+ type: { enum: ["string"] },
1092
+ title: { type: "string" },
1093
+ description: { type: "string" },
1094
+ pattern: { type: "string" },
1095
+ minLength: { type: "integer" },
1096
+ maxLength: { type: "integer" }
1097
+ },
1098
+ required: ["type"]
1099
+ },
1100
+ method: {
1101
+ type: "object",
1102
+ additionalProperties: false,
1103
+ properties: {
1104
+ type: { enum: ["string"] },
1105
+ title: { type: "string" },
1106
+ description: { type: "string" },
1107
+ pattern: { type: "string" },
1108
+ minLength: { type: "integer" },
1109
+ maxLength: { type: "integer" }
1110
+ },
1111
+ required: ["type"]
1112
+ },
1113
+ payload: {
1114
+ type: "object",
1115
+ additionalProperties: false,
1116
+ properties: {
1117
+ type: { enum: ["string"] },
1118
+ title: { type: "string" },
1119
+ description: { type: "string" },
1120
+ pattern: { type: "string" },
1121
+ minLength: { type: "integer" },
1122
+ maxLength: { type: "integer" }
1123
+ },
1124
+ required: ["type"]
1125
+ },
1126
+ userData: {
1127
+ type: "object",
1128
+ additionalProperties: false,
1129
+ properties: {
1130
+ type: { enum: ["object"] },
1131
+ title: { type: "string" },
1132
+ description: { type: "string" },
1133
+ properties: { type: "object" }
1134
+ },
1135
+ required: ["type"]
1136
+ },
1137
+ headers: {
1138
+ type: "object",
1139
+ additionalProperties: false,
1140
+ properties: {
1141
+ type: { enum: ["object"] },
1142
+ title: { type: "string" },
1143
+ description: { type: "string" },
1144
+ properties: { type: "object" }
1145
+ },
1146
+ required: ["type"]
1147
+ }
1148
+ }
1149
+ },
1150
+ required: {
1151
+ type: "array",
1152
+ minItems: 0,
1153
+ items: { type: "string" },
1154
+ uniqueItems: true
1155
+ },
1156
+ additionalProperties: { type: "boolean" }
1157
+ },
1158
+ required: ["type"]
1159
+ },
1160
+ arrayItemsPseudoUrls: {
1161
+ title: "Utils: Array items pseudoUrls definition",
1162
+ type: "object",
1163
+ additionalProperties: false,
1164
+ properties: {
1165
+ type: { enum: ["object"] },
1166
+ properties: {
1167
+ type: "object",
1168
+ additionalProperties: false,
1169
+ properties: {
1170
+ purl: {
1171
+ type: "object",
1172
+ additionalProperties: false,
1173
+ properties: {
1174
+ type: { enum: ["string"] },
1175
+ title: { type: "string" },
1176
+ description: { type: "string" },
1177
+ pattern: { type: "string" },
1178
+ minLength: { type: "integer" },
1179
+ maxLength: { type: "integer" }
1180
+ },
1181
+ required: ["type"]
1182
+ },
1183
+ method: {
1184
+ type: "object",
1185
+ additionalProperties: false,
1186
+ properties: {
1187
+ type: { enum: ["string"] },
1188
+ title: { type: "string" },
1189
+ description: { type: "string" },
1190
+ pattern: { type: "string" },
1191
+ minLength: { type: "integer" },
1192
+ maxLength: { type: "integer" }
1193
+ },
1194
+ required: ["type"]
1195
+ },
1196
+ payload: {
1197
+ type: "object",
1198
+ additionalProperties: false,
1199
+ properties: {
1200
+ type: { enum: ["string"] },
1201
+ title: { type: "string" },
1202
+ description: { type: "string" },
1203
+ pattern: { type: "string" },
1204
+ minLength: { type: "integer" },
1205
+ maxLength: { type: "integer" }
1206
+ },
1207
+ required: ["type"]
1208
+ },
1209
+ userData: {
1210
+ type: "object",
1211
+ additionalProperties: false,
1212
+ properties: {
1213
+ type: { enum: ["object"] },
1214
+ title: { type: "string" },
1215
+ description: { type: "string" },
1216
+ properties: { type: "object" }
1217
+ },
1218
+ required: ["type"]
1219
+ },
1220
+ headers: {
1221
+ type: "object",
1222
+ additionalProperties: false,
1223
+ properties: {
1224
+ type: { enum: ["object"] },
1225
+ title: { type: "string" },
1226
+ description: { type: "string" },
1227
+ properties: { type: "object" }
1228
+ },
1229
+ required: ["type"]
1230
+ }
1231
+ }
1232
+ },
1233
+ required: {
1234
+ type: "array",
1235
+ minItems: 0,
1236
+ items: { type: "string" },
1237
+ uniqueItems: true
1238
+ },
1239
+ additionalProperties: { type: "boolean" }
1240
+ },
1241
+ required: ["type"]
1242
+ },
1243
+ arrayItemsRequestListSources: {
1244
+ title: "Utils: Array items requestListSources definition",
1245
+ type: "object",
1246
+ additionalProperties: false,
1247
+ properties: {
1248
+ type: { enum: ["object"] },
1249
+ properties: {
1250
+ type: "object",
1251
+ additionalProperties: false,
1252
+ properties: {
1253
+ url: {
1254
+ type: "object",
1255
+ additionalProperties: false,
1256
+ properties: {
1257
+ type: { enum: ["string"] },
1258
+ title: { type: "string" },
1259
+ description: { type: "string" },
1260
+ pattern: { type: "string" },
1261
+ minLength: { type: "integer" },
1262
+ maxLength: { type: "integer" }
1263
+ },
1264
+ required: ["type"]
1265
+ },
1266
+ method: {
1267
+ type: "object",
1268
+ additionalProperties: false,
1269
+ properties: {
1270
+ type: { enum: ["string"] },
1271
+ title: { type: "string" },
1272
+ description: { type: "string" },
1273
+ pattern: { type: "string" },
1274
+ minLength: { type: "integer" },
1275
+ maxLength: { type: "integer" }
1276
+ },
1277
+ required: ["type"]
1278
+ },
1279
+ payload: {
1280
+ type: "object",
1281
+ additionalProperties: false,
1282
+ properties: {
1283
+ type: { enum: ["string"] },
1284
+ title: { type: "string" },
1285
+ description: { type: "string" },
1286
+ pattern: { type: "string" },
1287
+ minLength: { type: "integer" },
1288
+ maxLength: { type: "integer" }
1289
+ },
1290
+ required: ["type"]
1291
+ },
1292
+ userData: {
1293
+ type: "object",
1294
+ additionalProperties: false,
1295
+ properties: {
1296
+ type: { enum: ["object"] },
1297
+ title: { type: "string" },
1298
+ description: { type: "string" },
1299
+ properties: { type: "object" }
1300
+ },
1301
+ required: ["type"]
1302
+ },
1303
+ headers: {
1304
+ type: "object",
1305
+ additionalProperties: false,
1306
+ properties: {
1307
+ type: { enum: ["object"] },
1308
+ title: { type: "string" },
1309
+ description: { type: "string" },
1310
+ properties: { type: "object" }
1311
+ },
1312
+ required: ["type"]
1313
+ }
1314
+ }
1315
+ },
1316
+ required: {
1317
+ type: "array",
1318
+ minItems: 0,
1319
+ items: { type: "string" },
1320
+ uniqueItems: true
1321
+ },
1322
+ additionalProperties: { type: "boolean" }
1323
+ },
1324
+ required: ["type"]
1325
+ },
1326
+ subObjectProperties: {
1327
+ title: "Utils: Sub-object properties definition",
1328
+ type: "object",
1329
+ patternProperties: {
1330
+ "^": {
1331
+ oneOf: [
1332
+ { $ref: "#/definitions/subSchemaStringProperty" },
1333
+ { $ref: "#/definitions/subSchemaStringEnumProperty" },
1334
+ { $ref: "#/definitions/subSchemaArrayProperty" },
1335
+ { $ref: "#/definitions/subSchemaObjectProperty" },
1336
+ { $ref: "#/definitions/subSchemaIntegerProperty" },
1337
+ { $ref: "#/definitions/subSchemaBooleanProperty" },
1338
+ { $ref: "#/definitions/subSchemaResourceProperty" },
1339
+ { $ref: "#/definitions/subSchemaResourceArrayProperty" }
1340
+ ]
1341
+ }
1342
+ },
1343
+ additionalProperties: false
1344
+ },
1345
+ subObjectPropertiesProxy: {
1346
+ title: "Utils: Sub-object properties proxy definition",
1347
+ type: "object",
1348
+ additionalProperties: false,
1349
+ properties: {
1350
+ useApifyProxy: {
1351
+ type: "object",
1352
+ additionalProperties: false,
1353
+ properties: {
1354
+ type: { enum: ["boolean"] },
1355
+ title: { type: "string" },
1356
+ description: { type: "string" }
1357
+ },
1358
+ required: ["type"]
1359
+ },
1360
+ apifyProxyGroups: {
1361
+ type: "object",
1362
+ additionalProperties: false,
1363
+ properties: {
1364
+ type: { enum: ["array"] },
1365
+ title: { type: "string" },
1366
+ description: { type: "string" },
1367
+ items: {
1368
+ type: ["object"],
1369
+ properties: {
1370
+ type: { enum: ["string"] }
1371
+ },
1372
+ additionalProperties: false,
1373
+ required: ["type"]
1374
+ }
1375
+ },
1376
+ required: ["type"]
1377
+ },
1378
+ proxyUrls: {
1379
+ type: "object",
1380
+ additionalProperties: false,
1381
+ properties: {
1382
+ type: { enum: ["array"] },
1383
+ title: { type: "string" },
1384
+ description: { type: "string" },
1385
+ items: {
1386
+ type: ["object"],
1387
+ properties: {
1388
+ type: { enum: ["string"] }
1389
+ },
1390
+ additionalProperties: false,
1391
+ required: ["type"]
1392
+ }
1393
+ },
1394
+ required: ["type"]
1395
+ },
1396
+ apifyProxyCountry: {
1397
+ type: "object",
1398
+ additionalProperties: false,
1399
+ properties: {
1400
+ type: { enum: ["string"] },
1401
+ title: { type: "string" },
1402
+ description: { type: "string" },
1403
+ pattern: { type: "string" },
1404
+ minLength: { type: "integer" },
1405
+ maxLength: { type: "integer" }
1406
+ },
1407
+ required: ["type"]
1408
+ }
1409
+ }
1410
+ }
1411
+ }
1412
+ };
1413
+
1414
+ // src/utilities.ts
1415
+ var import_acorn_loose = require("acorn-loose");
661
1416
  var import_countries_list = require("countries-list");
662
1417
  var import_consts = require("@apify/consts");
663
1418
  var import_input_secrets = require("@apify/input_secrets");
@@ -893,8 +1648,168 @@ ${globalSpaces}`);
893
1648
  return niceJson;
894
1649
  }
895
1650
  __name(makeInputJsFieldsReadable, "makeInputJsFieldsReadable");
1651
+ var DRAFT_2019_09_META_SCHEMA = "https://json-schema.org/draft/2019-09/schema";
1652
+ function ensureAjvSupportsDraft2019(ajvInstance) {
1653
+ const metaSchema = ajvInstance.getSchema(DRAFT_2019_09_META_SCHEMA);
1654
+ if (!metaSchema) {
1655
+ throw new Error(
1656
+ `The provided Ajv instance does not support draft-2019-09 (missing meta-schema ${DRAFT_2019_09_META_SCHEMA}).`
1657
+ );
1658
+ }
1659
+ }
1660
+ __name(ensureAjvSupportsDraft2019, "ensureAjvSupportsDraft2019");
1661
+
1662
+ // src/input_schema.ts
1663
+ var { definitions } = schema_default;
1664
+ var [fieldDefinitions, subFieldDefinitions] = Object.values(definitions).reduce((acc, definition) => {
1665
+ if (definition.title.startsWith("Utils:")) {
1666
+ return acc;
1667
+ }
1668
+ if (definition.title.startsWith("Sub-schema:")) {
1669
+ acc[1].push(definition);
1670
+ } else {
1671
+ acc[0].push(definition);
1672
+ }
1673
+ return acc;
1674
+ }, [[], []]);
1675
+ function parseAjvError(error, rootName, properties = {}, input = {}) {
1676
+ let fieldKey;
1677
+ let message;
1678
+ const cleanPropertyName = /* @__PURE__ */ __name((name) => {
1679
+ return name.replace(/^\/|\/$/g, "").replace(/\//g, ".");
1680
+ }, "cleanPropertyName");
1681
+ if (error.keyword === "type") {
1682
+ fieldKey = error.instancePath.split("/").pop();
1683
+ if (properties[fieldKey] && properties[fieldKey].nullable && input[fieldKey] === null) {
1684
+ return null;
1685
+ }
1686
+ message = m("inputSchema.validation.generic", { rootName, fieldKey, message: error.message });
1687
+ } else if (error.keyword === "required") {
1688
+ fieldKey = cleanPropertyName(`${error.instancePath}/${error.params.missingProperty}`);
1689
+ message = m("inputSchema.validation.required", { rootName, fieldKey });
1690
+ } else if (error.keyword === "additionalProperties") {
1691
+ fieldKey = cleanPropertyName(`${error.instancePath}/${error.params.additionalProperty}`);
1692
+ message = m("inputSchema.validation.additionalProperty", { rootName, fieldKey });
1693
+ } else if (error.keyword === "unevaluatedProperties") {
1694
+ fieldKey = cleanPropertyName(`${error.instancePath}/${error.params.unevaluatedProperty}`);
1695
+ message = m("inputSchema.validation.additionalProperty", { rootName, fieldKey });
1696
+ } else if (error.keyword === "enum") {
1697
+ fieldKey = cleanPropertyName(error.instancePath);
1698
+ const errorMessage = `${error.message}: "${error.params.allowedValues.join('", "')}"`;
1699
+ message = m("inputSchema.validation.generic", { rootName, fieldKey, message: errorMessage });
1700
+ } else if (error.keyword === "const") {
1701
+ fieldKey = cleanPropertyName(error.instancePath);
1702
+ message = m("inputSchema.validation.generic", { rootName, fieldKey, message: error.message });
1703
+ } else {
1704
+ fieldKey = cleanPropertyName(error.instancePath);
1705
+ message = m("inputSchema.validation.generic", { rootName, fieldKey, message: error.message });
1706
+ }
1707
+ return { fieldKey, message };
1708
+ }
1709
+ __name(parseAjvError, "parseAjvError");
1710
+ var validateAgainstSchemaOrThrow = /* @__PURE__ */ __name((validator, obj, inputSchema, rootName) => {
1711
+ if (validator.validate(inputSchema, obj)) return;
1712
+ const errorMessage = parseAjvError(validator.errors[0], rootName)?.message;
1713
+ throw new Error(`Input schema is not valid (${errorMessage})`);
1714
+ }, "validateAgainstSchemaOrThrow");
1715
+ function validateBasicStructure(validator, obj) {
1716
+ const schemaWithoutProperties = {
1717
+ ...schema_default,
1718
+ properties: { ...schema_default.properties, properties: { type: "object" } }
1719
+ };
1720
+ validateAgainstSchemaOrThrow(validator, obj, schemaWithoutProperties, "schema");
1721
+ }
1722
+ __name(validateBasicStructure, "validateBasicStructure");
1723
+ function validateField(validator, fieldSchema, fieldKey, isSubField = false) {
1724
+ const relevantDefinitions = isSubField ? subFieldDefinitions : fieldDefinitions;
1725
+ const matchingDefinitions = Object.values(relevantDefinitions).filter((definition2) => {
1726
+ return definition2.properties.type.enum ? definition2.properties.type.enum[0] === fieldSchema.type : Array.isArray(fieldSchema.type);
1727
+ });
1728
+ if (matchingDefinitions.length === 0) {
1729
+ const errorMessage = m("inputSchema.validation.noMatchingDefinition", { fieldKey });
1730
+ throw new Error(`Input schema is not valid (${errorMessage})`);
1731
+ }
1732
+ const enhanceDefinition = /* @__PURE__ */ __name((definition2) => {
1733
+ return {
1734
+ ...definition2,
1735
+ definitions
1736
+ };
1737
+ }, "enhanceDefinition");
1738
+ if (matchingDefinitions.length === 1) {
1739
+ validateAgainstSchemaOrThrow(validator, fieldSchema, enhanceDefinition(matchingDefinitions[0]), `schema.properties.${fieldKey}`);
1740
+ return;
1741
+ }
1742
+ if (fieldSchema.enum) {
1743
+ const definition2 = matchingDefinitions.filter((item) => !!item.properties.enum).pop();
1744
+ if (!definition2) throw new Error('Input schema validation failed to find "enum property" definition');
1745
+ validateAgainstSchemaOrThrow(validator, fieldSchema, enhanceDefinition(definition2), `schema.properties.${fieldKey}.enum`);
1746
+ return;
1747
+ }
1748
+ if (fieldSchema.resourceType) {
1749
+ const definition2 = matchingDefinitions.filter((item) => !!item.properties.resourceType).pop();
1750
+ if (!definition2) throw new Error('Input schema validation failed to find "resource property" definition');
1751
+ validateAgainstSchemaOrThrow(validator, fieldSchema, enhanceDefinition(definition2), `schema.properties.${fieldKey}`);
1752
+ return;
1753
+ }
1754
+ const definition = matchingDefinitions.filter((item) => !item.properties.enum && !item.properties.resourceType).pop();
1755
+ if (!definition) throw new Error('Input schema validation failed to find other than "enum property" definition');
1756
+ validateAgainstSchemaOrThrow(validator, fieldSchema, enhanceDefinition(definition), `schema.properties.${fieldKey}`);
1757
+ }
1758
+ __name(validateField, "validateField");
1759
+ function validateSubFields(validator, fieldSchema, fieldKey) {
1760
+ Object.entries(fieldSchema.properties).forEach(([subFieldKey, subFieldSchema]) => {
1761
+ if (subFieldSchema.type === "object" && subFieldSchema.properties) {
1762
+ validateSubFields(validator, subFieldSchema, `${fieldKey}.${subFieldKey}`);
1763
+ }
1764
+ if (subFieldSchema.type === "array" && subFieldSchema.items) {
1765
+ validateArrayField(validator, subFieldSchema, `${fieldKey}.${subFieldKey}`);
1766
+ }
1767
+ validateField(validator, subFieldSchema, `${fieldKey}.${subFieldKey}`, true);
1768
+ });
1769
+ }
1770
+ __name(validateSubFields, "validateSubFields");
1771
+ function validateArrayField(validator, fieldSchema, fieldKey) {
1772
+ const arraySchema = fieldSchema.items;
1773
+ if (!arraySchema) return;
1774
+ if (arraySchema.type === "object" && arraySchema.properties) {
1775
+ validateSubFields(validator, arraySchema, `${fieldKey}.items`);
1776
+ }
1777
+ if (arraySchema.type === "array" && arraySchema.items) {
1778
+ validateArrayField(validator, arraySchema, `${fieldKey}.items`);
1779
+ }
1780
+ }
1781
+ __name(validateArrayField, "validateArrayField");
1782
+ function validateProperties(inputSchema, validator) {
1783
+ Object.entries(inputSchema.properties).forEach(([fieldKey, fieldSchema]) => {
1784
+ if (fieldSchema.type === "object" && fieldSchema.properties) {
1785
+ validateSubFields(validator, fieldSchema, fieldKey);
1786
+ }
1787
+ if (fieldSchema.type === "array" && fieldSchema.items) {
1788
+ validateArrayField(validator, fieldSchema, fieldKey);
1789
+ }
1790
+ validateField(validator, fieldSchema, fieldKey);
1791
+ });
1792
+ }
1793
+ __name(validateProperties, "validateProperties");
1794
+ function validateExistenceOfRequiredFields(inputSchema) {
1795
+ if (!inputSchema?.required?.length) return;
1796
+ Object.values(inputSchema?.required).forEach((fieldKey) => {
1797
+ if (inputSchema?.properties[fieldKey]) return;
1798
+ throw new Error(m("inputSchema.validation.missingRequiredField", { fieldKey }));
1799
+ });
1800
+ }
1801
+ __name(validateExistenceOfRequiredFields, "validateExistenceOfRequiredFields");
1802
+ function validateInputSchema(validator, inputSchema) {
1803
+ ensureAjvSupportsDraft2019(validator);
1804
+ validateBasicStructure(validator, inputSchema);
1805
+ validateProperties(inputSchema, validator);
1806
+ validateExistenceOfRequiredFields(inputSchema);
1807
+ validateAgainstSchemaOrThrow(validator, inputSchema, schema_default, "schema");
1808
+ }
1809
+ __name(validateInputSchema, "validateInputSchema");
896
1810
  // Annotate the CommonJS export names for ESM import in node:
897
1811
  0 && (module.exports = {
1812
+ ensureAjvSupportsDraft2019,
898
1813
  inputSchema,
899
1814
  m,
900
1815
  makeInputJsFieldsReadable,