@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/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +3 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +182 -174
- package/dist/index.mjs.map +1 -1
- package/dist/io/folder_reader.d.ts.map +1 -1
- package/dist/v2/registry/registry_reader.d.ts.map +1 -1
- package/package.json +11 -10
- package/src/io/folder_reader.ts +3 -2
- package/src/v2/registry/registry_reader.test.ts +2 -2
- package/src/v2/registry/registry_reader.ts +94 -86
|
@@ -16,12 +16,12 @@ import {
|
|
|
16
16
|
MainPrefix,
|
|
17
17
|
ManifestFileName,
|
|
18
18
|
ManifestSuffix,
|
|
19
|
-
packageContentPrefixInsideV2
|
|
20
|
-
packageOverviewPathInsideV2
|
|
19
|
+
packageContentPrefixInsideV2
|
|
21
20
|
} from './schema_public';
|
|
22
21
|
import { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';
|
|
23
22
|
import { LRUCache } from 'lru-cache';
|
|
24
23
|
import { calculateSha256 } from '../../util';
|
|
24
|
+
import { retry, Retry2TimesWithDelay } from '@milaboratories/ts-helpers';
|
|
25
25
|
|
|
26
26
|
export type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;
|
|
27
27
|
|
|
@@ -60,15 +60,16 @@ export class RegistryV2Reader {
|
|
|
60
60
|
{ meta: BlockPackMetaManifest; relativeTo?: BlockPackId }
|
|
61
61
|
>({
|
|
62
62
|
max: 500,
|
|
63
|
-
fetchMethod: async (_key, _staleValue, options) =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
fetchMethod: async (_key, _staleValue, options) =>
|
|
64
|
+
await retry(async () => {
|
|
65
|
+
const contentReader =
|
|
66
|
+
options.context.relativeTo !== undefined
|
|
67
|
+
? this.v2RootFolderReader
|
|
68
|
+
.relativeReader(packageContentPrefixInsideV2(options.context.relativeTo))
|
|
69
|
+
.getContentReader()
|
|
70
|
+
: this.v2RootFolderReader.getContentReader();
|
|
71
|
+
return await BlockPackMetaEmbedBytes(contentReader).parseAsync(options.context.meta);
|
|
72
|
+
}, Retry2TimesWithDelay)
|
|
72
73
|
});
|
|
73
74
|
|
|
74
75
|
private async embedMetaContent(
|
|
@@ -93,47 +94,49 @@ export class RegistryV2Reader {
|
|
|
93
94
|
)
|
|
94
95
|
return this.listCache;
|
|
95
96
|
try {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
channel,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
97
|
+
return await retry(async () => {
|
|
98
|
+
// const rootContentReader = this.v2RootFolderReader.getContentReader();
|
|
99
|
+
const globalOverview = GlobalOverviewReg.parse(
|
|
100
|
+
JSON.parse(
|
|
101
|
+
Buffer.from(await this.v2RootFolderReader.readFile(GlobalOverviewFileName)).toString()
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const result = await Promise.all(
|
|
106
|
+
globalOverview.packages.map(async (p) => {
|
|
107
|
+
const byChannelEntries = await Promise.all(
|
|
108
|
+
Object.entries(p.latestByChannel).map(async ([channel, data]) => [
|
|
109
|
+
channel,
|
|
110
|
+
{
|
|
111
|
+
id: data.description.id,
|
|
112
|
+
meta: await this.embedMetaContent(
|
|
113
|
+
p.latest.id,
|
|
114
|
+
p.latestManifestSha256,
|
|
115
|
+
true,
|
|
116
|
+
p.latest.meta
|
|
117
|
+
),
|
|
118
|
+
spec: {
|
|
119
|
+
type: 'from-registry-v2',
|
|
120
|
+
id: p.latest.id,
|
|
121
|
+
registryUrl: this.registryReader.rootUrl.toString(),
|
|
122
|
+
channel
|
|
123
|
+
}
|
|
121
124
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
125
|
+
])
|
|
126
|
+
);
|
|
127
|
+
return {
|
|
128
|
+
id: p.id,
|
|
129
|
+
latestByChannel: Object.fromEntries(byChannelEntries),
|
|
130
|
+
allVersions: p.allVersionsWithChannels
|
|
131
|
+
} satisfies BlockPackOverviewNoRegLabel;
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
this.listCache = result;
|
|
136
|
+
this.listCacheTimestamp = Date.now();
|
|
137
|
+
|
|
138
|
+
return result;
|
|
139
|
+
}, Retry2TimesWithDelay);
|
|
137
140
|
} catch (e: unknown) {
|
|
138
141
|
if (
|
|
139
142
|
this.listCache !== undefined &&
|
|
@@ -148,51 +151,56 @@ export class RegistryV2Reader {
|
|
|
148
151
|
id: BlockPackIdNoVersion,
|
|
149
152
|
channel: string
|
|
150
153
|
): Promise<SingleBlockPackOverview | undefined> {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
return await retry(async () => {
|
|
155
|
+
const overview = (await this.listBlockPacks()).find((e) =>
|
|
156
|
+
blockPackIdNoVersionEquals(id, e.id)
|
|
157
|
+
);
|
|
158
|
+
if (overview === undefined) return undefined;
|
|
159
|
+
return overview.latestByChannel[channel];
|
|
160
|
+
}, Retry2TimesWithDelay);
|
|
156
161
|
}
|
|
157
162
|
|
|
158
163
|
public async getSpecificOverview(
|
|
159
164
|
id: BlockPackId,
|
|
160
165
|
channel: string
|
|
161
166
|
): Promise<SingleBlockPackOverview> {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
167
|
+
return await retry(async () => {
|
|
168
|
+
const manifestContent = await this.v2RootFolderReader.readFile(
|
|
169
|
+
packageContentPrefixInsideV2(id) + ManifestSuffix
|
|
170
|
+
);
|
|
171
|
+
const overview = BlockPackManifest.parse(JSON.parse(Buffer.from(manifestContent).toString()));
|
|
172
|
+
return {
|
|
173
|
+
id: id,
|
|
174
|
+
meta: await this.embedMetaContent(
|
|
175
|
+
id,
|
|
176
|
+
await calculateSha256(manifestContent),
|
|
177
|
+
false,
|
|
178
|
+
overview.description.meta
|
|
179
|
+
),
|
|
180
|
+
spec: {
|
|
181
|
+
type: 'from-registry-v2',
|
|
182
|
+
id,
|
|
183
|
+
registryUrl: this.registryReader.rootUrl.toString(),
|
|
184
|
+
channel
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}, Retry2TimesWithDelay);
|
|
181
188
|
}
|
|
182
189
|
|
|
183
190
|
private readonly componentsCache = new LRUCache<string, BlockComponentsAbsoluteUrl, BlockPackId>({
|
|
184
191
|
max: 500,
|
|
185
|
-
fetchMethod: async (key, staleValue, { context: id }) =>
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
fetchMethod: async (key, staleValue, { context: id }) =>
|
|
193
|
+
await retry(async () => {
|
|
194
|
+
const packageFolderReader = this.v2RootFolderReader.relativeReader(
|
|
195
|
+
packageContentPrefixInsideV2(id)
|
|
196
|
+
);
|
|
197
|
+
const manifest = BlockPackManifest.parse(
|
|
198
|
+
JSON.parse(Buffer.from(await packageFolderReader.readFile(ManifestFileName)).toString())
|
|
199
|
+
);
|
|
200
|
+
return BlockComponentsAbsoluteUrl(packageFolderReader.rootUrl.toString()).parse(
|
|
201
|
+
manifest.description.components
|
|
202
|
+
);
|
|
203
|
+
}, Retry2TimesWithDelay)
|
|
196
204
|
});
|
|
197
205
|
|
|
198
206
|
public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {
|