@openforis/arena-core 3.1.6 → 3.2.1

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.
Files changed (121) hide show
  1. package/dist/esm/geo/geoFeature.js +2 -0
  2. package/dist/esm/geo/geoFeature.js.map +1 -0
  3. package/dist/esm/geo/index.js.map +1 -1
  4. package/dist/esm/geo/points/isFilled.js +5 -1
  5. package/dist/esm/geo/points/isFilled.js.map +1 -1
  6. package/dist/esm/geo/points/parse.js +2 -2
  7. package/dist/esm/geo/points/parse.js.map +1 -1
  8. package/dist/esm/geo/points/toLatLong.js +2 -2
  9. package/dist/esm/geo/points/toLatLong.js.map +1 -1
  10. package/dist/esm/geo/points/transform.js.map +1 -1
  11. package/dist/esm/index.js.map +1 -1
  12. package/dist/esm/logger/logger.js.map +1 -1
  13. package/dist/esm/node/index.js.map +1 -1
  14. package/dist/esm/node/node.js.map +1 -1
  15. package/dist/esm/node/nodeValue/coordinate.js.map +1 -1
  16. package/dist/esm/node/nodeValue/geo.js +2 -0
  17. package/dist/esm/node/nodeValue/geo.js.map +1 -0
  18. package/dist/esm/node/nodeValue/index.js.map +1 -1
  19. package/dist/esm/node/nodeValue/nodeValue.js +2 -0
  20. package/dist/esm/node/nodeValue/nodeValue.js.map +1 -0
  21. package/dist/esm/nodeDef/index.js.map +1 -1
  22. package/dist/esm/nodeDef/nodeDefs.js.map +1 -1
  23. package/dist/esm/nodeDef/types/coordinate.js.map +1 -1
  24. package/dist/esm/record/index.js.map +1 -1
  25. package/dist/esm/record/recordSummary.js +2 -0
  26. package/dist/esm/record/recordSummary.js.map +1 -0
  27. package/dist/esm/survey/index.js.map +1 -1
  28. package/dist/esm/survey/surveySummary.js +2 -0
  29. package/dist/esm/survey/surveySummary.js.map +1 -0
  30. package/dist/esm/survey/surveys/nodeDefs.js +1 -1
  31. package/dist/esm/survey/surveys/nodeDefs.js.map +1 -1
  32. package/dist/esm/survey/surveys/refsData.js +4 -3
  33. package/dist/esm/survey/surveys/refsData.js.map +1 -1
  34. package/dist/esm/survey/surveys/surveyGettersSecurity.js.map +1 -1
  35. package/dist/esm/survey/surveys/surveysGetters.js.map +1 -1
  36. package/dist/esm/utils/_objects/path.js +1 -0
  37. package/dist/esm/utils/_objects/path.js.map +1 -1
  38. package/dist/esm/utils/fileProcessor.js +1 -0
  39. package/dist/esm/utils/fileProcessor.js.map +1 -1
  40. package/dist/esm/utils/index.js.map +1 -1
  41. package/dist/esm/utils/numbers.js +4 -4
  42. package/dist/esm/utils/numbers.js.map +1 -1
  43. package/dist/esm/validation/validations.js +1 -1
  44. package/dist/esm/validation/validations.js.map +1 -1
  45. package/dist/geo/geoFeature.d.ts +16 -0
  46. package/dist/geo/geoFeature.js +3 -0
  47. package/dist/geo/geoFeature.js.map +1 -0
  48. package/dist/geo/index.d.ts +1 -0
  49. package/dist/geo/index.js.map +1 -1
  50. package/dist/geo/points/isFilled.d.ts +1 -1
  51. package/dist/geo/points/isFilled.js +5 -1
  52. package/dist/geo/points/isFilled.js.map +1 -1
  53. package/dist/geo/points/parse.d.ts +3 -3
  54. package/dist/geo/points/parse.js +2 -2
  55. package/dist/geo/points/parse.js.map +1 -1
  56. package/dist/geo/points/toLatLong.d.ts +1 -1
  57. package/dist/geo/points/toLatLong.js +1 -1
  58. package/dist/geo/points/toLatLong.js.map +1 -1
  59. package/dist/geo/points/transform.d.ts +2 -2
  60. package/dist/geo/points/transform.js.map +1 -1
  61. package/dist/index.d.ts +6 -6
  62. package/dist/index.js.map +1 -1
  63. package/dist/logger/logger.d.ts +4 -4
  64. package/dist/logger/logger.js.map +1 -1
  65. package/dist/node/index.d.ts +1 -1
  66. package/dist/node/index.js.map +1 -1
  67. package/dist/node/node.d.ts +2 -2
  68. package/dist/node/node.js.map +1 -1
  69. package/dist/node/nodeValue/coordinate.d.ts +3 -0
  70. package/dist/node/nodeValue/coordinate.js.map +1 -1
  71. package/dist/node/nodeValue/geo.d.ts +2 -0
  72. package/dist/node/nodeValue/geo.js +3 -0
  73. package/dist/node/nodeValue/geo.js.map +1 -0
  74. package/dist/node/nodeValue/index.d.ts +2 -0
  75. package/dist/node/nodeValue/index.js.map +1 -1
  76. package/dist/node/nodeValue/nodeValue.d.ts +9 -0
  77. package/dist/node/nodeValue/nodeValue.js +3 -0
  78. package/dist/node/nodeValue/nodeValue.js.map +1 -0
  79. package/dist/nodeDef/index.d.ts +1 -1
  80. package/dist/nodeDef/index.js.map +1 -1
  81. package/dist/nodeDef/nodeDefs.d.ts +2 -2
  82. package/dist/nodeDef/nodeDefs.js.map +1 -1
  83. package/dist/nodeDef/types/coordinate.d.ts +2 -0
  84. package/dist/nodeDef/types/coordinate.js.map +1 -1
  85. package/dist/record/index.d.ts +1 -0
  86. package/dist/record/index.js.map +1 -1
  87. package/dist/record/recordNodesUpdater/recordUpdateResult.d.ts +1 -1
  88. package/dist/record/recordSummary.d.ts +15 -0
  89. package/dist/record/recordSummary.js +3 -0
  90. package/dist/record/recordSummary.js.map +1 -0
  91. package/dist/survey/index.d.ts +1 -0
  92. package/dist/survey/index.js.map +1 -1
  93. package/dist/survey/surveySummary.d.ts +14 -0
  94. package/dist/survey/surveySummary.js +3 -0
  95. package/dist/survey/surveySummary.js.map +1 -0
  96. package/dist/survey/surveys/index.d.ts +3 -3
  97. package/dist/survey/surveys/nodeDefs.d.ts +2 -2
  98. package/dist/survey/surveys/nodeDefs.js +1 -1
  99. package/dist/survey/surveys/nodeDefs.js.map +1 -1
  100. package/dist/survey/surveys/refsData.d.ts +1 -1
  101. package/dist/survey/surveys/refsData.js +4 -3
  102. package/dist/survey/surveys/refsData.js.map +1 -1
  103. package/dist/survey/surveys/surveyGettersSecurity.d.ts +11 -10
  104. package/dist/survey/surveys/surveyGettersSecurity.js.map +1 -1
  105. package/dist/survey/surveys/surveysGetters.d.ts +17 -16
  106. package/dist/survey/surveys/surveysGetters.js.map +1 -1
  107. package/dist/utils/_objects/path.d.ts +2 -1
  108. package/dist/utils/_objects/path.js +1 -0
  109. package/dist/utils/_objects/path.js.map +1 -1
  110. package/dist/utils/fileProcessor.d.ts +24 -11
  111. package/dist/utils/fileProcessor.js +1 -0
  112. package/dist/utils/fileProcessor.js.map +1 -1
  113. package/dist/utils/index.d.ts +1 -1
  114. package/dist/utils/index.js.map +1 -1
  115. package/dist/utils/numbers.d.ts +5 -5
  116. package/dist/utils/numbers.js +4 -4
  117. package/dist/utils/numbers.js.map +1 -1
  118. package/dist/validation/validations.d.ts +10 -10
  119. package/dist/validation/validations.js +1 -1
  120. package/dist/validation/validations.js.map +1 -1
  121. package/package.json +1 -1
@@ -1,10 +1,11 @@
1
- import { ArenaSurvey, ArenaSurveySecurity, SurveySecurityProp } from '../survey';
2
- export declare const getSecurity: (survey: ArenaSurvey) => ArenaSurveySecurity;
3
- export declare const isSecurityPropEnabled: (prop: SurveySecurityProp) => (survey: ArenaSurvey) => boolean;
4
- export declare const isDataEditorViewNotOwnedRecordsAllowed: (survey: ArenaSurvey) => boolean;
5
- export declare const isDataAnalystViewNotOwnedRecordsAllowed: (survey: ArenaSurvey) => boolean;
6
- export declare const isVisibleInMobile: (survey: ArenaSurvey) => boolean;
7
- export declare const isRecordsDownloadInMobileAllowed: (survey: ArenaSurvey) => boolean;
8
- export declare const isRecordsUploadFromMobileAllowed: (survey: ArenaSurvey) => boolean;
9
- export declare const isRecordsWithErrorsUploadFromMobileAllowed: (survey: ArenaSurvey) => boolean;
10
- export declare const isRecordsMergeWithSameKeysAllowed: (survey: ArenaSurvey) => boolean;
1
+ import { ArenaSurveySecurity, SurveySecurityProp } from '../survey';
2
+ import type { ArenaSurveyOrSummary } from '../surveySummary';
3
+ export declare const getSecurity: (survey: ArenaSurveyOrSummary) => ArenaSurveySecurity;
4
+ export declare const isSecurityPropEnabled: (prop: SurveySecurityProp) => (survey: ArenaSurveyOrSummary) => boolean;
5
+ export declare const isDataEditorViewNotOwnedRecordsAllowed: (survey: ArenaSurveyOrSummary) => boolean;
6
+ export declare const isDataAnalystViewNotOwnedRecordsAllowed: (survey: ArenaSurveyOrSummary) => boolean;
7
+ export declare const isVisibleInMobile: (survey: ArenaSurveyOrSummary) => boolean;
8
+ export declare const isRecordsDownloadInMobileAllowed: (survey: ArenaSurveyOrSummary) => boolean;
9
+ export declare const isRecordsUploadFromMobileAllowed: (survey: ArenaSurveyOrSummary) => boolean;
10
+ export declare const isRecordsWithErrorsUploadFromMobileAllowed: (survey: ArenaSurveyOrSummary) => boolean;
11
+ export declare const isRecordsMergeWithSameKeysAllowed: (survey: ArenaSurveyOrSummary) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"surveyGettersSecurity.js","sourceRoot":"","sources":["../../../src/survey/surveys/surveyGettersSecurity.ts"],"names":[],"mappings":";;;AAAA,sCAAwG;AAEjG,MAAM,WAAW,GAAG,CAAC,MAAmB,EAAuB,EAAE,kBAAC,iCACpE,+BAAsB,GACtB,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,0CAAE,QAAQ,EAC1B,GAAA,CAAA;AAHW,QAAA,WAAW,GAAX,WAAW,CAGtB;AAEK,MAAM,qBAAqB,GAChC,CAAC,IAAwB,EAAE,EAAE,CAC7B,CAAC,MAAmB,EAAW,EAAE,CAC/B,CAAC,CAAC,IAAA,QAAA,WAAW,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAA;AAHlB,QAAA,qBAAqB,GAArB,qBAAqB,CAGH;AAExB,MAAM,sCAAsC,GAAG,CAAC,MAAmB,EAAW,EAAE,CACrF,IAAA,QAAA,qBAAqB,EAAC,2BAAkB,CAAC,oCAAoC,CAAC,CAAC,MAAM,CAAC,CAAA;AAD3E,QAAA,sCAAsC,GAAtC,sCAAsC,CACqC;AAEjF,MAAM,uCAAuC,GAAG,CAAC,MAAmB,EAAW,EAAE,CACtF,IAAA,QAAA,qBAAqB,EAAC,2BAAkB,CAAC,qCAAqC,CAAC,CAAC,MAAM,CAAC,CAAA;AAD5E,QAAA,uCAAuC,GAAvC,uCAAuC,CACqC;AAElF,MAAM,iBAAiB,GAAG,CAAC,MAAmB,EAAW,EAAE,CAChE,IAAA,QAAA,qBAAqB,EAAC,2BAAkB,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AADtD,QAAA,iBAAiB,GAAjB,iBAAiB,CACqC;AAE5D,MAAM,gCAAgC,GAAG,CAAC,MAAmB,EAAW,EAAE,CAC/E,IAAA,QAAA,qBAAqB,EAAC,2BAAkB,CAAC,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAA;AADnE,QAAA,gCAAgC,GAAhC,gCAAgC,CACmC;AAEzE,MAAM,gCAAgC,GAAG,CAAC,MAAmB,EAAW,EAAE,CAC/E,IAAA,QAAA,qBAAqB,EAAC,2BAAkB,CAAC,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAA;AADnE,QAAA,gCAAgC,GAAhC,gCAAgC,CACmC;AAEzE,MAAM,0CAA0C,GAAG,CAAC,MAAmB,EAAW,EAAE,CACzF,IAAA,QAAA,qBAAqB,EAAC,2BAAkB,CAAC,sCAAsC,CAAC,CAAC,MAAM,CAAC,CAAA;AAD7E,QAAA,0CAA0C,GAA1C,0CAA0C,CACmC;AAEnF,MAAM,iCAAiC,GAAG,CAAC,MAAmB,EAAW,EAAE,CAChF,IAAA,QAAA,qBAAqB,EAAC,2BAAkB,CAAC,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAA;AADpE,QAAA,iCAAiC,GAAjC,iCAAiC,CACmC","sourcesContent":["import { ArenaSurvey, ArenaSurveySecurity, surveySecurityDefaults, SurveySecurityProp } from '../survey'\n\nexport const getSecurity = (survey: ArenaSurvey): ArenaSurveySecurity => ({\n ...surveySecurityDefaults,\n ...survey?.props?.security,\n})\n\nexport const isSecurityPropEnabled =\n (prop: SurveySecurityProp) =>\n (survey: ArenaSurvey): boolean =>\n !!getSecurity(survey)[prop]\n\nexport const isDataEditorViewNotOwnedRecordsAllowed = (survey: ArenaSurvey): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.dataEditorViewNotOwnedRecordsAllowed)(survey)\n\nexport const isDataAnalystViewNotOwnedRecordsAllowed = (survey: ArenaSurvey): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.dataAnalystViewNotOwnedRecordsAllowed)(survey)\n\nexport const isVisibleInMobile = (survey: ArenaSurvey): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.visibleInMobile)(survey)\n\nexport const isRecordsDownloadInMobileAllowed = (survey: ArenaSurvey): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.allowRecordsDownloadInMobile)(survey)\n\nexport const isRecordsUploadFromMobileAllowed = (survey: ArenaSurvey): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.allowRecordsUploadFromMobile)(survey)\n\nexport const isRecordsWithErrorsUploadFromMobileAllowed = (survey: ArenaSurvey): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.allowRecordsWithErrorsUploadFromMobile)(survey)\n\nexport const isRecordsMergeWithSameKeysAllowed = (survey: ArenaSurvey): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.allowRecordsMergeWithSameKeys)(survey)\n"]}
1
+ {"version":3,"file":"surveyGettersSecurity.js","sourceRoot":"","sources":["../../../src/survey/surveys/surveyGettersSecurity.ts"],"names":[],"mappings":";;;AAAA,sCAA2F;AAGpF,MAAM,WAAW,GAAG,CAAC,MAA4B,EAAuB,EAAE,kBAAC,iCAC7E,+BAAsB,GACtB,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,0CAAE,QAAQ,EAC1B,GAAA,CAAA;AAHW,QAAA,WAAW,GAAX,WAAW,CAGtB;AAEK,MAAM,qBAAqB,GAChC,CAAC,IAAwB,EAAE,EAAE,CAC7B,CAAC,MAA4B,EAAW,EAAE,CACxC,CAAC,CAAC,IAAA,QAAA,WAAW,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAA;AAHlB,QAAA,qBAAqB,GAArB,qBAAqB,CAGH;AAExB,MAAM,sCAAsC,GAAG,CAAC,M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ourcesContent":["import { ArenaSurveySecurity, surveySecurityDefaults, SurveySecurityProp } from '../survey'\nimport type { ArenaSurveyOrSummary } from '../surveySummary'\n\nexport const getSecurity = (survey: ArenaSurveyOrSummary): ArenaSurveySecurity => ({\n ...surveySecurityDefaults,\n ...survey?.props?.security,\n})\n\nexport const isSecurityPropEnabled =\n (prop: SurveySecurityProp) =>\n (survey: ArenaSurveyOrSummary): boolean =>\n !!getSecurity(survey)[prop]\n\nexport const isDataEditorViewNotOwnedRecordsAllowed = (survey: ArenaSurveyOrSummary): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.dataEditorViewNotOwnedRecordsAllowed)(survey)\n\nexport const isDataAnalystViewNotOwnedRecordsAllowed = (survey: ArenaSurveyOrSummary): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.dataAnalystViewNotOwnedRecordsAllowed)(survey)\n\nexport const isVisibleInMobile = (survey: ArenaSurveyOrSummary): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.visibleInMobile)(survey)\n\nexport const isRecordsDownloadInMobileAllowed = (survey: ArenaSurveyOrSummary): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.allowRecordsDownloadInMobile)(survey)\n\nexport const isRecordsUploadFromMobileAllowed = (survey: ArenaSurveyOrSummary): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.allowRecordsUploadFromMobile)(survey)\n\nexport const isRecordsWithErrorsUploadFromMobileAllowed = (survey: ArenaSurveyOrSummary): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.allowRecordsWithErrorsUploadFromMobile)(survey)\n\nexport const isRecordsMergeWithSameKeysAllowed = (survey: ArenaSurveyOrSummary): boolean =>\n isSecurityPropEnabled(SurveySecurityProp.allowRecordsMergeWithSameKeys)(survey)\n"]}
@@ -5,17 +5,18 @@ import { LanguageCode } from '../../language';
5
5
  import { ArenaSRS, ArenaSRSIndex } from '../../srs';
6
6
  import { ArenaTaxonomy } from '../../taxonomy';
7
7
  import { ArenaSurvey } from '../survey';
8
- export declare const getName: (survey: ArenaSurvey) => string;
9
- export declare const getLanguages: (survey: ArenaSurvey) => LanguageCode[];
10
- export declare const getDefaultLanguage: (survey: ArenaSurvey) => LanguageCode;
11
- export declare const getLabel: (langCode?: LanguageCode) => (survey: ArenaSurvey) => string | undefined;
12
- export declare const getDescription: (langCode?: LanguageCode) => (survey: ArenaSurvey) => string | undefined;
13
- export declare const getFieldManualLink: (langCode?: LanguageCode) => (survey: ArenaSurvey) => string | undefined;
8
+ import type { ArenaSurveyOrSummary } from '../surveySummary';
9
+ export declare const getName: (survey: ArenaSurveyOrSummary) => string;
10
+ export declare const getLanguages: (survey: ArenaSurveyOrSummary) => LanguageCode[];
11
+ export declare const getDefaultLanguage: (survey: ArenaSurveyOrSummary) => LanguageCode;
12
+ export declare const getLabel: (langCode?: LanguageCode) => (survey: ArenaSurveyOrSummary) => string | undefined;
13
+ export declare const getDescription: (langCode?: LanguageCode) => (survey: ArenaSurveyOrSummary) => string | undefined;
14
+ export declare const getFieldManualLink: (langCode?: LanguageCode) => (survey: ArenaSurveyOrSummary) => string | undefined;
14
15
  /**
15
16
  * Returns the survey label in the specified language (the default language if not specified), or the survey name
16
17
  * when the label is missing or empty.
17
18
  */
18
- export declare const getLabelOrName: (langCode?: LanguageCode) => (survey: ArenaSurvey) => string;
19
+ export declare const getLabelOrName: (langCode?: LanguageCode) => (survey: ArenaSurveyOrSummary) => string;
19
20
  export declare const getCategoryByName: (params: {
20
21
  survey: ArenaSurvey;
21
22
  categoryName: string;
@@ -32,16 +33,16 @@ export declare const getTaxonomyByUuid: (params: {
32
33
  survey: ArenaSurvey;
33
34
  taxonomyUuid: string;
34
35
  }) => ArenaTaxonomy | undefined;
35
- export declare const getCycleKeys: (survey: ArenaSurvey) => string[];
36
- export declare const getLastCycleKey: (survey: ArenaSurvey) => string;
37
- export declare const isKeepNonApplicableValues: (survey: ArenaSurvey) => boolean;
38
- export declare const getDefaultCycleKey: (survey: ArenaSurvey) => string | undefined;
39
- export declare const getSRSs: (survey: ArenaSurvey) => ArenaSRS[];
40
- export declare const getSRSIndex: (survey: ArenaSurvey) => ArenaSRSIndex;
41
- export declare const getSRSByCode: (code: string) => (survey: ArenaSurvey) => ArenaSRS | undefined;
42
- export declare const getAreasOfInterest: (survey: ArenaSurvey) => ArenaAreaOfInterestDescriptor[];
36
+ export declare const getCycleKeys: (survey: ArenaSurveyOrSummary) => string[];
37
+ export declare const getLastCycleKey: (survey: ArenaSurveyOrSummary) => string;
38
+ export declare const isKeepNonApplicableValues: (survey: ArenaSurveyOrSummary) => boolean;
39
+ export declare const getDefaultCycleKey: (survey: ArenaSurveyOrSummary) => string | undefined;
40
+ export declare const getSRSs: (survey: ArenaSurveyOrSummary) => ArenaSRS[];
41
+ export declare const getSRSIndex: (survey: ArenaSurveyOrSummary) => ArenaSRSIndex;
42
+ export declare const getSRSByCode: (code: string) => (survey: ArenaSurveyOrSummary) => ArenaSRS | undefined;
43
+ export declare const getAreasOfInterest: (survey: ArenaSurveyOrSummary) => ArenaAreaOfInterestDescriptor[];
43
44
  export declare const getAreaOfInterestByName: (params: {
44
- survey: ArenaSurvey;
45
+ survey: ArenaSurveyOrSummary;
45
46
  name: string;
46
47
  }) => ArenaAreaOfInterestDescriptor | undefined;
47
48
  export declare const getAuthGroups: (survey: ArenaSurvey) => ArenaUserAuthGroup[];
@@ -1 +1 @@
1
- {"version":3,"file":"surveysGetters.js","sourceRoot":"","sources":["../../../src/survey/surveys/surveysGetters.ts"],"names":[],"mappings":";;;AAAA,qCAA8D;AAI9D,kDAAyD;AAGzD,uCAA6C;AAGtC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAA;AAA5D,QAAA,OAAO,GAAP,OAAO,CAAqD;AAElE,MAAM,YAAY,GAAG,CAAC,MAAmB,EAAkB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAA;AAA9E,QAAA,YAAY,GAAZ,YAAY,CAAk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,CAAC,CAAA;AAD5E,QAAA,iBAAiB,GAAjB,iBAAiB,CAC2D","sourcesContent":["import { AuthGroupName, ArenaUserAuthGroup } from '../../auth'\nimport { ArenaCategory } from '../../category'\nimport type { ArenaAreaOfInterestDescriptor } from '../../geo'\nimport { LanguageCode } from '../../language'\nimport { getLabelOrDefault } from '../../language/labels'\nimport { ArenaSRS, ArenaSRSIndex } from '../../srs'\nimport { ArenaTaxonomy } from '../../taxonomy'\nimport { Arrays, Objects } from '../../utils'\nimport { ArenaSurvey } from '../survey'\n\nexport const getName = (survey: ArenaSurvey): string => survey.props.name\n\nexport const getLanguages = (survey: ArenaSurvey): LanguageCode[] => survey.props.languages\n\nexport const getDefaultLanguage = (survey: ArenaSurvey): LanguageCode => getLanguages(survey)[0]\n\nconst getMultilangPropValue =\n (prop: 'labels' | 'descriptions' | 'fieldManualLinks') =>\n (langCode?: LanguageCode) =>\n (survey: ArenaSurvey): string | undefined => {\n const languageCode = langCode ?? getDefaultLanguage(survey)\n return survey.props[prop]?.[languageCode]\n }\nexport const getLabel = getMultilangPropValue('labels')\nexport const getDescription = getMultilangPropValue('descriptions')\nexport const getFieldManualLink = getMultilangPropValue('fieldManualLinks')\n\n/**\n * Returns the survey label in the specified language (the default language if not specified), or the survey name\n * when the label is missing or empty.\n */\nexport const getLabelOrName =\n (langCode?: LanguageCode) =>\n (survey: ArenaSurvey): string =>\n getLabelOrDefault(survey.props.labels, langCode ?? getDefaultLanguage(survey), getName(survey))\n\nexport const getCategoryByName = (params: { survey: ArenaSurvey; categoryName: string }): ArenaCategory | undefined => {\n const { survey, categoryName } = params\n return survey.categories\n ? Object.values(survey.categories).find((category) => category.props.name === categoryName)\n : undefined\n}\n\nexport const getCategoryByUuid = (params: { survey: ArenaSurvey; categoryUuid: string }): ArenaCategory | undefined => {\n const { survey, categoryUuid } = params\n return survey.categories?.[categoryUuid]\n}\n\nexport const getTaxonomyByName = (params: { survey: ArenaSurvey; taxonomyName: string }): ArenaTaxonomy | undefined => {\n const { survey, taxonomyName } = params\n return survey.taxonomies\n ? Object.values(survey.taxonomies).find((taxonomy) => taxonomy.props.name === taxonomyName)\n : undefined\n}\n\nexport const getTaxonomyByUuid = (params: { survey: ArenaSurvey; taxonomyUuid: string }): ArenaTaxonomy | undefined => {\n const { survey, taxonomyUuid } = params\n return survey.taxonomies?.[taxonomyUuid]\n}\n\nexport const getCycleKeys = (survey: ArenaSurvey): string[] => {\n const cycles = survey.props?.cycles ?? {}\n return Object.keys(cycles)\n}\n\nexport const getLastCycleKey = (survey: ArenaSurvey): string => Arrays.last(getCycleKeys(survey)) as string\n\nexport const isKeepNonApplicableValues = (survey: ArenaSurvey): boolean =>\n survey?.props?.keepNonApplicableValues === true\n\nexport const getDefaultCycleKey = (survey: ArenaSurvey) => {\n const defaultCycleKey = survey.props?.defaultCycleKey\n const lastCycleKey = getLastCycleKey(survey)\n return Objects.isEmpty(defaultCycleKey) || Number(defaultCycleKey) > Number(lastCycleKey)\n ? lastCycleKey\n : defaultCycleKey\n}\n\nexport const getSRSs = (survey: ArenaSurvey): ArenaSRS[] =>\n survey.props?.srs ??\n // backwards compatibility with Arena: srs stored in info in UI\n (survey as any).info?.props?.srs ??\n []\n\nexport const getSRSIndex = (survey: ArenaSurvey): ArenaSRSIndex =>\n getSRSs(survey).reduce((acc: ArenaSRSIndex, srs) => {\n acc[srs.code] = srs\n return acc\n }, {})\n\nexport const getSRSByCode =\n (code: string) =>\n (survey: ArenaSurvey): ArenaSRS | undefined =>\n getSRSIndex(survey)[code]\n\nexport const getAreasOfInterest = (survey: ArenaSurvey): ArenaAreaOfInterestDescriptor[] =>\n survey?.props?.areasOfInterest ??\n // backwards compatibility with Arena: survey info props stored in info\n (survey as any)?.info?.props?.areasOfInterest ??\n []\n\nexport const getAreaOfInterestByName = (params: {\n survey: ArenaSurvey\n name: string\n}): ArenaAreaOfInterestDescriptor | undefined =>\n getAreasOfInterest(params.survey).find((areaOfInterest) => areaOfInterest.name === params.name)\n\nexport const getAuthGroups = (survey: ArenaSurvey): ArenaUserAuthGroup[] => survey?.authGroups ?? []\n\nexport const getAuthGroupAdmin = (survey: ArenaSurvey): ArenaUserAuthGroup | undefined =>\n getAuthGroups(survey).find((authGroup) => authGroup.name === AuthGroupName.surveyAdmin)\n"]}
1
+ {"version":3,"file":"surveysGetters.js","sourceRoot":"","sources":["../../../src/survey/surveys/surveysGetters.ts"],"names":[],"mappings":";;;AAAA,qCAA8D;AAI9D,kDAAyD;AAGzD,uCAA6C;AAItC,MAAM,OAAO,GAAG,CAAC,MAA4B,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAA;AAArE,QAAA,OAAO,GAAP,OAAO,CAA8D;AAE3E,MAAM,YAAY,GAAG,CAAC,MAA4B,EAAkB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAA;AAAvF,QAAA,YAAY,GAAZ,YAAY,CAA2E;AAE7F,MAAM,kBAAkB,GAAG,CAAC,MAA4B,EAAgB,EAAE,CAAC,IAAA,QAAA,YAAY,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAA5F,QAAA,kBAAkB,GAAlB,kBAAkB,CAA0E;AAEzG,MAAM,qBAAqB,GACzB,CAAC,IAAoD,EAAE,EAAE,CACzD,CAAC,QAAuB,EAAE,EAAE,CAC5B,CAAC,MAA4B,EAAsB,EAAE;;IACnD,MAAM,YAAY,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,IAAA,QAAA,kBAAkB,EAAC,MAAM,CAAC,CAAA;IAC3D,OAAO,MAAA,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,0CAAG,YAAY,CAAC,CAAA;AAC3C,CAAC,CAAA;AACU,QAAA,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAA;AAC1C,QAAA,cAAc,GAAG,qBAAqB,CAAC,cAAc,CAAC,CAAA;AACtD,QAAA,kBAAkB,GAAG,qBAAqB,CAAC,kBAAkB,CAAC,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AAE,CAC9C,IAAA,QAAA,kBAAkB,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,CAAA;AAJpF,QAAA,uBAAuB,GAAvB,uBAAuB,CAI6D;AAE1F,MAAM,aAAa,GAAG,CAAC,MAAmB,EAAwB,EAAE,wBAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,mCAAI,EAAE,GAAA,CAAA;AAAvF,QAAA,aAAa,GAAb,aAAa,CAA0E;AAE7F,MAAM,iBAAiB,GAAG,CAAC,MAAmB,EAAkC,EAAE,CACvF,IAAA,QAAA,aAAa,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,oBAAa,CAAC,WAAW,CAAC,CAAA;AAD5E,QAAA,iBAAiB,GAAjB,iBAAiB,CAC2D","sourcesContent":["import { AuthGroupName, ArenaUserAuthGroup } from '../../auth'\nimport { ArenaCategory } from '../../category'\nimport type { ArenaAreaOfInterestDescriptor } from '../../geo'\nimport { LanguageCode } from '../../language'\nimport { getLabelOrDefault } from '../../language/labels'\nimport { ArenaSRS, ArenaSRSIndex } from '../../srs'\nimport { ArenaTaxonomy } from '../../taxonomy'\nimport { Arrays, Objects } from '../../utils'\nimport { ArenaSurvey } from '../survey'\nimport type { ArenaSurveyOrSummary } from '../surveySummary'\n\nexport const getName = (survey: ArenaSurveyOrSummary): string => survey.props.name\n\nexport const getLanguages = (survey: ArenaSurveyOrSummary): LanguageCode[] => survey.props.languages\n\nexport const getDefaultLanguage = (survey: ArenaSurveyOrSummary): LanguageCode => getLanguages(survey)[0]\n\nconst getMultilangPropValue =\n (prop: 'labels' | 'descriptions' | 'fieldManualLinks') =>\n (langCode?: LanguageCode) =>\n (survey: ArenaSurveyOrSummary): string | undefined => {\n const languageCode = langCode ?? getDefaultLanguage(survey)\n return survey.props[prop]?.[languageCode]\n }\nexport const getLabel = getMultilangPropValue('labels')\nexport const getDescription = getMultilangPropValue('descriptions')\nexport const getFieldManualLink = getMultilangPropValue('fieldManualLinks')\n\n/**\n * Returns the survey label in the specified language (the default language if not specified), or the survey name\n * when the label is missing or empty.\n */\nexport const getLabelOrName =\n (langCode?: LanguageCode) =>\n (survey: ArenaSurveyOrSummary): string =>\n getLabelOrDefault(survey.props.labels, langCode ?? getDefaultLanguage(survey), getName(survey))\n\nexport const getCategoryByName = (params: { survey: ArenaSurvey; categoryName: string }): ArenaCategory | undefined => {\n const { survey, categoryName } = params\n return survey.categories\n ? Object.values(survey.categories).find((category) => category.props.name === categoryName)\n : undefined\n}\n\nexport const getCategoryByUuid = (params: { survey: ArenaSurvey; categoryUuid: string }): ArenaCategory | undefined => {\n const { survey, categoryUuid } = params\n return survey.categories?.[categoryUuid]\n}\n\nexport const getTaxonomyByName = (params: { survey: ArenaSurvey; taxonomyName: string }): ArenaTaxonomy | undefined => {\n const { survey, taxonomyName } = params\n return survey.taxonomies\n ? Object.values(survey.taxonomies).find((taxonomy) => taxonomy.props.name === taxonomyName)\n : undefined\n}\n\nexport const getTaxonomyByUuid = (params: { survey: ArenaSurvey; taxonomyUuid: string }): ArenaTaxonomy | undefined => {\n const { survey, taxonomyUuid } = params\n return survey.taxonomies?.[taxonomyUuid]\n}\n\nexport const getCycleKeys = (survey: ArenaSurveyOrSummary): string[] => {\n const cycles = survey.props?.cycles ?? {}\n return Object.keys(cycles)\n}\n\nexport const getLastCycleKey = (survey: ArenaSurveyOrSummary): string => Arrays.last(getCycleKeys(survey)) as string\n\nexport const isKeepNonApplicableValues = (survey: ArenaSurveyOrSummary): boolean =>\n survey?.props?.keepNonApplicableValues === true\n\nexport const getDefaultCycleKey = (survey: ArenaSurveyOrSummary) => {\n const defaultCycleKey = survey.props?.defaultCycleKey\n const lastCycleKey = getLastCycleKey(survey)\n return Objects.isEmpty(defaultCycleKey) || Number(defaultCycleKey) > Number(lastCycleKey)\n ? lastCycleKey\n : defaultCycleKey\n}\n\nexport const getSRSs = (survey: ArenaSurveyOrSummary): ArenaSRS[] =>\n survey.props?.srs ??\n // backwards compatibility with Arena: srs stored in info in UI\n (survey as any).info?.props?.srs ??\n []\n\nexport const getSRSIndex = (survey: ArenaSurveyOrSummary): ArenaSRSIndex =>\n getSRSs(survey).reduce((acc: ArenaSRSIndex, srs) => {\n acc[srs.code] = srs\n return acc\n }, {})\n\nexport const getSRSByCode =\n (code: string) =>\n (survey: ArenaSurveyOrSummary): ArenaSRS | undefined =>\n getSRSIndex(survey)[code]\n\nexport const getAreasOfInterest = (survey: ArenaSurveyOrSummary): ArenaAreaOfInterestDescriptor[] =>\n survey?.props?.areasOfInterest ??\n // backwards compatibility with Arena: survey info props stored in info\n (survey as any)?.info?.props?.areasOfInterest ??\n []\n\nexport const getAreaOfInterestByName = (params: {\n survey: ArenaSurveyOrSummary\n name: string\n}): ArenaAreaOfInterestDescriptor | undefined =>\n getAreasOfInterest(params.survey).find((areaOfInterest) => areaOfInterest.name === params.name)\n\nexport const getAuthGroups = (survey: ArenaSurvey): ArenaUserAuthGroup[] => survey?.authGroups ?? []\n\nexport const getAuthGroupAdmin = (survey: ArenaSurvey): ArenaUserAuthGroup | undefined =>\n getAuthGroups(survey).find((authGroup) => authGroup.name === AuthGroupName.surveyAdmin)\n"]}
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Extracts the value in the specified path from the specified object.
3
3
  *
4
+ * @template T - Expected type of the value.
4
5
  * @param {array|string} path - Array of path parts or string with parts concatenated with dots.
5
6
  * @returns {any} Value at the specified path.
6
7
  */
7
- export declare const path: (path: Array<string> | string) => (obj: any) => any;
8
+ export declare const path: <T = any>(path: Array<string> | string) => (obj: any) => T | null | undefined;
@@ -4,6 +4,7 @@ exports.path = void 0;
4
4
  /**
5
5
  * Extracts the value in the specified path from the specified object.
6
6
  *
7
+ * @template T - Expected type of the value.
7
8
  * @param {array|string} path - Array of path parts or string with parts concatenated with dots.
8
9
  * @returns {any} Value at the specified path.
9
10
  */
@@ -1 +1 @@
1
- {"version":3,"file":"path.js","sourceRoot":"","sources":["../../../src/utils/_objects/path.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,MAAM,IAAI,GACf,CAAC,IAA4B,EAAE,EAAE,CACjC,CAAC,GAAQ,EAAO,EAAE;IAChB,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAA;IAErB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1D,IAAI,OAAO,GAAG,GAAG,CAAA;IACjB,IAAI,CAAC,GAAG,CAAC,CAAA;IAET,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACrB,kEAAkE;QAClE,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,IAAI,CAAC,MAAK,SAAS,EAAE,CAAC;YAClC,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAlBU,QAAA,IAAI,GAAJ,IAAI,CAkBd","sourcesContent":["/**\n * Extracts the value in the specified path from the specified object.\n *\n * @param {array|string} path - Array of path parts or string with parts concatenated with dots.\n * @returns {any} Value at the specified path.\n */\nexport const path =\n (path: Array<string> | string) =>\n (obj: any): any => {\n if (!obj) return null\n\n const parts = Array.isArray(path) ? path : path.split('.')\n let current = obj\n let i = 0\n\n for (; i < parts.length; i++) {\n const part = parts[i]\n // stop when a value along the path is missing (undefined) or null\n if (current?.[part] === undefined) {\n return undefined\n }\n current = current[part]\n }\n return current\n }\n"]}
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../../../src/utils/_objects/path.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACI,MAAM,IAAI,GACf,CAAU,IAA4B,EAAE,EAAE,CAC1C,CAAC,GAAQ,EAAwB,EAAE;IACjC,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAA;IAErB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1D,IAAI,OAAO,GAAG,GAAG,CAAA;IACjB,IAAI,CAAC,GAAG,CAAC,CAAA;IAET,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACrB,kEAAkE;QAClE,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,IAAI,CAAC,MAAK,SAAS,EAAE,CAAC;YAClC,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAlBU,QAAA,IAAI,GAAJ,IAAI,CAkBd","sourcesContent":["/**\n * Extracts the value in the specified path from the specified object.\n *\n * @template T - Expected type of the value.\n * @param {array|string} path - Array of path parts or string with parts concatenated with dots.\n * @returns {any} Value at the specified path.\n */\nexport const path =\n <T = any>(path: Array<string> | string) =>\n (obj: any): T | null | undefined => {\n if (!obj) return null\n\n const parts = Array.isArray(path) ? path : path.split('.')\n let current = obj\n let i = 0\n\n for (; i < parts.length; i++) {\n const part = parts[i]\n // stop when a value along the path is missing (undefined) or null\n if (current?.[part] === undefined) {\n return undefined\n }\n current = current[part]\n }\n return current\n }\n"]}
@@ -1,15 +1,28 @@
1
- type ChunkProcessor = (args: {
1
+ /**
2
+ * Chunk written to a temporary file, in the form accepted by React Native FormData.
3
+ */
4
+ export type ArenaFileProcessorUriChunk = {
5
+ uri: string;
6
+ type: string;
7
+ name: string;
8
+ };
9
+ export type ArenaFileProcessorChunk = Blob | string | Uint8Array | ArenaFileProcessorUriChunk;
10
+ type DefaultChunk = Blob | string | Uint8Array;
11
+ type ChunkProcessor<C, R> = (args: {
2
12
  chunk: number;
3
- content: Blob | string | Uint8Array;
13
+ content: C;
4
14
  totalChunks: number;
5
15
  totalFileSize: number;
6
- }) => Promise<any>;
7
- export type ArenaFileProcessorConstructorArgs = {
16
+ }) => Promise<R>;
17
+ /**
18
+ * C: type of the chunks extracted from the file, R: result of the chunk processor.
19
+ */
20
+ export type ArenaFileProcessorConstructorArgs<C extends ArenaFileProcessorChunk = DefaultChunk, R = any> = {
8
21
  file?: File;
9
22
  filePath?: string;
10
- chunkProcessor: ChunkProcessor;
23
+ chunkProcessor: ChunkProcessor<C, R>;
11
24
  onError?: (error: Error) => void;
12
- onComplete?: (result: any) => void;
25
+ onComplete?: (result?: R) => void;
13
26
  chunkSize?: number;
14
27
  maxTryings?: number;
15
28
  /**
@@ -17,14 +30,14 @@ export type ArenaFileProcessorConstructorArgs = {
17
30
  */
18
31
  retryDelay?: number;
19
32
  };
20
- export declare class FileProcessor {
33
+ export declare class FileProcessor<C extends ArenaFileProcessorChunk = DefaultChunk, R = any> {
21
34
  static readonly defaultChunkSize: number;
22
35
  static readonly defaultMaxTryings = 5;
23
36
  static readonly defaultRetryDelay = 1000;
24
37
  private readonly file?;
25
- private readonly filePath?;
38
+ protected readonly filePath?: string;
26
39
  private readonly chunkProcessor;
27
- private readonly chunkSize;
40
+ protected readonly chunkSize: number;
28
41
  private readonly maxTryings;
29
42
  private readonly retryDelay;
30
43
  private readonly onError?;
@@ -37,12 +50,12 @@ export declare class FileProcessor {
37
50
  protected completed: boolean;
38
51
  private runId;
39
52
  private retryProcessor?;
40
- constructor({ file, filePath, chunkProcessor, onError, onComplete, chunkSize, maxTryings, retryDelay, }: ArenaFileProcessorConstructorArgs);
53
+ constructor({ file, filePath, chunkProcessor, onError, onComplete, chunkSize, maxTryings, retryDelay, }: ArenaFileProcessorConstructorArgs<C, R>);
41
54
  private cancelCurrentRun;
42
55
  protected reset(): void;
43
56
  protected calculateFileSize(): Promise<number>;
44
57
  protected onFail(error: Error): void;
45
- protected extractCurrentFileChunk(): Promise<Blob | string | Uint8Array>;
58
+ protected extractCurrentFileChunk(): Promise<C>;
46
59
  protected processNextChunk(): void;
47
60
  start(startFromChunk?: number): void;
48
61
  stop(): void;
@@ -51,6 +51,7 @@ class FileProcessor {
51
51
  var _a;
52
52
  (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, error);
53
53
  }
54
+ // subclasses using another chunk type (e.g. reading from filePath) override it
54
55
  extractCurrentFileChunk() {
55
56
  const { file, currentChunkNumber, totalChunks, chunkSize } = this;
56
57
  if (!file) {
@@ -1 +1 @@
1
- {"version":3,"file":"fileProcessor.js","sourceRoot":"","sources":["../../src/utils/fileProcessor.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAuBjD;IA0BE,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,OAAO,EACP,UAAU,EACV,SAAS,GAAG,aAAa,CAAC,gBAAgB,EAC1C,UAAU,GAAG,aAAa,CAAC,iBAAiB,EAC5C,UAAU,GAAG,aAAa,CAAC,iBAAiB,GACV;QArBpC,mBAAmB;QACT,kBAAa,GAAW,CAAC,CAAA;QACzB,YAAO,GAAY,KAAK,CAAA;QACxB,gBAAW,GAAW,CAAC,CAAA;QACvB,uBAAkB,GAAW,CAAC,CAAA;QACxC,0FAA0F;QAChF,oBAAe,GAAY,KAAK,CAAA;QAChC,cAAS,GAAY,KAAK,CAAA;QACpC,qGAAqG;QAC7F,UAAK,GAAW,CAAC,CAAA;QAavB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAA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AC,OAAO;AAC3C,+BAAiB,GAAG,CAAC,AAAJ,CAAI;AACrB,+BAAiB,GAAG,IAAI,AAAP,CAAO,CAAC,qBAAqB","sourcesContent":["import { RetryProcessor } from './retryProcessor'\n\ntype ChunkProcessor = (args: {\n chunk: number\n content: Blob | string | Uint8Array\n totalChunks: number\n totalFileSize: number\n}) => Promise<any>\n\nexport type ArenaFileProcessorConstructorArgs = {\n file?: File\n filePath?: string\n chunkProcessor: ChunkProcessor\n onError?: (error: Error) => void\n onComplete?: (result: any) => void\n chunkSize?: number\n maxTryings?: number\n /**\n * Delay (in milliseconds) before retrying a failed chunk, doubled at every further retry.\n */\n retryDelay?: number\n}\n\nexport class FileProcessor {\n static readonly defaultChunkSize = 1024 * 1024 * 10 // 10MB\n static readonly defaultMaxTryings = 5\n static readonly defaultRetryDelay = 1000 // 1s, then 2s, 4s...\n\n private readonly file?: File\n private readonly filePath?: string\n private readonly chunkProcessor: ChunkProcessor\n private readonly chunkSize: number\n private readonly maxTryings: number\n private readonly retryDelay: number\n private readonly onError?: (error: Error) => void\n private readonly onComplete?: (result?: any) => void\n\n // State properties\n protected totalFileSize: number = 0\n protected running: boolean = false\n protected totalChunks: number = 0\n protected currentChunkNumber: number = 0\n // true while a chunk is being processed (resume must not start a second processing chain)\n protected processingChunk: boolean = false\n protected completed: boolean = false\n // incremented when a processing run is stopped: callbacks of the chunks of previous runs are ignored\n private runId: number = 0\n private retryProcessor?: RetryProcessor<any>\n\n constructor({\n file,\n filePath,\n chunkProcessor,\n onError,\n onComplete,\n chunkSize = FileProcessor.defaultChunkSize,\n maxTryings = FileProcessor.defaultMaxTryings,\n retryDelay = FileProcessor.defaultRetryDelay,\n }: ArenaFileProcessorConstructorArgs) {\n this.file = file\n this.filePath = filePath\n this.chunkProcessor = chunkProcessor\n this.chunkSize = chunkSize\n this.maxTryings = maxTryings\n this.retryDelay = retryDelay\n this.onError = onError\n this.onComplete = onComplete\n\n if (!this.file && !this.filePath) {\n throw new Error('File or filePath not specified')\n }\n\n this.reset()\n }\n\n private cancelCurrentRun(): void {\n this.runId += 1\n this.retryProcessor?.stop()\n this.retryProcessor = undefined\n }\n\n protected reset(): void {\n this.cancelCurrentRun()\n this.running = false\n this.totalChunks = 0\n this.currentChunkNumber = 0\n this.totalFileSize = 0\n this.processingChunk = false\n this.completed = false\n }\n\n protected calculateFileSize(): Promise<number> {\n return Promise.resolve(this.file?.size ?? 0)\n }\n\n protected onFail(error: Error): void {\n this.onError?.(error)\n }\n\n protected extractCurrentFileChunk(): Promise<Blob | string | Uint8Array> {\n const { file, currentChunkNumber, totalChunks, chunkSize } = this\n if (!file) {\n return Promise.reject(new Error('File property not initialized'))\n }\n return Promise.resolve(\n file.slice(\n (currentChunkNumber - 1) * chunkSize,\n currentChunkNumber === totalChunks ? undefined : currentChunkNumber * chunkSize\n )\n )\n }\n\n protected processNextChunk(): void {\n const { chunkProcessor, currentChunkNumber, totalFileSize, totalChunks, maxTryings, retryDelay, runId } = this\n const isStale = () => runId !== this.runId\n\n this.processingChunk = true\n this.extractCurrentFileChunk()\n .then((content) => {\n if (isStale()) return\n const retryProcessor = new RetryProcessor<any>({\n processor: () => chunkProcessor({ chunk: currentChunkNumber, totalFileSize, totalChunks, content }),\n onSuccess: (chunkResult) => {\n if (isStale()) return\n this.processingChunk = false\n if (this.currentChunkNumber < totalChunks) {\n // move to the next chunk also when paused: resume will continue from it\n this.currentChunkNumber += 1\n if (this.running) {\n this.processNextChunk()\n }\n } else {\n this.running = false\n this.completed = true\n // called outside the retried processor: if it throws, the last chunk is not processed again\n this.onComplete?.(chunkResult)\n }\n },\n onFail: (error: Error) => {\n if (isStale()) return\n this.processingChunk = false\n this.onFail(error)\n this.running = false\n },\n maxTryings,\n retryDelay,\n })\n this.retryProcessor = retryProcessor\n retryProcessor.start()\n })\n .catch((error) => {\n if (isStale()) return\n this.processingChunk = false\n this.onFail(error)\n this.running = false\n })\n }\n\n start(startFromChunk: number = 1): void {\n // a previous run still in progress must not continue in parallel\n this.cancelCurrentRun()\n const { runId } = this\n this.processingChunk = false\n this.running = true\n this.completed = false\n this.currentChunkNumber = startFromChunk\n this.calculateFileSize()\n .then((fileSize) => {\n if (runId !== this.runId) return\n this.totalFileSize = fileSize\n this.totalChunks = Math.ceil(fileSize / this.chunkSize)\n if (this.totalChunks > 0) {\n this.processNextChunk()\n } else {\n // empty file: nothing to process, complete immediately (callers wait for onComplete)\n this.running = false\n this.completed = true\n this.onComplete?.()\n }\n })\n .catch((error) => {\n if (runId !== this.runId) return\n this.onFail(error)\n this.running = false\n })\n }\n\n stop(): void {\n this.reset()\n }\n\n pause(): void {\n this.running = false\n }\n\n resume(): void {\n if (this.running || this.completed) return\n this.running = true\n // if a chunk is still being processed, processing continues when it completes\n if (!this.processingChunk && this.totalChunks > 0) {\n this.processNextChunk()\n }\n }\n}\n"]}
1
+ {"version":3,"file":"fileProcessor.js","sourceRoot":"","sources":["../../src/utils/fileProcessor.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAoCjD;IA0BE,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,OAAO,EACP,UAAU,EACV,SAAS,GAAG,aAAa,CAAC,gBAAgB,EAC1C,UAAU,GAAG,aAAa,CAAC,iBAAiB,EAC5C,UAAU,GAAG,aAAa,CAAC,iBAAiB,GACJ;QArB1C,mBAAmB;QACT,kBAAa,GAAW,CAAC,CAAA;QACzB,YAAO,GAAY,KAAK,CAAA;QACxB,gBAAW,GAAW,CAAC,CAAA;QACvB,uBAAkB,GAAW,CAAC,CAAA;QACxC,0FAA0F;QAChF,oBAAe,GAAY,KAAK,CAAA;QAChC,cAAS,GAAY,KAAK,CAAA;QACpC,qGAAqG;QAC7F,UAAK,GAAW,CAAC,CAAA;QAavB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,SAAS,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iB,GAAG,IAAI,AAAP,CAAO,CAAC,qBAAqB","sourcesContent":["import { RetryProcessor } from './retryProcessor'\n\n/**\n * Chunk written to a temporary file, in the form accepted by React Native FormData.\n */\nexport type ArenaFileProcessorUriChunk = { uri: string; type: string; name: string }\n\nexport type ArenaFileProcessorChunk = Blob | string | Uint8Array | ArenaFileProcessorUriChunk\n\ntype DefaultChunk = Blob | string | Uint8Array\n\ntype ChunkProcessor<C, R> = (args: {\n chunk: number\n content: C\n totalChunks: number\n totalFileSize: number\n}) => Promise<R>\n\n/**\n * C: type of the chunks extracted from the file, R: result of the chunk processor.\n */\nexport type ArenaFileProcessorConstructorArgs<C extends ArenaFileProcessorChunk = DefaultChunk, R = any> = {\n file?: File\n filePath?: string\n chunkProcessor: ChunkProcessor<C, R>\n onError?: (error: Error) => void\n // result of the last chunk (undefined for empty files)\n onComplete?: (result?: R) => void\n chunkSize?: number\n maxTryings?: number\n /**\n * Delay (in milliseconds) before retrying a failed chunk, doubled at every further retry.\n */\n retryDelay?: number\n}\n\nexport class FileProcessor<C extends ArenaFileProcessorChunk = DefaultChunk, R = any> {\n static readonly defaultChunkSize = 1024 * 1024 * 10 // 10MB\n static readonly defaultMaxTryings = 5\n static readonly defaultRetryDelay = 1000 // 1s, then 2s, 4s...\n\n private readonly file?: File\n protected readonly filePath?: string\n private readonly chunkProcessor: ChunkProcessor<C, R>\n protected readonly chunkSize: number\n private readonly maxTryings: number\n private readonly retryDelay: number\n private readonly onError?: (error: Error) => void\n private readonly onComplete?: (result?: R) => void\n\n // State properties\n protected totalFileSize: number = 0\n protected running: boolean = false\n protected totalChunks: number = 0\n protected currentChunkNumber: number = 0\n // true while a chunk is being processed (resume must not start a second processing chain)\n protected processingChunk: boolean = false\n protected completed: boolean = false\n // incremented when a processing run is stopped: callbacks of the chunks of previous runs are ignored\n private runId: number = 0\n private retryProcessor?: RetryProcessor<R>\n\n constructor({\n file,\n filePath,\n chunkProcessor,\n onError,\n onComplete,\n chunkSize = FileProcessor.defaultChunkSize,\n maxTryings = FileProcessor.defaultMaxTryings,\n retryDelay = FileProcessor.defaultRetryDelay,\n }: ArenaFileProcessorConstructorArgs<C, R>) {\n this.file = file\n this.filePath = filePath\n this.chunkProcessor = chunkProcessor\n this.chunkSize = chunkSize\n this.maxTryings = maxTryings\n this.retryDelay = retryDelay\n this.onError = onError\n this.onComplete = onComplete\n\n if (!this.file && !this.filePath) {\n throw new Error('File or filePath not specified')\n }\n\n this.reset()\n }\n\n private cancelCurrentRun(): void {\n this.runId += 1\n this.retryProcessor?.stop()\n this.retryProcessor = undefined\n }\n\n protected reset(): void {\n this.cancelCurrentRun()\n this.running = false\n this.totalChunks = 0\n this.currentChunkNumber = 0\n this.totalFileSize = 0\n this.processingChunk = false\n this.completed = false\n }\n\n protected calculateFileSize(): Promise<number> {\n return Promise.resolve(this.file?.size ?? 0)\n }\n\n protected onFail(error: Error): void {\n this.onError?.(error)\n }\n\n // subclasses using another chunk type (e.g. reading from filePath) override it\n protected extractCurrentFileChunk(): Promise<C> {\n const { file, currentChunkNumber, totalChunks, chunkSize } = this\n if (!file) {\n return Promise.reject(new Error('File property not initialized'))\n }\n return Promise.resolve(\n file.slice(\n (currentChunkNumber - 1) * chunkSize,\n currentChunkNumber === totalChunks ? undefined : currentChunkNumber * chunkSize\n ) as C\n )\n }\n\n protected processNextChunk(): void {\n const { chunkProcessor, currentChunkNumber, totalFileSize, totalChunks, maxTryings, retryDelay, runId } = this\n const isStale = () => runId !== this.runId\n\n this.processingChunk = true\n this.extractCurrentFileChunk()\n .then((content) => {\n if (isStale()) return\n const retryProcessor = new RetryProcessor<R>({\n processor: () => chunkProcessor({ chunk: currentChunkNumber, totalFileSize, totalChunks, content }),\n onSuccess: (chunkResult) => {\n if (isStale()) return\n this.processingChunk = false\n if (this.currentChunkNumber < totalChunks) {\n // move to the next chunk also when paused: resume will continue from it\n this.currentChunkNumber += 1\n if (this.running) {\n this.processNextChunk()\n }\n } else {\n this.running = false\n this.completed = true\n // called outside the retried processor: if it throws, the last chunk is not processed again\n this.onComplete?.(chunkResult)\n }\n },\n onFail: (error: Error) => {\n if (isStale()) return\n this.processingChunk = false\n this.onFail(error)\n this.running = false\n },\n maxTryings,\n retryDelay,\n })\n this.retryProcessor = retryProcessor\n retryProcessor.start()\n })\n .catch((error) => {\n if (isStale()) return\n this.processingChunk = false\n this.onFail(error)\n this.running = false\n })\n }\n\n start(startFromChunk: number = 1): void {\n // a previous run still in progress must not continue in parallel\n this.cancelCurrentRun()\n const { runId } = this\n this.processingChunk = false\n this.running = true\n this.completed = false\n this.currentChunkNumber = startFromChunk\n this.calculateFileSize()\n .then((fileSize) => {\n if (runId !== this.runId) return\n this.totalFileSize = fileSize\n this.totalChunks = Math.ceil(fileSize / this.chunkSize)\n if (this.totalChunks > 0) {\n this.processNextChunk()\n } else {\n // empty file: nothing to process, complete immediately (callers wait for onComplete)\n this.running = false\n this.completed = true\n this.onComplete?.()\n }\n })\n .catch((error) => {\n if (runId !== this.runId) return\n this.onFail(error)\n this.running = false\n })\n }\n\n stop(): void {\n this.reset()\n }\n\n pause(): void {\n this.running = false\n }\n\n resume(): void {\n if (this.running || this.completed) return\n this.running = true\n // if a chunk is still being processed, processing continues when it completes\n if (!this.processingChunk && this.totalChunks > 0) {\n this.processNextChunk()\n }\n }\n}\n"]}
@@ -3,7 +3,7 @@ export { Dates, DateFormats, UnitOfTime } from './dates';
3
3
  export { FileNames } from './fileNames';
4
4
  export { FileProcessor } from './fileProcessor';
5
5
  export type { ArenaMutationOptions } from './mutationOptions';
6
- export type { ArenaFileProcessorConstructorArgs } from './fileProcessor';
6
+ export type { ArenaFileProcessorChunk, ArenaFileProcessorConstructorArgs, ArenaFileProcessorUriChunk, } from './fileProcessor';
7
7
  export { Numbers } from './numbers';
8
8
  export { Objects } from './_objects';
9
9
  export { Promises } from './promises';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAAxB,gGAAA,MAAM,OAAA;AACf,iCAAwD;AAA/C,8FAAA,KAAK,OAAA;AAAE,oGAAA,WAAW,OAAA;AAAE,mGAAA,UAAU,OAAA;AACvC,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAClB,iDAA+C;AAAtC,8GAAA,aAAa,OAAA;AAGtB,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,uCAAoC;AAA3B,mGAAA,OAAO,OAAA;AAChB,uCAAqC;AAA5B,oGAAA,QAAQ,OAAA;AACjB,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AACd,mDAAiD;AAAxC,gHAAA,cAAc,OAAA;AACvB,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AACd,uCAAqC;AAA5B,oGAAA,QAAQ,OAAA","sourcesContent":["export { Arrays } from './arrays'\nexport { Dates, DateFormats, UnitOfTime } from './dates'\nexport { FileNames } from './fileNames'\nexport { FileProcessor } from './fileProcessor'\nexport type { ArenaMutationOptions } from './mutationOptions'\nexport type { ArenaFileProcessorConstructorArgs } from './fileProcessor'\nexport { Numbers } from './numbers'\nexport { Objects } from './_objects'\nexport { Promises } from './promises'\nexport { Queue } from './queue'\nexport { RetryProcessor } from './retryProcessor'\nexport { Strings } from './strings'\nexport { UUIDs } from './uuids'\nexport { Versions } from './versions'\nexport type { ArenaParsedVersion } from './versions'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAAxB,gGAAA,MAAM,OAAA;AACf,iCAAwD;AAA/C,8FAAA,KAAK,OAAA;AAAE,oGAAA,WAAW,OAAA;AAAE,mGAAA,UAAU,OAAA;AACvC,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAClB,iDAA+C;AAAtC,8GAAA,aAAa,OAAA;AAOtB,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,uCAAoC;AAA3B,mGAAA,OAAO,OAAA;AAChB,uCAAqC;AAA5B,oGAAA,QAAQ,OAAA;AACjB,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AACd,mDAAiD;AAAxC,gHAAA,cAAc,OAAA;AACvB,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AACd,uCAAqC;AAA5B,oGAAA,QAAQ,OAAA","sourcesContent":["export { Arrays } from './arrays'\nexport { Dates, DateFormats, UnitOfTime } from './dates'\nexport { FileNames } from './fileNames'\nexport { FileProcessor } from './fileProcessor'\nexport type { ArenaMutationOptions } from './mutationOptions'\nexport type {\n ArenaFileProcessorChunk,\n ArenaFileProcessorConstructorArgs,\n ArenaFileProcessorUriChunk,\n} from './fileProcessor'\nexport { Numbers } from './numbers'\nexport { Objects } from './_objects'\nexport { Promises } from './promises'\nexport { Queue } from './queue'\nexport { RetryProcessor } from './retryProcessor'\nexport { Strings } from './strings'\nexport { UUIDs } from './uuids'\nexport { Versions } from './versions'\nexport type { ArenaParsedVersion } from './versions'\n"]}
@@ -10,16 +10,16 @@ declare const between: (value: number, min: number, max: number) => boolean;
10
10
  declare const isFloat: (value: any) => boolean;
11
11
  declare const isInteger: (value: any) => boolean;
12
12
  /**
13
- * Formats the given value to the specified fixed dicimal digits.
13
+ * Formats the given value to the specified fixed decimal digits (null if the value is null, undefined or NaN).
14
14
  */
15
- declare const formatDecimal: (value: number, decimalDigits?: number) => string | null;
15
+ declare const formatDecimal: (value: number | null | undefined, decimalDigits?: number) => string | null;
16
16
  /**
17
17
  * Formats the given value to a rounded integer.
18
18
  *
19
- * @param {!number} value - The value to format.
20
- * @returns {string} - The formatted value or null if the value was null.
19
+ * @param {number} value - The value to format.
20
+ * @returns {string} - The formatted value or null if the value was null, undefined or NaN.
21
21
  */
22
- declare const formatInteger: (value: number) => string | null;
22
+ declare const formatInteger: (value: number | null | undefined) => string | null;
23
23
  declare const limit: ({ minValue, maxValue }: {
24
24
  maxValue?: number | undefined;
25
25
  minValue?: number | undefined;
@@ -37,10 +37,10 @@ const isInteger = (value) => {
37
37
  return Number.isInteger(number);
38
38
  };
39
39
  /**
40
- * Formats the given value to the specified fixed dicimal digits.
40
+ * Formats the given value to the specified fixed decimal digits (null if the value is null, undefined or NaN).
41
41
  */
42
42
  const formatDecimal = (value, decimalDigits = Number.NaN) => {
43
- if (Number.isNaN(value) || value === null)
43
+ if (value === null || value === undefined || Number.isNaN(value))
44
44
  return null;
45
45
  const num = new bignumber_js_1.default(value);
46
46
  if (decimalDigits > 0) {
@@ -57,8 +57,8 @@ const formatDecimal = (value, decimalDigits = Number.NaN) => {
57
57
  /**
58
58
  * Formats the given value to a rounded integer.
59
59
  *
60
- * @param {!number} value - The value to format.
61
- * @returns {string} - The formatted value or null if the value was null.
60
+ * @param {number} value - The value to format.
61
+ * @returns {string} - The formatted value or null if the value was null, undefined or NaN.
62
62
  */
63
63
  const formatInteger = (value) => formatDecimal(value, 0);
64
64
  const limit = ({ minValue = Number.NaN, maxValue = Number.NaN }) => (value) => {
@@ -1 +1 @@
1
- {"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src/utils/numbers.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAoC;AACpC,mCAAuD;AACvD,mCAAuD;AACvD,mCAAuD;AACvD,mCAAuD;AACvD,yCAA0D;AAC1D,mCAAuD;AAEvD,0CAA0C;AAC1C,yCAAoC;AAEpC,sBAAS,CAAC,MAAM,CAAC;IACf,MAAM,EAAE;QACN,gBAAgB,EAAE,GAAG;QACrB,cAAc,EAAE,GAAG;QACnB,SAAS,EAAE,CAAC;KACb;CACF,CAAC,CAAA;AAEF,MAAM,QAAQ,GAAG,CAAC,GAAQ,EAAU,EAAE,CAAC,CAAC,kBAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;AAExF;;;;G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E,eAAY;IAC/B,CAAC,uBAAY,CAAC,EAAE,CAAC,EAAE,eAAY;IAC/B,CAAC,uBAAY,CAAC,EAAE,CAAC,EAAE,eAAY;IAC/B,CAAC,uBAAY,CAAC,EAAE,CAAC,EAAE,eAAY;IAC/B,CAAC,uBAAY,CAAC,EAAE,CAAC,EAAE,kBAAY;IAC/B,CAAC,uBAAY,CAAC,EAAE,CAAC,EAAE,eAAY;CAChC,CAAA;AAED;;;;;GAKG;AACH,MAAM,OAAO,GAAG,CAAC,KAAU,EAAE,IAAI,GAAiB,uBAAY,CAAC,EAAE,EAAiB,EAAE;;IAClF,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IACzC,MAAM,UAAU,SAAG,gBAAgB,CAAC,IAAI,CAAC,mCAAI,gBAAgB,CAAC,uBAAY,CAAC,EAAE,CAAE,CAAA;IAC/E,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;eAAO,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAEY,QAAA,OAAO,GAAG;IACrB,MAAM;IACN,OAAO;IACP,aAAa;IACb,aAAa;IACb,OAAO;IACP,SAAS;IACT,KAAK;IACL,gBAAgB;IAChB,QAAQ;IACR,OAAO;CACR,CAAA","sourcesContent":["import BigNumber from 'bignumber.js'\nimport { toCardinal as toCardinalEn } from 'n2words/en'\nimport { toCardinal as toCardinalEs } from 'n2words/es'\nimport { toCardinal as toCardinalFr } from 'n2words/fr'\nimport { toCardinal as toCardinalJa } from 'n2words/ja'\nimport { toCardinal as toCardinalPt } from 'n2words/pt-PT'\nimport { toCardinal as toCardinalRu } from 'n2words/ru'\n\nimport { LanguageCode } from '../language'\nimport { Objects } from './_objects'\n\nBigNumber.config({\n FORMAT: {\n decimalSeparator: '.',\n groupSeparator: ',',\n groupSize: 3,\n },\n})\n\nconst toNumber = (num: any): number => (Objects.isEmpty(num) ? Number.NaN : Number(num))\n\n/**\n * Returns the absolute modulus of the specified value. The result will always be a positive number.\n * @param {!number} modulus - The modulus to apply.\n * @returns {number} - The result of the modulus (always positive or 0).\n */\nconst absMod =\n (modulus: number) =>\n (value: number): number =>\n ((value % modulus) + modulus) % modulus\n\nconst between = (value: number, min: number, max: number): boolean => min <= value && max >= value\n\nconst isFloat = (value: any): boolean => {\n const number = toNumber(value)\n return Number.isFinite(number)\n}\n\nconst isInteger = (value: any): boolean => {\n const number = toNumber(value)\n return Number.isInteger(number)\n}\n\n/**\n * Formats the given value to the specified fixed dicimal digits.\n */\nconst formatDecimal = (value: number, decimalDigits = Number.NaN) => {\n if (Number.isNaN(value) || value === null) return null\n const num = new BigNumber(value)\n\n if (decimalDigits > 0) {\n // round to fixed number of decimal digits\n return num.toFormat(decimalDigits)\n }\n if (decimalDigits === 0) {\n // format as integer\n return num.toFormat(0, { groupSeparator: '' })\n }\n // plain notation (toString would use the exponential one for very small or big numbers, e.g. 1e-7)\n return num.toFixed()\n}\n\n/**\n * Formats the given value to a rounded integer.\n *\n * @param {!number} value - The value to format.\n * @returns {string} - The formatted value or null if the value was null.\n */\nconst formatInteger = (value: number): string | null => formatDecimal(value, 0)\n\nconst limit =\n ({ minValue = Number.NaN, maxValue = Number.NaN }) =>\n (value: number) => {\n let result = Number(value)\n // NOTE: 0 is a valid bound\n if (!Number.isNaN(minValue)) result = Math.max(minValue, result)\n if (!Number.isNaN(maxValue)) result = Math.min(maxValue, result)\n return result\n }\n\nconst roundToPrecision = (value: any, precision = Number.NaN) => {\n const num = toNumber(value)\n if (Number.isNaN(num)) return Number.NaN\n if (Number.isNaN(precision)) return num\n // decimal arithmetic (1.005 * 100 is 100.49999... in floating point); halves rounded away from zero, as formatDecimal\n return new BigNumber(num).shiftedBy(precision).integerValue(BigNumber.ROUND_HALF_UP).shiftedBy(-precision).toNumber()\n}\n\nconst toCardinalByLang: Partial<Record<LanguageCode, (value: number | string | bigint) => string>> = {\n [LanguageCode.en]: toCardinalEn,\n [LanguageCode.es]: toCardinalEs,\n [LanguageCode.fr]: toCardinalFr,\n [LanguageCode.ja]: toCardinalJa,\n [LanguageCode.pt]: toCardinalPt,\n [LanguageCode.ru]: toCardinalRu,\n}\n\n/**\n * Converts the given number to words (cardinal form) in the specified language.\n * Falls back to English if the specified language is not supported.\n *\n * @returns The number in words, or null if the value is not a finite number or cannot be converted (e.g. too large).\n */\nconst toWords = (value: any, lang: LanguageCode = LanguageCode.en): string | null => {\n const number = toNumber(value)\n if (!Number.isFinite(number)) return null\n const toCardinal = toCardinalByLang[lang] ?? toCardinalByLang[LanguageCode.en]!\n try {\n return toCardinal(number)\n } catch {\n return null\n }\n}\n\nexport const Numbers = {\n absMod,\n between,\n formatDecimal,\n formatInteger,\n isFloat,\n isInteger,\n limit,\n roundToPrecision,\n toNumber,\n toWords,\n}\n"]}
1
+ {"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src/utils/numbers.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAoC;AACpC,mCAAuD;AACvD,mCAAuD;AACvD,mCAAuD;AACvD,mCAAuD;AACvD,yCAA0D;AAC1D,mCAAuD;AAEvD,0CAA0C;AAC1C,yCAAoC;AAEpC,sBAAS,CAAC,MAAM,CAAC;IACf,MAAM,EAAE;QACN,gBAAgB,EAAE,GAAG;QACrB,cAAc,EAAE,GAAG;QACnB,SAAS,EAAE,CAAC;KACb;CACF,CAAC,CAAA;AAEF,MAAM,QAAQ,GAAG,CAAC,GAAQ,EAAU,EAAE,CAAC,CAAC,kBAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;AAExF;;;;GAIG;AACH,MAAM,MAAM,GACV,CAAC,OAAe,EAAE,EAAE,CACpB,CAAC,KAAa,EAAU,E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AAE,eAAY;IAC/B,CAAC,uBAAY,CAAC,EAAE,CAAC,EAAE,eAAY;IAC/B,CAAC,uBAAY,CAAC,EAAE,CAAC,EAAE,eAAY;IAC/B,CAAC,uBAAY,CAAC,EAAE,CAAC,EAAE,kBAAY;IAC/B,CAAC,uBAAY,CAAC,EAAE,CAAC,EAAE,eAAY;CAChC,CAAA;AAED;;;;;GAKG;AACH,MAAM,OAAO,GAAG,CAAC,KAAU,EAAE,IAAI,GAAiB,uBAAY,CAAC,EAAE,EAAiB,EAAE;;IAClF,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IACzC,MAAM,UAAU,SAAG,gBAAgB,CAAC,IAAI,CAAC,mCAAI,gBAAgB,CAAC,uBAAY,CAAC,EAAE,CAAE,CAAA;IAC/E,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;eAAO,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAEY,QAAA,OAAO,GAAG;IACrB,MAAM;IACN,OAAO;IACP,aAAa;IACb,aAAa;IACb,OAAO;IACP,SAAS;IACT,KAAK;IACL,gBAAgB;IAChB,QAAQ;IACR,OAAO;CACR,CAAA","sourcesContent":["import BigNumber from 'bignumber.js'\nimport { toCardinal as toCardinalEn } from 'n2words/en'\nimport { toCardinal as toCardinalEs } from 'n2words/es'\nimport { toCardinal as toCardinalFr } from 'n2words/fr'\nimport { toCardinal as toCardinalJa } from 'n2words/ja'\nimport { toCardinal as toCardinalPt } from 'n2words/pt-PT'\nimport { toCardinal as toCardinalRu } from 'n2words/ru'\n\nimport { LanguageCode } from '../language'\nimport { Objects } from './_objects'\n\nBigNumber.config({\n FORMAT: {\n decimalSeparator: '.',\n groupSeparator: ',',\n groupSize: 3,\n },\n})\n\nconst toNumber = (num: any): number => (Objects.isEmpty(num) ? Number.NaN : Number(num))\n\n/**\n * Returns the absolute modulus of the specified value. The result will always be a positive number.\n * @param {!number} modulus - The modulus to apply.\n * @returns {number} - The result of the modulus (always positive or 0).\n */\nconst absMod =\n (modulus: number) =>\n (value: number): number =>\n ((value % modulus) + modulus) % modulus\n\nconst between = (value: number, min: number, max: number): boolean => min <= value && max >= value\n\nconst isFloat = (value: any): boolean => {\n const number = toNumber(value)\n return Number.isFinite(number)\n}\n\nconst isInteger = (value: any): boolean => {\n const number = toNumber(value)\n return Number.isInteger(number)\n}\n\n/**\n * Formats the given value to the specified fixed decimal digits (null if the value is null, undefined or NaN).\n */\nconst formatDecimal = (value: number | null | undefined, decimalDigits = Number.NaN): string | null => {\n if (value === null || value === undefined || Number.isNaN(value)) return null\n const num = new BigNumber(value)\n\n if (decimalDigits > 0) {\n // round to fixed number of decimal digits\n return num.toFormat(decimalDigits)\n }\n if (decimalDigits === 0) {\n // format as integer\n return num.toFormat(0, { groupSeparator: '' })\n }\n // plain notation (toString would use the exponential one for very small or big numbers, e.g. 1e-7)\n return num.toFixed()\n}\n\n/**\n * Formats the given value to a rounded integer.\n *\n * @param {number} value - The value to format.\n * @returns {string} - The formatted value or null if the value was null, undefined or NaN.\n */\nconst formatInteger = (value: number | null | undefined): string | null => formatDecimal(value, 0)\n\nconst limit =\n ({ minValue = Number.NaN, maxValue = Number.NaN }) =>\n (value: number) => {\n let result = Number(value)\n // NOTE: 0 is a valid bound\n if (!Number.isNaN(minValue)) result = Math.max(minValue, result)\n if (!Number.isNaN(maxValue)) result = Math.min(maxValue, result)\n return result\n }\n\nconst roundToPrecision = (value: any, precision = Number.NaN) => {\n const num = toNumber(value)\n if (Number.isNaN(num)) return Number.NaN\n if (Number.isNaN(precision)) return num\n // decimal arithmetic (1.005 * 100 is 100.49999... in floating point); halves rounded away from zero, as formatDecimal\n return new BigNumber(num).shiftedBy(precision).integerValue(BigNumber.ROUND_HALF_UP).shiftedBy(-precision).toNumber()\n}\n\nconst toCardinalByLang: Partial<Record<LanguageCode, (value: number | string | bigint) => string>> = {\n [LanguageCode.en]: toCardinalEn,\n [LanguageCode.es]: toCardinalEs,\n [LanguageCode.fr]: toCardinalFr,\n [LanguageCode.ja]: toCardinalJa,\n [LanguageCode.pt]: toCardinalPt,\n [LanguageCode.ru]: toCardinalRu,\n}\n\n/**\n * Converts the given number to words (cardinal form) in the specified language.\n * Falls back to English if the specified language is not supported.\n *\n * @returns The number in words, or null if the value is not a finite number or cannot be converted (e.g. too large).\n */\nconst toWords = (value: any, lang: LanguageCode = LanguageCode.en): string | null => {\n const number = toNumber(value)\n if (!Number.isFinite(number)) return null\n const toCardinal = toCardinalByLang[lang] ?? toCardinalByLang[LanguageCode.en]!\n try {\n return toCardinal(number)\n } catch {\n return null\n }\n}\n\nexport const Numbers = {\n absMod,\n between,\n formatDecimal,\n formatInteger,\n isFloat,\n isInteger,\n limit,\n roundToPrecision,\n toNumber,\n toWords,\n}\n"]}
@@ -2,19 +2,19 @@ import { ArenaMutationOptions } from '../utils/mutationOptions';
2
2
  import { ArenaValidation, ArenaValidationCounts, ArenaValidationFields, ArenaValidationResult } from './validation';
3
3
  declare const hasValidation: (obj: any) => boolean;
4
4
  declare const getValidation: (obj: any) => ArenaValidation;
5
- declare const getFieldValidations: (validation: ArenaValidation) => ArenaValidationFields;
5
+ declare const getFieldValidations: (validation?: ArenaValidation | null) => ArenaValidationFields;
6
6
  declare const getFieldValidation: (field: string | number, defaultValue?: ArenaValidation) => (validation: ArenaValidation) => ArenaValidation;
7
7
  declare const getFieldValidationsByFields: (fields: (string | number)[]) => (validation: ArenaValidation) => ArenaValidationFields;
8
- declare const getErrors: (validation: ArenaValidation) => ArenaValidationResult[];
9
- declare const getWarnings: (validation: ArenaValidation) => ArenaValidationResult[];
10
- declare const hasErrors: (validation: ArenaValidation) => boolean;
11
- declare const hasWarnings: (validation: ArenaValidation) => boolean;
12
- declare const isValid: (validation: ArenaValidation) => boolean;
13
- declare const isNotValid: (validation: ArenaValidation) => boolean;
8
+ declare const getErrors: (validation?: ArenaValidation | null) => ArenaValidationResult[];
9
+ declare const getWarnings: (validation?: ArenaValidation | null) => ArenaValidationResult[];
10
+ declare const hasErrors: (validation?: ArenaValidation | null) => boolean;
11
+ declare const hasWarnings: (validation?: ArenaValidation | null) => boolean;
12
+ declare const isValid: (validation?: ArenaValidation | null) => boolean;
13
+ declare const isNotValid: (validation?: ArenaValidation | null) => boolean;
14
14
  declare const isObjValid: (obj: object) => boolean;
15
- declare const getCounts: (validation: ArenaValidation) => ArenaValidationCounts | undefined;
16
- declare const getErrorsCount: (validation: ArenaValidation) => number;
17
- declare const getWarningsCount: (validation: ArenaValidation) => number;
15
+ declare const getCounts: (validation?: ArenaValidation | null) => ArenaValidationCounts | undefined;
16
+ declare const getErrorsCount: (validation?: ArenaValidation | null) => number;
17
+ declare const getWarningsCount: (validation?: ArenaValidation | null) => number;
18
18
  declare const recalculateValidity: (validation: ArenaValidation) => ArenaValidation;
19
19
  declare const traverse: (visitor: (visitedItem: ArenaValidation) => void) => (validation: ArenaValidation) => void;
20
20
  declare const calculateCounts: (validation: ArenaValidation) => ArenaValidationCounts;
@@ -49,7 +49,7 @@ const hasWarnings = (validation) => {
49
49
  const warnings = getWarnings(validation);
50
50
  return !utils_1.Objects.isEmpty(warnings) || Object.values(getFieldValidations(validation)).some(hasWarnings);
51
51
  };
52
- const isValid = (validation) => utils_1.Objects.isEmpty(validation) || validation.valid;
52
+ const isValid = (validation) => utils_1.Objects.isEmpty(validation) || !!(validation === null || validation === void 0 ? void 0 : validation.valid);
53
53
  const isNotValid = (validation) => !isValid(validation);
54
54
  const isObjValid = (obj) => isValid(getValidation(obj));
55
55
  const getCounts = (validation) => validation === null || validation === void 0 ? void 0 : validation.counts;
@@ -1 +1 @@
1
- {"version":3,"file":"validations.js","sourceRoot":"","sources":["../../src/validation/validations.ts"],"names":[],"mappings":";;;AAAA,oCAAkC;AAElC,uCAA6C;AAG7C,MAAM,IAAI,GA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B,YAAY;IACZ,OAAO;IACP,gBAAgB;IAChB,qBAAqB;IACrB,kCAAkC;IAClC,eAAe;IACf,qBAAqB;IACrB,QAAQ;IACR,SAAS;IACT,WAAW;IACX,mBAAmB;IACnB,oBAAoB;IACpB,kBAAkB;IAClB,eAAe;IACf,gBAAgB;CACjB,CAAA","sourcesContent":["import { Objects } from '../utils'\nimport { ArenaMutationOptions } from '../utils/mutationOptions'\nimport { ValidationFactory } from './factory'\nimport { ArenaValidation, ArenaValidationCounts, ArenaValidationFields, ArenaValidationResult } from './validation'\n\nconst keys = {\n counts: 'counts',\n errors: 'errors',\n fields: 'fields',\n valid: 'valid',\n validation: 'validation',\n warnings: 'warnings',\n}\n\nconst hasValidation = (obj: any): boolean => !!obj?.validation\n\nconst getValidation = (obj: any): ArenaValidation => obj?.validation || ValidationFactory.createInstance()\n\nconst getFieldValidations = (validation: ArenaValidation): ArenaValidationFields => validation?.fields ?? {}\n\nconst getFieldValidationUnsafe =\n (field: string | number) =>\n (validation: ArenaValidation): ArenaValidation | undefined => {\n if (typeof field === 'string') {\n let validationCurrent: ArenaValidation | undefined = validation\n const parts = field.split('.')\n parts.some((part) => {\n validationCurrent = getFieldValidations(validationCurrent!)[part]\n return !validationCurrent // breaks the loop if there is no field validation\n })\n return validationCurrent\n } else {\n return getFieldValidations(validation)[field]\n }\n }\n\nconst getFieldValidation =\n (field: string | number, defaultValue: ArenaValidation = ValidationFactory.createInstance()) =>\n (validation: ArenaValidation): ArenaValidation =>\n getFieldValidationUnsafe(field)(validation) ?? defaultValue\n\nconst getFieldValidationsByFields =\n (fields: (string | number)[]) =>\n (validation: ArenaValidation): ArenaValidationFields => {\n const result: ArenaValidationFields = {}\n for (const field of fields) {\n const fieldValidation = getFieldValidationUnsafe(field)(validation)\n if (fieldValidation) {\n result[String(field)] = fieldValidation\n }\n }\n return result\n }\n\nconst getErrors = (validation: ArenaValidation): ArenaValidationResult[] => validation?.errors ?? []\n\nconst getWarnings = (validation: ArenaValidation): ArenaValidationResult[] => validation?.warnings ?? []\n\nconst hasErrors = (validation: ArenaValidation): boolean => {\n const errors = getErrors(validation)\n return !Objects.isEmpty(errors) || Object.values(getFieldValidations(validation)).some(hasErrors)\n}\n\nconst hasWarnings = (validation: ArenaValidation): boolean => {\n const warnings = getWarnings(validation)\n return !Objects.isEmpty(warnings) || Object.values(getFieldValidations(validation)).some(hasWarnings)\n}\n\nconst isValid = (validation: ArenaValidation): boolean => Objects.isEmpty(validation) || validation.valid\nconst isNotValid = (validation: ArenaValidation): boolean => !isValid(validation)\nconst isObjValid = (obj: object): boolean => isValid(getValidation(obj))\n\nconst getCounts = (validation: ArenaValidation): ArenaValidationCounts | undefined => validation?.counts\nconst getErrorsCount = (validation: ArenaValidation): number => getCounts(validation)?.errors ?? 0\nconst getWarningsCount = (validation: ArenaValidation): number => getCounts(validation)?.warnings ?? 0\n\n/**\n * Creates a validation object like ValidationFactory.createInstance does, but without checking again\n * if fields is empty (checking it is O(N) for objects with many properties).\n */\nconst _createValidation = (params: {\n valid: boolean\n fields: ArenaValidationFields\n hasFields: boolean\n errors: ArenaValidationResult[]\n warnings: ArenaValidationResult[]\n}): ArenaValidation => {\n const { valid, fields, hasFields, errors, warnings } = params\n const result: ArenaValidation = { valid }\n if (errors.length > 0) result.errors = errors\n if (hasFields) result.fields = fields\n if (warnings.length > 0) result.warnings = warnings\n return result\n}\n\nconst recalculateValidity = (validation: ArenaValidation): ArenaValidation => {\n let allFieldsValid = true\n let hasFields = false\n\n const fieldsWithValidationRecalculated: ArenaValidationFields = {}\n\n for (const [fieldKey, fieldValidation] of Object.entries(getFieldValidations(validation))) {\n const fieldValidationUpdated = recalculateValidity(fieldValidation)\n fieldsWithValidationRecalculated[fieldKey] = fieldValidationUpdated\n hasFields = true\n if (!fieldValidationUpdated.valid) {\n allFieldsValid = false\n }\n }\n const errors = getErrors(validation)\n const warnings = getWarnings(validation)\n // nested errors and warnings already make the recalculated field validations not valid:\n // checking only own errors and warnings is enough (hasErrors/hasWarnings would visit the whole subtree again)\n const valid = allFieldsValid && errors.length === 0 && warnings.length === 0\n\n return _createValidation({ valid, fields: fieldsWithValidationRecalculated, hasFields, errors, warnings })\n}\n\nconst traverse = (visitor: (visitedItem: ArenaValidation) => void) => (validation: ArenaValidation) => {\n const stack: ArenaValidation[] = []\n stack.push(validation)\n\n while (stack.length) {\n const validationCurrent = stack.pop()!\n visitor(validationCurrent)\n // Add field validations to stack\n const validationFields = getFieldValidations(validationCurrent)\n for (const fieldValidation of Object.values(validationFields)) {\n stack.push(fieldValidation)\n }\n }\n}\n\nconst calculateCounts = (validation: ArenaValidation): ArenaValidationCounts => {\n let errors = 0\n let warnings = 0\n\n traverse((validationCurrent) => {\n errors += getErrors(validationCurrent).length\n warnings += getWarnings(validationCurrent).length\n })(validation)\n\n return {\n errors,\n warnings,\n }\n}\n\nconst updateCounts = (validation: ArenaValidation): ArenaValidation => ({\n ...validation,\n counts: calculateCounts(validation),\n})\n\nconst calculateHasNestedErrors = (validation: ArenaValidation): boolean => calculateCounts(validation).errors > 0\nconst calculateHasNestedWarnings = (validation: ArenaValidation): boolean => calculateCounts(validation).warnings > 0\n\nconst cleanup = (validation: ArenaValidation): ArenaValidation => {\n // only not valid field validations are kept\n let hasFields = false\n const fieldsCleaned: ArenaValidationFields = {}\n for (const [field, fieldValidation] of Object.entries(getFieldValidations(validation))) {\n const fieldValidationCleaned = cleanup(fieldValidation)\n if (!fieldValidationCleaned.valid) {\n fieldsCleaned[field] = fieldValidationCleaned\n hasFields = true\n }\n }\n const errors = getErrors(validation)\n const warnings = getWarnings(validation)\n // nested errors and warnings already make the cleaned field validations not valid:\n // checking only own errors and warnings is enough (hasErrors/hasWarnings would visit the whole subtree again)\n const valid = !hasFields && errors.length === 0 && warnings.length === 0\n\n return _createValidation({ valid, fields: fieldsCleaned, hasFields, errors, warnings })\n}\n\n/**\n * Options of the functions removing field validations.\n */\nexport interface ArenaDissocFieldValidationOptions extends ArenaMutationOptions {\n /**\n * When true (default), the validation is cleaned up after removing the field validations (empty field validations\n * removed and validity recalculated).\n */\n doCleanup?: boolean\n}\n\nfunction dissocFieldValidation(\n fieldKey: string,\n options?: ArenaDissocFieldValidationOptions\n): (validation: ArenaValidation) => ArenaValidation {\n const { sideEffect = false, doCleanup = true } = options ?? {}\n return (validation: ArenaValidation): ArenaValidation => {\n const validationUpdated = Objects.dissocPath({ obj: validation, path: ['fields', fieldKey], sideEffect })\n return doCleanup ? cleanup(validationUpdated) : validationUpdated\n }\n}\n\nfunction dissocFieldValidationsStartingWith(\n fieldStartsWith: string,\n options?: ArenaDissocFieldValidationOptions\n): (validation: ArenaValidation) => ArenaValidation {\n const { sideEffect = false, doCleanup = true } = options ?? {}\n return (validation: ArenaValidation): ArenaValidation => {\n if (!validation?.fields) return validation\n\n const fieldsUpdated = sideEffect ? validation.fields : { ...validation.fields }\n for (const fieldKey of Object.keys(fieldsUpdated)) {\n if (fieldKey.startsWith(fieldStartsWith)) {\n delete fieldsUpdated[fieldKey]\n }\n }\n if (sideEffect) {\n if (doCleanup) {\n // keep the same validation object: only fields and validity are changed by the cleanup\n const { valid, fields } = cleanup(validation)\n validation.valid = valid\n if (fields) {\n validation.fields = fields\n } else {\n delete validation.fields\n }\n }\n return validation\n }\n const validationUpdated = { ...validation, fields: fieldsUpdated }\n return doCleanup ? cleanup(validationUpdated) : validationUpdated\n }\n}\n\nconst mergeValidation =\n (validationNext: ArenaValidation, doCleanup = true) =>\n (validationPrev: ArenaValidation): ArenaValidation => {\n const validationFieldsResult: ArenaValidationFields = {\n ...getFieldValidations(validationPrev),\n }\n const validationFieldsNext = getFieldValidations(validationNext)\n\n // iterate over new field validations: remove valid ones, merge invalid ones with previous ones\n for (const [fieldKey, validationFieldNext] of Object.entries(validationFieldsNext)) {\n if (isValid(validationFieldNext)) {\n if (doCleanup) {\n // field validation valid: remove it from resulting validation\n delete validationFieldsResult[fieldKey]\n } else {\n validationFieldsResult[fieldKey] = ValidationFactory.createInstance()\n }\n } else {\n // field validation not valid: deep merge it with the previous one\n const validationFieldPrev = validationFieldsResult[fieldKey]\n const validationFieldMerged = validationFieldPrev\n ? mergeValidation(validationFieldNext, false)(validationFieldPrev)\n : validationFieldNext\n validationFieldsResult[fieldKey] = validationFieldMerged\n }\n }\n\n const validationResult: ArenaValidation = { ...validationPrev, fields: validationFieldsResult }\n validationResult.errors = getErrors(validationNext)\n validationResult.warnings = getWarnings(validationNext)\n\n return doCleanup ? cleanup(validationResult) : recalculateValidity(validationResult)\n }\n\n// same function as mergeValidation (kept for backwards compatibility)\nconst mergeValidations = mergeValidation\n\nconst mergeFieldValidations = (\n fieldValidationsNext: ArenaValidationFields,\n fieldValidationsPrev: ArenaValidationFields\n): ArenaValidationFields => {\n const result: ArenaValidationFields = { ...fieldValidationsPrev }\n for (const [fieldKey, fieldValidationNext] of Object.entries(fieldValidationsNext)) {\n const fieldValidationPrev = fieldValidationsPrev[fieldKey]\n result[fieldKey] = fieldValidationPrev\n ? mergeValidation(fieldValidationNext, false)(fieldValidationPrev)\n : fieldValidationNext\n }\n return result\n}\n\nconst setValid = (valid: boolean) => (obj: object) => Objects.setInPath({ obj, path: [keys.valid], value: valid })\n\nconst setErrors =\n (errors: ArenaValidationResult[]) =>\n <T extends object>(obj: T): T =>\n Objects.setInPath({ obj, path: [keys.errors], value: errors })\n\nconst setWarnings =\n (warnings: ArenaValidationResult[]) =>\n <T extends object>(obj: T): T =>\n Objects.setInPath({ obj, path: [keys.warnings], value: warnings })\n\nconst setFieldValidations =\n (fieldValidations: ArenaValidationFields) =>\n <T extends object>(obj: T): T =>\n Objects.setInPath({ obj, path: [keys.fields], value: fieldValidations })\n\nconst setFieldValidation =\n (field: string, fieldValidation: ArenaValidation) =>\n <T extends object>(obj: T): T =>\n Objects.setInPath({ obj, path: [keys.fields, field], value: fieldValidation })\n\nconst assocFieldValidation = (field: string, fieldValidation: ArenaValidation) => (validation: ArenaValidation) =>\n cleanup(Objects.assocPath({ obj: validation, path: [keys.fields, field], value: fieldValidation }))\n\nconst assocValidation = (v: ArenaValidation) => (obj: object) => Objects.assoc({ obj, prop: 'validation', value: v })\n\nconst dissocValidation = (obj: object) => Objects.dissoc({ obj, prop: 'validation' })\n\nexport const Validations = {\n keys,\n hasValidation,\n getValidation,\n getFieldValidation,\n getFieldValidations,\n getFieldValidationsByFields,\n getErrors,\n getWarnings,\n hasErrors,\n hasWarnings,\n isValid,\n isNotValid,\n isObjValid,\n getCounts,\n getErrorsCount,\n getWarningsCount,\n recalculateValidity,\n traverse,\n calculateCounts,\n calculateHasNestedErrors,\n calculateHasNestedWarnings,\n updateCounts,\n cleanup,\n mergeValidations,\n dissocFieldValidation,\n dissocFieldValidationsStartingWith,\n mergeValidation,\n mergeFieldValidations,\n setValid,\n setErrors,\n setWarnings,\n setFieldValidations,\n assocFieldValidation,\n setFieldValidation,\n assocValidation,\n dissocValidation,\n}\n"]}
1
+ {"version":3,"file":"validations.js","sourceRoot":"","sources":["../../src/validation/validations.ts"],"names":[],"mappings":";;;AAAA,oCAAkC;AAElC,uCAA6C;AAG7C,MAAM,IAAI,GAAG;IACX,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;CACrB,CAAA;AAED,MAAM,aAAa,GAAG,CAAC,GAAQ,EAAW,EAAE,CAAC,CAAC,EAAC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,CAAA,CAAA;AAE9D,MAAM,aAAa,GAAG,CAAC,GAAQ,EAAmB,EAAE,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,KAAI,2BAAiB,CAAC,cAAc,EAAE,CAAA;AAE1G,MAAM,mBAAmB,GAAG,CAAC,UAAmC,EAAyB,EAAE,wBAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,mCAAI,EAAE,GAAA,CAAA;AAEp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E,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC,CAAA;AAErG,MAAM,eAAe,GAAG,CAAC,CAAkB,EAAE,EAAE,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,eAAO,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;AAErH,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,eAAO,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;AAExE,QAAA,WAAW,GAAG;IACzB,IAAI;IACJ,aAAa;IACb,aAAa;IACb,kBAAkB;IAClB,mBAAmB;IACnB,2BAA2B;IAC3B,SAAS;IACT,WAAW;IACX,SAAS;IACT,WAAW;IACX,OAAO;IACP,UAAU;IACV,UAAU;IACV,SAAS;IACT,cAAc;IACd,gBAAgB;IAChB,mBAAmB;IACnB,QAAQ;IACR,eAAe;IACf,wBAAwB;IACxB,0BAA0B;IAC1B,YAAY;IACZ,OAAO;IACP,gBAAgB;IAChB,qBAAqB;IACrB,kCAAkC;IAClC,eAAe;IACf,qBAAqB;IACrB,QAAQ;IACR,SAAS;IACT,WAAW;IACX,mBAAmB;IACnB,oBAAoB;IACpB,kBAAkB;IAClB,eAAe;IACf,gBAAgB;CACjB,CAAA","sourcesContent":["import { Objects } from '../utils'\nimport { ArenaMutationOptions } from '../utils/mutationOptions'\nimport { ValidationFactory } from './factory'\nimport { ArenaValidation, ArenaValidationCounts, ArenaValidationFields, ArenaValidationResult } from './validation'\n\nconst keys = {\n counts: 'counts',\n errors: 'errors',\n fields: 'fields',\n valid: 'valid',\n validation: 'validation',\n warnings: 'warnings',\n}\n\nconst hasValidation = (obj: any): boolean => !!obj?.validation\n\nconst getValidation = (obj: any): ArenaValidation => obj?.validation || ValidationFactory.createInstance()\n\nconst getFieldValidations = (validation?: ArenaValidation | null): ArenaValidationFields => validation?.fields ?? {}\n\nconst getFieldValidationUnsafe =\n (field: string | number) =>\n (validation: ArenaValidation): ArenaValidation | undefined => {\n if (typeof field === 'string') {\n let validationCurrent: ArenaValidation | undefined = validation\n const parts = field.split('.')\n parts.some((part) => {\n validationCurrent = getFieldValidations(validationCurrent!)[part]\n return !validationCurrent // breaks the loop if there is no field validation\n })\n return validationCurrent\n } else {\n return getFieldValidations(validation)[field]\n }\n }\n\nconst getFieldValidation =\n (field: string | number, defaultValue: ArenaValidation = ValidationFactory.createInstance()) =>\n (validation: ArenaValidation): ArenaValidation =>\n getFieldValidationUnsafe(field)(validation) ?? defaultValue\n\nconst getFieldValidationsByFields =\n (fields: (string | number)[]) =>\n (validation: ArenaValidation): ArenaValidationFields => {\n const result: ArenaValidationFields = {}\n for (const field of fields) {\n const fieldValidation = getFieldValidationUnsafe(field)(validation)\n if (fieldValidation) {\n result[String(field)] = fieldValidation\n }\n }\n return result\n }\n\nconst getErrors = (validation?: ArenaValidation | null): ArenaValidationResult[] => validation?.errors ?? []\n\nconst getWarnings = (validation?: ArenaValidation | null): ArenaValidationResult[] => validation?.warnings ?? []\n\nconst hasErrors = (validation?: ArenaValidation | null): boolean => {\n const errors = getErrors(validation)\n return !Objects.isEmpty(errors) || Object.values(getFieldValidations(validation)).some(hasErrors)\n}\n\nconst hasWarnings = (validation?: ArenaValidation | null): boolean => {\n const warnings = getWarnings(validation)\n return !Objects.isEmpty(warnings) || Object.values(getFieldValidations(validation)).some(hasWarnings)\n}\n\nconst isValid = (validation?: ArenaValidation | null): boolean => Objects.isEmpty(validation) || !!validation?.valid\nconst isNotValid = (validation?: ArenaValidation | null): boolean => !isValid(validation)\nconst isObjValid = (obj: object): boolean => isValid(getValidation(obj))\n\nconst getCounts = (validation?: ArenaValidation | null): ArenaValidationCounts | undefined => validation?.counts\nconst getErrorsCount = (validation?: ArenaValidation | null): number => getCounts(validation)?.errors ?? 0\nconst getWarningsCount = (validation?: ArenaValidation | null): number => getCounts(validation)?.warnings ?? 0\n\n/**\n * Creates a validation object like ValidationFactory.createInstance does, but without checking again\n * if fields is empty (checking it is O(N) for objects with many properties).\n */\nconst _createValidation = (params: {\n valid: boolean\n fields: ArenaValidationFields\n hasFields: boolean\n errors: ArenaValidationResult[]\n warnings: ArenaValidationResult[]\n}): ArenaValidation => {\n const { valid, fields, hasFields, errors, warnings } = params\n const result: ArenaValidation = { valid }\n if (errors.length > 0) result.errors = errors\n if (hasFields) result.fields = fields\n if (warnings.length > 0) result.warnings = warnings\n return result\n}\n\nconst recalculateValidity = (validation: ArenaValidation): ArenaValidation => {\n let allFieldsValid = true\n let hasFields = false\n\n const fieldsWithValidationRecalculated: ArenaValidationFields = {}\n\n for (const [fieldKey, fieldValidation] of Object.entries(getFieldValidations(validation))) {\n const fieldValidationUpdated = recalculateValidity(fieldValidation)\n fieldsWithValidationRecalculated[fieldKey] = fieldValidationUpdated\n hasFields = true\n if (!fieldValidationUpdated.valid) {\n allFieldsValid = false\n }\n }\n const errors = getErrors(validation)\n const warnings = getWarnings(validation)\n // nested errors and warnings already make the recalculated field validations not valid:\n // checking only own errors and warnings is enough (hasErrors/hasWarnings would visit the whole subtree again)\n const valid = allFieldsValid && errors.length === 0 && warnings.length === 0\n\n return _createValidation({ valid, fields: fieldsWithValidationRecalculated, hasFields, errors, warnings })\n}\n\nconst traverse = (visitor: (visitedItem: ArenaValidation) => void) => (validation: ArenaValidation) => {\n const stack: ArenaValidation[] = []\n stack.push(validation)\n\n while (stack.length) {\n const validationCurrent = stack.pop()!\n visitor(validationCurrent)\n // Add field validations to stack\n const validationFields = getFieldValidations(validationCurrent)\n for (const fieldValidation of Object.values(validationFields)) {\n stack.push(fieldValidation)\n }\n }\n}\n\nconst calculateCounts = (validation: ArenaValidation): ArenaValidationCounts => {\n let errors = 0\n let warnings = 0\n\n traverse((validationCurrent) => {\n errors += getErrors(validationCurrent).length\n warnings += getWarnings(validationCurrent).length\n })(validation)\n\n return {\n errors,\n warnings,\n }\n}\n\nconst updateCounts = (validation: ArenaValidation): ArenaValidation => ({\n ...validation,\n counts: calculateCounts(validation),\n})\n\nconst calculateHasNestedErrors = (validation: ArenaValidation): boolean => calculateCounts(validation).errors > 0\nconst calculateHasNestedWarnings = (validation: ArenaValidation): boolean => calculateCounts(validation).warnings > 0\n\nconst cleanup = (validation: ArenaValidation): ArenaValidation => {\n // only not valid field validations are kept\n let hasFields = false\n const fieldsCleaned: ArenaValidationFields = {}\n for (const [field, fieldValidation] of Object.entries(getFieldValidations(validation))) {\n const fieldValidationCleaned = cleanup(fieldValidation)\n if (!fieldValidationCleaned.valid) {\n fieldsCleaned[field] = fieldValidationCleaned\n hasFields = true\n }\n }\n const errors = getErrors(validation)\n const warnings = getWarnings(validation)\n // nested errors and warnings already make the cleaned field validations not valid:\n // checking only own errors and warnings is enough (hasErrors/hasWarnings would visit the whole subtree again)\n const valid = !hasFields && errors.length === 0 && warnings.length === 0\n\n return _createValidation({ valid, fields: fieldsCleaned, hasFields, errors, warnings })\n}\n\n/**\n * Options of the functions removing field validations.\n */\nexport interface ArenaDissocFieldValidationOptions extends ArenaMutationOptions {\n /**\n * When true (default), the validation is cleaned up after removing the field validations (empty field validations\n * removed and validity recalculated).\n */\n doCleanup?: boolean\n}\n\nfunction dissocFieldValidation(\n fieldKey: string,\n options?: ArenaDissocFieldValidationOptions\n): (validation: ArenaValidation) => ArenaValidation {\n const { sideEffect = false, doCleanup = true } = options ?? {}\n return (validation: ArenaValidation): ArenaValidation => {\n const validationUpdated = Objects.dissocPath({ obj: validation, path: ['fields', fieldKey], sideEffect })\n return doCleanup ? cleanup(validationUpdated) : validationUpdated\n }\n}\n\nfunction dissocFieldValidationsStartingWith(\n fieldStartsWith: string,\n options?: ArenaDissocFieldValidationOptions\n): (validation: ArenaValidation) => ArenaValidation {\n const { sideEffect = false, doCleanup = true } = options ?? {}\n return (validation: ArenaValidation): ArenaValidation => {\n if (!validation?.fields) return validation\n\n const fieldsUpdated = sideEffect ? validation.fields : { ...validation.fields }\n for (const fieldKey of Object.keys(fieldsUpdated)) {\n if (fieldKey.startsWith(fieldStartsWith)) {\n delete fieldsUpdated[fieldKey]\n }\n }\n if (sideEffect) {\n if (doCleanup) {\n // keep the same validation object: only fields and validity are changed by the cleanup\n const { valid, fields } = cleanup(validation)\n validation.valid = valid\n if (fields) {\n validation.fields = fields\n } else {\n delete validation.fields\n }\n }\n return validation\n }\n const validationUpdated = { ...validation, fields: fieldsUpdated }\n return doCleanup ? cleanup(validationUpdated) : validationUpdated\n }\n}\n\nconst mergeValidation =\n (validationNext: ArenaValidation, doCleanup = true) =>\n (validationPrev: ArenaValidation): ArenaValidation => {\n const validationFieldsResult: ArenaValidationFields = {\n ...getFieldValidations(validationPrev),\n }\n const validationFieldsNext = getFieldValidations(validationNext)\n\n // iterate over new field validations: remove valid ones, merge invalid ones with previous ones\n for (const [fieldKey, validationFieldNext] of Object.entries(validationFieldsNext)) {\n if (isValid(validationFieldNext)) {\n if (doCleanup) {\n // field validation valid: remove it from resulting validation\n delete validationFieldsResult[fieldKey]\n } else {\n validationFieldsResult[fieldKey] = ValidationFactory.createInstance()\n }\n } else {\n // field validation not valid: deep merge it with the previous one\n const validationFieldPrev = validationFieldsResult[fieldKey]\n const validationFieldMerged = validationFieldPrev\n ? mergeValidation(validationFieldNext, false)(validationFieldPrev)\n : validationFieldNext\n validationFieldsResult[fieldKey] = validationFieldMerged\n }\n }\n\n const validationResult: ArenaValidation = { ...validationPrev, fields: validationFieldsResult }\n validationResult.errors = getErrors(validationNext)\n validationResult.warnings = getWarnings(validationNext)\n\n return doCleanup ? cleanup(validationResult) : recalculateValidity(validationResult)\n }\n\n// same function as mergeValidation (kept for backwards compatibility)\nconst mergeValidations = mergeValidation\n\nconst mergeFieldValidations = (\n fieldValidationsNext: ArenaValidationFields,\n fieldValidationsPrev: ArenaValidationFields\n): ArenaValidationFields => {\n const result: ArenaValidationFields = { ...fieldValidationsPrev }\n for (const [fieldKey, fieldValidationNext] of Object.entries(fieldValidationsNext)) {\n const fieldValidationPrev = fieldValidationsPrev[fieldKey]\n result[fieldKey] = fieldValidationPrev\n ? mergeValidation(fieldValidationNext, false)(fieldValidationPrev)\n : fieldValidationNext\n }\n return result\n}\n\nconst setValid = (valid: boolean) => (obj: object) => Objects.setInPath({ obj, path: [keys.valid], value: valid })\n\nconst setErrors =\n (errors: ArenaValidationResult[]) =>\n <T extends object>(obj: T): T =>\n Objects.setInPath({ obj, path: [keys.errors], value: errors })\n\nconst setWarnings =\n (warnings: ArenaValidationResult[]) =>\n <T extends object>(obj: T): T =>\n Objects.setInPath({ obj, path: [keys.warnings], value: warnings })\n\nconst setFieldValidations =\n (fieldValidations: ArenaValidationFields) =>\n <T extends object>(obj: T): T =>\n Objects.setInPath({ obj, path: [keys.fields], value: fieldValidations })\n\nconst setFieldValidation =\n (field: string, fieldValidation: ArenaValidation) =>\n <T extends object>(obj: T): T =>\n Objects.setInPath({ obj, path: [keys.fields, field], value: fieldValidation })\n\nconst assocFieldValidation = (field: string, fieldValidation: ArenaValidation) => (validation: ArenaValidation) =>\n cleanup(Objects.assocPath({ obj: validation, path: [keys.fields, field], value: fieldValidation }))\n\nconst assocValidation = (v: ArenaValidation) => (obj: object) => Objects.assoc({ obj, prop: 'validation', value: v })\n\nconst dissocValidation = (obj: object) => Objects.dissoc({ obj, prop: 'validation' })\n\nexport const Validations = {\n keys,\n hasValidation,\n getValidation,\n getFieldValidation,\n getFieldValidations,\n getFieldValidationsByFields,\n getErrors,\n getWarnings,\n hasErrors,\n hasWarnings,\n isValid,\n isNotValid,\n isObjValid,\n getCounts,\n getErrorsCount,\n getWarningsCount,\n recalculateValidity,\n traverse,\n calculateCounts,\n calculateHasNestedErrors,\n calculateHasNestedWarnings,\n updateCounts,\n cleanup,\n mergeValidations,\n dissocFieldValidation,\n dissocFieldValidationsStartingWith,\n mergeValidation,\n mergeFieldValidations,\n setValid,\n setErrors,\n setWarnings,\n setFieldValidations,\n assocFieldValidation,\n setFieldValidation,\n assocValidation,\n dissocValidation,\n}\n"]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "OpenForis",
5
5
  "email": "openforis.arena@gmail.com"
6
6
  },
7
- "version": "3.1.6",
7
+ "version": "3.2.1",
8
8
  "description": "Arena core module",
9
9
  "repository": {
10
10
  "type": "git",