mosquito-transport-js 0.4.2 → 0.4.6
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": "mosquito-transport-js",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "Javascript web sdk for mosquito-transport (https://github.com/brainbehindx/mosquito-transport)",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"bson": "^6.8.0",
|
|
33
33
|
"buffer": "^6.0.3",
|
|
34
34
|
"entity-serializer": "^1.0.2",
|
|
35
|
-
"guard-object": "^1.1.
|
|
35
|
+
"guard-object": "^1.1.4",
|
|
36
36
|
"limit-task": "1.0.0",
|
|
37
37
|
"lodash": "^4.17.21",
|
|
38
38
|
"simplify-error": "^1.0.1",
|
package/src/index.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export const insertRecord = async (builder, config, accessIdWithoutLimit, value,
|
|
|
96
96
|
export const getRecord = async (builder, accessIdWithoutLimit, episode = 0) => {
|
|
97
97
|
await awaitStore();
|
|
98
98
|
const { projectUrl, dbUrl, dbName, path, command } = builder;
|
|
99
|
-
const { limit, sort, direction, random } = command;
|
|
99
|
+
const { limit, sort, direction, random, findOne } = command;
|
|
100
100
|
const isEpisode = episode === 1;
|
|
101
101
|
|
|
102
102
|
const transformData = (data) => {
|
|
@@ -435,7 +435,7 @@ const hydrateForeignDoc = ({ data, doc_holder }) => {
|
|
|
435
435
|
if (v?._foreign_doc) {
|
|
436
436
|
v._foreign_doc = Array.isArray(v._foreign_doc)
|
|
437
437
|
? v._foreign_doc.map(k => doc_holder[k])
|
|
438
|
-
: doc_holder[
|
|
438
|
+
: doc_holder[v._foreign_doc];
|
|
439
439
|
}
|
|
440
440
|
return v;
|
|
441
441
|
});
|
|
@@ -49,7 +49,8 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
49
49
|
const isLink = Validator.LINK(input);
|
|
50
50
|
const isBaseUrl = isLink || rawApproach;
|
|
51
51
|
const disableAuth = method?.disableAuth || isBaseUrl;
|
|
52
|
-
const
|
|
52
|
+
const hasBody = body !== undefined;
|
|
53
|
+
const shouldCache = (retrieval !== RETRIEVAL.DEFAULT || (config.disableCache === undefined ? !hasBody : !disableCache)) &&
|
|
53
54
|
![RETRIEVAL.NO_CACHE_NO_AWAIT, RETRIEVAL.NO_CACHE_AWAIT].includes(retrieval);
|
|
54
55
|
const uglified = !!(!isBaseUrl && uglify);
|
|
55
56
|
|
|
@@ -137,23 +138,25 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
137
138
|
|
|
138
139
|
const mtoken = Scoped.AuthJWTToken[projectUrl];
|
|
139
140
|
const initType = rawHeader['content-type'];
|
|
141
|
+
const encodeBody = initType === undefined && hasBody && !isBaseUrl;
|
|
140
142
|
|
|
141
143
|
const [reqBuilder, [privateKey]] = uglified ? await serializeE2E(rawBody, mtoken, serverE2E_PublicKey) : [null, []];
|
|
142
144
|
|
|
143
145
|
const f = await fetch(isLink ? input : `${projectUrl}/${normalizeRoute(input)}`, {
|
|
144
|
-
...(!isBaseUrl ||
|
|
146
|
+
...(!isBaseUrl || hasBody) ? { method: 'POST' } : {},
|
|
145
147
|
...init,
|
|
146
|
-
...uglified ? { body: reqBuilder } : {},
|
|
148
|
+
...uglified ? { body: reqBuilder } : encodeBody ? { body: serialize(body) } : {},
|
|
147
149
|
// cache: 'no-cache',
|
|
148
150
|
headers: {
|
|
149
151
|
...extraHeaders,
|
|
150
|
-
...isBaseUrl ? {} : { 'content-type': 'application/json' },
|
|
151
152
|
...rawHeader,
|
|
152
153
|
...uglified ? {
|
|
153
154
|
uglified,
|
|
154
155
|
'content-type': 'request/buffer',
|
|
155
156
|
...initType ? { 'init-content-type': initType } : {}
|
|
156
|
-
} :
|
|
157
|
+
} : encodeBody
|
|
158
|
+
? { 'content-type': 'request/buffer' }
|
|
159
|
+
: {},
|
|
157
160
|
...(disableAuth || !mtoken || uglified || isBaseUrl) ? {} : { mtoken }
|
|
158
161
|
}
|
|
159
162
|
});
|