@furystack/repository
Advanced tools
Comparing version 7.0.18 to 8.0.0
@@ -5,7 +5,21 @@ import type { Injector } from '@furystack/inject'; | ||
import type { Disposable } from '@furystack/utils'; | ||
import { ObservableValue } from '@furystack/utils'; | ||
import { EventHub } from '@furystack/utils'; | ||
/** | ||
* An authorized Repository Store instance | ||
*/ | ||
export declare class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptionalId<T, TPrimaryKey>> implements Disposable { | ||
export declare class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptionalId<T, TPrimaryKey>> extends EventHub<'onEntityAdded' | 'onEntityUpdated' | 'onEntityRemoved', { | ||
onEntityAdded: { | ||
injector: Injector; | ||
entity: T; | ||
}; | ||
onEntityUpdated: { | ||
injector: Injector; | ||
id: T[TPrimaryKey]; | ||
change: Partial<T>; | ||
}; | ||
onEntityRemoved: { | ||
injector: Injector; | ||
key: T[TPrimaryKey]; | ||
}; | ||
}> implements Disposable { | ||
readonly settings: DataSetSettings<T, TPrimaryKey, TWritableData>; | ||
@@ -25,9 +39,2 @@ dispose(): void; | ||
/** | ||
* Observable that will be updated after the entity has been persisted | ||
*/ | ||
readonly onEntityAdded: ObservableValue<{ | ||
injector: Injector; | ||
entity: T; | ||
}>; | ||
/** | ||
* Updates an entity in the store | ||
@@ -40,10 +47,2 @@ * @param injector The injector from the context | ||
/** | ||
* Observable that will be updated right after an entity update | ||
*/ | ||
readonly onEntityUpdated: ObservableValue<{ | ||
injector: Injector; | ||
id: T[keyof T]; | ||
change: Partial<T>; | ||
}>; | ||
/** | ||
* Returns a Promise with the entity count | ||
@@ -77,11 +76,4 @@ * @param injector The Injector from the context | ||
remove(injector: Injector, key: T[TPrimaryKey]): Promise<void>; | ||
/** | ||
* Callback that fires right after entity update | ||
*/ | ||
readonly onEntityRemoved: ObservableValue<{ | ||
injector: Injector; | ||
key: T[TPrimaryKey]; | ||
}>; | ||
constructor(settings: DataSetSettings<T, TPrimaryKey, TWritableData>); | ||
} | ||
//# sourceMappingURL=data-set.d.ts.map |
import { AuthorizationError } from '@furystack/core'; | ||
import { ObservableValue } from '@furystack/utils'; | ||
import { EventHub } from '@furystack/utils'; | ||
/** | ||
* An authorized Repository Store instance | ||
*/ | ||
export class DataSet { | ||
export class DataSet extends EventHub { | ||
settings; | ||
dispose() { | ||
this.onEntityAdded.dispose(); | ||
this.onEntityRemoved.dispose(); | ||
this.onEntityUpdated.dispose(); | ||
super.dispose(); | ||
} | ||
@@ -36,10 +34,8 @@ /** | ||
const createResult = await this.settings.physicalStore.add(...parsed); | ||
createResult.created.map((entity) => this.onEntityAdded.setValue({ injector, entity })); | ||
createResult.created.map((entity) => { | ||
this.emit('onEntityAdded', { injector, entity }); | ||
}); | ||
return createResult; | ||
} | ||
/** | ||
* Observable that will be updated after the entity has been persisted | ||
*/ | ||
onEntityAdded = new ObservableValue(); | ||
/** | ||
* Updates an entity in the store | ||
@@ -70,9 +66,5 @@ * @param injector The injector from the context | ||
await this.settings.physicalStore.update(id, parsed); | ||
this.onEntityUpdated.setValue({ injector, change: parsed, id }); | ||
this.emit('onEntityUpdated', { injector, change: parsed, id }); | ||
} | ||
/** | ||
* Observable that will be updated right after an entity update | ||
*/ | ||
onEntityUpdated = new ObservableValue(); | ||
/** | ||
* Returns a Promise with the entity count | ||
@@ -154,9 +146,6 @@ * @param injector The Injector from the context | ||
await this.settings.physicalStore.remove(key); | ||
this.onEntityRemoved.setValue({ injector, key }); | ||
this.emit('onEntityRemoved', { injector, key }); | ||
} | ||
/** | ||
* Callback that fires right after entity update | ||
*/ | ||
onEntityRemoved = new ObservableValue(); | ||
constructor(settings) { | ||
super(); | ||
this.settings = settings; | ||
@@ -163,0 +152,0 @@ this.primaryKey = this.settings.physicalStore.primaryKey; |
@@ -117,3 +117,3 @@ import { Injector } from '@furystack/inject'; | ||
.getDataSetFor(TestClass, 'id') | ||
.onEntityAdded.subscribe(({ entity }) => { | ||
.subscribe('onEntityAdded', ({ entity }) => { | ||
expect(entity.value).toBe('asd'); | ||
@@ -225,3 +225,3 @@ }); | ||
.getDataSetFor(TestClass, 'id') | ||
.onEntityUpdated.subscribe(({ change }) => { | ||
.subscribe('onEntityUpdated', ({ change }) => { | ||
expect(change).toEqual({ id: 1, value: 'asd2' }); | ||
@@ -459,3 +459,3 @@ }); | ||
.getDataSetFor(TestClass, 'id') | ||
.onEntityRemoved.subscribe(({ key }) => { | ||
.subscribe('onEntityRemoved', ({ key }) => { | ||
expect(key).toEqual(1); | ||
@@ -462,0 +462,0 @@ }); |
{ | ||
"name": "@furystack/repository", | ||
"version": "7.0.18", | ||
"version": "8.0.0", | ||
"description": "Repository implementation for FuryStack", | ||
@@ -40,11 +40,11 @@ "type": "module", | ||
"dependencies": { | ||
"@furystack/core": "^12.0.18", | ||
"@furystack/inject": "^8.1.8", | ||
"@furystack/utils": "^4.0.17" | ||
"@furystack/core": "^13.0.0", | ||
"@furystack/inject": "^9.0.0", | ||
"@furystack/utils": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.4.2", | ||
"vitest": "^1.3.1" | ||
"vitest": "^1.4.0" | ||
}, | ||
"gitHead": "1045d854bfd8c475b7035471d130d401417a2321" | ||
} |
@@ -6,3 +6,3 @@ import type { Injector } from '@furystack/inject' | ||
import type { Disposable } from '@furystack/utils' | ||
import { ObservableValue } from '@furystack/utils' | ||
import { EventHub } from '@furystack/utils' | ||
@@ -13,8 +13,14 @@ /** | ||
export class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptionalId<T, TPrimaryKey>> | ||
extends EventHub< | ||
'onEntityAdded' | 'onEntityUpdated' | 'onEntityRemoved', | ||
{ | ||
onEntityAdded: { injector: Injector; entity: T } | ||
onEntityUpdated: { injector: Injector; id: T[TPrimaryKey]; change: Partial<T> } | ||
onEntityRemoved: { injector: Injector; key: T[TPrimaryKey] } | ||
} | ||
> | ||
implements Disposable | ||
{ | ||
public dispose() { | ||
this.onEntityAdded.dispose() | ||
this.onEntityRemoved.dispose() | ||
this.onEntityUpdated.dispose() | ||
super.dispose() | ||
} | ||
@@ -52,3 +58,5 @@ | ||
const createResult = await this.settings.physicalStore.add(...parsed) | ||
createResult.created.map((entity) => this.onEntityAdded.setValue({ injector, entity })) | ||
createResult.created.map((entity) => { | ||
this.emit('onEntityAdded', { injector, entity }) | ||
}) | ||
return createResult | ||
@@ -58,7 +66,2 @@ } | ||
/** | ||
* Observable that will be updated after the entity has been persisted | ||
*/ | ||
public readonly onEntityAdded = new ObservableValue<{ injector: Injector; entity: T }>() | ||
/** | ||
* Updates an entity in the store | ||
@@ -89,11 +92,6 @@ * @param injector The injector from the context | ||
await this.settings.physicalStore.update(id, parsed) | ||
this.onEntityUpdated.setValue({ injector, change: parsed, id }) | ||
this.emit('onEntityUpdated', { injector, change: parsed, id }) | ||
} | ||
/** | ||
* Observable that will be updated right after an entity update | ||
*/ | ||
public readonly onEntityUpdated = new ObservableValue<{ injector: Injector; id: T[keyof T]; change: Partial<T> }>() | ||
/** | ||
* Returns a Promise with the entity count | ||
@@ -181,16 +179,9 @@ * @param injector The Injector from the context | ||
await this.settings.physicalStore.remove(key) | ||
this.onEntityRemoved.setValue({ injector, key }) | ||
this.emit('onEntityRemoved', { injector, key }) | ||
} | ||
/** | ||
* Callback that fires right after entity update | ||
*/ | ||
public readonly onEntityRemoved = new ObservableValue<{ | ||
injector: Injector | ||
key: T[TPrimaryKey] | ||
}>() | ||
constructor(public readonly settings: DataSetSettings<T, TPrimaryKey, TWritableData>) { | ||
super() | ||
this.primaryKey = this.settings.physicalStore.primaryKey | ||
} | ||
} |
@@ -148,3 +148,3 @@ import { Injector } from '@furystack/inject' | ||
.getDataSetFor(TestClass, 'id') | ||
.onEntityAdded.subscribe(({ entity }) => { | ||
.subscribe('onEntityAdded', ({ entity }) => { | ||
expect(entity.value).toBe('asd') | ||
@@ -269,3 +269,3 @@ }) | ||
.getDataSetFor(TestClass, 'id') | ||
.onEntityUpdated.subscribe(({ change }) => { | ||
.subscribe('onEntityUpdated', ({ change }) => { | ||
expect(change).toEqual({ id: 1, value: 'asd2' }) | ||
@@ -530,3 +530,3 @@ }) | ||
.getDataSetFor(TestClass, 'id') | ||
.onEntityRemoved.subscribe(({ key }) => { | ||
.subscribe('onEntityRemoved', ({ key }) => { | ||
expect(key).toEqual(1) | ||
@@ -533,0 +533,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144073
1720
+ Added@furystack/core@13.0.0(transitive)
+ Added@furystack/inject@9.0.0(transitive)
+ Added@furystack/utils@5.0.0(transitive)
- Removed@furystack/core@12.0.18(transitive)
- Removed@furystack/inject@8.1.8(transitive)
- Removed@furystack/utils@4.0.17(transitive)
Updated@furystack/core@^13.0.0
Updated@furystack/inject@^9.0.0
Updated@furystack/utils@^5.0.0