@platforma-sdk/block-tools 2.22.6 → 2.24.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 +2 -2
- package/dist/cli.mjs +29 -29
- package/dist/cli.mjs.map +1 -1
- package/dist/config-CTcfHBGp.js +2 -0
- package/dist/config-CTcfHBGp.js.map +1 -0
- package/dist/{config-BusBoNIz.mjs → config-DlXp1y4o.mjs} +563 -515
- package/dist/config-DlXp1y4o.mjs.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +15 -15
- package/dist/index.mjs.map +1 -1
- package/dist/io/folder_reader.d.ts +9 -0
- package/dist/v2/kind/resolve-refs.d.ts +2 -0
- package/dist/v2/registry/registry_reader.d.ts +36 -2
- package/dist/v2/registry/schema_kinds.d.ts +13 -1
- package/package.json +3 -3
- package/src/io/folder_reader.ts +17 -1
- package/src/v2/build_kind_dist.test.ts +36 -0
- package/src/v2/build_kind_dist.ts +6 -2
- package/src/v2/kind/resolve-refs.ts +3 -1
- package/src/v2/registry/registry.test.ts +85 -2
- package/src/v2/registry/registry_reader.test.ts +108 -2
- package/src/v2/registry/registry_reader.ts +112 -12
- package/src/v2/registry/schema_kinds.ts +14 -1
- package/dist/config-BusBoNIz.mjs.map +0 -1
- package/dist/config-DG4SQFXv.js +0 -2
- package/dist/config-DG4SQFXv.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./config-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./config-CTcfHBGp.js");let t=require("@platforma-sdk/package-builder-lib");var n=e.Qt({GlobalOverviewPath:()=>e.r,MetaFile:()=>e.i,PlPackageConfigData:()=>e.c,PlPackageJsonConfigFile:()=>e.l,PlPackageYamlConfigFile:()=>e.u,PlRegCommonConfigData:()=>e.d,PlRegFullPackageConfigData:()=>e.f,PlRegPackageConfig:()=>e.t,PlRegPackageConfigDataShard:()=>e.p,packageContentPrefix:()=>e.a,packageOverviewPath:()=>e.o,payloadFilePath:()=>e.s});exports.BlockDescriptionPackageJsonField=e.yt,exports.BlockPackFolderName=e.bt,exports.BlockRegistryV2=e.w,exports.ChannelNameRegexp=e.T,exports.ChannelsFolder=e.E,Object.defineProperty(exports,"FSStorage",{enumerable:!0,get:function(){return t.FSStorage}}),exports.FileNotFoundError=e.x,Object.defineProperty(exports,"GcsStorage",{enumerable:!0,get:function(){return t.GcsStorage}}),exports.GlobalOverviewFileName=e.D,exports.GlobalOverviewGzFileName=e.O,exports.GlobalOverviewGzPath=e.k,exports.GlobalOverviewPath=e.A,exports.KindContractFileName=e.it,exports.KindDeclarationFileName=e.at,exports.KindImplementer=e.ot,exports.KindManifest=e.st,exports.KindManifestFile=e.nt,exports.KindManifestFileInfo=e.ct,exports.KindManifestFileName=e.lt,exports.KindManifestIdentity=e.ut,exports.KindOverview=e.dt,exports.KindOverviewFileName=e.ft,exports.KindOverviewPathPattern=e.pt,exports.KindResolutionError=e._,exports.KindVersionMismatchError=e.Z,exports.KindVersionOverview=e.mt,exports.KindsPrefix=e.ht,exports.MainPrefix=e.j,exports.ManifestFileName=e.M,exports.ManifestSuffix=e.N,exports.PackageManifestPattern=e.P,exports.PackageOverview=e.F,exports.PackageOverviewFileName=e.I,exports.PackageOverviewVersionEntry=e.L,exports.PublishedCoordsFileName=e.K,exports.RegistryReadError=e.m,Object.defineProperty(exports,"RegistryV1",{enumerable:!0,get:function(){return n}}),exports.RegistryV2Reader=e.h,Object.defineProperty(exports,"S3Storage",{enumerable:!0,get:function(){return t.S3Storage}}),exports.absoluteToBase64=e.Bt,exports.absoluteToBytes=e.Vt,exports.absoluteToString=e.Ht,exports.addRelativePathPrefix=e.Dt,exports.blockComponentsManifestToAbsoluteUrl=e.At,exports.buildBlockPackDist=e.Et,exports.buildKindDist=e.rt,exports.buildPublishedCoords=e.q,exports.checkKindVersionMatch=e.Q,exports.consolidateBlockComponents=e.jt,exports.consolidateBlockPackDescription=e.Ot,exports.consolidateBlockPackMeta=e.Pt,exports.cpAbsoluteToRelative=e.Ut,exports.embedBlockPackMetaAbsoluteBase64=e.Ft,exports.embedBlockPackMetaAbsoluteBytes=e.It,exports.embedBlockPackMetaBytes=e.Lt,exports.folderReaderByUrl=e.S,exports.inferUpdateSuggestions=e.g,exports.isFileNotFound=e.C,exports.kindContentPrefix=e.gt,exports.kindOverviewPath=e._t,exports.loadPackDescription=e.xt,exports.loadPackDescriptionFromManifest=e.St,exports.loadPackDescriptionRaw=e.Ct,exports.mapLocalToAbsolute=e.Wt,exports.npmNameToKindPath=e.vt,exports.packFolderToRelativeTgz=e.Gt,exports.packageChannelPrefix=e.R,exports.packageChannelPrefixInsideV2=e.z,exports.packageContentPrefix=e.B,exports.packageContentPrefixInsideV2=e.V,exports.packageOverviewPath=e.H,exports.packageOverviewPathInsideV2=e.U,exports.parseGlobalOverviewReg=e.W,exports.parsePackageName=e.wt,exports.parseSelector=e.v,exports.publishBlock=e.X,exports.readFacadeKindDependency=e.$,exports.readModelCompiledKindRef=e.et,exports.relativeToContentString=e.Kt,exports.relativeToExplicitBinary64=e.qt,exports.relativeToExplicitBytes=e.Jt,exports.relativeToExplicitString=e.Yt,exports.resolveBlockComponents=e.Mt,exports.resolveBlockPackDescription=e.kt,exports.resolveBlockPackMeta=e.Rt,exports.resolveFacadeKind=e.tt,exports.resolveKind=e.y,exports.resolveManifestBlockComponents=e.Nt,exports.resolveManifestBlockPackMeta=e.zt,exports.resolveModuleFile=e.Xt,exports.resolveModuleFolder=e.Zt,exports.resolveToRegistry=e.J,exports.selectorToRange=e.b,Object.defineProperty(exports,"storageByUrl",{enumerable:!0,get:function(){return t.storageByUrl}}),exports.tryLoadPackDescription=e.Tt,exports.writePublishedCoords=e.Y;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { $ as e,
|
|
1
|
+
import { $ as e, $t as t, A as n, At as r, B as i, Bt as a, C as o, Ct as s, D as c, Dt as l, E as u, Et as d, F as f, Ft as p, G as m, Gt as h, H as g, Ht as _, I as v, It as y, J as b, Jt as x, K as S, Kt as C, L as w, Lt as T, M as E, Mt as D, N as O, Nt as k, O as A, Ot as j, P as M, Pt as N, Q as P, Qt as F, R as I, Rt as L, S as R, St as z, T as B, Tt as V, U as H, Ut as U, V as W, Vt as G, W as K, Wt as q, X as J, Xt as Y, Yt as X, Z, Zt as Q, _ as $, _t as ee, a as te, at as ne, b as re, bt as ie, c as ae, ct as oe, d as se, dt as ce, en as le, et as ue, f as de, ft as fe, g as pe, gt as me, h as he, ht as ge, i as _e, it as ve, j as ye, jt as be, k as xe, kt as Se, l as Ce, lt as we, m as Te, mt as Ee, nn as De, nt as Oe, o as ke, ot as Ae, p as je, pt as Me, q as Ne, qt as Pe, r as Fe, rt as Ie, s as Le, st as Re, t as ze, tn as Be, tt as Ve, u as He, ut as Ue, v as We, vt as Ge, w as Ke, wt as qe, x as Je, xt as Ye, y as Xe, yt as Ze, z as Qe, zt as $e } from "./config-DlXp1y4o.mjs";
|
|
2
2
|
// src/registry_v1/index.ts
|
|
3
|
-
var
|
|
4
|
-
GlobalOverviewPath: () =>
|
|
5
|
-
MetaFile: () =>
|
|
6
|
-
PlPackageConfigData: () =>
|
|
7
|
-
PlPackageJsonConfigFile: () =>
|
|
8
|
-
PlPackageYamlConfigFile: () =>
|
|
9
|
-
PlRegCommonConfigData: () =>
|
|
10
|
-
PlRegFullPackageConfigData: () =>
|
|
11
|
-
PlRegPackageConfig: () =>
|
|
12
|
-
PlRegPackageConfigDataShard: () =>
|
|
13
|
-
packageContentPrefix: () =>
|
|
14
|
-
packageOverviewPath: () =>
|
|
15
|
-
payloadFilePath: () =>
|
|
3
|
+
var et = /* @__PURE__ */ De({
|
|
4
|
+
GlobalOverviewPath: () => Fe,
|
|
5
|
+
MetaFile: () => _e,
|
|
6
|
+
PlPackageConfigData: () => ae,
|
|
7
|
+
PlPackageJsonConfigFile: () => Ce,
|
|
8
|
+
PlPackageYamlConfigFile: () => He,
|
|
9
|
+
PlRegCommonConfigData: () => se,
|
|
10
|
+
PlRegFullPackageConfigData: () => de,
|
|
11
|
+
PlRegPackageConfig: () => ze,
|
|
12
|
+
PlRegPackageConfigDataShard: () => je,
|
|
13
|
+
packageContentPrefix: () => te,
|
|
14
|
+
packageOverviewPath: () => ke,
|
|
15
|
+
payloadFilePath: () => Le
|
|
16
16
|
});
|
|
17
|
-
export {
|
|
17
|
+
export { s as BlockDescriptionPackageJsonField, qe as BlockPackFolderName, A as BlockRegistryV2, xe as ChannelNameRegexp, n as ChannelsFolder, Je as FSStorage, B as FileNotFoundError, R as GcsStorage, ye as GlobalOverviewFileName, E as GlobalOverviewGzFileName, O as GlobalOverviewGzPath, M as GlobalOverviewPath, oe as KindContractFileName, we as KindDeclarationFileName, Ue as KindImplementer, ce as KindManifest, Ae as KindManifestFile, fe as KindManifestFileInfo, Me as KindManifestFileName, Ee as KindManifestIdentity, ge as KindOverview, me as KindOverviewFileName, ee as KindOverviewPathPattern, $ as KindResolutionError, Ve as KindVersionMismatchError, Ge as KindVersionOverview, Ze as KindsPrefix, f as MainPrefix, v as ManifestFileName, w as ManifestSuffix, I as PackageManifestPattern, Qe as PackageOverview, i as PackageOverviewFileName, W as PackageOverviewVersionEntry, J as PublishedCoordsFileName, Te as RegistryReadError, et as RegistryV1, he as RegistryV2Reader, o as S3Storage, q as absoluteToBase64, h as absoluteToBytes, C as absoluteToString, be as addRelativePathPrefix, N as blockComponentsManifestToAbsoluteUrl, r as buildBlockPackDist, Re as buildKindDist, Z as buildPublishedCoords, Oe as checkKindVersionMatch, p as consolidateBlockComponents, D as consolidateBlockPackDescription, L as consolidateBlockPackMeta, Pe as cpAbsoluteToRelative, $e as embedBlockPackMetaAbsoluteBase64, a as embedBlockPackMetaAbsoluteBytes, G as embedBlockPackMetaBytes, u as folderReaderByUrl, pe as inferUpdateSuggestions, c as isFileNotFound, ie as kindContentPrefix, Ye as kindOverviewPath, V as loadPackDescription, d as loadPackDescriptionFromManifest, l as loadPackDescriptionRaw, x as mapLocalToAbsolute, z as npmNameToKindPath, X as packFolderToRelativeTgz, g as packageChannelPrefix, H as packageChannelPrefixInsideV2, K as packageContentPrefix, m as packageContentPrefixInsideV2, S as packageOverviewPath, Ne as packageOverviewPathInsideV2, b as parseGlobalOverviewReg, j as parsePackageName, We as parseSelector, ue as publishBlock, Ie as readFacadeKindDependency, ve as readModelCompiledKindRef, Y as relativeToContentString, Q as relativeToExplicitBinary64, F as relativeToExplicitBytes, t as relativeToExplicitString, y as resolveBlockComponents, k as resolveBlockPackDescription, _ as resolveBlockPackMeta, ne as resolveFacadeKind, Xe as resolveKind, T as resolveManifestBlockComponents, U as resolveManifestBlockPackMeta, le as resolveModuleFile, Be as resolveModuleFolder, P as resolveToRegistry, re as selectorToRange, Ke as storageByUrl, Se as tryLoadPackDescription, e as writePublishedCoords };
|
|
18
18
|
|
|
19
19
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["writePublishedCoords","relativeToExplicitString","ChannelsFolder","buildBlockPackDist","PackageOverviewFileName","embedBlockPackMetaAbsoluteBytes","S3Storage","BlockDescriptionPackageJsonField","isFileNotFound","loadPackDescriptionRaw","folderReaderByUrl","loadPackDescriptionFromManifest","MainPrefix","consolidateBlockComponents","packageContentPrefixInsideV2","absoluteToBytes","packageChannelPrefix","resolveBlockPackMeta","ManifestFileName","resolveBlockComponents","parseGlobalOverviewReg","mapLocalToAbsolute","packageOverviewPath","absoluteToString","ManifestSuffix","resolveManifestBlockComponents","GlobalOverviewGzFileName","consolidateBlockPackDescription","GlobalOverviewGzPath","resolveBlockPackDescription","BlockRegistryV2","parsePackageName","GlobalOverviewPath","blockComponentsManifestToAbsoluteUrl","resolveToRegistry","relativeToExplicitBytes","PackageManifestPattern","consolidateBlockPackMeta","GcsStorage","npmNameToKindPath","FileNotFoundError","loadPackDescription","packageChannelPrefixInsideV2","resolveManifestBlockPackMeta","PackageOverviewVersionEntry","embedBlockPackMetaBytes","packageContentPrefix","absoluteToBase64","PublishedCoordsFileName","relativeToContentString","packFolderToRelativeTgz","relativeToExplicitBinary64","KindResolutionError","KindOverviewPathPattern","packageContentPrefix$1","resolveFacadeKind","selectorToRange","kindContentPrefix","PlPackageConfigData","KindContractFileName","PlRegCommonConfigData","KindManifest","resolveModuleFile","publishBlock","PlRegFullPackageConfigData","KindManifestFileInfo","inferUpdateSuggestions","KindOverviewFileName","RegistryV2Reader","KindOverview","MetaFile","readModelCompiledKindRef","GlobalOverviewFileName","addRelativePathPrefix","ChannelNameRegexp","tryLoadPackDescription","PlPackageJsonConfigFile","KindDeclarationFileName","RegistryReadError","KindManifestIdentity","__exportAll","checkKindVersionMatch","packageOverviewPath$1","KindManifestFile","PlRegPackageConfigDataShard","KindManifestFileName","packageOverviewPathInsideV2","cpAbsoluteToRelative","GlobalOverviewPath$1","readFacadeKindDependency","payloadFilePath","buildKindDist","PlRegPackageConfig","resolveModuleFolder","KindVersionMismatchError","PlPackageYamlConfigFile","KindImplementer","parseSelector","KindVersionOverview","storageByUrl","BlockPackFolderName","FSStorage","kindOverviewPath","resolveKind","KindsPrefix","PackageOverview","embedBlockPackMetaAbsoluteBase64","registry_v1_exports","buildPublishedCoords"],"sources":["../src/registry_v1/index.ts"],"sourcesContent":["export * from \"./v1_repo_schema\";\nexport * from \"./config_schema\";\nexport { PlRegPackageConfig } from \"./config\";\n"],"mappings":""}
|
|
@@ -3,6 +3,15 @@ import { RelativeContentReader } from '../v2';
|
|
|
3
3
|
export type ReadFileOptions = {
|
|
4
4
|
signal?: AbortSignal;
|
|
5
5
|
};
|
|
6
|
+
/** Thrown by {@link FolderReader.readFile} over HTTP when the server answers 404. */
|
|
7
|
+
export declare class FileNotFoundError extends Error {
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Whether `e` says the file is absent, as opposed to unreadable: HTTP 404 from an HTTP folder,
|
|
12
|
+
* `ENOENT` from a local one.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isFileNotFound(e: unknown): boolean;
|
|
6
15
|
export interface FolderReader {
|
|
7
16
|
readonly rootUrl: URL;
|
|
8
17
|
relativeReader(relativePath: string): FolderReader;
|
|
@@ -46,6 +46,8 @@ export interface ResolvedFacadeKind {
|
|
|
46
46
|
manifest: KindManifest;
|
|
47
47
|
/** Reads the manifest's `files[].name` relative to the kind's `dist/`. */
|
|
48
48
|
fileReader: RelativeContentReader;
|
|
49
|
+
/** Absolute path of the kind's `dist/`, which holds its built files. */
|
|
50
|
+
distDir: string;
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Resolve the facade's kind dependency to concrete publishable artifacts.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockPackId, BlockPackIdNoVersion, UpdateSuggestions, SingleBlockPackOverview, BlockPackOverviewNoRegistryId, BlockPackFromRegistryV2 } from '@milaboratories/pl-model-middle-layer';
|
|
1
|
+
import { BlockPackId, BlockPackIdNoVersion, UpdateSuggestions, SingleBlockPackOverview, BlockPackOverviewNoRegistryId, BlockPackFromRegistryV2, BlockPackManifest } from '@milaboratories/pl-model-middle-layer';
|
|
2
2
|
import { BlockKindReference } from '@milaboratories/pl-model-common';
|
|
3
3
|
import { FolderReader } from '../../io';
|
|
4
4
|
import { KindOverview } from './schema_kinds';
|
|
@@ -11,6 +11,13 @@ export type RegistryV2ReaderOps = {
|
|
|
11
11
|
};
|
|
12
12
|
/** @param availableVersions must be reverse sorted (from highest version to lowest) */
|
|
13
13
|
export declare function inferUpdateSuggestions(currentVersion: string, availableVersions: string[]): UpdateSuggestions<string>;
|
|
14
|
+
/**
|
|
15
|
+
* A registry file could not be read for a reason other than its absence: the network, the
|
|
16
|
+
* server, or content that does not parse. The message carries the cause's text.
|
|
17
|
+
*/
|
|
18
|
+
export declare class RegistryReadError extends Error {
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
14
21
|
export declare class RegistryV2Reader {
|
|
15
22
|
private readonly registryReader;
|
|
16
23
|
private readonly v2RootFolderReader;
|
|
@@ -33,8 +40,10 @@ export declare class RegistryV2Reader {
|
|
|
33
40
|
getLatestOverview(id: BlockPackIdNoVersion, channel: string): Promise<SingleBlockPackOverview | undefined>;
|
|
34
41
|
getUpdateSuggestions(id: BlockPackId, channel: string): Promise<UpdateSuggestions<string> | undefined>;
|
|
35
42
|
getSpecificOverview(id: BlockPackId, channel: string): Promise<SingleBlockPackOverview>;
|
|
36
|
-
private readonly
|
|
43
|
+
private readonly manifestCache;
|
|
37
44
|
getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl>;
|
|
45
|
+
/** The published manifest of a block version: file hashes and the pack-time meta. */
|
|
46
|
+
getManifest(id: BlockPackId): Promise<BlockPackManifest>;
|
|
38
47
|
/**
|
|
39
48
|
* Read the kind projection at `kinds/{org}/{name}/overview.json` for a kind
|
|
40
49
|
* npm package name. Single, no-LIST read against the `kinds/` sibling tree
|
|
@@ -43,10 +52,35 @@ export declare class RegistryV2Reader {
|
|
|
43
52
|
*
|
|
44
53
|
* Client-side selector→version resolution is left to the §6 resolution
|
|
45
54
|
* concern; this method only fetches and parses.
|
|
55
|
+
*
|
|
56
|
+
* @throws RegistryReadError when the overview is there but cannot be read or parsed, so an
|
|
57
|
+
* outage is not reported as a missing kind.
|
|
46
58
|
*/
|
|
47
59
|
getKindOverview(kindNpmName: string, options?: {
|
|
48
60
|
signal?: AbortSignal;
|
|
49
61
|
}): Promise<KindOverview | undefined>;
|
|
62
|
+
/**
|
|
63
|
+
* Reads one file of a published kind version, `kinds/{org}/{name}/{version}/{fileName}`, such
|
|
64
|
+
* as `contract.d.ts`. Returns `undefined` when the version has no such file.
|
|
65
|
+
*
|
|
66
|
+
* @param ref an exact kind reference, `{name}@{version}`
|
|
67
|
+
* @throws RegistryReadError when the file cannot be read for another reason
|
|
68
|
+
*/
|
|
69
|
+
readKindFile(ref: BlockKindReference, fileName: string, options?: {
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
}): Promise<Buffer | undefined>;
|
|
72
|
+
/**
|
|
73
|
+
* The URL of one file of a published kind version, as {@link readKindFile} reads it, without
|
|
74
|
+
* credentials or query.
|
|
75
|
+
*
|
|
76
|
+
* @param ref an exact kind reference, `{name}@{version}`
|
|
77
|
+
*/
|
|
78
|
+
kindFileUrl(ref: BlockKindReference, fileName: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* The homepage a published block names in its meta (`url`), `undefined` when it names none.
|
|
81
|
+
* Reads the block's manifest on every call.
|
|
82
|
+
*/
|
|
83
|
+
getBlockHomepage(id: BlockPackId): Promise<string | undefined>;
|
|
50
84
|
/**
|
|
51
85
|
* Resolve a kind reference (`{name}@{selector}`) to a concrete implementing
|
|
52
86
|
* block, returning the **byte-identical** `from-registry-v2` spec shape that
|
|
@@ -4,12 +4,24 @@ import { z } from 'zod';
|
|
|
4
4
|
*
|
|
5
5
|
* Layout mirrors the package tree one level down:
|
|
6
6
|
* kinds/{org}/{name}/{version}/manifest.json — immutable kind content (publishKind)
|
|
7
|
-
* kinds/{org}/{name}/{version}/
|
|
7
|
+
* kinds/{org}/{name}/{version}/contract.d.ts — kind artifacts (the files the manifest lists)
|
|
8
8
|
* kinds/{org}/{name}/overview.json — projection over implementing blocks (reconciler)
|
|
9
9
|
*/
|
|
10
10
|
export declare const KindsPrefix = "kinds/";
|
|
11
11
|
export declare const KindOverviewFileName = "overview.json";
|
|
12
12
|
export declare const KindManifestFileName = "manifest.json";
|
|
13
|
+
/**
|
|
14
|
+
* The declaration of a kind's params written for agents to read (`get_block_contract`): one file,
|
|
15
|
+
* the kind's own types written out, the SDK types they use imported by name. A kind version
|
|
16
|
+
* without it was built before; its declarations are only in {@link KindDeclarationFileName}.
|
|
17
|
+
* `@milaboratories/ts-builder build --target block-kind` writes it; `build-kind-manifest` requires it.
|
|
18
|
+
*/
|
|
19
|
+
export declare const KindContractFileName = "contract.d.ts";
|
|
20
|
+
/**
|
|
21
|
+
* The declarations kind versions were published with before {@link KindContractFileName}: every
|
|
22
|
+
* dependency inlined, tens of KB. Readers only point to it.
|
|
23
|
+
*/
|
|
24
|
+
export declare const KindDeclarationFileName = "kind.d.ts";
|
|
13
25
|
/** Location of a kind inside the `kinds/` tree, split into path segments. */
|
|
14
26
|
export interface KindPathLocation {
|
|
15
27
|
org: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/block-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.0",
|
|
4
4
|
"description": "Utility to manipulate Platforma Blocks and Block Registry",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"bin": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@aws-sdk/client-ecr-public": "3.1157.0",
|
|
27
27
|
"@inquirer/prompts": "^7.0.1",
|
|
28
28
|
"@milaboratories/pl-http": "1.2.7",
|
|
29
|
-
"@milaboratories/pl-model-backend": "1.4.
|
|
29
|
+
"@milaboratories/pl-model-backend": "1.4.59",
|
|
30
30
|
"@milaboratories/pl-model-common": "1.60.0",
|
|
31
31
|
"@milaboratories/pl-model-middle-layer": "1.41.5",
|
|
32
32
|
"@milaboratories/resolve-helper": "1.1.3",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@milaboratories/build-configs": "2.0.3",
|
|
47
|
-
"@milaboratories/ts-builder": "1.
|
|
47
|
+
"@milaboratories/ts-builder": "1.9.0",
|
|
48
48
|
"@milaboratories/ts-configs": "1.4.1",
|
|
49
49
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
50
50
|
"@types/mime-types": "^2.1.4",
|
package/src/io/folder_reader.ts
CHANGED
|
@@ -9,6 +9,21 @@ import { util } from "@platforma-sdk/package-builder-lib";
|
|
|
9
9
|
|
|
10
10
|
export type ReadFileOptions = { signal?: AbortSignal };
|
|
11
11
|
|
|
12
|
+
/** Thrown by {@link FolderReader.readFile} over HTTP when the server answers 404. */
|
|
13
|
+
export class FileNotFoundError extends Error {
|
|
14
|
+
name = "FileNotFoundError";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Whether `e` says the file is absent, as opposed to unreadable: HTTP 404 from an HTTP folder,
|
|
19
|
+
* `ENOENT` from a local one.
|
|
20
|
+
*/
|
|
21
|
+
export function isFileNotFound(e: unknown): boolean {
|
|
22
|
+
return (
|
|
23
|
+
e instanceof FileNotFoundError || (e instanceof Error && "code" in e && e.code === "ENOENT")
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
12
27
|
export interface FolderReader {
|
|
13
28
|
readonly rootUrl: URL;
|
|
14
29
|
relativeReader(relativePath: string): FolderReader;
|
|
@@ -31,7 +46,8 @@ class HttpFolderReader implements FolderReader {
|
|
|
31
46
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
32
47
|
// Release the connection; the error body (S3/GCS XML, an HTML page) is not registry content.
|
|
33
48
|
await response.body.dump();
|
|
34
|
-
|
|
49
|
+
const message = `Failed to read ${util.redactUrl(targetUrl)}: HTTP ${response.statusCode}`;
|
|
50
|
+
throw response.statusCode === 404 ? new FileNotFoundError(message) : new Error(message);
|
|
35
51
|
}
|
|
36
52
|
return Buffer.from(await response.body.arrayBuffer());
|
|
37
53
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import fsp from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, expect, test } from "vitest";
|
|
5
|
+
import { buildKindDist } from "./build_kind_dist";
|
|
6
|
+
|
|
7
|
+
let dir: string;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
dir = await fsp.mkdtemp(path.join(os.tmpdir(), "build-kind-dist-"));
|
|
10
|
+
await fsp.writeFile(
|
|
11
|
+
path.join(dir, "package.json"),
|
|
12
|
+
JSON.stringify({ name: "@platforma-open/test.fixture.kind", version: "1.0.0" }),
|
|
13
|
+
);
|
|
14
|
+
await fsp.mkdir(path.join(dir, "src"));
|
|
15
|
+
await fsp.writeFile(path.join(dir, "src", "index.ts"), "export const kind = 1;\n");
|
|
16
|
+
await fsp.mkdir(path.join(dir, "dist"));
|
|
17
|
+
await fsp.writeFile(path.join(dir, "dist", "kind.js"), "export const kind = 1;\n");
|
|
18
|
+
});
|
|
19
|
+
afterEach(async () => {
|
|
20
|
+
await fsp.rm(dir, { recursive: true, force: true });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("lists kind.js and contract.d.ts in the manifest", async () => {
|
|
24
|
+
await fsp.writeFile(path.join(dir, "dist", "contract.d.ts"), "export type Params = {};\n");
|
|
25
|
+
|
|
26
|
+
const manifest = await buildKindDist({ modulePath: dir });
|
|
27
|
+
|
|
28
|
+
expect(manifest.files.map((f) => f.name)).toEqual(["kind.js", "contract.d.ts"]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("fails naming contract.d.ts and the build that writes it when it is missing", async () => {
|
|
32
|
+
await expect(buildKindDist({ modulePath: dir })).rejects.toThrow(
|
|
33
|
+
/contract\.d\.ts is missing .*ts-builder build --target block-kind/,
|
|
34
|
+
);
|
|
35
|
+
await expect(fsp.access(path.join(dir, "dist", "manifest.json"))).rejects.toThrow();
|
|
36
|
+
});
|
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { util } from "@platforma-sdk/package-builder-lib";
|
|
4
4
|
import { calculateSha256 } from "../util";
|
|
5
5
|
import type { KindManifest, KindManifestFileInfo } from "./registry/schema_kinds";
|
|
6
|
+
import { KindContractFileName } from "./registry/schema_kinds";
|
|
6
7
|
|
|
7
8
|
export interface BuildKindDistOptions {
|
|
8
9
|
/** Kind package directory (the dir containing `package.json`, `src/`, `dist/`). */
|
|
@@ -72,7 +73,9 @@ export async function buildKindDist(opts: BuildKindDistOptions = {}): Promise<Ki
|
|
|
72
73
|
|
|
73
74
|
const sourceHash = util.hashDirSync(srcDir).digest("hex").toUpperCase();
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
// `@milaboratories/ts-builder build --target block-kind` writes both files
|
|
77
|
+
// (createRolldownBlockKindConfig); a missing contract means the two sides diverged.
|
|
78
|
+
const artifactNames = [entryFileName, KindContractFileName];
|
|
76
79
|
const files: KindManifestFileInfo[] = [];
|
|
77
80
|
for (const artifact of artifactNames) {
|
|
78
81
|
const abs = path.resolve(dst, artifact);
|
|
@@ -82,7 +85,8 @@ export async function buildKindDist(opts: BuildKindDistOptions = {}): Promise<Ki
|
|
|
82
85
|
} catch (err: unknown) {
|
|
83
86
|
if (err instanceof Error && "code" in err && err.code === "ENOENT") {
|
|
84
87
|
throw new Error(
|
|
85
|
-
`Kind build is incomplete: ${artifact} is missing from ${dst}. Run the kind's build
|
|
88
|
+
`Kind build is incomplete: ${artifact} is missing from ${dst}. Run the kind's build ` +
|
|
89
|
+
"(`ts-builder build --target block-kind`, which writes it) before building its manifest.",
|
|
86
90
|
);
|
|
87
91
|
}
|
|
88
92
|
throw err;
|
|
@@ -83,6 +83,8 @@ export interface ResolvedFacadeKind {
|
|
|
83
83
|
manifest: KindManifest;
|
|
84
84
|
/** Reads the manifest's `files[].name` relative to the kind's `dist/`. */
|
|
85
85
|
fileReader: RelativeContentReader;
|
|
86
|
+
/** Absolute path of the kind's `dist/`, which holds its built files. */
|
|
87
|
+
distDir: string;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
/**
|
|
@@ -120,7 +122,7 @@ export async function resolveFacadeKind(
|
|
|
120
122
|
const fileReader: RelativeContentReader = async (relativePath) =>
|
|
121
123
|
Buffer.from(await fsp.readFile(path.resolve(distDir, relativePath)));
|
|
122
124
|
|
|
123
|
-
return { ref, manifest, fileReader };
|
|
125
|
+
return { ref, manifest, fileReader, distDir };
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
/** Resolve the directory of an installed kind npm package from the facade's location. */
|
|
@@ -9,9 +9,12 @@ import {
|
|
|
9
9
|
BlockPackManifest,
|
|
10
10
|
StableChannel,
|
|
11
11
|
} from "@milaboratories/pl-model-middle-layer";
|
|
12
|
-
import { inferUpdateSuggestions } from "./registry_reader";
|
|
12
|
+
import { inferUpdateSuggestions, RegistryReadError, RegistryV2Reader } from "./registry_reader";
|
|
13
|
+
import { folderReaderByUrl } from "../../io";
|
|
14
|
+
import { calculateSha256 } from "../../util";
|
|
15
|
+
import type { BlockKindReference } from "@milaboratories/pl-model-common";
|
|
13
16
|
import { OverviewSnapshotsPrefix } from "./schema_internal";
|
|
14
|
-
import { KindOverview, kindOverviewPath, npmNameToKindPath } from "./schema_kinds";
|
|
17
|
+
import { KindManifest, KindOverview, kindOverviewPath, npmNameToKindPath } from "./schema_kinds";
|
|
15
18
|
import { resolveKind } from "./kind_resolver";
|
|
16
19
|
|
|
17
20
|
type TestStorageInstance = {
|
|
@@ -506,6 +509,86 @@ test.each(testStorages)(
|
|
|
506
509
|
},
|
|
507
510
|
);
|
|
508
511
|
|
|
512
|
+
test("readKindFile reads the files of a published kind version", async () => {
|
|
513
|
+
const storagePath = path.resolve("tmp", randomUUID().toString());
|
|
514
|
+
const registry = new BlockRegistryV2(storageByUrl("file://" + storagePath));
|
|
515
|
+
const reader = new RegistryV2Reader(folderReaderByUrl("file://" + storagePath));
|
|
516
|
+
const kindDts = Buffer.from("export declare const kind: CompiledBlockKind<{ a: number }>;\n");
|
|
517
|
+
const ref = `${kindTestKindNpmName}@1.0.0` as BlockKindReference;
|
|
518
|
+
|
|
519
|
+
try {
|
|
520
|
+
await registry.publishKind(
|
|
521
|
+
KindManifest.parse({
|
|
522
|
+
schema: "v1",
|
|
523
|
+
kind: { name: kindTestKindNpmName, version: "1.0.0" },
|
|
524
|
+
sourceHash: "0".repeat(64),
|
|
525
|
+
files: [
|
|
526
|
+
{ name: "kind.d.ts", size: kindDts.length, sha256: await calculateSha256(kindDts) },
|
|
527
|
+
],
|
|
528
|
+
}),
|
|
529
|
+
async (fileName) => {
|
|
530
|
+
if (fileName === "kind.d.ts") return kindDts;
|
|
531
|
+
throw new Error(`Unknown file: ${fileName}`);
|
|
532
|
+
},
|
|
533
|
+
);
|
|
534
|
+
|
|
535
|
+
expect(await reader.readKindFile(ref, "kind.d.ts")).toEqual(kindDts);
|
|
536
|
+
// A file the version does not have, and a version that is not published, read as absent.
|
|
537
|
+
expect(await reader.readKindFile(ref, "kind.js")).toBeUndefined();
|
|
538
|
+
expect(
|
|
539
|
+
await reader.readKindFile(`${kindTestKindNpmName}@2.0.0` as BlockKindReference, "kind.d.ts"),
|
|
540
|
+
).toBeUndefined();
|
|
541
|
+
// The URL names the same file.
|
|
542
|
+
expect(reader.kindFileUrl(ref, "kind.d.ts")).toBe(
|
|
543
|
+
`file://${storagePath}/kinds/kindorg/kindpkg/1.0.0/kind.d.ts`,
|
|
544
|
+
);
|
|
545
|
+
} finally {
|
|
546
|
+
await fsp.rm(storagePath, { recursive: true, force: true });
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
test("getBlockHomepage reads the url a block names in its meta", async () => {
|
|
551
|
+
const storagePath = path.resolve("tmp", randomUUID().toString());
|
|
552
|
+
const registry = new BlockRegistryV2(storageByUrl("file://" + storagePath));
|
|
553
|
+
const reader = new RegistryV2Reader(folderReaderByUrl("file://" + storagePath));
|
|
554
|
+
const plain = kindImplementingManifest("1.0.0", "1.0.0");
|
|
555
|
+
const named = BlockPackManifest.parse({
|
|
556
|
+
...kindImplementingManifest("1.1.0", "1.0.0"),
|
|
557
|
+
description: {
|
|
558
|
+
...kindImplementingManifest("1.1.0", "1.0.0").description,
|
|
559
|
+
meta: { ...plain.description.meta, url: "https://example.com/kindblk" },
|
|
560
|
+
},
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
try {
|
|
564
|
+
await registry.publishPackage(plain, kindTestFileReader);
|
|
565
|
+
await registry.publishPackage(named, kindTestFileReader);
|
|
566
|
+
|
|
567
|
+
expect(await reader.getBlockHomepage(named.description.id)).toBe("https://example.com/kindblk");
|
|
568
|
+
expect(await reader.getBlockHomepage(plain.description.id)).toBeUndefined();
|
|
569
|
+
} finally {
|
|
570
|
+
await fsp.rm(storagePath, { recursive: true, force: true });
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
test("readKindFile reports an unreadable registry as a read error", async () => {
|
|
575
|
+
// A registry root that is a file: every read under it fails with ENOTDIR, not ENOENT.
|
|
576
|
+
const filePath = path.resolve("tmp", randomUUID().toString());
|
|
577
|
+
await fsp.mkdir(path.dirname(filePath), { recursive: true });
|
|
578
|
+
await fsp.writeFile(filePath, "not a folder");
|
|
579
|
+
const reader = new RegistryV2Reader(folderReaderByUrl("file://" + filePath));
|
|
580
|
+
try {
|
|
581
|
+
const read = reader.readKindFile(
|
|
582
|
+
`${kindTestKindNpmName}@1.0.0` as BlockKindReference,
|
|
583
|
+
"kind.d.ts",
|
|
584
|
+
);
|
|
585
|
+
await expect(read).rejects.toBeInstanceOf(RegistryReadError);
|
|
586
|
+
await expect(read).rejects.toThrow(/kindorg\/kindpkg\/1\.0\.0\/kind\.d\.ts.*ENOTDIR/);
|
|
587
|
+
} finally {
|
|
588
|
+
await fsp.rm(filePath, { force: true });
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
|
|
509
592
|
test.each([
|
|
510
593
|
{
|
|
511
594
|
name: "test1",
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
|
-
import { RegistryV2Reader } from "./registry_reader";
|
|
3
|
-
import {
|
|
2
|
+
import { RegistryReadError, RegistryV2Reader } from "./registry_reader";
|
|
3
|
+
import type { FolderReader } from "../../io";
|
|
4
|
+
import { FileNotFoundError, folderReaderByUrl } from "../../io";
|
|
5
|
+
import { KindResolutionError } from "./kind_resolver";
|
|
6
|
+
import type { BlockKindReference } from "@milaboratories/pl-model-common";
|
|
4
7
|
import { request } from "undici";
|
|
5
8
|
import { AnyChannel } from "@milaboratories/pl-model-middle-layer";
|
|
6
9
|
|
|
@@ -31,3 +34,106 @@ test("test getting components from global registry", async () => {
|
|
|
31
34
|
(await (await request(components.workflow.main.url)).body.arrayBuffer()).byteLength,
|
|
32
35
|
).toBeGreaterThan(100);
|
|
33
36
|
}, 20000);
|
|
37
|
+
|
|
38
|
+
test("test reading kind files from global registry", async () => {
|
|
39
|
+
const registryReader = new RegistryV2Reader(folderReaderByUrl("https://blocks.pl-open.science"));
|
|
40
|
+
const ref = "@platforma-open/milaboratories.rarefaction.kind@1.2.0" as BlockKindReference;
|
|
41
|
+
const dts = await registryReader.readKindFile(ref, "kind.d.ts");
|
|
42
|
+
expect(dts?.toString()).toContain("export declare const kind: CompiledBlockKind<BlockParams>;");
|
|
43
|
+
// HTTP 404: the version was published without the file.
|
|
44
|
+
expect(await registryReader.readKindFile(ref, "no-such-file.d.ts")).toBeUndefined();
|
|
45
|
+
}, 20000);
|
|
46
|
+
|
|
47
|
+
/** A registry whose every read fails with `error`, and that counts the reads. */
|
|
48
|
+
function failingRegistry(error: () => Error): { folder: FolderReader; reads: () => number } {
|
|
49
|
+
let reads = 0;
|
|
50
|
+
const folder: FolderReader = {
|
|
51
|
+
rootUrl: new URL("https://registry.invalid/"),
|
|
52
|
+
relativeReader: () => folder,
|
|
53
|
+
readFile: async () => {
|
|
54
|
+
reads++;
|
|
55
|
+
throw error();
|
|
56
|
+
},
|
|
57
|
+
getContentReader: () => async () => {
|
|
58
|
+
throw error();
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
return { folder, reads: () => reads };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const kindName = "@platforma-open/kindorg.kindpkg.kind";
|
|
65
|
+
|
|
66
|
+
test("a missing kind overview reads as no such kind, at once", async () => {
|
|
67
|
+
const { folder, reads } = failingRegistry(() => new FileNotFoundError("HTTP 404"));
|
|
68
|
+
const reader = new RegistryV2Reader(folder);
|
|
69
|
+
|
|
70
|
+
expect(await reader.getKindOverview(kindName)).toBeUndefined();
|
|
71
|
+
expect(reads()).toBe(1);
|
|
72
|
+
await expect(
|
|
73
|
+
reader.resolveKind(`${kindName}@1.0.0` as BlockKindReference, { allowUnstable: false }),
|
|
74
|
+
).rejects.toBeInstanceOf(KindResolutionError);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("a failed read of a kind overview is a registry error with its text", async () => {
|
|
78
|
+
const { folder, reads } = failingRegistry(() => new Error("HTTP 503"));
|
|
79
|
+
const reader = new RegistryV2Reader(folder);
|
|
80
|
+
|
|
81
|
+
const read = reader.getKindOverview(kindName);
|
|
82
|
+
await expect(read).rejects.toBeInstanceOf(RegistryReadError);
|
|
83
|
+
await expect(read).rejects.toThrow(
|
|
84
|
+
`Reading the overview of kind ${kindName} from the registry failed: HTTP 503`,
|
|
85
|
+
);
|
|
86
|
+
// Retried like any other registry read.
|
|
87
|
+
expect(reads()).toBe(2);
|
|
88
|
+
await expect(
|
|
89
|
+
reader.resolveKind(`${kindName}@1.0.0` as BlockKindReference, { allowUnstable: false }),
|
|
90
|
+
).rejects.toBeInstanceOf(RegistryReadError);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
/** A registry with one kind file, `file`, whose reads `respond` answers; it counts the reads. */
|
|
94
|
+
function kindFileRegistry(respond: (read: number, signal?: AbortSignal) => Promise<Buffer>) {
|
|
95
|
+
let reads = 0;
|
|
96
|
+
const folder: FolderReader = {
|
|
97
|
+
rootUrl: new URL("https://registry.invalid/"),
|
|
98
|
+
relativeReader: () => folder,
|
|
99
|
+
readFile: async (_file, options) => await respond(++reads, options?.signal),
|
|
100
|
+
getContentReader: () => async () => Buffer.alloc(0),
|
|
101
|
+
};
|
|
102
|
+
return { folder, reads: () => reads };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const kindRef = `${kindName}@1.0.0` as BlockKindReference;
|
|
106
|
+
|
|
107
|
+
test("an aborted read of a kind file is not retried", async () => {
|
|
108
|
+
const { folder, reads } = kindFileRegistry(async () => {
|
|
109
|
+
const e = new Error("This operation was aborted");
|
|
110
|
+
e.name = "AbortError";
|
|
111
|
+
throw e;
|
|
112
|
+
});
|
|
113
|
+
const reader = new RegistryV2Reader(folder);
|
|
114
|
+
|
|
115
|
+
await expect(reader.readKindFile(kindRef, "kind.d.ts")).rejects.toBeInstanceOf(RegistryReadError);
|
|
116
|
+
expect(reads()).toBe(1);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("a kind overview that does not parse is read once, and is a registry error", async () => {
|
|
120
|
+
const { folder, reads } = kindFileRegistry(async () => Buffer.from("{ not json"));
|
|
121
|
+
const reader = new RegistryV2Reader(folder);
|
|
122
|
+
|
|
123
|
+
await expect(reader.getKindOverview(kindName)).rejects.toBeInstanceOf(RegistryReadError);
|
|
124
|
+
expect(reads()).toBe(1);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("a kind overview read the caller aborts is not retried, and is the abort", async () => {
|
|
128
|
+
const controller = new AbortController();
|
|
129
|
+
const { folder, reads } = kindFileRegistry(async () => {
|
|
130
|
+
controller.abort();
|
|
131
|
+
throw controller.signal.reason;
|
|
132
|
+
});
|
|
133
|
+
const reader = new RegistryV2Reader(folder);
|
|
134
|
+
|
|
135
|
+
await expect(
|
|
136
|
+
reader.getKindOverview(kindName, { signal: controller.signal }),
|
|
137
|
+
).rejects.not.toBeInstanceOf(RegistryReadError);
|
|
138
|
+
expect(reads()).toBe(1);
|
|
139
|
+
});
|