@naturalcycles/nodejs-lib 15.65.0 → 15.65.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/validation/ajv/getAjv.js +20 -0
- package/dist/validation/ajv/jsonSchemaBuilder.d.ts +1 -0
- package/dist/validation/ajv/jsonSchemaBuilder.js +1 -1
- package/package.json +1 -1
- package/src/stream/ndjson/ndjsonMap.ts +1 -2
- package/src/stream/transform/transformLogProgress.ts +1 -2
- package/src/validation/ajv/getAjv.ts +20 -0
- package/src/validation/ajv/jsonSchemaBuilder.ts +2 -1
|
@@ -414,6 +414,26 @@ export function createAjv(opt) {
|
|
|
414
414
|
return validate;
|
|
415
415
|
},
|
|
416
416
|
});
|
|
417
|
+
// This and `maxProperties2` are added because Ajv validates the `min/maxProperties` before validating the properties.
|
|
418
|
+
// So, in case of `minProperties(1)` and `{ foo: 'bar' }` Ajv will let it pass, even
|
|
419
|
+
// if the property validation would strip `foo` from the data.
|
|
420
|
+
// And Ajv would return `{}` as a successful validation.
|
|
421
|
+
// Since the keyword validation runs after JSON Schema validation,
|
|
422
|
+
// here we can make sure the number of properties are right ex-post property validation.
|
|
423
|
+
// It's named with the `2` suffix, because `minProperties` is reserved.
|
|
424
|
+
// And `maxProperties` does not suffer from this error due to the nature of how maximum works.
|
|
425
|
+
ajv.addKeyword({
|
|
426
|
+
keyword: 'minProperties2',
|
|
427
|
+
type: 'object',
|
|
428
|
+
modifying: false,
|
|
429
|
+
errors: true,
|
|
430
|
+
schemaType: 'number',
|
|
431
|
+
validate: function validate(minProperties, data, _schema, _ctx) {
|
|
432
|
+
if (typeof data !== 'object')
|
|
433
|
+
return true;
|
|
434
|
+
return Object.getOwnPropertyNames(data).length >= minProperties;
|
|
435
|
+
},
|
|
436
|
+
});
|
|
417
437
|
return ajv;
|
|
418
438
|
}
|
|
419
439
|
const monthLengths = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
@@ -401,6 +401,7 @@ export interface JsonSchema<IN = unknown, OUT = IN> {
|
|
|
401
401
|
errorMessages?: StringMap<string>;
|
|
402
402
|
optionalValues?: (string | number | boolean)[];
|
|
403
403
|
keySchema?: JsonSchema;
|
|
404
|
+
minProperties2?: number;
|
|
404
405
|
}
|
|
405
406
|
declare function object(props: AnyObject): never;
|
|
406
407
|
declare function object<IN extends AnyObject>(props: {
|
|
@@ -632,7 +632,7 @@ export class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
|
632
632
|
});
|
|
633
633
|
}
|
|
634
634
|
minProperties(minProperties) {
|
|
635
|
-
return this.cloneAndUpdateSchema({ minProperties });
|
|
635
|
+
return this.cloneAndUpdateSchema({ minProperties, minProperties2: minProperties });
|
|
636
636
|
}
|
|
637
637
|
maxProperties(maxProperties) {
|
|
638
638
|
return this.cloneAndUpdateSchema({ maxProperties });
|
package/package.json
CHANGED
|
@@ -4,8 +4,7 @@ import type { TransformLogProgressOptions, TransformMapOptions } from '../index.
|
|
|
4
4
|
import { Pipeline } from '../pipeline.js'
|
|
5
5
|
|
|
6
6
|
export interface NDJSONMapOptions<IN = any, OUT = IN>
|
|
7
|
-
extends TransformMapOptions<IN, OUT>,
|
|
8
|
-
TransformLogProgressOptions<IN> {
|
|
7
|
+
extends TransformMapOptions<IN, OUT>, TransformLogProgressOptions<IN> {
|
|
9
8
|
inputFilePath: string
|
|
10
9
|
outputFilePath: string
|
|
11
10
|
|
|
@@ -4,8 +4,7 @@ import { progressLogger } from '../progressLogger.js'
|
|
|
4
4
|
import type { TransformOptions, TransformTyped } from '../stream.model.js'
|
|
5
5
|
|
|
6
6
|
export interface TransformLogProgressOptions<IN = any>
|
|
7
|
-
extends ProgressLoggerCfg<IN>,
|
|
8
|
-
TransformOptions {}
|
|
7
|
+
extends ProgressLoggerCfg<IN>, TransformOptions {}
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Pass-through transform that optionally logs progress.
|
|
@@ -478,6 +478,26 @@ export function createAjv(opt?: Options): Ajv2020 {
|
|
|
478
478
|
},
|
|
479
479
|
})
|
|
480
480
|
|
|
481
|
+
// This and `maxProperties2` are added because Ajv validates the `min/maxProperties` before validating the properties.
|
|
482
|
+
// So, in case of `minProperties(1)` and `{ foo: 'bar' }` Ajv will let it pass, even
|
|
483
|
+
// if the property validation would strip `foo` from the data.
|
|
484
|
+
// And Ajv would return `{}` as a successful validation.
|
|
485
|
+
// Since the keyword validation runs after JSON Schema validation,
|
|
486
|
+
// here we can make sure the number of properties are right ex-post property validation.
|
|
487
|
+
// It's named with the `2` suffix, because `minProperties` is reserved.
|
|
488
|
+
// And `maxProperties` does not suffer from this error due to the nature of how maximum works.
|
|
489
|
+
ajv.addKeyword({
|
|
490
|
+
keyword: 'minProperties2',
|
|
491
|
+
type: 'object',
|
|
492
|
+
modifying: false,
|
|
493
|
+
errors: true,
|
|
494
|
+
schemaType: 'number',
|
|
495
|
+
validate: function validate(minProperties: number, data: AnyObject, _schema, _ctx) {
|
|
496
|
+
if (typeof data !== 'object') return true
|
|
497
|
+
return Object.getOwnPropertyNames(data).length >= minProperties
|
|
498
|
+
},
|
|
499
|
+
})
|
|
500
|
+
|
|
481
501
|
return ajv
|
|
482
502
|
}
|
|
483
503
|
|
|
@@ -920,7 +920,7 @@ export class JsonSchemaObjectBuilder<
|
|
|
920
920
|
}
|
|
921
921
|
|
|
922
922
|
minProperties(minProperties: number): this {
|
|
923
|
-
return this.cloneAndUpdateSchema({ minProperties })
|
|
923
|
+
return this.cloneAndUpdateSchema({ minProperties, minProperties2: minProperties })
|
|
924
924
|
}
|
|
925
925
|
|
|
926
926
|
maxProperties(maxProperties: number): this {
|
|
@@ -1239,6 +1239,7 @@ export interface JsonSchema<IN = unknown, OUT = IN> {
|
|
|
1239
1239
|
errorMessages?: StringMap<string>
|
|
1240
1240
|
optionalValues?: (string | number | boolean)[]
|
|
1241
1241
|
keySchema?: JsonSchema
|
|
1242
|
+
minProperties2?: number
|
|
1242
1243
|
}
|
|
1243
1244
|
|
|
1244
1245
|
function object(props: AnyObject): never
|