@qikdev/sdk 0.1.204 → 0.1.206
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/dist/main.js +1456 -1439
- package/package.json +1 -1
- package/src/api/qik.content.js +37 -4
- package/src/version.js +1 -1
package/package.json
CHANGED
package/src/api/qik.content.js
CHANGED
|
@@ -67,6 +67,28 @@ export default function (qik) {
|
|
|
67
67
|
|
|
68
68
|
let inflightGlossaryRequest;
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Inflate compressed glossary data from the /glossary/compressed endpoint
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
function inflateGlossary({ _s: strings, _k: keyMap, types }) {
|
|
75
|
+
function inflate(val) {
|
|
76
|
+
if (typeof val === "string" && val[0] === "~") {
|
|
77
|
+
return strings[parseInt(val.slice(1))];
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(val)) return val.map(inflate);
|
|
80
|
+
if (val && typeof val === "object") {
|
|
81
|
+
const result = {};
|
|
82
|
+
for (const [k, v] of Object.entries(val)) {
|
|
83
|
+
result[keyMap[k] || k] = inflate(v);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
return val;
|
|
88
|
+
}
|
|
89
|
+
return types.map(inflate);
|
|
90
|
+
}
|
|
91
|
+
|
|
70
92
|
/**
|
|
71
93
|
*
|
|
72
94
|
* Retrieves the glossary of all content types visible to the requesting user.
|
|
@@ -77,15 +99,20 @@ export default function (qik) {
|
|
|
77
99
|
allowing for fast selection of specific content types, by default will return as an array
|
|
78
100
|
* @param {Boolean} options.reload Force glossary to reload and not be cached.
|
|
79
101
|
If false will retrieve content type data from the in memory cache
|
|
102
|
+
* @param {Boolean} options.uncompressed Use the uncompressed endpoint
|
|
80
103
|
* @example
|
|
81
104
|
*
|
|
82
105
|
* const { article, profile } = await sdk.content.glossary({hash:true});
|
|
106
|
+
* // Use compressed endpoint for faster loading
|
|
107
|
+
* const glossary = await sdk.content.glossary({compressed:true});
|
|
83
108
|
*/
|
|
84
109
|
service.glossary = async function (options) {
|
|
85
110
|
options = options || {};
|
|
86
111
|
|
|
87
112
|
// Check if we already have the glossary cached
|
|
88
113
|
let cached = glossaryCache.get("glossary");
|
|
114
|
+
const uncompressed = !!options.uncompressed;
|
|
115
|
+
let compressed = !uncompressed;
|
|
89
116
|
var reload = options.refresh || options.reload || !cached;
|
|
90
117
|
|
|
91
118
|
// If we are forcing a reload
|
|
@@ -93,7 +120,9 @@ export default function (qik) {
|
|
|
93
120
|
if (!inflightGlossaryRequest) {
|
|
94
121
|
service.loadingGlossary = true;
|
|
95
122
|
|
|
96
|
-
|
|
123
|
+
// Use compressed endpoint if requested
|
|
124
|
+
const endpoint = compressed ? `/glossary/compressed` : `/glossary`;
|
|
125
|
+
inflightGlossaryRequest = qik.api.get(endpoint, { cache: false });
|
|
97
126
|
inflightGlossaryRequest.then(resolveRequest, resolveRequest);
|
|
98
127
|
function resolveRequest() {
|
|
99
128
|
inflightGlossaryRequest = null;
|
|
@@ -104,10 +133,14 @@ export default function (qik) {
|
|
|
104
133
|
// Now we have the glossary
|
|
105
134
|
const { data } = await inflightGlossaryRequest;
|
|
106
135
|
|
|
136
|
+
// Inflate if compressed format
|
|
137
|
+
const glossaryData =
|
|
138
|
+
data._s && data._k && data.types ? inflateGlossary(data) : data;
|
|
139
|
+
|
|
107
140
|
// Cache it for later
|
|
108
|
-
glossaryCache.set("glossary",
|
|
109
|
-
cached =
|
|
110
|
-
qik.dispatch("glossary",
|
|
141
|
+
glossaryCache.set("glossary", glossaryData);
|
|
142
|
+
cached = glossaryData;
|
|
143
|
+
qik.dispatch("glossary", glossaryData);
|
|
111
144
|
}
|
|
112
145
|
|
|
113
146
|
if (options.hash) {
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.1.
|
|
1
|
+
export const version = "0.1.206";
|