@declaro/data 2.0.0-beta.126 → 2.0.0-beta.128
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 +217 -92
- package/dist/node/index.cjs.map +6 -6
- package/dist/node/index.js +209 -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 +27 -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 +460 -0
- package/src/domain/services/model-service.ts +165 -67
- 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
|
}
|
|
@@ -12756,6 +12831,34 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12756
12831
|
async normalizeInput(input, args) {
|
|
12757
12832
|
return input;
|
|
12758
12833
|
}
|
|
12834
|
+
async detailsToInput(detail) {
|
|
12835
|
+
const inputModel = this.schema.definition.input;
|
|
12836
|
+
const inputJsonSchema = inputModel.toJSONSchema();
|
|
12837
|
+
const inputFields = Object.keys(inputJsonSchema.properties ?? {});
|
|
12838
|
+
const picked = {};
|
|
12839
|
+
for (const field of inputFields) {
|
|
12840
|
+
if (field in detail) {
|
|
12841
|
+
picked[field] = detail[field];
|
|
12842
|
+
}
|
|
12843
|
+
}
|
|
12844
|
+
const result = await inputModel.validate(picked);
|
|
12845
|
+
if ("value" in result) {
|
|
12846
|
+
return result.value;
|
|
12847
|
+
}
|
|
12848
|
+
return picked;
|
|
12849
|
+
}
|
|
12850
|
+
async duplicate(lookup, overrides, options) {
|
|
12851
|
+
const existing = await this.load(lookup);
|
|
12852
|
+
if (!existing) {
|
|
12853
|
+
throw new Error("Item not found");
|
|
12854
|
+
}
|
|
12855
|
+
const input = await this.detailsToInput(existing);
|
|
12856
|
+
if (this.entityMetadata?.primaryKey) {
|
|
12857
|
+
delete input[this.entityMetadata.primaryKey];
|
|
12858
|
+
}
|
|
12859
|
+
const finalInput = overrides ? Object.assign({}, input, overrides) : input;
|
|
12860
|
+
return this.create(finalInput, options);
|
|
12861
|
+
}
|
|
12759
12862
|
async remove(lookup, options) {
|
|
12760
12863
|
const beforeRemoveEvent = new MutationEvent(this.getDescriptor("beforeRemove" /* BeforeRemove */), lookup);
|
|
12761
12864
|
await this.emitter.emitAsync(beforeRemoveEvent);
|
|
@@ -12776,24 +12879,32 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12776
12879
|
const normalizedInput = await this.normalizeInput(input, {
|
|
12777
12880
|
descriptor: this.getDescriptor("create" /* Create */)
|
|
12778
12881
|
});
|
|
12779
|
-
|
|
12780
|
-
|
|
12882
|
+
if (!options?.doNotDispatchEvents) {
|
|
12883
|
+
const beforeCreateEvent = new MutationEvent(this.getDescriptor("beforeCreate" /* BeforeCreate */), normalizedInput);
|
|
12884
|
+
await this.emitter.emitAsync(beforeCreateEvent);
|
|
12885
|
+
}
|
|
12781
12886
|
const result = await this.repository.create(normalizedInput, options);
|
|
12782
|
-
|
|
12783
|
-
|
|
12887
|
+
if (!options?.doNotDispatchEvents) {
|
|
12888
|
+
const afterCreateEvent = new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */), normalizedInput).setResult(result);
|
|
12889
|
+
await this.emitter.emitAsync(afterCreateEvent);
|
|
12890
|
+
}
|
|
12784
12891
|
return await this.normalizeDetail(result);
|
|
12785
12892
|
}
|
|
12786
12893
|
async update(lookup, input, options) {
|
|
12787
|
-
const existing = await this.repository.load(lookup, options);
|
|
12894
|
+
const existing = await this.repository.load(lookup, { ...options, doNotDispatchEvents: true });
|
|
12788
12895
|
const normalizedInput = await this.normalizeInput(input, {
|
|
12789
12896
|
existing,
|
|
12790
12897
|
descriptor: this.getDescriptor("update" /* Update */)
|
|
12791
12898
|
});
|
|
12792
|
-
|
|
12793
|
-
|
|
12899
|
+
if (!options?.doNotDispatchEvents) {
|
|
12900
|
+
const beforeUpdateEvent = new MutationEvent(this.getDescriptor("beforeUpdate" /* BeforeUpdate */), normalizedInput);
|
|
12901
|
+
await this.emitter.emitAsync(beforeUpdateEvent);
|
|
12902
|
+
}
|
|
12794
12903
|
const result = await this.repository.update(lookup, normalizedInput, options);
|
|
12795
|
-
|
|
12796
|
-
|
|
12904
|
+
if (!options?.doNotDispatchEvents) {
|
|
12905
|
+
const afterUpdateEvent = new MutationEvent(this.getDescriptor("afterUpdate" /* AfterUpdate */), normalizedInput).setResult(result);
|
|
12906
|
+
await this.emitter.emitAsync(afterUpdateEvent);
|
|
12907
|
+
}
|
|
12797
12908
|
return await this.normalizeDetail(result);
|
|
12798
12909
|
}
|
|
12799
12910
|
async upsert(input, options) {
|
|
@@ -12809,7 +12920,10 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12809
12920
|
} else {
|
|
12810
12921
|
existingItem = await this.load({
|
|
12811
12922
|
[this.entityMetadata.primaryKey]: primaryKeyValue
|
|
12812
|
-
},
|
|
12923
|
+
}, {
|
|
12924
|
+
...options,
|
|
12925
|
+
doNotDispatchEvents: true
|
|
12926
|
+
});
|
|
12813
12927
|
if (existingItem) {
|
|
12814
12928
|
operation = "update" /* Update */;
|
|
12815
12929
|
beforeOperation = "beforeUpdate" /* BeforeUpdate */;
|
|
@@ -12824,11 +12938,15 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12824
12938
|
descriptor: this.getDescriptor(operation),
|
|
12825
12939
|
existing: existingItem
|
|
12826
12940
|
});
|
|
12827
|
-
|
|
12828
|
-
|
|
12941
|
+
if (!options?.doNotDispatchEvents) {
|
|
12942
|
+
const beforeUpsertEvent = new MutationEvent(this.getDescriptor(beforeOperation), normalizedInput);
|
|
12943
|
+
await this.emitter.emitAsync(beforeUpsertEvent);
|
|
12944
|
+
}
|
|
12829
12945
|
const result = await this.repository.upsert(normalizedInput, options);
|
|
12830
|
-
|
|
12831
|
-
|
|
12946
|
+
if (!options?.doNotDispatchEvents) {
|
|
12947
|
+
const afterUpsertEvent = new MutationEvent(this.getDescriptor(afterOperation), normalizedInput).setResult(result);
|
|
12948
|
+
await this.emitter.emitAsync(afterUpsertEvent);
|
|
12949
|
+
}
|
|
12832
12950
|
return await this.normalizeDetail(result);
|
|
12833
12951
|
}
|
|
12834
12952
|
async bulkUpsert(inputs, options) {
|
|
@@ -12855,7 +12973,10 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12855
12973
|
const existingEntitiesMap = new Map;
|
|
12856
12974
|
if (uniqueLookups.size > 0) {
|
|
12857
12975
|
const lookups = Array.from(uniqueLookups.values());
|
|
12858
|
-
const existingEntities = await this.loadMany(lookups,
|
|
12976
|
+
const existingEntities = await this.loadMany(lookups, {
|
|
12977
|
+
...options,
|
|
12978
|
+
doNotDispatchEvents: true
|
|
12979
|
+
});
|
|
12859
12980
|
existingEntities.forEach((entity) => {
|
|
12860
12981
|
if (entity) {
|
|
12861
12982
|
const pkValue = this.getPrimaryKeyValue(entity);
|
|
@@ -12878,20 +12999,24 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12878
12999
|
return normalizedInput;
|
|
12879
13000
|
});
|
|
12880
13001
|
const normalizedInputs = await Promise.all(normalizationPromises);
|
|
12881
|
-
|
|
12882
|
-
|
|
12883
|
-
|
|
13002
|
+
if (!options?.doNotDispatchEvents) {
|
|
13003
|
+
const beforeEvents = [];
|
|
13004
|
+
for (const inputInfo of inputInfos) {
|
|
13005
|
+
beforeEvents.push(new MutationEvent(this.getDescriptor(inputInfo.operation), inputInfo.input));
|
|
13006
|
+
}
|
|
13007
|
+
await Promise.all(beforeEvents.map((event) => this.emitter.emitAsync(event)));
|
|
12884
13008
|
}
|
|
12885
|
-
await Promise.all(beforeEvents.map((event) => this.emitter.emitAsync(event)));
|
|
12886
13009
|
const results = await this.repository.bulkUpsert(normalizedInputs, options);
|
|
12887
|
-
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
13010
|
+
if (!options?.doNotDispatchEvents) {
|
|
13011
|
+
const afterEvents = [];
|
|
13012
|
+
for (let i = 0;i < inputInfos.length; i++) {
|
|
13013
|
+
const inputInfo = inputInfos[i];
|
|
13014
|
+
const result = results[i];
|
|
13015
|
+
const afterOperation = inputInfo.operation === "beforeCreate" /* BeforeCreate */ ? "afterCreate" /* AfterCreate */ : "afterUpdate" /* AfterUpdate */;
|
|
13016
|
+
afterEvents.push(new MutationEvent(this.getDescriptor(afterOperation), inputInfo.input).setResult(result));
|
|
13017
|
+
}
|
|
13018
|
+
await Promise.all(afterEvents.map((event) => this.emitter.emitAsync(event)));
|
|
13019
|
+
}
|
|
12895
13020
|
return await Promise.all(results.map((result) => this.normalizeDetail(result)));
|
|
12896
13021
|
}
|
|
12897
13022
|
async emptyTrash(filters) {
|
|
@@ -12920,9 +13045,9 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12920
13045
|
}
|
|
12921
13046
|
}
|
|
12922
13047
|
// src/test/mock/models/mock-book-models.ts
|
|
12923
|
-
var
|
|
13048
|
+
var import_core12 = require("@declaro/core");
|
|
12924
13049
|
var import_zod2 = require("@declaro/zod");
|
|
12925
|
-
var MockBookSchema =
|
|
13050
|
+
var MockBookSchema = import_core12.ModelSchema.create("Book").read({
|
|
12926
13051
|
detail: (h) => new import_zod2.ZodModel(h.name, exports_external.object({
|
|
12927
13052
|
id: exports_external.number().int().positive(),
|
|
12928
13053
|
title: exports_external.string().min(2).max(100),
|
|
@@ -13231,5 +13356,5 @@ class MockMemoryRepository {
|
|
|
13231
13356
|
}
|
|
13232
13357
|
}
|
|
13233
13358
|
|
|
13234
|
-
//# debugId=
|
|
13359
|
+
//# debugId=F7D58E636DC6E2AF64756E2164756E21
|
|
13235
13360
|
//# sourceMappingURL=index.cjs.map
|