@ruiapp/rapid-core 0.1.36 → 0.1.38
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/index.js +37 -25
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/core/response.ts +4 -1
- package/src/dataAccess/entityManager.ts +1 -1
- package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +4 -4
- package/src/plugins/stateMachine/StateMachinePlugin.ts +31 -23
- package/src/types.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -712,7 +712,10 @@ class RapidResponse {
|
|
|
712
712
|
this.status = init?.status;
|
|
713
713
|
}
|
|
714
714
|
json(obj, status, headers) {
|
|
715
|
-
|
|
715
|
+
let body = null;
|
|
716
|
+
if (obj) {
|
|
717
|
+
body = JSON.stringify(obj);
|
|
718
|
+
}
|
|
716
719
|
this.headers.set("Content-Type", "application/json");
|
|
717
720
|
const responseHeaders = new Headers(this.headers);
|
|
718
721
|
if (headers) {
|
|
@@ -2205,7 +2208,7 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
|
2205
2208
|
before: entity,
|
|
2206
2209
|
changes: options.entityToSave,
|
|
2207
2210
|
}, plugin);
|
|
2208
|
-
changes = options.entityToSave;
|
|
2211
|
+
changes = getEntityPartChanges(entity, options.entityToSave);
|
|
2209
2212
|
const oneRelationPropertiesToUpdate = [];
|
|
2210
2213
|
const manyRelationPropertiesToUpdate = [];
|
|
2211
2214
|
lodash.keys(changes).forEach((propertyCode) => {
|
|
@@ -3339,12 +3342,12 @@ async function handler$h(plugin, ctx, options) {
|
|
|
3339
3342
|
if (operation) {
|
|
3340
3343
|
delete mergedInput.$operation;
|
|
3341
3344
|
}
|
|
3342
|
-
const
|
|
3343
|
-
if (
|
|
3344
|
-
delete mergedInput.$
|
|
3345
|
+
const stateProperties = mergedInput.$stateProperties;
|
|
3346
|
+
if (stateProperties) {
|
|
3347
|
+
delete mergedInput.$stateProperties;
|
|
3345
3348
|
}
|
|
3346
3349
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
3347
|
-
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation,
|
|
3350
|
+
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation, stateProperties }, plugin);
|
|
3348
3351
|
ctx.output = output;
|
|
3349
3352
|
}
|
|
3350
3353
|
|
|
@@ -5259,36 +5262,45 @@ class StateMachinePlugin {
|
|
|
5259
5262
|
*/
|
|
5260
5263
|
async beforeUpdateEntity(server, model, options, currentEntity) {
|
|
5261
5264
|
const entity = options.entityToSave;
|
|
5265
|
+
const stateMachineEnabledProperties = [];
|
|
5262
5266
|
for (const property of model.properties) {
|
|
5263
5267
|
const isStateMachineEnabled = lodash.get(property.config, "stateMachine.enabled", false);
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5268
|
+
if (isStateMachineEnabled) {
|
|
5269
|
+
stateMachineEnabledProperties.push(property);
|
|
5270
|
+
const isTransferControlEnabled = lodash.get(property.config, "stateMachine.transferControl", false);
|
|
5271
|
+
if (isTransferControlEnabled && !isNullOrUndefined(entity[property.code])) {
|
|
5272
|
+
throw new Error(`You're not allowed to change '${property.code}' property directly when transfer control is enabled, do an operation instead.`);
|
|
5273
|
+
}
|
|
5267
5274
|
}
|
|
5268
5275
|
}
|
|
5269
5276
|
if (!options.operation) {
|
|
5270
5277
|
return;
|
|
5271
5278
|
}
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
if (
|
|
5275
|
-
|
|
5279
|
+
let statePropertiesToUpdate;
|
|
5280
|
+
const statePropertyCodes = options.stateProperties;
|
|
5281
|
+
if (statePropertyCodes && statePropertyCodes.length) {
|
|
5282
|
+
statePropertiesToUpdate = lodash.filter(stateMachineEnabledProperties, (property) => statePropertyCodes.includes(property.code));
|
|
5283
|
+
}
|
|
5284
|
+
else {
|
|
5285
|
+
statePropertiesToUpdate = stateMachineEnabledProperties;
|
|
5276
5286
|
}
|
|
5277
|
-
if (!
|
|
5287
|
+
if (!statePropertiesToUpdate.length) {
|
|
5278
5288
|
throw new Error(`State machine property not found.`);
|
|
5279
5289
|
}
|
|
5280
|
-
const
|
|
5281
|
-
|
|
5282
|
-
|
|
5290
|
+
for (const statePropertyToUpdate of statePropertiesToUpdate) {
|
|
5291
|
+
const machineConfig = lodash.get(statePropertyToUpdate.config, "stateMachine.config", null);
|
|
5292
|
+
if (!machineConfig) {
|
|
5293
|
+
throw new Error(`State machine of property '${statePropertyToUpdate.code}' not configured.`);
|
|
5294
|
+
}
|
|
5295
|
+
machineConfig.id = getStateMachineCode(model, statePropertyToUpdate);
|
|
5296
|
+
const nextSnapshot = await getStateMachineNextSnapshot(server, {
|
|
5297
|
+
machineConfig,
|
|
5298
|
+
context: {},
|
|
5299
|
+
currentState: currentEntity[statePropertyToUpdate.code],
|
|
5300
|
+
event: options.operation,
|
|
5301
|
+
});
|
|
5302
|
+
entity[statePropertyToUpdate.code] = nextSnapshot.value;
|
|
5283
5303
|
}
|
|
5284
|
-
machineConfig.id = getStateMachineCode(model, stateMachineEnabledProperty);
|
|
5285
|
-
const nextSnapshot = await getStateMachineNextSnapshot(server, {
|
|
5286
|
-
machineConfig,
|
|
5287
|
-
context: {},
|
|
5288
|
-
currentState: currentEntity[stateMachineEnabledProperty.code],
|
|
5289
|
-
event: options.operation,
|
|
5290
|
-
});
|
|
5291
|
-
entity[stateMachineEnabledProperty.code] = nextSnapshot.value;
|
|
5292
5304
|
}
|
|
5293
5305
|
}
|
|
5294
5306
|
function getStateMachineCode(model, property) {
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/core/response.ts
CHANGED
|
@@ -49,7 +49,10 @@ export class RapidResponse {
|
|
|
49
49
|
status?: HttpStatus,
|
|
50
50
|
headers?: HeadersInit,
|
|
51
51
|
) {
|
|
52
|
-
|
|
52
|
+
let body: string | null = null;
|
|
53
|
+
if (obj) {
|
|
54
|
+
body = JSON.stringify(obj);
|
|
55
|
+
}
|
|
53
56
|
this.headers.set("Content-Type", "application/json");
|
|
54
57
|
const responseHeaders = new Headers(this.headers);
|
|
55
58
|
if (headers) {
|
|
@@ -615,7 +615,7 @@ async function updateEntityById(
|
|
|
615
615
|
plugin,
|
|
616
616
|
);
|
|
617
617
|
|
|
618
|
-
changes = options.entityToSave;
|
|
618
|
+
changes = getEntityPartChanges(entity, options.entityToSave);
|
|
619
619
|
|
|
620
620
|
const oneRelationPropertiesToUpdate: RpdDataModelProperty[] = [];
|
|
621
621
|
const manyRelationPropertiesToUpdate: RpdDataModelProperty[] = [];
|
|
@@ -21,12 +21,12 @@ export async function handler(
|
|
|
21
21
|
delete mergedInput.$operation;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
delete mergedInput.$
|
|
24
|
+
const stateProperties = mergedInput.$stateProperties;
|
|
25
|
+
if (stateProperties) {
|
|
26
|
+
delete mergedInput.$stateProperties;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
30
|
-
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation,
|
|
30
|
+
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput, operation, stateProperties }, plugin);
|
|
31
31
|
ctx.output = output;
|
|
32
32
|
}
|
|
@@ -127,12 +127,17 @@ class StateMachinePlugin implements RapidPlugin {
|
|
|
127
127
|
async beforeUpdateEntity(server: IRpdServer, model: RpdDataModel, options: UpdateEntityByIdOptions, currentEntity: any) {
|
|
128
128
|
const entity = options.entityToSave;
|
|
129
129
|
|
|
130
|
+
const stateMachineEnabledProperties: RpdDataModelProperty[] = [];
|
|
130
131
|
for (const property of model.properties) {
|
|
131
132
|
const isStateMachineEnabled = get(property.config, "stateMachine.enabled", false);
|
|
132
|
-
|
|
133
|
-
if (isStateMachineEnabled
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
|
|
134
|
+
if (isStateMachineEnabled) {
|
|
135
|
+
stateMachineEnabledProperties.push(property);
|
|
136
|
+
|
|
137
|
+
const isTransferControlEnabled = get(property.config, "stateMachine.transferControl", false);
|
|
138
|
+
if (isTransferControlEnabled && !isNullOrUndefined(entity[property.code])) {
|
|
139
|
+
throw new Error(`You're not allowed to change '${property.code}' property directly when transfer control is enabled, do an operation instead.`);
|
|
140
|
+
}
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
|
|
@@ -140,32 +145,35 @@ class StateMachinePlugin implements RapidPlugin {
|
|
|
140
145
|
return;
|
|
141
146
|
}
|
|
142
147
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
|
|
148
|
+
let statePropertiesToUpdate: RpdDataModelProperty[];
|
|
149
|
+
const statePropertyCodes = options.stateProperties;
|
|
150
|
+
if (statePropertyCodes && statePropertyCodes.length) {
|
|
151
|
+
statePropertiesToUpdate = filter(stateMachineEnabledProperties, (property) => statePropertyCodes.includes(property.code));
|
|
152
|
+
} else {
|
|
153
|
+
statePropertiesToUpdate = stateMachineEnabledProperties;
|
|
147
154
|
}
|
|
148
155
|
|
|
149
|
-
if (!
|
|
156
|
+
if (!statePropertiesToUpdate.length) {
|
|
150
157
|
throw new Error(`State machine property not found.`);
|
|
151
158
|
}
|
|
152
159
|
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
160
|
+
for (const statePropertyToUpdate of statePropertiesToUpdate) {
|
|
161
|
+
const machineConfig = get(statePropertyToUpdate.config, "stateMachine.config", null);
|
|
162
|
+
if (!machineConfig) {
|
|
163
|
+
throw new Error(`State machine of property '${statePropertyToUpdate.code}' not configured.`);
|
|
164
|
+
}
|
|
165
|
+
machineConfig.id = getStateMachineCode(model, statePropertyToUpdate);
|
|
166
|
+
|
|
167
|
+
const nextSnapshot = await getStateMachineNextSnapshot(server, {
|
|
168
|
+
machineConfig,
|
|
169
|
+
context: {},
|
|
170
|
+
currentState: currentEntity[statePropertyToUpdate.code],
|
|
171
|
+
event: options.operation,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
entity[statePropertyToUpdate.code] = nextSnapshot.value;
|
|
156
175
|
}
|
|
157
|
-
machineConfig.id = getStateMachineCode(model, stateMachineEnabledProperty);
|
|
158
|
-
|
|
159
|
-
const nextSnapshot = await getStateMachineNextSnapshot(server, {
|
|
160
|
-
machineConfig,
|
|
161
|
-
context: {},
|
|
162
|
-
currentState: currentEntity[stateMachineEnabledProperty.code],
|
|
163
|
-
event: options.operation,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
entity[stateMachineEnabledProperty.code] = nextSnapshot.value;
|
|
167
176
|
}
|
|
168
|
-
|
|
169
177
|
}
|
|
170
178
|
|
|
171
179
|
function getStateMachineCode(model: RpdDataModel, property: RpdDataModelProperty) {
|