@cadenza.io/core 3.19.3 → 3.19.4
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/index.d.mts +18 -16
- package/dist/index.d.ts +18 -16
- package/dist/index.js +99 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3603,9 +3603,9 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3603
3603
|
* @param {boolean} [isSubMeta=false] - Indicates if the task is a sub-meta-task.
|
|
3604
3604
|
* @param {boolean} [isHidden=false] - Determines if the task is hidden and not exposed publicly.
|
|
3605
3605
|
* @param {ThrottleTagGetter} [getTagCallback=undefined] - A callback to generate a throttle tag for the task.
|
|
3606
|
-
* @param {
|
|
3606
|
+
* @param {Schema} [inputSchema=undefined] - The input schema for validating the task's input context.
|
|
3607
3607
|
* @param {boolean} [validateInputContext=false] - Specifies if the input context should be validated against the input schema.
|
|
3608
|
-
* @param {
|
|
3608
|
+
* @param {Schema} [outputSchema=undefined] - The output schema for validating the task's output context.
|
|
3609
3609
|
* @param {boolean} [validateOutputContext=false] - Specifies if the output context should be validated against the output schema.
|
|
3610
3610
|
* @param {number} [retryCount=0] - The number of retry attempts allowed for the task in case of failure.
|
|
3611
3611
|
* @param {number} [retryDelay=0] - The initial delay (in milliseconds) between retry attempts.
|
|
@@ -3850,14 +3850,27 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3850
3850
|
* Validates a data object against a specified schema definition and returns validation results.
|
|
3851
3851
|
*
|
|
3852
3852
|
* @param {any} data - The target object to validate against the schema.
|
|
3853
|
-
* @param {
|
|
3853
|
+
* @param {Schema | undefined} schema - The schema definition describing the expected structure and constraints of the data.
|
|
3854
3854
|
* @param {string} [path="context"] - The base path or context for traversing the data, used in generating error messages.
|
|
3855
3855
|
* @return {{ valid: boolean, errors: Record<string, string> }} - An object containing a validity flag (`valid`)
|
|
3856
3856
|
* and a map (`errors`) of validation error messages keyed by property paths.
|
|
3857
3857
|
*/
|
|
3858
3858
|
validateSchema(data, schema, path = "context") {
|
|
3859
3859
|
const errors = {};
|
|
3860
|
-
if (!schema || typeof schema !== "object"
|
|
3860
|
+
if (!schema || typeof schema !== "object" && !Array.isArray(schema))
|
|
3861
|
+
return { valid: true, errors };
|
|
3862
|
+
if (Array.isArray(schema)) {
|
|
3863
|
+
for (const s of schema) {
|
|
3864
|
+
const subValidation = this.validateSchema(data, s, path);
|
|
3865
|
+
if (!subValidation.valid) {
|
|
3866
|
+
Object.assign(errors, subValidation.errors);
|
|
3867
|
+
}
|
|
3868
|
+
if (subValidation.valid) {
|
|
3869
|
+
return { valid: true, errors: {} };
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3872
|
+
return { valid: false, errors };
|
|
3873
|
+
}
|
|
3861
3874
|
const required = schema.required || [];
|
|
3862
3875
|
for (const key of required) {
|
|
3863
3876
|
if (!(key in data)) {
|
|
@@ -3868,84 +3881,12 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3868
3881
|
for (const [key, value] of Object.entries(data)) {
|
|
3869
3882
|
if (key in properties) {
|
|
3870
3883
|
const prop = properties[key];
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
}
|
|
3875
|
-
if ((value === void 0 || value === null) && !prop.strict) {
|
|
3876
|
-
continue;
|
|
3877
|
-
}
|
|
3878
|
-
if (propType === "string" && typeof value !== "string") {
|
|
3879
|
-
errors[`${path}.${key}`] = `Expected 'string' for '${key}', got '${typeof value}'`;
|
|
3880
|
-
} else if (propType === "number" && typeof value !== "number") {
|
|
3881
|
-
errors[`${path}.${key}`] = `Expected 'number' for '${key}', got '${typeof value}'`;
|
|
3882
|
-
} else if (propType === "boolean" && typeof value !== "boolean") {
|
|
3883
|
-
errors[`${path}.${key}`] = `Expected 'boolean' for '${key}', got '${typeof value}'`;
|
|
3884
|
-
} else if (propType === "array" && !Array.isArray(value)) {
|
|
3885
|
-
errors[`${path}.${key}`] = `Expected 'array' for '${key}', got '${typeof value}'`;
|
|
3886
|
-
} else if (propType === "object" && (typeof value !== "object" || value === null || Array.isArray(value))) {
|
|
3887
|
-
errors[`${path}.${key}`] = `Expected 'object' for '${key}', got '${typeof value}'`;
|
|
3888
|
-
} else if (propType === "array" && prop.items) {
|
|
3889
|
-
if (Array.isArray(value)) {
|
|
3890
|
-
value.forEach((item, index) => {
|
|
3891
|
-
const subValidation = this.validateSchema(
|
|
3892
|
-
item,
|
|
3893
|
-
prop.items,
|
|
3894
|
-
`${path}.${key}[${index}]`
|
|
3895
|
-
);
|
|
3896
|
-
if (!subValidation.valid) {
|
|
3897
|
-
Object.assign(errors, subValidation.errors);
|
|
3898
|
-
}
|
|
3899
|
-
});
|
|
3900
|
-
}
|
|
3901
|
-
} else if (propType === "object" && !Array.isArray(value) && value !== null) {
|
|
3902
|
-
const subValidation = this.validateSchema(
|
|
3903
|
-
value,
|
|
3904
|
-
prop,
|
|
3905
|
-
`${path}.${key}`
|
|
3906
|
-
);
|
|
3907
|
-
if (!subValidation.valid) {
|
|
3908
|
-
Object.assign(errors, subValidation.errors);
|
|
3909
|
-
}
|
|
3910
|
-
}
|
|
3911
|
-
const constraints = prop.constraints || {};
|
|
3912
|
-
if (typeof value === "string") {
|
|
3913
|
-
if (constraints.minLength && value.length < constraints.minLength) {
|
|
3914
|
-
errors[`${path}.${key}`] = `String '${key}' shorter than minLength ${constraints.minLength}`;
|
|
3915
|
-
}
|
|
3916
|
-
if (constraints.maxLength && value.length > constraints.maxLength) {
|
|
3917
|
-
errors[`${path}.${key}`] = `String '${key}' exceeds maxLength ${constraints.maxLength}`;
|
|
3918
|
-
}
|
|
3919
|
-
if (constraints.pattern && !new RegExp(constraints.pattern).test(value)) {
|
|
3920
|
-
errors[`${path}.${key}`] = `String '${key}' does not match pattern ${constraints.pattern}`;
|
|
3921
|
-
}
|
|
3922
|
-
} else if (typeof value === "number") {
|
|
3923
|
-
if (constraints.min && value < constraints.min) {
|
|
3924
|
-
errors[`${path}.${key}`] = `Number '${key}' below min ${constraints.min}`;
|
|
3925
|
-
}
|
|
3926
|
-
if (constraints.max && value > constraints.max) {
|
|
3927
|
-
errors[`${path}.${key}`] = `Number '${key}' exceeds max ${constraints.max}`;
|
|
3928
|
-
}
|
|
3929
|
-
if (constraints.multipleOf && value % constraints.multipleOf !== 0) {
|
|
3930
|
-
errors[`${path}.${key}`] = `Number '${key}' not multiple of ${constraints.multipleOf}`;
|
|
3884
|
+
if (Array.isArray(prop)) {
|
|
3885
|
+
for (const p of prop) {
|
|
3886
|
+
Object.assign(errors, this.validateProp(p, key, value, path));
|
|
3931
3887
|
}
|
|
3932
|
-
} else
|
|
3933
|
-
errors
|
|
3934
|
-
} else if (constraints.format) {
|
|
3935
|
-
const formats = {
|
|
3936
|
-
email: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
|
3937
|
-
url: /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/,
|
|
3938
|
-
"date-time": /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,
|
|
3939
|
-
uuid: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
|
|
3940
|
-
custom: /.*/
|
|
3941
|
-
// Placeholder; override with prop.constraints.pattern if present
|
|
3942
|
-
};
|
|
3943
|
-
const regex = formats[constraints.format] || new RegExp(constraints.pattern || ".*");
|
|
3944
|
-
if (typeof value === "string" && !regex.test(value)) {
|
|
3945
|
-
errors[`${path}.${key}`] = `Value '${value}' for '${key}' does not match format '${constraints.format}'`;
|
|
3946
|
-
}
|
|
3947
|
-
} else if (constraints.oneOf && !constraints.oneOf.includes(value)) {
|
|
3948
|
-
errors[`${path}.${key}`] = `Value '${value}' for '${key}' not in oneOf ${JSON.stringify(constraints.oneOf)}`;
|
|
3888
|
+
} else {
|
|
3889
|
+
Object.assign(errors, this.validateProp(prop, key, value, path));
|
|
3949
3890
|
}
|
|
3950
3891
|
} else if (schema.strict) {
|
|
3951
3892
|
errors[`${path}.${key}`] = `Key '${key}' is not allowed`;
|
|
@@ -3956,6 +3897,83 @@ var Task = class _Task extends SignalEmitter {
|
|
|
3956
3897
|
}
|
|
3957
3898
|
return { valid: true, errors: {} };
|
|
3958
3899
|
}
|
|
3900
|
+
validateProp(prop, key, value, path = "context") {
|
|
3901
|
+
const propType = prop.type;
|
|
3902
|
+
const errors = {};
|
|
3903
|
+
if (propType === "any") {
|
|
3904
|
+
return errors;
|
|
3905
|
+
}
|
|
3906
|
+
if ((value === void 0 || value === null) && !prop.strict) {
|
|
3907
|
+
return errors;
|
|
3908
|
+
}
|
|
3909
|
+
if (propType === "string" && typeof value !== "string") {
|
|
3910
|
+
errors[`${path}.${key}`] = `Expected 'string' for '${key}', got '${typeof value}'`;
|
|
3911
|
+
} else if (propType === "number" && typeof value !== "number") {
|
|
3912
|
+
errors[`${path}.${key}`] = `Expected 'number' for '${key}', got '${typeof value}'`;
|
|
3913
|
+
} else if (propType === "boolean" && typeof value !== "boolean") {
|
|
3914
|
+
errors[`${path}.${key}`] = `Expected 'boolean' for '${key}', got '${typeof value}'`;
|
|
3915
|
+
} else if (propType === "array" && !Array.isArray(value)) {
|
|
3916
|
+
errors[`${path}.${key}`] = `Expected 'array' for '${key}', got '${typeof value}'`;
|
|
3917
|
+
} else if (propType === "object" && (typeof value !== "object" || value === null || Array.isArray(value))) {
|
|
3918
|
+
errors[`${path}.${key}`] = `Expected 'object' for '${key}', got '${typeof value}'`;
|
|
3919
|
+
} else if (propType === "array" && prop.items) {
|
|
3920
|
+
value.forEach((item, index) => {
|
|
3921
|
+
const subValidation = this.validateSchema(
|
|
3922
|
+
item,
|
|
3923
|
+
prop.items,
|
|
3924
|
+
`${path}.${key}[${index}]`
|
|
3925
|
+
);
|
|
3926
|
+
if (!subValidation.valid) {
|
|
3927
|
+
Object.assign(errors, subValidation.errors);
|
|
3928
|
+
}
|
|
3929
|
+
});
|
|
3930
|
+
} else if (propType === "object" && !Array.isArray(value) && value !== null) {
|
|
3931
|
+
const subValidation = this.validateSchema(value, prop, `${path}.${key}`);
|
|
3932
|
+
if (!subValidation.valid) {
|
|
3933
|
+
Object.assign(errors, subValidation.errors);
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3936
|
+
const constraints = prop.constraints || {};
|
|
3937
|
+
if (typeof value === "string") {
|
|
3938
|
+
if (constraints.minLength && value.length < constraints.minLength) {
|
|
3939
|
+
errors[`${path}.${key}`] = `String '${key}' shorter than minLength ${constraints.minLength}`;
|
|
3940
|
+
}
|
|
3941
|
+
if (constraints.maxLength && value.length > constraints.maxLength) {
|
|
3942
|
+
errors[`${path}.${key}`] = `String '${key}' exceeds maxLength ${constraints.maxLength}`;
|
|
3943
|
+
}
|
|
3944
|
+
if (constraints.pattern && !new RegExp(constraints.pattern).test(value)) {
|
|
3945
|
+
errors[`${path}.${key}`] = `String '${key}' does not match pattern ${constraints.pattern}`;
|
|
3946
|
+
}
|
|
3947
|
+
} else if (typeof value === "number") {
|
|
3948
|
+
if (constraints.min && value < constraints.min) {
|
|
3949
|
+
errors[`${path}.${key}`] = `Number '${key}' below min ${constraints.min}`;
|
|
3950
|
+
}
|
|
3951
|
+
if (constraints.max && value > constraints.max) {
|
|
3952
|
+
errors[`${path}.${key}`] = `Number '${key}' exceeds max ${constraints.max}`;
|
|
3953
|
+
}
|
|
3954
|
+
if (constraints.multipleOf && value % constraints.multipleOf !== 0) {
|
|
3955
|
+
errors[`${path}.${key}`] = `Number '${key}' not multiple of ${constraints.multipleOf}`;
|
|
3956
|
+
}
|
|
3957
|
+
} else if (constraints.enum && !constraints.enum.includes(value)) {
|
|
3958
|
+
errors[`${path}.${key}`] = `Value '${value}' for '${key}' not in enum ${JSON.stringify(constraints.enum)}`;
|
|
3959
|
+
} else if (constraints.format) {
|
|
3960
|
+
const formats = {
|
|
3961
|
+
email: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
|
3962
|
+
url: /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/,
|
|
3963
|
+
"date-time": /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,
|
|
3964
|
+
uuid: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
|
|
3965
|
+
custom: /.*/
|
|
3966
|
+
// Placeholder; override with prop.constraints.pattern if present
|
|
3967
|
+
};
|
|
3968
|
+
const regex = formats[constraints.format] || new RegExp(constraints.pattern || ".*");
|
|
3969
|
+
if (typeof value === "string" && !regex.test(value)) {
|
|
3970
|
+
errors[`${path}.${key}`] = `Value '${value}' for '${key}' does not match format '${constraints.format}'`;
|
|
3971
|
+
}
|
|
3972
|
+
} else if (constraints.oneOf && !constraints.oneOf.includes(value)) {
|
|
3973
|
+
errors[`${path}.${key}`] = `Value '${value}' for '${key}' not in oneOf ${JSON.stringify(constraints.oneOf)}`;
|
|
3974
|
+
}
|
|
3975
|
+
return errors;
|
|
3976
|
+
}
|
|
3959
3977
|
/**
|
|
3960
3978
|
* Validates the input context against the predefined schema and emits metadata if validation fails.
|
|
3961
3979
|
*
|