@servicetitan/data-query 32.3.0 → 32.4.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/data-source/async-data-source.ts"],"sourcesContent":["import { State } from '../state';\nimport { DataResult } from '../data-result.interface';\nimport axios, { CancelToken, CancelTokenSource } from 'axios';\nimport { DataSource, IdType } from './data-source';\nimport cloneDeep from 'lodash/cloneDeep';\nimport { toJS, comparer } from 'mobx';\n\ninterface Operations<T, TId> {\n get(state: State, cancelToken?: CancelToken): Promise<DataResult<T>>;\n add?(item: T, index?: number): Promise<T>;\n update?(id: TId, changes: Partial<T>): Promise<void>;\n remove?(id: TId): Promise<T | undefined>;\n}\n\nexport class AsyncDataSource<T, TId extends IdType = never> implements DataSource<T, TId> {\n idSelector?: (row: T) => TId;\n\n private operations: Operations<T, TId>;\n\n private withCache?: boolean;\n private cached?: {\n state: State;\n result: DataResult<T>;\n };\n\n private cancelation?: CancelTokenSource;\n\n constructor(operations: Operations<T, TId>, idSelector?: (row: T) => TId, withCache?: boolean) {\n this.operations = operations;\n this.idSelector = idSelector;\n this.withCache = withCache;\n }\n\n async getData(state: State) {\n if (this.cancelation) {\n this.cancelation.cancel();\n }\n\n if (this.withCache && this.cached && comparer.structural(this.cached.state, state)) {\n return cloneDeep(this.cached.result);\n }\n\n this.cancelation = axios.CancelToken.source();\n const result = toJS(await this.operations.get(state, this.cancelation.token));\n this.cancelation = undefined;\n\n this.cached = { state, result };\n\n return cloneDeep(result);\n }\n\n async addData(row: T, index?: number) {\n if (!this.operations.add) {\n throw 'missing add function in the operations';\n }\n\n const result = await this.operations.add(row, index);\n\n this.cached = undefined;\n\n return result;\n }\n\n async updateData(id: TId, changes: Partial<T>) {\n if (!this.operations.update) {\n throw 'missing update function in the operations';\n }\n\n await this.operations.update(id, changes);\n\n this.cached = undefined;\n }\n\n async removeData(id: TId) {\n if (!this.operations.remove) {\n throw 'missing remove function in the operations';\n }\n\n const result = await this.operations.remove(id);\n\n this.cached = undefined;\n\n return result;\n }\n}\n"],"names":["axios","cloneDeep","toJS","comparer","AsyncDataSource","getData","state","cancelation","cancel","withCache","cached","structural","result","CancelToken","source","operations","get","token","undefined","addData","row","index","add","updateData","id","changes","update","removeData","remove","
|
|
1
|
+
{"version":3,"sources":["../../src/data-source/async-data-source.ts"],"sourcesContent":["import { State } from '../state';\nimport { DataResult } from '../data-result.interface';\nimport axios, { CancelToken, CancelTokenSource } from 'axios';\nimport { DataSource, IdType } from './data-source';\nimport cloneDeep from 'lodash/cloneDeep';\nimport { toJS, comparer } from 'mobx';\n\ninterface Operations<T, TId> {\n get(state: State, cancelToken?: CancelToken): Promise<DataResult<T>>;\n add?(item: T, index?: number): Promise<T>;\n update?(id: TId, changes: Partial<T>): Promise<void>;\n remove?(id: TId): Promise<T | undefined>;\n}\n\nexport class AsyncDataSource<T, TId extends IdType = never> implements DataSource<T, TId> {\n idSelector?: (row: T) => TId;\n\n private operations: Operations<T, TId>;\n\n private withCache?: boolean;\n private cached?: {\n state: State;\n result: DataResult<T>;\n };\n\n private cancelation?: CancelTokenSource;\n\n constructor(operations: Operations<T, TId>, idSelector?: (row: T) => TId, withCache?: boolean) {\n this.operations = operations;\n this.idSelector = idSelector;\n this.withCache = withCache;\n }\n\n async getData(state: State) {\n if (this.cancelation) {\n this.cancelation.cancel();\n }\n\n if (this.withCache && this.cached && comparer.structural(this.cached.state, state)) {\n return cloneDeep(this.cached.result);\n }\n\n this.cancelation = axios.CancelToken.source();\n const result = toJS(await this.operations.get(state, this.cancelation.token));\n this.cancelation = undefined;\n\n this.cached = { state, result };\n\n return cloneDeep(result);\n }\n\n async addData(row: T, index?: number) {\n if (!this.operations.add) {\n throw 'missing add function in the operations';\n }\n\n const result = await this.operations.add(row, index);\n\n this.cached = undefined;\n\n return result;\n }\n\n async updateData(id: TId, changes: Partial<T>) {\n if (!this.operations.update) {\n throw 'missing update function in the operations';\n }\n\n await this.operations.update(id, changes);\n\n this.cached = undefined;\n }\n\n async removeData(id: TId) {\n if (!this.operations.remove) {\n throw 'missing remove function in the operations';\n }\n\n const result = await this.operations.remove(id);\n\n this.cached = undefined;\n\n return result;\n }\n}\n"],"names":["axios","cloneDeep","toJS","comparer","AsyncDataSource","getData","state","cancelation","cancel","withCache","cached","structural","result","CancelToken","source","operations","get","token","undefined","addData","row","index","add","updateData","id","changes","update","removeData","remove","idSelector"],"mappings":";;;;;;;;;;;;;AAEA,OAAOA,WAA+C,QAAQ;AAE9D,OAAOC,eAAe,mBAAmB;AACzC,SAASC,IAAI,EAAEC,QAAQ,QAAQ,OAAO;AAStC,OAAO,MAAMC;IAmBT,MAAMC,QAAQC,KAAY,EAAE;QACxB,IAAI,IAAI,CAACC,WAAW,EAAE;YAClB,IAAI,CAACA,WAAW,CAACC,MAAM;QAC3B;QAEA,IAAI,IAAI,CAACC,SAAS,IAAI,IAAI,CAACC,MAAM,IAAIP,SAASQ,UAAU,CAAC,IAAI,CAACD,MAAM,CAACJ,KAAK,EAAEA,QAAQ;YAChF,OAAOL,UAAU,IAAI,CAACS,MAAM,CAACE,MAAM;QACvC;QAEA,IAAI,CAACL,WAAW,GAAGP,MAAMa,WAAW,CAACC,MAAM;QAC3C,MAAMF,SAASV,KAAK,MAAM,IAAI,CAACa,UAAU,CAACC,GAAG,CAACV,OAAO,IAAI,CAACC,WAAW,CAACU,KAAK;QAC3E,IAAI,CAACV,WAAW,GAAGW;QAEnB,IAAI,CAACR,MAAM,GAAG;YAAEJ;YAAOM;QAAO;QAE9B,OAAOX,UAAUW;IACrB;IAEA,MAAMO,QAAQC,GAAM,EAAEC,KAAc,EAAE;QAClC,IAAI,CAAC,IAAI,CAACN,UAAU,CAACO,GAAG,EAAE;YACtB,MAAM;QACV;QAEA,MAAMV,SAAS,MAAM,IAAI,CAACG,UAAU,CAACO,GAAG,CAACF,KAAKC;QAE9C,IAAI,CAACX,MAAM,GAAGQ;QAEd,OAAON;IACX;IAEA,MAAMW,WAAWC,EAAO,EAAEC,OAAmB,EAAE;QAC3C,IAAI,CAAC,IAAI,CAACV,UAAU,CAACW,MAAM,EAAE;YACzB,MAAM;QACV;QAEA,MAAM,IAAI,CAACX,UAAU,CAACW,MAAM,CAACF,IAAIC;QAEjC,IAAI,CAACf,MAAM,GAAGQ;IAClB;IAEA,MAAMS,WAAWH,EAAO,EAAE;QACtB,IAAI,CAAC,IAAI,CAACT,UAAU,CAACa,MAAM,EAAE;YACzB,MAAM;QACV;QAEA,MAAMhB,SAAS,MAAM,IAAI,CAACG,UAAU,CAACa,MAAM,CAACJ;QAE5C,IAAI,CAACd,MAAM,GAAGQ;QAEd,OAAON;IACX;IAxDA,YAAYG,UAA8B,EAAEc,UAA4B,EAAEpB,SAAmB,CAAE;QAZ/FoB,uBAAAA,cAAAA,KAAAA;QAEA,uBAAQd,cAAR,KAAA;QAEA,uBAAQN,aAAR,KAAA;QACA,uBAAQC,UAAR,KAAA;QAKA,uBAAQH,eAAR,KAAA;QAGI,IAAI,CAACQ,UAAU,GAAGA;QAClB,IAAI,CAACc,UAAU,GAAGA;QAClB,IAAI,CAACpB,SAAS,GAAGA;IACrB;AAqDJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/data-source/in-memory-data-source.ts"],"sourcesContent":["import { State } from '../state';\nimport { Preprocessors } from '../common.interfaces';\nimport { CompositeFilterDescriptor } from '../filtering/filter-descriptor.interface';\nimport { DataResult } from '../data-result.interface';\nimport { filterBy } from '../filtering/filter-expression.factory';\nimport { process } from '../array.operators';\nimport { DataSource, IdType } from './data-source';\nimport cloneDeep from 'lodash/cloneDeep';\nimport cloneDeepWith from 'lodash/cloneDeepWith';\nimport { toJS, comparer } from 'mobx';\n\nexport class InMemoryDataSource<T, TId extends IdType = never> implements DataSource<T, TId> {\n idSelector?: (row: T) => TId;\n\n private clone: <U>(value: U) => U;\n private data: T[];\n private preprocessors: Preprocessors<T>;\n\n private cached?: {\n state: State;\n result: DataResult<T>;\n };\n\n constructor(\n data: T[],\n idSelector?: (row: T) => TId,\n preprocessors: Preprocessors<T> = {},\n { cloneCustomizer }: { cloneCustomizer?: (value: any) => any } = {}\n ) {\n this.clone = cloneCustomizer\n ? <U>(value: U) => cloneDeepWith(value, cloneCustomizer)\n : cloneDeep;\n this.data = this.clone(toJS(data));\n this.idSelector = idSelector;\n this.preprocessors = preprocessors;\n }\n\n getData(state: State) {\n const { skip, take, sort, filter, group } = state;\n\n const sortedAndFiltered =\n this.cached && comparer.structural(this.cached.state, { sort, filter })\n ? this.cached.result\n : process(this.data, { sort, filter }, this.preprocessors);\n\n this.cached = {\n state: { sort, filter },\n result: sortedAndFiltered,\n };\n\n const { data } = process(sortedAndFiltered.data, { skip, take, group }, this.preprocessors);\n const { total } = sortedAndFiltered;\n\n return Promise.resolve({\n total,\n data: this.clone(data),\n } as DataResult<T>);\n }\n\n addData(row: T, index?: number) {\n if (index !== undefined) {\n this.data.splice(index, 0, this.clone(row));\n } else {\n this.data.push(this.clone(row));\n }\n\n this.cached = undefined;\n\n return Promise.resolve(this.clone(row));\n }\n\n async updateData(id: TId, changes: Partial<T>) {\n if (!this.idSelector) {\n throw 'missing idSelector';\n }\n\n const row = this.data.find(row => this.idSelector!(row) === id);\n\n if (row) {\n Object.assign(row, changes);\n\n this.cached = undefined;\n }\n\n return Promise.resolve();\n }\n\n async removeData(id: TId) {\n if (!this.idSelector) {\n throw 'missing idSelector';\n }\n\n const index = this.data.findIndex(row => this.idSelector!(row) === id);\n\n if (index !== -1) {\n const row = this.data[index];\n this.data.splice(index, 1);\n\n this.cached = undefined;\n\n return Promise.resolve(row);\n }\n }\n\n getFilteredPersistentItems(filter: CompositeFilterDescriptor) {\n const set = new Set(this.data);\n const inFilter = filterBy(this.data, filter, this.preprocessors);\n inFilter.forEach(dataItem => set.delete(dataItem));\n return this.clone(Array.from(set));\n }\n}\n"],"names":["filterBy","process","cloneDeep","cloneDeepWith","toJS","comparer","InMemoryDataSource","getData","state","skip","take","sort","filter","group","sortedAndFiltered","cached","structural","result","data","preprocessors","total","Promise","resolve","clone","addData","row","index","undefined","splice","push","updateData","id","changes","idSelector","find","Object","assign","removeData","findIndex","getFilteredPersistentItems","set","Set","inFilter","forEach","dataItem","delete","Array","from","
|
|
1
|
+
{"version":3,"sources":["../../src/data-source/in-memory-data-source.ts"],"sourcesContent":["import { State } from '../state';\nimport { Preprocessors } from '../common.interfaces';\nimport { CompositeFilterDescriptor } from '../filtering/filter-descriptor.interface';\nimport { DataResult } from '../data-result.interface';\nimport { filterBy } from '../filtering/filter-expression.factory';\nimport { process } from '../array.operators';\nimport { DataSource, IdType } from './data-source';\nimport cloneDeep from 'lodash/cloneDeep';\nimport cloneDeepWith from 'lodash/cloneDeepWith';\nimport { toJS, comparer } from 'mobx';\n\nexport class InMemoryDataSource<T, TId extends IdType = never> implements DataSource<T, TId> {\n idSelector?: (row: T) => TId;\n\n private clone: <U>(value: U) => U;\n private data: T[];\n private preprocessors: Preprocessors<T>;\n\n private cached?: {\n state: State;\n result: DataResult<T>;\n };\n\n constructor(\n data: T[],\n idSelector?: (row: T) => TId,\n preprocessors: Preprocessors<T> = {},\n { cloneCustomizer }: { cloneCustomizer?: (value: any) => any } = {}\n ) {\n this.clone = cloneCustomizer\n ? <U>(value: U) => cloneDeepWith(value, cloneCustomizer)\n : cloneDeep;\n this.data = this.clone(toJS(data));\n this.idSelector = idSelector;\n this.preprocessors = preprocessors;\n }\n\n getData(state: State) {\n const { skip, take, sort, filter, group } = state;\n\n const sortedAndFiltered =\n this.cached && comparer.structural(this.cached.state, { sort, filter })\n ? this.cached.result\n : process(this.data, { sort, filter }, this.preprocessors);\n\n this.cached = {\n state: { sort, filter },\n result: sortedAndFiltered,\n };\n\n const { data } = process(sortedAndFiltered.data, { skip, take, group }, this.preprocessors);\n const { total } = sortedAndFiltered;\n\n return Promise.resolve({\n total,\n data: this.clone(data),\n } as DataResult<T>);\n }\n\n addData(row: T, index?: number) {\n if (index !== undefined) {\n this.data.splice(index, 0, this.clone(row));\n } else {\n this.data.push(this.clone(row));\n }\n\n this.cached = undefined;\n\n return Promise.resolve(this.clone(row));\n }\n\n async updateData(id: TId, changes: Partial<T>) {\n if (!this.idSelector) {\n throw 'missing idSelector';\n }\n\n const row = this.data.find(row => this.idSelector!(row) === id);\n\n if (row) {\n Object.assign(row, changes);\n\n this.cached = undefined;\n }\n\n return Promise.resolve();\n }\n\n async removeData(id: TId) {\n if (!this.idSelector) {\n throw 'missing idSelector';\n }\n\n const index = this.data.findIndex(row => this.idSelector!(row) === id);\n\n if (index !== -1) {\n const row = this.data[index];\n this.data.splice(index, 1);\n\n this.cached = undefined;\n\n return Promise.resolve(row);\n }\n }\n\n getFilteredPersistentItems(filter: CompositeFilterDescriptor) {\n const set = new Set(this.data);\n const inFilter = filterBy(this.data, filter, this.preprocessors);\n inFilter.forEach(dataItem => set.delete(dataItem));\n return this.clone(Array.from(set));\n }\n}\n"],"names":["filterBy","process","cloneDeep","cloneDeepWith","toJS","comparer","InMemoryDataSource","getData","state","skip","take","sort","filter","group","sortedAndFiltered","cached","structural","result","data","preprocessors","total","Promise","resolve","clone","addData","row","index","undefined","splice","push","updateData","id","changes","idSelector","find","Object","assign","removeData","findIndex","getFilteredPersistentItems","set","Set","inFilter","forEach","dataItem","delete","Array","from","cloneCustomizer","value"],"mappings":";;;;;;;;;;;;;AAIA,SAASA,QAAQ,QAAQ,yCAAyC;AAClE,SAASC,OAAO,QAAQ,qBAAqB;AAE7C,OAAOC,eAAe,mBAAmB;AACzC,OAAOC,mBAAmB,uBAAuB;AACjD,SAASC,IAAI,EAAEC,QAAQ,QAAQ,OAAO;AAEtC,OAAO,MAAMC;IA0BTC,QAAQC,KAAY,EAAE;QAClB,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,EAAEC,KAAK,EAAE,GAAGL;QAE5C,MAAMM,oBACF,IAAI,CAACC,MAAM,IAAIV,SAASW,U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
|
+
"version": "32.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"cli": {
|
|
35
35
|
"webpack": false
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "3dab3310534a39aaacb0069e1d377579fe0a7fab"
|
|
38
38
|
}
|