Sample
ajv-keywords 5.1.0
Verified sample for npm ajv-keywords 5.1.0. The contract ran on node 22 · linux alpine/x64 · docker and passed: assert ajvKeywords default export registers…
sha256:09894d715b42a507cdc1d8ca4242f317cc83c763fd19348fbd5c6411d75e9209
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 npm
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-27 |
Case
HOW- Goal
- verify pkg:npm/ajv-keywords@5.1.0
- Packages
- Created
- 2026-08-27T23:40:05Z
Contract
- assert ajvKeywords default export registers all keywords on ajv instance when called with no keyword arguments
- assert ajvKeywords registers single keyword or array of keywords on ajv instance and returns the instance
- assert ajvKeywords.get returns keyword plugin function for valid keyword and throws Error for unknown keyword
- assert range and exclusiveRange macros generate numeric minimum and maximum schema constraints
- assert prohibited, allRequired, anyRequired, and oneRequired macros generate schema required constraints
Files
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:npm/ajv-keywords@5.1.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ajv-keywords@5.1.0
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:d2be9cf5bd05276e052f140753144a32c3f4b152b95f66911b806faacedeb944","contract":["assert ajvKeywords default export registers all keywords on ajv instance when called with no keyword arguments","assert ajvKeywords registers single keyword or array of keywords on ajv instance and returns the instance","assert ajvKeywords.get returns keyword plugin function for valid keyword and throws Error for unknown keyword","assert range and exclusiveRange macros generate numeric minimum and maximum schema constraints","assert prohibited, allRequired, anyRequired, and oneRequired macros generate schema required constraints"],"goal":"verify pkg:npm/ajv-keywords@5.1.0","kind":"HOW","packages":["pkg:npm/ajv-keywords@5.1.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/ajv-keywords@5.1.0"],"schemaVersion":1,"subject":"pkg:npm/ajv-keywords@5.1.0","verifierAdapter":"node-typescript@1"}
{
"name": "sample-ajv-keywords",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ajv-keywords",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ajv-keywords": "5.1.0"
}
},
"node_modules/ajv": {
"version": "8.20.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",
"integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==",
"license": "MIT",
"peer": true,
"dependencies": {
"fast-deep-equal": "^3.1.3",
"fast-uri": "^3.0.1",
"json-schema-traverse": "^1.0.0",
"require-from-string": "^2.0.2"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/epoberezkin"
}
},
"node_modules/ajv-keywords": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-5.1.0.tgz",
"integrity": "sha512-YCS/JNFAUyr5vAuhk1DWm1CBxRHW9LbJ2ozWeemrIqpbsqKjHVxYPyi5GC0rjZIT5JxJ3virVTS8wk4i/Z+krw==",
"license": "MIT",
"dependencies": {
"fast-deep-equal": "^3.1.3"
},
"peerDependencies": {
"ajv": "^8.8.2"
}
},
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
"license": "MIT"
},
"node_modules/fast-uri": {
"version": "3.1.6",
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.6.tgz",
"integrity": "sha512-7Ical1vFEMr0onbVzEDIreM22I4khW+fzyQPwvAFWBp1iwdshSZRsL4jjRvPG9JP1uiqMHRto+YU6R2/CzDz5Q==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fastify"
},
{
"type": "opencollective",
"url": "https://opencollective.com/fastify"
}
],
"license": "BSD-3-Clause",
"peer": true
},
"node_modules/json-schema-traverse": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
"license": "MIT",
"peer": true
},
"node_modules/require-from-string": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=0.10.0"
}
}
}
}
{
"name": "sample-ajv-keywords",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"dependencies": {
"ajv-keywords": "5.1.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/ajv-keywords@5.1.0",
"kind": "HOW",
"packages": [
"pkg:npm/ajv-keywords@5.1.0"
]
}
import ajvKeywords from "ajv-keywords";
import rangeDef from "ajv-keywords/dist/definitions/range.js";
import exclusiveRangeDef from "ajv-keywords/dist/definitions/exclusiveRange.js";
import prohibitedDef from "ajv-keywords/dist/definitions/prohibited.js";
import allRequiredDef from "ajv-keywords/dist/definitions/allRequired.js";
import anyRequiredDef from "ajv-keywords/dist/definitions/anyRequired.js";
import oneRequiredDef from "ajv-keywords/dist/definitions/oneRequired.js";
const getAjvKeywords = () => ajvKeywords.default || ajvKeywords;
/**
* Registers one, multiple, or all custom keywords onto an Ajv-compatible instance.
* @param {object} ajv - Ajv instance or compatible object with addKeyword method.
* @param {string|string[]} [keywords] - Keyword or array of keywords to register.
* @returns {object} The ajv instance.
*/
export function registerKeywords(ajv, keywords) {
const fn = getAjvKeywords();
return fn(ajv, keywords);
}
/**
* Retrieves the keyword plugin definition function for a specific keyword name.
* @param {string} keywordName - Name of the keyword.
* @returns {Function} Keyword plugin definition function.
*/
export function getKeywordPlugin(keywordName) {
const fn = getAjvKeywords();
return fn.get(keywordName);
}
/**
* Generates expanded range schema using range definition macro.
* @param {number} min - Minimum value.
* @param {number} max - Maximum value.
* @returns {object} Schema constraint object with minimum and maximum.
*/
export function expandRangeSchema(min, max) {
const factory = rangeDef.default || rangeDef;
const def = factory();
return def.macro([min, max]);
}
/**
* Generates expanded exclusive range schema using exclusiveRange definition macro.
* @param {number} min - Exclusive minimum value.
* @param {number} max - Exclusive maximum value.
* @returns {object} Schema constraint object with exclusiveMinimum and exclusiveMaximum.
*/
export function expandExclusiveRangeSchema(min, max) {
const factory = exclusiveRangeDef.default || exclusiveRangeDef;
const def = factory();
return def.macro([min, max]);
}
/**
* Generates expanded prohibited schema using prohibited definition macro.
* @param {string[]} properties - Prohibited property names.
* @returns {object} Schema constraint object with not and anyOf required clauses.
*/
export function expandProhibitedSchema(properties) {
const factory = prohibitedDef.default || prohibitedDef;
const def = factory();
return def.macro(properties);
}
/**
* Generates expanded allRequired schema using allRequired definition macro.
* @param {object} parentSchema - Schema containing properties object.
* @returns {object} Schema constraint object with required list of all property keys.
*/
export function expandAllRequiredSchema(parentSchema) {
const factory = allRequiredDef.default || allRequiredDef;
const def = factory();
return def.macro(true, parentSchema);
}
/**
* Generates expanded anyRequired schema using anyRequired definition macro.
* @param {string[]} properties - Candidate property names where at least one is required.
* @returns {object} Schema constraint object with anyOf required clauses.
*/
export function expandAnyRequiredSchema(properties) {
const factory = anyRequiredDef.default || anyRequiredDef;
const def = factory();
return def.macro(properties);
}
/**
* Generates expanded oneRequired schema using oneRequired definition macro.
* @param {string[]} properties - Candidate property names where exactly one is required.
* @returns {object} Schema constraint object with oneOf required clauses.
*/
export function expandOneRequiredSchema(properties) {
const factory = oneRequiredDef.default || oneRequiredDef;
const def = factory();
return def.macro(properties);
}
export default {
registerKeywords,
getKeywordPlugin,
expandRangeSchema,
expandExclusiveRangeSchema,
expandProhibitedSchema,
expandAllRequiredSchema,
expandAnyRequiredSchema,
expandOneRequiredSchema
};
import assert from "node:assert/strict";
import ajvKeywords from "ajv-keywords";
import {
registerKeywords,
getKeywordPlugin,
expandRangeSchema,
expandExclusiveRangeSchema,
expandProhibitedSchema,
expandAllRequiredSchema,
expandAnyRequiredSchema,
expandOneRequiredSchema
} from "../src/index.mjs";
// Helper function to create mock Ajv instance
function createMockAjv() {
const registered = [];
return {
registered,
addKeyword(def) {
registered.push(def);
return this;
}
};
}
// 1. assert ajvKeywords default export registers all keywords on ajv instance when called with no keyword arguments
{
const mockAjv = createMockAjv();
const returned = registerKeywords(mockAjv);
assert.strictEqual(returned, mockAjv, "registerKeywords must return the ajv instance");
const keywordNames = mockAjv.registered.map((def) => (typeof def === "string" ? def : def.keyword));
assert.ok(mockAjv.registered.length >= 16, "All default keywords must be registered");
assert.ok(keywordNames.includes("typeof"), "Must register typeof");
assert.ok(keywordNames.includes("instanceof"), "Must register instanceof");
assert.ok(keywordNames.includes("range"), "Must register range");
assert.ok(keywordNames.includes("exclusiveRange"), "Must register exclusiveRange");
assert.ok(keywordNames.includes("transform"), "Must register transform");
assert.ok(keywordNames.includes("uniqueItemProperties"), "Must register uniqueItemProperties");
assert.ok(keywordNames.includes("allRequired"), "Must register allRequired");
assert.ok(keywordNames.includes("anyRequired"), "Must register anyRequired");
assert.ok(keywordNames.includes("oneRequired"), "Must register oneRequired");
assert.ok(keywordNames.includes("patternRequired"), "Must register patternRequired");
assert.ok(keywordNames.includes("prohibited"), "Must register prohibited");
assert.ok(keywordNames.includes("deepProperties"), "Must register deepProperties");
assert.ok(keywordNames.includes("deepRequired"), "Must register deepRequired");
assert.ok(keywordNames.includes("dynamicDefaults"), "Must register dynamicDefaults");
}
// 2. assert ajvKeywords registers single keyword or array of keywords on ajv instance and returns the instance
{
const mockAjvSingle = createMockAjv();
const resSingle = registerKeywords(mockAjvSingle, "typeof");
assert.strictEqual(resSingle, mockAjvSingle);
assert.strictEqual(mockAjvSingle.registered.length, 1);
assert.strictEqual(mockAjvSingle.registered[0].keyword, "typeof");
const mockAjvMulti = createMockAjv();
const resMulti = registerKeywords(mockAjvMulti, ["range", "exclusiveRange", "prohibited"]);
assert.strictEqual(resMulti, mockAjvMulti);
assert.strictEqual(mockAjvMulti.registered.length, 3);
const registeredNames = mockAjvMulti.registered.map((d) => d.keyword);
assert.deepStrictEqual(registeredNames, ["range", "exclusiveRange", "prohibited"]);
}
// 3. assert ajvKeywords.get returns keyword plugin function for valid keyword and throws Error for unknown keyword
{
const typeofPlugin = getKeywordPlugin("typeof");
assert.strictEqual(typeof typeofPlugin, "function", "Keyword plugin must be a function");
const mockAjv = createMockAjv();
typeofPlugin(mockAjv);
assert.strictEqual(mockAjv.registered.length, 1);
const def = mockAjv.registered[0];
assert.strictEqual(def.keyword, "typeof");
assert.deepStrictEqual(def.schemaType, ["string", "array"]);
assert.strictEqual(typeof def.code, "function");
assert.throws(
() => getKeywordPlugin("unknownKeyword"),
(err) => err instanceof Error && /Unknown keyword unknownKeyword/.test(err.message),
"getKeywordPlugin must throw Error for unknown keyword"
);
}
// 4. assert range and exclusiveRange macros generate numeric minimum and maximum schema constraints
{
const rangeResult = expandRangeSchema(10, 50);
assert.deepStrictEqual(rangeResult, {
minimum: 10,
maximum: 50
});
const exclusiveRangeResult = expandExclusiveRangeSchema(5, 25);
assert.deepStrictEqual(exclusiveRangeResult, {
exclusiveMinimum: 5,
exclusiveMaximum: 25
});
}
// 5. assert prohibited, allRequired, anyRequired, and oneRequired macros generate schema required constraints
{
const prohibitedResult = expandProhibitedSchema(["secretKey", "accessToken"]);
assert.deepStrictEqual(prohibitedResult, {
not: {
anyOf: [
{ required: ["secretKey"] },
{ required: ["accessToken"] }
]
}
});
const allRequiredResult = expandAllRequiredSchema({
properties: {
id: { type: "integer" },
name: { type: "string" },
status: { type: "string" }
}
});
assert.deepStrictEqual(allRequiredResult, {
required: ["id", "name", "status"]
});
const anyRequiredResult = expandAnyRequiredSchema(["email", "phone"]);
assert.deepStrictEqual(anyRequiredResult, {
anyOf: [
{ required: ["email"] },
{ required: ["phone"] }
]
});
const oneRequiredResult = expandOneRequiredSchema(["creditCard", "bankTransfer"]);
assert.deepStrictEqual(oneRequiredResult, {
oneOf: [
{ required: ["creditCard"] },
{ required: ["bankTransfer"] }
]
});
}
console.log("All ajv-keywords contract tests passed successfully.");
Origin Seeder
anonymous