@orion-js/models
Advanced tools
Comparing version 3.0.36 to 3.0.37
@@ -23,2 +23,8 @@ "use strict"; | ||
resolvedSchema = (0, modelToSchema_1.modelToSchemaWithModel)(schema, model); | ||
if (modelOptions.clean) { | ||
resolvedSchema.__clean = modelOptions.clean; | ||
} | ||
if (modelOptions.validate) { | ||
resolvedSchema.__clean = modelOptions.validate; | ||
} | ||
return resolvedSchema; | ||
@@ -32,3 +38,9 @@ }; | ||
const schema = (0, resolveParam_1.default)(modelOptions.schema); | ||
resolvedCleanSchema = (0, modelToSchema_1.modelToSchema)(schema); | ||
resolvedCleanSchema = (0, modelToSchema_1.modelToSchemaClean)(schema); | ||
if (modelOptions.clean) { | ||
resolvedCleanSchema.__clean = modelOptions.clean; | ||
} | ||
if (modelOptions.validate) { | ||
resolvedCleanSchema.__clean = modelOptions.validate; | ||
} | ||
return resolvedCleanSchema; | ||
@@ -57,12 +69,8 @@ }; | ||
validate: async (doc) => { | ||
const schema = getCleanSchema(); | ||
if (modelOptions.validate) { | ||
await modelOptions.validate(doc); | ||
} | ||
const schema = getSchema(); | ||
return await (0, schema_1.validate)(schema, doc); | ||
}, | ||
clean: async (doc) => { | ||
const schema = getCleanSchema(); | ||
const cleanedDoc = modelOptions.clean ? await modelOptions.clean(doc) : doc; | ||
return await (0, schema_1.clean)(schema, cleanedDoc); | ||
const schema = getSchema(); | ||
return await (0, schema_1.clean)(schema, doc); | ||
}, | ||
@@ -69,0 +77,0 @@ clone: (cloneOptions) => { |
@@ -8,3 +8,3 @@ import { Model, ModelSchema } from '..'; | ||
__model: Model; | ||
__clean: (item: any) => Promise<any>; | ||
}; | ||
export declare function modelToSchemaClean(modelSchema: ModelSchema): Schema; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.modelToSchemaWithModel = exports.modelToSchema = void 0; | ||
exports.modelToSchemaClean = exports.modelToSchemaWithModel = exports.modelToSchema = void 0; | ||
const isArray_1 = __importDefault(require("lodash/isArray")); | ||
@@ -18,2 +18,4 @@ function isModelSchema(type) { | ||
for (const key in modelSchema) { | ||
if (key.startsWith('__')) | ||
continue; | ||
const fieldSchema = modelSchema[key]; | ||
@@ -49,6 +51,10 @@ let currNode; | ||
...schema, | ||
__model: model, | ||
__clean: model.clean | ||
__model: model | ||
}; | ||
} | ||
exports.modelToSchemaWithModel = modelToSchemaWithModel; | ||
function modelToSchemaClean(modelSchema) { | ||
const schema = modelToSchema(modelSchema, { cleanSchema: true }); | ||
return schema; | ||
} | ||
exports.modelToSchemaClean = modelToSchemaClean; |
@@ -50,1 +50,14 @@ "use strict"; | ||
}); | ||
it('Should return a schema with __clean if clean param is passed to model', async () => { | ||
const clean = () => ({ name: 'hello' }); | ||
const model = (0, _1.default)({ | ||
name: 'test', | ||
schema: { | ||
name: { type: String }, | ||
age: { type: Number } | ||
}, | ||
clean | ||
}); | ||
const schema = model.getSchema(); | ||
expect(await schema.__clean()).toEqual(await clean()); | ||
}); |
{ | ||
"name": "@orion-js/models", | ||
"version": "3.0.36", | ||
"version": "3.0.37", | ||
"main": "lib/index.js", | ||
@@ -21,4 +21,4 @@ "types": "lib/index.d.ts", | ||
"@orion-js/helpers": "^3.0.36", | ||
"@orion-js/resolvers": "^3.0.36", | ||
"@orion-js/schema": "^3.0.36" | ||
"@orion-js/resolvers": "^3.0.37", | ||
"@orion-js/schema": "^3.0.37" | ||
}, | ||
@@ -40,3 +40,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "7c921dbbf0ec679df743b9278abbf15cfcbac6ce" | ||
"gitHead": "741691d7603f3d42e6e3e8fa9dc0f9de51a29424" | ||
} |
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
25146
691
Updated@orion-js/resolvers@^3.0.37
Updated@orion-js/schema@^3.0.37