+1
-1
| { | ||
| "name": "ajv-cmd", | ||
| "version": "0.10.0", | ||
| "version": "0.10.1", | ||
| "description": "Deref, Validate, Transpile, and Test JSON-Schema (.json) files using ajv", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+41
-1
@@ -51,2 +51,28 @@ "use strict"; | ||
| }; | ||
| const draft2019Formats = /* @__PURE__ */ new Set([ | ||
| "iri", | ||
| "idn-email", | ||
| "idn-hostname", | ||
| "iri-reference" | ||
| ]); | ||
| const bridgeModuleName = "formats-draft2019-bridge"; | ||
| const bridgeModuleContent = ` | ||
| const Ajv = require("ajv/dist/2020.js").default; | ||
| const ajvFormatsDraft2019 = require("@silverbucket/ajv-formats-draft2019").default; | ||
| const ajv = new Ajv(); | ||
| ajvFormatsDraft2019(ajv); | ||
| exports.fullFormats = ajv.formats; | ||
| `; | ||
| const fixDraft2019FormatRequires = (code) => { | ||
| return code.replaceAll( | ||
| /require\("ajv-formats\/dist\/formats"\)\.fullFormats(?:\.(\w+)|\["([^"]+)"\])/g, | ||
| (match, dotName, bracketName) => { | ||
| const formatName = dotName ?? bracketName; | ||
| if (draft2019Formats.has(formatName)) { | ||
| return `require("./${bridgeModuleName}.cjs").fullFormats["${formatName}"]`; | ||
| } | ||
| return match; | ||
| } | ||
| ); | ||
| }; | ||
| const transpile = async (schema, options = {}) => { | ||
@@ -57,3 +83,17 @@ options = { ...defaultOptions, ...options }; | ||
| let js = (0, import_standalone.default)(ajv, validate); | ||
| const needsBridge = draft2019Formats.intersection( | ||
| new Set( | ||
| js.match(/fullFormats(?:\.(\w+)|\["([^"]+)"\])/g)?.map( | ||
| (m) => m.replace(/fullFormats[.[]"?/, "").replace(/"?\]$/, "") | ||
| ) ?? [] | ||
| ) | ||
| ).size > 0; | ||
| js = fixDraft2019FormatRequires(js); | ||
| const file = (0, import_node_path.join)(__dirname, `${(0, import_node_crypto.randomBytes)(16).toString("hex")}.js`); | ||
| const bridgeFile = (0, import_node_path.join)(__dirname, `${bridgeModuleName}.cjs`); | ||
| const cleanupFiles = [file]; | ||
| if (needsBridge) { | ||
| await (0, import_promises.writeFile)(bridgeFile, bridgeModuleContent, "utf8"); | ||
| cleanupFiles.push(bridgeFile); | ||
| } | ||
| await (0, import_promises.writeFile)(file, js, "utf8"); | ||
@@ -71,3 +111,3 @@ await (0, import_esbuild.build)({ | ||
| js = await (0, import_promises.readFile)(file, { encoding: "utf8" }); | ||
| await (0, import_promises.unlink)(file); | ||
| await Promise.all(cleanupFiles.map((f) => (0, import_promises.unlink)(f))); | ||
| return js; | ||
@@ -74,0 +114,0 @@ }; |
+53
-1
@@ -21,2 +21,34 @@ // Copyright 2026 will Farrell, and ajv-cmd contributors. | ||
| // Formats from @silverbucket/ajv-formats-draft2019 that AJV standalone | ||
| // incorrectly references via ajv-formats/dist/formats | ||
| const draft2019Formats = new Set([ | ||
| "iri", | ||
| "idn-email", | ||
| "idn-hostname", | ||
| "iri-reference", | ||
| ]); | ||
| const bridgeModuleName = "formats-draft2019-bridge"; | ||
| const bridgeModuleContent = ` | ||
| const Ajv = require("ajv/dist/2020.js").default; | ||
| const ajvFormatsDraft2019 = require("@silverbucket/ajv-formats-draft2019").default; | ||
| const ajv = new Ajv(); | ||
| ajvFormatsDraft2019(ajv); | ||
| exports.fullFormats = ajv.formats; | ||
| `; | ||
| const fixDraft2019FormatRequires = (code) => { | ||
| return code.replaceAll( | ||
| /require\("ajv-formats\/dist\/formats"\)\.fullFormats(?:\.(\w+)|\["([^"]+)"\])/g, | ||
| (match, dotName, bracketName) => { | ||
| const formatName = dotName ?? bracketName; | ||
| if (draft2019Formats.has(formatName)) { | ||
| return `require("./${bridgeModuleName}.cjs").fullFormats["${formatName}"]`; | ||
| } | ||
| return match; | ||
| }, | ||
| ); | ||
| }; | ||
| export const transpile = async (schema, options = {}) => { | ||
@@ -28,4 +60,24 @@ options = { ...defaultOptions, ...options }; | ||
| let js = standaloneCode(ajv, validate); | ||
| const needsBridge = | ||
| draft2019Formats.intersection( | ||
| new Set( | ||
| js | ||
| .match(/fullFormats(?:\.(\w+)|\["([^"]+)"\])/g) | ||
| ?.map((m) => | ||
| m.replace(/fullFormats[.[]"?/, "").replace(/"?\]$/, ""), | ||
| ) ?? [], | ||
| ), | ||
| ).size > 0; | ||
| js = fixDraft2019FormatRequires(js); | ||
| const file = join(__dirname, `${randomBytes(16).toString("hex")}.js`); | ||
| const bridgeFile = join(__dirname, `${bridgeModuleName}.cjs`); | ||
| const cleanupFiles = [file]; | ||
| if (needsBridge) { | ||
| await writeFile(bridgeFile, bridgeModuleContent, "utf8"); | ||
| cleanupFiles.push(bridgeFile); | ||
| } | ||
| await writeFile(file, js, "utf8"); | ||
@@ -45,3 +97,3 @@ | ||
| js = await readFile(file, { encoding: "utf8" }); | ||
| await unlink(file); | ||
| await Promise.all(cleanupFiles.map((f) => unlink(f))); | ||
@@ -48,0 +100,0 @@ return js; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
113700
2.58%3218
2.71%