construct-hub 0.3.303 → 0.3.304

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/.jsii CHANGED
@@ -14589,6 +14589,6 @@
14589
14589
  "symbolId": "src/package-sources/npmjs:NpmJsProps"
14590
14590
  }
14591
14591
  },
14592
- "version": "0.3.303",
14593
- "fingerprint": "QCnW96CDlKR9FHim3O4xJeXyOEOTTUo+HWMSZnMakyQ="
14592
+ "version": "0.3.304",
14593
+ "fingerprint": "kdrpQY8nBwseYt0Njp4sUB29JU6YZZ/bMOExLS1IgXs="
14594
14594
  }
package/changelog.md CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- ### [0.3.303](https://github.com/cdklabs/construct-hub/compare/v0.3.302...v0.3.303) (2022-04-02)
2
+ ### [0.3.304](https://github.com/cdklabs/construct-hub/compare/v0.3.303...v0.3.304) (2022-04-04)
@@ -3468,15 +3468,69 @@ var require_json_buffer = __commonJS({
3468
3468
  }
3469
3469
  });
3470
3470
 
3471
- // node_modules/keyv/src/index.js
3471
+ // node_modules/compress-brotli/src/merge-options.js
3472
+ var require_merge_options = __commonJS({
3473
+ "node_modules/compress-brotli/src/merge-options.js"(exports, module2) {
3474
+ "use strict";
3475
+ module2.exports = (defaultOptions = {}, options = {}) => {
3476
+ const params = __spreadValues(__spreadValues({}, defaultOptions.params || {}), options.params || {});
3477
+ return __spreadValues(__spreadValues(__spreadValues({}, defaultOptions), options), Object.keys(params).length ? {
3478
+ params
3479
+ } : {});
3480
+ };
3481
+ }
3482
+ });
3483
+
3484
+ // node_modules/compress-brotli/src/index.js
3472
3485
  var require_src3 = __commonJS({
3486
+ "node_modules/compress-brotli/src/index.js"(exports, module2) {
3487
+ "use strict";
3488
+ var { promisify } = require("util");
3489
+ var JSONB = require_json_buffer();
3490
+ var zlib = require("zlib");
3491
+ var mergeOptions = require_merge_options();
3492
+ var compress = promisify(zlib.brotliCompress);
3493
+ var decompress = promisify(zlib.brotliDecompress);
3494
+ var identity = (val) => val;
3495
+ var createCompress = ({
3496
+ enable = true,
3497
+ serialize = JSONB.stringify,
3498
+ deserialize = JSONB.parse,
3499
+ compressOptions,
3500
+ decompressOptions
3501
+ } = {}) => {
3502
+ if (!enable) {
3503
+ return { serialize, deserialize, decompress: identity, compress: identity };
3504
+ }
3505
+ return {
3506
+ serialize,
3507
+ deserialize,
3508
+ compress: async (data, options = {}) => {
3509
+ if (data === void 0)
3510
+ return data;
3511
+ const serializedData = serialize(data);
3512
+ return compress(serializedData, mergeOptions(compressOptions, options));
3513
+ },
3514
+ decompress: async (data, options = {}) => {
3515
+ if (data === void 0)
3516
+ return data;
3517
+ return deserialize(await decompress(data, mergeOptions(decompressOptions, options)));
3518
+ }
3519
+ };
3520
+ };
3521
+ module2.exports = createCompress;
3522
+ module2.exports.stringify = JSONB.stringify;
3523
+ module2.exports.parse = JSONB.parse;
3524
+ }
3525
+ });
3526
+
3527
+ // node_modules/keyv/src/index.js
3528
+ var require_src4 = __commonJS({
3473
3529
  "node_modules/keyv/src/index.js"(exports, module2) {
3474
3530
  "use strict";
3475
3531
  var EventEmitter = require("events");
3476
3532
  var JSONB = require_json_buffer();
3477
- BigInt.prototype.toJSON = function() {
3478
- return this.toString();
3479
- };
3533
+ var compressBrotli = require_src3();
3480
3534
  var loadStore = (options) => {
3481
3535
  const adapters = {
3482
3536
  redis: "@keyv/redis",
@@ -3494,36 +3548,121 @@ var require_src3 = __commonJS({
3494
3548
  }
3495
3549
  return /* @__PURE__ */ new Map();
3496
3550
  };
3551
+ var iterableAdapters = [
3552
+ "sqlite",
3553
+ "postgres",
3554
+ "mysql",
3555
+ "mongo",
3556
+ "redis"
3557
+ ];
3497
3558
  var Keyv = class extends EventEmitter {
3498
3559
  constructor(uri, options) {
3499
3560
  super();
3500
- this.opts = Object.assign({
3561
+ this.opts = __spreadValues(__spreadValues({
3501
3562
  namespace: "keyv",
3502
3563
  serialize: JSONB.stringify,
3503
3564
  deserialize: JSONB.parse
3504
- }, typeof uri === "string" ? { uri } : uri, options);
3565
+ }, typeof uri === "string" ? { uri } : uri), options);
3505
3566
  if (!this.opts.store) {
3506
- const adapterOptions = Object.assign({}, this.opts);
3567
+ const adapterOptions = __spreadValues({}, this.opts);
3507
3568
  this.opts.store = loadStore(adapterOptions);
3508
3569
  }
3570
+ if (this.opts.compress) {
3571
+ const brotli = compressBrotli(this.opts.compress.opts);
3572
+ this.opts.serialize = async ({ value, expires }) => brotli.serialize({ value: await brotli.compress(value), expires });
3573
+ this.opts.deserialize = async (data) => {
3574
+ const { value, expires } = brotli.deserialize(data);
3575
+ return { value: await brotli.decompress(value), expires };
3576
+ };
3577
+ }
3509
3578
  if (typeof this.opts.store.on === "function") {
3510
3579
  this.opts.store.on("error", (error) => this.emit("error", error));
3511
3580
  }
3512
3581
  this.opts.store.namespace = this.opts.namespace;
3582
+ const generateIterator = (iterator) => async function* () {
3583
+ for await (const [key, raw] of typeof iterator === "function" ? iterator(this.opts.store.namespace) : iterator) {
3584
+ const data = typeof raw === "string" ? this.opts.deserialize(raw) : raw;
3585
+ if (this.opts.store.namespace && !key.includes(this.opts.store.namespace)) {
3586
+ continue;
3587
+ }
3588
+ if (typeof data.expires === "number" && Date.now() > data.expires) {
3589
+ this.delete(key);
3590
+ continue;
3591
+ }
3592
+ yield [this._getKeyUnprefix(key), data.value];
3593
+ }
3594
+ };
3595
+ if (typeof this.opts.store[Symbol.iterator] === "function" && this.opts.store instanceof Map) {
3596
+ this.iterator = generateIterator(this.opts.store);
3597
+ } else if (typeof this.opts.store.iterator === "function" && this.opts.store.opts && this._checkIterableAdaptar()) {
3598
+ this.iterator = generateIterator(this.opts.store.iterator.bind(this.opts.store));
3599
+ }
3600
+ }
3601
+ _checkIterableAdaptar() {
3602
+ return iterableAdapters.includes(this.opts.store.opts.dialect) || iterableAdapters.findIndex((element) => this.opts.store.opts.url.includes(element)) >= 0;
3513
3603
  }
3514
3604
  _getKeyPrefix(key) {
3515
3605
  return `${this.opts.namespace}:${key}`;
3516
3606
  }
3607
+ _getKeyPrefixArray(keys) {
3608
+ return keys.map((key) => `${this.opts.namespace}:${key}`);
3609
+ }
3610
+ _getKeyUnprefix(key) {
3611
+ return this.opts.store.namespace ? key.split(":").splice(1).join(":") : key;
3612
+ }
3517
3613
  get(key, options) {
3518
- const keyPrefixed = this._getKeyPrefix(key);
3519
3614
  const { store } = this.opts;
3520
- return Promise.resolve().then(() => store.get(keyPrefixed)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : data).then((data) => {
3615
+ const isArray = Array.isArray(key);
3616
+ const keyPrefixed = isArray ? this._getKeyPrefixArray(key) : this._getKeyPrefix(key);
3617
+ if (isArray && store.getMany === void 0) {
3618
+ const promises = [];
3619
+ for (const key2 of keyPrefixed) {
3620
+ promises.push(Promise.resolve().then(() => store.get(key2)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : data).then((data) => {
3621
+ if (data === void 0 || data === null) {
3622
+ return void 0;
3623
+ }
3624
+ if (typeof data.expires === "number" && Date.now() > data.expires) {
3625
+ return this.delete(key2).then(() => void 0);
3626
+ }
3627
+ return options && options.raw ? data : data.value;
3628
+ }));
3629
+ }
3630
+ return Promise.allSettled(promises).then((values) => {
3631
+ const data = [];
3632
+ for (const value of values) {
3633
+ data.push(value.value);
3634
+ }
3635
+ return data.every((x) => x === void 0) ? [] : data;
3636
+ });
3637
+ }
3638
+ return Promise.resolve().then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : data).then((data) => {
3521
3639
  if (data === void 0 || data === null) {
3522
3640
  return void 0;
3523
3641
  }
3642
+ if (isArray) {
3643
+ const result = [];
3644
+ if (data.length === 0) {
3645
+ return [];
3646
+ }
3647
+ for (let row of data) {
3648
+ if (typeof row === "string") {
3649
+ row = this.opts.deserialize(row);
3650
+ }
3651
+ if (row === void 0 || row === null) {
3652
+ result.push(void 0);
3653
+ continue;
3654
+ }
3655
+ if (typeof row.expires === "number" && Date.now() > row.expires) {
3656
+ this.delete(key).then(() => void 0);
3657
+ result.push(void 0);
3658
+ } else {
3659
+ result.push(options && options.raw ? row : row.value);
3660
+ }
3661
+ }
3662
+ return result.every((x) => x === void 0) ? [] : result;
3663
+ }
3524
3664
  if (typeof data.expires === "number" && Date.now() > data.expires) {
3525
- this.delete(key);
3526
- return void 0;
3665
+ return this.delete(key).then(() => void 0);
3527
3666
  }
3528
3667
  return options && options.raw ? data : data.value;
3529
3668
  });
@@ -3547,21 +3686,43 @@ var require_src3 = __commonJS({
3547
3686
  }).then((value2) => store.set(keyPrefixed, value2, ttl)).then(() => true);
3548
3687
  }
3549
3688
  delete(key) {
3550
- const keyPrefixed = this._getKeyPrefix(key);
3551
3689
  const { store } = this.opts;
3690
+ if (Array.isArray(key)) {
3691
+ const keyPrefixed2 = this._getKeyPrefixArray(key);
3692
+ if (store.deleteMany === void 0) {
3693
+ const promises = [];
3694
+ for (const key2 of keyPrefixed2) {
3695
+ promises.push(store.delete(key2));
3696
+ }
3697
+ return Promise.allSettled(promises).then((values) => values.every((x) => x.value === true));
3698
+ }
3699
+ return Promise.resolve().then(() => store.deleteMany(keyPrefixed2));
3700
+ }
3701
+ const keyPrefixed = this._getKeyPrefix(key);
3552
3702
  return Promise.resolve().then(() => store.delete(keyPrefixed));
3553
3703
  }
3554
3704
  clear() {
3555
3705
  const { store } = this.opts;
3556
3706
  return Promise.resolve().then(() => store.clear());
3557
3707
  }
3708
+ has(key) {
3709
+ const keyPrefixed = this._getKeyPrefix(key);
3710
+ const { store } = this.opts;
3711
+ return Promise.resolve().then(async () => {
3712
+ if (typeof store.has === "function") {
3713
+ return store.has(keyPrefixed);
3714
+ }
3715
+ const value = await store.get(keyPrefixed);
3716
+ return value !== void 0;
3717
+ });
3718
+ }
3558
3719
  };
3559
3720
  module2.exports = Keyv;
3560
3721
  }
3561
3722
  });
3562
3723
 
3563
3724
  // node_modules/cacheable-request/src/index.js
3564
- var require_src4 = __commonJS({
3725
+ var require_src5 = __commonJS({
3565
3726
  "node_modules/cacheable-request/src/index.js"(exports, module2) {
3566
3727
  "use strict";
3567
3728
  var EventEmitter = require("events");
@@ -3572,7 +3733,7 @@ var require_src4 = __commonJS({
3572
3733
  var Response = require_src();
3573
3734
  var lowercaseKeys = require_lowercase_keys();
3574
3735
  var cloneResponse = require_src2();
3575
- var Keyv = require_src3();
3736
+ var Keyv = require_src4();
3576
3737
  var CacheableRequest = class {
3577
3738
  constructor(request, cacheAdapter) {
3578
3739
  if (typeof request !== "function") {
@@ -5653,7 +5814,7 @@ var require_core = __commonJS({
5653
5814
  var https = require("https");
5654
5815
  var http_timer_1 = require_source2();
5655
5816
  var cacheable_lookup_1 = require_source3();
5656
- var CacheableRequest = require_src4();
5817
+ var CacheableRequest = require_src5();
5657
5818
  var decompressResponse = require_decompress_response();
5658
5819
  var http2wrapper = require_source4();
5659
5820
  var lowercaseKeys = require_lowercase_keys();