@snowtop/ent 0.1.0-alpha92-56721980-4046-11ed-ba1f-832778cd7daa → 0.1.0-alpha92-7ebc5680-4591-11ed-b331-8b0a5597e9d8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha92-56721980-4046-11ed-ba1f-832778cd7daa",
3
+ "version": "0.1.0-alpha92-7ebc5680-4591-11ed-b331-8b0a5597e9d8",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -23,27 +23,28 @@ class StructField extends field_1.BaseField {
23
23
  };
24
24
  }
25
25
  }
26
- // right now, we store things in the db in lowerCase format
27
- // this will lead to issues if field changes.
28
- // TODO: use storageKey and convert back...
29
26
  formatImpl(obj, nested) {
30
27
  if (!(obj instanceof Object)) {
31
28
  throw new Error("valid was not called");
32
29
  }
33
30
  let ret = {};
34
31
  for (const k in this.options.fields) {
32
+ const field = this.options.fields[k];
33
+ // check two values
34
+ // wait, two different things
35
+ // getStoragetKey and getCamelCase()
36
+ // for weird graphql case and for typescript format...
37
+ // store in dbKey format
35
38
  // TODO more #510
36
- let dbKey = (0, camel_case_1.camelCase)(k);
37
- let val = obj[dbKey];
38
- // for tests with snake_case
39
- if (val === undefined && obj[k] !== undefined) {
40
- val = obj[k];
41
- dbKey = k;
39
+ let dbKey = (0, schema_1.getStorageKey)(field, k);
40
+ let camelKey = (0, camel_case_1.camelCase)(k);
41
+ let val = obj[camelKey];
42
+ if (val === undefined && obj[dbKey] !== undefined) {
43
+ val = obj[dbKey];
42
44
  }
43
45
  if (val === undefined) {
44
46
  continue;
45
47
  }
46
- const field = this.options.fields[k];
47
48
  if (field.format) {
48
49
  // indicate nested so this isn't JSON stringified
49
50
  ret[dbKey] = field.format(val, true);
@@ -78,12 +79,11 @@ class StructField extends field_1.BaseField {
78
79
  for (const k in this.options.fields) {
79
80
  const field = this.options.fields[k];
80
81
  // TODO more #510
81
- let dbKey = (0, camel_case_1.camelCase)(k);
82
- let val = obj[dbKey];
83
- // for tests with snake_case
84
- if (val === undefined && obj[k] !== undefined) {
85
- val = obj[k];
86
- dbKey = k;
82
+ let dbKey = (0, schema_1.getStorageKey)(field, k);
83
+ let camelKey = (0, camel_case_1.camelCase)(k);
84
+ let val = obj[camelKey];
85
+ if (val === undefined && obj[dbKey] !== undefined) {
86
+ val = obj[dbKey];
87
87
  }
88
88
  if (val === undefined || val === null) {
89
89
  // nullable, nothing to do here