@budibase/frontend-core 3.2.35 → 3.2.38

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/frontend-core",
3
- "version": "3.2.35",
3
+ "version": "3.2.38",
4
4
  "description": "Budibase frontend core libraries used in builder and client",
5
5
  "author": "Budibase",
6
6
  "license": "MPL-2.0",
@@ -20,5 +20,5 @@
20
20
  "devDependencies": {
21
21
  "svelte-check": "^4.1.0"
22
22
  },
23
- "gitHead": "b3b24c0789b35d089f69e9b56ddfc7462c09fc0e"
23
+ "gitHead": "e3eabe9c968e531a30fe8848141f536d2b8a0b65"
24
24
  }
@@ -16,7 +16,7 @@ import { BaseAPIClient } from "./types"
16
16
  export interface ConfigEndpoints {
17
17
  getConfig: (type: ConfigType) => Promise<FindConfigResponse>
18
18
  getTenantConfig: (tentantId: string) => Promise<GetPublicSettingsResponse>
19
- getOIDCConfig: (tenantId: string) => Promise<GetPublicOIDCConfigResponse>
19
+ getOIDCConfigs: (tenantId: string) => Promise<GetPublicOIDCConfigResponse>
20
20
  getOIDCLogos: () => Promise<Config<OIDCLogosConfig>>
21
21
  saveConfig: (config: SaveConfigRequest) => Promise<SaveConfigResponse>
22
22
  deleteConfig: (id: string, rev: string) => Promise<DeleteConfigResponse>
@@ -73,7 +73,7 @@ export const buildConfigEndpoints = (API: BaseAPIClient): ConfigEndpoints => ({
73
73
  * Gets the OIDC config for a certain tenant.
74
74
  * @param tenantId the tenant ID to get the config for
75
75
  */
76
- getOIDCConfig: async tenantId => {
76
+ getOIDCConfigs: async tenantId => {
77
77
  return await API.get({
78
78
  url: `/api/global/configs/public/oidc?tenantId=${tenantId}`,
79
79
  })
package/src/api/views.ts CHANGED
@@ -3,7 +3,15 @@ import { BaseAPIClient } from "./types"
3
3
 
4
4
  export interface ViewEndpoints {
5
5
  // Missing request or response types
6
- fetchViewData: (name: string, opts: any) => Promise<Row[]>
6
+ fetchViewData: (
7
+ name: string,
8
+ opts: {
9
+ calculation?: string
10
+ field?: string
11
+ groupBy?: string
12
+ tableId: string
13
+ }
14
+ ) => Promise<Row[]>
7
15
  exportView: (name: string, format: string) => Promise<any>
8
16
  saveView: (view: any) => Promise<any>
9
17
  deleteView: (name: string) => Promise<any>
@@ -20,7 +28,9 @@ export const buildViewEndpoints = (API: BaseAPIClient): ViewEndpoints => ({
20
28
  fetchViewData: async (name, { field, groupBy, calculation }) => {
21
29
  const params = new URLSearchParams()
22
30
  if (calculation) {
23
- params.set("field", field)
31
+ if (field) {
32
+ params.set("field", field)
33
+ }
24
34
  params.set("calculation", calculation)
25
35
  }
26
36
  if (groupBy) {
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  CreateViewRequest,
3
3
  CreateViewResponse,
4
+ PaginatedSearchRowResponse,
4
5
  SearchRowResponse,
5
6
  SearchViewRowRequest,
6
7
  UpdateViewRequest,
@@ -13,10 +14,14 @@ export interface ViewV2Endpoints {
13
14
  fetchDefinition: (viewId: string) => Promise<ViewResponseEnriched>
14
15
  create: (view: CreateViewRequest) => Promise<CreateViewResponse>
15
16
  update: (view: UpdateViewRequest) => Promise<UpdateViewResponse>
16
- fetch: (
17
+ fetch: <T extends SearchViewRowRequest>(
17
18
  viewId: string,
18
- opts: SearchViewRowRequest
19
- ) => Promise<SearchRowResponse>
19
+ opts: T
20
+ ) => Promise<
21
+ T extends { paginate: true }
22
+ ? PaginatedSearchRowResponse
23
+ : SearchRowResponse
24
+ >
20
25
  delete: (viewId: string) => Promise<void>
21
26
  }
22
27
 
@@ -59,7 +64,7 @@ export const buildViewV2Endpoints = (API: BaseAPIClient): ViewV2Endpoints => ({
59
64
  * @param viewId the id of the view
60
65
  * @param opts the search options
61
66
  */
62
- fetch: async (viewId, opts) => {
67
+ fetch: async (viewId, opts: SearchViewRowRequest) => {
63
68
  return await API.post({
64
69
  url: `/api/v2/views/${encodeURIComponent(viewId)}/search`,
65
70
  body: opts,
@@ -69,7 +69,7 @@ export const deriveStores = (context: StoreContext): ConfigDerivedStore => {
69
69
  }
70
70
 
71
71
  // Disable features for non DS+
72
- if (!["table", "viewV2"].includes(type)) {
72
+ if (type && !["table", "viewV2"].includes(type)) {
73
73
  config.canAddRows = false
74
74
  config.canEditRows = false
75
75
  config.canDeleteRows = false
@@ -1,3 +1,5 @@
1
+ // TODO: datasource and defitions are unions of the different implementations. At this point, the datasource does not know what type is being used, and the assignations will cause TS exceptions. Casting it "as any" for now. This should be fixed improving the type usages.
2
+
1
3
  import { derived, get, Readable, Writable } from "svelte/store"
2
4
  import { getDatasourceDefinition, getDatasourceSchema } from "../../../fetch"
3
5
  import { enrichSchemaWithRelColumns, memo } from "../../../utils"
@@ -71,10 +73,10 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => {
71
73
  } = context
72
74
 
73
75
  const schema = derived(definition, $definition => {
74
- let schema: Record<string, UIFieldSchema> = getDatasourceSchema({
76
+ const schema: Record<string, any> | undefined = getDatasourceSchema({
75
77
  API,
76
- datasource: get(datasource),
77
- definition: $definition,
78
+ datasource: get(datasource) as any, // TODO: see line 1
79
+ definition: $definition ?? undefined,
78
80
  })
79
81
  if (!schema) {
80
82
  return null
@@ -82,7 +84,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => {
82
84
 
83
85
  // Ensure schema is configured as objects.
84
86
  // Certain datasources like queries use primitives.
85
- Object.keys(schema || {}).forEach(key => {
87
+ Object.keys(schema).forEach(key => {
86
88
  if (typeof schema[key] !== "object") {
87
89
  schema[key] = { name: key, type: schema[key] }
88
90
  }
@@ -130,13 +132,13 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => {
130
132
  ([$datasource, $definition]) => {
131
133
  let type = $datasource?.type
132
134
  if (type === "provider") {
133
- type = ($datasource as any).value?.datasource?.type
135
+ type = ($datasource as any).value?.datasource?.type // TODO: see line 1
134
136
  }
135
137
  // Handle calculation views
136
138
  if (type === "viewV2" && $definition?.type === ViewV2Type.CALCULATION) {
137
139
  return false
138
140
  }
139
- return ["table", "viewV2", "link"].includes(type)
141
+ return !!type && ["table", "viewV2", "link"].includes(type)
140
142
  }
141
143
  )
142
144
 
@@ -184,9 +186,9 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
184
186
  const refreshDefinition = async () => {
185
187
  const def = await getDatasourceDefinition({
186
188
  API,
187
- datasource: get(datasource),
189
+ datasource: get(datasource) as any, // TODO: see line 1
188
190
  })
189
- definition.set(def)
191
+ definition.set(def as any) // TODO: see line 1
190
192
  }
191
193
 
192
194
  // Saves the datasource definition
@@ -231,7 +233,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
231
233
  if ("default" in newDefinition.schema[column]) {
232
234
  delete newDefinition.schema[column].default
233
235
  }
234
- return await saveDefinition(newDefinition as any)
236
+ return await saveDefinition(newDefinition as any) // TODO: see line 1
235
237
  }
236
238
 
237
239
  // Adds a schema mutation for a single field
@@ -307,7 +309,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
307
309
  await saveDefinition({
308
310
  ...$definition,
309
311
  schema: newSchema,
310
- } as any)
312
+ } as any) // TODO: see line 1
311
313
  resetSchemaMutations()
312
314
  }
313
315
 
@@ -10,9 +10,10 @@ import {
10
10
  import { tick } from "svelte"
11
11
  import { Helpers } from "@budibase/bbui"
12
12
  import { sleep } from "../../../utils/utils"
13
- import { FieldType, Row, UIFetchAPI, UIRow } from "@budibase/types"
13
+ import { FieldType, Row, UIRow } from "@budibase/types"
14
14
  import { getRelatedTableValues } from "../../../utils"
15
15
  import { Store as StoreContext } from "."
16
+ import DataFetch from "../../../fetch/DataFetch"
16
17
 
17
18
  interface IndexedUIRow extends UIRow {
18
19
  __idx: number
@@ -20,7 +21,7 @@ interface IndexedUIRow extends UIRow {
20
21
 
21
22
  interface RowStore {
22
23
  rows: Writable<UIRow[]>
23
- fetch: Writable<UIFetchAPI | null>
24
+ fetch: Writable<DataFetch<any, any, any> | null> // TODO: type this properly, having a union of all the possible options
24
25
  loaded: Writable<boolean>
25
26
  refreshing: Writable<boolean>
26
27
  loading: Writable<boolean>
@@ -225,7 +226,7 @@ export const createActions = (context: StoreContext): RowActionStore => {
225
226
  })
226
227
 
227
228
  // Subscribe to changes of this fetch model
228
- unsubscribe = newFetch.subscribe(async ($fetch: UIFetchAPI) => {
229
+ unsubscribe = newFetch.subscribe(async $fetch => {
229
230
  if ($fetch.error) {
230
231
  // Present a helpful error to the user
231
232
  let message = "An unknown error occurred"
@@ -253,7 +254,7 @@ export const createActions = (context: StoreContext): RowActionStore => {
253
254
 
254
255
  // Reset state properties when dataset changes
255
256
  if (!$instanceLoaded || resetRows) {
256
- definition.set($fetch.definition)
257
+ definition.set($fetch.definition as any) // TODO: datasource and defitions are unions of the different implementations. At this point, the datasource does not know what type is being used, and the assignations will cause TS exceptions. Casting it "as any" for now. This should be fixed improving the type usages.
257
258
  }
258
259
 
259
260
  // Reset scroll state when data changes
package/src/constants.ts CHANGED
@@ -32,8 +32,8 @@ export const Cookies = {
32
32
  }
33
33
 
34
34
  // Table names
35
- export const TableNames = {
36
- USERS: "ta_users",
35
+ export const enum TableNames {
36
+ USERS = "ta_users",
37
37
  }
38
38
 
39
39
  export const BudibaseRoles = {
@@ -1,8 +1,17 @@
1
- import DataFetch from "./DataFetch.js"
1
+ import DataFetch from "./DataFetch"
2
2
 
3
- export default class CustomFetch extends DataFetch {
3
+ interface CustomDatasource {
4
+ data: any
5
+ }
6
+
7
+ type CustomDefinition = Record<string, any>
8
+
9
+ export default class CustomFetch extends DataFetch<
10
+ CustomDatasource,
11
+ CustomDefinition
12
+ > {
4
13
  // Gets the correct Budibase type for a JS value
5
- getType(value) {
14
+ getType(value: any) {
6
15
  if (value == null) {
7
16
  return "string"
8
17
  }
@@ -22,7 +31,7 @@ export default class CustomFetch extends DataFetch {
22
31
  }
23
32
 
24
33
  // Parses the custom data into an array format
25
- parseCustomData(data) {
34
+ parseCustomData(data: any) {
26
35
  if (!data) {
27
36
  return []
28
37
  }
@@ -55,7 +64,7 @@ export default class CustomFetch extends DataFetch {
55
64
  }
56
65
 
57
66
  // Enriches the custom data to ensure the structure and format is usable
58
- enrichCustomData(data) {
67
+ enrichCustomData(data: (string | any)[]) {
59
68
  if (!data?.length) {
60
69
  return []
61
70
  }
@@ -72,7 +81,7 @@ export default class CustomFetch extends DataFetch {
72
81
  // Try parsing strings
73
82
  if (typeof value === "string") {
74
83
  const split = value.split(",").map(x => x.trim())
75
- let obj = {}
84
+ const obj: Record<string, string> = {}
76
85
  for (let i = 0; i < split.length; i++) {
77
86
  const suffix = i === 0 ? "" : ` ${i + 1}`
78
87
  const key = `Value${suffix}`
@@ -87,27 +96,29 @@ export default class CustomFetch extends DataFetch {
87
96
  }
88
97
 
89
98
  // Extracts and parses the custom data from the datasource definition
90
- getCustomData(datasource) {
99
+ getCustomData(datasource: CustomDatasource) {
91
100
  return this.enrichCustomData(this.parseCustomData(datasource?.data))
92
101
  }
93
102
 
94
- async getDefinition(datasource) {
103
+ async getDefinition() {
104
+ const { datasource } = this.options
105
+
95
106
  // Try and work out the schema from the array provided
96
- let schema = {}
107
+ const schema: CustomDefinition = {}
97
108
  const data = this.getCustomData(datasource)
98
109
  if (!data?.length) {
99
110
  return { schema }
100
111
  }
101
112
 
102
113
  // Go through every object and extract all valid keys
103
- for (let datum of data) {
104
- for (let key of Object.keys(datum)) {
114
+ for (const datum of data) {
115
+ for (const key of Object.keys(datum)) {
105
116
  if (key === "_id") {
106
117
  continue
107
118
  }
108
119
  if (!schema[key]) {
109
120
  let type = this.getType(datum[key])
110
- let constraints = {}
121
+ const constraints: any = {}
111
122
 
112
123
  // Determine whether we should render text columns as options instead
113
124
  if (type === "string") {