@webda/core 2.0.0-beta.3 → 2.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/lib/application.d.ts +5 -5
- package/lib/application.js +71 -84
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +121 -140
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +20 -24
- package/lib/core.js +222 -315
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +332 -406
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -48
- package/lib/index.js +53 -70
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +2 -2
- package/lib/models/aclmodel.js +63 -90
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +127 -152
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +7 -6
- package/lib/models/coremodel.js +65 -113
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +88 -107
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +3 -3
- package/lib/models/ident.js +4 -9
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js +9 -11
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/ownermodel.d.ts +2 -2
- package/lib/models/ownermodel.js +39 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +126 -168
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +1 -1
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -63
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +3 -3
- package/lib/models/user.js +3 -8
- package/lib/models/user.js.map +1 -1
- package/lib/models/user.spec.js +14 -16
- package/lib/models/user.spec.js.map +1 -1
- package/lib/queues/filequeue.d.ts +2 -2
- package/lib/queues/filequeue.js +72 -93
- package/lib/queues/filequeue.js.map +1 -1
- package/lib/queues/filequeue.spec.js +53 -70
- package/lib/queues/filequeue.spec.js.map +1 -1
- package/lib/queues/memoryqueue.d.ts +2 -2
- package/lib/queues/memoryqueue.js +37 -61
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/memoryqueue.spec.js +142 -165
- package/lib/queues/memoryqueue.spec.js.map +1 -1
- package/lib/queues/pubsubservice.d.ts +2 -2
- package/lib/queues/pubsubservice.js +3 -7
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queue.spec.d.ts +1 -1
- package/lib/queues/queue.spec.js +42 -56
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.d.ts +3 -3
- package/lib/queues/queueservice.js +51 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +3 -3
- package/lib/router.js +46 -47
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +64 -61
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +2 -2
- package/lib/services/asyncevents.js +44 -64
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/asyncevents.spec.js +81 -98
- package/lib/services/asyncevents.spec.js.map +1 -1
- package/lib/services/authentication.d.ts +23 -13
- package/lib/services/authentication.js +537 -563
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +411 -447
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +7 -5
- package/lib/services/binary.js +211 -244
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +3 -3
- package/lib/services/binary.spec.js +390 -443
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +3 -3
- package/lib/services/cloudbinary.js +45 -70
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/cloudbinary.spec.d.ts +3 -3
- package/lib/services/cloudbinary.spec.js +133 -162
- package/lib/services/cloudbinary.spec.js.map +1 -1
- package/lib/services/configuration.d.ts +1 -1
- package/lib/services/configuration.js +78 -105
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +63 -83
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +3 -2
- package/lib/services/cron.js +9 -13
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.js +18 -21
- package/lib/services/cron.spec.js.map +1 -1
- package/lib/services/cryptoservice.d.ts +9 -4
- package/lib/services/cryptoservice.js +187 -221
- package/lib/services/cryptoservice.js.map +1 -1
- package/lib/services/cryptoservice.spec.js +88 -115
- package/lib/services/cryptoservice.spec.js.map +1 -1
- package/lib/services/debugmailer.d.ts +1 -1
- package/lib/services/debugmailer.js +13 -34
- package/lib/services/debugmailer.js.map +1 -1
- package/lib/services/debugmailer.spec.js +16 -29
- package/lib/services/debugmailer.spec.js.map +1 -1
- package/lib/services/echo.d.ts +2 -2
- package/lib/services/echo.js +15 -31
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.js +27 -40
- package/lib/services/echo.spec.js.map +1 -1
- package/lib/services/filebinary.d.ts +5 -5
- package/lib/services/filebinary.js +165 -210
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -116
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +1 -1
- package/lib/services/fileconfiguration.js +25 -44
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/fileconfiguration.spec.js +79 -109
- package/lib/services/fileconfiguration.spec.js.map +1 -1
- package/lib/services/invitationservice.d.ts +7 -7
- package/lib/services/invitationservice.js +274 -314
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +442 -448
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +1 -1
- package/lib/services/kubernetesconfiguration.js +41 -60
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +80 -98
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +4 -4
- package/lib/services/mailer.js +62 -86
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/mailer.spec.js +86 -127
- package/lib/services/mailer.spec.js.map +1 -1
- package/lib/services/notificationservice.d.ts +3 -3
- package/lib/services/notificationservice.js +21 -42
- package/lib/services/notificationservice.js.map +1 -1
- package/lib/services/notificationservice.spec.js +47 -73
- package/lib/services/notificationservice.spec.js.map +1 -1
- package/lib/services/oauth.d.ts +4 -4
- package/lib/services/oauth.js +68 -83
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +130 -156
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +2 -6
- package/lib/services/proxy.js +45 -58
- package/lib/services/proxy.js.map +1 -1
- package/lib/services/proxy.spec.js +34 -53
- package/lib/services/proxy.spec.js.map +1 -1
- package/lib/services/resource.d.ts +2 -2
- package/lib/services/resource.js +12 -18
- package/lib/services/resource.js.map +1 -1
- package/lib/services/resource.spec.js +67 -99
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +26 -3
- package/lib/services/service.js +68 -40
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.js +62 -67
- package/lib/services/service.spec.js.map +1 -1
- package/lib/services/version.d.ts +1 -1
- package/lib/services/version.js +3 -8
- package/lib/services/version.js.map +1 -1
- package/lib/services/version.spec.js +11 -24
- package/lib/services/version.spec.js.map +1 -1
- package/lib/stores/aggregator.d.ts +2 -2
- package/lib/stores/aggregator.js +37 -58
- package/lib/stores/aggregator.js.map +1 -1
- package/lib/stores/file.d.ts +3 -3
- package/lib/stores/file.js +93 -131
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.d.ts +2 -2
- package/lib/stores/file.spec.js +261 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +3 -3
- package/lib/stores/mapper.js +110 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +131 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +3 -3
- package/lib/stores/memory.js +98 -144
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +2 -2
- package/lib/stores/memory.spec.js +124 -145
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +17 -13
- package/lib/stores/store.js +819 -847
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +5 -4
- package/lib/stores/store.spec.js +624 -669
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
- package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
- package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
- package/lib/stores/webdaql/query.d.ts +4 -5
- package/lib/stores/webdaql/query.js +16 -19
- package/lib/stores/webdaql/query.js.map +1 -1
- package/lib/stores/webdaql/query.spec.js +30 -32
- package/lib/stores/webdaql/query.spec.js.map +1 -1
- package/lib/test.d.ts +3 -3
- package/lib/test.js +73 -100
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +25 -31
- package/lib/unpackedapplication.js.map +1 -1
- package/lib/utils/abstractdeployer.js +1 -5
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/lib/utils/abstractdeployer.spec.js +6 -8
- package/lib/utils/abstractdeployer.spec.js.map +1 -1
- package/lib/utils/context.d.ts +7 -5
- package/lib/utils/context.js +95 -103
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +139 -163
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +3 -3
- package/lib/utils/cookie.js +42 -61
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +42 -64
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/esm.d.ts +4 -0
- package/lib/utils/esm.js +10 -0
- package/lib/utils/esm.js.map +1 -0
- package/lib/utils/httpcontext.d.ts +3 -0
- package/lib/utils/httpcontext.js +48 -65
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -56
- package/lib/utils/httpcontext.spec.js.map +1 -1
- package/lib/utils/logger.d.ts +2 -2
- package/lib/utils/logger.js +15 -28
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js +9 -11
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +17 -20
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +43 -44
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/session.d.ts +6 -6
- package/lib/utils/session.js +37 -59
- package/lib/utils/session.js.map +1 -1
- package/lib/utils/session.spec.js +38 -51
- package/lib/utils/session.spec.js.map +1 -1
- package/lib/utils/waiter.d.ts +1 -1
- package/lib/utils/waiter.js +32 -52
- package/lib/utils/waiter.js.map +1 -1
- package/lib/utils/waiter.spec.js +75 -92
- package/lib/utils/waiter.spec.js.map +1 -1
- package/package.json +17 -12
- package/test/config-invitation.json +1 -3
- package/test/config.json +1 -2
- package/test/config.old.json +1 -2
- package/test/moddas/annotatedservice.js +5 -5
- package/test/moddas/debugmailer.js +2 -3
- package/test/moddas/fakeservice.js +2 -3
- package/test/moddas/voidstore.js +6 -4
- package/test/models/ident.js +2 -6
- package/test/models/task.js +3 -7
- package/test/package.json +2 -1
- package/webda.module.json +956 -189
package/lib/stores/store.js
CHANGED
|
@@ -1,40 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
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;
|
|
10
6
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const query_1 = require("./webdaql/query");
|
|
17
|
-
class StoreNotFoundError extends core_1.WebdaError {
|
|
7
|
+
import { WebdaError } from "../core.js";
|
|
8
|
+
import { CoreModel } from "../models/coremodel.js";
|
|
9
|
+
import { Route, Service, ServiceParameters } from "../services/service.js";
|
|
10
|
+
import { WebdaQL } from "./webdaql/query.js";
|
|
11
|
+
export class StoreNotFoundError extends WebdaError {
|
|
18
12
|
constructor(uuid, storeName) {
|
|
19
13
|
super("STORE_NOTFOUND", `Item not found ${uuid} Store(${storeName})`);
|
|
20
14
|
}
|
|
21
15
|
}
|
|
22
|
-
|
|
23
|
-
class UpdateConditionFailError extends core_1.WebdaError {
|
|
16
|
+
export class UpdateConditionFailError extends WebdaError {
|
|
24
17
|
constructor(uuid, conditionField, condition) {
|
|
25
18
|
super("STORE_UPDATE_CONDITION_FAILED", `UpdateCondition not met on ${uuid}.${conditionField} === ${condition instanceof Date ? condition.toISOString() : condition}`);
|
|
26
19
|
}
|
|
27
20
|
}
|
|
28
|
-
exports.UpdateConditionFailError = UpdateConditionFailError;
|
|
29
21
|
/**
|
|
30
22
|
* Store parameter
|
|
31
23
|
*/
|
|
32
|
-
class StoreParameters extends
|
|
24
|
+
export class StoreParameters extends ServiceParameters {
|
|
33
25
|
constructor(params, service) {
|
|
34
|
-
var _a
|
|
35
|
-
var _e;
|
|
26
|
+
var _a;
|
|
36
27
|
super(params);
|
|
37
|
-
|
|
28
|
+
this.model ?? (this.model = "Webda/CoreModel");
|
|
38
29
|
let expose = params.expose;
|
|
39
30
|
if (typeof expose == "boolean") {
|
|
40
31
|
expose = {};
|
|
@@ -51,7 +42,8 @@ class StoreParameters extends service_1.ServiceParameters {
|
|
|
51
42
|
if (expose) {
|
|
52
43
|
expose.restrict = expose.restrict || {};
|
|
53
44
|
this.expose = expose;
|
|
54
|
-
(
|
|
45
|
+
(_a = this.expose).queryMethod ?? (_a.queryMethod = "GET");
|
|
46
|
+
this.url = expose.url;
|
|
55
47
|
}
|
|
56
48
|
if (params.map) {
|
|
57
49
|
throw new Error("Deprecated map usage, use a MapperService");
|
|
@@ -59,11 +51,10 @@ class StoreParameters extends service_1.ServiceParameters {
|
|
|
59
51
|
if (params.index) {
|
|
60
52
|
throw new Error("Deprecated index usage, use an AggregatorService");
|
|
61
53
|
}
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
this.strict ?? (this.strict = true);
|
|
55
|
+
this.slowQueryThreshold ?? (this.slowQueryThreshold = 30000);
|
|
64
56
|
}
|
|
65
57
|
}
|
|
66
|
-
exports.StoreParameters = StoreParameters;
|
|
67
58
|
/**
|
|
68
59
|
* This class handle NoSQL storage and mapping (duplication) between NoSQL object
|
|
69
60
|
* TODO Create the mapping documentation
|
|
@@ -98,7 +89,7 @@ exports.StoreParameters = StoreParameters;
|
|
|
98
89
|
* }
|
|
99
90
|
* @category CoreServices
|
|
100
91
|
*/
|
|
101
|
-
class Store extends
|
|
92
|
+
class Store extends Service {
|
|
102
93
|
constructor() {
|
|
103
94
|
super(...arguments);
|
|
104
95
|
/**
|
|
@@ -127,26 +118,19 @@ class Store extends service_1.Service {
|
|
|
127
118
|
slowQueries: 0
|
|
128
119
|
};
|
|
129
120
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Load the parameters for a service
|
|
132
|
-
*/
|
|
133
|
-
loadParameters(params) {
|
|
134
|
-
return new StoreParameters(params, this);
|
|
135
|
-
}
|
|
136
121
|
/**
|
|
137
122
|
* Retrieve the Model
|
|
138
123
|
*
|
|
139
124
|
* @throws Error if model is not found
|
|
140
125
|
*/
|
|
141
126
|
computeParameters() {
|
|
142
|
-
var _a;
|
|
143
127
|
super.computeParameters();
|
|
144
128
|
const p = this.parameters;
|
|
145
129
|
this._model = this._webda.getModel(p.model);
|
|
146
130
|
this._uuidField = this._model.getUuidField();
|
|
147
131
|
this._lastUpdateField = this._model.getLastUpdateField();
|
|
148
132
|
this._creationDateField = this._model.getCreationField();
|
|
149
|
-
|
|
133
|
+
this._cacheStore?.computeParameters();
|
|
150
134
|
this.cacheStorePatchException();
|
|
151
135
|
}
|
|
152
136
|
logSlowQuery(_query, _reason, _time) {
|
|
@@ -168,29 +152,45 @@ class Store extends service_1.Service {
|
|
|
168
152
|
* @param raiseIfNotFound
|
|
169
153
|
* @returns
|
|
170
154
|
*/
|
|
171
|
-
_getFromCache(uid, raiseIfNotFound = false) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
return res;
|
|
182
|
-
});
|
|
155
|
+
async _getFromCache(uid, raiseIfNotFound = false) {
|
|
156
|
+
let res = await this._cacheStore?._get(uid);
|
|
157
|
+
if (!res) {
|
|
158
|
+
res = await this._get(uid, raiseIfNotFound);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
res.__store = this;
|
|
162
|
+
}
|
|
163
|
+
return res;
|
|
183
164
|
}
|
|
184
165
|
/**
|
|
185
166
|
* Get object from store
|
|
186
167
|
* @param uid
|
|
187
168
|
* @returns
|
|
188
169
|
*/
|
|
189
|
-
getObject(uid) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
170
|
+
async getObject(uid) {
|
|
171
|
+
this.metrics.get++;
|
|
172
|
+
return this._getFromCache(uid);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* @override
|
|
176
|
+
*/
|
|
177
|
+
getUrl(url, methods) {
|
|
178
|
+
// If url is absolute
|
|
179
|
+
if (url.startsWith("/")) {
|
|
180
|
+
return url;
|
|
181
|
+
}
|
|
182
|
+
const expose = this.parameters.expose;
|
|
183
|
+
if (!expose.url ||
|
|
184
|
+
(url === "." && methods.includes("POST") && expose.restrict.create) ||
|
|
185
|
+
(url === "./{uuid}" && methods.includes("DELETE") && expose.restrict.delete) ||
|
|
186
|
+
(url === "./{uuid}" && methods.includes("PATCH") && expose.restrict.update) ||
|
|
187
|
+
(url === "./{uuid}" && methods.includes("PUT") && expose.restrict.update) ||
|
|
188
|
+
(url === "./{uuid}" && methods.includes("GET") && expose.restrict.get) ||
|
|
189
|
+
(url === ".{?q}" && methods.includes("GET") && expose.restrict.query) ||
|
|
190
|
+
(url === "." && methods.includes("PUT") && expose.restrict.query)) {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
return super.getUrl(url, methods);
|
|
194
194
|
}
|
|
195
195
|
/**
|
|
196
196
|
* @inheritdoc
|
|
@@ -199,60 +199,52 @@ class Store extends service_1.Service {
|
|
|
199
199
|
if (!this.parameters.expose) {
|
|
200
200
|
return;
|
|
201
201
|
}
|
|
202
|
+
super.initRoutes();
|
|
202
203
|
// We enforce ExposeParameters within the constructor
|
|
203
204
|
const expose = this.parameters.expose;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
// schema: this._model.name
|
|
205
|
+
// Query endpoint
|
|
206
|
+
if (!expose.restrict.query) {
|
|
207
|
+
let requestBody;
|
|
208
|
+
if (expose.queryMethod === "PUT") {
|
|
209
|
+
requestBody = {
|
|
210
|
+
content: {
|
|
211
|
+
"application/json": {
|
|
212
|
+
schema: {
|
|
213
|
+
properties: {
|
|
214
|
+
q: {
|
|
215
|
+
type: "string"
|
|
216
|
+
}
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
},
|
|
220
|
-
"400": {
|
|
221
|
-
description: "Object is invalid"
|
|
222
|
-
},
|
|
223
|
-
"403": {
|
|
224
|
-
description: "You don't have permissions"
|
|
225
|
-
},
|
|
226
|
-
"409": {
|
|
227
|
-
description: "Object already exists"
|
|
228
219
|
}
|
|
229
220
|
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Dont even create the route that are restricted so we can ease up the test on handler
|
|
234
|
-
let methods = [];
|
|
235
|
-
if (!expose.restrict.update) {
|
|
236
|
-
methods.push("PUT");
|
|
237
|
-
methods.push("PATCH");
|
|
238
|
-
}
|
|
239
|
-
if (!expose.restrict.get) {
|
|
240
|
-
methods.push("GET");
|
|
241
|
-
}
|
|
242
|
-
// Query endpoint
|
|
243
|
-
if (!expose.restrict.query) {
|
|
244
|
-
this.addRoute(expose.queryMethod === "GET" ? `${expose.url}{?q}` : expose.url, [expose.queryMethod], this.httpQuery, {
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
this.addRoute(expose.queryMethod === "GET" ? `.{?q}` : ".", [expose.queryMethod], this.httpQuery, {
|
|
245
224
|
model: this._model.name,
|
|
246
225
|
[expose.queryMethod.toLowerCase()]: {
|
|
247
226
|
description: `Query on ${this._model.name} model with WebdaQL`,
|
|
248
227
|
summary: "Query " + this._model.name,
|
|
249
|
-
operationId: `
|
|
228
|
+
operationId: `query${this._model.name}`,
|
|
229
|
+
requestBody,
|
|
250
230
|
responses: {
|
|
251
231
|
"200": {
|
|
252
232
|
description: "Retrieve models",
|
|
253
233
|
content: {
|
|
254
234
|
"application/json": {
|
|
255
|
-
|
|
235
|
+
schema: {
|
|
236
|
+
properties: {
|
|
237
|
+
contiuationToken: {
|
|
238
|
+
type: "string"
|
|
239
|
+
},
|
|
240
|
+
results: {
|
|
241
|
+
type: "array",
|
|
242
|
+
items: {
|
|
243
|
+
$ref: `#/components/schemas/${this._model.name}`
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
256
248
|
}
|
|
257
249
|
}
|
|
258
250
|
},
|
|
@@ -266,87 +258,7 @@ class Store extends service_1.Service {
|
|
|
266
258
|
}
|
|
267
259
|
});
|
|
268
260
|
}
|
|
269
|
-
|
|
270
|
-
methods.push("DELETE");
|
|
271
|
-
}
|
|
272
|
-
if (methods.length) {
|
|
273
|
-
this.addRoute(expose.url + "/{uuid}", methods, this.httpRoute, {
|
|
274
|
-
model: this._model.name,
|
|
275
|
-
get: {
|
|
276
|
-
description: `Retrieve ${this._model.name} model if permissions allow`,
|
|
277
|
-
summary: "Retrieve a " + this._model.name,
|
|
278
|
-
operationId: `get${this._model.name}`,
|
|
279
|
-
responses: {
|
|
280
|
-
"200": {
|
|
281
|
-
//model: this._model.name
|
|
282
|
-
},
|
|
283
|
-
"400": {
|
|
284
|
-
description: "Object is invalid"
|
|
285
|
-
},
|
|
286
|
-
"403": {
|
|
287
|
-
description: "You don't have permissions"
|
|
288
|
-
},
|
|
289
|
-
"404": {
|
|
290
|
-
description: "Unknown object"
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
put: {
|
|
295
|
-
description: `Update a ${this._model.name} if the permissions allow`,
|
|
296
|
-
summary: "Update a " + this._model.name,
|
|
297
|
-
operationId: `updatet${this._model.name}`,
|
|
298
|
-
responses: {
|
|
299
|
-
"200": {
|
|
300
|
-
// model: this._model.name
|
|
301
|
-
},
|
|
302
|
-
"400": {
|
|
303
|
-
description: "Object is invalid"
|
|
304
|
-
},
|
|
305
|
-
"403": {
|
|
306
|
-
description: "You don't have permissions"
|
|
307
|
-
},
|
|
308
|
-
"404": {
|
|
309
|
-
description: "Unknown object"
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
patch: {
|
|
314
|
-
description: `Patch a ${this._model.name} if the permissions allow`,
|
|
315
|
-
summary: "Patch a " + this._model.name,
|
|
316
|
-
operationId: `updatet${this._model.name}`,
|
|
317
|
-
responses: {
|
|
318
|
-
"204": {
|
|
319
|
-
description: ""
|
|
320
|
-
},
|
|
321
|
-
"400": {
|
|
322
|
-
description: "Object is invalid"
|
|
323
|
-
},
|
|
324
|
-
"403": {
|
|
325
|
-
description: "You don't have permissions"
|
|
326
|
-
},
|
|
327
|
-
"404": {
|
|
328
|
-
description: "Unknown object"
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
},
|
|
332
|
-
delete: {
|
|
333
|
-
operationId: `delete${this._model.name}`,
|
|
334
|
-
description: `Delete ${this._model.name} if the permissions allow`,
|
|
335
|
-
summary: "Delete a " + this._model.name,
|
|
336
|
-
responses: {
|
|
337
|
-
"204": {
|
|
338
|
-
description: ""
|
|
339
|
-
},
|
|
340
|
-
"403": {
|
|
341
|
-
description: "You don't have permissions"
|
|
342
|
-
},
|
|
343
|
-
"404": {
|
|
344
|
-
description: "Unknown object"
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
}
|
|
261
|
+
// Model actions
|
|
350
262
|
if (this._model && this._model.getActions) {
|
|
351
263
|
let actions = this._model.getActions();
|
|
352
264
|
Object.keys(actions).forEach(name => {
|
|
@@ -361,7 +273,7 @@ class Store extends service_1.Service {
|
|
|
361
273
|
throw Error("Action static method _" + name + " does not exist");
|
|
362
274
|
}
|
|
363
275
|
executer = this.httpGlobalAction;
|
|
364
|
-
this.addRoute(
|
|
276
|
+
this.addRoute(`./${name}`, action.methods, executer, action.openapi);
|
|
365
277
|
}
|
|
366
278
|
else {
|
|
367
279
|
// By default will grab the object and then call the action
|
|
@@ -369,7 +281,7 @@ class Store extends service_1.Service {
|
|
|
369
281
|
throw Error("Action method _" + name + " does not exist");
|
|
370
282
|
}
|
|
371
283
|
executer = this.httpAction;
|
|
372
|
-
this.addRoute(
|
|
284
|
+
this.addRoute(`./{uuid}/${name}`, action.methods, executer, action.openapi);
|
|
373
285
|
}
|
|
374
286
|
});
|
|
375
287
|
}
|
|
@@ -379,17 +291,10 @@ class Store extends service_1.Service {
|
|
|
379
291
|
* Used mainly in test
|
|
380
292
|
*/
|
|
381
293
|
setModel(model) {
|
|
382
|
-
var _a;
|
|
383
294
|
this._model = model;
|
|
384
|
-
|
|
295
|
+
this._cacheStore?.setModel(model);
|
|
385
296
|
this.parameters.strict = false;
|
|
386
297
|
}
|
|
387
|
-
/**
|
|
388
|
-
* Get the url where the store is exposed
|
|
389
|
-
*/
|
|
390
|
-
getUrl() {
|
|
391
|
-
return this.parameters.expose.url;
|
|
392
|
-
}
|
|
393
298
|
/**
|
|
394
299
|
* We should ignore exception from the store
|
|
395
300
|
*/
|
|
@@ -429,7 +334,6 @@ class Store extends service_1.Service {
|
|
|
429
334
|
*/
|
|
430
335
|
initModel(object = {}) {
|
|
431
336
|
var _a;
|
|
432
|
-
var _b;
|
|
433
337
|
// Make sure to send a model object
|
|
434
338
|
if (!(object instanceof this._model)) {
|
|
435
339
|
object = this._model.factory(this._model, object);
|
|
@@ -438,9 +342,9 @@ class Store extends service_1.Service {
|
|
|
438
342
|
object.setUuid(object.generateUid(object));
|
|
439
343
|
}
|
|
440
344
|
object.__store = this;
|
|
441
|
-
for (
|
|
442
|
-
|
|
443
|
-
for (
|
|
345
|
+
for (let i in this._reverseMap) {
|
|
346
|
+
object[_a = this._reverseMap[i].property] ?? (object[_a] = []);
|
|
347
|
+
for (let j in object[this._reverseMap[i].property]) {
|
|
444
348
|
// Use Partial
|
|
445
349
|
object[this._reverseMap[i].property][j] = this._reverseMap[i].mapper.initModel(object[this._reverseMap[i].property][j]);
|
|
446
350
|
object[this._reverseMap[i].property][j].setContext(object.getContext());
|
|
@@ -461,72 +365,63 @@ class Store extends service_1.Service {
|
|
|
461
365
|
mapper: store
|
|
462
366
|
});
|
|
463
367
|
}
|
|
464
|
-
incrementAttribute(uid, prop, value) {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
value: value,
|
|
482
|
-
property: prop
|
|
483
|
-
}
|
|
368
|
+
async incrementAttribute(uid, prop, value) {
|
|
369
|
+
// If value === 0 no need to update anything
|
|
370
|
+
if (value === 0) {
|
|
371
|
+
return Promise.resolve();
|
|
372
|
+
}
|
|
373
|
+
let updateDate = new Date();
|
|
374
|
+
this.metrics.increment++;
|
|
375
|
+
await this._incrementAttribute(uid, prop, value, updateDate);
|
|
376
|
+
await this._cacheStore?._incrementAttribute(uid, prop, value, updateDate);
|
|
377
|
+
return this.emitSync("Store.PartialUpdated", {
|
|
378
|
+
object_id: uid,
|
|
379
|
+
store: this,
|
|
380
|
+
updateDate,
|
|
381
|
+
partial_update: {
|
|
382
|
+
increment: {
|
|
383
|
+
value: value,
|
|
384
|
+
property: prop
|
|
484
385
|
}
|
|
485
|
-
}
|
|
386
|
+
}
|
|
486
387
|
});
|
|
487
388
|
}
|
|
488
|
-
upsertItemToCollection(uid, prop, item, index = undefined, itemWriteCondition = undefined, itemWriteConditionField = undefined) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
property: prop,
|
|
506
|
-
index: index
|
|
507
|
-
}
|
|
389
|
+
async upsertItemToCollection(uid, prop, item, index = undefined, itemWriteCondition = undefined, itemWriteConditionField = undefined) {
|
|
390
|
+
if (itemWriteConditionField === undefined) {
|
|
391
|
+
itemWriteConditionField = this._uuidField;
|
|
392
|
+
}
|
|
393
|
+
let updateDate = new Date();
|
|
394
|
+
this.metrics.collectionUpsert++;
|
|
395
|
+
await this._upsertItemToCollection(uid, prop, item, index, itemWriteCondition, itemWriteConditionField, updateDate);
|
|
396
|
+
await this._cacheStore?._upsertItemToCollection(uid, prop, item, index, itemWriteCondition, itemWriteConditionField, updateDate);
|
|
397
|
+
await this.emitSync("Store.PartialUpdated", {
|
|
398
|
+
object_id: uid,
|
|
399
|
+
store: this,
|
|
400
|
+
updateDate,
|
|
401
|
+
partial_update: {
|
|
402
|
+
addItem: {
|
|
403
|
+
value: item,
|
|
404
|
+
property: prop,
|
|
405
|
+
index: index
|
|
508
406
|
}
|
|
509
|
-
}
|
|
407
|
+
}
|
|
510
408
|
});
|
|
511
409
|
}
|
|
512
|
-
deleteItemFromCollection(uid, prop, index, itemWriteCondition, itemWriteConditionField = this._uuidField) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
property: prop,
|
|
526
|
-
index: index
|
|
527
|
-
}
|
|
410
|
+
async deleteItemFromCollection(uid, prop, index, itemWriteCondition, itemWriteConditionField = this._uuidField) {
|
|
411
|
+
let updateDate = new Date();
|
|
412
|
+
this.metrics.collectionDelete++;
|
|
413
|
+
await this._deleteItemFromCollection(uid, prop, index, itemWriteCondition, itemWriteConditionField, updateDate);
|
|
414
|
+
await this._cacheStore?._deleteItemFromCollection(uid, prop, index, itemWriteCondition, itemWriteConditionField, updateDate);
|
|
415
|
+
await this.emitSync("Store.PartialUpdated", {
|
|
416
|
+
object_id: uid,
|
|
417
|
+
store: this,
|
|
418
|
+
updateDate,
|
|
419
|
+
partial_update: {
|
|
420
|
+
deleteItem: {
|
|
421
|
+
property: prop,
|
|
422
|
+
index: index
|
|
528
423
|
}
|
|
529
|
-
}
|
|
424
|
+
}
|
|
530
425
|
});
|
|
531
426
|
}
|
|
532
427
|
/**
|
|
@@ -534,136 +429,132 @@ class Store extends service_1.Service {
|
|
|
534
429
|
* @param query
|
|
535
430
|
* @param context to apply permission
|
|
536
431
|
*/
|
|
537
|
-
query(query, context) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
fullQuery = `(${permissionQuery.query}) AND ${query}`;
|
|
546
|
-
}
|
|
547
|
-
else {
|
|
548
|
-
fullQuery = permissionQuery.query;
|
|
549
|
-
}
|
|
432
|
+
async query(query, context) {
|
|
433
|
+
let permissionQuery = this._model.getPermissionQuery(context);
|
|
434
|
+
let partialPermission = true;
|
|
435
|
+
let fullQuery;
|
|
436
|
+
if (permissionQuery) {
|
|
437
|
+
partialPermission = permissionQuery.partial;
|
|
438
|
+
if (query.trim() !== "") {
|
|
439
|
+
fullQuery = `(${permissionQuery.query}) AND ${query}`;
|
|
550
440
|
}
|
|
551
441
|
else {
|
|
552
|
-
fullQuery = query;
|
|
442
|
+
fullQuery = permissionQuery.query;
|
|
553
443
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
fullQuery = query;
|
|
447
|
+
}
|
|
448
|
+
let queryValidator = new WebdaQL.QueryValidator(fullQuery);
|
|
449
|
+
let offset = queryValidator.getOffset();
|
|
450
|
+
const limit = queryValidator.getLimit();
|
|
451
|
+
const parsedQuery = queryValidator.getQuery();
|
|
452
|
+
// Emit the default event
|
|
453
|
+
await this.emitSync("Store.Query", {
|
|
454
|
+
query,
|
|
455
|
+
parsedQuery,
|
|
456
|
+
store: this,
|
|
457
|
+
context
|
|
458
|
+
});
|
|
459
|
+
const result = {
|
|
460
|
+
results: [],
|
|
461
|
+
continuationToken: undefined
|
|
462
|
+
};
|
|
463
|
+
/*
|
|
464
|
+
Offset are split in two with _
|
|
465
|
+
|
|
466
|
+
MainOffset is the database offset, retrieving a page from the database
|
|
467
|
+
SubOffset is the offset within the page
|
|
468
|
+
|
|
469
|
+
As we filter through the page, for additional filters or permissions, the page cut
|
|
470
|
+
by database does not endup being our final page cut, so we need a page offset to
|
|
471
|
+
abstract this completely
|
|
472
|
+
*/
|
|
473
|
+
let [mainOffset, subOffset] = offset.split("_");
|
|
474
|
+
let secondOffset = parseInt(subOffset || "0");
|
|
475
|
+
let duration = Date.now();
|
|
476
|
+
this.metrics.query++;
|
|
477
|
+
while (result.results.length < limit) {
|
|
478
|
+
let tmpResults = await this.find({ ...parsedQuery, continuationToken: mainOffset });
|
|
479
|
+
// If no filter is returned assume it is by mistake and apply filtering
|
|
480
|
+
if (tmpResults.filter === undefined) {
|
|
481
|
+
tmpResults.filter = queryValidator.getExpression();
|
|
482
|
+
this.log("WARN", `Store '${this.getName()}' postquery full filtering`);
|
|
483
|
+
}
|
|
484
|
+
let subOffsetCount = 0;
|
|
485
|
+
for (let item of tmpResults.results) {
|
|
486
|
+
// Because of dynamic filter and permission we need to suboffset the pagination
|
|
487
|
+
subOffsetCount++;
|
|
488
|
+
if (subOffsetCount <= secondOffset) {
|
|
489
|
+
continue;
|
|
589
490
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
491
|
+
if (tmpResults.filter !== true && !tmpResults.filter.eval(item)) {
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
if (context && partialPermission) {
|
|
495
|
+
try {
|
|
496
|
+
await item.canAct(context, "get");
|
|
596
497
|
}
|
|
597
|
-
|
|
498
|
+
catch (err) {
|
|
598
499
|
continue;
|
|
599
500
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
continue;
|
|
606
|
-
}
|
|
501
|
+
}
|
|
502
|
+
result.results.push(item);
|
|
503
|
+
if (result.results.length >= limit) {
|
|
504
|
+
if (subOffsetCount === tmpResults.results.length) {
|
|
505
|
+
result.continuationToken = tmpResults.continuationToken;
|
|
607
506
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
if (subOffsetCount === tmpResults.results.length) {
|
|
611
|
-
result.continuationToken = tmpResults.continuationToken;
|
|
612
|
-
}
|
|
613
|
-
else {
|
|
614
|
-
result.continuationToken = `${mainOffset}_${subOffsetCount}`;
|
|
615
|
-
}
|
|
616
|
-
break;
|
|
507
|
+
else {
|
|
508
|
+
result.continuationToken = `${mainOffset}_${subOffsetCount}`;
|
|
617
509
|
}
|
|
618
|
-
}
|
|
619
|
-
// Update both offset
|
|
620
|
-
mainOffset = tmpResults.continuationToken;
|
|
621
|
-
// Fresh new query so we do not need to skip
|
|
622
|
-
secondOffset = 0;
|
|
623
|
-
if (mainOffset === undefined || result.results.length >= limit) {
|
|
624
510
|
break;
|
|
625
511
|
}
|
|
626
512
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
513
|
+
// Update both offset
|
|
514
|
+
mainOffset = tmpResults.continuationToken;
|
|
515
|
+
// Fresh new query so we do not need to skip
|
|
516
|
+
secondOffset = 0;
|
|
517
|
+
if (mainOffset === undefined || result.results.length >= limit) {
|
|
518
|
+
break;
|
|
632
519
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
520
|
+
}
|
|
521
|
+
duration = Date.now() - duration;
|
|
522
|
+
this.metrics.queryDuration =
|
|
523
|
+
(this.metrics.queryDuration * (this.metrics.query - 1) + duration) / this.metrics.query;
|
|
524
|
+
if (duration > this.parameters.slowQueryThreshold) {
|
|
525
|
+
this.logSlowQuery(query, "", duration);
|
|
526
|
+
}
|
|
527
|
+
await this.emitSync("Store.Queried", {
|
|
528
|
+
query,
|
|
529
|
+
parsedQuery: parsedQuery,
|
|
530
|
+
store: this,
|
|
531
|
+
continuationToken: result.continuationToken,
|
|
532
|
+
results: result.results,
|
|
533
|
+
context
|
|
642
534
|
});
|
|
535
|
+
return result;
|
|
643
536
|
}
|
|
644
537
|
/**
|
|
645
538
|
* Expose query to http
|
|
646
539
|
*/
|
|
647
|
-
httpQuery(ctx) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
throw 400;
|
|
663
|
-
}
|
|
664
|
-
throw err;
|
|
540
|
+
async httpQuery(ctx) {
|
|
541
|
+
let query;
|
|
542
|
+
if (ctx.getHttpContext().getMethod() === "GET") {
|
|
543
|
+
query = ctx.getParameters().q;
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
query = (await ctx.getRequestBody()).q;
|
|
547
|
+
}
|
|
548
|
+
try {
|
|
549
|
+
ctx.write(await this.query(query, ctx));
|
|
550
|
+
}
|
|
551
|
+
catch (err) {
|
|
552
|
+
if (err instanceof SyntaxError) {
|
|
553
|
+
this.log("INFO", "Query syntax error");
|
|
554
|
+
throw 400;
|
|
665
555
|
}
|
|
666
|
-
|
|
556
|
+
throw err;
|
|
557
|
+
}
|
|
667
558
|
}
|
|
668
559
|
/**
|
|
669
560
|
* Save an object
|
|
@@ -674,36 +565,33 @@ class Store extends service_1.Service {
|
|
|
674
565
|
*
|
|
675
566
|
* Might want to rename to create
|
|
676
567
|
*/
|
|
677
|
-
save(object, ctx = undefined) {
|
|
678
|
-
var _a
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
object
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
object
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
store: this,
|
|
702
|
-
context: ctx
|
|
703
|
-
});
|
|
704
|
-
yield object._onSaved();
|
|
705
|
-
return object;
|
|
568
|
+
async save(object, ctx = undefined) {
|
|
569
|
+
var _a;
|
|
570
|
+
object = this.initModel(object);
|
|
571
|
+
// Dates should be store by the Store
|
|
572
|
+
object[_a = this._creationDateField] ?? (object[_a] = new Date());
|
|
573
|
+
object[this._lastUpdateField] = new Date();
|
|
574
|
+
if (ctx) {
|
|
575
|
+
object.setContext(ctx);
|
|
576
|
+
}
|
|
577
|
+
await this.emitSync("Store.Save", {
|
|
578
|
+
object: object,
|
|
579
|
+
store: this,
|
|
580
|
+
context: ctx
|
|
581
|
+
});
|
|
582
|
+
// Handle object auto listener
|
|
583
|
+
await object._onSave();
|
|
584
|
+
this.metrics.save++;
|
|
585
|
+
let res = await this._save(object);
|
|
586
|
+
await this._cacheStore?._save(object);
|
|
587
|
+
object = this.initModel(res);
|
|
588
|
+
await this.emitSync("Store.Saved", {
|
|
589
|
+
object: object,
|
|
590
|
+
store: this,
|
|
591
|
+
context: ctx
|
|
706
592
|
});
|
|
593
|
+
await object._onSaved();
|
|
594
|
+
return object;
|
|
707
595
|
}
|
|
708
596
|
/**
|
|
709
597
|
* Patch an object
|
|
@@ -712,10 +600,8 @@ class Store extends service_1.Service {
|
|
|
712
600
|
* @param reverseMap
|
|
713
601
|
* @returns
|
|
714
602
|
*/
|
|
715
|
-
patch(object, reverseMap = true) {
|
|
716
|
-
return
|
|
717
|
-
return this.update(object, reverseMap, true);
|
|
718
|
-
});
|
|
603
|
+
async patch(object, reverseMap = true) {
|
|
604
|
+
return this.update(object, reverseMap, true);
|
|
719
605
|
}
|
|
720
606
|
/**
|
|
721
607
|
* Check if an UpdateCondition is met
|
|
@@ -757,21 +643,18 @@ class Store extends service_1.Service {
|
|
|
757
643
|
* @param conditionField
|
|
758
644
|
* @param condition
|
|
759
645
|
*/
|
|
760
|
-
conditionalPatch(uuid, updates, conditionField, condition) {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
if (err instanceof UpdateConditionFailError) {
|
|
770
|
-
return false;
|
|
771
|
-
}
|
|
772
|
-
throw err;
|
|
646
|
+
async conditionalPatch(uuid, updates, conditionField, condition) {
|
|
647
|
+
try {
|
|
648
|
+
await this._patch(updates, uuid, condition, conditionField);
|
|
649
|
+
await this._cacheStore?.patch({ uuid, ...updates });
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
catch (err) {
|
|
653
|
+
if (err instanceof UpdateConditionFailError) {
|
|
654
|
+
return false;
|
|
773
655
|
}
|
|
774
|
-
|
|
656
|
+
throw err;
|
|
657
|
+
}
|
|
775
658
|
}
|
|
776
659
|
/**
|
|
777
660
|
*
|
|
@@ -783,26 +666,24 @@ class Store extends service_1.Service {
|
|
|
783
666
|
* @param itemWriteConditionField
|
|
784
667
|
* @param updateDate
|
|
785
668
|
*/
|
|
786
|
-
simulateUpsertItemToCollection(model, prop, item, updateDate, index, itemWriteCondition, itemWriteConditionField) {
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
if (
|
|
793
|
-
|
|
794
|
-
model[prop] = [item];
|
|
795
|
-
}
|
|
796
|
-
else {
|
|
797
|
-
model[prop].push(item);
|
|
798
|
-
}
|
|
669
|
+
async simulateUpsertItemToCollection(model, prop, item, updateDate, index, itemWriteCondition, itemWriteConditionField) {
|
|
670
|
+
if (prop === "__proto__") {
|
|
671
|
+
throw new Error("Cannot update __proto__: js/prototype-polluting-assignment");
|
|
672
|
+
}
|
|
673
|
+
this.checkCollectionUpdateCondition(model, prop, itemWriteConditionField, itemWriteCondition, index);
|
|
674
|
+
if (index === undefined) {
|
|
675
|
+
if (model[prop] === undefined) {
|
|
676
|
+
model[prop] = [item];
|
|
799
677
|
}
|
|
800
678
|
else {
|
|
801
|
-
model[prop]
|
|
679
|
+
model[prop].push(item);
|
|
802
680
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
model[prop][index] = item;
|
|
684
|
+
}
|
|
685
|
+
model[this._lastUpdateField] = updateDate;
|
|
686
|
+
await this._save(model);
|
|
806
687
|
}
|
|
807
688
|
/**
|
|
808
689
|
* Update an object
|
|
@@ -813,88 +694,86 @@ class Store extends service_1.Service {
|
|
|
813
694
|
* @param {Boolean} reverseMap internal use only, for disable map resolution
|
|
814
695
|
* @return {Promise} with saved object
|
|
815
696
|
*/
|
|
816
|
-
update(object, reverseMap = true, partial = false) {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
if (object[this._reverseMap[i].property] != undefined) {
|
|
826
|
-
delete object[this._reverseMap[i].property];
|
|
827
|
-
}
|
|
697
|
+
async update(object, reverseMap = true, partial = false) {
|
|
698
|
+
/** @ignore */
|
|
699
|
+
let saved;
|
|
700
|
+
let loaded;
|
|
701
|
+
// Dont allow to update collections from map
|
|
702
|
+
if (this._reverseMap != undefined && reverseMap) {
|
|
703
|
+
for (let i in this._reverseMap) {
|
|
704
|
+
if (object[this._reverseMap[i].property] != undefined) {
|
|
705
|
+
delete object[this._reverseMap[i].property];
|
|
828
706
|
}
|
|
829
707
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
this.metrics.update++;
|
|
872
|
-
res = yield this._update(object, object[this._uuidField], load[this._lastUpdateField], this._lastUpdateField);
|
|
873
|
-
yield ((_b = this._cacheStore) === null || _b === void 0 ? void 0 : _b._update(object, object[this._uuidField], load[this._lastUpdateField], this._lastUpdateField));
|
|
874
|
-
}
|
|
875
|
-
// Return updated
|
|
876
|
-
for (let i in res) {
|
|
877
|
-
loaded[i] = res[i];
|
|
878
|
-
}
|
|
879
|
-
for (let i in object) {
|
|
880
|
-
loaded[i] = object[i];
|
|
881
|
-
}
|
|
882
|
-
saved = this.initModel(loaded);
|
|
883
|
-
if (partial) {
|
|
884
|
-
yield this.emitSync(`Store.PatchUpdated`, {
|
|
885
|
-
object: saved,
|
|
886
|
-
store: this
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
else {
|
|
890
|
-
yield this.emitSync(`Store.Updated`, {
|
|
891
|
-
object: saved,
|
|
892
|
-
store: this
|
|
893
|
-
});
|
|
708
|
+
}
|
|
709
|
+
if (Object.keys(object).length < 2) {
|
|
710
|
+
return undefined;
|
|
711
|
+
}
|
|
712
|
+
object[this._lastUpdateField] = new Date();
|
|
713
|
+
this.metrics.get++;
|
|
714
|
+
let load = await this._getFromCache(object[this._uuidField], true);
|
|
715
|
+
if (load.__type !== this._model.name && this.parameters.strict) {
|
|
716
|
+
this.log("WARN", `Object '${object[this._uuidField]}' was not created by this store`);
|
|
717
|
+
throw new StoreNotFoundError(object[this._uuidField], this.getName());
|
|
718
|
+
}
|
|
719
|
+
loaded = this.initModel(load);
|
|
720
|
+
if (object instanceof CoreModel) {
|
|
721
|
+
loaded.setContext(object.getContext());
|
|
722
|
+
}
|
|
723
|
+
if (partial) {
|
|
724
|
+
await this.emitSync(`Store.PatchUpdate`, {
|
|
725
|
+
object: loaded,
|
|
726
|
+
store: this,
|
|
727
|
+
update: object
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
await this.emitSync(`Store.Update`, {
|
|
732
|
+
object: loaded,
|
|
733
|
+
store: this,
|
|
734
|
+
update: object
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
await loaded._onUpdate(object);
|
|
738
|
+
let res;
|
|
739
|
+
if (partial) {
|
|
740
|
+
this.metrics.partialUpdate++;
|
|
741
|
+
await this._patch(object, object[this._uuidField], load[this._lastUpdateField], this._lastUpdateField);
|
|
742
|
+
await this._cacheStore?._patch(object, object[this._uuidField], load[this._lastUpdateField], this._lastUpdateField);
|
|
743
|
+
res = object;
|
|
744
|
+
}
|
|
745
|
+
else {
|
|
746
|
+
// Copy back the mappers
|
|
747
|
+
for (let i in this._reverseMap) {
|
|
748
|
+
object[this._reverseMap[i].property] = loaded[this._reverseMap[i].property];
|
|
894
749
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
750
|
+
object = this.initModel(object);
|
|
751
|
+
this.metrics.update++;
|
|
752
|
+
res = await this._update(object, object[this._uuidField], load[this._lastUpdateField], this._lastUpdateField);
|
|
753
|
+
await this._cacheStore?._update(object, object[this._uuidField], load[this._lastUpdateField], this._lastUpdateField);
|
|
754
|
+
}
|
|
755
|
+
// Return updated
|
|
756
|
+
for (let i in res) {
|
|
757
|
+
loaded[i] = res[i];
|
|
758
|
+
}
|
|
759
|
+
for (let i in object) {
|
|
760
|
+
loaded[i] = object[i];
|
|
761
|
+
}
|
|
762
|
+
saved = this.initModel(loaded);
|
|
763
|
+
if (partial) {
|
|
764
|
+
await this.emitSync(`Store.PatchUpdated`, {
|
|
765
|
+
object: saved,
|
|
766
|
+
store: this
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
await this.emitSync(`Store.Updated`, {
|
|
771
|
+
object: saved,
|
|
772
|
+
store: this
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
await saved._onUpdated();
|
|
776
|
+
return saved;
|
|
898
777
|
}
|
|
899
778
|
/**
|
|
900
779
|
* Remove an attribute from an object
|
|
@@ -903,18 +782,15 @@ class Store extends service_1.Service {
|
|
|
903
782
|
* @param attribute
|
|
904
783
|
* @returns
|
|
905
784
|
*/
|
|
906
|
-
removeAttribute(uuid, attribute, itemWriteCondition, itemWriteConditionField) {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
deleteAttribute: attribute
|
|
916
|
-
}
|
|
917
|
-
});
|
|
785
|
+
async removeAttribute(uuid, attribute, itemWriteCondition, itemWriteConditionField) {
|
|
786
|
+
this.metrics.attributeDelete++;
|
|
787
|
+
await this._removeAttribute(uuid, attribute, itemWriteCondition, itemWriteConditionField);
|
|
788
|
+
await this._cacheStore?._removeAttribute(uuid, attribute, itemWriteCondition, itemWriteConditionField);
|
|
789
|
+
await this.emitSync("Store.PartialUpdated", {
|
|
790
|
+
object_id: uuid,
|
|
791
|
+
partial_update: {
|
|
792
|
+
deleteAttribute: attribute
|
|
793
|
+
}
|
|
918
794
|
});
|
|
919
795
|
}
|
|
920
796
|
/**
|
|
@@ -924,21 +800,17 @@ class Store extends service_1.Service {
|
|
|
924
800
|
* @param uuid
|
|
925
801
|
* @returns
|
|
926
802
|
*/
|
|
927
|
-
cascadeDelete(obj, _uuid) {
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
return this.delete(obj.getUuid());
|
|
931
|
-
});
|
|
803
|
+
async cascadeDelete(obj, _uuid) {
|
|
804
|
+
// We dont need uuid but Binary store will need it
|
|
805
|
+
return this.delete(obj.getUuid());
|
|
932
806
|
}
|
|
933
807
|
/**
|
|
934
808
|
* Delete an object from the store without condition nor async
|
|
935
809
|
* @param uid to delete
|
|
936
810
|
* @returns
|
|
937
811
|
*/
|
|
938
|
-
forceDelete(uid) {
|
|
939
|
-
return
|
|
940
|
-
return this.delete(uid, undefined, undefined, true);
|
|
941
|
-
});
|
|
812
|
+
async forceDelete(uid) {
|
|
813
|
+
return this.delete(uid, undefined, undefined, true);
|
|
942
814
|
}
|
|
943
815
|
/**
|
|
944
816
|
* Delete an object
|
|
@@ -947,62 +819,59 @@ class Store extends service_1.Service {
|
|
|
947
819
|
* @param {Boolean} delete sync even if asyncDelete is active
|
|
948
820
|
* @return {Promise} the deletion promise
|
|
949
821
|
*/
|
|
950
|
-
delete(uid, writeCondition, writeConditionField, sync = false) {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
if (to_delete === undefined) {
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
if (to_delete.__type !== this._model.name && this.parameters.strict) {
|
|
966
|
-
this.log("WARN", `Object '${uid}' was not created by this store`);
|
|
967
|
-
return;
|
|
968
|
-
}
|
|
969
|
-
to_delete = this.initModel(to_delete);
|
|
970
|
-
}
|
|
971
|
-
// Check condition as we have the object
|
|
972
|
-
if (writeCondition) {
|
|
973
|
-
if (to_delete[writeConditionField] !== writeCondition) {
|
|
974
|
-
throw new UpdateConditionFailError(to_delete.getUuid(), writeConditionField, writeCondition);
|
|
975
|
-
}
|
|
822
|
+
async delete(uid, writeCondition, writeConditionField, sync = false) {
|
|
823
|
+
/** @ignore */
|
|
824
|
+
let to_delete;
|
|
825
|
+
// Allow full object or just its uuid
|
|
826
|
+
if (typeof uid === "object") {
|
|
827
|
+
to_delete = uid;
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
this.metrics.get++;
|
|
831
|
+
to_delete = await this._getFromCache(uid);
|
|
832
|
+
if (to_delete === undefined) {
|
|
833
|
+
return;
|
|
976
834
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
store: this
|
|
981
|
-
});
|
|
982
|
-
yield to_delete._onDelete();
|
|
983
|
-
// If async we just tag the object as deleted
|
|
984
|
-
if (this.parameters.asyncDelete && !sync) {
|
|
985
|
-
this.metrics.partialUpdate++;
|
|
986
|
-
yield this._patch({
|
|
987
|
-
__deleted: true
|
|
988
|
-
}, to_delete.getUuid());
|
|
989
|
-
yield ((_a = this._cacheStore) === null || _a === void 0 ? void 0 : _a._patch({
|
|
990
|
-
__deleted: true
|
|
991
|
-
}, to_delete.getUuid()));
|
|
835
|
+
if (to_delete.__type !== this._model.name && this.parameters.strict) {
|
|
836
|
+
this.log("WARN", `Object '${uid}' was not created by this store`);
|
|
837
|
+
return;
|
|
992
838
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
839
|
+
to_delete = this.initModel(to_delete);
|
|
840
|
+
}
|
|
841
|
+
// Check condition as we have the object
|
|
842
|
+
if (writeCondition) {
|
|
843
|
+
if (to_delete[writeConditionField] !== writeCondition) {
|
|
844
|
+
throw new UpdateConditionFailError(to_delete.getUuid(), writeConditionField, writeCondition);
|
|
998
845
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
yield to_delete._onDeleted();
|
|
846
|
+
}
|
|
847
|
+
// Send preevent
|
|
848
|
+
await this.emitSync("Store.Delete", {
|
|
849
|
+
object: to_delete,
|
|
850
|
+
store: this
|
|
1005
851
|
});
|
|
852
|
+
await to_delete._onDelete();
|
|
853
|
+
// If async we just tag the object as deleted
|
|
854
|
+
if (this.parameters.asyncDelete && !sync) {
|
|
855
|
+
this.metrics.partialUpdate++;
|
|
856
|
+
await this._patch({
|
|
857
|
+
__deleted: true
|
|
858
|
+
}, to_delete.getUuid());
|
|
859
|
+
await this._cacheStore?._patch({
|
|
860
|
+
__deleted: true
|
|
861
|
+
}, to_delete.getUuid());
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
this.metrics.delete++;
|
|
865
|
+
// Delete from the DB for real
|
|
866
|
+
await this._delete(to_delete.getUuid(), writeCondition, writeConditionField);
|
|
867
|
+
await this._cacheStore?._delete(to_delete.getUuid(), writeCondition, writeConditionField);
|
|
868
|
+
}
|
|
869
|
+
// Send post event
|
|
870
|
+
await this.emitSync("Store.Deleted", {
|
|
871
|
+
object: to_delete,
|
|
872
|
+
store: this
|
|
873
|
+
});
|
|
874
|
+
await to_delete._onDeleted();
|
|
1006
875
|
}
|
|
1007
876
|
/**
|
|
1008
877
|
* By default we cannot know if the store will trigger or not
|
|
@@ -1018,32 +887,31 @@ class Store extends service_1.Service {
|
|
|
1018
887
|
* @param {string} id
|
|
1019
888
|
* @returns {Promise<Map<string, any>>}
|
|
1020
889
|
*/
|
|
1021
|
-
getConfiguration(id) {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
continue;
|
|
1032
|
-
}
|
|
1033
|
-
result[i] = object[i];
|
|
890
|
+
async getConfiguration(id) {
|
|
891
|
+
this.metrics.get++;
|
|
892
|
+
let object = await this._getFromCache(id);
|
|
893
|
+
if (!object) {
|
|
894
|
+
return undefined;
|
|
895
|
+
}
|
|
896
|
+
let result = {};
|
|
897
|
+
for (let i in object) {
|
|
898
|
+
if (i === this._uuidField || i === this._lastUpdateField || i.startsWith("_")) {
|
|
899
|
+
continue;
|
|
1034
900
|
}
|
|
1035
|
-
|
|
1036
|
-
}
|
|
901
|
+
result[i] = object[i];
|
|
902
|
+
}
|
|
903
|
+
return result;
|
|
1037
904
|
}
|
|
1038
905
|
/**
|
|
1039
|
-
*
|
|
906
|
+
* Upsert the uuid object
|
|
1040
907
|
* @param uuid
|
|
1041
908
|
* @param data
|
|
1042
909
|
*/
|
|
1043
|
-
put(uuid, data) {
|
|
1044
|
-
|
|
1045
|
-
return this.
|
|
1046
|
-
}
|
|
910
|
+
async put(uuid, data) {
|
|
911
|
+
if (await this.exists(uuid)) {
|
|
912
|
+
return this.update({ ...data, uuid });
|
|
913
|
+
}
|
|
914
|
+
return this.save({ ...data, uuid });
|
|
1047
915
|
}
|
|
1048
916
|
/**
|
|
1049
917
|
* Get an object
|
|
@@ -1051,31 +919,29 @@ class Store extends service_1.Service {
|
|
|
1051
919
|
* @param {String} uuid to get
|
|
1052
920
|
* @return {Promise} the object retrieved ( can be undefined if not found )
|
|
1053
921
|
*/
|
|
1054
|
-
get(uid, ctx = undefined) {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
context: ctx
|
|
1075
|
-
});
|
|
1076
|
-
yield object._onGet();
|
|
1077
|
-
return object;
|
|
922
|
+
async get(uid, ctx = undefined, defaultValue = undefined) {
|
|
923
|
+
/** @ignore */
|
|
924
|
+
if (!uid) {
|
|
925
|
+
return undefined;
|
|
926
|
+
}
|
|
927
|
+
this.metrics.get++;
|
|
928
|
+
let object = await this._getFromCache(uid);
|
|
929
|
+
if (!object) {
|
|
930
|
+
return defaultValue ? this.initModel(defaultValue) : undefined;
|
|
931
|
+
}
|
|
932
|
+
if (object.__type !== this._model.name && this.parameters.strict) {
|
|
933
|
+
this.log("WARN", `Object '${uid}' was not created by this store`);
|
|
934
|
+
return undefined;
|
|
935
|
+
}
|
|
936
|
+
object = this.initModel(object);
|
|
937
|
+
object.setContext(ctx);
|
|
938
|
+
await this.emitSync("Store.Get", {
|
|
939
|
+
object: object,
|
|
940
|
+
store: this,
|
|
941
|
+
context: ctx
|
|
1078
942
|
});
|
|
943
|
+
await object._onGet();
|
|
944
|
+
return object;
|
|
1079
945
|
}
|
|
1080
946
|
/**
|
|
1081
947
|
* Set one attribute in an object
|
|
@@ -1087,159 +953,154 @@ class Store extends service_1.Service {
|
|
|
1087
953
|
* @param value new value
|
|
1088
954
|
* @returns
|
|
1089
955
|
*/
|
|
1090
|
-
setAttribute(uid, property, value) {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
yield this.patch(patch);
|
|
1096
|
-
});
|
|
956
|
+
async setAttribute(uid, property, value) {
|
|
957
|
+
let patch = {};
|
|
958
|
+
patch[property] = value;
|
|
959
|
+
patch[this.getUuidField()] = uid;
|
|
960
|
+
await this.patch(patch);
|
|
1097
961
|
}
|
|
1098
962
|
/**
|
|
1099
963
|
* @override
|
|
1100
964
|
*/
|
|
1101
|
-
simulateFind(query, uuids) {
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
965
|
+
async simulateFind(query, uuids) {
|
|
966
|
+
let result = {
|
|
967
|
+
results: [],
|
|
968
|
+
continuationToken: undefined,
|
|
969
|
+
filter: true
|
|
970
|
+
};
|
|
971
|
+
let count = 0;
|
|
972
|
+
let limit = query.limit;
|
|
973
|
+
let offset = parseInt(query.continuationToken || "0");
|
|
974
|
+
let originalOffset = offset;
|
|
975
|
+
if (query.orderBy && query.orderBy.length) {
|
|
976
|
+
offset = 0;
|
|
977
|
+
// We need to retrieve everything to orderBy after
|
|
978
|
+
limit = Number.MAX_SAFE_INTEGER;
|
|
979
|
+
}
|
|
980
|
+
// Need to transfert to Array
|
|
981
|
+
for (let uuid of uuids) {
|
|
982
|
+
count++;
|
|
983
|
+
// Offset start
|
|
984
|
+
if (offset >= count) {
|
|
985
|
+
continue;
|
|
1116
986
|
}
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
}
|
|
1124
|
-
let obj = yield this._getFromCache(uuid);
|
|
1125
|
-
if (obj && query.filter.eval(obj)) {
|
|
1126
|
-
result.results.push(obj);
|
|
1127
|
-
if (result.results.length >= limit) {
|
|
1128
|
-
result.continuationToken = count.toString();
|
|
1129
|
-
return result;
|
|
1130
|
-
}
|
|
987
|
+
let obj = await this._getFromCache(uuid);
|
|
988
|
+
if (obj && query.filter.eval(obj)) {
|
|
989
|
+
result.results.push(obj);
|
|
990
|
+
if (result.results.length >= limit) {
|
|
991
|
+
result.continuationToken = count.toString();
|
|
992
|
+
return result;
|
|
1131
993
|
}
|
|
1132
994
|
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
if (typeof valA === "string") {
|
|
1146
|
-
return valA.localeCompare(valB) * invert;
|
|
1147
|
-
}
|
|
1148
|
-
return (valA < valB ? -1 : 1) * invert;
|
|
995
|
+
}
|
|
996
|
+
// Order by
|
|
997
|
+
if (query.orderBy && query.orderBy.length) {
|
|
998
|
+
// Sorting the results
|
|
999
|
+
result.results.sort((a, b) => {
|
|
1000
|
+
let valA, valB;
|
|
1001
|
+
for (let orderBy of query.orderBy) {
|
|
1002
|
+
let invert = orderBy.direction === "ASC" ? 1 : -1;
|
|
1003
|
+
valA = WebdaQL.ComparisonExpression.getAttributeValue(a, orderBy.field.split("."));
|
|
1004
|
+
valB = WebdaQL.ComparisonExpression.getAttributeValue(b, orderBy.field.split("."));
|
|
1005
|
+
if (valA === valB) {
|
|
1006
|
+
continue;
|
|
1149
1007
|
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
result.continuationToken = (query.limit + originalOffset).toString();
|
|
1008
|
+
if (typeof valA === "string") {
|
|
1009
|
+
return valA.localeCompare(valB) * invert;
|
|
1010
|
+
}
|
|
1011
|
+
return (valA < valB ? -1 : 1) * invert;
|
|
1155
1012
|
}
|
|
1013
|
+
return -1;
|
|
1014
|
+
});
|
|
1015
|
+
result.results = result.results.slice(originalOffset, query.limit + originalOffset);
|
|
1016
|
+
if (result.results.length >= query.limit) {
|
|
1017
|
+
result.continuationToken = (query.limit + originalOffset).toString();
|
|
1156
1018
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1019
|
+
}
|
|
1020
|
+
return result;
|
|
1021
|
+
}
|
|
1022
|
+
getOpenApiReplacements() {
|
|
1023
|
+
return {
|
|
1024
|
+
modelName: this._model.name
|
|
1025
|
+
};
|
|
1159
1026
|
}
|
|
1160
1027
|
/**
|
|
1161
1028
|
* Handle POST
|
|
1162
1029
|
* @param ctx
|
|
1163
1030
|
*/
|
|
1164
|
-
httpCreate(ctx) {
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
store: this
|
|
1187
|
-
});
|
|
1031
|
+
async httpCreate(ctx) {
|
|
1032
|
+
let body = await ctx.getRequestBody();
|
|
1033
|
+
let object = this._model.factory(this._model, body, ctx);
|
|
1034
|
+
object[this._creationDateField] = new Date();
|
|
1035
|
+
await object.canAct(ctx, "create");
|
|
1036
|
+
try {
|
|
1037
|
+
await object.validate(ctx, body);
|
|
1038
|
+
}
|
|
1039
|
+
catch (err) {
|
|
1040
|
+
this.log("INFO", "Object is not valid", err);
|
|
1041
|
+
throw 400;
|
|
1042
|
+
}
|
|
1043
|
+
if (object[this._uuidField] && (await this.exists(object[this._uuidField]))) {
|
|
1044
|
+
throw 409;
|
|
1045
|
+
}
|
|
1046
|
+
await this.save(object, ctx);
|
|
1047
|
+
ctx.write(object);
|
|
1048
|
+
await this.emitSync("Store.WebCreate", {
|
|
1049
|
+
context: ctx,
|
|
1050
|
+
values: body,
|
|
1051
|
+
object: object,
|
|
1052
|
+
store: this
|
|
1188
1053
|
});
|
|
1189
1054
|
}
|
|
1190
1055
|
/**
|
|
1191
1056
|
* Handle obect action
|
|
1192
1057
|
* @param ctx
|
|
1193
1058
|
*/
|
|
1194
|
-
httpAction(ctx) {
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
result: res
|
|
1218
|
-
});
|
|
1059
|
+
async httpAction(ctx) {
|
|
1060
|
+
let action = ctx.getHttpContext().getUrl().split("/").pop();
|
|
1061
|
+
let object = await this.get(ctx.parameter("uuid"), ctx);
|
|
1062
|
+
if (object === undefined || object.__deleted) {
|
|
1063
|
+
throw 404;
|
|
1064
|
+
}
|
|
1065
|
+
await object.canAct(ctx, action);
|
|
1066
|
+
await this.emitSync("Store.Action", {
|
|
1067
|
+
action: action,
|
|
1068
|
+
object: object,
|
|
1069
|
+
store: this,
|
|
1070
|
+
context: ctx
|
|
1071
|
+
});
|
|
1072
|
+
let res = await object["_" + action](ctx);
|
|
1073
|
+
if (res) {
|
|
1074
|
+
ctx.write(res);
|
|
1075
|
+
}
|
|
1076
|
+
await this.emitSync("Store.Actioned", {
|
|
1077
|
+
action: action,
|
|
1078
|
+
object: object,
|
|
1079
|
+
store: this,
|
|
1080
|
+
context: ctx,
|
|
1081
|
+
result: res
|
|
1219
1082
|
});
|
|
1220
1083
|
}
|
|
1221
1084
|
/**
|
|
1222
1085
|
* Handle collection action
|
|
1223
1086
|
* @param ctx
|
|
1224
1087
|
*/
|
|
1225
|
-
httpGlobalAction(ctx) {
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
result: res
|
|
1242
|
-
});
|
|
1088
|
+
async httpGlobalAction(ctx) {
|
|
1089
|
+
let action = ctx.getHttpContext().getUrl().split("/").pop();
|
|
1090
|
+
await this.emitSync("Store.Action", {
|
|
1091
|
+
action: action,
|
|
1092
|
+
store: this,
|
|
1093
|
+
context: ctx
|
|
1094
|
+
});
|
|
1095
|
+
let res = await this._model["_" + action](ctx);
|
|
1096
|
+
if (res) {
|
|
1097
|
+
ctx.write(res);
|
|
1098
|
+
}
|
|
1099
|
+
await this.emitSync("Store.Actioned", {
|
|
1100
|
+
action: action,
|
|
1101
|
+
store: this,
|
|
1102
|
+
context: ctx,
|
|
1103
|
+
result: res
|
|
1243
1104
|
});
|
|
1244
1105
|
}
|
|
1245
1106
|
/**
|
|
@@ -1247,62 +1108,60 @@ class Store extends service_1.Service {
|
|
|
1247
1108
|
*
|
|
1248
1109
|
* @param ctx context of the request
|
|
1249
1110
|
*/
|
|
1250
|
-
httpUpdate(ctx) {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
yield object.validate(ctx, body);
|
|
1262
|
-
}
|
|
1263
|
-
catch (err) {
|
|
1264
|
-
this.log("INFO", "Object invalid", err);
|
|
1265
|
-
throw 400;
|
|
1266
|
-
}
|
|
1267
|
-
let updateObject = new this._model();
|
|
1268
|
-
// Clean any default attributes from the model
|
|
1269
|
-
Object.keys(updateObject)
|
|
1270
|
-
.filter(i => i !== "__class")
|
|
1271
|
-
.forEach(i => {
|
|
1272
|
-
delete updateObject[i];
|
|
1273
|
-
});
|
|
1274
|
-
updateObject.setContext(ctx);
|
|
1275
|
-
updateObject.load(body);
|
|
1276
|
-
yield this.patch(updateObject);
|
|
1277
|
-
object = undefined;
|
|
1111
|
+
async httpUpdate(ctx) {
|
|
1112
|
+
let body = await ctx.getRequestBody();
|
|
1113
|
+
let uuid = ctx.parameter("uuid");
|
|
1114
|
+
body[this._uuidField] = uuid;
|
|
1115
|
+
let object = await this.get(uuid, ctx);
|
|
1116
|
+
if (!object || object.__deleted)
|
|
1117
|
+
throw 404;
|
|
1118
|
+
await object.canAct(ctx, "update");
|
|
1119
|
+
if (ctx.getHttpContext().getMethod() === "PATCH") {
|
|
1120
|
+
try {
|
|
1121
|
+
await object.validate(ctx, body);
|
|
1278
1122
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
// Copy back the _ attributes
|
|
1283
|
-
Object.keys(object)
|
|
1284
|
-
.filter(i => i.startsWith("_"))
|
|
1285
|
-
.forEach(i => {
|
|
1286
|
-
updateObject[i] = object[i];
|
|
1287
|
-
});
|
|
1288
|
-
try {
|
|
1289
|
-
yield updateObject.validate(ctx, body);
|
|
1290
|
-
}
|
|
1291
|
-
catch (err) {
|
|
1292
|
-
this.log("INFO", "Object invalid", err);
|
|
1293
|
-
throw 400;
|
|
1294
|
-
}
|
|
1295
|
-
// Add mappers back to
|
|
1296
|
-
object = yield this.update(updateObject);
|
|
1123
|
+
catch (err) {
|
|
1124
|
+
this.log("INFO", "Object invalid", err);
|
|
1125
|
+
throw 400;
|
|
1297
1126
|
}
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
method: ctx.getHttpContext().getMethod()
|
|
1127
|
+
let updateObject = new this._model();
|
|
1128
|
+
// Clean any default attributes from the model
|
|
1129
|
+
Object.keys(updateObject)
|
|
1130
|
+
.filter(i => i !== "__class")
|
|
1131
|
+
.forEach(i => {
|
|
1132
|
+
delete updateObject[i];
|
|
1305
1133
|
});
|
|
1134
|
+
updateObject.setContext(ctx);
|
|
1135
|
+
updateObject.load(body);
|
|
1136
|
+
await this.patch(updateObject);
|
|
1137
|
+
object = undefined;
|
|
1138
|
+
}
|
|
1139
|
+
else {
|
|
1140
|
+
let updateObject = new this._model();
|
|
1141
|
+
updateObject.load(body);
|
|
1142
|
+
// Copy back the _ attributes
|
|
1143
|
+
Object.keys(object)
|
|
1144
|
+
.filter(i => i.startsWith("_"))
|
|
1145
|
+
.forEach(i => {
|
|
1146
|
+
updateObject[i] = object[i];
|
|
1147
|
+
});
|
|
1148
|
+
try {
|
|
1149
|
+
await updateObject.validate(ctx, body);
|
|
1150
|
+
}
|
|
1151
|
+
catch (err) {
|
|
1152
|
+
this.log("INFO", "Object invalid", err);
|
|
1153
|
+
throw 400;
|
|
1154
|
+
}
|
|
1155
|
+
// Add mappers back to
|
|
1156
|
+
object = await this.update(updateObject);
|
|
1157
|
+
}
|
|
1158
|
+
ctx.write(object);
|
|
1159
|
+
await this.emitSync("Store.WebUpdate", {
|
|
1160
|
+
context: ctx,
|
|
1161
|
+
updates: body,
|
|
1162
|
+
object: object,
|
|
1163
|
+
store: this,
|
|
1164
|
+
method: ctx.getHttpContext().getMethod()
|
|
1306
1165
|
});
|
|
1307
1166
|
}
|
|
1308
1167
|
/**
|
|
@@ -1310,32 +1169,25 @@ class Store extends service_1.Service {
|
|
|
1310
1169
|
*
|
|
1311
1170
|
* @param ctx context of the request
|
|
1312
1171
|
*/
|
|
1313
|
-
httpGet(ctx) {
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
object: object,
|
|
1331
|
-
store: this
|
|
1332
|
-
});
|
|
1333
|
-
ctx.write(object);
|
|
1334
|
-
}
|
|
1335
|
-
else {
|
|
1336
|
-
// List probably
|
|
1337
|
-
}
|
|
1172
|
+
async httpGet(ctx) {
|
|
1173
|
+
let uuid = ctx.parameter("uuid");
|
|
1174
|
+
let object = await this.get(uuid, ctx);
|
|
1175
|
+
await this.emitSync("Store.WebGetNotFound", {
|
|
1176
|
+
context: ctx,
|
|
1177
|
+
uuid,
|
|
1178
|
+
store: this
|
|
1179
|
+
});
|
|
1180
|
+
if (object === undefined || object.__deleted) {
|
|
1181
|
+
throw 404;
|
|
1182
|
+
}
|
|
1183
|
+
await object.canAct(ctx, "get");
|
|
1184
|
+
ctx.write(object);
|
|
1185
|
+
await this.emitSync("Store.WebGet", {
|
|
1186
|
+
context: ctx,
|
|
1187
|
+
object: object,
|
|
1188
|
+
store: this
|
|
1338
1189
|
});
|
|
1190
|
+
ctx.write(object);
|
|
1339
1191
|
}
|
|
1340
1192
|
/**
|
|
1341
1193
|
* Handle HTTP request
|
|
@@ -1343,31 +1195,21 @@ class Store extends service_1.Service {
|
|
|
1343
1195
|
* @param ctx context of the request
|
|
1344
1196
|
* @returns
|
|
1345
1197
|
*/
|
|
1346
|
-
httpRoute(ctx) {
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
yield this.delete(uuid);
|
|
1362
|
-
yield this.emitSync("Store.WebDelete", {
|
|
1363
|
-
context: ctx,
|
|
1364
|
-
object_id: uuid,
|
|
1365
|
-
store: this
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
|
-
else if (ctx.getHttpContext().getMethod() === "PUT" || ctx.getHttpContext().getMethod() === "PATCH") {
|
|
1369
|
-
return this.httpUpdate(ctx);
|
|
1370
|
-
}
|
|
1198
|
+
async httpRoute(ctx) {
|
|
1199
|
+
let uuid = ctx.parameter("uuid");
|
|
1200
|
+
let object = await this.get(uuid, ctx);
|
|
1201
|
+
if (!object || object.__deleted)
|
|
1202
|
+
throw 404;
|
|
1203
|
+
await object.canAct(ctx, "delete");
|
|
1204
|
+
// http://stackoverflow.com/questions/28684209/huge-delay-on-delete-requests-with-204-response-and-no-content-in-objectve-c#
|
|
1205
|
+
// IOS don't handle 204 with Content-Length != 0 it seems
|
|
1206
|
+
// Have trouble to handle the Content-Length on API Gateway so returning an empty object for now
|
|
1207
|
+
ctx.write({});
|
|
1208
|
+
await this.delete(uuid);
|
|
1209
|
+
await this.emitSync("Store.WebDelete", {
|
|
1210
|
+
context: ctx,
|
|
1211
|
+
object_id: uuid,
|
|
1212
|
+
store: this
|
|
1371
1213
|
});
|
|
1372
1214
|
}
|
|
1373
1215
|
/**
|
|
@@ -1377,5 +1219,135 @@ class Store extends service_1.Service {
|
|
|
1377
1219
|
return this._uuidField;
|
|
1378
1220
|
}
|
|
1379
1221
|
}
|
|
1380
|
-
|
|
1222
|
+
__decorate([
|
|
1223
|
+
Route(".", ["POST"], false, {
|
|
1224
|
+
post: {
|
|
1225
|
+
description: "The way to create a new ${modelName} model",
|
|
1226
|
+
summary: "Create a new ${modelName}",
|
|
1227
|
+
operationId: "create${modelName}",
|
|
1228
|
+
requestBody: {
|
|
1229
|
+
content: {
|
|
1230
|
+
"application/json": {
|
|
1231
|
+
schema: {
|
|
1232
|
+
$ref: "#/components/schemas/${modelName}"
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
},
|
|
1237
|
+
responses: {
|
|
1238
|
+
"200": {
|
|
1239
|
+
description: "Retrieve model",
|
|
1240
|
+
content: {
|
|
1241
|
+
"application/json": {
|
|
1242
|
+
schema: {
|
|
1243
|
+
$ref: "#/components/schemas/${modelName}"
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
},
|
|
1248
|
+
"400": {
|
|
1249
|
+
description: "Object is invalid"
|
|
1250
|
+
},
|
|
1251
|
+
"403": {
|
|
1252
|
+
description: "You don't have permissions"
|
|
1253
|
+
},
|
|
1254
|
+
"409": {
|
|
1255
|
+
description: "Object already exists"
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
})
|
|
1260
|
+
], Store.prototype, "httpCreate", null);
|
|
1261
|
+
__decorate([
|
|
1262
|
+
Route("./{uuid}", ["PUT", "PATCH"], false, {
|
|
1263
|
+
put: {
|
|
1264
|
+
description: "Update a ${modelName} if the permissions allow",
|
|
1265
|
+
summary: "Update a ${modelName}",
|
|
1266
|
+
operationId: "updatet${modelName}",
|
|
1267
|
+
schemas: {
|
|
1268
|
+
input: "${modelName}",
|
|
1269
|
+
output: "${modelName}"
|
|
1270
|
+
},
|
|
1271
|
+
responses: {
|
|
1272
|
+
"200": {},
|
|
1273
|
+
"400": {
|
|
1274
|
+
description: "Object is invalid"
|
|
1275
|
+
},
|
|
1276
|
+
"403": {
|
|
1277
|
+
description: "You don't have permissions"
|
|
1278
|
+
},
|
|
1279
|
+
"404": {
|
|
1280
|
+
description: "Unknown object"
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
},
|
|
1284
|
+
patch: {
|
|
1285
|
+
description: "Patch a ${modelName} if the permissions allow",
|
|
1286
|
+
summary: "Patch a ${modelName}",
|
|
1287
|
+
operationId: "partialUpdatet${modelName}",
|
|
1288
|
+
schemas: {
|
|
1289
|
+
input: "${modelName}"
|
|
1290
|
+
},
|
|
1291
|
+
responses: {
|
|
1292
|
+
"204": {
|
|
1293
|
+
description: ""
|
|
1294
|
+
},
|
|
1295
|
+
"400": {
|
|
1296
|
+
description: "Object is invalid"
|
|
1297
|
+
},
|
|
1298
|
+
"403": {
|
|
1299
|
+
description: "You don't have permissions"
|
|
1300
|
+
},
|
|
1301
|
+
"404": {
|
|
1302
|
+
description: "Unknown object"
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
})
|
|
1307
|
+
], Store.prototype, "httpUpdate", null);
|
|
1308
|
+
__decorate([
|
|
1309
|
+
Route("./{uuid}", ["GET"], false, {
|
|
1310
|
+
get: {
|
|
1311
|
+
description: "Retrieve ${modelName} model if permissions allow",
|
|
1312
|
+
summary: "Retrieve a ${modelName}",
|
|
1313
|
+
operationId: "get${modelName}",
|
|
1314
|
+
schemas: {
|
|
1315
|
+
output: "${modelName}"
|
|
1316
|
+
},
|
|
1317
|
+
responses: {
|
|
1318
|
+
"200": {},
|
|
1319
|
+
"400": {
|
|
1320
|
+
description: "Object is invalid"
|
|
1321
|
+
},
|
|
1322
|
+
"403": {
|
|
1323
|
+
description: "You don't have permissions"
|
|
1324
|
+
},
|
|
1325
|
+
"404": {
|
|
1326
|
+
description: "Unknown object"
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
})
|
|
1331
|
+
], Store.prototype, "httpGet", null);
|
|
1332
|
+
__decorate([
|
|
1333
|
+
Route("./{uuid}", ["DELETE"], false, {
|
|
1334
|
+
delete: {
|
|
1335
|
+
operationId: "delete${modelName}",
|
|
1336
|
+
description: "Delete ${modelName} if the permissions allow",
|
|
1337
|
+
summary: "Delete a ${modelName}",
|
|
1338
|
+
responses: {
|
|
1339
|
+
"204": {
|
|
1340
|
+
description: ""
|
|
1341
|
+
},
|
|
1342
|
+
"403": {
|
|
1343
|
+
description: "You don't have permissions"
|
|
1344
|
+
},
|
|
1345
|
+
"404": {
|
|
1346
|
+
description: "Unknown object"
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
})
|
|
1351
|
+
], Store.prototype, "httpRoute", null);
|
|
1352
|
+
export { Store };
|
|
1381
1353
|
//# sourceMappingURL=store.js.map
|