uniforms-bridge-json-schema
Advanced tools
Comparing version 3.0.0-rc.3 to 3.0.0-rc.4
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JSONSchemaBridge = exports.default = void 0; | ||
var JSONSchemaBridge_1 = require("./JSONSchemaBridge"); | ||
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return JSONSchemaBridge_1.default; } }); | ||
Object.defineProperty(exports, "JSONSchemaBridge", { enumerable: true, get: function () { return JSONSchemaBridge_1.default; } }); | ||
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(JSONSchemaBridge_1).default; } }); | ||
Object.defineProperty(exports, "JSONSchemaBridge", { enumerable: true, get: function () { return __importDefault(JSONSchemaBridge_1).default; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var invariant_1 = tslib_1.__importDefault(require("invariant")); | ||
var cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep")); | ||
var get_1 = tslib_1.__importDefault(require("lodash/get")); | ||
var invariant_1 = tslib_1.__importDefault(require("invariant")); | ||
var lowerCase_1 = tslib_1.__importDefault(require("lodash/lowerCase")); | ||
@@ -21,2 +21,9 @@ var memoize_1 = tslib_1.__importDefault(require("lodash/memoize")); | ||
} | ||
var propMapper = { | ||
maxItems: 'maxCount', | ||
minItems: 'minCount', | ||
maximum: 'max', | ||
minimum: 'min', | ||
multipleOf: 'step', | ||
}; | ||
function distinctSchema(schema) { | ||
@@ -157,8 +164,11 @@ if (schema.type === 'object') { | ||
var properties = _a.properties, required = _a.required, type = _a.type; | ||
if (properties) | ||
if (properties) { | ||
Object.assign(_definition.properties, properties); | ||
if (required) | ||
} | ||
if (required) { | ||
(_b = _definition.required).push.apply(_b, required); | ||
if (type && !_definition.type) | ||
} | ||
if (type && !_definition.type) { | ||
_definition.type = type; | ||
} | ||
}); | ||
@@ -176,4 +186,5 @@ } | ||
: get_1.default(this.schema.default, name) : _c, _d = _b.type, type = _d === void 0 ? _type : _d; | ||
if (defaultValue !== undefined) | ||
if (defaultValue !== undefined) { | ||
return cloneDeep_1.default(defaultValue); | ||
} | ||
if (type === 'array') { | ||
@@ -184,4 +195,5 @@ var item = this.getInitialValue(uniforms_1.joinName(name, '0')); | ||
} | ||
if (type === 'object') | ||
if (type === 'object') { | ||
return {}; | ||
} | ||
return undefined; | ||
@@ -193,10 +205,14 @@ }; | ||
var _b = omit_1.default(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, field), uniforms), this._compiledSchema[name]), ['default', 'format', 'type']), enum_ = _b.enum, isRequired = _b.isRequired, title = _b.title, ready = tslib_1.__rest(_b, ["enum", "isRequired", "title"]); | ||
if (enum_) | ||
if (enum_) { | ||
ready.allowedValues = enum_; | ||
if (field.type === 'number') | ||
} | ||
if (field.type === 'number') { | ||
ready.decimal = true; | ||
if (uniforms && uniforms.type !== undefined) | ||
} | ||
if (uniforms && uniforms.type !== undefined) { | ||
ready.type = uniforms.type; | ||
if (ready.required === undefined) | ||
} | ||
if (ready.required === undefined) { | ||
ready.required = isRequired; | ||
} | ||
ready.label = extractValue(ready.label, title, toHumanLabel(uniforms_1.joinName(null, name).slice(-1)[0])); | ||
@@ -216,2 +232,9 @@ var options = props.options || ready.options; | ||
} | ||
Object.keys(ready).forEach(function (key) { | ||
if (key in propMapper) { | ||
var newKey = propMapper[key]; | ||
ready[newKey] = ready[key]; | ||
delete ready[key]; | ||
} | ||
}); | ||
return ready; | ||
@@ -236,16 +259,23 @@ }; | ||
var _b = this._compiledSchema[name].type, fieldType = _b === void 0 ? _type : _b; | ||
if (fieldFormat === 'date-time') | ||
if (fieldFormat === 'date-time') { | ||
return Date; | ||
if (fieldType === 'string') | ||
} | ||
if (fieldType === 'string') { | ||
return String; | ||
if (fieldType === 'number') | ||
} | ||
if (fieldType === 'number') { | ||
return Number; | ||
if (fieldType === 'integer') | ||
} | ||
if (fieldType === 'integer') { | ||
return Number; | ||
if (fieldType === 'object') | ||
} | ||
if (fieldType === 'object') { | ||
return Object; | ||
if (fieldType === 'array') | ||
} | ||
if (fieldType === 'array') { | ||
return Array; | ||
if (fieldType === 'boolean') | ||
} | ||
if (fieldType === 'boolean') { | ||
return Boolean; | ||
} | ||
invariant_1.default(fieldType !== 'null', 'Field "%s" can not be represented as a type null', name); | ||
@@ -252,0 +282,0 @@ return fieldType; |
import { __rest } from "tslib"; | ||
import invariant from 'invariant'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import get from 'lodash/get'; | ||
import invariant from 'invariant'; | ||
import lowerCase from 'lodash/lowerCase'; | ||
@@ -19,2 +19,9 @@ import memoize from 'lodash/memoize'; | ||
} | ||
const propMapper = { | ||
maxItems: 'maxCount', | ||
minItems: 'minCount', | ||
maximum: 'max', | ||
minimum: 'min', | ||
multipleOf: 'step', | ||
}; | ||
function distinctSchema(schema) { | ||
@@ -134,8 +141,11 @@ if (schema.type === 'object') { | ||
combinedPartials.forEach(({ properties, required, type }) => { | ||
if (properties) | ||
if (properties) { | ||
Object.assign(_definition.properties, properties); | ||
if (required) | ||
} | ||
if (required) { | ||
_definition.required.push(...required); | ||
if (type && !_definition.type) | ||
} | ||
if (type && !_definition.type) { | ||
_definition.type = type; | ||
} | ||
}); | ||
@@ -152,4 +162,5 @@ } | ||
: get(this.schema.default, name), type = _type, } = this._compiledSchema[name]; | ||
if (defaultValue !== undefined) | ||
if (defaultValue !== undefined) { | ||
return cloneDeep(defaultValue); | ||
} | ||
if (type === 'array') { | ||
@@ -160,4 +171,5 @@ const item = this.getInitialValue(joinName(name, '0')); | ||
} | ||
if (type === 'object') | ||
if (type === 'object') { | ||
return {}; | ||
} | ||
return undefined; | ||
@@ -168,10 +180,14 @@ } | ||
const _b = omit(Object.assign(Object.assign(Object.assign({}, field), uniforms), this._compiledSchema[name]), ['default', 'format', 'type']), { enum: enum_, isRequired, title } = _b, ready = __rest(_b, ["enum", "isRequired", "title"]); | ||
if (enum_) | ||
if (enum_) { | ||
ready.allowedValues = enum_; | ||
if (field.type === 'number') | ||
} | ||
if (field.type === 'number') { | ||
ready.decimal = true; | ||
if (uniforms && uniforms.type !== undefined) | ||
} | ||
if (uniforms && uniforms.type !== undefined) { | ||
ready.type = uniforms.type; | ||
if (ready.required === undefined) | ||
} | ||
if (ready.required === undefined) { | ||
ready.required = isRequired; | ||
} | ||
ready.label = extractValue(ready.label, title, toHumanLabel(joinName(null, name).slice(-1)[0])); | ||
@@ -189,2 +205,9 @@ const options = props.options || ready.options; | ||
} | ||
Object.keys(ready).forEach(key => { | ||
if (key in propMapper) { | ||
const newKey = propMapper[key]; | ||
ready[newKey] = ready[key]; | ||
delete ready[key]; | ||
} | ||
}); | ||
return ready; | ||
@@ -209,16 +232,23 @@ } | ||
const { type: fieldType = _type } = this._compiledSchema[name]; | ||
if (fieldFormat === 'date-time') | ||
if (fieldFormat === 'date-time') { | ||
return Date; | ||
if (fieldType === 'string') | ||
} | ||
if (fieldType === 'string') { | ||
return String; | ||
if (fieldType === 'number') | ||
} | ||
if (fieldType === 'number') { | ||
return Number; | ||
if (fieldType === 'integer') | ||
} | ||
if (fieldType === 'integer') { | ||
return Number; | ||
if (fieldType === 'object') | ||
} | ||
if (fieldType === 'object') { | ||
return Object; | ||
if (fieldType === 'array') | ||
} | ||
if (fieldType === 'array') { | ||
return Array; | ||
if (fieldType === 'boolean') | ||
} | ||
if (fieldType === 'boolean') { | ||
return Boolean; | ||
} | ||
invariant(fieldType !== 'null', 'Field "%s" can not be represented as a type null', name); | ||
@@ -225,0 +255,0 @@ return fieldType; |
{ | ||
"name": "uniforms-bridge-json-schema", | ||
"version": "3.0.0-rc.3", | ||
"version": "3.0.0-rc.4", | ||
"license": "MIT", | ||
@@ -30,5 +30,5 @@ "main": "es5/index.js", | ||
"tslib": "^1.10.0", | ||
"uniforms": "^3.0.0-rc.3" | ||
"uniforms": "^3.0.0-rc.4" | ||
}, | ||
"gitHead": "ecdb0297c75ea20fccf95b73c8ab63d9c583a500" | ||
"gitHead": "606afa97d8cd6952d2622c47c79786f6a662a2e4" | ||
} |
@@ -0,4 +1,4 @@ | ||
import invariant from 'invariant'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import get from 'lodash/get'; | ||
import invariant from 'invariant'; | ||
import lowerCase from 'lodash/lowerCase'; | ||
@@ -31,2 +31,10 @@ import memoize from 'lodash/memoize'; | ||
const propMapper: Record<string, string> = { | ||
maxItems: 'maxCount', | ||
minItems: 'minCount', | ||
maximum: 'max', | ||
minimum: 'min', | ||
multipleOf: 'step', | ||
}; | ||
function distinctSchema(schema: Record<string, any>) { | ||
@@ -194,5 +202,11 @@ if (schema.type === 'object') { | ||
combinedPartials.forEach(({ properties, required, type }) => { | ||
if (properties) Object.assign(_definition.properties, properties); | ||
if (required) _definition.required.push(...required); | ||
if (type && !_definition.type) _definition.type = type; | ||
if (properties) { | ||
Object.assign(_definition.properties, properties); | ||
} | ||
if (required) { | ||
_definition.required.push(...required); | ||
} | ||
if (type && !_definition.type) { | ||
_definition.type = type; | ||
} | ||
}); | ||
@@ -216,3 +230,5 @@ } | ||
if (defaultValue !== undefined) return cloneDeep(defaultValue); | ||
if (defaultValue !== undefined) { | ||
return cloneDeep(defaultValue); | ||
} | ||
@@ -225,3 +241,5 @@ if (type === 'array') { | ||
if (type === 'object') return {}; | ||
if (type === 'object') { | ||
return {}; | ||
} | ||
@@ -238,6 +256,14 @@ return undefined; | ||
if (enum_) ready.allowedValues = enum_; | ||
if (field.type === 'number') ready.decimal = true; | ||
if (uniforms && uniforms.type !== undefined) ready.type = uniforms.type; | ||
if (ready.required === undefined) ready.required = isRequired; | ||
if (enum_) { | ||
ready.allowedValues = enum_; | ||
} | ||
if (field.type === 'number') { | ||
ready.decimal = true; | ||
} | ||
if (uniforms && uniforms.type !== undefined) { | ||
ready.type = uniforms.type; | ||
} | ||
if (ready.required === undefined) { | ||
ready.required = isRequired; | ||
} | ||
ready.label = extractValue( | ||
@@ -261,2 +287,10 @@ ready.label, | ||
Object.keys(ready).forEach(key => { | ||
if (key in propMapper) { | ||
const newKey = propMapper[key]; | ||
ready[newKey] = ready[key]; | ||
delete ready[key]; | ||
} | ||
}); | ||
return ready; | ||
@@ -291,9 +325,23 @@ } | ||
if (fieldFormat === 'date-time') return Date; | ||
if (fieldType === 'string') return String; | ||
if (fieldType === 'number') return Number; | ||
if (fieldType === 'integer') return Number; | ||
if (fieldType === 'object') return Object; | ||
if (fieldType === 'array') return Array; | ||
if (fieldType === 'boolean') return Boolean; | ||
if (fieldFormat === 'date-time') { | ||
return Date; | ||
} | ||
if (fieldType === 'string') { | ||
return String; | ||
} | ||
if (fieldType === 'number') { | ||
return Number; | ||
} | ||
if (fieldType === 'integer') { | ||
return Number; | ||
} | ||
if (fieldType === 'object') { | ||
return Object; | ||
} | ||
if (fieldType === 'array') { | ||
return Array; | ||
} | ||
if (fieldType === 'boolean') { | ||
return Boolean; | ||
} | ||
@@ -300,0 +348,0 @@ invariant( |
37017
885
Updateduniforms@^3.0.0-rc.4