@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/BaseORM.js +28 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vacantthinker/firefox-addon-framework-easy",
3
- "version": "2026.0603.2007",
3
+ "version": "2026.0603.2020",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
package/src/BaseORM.js CHANGED
@@ -1,4 +1,10 @@
1
- import {stoOpCheck, stoOpGet, stoOpRem, stoOpSet} from './opStorage.js';
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 (e.g., a specific hash or filename)
16
- * @param {object} [defaultValue={}] Custom initial value for the instance, defaults to an empty object
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('Both prefix and id must be specified.');
30
+ throw new Error("Both prefix and id must be specified.");
26
31
  }
27
32
 
28
- // Lock down the final storage key during instance construction
29
- this.#fullStorageKey = `${prefix}${id}`;
33
+ // Save the raw id to the private field
34
+ this.#id = id;
30
35
 
31
- // Deep clone the default value to protect against object reference shared-state bugs
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: checks if the bound key exists in the storage layer
60
+ // Private helper method
46
61
  async #exists() {
47
62
  return await stoOpCheck(this.#fullStorageKey);
48
63
  }
49
64
 
50
- // Private helper method: populates the storage key with the designated initial layout
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 and return its final state prior to deletion.
91
+ * [Delete] Wipe the bound key from storage.
78
92
  * @return {Promise<object>}
79
93
  */
80
94
  async delete() {