@learncard/core 8.1.1 → 8.3.0

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/dist/core.d.ts CHANGED
@@ -4751,7 +4751,8 @@ export declare type LearnCardStorePlane<Plugins extends Plugin[]> = Record<Filte
4751
4751
  };
4752
4752
  export declare type IndexPlane = {
4753
4753
  get: <Metadata extends Record<string, any> = Record<never, never>>(query?: Record<string, any>, options?: PlaneOptions) => Promise<CredentialRecord<Metadata>[]>;
4754
- add: <Metadata extends Record<string, any> = Record<never, never>>(obj: CredentialRecord<Metadata>, options?: PlaneOptions) => Promise<boolean>;
4754
+ add: <Metadata extends Record<string, any> = Record<never, never>>(record: CredentialRecord<Metadata>, options?: PlaneOptions) => Promise<boolean>;
4755
+ addMany?: <Metadata extends Record<string, any> = Record<never, never>>(records: CredentialRecord<Metadata>[], options?: PlaneOptions) => Promise<boolean>;
4755
4756
  update: (id: string, updates: Record<string, any>, options?: PlaneOptions) => Promise<boolean>;
4756
4757
  remove: (id: string, options?: PlaneOptions) => Promise<boolean>;
4757
4758
  removeAll?: (options?: PlaneOptions) => Promise<boolean>;
@@ -5961,6 +5962,8 @@ export declare const expirationPlugin: (learnCard: LearnCard<any, any, VerifyExt
5961
5962
  export declare const getIDXPlugin: <URI extends string = "">(learnCard: LearnCard<any, "read", IDXPluginDependentMethods<URI>>, { modelData, credentialAlias }: IDXArgs) => Promise<IDXPlugin>;
5962
5963
  export declare type TestCachePlugin = Plugin<"Test Cache", "cache">;
5963
5964
  export declare const getTestCache: () => TestCachePlugin;
5965
+ export declare type TestStoragePlugin = Plugin<"Test Storage", "read" | "store" | "index">;
5966
+ export declare const getTestStorage: () => TestStoragePlugin;
5964
5967
  /**
5965
5968
  * @group Plugins
5966
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
  }
@@ -46330,6 +46337,14 @@ var addCachingToIndexPlane = /* @__PURE__ */ __name((plane, name5) => ({
46330
46337
  }
46331
46338
  return plane.add(_learnCard, record);
46332
46339
  },
46340
+ ...plane.addMany ? {
46341
+ addMany: async (_learnCard, records, { cache = "cache-first" } = {}) => {
46342
+ if (cache !== "skip-cache" && learnCardImplementsPlane(_learnCard, "cache")) {
46343
+ await _learnCard.cache.flushIndex();
46344
+ }
46345
+ return plane.addMany?.(_learnCard, records);
46346
+ }
46347
+ } : {},
46333
46348
  update: async (_learnCard, id, update2, { cache = "cache-first" } = {}) => {
46334
46349
  if (cache !== "skip-cache" && learnCardImplementsPlane(_learnCard, "cache")) {
46335
46350
  await _learnCard.cache.flushIndex();
@@ -46386,7 +46401,7 @@ var generateIndexPlane = /* @__PURE__ */ __name((learnCard) => {
46386
46401
  return plugin.index.get(learnCard, query);
46387
46402
  })
46388
46403
  )).flat();
46389
- const results = [...new Set(resultsWithDuplicates)];
46404
+ const results = uniqBy(resultsWithDuplicates, "id");
46390
46405
  if (results && learnCardImplementsPlane(learnCard, "cache") && cache !== "skip-cache") {
46391
46406
  await learnCard.cache.setIndex("all", query ?? {}, results);
46392
46407
  }
@@ -46400,7 +46415,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
46400
46415
  getIndex: async (name5, query) => {
46401
46416
  learnCard.debug?.("learnCard.cache.getIndex");
46402
46417
  try {
46403
- const index = await Promise.any(
46418
+ const results = await Promise.allSettled(
46404
46419
  learnCard.plugins.map(async (plugin) => {
46405
46420
  if (!pluginImplementsPlane(plugin, "cache")) {
46406
46421
  throw new Error("Plugin is not a Cache Plugin");
@@ -46408,6 +46423,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
46408
46423
  return plugin.cache.getIndex(learnCard, name5, query);
46409
46424
  })
46410
46425
  );
46426
+ const index = results.find(isFulfilledAndNotEmpty)?.value;
46411
46427
  return index;
46412
46428
  } catch (error) {
46413
46429
  return void 0;
@@ -46440,7 +46456,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
46440
46456
  getVc: async (uri) => {
46441
46457
  learnCard.debug?.("learnCard.cache.getVc");
46442
46458
  try {
46443
- const vc = await Promise.any(
46459
+ const results = await Promise.allSettled(
46444
46460
  learnCard.plugins.map(async (plugin) => {
46445
46461
  if (!pluginImplementsPlane(plugin, "cache")) {
46446
46462
  throw new Error("Plugin is not a Cache Plugin");
@@ -46448,6 +46464,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
46448
46464
  return plugin.cache.getVc(learnCard, uri);
46449
46465
  })
46450
46466
  );
46467
+ const vc = results.find(isFulfilledAndNotEmpty)?.value;
46451
46468
  return vc;
46452
46469
  } catch (error) {
46453
46470
  return void 0;
@@ -67650,8 +67667,8 @@ var getIDXPlugin = /* @__PURE__ */ __name(async (learnCard, { modelData, credent
67650
67667
  alias = credentialAlias;
67651
67668
  return dataStore.set(alias, { credentials: [] });
67652
67669
  }, "removeAllCredentialsFromIdx");
67653
- const addCredentialInIdx = /* @__PURE__ */ __name(async (idxCredential) => {
67654
- const record = CredentialRecordValidator.parse(idxCredential);
67670
+ const addCredentialInIdx = /* @__PURE__ */ __name(async (_record) => {
67671
+ const record = await CredentialRecordValidator.parseAsync(_record);
67655
67672
  if (!record)
67656
67673
  throw new Error("record is required");
67657
67674
  if (!record.uri)
@@ -67667,6 +67684,23 @@ var getIDXPlugin = /* @__PURE__ */ __name(async (learnCard, { modelData, credent
67667
67684
  existing.credentials.push(record);
67668
67685
  return streamIdToCeramicURI(await dataStore.set(credentialAlias, existing));
67669
67686
  }, "addCredentialInIdx");
67687
+ const addCredentialsInIdx = /* @__PURE__ */ __name(async (_records) => {
67688
+ const records = CredentialRecordValidator.array().parse(_records);
67689
+ const existing = await getCredentialsListFromIdx(credentialAlias);
67690
+ await Promise.all(
67691
+ records.map(async (record) => {
67692
+ await learnCard.read.get(record.uri);
67693
+ const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
67694
+ return credential.id === record.id;
67695
+ });
67696
+ if (indexOfExistingCredential > -1) {
67697
+ existing.credentials[indexOfExistingCredential] = record;
67698
+ } else
67699
+ existing.credentials.push(record);
67700
+ })
67701
+ );
67702
+ return streamIdToCeramicURI(await dataStore.set(credentialAlias, existing));
67703
+ }, "addCredentialsInIdx");
67670
67704
  return {
67671
67705
  name: "IDX",
67672
67706
  displayName: "IDX",
@@ -67687,6 +67721,16 @@ var getIDXPlugin = /* @__PURE__ */ __name(async (learnCard, { modelData, credent
67687
67721
  return false;
67688
67722
  }
67689
67723
  },
67724
+ addMany: async (_learnCard, records) => {
67725
+ _learnCard.debug?.("learnCard.index.IDX.add");
67726
+ try {
67727
+ await addCredentialsInIdx(records);
67728
+ return true;
67729
+ } catch (error) {
67730
+ console.error("Error adding credential with IDX:", error);
67731
+ return false;
67732
+ }
67733
+ },
67690
67734
  update: async (_learnCard) => {
67691
67735
  _learnCard.debug?.("learnCard.index.IDX.update");
67692
67736
  return false;
@@ -71364,6 +71408,55 @@ var getTestCache = /* @__PURE__ */ __name(() => {
71364
71408
  methods: {}
71365
71409
  };
71366
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");
71367
71460
  export {
71368
71461
  BackwardsCompatCredentialsListValidator,
71369
71462
  BackwardsCompatIDXCredentialValidator,
@@ -71381,6 +71474,7 @@ export {
71381
71474
  getEthereumPlugin,
71382
71475
  getIDXPlugin,
71383
71476
  getTestCache,
71477
+ getTestStorage,
71384
71478
  getVCAPIPlugin,
71385
71479
  getVCPlugin,
71386
71480
  getVCTemplatesPlugin,