@furystack/repository 7.0.0 → 7.0.1
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/esm/data-set-setting.js +2 -0
- package/esm/data-set-setting.js.map +1 -0
- package/esm/data-set.js +161 -0
- package/esm/data-set.js.map +1 -0
- package/esm/helpers.js +16 -0
- package/esm/helpers.js.map +1 -0
- package/esm/index.js +5 -0
- package/esm/index.js.map +1 -0
- package/esm/repository.js +52 -0
- package/esm/repository.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-set-setting.js","sourceRoot":"","sources":["../src/data-set-setting.ts"],"names":[],"mappings":""}
|
package/esm/data-set.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { AuthorizationError } from '@furystack/core';
|
|
2
|
+
import { ObservableValue } from '@furystack/utils';
|
|
3
|
+
/**
|
|
4
|
+
* An authorized Repository Store instance
|
|
5
|
+
*/
|
|
6
|
+
export class DataSet {
|
|
7
|
+
dispose() {
|
|
8
|
+
this.onEntityAdded.dispose();
|
|
9
|
+
this.onEntityRemoved.dispose();
|
|
10
|
+
this.onEntityUpdated.dispose();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Adds an entity to the DataSet
|
|
14
|
+
* @param injector The injector from the context
|
|
15
|
+
* @param entities The entities to add
|
|
16
|
+
* @returns The CreateResult with the created entities
|
|
17
|
+
*/
|
|
18
|
+
async add(injector, ...entities) {
|
|
19
|
+
await Promise.all(entities.map(async (entity) => {
|
|
20
|
+
if (this.settings.authorizeAdd) {
|
|
21
|
+
const result = await this.settings.authorizeAdd({ injector, entity });
|
|
22
|
+
if (!result.isAllowed) {
|
|
23
|
+
throw new AuthorizationError(result.message);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}));
|
|
27
|
+
const parsed = await Promise.all(entities.map(async (entity) => {
|
|
28
|
+
return this.settings.modifyOnAdd ? await this.settings.modifyOnAdd({ injector, entity }) : entity;
|
|
29
|
+
}));
|
|
30
|
+
const createResult = await this.settings.physicalStore.add(...parsed);
|
|
31
|
+
createResult.created.map((entity) => this.onEntityAdded.setValue({ injector, entity }));
|
|
32
|
+
return createResult;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Updates an entity in the store
|
|
36
|
+
* @param injector The injector from the context
|
|
37
|
+
* @param id The identifier of the entity
|
|
38
|
+
* @param change The update
|
|
39
|
+
*/
|
|
40
|
+
async update(injector, id, change) {
|
|
41
|
+
if (this.settings.authorizeUpdate) {
|
|
42
|
+
const result = await this.settings.authorizeUpdate({ injector, change });
|
|
43
|
+
if (!result.isAllowed) {
|
|
44
|
+
throw new AuthorizationError(result.message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (this.settings.authorizeUpdateEntity) {
|
|
48
|
+
const entity = await this.settings.physicalStore.get(id);
|
|
49
|
+
if (entity) {
|
|
50
|
+
const result = await this.settings.authorizeUpdateEntity({ injector, change, entity });
|
|
51
|
+
if (!result.isAllowed) {
|
|
52
|
+
throw new AuthorizationError(result.message);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const parsed = this.settings.modifyOnUpdate
|
|
57
|
+
? await this.settings.modifyOnUpdate({ injector, id, entity: change })
|
|
58
|
+
: change;
|
|
59
|
+
await this.settings.physicalStore.update(id, parsed);
|
|
60
|
+
this.onEntityUpdated.setValue({ injector, change: parsed, id });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns a Promise with the entity count
|
|
64
|
+
* @param injector The Injector from the context
|
|
65
|
+
* @param filter The Filter that will be applied
|
|
66
|
+
* @returns the Count
|
|
67
|
+
*/
|
|
68
|
+
async count(injector, filter) {
|
|
69
|
+
if (this.settings.authorizeGet) {
|
|
70
|
+
const result = await this.settings.authorizeGet({ injector });
|
|
71
|
+
if (!result.isAllowed) {
|
|
72
|
+
throw new AuthorizationError(result.message);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return await this.settings.physicalStore.count(filter);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns a filtered subset of the entity
|
|
79
|
+
* @param injector The Injector from the context
|
|
80
|
+
* @param filter The Filter definition
|
|
81
|
+
* @returns A result with the current items
|
|
82
|
+
*/
|
|
83
|
+
async find(injector, filter) {
|
|
84
|
+
if (this.settings.authorizeGet) {
|
|
85
|
+
const result = await this.settings.authorizeGet({ injector });
|
|
86
|
+
if (!result.isAllowed) {
|
|
87
|
+
throw new AuthorizationError(result.message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const parsedFilter = this.settings.addFilter ? await this.settings.addFilter({ injector, filter }) : filter;
|
|
91
|
+
return this.settings.physicalStore.find(parsedFilter);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns an entity based on its primary key
|
|
95
|
+
* @param injector The injector from the context
|
|
96
|
+
* @param key The identifier of the entity
|
|
97
|
+
* @param select A field list used for projection
|
|
98
|
+
* @returns An item with the current unique key or Undefined
|
|
99
|
+
*/
|
|
100
|
+
async get(injector, key, select) {
|
|
101
|
+
if (this.settings.authorizeGet) {
|
|
102
|
+
const result = await this.settings.authorizeGet({ injector });
|
|
103
|
+
if (!result.isAllowed) {
|
|
104
|
+
throw new AuthorizationError(result.message);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const instance = await this.settings.physicalStore.get(key, select);
|
|
108
|
+
if (instance && this.settings && this.settings.authorizeGetEntity) {
|
|
109
|
+
const result = await this.settings.authorizeGetEntity({ injector, entity: instance });
|
|
110
|
+
if (!result.isAllowed) {
|
|
111
|
+
throw new AuthorizationError(result.message);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return instance;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Removes an entity based on its primary key
|
|
118
|
+
* @param injector The Injector from the context
|
|
119
|
+
* @param key The primary key
|
|
120
|
+
* @returns A promise that will be resolved / rejected based on the remove success
|
|
121
|
+
*/
|
|
122
|
+
async remove(injector, key) {
|
|
123
|
+
if (this.settings.authorizeRemove) {
|
|
124
|
+
const result = await this.settings.authorizeRemove({ injector });
|
|
125
|
+
if (!result.isAllowed) {
|
|
126
|
+
throw new AuthorizationError(result.message);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (this.settings.authroizeRemoveEntity) {
|
|
130
|
+
const entity = await this.settings.physicalStore.get(key);
|
|
131
|
+
if (entity) {
|
|
132
|
+
const removeResult = await this.settings.authroizeRemoveEntity({ injector, entity });
|
|
133
|
+
if (!removeResult.isAllowed) {
|
|
134
|
+
throw new AuthorizationError(removeResult.message);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
await this.settings.physicalStore.remove(key);
|
|
139
|
+
this.onEntityRemoved.setValue({ injector, key });
|
|
140
|
+
}
|
|
141
|
+
constructor(settings) {
|
|
142
|
+
this.settings = settings;
|
|
143
|
+
/**
|
|
144
|
+
* Primary key of the contained entity
|
|
145
|
+
*/
|
|
146
|
+
this.primaryKey = this.settings.physicalStore.primaryKey;
|
|
147
|
+
/**
|
|
148
|
+
* Observable that will be updated after the entity has been persisted
|
|
149
|
+
*/
|
|
150
|
+
this.onEntityAdded = new ObservableValue();
|
|
151
|
+
/**
|
|
152
|
+
* Observable that will be updated right after an entity update
|
|
153
|
+
*/
|
|
154
|
+
this.onEntityUpdated = new ObservableValue();
|
|
155
|
+
/**
|
|
156
|
+
* Callback that fires right after entity update
|
|
157
|
+
*/
|
|
158
|
+
this.onEntityRemoved = new ObservableValue();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=data-set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-set.js","sourceRoot":"","sources":["../src/data-set.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AA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AY,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAA;gBACpF,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE;oBAC3B,MAAM,IAAI,kBAAkB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;iBACnD;aACF;SACF;QACD,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC7C,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAA;IAClD,CAAC;IAUD,YAA4B,QAAwD;QAAxD,aAAQ,GAAR,QAAQ,CAAgD;QAvKpF;;WAEG;QACI,eAAU,GAAgB,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAA;QA+BvE;;WAEG;QACa,kBAAa,GAAG,IAAI,eAAe,EAAqC,CAAA;QA+BxF;;WAEG;QACa,oBAAe,GAAG,IAAI,eAAe,EAA8D,CAAA;QAwFnH;;WAEG;QACa,oBAAe,GAAG,IAAI,eAAe,EAGjD,CAAA;IAEmF,CAAC;CACzF"}
|
package/esm/helpers.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Repository } from './repository';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a Repository on an injector
|
|
4
|
+
* @param injector The Injector instance
|
|
5
|
+
* @returns The Repository instance
|
|
6
|
+
*/
|
|
7
|
+
export const getRepository = (injector) => injector.getInstance(Repository);
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param injector The Injector instance
|
|
11
|
+
* @param model The Model
|
|
12
|
+
* @param primaryKey The Primary Key field
|
|
13
|
+
* @returns A Repository DataSet for a specific model
|
|
14
|
+
*/
|
|
15
|
+
export const getDataSetFor = (injector, model, primaryKey) => injector.getInstance(Repository).getDataSetFor(model, primaryKey);
|
|
16
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAA;AAErF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,QAAkB,EAClB,KAAuB,EACvB,UAAuB,EACvB,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA"}
|
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { StoreManager } from '@furystack/core';
|
|
11
|
+
import { Injectable, Injected } from '@furystack/inject';
|
|
12
|
+
import { DataSet } from './data-set';
|
|
13
|
+
/**
|
|
14
|
+
* Collection of authorized physical stores
|
|
15
|
+
*/
|
|
16
|
+
let Repository = class Repository {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.dataSets = new Map();
|
|
19
|
+
}
|
|
20
|
+
dispose() {
|
|
21
|
+
this.dataSets.forEach((ds) => ds.dispose());
|
|
22
|
+
this.dataSets.clear();
|
|
23
|
+
}
|
|
24
|
+
getDataSetFor(model, primaryKey) {
|
|
25
|
+
const instance = this.dataSets.get(model);
|
|
26
|
+
if (!instance) {
|
|
27
|
+
throw Error(`No DataSet found for '${model}'`);
|
|
28
|
+
}
|
|
29
|
+
if (instance.primaryKey !== primaryKey) {
|
|
30
|
+
throw Error('Primary key mismatch');
|
|
31
|
+
}
|
|
32
|
+
return instance;
|
|
33
|
+
}
|
|
34
|
+
createDataSet(model, primaryKey, settings) {
|
|
35
|
+
const physicalStore = (settings && settings.physicalStore) || this.storeManager.getStoreFor(model, primaryKey);
|
|
36
|
+
const instance = new DataSet({
|
|
37
|
+
...settings,
|
|
38
|
+
physicalStore,
|
|
39
|
+
});
|
|
40
|
+
this.dataSets.set(model, instance);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
__decorate([
|
|
45
|
+
Injected(StoreManager),
|
|
46
|
+
__metadata("design:type", StoreManager)
|
|
47
|
+
], Repository.prototype, "storeManager", void 0);
|
|
48
|
+
Repository = __decorate([
|
|
49
|
+
Injectable({ lifetime: 'singleton' })
|
|
50
|
+
], Repository);
|
|
51
|
+
export { Repository };
|
|
52
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../src/repository.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,C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;AApCjC,UAAU;IADtB,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,UAAU,CAqCtB;SArCY,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/repository",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Repository implementation for FuryStack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
|
-
"
|
|
24
|
+
"esm",
|
|
25
25
|
"types",
|
|
26
26
|
"src"
|
|
27
27
|
],
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://github.com/furystack/furystack",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@furystack/core": "^12.0.
|
|
50
|
-
"@furystack/inject": "^8.0.
|
|
51
|
-
"@furystack/utils": "^4.0.
|
|
49
|
+
"@furystack/core": "^12.0.1",
|
|
50
|
+
"@furystack/inject": "^8.0.1",
|
|
51
|
+
"@furystack/utils": "^4.0.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"typescript": "^5.0.4",
|