@budibase/frontend-core 2.19.5 → 2.19.6

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,17 +1,17 @@
1
1
  {
2
2
  "name": "@budibase/frontend-core",
3
- "version": "2.19.5",
3
+ "version": "2.19.6",
4
4
  "description": "Budibase frontend core libraries used in builder and client",
5
5
  "author": "Budibase",
6
6
  "license": "MPL-2.0",
7
7
  "svelte": "src/index.js",
8
8
  "dependencies": {
9
- "@budibase/bbui": "2.19.5",
10
- "@budibase/shared-core": "2.19.5",
9
+ "@budibase/bbui": "2.19.6",
10
+ "@budibase/shared-core": "2.19.6",
11
11
  "dayjs": "^1.10.8",
12
12
  "lodash": "4.17.21",
13
13
  "socket.io-client": "^4.6.1",
14
14
  "svelte": "^3.49.0"
15
15
  },
16
- "gitHead": "856fc3e574dfd19c5b3b98fed3198ee1d58e4d48"
16
+ "gitHead": "8c4b94df09fdfac23f25a0bea15289236727f4d4"
17
17
  }
@@ -0,0 +1,25 @@
1
+ import FieldFetch from "./FieldFetch.js"
2
+ import {
3
+ getJSONArrayDatasourceSchema,
4
+ generateQueryArraySchemas,
5
+ } from "../utils/json"
6
+
7
+ export default class QueryArrayFetch extends FieldFetch {
8
+ async getDefinition(datasource) {
9
+ if (!datasource?.tableId) {
10
+ return null
11
+ }
12
+ // JSON arrays need their table definitions fetched.
13
+ // We can then extract their schema as a subset of the table schema.
14
+ try {
15
+ const table = await this.API.fetchQueryDefinition(datasource.tableId)
16
+ const schema = generateQueryArraySchemas(
17
+ table?.schema,
18
+ table?.nestedSchemaFields
19
+ )
20
+ return { schema: getJSONArrayDatasourceSchema(schema, datasource) }
21
+ } catch (error) {
22
+ return null
23
+ }
24
+ }
25
+ }
@@ -9,6 +9,7 @@ import JSONArrayFetch from "./JSONArrayFetch.js"
9
9
  import UserFetch from "./UserFetch.js"
10
10
  import GroupUserFetch from "./GroupUserFetch.js"
11
11
  import CustomFetch from "./CustomFetch.js"
12
+ import QueryArrayFetch from "./QueryArrayFetch.js"
12
13
 
13
14
  const DataFetchMap = {
14
15
  table: TableFetch,
@@ -24,6 +25,7 @@ const DataFetchMap = {
24
25
  provider: NestedProviderFetch,
25
26
  field: FieldFetch,
26
27
  jsonarray: JSONArrayFetch,
28
+ queryarray: QueryArrayFetch,
27
29
  }
28
30
 
29
31
  // Constructs a new fetch model for a certain datasource
package/src/utils/json.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { utils } from "@budibase/shared-core"
2
+
1
3
  /**
2
4
  * Gets the schema for a datasource which is targeting a JSON array, including
3
5
  * nested JSON arrays. The returned schema is a squashed, table-like schema
@@ -119,3 +121,33 @@ const extractJSONSchemaKeys = (jsonSchema, squashObjects = false) => {
119
121
  })
120
122
  return keys
121
123
  }
124
+
125
+ export const generateQueryArraySchemas = (schema, nestedSchemaFields) => {
126
+ for (let key in schema) {
127
+ if (
128
+ schema[key]?.type === "json" &&
129
+ schema[key]?.subtype === "array" &&
130
+ utils.hasSchema(nestedSchemaFields[key])
131
+ ) {
132
+ schema[key] = {
133
+ schema: {
134
+ schema: Object.entries(nestedSchemaFields[key] || {}).reduce(
135
+ (acc, [nestedKey, fieldSchema]) => {
136
+ acc[nestedKey] = {
137
+ name: nestedKey,
138
+ type: fieldSchema.type,
139
+ subtype: fieldSchema.subtype,
140
+ }
141
+ return acc
142
+ },
143
+ {}
144
+ ),
145
+ type: "json",
146
+ },
147
+ type: "json",
148
+ subtype: "array",
149
+ }
150
+ }
151
+ }
152
+ return schema
153
+ }