diff --git a/packages/builder/src/constants/lucene.js b/packages/builder/src/constants/lucene.js deleted file mode 100644 index 159b66e35d..0000000000 --- a/packages/builder/src/constants/lucene.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Returns the valid operator options for a certain data type - * @param type the data type - */ -export const getValidOperatorsForType = type => { - const Op = OperatorOptions - if (type === "string") { - return [ - Op.Equals, - Op.NotEquals, - Op.StartsWith, - Op.Like, - Op.Empty, - Op.NotEmpty, - ] - } else if (type === "number") { - return [ - Op.Equals, - Op.NotEquals, - Op.MoreThan, - Op.LessThan, - Op.Empty, - Op.NotEmpty, - ] - } else if (type === "options") { - return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty] - } else if (type === "array") { - return [Op.Contains, Op.NotContains, Op.Empty, Op.NotEmpty] - } else if (type === "boolean") { - return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty] - } else if (type === "longform") { - return [ - Op.Equals, - Op.NotEquals, - Op.StartsWith, - Op.Like, - Op.Empty, - Op.NotEmpty, - ] - } else if (type === "datetime") { - return [ - Op.Equals, - Op.NotEquals, - Op.MoreThan, - Op.LessThan, - Op.Empty, - Op.NotEmpty, - ] - } - return [] -} diff --git a/packages/client/package.json b/packages/client/package.json index 68f9b8dd46..b45bb995e3 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -20,7 +20,7 @@ }, "dependencies": { "@budibase/bbui": "^1.0.44-alpha.7", - "@budibase/frontend-core": "^1.0.44-alpha.2", + "@budibase/frontend-core": "^1.0.44-alpha.7", "@budibase/standard-components": "^0.9.139", "@budibase/string-templates": "^1.0.44-alpha.7", "regexparam": "^1.3.0", diff --git a/packages/client/src/api.js b/packages/client/src/api.js index 71eb8fb2a4..911d421844 100644 --- a/packages/client/src/api.js +++ b/packages/client/src/api.js @@ -1,7 +1,6 @@ -import { createAPIClient } from "@budibase/frontend-core" +import { createAPIClient, Constants } from "@budibase/frontend-core" import { notificationStore } from "./stores" import { FieldTypes } from "./constants" -import { TableNames } from "@budibase/frontend-core/src/constants.js" export const API = createAPIClient({ // Attach client specific headers @@ -32,7 +31,7 @@ export const API = createAPIClient({ // Don't try to enrich a public user as it will 403 return user } else { - return (await enrichRows([user], TableNames.USERS))[0] + return (await enrichRows([user], Constants.TableNames.USERS))[0] } } else { return null diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte index 3ee288a8b6..a156c4c9e6 100644 --- a/packages/client/src/components/Component.svelte +++ b/packages/client/src/components/Component.svelte @@ -9,7 +9,7 @@ import Router from "./Router.svelte" import { enrichProps, propsAreSame } from "utils/componentProps" import { builderStore } from "stores" - import { Helpers } from "@budibase/frontend-core" + import { Helpers } from "@budibase/bbui" import Manifest from "manifest.json" import { getActiveConditions, reduceConditionActions } from "utils/conditions" import Placeholder from "components/app/Placeholder.svelte" diff --git a/packages/client/src/components/app/forms/Form.svelte b/packages/client/src/components/app/forms/Form.svelte index 134ca169a5..f0000233e6 100644 --- a/packages/client/src/components/app/forms/Form.svelte +++ b/packages/client/src/components/app/forms/Form.svelte @@ -1,7 +1,7 @@ diff --git a/packages/client/src/stores/context.js b/packages/client/src/stores/context.js index f8f8a49fe7..9c35bc4862 100644 --- a/packages/client/src/stores/context.js +++ b/packages/client/src/stores/context.js @@ -1,5 +1,5 @@ import { writable, derived } from "svelte/store" -import { Helpers } from "@budibase/frontend-core" +import { Helpers } from "@budibase/bbui" export const createContextStore = oldContext => { const newContext = writable({}) diff --git a/packages/client/src/utils/buttonActions.js b/packages/client/src/utils/buttonActions.js index a683ac2307..4498b3cb32 100644 --- a/packages/client/src/utils/buttonActions.js +++ b/packages/client/src/utils/buttonActions.js @@ -11,7 +11,7 @@ import { import { API } from "api" import { ActionTypes } from "constants" import { enrichDataBindings } from "./enrichDataBinding" -import { deepSet } from "@budibase/bbui" +import { Helpers } from "@budibase/bbui" const saveRowHandler = async (action, context) => { const { fields, providerId, tableId } = action.parameters @@ -23,7 +23,7 @@ const saveRowHandler = async (action, context) => { } if (fields) { for (let [field, value] of Object.entries(fields)) { - deepSet(payload, field, value) + Helpers.deepSet(payload, field, value) } } if (tableId) { @@ -49,7 +49,7 @@ const duplicateRowHandler = async (action, context) => { let payload = { ...context[providerId] } if (fields) { for (let [field, value] of Object.entries(fields)) { - deepSet(payload, field, value) + Helpers.deepSet(payload, field, value) } } if (tableId) { diff --git a/packages/client/src/utils/conditions.js b/packages/client/src/utils/conditions.js index 765c8141d0..1914e942ad 100644 --- a/packages/client/src/utils/conditions.js +++ b/packages/client/src/utils/conditions.js @@ -34,7 +34,7 @@ export const getActiveConditions = conditions => { } const query = LuceneUtils.buildLuceneQuery([luceneCondition]) - const result = LuceneUtils.luceneQuery([luceneCondition], query) + const result = LuceneUtils.runLuceneQuery([luceneCondition], query) return result.length > 0 }) } diff --git a/packages/frontend-core/.gitignore b/packages/frontend-core/.gitignore new file mode 100644 index 0000000000..1947eba17b --- /dev/null +++ b/packages/frontend-core/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +node_modules +package-lock.json +release/ +dist/ \ No newline at end of file diff --git a/packages/frontend-core/package.json b/packages/frontend-core/package.json index fcb2e8bd75..079ed250ad 100644 --- a/packages/frontend-core/package.json +++ b/packages/frontend-core/package.json @@ -1,11 +1,12 @@ { "name": "@budibase/frontend-core", - "version": "1.0.44-alpha.2", + "version": "1.0.44-alpha.7", "description": "Budibase frontend core libraries used in builder and client", "author": "Budibase", "license": "GPL-3.0", "svelte": "src/index.js", "dependencies": { + "@budibase/bbui": "^1.0.44-alpha.7", "lodash": "^4.17.21", "svelte": "^3.46.2" } diff --git a/packages/frontend-core/src/api/index.js b/packages/frontend-core/src/api/index.js index 3814f77ae6..3632670dce 100644 --- a/packages/frontend-core/src/api/index.js +++ b/packages/frontend-core/src/api/index.js @@ -154,7 +154,9 @@ export const createAPIClient = config => { get: requestApiCall("GET"), patch: requestApiCall("PATCH"), delete: requestApiCall("DELETE"), - error: message => throw makeError(message), + error: message => { + throw makeError(message) + }, } // Attach all other endpoints diff --git a/packages/frontend-core/src/index.js b/packages/frontend-core/src/index.js index 8aa941463f..7e474db757 100644 --- a/packages/frontend-core/src/index.js +++ b/packages/frontend-core/src/index.js @@ -1,9 +1,8 @@ -export * as API from "./api" +export { createAPIClient } from "./api" +export { createLocalStorageStore } from "./stores/localStorage" +export { fetchData } from "./fetch/fetchData" export * as Constants from "./constants" -export * as Helpers from "./utils/helpers" export * as LuceneUtils from "./utils/lucene" export * as JSONUtils from "./utils/json" export * as CookieUtils from "./utils/cookies" export * as SchemaUtils from "./utils/schema" -export { createLocalStorageStore } from "./stores/localStorage" -export { fetchData } from "./fetch/fetchData" diff --git a/packages/frontend-core/src/utils/lucene.js b/packages/frontend-core/src/utils/lucene.js index 242d453c96..7b725ad63d 100644 --- a/packages/frontend-core/src/utils/lucene.js +++ b/packages/frontend-core/src/utils/lucene.js @@ -1,4 +1,4 @@ -import { deepGet } from "./helpers" +import { Helpers } from "@budibase/bbui" /** * Operator options for lucene queries @@ -46,6 +46,58 @@ export const OperatorOptions = { }, } +/** + * Returns the valid operator options for a certain data type + * @param type the data type + */ +export const getValidOperatorsForType = type => { + const Op = OperatorOptions + if (type === "string") { + return [ + Op.Equals, + Op.NotEquals, + Op.StartsWith, + Op.Like, + Op.Empty, + Op.NotEmpty, + ] + } else if (type === "number") { + return [ + Op.Equals, + Op.NotEquals, + Op.MoreThan, + Op.LessThan, + Op.Empty, + Op.NotEmpty, + ] + } else if (type === "options") { + return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty] + } else if (type === "array") { + return [Op.Contains, Op.NotContains, Op.Empty, Op.NotEmpty] + } else if (type === "boolean") { + return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty] + } else if (type === "longform") { + return [ + Op.Equals, + Op.NotEquals, + Op.StartsWith, + Op.Like, + Op.Empty, + Op.NotEmpty, + ] + } else if (type === "datetime") { + return [ + Op.Equals, + Op.NotEquals, + Op.MoreThan, + Op.LessThan, + Op.Empty, + Op.NotEmpty, + ] + } + return [] +} + /** * Operators which do not support empty strings as values */ @@ -169,7 +221,7 @@ export const runLuceneQuery = (docs, query) => { const filters = Object.entries(query[type] || {}) for (let i = 0; i < filters.length; i++) { const [key, testValue] = filters[i] - const docValue = deepGet(doc, key) + const docValue = Helpers.deepGet(doc, key) if (failFn(docValue, testValue)) { return false }