@platforma-sdk/block-tools 2.6.27 → 2.6.29

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 (48) hide show
  1. package/dist/cli.js +3 -3
  2. package/dist/cli.js.map +1 -1
  3. package/dist/cli.mjs +15 -13
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/{config-XBQ2O39y.mjs → config-DKBY0B2u.mjs} +272 -273
  6. package/dist/config-DKBY0B2u.mjs.map +1 -0
  7. package/dist/config-Ycas5fbX.js +3 -0
  8. package/dist/config-Ycas5fbX.js.map +1 -0
  9. package/dist/index.js +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +18 -17
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/registry_v1/v1_repo_schema.d.ts +2 -2
  14. package/package.json +18 -15
  15. package/src/cmd/build-meta.ts +9 -9
  16. package/src/cmd/build-model.ts +20 -16
  17. package/src/cmd/index.ts +0 -1
  18. package/src/cmd/list-overview-snapshots.ts +5 -5
  19. package/src/cmd/mark-stable.ts +14 -15
  20. package/src/cmd/pack.ts +7 -7
  21. package/src/cmd/publish.ts +16 -16
  22. package/src/cmd/refresh-registry.ts +4 -10
  23. package/src/cmd/restore-overview-from-snapshot.ts +16 -16
  24. package/src/cmd/update-deps.ts +3 -2
  25. package/src/cmd/upload-package-v1.ts +12 -12
  26. package/src/io/folder_reader.ts +15 -11
  27. package/src/io/storage.ts +25 -23
  28. package/src/registry_v1/config.ts +11 -10
  29. package/src/registry_v1/config_schema.ts +5 -5
  30. package/src/registry_v1/flags.ts +3 -2
  31. package/src/registry_v1/registry.ts +34 -35
  32. package/src/registry_v1/v1_repo_schema.ts +2 -2
  33. package/src/util.ts +15 -11
  34. package/src/v2/build_dist.ts +12 -9
  35. package/src/v2/model/block_components.ts +6 -6
  36. package/src/v2/model/block_description.ts +13 -13
  37. package/src/v2/model/block_meta.ts +10 -9
  38. package/src/v2/model/content_conversion.ts +28 -26
  39. package/src/v2/registry/index.ts +3 -3
  40. package/src/v2/registry/registry.test.ts +1 -1
  41. package/src/v2/registry/registry.ts +64 -63
  42. package/src/v2/registry/registry_reader.ts +47 -46
  43. package/src/v2/registry/schema_internal.ts +3 -3
  44. package/src/v2/registry/schema_public.ts +29 -26
  45. package/src/v2/source_package.ts +26 -23
  46. package/dist/config-DjpRXRy9.js +0 -3
  47. package/dist/config-DjpRXRy9.js.map +0 -1
  48. package/dist/config-XBQ2O39y.mjs.map +0 -1
@@ -1,18 +1,20 @@
1
- import { RegistryStorage } from '../io/storage';
1
+ import type { RegistryStorage } from '../io/storage';
2
2
  import { randomUUID } from 'node:crypto';
3
- import semver from 'semver';
4
- import {
3
+ import * as semver from 'semver';
4
+ import type {
5
5
  BlockPackageNameWithoutVersion,
6
6
  FullBlockPackageName,
7
7
  GlobalOverview,
8
+ PackageOverview } from './v1_repo_schema';
9
+ import {
8
10
  GlobalOverviewPath,
9
11
  MetaFile,
10
- PackageOverview,
11
12
  packageOverviewPath,
12
- payloadFilePath
13
+ payloadFilePath,
13
14
  } from './v1_repo_schema';
14
- import { MiLogger } from '@milaboratories/ts-helpers';
15
+ import type { MiLogger } from '@milaboratories/ts-helpers';
15
16
 
17
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
18
  function fullNameToPath(name: FullBlockPackageName): string {
17
19
  return `${name.organization}/${name.package}/${name.version}`;
18
20
  }
@@ -23,8 +25,8 @@ function packageUpdatePath(bp: FullBlockPackageName, seed: string): string {
23
25
  return `${VersionUpdatesPrefix}${bp.organization}/${bp.package}/${bp.version}/${seed}`;
24
26
  }
25
27
 
26
- const PackageUpdatePattern =
27
- /(?<packageKeyWithoutVersion>(?<organization>[^\/]+)\/(?<pkg>[^\/]+))\/(?<version>[^\/]+)\/(?<seed>[^\/]+)$/;
28
+ const PackageUpdatePattern
29
+ = /(?<packageKeyWithoutVersion>(?<organization>[^/]+)\/(?<pkg>[^/]+))\/(?<version>[^/]+)\/(?<seed>[^/]+)$/;
28
30
 
29
31
  const GlobalUpdateSeedInFile = '_updates_v1/_global_update_in';
30
32
  const GlobalUpdateSeedOutFile = '_updates_v1/_global_update_out';
@@ -77,14 +79,14 @@ const GlobalUpdateSeedOutFile = '_updates_v1/_global_update_out';
77
79
  export class BlockRegistry {
78
80
  constructor(
79
81
  private readonly storage: RegistryStorage,
80
- private readonly logger?: MiLogger
82
+ private readonly logger?: MiLogger,
81
83
  ) {}
82
84
 
83
85
  constructNewPackage(pack: FullBlockPackageName): BlockRegistryPackConstructor {
84
86
  return new BlockRegistryPackConstructor(this.storage, pack);
85
87
  }
86
88
 
87
- private async updateRegistry() {
89
+ private async updateRegistry(): Promise<void> {
88
90
  this.logger?.info('Initiating registry refresh...');
89
91
 
90
92
  // reading update requests
@@ -96,27 +98,24 @@ export class BlockRegistry {
96
98
  const match = seedPath.match(PackageUpdatePattern);
97
99
  if (!match) continue;
98
100
  seedPaths.push(seedPath);
99
- const { packageKeyWithoutVersion, organization, pkg, version, seed } = match.groups!;
101
+ const { packageKeyWithoutVersion, organization, pkg, version, seed: _seed } = match.groups!;
100
102
 
101
- let update = packagesToUpdate.get(packageKeyWithoutVersion);
102
- let added = false;
103
+ const update = packagesToUpdate.get(packageKeyWithoutVersion);
103
104
  if (!update) {
104
105
  packagesToUpdate.set(packageKeyWithoutVersion, {
105
106
  package: { organization, package: pkg },
106
- versions: new Set([version])
107
+ versions: new Set([version]),
107
108
  });
108
- added = true;
109
109
  } else if (!update.versions.has(version)) {
110
110
  update.versions.add(version);
111
- added = true;
112
111
  }
113
112
  this.logger?.info(` - ${organization}:${pkg}:${version}`);
114
113
  }
115
114
 
116
115
  // loading global overview
117
116
  const overviewContent = await this.storage.getFile(GlobalOverviewPath);
118
- let overview =
119
- overviewContent === undefined
117
+ let overview: GlobalOverview
118
+ = overviewContent === undefined
120
119
  ? []
121
120
  : (JSON.parse(overviewContent.toString()) as GlobalOverview);
122
121
  this.logger?.info(`Global overview loaded, ${overview.length} records`);
@@ -126,12 +125,12 @@ export class BlockRegistry {
126
125
  // reading existing overview
127
126
  const overviewFile = packageOverviewPath(packageInfo.package);
128
127
  const pOverviewContent = await this.storage.getFile(overviewFile);
129
- let packageOverview =
130
- pOverviewContent === undefined
128
+ let packageOverview
129
+ = pOverviewContent === undefined
131
130
  ? []
132
131
  : (JSON.parse(pOverviewContent.toString()) as PackageOverview);
133
132
  this.logger?.info(
134
- `Updating ${packageInfo.package.organization}:${packageInfo.package.package} overview, ${packageOverview.length} records`
133
+ `Updating ${packageInfo.package.organization}:${packageInfo.package.package} overview, ${packageOverview.length} records`,
135
134
  );
136
135
 
137
136
  // removing versions that we will update
@@ -144,13 +143,13 @@ export class BlockRegistry {
144
143
  payloadFilePath(
145
144
  {
146
145
  ...packageInfo.package,
147
- version
146
+ version,
148
147
  },
149
- MetaFile
150
- )
148
+ MetaFile,
149
+ ),
151
150
  );
152
151
  if (!metaContent) continue;
153
- packageOverview.push({ version, meta: JSON.parse(metaContent.toString()) });
152
+ packageOverview.push({ version, meta: JSON.parse(metaContent.toString()) as Record<string, unknown> });
154
153
  }
155
154
 
156
155
  // sorting entries according to version
@@ -163,15 +162,15 @@ export class BlockRegistry {
163
162
  // patching corresponding entry in overview
164
163
  overview = overview.filter(
165
164
  (e) =>
166
- e.organization !== packageInfo.package.organization ||
167
- e.package !== packageInfo.package.package
165
+ e.organization !== packageInfo.package.organization
166
+ || e.package !== packageInfo.package.package,
168
167
  );
169
168
  overview.push({
170
169
  organization: packageInfo.package.organization,
171
170
  package: packageInfo.package.package,
172
171
  allVersions: packageOverview.map((e) => e.version).reverse(),
173
172
  latestVersion: packageOverview[0].version,
174
- latestMeta: packageOverview[0].meta
173
+ latestMeta: packageOverview[0].meta,
175
174
  });
176
175
  }
177
176
 
@@ -192,10 +191,10 @@ export class BlockRegistry {
192
191
  const currentUpdatedSeed = await this.storage.getFile(GlobalUpdateSeedOutFile);
193
192
  if (!force && updateRequestSeed === undefined && currentUpdatedSeed === undefined) return;
194
193
  if (
195
- !force &&
196
- updateRequestSeed !== undefined &&
197
- currentUpdatedSeed !== undefined &&
198
- updateRequestSeed.equals(currentUpdatedSeed)
194
+ !force
195
+ && updateRequestSeed !== undefined
196
+ && currentUpdatedSeed !== undefined
197
+ && updateRequestSeed.equals(currentUpdatedSeed)
199
198
  )
200
199
  return;
201
200
 
@@ -208,7 +207,7 @@ export class BlockRegistry {
208
207
  }
209
208
 
210
209
  async getPackageOverview(
211
- name: BlockPackageNameWithoutVersion
210
+ name: BlockPackageNameWithoutVersion,
212
211
  ): Promise<undefined | PackageOverview> {
213
212
  const content = await this.storage.getFile(packageOverviewPath(name));
214
213
  if (content === undefined) return undefined;
@@ -228,7 +227,7 @@ export class BlockRegistryPackConstructor {
228
227
 
229
228
  constructor(
230
229
  private readonly storage: RegistryStorage,
231
- public readonly name: FullBlockPackageName
230
+ public readonly name: FullBlockPackageName,
232
231
  ) {}
233
232
 
234
233
  async addFile(file: string, content: Buffer): Promise<void> {
@@ -249,5 +248,5 @@ export class BlockRegistryPackConstructor {
249
248
 
250
249
  interface PackageUpdateInfo {
251
250
  package: BlockPackageNameWithoutVersion;
252
- versions: Set<String>;
251
+ versions: Set<string>;
253
252
  }
@@ -26,7 +26,7 @@ export const MetaFile = 'meta.json';
26
26
 
27
27
  export interface PackageOverviewEntry {
28
28
  version: string;
29
- meta: object;
29
+ meta: Record<string, unknown>;
30
30
  }
31
31
 
32
32
  export type PackageOverview = PackageOverviewEntry[];
@@ -36,7 +36,7 @@ export interface GlobalOverviewEntry {
36
36
  package: string;
37
37
  allVersions: string[];
38
38
  latestVersion: string;
39
- latestMeta: any;
39
+ latestMeta: Record<string, unknown>;
40
40
  }
41
41
 
42
42
  export type GlobalOverview = GlobalOverviewEntry[];
package/src/util.ts CHANGED
@@ -1,31 +1,35 @@
1
- import { BigIntStats } from 'node:fs';
1
+ import type { BigIntStats } from 'node:fs';
2
2
  import fsp from 'node:fs/promises';
3
+ import { createHash } from 'node:crypto';
3
4
 
4
5
  export async function tryLoadFile<T>(
5
6
  file: string,
6
- map: (buf: Buffer) => T
7
+ map: (buf: Buffer) => T,
7
8
  ): Promise<T | undefined> {
8
9
  try {
9
10
  return map(await fsp.readFile(file));
10
- } catch (err: any) {
11
- if (err.code == 'ENOENT') return undefined;
12
- else throw new Error('', { cause: err });
11
+ } catch (err: unknown) {
12
+ if (err instanceof Error && 'code' in err && err.code === 'ENOENT') return undefined;
13
+ else throw err;
13
14
  }
14
15
  }
15
16
 
16
17
  export async function tryStat(path: string): Promise<BigIntStats | undefined> {
17
18
  try {
18
19
  return await fsp.stat(path, { bigint: true });
19
- } catch (error: any) {
20
- if (error.code === 'ENOENT') {
20
+ } catch (error: unknown) {
21
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
21
22
  return undefined;
22
23
  }
23
24
  throw error;
24
25
  }
25
26
  }
26
27
 
27
- export async function calculateSha256(bytes: ArrayBuffer) {
28
- return Buffer.from(await crypto.subtle.digest('sha-256', bytes))
29
- .toString('hex')
30
- .toUpperCase();
28
+ export function calculateSha256(bytes: ArrayBuffer): Promise<string> {
29
+ return Promise.resolve(
30
+ createHash('sha256')
31
+ .update(Buffer.from(bytes))
32
+ .digest('hex')
33
+ .toUpperCase(),
34
+ );
31
35
  }
@@ -1,37 +1,40 @@
1
- import {
1
+ import type {
2
2
  BlockPackDescriptionManifest,
3
+ ManifestFileInfo,
4
+ } from '@milaboratories/pl-model-middle-layer';
5
+ import {
3
6
  BlockPackManifest,
4
7
  BlockPackManifestFile,
5
- ManifestFileInfo
6
8
  } from '@milaboratories/pl-model-middle-layer';
7
- import { BlockPackDescriptionAbsolute, BlockPackDescriptionConsolidateToFolder } from './model';
9
+ import type { BlockPackDescriptionAbsolute } from './model';
10
+ import { BlockPackDescriptionConsolidateToFolder } from './model';
8
11
  import fsp from 'node:fs/promises';
9
12
  import path from 'node:path';
10
13
  import { calculateSha256 } from '../util';
11
14
 
12
15
  export async function buildBlockPackDist(
13
16
  description: BlockPackDescriptionAbsolute,
14
- dst: string
17
+ dst: string,
15
18
  ): Promise<BlockPackManifest> {
16
19
  await fsp.mkdir(dst, { recursive: true });
17
20
  const files: string[] = [];
18
- const descriptionRelative: BlockPackDescriptionManifest =
19
- await BlockPackDescriptionConsolidateToFolder(dst, files).parseAsync(description);
21
+ const descriptionRelative: BlockPackDescriptionManifest
22
+ = await BlockPackDescriptionConsolidateToFolder(dst, files).parseAsync(description);
20
23
  const filesForManifest = await Promise.all(
21
24
  files.map(async (f): Promise<ManifestFileInfo> => {
22
25
  const bytes = await fsp.readFile(path.resolve(dst, f));
23
26
  const sha256 = await calculateSha256(bytes);
24
27
  return { name: f, size: bytes.length, sha256 };
25
- })
28
+ }),
26
29
  );
27
30
 
28
31
  const manifest: BlockPackManifest = BlockPackManifest.parse({
29
32
  schema: 'v2',
30
33
  description: {
31
- ...descriptionRelative
34
+ ...descriptionRelative,
32
35
  },
33
36
  files: filesForManifest,
34
- timestamp: Date.now()
37
+ timestamp: Date.now(),
35
38
  } satisfies BlockPackManifest);
36
39
  await fsp.writeFile(path.resolve(dst, BlockPackManifestFile), JSON.stringify(manifest));
37
40
  return manifest;
@@ -1,9 +1,9 @@
1
- import { z } from 'zod';
1
+ import type { z } from 'zod';
2
2
  import {
3
3
  ResolvedModuleFile,
4
4
  ResolvedModuleFolder,
5
5
  packFolderToRelativeTgz,
6
- cpAbsoluteToRelative
6
+ cpAbsoluteToRelative,
7
7
  } from './content_conversion';
8
8
  import {
9
9
  BlockComponents,
@@ -11,13 +11,13 @@ import {
11
11
  ContentAbsoluteBinaryLocal,
12
12
  ContentAbsoluteFolder,
13
13
  ContentRelative,
14
- mapRemoteToAbsolute
14
+ mapRemoteToAbsolute,
15
15
  } from '@milaboratories/pl-model-middle-layer';
16
16
 
17
17
  export function BlockComponentsDescription(moduleRoot: string) {
18
18
  return BlockComponents(
19
19
  ResolvedModuleFile(moduleRoot),
20
- ResolvedModuleFolder(moduleRoot, 'index.html')
20
+ ResolvedModuleFolder(moduleRoot, 'index.html'),
21
21
  );
22
22
  }
23
23
  export type BlockComponentsDescription = z.infer<ReturnType<typeof BlockComponentsDescription>>;
@@ -25,14 +25,14 @@ export type BlockComponentsDescription = z.infer<ReturnType<typeof BlockComponen
25
25
  export function BlockComponentsConsolidate(dstFolder: string, fileAccumulator?: string[]) {
26
26
  return BlockComponents(
27
27
  ContentAbsoluteBinaryLocal.transform(cpAbsoluteToRelative(dstFolder, fileAccumulator)),
28
- ContentAbsoluteFolder.transform(packFolderToRelativeTgz(dstFolder, 'ui.tgz', fileAccumulator))
28
+ ContentAbsoluteFolder.transform(packFolderToRelativeTgz(dstFolder, 'ui.tgz', fileAccumulator)),
29
29
  ).pipe(BlockComponentsManifest);
30
30
  }
31
31
 
32
32
  export function BlockComponentsAbsoluteUrl(prefix: string) {
33
33
  return BlockComponents(
34
34
  ContentRelative.transform(mapRemoteToAbsolute(prefix)),
35
- ContentRelative.transform(mapRemoteToAbsolute(prefix))
35
+ ContentRelative.transform(mapRemoteToAbsolute(prefix)),
36
36
  );
37
37
  }
38
38
  export type BlockComponentsAbsoluteUrl = z.infer<ReturnType<typeof BlockComponentsAbsoluteUrl>>;
@@ -6,25 +6,25 @@ import {
6
6
  ContentRelative,
7
7
  ContentRelativeBinary,
8
8
  ContentRelativeText,
9
- CreateBlockPackDescriptionSchema
9
+ CreateBlockPackDescriptionSchema,
10
10
  } from '@milaboratories/pl-model-middle-layer';
11
11
  import { BlockComponentsConsolidate, BlockComponentsDescription } from './block_components';
12
12
  import { BlockPackMetaConsolidate, BlockPackMetaDescription } from './block_meta';
13
- import { z } from 'zod';
14
- import path from 'node:path';
13
+ import type { z } from 'zod';
15
14
  import fsp from 'node:fs/promises';
16
- import { BlockConfigContainer, extractConfigGeneric } from '@milaboratories/pl-model-common';
15
+ import type { BlockConfigContainer } from '@milaboratories/pl-model-common';
16
+ import { extractConfigGeneric } from '@milaboratories/pl-model-common';
17
17
 
18
18
  export function ResolvedBlockPackDescriptionFromPackageJson(root: string) {
19
19
  return CreateBlockPackDescriptionSchema(
20
20
  BlockComponentsDescription(root),
21
- BlockPackMetaDescription(root)
22
- ).transform(async (description, ctx) => {
21
+ BlockPackMetaDescription(root),
22
+ ).transform(async (description, _ctx) => {
23
23
  const cfg = extractConfigGeneric(JSON.parse(await fsp.readFile(description.components.model.file, 'utf-8')) as BlockConfigContainer);
24
24
  const featureFlags = cfg.featureFlags;
25
25
  return {
26
26
  ...description,
27
- featureFlags
27
+ featureFlags,
28
28
  };
29
29
  });
30
30
  }
@@ -34,11 +34,11 @@ export type BlockPackDescriptionAbsolute = z.infer<
34
34
 
35
35
  export function BlockPackDescriptionConsolidateToFolder(
36
36
  dstFolder: string,
37
- fileAccumulator?: string[]
37
+ fileAccumulator?: string[],
38
38
  ) {
39
39
  return CreateBlockPackDescriptionSchema(
40
40
  BlockComponentsConsolidate(dstFolder, fileAccumulator),
41
- BlockPackMetaConsolidate(dstFolder, fileAccumulator)
41
+ BlockPackMetaConsolidate(dstFolder, fileAccumulator),
42
42
  ).pipe(BlockPackDescriptionManifest);
43
43
  }
44
44
 
@@ -48,12 +48,12 @@ export function BlockPackDescriptionManifestAddRelativePathPrefix(prefix: string
48
48
  CreateBlockPackDescriptionSchema(
49
49
  BlockComponents(
50
50
  ContentRelative.transform(transformer),
51
- ContentRelative.transform(transformer)
51
+ ContentRelative.transform(transformer),
52
52
  ),
53
53
  BlockPackMeta(
54
54
  ContentRelativeText.transform(transformer),
55
- ContentRelativeBinary.transform(transformer)
56
- )
57
- )
55
+ ContentRelativeBinary.transform(transformer),
56
+ ),
57
+ ),
58
58
  ).pipe(BlockPackDescriptionManifest);
59
59
  }
@@ -7,24 +7,25 @@ import {
7
7
  ContentRelativeBinary,
8
8
  ContentRelativeText,
9
9
  DescriptionContentBinary,
10
- DescriptionContentText
10
+ DescriptionContentText,
11
11
  } from '@milaboratories/pl-model-middle-layer';
12
+ import type {
13
+ RelativeContentReader } from './content_conversion';
12
14
  import {
13
15
  absoluteToBase64,
14
16
  absoluteToBytes,
15
17
  absoluteToString,
16
18
  cpAbsoluteToRelative,
17
19
  mapLocalToAbsolute,
18
- RelativeContentReader,
19
20
  relativeToContentString,
20
- relativeToExplicitBytes
21
+ relativeToExplicitBytes,
21
22
  } from './content_conversion';
22
- import { z } from 'zod';
23
+ import type { z } from 'zod';
23
24
 
24
25
  export function BlockPackMetaDescription(root: string) {
25
26
  return BlockPackMeta(
26
27
  DescriptionContentText.transform(mapLocalToAbsolute(root)),
27
- DescriptionContentBinary.transform(mapLocalToAbsolute(root))
28
+ DescriptionContentBinary.transform(mapLocalToAbsolute(root)),
28
29
  );
29
30
  }
30
31
  export type BlockPackMetaDescription = z.infer<ReturnType<typeof BlockPackMetaDescription>>;
@@ -32,23 +33,23 @@ export type BlockPackMetaDescription = z.infer<ReturnType<typeof BlockPackMetaDe
32
33
  export function BlockPackMetaConsolidate(dstFolder: string, fileAccumulator?: string[]) {
33
34
  return BlockPackMeta(
34
35
  ContentAbsoluteTextLocal.transform(cpAbsoluteToRelative(dstFolder, fileAccumulator)),
35
- ContentAbsoluteBinaryLocal.transform(cpAbsoluteToRelative(dstFolder, fileAccumulator))
36
+ ContentAbsoluteBinaryLocal.transform(cpAbsoluteToRelative(dstFolder, fileAccumulator)),
36
37
  );
37
38
  }
38
39
 
39
40
  export const BlockPackMetaEmbedAbsoluteBase64 = BlockPackMeta(
40
41
  ContentAbsoluteTextLocal.transform(absoluteToString()),
41
- ContentAbsoluteBinaryLocal.transform(absoluteToBase64())
42
+ ContentAbsoluteBinaryLocal.transform(absoluteToBase64()),
42
43
  ).pipe(BlockPackMetaEmbeddedBase64);
43
44
 
44
45
  export const BlockPackMetaEmbedAbsoluteBytes = BlockPackMeta(
45
46
  ContentAbsoluteTextLocal.transform(absoluteToString()),
46
- ContentAbsoluteBinaryLocal.transform(absoluteToBytes())
47
+ ContentAbsoluteBinaryLocal.transform(absoluteToBytes()),
47
48
  ).pipe(BlockPackMetaEmbeddedBytes);
48
49
 
49
50
  export function BlockPackMetaEmbedBytes(reader: RelativeContentReader) {
50
51
  return BlockPackMeta(
51
52
  ContentRelativeText.transform(relativeToContentString(reader)),
52
- ContentRelativeBinary.transform(relativeToExplicitBytes(reader))
53
+ ContentRelativeBinary.transform(relativeToExplicitBytes(reader)),
53
54
  ).pipe(BlockPackMetaEmbeddedBytes);
54
55
  }
@@ -1,9 +1,9 @@
1
1
  import { z } from 'zod';
2
- import path from 'path';
2
+ import path from 'node:path';
3
3
  import fsp from 'node:fs/promises';
4
4
  import * as mime from 'mime-types';
5
5
  import * as tar from 'tar';
6
- import {
6
+ import type {
7
7
  ContentAbsoluteBinaryLocal,
8
8
  ContentAbsoluteFile,
9
9
  ContentAbsoluteFolder,
@@ -14,7 +14,7 @@ import {
14
14
  ContentExplicitString,
15
15
  ContentRelative,
16
16
  ContentRelativeBinary,
17
- ContentRelativeText
17
+ ContentRelativeText,
18
18
  } from '@milaboratories/pl-model-middle-layer';
19
19
  import { tryResolve } from '@milaboratories/resolve-helper';
20
20
 
@@ -33,6 +33,7 @@ type ContentCtxUrl = {
33
33
  /** Describes a place relative to which any content references should be interpreted */
34
34
  export type ContentCtx = ContentCtxFs | ContentCtxUrl;
35
35
 
36
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- utility function for future use
36
37
  function mustResolve(root: string, request: string): string {
37
38
  const res = tryResolve(root, request);
38
39
  if (res === undefined) throw new Error(`Can't resolve ${request} against ${root}`);
@@ -46,13 +47,13 @@ export function ResolvedModuleFile(moduleRoot: string) {
46
47
  if (result === undefined) {
47
48
  ctx.addIssue({
48
49
  code: z.ZodIssueCode.custom,
49
- message: `Can't resolve ${request} against ${moduleRoot}`
50
+ message: `Can't resolve ${request} against ${moduleRoot}`,
50
51
  });
51
52
  return z.NEVER;
52
53
  }
53
54
  return {
54
55
  type: 'absolute-file',
55
- file: result
56
+ file: result,
56
57
  };
57
58
  });
58
59
  }
@@ -75,21 +76,21 @@ export function ResolvedModuleFolder(
75
76
  throw new Error(`Unexpected resolve result ${result} with index file ${idxFile}`);
76
77
  return {
77
78
  type: 'absolute-folder',
78
- folder: result.slice(0, result.length - idxFile.length)
79
+ folder: result.slice(0, result.length - idxFile.length),
79
80
  };
80
81
  }
81
82
  }
82
83
 
83
84
  ctx.addIssue({
84
85
  code: z.ZodIssueCode.custom,
85
- message: `Can't resolve ${request} folder against ${moduleRoot}, no index file found (${indexFilesToLookFor.join(', ')})`
86
+ message: `Can't resolve ${request} folder against ${moduleRoot}, no index file found (${indexFilesToLookFor.join(', ')})`,
86
87
  });
87
88
  return z.NEVER;
88
89
  });
89
90
  }
90
91
 
91
92
  export function mapLocalToAbsolute(
92
- root: string
93
+ root: string,
93
94
  ): <T extends ContentAnyLocal>(value: T) => Exclude<T, ContentRelative> | ContentAbsoluteFile {
94
95
  return <T extends ContentAnyLocal>(value: T) =>
95
96
  value.type === 'relative'
@@ -107,7 +108,7 @@ export function absoluteToString(): (value: ContentAbsoluteTextLocal) => Promise
107
108
 
108
109
  // TODO add type and size limitations
109
110
  export function absoluteToBase64(): (
110
- value: ContentAbsoluteBinaryLocal
111
+ value: ContentAbsoluteBinaryLocal
111
112
  ) => Promise<ContentExplicitBase64> {
112
113
  return async (value) => {
113
114
  if (value.type === 'absolute-file') {
@@ -116,14 +117,14 @@ export function absoluteToBase64(): (
116
117
  return {
117
118
  type: 'explicit-base64',
118
119
  mimeType,
119
- content: await fsp.readFile(value.file, { encoding: 'base64' })
120
+ content: await fsp.readFile(value.file, { encoding: 'base64' }),
120
121
  };
121
122
  } else return value;
122
123
  };
123
124
  }
124
125
 
125
126
  export function absoluteToBytes(): (
126
- value: ContentAbsoluteBinaryLocal
127
+ value: ContentAbsoluteBinaryLocal
127
128
  ) => Promise<ContentExplicitBytes> {
128
129
  return async (value) => {
129
130
  if (value.type === 'absolute-file') {
@@ -132,13 +133,13 @@ export function absoluteToBytes(): (
132
133
  return {
133
134
  type: 'explicit-bytes',
134
135
  mimeType,
135
- content: Buffer.from(await fsp.readFile(value.file))
136
+ content: Buffer.from(await fsp.readFile(value.file)),
136
137
  };
137
138
  } else if (value.type === 'explicit-base64') {
138
139
  return {
139
140
  type: 'explicit-bytes',
140
141
  mimeType: value.mimeType,
141
- content: Buffer.from(value.content, 'base64')
142
+ content: Buffer.from(value.content, 'base64'),
142
143
  };
143
144
  } else return value;
144
145
  };
@@ -146,15 +147,16 @@ export function absoluteToBytes(): (
146
147
 
147
148
  export function cpAbsoluteToRelative(
148
149
  dstFolder: string,
149
- fileAccumulator?: string[]
150
+ fileAccumulator?: string[],
150
151
  ): <T extends Exclude<ContentAnyLocal, ContentRelative>>(
151
- value: T
152
- ) => Promise<Exclude<T, ContentAbsoluteFile> | ContentRelative> {
152
+ value: T
153
+ ) => Promise<Exclude<T, ContentAbsoluteFile> | ContentRelative> {
153
154
  return async <T extends Exclude<ContentAnyLocal, ContentRelative>>(value: T) => {
154
155
  if (value.type === 'absolute-file') {
155
156
  const fileName = path.basename(value.file);
156
157
  const dst = path.resolve(dstFolder, fileName);
157
158
  fileAccumulator?.push(fileName);
159
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
158
160
  await fsp.cp(value.file, dst);
159
161
  return { type: 'relative', path: fileName };
160
162
  } else return value as Exclude<T, ContentAbsoluteFile>;
@@ -164,7 +166,7 @@ export function cpAbsoluteToRelative(
164
166
  export function packFolderToRelativeTgz(
165
167
  dstFolder: string,
166
168
  tgzName: string,
167
- fileAccumulator?: string[]
169
+ fileAccumulator?: string[],
168
170
  ): (value: ContentAbsoluteFolder) => Promise<ContentRelative> {
169
171
  if (!tgzName.endsWith('.tgz')) throw new Error(`Unexpected tgz file name: ${tgzName}`);
170
172
  return async (value: ContentAbsoluteFolder) => {
@@ -173,9 +175,9 @@ export function packFolderToRelativeTgz(
173
175
  {
174
176
  gzip: true,
175
177
  file: dst,
176
- cwd: value.folder
178
+ cwd: value.folder,
177
179
  },
178
- ['.']
180
+ ['.'],
179
181
  );
180
182
  fileAccumulator?.push(tgzName);
181
183
  return { type: 'relative', path: tgzName };
@@ -185,7 +187,7 @@ export function packFolderToRelativeTgz(
185
187
  export type RelativeContentReader = (relativePath: string) => Promise<Buffer>;
186
188
 
187
189
  export function relativeToExplicitString(
188
- reader: RelativeContentReader
190
+ reader: RelativeContentReader,
189
191
  ): (value: ContentRelativeText) => Promise<ContentExplicitString> {
190
192
  return async (value) =>
191
193
  value.type === 'explicit-string'
@@ -194,14 +196,14 @@ export function relativeToExplicitString(
194
196
  }
195
197
 
196
198
  export function relativeToContentString(
197
- reader: RelativeContentReader
199
+ reader: RelativeContentReader,
198
200
  ): (value: ContentRelativeText) => Promise<string> {
199
201
  return async (value) =>
200
202
  value.type === 'explicit-string' ? value.content : (await reader(value.path)).toString('utf8');
201
203
  }
202
204
 
203
205
  export function relativeToExplicitBinary64(
204
- reader: RelativeContentReader
206
+ reader: RelativeContentReader,
205
207
  ): (value: ContentRelativeBinary) => Promise<ContentExplicitBase64> {
206
208
  return async (value) => {
207
209
  if (value.type === 'explicit-base64') return value;
@@ -210,27 +212,27 @@ export function relativeToExplicitBinary64(
210
212
  return {
211
213
  type: 'explicit-base64',
212
214
  mimeType,
213
- content: (await reader(value.path)).toString('base64')
215
+ content: (await reader(value.path)).toString('base64'),
214
216
  };
215
217
  };
216
218
  }
217
219
 
218
220
  export function relativeToExplicitBytes(
219
- reader: RelativeContentReader
221
+ reader: RelativeContentReader,
220
222
  ): (value: ContentRelativeBinary) => Promise<ContentExplicitBytes> {
221
223
  return async (value) => {
222
224
  if (value.type === 'explicit-base64')
223
225
  return {
224
226
  type: 'explicit-bytes',
225
227
  mimeType: value.mimeType,
226
- content: Buffer.from(value.content, 'base64')
228
+ content: Buffer.from(value.content, 'base64'),
227
229
  };
228
230
  const mimeType = mime.lookup(value.path);
229
231
  if (!mimeType) throw new Error(`Can't recognize mime type of the file: ${value.path}.`);
230
232
  return {
231
233
  type: 'explicit-bytes',
232
234
  mimeType,
233
- content: await reader(value.path)
235
+ content: await reader(value.path),
234
236
  };
235
237
  };
236
238
  }
@@ -1,3 +1,3 @@
1
- export * from './registry'
2
- export * from './registry_reader'
3
- export * from './schema_public'
1
+ export * from './registry';
2
+ export * from './registry_reader';
3
+ export * from './schema_public';