@blibliki/models 0.5.2 → 0.9.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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FirebaseApp } from 'firebase/app';
2
2
  import { Firestore } from 'firebase/firestore';
3
- import { IAnyModuleSerialize, IEngineSerialize } from '@blibliki/engine';
3
+ import { BPM, IAnyModuleSerialize, IEngineSerialize } from '@blibliki/engine';
4
4
  import { AnyObject, Optional } from '@blibliki/utils';
5
5
 
6
6
  type FirebaseConfig = {
@@ -54,6 +54,7 @@ type IGridNodes = {
54
54
  viewport: Viewport;
55
55
  };
56
56
  type IConfig = {
57
+ bpm: BPM;
57
58
  modules: IAnyModuleSerialize[];
58
59
  gridNodes: IGridNodes;
59
60
  };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{initializeApp as w}from"firebase/app";import{getFirestore as D}from"firebase/firestore";var m,d,g,P=o=>{m=o,d=w(m),g=D(d)},x=()=>{if(!d)throw Error("You have to initialize db first");return d},s=()=>{if(!g)throw Error("You have to initialize db first");return g};import{pick as S}from"@blibliki/utils";import{collection as l,addDoc as z,getDoc as F,doc as f,updateDoc as C,getDocs as R,deleteDoc as q}from"firebase/firestore";var c=class o{id;name;userId;config;static async find(e){let i=s(),r=f(i,"patches",e),t=await F(r);if(t.exists()){let n={id:t.id,...t.data()};return new o(n)}else throw Error(`Patch ${e} not found`)}static async all(){let e=s();return(await R(l(e,"patches"))).docs.map(r=>new o({id:r.id,...r.data()}))}constructor(e){Object.assign(this,S(e,["id","name","userId","config"]))}async save(){let e=s();if(this.id)await C(this.docRef,this.props);else{let i=await z(l(e,"patches"),this.props);this.id=i.id}}async delete(){if(!this.id)throw Error("Cannot delete a patch without id");await q(this.docRef)}serialize(){return{id:this.id,...this.props}}engineSerialize(){let{modules:e,gridNodes:i}=this.props.config,r=i.edges.map(t=>({id:t.id,source:{moduleId:t.source,ioName:t.sourceHandle},destination:{moduleId:t.target,ioName:t.targetHandle}}));return{bpm:120,timeSignature:[4,4],modules:e,routes:r}}get docRef(){let e=s();return f(e,"patches",this.id)}get props(){return{name:this.name,userId:this.userId,config:this.config}}};import{pick as O}from"@blibliki/utils";import{collection as p,addDoc as A,getDoc as E,doc as I,updateDoc as k,getDocs as h,deleteDoc as N,query as b,where as y}from"firebase/firestore";var u=class o{id;token;name;patchId;userId;static async find(e){let i=s(),r=I(i,"devices",e),t=await E(r);if(t.exists()){let n={id:t.id,...t.data()};return new o(n)}else throw Error(`Device ${e} not found`)}static async findByUserId(e){let i=s(),r=b(p(i,"devices"),y("userId","==",e));return(await h(r)).docs.map(n=>new o({id:n.id,...n.data()}))}static async findBy(e){let i=s(),r=Object.entries(e).map(([a,v])=>y(a,"==",v)),t=b(p(i,"devices"),...r);return(await h(t)).docs.map(a=>new o({id:a.id,...a.data()}))}static async all(){let e=s();return(await h(p(e,"devices"))).docs.map(r=>new o({id:r.id,...r.data()}))}constructor(e){Object.assign(this,O(e,["id","token","name","patchId","userId"]))}async save(){let e=s();if(this.id)await k(this.docRef,this.props);else{let i=await A(p(e,"devices"),this.props);this.id=i.id}}async delete(){if(!this.id)throw Error("Cannot delete a device without id");await N(this.docRef)}serialize(){return{id:this.id,...this.props}}get docRef(){let e=s();return I(e,"devices",this.id)}get props(){return{token:this.token,name:this.name,patchId:this.patchId,userId:this.userId}}};export{u as Device,c as Patch,x as getApp,s as getDb,P as initializeFirebase};
1
+ import{initializeApp as w}from"firebase/app";import{getFirestore as D}from"firebase/firestore";var m,d,g,P=n=>{m=n,d=w(m),g=D(d)},x=()=>{if(!d)throw Error("You have to initialize db first");return d},s=()=>{if(!g)throw Error("You have to initialize db first");return g};import{pick as S}from"@blibliki/utils";import{collection as l,addDoc as z,getDoc as F,doc as f,updateDoc as C,getDocs as R,deleteDoc as q}from"firebase/firestore";var c=class n{id;name;userId;config;static async find(e){let t=s(),i=f(t,"patches",e),o=await F(i);if(o.exists()){let r={id:o.id,...o.data()};return new n(r)}else throw Error(`Patch ${e} not found`)}static async all(){let e=s();return(await R(l(e,"patches"))).docs.map(i=>new n({id:i.id,...i.data()}))}constructor(e){Object.assign(this,S(e,["id","name","userId","config"]))}async save(){let e=s();if(this.id)await C(this.docRef,this.props);else{let t=await z(l(e,"patches"),this.props);this.id=t.id}}async delete(){if(!this.id)throw Error("Cannot delete a patch without id");await q(this.docRef)}serialize(){return{id:this.id,...this.props}}engineSerialize(){let{bpm:e,modules:t,gridNodes:i}=this.props.config,o=i.edges.map(r=>({id:r.id,source:{moduleId:r.source,ioName:r.sourceHandle},destination:{moduleId:r.target,ioName:r.targetHandle}}));return{bpm:e,timeSignature:[4,4],modules:t,routes:o}}get docRef(){let e=s();return f(e,"patches",this.id)}get props(){return{name:this.name,userId:this.userId,config:this.config}}};import{pick as O}from"@blibliki/utils";import{collection as p,addDoc as A,getDoc as E,doc as I,updateDoc as k,getDocs as h,deleteDoc as N,query as b,where as y}from"firebase/firestore";var u=class n{id;token;name;patchId;userId;static async find(e){let t=s(),i=I(t,"devices",e),o=await E(i);if(o.exists()){let r={id:o.id,...o.data()};return new n(r)}else throw Error(`Device ${e} not found`)}static async findByUserId(e){let t=s(),i=b(p(t,"devices"),y("userId","==",e));return(await h(i)).docs.map(r=>new n({id:r.id,...r.data()}))}static async findBy(e){let t=s(),i=Object.entries(e).map(([a,v])=>y(a,"==",v)),o=b(p(t,"devices"),...i);return(await h(o)).docs.map(a=>new n({id:a.id,...a.data()}))}static async all(){let e=s();return(await h(p(e,"devices"))).docs.map(i=>new n({id:i.id,...i.data()}))}constructor(e){Object.assign(this,O(e,["id","token","name","patchId","userId"]))}async save(){let e=s();if(this.id)await k(this.docRef,this.props);else{let t=await A(p(e,"devices"),this.props);this.id=t.id}}async delete(){if(!this.id)throw Error("Cannot delete a device without id");await N(this.docRef)}serialize(){return{id:this.id,...this.props}}get docRef(){let e=s();return I(e,"devices",this.id)}get props(){return{token:this.token,name:this.name,patchId:this.patchId,userId:this.userId}}};export{u as Device,c as Patch,x as getApp,s as getDb,P as initializeFirebase};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/db.ts","../src/Patch.ts","../src/Device.ts"],"sourcesContent":["import { type FirebaseApp, initializeApp } from \"firebase/app\";\nimport { type Firestore, getFirestore } from \"firebase/firestore\";\n\nexport type FirebaseConfig = {\n apiKey: string;\n authDomain: string;\n projectId: string;\n storageBucket: string;\n messagingSenderId: string;\n appId: string;\n};\n\nlet firebaseConfig: FirebaseConfig | undefined;\nlet app: FirebaseApp | undefined;\nlet db: Firestore | undefined;\n\nexport const initializeFirebase = (config: FirebaseConfig) => {\n firebaseConfig = config;\n app = initializeApp(firebaseConfig);\n db = getFirestore(app);\n};\n\nexport const getApp = (): FirebaseApp => {\n if (!app) throw Error(\"You have to initialize db first\");\n\n return app;\n};\n\nexport const getDb = (): Firestore => {\n if (!db) throw Error(\"You have to initialize db first\");\n\n return db;\n};\n","import {\n IAnyModuleSerialize,\n IEngineSerialize,\n IRoute,\n} from \"@blibliki/engine\";\nimport { AnyObject, Optional, pick } from \"@blibliki/utils\";\nimport {\n collection,\n addDoc,\n getDoc,\n doc,\n updateDoc,\n getDocs,\n deleteDoc,\n} from \"firebase/firestore\";\nimport { getDb } from \"./db\";\n\nexport type IPatch = {\n id: string;\n name: string;\n userId: string;\n config: IConfig;\n};\n\ntype Viewport = {\n x: number;\n y: number;\n zoom: number;\n};\n\ntype Node = {\n data: AnyObject;\n dragging?: boolean;\n id: string;\n measured?: {\n height?: number;\n width?: number;\n };\n position: {\n x: number;\n y: number;\n };\n selected?: boolean;\n type?: string;\n};\n\ntype Edge = {\n id: string;\n source: string;\n sourceHandle?: string | null;\n target: string;\n targetHandle?: string | null;\n};\n\ntype IGridNodes = {\n nodes: Node[];\n edges: Edge[];\n viewport: Viewport;\n};\n\nexport type IConfig = {\n modules: IAnyModuleSerialize[];\n gridNodes: IGridNodes;\n};\n\nexport default class Patch implements IPatch {\n id!: string;\n name!: string;\n userId!: string;\n config!: IConfig;\n\n static async find(id: string): Promise<Patch> {\n const db = getDb();\n\n const docRef = doc(db, \"patches\", id);\n const docSnap = await getDoc(docRef);\n\n if (docSnap.exists()) {\n const data = { id: docSnap.id, ...docSnap.data() } as IPatch;\n return new Patch(data);\n } else {\n throw Error(`Patch ${id} not found`);\n }\n }\n\n static async all(): Promise<Patch[]> {\n const db = getDb();\n\n const querySnapshot = await getDocs(collection(db, \"patches\"));\n\n return querySnapshot.docs.map((doc) => {\n return new Patch({\n id: doc.id,\n ...doc.data(),\n } as IPatch);\n });\n }\n\n constructor(props: Optional<IPatch, \"id\">) {\n Object.assign(this, pick(props, [\"id\", \"name\", \"userId\", \"config\"]));\n }\n\n async save(): Promise<void> {\n const db = getDb();\n\n if (this.id) {\n await updateDoc(this.docRef, this.props);\n } else {\n const docRef = await addDoc(collection(db, \"patches\"), this.props);\n this.id = docRef.id;\n }\n }\n\n async delete(): Promise<void> {\n if (!this.id) throw Error(\"Cannot delete a patch without id\");\n\n await deleteDoc(this.docRef);\n }\n\n serialize(): IPatch {\n return {\n id: this.id,\n ...this.props,\n };\n }\n\n engineSerialize(): IEngineSerialize {\n const { modules, gridNodes } = this.props.config;\n\n const routes: IRoute[] = gridNodes.edges.map((edge) => {\n return {\n id: edge.id,\n source: { moduleId: edge.source, ioName: edge.sourceHandle! },\n destination: { moduleId: edge.target, ioName: edge.targetHandle! },\n };\n });\n\n return {\n bpm: 120, // Temp: static until I set it from grid\n timeSignature: [4, 4], // Temp: static until I set it from grid\n modules,\n routes,\n };\n }\n\n private get docRef() {\n const db = getDb();\n\n return doc(db, \"patches\", this.id);\n }\n\n private get props(): Omit<IPatch, \"id\"> {\n return { name: this.name, userId: this.userId, config: this.config };\n }\n}\n","import { Optional, pick } from \"@blibliki/utils\";\nimport {\n collection,\n addDoc,\n getDoc,\n doc,\n updateDoc,\n getDocs,\n deleteDoc,\n query,\n where,\n} from \"firebase/firestore\";\nimport { getDb } from \"./db\";\n\nexport type IDevice = {\n id: string;\n token: string;\n name: string;\n patchId: string | null;\n userId: string;\n};\n\nexport default class Device implements IDevice {\n id!: string;\n token!: string;\n name!: string;\n patchId!: string | null;\n userId!: string;\n\n static async find(id: string): Promise<Device> {\n const db = getDb();\n\n const docRef = doc(db, \"devices\", id);\n const docSnap = await getDoc(docRef);\n\n if (docSnap.exists()) {\n const data = { id: docSnap.id, ...docSnap.data() } as IDevice;\n return new Device(data);\n } else {\n throw Error(`Device ${id} not found`);\n }\n }\n\n static async findByUserId(userId: string): Promise<Device[]> {\n const db = getDb();\n\n const q = query(collection(db, \"devices\"), where(\"userId\", \"==\", userId));\n const querySnapshot = await getDocs(q);\n\n return querySnapshot.docs.map((doc) => {\n return new Device({\n id: doc.id,\n ...doc.data(),\n } as IDevice);\n });\n }\n\n static async findBy(opts: {\n userId?: string;\n token?: string;\n }): Promise<Device[]> {\n const db = getDb();\n\n const whereClauses = Object.entries(opts).map(([key, value]) =>\n where(key, \"==\", value),\n );\n const q = query(collection(db, \"devices\"), ...whereClauses);\n const querySnapshot = await getDocs(q);\n\n return querySnapshot.docs.map((doc) => {\n return new Device({\n id: doc.id,\n ...doc.data(),\n } as IDevice);\n });\n }\n\n static async all(): Promise<Device[]> {\n const db = getDb();\n\n const querySnapshot = await getDocs(collection(db, \"devices\"));\n\n return querySnapshot.docs.map((doc) => {\n return new Device({\n id: doc.id,\n ...doc.data(),\n } as IDevice);\n });\n }\n\n constructor(props: Optional<IDevice, \"id\">) {\n Object.assign(\n this,\n pick(props, [\"id\", \"token\", \"name\", \"patchId\", \"userId\"]),\n );\n }\n\n async save(): Promise<void> {\n const db = getDb();\n\n if (this.id) {\n await updateDoc(this.docRef, this.props);\n } else {\n const docRef = await addDoc(collection(db, \"devices\"), this.props);\n this.id = docRef.id;\n }\n }\n\n async delete(): Promise<void> {\n if (!this.id) throw Error(\"Cannot delete a device without id\");\n\n await deleteDoc(this.docRef);\n }\n\n serialize(): IDevice {\n return {\n id: this.id,\n ...this.props,\n };\n }\n\n private get docRef() {\n const db = getDb();\n return doc(db, \"devices\", this.id);\n }\n\n private get props(): Omit<IDevice, \"id\"> {\n return {\n token: this.token,\n name: this.name,\n patchId: this.patchId,\n userId: this.userId,\n };\n }\n}\n"],"mappings":"AAAA,OAA2B,iBAAAA,MAAqB,eAChD,OAAyB,gBAAAC,MAAoB,qBAW7C,IAAIC,EACAC,EACAC,EAESC,EAAsBC,GAA2B,CAC5DJ,EAAiBI,EACjBH,EAAMH,EAAcE,CAAc,EAClCE,EAAKH,EAAaE,CAAG,CACvB,EAEaI,EAAS,IAAmB,CACvC,GAAI,CAACJ,EAAK,MAAM,MAAM,iCAAiC,EAEvD,OAAOA,CACT,EAEaK,EAAQ,IAAiB,CACpC,GAAI,CAACJ,EAAI,MAAM,MAAM,iCAAiC,EAEtD,OAAOA,CACT,EC3BA,OAA8B,QAAAK,MAAY,kBAC1C,OACE,cAAAC,EACA,UAAAC,EACA,UAAAC,EACA,OAAAC,EACA,aAAAC,EACA,WAAAC,EACA,aAAAC,MACK,qBAmDP,IAAqBC,EAArB,MAAqBC,CAAwB,CAC3C,GACA,KACA,OACA,OAEA,aAAa,KAAKC,EAA4B,CAC5C,IAAMC,EAAKC,EAAM,EAEXC,EAASC,EAAIH,EAAI,UAAWD,CAAE,EAC9BK,EAAU,MAAMC,EAAOH,CAAM,EAEnC,GAAIE,EAAQ,OAAO,EAAG,CACpB,IAAME,EAAO,CAAE,GAAIF,EAAQ,GAAI,GAAGA,EAAQ,KAAK,CAAE,EACjD,OAAO,IAAIN,EAAMQ,CAAI,CACvB,KACE,OAAM,MAAM,SAASP,CAAE,YAAY,CAEvC,CAEA,aAAa,KAAwB,CACnC,IAAMC,EAAKC,EAAM,EAIjB,OAFsB,MAAMM,EAAQC,EAAWR,EAAI,SAAS,CAAC,GAExC,KAAK,IAAKG,GACtB,IAAIL,EAAM,CACf,GAAIK,EAAI,GACR,GAAGA,EAAI,K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YAAYc,EAAgC,CAC1C,OAAO,OACL,KACAC,EAAKD,EAAO,CAAC,KAAM,QAAS,OAAQ,UAAW,QAAQ,CAAC,CAC1D,CACF,CAEA,MAAM,MAAsB,CAC1B,IAAMjB,EAAKC,EAAM,EAEjB,GAAI,KAAK,GACP,MAAMkB,EAAU,KAAK,OAAQ,KAAK,KAAK,MAClC,CACL,IAAMjB,EAAS,MAAMkB,EAAOV,EAAWV,EAAI,SAAS,EAAG,KAAK,KAAK,EACjE,KAAK,GAAKE,EAAO,EACnB,CACF,CAEA,MAAM,QAAwB,CAC5B,GAAI,CAAC,KAAK,GAAI,MAAM,MAAM,mCAAmC,EAE7D,MAAMmB,EAAU,KAAK,MAAM,CAC7B,CAEA,WAAqB,CACnB,MAAO,CACL,GAAI,KAAK,GACT,GAAG,KAAK,KACV,CACF,CAEA,IAAY,QAAS,CACnB,IAAMrB,EAAKC,EAAM,EACjB,OAAOE,EAAIH,EAAI,UAAW,KAAK,EAAE,CACnC,CAEA,IAAY,OAA6B,CACvC,MAAO,CACL,MAAO,KAAK,MACZ,KAAM,KAAK,KACX,QAAS,KAAK,QACd,OAAQ,KAAK,MACf,CACF,CACF","names":["initializeApp","getFirestore","firebaseConfig","app","db","initializeFirebase","config","getApp","getDb","pick","collection","addDoc","getDoc","doc","updateDoc","getDocs","deleteDoc","Patch","_Patch","id","db","getDb","docRef","doc","docSnap","getDoc","data","getDocs","collection","props","pick","updateDoc","addDoc","deleteDoc","modules","gridNodes","routes","edge","pick","collection","addDoc","getDoc","doc","updateDoc","getDocs","deleteDoc","query","where","Device","_Device","id","db","getDb","docRef","doc","docSnap","getDoc","data","userId","q","query","collection","where","getDocs","opts","whereClauses","key","value","props","pick","updateDoc","addDoc","deleteDoc"]}
1
+ {"version":3,"sources":["../src/db.ts","../src/Patch.ts","../src/Device.ts"],"sourcesContent":["import { type FirebaseApp, initializeApp } from \"firebase/app\";\nimport { type Firestore, getFirestore } from \"firebase/firestore\";\n\nexport type FirebaseConfig = {\n apiKey: string;\n authDomain: string;\n projectId: string;\n storageBucket: string;\n messagingSenderId: string;\n appId: string;\n};\n\nlet firebaseConfig: FirebaseConfig | undefined;\nlet app: FirebaseApp | undefined;\nlet db: Firestore | undefined;\n\nexport const initializeFirebase = (config: FirebaseConfig) => {\n firebaseConfig = config;\n app = initializeApp(firebaseConfig);\n db = getFirestore(app);\n};\n\nexport const getApp = (): FirebaseApp => {\n if (!app) throw Error(\"You have to initialize db first\");\n\n return app;\n};\n\nexport const getDb = (): Firestore => {\n if (!db) throw Error(\"You have to initialize db first\");\n\n return db;\n};\n","import {\n BPM,\n IAnyModuleSerialize,\n IEngineSerialize,\n IRoute,\n} from \"@blibliki/engine\";\nimport { AnyObject, Optional, pick } from \"@blibliki/utils\";\nimport {\n collection,\n addDoc,\n getDoc,\n doc,\n updateDoc,\n getDocs,\n deleteDoc,\n} from \"firebase/firestore\";\nimport { getDb } from \"./db\";\n\nexport type IPatch = {\n id: string;\n name: string;\n userId: string;\n config: IConfig;\n};\n\ntype Viewport = {\n x: number;\n y: number;\n zoom: number;\n};\n\ntype Node = {\n data: AnyObject;\n dragging?: boolean;\n id: string;\n measured?: {\n height?: number;\n width?: number;\n };\n position: {\n x: number;\n y: number;\n };\n selected?: boolean;\n type?: string;\n};\n\ntype Edge = {\n id: string;\n source: string;\n sourceHandle?: string | null;\n target: string;\n targetHandle?: string | null;\n};\n\ntype IGridNodes = {\n nodes: Node[];\n edges: Edge[];\n viewport: Viewport;\n};\n\nexport type IConfig = {\n bpm: BPM;\n modules: IAnyModuleSerialize[];\n gridNodes: IGridNodes;\n};\n\nexport default class Patch implements IPatch {\n id!: string;\n name!: string;\n userId!: string;\n config!: IConfig;\n\n static async find(id: string): Promise<Patch> {\n const db = getDb();\n\n const docRef = doc(db, \"patches\", id);\n const docSnap = await getDoc(docRef);\n\n if (docSnap.exists()) {\n const data = { id: docSnap.id, ...docSnap.data() } as IPatch;\n return new Patch(data);\n } else {\n throw Error(`Patch ${id} not found`);\n }\n }\n\n static async all(): Promise<Patch[]> {\n const db = getDb();\n\n const querySnapshot = await getDocs(collection(db, \"patches\"));\n\n return querySnapshot.docs.map((doc) => {\n return new Patch({\n id: doc.id,\n ...doc.data(),\n } as IPatch);\n });\n }\n\n constructor(props: Optional<IPatch, \"id\">) {\n Object.assign(this, pick(props, [\"id\", \"name\", \"userId\", \"config\"]));\n }\n\n async save(): Promise<void> {\n const db = getDb();\n\n if (this.id) {\n await updateDoc(this.docRef, this.props);\n } else {\n const docRef = await addDoc(collection(db, \"patches\"), this.props);\n this.id = docRef.id;\n }\n }\n\n async delete(): Promise<void> {\n if (!this.id) throw Error(\"Cannot delete a patch without id\");\n\n await deleteDoc(this.docRef);\n }\n\n serialize(): IPatch {\n return {\n id: this.id,\n ...this.props,\n };\n }\n\n engineSerialize(): IEngineSerialize {\n const { bpm, modules, gridNodes } = this.props.config;\n\n const routes: IRoute[] = gridNodes.edges.map((edge) => {\n return {\n id: edge.id,\n source: { moduleId: edge.source, ioName: edge.sourceHandle! },\n destination: { moduleId: edge.target, ioName: edge.targetHandle! },\n };\n });\n\n return {\n bpm,\n timeSignature: [4, 4], // Temp: static until I set it from grid\n modules,\n routes,\n };\n }\n\n private get docRef() {\n const db = getDb();\n\n return doc(db, \"patches\", this.id);\n }\n\n private get props(): Omit<IPatch, \"id\"> {\n return { name: this.name, userId: this.userId, config: this.config };\n }\n}\n","import { Optional, pick } from \"@blibliki/utils\";\nimport {\n collection,\n addDoc,\n getDoc,\n doc,\n updateDoc,\n getDocs,\n deleteDoc,\n query,\n where,\n} from \"firebase/firestore\";\nimport { getDb } from \"./db\";\n\nexport type IDevice = {\n id: string;\n token: string;\n name: string;\n patchId: string | null;\n userId: string;\n};\n\nexport default class Device implements IDevice {\n id!: string;\n token!: string;\n name!: string;\n patchId!: string | null;\n userId!: string;\n\n static async find(id: string): Promise<Device> {\n const db = getDb();\n\n const docRef = doc(db, \"devices\", id);\n const docSnap = await getDoc(docRef);\n\n if (docSnap.exists()) {\n const data = { id: docSnap.id, ...docSnap.data() } as IDevice;\n return new Device(data);\n } else {\n throw Error(`Device ${id} not found`);\n }\n }\n\n static async findByUserId(userId: string): Promise<Device[]> {\n const db = getDb();\n\n const q = query(collection(db, \"devices\"), where(\"userId\", \"==\", userId));\n const querySnapshot = await getDocs(q);\n\n return querySnapshot.docs.map((doc) => {\n return new Device({\n id: doc.id,\n ...doc.data(),\n } as IDevice);\n });\n }\n\n static async findBy(opts: {\n userId?: string;\n token?: string;\n }): Promise<Device[]> {\n const db = getDb();\n\n const whereClauses = Object.entries(opts).map(([key, value]) =>\n where(key, \"==\", value),\n );\n const q = query(collection(db, \"devices\"), ...whereClauses);\n const querySnapshot = await getDocs(q);\n\n return querySnapshot.docs.map((doc) => {\n return new Device({\n id: doc.id,\n ...doc.data(),\n } as IDevice);\n });\n }\n\n static async all(): Promise<Device[]> {\n const db = getDb();\n\n const querySnapshot = await getDocs(collection(db, \"devices\"));\n\n return querySnapshot.docs.map((doc) => {\n return new Device({\n id: doc.id,\n ...doc.data(),\n } as IDevice);\n });\n }\n\n constructor(props: Optional<IDevice, \"id\">) {\n Object.assign(\n this,\n pick(props, [\"id\", \"token\", \"name\", \"patchId\", \"userId\"]),\n );\n }\n\n async save(): Promise<void> {\n const db = getDb();\n\n if (this.id) {\n await updateDoc(this.docRef, this.props);\n } else {\n const docRef = await addDoc(collection(db, \"devices\"), this.props);\n this.id = docRef.id;\n }\n }\n\n async delete(): Promise<void> {\n if (!this.id) throw Error(\"Cannot delete a device without id\");\n\n await deleteDoc(this.docRef);\n }\n\n serialize(): IDevice {\n return {\n id: this.id,\n ...this.props,\n };\n }\n\n private get docRef() {\n const db = getDb();\n return doc(db, \"devices\", this.id);\n }\n\n private get props(): Omit<IDevice, \"id\"> {\n return {\n token: this.token,\n name: this.name,\n patchId: this.patchId,\n userId: this.userId,\n };\n }\n}\n"],"mappings":"AAAA,OAA2B,iBAAAA,MAAqB,eAChD,OAAyB,gBAAAC,MAAoB,qBAW7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MAAMkB,EAAOV,EAAWV,EAAI,SAAS,EAAG,KAAK,KAAK,EACjE,KAAK,GAAKE,EAAO,EACnB,CACF,CAEA,MAAM,QAAwB,CAC5B,GAAI,CAAC,KAAK,GAAI,MAAM,MAAM,mCAAmC,EAE7D,MAAMmB,EAAU,KAAK,MAAM,CAC7B,CAEA,WAAqB,CACnB,MAAO,CACL,GAAI,KAAK,GACT,GAAG,KAAK,KACV,CACF,CAEA,IAAY,QAAS,CACnB,IAAMrB,EAAKC,EAAM,EACjB,OAAOE,EAAIH,EAAI,UAAW,KAAK,EAAE,CACnC,CAEA,IAAY,OAA6B,CACvC,MAAO,CACL,MAAO,KAAK,MACZ,KAAM,KAAK,KACX,QAAS,KAAK,QACd,OAAQ,KAAK,MACf,CACF,CACF","names":["initializeApp","getFirestore","firebaseConfig","app","db","initializeFirebase","config","getApp","getDb","pick","collection","addDoc","getDoc","doc","updateDoc","getDocs","deleteDoc","Patch","_Patch","id","db","getDb","docRef","doc","docSnap","getDoc","data","getDocs","collection","props","pick","updateDoc","addDoc","deleteDoc","bpm","modules","gridNodes","routes","edge","pick","collection","addDoc","getDoc","doc","updateDoc","getDocs","deleteDoc","query","where","Device","_Device","id","db","getDb","docRef","doc","docSnap","getDoc","data","userId","q","query","collection","where","getDocs","opts","whereClauses","key","value","props","pick","updateDoc","addDoc","deleteDoc"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blibliki/models",
3
- "version": "0.5.2",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -15,13 +15,13 @@
15
15
  "dist"
16
16
  ],
17
17
  "devDependencies": {
18
- "@types/audioworklet": "0.0.92",
19
- "@types/node": "^22.10.2"
18
+ "@types/audioworklet": "0.0.93",
19
+ "@types/node": "25.1.0"
20
20
  },
21
21
  "dependencies": {
22
- "firebase": "12.6.0",
23
- "@blibliki/utils": "^0.5.2",
24
- "@blibliki/engine": "^0.5.2"
22
+ "firebase": "12.8.0",
23
+ "@blibliki/engine": "^0.9.0",
24
+ "@blibliki/utils": "^0.9.0"
25
25
  },
26
26
  "scripts": {
27
27
  "build": "tsup",
package/src/Patch.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ BPM,
2
3
  IAnyModuleSerialize,
3
4
  IEngineSerialize,
4
5
  IRoute,
@@ -59,6 +60,7 @@ type IGridNodes = {
59
60
  };
60
61
 
61
62
  export type IConfig = {
63
+ bpm: BPM;
62
64
  modules: IAnyModuleSerialize[];
63
65
  gridNodes: IGridNodes;
64
66
  };
@@ -125,7 +127,7 @@ export default class Patch implements IPatch {
125
127
  }
126
128
 
127
129
  engineSerialize(): IEngineSerialize {
128
- const { modules, gridNodes } = this.props.config;
130
+ const { bpm, modules, gridNodes } = this.props.config;
129
131
 
130
132
  const routes: IRoute[] = gridNodes.edges.map((edge) => {
131
133
  return {
@@ -136,7 +138,7 @@ export default class Patch implements IPatch {
136
138
  });
137
139
 
138
140
  return {
139
- bpm: 120, // Temp: static until I set it from grid
141
+ bpm,
140
142
  timeSignature: [4, 4], // Temp: static until I set it from grid
141
143
  modules,
142
144
  routes,