1/*
2  2022-07-22
3
4  The author disclaims copyright to this source code.  In place of a
5  legal notice, here is a blessing:
6
7  *   May you do good and not evil.
8  *   May you find forgiveness for yourself and forgive others.
9  *   May you share freely, never taking more than you give.
10
11  ***********************************************************************
12
13  This file is the tail end of the sqlite3-api.js constellation,
14  intended to be appended after all other files so that it can clean
15  up any global systems temporarily used for setting up the API's
16  various subsystems.
17*/
18'use strict';
19(function(){
20  /**
21     Replace sqlite3ApiBootstrap() with a variant which plugs in the
22     Emscripten-based config for all config options which the client
23     does not provide.
24  */
25  const SAB = self.sqlite3ApiBootstrap;
26  self.sqlite3ApiBootstrap = function(apiConfig){
27    apiConfig = apiConfig||{};
28    const configDefaults = {
29      Module: Module /* ==> Emscripten-style Module object. Currently
30                        needs to be exposed here for test code. NOT part
31                        of the public API. */,
32      exports: Module['asm'],
33      memory: Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */
34    };
35    const config = {};
36    Object.keys(configDefaults).forEach(function(k){
37      config[k] = Object.prototype.hasOwnProperty.call(apiConfig, k)
38        ? apiConfig[k] : configDefaults[k];
39    });
40    return SAB(config);
41  };
42
43  /**
44     For current (2022-08-22) purposes, automatically call sqlite3ApiBootstrap().
45     That decision will be revisited at some point, as we really want client code
46     to be able to call this to configure certain parts.
47   */
48  const sqlite3 = self.sqlite3ApiBootstrap();
49
50  if(self.location && +self.location.port > 1024){
51    console.warn("Installing sqlite3 bits as global S for dev-testing purposes.");
52    self.S = sqlite3;
53  }
54
55  /* Clean up temporary references to our APIs... */
56  delete self.sqlite3ApiBootstrap;
57  Module.sqlite3 = sqlite3 /* Currently needed by test code */;
58  delete sqlite3.capi.util /* arguable, but these are (currently) internal-use APIs */;
59  //console.warn("Module.sqlite3 =",Module.sqlite3);
60})();
61