@platforma-sdk/block-tools 2.3.13 → 2.3.15
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/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var u=(i,t,a)=>t in i?h(i,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[t]=a;var r=(i,t,a)=>u(i,typeof t!="symbol"?t+"":t,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./config-BVDkG_N7.js"),v=require("undici"),l=require("node:path"),c=require("node:path/posix"),f=require("node:fs/promises"),p=require("@milaboratories/pl-model-middle-layer"),k=require("canonicalize");require("zod");require("mime-types");require("tar");require("@milaboratories/resolve-helper");const g=require("lru-cache"),B={cacheBlockListFor:45e3,keepStaleBlockListFor:3e5};class R{constructor(t,a){r(this,"v2RootFolderReader");r(this,"ops");r(this,"embeddedMetaCache",new g.LRUCache({max:500,fetchMethod:async(t,a,o)=>{const s=this.v2RootFolderReader.getContentReader();return await e.BlockPackMetaEmbedBytes(s).parseAsync(o.context.latest.meta)}}));r(this,"listCacheTimestamp",0);r(this,"listCache");r(this,"componentsCache",new g.LRUCache({max:500,fetchMethod:async(t,a,{context:o})=>{const s=this.v2RootFolderReader.relativeReader(e.packageContentPrefixInsideV2(o)),P=p.BlockPackManifest.parse(JSON.parse(Buffer.from(await s.readFile(e.ManifestFileName)).toString()));return e.BlockComponentsAbsoluteUrl(s.rootUrl.toString()).parse(P.description.components)}}));this.registryReader=t,this.v2RootFolderReader=t.relativeReader(e.MainPrefix),this.ops={...B,...a??{}}}async embedMetaContent(t){return await this.embeddedMetaCache.forceFetch(k({id:t.id,sha256:t.latestManifestSha256}),{context:t})}async listBlockPacks(){if(this.listCache!==void 0&&Date.now()-this.listCacheTimestamp<=this.ops.cacheBlockListFor)return this.listCache;try{const t=e.GlobalOverviewReg.parse(JSON.parse(Buffer.from(await this.v2RootFolderReader.readFile(e.GlobalOverviewFileName)).toString())),a=await Promise.all(t.packages.map(async o=>({id:o.latest.id,meta:await this.embedMetaContent(o),spec:{type:"from-registry-v2",id:o.latest.id,registryUrl:this.registryReader.rootUrl.toString()},otherVersions:o.allVersions})));return this.listCache=a,this.listCacheTimestamp=Date.now(),a}catch(t){if(this.listCache!==void 0&&Date.now()-this.listCacheTimestamp<=this.ops.keepStaleBlockListFor)return this.listCache;throw t}}async getOverviewForSpec(t){return(await this.listBlockPacks()).find(a=>p.blockPackIdNoVersionEquals(t,a.id))}async getComponents(t){return await this.componentsCache.forceFetch(k(t),{context:t})}}const m=Object.freeze(Object.defineProperty({__proto__:null,GlobalOverviewPath:e.GlobalOverviewPath,MetaFile:e.MetaFile,PlPackageConfigData:e.PlPackageConfigData,PlPackageJsonConfigFile:e.PlPackageJsonConfigFile,PlPackageYamlConfigFile:e.PlPackageYamlConfigFile,PlRegCommonConfigData:e.PlRegCommonConfigData,PlRegFullPackageConfigData:e.PlRegFullPackageConfigData,PlRegPackageConfig:e.PlRegPackageConfig,PlRegPackageConfigDataShard:e.PlRegPackageConfigDataShard,packageContentPrefix:e.packageContentPrefix,packageOverviewPath:e.packageOverviewPath,payloadFilePath:e.payloadFilePath},Symbol.toStringTag,{value:"Module"}));class n{constructor(t,a){this.rootUrl=t,this.httpDispatcher=a}async readFile(t){const a=new URL(t,this.rootUrl),o=await v.request(a,{dispatcher:this.httpDispatcher});return Buffer.from(await o.body.arrayBuffer())}relativeReader(t){return t.endsWith("/")||(t=t+"/"),new n(new URL(t,this.rootUrl),this.httpDispatcher)}getContentReader(t){let a=this;return t!==void 0&&(a=a.relativeReader(t)),o=>a.readFile(o)}}class d{constructor(t,a){this.rootUrl=t,this.root=a}async readFile(t){const a=l.join(this.root,...t.split(c.sep));return await f.readFile(a)}relativeReader(t){return t.endsWith("/")||(t=t+"/"),new d(new URL(t,this.rootUrl),l.join(this.root,...t.split(c.sep)))}getContentReader(t){let a=this;return t!==void 0&&(a=a.relativeReader(t)),o=>a.readFile(o)}}function w(i){return i.split(c.sep).join(l.sep)}function y(i){return i.split(l.sep).join(c.sep)}function C(i,t){i.endsWith("/")||(i=i+"/");const a=new URL(i,`file:${y(l.resolve("."))}/`);switch(a.protocol){case"file:":const o=w(a.pathname);return new d(a,o);case"https:":case"http:":return new n(a,t??new v.Agent);default:throw new Error(`Unknown protocol: ${a.protocol}`)}}exports.BlockComponentsAbsoluteUrl=e.BlockComponentsAbsoluteUrl;exports.BlockComponentsConsolidate=e.BlockComponentsConsolidate;exports.BlockComponentsDescription=e.BlockComponentsDescription;exports.BlockDescriptionPackageJsonField=e.BlockDescriptionPackageJsonField;exports.BlockDescriptionToExplicitBinaryBytes=e.BlockDescriptionToExplicitBinaryBytes;exports.BlockPackDescriptionConsolidateToFolder=e.BlockPackDescriptionConsolidateToFolder;exports.BlockPackDescriptionManifestAddRelativePathPrefix=e.BlockPackDescriptionManifestAddRelativePathPrefix;exports.BlockPackMetaConsolidate=e.BlockPackMetaConsolidate;exports.BlockPackMetaDescription=e.BlockPackMetaDescription;exports.BlockPackMetaEmbedAbsoluteBase64=e.BlockPackMetaEmbedAbsoluteBase64;exports.BlockPackMetaEmbedAbsoluteBytes=e.BlockPackMetaEmbedAbsoluteBytes;exports.BlockPackMetaEmbedBytes=e.BlockPackMetaEmbedBytes;exports.BlockRegistryV2=e.BlockRegistryV2;exports.FSStorage=e.FSStorage;exports.GlobalOverview=e.GlobalOverview;exports.GlobalOverviewEntry=e.GlobalOverviewEntry;exports.GlobalOverviewEntryReg=e.GlobalOverviewEntryReg;exports.GlobalOverviewFileName=e.GlobalOverviewFileName;exports.GlobalOverviewPath=e.GlobalOverviewPath$1;exports.GlobalOverviewReg=e.GlobalOverviewReg;exports.GlobalOverviewToExplicitBinaryBase64=e.GlobalOverviewToExplicitBinaryBase64;exports.GlobalOverviewToExplicitBinaryBytes=e.GlobalOverviewToExplicitBinaryBytes;exports.MainPrefix=e.MainPrefix;exports.ManifestFileName=e.ManifestFileName;exports.ManifestSuffix=e.ManifestSuffix;exports.PackageOverview=e.PackageOverview;exports.PackageOverviewFileName=e.PackageOverviewFileName;exports.PackageOverviewVersionEntry=e.PackageOverviewVersionEntry;exports.ResolvedBlockPackDescriptionFromPackageJson=e.ResolvedBlockPackDescriptionFromPackageJson;exports.ResolvedModuleFile=e.ResolvedModuleFile;exports.ResolvedModuleFolder=e.ResolvedModuleFolder;exports.S3Storage=e.S3Storage;exports.absoluteToBase64=e.absoluteToBase64;exports.absoluteToBytes=e.absoluteToBytes;exports.absoluteToString=e.absoluteToString;exports.buildBlockPackDist=e.buildBlockPackDist;exports.cpAbsoluteToRelative=e.cpAbsoluteToRelative;exports.loadPackDescription=e.loadPackDescription;exports.loadPackDescriptionRaw=e.loadPackDescriptionRaw;exports.mapLocalToAbsolute=e.mapLocalToAbsolute;exports.packFolderToRelativeTgz=e.packFolderToRelativeTgz;exports.packageContentPrefix=e.packageContentPrefix$1;exports.packageContentPrefixInsideV2=e.packageContentPrefixInsideV2;exports.packageOverviewPath=e.packageOverviewPath$1;exports.parsePackageName=e.parsePackageName;exports.relativeToContentString=e.relativeToContentString;exports.relativeToExplicitBinary64=e.relativeToExplicitBinary64;exports.relativeToExplicitBytes=e.relativeToExplicitBytes;exports.relativeToExplicitString=e.relativeToExplicitString;exports.storageByUrl=e.storageByUrl;exports.tryLoadPackDescription=e.tryLoadPackDescription;exports.RegistryV1=m;exports.RegistryV2Reader=R;exports.folderReaderByUrl=C;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/v2/registry/registry_reader.ts","../src/io/folder_reader.ts"],"sourcesContent":["import {\n BlockPackId,\n BlockPackIdNoVersion,\n blockPackIdNoVersionEquals,\n BlockPackManifest,\n BlockPackMetaEmbeddedBytes,\n BlockPackOverview,\n BlockPackSpec\n} from '@milaboratories/pl-model-middle-layer';\nimport { FolderReader } from '../../io';\nimport canonicalize from 'canonicalize';\nimport {\n GlobalOverviewEntryReg,\n GlobalOverviewFileName,\n GlobalOverviewReg,\n MainPrefix,\n ManifestFileName,\n packageContentPrefix,\n packageContentPrefixInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\nimport { LRUCache } from 'lru-cache';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport type RegistryV2ReaderOps = {\n /** Number of milliseconds to cache retrieved block list for */\n cacheBlockListFor: number;\n /** Number of milliseconds to keep cached retrieved block list for, if new requests returns error */\n keepStaleBlockListFor: number;\n};\n\nconst DefaultRegistryV2ReaderOps: RegistryV2ReaderOps = {\n cacheBlockListFor: 45e3, // 45 seconds\n keepStaleBlockListFor: 300e3 // 5 minutes\n};\n\nexport class RegistryV2Reader {\n private readonly v2RootFolderReader: FolderReader;\n private readonly ops: RegistryV2ReaderOps;\n\n constructor(\n private readonly registryReader: FolderReader,\n ops?: Partial<RegistryV2ReaderOps>\n ) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n this.ops = { ...DefaultRegistryV2ReaderOps, ...(ops ?? {}) };\n }\n\n private readonly embeddedMetaCache = new LRUCache<\n string,\n BlockPackMetaEmbeddedBytes,\n GlobalOverviewEntryReg\n >({\n max: 500,\n fetchMethod: async (key, staleValue, options) => {\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n const meta = await BlockPackMetaEmbedBytes(rootContentReader).parseAsync(\n options.context.latest.meta\n );\n return meta;\n }\n });\n\n private async embedMetaContent(\n entry: GlobalOverviewEntryReg\n ): Promise<BlockPackMetaEmbeddedBytes> {\n return await this.embeddedMetaCache.forceFetch(\n canonicalize({ id: entry.id, sha256: entry.latestManifestSha256 })!,\n { context: entry }\n );\n }\n\n private listCacheTimestamp: number = 0;\n private listCache: BlockPackOverviewNoRegLabel[] | undefined = undefined;\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.cacheBlockListFor\n )\n return this.listCache;\n try {\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n\n const globalOverview = GlobalOverviewReg.parse(\n JSON.parse(\n Buffer.from(await this.v2RootFolderReader.readFile(GlobalOverviewFileName)).toString()\n )\n );\n\n const result = await Promise.all(\n globalOverview.packages.map(\n async (p) =>\n ({\n id: p.latest.id,\n meta: await this.embedMetaContent(p),\n spec: {\n type: 'from-registry-v2',\n id: p.latest.id,\n registryUrl: this.registryReader.rootUrl.toString()\n },\n otherVersions: p.allVersions\n }) satisfies BlockPackOverviewNoRegLabel\n )\n );\n\n this.listCache = result;\n this.listCacheTimestamp = Date.now();\n\n return result;\n } catch (e: unknown) {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.keepStaleBlockListFor\n )\n return this.listCache;\n throw e;\n }\n }\n\n public async getOverviewForSpec(\n id: BlockPackIdNoVersion\n ): Promise<BlockPackOverviewNoRegLabel | undefined> {\n return (await this.listBlockPacks()).find((e) => blockPackIdNoVersionEquals(id, e.id));\n }\n\n private readonly componentsCache = new LRUCache<string, BlockComponentsAbsoluteUrl, BlockPackId>({\n max: 500,\n fetchMethod: async (key, staleValue, { context: id }) => {\n const packageFolderReader = this.v2RootFolderReader.relativeReader(\n packageContentPrefixInsideV2(id)\n );\n const manifest = BlockPackManifest.parse(\n JSON.parse(Buffer.from(await packageFolderReader.readFile(ManifestFileName)).toString())\n );\n return BlockComponentsAbsoluteUrl(packageFolderReader.rootUrl.toString()).parse(\n manifest.description.components\n );\n }\n });\n\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\n return await this.componentsCache.forceFetch(canonicalize(id)!, { context: id });\n }\n}\n","import { Agent, Dispatcher, request } from 'undici';\nimport { RelativeContentReader } from '../v2';\nimport path from 'node:path';\nimport pathPosix from 'node:path/posix';\nimport fsp from 'node:fs/promises';\n\nexport interface FolderReader {\n readonly rootUrl: URL;\n relativeReader(relativePath: string): FolderReader;\n readFile(file: string): Promise<Buffer>;\n getContentReader(relativePath?: string): RelativeContentReader;\n}\n\nclass HttpFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly httpDispatcher: Dispatcher\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetUrl = new URL(file, this.rootUrl);\n const response = await request(targetUrl, {\n dispatcher: this.httpDispatcher\n });\n return Buffer.from(await response.body.arrayBuffer());\n }\n\n public relativeReader(relativePath: string): HttpFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new HttpFolderReader(new URL(relativePath, this.rootUrl), this.httpDispatcher);\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: HttpFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nclass FSFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly root: string\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetPath = path.join(this.root, ...file.split(pathPosix.sep));\n return await fsp.readFile(targetPath);\n }\n\n public relativeReader(relativePath: string): FSFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new FSFolderReader(\n new URL(relativePath, this.rootUrl),\n path.join(this.root, ...relativePath.split(pathPosix.sep))\n );\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: FSFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nfunction posixToLocalPath(p: string): string {\n return p.split(pathPosix.sep).join(path.sep);\n}\n\nfunction localToPosix(p: string): string {\n return p.split(path.sep).join(pathPosix.sep);\n}\n\nexport function folderReaderByUrl(address: string, httpDispatcher?: Dispatcher): FolderReader {\n if (!address.endsWith('/')) address = address + '/';\n const url = new URL(address, `file:${localToPosix(path.resolve('.'))}/`);\n switch (url.protocol) {\n case 'file:':\n const rootPath = posixToLocalPath(url.pathname);\n return new FSFolderReader(url, rootPath);\n case 'https:':\n case 'http:':\n return new HttpFolderReader(url, httpDispatcher ?? new Agent());\n default:\n throw new Error(`Unknown protocol: ${url.protocol}`);\n }\n}\n"],"names":["DefaultRegistryV2ReaderOps","RegistryV2Reader","registryReader","ops","__publicField","LRUCache","key","staleValue","options","rootContentReader","BlockPackMetaEmbedBytes","id","packageFolderReader","packageContentPrefixInsideV2","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","MainPrefix","entry","canonicalize","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","result","p","e","blockPackIdNoVersionEquals","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","posixToLocalPath","localToPosix","folderReaderByUrl","address","url","rootPath","Agent"],"mappings":"0kBAgCMA,EAAkD,CACtD,kBAAmB,KACnB,sBAAuB,GACzB,EAEO,MAAMC,CAAiB,CAI5B,YACmBC,EACjBC,EACA,CANeC,EAAA,2BACAA,EAAA,YAUAA,EAAA,yBAAoB,IAAIC,EAAAA,SAIvC,CACA,IAAK,IACL,YAAa,MAAOC,EAAKC,EAAYC,IAAY,CACzC,MAAAC,EAAoB,KAAK,mBAAmB,iBAAiB,EAI5D,OAHM,MAAMC,0BAAwBD,CAAiB,EAAE,WAC5DD,EAAQ,QAAQ,OAAO,IAAA,CAG3B,CAAA,CACD,GAWOJ,EAAA,0BAA6B,GAC7BA,EAAA,kBAqDSA,EAAA,uBAAkB,IAAIC,EAAAA,SAA0D,CAC/F,IAAK,IACL,YAAa,MAAOC,EAAKC,EAAY,CAAE,QAASI,KAAS,CACjD,MAAAC,EAAsB,KAAK,mBAAmB,eAClDC,EAAAA,6BAA6BF,CAAE,CAAA,EAE3BG,EAAWC,EAAAA,kBAAkB,MACjC,KAAK,MAAM,OAAO,KAAK,MAAMH,EAAoB,SAAS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AAiBN,EAA8C,CACpE,IAAIC,EAAyB,KAC7B,OAAID,IAAiB,SAAoBC,EAAAA,EAAO,eAAeD,CAAY,GACnEE,GAASD,EAAO,SAASC,CAAI,CACvC,CACF,CAEA,SAASM,EAAiBlB,EAAmB,CAC3C,OAAOA,EAAE,MAAMgB,EAAU,GAAG,EAAE,KAAKJ,EAAK,GAAG,CAC7C,CAEA,SAASO,EAAanB,EAAmB,CACvC,OAAOA,EAAE,MAAMY,EAAK,GAAG,EAAE,KAAKI,EAAU,GAAG,CAC7C,CAEgB,SAAAI,EAAkBC,EAAiBhB,EAA2C,CACvFgB,EAAQ,SAAS,GAAG,MAAaA,EAAU,KAC1C,MAAAC,EAAM,IAAI,IAAID,EAAS,QAAQF,EAAaP,EAAK,QAAQ,GAAG,CAAC,CAAC,GAAG,EACvE,OAAQU,EAAI,SAAU,CACpB,IAAK,QACG,MAAAC,EAAWL,EAAiBI,EAAI,QAAQ,EACvC,OAAA,IAAIT,EAAeS,EAAKC,CAAQ,EACzC,IAAK,SACL,IAAK,QACH,OAAO,IAAIpB,EAAiBmB,EAAKjB,GAAkB,IAAImB,EAAAA,KAAO,EAChE,QACE,MAAM,IAAI,MAAM,qBAAqBF,EAAI,QAAQ,EAAE,CACvD,CACF"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/v2/registry/registry_reader.ts","../src/io/folder_reader.ts"],"sourcesContent":["import {\n BlockPackId,\n BlockPackIdNoVersion,\n blockPackIdNoVersionEquals,\n BlockPackManifest,\n BlockPackMetaEmbeddedBytes,\n BlockPackOverview\n} from '@milaboratories/pl-model-middle-layer';\nimport { FolderReader } from '../../io';\nimport canonicalize from 'canonicalize';\nimport {\n GlobalOverviewEntryReg,\n GlobalOverviewFileName,\n GlobalOverviewReg,\n MainPrefix,\n ManifestFileName,\n packageContentPrefixInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\nimport { LRUCache } from 'lru-cache';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport type RegistryV2ReaderOps = {\n /** Number of milliseconds to cache retrieved block list for */\n cacheBlockListFor: number;\n /** Number of milliseconds to keep cached retrieved block list for, if new requests returns error */\n keepStaleBlockListFor: number;\n};\n\nconst DefaultRegistryV2ReaderOps: RegistryV2ReaderOps = {\n cacheBlockListFor: 45e3, // 45 seconds\n keepStaleBlockListFor: 300e3 // 5 minutes\n};\n\nexport class RegistryV2Reader {\n private readonly v2RootFolderReader: FolderReader;\n private readonly ops: RegistryV2ReaderOps;\n\n constructor(\n private readonly registryReader: FolderReader,\n ops?: Partial<RegistryV2ReaderOps>\n ) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n this.ops = { ...DefaultRegistryV2ReaderOps, ...(ops ?? {}) };\n }\n\n private readonly embeddedMetaCache = new LRUCache<\n string,\n BlockPackMetaEmbeddedBytes,\n GlobalOverviewEntryReg\n >({\n max: 500,\n fetchMethod: async (_key, _staleValue, options) => {\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n return await BlockPackMetaEmbedBytes(rootContentReader).parseAsync(\n options.context.latest.meta\n );\n }\n });\n\n private async embedMetaContent(\n entry: GlobalOverviewEntryReg\n ): Promise<BlockPackMetaEmbeddedBytes> {\n return await this.embeddedMetaCache.forceFetch(\n canonicalize({ id: entry.id, sha256: entry.latestManifestSha256 })!,\n { context: entry }\n );\n }\n\n private listCacheTimestamp: number = 0;\n private listCache: BlockPackOverviewNoRegLabel[] | undefined = undefined;\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.cacheBlockListFor\n )\n return this.listCache;\n try {\n // const rootContentReader = this.v2RootFolderReader.getContentReader();\n const globalOverview = GlobalOverviewReg.parse(\n JSON.parse(\n Buffer.from(await this.v2RootFolderReader.readFile(GlobalOverviewFileName)).toString()\n )\n );\n\n const result = await Promise.all(\n globalOverview.packages.map(\n async (p) =>\n ({\n id: p.latest.id,\n meta: await this.embedMetaContent(p),\n spec: {\n type: 'from-registry-v2',\n id: p.latest.id,\n registryUrl: this.registryReader.rootUrl.toString()\n },\n otherVersions: p.allVersions\n }) satisfies BlockPackOverviewNoRegLabel\n )\n );\n\n this.listCache = result;\n this.listCacheTimestamp = Date.now();\n\n return result;\n } catch (e: unknown) {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.keepStaleBlockListFor\n )\n return this.listCache;\n throw e;\n }\n }\n\n public async getOverviewForSpec(\n id: BlockPackIdNoVersion\n ): Promise<BlockPackOverviewNoRegLabel | undefined> {\n return (await this.listBlockPacks()).find((e) => blockPackIdNoVersionEquals(id, e.id));\n }\n\n private readonly componentsCache = new LRUCache<string, BlockComponentsAbsoluteUrl, BlockPackId>({\n max: 500,\n fetchMethod: async (key, staleValue, { context: id }) => {\n const packageFolderReader = this.v2RootFolderReader.relativeReader(\n packageContentPrefixInsideV2(id)\n );\n const manifest = BlockPackManifest.parse(\n JSON.parse(Buffer.from(await packageFolderReader.readFile(ManifestFileName)).toString())\n );\n return BlockComponentsAbsoluteUrl(packageFolderReader.rootUrl.toString()).parse(\n manifest.description.components\n );\n }\n });\n\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\n return await this.componentsCache.forceFetch(canonicalize(id)!, { context: id });\n }\n}\n","import { Agent, Dispatcher, request } from 'undici';\nimport { RelativeContentReader } from '../v2';\nimport path from 'node:path';\nimport pathPosix from 'node:path/posix';\nimport fsp from 'node:fs/promises';\n\nexport interface FolderReader {\n readonly rootUrl: URL;\n relativeReader(relativePath: string): FolderReader;\n readFile(file: string): Promise<Buffer>;\n getContentReader(relativePath?: string): RelativeContentReader;\n}\n\nclass HttpFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly httpDispatcher: Dispatcher\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetUrl = new URL(file, this.rootUrl);\n const response = await request(targetUrl, {\n dispatcher: this.httpDispatcher\n });\n return Buffer.from(await response.body.arrayBuffer());\n }\n\n public relativeReader(relativePath: string): HttpFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new HttpFolderReader(new URL(relativePath, this.rootUrl), this.httpDispatcher);\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: HttpFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nclass FSFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly root: string\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetPath = path.join(this.root, ...file.split(pathPosix.sep));\n return await fsp.readFile(targetPath);\n }\n\n public relativeReader(relativePath: string): FSFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new FSFolderReader(\n new URL(relativePath, this.rootUrl),\n path.join(this.root, ...relativePath.split(pathPosix.sep))\n );\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: FSFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nfunction posixToLocalPath(p: string): string {\n return p.split(pathPosix.sep).join(path.sep);\n}\n\nfunction localToPosix(p: string): string {\n return p.split(path.sep).join(pathPosix.sep);\n}\n\nexport function folderReaderByUrl(address: string, httpDispatcher?: Dispatcher): FolderReader {\n if (!address.endsWith('/')) address = address + '/';\n const url = new URL(address, `file:${localToPosix(path.resolve('.'))}/`);\n switch (url.protocol) {\n case 'file:':\n const rootPath = posixToLocalPath(url.pathname);\n return new FSFolderReader(url, rootPath);\n case 'https:':\n case 'http:':\n return new HttpFolderReader(url, httpDispatcher ?? new Agent());\n default:\n throw new Error(`Unknown protocol: ${url.protocol}`);\n }\n}\n"],"names":["DefaultRegistryV2ReaderOps","RegistryV2Reader","registryReader","ops","__publicField","LRUCache","_key","_staleValue","options","rootContentReader","BlockPackMetaEmbedBytes","key","staleValue","id","packageFolderReader","packageContentPrefixInsideV2","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","MainPrefix","entry","canonicalize","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","result","p","e","blockPackIdNoVersionEquals","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","posixToLocalPath","localToPosix","folderReaderByUrl","address","url","rootPath","Agent"],"mappings":"0kBA8BMA,EAAkD,CACtD,kBAAmB,KACnB,sBAAuB,GACzB,EAEO,MAAMC,CAAiB,CAI5B,YACmBC,EACjBC,EACA,CANeC,EAAA,2BACAA,EAAA,YAUAA,EAAA,yBAAoB,IAAIC,EAAAA,SAIvC,CACA,IAAK,IACL,YAAa,MAAOC,EAAMC,EAAaC,IAAY,CAC3C,MAAAC,EAAoB,KAAK,mBAAmB,iBAAiB,EAC5D,OAAA,MAAMC,EAAAA,wBAAwBD,CAAiB,EAAE,WACtDD,EAAQ,QAAQ,OAAO,IAAA,CAE3B,CAAA,CACD,GAWOJ,EAAA,0BAA6B,GAC7BA,EAAA,kBAoDSA,EAAA,uBAAkB,IAAIC,EAAAA,SAA0D,CAC/F,IAAK,IACL,YAAa,MAAOM,EAAKC,EAAY,CAAE,QAASC,KAAS,CACjD,MAAAC,EAAsB,KAAK,mBAAmB,eAClDC,EAAAA,6BAA6BF,CAAE,CAAA,EAE3BG,EAAWC,EAAAA,kBAAkB,MACjC,KAAK,MAAM,OAAO,KAAK,MAAMH,EAAoB,SAASI,EAAgB,gBAAA,CAAC,EAAE,UAAU,CAAA,EAEzF,OAAOC,EAA2B,2BAAAL,EAAoB,QAAQ,SAAA,CAAU,EAAE,MACxEE,EAAS,YAAY,UAAA,CAEzB,CAAA,CACD,GAhGkB,KAAA,eAAAd,EAGZ,KAAA,mBAAqBA,EAAe,eAAekB,EAAU,UAAA,EAClE,KAAK,IAAM,CAAE,GAAGpB,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AAK,GAAG,EAAE,KAAKI,EAAU,GAAG,CAC7C,CAEgB,SAAAI,EAAkBC,EAAiBhB,EAA2C,CACvFgB,EAAQ,SAAS,GAAG,MAAaA,EAAU,KAC1C,MAAAC,EAAM,IAAI,IAAID,EAAS,QAAQF,EAAaP,EAAK,QAAQ,GAAG,CAAC,CAAC,GAAG,EACvE,OAAQU,EAAI,SAAU,CACpB,IAAK,QACG,MAAAC,EAAWL,EAAiBI,EAAI,QAAQ,EACvC,OAAA,IAAIT,EAAeS,EAAKC,CAAQ,EACzC,IAAK,SACL,IAAK,QACH,OAAO,IAAIpB,EAAiBmB,EAAKjB,GAAkB,IAAImB,EAAAA,KAAO,EAChE,QACE,MAAM,IAAI,MAAM,qBAAqBF,EAAI,QAAQ,EAAE,CACvD,CACF"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
var m = Object.defineProperty;
|
|
2
|
-
var f = (
|
|
3
|
-
var
|
|
4
|
-
import { e as k, f as g, G as
|
|
5
|
-
import { Q as
|
|
2
|
+
var f = (o, e, a) => e in o ? m(o, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : o[e] = a;
|
|
3
|
+
var s = (o, e, a) => f(o, typeof e != "symbol" ? e + "" : e, a);
|
|
4
|
+
import { e as k, f as g, G as u, h as v, p as w, M as R, i as P, j as B, k as y, m as C, n as F, o as b, q as x, r as D, t as T, P as M, u as O, v as S, w as U } from "./config-C9KOwWbG.mjs";
|
|
5
|
+
import { Q as re, O as le, W as ne, a7 as ce, U as pe, V as de, L as he, a as me, B as fe, N as ke, d as ge, F as ue, a6 as ve, a4 as we, a5 as Re, a3 as Pe, a9 as Be, a8 as ye, $ as Ce, a1 as Fe, Z as be, a0 as xe, T as De, R as Te, x as Me, S as Oe, A as Se, C as Ue, z as Ee, c as Le, D as Ve, b as Ge, l as Ae, y as Ne, E as je, _ as Je, a2 as _e, X as ze, I as We, J as qe, K as Ie, H as $e, s as Ye, Y as He } from "./config-C9KOwWbG.mjs";
|
|
6
6
|
import { Agent as E, request as L } from "undici";
|
|
7
7
|
import i from "node:path";
|
|
8
8
|
import l from "node:path/posix";
|
|
9
9
|
import V from "node:fs/promises";
|
|
10
10
|
import { blockPackIdNoVersionEquals as G, BlockPackManifest as A } from "@milaboratories/pl-model-middle-layer";
|
|
11
|
-
import
|
|
11
|
+
import p from "canonicalize";
|
|
12
12
|
import "zod";
|
|
13
13
|
import "mime-types";
|
|
14
14
|
import "tar";
|
|
15
15
|
import "@milaboratories/resolve-helper";
|
|
16
|
-
import { LRUCache as
|
|
16
|
+
import { LRUCache as d } from "lru-cache";
|
|
17
17
|
const N = {
|
|
18
18
|
cacheBlockListFor: 45e3,
|
|
19
19
|
// 45 seconds
|
|
20
20
|
keepStaleBlockListFor: 3e5
|
|
21
21
|
// 5 minutes
|
|
22
22
|
};
|
|
23
|
-
class
|
|
24
|
-
constructor(e,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
class ae {
|
|
24
|
+
constructor(e, a) {
|
|
25
|
+
s(this, "v2RootFolderReader");
|
|
26
|
+
s(this, "ops");
|
|
27
|
+
s(this, "embeddedMetaCache", new d({
|
|
28
28
|
max: 500,
|
|
29
|
-
fetchMethod: async (e,
|
|
30
|
-
const
|
|
31
|
-
return await g(
|
|
32
|
-
|
|
29
|
+
fetchMethod: async (e, a, t) => {
|
|
30
|
+
const r = this.v2RootFolderReader.getContentReader();
|
|
31
|
+
return await g(r).parseAsync(
|
|
32
|
+
t.context.latest.meta
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
}));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
s(this, "listCacheTimestamp", 0);
|
|
37
|
+
s(this, "listCache");
|
|
38
|
+
s(this, "componentsCache", new d({
|
|
39
39
|
max: 500,
|
|
40
|
-
fetchMethod: async (e,
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
),
|
|
44
|
-
JSON.parse(Buffer.from(await
|
|
40
|
+
fetchMethod: async (e, a, { context: t }) => {
|
|
41
|
+
const r = this.v2RootFolderReader.relativeReader(
|
|
42
|
+
w(t)
|
|
43
|
+
), h = A.parse(
|
|
44
|
+
JSON.parse(Buffer.from(await r.readFile(R)).toString())
|
|
45
45
|
);
|
|
46
|
-
return P(
|
|
47
|
-
|
|
46
|
+
return P(r.rootUrl.toString()).parse(
|
|
47
|
+
h.description.components
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
}));
|
|
51
|
-
this.registryReader = e, this.v2RootFolderReader = e.relativeReader(k), this.ops = { ...N, ...
|
|
51
|
+
this.registryReader = e, this.v2RootFolderReader = e.relativeReader(k), this.ops = { ...N, ...a ?? {} };
|
|
52
52
|
}
|
|
53
53
|
async embedMetaContent(e) {
|
|
54
54
|
return await this.embeddedMetaCache.forceFetch(
|
|
55
|
-
|
|
55
|
+
p({ id: e.id, sha256: e.latestManifestSha256 }),
|
|
56
56
|
{ context: e }
|
|
57
57
|
);
|
|
58
58
|
}
|
|
@@ -60,25 +60,25 @@ class te {
|
|
|
60
60
|
if (this.listCache !== void 0 && Date.now() - this.listCacheTimestamp <= this.ops.cacheBlockListFor)
|
|
61
61
|
return this.listCache;
|
|
62
62
|
try {
|
|
63
|
-
const e =
|
|
63
|
+
const e = u.parse(
|
|
64
64
|
JSON.parse(
|
|
65
|
-
Buffer.from(await this.v2RootFolderReader.readFile(
|
|
65
|
+
Buffer.from(await this.v2RootFolderReader.readFile(v)).toString()
|
|
66
66
|
)
|
|
67
|
-
),
|
|
68
|
-
|
|
69
|
-
async (
|
|
70
|
-
id:
|
|
71
|
-
meta: await this.embedMetaContent(
|
|
67
|
+
), a = await Promise.all(
|
|
68
|
+
e.packages.map(
|
|
69
|
+
async (t) => ({
|
|
70
|
+
id: t.latest.id,
|
|
71
|
+
meta: await this.embedMetaContent(t),
|
|
72
72
|
spec: {
|
|
73
73
|
type: "from-registry-v2",
|
|
74
|
-
id:
|
|
74
|
+
id: t.latest.id,
|
|
75
75
|
registryUrl: this.registryReader.rootUrl.toString()
|
|
76
76
|
},
|
|
77
|
-
otherVersions:
|
|
77
|
+
otherVersions: t.allVersions
|
|
78
78
|
})
|
|
79
79
|
)
|
|
80
80
|
);
|
|
81
|
-
return this.listCache =
|
|
81
|
+
return this.listCache = a, this.listCacheTimestamp = Date.now(), a;
|
|
82
82
|
} catch (e) {
|
|
83
83
|
if (this.listCache !== void 0 && Date.now() - this.listCacheTimestamp <= this.ops.keepStaleBlockListFor)
|
|
84
84
|
return this.listCache;
|
|
@@ -86,17 +86,17 @@ class te {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
async getOverviewForSpec(e) {
|
|
89
|
-
return (await this.listBlockPacks()).find((
|
|
89
|
+
return (await this.listBlockPacks()).find((a) => G(e, a.id));
|
|
90
90
|
}
|
|
91
91
|
async getComponents(e) {
|
|
92
|
-
return await this.componentsCache.forceFetch(
|
|
92
|
+
return await this.componentsCache.forceFetch(p(e), { context: e });
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
const
|
|
95
|
+
const te = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
96
96
|
__proto__: null,
|
|
97
|
-
GlobalOverviewPath:
|
|
98
|
-
MetaFile:
|
|
99
|
-
PlPackageConfigData:
|
|
97
|
+
GlobalOverviewPath: B,
|
|
98
|
+
MetaFile: y,
|
|
99
|
+
PlPackageConfigData: C,
|
|
100
100
|
PlPackageJsonConfigFile: F,
|
|
101
101
|
PlPackageYamlConfigFile: b,
|
|
102
102
|
PlRegCommonConfigData: x,
|
|
@@ -108,30 +108,30 @@ const ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
108
108
|
payloadFilePath: U
|
|
109
109
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
110
110
|
class n {
|
|
111
|
-
constructor(e,
|
|
112
|
-
this.rootUrl = e, this.httpDispatcher =
|
|
111
|
+
constructor(e, a) {
|
|
112
|
+
this.rootUrl = e, this.httpDispatcher = a;
|
|
113
113
|
}
|
|
114
114
|
async readFile(e) {
|
|
115
|
-
const
|
|
115
|
+
const a = new URL(e, this.rootUrl), t = await L(a, {
|
|
116
116
|
dispatcher: this.httpDispatcher
|
|
117
117
|
});
|
|
118
|
-
return Buffer.from(await
|
|
118
|
+
return Buffer.from(await t.body.arrayBuffer());
|
|
119
119
|
}
|
|
120
120
|
relativeReader(e) {
|
|
121
121
|
return e.endsWith("/") || (e = e + "/"), new n(new URL(e, this.rootUrl), this.httpDispatcher);
|
|
122
122
|
}
|
|
123
123
|
getContentReader(e) {
|
|
124
|
-
let
|
|
125
|
-
return e !== void 0 && (
|
|
124
|
+
let a = this;
|
|
125
|
+
return e !== void 0 && (a = a.relativeReader(e)), (t) => a.readFile(t);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
class c {
|
|
129
|
-
constructor(e,
|
|
130
|
-
this.rootUrl = e, this.root =
|
|
129
|
+
constructor(e, a) {
|
|
130
|
+
this.rootUrl = e, this.root = a;
|
|
131
131
|
}
|
|
132
132
|
async readFile(e) {
|
|
133
|
-
const
|
|
134
|
-
return await V.readFile(
|
|
133
|
+
const a = i.join(this.root, ...e.split(l.sep));
|
|
134
|
+
return await V.readFile(a);
|
|
135
135
|
}
|
|
136
136
|
relativeReader(e) {
|
|
137
137
|
return e.endsWith("/") || (e = e + "/"), new c(
|
|
@@ -140,33 +140,33 @@ class c {
|
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
142
|
getContentReader(e) {
|
|
143
|
-
let
|
|
144
|
-
return e !== void 0 && (
|
|
143
|
+
let a = this;
|
|
144
|
+
return e !== void 0 && (a = a.relativeReader(e)), (t) => a.readFile(t);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
function j(
|
|
148
|
-
return
|
|
147
|
+
function j(o) {
|
|
148
|
+
return o.split(l.sep).join(i.sep);
|
|
149
149
|
}
|
|
150
|
-
function J(
|
|
151
|
-
return
|
|
150
|
+
function J(o) {
|
|
151
|
+
return o.split(i.sep).join(l.sep);
|
|
152
152
|
}
|
|
153
|
-
function oe(
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
switch (
|
|
153
|
+
function oe(o, e) {
|
|
154
|
+
o.endsWith("/") || (o = o + "/");
|
|
155
|
+
const a = new URL(o, `file:${J(i.resolve("."))}/`);
|
|
156
|
+
switch (a.protocol) {
|
|
157
157
|
case "file:":
|
|
158
|
-
const
|
|
159
|
-
return new c(
|
|
158
|
+
const t = j(a.pathname);
|
|
159
|
+
return new c(a, t);
|
|
160
160
|
case "https:":
|
|
161
161
|
case "http:":
|
|
162
|
-
return new n(
|
|
162
|
+
return new n(a, e ?? new E());
|
|
163
163
|
default:
|
|
164
|
-
throw new Error(`Unknown protocol: ${
|
|
164
|
+
throw new Error(`Unknown protocol: ${a.protocol}`);
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
export {
|
|
168
168
|
P as BlockComponentsAbsoluteUrl,
|
|
169
|
-
|
|
169
|
+
re as BlockComponentsConsolidate,
|
|
170
170
|
le as BlockComponentsDescription,
|
|
171
171
|
ne as BlockDescriptionPackageJsonField,
|
|
172
172
|
ce as BlockDescriptionToExplicitBinaryBytes,
|
|
@@ -178,23 +178,23 @@ export {
|
|
|
178
178
|
ke as BlockPackMetaEmbedAbsoluteBytes,
|
|
179
179
|
g as BlockPackMetaEmbedBytes,
|
|
180
180
|
ge as BlockRegistryV2,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
ue as FSStorage,
|
|
182
|
+
ve as GlobalOverview,
|
|
183
|
+
we as GlobalOverviewEntry,
|
|
184
|
+
Re as GlobalOverviewEntryReg,
|
|
185
|
+
v as GlobalOverviewFileName,
|
|
186
186
|
Pe as GlobalOverviewPath,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
u as GlobalOverviewReg,
|
|
188
|
+
Be as GlobalOverviewToExplicitBinaryBase64,
|
|
189
|
+
ye as GlobalOverviewToExplicitBinaryBytes,
|
|
190
190
|
k as MainPrefix,
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
R as ManifestFileName,
|
|
192
|
+
Ce as ManifestSuffix,
|
|
193
193
|
Fe as PackageOverview,
|
|
194
194
|
be as PackageOverviewFileName,
|
|
195
195
|
xe as PackageOverviewVersionEntry,
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
te as RegistryV1,
|
|
197
|
+
ae as RegistryV2Reader,
|
|
198
198
|
De as ResolvedBlockPackDescriptionFromPackageJson,
|
|
199
199
|
Te as ResolvedModuleFile,
|
|
200
200
|
Me as ResolvedModuleFolder,
|
|
@@ -210,12 +210,12 @@ export {
|
|
|
210
210
|
Ne as mapLocalToAbsolute,
|
|
211
211
|
je as packFolderToRelativeTgz,
|
|
212
212
|
Je as packageContentPrefix,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
213
|
+
w as packageContentPrefixInsideV2,
|
|
214
|
+
_e as packageOverviewPath,
|
|
215
|
+
ze as parsePackageName,
|
|
216
|
+
We as relativeToContentString,
|
|
217
|
+
qe as relativeToExplicitBinary64,
|
|
218
|
+
Ie as relativeToExplicitBytes,
|
|
219
219
|
$e as relativeToExplicitString,
|
|
220
220
|
Ye as storageByUrl,
|
|
221
221
|
He as tryLoadPackDescription
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/v2/registry/registry_reader.ts","../src/io/folder_reader.ts"],"sourcesContent":["import {\n BlockPackId,\n BlockPackIdNoVersion,\n blockPackIdNoVersionEquals,\n BlockPackManifest,\n BlockPackMetaEmbeddedBytes,\n BlockPackOverview,\n BlockPackSpec\n} from '@milaboratories/pl-model-middle-layer';\nimport { FolderReader } from '../../io';\nimport canonicalize from 'canonicalize';\nimport {\n GlobalOverviewEntryReg,\n GlobalOverviewFileName,\n GlobalOverviewReg,\n MainPrefix,\n ManifestFileName,\n packageContentPrefix,\n packageContentPrefixInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\nimport { LRUCache } from 'lru-cache';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport type RegistryV2ReaderOps = {\n /** Number of milliseconds to cache retrieved block list for */\n cacheBlockListFor: number;\n /** Number of milliseconds to keep cached retrieved block list for, if new requests returns error */\n keepStaleBlockListFor: number;\n};\n\nconst DefaultRegistryV2ReaderOps: RegistryV2ReaderOps = {\n cacheBlockListFor: 45e3, // 45 seconds\n keepStaleBlockListFor: 300e3 // 5 minutes\n};\n\nexport class RegistryV2Reader {\n private readonly v2RootFolderReader: FolderReader;\n private readonly ops: RegistryV2ReaderOps;\n\n constructor(\n private readonly registryReader: FolderReader,\n ops?: Partial<RegistryV2ReaderOps>\n ) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n this.ops = { ...DefaultRegistryV2ReaderOps, ...(ops ?? {}) };\n }\n\n private readonly embeddedMetaCache = new LRUCache<\n string,\n BlockPackMetaEmbeddedBytes,\n GlobalOverviewEntryReg\n >({\n max: 500,\n fetchMethod: async (key, staleValue, options) => {\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n const meta = await BlockPackMetaEmbedBytes(rootContentReader).parseAsync(\n options.context.latest.meta\n );\n return meta;\n }\n });\n\n private async embedMetaContent(\n entry: GlobalOverviewEntryReg\n ): Promise<BlockPackMetaEmbeddedBytes> {\n return await this.embeddedMetaCache.forceFetch(\n canonicalize({ id: entry.id, sha256: entry.latestManifestSha256 })!,\n { context: entry }\n );\n }\n\n private listCacheTimestamp: number = 0;\n private listCache: BlockPackOverviewNoRegLabel[] | undefined = undefined;\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.cacheBlockListFor\n )\n return this.listCache;\n try {\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n\n const globalOverview = GlobalOverviewReg.parse(\n JSON.parse(\n Buffer.from(await this.v2RootFolderReader.readFile(GlobalOverviewFileName)).toString()\n )\n );\n\n const result = await Promise.all(\n globalOverview.packages.map(\n async (p) =>\n ({\n id: p.latest.id,\n meta: await this.embedMetaContent(p),\n spec: {\n type: 'from-registry-v2',\n id: p.latest.id,\n registryUrl: this.registryReader.rootUrl.toString()\n },\n otherVersions: p.allVersions\n }) satisfies BlockPackOverviewNoRegLabel\n )\n );\n\n this.listCache = result;\n this.listCacheTimestamp = Date.now();\n\n return result;\n } catch (e: unknown) {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.keepStaleBlockListFor\n )\n return this.listCache;\n throw e;\n }\n }\n\n public async getOverviewForSpec(\n id: BlockPackIdNoVersion\n ): Promise<BlockPackOverviewNoRegLabel | undefined> {\n return (await this.listBlockPacks()).find((e) => blockPackIdNoVersionEquals(id, e.id));\n }\n\n private readonly componentsCache = new LRUCache<string, BlockComponentsAbsoluteUrl, BlockPackId>({\n max: 500,\n fetchMethod: async (key, staleValue, { context: id }) => {\n const packageFolderReader = this.v2RootFolderReader.relativeReader(\n packageContentPrefixInsideV2(id)\n );\n const manifest = BlockPackManifest.parse(\n JSON.parse(Buffer.from(await packageFolderReader.readFile(ManifestFileName)).toString())\n );\n return BlockComponentsAbsoluteUrl(packageFolderReader.rootUrl.toString()).parse(\n manifest.description.components\n );\n }\n });\n\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\n return await this.componentsCache.forceFetch(canonicalize(id)!, { context: id });\n }\n}\n","import { Agent, Dispatcher, request } from 'undici';\nimport { RelativeContentReader } from '../v2';\nimport path from 'node:path';\nimport pathPosix from 'node:path/posix';\nimport fsp from 'node:fs/promises';\n\nexport interface FolderReader {\n readonly rootUrl: URL;\n relativeReader(relativePath: string): FolderReader;\n readFile(file: string): Promise<Buffer>;\n getContentReader(relativePath?: string): RelativeContentReader;\n}\n\nclass HttpFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly httpDispatcher: Dispatcher\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetUrl = new URL(file, this.rootUrl);\n const response = await request(targetUrl, {\n dispatcher: this.httpDispatcher\n });\n return Buffer.from(await response.body.arrayBuffer());\n }\n\n public relativeReader(relativePath: string): HttpFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new HttpFolderReader(new URL(relativePath, this.rootUrl), this.httpDispatcher);\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: HttpFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nclass FSFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly root: string\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetPath = path.join(this.root, ...file.split(pathPosix.sep));\n return await fsp.readFile(targetPath);\n }\n\n public relativeReader(relativePath: string): FSFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new FSFolderReader(\n new URL(relativePath, this.rootUrl),\n path.join(this.root, ...relativePath.split(pathPosix.sep))\n );\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: FSFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nfunction posixToLocalPath(p: string): string {\n return p.split(pathPosix.sep).join(path.sep);\n}\n\nfunction localToPosix(p: string): string {\n return p.split(path.sep).join(pathPosix.sep);\n}\n\nexport function folderReaderByUrl(address: string, httpDispatcher?: Dispatcher): FolderReader {\n if (!address.endsWith('/')) address = address + '/';\n const url = new URL(address, `file:${localToPosix(path.resolve('.'))}/`);\n switch (url.protocol) {\n case 'file:':\n const rootPath = posixToLocalPath(url.pathname);\n return new FSFolderReader(url, rootPath);\n case 'https:':\n case 'http:':\n return new HttpFolderReader(url, httpDispatcher ?? new Agent());\n default:\n throw new Error(`Unknown protocol: ${url.protocol}`);\n }\n}\n"],"names":["DefaultRegistryV2ReaderOps","RegistryV2Reader","registryReader","ops","__publicField","LRUCache","key","staleValue","options","rootContentReader","BlockPackMetaEmbedBytes","id","packageFolderReader","packageContentPrefixInsideV2","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","MainPrefix","entry","canonicalize","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","result","p","e","blockPackIdNoVersionEquals","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","posixToLocalPath","localToPosix","folderReaderByUrl","address","url","rootPath","Agent"],"mappings":";;;;;;;;;;;;;;;;AAgCA,MAAMA,IAAkD;AAAA,EACtD,mBAAmB;AAAA;AAAA,EACnB,uBAAuB;AAAA;AACzB;AAEO,MAAMC,GAAiB;AAAA,EAI5B,YACmBC,GACjBC,GACA;AANe,IAAAC,EAAA;AACA,IAAAA,EAAA;AAUA,IAAAA,EAAA,2BAAoB,IAAIC,EAIvC;AAAA,MACA,KAAK;AAAA,MACL,aAAa,OAAOC,GAAKC,GAAYC,MAAY;AACzC,cAAAC,IAAoB,KAAK,mBAAmB,iBAAiB;AAI5D,eAHM,MAAMC,EAAwBD,CAAiB,EAAE;AAAA,UAC5DD,EAAQ,QAAQ,OAAO;AAAA,QAAA;AAAA,MAG3B;AAAA,IAAA,CACD;AAWO,IAAAJ,EAAA,4BAA6B;AAC7B,IAAAA,EAAA;AAqDS,IAAAA,EAAA,yBAAkB,IAAIC,EAA0D;AAAA,MAC/F,KAAK;AAAA,MACL,aAAa,OAAOC,GAAKC,GAAY,EAAE,SAASI,QAAS;AACjD,cAAAC,IAAsB,KAAK,mBAAmB;AAAA,UAClDC,EAA6BF,CAAE;AAAA,QAAA,GAE3BG,IAAWC,EAAkB;AAAA,UACjC,KA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src/io/folder_reader.ts"],"sourcesContent":["import {\n BlockPackId,\n BlockPackIdNoVersion,\n blockPackIdNoVersionEquals,\n BlockPackManifest,\n BlockPackMetaEmbeddedBytes,\n BlockPackOverview\n} from '@milaboratories/pl-model-middle-layer';\nimport { FolderReader } from '../../io';\nimport canonicalize from 'canonicalize';\nimport {\n GlobalOverviewEntryReg,\n GlobalOverviewFileName,\n GlobalOverviewReg,\n MainPrefix,\n ManifestFileName,\n packageContentPrefixInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\nimport { LRUCache } from 'lru-cache';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport type RegistryV2ReaderOps = {\n /** Number of milliseconds to cache retrieved block list for */\n cacheBlockListFor: number;\n /** Number of milliseconds to keep cached retrieved block list for, if new requests returns error */\n keepStaleBlockListFor: number;\n};\n\nconst DefaultRegistryV2ReaderOps: RegistryV2ReaderOps = {\n cacheBlockListFor: 45e3, // 45 seconds\n keepStaleBlockListFor: 300e3 // 5 minutes\n};\n\nexport class RegistryV2Reader {\n private readonly v2RootFolderReader: FolderReader;\n private readonly ops: RegistryV2ReaderOps;\n\n constructor(\n private readonly registryReader: FolderReader,\n ops?: Partial<RegistryV2ReaderOps>\n ) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n this.ops = { ...DefaultRegistryV2ReaderOps, ...(ops ?? {}) };\n }\n\n private readonly embeddedMetaCache = new LRUCache<\n string,\n BlockPackMetaEmbeddedBytes,\n GlobalOverviewEntryReg\n >({\n max: 500,\n fetchMethod: async (_key, _staleValue, options) => {\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n return await BlockPackMetaEmbedBytes(rootContentReader).parseAsync(\n options.context.latest.meta\n );\n }\n });\n\n private async embedMetaContent(\n entry: GlobalOverviewEntryReg\n ): Promise<BlockPackMetaEmbeddedBytes> {\n return await this.embeddedMetaCache.forceFetch(\n canonicalize({ id: entry.id, sha256: entry.latestManifestSha256 })!,\n { context: entry }\n );\n }\n\n private listCacheTimestamp: number = 0;\n private listCache: BlockPackOverviewNoRegLabel[] | undefined = undefined;\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.cacheBlockListFor\n )\n return this.listCache;\n try {\n // const rootContentReader = this.v2RootFolderReader.getContentReader();\n const globalOverview = GlobalOverviewReg.parse(\n JSON.parse(\n Buffer.from(await this.v2RootFolderReader.readFile(GlobalOverviewFileName)).toString()\n )\n );\n\n const result = await Promise.all(\n globalOverview.packages.map(\n async (p) =>\n ({\n id: p.latest.id,\n meta: await this.embedMetaContent(p),\n spec: {\n type: 'from-registry-v2',\n id: p.latest.id,\n registryUrl: this.registryReader.rootUrl.toString()\n },\n otherVersions: p.allVersions\n }) satisfies BlockPackOverviewNoRegLabel\n )\n );\n\n this.listCache = result;\n this.listCacheTimestamp = Date.now();\n\n return result;\n } catch (e: unknown) {\n if (\n this.listCache !== undefined &&\n Date.now() - this.listCacheTimestamp <= this.ops.keepStaleBlockListFor\n )\n return this.listCache;\n throw e;\n }\n }\n\n public async getOverviewForSpec(\n id: BlockPackIdNoVersion\n ): Promise<BlockPackOverviewNoRegLabel | undefined> {\n return (await this.listBlockPacks()).find((e) => blockPackIdNoVersionEquals(id, e.id));\n }\n\n private readonly componentsCache = new LRUCache<string, BlockComponentsAbsoluteUrl, BlockPackId>({\n max: 500,\n fetchMethod: async (key, staleValue, { context: id }) => {\n const packageFolderReader = this.v2RootFolderReader.relativeReader(\n packageContentPrefixInsideV2(id)\n );\n const manifest = BlockPackManifest.parse(\n JSON.parse(Buffer.from(await packageFolderReader.readFile(ManifestFileName)).toString())\n );\n return BlockComponentsAbsoluteUrl(packageFolderReader.rootUrl.toString()).parse(\n manifest.description.components\n );\n }\n });\n\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\n return await this.componentsCache.forceFetch(canonicalize(id)!, { context: id });\n }\n}\n","import { Agent, Dispatcher, request } from 'undici';\nimport { RelativeContentReader } from '../v2';\nimport path from 'node:path';\nimport pathPosix from 'node:path/posix';\nimport fsp from 'node:fs/promises';\n\nexport interface FolderReader {\n readonly rootUrl: URL;\n relativeReader(relativePath: string): FolderReader;\n readFile(file: string): Promise<Buffer>;\n getContentReader(relativePath?: string): RelativeContentReader;\n}\n\nclass HttpFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly httpDispatcher: Dispatcher\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetUrl = new URL(file, this.rootUrl);\n const response = await request(targetUrl, {\n dispatcher: this.httpDispatcher\n });\n return Buffer.from(await response.body.arrayBuffer());\n }\n\n public relativeReader(relativePath: string): HttpFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new HttpFolderReader(new URL(relativePath, this.rootUrl), this.httpDispatcher);\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: HttpFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nclass FSFolderReader implements FolderReader {\n constructor(\n public readonly rootUrl: URL,\n private readonly root: string\n ) {}\n\n public async readFile(file: string): Promise<Buffer> {\n const targetPath = path.join(this.root, ...file.split(pathPosix.sep));\n return await fsp.readFile(targetPath);\n }\n\n public relativeReader(relativePath: string): FSFolderReader {\n if (!relativePath.endsWith('/')) relativePath = relativePath + '/';\n return new FSFolderReader(\n new URL(relativePath, this.rootUrl),\n path.join(this.root, ...relativePath.split(pathPosix.sep))\n );\n }\n\n public getContentReader(relativePath?: string): RelativeContentReader {\n let reader: FSFolderReader = this;\n if (relativePath !== undefined) reader = reader.relativeReader(relativePath);\n return (path) => reader.readFile(path);\n }\n}\n\nfunction posixToLocalPath(p: string): string {\n return p.split(pathPosix.sep).join(path.sep);\n}\n\nfunction localToPosix(p: string): string {\n return p.split(path.sep).join(pathPosix.sep);\n}\n\nexport function folderReaderByUrl(address: string, httpDispatcher?: Dispatcher): FolderReader {\n if (!address.endsWith('/')) address = address + '/';\n const url = new URL(address, `file:${localToPosix(path.resolve('.'))}/`);\n switch (url.protocol) {\n case 'file:':\n const rootPath = posixToLocalPath(url.pathname);\n return new FSFolderReader(url, rootPath);\n case 'https:':\n case 'http:':\n return new HttpFolderReader(url, httpDispatcher ?? new Agent());\n default:\n throw new Error(`Unknown protocol: ${url.protocol}`);\n }\n}\n"],"names":["DefaultRegistryV2ReaderOps","RegistryV2Reader","registryReader","ops","__publicField","LRUCache","_key","_staleValue","options","rootContentReader","BlockPackMetaEmbedBytes","key","staleValue","id","packageFolderReader","packageContentPrefixInsideV2","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","MainPrefix","entry","canonicalize","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","result","p","e","blockPackIdNoVersionEquals","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","posixToLocalPath","localToPosix","folderReaderByUrl","address","url","rootPath","Agent"],"mappings":";;;;;;;;;;;;;;;;AA8BA,MAAMA,IAAkD;AAAA,EACtD,mBAAmB;AAAA;AAAA,EACnB,uBAAuB;AAAA;AACzB;AAEO,MAAMC,GAAiB;AAAA,EAI5B,YACmBC,GACjBC,GACA;AANe,IAAAC,EAAA;AACA,IAAAA,EAAA;AAUA,IAAAA,EAAA,2BAAoB,IAAIC,EAIvC;AAAA,MACA,KAAK;AAAA,MACL,aAAa,OAAOC,GAAMC,GAAaC,MAAY;AAC3C,cAAAC,IAAoB,KAAK,mBAAmB,iBAAiB;AAC5D,eAAA,MAAMC,EAAwBD,CAAiB,EAAE;AAAA,UACtDD,EAAQ,QAAQ,OAAO;AAAA,QAAA;AAAA,MAE3B;AAAA,IAAA,CACD;AAWO,IAAAJ,EAAA,4BAA6B;AAC7B,IAAAA,EAAA;AAoDS,IAAAA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AKjB,KAAkB,IAAImB,EAAO,CAAA;AAAA,IAChE;AACE,YAAM,IAAI,MAAM,qBAAqBF,EAAI,QAAQ,EAAE;AAAA,EACvD;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry_reader.d.ts","sourceRoot":"","sources":["../../../src/v2/registry/registry_reader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,oBAAoB,EAIpB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"registry_reader.d.ts","sourceRoot":"","sources":["../../../src/v2/registry/registry_reader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,oBAAoB,EAIpB,iBAAiB,EAClB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAUxC,OAAO,EAAE,0BAA0B,EAA2B,MAAM,UAAU,CAAC;AAG/E,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;AAEhF,MAAM,MAAM,mBAAmB,GAAG;IAChC,+DAA+D;IAC/D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oGAAoG;IACpG,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAC;AAOF,qBAAa,gBAAgB;IAKzB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAJjC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAe;IAClD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAsB;gBAGvB,cAAc,EAAE,YAAY,EAC7C,GAAG,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC;IAMpC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAY/B;YAEW,gBAAgB;IAS9B,OAAO,CAAC,kBAAkB,CAAa;IACvC,OAAO,CAAC,SAAS,CAAwD;IAE5D,cAAc,IAAI,OAAO,CAAC,2BAA2B,EAAE,CAAC;IA4CxD,kBAAkB,CAC7B,EAAE,EAAE,oBAAoB,GACvB,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAInD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAa7B;IAEU,aAAa,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,0BAA0B,CAAC;CAGjF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/block-tools",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.15",
|
|
4
4
|
"description": "Utility to manipulate Platforma Blocks and Block Registry",
|
|
5
5
|
"types": "./dist/lib.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"yaml": "^2.5.1",
|
|
34
34
|
"zod": "^3.23.8",
|
|
35
35
|
"@milaboratories/resolve-helper": "^1.0.1",
|
|
36
|
-
"@milaboratories/pl-model-middle-layer": "^1.
|
|
37
|
-
"@milaboratories/ts-helpers
|
|
38
|
-
"@milaboratories/ts-helpers": "^1.
|
|
36
|
+
"@milaboratories/pl-model-middle-layer": "^1.5.1",
|
|
37
|
+
"@milaboratories/ts-helpers": "^1.1.0",
|
|
38
|
+
"@milaboratories/ts-helpers-oclif": "^1.1.9"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"typescript": "~5.5.4",
|
|
@@ -4,8 +4,7 @@ import {
|
|
|
4
4
|
blockPackIdNoVersionEquals,
|
|
5
5
|
BlockPackManifest,
|
|
6
6
|
BlockPackMetaEmbeddedBytes,
|
|
7
|
-
BlockPackOverview
|
|
8
|
-
BlockPackSpec
|
|
7
|
+
BlockPackOverview
|
|
9
8
|
} from '@milaboratories/pl-model-middle-layer';
|
|
10
9
|
import { FolderReader } from '../../io';
|
|
11
10
|
import canonicalize from 'canonicalize';
|
|
@@ -15,7 +14,6 @@ import {
|
|
|
15
14
|
GlobalOverviewReg,
|
|
16
15
|
MainPrefix,
|
|
17
16
|
ManifestFileName,
|
|
18
|
-
packageContentPrefix,
|
|
19
17
|
packageContentPrefixInsideV2
|
|
20
18
|
} from './schema_public';
|
|
21
19
|
import { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';
|
|
@@ -53,12 +51,11 @@ export class RegistryV2Reader {
|
|
|
53
51
|
GlobalOverviewEntryReg
|
|
54
52
|
>({
|
|
55
53
|
max: 500,
|
|
56
|
-
fetchMethod: async (
|
|
54
|
+
fetchMethod: async (_key, _staleValue, options) => {
|
|
57
55
|
const rootContentReader = this.v2RootFolderReader.getContentReader();
|
|
58
|
-
|
|
56
|
+
return await BlockPackMetaEmbedBytes(rootContentReader).parseAsync(
|
|
59
57
|
options.context.latest.meta
|
|
60
58
|
);
|
|
61
|
-
return meta;
|
|
62
59
|
}
|
|
63
60
|
});
|
|
64
61
|
|
|
@@ -81,8 +78,7 @@ export class RegistryV2Reader {
|
|
|
81
78
|
)
|
|
82
79
|
return this.listCache;
|
|
83
80
|
try {
|
|
84
|
-
const rootContentReader = this.v2RootFolderReader.getContentReader();
|
|
85
|
-
|
|
81
|
+
// const rootContentReader = this.v2RootFolderReader.getContentReader();
|
|
86
82
|
const globalOverview = GlobalOverviewReg.parse(
|
|
87
83
|
JSON.parse(
|
|
88
84
|
Buffer.from(await this.v2RootFolderReader.readFile(GlobalOverviewFileName)).toString()
|