the editable site (validation-lab)

This commit is contained in:
kpgarrod committed 2026-11-21 08:03:55 +01:00
commit 3ac81d5a52
13454 files changed
+2227005

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
export type CompareFunction<T> = (a: T, b: T) => number;
export declare function quickselect<T>(arr: T[], k: number, left: number, right: number, compare: CompareFunction<T>): void;
@@ -0,0 +1 @@
export {};
+35
View File
@@ -0,0 +1,35 @@
export type Node = {
children: Node[];
height: number;
leaf: boolean;
minX: number;
minY: number;
maxX: number;
maxY: number;
};
export declare class RBush {
private _maxEntries;
private _minEntries;
private data;
constructor(maxEntries: number);
search(bbox: Node): Node[];
collides(bbox: Node): boolean;
load(data: Node[]): void;
insert(item: Node): void;
clear(): void;
remove(item: Node): void;
private toBBox;
private compareMinX;
private compareMinY;
private _all;
private _build;
private _chooseSubtree;
private _insert;
private _split;
private _splitRoot;
private _chooseSplitIndex;
private _chooseSplitAxis;
private _allDistMargin;
private _adjustParentBBoxes;
private _condense;
}
+1
View File
@@ -0,0 +1 @@
export {};
+18
View File
@@ -0,0 +1,18 @@
import { FeatureId, GeoJSONStoreFeatures } from "../store";
export declare class SpatialIndex {
private tree;
private idToNode;
private nodeToId;
constructor(options?: {
maxEntries: number;
});
private setMaps;
private toBBox;
insert(feature: GeoJSONStoreFeatures): void;
load(features: GeoJSONStoreFeatures[]): void;
update(feature: GeoJSONStoreFeatures): void;
remove(featureId: FeatureId): void;
clear(): void;
search(feature: GeoJSONStoreFeatures): FeatureId[];
collides(feature: GeoJSONStoreFeatures): boolean;
}
@@ -0,0 +1 @@
export {};
+22
View File
@@ -0,0 +1,22 @@
import { Validation } from "../common";
import { FeatureId, IdStrategy } from "./store";
export declare const StoreValidationErrors: {
readonly FeatureHasNoId: "Feature has no id";
readonly FeatureIsNotObject: "Feature is not object";
readonly InvalidTrackedProperties: "updatedAt and createdAt are not valid timestamps";
readonly FeatureHasNoMode: "Feature does not have a set mode";
readonly FeatureIdIsNotValidGeoJSON: "Feature must be string or number as per GeoJSON spec";
readonly FeatureIdIsNotValid: "Feature must match the id strategy (default is UUID4)";
readonly FeatureHasNoGeometry: "Feature has no geometry";
readonly FeatureHasNoProperties: "Feature has no properties";
readonly FeatureGeometryNotSupported: "Feature is not Point, LineString or Polygon";
readonly FeatureCoordinatesNotAnArray: "Feature coordinates is not an array";
readonly InvalidModeProperty: "Feature does not have a valid mode property";
};
export declare function hasModeProperty(feature: unknown): feature is {
properties: {
mode: string;
};
};
export declare function isValidTimestamp(timestamp: unknown): boolean;
export declare function isValidStoreFeature(feature: unknown, isValidId: IdStrategy<FeatureId>["isValidId"]): ReturnType<Validation>;
+1
View File
@@ -0,0 +1 @@
export {};
+65
View File
@@ -0,0 +1,65 @@
import { Feature, Point, Polygon, LineString } from "geojson";
import { Validation } from "../common";
export type JSON = string | number | boolean | null | JSONArray | JSONObject;
export interface JSONObject {
[member: string]: JSON;
}
type JSONArray = Array<JSON>;
type DefinedProperties = Record<string, JSON>;
export type GeoJSONStoreGeometries = Polygon | LineString | Point;
export type BBoxPolygon = Feature<Polygon, DefinedProperties>;
export type GeoJSONStoreFeatures<G extends GeoJSONStoreGeometries = GeoJSONStoreGeometries> = Feature<G, DefinedProperties>;
export type StoreValidation = {
id?: FeatureId;
} & ReturnType<Validation>;
type StoreChangeEvents = "delete" | "create" | "update" | "styling";
export type StoreChangeHandler<OnChangeContext> = (ids: FeatureId[], change: StoreChangeEvents, context?: OnChangeContext) => void;
export type FeatureId = string | number;
export type IdStrategy<Id extends FeatureId> = {
isValidId: (id: Id) => boolean;
getId: () => Id;
};
type GeoJSONStoreConfig<Id extends FeatureId> = {
idStrategy?: IdStrategy<Id>;
tracked?: boolean;
};
export declare const defaultIdStrategy: {
getId: <FeatureId>() => FeatureId;
isValidId: (id: FeatureId) => boolean;
};
export declare class GeoJSONStore<OnChangeContext extends JSONObject | undefined, Id extends FeatureId = FeatureId> {
constructor(config?: GeoJSONStoreConfig<Id>);
idStrategy: IdStrategy<Id>;
private tracked;
private spatialIndex;
private store;
private _onChange;
private clone;
getId(): FeatureId;
has(id: FeatureId): boolean;
load(data: GeoJSONStoreFeatures[], featureValidation?: (feature: unknown, tracked?: boolean) => StoreValidation, afterFeatureAdded?: (feature: GeoJSONStoreFeatures) => void, context?: OnChangeContext): StoreValidation[];
search(bbox: BBoxPolygon, filter?: (feature: GeoJSONStoreFeatures) => boolean): GeoJSONStoreFeatures<GeoJSONStoreGeometries>[];
registerOnChange(onChange: StoreChangeHandler<OnChangeContext | undefined>): void;
getGeometryCopy<T extends GeoJSONStoreGeometries>(id: FeatureId): T;
getPropertiesCopy(id: FeatureId): DefinedProperties;
updateProperty(propertiesToUpdate: {
id: FeatureId;
property: string;
value: JSON | undefined;
}[], context?: OnChangeContext): void;
updateGeometry(geometriesToUpdate: {
id: FeatureId;
geometry: GeoJSONStoreGeometries;
}[], context?: OnChangeContext): void;
create<Id extends FeatureId>(features: {
geometry: GeoJSONStoreGeometries;
properties?: JSONObject;
}[], context?: OnChangeContext): Id[];
delete(ids: FeatureId[], context?: OnChangeContext): void;
copy(id: FeatureId): GeoJSONStoreFeatures;
copyAll(): GeoJSONStoreFeatures[];
copyAllWhere(equals: (properties: JSONObject) => boolean): GeoJSONStoreFeatures[];
clear(context: OnChangeContext): void;
size(): number;
}
export {};
+1
View File
@@ -0,0 +1 @@
export {};
+6
View File
@@ -0,0 +1,6 @@
/**
* Checks if a value is a valid JSON value.
* @param value - The value to check
* @returns true if the value is valid JSON, false otherwise
*/
export declare function isValidJSONValue(value: unknown): value is JSON;
+1
View File
@@ -0,0 +1 @@
export {};