Skip to content

Commit

Permalink
feat(schema-utils): Separate out utils from the schema module (#3114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen authored Oct 2, 2024
1 parent 4a2f920 commit 1eca278
Show file tree
Hide file tree
Showing 152 changed files with 531 additions and 235 deletions.
2 changes: 1 addition & 1 deletion modules/arrow/src/exports/geoarrow-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright (c) vis.gl contributors

import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';
import {ArrowWorkerLoader} from './arrow-loader';
import type {BinaryGeometry} from '@loaders.gl/schema';
import {ArrowWorkerLoader} from './arrow-loader';
import type {ArrowTable, ArrowTableBatch} from '../schema/arrow-table-type';

export type GeoArrowLoaderOptions = LoaderOptions & {
Expand Down
2 changes: 1 addition & 1 deletion modules/arrow/src/geoarrow-writer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import type {} from '@loaders.gl/loader-utils';

import type {WriterWithEncoder, WriterOptions} from '@loaders.gl/loader-utils';
import {GeoJSONTable, BinaryGeometry} from '@loaders.gl/schema';
import type {GeoJSONTable, BinaryGeometry} from '@loaders.gl/schema';
import {encodeGeoArrowSync} from './lib/encoders/encode-geoarrow';

// __VERSION__ is injected by babel-plugin-version-inline
Expand Down
2 changes: 1 addition & 1 deletion modules/arrow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export {VECTOR_TYPES} from './lib/types';
import {ArrowTableBatchAggregator} from './schema/arrow-table-batch';

// Make the ArrowBatch type available
import {TableBatchBuilder} from '@loaders.gl/schema';
import {TableBatchBuilder} from '@loaders.gl/schema-utils';
TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;

// Arrow loader / Writer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import * as arrow from 'apache-arrow';
import {earcut} from '@math.gl/polygon';
import {BinaryFeatureCollection as BinaryFeatures} from '@loaders.gl/schema';
import type {BinaryFeatureCollection as BinaryFeatures} from '@loaders.gl/schema';
import {GeoArrowEncoding} from '@loaders.gl/gis';
import {updateBoundsFromGeoArrowSamples} from './get-arrow-bounds';
import {TypedArray} from '@loaders.gl/loader-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) vis.gl contributors

// import * as arrow from 'apache-arrow';
import {
import type {
MultiPolygon,
Position,
Polygon,
Expand Down
2 changes: 1 addition & 1 deletion modules/arrow/src/lib/tables/convert-arrow-to-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
} from '@loaders.gl/schema';
import type {ArrowTable} from '../../schema/arrow-table-type';

import {convertTable} from '@loaders.gl/schema';
import {convertTable} from '@loaders.gl/schema-utils';
import {getGeometryColumnsFromSchema} from '@loaders.gl/gis';
import {convertArrowToSchema} from '../tables/convert-arrow-schema';
import {parseGeometryFromArrow} from '../geoarrow/convert-geoarrow-to-geojson-geometry';
Expand Down
3 changes: 2 additions & 1 deletion modules/arrow/src/lib/tables/convert-table-to-arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Copyright (c) vis.gl contributors

import * as arrow from 'apache-arrow';
import {Table, getTableLength, getTableNumCols, getTableCellAt} from '@loaders.gl/schema';
import type {Table} from '@loaders.gl/schema';
import {getTableLength, getTableNumCols, getTableCellAt} from '@loaders.gl/schema-utils';
import {deserializeArrowSchema} from '../tables/convert-arrow-schema';

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/arrow/src/schema/arrow-table-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {ColumnarTableBatchAggregator} from '@loaders.gl/schema';
import {ColumnarTableBatchAggregator} from '@loaders.gl/schema-utils';
import type {ArrowTableBatch} from './arrow-table-type';
import * as arrow from 'apache-arrow';

Expand Down
2 changes: 1 addition & 1 deletion modules/arrow/test/data/geoarrow/test-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {FeatureCollection} from '@loaders.gl/schema';
import type {FeatureCollection} from '@loaders.gl/schema';

export const GEOARROW_POINT_FILE = '@loaders.gl/arrow/test/data/geoarrow/point.arrow';
export const GEOARROW_MULTIPOINT_FILE = '@loaders.gl/arrow/test/data/geoarrow/multipoint.arrow';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import test, {Test} from 'tape-promise/tape';
import {GEOARROW_TEST_CASES, GEOARROW_ENCODINGS} from '../data/geoarrow/test-cases';

import {load} from '@loaders.gl/core';
import {FeatureCollection} from '@loaders.gl/schema';
import type {FeatureCollection} from '@loaders.gl/schema';
import {ArrowLoader, serializeArrowSchema, parseGeometryFromArrow} from '@loaders.gl/arrow';
import {getGeometryColumnsFromSchema} from '@loaders.gl/gis';

Expand Down
1 change: 1 addition & 0 deletions modules/arrow/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{"path": "../gis"},
{"path": "../loader-utils"},
{"path": "../schema"},
{"path": "../schema-utils"},
{"path": "../wkt"}
]
}
3 changes: 2 additions & 1 deletion modules/bson/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"references": [
{"path": "../loader-utils"},
{"path": "../schema"}
{"path": "../schema"},
{"path": "../schema-utils"}
]
}
1 change: 1 addition & 0 deletions modules/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"dependencies": {
"@loaders.gl/loader-utils": "^5.0.0-alpha.0",
"@loaders.gl/schema": "^5.0.0-alpha.0",
"@loaders.gl/schema-utils": "^5.0.0-alpha.0",
"@loaders.gl/worker-utils": "^5.0.0-alpha.0",
"@probe.gl/log": "^4.0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/lib/api/encode-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
WriterOptionsType,
WriterWithEncoder
} from '@loaders.gl/loader-utils';
import {Table} from '@loaders.gl/schema';
import type {Table} from '@loaders.gl/schema';

export async function encodeTable<WriterT extends WriterWithEncoder = WriterWithEncoder>(
data: Table,
Expand Down
3 changes: 2 additions & 1 deletion modules/core/src/lib/api/parse-in-batches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {isTable, makeBatchFromTable, type Batch} from '@loaders.gl/schema';
import type {Batch} from '@loaders.gl/schema';
import {isTable, makeBatchFromTable} from '@loaders.gl/schema-utils';
import type {
Loader,
LoaderWithParser,
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/lib/api/select-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import type {LoaderContext, LoaderOptions, Loader} from '@loaders.gl/loader-utils';
import {compareArrayBuffers, path, log} from '@loaders.gl/loader-utils';
import {TypedArray} from '@loaders.gl/schema';
import {normalizeLoader} from '../loader-utils/normalize-loader';
import {getResourceUrl, getResourceMIMEType} from '../utils/resource-utils';
import {compareMIMETypes} from '../utils/mime-type-utils';
import {getRegisteredLoaders} from './register-loaders';
import {isBlob} from '../../javascript-utils/is-type';
import {stripQueryString} from '../utils/url-utils';
import {TypedArray} from '@loaders.gl/schema';

const EXT_PATTERN = /\.([^.]+)$/;

Expand Down
2 changes: 1 addition & 1 deletion modules/core/test/lib/api/load-in-batches.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {loadInBatches, fetchFile, isBrowser} from '@loaders.gl/core';
import {CSVLoader} from '@loaders.gl/csv';
import {OBJLoader} from '@loaders.gl/obj';
import {KMLLoader} from '@loaders.gl/kml';
import {ObjectRowTableBatch} from '@loaders.gl/schema';
import type {ObjectRowTableBatch} from '@loaders.gl/schema';

const CSV_SAMPLE_VERY_LONG_URL = '@loaders.gl/csv/test/data/sample-very-long.csv';
const OBJ_ASCII_URL = '@loaders.gl/obj/test/data/bunny.obj';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as threeDTiles from '@loaders.gl/3d-tiles';
import * as arrow from '@loaders.gl/arrow';
import * as csv from '@loaders.gl/csv';
import * as draco from '@loaders.gl/draco';
import * as tables from '@loaders.gl/schema';
import * as tables from '@loaders.gl/schema-utils';
import * as gltf from '@loaders.gl/gltf';
import * as images from '@loaders.gl/images';
import * as kml from '@loaders.gl/kml';
Expand Down
1 change: 1 addition & 0 deletions modules/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"references": [
{"path": "../loader-utils"},
{"path": "../schema"},
{"path": "../schema-utils"},
{"path": "../worker-utils"}
]
}
2 changes: 1 addition & 1 deletion modules/csv/src/csv-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TableBatchBuilder,
convertToArrayRow,
convertToObjectRow
} from '@loaders.gl/schema';
} from '@loaders.gl/schema-utils';
import Papa from './papaparse/papaparse';
import AsyncIteratorStreamer from './papaparse/async-iterator-streamer';

Expand Down
3 changes: 2 additions & 1 deletion modules/csv/src/lib/encoders/encode-csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Copyright (c) vis.gl contributors
// Copyright 2022 Foursquare Labs, Inc.

import {Table, makeArrayRowIterator, getTableNumCols} from '@loaders.gl/schema';
import type {Table} from '@loaders.gl/schema';
import {makeArrayRowIterator, getTableNumCols} from '@loaders.gl/schema-utils';
import {csvFormatRows} from 'd3-dsv';
import type {CSVWriterOptions} from '../../csv-writer';

Expand Down
2 changes: 1 addition & 1 deletion modules/csv/test/csv-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {validateLoader} from 'test/common/conformance';

import {load, loadInBatches, isAsyncIterable} from '@loaders.gl/core';
import {CSVLoader} from '../src/csv-loader';
import {getTableLength} from '@loaders.gl/schema';
import {getTableLength} from '@loaders.gl/schema-utils';

// Small CSV Sample Files
const CSV_SAMPLE_URL = '@loaders.gl/csv/test/data/sample.csv';
Expand Down
2 changes: 1 addition & 1 deletion modules/csv/test/csv-writer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {CSVWriterOptions, CSVWriter} from '@loaders.gl/csv';
import {encodeTableAsText} from '@loaders.gl/core';

import {Table} from '@loaders.gl/schema';
import {makeTestTable, tableWithGeometryColumn} from '@loaders.gl/schema/test/shared-utils';
import {makeTestTable, tableWithGeometryColumn} from '@loaders.gl/schema-utils/test/shared-utils';

type TestCase = {
name: string;
Expand Down
3 changes: 2 additions & 1 deletion modules/csv/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"references": [
{"path": "../loader-utils"},
{"path": "../schema"}
{"path": "../schema"},
{"path": "../schema-utils"}
]
}
2 changes: 1 addition & 1 deletion modules/draco/src/lib/draco-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
DracoOctahedronTransform
} from './draco-types';

import {getMeshBoundingBox} from '@loaders.gl/schema';
import {getMeshBoundingBox} from '@loaders.gl/schema-utils';
import {getDracoSchema} from './utils/get-draco-schema';

/** Options to control draco parsing */
Expand Down
3 changes: 2 additions & 1 deletion modules/draco/src/lib/utils/get-draco-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {deduceMeshField, MeshAttribute, Schema, Field} from '@loaders.gl/schema';
import {MeshAttribute, Schema, Field} from '@loaders.gl/schema';
import {deduceMeshField} from '@loaders.gl/schema-utils';
import type {DracoAttribute, DracoLoaderData, DracoMetadataEntry} from '../draco-types';

/** Extract an arrow-like schema from a Draco mesh */
Expand Down
2 changes: 1 addition & 1 deletion modules/draco/test/draco-compression-ratio.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-len */
import test from 'tape-promise/tape';
import {fetchFile, parse, encode} from '@loaders.gl/core';
import {getMeshSize} from '@loaders.gl/schema';
// import {getMeshSize} from '@loaders.gl/schema-utils';
import {DracoWriter, DracoLoader} from '@loaders.gl/draco';
import {validateMeshCategoryData} from 'test/common/conformance';

Expand Down
1 change: 1 addition & 0 deletions modules/draco/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"references": [
{"path": "../loader-utils"},
{"path": "../schema"},
{"path": "../schema-utils"},
{"path": "../worker-utils"},
{"path": "../polyfills"}
]
Expand Down
4 changes: 4 additions & 0 deletions modules/excel/src/lib/parse-excel.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// loaders.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import type {ExcelLoaderOptions} from '../excel-loader';
import {utils, read} from 'xlsx';
// import {convertToArrayRow} from '@loaders.gl/schema';
Expand Down
4 changes: 4 additions & 0 deletions modules/excel/test/excel-loader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// loaders.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import test from 'tape-promise/tape';
import {load, loadInBatches} from '@loaders.gl/core';
import type {ObjectRowTable, ObjectRowTableBatch} from '@loaders.gl/schema';
Expand Down
10 changes: 9 additions & 1 deletion modules/geopackage/src/lib/parse-geopackage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/* eslint-disable camelcase, @typescript-eslint/no-use-before-define */
import {isBrowser} from '@loaders.gl/loader-utils';
import {WKBLoader} from '@loaders.gl/wkt';
import {Schema, Field, Geometry, DataType, Tables, GeoJSONTable, Feature} from '@loaders.gl/schema';
import type {
Schema,
Field,
Geometry,
DataType,
Tables,
GeoJSONTable,
Feature
} from '@loaders.gl/schema';
import {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';
import {Proj4Projection} from '@math.gl/proj4';
import initSqlJs, {SqlJsStatic, Database, Statement} from 'sql.js';
Expand Down
2 changes: 1 addition & 1 deletion modules/geopackage/test/geopackage-loader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'tape-promise/tape';
import {load, fetchFile} from '@loaders.gl/core';
import {GeoPackageLoader} from '@loaders.gl/geopackage';
// import {Tables, ObjectRowTable, Feature} from '@loaders.gl/schema';
// import type {Tables, ObjectRowTable, Feature} from '@loaders.gl/schema';

const GPKG_RIVERS = '@loaders.gl/geopackage/test/data/rivers_small.gpkg';
const GPKG_RIVERS_GEOJSON = '@loaders.gl/geopackage/test/data/rivers_small.geojson';
Expand Down
6 changes: 5 additions & 1 deletion modules/gis/src/lib/binary-features/extract-geometry-info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';
// loaders.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import type {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';

/**
* Initial scan over GeoJSON features
Expand Down
2 changes: 1 addition & 1 deletion modules/gis/src/lib/tables/convert-table-to-geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
Feature,
Geometry
} from '@loaders.gl/schema';
import {getTableLength, getTableRowAsObject} from '@loaders.gl/schema';
import {getTableLength, getTableRowAsObject} from '@loaders.gl/schema-utils';

import {GeoColumnMetadata, getGeoMetadata} from '../geo/geoparquet-metadata';

Expand Down
3 changes: 2 additions & 1 deletion modules/gis/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"references": [
{"path": "../loader-utils"},
{"path": "../schema"}
{"path": "../schema"},
{"path": "../schema-utils"}
]
}
3 changes: 2 additions & 1 deletion modules/json/src/lib/encoder-utils/encode-table-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Copyright (c) vis.gl contributors
// Copyright 2022 Foursquare Labs, Inc.

import {Feature, Table, getTableRowAsObject} from '@loaders.gl/schema';
import type {Feature, Table} from '@loaders.gl/schema';
import {getTableRowAsObject} from '@loaders.gl/schema-utils';
import {getRowPropertyObject} from './encode-utils';
import {Utf8ArrayBufferEncoder} from './utf8-encoder';

Expand Down
3 changes: 2 additions & 1 deletion modules/json/src/lib/encoder-utils/encode-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Copyright (c) vis.gl contributors
// Copyright 2022 Foursquare Labs, Inc.

import {Table, getTableLength, getTableNumCols, getTableRowAsArray} from '@loaders.gl/schema';
import type {Table} from '@loaders.gl/schema';
import {getTableLength, getTableNumCols, getTableRowAsArray} from '@loaders.gl/schema-utils';

type Row = {[key: string]: unknown};

Expand Down
2 changes: 1 addition & 1 deletion modules/json/src/lib/encoders/geojson-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright 2022 Foursquare Labs, Inc.

import type {TableBatch} from '@loaders.gl/schema';
import {getTableLength} from '@loaders.gl/schema';
import {getTableLength} from '@loaders.gl/schema-utils';
import {detectGeometryColumnIndex} from '../encoder-utils/encode-utils';
import {encodeTableRow} from '../encoder-utils/encode-table-row';
import {Utf8ArrayBufferEncoder} from '../encoder-utils/utf8-encoder';
Expand Down
3 changes: 2 additions & 1 deletion modules/json/src/lib/encoders/json-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Copyright (c) vis.gl contributors
// Copyright 2022 Foursquare Labs, Inc.

import {Table, makeRowIterator} from '@loaders.gl/schema';
import type {Table} from '@loaders.gl/schema';
import {makeRowIterator} from '@loaders.gl/schema-utils';
import type {JSONWriterOptions} from '../../json-writer';

/**
Expand Down
3 changes: 2 additions & 1 deletion modules/json/src/lib/parsers/parse-json-in-batches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import type {Schema, TableBatch} from '@loaders.gl/schema';
import type {JSONLoaderOptions, MetadataBatch, JSONBatch} from '../../json-loader';
import {TableBatchBuilder} from '@loaders.gl/schema';

import {TableBatchBuilder} from '@loaders.gl/schema-utils';
import {assert, makeTextDecoderIterator} from '@loaders.gl/loader-utils';
import StreamingJSONParser from '../json-parser/streaming-json-parser';
import JSONPath from '../jsonpath/jsonpath';
Expand Down
2 changes: 1 addition & 1 deletion modules/json/src/lib/parsers/parse-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) vis.gl contributors

import type {RowTable} from '@loaders.gl/schema';
import {makeTableFromData} from '@loaders.gl/schema';
import {makeTableFromData} from '@loaders.gl/schema-utils';
import type {JSONLoaderOptions} from '../../json-loader';

export function parseJSONSync(jsonText: string, options: JSONLoaderOptions): RowTable {
Expand Down
2 changes: 1 addition & 1 deletion modules/json/src/lib/parsers/parse-ndjson-in-batches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) vis.gl contributors

import type {TableBatch} from '@loaders.gl/schema';
import {TableBatchBuilder} from '@loaders.gl/schema';
import {TableBatchBuilder} from '@loaders.gl/schema-utils';
import {
LoaderOptions,
makeLineIterator,
Expand Down
Loading

0 comments on commit 1eca278

Please sign in to comment.