adminforth 1.3.6 → 1.3.8
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 +3 -2
- package/dist/modules/configValidator.js +6 -4
- package/dist/modules/restApi.js +3 -3
- package/index.ts +5 -2
- package/modules/configValidator.ts +6 -6
- package/modules/restApi.ts +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -179,7 +179,7 @@ class AdminForth {
|
|
|
179
179
|
}
|
|
180
180
|
// execute hook if needed
|
|
181
181
|
for (const hook of listify((_e = (_d = resource.hooks) === null || _d === void 0 ? void 0 : _d.create) === null || _e === void 0 ? void 0 : _e.beforeSave)) {
|
|
182
|
-
const resp = yield hook({ resource, record, adminUser });
|
|
182
|
+
const resp = yield hook({ recordId: undefined, resource, record, adminUser });
|
|
183
183
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
184
184
|
throw new Error(`Hook beforeSave must return object with {ok: true} or { error: 'Error' } `);
|
|
185
185
|
}
|
|
@@ -196,10 +196,11 @@ class AdminForth {
|
|
|
196
196
|
const connector = this.connectors[resource.dataSource];
|
|
197
197
|
process.env.HEAVY_DEBUG && console.log('🪲🪲🪲🪲 creating record createResourceRecord', record);
|
|
198
198
|
yield connector.createRecord({ resource, record, adminUser });
|
|
199
|
+
const primaryKey = record[resource.columns.find((col) => col.primaryKey).name];
|
|
199
200
|
// execute hook if needed
|
|
200
201
|
for (const hook of listify((_g = (_f = resource.hooks) === null || _f === void 0 ? void 0 : _f.create) === null || _g === void 0 ? void 0 : _g.afterSave)) {
|
|
201
202
|
console.log('Hook afterSave', hook);
|
|
202
|
-
const resp = yield hook({ resource, record, adminUser });
|
|
203
|
+
const resp = yield hook({ recordId: primaryKey, resource, record, adminUser });
|
|
203
204
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
204
205
|
throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
|
|
205
206
|
}
|
|
@@ -251,10 +251,10 @@ export default class ConfigValidator {
|
|
|
251
251
|
const record = yield connector.getRecordByPrimaryKey(res, recordId);
|
|
252
252
|
yield Promise.all(res.hooks.delete.beforeSave.map((hook) => __awaiter(this, void 0, void 0, function* () {
|
|
253
253
|
const resp = yield hook({
|
|
254
|
-
|
|
254
|
+
recordId: recordId,
|
|
255
255
|
resource: res,
|
|
256
256
|
record,
|
|
257
|
-
adminUser
|
|
257
|
+
adminUser,
|
|
258
258
|
});
|
|
259
259
|
if (!error && resp.error) {
|
|
260
260
|
error = resp.error;
|
|
@@ -267,8 +267,10 @@ export default class ConfigValidator {
|
|
|
267
267
|
// call afterDelete hook
|
|
268
268
|
yield Promise.all(res.hooks.delete.afterSave.map((hook) => __awaiter(this, void 0, void 0, function* () {
|
|
269
269
|
yield hook({
|
|
270
|
-
resource: res,
|
|
271
|
-
|
|
270
|
+
resource: res,
|
|
271
|
+
record,
|
|
272
|
+
adminUser,
|
|
273
|
+
recordId: recordId
|
|
272
274
|
});
|
|
273
275
|
})));
|
|
274
276
|
})));
|
package/dist/modules/restApi.js
CHANGED
|
@@ -519,7 +519,7 @@ export default class AdminForthRestAPI {
|
|
|
519
519
|
// execute hook if needed
|
|
520
520
|
for (const hook of listify((_5 = (_4 = resource.hooks) === null || _4 === void 0 ? void 0 : _4.edit) === null || _5 === void 0 ? void 0 : _5.beforeSave)) {
|
|
521
521
|
const resp = yield hook({
|
|
522
|
-
|
|
522
|
+
recordId,
|
|
523
523
|
resource,
|
|
524
524
|
record,
|
|
525
525
|
adminUser
|
|
@@ -555,7 +555,7 @@ export default class AdminForthRestAPI {
|
|
|
555
555
|
record,
|
|
556
556
|
adminUser,
|
|
557
557
|
oldRecord,
|
|
558
|
-
|
|
558
|
+
recordId,
|
|
559
559
|
});
|
|
560
560
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
561
561
|
throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
|
|
@@ -613,7 +613,7 @@ export default class AdminForthRestAPI {
|
|
|
613
613
|
resource,
|
|
614
614
|
record,
|
|
615
615
|
adminUser,
|
|
616
|
-
|
|
616
|
+
recordId: body['primaryKey']
|
|
617
617
|
});
|
|
618
618
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
619
619
|
throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
|
package/index.ts
CHANGED
|
@@ -224,7 +224,7 @@ class AdminForth implements IAdminForth {
|
|
|
224
224
|
|
|
225
225
|
// execute hook if needed
|
|
226
226
|
for (const hook of listify(resource.hooks?.create?.beforeSave as BeforeSaveFunction[])) {
|
|
227
|
-
const resp = await hook({ resource, record, adminUser });
|
|
227
|
+
const resp = await hook({ recordId: undefined, resource, record, adminUser });
|
|
228
228
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
229
229
|
throw new Error(`Hook beforeSave must return object with {ok: true} or { error: 'Error' } `);
|
|
230
230
|
}
|
|
@@ -243,10 +243,13 @@ class AdminForth implements IAdminForth {
|
|
|
243
243
|
const connector = this.connectors[resource.dataSource];
|
|
244
244
|
process.env.HEAVY_DEBUG && console.log('🪲🪲🪲🪲 creating record createResourceRecord', record);
|
|
245
245
|
await connector.createRecord({ resource, record, adminUser });
|
|
246
|
+
|
|
247
|
+
const primaryKey = record[resource.columns.find((col) => col.primaryKey).name];
|
|
248
|
+
|
|
246
249
|
// execute hook if needed
|
|
247
250
|
for (const hook of listify(resource.hooks?.create?.afterSave as AfterSaveFunction[])) {
|
|
248
251
|
console.log('Hook afterSave', hook);
|
|
249
|
-
const resp = await hook({ resource, record, adminUser });
|
|
252
|
+
const resp = await hook({ recordId: primaryKey, resource, record, adminUser });
|
|
250
253
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
251
254
|
throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
|
|
252
255
|
}
|
|
@@ -278,10 +278,10 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
278
278
|
(res.hooks.delete.beforeSave as AfterSaveFunction[]).map(
|
|
279
279
|
async (hook) => {
|
|
280
280
|
const resp = await hook({
|
|
281
|
-
|
|
281
|
+
recordId: recordId,
|
|
282
282
|
resource: res,
|
|
283
283
|
record,
|
|
284
|
-
adminUser
|
|
284
|
+
adminUser,
|
|
285
285
|
});
|
|
286
286
|
if (!error && resp.error) {
|
|
287
287
|
error = resp.error;
|
|
@@ -300,8 +300,10 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
300
300
|
(res.hooks.delete.afterSave as AfterSaveFunction[]).map(
|
|
301
301
|
async (hook) => {
|
|
302
302
|
await hook({
|
|
303
|
-
resource: res,
|
|
304
|
-
|
|
303
|
+
resource: res,
|
|
304
|
+
record,
|
|
305
|
+
adminUser,
|
|
306
|
+
recordId: recordId
|
|
305
307
|
});
|
|
306
308
|
}
|
|
307
309
|
)
|
|
@@ -391,8 +393,6 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
391
393
|
}
|
|
392
394
|
});
|
|
393
395
|
|
|
394
|
-
|
|
395
|
-
|
|
396
396
|
if (!this.config.menu) {
|
|
397
397
|
errors.push('No config.menu defined');
|
|
398
398
|
}
|
package/modules/restApi.ts
CHANGED
|
@@ -605,7 +605,7 @@ export default class AdminForthRestAPI {
|
|
|
605
605
|
// execute hook if needed
|
|
606
606
|
for (const hook of listify(resource.hooks?.edit?.beforeSave as BeforeSaveFunction[])) {
|
|
607
607
|
const resp = await hook({
|
|
608
|
-
|
|
608
|
+
recordId,
|
|
609
609
|
resource,
|
|
610
610
|
record,
|
|
611
611
|
adminUser
|
|
@@ -644,7 +644,7 @@ export default class AdminForthRestAPI {
|
|
|
644
644
|
record,
|
|
645
645
|
adminUser,
|
|
646
646
|
oldRecord,
|
|
647
|
-
|
|
647
|
+
recordId,
|
|
648
648
|
});
|
|
649
649
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
650
650
|
throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
|
|
@@ -709,7 +709,7 @@ export default class AdminForthRestAPI {
|
|
|
709
709
|
resource,
|
|
710
710
|
record,
|
|
711
711
|
adminUser,
|
|
712
|
-
|
|
712
|
+
recordId: body['primaryKey']
|
|
713
713
|
});
|
|
714
714
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
715
715
|
throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
|