@qikdev/sdk 0.1.212 → 0.1.214

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.212",
3
+ "version": "0.1.214",
4
4
  "type": "module",
5
5
  "description": "Promise based Javascript SDK",
6
6
  "main": "./dist/main.js",
@@ -64,8 +64,160 @@ export default function (qik) {
64
64
  ///////////////////////////////////////////////////
65
65
 
66
66
  const glossaryCache = qik.cache.get("user:glossary");
67
+ const glossaryIndexCache = qik.cache.get("user:glossary:index");
68
+ const definitionCache = qik.cache.get("user:glossary:definitions");
67
69
 
68
70
  let inflightGlossaryRequest;
71
+ let inflightGlossaryIndexRequest;
72
+ let inflightDefinitionRequests = {};
73
+
74
+ /**
75
+ * Load the lightweight glossary index.
76
+ * Returns cached version unless reload is specified.
77
+ * @alias content.loadGlossaryIndex
78
+ * @param {Object} options Additional options
79
+ * @param {Boolean} options.hash Return as object keyed by type key
80
+ * @param {Boolean} options.hex Return as object keyed by hex
81
+ * @param {Boolean} options.reload Force reload from server
82
+ * @returns {Promise<Array|Object>} The glossary index
83
+ * @example
84
+ * const index = await sdk.content.loadGlossaryIndex();
85
+ * const indexHash = await sdk.content.loadGlossaryIndex({ hash: true });
86
+ */
87
+ service.loadGlossaryIndex = async function (options) {
88
+ options = options || {};
89
+
90
+ let cached = glossaryIndexCache.get("index");
91
+ const reload = options.reload || options.refresh || !cached;
92
+
93
+ if (reload) {
94
+ if (!inflightGlossaryIndexRequest) {
95
+ inflightGlossaryIndexRequest = qik.api.get("/glossary/index");
96
+ inflightGlossaryIndexRequest.then(
97
+ () => {
98
+ inflightGlossaryIndexRequest = null;
99
+ },
100
+ () => {
101
+ inflightGlossaryIndexRequest = null;
102
+ },
103
+ );
104
+ }
105
+
106
+ const { data } = await inflightGlossaryIndexRequest;
107
+ glossaryIndexCache.set("index", data);
108
+ cached = data;
109
+ qik.dispatch("glossary:index", data);
110
+ }
111
+
112
+ if (options.hash) {
113
+ return qik.utils.hash(cached, "key");
114
+ }
115
+
116
+ if (options.hex) {
117
+ return qik.utils.hash(cached, "hex");
118
+ }
119
+
120
+ return cached;
121
+ };
122
+
123
+ /**
124
+ * Get a full definition for a specific type.
125
+ * Returns cached if available, otherwise fetches from server.
126
+ * Multiple simultaneous calls for the same key share one request.
127
+ * @alias content.getDefinition
128
+ * @param {String} key The type key (e.g., 'article', 'profile')
129
+ * @param {Object} options Additional options
130
+ * @param {Boolean} options.reload Force reload from server
131
+ * @returns {Promise<Object>} The full type definition
132
+ * @example
133
+ * const article = await sdk.content.getDefinition('article');
134
+ * console.log(article.fields);
135
+ */
136
+ service.getDefinition = async function (key, options) {
137
+ options = options || {};
138
+
139
+ // Return cached if available and not forcing reload
140
+ let cached = definitionCache.get(key);
141
+ if (cached && !options.reload && !options.refresh) {
142
+ return cached;
143
+ }
144
+
145
+ // If already loading, wait for it (request deduplication)
146
+ if (inflightDefinitionRequests[key]) {
147
+ await inflightDefinitionRequests[key];
148
+ return definitionCache.get(key);
149
+ }
150
+
151
+ // Make the request
152
+ inflightDefinitionRequests[key] = qik.api.get(`/glossary/index/${key}`);
153
+
154
+ try {
155
+ const { data } = await inflightDefinitionRequests[key];
156
+ definitionCache.set(key, data);
157
+ qik.dispatch("glossary:definition", { key, data });
158
+ return data;
159
+ } finally {
160
+ inflightDefinitionRequests[key] = null;
161
+ }
162
+ };
163
+
164
+ let inflightTypeRequests = {};
165
+ let typeResultsCache = {};
166
+
167
+ /**
168
+ * Load all definitions that match or extend a given type.
169
+ * For example, loadDefinitionsForType('submission') returns all form definitions.
170
+ * Results are cached individually - subsequent getDefinition() calls return from cache.
171
+ * @alias content.loadDefinitionsForType
172
+ * @param {String} type The base type key (e.g., 'submission', 'workflowcard', 'article')
173
+ * @param {Object} options Additional options
174
+ * @param {Boolean} options.hash Return as object keyed by definition key
175
+ * @param {Boolean} options.reload Force reload from server
176
+ * @returns {Promise<Array|Object>} Array of definitions, or hash if options.hash
177
+ * @example
178
+ * const submissions = await sdk.content.loadDefinitionsForType('submission');
179
+ * const workflowCards = await sdk.content.loadDefinitionsForType('workflowcard', { hash: true });
180
+ */
181
+ service.loadDefinitionsForType = async function (type, options) {
182
+ options = options || {};
183
+
184
+ // Return cached if available and not forcing reload
185
+ if (typeResultsCache[type] && !options.reload && !options.refresh) {
186
+ const data = typeResultsCache[type];
187
+ return options.hash ? qik.utils.hash(data, "key") : data;
188
+ }
189
+
190
+ // If already loading this type, wait for it
191
+ if (inflightTypeRequests[type]) {
192
+ await inflightTypeRequests[type];
193
+ const data = typeResultsCache[type];
194
+ return options.hash ? qik.utils.hash(data, "key") : data;
195
+ }
196
+
197
+ // Make the request
198
+ inflightTypeRequests[type] = qik.api.get(`/glossary/index/${type}/all`);
199
+
200
+ try {
201
+ const { data } = await inflightTypeRequests[type];
202
+
203
+ // Cache the type results for subsequent calls
204
+ typeResultsCache[type] = data;
205
+
206
+ // Cache each definition individually in the unified cache
207
+ data.forEach((definition) => {
208
+ definitionCache.set(definition.key, definition);
209
+ });
210
+
211
+ qik.dispatch("glossary:type", { type, definitions: data });
212
+
213
+ if (options.hash) {
214
+ return qik.utils.hash(data, "key");
215
+ }
216
+ return data;
217
+ } finally {
218
+ inflightTypeRequests[type] = null;
219
+ }
220
+ };
69
221
 
70
222
  /**
71
223
  * Inflate a single value from compressed format
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.1.212";
1
+ export const version = "0.1.214";