🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@pocketlantern/schema

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pocketlantern/schema - npm Package Compare versions

Comparing version
0.1.1
to
0.1.2
+40
-30
dist/__tests__/json-schema.test.js
import { describe, it, expect } from "vitest";
import { CardSchema, CandidateSchema } from "../card.js";
import { cardJsonSchema, candidateJsonSchema } from "../json-schema.js";
describe("cardJsonSchema", () => {
it("is a valid JSON Schema object with type and properties", () => {
const schema = cardJsonSchema;
const def = schema["$defs"]?.["Card"] ?? schema;
const defObj = def;
expect(defObj).toHaveProperty("type");
expect(defObj).toHaveProperty("properties");
function resolveSchema(raw) {
const schema = raw;
const def = schema["$defs"]?.["Card"] ?? schema;
return def;
}
describe("cardJsonSchema ↔ CardSchema sync", () => {
const jsonSchema = resolveSchema(cardJsonSchema);
const zodShape = CardSchema.shape;
it("JSON Schema properties match Zod schema fields exactly", () => {
const jsonProps = Object.keys(jsonSchema.properties).sort();
const zodFields = Object.keys(zodShape).sort();
expect(jsonProps).toEqual(zodFields);
});
it("properties include all required card fields", () => {
const schema = cardJsonSchema;
const def = schema["$defs"]?.["Card"] ?? schema;
const properties = def["properties"];
const requiredFields = ["id", "title", "problem", "candidates", "tags", "updated"];
for (const field of requiredFields) {
expect(properties).toHaveProperty(field);
}
it("JSON Schema required fields match Zod non-optional fields", () => {
const jsonRequired = (jsonSchema.required ?? []).sort();
const zodRequired = Object.entries(zodShape)
.filter(([, v]) => !v.isOptional?.())
.map(([k]) => k)
.sort();
expect(jsonRequired).toEqual(zodRequired);
});
it("id field preserves regex pattern from Zod", () => {
const idProp = jsonSchema.properties.id;
expect(idProp.pattern).toBeDefined();
expect(new RegExp(idProp.pattern).test("auth/jwt-vs-session")).toBe(true);
expect(new RegExp(idProp.pattern).test("BAD")).toBe(false);
});
});
describe("candidateJsonSchema", () => {
it("is a valid JSON Schema object with type and properties", () => {
const schema = candidateJsonSchema;
const def = schema["$defs"]?.["Candidate"] ?? schema;
const defObj = def;
expect(defObj).toHaveProperty("type");
expect(defObj).toHaveProperty("properties");
describe("candidateJsonSchema ↔ CandidateSchema sync", () => {
const jsonSchema = resolveSchema(candidateJsonSchema);
const zodShape = CandidateSchema.shape;
it("JSON Schema properties match Zod schema fields exactly", () => {
const jsonProps = Object.keys(jsonSchema.properties).sort();
const zodFields = Object.keys(zodShape).sort();
expect(jsonProps).toEqual(zodFields);
});
it("properties include all required candidate fields", () => {
const schema = candidateJsonSchema;
const def = schema["$defs"]?.["Candidate"] ?? schema;
const properties = def["properties"];
const requiredFields = ["name", "summary", "when_to_use", "tradeoffs", "cautions"];
for (const field of requiredFields) {
expect(properties).toHaveProperty(field);
}
it("JSON Schema required fields match Zod non-optional fields", () => {
const jsonRequired = (jsonSchema.required ?? []).sort();
const zodRequired = Object.entries(zodShape)
.filter(([, v]) => !v.isOptional?.())
.map(([k]) => k)
.sort();
expect(jsonRequired).toEqual(zodRequired);
});
});
//# sourceMappingURL=json-schema.test.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"json-schema.test.js","sourceRoot":"","sources":["../../src/__tests__/json-schema.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExE,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,MAAM,GAAG,cAAyC,CAAC;QACzD,MAAM,GAAG,GAAI,MAAM,CAAC,OAAO,CAA6B,EAAE,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC;QAE7E,MAAM,MAAM,GAAG,GAA8B,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAA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AG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QAC/C,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACnE,MAAM,YAAY,GAAG,CAAC,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACxD,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;aACzC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAoC,CAAC,UAAU,EAAE,EAAE,CAAC;aACxE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;aACf,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
{
"name": "@pocketlantern/schema",
"version": "0.1.1",
"version": "0.1.2",
"type": "module",

@@ -5,0 +5,0 @@ "description": "Card schema definitions for PocketLantern (zod + TypeScript)",

export {};
//# sourceMappingURL=index.test.d.ts.map
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/index.test.ts"],"names":[],"mappings":""}
import { describe, it, expect } from "vitest";
import * as schema from "../index.js";
describe("index exports", () => {
it.each([
"CardSchema",
"CandidateSchema",
"ConstraintSchema",
"CardStatusSchema",
"CardSummarySchema",
"cardJsonSchema",
"candidateJsonSchema",
])("exports %s", (name) => {
expect(schema).toHaveProperty(name);
expect(schema[name]).toBeDefined();
});
});
//# sourceMappingURL=index.test.js.map
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/__tests__/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,IAAI,CAAC;QACN,YAAY;QACZ,iBAAiB;QACjB,kBAAkB;QAClB,kBAAkB;QAClB,mBAAmB;QACnB,gBAAgB;QAChB,qBAAqB;KACtB,CAAC,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;QACxB,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAE,MAAkC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}