@vacantthinker/firefox-addon-framework-easy 2026.603.2007 → 2026.603.2020
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/package.json +1 -1
- package/src/BaseORM.js +28 -14
package/package.json
CHANGED
package/src/BaseORM.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
stoOpCheck,
|
|
3
|
+
stoOpGet,
|
|
4
|
+
stoOpQueryStartWith,
|
|
5
|
+
stoOpRem,
|
|
6
|
+
stoOpSet,
|
|
7
|
+
} from './opStorage.js';
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* Abstract base class BaseORM (similar to Java's Abstract Class).
|
|
@@ -6,32 +12,41 @@ import {stoOpCheck, stoOpGet, stoOpRem, stoOpSet} from './opStorage.js';
|
|
|
6
12
|
*/
|
|
7
13
|
export class BaseORM {
|
|
8
14
|
// Private fields for data encapsulation
|
|
15
|
+
#id; // Added to store the raw unique identifier
|
|
9
16
|
#fullStorageKey;
|
|
10
17
|
#defaultValue;
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
20
|
* Constructor
|
|
14
21
|
* @param {string} prefix The prefix for the keys (e.g., 'magnetKey')
|
|
15
|
-
* @param {string} id The unique identifier for this instance
|
|
16
|
-
* @param {object} [defaultValue={}] Custom initial value
|
|
22
|
+
* @param {string} id The unique identifier for this instance
|
|
23
|
+
* @param {object} [defaultValue={}] Custom initial value
|
|
17
24
|
*/
|
|
18
25
|
constructor(prefix, id, defaultValue = {}) {
|
|
19
|
-
// Simulating Java's abstract class behavior: prevent direct instantiation of the base class
|
|
20
26
|
if (new.target === BaseORM) {
|
|
21
|
-
throw new TypeError(
|
|
22
|
-
'Cannot construct BaseORM instances directly (Abstract Class).');
|
|
27
|
+
throw new TypeError("Cannot construct BaseORM instances directly (Abstract Class).");
|
|
23
28
|
}
|
|
24
29
|
if (!prefix || !id) {
|
|
25
|
-
throw new Error(
|
|
30
|
+
throw new Error("Both prefix and id must be specified.");
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
//
|
|
29
|
-
this.#
|
|
33
|
+
// Save the raw id to the private field
|
|
34
|
+
this.#id = id;
|
|
30
35
|
|
|
31
|
-
|
|
36
|
+
const formattedPrefix = prefix.endsWith(' ') ? prefix : `${prefix} `;
|
|
37
|
+
this.#fullStorageKey = `${formattedPrefix}${id}`;
|
|
32
38
|
this.#defaultValue = JSON.parse(JSON.stringify(defaultValue));
|
|
33
39
|
}
|
|
34
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Public Getter to retrieve the bound unique identifier (id).
|
|
43
|
+
* Can be accessed as `this.id` inside subclasses or `instance.id` externally.
|
|
44
|
+
* @return {string} The raw id
|
|
45
|
+
*/
|
|
46
|
+
get id() {
|
|
47
|
+
return this.#id;
|
|
48
|
+
}
|
|
49
|
+
|
|
35
50
|
/**
|
|
36
51
|
* Protected Getter for subclasses to safely access the complete key.
|
|
37
52
|
* Can be used in subclasses as `this.storageKey`.
|
|
@@ -42,19 +57,18 @@ export class BaseORM {
|
|
|
42
57
|
return this.#fullStorageKey;
|
|
43
58
|
}
|
|
44
59
|
|
|
45
|
-
// Private helper method
|
|
60
|
+
// Private helper method
|
|
46
61
|
async #exists() {
|
|
47
62
|
return await stoOpCheck(this.#fullStorageKey);
|
|
48
63
|
}
|
|
49
64
|
|
|
50
|
-
// Private helper method
|
|
65
|
+
// Private helper method
|
|
51
66
|
async #initDefaultObject() {
|
|
52
67
|
await stoOpSet(this.#fullStorageKey, this.#defaultValue);
|
|
53
68
|
}
|
|
54
69
|
|
|
55
70
|
/**
|
|
56
71
|
* [Read] Retrieve the value associated with the bound key.
|
|
57
|
-
* If it does not exist yet, it automatically initializes it with the default value first.
|
|
58
72
|
* @return {Promise<object>}
|
|
59
73
|
*/
|
|
60
74
|
async get() {
|
|
@@ -74,7 +88,7 @@ export class BaseORM {
|
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
/**
|
|
77
|
-
* [Delete] Wipe the bound key from storage
|
|
91
|
+
* [Delete] Wipe the bound key from storage.
|
|
78
92
|
* @return {Promise<object>}
|
|
79
93
|
*/
|
|
80
94
|
async delete() {
|