firebird-wasm 0.6.0 → 0.7.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.
- package/CHANGELOG.md +103 -0
- package/README.md +4 -3
- package/dist/.tsbuildinfo.build +1 -1
- package/dist/batch-block.d.ts +60 -0
- package/dist/batch-block.d.ts.map +1 -0
- package/dist/batch-block.js +176 -0
- package/dist/batch-block.js.map +1 -0
- package/dist/browser/db-lock.d.ts +11 -4
- package/dist/browser/db-lock.d.ts.map +1 -1
- package/dist/browser/db-lock.js +60 -10
- package/dist/browser/db-lock.js.map +1 -1
- package/dist/browser/engine-transport.d.ts +20 -2
- package/dist/browser/engine-transport.d.ts.map +1 -1
- package/dist/browser/engine-transport.js +107 -17
- package/dist/browser/engine-transport.js.map +1 -1
- package/dist/browser/firebird-browser.d.ts +14 -6
- package/dist/browser/firebird-browser.d.ts.map +1 -1
- package/dist/browser/firebird-browser.js +23 -13
- package/dist/browser/firebird-browser.js.map +1 -1
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +10 -4
- package/dist/browser/index.js.map +1 -1
- package/dist/firebird.d.ts +16 -0
- package/dist/firebird.d.ts.map +1 -1
- package/dist/firebird.js +136 -2
- package/dist/firebird.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -0
- package/dist/wasm/firebird-embedded-st.js +5 -0
- package/dist/wasm/firebird-embedded-st.wasm +0 -0
- package/dist/wasm/firebird-embedded.js +4 -1
- package/dist/wasm/firebird-embedded.wasm +0 -0
- package/dist/wasm-loader.d.ts +82 -0
- package/dist/wasm-loader.d.ts.map +1 -1
- package/dist/wasm-loader.js +101 -9
- package/dist/wasm-loader.js.map +1 -1
- package/package.json +3 -1
- package/dist/browser/statement-types.d.ts +0 -18
- package/dist/browser/statement-types.d.ts.map +0 -1
- package/dist/browser/statement-types.js +0 -39
- package/dist/browser/statement-types.js.map +0 -1
package/dist/wasm-loader.d.ts
CHANGED
|
@@ -115,6 +115,12 @@ export interface FirebirdWasmModule {
|
|
|
115
115
|
* in its own transaction.
|
|
116
116
|
*/
|
|
117
117
|
_fb_read_transaction(dbHandle: number, on: number): number;
|
|
118
|
+
/**
|
|
119
|
+
* The columns of a kept statement's shape, `{"columns":[...]}`, for a
|
|
120
|
+
* result that named them by id (`{"shape":N,...}`); 0 if no kept statement
|
|
121
|
+
* has that shape any more. Free with `_fb_free_result`.
|
|
122
|
+
*/
|
|
123
|
+
_fb_shape_columns(id: number): number;
|
|
118
124
|
/**
|
|
119
125
|
* Pointer to the binary BLOB side buffer for the most recent query, or 0.
|
|
120
126
|
*
|
|
@@ -193,7 +199,35 @@ export interface WasmLoadOptions {
|
|
|
193
199
|
* automatically (e.g. bundled browser apps).
|
|
194
200
|
*/
|
|
195
201
|
locateFile?: (filename: string) => string;
|
|
202
|
+
/**
|
|
203
|
+
* Which build to load. `true` is `firebird-embedded.js`: pthreads over Web
|
|
204
|
+
* Workers, whose heap is a `SharedArrayBuffer` and which a browser gives
|
|
205
|
+
* only to a cross-origin isolated page. `false` is
|
|
206
|
+
* `firebird-embedded-st.js`: no threads and a plain `ArrayBuffer` heap, at
|
|
207
|
+
* the cost of statement and idle timeouts. `'auto'` (the default) is `true`
|
|
208
|
+
* in Node.
|
|
209
|
+
*
|
|
210
|
+
* In Node this picks the file the loader requires. In a browser the page
|
|
211
|
+
* loads the glue itself, so the choice is made there:
|
|
212
|
+
* {@link wasmGlueFile} names the file to load.
|
|
213
|
+
*/
|
|
214
|
+
threads?: boolean | 'auto';
|
|
196
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* The glue script of the build `threads` selects.
|
|
218
|
+
*
|
|
219
|
+
* `'auto'` (the default) picks the threaded build where it can run: in Node,
|
|
220
|
+
* and in a browser page or worker that is cross-origin isolated. Elsewhere,
|
|
221
|
+
* GitHub Pages and other static hosts that cannot send COOP/COEP among them,
|
|
222
|
+
* it picks the build without threads, which needs neither.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```js
|
|
226
|
+
* // in the engine's Worker, before the transport loads the module
|
|
227
|
+
* importScripts(`/wasm/${wasmGlueFile()}`);
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export declare function wasmGlueFile(threads?: boolean | 'auto'): string;
|
|
197
231
|
/**
|
|
198
232
|
* Load the Firebird Embedded WASM module.
|
|
199
233
|
*
|
|
@@ -210,6 +244,54 @@ export interface WasmLoadOptions {
|
|
|
210
244
|
* ```
|
|
211
245
|
*/
|
|
212
246
|
export declare function loadFirebirdWasm(options?: WasmLoadOptions): Promise<FirebirdWasmModule>;
|
|
247
|
+
/** Options for {@link cdnArtifacts}. */
|
|
248
|
+
export interface CdnOptions {
|
|
249
|
+
/** Which build; as {@link wasmGlueFile}. Default `'auto'`. */
|
|
250
|
+
threads?: boolean | 'auto';
|
|
251
|
+
/**
|
|
252
|
+
* `'jsdelivr'` (the default), `'unpkg'`, or the base URL of a directory
|
|
253
|
+
* holding the four artifacts, such as a mirror of `dist/wasm/`.
|
|
254
|
+
*/
|
|
255
|
+
cdn?: 'jsdelivr' | 'unpkg' | string;
|
|
256
|
+
/** The package version to load. Default: this package's own. */
|
|
257
|
+
version?: string;
|
|
258
|
+
}
|
|
259
|
+
/** Where to load the engine from: the glue script, and a `locateFile` for its `.wasm`. */
|
|
260
|
+
export interface CdnArtifacts {
|
|
261
|
+
/** URL of the glue script, for `importScripts()` or a `<script src>`. */
|
|
262
|
+
glueUrl: string;
|
|
263
|
+
/** Pass to `FirebirdBrowser`, `DirectTransport` or `FIREBIRD_WORKER_OPTIONS`. */
|
|
264
|
+
locateFile: (file: string) => string;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The engine's URLs on a CDN, so nothing has to be copied next to the app.
|
|
268
|
+
*
|
|
269
|
+
* Emscripten finds the `.wasm` next to the script that loaded the glue. Glue
|
|
270
|
+
* pulled into a Worker with `importScripts()` sees the *Worker's* URL instead,
|
|
271
|
+
* so without a `locateFile` it fetches the binary from the app's own origin;
|
|
272
|
+
* this pairs the glue's URL with one that points at the CDN. The URLs name
|
|
273
|
+
* this package's exact version by default, so the glue and the TypeScript
|
|
274
|
+
* calling it always match.
|
|
275
|
+
*
|
|
276
|
+
* Both builds load this way. jsDelivr and unpkg send
|
|
277
|
+
* `Cross-Origin-Resource-Policy: cross-origin`, which a cross-origin isolated
|
|
278
|
+
* page needs for the threaded build; the threaded build's own workers start
|
|
279
|
+
* from the Worker's script, which must be on the app's origin.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```js
|
|
283
|
+
* // the engine Worker, on the app's own origin
|
|
284
|
+
* const { glueUrl, locateFile } = cdnArtifacts();
|
|
285
|
+
* importScripts(glueUrl);
|
|
286
|
+
* self.FIREBIRD_WORKER_OPTIONS = { locateFile };
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
export declare function cdnArtifacts(options?: CdnOptions): CdnArtifacts;
|
|
290
|
+
/**
|
|
291
|
+
* True when the module's heap is a `SharedArrayBuffer`, which is the case for
|
|
292
|
+
* the threaded build only.
|
|
293
|
+
*/
|
|
294
|
+
export declare function hasSharedHeap(mod: FirebirdWasmModule): boolean;
|
|
213
295
|
/**
|
|
214
296
|
* Allocate a UTF-8 C string on the WASM heap and return its pointer.
|
|
215
297
|
* The caller is responsible for calling `mod._free(ptr)` afterwards.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm-loader.d.ts","sourceRoot":"","sources":["../src/wasm-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"wasm-loader.d.ts","sourceRoot":"","sources":["../src/wasm-loader.ts"],"names":[],"mappings":"AAAA;;;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,MAAM,CAKxE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAGzD"}
|
package/dist/wasm-loader.js
CHANGED
|
@@ -11,13 +11,45 @@
|
|
|
11
11
|
* library.
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.wasmGlueFile = wasmGlueFile;
|
|
14
15
|
exports.loadFirebirdWasm = loadFirebirdWasm;
|
|
16
|
+
exports.cdnArtifacts = cdnArtifacts;
|
|
17
|
+
exports.hasSharedHeap = hasSharedHeap;
|
|
15
18
|
exports.allocString = allocString;
|
|
16
19
|
exports.lastError = lastError;
|
|
20
|
+
const version_1 = require("./version");
|
|
17
21
|
// ---------------------------------------------------------------------------
|
|
18
22
|
// Module state
|
|
19
23
|
// ---------------------------------------------------------------------------
|
|
20
|
-
|
|
24
|
+
/** One module per build: the two can live side by side in one process. */
|
|
25
|
+
const cachedModules = new Map();
|
|
26
|
+
/**
|
|
27
|
+
* The glue script of the build `threads` selects.
|
|
28
|
+
*
|
|
29
|
+
* `'auto'` (the default) picks the threaded build where it can run: in Node,
|
|
30
|
+
* and in a browser page or worker that is cross-origin isolated. Elsewhere,
|
|
31
|
+
* GitHub Pages and other static hosts that cannot send COOP/COEP among them,
|
|
32
|
+
* it picks the build without threads, which needs neither.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```js
|
|
36
|
+
* // in the engine's Worker, before the transport loads the module
|
|
37
|
+
* importScripts(`/wasm/${wasmGlueFile()}`);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function wasmGlueFile(threads = 'auto') {
|
|
41
|
+
return useThreads(threads) ? 'firebird-embedded.js' : 'firebird-embedded-st.js';
|
|
42
|
+
}
|
|
43
|
+
function useThreads(threads) {
|
|
44
|
+
if (threads === true || threads === false)
|
|
45
|
+
return threads;
|
|
46
|
+
const g = globalThis;
|
|
47
|
+
if (typeof g['process'] !== 'undefined' && typeof g['window'] === 'undefined'
|
|
48
|
+
&& typeof g['WorkerGlobalScope'] === 'undefined') {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return g['crossOriginIsolated'] === true;
|
|
52
|
+
}
|
|
21
53
|
// ---------------------------------------------------------------------------
|
|
22
54
|
// Public API
|
|
23
55
|
// ---------------------------------------------------------------------------
|
|
@@ -37,13 +69,24 @@ let cachedModule = null;
|
|
|
37
69
|
* ```
|
|
38
70
|
*/
|
|
39
71
|
async function loadFirebirdWasm(options = {}) {
|
|
40
|
-
|
|
41
|
-
|
|
72
|
+
const glueFile = wasmGlueFile(options.threads);
|
|
73
|
+
const cached = cachedModules.get(glueFile);
|
|
74
|
+
if (cached)
|
|
75
|
+
return cached;
|
|
42
76
|
// The Emscripten glue script exports a factory function named
|
|
43
77
|
// `createFirebirdModule` (configured via `-s EXPORT_NAME` in CMake).
|
|
44
78
|
// In Node it can be `require()`-d; in browsers it is expected to be
|
|
45
79
|
// available on `globalThis` or loaded via a <script> tag / importmap.
|
|
46
|
-
const factory = await resolveFactory(
|
|
80
|
+
const factory = await resolveFactory(glueFile);
|
|
81
|
+
// Each build marks its factory (wasm/glue-threads.js, wasm/glue-st.js).
|
|
82
|
+
// The threaded one cannot run without SharedArrayBuffer: its runtime fails
|
|
83
|
+
// to hand its memory to its own workers, the error is not reported to the
|
|
84
|
+
// caller, and every call waits forever. Say so instead.
|
|
85
|
+
if (factory.threads === true && globalThis['crossOriginIsolated'] === false) {
|
|
86
|
+
throw new Error('firebird-embedded.js is the threaded build, which needs SharedArrayBuffer, and this page is ' +
|
|
87
|
+
'not cross-origin isolated (it needs COOP/COEP headers). Load firebird-embedded-st.js, the ' +
|
|
88
|
+
'build without threads, instead: wasmGlueFile() names the build a page can run.');
|
|
89
|
+
}
|
|
47
90
|
const moduleOptions = {};
|
|
48
91
|
if (options.locateFile) {
|
|
49
92
|
moduleOptions['locateFile'] = options.locateFile;
|
|
@@ -57,9 +100,52 @@ async function loadFirebirdWasm(options = {}) {
|
|
|
57
100
|
}
|
|
58
101
|
}
|
|
59
102
|
const mod = await factory(moduleOptions);
|
|
60
|
-
|
|
103
|
+
cachedModules.set(glueFile, mod);
|
|
61
104
|
return mod;
|
|
62
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* The engine's URLs on a CDN, so nothing has to be copied next to the app.
|
|
108
|
+
*
|
|
109
|
+
* Emscripten finds the `.wasm` next to the script that loaded the glue. Glue
|
|
110
|
+
* pulled into a Worker with `importScripts()` sees the *Worker's* URL instead,
|
|
111
|
+
* so without a `locateFile` it fetches the binary from the app's own origin;
|
|
112
|
+
* this pairs the glue's URL with one that points at the CDN. The URLs name
|
|
113
|
+
* this package's exact version by default, so the glue and the TypeScript
|
|
114
|
+
* calling it always match.
|
|
115
|
+
*
|
|
116
|
+
* Both builds load this way. jsDelivr and unpkg send
|
|
117
|
+
* `Cross-Origin-Resource-Policy: cross-origin`, which a cross-origin isolated
|
|
118
|
+
* page needs for the threaded build; the threaded build's own workers start
|
|
119
|
+
* from the Worker's script, which must be on the app's origin.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```js
|
|
123
|
+
* // the engine Worker, on the app's own origin
|
|
124
|
+
* const { glueUrl, locateFile } = cdnArtifacts();
|
|
125
|
+
* importScripts(glueUrl);
|
|
126
|
+
* self.FIREBIRD_WORKER_OPTIONS = { locateFile };
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
function cdnArtifacts(options = {}) {
|
|
130
|
+
const version = options.version ?? version_1.VERSION;
|
|
131
|
+
const cdn = options.cdn ?? 'jsdelivr';
|
|
132
|
+
const base = cdn === 'jsdelivr'
|
|
133
|
+
? `https://cdn.jsdelivr.net/npm/firebird-wasm@${version}/dist/wasm/`
|
|
134
|
+
: cdn === 'unpkg'
|
|
135
|
+
? `https://unpkg.com/firebird-wasm@${version}/dist/wasm/`
|
|
136
|
+
: cdn.endsWith('/') ? cdn : `${cdn}/`;
|
|
137
|
+
return {
|
|
138
|
+
glueUrl: base + wasmGlueFile(options.threads),
|
|
139
|
+
locateFile: (file) => base + file,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* True when the module's heap is a `SharedArrayBuffer`, which is the case for
|
|
144
|
+
* the threaded build only.
|
|
145
|
+
*/
|
|
146
|
+
function hasSharedHeap(mod) {
|
|
147
|
+
return typeof SharedArrayBuffer !== 'undefined' && mod.HEAPU8.buffer instanceof SharedArrayBuffer;
|
|
148
|
+
}
|
|
63
149
|
/**
|
|
64
150
|
* Allocate a UTF-8 C string on the WASM heap and return its pointer.
|
|
65
151
|
* The caller is responsible for calling `mod._free(ptr)` afterwards.
|
|
@@ -80,16 +166,22 @@ function lastError(mod) {
|
|
|
80
166
|
const ptr = mod._fb_last_error();
|
|
81
167
|
return ptr ? mod.UTF8ToString(ptr) : '';
|
|
82
168
|
}
|
|
83
|
-
async function resolveFactory(
|
|
169
|
+
async function resolveFactory(glueFile) {
|
|
84
170
|
// Node.js environment
|
|
85
171
|
if (typeof globalThis !== 'undefined' && typeof globalThis['process'] !== 'undefined') {
|
|
86
172
|
try {
|
|
87
|
-
//
|
|
88
|
-
|
|
173
|
+
// Two literal requires, not one with the name in a template: a bundler
|
|
174
|
+
// resolves string literals (and marks these external), but turns a
|
|
175
|
+
// template into a glob over dist/wasm, .wasm files included.
|
|
176
|
+
const glue = glueFile === 'firebird-embedded-st.js'
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
178
|
+
? require('../dist/wasm/firebird-embedded-st.js')
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
180
|
+
: require('../dist/wasm/firebird-embedded.js');
|
|
89
181
|
return glue;
|
|
90
182
|
}
|
|
91
183
|
catch {
|
|
92
|
-
throw new Error(
|
|
184
|
+
throw new Error(`${glueFile} not found. Run the WASM build first: packages/firebird-wasm/wasm/build.sh`);
|
|
93
185
|
}
|
|
94
186
|
}
|
|
95
187
|
// Browser environment – look on globalThis
|
package/dist/wasm-loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm-loader.js","sourceRoot":"","sources":["../src/wasm-loader.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;
|
|
1
|
+
{"version":3,"file":"wasm-loader.js","sourceRoot":"","sources":["../src/wasm-loader.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AA2QH,oCAEC;AA+BD,4CA0CC;AA8CD,oCAaC;AAMD,sCAEC;AAMD,kCAKC;AAQD,8BAGC;AA7aD,uCAAoC;AAoPpC,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E,0EAA0E;AAC1E,MAAM,aAAa,GAAG,IAAI,GAAG,EAA8B,CAAC;AAE5D;;;;;;;;;;;;;GAaG;AACH,SAAgB,YAAY,CAAC,UAA4B,MAAM;IAC7D,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,yBAAyB,CAAC;AAClF,CAAC;AAED,SAAS,UAAU,CAAC,OAAqC;IACvD,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK;QAAE,OAAO,OAAO,CAAC;IAC1D,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,IAAI,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,WAAW,IAAI,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,WAAW;WACxE,OAAO,CAAC,CAAC,mBAAmB,CAAC,KAAK,WAAW,EAAE,CAAC;QACnD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,CAAC,qBAAqB,CAAC,KAAK,IAAI,CAAC;AAC3C,CAAC;AAED,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,gBAAgB,CACpC,UAA2B,EAAE;IAE7B,MAAM,QAAQ,GAAG,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AAU,cAAc,CAAC,QAAgB;IAC5C,sBAAsB;IACtB,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,OAAQ,UAAsC,CAAC,SAAS,CAAC,KAAK,WAAW,EAAE,CAAC;QACnH,IAAI,CAAC;YACH,uEAAuE;YACvE,mEAAmE;YACnE,6DAA6D;YAC7D,MAAM,IAAI,GAAG,QAAQ,KAAK,yBAAyB;gBACjD,8DAA8D;gBAC9D,CAAC,CAAC,OAAO,CAAC,sCAAsC,CAAC;gBACjD,8DAA8D;gBAC9D,CAAC,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC;YACjD,OAAO,IAAqB,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CACb,GAAG,QAAQ,6EAA6E,CACzF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,2CAA2C;IAC3C,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,IAAI,OAAO,CAAC,CAAC,sBAAsB,CAAC,KAAK,UAAU,EAAE,CAAC;QACpD,OAAO,CAAC,CAAC,sBAAsB,CAAkB,CAAC;IACpD,CAAC;IAED,MAAM,IAAI,KAAK,CACb,8CAA8C;QAC5C,8FAA8F,CACjG,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebird-wasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Firebird embedded database in WebAssembly — runs in the browser and Node, like PGlite for PostgreSQL",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"build:wasm": "bash wasm/build.sh",
|
|
21
21
|
"test": "jest --forceExit",
|
|
22
22
|
"bench": "node bench/decode-bench.js",
|
|
23
|
+
"bench:calls": "node bench/call-cost.js",
|
|
24
|
+
"size": "node scripts/size-budget.mjs",
|
|
23
25
|
"lint": "eslint src --ext .ts",
|
|
24
26
|
"clean": "rm -rf dist",
|
|
25
27
|
"prepublishOnly": "node scripts/check-publish.mjs"
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* statement-types.ts – names for Firebird's statement-type codes.
|
|
3
|
-
*
|
|
4
|
-
* The engine reports what a statement *is* as one of the `isc_info_sql_stmt_*`
|
|
5
|
-
* constants. A caller asking `describeQuery()` what they have wants the name,
|
|
6
|
-
* not the number — the number is only meaningful next to a copy of
|
|
7
|
-
* `iberror.h`.
|
|
8
|
-
*/
|
|
9
|
-
import type { StatementKind } from '../types';
|
|
10
|
-
/**
|
|
11
|
-
* Name a statement-type code.
|
|
12
|
-
*
|
|
13
|
-
* An unrecognised code is `'UNKNOWN'` rather than an error: a Firebird release
|
|
14
|
-
* may add one, and a name this library has not learned yet is no reason to
|
|
15
|
-
* fail a description that is otherwise complete.
|
|
16
|
-
*/
|
|
17
|
-
export declare function statementKind(code: number): StatementKind;
|
|
18
|
-
//# sourceMappingURL=statement-types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"statement-types.d.ts","sourceRoot":"","sources":["../../src/browser/statement-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAoB9C;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAEzD"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* statement-types.ts – names for Firebird's statement-type codes.
|
|
4
|
-
*
|
|
5
|
-
* The engine reports what a statement *is* as one of the `isc_info_sql_stmt_*`
|
|
6
|
-
* constants. A caller asking `describeQuery()` what they have wants the name,
|
|
7
|
-
* not the number — the number is only meaningful next to a copy of
|
|
8
|
-
* `iberror.h`.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.statementKind = statementKind;
|
|
12
|
-
// From firebird/impl/consts_pub.h (isc_info_sql_stmt_*).
|
|
13
|
-
const NAMES = {
|
|
14
|
-
1: 'SELECT',
|
|
15
|
-
2: 'INSERT',
|
|
16
|
-
3: 'UPDATE',
|
|
17
|
-
4: 'DELETE',
|
|
18
|
-
5: 'DDL',
|
|
19
|
-
6: 'GET_SEGMENT',
|
|
20
|
-
7: 'PUT_SEGMENT',
|
|
21
|
-
8: 'EXEC_PROCEDURE',
|
|
22
|
-
9: 'START_TRANS',
|
|
23
|
-
10: 'COMMIT',
|
|
24
|
-
11: 'ROLLBACK',
|
|
25
|
-
12: 'SELECT_FOR_UPD',
|
|
26
|
-
13: 'SET_GENERATOR',
|
|
27
|
-
14: 'SAVEPOINT',
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Name a statement-type code.
|
|
31
|
-
*
|
|
32
|
-
* An unrecognised code is `'UNKNOWN'` rather than an error: a Firebird release
|
|
33
|
-
* may add one, and a name this library has not learned yet is no reason to
|
|
34
|
-
* fail a description that is otherwise complete.
|
|
35
|
-
*/
|
|
36
|
-
function statementKind(code) {
|
|
37
|
-
return NAMES[code] ?? 'UNKNOWN';
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=statement-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"statement-types.js","sourceRoot":"","sources":["../../src/browser/statement-types.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AA6BH,sCAEC;AA3BD,yDAAyD;AACzD,MAAM,KAAK,GAAkC;IAC3C,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,aAAa;IAChB,CAAC,EAAE,aAAa;IAChB,CAAC,EAAE,gBAAgB;IACnB,CAAC,EAAE,aAAa;IAChB,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,gBAAgB;IACpB,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,WAAW;CAChB,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,IAAY;IACxC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC;AAClC,CAAC"}
|