@nsshunt/stsfhirpg 1.0.12 → 1.0.14

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.
@@ -3,16 +3,16 @@ import { defaultLogger } from "@nsshunt/stsutils";
3
3
  import { isAbsoluteUrl } from "@nsshunt/stsfhirclient";
4
4
  import { goptions } from "@nsshunt/stsconfig";
5
5
  import cluster from "cluster";
6
- import require$$0$1 from "crypto";
7
- import require$$0$4 from "events";
8
- import require$$1 from "util";
9
- import require$$0$3 from "dns";
10
- import require$$0$2 from "fs";
11
- import require$$0$5 from "net";
12
- import require$$1$1 from "tls";
13
- import require$$0$8 from "path";
14
- import require$$0$7 from "stream";
15
- import require$$0$6 from "buffer";
6
+ import require$$0 from "crypto";
7
+ import require$$0$3 from "events";
8
+ import require$$1$1 from "util";
9
+ import require$$0$2 from "dns";
10
+ import require$$0$1 from "fs";
11
+ import require$$0$4 from "net";
12
+ import require$$1$2 from "tls";
13
+ import require$$0$7 from "path";
14
+ import require$$0$6 from "stream";
15
+ import require$$0$5 from "buffer";
16
16
  class LuxonError extends Error {
17
17
  }
18
18
  class InvalidDateTimeError extends LuxonError {
@@ -12551,7 +12551,7 @@ function requireUtils$1() {
12551
12551
  if (hasRequiredUtils$1) return utils$1;
12552
12552
  hasRequiredUtils$1 = 1;
12553
12553
  const defaults2 = requireDefaults();
12554
- const util2 = require$$1;
12554
+ const util2 = require$$1$1;
12555
12555
  const { isDate: isDate2 } = util2.types || util2;
12556
12556
  function escapeElement(elementRepresentation) {
12557
12557
  const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
@@ -12709,7 +12709,7 @@ var hasRequiredUtilsLegacy;
12709
12709
  function requireUtilsLegacy() {
12710
12710
  if (hasRequiredUtilsLegacy) return utilsLegacy;
12711
12711
  hasRequiredUtilsLegacy = 1;
12712
- const nodeCrypto = require$$0$1;
12712
+ const nodeCrypto = require$$0;
12713
12713
  function md5(string) {
12714
12714
  return nodeCrypto.createHash("md5").update(string, "utf-8").digest("hex");
12715
12715
  }
@@ -12747,7 +12747,7 @@ var hasRequiredUtilsWebcrypto;
12747
12747
  function requireUtilsWebcrypto() {
12748
12748
  if (hasRequiredUtilsWebcrypto) return utilsWebcrypto;
12749
12749
  hasRequiredUtilsWebcrypto = 1;
12750
- const nodeCrypto = require$$0$1;
12750
+ const nodeCrypto = require$$0;
12751
12751
  utilsWebcrypto = {
12752
12752
  postgresMd5PasswordHash,
12753
12753
  randomBytes,
@@ -13180,7 +13180,7 @@ function requirePgConnectionString() {
13180
13180
  if (config.sslcert || config.sslkey || config.sslrootcert || config.sslmode) {
13181
13181
  config.ssl = {};
13182
13182
  }
13183
- const fs2 = config.sslcert || config.sslkey || config.sslrootcert ? require$$0$2 : null;
13183
+ const fs2 = config.sslcert || config.sslkey || config.sslrootcert ? require$$0$1 : null;
13184
13184
  if (config.sslcert) {
13185
13185
  config.ssl.cert = fs2.readFileSync(config.sslcert).toString();
13186
13186
  }
@@ -13309,7 +13309,7 @@ var hasRequiredConnectionParameters;
13309
13309
  function requireConnectionParameters() {
13310
13310
  if (hasRequiredConnectionParameters) return connectionParameters;
13311
13311
  hasRequiredConnectionParameters = 1;
13312
- const dns = require$$0$3;
13312
+ const dns = require$$0$2;
13313
13313
  const defaults2 = requireDefaults();
13314
13314
  const parse2 = requirePgConnectionString().parse;
13315
13315
  const val = function(key, config, envVar) {
@@ -13541,7 +13541,7 @@ var hasRequiredQuery$1;
13541
13541
  function requireQuery$1() {
13542
13542
  if (hasRequiredQuery$1) return query$1;
13543
13543
  hasRequiredQuery$1 = 1;
13544
- const { EventEmitter } = require$$0$4;
13544
+ const { EventEmitter } = require$$0$3;
13545
13545
  const Result = requireResult();
13546
13546
  const utils2 = requireUtils$1();
13547
13547
  class Query extends EventEmitter {
@@ -14205,11 +14205,10 @@ function requireBufferReader() {
14205
14205
  hasRequiredBufferReader = 1;
14206
14206
  Object.defineProperty(bufferReader, "__esModule", { value: true });
14207
14207
  bufferReader.BufferReader = void 0;
14208
- const emptyBuffer = Buffer.allocUnsafe(0);
14209
14208
  class BufferReader {
14210
14209
  constructor(offset2 = 0) {
14211
14210
  this.offset = offset2;
14212
- this.buffer = emptyBuffer;
14211
+ this.buffer = Buffer.allocUnsafe(0);
14213
14212
  this.encoding = "utf-8";
14214
14213
  }
14215
14214
  setBuffer(offset2, buffer) {
@@ -14619,11 +14618,11 @@ function requireStream() {
14619
14618
  };
14620
14619
  function getNodejsStreamFuncs() {
14621
14620
  function getStream2(ssl) {
14622
- const net = require$$0$5;
14621
+ const net = require$$0$4;
14623
14622
  return new net.Socket();
14624
14623
  }
14625
14624
  function getSecureStream2(options) {
14626
- const tls = require$$1$1;
14625
+ const tls = require$$1$2;
14627
14626
  return tls.connect(options);
14628
14627
  }
14629
14628
  return {
@@ -14670,7 +14669,7 @@ var hasRequiredConnection;
14670
14669
  function requireConnection() {
14671
14670
  if (hasRequiredConnection) return connection;
14672
14671
  hasRequiredConnection = 1;
14673
- const EventEmitter = require$$0$4.EventEmitter;
14672
+ const EventEmitter = require$$0$3.EventEmitter;
14674
14673
  const { parse: parse2, serialize } = requireDist();
14675
14674
  const { getStream, getSecureStream } = requireStream();
14676
14675
  const flushBuffer = serialize.flush();
@@ -14742,7 +14741,7 @@ function requireConnection() {
14742
14741
  options.key = self2.ssl.key;
14743
14742
  }
14744
14743
  }
14745
- const net = require$$0$5;
14744
+ const net = require$$0$4;
14746
14745
  if (net.isIP && net.isIP(host) === 0) {
14747
14746
  options.servername = host;
14748
14747
  }
@@ -14857,7 +14856,7 @@ function requireSafeBuffer() {
14857
14856
  if (hasRequiredSafeBuffer) return safeBuffer.exports;
14858
14857
  hasRequiredSafeBuffer = 1;
14859
14858
  (function(module, exports$1) {
14860
- var buffer = require$$0$6;
14859
+ var buffer = require$$0$5;
14861
14860
  var Buffer2 = buffer.Buffer;
14862
14861
  function copyProps(src, dst) {
14863
14862
  for (var key in src) {
@@ -15154,7 +15153,7 @@ var hasRequiredSplit2;
15154
15153
  function requireSplit2() {
15155
15154
  if (hasRequiredSplit2) return split2;
15156
15155
  hasRequiredSplit2 = 1;
15157
- const { Transform } = require$$0$7;
15156
+ const { Transform } = require$$0$6;
15158
15157
  const { StringDecoder } = requireString_decoder();
15159
15158
  const kLast = /* @__PURE__ */ Symbol("last");
15160
15159
  const kDecoder = /* @__PURE__ */ Symbol("decoder");
@@ -15255,7 +15254,7 @@ function requireHelper() {
15255
15254
  if (hasRequiredHelper) return helper.exports;
15256
15255
  hasRequiredHelper = 1;
15257
15256
  (function(module) {
15258
- var path = require$$0$8, Stream = require$$0$7.Stream, split = requireSplit2(), util2 = require$$1, defaultPort = 5432, isWin = process.platform === "win32", warnStream = process.stderr;
15257
+ var path = require$$0$7, Stream = require$$0$6.Stream, split = requireSplit2(), util2 = require$$1$1, defaultPort = 5432, isWin = process.platform === "win32", warnStream = process.stderr;
15259
15258
  var S_IRWXG = 56, S_IRWXO = 7, S_IFMT = 61440, S_IFREG = 32768;
15260
15259
  function isRegFile(mode) {
15261
15260
  return (mode & S_IFMT) == S_IFREG;
@@ -15416,7 +15415,7 @@ var hasRequiredLib$1;
15416
15415
  function requireLib$1() {
15417
15416
  if (hasRequiredLib$1) return lib.exports;
15418
15417
  hasRequiredLib$1 = 1;
15419
- var fs2 = require$$0$2, helper2 = requireHelper();
15418
+ var fs2 = require$$0$1, helper2 = requireHelper();
15420
15419
  lib.exports = function(connInfo, cb) {
15421
15420
  var file = helper2.getFileName();
15422
15421
  fs2.stat(file, function(err, stat) {
@@ -15435,9 +15434,9 @@ var hasRequiredClient$1;
15435
15434
  function requireClient$1() {
15436
15435
  if (hasRequiredClient$1) return client$1;
15437
15436
  hasRequiredClient$1 = 1;
15438
- const EventEmitter = require$$0$4.EventEmitter;
15437
+ const EventEmitter = require$$0$3.EventEmitter;
15439
15438
  const utils2 = requireUtils$1();
15440
- const nodeUtils = require$$1;
15439
+ const nodeUtils = require$$1$1;
15441
15440
  const sasl2 = requireSasl();
15442
15441
  const TypeOverrides = requireTypeOverrides();
15443
15442
  const ConnectionParameters = requireConnectionParameters();
@@ -15448,22 +15447,27 @@ function requireClient$1() {
15448
15447
  const activeQueryDeprecationNotice = nodeUtils.deprecate(
15449
15448
  () => {
15450
15449
  },
15451
- "Client.activeQuery is deprecated and will be removed in a future version."
15450
+ "Client.activeQuery is deprecated and will be removed in pg@9.0"
15452
15451
  );
15453
15452
  const queryQueueDeprecationNotice = nodeUtils.deprecate(
15454
15453
  () => {
15455
15454
  },
15456
- "Client.queryQueue is deprecated and will be removed in a future version."
15455
+ "Client.queryQueue is deprecated and will be removed in pg@9.0."
15457
15456
  );
15458
15457
  const pgPassDeprecationNotice = nodeUtils.deprecate(
15459
15458
  () => {
15460
15459
  },
15461
- "pgpass support is deprecated and will be removed in a future version. You can provide an async function as the password property to the Client/Pool constructor that returns a password instead. Within this funciton you can call the pgpass module in your own code."
15460
+ "pgpass support is deprecated and will be removed in pg@9.0. You can provide an async function as the password property to the Client/Pool constructor that returns a password instead. Within this function you can call the pgpass module in your own code."
15462
15461
  );
15463
15462
  const byoPromiseDeprecationNotice = nodeUtils.deprecate(
15464
15463
  () => {
15465
15464
  },
15466
- "Passing a custom Promise implementation to the Client/Pool constructor is deprecated and will be removed in a future version."
15465
+ "Passing a custom Promise implementation to the Client/Pool constructor is deprecated and will be removed in pg@9.0."
15466
+ );
15467
+ const queryQueueLengthDeprecationNotice = nodeUtils.deprecate(
15468
+ () => {
15469
+ },
15470
+ "Calling client.query() when the client is already executing a query is deprecated and will be removed in pg@9.0. Use async/await or an external async flow control mechanism instead."
15467
15471
  );
15468
15472
  class Client extends EventEmitter {
15469
15473
  constructor(config) {
@@ -15635,7 +15639,7 @@ function requireClient$1() {
15635
15639
  _getPassword(cb) {
15636
15640
  const con = this.connection;
15637
15641
  if (typeof this.password === "function") {
15638
- this._Promise.resolve().then(() => this.password()).then((pass) => {
15642
+ this._Promise.resolve().then(() => this.password(this.connectionParameters)).then((pass) => {
15639
15643
  if (pass !== void 0) {
15640
15644
  if (typeof pass !== "string") {
15641
15645
  con.emit("error", new TypeError("Password must be a string"));
@@ -15941,8 +15945,12 @@ function requireClient$1() {
15941
15945
  } else if (typeof config.submit === "function") {
15942
15946
  readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
15943
15947
  result2 = query2 = config;
15944
- if (typeof values === "function") {
15945
- query2.callback = query2.callback || values;
15948
+ if (!query2.callback) {
15949
+ if (typeof values === "function") {
15950
+ query2.callback = values;
15951
+ } else if (callback) {
15952
+ query2.callback = callback;
15953
+ }
15946
15954
  }
15947
15955
  } else {
15948
15956
  readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
@@ -15957,7 +15965,8 @@ function requireClient$1() {
15957
15965
  }
15958
15966
  }
15959
15967
  if (readTimeout) {
15960
- queryCallback = query2.callback;
15968
+ queryCallback = query2.callback || (() => {
15969
+ });
15961
15970
  readTimeoutTimer = setTimeout(() => {
15962
15971
  const error = new Error("Query read timeout");
15963
15972
  process.nextTick(() => {
@@ -15995,6 +16004,9 @@ function requireClient$1() {
15995
16004
  });
15996
16005
  return result2;
15997
16006
  }
16007
+ if (this._queryQueue.length > 0) {
16008
+ queryQueueLengthDeprecationNotice();
16009
+ }
15998
16010
  this._queryQueue.push(query2);
15999
16011
  this._pulseQueryQueue();
16000
16012
  return result2;
@@ -16041,7 +16053,7 @@ var hasRequiredPgPool;
16041
16053
  function requirePgPool() {
16042
16054
  if (hasRequiredPgPool) return pgPool;
16043
16055
  hasRequiredPgPool = 1;
16044
- const EventEmitter = require$$0$4.EventEmitter;
16056
+ const EventEmitter = require$$0$3.EventEmitter;
16045
16057
  const NOOP = function() {
16046
16058
  };
16047
16059
  const removeWhere = (list, predicate) => {
@@ -16129,6 +16141,13 @@ function requirePgPool() {
16129
16141
  this.ending = false;
16130
16142
  this.ended = false;
16131
16143
  }
16144
+ _promiseTry(f) {
16145
+ const Promise2 = this.Promise;
16146
+ if (typeof Promise2.try === "function") {
16147
+ return Promise2.try(f);
16148
+ }
16149
+ return new Promise2((resolve) => resolve(f()));
16150
+ }
16132
16151
  _isFull() {
16133
16152
  return this._clients.length >= this.options.max;
16134
16153
  }
@@ -16232,9 +16251,15 @@ function requirePgPool() {
16232
16251
  let timeoutHit = false;
16233
16252
  if (this.options.connectionTimeoutMillis) {
16234
16253
  tid = setTimeout(() => {
16235
- this.log("ending client due to timeout");
16236
- timeoutHit = true;
16237
- client2.connection ? client2.connection.stream.destroy() : client2.end();
16254
+ if (client2.connection) {
16255
+ this.log("ending client due to timeout");
16256
+ timeoutHit = true;
16257
+ client2.connection.stream.destroy();
16258
+ } else if (!client2.isConnected()) {
16259
+ this.log("ending client due to timeout");
16260
+ timeoutHit = true;
16261
+ client2.end();
16262
+ }
16238
16263
  }, this.options.connectionTimeoutMillis);
16239
16264
  }
16240
16265
  this.log("connecting new client");
@@ -16255,27 +16280,47 @@ function requirePgPool() {
16255
16280
  }
16256
16281
  } else {
16257
16282
  this.log("new client connected");
16258
- if (this.options.maxLifetimeSeconds !== 0) {
16259
- const maxLifetimeTimeout = setTimeout(() => {
16260
- this.log("ending client due to expired lifetime");
16261
- this._expired.add(client2);
16262
- const idleIndex = this._idle.findIndex((idleItem) => idleItem.client === client2);
16263
- if (idleIndex !== -1) {
16264
- this._acquireClient(
16265
- client2,
16266
- new PendingItem((err2, client3, clientRelease) => clientRelease()),
16267
- idleListener,
16268
- false
16269
- );
16283
+ if (this.options.onConnect) {
16284
+ this._promiseTry(() => this.options.onConnect(client2)).then(
16285
+ () => {
16286
+ this._afterConnect(client2, pendingItem, idleListener);
16287
+ },
16288
+ (hookErr) => {
16289
+ this._clients = this._clients.filter((c) => c !== client2);
16290
+ client2.end(() => {
16291
+ this._pulseQueue();
16292
+ if (!pendingItem.timedOut) {
16293
+ pendingItem.callback(hookErr, void 0, NOOP);
16294
+ }
16295
+ });
16270
16296
  }
16271
- }, this.options.maxLifetimeSeconds * 1e3);
16272
- maxLifetimeTimeout.unref();
16273
- client2.once("end", () => clearTimeout(maxLifetimeTimeout));
16297
+ );
16298
+ return;
16274
16299
  }
16275
- return this._acquireClient(client2, pendingItem, idleListener, true);
16300
+ return this._afterConnect(client2, pendingItem, idleListener);
16276
16301
  }
16277
16302
  });
16278
16303
  }
16304
+ _afterConnect(client2, pendingItem, idleListener) {
16305
+ if (this.options.maxLifetimeSeconds !== 0) {
16306
+ const maxLifetimeTimeout = setTimeout(() => {
16307
+ this.log("ending client due to expired lifetime");
16308
+ this._expired.add(client2);
16309
+ const idleIndex = this._idle.findIndex((idleItem) => idleItem.client === client2);
16310
+ if (idleIndex !== -1) {
16311
+ this._acquireClient(
16312
+ client2,
16313
+ new PendingItem((err, client3, clientRelease) => clientRelease()),
16314
+ idleListener,
16315
+ false
16316
+ );
16317
+ }
16318
+ }, this.options.maxLifetimeSeconds * 1e3);
16319
+ maxLifetimeTimeout.unref();
16320
+ client2.once("end", () => clearTimeout(maxLifetimeTimeout));
16321
+ }
16322
+ return this._acquireClient(client2, pendingItem, idleListener, true);
16323
+ }
16279
16324
  // acquire a client for a pending work item
16280
16325
  _acquireClient(client2, pendingItem, idleListener, isNew) {
16281
16326
  if (isNew) {
@@ -16435,14 +16480,14 @@ const __viteOptionalPeerDep_pgNative_pg_true$1 = /* @__PURE__ */ Object.freeze(/
16435
16480
  __proto__: null,
16436
16481
  default: __viteOptionalPeerDep_pgNative_pg_true
16437
16482
  }, Symbol.toStringTag, { value: "Module" }));
16438
- const require$$0 = /* @__PURE__ */ getAugmentedNamespace(__viteOptionalPeerDep_pgNative_pg_true$1);
16483
+ const require$$1 = /* @__PURE__ */ getAugmentedNamespace(__viteOptionalPeerDep_pgNative_pg_true$1);
16439
16484
  var query = { exports: {} };
16440
16485
  var hasRequiredQuery;
16441
16486
  function requireQuery() {
16442
16487
  if (hasRequiredQuery) return query.exports;
16443
16488
  hasRequiredQuery = 1;
16444
- const EventEmitter = require$$0$4.EventEmitter;
16445
- const util2 = require$$1;
16489
+ const EventEmitter = require$$0$3.EventEmitter;
16490
+ const util2 = require$$1$1;
16446
16491
  const utils2 = requireUtils$1();
16447
16492
  const NativeQuery = query.exports = function(config, values, callback) {
16448
16493
  EventEmitter.call(this);
@@ -16581,17 +16626,23 @@ var hasRequiredClient;
16581
16626
  function requireClient() {
16582
16627
  if (hasRequiredClient) return client.exports;
16583
16628
  hasRequiredClient = 1;
16629
+ const nodeUtils = require$$1$1;
16584
16630
  var Native;
16585
16631
  try {
16586
- Native = require$$0;
16632
+ Native = require$$1;
16587
16633
  } catch (e) {
16588
16634
  throw e;
16589
16635
  }
16590
16636
  const TypeOverrides = requireTypeOverrides();
16591
- const EventEmitter = require$$0$4.EventEmitter;
16592
- const util2 = require$$1;
16637
+ const EventEmitter = require$$0$3.EventEmitter;
16638
+ const util2 = require$$1$1;
16593
16639
  const ConnectionParameters = requireConnectionParameters();
16594
16640
  const NativeQuery = requireQuery();
16641
+ const queryQueueLengthDeprecationNotice = nodeUtils.deprecate(
16642
+ () => {
16643
+ },
16644
+ "Calling client.query() when the client is already executing a query is deprecated and will be removed in pg@9.0. Use async/await or an external async flow control mechanism instead."
16645
+ );
16595
16646
  const Client = client.exports = function(config) {
16596
16647
  EventEmitter.call(this);
16597
16648
  config = config || {};
@@ -16713,7 +16764,8 @@ function requireClient() {
16713
16764
  }
16714
16765
  }
16715
16766
  if (readTimeout) {
16716
- queryCallback = query2.callback;
16767
+ queryCallback = query2.callback || (() => {
16768
+ });
16717
16769
  readTimeoutTimer = setTimeout(() => {
16718
16770
  const error = new Error("Query read timeout");
16719
16771
  process.nextTick(() => {
@@ -16747,6 +16799,9 @@ function requireClient() {
16747
16799
  });
16748
16800
  return result2;
16749
16801
  }
16802
+ if (this._queryQueue.length > 0) {
16803
+ queryQueueLengthDeprecationNotice();
16804
+ }
16750
16805
  this._queryQueue.push(query2);
16751
16806
  this._pulseQueryQueue();
16752
16807
  return result2;
@@ -16764,6 +16819,7 @@ function requireClient() {
16764
16819
  });
16765
16820
  }
16766
16821
  this.native.end(function() {
16822
+ self2._connected = false;
16767
16823
  self2._errorAllQueries(new Error("Connection terminated"));
16768
16824
  process.nextTick(() => {
16769
16825
  self2.emit("end");
@@ -16814,6 +16870,9 @@ function requireClient() {
16814
16870
  Client.prototype.getTypeParser = function(oid, format) {
16815
16871
  return this._types.getTypeParser(oid, format);
16816
16872
  };
16873
+ Client.prototype.isConnected = function() {
16874
+ return this._connected;
16875
+ };
16817
16876
  return client.exports;
16818
16877
  }
16819
16878
  var native;
@@ -17073,7 +17132,7 @@ class PGPoolManager extends tinyEmitterExports.TinyEmitter {
17073
17132
  return this.#pools[this.#GetPoolKey(0)].pool.connect();
17074
17133
  }
17075
17134
  async connectReadOnly() {
17076
- const poolIndex = require$$0$1.randomInt(0, Object.keys(this.#pools).length);
17135
+ const poolIndex = require$$0.randomInt(0, Object.keys(this.#pools).length);
17077
17136
  return this.#pools[this.#GetPoolKey(poolIndex)].pool.connect();
17078
17137
  }
17079
17138
  //@@ make event using TinyEmitter