Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

schematized

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

schematized - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

dist/schema-node.d.ts

2

dist/builder.d.ts

@@ -6,3 +6,3 @@ export declare class SchemaBuilder {

addObject(object: Record<string, unknown>): void;
addSchema(schema: any): void;
addSchema(schema: Record<string, any>): void;
toSchema(): any;

@@ -9,0 +9,0 @@ toJson(): string;

@@ -7,3 +7,3 @@ "use strict";

exports.SchemaBuilder = void 0;
const node_1 = require("./node");
const schema_node_1 = require("./schema-node");
const lodash_1 = __importDefault(require("lodash"));

@@ -14,3 +14,3 @@ const DEFAULT_URI = 'http://json-schema.org/schema#';

this.schemaUri = schemaUri;
this.rootNode = new node_1.SchemaNode();
this.rootNode = new schema_node_1.SchemaNode();
}

@@ -28,3 +28,3 @@ addObject(object) {

}
else if (schema instanceof node_1.SchemaNode) {
else if (schema instanceof schema_node_1.SchemaNode) {
schema = schema.toSchema();

@@ -31,0 +31,0 @@ }

@@ -0,11 +1,12 @@

import { SchemaNode } from '../schema-node';
import { SchemaStrategy } from './base';
export declare class Array extends SchemaStrategy {
export declare class ArrayStrategy extends SchemaStrategy {
keywords: Set<string>;
items: any;
constructor();
items: SchemaNode;
constructor(schemaNode: any);
matchObject(object: any): boolean;
matchSchema(schema: any): boolean;
addSchema(schema: any): void;
addObject(object: any): void;
addObject(array: any[]): void;
toSchema(): any;
}

@@ -6,11 +6,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Array = void 0;
const node_1 = require("../node");
exports.ArrayStrategy = void 0;
const schema_node_1 = require("../schema-node");
const base_1 = require("./base");
const lodash_1 = __importDefault(require("lodash"));
class Array extends base_1.SchemaStrategy {
constructor() {
super();
class ArrayStrategy extends base_1.SchemaStrategy {
constructor(schemaNode) {
super(schemaNode);
this.keywords = new Set(['type', 'items']);
this.items = new node_1.SchemaNode();
this.items = new schema_node_1.SchemaNode();
}

@@ -30,4 +30,4 @@ matchObject(object) {

}
addObject(object) {
for (const item of object) {
addObject(array) {
for (const item of array) {
this.items.addObject(item);

@@ -40,3 +40,9 @@ }

if (this.items) {
schema.items = this.items.toSchema();
const items = this.items.toSchema();
if (items?.anyOf && Array.isArray(items.anyOf)) {
console.log(items.anyOf);
items.anyOf = lodash_1.default.uniqWith(items.anyOf, lodash_1.default.isEqual);
console.log(items.anyOf);
}
schema.items = items;
}

@@ -46,3 +52,3 @@ return schema;

}
exports.Array = Array;
exports.ArrayStrategy = ArrayStrategy;
//# sourceMappingURL=array.js.map

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

import { SchemaNode } from '../node';
export declare abstract class SchemaStrategy extends Object {
import { SchemaNode } from '../schema-node';
export declare abstract class SchemaStrategy {
keywords: Set<string>;

@@ -7,7 +7,7 @@ nodeClass: SchemaNode;

type: string;
constructor();
addSchema(schema: any): void;
constructor(schemaNode: any);
addSchema(schema: Record<string, unknown>): void;
addObject(_object: any): void;
addExtraKeywords(schema: any): void;
matchSchema(_schema: any): void;
matchSchema(_schema: Record<string, unknown>): void;
matchObject(_object: any): void;

@@ -17,4 +17,4 @@ toSchema(): any;

export declare abstract class TypedSchemaStrategy extends SchemaStrategy {
matchSchema(schema: any): boolean;
matchSchema(schema: Record<string, unknown>): boolean;
toSchema(): any;
}

@@ -7,9 +7,7 @@ "use strict";

exports.TypedSchemaStrategy = exports.SchemaStrategy = void 0;
const node_1 = require("../node");
const lodash_1 = __importDefault(require("lodash"));
class SchemaStrategy extends Object {
constructor() {
super();
class SchemaStrategy {
constructor(schemaNode) {
this.keywords = new Set(['type']);
this.nodeClass = new node_1.SchemaNode();
this.nodeClass = schemaNode;
this.extraKeywords = {};

@@ -16,0 +14,0 @@ }

import { Boolean } from './scalar';
import { MaxNumber, MinNumber } from './number';
import { ObjectStrategy as Object } from './object';
export declare const BASIC_SCHEMA_STRATEGIES: (typeof Boolean)[];
export declare const OPTIONAL_SCHEMA_STRATEGIES: (typeof MaxNumber | typeof MinNumber)[];
export * from './scalar';
export * from './array';
export { Object };
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Object = exports.OPTIONAL_SCHEMA_STRATEGIES = exports.BASIC_SCHEMA_STRATEGIES = void 0;
exports.BASIC_SCHEMA_STRATEGIES = void 0;
const scalar_1 = require("./scalar");
const array_1 = require("./array");
const number_1 = require("./number");
const array_1 = require("./array");
const object_1 = require("./object");
Object.defineProperty(exports, "Object", { enumerable: true, get: function () { return object_1.ObjectStrategy; } });
const string_1 = require("./string");
exports.BASIC_SCHEMA_STRATEGIES = [

@@ -24,9 +14,6 @@ scalar_1.Boolean,

scalar_1.Integer,
scalar_1.String,
array_1.Array,
object_1.ObjectStrategy,
string_1.StringStrategy,
array_1.ArrayStrategy,
object_1.ObjectStrategy
];
exports.OPTIONAL_SCHEMA_STRATEGIES = [number_1.MinNumber, number_1.MaxNumber];
__exportStar(require("./scalar"), exports);
__exportStar(require("./array"), exports);
//# sourceMappingURL=index.js.map

@@ -0,7 +1,13 @@

import { Maximum } from './maximum';
import { Minimum } from './minimum';
import { TypedSchemaStrategy } from '../base';
export { MaxNumber } from './max-number';
export { MinNumber } from './min-number';
export declare class NumberStrategy extends TypedSchemaStrategy {
type: string;
maximumStrategy: Maximum;
minimumStrategy: Minimum;
constructor(schemaNode: any);
matchObject(object: any): boolean;
addObject(number: number): void;
addSchema(schema: Record<string, unknown>): void;
toSchema(): any;
}

@@ -7,12 +7,12 @@ "use strict";

exports.NumberStrategy = void 0;
const maximum_1 = require("./maximum");
const minimum_1 = require("./minimum");
const base_1 = require("../base");
const lodash_1 = __importDefault(require("lodash"));
var max_number_1 = require("./max-number");
Object.defineProperty(exports, "MaxNumber", { enumerable: true, get: function () { return max_number_1.MaxNumber; } });
var min_number_1 = require("./min-number");
Object.defineProperty(exports, "MinNumber", { enumerable: true, get: function () { return min_number_1.MinNumber; } });
class NumberStrategy extends base_1.TypedSchemaStrategy {
constructor() {
super(...arguments);
constructor(schemaNode) {
super(schemaNode);
this.type = 'number';
this.maximumStrategy = new maximum_1.Maximum();
this.minimumStrategy = new minimum_1.Minimum();
}

@@ -22,4 +22,20 @@ matchObject(object) {

}
addObject(number) {
super.addObject(number);
this.maximumStrategy.addObject(number);
this.minimumStrategy.addObject(number);
}
addSchema(schema) {
super.addSchema(schema);
this.maximumStrategy.addSchema(schema);
this.minimumStrategy.addSchema(schema);
}
toSchema() {
let schema = super.toSchema();
schema = { ...schema, ...this.maximumStrategy.toSchema() };
schema = { ...schema, ...this.minimumStrategy.toSchema() };
return schema;
}
}
exports.NumberStrategy = NumberStrategy;
//# sourceMappingURL=index.js.map

@@ -8,5 +8,5 @@ import { SchemaStrategy } from './base';

keywords: Set<string>;
constructor();
addSchema(schema: any): void;
addObject(object: any): void;
constructor(schemaNode: any);
addSchema(schema: Record<string, any>): void;
addObject(object: Record<string, unknown>): void;
matchObject(object: any): boolean;

@@ -13,0 +13,0 @@ matchSchema(schema: any): boolean;

@@ -7,8 +7,8 @@ "use strict";

exports.ObjectStrategy = void 0;
const node_1 = require("../node");
const schema_node_1 = require("../schema-node");
const base_1 = require("./base");
const lodash_1 = __importDefault(require("lodash"));
class ObjectStrategy extends base_1.SchemaStrategy {
constructor() {
super();
constructor(schemaNode) {
super(schemaNode);
this.keywords = new Set(['type', 'properties', 'patternProperties', 'required']);

@@ -61,3 +61,3 @@ this.properties = {};

if (!this.properties[key]) {
this.properties[key] = new node_1.SchemaNode();
this.properties[key] = new schema_node_1.SchemaNode();
}

@@ -70,7 +70,8 @@ this.properties[key].addObject(value);

}
if (lodash_1.default.isNil(this.required)) {
if (lodash_1.default.isNil(this.required) || this.required.size === 0) {
this.required = properties;
}
else {
this.required = new Set([...properties, ...properties]);
const newRequirements = lodash_1.default.intersection([...properties], [...this.required]);
this.required = new Set(newRequirements);
}

@@ -77,0 +78,0 @@ }

import { SchemaStrategy, TypedSchemaStrategy } from './base';
export declare class Typeless extends SchemaStrategy {
matchSchema(schema: any): boolean;
matchSchema(schema: Record<string, unknown>): boolean;
matchObject(_object: any): boolean;

@@ -10,10 +10,2 @@ }

}
export declare class String extends TypedSchemaStrategy {
type: string;
matchObject(object: any): boolean;
}
export declare class Number extends TypedSchemaStrategy {
type: string;
matchObject(object: any): boolean;
}
export declare class Integer extends TypedSchemaStrategy {

@@ -20,0 +12,0 @@ type: string;

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Null = exports.Integer = exports.Number = exports.String = exports.Boolean = exports.Typeless = void 0;
exports.Null = exports.Integer = exports.Boolean = exports.Typeless = void 0;
const base_1 = require("./base");

@@ -29,22 +29,2 @@ const lodash_1 = __importDefault(require("lodash"));

exports.Boolean = Boolean;
class String extends base_1.TypedSchemaStrategy {
constructor() {
super(...arguments);
this.type = 'string';
}
matchObject(object) {
return lodash_1.default.isString(object);
}
}
exports.String = String;
class Number extends base_1.TypedSchemaStrategy {
constructor() {
super(...arguments);
this.type = 'number';
}
matchObject(object) {
return lodash_1.default.isNumber(object);
}
}
exports.Number = Number;
class Integer extends base_1.TypedSchemaStrategy {

@@ -51,0 +31,0 @@ constructor() {

{
"name": "schematized",
"description": "Turn JS objects into JSON schemas that continue to improve as you provide examples.",
"version": "1.2.0",
"version": "1.3.0",
"files": [

@@ -10,3 +10,3 @@ "dist/"

"types": "dist/index.d.ts",
"repository": "git://github.com/ryparker/json-schema-builder.git",
"repository": "https://github.com/ryparker/Schematized.git",
"author": "Ryan Parker",

@@ -48,2 +48,5 @@ "license": "MIT",

],
"include": [
"__tests__/*"
],
"exclude": [

@@ -50,0 +53,0 @@ "dist/**",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc