Socket
Socket
Sign inDemoInstall

@jsonforms/core

Package Overview
Dependencies
Maintainers
5
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsonforms/core - npm Package Compare versions

Comparing version 2.4.1 to 2.5.0-alpha.0

docs/interfaces/action.html

11

lib/actions/index.d.ts

@@ -8,2 +8,3 @@ import AJV, { ErrorObject } from 'ajv';

export declare const INIT: 'jsonforms/INIT';
export declare const UPDATE_CORE: 'jsonforms/UPDATE_CORE';
export declare const SET_AJV: 'jsonforms/SET_AJV';

@@ -28,3 +29,3 @@ export declare const UPDATE_DATA: 'jsonforms/UPDATE';

export declare const REMOVE_DEFAULT_DATA: 'jsonforms/REMOVE_DEFAULT_DATA';
export declare type CoreActions = InitAction | UpdateAction | UpdateErrorsAction | SetAjvAction | SetSchemaAction | SetUISchemaAction | SetValidationModeAction;
export declare type CoreActions = InitAction | UpdateCoreAction | UpdateAction | UpdateErrorsAction | SetAjvAction | SetSchemaAction | SetUISchemaAction | SetValidationModeAction;
export interface UpdateAction {

@@ -46,2 +47,9 @@ type: 'jsonforms/UPDATE';

}
export interface UpdateCoreAction {
type: 'jsonforms/UPDATE_CORE';
data?: any;
schema?: JsonSchema;
uischema?: UISchemaElement;
options?: InitActionOptions | AJV.Ajv;
}
export interface InitActionOptions {

@@ -63,2 +71,3 @@ ajv?: AJV.Ajv;

};
export declare const updateCore: (data: any, schema: JsonSchema, uischema?: UISchemaElement, options?: AJV.Ajv | InitActionOptions) => UpdateCoreAction;
export interface RegisterDefaultDataAction {

@@ -65,0 +74,0 @@ type: 'jsonforms/ADD_DEFAULT_DATA';

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

exports.INIT = 'jsonforms/INIT';
exports.UPDATE_CORE = "jsonforms/UPDATE_CORE";
exports.SET_AJV = 'jsonforms/SET_AJV';

@@ -35,2 +36,9 @@ exports.UPDATE_DATA = 'jsonforms/UPDATE';

};
exports.updateCore = function (data, schema, uischema, options) { return ({
type: exports.UPDATE_CORE,
data: data,
schema: schema,
uischema: uischema,
options: options
}); };
exports.registerDefaultData = function (schemaPath, data) { return ({

@@ -37,0 +45,0 @@ type: exports.ADD_DEFAULT_DATA,

3

lib/reducers/cells.d.ts
import { RankedTester } from '../testers';
import { AddCellRendererAction, RemoveCellRendererAction } from '../actions';
import { Reducer } from '../util/type';
declare type ValidCellReducerActions = AddCellRendererAction | RemoveCellRendererAction;

@@ -9,3 +10,3 @@ export declare type JsonFormsCellRendererRegistryState = JsonFormsCellRendererRegistryEntry[];

}
export declare const cellReducer: (state: JsonFormsCellRendererRegistryState, { type, tester, cell }: ValidCellReducerActions) => JsonFormsCellRendererRegistryState;
export declare const cellReducer: Reducer<JsonFormsCellRendererRegistryState, ValidCellReducerActions>;
export {};
import { SetConfigAction } from '../actions';
export declare const configReducer: (state: any, action: SetConfigAction) => any;
import { Reducer } from '../util/type';
export declare const configReducer: Reducer<any, SetConfigAction>;
import { Ajv, ErrorObject, ValidateFunction } from 'ajv';
import RefParser from 'json-schema-ref-parser';
import { CoreActions } from '../actions';
import { Reducer } from '../util/type';
import { JsonSchema, UISchemaElement } from '..';

@@ -17,3 +18,3 @@ export declare const sanitizeErrors: (validator: ValidateFunction, data: any) => ErrorObject[];

}
export declare const coreReducer: (state: JsonFormsCore, action: CoreActions) => JsonFormsCore;
export declare const coreReducer: Reducer<JsonFormsCore, CoreActions>;
export declare const extractData: (state: JsonFormsCore) => any;

@@ -20,0 +21,0 @@ export declare const extractSchema: (state: JsonFormsCore) => JsonSchema;

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

};
// tslint:disable-next-line: cyclomatic-complexity
exports.coreReducer = function (state, action) {

@@ -131,2 +132,32 @@ if (state === void 0) { state = initState; }

}
case actions_1.UPDATE_CORE: {
var thisAjv = getOrCreateAjv(state, action);
var refParserOptions = getRefParserOptions(state, action);
var validationMode = getValidationMode(state, action);
var validator = state.validator;
var errors = state.errors;
if (state.schema !== action.schema ||
state.validationMode !== validationMode ||
state.ajv !== thisAjv) {
// revalidate only if necessary
validator =
validationMode === 'NoValidation'
? alwaysValid
: thisAjv.compile(action.schema);
errors = exports.sanitizeErrors(validator, action.data);
}
else if (state.data !== action.data) {
errors = exports.sanitizeErrors(validator, action.data);
}
var stateChanged = state.data !== action.data ||
state.schema !== action.schema ||
state.uischema !== action.uischema ||
state.ajv !== thisAjv ||
state.errors !== errors ||
state.validator !== validator ||
state.refParserOptions !== refParserOptions ||
state.validationMode !== validationMode;
return stateChanged
? tslib_1.__assign(tslib_1.__assign({}, state), { data: state.data === action.data ? state.data : action.data, schema: state.schema === action.schema ? state.schema : action.schema, uischema: state.uischema === action.uischema ? state.uischema : action.uischema, ajv: thisAjv === state.ajv ? state.ajv : thisAjv, errors: isEqual_1.default(errors, state.errors) ? state.errors : errors, validator: validator === state.validator ? state.validator : validator, refParserOptions: refParserOptions === state.refParserOptions ? state.refParserOptions : refParserOptions, validationMode: validationMode === state.validationMode ? state.validationMode : validationMode }) : state;
}
case actions_1.SET_AJV: {

@@ -144,3 +175,4 @@ var currentAjv = action.ajv;

: state.validator;
return tslib_1.__assign(tslib_1.__assign({}, state), { validator: v, schema: action.schema });
var errors = exports.sanitizeErrors(v, state.data);
return tslib_1.__assign(tslib_1.__assign({}, state), { validator: v, schema: action.schema, errors: errors });
}

@@ -147,0 +179,0 @@ case actions_1.SET_UISCHEMA: {

import { RegisterDefaultDataAction, UnregisterDefaultDataAction } from '../actions';
import { Reducer } from '../util/type';
export interface JsonFormsDefaultDataRegistryEntry {

@@ -7,4 +8,4 @@ schemaPath: string;

declare type ValidDefaultDataActions = RegisterDefaultDataAction | UnregisterDefaultDataAction;
export declare const defaultDataReducer: (state: JsonFormsDefaultDataRegistryEntry[], action: ValidDefaultDataActions) => JsonFormsDefaultDataRegistryEntry[];
export declare const defaultDataReducer: Reducer<JsonFormsDefaultDataRegistryEntry[], ValidDefaultDataActions>;
export declare const extractDefaultData: (state: JsonFormsDefaultDataRegistryEntry[]) => JsonFormsDefaultDataRegistryEntry[];
export {};
import { JsonSchema, UISchemaElement } from '..';
import { Reducer } from '../util/type';
export interface JsonFormsLocaleState {

@@ -7,17 +8,5 @@ locale?: string;

}
export declare const i18nReducer: (state: JsonFormsLocaleState, action: any) => {
localizedSchemas: any;
locale?: string;
localizedUISchemas: Map<string, UISchemaElement>;
} | {
localizedUISchemas: any;
locale?: string;
localizedSchemas: Map<string, JsonSchema>;
} | {
locale: any;
localizedSchemas: Map<string, JsonSchema>;
localizedUISchemas: Map<string, UISchemaElement>;
};
export declare const i18nReducer: Reducer<any, any>;
export declare const fetchLocale: (state?: JsonFormsLocaleState) => string;
export declare const findLocalizedSchema: (locale: string) => (state?: JsonFormsLocaleState) => JsonSchema;
export declare const findLocalizedUISchema: (locale: string) => (state?: JsonFormsLocaleState) => UISchemaElement;
import { ControlElement, UISchemaElement } from '../models/uischema';
import { JsonFormsCore, coreReducer, errorsAt, ValidationMode } from './core';
import { coreReducer, errorsAt, JsonFormsCore, ValidationMode } from './core';
import { JsonFormsDefaultDataRegistryEntry } from './default-data';
import { JsonFormsRendererRegistryEntry, rendererReducer } from './renderers';
import { JsonFormsState, JsonFormsSubStates } from '../store';
import { Reducer } from 'redux';
import { UISchemaTester, findMatchingUISchema, uischemaRegistryReducer } from './uischemas';
import { JsonFormsState } from '../store';
import { findMatchingUISchema, JsonFormsUISchemaRegistryEntry, uischemaRegistryReducer, UISchemaTester } from './uischemas';
import { i18nReducer } from './i18n';

@@ -15,5 +14,13 @@ import { JsonFormsCellRendererRegistryEntry } from './cells';

import { Ajv } from 'ajv';
export { rendererReducer, cellReducer, coreReducer, i18nReducer, configReducer, UISchemaTester, uischemaRegistryReducer, findMatchingUISchema };
export { rendererReducer, cellReducer, coreReducer, i18nReducer, configReducer, UISchemaTester, uischemaRegistryReducer, findMatchingUISchema, JsonFormsUISchemaRegistryEntry };
export { JsonFormsCore, ValidationMode };
export declare const jsonformsReducer: (additionalReducers?: {}) => Reducer<JsonFormsSubStates, import("redux").AnyAction>;
export declare const jsonFormsReducerConfig: {
core: import("..").Reducer<JsonFormsCore, import("..").CoreActions>;
renderers: import("..").Reducer<JsonFormsRendererRegistryEntry[], import("..").AddRendererAction | import("..").RemoveRendererAction>;
cells: import("..").Reducer<import("./cells").JsonFormsCellRendererRegistryState, import("..").AddCellRendererAction | import("..").RemoveCellRendererAction>;
config: import("..").Reducer<any, import("..").SetConfigAction>;
uischemas: import("..").Reducer<JsonFormsUISchemaRegistryEntry[], import("..").UISchemaActions>;
defaultData: import("..").Reducer<JsonFormsDefaultDataRegistryEntry[], import("..").RegisterDefaultDataAction | import("..").UnregisterDefaultDataAction>;
i18n: import("..").Reducer<any, any>;
};
export declare const getData: (state: JsonFormsState) => any;

@@ -27,2 +34,3 @@ export declare const getSchema: (state: JsonFormsState) => JsonSchema;

export declare const getCells: (state: JsonFormsState) => JsonFormsCellRendererRegistryEntry[];
export declare const getUISchemas: (state: JsonFormsState) => JsonFormsUISchemaRegistryEntry[];
/**

@@ -36,6 +44,3 @@ * Finds a registered UI schema to use, if any.

*/
export declare const findUISchema: (uischemas: {
tester: UISchemaTester;
uischema: UISchemaElement;
}[], schema: JsonSchema, schemaPath: string, path: string, fallbackLayoutType?: string, control?: ControlElement, rootSchema?: JsonSchema) => UISchemaElement;
export declare const findUISchema: (uischemas: JsonFormsUISchemaRegistryEntry[], schema: JsonSchema, schemaPath: string, path: string, fallbackLayoutType?: string, control?: ControlElement, rootSchema?: JsonSchema) => UISchemaElement;
export declare const getErrorAt: (instancePath: string, schema: JsonSchema) => (state: JsonFormsState) => import("ajv").ErrorObject[];

@@ -42,0 +47,0 @@ export { errorsAt };

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

var default_data_1 = require("./default-data");
var default_data_2 = require("../reducers/default-data");
var renderers_1 = require("./renderers");
exports.rendererReducer = renderers_1.rendererReducer;
var redux_1 = require("redux");
var uischemas_1 = require("./uischemas");

@@ -23,5 +23,10 @@ exports.findMatchingUISchema = uischemas_1.findMatchingUISchema;

var get_1 = tslib_1.__importDefault(require("lodash/get"));
exports.jsonformsReducer = function (additionalReducers) {
if (additionalReducers === void 0) { additionalReducers = {}; }
return redux_1.combineReducers(tslib_1.__assign({ core: core_1.coreReducer, renderers: renderers_1.rendererReducer, cells: cells_1.cellReducer, config: config_1.configReducer, uischemas: uischemas_1.uischemaRegistryReducer, defaultData: default_data_1.defaultDataReducer, i18n: i18n_1.i18nReducer }, additionalReducers));
exports.jsonFormsReducerConfig = {
core: core_1.coreReducer,
renderers: renderers_1.rendererReducer,
cells: cells_1.cellReducer,
config: config_1.configReducer,
uischemas: uischemas_1.uischemaRegistryReducer,
defaultData: default_data_2.defaultDataReducer,
i18n: i18n_1.i18nReducer
};

@@ -46,2 +51,3 @@ exports.getData = function (state) {

exports.getCells = function (state) { return get_1.default(state, 'jsonforms.cells'); };
exports.getUISchemas = function (state) { return get_1.default(state, 'jsonforms.uischemas'); };
/**

@@ -48,0 +54,0 @@ * Finds a registered UI schema to use, if any.

import { RankedTester } from '../testers';
import { AddRendererAction, RemoveRendererAction } from '../actions';
import { Reducer } from '../util/type';
export interface JsonFormsRendererRegistryEntry {

@@ -8,3 +9,3 @@ tester: RankedTester;

declare type ValidRendererReducerActions = AddRendererAction | RemoveRendererAction;
export declare const rendererReducer: (state: JsonFormsRendererRegistryEntry[], action: ValidRendererReducerActions) => JsonFormsRendererRegistryEntry[];
export declare const rendererReducer: Reducer<JsonFormsRendererRegistryEntry[], ValidRendererReducerActions>;
export {};
import { UISchemaActions } from '../actions';
import { JsonSchema, UISchemaElement } from '..';
import { Reducer } from '../util/type';
export declare type UISchemaTester = (schema: JsonSchema, schemaPath: string, path: string) => number;
export declare const uischemaRegistryReducer: (state: {
export interface JsonFormsUISchemaRegistryEntry {
tester: UISchemaTester;
uischema: UISchemaElement;
}[], action: UISchemaActions) => {
tester: UISchemaTester;
uischema: UISchemaElement;
}[];
export declare const findMatchingUISchema: (state: {
tester: UISchemaTester;
uischema: UISchemaElement;
}[]) => (jsonSchema: JsonSchema, schemaPath: string, path: string) => UISchemaElement;
}
export declare const uischemaRegistryReducer: Reducer<JsonFormsUISchemaRegistryEntry[], UISchemaActions>;
export declare const findMatchingUISchema: (state: JsonFormsUISchemaRegistryEntry[]) => (jsonSchema: JsonSchema, schemaPath: string, path: string) => UISchemaElement;

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

import { Store } from 'redux';
import { Store } from './util';
import { JsonFormsCore } from './reducers/core';

@@ -6,4 +6,3 @@ import { JsonFormsCellRendererRegistryEntry } from './reducers/cells';

import { JsonFormsLocaleState } from './reducers/i18n';
import { UISchemaTester } from './reducers/uischemas';
import { UISchemaElement } from './models/uischema';
import { JsonFormsUISchemaRegistryEntry } from './reducers/uischemas';
/**

@@ -47,6 +46,3 @@ * JSONForms store.

*/
uischemas?: {
tester: UISchemaTester;
uischema: UISchemaElement;
}[];
uischemas?: JsonFormsUISchemaRegistryEntry[];
/**

@@ -53,0 +49,0 @@ * If true, sets all controls to read-only.

@@ -1,5 +0,4 @@

import { OwnPropsOfControl, OwnPropsOfEnum, StatePropsOfScopedRenderer } from '.';
import { AnyAction, Dispatch, OwnPropsOfControl, OwnPropsOfEnum, StatePropsOfScopedRenderer } from '.';
import { DispatchPropsOfControl } from './renderer';
import { JsonFormsState } from '../store';
import { AnyAction, Dispatch } from 'redux';
import { JsonFormsCellRendererRegistryEntry } from '../reducers/cells';

@@ -6,0 +5,0 @@ import { JsonSchema } from '..';

import { JsonSchema } from '../models/jsonSchema';
import { ControlElement, UISchemaElement } from '../models/uischema';
import { UISchemaTester } from '../reducers';
import { JsonFormsUISchemaRegistryEntry } from '../reducers/uischemas';
export interface CombinatorSubSchemaRenderInfo {

@@ -11,5 +11,2 @@ schema: JsonSchema;

export declare const resolveSubSchemas: (schema: JsonSchema, rootSchema: JsonSchema, keyword: CombinatorKeyword) => JsonSchema;
export declare const createCombinatorRenderInfos: (combinatorSubSchemas: JsonSchema[], rootSchema: JsonSchema, keyword: CombinatorKeyword, control: ControlElement, path: string, uischemas: {
tester: UISchemaTester;
uischema: UISchemaElement;
}[]) => CombinatorSubSchemaRenderInfo[];
export declare const createCombinatorRenderInfos: (combinatorSubSchemas: JsonSchema[], rootSchema: JsonSchema, keyword: CombinatorKeyword, control: ControlElement, path: string, uischemas: JsonFormsUISchemaRegistryEntry[]) => CombinatorSubSchemaRenderInfo[];

@@ -48,1 +48,2 @@ import { JsonSchema, Scopable, UISchemaElement } from '../';

export * from './array';
export * from './type';
import { ControlElement, UISchemaElement } from '../models/uischema';
import { UISchemaTester } from '../reducers';
import { RankedTester } from '../testers';
import { JsonSchema } from '../models/jsonSchema';
import { AnyAction, Dispatch } from '../util';
import { CoreActions } from '../actions';
import { ErrorObject } from 'ajv';
import { JsonFormsState } from '../store';
import { AnyAction, Dispatch } from 'redux';
import { JsonFormsRendererRegistryEntry } from '../reducers/renderers';
import { JsonFormsCellRendererRegistryEntry } from '../reducers/cells';
import { JsonFormsUISchemaRegistryEntry } from '../reducers/uischemas';
export { JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry };

@@ -75,2 +75,3 @@ export interface Labels {

cells?: JsonFormsCellRendererRegistryEntry[];
uischemas?: JsonFormsUISchemaRegistryEntry[];
}

@@ -257,6 +258,3 @@ export interface OwnPropsOfControl extends OwnPropsOfRenderer {

export interface StatePropsOfControlWithDetail extends StatePropsOfControl {
uischemas?: {
tester: UISchemaTester;
uischema: UISchemaElement;
}[];
uischemas?: JsonFormsUISchemaRegistryEntry[];
renderers?: JsonFormsRendererRegistryEntry[];

@@ -356,6 +354,3 @@ cells?: JsonFormsCellRendererRegistryEntry[];

indexOfFittingSchema: number;
uischemas: {
tester: UISchemaTester;
uischema: UISchemaElement;
}[];
uischemas: JsonFormsUISchemaRegistryEntry[];
data: any;

@@ -362,0 +357,0 @@ }

{
"name": "@jsonforms/core",
"version": "2.4.1",
"version": "2.5.0-alpha.0",
"description": "Core module of JSON Forms",

@@ -71,5 +71,2 @@ "repository": "https://github.com/eclipsesource/jsonforms",

},
"peerDependencies": {
"redux": "^4.0.4"
},
"devDependencies": {

@@ -87,3 +84,3 @@ "@istanbuljs/nyc-config-typescript": "0.1.3",

},
"gitHead": "fac1ef6254299925fc53e941eee76fb96619925b"
"gitHead": "a648f46ca842330a38731fb497bc126d9fbd4712"
}

@@ -35,2 +35,3 @@ /*

export const INIT: 'jsonforms/INIT' = 'jsonforms/INIT';
export const UPDATE_CORE: 'jsonforms/UPDATE_CORE' = `jsonforms/UPDATE_CORE`;
export const SET_AJV: 'jsonforms/SET_AJV' = 'jsonforms/SET_AJV';

@@ -65,2 +66,3 @@ export const UPDATE_DATA: 'jsonforms/UPDATE' = 'jsonforms/UPDATE';

| InitAction
| UpdateCoreAction
| UpdateAction

@@ -92,2 +94,10 @@ | UpdateErrorsAction

export interface UpdateCoreAction {
type: 'jsonforms/UPDATE_CORE';
data?: any;
schema?: JsonSchema;
uischema?: UISchemaElement;
options?: InitActionOptions | AJV.Ajv;
}
export interface InitActionOptions {

@@ -118,2 +128,15 @@ ajv?: AJV.Ajv;

export const updateCore = (
data: any,
schema: JsonSchema,
uischema?: UISchemaElement,
options?: AJV.Ajv | InitActionOptions
): UpdateCoreAction => ({
type: UPDATE_CORE,
data,
schema,
uischema,
options
});
export interface RegisterDefaultDataAction {

@@ -120,0 +143,0 @@ type: 'jsonforms/ADD_DEFAULT_DATA';

@@ -32,2 +32,3 @@ /*

} from '../actions';
import { Reducer } from '../util/type';

@@ -43,5 +44,5 @@ type ValidCellReducerActions = AddCellRendererAction | RemoveCellRendererAction;

export const cellReducer = (
state: JsonFormsCellRendererRegistryState = [],
{ type, tester, cell }: ValidCellReducerActions
export const cellReducer: Reducer<JsonFormsCellRendererRegistryState, ValidCellReducerActions> = (
state = [],
{ type, tester, cell }
) => {

@@ -48,0 +49,0 @@ switch (type) {

@@ -28,2 +28,3 @@ /*

import { configDefault } from '../configDefault';
import { Reducer } from '../util/type';

@@ -33,5 +34,5 @@ const applyDefaultConfiguration = (config: any = {}) =>

export const configReducer = (
export const configReducer: Reducer<any, SetConfigAction> = (
state = applyDefaultConfiguration(),
action: SetConfigAction
action
) => {

@@ -38,0 +39,0 @@ switch (action.type) {

@@ -34,2 +34,3 @@ /*

import {
CoreActions,
INIT,

@@ -41,8 +42,10 @@ InitAction,

SET_UISCHEMA,
SET_VALIDATION_MODE,
UPDATE_DATA,
UPDATE_ERRORS,
CoreActions,
SET_VALIDATION_MODE
UPDATE_CORE,
UpdateCoreAction
} from '../actions';
import { createAjv } from '../util/validator';
import { Reducer } from '../util/type';
import { JsonSchema, UISchemaElement } from '..';

@@ -103,3 +106,3 @@

const getOrCreateAjv = (state: JsonFormsCore, action?: InitAction): Ajv => {
const getOrCreateAjv = (state: JsonFormsCore, action?: InitAction | UpdateCoreAction): Ajv => {
if (action) {

@@ -129,3 +132,3 @@ if (hasAjvOption(action.options)) {

state: JsonFormsCore,
action?: InitAction
action?: InitAction | UpdateCoreAction
): RefParser.Options => {

@@ -154,3 +157,3 @@ if (action && hasRefParserOption(action.options)) {

state: JsonFormsCore,
action?: InitAction
action?: InitAction | UpdateCoreAction
): ValidationMode => {

@@ -170,6 +173,7 @@ if (action && hasValidationModeOption(action.options)) {

export const coreReducer = (
state: JsonFormsCore = initState,
action: CoreActions
): JsonFormsCore => {
// tslint:disable-next-line: cyclomatic-complexity
export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
state = initState,
action
) => {
switch (action.type) {

@@ -196,2 +200,46 @@ case INIT: {

}
case UPDATE_CORE: {
const thisAjv = getOrCreateAjv(state, action);
const refParserOptions = getRefParserOptions(state, action);
const validationMode = getValidationMode(state, action);
let validator = state.validator;
let errors = state.errors;
if (
state.schema !== action.schema ||
state.validationMode !== validationMode ||
state.ajv !== thisAjv
) {
// revalidate only if necessary
validator =
validationMode === 'NoValidation'
? alwaysValid
: thisAjv.compile(action.schema);
errors = sanitizeErrors(validator, action.data);
} else if (state.data !== action.data) {
errors = sanitizeErrors(validator, action.data);
}
const stateChanged =
state.data !== action.data ||
state.schema !== action.schema ||
state.uischema !== action.uischema ||
state.ajv !== thisAjv ||
state.errors !== errors ||
state.validator !== validator ||
state.refParserOptions !== refParserOptions ||
state.validationMode !== validationMode;
return stateChanged
? {
...state,
data: state.data === action.data ? state.data : action.data,
schema: state.schema === action.schema ? state.schema : action.schema,
uischema: state.uischema === action.uischema ? state.uischema : action.uischema,
ajv: thisAjv === state.ajv ? state.ajv : thisAjv,
errors: isEqual(errors, state.errors) ? state.errors : errors,
validator: validator === state.validator ? state.validator : validator,
refParserOptions: refParserOptions === state.refParserOptions ? state.refParserOptions : refParserOptions,
validationMode: validationMode === state.validationMode ? state.validationMode : validationMode
}
: state;
}
case SET_AJV: {

@@ -212,6 +260,8 @@ const currentAjv = action.ajv;

: state.validator;
const errors = sanitizeErrors(v, state.data);
return {
...state,
validator: v,
schema: action.schema
schema: action.schema,
errors
};

@@ -218,0 +268,0 @@ }

@@ -31,2 +31,3 @@ /*

} from '../actions';
import { Reducer } from '../util/type';

@@ -42,5 +43,5 @@ export interface JsonFormsDefaultDataRegistryEntry {

export const defaultDataReducer = (
state: JsonFormsDefaultDataRegistryEntry[] = [],
action: ValidDefaultDataActions
export const defaultDataReducer: Reducer<JsonFormsDefaultDataRegistryEntry[], ValidDefaultDataActions> = (
state = [],
action
) => {

@@ -47,0 +48,0 @@ switch (action.type) {

@@ -27,2 +27,3 @@ /*

import { JsonSchema, SET_LOCALIZED_UISCHEMAS, UISchemaElement } from '..';
import { Reducer } from '../util/type';

@@ -41,3 +42,3 @@ export interface JsonFormsLocaleState {

export const i18nReducer = (state = initState, action: any) => {
export const i18nReducer: Reducer<any, any> = (state = initState, action) => {
switch (action.type) {

@@ -44,0 +45,0 @@ case SET_LOCALIZED_SCHEMAS:

@@ -27,3 +27,2 @@ /*

import {
JsonFormsCore,
coreReducer,

@@ -37,2 +36,3 @@ errorAt,

extractUiSchema,
JsonFormsCore,
subErrorsAt,

@@ -42,13 +42,13 @@ ValidationMode

import {
JsonFormsDefaultDataRegistryEntry,
defaultDataReducer,
extractDefaultData
extractDefaultData,
JsonFormsDefaultDataRegistryEntry
} from './default-data';
import { defaultDataReducer } from '../reducers/default-data';
import { JsonFormsRendererRegistryEntry, rendererReducer } from './renderers';
import { JsonFormsState, JsonFormsSubStates } from '../store';
import { Reducer, combineReducers } from 'redux';
import { JsonFormsState } from '../store';
import {
UISchemaTester,
findMatchingUISchema,
uischemaRegistryReducer
JsonFormsUISchemaRegistryEntry,
uischemaRegistryReducer,
UISchemaTester
} from './uischemas';

@@ -80,19 +80,16 @@ import {

uischemaRegistryReducer,
findMatchingUISchema
findMatchingUISchema,
JsonFormsUISchemaRegistryEntry
};
export { JsonFormsCore, ValidationMode };
export const jsonformsReducer = (
additionalReducers = {}
): Reducer<JsonFormsSubStates> =>
combineReducers<JsonFormsSubStates>({
core: coreReducer,
renderers: rendererReducer,
cells: cellReducer,
config: configReducer,
uischemas: uischemaRegistryReducer,
defaultData: defaultDataReducer,
i18n: i18nReducer,
...additionalReducers
});
export const jsonFormsReducerConfig = {
core: coreReducer,
renderers: rendererReducer,
cells: cellReducer,
config: configReducer,
uischemas: uischemaRegistryReducer,
defaultData: defaultDataReducer,
i18n: i18nReducer
};

@@ -120,2 +117,6 @@ export const getData = (state: JsonFormsState) =>

): JsonFormsCellRendererRegistryEntry[] => get(state, 'jsonforms.cells');
export const getUISchemas = (
state: JsonFormsState
): JsonFormsUISchemaRegistryEntry[] => get(state, 'jsonforms.uischemas');
/**

@@ -130,3 +131,3 @@ * Finds a registered UI schema to use, if any.

export const findUISchema = (
uischemas: { tester: UISchemaTester; uischema: UISchemaElement }[],
uischemas: JsonFormsUISchemaRegistryEntry[],
schema: JsonSchema,

@@ -133,0 +134,0 @@ schemaPath: string,

@@ -32,2 +32,3 @@ /*

} from '../actions';
import { Reducer } from '../util/type';

@@ -41,5 +42,5 @@ export interface JsonFormsRendererRegistryEntry {

export const rendererReducer = (
state: JsonFormsRendererRegistryEntry[] = [],
action: ValidRendererReducerActions
export const rendererReducer: Reducer<JsonFormsRendererRegistryEntry[], ValidRendererReducerActions> = (
state = [],
action
) => {

@@ -46,0 +47,0 @@ switch (action.type) {

@@ -29,2 +29,3 @@ /*

import { JsonSchema, NOT_APPLICABLE, UISchemaElement } from '..';
import { Reducer } from '../util/type';

@@ -37,5 +38,10 @@ export type UISchemaTester = (

export const uischemaRegistryReducer = (
state: { tester: UISchemaTester; uischema: UISchemaElement }[] = [],
action: UISchemaActions
export interface JsonFormsUISchemaRegistryEntry {
tester: UISchemaTester;
uischema: UISchemaElement;
}
export const uischemaRegistryReducer: Reducer<JsonFormsUISchemaRegistryEntry[], UISchemaActions> = (
state = [],
action
) => {

@@ -57,3 +63,3 @@ switch (action.type) {

export const findMatchingUISchema = (
state: { tester: UISchemaTester; uischema: UISchemaElement }[]
state: JsonFormsUISchemaRegistryEntry[]
) => (

@@ -60,0 +66,0 @@ jsonSchema: JsonSchema,

@@ -25,3 +25,3 @@ /*

*/
import { Store } from 'redux';
import { Store } from './util';
import { JsonFormsCore } from './reducers/core';

@@ -31,4 +31,3 @@ import { JsonFormsCellRendererRegistryEntry } from './reducers/cells';

import { JsonFormsLocaleState } from './reducers/i18n';
import { UISchemaTester } from './reducers/uischemas';
import { UISchemaElement } from './models/uischema';
import { JsonFormsUISchemaRegistryEntry } from './reducers/uischemas';

@@ -74,3 +73,3 @@ /**

*/
uischemas?: { tester: UISchemaTester; uischema: UISchemaElement }[];
uischemas?: JsonFormsUISchemaRegistryEntry[];
/**

@@ -77,0 +76,0 @@ * If true, sets all controls to read-only.

@@ -29,2 +29,4 @@ /*

import {
AnyAction,
Dispatch,
formatErrorMessage,

@@ -45,3 +47,2 @@ isEnabled,

import { JsonFormsState } from '../store';
import { AnyAction, Dispatch } from 'redux';
import { JsonFormsCellRendererRegistryEntry } from '../reducers/cells';

@@ -48,0 +49,0 @@ import { JsonSchema } from '..';

@@ -29,3 +29,4 @@ /*

import { resolveSchema } from './resolvers';
import { findUISchema, UISchemaTester } from '../reducers';
import { findUISchema } from '../reducers';
import { JsonFormsUISchemaRegistryEntry } from '../reducers/uischemas';

@@ -76,3 +77,3 @@ export interface CombinatorSubSchemaRenderInfo {

path: string,
uischemas: { tester: UISchemaTester; uischema: UISchemaElement }[]
uischemas: JsonFormsUISchemaRegistryEntry[]
): CombinatorSubSchemaRenderInfo[] =>

@@ -79,0 +80,0 @@ combinatorSubSchemas.map((subSchema, subSchemaIndex) => ({

@@ -154,1 +154,2 @@ /*

export * from './array';
export * from './type';

@@ -41,4 +41,3 @@ /*

getSubErrorsAt,
getUiSchema,
UISchemaTester
getUiSchema
} from '../reducers';

@@ -48,2 +47,3 @@ import { RankedTester } from '../testers';

import {
AnyAction,
CombinatorKeyword,

@@ -53,2 +53,3 @@ composePaths,

createLabelDescriptionFrom,
Dispatch,
formatErrorMessage,

@@ -64,8 +65,8 @@ hasEnableRule,

} from '../util';
import { update, CoreActions } from '../actions';
import { CoreActions, update } from '../actions';
import { ErrorObject } from 'ajv';
import { JsonFormsState } from '../store';
import { AnyAction, Dispatch } from 'redux';
import { JsonFormsRendererRegistryEntry } from '../reducers/renderers';
import { JsonFormsCellRendererRegistryEntry } from '../reducers/cells';
import { JsonFormsUISchemaRegistryEntry } from '../reducers/uischemas';

@@ -218,2 +219,4 @@ export { JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry };

cells?: JsonFormsCellRendererRegistryEntry[];
uischemas?: JsonFormsUISchemaRegistryEntry[];
}

@@ -542,3 +545,3 @@

export interface StatePropsOfControlWithDetail extends StatePropsOfControl {
uischemas?: { tester: UISchemaTester; uischema: UISchemaElement }[];
uischemas?: JsonFormsUISchemaRegistryEntry[];
renderers?: JsonFormsRendererRegistryEntry[];

@@ -791,3 +794,3 @@ cells?: JsonFormsCellRendererRegistryEntry[];

indexOfFittingSchema: number;
uischemas: { tester: UISchemaTester; uischema: UISchemaElement }[];
uischemas: JsonFormsUISchemaRegistryEntry[];
data: any;

@@ -794,0 +797,0 @@ }

@@ -38,3 +38,3 @@ /*

import { createAjv } from '../../src';
import { createAjv, updateCore } from '../../src';
import { setSchema, setValidationMode } from '../../lib';

@@ -1443,2 +1443,78 @@ import { cloneDeep } from 'lodash';

test('core reducer - update core - state should be unchanged when nothing changes', t => {
const schema = {
type: 'object',
properties: {
animal: {
type: 'string'
}
}
};
const data = {
animal: 'dog'
};
const before: JsonFormsCore = coreReducer(
undefined,
init(data, schema)
);
const after: JsonFormsCore = coreReducer(
before,
updateCore(before.data, before.schema, before.uischema, before.ajv)
);
t.true(before === after);
});
test('core reducer - update core - unchanged state properties should be unchanged when state changes', t => {
const schema = {
type: 'object',
properties: {
animal: {
type: 'string'
}
}
};
const data = {
animal: 'dog'
};
const before: JsonFormsCore = coreReducer(
undefined,
init(data, schema)
);
const afterDataUpdate: JsonFormsCore = coreReducer(
before,
updateCore({
animal: 'cat'
}, before.schema, before.uischema, before.ajv)
);
t.true(before.schema === afterDataUpdate.schema);
t.true(before.ajv === afterDataUpdate.ajv);
t.true(before.errors === afterDataUpdate.errors);
t.true(before.refParserOptions === afterDataUpdate.refParserOptions);
t.true(before.uischema === afterDataUpdate.uischema);
t.true(before.validationMode === afterDataUpdate.validationMode);
t.true(before.validator === afterDataUpdate.validator);
const updatedSchema = {
type: 'object',
properties: {
animal: {
type: 'string'
},
id: {
type: 'number'
}
}
};
// check that data stays unchanged as well
const afterSchemaUpdate : JsonFormsCore = coreReducer(
before,
updateCore(before.data, updatedSchema, before.uischema, before.ajv)
);
t.true(before.data === afterSchemaUpdate.data);
});
test('core reducer - setSchema - schema with id', t => {

@@ -1445,0 +1521,0 @@ const schema: JsonSchema = {

@@ -46,3 +46,6 @@ /*

ControlElement,
CoreActions,
coreReducer,
Dispatch,
JsonFormsCore,
JsonFormsState,

@@ -54,5 +57,3 @@ JsonSchema,

} from '../../src';
import { jsonformsReducer } from '../../src/reducers';
import { ErrorObject } from 'ajv';
import { combineReducers, createStore, Store } from 'redux';
import { setValidationMode } from '../../lib';

@@ -63,2 +64,14 @@

const mockDispatch = (
initialCore: JsonFormsCore
): [() => JsonFormsCore, Dispatch<CoreActions>] => {
const coreContainer = { core: initialCore };
const dispatch: Dispatch<CoreActions> = <T extends CoreActions> (action: T) : T => {
coreContainer.core = coreReducer(coreContainer.core, action);
return action;
};
const getCore = () => coreContainer.core;
return [getCore, dispatch];
};
const hideRule = {

@@ -559,20 +572,13 @@ effect: RuleEffect.HIDE,

};
const initState: JsonFormsState = {
jsonforms: {
core: {
uischema,
schema,
data,
errors: [] as ErrorObject[]
}
}
const initCore: JsonFormsCore = {
uischema,
schema,
data,
errors: [] as ErrorObject[]
};
const store: Store<JsonFormsState> = createStore(
combineReducers<JsonFormsState>({ jsonforms: jsonformsReducer() }),
initState
);
store.dispatch(init(data, schema, uischema));
const props = mapDispatchToArrayControlProps(store.dispatch);
const [getCore, dispatch] = mockDispatch(initCore);
dispatch(init(data, schema, uischema));
const props = mapDispatchToArrayControlProps(dispatch);
props.addItem('', createDefaultValue(schema))();
t.is(store.getState().jsonforms.core.data.length, 2);
t.is(getCore().data.length, 2);
});

@@ -592,19 +598,14 @@

};
const initState: JsonFormsState = {
jsonforms: {
core: {
uischema,
schema,
data,
errors: [] as ErrorObject[]
}
}
const initCore: JsonFormsCore = {
uischema,
schema,
data,
errors: [] as ErrorObject[]
};
const reducer = combineReducers({ jsonforms: jsonformsReducer() });
const store: Store<JsonFormsState> = createStore(reducer, initState);
store.dispatch(init(data, schema, uischema));
const props = mapDispatchToArrayControlProps(store.dispatch);
const [getCore, dispatch] = mockDispatch(initCore);
dispatch(init(data, schema, uischema));
const props = mapDispatchToArrayControlProps(dispatch);
props.removeItems('', [0, 1])();
t.is(store.getState().jsonforms.core.data.length, 1);
t.is(store.getState().jsonforms.core.data[0], 'quux');
t.is(getCore().data.length, 1);
t.is(getCore().data[0], 'quux');
});

@@ -893,9 +894,4 @@

};
const reducer = combineReducers({ jsonforms: jsonformsReducer() });
const store: Store<JsonFormsState> = createStore(reducer, initState);
store.dispatch(
init(data, schema, uischema, createAjv({ useDefaults: true }))
);
t.is(store.getState().jsonforms.core.data.color, 'green');
const newCore = coreReducer(initState.jsonforms.core, init(data, schema, uischema, createAjv({ useDefaults: true })));
t.is(newCore.data.color, 'green');
});

@@ -934,10 +930,6 @@

};
const reducer = combineReducers({ jsonforms: jsonformsReducer() });
const store: Store<JsonFormsState> = createStore(reducer, initState);
store.dispatch(
init(data, schema, uischema, createAjv({ useDefaults: true }))
);
t.is(store.getState().jsonforms.core.data.length, 1);
t.deepEqual(store.getState().jsonforms.core.data[0], { message: 'foo' });
const newCore = coreReducer(initState.jsonforms.core, init(data, schema, uischema, createAjv({ useDefaults: true })));
t.is(newCore.data.length, 1);
t.deepEqual(newCore.data[0], { message: 'foo' });
});

@@ -966,23 +958,15 @@

const initState: JsonFormsState = {
jsonforms: {
core: {
uischema,
schema,
data,
errors: [] as ErrorObject[]
}
}
const initCore: JsonFormsCore = {
uischema,
schema,
data,
errors: [] as ErrorObject[]
};
const reducer = combineReducers({ jsonforms: jsonformsReducer() });
const store: Store<JsonFormsState> = createStore(reducer, initState);
store.dispatch(
init(data, schema, uischema, createAjv({ useDefaults: true }))
);
const props = mapDispatchToArrayControlProps(store.dispatch);
const [getCore, dispatch] = mockDispatch(initCore);
dispatch(init(data, schema, uischema, createAjv({ useDefaults: true })));
const props = mapDispatchToArrayControlProps(dispatch);
props.addItem('', createDefaultValue(schema))();
t.is(store.getState().jsonforms.core.data.length, 2);
t.deepEqual(store.getState().jsonforms.core.data[0], { message: 'foo' });
t.is(getCore().data.length, 2);
t.deepEqual(getCore().data[0], { message: 'foo' });
});

@@ -989,0 +973,0 @@

Sorry, the diff of this file is too big to display

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

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

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

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

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

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

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

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

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

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

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