@budibase/backend-core 2.22.15 → 2.22.16

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/backend-core",
3
- "version": "2.22.15",
3
+ "version": "2.22.16",
4
4
  "description": "Budibase backend core libraries used in server and worker",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "dependencies": {
24
24
  "@budibase/nano": "10.1.5",
25
25
  "@budibase/pouchdb-replication-stream": "1.2.10",
26
- "@budibase/shared-core": "2.22.15",
27
- "@budibase/types": "2.22.15",
26
+ "@budibase/shared-core": "2.22.16",
27
+ "@budibase/types": "2.22.16",
28
28
  "@govtechsg/passport-openidconnect": "^1.0.2",
29
29
  "aws-cloudfront-sign": "3.0.2",
30
30
  "aws-sdk": "2.1030.0",
@@ -96,5 +96,5 @@
96
96
  }
97
97
  }
98
98
  },
99
- "gitHead": "5ec5e990b3e96a2720470158c4cc8cf10926b637"
99
+ "gitHead": "4a14e2ae9fdbc95da043dae51af41e53a7cd8bb8"
100
100
  }
@@ -1 +1,26 @@
1
+ interface ContainerInfo {
2
+ Command: string;
3
+ CreatedAt: string;
4
+ ID: string;
5
+ Image: string;
6
+ Labels: string;
7
+ LocalVolumes: string;
8
+ Mounts: string;
9
+ Names: string;
10
+ Networks: string;
11
+ Ports: string;
12
+ RunningFor: string;
13
+ Size: string;
14
+ State: string;
15
+ Status: string;
16
+ }
17
+ export declare function getContainerByImage(image: string): ContainerInfo;
18
+ export declare function getContainerById(id: string): ContainerInfo | undefined;
19
+ export interface Port {
20
+ host: number;
21
+ container: number;
22
+ }
23
+ export declare function getExposedV4Ports(container: ContainerInfo): Port[];
24
+ export declare function getExposedV4Port(container: ContainerInfo, port: number): number | undefined;
1
25
  export declare function setupEnv(...envs: any[]): void;
26
+ export {};
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupEnv = void 0;
4
- const db_1 = require("../../../src/db");
3
+ exports.setupEnv = exports.getExposedV4Port = exports.getExposedV4Ports = exports.getContainerById = exports.getContainerByImage = void 0;
5
4
  const child_process_1 = require("child_process");
5
+ const IPV4_PORT_REGEX = new RegExp(`0\\.0\\.0\\.0:(\\d+)->(\\d+)/tcp`, "g");
6
6
  function getTestcontainers() {
7
- return (0, child_process_1.execSync)("docker ps --format json")
7
+ // We use --format json to make sure the output is nice and machine-readable,
8
+ // and we use --no-trunc so that the command returns full container IDs so we
9
+ // can filter on them correctly.
10
+ return (0, child_process_1.execSync)("docker ps --format json --no-trunc")
8
11
  .toString()
9
12
  .split("\n")
10
13
  .filter(x => x.length > 0)
@@ -12,35 +15,54 @@ function getTestcontainers() {
12
15
  .filter(x => x.Labels.includes("org.testcontainers=true"));
13
16
  }
14
17
  function getContainerByImage(image) {
15
- return getTestcontainers().find(x => x.Image.startsWith(image));
18
+ const containers = getTestcontainers().filter(x => x.Image.startsWith(image));
19
+ if (containers.length > 1) {
20
+ let errorMessage = `Multiple containers found starting with image: "${image}"\n\n`;
21
+ for (const container of containers) {
22
+ errorMessage += JSON.stringify(container, null, 2);
23
+ }
24
+ throw new Error(errorMessage);
25
+ }
26
+ return containers[0];
16
27
  }
17
- function getExposedPort(container, port) {
18
- const match = container.Ports.match(new RegExp(`0.0.0.0:(\\d+)->${port}/tcp`));
19
- if (!match) {
20
- return undefined;
28
+ exports.getContainerByImage = getContainerByImage;
29
+ function getContainerById(id) {
30
+ return getTestcontainers().find(x => x.ID === id);
31
+ }
32
+ exports.getContainerById = getContainerById;
33
+ function getExposedV4Ports(container) {
34
+ let ports = [];
35
+ for (const match of container.Ports.matchAll(IPV4_PORT_REGEX)) {
36
+ ports.push({ host: parseInt(match[1]), container: parseInt(match[2]) });
21
37
  }
22
- return parseInt(match[1]);
38
+ return ports;
39
+ }
40
+ exports.getExposedV4Ports = getExposedV4Ports;
41
+ function getExposedV4Port(container, port) {
42
+ var _a;
43
+ return (_a = getExposedV4Ports(container).find(x => x.container === port)) === null || _a === void 0 ? void 0 : _a.host;
23
44
  }
45
+ exports.getExposedV4Port = getExposedV4Port;
24
46
  function setupEnv(...envs) {
47
+ // We start couchdb in globalSetup.ts, in the root of the monorepo, so it
48
+ // should be relatively safe to look for it by its image name.
25
49
  const couch = getContainerByImage("budibase/couchdb");
26
50
  if (!couch) {
27
51
  throw new Error("CouchDB container not found");
28
52
  }
29
- const couchPort = getExposedPort(couch, 5984);
53
+ const couchPort = getExposedV4Port(couch, 5984);
30
54
  if (!couchPort) {
31
55
  throw new Error("CouchDB port not found");
32
56
  }
33
57
  const configs = [
34
58
  { key: "COUCH_DB_PORT", value: `${couchPort}` },
35
- { key: "COUCH_DB_URL", value: `http://localhost:${couchPort}` },
59
+ { key: "COUCH_DB_URL", value: `http://127.0.0.1:${couchPort}` },
36
60
  ];
37
61
  for (const config of configs.filter(x => !!x.value)) {
38
62
  for (const env of envs) {
39
63
  env._set(config.key, config.value);
40
64
  }
41
65
  }
42
- // @ts-expect-error
43
- db_1.DatabaseImpl.nano = undefined;
44
66
  }
45
67
  exports.setupEnv = setupEnv;
46
68
  //# sourceMappingURL=testContainerUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testContainerUtils.js","sourceRoot":"","sources":["../../../../tests/core/utilities/testContainerUtils.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAC9C,iDAAwC;AAmBxC,SAAS,iBAAiB;IACxB,OAAO,IAAA,wBAAQ,EAAC,yBAAyB,CAAC;SACvC,QAAQ,EAAE;SACV,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAkB,CAAC;SACxC,MAAM,CAAC,CAAC,C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;KAC1C;IAED,MAAM,OAAO,GAAG;QACd,EAAE,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE;QAC/C,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,oBAAoB,SAAS,EAAE,EAAE;KAChE,CAAA;IAED,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;QACnD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;SACnC;KACF;AACH,CAAC;AAvBD,4BAuBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/backend-core",
3
- "version": "2.22.15",
3
+ "version": "2.22.16",
4
4
  "description": "Budibase backend core libraries used in server and worker",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "dependencies": {
24
24
  "@budibase/nano": "10.1.5",
25
25
  "@budibase/pouchdb-replication-stream": "1.2.10",
26
- "@budibase/shared-core": "2.22.15",
27
- "@budibase/types": "2.22.15",
26
+ "@budibase/shared-core": "2.22.16",
27
+ "@budibase/types": "2.22.16",
28
28
  "@govtechsg/passport-openidconnect": "^1.0.2",
29
29
  "aws-cloudfront-sign": "3.0.2",
30
30
  "aws-sdk": "2.1030.0",
@@ -96,5 +96,5 @@
96
96
  }
97
97
  }
98
98
  },
99
- "gitHead": "5ec5e990b3e96a2720470158c4cc8cf10926b637"
99
+ "gitHead": "4a14e2ae9fdbc95da043dae51af41e53a7cd8bb8"
100
100
  }
@@ -1,6 +1,7 @@
1
- import { DatabaseImpl } from "../../../src/db"
2
1
  import { execSync } from "child_process"
3
2
 
3
+ const IPV4_PORT_REGEX = new RegExp(`0\\.0\\.0\\.0:(\\d+)->(\\d+)/tcp`, "g")
4
+
4
5
  interface ContainerInfo {
5
6
  Command: string
6
7
  CreatedAt: string
@@ -19,7 +20,10 @@ interface ContainerInfo {
19
20
  }
20
21
 
21
22
  function getTestcontainers(): ContainerInfo[] {
22
- return execSync("docker ps --format json")
23
+ // We use --format json to make sure the output is nice and machine-readable,
24
+ // and we use --no-trunc so that the command returns full container IDs so we
25
+ // can filter on them correctly.
26
+ return execSync("docker ps --format json --no-trunc")
23
27
  .toString()
24
28
  .split("\n")
25
29
  .filter(x => x.length > 0)
@@ -27,32 +31,55 @@ function getTestcontainers(): ContainerInfo[] {
27
31
  .filter(x => x.Labels.includes("org.testcontainers=true"))
28
32
  }
29
33
 
30
- function getContainerByImage(image: string) {
31
- return getTestcontainers().find(x => x.Image.startsWith(image))
34
+ export function getContainerByImage(image: string) {
35
+ const containers = getTestcontainers().filter(x => x.Image.startsWith(image))
36
+ if (containers.length > 1) {
37
+ let errorMessage = `Multiple containers found starting with image: "${image}"\n\n`
38
+ for (const container of containers) {
39
+ errorMessage += JSON.stringify(container, null, 2)
40
+ }
41
+ throw new Error(errorMessage)
42
+ }
43
+ return containers[0]
44
+ }
45
+
46
+ export function getContainerById(id: string) {
47
+ return getTestcontainers().find(x => x.ID === id)
32
48
  }
33
49
 
34
- function getExposedPort(container: ContainerInfo, port: number) {
35
- const match = container.Ports.match(new RegExp(`0.0.0.0:(\\d+)->${port}/tcp`))
36
- if (!match) {
37
- return undefined
50
+ export interface Port {
51
+ host: number
52
+ container: number
53
+ }
54
+
55
+ export function getExposedV4Ports(container: ContainerInfo): Port[] {
56
+ let ports: Port[] = []
57
+ for (const match of container.Ports.matchAll(IPV4_PORT_REGEX)) {
58
+ ports.push({ host: parseInt(match[1]), container: parseInt(match[2]) })
38
59
  }
39
- return parseInt(match[1])
60
+ return ports
61
+ }
62
+
63
+ export function getExposedV4Port(container: ContainerInfo, port: number) {
64
+ return getExposedV4Ports(container).find(x => x.container === port)?.host
40
65
  }
41
66
 
42
67
  export function setupEnv(...envs: any[]) {
68
+ // We start couchdb in globalSetup.ts, in the root of the monorepo, so it
69
+ // should be relatively safe to look for it by its image name.
43
70
  const couch = getContainerByImage("budibase/couchdb")
44
71
  if (!couch) {
45
72
  throw new Error("CouchDB container not found")
46
73
  }
47
74
 
48
- const couchPort = getExposedPort(couch, 5984)
75
+ const couchPort = getExposedV4Port(couch, 5984)
49
76
  if (!couchPort) {
50
77
  throw new Error("CouchDB port not found")
51
78
  }
52
79
 
53
80
  const configs = [
54
81
  { key: "COUCH_DB_PORT", value: `${couchPort}` },
55
- { key: "COUCH_DB_URL", value: `http://localhost:${couchPort}` },
82
+ { key: "COUCH_DB_URL", value: `http://127.0.0.1:${couchPort}` },
56
83
  ]
57
84
 
58
85
  for (const config of configs.filter(x => !!x.value)) {
@@ -60,7 +87,4 @@ export function setupEnv(...envs: any[]) {
60
87
  env._set(config.key, config.value)
61
88
  }
62
89
  }
63
-
64
- // @ts-expect-error
65
- DatabaseImpl.nano = undefined
66
90
  }