@furystack/repository 10.1.11 → 11.0.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/CHANGELOG.md +10 -0
- package/README.md +74 -36
- package/esm/data-set.spec.d.ts +2 -0
- package/esm/data-set.spec.d.ts.map +1 -0
- package/esm/data-set.spec.js +348 -0
- package/esm/data-set.spec.js.map +1 -0
- package/esm/define-data-set.d.ts +89 -0
- package/esm/define-data-set.d.ts.map +1 -0
- package/esm/define-data-set.js +75 -0
- package/esm/define-data-set.js.map +1 -0
- package/esm/define-data-set.spec.d.ts +2 -0
- package/esm/define-data-set.spec.d.ts.map +1 -0
- package/esm/define-data-set.spec.js +134 -0
- package/esm/define-data-set.spec.js.map +1 -0
- package/esm/helpers.d.ts +21 -22
- package/esm/helpers.d.ts.map +1 -1
- package/esm/helpers.js +17 -21
- package/esm/helpers.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/src/data-set.spec.ts +396 -0
- package/src/define-data-set.spec.ts +145 -0
- package/src/define-data-set.ts +140 -0
- package/src/helpers.ts +23 -26
- package/src/index.ts +2 -2
- package/esm/dataset.spec.d.ts +0 -2
- package/esm/dataset.spec.d.ts.map +0 -1
- package/esm/dataset.spec.js +0 -552
- package/esm/dataset.spec.js.map +0 -1
- package/esm/repository.d.ts +0 -15
- package/esm/repository.d.ts.map +0 -1
- package/esm/repository.js +0 -50
- package/esm/repository.js.map +0 -1
- package/esm/repository.spec.d.ts +0 -2
- package/esm/repository.spec.d.ts.map +0 -1
- package/esm/repository.spec.js +0 -18
- package/esm/repository.spec.js.map +0 -1
- package/src/dataset.spec.ts +0 -641
- package/src/repository.spec.ts +0 -19
- package/src/repository.ts +0 -50
package/src/repository.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { WithOptionalId } from '@furystack/core'
|
|
2
|
-
import { StoreManager } from '@furystack/core'
|
|
3
|
-
import type { Constructable } from '@furystack/inject'
|
|
4
|
-
import { Injectable, Injected } from '@furystack/inject'
|
|
5
|
-
import type { DataSetSettings } from './data-set-setting.js'
|
|
6
|
-
import { DataSet } from './data-set.js'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Collection of authorized physical stores
|
|
10
|
-
*/
|
|
11
|
-
@Injectable({ lifetime: 'singleton' })
|
|
12
|
-
export class Repository implements Disposable {
|
|
13
|
-
public [Symbol.dispose]() {
|
|
14
|
-
this.dataSets.forEach((ds) => ds[Symbol.dispose]())
|
|
15
|
-
this.dataSets.clear()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private dataSets: Map<any, DataSet<any, any>> = new Map()
|
|
19
|
-
|
|
20
|
-
public getDataSetFor<T, TPrimaryKey extends keyof T, TWritableData = WithOptionalId<T, TPrimaryKey>>(
|
|
21
|
-
model: Constructable<T>,
|
|
22
|
-
primaryKey: TPrimaryKey,
|
|
23
|
-
) {
|
|
24
|
-
const instance = this.dataSets.get(model)
|
|
25
|
-
if (!instance) {
|
|
26
|
-
throw Error(`No DataSet found for '${model.toString()}'`)
|
|
27
|
-
}
|
|
28
|
-
if (instance.primaryKey !== primaryKey) {
|
|
29
|
-
throw Error('Primary key mismatch')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return instance as any as DataSet<T, TPrimaryKey, TWritableData>
|
|
33
|
-
}
|
|
34
|
-
public createDataSet<T, TPrimaryKey extends keyof T>(
|
|
35
|
-
model: Constructable<T>,
|
|
36
|
-
primaryKey: TPrimaryKey,
|
|
37
|
-
settings?: Partial<DataSetSettings<T, TPrimaryKey>>,
|
|
38
|
-
) {
|
|
39
|
-
const physicalStore = (settings && settings.physicalStore) || this.storeManager.getStoreFor(model, primaryKey)
|
|
40
|
-
const instance = new DataSet({
|
|
41
|
-
...settings,
|
|
42
|
-
physicalStore,
|
|
43
|
-
})
|
|
44
|
-
this.dataSets.set(model, instance)
|
|
45
|
-
return this
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@Injected(StoreManager)
|
|
49
|
-
declare private readonly storeManager: StoreManager
|
|
50
|
-
}
|