@peerbit/indexer-sqlite3 1.2.30 → 1.3.1

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 (29) hide show
  1. package/dist/{peerbit/sqlite3-worker1-promiser.mjs → assets/sqlite3/sqlite3-worker1-promiser-bundler-friendly.mjs} +6 -1
  2. package/dist/{peerbit → assets/sqlite3}/sqlite3-worker1-promiser.js +6 -1
  3. package/dist/assets/sqlite3/sqlite3-worker1-promiser.mjs +187 -0
  4. package/dist/assets/sqlite3/sqlite3-worker1.mjs +35 -0
  5. package/dist/{peerbit/sqlite3-bundler-friendly.mjs → assets/sqlite3/sqlite3.js} +2986 -3159
  6. package/dist/assets/sqlite3/sqlite3.mjs +13669 -0
  7. package/dist/assets/sqlite3/sqlite3.wasm +0 -0
  8. package/dist/{peerbit → assets/sqlite3}/sqlite3.worker.min.js +10364 -10214
  9. package/dist/{peerbit/sqlite3.min.js → index.min.js} +11646 -10803
  10. package/dist/index.min.js.map +7 -0
  11. package/dist/src/query-planner.js +70 -35
  12. package/dist/src/query-planner.js.map +1 -1
  13. package/dist/src/schema.js +62 -22
  14. package/dist/src/schema.js.map +1 -1
  15. package/dist/src/sqlite3.browser.js +1 -1
  16. package/dist/src/sqlite3.browser.js.map +1 -1
  17. package/dist/src/sqlite3.wasm.d.ts.map +1 -1
  18. package/dist/src/sqlite3.wasm.js +6 -1
  19. package/dist/src/sqlite3.wasm.js.map +1 -1
  20. package/package.json +15 -15
  21. package/src/sqlite3.browser.ts +1 -1
  22. package/src/sqlite3.wasm.ts +6 -1
  23. package/dist/peerbit/sqlite3-node.mjs +0 -12043
  24. package/dist/peerbit/sqlite3.js +0 -14070
  25. package/dist/peerbit/sqlite3.mjs +0 -14039
  26. package/dist/peerbit/sqlite3.wasm +0 -0
  27. /package/dist/{peerbit → assets/sqlite3}/sqlite3-opfs-async-proxy.js +0 -0
  28. /package/dist/{peerbit → assets/sqlite3}/sqlite3-worker1-bundler-friendly.mjs +0 -0
  29. /package/dist/{peerbit → assets/sqlite3}/sqlite3-worker1.js +0 -0
@@ -150,7 +150,9 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = {
150
150
  onerror: (...args) => console.error('worker1 promiser error', ...args),
151
151
  };
152
152
 
153
- sqlite3Worker1Promiser.v2 = function (config) {
153
+ globalThis.sqlite3Worker1Promiser.v2 = function callee(
154
+ config = callee.defaultConfig,
155
+ ) {
154
156
  let oldFunc;
155
157
  if ('function' == typeof config) {
156
158
  oldFunc = config;
@@ -184,4 +186,7 @@ sqlite3Worker1Promiser.v2 = function (config) {
184
186
  original: sqlite3Worker1Promiser,
185
187
  });
186
188
 
189
+ globalThis.sqlite3Worker1Promiser.v2.defaultConfig =
190
+ globalThis.sqlite3Worker1Promiser.defaultConfig;
191
+
187
192
  export default sqlite3Worker1Promiser.v2;
@@ -158,7 +158,9 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = {
158
158
  onerror: (...args) => console.error('worker1 promiser error', ...args),
159
159
  };
160
160
 
161
- sqlite3Worker1Promiser.v2 = function (config) {
161
+ globalThis.sqlite3Worker1Promiser.v2 = function callee(
162
+ config = callee.defaultConfig,
163
+ ) {
162
164
  let oldFunc;
163
165
  if ('function' == typeof config) {
164
166
  oldFunc = config;
@@ -191,3 +193,6 @@ sqlite3Worker1Promiser.v2 = function (config) {
191
193
  }.bind({
192
194
  original: sqlite3Worker1Promiser,
193
195
  });
196
+
197
+ globalThis.sqlite3Worker1Promiser.v2.defaultConfig =
198
+ globalThis.sqlite3Worker1Promiser.defaultConfig;
@@ -0,0 +1,187 @@
1
+ /*
2
+ 2022-08-24
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 implements a Promise-based proxy for the sqlite3 Worker
14
+ API #1. It is intended to be included either from the main thread or
15
+ a Worker, but only if (A) the environment supports nested Workers
16
+ and (B) it's _not_ a Worker which loads the sqlite3 WASM/JS
17
+ module. This file's features will load that module and provide a
18
+ slightly simpler client-side interface than the slightly-lower-level
19
+ Worker API does.
20
+
21
+ This script necessarily exposes one global symbol, but clients may
22
+ freely `delete` that symbol after calling it.
23
+ */
24
+ 'use strict';
25
+
26
+ globalThis.sqlite3Worker1Promiser = function callee(
27
+ config = callee.defaultConfig,
28
+ ) {
29
+ if (1 === arguments.length && 'function' === typeof arguments[0]) {
30
+ const f = config;
31
+ config = Object.assign(Object.create(null), callee.defaultConfig);
32
+ config.onready = f;
33
+ } else {
34
+ config = Object.assign(Object.create(null), callee.defaultConfig, config);
35
+ }
36
+ const handlerMap = Object.create(null);
37
+ const noop = function () {};
38
+ const err = config.onerror || noop;
39
+ const debug = config.debug || noop;
40
+ const idTypeMap = config.generateMessageId ? undefined : Object.create(null);
41
+ const genMsgId =
42
+ config.generateMessageId ||
43
+ function (msg) {
44
+ return (
45
+ msg.type + '#' + (idTypeMap[msg.type] = (idTypeMap[msg.type] || 0) + 1)
46
+ );
47
+ };
48
+ const toss = (...args) => {
49
+ throw new Error(args.join(' '));
50
+ };
51
+ if (!config.worker) config.worker = callee.defaultConfig.worker;
52
+ if ('function' === typeof config.worker) config.worker = config.worker();
53
+ let dbId;
54
+ let promiserFunc;
55
+ config.worker.onmessage = function (ev) {
56
+ ev = ev.data;
57
+ debug('worker1.onmessage', ev);
58
+ let msgHandler = handlerMap[ev.messageId];
59
+ if (!msgHandler) {
60
+ if (ev && 'sqlite3-api' === ev.type && 'worker1-ready' === ev.result) {
61
+ if (config.onready) config.onready(promiserFunc);
62
+ return;
63
+ }
64
+ msgHandler = handlerMap[ev.type];
65
+ if (msgHandler && msgHandler.onrow) {
66
+ msgHandler.onrow(ev);
67
+ return;
68
+ }
69
+ if (config.onunhandled) config.onunhandled(arguments[0]);
70
+ else err('sqlite3Worker1Promiser() unhandled worker message:', ev);
71
+ return;
72
+ }
73
+ delete handlerMap[ev.messageId];
74
+ switch (ev.type) {
75
+ case 'error':
76
+ msgHandler.reject(ev);
77
+ return;
78
+ case 'open':
79
+ if (!dbId) dbId = ev.dbId;
80
+ break;
81
+ case 'close':
82
+ if (ev.dbId === dbId) dbId = undefined;
83
+ break;
84
+ default:
85
+ break;
86
+ }
87
+ try {
88
+ msgHandler.resolve(ev);
89
+ } catch (e) {
90
+ msgHandler.reject(e);
91
+ }
92
+ };
93
+ return (promiserFunc = function () {
94
+ let msg;
95
+ if (1 === arguments.length) {
96
+ msg = arguments[0];
97
+ } else if (2 === arguments.length) {
98
+ msg = Object.create(null);
99
+ msg.type = arguments[0];
100
+ msg.args = arguments[1];
101
+ msg.dbId = msg.args.dbId;
102
+ } else {
103
+ toss('Invalid arguments for sqlite3Worker1Promiser()-created factory.');
104
+ }
105
+ if (!msg.dbId && msg.type !== 'open') msg.dbId = dbId;
106
+ msg.messageId = genMsgId(msg);
107
+ msg.departureTime = performance.now();
108
+ const proxy = Object.create(null);
109
+ proxy.message = msg;
110
+ let rowCallbackId;
111
+ if ('exec' === msg.type && msg.args) {
112
+ if ('function' === typeof msg.args.callback) {
113
+ rowCallbackId = msg.messageId + ':row';
114
+ proxy.onrow = msg.args.callback;
115
+ msg.args.callback = rowCallbackId;
116
+ handlerMap[rowCallbackId] = proxy;
117
+ } else if ('string' === typeof msg.args.callback) {
118
+ toss(
119
+ 'exec callback may not be a string when using the Promise interface.',
120
+ );
121
+ }
122
+ }
123
+
124
+ let p = new Promise(function (resolve, reject) {
125
+ proxy.resolve = resolve;
126
+ proxy.reject = reject;
127
+ handlerMap[msg.messageId] = proxy;
128
+ debug(
129
+ 'Posting',
130
+ msg.type,
131
+ 'message to Worker dbId=' + (dbId || 'default') + ':',
132
+ msg,
133
+ );
134
+ config.worker.postMessage(msg);
135
+ });
136
+ if (rowCallbackId) p = p.finally(() => delete handlerMap[rowCallbackId]);
137
+ return p;
138
+ });
139
+ };
140
+
141
+ globalThis.sqlite3Worker1Promiser.defaultConfig = {
142
+ worker: function () {
143
+ return new Worker(new URL('sqlite3-worker1.js', import.meta.url));
144
+ },
145
+ onerror: (...args) => console.error('worker1 promiser error', ...args),
146
+ };
147
+
148
+ globalThis.sqlite3Worker1Promiser.v2 = function callee(
149
+ config = callee.defaultConfig,
150
+ ) {
151
+ let oldFunc;
152
+ if ('function' == typeof config) {
153
+ oldFunc = config;
154
+ config = {};
155
+ } else if ('function' === typeof config?.onready) {
156
+ oldFunc = config.onready;
157
+ delete config.onready;
158
+ }
159
+ const promiseProxy = Object.create(null);
160
+ config = Object.assign(config || Object.create(null), {
161
+ onready: async function (func) {
162
+ try {
163
+ if (oldFunc) await oldFunc(func);
164
+ promiseProxy.resolve(func);
165
+ } catch (e) {
166
+ promiseProxy.reject(e);
167
+ }
168
+ },
169
+ });
170
+ const p = new Promise(function (resolve, reject) {
171
+ promiseProxy.resolve = resolve;
172
+ promiseProxy.reject = reject;
173
+ });
174
+ try {
175
+ this.original(config);
176
+ } catch (e) {
177
+ promiseProxy.reject(e);
178
+ }
179
+ return p;
180
+ }.bind({
181
+ original: sqlite3Worker1Promiser,
182
+ });
183
+
184
+ globalThis.sqlite3Worker1Promiser.v2.defaultConfig =
185
+ globalThis.sqlite3Worker1Promiser.defaultConfig;
186
+
187
+ export default sqlite3Worker1Promiser.v2;
@@ -0,0 +1,35 @@
1
+ /*
2
+ 2022-05-23
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 is a JS Worker file for the main sqlite3 api. It loads
14
+ sqlite3.js, initializes the module, and postMessage()'s a message
15
+ after the module is initialized:
16
+
17
+ {type: 'sqlite3-api', result: 'worker1-ready'}
18
+
19
+ This seemingly superfluous level of indirection is necessary when
20
+ loading sqlite3.js via a Worker. Instantiating a worker with new
21
+ Worker("sqlite.js") will not (cannot) call sqlite3InitModule() to
22
+ initialize the module due to a timing/order-of-operations conflict
23
+ (and that symbol is not exported in a way that a Worker loading it
24
+ that way can see it). Thus JS code wanting to load the sqlite3
25
+ Worker-specific API needs to pass _this_ file (or equivalent) to the
26
+ Worker constructor and then listen for an event in the form shown
27
+ above in order to know when the module has completed initialization.
28
+
29
+ This file accepts a URL arguments to adjust how it loads sqlite3.js:
30
+
31
+ - `sqlite3.dir`, if set, treats the given directory name as the
32
+ directory from which `sqlite3.js` will be loaded.
33
+ */
34
+ return new Worker(new URL('sqlite3.js', import.meta.url));
35
+ sqlite3InitModule().then((sqlite3) => sqlite3.initWorker1API());