@flumens/models 0.19.0 → 0.20.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.
@@ -8,8 +8,6 @@ interface IObservableArray<T = any> extends Array<T> {
8
8
  remove(value: T): boolean;
9
9
  toJSON(): T[];
10
10
  }
11
- type CID = string | number;
12
- type ID = string | number;
13
11
  export type Options<T extends ModelClass> = {
14
12
  data?: T[];
15
13
  id?: string;
@@ -30,8 +28,8 @@ export default class Collection<T extends ModelClass> {
30
28
  * Mobx observable array of model items.
31
29
  */
32
30
  data: IObservableArray<T>;
33
- cidMap: Map<CID, T>;
34
- idMap: Map<ID, T>;
31
+ cidMap: Map<string, T>;
32
+ idMap: Map<string, T>;
35
33
  /**
36
34
  * The offline store used to save and fetch the model from.
37
35
  */
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("mobx"),i=require("@flumens/utils"),r=require("./Model.js");class d{constructor({id:t,cid:d,data:s=[],store:a,Model:o=r.default}){this.ready=new i.Deferred,this.data=e.observable.array(s),this.id=this.id||t,this.cid=this.cid||d||t||i.UUIDv7(),this.Model=o,this.store=this.store||a,this.cidMap=new Map,this.idMap=new Map;e.intercept(this.data,(t=>{if(t.added&&t.added.length){const e=t=>{this.cidMap.set(t.cid,t),this.idMap.set(t.id,t)};t.added.forEach(e)}if(t.removedCount>0){let e=Array.from(this.cidMap.keys())[t.index];this.cidMap.delete(e),e=Array.from(this.idMap.keys())[t.index],this.idMap.delete(e)}return t}))}fetch(){return t.__awaiter(this,void 0,void 0,(function*(){if(!this.store||!this.Model)return void this.ready.resolve(!1);const t=(yield this.store.findAll()).map((t=>new this.Model(t)));this.data.push(...t),this.ready.resolve(!0)}))}reset(){return t.__awaiter(this,void 0,void 0,(function*(){for(;this.data.length;){const t=this.data.pop();yield null==t?void 0:t.destroy()}}))}filter(t){return this.data.filter(t)}push(...t){return this.data.push(...t)}pop(){return this.data.pop()}find(t){return this.data.find(t)}map(t){return this.data.map(t)}remove(t){return this.data.remove(t)}[Symbol.iterator](){return this.data[Symbol.iterator]()}get length(){return this.data.length}}exports.default=d;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("mobx"),i=require("@flumens/utils"),r=require("./Model.js");class s{constructor({id:t,cid:s,data:d=[],store:a,Model:o=r.default}){this.ready=new i.Deferred,this.data=e.observable.array(d),this.id=this.id||t,this.cid=this.cid||s||t||i.UUIDv7(),this.Model=o,this.store=this.store||a,this.cidMap=e.observable.map(),this.idMap=e.observable.map();e.intercept(this.data,(t=>{if("update"===t.type)return t;const{added:e,index:i,removedCount:r,object:s}=t;if(t.removedCount>0){s.slice(i,i+r).forEach((t=>{this.cidMap.delete(t.cid),t.id&&this.idMap.delete(t.id)}))}return e.forEach((t=>{this.cidMap.set(t.cid,t),this.idMap.set(t.id,t)})),t}))}fetch(){return t.__awaiter(this,void 0,void 0,(function*(){if(!this.store||!this.Model)return void this.ready.resolve(!1);const t=(yield this.store.findAll()).map((t=>new this.Model(t)));this.data.push(...t),this.ready.resolve(!0)}))}reset(){return t.__awaiter(this,void 0,void 0,(function*(){for(;this.data.length;){const t=this.data.pop();yield null==t?void 0:t.destroy()}}))}filter(t){return this.data.filter(t)}push(...t){return this.data.push(...t)}pop(){return this.data.pop()}find(t){return this.data.find(t)}map(t){return this.data.map(t)}remove(t){return this.data.remove(t)}[Symbol.iterator](){return this.data[Symbol.iterator]()}get length(){return this.data.length}}exports.default=s;
@@ -37,6 +37,14 @@ export interface Data extends DataOriginal {
37
37
  date?: any;
38
38
  sampleMethodId?: number;
39
39
  enteredSrefSystem: 'OSGB' | 'OSIE' | 'utm30ed50' | 4326;
40
+ /**
41
+ * Site the sample was linked to.
42
+ */
43
+ locationId?: string;
44
+ /**
45
+ * Group/project the sample was linked to.
46
+ */
47
+ groupId?: string;
40
48
  /**
41
49
  * Allows record precision to be blurred for public viewing for privacy
42
50
  * (as opposed to sensitivity) reasons. An example might be to obscure
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flumens/models",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {