@openforis/arena-core 2.16.13 → 2.17.0

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.
@@ -7,7 +7,6 @@ declare const getSurveyUuid: (authGroup: AuthGroup) => string | undefined;
7
7
  declare const getRecordSteps: (authGroup?: AuthGroup) => {
8
8
  [key: string]: RecordStepPermission;
9
9
  } | undefined;
10
- declare const getRecordEditLevel: (step: string) => (authGroup?: AuthGroup) => RecordStepPermission;
11
10
  declare const getDefaultAuthGroups: (surveyUuid: string) => AuthGroup[];
12
11
  declare const getPermissions: (group: AuthGroup) => import("./permission").Permission[];
13
12
  declare const sortGroups: (groups: AuthGroup[]) => AuthGroup[];
@@ -17,7 +16,6 @@ export declare const AuthGroups: {
17
16
  isSurveyManager: typeof isSurveyManager;
18
17
  getSurveyUuid: typeof getSurveyUuid;
19
18
  getRecordSteps: typeof getRecordSteps;
20
- getRecordEditLevel: typeof getRecordEditLevel;
21
19
  getDefaultAuthGroups: typeof getDefaultAuthGroups;
22
20
  getPermissions: typeof getPermissions;
23
21
  sortGroups: typeof sortGroups;
@@ -8,12 +8,6 @@ const isSurveyManager = (authGroup) => (authGroup === null || authGroup === void
8
8
  const isSurveyGroup = (authGroup) => !isSystemAdmin(authGroup) && !isSurveyManager(authGroup);
9
9
  const getSurveyUuid = (authGroup) => authGroup === null || authGroup === void 0 ? void 0 : authGroup.surveyUuid;
10
10
  const getRecordSteps = (authGroup) => authGroup === null || authGroup === void 0 ? void 0 : authGroup.recordSteps;
11
- const getRecordEditLevel = (step) => (authGroup) => {
12
- const steps = getRecordSteps(authGroup);
13
- if (!steps)
14
- throw new Error('No steps');
15
- return steps[step];
16
- };
17
11
  const getDefaultAuthGroups = (surveyUuid) => (0, authGroup_1.createDefaultAuthGroups)().map((group) => (Object.assign(Object.assign({}, group), { uuid: utils_1.UUIDs.v4(), surveyUuid })));
18
12
  const getPermissions = (group) => { var _a; return (_a = authGroup_1.permissionsByGroupName[group.name]) !== null && _a !== void 0 ? _a : []; };
19
13
  const sortGroups = (groups) => {
@@ -31,7 +25,6 @@ exports.AuthGroups = {
31
25
  isSurveyManager,
32
26
  getSurveyUuid,
33
27
  getRecordSteps,
34
- getRecordEditLevel,
35
28
  getDefaultAuthGroups,
36
29
  getPermissions,
37
30
  sortGroups,
@@ -1 +1 @@
1
- {"version":3,"file":"authGroups.js","sourceRoot":"","sources":["../../src/auth/authGroups.ts"],"names":[],"mappings":";;;AAAA,oCAAgC;AAChC,2CAMoB;AAGpB,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,yBAAa,CAAC,WAAW,CAAA;AAEtG,MAAM,eAAe,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,yBAAa,CAAC,aAAa,CAAA;AAE1G,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;AAEjH,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAsB,EAAE,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,UAAU,CAAA;AAEzF,MAAM,cAAc,GAAG,CAAC,SAAqB,EAAuD,EAAE,CACpG,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,CAAA;AAExB,MAAM,kBAAkB,GACtB,CAAC,IAAY,EAAE,EAAE,CACjB,CAAC,SAAqB,EAAwB,EAAE;IAC9C,MAAM,KAAK,GAAG,cAAc,CAAC,SAAS,CAAC,CAAA;IACvC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAA;IAEvC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAA;AACpB,CAAC,CAAA;AAEH,MAAM,oBAAoB,GAAG,CAAC,UAAkB,EAAe,EAAE,CAC/D,IAAA,mCAAuB,GAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCAAM,KAAK,KAAE,IAAI,EAAE,aAAK,CAAC,EAAE,EAAE,EAAE,UAAU,IAAG,CAAC,CAAA;AAExF,MAAM,cAAc,GAAG,CAAC,KAAgB,EAAE,EAAE,wBAAC,kCAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,mCAAI,EAAE,GAAA,CAAA;AAErF,MAAM,UAAU,GAAG,CAAC,MAAmB,EAAE,EAAE;IACzC,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,CAAC,CAAA;IAChC,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,UAAU,GAAG,4BAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,MAAM,UAAU,GAAG,4BAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,OAAO,UAAU,GAAG,UAAU,CAAA;IAChC,CAAC,CAAC,CAAA;IACF,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAEY,QAAA,UAAU,GAAG;IACxB,aAAa;IACb,aAAa;IACb,eAAe;IACf,aAAa;IACb,cAAc;IACd,kBAAkB;IAClB,oBAAoB;IACpB,cAAc;IACd,UAAU;CACX,CAAA","sourcesContent":["import { UUIDs } from '../utils'\nimport {\n AuthGroup,\n AuthGroupName,\n createDefaultAuthGroups,\n permissionsByGroupName,\n sortedGroupNames,\n} from './authGroup'\nimport { RecordStepPermission } from './permission'\n\nconst isSystemAdmin = (authGroup: AuthGroup): boolean => authGroup?.name === AuthGroupName.systemAdmin\n\nconst isSurveyManager = (authGroup: AuthGroup): boolean => authGroup?.name === AuthGroupName.surveyManager\n\nconst isSurveyGroup = (authGroup: AuthGroup): boolean => !isSystemAdmin(authGroup) && !isSurveyManager(authGroup)\n\nconst getSurveyUuid = (authGroup: AuthGroup): string | undefined => authGroup?.surveyUuid\n\nconst getRecordSteps = (authGroup?: AuthGroup): { [key: string]: RecordStepPermission } | undefined =>\n authGroup?.recordSteps\n\nconst getRecordEditLevel =\n (step: string) =>\n (authGroup?: AuthGroup): RecordStepPermission => {\n const steps = getRecordSteps(authGroup)\n if (!steps) throw new Error('No steps')\n\n return steps[step]\n }\n\nconst getDefaultAuthGroups = (surveyUuid: string): AuthGroup[] =>\n createDefaultAuthGroups().map((group) => ({ ...group, uuid: UUIDs.v4(), surveyUuid }))\n\nconst getPermissions = (group: AuthGroup) => permissionsByGroupName[group.name] ?? []\n\nconst sortGroups = (groups: AuthGroup[]) => {\n const sortedGroups = [...groups]\n sortedGroups.sort((group1, group2) => {\n const sortOrder1 = sortedGroupNames.indexOf(group1.name)\n const sortOrder2 = sortedGroupNames.indexOf(group2.name)\n return sortOrder1 - sortOrder2\n })\n return sortedGroups\n}\n\nexport const AuthGroups = {\n isSystemAdmin,\n isSurveyGroup,\n isSurveyManager,\n getSurveyUuid,\n getRecordSteps,\n getRecordEditLevel,\n getDefaultAuthGroups,\n getPermissions,\n sortGroups,\n}\n"]}
1
+ {"version":3,"file":"authGroups.js","sourceRoot":"","sources":["../../src/auth/authGroups.ts"],"names":[],"mappings":";;;AAAA,oCAAgC;AAChC,2CAMoB;AAGpB,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,yBAAa,CAAC,WAAW,CAAA;AAEtG,MAAM,eAAe,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,yBAAa,CAAC,aAAa,CAAA;AAE1G,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;AAEjH,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAsB,EAAE,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,UAAU,CAAA;AAEzF,MAAM,cAAc,GAAG,CAAC,SAAqB,EAAuD,EAAE,CACpG,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,CAAA;AAExB,MAAM,oBAAoB,GAAG,CAAC,UAAkB,EAAe,EAAE,CAC/D,IAAA,mCAAuB,GAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCAAM,KAAK,KAAE,IAAI,EAAE,aAAK,CAAC,EAAE,EAAE,EAAE,UAAU,IAAG,CAAC,CAAA;AAExF,MAAM,cAAc,GAAG,CAAC,KAAgB,EAAE,EAAE,wBAAC,kCAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,mCAAI,EAAE,GAAA,CAAA;AAErF,MAAM,UAAU,GAAG,CAAC,MAAmB,EAAE,EAAE;IACzC,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,CAAC,CAAA;IAChC,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,UAAU,GAAG,4BAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,MAAM,UAAU,GAAG,4BAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,OAAO,UAAU,GAAG,UAAU,CAAA;IAChC,CAAC,CAAC,CAAA;IACF,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAEY,QAAA,UAAU,GAAG;IACxB,aAAa;IACb,aAAa;IACb,eAAe;IACf,aAAa;IACb,cAAc;IACd,oBAAoB;IACpB,cAAc;IACd,UAAU;CACX,CAAA","sourcesContent":["import { UUIDs } from '../utils'\nimport {\n AuthGroup,\n AuthGroupName,\n createDefaultAuthGroups,\n permissionsByGroupName,\n sortedGroupNames,\n} from './authGroup'\nimport { RecordStepPermission } from './permission'\n\nconst isSystemAdmin = (authGroup: AuthGroup): boolean => authGroup?.name === AuthGroupName.systemAdmin\n\nconst isSurveyManager = (authGroup: AuthGroup): boolean => authGroup?.name === AuthGroupName.surveyManager\n\nconst isSurveyGroup = (authGroup: AuthGroup): boolean => !isSystemAdmin(authGroup) && !isSurveyManager(authGroup)\n\nconst getSurveyUuid = (authGroup: AuthGroup): string | undefined => authGroup?.surveyUuid\n\nconst getRecordSteps = (authGroup?: AuthGroup): { [key: string]: RecordStepPermission } | undefined =>\n authGroup?.recordSteps\n\nconst getDefaultAuthGroups = (surveyUuid: string): AuthGroup[] =>\n createDefaultAuthGroups().map((group) => ({ ...group, uuid: UUIDs.v4(), surveyUuid }))\n\nconst getPermissions = (group: AuthGroup) => permissionsByGroupName[group.name] ?? []\n\nconst sortGroups = (groups: AuthGroup[]) => {\n const sortedGroups = [...groups]\n sortedGroups.sort((group1, group2) => {\n const sortOrder1 = sortedGroupNames.indexOf(group1.name)\n const sortOrder2 = sortedGroupNames.indexOf(group2.name)\n return sortOrder1 - sortOrder2\n })\n return sortedGroups\n}\n\nexport const AuthGroups = {\n isSystemAdmin,\n isSurveyGroup,\n isSurveyManager,\n getSurveyUuid,\n getRecordSteps,\n getDefaultAuthGroups,\n getPermissions,\n sortGroups,\n}\n"]}
@@ -5,12 +5,6 @@ const isSurveyManager = (authGroup) => (authGroup === null || authGroup === void
5
5
  const isSurveyGroup = (authGroup) => !isSystemAdmin(authGroup) && !isSurveyManager(authGroup);
6
6
  const getSurveyUuid = (authGroup) => authGroup === null || authGroup === void 0 ? void 0 : authGroup.surveyUuid;
7
7
  const getRecordSteps = (authGroup) => authGroup === null || authGroup === void 0 ? void 0 : authGroup.recordSteps;
8
- const getRecordEditLevel = (step) => (authGroup) => {
9
- const steps = getRecordSteps(authGroup);
10
- if (!steps)
11
- throw new Error('No steps');
12
- return steps[step];
13
- };
14
8
  const getDefaultAuthGroups = (surveyUuid) => createDefaultAuthGroups().map((group) => (Object.assign(Object.assign({}, group), { uuid: UUIDs.v4(), surveyUuid })));
15
9
  const getPermissions = (group) => { var _a; return (_a = permissionsByGroupName[group.name]) !== null && _a !== void 0 ? _a : []; };
16
10
  const sortGroups = (groups) => {
@@ -28,7 +22,6 @@ export const AuthGroups = {
28
22
  isSurveyManager,
29
23
  getSurveyUuid,
30
24
  getRecordSteps,
31
- getRecordEditLevel,
32
25
  getDefaultAuthGroups,
33
26
  getPermissions,
34
27
  sortGroups,
@@ -1 +1 @@
1
- {"version":3,"file":"authGroups.js","sourceRoot":"","sources":["../../../src/auth/authGroups.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAEL,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,aAAa,CAAA;AAGpB,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,aAAa,CAAC,WAAW,CAAA;AAEtG,MAAM,eAAe,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,aAAa,CAAC,aAAa,CAAA;AAE1G,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;AAEjH,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAsB,EAAE,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,UAAU,CAAA;AAEzF,MAAM,cAAc,GAAG,CAAC,SAAqB,EAAuD,EAAE,CACpG,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,CAAA;AAExB,MAAM,kBAAkB,GACtB,CAAC,IAAY,EAAE,EAAE,CACjB,CAAC,SAAqB,EAAwB,EAAE;IAC9C,MAAM,KAAK,GAAG,cAAc,CAAC,SAAS,CAAC,CAAA;IACvC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAA;IAEvC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAA;AACpB,CAAC,CAAA;AAEH,MAAM,oBAAoB,GAAG,CAAC,UAAkB,EAAe,EAAE,CAC/D,uBAAuB,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCAAM,KAAK,KAAE,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,UAAU,IAAG,CAAC,CAAA;AAExF,MAAM,cAAc,GAAG,CAAC,KAAgB,EAAE,EAAE,wBAAC,sBAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,mCAAI,EAAE,GAAA,CAAA;AAErF,MAAM,UAAU,GAAG,CAAC,MAAmB,EAAE,EAAE;IACzC,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,CAAC,CAAA;IAChC,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,OAAO,UAAU,GAAG,UAAU,CAAA;IAChC,CAAC,CAAC,CAAA;IACF,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,aAAa;IACb,aAAa;IACb,eAAe;IACf,aAAa;IACb,cAAc;IACd,kBAAkB;IAClB,oBAAoB;IACpB,cAAc;IACd,UAAU;CACX,CAAA","sourcesContent":["import { UUIDs } from '../utils'\nimport {\n AuthGroup,\n AuthGroupName,\n createDefaultAuthGroups,\n permissionsByGroupName,\n sortedGroupNames,\n} from './authGroup'\nimport { RecordStepPermission } from './permission'\n\nconst isSystemAdmin = (authGroup: AuthGroup): boolean => authGroup?.name === AuthGroupName.systemAdmin\n\nconst isSurveyManager = (authGroup: AuthGroup): boolean => authGroup?.name === AuthGroupName.surveyManager\n\nconst isSurveyGroup = (authGroup: AuthGroup): boolean => !isSystemAdmin(authGroup) && !isSurveyManager(authGroup)\n\nconst getSurveyUuid = (authGroup: AuthGroup): string | undefined => authGroup?.surveyUuid\n\nconst getRecordSteps = (authGroup?: AuthGroup): { [key: string]: RecordStepPermission } | undefined =>\n authGroup?.recordSteps\n\nconst getRecordEditLevel =\n (step: string) =>\n (authGroup?: AuthGroup): RecordStepPermission => {\n const steps = getRecordSteps(authGroup)\n if (!steps) throw new Error('No steps')\n\n return steps[step]\n }\n\nconst getDefaultAuthGroups = (surveyUuid: string): AuthGroup[] =>\n createDefaultAuthGroups().map((group) => ({ ...group, uuid: UUIDs.v4(), surveyUuid }))\n\nconst getPermissions = (group: AuthGroup) => permissionsByGroupName[group.name] ?? []\n\nconst sortGroups = (groups: AuthGroup[]) => {\n const sortedGroups = [...groups]\n sortedGroups.sort((group1, group2) => {\n const sortOrder1 = sortedGroupNames.indexOf(group1.name)\n const sortOrder2 = sortedGroupNames.indexOf(group2.name)\n return sortOrder1 - sortOrder2\n })\n return sortedGroups\n}\n\nexport const AuthGroups = {\n isSystemAdmin,\n isSurveyGroup,\n isSurveyManager,\n getSurveyUuid,\n getRecordSteps,\n getRecordEditLevel,\n getDefaultAuthGroups,\n getPermissions,\n sortGroups,\n}\n"]}
1
+ {"version":3,"file":"authGroups.js","sourceRoot":"","sources":["../../../src/auth/authGroups.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAEL,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,aAAa,CAAA;AAGpB,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAW,EAAE,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE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A;IACF,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,aAAa;IACb,aAAa;IACb,eAAe;IACf,aAAa;IACb,cAAc;IACd,oBAAoB;IACpB,cAAc;IACd,UAAU;CACX,CAAA","sourcesContent":["import { UUIDs } from '../utils'\nimport {\n AuthGroup,\n AuthGroupName,\n createDefaultAuthGroups,\n permissionsByGroupName,\n sortedGroupNames,\n} from './authGroup'\nimport { RecordStepPermission } from './permission'\n\nconst isSystemAdmin = (authGroup: AuthGroup): boolean => authGroup?.name === AuthGroupName.systemAdmin\n\nconst isSurveyManager = (authGroup: AuthGroup): boolean => authGroup?.name === AuthGroupName.surveyManager\n\nconst isSurveyGroup = (authGroup: AuthGroup): boolean => !isSystemAdmin(authGroup) && !isSurveyManager(authGroup)\n\nconst getSurveyUuid = (authGroup: AuthGroup): string | undefined => authGroup?.surveyUuid\n\nconst getRecordSteps = (authGroup?: AuthGroup): { [key: string]: RecordStepPermission } | undefined =>\n authGroup?.recordSteps\n\nconst getDefaultAuthGroups = (surveyUuid: string): AuthGroup[] =>\n createDefaultAuthGroups().map((group) => ({ ...group, uuid: UUIDs.v4(), surveyUuid }))\n\nconst getPermissions = (group: AuthGroup) => permissionsByGroupName[group.name] ?? []\n\nconst sortGroups = (groups: AuthGroup[]) => {\n const sortedGroups = [...groups]\n sortedGroups.sort((group1, group2) => {\n const sortOrder1 = sortedGroupNames.indexOf(group1.name)\n const sortOrder2 = sortedGroupNames.indexOf(group2.name)\n return sortOrder1 - sortOrder2\n })\n return sortedGroups\n}\n\nexport const AuthGroups = {\n isSystemAdmin,\n isSurveyGroup,\n isSurveyManager,\n getSurveyUuid,\n getRecordSteps,\n getDefaultAuthGroups,\n getPermissions,\n sortGroups,\n}\n"]}
@@ -16,6 +16,8 @@ export const distanceToPolygonBoundary = (point, polygon, srsIndex = DEFAULT_SRS
16
16
  try {
17
17
  // turf expects [longitude, latitude]; planar: polygon edges are straight lines (as in GeoJSON and on the map),
18
18
  // consistent with the inside/outside check (geodesic would measure to great-circle edges)
19
+ // shortcut: polygons crossing the antimeridian (longitudes jumping from 180 to -180) are measured wrong,
20
+ // split them in 2 polygons (one for each side) if such areas of interest are needed
19
21
  return pointToPolygonDistance([pointLatLong.x, pointLatLong.y], polygon, { units: 'meters', method: 'planar' });
20
22
  }
21
23
  catch (_a) {
@@ -1 +1 @@
1
- {"version":3,"file":"distanceToPolygonBoundary.js","sourceRoot":"","sources":["../../../../src/geo/points/distanceToPolygonBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,MAAM,iCAAiC,CAAA;AAEpE,OAAO,EAAE,iBAAiB,EAAY,MAAM,WAAW,CAAA;AAGvD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,KAAY,EACZ,OAAuB,EACvB,QAAQ,GAAa,iBAAiB,EACvB,EAAE;IACjB,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC/C,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAA;IAC9B,IAAI,CAAC;QACH,+GAA+G;QAC/G,0FAA0F;QAC1F,OAAO,sBAAsB,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;IACjH,CAAC;eAAO,CAAC;QACP,2BAA2B;QAC3B,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA","sourcesContent":["import pointToPolygonDistance from '@turf/point-to-polygon-distance'\n\nimport { DEFAULT_SRS_INDEX, SRSIndex } from '../../srs'\nimport { AreaOfInterest } from '../areaOfInterest'\nimport { Point } from '../point'\nimport { toLatLong } from './toLatLong'\n\n/**\n * Returns the distance (in meters) between a point and the boundary of a polygon: negative inside, positive outside.\n *\n * @param {!Point} point - The point.\n * @param {!AreaOfInterest} polygon - Polygon or multi polygon in WGS84.\n * @param {!SRSIndex} srsIndex - SRSs indexed by SRS code.\n * @returns {number|null} - The signed distance in meters, or null if the point or the polygon are not valid.\n */\nexport const distanceToPolygonBoundary = (\n point: Point,\n polygon: AreaOfInterest,\n srsIndex: SRSIndex = DEFAULT_SRS_INDEX\n): number | null => {\n const pointLatLong = toLatLong(point, srsIndex)\n if (!pointLatLong) return null\n try {\n // turf expects [longitude, latitude]; planar: polygon edges are straight lines (as in GeoJSON and on the map),\n // consistent with the inside/outside check (geodesic would measure to great-circle edges)\n return pointToPolygonDistance([pointLatLong.x, pointLatLong.y], polygon, { units: 'meters', method: 'planar' })\n } catch {\n // invalid polygon geometry\n return null\n }\n}\n"]}
1
+ {"version":3,"file":"distanceToPolygonBoundary.js","sourceRoot":"","sources":["../../../../src/geo/points/distanceToPolygonBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,MAAM,iCAAiC,CAAA;AAEpE,OAAO,EAAE,iBAAiB,EAAY,MAAM,WAAW,CAAA;AAGvD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,KAAY,EACZ,OAAuB,EACvB,QAAQ,GAAa,iBAAiB,EACvB,EAAE;IACjB,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC/C,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAA;IAC9B,IAAI,CAAC;QACH,+GAA+G;QAC/G,0FAA0F;QAC1F,yGAAyG;QACzG,oFAAoF;QACpF,OAAO,sBAAsB,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;IACjH,CAAC;eAAO,CAAC;QACP,2BAA2B;QAC3B,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA","sourcesContent":["import pointToPolygonDistance from '@turf/point-to-polygon-distance'\n\nimport { DEFAULT_SRS_INDEX, SRSIndex } from '../../srs'\nimport { AreaOfInterest } from '../areaOfInterest'\nimport { Point } from '../point'\nimport { toLatLong } from './toLatLong'\n\n/**\n * Returns the distance (in meters) between a point and the boundary of a polygon: negative inside, positive outside.\n *\n * @param {!Point} point - The point.\n * @param {!AreaOfInterest} polygon - Polygon or multi polygon in WGS84.\n * @param {!SRSIndex} srsIndex - SRSs indexed by SRS code.\n * @returns {number|null} - The signed distance in meters, or null if the point or the polygon are not valid.\n */\nexport const distanceToPolygonBoundary = (\n point: Point,\n polygon: AreaOfInterest,\n srsIndex: SRSIndex = DEFAULT_SRS_INDEX\n): number | null => {\n const pointLatLong = toLatLong(point, srsIndex)\n if (!pointLatLong) return null\n try {\n // turf expects [longitude, latitude]; planar: polygon edges are straight lines (as in GeoJSON and on the map),\n // consistent with the inside/outside check (geodesic would measure to great-circle edges)\n // shortcut: polygons crossing the antimeridian (longitudes jumping from 180 to -180) are measured wrong,\n // split them in 2 polygons (one for each side) if such areas of interest are needed\n return pointToPolygonDistance([pointLatLong.x, pointLatLong.y], polygon, { units: 'meters', method: 'planar' })\n } catch {\n // invalid polygon geometry\n return null\n }\n}\n"]}
@@ -11,15 +11,14 @@ import { Nodes } from '../../node';
11
11
  import { NodeDefs } from '../../nodeDef';
12
12
  import { Surveys } from '../../survey';
13
13
  import { SurveyDependencyType } from '../../survey/survey';
14
- import { RecordExpressionEvaluator } from '../recordExpressionEvaluator';
15
14
  import { Records } from '../records';
15
+ import { calculateBooleanValueNext } from './recordNodeDependentsBooleanUpdater';
16
16
  import { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater';
17
17
  import { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater';
18
18
  import { addNodeAndDescendants } from './recordNodesCreator';
19
19
  import { removeNodes } from './recordNodesDeleter';
20
20
  import { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons';
21
21
  import { RecordUpdateResult } from './recordUpdateResult';
22
- const expressionEvaluator = new RecordExpressionEvaluator();
23
22
  const extractNodePointersToUpdate = (params) => {
24
23
  const { survey, record, node } = params;
25
24
  const nodePointersToUpdate = getDependentNodePointersByType({
@@ -32,28 +31,7 @@ const extractNodePointersToUpdate = (params) => {
32
31
  });
33
32
  return nodePointersToUpdate;
34
33
  };
35
- const calculateApplicableNext = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, updateResult, nodePointer, nodeCtx, }) {
36
- const { nodeDef: nodeDefNodePointer } = nodePointer;
37
- const { uuid: nodeDefUuid } = nodeDefNodePointer;
38
- const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid);
39
- const expressionsToEvaluate = NodeDefs.getApplicable(nodeDefNodePointer);
40
- if (expressionsToEvaluate.length === 0) {
41
- if (applicablePrev) {
42
- // skip nodes that were already applicable and have no applicable expression, as they will remain applicable
43
- return undefined;
44
- }
45
- else {
46
- // used during survey publishing: node def could have had applicable expression(s) that were removed,
47
- // and node could have been not applicable, but now it should be applicable, as there are no more applicable expressions
48
- return true;
49
- }
50
- }
51
- else {
52
- // 3. evaluate applicable expression
53
- const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, expressions: expressionsToEvaluate }));
54
- return (exprEval === null || exprEval === void 0 ? void 0 : exprEval.value) || false;
55
- }
56
- });
34
+ const calculateApplicableNext = (params) => calculateBooleanValueNext(Object.assign(Object.assign({}, params), { getExpressions: (nodePointer) => NodeDefs.getApplicable(nodePointer.nodeDef), getValuePrev: Nodes.isChildApplicable }));
57
35
  const updateDescendantsApplicability = ({ updateResult, nodeCtxChild, applicable, params, recordUpdateOptions, }) => {
58
36
  const { survey, sideEffect = false, clearNonApplicableValues = false } = params;
59
37
  // only values entered by the user are reported as cleared (they need a confirmation)
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsApplicableUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAgC,KAAK,EAAE,MAAM,YAAY,CAAA;AAChE,OAAO,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAU,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,OAAO,EAAuB,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,gCAAgC,EAAE,MAAM,iDAAiD,CAAA;AAClG,OAAO,EAAE,4BAA4B,EAAE,MAAM,+CAA+C,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAA;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AAE3D,MAAM,2BAA2B,GAAG,CAAC,MAAsE,EAAE,EAAE;IAC7G,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAEvC,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;QAC1D,MAAM;QACN,MAAM;QACN,IAAI;QACJ,cAAc,EAAE,oBAAoB,CAAC,UAAU;QAC/C,gCAAgC,EAAE,IAAI;QACtC,6BAA6B,EAAE,IAAI;KACpC,CAAC,CAAA;IACF,OAAO,oBAAoB,CAAA;AAC7B,CAAC,CAAA;AAED,MAAM,uBAAuB,GAA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AAC;QAC/C,MAAM,8BAA8B,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAA,CAAC,UAAU;IAC7G,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodePointer, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records, RecordUpdateOptions } from '../records'\nimport { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { addNodeAndDescendants } from './recordNodesCreator'\nimport { removeNodes } from './recordNodesDeleter'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nconst extractNodePointersToUpdate = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }) => {\n const { survey, record, node } = params\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.applicable,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntityChildPointers: true,\n })\n return nodePointersToUpdate\n}\n\nconst calculateApplicableNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = NodeDefs.getApplicable(nodeDefNodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (applicablePrev) {\n // skip nodes that were already applicable and have no applicable expression, as they will remain applicable\n return undefined\n } else {\n // used during survey publishing: node def could have had applicable expression(s) that were removed,\n // and node could have been not applicable, but now it should be applicable, as there are no more applicable expressions\n return true\n }\n } else {\n // 3. evaluate applicable expression\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n }\n}\n\nconst updateDescendantsApplicability = ({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n}: {\n updateResult: RecordUpdateResult\n nodeCtxChild: ArenaRecordNode\n applicable: boolean\n params: RecordNodeDependentsUpdateParams\n recordUpdateOptions: RecordUpdateOptions\n}): void => {\n const { survey, sideEffect = false, clearNonApplicableValues = false } = params\n\n // only values entered by the user are reported as cleared (they need a confirmation)\n let userValuesCleared = false\n\n Records.visitDescendantsAndSelf(nodeCtxChild, (nodeDescendant): boolean => {\n const nodeDescendantCleared = clearNonApplicableValues && !applicable && Nodes.isValueNotBlank(nodeDescendant)\n // values set by expressions (default values, read only attributes) are applied again when applicable: not reported\n // (evaluated before clearing the value: with sideEffect the node is modified in place)\n const nodeDescendantDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDescendant.nodeDefUuid })\n const userValueCleared =\n nodeDescendantCleared && !NodeDefs.isReadOnly(nodeDescendantDef) && Nodes.hasUserInputValue(nodeDescendant)\n // Clear value if becoming non-applicable and parameter is enabled\n const nodeDescendantUpdated = nodeDescendantCleared\n ? Nodes.assocValue(nodeDescendant, null, { sideEffect })\n : nodeDescendant\n updateResult.addNode(nodeDescendantUpdated, recordUpdateOptions)\n if (userValueCleared) {\n updateResult.addClearedDefUuid(nodeDescendant.nodeDefUuid)\n userValuesCleared = true\n }\n return false\n })(updateResult.record)\n\n // if a multiple entity became not applicable and it's empty, delete it instead of just marking descendants as not applicable\n if (!applicable && clearNonApplicableValues) {\n const { uuid: nodeCtxChildUuid, nodeDefUuid: nodeCtxChildDefUuid } = nodeCtxChild\n const nodeCtxChildDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeCtxChildDefUuid })\n if (NodeDefs.isMultipleEntity(nodeCtxChildDef) && Records.isNodeEmpty(nodeCtxChild)(updateResult.record)) {\n const deleteResult = removeNodes([nodeCtxChildUuid], recordUpdateOptions)(updateResult.record)\n updateResult.merge(deleteResult)\n if (userValuesCleared) {\n updateResult.addClearedDefUuid(nodeCtxChildDefUuid)\n }\n }\n }\n}\n\nconst createMissingApplicableMultipleEntities = async ({\n params,\n updateResult,\n parentNode,\n nodeDef,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n parentNode: ArenaRecordNode\n nodeDef: NodeDefEntity\n}): Promise<void> => {\n if (!NodeDefs.isAutoCreateMinCountItems(nodeDef)) return\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef })\n if (Number.isNaN(minCount) || minCount <= 0) return\n\n const existingChildren = Records.getChildren(parentNode, nodeDef.uuid)(updateResult.record)\n const missingCount = Math.max(0, minCount - existingChildren.length)\n\n for (let index = 0; index < missingCount; index++) {\n const createParams = { ...params, record: updateResult.record, parentNode, nodeDef }\n // create nodes sequentially: every iteration works on the record updated by the previous one\n const childUpdateResult = await addNodeAndDescendants(createParams) // NOSONAR\n updateResult.merge(childUpdateResult)\n }\n}\n\nconst updateNodePointerApplicability = async ({\n params,\n updateResult,\n nodePointer,\n recordUpdateOptions,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n recordUpdateOptions: RecordUpdateOptions\n}): Promise<void> => {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n // nodeCtx could have been updated in a previous iteration\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const applicable = await calculateApplicableNext({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n })\n if (applicable === undefined) {\n return\n }\n\n if (applicable && NodeDefs.isMultipleEntity(nodeDefNodePointer)) {\n await createMissingApplicableMultipleEntities({\n params,\n updateResult,\n parentNode: nodeCtx,\n nodeDef: nodeDefNodePointer as NodeDefEntity,\n })\n }\n\n // 4. persist updated applicability if changed, and return updated nodes\n if (applicablePrev === applicable) {\n return\n }\n // Applicability changed\n\n // update node and add it to nodes updated\n const nodeCtxUpdated = Nodes.assocChildApplicability(nodeCtx, nodeDefUuid, applicable)\n updateResult.addNode(nodeCtxUpdated, recordUpdateOptions)\n\n let nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n\n if (NodeDefs.isMultipleEntity(nodeDefNodePointer) && NodeDefs.isEnumerate(nodeDefNodePointer as NodeDefEntity)) {\n const entityDef = nodeDefNodePointer as NodeDefEntity\n if (NodeDefs.getEnumeratingItemsExpression(entityDef)) {\n await syncEnumeratingItemsEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n } else {\n await createOrDeleteEnumeratedEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n }\n nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n }\n for (const nodeCtxChild of nodeCtxChildren) {\n // add nodeCtxChild and its descendants to nodesUpdated\n updateDescendantsApplicability({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n })\n }\n}\n\nexport const updateSelfAndDependentsApplicable = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions: RecordUpdateOptions = { sideEffect }\n\n // 1. fetch dependent nodes\n const nodePointersToUpdate = extractNodePointersToUpdate({ survey, record, node })\n\n // 2. update expr to node and dependent nodes\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n await updateNodePointerApplicability({ params, updateResult, nodePointer, recordUpdateOptions }) // NOSONAR\n }\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsApplicableUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAgC,KAAK,EAAE,MAAM,YAAY,CAAA;AAChE,OAAO,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAU,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,EAAE,OAAO,EAAuB,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AAChF,OAAO,EAAE,gCAAgC,EAAE,MAAM,iDAAiD,CAAA;AAClG,OAAO,EAAE,4BAA4B,EAAE,MAAM,+CAA+C,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAA;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,2BAA2B,GAAG,CAAC,MAAsE,EAAE,EAAE;IAC7G,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAEvC,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;QAC1D,MAAM;QACN,MAAM;QACN,IAAI;QACJ,cAAc,EAAE,o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C,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;IAClF,CAAC;IACD,KAAK,MAAM,YAAY,IAAI,eAAe,EAAE,CAAC;QAC3C,uDAAuD;QACvD,8BAA8B,CAAC;YAC7B,YAAY;YACZ,YAAY;YACZ,UAAU;YACV,MAAM;YACN,mBAAmB;SACpB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC/C,MAAwC,EACX,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAE3D,MAAM,YAAY,GAAG,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEvD,MAAM,mBAAmB,GAAwB,EAAE,UAAU,EAAE,CAAA;IAE/D,2BAA2B;IAC3B,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAElF,6CAA6C;IAC7C,4EAA4E;IAC5E,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,MAAM,8BAA8B,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAA,CAAC,UAAU;IAC7G,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodePointer, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { ArenaRecord } from '../record'\nimport { Records, RecordUpdateOptions } from '../records'\nimport { calculateBooleanValueNext } from './recordNodeDependentsBooleanUpdater'\nimport { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { addNodeAndDescendants } from './recordNodesCreator'\nimport { removeNodes } from './recordNodesDeleter'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst extractNodePointersToUpdate = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }) => {\n const { survey, record, node } = params\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.applicable,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntityChildPointers: true,\n })\n return nodePointersToUpdate\n}\n\nconst calculateApplicableNext = (params: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n}): Promise<boolean | undefined> =>\n calculateBooleanValueNext({\n ...params,\n getExpressions: (nodePointer) => NodeDefs.getApplicable(nodePointer.nodeDef),\n getValuePrev: Nodes.isChildApplicable,\n })\n\nconst updateDescendantsApplicability = ({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n}: {\n updateResult: RecordUpdateResult\n nodeCtxChild: ArenaRecordNode\n applicable: boolean\n params: RecordNodeDependentsUpdateParams\n recordUpdateOptions: RecordUpdateOptions\n}): void => {\n const { survey, sideEffect = false, clearNonApplicableValues = false } = params\n\n // only values entered by the user are reported as cleared (they need a confirmation)\n let userValuesCleared = false\n\n Records.visitDescendantsAndSelf(nodeCtxChild, (nodeDescendant): boolean => {\n const nodeDescendantCleared = clearNonApplicableValues && !applicable && Nodes.isValueNotBlank(nodeDescendant)\n // values set by expressions (default values, read only attributes) are applied again when applicable: not reported\n // (evaluated before clearing the value: with sideEffect the node is modified in place)\n const nodeDescendantDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDescendant.nodeDefUuid })\n const userValueCleared =\n nodeDescendantCleared && !NodeDefs.isReadOnly(nodeDescendantDef) && Nodes.hasUserInputValue(nodeDescendant)\n // Clear value if becoming non-applicable and parameter is enabled\n const nodeDescendantUpdated = nodeDescendantCleared\n ? Nodes.assocValue(nodeDescendant, null, { sideEffect })\n : nodeDescendant\n updateResult.addNode(nodeDescendantUpdated, recordUpdateOptions)\n if (userValueCleared) {\n updateResult.addClearedDefUuid(nodeDescendant.nodeDefUuid)\n userValuesCleared = true\n }\n return false\n })(updateResult.record)\n\n // if a multiple entity became not applicable and it's empty, delete it instead of just marking descendants as not applicable\n if (!applicable && clearNonApplicableValues) {\n const { uuid: nodeCtxChildUuid, nodeDefUuid: nodeCtxChildDefUuid } = nodeCtxChild\n const nodeCtxChildDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeCtxChildDefUuid })\n if (NodeDefs.isMultipleEntity(nodeCtxChildDef) && Records.isNodeEmpty(nodeCtxChild)(updateResult.record)) {\n const deleteResult = removeNodes([nodeCtxChildUuid], recordUpdateOptions)(updateResult.record)\n updateResult.merge(deleteResult)\n if (userValuesCleared) {\n updateResult.addClearedDefUuid(nodeCtxChildDefUuid)\n }\n }\n }\n}\n\nconst createMissingApplicableMultipleEntities = async ({\n params,\n updateResult,\n parentNode,\n nodeDef,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n parentNode: ArenaRecordNode\n nodeDef: NodeDefEntity\n}): Promise<void> => {\n if (!NodeDefs.isAutoCreateMinCountItems(nodeDef)) return\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef })\n if (Number.isNaN(minCount) || minCount <= 0) return\n\n const existingChildren = Records.getChildren(parentNode, nodeDef.uuid)(updateResult.record)\n const missingCount = Math.max(0, minCount - existingChildren.length)\n\n for (let index = 0; index < missingCount; index++) {\n const createParams = { ...params, record: updateResult.record, parentNode, nodeDef }\n // create nodes sequentially: every iteration works on the record updated by the previous one\n const childUpdateResult = await addNodeAndDescendants(createParams) // NOSONAR\n updateResult.merge(childUpdateResult)\n }\n}\n\nconst updateNodePointerApplicability = async ({\n params,\n updateResult,\n nodePointer,\n recordUpdateOptions,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n recordUpdateOptions: RecordUpdateOptions\n}): Promise<void> => {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n // nodeCtx could have been updated in a previous iteration\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const applicable = await calculateApplicableNext({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n })\n if (applicable === undefined) {\n return\n }\n\n if (applicable && NodeDefs.isMultipleEntity(nodeDefNodePointer)) {\n await createMissingApplicableMultipleEntities({\n params,\n updateResult,\n parentNode: nodeCtx,\n nodeDef: nodeDefNodePointer as NodeDefEntity,\n })\n }\n\n // 4. persist updated applicability if changed, and return updated nodes\n if (applicablePrev === applicable) {\n return\n }\n // Applicability changed\n\n // update node and add it to nodes updated\n const nodeCtxUpdated = Nodes.assocChildApplicability(nodeCtx, nodeDefUuid, applicable)\n updateResult.addNode(nodeCtxUpdated, recordUpdateOptions)\n\n let nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n\n if (NodeDefs.isMultipleEntity(nodeDefNodePointer) && NodeDefs.isEnumerate(nodeDefNodePointer as NodeDefEntity)) {\n const entityDef = nodeDefNodePointer as NodeDefEntity\n if (NodeDefs.getEnumeratingItemsExpression(entityDef)) {\n await syncEnumeratingItemsEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n } else {\n await createOrDeleteEnumeratedEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n }\n nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n }\n for (const nodeCtxChild of nodeCtxChildren) {\n // add nodeCtxChild and its descendants to nodesUpdated\n updateDescendantsApplicability({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n })\n }\n}\n\nexport const updateSelfAndDependentsApplicable = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions: RecordUpdateOptions = { sideEffect }\n\n // 1. fetch dependent nodes\n const nodePointersToUpdate = extractNodePointersToUpdate({ survey, record, node })\n\n // 2. update expr to node and dependent nodes\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n await updateNodePointerApplicability({ params, updateResult, nodePointer, recordUpdateOptions }) // NOSONAR\n }\n return updateResult\n}\n"]}
@@ -11,15 +11,18 @@ import { RecordExpressionEvaluator } from '../recordExpressionEvaluator';
11
11
  import { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons';
12
12
  import { RecordUpdateResult } from './recordUpdateResult';
13
13
  const expressionEvaluator = new RecordExpressionEvaluator();
14
- const calculateBooleanValueNext = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev, }) {
14
+ export const calculateBooleanValueNext = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev, }) {
15
15
  const { nodeDef: nodeDefNodePointer } = nodePointer;
16
16
  const { uuid: nodeDefUuid } = nodeDefNodePointer;
17
17
  const valuePrev = getValuePrev(nodeCtx, nodeDefUuid);
18
18
  const expressionsToEvaluate = getExpressions(nodePointer);
19
19
  if (expressionsToEvaluate.length === 0) {
20
20
  if (valuePrev) {
21
+ // skip nodes already having the value true and no expressions, as they will keep it
21
22
  return undefined;
22
23
  }
24
+ // used during survey publishing: node def could have had expression(s) that were removed,
25
+ // and the value could have been false, but now it should be true, as there are no more expressions
23
26
  return true;
24
27
  }
25
28
  const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, expressions: expressionsToEvaluate }));
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsBooleanUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAA;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AAgB3D,MAAM,yBAAyB,GAAG,KAcD,EAAE,4CAdM,EACvC,MAAM,EACN,YAAY,EACZ,WAAW,EACX,OAAO,EACP,cAAc,EACd,YAAY,GAQb;IACC,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,WAAW,CAAA;IACnD,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,kBAAkB,CAAA;IAEhD,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IACpD,MAAM,qBAAqB,GAAG,cAAc,CAAC,WAAW,CAAC,CAAA;IACzD,IAAI,qBAAqB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,wBAAwB,iCAC9D,MAAM,KACT,MAAM,EAAE,YAAY,CAAC,MAAM,EAC3B,OAAO,EACP,WAAW,EAAE,qBAAqB,IAClC,CAAA;IACF,OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAA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,cAAc,GAAG,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QAC9E,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IACtD,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodePointer } from '../../node'\nimport { NodeDefExpression } from '../../nodeDef'\nimport { MutationOptions } from '../../utils/mutationOptions'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\ntype UpdateSelfAndDependentsBooleanParams = {\n params: RecordNodeDependentsUpdateParams\n dependencyType: SurveyDependencyType\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n assocValue: (\n nodeCtx: ArenaRecordNode,\n nodeDefUuid: string,\n value: boolean,\n options: MutationOptions\n ) => ArenaRecordNode\n includeNewEntitySelf?: boolean\n}\n\nconst calculateBooleanValueNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n getExpressions,\n getValuePrev,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = getExpressions(nodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (valuePrev) {\n return undefined\n }\n return true\n }\n\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n}\n\nexport const updateSelfAndDependentsBoolean = async ({\n params,\n dependencyType,\n getExpressions,\n getValuePrev,\n assocValue,\n includeNewEntitySelf = true,\n}: UpdateSelfAndDependentsBooleanParams): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n const updateResult = new RecordUpdateResult({ record })\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntitySelf,\n includeNewEntityChildPointers: true,\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev }\n const value = await calculateBooleanValueNext(calculateParams) // NOSONAR\n\n if (value === undefined || valuePrev === value) {\n continue\n }\n\n const nodeCtxUpdated = assocValue(nodeCtx, nodeDefUuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsBooleanUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,8BAA8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ationOptions } from '../../utils/mutationOptions'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\ntype UpdateSelfAndDependentsBooleanParams = {\n params: RecordNodeDependentsUpdateParams\n dependencyType: SurveyDependencyType\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n assocValue: (\n nodeCtx: ArenaRecordNode,\n nodeDefUuid: string,\n value: boolean,\n options: MutationOptions\n ) => ArenaRecordNode\n includeNewEntitySelf?: boolean\n}\n\nexport const calculateBooleanValueNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n getExpressions,\n getValuePrev,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = getExpressions(nodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (valuePrev) {\n // skip nodes already having the value true and no expressions, as they will keep it\n return undefined\n }\n // used during survey publishing: node def could have had expression(s) that were removed,\n // and the value could have been false, but now it should be true, as there are no more expressions\n return true\n }\n\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n}\n\nexport const updateSelfAndDependentsBoolean = async ({\n params,\n dependencyType,\n getExpressions,\n getValuePrev,\n assocValue,\n includeNewEntitySelf = true,\n}: UpdateSelfAndDependentsBooleanParams): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n const updateResult = new RecordUpdateResult({ record })\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntitySelf,\n includeNewEntityChildPointers: true,\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev }\n const value = await calculateBooleanValueNext(calculateParams) // NOSONAR\n\n if (value === undefined || valuePrev === value) {\n continue\n }\n\n const nodeCtxUpdated = assocValue(nodeCtx, nodeDefUuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n\n return updateResult\n}\n"]}
@@ -22,6 +22,8 @@ const distanceToPolygonBoundary = (point, polygon, srsIndex = srs_1.DEFAULT_SRS_
22
22
  try {
23
23
  // turf expects [longitude, latitude]; planar: polygon edges are straight lines (as in GeoJSON and on the map),
24
24
  // consistent with the inside/outside check (geodesic would measure to great-circle edges)
25
+ // shortcut: polygons crossing the antimeridian (longitudes jumping from 180 to -180) are measured wrong,
26
+ // split them in 2 polygons (one for each side) if such areas of interest are needed
25
27
  return (0, point_to_polygon_distance_1.default)([pointLatLong.x, pointLatLong.y], polygon, { units: 'meters', method: 'planar' });
26
28
  }
27
29
  catch (_a) {
@@ -1 +1 @@
1
- {"version":3,"file":"distanceToPolygonBoundary.js","sourceRoot":"","sources":["../../../src/geo/points/distanceToPolygonBoundary.ts"],"names":[],"mappings":";;;;;;AAAA,gGAAoE;AAEpE,mCAAuD;AAGvD,2CAAuC;AAEvC;;;;;;;GAOG;AACI,MAAM,yBAAyB,GAAG,CACvC,KAAY,EACZ,OAAuB,EACvB,QAAQ,GAAa,uBAAiB,EACvB,EAAE;IACjB,MAAM,YAAY,GAAG,IAAA,qBAAS,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC/C,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAA;IAC9B,IAAI,CAAC;QACH,+GAA+G;QAC/G,0FAA0F;QAC1F,OAAO,IAAA,mCAAsB,EAAC,CAAC,YAAY,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;IACjH,CAAC;eAAO,CAAC;QACP,2BAA2B;QAC3B,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAfY,QAAA,yBAAyB,GAAzB,yBAAyB,CAerC","sourcesContent":["import pointToPolygonDistance from '@turf/point-to-polygon-distance'\n\nimport { DEFAULT_SRS_INDEX, SRSIndex } from '../../srs'\nimport { AreaOfInterest } from '../areaOfInterest'\nimport { Point } from '../point'\nimport { toLatLong } from './toLatLong'\n\n/**\n * Returns the distance (in meters) between a point and the boundary of a polygon: negative inside, positive outside.\n *\n * @param {!Point} point - The point.\n * @param {!AreaOfInterest} polygon - Polygon or multi polygon in WGS84.\n * @param {!SRSIndex} srsIndex - SRSs indexed by SRS code.\n * @returns {number|null} - The signed distance in meters, or null if the point or the polygon are not valid.\n */\nexport const distanceToPolygonBoundary = (\n point: Point,\n polygon: AreaOfInterest,\n srsIndex: SRSIndex = DEFAULT_SRS_INDEX\n): number | null => {\n const pointLatLong = toLatLong(point, srsIndex)\n if (!pointLatLong) return null\n try {\n // turf expects [longitude, latitude]; planar: polygon edges are straight lines (as in GeoJSON and on the map),\n // consistent with the inside/outside check (geodesic would measure to great-circle edges)\n return pointToPolygonDistance([pointLatLong.x, pointLatLong.y], polygon, { units: 'meters', method: 'planar' })\n } catch {\n // invalid polygon geometry\n return null\n }\n}\n"]}
1
+ {"version":3,"file":"distanceToPolygonBoundary.js","sourceRoot":"","sources":["../../../src/geo/points/distanceToPolygonBoundary.ts"],"names":[],"mappings":";;;;;;AAAA,gGAAoE;AAEpE,mCAAuD;AAGvD,2CAAuC;AAEvC;;;;;;;GAOG;AACI,MAAM,yBAAyB,GAAG,CACvC,KAAY,EACZ,OAAuB,EACvB,QAAQ,GAAa,uBAAiB,EACvB,EAAE;IACjB,MAAM,YAAY,GAAG,IAAA,qBAAS,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC/C,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAA;IAC9B,IAAI,CAAC;QACH,+GAA+G;QAC/G,0FAA0F;QAC1F,yGAAyG;QACzG,oFAAoF;QACpF,OAAO,IAAA,mCAAsB,EAAC,CAAC,YAAY,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;IACjH,CAAC;eAAO,CAAC;QACP,2BAA2B;QAC3B,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAjBY,QAAA,yBAAyB,GAAzB,yBAAyB,CAiBrC","sourcesContent":["import pointToPolygonDistance from '@turf/point-to-polygon-distance'\n\nimport { DEFAULT_SRS_INDEX, SRSIndex } from '../../srs'\nimport { AreaOfInterest } from '../areaOfInterest'\nimport { Point } from '../point'\nimport { toLatLong } from './toLatLong'\n\n/**\n * Returns the distance (in meters) between a point and the boundary of a polygon: negative inside, positive outside.\n *\n * @param {!Point} point - The point.\n * @param {!AreaOfInterest} polygon - Polygon or multi polygon in WGS84.\n * @param {!SRSIndex} srsIndex - SRSs indexed by SRS code.\n * @returns {number|null} - The signed distance in meters, or null if the point or the polygon are not valid.\n */\nexport const distanceToPolygonBoundary = (\n point: Point,\n polygon: AreaOfInterest,\n srsIndex: SRSIndex = DEFAULT_SRS_INDEX\n): number | null => {\n const pointLatLong = toLatLong(point, srsIndex)\n if (!pointLatLong) return null\n try {\n // turf expects [longitude, latitude]; planar: polygon edges are straight lines (as in GeoJSON and on the map),\n // consistent with the inside/outside check (geodesic would measure to great-circle edges)\n // shortcut: polygons crossing the antimeridian (longitudes jumping from 180 to -180) are measured wrong,\n // split them in 2 polygons (one for each side) if such areas of interest are needed\n return pointToPolygonDistance([pointLatLong.x, pointLatLong.y], polygon, { units: 'meters', method: 'planar' })\n } catch {\n // invalid polygon geometry\n return null\n }\n}\n"]}
@@ -14,15 +14,14 @@ const node_1 = require("../../node");
14
14
  const nodeDef_1 = require("../../nodeDef");
15
15
  const survey_1 = require("../../survey");
16
16
  const survey_2 = require("../../survey/survey");
17
- const recordExpressionEvaluator_1 = require("../recordExpressionEvaluator");
18
17
  const records_1 = require("../records");
18
+ const recordNodeDependentsBooleanUpdater_1 = require("./recordNodeDependentsBooleanUpdater");
19
19
  const recordNodeDependentsEnumeratedEntitiesUpdater_1 = require("./recordNodeDependentsEnumeratedEntitiesUpdater");
20
20
  const recordNodeDependentsEnumeratingItemsUpdater_1 = require("./recordNodeDependentsEnumeratingItemsUpdater");
21
21
  const recordNodesCreator_1 = require("./recordNodesCreator");
22
22
  const recordNodesDeleter_1 = require("./recordNodesDeleter");
23
23
  const recordNodesDependentsUpdaterCommons_1 = require("./recordNodesDependentsUpdaterCommons");
24
24
  const recordUpdateResult_1 = require("./recordUpdateResult");
25
- const expressionEvaluator = new recordExpressionEvaluator_1.RecordExpressionEvaluator();
26
25
  const extractNodePointersToUpdate = (params) => {
27
26
  const { survey, record, node } = params;
28
27
  const nodePointersToUpdate = (0, recordNodesDependentsUpdaterCommons_1.getDependentNodePointersByType)({
@@ -35,28 +34,7 @@ const extractNodePointersToUpdate = (params) => {
35
34
  });
36
35
  return nodePointersToUpdate;
37
36
  };
38
- const calculateApplicableNext = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, updateResult, nodePointer, nodeCtx, }) {
39
- const { nodeDef: nodeDefNodePointer } = nodePointer;
40
- const { uuid: nodeDefUuid } = nodeDefNodePointer;
41
- const applicablePrev = node_1.Nodes.isChildApplicable(nodeCtx, nodeDefUuid);
42
- const expressionsToEvaluate = nodeDef_1.NodeDefs.getApplicable(nodeDefNodePointer);
43
- if (expressionsToEvaluate.length === 0) {
44
- if (applicablePrev) {
45
- // skip nodes that were already applicable and have no applicable expression, as they will remain applicable
46
- return undefined;
47
- }
48
- else {
49
- // used during survey publishing: node def could have had applicable expression(s) that were removed,
50
- // and node could have been not applicable, but now it should be applicable, as there are no more applicable expressions
51
- return true;
52
- }
53
- }
54
- else {
55
- // 3. evaluate applicable expression
56
- const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, expressions: expressionsToEvaluate }));
57
- return (exprEval === null || exprEval === void 0 ? void 0 : exprEval.value) || false;
58
- }
59
- });
37
+ const calculateApplicableNext = (params) => (0, recordNodeDependentsBooleanUpdater_1.calculateBooleanValueNext)(Object.assign(Object.assign({}, params), { getExpressions: (nodePointer) => nodeDef_1.NodeDefs.getApplicable(nodePointer.nodeDef), getValuePrev: node_1.Nodes.isChildApplicable }));
60
38
  const updateDescendantsApplicability = ({ updateResult, nodeCtxChild, applicable, params, recordUpdateOptions, }) => {
61
39
  const { survey, sideEffect = false, clearNonApplicableValues = false } = params;
62
40
  // only values entered by the user are reported as cleared (they need a confirmation)
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsApplicableUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAgE;AAChE,2CAAuD;AACvD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QAC3C,uDAAuD;QACvD,8BAA8B,CAAC;YAC7B,YAAY;YACZ,YAAY;YACZ,UAAU;YACV,MAAM;YACN,mBAAmB;SACpB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA,CAAA;AAEM,MAAM,iCAAiC,GAAG,CAC/C,MAAwC,EACX,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAE3D,MAAM,YAAY,GAAG,IAAI,uCAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEvD,MAAM,mBAAmB,GAAwB,EAAE,UAAU,EAAE,CAAA;IAE/D,2BAA2B;IAC3B,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAElF,6CAA6C;IAC7C,4EAA4E;IAC5E,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,MAAM,8BAA8B,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAA,CAAC,UAAU;IAC7G,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAlBY,QAAA,iCAAiC,GAAjC,iCAAiC,CAkB7C","sourcesContent":["import { ArenaRecordNode, NodePointer, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records, RecordUpdateOptions } from '../records'\nimport { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { addNodeAndDescendants } from './recordNodesCreator'\nimport { removeNodes } from './recordNodesDeleter'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nconst extractNodePointersToUpdate = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }) => {\n const { survey, record, node } = params\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.applicable,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntityChildPointers: true,\n })\n return nodePointersToUpdate\n}\n\nconst calculateApplicableNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = NodeDefs.getApplicable(nodeDefNodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (applicablePrev) {\n // skip nodes that were already applicable and have no applicable expression, as they will remain applicable\n return undefined\n } else {\n // used during survey publishing: node def could have had applicable expression(s) that were removed,\n // and node could have been not applicable, but now it should be applicable, as there are no more applicable expressions\n return true\n }\n } else {\n // 3. evaluate applicable expression\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n }\n}\n\nconst updateDescendantsApplicability = ({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n}: {\n updateResult: RecordUpdateResult\n nodeCtxChild: ArenaRecordNode\n applicable: boolean\n params: RecordNodeDependentsUpdateParams\n recordUpdateOptions: RecordUpdateOptions\n}): void => {\n const { survey, sideEffect = false, clearNonApplicableValues = false } = params\n\n // only values entered by the user are reported as cleared (they need a confirmation)\n let userValuesCleared = false\n\n Records.visitDescendantsAndSelf(nodeCtxChild, (nodeDescendant): boolean => {\n const nodeDescendantCleared = clearNonApplicableValues && !applicable && Nodes.isValueNotBlank(nodeDescendant)\n // values set by expressions (default values, read only attributes) are applied again when applicable: not reported\n // (evaluated before clearing the value: with sideEffect the node is modified in place)\n const nodeDescendantDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDescendant.nodeDefUuid })\n const userValueCleared =\n nodeDescendantCleared && !NodeDefs.isReadOnly(nodeDescendantDef) && Nodes.hasUserInputValue(nodeDescendant)\n // Clear value if becoming non-applicable and parameter is enabled\n const nodeDescendantUpdated = nodeDescendantCleared\n ? Nodes.assocValue(nodeDescendant, null, { sideEffect })\n : nodeDescendant\n updateResult.addNode(nodeDescendantUpdated, recordUpdateOptions)\n if (userValueCleared) {\n updateResult.addClearedDefUuid(nodeDescendant.nodeDefUuid)\n userValuesCleared = true\n }\n return false\n })(updateResult.record)\n\n // if a multiple entity became not applicable and it's empty, delete it instead of just marking descendants as not applicable\n if (!applicable && clearNonApplicableValues) {\n const { uuid: nodeCtxChildUuid, nodeDefUuid: nodeCtxChildDefUuid } = nodeCtxChild\n const nodeCtxChildDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeCtxChildDefUuid })\n if (NodeDefs.isMultipleEntity(nodeCtxChildDef) && Records.isNodeEmpty(nodeCtxChild)(updateResult.record)) {\n const deleteResult = removeNodes([nodeCtxChildUuid], recordUpdateOptions)(updateResult.record)\n updateResult.merge(deleteResult)\n if (userValuesCleared) {\n updateResult.addClearedDefUuid(nodeCtxChildDefUuid)\n }\n }\n }\n}\n\nconst createMissingApplicableMultipleEntities = async ({\n params,\n updateResult,\n parentNode,\n nodeDef,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n parentNode: ArenaRecordNode\n nodeDef: NodeDefEntity\n}): Promise<void> => {\n if (!NodeDefs.isAutoCreateMinCountItems(nodeDef)) return\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef })\n if (Number.isNaN(minCount) || minCount <= 0) return\n\n const existingChildren = Records.getChildren(parentNode, nodeDef.uuid)(updateResult.record)\n const missingCount = Math.max(0, minCount - existingChildren.length)\n\n for (let index = 0; index < missingCount; index++) {\n const createParams = { ...params, record: updateResult.record, parentNode, nodeDef }\n // create nodes sequentially: every iteration works on the record updated by the previous one\n const childUpdateResult = await addNodeAndDescendants(createParams) // NOSONAR\n updateResult.merge(childUpdateResult)\n }\n}\n\nconst updateNodePointerApplicability = async ({\n params,\n updateResult,\n nodePointer,\n recordUpdateOptions,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n recordUpdateOptions: RecordUpdateOptions\n}): Promise<void> => {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n // nodeCtx could have been updated in a previous iteration\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const applicable = await calculateApplicableNext({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n })\n if (applicable === undefined) {\n return\n }\n\n if (applicable && NodeDefs.isMultipleEntity(nodeDefNodePointer)) {\n await createMissingApplicableMultipleEntities({\n params,\n updateResult,\n parentNode: nodeCtx,\n nodeDef: nodeDefNodePointer as NodeDefEntity,\n })\n }\n\n // 4. persist updated applicability if changed, and return updated nodes\n if (applicablePrev === applicable) {\n return\n }\n // Applicability changed\n\n // update node and add it to nodes updated\n const nodeCtxUpdated = Nodes.assocChildApplicability(nodeCtx, nodeDefUuid, applicable)\n updateResult.addNode(nodeCtxUpdated, recordUpdateOptions)\n\n let nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n\n if (NodeDefs.isMultipleEntity(nodeDefNodePointer) && NodeDefs.isEnumerate(nodeDefNodePointer as NodeDefEntity)) {\n const entityDef = nodeDefNodePointer as NodeDefEntity\n if (NodeDefs.getEnumeratingItemsExpression(entityDef)) {\n await syncEnumeratingItemsEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n } else {\n await createOrDeleteEnumeratedEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n }\n nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n }\n for (const nodeCtxChild of nodeCtxChildren) {\n // add nodeCtxChild and its descendants to nodesUpdated\n updateDescendantsApplicability({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n })\n }\n}\n\nexport const updateSelfAndDependentsApplicable = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions: RecordUpdateOptions = { sideEffect }\n\n // 1. fetch dependent nodes\n const nodePointersToUpdate = extractNodePointersToUpdate({ survey, record, node })\n\n // 2. update expr to node and dependent nodes\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n await updateNodePointerApplicability({ params, updateResult, nodePointer, recordUpdateOptions }) // NOSONAR\n }\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsApplicableUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAgE;AAChE,2CAAuD;AACvD,yCAAsC;AACtC,gDAAkE;AAElE,wCAAyD;AACzD,6FAAgF;AAChF,mHAAkG;AAClG,+GAA4F;AAC5F,6DAA4D;AAC5D,6DAAkD;AAClD,+FAAsF;AAEtF,6DAAyD;AA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, NodePointer, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { ArenaRecord } from '../record'\nimport { Records, RecordUpdateOptions } from '../records'\nimport { calculateBooleanValueNext } from './recordNodeDependentsBooleanUpdater'\nimport { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { addNodeAndDescendants } from './recordNodesCreator'\nimport { removeNodes } from './recordNodesDeleter'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst extractNodePointersToUpdate = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }) => {\n const { survey, record, node } = params\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.applicable,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntityChildPointers: true,\n })\n return nodePointersToUpdate\n}\n\nconst calculateApplicableNext = (params: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n}): Promise<boolean | undefined> =>\n calculateBooleanValueNext({\n ...params,\n getExpressions: (nodePointer) => NodeDefs.getApplicable(nodePointer.nodeDef),\n getValuePrev: Nodes.isChildApplicable,\n })\n\nconst updateDescendantsApplicability = ({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n}: {\n updateResult: RecordUpdateResult\n nodeCtxChild: ArenaRecordNode\n applicable: boolean\n params: RecordNodeDependentsUpdateParams\n recordUpdateOptions: RecordUpdateOptions\n}): void => {\n const { survey, sideEffect = false, clearNonApplicableValues = false } = params\n\n // only values entered by the user are reported as cleared (they need a confirmation)\n let userValuesCleared = false\n\n Records.visitDescendantsAndSelf(nodeCtxChild, (nodeDescendant): boolean => {\n const nodeDescendantCleared = clearNonApplicableValues && !applicable && Nodes.isValueNotBlank(nodeDescendant)\n // values set by expressions (default values, read only attributes) are applied again when applicable: not reported\n // (evaluated before clearing the value: with sideEffect the node is modified in place)\n const nodeDescendantDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDescendant.nodeDefUuid })\n const userValueCleared =\n nodeDescendantCleared && !NodeDefs.isReadOnly(nodeDescendantDef) && Nodes.hasUserInputValue(nodeDescendant)\n // Clear value if becoming non-applicable and parameter is enabled\n const nodeDescendantUpdated = nodeDescendantCleared\n ? Nodes.assocValue(nodeDescendant, null, { sideEffect })\n : nodeDescendant\n updateResult.addNode(nodeDescendantUpdated, recordUpdateOptions)\n if (userValueCleared) {\n updateResult.addClearedDefUuid(nodeDescendant.nodeDefUuid)\n userValuesCleared = true\n }\n return false\n })(updateResult.record)\n\n // if a multiple entity became not applicable and it's empty, delete it instead of just marking descendants as not applicable\n if (!applicable && clearNonApplicableValues) {\n const { uuid: nodeCtxChildUuid, nodeDefUuid: nodeCtxChildDefUuid } = nodeCtxChild\n const nodeCtxChildDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeCtxChildDefUuid })\n if (NodeDefs.isMultipleEntity(nodeCtxChildDef) && Records.isNodeEmpty(nodeCtxChild)(updateResult.record)) {\n const deleteResult = removeNodes([nodeCtxChildUuid], recordUpdateOptions)(updateResult.record)\n updateResult.merge(deleteResult)\n if (userValuesCleared) {\n updateResult.addClearedDefUuid(nodeCtxChildDefUuid)\n }\n }\n }\n}\n\nconst createMissingApplicableMultipleEntities = async ({\n params,\n updateResult,\n parentNode,\n nodeDef,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n parentNode: ArenaRecordNode\n nodeDef: NodeDefEntity\n}): Promise<void> => {\n if (!NodeDefs.isAutoCreateMinCountItems(nodeDef)) return\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef })\n if (Number.isNaN(minCount) || minCount <= 0) return\n\n const existingChildren = Records.getChildren(parentNode, nodeDef.uuid)(updateResult.record)\n const missingCount = Math.max(0, minCount - existingChildren.length)\n\n for (let index = 0; index < missingCount; index++) {\n const createParams = { ...params, record: updateResult.record, parentNode, nodeDef }\n // create nodes sequentially: every iteration works on the record updated by the previous one\n const childUpdateResult = await addNodeAndDescendants(createParams) // NOSONAR\n updateResult.merge(childUpdateResult)\n }\n}\n\nconst updateNodePointerApplicability = async ({\n params,\n updateResult,\n nodePointer,\n recordUpdateOptions,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n recordUpdateOptions: RecordUpdateOptions\n}): Promise<void> => {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n // nodeCtx could have been updated in a previous iteration\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const applicable = await calculateApplicableNext({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n })\n if (applicable === undefined) {\n return\n }\n\n if (applicable && NodeDefs.isMultipleEntity(nodeDefNodePointer)) {\n await createMissingApplicableMultipleEntities({\n params,\n updateResult,\n parentNode: nodeCtx,\n nodeDef: nodeDefNodePointer as NodeDefEntity,\n })\n }\n\n // 4. persist updated applicability if changed, and return updated nodes\n if (applicablePrev === applicable) {\n return\n }\n // Applicability changed\n\n // update node and add it to nodes updated\n const nodeCtxUpdated = Nodes.assocChildApplicability(nodeCtx, nodeDefUuid, applicable)\n updateResult.addNode(nodeCtxUpdated, recordUpdateOptions)\n\n let nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n\n if (NodeDefs.isMultipleEntity(nodeDefNodePointer) && NodeDefs.isEnumerate(nodeDefNodePointer as NodeDefEntity)) {\n const entityDef = nodeDefNodePointer as NodeDefEntity\n if (NodeDefs.getEnumeratingItemsExpression(entityDef)) {\n await syncEnumeratingItemsEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n } else {\n await createOrDeleteEnumeratedEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n }\n nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n }\n for (const nodeCtxChild of nodeCtxChildren) {\n // add nodeCtxChild and its descendants to nodesUpdated\n updateDescendantsApplicability({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n })\n }\n}\n\nexport const updateSelfAndDependentsApplicable = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions: RecordUpdateOptions = { sideEffect }\n\n // 1. fetch dependent nodes\n const nodePointersToUpdate = extractNodePointersToUpdate({ survey, record, node })\n\n // 2. update expr to node and dependent nodes\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n await updateNodePointerApplicability({ params, updateResult, nodePointer, recordUpdateOptions }) // NOSONAR\n }\n return updateResult\n}\n"]}
@@ -12,5 +12,13 @@ type UpdateSelfAndDependentsBooleanParams = {
12
12
  assocValue: (nodeCtx: ArenaRecordNode, nodeDefUuid: string, value: boolean, options: MutationOptions) => ArenaRecordNode;
13
13
  includeNewEntitySelf?: boolean;
14
14
  };
15
+ export declare const calculateBooleanValueNext: ({ params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev, }: {
16
+ params: RecordNodeDependentsUpdateParams;
17
+ updateResult: RecordUpdateResult;
18
+ nodePointer: NodePointer;
19
+ nodeCtx: ArenaRecordNode;
20
+ getExpressions: (nodePointer: NodePointer) => NodeDefExpression[];
21
+ getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean;
22
+ }) => Promise<boolean | undefined>;
15
23
  export declare const updateSelfAndDependentsBoolean: ({ params, dependencyType, getExpressions, getValuePrev, assocValue, includeNewEntitySelf, }: UpdateSelfAndDependentsBooleanParams) => Promise<RecordUpdateResult>;
16
24
  export {};
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.updateSelfAndDependentsBoolean = void 0;
12
+ exports.updateSelfAndDependentsBoolean = exports.calculateBooleanValueNext = void 0;
13
13
  const recordExpressionEvaluator_1 = require("../recordExpressionEvaluator");
14
14
  const recordNodesDependentsUpdaterCommons_1 = require("./recordNodesDependentsUpdaterCommons");
15
15
  const recordUpdateResult_1 = require("./recordUpdateResult");
@@ -21,13 +21,17 @@ const calculateBooleanValueNext = (_a) => __awaiter(void 0, [_a], void 0, functi
21
21
  const expressionsToEvaluate = getExpressions(nodePointer);
22
22
  if (expressionsToEvaluate.length === 0) {
23
23
  if (valuePrev) {
24
+ // skip nodes already having the value true and no expressions, as they will keep it
24
25
  return undefined;
25
26
  }
27
+ // used during survey publishing: node def could have had expression(s) that were removed,
28
+ // and the value could have been false, but now it should be true, as there are no more expressions
26
29
  return true;
27
30
  }
28
31
  const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, expressions: expressionsToEvaluate }));
29
32
  return (exprEval === null || exprEval === void 0 ? void 0 : exprEval.value) || false;
30
33
  });
34
+ exports.calculateBooleanValueNext = calculateBooleanValueNext;
31
35
  const updateSelfAndDependentsBoolean = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, dependencyType, getExpressions, getValuePrev, assocValue, includeNewEntitySelf = true, }) {
32
36
  var _b;
33
37
  const { survey, record, node, sideEffect = false } = params;
@@ -49,7 +53,7 @@ const updateSelfAndDependentsBoolean = (_a) => __awaiter(void 0, [_a], void 0, f
49
53
  const nodeCtx = (_b = updateResult.getNodeByUuid(nodeCtxUuid)) !== null && _b !== void 0 ? _b : nodeCtxNodePointer;
50
54
  const valuePrev = getValuePrev(nodeCtx, nodeDefUuid);
51
55
  const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev };
52
- const value = yield calculateBooleanValueNext(calculateParams); // NOSONAR
56
+ const value = yield (0, exports.calculateBooleanValueNext)(calculateParams); // NOSONAR
53
57
  if (value === undefined || valuePrev === value) {
54
58
  continue;
55
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsBooleanUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,4EAAwE;AACxE,+FAAsF;AAEtF,6DAAyD;AAEzD,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAgB3D,MAAM,yBAAyB,GAAG,KAcD,EAAE,4CAdM,EACvC,MAAM,EACN,YAAY,EACZ,WAAW,EACX,OAAO,EACP,cAAc,EACd,YAAY,GAQb;IACC,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,WAAW,CAAA;IACnD,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,kBAAkB,CAAA;IAEhD,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IACpD,MAAM,qBAAqB,GAAG,cAAc,CAAC,WAAW,CAAC,CAAA;IACzD,IAAI,qBAAqB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,wBAAwB,iCAC9D,MAAM,KACT,MAAM,EAAE,YAAY,CAAC,MAA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,UAAU;QAEzE,IAAI,KAAK,KAAK,SAAS,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YAC/C,SAAQ;QACV,CAAC;QAED,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QAC9E,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IACtD,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AA3CY,QAAA,8BAA8B,GAA9B,8BAA8B,CA2C1C","sourcesContent":["import { ArenaRecordNode, NodePointer } from '../../node'\nimport { NodeDefExpression } from '../../nodeDef'\nimport { MutationOptions } from '../../utils/mutationOptions'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\ntype UpdateSelfAndDependentsBooleanParams = {\n params: RecordNodeDependentsUpdateParams\n dependencyType: SurveyDependencyType\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n assocValue: (\n nodeCtx: ArenaRecordNode,\n nodeDefUuid: string,\n value: boolean,\n options: MutationOptions\n ) => ArenaRecordNode\n includeNewEntitySelf?: boolean\n}\n\nconst calculateBooleanValueNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n getExpressions,\n getValuePrev,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = getExpressions(nodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (valuePrev) {\n return undefined\n }\n return true\n }\n\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n}\n\nexport const updateSelfAndDependentsBoolean = async ({\n params,\n dependencyType,\n getExpressions,\n getValuePrev,\n assocValue,\n includeNewEntitySelf = true,\n}: UpdateSelfAndDependentsBooleanParams): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n const updateResult = new RecordUpdateResult({ record })\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntitySelf,\n includeNewEntityChildPointers: true,\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev }\n const value = await calculateBooleanValueNext(calculateParams) // NOSONAR\n\n if (value === undefined || valuePrev === value) {\n continue\n }\n\n const nodeCtxUpdated = assocValue(nodeCtx, nodeDefUuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsBooleanUpdater.js","sourceRoot":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CAAA;AA3CY,QAAA,8BAA8B,GAA9B,8BAA8B,CA2C1C","sourcesContent":["import { ArenaRecordNode, NodePointer } from '../../node'\nimport { NodeDefExpression } from '../../nodeDef'\nimport { MutationOptions } from '../../utils/mutationOptions'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\ntype UpdateSelfAndDependentsBooleanParams = {\n params: RecordNodeDependentsUpdateParams\n dependencyType: SurveyDependencyType\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n assocValue: (\n nodeCtx: ArenaRecordNode,\n nodeDefUuid: string,\n value: boolean,\n options: MutationOptions\n ) => ArenaRecordNode\n includeNewEntitySelf?: boolean\n}\n\nexport const calculateBooleanValueNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n getExpressions,\n getValuePrev,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = getExpressions(nodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (valuePrev) {\n // skip nodes already having the value true and no expressions, as they will keep it\n return undefined\n }\n // used during survey publishing: node def could have had expression(s) that were removed,\n // and the value could have been false, but now it should be true, as there are no more expressions\n return true\n }\n\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n}\n\nexport const updateSelfAndDependentsBoolean = async ({\n params,\n dependencyType,\n getExpressions,\n getValuePrev,\n assocValue,\n includeNewEntitySelf = true,\n}: UpdateSelfAndDependentsBooleanParams): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n const updateResult = new RecordUpdateResult({ record })\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntitySelf,\n includeNewEntityChildPointers: true,\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev }\n const value = await calculateBooleanValueNext(calculateParams) // NOSONAR\n\n if (value === undefined || valuePrev === value) {\n continue\n }\n\n const nodeCtxUpdated = assocValue(nodeCtx, nodeDefUuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n\n return updateResult\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": "2.16.13",
7
+ "version": "2.17.0",
8
8
  "description": "Arena core module",
9
9
  "repository": {
10
10
  "type": "git",