@oridune/epic-odm
Advanced tools
Comparing version 1.0.55 to 1.0.56
{ | ||
"name": "@oridune/epic-odm", | ||
"version": "1.0.55", | ||
"version": "1.0.56", | ||
"description": "Install 1 ODM and code once with any database driver.", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getModelOptions = exports.setModelOptions = exports.Model = void 0; | ||
const utils_1 = require("../utils"); | ||
const utils_2 = require("./utils"); | ||
const Model = (options) => (constructor) => (0, exports.setModelOptions)(constructor, Object.assign(Object.assign({}, options), { fields: Reflect.getMetadata(utils_2.MetaDataKeys.MODEL_FIELDS, constructor) || {}, embeds: Reflect.getMetadata(utils_2.MetaDataKeys.MODEL_EMBEDS, constructor) || {}, metas: Reflect.getMetadata(utils_2.MetaDataKeys.MODEL_METAS, constructor) || {}, relations: Reflect.getMetadata(utils_2.MetaDataKeys.MODEL_RELATIONS, constructor) || {} })); | ||
const utils_1 = require("./utils"); | ||
const utils_2 = require("../utils"); | ||
const Model = (options) => (constructor) => (0, exports.setModelOptions)(constructor, Object.assign(Object.assign({}, options), { fields: Reflect.getMetadata(utils_1.MetaDataKeys.MODEL_FIELDS, constructor) || {}, embeds: Reflect.getMetadata(utils_1.MetaDataKeys.MODEL_EMBEDS, constructor) || {}, metas: Reflect.getMetadata(utils_1.MetaDataKeys.MODEL_METAS, constructor) || {}, relations: Reflect.getMetadata(utils_1.MetaDataKeys.MODEL_RELATIONS, constructor) || {} })); | ||
exports.Model = Model; | ||
@@ -15,3 +15,3 @@ const setModelOptions = (model, options) => { | ||
const Name = (Options === null || Options === void 0 ? void 0 : Options.name) || model.name; | ||
Reflect.defineMetadata(utils_2.MetaDataKeys.MODEL_OPTIONS, Object.assign(Object.assign(Object.assign({}, ((0, exports.getModelOptions)(model) || {})), Options), { name: Name, indexes: (Options === null || Options === void 0 ? void 0 : Options.indexes) || {}, getResolvedName: () => (0, utils_1.Pluralize)(Name.replace(/Model$/, "")) | ||
Reflect.defineMetadata(utils_1.MetaDataKeys.MODEL_OPTIONS, Object.assign(Object.assign(Object.assign({}, ((0, exports.getModelOptions)(model) || {})), Options), { name: Name, indexes: (Options === null || Options === void 0 ? void 0 : Options.indexes) || {}, getResolvedName: () => utils_2.Utils.pluralize(Name.replace(/Model$/, "")) | ||
.replace(/[A-Z]/g, (a) => "-" + a.toLowerCase()) | ||
@@ -21,3 +21,3 @@ .replace(/^-/, "") }), model); | ||
exports.setModelOptions = setModelOptions; | ||
const getModelOptions = (model) => Reflect.getMetadata(utils_2.MetaDataKeys.MODEL_OPTIONS, model); | ||
const getModelOptions = (model) => Reflect.getMetadata(utils_1.MetaDataKeys.MODEL_OPTIONS, model); | ||
exports.getModelOptions = getModelOptions; |
@@ -11,8 +11,9 @@ export declare type OptionalPropertyNames<T> = { | ||
export declare type Spread<L, R> = Id<Pick<L, Exclude<keyof L, keyof R>> & Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>> & Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>> & SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>>; | ||
export declare const Pluralize: <T extends string>(text: T) => T; | ||
export declare class Utils { | ||
static pluralize: <T extends string>(text: T) => T; | ||
static deepMerge<T extends Record<any, any>, S extends Array<any>>(target: T, ...sources: S): Spread<T, S>; | ||
static uuidShort(): number; | ||
static uuid(): string; | ||
static signature(target: string, algorithm?: string): string; | ||
static transposeObjectToDotNotation(object: any, results?: Record<string, any>, prefix?: string): Record<string, any>; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Utils = exports.Pluralize = void 0; | ||
// Pluralize String | ||
exports.Pluralize = require("pluralize"); | ||
exports.Utils = void 0; | ||
const crypto_1 = __importDefault(require("crypto")); | ||
// Universally Unique Identifier | ||
@@ -10,22 +12,33 @@ class Utils { | ||
// Validation | ||
if (!(sources instanceof Array) || !sources.length) | ||
if (!sources.length) | ||
return target; | ||
// Get First Source | ||
const source = sources.shift(); | ||
// Check Merge Data | ||
// Merge Data | ||
if (typeof target === "object" && typeof source === "object") | ||
for (const key in source) { | ||
if (typeof source[key] === "object") { | ||
if (!target[key]) | ||
Object.assign(target, { | ||
[key]: source[key] instanceof Array ? [] : {}, | ||
}); | ||
this.deepMerge(target[key], source[key]); | ||
} | ||
else if (source instanceof Array && target instanceof Array) | ||
source.forEach((item) => !target.includes(item) ? target.push(item) : null); | ||
else | ||
Object.assign(target, { [key]: source[key] }); | ||
if (target instanceof Array && source instanceof Array) { | ||
source.forEach((item) => { | ||
var _a, _b; | ||
const ExistingIndex = (_b = (_a = target.indexOf) === null || _a === void 0 ? void 0 : _a.call(target, item)) !== null && _b !== void 0 ? _b : -1; | ||
if (ExistingIndex < 0) | ||
target.push(item); | ||
else | ||
target[ExistingIndex] = Utils.deepMerge(target[ExistingIndex], item); | ||
}); | ||
} | ||
return this.deepMerge(target, ...sources); | ||
else if ((target instanceof Array && !(source instanceof Array)) || | ||
(!(target instanceof Array) && source instanceof Array)) | ||
target = source; | ||
else | ||
for (const key in source) | ||
if (typeof source[key] === "object") { | ||
if (!target[key]) | ||
Object.assign(target, { | ||
[key]: source[key] instanceof Array ? [] : {}, | ||
}); | ||
target[key] = Utils.deepMerge(target[key], source[key]); | ||
} | ||
else | ||
Object.assign(target, { [key]: source[key] }); | ||
return Utils.deepMerge(target, ...sources); | ||
} | ||
@@ -44,2 +57,5 @@ static uuidShort() { | ||
} | ||
static signature(target, algorithm = "sha1") { | ||
return crypto_1.default.createHash(algorithm).update(target).digest("hex"); | ||
} | ||
static transposeObjectToDotNotation(object, results = {}, prefix) { | ||
@@ -58,1 +74,2 @@ for (const Key in object) { | ||
exports.Utils = Utils; | ||
Utils.pluralize = require("pluralize"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112821
2264