@medusajs/utils
Advanced tools
Comparing version 1.9.2-next-20230629132216 to 1.9.2-next-20230629133602
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -24,3 +40,3 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
var srcFiles = glob_1.default.sync(path_1.default.join(directory, "src", "**/*.{ts,tsx,js,jsx}")); | ||
var files = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], adminFiles, true), onboardingFiles, true), typeFiles, true), srcFiles, true); | ||
var files = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(adminFiles), false), __read(onboardingFiles), false), __read(typeFiles), false), __read(srcFiles), false); | ||
files.forEach(function (file) { | ||
@@ -27,0 +43,0 @@ return fs_1.default.rmSync(file, { |
"use strict"; | ||
// Those utils are used in a typeorm context and we can't be sure that they can be used elsewhere | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -58,21 +69,31 @@ exports.buildOrder = exports.buildRelations = exports.buildSelects = void 0; | ||
function buildRelationsOrSelect(collection) { | ||
var _a; | ||
var e_1, _a; | ||
var _b; | ||
var output = {}; | ||
for (var _i = 0, collection_1 = collection; _i < collection_1.length; _i++) { | ||
var relation = collection_1[_i]; | ||
if (relation.indexOf(".") > -1) { | ||
var nestedRelations = relation.split("."); | ||
var parent_1 = output; | ||
while (nestedRelations.length > 1) { | ||
var nestedRelation = nestedRelations.shift(); | ||
parent_1 = parent_1[nestedRelation] = (parent_1[nestedRelation] !== true && | ||
typeof parent_1[nestedRelation] === "object" | ||
? parent_1[nestedRelation] | ||
: {}); | ||
try { | ||
for (var collection_1 = __values(collection), collection_1_1 = collection_1.next(); !collection_1_1.done; collection_1_1 = collection_1.next()) { | ||
var relation = collection_1_1.value; | ||
if (relation.indexOf(".") > -1) { | ||
var nestedRelations = relation.split("."); | ||
var parent_1 = output; | ||
while (nestedRelations.length > 1) { | ||
var nestedRelation = nestedRelations.shift(); | ||
parent_1 = parent_1[nestedRelation] = (parent_1[nestedRelation] !== true && | ||
typeof parent_1[nestedRelation] === "object" | ||
? parent_1[nestedRelation] | ||
: {}); | ||
} | ||
parent_1[nestedRelations[0]] = true; | ||
continue; | ||
} | ||
parent_1[nestedRelations[0]] = true; | ||
continue; | ||
output[relation] = (_b = output[relation]) !== null && _b !== void 0 ? _b : true; | ||
} | ||
output[relation] = (_a = output[relation]) !== null && _a !== void 0 ? _a : true; | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (collection_1_1 && !collection_1_1.done && (_a = collection_1.return)) _a.call(collection_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return output; | ||
@@ -96,19 +117,29 @@ } | ||
function buildOrder(orderBy) { | ||
var _a; | ||
var e_2, _a; | ||
var _b; | ||
var output = {}; | ||
var orderKeys = Object.keys(orderBy); | ||
for (var _i = 0, orderKeys_1 = orderKeys; _i < orderKeys_1.length; _i++) { | ||
var order = orderKeys_1[_i]; | ||
if (order.indexOf(".") > -1) { | ||
var nestedOrder = order.split("."); | ||
var parent_2 = output; | ||
while (nestedOrder.length > 1) { | ||
var nestedRelation = nestedOrder.shift(); | ||
parent_2 = (_a = parent_2[nestedRelation]) !== null && _a !== void 0 ? _a : (parent_2[nestedRelation] = {}); | ||
try { | ||
for (var orderKeys_1 = __values(orderKeys), orderKeys_1_1 = orderKeys_1.next(); !orderKeys_1_1.done; orderKeys_1_1 = orderKeys_1.next()) { | ||
var order = orderKeys_1_1.value; | ||
if (order.indexOf(".") > -1) { | ||
var nestedOrder = order.split("."); | ||
var parent_2 = output; | ||
while (nestedOrder.length > 1) { | ||
var nestedRelation = nestedOrder.shift(); | ||
parent_2 = (_b = parent_2[nestedRelation]) !== null && _b !== void 0 ? _b : (parent_2[nestedRelation] = {}); | ||
} | ||
parent_2[nestedOrder[0]] = orderBy[order]; | ||
continue; | ||
} | ||
parent_2[nestedOrder[0]] = orderBy[order]; | ||
continue; | ||
output[order] = orderBy[order]; | ||
} | ||
output[order] = orderBy[order]; | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (orderKeys_1_1 && !orderKeys_1_1.done && (_a = orderKeys_1.return)) _a.call(orderKeys_1); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
return output; | ||
@@ -115,0 +146,0 @@ } |
@@ -17,2 +17,27 @@ "use strict"; | ||
})(); | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -59,3 +84,3 @@ exports.MedusaError = exports.MedusaErrorCodes = exports.MedusaErrorTypes = void 0; | ||
} | ||
var _this = _super.apply(this, params) || this; | ||
var _this = _super.apply(this, __spreadArray([], __read(params), false)) || this; | ||
if (Error.captureStackTrace) { | ||
@@ -62,0 +87,0 @@ Error.captureStackTrace(_this, MedusaError); |
@@ -5,2 +5,3 @@ export * from "./build-query"; | ||
export * from "./get-config-file"; | ||
export * from "./handle-postgres-database-error"; | ||
export * from "./is-date"; | ||
@@ -21,3 +22,4 @@ export * from "./is-defined"; | ||
export * from "./stringify-circular"; | ||
export * from "./build-query"; | ||
export * from "./handle-postgres-database-error"; | ||
export * from "./to-kebab-case"; | ||
export * from "./to-pascal-case"; | ||
export * from "./wrap-handler"; |
@@ -21,2 +21,3 @@ "use strict"; | ||
__exportStar(require("./get-config-file"), exports); | ||
__exportStar(require("./handle-postgres-database-error"), exports); | ||
__exportStar(require("./is-date"), exports); | ||
@@ -37,4 +38,5 @@ __exportStar(require("./is-defined"), exports); | ||
__exportStar(require("./stringify-circular"), exports); | ||
__exportStar(require("./build-query"), exports); | ||
__exportStar(require("./handle-postgres-database-error"), exports); | ||
__exportStar(require("./to-kebab-case"), exports); | ||
__exportStar(require("./to-pascal-case"), exports); | ||
__exportStar(require("./wrap-handler"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,4 @@ /** | ||
* @example | ||
* input: { | ||
* // With `includeTruePropertiesOnly` default value set to false | ||
* const result = objectToStringPath({ | ||
* test: { | ||
@@ -15,6 +16,29 @@ * test1: true, | ||
* test2: true | ||
* } | ||
* output: ['test.test1', 'test.test2', 'test.test3.test4', 'test2'] | ||
* @param input | ||
* }) | ||
* console.log(result) | ||
* // output: ['test', 'test.test1', 'test.test2', 'test.test3', 'test.test3.test4', 'test2'] | ||
* | ||
* @example | ||
* // With `includeTruePropertiesOnly` set to true | ||
* const result = objectToStringPath({ | ||
* test: { | ||
* test1: true, | ||
* test2: true, | ||
* test3: { | ||
* test4: true | ||
* }, | ||
* }, | ||
* test2: true | ||
* }, { | ||
* includeTruePropertiesOnly: true | ||
* }) | ||
* console.log(result) | ||
* // output: ['test.test1', 'test.test2', 'test.test3.test4', 'test2'] | ||
* | ||
* @param {InputObject} input | ||
* @param {boolean} includeParentPropertyFields If set to true (example 1), all properties will be included as well as the parents, | ||
* otherwise (example 2) all properties path set to true will included, excluded the parents | ||
*/ | ||
export declare function objectToStringPath(input?: object): string[]; | ||
export declare function objectToStringPath(input?: object, { includeParentPropertyFields }?: { | ||
includeParentPropertyFields: boolean; | ||
}): string[]; |
"use strict"; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -9,3 +20,4 @@ exports.objectToStringPath = void 0; | ||
* @example | ||
* input: { | ||
* // With `includeTruePropertiesOnly` default value set to false | ||
* const result = objectToStringPath({ | ||
* test: { | ||
@@ -19,15 +31,44 @@ * test1: true, | ||
* test2: true | ||
* } | ||
* output: ['test.test1', 'test.test2', 'test.test3.test4', 'test2'] | ||
* @param input | ||
* }) | ||
* console.log(result) | ||
* // output: ['test', 'test.test1', 'test.test2', 'test.test3', 'test.test3.test4', 'test2'] | ||
* | ||
* @example | ||
* // With `includeTruePropertiesOnly` set to true | ||
* const result = objectToStringPath({ | ||
* test: { | ||
* test1: true, | ||
* test2: true, | ||
* test3: { | ||
* test4: true | ||
* }, | ||
* }, | ||
* test2: true | ||
* }, { | ||
* includeTruePropertiesOnly: true | ||
* }) | ||
* console.log(result) | ||
* // output: ['test.test1', 'test.test2', 'test.test3.test4', 'test2'] | ||
* | ||
* @param {InputObject} input | ||
* @param {boolean} includeParentPropertyFields If set to true (example 1), all properties will be included as well as the parents, | ||
* otherwise (example 2) all properties path set to true will included, excluded the parents | ||
*/ | ||
function objectToStringPath(input) { | ||
function objectToStringPath(input, _a) { | ||
var e_1, _b; | ||
if (input === void 0) { input = {}; } | ||
var _c = _a === void 0 ? { | ||
includeParentPropertyFields: true, | ||
} : _a, includeParentPropertyFields = _c.includeParentPropertyFields; | ||
if (!(0, is_object_1.isObject)(input) || !Object.keys(input).length) { | ||
return []; | ||
} | ||
var output = new Set(Object.keys(input)); | ||
var output = includeParentPropertyFields | ||
? new Set(Object.keys(input)) | ||
: new Set(); | ||
var _loop_1 = function (key) { | ||
if (input[key] != undefined && typeof input[key] === "object") { | ||
var deepRes = objectToStringPath(input[key]); | ||
if ((0, is_object_1.isObject)(input[key])) { | ||
var deepRes = objectToStringPath(input[key], { | ||
includeParentPropertyFields: includeParentPropertyFields, | ||
}); | ||
var items = deepRes.reduce(function (acc, val) { | ||
@@ -40,8 +81,19 @@ acc.push("".concat(key, ".").concat(val)); | ||
} | ||
output.add(key); | ||
if ((0, is_object_1.isObject)(key) || input[key] === true) { | ||
output.add(key); | ||
} | ||
}; | ||
for (var _i = 0, _a = Object.keys(input); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
_loop_1(key); | ||
try { | ||
for (var _d = __values(Object.keys(input)), _e = _d.next(); !_e.done; _e = _d.next()) { | ||
var key = _e.value; | ||
_loop_1(key); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_e && !_e.done && (_b = _d.return)) _b.call(_d); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return Array.from(output); | ||
@@ -48,0 +100,0 @@ } |
@@ -13,2 +13,29 @@ "use strict"; | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -24,23 +51,33 @@ exports.setMetadata = void 0; | ||
function setMetadata(obj, metadata) { | ||
var e_1, _a; | ||
var existing = obj.metadata || {}; | ||
var newData = {}; | ||
for (var _i = 0, _a = Object.entries(metadata); _i < _a.length; _i++) { | ||
var _b = _a[_i], key = _b[0], value = _b[1]; | ||
if (typeof key !== "string") { | ||
throw new errors_1.MedusaError(errors_1.MedusaError.Types.INVALID_ARGUMENT, "Key type is invalid. Metadata keys must be strings"); | ||
} | ||
/** | ||
* We reserve the empty string as a way to delete a key. | ||
* If the value is an empty string, we don't | ||
* set it, and if it exists in the existing metadata, we | ||
* unset the field. | ||
*/ | ||
if (value === "") { | ||
if (key in existing) { | ||
delete existing[key]; | ||
try { | ||
for (var _b = __values(Object.entries(metadata)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read(_c.value, 2), key = _d[0], value = _d[1]; | ||
if (typeof key !== "string") { | ||
throw new errors_1.MedusaError(errors_1.MedusaError.Types.INVALID_ARGUMENT, "Key type is invalid. Metadata keys must be strings"); | ||
} | ||
continue; | ||
/** | ||
* We reserve the empty string as a way to delete a key. | ||
* If the value is an empty string, we don't | ||
* set it, and if it exists in the existing metadata, we | ||
* unset the field. | ||
*/ | ||
if (value === "") { | ||
if (key in existing) { | ||
delete existing[key]; | ||
} | ||
continue; | ||
} | ||
newData[key] = value; | ||
} | ||
newData[key] = value; | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return __assign(__assign({}, existing), newData); | ||
@@ -47,0 +84,0 @@ } |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -34,3 +50,3 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
} | ||
this.eventToSubscribersMap_.set(event, __spreadArray(__spreadArray([], existingSubscribers, true), [ | ||
this.eventToSubscribersMap_.set(event, __spreadArray(__spreadArray([], __read(existingSubscribers), false), [ | ||
newSubscriberDescriptor, | ||
@@ -37,0 +53,0 @@ ], false)); |
{ | ||
"name": "@medusajs/utils", | ||
"version": "1.9.2-next-20230629132216", | ||
"version": "1.9.2-next-20230629133602", | ||
"description": "Medusa utilities functions shared by Medusa core and Modules", | ||
@@ -20,3 +20,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@medusajs/types": "1.8.10-next-20230629132216", | ||
"@medusajs/types": "1.8.10-next-20230629133602", | ||
"@types/express": "^4.17.17", | ||
@@ -38,4 +38,4 @@ "cross-env": "^5.2.1", | ||
"watch": "tsc --build --watch", | ||
"test": "jest --passWithNoTests src" | ||
"test": "jest" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
80137
106
1436