@bbn/bbn 2.0.238 → 2.0.239
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/dist/bbn.js +3 -3
- package/dist/bbn.js.map +1 -1
- package/dist/bbn.sw.js +3 -3
- package/dist/bbn.sw.js.map +1 -1
- package/dist/db/classes/Center.d.ts +10 -0
- package/dist/db/classes/Center.js +88 -0
- package/dist/db/classes/Object.d.ts +2 -2
- package/dist/db/classes/Object.js +24 -13
- package/dist/db/classes/ObjectProxy.d.ts +2 -2
- package/dist/db/classes/ObjectProxy.js +13 -11
- package/dist/db/classes/Proxy.d.ts +3 -10
- package/dist/db/classes/Proxy.js +6 -20
- package/dist/db/types.d.ts +11 -9
- package/dist/db.d.ts +3 -2
- package/dist/db.js +3 -2
- package/dist/dt.js +2 -3
- package/dist/fn/ajax/stream.js +3 -2
- package/dist/fn/browser/log.js +3 -0
- package/dist/fn/object/_filter.js +2 -1
- package/dist/fn/object/filter.js +2 -1
- package/dist/index-no-dep.js +9 -2
- package/dist/index.js +11 -2
- package/package.json +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import bbnDb from './Object.js';
|
|
2
|
+
export default class bbnDbCenter {
|
|
3
|
+
queues = {};
|
|
4
|
+
async handleMessage(event) {
|
|
5
|
+
const command = event.data;
|
|
6
|
+
const port = event.ports?.[0];
|
|
7
|
+
bbn.fn.log("Received DB command:", command, port, "END");
|
|
8
|
+
if (!port || !command?.method?.includes('.')) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const [scope] = command.method.split('.');
|
|
12
|
+
if (scope !== 'manager' && scope !== 'object') {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (!command.id || !command.database) {
|
|
16
|
+
this.postError(port, command?.id ?? 0, 'Invalid DB command');
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
const database = command.database;
|
|
20
|
+
this.queues[database] = (this.queues[database] || Promise.resolve())
|
|
21
|
+
.catch(() => undefined)
|
|
22
|
+
.then(async () => {
|
|
23
|
+
try {
|
|
24
|
+
const result = await this.execute(command);
|
|
25
|
+
this.postSuccess(port, command.id, result);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
this.postError(port, command.id, this.serializeError(error));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
async execute(command) {
|
|
34
|
+
const [scope, action] = command.method.split('.');
|
|
35
|
+
if (!action) {
|
|
36
|
+
throw new Error(`Invalid DB method: ${command.method}`);
|
|
37
|
+
}
|
|
38
|
+
if (scope === 'manager') {
|
|
39
|
+
return this.executeManager(action, command.args || []);
|
|
40
|
+
}
|
|
41
|
+
if (scope === 'object') {
|
|
42
|
+
return this.executeObject(action, [command.database, ...(command.args || [])]);
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`Unknown DB command scope: ${scope}`);
|
|
45
|
+
}
|
|
46
|
+
async executeManager(action, args) {
|
|
47
|
+
const fn = bbnDb[action];
|
|
48
|
+
if (typeof fn !== 'function') {
|
|
49
|
+
throw new Error(`Unknown DB manager method: ${action}`);
|
|
50
|
+
}
|
|
51
|
+
return fn.apply(bbnDb, args);
|
|
52
|
+
}
|
|
53
|
+
async executeObject(action, args) {
|
|
54
|
+
const [database, ...methodArgs] = args;
|
|
55
|
+
if (!database) {
|
|
56
|
+
throw new Error('Missing database name for object method');
|
|
57
|
+
}
|
|
58
|
+
bbn.fn.log(`Executing object method: ${action} on database: ${database}`);
|
|
59
|
+
const dbo = await bbnDb.open(database);
|
|
60
|
+
const fn = dbo[action];
|
|
61
|
+
if (typeof fn !== 'function') {
|
|
62
|
+
throw new Error(`Unknown DB object method: ${action}`);
|
|
63
|
+
}
|
|
64
|
+
return fn.apply(dbo, methodArgs);
|
|
65
|
+
}
|
|
66
|
+
postSuccess(port, id, result) {
|
|
67
|
+
port.postMessage({
|
|
68
|
+
id,
|
|
69
|
+
ok: true,
|
|
70
|
+
result
|
|
71
|
+
});
|
|
72
|
+
port.close();
|
|
73
|
+
}
|
|
74
|
+
postError(port, id, error) {
|
|
75
|
+
port.postMessage({
|
|
76
|
+
id,
|
|
77
|
+
ok: false,
|
|
78
|
+
error
|
|
79
|
+
});
|
|
80
|
+
port.close();
|
|
81
|
+
}
|
|
82
|
+
serializeError(error) {
|
|
83
|
+
if (error instanceof Error) {
|
|
84
|
+
return error.message;
|
|
85
|
+
}
|
|
86
|
+
return String(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const db:
|
|
1
|
+
import { DbManagerInternal } from '../types.js';
|
|
2
|
+
declare const db: DbManagerInternal;
|
|
3
3
|
export default db;
|
|
@@ -9,17 +9,20 @@ import getPrimaryKey from '../functions/getPrimaryKey.js';
|
|
|
9
9
|
import requestToPromise from '../functions/requestToPromise.js';
|
|
10
10
|
import transformResult from '../functions/transformResult.js';
|
|
11
11
|
import fieldsFromFilter from '../functions/fieldsFromFilter.js';
|
|
12
|
-
import
|
|
12
|
+
import bbnDbObjectProxy from './ObjectProxy.js';
|
|
13
13
|
const idb = globalThis.indexedDB ||
|
|
14
14
|
globalThis.webkitIndexedDB ||
|
|
15
15
|
globalThis.mozIndexedDB ||
|
|
16
16
|
globalThis.OIndexedDB ||
|
|
17
17
|
globalThis.msIndexedDB;
|
|
18
18
|
class DbObject {
|
|
19
|
-
|
|
19
|
+
_dbName;
|
|
20
20
|
lastErr = null;
|
|
21
21
|
constructor(dbName) {
|
|
22
|
-
this.
|
|
22
|
+
this._dbName = dbName;
|
|
23
|
+
}
|
|
24
|
+
get dbName() {
|
|
25
|
+
return this._dbName;
|
|
23
26
|
}
|
|
24
27
|
hasMissingStores(database, conn) {
|
|
25
28
|
const structures = db._structures[database] || {};
|
|
@@ -29,6 +32,7 @@ class DbObject {
|
|
|
29
32
|
let conn = db._connections[database || this.dbName];
|
|
30
33
|
if (!conn) {
|
|
31
34
|
debugger;
|
|
35
|
+
log("Opening connection through getConnection to database: " + (database || this.dbName));
|
|
32
36
|
await db.open(database || this.dbName);
|
|
33
37
|
if (!db._connections[database || this.dbName]) {
|
|
34
38
|
throw new Error(_('The database %s is not open', this.dbName));
|
|
@@ -47,6 +51,7 @@ class DbObject {
|
|
|
47
51
|
async getStore(table, mode) {
|
|
48
52
|
const connection = await this.getConnection();
|
|
49
53
|
if (!this.structure[table]) {
|
|
54
|
+
log("No structure for table: " + table, this.structure, db._structures);
|
|
50
55
|
throw new Error(_('Table %s is not defined in database structure %s', table, this.dbName));
|
|
51
56
|
}
|
|
52
57
|
if (!connection.objectStoreNames.contains(table)) {
|
|
@@ -75,11 +80,7 @@ class DbObject {
|
|
|
75
80
|
return this.lastErr;
|
|
76
81
|
}
|
|
77
82
|
close() {
|
|
78
|
-
|
|
79
|
-
if (conn) {
|
|
80
|
-
conn.close();
|
|
81
|
-
delete db._connections[this.dbName];
|
|
82
|
-
}
|
|
83
|
+
return db.close(this.dbName);
|
|
83
84
|
}
|
|
84
85
|
async insert(table, data) {
|
|
85
86
|
const rows = Array.isArray(data) ? data : [data];
|
|
@@ -266,12 +267,14 @@ const db = {
|
|
|
266
267
|
if (conn) {
|
|
267
268
|
conn.close();
|
|
268
269
|
delete this._connections[database];
|
|
270
|
+
log("Closing connection to database: " + database);
|
|
269
271
|
}
|
|
270
272
|
if (this._objects[database]) {
|
|
271
273
|
delete this._objects[database];
|
|
272
274
|
}
|
|
273
275
|
},
|
|
274
276
|
updateStructure(storeName, structure, database) {
|
|
277
|
+
log("fn updateStructure, table: " + storeName + ", in SW? " + !globalThis.document);
|
|
275
278
|
const primary = getPrimaryKey(structure);
|
|
276
279
|
if (!database.objectStoreNames.contains(storeName)) {
|
|
277
280
|
const store = database.createObjectStore(storeName, {
|
|
@@ -285,13 +288,13 @@ const db = {
|
|
|
285
288
|
}
|
|
286
289
|
},
|
|
287
290
|
async importStructure(database, structure) {
|
|
291
|
+
log("fn importStructure");
|
|
288
292
|
if (!this._structures[database]) {
|
|
289
293
|
this._structures[database] = {};
|
|
290
294
|
}
|
|
291
|
-
if (this._connections[database]) {
|
|
292
|
-
|
|
295
|
+
if (!this._connections[database]) {
|
|
296
|
+
await this.open(database);
|
|
293
297
|
}
|
|
294
|
-
await this.open(database);
|
|
295
298
|
const conn = this._connections[database];
|
|
296
299
|
let upgrade = false;
|
|
297
300
|
for (const storeName in structure) {
|
|
@@ -340,10 +343,11 @@ const db = {
|
|
|
340
343
|
});
|
|
341
344
|
},
|
|
342
345
|
async reopenWithUpgrade(name) {
|
|
346
|
+
log("fn reopenWithUpgrade", this._structures);
|
|
343
347
|
if (!this._structures[name]) {
|
|
344
348
|
throw new Error(_('Impossible to find a structure for the database %s', name));
|
|
345
349
|
}
|
|
346
|
-
const existingVersion = await this.getExistingVersion(name);
|
|
350
|
+
const existingVersion = await this.getExistingVersion(name) || 0;
|
|
347
351
|
const nextVersion = existingVersion + 1;
|
|
348
352
|
log(_('Going from version %s to version %s for database %s', existingVersion, nextVersion, name));
|
|
349
353
|
if (this._connections[name]) {
|
|
@@ -352,11 +356,16 @@ const db = {
|
|
|
352
356
|
return await this.open(name, nextVersion);
|
|
353
357
|
},
|
|
354
358
|
async open(database, version) {
|
|
359
|
+
log("fn open database " + database + " version " + version, this._structures);
|
|
360
|
+
if (database !== 'bbn') {
|
|
361
|
+
log("THERE SHOULD BE A DEBUGGER!!!!!!!");
|
|
362
|
+
debugger;
|
|
363
|
+
}
|
|
355
364
|
if (!idb) {
|
|
356
365
|
throw new Error(_('IndexedDB is not available'));
|
|
357
366
|
}
|
|
358
367
|
if (navigator.serviceWorker?.controller) {
|
|
359
|
-
return new Promise(resolve => resolve(new
|
|
368
|
+
return new Promise(resolve => resolve(new bbnDbObjectProxy(database)));
|
|
360
369
|
}
|
|
361
370
|
if (!this._structures[database]) {
|
|
362
371
|
throw new Error(_('Impossible to find a structure for the database %s', database));
|
|
@@ -389,6 +398,7 @@ const db = {
|
|
|
389
398
|
return this._objects[database];
|
|
390
399
|
},
|
|
391
400
|
async add(database, name, structure) {
|
|
401
|
+
log("fn add " + name);
|
|
392
402
|
if (!structure?.keys?.PRIMARY || !structure?.fields) {
|
|
393
403
|
log("Error on add", structure);
|
|
394
404
|
throw new Error(_('The database structure for %s is not valid (missing keys, fields, or primary key)', name));
|
|
@@ -415,6 +425,7 @@ const db = {
|
|
|
415
425
|
return true;
|
|
416
426
|
},
|
|
417
427
|
async remove(database, name) {
|
|
428
|
+
log("fn remove");
|
|
418
429
|
const currentStructure = this._structures[database];
|
|
419
430
|
if (!currentStructure?.[name]) {
|
|
420
431
|
return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class bbnDbObjectProxy implements
|
|
1
|
+
import { DbApi, OrderClause } from '../types.js';
|
|
2
|
+
export default class bbnDbObjectProxy implements DbApi {
|
|
3
3
|
private readonly _dbName;
|
|
4
4
|
lastErr: any;
|
|
5
5
|
constructor(dbName: string);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import log from '../../fn/browser/log.js';
|
|
1
2
|
let requestId = 0;
|
|
2
3
|
function callServiceWorker(obj, method, args) {
|
|
3
4
|
return new Promise((resolve, reject) => {
|
|
@@ -9,6 +10,7 @@ function callServiceWorker(obj, method, args) {
|
|
|
9
10
|
const channel = new MessageChannel();
|
|
10
11
|
channel.port1.onmessage = event => {
|
|
11
12
|
const msg = event.data;
|
|
13
|
+
log(['SW response', msg]);
|
|
12
14
|
if (msg?.id !== id) {
|
|
13
15
|
return;
|
|
14
16
|
}
|
|
@@ -42,36 +44,36 @@ export default class bbnDbObjectProxy {
|
|
|
42
44
|
return this._dbName;
|
|
43
45
|
}
|
|
44
46
|
insert(table, data) {
|
|
45
|
-
return callServiceWorker(this, 'insert', [table, data]);
|
|
47
|
+
return callServiceWorker(this, 'object.insert', [table, data]);
|
|
46
48
|
}
|
|
47
49
|
update(table, data, where, replace = false) {
|
|
48
|
-
return callServiceWorker(this, 'update', [table, data, where, replace]);
|
|
50
|
+
return callServiceWorker(this, 'object.update', [table, data, where, replace]);
|
|
49
51
|
}
|
|
50
52
|
delete(table, where) {
|
|
51
|
-
return callServiceWorker(this, 'delete', [table, where]);
|
|
53
|
+
return callServiceWorker(this, 'object.delete', [table, where]);
|
|
52
54
|
}
|
|
53
55
|
selectOne(table, field, where, order, start, limit) {
|
|
54
|
-
return callServiceWorker(this, 'selectOne', [table, field, where, order, start, limit]);
|
|
56
|
+
return callServiceWorker(this, 'object.selectOne', [table, field, where, order, start, limit]);
|
|
55
57
|
}
|
|
56
58
|
select(table, fields, where, order, start) {
|
|
57
|
-
return callServiceWorker(this, 'select', [table, fields, where, order, start]);
|
|
59
|
+
return callServiceWorker(this, 'object.select', [table, fields, where, order, start]);
|
|
58
60
|
}
|
|
59
61
|
selectAll(table, fields, where, order, start, limit) {
|
|
60
|
-
return callServiceWorker(this, 'selectAll', [table, fields, where, order, start, limit]);
|
|
62
|
+
return callServiceWorker(this, 'object.selectAll', [table, fields, where, order, start, limit]);
|
|
61
63
|
}
|
|
62
64
|
getColumnValues(table, field, where, order, start, limit) {
|
|
63
|
-
return callServiceWorker(this, 'getColumnValues', [table, field, where, order, start, limit]);
|
|
65
|
+
return callServiceWorker(this, 'object.getColumnValues', [table, field, where, order, start, limit]);
|
|
64
66
|
}
|
|
65
67
|
copyTable(target, table, fields, where, order, start, limit) {
|
|
66
|
-
return callServiceWorker(this, 'copyTable', [target, table, fields, where, order, start, limit]);
|
|
68
|
+
return callServiceWorker(this, 'object.copyTable', [target, table, fields, where, order, start, limit]);
|
|
67
69
|
}
|
|
68
70
|
deleteTable(table) {
|
|
69
|
-
return callServiceWorker(this, 'deleteTable', [table]);
|
|
71
|
+
return callServiceWorker(this, 'object.deleteTable', [table]);
|
|
70
72
|
}
|
|
71
73
|
close() {
|
|
72
|
-
void callServiceWorker(this, 'close', []);
|
|
74
|
+
void callServiceWorker(this, 'object.close', []);
|
|
73
75
|
}
|
|
74
76
|
lastError() {
|
|
75
|
-
return this.
|
|
77
|
+
return callServiceWorker(this, 'object.lastError', [this.dbName]);
|
|
76
78
|
}
|
|
77
79
|
}
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DbApi, DbStructure } from '../types.js';
|
|
2
2
|
declare const bbnDbProxy: {
|
|
3
|
-
_structures: {};
|
|
4
|
-
_connections: {};
|
|
5
|
-
_objects: {};
|
|
6
|
-
_stores: {};
|
|
7
3
|
ok: boolean;
|
|
8
|
-
open(database: string, version?: number): Promise<
|
|
4
|
+
open(database: string, version?: number): Promise<DbApi>;
|
|
9
5
|
add(database: string, name: string, structure: DbStructure): Promise<boolean>;
|
|
10
6
|
remove(database: string, name: string): Promise<void>;
|
|
11
7
|
importStructure(database: string, structure: Record<string, DbStructure>): Promise<void>;
|
|
12
|
-
|
|
13
|
-
getExistingVersion(database: string): Promise<number>;
|
|
14
|
-
close(database: string): void;
|
|
15
|
-
updateStructure(): never;
|
|
8
|
+
close(database: string): Promise<void>;
|
|
16
9
|
};
|
|
17
10
|
export default bbnDbProxy;
|
package/dist/db/classes/Proxy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import bbnDbObjectProxy from './ObjectProxy.js';
|
|
2
|
-
let requestId =
|
|
2
|
+
let requestId = 0;
|
|
3
3
|
function callServiceWorker(database, method, args) {
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
5
5
|
if (!navigator.serviceWorker?.controller) {
|
|
@@ -31,36 +31,22 @@ function callServiceWorker(database, method, args) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
const bbnDbProxy = {
|
|
34
|
-
_structures: {},
|
|
35
|
-
_connections: {},
|
|
36
|
-
_objects: {},
|
|
37
|
-
_stores: {},
|
|
38
34
|
ok: true,
|
|
39
35
|
async open(database, version) {
|
|
40
36
|
await callServiceWorker(database, 'manager.open', [database, version]);
|
|
41
37
|
return new bbnDbObjectProxy(database);
|
|
42
38
|
},
|
|
43
39
|
async add(database, name, structure) {
|
|
44
|
-
return callServiceWorker(database, 'manager.add', [database, name, structure]);
|
|
40
|
+
return await callServiceWorker(database, 'manager.add', [database, name, structure]);
|
|
45
41
|
},
|
|
46
42
|
async remove(database, name) {
|
|
47
|
-
return callServiceWorker(database, 'manager.remove', [database, name]);
|
|
43
|
+
return await callServiceWorker(database, 'manager.remove', [database, name]);
|
|
48
44
|
},
|
|
49
45
|
async importStructure(database, structure) {
|
|
50
|
-
return callServiceWorker(database, 'manager.importStructure', [database, structure]);
|
|
46
|
+
return await callServiceWorker(database, 'manager.importStructure', [database, structure]);
|
|
51
47
|
},
|
|
52
|
-
async
|
|
53
|
-
await callServiceWorker(database, 'manager.
|
|
54
|
-
return new bbnDbObjectProxy(database);
|
|
55
|
-
},
|
|
56
|
-
async getExistingVersion(database) {
|
|
57
|
-
return callServiceWorker(database, 'manager.getExistingVersion', [database]);
|
|
58
|
-
},
|
|
59
|
-
close(database) {
|
|
60
|
-
void callServiceWorker(database, 'manager.close', [database]);
|
|
61
|
-
},
|
|
62
|
-
updateStructure() {
|
|
63
|
-
throw new Error('updateStructure cannot be called from the window proxy');
|
|
48
|
+
async close(database) {
|
|
49
|
+
return await callServiceWorker(database, 'manager.close', [database]);
|
|
64
50
|
}
|
|
65
51
|
};
|
|
66
52
|
export default bbnDbProxy;
|
package/dist/db/types.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type DbCommand = {
|
|
|
22
22
|
method: string;
|
|
23
23
|
args: unknown[];
|
|
24
24
|
};
|
|
25
|
-
export interface
|
|
25
|
+
export interface DbApi {
|
|
26
26
|
lastErr: any;
|
|
27
27
|
get dbName(): string;
|
|
28
28
|
lastError(): unknown;
|
|
@@ -38,17 +38,19 @@ export interface IDbApi {
|
|
|
38
38
|
deleteTable(table: string): Promise<boolean>;
|
|
39
39
|
}
|
|
40
40
|
export interface DbManager {
|
|
41
|
-
_structures: DbStructures;
|
|
42
|
-
_connections: Record<string, IDBDatabase>;
|
|
43
|
-
_objects: Record<string, IDbApi>;
|
|
44
|
-
_stores: Record<string, unknown>;
|
|
45
41
|
ok: boolean;
|
|
46
|
-
open(name: string, version?: number): Promise<
|
|
42
|
+
open(name: string, version?: number): Promise<DbApi>;
|
|
47
43
|
add(database: string, name: string, structure: DbStructure): Promise<boolean>;
|
|
48
44
|
remove(database: string, name: string): Promise<void>;
|
|
49
|
-
updateStructure(storeName: string, structure: DbStructure, database: IDBDatabase): void;
|
|
50
45
|
importStructure(database: string, structure: Record<string, DbStructure>): Promise<void>;
|
|
51
|
-
reopenWithUpgrade(name: string): Promise<IDbApi>;
|
|
52
|
-
getExistingVersion(name: string): Promise<number>;
|
|
53
46
|
close(database: string): void;
|
|
54
47
|
}
|
|
48
|
+
export interface DbManagerInternal extends DbManager {
|
|
49
|
+
_structures: DbStructures;
|
|
50
|
+
_connections: Record<string, IDBDatabase>;
|
|
51
|
+
_objects: Record<string, DbApi>;
|
|
52
|
+
_stores: Record<string, unknown>;
|
|
53
|
+
updateStructure(storeName: string, structure: DbStructure, database: IDBDatabase): void;
|
|
54
|
+
reopenWithUpgrade(name: string): Promise<DbApi>;
|
|
55
|
+
getExistingVersion(name: string): Promise<number>;
|
|
56
|
+
}
|
package/dist/db.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import bbnDb from './db/classes/Object.js';
|
|
2
|
+
import bbnDbProxy from './db/classes/Proxy.js';
|
|
3
|
+
export { bbnDb, bbnDbProxy };
|
package/dist/db.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import bbnDb from './db/classes/Object.js';
|
|
2
|
+
import bbnDbProxy from './db/classes/Proxy.js';
|
|
3
|
+
export { bbnDb, bbnDbProxy };
|
package/dist/dt.js
CHANGED
|
@@ -9,7 +9,7 @@ import bbnDtDuration from './dt/classes/Duration.js';
|
|
|
9
9
|
import _ from './_.js';
|
|
10
10
|
import parse from './dt/functions/parse.js';
|
|
11
11
|
import guessFormat from './dt/functions/guessFormat.js';
|
|
12
|
-
import
|
|
12
|
+
import log from './fn/browser/log.js';
|
|
13
13
|
const patterns = [
|
|
14
14
|
// MariaDB DATETIME "YYYY-MM-DD HH:MM:SS"
|
|
15
15
|
{
|
|
@@ -227,13 +227,12 @@ const dt = (value, inputFormat = null, cls = 'auto') => {
|
|
|
227
227
|
return new bbnDtDuration(value);
|
|
228
228
|
}
|
|
229
229
|
else {
|
|
230
|
-
|
|
230
|
+
log('Invalid date value', value);
|
|
231
231
|
throw new Error(_('Invalid date value'));
|
|
232
232
|
}
|
|
233
233
|
//throw new Error(_('Invalid date value: %s', value));
|
|
234
234
|
};
|
|
235
235
|
dt.locales = Object.create(null);
|
|
236
|
-
buildLocaleFromIntl();
|
|
237
236
|
dt.parse = parse;
|
|
238
237
|
dt.guessFormat = guessFormat;
|
|
239
238
|
dt.time = () => { };
|
package/dist/fn/ajax/stream.js
CHANGED
|
@@ -3,6 +3,7 @@ import getLoader from './getLoader.js';
|
|
|
3
3
|
import _deleteLoader from './_deleteLoader.js';
|
|
4
4
|
import isFunction from '../type/isFunction.js';
|
|
5
5
|
import _addLoader from './_addLoader.js';
|
|
6
|
+
import log from '../browser/log.js';
|
|
6
7
|
import defaultStartLoadingFunction from '../default/defaultStartLoadingFunction.js';
|
|
7
8
|
import defaultEndLoadingFunction from '../default/defaultEndLoadingFunction.js';
|
|
8
9
|
import defaultAjaxAbortFunction from '../default/defaultAjaxAbortFunction.js';
|
|
@@ -94,7 +95,7 @@ export default function stream(url, success, data, failure, abort, finished) {
|
|
|
94
95
|
}
|
|
95
96
|
if (isFn) {
|
|
96
97
|
json += arrayBuffer2String(value).trim();
|
|
97
|
-
|
|
98
|
+
log(["STREAM RESULT", json.length, json]);
|
|
98
99
|
if (json) {
|
|
99
100
|
try {
|
|
100
101
|
treatJSON(json);
|
|
@@ -107,7 +108,7 @@ export default function stream(url, success, data, failure, abort, finished) {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
else {
|
|
110
|
-
|
|
111
|
+
log(["STREAM SUCCESS IS FN? " + isFn]);
|
|
111
112
|
}
|
|
112
113
|
// Read some more, and call this function again
|
|
113
114
|
return reader.read().then(pump);
|
package/dist/fn/browser/log.js
CHANGED
|
@@ -34,6 +34,9 @@ export default function log(...args) {
|
|
|
34
34
|
let t = typeof args[i];
|
|
35
35
|
let consoleArguments = [args[i]];
|
|
36
36
|
if (t === 'string' || t === 'number') {
|
|
37
|
+
if (!globalThis.document) {
|
|
38
|
+
consoleArguments[0] = `[SW] ${consoleArguments[0]}`;
|
|
39
|
+
}
|
|
37
40
|
consoleArguments.unshift('%c %s ', cfg);
|
|
38
41
|
}
|
|
39
42
|
exec.apply(globalThis.console, consoleArguments);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import isArray from '../type/isArray.js';
|
|
2
2
|
import compareConditions from './compareConditions.js';
|
|
3
|
+
import log from '../browser/log.js';
|
|
3
4
|
/**
|
|
4
5
|
* Returns a new array with only the data matching the given filter.
|
|
5
6
|
*
|
|
@@ -53,7 +54,7 @@ export default function _filter(arr, prop, val = null, operator = '=', limit = 0
|
|
|
53
54
|
arr = Array.from(arr);
|
|
54
55
|
}
|
|
55
56
|
catch {
|
|
56
|
-
|
|
57
|
+
log("NOT ARRAY", arr);
|
|
57
58
|
throw new Error('Error in filter: The first argument must be an array');
|
|
58
59
|
}
|
|
59
60
|
}
|
package/dist/fn/object/filter.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import isArray from '../type/isArray.js';
|
|
2
2
|
import { filterToConditions } from './filterToConditions.js';
|
|
3
3
|
import compareConditions from './compareConditions.js';
|
|
4
|
+
import log from '../browser/log.js';
|
|
4
5
|
/**
|
|
5
6
|
* Returns a new array with only the data matching the given filter.
|
|
6
7
|
*
|
|
@@ -50,7 +51,7 @@ import compareConditions from './compareConditions.js';
|
|
|
50
51
|
*/
|
|
51
52
|
export default function filter(arr, prop, val = null, operator = '=') {
|
|
52
53
|
if (!isArray(arr)) {
|
|
53
|
-
|
|
54
|
+
log("NOT ARRAY", arr);
|
|
54
55
|
throw new Error('Error in filter: The first argument must be an array');
|
|
55
56
|
}
|
|
56
57
|
let cfg = {};
|
package/dist/index-no-dep.js
CHANGED
|
@@ -4,9 +4,10 @@ import lng from './lng.js';
|
|
|
4
4
|
import data from './data.js';
|
|
5
5
|
import env from './env.js';
|
|
6
6
|
import com from './com.js';
|
|
7
|
-
import
|
|
7
|
+
import { bbnDb, bbnDbProxy } from './db.js';
|
|
8
8
|
import fn from './fn.js';
|
|
9
9
|
import dt from './dt.js';
|
|
10
|
+
import buildLocaleFromIntl from './dt/functions/buildLocaleFromIntl.js';
|
|
10
11
|
const bbn = {
|
|
11
12
|
version: "1.0.1",
|
|
12
13
|
opt: {
|
|
@@ -20,7 +21,12 @@ const bbn = {
|
|
|
20
21
|
dt,
|
|
21
22
|
com,
|
|
22
23
|
env,
|
|
23
|
-
db
|
|
24
|
+
get db() {
|
|
25
|
+
if (navigator.serviceWorker?.controller) {
|
|
26
|
+
return bbnDbProxy;
|
|
27
|
+
}
|
|
28
|
+
return bbnDb;
|
|
29
|
+
},
|
|
24
30
|
fn,
|
|
25
31
|
info: [
|
|
26
32
|
{
|
|
@@ -91,4 +97,5 @@ const bbn = {
|
|
|
91
97
|
}
|
|
92
98
|
]
|
|
93
99
|
};
|
|
100
|
+
buildLocaleFromIntl();
|
|
94
101
|
export default bbn;
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,11 @@ import lng from './lng.js';
|
|
|
5
5
|
import data from './data.js';
|
|
6
6
|
import env from './env.js';
|
|
7
7
|
import com from './com.js';
|
|
8
|
-
import
|
|
8
|
+
import { bbnDb, bbnDbProxy } from './db.js';
|
|
9
|
+
import bbnDbCenter from './db/classes/Center.js';
|
|
9
10
|
import fn from './fn.js';
|
|
10
11
|
import dt from './dt.js';
|
|
12
|
+
import buildLocaleFromIntl from './dt/functions/buildLocaleFromIntl.js';
|
|
11
13
|
const bbn = {
|
|
12
14
|
version: "1.0.1",
|
|
13
15
|
opt: {
|
|
@@ -21,7 +23,13 @@ const bbn = {
|
|
|
21
23
|
dt,
|
|
22
24
|
com,
|
|
23
25
|
env,
|
|
24
|
-
db
|
|
26
|
+
get db() {
|
|
27
|
+
if (navigator.serviceWorker?.controller) {
|
|
28
|
+
return bbnDbProxy;
|
|
29
|
+
}
|
|
30
|
+
return bbnDb;
|
|
31
|
+
},
|
|
32
|
+
dbCenter: () => new bbnDbCenter(),
|
|
25
33
|
fn,
|
|
26
34
|
info: [
|
|
27
35
|
{
|
|
@@ -98,4 +106,5 @@ if ('undefined' !== typeof globalThis) {
|
|
|
98
106
|
globalThis.Temporal = Temporal;
|
|
99
107
|
}
|
|
100
108
|
}
|
|
109
|
+
buildLocaleFromIntl();
|
|
101
110
|
export { bbn as default, bbn, Temporal };
|