@coderich/autograph 0.13.39 → 0.13.40
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/package.json +1 -1
- package/src/data/Pipeline.js +8 -6
- package/src/data/Resolver.js +1 -1
- package/src/schema/Schema.js +10 -2
package/package.json
CHANGED
package/src/data/Pipeline.js
CHANGED
|
@@ -73,17 +73,19 @@ module.exports = class Pipeline {
|
|
|
73
73
|
}, { ignoreNull: false });
|
|
74
74
|
|
|
75
75
|
Pipeline.define('$fk', (params) => {
|
|
76
|
-
const { fkField } = params.field;
|
|
77
|
-
const
|
|
76
|
+
const { fkField, isPrimaryKey } = params.field;
|
|
77
|
+
const lookupField = isPrimaryKey ? params.field : fkField;
|
|
78
|
+
const v = params.value?.[lookupField] || params.value;
|
|
78
79
|
return Util.map(v, value => params.field.generator({ ...params, value }));
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
//
|
|
82
|
-
Pipeline.define('$cast', (
|
|
83
|
-
const {
|
|
84
|
-
if (isEmbedded) return value;
|
|
83
|
+
Pipeline.define('$cast', (params) => {
|
|
84
|
+
const { field, value } = params;
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
if (field.isEmbedded) return value;
|
|
87
|
+
|
|
88
|
+
switch (field.type.toLowerCase()) {
|
|
87
89
|
case 'string': {
|
|
88
90
|
return `${value}`;
|
|
89
91
|
}
|
package/src/data/Resolver.js
CHANGED
|
@@ -173,7 +173,7 @@ module.exports = class Resolver {
|
|
|
173
173
|
|
|
174
174
|
// All transactions bound to this resolver are to be rolled back
|
|
175
175
|
return Util.promiseChain(session.map(transaction => () => {
|
|
176
|
-
transaction.rollback().catch(e => errors.push(e));
|
|
176
|
+
return transaction.rollback().catch(e => errors.push(e));
|
|
177
177
|
})).then(() => {
|
|
178
178
|
return errors.length ? Promise.reject(errors) : Promise.all(session.thunks.map(thunk => thunk()));
|
|
179
179
|
});
|
package/src/schema/Schema.js
CHANGED
|
@@ -459,7 +459,16 @@ module.exports = class Schema {
|
|
|
459
459
|
if (scalar) Object.entries(scalar.pipelines).forEach(([key, values]) => $field.pipelines[key].push(...values));
|
|
460
460
|
|
|
461
461
|
if ($field.isArray) $field.pipelines.normalize.unshift('toArray');
|
|
462
|
-
|
|
462
|
+
|
|
463
|
+
// Will create/convert to ID type always
|
|
464
|
+
if ($field.isPrimaryKey) {
|
|
465
|
+
$field.pipelines.construct.unshift('$pk');
|
|
466
|
+
$field.pipelines.restruct.unshift('$pk');
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// Will convert to ID type IFF defined in payload
|
|
470
|
+
if ($field.isFKReference || $field.isPrimaryKey) $field.pipelines.serialize.unshift('$fk');
|
|
471
|
+
|
|
463
472
|
if ($field.isRequired && $field.isPersistable && !$field.isVirtual) $field.pipelines.validate.push('required');
|
|
464
473
|
|
|
465
474
|
if ($field.isFKReference) {
|
|
@@ -468,7 +477,6 @@ module.exports = class Schema {
|
|
|
468
477
|
const from = $field.linkField.key;
|
|
469
478
|
const as = `join_${to}`;
|
|
470
479
|
$field.join = { to, on, from, as };
|
|
471
|
-
$field.pipelines.serialize.unshift('$fk'); // Will convert to FK type IFF defined in payload
|
|
472
480
|
$field.pipelines.validate.push('ensureFK'); // Absolute Last
|
|
473
481
|
}
|
|
474
482
|
});
|