@stacksjs/validation 0.75.256 → 0.75.258

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.
@@ -1 +1 @@
1
- import{applyConditionals,withConditionals}from"./conditional";export function objectWithContext(initialShape){let shape=initialShape??{},isRequired=!0;const validator={name:"object",get isRequired(){return isRequired},getRules:()=>[],test(value){return this.validate(value).valid},isPartOfShape:!1,shape(next){shape=next;return validator},getShape(){return shape},required(){isRequired=!0;return augmented},optional(){isRequired=!1;return augmented},validate(value){const isEmpty=value===void 0||value===null;if(!isRequired&&isEmpty)return{valid:!0,errors:this.isPartOfShape?{}:[]};if(isRequired&&isEmpty){const message="value is required";return this.isPartOfShape?{valid:!1,errors:{object:[{message}]}}:{valid:!1,errors:[{message}]}}if(typeof value!=="object"||Array.isArray(value)){const message="Must be an object";return this.isPartOfShape?{valid:!1,errors:{object:[{message}]}}:{valid:!1,errors:[{message}]}}const parent=value,errors={};let hasErrors=!1;for(const key of Object.keys(shape)){const baseChild=shape[key];if(!baseChild)continue;const child=applyConditionals(baseChild,parent),fieldValue=parent[key],result=child.validate(fieldValue);if(result.valid)continue;hasErrors=!0;if(!Array.isArray(result.errors))for(const[nestedKey,nestedErrors]of Object.entries(result.errors))errors[`${key}.${nestedKey}`]=nestedErrors;else errors[key]=result.errors}if(hasErrors)return{valid:!1,errors};return{valid:!0,errors:{}}}},augmented=withConditionals(validator);return augmented}
1
+ import{applyConditionals,withConditionals}from"./conditional";export function objectWithContext(initialShape){return withConditionals({name:"object",isRequired:!0,schema:initialShape??{},getRules:()=>[],test(value){return this.validate(value).valid},isPartOfShape:!1,shape(next){this.schema=next;return this},getShape(){return this.schema},required(){this.isRequired=!0;return this},optional(){this.isRequired=!1;return this},validate(value){const isEmpty=value===void 0||value===null;if(!this.isRequired&&isEmpty)return{valid:!0,errors:this.isPartOfShape?{}:[]};if(this.isRequired&&isEmpty){const message="value is required";return this.isPartOfShape?{valid:!1,errors:{object:[{message}]}}:{valid:!1,errors:[{message}]}}if(typeof value!=="object"||Array.isArray(value)){const message="Must be an object";return this.isPartOfShape?{valid:!1,errors:{object:[{message}]}}:{valid:!1,errors:[{message}]}}const parent=value,errors={};let hasErrors=!1;for(const key of Object.keys(this.schema)){const baseChild=this.schema[key];if(!baseChild)continue;const child=applyConditionals(baseChild,parent),fieldValue=parent[key],result=child.validate(fieldValue);if(result.valid)continue;hasErrors=!0;if(!Array.isArray(result.errors))for(const[nestedKey,nestedErrors]of Object.entries(result.errors))errors[`${key}.${nestedKey}`]=nestedErrors;else errors[key]=result.errors}if(hasErrors)return{valid:!1,errors};return{valid:!0,errors:{}}}})}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/validation",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.256",
5
+ "version": "0.75.258",
6
6
  "description": "The Stacks Validation ways.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -64,18 +64,18 @@
64
64
  "prepublishOnly": "bun run build"
65
65
  },
66
66
  "dependencies": {
67
- "@stacksjs/error-handling": "0.75.256",
68
- "@stacksjs/path": "0.75.256",
69
- "@stacksjs/strings": "0.75.256",
67
+ "@stacksjs/error-handling": "0.75.258",
68
+ "@stacksjs/path": "0.75.258",
69
+ "@stacksjs/strings": "0.75.258",
70
70
  "@stacksjs/ts-validation": "^0.5.6",
71
- "@stacksjs/types": "0.75.256",
72
- "@stacksjs/utils": "0.75.256"
71
+ "@stacksjs/types": "0.75.258",
72
+ "@stacksjs/utils": "0.75.258"
73
73
  },
74
74
  "devDependencies": {
75
75
  "better-dx": "^0.2.24"
76
76
  },
77
77
  "peerDependencies": {
78
- "@stacksjs/database": "0.75.256"
78
+ "@stacksjs/database": "0.75.258"
79
79
  },
80
80
  "peerDependenciesMeta": {
81
81
  "@stacksjs/database": {