@webda/core 3.6.0 → 3.8.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 +7 -1
- package/lib/application.js.map +1 -1
- package/lib/core.d.ts +9 -0
- package/lib/core.js +44 -1
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +5 -4
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +5 -4
- package/lib/index.js +5 -4
- package/lib/index.js.map +1 -1
- package/lib/models/coremodel.d.ts +103 -12
- package/lib/models/coremodel.js +230 -33
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +21 -4
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/ident.d.ts +2 -6
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/relations.d.ts +24 -14
- package/lib/models/relations.js +36 -8
- package/lib/models/relations.js.map +1 -1
- package/lib/models/relations.spec.d.ts +12 -0
- package/lib/models/relations.spec.js +223 -0
- package/lib/models/relations.spec.js.map +1 -0
- package/lib/models/user.d.ts +2 -2
- package/lib/models/user.js.map +1 -1
- package/lib/services/asyncevents.d.ts +4 -3
- package/lib/services/asyncevents.js +17 -4
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/authentication.js +1 -1
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/binary.d.ts +26 -2
- package/lib/services/binary.js +160 -63
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.js +3 -1
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +0 -18
- package/lib/services/cloudbinary.js +0 -94
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/cloudbinary.spec.js +18 -11
- package/lib/services/cloudbinary.spec.js.map +1 -1
- package/lib/services/domainservice.d.ts +2 -1
- package/lib/services/domainservice.js +13 -22
- package/lib/services/domainservice.js.map +1 -1
- package/lib/services/filebinary.js +1 -1
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +1 -0
- package/lib/services/filebinary.spec.js +24 -2
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/invitationservice.spec.js +3 -1
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/prometheus.js +1 -0
- package/lib/services/prometheus.js.map +1 -1
- package/lib/services/service.d.ts +0 -5
- package/lib/services/service.js +3 -34
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.js +2 -2
- package/lib/services/service.spec.js.map +1 -1
- package/lib/stores/aliasstore.js +5 -1
- package/lib/stores/aliasstore.js.map +1 -1
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/mapper.d.ts +4 -4
- package/lib/stores/mapper.spec.js +1 -1
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +1 -0
- package/lib/stores/memory.spec.js +28 -1
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/modelmapper.d.ts +61 -0
- package/lib/stores/modelmapper.js +199 -0
- package/lib/stores/modelmapper.js.map +1 -0
- package/lib/stores/store.d.ts +33 -11
- package/lib/stores/store.js +155 -95
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.js +2 -2
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/test.js +1 -1
- package/lib/test.js.map +1 -1
- package/lib/utils/case.d.ts +7 -0
- package/lib/utils/case.js +43 -0
- package/lib/utils/case.js.map +1 -0
- package/lib/utils/case.spec.d.ts +1 -0
- package/lib/utils/case.spec.js +50 -0
- package/lib/utils/case.spec.js.map +1 -0
- package/lib/utils/context.d.ts +3 -2
- package/lib/utils/context.js +6 -2
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/cookie.spec.js +2 -2
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/esm.d.ts +9 -0
- package/lib/utils/esm.js +9 -0
- package/lib/utils/esm.js.map +1 -1
- package/lib/utils/httpcontext.d.ts +1 -1
- package/lib/utils/httpcontext.js +1 -0
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/logger.spec.js +5 -2
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +8 -1
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +6 -0
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/session.spec.js +1 -1
- package/lib/utils/session.spec.js.map +1 -1
- package/lib/utils/throttler.d.ts +22 -2
- package/lib/utils/throttler.js +35 -3
- package/lib/utils/throttler.js.map +1 -1
- package/lib/utils/throttler.spec.js +10 -2
- package/lib/utils/throttler.spec.js.map +1 -1
- package/package.json +10 -10
- package/webda.module.json +60 -26
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CoreModel, CoreModelDefinition } from "../models/coremodel.js";
|
|
2
|
+
import { Service } from "../services/service.js";
|
|
3
|
+
export interface Mapper {
|
|
4
|
+
modelAttribute: string;
|
|
5
|
+
model: CoreModelDefinition<CoreModel>;
|
|
6
|
+
attributes: string[];
|
|
7
|
+
attribute: string;
|
|
8
|
+
}
|
|
9
|
+
interface ModelMapperInfo {
|
|
10
|
+
modelAttribute: string;
|
|
11
|
+
model: CoreModelDefinition<CoreModel>;
|
|
12
|
+
attributes: string[];
|
|
13
|
+
attribute: string;
|
|
14
|
+
type: "LINK" | "LINKS_MAP" | "LINKS_ARRAY" | "LINKS_SIMPLE_ARRAY";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Mapper service
|
|
18
|
+
*
|
|
19
|
+
* Ensure each ModelMapped properties is in-sync with their respective model
|
|
20
|
+
*/
|
|
21
|
+
export declare class ModelMapper extends Service {
|
|
22
|
+
mappers: {
|
|
23
|
+
[key: string]: ModelMapperInfo[];
|
|
24
|
+
};
|
|
25
|
+
resolve(): this;
|
|
26
|
+
/**
|
|
27
|
+
* Get uuids from a ModelLinker
|
|
28
|
+
* @param object
|
|
29
|
+
* @param mapper
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getUuidsFromMapper(object: CoreModel, mapper: ModelMapperInfo): any[];
|
|
33
|
+
/**
|
|
34
|
+
* Handle event
|
|
35
|
+
* @param modelName
|
|
36
|
+
* @param evt
|
|
37
|
+
* @param type
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
handleEvent(modelName: string, evt: any, type: "Store.Saved" | "Store.Deleted" | "Store.Updated" | "Store.PatchUpdated" | "Store.PartialUpdated"): Promise<any[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Handle partial event to update a mapper
|
|
43
|
+
*
|
|
44
|
+
* @param modelName
|
|
45
|
+
* @param evt
|
|
46
|
+
* @param type
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
handlePartialEvent(modelName: string, evt: any, type: "Store.Saved" | "Store.Deleted" | "Store.Updated" | "Store.PatchUpdated" | "Store.PartialUpdated"): Promise<any[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Get a mapped object based on Mapper
|
|
52
|
+
*
|
|
53
|
+
* Copy attributes that are supposed to be copied
|
|
54
|
+
*
|
|
55
|
+
* @param model
|
|
56
|
+
* @param mapper
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
getMapped(model: any, mapper: Mapper): any;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Service } from "../services/service.js";
|
|
2
|
+
/**
|
|
3
|
+
* Mapper service
|
|
4
|
+
*
|
|
5
|
+
* Ensure each ModelMapped properties is in-sync with their respective model
|
|
6
|
+
*/
|
|
7
|
+
export class ModelMapper extends Service {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.mappers = {};
|
|
11
|
+
}
|
|
12
|
+
resolve() {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
super.resolve();
|
|
15
|
+
const app = this.getWebda().getApplication();
|
|
16
|
+
const graph = app.getGraph();
|
|
17
|
+
for (let i in graph) {
|
|
18
|
+
if (!graph[i].maps)
|
|
19
|
+
continue;
|
|
20
|
+
this.log("INFO", i, graph[i].maps);
|
|
21
|
+
const targetModel = app.getModel(i);
|
|
22
|
+
for (let j in graph[i].maps) {
|
|
23
|
+
const mapper = graph[i].maps[j];
|
|
24
|
+
(_a = this.mappers)[_b = mapper.model] ?? (_a[_b] = []);
|
|
25
|
+
// Search for links
|
|
26
|
+
this.mappers[mapper.model].push({
|
|
27
|
+
attribute: mapper.targetLink,
|
|
28
|
+
attributes: mapper.targetAttributes,
|
|
29
|
+
model: targetModel,
|
|
30
|
+
modelAttribute: mapper.attribute,
|
|
31
|
+
type: graph[mapper.model].links?.find(p => p.attribute === mapper.targetLink)?.type || "LINK"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
this.log("INFO", "Add listeners for", this.mappers);
|
|
36
|
+
for (let modelName in this.mappers) {
|
|
37
|
+
const model = app.getModel(modelName);
|
|
38
|
+
model.on("Store.Deleted", async (evt) => {
|
|
39
|
+
return this.handleEvent(modelName, evt, "Store.Deleted");
|
|
40
|
+
});
|
|
41
|
+
model.on("Store.Saved", async (evt) => {
|
|
42
|
+
return this.handleEvent(modelName, evt, "Store.Saved");
|
|
43
|
+
});
|
|
44
|
+
model.on("Store.Updated", async (evt) => {
|
|
45
|
+
return this.handleEvent(modelName, evt, "Store.Updated");
|
|
46
|
+
});
|
|
47
|
+
model.on("Store.PatchUpdated", async (evt) => {
|
|
48
|
+
return this.handlePartialEvent(modelName, evt, "Store.PatchUpdated");
|
|
49
|
+
});
|
|
50
|
+
model.on("Store.PartialUpdated", async (evt) => {
|
|
51
|
+
return this.handlePartialEvent(modelName, evt, "Store.PartialUpdated");
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get uuids from a ModelLinker
|
|
58
|
+
* @param object
|
|
59
|
+
* @param mapper
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
getUuidsFromMapper(object, mapper) {
|
|
63
|
+
const targetUuids = [];
|
|
64
|
+
if (mapper.type === "LINK") {
|
|
65
|
+
targetUuids.push(object[mapper.attribute]?.getUuid());
|
|
66
|
+
}
|
|
67
|
+
else if (mapper.type === "LINKS_MAP") {
|
|
68
|
+
targetUuids.push(...Object.values(object[mapper.attribute]).map((p) => p.getUuid()));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
targetUuids.push(...object[mapper.attribute].map(p => (typeof p === "string" ? p : p.getUuid())));
|
|
72
|
+
}
|
|
73
|
+
return targetUuids.filter(p => p);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Handle event
|
|
77
|
+
* @param modelName
|
|
78
|
+
* @param evt
|
|
79
|
+
* @param type
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
async handleEvent(modelName, evt, type) {
|
|
83
|
+
let p = [];
|
|
84
|
+
for (let mapper of this.mappers[modelName]) {
|
|
85
|
+
// For each mapper we identify uuid to add mapper to, uuid to remove mapper from and uuid to update
|
|
86
|
+
const toAdds = [];
|
|
87
|
+
const toRemoves = [];
|
|
88
|
+
const toUpdates = [];
|
|
89
|
+
if (type === "Store.Saved") {
|
|
90
|
+
toAdds.push(...this.getUuidsFromMapper(evt.object, mapper));
|
|
91
|
+
}
|
|
92
|
+
else if (type === "Store.Deleted") {
|
|
93
|
+
toRemoves.push(...this.getUuidsFromMapper(evt.object, mapper));
|
|
94
|
+
}
|
|
95
|
+
else if (type === "Store.Updated") {
|
|
96
|
+
const oldUuids = this.getUuidsFromMapper(evt.previous, mapper);
|
|
97
|
+
const newUuids = this.getUuidsFromMapper(evt.object, mapper);
|
|
98
|
+
oldUuids.forEach(u => {
|
|
99
|
+
if (newUuids.includes(u)) {
|
|
100
|
+
toUpdates.push(u);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
toRemoves.push(u);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
newUuids.forEach(u => {
|
|
107
|
+
if (!oldUuids.includes(u)) {
|
|
108
|
+
toAdds.push(u);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const mapped = this.getMapped(evt.object, mapper);
|
|
113
|
+
// Add all promise
|
|
114
|
+
toAdds.forEach(u => {
|
|
115
|
+
p.push(mapper.model.ref(u).upsertItemToCollection(mapper.modelAttribute, mapped));
|
|
116
|
+
});
|
|
117
|
+
// Remove all promise
|
|
118
|
+
toRemoves.forEach(u => {
|
|
119
|
+
p.push((async () => {
|
|
120
|
+
const targetModel = await mapper.model.ref(u).get();
|
|
121
|
+
if (!targetModel)
|
|
122
|
+
return;
|
|
123
|
+
const ind = targetModel[mapper.modelAttribute].findIndex(p => p.uuid === evt.object.getUuid());
|
|
124
|
+
if (ind >= 0) {
|
|
125
|
+
await mapper.model.ref(u).deleteItemFromCollection(mapper.modelAttribute, ind, evt.object.getUuid());
|
|
126
|
+
}
|
|
127
|
+
})());
|
|
128
|
+
});
|
|
129
|
+
// Update all promise
|
|
130
|
+
toUpdates.forEach(u => {
|
|
131
|
+
p.push((async () => {
|
|
132
|
+
const targetModel = await mapper.model.ref(u).get();
|
|
133
|
+
if (!targetModel)
|
|
134
|
+
return;
|
|
135
|
+
const ind = targetModel[mapper.modelAttribute].findIndex(p => p.uuid === evt.object.getUuid());
|
|
136
|
+
if (ind >= 0) {
|
|
137
|
+
await mapper.model
|
|
138
|
+
.ref(u)
|
|
139
|
+
.upsertItemToCollection(mapper.modelAttribute, mapped, ind, evt.object.getUuid());
|
|
140
|
+
}
|
|
141
|
+
})());
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return Promise.all(p);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Handle partial event to update a mapper
|
|
148
|
+
*
|
|
149
|
+
* @param modelName
|
|
150
|
+
* @param evt
|
|
151
|
+
* @param type
|
|
152
|
+
* @returns
|
|
153
|
+
*/
|
|
154
|
+
async handlePartialEvent(modelName, evt, type) {
|
|
155
|
+
let uuid = evt.object?.getUuid();
|
|
156
|
+
// Only use in Store.PartialUpdated
|
|
157
|
+
const attributes = [];
|
|
158
|
+
if (type === "Store.PartialUpdated") {
|
|
159
|
+
const partial = evt;
|
|
160
|
+
if (partial.partial_update.increments) {
|
|
161
|
+
attributes.push(...partial.partial_update.increments.map(p => p.property));
|
|
162
|
+
}
|
|
163
|
+
if (partial.partial_update.deleteAttribute) {
|
|
164
|
+
attributes.push(partial.partial_update.deleteAttribute);
|
|
165
|
+
}
|
|
166
|
+
uuid = partial.object_id;
|
|
167
|
+
}
|
|
168
|
+
else if (type === "Store.PatchUpdated") {
|
|
169
|
+
attributes.push(...Object.keys(evt.object));
|
|
170
|
+
}
|
|
171
|
+
for (let mapper of this.mappers[modelName]) {
|
|
172
|
+
this.log("TRACE", "Should update a mapper based on Store.PartialUpdated", evt);
|
|
173
|
+
const partial = evt;
|
|
174
|
+
// Search if one property is mapped then redirect to Store.Updated
|
|
175
|
+
if (mapper.attributes.find(p => attributes.find(i => i === p))) {
|
|
176
|
+
const object = await partial.store.get(uuid);
|
|
177
|
+
return await this.handleEvent(modelName, { object, previous: object }, "Store.Updated");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get a mapped object based on Mapper
|
|
183
|
+
*
|
|
184
|
+
* Copy attributes that are supposed to be copied
|
|
185
|
+
*
|
|
186
|
+
* @param model
|
|
187
|
+
* @param mapper
|
|
188
|
+
* @returns
|
|
189
|
+
*/
|
|
190
|
+
getMapped(model, mapper) {
|
|
191
|
+
let obj = {};
|
|
192
|
+
for (let attr of mapper.attributes) {
|
|
193
|
+
obj[attr] = model[attr];
|
|
194
|
+
}
|
|
195
|
+
obj["uuid"] = model.getUuid();
|
|
196
|
+
return obj;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=modelmapper.js.map
|
|
@@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AsD,EAAE,GAAG,CAAC,CAAC;YAC/E,MAAM,OAAO,GAA6B,GAAG,CAAC;YAC9C,kEAAkE;YAClE,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;gBAC9D,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC7C,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,eAAe,CAAC,CAAC;aACzF;SACF;IACH,CAAC;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,KAAU,EAAE,MAAc;QAClC,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,UAAU,EAAE;YAClC,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;SACzB;QACD,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
package/lib/stores/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Counter, EventWithContext, Histogram } from "../core.js";
|
|
2
2
|
import { ConfigurationProvider, WebdaError } from "../index.js";
|
|
3
|
-
import { Constructor, CoreModel, CoreModelDefinition,
|
|
3
|
+
import { Constructor, CoreModel, CoreModelDefinition, FilterAttributes } from "../models/coremodel.js";
|
|
4
4
|
import { Service, ServiceParameters } from "../services/service.js";
|
|
5
5
|
import { OperationContext, WebContext } from "../utils/context.js";
|
|
6
6
|
import { HttpMethodType } from "../utils/httpcontext.js";
|
|
@@ -83,7 +83,7 @@ export interface EventStoreActioned extends EventStoreAction {
|
|
|
83
83
|
/**
|
|
84
84
|
* Event called before update of an object
|
|
85
85
|
*/
|
|
86
|
-
export interface EventStoreUpdate extends
|
|
86
|
+
export interface EventStoreUpdate extends EventStore {
|
|
87
87
|
/**
|
|
88
88
|
* Update content
|
|
89
89
|
*/
|
|
@@ -92,7 +92,11 @@ export interface EventStoreUpdate extends EventStoreUpdated {
|
|
|
92
92
|
/**
|
|
93
93
|
* Event called after update of an object
|
|
94
94
|
*/
|
|
95
|
-
export interface EventStoreUpdated extends
|
|
95
|
+
export interface EventStoreUpdated extends EventStoreUpdate {
|
|
96
|
+
/**
|
|
97
|
+
* Object before update
|
|
98
|
+
*/
|
|
99
|
+
previous: any;
|
|
96
100
|
}
|
|
97
101
|
/**
|
|
98
102
|
* Event called before patch update of an object
|
|
@@ -358,6 +362,14 @@ export declare class StoreParameters extends ServiceParameters {
|
|
|
358
362
|
* @default "Webda/CoreModel"
|
|
359
363
|
*/
|
|
360
364
|
model?: string;
|
|
365
|
+
/**
|
|
366
|
+
* Additional models
|
|
367
|
+
*
|
|
368
|
+
* Allow this store to manage other models
|
|
369
|
+
*
|
|
370
|
+
* @default []
|
|
371
|
+
*/
|
|
372
|
+
additionalModels?: string[];
|
|
361
373
|
/**
|
|
362
374
|
* async delete
|
|
363
375
|
*/
|
|
@@ -594,10 +606,10 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
|
|
|
594
606
|
* @param info
|
|
595
607
|
* @returns
|
|
596
608
|
*/
|
|
597
|
-
incrementAttributes<FK extends
|
|
609
|
+
incrementAttributes<FK extends FilterAttributes<T, number>>(uid: string, info: {
|
|
598
610
|
property: FK;
|
|
599
611
|
value: number;
|
|
600
|
-
}[]): Promise<
|
|
612
|
+
}[]): Promise<Date>;
|
|
601
613
|
/**
|
|
602
614
|
* Helper function that call incrementAttributes
|
|
603
615
|
* @param uid
|
|
@@ -605,7 +617,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
|
|
|
605
617
|
* @param value
|
|
606
618
|
* @returns
|
|
607
619
|
*/
|
|
608
|
-
incrementAttribute<FK extends
|
|
620
|
+
incrementAttribute<FK extends FilterAttributes<T, number>>(uid: string, prop: FK, value: number): Promise<Date>;
|
|
609
621
|
/**
|
|
610
622
|
* Add or update an item to an array in the model
|
|
611
623
|
*
|
|
@@ -616,7 +628,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
|
|
|
616
628
|
* @param itemWriteCondition value of the condition to test (in case of update)
|
|
617
629
|
* @param itemWriteConditionField field to read the condition from (in case of update)
|
|
618
630
|
*/
|
|
619
|
-
upsertItemToCollection<FK extends
|
|
631
|
+
upsertItemToCollection<FK extends FilterAttributes<T, Array<any>>>(uid: string, prop: FK, item: any, index?: number, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<Date>;
|
|
620
632
|
/**
|
|
621
633
|
* Remove an item from an array in the model
|
|
622
634
|
*
|
|
@@ -626,15 +638,25 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
|
|
|
626
638
|
* @param itemWriteCondition value of the condition
|
|
627
639
|
* @param itemWriteConditionField field to read the condition from
|
|
628
640
|
*/
|
|
629
|
-
deleteItemFromCollection<FK extends
|
|
641
|
+
deleteItemFromCollection<FK extends FilterAttributes<T, Array<any>>>(uid: string, prop: FK, index: number, itemWriteCondition: any, itemWriteConditionField?: string): Promise<Date>;
|
|
630
642
|
/**
|
|
631
|
-
*
|
|
643
|
+
* Iterate through the results
|
|
632
644
|
*
|
|
633
645
|
* This can be resource consuming
|
|
634
646
|
*
|
|
635
647
|
* @param query
|
|
636
648
|
* @param context
|
|
637
649
|
*/
|
|
650
|
+
iterate(query?: string, context?: OperationContext): AsyncGenerator<T>;
|
|
651
|
+
/**
|
|
652
|
+
* Query all the results
|
|
653
|
+
*
|
|
654
|
+
*
|
|
655
|
+
* @param query
|
|
656
|
+
* @param context
|
|
657
|
+
* @returns
|
|
658
|
+
* @deprecated use iterate instead
|
|
659
|
+
*/
|
|
638
660
|
queryAll(query: string, context?: OperationContext): Promise<T[]>;
|
|
639
661
|
/**
|
|
640
662
|
* Check that __type Comparison is only used with = and CONTAINS
|
|
@@ -695,7 +717,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
|
|
|
695
717
|
* @param condition
|
|
696
718
|
* @param uid
|
|
697
719
|
*/
|
|
698
|
-
checkCollectionUpdateCondition<FK extends
|
|
720
|
+
checkCollectionUpdateCondition<FK extends FilterAttributes<T, Array<any>>, CK extends keyof T>(model: T, collection: FK, conditionField?: CK, condition?: any, index?: number): void;
|
|
699
721
|
/**
|
|
700
722
|
* Update conditionally
|
|
701
723
|
* @param uuid
|
|
@@ -714,7 +736,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
|
|
|
714
736
|
* @param itemWriteConditionField
|
|
715
737
|
* @param updateDate
|
|
716
738
|
*/
|
|
717
|
-
simulateUpsertItemToCollection<FK extends
|
|
739
|
+
simulateUpsertItemToCollection<FK extends FilterAttributes<T, Array<any>>>(model: T, prop: FK, item: any, updateDate: Date, index?: number, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<void>;
|
|
718
740
|
/**
|
|
719
741
|
* Update an object
|
|
720
742
|
*
|