diff --git a/modules/json/src/utils/expression-eval.ts b/modules/json/src/expression-eval/expression-eval.ts similarity index 98% rename from modules/json/src/utils/expression-eval.ts rename to modules/json/src/expression-eval/expression-eval.ts index 48907154f09..20e8cbcec7b 100644 --- a/modules/json/src/utils/expression-eval.ts +++ b/modules/json/src/expression-eval/expression-eval.ts @@ -2,15 +2,15 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import jsep from 'jsep'; - /** * Sources: * - Copyright (c) 2013 Stephen Oney, http://jsep.from.so/, MIT License * - Copyright (c) 2023 Don McCurdy, https://github.com/donmccurdy/expression-eval, MIT License */ -// Default operator precedence from https://github.com/EricSmekens/jsep/blob/master/src/jsep.js#L55 +import jsep from 'jsep'; + +/** Default operator precedence from https://github.com/EricSmekens/jsep/blob/master/src/jsep.js#L55 */ const DEFAULT_PRECEDENCE = { '||': 1, '&&': 2, diff --git a/modules/json/src/helpers/convert-functions.ts b/modules/json/src/helpers/convert-functions.ts index 0e5827297e5..b1f4461183c 100644 --- a/modules/json/src/helpers/convert-functions.ts +++ b/modules/json/src/helpers/convert-functions.ts @@ -2,33 +2,37 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import parseExpressionString from './parse-expression-string'; +import {parseExpressionString} from './parse-expression-string'; import {FUNCTION_IDENTIFIER} from '../syntactic-sugar'; +import {type JSONConfiguration} from '../json-configuration'; -function hasFunctionIdentifier(value) { +function hasFunctionIdentifier(value: unknown): value is string { return typeof value === 'string' && value.startsWith(FUNCTION_IDENTIFIER); } -function trimFunctionIdentifier(value) { +function trimFunctionIdentifier(value: string): string { return value.replace(FUNCTION_IDENTIFIER, ''); } -// Try to determine if any props are function valued -// and if so convert their string values to functions -export default function convertFunctions(props, configuration) { +/** + * Tries to determine if any props are "function valued" + * and if so convert their string values to functions + */ +export function convertFunctions( + props: Record, + configuration: JSONConfiguration +): Record { // Use deck.gl prop types if available. const replacedProps = {}; for (const propName in props) { let propValue = props[propName]; // Parse string valued expressions - const isFunction = hasFunctionIdentifier(propValue); - - if (isFunction) { + if (hasFunctionIdentifier(propValue)) { // Parse string as "expression", return equivalent JavaScript function - propValue = trimFunctionIdentifier(propValue); - propValue = parseExpressionString(propValue, configuration); + const trimmedFunctionIdentifier = trimFunctionIdentifier(propValue); + propValue = parseExpressionString(trimmedFunctionIdentifier, configuration); } replacedProps[propName] = propValue; diff --git a/modules/json/src/helpers/execute-function.ts b/modules/json/src/helpers/execute-function.ts index 41e71251030..1858d2f1f3f 100644 --- a/modules/json/src/helpers/execute-function.ts +++ b/modules/json/src/helpers/execute-function.ts @@ -2,14 +2,22 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -// This attempts to execute a function -export function executeFunction(targetFunction, props, configuration) { +import {type JSONConfiguration} from '../json-configuration'; + +/** + * Attempt to execute a function + */ +export function executeFunction( + targetFunction: string, + props: Record, + configuration: JSONConfiguration +) { // Find the function - const matchedFunction = configuration.functions[targetFunction]; + const matchedFunction = configuration.config.functions[targetFunction]; // Check that the function is in the configuration. if (!matchedFunction) { - const {log} = configuration; // eslint-disable-line + const {log} = configuration.config; // eslint-disable-line if (log) { const stringProps = JSON.stringify(props, null, 0).slice(0, 40); log.warn(`JSON converter: No registered function ${targetFunction}(${stringProps}...) `); diff --git a/modules/json/src/helpers/instantiate-class.ts b/modules/json/src/helpers/instantiate-class.ts index 29818976a37..ef8da898620 100644 --- a/modules/json/src/helpers/instantiate-class.ts +++ b/modules/json/src/helpers/instantiate-class.ts @@ -2,17 +2,26 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import convertFunctions from './convert-functions'; - -// This attempts to instantiate a class, either as a class or as a React component -export function instantiateClass(type, props, configuration) { +import {JSONConfiguration} from '../json-configuration'; +import {convertFunctions} from './convert-functions'; + +type Constructor = new (props: Record) => T; + +/** + * Attempt to instantiate a class, either as a class or as a React component + */ +export function instantiateClass( + type: string, + props: Record, + configuration: JSONConfiguration +): unknown { // Find the class - const Class = configuration.classes[type]; - const Component = configuration.reactComponents[type]; + const Class = configuration.config.classes[type]; + const Component = configuration.config.reactComponents[type]; // Check that the class is in the configuration. if (!Class && !Component) { - const {log} = configuration; // eslint-disable-line + const {log} = configuration.config; // eslint-disable-line if (log) { const stringProps = JSON.stringify(props, null, 0).slice(0, 40); log.warn(`JSON converter: No registered class of type ${type}(${stringProps}...) `); @@ -27,20 +36,24 @@ export function instantiateClass(type, props, configuration) { return instantiateReactComponent(Component, props, configuration); } -function instantiateJavaScriptClass(Class, props, configuration) { +function instantiateJavaScriptClass( + Class: Constructor, + props: Record, + configuration: JSONConfiguration +): unknown { if (configuration.preProcessClassProps) { - props = configuration.preProcessClassProps(Class, props, configuration); + props = configuration.preProcessClassProps(Class, props); } props = convertFunctions(props, configuration); return new Class(props); } -function instantiateReactComponent(Component, props, configuration) { - const {React} = configuration; +function instantiateReactComponent(Component, props, configuration: JSONConfiguration) { + const {React} = configuration.config; const {children = []} = props; delete props.children; if (configuration.preProcessClassProps) { - props = configuration.preProcessClassProps(Component, props, configuration); + props = configuration.preProcessClassProps(Component, props); } props = convertFunctions(props, configuration); diff --git a/modules/json/src/helpers/parse-expression-string.ts b/modules/json/src/helpers/parse-expression-string.ts index a87dec36983..4210ab8ebea 100644 --- a/modules/json/src/helpers/parse-expression-string.ts +++ b/modules/json/src/helpers/parse-expression-string.ts @@ -5,16 +5,24 @@ import {get} from '../utils/get'; // expression-eval: Small jsep based expression parser that supports array and object indexing -import {parse, eval as evaluate} from '../utils/expression-eval'; +import {parse, eval as evaluate} from '../expression-eval/expression-eval'; -const cachedExpressionMap = { +type AccessorFunction = (row: Record) => unknown; + +const cachedExpressionMap: Record = { + // Identity function '-': object => object }; -// Calculates an accessor function from a JSON string -// '-' : x => x -// 'a.b.c': x => x.a.b.c -export default function parseExpressionString(propValue, configuration) { +/** + * Generates an accessor function from a JSON string + * '-' : x => x + * 'a.b.c': x => x.a.b.c + */ +export function parseExpressionString( + propValue: string, + configuration? +): (row: Record) => unknown { // NOTE: Can be null which represents invalid function. Return null so that prop can be omitted if (propValue in cachedExpressionMap) { return cachedExpressionMap[propValue]; @@ -47,7 +55,7 @@ export default function parseExpressionString(propValue, configuration) { return func; } -// Helper function to search all nodes in AST returned by expressionEval +/** Helper function to search all nodes in AST returned by expressionEval */ // eslint-disable-next-line complexity function traverse(node, visitor) { if (Array.isArray(node)) { diff --git a/modules/json/src/helpers/parse-json.ts b/modules/json/src/helpers/parse-json.ts index 743389333ad..629bafbe235 100644 --- a/modules/json/src/helpers/parse-json.ts +++ b/modules/json/src/helpers/parse-json.ts @@ -4,6 +4,6 @@ // Accept JSON strings by parsing them // TODO - use a parser that provides meaninful error messages -export default function parseJSON(json) { +export function parseJSON(json) { return typeof json === 'string' ? JSON.parse(json) : json; } diff --git a/modules/json/src/index.ts b/modules/json/src/index.ts index 23625bf1e7b..d8c321602c3 100644 --- a/modules/json/src/index.ts +++ b/modules/json/src/index.ts @@ -5,13 +5,13 @@ // @deck.gl/json: top-level exports // Generic JSON converter, usable by other wrapper modules -export {default as JSONConverter} from './json-converter'; -export {default as JSONConfiguration} from './json-configuration'; +export {JSONConverter, type JSONConverterProps} from './json-converter'; +export {JSONConfiguration, type JSONConfigurationProps} from './json-configuration'; // Transports -export {default as Transport} from './transports/transport'; +export {Transport} from './transports/transport'; // Helpers -export {default as _convertFunctions} from './helpers/convert-functions'; -export {default as _parseExpressionString} from './helpers/parse-expression-string'; +export {convertFunctions as _convertFunctions} from './helpers/convert-functions'; +export {parseExpressionString as _parseExpressionString} from './helpers/parse-expression-string'; export {shallowEqualObjects as _shallowEqualObjects} from './utils/shallow-equal-objects'; diff --git a/modules/json/src/json-configuration.ts b/modules/json/src/json-configuration.ts index 9f2c596cace..13d34dad493 100644 --- a/modules/json/src/json-configuration.ts +++ b/modules/json/src/json-configuration.ts @@ -2,56 +2,57 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -// TODO - default parsing code should not be part of the configuration. -import parseExpressionString from './helpers/parse-expression-string'; -import assert from './utils/assert'; - import {TYPE_KEY, FUNCTION_KEY} from './syntactic-sugar'; +// TODO - default parsing code should not be part of the configuration. +import {parseExpressionString} from './helpers/parse-expression-string'; const isObject = value => value && typeof value === 'object'; -export default class JSONConfiguration { - typeKey = TYPE_KEY; - functionKey = FUNCTION_KEY; - log = console; // eslint-disable-line - classes = {}; - reactComponents = {}; - enumerations = {}; - constants = {}; - functions = {}; - React = null; +export type JSONConfigurationProps = { + log?; // eslint-disable-line + typeKey?: string; + functionKey?: string; + classes?: Record) => unknown>; + enumerations?: Record; + constants: Record; + functions: Record; + React?: {createElement: (Component, props, children) => any}; + reactComponents?: Record; +}; + +export class JSONConfiguration { + static defaultProps: Required = { + log: console, // eslint-disable-lin, + typeKey: TYPE_KEY, + functionKey: FUNCTION_KEY, + classes: {}, + reactComponents: {}, + enumerations: {}, + constants: {}, + functions: {}, + React: undefined! + }; + + config: Required = {...JSONConfiguration.defaultProps}; + // TODO - this needs to be simpler, function conversion should be built in convertFunction = parseExpressionString; preProcessClassProps = (Class, props) => props; postProcessConvertedJson = json => json; - constructor(...configurations) { - for (const configuration of configurations) { - this.merge(configuration); - } + constructor(configuration: JSONConfigurationProps) { + this.merge(configuration); } - merge(configuration) { + merge(configuration: JSONConfigurationProps) { for (const key in configuration) { - switch (key) { - // DEPRECATED = For backwards compatibility, add views and layers to classes; - case 'layers': - case 'views': - Object.assign(this.classes, configuration[key]); - break; - default: - // Store configuration as root fields (this.classes, ...) - if (key in this) { - const value = configuration[key]; - this[key] = isObject(this[key]) ? Object.assign(this[key], value) : value; - } + // Store configuration as root fields (this.classes, ...) + if (key in this.config) { + const value = configuration[key]; + this.config[key] = isObject(this.config[key]) + ? Object.assign(this.config[key], value) + : value; } } } - - validate(configuration) { - assert(!this.typeKey || typeof this.typeKey === 'string'); - assert(isObject(this.classes)); - return true; - } } diff --git a/modules/json/src/json-converter.ts b/modules/json/src/json-converter.ts index ab4f7eb3128..6c8238b5b88 100644 --- a/modules/json/src/json-converter.ts +++ b/modules/json/src/json-converter.ts @@ -2,37 +2,39 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -// Converts JSON to props ("hydrating" classes, resolving enums and functions etc). -// Lightly processes `json` props, transform string values, and extract `views` and `layers` -// See: https://github.com/visgl/deck.gl/blob/master/dev-docs/RFCs/v6.1/json-layers-rfc.md -// -// NOTES: -// * This is intended to provide minimal necessary processing required to support -// existing deck.gl props via JSON. This is not an implementation of alternate JSON schemas. -// * Optionally, error checking could be applied, but ideally should leverage -// non-JSON specific mechanisms like prop types. - -import assert from './utils/assert'; -import JSONConfiguration from './json-configuration'; +import {JSONConfiguration, JSONConfigurationProps} from './json-configuration'; +import {FUNCTION_IDENTIFIER, CONSTANT_IDENTIFIER, FUNCTION_KEY} from './syntactic-sugar'; import {instantiateClass} from './helpers/instantiate-class'; import {executeFunction} from './helpers/execute-function'; +import {parseJSON} from './helpers/parse-json'; -import {FUNCTION_IDENTIFIER, CONSTANT_IDENTIFIER, FUNCTION_KEY} from './syntactic-sugar'; -import parseJSON from './helpers/parse-json'; - -const isObject = value => value && typeof value === 'object'; +function isObject(value: unknown): value is Record { + return Boolean(value) && typeof value === 'object'; +} export type JSONConverterProps = { - configuration: JSONConfiguration | Record; - onJSONChange; + configuration: JSONConfiguration | JSONConfigurationProps; + onJSONChange: () => void; }; -export default class JSONConverter { +/** + * Converts JSON to "props" by "hydrating" classes, resolving enums and functions etc. + * + * Lightly processes `json` props, transform string values, and extract `views` and `layers` + * @see https://github.com/visgl/deck.gl/blob/master/dev-docs/RFCs/v6.1/json-layers-rfc.md + * + * NOTES: + * - This is intended to provide minimal necessary processing required to support + * existing deck.gl props via JSON. This is not an implementation of alternate JSON schemas. + * - Optionally, error checking could be applied, but ideally should leverage + * non-JSON specific mechanisms like prop types. + */ +export class JSONConverter { log = console; // eslint-disable-line configuration!: JSONConfiguration; - onJSONChange = () => {}; - json = null; - convertedJson = null; + onJSONChange: () => void = () => {}; + json: unknown = null; + convertedJson: unknown = null; constructor(props) { this.setProps(props); @@ -41,7 +43,7 @@ export default class JSONConverter { // eslint-disable-next-line @typescript-eslint/no-empty-function finalize() {} - setProps(props: JSONConverterProps) { + setProps(props: JSONConverterProps | JSONConfiguration) { // HANDLE CONFIGURATION PROPS if ('configuration' in props) { // Accept object or `JSONConfiguration` @@ -56,11 +58,11 @@ export default class JSONConverter { } } - mergeConfiguration(config) { - this.configuration.merge(config); + mergeConfiguration(config: JSONConfiguration) { + this.configuration.merge(config.config); } - convert(json) { + convert(json: unknown): unknown { // Use shallow equality to ensure we only convert same json once if (!json || json === this.json) { return this.convertedJson; @@ -70,6 +72,9 @@ export default class JSONConverter { // Accept JSON strings by parsing them const parsedJSON = parseJSON(json); + if (!isObject(parsedJSON)) { + throw new Error('JSONConverter: expected an object'); + } // Convert the JSON let convertedJson = convertJSON(parsedJSON, this.configuration); @@ -86,24 +91,24 @@ export default class JSONConverter { } } -function convertJSON(json, configuration) { +function convertJSON(json: Record, configuration: JSONConfiguration) { // Fixup configuration - configuration = new JSONConfiguration(configuration); + configuration = new JSONConfiguration(configuration.config); return convertJSONRecursively(json, '', configuration); } -// Converts JSON to props ("hydrating" classes, resolving enums and functions etc). -function convertJSONRecursively(json, key, configuration) { +/** Converts JSON to props ("hydrating" classes, resolving enums and functions etc). */ +function convertJSONRecursively(json: unknown, key, configuration) { if (Array.isArray(json)) { return json.map((element, i) => convertJSONRecursively(element, String(i), configuration)); } - // If object.type is in configuration, instantiate - if (isClassInstance(json, configuration)) { - return convertClassInstance(json, configuration); - } - if (isObject(json)) { + // If object.type is in configuration, instantiate + if (isClassInstance(json, configuration)) { + return convertClassInstance(json, configuration); + } + // If object.function is in configuration, convert object to function if (FUNCTION_KEY in json) { return convertFunctionObject(json, configuration); @@ -120,16 +125,16 @@ function convertJSONRecursively(json, key, configuration) { return json; } -// Returns true if an object has a `type` field -function isClassInstance(json, configuration) { - const {typeKey} = configuration; +/** Returns true if an object has a `type` field */ +function isClassInstance(json: Record, configuration: JSONConfiguration) { + const {typeKey} = configuration.config; const isClass = isObject(json) && Boolean(json[typeKey]); return isClass; } -function convertClassInstance(json, configuration) { +function convertClassInstance(json: Record, configuration: JSONConfiguration) { // Extract the class type field - const {typeKey} = configuration; + const {typeKey} = configuration.config; const type = json[typeKey]; // Prepare a props object and ensure all values have been converted @@ -138,13 +143,13 @@ function convertClassInstance(json, configuration) { props = convertPlainObject(props, configuration); - return instantiateClass(type, props, configuration); + return instantiateClass(type as string, props, configuration); } -// Plain JS object, embed functions. -function convertFunctionObject(json, configuration) { +/** Plain JS object, embed functions. */ +function convertFunctionObject(json, configuration: JSONConfiguration) { // Extract the target function field - const {functionKey} = configuration; + const {functionKey} = configuration.config; const targetFunction = json[functionKey]; // Prepare a props object and ensure all values have been converted @@ -156,22 +161,23 @@ function convertFunctionObject(json, configuration) { return executeFunction(targetFunction, props, configuration); } -// Plain JS object, convert each key and return. -function convertPlainObject(json, configuration) { - assert(isObject(json)); +/** Plain JS object, convert each key and return. */ +function convertPlainObject(json: unknown, configuration: JSONConfiguration) { + if (!isObject(json)) { + throw new Error('convertPlainObject: expected an object'); + } const result = {}; - for (const key in json) { - const value = json[key]; + for (const [key, value] of Object.entries(json)) { result[key] = convertJSONRecursively(value, key, configuration); } return result; } -// Convert one string value in an object -// TODO - We could also support string syntax for hydrating other types, like regexps... -// But no current use case -function convertString(string, key, configuration) { +/** Convert one string value in an object + * @todo We could also support string syntax for hydrating other types, like regexps... But no current use case + */ +function convertString(string: string, key: string, configuration: JSONConfiguration) { // Here the JSON value is supposed to be treated as a function if (string.startsWith(FUNCTION_IDENTIFIER) && configuration.convertFunction) { string = string.replace(FUNCTION_IDENTIFIER, ''); @@ -179,12 +185,12 @@ function convertString(string, key, configuration) { } if (string.startsWith(CONSTANT_IDENTIFIER)) { string = string.replace(CONSTANT_IDENTIFIER, ''); - if (configuration.constants[string]) { - return configuration.constants[string]; + if (configuration.config.constants[string]) { + return configuration.config.constants[string]; } // enum const [enumVarName, enumValName] = string.split('.'); - return configuration.enumerations[enumVarName][enumValName]; + return configuration.config.enumerations[enumVarName][enumValName]; } return string; } diff --git a/modules/json/src/transports/transport.ts b/modules/json/src/transports/transport.ts index 3a39d948077..16959516b6d 100644 --- a/modules/json/src/transports/transport.ts +++ b/modules/json/src/transports/transport.ts @@ -2,15 +2,22 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors +export type TransportCallbacks = { + onInitialize: (message: any) => void; + onFinalize: (message: any) => void; + onMessage: (message: any) => void; +}; + /* global document */ -const state = { +const state: TransportCallbacks = { onInitialize: _ => _, onFinalize: _ => _, onMessage: _ => _ }; -export default class Transport { - static setCallbacks({onInitialize, onFinalize, onMessage}) { +/** Helper class for Python / Jupyter integration */ +export class Transport { + static setCallbacks({onInitialize, onFinalize, onMessage}: Partial) { if (onInitialize) { state.onInitialize = onInitialize; } @@ -34,10 +41,10 @@ export default class Transport { /** * Return a root DOM element for this transport connection - * @return {HTMLElement} default implementation returns document.body + * @returns default implementation returns document.body * Jupyter Notebook transports will return an element associated with the notebook cell */ - getRootDOMElement() { + getRootDOMElement(): HTMLElement | null { return typeof document !== 'undefined' ? document.body : null; } diff --git a/modules/json/src/utils/assert.ts b/modules/json/src/utils/assert.ts index d315557cf84..9e13cd2f739 100644 --- a/modules/json/src/utils/assert.ts +++ b/modules/json/src/utils/assert.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -export default function assert(condition, message = '') { +export function assert(condition, message = '') { if (!condition) { throw new Error(`JSON conversion error ${message}`); } diff --git a/modules/json/src/utils/get.ts b/modules/json/src/utils/get.ts index 2e8a4a583c5..6883071ad32 100644 --- a/modules/json/src/utils/get.ts +++ b/modules/json/src/utils/get.ts @@ -5,15 +5,15 @@ /** * Access properties of nested containers using dot-path notation * Returns `undefined` if any container is not valid, instead of throwing - * @param {Object} container - container that supports get - * @param {String|*} compositeKey - key to access, can be '.'-separated string - * @return {*} - value in the final key of the nested container, or `undefined` + * @param container - container that supports get + * @param compositeKey - key to access, can be '.'-separated string + * @return value in the final key of the nested container, or `undefined` */ -export function get(container, compositeKey) { +export function get(container: Record, compositeKey: string): unknown { // Split the key into subkeys const keyList = getKeys(compositeKey); // Recursively get the value of each key; - let value = container; + let value: Record | unknown = container; for (const key of keyList) { // If any intermediate subfield is not an object, return undefined value = isObject(value) ? value[key] : undefined; @@ -23,20 +23,20 @@ export function get(container, compositeKey) { /** * Checks if argument is an "indexable" object (not a primitive value, nor null) - * @param {*} value - JavaScript value to be tested - * @return {Boolean} - true if argument is a JavaScript object + * @param value - JavaScript value to be tested + * @return true if argument is a JavaScript object */ -function isObject(value) { +function isObject(value: unknown): value is Record { return value !== null && typeof value === 'object'; } // Cache key to key arrays for speed -const keyMap = {}; +const keyMap: Record = {}; // Takes a string of '.' separated keys and returns an array of keys // - 'feature.geometry.type' => ['feature', 'geometry', 'type'] // - 'feature' => ['feature'] -function getKeys(compositeKey) { +function getKeys(compositeKey: string): string[] { if (typeof compositeKey === 'string') { // else assume string and split around dots let keyList = keyMap[compositeKey]; diff --git a/modules/jupyter-widget/src/playground/create-deck.js b/modules/jupyter-widget/src/playground/create-deck.js index 75e2b1d5339..42703264db1 100644 --- a/modules/jupyter-widget/src/playground/create-deck.js +++ b/modules/jupyter-widget/src/playground/create-deck.js @@ -38,7 +38,7 @@ function extractElements(library = {}, filter) { } // Handle JSONConverter and loaders configuration -const jsonConverterConfiguration = { +const JSON_CONVERTER_CONFIGURATION = { classes: extractElements(deckExports, classesFilter), // Will be resolved as `.` enumerations: { @@ -50,7 +50,7 @@ const jsonConverterConfiguration = { registerLoaders([CSVLoader]); const jsonConverter = new JSONConverter({ - configuration: jsonConverterConfiguration + configuration: JSON_CONVERTER_CONFIGURATION }); function addModuleToConverter(module, converter) { diff --git a/test/modules/json/utils/expression-eval.spec.ts b/test/modules/json/expression-eval/expression-eval.spec.ts similarity index 97% rename from test/modules/json/utils/expression-eval.spec.ts rename to test/modules/json/expression-eval/expression-eval.spec.ts index 37e62c12d94..4bfe3cfaff2 100644 --- a/test/modules/json/utils/expression-eval.spec.ts +++ b/test/modules/json/expression-eval/expression-eval.spec.ts @@ -3,7 +3,12 @@ // Copyright (c) vis.gl contributors import test from 'tape-promise/tape'; -import {compile, compileAsync, addUnaryOp, addBinaryOp} from '@deck.gl/json/utils/expression-eval'; +import { + compile, + compileAsync, + addUnaryOp, + addBinaryOp +} from '@deck.gl/json/expression-eval/expression-eval'; const fixtures = [ // array expression diff --git a/test/modules/json/helpers/convert-functions.spec.ts b/test/modules/json/helpers/convert-functions.spec.ts index a57d52bc5c0..dffed607368 100644 --- a/test/modules/json/helpers/convert-functions.spec.ts +++ b/test/modules/json/helpers/convert-functions.spec.ts @@ -4,7 +4,7 @@ // Based on https://github.com/donmccurdy/expression-eval under MIT license import test from 'tape-promise/tape'; -import convertFunctions from '@deck.gl/json/helpers/convert-functions'; +import {_convertFunctions as convertFunctions} from '@deck.gl/json'; const TEST_CASES = [ {expr: 'true', expected: true}, // boolean literal diff --git a/test/modules/json/helpers/parse-expression-string.spec.ts b/test/modules/json/helpers/parse-expression-string.spec.ts index 2b45af3bb9f..c821b871ecf 100644 --- a/test/modules/json/helpers/parse-expression-string.spec.ts +++ b/test/modules/json/helpers/parse-expression-string.spec.ts @@ -4,7 +4,7 @@ // Based on https://github.com/donmccurdy/expression-eval under MIT license import test from 'tape-promise/tape'; -import parseExpressionString from '@deck.gl/json/helpers/parse-expression-string'; +import {_parseExpressionString as parseExpressionString} from '@deck.gl/json'; const row = Object.freeze({ foo: { diff --git a/test/modules/json/index.ts b/test/modules/json/index.ts index 7634ed65a47..b4df8abfc41 100644 --- a/test/modules/json/index.ts +++ b/test/modules/json/index.ts @@ -2,7 +2,8 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import './utils/expression-eval.spec'; +import './expression-eval/expression-eval.spec'; + import './utils/get.spec'; import './utils/shallow-equal-objects.spec'; diff --git a/test/modules/json/json-configuration-for-deck.ts b/test/modules/json/json-configuration-for-deck.ts index d3c1c275a3e..a9e9fcb0052 100644 --- a/test/modules/json/json-configuration-for-deck.ts +++ b/test/modules/json/json-configuration-for-deck.ts @@ -13,7 +13,7 @@ export function calculateRadius({base, exponent}) { return Math.pow(base, exponent); } -export default { +export const JSON_CONFIGURATION = { log, // a map of all layers that should be exposes as JSONLayers classes: Object.assign({MapView, FirstPersonView}, deckglLayers), diff --git a/test/modules/json/json-configuration.spec.ts b/test/modules/json/json-configuration.spec.ts index 3b5e4a7b69c..fd95c1f0879 100644 --- a/test/modules/json/json-configuration.spec.ts +++ b/test/modules/json/json-configuration.spec.ts @@ -5,7 +5,7 @@ import test from 'tape-promise/tape'; import {JSONConfiguration} from '@deck.gl/json'; -import configuration from './json-configuration-for-deck'; +import {JSON_CONFIGURATION} from './json-configuration-for-deck'; test('JSONConfiguration#import', t => { t.ok(JSONConfiguration, 'JSONConfiguration imported'); @@ -13,7 +13,7 @@ test('JSONConfiguration#import', t => { }); test('JSONConfiguration#create', t => { - const jsonConverter = new JSONConfiguration({configuration}); + const jsonConverter = new JSONConfiguration({configuration: JSON_CONFIGURATION}); t.ok(jsonConverter, 'JSONConfiguration created'); t.end(); }); diff --git a/test/modules/json/json-converter.spec.ts b/test/modules/json/json-converter.spec.ts index df68ad1dbda..28c10011dca 100644 --- a/test/modules/json/json-converter.spec.ts +++ b/test/modules/json/json-converter.spec.ts @@ -5,10 +5,10 @@ import test from 'tape-promise/tape'; import {makeSpy} from '@probe.gl/test-utils'; -import {COORDINATE_SYSTEM} from '@deck.gl/core/lib/constants'; +import {COORDINATE_SYSTEM} from '@deck.gl/core'; import {MapController} from '@deck.gl/core'; import {JSONConverter} from '@deck.gl/json'; -import configuration, {log, calculateRadius} from './json-configuration-for-deck'; +import {JSON_CONFIGURATION, log, calculateRadius} from './json-configuration-for-deck'; import JSON_DATA from './data/deck-props.json'; import COMPLEX_JSON from './data/complex-data.json'; @@ -20,13 +20,13 @@ test('JSONConverter#import', t => { }); test('JSONConverter#create', t => { - const jsonConverter = new JSONConverter({configuration}); + const jsonConverter = new JSONConverter({configuration: JSON_CONFIGURATION}); t.ok(jsonConverter, 'JSONConverter created'); t.end(); }); test('JSONConverter#convert', t => { - const jsonConverter = new JSONConverter({configuration}); + const jsonConverter = new JSONConverter({configuration: JSON_CONFIGURATION}); t.ok(jsonConverter, 'JSONConverter created'); let deckProps = jsonConverter.convert(JSON_DATA); @@ -52,7 +52,7 @@ test('JSONConverter#convert', t => { }); test('JSONConverter#merge', t => { - const jsonConverter = new JSONConverter({configuration}); + const jsonConverter = new JSONConverter({configuration: JSON_CONFIGURATION}); jsonConverter.mergeConfiguration({ classes: {OrbitView} }); @@ -69,7 +69,7 @@ test('JSONConverter#merge', t => { }); test('JSONConverter#badConvert', t => { - const jsonConverter = new JSONConverter({configuration}); + const jsonConverter = new JSONConverter({configuration: JSON_CONFIGURATION}); t.ok(jsonConverter, 'JSONConverter created'); const badData = JSON.parse(JSON.stringify(JSON_DATA)); badData.layers[0]['@@type'] = 'InvalidLayer'; @@ -81,7 +81,7 @@ test('JSONConverter#badConvert', t => { }); test('JSONConverter#handleTypeAsKey', t => { - const jsonConverter = new JSONConverter({configuration}); + const jsonConverter = new JSONConverter({configuration: JSON_CONFIGURATION}); t.ok(jsonConverter, 'JSONConverter created'); const complexData = JSON.parse(JSON.stringify(COMPLEX_JSON)); const deckProps = jsonConverter.convert(complexData); diff --git a/test/modules/json/json-render.spec.ts b/test/modules/json/json-render.spec.ts index bab8473c076..f4b5a5c379c 100644 --- a/test/modules/json/json-render.spec.ts +++ b/test/modules/json/json-render.spec.ts @@ -5,13 +5,12 @@ import test from 'tape-promise/tape'; import {Deck} from '@deck.gl/core'; import {JSONConverter} from '@deck.gl/json'; -import configuration from './json-configuration-for-deck'; +import {JSON_CONFIGURATION} from './json-configuration-for-deck'; import JSON_DATA from './data/deck-props.json'; import {gl} from '@deck.gl/test-utils'; test('JSONConverter#render', t => { - const jsonConverter = new JSONConverter({configuration}); - t.ok(jsonConverter, 'JSONConverter created'); + const jsonConverter = new JSONConverter({configuration: JSON_CONFIGURATION}); const deckProps = jsonConverter.convert(JSON_DATA); t.ok(deckProps, 'JSONConverter converted correctly'); diff --git a/test/modules/json/transports/transport.spec.ts b/test/modules/json/transports/transport.spec.ts index 496a5cdee6e..a0e6ef38e2f 100644 --- a/test/modules/json/transports/transport.spec.ts +++ b/test/modules/json/transports/transport.spec.ts @@ -3,7 +3,7 @@ // Copyright (c) vis.gl contributors import test from 'tape-promise/tape'; -import Transport from '@deck.gl/json/transports/transport'; +import {Transport} from '@deck.gl/json'; test('delayed onInitialized()', t => { Transport.setCallbacks({