diff --git a/packages/builder/rollup.config.js b/packages/builder/rollup.config.js index a9897b1664..397a02b64d 100644 --- a/packages/builder/rollup.config.js +++ b/packages/builder/rollup.config.js @@ -60,6 +60,10 @@ export default { find: "builderStore", replacement: path.resolve(projectRootDir, "src/builderStore"), }, + { + find: "stores", + replacement: path.resolve(projectRootDir, "src/stores"), + }, { find: "constants", replacement: path.resolve(projectRootDir, "src/constants"), diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index f53fc66a01..a728b6d795 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -4,7 +4,7 @@ import { store } from "builderStore" import { tables as tablesStore, queries as queriesStores, -} from "builderStore/store/backend/" +} from "stores/backend/" import { findComponentPath } from "./storeUtils" import { makePropSafe } from "@budibase/string-templates" import { TableNames } from "../constants" diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 58717050dc..ac78f1a829 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -15,7 +15,7 @@ import { queries, database, tables, -} from "builderStore/store/backend/" +} from "stores/backend/" import { fetchComponentLibDefinitions } from "../loadComponentLibraries" import api from "../api" diff --git a/packages/builder/src/builderStore/store/screenTemplates/index.js b/packages/builder/src/builderStore/store/screenTemplates/index.js index 38ae434753..6f068674bf 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/index.js +++ b/packages/builder/src/builderStore/store/screenTemplates/index.js @@ -24,7 +24,7 @@ export default (frontendState, tables) => { }) const fromScratch = enrichTemplate(createFromScratchScreen) - const tableTemplates = allTemplates(tables).map(enrichTemplate) + const tableTemplates = allTemplates(tables.list).map(enrichTemplate) return [ fromScratch, ...tableTemplates.sort((templateA, templateB) => { diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte index 318d54943f..99b843ebc6 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte @@ -1,7 +1,7 @@ diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte index bde14adcb1..75a0a740f8 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte @@ -1,6 +1,6 @@ diff --git a/packages/builder/src/components/integration/QueryViewer.svelte b/packages/builder/src/components/integration/QueryViewer.svelte index ebdeb997b4..063bbf2309 100644 --- a/packages/builder/src/components/integration/QueryViewer.svelte +++ b/packages/builder/src/components/integration/QueryViewer.svelte @@ -15,7 +15,7 @@ import IntegrationQueryEditor from "components/integration/index.svelte" import ExternalDataSourceTable from "components/backend/DataTable/ExternalDataSourceTable.svelte" import ParameterBuilder from "components/integration/QueryParameterBuilder.svelte" - import { datasources, integrations } from 'builderStore/store/backend/' + import { datasources, integrations } from 'stores/backend/' const PREVIEW_HEADINGS = [ { diff --git a/packages/builder/src/components/settings/tabs/APIKeys.svelte b/packages/builder/src/components/settings/tabs/APIKeys.svelte index 546f24c106..e48af500dc 100644 --- a/packages/builder/src/components/settings/tabs/APIKeys.svelte +++ b/packages/builder/src/components/settings/tabs/APIKeys.svelte @@ -2,7 +2,7 @@ import { Input, Label, TextButton } from "@budibase/bbui" import api from "builderStore/api" import { notifier } from "builderStore/store/notifications" - import { database } from 'builderStore/store/backend/' + import { database } from 'stores/backend/' import analytics from "analytics" let keys = { budibase: "" } diff --git a/packages/builder/src/pages/[application]/_reset.svelte b/packages/builder/src/pages/[application]/_reset.svelte index dcc19e16c1..67df37de01 100644 --- a/packages/builder/src/pages/[application]/_reset.svelte +++ b/packages/builder/src/pages/[application]/_reset.svelte @@ -1,6 +1,6 @@ {#if $database?._id && $tables?.selected?.name} diff --git a/packages/builder/src/pages/[application]/data/table/_layout.svelte b/packages/builder/src/pages/[application]/data/table/_layout.svelte index f94954b840..1a542d9ad8 100644 --- a/packages/builder/src/pages/[application]/data/table/_layout.svelte +++ b/packages/builder/src/pages/[application]/data/table/_layout.svelte @@ -1,5 +1,5 @@ diff --git a/packages/builder/src/builderStore/store/backend/database.js b/packages/builder/src/stores/backend/database.js similarity index 100% rename from packages/builder/src/builderStore/store/backend/database.js rename to packages/builder/src/stores/backend/database.js diff --git a/packages/builder/src/builderStore/store/backend/datasources.js b/packages/builder/src/stores/backend/datasources.js similarity index 94% rename from packages/builder/src/builderStore/store/backend/datasources.js rename to packages/builder/src/stores/backend/datasources.js index 3fb54dd624..0f30695ea3 100644 --- a/packages/builder/src/builderStore/store/backend/datasources.js +++ b/packages/builder/src/stores/backend/datasources.js @@ -1,8 +1,8 @@ import { writable } from "svelte/store" import { queries } from "./" -import api from "../../api" +import api from "builderStore/api" -function createDatasourcesStore() { +export function createDatasourcesStore(_api = api) { const { subscribe, update, set } = writable({ list: [], selected: null, diff --git a/packages/builder/src/builderStore/store/backend/index.js b/packages/builder/src/stores/backend/index.js similarity index 100% rename from packages/builder/src/builderStore/store/backend/index.js rename to packages/builder/src/stores/backend/index.js diff --git a/packages/builder/src/builderStore/store/backend/integrations.js b/packages/builder/src/stores/backend/integrations.js similarity index 100% rename from packages/builder/src/builderStore/store/backend/integrations.js rename to packages/builder/src/stores/backend/integrations.js diff --git a/packages/builder/src/builderStore/store/backend/permissions.js b/packages/builder/src/stores/backend/permissions.js similarity index 90% rename from packages/builder/src/builderStore/store/backend/permissions.js rename to packages/builder/src/stores/backend/permissions.js index 70070f9072..6669ef3270 100644 --- a/packages/builder/src/builderStore/store/backend/permissions.js +++ b/packages/builder/src/stores/backend/permissions.js @@ -1,7 +1,8 @@ import { writable } from "svelte/store" -import api from "../../api" +import api from "builderStore/api" -function createPermissionStore() { + +export function createPermissionStore() { const { subscribe, set } = writable([]) return { diff --git a/packages/builder/src/builderStore/store/backend/queries.js b/packages/builder/src/stores/backend/queries.js similarity index 96% rename from packages/builder/src/builderStore/store/backend/queries.js rename to packages/builder/src/stores/backend/queries.js index ff2eda67ff..8bda870179 100644 --- a/packages/builder/src/builderStore/store/backend/queries.js +++ b/packages/builder/src/stores/backend/queries.js @@ -1,8 +1,9 @@ import { writable, get } from "svelte/store" import { datasources, integrations } from "./" -import api from "../../api" +import api from "builderStore/api" -function createQueriesStore() { + +export function createQueriesStore() { const { subscribe, set, update } = writable({ list: [], selected: null }) return { diff --git a/packages/builder/src/builderStore/store/backend/roles.js b/packages/builder/src/stores/backend/roles.js similarity index 89% rename from packages/builder/src/builderStore/store/backend/roles.js rename to packages/builder/src/stores/backend/roles.js index 1d353e433f..146ba9fbd8 100644 --- a/packages/builder/src/builderStore/store/backend/roles.js +++ b/packages/builder/src/stores/backend/roles.js @@ -1,7 +1,8 @@ import { writable } from "svelte/store" -import api from "../../api" +import api from "builderStore/api" -function createRolesStore() { + +export function createRolesStore() { const { subscribe, set } = writable([]) return { diff --git a/packages/builder/src/builderStore/store/backend/rows.js b/packages/builder/src/stores/backend/rows.js similarity index 88% rename from packages/builder/src/builderStore/store/backend/rows.js rename to packages/builder/src/stores/backend/rows.js index c16941925c..e3872d5873 100644 --- a/packages/builder/src/builderStore/store/backend/rows.js +++ b/packages/builder/src/stores/backend/rows.js @@ -1,7 +1,7 @@ import { writable, get } from "svelte/store" import { views } from "./" -function createRowsStore() { +export function createRowsStore() { const { subscribe } = writable([]) return { diff --git a/packages/builder/src/builderStore/store/backend/tables.js b/packages/builder/src/stores/backend/tables.js similarity index 97% rename from packages/builder/src/builderStore/store/backend/tables.js rename to packages/builder/src/stores/backend/tables.js index 74fd19bef9..c13a3d46ce 100644 --- a/packages/builder/src/builderStore/store/backend/tables.js +++ b/packages/builder/src/stores/backend/tables.js @@ -1,9 +1,10 @@ import { writable, get } from "svelte/store" import { views } from "./" import { cloneDeep } from "lodash/fp" -import api from "../../api" +import api from "builderStore/api" -function createTablesStore() { + +export function createTablesStore() { const store = writable({ list: [], selected: {}, diff --git a/packages/builder/src/stores/backend/tests/database.spec.js b/packages/builder/src/stores/backend/tests/database.spec.js new file mode 100644 index 0000000000..ccaf9c0570 --- /dev/null +++ b/packages/builder/src/stores/backend/tests/database.spec.js @@ -0,0 +1,26 @@ +import { database } from "../" + +describe("Backend DataSources Store", () => { + + let state; + let unsub; + + beforeEach(() => { + unsub = database.subscribe(s => state = s); + }) + afterEach(() => { + unsub() + }) + + it("initialises correctly", () => { + expect(state.list, []) + }) +}) + +const api = { + post: () => ({}), + get: () => ({}), + patch: () => ({}), + delete: () => ({}), + put: () => ({}), + } \ No newline at end of file diff --git a/packages/builder/src/stores/backend/tests/datasources.spec.js b/packages/builder/src/stores/backend/tests/datasources.spec.js new file mode 100644 index 0000000000..02c90d134c --- /dev/null +++ b/packages/builder/src/stores/backend/tests/datasources.spec.js @@ -0,0 +1,24 @@ +import { get } from 'svelte/store' +import { createDatasourcesStore } from "../datasources" + +const mockApi = { + post: () => ({}), + get: () => ({}), + patch: () => ({}), + delete: () => ({}), + put: () => ({}), +} + + +describe("Automation Data Object", () => { + let store + + beforeEach(() => { + store = createDatasourcesStore(mockApi) + }) + + it("Inits properly", () => { + const value = get(store) + expect(value).toBe(true) + }) +}) diff --git a/packages/builder/src/builderStore/store/backend/views.js b/packages/builder/src/stores/backend/views.js similarity index 93% rename from packages/builder/src/builderStore/store/backend/views.js rename to packages/builder/src/stores/backend/views.js index 7a97a9d325..5cd3c60267 100644 --- a/packages/builder/src/builderStore/store/backend/views.js +++ b/packages/builder/src/stores/backend/views.js @@ -1,8 +1,8 @@ import { writable, get } from "svelte/store" import { tables } from "./" -import api from "../../api" +import api from "builderStore/api" -function createViewsStore() { +export function createViewsStore() { const { subscribe, update } = writable({ list: [], selected: null, diff --git a/packages/builder/tests/stores/backend.spec.js b/packages/builder/tests/stores/backend.spec.js deleted file mode 100644 index e69de29bb2..0000000000