@medusajs/utils 0.0.2-next-20230323083446 → 0.0.2-rc.0
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/common/build-query.d.ts +31 -0
- package/dist/common/build-query.js +302 -0
- package/dist/common/build-query.js.map +1 -0
- package/dist/common/db-aware-column.d.ts +4 -0
- package/dist/common/db-aware-column.js +57 -0
- package/dist/common/db-aware-column.js.map +1 -0
- package/dist/common/errors.d.ts +56 -0
- package/dist/common/errors.js +73 -0
- package/dist/common/errors.js.map +1 -0
- package/dist/common/generate-entity-id.d.ts +6 -0
- package/dist/common/generate-entity-id.js +19 -0
- package/dist/common/generate-entity-id.js.map +1 -0
- package/dist/common/get-config-file.d.ts +12 -0
- package/dist/common/get-config-file.js +28 -0
- package/dist/common/get-config-file.js.map +1 -0
- package/dist/common/index.d.ts +15 -0
- package/dist/common/index.js +32 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/is-date.d.ts +1 -0
- package/dist/common/is-date.js +9 -0
- package/dist/common/is-date.js.map +1 -0
- package/dist/common/is-defined.d.ts +1 -0
- package/dist/common/is-defined.js +8 -0
- package/dist/common/is-defined.js.map +1 -0
- package/dist/common/is-email.d.ts +6 -0
- package/dist/common/is-email.js +19 -0
- package/dist/common/is-email.js.map +1 -0
- package/dist/common/is-object.d.ts +1 -0
- package/dist/common/is-object.js +8 -0
- package/dist/common/is-object.js.map +1 -0
- package/dist/common/is-string.d.ts +1 -0
- package/dist/common/is-string.js +8 -0
- package/dist/common/is-string.js.map +1 -0
- package/dist/common/medusa-container.d.ts +2 -0
- package/dist/common/medusa-container.js +40 -0
- package/dist/common/medusa-container.js.map +1 -0
- package/dist/common/models/base-entity.d.ts +8 -0
- package/dist/common/models/base-entity.js +36 -0
- package/dist/common/models/base-entity.js.map +1 -0
- package/dist/common/models/index.d.ts +2 -0
- package/dist/common/models/index.js +19 -0
- package/dist/common/models/index.js.map +1 -0
- package/dist/common/models/soft-deletable-entity.d.ts +4 -0
- package/dist/common/models/soft-deletable-entity.js +43 -0
- package/dist/common/models/soft-deletable-entity.js.map +1 -0
- package/dist/common/set-metadata.d.ts +9 -0
- package/dist/common/set-metadata.js +47 -0
- package/dist/common/set-metadata.js.map +1 -0
- package/dist/common/transaction-base-service.d.ts +25 -0
- package/dist/common/transaction-base-service.js +205 -0
- package/dist/common/transaction-base-service.js.map +1 -0
- package/dist/common/wrap-handler.d.ts +18 -0
- package/dist/common/wrap-handler.js +31 -0
- package/dist/common/wrap-handler.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +9 -5
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ExtendedFindConfig, FindConfig } from "@medusajs/types";
|
|
2
|
+
import { FindOperator, FindOptionsRelations, FindOptionsSelect, FindOptionsWhere } from "typeorm";
|
|
3
|
+
import { FindOptionsOrder } from "typeorm/find-options/FindOptionsOrder";
|
|
4
|
+
/**
|
|
5
|
+
* Used to build TypeORM queries.
|
|
6
|
+
* @param selector The selector
|
|
7
|
+
* @param config The config
|
|
8
|
+
* @return The QueryBuilderConfig
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildQuery<TWhereKeys extends object, TEntity = unknown>(selector: TWhereKeys, config?: FindConfig<TEntity>): ExtendedFindConfig<TEntity>;
|
|
11
|
+
/**
|
|
12
|
+
* Revert new object structure of find options to the legacy structure of previous version
|
|
13
|
+
* @example
|
|
14
|
+
* input: {
|
|
15
|
+
* test: {
|
|
16
|
+
* test1: true,
|
|
17
|
+
* test2: true,
|
|
18
|
+
* test3: {
|
|
19
|
+
* test4: true
|
|
20
|
+
* },
|
|
21
|
+
* },
|
|
22
|
+
* test2: true
|
|
23
|
+
* }
|
|
24
|
+
* output: ['test.test1', 'test.test2', 'test.test3.test4', 'test2']
|
|
25
|
+
* @param input
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildLegacyFieldsListFrom<TEntity>(input?: FindOptionsWhere<TEntity> | FindOptionsSelect<TEntity> | FindOptionsOrder<TEntity> | FindOptionsRelations<TEntity>): (keyof TEntity)[];
|
|
28
|
+
export declare function buildSelects<TEntity>(selectCollection: string[]): FindOptionsSelect<TEntity>;
|
|
29
|
+
export declare function buildRelations<TEntity>(relationCollection: string[]): FindOptionsRelations<TEntity>;
|
|
30
|
+
export declare function addOrderToSelect<TEntity>(order: FindOptionsOrder<TEntity>, select: FindOptionsSelect<TEntity>): void;
|
|
31
|
+
export declare function nullableValue(value: any): FindOperator<any>;
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.nullableValue = exports.addOrderToSelect = exports.buildRelations = exports.buildSelects = exports.buildLegacyFieldsListFrom = exports.buildQuery = void 0;
|
|
15
|
+
var typeorm_1 = require("typeorm");
|
|
16
|
+
var is_object_1 = require("./is-object");
|
|
17
|
+
/**
|
|
18
|
+
* Used to build TypeORM queries.
|
|
19
|
+
* @param selector The selector
|
|
20
|
+
* @param config The config
|
|
21
|
+
* @return The QueryBuilderConfig
|
|
22
|
+
*/
|
|
23
|
+
function buildQuery(selector, config) {
|
|
24
|
+
if (config === void 0) { config = {}; }
|
|
25
|
+
var query = {
|
|
26
|
+
where: buildWhere(selector),
|
|
27
|
+
};
|
|
28
|
+
if ("deleted_at" in selector) {
|
|
29
|
+
query.withDeleted = true;
|
|
30
|
+
}
|
|
31
|
+
if ("skip" in config) {
|
|
32
|
+
;
|
|
33
|
+
query.skip = config.skip;
|
|
34
|
+
}
|
|
35
|
+
if ("take" in config) {
|
|
36
|
+
;
|
|
37
|
+
query.take = config.take;
|
|
38
|
+
}
|
|
39
|
+
if (config.relations) {
|
|
40
|
+
query.relations = buildRelations(config.relations);
|
|
41
|
+
}
|
|
42
|
+
if (config.select) {
|
|
43
|
+
query.select = buildSelects(config.select);
|
|
44
|
+
}
|
|
45
|
+
if (config.order) {
|
|
46
|
+
query.order = buildOrder(config.order);
|
|
47
|
+
}
|
|
48
|
+
return query;
|
|
49
|
+
}
|
|
50
|
+
exports.buildQuery = buildQuery;
|
|
51
|
+
/**
|
|
52
|
+
* @param constraints
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const q = buildWhere(
|
|
56
|
+
* {
|
|
57
|
+
* id: "1234",
|
|
58
|
+
* test1: ["123", "12", "1"],
|
|
59
|
+
* test2: Not("this"),
|
|
60
|
+
* date: { gt: date },
|
|
61
|
+
* amount: { gt: 10 },
|
|
62
|
+
* },
|
|
63
|
+
*)
|
|
64
|
+
*
|
|
65
|
+
* // Output
|
|
66
|
+
* {
|
|
67
|
+
* id: "1234",
|
|
68
|
+
* test1: In(["123", "12", "1"]),
|
|
69
|
+
* test2: Not("this"),
|
|
70
|
+
* date: MoreThan(date),
|
|
71
|
+
* amount: MoreThan(10)
|
|
72
|
+
* }
|
|
73
|
+
*/
|
|
74
|
+
function buildWhere(constraints) {
|
|
75
|
+
var where = {};
|
|
76
|
+
var _loop_1 = function (key, value) {
|
|
77
|
+
if (value === undefined) {
|
|
78
|
+
return "continue";
|
|
79
|
+
}
|
|
80
|
+
if (value === null) {
|
|
81
|
+
where[key] = (0, typeorm_1.IsNull)();
|
|
82
|
+
return "continue";
|
|
83
|
+
}
|
|
84
|
+
if (value instanceof typeorm_1.FindOperator) {
|
|
85
|
+
where[key] = value;
|
|
86
|
+
return "continue";
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
where[key] = (0, typeorm_1.In)(value);
|
|
90
|
+
return "continue";
|
|
91
|
+
}
|
|
92
|
+
if (typeof value === "object") {
|
|
93
|
+
Object.entries(value).forEach(function (_a) {
|
|
94
|
+
var objectKey = _a[0], objectValue = _a[1];
|
|
95
|
+
switch (objectKey) {
|
|
96
|
+
case "lt":
|
|
97
|
+
where[key] = (0, typeorm_1.LessThan)(objectValue);
|
|
98
|
+
break;
|
|
99
|
+
case "gt":
|
|
100
|
+
where[key] = (0, typeorm_1.MoreThan)(objectValue);
|
|
101
|
+
break;
|
|
102
|
+
case "lte":
|
|
103
|
+
where[key] = (0, typeorm_1.LessThanOrEqual)(objectValue);
|
|
104
|
+
break;
|
|
105
|
+
case "gte":
|
|
106
|
+
where[key] = (0, typeorm_1.MoreThanOrEqual)(objectValue);
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
if (objectValue != undefined && typeof objectValue === "object") {
|
|
110
|
+
where[key] = buildWhere(objectValue);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
where[key] = value;
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
});
|
|
117
|
+
return "continue";
|
|
118
|
+
}
|
|
119
|
+
where[key] = value;
|
|
120
|
+
};
|
|
121
|
+
for (var _i = 0, _a = Object.entries(constraints); _i < _a.length; _i++) {
|
|
122
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
123
|
+
_loop_1(key, value);
|
|
124
|
+
}
|
|
125
|
+
return where;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Revert new object structure of find options to the legacy structure of previous version
|
|
129
|
+
* @example
|
|
130
|
+
* input: {
|
|
131
|
+
* test: {
|
|
132
|
+
* test1: true,
|
|
133
|
+
* test2: true,
|
|
134
|
+
* test3: {
|
|
135
|
+
* test4: true
|
|
136
|
+
* },
|
|
137
|
+
* },
|
|
138
|
+
* test2: true
|
|
139
|
+
* }
|
|
140
|
+
* output: ['test.test1', 'test.test2', 'test.test3.test4', 'test2']
|
|
141
|
+
* @param input
|
|
142
|
+
*/
|
|
143
|
+
function buildLegacyFieldsListFrom(input) {
|
|
144
|
+
if (input === void 0) { input = {}; }
|
|
145
|
+
if (!Object.keys(input).length) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
var output = new Set(Object.keys(input));
|
|
149
|
+
var _loop_2 = function (key) {
|
|
150
|
+
if (input[key] != undefined && typeof input[key] === "object") {
|
|
151
|
+
var deepRes = buildLegacyFieldsListFrom(input[key]);
|
|
152
|
+
var items = deepRes.reduce(function (acc, val) {
|
|
153
|
+
acc.push("".concat(key, ".").concat(val));
|
|
154
|
+
return acc;
|
|
155
|
+
}, []);
|
|
156
|
+
items.forEach(function (item) { return output.add(item); });
|
|
157
|
+
return "continue";
|
|
158
|
+
}
|
|
159
|
+
output.add(key);
|
|
160
|
+
};
|
|
161
|
+
for (var _i = 0, _a = Object.keys(input); _i < _a.length; _i++) {
|
|
162
|
+
var key = _a[_i];
|
|
163
|
+
_loop_2(key);
|
|
164
|
+
}
|
|
165
|
+
return Array.from(output);
|
|
166
|
+
}
|
|
167
|
+
exports.buildLegacyFieldsListFrom = buildLegacyFieldsListFrom;
|
|
168
|
+
function buildSelects(selectCollection) {
|
|
169
|
+
return buildRelationsOrSelect(selectCollection);
|
|
170
|
+
}
|
|
171
|
+
exports.buildSelects = buildSelects;
|
|
172
|
+
function buildRelations(relationCollection) {
|
|
173
|
+
return buildRelationsOrSelect(relationCollection);
|
|
174
|
+
}
|
|
175
|
+
exports.buildRelations = buildRelations;
|
|
176
|
+
function addOrderToSelect(order, select) {
|
|
177
|
+
var _a;
|
|
178
|
+
for (var _i = 0, _b = Object.keys(order); _i < _b.length; _i++) {
|
|
179
|
+
var orderBy = _b[_i];
|
|
180
|
+
if ((0, is_object_1.isObject)(order[orderBy])) {
|
|
181
|
+
select[orderBy] =
|
|
182
|
+
select[orderBy] && (0, is_object_1.isObject)(select[orderBy]) ? select[orderBy] : {};
|
|
183
|
+
addOrderToSelect(order[orderBy], select[orderBy]);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
select[orderBy] = (0, is_object_1.isObject)(select[orderBy])
|
|
187
|
+
? __assign(__assign({}, select[orderBy]), (_a = { id: true }, _a[orderBy] = true, _a)) : true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.addOrderToSelect = addOrderToSelect;
|
|
191
|
+
/**
|
|
192
|
+
* Convert an collection of dot string into a nested object
|
|
193
|
+
* @example
|
|
194
|
+
* input: [
|
|
195
|
+
* order,
|
|
196
|
+
* order.items,
|
|
197
|
+
* order.swaps,
|
|
198
|
+
* order.swaps.additional_items,
|
|
199
|
+
* order.discounts,
|
|
200
|
+
* order.discounts.rule,
|
|
201
|
+
* order.claims,
|
|
202
|
+
* order.claims.additional_items,
|
|
203
|
+
* additional_items,
|
|
204
|
+
* additional_items.variant,
|
|
205
|
+
* return_order,
|
|
206
|
+
* return_order.items,
|
|
207
|
+
* return_order.shipping_method,
|
|
208
|
+
* return_order.shipping_method.tax_lines
|
|
209
|
+
* ]
|
|
210
|
+
* output: {
|
|
211
|
+
* "order": {
|
|
212
|
+
* "items": true,
|
|
213
|
+
* "swaps": {
|
|
214
|
+
* "additional_items": true
|
|
215
|
+
* },
|
|
216
|
+
* "discounts": {
|
|
217
|
+
* "rule": true
|
|
218
|
+
* },
|
|
219
|
+
* "claims": {
|
|
220
|
+
* "additional_items": true
|
|
221
|
+
* }
|
|
222
|
+
* },
|
|
223
|
+
* "additional_items": {
|
|
224
|
+
* "variant": true
|
|
225
|
+
* },
|
|
226
|
+
* "return_order": {
|
|
227
|
+
* "items": true,
|
|
228
|
+
* "shipping_method": {
|
|
229
|
+
* "tax_lines": true
|
|
230
|
+
* }
|
|
231
|
+
* }
|
|
232
|
+
* }
|
|
233
|
+
* @param collection
|
|
234
|
+
*/
|
|
235
|
+
function buildRelationsOrSelect(collection) {
|
|
236
|
+
var _a;
|
|
237
|
+
var output = {};
|
|
238
|
+
for (var _i = 0, collection_1 = collection; _i < collection_1.length; _i++) {
|
|
239
|
+
var relation = collection_1[_i];
|
|
240
|
+
if (relation.indexOf(".") > -1) {
|
|
241
|
+
var nestedRelations = relation.split(".");
|
|
242
|
+
var parent_1 = output;
|
|
243
|
+
while (nestedRelations.length > 1) {
|
|
244
|
+
var nestedRelation = nestedRelations.shift();
|
|
245
|
+
parent_1 = parent_1[nestedRelation] =
|
|
246
|
+
parent_1[nestedRelation] !== true &&
|
|
247
|
+
typeof parent_1[nestedRelation] === "object"
|
|
248
|
+
? parent_1[nestedRelation]
|
|
249
|
+
: {};
|
|
250
|
+
}
|
|
251
|
+
parent_1[nestedRelations[0]] = true;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
output[relation] = (_a = output[relation]) !== null && _a !== void 0 ? _a : true;
|
|
255
|
+
}
|
|
256
|
+
return output;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Convert an order of dot string into a nested object
|
|
260
|
+
* @example
|
|
261
|
+
* input: { id: "ASC", "items.title": "ASC", "items.variant.title": "ASC" }
|
|
262
|
+
* output: {
|
|
263
|
+
* "id": "ASC",
|
|
264
|
+
* "items": {
|
|
265
|
+
* "id": "ASC",
|
|
266
|
+
* "variant": {
|
|
267
|
+
* "title": "ASC"
|
|
268
|
+
* }
|
|
269
|
+
* },
|
|
270
|
+
* }
|
|
271
|
+
* @param orderBy
|
|
272
|
+
*/
|
|
273
|
+
function buildOrder(orderBy) {
|
|
274
|
+
var _a;
|
|
275
|
+
var output = {};
|
|
276
|
+
var orderKeys = Object.keys(orderBy);
|
|
277
|
+
for (var _i = 0, orderKeys_1 = orderKeys; _i < orderKeys_1.length; _i++) {
|
|
278
|
+
var order = orderKeys_1[_i];
|
|
279
|
+
if (order.indexOf(".") > -1) {
|
|
280
|
+
var nestedOrder = order.split(".");
|
|
281
|
+
var parent_2 = output;
|
|
282
|
+
while (nestedOrder.length > 1) {
|
|
283
|
+
var nestedRelation = nestedOrder.shift();
|
|
284
|
+
parent_2 = parent_2[nestedRelation] = (_a = parent_2[nestedRelation]) !== null && _a !== void 0 ? _a : {};
|
|
285
|
+
}
|
|
286
|
+
parent_2[nestedOrder[0]] = orderBy[order];
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
output[order] = orderBy[order];
|
|
290
|
+
}
|
|
291
|
+
return output;
|
|
292
|
+
}
|
|
293
|
+
function nullableValue(value) {
|
|
294
|
+
if (value === null) {
|
|
295
|
+
return (0, typeorm_1.IsNull)();
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
return value;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.nullableValue = nullableValue;
|
|
302
|
+
//# sourceMappingURL=build-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-query.js","sourceRoot":"","sources":["../../src/common/build-query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,mCAYgB;AAEhB,yCAAsC;AAEtC;;;;;GAKG;AACH,SAAgB,UAAU,CACxB,QAAoB,EACpB,MAAgC;IAAhC,uBAAA,EAAA,WAAgC;IAEhC,IAAM,KAAK,GAAgC;QACzC,KAAK,EAAE,UAAU,CAAsB,QAAQ,CAAC;KACjD,CAAA;IAED,IAAI,YAAY,IAAI,QAAQ,EAAE;QAC5B,KAAK,CAAC,WAAW,GAAG,IAAI,CAAA;KACzB;IAED,IAAI,MAAM,IAAI,MAAM,EAAE;QACpB,CAAC;QAAC,KAAkC,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;KACxD;IAED,IAAI,MAAM,IAAI,MAAM,EAAE;QACpB,CAAC;QAAC,KAAkC,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;KACxD;IAED,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,KAAK,CAAC,SAAS,GAAG,cAAc,CAAU,MAAM,CAAC,SAAS,CAAC,CAAA;KAC5D;IAED,IAAI,M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AED;;;;;;;;;;;;;;GAcG;AACH,SAAS,UAAU,CAAU,OAE5B;;IACC,IAAM,MAAM,GAA8B,EAAE,CAAA;IAE5C,IAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAEtC,KAAoB,UAAS,EAAT,uBAAS,EAAT,uBAAS,EAAT,IAAS,EAAE;QAA1B,IAAM,KAAK,kBAAA;QACd,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;YAC3B,IAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAEpC,IAAI,QAAM,GAAG,MAAM,CAAA;YAEnB,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC7B,IAAM,cAAc,GAAG,WAAW,CAAC,KAAK,EAAY,CAAA;gBACpD,QAAM,GAAG,QAAM,CAAC,cAAc,CAAC,GAAG,MAAA,QAAM,CAAC,cAAc,CAAC,mCAAI,EAAE,CAAA;aAC/D;YAED,QAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;YAEvC,SAAQ;SACT;QAED,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;KAC/B;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAgB,aAAa,CAAC,KAAU;IACtC,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,IAAA,gBAAM,GAAE,CAAA;KAChB;SAAM;QACL,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAND,sCAMC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ColumnOptions, ColumnType } from "typeorm";
|
|
2
|
+
export declare function resolveDbType(pgSqlType: ColumnType): ColumnType;
|
|
3
|
+
export declare function resolveDbGenerationStrategy(pgSqlType: "increment" | "uuid" | "rowid"): "increment" | "uuid" | "rowid";
|
|
4
|
+
export declare function DbAwareColumn(columnOptions: ColumnOptions): PropertyDecorator;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DbAwareColumn = exports.resolveDbGenerationStrategy = exports.resolveDbType = void 0;
|
|
7
|
+
var path_1 = __importDefault(require("path"));
|
|
8
|
+
var typeorm_1 = require("typeorm");
|
|
9
|
+
var get_config_file_1 = __importDefault(require("./get-config-file"));
|
|
10
|
+
var pgSqliteTypeMapping = {
|
|
11
|
+
increment: "rowid",
|
|
12
|
+
timestamptz: "datetime",
|
|
13
|
+
jsonb: "simple-json",
|
|
14
|
+
enum: "text",
|
|
15
|
+
};
|
|
16
|
+
var pgSqliteGenerationMapping = {
|
|
17
|
+
increment: "rowid",
|
|
18
|
+
};
|
|
19
|
+
var dbType;
|
|
20
|
+
function resolveDbType(pgSqlType) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (!dbType) {
|
|
23
|
+
var configModule = (0, get_config_file_1.default)(path_1.default.resolve("."), "medusa-config").configModule;
|
|
24
|
+
dbType = ((_a = configModule === null || configModule === void 0 ? void 0 : configModule.projectConfig) === null || _a === void 0 ? void 0 : _a.database_type) || "postgres";
|
|
25
|
+
}
|
|
26
|
+
if (dbType === "sqlite" && pgSqlType in pgSqliteTypeMapping) {
|
|
27
|
+
return pgSqliteTypeMapping[pgSqlType.toString()];
|
|
28
|
+
}
|
|
29
|
+
return pgSqlType;
|
|
30
|
+
}
|
|
31
|
+
exports.resolveDbType = resolveDbType;
|
|
32
|
+
function resolveDbGenerationStrategy(pgSqlType) {
|
|
33
|
+
var _a;
|
|
34
|
+
if (!dbType) {
|
|
35
|
+
var configModule = (0, get_config_file_1.default)(path_1.default.resolve("."), "medusa-config").configModule;
|
|
36
|
+
dbType = ((_a = configModule === null || configModule === void 0 ? void 0 : configModule.projectConfig) === null || _a === void 0 ? void 0 : _a.database_type) || "postgres";
|
|
37
|
+
}
|
|
38
|
+
if (dbType === "sqlite" && pgSqlType in pgSqliteTypeMapping) {
|
|
39
|
+
return pgSqliteGenerationMapping[pgSqlType];
|
|
40
|
+
}
|
|
41
|
+
return pgSqlType;
|
|
42
|
+
}
|
|
43
|
+
exports.resolveDbGenerationStrategy = resolveDbGenerationStrategy;
|
|
44
|
+
function DbAwareColumn(columnOptions) {
|
|
45
|
+
var pre = columnOptions.type;
|
|
46
|
+
if (columnOptions.type) {
|
|
47
|
+
columnOptions.type = resolveDbType(columnOptions.type);
|
|
48
|
+
}
|
|
49
|
+
if (pre === "jsonb" && pre !== columnOptions.type) {
|
|
50
|
+
if ("default" in columnOptions) {
|
|
51
|
+
columnOptions.default = JSON.stringify(columnOptions.default);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return (0, typeorm_1.Column)(columnOptions);
|
|
55
|
+
}
|
|
56
|
+
exports.DbAwareColumn = DbAwareColumn;
|
|
57
|
+
//# sourceMappingURL=db-aware-column.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-aware-column.js","sourceRoot":"","sources":["../../src/common/db-aware-column.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAuB;AACvB,mCAA2D;AAC3D,sEAA6C;AAE7C,IAAM,mBAAmB,GAAkC;IACzD,SAAS,EAAE,OAAO;IAClB,WAAW,EAAE,UAAU;IACvB,KAAK,EAAE,aAAa;IACpB,IAAI,EAAE,MAAM;CACb,CAAA;AAED,IAAM,yBAAyB,GAE3B;IACF,SAAS,EAAE,OAAO;CACnB,CAAA;AAED,IAAI,MAAc,CAAA;AAClB,SAAgB,aAAa,CAAC,SAAqB;;IACjD,IAAI,CAAC,MAAM,EAAE;QACH,IAAA,YAAY,GAAK,IAAA,yBAAa,EACpC,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EACjB,e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bD,sCAaC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef MedusaErrorType
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
export declare const MedusaErrorTypes: {
|
|
6
|
+
/** Errors stemming from the database */
|
|
7
|
+
DB_ERROR: string;
|
|
8
|
+
DUPLICATE_ERROR: string;
|
|
9
|
+
INVALID_ARGUMENT: string;
|
|
10
|
+
INVALID_DATA: string;
|
|
11
|
+
UNAUTHORIZED: string;
|
|
12
|
+
NOT_FOUND: string;
|
|
13
|
+
NOT_ALLOWED: string;
|
|
14
|
+
UNEXPECTED_STATE: string;
|
|
15
|
+
CONFLICT: string;
|
|
16
|
+
PAYMENT_AUTHORIZATION_ERROR: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const MedusaErrorCodes: {
|
|
19
|
+
INSUFFICIENT_INVENTORY: string;
|
|
20
|
+
CART_INCOMPATIBLE_STATE: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Standardized error to be used across Medusa project.
|
|
24
|
+
* @extends Error
|
|
25
|
+
*/
|
|
26
|
+
export declare class MedusaError extends Error {
|
|
27
|
+
type: string;
|
|
28
|
+
message: string;
|
|
29
|
+
code?: string;
|
|
30
|
+
date: Date;
|
|
31
|
+
static Types: {
|
|
32
|
+
/** Errors stemming from the database */
|
|
33
|
+
DB_ERROR: string;
|
|
34
|
+
DUPLICATE_ERROR: string;
|
|
35
|
+
INVALID_ARGUMENT: string;
|
|
36
|
+
INVALID_DATA: string;
|
|
37
|
+
UNAUTHORIZED: string;
|
|
38
|
+
NOT_FOUND: string;
|
|
39
|
+
NOT_ALLOWED: string;
|
|
40
|
+
UNEXPECTED_STATE: string;
|
|
41
|
+
CONFLICT: string;
|
|
42
|
+
PAYMENT_AUTHORIZATION_ERROR: string;
|
|
43
|
+
};
|
|
44
|
+
static Codes: {
|
|
45
|
+
INSUFFICIENT_INVENTORY: string;
|
|
46
|
+
CART_INCOMPATIBLE_STATE: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Creates a standardized error to be used across Medusa project.
|
|
50
|
+
* @param {string} type - type of error
|
|
51
|
+
* @param {string} message - message to go along with error
|
|
52
|
+
* @param {string} code - code of error
|
|
53
|
+
* @param {Array} params - params
|
|
54
|
+
*/
|
|
55
|
+
constructor(type: string, message: string, code?: string, ...params: any);
|
|
56
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.MedusaError = exports.MedusaErrorCodes = exports.MedusaErrorTypes = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* @typedef MedusaErrorType
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
exports.MedusaErrorTypes = {
|
|
24
|
+
/** Errors stemming from the database */
|
|
25
|
+
DB_ERROR: "database_error",
|
|
26
|
+
DUPLICATE_ERROR: "duplicate_error",
|
|
27
|
+
INVALID_ARGUMENT: "invalid_argument",
|
|
28
|
+
INVALID_DATA: "invalid_data",
|
|
29
|
+
UNAUTHORIZED: "unauthorized",
|
|
30
|
+
NOT_FOUND: "not_found",
|
|
31
|
+
NOT_ALLOWED: "not_allowed",
|
|
32
|
+
UNEXPECTED_STATE: "unexpected_state",
|
|
33
|
+
CONFLICT: "conflict",
|
|
34
|
+
PAYMENT_AUTHORIZATION_ERROR: "payment_authorization_error",
|
|
35
|
+
};
|
|
36
|
+
exports.MedusaErrorCodes = {
|
|
37
|
+
INSUFFICIENT_INVENTORY: "insufficient_inventory",
|
|
38
|
+
CART_INCOMPATIBLE_STATE: "cart_incompatible_state",
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Standardized error to be used across Medusa project.
|
|
42
|
+
* @extends Error
|
|
43
|
+
*/
|
|
44
|
+
var MedusaError = /** @class */ (function (_super) {
|
|
45
|
+
__extends(MedusaError, _super);
|
|
46
|
+
/**
|
|
47
|
+
* Creates a standardized error to be used across Medusa project.
|
|
48
|
+
* @param {string} type - type of error
|
|
49
|
+
* @param {string} message - message to go along with error
|
|
50
|
+
* @param {string} code - code of error
|
|
51
|
+
* @param {Array} params - params
|
|
52
|
+
*/
|
|
53
|
+
function MedusaError(type, message, code) {
|
|
54
|
+
var params = [];
|
|
55
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
|
56
|
+
params[_i - 3] = arguments[_i];
|
|
57
|
+
}
|
|
58
|
+
var _this = _super.apply(this, params) || this;
|
|
59
|
+
if (Error.captureStackTrace) {
|
|
60
|
+
Error.captureStackTrace(_this, MedusaError);
|
|
61
|
+
}
|
|
62
|
+
_this.type = type;
|
|
63
|
+
_this.code = code;
|
|
64
|
+
_this.message = message;
|
|
65
|
+
_this.date = new Date();
|
|
66
|
+
return _this;
|
|
67
|
+
}
|
|
68
|
+
MedusaError.Types = exports.MedusaErrorTypes;
|
|
69
|
+
MedusaError.Codes = exports.MedusaErrorCodes;
|
|
70
|
+
return MedusaError;
|
|
71
|
+
}(Error));
|
|
72
|
+
exports.MedusaError = MedusaError;
|
|
73
|
+
//# sourceMappingURL=errors.js.map
|
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defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateEntityId = void 0;
|
|
4
|
+
var ulid_1 = require("ulid");
|
|
5
|
+
/**
|
|
6
|
+
* Generate a composed id based on the input parameters and return either the is if it exists or the generated one.
|
|
7
|
+
* @param idProperty
|
|
8
|
+
* @param prefix
|
|
9
|
+
*/
|
|
10
|
+
function generateEntityId(idProperty, prefix) {
|
|
11
|
+
if (idProperty) {
|
|
12
|
+
return idProperty;
|
|
13
|
+
}
|
|
14
|
+
var id = (0, ulid_1.ulid)();
|
|
15
|
+
prefix = prefix ? "".concat(prefix, "_") : "";
|
|
16
|
+
return "".concat(prefix).concat(id);
|
|
17
|
+
}
|
|
18
|
+
exports.generateEntityId = generateEntityId;
|
|
19
|
+
//# sourceMappingURL=generate-entity-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-entity-id.js","sourceRoot":"","sources":["../../src/common/generate-entity-id.ts"],"names":[],"mappings":";;;AAAA,6BAA2B;AAE3B;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,UAAkB,EAAE,MAAe;IAClE,IAAI,UAAU,EAAE;QACd,OAAO,UAAU,CAAA;KAClB;IAED,IAAM,EAAE,GAAG,IAAA,WAAI,GAAE,CAAA;IACjB,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,UAAG,MAAM,MAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IACnC,OAAO,UAAG,MAAM,SAAG,EAAE,CAAE,CAAA;AACzB,CAAC;AARD,4CAQC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attempts to resolve the config file in a given root directory.
|
|
3
|
+
* @param {string} rootDir - the directory to find the config file in.
|
|
4
|
+
* @param {string} configName - the name of the config file.
|
|
5
|
+
* @return {object} an object containing the config module and its path as well as an error property if the config couldn't be loaded.
|
|
6
|
+
*/
|
|
7
|
+
declare function getConfigFile<TConfig = unknown>(rootDir: string, configName: string): {
|
|
8
|
+
configModule: TConfig;
|
|
9
|
+
configFilePath: string;
|
|
10
|
+
error?: any;
|
|
11
|
+
};
|
|
12
|
+
export default getConfigFile;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var path_1 = require("path");
|
|
4
|
+
/**
|
|
5
|
+
* Attempts to resolve the config file in a given root directory.
|
|
6
|
+
* @param {string} rootDir - the directory to find the config file in.
|
|
7
|
+
* @param {string} configName - the name of the config file.
|
|
8
|
+
* @return {object} an object containing the config module and its path as well as an error property if the config couldn't be loaded.
|
|
9
|
+
*/
|
|
10
|
+
function getConfigFile(rootDir, configName) {
|
|
11
|
+
var configPath = (0, path_1.join)(rootDir, configName);
|
|
12
|
+
var configFilePath = "";
|
|
13
|
+
var configModule;
|
|
14
|
+
var err;
|
|
15
|
+
try {
|
|
16
|
+
configFilePath = require.resolve(configPath);
|
|
17
|
+
configModule = require(configFilePath);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
err = e;
|
|
21
|
+
}
|
|
22
|
+
if (configModule && typeof configModule.default === "object") {
|
|
23
|
+
configModule = configModule.default;
|
|
24
|
+
}
|
|
25
|
+
return { configModule: configModule, configFilePath: configFilePath, error: err };
|
|
26
|
+
}
|
|
27
|
+
exports.default = getConfigFile;
|
|
28
|
+
//# sourceMappingURL=get-config-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-config-file.js","sourceRoot":"","sources":["../../src/common/get-config-file.ts"],"names":[],"mappings":";;AAAA,6BAA2B;AAE3B;;;;;GAKG;AACH,SAAS,aAAa,CACpB,OAAe,EACf,UAAkB;IAElB,IAAM,UAAU,GAAG,IAAA,WAAI,EAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IAC5C,IAAI,cAAc,GAAG,EAAE,CAAA;IACvB,IAAI,YAAY,CAAA;IAChB,IAAI,GAAG,CAAA;IAEP,IAAI;QACF,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAC5C,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;KACvC;IAAC,OAAO,CAAC,EAAE;QACV,GAAG,GAAG,CAAC,CAAA;KACR;IAED,IAAI,YAAY,IAAI,OAAO,YAAY,CAAC,OAAO,KAAK,QAAQ,EAAE;QAC5D,YAAY,GAAG,YAAY,CAAC,OAAO,CAAA;KACpC;IAED,OAAO,EAAE,YAAY,cAAA,EAAE,cAAc,gBAAA,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;AACrD,CAAC;AAED,kBAAe,aAAa,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./build-query";
|
|
2
|
+
export * from "./db-aware-column";
|
|
3
|
+
export * from "./errors";
|
|
4
|
+
export * from "./generate-entity-id";
|
|
5
|
+
export * from "./get-config-file";
|
|
6
|
+
export * from "./is-date";
|
|
7
|
+
export * from "./is-defined";
|
|
8
|
+
export * from "./is-email";
|
|
9
|
+
export * from "./is-object";
|
|
10
|
+
export * from "./is-string";
|
|
11
|
+
export * from "./medusa-container";
|
|
12
|
+
export * from "./models";
|
|
13
|
+
export * from "./set-metadata";
|
|
14
|
+
export * from "./transaction-base-service";
|
|
15
|
+
export * from "./wrap-handler";
|