@furystack/repository 6.1.17 → 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/{dist → esm}/data-set.js +15 -25
- 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/{dist → esm}/repository.js +8 -11
- package/esm/repository.js.map +1 -0
- package/package.json +25 -8
- package/src/data-set.ts +0 -6
- package/src/dataset.spec.ts +21 -22
- package/src/helpers.ts +0 -1
- package/src/repository.spec.ts +1 -0
- package/types/data-set.d.ts +0 -6
- package/types/data-set.d.ts.map +1 -1
- package/types/helpers.d.ts +0 -1
- package/types/helpers.d.ts.map +1 -1
- package/dist/data-set-setting.js +0 -3
- package/dist/data-set.js.map +0 -1
- package/dist/dataset.spec.js +0 -463
- package/dist/dataset.spec.js.map +0 -1
- package/dist/helpers.js +0 -22
- package/dist/helpers.js.map +0 -1
- package/dist/index.js +0 -21
- package/dist/index.js.map +0 -1
- package/dist/repository.js.map +0 -1
- package/dist/repository.spec.js +0 -20
- package/dist/repository.spec.js.map +0 -1
- package/types/dataset.spec.d.ts +0 -2
- package/types/dataset.spec.d.ts.map +0 -1
- package/types/repository.spec.d.ts +0 -2
- package/types/repository.spec.d.ts.map +0 -1
- /package/{dist → esm}/data-set-setting.js.map +0 -0
package/{dist → esm}/data-set.js
RENAMED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DataSet = void 0;
|
|
4
|
-
const core_1 = require("@furystack/core");
|
|
5
|
-
const utils_1 = require("@furystack/utils");
|
|
1
|
+
import { AuthorizationError } from '@furystack/core';
|
|
2
|
+
import { ObservableValue } from '@furystack/utils';
|
|
6
3
|
/**
|
|
7
4
|
* An authorized Repository Store instance
|
|
8
5
|
*/
|
|
9
|
-
class DataSet {
|
|
6
|
+
export class DataSet {
|
|
10
7
|
dispose() {
|
|
11
8
|
this.onEntityAdded.dispose();
|
|
12
9
|
this.onEntityRemoved.dispose();
|
|
@@ -14,7 +11,6 @@ class DataSet {
|
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
16
13
|
* Adds an entity to the DataSet
|
|
17
|
-
*
|
|
18
14
|
* @param injector The injector from the context
|
|
19
15
|
* @param entities The entities to add
|
|
20
16
|
* @returns The CreateResult with the created entities
|
|
@@ -24,7 +20,7 @@ class DataSet {
|
|
|
24
20
|
if (this.settings.authorizeAdd) {
|
|
25
21
|
const result = await this.settings.authorizeAdd({ injector, entity });
|
|
26
22
|
if (!result.isAllowed) {
|
|
27
|
-
throw new
|
|
23
|
+
throw new AuthorizationError(result.message);
|
|
28
24
|
}
|
|
29
25
|
}
|
|
30
26
|
}));
|
|
@@ -37,7 +33,6 @@ class DataSet {
|
|
|
37
33
|
}
|
|
38
34
|
/**
|
|
39
35
|
* Updates an entity in the store
|
|
40
|
-
*
|
|
41
36
|
* @param injector The injector from the context
|
|
42
37
|
* @param id The identifier of the entity
|
|
43
38
|
* @param change The update
|
|
@@ -46,7 +41,7 @@ class DataSet {
|
|
|
46
41
|
if (this.settings.authorizeUpdate) {
|
|
47
42
|
const result = await this.settings.authorizeUpdate({ injector, change });
|
|
48
43
|
if (!result.isAllowed) {
|
|
49
|
-
throw new
|
|
44
|
+
throw new AuthorizationError(result.message);
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
47
|
if (this.settings.authorizeUpdateEntity) {
|
|
@@ -54,7 +49,7 @@ class DataSet {
|
|
|
54
49
|
if (entity) {
|
|
55
50
|
const result = await this.settings.authorizeUpdateEntity({ injector, change, entity });
|
|
56
51
|
if (!result.isAllowed) {
|
|
57
|
-
throw new
|
|
52
|
+
throw new AuthorizationError(result.message);
|
|
58
53
|
}
|
|
59
54
|
}
|
|
60
55
|
}
|
|
@@ -66,7 +61,6 @@ class DataSet {
|
|
|
66
61
|
}
|
|
67
62
|
/**
|
|
68
63
|
* Returns a Promise with the entity count
|
|
69
|
-
*
|
|
70
64
|
* @param injector The Injector from the context
|
|
71
65
|
* @param filter The Filter that will be applied
|
|
72
66
|
* @returns the Count
|
|
@@ -75,14 +69,13 @@ class DataSet {
|
|
|
75
69
|
if (this.settings.authorizeGet) {
|
|
76
70
|
const result = await this.settings.authorizeGet({ injector });
|
|
77
71
|
if (!result.isAllowed) {
|
|
78
|
-
throw new
|
|
72
|
+
throw new AuthorizationError(result.message);
|
|
79
73
|
}
|
|
80
74
|
}
|
|
81
75
|
return await this.settings.physicalStore.count(filter);
|
|
82
76
|
}
|
|
83
77
|
/**
|
|
84
78
|
* Returns a filtered subset of the entity
|
|
85
|
-
*
|
|
86
79
|
* @param injector The Injector from the context
|
|
87
80
|
* @param filter The Filter definition
|
|
88
81
|
* @returns A result with the current items
|
|
@@ -91,7 +84,7 @@ class DataSet {
|
|
|
91
84
|
if (this.settings.authorizeGet) {
|
|
92
85
|
const result = await this.settings.authorizeGet({ injector });
|
|
93
86
|
if (!result.isAllowed) {
|
|
94
|
-
throw new
|
|
87
|
+
throw new AuthorizationError(result.message);
|
|
95
88
|
}
|
|
96
89
|
}
|
|
97
90
|
const parsedFilter = this.settings.addFilter ? await this.settings.addFilter({ injector, filter }) : filter;
|
|
@@ -99,7 +92,6 @@ class DataSet {
|
|
|
99
92
|
}
|
|
100
93
|
/**
|
|
101
94
|
* Returns an entity based on its primary key
|
|
102
|
-
*
|
|
103
95
|
* @param injector The injector from the context
|
|
104
96
|
* @param key The identifier of the entity
|
|
105
97
|
* @param select A field list used for projection
|
|
@@ -109,21 +101,20 @@ class DataSet {
|
|
|
109
101
|
if (this.settings.authorizeGet) {
|
|
110
102
|
const result = await this.settings.authorizeGet({ injector });
|
|
111
103
|
if (!result.isAllowed) {
|
|
112
|
-
throw new
|
|
104
|
+
throw new AuthorizationError(result.message);
|
|
113
105
|
}
|
|
114
106
|
}
|
|
115
107
|
const instance = await this.settings.physicalStore.get(key, select);
|
|
116
108
|
if (instance && this.settings && this.settings.authorizeGetEntity) {
|
|
117
109
|
const result = await this.settings.authorizeGetEntity({ injector, entity: instance });
|
|
118
110
|
if (!result.isAllowed) {
|
|
119
|
-
throw new
|
|
111
|
+
throw new AuthorizationError(result.message);
|
|
120
112
|
}
|
|
121
113
|
}
|
|
122
114
|
return instance;
|
|
123
115
|
}
|
|
124
116
|
/**
|
|
125
117
|
* Removes an entity based on its primary key
|
|
126
|
-
*
|
|
127
118
|
* @param injector The Injector from the context
|
|
128
119
|
* @param key The primary key
|
|
129
120
|
* @returns A promise that will be resolved / rejected based on the remove success
|
|
@@ -132,7 +123,7 @@ class DataSet {
|
|
|
132
123
|
if (this.settings.authorizeRemove) {
|
|
133
124
|
const result = await this.settings.authorizeRemove({ injector });
|
|
134
125
|
if (!result.isAllowed) {
|
|
135
|
-
throw new
|
|
126
|
+
throw new AuthorizationError(result.message);
|
|
136
127
|
}
|
|
137
128
|
}
|
|
138
129
|
if (this.settings.authroizeRemoveEntity) {
|
|
@@ -140,7 +131,7 @@ class DataSet {
|
|
|
140
131
|
if (entity) {
|
|
141
132
|
const removeResult = await this.settings.authroizeRemoveEntity({ injector, entity });
|
|
142
133
|
if (!removeResult.isAllowed) {
|
|
143
|
-
throw new
|
|
134
|
+
throw new AuthorizationError(removeResult.message);
|
|
144
135
|
}
|
|
145
136
|
}
|
|
146
137
|
}
|
|
@@ -156,16 +147,15 @@ class DataSet {
|
|
|
156
147
|
/**
|
|
157
148
|
* Observable that will be updated after the entity has been persisted
|
|
158
149
|
*/
|
|
159
|
-
this.onEntityAdded = new
|
|
150
|
+
this.onEntityAdded = new ObservableValue();
|
|
160
151
|
/**
|
|
161
152
|
* Observable that will be updated right after an entity update
|
|
162
153
|
*/
|
|
163
|
-
this.onEntityUpdated = new
|
|
154
|
+
this.onEntityUpdated = new ObservableValue();
|
|
164
155
|
/**
|
|
165
156
|
* Callback that fires right after entity update
|
|
166
157
|
*/
|
|
167
|
-
this.onEntityRemoved = new
|
|
158
|
+
this.onEntityRemoved = new ObservableValue();
|
|
168
159
|
}
|
|
169
160
|
}
|
|
170
|
-
exports.DataSet = DataSet;
|
|
171
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;AAGpD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAElD;;GAEG;AACH,MAAM,OAAO,OAAO;IAGX,OAAO;QACZ,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAA;QAC5B,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAA;QAC9B,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAA;IAChC,CAAC;IAOD;;;;;OAKG;IACI,KAAK,CAAC,GAAG,CAAC,QAAkB,EAAE,GAAG,QAAyB;QAC/D,MAAM,OAAO,CAAC,GAAG,CACf,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAC5B,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;gBAC9B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAA;gBACrE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;oBACrB,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;iBAC7C;aACF;QACH,CAAC,CAAC,CACH,CAAA;QAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAA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,CAAC,SAAS,EAAE;gBACrB,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;aAC7C;SACF;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE;YACvC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACzD,IAAI,MAAM,EAAE;gBACV,MAAM,YAAY,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"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,11 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const inject_1 = require("@furystack/inject");
|
|
15
|
-
const data_set_1 = require("./data-set");
|
|
10
|
+
import { StoreManager } from '@furystack/core';
|
|
11
|
+
import { Injectable, Injected } from '@furystack/inject';
|
|
12
|
+
import { DataSet } from './data-set';
|
|
16
13
|
/**
|
|
17
14
|
* Collection of authorized physical stores
|
|
18
15
|
*/
|
|
@@ -36,7 +33,7 @@ let Repository = class Repository {
|
|
|
36
33
|
}
|
|
37
34
|
createDataSet(model, primaryKey, settings) {
|
|
38
35
|
const physicalStore = (settings && settings.physicalStore) || this.storeManager.getStoreFor(model, primaryKey);
|
|
39
|
-
const instance = new
|
|
36
|
+
const instance = new DataSet({
|
|
40
37
|
...settings,
|
|
41
38
|
physicalStore,
|
|
42
39
|
});
|
|
@@ -45,11 +42,11 @@ let Repository = class Repository {
|
|
|
45
42
|
}
|
|
46
43
|
};
|
|
47
44
|
__decorate([
|
|
48
|
-
|
|
49
|
-
__metadata("design:type",
|
|
45
|
+
Injected(StoreManager),
|
|
46
|
+
__metadata("design:type", StoreManager)
|
|
50
47
|
], Repository.prototype, "storeManager", void 0);
|
|
51
48
|
Repository = __decorate([
|
|
52
|
-
|
|
49
|
+
Injectable({ lifetime: 'singleton' })
|
|
53
50
|
], Repository);
|
|
54
|
-
|
|
51
|
+
export { Repository };
|
|
55
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,CAAA;AAE9C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AU;IADtB,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,UAAU,CAqCtB;SArCY,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/repository",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Repository implementation for FuryStack",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build:es6": "tsc --outDir ./esm"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./esm/index.js",
|
|
12
|
+
"types": "./types/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
"*": [
|
|
19
|
+
"types/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
6
23
|
"files": [
|
|
7
|
-
"
|
|
24
|
+
"esm",
|
|
8
25
|
"types",
|
|
9
26
|
"src"
|
|
10
27
|
],
|
|
@@ -29,13 +46,13 @@
|
|
|
29
46
|
},
|
|
30
47
|
"homepage": "https://github.com/furystack/furystack",
|
|
31
48
|
"dependencies": {
|
|
32
|
-
"@furystack/core": "^
|
|
33
|
-
"@furystack/inject": "^
|
|
34
|
-
"@furystack/utils": "^
|
|
49
|
+
"@furystack/core": "^12.0.1",
|
|
50
|
+
"@furystack/inject": "^8.0.1",
|
|
51
|
+
"@furystack/utils": "^4.0.1"
|
|
35
52
|
},
|
|
36
53
|
"devDependencies": {
|
|
37
|
-
"
|
|
54
|
+
"typescript": "^5.0.4",
|
|
55
|
+
"vitest": "^0.30.1"
|
|
38
56
|
},
|
|
39
|
-
"typings": "./types/index.d.ts",
|
|
40
57
|
"gitHead": "1045d854bfd8c475b7035471d130d401417a2321"
|
|
41
58
|
}
|
package/src/data-set.ts
CHANGED
|
@@ -24,7 +24,6 @@ export class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptiona
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Adds an entity to the DataSet
|
|
27
|
-
*
|
|
28
27
|
* @param injector The injector from the context
|
|
29
28
|
* @param entities The entities to add
|
|
30
29
|
* @returns The CreateResult with the created entities
|
|
@@ -59,7 +58,6 @@ export class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptiona
|
|
|
59
58
|
|
|
60
59
|
/**
|
|
61
60
|
* Updates an entity in the store
|
|
62
|
-
*
|
|
63
61
|
* @param injector The injector from the context
|
|
64
62
|
* @param id The identifier of the entity
|
|
65
63
|
* @param change The update
|
|
@@ -94,7 +92,6 @@ export class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptiona
|
|
|
94
92
|
|
|
95
93
|
/**
|
|
96
94
|
* Returns a Promise with the entity count
|
|
97
|
-
*
|
|
98
95
|
* @param injector The Injector from the context
|
|
99
96
|
* @param filter The Filter that will be applied
|
|
100
97
|
* @returns the Count
|
|
@@ -111,7 +108,6 @@ export class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptiona
|
|
|
111
108
|
|
|
112
109
|
/**
|
|
113
110
|
* Returns a filtered subset of the entity
|
|
114
|
-
*
|
|
115
111
|
* @param injector The Injector from the context
|
|
116
112
|
* @param filter The Filter definition
|
|
117
113
|
* @returns A result with the current items
|
|
@@ -132,7 +128,6 @@ export class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptiona
|
|
|
132
128
|
|
|
133
129
|
/**
|
|
134
130
|
* Returns an entity based on its primary key
|
|
135
|
-
*
|
|
136
131
|
* @param injector The injector from the context
|
|
137
132
|
* @param key The identifier of the entity
|
|
138
133
|
* @param select A field list used for projection
|
|
@@ -157,7 +152,6 @@ export class DataSet<T, TPrimaryKey extends keyof T, TWritableData = WithOptiona
|
|
|
157
152
|
|
|
158
153
|
/**
|
|
159
154
|
* Removes an entity based on its primary key
|
|
160
|
-
*
|
|
161
155
|
* @param injector The Injector from the context
|
|
162
156
|
* @param key The primary key
|
|
163
157
|
* @returns A promise that will be resolved / rejected based on the remove success
|
package/src/dataset.spec.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { InMemoryStore, addStore } from '@furystack/core'
|
|
|
5
5
|
import { Repository } from './repository'
|
|
6
6
|
import type { AuthorizationResult, DataSetSettings } from './data-set-setting'
|
|
7
7
|
import { getDataSetFor, getRepository } from './helpers'
|
|
8
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
8
9
|
|
|
9
10
|
class TestClass {
|
|
10
11
|
public id = 1
|
|
@@ -73,7 +74,7 @@ describe('DataSet', () => {
|
|
|
73
74
|
|
|
74
75
|
it('should call the add async authorizer and add the entity on pass', async () => {
|
|
75
76
|
await usingAsync(new Injector(), async (i) => {
|
|
76
|
-
const authorizeAdd =
|
|
77
|
+
const authorizeAdd = vi.fn(async () => ({ isAllowed: true } as AuthorizationResult))
|
|
77
78
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
78
79
|
|
|
79
80
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeAdd })
|
|
@@ -87,7 +88,7 @@ describe('DataSet', () => {
|
|
|
87
88
|
|
|
88
89
|
it('should throw if the add authorizer returns a non-valid result and should not add a value to the store', async () => {
|
|
89
90
|
await usingAsync(new Injector(), async (i) => {
|
|
90
|
-
const authorizeAdd =
|
|
91
|
+
const authorizeAdd = vi.fn(async () => ({ isAllowed: false, message: '...' } as AuthorizationResult))
|
|
91
92
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
92
93
|
|
|
93
94
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeAdd })
|
|
@@ -108,7 +109,7 @@ describe('DataSet', () => {
|
|
|
108
109
|
|
|
109
110
|
it('should modify an entity on add, if modifyOnAdd is provided', async () => {
|
|
110
111
|
await usingAsync(new Injector(), async (i) => {
|
|
111
|
-
const modifyOnAdd =
|
|
112
|
+
const modifyOnAdd = vi.fn(
|
|
112
113
|
async (options: { injector: Injector; entity: WithOptionalId<TestClass, 'id'> }) => ({
|
|
113
114
|
...options.entity,
|
|
114
115
|
value: options.entity.value.toUpperCase(),
|
|
@@ -161,7 +162,7 @@ describe('DataSet', () => {
|
|
|
161
162
|
|
|
162
163
|
it('should call the authorizeUpdate authorizer and add the entity on pass', async () => {
|
|
163
164
|
await usingAsync(new Injector(), async (i) => {
|
|
164
|
-
const authorizeUpdate =
|
|
165
|
+
const authorizeUpdate = vi.fn(async () => ({ isAllowed: true } as AuthorizationResult))
|
|
165
166
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
166
167
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeUpdate })
|
|
167
168
|
const dataSet = getDataSetFor(i, TestClass, 'id')
|
|
@@ -175,9 +176,7 @@ describe('DataSet', () => {
|
|
|
175
176
|
|
|
176
177
|
it('should throw if the authorizeUpdateEntity returns a non-valid result and should not update a value to the store', async () => {
|
|
177
178
|
await usingAsync(new Injector(), async (i) => {
|
|
178
|
-
const authorizeUpdateEntity =
|
|
179
|
-
async () => ({ isAllowed: false, message: '...' } as AuthorizationResult),
|
|
180
|
-
)
|
|
179
|
+
const authorizeUpdateEntity = vi.fn(async () => ({ isAllowed: false, message: '...' } as AuthorizationResult))
|
|
181
180
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
182
181
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeUpdateEntity })
|
|
183
182
|
|
|
@@ -197,7 +196,7 @@ describe('DataSet', () => {
|
|
|
197
196
|
})
|
|
198
197
|
it('should call the authorizeUpdateEntity authorizer and add the entity on pass', async () => {
|
|
199
198
|
await usingAsync(new Injector(), async (i) => {
|
|
200
|
-
const authorizeUpdateEntity =
|
|
199
|
+
const authorizeUpdateEntity = vi.fn(async () => ({ isAllowed: true } as AuthorizationResult))
|
|
201
200
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
202
201
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeUpdateEntity })
|
|
203
202
|
const dataSet = getDataSetFor(i, TestClass, 'id')
|
|
@@ -211,7 +210,7 @@ describe('DataSet', () => {
|
|
|
211
210
|
|
|
212
211
|
it('should throw if the authorizeUpdate returns a non-valid result and should not update a value to the store', async () => {
|
|
213
212
|
await usingAsync(new Injector(), async (i) => {
|
|
214
|
-
const authorizeUpdate =
|
|
213
|
+
const authorizeUpdate = vi.fn(async () => ({ isAllowed: false, message: '...' } as AuthorizationResult))
|
|
215
214
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
216
215
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeUpdate })
|
|
217
216
|
|
|
@@ -232,7 +231,7 @@ describe('DataSet', () => {
|
|
|
232
231
|
|
|
233
232
|
it('should modify an entity on update, if modifyOnAdd is provided', async () => {
|
|
234
233
|
await usingAsync(new Injector(), async (i) => {
|
|
235
|
-
const modifyOnUpdate: DataSetSettings<TestClass, 'id'>['modifyOnUpdate'] =
|
|
234
|
+
const modifyOnUpdate: DataSetSettings<TestClass, 'id'>['modifyOnUpdate'] = vi.fn(async (options) => ({
|
|
236
235
|
...options.entity,
|
|
237
236
|
value: options.entity.value?.toUpperCase(),
|
|
238
237
|
}))
|
|
@@ -283,7 +282,7 @@ describe('DataSet', () => {
|
|
|
283
282
|
|
|
284
283
|
it('should return the count if authorizeGet returns valid result', async () => {
|
|
285
284
|
await usingAsync(new Injector(), async (i) => {
|
|
286
|
-
const authorizeGet =
|
|
285
|
+
const authorizeGet = vi.fn(async () => ({ isAllowed: true, message: '' }))
|
|
287
286
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
288
287
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeGet })
|
|
289
288
|
|
|
@@ -296,7 +295,7 @@ describe('DataSet', () => {
|
|
|
296
295
|
|
|
297
296
|
it('should throw if authorizeGet returns invalid result', async () => {
|
|
298
297
|
await usingAsync(new Injector(), async (i) => {
|
|
299
|
-
const authorizeGet =
|
|
298
|
+
const authorizeGet = vi.fn(async () => ({ isAllowed: false, message: ':(' }))
|
|
300
299
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
301
300
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeGet })
|
|
302
301
|
|
|
@@ -328,7 +327,7 @@ describe('DataSet', () => {
|
|
|
328
327
|
|
|
329
328
|
it('should return the unfiltered result if authorizeGet returns valid result', async () => {
|
|
330
329
|
await usingAsync(new Injector(), async (i) => {
|
|
331
|
-
const authorizeGet =
|
|
330
|
+
const authorizeGet = vi.fn(async () => ({ isAllowed: true, message: '' }))
|
|
332
331
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
333
332
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeGet })
|
|
334
333
|
|
|
@@ -341,7 +340,7 @@ describe('DataSet', () => {
|
|
|
341
340
|
|
|
342
341
|
it('should throw if authorizeGet returns invalid result', async () => {
|
|
343
342
|
await usingAsync(new Injector(), async (i) => {
|
|
344
|
-
const authorizeGet =
|
|
343
|
+
const authorizeGet = vi.fn(async () => ({ isAllowed: false, message: ':(' }))
|
|
345
344
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
346
345
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeGet })
|
|
347
346
|
|
|
@@ -372,7 +371,7 @@ describe('DataSet', () => {
|
|
|
372
371
|
|
|
373
372
|
it('should return the entity if authorizeGet returns valid result', async () => {
|
|
374
373
|
await usingAsync(new Injector(), async (i) => {
|
|
375
|
-
const authorizeGet =
|
|
374
|
+
const authorizeGet = vi.fn(async () => ({ isAllowed: true, message: '' }))
|
|
376
375
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
377
376
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeGet })
|
|
378
377
|
|
|
@@ -385,7 +384,7 @@ describe('DataSet', () => {
|
|
|
385
384
|
|
|
386
385
|
it('should throw if authorizeGet returns invalid result', async () => {
|
|
387
386
|
await usingAsync(new Injector(), async (i) => {
|
|
388
|
-
const authorizeGet =
|
|
387
|
+
const authorizeGet = vi.fn(async () => ({ isAllowed: false, message: ':(' }))
|
|
389
388
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
390
389
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeGet })
|
|
391
390
|
|
|
@@ -402,7 +401,7 @@ describe('DataSet', () => {
|
|
|
402
401
|
|
|
403
402
|
it('should return the entity if authorizeGetEntity returns valid result', async () => {
|
|
404
403
|
await usingAsync(new Injector(), async (i) => {
|
|
405
|
-
const authorizeGetEntity =
|
|
404
|
+
const authorizeGetEntity = vi.fn(async () => ({ isAllowed: true, message: '' }))
|
|
406
405
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
407
406
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeGetEntity })
|
|
408
407
|
|
|
@@ -415,7 +414,7 @@ describe('DataSet', () => {
|
|
|
415
414
|
|
|
416
415
|
it('should throw if authorizeGetEntity returns invalid result', async () => {
|
|
417
416
|
await usingAsync(new Injector(), async (i) => {
|
|
418
|
-
const authorizeGetEntity =
|
|
417
|
+
const authorizeGetEntity = vi.fn(async () => ({ isAllowed: false, message: ':(' }))
|
|
419
418
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
420
419
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeGetEntity })
|
|
421
420
|
|
|
@@ -446,7 +445,7 @@ describe('DataSet', () => {
|
|
|
446
445
|
|
|
447
446
|
it('should remove the entity if authorizeRemove returns valid result', async () => {
|
|
448
447
|
await usingAsync(new Injector(), async (i) => {
|
|
449
|
-
const authorizeRemove =
|
|
448
|
+
const authorizeRemove = vi.fn(async () => ({ isAllowed: true, message: '' }))
|
|
450
449
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
451
450
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeRemove })
|
|
452
451
|
|
|
@@ -460,7 +459,7 @@ describe('DataSet', () => {
|
|
|
460
459
|
|
|
461
460
|
it('should throw if authorizeRemove returns invalid result', async () => {
|
|
462
461
|
await usingAsync(new Injector(), async (i) => {
|
|
463
|
-
const authorizeRemove =
|
|
462
|
+
const authorizeRemove = vi.fn(async () => ({ isAllowed: false, message: ':(' }))
|
|
464
463
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
465
464
|
getRepository(i).createDataSet(TestClass, 'id', { authorizeRemove })
|
|
466
465
|
|
|
@@ -479,7 +478,7 @@ describe('DataSet', () => {
|
|
|
479
478
|
|
|
480
479
|
it('should remove the entity if authroizeRemoveEntity returns valid result', async () => {
|
|
481
480
|
await usingAsync(new Injector(), async (i) => {
|
|
482
|
-
const authroizeRemoveEntity =
|
|
481
|
+
const authroizeRemoveEntity = vi.fn(async () => ({ isAllowed: true, message: '' }))
|
|
483
482
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
484
483
|
getRepository(i).createDataSet(TestClass, 'id', { authroizeRemoveEntity })
|
|
485
484
|
|
|
@@ -493,7 +492,7 @@ describe('DataSet', () => {
|
|
|
493
492
|
|
|
494
493
|
it('should throw if authroizeRemoveEntity returns invalid result', async () => {
|
|
495
494
|
await usingAsync(new Injector(), async (i) => {
|
|
496
|
-
const authroizeRemoveEntity =
|
|
495
|
+
const authroizeRemoveEntity = vi.fn(async () => ({ isAllowed: false, message: ':(' }))
|
|
497
496
|
addStore(i, new InMemoryStore({ model: TestClass, primaryKey: 'id' }))
|
|
498
497
|
getRepository(i).createDataSet(TestClass, 'id', { authroizeRemoveEntity })
|
|
499
498
|
|
package/src/helpers.ts
CHANGED
package/src/repository.spec.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { using } from '@furystack/utils'
|
|
|
3
3
|
import { getDataSetFor, getRepository } from './helpers'
|
|
4
4
|
import { addStore, InMemoryStore } from '@furystack/core'
|
|
5
5
|
import { DataSet } from './data-set'
|
|
6
|
+
import { describe, it, expect } from 'vitest'
|
|
6
7
|
|
|
7
8
|
describe('Repository', () => {
|
|
8
9
|
it('Should retrieve a dataSet', () => {
|
package/types/data-set.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export declare class DataSet<T, TPrimaryKey extends keyof T, TWritableData = Wit
|
|
|
15
15
|
primaryKey: TPrimaryKey;
|
|
16
16
|
/**
|
|
17
17
|
* Adds an entity to the DataSet
|
|
18
|
-
*
|
|
19
18
|
* @param injector The injector from the context
|
|
20
19
|
* @param entities The entities to add
|
|
21
20
|
* @returns The CreateResult with the created entities
|
|
@@ -30,7 +29,6 @@ export declare class DataSet<T, TPrimaryKey extends keyof T, TWritableData = Wit
|
|
|
30
29
|
}>;
|
|
31
30
|
/**
|
|
32
31
|
* Updates an entity in the store
|
|
33
|
-
*
|
|
34
32
|
* @param injector The injector from the context
|
|
35
33
|
* @param id The identifier of the entity
|
|
36
34
|
* @param change The update
|
|
@@ -46,7 +44,6 @@ export declare class DataSet<T, TPrimaryKey extends keyof T, TWritableData = Wit
|
|
|
46
44
|
}>;
|
|
47
45
|
/**
|
|
48
46
|
* Returns a Promise with the entity count
|
|
49
|
-
*
|
|
50
47
|
* @param injector The Injector from the context
|
|
51
48
|
* @param filter The Filter that will be applied
|
|
52
49
|
* @returns the Count
|
|
@@ -54,7 +51,6 @@ export declare class DataSet<T, TPrimaryKey extends keyof T, TWritableData = Wit
|
|
|
54
51
|
count(injector: Injector, filter?: FilterType<T>): Promise<number>;
|
|
55
52
|
/**
|
|
56
53
|
* Returns a filtered subset of the entity
|
|
57
|
-
*
|
|
58
54
|
* @param injector The Injector from the context
|
|
59
55
|
* @param filter The Filter definition
|
|
60
56
|
* @returns A result with the current items
|
|
@@ -62,7 +58,6 @@ export declare class DataSet<T, TPrimaryKey extends keyof T, TWritableData = Wit
|
|
|
62
58
|
find<TFields extends Array<keyof T>>(injector: Injector, filter: FindOptions<T, TFields>): Promise<Array<PartialResult<T, TFields>>>;
|
|
63
59
|
/**
|
|
64
60
|
* Returns an entity based on its primary key
|
|
65
|
-
*
|
|
66
61
|
* @param injector The injector from the context
|
|
67
62
|
* @param key The identifier of the entity
|
|
68
63
|
* @param select A field list used for projection
|
|
@@ -71,7 +66,6 @@ export declare class DataSet<T, TPrimaryKey extends keyof T, TWritableData = Wit
|
|
|
71
66
|
get(injector: Injector, key: T[TPrimaryKey], select?: Array<keyof T>): Promise<PartialResult<T, (keyof T)[]> | undefined>;
|
|
72
67
|
/**
|
|
73
68
|
* Removes an entity based on its primary key
|
|
74
|
-
*
|
|
75
69
|
* @param injector The Injector from the context
|
|
76
70
|
* @param key The primary key
|
|
77
71
|
* @returns A promise that will be resolved / rejected based on the remove success
|
package/types/data-set.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-set.d.ts","sourceRoot":"","sources":["../src/data-set.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE3G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAElD;;GAEG;AACH,qBAAa,OAAO,CAAC,CAAC,EAAE,WAAW,SAAS,MAAM,CAAC,EAAE,aAAa,GAAG,cAAc,CAAC,CAAC,EAAE,WAAW,CAAC,CACjG,YAAW,UAAU;
|
|
1
|
+
{"version":3,"file":"data-set.d.ts","sourceRoot":"","sources":["../src/data-set.ts"],"names":[],"mappings":"AAA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;;;;OAKG;IACU,IAAI,CAAC,OAAO,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,EAC9C,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAW5C;;;;;;OAMG;IACU,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAiBjF;;;;;OAKG;IACU,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB3E;;OAEG;IACH,SAAgB,eAAe;kBACnB,QAAQ;aACb,CAAC,CAAC,WAAW,CAAC;OACjB;gBAEwB,QAAQ,EAAE,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC;CACrF"}
|
package/types/helpers.d.ts
CHANGED
package/types/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AA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