open-vector-tile
Version:
This library reads/writes Open Vector Tiles
87 lines • 3.77 kB
TypeScript
import type { ColumnCacheReader, ColumnCacheWriter } from './columnCache.js';
import type { Properties as OProperties, Properties } from 's2json-spec';
/**
* Primitive types that can be found in a shape
*/
export type PrimitiveShapes = 'string' | 'f32' | 'f64' | 'u64' | 'i64' | 'bool' | 'null';
/** The Shape Object But the values can only be primitives */
export interface ShapePrimitive {
[key: string]: PrimitiveShapes;
}
/**
* Arrays may contain either a primitive or an object whose values are primitives
*/
export type ShapePrimitiveType = PrimitiveShapes | ShapePrimitive;
/**
* Shape types that can be found in a shapes object.
* Either a primitive, an array containing any type, or a nested shape.
* If the type is an array, all elements must be the same type
*/
export type ShapeType = PrimitiveShapes | [ShapePrimitiveType] | Shape;
/** The Shape Object */
export interface Shape {
[key: string]: ShapeType;
}
/**
* Create shapes
*
* Used by Layer's and Feature's M-Values
* Must be an object of key values
* all keys will be the same, values will be different
* A layer's Shape defines what the properties look like for every Feature in that layer
* so we only have to store the properties and M-Value shape **once** per layer.
* @param cache - the cache where all data is stored in a column format
* @param shape - the shape object to encode
* @returns - The index of where the shape was stored in the cache
*/
export declare function encodeShape(cache: ColumnCacheWriter, shape: Shape): number;
/**
* @param shapeIndex - the index to the key indices and whether the value is an object or not
* @param cache - the cache where all data is stored in a column format
* @returns - The shape object
*/
export declare function decodeShape(shapeIndex: number, cache: ColumnCacheReader): Shape;
/**
* @param value - the value to encode
* @param shape - the shape of the value
* @param cache - the cache where all data is stored in a column format
* @returns - The index of where the value was stored in the cache
*/
export declare function encodeValue(value: OProperties, shape: Shape, cache: ColumnCacheWriter): number;
/**
* @param valueIndex - the index of the encoded value in the cache
* @param shape - the shape of the value to decode
* @param cache - the cache where all data is stored in a column format
* @returns The decoded value
*/
export declare function decodeValue(valueIndex: number, shape: Shape, cache: ColumnCacheReader): OProperties;
/**
* A shape pair for stronger compression and decoding
*/
export interface ShapePair {
/** The type (0 - array, 1 - object, 2 - value) */
type: 0 | 1 | 2;
/** the length if object or array; or the column to read from */
countOrCol: number;
}
/**
* @param data - the data to create the shape from
* @returns - the shape type we want to create based upon the data
*/
export declare function createShapeFromData(data: OProperties[] | Properties[]): Shape;
/**
* Update/Mutate the shape from the data provided
* @param shape - the shape
* @param data - the data to update the shape
*/
export declare function updateShapeFromData(shape: Shape, data: OProperties | Properties): void;
/**
* This is primarily to check if the type is a primitive.
* If the primitive is a number, find the "depth", the most complex is f64, then i64, then u64.
* Otherwise, if the primitives don't match, throw an error.
* If the type is NOT a primitive, ensure that all types in the array match
* @param types - either a primitive type, array, or object
* @returns - a single type from the list to validate the correct type to be parsed from values later
*/
export declare function validateTypes(types: ShapeType[]): ShapeType;
//# sourceMappingURL=shape.d.ts.map