@axinom/mosaic-db-common 0.27.0 → 0.28.0-rc.1

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.
@@ -1,6 +1,13 @@
1
- import { Pool } from 'pg';
2
- import { IsolationLevel, IsolationSatisfying, TxnClient } from 'zapatos/db';
1
+ import { ClientBase, Pool } from 'pg';
2
+ import { IsolationLevel, TxnClient } from 'zapatos/db';
3
3
  export type DbClient = Pool | TxnClient<IsolationLevel>;
4
+ /**
5
+ * Iterates through pgSettings properties, composes and runs a single SELECT
6
+ * query to execute set_config for each property.
7
+ */
8
+ export declare const setPgSettingsConfig: (pgSettings: {
9
+ [key: string]: string;
10
+ } | undefined, txn: ClientBase) => Promise<void>;
4
11
  /**
5
12
  * Creates a transaction and sets pg settings before executing queries.
6
13
  * The applied pgSettings are added to the field "_debugPgSettings" in the transaction object for debug purposes.
@@ -12,12 +19,4 @@ export type DbClient = Pool | TxnClient<IsolationLevel>;
12
19
  export declare const transactionWithContext: <T>(pool: DbClient, isolationLevel: IsolationLevel, pgSettings: {
13
20
  [key: string]: string;
14
21
  } | undefined, callback: (client: TxnClient<IsolationLevel>) => Promise<T>) => Promise<T>;
15
- /**
16
- * Set a key-value pair as PostgreSQL config variables via `set_config(key, value, TRUE)`.
17
- * The applied values are added to the field "_debugPgSettings" in the transaction object for debug purposes.
18
- * @param key The configuration key to set. There are a few well known keys like MOSAIC_AUTH_SUBJECT_NAME and MOSAIC_AUTH_PERMISSIONS.
19
- * @param value The value to set for the key
20
- * @param txn The transaction client for which to set those config values
21
- */
22
- export declare const setConfigInTransaction: (key: string, value: string, txn: TxnClient<IsolationSatisfying<IsolationLevel>>) => Promise<void>;
23
22
  //# sourceMappingURL=transaction-with-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-with-context.d.ts","sourceRoot":"","sources":["../../src/zapatos/transaction-with-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EACL,cAAc,EACd,mBAAmB,EAMnB,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;AA0BxD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,YAC3B,QAAQ,kBACE,cAAc;;kCAEX,UAAU,cAAc,CAAC,8BAM7C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,QAC5B,MAAM,SACJ,MAAM,OACR,UAAU,oBAAoB,cAAc,CAAC,CAAC,KAClD,QAAQ,IAAI,CAYd,CAAC"}
1
+ {"version":3,"file":"transaction-with-context.d.ts","sourceRoot":"","sources":["../../src/zapatos/transaction-with-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,EACL,cAAc,EAGd,SAAS,EAGV,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;oBAEzB,UAAU,KACd,QAAQ,IAAI,CAiBd,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,YAC3B,QAAQ,kBACE,cAAc;;kCAEX,UAAU,cAAc,CAAC,8BAM7C,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setConfigInTransaction = exports.transactionWithContext = void 0;
3
+ exports.transactionWithContext = exports.setPgSettingsConfig = void 0;
4
4
  const db_1 = require("zapatos/db");
5
5
  /**
6
6
  * Iterates through pgSettings properties, composes and runs a single SELECT
@@ -18,8 +18,11 @@ const setPgSettingsConfig = async (pgSettings = {}, txn) => {
18
18
  }
19
19
  if (params.length > 0) {
20
20
  await new db_1.SQLFragment(`${literal.slice(0, -2)};`.split('$'), params).run(txn);
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- for debug purposes add the applied PG settings to the transaction object
22
+ txn._debugPgSettings = pgSettings;
21
23
  }
22
24
  };
25
+ exports.setPgSettingsConfig = setPgSettingsConfig;
23
26
  /**
24
27
  * Creates a transaction and sets pg settings before executing queries.
25
28
  * The applied pgSettings are added to the field "_debugPgSettings" in the transaction object for debug purposes.
@@ -30,29 +33,9 @@ const setPgSettingsConfig = async (pgSettings = {}, txn) => {
30
33
  */
31
34
  const transactionWithContext = async (pool, isolationLevel, pgSettings = {}, callback) => {
32
35
  return (0, db_1.transaction)(pool, isolationLevel, async (txn) => {
33
- await setPgSettingsConfig(pgSettings, txn);
36
+ await (0, exports.setPgSettingsConfig)(pgSettings, txn);
34
37
  return callback(txn);
35
38
  });
36
39
  };
37
40
  exports.transactionWithContext = transactionWithContext;
38
- /**
39
- * Set a key-value pair as PostgreSQL config variables via `set_config(key, value, TRUE)`.
40
- * The applied values are added to the field "_debugPgSettings" in the transaction object for debug purposes.
41
- * @param key The configuration key to set. There are a few well known keys like MOSAIC_AUTH_SUBJECT_NAME and MOSAIC_AUTH_PERMISSIONS.
42
- * @param value The value to set for the key
43
- * @param txn The transaction client for which to set those config values
44
- */
45
- const setConfigInTransaction = async (key, value, txn) => {
46
- const keyParm = (0, db_1.param)(key);
47
- const valueParam = (0, db_1.param)(value);
48
- await (0, db_1.sql) `SELECT set_config(${keyParm}, ${valueParam}, TRUE)`.run(txn);
49
- // for debug purposes add the applied PG settings to the transaction object
50
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
- const transaction = txn;
52
- if (!('_debugPgSettings' in transaction)) {
53
- transaction._debugPgSettings = {};
54
- }
55
- transaction._debugPgSettings[key] = value;
56
- };
57
- exports.setConfigInTransaction = setConfigInTransaction;
58
41
  //# sourceMappingURL=transaction-with-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-with-context.js","sourceRoot":"","sources":["../../src/zapatos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AAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CACtE,GAAG,CACJ,CAAC;QACF,0IAA0I;QACzI,GAAW,CAAC,gBAAgB,GAAG,UAAU,CAAC;KAC5C;AACH,CAAC,CAAC;AApBW,QAAA,mBAAmB,uBAoB9B;AAEF;;;;;;;GAOG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACzC,IAAc,EACd,cAA8B,EAC9B,aAAwC,EAAE,EAC1C,QAA2D,EAC/C,EAAE;IACd,OAAO,IAAA,gBAAW,EAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACrD,MAAM,IAAA,2BAAmB,EAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAC3C,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAVW,QAAA,sBAAsB,0BAUjC"}
@@ -117,7 +117,7 @@ $$;
117
117
  }
118
118
  snippet-*/
119
119
  CREATE OR REPLACE FUNCTION ax_utils.current_tenant_id() RETURNS UUID AS $$
120
- SELECT coalesce(nullif(current_setting('mosaic.tenant_id', TRUE), ''), uuid_nil()::TEXT)::UUID;
120
+ SELECT coalesce(nullif(current_setting('mosaic.tenant_id', TRUE), ''), 'ffffffff-ffff-ffff-ffff-ffffffffffff')::UUID;
121
121
  $$ LANGUAGE sql STABLE;
122
122
 
123
123
  /*-snippet
@@ -132,7 +132,7 @@ $$ LANGUAGE sql STABLE;
132
132
  }
133
133
  snippet-*/
134
134
  CREATE OR REPLACE FUNCTION ax_utils.current_environment_id() RETURNS UUID AS $$
135
- SELECT coalesce(nullif(current_setting('mosaic.environment_id', TRUE), ''), uuid_nil()::TEXT)::UUID;
135
+ SELECT coalesce(nullif(current_setting('mosaic.environment_id', TRUE), ''), 'ffffffff-ffff-ffff-ffff-ffffffffffff')::UUID;
136
136
  $$ LANGUAGE sql STABLE;
137
137
 
138
138
  /*-snippet
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axinom/mosaic-db-common",
3
- "version": "0.27.0",
3
+ "version": "0.28.0-rc.1",
4
4
  "description": "This library encapsulates database-related functionality to develop Mosaic based services.",
5
5
  "author": "Axinom",
6
6
  "license": "PROPRIETARY",
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "express": "^4.17.1",
34
34
  "graphile-migrate": "^1.4.0",
35
- "pg": "^8.5.1",
35
+ "pg": "^8.11.3",
36
36
  "pg-logical-replication": "^2.0.3",
37
37
  "prom-client": "^13.2.0",
38
38
  "readdirp": "^3.4.0",
@@ -52,5 +52,5 @@
52
52
  "publishConfig": {
53
53
  "access": "public"
54
54
  },
55
- "gitHead": "7eb762e7cec90f882c2fe11f5c294c44fc2c3bc3"
55
+ "gitHead": "19386d17cc908f49f470c3a2095c084a93ceab55"
56
56
  }
@@ -1,13 +1,11 @@
1
- import { Pool } from 'pg';
1
+ import { ClientBase, Pool } from 'pg';
2
2
  import {
3
3
  IsolationLevel,
4
- IsolationSatisfying,
5
- param,
6
4
  Parameter,
7
- sql,
8
5
  SQLFragment,
9
- transaction,
10
6
  TxnClient,
7
+ param,
8
+ transaction,
11
9
  } from 'zapatos/db';
12
10
 
13
11
  export type DbClient = Pool | TxnClient<IsolationLevel>;
@@ -16,9 +14,9 @@ export type DbClient = Pool | TxnClient<IsolationLevel>;
16
14
  * Iterates through pgSettings properties, composes and runs a single SELECT
17
15
  * query to execute set_config for each property.
18
16
  */
19
- const setPgSettingsConfig = async (
17
+ export const setPgSettingsConfig = async (
20
18
  pgSettings: { [key: string]: string } = {},
21
- txn: TxnClient<IsolationSatisfying<IsolationLevel>>,
19
+ txn: ClientBase,
22
20
  ): Promise<void> => {
23
21
  let literal = 'SELECT ';
24
22
  const params: Parameter<string>[] = [];
@@ -33,6 +31,8 @@ const setPgSettingsConfig = async (
33
31
  await new SQLFragment(`${literal.slice(0, -2)};`.split('$'), params).run(
34
32
  txn,
35
33
  );
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- for debug purposes add the applied PG settings to the transaction object
35
+ (txn as any)._debugPgSettings = pgSettings;
36
36
  }
37
37
  };
38
38
 
@@ -55,28 +55,3 @@ export const transactionWithContext = async <T>(
55
55
  return callback(txn);
56
56
  });
57
57
  };
58
-
59
- /**
60
- * Set a key-value pair as PostgreSQL config variables via `set_config(key, value, TRUE)`.
61
- * The applied values are added to the field "_debugPgSettings" in the transaction object for debug purposes.
62
- * @param key The configuration key to set. There are a few well known keys like MOSAIC_AUTH_SUBJECT_NAME and MOSAIC_AUTH_PERMISSIONS.
63
- * @param value The value to set for the key
64
- * @param txn The transaction client for which to set those config values
65
- */
66
- export const setConfigInTransaction = async (
67
- key: string,
68
- value: string,
69
- txn: TxnClient<IsolationSatisfying<IsolationLevel>>,
70
- ): Promise<void> => {
71
- const keyParm = param(key);
72
- const valueParam = param(value);
73
- await sql`SELECT set_config(${keyParm}, ${valueParam}, TRUE)`.run(txn);
74
-
75
- // for debug purposes add the applied PG settings to the transaction object
76
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
- const transaction = txn as any;
78
- if (!('_debugPgSettings' in transaction)) {
79
- transaction._debugPgSettings = {};
80
- }
81
- transaction._debugPgSettings[key] = value;
82
- };