@platforma-sdk/block-tools 2.1.10 → 2.2.0
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 +266 -80
- package/dist/cli.mjs.map +1 -1
- package/dist/cmd/index.d.ts +2 -0
- package/dist/cmd/index.d.ts.map +1 -1
- package/dist/cmd/publish.d.ts +11 -0
- package/dist/cmd/publish.d.ts.map +1 -0
- package/dist/config-DJqN5LSx.js +3 -0
- package/dist/config-DJqN5LSx.js.map +1 -0
- package/dist/{config-jteHItEq.mjs → config-rGaQLD-7.mjs} +634 -609
- package/dist/config-rGaQLD-7.mjs.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +29 -27
- package/dist/registry_v1/config_schema.d.ts +13 -13
- package/dist/v2/build_dist.d.ts +2 -1
- package/dist/v2/build_dist.d.ts.map +1 -1
- package/dist/v2/model/block_components.d.ts +169 -177
- package/dist/v2/model/block_components.d.ts.map +1 -1
- package/dist/v2/model/block_description.d.ts +2873 -0
- package/dist/v2/model/block_description.d.ts.map +1 -0
- package/dist/v2/model/{meta.d.ts → block_meta.d.ts} +1 -1
- package/dist/v2/model/block_meta.d.ts.map +1 -0
- package/dist/v2/model/content_conversion.d.ts +5 -2
- package/dist/v2/model/content_conversion.d.ts.map +1 -1
- package/dist/v2/model/index.d.ts +3 -2079
- package/dist/v2/model/index.d.ts.map +1 -1
- package/dist/v2/registry/registry.d.ts +16 -0
- package/dist/v2/registry/registry.d.ts.map +1 -0
- package/dist/v2/registry/schema_internal.d.ts +7 -0
- package/dist/v2/registry/schema_internal.d.ts.map +1 -0
- package/dist/v2/registry/schema_public.d.ts +2828 -0
- package/dist/v2/registry/schema_public.d.ts.map +1 -0
- package/package.json +11 -10
- package/src/cmd/build-meta.ts +1 -1
- package/src/cmd/index.ts +2 -0
- package/src/cmd/publish.ts +69 -0
- package/src/registry_v1/registry.ts +1 -1
- package/src/v2/build_dist.ts +16 -12
- package/src/v2/model/block_components.ts +14 -10
- package/src/v2/model/block_description.ts +49 -0
- package/src/v2/model/{meta.ts → block_meta.ts} +1 -1
- package/src/v2/model/content_conversion.ts +50 -21
- package/src/v2/model/index.ts +3 -44
- package/src/v2/registry/registry.ts +233 -0
- package/src/v2/registry/schema_internal.ts +13 -0
- package/src/v2/registry/schema_public.ts +90 -0
- package/dist/config-B8NlJ02C.js +0 -3
- package/dist/config-B8NlJ02C.js.map +0 -1
- package/dist/config-jteHItEq.mjs.map +0 -1
- package/dist/v2/model/common.d.ts +0 -3
- package/dist/v2/model/common.d.ts.map +0 -1
- package/dist/v2/model/content_types.d.ts +0 -478
- package/dist/v2/model/content_types.d.ts.map +0 -1
- package/dist/v2/model/meta.d.ts.map +0 -1
- package/dist/v2/registry/schema.d.ts +0 -15
- package/dist/v2/registry/schema.d.ts.map +0 -1
- package/src/v2/model/common.ts +0 -2
- package/src/v2/model/content_types.ts +0 -233
- package/src/v2/registry/schema.ts +0 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema_public.d.ts","sourceRoot":"","sources":["../../../src/v2/registry/schema_public.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EACX,oBAAoB,EAKrB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAmD,MAAM,UAAU,CAAC;AAIlG,eAAO,MAAM,gBAAgB,kBAAkB,CAAC;AAEhD,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,WAAW,GAAG,MAAM,CAE5D;AAED,eAAO,MAAM,cAAc,QAAyB,CAAC;AAMrD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAUjF;AACD,MAAM,MAAM,kCAAkC,GAAG,CAAC,CAAC,KAAK,CACtD,UAAU,CAAC,OAAO,oCAAoC,CAAC,CACxD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/block-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
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,23 +23,24 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "UNLICENSED",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@aws-sdk/client-s3": "^3.
|
|
27
|
-
"@oclif/core": "^4.0.
|
|
26
|
+
"@aws-sdk/client-s3": "^3.658.1",
|
|
27
|
+
"@oclif/core": "^4.0.23",
|
|
28
28
|
"mime-types": "^2.1.35",
|
|
29
29
|
"tar": "^7.4.3",
|
|
30
30
|
"yaml": "^2.5.1",
|
|
31
31
|
"zod": "^3.23.8",
|
|
32
|
-
"@milaboratories/
|
|
33
|
-
"@milaboratories/
|
|
34
|
-
"@milaboratories/ts-helpers
|
|
32
|
+
"@milaboratories/resolve-helper": "^1.0.1",
|
|
33
|
+
"@milaboratories/pl-model-middle-layer": "^1.3.0",
|
|
34
|
+
"@milaboratories/ts-helpers": "^1.0.26",
|
|
35
|
+
"@milaboratories/ts-helpers-oclif": "^1.1.4"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"semver": "^7.6.3",
|
|
38
38
|
"typescript": "~5.5.4",
|
|
39
|
-
"vite": "^5.4.
|
|
39
|
+
"vite": "^5.4.8",
|
|
40
40
|
"rollup-plugin-node-externals": "^7.1.3",
|
|
41
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
42
|
-
"vite-plugin-dts": "^4.2.
|
|
41
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
42
|
+
"vite-plugin-dts": "^4.2.2",
|
|
43
|
+
"semver": "^7.6.3",
|
|
43
44
|
"@types/jest": "^29.5.13",
|
|
44
45
|
"@types/mime-types": "^2.1.4",
|
|
45
46
|
"@types/node": "~20.16.5",
|
package/src/cmd/build-meta.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Command, Flags } from '@oclif/core';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { loadPackDescriptionRaw } from '../v2';
|
|
5
|
-
import { BlockPackMetaDescription, BlockPackMetaEmbed } from '../v2/model/
|
|
5
|
+
import { BlockPackMetaDescription, BlockPackMetaEmbed } from '../v2/model/block_meta';
|
|
6
6
|
|
|
7
7
|
export default class BuildMeta extends Command {
|
|
8
8
|
static override description =
|
package/src/cmd/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BuildMeta from './build-meta';
|
|
2
2
|
import BuildModel from './build-model';
|
|
3
3
|
import PackBlock from './pack-block';
|
|
4
|
+
import Publish from './publish';
|
|
4
5
|
import UploadPackageV1 from './upload-package-v1';
|
|
5
6
|
|
|
6
7
|
// prettier-ignore
|
|
@@ -9,4 +10,5 @@ export const COMMANDS = {
|
|
|
9
10
|
'pack': PackBlock,
|
|
10
11
|
'build-model': BuildModel,
|
|
11
12
|
'build-meta': BuildMeta,
|
|
13
|
+
'publish': Publish,
|
|
12
14
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { OclifLoggerAdapter } from '@milaboratories/ts-helpers-oclif';
|
|
4
|
+
import { ManifestFileName } from '../v2/registry/schema_public';
|
|
5
|
+
import { BlockPackManifest } from '@milaboratories/pl-model-middle-layer';
|
|
6
|
+
import { storageByUrl } from '../lib/storage';
|
|
7
|
+
import { BlockRegistryV2 } from '../v2/registry/registry';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
export default class Publish extends Command {
|
|
11
|
+
static description =
|
|
12
|
+
'Publishes the block package and refreshes the registry (for v2 block-pack schema)';
|
|
13
|
+
|
|
14
|
+
static flags = {
|
|
15
|
+
registry: Flags.string({
|
|
16
|
+
char: 'r',
|
|
17
|
+
summary: 'full address of the registry',
|
|
18
|
+
helpValue: '<address>',
|
|
19
|
+
env: 'PL_REGISTRY',
|
|
20
|
+
required: true
|
|
21
|
+
}),
|
|
22
|
+
|
|
23
|
+
manifest: Flags.file({
|
|
24
|
+
char: 'm',
|
|
25
|
+
summary: 'manifest file path',
|
|
26
|
+
exists: true,
|
|
27
|
+
default: `./block-pack/${ManifestFileName}`
|
|
28
|
+
}),
|
|
29
|
+
|
|
30
|
+
refresh: Flags.boolean({
|
|
31
|
+
summary: 'refresh repository after adding the package',
|
|
32
|
+
default: true,
|
|
33
|
+
allowNo: true,
|
|
34
|
+
env: 'PL_REGISTRY_REFRESH'
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
public async run(): Promise<void> {
|
|
39
|
+
const { flags } = await this.parse(Publish);
|
|
40
|
+
|
|
41
|
+
// if (flags.meta) {
|
|
42
|
+
// if (flags.meta.endsWith('.json'))
|
|
43
|
+
// configFromFlags.meta = JSON.parse(
|
|
44
|
+
// await fs.promises.readFile(flags.meta, { encoding: 'utf-8' })
|
|
45
|
+
// );
|
|
46
|
+
// else if (flags.meta.endsWith('.yaml'))
|
|
47
|
+
// configFromFlags.meta = YAML.parse(
|
|
48
|
+
// await fs.promises.readFile(flags.meta, { encoding: 'utf-8' })
|
|
49
|
+
// );
|
|
50
|
+
// }
|
|
51
|
+
|
|
52
|
+
const manifestPath = path.resolve(flags.manifest);
|
|
53
|
+
const manifest = BlockPackManifest.parse(
|
|
54
|
+
JSON.parse(await fs.promises.readFile(manifestPath, { encoding: 'utf-8' }))
|
|
55
|
+
);
|
|
56
|
+
const manifestRoot = path.dirname(manifestPath);
|
|
57
|
+
|
|
58
|
+
this.log(`Manifest root = ${manifestRoot}`);
|
|
59
|
+
|
|
60
|
+
const storage = storageByUrl(flags.registry);
|
|
61
|
+
const registry = new BlockRegistryV2(storage, new OclifLoggerAdapter(this));
|
|
62
|
+
|
|
63
|
+
await registry.publishPackage(manifest, async (file) =>
|
|
64
|
+
Buffer.from(await fs.promises.readFile(path.resolve(manifestRoot, file)))
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
if (flags.refresh) await registry.updateIfNeeded();
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/v2/build_dist.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
BlockPackDescriptionAbsolute,
|
|
3
|
-
BlockPackDescriptionConsolidateToFolder,
|
|
4
2
|
BlockPackDescriptionManifest,
|
|
5
3
|
BlockPackManifest,
|
|
6
|
-
BlockPackManifestFile
|
|
7
|
-
|
|
4
|
+
BlockPackManifestFile,
|
|
5
|
+
ManifestFileInfo
|
|
6
|
+
} from '@milaboratories/pl-model-middle-layer';
|
|
7
|
+
import { BlockPackDescriptionAbsolute, BlockPackDescriptionConsolidateToFolder } from './model';
|
|
8
8
|
import fsp from 'node:fs/promises';
|
|
9
|
-
import { BlockPackMetaConsolidate, BlockPackMetaDescription } from './model/meta';
|
|
10
|
-
import { patch } from 'semver';
|
|
11
9
|
import path from 'node:path';
|
|
12
10
|
|
|
13
11
|
export async function buildBlockPackDist(
|
|
@@ -16,14 +14,20 @@ export async function buildBlockPackDist(
|
|
|
16
14
|
): Promise<BlockPackManifest> {
|
|
17
15
|
await fsp.mkdir(dst, { recursive: true });
|
|
18
16
|
const files: string[] = [];
|
|
19
|
-
const descriptionRelative =
|
|
20
|
-
description
|
|
17
|
+
const descriptionRelative: BlockPackDescriptionManifest =
|
|
18
|
+
await BlockPackDescriptionConsolidateToFolder(dst, files).parseAsync(description);
|
|
19
|
+
const filesForManifest = await Promise.all(
|
|
20
|
+
files.map(async (f): Promise<ManifestFileInfo> => {
|
|
21
|
+
const bytes = await fsp.readFile(path.resolve(dst, f));
|
|
22
|
+
const sha256 = Buffer.from(await crypto.subtle.digest('sha-256', bytes)).toString('hex');
|
|
23
|
+
return { name: f, size: bytes.length, sha256 };
|
|
24
|
+
})
|
|
21
25
|
);
|
|
22
26
|
const manifest: BlockPackManifest = BlockPackManifest.parse({
|
|
23
|
-
schema: '
|
|
24
|
-
|
|
25
|
-
files
|
|
26
|
-
});
|
|
27
|
+
schema: 'v2',
|
|
28
|
+
description: descriptionRelative,
|
|
29
|
+
files: filesForManifest
|
|
30
|
+
} satisfies BlockPackManifest);
|
|
27
31
|
await fsp.writeFile(path.resolve(dst, BlockPackManifestFile), JSON.stringify(manifest));
|
|
28
32
|
return manifest;
|
|
29
33
|
}
|
|
@@ -3,10 +3,14 @@ import {
|
|
|
3
3
|
ResolvedModuleFile,
|
|
4
4
|
ResolvedModuleFolder,
|
|
5
5
|
packFolderToRelativeTgz,
|
|
6
|
-
cpAbsoluteToRelative
|
|
7
|
-
mapRemoteToAbsolute,
|
|
6
|
+
cpAbsoluteToRelative
|
|
8
7
|
} from './content_conversion';
|
|
9
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
BlockComponents,
|
|
10
|
+
BlockComponentsManifest,
|
|
11
|
+
ContentAbsoluteBinaryLocal,
|
|
12
|
+
ContentAbsoluteFolder
|
|
13
|
+
} from '@milaboratories/pl-model-middle-layer';
|
|
10
14
|
|
|
11
15
|
export function BlockComponentsDescription(moduleRoot: string) {
|
|
12
16
|
return BlockComponents(
|
|
@@ -23,10 +27,10 @@ export function BlockComponentsConsolidate(dstFolder: string, fileAccumulator?:
|
|
|
23
27
|
).pipe(BlockComponentsManifest);
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
export function BlockComponentsAbsoluteUrl(prefix: string) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
export type BlockComponentsAbsolute = z.infer<ReturnType<typeof BlockComponentsAbsoluteUrl>>;
|
|
30
|
+
// export function BlockComponentsAbsoluteUrl(prefix: string) {
|
|
31
|
+
// return BlockComponents(
|
|
32
|
+
// ContentRelativeBinary.transform(mapRemoteToAbsolute(prefix)),
|
|
33
|
+
// ContentRelativeBinary.transform(mapRemoteToAbsolute(prefix))
|
|
34
|
+
// );
|
|
35
|
+
// }
|
|
36
|
+
// export type BlockComponentsAbsolute = z.infer<ReturnType<typeof BlockComponentsAbsoluteUrl>>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addPrefixToRelative,
|
|
3
|
+
BlockComponents,
|
|
4
|
+
BlockPackDescriptionManifest,
|
|
5
|
+
BlockPackMeta,
|
|
6
|
+
ContentRelative,
|
|
7
|
+
ContentRelativeBinary,
|
|
8
|
+
ContentRelativeText,
|
|
9
|
+
CreateBlockPackDescriptionSchema
|
|
10
|
+
} from '@milaboratories/pl-model-middle-layer';
|
|
11
|
+
import { BlockComponentsConsolidate, BlockComponentsDescription } from './block_components';
|
|
12
|
+
import { BlockPackMetaConsolidate, BlockPackMetaDescription } from './block_meta';
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
|
|
15
|
+
export function ResolvedBlockPackDescriptionFromPackageJson(root: string) {
|
|
16
|
+
return CreateBlockPackDescriptionSchema(
|
|
17
|
+
BlockComponentsDescription(root),
|
|
18
|
+
BlockPackMetaDescription(root)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
export type BlockPackDescriptionAbsolute = z.infer<
|
|
22
|
+
ReturnType<typeof ResolvedBlockPackDescriptionFromPackageJson>
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
export function BlockPackDescriptionConsolidateToFolder(
|
|
26
|
+
dstFolder: string,
|
|
27
|
+
fileAccumulator?: string[]
|
|
28
|
+
) {
|
|
29
|
+
return CreateBlockPackDescriptionSchema(
|
|
30
|
+
BlockComponentsConsolidate(dstFolder, fileAccumulator),
|
|
31
|
+
BlockPackMetaConsolidate(dstFolder, fileAccumulator)
|
|
32
|
+
).pipe(BlockPackDescriptionManifest);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function BlockPackDescriptionManifestAddRelativePathPrefix(prefix: string) {
|
|
36
|
+
const transformer = addPrefixToRelative(prefix);
|
|
37
|
+
return BlockPackDescriptionManifest.pipe(
|
|
38
|
+
CreateBlockPackDescriptionSchema(
|
|
39
|
+
BlockComponents(
|
|
40
|
+
ContentRelative.transform(transformer),
|
|
41
|
+
ContentRelative.transform(transformer)
|
|
42
|
+
),
|
|
43
|
+
BlockPackMeta(
|
|
44
|
+
ContentRelativeText.transform(transformer),
|
|
45
|
+
ContentRelativeBinary.transform(transformer)
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
).pipe(BlockPackDescriptionManifest);
|
|
49
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BlockPackMeta,
|
|
3
|
+
BlockPackMetaEmbeddedContent,
|
|
3
4
|
ContentAbsoluteBinaryLocal,
|
|
4
5
|
ContentAbsoluteTextLocal,
|
|
5
6
|
DescriptionContentBinary,
|
|
@@ -12,7 +13,6 @@ import {
|
|
|
12
13
|
mapLocalToAbsolute
|
|
13
14
|
} from './content_conversion';
|
|
14
15
|
import { z } from 'zod';
|
|
15
|
-
import { BlockPackMetaEmbeddedContent } from '@milaboratories/pl-model-middle-layer';
|
|
16
16
|
|
|
17
17
|
export function BlockPackMetaDescription(root: string) {
|
|
18
18
|
return BlockPackMeta(
|
|
@@ -8,11 +8,15 @@ import {
|
|
|
8
8
|
ContentAbsoluteFile,
|
|
9
9
|
ContentAbsoluteFolder,
|
|
10
10
|
ContentAbsoluteTextLocal,
|
|
11
|
-
ContentAbsoluteUrl,
|
|
12
11
|
ContentAnyLocal,
|
|
13
12
|
ContentExplicitBase64,
|
|
14
|
-
|
|
13
|
+
ContentExplicitBytes,
|
|
14
|
+
ContentExplicitString,
|
|
15
|
+
ContentRelative,
|
|
16
|
+
ContentRelativeBinary,
|
|
17
|
+
ContentRelativeText
|
|
15
18
|
} from '@milaboratories/pl-model-middle-layer';
|
|
19
|
+
import { tryResolve } from '@milaboratories/resolve-helper';
|
|
16
20
|
|
|
17
21
|
type ContentCtxFs = {
|
|
18
22
|
type: 'local';
|
|
@@ -29,17 +33,6 @@ type ContentCtxUrl = {
|
|
|
29
33
|
/** Describes a place relative to which any content references should be interpreted */
|
|
30
34
|
export type ContentCtx = ContentCtxFs | ContentCtxUrl;
|
|
31
35
|
|
|
32
|
-
function tryResolve(root: string, request: string): string | undefined {
|
|
33
|
-
try {
|
|
34
|
-
return require.resolve(request, {
|
|
35
|
-
paths: [root]
|
|
36
|
-
});
|
|
37
|
-
} catch (err: any) {
|
|
38
|
-
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
|
39
|
-
}
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
36
|
function mustResolve(root: string, request: string): string {
|
|
44
37
|
const res = tryResolve(root, request);
|
|
45
38
|
if (res === undefined) throw new Error(`Can't resolve ${request} against ${root}`);
|
|
@@ -167,12 +160,48 @@ export function packFolderToRelativeTgz(
|
|
|
167
160
|
};
|
|
168
161
|
}
|
|
169
162
|
|
|
170
|
-
export
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
163
|
+
export type RelativeContentReader = (relativePath: string) => Promise<Buffer>;
|
|
164
|
+
|
|
165
|
+
export function relativeToExplicitText(
|
|
166
|
+
reader: RelativeContentReader
|
|
167
|
+
): (value: ContentRelativeText) => Promise<ContentExplicitString> {
|
|
168
|
+
return async (value) =>
|
|
169
|
+
value.type === 'explicit-string'
|
|
170
|
+
? value
|
|
171
|
+
: { type: 'explicit-string', content: (await reader(value.path)).toString('utf8') };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function relativeToExplicitBinary64(
|
|
175
|
+
reader: RelativeContentReader
|
|
176
|
+
): (value: ContentRelativeBinary) => Promise<ContentExplicitBase64> {
|
|
177
|
+
return async (value) => {
|
|
178
|
+
if (value.type === 'explicit-base64') return value;
|
|
179
|
+
const mimeType = mime.lookup(value.path);
|
|
180
|
+
if (!mimeType) throw new Error(`Can't recognize mime type of the file: ${value.path}.`);
|
|
181
|
+
return {
|
|
182
|
+
type: 'explicit-base64',
|
|
183
|
+
mimeType,
|
|
184
|
+
content: (await reader(value.path)).toString('base64')
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function relativeToExplicitBytes(
|
|
190
|
+
reader: RelativeContentReader
|
|
191
|
+
): (value: ContentRelativeBinary) => Promise<ContentExplicitBytes> {
|
|
192
|
+
return async (value) => {
|
|
193
|
+
if (value.type === 'explicit-base64')
|
|
194
|
+
return {
|
|
195
|
+
type: 'explicit-bytes',
|
|
196
|
+
mimeType: value.mimeType,
|
|
197
|
+
content: Buffer.from(value.content, 'base64')
|
|
198
|
+
};
|
|
199
|
+
const mimeType = mime.lookup(value.path);
|
|
200
|
+
if (!mimeType) throw new Error(`Can't recognize mime type of the file: ${value.path}.`);
|
|
201
|
+
return {
|
|
202
|
+
type: 'explicit-bytes',
|
|
203
|
+
mimeType,
|
|
204
|
+
content: await reader(value.path)
|
|
205
|
+
};
|
|
206
|
+
};
|
|
178
207
|
}
|
package/src/v2/model/index.ts
CHANGED
|
@@ -1,46 +1,5 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { BlockComponentsConsolidate, BlockComponentsDescription } from './block_components';
|
|
3
|
-
import {
|
|
4
|
-
BlockComponentsManifest,
|
|
5
|
-
BlockPackMetaManifest,
|
|
6
|
-
CreateBlockPackDescriptionSchema
|
|
7
|
-
} from '@milaboratories/pl-model-middle-layer';
|
|
8
|
-
import { BlockPackMetaConsolidate, BlockPackMetaDescription } from './meta';
|
|
9
|
-
|
|
10
|
-
export * from './block_components';
|
|
11
1
|
export * from './content_conversion';
|
|
12
2
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
BlockPackMetaDescription(root)
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
export type BlockPackDescriptionAbsolute = z.infer<
|
|
20
|
-
ReturnType<typeof ResolvedBlockPackDescriptionFromPackageJson>
|
|
21
|
-
>;
|
|
22
|
-
|
|
23
|
-
export function BlockPackDescriptionConsolidateToFolder(
|
|
24
|
-
dstFolder: string,
|
|
25
|
-
fileAccumulator?: string[]
|
|
26
|
-
) {
|
|
27
|
-
return CreateBlockPackDescriptionSchema(
|
|
28
|
-
BlockComponentsConsolidate(dstFolder, fileAccumulator),
|
|
29
|
-
//BlockPackMetaToExplicit
|
|
30
|
-
BlockPackMetaConsolidate(dstFolder, fileAccumulator)
|
|
31
|
-
).pipe(BlockPackDescriptionManifest);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const BlockPackDescriptionManifest = CreateBlockPackDescriptionSchema(
|
|
35
|
-
BlockComponentsManifest,
|
|
36
|
-
BlockPackMetaManifest
|
|
37
|
-
);
|
|
38
|
-
export type BlockPackDescriptionManifest = z.infer<typeof BlockPackDescriptionManifest>;
|
|
39
|
-
|
|
40
|
-
export const BlockPackManifest = BlockPackDescriptionManifest.extend({
|
|
41
|
-
schema: z.literal('v1'),
|
|
42
|
-
files: z.array(z.string())
|
|
43
|
-
});
|
|
44
|
-
export type BlockPackManifest = z.infer<typeof BlockPackManifest>;
|
|
45
|
-
|
|
46
|
-
export const BlockPackManifestFile = 'manifest.json';
|
|
3
|
+
export * from './block_meta';
|
|
4
|
+
export * from './block_components';
|
|
5
|
+
export * from './block_description';
|