@medusajs/utils 1.10.1 → 1.10.2-next-20230925165416

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.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Convert a string fields array to a remote query object
3
+ * @param entryPoint
4
+ * @param variables
5
+ * @param fields
6
+ *
7
+ * @example
8
+ * const fields = [
9
+ * "id",
10
+ * "created_at",
11
+ * "updated_at",
12
+ * "deleted_at",
13
+ * "url",
14
+ * "metadata",
15
+ * "tags.id",
16
+ * "tags.created_at",
17
+ * "tags.updated_at",
18
+ * "tags.deleted_at",
19
+ * "tags.value",
20
+ * "options.id",
21
+ * "options.created_at",
22
+ * "options.updated_at",
23
+ * "options.deleted_at",
24
+ * "options.title",
25
+ * "options.product_id",
26
+ * "options.metadata",
27
+ * "options.values.id",
28
+ * "options.values.created_at",
29
+ * "options.values.updated_at",
30
+ * "options.values.deleted_at",
31
+ * "options.values.value",
32
+ * "options.values.option_id",
33
+ * "options.values.variant_id",
34
+ * "options.values.metadata",
35
+ * ]
36
+ *
37
+ * const remoteQueryObject = stringToRemoteQueryObject({
38
+ * entryPoint: "product",
39
+ * variables: {},
40
+ * fields,
41
+ * })
42
+ *
43
+ * console.log(remoteQueryObject)
44
+ * // {
45
+ * // product: {
46
+ * // __args: {},
47
+ * // fields: [
48
+ * // "id",
49
+ * // "created_at",
50
+ * // "updated_at",
51
+ * // "deleted_at",
52
+ * // "url",
53
+ * // "metadata",
54
+ * // ],
55
+ * //
56
+ * // tags: {
57
+ * // fields: ["id", "created_at", "updated_at", "deleted_at", "value"],
58
+ * // },
59
+ * //
60
+ * // options: {
61
+ * // fields: [
62
+ * // "id",
63
+ * // "created_at",
64
+ * // "updated_at",
65
+ * // "deleted_at",
66
+ * // "title",
67
+ * // "product_id",
68
+ * // "metadata",
69
+ * // ],
70
+ * // values: {
71
+ * // fields: [
72
+ * // "id",
73
+ * // "created_at",
74
+ * // "updated_at",
75
+ * // "deleted_at",
76
+ * // "value",
77
+ * // "option_id",
78
+ * // "variant_id",
79
+ * // "metadata",
80
+ * // ],
81
+ * // },
82
+ * // },
83
+ * // },
84
+ * // }
85
+ */
86
+ export declare function stringToRemoteQueryObject({ entryPoint, variables, fields, }: {
87
+ entryPoint: string;
88
+ variables?: any;
89
+ fields: string[];
90
+ }): object;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.stringToRemoteQueryObject = void 0;
15
+ /**
16
+ * Convert a string fields array to a remote query object
17
+ * @param entryPoint
18
+ * @param variables
19
+ * @param fields
20
+ *
21
+ * @example
22
+ * const fields = [
23
+ * "id",
24
+ * "created_at",
25
+ * "updated_at",
26
+ * "deleted_at",
27
+ * "url",
28
+ * "metadata",
29
+ * "tags.id",
30
+ * "tags.created_at",
31
+ * "tags.updated_at",
32
+ * "tags.deleted_at",
33
+ * "tags.value",
34
+ * "options.id",
35
+ * "options.created_at",
36
+ * "options.updated_at",
37
+ * "options.deleted_at",
38
+ * "options.title",
39
+ * "options.product_id",
40
+ * "options.metadata",
41
+ * "options.values.id",
42
+ * "options.values.created_at",
43
+ * "options.values.updated_at",
44
+ * "options.values.deleted_at",
45
+ * "options.values.value",
46
+ * "options.values.option_id",
47
+ * "options.values.variant_id",
48
+ * "options.values.metadata",
49
+ * ]
50
+ *
51
+ * const remoteQueryObject = stringToRemoteQueryObject({
52
+ * entryPoint: "product",
53
+ * variables: {},
54
+ * fields,
55
+ * })
56
+ *
57
+ * console.log(remoteQueryObject)
58
+ * // {
59
+ * // product: {
60
+ * // __args: {},
61
+ * // fields: [
62
+ * // "id",
63
+ * // "created_at",
64
+ * // "updated_at",
65
+ * // "deleted_at",
66
+ * // "url",
67
+ * // "metadata",
68
+ * // ],
69
+ * //
70
+ * // tags: {
71
+ * // fields: ["id", "created_at", "updated_at", "deleted_at", "value"],
72
+ * // },
73
+ * //
74
+ * // options: {
75
+ * // fields: [
76
+ * // "id",
77
+ * // "created_at",
78
+ * // "updated_at",
79
+ * // "deleted_at",
80
+ * // "title",
81
+ * // "product_id",
82
+ * // "metadata",
83
+ * // ],
84
+ * // values: {
85
+ * // fields: [
86
+ * // "id",
87
+ * // "created_at",
88
+ * // "updated_at",
89
+ * // "deleted_at",
90
+ * // "value",
91
+ * // "option_id",
92
+ * // "variant_id",
93
+ * // "metadata",
94
+ * // ],
95
+ * // },
96
+ * // },
97
+ * // },
98
+ * // }
99
+ */
100
+ function stringToRemoteQueryObject(_a) {
101
+ var _b, e_1, _c;
102
+ var _d;
103
+ var entryPoint = _a.entryPoint, variables = _a.variables, fields = _a.fields;
104
+ var remoteJoinerConfig = (_b = {},
105
+ _b[entryPoint] = {
106
+ fields: [],
107
+ },
108
+ _b);
109
+ if (variables) {
110
+ remoteJoinerConfig[entryPoint]["__args"] = variables;
111
+ }
112
+ try {
113
+ for (var fields_1 = __values(fields), fields_1_1 = fields_1.next(); !fields_1_1.done; fields_1_1 = fields_1.next()) {
114
+ var field = fields_1_1.value;
115
+ if (!field.includes(".")) {
116
+ remoteJoinerConfig[entryPoint]["fields"].push(field);
117
+ continue;
118
+ }
119
+ var fieldSegments = field.split(".");
120
+ var fieldProperty = fieldSegments.pop();
121
+ var deepConfigRef = fieldSegments.reduce(function (acc, curr) {
122
+ var _a;
123
+ (_a = acc[curr]) !== null && _a !== void 0 ? _a : (acc[curr] = {});
124
+ return acc[curr];
125
+ }, remoteJoinerConfig[entryPoint]);
126
+ (_d = deepConfigRef["fields"]) !== null && _d !== void 0 ? _d : (deepConfigRef["fields"] = []);
127
+ deepConfigRef["fields"].push(fieldProperty);
128
+ }
129
+ }
130
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
131
+ finally {
132
+ try {
133
+ if (fields_1_1 && !fields_1_1.done && (_c = fields_1.return)) _c.call(fields_1);
134
+ }
135
+ finally { if (e_1) throw e_1.error; }
136
+ }
137
+ return remoteJoinerConfig;
138
+ }
139
+ exports.stringToRemoteQueryObject = stringToRemoteQueryObject;
140
+ //# sourceMappingURL=string-to-remote-query-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-to-remote-query-object.js","sourceRoot":"","sources":["../../src/common/string-to-remote-query-object.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AACH,SAAgB,yBAAyB,CAAC,EAQzC;;;QAPC,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,MAAM,YAAA;IAMN,IAAM,kBAAkB;QACtB,GAAC,UAAU,IAAG;YACZ,MAAM,EAAE,EAAE;SACX;WACF,CAAA;IAED,IAAI,SAAS,EAAE;QACb,kBAAkB,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;KACrD;;QAED,KAAoB,IAAA,WAAA,SAAA,MAAM,CAAA,8BAAA,kDAAE;YAAvB,IAAM,KAAK,mBAAA;YACd,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBACxB,kBAAkB,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACpD,SAAQ;aACT;YAED,IAAM,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACtC,IAAM,aAAa,GAAG,aAAa,CAAC,GAAG,EAAE,CAAA;YAEzC,IAAM,aAAa,GAAG,aAAa,CAAC,MAAM,CAAC,UAAC,GAAG,EAAE,IAAI;;gBACnD,MAAA,GAAG,CAAC,IAAI,qCAAR,GAAG,CAAC,IAAI,IAAM,EAAE,EAAA;gBAChB,OAAO,GAAG,CAAC,IAAI,CAAC,CAAA;YAClB,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAA;YAElC,MAAA,aAAa,CAAC,QAAQ,qCAAtB,aAAa,CAAC,QAAQ,IAAM,EAAE,EAAA;YAC9B,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;SAC5C;;;;;;;;;IAED,OAAO,kBAAkB,CAAA;AAC3B,CAAC;AAtCD,8DAsCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/utils",
3
- "version": "1.10.1",
3
+ "version": "1.10.2-next-20230925165416",
4
4
  "description": "Medusa utilities functions shared by Medusa core and Modules",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "typescript": "^5.1.6"
28
28
  },
29
29
  "dependencies": {
30
- "@medusajs/types": "^1.11.1",
30
+ "@medusajs/types": "1.11.2-next-20230925165416",
31
31
  "@mikro-orm/core": "5.7.12",
32
32
  "@mikro-orm/migrations": "5.7.12",
33
33
  "@mikro-orm/postgresql": "5.7.12",