@flumens/models 0.17.3 → 0.18.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.
package/dist/Indicia/Group.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("mobx"),o=require("axios"),i=require("zod"),r=require("@flumens/utils
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("mobx"),o=require("axios"),i=require("zod"),r=require("@flumens/utils"),n=require("@flumens/utils/dist/errors"),s=require("@flumens/utils/dist/uuid"),a=require("../Model.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=l(o);const d=i.object({id:i.z.string(),title:i.z.string(),createdOn:i.z.string(),description:i.z.string().nullable().optional(),groupType:i.z.string().nullable().optional(),joiningMethod:i.z.enum(["P","R","A","I"]).nullable().optional(),websiteId:i.z.string().nullable().optional(),groupTypeId:i.z.string().nullable().optional(),createdById:i.z.string().nullable().optional(),fromDate:i.z.string().nullable().optional(),toDate:i.z.string().nullable().optional(),indexedLocationIds:i.z.array(i.z.number()).nullable().optional(),userIsAdministrator:i.z.enum(["t","f"]).nullable().optional(),userIsMember:i.z.enum(["t","f"]).nullable().optional(),userIsPending:i.z.enum(["t","f"]).nullable().optional()}),c=i.object({id:i.z.string().nullable().optional(),createdOn:i.z.string().nullable().optional(),createdById:i.z.string().nullable().optional(),groupId:i.z.string().nullable().optional(),groupTitle:i.z.string().nullable().optional(),locationId:i.z.string(),locationName:i.z.string(),locationBoundaryGeom:i.z.string(),locationLat:i.z.string(),locationLon:i.z.string(),locationCreatedOn:i.z.string(),locationUpdatedOn:i.z.string(),locationCentroidSref:i.z.string(),locationCentroidSrefSystem:i.z.string(),locationCode:i.z.string().nullable().optional(),locationCreatedById:i.z.string().nullable().optional(),locationUpdatedById:i.z.string().nullable().optional(),locationComment:i.z.string().nullable().optional(),locationExternalKey:i.z.string().nullable().optional()});class g extends a.default{static fromDTO(t,o={}){d.parse(t);const{id:i,createdOn:r}=t,n=e.__rest(t,["id","createdOn"]);return new this(Object.assign({id:i,cid:s.UUIDv7(),data:n,createdAt:new Date(r).getTime()},o))}constructor(o){var{skipStore:i,store:r,url:n,getAccessToken:s,getIndiciaUserId:a}=o,l=e.__rest(o,["skipStore","store","url","getAccessToken","getIndiciaUserId"]);super(Object.assign(Object.assign({},l),{store:i?void 0:r})),this.remote=t.observable({synchronising:!1,url:n,getAccessToken:s,getIndiciaUserId:a})}join(){return e.__awaiter(this,void 0,void 0,(function*(){const e=`${this.remote.url}/index.php/services/rest/groups/${this.id}/users`,t=yield this.remote.getAccessToken(),o={values:{id:yield this.remote.getIndiciaUserId()}},i={headers:{Authorization:`Bearer ${t}`},timeout:8e4};try{yield u.default.post(e,o,i)}catch(e){if(u.default.isCancel(e))return;if(n.isAxiosNetworkError(e))throw new n.HandledError("Request aborted because of a network issue (timeout or similar).");throw e}}))}leave(){return e.__awaiter(this,void 0,void 0,(function*(){var e,t,o;const i=yield this.remote.getIndiciaUserId(),r=`${this.remote.url}/index.php/services/rest/groups/${this.id}/users/${i}`,s={headers:{Authorization:`Bearer ${yield this.remote.getAccessToken()}`},timeout:8e4};try{yield u.default.delete(r,s)}catch(i){if(u.default.isCancel(i))return;if(n.isAxiosNetworkError(i))throw new n.HandledError("Request aborted because of a network issue (timeout or similar).");if(null===(o=null===(t=null===(e=i.response)||void 0===e?void 0:e.data)||void 0===t?void 0:t.message)||void 0===o?void 0:o.includes("User is not a member of the group"))return;throw i}}))}addRemoteLocation(t){return e.__awaiter(this,void 0,void 0,(function*(){var e,o,i;console.log("Group location uploading");const r={values:{id:t}},n=`${this.remote.url}/index.php/services/rest/groups/${this.id}/locations`;try{this.remote.synchronising=!0;const e={url:n,method:"post",headers:{Authorization:`Bearer ${yield this.remote.getAccessToken()}`},timeout:8e4,data:r};return yield u.default(e),this.remote.synchronising=!1,console.log("Group location uploading done"),this}catch(t){this.remote.synchronising=!1;const r=t;if(409===(null===(e=r.response)||void 0===e?void 0:e.status))return console.log("Location uploading duplicate was found"),this;const n=null===(i=null===(o=r.response)||void 0===o?void 0:o.data)||void 0===i?void 0:i.message;if(!n)throw t;if("object"==typeof n){const e=e=>Object.entries(e).reduce(((e,t)=>`${e}${t[0]} ${t[1]}\n`),"");throw new Error(e(n))}throw new Error(n)}}))}fetchRemoteLocations(){return e.__awaiter(this,void 0,void 0,(function*(){const e=`${this.remote.url}/index.php/services/rest/groups/${this.id}/locations`,t={headers:{Authorization:`Bearer ${yield this.remote.getAccessToken()}`},timeout:8e4};try{const o=yield u.default.get(e,t),i=({values:e})=>r.getCamelCaseObj(e),n=o.data.map(i);return n.forEach((e=>c.parse(e))),n}catch(e){if(u.default.isCancel(e))return[];if(n.isAxiosNetworkError(e))throw new n.HandledError("Request aborted because of a network issue (timeout or similar).");if("issues"in e){throw new Error(e.issues.map((e=>`${e.path.join(" ")} ${e.message}`)).join(" "))}throw e}}))}}exports.default=g,exports.dtoSchema=d;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("mobx"),s=require("axios"),i=require("@flumens/utils
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("mobx"),s=require("axios"),i=require("@flumens/utils"),r=require("@flumens/utils/dist/errors"),o=require("../Collection.js"),a=require("./Group.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=n(s);class d extends o.default{constructor(e){super(Object.assign({id:"groups",Model:a.default},e)),this.remote=t.observable({synchronising:!1,url:e.url,getAccessToken:e.getAccessToken})}fetchRemote(){return e.__awaiter(this,arguments,void 0,(function*(e={}){console.log(`📚 Collection: ${this.id} collection fetching`),this.remote.synchronising=!0;try{const{type:t,form:s,location:r}=e,o=yield this.remote.getAccessToken(),a=`${this.remote.url}/index.php/services/rest/groups`,n={};t&&(n.view=t),s&&(n.page=s.join(",")),Number.isFinite(r)&&(n.indexed_location_ids=r);const d={params:n,headers:{Authorization:`Bearer ${o}`},timeout:8e4},u=yield l.default.get(a,d),c=e=>!e.toDate||new Date(e.toDate)>new Date,h=e=>!e.fromDate||new Date(e.fromDate)<new Date,m=u.data.map((({values:e})=>e)).map(i.getCamelCaseObj).filter(c).filter(h),f=m.map((e=>this.Model.fromDTO(e,{skipStore:"joinable"===t})));if(t){if("member"===t)for(let e=0;e<this.data.length;e++){const t=this.data[e];t.isStored&&"t"===t.data.userIsMember&&(yield t.destroy(),this.data.splice(e,1),e--)}else if("pending"===t)for(let e=0;e<this.data.length;e++){const t=this.data[e];t.isStored&&"t"===t.data.userIsPending&&(yield t.destroy(),this.data.splice(e,1),e--)}else if("joinable"===t)for(let e=0;e<this.data.length;e++){this.data[e].isStored||(this.data.splice(e,1),e--)}}else for(let e=0;e<this.data.length;e++){const t=this.data[e];t.isStored&&(yield t.destroy()),this.data.splice(e,1),e--}"member"===t&&(yield Promise.all(f.map((e=>e.save())))),"pending"===t&&(yield Promise.all(f.map((e=>e.save())))),this.data.push(...f),console.log(`📚 Collection: ${this.id} collection fetching done ${m.length} documents`)}catch(e){if(l.default.isCancel(e))return;if(r.isAxiosNetworkError(e))throw new r.HandledError("Request aborted because of a network issue (timeout or similar).");if("issues"in e){throw new Error(e.issues.map((e=>`${e.path.join(" ")} ${e.message}`)).join(" "))}throw this.remote.synchronising=!1,e}this.remote.synchronising=!1}))}get isSynchronising(){return this.remote.synchronising}}exports.byGroupMembershipStatus=function(e){return t=>{const s=t.data.userIsMember||t.data.userIsPending;return"member"===e?s:!s}},exports.default=d;
|
|
@@ -23,7 +23,16 @@ interface RemoteAttr {
|
|
|
23
23
|
id: string;
|
|
24
24
|
}
|
|
25
25
|
type AttrConfig = any;
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* A generic ElasticSearch response type.
|
|
28
|
+
*/
|
|
29
|
+
export type ElasticSearchResponse<T> = {
|
|
30
|
+
hits: {
|
|
31
|
+
hits: {
|
|
32
|
+
_source: T;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
27
36
|
export declare const parseRemoteAttrs: (config: {
|
|
28
37
|
[key: string]: AttrConfig;
|
|
29
38
|
}, remoteAttrs: RemoteAttr[]) => any;
|
package/dist/Indicia/helpers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.getErrorMessageFromObject=e=>Object.entries(e).reduce(((e,t)=>`${e}${t[0]} ${t[1]}\n`),""),exports.parseRemoteAttrs=(e,t)=>{e=e||{};const s=Object.entries(e);return t.reduce(((e,t)=>{const r=s.find((([,e])=>{var s;return(null===(s=e.remote)||void 0===s?void 0:s.id)===parseInt(t.id,10)}));if(!r)return e;const[i]=r,n=isNaN(t.value)?t.value:parseFloat(t.value);return e[i]=n,e}),{})},exports.validateRemoteModel=function(){const e=this.getSurvey(),t=e.verify&&e.verify(this.data,this);let s={};if(t){const e=t&&"issues"in t;!("ValidationError"===(null==t?void 0:t.name)||"ValidationError"===(null==t?void 0:t.type))&&!e?s.errors=[t.message]:e?s.errors=t.issues.map((({message:e})=>e)):s=Object.assign({},t)}const r=(e,t)=>{const s=t.validateRemote();return s&&(e[t.cid]=s,e[t.cid].model=t),e},i=(this.samples||[]).reduce(r,{}),n=(this.occurrences||[]).reduce(r,{}),o=(this.media||[]).reduce(r,{});if(Object.keys(s).length||Object.keys(i).length||Object.keys(n).length||Object.keys(o).length){return{attributes:s,model:this,models:Object.assign(Object.assign(Object.assign({},i),n),o)}}return null};
|