@vacantthinker/firefox-addon-framework-easy 2026.625.1200 → 2026.625.1620
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/BaseArrayORM.d.ts +37 -0
- package/dist/BaseArrayORM.d.ts.map +1 -0
- package/dist/BaseArrayORM.js +84 -0
- package/dist/BaseNumberKeyORM.d.ts +6 -5
- package/dist/BaseNumberKeyORM.d.ts.map +1 -1
- package/dist/BaseNumberKeyORM.js +14 -8
- package/dist/{BaseORM.d.ts → BaseObjectORM.d.ts} +8 -6
- package/dist/BaseObjectORM.d.ts.map +1 -0
- package/dist/{BaseORM.js → BaseObjectORM.js} +18 -13
- package/dist/BaseOneBooleanORM.d.ts +28 -8
- package/dist/BaseOneBooleanORM.d.ts.map +1 -1
- package/dist/BaseOneBooleanORM.js +48 -18
- package/dist/BaseStringKeyORM.d.ts +4 -4
- package/dist/BaseStringKeyORM.d.ts.map +1 -1
- package/dist/BaseStringKeyORM.js +4 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/dist/BaseORM.d.ts.map +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseObjectORM } from './BaseObjectORM';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract class for ORMs that store an Array of items (T[]).
|
|
4
|
+
* Includes atomic mutation methods to prevent race conditions.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseArrayORM<T> extends BaseObjectORM<T[]> {
|
|
7
|
+
private mutationQueue;
|
|
8
|
+
protected constructor(prefix: string, id: string);
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the current array. Returns a copy to prevent accidental
|
|
11
|
+
* by-reference mutations outside the ORM.
|
|
12
|
+
*/
|
|
13
|
+
getArray(): Promise<T[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Safely appends a new item to the array without race conditions.
|
|
16
|
+
*/
|
|
17
|
+
push(item: T): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Safely appends multiple items.
|
|
20
|
+
*/
|
|
21
|
+
pushMany(items: T[]): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Removes items that match the provided predicate function.
|
|
24
|
+
* @returns {Promise<number>} The number of items removed.
|
|
25
|
+
*/
|
|
26
|
+
remove(predicate: (item: T) => boolean): Promise<number>;
|
|
27
|
+
/**
|
|
28
|
+
* Completely clears the array.
|
|
29
|
+
*/
|
|
30
|
+
clearArray(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Internal mechanism to queue array mutations sequentially.
|
|
33
|
+
* Guarantees that concurrent pushes do not result in lost updates.
|
|
34
|
+
*/
|
|
35
|
+
private mutateArray;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=BaseArrayORM.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseArrayORM.d.ts","sourceRoot":"","sources":["../src/BaseArrayORM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,8BAAsB,YAAY,CAAC,CAAC,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,CAAC;IAG9D,OAAO,CAAC,aAAa,CAAoC;IAEzD,SAAS,aAAa,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAMhD;;;OAGG;IACU,QAAQ,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC;IAKrC;;OAEG;IACU,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzC;;OAEG;IACU,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhD;;;OAGG;IACU,MAAM,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAWrE;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC;;;OAGG;YACW,WAAW;CAuB1B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { BaseObjectORM } from './BaseObjectORM';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract class for ORMs that store an Array of items (T[]).
|
|
4
|
+
* Includes atomic mutation methods to prevent race conditions.
|
|
5
|
+
*/
|
|
6
|
+
export class BaseArrayORM extends BaseObjectORM {
|
|
7
|
+
// A promise queue acting as a Mutex to serialize array mutations
|
|
8
|
+
mutationQueue = Promise.resolve();
|
|
9
|
+
constructor(prefix, id) {
|
|
10
|
+
// Correctly initialize with an empty array.
|
|
11
|
+
// BaseObjectORM accepts 'any[]' so this is type-safe.
|
|
12
|
+
super(prefix, id, []);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the current array. Returns a copy to prevent accidental
|
|
16
|
+
* by-reference mutations outside the ORM.
|
|
17
|
+
*/
|
|
18
|
+
async getArray() {
|
|
19
|
+
const data = await this.get();
|
|
20
|
+
return Array.isArray(data) ? [...data] : [];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Safely appends a new item to the array without race conditions.
|
|
24
|
+
*/
|
|
25
|
+
async push(item) {
|
|
26
|
+
return this.mutateArray(async (currentArray) => {
|
|
27
|
+
currentArray.push(item);
|
|
28
|
+
return currentArray;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Safely appends multiple items.
|
|
33
|
+
*/
|
|
34
|
+
async pushMany(items) {
|
|
35
|
+
return this.mutateArray(async (currentArray) => {
|
|
36
|
+
return currentArray.concat(items);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Removes items that match the provided predicate function.
|
|
41
|
+
* @returns {Promise<number>} The number of items removed.
|
|
42
|
+
*/
|
|
43
|
+
async remove(predicate) {
|
|
44
|
+
let removedCount = 0;
|
|
45
|
+
await this.mutateArray(async (currentArray) => {
|
|
46
|
+
const initialLength = currentArray.length;
|
|
47
|
+
const filtered = currentArray.filter((item) => !predicate(item));
|
|
48
|
+
removedCount = initialLength - filtered.length;
|
|
49
|
+
return filtered;
|
|
50
|
+
});
|
|
51
|
+
return removedCount;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Completely clears the array.
|
|
55
|
+
*/
|
|
56
|
+
async clearArray() {
|
|
57
|
+
await this.set([]);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Internal mechanism to queue array mutations sequentially.
|
|
61
|
+
* Guarantees that concurrent pushes do not result in lost updates.
|
|
62
|
+
*/
|
|
63
|
+
async mutateArray(mutator) {
|
|
64
|
+
this.mutationQueue = this.mutationQueue.then(async () => {
|
|
65
|
+
try {
|
|
66
|
+
let currentData = await this.get();
|
|
67
|
+
// Data integrity fallback
|
|
68
|
+
if (!Array.isArray(currentData)) {
|
|
69
|
+
console.warn(`BaseArrayORM: Invalid data type for ${this.storageKey}. Resetting to Array.`);
|
|
70
|
+
currentData = [];
|
|
71
|
+
}
|
|
72
|
+
const updatedArray = await mutator(currentData);
|
|
73
|
+
await this.set(updatedArray);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error(`BaseArrayORM: Failed to mutate array for ${this.storageKey}`, error);
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}).catch(() => {
|
|
80
|
+
// Prevents queue deadlocks on individual transaction failures
|
|
81
|
+
});
|
|
82
|
+
return this.mutationQueue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseObjectORM } from './BaseObjectORM';
|
|
2
2
|
/**
|
|
3
3
|
* Abstract class for ORMs that store Map<number, V> data.
|
|
4
|
-
* Automatically handles the conversion between internal
|
|
5
|
-
* Map<number, V>.
|
|
4
|
+
* Automatically handles the conversion between internal
|
|
5
|
+
* Record<number, V> and Map<number, V>.
|
|
6
6
|
*/
|
|
7
|
-
export declare abstract class BaseNumberKeyORM<V> extends
|
|
7
|
+
export declare abstract class BaseNumberKeyORM<V> extends BaseObjectORM<Record<number, V>> {
|
|
8
8
|
protected constructor(prefix: string, id: string);
|
|
9
9
|
/**
|
|
10
10
|
* Fetches data as Record, handles legacy arrays/corruption,
|
|
11
|
-
* and converts it to Map<number, V> with properly cast number
|
|
11
|
+
* and converts it to Map<number, V> with properly cast number
|
|
12
|
+
* keys.
|
|
12
13
|
*/
|
|
13
14
|
protected getMap(): Promise<Map<number, V>>;
|
|
14
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseNumberKeyORM.d.ts","sourceRoot":"","sources":["../src/BaseNumberKeyORM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"BaseNumberKeyORM.d.ts","sourceRoot":"","sources":["../src/BaseNumberKeyORM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;;;GAIG;AACH,8BAAsB,gBAAgB,CAAC,CAAC,CAAE,SAAQ,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAChF,SAAS,aAAa,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAKhD;;;;OAIG;cACa,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAwBjD;;OAEG;cACa,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAG3D"}
|
package/dist/BaseNumberKeyORM.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseObjectORM } from './BaseObjectORM';
|
|
2
2
|
/**
|
|
3
3
|
* Abstract class for ORMs that store Map<number, V> data.
|
|
4
|
-
* Automatically handles the conversion between internal
|
|
5
|
-
* Map<number, V>.
|
|
4
|
+
* Automatically handles the conversion between internal
|
|
5
|
+
* Record<number, V> and Map<number, V>.
|
|
6
6
|
*/
|
|
7
|
-
export class BaseNumberKeyORM extends
|
|
7
|
+
export class BaseNumberKeyORM extends BaseObjectORM {
|
|
8
8
|
constructor(prefix, id) {
|
|
9
9
|
// Hardcode the default value to an empty object
|
|
10
10
|
super(prefix, id, {});
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Fetches data as Record, handles legacy arrays/corruption,
|
|
14
|
-
* and converts it to Map<number, V> with properly cast number
|
|
14
|
+
* and converts it to Map<number, V> with properly cast number
|
|
15
|
+
* keys.
|
|
15
16
|
*/
|
|
16
17
|
async getMap() {
|
|
17
18
|
let data = await this.get();
|
|
18
|
-
// Data Migration / Corruption Guard (carried over from your
|
|
19
|
+
// Data Migration / Corruption Guard (carried over from your
|
|
20
|
+
// original logic)
|
|
19
21
|
if (Array.isArray(data)) {
|
|
20
22
|
console.warn(`BaseNumberKeyORM: Old Array data detected for ${this.storageKey}. Migrating to Record.`);
|
|
21
23
|
data = Object.fromEntries(data);
|
|
@@ -25,8 +27,12 @@ export class BaseNumberKeyORM extends BaseORM {
|
|
|
25
27
|
data = {};
|
|
26
28
|
await this.set(data);
|
|
27
29
|
}
|
|
28
|
-
// Convert object entries back to Map, casting string keys to
|
|
29
|
-
|
|
30
|
+
// Convert object entries back to Map, casting string keys to
|
|
31
|
+
// numbers
|
|
32
|
+
return new Map(Object.entries(data).map(([key, value]) => [
|
|
33
|
+
Number(key),
|
|
34
|
+
value
|
|
35
|
+
]));
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* Converts internal Map<number, V> back to Record for storage.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Abstract base class BaseORM.
|
|
3
|
-
* Provides encapsulated CRUD operations for JSON-serializable
|
|
4
|
-
* Uses Generics (T) to ensure type safety for
|
|
3
|
+
* Provides encapsulated CRUD operations for JSON-serializable
|
|
4
|
+
* Key-Value pairs. Uses Generics (T) to ensure type safety for
|
|
5
|
+
* the stored object structure.
|
|
5
6
|
*/
|
|
6
|
-
export declare abstract class
|
|
7
|
+
export declare abstract class BaseObjectORM<T extends Record<string, any> | any[]> {
|
|
7
8
|
protected readonly id: string;
|
|
8
9
|
protected readonly storageKey: string;
|
|
9
10
|
private readonly defaultValue;
|
|
@@ -26,11 +27,12 @@ export declare abstract class BaseORM<T extends Record<string, any> | any[]> {
|
|
|
26
27
|
*/
|
|
27
28
|
protected delete(): Promise<T>;
|
|
28
29
|
/**
|
|
29
|
-
* Safely initialize the default object. Prevents multiple
|
|
30
|
-
* requests from writing the default value
|
|
30
|
+
* Safely initialize the default object. Prevents multiple
|
|
31
|
+
* concurrent requests from writing the default value
|
|
32
|
+
* simultaneously.
|
|
31
33
|
*/
|
|
32
34
|
private safeInit;
|
|
33
35
|
private exists;
|
|
34
36
|
private initDefaultObject;
|
|
35
37
|
}
|
|
36
|
-
//# sourceMappingURL=
|
|
38
|
+
//# sourceMappingURL=BaseObjectORM.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseObjectORM.d.ts","sourceRoot":"","sources":["../src/BaseObjectORM.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AAGH,8BAAsB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE;IACvE,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAI;IAIjC,OAAO,CAAC,WAAW,CAA8B;IAEjD,SAAS,aACP,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,YAAY,GAAE,CAAsB;IAmBtC;;;OAGG;cACa,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC;IASjC;;;;OAIG;cACa,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAO5C;;;OAGG;cACa,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC;IAMpC;;;;OAIG;YACW,QAAQ;YAiBR,MAAM;YAIN,iBAAiB;CAMhC"}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { stoOpCheck, stoOpGet, stoOpRem, stoOpSet } from './opStorage';
|
|
2
2
|
/**
|
|
3
3
|
* Abstract base class BaseORM.
|
|
4
|
-
* Provides encapsulated CRUD operations for JSON-serializable
|
|
5
|
-
* Uses Generics (T) to ensure type safety for
|
|
4
|
+
* Provides encapsulated CRUD operations for JSON-serializable
|
|
5
|
+
* Key-Value pairs. Uses Generics (T) to ensure type safety for
|
|
6
|
+
* the stored object structure.
|
|
6
7
|
*/
|
|
7
|
-
// FIX: Expand constraint to 'any[]' so TabMessageStorageData (an
|
|
8
|
-
// tuples) is permitted.
|
|
9
|
-
export class
|
|
8
|
+
// FIX: Expand constraint to 'any[]' so TabMessageStorageData (an
|
|
9
|
+
// array of tuples) is permitted.
|
|
10
|
+
export class BaseObjectORM {
|
|
10
11
|
id;
|
|
11
12
|
storageKey;
|
|
12
13
|
defaultValue;
|
|
13
|
-
// The Mutex "Lock" for preventing race conditions during
|
|
14
|
+
// The Mutex "Lock" for preventing race conditions during
|
|
15
|
+
// initialization
|
|
14
16
|
initPromise = null;
|
|
15
17
|
constructor(prefix, id, defaultValue = {}) {
|
|
16
|
-
if (new.target ===
|
|
17
|
-
throw new TypeError('Cannot construct
|
|
18
|
+
if (new.target === BaseObjectORM) {
|
|
19
|
+
throw new TypeError('Cannot construct BaseObjectORM' +
|
|
20
|
+
' instances directly (Abstract Class).');
|
|
18
21
|
}
|
|
19
22
|
if (!prefix || !id) {
|
|
20
23
|
throw new Error('Both prefix and id must be specified.');
|
|
@@ -32,8 +35,8 @@ export class BaseORM {
|
|
|
32
35
|
*/
|
|
33
36
|
async get() {
|
|
34
37
|
if (!(await this.exists())) {
|
|
35
|
-
// Calls the lock-protected initialization instead of
|
|
36
|
-
// directly
|
|
38
|
+
// Calls the lock-protected initialization instead of
|
|
39
|
+
// initDefaultObject directly
|
|
37
40
|
await this.safeInit();
|
|
38
41
|
}
|
|
39
42
|
return (await stoOpGet(this.storageKey));
|
|
@@ -56,8 +59,9 @@ export class BaseORM {
|
|
|
56
59
|
return previousValue;
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
|
-
* Safely initialize the default object. Prevents multiple
|
|
60
|
-
* requests from writing the default value
|
|
62
|
+
* Safely initialize the default object. Prevents multiple
|
|
63
|
+
* concurrent requests from writing the default value
|
|
64
|
+
* simultaneously.
|
|
61
65
|
*/
|
|
62
66
|
async safeInit() {
|
|
63
67
|
// If an initialization is already in progress, wait for it
|
|
@@ -67,7 +71,8 @@ export class BaseORM {
|
|
|
67
71
|
// Start initialization and store the Promise as the lock
|
|
68
72
|
this.initPromise = this.initDefaultObject()
|
|
69
73
|
.finally(() => {
|
|
70
|
-
// Clear the lock whether the initialization succeeds or
|
|
74
|
+
// Clear the lock whether the initialization succeeds or
|
|
75
|
+
// fails
|
|
71
76
|
this.initPromise = null;
|
|
72
77
|
});
|
|
73
78
|
return this.initPromise;
|
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseObjectORM } from './BaseObjectORM';
|
|
2
|
+
interface BooleanState {
|
|
3
|
+
state: boolean;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
|
-
* Abstract class for ORMs that store
|
|
4
|
-
*
|
|
5
|
-
* Record<string, V> and Map<string, V>.
|
|
6
|
+
* Abstract class for ORMs that store a single boolean state.
|
|
7
|
+
* Optimized to remove Map overhead and prevent race conditions.
|
|
6
8
|
*/
|
|
7
|
-
export declare abstract class BaseOneBooleanORM extends
|
|
8
|
-
private readonly
|
|
9
|
+
export declare abstract class BaseOneBooleanORM extends BaseObjectORM<BooleanState> {
|
|
10
|
+
private readonly stateKey;
|
|
11
|
+
private writeLock;
|
|
9
12
|
protected constructor(prefix: string, id: string);
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the current boolean value.
|
|
15
|
+
*/
|
|
10
16
|
getValue(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Direct overwrite of the boolean value.
|
|
19
|
+
* Queued to prevent overwriting a concurrent toggle/update
|
|
20
|
+
* operation.
|
|
21
|
+
*/
|
|
11
22
|
setValue(value: boolean): Promise<void>;
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Safely toggles or updates the value based on the previous
|
|
25
|
+
* state. This guarantees no race conditions during
|
|
26
|
+
* Read-Modify-Write cycles.
|
|
27
|
+
*/
|
|
28
|
+
protected updateValue(updater: (prevValue: boolean) => boolean): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Internal mechanism to queue state changes sequentially.
|
|
31
|
+
*/
|
|
32
|
+
private atomicUpdate;
|
|
14
33
|
}
|
|
34
|
+
export {};
|
|
15
35
|
//# sourceMappingURL=BaseOneBooleanORM.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseOneBooleanORM.d.ts","sourceRoot":"","sources":["../src/BaseOneBooleanORM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"BaseOneBooleanORM.d.ts","sourceRoot":"","sources":["../src/BaseOneBooleanORM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAG9C,UAAU,YAAY;IACpB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,8BAAsB,iBAAkB,SAAQ,aAAa,CAAC,YAAY,CAAC;IACzE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IAIpC,OAAO,CAAC,SAAS,CAAoC;IAErD,SAAS,aAAa,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAKhD;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAKzC;;;;OAIG;IACU,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD;;;;OAIG;cACa,WAAW,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpF;;OAEG;YACW,YAAY;CAoB3B"}
|
|
@@ -1,29 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseObjectORM } from './BaseObjectORM';
|
|
2
2
|
/**
|
|
3
|
-
* Abstract class for ORMs that store
|
|
4
|
-
*
|
|
5
|
-
* Record<string, V> and Map<string, V>.
|
|
3
|
+
* Abstract class for ORMs that store a single boolean state.
|
|
4
|
+
* Optimized to remove Map overhead and prevent race conditions.
|
|
6
5
|
*/
|
|
7
|
-
export class BaseOneBooleanORM extends
|
|
8
|
-
|
|
6
|
+
export class BaseOneBooleanORM extends BaseObjectORM {
|
|
7
|
+
stateKey = 'state';
|
|
8
|
+
// A promise queue acting as a Mutex to serialize write
|
|
9
|
+
// operations
|
|
10
|
+
writeLock = Promise.resolve();
|
|
9
11
|
constructor(prefix, id) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
// Pass the default state directly to the parent
|
|
13
|
+
super(prefix, id, { state: false });
|
|
12
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the current boolean value.
|
|
17
|
+
*/
|
|
13
18
|
async getValue() {
|
|
14
|
-
const
|
|
15
|
-
return
|
|
19
|
+
const data = await this.get();
|
|
20
|
+
return data?.[this.stateKey] ?? false;
|
|
16
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Direct overwrite of the boolean value.
|
|
24
|
+
* Queued to prevent overwriting a concurrent toggle/update
|
|
25
|
+
* operation.
|
|
26
|
+
*/
|
|
17
27
|
async setValue(value) {
|
|
18
|
-
|
|
19
|
-
map.set(this.state, value);
|
|
20
|
-
await this.setMap(map);
|
|
28
|
+
return this.atomicUpdate(() => value);
|
|
21
29
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Safely toggles or updates the value based on the previous
|
|
32
|
+
* state. This guarantees no race conditions during
|
|
33
|
+
* Read-Modify-Write cycles.
|
|
34
|
+
*/
|
|
35
|
+
async updateValue(updater) {
|
|
36
|
+
return this.atomicUpdate(updater);
|
|
25
37
|
}
|
|
26
|
-
|
|
27
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Internal mechanism to queue state changes sequentially.
|
|
40
|
+
*/
|
|
41
|
+
async atomicUpdate(updater) {
|
|
42
|
+
this.writeLock = this.writeLock.then(async () => {
|
|
43
|
+
try {
|
|
44
|
+
const currentData = await this.get();
|
|
45
|
+
const currentValue = currentData?.[this.stateKey] ?? false;
|
|
46
|
+
const newValue = updater(currentValue);
|
|
47
|
+
await this.set({ [this.stateKey]: newValue });
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error(`BaseOneBooleanORM: Failed to update state for ${this.storageKey}`, error);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}).catch(() => {
|
|
54
|
+
// Catch prevents a single failure from permanently
|
|
55
|
+
// breaking the queue chain
|
|
56
|
+
});
|
|
57
|
+
return this.writeLock;
|
|
28
58
|
}
|
|
29
59
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseObjectORM } from './BaseObjectORM';
|
|
2
2
|
/**
|
|
3
3
|
* Abstract class for ORMs that store Map<string, V> data.
|
|
4
|
-
* Automatically handles the conversion between internal
|
|
5
|
-
* Map<string, V>.
|
|
4
|
+
* Automatically handles the conversion between internal
|
|
5
|
+
* Record<string, V> and Map<string, V>.
|
|
6
6
|
*/
|
|
7
|
-
export declare abstract class BaseStringKeyORM<V> extends
|
|
7
|
+
export declare abstract class BaseStringKeyORM<V> extends BaseObjectORM<Record<string, V>> {
|
|
8
8
|
protected constructor(prefix: string, id: string);
|
|
9
9
|
/**
|
|
10
10
|
* Fetches data as Record and converts it to Map<string, V>.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseStringKeyORM.d.ts","sourceRoot":"","sources":["../src/BaseStringKeyORM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"BaseStringKeyORM.d.ts","sourceRoot":"","sources":["../src/BaseStringKeyORM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;;;GAIG;AACH,8BAAsB,gBAAgB,CAAC,CAAC,CAAE,SAAQ,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAChF,SAAS,aAAa,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAKhD;;OAEG;cACa,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAOjD;;OAEG;cACa,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAG3D"}
|
package/dist/BaseStringKeyORM.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseObjectORM } from './BaseObjectORM';
|
|
2
2
|
/**
|
|
3
3
|
* Abstract class for ORMs that store Map<string, V> data.
|
|
4
|
-
* Automatically handles the conversion between internal
|
|
5
|
-
* Map<string, V>.
|
|
4
|
+
* Automatically handles the conversion between internal
|
|
5
|
+
* Record<string, V> and Map<string, V>.
|
|
6
6
|
*/
|
|
7
|
-
export class BaseStringKeyORM extends
|
|
7
|
+
export class BaseStringKeyORM extends BaseObjectORM {
|
|
8
8
|
constructor(prefix, id) {
|
|
9
9
|
// Hardcode the default value to an empty object
|
|
10
10
|
super(prefix, id, {});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from './backgroundJs';
|
|
2
|
+
export * from './BaseArrayORM';
|
|
2
3
|
export * from './BaseNumberKeyORM';
|
|
4
|
+
export * from './BaseObjectORM';
|
|
3
5
|
export * from './BaseOneBooleanORM';
|
|
4
|
-
export * from './BaseORM';
|
|
5
6
|
export * from './BaseStringKeyORM';
|
|
6
7
|
export * from './browserBrowsingData';
|
|
7
8
|
export * from './browserDownload';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from './backgroundJs';
|
|
2
|
+
export * from './BaseArrayORM';
|
|
2
3
|
export * from './BaseNumberKeyORM';
|
|
4
|
+
export * from './BaseObjectORM';
|
|
3
5
|
export * from './BaseOneBooleanORM';
|
|
4
|
-
export * from './BaseORM';
|
|
5
6
|
export * from './BaseStringKeyORM';
|
|
6
7
|
export * from './browserBrowsingData';
|
|
7
8
|
export * from './browserDownload';
|
package/package.json
CHANGED
package/dist/BaseORM.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseORM.d.ts","sourceRoot":"","sources":["../src/BaseORM.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AAGH,8BAAsB,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE;IACjE,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAI;IAGjC,OAAO,CAAC,WAAW,CAA8B;IAEjD,SAAS,aACP,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,YAAY,GAAE,CAAsB;IAkBtC;;;OAGG;cACa,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC;IASjC;;;;OAIG;cACa,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAO5C;;;OAGG;cACa,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC;IAMpC;;;OAGG;YACW,QAAQ;YAgBR,MAAM;YAIN,iBAAiB;CAMhC"}
|