@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.
- package/README.md +16 -9
- package/bin/dev.js +4 -4
- package/bin/run.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +16 -6
- package/dist/cli.mjs.map +1 -1
- package/dist/cmd/index.d.ts +8 -8
- package/dist/cmd/mark-stable.d.ts +1 -1
- package/dist/cmd/publish.d.ts +1 -1
- package/dist/cmd/restore-overview-from-snapshot.d.ts +1 -1
- package/dist/{config-DKBY0B2u.mjs → config-Cc8_zV3b.mjs} +48 -17
- package/dist/config-Cc8_zV3b.mjs.map +1 -0
- package/dist/config-Ycas5fbX.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -4
- package/dist/index.mjs.map +1 -1
- package/dist/registry_v1/config_schema.d.ts +7 -7
- package/dist/registry_v1/v1_repo_schema.d.ts +1 -1
- package/dist/v2/model/block_components.d.ts +19 -19
- package/dist/v2/model/block_description.d.ts +102 -102
- package/dist/v2/model/block_meta.d.ts +20 -20
- package/dist/v2/model/content_conversion.d.ts +2 -2
- package/dist/v2/registry/registry.d.ts +1 -1
- package/dist/v2/source_package.d.ts +1 -1
- package/package.json +31 -29
- package/src/cmd/build-meta.ts +15 -15
- package/src/cmd/build-model.ts +23 -26
- package/src/cmd/index.ts +20 -20
- package/src/cmd/list-overview-snapshots.ts +12 -12
- package/src/cmd/mark-stable.ts +30 -33
- package/src/cmd/pack.ts +15 -15
- package/src/cmd/publish.ts +46 -34
- package/src/cmd/refresh-registry.ts +15 -15
- package/src/cmd/restore-overview-from-snapshot.ts +27 -25
- package/src/cmd/update-deps.ts +8 -8
- package/src/cmd/upload-package-v1.ts +33 -33
- package/src/common_types.ts +1 -1
- package/src/io/folder_reader.test.ts +13 -13
- package/src/io/folder_reader.ts +18 -20
- package/src/io/index.ts +2 -2
- package/src/io/storage.test.ts +48 -48
- package/src/io/storage.ts +20 -15
- package/src/lib.ts +3 -3
- package/src/registry_v1/config.ts +11 -11
- package/src/registry_v1/config_schema.ts +5 -5
- package/src/registry_v1/flags.ts +4 -4
- package/src/registry_v1/index.ts +3 -3
- package/src/registry_v1/registry.test.ts +54 -54
- package/src/registry_v1/registry.ts +29 -25
- package/src/registry_v1/v1_repo_schema.ts +3 -3
- package/src/util.ts +6 -9
- package/src/v2/build_dist.test.ts +8 -9
- package/src/v2/build_dist.ts +10 -13
- package/src/v2/index.ts +4 -4
- package/src/v2/model/block_components.ts +5 -5
- package/src/v2/model/block_description.ts +12 -8
- package/src/v2/model/block_meta.ts +4 -5
- package/src/v2/model/content_conversion.ts +44 -44
- package/src/v2/model/index.ts +4 -4
- package/src/v2/registry/index.ts +3 -3
- package/src/v2/registry/registry.test.ts +223 -197
- package/src/v2/registry/registry.ts +93 -66
- package/src/v2/registry/registry_reader.test.ts +15 -15
- package/src/v2/registry/registry_reader.ts +29 -27
- package/src/v2/registry/schema_internal.ts +11 -10
- package/src/v2/registry/schema_public.ts +56 -47
- package/src/v2/source_package.test.ts +15 -15
- package/src/v2/source_package.ts +33 -26
- 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
|
|
15
|
-
import { z } from
|
|
16
|
-
import type { RelativeContentReader } from
|
|
17
|
-
import { relativeToExplicitBytes, relativeToExplicitString } from
|
|
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 =
|
|
18
|
+
export const MainPrefix = "v2/";
|
|
20
19
|
|
|
21
|
-
export const GlobalOverviewFileName =
|
|
22
|
-
export const GlobalOverviewGzFileName =
|
|
23
|
-
export const PackageOverviewFileName =
|
|
24
|
-
export const ManifestFileName =
|
|
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 =
|
|
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 =
|
|
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
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
|
2
|
-
import { loadPackDescription, parsePackageName } from
|
|
1
|
+
import { test, expect } from "vitest";
|
|
2
|
+
import { loadPackDescription, parsePackageName } from "./source_package";
|
|
3
3
|
|
|
4
|
-
test(
|
|
5
|
-
expect(parsePackageName(
|
|
6
|
-
organization:
|
|
7
|
-
name:
|
|
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(
|
|
11
|
-
organization:
|
|
12
|
-
name:
|
|
10
|
+
expect(parsePackageName("milaboratories.block-template")).toStrictEqual({
|
|
11
|
+
organization: "milaboratories",
|
|
12
|
+
name: "block-template",
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
expect(parsePackageName(
|
|
16
|
-
organization:
|
|
17
|
-
name:
|
|
15
|
+
expect(parsePackageName("mi-laboratories.block-template")).toStrictEqual({
|
|
16
|
+
organization: "mi-laboratories",
|
|
17
|
+
name: "block-template",
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
expect(() => parsePackageName(
|
|
20
|
+
expect(() => parsePackageName("block-template")).toThrow(/Malformed/);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
test.skip(
|
|
23
|
+
test.skip("full description parsing test", async () => {
|
|
24
24
|
const description = await loadPackDescription(
|
|
25
|
-
|
|
25
|
+
"/Volumes/Data/Projects/MiLaboratory/blocks-beta/block-template",
|
|
26
26
|
);
|
|
27
27
|
console.dir(description, { depth: 5 });
|
|
28
28
|
});
|
package/src/v2/source_package.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import { tryLoadFile } from
|
|
3
|
-
import type { BlockPackDescriptionAbsolute } from
|
|
4
|
-
import { ResolvedBlockPackDescriptionFromPackageJson } from
|
|
5
|
-
import type { MiLogger } from
|
|
6
|
-
import { notEmpty } from
|
|
7
|
-
import fsp from
|
|
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
|
|
12
|
+
} from "@milaboratories/pl-model-middle-layer";
|
|
15
13
|
|
|
16
|
-
export const BlockDescriptionPackageJsonField =
|
|
14
|
+
export const BlockDescriptionPackageJsonField = "block";
|
|
17
15
|
|
|
18
|
-
const ConventionPackageNamePattern
|
|
19
|
-
|
|
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,
|
|
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,
|
|
33
|
+
const fullPackageJsonPath = path.resolve(moduleRoot, "package.json");
|
|
36
34
|
try {
|
|
37
|
-
const packageJson = await tryLoadFile(
|
|
38
|
-
|
|
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(
|
|
46
|
+
notEmpty(
|
|
47
|
+
packageJson["name"] as string | undefined,
|
|
48
|
+
`"name" not found in ${fullPackageJsonPath}`,
|
|
49
|
+
),
|
|
48
50
|
),
|
|
49
|
-
version: SemVer.parse(packageJson[
|
|
51
|
+
version: SemVer.parse(packageJson["version"]),
|
|
50
52
|
},
|
|
51
53
|
};
|
|
52
|
-
const descriptionParsingResult
|
|
53
|
-
|
|
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,
|
|
65
|
-
const packageJson = JSON.parse(
|
|
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(
|
|
79
|
+
notEmpty(
|
|
80
|
+
packageJson["name"] as string | undefined,
|
|
81
|
+
`"name" not found in ${fullPackageJsonPath}`,
|
|
82
|
+
),
|
|
76
83
|
),
|
|
77
|
-
version: SemVer.parse(packageJson[
|
|
84
|
+
version: SemVer.parse(packageJson["version"]),
|
|
78
85
|
},
|
|
79
86
|
featureFlags: {},
|
|
80
87
|
};
|