From 75a18e13a415d3eac97ec22227dbe9a5d14555d2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:28:43 +0000 Subject: [PATCH 1/4] Bump next from 14.2.10 to 14.2.15 in /examples/nextjs-api-sales Bumps [next](https://github.com/vercel/next.js) from 14.2.10 to 14.2.15. - [Release notes](https://github.com/vercel/next.js/releases) - [Changelog](https://github.com/vercel/next.js/blob/canary/release.js) - [Commits](https://github.com/vercel/next.js/compare/v14.2.10...v14.2.15) --- updated-dependencies: - dependency-name: next dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- examples/nextjs-api-sales/package.json | 2 +- examples/nextjs-api-sales/yarn.lock | 108 ++++++++++++------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/examples/nextjs-api-sales/package.json b/examples/nextjs-api-sales/package.json index 1f4335462b..1050c6b75e 100644 --- a/examples/nextjs-api-sales/package.json +++ b/examples/nextjs-api-sales/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "bulma": "^0.9.3", - "next": "14.2.10", + "next": "14.2.15", "node-fetch": "^3.2.10", "sass": "^1.52.3", "react": "17.0.2", diff --git a/examples/nextjs-api-sales/yarn.lock b/examples/nextjs-api-sales/yarn.lock index 40bf33da70..b595a148bf 100644 --- a/examples/nextjs-api-sales/yarn.lock +++ b/examples/nextjs-api-sales/yarn.lock @@ -46,10 +46,10 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== -"@next/env@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/env/-/env-14.2.10.tgz#1d3178340028ced2d679f84140877db4f420333c" - integrity sha512-dZIu93Bf5LUtluBXIv4woQw2cZVZ2DJTjax5/5DOs3lzEOeKLy7GxRSr4caK9/SCPdaW6bCgpye6+n4Dh9oJPw== +"@next/env@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/env/-/env-14.2.15.tgz#06d984e37e670d93ddd6790af1844aeb935f332f" + integrity sha512-S1qaj25Wru2dUpcIZMjxeMVSwkt8BK4dmWHHiBuRstcIyOsMapqT4A4jSB6onvqeygkSSmOkyny9VVx8JIGamQ== "@next/eslint-plugin-next@12.1.0": version "12.1.0" @@ -58,50 +58,50 @@ dependencies: glob "7.1.7" -"@next/swc-darwin-arm64@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.10.tgz#49d10ca4086fbd59ee68e204f75d7136eda2aa80" - integrity sha512-V3z10NV+cvMAfxQUMhKgfQnPbjw+Ew3cnr64b0lr8MDiBJs3eLnM6RpGC46nhfMZsiXgQngCJKWGTC/yDcgrDQ== +"@next/swc-darwin-arm64@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.15.tgz#6386d585f39a1c490c60b72b1f76612ba4434347" + integrity sha512-Rvh7KU9hOUBnZ9TJ28n2Oa7dD9cvDBKua9IKx7cfQQ0GoYUwg9ig31O2oMwH3wm+pE3IkAQ67ZobPfEgurPZIA== -"@next/swc-darwin-x64@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.10.tgz#0ebeae3afb8eac433882b79543295ab83624a1a8" - integrity sha512-Y0TC+FXbFUQ2MQgimJ/7Ina2mXIKhE7F+GUe1SgnzRmwFY3hX2z8nyVCxE82I2RicspdkZnSWMn4oTjIKz4uzA== +"@next/swc-darwin-x64@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.15.tgz#b7baeedc6a28f7545ad2bc55adbab25f7b45cb89" + integrity sha512-5TGyjFcf8ampZP3e+FyCax5zFVHi+Oe7sZyaKOngsqyaNEpOgkKB3sqmymkZfowy3ufGA/tUgDPPxpQx931lHg== -"@next/swc-linux-arm64-gnu@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.10.tgz#7e602916d2fb55a3c532f74bed926a0137c16f20" - integrity sha512-ZfQ7yOy5zyskSj9rFpa0Yd7gkrBnJTkYVSya95hX3zeBG9E55Z6OTNPn1j2BTFWvOVVj65C3T+qsjOyVI9DQpA== +"@next/swc-linux-arm64-gnu@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.15.tgz#fa13c59d3222f70fb4cb3544ac750db2c6e34d02" + integrity sha512-3Bwv4oc08ONiQ3FiOLKT72Q+ndEMyLNsc/D3qnLMbtUYTQAmkx9E/JRu0DBpHxNddBmNT5hxz1mYBphJ3mfrrw== -"@next/swc-linux-arm64-musl@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.10.tgz#6b143f628ccee490b527562e934f8de578d4be47" - integrity sha512-n2i5o3y2jpBfXFRxDREr342BGIQCJbdAUi/K4q6Env3aSx8erM9VuKXHw5KNROK9ejFSPf0LhoSkU/ZiNdacpQ== +"@next/swc-linux-arm64-musl@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.15.tgz#30e45b71831d9a6d6d18d7ac7d611a8d646a17f9" + integrity sha512-k5xf/tg1FBv/M4CMd8S+JL3uV9BnnRmoe7F+GWC3DxkTCD9aewFRH1s5rJ1zkzDa+Do4zyN8qD0N8c84Hu96FQ== -"@next/swc-linux-x64-gnu@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.10.tgz#086f2f16a0678890a1eb46518c4dda381b046082" - integrity sha512-GXvajAWh2woTT0GKEDlkVhFNxhJS/XdDmrVHrPOA83pLzlGPQnixqxD8u3bBB9oATBKB//5e4vpACnx5Vaxdqg== +"@next/swc-linux-x64-gnu@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.15.tgz#5065db17fc86f935ad117483f21f812dc1b39254" + integrity sha512-kE6q38hbrRbKEkkVn62reLXhThLRh6/TvgSP56GkFNhU22TbIrQDEMrO7j0IcQHcew2wfykq8lZyHFabz0oBrA== -"@next/swc-linux-x64-musl@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.10.tgz#1befef10ed8dbcc5047b5d637a25ae3c30a0bfc3" - integrity sha512-opFFN5B0SnO+HTz4Wq4HaylXGFV+iHrVxd3YvREUX9K+xfc4ePbRrxqOuPOFjtSuiVouwe6uLeDtabjEIbkmDA== +"@next/swc-linux-x64-musl@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.15.tgz#3c4a4568d8be7373a820f7576cf33388b5dab47e" + integrity sha512-PZ5YE9ouy/IdO7QVJeIcyLn/Rc4ml9M2G4y3kCM9MNf1YKvFY4heg3pVa/jQbMro+tP6yc4G2o9LjAz1zxD7tQ== -"@next/swc-win32-arm64-msvc@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.10.tgz#731f52c3ae3c56a26cf21d474b11ae1529531209" - integrity sha512-9NUzZuR8WiXTvv+EiU/MXdcQ1XUvFixbLIMNQiVHuzs7ZIFrJDLJDaOF1KaqttoTujpcxljM/RNAOmw1GhPPQQ== +"@next/swc-win32-arm64-msvc@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.15.tgz#fb812cc4ca0042868e32a6a021da91943bb08b98" + integrity sha512-2raR16703kBvYEQD9HNLyb0/394yfqzmIeyp2nDzcPV4yPjqNUG3ohX6jX00WryXz6s1FXpVhsCo3i+g4RUX+g== -"@next/swc-win32-ia32-msvc@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.10.tgz#32723ef7f04e25be12af357cc72ddfdd42fd1041" - integrity sha512-fr3aEbSd1GeW3YUMBkWAu4hcdjZ6g4NBl1uku4gAn661tcxd1bHs1THWYzdsbTRLcCKLjrDZlNp6j2HTfrw+Bg== +"@next/swc-win32-ia32-msvc@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.15.tgz#ec26e6169354f8ced240c1427be7fd485c5df898" + integrity sha512-fyTE8cklgkyR1p03kJa5zXEaZ9El+kDNM5A+66+8evQS5e/6v0Gk28LqA0Jet8gKSOyP+OTm/tJHzMlGdQerdQ== -"@next/swc-win32-x64-msvc@14.2.10": - version "14.2.10" - resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.10.tgz#ee1d036cb5ec871816f96baee7991035bb242455" - integrity sha512-UjeVoRGKNL2zfbcQ6fscmgjBAS/inHBh63mjIlfPg/NG8Yn2ztqylXt5qilYb6hoHIwaU2ogHknHWWmahJjgZQ== +"@next/swc-win32-x64-msvc@14.2.15": + version "14.2.15" + resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.15.tgz#18d68697002b282006771f8d92d79ade9efd35c4" + integrity sha512-SzqGbsLsP9OwKNUG9nekShTwhj6JSB9ZLMWQ8g1gG6hdE5gQLncbnbymrwy2yVmH9nikSLYRYxYMFu78Ggp7/g== "@nodelib/fs.scandir@2.1.5": version "2.1.5" @@ -1253,12 +1253,12 @@ natural-compare@^1.4.0: resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= -next@14.2.10: - version "14.2.10" - resolved "https://registry.yarnpkg.com/next/-/next-14.2.10.tgz#331981a4fecb1ae8af1817d4db98fc9687ee1cb6" - integrity sha512-sDDExXnh33cY3RkS9JuFEKaS4HmlWmDKP1VJioucCG6z5KuA008DPsDZOzi8UfqEk3Ii+2NCQSJrfbEWtZZfww== +next@14.2.15: + version "14.2.15" + resolved "https://registry.yarnpkg.com/next/-/next-14.2.15.tgz#348e5603e22649775d19c785c09a89c9acb5189a" + integrity sha512-h9ctmOokpoDphRvMGnwOJAedT6zKhwqyZML9mDtspgf4Rh3Pn7UTYKqePNoDvhsWBAO5GoPNYshnAUGIazVGmw== dependencies: - "@next/env" "14.2.10" + "@next/env" "14.2.15" "@swc/helpers" "0.5.5" busboy "1.6.0" caniuse-lite "^1.0.30001579" @@ -1266,15 +1266,15 @@ next@14.2.10: postcss "8.4.31" styled-jsx "5.1.1" optionalDependencies: - "@next/swc-darwin-arm64" "14.2.10" - "@next/swc-darwin-x64" "14.2.10" - "@next/swc-linux-arm64-gnu" "14.2.10" - "@next/swc-linux-arm64-musl" "14.2.10" - "@next/swc-linux-x64-gnu" "14.2.10" - "@next/swc-linux-x64-musl" "14.2.10" - "@next/swc-win32-arm64-msvc" "14.2.10" - "@next/swc-win32-ia32-msvc" "14.2.10" - "@next/swc-win32-x64-msvc" "14.2.10" + "@next/swc-darwin-arm64" "14.2.15" + "@next/swc-darwin-x64" "14.2.15" + "@next/swc-linux-arm64-gnu" "14.2.15" + "@next/swc-linux-arm64-musl" "14.2.15" + "@next/swc-linux-x64-gnu" "14.2.15" + "@next/swc-linux-x64-musl" "14.2.15" + "@next/swc-win32-arm64-msvc" "14.2.15" + "@next/swc-win32-ia32-msvc" "14.2.15" + "@next/swc-win32-x64-msvc" "14.2.15" node-domexception@^1.0.0: version "1.0.0" From fd388c3d36e037f2725b3069b35f71aea90035de Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 18 Dec 2024 15:43:05 +0000 Subject: [PATCH 2/4] Fix datasource validity checking --- packages/builder/src/stores/builder/datasources.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/stores/builder/datasources.ts b/packages/builder/src/stores/builder/datasources.ts index 6eeaeceaaf..e02774f1d5 100644 --- a/packages/builder/src/stores/builder/datasources.ts +++ b/packages/builder/src/stores/builder/datasources.ts @@ -220,7 +220,7 @@ export class DatasourceStore extends BudiStore { integration: Integration datasource: Datasource }) { - if (await this.checkDatasourceValidity(integration, datasource)) { + if (!(await this.checkDatasourceValidity(integration, datasource)).valid) { throw new Error("Unable to connect") } From 9650b388c4b6440ed9de4c73b3fd6029962205cd Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 18 Dec 2024 16:45:28 +0000 Subject: [PATCH 3/4] Refactor derived BudiStores --- packages/builder/src/stores/BudiStore.ts | 41 +++--- packages/builder/src/stores/builder/app.js | 2 +- .../builder/src/stores/builder/builder.js | 2 +- .../builder/src/stores/builder/components.js | 2 +- .../builder/src/stores/builder/datasources.ts | 132 +++++++++--------- packages/builder/src/stores/builder/hover.js | 2 +- .../builder/src/stores/builder/layouts.js | 2 +- .../builder/src/stores/builder/navigation.js | 2 +- .../builder/src/stores/builder/rowActions.js | 2 +- .../builder/src/stores/builder/screens.js | 2 +- .../src/stores/builder/sortedIntegrations.ts | 2 +- packages/builder/src/stores/portal/apps.ts | 2 +- .../builder/src/stores/portal/auditLogs.ts | 2 +- packages/builder/src/stores/portal/auth.ts | 2 +- 14 files changed, 97 insertions(+), 100 deletions(-) diff --git a/packages/builder/src/stores/BudiStore.ts b/packages/builder/src/stores/BudiStore.ts index c645ea6a24..706fa9474a 100644 --- a/packages/builder/src/stores/BudiStore.ts +++ b/packages/builder/src/stores/BudiStore.ts @@ -1,40 +1,22 @@ -import { writable, Writable } from "svelte/store" +import { writable, Writable, Readable } from "svelte/store" interface BudiStoreOpts { debug?: boolean } -export default class BudiStore implements Writable { +export class BudiStore { store: Writable subscribe: Writable["subscribe"] update: Writable["update"] set: Writable["set"] constructor(init: T, opts?: BudiStoreOpts) { - const store = writable(init) - - /** - * Internal Svelte store - */ - this.store = store - - /** - * Exposes the svelte subscribe fn to allow $ notation access - * @example - * $navigation.selectedScreenId - */ + this.store = writable(init) this.subscribe = this.store.subscribe - - /** - * Exposes the svelte update fn. - * *Store modification should be kept to a minimum - */ this.update = this.store.update this.set = this.store.set - /** - * Optional debug mode to output the store updates to console - */ + // Optional debug mode to output the store updates to console if (opts?.debug) { this.subscribe(state => { console.warn(`${this.constructor.name}`, state) @@ -42,3 +24,18 @@ export default class BudiStore implements Writable { } } } + +export class DerivedBudiStore extends BudiStore { + derivedStore: Readable + subscribe: Readable["subscribe"] + + constructor( + init: T, + makeDerivedStore: (store: Writable) => Readable, + opts?: BudiStoreOpts + ) { + super(init, opts) + this.derivedStore = makeDerivedStore(this.store) + this.subscribe = this.derivedStore.subscribe + } +} diff --git a/packages/builder/src/stores/builder/app.js b/packages/builder/src/stores/builder/app.js index e57a079185..3b9e4e0b3c 100644 --- a/packages/builder/src/stores/builder/app.js +++ b/packages/builder/src/stores/builder/app.js @@ -1,5 +1,5 @@ import { API } from "api" -import BudiStore from "../BudiStore" +import { BudiStore } from "../BudiStore" export const INITIAL_APP_META_STATE = { appId: "", diff --git a/packages/builder/src/stores/builder/builder.js b/packages/builder/src/stores/builder/builder.js index d002062da9..9b5a847680 100644 --- a/packages/builder/src/stores/builder/builder.js +++ b/packages/builder/src/stores/builder/builder.js @@ -1,7 +1,7 @@ import { get } from "svelte/store" import { createBuilderWebsocket } from "./websocket.js" import { BuilderSocketEvent } from "@budibase/shared-core" -import BudiStore from "../BudiStore.js" +import { BudiStore } from "../BudiStore.js" import { TOUR_KEYS } from "components/portal/onboarding/tours.js" export const INITIAL_BUILDER_STATE = { diff --git a/packages/builder/src/stores/builder/components.js b/packages/builder/src/stores/builder/components.js index faa6a086ca..e3fafd6f83 100644 --- a/packages/builder/src/stores/builder/components.js +++ b/packages/builder/src/stores/builder/components.js @@ -28,7 +28,7 @@ import { DB_TYPE_INTERNAL, DB_TYPE_EXTERNAL, } from "constants/backend" -import BudiStore from "../BudiStore" +import { BudiStore } from "../BudiStore" import { Utils } from "@budibase/frontend-core" import { FieldType } from "@budibase/types" import { utils } from "@budibase/shared-core" diff --git a/packages/builder/src/stores/builder/datasources.ts b/packages/builder/src/stores/builder/datasources.ts index e02774f1d5..6d94c1b26f 100644 --- a/packages/builder/src/stores/builder/datasources.ts +++ b/packages/builder/src/stores/builder/datasources.ts @@ -1,4 +1,4 @@ -import { derived, get } from "svelte/store" +import { derived, get, Writable } from "svelte/store" import { IntegrationTypes, DEFAULT_BB_DATASOURCE_ID, @@ -17,12 +17,7 @@ import { } from "@budibase/types" // @ts-ignore import { TableNames } from "constants" -import BudiStore from "stores/BudiStore" - -// when building the internal DS - seems to represent it slightly differently to the backend typing of a DS -interface InternalDatasource extends Omit { - entities: Table[] -} +import { DerivedBudiStore } from "stores/BudiStore" class TableImportError extends Error { errors: Record @@ -42,68 +37,76 @@ class TableImportError extends Error { } } +// when building the internal DS - seems to represent it slightly differently to the backend typing of a DS +interface InternalDatasource extends Omit { + entities: Table[] +} + interface BuilderDatasourceStore { - list: Datasource[] + datasources: Datasource[] selectedDatasourceId: null | string } -interface DerivedDatasourceStore extends Omit { +interface DerivedDatasourceStore extends BuilderDatasourceStore { list: (Datasource | InternalDatasource)[] selected?: Datasource | InternalDatasource hasDefaultData: boolean hasData: boolean } -export class DatasourceStore extends BudiStore { +export class DatasourceStore extends DerivedBudiStore< + BuilderDatasourceStore, + DerivedDatasourceStore +> { constructor() { - super({ - list: [], - selectedDatasourceId: null, - hasDefaultData: false, - hasData: false, - }) - - const derivedStore = derived< - [DatasourceStore, BudiStore], - DerivedDatasourceStore - >([this, tables as any], ([$store, $tables]) => { - // Set the internal datasource entities from the table list, which we're - // able to keep updated unlike the egress generated definition of the - // internal datasource - let internalDS: Datasource | InternalDatasource | undefined = - $store.list?.find(ds => ds._id === BUDIBASE_INTERNAL_DB_ID) - let otherDS = $store.list?.filter( - ds => ds._id !== BUDIBASE_INTERNAL_DB_ID - ) - if (internalDS) { - const tables: Table[] = $tables.list?.filter((table: Table) => { - return ( - table.sourceId === BUDIBASE_INTERNAL_DB_ID && - table._id !== TableNames.USERS - ) - }) - internalDS = { - ...internalDS, - entities: tables, + const makeDerivedStore = (store: Writable) => { + return derived([store, tables], ([$store, $tables]) => { + // Set the internal datasource entities from the table list, which we're + // able to keep updated unlike the egress generated definition of the + // internal datasource + let internalDS: Datasource | InternalDatasource | undefined = + $store.datasources?.find(ds => ds._id === BUDIBASE_INTERNAL_DB_ID) + let otherDS = $store.datasources?.filter( + ds => ds._id !== BUDIBASE_INTERNAL_DB_ID + ) + if (internalDS) { + const tables: Table[] = $tables.list?.filter((table: Table) => { + return ( + table.sourceId === BUDIBASE_INTERNAL_DB_ID && + table._id !== TableNames.USERS + ) + }) + internalDS = { + ...internalDS, + entities: tables, + } } - } - // Build up enriched DS list - // Only add the internal DS if we have at least one non-users table - let list: (InternalDatasource | Datasource)[] = [] - if (internalDS?.entities?.length) { - list.push(internalDS) - } - list = list.concat(otherDS || []) + // Build up enriched DS list + // Only add the internal DS if we have at least one non-users table + let list: (InternalDatasource | Datasource)[] = [] + if (internalDS?.entities?.length) { + list.push(internalDS) + } + list = list.concat(otherDS || []) - return { - ...$store, - list, - selected: list?.find(ds => ds._id === $store.selectedDatasourceId), - hasDefaultData: list?.some(ds => ds._id === DEFAULT_BB_DATASOURCE_ID), - hasData: list?.length > 0, - } - }) + return { + ...$store, + list, + selected: list?.find(ds => ds._id === $store.selectedDatasourceId), + hasDefaultData: list?.some(ds => ds._id === DEFAULT_BB_DATASOURCE_ID), + hasData: list?.length > 0, + } + }) + } + + super( + { + datasources: [], + selectedDatasourceId: null, + }, + makeDerivedStore + ) this.fetch = this.fetch.bind(this) this.init = this.fetch.bind(this) @@ -114,14 +117,13 @@ export class DatasourceStore extends BudiStore { this.save = this.save.bind(this) this.replaceDatasource = this.replaceDatasource.bind(this) this.getTableNames = this.getTableNames.bind(this) - this.subscribe = derivedStore.subscribe } async fetch() { const datasources = await API.getDatasources() this.store.update(state => ({ ...state, - list: datasources, + datasources, })) } @@ -158,7 +160,7 @@ export class DatasourceStore extends BudiStore { } sourceCount(source: string) { - return get(this.store).list.filter( + return get(this.store).datasources.filter( datasource => datasource.source === source ).length } @@ -250,7 +252,7 @@ export class DatasourceStore extends BudiStore { if (!datasource) { this.store.update(state => ({ ...state, - list: state.list.filter(x => x._id !== datasourceId), + datasources: state.datasources.filter(x => x._id !== datasourceId), })) tables.removeDatasourceTables(datasourceId) queries.removeDatasourceQueries(datasourceId) @@ -258,11 +260,13 @@ export class DatasourceStore extends BudiStore { } // Add new datasource - const index = get(this.store).list.findIndex(x => x._id === datasource._id) + const index = get(this.store).datasources.findIndex( + x => x._id === datasource._id + ) if (index === -1) { this.store.update(state => ({ ...state, - list: [...state.list, datasource], + datasources: [...state.datasources, datasource], })) // If this is a new datasource then we should refresh the tables list, @@ -273,7 +277,7 @@ export class DatasourceStore extends BudiStore { // Update existing datasource else if (datasource) { this.store.update(state => { - state.list[index] = datasource + state.datasources[index] = datasource return state }) } @@ -283,10 +287,6 @@ export class DatasourceStore extends BudiStore { const info = await API.fetchInfoForDatasource(datasource) return info.tableNames || [] } - - // subscribe() { - // return this.derivedStore.subscribe() - // } } export const datasources = new DatasourceStore() diff --git a/packages/builder/src/stores/builder/hover.js b/packages/builder/src/stores/builder/hover.js index 98cdc9e416..8da7191cf5 100644 --- a/packages/builder/src/stores/builder/hover.js +++ b/packages/builder/src/stores/builder/hover.js @@ -1,6 +1,6 @@ import { get } from "svelte/store" import { previewStore } from "stores/builder" -import BudiStore from "../BudiStore" +import { BudiStore } from "../BudiStore" export const INITIAL_HOVER_STATE = { componentId: null, diff --git a/packages/builder/src/stores/builder/layouts.js b/packages/builder/src/stores/builder/layouts.js index b105989746..6b68850a93 100644 --- a/packages/builder/src/stores/builder/layouts.js +++ b/packages/builder/src/stores/builder/layouts.js @@ -1,6 +1,6 @@ import { derived, get } from "svelte/store" import { componentStore } from "stores/builder" -import BudiStore from "../BudiStore" +import { BudiStore } from "../BudiStore" import { API } from "api" export const INITIAL_LAYOUT_STATE = { diff --git a/packages/builder/src/stores/builder/navigation.js b/packages/builder/src/stores/builder/navigation.js index c3e19a4327..abdd9638f3 100644 --- a/packages/builder/src/stores/builder/navigation.js +++ b/packages/builder/src/stores/builder/navigation.js @@ -1,7 +1,7 @@ import { get } from "svelte/store" import { API } from "api" import { appStore } from "stores/builder" -import BudiStore from "../BudiStore" +import { BudiStore } from "../BudiStore" export const INITIAL_NAVIGATION_STATE = { navigation: "Top", diff --git a/packages/builder/src/stores/builder/rowActions.js b/packages/builder/src/stores/builder/rowActions.js index a7ed45e707..553a574d53 100644 --- a/packages/builder/src/stores/builder/rowActions.js +++ b/packages/builder/src/stores/builder/rowActions.js @@ -1,5 +1,5 @@ import { get, derived } from "svelte/store" -import BudiStore from "stores/BudiStore" +import { BudiStore } from "stores/BudiStore" import { tables } from "./tables" import { viewsV2 } from "./viewsV2" import { automationStore } from "./automations" diff --git a/packages/builder/src/stores/builder/screens.js b/packages/builder/src/stores/builder/screens.js index 55fa3d5433..4e3d9b1ec6 100644 --- a/packages/builder/src/stores/builder/screens.js +++ b/packages/builder/src/stores/builder/screens.js @@ -12,7 +12,7 @@ import { } from "stores/builder" import { createHistoryStore } from "stores/builder/history" import { API } from "api" -import BudiStore from "../BudiStore" +import { BudiStore } from "../BudiStore" export const INITIAL_SCREENS_STATE = { screens: [], diff --git a/packages/builder/src/stores/builder/sortedIntegrations.ts b/packages/builder/src/stores/builder/sortedIntegrations.ts index 2c12e61b7f..76044af331 100644 --- a/packages/builder/src/stores/builder/sortedIntegrations.ts +++ b/packages/builder/src/stores/builder/sortedIntegrations.ts @@ -3,7 +3,7 @@ import { derived } from "svelte/store" import { DatasourceTypes } from "constants/backend" import { UIIntegration, Integration } from "@budibase/types" -import BudiStore from "stores/BudiStore" +import { BudiStore } from "stores/BudiStore" const getIntegrationOrder = (type: string | undefined) => { // if type is not known, sort to end diff --git a/packages/builder/src/stores/portal/apps.ts b/packages/builder/src/stores/portal/apps.ts index 867a554f00..f74ae4bfe2 100644 --- a/packages/builder/src/stores/portal/apps.ts +++ b/packages/builder/src/stores/portal/apps.ts @@ -3,7 +3,7 @@ import { derived } from "svelte/store" import { AppStatus } from "constants" import { API } from "api" import { auth } from "./auth" -import BudiStore from "../BudiStore" +import { BudiStore } from "../BudiStore" import { App, UpdateAppRequest } from "@budibase/types" interface AppIdentifierMetadata { diff --git a/packages/builder/src/stores/portal/auditLogs.ts b/packages/builder/src/stores/portal/auditLogs.ts index 10d79120ee..e97b301360 100644 --- a/packages/builder/src/stores/portal/auditLogs.ts +++ b/packages/builder/src/stores/portal/auditLogs.ts @@ -1,7 +1,7 @@ import { get } from "svelte/store" import { API } from "api" import { licensing } from "./licensing" -import BudiStore from "../BudiStore" +import { BudiStore } from "../BudiStore" import { DownloadAuditLogsRequest, SearchAuditLogsRequest, diff --git a/packages/builder/src/stores/portal/auth.ts b/packages/builder/src/stores/portal/auth.ts index 1f9646dd56..2affea85a7 100644 --- a/packages/builder/src/stores/portal/auth.ts +++ b/packages/builder/src/stores/portal/auth.ts @@ -2,7 +2,7 @@ import { get } from "svelte/store" import { API } from "api" import { admin } from "stores/portal" import analytics from "analytics" -import BudiStore from "stores/BudiStore" +import { BudiStore } from "stores/BudiStore" import { isSSOUser, SetInitInfoRequest, From 54c97186dfdcc0407a706adb211c92273ec9faea Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 18 Dec 2024 16:53:09 +0000 Subject: [PATCH 4/4] Rename datasources to rawList --- .../builder/src/stores/builder/datasources.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/builder/src/stores/builder/datasources.ts b/packages/builder/src/stores/builder/datasources.ts index 6d94c1b26f..54e9f85dbd 100644 --- a/packages/builder/src/stores/builder/datasources.ts +++ b/packages/builder/src/stores/builder/datasources.ts @@ -43,7 +43,7 @@ interface InternalDatasource extends Omit { } interface BuilderDatasourceStore { - datasources: Datasource[] + rawList: Datasource[] selectedDatasourceId: null | string } @@ -65,8 +65,8 @@ export class DatasourceStore extends DerivedBudiStore< // able to keep updated unlike the egress generated definition of the // internal datasource let internalDS: Datasource | InternalDatasource | undefined = - $store.datasources?.find(ds => ds._id === BUDIBASE_INTERNAL_DB_ID) - let otherDS = $store.datasources?.filter( + $store.rawList?.find(ds => ds._id === BUDIBASE_INTERNAL_DB_ID) + let otherDS = $store.rawList?.filter( ds => ds._id !== BUDIBASE_INTERNAL_DB_ID ) if (internalDS) { @@ -102,7 +102,7 @@ export class DatasourceStore extends DerivedBudiStore< super( { - datasources: [], + rawList: [], selectedDatasourceId: null, }, makeDerivedStore @@ -123,7 +123,7 @@ export class DatasourceStore extends DerivedBudiStore< const datasources = await API.getDatasources() this.store.update(state => ({ ...state, - datasources, + rawList: datasources, })) } @@ -160,7 +160,7 @@ export class DatasourceStore extends DerivedBudiStore< } sourceCount(source: string) { - return get(this.store).datasources.filter( + return get(this.store).rawList.filter( datasource => datasource.source === source ).length } @@ -252,7 +252,7 @@ export class DatasourceStore extends DerivedBudiStore< if (!datasource) { this.store.update(state => ({ ...state, - datasources: state.datasources.filter(x => x._id !== datasourceId), + rawList: state.rawList.filter(x => x._id !== datasourceId), })) tables.removeDatasourceTables(datasourceId) queries.removeDatasourceQueries(datasourceId) @@ -260,13 +260,13 @@ export class DatasourceStore extends DerivedBudiStore< } // Add new datasource - const index = get(this.store).datasources.findIndex( + const index = get(this.store).rawList.findIndex( x => x._id === datasource._id ) if (index === -1) { this.store.update(state => ({ ...state, - datasources: [...state.datasources, datasource], + rawList: [...state.rawList, datasource], })) // If this is a new datasource then we should refresh the tables list, @@ -277,7 +277,7 @@ export class DatasourceStore extends DerivedBudiStore< // Update existing datasource else if (datasource) { this.store.update(state => { - state.datasources[index] = datasource + state.rawList[index] = datasource return state }) }