@budibase/backend-core 2.8.6-alpha.6 → 2.8.6

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/backend-core",
3
- "version": "2.8.6-alpha.6",
3
+ "version": "2.8.6",
4
4
  "description": "Budibase backend core libraries used in server and worker",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@budibase/nano": "10.1.2",
24
24
  "@budibase/pouchdb-replication-stream": "1.2.10",
25
- "@budibase/types": "2.8.6-alpha.6",
25
+ "@budibase/types": "2.8.6",
26
26
  "@shopify/jest-koa-mocks": "5.0.1",
27
27
  "@techpass/passport-openidconnect": "0.3.2",
28
28
  "aws-cloudfront-sign": "2.2.0",
@@ -51,7 +51,6 @@
51
51
  "pouchdb": "7.3.0",
52
52
  "pouchdb-find": "7.2.2",
53
53
  "redlock": "4.2.0",
54
- "rotating-file-stream": "3.1.0",
55
54
  "sanitize-s3-objectkey": "0.0.1",
56
55
  "semver": "7.3.7",
57
56
  "tar-fs": "2.1.1",
@@ -102,5 +101,5 @@
102
101
  }
103
102
  }
104
103
  },
105
- "gitHead": "19c9a9dadf41ed82e52b1adadcf2ac5698ced432"
104
+ "gitHead": "723068eae6b11ab8a807d90e6467eb19391de08e"
106
105
  }
package/src/db/lucene.ts CHANGED
@@ -433,6 +433,9 @@ export class QueryBuilder<T> {
433
433
  if (!value) {
434
434
  return null
435
435
  }
436
+ if (typeof value === "boolean") {
437
+ return `(*:* AND !${key}:${value})`
438
+ }
436
439
  return `!${key}:${builder.preprocess(value, allPreProcessingOpts)}`
437
440
  })
438
441
  }
@@ -47,10 +47,7 @@ function httpLogging() {
47
47
  return process.env.HTTP_LOGGING
48
48
  }
49
49
 
50
- function getPackageJsonFields(): {
51
- VERSION: string
52
- SERVICE_NAME: string
53
- } {
50
+ function findVersion() {
54
51
  function findFileInAncestors(
55
52
  fileName: string,
56
53
  currentDir: string
@@ -72,14 +69,10 @@ function getPackageJsonFields(): {
72
69
  try {
73
70
  const packageJsonFile = findFileInAncestors("package.json", process.cwd())
74
71
  const content = readFileSync(packageJsonFile!, "utf-8")
75
- const parsedContent = JSON.parse(content)
76
- return {
77
- VERSION: parsedContent.version,
78
- SERVICE_NAME: parsedContent.name,
79
- }
72
+ return JSON.parse(content).version
80
73
  } catch {
81
74
  // throwing an error here is confusing/causes backend-core to be hard to import
82
- return { VERSION: "", SERVICE_NAME: "" }
75
+ return undefined
83
76
  }
84
77
  }
85
78
 
@@ -161,14 +154,13 @@ const environment = {
161
154
  ENABLE_SSO_MAINTENANCE_MODE: selfHosted
162
155
  ? process.env.ENABLE_SSO_MAINTENANCE_MODE
163
156
  : false,
164
- ...getPackageJsonFields(),
157
+ VERSION: findVersion(),
165
158
  DISABLE_PINO_LOGGER: process.env.DISABLE_PINO_LOGGER,
166
159
  _set(key: any, value: any) {
167
160
  process.env[key] = value
168
161
  // @ts-ignore
169
162
  environment[key] = value
170
163
  },
171
- ROLLING_LOG_MAX_SIZE: process.env.ROLLING_LOG_MAX_SIZE || "10M",
172
164
  }
173
165
 
174
166
  // clean up any environment variable edge cases
@@ -1,7 +1,6 @@
1
1
  export * as correlation from "./correlation/correlation"
2
2
  export { logger } from "./pino/logger"
3
3
  export * from "./alerts"
4
- export * as system from "./system"
5
4
 
6
5
  // turn off or on context logging i.e. tenantId, appId etc
7
6
  export let LOG_CONTEXT = true
@@ -1,15 +1,10 @@
1
- import pino, { LoggerOptions } from "pino"
2
- import pinoPretty from "pino-pretty"
3
-
4
- import { IdentityType } from "@budibase/types"
5
-
6
1
  import env from "../../environment"
2
+ import pino, { LoggerOptions } from "pino"
7
3
  import * as context from "../../context"
8
4
  import * as correlation from "../correlation"
5
+ import { IdentityType } from "@budibase/types"
9
6
  import { LOG_CONTEXT } from "../index"
10
7
 
11
- import { localFileDestination } from "../system"
12
-
13
8
  // LOGGER
14
9
 
15
10
  let pinoInstance: pino.Logger | undefined
@@ -21,27 +16,22 @@ if (!env.DISABLE_PINO_LOGGER) {
21
16
  return { level: label.toUpperCase() }
22
17
  },
23
18
  bindings: () => {
24
- return {
25
- service: env.SERVICE_NAME,
26
- }
19
+ return {}
27
20
  },
28
21
  },
29
22
  timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
30
23
  }
31
24
 
32
- const destinations: pino.DestinationStream[] = []
33
-
34
25
  if (env.isDev()) {
35
- destinations.push(pinoPretty({ singleLine: true }))
36
- }
37
-
38
- if (env.SELF_HOSTED) {
39
- destinations.push(localFileDestination())
26
+ pinoOptions.transport = {
27
+ target: "pino-pretty",
28
+ options: {
29
+ singleLine: true,
30
+ },
31
+ }
40
32
  }
41
33
 
42
- pinoInstance = destinations.length
43
- ? pino(pinoOptions, pino.multistream(destinations))
44
- : pino(pinoOptions)
34
+ pinoInstance = pino(pinoOptions)
45
35
 
46
36
  // CONSOLE OVERRIDES
47
37
 
@@ -1,9 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="pouchdb-core" />
3
- import * as rfs from "rotating-file-stream";
4
- export declare function getSingleFileMaxSizeInfo(totalMaxSize: string): {
5
- size: string;
6
- totalHistoryFiles: number;
7
- } | undefined;
8
- export declare function localFileDestination(): rfs.RotatingFileStream;
9
- export declare function getLogReadStream(): Buffer;
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getLogReadStream = exports.localFileDestination = exports.getSingleFileMaxSizeInfo = void 0;
30
- const fs_1 = __importDefault(require("fs"));
31
- const path_1 = __importDefault(require("path"));
32
- const rfs = __importStar(require("rotating-file-stream"));
33
- const environment_1 = __importDefault(require("../environment"));
34
- const objectStore_1 = require("../objectStore");
35
- const logsFileName = `budibase.log`;
36
- const budibaseLogsHistoryFileName = "budibase-logs-history.txt";
37
- const logsPath = path_1.default.join((0, objectStore_1.budibaseTempDir)(), "systemlogs");
38
- function getFullPath(fileName) {
39
- return path_1.default.join(logsPath, fileName);
40
- }
41
- function getSingleFileMaxSizeInfo(totalMaxSize) {
42
- const regex = /(\d+)([A-Za-z])/;
43
- const match = totalMaxSize === null || totalMaxSize === void 0 ? void 0 : totalMaxSize.match(regex);
44
- if (!match) {
45
- console.warn(`totalMaxSize does not have a valid value`, {
46
- totalMaxSize,
47
- });
48
- return undefined;
49
- }
50
- const size = +match[1];
51
- const unit = match[2];
52
- if (size === 1) {
53
- switch (unit) {
54
- case "B":
55
- return { size: `${size}B`, totalHistoryFiles: 1 };
56
- case "K":
57
- return { size: `${(size * 1000) / 2}B`, totalHistoryFiles: 1 };
58
- case "M":
59
- return { size: `${(size * 1000) / 2}K`, totalHistoryFiles: 1 };
60
- case "G":
61
- return { size: `${(size * 1000) / 2}M`, totalHistoryFiles: 1 };
62
- default:
63
- return undefined;
64
- }
65
- }
66
- if (size % 2 === 0) {
67
- return { size: `${size / 2}${unit}`, totalHistoryFiles: 1 };
68
- }
69
- return { size: `1${unit}`, totalHistoryFiles: size - 1 };
70
- }
71
- exports.getSingleFileMaxSizeInfo = getSingleFileMaxSizeInfo;
72
- function localFileDestination() {
73
- const fileInfo = getSingleFileMaxSizeInfo(environment_1.default.ROLLING_LOG_MAX_SIZE);
74
- const outFile = rfs.createStream(logsFileName, {
75
- // As we have a rolling size, we want to half the max size
76
- size: fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.size,
77
- path: logsPath,
78
- maxFiles: (fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.totalHistoryFiles) || 1,
79
- immutable: true,
80
- history: budibaseLogsHistoryFileName,
81
- initialRotation: false,
82
- });
83
- return outFile;
84
- }
85
- exports.localFileDestination = localFileDestination;
86
- function getLogReadStream() {
87
- const streams = [];
88
- const historyFile = getFullPath(budibaseLogsHistoryFileName);
89
- if (fs_1.default.existsSync(historyFile)) {
90
- const fileContent = fs_1.default.readFileSync(historyFile, "utf-8");
91
- const historyFiles = fileContent.split("\n");
92
- for (const historyFile of historyFiles.filter(x => x)) {
93
- streams.push(fs_1.default.readFileSync(historyFile));
94
- }
95
- }
96
- streams.push(fs_1.default.readFileSync(getFullPath(logsFileName)));
97
- const combinedContent = Buffer.concat(streams);
98
- return combinedContent;
99
- }
100
- exports.getLogReadStream = getLogReadStream;
101
- //# sourceMappingURL=system.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"system.js","sourceRoot":"","sources":["../../../src/logging/system.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,0DAA2C;AAE3C,iEAAgC;AAChC,gDAAgD;AAEhD,MAAM,YAAY,GAAG,cAAc,CAAA;AACnC,MAAM,2BAA2B,GAAG,2BAA2B,CAAA;AAE/D,MAAM,QAAQ,GAAG,cAAI,CAAC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AAC,CAAC,CAAA;SAC3C;KACF;IAED,OAAO,CAAC,IAAI,CAAC,YAAE,CAAC,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAExD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC9C,OAAO,eAAe,CAAA;AACxB,CAAC;AAfD,4CAeC"}
@@ -1,81 +0,0 @@
1
- import fs from "fs"
2
- import path from "path"
3
- import * as rfs from "rotating-file-stream"
4
-
5
- import env from "../environment"
6
- import { budibaseTempDir } from "../objectStore"
7
-
8
- const logsFileName = `budibase.log`
9
- const budibaseLogsHistoryFileName = "budibase-logs-history.txt"
10
-
11
- const logsPath = path.join(budibaseTempDir(), "systemlogs")
12
-
13
- function getFullPath(fileName: string) {
14
- return path.join(logsPath, fileName)
15
- }
16
-
17
- export function getSingleFileMaxSizeInfo(totalMaxSize: string) {
18
- const regex = /(\d+)([A-Za-z])/
19
- const match = totalMaxSize?.match(regex)
20
- if (!match) {
21
- console.warn(`totalMaxSize does not have a valid value`, {
22
- totalMaxSize,
23
- })
24
- return undefined
25
- }
26
-
27
- const size = +match[1]
28
- const unit = match[2]
29
- if (size === 1) {
30
- switch (unit) {
31
- case "B":
32
- return { size: `${size}B`, totalHistoryFiles: 1 }
33
- case "K":
34
- return { size: `${(size * 1000) / 2}B`, totalHistoryFiles: 1 }
35
- case "M":
36
- return { size: `${(size * 1000) / 2}K`, totalHistoryFiles: 1 }
37
- case "G":
38
- return { size: `${(size * 1000) / 2}M`, totalHistoryFiles: 1 }
39
- default:
40
- return undefined
41
- }
42
- }
43
-
44
- if (size % 2 === 0) {
45
- return { size: `${size / 2}${unit}`, totalHistoryFiles: 1 }
46
- }
47
-
48
- return { size: `1${unit}`, totalHistoryFiles: size - 1 }
49
- }
50
-
51
- export function localFileDestination() {
52
- const fileInfo = getSingleFileMaxSizeInfo(env.ROLLING_LOG_MAX_SIZE)
53
- const outFile = rfs.createStream(logsFileName, {
54
- // As we have a rolling size, we want to half the max size
55
- size: fileInfo?.size,
56
- path: logsPath,
57
- maxFiles: fileInfo?.totalHistoryFiles || 1,
58
- immutable: true,
59
- history: budibaseLogsHistoryFileName,
60
- initialRotation: false,
61
- })
62
-
63
- return outFile
64
- }
65
-
66
- export function getLogReadStream() {
67
- const streams = []
68
- const historyFile = getFullPath(budibaseLogsHistoryFileName)
69
- if (fs.existsSync(historyFile)) {
70
- const fileContent = fs.readFileSync(historyFile, "utf-8")
71
- const historyFiles = fileContent.split("\n")
72
- for (const historyFile of historyFiles.filter(x => x)) {
73
- streams.push(fs.readFileSync(historyFile))
74
- }
75
- }
76
-
77
- streams.push(fs.readFileSync(getFullPath(logsFileName)))
78
-
79
- const combinedContent = Buffer.concat(streams)
80
- return combinedContent
81
- }
@@ -1,61 +0,0 @@
1
- import { getSingleFileMaxSizeInfo } from "../system"
2
-
3
- describe("system", () => {
4
- describe("getSingleFileMaxSizeInfo", () => {
5
- it.each([
6
- ["100B", "50B"],
7
- ["200K", "100K"],
8
- ["20M", "10M"],
9
- ["4G", "2G"],
10
- ])(
11
- "Halving even number (%s) returns halved size and 1 history file (%s)",
12
- (totalValue, expectedMaxSize) => {
13
- const result = getSingleFileMaxSizeInfo(totalValue)
14
- expect(result).toEqual({
15
- size: expectedMaxSize,
16
- totalHistoryFiles: 1,
17
- })
18
- }
19
- )
20
-
21
- it.each([
22
- ["5B", "1B", 4],
23
- ["17K", "1K", 16],
24
- ["21M", "1M", 20],
25
- ["3G", "1G", 2],
26
- ])(
27
- "Halving an odd number (%s) returns as many files as size (-1) (%s)",
28
- (totalValue, expectedMaxSize, totalHistoryFiles) => {
29
- const result = getSingleFileMaxSizeInfo(totalValue)
30
- expect(result).toEqual({
31
- size: expectedMaxSize,
32
- totalHistoryFiles,
33
- })
34
- }
35
- )
36
-
37
- it.each([
38
- ["1B", "1B"],
39
- ["1K", "500B"],
40
- ["1M", "500K"],
41
- ["1G", "500M"],
42
- ])(
43
- "Halving '%s' returns halved unit (%s)",
44
- (totalValue, expectedMaxSize) => {
45
- const result = getSingleFileMaxSizeInfo(totalValue)
46
- expect(result).toEqual({
47
- size: expectedMaxSize,
48
- totalHistoryFiles: 1,
49
- })
50
- }
51
- )
52
-
53
- it.each([[undefined], [""], ["50"], ["wrongvalue"]])(
54
- "Halving wrongly formatted value ('%s') returns undefined",
55
- totalValue => {
56
- const result = getSingleFileMaxSizeInfo(totalValue!)
57
- expect(result).toBeUndefined()
58
- }
59
- )
60
- })
61
- })