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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squirreling",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "Squirreling Async SQL Engine",
5
5
  "author": "Hyperparam",
6
6
  "homepage": "https://hyperparam.app",
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'
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @import { BBox, SimpleGeometry } from './geometry.js'
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, BBox>} */
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 {BBox}
29
+ * @returns {BoundingBox}
30
30
  */
31
31
  export function bbox(geom) {
32
32
  let b = bboxCache.get(geom)
@@ -15,7 +15,7 @@ export type Geometry =
15
15
  */
16
16
  export type SimpleGeometry = Point | LineString | Polygon
17
17
 
18
- export interface BBox {
18
+ export interface BoundingBox {
19
19
  minX: number
20
20
  minY: number
21
21
  maxX: number
@@ -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
@@ -0,0 +1,3 @@
1
+ export { decompose } from './spatial.js'
2
+ export { bbox, bboxOverlap } from './bbox.js'
3
+ export { parseWkt } from './wkt.js'
@@ -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