@platforma-sdk/block-tools 2.4.7 → 2.4.9

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/index.mjs CHANGED
@@ -1,26 +1,28 @@
1
- var v = Object.defineProperty;
2
- var k = (o, e, a) => e in o ? v(o, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : o[e] = a;
3
- var r = (o, e, a) => k(o, typeof e != "symbol" ? e + "" : e, a);
4
- import { e as u, p as c, f as w, G as R, h as y, i as C, j as P, M as B, k as F, m as b, n as x, o as O, q as S, r as T, t as D, u as M, v as U, P as E, w as L, x as V, y as G } from "./config-dqDSqXfz.mjs";
5
- import { U as ce, T as pe, Y as de, ad as he, W as fe, X as me, O as ge, a as ve, B as ke, Q as ue, b as we, a1 as Re, a0 as ye, F as Ce, ac as Pe, aa as Be, ab as Fe, a9 as be, af as xe, ae as Oe, a4 as Se, $ as Te, a3 as De, V as Me, R as Ue, z as Ee, S as Le, D as Ve, E as Ge, C as Ne, d as je, H as Ae, c as Je, l as Ie, A as We, I as _e, a8 as ze, a7 as qe, a2 as $e, a6 as Ye, a5 as He, Z as Ke, K as Qe, L as Xe, N as Ze, J as ea, s as aa, _ as ta } from "./config-dqDSqXfz.mjs";
6
- import { Agent as N, request as j } from "undici";
7
- import i from "node:path";
8
- import l from "node:path/posix";
9
- import A from "node:fs/promises";
10
- import { blockPackIdNoVersionEquals as J, BlockPackManifest as h } from "@milaboratories/pl-model-middle-layer";
11
- import f from "canonicalize";
1
+ var u = Object.defineProperty;
2
+ var y = (o, e, a) => e in o ? u(o, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : o[e] = a;
3
+ var r = (o, e, a) => y(o, typeof e != "symbol" ? e + "" : e, a);
4
+ import { e as w, p as d, f as R, G as C, h as P, i as B, j as F, M as b, k as x, m as O, n as T, o as S, q as D, r as M, t as U, u as E, v as L, P as V, w as G, x as N, y as j } from "./config-dqDSqXfz.mjs";
5
+ import { U as me, T as fe, Y as ve, ad as ge, W as ke, X as ue, O as ye, a as we, B as Re, Q as Ce, b as Pe, a1 as Be, a0 as Fe, F as be, ac as xe, aa as Oe, ab as Te, a9 as Se, af as De, ae as Me, a4 as Ue, $ as Ee, a3 as Le, V as Ve, R as Ge, z as Ne, S as je, D as Ae, E as Je, C as We, d as Ie, H as _e, c as ze, l as qe, A as $e, I as He, a8 as Ye, a7 as Ke, a2 as Qe, a6 as Xe, a5 as Ze, Z as ea, K as aa, L as ta, N as oa, J as sa, s as ra, _ as ia } from "./config-dqDSqXfz.mjs";
6
+ import { request as A } from "undici";
7
+ import l from "node:path";
8
+ import p from "node:path/posix";
9
+ import J from "node:fs/promises";
10
+ import { defaultHttpDispatcher as W } from "@milaboratories/pl-http";
11
+ import { blockPackIdNoVersionEquals as I, BlockPackManifest as f } from "@milaboratories/pl-model-middle-layer";
12
+ import v from "canonicalize";
12
13
  import "zod";
13
14
  import "mime-types";
14
15
  import "tar";
15
16
  import "@milaboratories/resolve-helper";
16
- import { LRUCache as m } from "lru-cache";
17
- const I = {
17
+ import { LRUCache as g } from "lru-cache";
18
+ import { retry as i, Retry2TimesWithDelay as n } from "@milaboratories/ts-helpers";
19
+ const _ = {
18
20
  cacheBlockListFor: 45e3,
19
21
  // 45 seconds
20
22
  keepStaleBlockListFor: 3e5
21
23
  // 5 minutes
22
24
  };
23
- class se {
25
+ class le {
24
26
  constructor(e, a) {
25
27
  r(this, "v2RootFolderReader");
26
28
  r(this, "ops");
@@ -29,33 +31,33 @@ class se {
29
31
  * Meta information that looks like:
30
32
  *
31
33
  * */
32
- r(this, "embeddedGlobalMetaCache", new m({
34
+ r(this, "embeddedGlobalMetaCache", new g({
33
35
  max: 500,
34
- fetchMethod: async (e, a, t) => {
35
- const s = t.context.relativeTo !== void 0 ? this.v2RootFolderReader.relativeReader(c(t.context.relativeTo)).getContentReader() : this.v2RootFolderReader.getContentReader();
36
- return await w(s).parseAsync(t.context.meta);
37
- }
36
+ fetchMethod: async (e, a, t) => await i(async () => {
37
+ const s = t.context.relativeTo !== void 0 ? this.v2RootFolderReader.relativeReader(d(t.context.relativeTo)).getContentReader() : this.v2RootFolderReader.getContentReader();
38
+ return await R(s).parseAsync(t.context.meta);
39
+ }, n)
38
40
  }));
39
41
  r(this, "listCacheTimestamp", 0);
40
42
  r(this, "listCache");
41
- r(this, "componentsCache", new m({
43
+ r(this, "componentsCache", new g({
42
44
  max: 500,
43
- fetchMethod: async (e, a, { context: t }) => {
45
+ fetchMethod: async (e, a, { context: t }) => await i(async () => {
44
46
  const s = this.v2RootFolderReader.relativeReader(
45
- c(t)
46
- ), n = h.parse(
47
- JSON.parse(Buffer.from(await s.readFile(B)).toString())
47
+ d(t)
48
+ ), c = f.parse(
49
+ JSON.parse(Buffer.from(await s.readFile(b)).toString())
48
50
  );
49
- return F(s.rootUrl.toString()).parse(
50
- n.description.components
51
+ return x(s.rootUrl.toString()).parse(
52
+ c.description.components
51
53
  );
52
- }
54
+ }, n)
53
55
  }));
54
- this.registryReader = e, this.v2RootFolderReader = e.relativeReader(u), this.ops = { ...I, ...a ?? {} };
56
+ this.registryReader = e, this.v2RootFolderReader = e.relativeReader(w), this.ops = { ..._, ...a ?? {} };
55
57
  }
56
58
  async embedMetaContent(e, a, t, s) {
57
59
  return await this.embeddedGlobalMetaCache.forceFetch(
58
- f({ id: e, sha256: a, absolutePath: t }),
60
+ v({ id: e, sha256: a, absolutePath: t }),
59
61
  { context: { meta: s, relativeTo: t ? void 0 : e } }
60
62
  );
61
63
  }
@@ -63,40 +65,42 @@ class se {
63
65
  if (this.listCache !== void 0 && Date.now() - this.listCacheTimestamp <= this.ops.cacheBlockListFor)
64
66
  return this.listCache;
65
67
  try {
66
- const e = R.parse(
67
- JSON.parse(
68
- Buffer.from(await this.v2RootFolderReader.readFile(y)).toString()
69
- )
70
- ), a = await Promise.all(
71
- e.packages.map(async (t) => {
72
- const s = await Promise.all(
73
- Object.entries(t.latestByChannel).map(async ([n, g]) => [
74
- n,
75
- {
76
- id: g.description.id,
77
- meta: await this.embedMetaContent(
78
- t.latest.id,
79
- t.latestManifestSha256,
80
- !0,
81
- t.latest.meta
82
- ),
83
- spec: {
84
- type: "from-registry-v2",
85
- id: t.latest.id,
86
- registryUrl: this.registryReader.rootUrl.toString(),
87
- channel: n
68
+ return await i(async () => {
69
+ const e = C.parse(
70
+ JSON.parse(
71
+ Buffer.from(await this.v2RootFolderReader.readFile(P)).toString()
72
+ )
73
+ ), a = await Promise.all(
74
+ e.packages.map(async (t) => {
75
+ const s = await Promise.all(
76
+ Object.entries(t.latestByChannel).map(async ([c, k]) => [
77
+ c,
78
+ {
79
+ id: k.description.id,
80
+ meta: await this.embedMetaContent(
81
+ t.latest.id,
82
+ t.latestManifestSha256,
83
+ !0,
84
+ t.latest.meta
85
+ ),
86
+ spec: {
87
+ type: "from-registry-v2",
88
+ id: t.latest.id,
89
+ registryUrl: this.registryReader.rootUrl.toString(),
90
+ channel: c
91
+ }
88
92
  }
89
- }
90
- ])
91
- );
92
- return {
93
- id: t.id,
94
- latestByChannel: Object.fromEntries(s),
95
- allVersions: t.allVersionsWithChannels
96
- };
97
- })
98
- );
99
- return this.listCache = a, this.listCacheTimestamp = Date.now(), a;
93
+ ])
94
+ );
95
+ return {
96
+ id: t.id,
97
+ latestByChannel: Object.fromEntries(s),
98
+ allVersions: t.allVersionsWithChannels
99
+ };
100
+ })
101
+ );
102
+ return this.listCache = a, this.listCacheTimestamp = Date.now(), a;
103
+ }, n);
100
104
  } catch (e) {
101
105
  if (this.listCache !== void 0 && Date.now() - this.listCacheTimestamp <= this.ops.keepStaleBlockListFor)
102
106
  return this.listCache;
@@ -104,66 +108,70 @@ class se {
104
108
  }
105
109
  }
106
110
  async getLatestOverview(e, a) {
107
- const t = (await this.listBlockPacks()).find(
108
- (s) => J(e, s.id)
109
- );
110
- if (t !== void 0)
111
- return t.latestByChannel[a];
111
+ return await i(async () => {
112
+ const t = (await this.listBlockPacks()).find(
113
+ (s) => I(e, s.id)
114
+ );
115
+ if (t !== void 0)
116
+ return t.latestByChannel[a];
117
+ }, n);
112
118
  }
113
119
  async getSpecificOverview(e, a) {
114
- const t = await this.v2RootFolderReader.readFile(
115
- c(e) + C
116
- ), s = h.parse(JSON.parse(Buffer.from(t).toString()));
117
- return {
118
- id: e,
119
- meta: await this.embedMetaContent(
120
- e,
121
- await P(t),
122
- !1,
123
- s.description.meta
124
- ),
125
- spec: {
126
- type: "from-registry-v2",
120
+ return await i(async () => {
121
+ const t = await this.v2RootFolderReader.readFile(
122
+ d(e) + B
123
+ ), s = f.parse(JSON.parse(Buffer.from(t).toString()));
124
+ return {
127
125
  id: e,
128
- registryUrl: this.registryReader.rootUrl.toString(),
129
- channel: a
130
- }
131
- };
126
+ meta: await this.embedMetaContent(
127
+ e,
128
+ await F(t),
129
+ !1,
130
+ s.description.meta
131
+ ),
132
+ spec: {
133
+ type: "from-registry-v2",
134
+ id: e,
135
+ registryUrl: this.registryReader.rootUrl.toString(),
136
+ channel: a
137
+ }
138
+ };
139
+ }, n);
132
140
  }
133
141
  async getComponents(e) {
134
- return await this.componentsCache.forceFetch(f(e), { context: e });
142
+ return await this.componentsCache.forceFetch(v(e), { context: e });
135
143
  }
136
144
  }
137
- class p {
145
+ class h {
138
146
  constructor(e, a) {
139
147
  this.rootUrl = e, this.httpDispatcher = a;
140
148
  }
141
149
  async readFile(e) {
142
- const a = new URL(e, this.rootUrl), t = await j(a, {
150
+ const a = new URL(e, this.rootUrl), t = await A(a, {
143
151
  dispatcher: this.httpDispatcher
144
152
  });
145
153
  return Buffer.from(await t.body.arrayBuffer());
146
154
  }
147
155
  relativeReader(e) {
148
- return e.endsWith("/") || (e = e + "/"), new p(new URL(e, this.rootUrl), this.httpDispatcher);
156
+ return e.endsWith("/") || (e = e + "/"), new h(new URL(e, this.rootUrl), this.httpDispatcher);
149
157
  }
150
158
  getContentReader(e) {
151
159
  let a = this;
152
160
  return e !== void 0 && (a = a.relativeReader(e)), (t) => a.readFile(t);
153
161
  }
154
162
  }
155
- class d {
163
+ class m {
156
164
  constructor(e, a) {
157
165
  this.rootUrl = e, this.root = a;
158
166
  }
159
167
  async readFile(e) {
160
- const a = i.join(this.root, ...e.split(l.sep));
161
- return await A.readFile(a);
168
+ const a = l.join(this.root, ...e.split(p.sep));
169
+ return await J.readFile(a);
162
170
  }
163
171
  relativeReader(e) {
164
- return e.endsWith("/") || (e = e + "/"), new d(
172
+ return e.endsWith("/") || (e = e + "/"), new m(
165
173
  new URL(e, this.rootUrl),
166
- i.join(this.root, ...e.split(l.sep))
174
+ l.join(this.root, ...e.split(p.sep))
167
175
  );
168
176
  }
169
177
  getContentReader(e) {
@@ -171,100 +179,100 @@ class d {
171
179
  return e !== void 0 && (a = a.relativeReader(e)), (t) => a.readFile(t);
172
180
  }
173
181
  }
174
- function W(o) {
175
- return o.split(l.sep).join(i.sep);
182
+ function z(o) {
183
+ return o.split(p.sep).join(l.sep);
176
184
  }
177
- function _(o) {
178
- return o.split(i.sep).join(l.sep);
185
+ function q(o) {
186
+ return o.split(l.sep).join(p.sep);
179
187
  }
180
- function re(o, e) {
188
+ function ce(o, e) {
181
189
  o.endsWith("/") || (o = o + "/");
182
- const a = new URL(o, `file:${_(i.resolve("."))}/`);
190
+ const a = new URL(o, `file:${q(l.resolve("."))}/`);
183
191
  switch (a.protocol) {
184
192
  case "file:":
185
- const t = W(a.pathname);
186
- return new d(a, t);
193
+ const t = z(a.pathname);
194
+ return new m(a, t);
187
195
  case "https:":
188
196
  case "http:":
189
- return new p(a, e ?? new N());
197
+ return new h(a, e ?? W());
190
198
  default:
191
199
  throw new Error(`Unknown protocol: ${a.protocol}`);
192
200
  }
193
201
  }
194
- const ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
202
+ const pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
195
203
  __proto__: null,
196
- GlobalOverviewPath: b,
197
- MetaFile: x,
198
- PlPackageConfigData: O,
199
- PlPackageJsonConfigFile: S,
200
- PlPackageYamlConfigFile: T,
201
- PlRegCommonConfigData: D,
202
- PlRegFullPackageConfigData: M,
203
- PlRegPackageConfig: U,
204
- PlRegPackageConfigDataShard: E,
205
- packageContentPrefix: L,
206
- packageOverviewPath: V,
207
- payloadFilePath: G
204
+ GlobalOverviewPath: O,
205
+ MetaFile: T,
206
+ PlPackageConfigData: S,
207
+ PlPackageJsonConfigFile: D,
208
+ PlPackageYamlConfigFile: M,
209
+ PlRegCommonConfigData: U,
210
+ PlRegFullPackageConfigData: E,
211
+ PlRegPackageConfig: L,
212
+ PlRegPackageConfigDataShard: V,
213
+ packageContentPrefix: G,
214
+ packageOverviewPath: N,
215
+ payloadFilePath: j
208
216
  }, Symbol.toStringTag, { value: "Module" }));
209
217
  export {
210
- F as BlockComponentsAbsoluteUrl,
211
- ce as BlockComponentsConsolidate,
212
- pe as BlockComponentsDescription,
213
- de as BlockDescriptionPackageJsonField,
214
- he as BlockDescriptionToExplicitBinaryBytes,
215
- fe as BlockPackDescriptionConsolidateToFolder,
216
- me as BlockPackDescriptionManifestAddRelativePathPrefix,
217
- ge as BlockPackMetaConsolidate,
218
- ve as BlockPackMetaDescription,
219
- ke as BlockPackMetaEmbedAbsoluteBase64,
220
- ue as BlockPackMetaEmbedAbsoluteBytes,
221
- w as BlockPackMetaEmbedBytes,
222
- we as BlockRegistryV2,
223
- Re as ChannelNameRegexp,
224
- ye as ChannelsFolder,
225
- Ce as FSStorage,
226
- Pe as GlobalOverview,
227
- Be as GlobalOverviewEntry,
228
- Fe as GlobalOverviewEntryReg,
229
- y as GlobalOverviewFileName,
230
- be as GlobalOverviewPath,
231
- R as GlobalOverviewReg,
232
- xe as GlobalOverviewToExplicitBinaryBase64,
233
- Oe as GlobalOverviewToExplicitBinaryBytes,
234
- u as MainPrefix,
235
- B as ManifestFileName,
236
- C as ManifestSuffix,
237
- Se as PackageOverview,
238
- Te as PackageOverviewFileName,
239
- De as PackageOverviewVersionEntry,
240
- ie as RegistryV1,
241
- se as RegistryV2Reader,
242
- Me as ResolvedBlockPackDescriptionFromPackageJson,
243
- Ue as ResolvedModuleFile,
244
- Ee as ResolvedModuleFolder,
245
- Le as S3Storage,
246
- Ve as absoluteToBase64,
247
- Ge as absoluteToBytes,
248
- Ne as absoluteToString,
249
- je as buildBlockPackDist,
250
- Ae as cpAbsoluteToRelative,
251
- re as folderReaderByUrl,
252
- Je as loadPackDescription,
253
- Ie as loadPackDescriptionRaw,
254
- We as mapLocalToAbsolute,
255
- _e as packFolderToRelativeTgz,
256
- ze as packageChannelPrefix,
257
- qe as packageChannelPrefixInsideV2,
258
- $e as packageContentPrefix,
259
- c as packageContentPrefixInsideV2,
260
- Ye as packageOverviewPath,
261
- He as packageOverviewPathInsideV2,
262
- Ke as parsePackageName,
263
- Qe as relativeToContentString,
264
- Xe as relativeToExplicitBinary64,
265
- Ze as relativeToExplicitBytes,
266
- ea as relativeToExplicitString,
267
- aa as storageByUrl,
268
- ta as tryLoadPackDescription
218
+ x as BlockComponentsAbsoluteUrl,
219
+ me as BlockComponentsConsolidate,
220
+ fe as BlockComponentsDescription,
221
+ ve as BlockDescriptionPackageJsonField,
222
+ ge as BlockDescriptionToExplicitBinaryBytes,
223
+ ke as BlockPackDescriptionConsolidateToFolder,
224
+ ue as BlockPackDescriptionManifestAddRelativePathPrefix,
225
+ ye as BlockPackMetaConsolidate,
226
+ we as BlockPackMetaDescription,
227
+ Re as BlockPackMetaEmbedAbsoluteBase64,
228
+ Ce as BlockPackMetaEmbedAbsoluteBytes,
229
+ R as BlockPackMetaEmbedBytes,
230
+ Pe as BlockRegistryV2,
231
+ Be as ChannelNameRegexp,
232
+ Fe as ChannelsFolder,
233
+ be as FSStorage,
234
+ xe as GlobalOverview,
235
+ Oe as GlobalOverviewEntry,
236
+ Te as GlobalOverviewEntryReg,
237
+ P as GlobalOverviewFileName,
238
+ Se as GlobalOverviewPath,
239
+ C as GlobalOverviewReg,
240
+ De as GlobalOverviewToExplicitBinaryBase64,
241
+ Me as GlobalOverviewToExplicitBinaryBytes,
242
+ w as MainPrefix,
243
+ b as ManifestFileName,
244
+ B as ManifestSuffix,
245
+ Ue as PackageOverview,
246
+ Ee as PackageOverviewFileName,
247
+ Le as PackageOverviewVersionEntry,
248
+ pe as RegistryV1,
249
+ le as RegistryV2Reader,
250
+ Ve as ResolvedBlockPackDescriptionFromPackageJson,
251
+ Ge as ResolvedModuleFile,
252
+ Ne as ResolvedModuleFolder,
253
+ je as S3Storage,
254
+ Ae as absoluteToBase64,
255
+ Je as absoluteToBytes,
256
+ We as absoluteToString,
257
+ Ie as buildBlockPackDist,
258
+ _e as cpAbsoluteToRelative,
259
+ ce as folderReaderByUrl,
260
+ ze as loadPackDescription,
261
+ qe as loadPackDescriptionRaw,
262
+ $e as mapLocalToAbsolute,
263
+ He as packFolderToRelativeTgz,
264
+ Ye as packageChannelPrefix,
265
+ Ke as packageChannelPrefixInsideV2,
266
+ Qe as packageContentPrefix,
267
+ d as packageContentPrefixInsideV2,
268
+ Xe as packageOverviewPath,
269
+ Ze as packageOverviewPathInsideV2,
270
+ ea as parsePackageName,
271
+ aa as relativeToContentString,
272
+ ta as relativeToExplicitBinary64,
273
+ oa as relativeToExplicitBytes,
274
+ sa as relativeToExplicitString,
275
+ ra as storageByUrl,
276
+ ia as tryLoadPackDescription
269
277
  };
270
278
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/v2/registry/registry_reader.ts","../src/io/folder_reader.ts"],"sourcesContent":["import {\n BlockPackId,\n BlockPackIdNoVersion,\n blockPackIdNoVersionEquals,\n BlockPackManifest,\n BlockPackMetaEmbeddedBytes,\n BlockPackMetaManifest,\n BlockPackOverview,\n SingleBlockPackOverview\n} from '@milaboratories/pl-model-middle-layer';\nimport { FolderReader } from '../../io';\nimport canonicalize from 'canonicalize';\nimport {\n GlobalOverviewFileName,\n GlobalOverviewReg,\n MainPrefix,\n ManifestFileName,\n ManifestSuffix,\n packageContentPrefixInsideV2,\n packageOverviewPathInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\nimport { LRUCache } from 'lru-cache';\nimport { calculateSha256 } from '../../util';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport type RegistryV2ReaderOps = {\n /** Number of milliseconds to cache retrieved block list for */\n cacheBlockListFor: number;\n /** Number of milliseconds to keep cached retrieved block list for, if new requests returns error */\n keepStaleBlockListFor: number;\n};\n\nconst DefaultRegistryV2ReaderOps: RegistryV2ReaderOps = {\n cacheBlockListFor: 45e3, // 45 seconds\n keepStaleBlockListFor: 300e3 // 5 minutes\n};\n\nexport class RegistryV2Reader {\n private readonly v2RootFolderReader: FolderReader;\n private readonly ops: RegistryV2ReaderOps;\n\n constructor(\n private readonly registryReader: FolderReader,\n ops?: Partial<RegistryV2ReaderOps>\n ) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n this.ops = { ...DefaultRegistryV2ReaderOps, ...(ops ?? {}) };\n }\n\n /**\n * Embeds meta infromation relative to registry root.\n * Meta information that looks like:\n *\n * */\n private readonly embeddedGlobalMetaCache = new LRUCache<\n string,\n BlockPackMetaEmbeddedBytes,\n { meta: BlockPackMetaManifest; relativeTo?: BlockPackId }\n >({\n max: 500,\n fetchMethod: async (_key, _staleValue, options) => {\n const contentReader =\n options.context.relativeTo !== undefined\n ? this.v2RootFolderReader\n .relativeReader(packageContentPrefixInsideV2(options.context.relativeTo))\n .getContentReader()\n : this.v2RootFolderReader.getContentReader();\n return await BlockPackMetaEmbedBytes(contentReader).parseAsync(options.context.meta);\n }\n });\n\n private async embedMetaContent(\n id: BlockPackId,\n sha256: string,\n absolutePath: boolean,\n meta: BlockPackMetaManifest\n ): Promise<BlockPackMetaEmbeddedBytes> {\n return await this.embeddedGlobalMetaCache.forceFetch(\n canonicalize({ id, sha256, absolutePath })!,\n { context: { meta, relativeTo: absolutePath ? undefined : id } }\n );\n }\n\n private listCacheTimestamp: number = 0;\n private listCache: BlockPackOverviewNoRegLabel[] | undefined = undefined;\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.cacheBlockListFor\n )\n return this.listCache;\n try {\n // const rootContentReader = this.v2RootFolderReader.getContentReader();\n const globalOverview = GlobalOverviewReg.parse(\n JSON.parse(\n Buffer.from(await this.v2RootFolderReader.readFile(GlobalOverviewFileName)).toString()\n )\n );\n\n const result = await Promise.all(\n globalOverview.packages.map(async (p) => {\n const byChannelEntries = await Promise.all(\n Object.entries(p.latestByChannel).map(async ([channel, data]) => [\n channel,\n {\n id: data.description.id,\n meta: await this.embedMetaContent(\n p.latest.id,\n p.latestManifestSha256,\n true,\n p.latest.meta\n ),\n spec: {\n type: 'from-registry-v2',\n id: p.latest.id,\n registryUrl: this.registryReader.rootUrl.toString(),\n channel\n }\n }\n ])\n );\n return {\n id: p.id,\n latestByChannel: Object.fromEntries(byChannelEntries),\n allVersions: p.allVersionsWithChannels\n } satisfies BlockPackOverviewNoRegLabel;\n })\n );\n\n this.listCache = result;\n this.listCacheTimestamp = Date.now();\n\n return result;\n } catch (e: unknown) {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.keepStaleBlockListFor\n )\n return this.listCache;\n throw e;\n }\n }\n\n public async getLatestOverview(\n id: BlockPackIdNoVersion,\n channel: string\n ): Promise<SingleBlockPackOverview | undefined> {\n const overview = (await this.listBlockPacks()).find((e) =>\n blockPackIdNoVersionEquals(id, e.id)\n );\n if (overview === undefined) return undefined;\n return overview.latestByChannel[channel];\n }\n\n public async getSpecificOverview(\n id: BlockPackId,\n channel: string\n ): Promise<SingleBlockPackOverview> {\n const manifestContent = await this.v2RootFolderReader.readFile(\n packageContentPrefixInsideV2(id) + ManifestSuffix\n );\n const overview = BlockPackManifest.parse(JSON.parse(Buffer.from(manifestContent).toString()));\n return {\n id: id,\n meta: await this.embedMetaContent(\n id,\n await calculateSha256(manifestContent),\n false,\n overview.description.meta\n ),\n spec: {\n type: 'from-registry-v2',\n id,\n registryUrl: this.registryReader.rootUrl.toString(),\n channel\n }\n };\n }\n\n private readonly componentsCache = new LRUCache<string, BlockComponentsAbsoluteUrl, BlockPackId>({\n max: 500,\n fetchMethod: async (key, staleValue, { context: id }) => {\n const packageFolderReader = this.v2RootFolderReader.relativeReader(\n packageContentPrefixInsideV2(id)\n );\n const manifest = BlockPackManifest.parse(\n JSON.parse(Buffer.from(await packageFolderReader.readFile(ManifestFileName)).toString())\n );\n return BlockComponentsAbsoluteUrl(packageFolderReader.rootUrl.toString()).parse(\n manifest.description.components\n );\n }\n });\n\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\n return await this.componentsCache.forceFetch(canonicalize(id)!, { context: id });\n }\n}\n","import { Agent, Dispatcher, request } from 'undici';\nimport { RelativeContentReader } from '../v2';\nimport path from 'node:path';\nimport pathPosix from 'node:path/posix';\nimport fsp from 'node:fs/promises';\n\nexport interface FolderReader {\n readonly rootUrl: URL;\n relativeReader(relativePath: string): FolderReader;\n readFile(file: string): Promise<Buffer>;\n getContentReader(relativePath?: string): RelativeContentReader;\n}\n\nclass HttpFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly httpDispatcher: Dispatcher\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetUrl = new URL(file, this.rootUrl);\n const response = await request(targetUrl, {\n dispatcher: this.httpDispatcher\n });\n return Buffer.from(await response.body.arrayBuffer());\n }\n\n public relativeReader(relativePath: string): HttpFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new HttpFolderReader(new URL(relativePath, this.rootUrl), this.httpDispatcher);\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: HttpFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nclass FSFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly root: string\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetPath = path.join(this.root, ...file.split(pathPosix.sep));\n return await fsp.readFile(targetPath);\n }\n\n public relativeReader(relativePath: string): FSFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new FSFolderReader(\n new URL(relativePath, this.rootUrl),\n path.join(this.root, ...relativePath.split(pathPosix.sep))\n );\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: FSFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nfunction posixToLocalPath(p: string): string {\n return p.split(pathPosix.sep).join(path.sep);\n}\n\nfunction localToPosix(p: string): string {\n return p.split(path.sep).join(pathPosix.sep);\n}\n\nexport function folderReaderByUrl(address: string, httpDispatcher?: Dispatcher): FolderReader {\n if (!address.endsWith('/')) address = address + '/';\n const url = new URL(address, `file:${localToPosix(path.resolve('.'))}/`);\n switch (url.protocol) {\n case 'file:':\n const rootPath = posixToLocalPath(url.pathname);\n return new FSFolderReader(url, rootPath);\n case 'https:':\n case 'http:':\n return new HttpFolderReader(url, httpDispatcher ?? new Agent());\n default:\n throw new Error(`Unknown protocol: ${url.protocol}`);\n }\n}\n"],"names":["DefaultRegistryV2ReaderOps","RegistryV2Reader","registryReader","ops","__publicField","LRUCache","_key","_staleValue","options","contentReader","packageContentPrefixInsideV2","BlockPackMetaEmbedBytes","key","staleValue","id","packageFolderReader","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","MainPrefix","sha256","absolutePath","meta","canonicalize","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","result","p","byChannelEntries","channel","data","overview","e","blockPackIdNoVersionEquals","manifestContent","ManifestSuffix","calculateSha256","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","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K,GAAG;AAC7C;AAEA,SAASO,EAAa1B,GAAmB;AACvC,SAAOA,EAAE,MAAMmB,EAAK,GAAG,EAAE,KAAKI,EAAU,GAAG;AAC7C;AAEgB,SAAAI,GAAkBC,GAAiBhB,GAA2C;AAC5F,EAAKgB,EAAQ,SAAS,GAAG,UAAaA,IAAU;AAC1C,QAAAC,IAAM,IAAI,IAAID,GAAS,QAAQF,EAAaP,EAAK,QAAQ,GAAG,CAAC,CAAC,GAAG;AACvE,UAAQU,EAAI,UAAU;AAAA,IACpB,KAAK;AACG,YAAAC,IAAWL,EAAiBI,EAAI,QAAQ;AACvC,aAAA,IAAIT,EAAeS,GAAKC,CAAQ;AAAA,IACzC,KAAK;AAAA,IACL,KAAK;AACH,aAAO,IAAIpB,EAAiBmB,GAAKjB,KAAkB,IAAImB,GAAO;AAAA,IAChE;AACE,YAAM,IAAI,MAAM,qBAAqBF,EAAI,QAAQ,EAAE;AAAA,EAAA;AAEzD;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/v2/registry/registry_reader.ts","../src/io/folder_reader.ts"],"sourcesContent":["import {\n BlockPackId,\n BlockPackIdNoVersion,\n blockPackIdNoVersionEquals,\n BlockPackManifest,\n BlockPackMetaEmbeddedBytes,\n BlockPackMetaManifest,\n BlockPackOverview,\n SingleBlockPackOverview\n} from '@milaboratories/pl-model-middle-layer';\nimport { FolderReader } from '../../io';\nimport canonicalize from 'canonicalize';\nimport {\n GlobalOverviewFileName,\n GlobalOverviewReg,\n MainPrefix,\n ManifestFileName,\n ManifestSuffix,\n packageContentPrefixInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\nimport { LRUCache } from 'lru-cache';\nimport { calculateSha256 } from '../../util';\nimport { retry, Retry2TimesWithDelay } from '@milaboratories/ts-helpers';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport type RegistryV2ReaderOps = {\n /** Number of milliseconds to cache retrieved block list for */\n cacheBlockListFor: number;\n /** Number of milliseconds to keep cached retrieved block list for, if new requests returns error */\n keepStaleBlockListFor: number;\n};\n\nconst DefaultRegistryV2ReaderOps: RegistryV2ReaderOps = {\n cacheBlockListFor: 45e3, // 45 seconds\n keepStaleBlockListFor: 300e3 // 5 minutes\n};\n\nexport class RegistryV2Reader {\n private readonly v2RootFolderReader: FolderReader;\n private readonly ops: RegistryV2ReaderOps;\n\n constructor(\n private readonly registryReader: FolderReader,\n ops?: Partial<RegistryV2ReaderOps>\n ) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n this.ops = { ...DefaultRegistryV2ReaderOps, ...(ops ?? {}) };\n }\n\n /**\n * Embeds meta infromation relative to registry root.\n * Meta information that looks like:\n *\n * */\n private readonly embeddedGlobalMetaCache = new LRUCache<\n string,\n BlockPackMetaEmbeddedBytes,\n { meta: BlockPackMetaManifest; relativeTo?: BlockPackId }\n >({\n max: 500,\n fetchMethod: async (_key, _staleValue, options) =>\n await retry(async () => {\n const contentReader =\n options.context.relativeTo !== undefined\n ? this.v2RootFolderReader\n .relativeReader(packageContentPrefixInsideV2(options.context.relativeTo))\n .getContentReader()\n : this.v2RootFolderReader.getContentReader();\n return await BlockPackMetaEmbedBytes(contentReader).parseAsync(options.context.meta);\n }, Retry2TimesWithDelay)\n });\n\n private async embedMetaContent(\n id: BlockPackId,\n sha256: string,\n absolutePath: boolean,\n meta: BlockPackMetaManifest\n ): Promise<BlockPackMetaEmbeddedBytes> {\n return await this.embeddedGlobalMetaCache.forceFetch(\n canonicalize({ id, sha256, absolutePath })!,\n { context: { meta, relativeTo: absolutePath ? undefined : id } }\n );\n }\n\n private listCacheTimestamp: number = 0;\n private listCache: BlockPackOverviewNoRegLabel[] | undefined = undefined;\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.cacheBlockListFor\n )\n return this.listCache;\n try {\n return await retry(async () => {\n // const rootContentReader = this.v2RootFolderReader.getContentReader();\n const globalOverview = GlobalOverviewReg.parse(\n JSON.parse(\n Buffer.from(await this.v2RootFolderReader.readFile(GlobalOverviewFileName)).toString()\n )\n );\n\n const result = await Promise.all(\n globalOverview.packages.map(async (p) => {\n const byChannelEntries = await Promise.all(\n Object.entries(p.latestByChannel).map(async ([channel, data]) => [\n channel,\n {\n id: data.description.id,\n meta: await this.embedMetaContent(\n p.latest.id,\n p.latestManifestSha256,\n true,\n p.latest.meta\n ),\n spec: {\n type: 'from-registry-v2',\n id: p.latest.id,\n registryUrl: this.registryReader.rootUrl.toString(),\n channel\n }\n }\n ])\n );\n return {\n id: p.id,\n latestByChannel: Object.fromEntries(byChannelEntries),\n allVersions: p.allVersionsWithChannels\n } satisfies BlockPackOverviewNoRegLabel;\n })\n );\n\n this.listCache = result;\n this.listCacheTimestamp = Date.now();\n\n return result;\n }, Retry2TimesWithDelay);\n } catch (e: unknown) {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.keepStaleBlockListFor\n )\n return this.listCache;\n throw e;\n }\n }\n\n public async getLatestOverview(\n id: BlockPackIdNoVersion,\n channel: string\n ): Promise<SingleBlockPackOverview | undefined> {\n return await retry(async () => {\n const overview = (await this.listBlockPacks()).find((e) =>\n blockPackIdNoVersionEquals(id, e.id)\n );\n if (overview === undefined) return undefined;\n return overview.latestByChannel[channel];\n }, Retry2TimesWithDelay);\n }\n\n public async getSpecificOverview(\n id: BlockPackId,\n channel: string\n ): Promise<SingleBlockPackOverview> {\n return await retry(async () => {\n const manifestContent = await this.v2RootFolderReader.readFile(\n packageContentPrefixInsideV2(id) + ManifestSuffix\n );\n const overview = BlockPackManifest.parse(JSON.parse(Buffer.from(manifestContent).toString()));\n return {\n id: id,\n meta: await this.embedMetaContent(\n id,\n await calculateSha256(manifestContent),\n false,\n overview.description.meta\n ),\n spec: {\n type: 'from-registry-v2',\n id,\n registryUrl: this.registryReader.rootUrl.toString(),\n channel\n }\n };\n }, Retry2TimesWithDelay);\n }\n\n private readonly componentsCache = new LRUCache<string, BlockComponentsAbsoluteUrl, BlockPackId>({\n max: 500,\n fetchMethod: async (key, staleValue, { context: id }) =>\n await retry(async () => {\n const packageFolderReader = this.v2RootFolderReader.relativeReader(\n packageContentPrefixInsideV2(id)\n );\n const manifest = BlockPackManifest.parse(\n JSON.parse(Buffer.from(await packageFolderReader.readFile(ManifestFileName)).toString())\n );\n return BlockComponentsAbsoluteUrl(packageFolderReader.rootUrl.toString()).parse(\n manifest.description.components\n );\n }, Retry2TimesWithDelay)\n });\n\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\n return await this.componentsCache.forceFetch(canonicalize(id)!, { context: id });\n }\n}\n","import { Dispatcher, request } from 'undici';\nimport { RelativeContentReader } from '../v2';\nimport path from 'node:path';\nimport pathPosix from 'node:path/posix';\nimport fsp from 'node:fs/promises';\nimport { defaultHttpDispatcher } from '@milaboratories/pl-http';\n\nexport interface FolderReader {\n readonly rootUrl: URL;\n relativeReader(relativePath: string): FolderReader;\n readFile(file: string): Promise<Buffer>;\n getContentReader(relativePath?: string): RelativeContentReader;\n}\n\nclass HttpFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly httpDispatcher: Dispatcher\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetUrl = new URL(file, this.rootUrl);\n const response = await request(targetUrl, {\n dispatcher: this.httpDispatcher\n });\n return Buffer.from(await response.body.arrayBuffer());\n }\n\n public relativeReader(relativePath: string): HttpFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new HttpFolderReader(new URL(relativePath, this.rootUrl), this.httpDispatcher);\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: HttpFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nclass FSFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly root: string\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetPath = path.join(this.root, ...file.split(pathPosix.sep));\n return await fsp.readFile(targetPath);\n }\n\n public relativeReader(relativePath: string): FSFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new FSFolderReader(\n new URL(relativePath, this.rootUrl),\n path.join(this.root, ...relativePath.split(pathPosix.sep))\n );\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: FSFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nfunction posixToLocalPath(p: string): string {\n return p.split(pathPosix.sep).join(path.sep);\n}\n\nfunction localToPosix(p: string): string {\n return p.split(path.sep).join(pathPosix.sep);\n}\n\nexport function folderReaderByUrl(address: string, httpDispatcher?: Dispatcher): FolderReader {\n if (!address.endsWith('/')) address = address + '/';\n const url = new URL(address, `file:${localToPosix(path.resolve('.'))}/`);\n switch (url.protocol) {\n case 'file:':\n const rootPath = posixToLocalPath(url.pathname);\n return new FSFolderReader(url, rootPath);\n case 'https:':\n case 'http:':\n return new HttpFolderReader(url, httpDispatcher ?? defaultHttpDispatcher());\n default:\n throw new Error(`Unknown protocol: ${url.protocol}`);\n }\n}\n"],"names":["DefaultRegistryV2ReaderOps","RegistryV2Reader","registryReader","ops","__publicField","LRUCache","_key","_staleValue","options","retry","contentReader","packageContentPrefixInsideV2","BlockPackMetaEmbedBytes","Retry2TimesWithDelay","key","staleValue","id","packageFolderReader","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","MainPrefix","sha256","absolutePath","meta","canonicalize","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","result","p","byChannelEntries","channel","data","overview","e","blockPackIdNoVersionEquals","manifestContent","ManifestSuffix","calculateSha256","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","posixToLoc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AC,MAAM,CAAC,CAAC;IACxC,gBAAgB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAAC;CAChE;AA8DD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,UAAU,GAAG,YAAY,CAa5F"}
1
+ {"version":3,"file":"folder_reader.d.ts","sourceRoot":"","sources":["../../src/io/folder_reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAM9C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IACtB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,CAAC;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,gBAAgB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAAC;CAChE;AA8DD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,UAAU,GAAG,YAAY,CAa5F"}
@@ -1 +1 @@
1
- {"version":3,"file":"registry_reader.d.ts","sourceRoot":"","sources":["../../../src/v2/registry/registry_reader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,oBAAoB,EAKpB,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAWxC,OAAO,EAAE,0BAA0B,EAA2B,MAAM,UAAU,CAAC;AAI/E,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;AAEhF,MAAM,MAAM,mBAAmB,GAAG;IAChC,+DAA+D;IAC/D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oGAAoG;IACpG,qBAAqB,EAAE,MAA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ACpG,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAC;AAOF,qBAAa,gBAAgB;IAKzB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAJjC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAe;IAClD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAsB;gBAGvB,cAAc,EAAE,YAAY,EAC7C,GAAG,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC;IAMpC;;;;SAIK;IACL,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAgBrC;YAEW,gBAAgB;IAY9B,OAAO,CAAC,kBAAkB,CAAa;IACvC,OAAO,CAAC,SAAS,CAAwD;IAE5D,cAAc,IAAI,OAAO,CAAC,2BAA2B,EAAE,CAAC;IA4DxD,iBAAiB,CAC5B,EAAE,EAAE,oBAAoB,EACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC;IAUlC,mBAAmB,CAC9B,EAAE,EAAE,WAAW,EACf,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,uBAAuB,CAAC;IAwBnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAc7B;IAEU,aAAa,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,0BAA0B,CAAC;CAGjF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/block-tools",
3
- "version": "2.4.7",
3
+ "version": "2.4.9",
4
4
  "description": "Utility to manipulate Platforma Blocks and Block Registry",
5
5
  "types": "./dist/lib.d.ts",
6
6
  "main": "./dist/index.js",
@@ -23,20 +23,21 @@
23
23
  ],
24
24
  "license": "UNLICENSED",
25
25
  "dependencies": {
26
- "@aws-sdk/client-s3": "^3.701.0",
26
+ "@aws-sdk/client-s3": "^3.705.0",
27
27
  "remeda": "^2.17.4",
28
- "@oclif/core": "^4.0.33",
28
+ "@oclif/core": "^4.0.34",
29
29
  "canonicalize": "^2.0.0",
30
30
  "lru-cache": "^11.0.2",
31
- "undici": "^6.21.0",
31
+ "undici": "^7.1.0",
32
32
  "mime-types": "^2.1.35",
33
33
  "tar": "^7.4.3",
34
34
  "yaml": "^2.6.1",
35
35
  "zod": "^3.23.8",
36
36
  "@milaboratories/resolve-helper": "^1.0.2",
37
- "@milaboratories/ts-helpers": "^1.1.2",
38
- "@milaboratories/ts-helpers-oclif": "^1.1.11",
39
- "@milaboratories/pl-model-middle-layer": "^1.6.4"
37
+ "@milaboratories/pl-http": "^1.0.1",
38
+ "@milaboratories/pl-model-middle-layer": "^1.6.5",
39
+ "@milaboratories/ts-helpers": "^1.1.3",
40
+ "@milaboratories/ts-helpers-oclif": "^1.1.12"
40
41
  },
41
42
  "devDependencies": {
42
43
  "typescript": "~5.5.4",
@@ -51,10 +52,10 @@
51
52
  "@types/semver": "^7.5.8",
52
53
  "jest": "^29.7.0",
53
54
  "@jest/globals": "^29.7.0",
54
- "oclif": "^4.15.29",
55
+ "oclif": "^4.16.0",
55
56
  "ts-jest": "^29.2.5",
56
- "@milaboratories/platforma-build-configs": "1.0.2",
57
- "@milaboratories/oclif-index": "1.1.0"
57
+ "@milaboratories/oclif-index": "1.1.0",
58
+ "@milaboratories/platforma-build-configs": "1.0.2"
58
59
  },
59
60
  "oclif": {
60
61
  "bin": "block-tools",
@@ -1,8 +1,9 @@
1
- import { Agent, Dispatcher, request } from 'undici';
1
+ import { Dispatcher, request } from 'undici';
2
2
  import { RelativeContentReader } from '../v2';
3
3
  import path from 'node:path';
4
4
  import pathPosix from 'node:path/posix';
5
5
  import fsp from 'node:fs/promises';
6
+ import { defaultHttpDispatcher } from '@milaboratories/pl-http';
6
7
 
7
8
  export interface FolderReader {
8
9
  readonly rootUrl: URL;
@@ -80,7 +81,7 @@ export function folderReaderByUrl(address: string, httpDispatcher?: Dispatcher):
80
81
  return new FSFolderReader(url, rootPath);
81
82
  case 'https:':
82
83
  case 'http:':
83
- return new HttpFolderReader(url, httpDispatcher ?? new Agent());
84
+ return new HttpFolderReader(url, httpDispatcher ?? defaultHttpDispatcher());
84
85
  default:
85
86
  throw new Error(`Unknown protocol: ${url.protocol}`);
86
87
  }
@@ -11,7 +11,7 @@ test('test listing packets from global registry', async () => {
11
11
  // console.dir(listing, { depth: 5 });
12
12
  expect(listing[0].allVersions.length).toBeGreaterThanOrEqual(1);
13
13
  expect(listing[0].latestByChannel[AnyChannel]).toBeDefined();
14
- });
14
+ }, 20000);
15
15
 
16
16
  test('test getting components from global registry', async () => {
17
17
  const registryReader = new RegistryV2Reader(folderReaderByUrl('https://blocks.pl-open.science'));
@@ -30,4 +30,4 @@ test('test getting components from global registry', async () => {
30
30
  expect(
31
31
  (await (await request(components.workflow.main.url)).body.arrayBuffer()).byteLength
32
32
  ).toBeGreaterThan(100);
33
- }, 10000);
33
+ }, 20000);