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

@trayio/commons

Package Overview
Dependencies
Maintainers
0
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trayio/commons - npm Package Compare versions

Comparing version 4.37.0 to 4.38.0

2

dist/dynamicschema/DynamicSchema.d.ts

@@ -13,2 +13,4 @@ import * as E from 'fp-ts/Either';

validate: (schema: DynamicSchema | DynamicObject, value: DynamicObject, strict?: O.Option<boolean>, coerce?: boolean) => E.Either<Error, DynamicObject>;
fromValue: (value: DynamicObject, schemaUrl: O.Option<string>) => DynamicObject;
isValidJsonSchema: (schema: DynamicObject) => boolean;
}

@@ -15,0 +17,0 @@ export declare const DynamicSchema: DynamicSchemaInterface;

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

const t = __importStar(require("io-ts"));
const function_1 = require("fp-ts/function");
const function_1 = require("fp-ts/lib/function");
const deep_copy_ts_1 = require("deep-copy-ts");

@@ -41,2 +41,4 @@ const DynamicType_1 = require("../dynamictype/DynamicType");

const Try_1 = require("../try/Try");
const draft04SchemaUrl = 'http://json-schema.org/draft-04/schema';
const schemaProperty = '$schema';
const ajv = new ajv_draft_04_1.default({ strict: false, removeAdditional: 'all' });

@@ -97,2 +99,40 @@ /*

};
const createSchema = (value) => {
if (Array.isArray(value) && value.length > 0) {
return {
type: 'array',
items: createSchema(value[0]),
};
}
if (typeof value === 'object' && value !== null) {
const properties = {};
for (const [key, val] of Object.entries(value)) {
properties[key] = createSchema(val);
}
return {
type: 'object',
properties,
required: Object.keys(properties),
};
}
if (value === null) {
return { type: 'null' };
}
if (typeof value === 'boolean') {
return { type: 'boolean' };
}
if (typeof value === 'number') {
return { type: 'number' };
}
if (typeof value === 'string') {
return { type: 'string' };
}
return {};
};
const createSchemaWithSchemaUrl = (schema, schemaUrl) => {
const hasSchemaUrl = O.isSome(schemaUrl);
const schemaObj = createSchema(schema);
schemaObj[schemaProperty] = hasSchemaUrl ? schemaUrl.value : draft04SchemaUrl;
return schemaObj;
};
exports.DynamicSchema = {

@@ -124,2 +164,4 @@ fromDynamicObject: (schema, strict = O.none) => {

},
fromValue: (value, schemaUrl = O.none) => createSchemaWithSchemaUrl(value, schemaUrl),
isValidJsonSchema: (schema) => isDynamicSchema(schema),
};

@@ -33,2 +33,3 @@ "use strict";

let value;
let validSchemaWithoutExtraFields;
let valueWithExtraFields;

@@ -71,2 +72,36 @@ let valueWithCoerceableTypes;

};
validSchemaWithoutExtraFields = {
type: 'object',
properties: {
name: {
type: 'string',
},
age: {
type: 'number',
},
races: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
car: {
type: 'object',
properties: {
model: {
type: 'string',
},
},
required: ['model'],
},
},
required: ['name', 'car'],
},
},
},
required: ['name', 'age', 'races'],
$schema: 'http://json-schema.org/draft-04/schema',
};
invalidSchema = {

@@ -579,2 +614,13 @@ type: 'invalidType',

});
describe('fromValue', () => {
it('should return a Right with the schema when given a valid value object', () => {
const result = DynamicSchema_1.DynamicSchema.fromValue(value, O.none);
expect(result).toEqual(validSchemaWithoutExtraFields);
});
it('should return a Right with the schema when given a valid value object and a schema url', () => {
const schemaUrl = 'http://json-schema.org/draft-04/schema#';
const result = DynamicSchema_1.DynamicSchema.fromValue(value, O.some(schemaUrl));
expect(result.$schema).toEqual(schemaUrl);
});
});
});

2

package.json
{
"name": "@trayio/commons",
"version": "4.37.0",
"version": "4.38.0",
"description": "Extensions to the standard/core libraries and basic features",

@@ -5,0 +5,0 @@ "exports": {

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