@pkcprotocol/pkc-js 0.0.44 → 0.0.46

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 (148) hide show
  1. package/README.md +41 -0
  2. package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +2 -1
  3. package/dist/browser/clients/rpc-client/pkc-rpc-client.js +5 -1
  4. package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  5. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +96 -0
  6. package/dist/browser/clients/rpc-client/rpc-schema-util.js +4 -1
  7. package/dist/browser/clients/rpc-client/rpc-schema-util.js.map +1 -1
  8. package/dist/browser/clients/rpc-client/schema.d.ts +89 -2
  9. package/dist/browser/clients/rpc-client/schema.js +10 -1
  10. package/dist/browser/clients/rpc-client/schema.js.map +1 -1
  11. package/dist/browser/clients/rpc-client/types.d.ts +3 -1
  12. package/dist/browser/community/remote-community.d.ts +5 -1
  13. package/dist/browser/community/remote-community.js +6 -0
  14. package/dist/browser/community/remote-community.js.map +1 -1
  15. package/dist/browser/community/rpc-local-community.d.ts +5 -1
  16. package/dist/browser/community/rpc-local-community.js +3 -0
  17. package/dist/browser/community/rpc-local-community.js.map +1 -1
  18. package/dist/browser/community/schema.d.ts +28 -18
  19. package/dist/browser/community/schema.js +8 -0
  20. package/dist/browser/community/schema.js.map +1 -1
  21. package/dist/browser/community/types.d.ts +2 -1
  22. package/dist/browser/generated-version.d.ts +1 -1
  23. package/dist/browser/generated-version.js +1 -1
  24. package/dist/browser/index-with-compile-cache.d.ts +254 -0
  25. package/dist/browser/index-with-compile-cache.js +25 -0
  26. package/dist/browser/index-with-compile-cache.js.map +1 -0
  27. package/dist/browser/pages/schema.d.ts +5 -5
  28. package/dist/browser/pkc/pkc.d.ts +3 -4
  29. package/dist/browser/pkc/pkc.js +16 -19
  30. package/dist/browser/pkc/pkc.js.map +1 -1
  31. package/dist/browser/publications/comment/schema.d.ts +2 -2
  32. package/dist/browser/publications/comment/schema.js +7 -1
  33. package/dist/browser/publications/comment/schema.js.map +1 -1
  34. package/dist/browser/rpc/src/index.d.ts +2 -1
  35. package/dist/browser/rpc/src/index.js +30 -2
  36. package/dist/browser/rpc/src/index.js.map +1 -1
  37. package/dist/browser/runtime/browser/compile-cache.d.ts +1 -0
  38. package/dist/browser/runtime/browser/compile-cache.js +7 -0
  39. package/dist/browser/runtime/browser/compile-cache.js.map +1 -0
  40. package/dist/browser/runtime/browser/setup-kubo-http-routers.d.ts +1 -0
  41. package/dist/browser/runtime/browser/setup-kubo-http-routers.js +4 -0
  42. package/dist/browser/runtime/browser/setup-kubo-http-routers.js.map +1 -0
  43. package/dist/browser/runtime/node/community/db-handler.d.ts +4 -2
  44. package/dist/browser/runtime/node/community/db-handler.js +30 -1
  45. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  46. package/dist/browser/runtime/node/community/db-row-parser.d.ts +2 -0
  47. package/dist/browser/runtime/node/community/db-row-parser.js +6 -0
  48. package/dist/browser/runtime/node/community/db-row-parser.js.map +1 -1
  49. package/dist/browser/runtime/node/community/local-community.d.ts +5 -1
  50. package/dist/browser/runtime/node/community/local-community.js +12 -0
  51. package/dist/browser/runtime/node/community/local-community.js.map +1 -1
  52. package/dist/browser/runtime/node/compile-cache.d.ts +1 -0
  53. package/dist/browser/runtime/node/compile-cache.js +29 -0
  54. package/dist/browser/runtime/node/compile-cache.js.map +1 -0
  55. package/dist/browser/runtime/node/setup-kubo-http-routers.d.ts +2 -0
  56. package/dist/browser/runtime/node/{setup-kubo-address-rewriter-and-http-router.js → setup-kubo-http-routers.js} +10 -79
  57. package/dist/browser/runtime/node/setup-kubo-http-routers.js.map +1 -0
  58. package/dist/bundled/bundle-manifest.json +1288 -0
  59. package/dist/bundled/challenges.js +1 -0
  60. package/dist/bundled/chunks/helia-for-pkc-uRINWDzG.js +281 -0
  61. package/dist/bundled/chunks/local-community-CCSP8e6_.js +2 -0
  62. package/dist/bundled/chunks/local-community-iVvgerOY.js +7218 -0
  63. package/dist/bundled/chunks/node-DMNVMYGv.js +7567 -0
  64. package/dist/bundled/chunks/rpc-local-community-DG6G0xL6.js +128945 -0
  65. package/dist/bundled/chunks/schema-Bo3XK8Oe.js +34342 -0
  66. package/dist/bundled/chunks/util-I3gVOp6w.js +200 -0
  67. package/dist/bundled/index-with-compile-cache.js +19 -0
  68. package/dist/bundled/index.js +2 -0
  69. package/dist/bundled/rpc/src/index.js +1473 -0
  70. package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +2 -1
  71. package/dist/node/clients/rpc-client/pkc-rpc-client.js +5 -1
  72. package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
  73. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +96 -0
  74. package/dist/node/clients/rpc-client/rpc-schema-util.js +4 -1
  75. package/dist/node/clients/rpc-client/rpc-schema-util.js.map +1 -1
  76. package/dist/node/clients/rpc-client/schema.d.ts +89 -2
  77. package/dist/node/clients/rpc-client/schema.js +10 -1
  78. package/dist/node/clients/rpc-client/schema.js.map +1 -1
  79. package/dist/node/clients/rpc-client/types.d.ts +3 -1
  80. package/dist/node/community/remote-community.d.ts +5 -1
  81. package/dist/node/community/remote-community.js +6 -0
  82. package/dist/node/community/remote-community.js.map +1 -1
  83. package/dist/node/community/rpc-local-community.d.ts +5 -1
  84. package/dist/node/community/rpc-local-community.js +3 -0
  85. package/dist/node/community/rpc-local-community.js.map +1 -1
  86. package/dist/node/community/schema.d.ts +28 -18
  87. package/dist/node/community/schema.js +8 -0
  88. package/dist/node/community/schema.js.map +1 -1
  89. package/dist/node/community/types.d.ts +2 -1
  90. package/dist/node/generated-version.d.ts +1 -1
  91. package/dist/node/generated-version.js +1 -1
  92. package/dist/node/index-with-compile-cache.d.ts +254 -0
  93. package/dist/node/index-with-compile-cache.js +25 -0
  94. package/dist/node/index-with-compile-cache.js.map +1 -0
  95. package/dist/node/pages/schema.d.ts +5 -5
  96. package/dist/node/pkc/pkc.d.ts +3 -4
  97. package/dist/node/pkc/pkc.js +16 -19
  98. package/dist/node/pkc/pkc.js.map +1 -1
  99. package/dist/node/publications/comment/schema.d.ts +2 -2
  100. package/dist/node/publications/comment/schema.js +7 -1
  101. package/dist/node/publications/comment/schema.js.map +1 -1
  102. package/dist/node/rpc/src/index.d.ts +2 -1
  103. package/dist/node/rpc/src/index.js +30 -2
  104. package/dist/node/rpc/src/index.js.map +1 -1
  105. package/dist/node/runtime/browser/compile-cache.d.ts +1 -0
  106. package/dist/node/runtime/browser/compile-cache.js +7 -0
  107. package/dist/node/runtime/browser/compile-cache.js.map +1 -0
  108. package/dist/node/runtime/browser/setup-kubo-http-routers.d.ts +1 -0
  109. package/dist/node/runtime/browser/setup-kubo-http-routers.js +4 -0
  110. package/dist/node/runtime/browser/setup-kubo-http-routers.js.map +1 -0
  111. package/dist/node/runtime/node/community/db-handler.d.ts +4 -2
  112. package/dist/node/runtime/node/community/db-handler.js +30 -1
  113. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  114. package/dist/node/runtime/node/community/db-row-parser.d.ts +2 -0
  115. package/dist/node/runtime/node/community/db-row-parser.js +6 -0
  116. package/dist/node/runtime/node/community/db-row-parser.js.map +1 -1
  117. package/dist/node/runtime/node/community/local-community.d.ts +5 -1
  118. package/dist/node/runtime/node/community/local-community.js +12 -0
  119. package/dist/node/runtime/node/community/local-community.js.map +1 -1
  120. package/dist/node/runtime/node/compile-cache.d.ts +1 -0
  121. package/dist/node/runtime/node/compile-cache.js +29 -0
  122. package/dist/node/runtime/node/compile-cache.js.map +1 -0
  123. package/dist/node/runtime/node/setup-kubo-http-routers.d.ts +2 -0
  124. package/dist/node/runtime/node/{setup-kubo-address-rewriter-and-http-router.js → setup-kubo-http-routers.js} +10 -79
  125. package/dist/node/runtime/node/setup-kubo-http-routers.js.map +1 -0
  126. package/package.json +18 -9
  127. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +0 -1
  128. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +0 -4
  129. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
  130. package/dist/browser/runtime/node/address-rewriter-db.d.ts +0 -31
  131. package/dist/browser/runtime/node/address-rewriter-db.js +0 -156
  132. package/dist/browser/runtime/node/address-rewriter-db.js.map +0 -1
  133. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.d.ts +0 -45
  134. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js +0 -493
  135. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js.map +0 -1
  136. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +0 -4
  137. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
  138. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +0 -1
  139. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +0 -4
  140. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
  141. package/dist/node/runtime/node/address-rewriter-db.d.ts +0 -31
  142. package/dist/node/runtime/node/address-rewriter-db.js +0 -156
  143. package/dist/node/runtime/node/address-rewriter-db.js.map +0 -1
  144. package/dist/node/runtime/node/addresses-rewriter-proxy-server.d.ts +0 -45
  145. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js +0 -493
  146. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js.map +0 -1
  147. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +0 -4
  148. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
@@ -0,0 +1,29 @@
1
+ // Enables Node's on-disk V8 compile cache (issue #120). Caching the compiled bytecode
2
+ // recovers the parse/compile portion of import time (~29% of the post-lazy-load cost) on
3
+ // every run after the first.
4
+ //
5
+ // V8 only caches modules compiled AFTER the cache is enabled — and Node's ESM loader
6
+ // compiles the entire static import graph before any module body runs. So calling this
7
+ // from inside index.ts would never cover the package's own graph; it must be called from
8
+ // a thin bootstrap entry (index-with-compile-cache.ts) BEFORE the real entry is
9
+ // dynamic-imported.
10
+ //
11
+ // Designed to be a quiet optimization, never fatal:
12
+ // - no-op on Node < 22.8 (enableCompileCache doesn't exist there; engines allows >= 22)
13
+ // - cache dir is Node's default (os.tmpdir()/node-compile-cache), overridable with the
14
+ // NODE_COMPILE_CACHE env var; consumers can opt out with NODE_DISABLE_COMPILE_CACHE=1
15
+ // - enableCompileCache itself reports failures via its return value instead of throwing,
16
+ // but we still guard with try/catch in case of exotic runtimes
17
+ // Default import, not a named import: named imports of builtins are validated at link
18
+ // time, so `import { enableCompileCache }` would throw on Node 22.0-22.7.
19
+ import nodeModule from "node:module";
20
+ export function enableNodeCompileCache() {
21
+ try {
22
+ if (typeof nodeModule.enableCompileCache === "function")
23
+ nodeModule.enableCompileCache();
24
+ }
25
+ catch {
26
+ // compile cache is an optimization only — never let it break startup
27
+ }
28
+ }
29
+ //# sourceMappingURL=compile-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile-cache.js","sourceRoot":"","sources":["../../../../src/runtime/node/compile-cache.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,yFAAyF;AACzF,6BAA6B;AAC7B,EAAE;AACF,qFAAqF;AACrF,uFAAuF;AACvF,yFAAyF;AACzF,gFAAgF;AAChF,oBAAoB;AACpB,EAAE;AACF,oDAAoD;AACpD,wFAAwF;AACxF,uFAAuF;AACvF,wFAAwF;AACxF,yFAAyF;AACzF,iEAAiE;AAEjE,sFAAsF;AACtF,0EAA0E;AAC1E,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,MAAM,UAAU,sBAAsB;IAClC,IAAI,CAAC;QACD,IAAI,OAAO,UAAU,CAAC,kBAAkB,KAAK,UAAU;YAAE,UAAU,CAAC,kBAAkB,EAAE,CAAC;IAC7F,CAAC;IAAC,MAAM,CAAC;QACL,qEAAqE;IACzE,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { PKC } from "../../pkc/pkc.js";
2
+ export declare function setupKuboHttpRouters(pkc: PKC): Promise<void>;
@@ -1,9 +1,7 @@
1
1
  import retry from "retry";
2
- import { AddressesRewriterProxyServer } from "./addresses-rewriter-proxy-server.js";
3
2
  import Logger from "../../logger.js";
4
3
  import { PKCError } from "../../pkc-error.js";
5
4
  import * as remeda from "remeda";
6
- import tcpPortUsed from "tcp-port-used";
7
5
  function _mergeRouterConfigs(existingConfig, newConfig) {
8
6
  if (!existingConfig?.Routers)
9
7
  return newConfig;
@@ -107,85 +105,21 @@ async function _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue) {
107
105
  }
108
106
  }
109
107
  }
110
- async function _getStartedProxyUrl(pkc, httpRouterUrl) {
108
+ export async function setupKuboHttpRouters(pkc) {
111
109
  if (pkc.destroyed)
112
- return undefined;
113
- const mappingKeyName = `httprouter_proxy_${httpRouterUrl}`;
114
- try {
115
- const urlOfProxyOfHttpRouter = await pkc._storage.getItem(mappingKeyName);
116
- if (pkc.destroyed)
117
- return undefined;
118
- if (urlOfProxyOfHttpRouter) {
119
- const proxyHttpUrl = new URL(urlOfProxyOfHttpRouter);
120
- if (await tcpPortUsed.check(Number(proxyHttpUrl.port), "127.0.0.1"))
121
- return urlOfProxyOfHttpRouter;
122
- if (pkc.destroyed)
123
- return undefined;
124
- await pkc._storage.removeItem(mappingKeyName);
125
- }
126
- return undefined;
127
- }
128
- catch (error) {
129
- if (pkc.destroyed && error instanceof Error && error.message.includes("database connection is not open")) {
130
- return undefined;
131
- }
132
- throw error;
133
- }
134
- }
135
- export async function setupKuboAddressesRewriterAndHttpRouters(pkc) {
136
- if (pkc.destroyed) {
137
- return {
138
- destroy: async () => { }
139
- };
140
- }
110
+ return;
141
111
  if (!Array.isArray(pkc.kuboRpcClientsOptions) || pkc.kuboRpcClientsOptions.length <= 0)
142
112
  throw Error("need ipfs http client to be defined");
143
113
  if (!Array.isArray(pkc.httpRoutersOptions) || pkc.httpRoutersOptions.length <= 0)
144
114
  throw Error("Need http router options to defined");
145
- const log = Logger("pkc-js:node:setupKuboAddressesRewriterAndHttpRouters");
146
- // Set up http proxies first to rewrite addresses
147
- const httpRouterProxyUrls = [];
148
- const proxyServers = [];
149
- let addressesRewriterStartPort = 19575; // use port 19575 as first port, looks like IPRTR (IPFS ROUTER)
150
- for (const httpRouter of pkc.httpRoutersOptions) {
151
- if (pkc.destroyed)
152
- break;
153
- const startedProxyUrl = await _getStartedProxyUrl(pkc, httpRouter);
154
- if (startedProxyUrl) {
155
- httpRouterProxyUrls.push(startedProxyUrl);
156
- continue;
157
- }
158
- // launch the proxy server
159
- let port = addressesRewriterStartPort;
160
- const hostname = "127.0.0.1";
161
- while (await tcpPortUsed.check(port, hostname))
162
- // keep increasing port till we find an empty port
163
- port++;
164
- const addressesRewriterProxyServer = new AddressesRewriterProxyServer({
165
- kuboClients: Object.values(pkc.clients.kuboRpcClients).map((kubo) => kubo._client),
166
- port,
167
- hostname,
168
- proxyTargetUrl: httpRouter,
169
- pkc
170
- });
171
- await addressesRewriterProxyServer.listen();
172
- if (pkc.destroyed) {
173
- await addressesRewriterProxyServer.destroy();
174
- break;
175
- }
176
- proxyServers.push(addressesRewriterProxyServer);
177
- // save the proxy urls to use them later
178
- const httpRouterProxyUrl = `http://${hostname}:${port}`;
179
- httpRouterProxyUrls.push(httpRouterProxyUrl);
180
- }
181
- httpRouterProxyUrls.sort(); // make sure it's always the same order
182
- // Set up http routers to use proxies
115
+ const httpRouterUrls = [...pkc.httpRoutersOptions].sort(); // make sure it's always the same order
116
+ // Set up http routers directly on the kubo nodes
183
117
  const kuboClients = pkc.clients.kuboRpcClients;
184
118
  const httpRoutersConfig = {
185
119
  HttpRoutersParallel: { Type: "parallel", Parameters: { Routers: [] } },
186
120
  HttpRouterNotSupported: { Type: "http", Parameters: { Endpoint: "http://kubohttprouternotsupported" } }
187
121
  };
188
- for (const [i, httpRouterUrl] of httpRouterProxyUrls.entries()) {
122
+ for (const [i, httpRouterUrl] of httpRouterUrls.entries()) {
189
123
  const RouterName = `HttpRouter${i + 1}`;
190
124
  httpRoutersConfig[RouterName] = {
191
125
  Type: "http",
@@ -215,6 +149,10 @@ export async function setupKuboAddressesRewriterAndHttpRouters(pkc) {
215
149
  const settingOptionRetryOption = retry.operation({ forever: true, factor: 2 });
216
150
  const setHttpRouterOnAllNodes = new Promise((resolve) => {
217
151
  settingOptionRetryOption.attempt(async (curAttempt) => {
152
+ if (pkc.destroyed) {
153
+ resolve(1);
154
+ return;
155
+ }
218
156
  for (const kuboClient of Object.values(kuboClients)) {
219
157
  try {
220
158
  await _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue);
@@ -229,12 +167,5 @@ export async function setupKuboAddressesRewriterAndHttpRouters(pkc) {
229
167
  });
230
168
  await setHttpRouterOnAllNodes;
231
169
  settingOptionRetryOption.stop();
232
- return {
233
- destroy: async () => {
234
- for (const proxyServer of proxyServers) {
235
- await proxyServer.destroy();
236
- }
237
- }
238
- };
239
170
  }
240
- //# sourceMappingURL=setup-kubo-address-rewriter-and-http-router.js.map
171
+ //# sourceMappingURL=setup-kubo-http-routers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-kubo-http-routers.js","sourceRoot":"","sources":["../../../../src/runtime/node/setup-kubo-http-routers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,SAAS,mBAAmB,CAAC,cAAmB,EAAE,SAAc;IAC5D,IAAI,CAAC,cAAc,EAAE,OAAO;QAAE,OAAO,SAAS,CAAC;IAE/C,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAAE,CAAC;IAC5C,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,OAAO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B,CAAC;IAEF,MAAM,wBAAwB,GAAG,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IAE/E,MAAM,uBAAuB,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACpD,wBAAwB,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YAClD,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;gBAChB,OAAO,CAAC,CAAC,CAAC,CAAC;gBACX,OAAO;YACX,CAAC;YACD,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;gBAClD,IAAI,CAAC;oBACD,MAAM,+BAA+B,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;gBACpE,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,wBAAwB,CAAC,KAAK,CAAQ,CAAC,CAAC,CAAC;oBACzC,OAAO;gBACX,CAAC;YACL,CAAC;YACD,OAAO,CAAC,CAAC,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,uBAAuB,CAAC;IAC9B,wBAAwB,CAAC,IAAI,EAAE,CAAC;AACpC,CAAC"}
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@pkcprotocol/pkc-js",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "node config/generate-version.js",
7
- "build": "npm run clean && run-s build:node build:browser verify:browser-imports",
7
+ "build": "npm run clean && run-s build:node build:browser verify:browser-imports build:node:bundle verify:bundle",
8
8
  "build:node": "tsc --project config/tsconfig.json",
9
+ "build:node:bundle": "node config/build-node-bundle.js",
10
+ "verify:bundle": "node config/verify-bundle.js",
9
11
  "build:node:watch": "tsc --project config/tsconfig.json --watch",
10
12
  "build:browser": "node config/build-browser",
11
13
  "build:browser:watch": "node config/build-browser --watch",
@@ -36,7 +38,7 @@
36
38
  "release": "HUSKY=0 release-it --config config/.release-it.json",
37
39
  "prepare": "husky"
38
40
  },
39
- "main": "dist/node/index.js",
41
+ "main": "dist/bundled/index.js",
40
42
  "types": "dist/node/index.d.ts",
41
43
  "browser": {
42
44
  ".": "dist/browser/index.js"
@@ -48,19 +50,19 @@
48
50
  ".": {
49
51
  "types": "./dist/node/index.d.ts",
50
52
  "browser": "./dist/browser/index.js",
51
- "import": "./dist/node/index.js",
52
- "require": "./dist/node/index.js"
53
+ "import": "./dist/bundled/index-with-compile-cache.js",
54
+ "require": "./dist/bundled/index.js"
53
55
  },
54
56
  "./challenges": {
55
57
  "types": "./dist/node/challenges.d.ts",
56
58
  "browser": null,
57
- "import": "./dist/node/challenges.js"
59
+ "import": "./dist/bundled/challenges.js"
58
60
  },
59
61
  "./rpc": {
60
62
  "types": "./dist/node/rpc/src/index.d.ts",
61
63
  "browser": null,
62
- "import": "./dist/node/rpc/src/index.js",
63
- "require": "./dist/node/rpc/src/index.js"
64
+ "import": "./dist/bundled/rpc/src/index.js",
65
+ "require": "./dist/bundled/rpc/src/index.js"
64
66
  }
65
67
  },
66
68
  "dependencies": {
@@ -83,10 +85,13 @@
83
85
  "blockstore-core": "6.1.2",
84
86
  "buffer": "6.0.3",
85
87
  "cbor": "10.0.11",
88
+ "cborg": "4.5.8",
86
89
  "debounce": "1.2.1",
87
90
  "ext-name": "5.0.0",
88
91
  "helia": "6.1.4",
89
92
  "hpagent": "1.2.0",
93
+ "ipfs-unixfs-importer": "16.1.4",
94
+ "ipns": "10.1.3",
90
95
  "it-all": "3.0.6",
91
96
  "js-sha256": "0.11.1",
92
97
  "js-sha512": "0.9.0",
@@ -95,6 +100,8 @@
95
100
  "localforage": "1.10.0",
96
101
  "lodash.merge": "4.6.2",
97
102
  "lru-cache": "10.1.0",
103
+ "multiformats": "13.4.2",
104
+ "node-forge": "1.4.0",
98
105
  "open-graph-scraper": "6.11.0",
99
106
  "p-limit": "7.3.0",
100
107
  "p-retry": "8.0.0",
@@ -104,11 +111,11 @@
104
111
  "retry": "0.13.1",
105
112
  "rpc-websockets": "9.3.8",
106
113
  "safe-stable-stringify": "2.4.3",
107
- "tcp-port-used": "1.0.2",
108
114
  "tiny-typed-emitter": "2.1.0",
109
115
  "tinycache": "1.1.2",
110
116
  "ts-custom-error": "3.3.1",
111
117
  "typestub-ipfs-only-hash": "4.0.0",
118
+ "uint8arrays": "5.1.0",
112
119
  "uuid": "13.0.0",
113
120
  "zod": "4.3.6"
114
121
  },
@@ -140,8 +147,10 @@
140
147
  "prettier": "3.2.4",
141
148
  "release-it": "19.2.4",
142
149
  "rimraf": "6.1.3",
150
+ "rolldown": "1.1.0",
143
151
  "socket.io": "4.8.1",
144
152
  "socket.io-client": "4.8.1",
153
+ "tcp-port-used": "1.0.2",
145
154
  "tempy": "3.2.0",
146
155
  "typescript": "5.9.3",
147
156
  "vitest": "4.0.15",
@@ -1 +0,0 @@
1
- export declare function setupKuboAddressesRewriterAndHttpRouters(): void;
@@ -1,4 +0,0 @@
1
- export function setupKuboAddressesRewriterAndHttpRouters() {
2
- throw Error("Should not be called in browser");
3
- }
4
- //# sourceMappingURL=setup-kubo-address-rewriter-and-http-router.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup-kubo-address-rewriter-and-http-router.js","sourceRoot":"","sources":["../../../../src/runtime/browser/setup-kubo-address-rewriter-and-http-router.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,wCAAwC;IACpD,MAAM,KAAK,CAAC,iCAAiC,CAAC,CAAC;AACnD,CAAC"}
@@ -1,31 +0,0 @@
1
- export type RequestLogEntry = {
2
- keys: string[];
3
- receivedAt: number;
4
- transmittedAt?: number;
5
- success: boolean;
6
- statusCode?: number;
7
- method: string;
8
- url: string;
9
- error?: string;
10
- retryCount?: number;
11
- bodyPreview?: string;
12
- };
13
- export type ReprovideLogEntry = {
14
- key: string;
15
- timestamp: number;
16
- success: boolean;
17
- error?: string;
18
- blockNotLocal?: boolean;
19
- };
20
- export declare class AddressRewriterDatabase {
21
- private _db;
22
- private _dbPath;
23
- constructor(dataPath: string, kuboConfig: any, proxyTarget: URL);
24
- private _initializeDbPath;
25
- initialize(): Promise<void>;
26
- close(): void;
27
- insertRequestLogs(logs: RequestLogEntry[]): void;
28
- insertReprovideLog(key: string, success: boolean, error?: string, blockNotLocal?: boolean): void;
29
- loadFailedKeys(): string[];
30
- saveFailedKeys(keys: string[]): void;
31
- }
@@ -1,156 +0,0 @@
1
- import path from "node:path";
2
- import fs from "node:fs/promises";
3
- import Database from "better-sqlite3";
4
- import Logger from "../../logger.js";
5
- const debug = Logger("pkc-js:address-rewriter-db");
6
- export class AddressRewriterDatabase {
7
- constructor(dataPath, kuboConfig, proxyTarget) {
8
- this._db = null;
9
- this._dbPath = this._initializeDbPath(dataPath, kuboConfig, proxyTarget);
10
- }
11
- _initializeDbPath(dataPath, kuboConfig, proxyTarget) {
12
- if (!dataPath) {
13
- throw new Error("dataPath must be defined for request logging");
14
- }
15
- // Get kubo client hostname:port
16
- let kuboIdentifier = "unknown";
17
- if (kuboConfig && typeof kuboConfig === "object" && "host" in kuboConfig && "port" in kuboConfig) {
18
- kuboIdentifier = `${kuboConfig.host}_${kuboConfig.port}`;
19
- }
20
- // Get proxy target hostname:port
21
- const proxyIdentifier = `${proxyTarget.hostname}_${proxyTarget.port || (proxyTarget.protocol === "https:" ? "443" : "80")}`;
22
- const fileName = `address_rewriter_${kuboIdentifier}_${proxyIdentifier}.db`;
23
- return path.join(dataPath, ".address-rewriter", fileName);
24
- }
25
- async initialize() {
26
- try {
27
- // Ensure directory exists
28
- const dbDir = path.dirname(this._dbPath);
29
- await fs.mkdir(dbDir, { recursive: true });
30
- // Initialize SQLite database
31
- this._db = new Database(this._dbPath);
32
- // Create request logs table - logs HTTP requests through the proxy
33
- this._db.exec(`
34
- CREATE TABLE IF NOT EXISTS request_logs (
35
- id INTEGER PRIMARY KEY AUTOINCREMENT,
36
- keys TEXT NOT NULL,
37
- received_at INTEGER NOT NULL,
38
- transmitted_at INTEGER,
39
- success INTEGER NOT NULL,
40
- status_code INTEGER,
41
- method TEXT NOT NULL,
42
- url TEXT NOT NULL,
43
- error TEXT,
44
- retry_count INTEGER DEFAULT 0,
45
- body_preview TEXT,
46
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
47
- )
48
- `);
49
- // Create reprovide logs table - logs kubo routing.provide() attempts
50
- this._db.exec(`
51
- CREATE TABLE IF NOT EXISTS reprovide_logs (
52
- id INTEGER PRIMARY KEY AUTOINCREMENT,
53
- key TEXT NOT NULL,
54
- timestamp INTEGER NOT NULL,
55
- success INTEGER NOT NULL,
56
- error TEXT,
57
- block_not_local INTEGER DEFAULT 0,
58
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
59
- )
60
- `);
61
- // Create failed keys table
62
- this._db.exec(`
63
- CREATE TABLE IF NOT EXISTS failed_keys (
64
- key TEXT PRIMARY KEY,
65
- added_at INTEGER NOT NULL,
66
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
67
- )
68
- `);
69
- // Create indexes
70
- this._db.exec(`
71
- CREATE INDEX IF NOT EXISTS idx_request_logs_received_at ON request_logs(received_at);
72
- CREATE INDEX IF NOT EXISTS idx_reprovide_logs_timestamp ON reprovide_logs(timestamp);
73
- CREATE INDEX IF NOT EXISTS idx_reprovide_logs_key ON reprovide_logs(key);
74
- `);
75
- try {
76
- this._db.exec("ALTER TABLE request_logs ADD COLUMN body_preview TEXT");
77
- }
78
- catch (error) {
79
- const message = error instanceof Error ? error.message : String(error);
80
- if (!message.toLowerCase().includes("duplicate column name")) {
81
- throw error;
82
- }
83
- }
84
- debug(`Initialized SQLite database at ${this._dbPath}`);
85
- }
86
- catch (error) {
87
- debug.error(`Failed to initialize database at ${this._dbPath}:`, error);
88
- throw error;
89
- }
90
- }
91
- close() {
92
- if (this._db) {
93
- this._db.close();
94
- this._db = null;
95
- }
96
- }
97
- insertRequestLogs(logs) {
98
- if (!this._db) {
99
- throw new Error("Database not initialized");
100
- }
101
- const insertStmt = this._db.prepare(`
102
- INSERT INTO request_logs (
103
- keys, received_at, transmitted_at, success, status_code,
104
- method, url, error, retry_count, body_preview
105
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
106
- `);
107
- const transaction = this._db.transaction(() => {
108
- for (const log of logs) {
109
- insertStmt.run(JSON.stringify(log.keys), log.receivedAt, log.transmittedAt || null, log.success ? 1 : 0, log.statusCode || null, log.method, log.url, log.error || null, log.retryCount || 0, log.bodyPreview || null);
110
- }
111
- });
112
- transaction();
113
- }
114
- insertReprovideLog(key, success, error, blockNotLocal) {
115
- if (!this._db) {
116
- throw new Error("Database not initialized");
117
- }
118
- const insertStmt = this._db.prepare(`
119
- INSERT INTO reprovide_logs (key, timestamp, success, error, block_not_local)
120
- VALUES (?, ?, ?, ?, ?)
121
- `);
122
- insertStmt.run(key, Date.now(), success ? 1 : 0, error || null, blockNotLocal ? 1 : 0);
123
- }
124
- loadFailedKeys() {
125
- if (!this._db) {
126
- return [];
127
- }
128
- try {
129
- const stmt = this._db.prepare("SELECT key FROM failed_keys");
130
- const rows = stmt.all();
131
- return rows.map((row) => row.key);
132
- }
133
- catch (error) {
134
- debug.error("Failed to load failed keys from database:", error);
135
- return [];
136
- }
137
- }
138
- saveFailedKeys(keys) {
139
- if (!this._db) {
140
- throw new Error("Database not initialized");
141
- }
142
- // Clear existing failed keys and insert current ones
143
- const transaction = this._db.transaction(() => {
144
- this._db.exec("DELETE FROM failed_keys");
145
- if (keys.length > 0) {
146
- const insertStmt = this._db.prepare("INSERT INTO failed_keys (key, added_at) VALUES (?, ?)");
147
- const now = Date.now();
148
- for (const key of keys) {
149
- insertStmt.run(key, now);
150
- }
151
- }
152
- });
153
- transaction();
154
- }
155
- }
156
- //# sourceMappingURL=address-rewriter-db.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"address-rewriter-db.js","sourceRoot":"","sources":["../../../../src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AG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACvB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;oBACrB,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;gBAC7B,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,WAAW,EAAE,CAAC;IAClB,CAAC;CACJ"}
@@ -1,45 +0,0 @@
1
- import http from "node:http";
2
- import { PKC } from "../../pkc/pkc.js";
3
- type AddressesRewriterOptions = {
4
- kuboClients: PKC["clients"]["kuboRpcClients"][string]["_client"][];
5
- port: number;
6
- hostname: string | undefined;
7
- proxyTargetUrl: string;
8
- pkc: Pick<PKC, "_storage" | "dataPath">;
9
- };
10
- export declare class AddressesRewriterProxyServer {
11
- addresses: Record<string, string[]>;
12
- kuboClients: AddressesRewriterOptions["kuboClients"];
13
- port: number;
14
- hostname: string;
15
- proxyTarget: URL;
16
- server: ReturnType<(typeof http)["createServer"]>;
17
- _storageKeyName: string;
18
- _pkc: Pick<PKC, "_storage" | "dataPath">;
19
- private _db;
20
- private _logWriteInterval?;
21
- private _requestLogBuffer;
22
- private _isWritingLogs;
23
- private _loggingEnabled;
24
- private _failedKeys;
25
- private _retryInterval?;
26
- private _updateAddressesInterval?;
27
- private _httpAgent;
28
- private _httpsAgent;
29
- constructor({ kuboClients: kuboClient, port, hostname, proxyTargetUrl, pkc }: AddressesRewriterOptions);
30
- listen(callback?: () => void): Promise<void>;
31
- destroy(): Promise<void>;
32
- _proxyRequestRewrite(req: Parameters<http.RequestListener>[0], res: Parameters<http.RequestListener>[1]): void;
33
- private _proxyRequest;
34
- _startUpdateAddressesLoop(): Promise<void>;
35
- private _extractKeysFromRequestBody;
36
- private _createBodyPreview;
37
- private _writeRequestLogs;
38
- private _startRequestLogging;
39
- private _startFailedKeysRetry;
40
- private _loadFailedKeysFromDatabase;
41
- private _saveFailedKeysToDatabase;
42
- private _retryFailedKeys;
43
- private _logReprovideAttempt;
44
- }
45
- export {};