Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Chore]: Technical: Isolate schemas (#1962)

dariaterekhovaae9b81e49f33c8
diff --git a/package.json b/package.json
index c4b9dd8b9..f5ace2218 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
"./src/middleware",
"./src/deckgl-layers",
"./src/layers",
+ "./src/schemas",
"./src/table",
"./src/cloud-providers",
"./src/processors",
@@ -63,7 +64,7 @@
"start:web": "yarn install-and-start -- website start",
"start:https": "yarn install-and-start -- examples/demo-app start-local-https",
"start:e2e": "yarn install-and-start -- examples/demo-app start-local-e2e",
- "build": "rm -fr dist && babel src/{actions,components,middleware,reducers,cloud-providers,connect,localization,schemas,tasks} --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src/{actions,components,middleware,reducers,cloud-providers,connect,localization,tasks} --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:umd": "webpack --config ./webpack/umd.js --progress --env.prod",
"build:types": "tsc --project tsconfig.production.json",
"analyze": "yarn analyze:bundle",
diff --git a/src/components/geocoder-panel.tsx b/src/components/geocoder-panel.tsx
index 2bb4f8a5b..82b358b47 100644
--- a/src/components/geocoder-panel.tsx
+++ b/src/components/geocoder-panel.tsx
@@ -22,7 +22,7 @@ import React, {Component, ComponentType} from 'react';
import styled from 'styled-components';
import {processRowObject} from '@kepler.gl/processors';
import {FlyToInterpolator} from '@deck.gl/core';
-import KeplerGlSchema from 'schemas';
+import KeplerGlSchema from '@kepler.gl/schemas';
import {getCenterAndZoomFromBounds} from '@kepler.gl/utils';
import Geocoder, {Result} from './geocoder/geocoder';
diff --git a/src/processors/src/data-processor.ts b/src/processors/src/data-processor.ts
index 12e9d3bb8..5fcd716ba 100644
--- a/src/processors/src/data-processor.ts
+++ b/src/processors/src/data-processor.ts
@@ -31,9 +31,8 @@ import {
getFieldsFromData,
toArray
} from '@kepler.gl/utils';
-import {KeplerGlSchema, ParsedDataset, SavedMap} from 'schemas';
+import {KeplerGlSchema, ParsedDataset, SavedMap, LoadedMap} from '@kepler.gl/schemas';
import {Feature} from '@nebula.gl/edit-modes';
-import {LoadedMap} from 'schemas/schema-manager';
// if any of these value occurs in csv, parse it to null;
// const CSV_NULLS = ['', 'null', 'NULL', 'Null', 'NaN', '/N'];
diff --git a/src/reducers/src/vis-state-merger.ts b/src/reducers/src/vis-state-merger.ts
index ebe22ab85..748cee4f6 100644
--- a/src/reducers/src/vis-state-merger.ts
+++ b/src/reducers/src/vis-state-merger.ts
@@ -25,7 +25,13 @@ import {isObject, arrayInsert, getInitialMapLayersForSplitMap} from '@kepler.gl/
import {LayerColumns, LayerColumn, Layer} from '@kepler.gl/layers';
import {LAYER_BLENDINGS} from '@kepler.gl/constants';
-import {CURRENT_VERSION, Merger, VisState, VisStateMergers, visStateSchema} from 'schemas';
+import {
+ CURRENT_VERSION,
+ Merger,
+ VisState,
+ VisStateMergers,
+ visStateSchema
+} from '@kepler.gl/schemas';
import {ParsedConfig} from 'schemas';
import {ParsedLayer, SavedInteractionConfig, TooltipInfo} from '@kepler.gl/types';
diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.ts
index 352779587..c6b2a3239 100644
--- a/src/reducers/src/vis-state-updaters.ts
+++ b/src/reducers/src/vis-state-updaters.ts
@@ -73,7 +73,7 @@ import {
} from '@kepler.gl/constants';
import {pick_, merge_, swap_} from './composer-helpers';
-import KeplerGLSchema, {VisState} from 'schemas';
+import KeplerGLSchema, {VisState} from '@kepler.gl/schemas';
import {Filter, InteractionConfig, AnimationConfig, Editor} from '@kepler.gl/types';
import {Loader} from '@loaders.gl/loader-utils';
diff --git a/src/schemas/babel.config.js b/src/schemas/babel.config.js
new file mode 100644
index 000000000..8693d21ea
--- /dev/null
+++ b/src/schemas/babel.config.js
@@ -0,0 +1,66 @@
+// Copyright (c) 2022 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+const KeplerPackage = require('./package');
+
+const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'];
+const PLUGINS = [
+ ['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}],
+ '@babel/plugin-transform-modules-commonjs',
+ '@babel/plugin-proposal-class-properties',
+ '@babel/plugin-proposal-export-namespace-from',
+ '@babel/plugin-proposal-optional-chaining',
+ [
+ '@babel/transform-runtime',
+ {
+ regenerator: true
+ }
+ ],
+ [
+ 'search-and-replace',
+ {
+ rules: [
+ {
+ search: '__PACKAGE_VERSION__',
+ replace: KeplerPackage.version
+ }
+ ]
+ }
+ ]
+];
+const ENV = {
+ test: {
+ plugins: ['istanbul']
+ },
+ debug: {
+ sourceMaps: 'inline',
+ retainLines: true
+ }
+};
+
+module.exports = function babel(api) {
+ api.cache(true);
+
+ return {
+ presets: PRESETS,
+ plugins: PLUGINS,
+ env: ENV
+ };
+};
diff --git a/src/schemas/package.json b/src/schemas/package.json
new file mode 100644
index 000000000..6245d02b8
--- /dev/null
+++ b/src/schemas/package.json
@@ -0,0 +1,65 @@
+{
+ "name": "@kepler.gl/schemas",
+ "author": "Shan He <[email protected]>",
+ "version": "2.5.5",
+ "description": "kepler.gl schemas used by kepler.gl components, actions and reducers",
+ "license": "MIT",
+ "main": "dist/index.js",
+ "types": "index.d.ts",
+ "keywords": [
+ "babel",
+ "es6",
+ "react",
+ "webgl",
+ "visualization",
+ "deck.gl"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/keplergl/kepler.gl.git"
+ },
+ "scripts": {
+ "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build:umd": "webpack --config ./webpack/umd.js --progress --env.prod",
+ "build:types": "tsc --project ./tsconfig.production.json",
+ "prepublish": "uber-licence && yarn build && yarn build:types",
+ "stab": "mkdir -p dist && touch dist/index.js"
+ },
+ "files": [
+ "dist",
+ "umd"
+ ],
+ "dependencies": {
+ "@babel/runtime": "^7.12.1",
+ "colorbrewer": "^1.5.0",
+ "d3-scale": "^3.2.3",
+ "global": "^4.3.0",
+ "keymirror": "^0.1.1",
+ "react-map-gl-draw": "0.14.8",
+ "@kepler.gl/types": "2.5.5"
+ },
+ "exports": {
+ ".": "./dist/index.js",
+ "./*": "./dist/*"
+ },
+ "typesVersions": {
+ "*": {
+ "*": ["dist/*"]
+ }
+ },
+ "nyc": {
+ "sourceMap": false,
+ "instrument": false
+ },
+ "engines": {
+ "node": ">=12.0.0"
+ },
+ "maintainers": [
+ "Shan He <[email protected]>",
+ "Giuseppe Macri <[email protected]>"
+ ],
+ "volta": {
+ "node": "12.22.0",
+ "yarn": "1.22.17"
+ }
+}
diff --git a/src/schemas/dataset-schema.ts b/src/schemas/src/dataset-schema.ts
similarity index 98%
rename from src/schemas/dataset-schema.ts
rename to src/schemas/src/dataset-schema.ts
index 3ab95e8df..524f1338d 100644
--- a/src/schemas/dataset-schema.ts
+++ b/src/schemas/src/dataset-schema.ts
@@ -21,9 +21,8 @@
import pick from 'lodash.pick';
import {console as globalConsole} from 'global/window';
-import {ProtoDataset} from '@kepler.gl/types';
+import {ProtoDataset, RGBColor} from '@kepler.gl/types';
import {KeplerTable} from '@kepler.gl/table';
-import {RGBColor} from 'types';
import {VERSIONS} from './versions';
import Schema from './schema';
import {getFieldsFromData, getSampleForTypeAnalyze} from '@kepler.gl/utils';
diff --git a/src/schemas/index.ts b/src/schemas/src/index.ts
similarity index 98%
rename from src/schemas/index.ts
rename to src/schemas/src/index.ts
index d3c59e009..5010b7a2e 100644
--- a/src/schemas/index.ts
+++ b/src/schemas/src/index.ts
@@ -30,7 +30,8 @@ export {
export type {
ParsedConfig,
SavedConfigV1,
- SavedMap
+ SavedMap,
+ LoadedMap
} from './schema-manager';
export {CURRENT_VERSION, VERSIONS} from './versions';
export {
diff --git a/src/schemas/map-state-schema.ts b/src/schemas/src/map-state-schema.ts
similarity index 100%
rename from src/schemas/map-state-schema.ts
rename to src/schemas/src/map-state-schema.ts
diff --git a/src/schemas/map-style-schema.ts b/src/schemas/src/map-style-schema.ts
similarity index 100%
rename from src/schemas/map-style-schema.ts
rename to src/schemas/src/map-style-schema.ts
diff --git a/src/schemas/schema-manager.ts b/src/schemas/src/schema-manager.ts
similarity index 100%
rename from src/schemas/schema-manager.ts
rename to src/schemas/src/schema-manager.ts
diff --git a/src/schemas/schema-utils.ts b/src/schemas/src/schema-utils.ts
similarity index 100%
rename from src/schemas/schema-utils.ts
rename to src/schemas/src/schema-utils.ts
diff --git a/src/schemas/schema.ts b/src/schemas/src/schema.ts
similarity index 100%
rename from src/schemas/schema.ts
rename to src/schemas/src/schema.ts
diff --git a/src/schemas/versions.ts b/src/schemas/src/versions.ts
similarity index 100%
rename from src/schemas/versions.ts
rename to src/schemas/src/versions.ts
diff --git a/src/schemas/vis-state-schema.ts b/src/schemas/src/vis-state-schema.ts
similarity index 100%
rename from src/schemas/vis-state-schema.ts
rename to src/schemas/src/vis-state-schema.ts
diff --git a/src/schemas/tsconfig.production.json b/src/schemas/tsconfig.production.json
new file mode 100644
index 000000000..c0f69724d
--- /dev/null
+++ b/src/schemas/tsconfig.production.json
@@ -0,0 +1,35 @@
+{
+ "compilerOptions": {
+ "target": "es2020",
+ "allowJs": false,
+ "checkJs": false,
+ "jsx": "react",
+ "module": "esnext",
+ "moduleResolution": "node",
+ "declaration":true,
+ "emitDeclarationOnly":true,
+ "noImplicitAny": false,
+ "noImplicitReturns": true,
+ "noImplicitThis": true,
+ "noUnusedLocals": true,
+ "outDir": "dist",
+ "sourceMap": true,
+ "strictNullChecks": true,
+ "suppressImplicitAnyIndexErrors": false,
+ "esModuleInterop": true,
+ "allowSyntheticDefaultImports": true,
+ "skipLibCheck": true,
+ "strict": true,
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "baseUrl": "./src",
+ "paths": {
+ "*": ["*"]
+ }
+ },
+ "include": [
+ "src"
+ ],
+ "exclude": [
+ ]
+}
diff --git a/src/schemas/webpack/umd.js b/src/schemas/webpack/umd.js
new file mode 100644
index 000000000..3eb025d5e
--- /dev/null
+++ b/src/schemas/webpack/umd.js
@@ -0,0 +1,120 @@
+// Copyright (c) 2022 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+const resolve = require('path').resolve;
+const join = require('path').join;
+
+// Import package.json to read version
+const KeplerPackage = require('../package');
+
+const SRC_DIR = resolve(__dirname, '../src');
+const OUTPUT_DIR = resolve(__dirname, '../umd');
+
+const LIBRARY_BUNDLE_CONFIG = env => ({
+ entry: {
+ KeplerGl: join(SRC_DIR, 'index.ts')
+ },
+
+ // Silence warnings about big bundles
+ stats: {
+ warnings: false
+ },
+
+ output: {
+ // Generate the bundle in dist folder
+ path: OUTPUT_DIR,
+ filename: 'keplergl.min.js',
+ globalObject: 'this',
+ library: '[name]',
+ libraryTarget: 'umd'
+ },
+
+ // let's put everything in
+ externals: {
+ react: {
+ root: 'React',
+ commonjs2: 'react',
+ commonjs: 'react',
+ amd: 'react',
+ umd: 'react'
+ },
+ 'react-dom': {
+ root: 'ReactDOM',
+ commonjs2: 'react-dom',
+ commonjs: 'react-dom',
+ amd: 'react-dom',
+ umd: 'react-dom'
+ },
+ redux: {
+ root: 'Redux',
+ commonjs2: 'redux',
+ commonjs: 'redux',
+ amd: 'redux',
+ umd: 'redux'
+ },
+ 'react-redux': {
+ root: 'ReactRedux',
+ commonjs2: 'react-redux',
+ commonjs: 'react-redux',
+ amd: 'react-redux',
+ umd: 'react-redux'
+ },
+ 'styled-components': {
+ commonjs: 'styled-components',
+ commonjs2: 'styled-components',
+ amd: 'styled-components',
+ root: 'styled'
+ }
+ },
+ resolve: {
+ extensions: ['.tsx', '.ts', '.js'],
+ modules: ['node_modules', SRC_DIR]
+ },
+ module: {
+ rules: [
+ {
+ test: /\.(js|ts|tsx)$/,
+ loader: 'babel-loader',
+ include: [SRC_DIR],
+ options: {
+ plugins: [
+ [
+ 'search-and-replace',
+ {
+ rules: [
+ {
+ search: '__PACKAGE_VERSION__',
+ replace: KeplerPackage.version
+ }
+ ]
+ }
+ ]
+ ]
+ }
+ }
+ ]
+ },
+
+ node: {
+ fs: 'empty'
+ }
+});
+
+module.exports = env => LIBRARY_BUNDLE_CONFIG(env);
diff --git a/test/node/reducers/map-style-test.js b/test/node/reducers/map-style-test.js
index d46fa0b5b..874293c56 100644
--- a/test/node/reducers/map-style-test.js
+++ b/test/node/reducers/map-style-test.js
@@ -28,7 +28,7 @@ import {
getInitialInputStyle
} from '@kepler.gl/reducers';
import {keplerGlInit, receiveMapConfig} from '@kepler.gl/actions';
-import SchemaManager from 'schemas';
+import SchemaManager from '@kepler.gl/schemas';
import {DEFAULT_MAP_STYLES, DEFAULT_MAPBOX_API_URL} from '@kepler.gl/constants';
// helpers
diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.js
index 37f0d4108..7bd7d8d21 100644
--- a/test/node/reducers/vis-state-merger-test.js
+++ b/test/node/reducers/vis-state-merger-test.js
@@ -33,7 +33,7 @@ import {
defaultInteractionConfig
} from '@kepler.gl/reducers';
-import SchemaManager from 'schemas';
+import SchemaManager from '@kepler.gl/schemas';
import {processKeplerglJSON} from '@kepler.gl/processors';
import {updateVisData, receiveMapConfig, addDataToMap} from '@kepler.gl/actions';
diff --git a/test/node/schemas/dataset-schema-test.js b/test/node/schemas/dataset-schema-test.js
index 67b5fda2f..a220c95d6 100644
--- a/test/node/schemas/dataset-schema-test.js
+++ b/test/node/schemas/dataset-schema-test.js
@@ -20,7 +20,7 @@
import test from 'tape';
import cloneDeep from 'lodash.clonedeep';
-import SchemaManager from 'schemas';
+import SchemaManager from '@kepler.gl/schemas';
// fixtures
import {
diff --git a/test/node/schemas/map-state-schema-test.js b/test/node/schemas/map-state-schema-test.js
index fa5e79937..4b8c1fbec 100644
--- a/test/node/schemas/map-state-schema-test.js
+++ b/test/node/schemas/map-state-schema-test.js
@@ -20,7 +20,7 @@
import test from 'tape';
import cloneDeep from 'lodash.clonedeep';
-import SchemaManager from 'schemas';
+import SchemaManager from '@kepler.gl/schemas';
import {InitialState} from 'test/helpers/mock-state';
test('#mapStateSchema -> v1 -> save load mapState', t => {
diff --git a/test/node/schemas/map-style-schema-test.js b/test/node/schemas/map-style-schema-test.js
index 3ee0b214a..9154c330f 100644
--- a/test/node/schemas/map-style-schema-test.js
+++ b/test/node/schemas/map-style-schema-test.js
@@ -20,7 +20,7 @@
import test from 'tape';
import cloneDeep from 'lodash.clonedeep';
-import SchemaManager from 'schemas';
+import SchemaManager from '@kepler.gl/schemas';
import {InitialState, StateWCustomMapStyle} from 'test/helpers/mock-state';
test('#mapStyleSchema -> v1 -> save load mapStyle', t => {
diff --git a/test/node/schemas/schema-conversion-test.js b/test/node/schemas/schema-conversion-test.js
index 86b16b893..4b2dfa66e 100644
--- a/test/node/schemas/schema-conversion-test.js
+++ b/test/node/schemas/schema-conversion-test.js
@@ -20,7 +20,7 @@
import test from 'tape';
-import SchemaManager from 'schemas';
+import SchemaManager from '@kepler.gl/schemas';
import {cmpParsedAppConfigs} from 'test/helpers/comparison-utils';
import {logStep} from '../../../scripts/log';
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index dc466989f..4b89e1716 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -21,7 +21,7 @@
import test from 'tape';
import cloneDeep from 'lodash.clonedeep';
import {cmpFilters, cmpSavedLayers} from 'test/helpers/comparison-utils';
-import SchemaManager from 'schemas';
+import SchemaManager from '@kepler.gl/schemas';
import {
StateWFilesFiltersLayerColor,