@pkcprotocol/pkc-js 0.0.87 → 0.0.89

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.
Files changed (58) hide show
  1. package/README.md +1 -1
  2. package/dist/browser/community/schema.d.ts +10 -10
  3. package/dist/browser/community/schema.js +1 -1
  4. package/dist/browser/community/schema.js.map +1 -1
  5. package/dist/browser/generated-version.d.ts +1 -1
  6. package/dist/browser/generated-version.js +1 -1
  7. package/dist/browser/helia/helia-for-pkc.d.ts +2 -0
  8. package/dist/browser/helia/helia-for-pkc.js +158 -55
  9. package/dist/browser/helia/helia-for-pkc.js.map +1 -1
  10. package/dist/browser/helia/libp2pjsClient.d.ts +1 -1
  11. package/dist/browser/helia/lru-blockstore.d.ts +9 -8
  12. package/dist/browser/helia/lru-blockstore.js.map +1 -1
  13. package/dist/browser/helia/types.d.ts +10 -10
  14. package/dist/browser/rpc/src/schema.d.ts +148 -22
  15. package/dist/browser/runtime/node/community/local-community/cleanup.js +31 -1
  16. package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -1
  17. package/dist/browser/schema/schema-util.d.ts +3 -3
  18. package/dist/browser/schema.d.ts +8 -6
  19. package/dist/browser/schema.js +8 -1
  20. package/dist/browser/schema.js.map +1 -1
  21. package/dist/browser/test/test-util.d.ts +3 -3
  22. package/dist/browser/test/test-util.js +3 -1
  23. package/dist/browser/test/test-util.js.map +1 -1
  24. package/dist/bundled/bundle-manifest.json +165 -146
  25. package/dist/bundled/chunks/{helia-for-pkc-CjrfyXsA.js → helia-for-pkc-BKXOmklx.js} +101 -70
  26. package/dist/bundled/chunks/{local-community-DbfQyZow.js → local-community-C7tTEYDD.js} +1 -1
  27. package/dist/bundled/chunks/{local-community-Ba5iR3bD.js → local-community-D5fzgPCr.js} +60 -31
  28. package/dist/bundled/chunks/{node-gCrky-14.js → node-C9RpmtmM.js} +5 -5
  29. package/dist/bundled/chunks/{rpc-local-community-BYd-0Aw4.js → rpc-local-community-Dq00OHRf.js} +432 -6
  30. package/dist/bundled/chunks/{schema-0b9XHoqX.js → schema-bDrzx9EZ.js} +4 -4
  31. package/dist/bundled/chunks/{src-WLgFbUwZ.js → src-629pKfxo.js} +2731 -415
  32. package/dist/bundled/chunks/{src-B2CwDTfy.js → src-Dz9wtvrK.js} +18 -18
  33. package/dist/bundled/chunks/{util-CvgcZ9iH.js → util-DuJcVQ7Y.js} +1 -1
  34. package/dist/bundled/index.js +1 -1
  35. package/dist/bundled/rpc/src/index.js +4 -4
  36. package/dist/node/community/schema.d.ts +10 -10
  37. package/dist/node/community/schema.js +1 -1
  38. package/dist/node/community/schema.js.map +1 -1
  39. package/dist/node/generated-version.d.ts +1 -1
  40. package/dist/node/generated-version.js +1 -1
  41. package/dist/node/helia/helia-for-pkc.d.ts +2 -0
  42. package/dist/node/helia/helia-for-pkc.js +158 -55
  43. package/dist/node/helia/helia-for-pkc.js.map +1 -1
  44. package/dist/node/helia/libp2pjsClient.d.ts +1 -1
  45. package/dist/node/helia/lru-blockstore.d.ts +9 -8
  46. package/dist/node/helia/lru-blockstore.js.map +1 -1
  47. package/dist/node/helia/types.d.ts +10 -10
  48. package/dist/node/rpc/src/schema.d.ts +148 -22
  49. package/dist/node/runtime/node/community/local-community/cleanup.js +31 -1
  50. package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -1
  51. package/dist/node/schema/schema-util.d.ts +3 -3
  52. package/dist/node/schema.d.ts +8 -6
  53. package/dist/node/schema.js +8 -1
  54. package/dist/node/schema.js.map +1 -1
  55. package/dist/node/test/test-util.d.ts +3 -3
  56. package/dist/node/test/test-util.js +3 -1
  57. package/dist/node/test/test-util.js.map +1 -1
  58. package/package.json +18 -16
@@ -1,35 +1,36 @@
1
1
  import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { L as hideClassPrivateProps, R as ipnsNameToIpnsOverPubsubTopic, Sr as logger_default, br as PKCError } from "./schema-0b9XHoqX.js";
3
- import { a as fetchBlockWithStalledSessionFailover, i as directFetchIpnsRecordFromProviders, n as cacheIpnsRecordInPubsubLocalStore, o as getHeliaDebugContext, r as connectToPubsubPeers, s as selectBitswapSessionSeedPeers } from "./util-CvgcZ9iH.js";
2
+ import { L as hideClassPrivateProps, R as ipnsNameToIpnsOverPubsubTopic, Sr as logger_default, br as PKCError } from "./schema-bDrzx9EZ.js";
3
+ import { a as fetchBlockWithStalledSessionFailover, i as directFetchIpnsRecordFromProviders, n as cacheIpnsRecordInPubsubLocalStore, o as getHeliaDebugContext, r as connectToPubsubPeers, s as selectBitswapSessionSeedPeers } from "./util-DuJcVQ7Y.js";
4
4
  import { t as map } from "./src-Cpx2Sts8.js";
5
5
  import { t as parallelBatch } from "./src-DKntVmyX.js";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import fsp, { rename, writeFile } from "node:fs/promises";
8
- import Path, { basename, dirname, join } from "node:path";
9
- import path from "path";
8
+ import path, { basename, dirname, join } from "node:path";
9
+ import path$1 from "path";
10
10
  import { CID } from "multiformats/cid";
11
11
  import { peerIdFromString } from "@libp2p/peer-id";
12
12
  import * as Digest from "multiformats/hashes/digest";
13
13
  import { base32, base32upper } from "multiformats/bases/base32";
14
14
  import { EventEmitter as EventEmitter$1 } from "events";
15
- import { createHelia, libp2pDefaults } from "helia";
16
- import { ipns } from "@helia/ipns";
15
+ import { createHeliaLight } from "helia";
16
+ import { libp2pDefaults, withLibp2p } from "@helia/libp2p";
17
+ import { withBitswap } from "@helia/bitswap";
18
+ import { ipns, pubSubIPNSRouting } from "@helia/ipns";
17
19
  import { multihashToIPNSRoutingKey, unmarshalIPNSRecord } from "ipns";
18
20
  import { ipnsValidator } from "ipns/validator";
19
21
  import { gossipsub } from "@libp2p/gossipsub";
20
22
  import { identify } from "@libp2p/identify";
21
- import { bitswap } from "@helia/block-brokers";
23
+ import { sha512 } from "multiformats/hashes/sha2";
22
24
  import { MemoryBlockstore } from "blockstore-core";
23
25
  import * as raw from "multiformats/codecs/raw";
24
26
  import { delegatedRoutingV1HttpApiClientContentRouting } from "@helia/delegated-routing-v1-http-api-client";
25
27
  import { NotFoundError } from "@libp2p/interface";
26
28
  import { unixfs } from "@helia/unixfs";
27
29
  import { fetch } from "@libp2p/fetch";
28
- import { pubsub } from "@helia/ipns/routing";
29
30
  //#region dist/node/runtime/node/libp2p-extra-transports.js
30
31
  const extraLibp2pTransports = [];
31
32
  //#endregion
32
- //#region node_modules/blockstore-fs/node_modules/interface-store/dist/src/errors.js
33
+ //#region node_modules/interface-store/dist/src/errors.js
33
34
  var OpenFailedError = class OpenFailedError extends Error {
34
35
  static name = "OpenFailedError";
35
36
  name = OpenFailedError.name;
@@ -148,7 +149,7 @@ var require_path = /* @__PURE__ */ __commonJSMin(((exports) => {
148
149
  Object.defineProperty(exports, "__esModule", { value: true });
149
150
  exports.convertPosixPathToPattern = exports.convertWindowsPathToPattern = exports.convertPathToPattern = exports.escapePosixPath = exports.escapeWindowsPath = exports.escape = exports.removeLeadingDotSegment = exports.makeAbsolute = exports.unixify = void 0;
150
151
  const os$1 = __require("os");
151
- const path$9 = __require("path");
152
+ const path$10 = __require("path");
152
153
  const IS_WINDOWS_PLATFORM = os$1.platform() === "win32";
153
154
  const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2;
154
155
  /**
@@ -177,7 +178,7 @@ var require_path = /* @__PURE__ */ __commonJSMin(((exports) => {
177
178
  }
178
179
  exports.unixify = unixify;
179
180
  function makeAbsolute(cwd, filepath) {
180
- return path$9.resolve(cwd, filepath);
181
+ return path$10.resolve(cwd, filepath);
181
182
  }
182
183
  exports.makeAbsolute = makeAbsolute;
183
184
  function removeLeadingDotSegment(entry) {
@@ -1429,7 +1430,7 @@ var require_braces = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1429
1430
  //#endregion
1430
1431
  //#region node_modules/picomatch/lib/constants.js
1431
1432
  var require_constants$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1432
- const path$8 = __require("path");
1433
+ const path$9 = __require("path");
1433
1434
  const WIN_SLASH = "\\\\/";
1434
1435
  const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
1435
1436
  const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
@@ -1554,7 +1555,7 @@ var require_constants$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1554
1555
  CHAR_UNDERSCORE: 95,
1555
1556
  CHAR_VERTICAL_LINE: 124,
1556
1557
  CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
1557
- SEP: path$8.sep,
1558
+ SEP: path$9.sep,
1558
1559
  /**
1559
1560
  * Create EXTGLOB_CHARS
1560
1561
  */
@@ -1598,7 +1599,7 @@ var require_constants$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1598
1599
  //#endregion
1599
1600
  //#region node_modules/picomatch/lib/utils.js
1600
1601
  var require_utils$2 = /* @__PURE__ */ __commonJSMin(((exports) => {
1601
- const path$7 = __require("path");
1602
+ const path$8 = __require("path");
1602
1603
  const win32 = process.platform === "win32";
1603
1604
  const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL } = require_constants$1();
1604
1605
  exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
@@ -1618,7 +1619,7 @@ var require_utils$2 = /* @__PURE__ */ __commonJSMin(((exports) => {
1618
1619
  };
1619
1620
  exports.isWindows = (options) => {
1620
1621
  if (options && typeof options.windows === "boolean") return options.windows;
1621
- return win32 === true || path$7.sep === "\\";
1622
+ return win32 === true || path$8.sep === "\\";
1622
1623
  };
1623
1624
  exports.escapeLast = (input, char, lastIdx) => {
1624
1625
  const idx = input.lastIndexOf(char, lastIdx);
@@ -2988,7 +2989,7 @@ var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2988
2989
  //#endregion
2989
2990
  //#region node_modules/picomatch/lib/picomatch.js
2990
2991
  var require_picomatch$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2991
- const path$6 = __require("path");
2992
+ const path$7 = __require("path");
2992
2993
  const scan = require_scan();
2993
2994
  const parse = require_parse();
2994
2995
  const utils = require_utils$2();
@@ -3127,7 +3128,7 @@ var require_picomatch$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3127
3128
  * @api public
3128
3129
  */
3129
3130
  picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
3130
- return (glob instanceof RegExp ? glob : picomatch.makeRe(glob, options)).test(path$6.basename(input));
3131
+ return (glob instanceof RegExp ? glob : picomatch.makeRe(glob, options)).test(path$7.basename(input));
3131
3132
  };
3132
3133
  /**
3133
3134
  * Returns true if **any** of the given glob `patterns` match the specified `string`.
@@ -3682,7 +3683,7 @@ var require_micromatch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3682
3683
  var require_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
3683
3684
  Object.defineProperty(exports, "__esModule", { value: true });
3684
3685
  exports.isAbsolute = exports.partitionAbsoluteAndRelative = exports.removeDuplicateSlashes = exports.matchAny = exports.convertPatternsToRe = exports.makeRe = exports.getPatternParts = exports.expandBraceExpansion = exports.expandPatternsWithBraceExpansion = exports.isAffectDepthOfReadingPattern = exports.endsWithSlashGlobStar = exports.hasGlobStar = exports.getBaseDirectory = exports.isPatternRelatedToParentDirectory = exports.getPatternsOutsideCurrentDirectory = exports.getPatternsInsideCurrentDirectory = exports.getPositivePatterns = exports.getNegativePatterns = exports.isPositivePattern = exports.isNegativePattern = exports.convertToNegativePattern = exports.convertToPositivePattern = exports.isDynamicPattern = exports.isStaticPattern = void 0;
3685
- const path$5 = __require("path");
3686
+ const path$6 = __require("path");
3686
3687
  const globParent = require_glob_parent();
3687
3688
  const micromatch = require_micromatch();
3688
3689
  const GLOBSTAR = "**";
@@ -3790,7 +3791,7 @@ var require_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
3790
3791
  }
3791
3792
  exports.endsWithSlashGlobStar = endsWithSlashGlobStar;
3792
3793
  function isAffectDepthOfReadingPattern(pattern) {
3793
- const basename = path$5.basename(pattern);
3794
+ const basename = path$6.basename(pattern);
3794
3795
  return endsWithSlashGlobStar(pattern) || isStaticPattern(basename);
3795
3796
  }
3796
3797
  exports.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
@@ -3864,7 +3865,7 @@ var require_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
3864
3865
  }
3865
3866
  exports.partitionAbsoluteAndRelative = partitionAbsoluteAndRelative;
3866
3867
  function isAbsolute(pattern) {
3867
- return path$5.isAbsolute(pattern);
3868
+ return path$6.isAbsolute(pattern);
3868
3869
  }
3869
3870
  exports.isAbsolute = isAbsolute;
3870
3871
  }));
@@ -4492,7 +4493,7 @@ var require_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
4492
4493
  //#region node_modules/@nodelib/fs.scandir/out/settings.js
4493
4494
  var require_settings$2 = /* @__PURE__ */ __commonJSMin(((exports) => {
4494
4495
  Object.defineProperty(exports, "__esModule", { value: true });
4495
- const path$4 = __require("path");
4496
+ const path$5 = __require("path");
4496
4497
  const fsStat = require_out$3();
4497
4498
  const fs = require_fs();
4498
4499
  var Settings = class {
@@ -4500,7 +4501,7 @@ var require_settings$2 = /* @__PURE__ */ __commonJSMin(((exports) => {
4500
4501
  this._options = _options;
4501
4502
  this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
4502
4503
  this.fs = fs.createFileSystemAdapter(this._options.fs);
4503
- this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path$4.sep);
4504
+ this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path$5.sep);
4504
4505
  this.stats = this._getValue(this._options.stats, false);
4505
4506
  this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
4506
4507
  this.fsStatSettings = new fsStat.Settings({
@@ -5094,7 +5095,7 @@ var require_sync$2 = /* @__PURE__ */ __commonJSMin(((exports) => {
5094
5095
  //#region node_modules/@nodelib/fs.walk/out/settings.js
5095
5096
  var require_settings$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
5096
5097
  Object.defineProperty(exports, "__esModule", { value: true });
5097
- const path$3 = __require("path");
5098
+ const path$4 = __require("path");
5098
5099
  const fsScandir = require_out$2();
5099
5100
  var Settings = class {
5100
5101
  constructor(_options = {}) {
@@ -5104,7 +5105,7 @@ var require_settings$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
5104
5105
  this.deepFilter = this._getValue(this._options.deepFilter, null);
5105
5106
  this.entryFilter = this._getValue(this._options.entryFilter, null);
5106
5107
  this.errorFilter = this._getValue(this._options.errorFilter, null);
5107
- this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path$3.sep);
5108
+ this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path$4.sep);
5108
5109
  this.fsScandirSettings = new fsScandir.Settings({
5109
5110
  followSymbolicLinks: this._options.followSymbolicLinks,
5110
5111
  fs: this._options.fs,
@@ -5156,7 +5157,7 @@ var require_out$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
5156
5157
  //#region node_modules/fast-glob/out/readers/reader.js
5157
5158
  var require_reader = /* @__PURE__ */ __commonJSMin(((exports) => {
5158
5159
  Object.defineProperty(exports, "__esModule", { value: true });
5159
- const path$2 = __require("path");
5160
+ const path$3 = __require("path");
5160
5161
  const fsStat = require_out$3();
5161
5162
  const utils = require_utils$1();
5162
5163
  var Reader = class {
@@ -5169,7 +5170,7 @@ var require_reader = /* @__PURE__ */ __commonJSMin(((exports) => {
5169
5170
  });
5170
5171
  }
5171
5172
  _getFullEntryPath(filepath) {
5172
- return path$2.resolve(this._settings.cwd, filepath);
5173
+ return path$3.resolve(this._settings.cwd, filepath);
5173
5174
  }
5174
5175
  _makeEntry(stats, pattern) {
5175
5176
  const entry = {
@@ -5504,7 +5505,7 @@ var require_entry = /* @__PURE__ */ __commonJSMin(((exports) => {
5504
5505
  //#region node_modules/fast-glob/out/providers/provider.js
5505
5506
  var require_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
5506
5507
  Object.defineProperty(exports, "__esModule", { value: true });
5507
- const path$1 = __require("path");
5508
+ const path$2 = __require("path");
5508
5509
  const deep_1 = require_deep();
5509
5510
  const entry_1 = require_entry$1();
5510
5511
  const error_1 = require_error();
@@ -5518,7 +5519,7 @@ var require_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
5518
5519
  this.entryTransformer = new entry_2.default(this._settings);
5519
5520
  }
5520
5521
  _getRootDirectory(task) {
5521
- return path$1.resolve(this._settings.cwd, task.base);
5522
+ return path$2.resolve(this._settings.cwd, task.base);
5522
5523
  }
5523
5524
  _getReaderOptions(task) {
5524
5525
  const basePath = task.base === "." ? "" : task.base;
@@ -5849,7 +5850,7 @@ var import_out = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((export
5849
5850
  * Async iterable filename pattern matcher
5850
5851
  */
5851
5852
  async function* glob(dir, pattern, options = {}) {
5852
- const absoluteDir = Path.resolve(dir);
5853
+ const absoluteDir = path.resolve(dir);
5853
5854
  const stats = await fsp.stat(absoluteDir);
5854
5855
  for await (const entry of import_out.default.stream(pattern, {
5855
5856
  ...options,
@@ -5916,27 +5917,22 @@ async function* glob(dir, pattern, options = {}) {
5916
5917
  function defaultTranslate(signal) {
5917
5918
  return signal.reason;
5918
5919
  }
5919
- /**
5920
- * Race a promise against an abort signal
5921
- */
5922
- async function raceSignal(promise, signal, opts) {
5923
- if (signal == null) return promise;
5920
+ function raceSignal(promise, signal, opts) {
5921
+ if (signal == null || promise == null) return promise;
5924
5922
  const translateError = opts?.translateError ?? defaultTranslate;
5925
5923
  if (signal.aborted) {
5926
5924
  promise.catch(() => {});
5927
5925
  return Promise.reject(translateError(signal));
5928
5926
  }
5929
5927
  let listener;
5930
- try {
5931
- return await Promise.race([promise, new Promise((resolve, reject) => {
5932
- listener = () => {
5933
- reject(translateError(signal));
5934
- };
5935
- signal.addEventListener("abort", listener);
5936
- })]);
5937
- } finally {
5928
+ return Promise.race([promise, new Promise((resolve, reject) => {
5929
+ listener = () => {
5930
+ reject(translateError(signal));
5931
+ };
5932
+ signal.addEventListener("abort", listener);
5933
+ })]).finally(() => {
5938
5934
  if (listener != null) signal.removeEventListener("abort", listener);
5939
- }
5935
+ });
5940
5936
  }
5941
5937
  //#endregion
5942
5938
  //#region node_modules/steno/lib/index.js
@@ -6024,7 +6020,7 @@ var NextToLast = class {
6024
6020
  };
6025
6021
  }
6026
6022
  decode(str) {
6027
- let fileName = Path.basename(str);
6023
+ let fileName = path.basename(str);
6028
6024
  if (fileName.endsWith(this.extension)) fileName = fileName.substring(0, fileName.length - this.extension.length);
6029
6025
  return CID.decode(this.base.decoder.decode(fileName));
6030
6026
  }
@@ -6050,7 +6046,7 @@ var NextToLast = class {
6050
6046
  async function writeFile$1(file, contents, options) {
6051
6047
  try {
6052
6048
  options?.signal?.throwIfAborted();
6053
- await raceSignal(fsp.mkdir(Path.dirname(file), { recursive: true }), options?.signal);
6049
+ await raceSignal(fsp.mkdir(path.dirname(file), { recursive: true }), options?.signal);
6054
6050
  const writer = new Writer(file);
6055
6051
  options?.signal?.throwIfAborted();
6056
6052
  await writer.write(contents);
@@ -6075,7 +6071,7 @@ var FsBlockstore = class {
6075
6071
  deleteManyConcurrency;
6076
6072
  shardingStrategy;
6077
6073
  constructor(location, init = {}) {
6078
- this.path = Path.resolve(location);
6074
+ this.path = path.resolve(location);
6079
6075
  this.createIfMissing = init.createIfMissing ?? true;
6080
6076
  this.errorIfExists = init.errorIfExists ?? false;
6081
6077
  this.deleteManyConcurrency = init.deleteManyConcurrency ?? 50;
@@ -6101,7 +6097,7 @@ var FsBlockstore = class {
6101
6097
  async put(key, val, options) {
6102
6098
  const { dir, file } = this.shardingStrategy.encode(key);
6103
6099
  try {
6104
- await writeFile$1(Path.join(this.path, dir, file), val, options);
6100
+ await writeFile$1(path.join(this.path, dir, file), val, options);
6105
6101
  return key;
6106
6102
  } catch (err) {
6107
6103
  throw new PutFailedError(String(err));
@@ -6120,7 +6116,7 @@ var FsBlockstore = class {
6120
6116
  let handle;
6121
6117
  try {
6122
6118
  options?.signal?.throwIfAborted();
6123
- handle = await raceSignal(fsp.open(Path.join(this.path, dir, file)), options?.signal);
6119
+ handle = await raceSignal(fsp.open(path.join(this.path, dir, file)), options?.signal);
6124
6120
  yield* handle.createReadStream();
6125
6121
  } catch (err) {
6126
6122
  if (handle != null) await raceSignal(handle.close(), options?.signal);
@@ -6141,7 +6137,7 @@ var FsBlockstore = class {
6141
6137
  const { dir, file } = this.shardingStrategy.encode(key);
6142
6138
  try {
6143
6139
  options?.signal?.throwIfAborted();
6144
- await raceSignal(fsp.unlink(Path.join(this.path, dir, file)), options?.signal);
6140
+ await raceSignal(fsp.unlink(path.join(this.path, dir, file)), options?.signal);
6145
6141
  } catch (err) {
6146
6142
  if (err.code === "ENOENT") return;
6147
6143
  throw new DeleteFailedError(String(err));
@@ -6159,14 +6155,14 @@ var FsBlockstore = class {
6159
6155
  const { dir, file } = this.shardingStrategy.encode(key);
6160
6156
  try {
6161
6157
  options?.signal?.throwIfAborted();
6162
- await raceSignal(fsp.access(Path.join(this.path, dir, file)), options?.signal);
6158
+ await raceSignal(fsp.access(path.join(this.path, dir, file)), options?.signal);
6163
6159
  } catch (err) {
6164
6160
  return false;
6165
6161
  }
6166
6162
  return true;
6167
6163
  }
6168
6164
  async *getAll(options) {
6169
- const pattern = `**/*${this.shardingStrategy.extension}`.split(Path.sep).join("/");
6165
+ const pattern = `**/*${this.shardingStrategy.extension}`.split(path.sep).join("/");
6170
6166
  const files = glob(this.path, pattern, { absolute: true });
6171
6167
  for await (const file of files) try {
6172
6168
  options?.signal?.throwIfAborted();
@@ -6218,7 +6214,7 @@ async function createBlockstoreForLibp2pJsClient({ dataPath, key }) {
6218
6214
  defaultMaxBytes: DEFAULT_IN_MEMORY_BLOCKSTORE_MAX_BYTES,
6219
6215
  close: async () => {}
6220
6216
  };
6221
- const store = new FsBlockstore(path.join(dataPath, "blockstore", key));
6217
+ const store = new FsBlockstore(path$1.join(dataPath, "blockstore", key));
6222
6218
  await store.open();
6223
6219
  return {
6224
6220
  blockstore: store,
@@ -6497,6 +6493,12 @@ function getDelegatedRoutingFields(routers) {
6497
6493
  }
6498
6494
  return routersObj;
6499
6495
  }
6496
+ function ipnsRouterTag(router) {
6497
+ return String(router);
6498
+ }
6499
+ function isLocalStoreIpnsRouter(router) {
6500
+ return ipnsRouterTag(router) === "LocalStoreRouting()";
6501
+ }
6500
6502
  async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6501
6503
  if (!pkcOptions.httpRoutersOptions?.length) throw Error("You need to have pkc.httpRouterOptions to set up helia");
6502
6504
  const existingClient = libp2pJsClients[pkcOptions.key];
@@ -6510,9 +6512,10 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6510
6512
  client.countOfUsesOfInstance++;
6511
6513
  return client;
6512
6514
  }
6515
+ let startedHelia;
6516
+ let closeBlockstore = async () => {};
6513
6517
  creatingLibp2pJsClients[pkcOptions.key] = (async () => {
6514
6518
  let lruBlockstore;
6515
- let closeBlockstore = async () => {};
6516
6519
  if (!pkcOptions.heliaOptions?.blockstore) {
6517
6520
  const { blockstore: childBlockstore, persistent, defaultMaxBytes, close } = await createBlockstoreForLibp2pJsClient({
6518
6521
  dataPath: pkcOptions.dataPath,
@@ -6542,12 +6545,17 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6542
6545
  }
6543
6546
  },
6544
6547
  blockstore: lruBlockstore,
6545
- blockBrokers: [bitswap()],
6546
- start: false,
6547
6548
  ...pkcOptions.heliaOptions
6548
6549
  };
6549
- const helia = await createHelia(mergedHeliaInit);
6550
- helia.routing.routers = helia.routing.routers.filter((r) => r.constructor.name !== "HTTPGatewayRouter");
6550
+ const { libp2p: mergedLibp2pInit, bitswap: bitswapInit, blockBrokers: callerBlockBrokers, ...heliaLightInit } = mergedHeliaInit;
6551
+ const heliaWithLibp2p = withLibp2p(createHeliaLight({
6552
+ ...heliaLightInit,
6553
+ blockBrokers: callerBlockBrokers,
6554
+ hashers: [sha512, ...heliaLightInit.hashers ?? []]
6555
+ }), mergedLibp2pInit ?? {});
6556
+ const helia = callerBlockBrokers === void 0 ? withBitswap(heliaWithLibp2p, bitswapInit) : heliaWithLibp2p;
6557
+ startedHelia = helia;
6558
+ await helia.start();
6551
6559
  log("Initialized libp2pjs helia with key", pkcOptions.key, "peer id", helia.libp2p.peerId.toString());
6552
6560
  const pubsubEventHandler = new EventEmitter$1();
6553
6561
  helia.libp2p.services.pubsub.addEventListener("message", (evt) => {
@@ -6560,10 +6568,6 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6560
6568
  pubsubEventHandler.emit(evt.detail.topic, msgFormatted);
6561
6569
  });
6562
6570
  const heliaFs = unixfs(helia);
6563
- const asHeliaCatCid = (ipfsPathOrCid) => {
6564
- CID.parse(ipfsPathOrCid.split("/")[0]);
6565
- return ipfsPathOrCid;
6566
- };
6567
6571
  const MAX_BITSWAP_SESSION_SEED_PEERS = 3;
6568
6572
  const getBitswapSessionSeedPeers = (scopeIpnsPubsubTopic) => {
6569
6573
  const pubsub = helia.libp2p.services.pubsub;
@@ -6616,10 +6620,12 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6616
6620
  }, ms);
6617
6621
  signal.addEventListener("abort", onAbort, { once: true });
6618
6622
  });
6619
- const ipnsPubsubRouter = pubsub(helia);
6620
- const ipnsPubsubLocalStore = ipnsPubsubRouter.localStore;
6623
+ const ipnsPubsubRouter = pubSubIPNSRouting(helia);
6621
6624
  const ipnsNameResolver = ipns(helia, { routers: [ipnsPubsubRouter] });
6622
- ipnsNameResolver.routers = ipnsNameResolver.routers.filter((r) => r?.constructor?.name !== "LocalStoreRouting");
6625
+ for (let i = ipnsNameResolver.routers.length - 1; i >= 0; i--) if (isLocalStoreIpnsRouter(ipnsNameResolver.routers[i])) ipnsNameResolver.routers.splice(i, 1);
6626
+ ipnsNameResolver.start?.();
6627
+ await ipnsPubsubRouter.start?.();
6628
+ const ipnsPubsubLocalStore = ipnsPubsubRouter.localStore;
6623
6629
  const WARMUP_MAX_PEERS = 4;
6624
6630
  const warmupPromisesByTopic = /* @__PURE__ */ new Map();
6625
6631
  const warmupForTopic = (topic, options) => {
@@ -6758,7 +6764,9 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6758
6764
  } },
6759
6765
  cat(ipfsPath, options) {
6760
6766
  throwIfHeliaIsStoppingOrStopped();
6761
- const rootCid = CID.parse(ipfsPath.split("/")[0]);
6767
+ const [rootCidString, ...ipfsSubPathSegments] = ipfsPath.split("/");
6768
+ const rootCid = CID.parse(rootCidString);
6769
+ const ipfsSubPath = ipfsSubPathSegments.length > 0 ? ipfsSubPathSegments.join("/") : void 0;
6762
6770
  const timeoutMs = parseKuboStyleTimeoutMs(options?.timeout);
6763
6771
  const { bitswapSessionSeedScopeIpnsPubsubTopic, ...unixfsCatOptions } = options ?? {};
6764
6772
  return (async function* () {
@@ -6773,7 +6781,7 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6773
6781
  })), timeoutMs) : void 0;
6774
6782
  try {
6775
6783
  for (let attempt = 0;; attempt++) {
6776
- const session = helia.blockstore.createSession(rootCid, { providers: getBitswapSessionSeedPeers(bitswapSessionSeedScopeIpnsPubsubTopic) });
6784
+ const session = helia.blockstore.createSession(rootCid, { providers: getBitswapSessionSeedPeers(bitswapSessionSeedScopeIpnsPubsubTopic).map((peerId) => peerId.toCID()) });
6777
6785
  const sessionGet = session.get.bind(session);
6778
6786
  const fallbackGet = helia.blockstore.get.bind(helia.blockstore);
6779
6787
  session.get = (blockCid, blockGetOptions) => fetchBlockWithStalledSessionFailover({
@@ -6786,8 +6794,9 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6786
6794
  });
6787
6795
  let yieldedAnyBytes = false;
6788
6796
  try {
6789
- const catIterable = unixfs({ blockstore: session }).cat(asHeliaCatCid(ipfsPath), {
6797
+ const catIterable = unixfs({ blockstore: session }).cat(rootCid, {
6790
6798
  ...unixfsCatOptions,
6799
+ path: ipfsSubPath,
6791
6800
  signal: controller.signal
6792
6801
  });
6793
6802
  for await (const chunk of catIterable) {
@@ -6859,7 +6868,7 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6859
6868
  if (typeof lifecycle.stop === "function") try {
6860
6869
  await lifecycle.stop();
6861
6870
  } catch (e) {
6862
- log.error("Error stopping IPNS router", router?.constructor?.name, e);
6871
+ log.error("Error stopping IPNS router", ipnsRouterTag(router), e);
6863
6872
  }
6864
6873
  }
6865
6874
  for (const topic of helia.libp2p.services.pubsub.getTopics()) helia.libp2p.services.pubsub.unsubscribe(topic);
@@ -6898,11 +6907,33 @@ async function createLibp2pJsClientOrUseExistingOne(pkcOptions) {
6898
6907
  libp2pJsClientsOptions: pkcOptions,
6899
6908
  key: pkcOptions.key
6900
6909
  });
6901
- await helia.start();
6902
6910
  log("Helia/libp2p-js started with key", pkcOptions.key, "and peer id", helia.libp2p.peerId.toString());
6903
6911
  libp2pJsClients[pkcOptions.key] = client;
6904
6912
  return client;
6905
- })();
6913
+ })().catch(async (creationError) => {
6914
+ if (startedHelia) {
6915
+ let connections = [];
6916
+ try {
6917
+ connections = startedHelia.libp2p.getConnections();
6918
+ } catch {}
6919
+ for (const connection of connections) try {
6920
+ connection.abort(/* @__PURE__ */ new Error("pkc-js libp2p instance failed to initialize"));
6921
+ } catch (e) {
6922
+ log.error("Error aborting libp2p connection during failed initialization", e);
6923
+ }
6924
+ try {
6925
+ await startedHelia.stop();
6926
+ } catch (e) {
6927
+ log.error("Error stopping helia after failed initialization", e);
6928
+ }
6929
+ }
6930
+ try {
6931
+ await closeBlockstore();
6932
+ } catch (e) {
6933
+ log.error("Error closing blockstore after failed initialization", e);
6934
+ }
6935
+ throw creationError;
6936
+ });
6906
6937
  const createdClientPromise = creatingLibp2pJsClients[pkcOptions.key];
6907
6938
  if (!createdClientPromise) throw new Error("Missing creation promise after initialization");
6908
6939
  try {
@@ -1,2 +1,2 @@
1
- import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-Ba5iR3bD.js";
1
+ import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-D5fzgPCr.js";
2
2
  export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };