-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f5e4c8
commit 097701a
Showing
6 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM node:22-alpine | ||
|
||
COPY . /app | ||
RUN npm ci --prefix /app | ||
ENTRYPOINT ["node", "--disable-warning=ExperimentalWarning", "/app/main.mjs"] | ||
CMD [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { registerSchema, validate } from "@hyperjump/json-schema/draft-07"; | ||
import fs from 'fs'; | ||
import readline from 'readline'; | ||
import { performance } from 'perf_hooks'; | ||
|
||
function readJSONFile(filePath) { | ||
try { | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
return JSON.parse(fileContent); | ||
} catch (error) { | ||
process.exit(1); | ||
} | ||
} | ||
|
||
async function* readJSONLines(filePath) { | ||
const rl = readline.createInterface({ | ||
input: fs.createReadStream(filePath), | ||
}); | ||
for await (const line of rl) { | ||
yield JSON.parse(line); | ||
} | ||
} | ||
|
||
async function validateSchema(schemaPath, instancePath) { | ||
const schema = readJSONFile(schemaPath); | ||
|
||
const schemaId = schema["$id"] || "https://example.com" + schemaPath; | ||
registerSchema(schema, schemaId); | ||
|
||
const instances = []; | ||
for await (const instance of readJSONLines(instancePath)) { | ||
instances.push(instance); | ||
} | ||
let failed = false; | ||
const startTime = performance.now(); | ||
for (const instance of instances) { | ||
const output = await validate(schemaId, instance); | ||
if (!output.valid) { | ||
failed = true; | ||
} | ||
} | ||
|
||
const endTime = performance.now(); | ||
|
||
const durationNs = (endTime - startTime) * 1e6; | ||
console.log(durationNs.toFixed(0)); | ||
|
||
// Exit with non-zero status on validation failure | ||
if (failed) { | ||
process.exit(1); | ||
} | ||
} | ||
|
||
if (process.argv.length !== 4) { | ||
process.exit(1); | ||
} | ||
|
||
const schemaPath = process.argv[2]; | ||
const instancePath = process.argv[3]; | ||
|
||
await validateSchema(schemaPath, instancePath); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "jsonschema-benchmark", | ||
"version": "1.0.0", | ||
"author": "Juan Cruz Viotti <[email protected]>", | ||
"dependencies": { | ||
"@hyperjump/json-schema": "^1.9.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
jq --raw-output '.packages["node_modules/ajv"].version' < implementations/ajv/package-lock.json |