Socket
Socket
Sign inDemoInstall

@jsonforms/core

Package Overview
Dependencies
Maintainers
6
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 3.4.0-alpha.0 to 3.4.0-alpha.1

lib/i18n/selectors.d.ts

7

lib/actions/actions.d.ts
import type AJV from 'ajv';
import type { ErrorObject } from 'ajv';
import type { JsonSchema, UISchemaElement } from '../models';
import type { RankedTester } from '../testers';
import type { UISchemaTester, ValidationMode } from '../reducers';
import type { ErrorTranslator, Translator } from '../i18n';
import { JsonSchema, UISchemaElement } from '../models';
import { RankedTester, UISchemaTester } from '../testers';
import { ErrorTranslator, Translator, ValidationMode } from '../store';
export declare const INIT: "jsonforms/INIT";

@@ -8,0 +7,0 @@ export declare const UPDATE_CORE: "jsonforms/UPDATE_CORE";

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

import type { ControlElement, JsonSchema, UISchemaElement } from '../';
import { ControlElement, JsonSchema, UISchemaElement } from '../models';
export declare const Generate: {

@@ -3,0 +3,0 @@ jsonSchema(instance: Object, options?: any): JsonSchema;

import type { ErrorObject } from 'ajv';
import { Labelable, UISchemaElement } from '../models';
import type { i18nJsonSchema, ErrorTranslator, Translator } from './i18nTypes';
import type { i18nJsonSchema, ErrorTranslator, Translator } from '../store';
import { ArrayDefaultTranslation, ArrayTranslations } from './arrayTranslations';

@@ -5,0 +5,0 @@ import { CombinatorDefaultTranslation, CombinatorTranslations } from './combinatorTranslations';

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

export * from './i18nTypes';
export * from './i18nUtil';
export * from './arrayTranslations';
export * from './combinatorTranslations';
export * from './selectors';
export * from './i18nUtil';

@@ -9,4 +9,4 @@ export * from './actions';

export * from './util';
export * from './Helpers';
export * from './store';
export * from './i18n';
export * from './mappers';

@@ -224,9 +224,1 @@ import type { JsonSchema } from './jsonSchema';

}
export declare const isInternationalized: (element: unknown) => element is Required<Internationalizable>;
export declare const isGroup: (layout: Layout) => layout is GroupLayout;
export declare const isLayout: (uischema: UISchemaElement) => uischema is Layout;
export declare const isScopable: (obj: unknown) => obj is Scopable;
export declare const isScoped: (obj: unknown) => obj is Scoped;
export declare const isLabelable: (obj: unknown) => obj is Labelable<string>;
export declare const isLabeled: <T = never>(obj: unknown) => obj is Labeled<T>;
export declare const isControlElement: (uiSchema: UISchemaElement) => uiSchema is ControlElement;

@@ -1,11 +0,6 @@

import type { RankedTester } from '../testers';
import { AddCellRendererAction, RemoveCellRendererAction } from '../actions';
import type { Reducer } from '../util';
import { JsonFormsCellRendererRegistryEntry, Reducer } from '../store';
type ValidCellReducerActions = AddCellRendererAction | RemoveCellRendererAction;
export type JsonFormsCellRendererRegistryState = JsonFormsCellRendererRegistryEntry[];
export interface JsonFormsCellRendererRegistryEntry {
tester: RankedTester;
cell: any;
}
export declare const cellReducer: Reducer<JsonFormsCellRendererRegistryState, ValidCellReducerActions>;
export {};
import { SetConfigAction } from '../actions';
import type { Reducer } from '../util';
import { Reducer } from '../store';
export declare const configReducer: Reducer<any, SetConfigAction>;

@@ -1,26 +0,8 @@

import type Ajv from 'ajv';
import type { ErrorObject, ValidateFunction } from 'ajv';
import { CoreActions } from '../actions';
import { Reducer } from '../util';
import type { JsonSchema, UISchemaElement } from '../models';
export declare const validate: (validator: ValidateFunction | undefined, data: any) => ErrorObject[];
export type ValidationMode = 'ValidateAndShow' | 'ValidateAndHide' | 'NoValidation';
export interface JsonFormsCore {
data: any;
schema: JsonSchema;
uischema: UISchemaElement;
errors?: ErrorObject[];
additionalErrors?: ErrorObject[];
validator?: ValidateFunction;
ajv?: Ajv;
validationMode?: ValidationMode;
}
import { CoreActions, InitAction, UpdateCoreAction } from '../actions';
import { JsonFormsCore, Reducer, ValidationMode } from '../store';
import Ajv, { ErrorObject } from 'ajv';
export declare const initState: JsonFormsCore;
export declare const getValidationMode: (state: JsonFormsCore, action?: InitAction | UpdateCoreAction) => ValidationMode;
export declare const getAdditionalErrors: (state: JsonFormsCore, action?: InitAction | UpdateCoreAction) => ErrorObject[];
export declare const getOrCreateAjv: (state: JsonFormsCore, action?: InitAction | UpdateCoreAction) => Ajv;
export declare const coreReducer: Reducer<JsonFormsCore, CoreActions>;
export declare const extractData: (state: JsonFormsCore) => any;
export declare const extractSchema: (state: JsonFormsCore) => JsonSchema;
export declare const extractUiSchema: (state: JsonFormsCore) => UISchemaElement;
export declare const extractAjv: (state: JsonFormsCore) => Ajv;
export declare const getControlPath: (error: ErrorObject) => any;
export declare const errorsAt: (instancePath: string, schema: JsonSchema, matchPath: (path: string) => boolean) => (errors: ErrorObject[]) => ErrorObject[];
export declare const errorAt: (instancePath: string, schema: JsonSchema) => (state: JsonFormsCore) => ErrorObject[];
export declare const subErrorsAt: (instancePath: string, schema: JsonSchema) => (state: JsonFormsCore) => ErrorObject[];
import { RegisterDefaultDataAction, UnregisterDefaultDataAction } from '../actions';
import type { Reducer } from '../util';
import type { Reducer } from '../store/type';
import { JsonFormsState } from '../store';
export interface JsonFormsDefaultDataRegistryEntry {

@@ -9,3 +10,4 @@ schemaPath: string;

export declare const defaultDataReducer: Reducer<JsonFormsDefaultDataRegistryEntry[], ValidDefaultDataActions>;
export declare const getDefaultData: (state: JsonFormsState) => JsonFormsDefaultDataRegistryEntry[];
export declare const extractDefaultData: (state: JsonFormsDefaultDataRegistryEntry[]) => JsonFormsDefaultDataRegistryEntry[];
export {};

@@ -1,8 +0,5 @@

import { JsonFormsI18nState } from '../i18n';
import { I18nActions } from '../actions';
import type { Reducer } from '../util';
import { Reducer } from '../store/type';
import { JsonFormsI18nState } from '../store';
export declare const defaultJsonFormsI18nState: Required<JsonFormsI18nState>;
export declare const i18nReducer: Reducer<JsonFormsI18nState, I18nActions>;
export declare const fetchLocale: (state?: JsonFormsI18nState) => string;
export declare const fetchTranslator: (state?: JsonFormsI18nState) => import("../i18n").Translator;
export declare const fetchErrorTranslator: (state?: JsonFormsI18nState) => import("../i18n").ErrorTranslator;

@@ -8,4 +8,3 @@ export * from './cells';

export * from './renderers';
export * from './selectors';
export * from './uischemas';
export * from './middleware';
import { CoreActions } from '../actions';
import { JsonFormsCore } from './core';
import { JsonFormsCore } from '../store';
export interface Middleware {

@@ -4,0 +4,0 @@ (state: JsonFormsCore, action: CoreActions, defaultReducer: (state: JsonFormsCore, action: CoreActions) => JsonFormsCore): JsonFormsCore;

import type { ControlElement, UISchemaElement } from '../models';
import type { JsonFormsState } from '../store';
import type { JsonFormsUISchemaRegistryEntry } from './uischemas';
import type { JsonSchema } from '../models/jsonSchema';
import type { ErrorTranslator, Translator } from '../i18n';
import { JsonFormsUISchemaRegistryEntry } from '../store';
export declare const jsonFormsReducerConfig: {
core: import("..").Reducer<import("./core").JsonFormsCore, import("..").CoreActions>;
renderers: import("..").Reducer<import("./renderers").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<import("./default-data").JsonFormsDefaultDataRegistryEntry[], import("..").RegisterDefaultDataAction | import("..").UnregisterDefaultDataAction>;
i18n: import("..").Reducer<import("../i18n").JsonFormsI18nState, import("..").I18nActions>;
core: import("../store").Reducer<import("../store").JsonFormsCore, import("..").CoreActions>;
renderers: import("../store").Reducer<import("../store").JsonFormsRendererRegistryEntry[], import("..").AddRendererAction | import("..").RemoveRendererAction>;
cells: import("../store").Reducer<import("./cells").JsonFormsCellRendererRegistryState, import("..").AddCellRendererAction | import("..").RemoveCellRendererAction>;
config: import("../store").Reducer<any, import("..").SetConfigAction>;
uischemas: import("../store").Reducer<JsonFormsUISchemaRegistryEntry[], import("..").UISchemaActions>;
defaultData: import("../store").Reducer<import("./default-data").JsonFormsDefaultDataRegistryEntry[], import("..").RegisterDefaultDataAction | import("..").UnregisterDefaultDataAction>;
i18n: import("../store").Reducer<import("../store").JsonFormsI18nState, import("..").I18nActions>;
};

@@ -24,7 +22,1 @@ /**

export declare const findUISchema: (uischemas: JsonFormsUISchemaRegistryEntry[], schema: JsonSchema, schemaPath: string, path: string, fallback?: string | (() => UISchemaElement), control?: ControlElement, rootSchema?: JsonSchema) => UISchemaElement;
export declare const getErrorAt: (instancePath: string, schema: JsonSchema) => (state: JsonFormsState) => import("ajv").ErrorObject<string, Record<string, any>, unknown>[];
export declare const getSubErrorsAt: (instancePath: string, schema: JsonSchema) => (state: JsonFormsState) => import("ajv").ErrorObject<string, Record<string, any>, unknown>[];
export declare const getConfig: (state: JsonFormsState) => any;
export declare const getLocale: (state: JsonFormsState) => string;
export declare const getTranslator: () => (state: JsonFormsState) => Translator;
export declare const getErrorTranslator: () => (state: JsonFormsState) => ErrorTranslator;

@@ -1,10 +0,6 @@

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

@@ -26,2 +26,3 @@ import type { Categorization, ControlElement, JsonSchema, UISchemaElement } from '../models';

}
export type UISchemaTester = (schema: JsonSchema, schemaPath: string, path: string) => number;
export declare const isControl: (uischema: any) => uischema is ControlElement;

@@ -28,0 +29,0 @@ /**

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

export * from './array';
export * from './cell';
export * from './combinators';
export * from './Formatted';

@@ -8,7 +5,5 @@ export * from './ids';

export * from './path';
export * from './renderer';
export * from './resolvers';
export * from './runtime';
export * from './schema';
export * from './type';
export * from './uischema';

@@ -18,1 +13,3 @@ export * from './util';

export * from './defaultDateFormat';
export * from './errors';
export * from './helpers';

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

import { ControlElement, JsonSchema, LabelDescription, UISchemaElement } from '../models';
import { Translator } from '../i18n';
import { ControlElement, JsonSchema, LabelDescription } from '../models';
export declare const createCleanLabel: (label: string) => string;

@@ -11,12 +10,1 @@ /**

export declare const createLabelDescriptionFrom: (withLabel: ControlElement, schema?: JsonSchema) => LabelDescription;
/**
* Compute the child label title for array based controls
* @param data the data of the control
* @param childPath the child path
* @param childLabelProp the dotted path to the value used as child label
* @param {JsonSchema} schema the json schema for this control
* @param {JsonSchema} rootSchema the root json schema
* @param {Translator} translateFct the translator fonction
* @param {UISchemaElement} uiSchema the uiSchema of the control
*/
export declare const computeChildLabel: (data: any, childPath: string, childLabelProp: string, schema: JsonSchema, rootSchema: JsonSchema, translateFct: Translator, uiSchema: UISchemaElement) => string;

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

import { Scopable } from '../models';
export declare const compose: (path1: string, path2: string) => string;

@@ -28,3 +27,2 @@ export { compose as composePaths };

export declare const toDataPath: (schemaPath: string) => string;
export declare const composeWithUi: (scopableUi: Scopable, path: string) => string;
/**

@@ -40,1 +38,7 @@ * Encodes the given segment to be used as part of a JSON Pointer

export declare const decode: (pointerSegment: string) => string;
/**
* Transform a dotted path to a uiSchema properties path
* @param path a dotted prop path to a schema value (i.e. articles.comment.author)
* @return the uiSchema properties path (i.e. /properties/articles/properties/comment/properties/author)
*/
export declare const getPropPath: (path: string) => string;

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

import { JsonSchema, UISchemaElement } from '../models';
import { UISchemaElement } from '../models';
import type Ajv from 'ajv';
import type { JsonFormsState } from '../store';
export declare const evalVisibility: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv) => boolean;

@@ -10,9 +9,1 @@ export declare const evalEnablement: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv) => boolean;

export declare const isEnabled: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv) => boolean;
/**
* Indicates whether the given `uischema` element shall be enabled or disabled.
* Checks the global readonly flag, uischema rule, uischema options (including the config),
* the schema and the enablement indicator of the parent.
*/
export declare const isInherentlyEnabled: (state: JsonFormsState, ownProps: any, uischema: UISchemaElement, schema: (JsonSchema & {
readOnly?: boolean;
}) | undefined, rootData: any, config: any) => any;

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

import { JsonSchema } from '../models';
import type { JsonSchema } from '../models';
export declare const getFirstPrimitiveProp: (schema: any) => string;

@@ -3,0 +3,0 @@ /**

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

import { UISchemaElement } from '../models';
import { ControlElement, GroupLayout, Internationalizable, Labelable, Labeled, Layout, Scopable, Scoped, UISchemaElement } from '../models';
export type IterateCallback = (uischema: UISchemaElement) => void;

@@ -7,8 +7,2 @@ export declare const setReadonly: (uischema: UISchemaElement) => void;

/**
* Transform a dotted path to a uiSchema properties path
* @param path a dotted prop path to a schema value (i.e. articles.comment.author)
* @return the uiSchema properties path (i.e. /properties/articles/properties/comment/properties/author)
*/
export declare const getPropPath: (path: string) => string;
/**
* Find a control in a uiSchema, based on the dotted path of the schema value

@@ -20,1 +14,10 @@ * @param {UISchemaElement} uiSchema the uiSchema to search from

export declare const findUiControl: (uiSchema: UISchemaElement, path: string) => UISchemaElement | undefined;
export declare const composeWithUi: (scopableUi: Scopable, path: string) => string;
export declare const isInternationalized: (element: unknown) => element is Required<Internationalizable>;
export declare const isGroup: (layout: Layout) => layout is GroupLayout;
export declare const isLayout: (uischema: UISchemaElement) => uischema is Layout;
export declare const isScopable: (obj: unknown) => obj is Scopable;
export declare const isScoped: (obj: unknown) => obj is Scoped;
export declare const isLabelable: (obj: unknown) => obj is Labelable<string>;
export declare const isLabeled: <T = never>(obj: unknown) => obj is Labeled<T>;
export declare const isControlElement: (uiSchema: UISchemaElement) => uiSchema is ControlElement;

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

import type { JsonSchema, Scoped, UISchemaElement } from '..';
import type Ajv from 'ajv';
import type { JsonSchema, Scoped, UISchemaElement } from '../models';
/**

@@ -37,3 +37,2 @@ * Returns the string representation of the given date. The format of the output string can be specified:

export declare const convertToValidClassName: (s: string) => string;
export declare const formatErrorMessage: (errors: string[]) => string;
export declare const hasType: (jsonSchema: JsonSchema, expected: string) => boolean;

@@ -40,0 +39,0 @@ /**

import Ajv from 'ajv';
import type { Options } from 'ajv';
import type { ErrorObject, Options, ValidateFunction } from 'ajv';
export declare const createAjv: (options?: Options) => Ajv;
export declare const validate: (validator: ValidateFunction | undefined, data: any) => ErrorObject[];
{
"name": "@jsonforms/core",
"version": "3.4.0-alpha.0",
"version": "3.4.0-alpha.1",
"description": "Core module of JSON Forms",

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

@@ -28,8 +28,7 @@ /*

import type { ErrorObject } from 'ajv';
import type { JsonSchema, UISchemaElement } from '../models';
import { JsonSchema, UISchemaElement } from '../models';
import { generateDefaultUISchema, generateJsonSchema } from '../generators';
import type { RankedTester } from '../testers';
import type { UISchemaTester, ValidationMode } from '../reducers';
import type { ErrorTranslator, Translator } from '../i18n';
import { RankedTester, UISchemaTester } from '../testers';
import { ErrorTranslator, Translator, ValidationMode } from '../store';

@@ -36,0 +35,0 @@ export const INIT = 'jsonforms/INIT' as const;

@@ -26,5 +26,5 @@ /*

import { ControlElement, JsonSchema, UISchemaElement } from '../models';
import { generateJsonSchema } from './schema';
import { createControlElement, generateDefaultUISchema } from './uischema';
import type { ControlElement, JsonSchema, UISchemaElement } from '../';

@@ -31,0 +31,0 @@ export const Generate: {

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

ControlElement,
isGroup,
isLayout,
JsonSchema,

@@ -39,3 +37,3 @@ LabelElement,

} from '../models';
import { deriveTypes, encode, resolveSchema } from '../util';
import { deriveTypes, encode, isGroup, isLayout, resolveSchema } from '../util';

@@ -42,0 +40,0 @@ /**

import type { ErrorObject } from 'ajv';
import { isInternationalized, Labelable, UISchemaElement } from '../models';
import { getControlPath } from '../reducers';
import { formatErrorMessage } from '../util';
import type { i18nJsonSchema, ErrorTranslator, Translator } from './i18nTypes';
import { Labelable, UISchemaElement } from '../models';
import type { i18nJsonSchema, ErrorTranslator, Translator } from '../store';
import {

@@ -14,2 +12,7 @@ ArrayDefaultTranslation,

} from './combinatorTranslations';
import {
formatErrorMessage,
getControlPath,
isInternationalized,
} from '../util';

@@ -16,0 +19,0 @@ export const getI18nKeyPrefixBySchema = (

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

export * from './i18nTypes';
export * from './i18nUtil';
export * from './arrayTranslations';
export * from './combinatorTranslations';
export * from './selectors';
export * from './i18nUtil';

@@ -34,5 +34,4 @@ /*

export * from './util';
export * from './Helpers';
export * from './store';
export * from './i18n';
export * from './mappers';

@@ -287,30 +287,1 @@ /*

}
export const isInternationalized = (
element: unknown
): element is Required<Internationalizable> =>
typeof element === 'object' &&
element !== null &&
typeof (element as Internationalizable).i18n === 'string';
export const isGroup = (layout: Layout): layout is GroupLayout =>
layout.type === 'Group';
export const isLayout = (uischema: UISchemaElement): uischema is Layout =>
(uischema as Layout).elements !== undefined;
export const isScopable = (obj: unknown): obj is Scopable =>
!!obj && typeof obj === 'object';
export const isScoped = (obj: unknown): obj is Scoped =>
isScopable(obj) && typeof obj.scope === 'string';
export const isLabelable = (obj: unknown): obj is Labelable =>
!!obj && typeof obj === 'object';
export const isLabeled = <T = never>(obj: unknown): obj is Labeled<T> =>
isLabelable(obj) && ['string', 'boolean'].includes(typeof obj.label);
export const isControlElement = (
uiSchema: UISchemaElement
): uiSchema is ControlElement => uiSchema.type === 'Control';

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

import type { RankedTester } from '../testers';
import {

@@ -34,3 +33,3 @@ ADD_CELL,

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

@@ -42,7 +41,2 @@ type ValidCellReducerActions = AddCellRendererAction | RemoveCellRendererAction;

export interface JsonFormsCellRendererRegistryEntry {
tester: RankedTester;
cell: any;
}
export const cellReducer: Reducer<

@@ -49,0 +43,0 @@ JsonFormsCellRendererRegistryState,

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

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

@@ -32,0 +32,0 @@ const applyDefaultConfiguration = (config: any = {}) =>

@@ -30,7 +30,3 @@ /*

import get from 'lodash/get';
import filter from 'lodash/filter';
import isEqual from 'lodash/isEqual';
import isFunction from 'lodash/isFunction';
import type Ajv from 'ajv';
import type { ErrorObject, ValidateFunction } from 'ajv';
import {

@@ -45,41 +41,13 @@ CoreActions,

SET_VALIDATION_MODE,
UPDATE_CORE,
UPDATE_DATA,
UPDATE_ERRORS,
UPDATE_CORE,
UpdateCoreAction,
} from '../actions';
import { createAjv, decode, isOneOfEnumSchema, Reducer } from '../util';
import type { JsonSchema, UISchemaElement } from '../models';
import { JsonFormsCore, Reducer, ValidationMode } from '../store';
import Ajv, { ErrorObject } from 'ajv';
import { isFunction } from 'lodash';
import { createAjv, validate } from '../util';
export const validate = (
validator: ValidateFunction | undefined,
data: any
): ErrorObject[] => {
if (validator === undefined) {
return [];
}
const valid = validator(data);
if (valid) {
return [];
}
return validator.errors;
};
export type ValidationMode =
| 'ValidateAndShow'
| 'ValidateAndHide'
| 'NoValidation';
export interface JsonFormsCore {
data: any;
schema: JsonSchema;
uischema: UISchemaElement;
errors?: ErrorObject[];
additionalErrors?: ErrorObject[];
validator?: ValidateFunction;
ajv?: Ajv;
validationMode?: ValidationMode;
}
const initState: JsonFormsCore = {
export const initState: JsonFormsCore = {
data: {},

@@ -95,30 +63,5 @@ schema: {},

const getOrCreateAjv = (
export const getValidationMode = (
state: JsonFormsCore,
action?: InitAction | UpdateCoreAction
): Ajv => {
if (action) {
if (hasAjvOption(action.options)) {
// options object with ajv
return action.options.ajv;
} else if (action.options !== undefined) {
// it is not an option object => should be ajv itself => check for compile function
if (isFunction(action.options.compile)) {
return action.options;
}
}
}
return state.ajv ? state.ajv : createAjv();
};
const hasAjvOption = (option: any): option is InitActionOptions => {
if (option) {
return option.ajv !== undefined;
}
return false;
};
const getValidationMode = (
state: JsonFormsCore,
action?: InitAction | UpdateCoreAction
): ValidationMode => {

@@ -147,3 +90,3 @@ if (action && hasValidationModeOption(action.options)) {

const getAdditionalErrors = (
export const getAdditionalErrors = (
state: JsonFormsCore,

@@ -158,2 +101,27 @@ action?: InitAction | UpdateCoreAction

export const getOrCreateAjv = (
state: JsonFormsCore,
action?: InitAction | UpdateCoreAction
): Ajv => {
if (action) {
if (hasAjvOption(action.options)) {
// options object with ajv
return action.options.ajv;
} else if (action.options !== undefined) {
// it is not an option object => should be ajv itself => check for compile function
if (isFunction(action.options.compile)) {
return action.options;
}
}
}
return state.ajv ? state.ajv : createAjv();
};
const hasAjvOption = (option: any): option is InitActionOptions => {
if (option) {
return option.ajv !== undefined;
}
return false;
};
export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (

@@ -337,136 +305,1 @@ state = initState,

};
export const extractData = (state: JsonFormsCore) => get(state, 'data');
export const extractSchema = (state: JsonFormsCore) => get(state, 'schema');
export const extractUiSchema = (state: JsonFormsCore) => get(state, 'uischema');
export const extractAjv = (state: JsonFormsCore) => get(state, 'ajv');
const getInvalidProperty = (error: ErrorObject): string | undefined => {
switch (error.keyword) {
case 'required':
case 'dependencies':
return error.params.missingProperty;
case 'additionalProperties':
return error.params.additionalProperty;
default:
return undefined;
}
};
export const getControlPath = (error: ErrorObject) => {
// Up until AJV v7 the path property was called 'dataPath'
// With AJV v8 the property was renamed to 'instancePath'
let controlPath = (error as any).dataPath || error.instancePath || '';
// change '/' chars to '.'
controlPath = controlPath.replace(/\//g, '.');
const invalidProperty = getInvalidProperty(error);
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
controlPath = `${controlPath}.${invalidProperty}`;
}
// remove '.' chars at the beginning of paths
controlPath = controlPath.replace(/^./, '');
// decode JSON Pointer escape sequences
controlPath = decode(controlPath);
return controlPath;
};
export const errorsAt =
(
instancePath: string,
schema: JsonSchema,
matchPath: (path: string) => boolean
) =>
(errors: ErrorObject[]): ErrorObject[] => {
// Get data paths of oneOf and anyOf errors to later determine whether an error occurred inside a subschema of oneOf or anyOf.
const combinatorPaths = filter(
errors,
(error) => error.keyword === 'oneOf' || error.keyword === 'anyOf'
).map((error) => getControlPath(error));
return filter(errors, (error) => {
// Filter errors that match any keyword that we don't want to show in the UI
// but keep the errors for oneOf enums
if (
filteredErrorKeywords.indexOf(error.keyword) !== -1 &&
!isOneOfEnumSchema(error.parentSchema)
) {
return false;
}
const controlPath = getControlPath(error);
let result = matchPath(controlPath);
// In anyOf and oneOf blocks with "primitive" (i.e. string, number etc.) or array subschemas,
// we want to make sure that errors are only shown for the correct subschema.
// Therefore, we compare the error's parent schema with the property's schema.
// In the primitive case the error's data path is the same for all subschemas:
// It directly points to the property defining the anyOf/oneOf.
// The same holds true for errors on the array level (e.g. min item amount).
// In contrast, this comparison must not be done for errors whose parent schema defines an object or a oneOf enum,
// because the parent schema can never match the property schema (e.g. for 'required' checks).
const parentSchema: JsonSchema | undefined = error.parentSchema;
if (
result &&
!isObjectSchema(parentSchema) &&
!isOneOfEnumSchema(parentSchema) &&
combinatorPaths.findIndex((p) => instancePath.startsWith(p)) !== -1
) {
result = result && isEqual(parentSchema, schema);
}
return result;
});
};
/**
* @returns true if the schema describes an object.
*/
const isObjectSchema = (schema?: JsonSchema): boolean => {
return schema?.type === 'object' || !!schema?.properties;
};
/**
* The error-type of an AJV error is defined by its `keyword` property.
* Certain errors are filtered because they don't fit to any rendered control.
* All of them have in common that we don't want to show them in the UI
* because controls will show the actual reason why they don't match their correponding sub schema.
* - additionalProperties: Indicates that a property is present that is not defined in the schema.
* Jsonforms only allows to edit defined properties. These errors occur if an oneOf doesn't match.
* - allOf: Indicates that not all of the allOf definitions match as a whole.
* - anyOf: Indicates that an anyOf definition itself is not valid because none of its subschemas matches.
* - oneOf: Indicates that an oneOf definition itself is not valid because not exactly one of its subschemas matches.
*/
const filteredErrorKeywords = [
'additionalProperties',
'allOf',
'anyOf',
'oneOf',
];
const getErrorsAt =
(
instancePath: string,
schema: JsonSchema,
matchPath: (path: string) => boolean
) =>
(state: JsonFormsCore): ErrorObject[] => {
const errors = state.errors ?? [];
const additionalErrors = state.additionalErrors ?? [];
return errorsAt(
instancePath,
schema,
matchPath
)(
state.validationMode === 'ValidateAndHide'
? additionalErrors
: [...errors, ...additionalErrors]
);
};
export const errorAt = (instancePath: string, schema: JsonSchema) =>
getErrorsAt(instancePath, schema, (path) => path === instancePath);
export const subErrorsAt = (instancePath: string, schema: JsonSchema) =>
getErrorsAt(instancePath, schema, (path) =>
path.startsWith(instancePath + '.')
);

@@ -26,9 +26,11 @@ /*

import get from 'lodash/get';
import {
ADD_DEFAULT_DATA,
REMOVE_DEFAULT_DATA,
RegisterDefaultDataAction,
REMOVE_DEFAULT_DATA,
UnregisterDefaultDataAction,
} from '../actions';
import type { Reducer } from '../util';
import type { Reducer } from '../store/type';
import { JsonFormsState } from '../store';

@@ -60,4 +62,8 @@ export interface JsonFormsDefaultDataRegistryEntry {

export const getDefaultData = (
state: JsonFormsState
): JsonFormsDefaultDataRegistryEntry[] =>
extractDefaultData(get(state, 'jsonforms.defaultData'));
export const extractDefaultData = (
state: JsonFormsDefaultDataRegistryEntry[]
): JsonFormsDefaultDataRegistryEntry[] => state;

@@ -26,8 +26,4 @@ /*

import { defaultErrorTranslator, defaultTranslator } from '../i18n';
import {
defaultErrorTranslator,
defaultTranslator,
JsonFormsI18nState,
} from '../i18n';
import {
I18nActions,

@@ -38,3 +34,4 @@ SET_LOCALE,

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

@@ -88,22 +85,1 @@ export const defaultJsonFormsI18nState: Required<JsonFormsI18nState> = {

};
export const fetchLocale = (state?: JsonFormsI18nState) => {
if (state === undefined) {
return undefined;
}
return state.locale;
};
export const fetchTranslator = (state?: JsonFormsI18nState) => {
if (state === undefined) {
return defaultTranslator;
}
return state.translate;
};
export const fetchErrorTranslator = (state?: JsonFormsI18nState) => {
if (state === undefined) {
return defaultErrorTranslator;
}
return state.translateError;
};

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

export * from './renderers';
export * from './selectors';
export * from './uischemas';
export * from './middleware';

@@ -26,3 +26,3 @@ /*

import { CoreActions } from '../actions';
import { JsonFormsCore } from './core';
import { JsonFormsCore } from '../store';

@@ -29,0 +29,0 @@ export interface Middleware {

@@ -27,9 +27,6 @@ /*

import type { ControlElement, UISchemaElement } from '../models';
import { coreReducer, errorAt, subErrorsAt } from './core';
import { defaultDataReducer } from './default-data';
import { rendererReducer } from './renderers';
import type { JsonFormsState } from '../store';
import type { JsonFormsUISchemaRegistryEntry } from './uischemas';
import { findMatchingUISchema, uischemaRegistryReducer } from './uischemas';
import { fetchErrorTranslator, fetchLocale, i18nReducer } from './i18n';
import { i18nReducer } from './i18n';

@@ -41,5 +38,4 @@ import { Generate } from '../generators';

import { configReducer } from './config';
import get from 'lodash/get';
import { fetchTranslator } from '.';
import type { ErrorTranslator, Translator } from '../i18n';
import { coreReducer } from './core';
import { JsonFormsUISchemaRegistryEntry } from '../store';

@@ -105,25 +101,1 @@ export const jsonFormsReducerConfig = {

};
export const getErrorAt =
(instancePath: string, schema: JsonSchema) => (state: JsonFormsState) => {
return errorAt(instancePath, schema)(state.jsonforms.core);
};
export const getSubErrorsAt =
(instancePath: string, schema: JsonSchema) => (state: JsonFormsState) =>
subErrorsAt(instancePath, schema)(state.jsonforms.core);
export const getConfig = (state: JsonFormsState) => state.jsonforms.config;
export const getLocale = (state: JsonFormsState) =>
fetchLocale(get(state, 'jsonforms.i18n'));
export const getTranslator =
() =>
(state: JsonFormsState): Translator =>
fetchTranslator(get(state, 'jsonforms.i18n'));
export const getErrorTranslator =
() =>
(state: JsonFormsState): ErrorTranslator =>
fetchErrorTranslator(get(state, 'jsonforms.i18n'));

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

import type { RankedTester } from '../testers';
import {

@@ -34,9 +33,5 @@ ADD_RENDERER,

} from '../actions';
import type { Reducer } from '../util';
import { Reducer } from '../store/type';
import { JsonFormsRendererRegistryEntry } from '../store';
export interface JsonFormsRendererRegistryEntry {
tester: RankedTester;
renderer: any;
}
type ValidRendererReducerActions = AddRendererAction | RemoveRendererAction;

@@ -43,0 +38,0 @@

@@ -31,15 +31,5 @@ /*

import type { JsonSchema, UISchemaElement } from '../models';
import type { Reducer } from '../util';
import type { Reducer } from '../store/type';
import { JsonFormsUISchemaRegistryEntry } from '../store';
export type UISchemaTester = (
schema: JsonSchema,
schemaPath: string,
path: string
) => number;
export interface JsonFormsUISchemaRegistryEntry {
tester: UISchemaTester;
uischema: UISchemaElement;
}
export const uischemaRegistryReducer: Reducer<

@@ -46,0 +36,0 @@ JsonFormsUISchemaRegistryEntry[],

@@ -84,2 +84,8 @@ /*

export type UISchemaTester = (
schema: JsonSchema,
schemaPath: string,
path: string
) => number;
export const isControl = (uischema: any): uischema is ControlElement =>

@@ -86,0 +92,0 @@ !isEmpty(uischema) && uischema.scope !== undefined;

@@ -26,5 +26,2 @@ /*

export * from './array';
export * from './cell';
export * from './combinators';
export * from './Formatted';

@@ -34,7 +31,5 @@ export * from './ids';

export * from './path';
export * from './renderer';
export * from './resolvers';
export * from './runtime';
export * from './schema';
export * from './type';
export * from './uischema';

@@ -44,1 +39,3 @@ export * from './util';

export * from './defaultDateFormat';
export * from './errors';
export * from './helpers';

@@ -28,24 +28,4 @@ /*

import {
ControlElement,
JsonSchema,
LabelDescription,
UISchemaElement,
} from '../models';
import { ControlElement, JsonSchema, LabelDescription } from '../models';
import { decode } from './path';
import { getI18nKeyPrefix, Translator } from '../i18n';
import { Resolve } from './util';
import {
getFirstPrimitiveProp,
isEnumSchema,
isOneOfEnumSchema,
} from './schema';
import get from 'lodash/get';
import { findUiControl, getPropPath } from './uischema';
import {
EnumOption,
enumToEnumOptionMapper,
oneOfToEnumOptionMapper,
} from './renderer';
import isEqual from 'lodash/isEqual';

@@ -105,78 +85,1 @@ const deriveLabel = (

});
/**
* Compute the child label title for array based controls
* @param data the data of the control
* @param childPath the child path
* @param childLabelProp the dotted path to the value used as child label
* @param {JsonSchema} schema the json schema for this control
* @param {JsonSchema} rootSchema the root json schema
* @param {Translator} translateFct the translator fonction
* @param {UISchemaElement} uiSchema the uiSchema of the control
*/
export const computeChildLabel = (
data: any,
childPath: string,
childLabelProp: string,
schema: JsonSchema,
rootSchema: JsonSchema,
translateFct: Translator,
uiSchema: UISchemaElement
): string => {
const childData = Resolve.data(data, childPath);
if (!childLabelProp) {
childLabelProp = getFirstPrimitiveProp(schema);
}
// return early in case there is no prop we can query
if (!childLabelProp) {
return '';
}
const currentValue = get(childData, childLabelProp);
// in case there is no value, then we can't map it to an enum or oneOf
if (currentValue === undefined) {
return '';
}
// check whether the value is part of a oneOf or enum and needs to be translated
const childSchema = Resolve.schema(
schema,
'#' + getPropPath(childLabelProp),
rootSchema
);
let enumOption: EnumOption = undefined;
if (isEnumSchema(childSchema)) {
enumOption = enumToEnumOptionMapper(
currentValue,
translateFct,
getI18nKeyPrefix(
childSchema,
findUiControl(uiSchema, childLabelProp),
childPath + '.' + childLabelProp
)
);
} else if (isOneOfEnumSchema(childSchema)) {
const oneOfArray = childSchema.oneOf as JsonSchema[];
const oneOfSchema = oneOfArray.find((e: JsonSchema) =>
isEqual(e.const, currentValue)
);
if (oneOfSchema) {
enumOption = oneOfToEnumOptionMapper(
oneOfSchema,
translateFct,
getI18nKeyPrefix(
oneOfSchema,
undefined,
childPath + '.' + childLabelProp
)
);
}
}
return enumOption ? enumOption.label : currentValue;
};

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

import range from 'lodash/range';
import { isScoped, Scopable } from '../models';

@@ -89,16 +88,2 @@ export const compose = (path1: string, path2: string) => {

export const composeWithUi = (scopableUi: Scopable, path: string): string => {
if (!isScoped(scopableUi)) {
return path ?? '';
}
const segments = toDataPathSegments(scopableUi.scope);
if (isEmpty(segments)) {
return path ?? '';
}
return compose(path, segments.join('.'));
};
/**

@@ -116,1 +101,13 @@ * Encodes the given segment to be used as part of a JSON Pointer

pointerSegment?.replace(/~1/g, '/').replace(/~0/, '~');
/**
* Transform a dotted path to a uiSchema properties path
* @param path a dotted prop path to a schema value (i.e. articles.comment.author)
* @return the uiSchema properties path (i.e. /properties/articles/properties/comment/properties/author)
*/
export const getPropPath = (path: string): string => {
return `/properties/${path
.split('.')
.map((p) => encode(p))
.join('/properties/')}`;
};

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

Condition,
JsonSchema,
LeafCondition,

@@ -40,6 +39,4 @@ OrCondition,

import { resolveData } from './resolvers';
import { composeWithUi } from './path';
import type Ajv from 'ajv';
import { getAjv } from '../reducers';
import type { JsonFormsState } from '../store';
import { composeWithUi } from './uischema';

@@ -189,41 +186,1 @@ const isOrCondition = (condition: Condition): condition is OrCondition =>

};
/**
* Indicates whether the given `uischema` element shall be enabled or disabled.
* Checks the global readonly flag, uischema rule, uischema options (including the config),
* the schema and the enablement indicator of the parent.
*/
export const isInherentlyEnabled = (
state: JsonFormsState,
ownProps: any,
uischema: UISchemaElement,
schema: (JsonSchema & { readOnly?: boolean }) | undefined,
rootData: any,
config: any
) => {
if (state?.jsonforms?.readonly) {
return false;
}
if (uischema && hasEnableRule(uischema)) {
return isEnabled(uischema, rootData, ownProps?.path, getAjv(state));
}
if (typeof uischema?.options?.readonly === 'boolean') {
return !uischema.options.readonly;
}
if (typeof uischema?.options?.readOnly === 'boolean') {
return !uischema.options.readOnly;
}
if (typeof config?.readonly === 'boolean') {
return !config.readonly;
}
if (typeof config?.readOnly === 'boolean') {
return !config.readOnly;
}
if (schema?.readOnly === true) {
return false;
}
if (typeof ownProps?.enabled === 'boolean') {
return ownProps.enabled;
}
return true;
};

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

import find from 'lodash/find';
import { JsonSchema } from '../models';
import type { JsonSchema } from '../models';

@@ -30,0 +30,0 @@ export const getFirstPrimitiveProp = (schema: any) => {

@@ -28,8 +28,13 @@ /*

import {
isControlElement,
isLayout,
isScoped,
ControlElement,
GroupLayout,
Internationalizable,
Labelable,
Labeled,
Layout,
Scopable,
Scoped,
UISchemaElement,
} from '../models';
import { encode } from './path';
import { compose, getPropPath, toDataPathSegments } from './path';

@@ -67,14 +72,2 @@ export type IterateCallback = (uischema: UISchemaElement) => void;

/**
* Transform a dotted path to a uiSchema properties path
* @param path a dotted prop path to a schema value (i.e. articles.comment.author)
* @return the uiSchema properties path (i.e. /properties/articles/properties/comment/properties/author)
*/
export const getPropPath = (path: string): string => {
return `/properties/${path
.split('.')
.map((p) => encode(p))
.join('/properties/')}`;
};
/**
* Find a control in a uiSchema, based on the dotted path of the schema value

@@ -106,1 +99,44 @@ * @param {UISchemaElement} uiSchema the uiSchema to search from

};
export const composeWithUi = (scopableUi: Scopable, path: string): string => {
if (!isScoped(scopableUi)) {
return path ?? '';
}
const segments = toDataPathSegments(scopableUi.scope);
if (isEmpty(segments)) {
return path ?? '';
}
return compose(path, segments.join('.'));
};
export const isInternationalized = (
element: unknown
): element is Required<Internationalizable> =>
typeof element === 'object' &&
element !== null &&
typeof (element as Internationalizable).i18n === 'string';
export const isGroup = (layout: Layout): layout is GroupLayout =>
layout.type === 'Group';
export const isLayout = (uischema: UISchemaElement): uischema is Layout =>
(uischema as Layout).elements !== undefined;
export const isScopable = (obj: unknown): obj is Scopable =>
!!obj && typeof obj === 'object';
export const isScoped = (obj: unknown): obj is Scoped =>
isScopable(obj) && typeof obj.scope === 'string';
export const isLabelable = (obj: unknown): obj is Labelable =>
!!obj && typeof obj === 'object';
export const isLabeled = <T = never>(obj: unknown): obj is Labeled<T> =>
isLabelable(obj) && ['string', 'boolean'].includes(typeof obj.label);
export const isControlElement = (
uiSchema: UISchemaElement
): uiSchema is ControlElement => uiSchema.type === 'Control';

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

import find from 'lodash/find';
import type { JsonSchema, Scoped, UISchemaElement } from '..';
import { resolveData, resolveSchema } from './resolvers';

@@ -36,2 +35,3 @@ import { composePaths, toDataPathSegments } from './path';

import type Ajv from 'ajv';
import type { JsonSchema, Scoped, UISchemaElement } from '../models';

@@ -91,10 +91,2 @@ /**

export const formatErrorMessage = (errors: string[]) => {
if (errors === undefined || errors === null) {
return '';
}
return errors.join('\n');
};
export const hasType = (jsonSchema: JsonSchema, expected: string): boolean => {

@@ -101,0 +93,0 @@ return includes(deriveTypes(jsonSchema), expected);

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

import addFormats from 'ajv-formats';
import type { Options } from 'ajv';
import type { ErrorObject, Options, ValidateFunction } from 'ajv';

@@ -41,1 +41,15 @@ export const createAjv = (options?: Options) => {

};
export const validate = (
validator: ValidateFunction | undefined,
data: any
): ErrorObject[] => {
if (validator === undefined) {
return [];
}
const valid = validator(data);
if (valid) {
return [];
}
return validator.errors;
};

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 too big to display

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