@qikdev/sdk 0.1.209 → 0.1.211

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qikdev/sdk",
3
- "version": "0.1.209",
3
+ "version": "0.1.211",
4
4
  "type": "module",
5
5
  "description": "Promise based Javascript SDK",
6
6
  "main": "./dist/main.js",
@@ -67,38 +67,12 @@ export default function (qik) {
67
67
 
68
68
  let inflightGlossaryRequest;
69
69
 
70
- let inflateWorker = null;
71
- let workerLoadPromise = null;
72
-
73
- /**
74
- * Lazily load the Worker module (Vite-specific import)
75
- * @private
76
- */
77
- async function loadWorkerModule() {
78
- if (workerLoadPromise) return workerLoadPromise;
79
- workerLoadPromise = import(
80
- "../workers/inflate-glossary.worker.js?worker&inline"
81
- );
82
- return workerLoadPromise;
83
- }
84
-
85
- /**
86
- * Get or create the inflate worker instance
87
- * @private
88
- */
89
- async function getInflateWorker() {
90
- if (inflateWorker) return inflateWorker;
91
- const module = await loadWorkerModule();
92
- inflateWorker = new module.default();
93
- return inflateWorker;
94
- }
95
-
96
70
  /**
97
- * Sync fallback for SSR/Node environments where Workers don't exist
71
+ * Inflate a single value from compressed format
98
72
  * @private
99
73
  */
100
- function inflateGlossarySync({ _s: strings, _k: keyMap, types }) {
101
- function inflate(val) {
74
+ function createInflator(strings, keyMap) {
75
+ return function inflate(val) {
102
76
  if (typeof val === "string" && val[0] === "~") {
103
77
  return strings[parseInt(val.slice(1))];
104
78
  }
@@ -111,46 +85,111 @@ export default function (qik) {
111
85
  return result;
112
86
  }
113
87
  return val;
114
- }
115
- return types.map(inflate);
88
+ };
116
89
  }
117
90
 
118
91
  /**
119
- * Inflate compressed glossary data using a Web Worker
120
- * Runs on a separate thread to avoid blocking the UI
92
+ * Create a lazy-inflating array that only inflates items when accessed
93
+ * This avoids the upfront cost of inflating the entire glossary
121
94
  * @private
122
95
  */
123
- async function inflateGlossary(data) {
124
- // Fallback for non-browser environments (SSR/Node)
125
- if (typeof Worker === "undefined") {
126
- return inflateGlossarySync(data);
127
- }
128
-
129
- try {
130
- const worker = await getInflateWorker();
96
+ function createLazyGlossary({ _s: strings, _k: keyMap, types }) {
97
+ const inflate = createInflator(strings, keyMap);
98
+ const cache = new Array(types.length);
99
+ const inflated = new Array(types.length).fill(false);
100
+
101
+ return new Proxy(types, {
102
+ get(target, prop) {
103
+ // Handle array methods and properties
104
+ if (prop === "length") return target.length;
105
+ if (prop === Symbol.iterator) {
106
+ return function* () {
107
+ for (let i = 0; i < target.length; i++) {
108
+ if (!inflated[i]) {
109
+ cache[i] = inflate(target[i]);
110
+ inflated[i] = true;
111
+ }
112
+ yield cache[i];
113
+ }
114
+ };
115
+ }
116
+ if (prop === "map") {
117
+ return function (fn) {
118
+ const result = [];
119
+ for (let i = 0; i < target.length; i++) {
120
+ if (!inflated[i]) {
121
+ cache[i] = inflate(target[i]);
122
+ inflated[i] = true;
123
+ }
124
+ result.push(fn(cache[i], i, this));
125
+ }
126
+ return result;
127
+ };
128
+ }
129
+ if (prop === "filter") {
130
+ return function (fn) {
131
+ const result = [];
132
+ for (let i = 0; i < target.length; i++) {
133
+ if (!inflated[i]) {
134
+ cache[i] = inflate(target[i]);
135
+ inflated[i] = true;
136
+ }
137
+ if (fn(cache[i], i, this)) {
138
+ result.push(cache[i]);
139
+ }
140
+ }
141
+ return result;
142
+ };
143
+ }
144
+ if (prop === "find") {
145
+ return function (fn) {
146
+ for (let i = 0; i < target.length; i++) {
147
+ if (!inflated[i]) {
148
+ cache[i] = inflate(target[i]);
149
+ inflated[i] = true;
150
+ }
151
+ if (fn(cache[i], i, this)) {
152
+ return cache[i];
153
+ }
154
+ }
155
+ return undefined;
156
+ };
157
+ }
158
+ if (prop === "forEach") {
159
+ return function (fn) {
160
+ for (let i = 0; i < target.length; i++) {
161
+ if (!inflated[i]) {
162
+ cache[i] = inflate(target[i]);
163
+ inflated[i] = true;
164
+ }
165
+ fn(cache[i], i, this);
166
+ }
167
+ };
168
+ }
131
169
 
132
- return new Promise((resolve) => {
133
- const handler = (e) => {
134
- worker.removeEventListener("message", handler);
135
- worker.removeEventListener("error", errorHandler);
136
- resolve(e.data);
137
- };
170
+ // Handle numeric indices
171
+ const index = typeof prop === "string" ? parseInt(prop, 10) : prop;
172
+ if (Number.isInteger(index) && index >= 0 && index < target.length) {
173
+ if (!inflated[index]) {
174
+ cache[index] = inflate(target[index]);
175
+ inflated[index] = true;
176
+ }
177
+ return cache[index];
178
+ }
138
179
 
139
- const errorHandler = () => {
140
- worker.removeEventListener("message", handler);
141
- worker.removeEventListener("error", errorHandler);
142
- // Fallback to sync on error
143
- resolve(inflateGlossarySync(data));
144
- };
180
+ // Pass through other properties
181
+ return Reflect.get(target, prop);
182
+ },
183
+ });
184
+ }
145
185
 
146
- worker.addEventListener("message", handler);
147
- worker.addEventListener("error", errorHandler);
148
- worker.postMessage(data);
149
- });
150
- } catch {
151
- // Dynamic import failed (Node.js or unsupported environment)
152
- return inflateGlossarySync(data);
153
- }
186
+ /**
187
+ * Process compressed glossary data
188
+ * Uses lazy inflation to avoid blocking the main thread
189
+ * @private
190
+ */
191
+ function inflateGlossary(data) {
192
+ return createLazyGlossary(data);
154
193
  }
155
194
 
156
195
  /**
@@ -197,9 +236,9 @@ export default function (qik) {
197
236
  // Now we have the glossary
198
237
  const { data } = await inflightGlossaryRequest;
199
238
 
200
- // Inflate if compressed format (async to avoid blocking UI)
239
+ // Inflate if compressed format (lazy - inflates on access)
201
240
  const glossaryData =
202
- data._s && data._k && data.types ? await inflateGlossary(data) : data;
241
+ data._s && data._k && data.types ? inflateGlossary(data) : data;
203
242
 
204
243
  // Cache it for later
205
244
  glossaryCache.set("glossary", glossaryData);
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.1.209";
1
+ export const version = "0.1.211";
@@ -1,24 +0,0 @@
1
- const s = `(function(){"use strict";self.onmessage=function(r){const{_s:o,_k:f,types:i}=r.data;function e(t){if(typeof t=="string"&&t[0]==="~")return o[parseInt(t.slice(1))];if(Array.isArray(t))return t.map(e);if(t&&typeof t=="object"){const s={};for(const[n,u]of Object.entries(t))s[f[n]||n]=e(u);return s}return t}const c=i.map(e);self.postMessage(c)}})();
2
- `, n = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", s], { type: "text/javascript;charset=utf-8" });
3
- function o(r) {
4
- let e;
5
- try {
6
- if (e = n && (self.URL || self.webkitURL).createObjectURL(n), !e) throw "";
7
- const t = new Worker(e, {
8
- name: r?.name
9
- });
10
- return t.addEventListener("error", () => {
11
- (self.URL || self.webkitURL).revokeObjectURL(e);
12
- }), t;
13
- } catch {
14
- return new Worker(
15
- "data:text/javascript;charset=utf-8," + encodeURIComponent(s),
16
- {
17
- name: r?.name
18
- }
19
- );
20
- }
21
- }
22
- export {
23
- o as default
24
- };
@@ -1,25 +0,0 @@
1
- /**
2
- * Web Worker for inflating compressed glossary data
3
- * Runs on a separate thread to avoid blocking the main UI
4
- */
5
- self.onmessage = function (e) {
6
- const { _s: strings, _k: keyMap, types } = e.data;
7
-
8
- function inflate(val) {
9
- if (typeof val === "string" && val[0] === "~") {
10
- return strings[parseInt(val.slice(1))];
11
- }
12
- if (Array.isArray(val)) return val.map(inflate);
13
- if (val && typeof val === "object") {
14
- const result = {};
15
- for (const [k, v] of Object.entries(val)) {
16
- result[keyMap[k] || k] = inflate(v);
17
- }
18
- return result;
19
- }
20
- return val;
21
- }
22
-
23
- const result = types.map(inflate);
24
- self.postMessage(result);
25
- };