@kubernetes-models/validate
Advanced tools
Comparing version 0.0.0-202145103037 to 0.0.0-202177121237
import Ajv from "ajv"; | ||
export declare const ajv: Ajv.Ajv; | ||
export declare const ajv: Ajv; | ||
export declare function register(id: string, schema: object): void; |
@@ -6,8 +6,18 @@ "use strict"; | ||
const ajv_1 = tslib_1.__importDefault(require("ajv")); | ||
const ajv_formats_1 = tslib_1.__importDefault(require("ajv-formats")); | ||
// From: https://github.com/miguelmota/is-base64/blob/0702e189090921a2f11b4342f27906ff8c43d7ec/is-base64.js#L15 | ||
const rBase64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/; | ||
// https://github.com/kubernetes/apimachinery/blob/8c18d83/pkg/api/resource/quantity.go | ||
const rSignedNumber = /[+-]?(?:\d+|\d+\.\d+|\d+\.|\.\d+)/; | ||
// https://physics.nist.gov/cuu/Units/binary.html | ||
const rBinarySI = /[KMGTPE]i/; | ||
// https://en.wikipedia.org/wiki/Metric_prefix#List_of_SI_prefixes | ||
const rDecimalSI = /(?:[YZEPTGMkhdcmunpfazy]|da)/; | ||
const rDecimalExponent = new RegExp(`[eE]${rSignedNumber.source}`); | ||
const rQuantitySuffix = new RegExp(`(?:${rBinarySI.source}|${rDecimalSI.source}|${rDecimalExponent.source})?`); | ||
const rQuantity = new RegExp(`^${rSignedNumber.source}${rQuantitySuffix.source}$`); | ||
exports.ajv = new ajv_1.default({ | ||
extendRefs: "fail", | ||
format: "full" | ||
strictTypes: false | ||
}); | ||
ajv_formats_1.default(exports.ajv); | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
@@ -20,41 +30,15 @@ function register(id, schema) { | ||
exports.register = register; | ||
function intFormat(bits) { | ||
const max = BigInt(2) ** BigInt(bits - 1) - BigInt(1); | ||
const min = BigInt(-2) ** BigInt(bits - 1); | ||
return { | ||
validate(input) { | ||
const n = BigInt(input); | ||
return n >= min && n <= max; | ||
}, | ||
compare(a, b) { | ||
const diff = BigInt(a) - BigInt(b); | ||
if (diff > 0) | ||
return 1; | ||
if (diff < 0) | ||
return -1; | ||
return 0; | ||
}, | ||
type: "number" | ||
}; | ||
} | ||
exports.ajv.addFormat("int32", intFormat(32)); | ||
exports.ajv.addFormat("int64", intFormat(64)); | ||
exports.ajv.addFormat("float", { | ||
type: "number", | ||
validate() { | ||
return true; | ||
} | ||
exports.ajv.addFormat("byte", { | ||
type: "string", | ||
validate: (value) => rBase64.test(value) | ||
}); | ||
exports.ajv.addFormat("double", { | ||
type: "number", | ||
validate() { | ||
return true; | ||
} | ||
exports.ajv.addFormat("quantity", { | ||
type: "string", | ||
validate: rQuantity | ||
}); | ||
exports.ajv.addFormat("byte", { | ||
// This format is used in Istio. | ||
exports.ajv.addFormat("string", { | ||
type: "string", | ||
validate(input) { | ||
return rBase64.test(input); | ||
} | ||
validate: (value) => typeof value === "string" | ||
}); | ||
//# sourceMappingURL=ajv.js.map |
{ | ||
"name": "@kubernetes-models/validate", | ||
"version": "0.0.0-202145103037", | ||
"version": "0.0.0-202177121237", | ||
"main": "dist/index.js", | ||
@@ -32,8 +32,9 @@ "module": "dist/index.mjs", | ||
"engines": { | ||
"node": ">=10.4.0" | ||
"node": ">=12" | ||
}, | ||
"dependencies": { | ||
"ajv": "^6.12.6", | ||
"tslib": "^2.0.3" | ||
"ajv": "^8.6.2", | ||
"ajv-formats": "^2.1.0", | ||
"tslib": "^2.3.0" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10573
3
17
115
+ Addedajv-formats@^2.1.0
+ Addedajv@8.17.1(transitive)
+ Addedajv-formats@2.1.1(transitive)
+ Addedfast-uri@3.0.6(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
- Removedajv@6.12.6(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removeduri-js@4.4.1(transitive)
Updatedajv@^8.6.2
Updatedtslib@^2.3.0