@learncard/core 8.2.0 → 8.3.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/core.d.ts CHANGED
@@ -5962,6 +5962,8 @@ export declare const expirationPlugin: (learnCard: LearnCard<any, any, VerifyExt
5962
5962
  export declare const getIDXPlugin: <URI extends string = "">(learnCard: LearnCard<any, "read", IDXPluginDependentMethods<URI>>, { modelData, credentialAlias }: IDXArgs) => Promise<IDXPlugin>;
5963
5963
  export declare type TestCachePlugin = Plugin<"Test Cache", "cache">;
5964
5964
  export declare const getTestCache: () => TestCachePlugin;
5965
+ export declare type TestStoragePlugin = Plugin<"Test Storage", "read" | "store" | "index">;
5966
+ export declare const getTestStorage: () => TestStoragePlugin;
5965
5967
  /**
5966
5968
  * @group Plugins
5967
5969
  */
package/dist/core.esm.js CHANGED
@@ -7134,10 +7134,10 @@ var require_lodash = __commonJS({
7134
7134
  return array && array.length ? baseUniq(array) : [];
7135
7135
  }
7136
7136
  __name(uniq, "uniq");
7137
- function uniqBy(array, iteratee2) {
7137
+ function uniqBy2(array, iteratee2) {
7138
7138
  return array && array.length ? baseUniq(array, getIteratee(iteratee2, 2)) : [];
7139
7139
  }
7140
- __name(uniqBy, "uniqBy");
7140
+ __name(uniqBy2, "uniqBy");
7141
7141
  function uniqWith(array, comparator) {
7142
7142
  comparator = typeof comparator == "function" ? comparator : undefined2;
7143
7143
  return array && array.length ? baseUniq(array, undefined2, comparator) : [];
@@ -8977,7 +8977,7 @@ var require_lodash = __commonJS({
8977
8977
  lodash.unionBy = unionBy;
8978
8978
  lodash.unionWith = unionWith;
8979
8979
  lodash.uniq = uniq;
8980
- lodash.uniqBy = uniqBy;
8980
+ lodash.uniqBy = uniqBy2;
8981
8981
  lodash.uniqWith = uniqWith;
8982
8982
  lodash.unset = unset;
8983
8983
  lodash.unzip = unzip;
@@ -46217,6 +46217,12 @@ var mapObject = /* @__PURE__ */ __name((obj, callback) => {
46217
46217
  Object.entries(obj).map(([key2, value], index) => [key2, callback(value, index)])
46218
46218
  );
46219
46219
  }, "mapObject");
46220
+ var isFulfilledAndNotEmpty = /* @__PURE__ */ __name((input) => input.status === "fulfilled" && !!input.value, "isFulfilledAndNotEmpty");
46221
+ var uniqBy = /* @__PURE__ */ __name((array, key2) => {
46222
+ return [
46223
+ ...new Map(array.map((obj) => [key2 instanceof Function ? key2(obj) : obj[key2], obj])).values()
46224
+ ];
46225
+ }, "uniqBy");
46220
46226
 
46221
46227
  // src/wallet/base/wallet.ts
46222
46228
  var getPlaneProviders = /* @__PURE__ */ __name((plugins, plane) => {
@@ -46257,7 +46263,7 @@ var generateReadPlane = /* @__PURE__ */ __name((learnCard) => {
46257
46263
  return cachedResponse;
46258
46264
  }
46259
46265
  }
46260
- const vc = await Promise.any(
46266
+ const results = await Promise.allSettled(
46261
46267
  learnCard.plugins.map(async (plugin) => {
46262
46268
  if (!pluginImplementsPlane(plugin, "read")) {
46263
46269
  throw new Error("Plugin is not a Read Plugin");
@@ -46265,6 +46271,7 @@ var generateReadPlane = /* @__PURE__ */ __name((learnCard) => {
46265
46271
  return plugin.read.get(learnCard, uri);
46266
46272
  })
46267
46273
  );
46274
+ const vc = results.find(isFulfilledAndNotEmpty)?.value;
46268
46275
  if (vc && learnCardImplementsPlane(learnCard, "cache") && cache !== "skip-cache") {
46269
46276
  await learnCard.cache.setVc(uri, vc);
46270
46277
  }
@@ -46394,7 +46401,7 @@ var generateIndexPlane = /* @__PURE__ */ __name((learnCard) => {
46394
46401
  return plugin.index.get(learnCard, query);
46395
46402
  })
46396
46403
  )).flat();
46397
- const results = [...new Set(resultsWithDuplicates)];
46404
+ const results = uniqBy(resultsWithDuplicates, "id");
46398
46405
  if (results && learnCardImplementsPlane(learnCard, "cache") && cache !== "skip-cache") {
46399
46406
  await learnCard.cache.setIndex("all", query ?? {}, results);
46400
46407
  }
@@ -46408,7 +46415,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
46408
46415
  getIndex: async (name5, query) => {
46409
46416
  learnCard.debug?.("learnCard.cache.getIndex");
46410
46417
  try {
46411
- const index = await Promise.any(
46418
+ const results = await Promise.allSettled(
46412
46419
  learnCard.plugins.map(async (plugin) => {
46413
46420
  if (!pluginImplementsPlane(plugin, "cache")) {
46414
46421
  throw new Error("Plugin is not a Cache Plugin");
@@ -46416,6 +46423,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
46416
46423
  return plugin.cache.getIndex(learnCard, name5, query);
46417
46424
  })
46418
46425
  );
46426
+ const index = results.find(isFulfilledAndNotEmpty)?.value;
46419
46427
  return index;
46420
46428
  } catch (error) {
46421
46429
  return void 0;
@@ -46448,7 +46456,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
46448
46456
  getVc: async (uri) => {
46449
46457
  learnCard.debug?.("learnCard.cache.getVc");
46450
46458
  try {
46451
- const vc = await Promise.any(
46459
+ const results = await Promise.allSettled(
46452
46460
  learnCard.plugins.map(async (plugin) => {
46453
46461
  if (!pluginImplementsPlane(plugin, "cache")) {
46454
46462
  throw new Error("Plugin is not a Cache Plugin");
@@ -46456,6 +46464,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
46456
46464
  return plugin.cache.getVc(learnCard, uri);
46457
46465
  })
46458
46466
  );
46467
+ const vc = results.find(isFulfilledAndNotEmpty)?.value;
46459
46468
  return vc;
46460
46469
  } catch (error) {
46461
46470
  return void 0;
@@ -71399,6 +71408,55 @@ var getTestCache = /* @__PURE__ */ __name(() => {
71399
71408
  methods: {}
71400
71409
  };
71401
71410
  }, "getTestCache");
71411
+
71412
+ // src/wallet/plugins/test-storage/index.ts
71413
+ var getTestStorage = /* @__PURE__ */ __name(() => {
71414
+ let index = [];
71415
+ let vcs = [];
71416
+ return {
71417
+ name: "Test Storage",
71418
+ displayName: "Test Storage",
71419
+ description: "[Testing] Tests Storage Implementations",
71420
+ read: {
71421
+ get: async (_learnCard, uri) => {
71422
+ _learnCard.debug?.("Test Storage, read, get", { uri });
71423
+ if (!uri)
71424
+ return void 0;
71425
+ const [_lc, method, vcIndex] = uri.split(":");
71426
+ if (method !== "test")
71427
+ return void 0;
71428
+ return vcs[Number.parseInt(vcIndex)];
71429
+ }
71430
+ },
71431
+ store: {
71432
+ upload: async (_learnCard, vc) => {
71433
+ _learnCard.debug?.("Test Storage, store, upload", { vc });
71434
+ const vcIndex = vcs.length;
71435
+ vcs.push(vc);
71436
+ return `lc:test:${vcIndex}`;
71437
+ }
71438
+ },
71439
+ index: {
71440
+ get: async (_learnCard, query) => {
71441
+ _learnCard.debug?.("Test Storage, index, get", { query });
71442
+ return index;
71443
+ },
71444
+ add: async (_learnCard, record) => {
71445
+ _learnCard.debug?.("Test Storage, index, add", { record });
71446
+ index.push(record);
71447
+ return true;
71448
+ },
71449
+ update: async () => false,
71450
+ remove: async (_learnCard, id) => {
71451
+ _learnCard.debug?.("Test Storage, index, remove", { id });
71452
+ let recordIndex = index.findIndex((record) => record.id === id);
71453
+ index.splice(recordIndex, 1);
71454
+ return true;
71455
+ }
71456
+ },
71457
+ methods: {}
71458
+ };
71459
+ }, "getTestStorage");
71402
71460
  export {
71403
71461
  BackwardsCompatCredentialsListValidator,
71404
71462
  BackwardsCompatIDXCredentialValidator,
@@ -71416,6 +71474,7 @@ export {
71416
71474
  getEthereumPlugin,
71417
71475
  getIDXPlugin,
71418
71476
  getTestCache,
71477
+ getTestStorage,
71419
71478
  getVCAPIPlugin,
71420
71479
  getVCPlugin,
71421
71480
  getVCTemplatesPlugin,