@snowtop/ent 0.2.3-alpha2 → 0.2.4

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.
@@ -696,12 +696,29 @@ class Orchestrator {
696
696
  data[dbKey] = value;
697
697
  }
698
698
  if (defaultValue !== undefined) {
699
+ // Format defaults early so JSON/list defaults are DB-ready in edited data.
700
+ let formattedDefaultValue = defaultValue;
701
+ if (defaultValue !== null && !this.isBuilder(defaultValue) && field.format) {
702
+ let valid = true;
703
+ if (field.valid) {
704
+ valid = field.valid(defaultValue);
705
+ if ((0, types_1.isPromise)(valid)) {
706
+ valid = await valid;
707
+ }
708
+ }
709
+ if (valid) {
710
+ formattedDefaultValue = field.format(defaultValue);
711
+ if ((0, types_1.isPromise)(formattedDefaultValue)) {
712
+ formattedDefaultValue = await formattedDefaultValue;
713
+ }
714
+ }
715
+ }
699
716
  updateInput = true;
700
717
  if (updateOnlyIfOther) {
701
- defaultData[dbKey] = defaultValue;
718
+ defaultData[dbKey] = formattedDefaultValue;
702
719
  }
703
720
  else {
704
- data[dbKey] = defaultValue;
721
+ data[dbKey] = formattedDefaultValue;
705
722
  }
706
723
  this.defaultFieldsByFieldName[fieldName] = defaultValue;
707
724
  this.defaultFieldsByTSName[this.getInputKey(fieldName)] = defaultValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.2.3-alpha2",
3
+ "version": "0.2.4",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",