@arcote.tech/arc-adapter-db-sqlite 0.4.6 → 0.4.9

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 (2) hide show
  1. package/dist/index.js +67 -52
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1357,14 +1357,23 @@ var TOKEN_PREFIX = "arc:token:";
1357
1357
  function hasLocalStorage() {
1358
1358
  return typeof localStorage !== "undefined";
1359
1359
  }
1360
+ function notifyTokenChange(scope) {
1361
+ if (typeof window !== "undefined") {
1362
+ queueMicrotask(() => {
1363
+ window.dispatchEvent(new CustomEvent("arc:token-change", { detail: { scope } }));
1364
+ });
1365
+ }
1366
+ }
1360
1367
 
1361
1368
  class AuthAdapter {
1362
1369
  scopes = new Map;
1363
1370
  setToken(token, scope = "default") {
1364
1371
  if (!token) {
1365
1372
  this.scopes.delete(scope);
1366
- if (hasLocalStorage())
1373
+ if (hasLocalStorage()) {
1367
1374
  localStorage.removeItem(TOKEN_PREFIX + scope);
1375
+ notifyTokenChange(scope);
1376
+ }
1368
1377
  return;
1369
1378
  }
1370
1379
  try {
@@ -1385,8 +1394,10 @@ class AuthAdapter {
1385
1394
  exp: payload.exp
1386
1395
  }
1387
1396
  });
1388
- if (hasLocalStorage())
1397
+ if (hasLocalStorage()) {
1389
1398
  localStorage.setItem(TOKEN_PREFIX + scope, token);
1399
+ notifyTokenChange(scope);
1400
+ }
1390
1401
  } catch {
1391
1402
  this.scopes.delete(scope);
1392
1403
  if (hasLocalStorage())
@@ -2442,38 +2453,6 @@ class ArcPrimitive extends ArcAbstract {
2442
2453
  return value;
2443
2454
  }
2444
2455
  }
2445
-
2446
- class ArcBoolean extends ArcPrimitive {
2447
- hasToBeTrue() {
2448
- return this.validation("hasToBeTrue", (value) => {
2449
- if (!value)
2450
- return {
2451
- current: value
2452
- };
2453
- });
2454
- }
2455
- validation(name, validator) {
2456
- const instance = this.pipeValidation(name, validator);
2457
- return instance;
2458
- }
2459
- toJsonSchema() {
2460
- const schema = { type: "boolean" };
2461
- if (this._description) {
2462
- schema.description = this._description;
2463
- }
2464
- return schema;
2465
- }
2466
- getColumnData() {
2467
- const storeData = this.getStoreData();
2468
- return {
2469
- type: "boolean",
2470
- storeData: {
2471
- ...storeData,
2472
- isNullable: false
2473
- }
2474
- };
2475
- }
2476
- }
2477
2456
  var stringValidator = typeValidatorBuilder("string");
2478
2457
 
2479
2458
  class ArcString extends ArcPrimitive {
@@ -2625,6 +2604,60 @@ class ArcString extends ArcPrimitive {
2625
2604
  function string() {
2626
2605
  return new ArcString;
2627
2606
  }
2607
+
2608
+ class ArcFragmentBase {
2609
+ is(type) {
2610
+ return this.types.includes(type);
2611
+ }
2612
+ }
2613
+
2614
+ class ArcContextElement extends ArcFragmentBase {
2615
+ name;
2616
+ types = ["context-element"];
2617
+ get id() {
2618
+ return this.name;
2619
+ }
2620
+ constructor(name) {
2621
+ super();
2622
+ this.name = name;
2623
+ }
2624
+ _seeds;
2625
+ getSeeds() {
2626
+ return this._seeds;
2627
+ }
2628
+ }
2629
+
2630
+ class ArcBoolean extends ArcPrimitive {
2631
+ hasToBeTrue() {
2632
+ return this.validation("hasToBeTrue", (value) => {
2633
+ if (!value)
2634
+ return {
2635
+ current: value
2636
+ };
2637
+ });
2638
+ }
2639
+ validation(name, validator) {
2640
+ const instance = this.pipeValidation(name, validator);
2641
+ return instance;
2642
+ }
2643
+ toJsonSchema() {
2644
+ const schema = { type: "boolean" };
2645
+ if (this._description) {
2646
+ schema.description = this._description;
2647
+ }
2648
+ return schema;
2649
+ }
2650
+ getColumnData() {
2651
+ const storeData = this.getStoreData();
2652
+ return {
2653
+ type: "boolean",
2654
+ storeData: {
2655
+ ...storeData,
2656
+ isNullable: false
2657
+ }
2658
+ };
2659
+ }
2660
+ }
2628
2661
  class ArcId extends ArcBranded {
2629
2662
  generateFn;
2630
2663
  constructor(name, generateFn) {
@@ -2694,24 +2727,6 @@ class ArcNumber extends ArcPrimitive {
2694
2727
  };
2695
2728
  }
2696
2729
  }
2697
- class ArcFragmentBase {
2698
- is(type) {
2699
- return this.types.includes(type);
2700
- }
2701
- }
2702
-
2703
- class ArcContextElement extends ArcFragmentBase {
2704
- name;
2705
- types = ["context-element"];
2706
- get id() {
2707
- return this.name;
2708
- }
2709
- constructor(name) {
2710
- super();
2711
- this.name = name;
2712
- }
2713
- }
2714
-
2715
2730
  class ArcEvent extends ArcContextElement {
2716
2731
  data;
2717
2732
  eventId = id("event");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-adapter-db-sqlite",
3
- "version": "0.4.6",
3
+ "version": "0.4.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "test": "bun test"
21
21
  },
22
22
  "peerDependencies": {
23
- "@arcote.tech/arc": "^0.4.6"
23
+ "@arcote.tech/arc": "^0.4.9"
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "^5.0.0"