spl.js 0.1.0-beta.8 → 0.1.0-rc.0

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.
Files changed (48) hide show
  1. package/Makefile +54 -57
  2. package/README.md +6 -27
  3. package/dist/index.js +53 -2
  4. package/dist/index.mjs +43 -0
  5. package/dist/{spl.wasm → index.wasm} +0 -0
  6. package/dist/proj/proj.db +0 -0
  7. package/dist/proj/proj.ini +10 -0
  8. package/dist/proj/projjson.schema.json +31 -5
  9. package/dist/spl-node.mjs +1 -0
  10. package/dist/spl-web.js +2 -0
  11. package/examples/extensions.html +45 -45
  12. package/examples/lib/index.js +38 -0
  13. package/examples/lib/lib.js +456 -0
  14. package/examples/lib/ol.css +345 -0
  15. package/examples/lib/package-lock.json +2291 -0
  16. package/examples/lib/package.json +26 -0
  17. package/examples/lib/rollup.config.js +17 -0
  18. package/examples/lights-performance.html +240 -250
  19. package/examples/openlayers.html +76 -75
  20. package/examples/topology.html +3 -4
  21. package/package.json +19 -20
  22. package/rollup.config.node.js +16 -11
  23. package/rollup.config.web.js +5 -12
  24. package/rollup.config.worker.js +6 -10
  25. package/scripts/stringify.js +3 -3
  26. package/src/index.js +53 -0
  27. package/src/index.mjs +43 -0
  28. package/src/{result.ts → result.js} +2 -4
  29. package/src/spl-node.mjs +3 -0
  30. package/src/{spl-web.ts → spl-web.js} +42 -22
  31. package/src/{spl-worker.ts → spl-worker.js} +12 -5
  32. package/src/{spl.ts → spl.js} +96 -73
  33. package/test/browser.js +4 -87
  34. package/test/electron.js +8 -3
  35. package/test/files/tmp/memory_and_local_dbs_1.db +0 -0
  36. package/test/files/tmp/save_and_load_from_to_memory.db +0 -0
  37. package/test/node.js +39 -42
  38. package/dist/index.d.ts +0 -54
  39. package/dist/spl.d.ts +0 -46
  40. package/dist/spl.js +0 -1
  41. package/src/interfaces.ts +0 -85
  42. package/src/spl-node.ts +0 -4
  43. package/src/spl-web.d.ts +0 -54
  44. package/src/spl.d.ts +0 -46
  45. package/tsconfig.json +0 -9
  46. package/tslint.json +0 -126
  47. /package/examples/{lights.zip → data/lights.zip} +0 -0
  48. /package/examples/{world.json → data/world.json} +0 -0
package/Makefile CHANGED
@@ -3,14 +3,14 @@ BUILD_DIR = $(PWD)/src/build
3
3
  BC_DIR = $(BUILD_DIR)/bc
4
4
  PREFIX = --prefix=$(BC_DIR)
5
5
 
6
- SQLITE_VERSION = 3390400
7
- GEOS_VERSION = 3.9.0
8
- PROJ_VERSION = 9.1.0
6
+ SQLITE_VERSION = 3440100
7
+ GEOS_VERSION = 3.12.0
8
+ PROJ_VERSION = 9.2.1
9
9
  RTTOPO_VERSION = 1.1.0
10
10
 
11
- ZLIB_VERSION = 1.2.12
11
+ ZLIB_VERSION = 1.3
12
12
  XML2_VERSION = 2.9.12
13
- ICONV_VERSION = 1.16
13
+ ICONV_VERSION = 1.17
14
14
 
15
15
  SPATIALITE_SRC = src/spatialite
16
16
  SQLITE_SRC = $(BUILD_DIR)/sqlite-autoconf-$(SQLITE_VERSION)
@@ -22,13 +22,23 @@ XML2_SRC = $(BUILD_DIR)/libxml2-$(XML2_VERSION)
22
22
  ICONV_SRC = $(BUILD_DIR)/libiconv-$(ICONV_VERSION)
23
23
  SQLEAN_EXT_SRC = src/sqlean/src
24
24
 
25
- DIST_FLAGS :=
26
- DIST_FLAGS += -s EXPORT_ES6=1
27
- DIST_FLAGS += -s USE_ES6_IMPORT_META=0
28
- DIST_FLAGS += -s MODULARIZE=1
29
- DIST_FLAGS += -s EXPORT_NAME="spl"
30
- DIST_FLAGS += -s ENVIRONMENT="node,worker"
31
- DIST_FLAGS += -s WASM_ASYNC_COMPILATION=0
25
+ DIST_WORKER_FLAGS :=
26
+ DIST_WORKER_FLAGS += -s EXPORT_ES6=1
27
+ DIST_WORKER_FLAGS += -s USE_ES6_IMPORT_META=0
28
+ DIST_WORKER_FLAGS += -s MODULARIZE=1
29
+ DIST_WORKER_FLAGS += -s EXPORT_NAME="spl"
30
+ DIST_WORKER_FLAGS += -s ENVIRONMENT="worker"
31
+ DIST_WORKER_FLAGS += -s WASM_ASYNC_COMPILATION=0
32
+ DIST_WORKER_FLAGS += --memory-init-file 0
33
+
34
+ DIST_NODE_FLAGS :=
35
+ DIST_NODE_FLAGS += -s EXPORT_ES6=1
36
+ DIST_NODE_FLAGS += -s USE_ES6_IMPORT_META=1
37
+ DIST_NODE_FLAGS += -s MODULARIZE=1
38
+ DIST_NODE_FLAGS += -s EXPORT_NAME="spl"
39
+ DIST_NODE_FLAGS += -s ENVIRONMENT="node"
40
+ DIST_NODE_FLAGS += -s WASM_ASYNC_COMPILATION=0
41
+ DIST_NODE_FLAGS += --memory-init-file 0
32
42
 
33
43
  ELD_FLAGS += -s INITIAL_MEMORY=64MB
34
44
  ELD_FLAGS += -s ALLOW_MEMORY_GROWTH=1
@@ -40,7 +50,7 @@ ELD_FLAGS += -lworkerfs.js
40
50
 
41
51
  EMX_FLAGS :=
42
52
  EMX_FLAGS += -s DISABLE_EXCEPTION_CATCHING=0
43
- EMX_FLAGS += --memory-init-file 0
53
+
44
54
 
45
55
  EXPORTED_FUNCTIONS = -s EXPORTED_FUNCTIONS=@$(PWD)/src/exported_functions.json
46
56
  EXPORTED_RUNTIME_METHODS = -s EXPORTED_RUNTIME_METHODS=@$(PWD)/src/exported_runtime_methods.json
@@ -78,12 +88,12 @@ zlib: zlib-conf
78
88
 
79
89
  zlib-src:
80
90
  cd $(BUILD_DIR); \
81
- wget -nc http://zlib.net/zlib-$(ZLIB_VERSION).tar.gz; \
91
+ wget -nc https://zlib.net/zlib-$(ZLIB_VERSION).tar.gz; \
82
92
  tar -xf zlib-$(ZLIB_VERSION).tar.gz;
83
93
 
84
94
  iconv-conf: iconv-src
85
95
  cd $(ICONV_SRC); \
86
- emconfigure ./configure $(PREFIX) --disable-shared;
96
+ emconfigure ./configure $(PREFIX) --disable-shared --host=none-none-none;
87
97
 
88
98
  iconv: iconv-conf
89
99
  cd $(ICONV_SRC); \
@@ -97,12 +107,12 @@ iconv-src:
97
107
 
98
108
  sqlite-src:
99
109
  cd $(BUILD_DIR); \
100
- wget -nc https://www.sqlite.org/2022/sqlite-autoconf-$(SQLITE_VERSION).tar.gz; \
110
+ wget -nc https://www.sqlite.org/2023/sqlite-autoconf-$(SQLITE_VERSION).tar.gz; \
101
111
  tar -xf sqlite-autoconf-$(SQLITE_VERSION).tar.gz;
102
112
 
103
113
  sqlite-conf: sqlite-src
104
114
  cd $(SQLITE_SRC); \
105
- emconfigure ./configure $(PREFIX) \
115
+ emconfigure ./configure $(PREFIX) --host=none-none-none \
106
116
  --disable-tcl --disable-shared --disable-editline --disable-readline --disable-load-extension;
107
117
 
108
118
  sqlite: sqlite-conf
@@ -127,7 +137,7 @@ xml2-src:
127
137
  xml2-conf: xml2-src
128
138
  cd $(XML2_SRC); \
129
139
  ./autogen.sh $(PREFIX) --without-python; \
130
- emconfigure ./configure $(PREFIX) --without-python --disable-shared --with-zlib CPPFLAGS="-DDEBUG_HTTP" Z_LIBS="-L$(BC_DIR)/lib -lz" Z_CFLAGS="-I$(BC_DIR)/include";
140
+ emconfigure ./configure $(PREFIX) --host=none-none-none --without-python --disable-shared --with-zlib CPPFLAGS="-DDEBUG_HTTP" Z_LIBS="-L$(BC_DIR)/lib -lz" Z_CFLAGS="-I$(BC_DIR)/include";
131
141
 
132
142
  xml2: xml2-conf
133
143
  cd $(XML2_SRC); \
@@ -166,33 +176,14 @@ geos-src:
166
176
  wget -nc http://download.osgeo.org/geos/geos-$(GEOS_VERSION).tar.bz2; \
167
177
  tar -xf geos-$(GEOS_VERSION).tar.bz2; \
168
178
 
169
- # sed -i '/add_subdirectory(doc)/d' $(GEOS_SRC)/CMakeLists.txt;
170
-
171
- # geos: geos-src
172
- # cd $(GEOS_SRC) && mkdir -p build && cd build; \
173
- # emcmake cmake -DCMAKE_CXX_FLAGS="$(EMX_FLAGS)" \
174
- # -DDISABLE_GEOS_INLINE=ON -DBUILD_TESTING=OFF -DBUILD_BENCHMARKS=OFF -DBUILD_SHARED_LIBS=OFF \
175
- # -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(BC_DIR) ..; \
176
- # emmake make -j4; \
177
- # emmake make install;
178
-
179
- geos-conf: geos-src
180
- cd $(GEOS_SRC); \
181
- emconfigure ./configure $(PREFIX) --disable-inline --disable-shared;
182
-
183
- # sed -i '/doc/d' $(GEOS_SRC)/Makefile;
184
- # sed -i '/tests/d' $(GEOS_SRC)/Makefile;
185
- # sed -i '/benchmarks/d' $(GEOS_SRC)/Makefile;
186
- # sed -i '/tools/d' $(GEOS_SRC)/Makefile;
187
-
188
- geos: geos-conf
189
- cd $(GEOS_SRC); \
190
- emmake make -j4 \
191
- CPPFLAGS="$(EMX_FLAGS)"; \
179
+ geos: geos-src
180
+ cd $(GEOS_SRC) && mkdir -p build && cd build; \
181
+ emcmake cmake -DCMAKE_CXX_FLAGS="$(EMX_FLAGS)" \
182
+ -DBUILD_TESTING=OFF -DBUILD_BENCHMARKS=OFF -DBUILD_SHARED_LIBS=OFF \
183
+ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(BC_DIR) ..; \
184
+ emmake make -j4; \
192
185
  emmake make install;
193
186
 
194
- # cd $(GEOS_SRC)/tools && emmake make install geos-config;
195
-
196
187
  geos-clean:
197
188
  cd $(GEOS_SRC) && make clean;
198
189
 
@@ -204,7 +195,7 @@ rttopo-src:
204
195
  rttopo-conf: rttopo-src
205
196
  cd $(RTTOPO_SRC); \
206
197
  ./autogen.sh; \
207
- emconfigure ./configure $(PREFIX) --disable-shared --with-geosconfig="$(BC_DIR)/bin/geos-config";
198
+ emconfigure ./configure $(PREFIX) --host=none-none-none --disable-shared --with-geosconfig="$(BC_DIR)/bin/geos-config";
208
199
 
209
200
  rttopo: rttopo-conf
210
201
  cd $(RTTOPO_SRC); \
@@ -214,9 +205,6 @@ rttopo: rttopo-conf
214
205
  rttopo-clean:
215
206
  cd $(RTTOPO_SRC) && make clean;
216
207
 
217
- # LIBXML2_LIBS="-L$(BC_DIR)/lib"
218
- # LIBXML2_CFLAGS="-I$(BC_DIR)/include/libxml2"
219
-
220
208
  # remove some irrelevant tests that will fail (still some xls tests failing)
221
209
  spatialite-conf:
222
210
  sed -i '/check_extension/d' $(SPATIALITE_SRC)/test/Makefile.am;
@@ -227,14 +215,13 @@ spatialite-conf:
227
215
  -rm $(SPATIALITE_SRC)/test/sql_stmt_security_tests/importxls*;
228
216
  cd $(SPATIALITE_SRC); \
229
217
  aclocal && automake; \
230
- emconfigure ./configure $(PREFIX) \
218
+ emconfigure ./configure $(PREFIX) --host=none-none-none \
231
219
  CFLAGS="$(EMX_FLAGS) -DENABLE_MINIZIP -UOMIT_PROJ -DPROJ_NEW -ULOADABLE_EXTENSION -I$(ZLIB_SRC)/contrib" \
232
220
  CPPFLAGS="-I$(BC_DIR)/include" \
233
221
  LDFLAGS="-L$(BC_DIR)/lib" \
222
+ PKG_CONFIG_LIBDIR="$(BC_DIR)/lib/pkgconfig" \
234
223
  --with-geosconfig="$(BC_DIR)/bin/geos-config" \
235
- --with-geosonlyreentrant \
236
224
  --enable-rttopo \
237
- --enable-geocallbacks \
238
225
  --enable-geosadvanced \
239
226
  --enable-geopackage \
240
227
  --enable-gcp \
@@ -258,7 +245,7 @@ spatialite-clean:
258
245
  extensions:
259
246
  emcc -v -I$(SQLITE_SRC) -DSQLITE_CORE $(EMX_FLAGS) $(ELD_FLAGS) -c $(SQLEAN_EXT_SRC)/sqlite3-stats.c -o $(BC_DIR)/ex.o;
260
247
 
261
-
248
+ # requires node 21 to load fils without extension as mjs
262
249
  tests:
263
250
  cd $(SPATIALITE_SRC)/test; \
264
251
  echo " \
@@ -273,19 +260,29 @@ tests:
273
260
  };" > pre.js; \
274
261
  mkdir -p proj && cp -f $(BC_DIR)/share/proj/* proj; \
275
262
  emmake make check -j4 LOG_COMPILE="node" \
276
- LDFLAGS="$(ELD_FLAGS) -s ENVIRONMENT=node -s FORCE_FILESYSTEM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s EXPORTED_FUNCTIONS="[_main]" -liconv -lminizip" \
263
+ LDFLAGS="$(ELD_FLAGS) -lgeos -s WASM_ASYNC_COMPILATION=0 -s ENVIRONMENT=node -s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=1 -s FORCE_FILESYSTEM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s EXPORTED_FUNCTIONS="[_main]" -liconv -lminizip" \
277
264
  CFLAGS="$(EMX_FLAGS) -D_GNU_SOURCE --pre-js pre.js";
278
265
 
279
266
 
280
- .PHONY: spl
281
- spl: src/pre.js
282
- emcc -v $(EMX_FLAGS) $(ELD_FLAGS) $(DIST_FLAGS) $(EXPORTED_FUNCTIONS) $(EXPORTED_RUNTIME_METHODS) \
267
+ .PHONY: worker
268
+ worker: src/pre.js
269
+ emcc -v $(EMX_FLAGS) $(ELD_FLAGS) $(DIST_WORKER_FLAGS) $(EXPORTED_FUNCTIONS) $(EXPORTED_RUNTIME_METHODS) \
270
+ -lz -lminizip -liconv -lsqlite3 -lgeos_c -lgeos -lrttopo -lproj -L$(BC_DIR)/lib \
271
+ -s ERROR_ON_UNDEFINED_SYMBOLS=1 $(BC_DIR)/lib/libspatialite.a $(BC_DIR)/ex.o \
272
+ -I$(SQLITE_SRC) \
273
+ -I$(SPATIALITE_SRC)/src/headers \
274
+ -I$(SPATIALITE_SRC)/src/headers/spatialite \
275
+ src/spl.c --pre-js src/pre.js -o $(BUILD_DIR)/js/em-worker.js --embed-file $(BC_DIR)/share/proj_min.db@/proj_min.db;
276
+
277
+ .PHONY: node
278
+ node: src/pre.js
279
+ emcc -v $(EMX_FLAGS) $(ELD_FLAGS) $(DIST_NODE_FLAGS) $(EXPORTED_FUNCTIONS) $(EXPORTED_RUNTIME_METHODS) \
283
280
  -lz -lminizip -liconv -lsqlite3 -lgeos_c -lgeos -lrttopo -lproj -L$(BC_DIR)/lib \
284
- -s ERROR_ON_UNDEFINED_SYMBOLS=0 $(BC_DIR)/lib/libspatialite.a $(BC_DIR)/ex.o \
281
+ -s ERROR_ON_UNDEFINED_SYMBOLS=1 $(BC_DIR)/lib/libspatialite.a $(BC_DIR)/ex.o \
285
282
  -I$(SQLITE_SRC) \
286
283
  -I$(SPATIALITE_SRC)/src/headers \
287
284
  -I$(SPATIALITE_SRC)/src/headers/spatialite \
288
- src/spl.c --pre-js src/pre.js -o $(BUILD_DIR)/js/spl.js --embed-file $(BC_DIR)/share/proj_min.db@/proj_min.db;
285
+ src/spl.c --pre-js src/pre.js -o $(BUILD_DIR)/js/index.js --embed-file $(BC_DIR)/share/proj_min.db@/proj_min.db;
289
286
 
290
287
  clean:
291
288
  rm -rf $(PWD)/dist/*;
package/README.md CHANGED
@@ -4,8 +4,6 @@ SpatiaLite and friends - sqlite, geos, proj, rttopo - for node (sync API) and br
4
4
 
5
5
  [Here is a list](doc/spatialite_functions.md) of supported SpatiaLite SQL functions and [a list](doc/extensions_functions.md) of available SQLite extension functions/modules.
6
6
 
7
- Comments, bug reports and suggestions are welcome! spl.js will remain beta at least until the release of SpatiaLite 5.1.0.
8
-
9
7
  ## Install
10
8
 
11
9
  ```bash
@@ -17,24 +15,6 @@ The library for browsers bundles both the WebWorker script and the wasm file (~
17
15
  A minimal proj.db including EPSG codes for lon/lat to "Web Mercator" and UTM is embeded. Other PROJ files and the complete proj.db are available from the `dist/proj` folder.
18
16
  If you like to use the full proj.db instead you need to mount it to `/proj/proj.db` and set the path with spatialite's `PROJ_SetDatabasePath`.
19
17
 
20
- [Apparently](https://github.com/jvail/spl.js/issues/1) typescript has no option to switch between `main` and `browser` entrypoints in `package.json`. For typescript & browser development you need to import spl.js (async version) as
21
-
22
- ```ts
23
- import SPL from 'spl.js/dist/index'
24
- ```
25
-
26
- or add this option to tsconfig.json
27
-
28
- ```json
29
- {
30
- "compilerOptions": {
31
- "baseUrl": ".",
32
- "paths": {
33
- "spl.js": ["node_modules/spl.js/dist/index"]
34
- }
35
- }
36
- }
37
- ```
38
18
 
39
19
  ## Code Examples
40
20
 
@@ -45,7 +25,7 @@ import SPL from 'spl.js';
45
25
  const db = await SPL().then(spl => spl.db());
46
26
 
47
27
  console.assert(
48
- await db.exec('SELECT spatialite_version()').get.first === '5.0.1'
28
+ await db.exec('SELECT spatialite_version()').get.first === '5.1.0'
49
29
  );
50
30
 
51
31
  db.exec('SELECT ? AS hello', ['spatialite']).get.objs
@@ -148,7 +128,7 @@ If you are looking for more examples there are many snippets in the `test/node.j
148
128
 
149
129
  ## SPL
150
130
 
151
- ### `SPL`([`extensions`: [], `options`: {}]) -> `SPL`
131
+ ### `SPL`([`options`: {}, `extensions`: []]) -> `SPL`
152
132
 
153
133
  extensions: Browser only - see "Extensions API" section below.
154
134
 
@@ -247,8 +227,6 @@ With `sync` (browser only) all ArrayBuffers will be transfered without copying (
247
227
 
248
228
  ## Extensions API (Browser only)
249
229
 
250
- *Experimental since Firefox does currently not support dynamic imports in Workers.*
251
-
252
230
  Sometimes you want to run code inside the WebWorker. With this API you can supply additional functions to extend the `SPL` and `DB` APIs executed inside the WebWorker.
253
231
 
254
232
  Example: https://jvail.github.io/spl.js/examples/extensions.html
@@ -277,7 +255,7 @@ const extensions = [
277
255
  }
278
256
  ];
279
257
 
280
- const spl = await SPL(extensions);
258
+ const spl = await SPL({}, extensions);
281
259
  const db = await spl.db()
282
260
  .read(`
283
261
  CREATE TABLE hello (world);
@@ -286,12 +264,12 @@ const db = await spl.db()
286
264
 
287
265
  console.assert(await db.tables().get.first === 'hello');
288
266
  console.assert(await db.master('view').get.first === 'hello_view');
289
- console.assert(await spl.spatialite_version() === '5.0.1');
267
+ console.assert(await spl.spatialite_version() === '5.1.0');
290
268
  ```
291
269
 
292
270
  ## Building and Testing
293
271
 
294
- An activated, working emsdk environment (3.1.23) is required (https://emscripten.org/docs/tools_reference/emsdk.html). All dependencies except SpatiaLite & sqlean (git submodules) are fetched from the web. The git submodules needs to be initialized before running the build script.
272
+ An activated, working emsdk environment (3.1.49) is required (https://emscripten.org/docs/tools_reference/emsdk.html). All dependencies except SpatiaLite & sqlean (git submodules) are fetched from the web. The git submodules needs to be initialized before running the build script.
295
273
 
296
274
  ```bash
297
275
  npm install && npm run build:all
@@ -304,6 +282,7 @@ npm run test:node && npm run test:firefox && npm run test:chrome
304
282
  ```
305
283
 
306
284
  Running (the relevant) SpatiaLite test cases - this will take quite some time ... ~ 45 minutes or more.
285
+ Requires node >= v21 to run test cases without .mjs extension.
307
286
 
308
287
  ```bash
309
288
  npm run test:em