cogsbox-state 0.5.459 → 0.5.461

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/src/store.ts CHANGED
@@ -251,10 +251,6 @@ export type CogsGlobalState = {
251
251
  setInitialStateOptions: (key: string, value: OptionsType) => void;
252
252
 
253
253
  // --- Validation ---
254
- validationErrors: Map<string, string[]>;
255
- addValidationError: (path: string, message: string) => void;
256
- getValidationErrors: (path: string) => string[];
257
- removeValidationError: (path: string) => void;
258
254
 
259
255
  // --- Server Sync and Logging ---
260
256
 
@@ -863,95 +859,6 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
863
859
  });
864
860
  },
865
861
 
866
- addValidationError: (path, message) => {
867
- set((prev) => {
868
- const updatedErrors = new Map(prev.validationErrors);
869
- const existingMessages = updatedErrors.get(path) || [];
870
- console.log('addValidationError', path, message, existingMessages);
871
- // Append the new message instead of replacing
872
- updatedErrors.set(path, [...existingMessages, message]);
873
- return { validationErrors: updatedErrors };
874
- });
875
- },
876
- removeValidationError: (path) => {
877
- set((prev) => {
878
- const updatedErrors = new Map(prev.validationErrors);
879
-
880
- let doSomething = false;
881
- const pathArray = path.split('.');
882
- Array.from(updatedErrors.keys()).forEach((key) => {
883
- const keyArray = key.split('.');
884
- if (keyArray.length >= pathArray.length) {
885
- let match = true;
886
- for (let i = 0; i < pathArray.length; i++) {
887
- if (keyArray[i] !== pathArray[i]) {
888
- match = false;
889
- break;
890
- }
891
- }
892
-
893
- if (match) {
894
- doSomething = true;
895
- updatedErrors.delete(key);
896
- }
897
- }
898
- });
899
-
900
- return doSomething ? { validationErrors: updatedErrors } : prev;
901
- });
902
- },
903
- getValidationErrors: (path: string) => {
904
- const errors: string[] = [];
905
- const valErrors = get().validationErrors;
906
- const pathArray = path.split('.');
907
-
908
- // Helper to check if an index matches either a wildcard or is in an array of indices
909
- const isIndexMatch = (pathSegment: string, keySegment: string) => {
910
- if (pathSegment === '[*]') return true;
911
- if (Array.isArray(pathSegment)) {
912
- return pathSegment.includes(parseInt(keySegment));
913
- }
914
- return pathSegment === keySegment;
915
- };
916
-
917
- Array.from(valErrors.keys()).forEach((key) => {
918
- const keyArray = key.split('.');
919
- if (keyArray.length >= pathArray.length) {
920
- let match = true;
921
- for (let i = 0; i < pathArray.length; i++) {
922
- const pathSegment = pathArray[i];
923
- const keySegment = keyArray[i]!;
924
-
925
- // If current path segment is a number or [*], we need special handling
926
- if (pathSegment === '[*]' || Array.isArray(pathSegment)) {
927
- // Key segment should be a number if we're using [*] or array indices
928
- const keyIndex = parseInt(keySegment);
929
- if (isNaN(keyIndex)) {
930
- match = false;
931
- break;
932
- }
933
-
934
- if (!isIndexMatch(pathSegment, keySegment)) {
935
- match = false;
936
- break;
937
- }
938
- } else if (pathSegment !== keySegment) {
939
- match = false;
940
- break;
941
- }
942
- }
943
-
944
- if (match) {
945
- const errorMessages = valErrors.get(key);
946
- if (errorMessages) {
947
- errors.push(...errorMessages);
948
- }
949
- }
950
- }
951
- });
952
-
953
- return errors;
954
- },
955
862
  getInitialOptions: (key) => {
956
863
  return get().initialStateOptions[key];
957
864
  },