@apigames/json
Advanced tools
Comparing version 1.0.13 to 1.0.14
93
index.js
@@ -1,24 +0,79 @@ | ||
exports.PayloadValidator = require("./src/json.schema.validator").PayloadValidator; | ||
exports.Schema = { | ||
import { append, areEqual, clone, extractAndRedact, isArray, isBoolean, isDate, isEmpty, isError, isNumber, isObject, | ||
isRegExp, isString, isDefined, isUndefined, stringify } from "./src/json.utils"; | ||
import {SystemTypeDatetimeSchema} from "./src/document-schemas/primitives/system.type.datetime.schema"; | ||
import {SystemTypeEmailAddressSchema} from "./src/document-schemas/primitives/system.type.email.address.schema"; | ||
import {SystemTypeGeolocationPointSchema} from "./src/document-schemas/primitives/system.type.geolocation.point.schema"; | ||
import {SystemTypeIpAddressSchema} from "./src/document-schemas/primitives/system.type.ip.address.schema"; | ||
import {SystemTypeMongoDBObjectIdSchema} from "./src/document-schemas/primitives/system.type.mongodb.objectid.schema"; | ||
import {SystemTypePhoneNumberSchema} from "./src/document-schemas/primitives/system.type.phone.number.schema"; | ||
import {SystemTypeTimeDurationSchema} from "./src/document-schemas/primitives/system.type.time.duration.schema"; | ||
import {SystemTypeWeblinkListSchema} from "./src/document-schemas/primitives/system.type.weblink.list.schema"; | ||
import {SystemTypeWeblinkSchema} from "./src/document-schemas/primitives/system.type.weblink.schema"; | ||
import {SystemTypeWebsiteUrlSchema} from "./src/document-schemas/primitives/system.type.website.url.schema"; | ||
import {SystemTypeSocialFacebookUrlSchema} from "./src/document-schemas/social/system.type.social.facebook.url.schema"; | ||
import {SystemTypeSocialGooglePlusUrlSchema} from "./src/document-schemas/social/system.type.social.googlePlus.url.schema"; | ||
import {SystemTypeSocialInstagramUrlSchema} from "./src/document-schemas/social/system.type.social.instagram.url.schema"; | ||
import {SystemTypeSocialMediaLinksSchema} from "./src/document-schemas/social/system.type.social.media.links.schema"; | ||
import {SystemTypeSocialTwitterUrlSchema} from "./src/document-schemas/social/system.type.social.twitter.url.schema"; | ||
import {SystemTypeSocialYoutubeUrlSchema} from "./src/document-schemas/social/system.type.social.youtube.url.schema"; | ||
export { SystemTypeDatetimeSchema } from "./src/document-schemas/primitives/system.type.datetime.schema"; | ||
export { SystemTypeEmailAddressSchema } from "./src/document-schemas/primitives/system.type.email.address.schema"; | ||
export { SystemTypeGeolocationPointSchema } from "./src/document-schemas/primitives/system.type.geolocation.point.schema"; | ||
export { SystemTypeIpAddressSchema } from "./src/document-schemas/primitives/system.type.ip.address.schema"; | ||
export { SystemTypeMongoDBObjectIdSchema } from "./src/document-schemas/primitives/system.type.mongodb.objectid.schema"; | ||
export { SystemTypePhoneNumberSchema } from "./src/document-schemas/primitives/system.type.phone.number.schema"; | ||
export { SystemTypeTimeDurationSchema } from "./src/document-schemas/primitives/system.type.time.duration.schema"; | ||
export { SystemTypeWeblinkListSchema } from "./src/document-schemas/primitives/system.type.weblink.list.schema"; | ||
export { SystemTypeWeblinkSchema } from "./src/document-schemas/primitives/system.type.weblink.schema"; | ||
export { SystemTypeWebsiteUrlSchema } from "./src/document-schemas/primitives/system.type.website.url.schema"; | ||
export { SystemTypeSocialFacebookUrlSchema } from "./src/document-schemas/social/system.type.social.facebook.url.schema"; | ||
export { SystemTypeSocialGooglePlusUrlSchema } from "./src/document-schemas/social/system.type.social.googlePlus.url.schema"; | ||
export { SystemTypeSocialInstagramUrlSchema } from "./src/document-schemas/social/system.type.social.instagram.url.schema"; | ||
export { SystemTypeSocialMediaLinksSchema } from "./src/document-schemas/social/system.type.social.media.links.schema"; | ||
export { SystemTypeSocialTwitterUrlSchema } from "./src/document-schemas/social/system.type.social.twitter.url.schema"; | ||
export { SystemTypeSocialYoutubeUrlSchema } from "./src/document-schemas/social/system.type.social.youtube.url.schema"; | ||
export { PayloadValidator, PayloadValidatorClass } from "./src/json.schema.validator"; | ||
export const Schema = { | ||
Primitives: { | ||
DateTimeValidator: require("./src/document-schemas/primitives/system.type.datetime.schema").Validator, | ||
EmailAddressValidator: require("./src/document-schemas/primitives/system.type.email.address.schema").Validator, | ||
GeolocationPointValidator: require("./src/document-schemas/primitives/system.type.geolocation.point.schema").Validator, | ||
IpAddressValidator: require("./src/document-schemas/primitives/system.type.ip.address.schema").Validator, | ||
MongoDbObjectIdValidator: require("./src/document-schemas/primitives/system.type.mongodb.objectid.schema").Validator, | ||
PhoneNumberValidator: require("./src/document-schemas/primitives/system.type.phone.number.schema").Validator, | ||
TimeDurationValidator: require("./src/document-schemas/primitives/system.type.time.duration.schema").Validator, | ||
WeblinkListValidator: require("./src/document-schemas/primitives/system.type.weblink.list.schema").Validator, | ||
WeblinkValidator: require("./src/document-schemas/primitives/system.type.weblink.schema").Validator, | ||
WebsiteUrlValidator: require("./src/document-schemas/primitives/system.type.website.url.schema").Validator | ||
DateTimeValidator: SystemTypeDatetimeSchema, | ||
EmailAddressValidator: SystemTypeEmailAddressSchema, | ||
GeolocationPointValidator: SystemTypeGeolocationPointSchema, | ||
IpAddressValidator: SystemTypeIpAddressSchema, | ||
MongoDbObjectIdValidator: SystemTypeMongoDBObjectIdSchema, | ||
PhoneNumberValidator: SystemTypePhoneNumberSchema, | ||
TimeDurationValidator: SystemTypeTimeDurationSchema, | ||
WeblinkListValidator: SystemTypeWeblinkListSchema, | ||
WeblinkValidator: SystemTypeWeblinkSchema, | ||
WebsiteUrlValidator: SystemTypeWebsiteUrlSchema | ||
}, | ||
SocialMedia: { | ||
FacebookUrlValidator: require("./src/document-schemas/social/system.type.social.facebook.url.schema").Validator, | ||
GooglePlusUrlValidator: require("./src/document-schemas/social/system.type.social.googlePlus.url.schema").Validator, | ||
InstagramUrlValidator: require("./src/document-schemas/social/system.type.social.instagram.url.schema").Validator, | ||
SocialMediaLinksValidator: require("./src/document-schemas/social/system.type.social.media.links.schema").Validator, | ||
TwitterUrlValidator: require("./src/document-schemas/social/system.type.social.twitter.url.schema").Validator, | ||
YoutubeUrlValidator: require("./src/document-schemas/social/system.type.social.youtube.url.schema").Validator | ||
FacebookUrlValidator: SystemTypeSocialFacebookUrlSchema, | ||
GooglePlusUrlValidator: SystemTypeSocialGooglePlusUrlSchema, | ||
InstagramUrlValidator: SystemTypeSocialInstagramUrlSchema, | ||
SocialMediaLinksValidator: SystemTypeSocialMediaLinksSchema, | ||
TwitterUrlValidator: SystemTypeSocialTwitterUrlSchema, | ||
YoutubeUrlValidator: SystemTypeSocialYoutubeUrlSchema | ||
} | ||
}; | ||
exports.Utils = require("./src/json.utils"); | ||
export const Utils = { | ||
append: append, | ||
areEqual: areEqual, | ||
clone: clone, | ||
extractAndRedact: extractAndRedact, | ||
isArray: isArray, | ||
isBoolean: isBoolean, | ||
isDate: isDate, | ||
isEmpty: isEmpty, | ||
isError: isError, | ||
isNumber: isNumber, | ||
isObject: isObject, | ||
isRegExp: isRegExp, | ||
isString: isString, | ||
isDefined: isDefined, | ||
isUndefined: isUndefined, | ||
stringify: stringify | ||
}; |
@@ -6,3 +6,3 @@ { | ||
"license": "UNLICENSED", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"main": "index.js", | ||
@@ -12,2 +12,9 @@ "scripts": { | ||
}, | ||
"babel": { | ||
"env": { | ||
"test": { | ||
"plugins": ["@babel/plugin-transform-modules-commonjs"] | ||
} | ||
} | ||
}, | ||
"jest": { | ||
@@ -26,3 +33,6 @@ "automock": false, | ||
"<rootDir>" | ||
] | ||
], | ||
"transform": { | ||
"^.+\\.m?js$": "babel-jest" | ||
} | ||
}, | ||
@@ -35,2 +45,3 @@ "dependencies": { | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.8.3", | ||
"jest": "^24.9.0" | ||
@@ -37,0 +48,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
class SystemTypeDatetimeSchema { | ||
export class SystemTypeDatetimeSchema { | ||
@@ -27,6 +27,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeDatetimeSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypeEmailAddressSchema { | ||
export class SystemTypeEmailAddressSchema { | ||
@@ -19,6 +19,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeEmailAddressSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypeGeolocationPointSchema { | ||
export class SystemTypeGeolocationPointSchema { | ||
@@ -43,6 +43,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeGeolocationPointSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypeIpAddressSchema { | ||
export class SystemTypeIpAddressSchema { | ||
@@ -19,6 +19,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeIpAddressSchema | ||
}; | ||
} |
const MongoDbObjectIdRegex = /[a-fA-F0-9]{24}/; | ||
class SystemTypeMongoDBObjectIdSchema { | ||
export class SystemTypeMongoDBObjectIdSchema { | ||
@@ -21,6 +21,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeMongoDBObjectIdSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypePhoneNumberSchema { | ||
export class SystemTypePhoneNumberSchema { | ||
@@ -31,6 +31,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypePhoneNumberSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTimeDurationSchema { | ||
export class SystemTypeTimeDurationSchema { | ||
@@ -17,6 +17,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTimeDurationSchema | ||
}; | ||
} |
@@ -1,4 +0,4 @@ | ||
const systemTypeWeblinkSchema = require("./system.type.weblink.schema").Validator; | ||
import { SystemTypeWeblinkSchema } from "./system.type.weblink.schema"; | ||
class SystemTypeWeblinkListSchema { | ||
export class SystemTypeWeblinkListSchema { | ||
@@ -10,3 +10,3 @@ static schemaName() { | ||
static setupSchemaDependencies(registerSchema) { | ||
registerSchema(systemTypeWeblinkSchema); | ||
registerSchema(SystemTypeWeblinkSchema); | ||
} | ||
@@ -21,9 +21,5 @@ | ||
type: "array", | ||
items : { "$ref" : systemTypeWeblinkSchema.schemaName() } | ||
items : { "$ref" : SystemTypeWeblinkSchema.schemaName() } | ||
}; | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeWeblinkListSchema | ||
}; | ||
} |
@@ -1,4 +0,4 @@ | ||
const systemTypeWebsiteUrlSchema = require("./system.type.website.url.schema").Validator; | ||
import { SystemTypeWebsiteUrlSchema } from "./system.type.website.url.schema"; | ||
class SystemTypeWeblinkSchema { | ||
export class SystemTypeWeblinkSchema { | ||
@@ -10,3 +10,3 @@ static schemaName() { | ||
static setupSchemaDependencies(registerSchema) { | ||
registerSchema(systemTypeWebsiteUrlSchema); | ||
registerSchema(SystemTypeWebsiteUrlSchema); | ||
} | ||
@@ -32,3 +32,3 @@ | ||
}, | ||
url: { "$ref" : systemTypeWebsiteUrlSchema.schemaName() } | ||
url: { "$ref" : SystemTypeWebsiteUrlSchema.schemaName() } | ||
}, | ||
@@ -39,6 +39,2 @@ additionalProperties: false, | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeWeblinkSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypeWebsiteUrlSchema { | ||
export class SystemTypeWebsiteUrlSchema { | ||
@@ -18,6 +18,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeWebsiteUrlSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypeSocialFacebookUrlSchema { | ||
export class SystemTypeSocialFacebookUrlSchema { | ||
@@ -18,6 +18,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeSocialFacebookUrlSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypeSocialGooglePlusUrlSchema { | ||
export class SystemTypeSocialGooglePlusUrlSchema { | ||
@@ -18,6 +18,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeSocialGooglePlusUrlSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypeSocialInstagramUrlSchema { | ||
export class SystemTypeSocialInstagramUrlSchema { | ||
@@ -18,6 +18,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeSocialInstagramUrlSchema | ||
}; | ||
} |
@@ -1,8 +0,8 @@ | ||
const systemTypeSocialFacebookAddressSchema = require("./system.type.social.facebook.url.schema").Validator, | ||
systemTypeSocialTwitterAddressSchema = require("./system.type.social.twitter.url.schema").Validator, | ||
systemTypeSocialGooglePlusAddressSchema = require("./system.type.social.googlePlus.url.schema").Validator, | ||
systemTypeSocialInstagramAddressSchema = require("./system.type.social.instagram.url.schema").Validator, | ||
systemTypeSocialYoutubeAddressSchema = require("./system.type.social.youtube.url.schema").Validator; | ||
import { SystemTypeSocialFacebookUrlSchema } from "./system.type.social.facebook.url.schema"; | ||
import { SystemTypeSocialTwitterUrlSchema } from "./system.type.social.twitter.url.schema"; | ||
import { SystemTypeSocialGooglePlusUrlSchema } from "./system.type.social.googlePlus.url.schema"; | ||
import { SystemTypeSocialInstagramUrlSchema } from "./system.type.social.instagram.url.schema"; | ||
import { SystemTypeSocialYoutubeUrlSchema } from "./system.type.social.youtube.url.schema"; | ||
class SystemTypeSocialMediaLinksSchema { | ||
export class SystemTypeSocialMediaLinksSchema { | ||
@@ -14,7 +14,7 @@ static schemaName() { | ||
static setupSchemaDependencies(registerSchema) { | ||
registerSchema(systemTypeSocialFacebookAddressSchema); | ||
registerSchema(systemTypeSocialTwitterAddressSchema); | ||
registerSchema(systemTypeSocialGooglePlusAddressSchema); | ||
registerSchema(systemTypeSocialInstagramAddressSchema); | ||
registerSchema(systemTypeSocialYoutubeAddressSchema); | ||
registerSchema(SystemTypeSocialFacebookUrlSchema); | ||
registerSchema(SystemTypeSocialTwitterUrlSchema); | ||
registerSchema(SystemTypeSocialGooglePlusUrlSchema); | ||
registerSchema(SystemTypeSocialInstagramUrlSchema); | ||
registerSchema(SystemTypeSocialYoutubeUrlSchema); | ||
} | ||
@@ -30,7 +30,7 @@ | ||
properties: { | ||
facebook : { "$ref" : systemTypeSocialFacebookAddressSchema.schemaName() }, | ||
twitter : { "$ref" : systemTypeSocialTwitterAddressSchema.schemaName() }, | ||
googlePlus : { "$ref" : systemTypeSocialGooglePlusAddressSchema.schemaName() }, | ||
instagram : { "$ref" : systemTypeSocialInstagramAddressSchema.schemaName() }, | ||
youtube : { "$ref" : systemTypeSocialYoutubeAddressSchema.schemaName() } | ||
facebook : { "$ref": SystemTypeSocialFacebookUrlSchema.schemaName() }, | ||
twitter : { "$ref": SystemTypeSocialTwitterUrlSchema.schemaName() }, | ||
googlePlus : { "$ref": SystemTypeSocialGooglePlusUrlSchema.schemaName() }, | ||
instagram : { "$ref": SystemTypeSocialInstagramUrlSchema.schemaName() }, | ||
youtube : { "$ref": SystemTypeSocialYoutubeUrlSchema.schemaName() } | ||
}, | ||
@@ -41,6 +41,2 @@ additionalProperties: false, | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeSocialMediaLinksSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypeSocialTwitterUrlSchema { | ||
export class SystemTypeSocialTwitterUrlSchema { | ||
@@ -18,6 +18,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeSocialTwitterUrlSchema | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
class SystemTypeSocialYoutubeUrlSchema { | ||
export class SystemTypeSocialYoutubeUrlSchema { | ||
@@ -18,6 +18,2 @@ static schemaName() { | ||
} | ||
} | ||
module.exports = { | ||
Validator: SystemTypeSocialYoutubeUrlSchema | ||
}; | ||
} |
@@ -1,4 +0,4 @@ | ||
const jsonSchemaValidator = require("jsonschema").Validator; | ||
import { Validator as jsonSchemaValidator } from "jsonschema"; | ||
class PayloadValidator { | ||
export class PayloadValidatorClass { | ||
constructor () { | ||
@@ -74,4 +74,4 @@ this._validator = undefined; | ||
exports.PayloadValidator = function() { | ||
return new PayloadValidator(); | ||
}; | ||
export function PayloadValidator() { | ||
return new PayloadValidatorClass(); | ||
} |
@@ -1,48 +0,48 @@ | ||
const deepEqual = require("deep-equal"); | ||
import deepEqual from "deep-equal"; | ||
function isArray (value) { | ||
export function isArray (value) { | ||
return ((value !== null) && ((value !== undefined))) && (typeof value === "object") && (value.constructor === Array); | ||
} | ||
function isBoolean (value) { | ||
export function isBoolean (value) { | ||
return ((value !== null) && ((value !== undefined))) && (typeof value === 'boolean'); | ||
} | ||
function isDate (value) { | ||
export function isDate (value) { | ||
return ((value !== null) && ((value !== undefined))) && (value instanceof Date); | ||
} | ||
function isEmpty(document) { | ||
export function isEmpty(document) { | ||
return (!document) || (Object.keys(document).length === 0 && document.constructor === Object); | ||
} | ||
function isError (value) { | ||
export function isError (value) { | ||
return ((value !== null) && ((value !== undefined))) && (value instanceof Error) && (typeof value.message !== "undefined"); | ||
} | ||
function isNumber (value) { | ||
export function isNumber (value) { | ||
return ((value !== null) && ((value !== undefined))) && (typeof value === "number") && isFinite(value); | ||
} | ||
function isObject (value) { | ||
export function isObject (value) { | ||
return ((value !== null) && ((value !== undefined))) && (typeof value === "object") && (value.constructor === Object); | ||
} | ||
function isRegExp (value) { | ||
export function isRegExp (value) { | ||
return ((value !== null) && ((value !== undefined))) && (typeof value === "object") && (value.constructor === RegExp); | ||
} | ||
function isString (value) { | ||
export function isString (value) { | ||
return ((value !== null) && ((value !== undefined))) && ((typeof value === "string") || (value instanceof String)); | ||
} | ||
function isDefined (value) { | ||
export function isDefined (value) { | ||
return (value !== undefined); | ||
} | ||
function isUndefined (value) { | ||
export function isUndefined (value) { | ||
return (value === undefined); | ||
} | ||
function append(document, extensionDocument) { | ||
export function append(document, extensionDocument) { | ||
const extensionDoc = extensionDocument || {}; | ||
@@ -79,7 +79,7 @@ const doc = document || {}; | ||
function areEqual(firstObject, secondObject) { | ||
export function areEqual(firstObject, secondObject) { | ||
return deepEqual(firstObject, secondObject); | ||
} | ||
function clone(value) { | ||
export function clone(value) { | ||
if (value) { | ||
@@ -90,3 +90,3 @@ return JSON.parse(JSON.stringify(value)); | ||
function stringify(obj, indent = 4, linePrefix = "", quoteFieldNames = true) { | ||
export function stringify(obj, indent = 4, linePrefix = "", quoteFieldNames = true) { | ||
let lines = JSON.stringify(obj, null, indent).split("\n"); | ||
@@ -113,3 +113,3 @@ | ||
function extractAndRedact(document, property) { | ||
export function extractAndRedact(document, property) { | ||
if (document.hasOwnProperty(property)) { | ||
@@ -120,21 +120,2 @@ let value = JSON.parse(JSON.stringify(document[property])); | ||
} | ||
} | ||
module.exports = { | ||
append: append, | ||
areEqual: areEqual, | ||
clone: clone, | ||
extractAndRedact: extractAndRedact, | ||
isArray: isArray, | ||
isBoolean: isBoolean, | ||
isDate: isDate, | ||
isEmpty: isEmpty, | ||
isError: isError, | ||
isNumber: isNumber, | ||
isObject: isObject, | ||
isRegExp: isRegExp, | ||
isString: isString, | ||
isDefined: isDefined, | ||
isUndefined: isUndefined, | ||
stringify: stringify | ||
}; | ||
} |
28459
2
558