@learncard/core 8.1.1 → 8.2.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.
@@ -46351,6 +46351,14 @@ var addCachingToIndexPlane = /* @__PURE__ */ __name((plane, name5) => ({
46351
46351
  }
46352
46352
  return plane.add(_learnCard, record);
46353
46353
  },
46354
+ ...plane.addMany ? {
46355
+ addMany: async (_learnCard, records, { cache = "cache-first" } = {}) => {
46356
+ if (cache !== "skip-cache" && learnCardImplementsPlane(_learnCard, "cache")) {
46357
+ await _learnCard.cache.flushIndex();
46358
+ }
46359
+ return plane.addMany?.(_learnCard, records);
46360
+ }
46361
+ } : {},
46354
46362
  update: async (_learnCard, id, update2, { cache = "cache-first" } = {}) => {
46355
46363
  if (cache !== "skip-cache" && learnCardImplementsPlane(_learnCard, "cache")) {
46356
46364
  await _learnCard.cache.flushIndex();
@@ -67672,8 +67680,8 @@ var getIDXPlugin = /* @__PURE__ */ __name(async (learnCard, { modelData, credent
67672
67680
  alias = credentialAlias;
67673
67681
  return dataStore.set(alias, { credentials: [] });
67674
67682
  }, "removeAllCredentialsFromIdx");
67675
- const addCredentialInIdx = /* @__PURE__ */ __name(async (idxCredential) => {
67676
- const record = CredentialRecordValidator.parse(idxCredential);
67683
+ const addCredentialInIdx = /* @__PURE__ */ __name(async (_record) => {
67684
+ const record = await CredentialRecordValidator.parseAsync(_record);
67677
67685
  if (!record)
67678
67686
  throw new Error("record is required");
67679
67687
  if (!record.uri)
@@ -67689,6 +67697,23 @@ var getIDXPlugin = /* @__PURE__ */ __name(async (learnCard, { modelData, credent
67689
67697
  existing.credentials.push(record);
67690
67698
  return streamIdToCeramicURI(await dataStore.set(credentialAlias, existing));
67691
67699
  }, "addCredentialInIdx");
67700
+ const addCredentialsInIdx = /* @__PURE__ */ __name(async (_records) => {
67701
+ const records = CredentialRecordValidator.array().parse(_records);
67702
+ const existing = await getCredentialsListFromIdx(credentialAlias);
67703
+ await Promise.all(
67704
+ records.map(async (record) => {
67705
+ await learnCard.read.get(record.uri);
67706
+ const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
67707
+ return credential.id === record.id;
67708
+ });
67709
+ if (indexOfExistingCredential > -1) {
67710
+ existing.credentials[indexOfExistingCredential] = record;
67711
+ } else
67712
+ existing.credentials.push(record);
67713
+ })
67714
+ );
67715
+ return streamIdToCeramicURI(await dataStore.set(credentialAlias, existing));
67716
+ }, "addCredentialsInIdx");
67692
67717
  return {
67693
67718
  name: "IDX",
67694
67719
  displayName: "IDX",
@@ -67709,6 +67734,16 @@ var getIDXPlugin = /* @__PURE__ */ __name(async (learnCard, { modelData, credent
67709
67734
  return false;
67710
67735
  }
67711
67736
  },
67737
+ addMany: async (_learnCard, records) => {
67738
+ _learnCard.debug?.("learnCard.index.IDX.add");
67739
+ try {
67740
+ await addCredentialsInIdx(records);
67741
+ return true;
67742
+ } catch (error) {
67743
+ console.error("Error adding credential with IDX:", error);
67744
+ return false;
67745
+ }
67746
+ },
67712
67747
  update: async (_learnCard) => {
67713
67748
  _learnCard.debug?.("learnCard.index.IDX.update");
67714
67749
  return false;