@dyrected/sdk 2.5.13 → 2.5.14
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/index.cjs +41 -15
- package/dist/index.js +40 -6
- package/package.json +14 -7
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -37,7 +27,43 @@ __export(index_exports, {
|
|
|
37
27
|
generateFreshSetupPrompt: () => generateFreshSetupPrompt
|
|
38
28
|
});
|
|
39
29
|
module.exports = __toCommonJS(index_exports);
|
|
40
|
-
|
|
30
|
+
|
|
31
|
+
// src/utils/stringify.ts
|
|
32
|
+
function stringify(obj, prefix = "") {
|
|
33
|
+
if (obj === null || obj === void 0) {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
const pairs = [];
|
|
37
|
+
for (const key in obj) {
|
|
38
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
39
|
+
const value = obj[key];
|
|
40
|
+
const enKey = prefix ? `${prefix}[${encodeURIComponent(key)}]` : encodeURIComponent(key);
|
|
41
|
+
if (value === null || value === void 0) {
|
|
42
|
+
continue;
|
|
43
|
+
} else if (Array.isArray(value)) {
|
|
44
|
+
for (let i = 0; i < value.length; i++) {
|
|
45
|
+
const val = value[i];
|
|
46
|
+
if (typeof val === "object" && val !== null) {
|
|
47
|
+
pairs.push(stringify(val, `${enKey}[${i}]`));
|
|
48
|
+
} else if (val !== null && val !== void 0) {
|
|
49
|
+
pairs.push(`${enKey}[${i}]=${encodeURIComponent(val)}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else if (typeof value === "object") {
|
|
53
|
+
pairs.push(stringify(value, enKey));
|
|
54
|
+
} else {
|
|
55
|
+
pairs.push(`${enKey}=${encodeURIComponent(value)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return pairs.filter(Boolean).join("&");
|
|
59
|
+
}
|
|
60
|
+
function stringifyQuery(obj, options) {
|
|
61
|
+
const result = stringify(obj);
|
|
62
|
+
if (options?.addQueryPrefix && result) {
|
|
63
|
+
return `?${result}`;
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
41
67
|
|
|
42
68
|
// src/query-builder.ts
|
|
43
69
|
var QueryBuilder = class {
|
|
@@ -953,7 +979,7 @@ var DyrectedClient = class {
|
|
|
953
979
|
if (normalizedArgs.where && typeof normalizedArgs.where === "object") {
|
|
954
980
|
normalizedArgs.where = JSON.stringify(normalizedArgs.where);
|
|
955
981
|
}
|
|
956
|
-
const query =
|
|
982
|
+
const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
|
|
957
983
|
const res = await this.request(`/api/collections/${collection}${query}`);
|
|
958
984
|
if (res.docs.length === 0 && initialData && initialData.length > 0) {
|
|
959
985
|
this.request(`/api/collections/${collection}/seed`, {
|
|
@@ -1063,7 +1089,7 @@ var DyrectedClient = class {
|
|
|
1063
1089
|
}
|
|
1064
1090
|
async findOne(collection, id, args = {}) {
|
|
1065
1091
|
const { initialData, ...queryArgs } = args;
|
|
1066
|
-
const query =
|
|
1092
|
+
const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
|
|
1067
1093
|
try {
|
|
1068
1094
|
return await this.request(`/api/collections/${collection}/${id}${query}`);
|
|
1069
1095
|
} catch (err) {
|
|
@@ -1099,12 +1125,12 @@ var DyrectedClient = class {
|
|
|
1099
1125
|
async deleteMany(collection, ids) {
|
|
1100
1126
|
return this.request(`/api/collections/${collection}/delete-many`, {
|
|
1101
1127
|
method: "DELETE",
|
|
1102
|
-
body:
|
|
1128
|
+
body: stringify({ ids })
|
|
1103
1129
|
});
|
|
1104
1130
|
}
|
|
1105
1131
|
async getGlobal(slug, args = {}) {
|
|
1106
1132
|
const { initialData, ...queryArgs } = args;
|
|
1107
|
-
const query =
|
|
1133
|
+
const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
|
|
1108
1134
|
try {
|
|
1109
1135
|
const res = await this.request(`/api/globals/${slug}${query}`);
|
|
1110
1136
|
if ((!res || Object.keys(res).length === 0) && initialData) {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
1
|
+
// src/utils/stringify.ts
|
|
2
|
+
function stringify(obj, prefix = "") {
|
|
3
|
+
if (obj === null || obj === void 0) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
const pairs = [];
|
|
7
|
+
for (const key in obj) {
|
|
8
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
9
|
+
const value = obj[key];
|
|
10
|
+
const enKey = prefix ? `${prefix}[${encodeURIComponent(key)}]` : encodeURIComponent(key);
|
|
11
|
+
if (value === null || value === void 0) {
|
|
12
|
+
continue;
|
|
13
|
+
} else if (Array.isArray(value)) {
|
|
14
|
+
for (let i = 0; i < value.length; i++) {
|
|
15
|
+
const val = value[i];
|
|
16
|
+
if (typeof val === "object" && val !== null) {
|
|
17
|
+
pairs.push(stringify(val, `${enKey}[${i}]`));
|
|
18
|
+
} else if (val !== null && val !== void 0) {
|
|
19
|
+
pairs.push(`${enKey}[${i}]=${encodeURIComponent(val)}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
} else if (typeof value === "object") {
|
|
23
|
+
pairs.push(stringify(value, enKey));
|
|
24
|
+
} else {
|
|
25
|
+
pairs.push(`${enKey}=${encodeURIComponent(value)}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return pairs.filter(Boolean).join("&");
|
|
29
|
+
}
|
|
30
|
+
function stringifyQuery(obj, options) {
|
|
31
|
+
const result = stringify(obj);
|
|
32
|
+
if (options?.addQueryPrefix && result) {
|
|
33
|
+
return `?${result}`;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
3
37
|
|
|
4
38
|
// src/query-builder.ts
|
|
5
39
|
var QueryBuilder = class {
|
|
@@ -915,7 +949,7 @@ var DyrectedClient = class {
|
|
|
915
949
|
if (normalizedArgs.where && typeof normalizedArgs.where === "object") {
|
|
916
950
|
normalizedArgs.where = JSON.stringify(normalizedArgs.where);
|
|
917
951
|
}
|
|
918
|
-
const query =
|
|
952
|
+
const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
|
|
919
953
|
const res = await this.request(`/api/collections/${collection}${query}`);
|
|
920
954
|
if (res.docs.length === 0 && initialData && initialData.length > 0) {
|
|
921
955
|
this.request(`/api/collections/${collection}/seed`, {
|
|
@@ -1025,7 +1059,7 @@ var DyrectedClient = class {
|
|
|
1025
1059
|
}
|
|
1026
1060
|
async findOne(collection, id, args = {}) {
|
|
1027
1061
|
const { initialData, ...queryArgs } = args;
|
|
1028
|
-
const query =
|
|
1062
|
+
const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
|
|
1029
1063
|
try {
|
|
1030
1064
|
return await this.request(`/api/collections/${collection}/${id}${query}`);
|
|
1031
1065
|
} catch (err) {
|
|
@@ -1061,12 +1095,12 @@ var DyrectedClient = class {
|
|
|
1061
1095
|
async deleteMany(collection, ids) {
|
|
1062
1096
|
return this.request(`/api/collections/${collection}/delete-many`, {
|
|
1063
1097
|
method: "DELETE",
|
|
1064
|
-
body:
|
|
1098
|
+
body: stringify({ ids })
|
|
1065
1099
|
});
|
|
1066
1100
|
}
|
|
1067
1101
|
async getGlobal(slug, args = {}) {
|
|
1068
1102
|
const { initialData, ...queryArgs } = args;
|
|
1069
|
-
const query =
|
|
1103
|
+
const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
|
|
1070
1104
|
try {
|
|
1071
1105
|
const res = await this.request(`/api/globals/${slug}${query}`);
|
|
1072
1106
|
if ((!res || Object.keys(res).length === 0) && initialData) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dyrected/sdk",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -15,15 +15,22 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"tsup": {
|
|
19
|
+
"entry": [
|
|
20
|
+
"src/index.ts"
|
|
21
|
+
],
|
|
22
|
+
"format": [
|
|
23
|
+
"cjs",
|
|
24
|
+
"esm"
|
|
25
|
+
],
|
|
26
|
+
"dts": true
|
|
20
27
|
},
|
|
28
|
+
"dependencies": {},
|
|
21
29
|
"devDependencies": {
|
|
22
|
-
"@types/qs": "^6.15.1",
|
|
23
30
|
"tsup": "^8.5.1",
|
|
24
31
|
"typescript": "^5.4.5",
|
|
25
32
|
"vitest": "^1.0.0",
|
|
26
|
-
"@dyrected/core": "2.5.
|
|
33
|
+
"@dyrected/core": "2.5.14"
|
|
27
34
|
},
|
|
28
35
|
"license": "BSL-1.1",
|
|
29
36
|
"author": "Busola Okeowo <busolaokemoney@gmail.com>",
|
|
@@ -37,8 +44,8 @@
|
|
|
37
44
|
},
|
|
38
45
|
"description": "Client-side SDK for Dyrected CMS",
|
|
39
46
|
"scripts": {
|
|
40
|
-
"build": "tsup
|
|
41
|
-
"dev": "tsup
|
|
47
|
+
"build": "tsup",
|
|
48
|
+
"dev": "tsup --watch",
|
|
42
49
|
"lint": "eslint src",
|
|
43
50
|
"test": "vitest run"
|
|
44
51
|
}
|