@platforma-sdk/block-tools 2.6.44 → 2.6.45

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 (70) hide show
  1. package/README.md +16 -9
  2. package/bin/dev.js +4 -4
  3. package/bin/run.js +3 -3
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cli.mjs +16 -6
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/cmd/index.d.ts +8 -8
  8. package/dist/cmd/mark-stable.d.ts +1 -1
  9. package/dist/cmd/publish.d.ts +1 -1
  10. package/dist/cmd/restore-overview-from-snapshot.d.ts +1 -1
  11. package/dist/{config-DKBY0B2u.mjs → config-Cc8_zV3b.mjs} +48 -17
  12. package/dist/config-Cc8_zV3b.mjs.map +1 -0
  13. package/dist/config-Ycas5fbX.js.map +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +6 -4
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/registry_v1/config_schema.d.ts +7 -7
  19. package/dist/registry_v1/v1_repo_schema.d.ts +1 -1
  20. package/dist/v2/model/block_components.d.ts +19 -19
  21. package/dist/v2/model/block_description.d.ts +102 -102
  22. package/dist/v2/model/block_meta.d.ts +20 -20
  23. package/dist/v2/model/content_conversion.d.ts +2 -2
  24. package/dist/v2/registry/registry.d.ts +1 -1
  25. package/dist/v2/source_package.d.ts +1 -1
  26. package/package.json +31 -29
  27. package/src/cmd/build-meta.ts +15 -15
  28. package/src/cmd/build-model.ts +23 -26
  29. package/src/cmd/index.ts +20 -20
  30. package/src/cmd/list-overview-snapshots.ts +12 -12
  31. package/src/cmd/mark-stable.ts +30 -33
  32. package/src/cmd/pack.ts +15 -15
  33. package/src/cmd/publish.ts +46 -34
  34. package/src/cmd/refresh-registry.ts +15 -15
  35. package/src/cmd/restore-overview-from-snapshot.ts +27 -25
  36. package/src/cmd/update-deps.ts +8 -8
  37. package/src/cmd/upload-package-v1.ts +33 -33
  38. package/src/common_types.ts +1 -1
  39. package/src/io/folder_reader.test.ts +13 -13
  40. package/src/io/folder_reader.ts +18 -20
  41. package/src/io/index.ts +2 -2
  42. package/src/io/storage.test.ts +48 -48
  43. package/src/io/storage.ts +20 -15
  44. package/src/lib.ts +3 -3
  45. package/src/registry_v1/config.ts +11 -11
  46. package/src/registry_v1/config_schema.ts +5 -5
  47. package/src/registry_v1/flags.ts +4 -4
  48. package/src/registry_v1/index.ts +3 -3
  49. package/src/registry_v1/registry.test.ts +54 -54
  50. package/src/registry_v1/registry.ts +29 -25
  51. package/src/registry_v1/v1_repo_schema.ts +3 -3
  52. package/src/util.ts +6 -9
  53. package/src/v2/build_dist.test.ts +8 -9
  54. package/src/v2/build_dist.ts +10 -13
  55. package/src/v2/index.ts +4 -4
  56. package/src/v2/model/block_components.ts +5 -5
  57. package/src/v2/model/block_description.ts +12 -8
  58. package/src/v2/model/block_meta.ts +4 -5
  59. package/src/v2/model/content_conversion.ts +44 -44
  60. package/src/v2/model/index.ts +4 -4
  61. package/src/v2/registry/index.ts +3 -3
  62. package/src/v2/registry/registry.test.ts +223 -197
  63. package/src/v2/registry/registry.ts +93 -66
  64. package/src/v2/registry/registry_reader.test.ts +15 -15
  65. package/src/v2/registry/registry_reader.ts +29 -27
  66. package/src/v2/registry/schema_internal.ts +11 -10
  67. package/src/v2/registry/schema_public.ts +56 -47
  68. package/src/v2/source_package.test.ts +15 -15
  69. package/src/v2/source_package.ts +33 -26
  70. package/dist/config-DKBY0B2u.mjs.map +0 -1
@@ -1,5 +1,4 @@
1
- import type {
2
- BlockPackId } from '@milaboratories/pl-model-middle-layer';
1
+ import type { BlockPackId } from "@milaboratories/pl-model-middle-layer";
3
2
  import {
4
3
  AnyChannel,
5
4
  BlockComponentsManifest,
@@ -11,19 +10,19 @@ import {
11
10
  CreateBlockPackDescriptionSchema,
12
11
  Sha256Schema,
13
12
  VersionWithChannels,
14
- } from '@milaboratories/pl-model-middle-layer';
15
- import { z } from 'zod';
16
- import type { RelativeContentReader } from '../model';
17
- import { relativeToExplicitBytes, relativeToExplicitString } from '../model';
13
+ } from "@milaboratories/pl-model-middle-layer";
14
+ import { z } from "zod";
15
+ import type { RelativeContentReader } from "../model";
16
+ import { relativeToExplicitBytes, relativeToExplicitString } from "../model";
18
17
 
19
- export const MainPrefix = 'v2/';
18
+ export const MainPrefix = "v2/";
20
19
 
21
- export const GlobalOverviewFileName = 'overview.json';
22
- export const GlobalOverviewGzFileName = 'overview.json.gz';
23
- export const PackageOverviewFileName = 'overview.json';
24
- export const ManifestFileName = 'manifest.json';
20
+ export const GlobalOverviewFileName = "overview.json";
21
+ export const GlobalOverviewGzFileName = "overview.json.gz";
22
+ export const PackageOverviewFileName = "overview.json";
23
+ export const ManifestFileName = "manifest.json";
25
24
 
26
- export const ChannelsFolder = 'channels';
25
+ export const ChannelsFolder = "channels";
27
26
 
28
27
  export const ChannelNameRegexp = /^[-a-z0-9]+$/;
29
28
 
@@ -35,23 +34,27 @@ export function packageContentPrefix(bp: BlockPackId): string {
35
34
  return `${MainPrefix}${packageContentPrefixInsideV2(bp)}`;
36
35
  }
37
36
 
38
- export const ManifestSuffix = '/' + ManifestFileName;
37
+ export const ManifestSuffix = "/" + ManifestFileName;
39
38
 
40
39
  // export function payloadFilePath(bp: BlockPackId, file: string): string {
41
40
  // return `${MainPrefix}${bp.organization}/${bp.name}/${bp.version}/${file}`;
42
41
  // }
43
42
 
44
- export const PackageOverviewVersionEntry = z.object({
45
- description: BlockPackDescriptionManifest,
46
- channels: z.array(z.string()).default(() => []),
47
- manifestSha256: Sha256Schema,
48
- }).passthrough();
43
+ export const PackageOverviewVersionEntry = z
44
+ .object({
45
+ description: BlockPackDescriptionManifest,
46
+ channels: z.array(z.string()).default(() => []),
47
+ manifestSha256: Sha256Schema,
48
+ })
49
+ .passthrough();
49
50
  export type PackageOverviewVersionEntry = z.infer<typeof PackageOverviewVersionEntry>;
50
51
 
51
- export const PackageOverview = z.object({
52
- schema: z.literal('v2'),
53
- versions: z.array(PackageOverviewVersionEntry),
54
- }).passthrough();
52
+ export const PackageOverview = z
53
+ .object({
54
+ schema: z.literal("v2"),
55
+ versions: z.array(PackageOverviewVersionEntry),
56
+ })
57
+ .passthrough();
55
58
  export type PackageOverview = z.infer<typeof PackageOverview>;
56
59
 
57
60
  export function packageOverviewPathInsideV2(bp: BlockPackIdNoVersion): string {
@@ -70,8 +73,8 @@ export function packageChannelPrefix(bp: BlockPackId): string {
70
73
  return `${MainPrefix}${packageChannelPrefixInsideV2(bp)}`;
71
74
  }
72
75
 
73
- export const PackageManifestPattern
74
- = /(?<packageKeyWithoutVersion>(?<organization>[^/]+)\/(?<name>[^/]+))\/(?<version>[^/]+)\/manifest\.json$/;
76
+ export const PackageManifestPattern =
77
+ /(?<packageKeyWithoutVersion>(?<organization>[^/]+)\/(?<name>[^/]+))\/(?<version>[^/]+)\/manifest\.json$/;
75
78
 
76
79
  export const GlobalOverviewPath = `${MainPrefix}${GlobalOverviewFileName}`;
77
80
  export const GlobalOverviewGzPath = `${MainPrefix}${GlobalOverviewGzFileName}`;
@@ -79,25 +82,29 @@ export const GlobalOverviewGzPath = `${MainPrefix}${GlobalOverviewGzFileName}`;
79
82
  export function GlobalOverviewEntry<const Description extends z.ZodTypeAny>(
80
83
  descriptionType: Description,
81
84
  ) {
82
- const universalSchema = z.object({
83
- id: BlockPackIdNoVersion,
84
- /** @deprecated to be removed at some point, not used, left for compatibility with older versions */
85
- allVersions: z.array(z.string()).optional(),
86
- allVersionsWithChannels: z.array(VersionWithChannels).optional(),
87
- /** @deprecated to be removed at some point, not used, left for compatibility with older versions */
88
- latest: descriptionType,
89
- /** @deprecated to be removed at some point, not used, left for compatibility with older versions */
90
- latestManifestSha256: Sha256Schema,
91
- latestByChannel: z
92
- .record(
93
- z.string(),
94
- z.object({
95
- description: descriptionType,
96
- manifestSha256: Sha256Schema,
97
- }).passthrough(),
98
- )
99
- .default({}),
100
- }).passthrough();
85
+ const universalSchema = z
86
+ .object({
87
+ id: BlockPackIdNoVersion,
88
+ /** @deprecated to be removed at some point, not used, left for compatibility with older versions */
89
+ allVersions: z.array(z.string()).optional(),
90
+ allVersionsWithChannels: z.array(VersionWithChannels).optional(),
91
+ /** @deprecated to be removed at some point, not used, left for compatibility with older versions */
92
+ latest: descriptionType,
93
+ /** @deprecated to be removed at some point, not used, left for compatibility with older versions */
94
+ latestManifestSha256: Sha256Schema,
95
+ latestByChannel: z
96
+ .record(
97
+ z.string(),
98
+ z
99
+ .object({
100
+ description: descriptionType,
101
+ manifestSha256: Sha256Schema,
102
+ })
103
+ .passthrough(),
104
+ )
105
+ .default({}),
106
+ })
107
+ .passthrough();
101
108
  return (
102
109
  universalSchema
103
110
  .transform((o) => {
@@ -131,10 +138,12 @@ export type GlobalOverviewEntryReg = z.infer<typeof GlobalOverviewEntryReg>;
131
138
  export function GlobalOverview<const Description extends z.ZodTypeAny>(
132
139
  descriptionType: Description,
133
140
  ) {
134
- return z.object({
135
- schema: z.literal('v2'),
136
- packages: z.array(GlobalOverviewEntry(descriptionType)),
137
- }).passthrough();
141
+ return z
142
+ .object({
143
+ schema: z.literal("v2"),
144
+ packages: z.array(GlobalOverviewEntry(descriptionType)),
145
+ })
146
+ .passthrough();
138
147
  }
139
148
 
140
149
  export const GlobalOverviewReg = GlobalOverview(BlockPackDescriptionManifest);
@@ -1,28 +1,28 @@
1
- import { test, expect } from 'vitest';
2
- import { loadPackDescription, parsePackageName } from './source_package';
1
+ import { test, expect } from "vitest";
2
+ import { loadPackDescription, parsePackageName } from "./source_package";
3
3
 
4
- test('test parsing of convention package names', () => {
5
- expect(parsePackageName('@milaboratory/milaboratories.block-template')).toStrictEqual({
6
- organization: 'milaboratories',
7
- name: 'block-template'
4
+ test("test parsing of convention package names", () => {
5
+ expect(parsePackageName("@milaboratory/milaboratories.block-template")).toStrictEqual({
6
+ organization: "milaboratories",
7
+ name: "block-template",
8
8
  });
9
9
 
10
- expect(parsePackageName('milaboratories.block-template')).toStrictEqual({
11
- organization: 'milaboratories',
12
- name: 'block-template'
10
+ expect(parsePackageName("milaboratories.block-template")).toStrictEqual({
11
+ organization: "milaboratories",
12
+ name: "block-template",
13
13
  });
14
14
 
15
- expect(parsePackageName('mi-laboratories.block-template')).toStrictEqual({
16
- organization: 'mi-laboratories',
17
- name: 'block-template'
15
+ expect(parsePackageName("mi-laboratories.block-template")).toStrictEqual({
16
+ organization: "mi-laboratories",
17
+ name: "block-template",
18
18
  });
19
19
 
20
- expect(() => parsePackageName('block-template')).toThrow(/Malformed/);
20
+ expect(() => parsePackageName("block-template")).toThrow(/Malformed/);
21
21
  });
22
22
 
23
- test.skip('full description parsing test', async () => {
23
+ test.skip("full description parsing test", async () => {
24
24
  const description = await loadPackDescription(
25
- '/Volumes/Data/Projects/MiLaboratory/blocks-beta/block-template'
25
+ "/Volumes/Data/Projects/MiLaboratory/blocks-beta/block-template",
26
26
  );
27
27
  console.dir(description, { depth: 5 });
28
28
  });
@@ -1,24 +1,22 @@
1
- import path from 'node:path';
2
- import { tryLoadFile } from '../util';
3
- import type { BlockPackDescriptionAbsolute } from './model';
4
- import { ResolvedBlockPackDescriptionFromPackageJson } from './model';
5
- import type { MiLogger } from '@milaboratories/ts-helpers';
6
- import { notEmpty } from '@milaboratories/ts-helpers';
7
- import fsp from 'node:fs/promises';
8
- import type {
9
- BlockPackDescriptionRaw,
10
- BlockPackId } from '@milaboratories/pl-model-middle-layer';
1
+ import path from "node:path";
2
+ import { tryLoadFile } from "../util";
3
+ import type { BlockPackDescriptionAbsolute } from "./model";
4
+ import { ResolvedBlockPackDescriptionFromPackageJson } from "./model";
5
+ import type { MiLogger } from "@milaboratories/ts-helpers";
6
+ import { notEmpty } from "@milaboratories/ts-helpers";
7
+ import fsp from "node:fs/promises";
8
+ import type { BlockPackDescriptionRaw, BlockPackId } from "@milaboratories/pl-model-middle-layer";
11
9
  import {
12
10
  BlockPackDescriptionFromPackageJsonRaw,
13
11
  SemVer,
14
- } from '@milaboratories/pl-model-middle-layer';
12
+ } from "@milaboratories/pl-model-middle-layer";
15
13
 
16
- export const BlockDescriptionPackageJsonField = 'block';
14
+ export const BlockDescriptionPackageJsonField = "block";
17
15
 
18
- const ConventionPackageNamePattern
19
- = /(?:@[a-zA-Z0-9-.]+\/)?(?<organization>[a-zA-Z0-9-]+)\.(?<name>[a-zA-Z0-9-]+)/;
16
+ const ConventionPackageNamePattern =
17
+ /(?:@[a-zA-Z0-9-.]+\/)?(?<organization>[a-zA-Z0-9-]+)\.(?<name>[a-zA-Z0-9-]+)/;
20
18
 
21
- export function parsePackageName(packageName: string): Pick<BlockPackId, 'organization' | 'name'> {
19
+ export function parsePackageName(packageName: string): Pick<BlockPackId, "organization" | "name"> {
22
20
  const match = packageName.match(ConventionPackageNamePattern);
23
21
  if (!match)
24
22
  throw new Error(
@@ -32,10 +30,11 @@ export async function tryLoadPackDescription(
32
30
  moduleRoot: string,
33
31
  logger?: MiLogger,
34
32
  ): Promise<BlockPackDescriptionAbsolute | undefined> {
35
- const fullPackageJsonPath = path.resolve(moduleRoot, 'package.json');
33
+ const fullPackageJsonPath = path.resolve(moduleRoot, "package.json");
36
34
  try {
37
- const packageJson = await tryLoadFile(fullPackageJsonPath, (buf) =>
38
- JSON.parse(buf.toString('utf-8')) as Record<string, unknown>,
35
+ const packageJson = await tryLoadFile(
36
+ fullPackageJsonPath,
37
+ (buf) => JSON.parse(buf.toString("utf-8")) as Record<string, unknown>,
39
38
  );
40
39
  if (packageJson === undefined) return undefined;
41
40
  const descriptionNotParsed = packageJson[BlockDescriptionPackageJsonField];
@@ -44,13 +43,16 @@ export async function tryLoadPackDescription(
44
43
  ...BlockPackDescriptionFromPackageJsonRaw.parse(descriptionNotParsed),
45
44
  id: {
46
45
  ...parsePackageName(
47
- notEmpty(packageJson['name'] as string | undefined, `"name" not found in ${fullPackageJsonPath}`),
46
+ notEmpty(
47
+ packageJson["name"] as string | undefined,
48
+ `"name" not found in ${fullPackageJsonPath}`,
49
+ ),
48
50
  ),
49
- version: SemVer.parse(packageJson['version']),
51
+ version: SemVer.parse(packageJson["version"]),
50
52
  },
51
53
  };
52
- const descriptionParsingResult
53
- = await ResolvedBlockPackDescriptionFromPackageJson(moduleRoot).safeParseAsync(descriptionRaw);
54
+ const descriptionParsingResult =
55
+ await ResolvedBlockPackDescriptionFromPackageJson(moduleRoot).safeParseAsync(descriptionRaw);
54
56
  if (descriptionParsingResult.success) return descriptionParsingResult.data;
55
57
  logger?.warn(descriptionParsingResult.error);
56
58
  return undefined;
@@ -61,8 +63,10 @@ export async function tryLoadPackDescription(
61
63
  }
62
64
 
63
65
  export async function loadPackDescriptionRaw(moduleRoot: string): Promise<BlockPackDescriptionRaw> {
64
- const fullPackageJsonPath = path.resolve(moduleRoot, 'package.json');
65
- const packageJson = JSON.parse(await fsp.readFile(fullPackageJsonPath, { encoding: 'utf-8' })) as Record<string, unknown>;
66
+ const fullPackageJsonPath = path.resolve(moduleRoot, "package.json");
67
+ const packageJson = JSON.parse(
68
+ await fsp.readFile(fullPackageJsonPath, { encoding: "utf-8" }),
69
+ ) as Record<string, unknown>;
66
70
  const descriptionNotParsed = packageJson[BlockDescriptionPackageJsonField];
67
71
  if (descriptionNotParsed === undefined)
68
72
  throw new Error(
@@ -72,9 +76,12 @@ export async function loadPackDescriptionRaw(moduleRoot: string): Promise<BlockP
72
76
  ...BlockPackDescriptionFromPackageJsonRaw.parse(descriptionNotParsed),
73
77
  id: {
74
78
  ...parsePackageName(
75
- notEmpty(packageJson['name'] as string | undefined, `"name" not found in ${fullPackageJsonPath}`),
79
+ notEmpty(
80
+ packageJson["name"] as string | undefined,
81
+ `"name" not found in ${fullPackageJsonPath}`,
82
+ ),
76
83
  ),
77
- version: SemVer.parse(packageJson['version']),
84
+ version: SemVer.parse(packageJson["version"]),
78
85
  },
79
86
  featureFlags: {},
80
87
  };