@strapi/database 5.0.0-rc.1 → 5.0.0-rc.11

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.
@@ -1,6 +1,6 @@
1
1
  import Field from './field';
2
2
  export default class JSONField extends Field {
3
- toDB(value: unknown): string;
3
+ toDB(value: unknown): {} | null;
4
4
  fromDB(value: unknown): any;
5
5
  }
6
6
  //# sourceMappingURL=json.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/fields/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,KAAK;IAC1C,IAAI,CAAC,KAAK,EAAE,OAAO;IAInB,MAAM,CAAC,KAAK,EAAE,OAAO;CAWtB"}
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/fields/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,KAAK;IAC1C,IAAI,CAAC,KAAK,EAAE,OAAO;IAYnB,MAAM,CAAC,KAAK,EAAE,OAAO;CAsBtB"}
package/dist/index.js CHANGED
@@ -2589,7 +2589,8 @@ const createJoinTable = (metadata, { attributeName, attribute, meta }) => {
2589
2589
  column: {
2590
2590
  unsigned: true,
2591
2591
  defaultTo: null
2592
- }
2592
+ },
2593
+ columnName: orderColumnName
2593
2594
  };
2594
2595
  metadataSchema.indexes.push({
2595
2596
  name: identifiers.getOrderFkIndexName(joinTableName),
@@ -2604,7 +2605,8 @@ const createJoinTable = (metadata, { attributeName, attribute, meta }) => {
2604
2605
  column: {
2605
2606
  unsigned: true,
2606
2607
  defaultTo: null
2607
- }
2608
+ },
2609
+ columnName: inverseOrderColumnName
2608
2610
  };
2609
2611
  metadataSchema.indexes.push({
2610
2612
  name: identifiers.getOrderInverseFkIndexName(joinTableName),
@@ -2775,12 +2777,22 @@ class StringField extends Field {
2775
2777
  }
2776
2778
  class JSONField extends Field {
2777
2779
  toDB(value) {
2778
- return JSON.stringify(value);
2780
+ if (value == null) {
2781
+ return null;
2782
+ }
2783
+ if (typeof value === "object") {
2784
+ return JSON.stringify(value);
2785
+ }
2786
+ return value;
2779
2787
  }
2780
2788
  fromDB(value) {
2781
2789
  try {
2782
2790
  if (typeof value === "string") {
2783
- return JSON.parse(value);
2791
+ const parsedValue = JSON.parse(value);
2792
+ if (typeof parsedValue === "string") {
2793
+ return JSON.parse(parsedValue);
2794
+ }
2795
+ return parsedValue;
2784
2796
  }
2785
2797
  } catch (error) {
2786
2798
  return value;