From 097701afbc7988897d171d368e1c543451a6b0b7 Mon Sep 17 00:00:00 2001 From: Michael Mior Date: Tue, 1 Oct 2024 20:17:05 -0400 Subject: [PATCH] Add hyperjump implementation (#52) --- Makefile | 18 +++ implementations/hyperjump/Dockerfile | 6 + implementations/hyperjump/main.mjs | 61 ++++++++++ implementations/hyperjump/package-lock.json | 127 ++++++++++++++++++++ implementations/hyperjump/package.json | 8 ++ implementations/hyperjump/version.sh | 6 + 6 files changed, 226 insertions(+) create mode 100644 implementations/hyperjump/Dockerfile create mode 100644 implementations/hyperjump/main.mjs create mode 100644 implementations/hyperjump/package-lock.json create mode 100644 implementations/hyperjump/package.json create mode 100755 implementations/hyperjump/version.sh diff --git a/Makefile b/Makefile index ed8ceaa..94a7b40 100644 --- a/Makefile +++ b/Makefile @@ -134,3 +134,21 @@ dist/results/go-jsonschema/%: \ schemas/%/instances.jsonl \ | dist/results/go-jsonschema @$(call docker_run,go-jsonschema,/workspace/$(dir $(word 2,$^))) + +# HYPERJUMP + +implementations/hyperjump/.dockertimestamp: \ + implementations/hyperjump/main.mjs \ + implementations/hyperjump/package.json \ + implementations/hyperjump/package-lock.json \ + implementations/hyperjump/Dockerfile + docker build -t jsonschema-benchmark/hyperjump implementations/hyperjump + touch $@ + +dist/results/hyperjump/%: \ + implementations/hyperjump/.dockertimestamp \ + schemas/%/schema.json \ + schemas/%/instances.jsonl \ + | dist/results/hyperjump + @$(call docker_run,hyperjump,/workspace/$(word 2,$^) /workspace/$(word 3,$^)) + diff --git a/implementations/hyperjump/Dockerfile b/implementations/hyperjump/Dockerfile new file mode 100644 index 0000000..5381e31 --- /dev/null +++ b/implementations/hyperjump/Dockerfile @@ -0,0 +1,6 @@ +FROM node:22-alpine + +COPY . /app +RUN npm ci --prefix /app +ENTRYPOINT ["node", "--disable-warning=ExperimentalWarning", "/app/main.mjs"] +CMD [] diff --git a/implementations/hyperjump/main.mjs b/implementations/hyperjump/main.mjs new file mode 100644 index 0000000..3055e98 --- /dev/null +++ b/implementations/hyperjump/main.mjs @@ -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); diff --git a/implementations/hyperjump/package-lock.json b/implementations/hyperjump/package-lock.json new file mode 100644 index 0000000..3ecad35 --- /dev/null +++ b/implementations/hyperjump/package-lock.json @@ -0,0 +1,127 @@ +{ + "name": "jsonschema-benchmark", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "jsonschema-benchmark", + "version": "1.0.0", + "dependencies": { + "@hyperjump/json-schema": "^1.9.8" + } + }, + "node_modules/@hyperjump/browser": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@hyperjump/browser/-/browser-1.1.6.tgz", + "integrity": "sha512-i27uPV7SxK1GOn7TLTRxTorxchYa5ur9JHgtl6TxZ1MHuyb9ROAnXxEeu4q4H1836Xb7lL2PGPsaa5Jl3p+R6g==", + "license": "MIT", + "peer": true, + "dependencies": { + "@hyperjump/json-pointer": "^1.1.0", + "@hyperjump/uri": "^1.2.0", + "content-type": "^1.0.5", + "just-curry-it": "^5.3.0" + }, + "engines": { + "node": ">=18.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jdesrosiers" + } + }, + "node_modules/@hyperjump/json-pointer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@hyperjump/json-pointer/-/json-pointer-1.1.0.tgz", + "integrity": "sha512-tFCKxMKDKK3VEdtUA3EBOS9GmSOS4mbrTjh9v3RnK10BphDMOb6+bxTh++/ae1AyfHyWb6R54O/iaoAtPMZPCg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jdesrosiers" + } + }, + "node_modules/@hyperjump/json-schema": { + "version": "1.9.8", + "resolved": "https://registry.npmjs.org/@hyperjump/json-schema/-/json-schema-1.9.8.tgz", + "integrity": "sha512-qmdMpYn8CpYR7z3fxkL6fgkDvMaAEFKtmYu3XDi6hWW2BT+rLl7T4Y4QpafEIR4wkcmCxcJf9me9FmxKpv3i9g==", + "license": "MIT", + "dependencies": { + "@hyperjump/json-pointer": "^1.1.0", + "@hyperjump/pact": "^1.2.0", + "@hyperjump/uri": "^1.2.0", + "content-type": "^1.0.4", + "json-stringify-deterministic": "^1.0.12", + "just-curry-it": "^5.3.0", + "uuid": "^9.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jdesrosiers" + }, + "peerDependencies": { + "@hyperjump/browser": "^1.1.0" + } + }, + "node_modules/@hyperjump/pact": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@hyperjump/pact/-/pact-1.3.0.tgz", + "integrity": "sha512-/UIKatOtyZ3kN4A7AQmqZKzg/6es9jKyeWbfrenb2rDb3I9W4ZrVZT8q1zDrI/G+849I6Eq0ybzV1mmEC9zoDg==", + "license": "MIT", + "dependencies": { + "just-curry-it": "^5.3.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jdesrosiers" + } + }, + "node_modules/@hyperjump/uri": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@hyperjump/uri/-/uri-1.2.2.tgz", + "integrity": "sha512-Zn8AZb/j54KKUCckmcOzKCSCKpIpMVBc60zYaajD8Dq/1g4UN6TfAFi+uDa5o/6rf+I+5xDZjZpdzwfuhlC0xQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jdesrosiers" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/json-stringify-deterministic": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/json-stringify-deterministic/-/json-stringify-deterministic-1.0.12.tgz", + "integrity": "sha512-q3PN0lbUdv0pmurkBNdJH3pfFvOTL/Zp0lquqpvcjfKzt6Y0j49EPHAmVHCAS4Ceq/Y+PejWTzyiVpoY71+D6g==", + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/just-curry-it": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/just-curry-it/-/just-curry-it-5.3.0.tgz", + "integrity": "sha512-silMIRiFjUWlfaDhkgSzpuAyQ6EX/o09Eu8ZBfmFwQMbax7+LQzeIU2CBrICT6Ne4l86ITCGvUCBpCubWYy0Yw==", + "license": "MIT" + }, + "node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + } + } +} diff --git a/implementations/hyperjump/package.json b/implementations/hyperjump/package.json new file mode 100644 index 0000000..07d6059 --- /dev/null +++ b/implementations/hyperjump/package.json @@ -0,0 +1,8 @@ +{ + "name": "jsonschema-benchmark", + "version": "1.0.0", + "author": "Juan Cruz Viotti ", + "dependencies": { + "@hyperjump/json-schema": "^1.9.8" + } +} diff --git a/implementations/hyperjump/version.sh b/implementations/hyperjump/version.sh new file mode 100755 index 0000000..62e901d --- /dev/null +++ b/implementations/hyperjump/version.sh @@ -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