本文整理汇总了TypeScript中lodash.clonedeep.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript clonedeep.default方法的具体用法?TypeScript clonedeep.default怎么用?TypeScript clonedeep.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lodash.clonedeep
的用法示例。
在下文中一共展示了clonedeep.default方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: cloneDeep
// Exports
export default function ensureModel<T extends object = object>(
jsonSchema: object,
data: T | any,
message: string = 'Invalid data provided',
): T {
const safeProps = cloneDeep(data);
const isValid = schema.validate(jsonSchema, safeProps);
if (!isValid) {
throw Schema.createValidationError({
data,
message,
schema: jsonSchema,
errors: schema.errors,
});
}
return safeProps;
}
示例2: validate
/**
* Validate Legacy Jobs
* DEPRECATED to accommadate for new Job APIs,
* use validateConfig
*/
validate(job: any) {
let validJob = cloneDeep(job);
// this is used if an operation needs to provide additional validation beyond its own scope
const topLevelJobValidators : crossValidationFn[] = [];
// top level job validation occurs, but not operations
validJob = validateJobConfig(this.schema, validJob);
validJob.operations = job.operations.map((opConfig: OpConfig) => {
const operation = this.opLoader.load(opConfig._op, job.assets);
this.hasSchema(operation, opConfig._op);
const validOP = validateOpConfig(operation.schema(), opConfig);
if (operation.selfValidation) {
operation.selfValidation(validOP);
}
if (operation.crossValidation) {
topLevelJobValidators.push(operation.crossValidation);
}
return validOP;
});
registerApis(this.context, job);
topLevelJobValidators.forEach((fn) => {
fn(validJob, this.context.sysconfig);
});
return validJob;
}
示例3: handleModule
validateConfig(_jobConfig: JobConfig): ValidatedJobConfig {
// top level job validation occurs, but not operations
const jobConfig = validateJobConfig(this.schema, cloneDeep(_jobConfig));
const assetIds = jobConfig.assets || [];
const apis = {};
type validateJobFn = (job: ValidatedJobConfig) => void;
const validateJobFns: validateJobFn[] = [];
const handleModule = (opConfig: OpConfig, op: OperationModule) => {
const { Schema, API } = op;
if (API != null) {
apis[opConfig._op] = API;
}
const schema = new Schema(this.context);
validateJobFns.push((job) => {
if (!schema.validateJob) return;
schema.validateJob(job);
});
return schema.validate(opConfig);
};
jobConfig.operations = jobConfig.operations.map((opConfig, index) => {
if (index === 0) {
return handleModule(opConfig, this.opLoader.loadReader(opConfig._op, assetIds));
}
return handleModule(opConfig, this.opLoader.loadProcessor(opConfig._op, assetIds));
});
registerApis(this.context, jobConfig);
validateJobFns.forEach((fn) => { fn(jobConfig); });
Object.keys(apis).forEach((name) => {
const api = apis[name];
this.context.apis.executionContext.addToRegistry(name, api);
});
// @ts-ignore
return jobConfig;
}
示例4: setIn
export function setIn(obj: any, path: string, value: any): any {
let res: any = {};
let resVal: any = res;
let i = 0;
let pathArray = toPath(path);
for (; i < pathArray.length - 1; i++) {
const currentPath: string = pathArray[i];
let currentObj: any = getIn(obj, pathArray.slice(0, i + 1));
if (resVal[currentPath]) {
resVal = resVal[currentPath];
} else if (currentObj) {
resVal = resVal[currentPath] = cloneDeep(currentObj);
} else {
const nextPath: string = pathArray[i + 1];
resVal = resVal[currentPath] =
isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {};
}
}
resVal[pathArray[i]] = value;
return { ...obj, ...res };
}