construct-hub 0.3.303 → 0.3.304

Sign up to get free protection for your applications and to get access to all the features.
@@ -303,7 +303,7 @@ class ConstructHub extends core_1.Construct {
303
303
  }
304
304
  exports.ConstructHub = ConstructHub;
305
305
  _a = JSII_RTTI_SYMBOL_1;
306
- ConstructHub[_a] = { fqn: "construct-hub.ConstructHub", version: "0.3.303" };
306
+ ConstructHub[_a] = { fqn: "construct-hub.ConstructHub", version: "0.3.304" };
307
307
  /**
308
308
  * How possibly risky operations (such as doc-generation, which requires
309
309
  * installing the indexed packages in order to trans-literate sample code) are
@@ -2141,15 +2141,69 @@ var require_json_buffer = __commonJS({
2141
2141
  }
2142
2142
  });
2143
2143
 
2144
- // node_modules/keyv/src/index.js
2144
+ // node_modules/compress-brotli/src/merge-options.js
2145
+ var require_merge_options = __commonJS({
2146
+ "node_modules/compress-brotli/src/merge-options.js"(exports, module2) {
2147
+ "use strict";
2148
+ module2.exports = (defaultOptions = {}, options = {}) => {
2149
+ const params = __spreadValues(__spreadValues({}, defaultOptions.params || {}), options.params || {});
2150
+ return __spreadValues(__spreadValues(__spreadValues({}, defaultOptions), options), Object.keys(params).length ? {
2151
+ params
2152
+ } : {});
2153
+ };
2154
+ }
2155
+ });
2156
+
2157
+ // node_modules/compress-brotli/src/index.js
2145
2158
  var require_src3 = __commonJS({
2159
+ "node_modules/compress-brotli/src/index.js"(exports, module2) {
2160
+ "use strict";
2161
+ var { promisify } = require("util");
2162
+ var JSONB = require_json_buffer();
2163
+ var zlib = require("zlib");
2164
+ var mergeOptions = require_merge_options();
2165
+ var compress = promisify(zlib.brotliCompress);
2166
+ var decompress = promisify(zlib.brotliDecompress);
2167
+ var identity = (val) => val;
2168
+ var createCompress = ({
2169
+ enable = true,
2170
+ serialize = JSONB.stringify,
2171
+ deserialize = JSONB.parse,
2172
+ compressOptions,
2173
+ decompressOptions
2174
+ } = {}) => {
2175
+ if (!enable) {
2176
+ return { serialize, deserialize, decompress: identity, compress: identity };
2177
+ }
2178
+ return {
2179
+ serialize,
2180
+ deserialize,
2181
+ compress: async (data, options = {}) => {
2182
+ if (data === void 0)
2183
+ return data;
2184
+ const serializedData = serialize(data);
2185
+ return compress(serializedData, mergeOptions(compressOptions, options));
2186
+ },
2187
+ decompress: async (data, options = {}) => {
2188
+ if (data === void 0)
2189
+ return data;
2190
+ return deserialize(await decompress(data, mergeOptions(decompressOptions, options)));
2191
+ }
2192
+ };
2193
+ };
2194
+ module2.exports = createCompress;
2195
+ module2.exports.stringify = JSONB.stringify;
2196
+ module2.exports.parse = JSONB.parse;
2197
+ }
2198
+ });
2199
+
2200
+ // node_modules/keyv/src/index.js
2201
+ var require_src4 = __commonJS({
2146
2202
  "node_modules/keyv/src/index.js"(exports, module2) {
2147
2203
  "use strict";
2148
2204
  var EventEmitter = require("events");
2149
2205
  var JSONB = require_json_buffer();
2150
- BigInt.prototype.toJSON = function() {
2151
- return this.toString();
2152
- };
2206
+ var compressBrotli = require_src3();
2153
2207
  var loadStore = (options) => {
2154
2208
  const adapters = {
2155
2209
  redis: "@keyv/redis",
@@ -2167,36 +2221,121 @@ var require_src3 = __commonJS({
2167
2221
  }
2168
2222
  return /* @__PURE__ */ new Map();
2169
2223
  };
2224
+ var iterableAdapters = [
2225
+ "sqlite",
2226
+ "postgres",
2227
+ "mysql",
2228
+ "mongo",
2229
+ "redis"
2230
+ ];
2170
2231
  var Keyv = class extends EventEmitter {
2171
2232
  constructor(uri, options) {
2172
2233
  super();
2173
- this.opts = Object.assign({
2234
+ this.opts = __spreadValues(__spreadValues({
2174
2235
  namespace: "keyv",
2175
2236
  serialize: JSONB.stringify,
2176
2237
  deserialize: JSONB.parse
2177
- }, typeof uri === "string" ? { uri } : uri, options);
2238
+ }, typeof uri === "string" ? { uri } : uri), options);
2178
2239
  if (!this.opts.store) {
2179
- const adapterOptions = Object.assign({}, this.opts);
2240
+ const adapterOptions = __spreadValues({}, this.opts);
2180
2241
  this.opts.store = loadStore(adapterOptions);
2181
2242
  }
2243
+ if (this.opts.compress) {
2244
+ const brotli = compressBrotli(this.opts.compress.opts);
2245
+ this.opts.serialize = async ({ value, expires }) => brotli.serialize({ value: await brotli.compress(value), expires });
2246
+ this.opts.deserialize = async (data) => {
2247
+ const { value, expires } = brotli.deserialize(data);
2248
+ return { value: await brotli.decompress(value), expires };
2249
+ };
2250
+ }
2182
2251
  if (typeof this.opts.store.on === "function") {
2183
2252
  this.opts.store.on("error", (error) => this.emit("error", error));
2184
2253
  }
2185
2254
  this.opts.store.namespace = this.opts.namespace;
2255
+ const generateIterator = (iterator) => async function* () {
2256
+ for await (const [key, raw] of typeof iterator === "function" ? iterator(this.opts.store.namespace) : iterator) {
2257
+ const data = typeof raw === "string" ? this.opts.deserialize(raw) : raw;
2258
+ if (this.opts.store.namespace && !key.includes(this.opts.store.namespace)) {
2259
+ continue;
2260
+ }
2261
+ if (typeof data.expires === "number" && Date.now() > data.expires) {
2262
+ this.delete(key);
2263
+ continue;
2264
+ }
2265
+ yield [this._getKeyUnprefix(key), data.value];
2266
+ }
2267
+ };
2268
+ if (typeof this.opts.store[Symbol.iterator] === "function" && this.opts.store instanceof Map) {
2269
+ this.iterator = generateIterator(this.opts.store);
2270
+ } else if (typeof this.opts.store.iterator === "function" && this.opts.store.opts && this._checkIterableAdaptar()) {
2271
+ this.iterator = generateIterator(this.opts.store.iterator.bind(this.opts.store));
2272
+ }
2273
+ }
2274
+ _checkIterableAdaptar() {
2275
+ return iterableAdapters.includes(this.opts.store.opts.dialect) || iterableAdapters.findIndex((element) => this.opts.store.opts.url.includes(element)) >= 0;
2186
2276
  }
2187
2277
  _getKeyPrefix(key) {
2188
2278
  return `${this.opts.namespace}:${key}`;
2189
2279
  }
2280
+ _getKeyPrefixArray(keys) {
2281
+ return keys.map((key) => `${this.opts.namespace}:${key}`);
2282
+ }
2283
+ _getKeyUnprefix(key) {
2284
+ return this.opts.store.namespace ? key.split(":").splice(1).join(":") : key;
2285
+ }
2190
2286
  get(key, options) {
2191
- const keyPrefixed = this._getKeyPrefix(key);
2192
2287
  const { store } = this.opts;
2193
- return Promise.resolve().then(() => store.get(keyPrefixed)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : data).then((data) => {
2288
+ const isArray = Array.isArray(key);
2289
+ const keyPrefixed = isArray ? this._getKeyPrefixArray(key) : this._getKeyPrefix(key);
2290
+ if (isArray && store.getMany === void 0) {
2291
+ const promises = [];
2292
+ for (const key2 of keyPrefixed) {
2293
+ promises.push(Promise.resolve().then(() => store.get(key2)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : data).then((data) => {
2294
+ if (data === void 0 || data === null) {
2295
+ return void 0;
2296
+ }
2297
+ if (typeof data.expires === "number" && Date.now() > data.expires) {
2298
+ return this.delete(key2).then(() => void 0);
2299
+ }
2300
+ return options && options.raw ? data : data.value;
2301
+ }));
2302
+ }
2303
+ return Promise.allSettled(promises).then((values) => {
2304
+ const data = [];
2305
+ for (const value of values) {
2306
+ data.push(value.value);
2307
+ }
2308
+ return data.every((x) => x === void 0) ? [] : data;
2309
+ });
2310
+ }
2311
+ return Promise.resolve().then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : data).then((data) => {
2194
2312
  if (data === void 0 || data === null) {
2195
2313
  return void 0;
2196
2314
  }
2315
+ if (isArray) {
2316
+ const result = [];
2317
+ if (data.length === 0) {
2318
+ return [];
2319
+ }
2320
+ for (let row of data) {
2321
+ if (typeof row === "string") {
2322
+ row = this.opts.deserialize(row);
2323
+ }
2324
+ if (row === void 0 || row === null) {
2325
+ result.push(void 0);
2326
+ continue;
2327
+ }
2328
+ if (typeof row.expires === "number" && Date.now() > row.expires) {
2329
+ this.delete(key).then(() => void 0);
2330
+ result.push(void 0);
2331
+ } else {
2332
+ result.push(options && options.raw ? row : row.value);
2333
+ }
2334
+ }
2335
+ return result.every((x) => x === void 0) ? [] : result;
2336
+ }
2197
2337
  if (typeof data.expires === "number" && Date.now() > data.expires) {
2198
- this.delete(key);
2199
- return void 0;
2338
+ return this.delete(key).then(() => void 0);
2200
2339
  }
2201
2340
  return options && options.raw ? data : data.value;
2202
2341
  });
@@ -2220,21 +2359,43 @@ var require_src3 = __commonJS({
2220
2359
  }).then((value2) => store.set(keyPrefixed, value2, ttl)).then(() => true);
2221
2360
  }
2222
2361
  delete(key) {
2223
- const keyPrefixed = this._getKeyPrefix(key);
2224
2362
  const { store } = this.opts;
2363
+ if (Array.isArray(key)) {
2364
+ const keyPrefixed2 = this._getKeyPrefixArray(key);
2365
+ if (store.deleteMany === void 0) {
2366
+ const promises = [];
2367
+ for (const key2 of keyPrefixed2) {
2368
+ promises.push(store.delete(key2));
2369
+ }
2370
+ return Promise.allSettled(promises).then((values) => values.every((x) => x.value === true));
2371
+ }
2372
+ return Promise.resolve().then(() => store.deleteMany(keyPrefixed2));
2373
+ }
2374
+ const keyPrefixed = this._getKeyPrefix(key);
2225
2375
  return Promise.resolve().then(() => store.delete(keyPrefixed));
2226
2376
  }
2227
2377
  clear() {
2228
2378
  const { store } = this.opts;
2229
2379
  return Promise.resolve().then(() => store.clear());
2230
2380
  }
2381
+ has(key) {
2382
+ const keyPrefixed = this._getKeyPrefix(key);
2383
+ const { store } = this.opts;
2384
+ return Promise.resolve().then(async () => {
2385
+ if (typeof store.has === "function") {
2386
+ return store.has(keyPrefixed);
2387
+ }
2388
+ const value = await store.get(keyPrefixed);
2389
+ return value !== void 0;
2390
+ });
2391
+ }
2231
2392
  };
2232
2393
  module2.exports = Keyv;
2233
2394
  }
2234
2395
  });
2235
2396
 
2236
2397
  // node_modules/cacheable-request/src/index.js
2237
- var require_src4 = __commonJS({
2398
+ var require_src5 = __commonJS({
2238
2399
  "node_modules/cacheable-request/src/index.js"(exports, module2) {
2239
2400
  "use strict";
2240
2401
  var EventEmitter = require("events");
@@ -2245,7 +2406,7 @@ var require_src4 = __commonJS({
2245
2406
  var Response = require_src();
2246
2407
  var lowercaseKeys = require_lowercase_keys();
2247
2408
  var cloneResponse = require_src2();
2248
- var Keyv = require_src3();
2409
+ var Keyv = require_src4();
2249
2410
  var CacheableRequest = class {
2250
2411
  constructor(request, cacheAdapter) {
2251
2412
  if (typeof request !== "function") {
@@ -4326,7 +4487,7 @@ var require_core = __commonJS({
4326
4487
  var https = require("https");
4327
4488
  var http_timer_1 = require_source2();
4328
4489
  var cacheable_lookup_1 = require_source3();
4329
- var CacheableRequest = require_src4();
4490
+ var CacheableRequest = require_src5();
4330
4491
  var decompressResponse = require_decompress_response();
4331
4492
  var http2wrapper = require_source4();
4332
4493
  var lowercaseKeys = require_lowercase_keys();