@vacantthinker/firefox-addon-framework-easy 2026.603.1511 → 2026.603.1932

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/README.md CHANGED
@@ -17,7 +17,7 @@ You can download, clone, or view the complete source code for this application h
17
17
 
18
18
  Below is a list of all public functions found inside the `src` directory:
19
19
 
20
- ### 📄 File: `src/baseORM.js`
20
+ ### 📄 File: `src/BaseORM.js`
21
21
  ```javascript
22
22
  export class BaseORM { }
23
23
 
@@ -69,6 +69,12 @@ export function browserTabWaitReloadThenRemoveIt({ }
69
69
 
70
70
  ```
71
71
 
72
+ ### 📄 File: `src/DomainORM.js`
73
+ ```javascript
74
+ export class DomainORM extends BaseORM { }
75
+
76
+ ```
77
+
72
78
  ### 📄 File: `src/generate.js`
73
79
  ```javascript
74
80
  export function generateHtmlByUserSettings(
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
- export * from './src/baseORM.js'
1
+ export * from './src/BaseORM.js'
2
2
  export * from './src/browserDownload.js'
3
3
  export * from './src/browserNotification.js'
4
4
  export * from './src/browserRuntime.js'
5
5
  export * from './src/browserTab.js'
6
+ export * from './src/DomainORM.js'
6
7
  export * from './src/generate.js'
7
8
  export * from './src/opStorage.js'
8
9
  export * from './src/opTab.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vacantthinker/firefox-addon-framework-easy",
3
- "version": "2026.0603.1511",
3
+ "version": "2026.0603.1932",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
package/src/BaseORM.js ADDED
@@ -0,0 +1,101 @@
1
+ import {stoOpCheck, stoOpGet, stoOpRem, stoOpSet} from './opStorage.js';
2
+
3
+ /**
4
+ * Abstract base class BaseORM (similar to Java's Abstract Class).
5
+ * Provides encapsulated CRUD operations for specific Key-Value pairs bound at instantiation.
6
+ */
7
+ export class BaseORM {
8
+ // Private fields for data encapsulation
9
+ #fullStorageKey;
10
+ #defaultValue;
11
+
12
+ /**
13
+ * Constructor
14
+ * @param {string} prefix The prefix for the keys (e.g., 'magnetKey')
15
+ * @param {string} id The unique identifier for this instance (e.g., a specific hash or filename)
16
+ * @param {object} [defaultValue={}] Custom initial value for the instance, defaults to an empty object
17
+ */
18
+ constructor(prefix, id, defaultValue = {}) {
19
+ // Simulating Java's abstract class behavior: prevent direct instantiation of the base class
20
+ if (new.target === BaseORM) {
21
+ throw new TypeError(
22
+ 'Cannot construct BaseORM instances directly (Abstract Class).');
23
+ }
24
+ if (!prefix || !id) {
25
+ throw new Error('Both prefix and id must be specified.');
26
+ }
27
+
28
+ // Automatically normalize the prefix format to ensure a clean trailing space
29
+ const formattedPrefix = prefix.endsWith(' ') ? prefix : `${prefix} `;
30
+
31
+ // Lock down the final storage key during instance construction
32
+ this.#fullStorageKey = `${formattedPrefix}${id}`;
33
+
34
+ // Deep clone the default value to protect against object reference shared-state bugs
35
+ this.#defaultValue = JSON.parse(JSON.stringify(defaultValue));
36
+ }
37
+
38
+ /**
39
+ * Protected Getter for subclasses to safely access the complete key.
40
+ * Can be used in subclasses as `this.storageKey`.
41
+ * @protected
42
+ * @return {string} The full storage key
43
+ */
44
+ get storageKey() {
45
+ return this.#fullStorageKey;
46
+ }
47
+
48
+ // Private helper method: checks if the bound key exists in the storage layer
49
+ async #exists() {
50
+ return await stoOpCheck(this.#fullStorageKey);
51
+ }
52
+
53
+ // Private helper method: populates the storage key with the designated initial layout
54
+ async #initDefaultObject() {
55
+ await stoOpSet(this.#fullStorageKey, this.#defaultValue);
56
+ }
57
+
58
+ /**
59
+ * [Read] Retrieve the value associated with the bound key.
60
+ * If it does not exist yet, it automatically initializes it with the default value first.
61
+ * @return {Promise<object>}
62
+ */
63
+ async get() {
64
+ if (!(await this.#exists())) {
65
+ await this.#initDefaultObject();
66
+ }
67
+ return await stoOpGet(this.#fullStorageKey);
68
+ }
69
+
70
+ /**
71
+ * [Create/Update] Overwrite the value of the bound key completely.
72
+ * @param {object} value The new Object data to store
73
+ * @return {Promise<void>}
74
+ */
75
+ async set(value) {
76
+ await stoOpSet(this.#fullStorageKey, value || this.#defaultValue);
77
+ }
78
+
79
+ /**
80
+ * [Delete] Wipe the bound key from storage and return its final state prior to deletion.
81
+ * @return {Promise<object>}
82
+ */
83
+ async delete() {
84
+ const previousValue = await this.get();
85
+ await stoOpRem(this.#fullStorageKey);
86
+ return previousValue;
87
+ }
88
+
89
+ /**
90
+ * [Partial Update] Modify a single targeted key-value pair nested deep within the stored object.
91
+ * @param {string} objectKey The internal key path inside the main value object
92
+ * @param {*} objectValue The new value to map to that key
93
+ * @return {Promise<object>} Returns the fully updated object structure
94
+ */
95
+ async updateValueKeyValue(objectKey, objectValue) {
96
+ const currentData = await this.get();
97
+ currentData[objectKey] = objectValue;
98
+ await this.set(currentData);
99
+ return currentData;
100
+ }
101
+ }
@@ -0,0 +1,9 @@
1
+ import {BaseORM} from './BaseORM.js';
2
+
3
+ export class DomainORM extends BaseORM {
4
+ constructor(domain) {
5
+ super(`domain`, domain, {
6
+
7
+ });
8
+ }
9
+ }
package/src/baseORM.js DELETED
@@ -1,121 +0,0 @@
1
- import {
2
- stoOpCheck,
3
- stoOpGet,
4
- stoOpQueryStartWith,
5
- stoOpRem,
6
- stoOpSet,
7
- } from './opStorage.js';
8
-
9
- /**
10
- * eg:
11
- *
12
- * "domain ://abcdefg.com":{
13
- * "keyAAA": "valueBBB"
14
- * }
15
- */
16
- export class BaseORM {
17
- // Private class fields for encapsulation
18
- #keyPrefix = `domain `;
19
- #domainDefaultValue = {};
20
-
21
- // Private helper method to generate the prefix key
22
- #domainKey(k) {
23
- return `${this.#keyPrefix}${k}`;
24
- }
25
-
26
- /**
27
- * check domain exists, return true/false
28
- * @param {string} domain
29
- * @return {Promise<boolean>}
30
- */
31
- async #checkDomain(domain) {
32
- return await stoOpCheck(this.#domainKey(domain));
33
- }
34
-
35
- /**
36
- * @param {string} domain
37
- * @return {Promise<void>}
38
- */
39
- async #addDomain(domain) {
40
- await stoOpSet(this.#domainKey(domain), this.#domainDefaultValue);
41
- }
42
-
43
- /**
44
- * @param {string} domain
45
- * @return {Promise<void>}
46
- */
47
- async #removeDomain(domain) {
48
- await stoOpRem(this.#domainKey(domain));
49
- }
50
-
51
- /**
52
- * @param {string} domain
53
- * @param {*} valueNew
54
- * @return {Promise<void>}
55
- */
56
- async #updateDomain(domain, valueNew) {
57
- await stoOpSet(this.#domainKey(domain), valueNew);
58
- }
59
-
60
- /**
61
- * eg: ['a.com', 'b.com', 'c.com']
62
- * @returns {Promise<string[]>}
63
- */
64
- async getALLDomainKey() {
65
- // stoOpQueryByPrefix
66
- let strings = await stoOpQueryStartWith(this.#keyPrefix);
67
- return strings.map(v => v.replaceAll(this.#keyPrefix, ''));
68
- }
69
-
70
- /**
71
- * @returns {Promise<{domainList: string[], domainKeyValueMap: {}}>}
72
- */
73
- async getALLDomainMap() {
74
- let domainList = await this.getALLDomainKey();
75
-
76
- const domainKeyValueMap = {};
77
- for (let domain of domainList) {
78
- domainKeyValueMap[domain] = await this.getDomain(domain);
79
- }
80
-
81
- return {domainList, domainKeyValueMap};
82
- }
83
-
84
- /**
85
- * @param {string} domain
86
- * @returns {Promise<{}>}
87
- */
88
- async getDomain(domain) {
89
- if (!(await this.#checkDomain(domain))) {
90
- await this.#addDomain(domain);
91
- }
92
- return await stoOpGet(this.#domainKey(domain));
93
- }
94
-
95
- /**
96
- * {a:a1} => {a:a222}
97
- * @param {string} domain 'xxx.xxxxx.xxx'
98
- * @param {string} key
99
- * @param {string} valueToUpdate
100
- * @return {Promise<{}>}
101
- */
102
- async updateDomainValueByOneKeyValue(domain, key, valueToUpdate) {
103
- if (!(await this.#checkDomain(domain))) {
104
- await this.#addDomain(domain);
105
- }
106
- let domainValueGet = await this.getDomain(domain);
107
- domainValueGet[key] = valueToUpdate;
108
- await this.#updateDomain(domain, domainValueGet);
109
- return await this.getDomain(domain);
110
- }
111
-
112
- /**
113
- * @param {string} domain 'xxx.xxxxx.xxx'
114
- * @return {Promise<{}>}
115
- */
116
- async clearThisDomain(domain) {
117
- let domainValue = await this.getDomain(domain);
118
- await this.#removeDomain(domain);
119
- return domainValue;
120
- }
121
- }