@bbn/bbn 2.0.222 → 2.0.224

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/db.d.ts CHANGED
@@ -32,13 +32,15 @@ interface DbManager {
32
32
  _connections: Record<string, IDBDatabase>;
33
33
  _stores: Record<string, unknown>;
34
34
  ok: boolean;
35
- open(name: string): Promise<IDbApi>;
36
- add(database: string, name: string, structure: DbStructure): Promise<IDBDatabase>;
35
+ open(name: string, version?: number): Promise<IDbApi>;
36
+ add(database: string, name: string, structure: DbStructure): Promise<boolean>;
37
37
  openRaw(name: string, version?: number): Promise<IDBDatabase>;
38
38
  remove(database: string, name: string): Promise<void>;
39
39
  updateStructure(storeName: string, structure: DbStructure, database: IDBDatabase): void;
40
- reopenWithUpgrade(name: string): Promise<IDBDatabase>;
40
+ importStructure(database: string, structure: Record<string, DbStructure>): Promise<void>;
41
+ reopenWithUpgrade(name: string): Promise<IDbApi>;
41
42
  getExistingVersion(name: string): Promise<number>;
43
+ close(database: string): void;
42
44
  }
43
45
  declare const db: DbManager;
44
46
  export default db;
package/dist/db.js CHANGED
@@ -333,6 +333,13 @@ const db = {
333
333
  _connections: {},
334
334
  _stores: {},
335
335
  ok: idb !== undefined,
336
+ close(database) {
337
+ const conn = this._connections[database];
338
+ if (conn) {
339
+ conn.close();
340
+ delete this._connections[database];
341
+ }
342
+ },
336
343
  updateStructure(storeName, structure, database) {
337
344
  const primary = getPrimaryKey(structure);
338
345
  if (!database.objectStoreNames.contains(storeName)) {
@@ -346,6 +353,20 @@ const db = {
346
353
  });
347
354
  }
348
355
  },
356
+ importStructure(database, structure) {
357
+ return __awaiter(this, void 0, void 0, function* () {
358
+ if (!this._structures[database]) {
359
+ this._structures[database] = {};
360
+ }
361
+ for (const storeName in structure) {
362
+ if (!this._structures[database].hasOwnProperty(storeName)) {
363
+ this._structures[database][storeName] = structure[storeName];
364
+ }
365
+ }
366
+ yield this.reopenWithUpgrade(database);
367
+ this.close(database);
368
+ });
369
+ },
349
370
  getExistingVersion(name) {
350
371
  return __awaiter(this, void 0, void 0, function* () {
351
372
  const live = this._connections[name];
@@ -385,37 +406,12 @@ const db = {
385
406
  const nextVersion = existingVersion + 1;
386
407
  log(_('Going from version %s to version %s for database %s', existingVersion, nextVersion, name));
387
408
  if (this._connections[name]) {
388
- this._connections[name].close();
389
- delete this._connections[name];
409
+ this.close(name);
390
410
  }
391
- return new Promise((resolve, reject) => {
392
- if (!idb) {
393
- reject(new Error(_('IndexedDB is not available')));
394
- return;
395
- }
396
- const req = idb.open(name, nextVersion);
397
- req.onupgradeneeded = () => {
398
- const database = req.result;
399
- const dbStructure = this._structures[name] || {};
400
- iterate(dbStructure, (structure, storeName) => {
401
- if (!database.objectStoreNames.contains(storeName)) {
402
- this.updateStructure(storeName, structure, database);
403
- }
404
- });
405
- };
406
- req.onsuccess = () => {
407
- this._connections[name] = req.result;
408
- resolve(req.result);
409
- };
410
- req.onerror = () => reject(req.error);
411
- req.onblocked = (event) => {
412
- log(event);
413
- reject(_('reopenWithUpgrade: Upgrade blocked for database %s. Please close other connections to proceed.', name));
414
- };
415
- });
411
+ return yield this.open(name, nextVersion);
416
412
  });
417
413
  },
418
- open(database) {
414
+ open(database, version) {
419
415
  return __awaiter(this, void 0, void 0, function* () {
420
416
  if (!idb) {
421
417
  throw new Error(_('IndexedDB is not available'));
@@ -427,7 +423,7 @@ const db = {
427
423
  return new DbObject(database);
428
424
  }
429
425
  yield new Promise((resolve, reject) => {
430
- const req = idb.open(database);
426
+ const req = version ? idb.open(database, version) : idb.open(database);
431
427
  req.onupgradeneeded = () => {
432
428
  const db = req.result;
433
429
  const dbStructure = this._structures[database] || {};
@@ -452,7 +448,6 @@ const db = {
452
448
  add(database, name, structure) {
453
449
  return __awaiter(this, void 0, void 0, function* () {
454
450
  var _a;
455
- log(_('Adding database structure for %s.%s', database, name));
456
451
  if (!((_a = structure === null || structure === void 0 ? void 0 : structure.keys) === null || _a === void 0 ? void 0 : _a.PRIMARY) || !(structure === null || structure === void 0 ? void 0 : structure.fields)) {
457
452
  throw new Error(_('The database structure for %s is not valid (missing keys, fields, or primary key)', name));
458
453
  }
@@ -460,28 +455,25 @@ const db = {
460
455
  this._structures[database] = {};
461
456
  }
462
457
  this._structures[database][name] = structure;
463
- const conn = this._connections[database];
464
- if (conn) {
465
- if (!conn.objectStoreNames.contains(name)) {
466
- return yield this.reopenWithUpgrade(database);
467
- }
468
- return conn;
469
- }
470
- // No live connection: inspect current DB and upgrade if needed.
471
- const existingVersion = yield this.getExistingVersion(database);
472
- const hasDbAlready = existingVersion > 0;
473
- if (!hasDbAlready) {
458
+ const hadConn = !!this._connections[database];
459
+ let conn;
460
+ if (!hadConn) {
474
461
  yield this.open(database);
475
- return this._connections[database];
476
462
  }
463
+ conn = this._connections[database];
477
464
  // DB exists already: open temporarily and check if store exists
478
- const tmp = yield this.openRaw(database);
479
- const hasStore = tmp.objectStoreNames.contains(name);
480
- tmp.close();
465
+ const hasStore = conn.objectStoreNames.contains(name);
481
466
  if (!hasStore) {
482
- return yield this.reopenWithUpgrade(database);
467
+ const tmp = yield this.reopenWithUpgrade(database);
468
+ if (!this._connections[database]) {
469
+ throw new Error(_('The database %s is not open after upgrade', database));
470
+ }
471
+ conn = this._connections[database];
483
472
  }
484
- return yield this.openRaw(database);
473
+ if (!hadConn) {
474
+ this.close(database);
475
+ }
476
+ return true;
485
477
  });
486
478
  },
487
479
  openRaw(name, version) {
@@ -510,8 +502,7 @@ const db = {
510
502
  return;
511
503
  }
512
504
  const nextVersion = conn.version + 1;
513
- conn.close();
514
- delete this._connections[database];
505
+ this.close(database);
515
506
  yield new Promise((resolve, reject) => {
516
507
  if (!idb) {
517
508
  reject(new Error(_('IndexedDB is not available')));
@@ -522,10 +513,11 @@ const db = {
522
513
  const dbInstance = req.result;
523
514
  if (dbInstance.objectStoreNames.contains(name)) {
524
515
  dbInstance.deleteObjectStore(name);
516
+ dbInstance.close();
525
517
  }
526
518
  };
527
519
  req.onsuccess = () => {
528
- this._connections[database] = req.result;
520
+ req.result.close();
529
521
  resolve();
530
522
  };
531
523
  req.onerror = () => reject(req.error);
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtDate extends bbnDt<Temporal.PlainDate> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  import getRow from '../../fn/object/getRow.js';
4
4
  export default class bbnDtDate extends bbnDt {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtDateTime extends bbnDt<Temporal.PlainDateTime> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  import getRow from '../../fn/object/getRow.js';
4
4
  export default class bbnDtDateTime extends bbnDt {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import { bbnDtTemporal } from '../vars/types.js';
3
3
  import bbnDtDuration from './duration.js';
4
4
  export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _bbnDt_value;
13
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
13
+ import { Temporal } from 'temporal-polyfill';
14
14
  import { unitsCorrespondence, units, formatsMap } from '../vars/units.js';
15
15
  import _ from '../../_.js';
16
16
  import substr from '../../fn/string/substr.js';
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  export default class bbnDtDuration {
3
3
  #private;
4
4
  static fromUnit(value: number, unit: string): bbnDtDuration;
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _bbnDtDuration_instances, _bbnDtDuration_value, _bbnDtDuration_unit, _bbnDtDuration_getUnitValue;
13
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
13
+ import { Temporal } from 'temporal-polyfill';
14
14
  import { units, unitsCorrespondence } from '../vars/units.js';
15
15
  import getRow from '../../fn/object/getRow.js';
16
16
  const DURATION_RELATIVE_TO = Temporal.ZonedDateTime.from('1970-01-01T00:00Z[UTC]');
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtMonthDay extends bbnDt<Temporal.PlainMonthDay> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtMonthDay extends bbnDt {
4
4
  constructor(m, d) {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtTime extends bbnDt<Temporal.PlainTime> {
4
4
  readonly kind: 'time';
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtTime extends bbnDt {
4
4
  constructor(h, i, s, ms) {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtYearMonth extends bbnDt<Temporal.PlainYearMonth> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  import getRow from '../../fn/object/getRow.js';
4
4
  export default class bbnDtYearMonth extends bbnDt {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtZoned extends bbnDt<Temporal.ZonedDateTime> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import fromJsDate from '../functions/fromJsDate.js';
3
3
  import bbnDt from './dt.js';
4
4
  export default class bbnDtZoned extends bbnDt {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  /**
3
3
  * Convert a JS Date into:
4
4
  * - Temporal.Instant (if hasZone=true)
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  /**
3
3
  * Convert a JS Date into:
4
4
  * - Temporal.Instant (if hasZone=true)
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import buildLocaleFromIntl from './buildLocaleFromIntl.js';
3
3
  import bbnDtZoned from '../classes/zoned.js';
4
4
  import bbnDtDateTime from '../classes/dateTime.js';
@@ -1,2 +1,2 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  export type bbnDtTemporal = Temporal.PlainDateTime | Temporal.PlainDate | Temporal.PlainTime | Temporal.PlainYearMonth | Temporal.PlainMonthDay | Temporal.ZonedDateTime;
package/dist/dt.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDtDateTime from './dt/classes/dateTime.js';
3
3
  import bbnDtDate from './dt/classes/date.js';
4
4
  import bbnDtTime from './dt/classes/zoned.js';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Temporal } from '../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  declare const bbn: Bbn;
3
3
  export { bbn as default, bbn, Temporal };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import _ from './_.js';
3
3
  import $ from './$.js';
4
4
  import lng from './lng.js';
package/package.json CHANGED
@@ -1,13 +1,24 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.222",
3
+ "version": "2.0.224",
4
4
  "description": "Javascript toolkit",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "type": "module",
7
9
  "files": [
8
- "/dist"
10
+ "dist"
9
11
  ],
10
- "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "./sw": {
19
+ "default": "./dist/bbn.sw.js"
20
+ }
21
+ },
11
22
  "scripts": {
12
23
  "type": "./node_modules/.bin/tsc",
13
24
  "gitauto": "git stage ./src/* ./*.ts ./*.json ./*.config.js ./test/*.mjs && git stage -f ./dist/* && git commit -m \"Latest changes\"",
@@ -24,7 +35,6 @@
24
35
  "author": "Thomas Nabet <thomas.nabet@gmail.com>",
25
36
  "license": "MIT",
26
37
  "devDependencies": {
27
- "@rollup/plugin-commonjs": "^29.0.0",
28
38
  "@rollup/plugin-json": "^6.1.0",
29
39
  "@rollup/plugin-node-resolve": "^16.0.3",
30
40
  "@rollup/plugin-replace": "^6.0.3",
@@ -32,7 +42,6 @@
32
42
  "@rollup/plugin-typescript": "^12.3.0",
33
43
  "@types/mocha": "^10.0.10",
34
44
  "chai": "^6.2.1",
35
- "dayjs": "^1.11.19",
36
45
  "jsdom": "^27.2.0",
37
46
  "jsdom-global": "^3.0.2",
38
47
  "mocha": "^11.7.5",
@@ -40,9 +49,7 @@
40
49
  "ts-loader": "^9.5.4",
41
50
  "tslib": "^2.8.1",
42
51
  "tsx": "^4.21.0",
43
- "typescript": "^5.9.3",
44
- "webpack": "^5.102.1",
45
- "webpack-cli": "^6.0.1"
52
+ "typescript": "^5.9.3"
46
53
  },
47
54
  "bugs": {
48
55
  "url": "https://github.com/nabab/bbn-js/issues"