@declaro/data 2.0.0-beta.125 → 2.0.0-beta.127
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/dist/browser/index.js +11 -11
- package/dist/browser/index.js.map +6 -6
- package/dist/node/index.cjs +189 -92
- package/dist/node/index.cjs.map +6 -6
- package/dist/node/index.js +181 -84
- package/dist/node/index.js.map +6 -6
- package/dist/ts/application/model-controller.d.ts +15 -5
- package/dist/ts/application/model-controller.d.ts.map +1 -1
- package/dist/ts/application/read-only-model-controller.d.ts +5 -1
- package/dist/ts/application/read-only-model-controller.d.ts.map +1 -1
- package/dist/ts/domain/services/model-service.d.ts +8 -0
- package/dist/ts/domain/services/model-service.d.ts.map +1 -1
- package/dist/ts/domain/services/read-only-model-service.d.ts +8 -0
- package/dist/ts/domain/services/read-only-model-service.d.ts.map +1 -1
- package/dist/ts/shared/utils/schema-inheritance.test.d.ts +2 -0
- package/dist/ts/shared/utils/schema-inheritance.test.d.ts.map +1 -0
- package/dist/ts/shared/utils/test/animal-schema.d.ts +57 -0
- package/dist/ts/shared/utils/test/animal-schema.d.ts.map +1 -0
- package/dist/ts/shared/utils/test/animal-trait-schema.d.ts +55 -0
- package/dist/ts/shared/utils/test/animal-trait-schema.d.ts.map +1 -0
- package/dist/ts/shared/utils/test/elephant-schema.d.ts +30 -0
- package/dist/ts/shared/utils/test/elephant-schema.d.ts.map +1 -0
- package/dist/ts/shared/utils/test/elephant-trait-schema.d.ts +26 -0
- package/dist/ts/shared/utils/test/elephant-trait-schema.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/application/model-controller.ts +110 -59
- package/src/application/read-only-model-controller.ts +43 -25
- package/src/domain/services/model-service.test.ts +280 -0
- package/src/domain/services/model-service.ts +98 -66
- package/src/domain/services/read-only-model-service.test.ts +230 -0
- package/src/domain/services/read-only-model-service.ts +65 -40
- package/src/shared/utils/schema-inheritance.test.ts +295 -0
- package/src/shared/utils/test/animal-schema.ts +46 -0
- package/src/shared/utils/test/animal-trait-schema.ts +45 -0
- package/src/shared/utils/test/elephant-schema.ts +58 -0
- package/src/shared/utils/test/elephant-trait-schema.ts +53 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts +0 -1
- package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts.map +0 -1
- package/src/test/mock/repositories/mock-memory-repository.custom-lookup.test.ts +0 -0
package/dist/node/index.cjs
CHANGED
|
@@ -49,10 +49,11 @@ __export(exports_src, {
|
|
|
49
49
|
module.exports = __toCommonJS(exports_src);
|
|
50
50
|
|
|
51
51
|
// src/application/model-controller.ts
|
|
52
|
-
var
|
|
52
|
+
var import_core2 = require("@declaro/core");
|
|
53
53
|
|
|
54
54
|
// src/application/read-only-model-controller.ts
|
|
55
55
|
var import_auth = require("@declaro/auth");
|
|
56
|
+
var import_core = require("@declaro/core");
|
|
56
57
|
|
|
57
58
|
class ReadOnlyModelController {
|
|
58
59
|
service;
|
|
@@ -61,32 +62,48 @@ class ReadOnlyModelController {
|
|
|
61
62
|
this.service = service;
|
|
62
63
|
this.authValidator = authValidator;
|
|
63
64
|
}
|
|
64
|
-
async
|
|
65
|
-
|
|
65
|
+
async loadPermissions(lookup) {
|
|
66
|
+
return import_core.PermissionValidator.create().someOf([
|
|
66
67
|
this.service.getDescriptor("load", "*").toString(),
|
|
67
68
|
this.service.getDescriptor("read", "*").toString()
|
|
68
|
-
])
|
|
69
|
+
]);
|
|
70
|
+
}
|
|
71
|
+
async load(lookup, options) {
|
|
72
|
+
const permissions = await this.loadPermissions(lookup);
|
|
73
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
69
74
|
return this.service.load(lookup, options);
|
|
70
75
|
}
|
|
71
|
-
async
|
|
72
|
-
|
|
76
|
+
async loadManyPermissions(lookups) {
|
|
77
|
+
return import_core.PermissionValidator.create().someOf([
|
|
73
78
|
this.service.getDescriptor("loadMany", "*").toString(),
|
|
74
79
|
this.service.getDescriptor("read", "*").toString()
|
|
75
|
-
])
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
async loadMany(lookups, options) {
|
|
83
|
+
const permissions = await this.loadManyPermissions(lookups);
|
|
84
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
76
85
|
return this.service.loadMany(lookups, options);
|
|
77
86
|
}
|
|
78
|
-
async
|
|
79
|
-
|
|
87
|
+
async searchPermissions(input, options) {
|
|
88
|
+
return import_core.PermissionValidator.create().someOf([
|
|
80
89
|
this.service.getDescriptor("search", "*").toString(),
|
|
81
90
|
this.service.getDescriptor("read", "*").toString()
|
|
82
|
-
])
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
async search(input, options) {
|
|
94
|
+
const permissions = await this.searchPermissions(input, options);
|
|
95
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
83
96
|
return this.service.search(input, options);
|
|
84
97
|
}
|
|
85
|
-
async
|
|
86
|
-
|
|
98
|
+
async countPermissions(input, options) {
|
|
99
|
+
return import_core.PermissionValidator.create().someOf([
|
|
87
100
|
this.service.getDescriptor("count", "*").toString(),
|
|
88
101
|
this.service.getDescriptor("read", "*").toString()
|
|
89
|
-
])
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
async count(input, options) {
|
|
105
|
+
const permissions = await this.countPermissions(input, options);
|
|
106
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
90
107
|
return this.service.count(input, options);
|
|
91
108
|
}
|
|
92
109
|
}
|
|
@@ -100,69 +117,111 @@ class ModelController extends ReadOnlyModelController {
|
|
|
100
117
|
this.service = service;
|
|
101
118
|
this.authValidator = authValidator;
|
|
102
119
|
}
|
|
103
|
-
async
|
|
104
|
-
|
|
120
|
+
async createPermissions(input, options) {
|
|
121
|
+
return import_core2.PermissionValidator.create().someOf([
|
|
105
122
|
this.service.getDescriptor("create", "*").toString(),
|
|
106
123
|
this.service.getDescriptor("write", "*").toString()
|
|
107
|
-
])
|
|
108
|
-
return this.service.create(input);
|
|
124
|
+
]);
|
|
109
125
|
}
|
|
110
|
-
async
|
|
111
|
-
this.
|
|
126
|
+
async create(input, options) {
|
|
127
|
+
const permissions = await this.createPermissions(input, options);
|
|
128
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
129
|
+
return this.service.create(input, options);
|
|
130
|
+
}
|
|
131
|
+
async updatePermissions(lookup, input, options) {
|
|
132
|
+
return import_core2.PermissionValidator.create().someOf([
|
|
112
133
|
this.service.getDescriptor("update", "*").toString(),
|
|
113
134
|
this.service.getDescriptor("write", "*").toString()
|
|
114
|
-
])
|
|
115
|
-
return this.service.update(lookup, input);
|
|
135
|
+
]);
|
|
116
136
|
}
|
|
117
|
-
async
|
|
118
|
-
this.
|
|
137
|
+
async update(lookup, input, options) {
|
|
138
|
+
const permissions = await this.updatePermissions(lookup, input, options);
|
|
139
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
140
|
+
return this.service.update(lookup, input, options);
|
|
141
|
+
}
|
|
142
|
+
async removePermissions(lookup, options) {
|
|
143
|
+
return import_core2.PermissionValidator.create().someOf([
|
|
119
144
|
this.service.getDescriptor("remove", "*").toString(),
|
|
120
145
|
this.service.getDescriptor("write", "*").toString()
|
|
121
|
-
])
|
|
122
|
-
return this.service.remove(lookup);
|
|
146
|
+
]);
|
|
123
147
|
}
|
|
124
|
-
async
|
|
125
|
-
this.
|
|
148
|
+
async remove(lookup, options) {
|
|
149
|
+
const permissions = await this.removePermissions(lookup, options);
|
|
150
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
151
|
+
return this.service.remove(lookup, options);
|
|
152
|
+
}
|
|
153
|
+
async restorePermissions(lookup, options) {
|
|
154
|
+
return import_core2.PermissionValidator.create().someOf([
|
|
126
155
|
this.service.getDescriptor("restore", "*").toString(),
|
|
127
156
|
this.service.getDescriptor("write", "*").toString()
|
|
128
|
-
])
|
|
129
|
-
return this.service.restore(lookup);
|
|
157
|
+
]);
|
|
130
158
|
}
|
|
131
|
-
async
|
|
132
|
-
const
|
|
159
|
+
async restore(lookup, options) {
|
|
160
|
+
const permissions = await this.restorePermissions(lookup, options);
|
|
161
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
162
|
+
return this.service.restore(lookup, options);
|
|
163
|
+
}
|
|
164
|
+
async upsertPermissions(input, options) {
|
|
165
|
+
const createAndUpdateValidator = import_core2.PermissionValidator.create().allOf([
|
|
133
166
|
this.service.getDescriptor("create", "*").toString(),
|
|
134
167
|
this.service.getDescriptor("update", "*").toString()
|
|
135
168
|
]);
|
|
136
|
-
|
|
169
|
+
return import_core2.PermissionValidator.create().someOf([
|
|
170
|
+
createAndUpdateValidator,
|
|
171
|
+
this.service.getDescriptor("write", "*").toString()
|
|
172
|
+
]);
|
|
173
|
+
}
|
|
174
|
+
async upsert(input, options) {
|
|
175
|
+
const permissions = await this.upsertPermissions(input, options);
|
|
176
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
137
177
|
return this.service.upsert(input, options);
|
|
138
178
|
}
|
|
139
|
-
async
|
|
140
|
-
const createAndUpdateValidator =
|
|
179
|
+
async bulkUpsertPermissions(inputs, options) {
|
|
180
|
+
const createAndUpdateValidator = import_core2.PermissionValidator.create().allOf([
|
|
141
181
|
this.service.getDescriptor("create", "*").toString(),
|
|
142
182
|
this.service.getDescriptor("update", "*").toString()
|
|
143
183
|
]);
|
|
144
|
-
|
|
184
|
+
return import_core2.PermissionValidator.create().someOf([
|
|
185
|
+
createAndUpdateValidator,
|
|
186
|
+
this.service.getDescriptor("write", "*").toString()
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
189
|
+
async bulkUpsert(inputs, options) {
|
|
190
|
+
const permissions = await this.bulkUpsertPermissions(inputs, options);
|
|
191
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
145
192
|
return this.service.bulkUpsert(inputs, options);
|
|
146
193
|
}
|
|
147
|
-
async
|
|
148
|
-
|
|
194
|
+
async permanentlyDeleteFromTrashPermissions(lookup) {
|
|
195
|
+
return import_core2.PermissionValidator.create().someOf([
|
|
149
196
|
this.service.getDescriptor("permanently-delete-from-trash", "*").toString(),
|
|
150
197
|
this.service.getDescriptor("permanently-delete", "*").toString(),
|
|
151
198
|
this.service.getDescriptor("empty-trash", "*").toString()
|
|
152
|
-
])
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
201
|
+
async permanentlyDeleteFromTrash(lookup) {
|
|
202
|
+
const permissions = await this.permanentlyDeleteFromTrashPermissions(lookup);
|
|
203
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
153
204
|
return this.service.permanentlyDeleteFromTrash(lookup);
|
|
154
205
|
}
|
|
206
|
+
async permanentlyDeletePermissions(lookup) {
|
|
207
|
+
return import_core2.PermissionValidator.create().someOf([this.service.getDescriptor("permanently-delete", "*").toString()]);
|
|
208
|
+
}
|
|
155
209
|
async permanentlyDelete(lookup) {
|
|
156
|
-
|
|
210
|
+
const permissions = await this.permanentlyDeletePermissions(lookup);
|
|
211
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
157
212
|
return this.service.permanentlyDelete(lookup);
|
|
158
213
|
}
|
|
214
|
+
async emptyTrashPermissions(filters) {
|
|
215
|
+
return import_core2.PermissionValidator.create().someOf([this.service.getDescriptor("empty-trash", "*").toString()]);
|
|
216
|
+
}
|
|
159
217
|
async emptyTrash(filters) {
|
|
160
|
-
|
|
218
|
+
const permissions = await this.emptyTrashPermissions(filters);
|
|
219
|
+
this.authValidator.validatePermissions((v) => v.extend(permissions));
|
|
161
220
|
return this.service.emptyTrash(filters);
|
|
162
221
|
}
|
|
163
222
|
}
|
|
164
223
|
// src/domain/events/domain-event.ts
|
|
165
|
-
var
|
|
224
|
+
var import_core3 = require("@declaro/core");
|
|
166
225
|
|
|
167
226
|
// ../../node_modules/uuid/dist/esm/stringify.js
|
|
168
227
|
var byteToHex = [];
|
|
@@ -229,7 +288,7 @@ class DomainEvent {
|
|
|
229
288
|
}
|
|
230
289
|
this.eventId = options.eventId ?? v4_default();
|
|
231
290
|
this.timestamp = options.timestamp ?? new Date;
|
|
232
|
-
this.descriptor = options.descriptor ?
|
|
291
|
+
this.descriptor = options.descriptor ? import_core3.ActionDescriptor.fromJSON(options.descriptor) : import_core3.ActionDescriptor.fromString(this.type);
|
|
233
292
|
if (options.descriptor && this.type === "UNKNOWN_EVENT") {
|
|
234
293
|
this.type = this.descriptor.toString();
|
|
235
294
|
}
|
|
@@ -12654,7 +12713,7 @@ var v4_default2 = classic_default;
|
|
|
12654
12713
|
|
|
12655
12714
|
// src/domain/models/pagination.ts
|
|
12656
12715
|
var import_zod = require("@declaro/zod");
|
|
12657
|
-
var
|
|
12716
|
+
var import_core10 = require("@declaro/core");
|
|
12658
12717
|
var PaginationInput = new import_zod.ZodModel("PaginationInput", v4_default2.object({
|
|
12659
12718
|
page: v4_default2.number().int().min(1).default(1).nullish(),
|
|
12660
12719
|
pageSize: v4_default2.number().int().min(1).default(25).nullish()
|
|
@@ -12665,12 +12724,12 @@ var PaginationOutput = new import_zod.ZodModel("PaginationOutput", v4_default2.o
|
|
|
12665
12724
|
total: v4_default2.number().int().min(0).default(0),
|
|
12666
12725
|
totalPages: v4_default2.number().int().min(1).default(1)
|
|
12667
12726
|
}));
|
|
12668
|
-
var PaginationSchema =
|
|
12727
|
+
var PaginationSchema = import_core10.ModelSchema.create("Pagination").custom({
|
|
12669
12728
|
input: () => PaginationInput,
|
|
12670
12729
|
output: () => PaginationOutput
|
|
12671
12730
|
});
|
|
12672
12731
|
// src/domain/services/base-model-service.ts
|
|
12673
|
-
var
|
|
12732
|
+
var import_core11 = require("@declaro/core");
|
|
12674
12733
|
|
|
12675
12734
|
class BaseModelService {
|
|
12676
12735
|
namespace;
|
|
@@ -12686,7 +12745,7 @@ class BaseModelService {
|
|
|
12686
12745
|
this.entityMetadata = this.schema.getEntityMetadata();
|
|
12687
12746
|
}
|
|
12688
12747
|
getDescriptor(action, scope) {
|
|
12689
|
-
return
|
|
12748
|
+
return import_core11.ActionDescriptor.fromJSON({
|
|
12690
12749
|
namespace: this.namespace,
|
|
12691
12750
|
resource: this.schema.name,
|
|
12692
12751
|
action,
|
|
@@ -12712,38 +12771,54 @@ class ReadOnlyModelService extends BaseModelService {
|
|
|
12712
12771
|
return summary;
|
|
12713
12772
|
}
|
|
12714
12773
|
async load(lookup, options) {
|
|
12715
|
-
|
|
12716
|
-
|
|
12774
|
+
if (!options?.doNotDispatchEvents) {
|
|
12775
|
+
const beforeLoadEvent = new QueryEvent(this.getDescriptor("beforeLoad" /* BeforeLoad */, options?.scope), lookup);
|
|
12776
|
+
await this.emitter.emitAsync(beforeLoadEvent);
|
|
12777
|
+
}
|
|
12717
12778
|
const details = await this.repository.load(lookup, options);
|
|
12718
|
-
|
|
12719
|
-
|
|
12779
|
+
if (!options?.doNotDispatchEvents) {
|
|
12780
|
+
const afterLoadEvent = new QueryEvent(this.getDescriptor("afterLoad" /* AfterLoad */, options?.scope), lookup).setResult(details);
|
|
12781
|
+
await this.emitter.emitAsync(afterLoadEvent);
|
|
12782
|
+
}
|
|
12720
12783
|
return await this.normalizeDetail(details);
|
|
12721
12784
|
}
|
|
12722
12785
|
async loadMany(lookups, options) {
|
|
12723
|
-
|
|
12724
|
-
|
|
12786
|
+
if (!options?.doNotDispatchEvents) {
|
|
12787
|
+
const beforeLoadManyEvent = new QueryEvent(this.getDescriptor("beforeLoadMany" /* BeforeLoadMany */, options?.scope), lookups);
|
|
12788
|
+
await this.emitter.emitAsync(beforeLoadManyEvent);
|
|
12789
|
+
}
|
|
12725
12790
|
const details = await this.repository.loadMany(lookups, options);
|
|
12726
|
-
|
|
12727
|
-
|
|
12791
|
+
if (!options?.doNotDispatchEvents) {
|
|
12792
|
+
const afterLoadManyEvent = new QueryEvent(this.getDescriptor("afterLoadMany" /* AfterLoadMany */, options?.scope), lookups).setResult(details);
|
|
12793
|
+
await this.emitter.emitAsync(afterLoadManyEvent);
|
|
12794
|
+
}
|
|
12728
12795
|
return await Promise.all(details.map((detail) => this.normalizeDetail(detail)));
|
|
12729
12796
|
}
|
|
12730
12797
|
async search(filters, options) {
|
|
12731
|
-
|
|
12732
|
-
|
|
12798
|
+
if (!options?.doNotDispatchEvents) {
|
|
12799
|
+
const beforeSearchEvent = new QueryEvent(this.getDescriptor("beforeSearch" /* BeforeSearch */, options?.scope), filters);
|
|
12800
|
+
await this.emitter.emitAsync(beforeSearchEvent);
|
|
12801
|
+
}
|
|
12733
12802
|
const results = await this.repository.search(filters, options);
|
|
12734
|
-
|
|
12735
|
-
|
|
12803
|
+
if (!options?.doNotDispatchEvents) {
|
|
12804
|
+
const afterSearchEvent = new QueryEvent(this.getDescriptor("afterSearch" /* AfterSearch */, options?.scope), filters).setResult(results);
|
|
12805
|
+
await this.emitter.emitAsync(afterSearchEvent);
|
|
12806
|
+
}
|
|
12736
12807
|
return {
|
|
12737
12808
|
...results,
|
|
12738
12809
|
results: await Promise.all(results.results.map((detail) => this.normalizeSummary(detail)))
|
|
12739
12810
|
};
|
|
12740
12811
|
}
|
|
12741
12812
|
async count(filters, options) {
|
|
12742
|
-
|
|
12743
|
-
|
|
12813
|
+
if (!options?.doNotDispatchEvents) {
|
|
12814
|
+
const beforeCountEvent = new QueryEvent(this.getDescriptor("beforeCount" /* BeforeCount */, options?.scope), filters);
|
|
12815
|
+
await this.emitter.emitAsync(beforeCountEvent);
|
|
12816
|
+
}
|
|
12744
12817
|
const count = await this.repository.count(filters, options);
|
|
12745
|
-
|
|
12746
|
-
|
|
12818
|
+
if (!options?.doNotDispatchEvents) {
|
|
12819
|
+
const afterCountEvent = new QueryEvent(this.getDescriptor("afterCount" /* AfterCount */, options?.scope), filters).setResult(count);
|
|
12820
|
+
await this.emitter.emitAsync(afterCountEvent);
|
|
12821
|
+
}
|
|
12747
12822
|
return count;
|
|
12748
12823
|
}
|
|
12749
12824
|
}
|
|
@@ -12776,24 +12851,32 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12776
12851
|
const normalizedInput = await this.normalizeInput(input, {
|
|
12777
12852
|
descriptor: this.getDescriptor("create" /* Create */)
|
|
12778
12853
|
});
|
|
12779
|
-
|
|
12780
|
-
|
|
12854
|
+
if (!options?.doNotDispatchEvents) {
|
|
12855
|
+
const beforeCreateEvent = new MutationEvent(this.getDescriptor("beforeCreate" /* BeforeCreate */), normalizedInput);
|
|
12856
|
+
await this.emitter.emitAsync(beforeCreateEvent);
|
|
12857
|
+
}
|
|
12781
12858
|
const result = await this.repository.create(normalizedInput, options);
|
|
12782
|
-
|
|
12783
|
-
|
|
12859
|
+
if (!options?.doNotDispatchEvents) {
|
|
12860
|
+
const afterCreateEvent = new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */), normalizedInput).setResult(result);
|
|
12861
|
+
await this.emitter.emitAsync(afterCreateEvent);
|
|
12862
|
+
}
|
|
12784
12863
|
return await this.normalizeDetail(result);
|
|
12785
12864
|
}
|
|
12786
12865
|
async update(lookup, input, options) {
|
|
12787
|
-
const existing = await this.repository.load(lookup, options);
|
|
12866
|
+
const existing = await this.repository.load(lookup, { ...options, doNotDispatchEvents: true });
|
|
12788
12867
|
const normalizedInput = await this.normalizeInput(input, {
|
|
12789
12868
|
existing,
|
|
12790
12869
|
descriptor: this.getDescriptor("update" /* Update */)
|
|
12791
12870
|
});
|
|
12792
|
-
|
|
12793
|
-
|
|
12871
|
+
if (!options?.doNotDispatchEvents) {
|
|
12872
|
+
const beforeUpdateEvent = new MutationEvent(this.getDescriptor("beforeUpdate" /* BeforeUpdate */), normalizedInput);
|
|
12873
|
+
await this.emitter.emitAsync(beforeUpdateEvent);
|
|
12874
|
+
}
|
|
12794
12875
|
const result = await this.repository.update(lookup, normalizedInput, options);
|
|
12795
|
-
|
|
12796
|
-
|
|
12876
|
+
if (!options?.doNotDispatchEvents) {
|
|
12877
|
+
const afterUpdateEvent = new MutationEvent(this.getDescriptor("afterUpdate" /* AfterUpdate */), normalizedInput).setResult(result);
|
|
12878
|
+
await this.emitter.emitAsync(afterUpdateEvent);
|
|
12879
|
+
}
|
|
12797
12880
|
return await this.normalizeDetail(result);
|
|
12798
12881
|
}
|
|
12799
12882
|
async upsert(input, options) {
|
|
@@ -12809,7 +12892,10 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12809
12892
|
} else {
|
|
12810
12893
|
existingItem = await this.load({
|
|
12811
12894
|
[this.entityMetadata.primaryKey]: primaryKeyValue
|
|
12812
|
-
},
|
|
12895
|
+
}, {
|
|
12896
|
+
...options,
|
|
12897
|
+
doNotDispatchEvents: true
|
|
12898
|
+
});
|
|
12813
12899
|
if (existingItem) {
|
|
12814
12900
|
operation = "update" /* Update */;
|
|
12815
12901
|
beforeOperation = "beforeUpdate" /* BeforeUpdate */;
|
|
@@ -12824,11 +12910,15 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12824
12910
|
descriptor: this.getDescriptor(operation),
|
|
12825
12911
|
existing: existingItem
|
|
12826
12912
|
});
|
|
12827
|
-
|
|
12828
|
-
|
|
12913
|
+
if (!options?.doNotDispatchEvents) {
|
|
12914
|
+
const beforeUpsertEvent = new MutationEvent(this.getDescriptor(beforeOperation), normalizedInput);
|
|
12915
|
+
await this.emitter.emitAsync(beforeUpsertEvent);
|
|
12916
|
+
}
|
|
12829
12917
|
const result = await this.repository.upsert(normalizedInput, options);
|
|
12830
|
-
|
|
12831
|
-
|
|
12918
|
+
if (!options?.doNotDispatchEvents) {
|
|
12919
|
+
const afterUpsertEvent = new MutationEvent(this.getDescriptor(afterOperation), normalizedInput).setResult(result);
|
|
12920
|
+
await this.emitter.emitAsync(afterUpsertEvent);
|
|
12921
|
+
}
|
|
12832
12922
|
return await this.normalizeDetail(result);
|
|
12833
12923
|
}
|
|
12834
12924
|
async bulkUpsert(inputs, options) {
|
|
@@ -12855,7 +12945,10 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12855
12945
|
const existingEntitiesMap = new Map;
|
|
12856
12946
|
if (uniqueLookups.size > 0) {
|
|
12857
12947
|
const lookups = Array.from(uniqueLookups.values());
|
|
12858
|
-
const existingEntities = await this.loadMany(lookups,
|
|
12948
|
+
const existingEntities = await this.loadMany(lookups, {
|
|
12949
|
+
...options,
|
|
12950
|
+
doNotDispatchEvents: true
|
|
12951
|
+
});
|
|
12859
12952
|
existingEntities.forEach((entity) => {
|
|
12860
12953
|
if (entity) {
|
|
12861
12954
|
const pkValue = this.getPrimaryKeyValue(entity);
|
|
@@ -12878,20 +12971,24 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12878
12971
|
return normalizedInput;
|
|
12879
12972
|
});
|
|
12880
12973
|
const normalizedInputs = await Promise.all(normalizationPromises);
|
|
12881
|
-
|
|
12882
|
-
|
|
12883
|
-
|
|
12974
|
+
if (!options?.doNotDispatchEvents) {
|
|
12975
|
+
const beforeEvents = [];
|
|
12976
|
+
for (const inputInfo of inputInfos) {
|
|
12977
|
+
beforeEvents.push(new MutationEvent(this.getDescriptor(inputInfo.operation), inputInfo.input));
|
|
12978
|
+
}
|
|
12979
|
+
await Promise.all(beforeEvents.map((event) => this.emitter.emitAsync(event)));
|
|
12884
12980
|
}
|
|
12885
|
-
await Promise.all(beforeEvents.map((event) => this.emitter.emitAsync(event)));
|
|
12886
12981
|
const results = await this.repository.bulkUpsert(normalizedInputs, options);
|
|
12887
|
-
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12982
|
+
if (!options?.doNotDispatchEvents) {
|
|
12983
|
+
const afterEvents = [];
|
|
12984
|
+
for (let i = 0;i < inputInfos.length; i++) {
|
|
12985
|
+
const inputInfo = inputInfos[i];
|
|
12986
|
+
const result = results[i];
|
|
12987
|
+
const afterOperation = inputInfo.operation === "beforeCreate" /* BeforeCreate */ ? "afterCreate" /* AfterCreate */ : "afterUpdate" /* AfterUpdate */;
|
|
12988
|
+
afterEvents.push(new MutationEvent(this.getDescriptor(afterOperation), inputInfo.input).setResult(result));
|
|
12989
|
+
}
|
|
12990
|
+
await Promise.all(afterEvents.map((event) => this.emitter.emitAsync(event)));
|
|
12991
|
+
}
|
|
12895
12992
|
return await Promise.all(results.map((result) => this.normalizeDetail(result)));
|
|
12896
12993
|
}
|
|
12897
12994
|
async emptyTrash(filters) {
|
|
@@ -12920,9 +13017,9 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12920
13017
|
}
|
|
12921
13018
|
}
|
|
12922
13019
|
// src/test/mock/models/mock-book-models.ts
|
|
12923
|
-
var
|
|
13020
|
+
var import_core12 = require("@declaro/core");
|
|
12924
13021
|
var import_zod2 = require("@declaro/zod");
|
|
12925
|
-
var MockBookSchema =
|
|
13022
|
+
var MockBookSchema = import_core12.ModelSchema.create("Book").read({
|
|
12926
13023
|
detail: (h) => new import_zod2.ZodModel(h.name, exports_external.object({
|
|
12927
13024
|
id: exports_external.number().int().positive(),
|
|
12928
13025
|
title: exports_external.string().min(2).max(100),
|
|
@@ -13231,5 +13328,5 @@ class MockMemoryRepository {
|
|
|
13231
13328
|
}
|
|
13232
13329
|
}
|
|
13233
13330
|
|
|
13234
|
-
//# debugId=
|
|
13331
|
+
//# debugId=A88573935D4966CE64756E2164756E21
|
|
13235
13332
|
//# sourceMappingURL=index.cjs.map
|