From f5da1a04e2a0dcb1ae00cd801d1482805a2a96c6 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Tue, 10 May 2022 21:59:39 +0100 Subject: [PATCH 1/5] Add query quota increment to rows CRUD --- .../server/src/api/controllers/row/index.ts | 34 +++++++++++-------- packages/server/yarn.lock | 18 +++++----- packages/worker/yarn.lock | 18 +++++----- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index c50fef496e..27810008d3 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -31,7 +31,9 @@ export async function patch(ctx: any): Promise { return save(ctx) } try { - const { row, table } = await pickApi(tableId).patch(ctx) + const { row, table } = await quotas.addQuery(() => + pickApi(tableId).patch(ctx) + ) ctx.status = 200 ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table) @@ -42,7 +44,7 @@ export async function patch(ctx: any): Promise { } } -const saveRow = async (ctx: any) => { +export const save = async (ctx: any) => { const appId = ctx.appId const tableId = getTableId(ctx) const body = ctx.request.body @@ -51,7 +53,9 @@ const saveRow = async (ctx: any) => { return patch(ctx) } try { - const { row, table } = await pickApi(tableId).save(ctx) + const { row, table } = await quotas.addRow(() => + quotas.addQuery(() => pickApi(tableId).save(ctx)) + ) ctx.status = 200 ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table) ctx.message = `${table.name} saved successfully` @@ -61,14 +65,10 @@ const saveRow = async (ctx: any) => { } } -export async function save(ctx: any) { - await quotas.addRow(() => saveRow(ctx)) -} - export async function fetchView(ctx: any) { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).fetchView(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).fetchView(ctx)) } catch (err) { ctx.throw(400, err) } @@ -77,7 +77,7 @@ export async function fetchView(ctx: any) { export async function fetch(ctx: any) { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).fetch(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).fetch(ctx)) } catch (err) { ctx.throw(400, err) } @@ -86,7 +86,7 @@ export async function fetch(ctx: any) { export async function find(ctx: any) { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).find(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx)) } catch (err) { ctx.throw(400, err) } @@ -98,14 +98,16 @@ export async function destroy(ctx: any) { const tableId = getTableId(ctx) let response, row if (inputs.rows) { - let { rows } = await pickApi(tableId).bulkDestroy(ctx) + let { rows } = await quotas.addQuery(() => + pickApi(tableId).bulkDestroy(ctx) + ) await quotas.removeRows(rows.length) response = rows for (let row of rows) { ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row) } } else { - let resp = await pickApi(tableId).destroy(ctx) + let resp = await quotas.addQuery(() => pickApi(tableId).destroy(ctx)) await quotas.removeRow() response = resp.response row = resp.row @@ -121,7 +123,7 @@ export async function search(ctx: any) { const tableId = getTableId(ctx) try { ctx.status = 200 - ctx.body = await pickApi(tableId).search(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).search(ctx)) } catch (err) { ctx.throw(400, err) } @@ -139,7 +141,9 @@ export async function validate(ctx: any) { export async function fetchEnrichedRow(ctx: any) { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx) + ctx.body = await quotas.addQuery(() => + pickApi(tableId).fetchEnrichedRow(ctx) + ) } catch (err) { ctx.throw(400, err) } @@ -148,7 +152,7 @@ export async function fetchEnrichedRow(ctx: any) { export const exportRows = async (ctx: any) => { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).exportRows(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).exportRows(ctx)) } catch (err) { ctx.throw(400, err) } diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index f9b414118f..9dd96cbd09 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -1014,10 +1014,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@1.0.147": - version "1.0.147" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.147.tgz#fc93a803e97e304170b33bd28b4f5deda32bec18" - integrity sha512-0GcF9G/tTAsko9g352MB8K3EtMTVb7v7Av6RdsYyKBdVtOD42HKFzSOD0n/RQUL4v70YByiu99zJAB6z1m1Pcg== +"@budibase/backend-core@1.0.149": + version "1.0.149" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.149.tgz#44e00dc718ef3f5c2f8021a13799c05b89f03cfa" + integrity sha512-RudWkU6I+AoiARKcjDAKYmKgpW99VAmw8cULyL2QexFtrJaPwRX6UXDqP3Et887rAN+ee3t3tFIWEui51LAVPg== dependencies: "@techpass/passport-openidconnect" "^0.3.0" aws-sdk "^2.901.0" @@ -1091,12 +1091,12 @@ svelte-flatpickr "^3.2.3" svelte-portal "^1.0.0" -"@budibase/pro@1.0.147": - version "1.0.147" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.147.tgz#c1ec9d92ffaa40285a83c57ddbec1f32802cd9a1" - integrity sha512-e4im6Byqeeit/QFHkVhVdRmgIlJJY/W06cQrOuiG/1ngO4PGnXeJqtjQjHVfvchD5Xi3y1MgQ4AtH2Bzb5LEhw== +"@budibase/pro@1.0.149": + version "1.0.149" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.149.tgz#6d3cc93635baffad4f425576c452bf9b8c6eb15e" + integrity sha512-zS+xIezmcJEB2yXzwSNI0OVDmFsBtE4r8ZVHKw+pGo1KqdJ1i11DEsfoAp9VxKOoo1ENDultujALfZQYlesMww== dependencies: - "@budibase/backend-core" "1.0.147" + "@budibase/backend-core" "1.0.149" node-fetch "^2.6.1" "@budibase/standard-components@^0.9.139": diff --git a/packages/worker/yarn.lock b/packages/worker/yarn.lock index 80f2996bec..c0a3bd76ce 100644 --- a/packages/worker/yarn.lock +++ b/packages/worker/yarn.lock @@ -293,10 +293,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@1.0.147": - version "1.0.147" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.147.tgz#fc93a803e97e304170b33bd28b4f5deda32bec18" - integrity sha512-0GcF9G/tTAsko9g352MB8K3EtMTVb7v7Av6RdsYyKBdVtOD42HKFzSOD0n/RQUL4v70YByiu99zJAB6z1m1Pcg== +"@budibase/backend-core@1.0.149": + version "1.0.149" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.149.tgz#44e00dc718ef3f5c2f8021a13799c05b89f03cfa" + integrity sha512-RudWkU6I+AoiARKcjDAKYmKgpW99VAmw8cULyL2QexFtrJaPwRX6UXDqP3Et887rAN+ee3t3tFIWEui51LAVPg== dependencies: "@techpass/passport-openidconnect" "^0.3.0" aws-sdk "^2.901.0" @@ -321,12 +321,12 @@ uuid "^8.3.2" zlib "^1.0.5" -"@budibase/pro@1.0.147": - version "1.0.147" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.147.tgz#c1ec9d92ffaa40285a83c57ddbec1f32802cd9a1" - integrity sha512-e4im6Byqeeit/QFHkVhVdRmgIlJJY/W06cQrOuiG/1ngO4PGnXeJqtjQjHVfvchD5Xi3y1MgQ4AtH2Bzb5LEhw== +"@budibase/pro@1.0.149": + version "1.0.149" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.149.tgz#6d3cc93635baffad4f425576c452bf9b8c6eb15e" + integrity sha512-zS+xIezmcJEB2yXzwSNI0OVDmFsBtE4r8ZVHKw+pGo1KqdJ1i11DEsfoAp9VxKOoo1ENDultujALfZQYlesMww== dependencies: - "@budibase/backend-core" "1.0.147" + "@budibase/backend-core" "1.0.149" node-fetch "^2.6.1" "@cspotcode/source-map-consumer@0.8.0": From 232c22305480c7f88b7c7d50342363ea3aa3461e Mon Sep 17 00:00:00 2001 From: Budibase Release Bot <> Date: Wed, 11 May 2022 09:42:20 +0000 Subject: [PATCH 2/5] v1.0.151 --- lerna.json | 2 +- packages/backend-core/package.json | 2 +- packages/bbui/package.json | 4 ++-- packages/builder/package.json | 10 +++++----- packages/cli/package.json | 2 +- packages/client/package.json | 8 ++++---- packages/frontend-core/package.json | 4 ++-- packages/server/package.json | 8 ++++---- packages/string-templates/package.json | 2 +- packages/worker/package.json | 6 +++--- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lerna.json b/lerna.json index a72ecea0e2..f2c4ad1456 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.0.150", + "version": "1.0.151", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json index a45cbb1e33..0be5e7ad0c 100644 --- a/packages/backend-core/package.json +++ b/packages/backend-core/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/backend-core", - "version": "1.0.150", + "version": "1.0.151", "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 cb3d754435..f453175449 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.150", + "version": "1.0.151", "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.150", + "@budibase/string-templates": "^1.0.151", "@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 03bbb4483f..1954fb48a3 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "1.0.150", + "version": "1.0.151", "license": "GPL-3.0", "private": true, "scripts": { @@ -67,10 +67,10 @@ } }, "dependencies": { - "@budibase/bbui": "^1.0.150", - "@budibase/client": "^1.0.150", - "@budibase/frontend-core": "^1.0.150", - "@budibase/string-templates": "^1.0.150", + "@budibase/bbui": "^1.0.151", + "@budibase/client": "^1.0.151", + "@budibase/frontend-core": "^1.0.151", + "@budibase/string-templates": "^1.0.151", "@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 2c218728e0..f1968db2a6 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/cli", - "version": "1.0.150", + "version": "1.0.151", "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 5357264d22..b5f6ae0e20 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/client", - "version": "1.0.150", + "version": "1.0.151", "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.150", - "@budibase/frontend-core": "^1.0.150", - "@budibase/string-templates": "^1.0.150", + "@budibase/bbui": "^1.0.151", + "@budibase/frontend-core": "^1.0.151", + "@budibase/string-templates": "^1.0.151", "@spectrum-css/button": "^3.0.3", "@spectrum-css/card": "^3.0.3", "@spectrum-css/divider": "^1.0.3", diff --git a/packages/frontend-core/package.json b/packages/frontend-core/package.json index 6e9308712c..a3c4e5096f 100644 --- a/packages/frontend-core/package.json +++ b/packages/frontend-core/package.json @@ -1,12 +1,12 @@ { "name": "@budibase/frontend-core", - "version": "1.0.150", + "version": "1.0.151", "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.150", + "@budibase/bbui": "^1.0.151", "lodash": "^4.17.21", "svelte": "^3.46.2" } diff --git a/packages/server/package.json b/packages/server/package.json index 1caebe235f..33c18e7d07 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.150", + "version": "1.0.151", "description": "Budibase Web Server", "main": "src/index.ts", "repository": { @@ -69,10 +69,10 @@ "license": "GPL-3.0", "dependencies": { "@apidevtools/swagger-parser": "^10.0.3", - "@budibase/backend-core": "^1.0.150", - "@budibase/client": "^1.0.150", + "@budibase/backend-core": "^1.0.151", + "@budibase/client": "^1.0.151", "@budibase/pro": "1.0.150", - "@budibase/string-templates": "^1.0.150", + "@budibase/string-templates": "^1.0.151", "@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 49737dfc2e..b9cbe92a55 100644 --- a/packages/string-templates/package.json +++ b/packages/string-templates/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/string-templates", - "version": "1.0.150", + "version": "1.0.151", "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 58400142bc..1f7778fffa 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.150", + "version": "1.0.151", "description": "Budibase background service", "main": "src/index.ts", "repository": { @@ -31,9 +31,9 @@ "author": "Budibase", "license": "GPL-3.0", "dependencies": { - "@budibase/backend-core": "^1.0.150", + "@budibase/backend-core": "^1.0.151", "@budibase/pro": "1.0.150", - "@budibase/string-templates": "^1.0.150", + "@budibase/string-templates": "^1.0.151", "@koa/router": "^8.0.0", "@sentry/node": "6.17.7", "@techpass/passport-openidconnect": "^0.3.0", From df915ad7be769306eb364b0f9b12343322fefcc7 Mon Sep 17 00:00:00 2001 From: Budibase Release Bot <> Date: Wed, 11 May 2022 09:43:28 +0000 Subject: [PATCH 3/5] Update pro version to 1.0.151 --- packages/server/package.json | 2 +- packages/worker/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/package.json b/packages/server/package.json index 33c18e7d07..c7da608ec7 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -71,7 +71,7 @@ "@apidevtools/swagger-parser": "^10.0.3", "@budibase/backend-core": "^1.0.151", "@budibase/client": "^1.0.151", - "@budibase/pro": "1.0.150", + "@budibase/pro": "1.0.151", "@budibase/string-templates": "^1.0.151", "@bull-board/api": "^3.7.0", "@bull-board/koa": "^3.7.0", diff --git a/packages/worker/package.json b/packages/worker/package.json index 1f7778fffa..219652ab3f 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -32,7 +32,7 @@ "license": "GPL-3.0", "dependencies": { "@budibase/backend-core": "^1.0.151", - "@budibase/pro": "1.0.150", + "@budibase/pro": "1.0.151", "@budibase/string-templates": "^1.0.151", "@koa/router": "^8.0.0", "@sentry/node": "6.17.7", From 54eea4191cf663505ad4c81074147434a15d7053 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 11 May 2022 11:32:53 +0100 Subject: [PATCH 4/5] tests --- .../server/src/api/routes/tests/row.spec.js | 92 ++++++++++++++++++- 1 file changed, 87 insertions(+), 5 deletions(-) diff --git a/packages/server/src/api/routes/tests/row.spec.js b/packages/server/src/api/routes/tests/row.spec.js index d7ec995edb..6b06b93872 100644 --- a/packages/server/src/api/routes/tests/row.spec.js +++ b/packages/server/src/api/routes/tests/row.spec.js @@ -3,6 +3,7 @@ const setup = require("./utilities") const { basicRow } = setup.structures const { doInAppContext } = require("@budibase/backend-core/context") const { doInTenant } = require("@budibase/backend-core/tenancy") +const { quotas, QuotaUsageType, StaticQuotaName, MonthlyQuotaName } = require("@budibase/pro") // mock the fetch for the search system jest.mock("node-fetch") @@ -28,9 +29,29 @@ describe("/rows", () => { .expect('Content-Type', /json/) .expect(status) + const getRowUsage = async () => { + return config.doInContext(null, () => quotas.getCurrentUsageValue(QuotaUsageType.STATIC, StaticQuotaName.ROWS)) + } + + const getQueryUsage = async () => { + return config.doInContext(null, () => quotas.getCurrentUsageValue(QuotaUsageType.MONTHLY, MonthlyQuotaName.QUERIES)) + } + + const assertRowUsage = async (expected) => { + const usage = await getRowUsage() + expect(usage).toBe(expected) + } + + const assertQueryUsage = async (expected) => { + const usage = await getQueryUsage() + expect(usage).toBe(expected) + } describe("save, load, update", () => { it("returns a success message when the row is created", async () => { + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + const res = await request .post(`/api/${row.tableId}/rows`) .send(row) @@ -40,10 +61,14 @@ describe("/rows", () => { expect(res.res.statusMessage).toEqual(`${table.name} saved successfully`) expect(res.body.name).toEqual("Test Contact") expect(res.body._rev).toBeDefined() + await assertRowUsage(rowUsage + 1) + await assertQueryUsage(queryUsage + 1) }) it("updates a row successfully", async () => { const existing = await config.createRow() + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() const res = await request .post(`/api/${table._id}/rows`) @@ -59,10 +84,13 @@ describe("/rows", () => { expect(res.res.statusMessage).toEqual(`${table.name} updated successfully.`) expect(res.body.name).toEqual("Updated Name") + await assertRowUsage(rowUsage) + await assertQueryUsage(queryUsage + 1) }) it("should load a row", async () => { const existing = await config.createRow() + const queryUsage = await getQueryUsage() const res = await request .get(`/api/${table._id}/rows/${existing._id}`) @@ -76,6 +104,7 @@ describe("/rows", () => { _rev: existing._rev, type: "row", }) + await assertQueryUsage(queryUsage + 1) }) it("should list all rows for given tableId", async () => { @@ -86,6 +115,7 @@ describe("/rows", () => { } await config.createRow() await config.createRow(newRow) + const queryUsage = await getQueryUsage() const res = await request .get(`/api/${table._id}/rows`) @@ -96,15 +126,19 @@ describe("/rows", () => { expect(res.body.length).toBe(2) expect(res.body.find(r => r.name === newRow.name)).toBeDefined() expect(res.body.find(r => r.name === row.name)).toBeDefined() + await assertQueryUsage(queryUsage + 1) }) it("load should return 404 when row does not exist", async () => { await config.createRow() + const queryUsage = await getQueryUsage() + await request .get(`/api/${table._id}/rows/not-a-valid-id`) .set(config.defaultHeaders()) .expect('Content-Type', /json/) .expect(404) + await assertQueryUsage(queryUsage) // no change }) it("row values are coerced", async () => { @@ -202,6 +236,9 @@ describe("/rows", () => { it("should update only the fields that are supplied", async () => { const existing = await config.createRow() + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + const res = await request .patch(`/api/${table._id}/rows`) .send({ @@ -222,10 +259,15 @@ describe("/rows", () => { expect(savedRow.body.description).toEqual(existing.description) expect(savedRow.body.name).toEqual("Updated Name") + await assertRowUsage(rowUsage) + await assertQueryUsage(queryUsage + 2) // account for the second load }) it("should throw an error when given improper types", async () => { const existing = await config.createRow() + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + await request .patch(`/api/${table._id}/rows`) .send({ @@ -236,12 +278,18 @@ describe("/rows", () => { }) .set(config.defaultHeaders()) .expect(400) + + await assertRowUsage(rowUsage) + await assertQueryUsage(queryUsage) }) }) describe("destroy", () => { it("should be able to delete a row", async () => { const createdRow = await config.createRow(row) + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + const res = await request .delete(`/api/${table._id}/rows`) .send({ @@ -253,11 +301,16 @@ describe("/rows", () => { .expect('Content-Type', /json/) .expect(200) expect(res.body[0]._id).toEqual(createdRow._id) + await assertRowUsage(rowUsage -1) + await assertQueryUsage(queryUsage +1) }) }) describe("validate", () => { it("should return no errors on valid row", async () => { + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + const res = await request .post(`/api/${table._id}/rows/validate`) .send({ name: "ivan" }) @@ -267,9 +320,14 @@ describe("/rows", () => { expect(res.body.valid).toBe(true) expect(Object.keys(res.body.errors)).toEqual([]) + await assertRowUsage(rowUsage) + await assertQueryUsage(queryUsage) }) it("should errors on invalid row", async () => { + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + const res = await request .post(`/api/${table._id}/rows/validate`) .send({ name: 1 }) @@ -279,7 +337,8 @@ describe("/rows", () => { expect(res.body.valid).toBe(false) expect(Object.keys(res.body.errors)).toEqual(["name"]) - + await assertRowUsage(rowUsage) + await assertQueryUsage(queryUsage) }) }) @@ -287,6 +346,9 @@ describe("/rows", () => { it("should be able to delete a bulk set of rows", async () => { const row1 = await config.createRow() const row2 = await config.createRow() + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + const res = await request .delete(`/api/${table._id}/rows`) .send({ @@ -298,14 +360,20 @@ describe("/rows", () => { .set(config.defaultHeaders()) .expect('Content-Type', /json/) .expect(200) + expect(res.body.length).toEqual(2) await loadRow(row1._id, 404) + await assertRowUsage(rowUsage - 2) + await assertQueryUsage(queryUsage +1) }) }) describe("fetchView", () => { it("should be able to fetch tables contents via 'view'", async () => { const row = await config.createRow() + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + const res = await request .get(`/api/views/${table._id}`) .set(config.defaultHeaders()) @@ -313,18 +381,29 @@ describe("/rows", () => { .expect(200) expect(res.body.length).toEqual(1) expect(res.body[0]._id).toEqual(row._id) + await assertRowUsage(rowUsage) + await assertQueryUsage(queryUsage +1) }) it("should throw an error if view doesn't exist", async () => { + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + await request .get(`/api/views/derp`) .set(config.defaultHeaders()) .expect(404) + + await assertRowUsage(rowUsage) + await assertQueryUsage(queryUsage) }) it("should be able to run on a view", async () => { const view = await config.createView() const row = await config.createRow() + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() + const res = await request .get(`/api/views/${view.name}`) .set(config.defaultHeaders()) @@ -332,13 +411,12 @@ describe("/rows", () => { .expect(200) expect(res.body.length).toEqual(1) expect(res.body[0]._id).toEqual(row._id) + + await assertRowUsage(rowUsage) + await assertQueryUsage(queryUsage + 1) }) }) - describe("user testing", () => { - - }) - describe("fetchEnrichedRows", () => { it("should allow enriching some linked rows", async () => { const { table, firstRow, secondRow } = await doInTenant(setup.structures.TENANT_ID, async () => { @@ -356,6 +434,8 @@ describe("/rows", () => { }) return { table, firstRow, secondRow } }) + const rowUsage = await getRowUsage() + const queryUsage = await getQueryUsage() // test basic enrichment const resBasic = await request @@ -376,6 +456,8 @@ describe("/rows", () => { expect(resEnriched.body.link[0]._id).toBe(firstRow._id) expect(resEnriched.body.link[0].name).toBe("Test Contact") expect(resEnriched.body.link[0].description).toBe("original description") + await assertRowUsage(rowUsage) + await assertQueryUsage(queryUsage +2) }) }) From a269f123a1c6cb01c0e71b75bd3b34bbeb430d9b Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 11 May 2022 11:57:55 +0100 Subject: [PATCH 5/5] Bump pro --- packages/server/package.json | 2 +- packages/server/yarn.lock | 18 +++++++++--------- packages/worker/package.json | 2 +- packages/worker/yarn.lock | 18 +++++++++--------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/server/package.json b/packages/server/package.json index c7da608ec7..33c18e7d07 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -71,7 +71,7 @@ "@apidevtools/swagger-parser": "^10.0.3", "@budibase/backend-core": "^1.0.151", "@budibase/client": "^1.0.151", - "@budibase/pro": "1.0.151", + "@budibase/pro": "1.0.150", "@budibase/string-templates": "^1.0.151", "@bull-board/api": "^3.7.0", "@bull-board/koa": "^3.7.0", diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 9dd96cbd09..dd402c4361 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -1014,10 +1014,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@1.0.149": - version "1.0.149" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.149.tgz#44e00dc718ef3f5c2f8021a13799c05b89f03cfa" - integrity sha512-RudWkU6I+AoiARKcjDAKYmKgpW99VAmw8cULyL2QexFtrJaPwRX6UXDqP3Et887rAN+ee3t3tFIWEui51LAVPg== +"@budibase/backend-core@1.0.150": + version "1.0.150" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.150.tgz#a48beb1e38f5e3e09473235fd2b7f35a05a15342" + integrity sha512-ceQVPnypKFurQMJgghky+MxtiF3x4b7rIzYhXv6Y+QfIb7IdY6wvv9o+dD3GPwNZJCRFSFizPR4YLBXdL+2+yw== dependencies: "@techpass/passport-openidconnect" "^0.3.0" aws-sdk "^2.901.0" @@ -1091,12 +1091,12 @@ svelte-flatpickr "^3.2.3" svelte-portal "^1.0.0" -"@budibase/pro@1.0.149": - version "1.0.149" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.149.tgz#6d3cc93635baffad4f425576c452bf9b8c6eb15e" - integrity sha512-zS+xIezmcJEB2yXzwSNI0OVDmFsBtE4r8ZVHKw+pGo1KqdJ1i11DEsfoAp9VxKOoo1ENDultujALfZQYlesMww== +"@budibase/pro@1.0.150": + version "1.0.150" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.150.tgz#06384561b67130bb2a93f0119921bd35d2be245c" + integrity sha512-Wlam8b5nhSeuNEj5Bb3ro1DKGX81mxxsjKMmxT4rbTqZrzuHSlTkxJ59IvUQqKuyp+cqfP6Rq/i4UXrhK0cg9Q== dependencies: - "@budibase/backend-core" "1.0.149" + "@budibase/backend-core" "1.0.150" node-fetch "^2.6.1" "@budibase/standard-components@^0.9.139": diff --git a/packages/worker/package.json b/packages/worker/package.json index 219652ab3f..1f7778fffa 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -32,7 +32,7 @@ "license": "GPL-3.0", "dependencies": { "@budibase/backend-core": "^1.0.151", - "@budibase/pro": "1.0.151", + "@budibase/pro": "1.0.150", "@budibase/string-templates": "^1.0.151", "@koa/router": "^8.0.0", "@sentry/node": "6.17.7", diff --git a/packages/worker/yarn.lock b/packages/worker/yarn.lock index c0a3bd76ce..a58efbdbcb 100644 --- a/packages/worker/yarn.lock +++ b/packages/worker/yarn.lock @@ -293,10 +293,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@1.0.149": - version "1.0.149" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.149.tgz#44e00dc718ef3f5c2f8021a13799c05b89f03cfa" - integrity sha512-RudWkU6I+AoiARKcjDAKYmKgpW99VAmw8cULyL2QexFtrJaPwRX6UXDqP3Et887rAN+ee3t3tFIWEui51LAVPg== +"@budibase/backend-core@1.0.150": + version "1.0.150" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.150.tgz#a48beb1e38f5e3e09473235fd2b7f35a05a15342" + integrity sha512-ceQVPnypKFurQMJgghky+MxtiF3x4b7rIzYhXv6Y+QfIb7IdY6wvv9o+dD3GPwNZJCRFSFizPR4YLBXdL+2+yw== dependencies: "@techpass/passport-openidconnect" "^0.3.0" aws-sdk "^2.901.0" @@ -321,12 +321,12 @@ uuid "^8.3.2" zlib "^1.0.5" -"@budibase/pro@1.0.149": - version "1.0.149" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.149.tgz#6d3cc93635baffad4f425576c452bf9b8c6eb15e" - integrity sha512-zS+xIezmcJEB2yXzwSNI0OVDmFsBtE4r8ZVHKw+pGo1KqdJ1i11DEsfoAp9VxKOoo1ENDultujALfZQYlesMww== +"@budibase/pro@1.0.150": + version "1.0.150" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.150.tgz#06384561b67130bb2a93f0119921bd35d2be245c" + integrity sha512-Wlam8b5nhSeuNEj5Bb3ro1DKGX81mxxsjKMmxT4rbTqZrzuHSlTkxJ59IvUQqKuyp+cqfP6Rq/i4UXrhK0cg9Q== dependencies: - "@budibase/backend-core" "1.0.149" + "@budibase/backend-core" "1.0.150" node-fetch "^2.6.1" "@cspotcode/source-map-consumer@0.8.0":