diff --git a/lerna.json b/lerna.json index cd7687bc2d..3ce6a69194 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json index 89a143d769..144eb9b621 100644 --- a/packages/backend-core/package.json +++ b/packages/backend-core/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/backend-core", - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "description": "Budibase backend core libraries used in server and worker", "main": "src/index.js", "author": "Budibase", diff --git a/packages/bbui/package.json b/packages/bbui/package.json index 8a29c32a32..f6e75bcba0 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/bbui", "description": "A UI solution used in the different Budibase projects.", - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "license": "MPL-2.0", "svelte": "src/index.js", "module": "dist/bbui.es.js", @@ -38,7 +38,7 @@ ], "dependencies": { "@adobe/spectrum-css-workflow-icons": "^1.2.1", - "@budibase/string-templates": "^1.0.188-alpha.0", + "@budibase/string-templates": "^1.0.188-alpha.1", "@spectrum-css/actionbutton": "^1.0.1", "@spectrum-css/actiongroup": "^1.0.1", "@spectrum-css/avatar": "^3.0.2", diff --git a/packages/builder/package.json b/packages/builder/package.json index 0a4e019c8e..216a2a9ab0 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "license": "GPL-3.0", "private": true, "scripts": { @@ -69,10 +69,10 @@ } }, "dependencies": { - "@budibase/bbui": "^1.0.188-alpha.0", - "@budibase/client": "^1.0.188-alpha.0", - "@budibase/frontend-core": "^1.0.188-alpha.0", - "@budibase/string-templates": "^1.0.188-alpha.0", + "@budibase/bbui": "^1.0.188-alpha.1", + "@budibase/client": "^1.0.188-alpha.1", + "@budibase/frontend-core": "^1.0.188-alpha.1", + "@budibase/string-templates": "^1.0.188-alpha.1", "@sentry/browser": "5.19.1", "@spectrum-css/page": "^3.0.1", "@spectrum-css/vars": "^3.0.1", diff --git a/packages/cli/package.json b/packages/cli/package.json index b9c1326c8f..644a4671d3 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/cli", - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "description": "Budibase CLI, for developers, self hosting and migrations.", "main": "src/index.js", "bin": { diff --git a/packages/client/package.json b/packages/client/package.json index cb554a3005..c2382e6f0d 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/client", - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "license": "MPL-2.0", "module": "dist/budibase-client.js", "main": "dist/budibase-client.js", @@ -19,9 +19,9 @@ "dev:builder": "rollup -cw" }, "dependencies": { - "@budibase/bbui": "^1.0.188-alpha.0", - "@budibase/frontend-core": "^1.0.188-alpha.0", - "@budibase/string-templates": "^1.0.188-alpha.0", + "@budibase/bbui": "^1.0.188-alpha.1", + "@budibase/frontend-core": "^1.0.188-alpha.1", + "@budibase/string-templates": "^1.0.188-alpha.1", "@spectrum-css/button": "^3.0.3", "@spectrum-css/card": "^3.0.3", "@spectrum-css/divider": "^1.0.3", diff --git a/packages/client/src/utils/schema.js b/packages/client/src/utils/schema.js index fba25e384a..46c352a29f 100644 --- a/packages/client/src/utils/schema.js +++ b/packages/client/src/utils/schema.js @@ -1,5 +1,4 @@ import { API } from "api" -import { JSONUtils } from "@budibase/frontend-core" import TableFetch from "@budibase/frontend-core/src/fetch/TableFetch.js" import ViewFetch from "@budibase/frontend-core/src/fetch/ViewFetch.js" import QueryFetch from "@budibase/frontend-core/src/fetch/QueryFetch.js" @@ -40,44 +39,41 @@ export const fetchDatasourceSchema = async ( return null } - // Check for any JSON fields so we can add any top level properties - let jsonAdditions = {} - Object.keys(schema).forEach(fieldKey => { + // Enrich schema with relationships if required + if (definition?.sql && options?.enrichRelationships) { + const relationshipAdditions = await getRelationshipSchemaAdditions(schema) + schema = { + ...schema, + ...relationshipAdditions, + } + } + + // Ensure schema is in the correct structure + return instance.enrichSchema(schema) +} + +/** + * Fetches the schema of relationship fields for a SQL table schema + * @param schema the schema to enrich + */ +export const getRelationshipSchemaAdditions = async schema => { + if (!schema) { + return null + } + let relationshipAdditions = {} + for (let fieldKey of Object.keys(schema)) { const fieldSchema = schema[fieldKey] - if (fieldSchema?.type === "json") { - const jsonSchema = JSONUtils.convertJSONSchemaToTableSchema(fieldSchema, { - squashObjects: true, + if (fieldSchema?.type === "link") { + const linkSchema = await fetchDatasourceSchema({ + type: "table", + tableId: fieldSchema?.tableId, }) - Object.keys(jsonSchema).forEach(jsonKey => { - jsonAdditions[`${fieldKey}.${jsonKey}`] = { - type: jsonSchema[jsonKey].type, - nestedJSON: true, + Object.keys(linkSchema || {}).forEach(linkKey => { + relationshipAdditions[`${fieldKey}.${linkKey}`] = { + type: linkSchema[linkKey].type, } }) } - }) - schema = { ...schema, ...jsonAdditions } - - // Check for any relationship fields if required - if (options?.enrichRelationships && definition.sql) { - let relationshipAdditions = {} - for (let fieldKey of Object.keys(schema)) { - const fieldSchema = schema[fieldKey] - if (fieldSchema?.type === "link") { - const linkSchema = await fetchDatasourceSchema({ - type: "table", - tableId: fieldSchema?.tableId, - }) - Object.keys(linkSchema || {}).forEach(linkKey => { - relationshipAdditions[`${fieldKey}.${linkKey}`] = { - type: linkSchema[linkKey].type, - } - }) - } - } - schema = { ...schema, ...relationshipAdditions } } - - // Ensure schema structure is correct - return instance.enrichSchema(schema) + return relationshipAdditions } diff --git a/packages/frontend-core/package.json b/packages/frontend-core/package.json index 73fe396b8e..546c3de615 100644 --- a/packages/frontend-core/package.json +++ b/packages/frontend-core/package.json @@ -1,12 +1,12 @@ { "name": "@budibase/frontend-core", - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "description": "Budibase frontend core libraries used in builder and client", "author": "Budibase", "license": "MPL-2.0", "svelte": "src/index.js", "dependencies": { - "@budibase/bbui": "^1.0.188-alpha.0", + "@budibase/bbui": "^1.0.188-alpha.1", "lodash": "^4.17.21", "svelte": "^3.46.2" } diff --git a/packages/frontend-core/src/fetch/DataFetch.js b/packages/frontend-core/src/fetch/DataFetch.js index 3455ee132b..ecd5313af5 100644 --- a/packages/frontend-core/src/fetch/DataFetch.js +++ b/packages/frontend-core/src/fetch/DataFetch.js @@ -6,6 +6,7 @@ import { runLuceneQuery, luceneSort, } from "../utils/lucene" +import { convertJSONSchemaToTableSchema } from "../utils/json" /** * Parent class which handles the implementation of fetching data from an @@ -248,7 +249,8 @@ export default class DataFetch { } /** - * Enriches the schema and ensures that entries are objects with names + * Enriches a datasource schema with nested fields and ensures the structure + * is correct. * @param schema the datasource schema * @return {object} the enriched datasource schema */ @@ -256,6 +258,26 @@ export default class DataFetch { if (schema == null) { return null } + + // Check for any JSON fields so we can add any top level properties + let jsonAdditions = {} + Object.keys(schema).forEach(fieldKey => { + const fieldSchema = schema[fieldKey] + if (fieldSchema?.type === "json") { + const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, { + squashObjects: true, + }) + Object.keys(jsonSchema).forEach(jsonKey => { + jsonAdditions[`${fieldKey}.${jsonKey}`] = { + type: jsonSchema[jsonKey].type, + nestedJSON: true, + } + }) + } + }) + schema = { ...schema, ...jsonAdditions } + + // Ensure schema is in the correct structure let enrichedSchema = {} Object.entries(schema).forEach(([fieldName, fieldSchema]) => { if (typeof fieldSchema === "string") { @@ -270,6 +292,7 @@ export default class DataFetch { } } }) + return enrichedSchema } diff --git a/packages/server/package.json b/packages/server/package.json index 45bbbe2aed..6b8f684c28 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/server", "email": "hi@budibase.com", - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "description": "Budibase Web Server", "main": "src/index.ts", "repository": { @@ -70,10 +70,10 @@ "license": "GPL-3.0", "dependencies": { "@apidevtools/swagger-parser": "^10.0.3", - "@budibase/backend-core": "^1.0.188-alpha.0", - "@budibase/client": "^1.0.188-alpha.0", - "@budibase/pro": "1.0.188-alpha.0", - "@budibase/string-templates": "^1.0.188-alpha.0", + "@budibase/backend-core": "^1.0.188-alpha.1", + "@budibase/client": "^1.0.188-alpha.1", + "@budibase/pro": "1.0.188-alpha.1", + "@budibase/string-templates": "^1.0.188-alpha.1", "@bull-board/api": "^3.7.0", "@bull-board/koa": "^3.7.0", "@elastic/elasticsearch": "7.10.0", diff --git a/packages/string-templates/package.json b/packages/string-templates/package.json index 5f20272f29..e923c067cd 100644 --- a/packages/string-templates/package.json +++ b/packages/string-templates/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/string-templates", - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "description": "Handlebars wrapper for Budibase templating.", "main": "src/index.cjs", "module": "dist/bundle.mjs", diff --git a/packages/worker/package.json b/packages/worker/package.json index abb5d2792b..ab3d4412f4 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/worker", "email": "hi@budibase.com", - "version": "1.0.188-alpha.0", + "version": "1.0.188-alpha.1", "description": "Budibase background service", "main": "src/index.ts", "repository": { @@ -32,9 +32,9 @@ "author": "Budibase", "license": "GPL-3.0", "dependencies": { - "@budibase/backend-core": "^1.0.188-alpha.0", - "@budibase/pro": "1.0.188-alpha.0", - "@budibase/string-templates": "^1.0.188-alpha.0", + "@budibase/backend-core": "^1.0.188-alpha.1", + "@budibase/pro": "1.0.188-alpha.1", + "@budibase/string-templates": "^1.0.188-alpha.1", "@koa/router": "^8.0.0", "@sentry/node": "6.17.7", "@techpass/passport-openidconnect": "^0.3.0",