squirreling 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.d.ts +2 -0
- package/src/index.js +1 -1
- package/src/spatial/bbox.js +3 -3
- package/src/spatial/geometry.d.ts +1 -1
- package/src/spatial/index.d.ts +6 -0
- package/src/spatial/index.js +3 -0
- package/src/spatial/spatial.js +19 -53
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -76,6 +76,8 @@ export function tokenizeSql(sql: string): Token[]
|
|
|
76
76
|
*/
|
|
77
77
|
export function collect<T>(asyncGen: AsyncGenerator<AsyncRow>): Promise<Record<string, SqlPrimitive>[]>
|
|
78
78
|
|
|
79
|
+
export function asyncRow(row: Record<string, SqlPrimitive>, columns: string[]): AsyncRow
|
|
80
|
+
|
|
79
81
|
export function cachedDataSource(source: AsyncDataSource): AsyncDataSource
|
|
80
82
|
|
|
81
83
|
/**
|
package/src/index.js
CHANGED
|
@@ -3,5 +3,5 @@ export { parseSql } from './parse/parse.js'
|
|
|
3
3
|
export { planSql } from './plan/plan.js'
|
|
4
4
|
export { tokenizeSql } from './parse/tokenize.js'
|
|
5
5
|
export { collect } from './execute/utils.js'
|
|
6
|
-
export { cachedDataSource } from './backend/dataSource.js'
|
|
6
|
+
export { asyncRow, cachedDataSource } from './backend/dataSource.js'
|
|
7
7
|
export { derivedAlias } from './expression/alias.js'
|
package/src/spatial/bbox.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import {
|
|
2
|
+
* @import { BoundingBox, SimpleGeometry } from './geometry.js'
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export const EPSILON = 1e-10
|
|
6
6
|
export const EPSILON_SQ = EPSILON * EPSILON
|
|
7
7
|
|
|
8
|
-
/** @type {WeakMap<SimpleGeometry,
|
|
8
|
+
/** @type {WeakMap<SimpleGeometry, BoundingBox>} */
|
|
9
9
|
const bboxCache = new WeakMap()
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -26,7 +26,7 @@ export function bboxOverlap(a, b) {
|
|
|
26
26
|
* Results are cached per geometry object.
|
|
27
27
|
*
|
|
28
28
|
* @param {SimpleGeometry} geom
|
|
29
|
-
* @returns {
|
|
29
|
+
* @returns {BoundingBox}
|
|
30
30
|
*/
|
|
31
31
|
export function bbox(geom) {
|
|
32
32
|
let b = bboxCache.get(geom)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BoundingBox, Geometry, SimpleGeometry } from './geometry.js'
|
|
2
|
+
|
|
3
|
+
export function decompose(geom: Geometry): SimpleGeometry[]
|
|
4
|
+
export function bbox(geom: SimpleGeometry): BoundingBox
|
|
5
|
+
export function bboxOverlap(a: SimpleGeometry, b: SimpleGeometry): boolean
|
|
6
|
+
export function parseWkt(wkt: string): Geometry | null
|
package/src/spatial/spatial.js
CHANGED
|
@@ -68,6 +68,25 @@ export function evaluateSpatialFunc({ funcName, args }) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Decompose Multi* and GeometryCollection into simple geometries.
|
|
73
|
+
*
|
|
74
|
+
* @param {Geometry} geom
|
|
75
|
+
* @returns {SimpleGeometry[]}
|
|
76
|
+
*/
|
|
77
|
+
export function decompose(geom) {
|
|
78
|
+
if (geom.type === 'MultiPoint') {
|
|
79
|
+
return geom.coordinates.map(c => ({ type: 'Point', coordinates: c }))
|
|
80
|
+
} else if (geom.type === 'MultiLineString') {
|
|
81
|
+
return geom.coordinates.map(c => ({ type: 'LineString', coordinates: c }))
|
|
82
|
+
} else if (geom.type === 'MultiPolygon') {
|
|
83
|
+
return geom.coordinates.map(c => ({ type: 'Polygon', coordinates: c }))
|
|
84
|
+
} else if (geom.type === 'GeometryCollection') {
|
|
85
|
+
return geom.geometries.flatMap(decompose)
|
|
86
|
+
}
|
|
87
|
+
return [geom]
|
|
88
|
+
}
|
|
89
|
+
|
|
71
90
|
/**
|
|
72
91
|
* Normalize a geometry value. Accepts GeoJSON objects.
|
|
73
92
|
* Returns null if the value is not a valid geometry.
|
|
@@ -90,10 +109,6 @@ function toGeometry(val) {
|
|
|
90
109
|
return null
|
|
91
110
|
}
|
|
92
111
|
|
|
93
|
-
// ============================================================================
|
|
94
|
-
// Minimum distance between geometries
|
|
95
|
-
// ============================================================================
|
|
96
|
-
|
|
97
112
|
/**
|
|
98
113
|
* Get all line segments from a geometry.
|
|
99
114
|
*
|
|
@@ -165,35 +180,6 @@ function stDWithin(a, b, distance) {
|
|
|
165
180
|
return false
|
|
166
181
|
}
|
|
167
182
|
|
|
168
|
-
// ============================================================================
|
|
169
|
-
// Spatial predicate dispatch - decompose to primitive type pairs
|
|
170
|
-
// ============================================================================
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Decompose Multi* and GeometryCollection into simple geometries.
|
|
174
|
-
*
|
|
175
|
-
* @param {Geometry} geom
|
|
176
|
-
* @returns {SimpleGeometry[]}
|
|
177
|
-
*/
|
|
178
|
-
function decompose(geom) {
|
|
179
|
-
switch (geom.type) {
|
|
180
|
-
case 'MultiPoint':
|
|
181
|
-
return geom.coordinates.map(c => ({ type: 'Point', coordinates: c }))
|
|
182
|
-
case 'MultiLineString':
|
|
183
|
-
return geom.coordinates.map(c => ({ type: 'LineString', coordinates: c }))
|
|
184
|
-
case 'MultiPolygon':
|
|
185
|
-
return geom.coordinates.map(c => ({ type: 'Polygon', coordinates: c }))
|
|
186
|
-
case 'GeometryCollection':
|
|
187
|
-
return geom.geometries.flatMap(decompose)
|
|
188
|
-
default:
|
|
189
|
-
return [geom]
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// ============================================================================
|
|
194
|
-
// ST_Contains
|
|
195
|
-
// ============================================================================
|
|
196
|
-
|
|
197
183
|
/**
|
|
198
184
|
* @param {SimpleGeometry[]} a
|
|
199
185
|
* @param {SimpleGeometry[]} b
|
|
@@ -204,10 +190,6 @@ function stContains(a, b) {
|
|
|
204
190
|
return b.every(pb => a.some(pa => pairContainment(pa, pb) !== 'OUTSIDE'))
|
|
205
191
|
}
|
|
206
192
|
|
|
207
|
-
// ============================================================================
|
|
208
|
-
// ST_ContainsProperly
|
|
209
|
-
// ============================================================================
|
|
210
|
-
|
|
211
193
|
/**
|
|
212
194
|
* @param {SimpleGeometry[]} a
|
|
213
195
|
* @param {SimpleGeometry[]} b
|
|
@@ -218,10 +200,6 @@ function stContainsProperly(a, b) {
|
|
|
218
200
|
return b.every(pb => a.some(pa => pairContainment(pa, pb) === 'INSIDE'))
|
|
219
201
|
}
|
|
220
202
|
|
|
221
|
-
// ============================================================================
|
|
222
|
-
// ST_Touches
|
|
223
|
-
// ============================================================================
|
|
224
|
-
|
|
225
203
|
/**
|
|
226
204
|
* @param {SimpleGeometry[]} a
|
|
227
205
|
* @param {SimpleGeometry[]} b
|
|
@@ -239,10 +217,6 @@ function stTouches(a, b) {
|
|
|
239
217
|
return intersects
|
|
240
218
|
}
|
|
241
219
|
|
|
242
|
-
// ============================================================================
|
|
243
|
-
// ST_Overlaps
|
|
244
|
-
// ============================================================================
|
|
245
|
-
|
|
246
220
|
/**
|
|
247
221
|
* @param {SimpleGeometry[]} a
|
|
248
222
|
* @param {SimpleGeometry[]} b
|
|
@@ -281,10 +255,6 @@ function geometryDimension(parts) {
|
|
|
281
255
|
return max
|
|
282
256
|
}
|
|
283
257
|
|
|
284
|
-
// ============================================================================
|
|
285
|
-
// ST_Equals
|
|
286
|
-
// ============================================================================
|
|
287
|
-
|
|
288
258
|
/**
|
|
289
259
|
* @param {SimpleGeometry[]} a
|
|
290
260
|
* @param {SimpleGeometry[]} b
|
|
@@ -310,10 +280,6 @@ function stEquals(a, b) {
|
|
|
310
280
|
return true
|
|
311
281
|
}
|
|
312
282
|
|
|
313
|
-
// ============================================================================
|
|
314
|
-
// ST_Crosses
|
|
315
|
-
// ============================================================================
|
|
316
|
-
|
|
317
283
|
/**
|
|
318
284
|
* @param {SimpleGeometry[]} a
|
|
319
285
|
* @param {SimpleGeometry[]} b
|