Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 175 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@
"rimraf": "^5.0.1",
"rollup": "^4.22.4",
"rollup-plugin-includepaths": "^0.2.4",
"ts-node": "^10.9.2",
"typescript": "^5.1.6"
},
"scripts": {
"build": "rm -rf src/api/rest && npm run build:index && npm run build:generateRestBindings && rollup -c",
"dev": "rollup -c -w",
"test": "node test/test.js",
"test": "node --loader ts-node/esm --experimental-specifier-resolution=node test/test.js",
"pretest": "npm run build",
"build:index": "npx barrelsby -d ./src --delete --exclude '(jestHoc|\\.test|\\.d).(js|tsx?)$' --exportDefault --verbose",
"build:generateRestBindings": "cd ./scripts/ && tsc --downlevelIteration --resolveJsonModule generateRestBindings.ts && mv generateRestBindings.js generateRestBindings.cjs",
Expand Down
1 change: 1 addition & 0 deletions src/api/C6Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const C6Constants = {
ST_GEOMFROMWKB: 'ST_GeomFromWKB',
ST_INTERSECTS: 'ST_Intersects',
ST_LENGTH: 'ST_Length',
ST_MAKEENVELOPE: 'ST_MakeEnvelope',
ST_OVERLAPS: 'ST_Overlaps',
ST_POINT: 'ST_Point',
ST_SETSRID: 'ST_SetSRID',
Expand Down
11 changes: 11 additions & 0 deletions src/api/orm/queryHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ export const fieldEq = (leftCol: string, rightCol: string, leftAlias: string, ri
// ST_Distance_Sphere for aliased fields
export const distSphere = (fromCol: string, toCol: string, fromAlias: string, toAlias: string): any[] =>
[C6C.ST_DISTANCE_SPHERE, F(fromCol, fromAlias), F(toCol, toAlias)];

// Build a bounding-box expression.
//
// Arguments must be provided in `(minLng, minLat, maxLng, maxLat)` order. The
// helper does not attempt to swap or validate coordinates; if a minimum value
// is greater than its corresponding maximum value, MySQL's `ST_MakeEnvelope`
// returns `NULL`.
export const bbox = (minLng: number, minLat: number, maxLng: number, maxLat: number): any[] =>
[C6C.ST_SRID, [C6C.ST_MAKEENVELOPE,
[C6C.ST_POINT, minLng, minLat],
[C6C.ST_POINT, maxLng, maxLat]], 4326];
45 changes: 45 additions & 0 deletions test/queryHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import assert from 'assert';
import { bbox } from '../src/api/orm/queryHelpers.js';
import { C6C } from '../src/api/C6Constants.js';

// Verify basic bounding box construction
const expected = [
C6C.ST_SRID,
[
C6C.ST_MAKEENVELOPE,
[C6C.ST_POINT, 10, 20],
[C6C.ST_POINT, 30, 40],
],
4326,
];
const actual = bbox(10, 20, 30, 40);
assert.deepStrictEqual(actual, expected);
console.log('\u001B[32m✓\u001B[39m bbox basic structure test passed');

// Negative coordinate handling
const expectedNegative = [
C6C.ST_SRID,
[
C6C.ST_MAKEENVELOPE,
[C6C.ST_POINT, -10, -20],
[C6C.ST_POINT, -30, -40],
],
4326,
];
const actualNegative = bbox(-10, -20, -30, -40);
assert.deepStrictEqual(actualNegative, expectedNegative);
console.log('\u001B[32m✓\u001B[39m bbox negative coordinates test passed');

// Swapped min/max arguments
const expectedSwapped = [
C6C.ST_SRID,
[
C6C.ST_MAKEENVELOPE,
[C6C.ST_POINT, 30, 40],
[C6C.ST_POINT, 10, 20],
],
4326,
];
const actualSwapped = bbox(30, 40, 10, 20);
assert.deepStrictEqual(actualSwapped, expectedSwapped);
console.log('\u001B[32m✓\u001B[39m bbox swapped arguments test passed');
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './queryHelpers.test.ts';
import assert from 'assert';

// basic sanity test to ensure test infrastructure runs
Expand Down