@vacantthinker/firefox-addon-framework-easy 2026.603.1511 → 2026.603.1748
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 +7 -1
- package/index.js +2 -1
- package/package.json +1 -1
- package/src/BaseORM.js +95 -0
- package/src/DomainORM.js +9 -0
- package/src/baseORM.js +0 -121
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/
|
|
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/
|
|
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
package/src/BaseORM.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stoOpCheck,
|
|
3
|
+
stoOpGet,
|
|
4
|
+
stoOpRem,
|
|
5
|
+
stoOpSet,
|
|
6
|
+
} from './opStorage.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Abstract base class BaseORM (similar to Java's Abstract Class).
|
|
10
|
+
* Provides encapsulated CRUD operations for specific Key-Value pairs bound at instantiation.
|
|
11
|
+
*/
|
|
12
|
+
export class BaseORM {
|
|
13
|
+
// Private fields for data encapsulation
|
|
14
|
+
#fullStorageKey;
|
|
15
|
+
#defaultValue;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Constructor
|
|
19
|
+
* @param {string} prefix The prefix for the keys (e.g., 'magnetKey')
|
|
20
|
+
* @param {string} id The unique identifier for this instance (e.g., a specific hash or filename)
|
|
21
|
+
* @param {object} [defaultValue={}] Custom initial value for the instance, defaults to an empty object
|
|
22
|
+
*/
|
|
23
|
+
constructor(prefix, id, defaultValue = {}) {
|
|
24
|
+
// Simulating Java's abstract class behavior: prevent direct instantiation of the base class
|
|
25
|
+
if (new.target === BaseORM) {
|
|
26
|
+
throw new TypeError("Cannot construct BaseORM instances directly (Abstract Class).");
|
|
27
|
+
}
|
|
28
|
+
if (!prefix || !id) {
|
|
29
|
+
throw new Error("Both prefix and id must be specified.");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Automatically normalize the prefix format to ensure a clean trailing space
|
|
33
|
+
const formattedPrefix = prefix.endsWith(' ') ? prefix : `${prefix} `;
|
|
34
|
+
|
|
35
|
+
// Lock down the final storage key during instance construction
|
|
36
|
+
this.#fullStorageKey = `${formattedPrefix}${id}`;
|
|
37
|
+
|
|
38
|
+
// Deep clone the default value to protect against object reference shared-state bugs
|
|
39
|
+
this.#defaultValue = JSON.parse(JSON.stringify(defaultValue));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Private helper method: checks if the bound key exists in the storage layer
|
|
43
|
+
async #exists() {
|
|
44
|
+
return await stoOpCheck(this.#fullStorageKey);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Private helper method: populates the storage key with the designated initial layout
|
|
48
|
+
async #initDefaultObject() {
|
|
49
|
+
await stoOpSet(this.#fullStorageKey, this.#defaultValue);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* [Read] Retrieve the value associated with the bound key.
|
|
54
|
+
* If it does not exist yet, it automatically initializes it with the default value first.
|
|
55
|
+
* @return {Promise<object>}
|
|
56
|
+
*/
|
|
57
|
+
async get() {
|
|
58
|
+
if (!(await this.#exists())) {
|
|
59
|
+
await this.#initDefaultObject();
|
|
60
|
+
}
|
|
61
|
+
return await stoOpGet(this.#fullStorageKey);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* [Create/Update] Overwrite the value of the bound key completely.
|
|
66
|
+
* @param {object} value The new Object data to store
|
|
67
|
+
* @return {Promise<void>}
|
|
68
|
+
*/
|
|
69
|
+
async set(value) {
|
|
70
|
+
await stoOpSet(this.#fullStorageKey, value || this.#defaultValue);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* [Delete] Wipe the bound key from storage and return its final state prior to deletion.
|
|
75
|
+
* @return {Promise<object>}
|
|
76
|
+
*/
|
|
77
|
+
async delete() {
|
|
78
|
+
const previousValue = await this.get();
|
|
79
|
+
await stoOpRem(this.#fullStorageKey);
|
|
80
|
+
return previousValue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* [Partial Update] Modify a single targeted key-value pair nested deep within the stored object.
|
|
85
|
+
* @param {string} objectKey The internal key path inside the main value object
|
|
86
|
+
* @param {*} objectValue The new value to map to that key
|
|
87
|
+
* @return {Promise<object>} Returns the fully updated object structure
|
|
88
|
+
*/
|
|
89
|
+
async updateValueKeyValue(objectKey, objectValue) {
|
|
90
|
+
const currentData = await this.get();
|
|
91
|
+
currentData[objectKey] = objectValue;
|
|
92
|
+
await this.set(currentData);
|
|
93
|
+
return currentData;
|
|
94
|
+
}
|
|
95
|
+
}
|
package/src/DomainORM.js
ADDED
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
|
-
}
|