@platforma-sdk/block-tools 2.3.1 → 2.3.3
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 +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -33
- package/dist/index.mjs.map +1 -1
- package/dist/io/folder_reader.d.ts.map +1 -1
- package/dist/v2/model/block_description.d.ts +360 -0
- package/dist/v2/model/block_description.d.ts.map +1 -1
- package/dist/v2/model/block_meta.d.ts +231 -0
- package/dist/v2/model/block_meta.d.ts.map +1 -1
- package/dist/v2/registry/schema_public.d.ts +466 -0
- package/dist/v2/registry/schema_public.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/io/folder_reader.ts +2 -0
- package/src/v2/registry/registry_reader.test.ts +19 -0
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var k=Object.defineProperty;var v=(o,t,a)=>t in o?k(o,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[t]=a;var n=(o,t,a)=>v(o,typeof t!="symbol"?t+"":t,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./config-BczgUC2N.js"),g=require("undici"),r=require("node:path"),l=require("node:path/posix"),P=require("node:fs/promises"),
|
|
1
|
+
"use strict";var k=Object.defineProperty;var v=(o,t,a)=>t in o?k(o,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[t]=a;var n=(o,t,a)=>v(o,typeof t!="symbol"?t+"":t,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./config-BczgUC2N.js"),g=require("undici"),r=require("node:path"),l=require("node:path/posix"),P=require("node:fs/promises"),f=require("@milaboratories/pl-model-middle-layer"),u=require("canonicalize");require("zod");require("mime-types");require("tar");require("@milaboratories/resolve-helper");class B{constructor(t){n(this,"metaCache",new Map);n(this,"v2RootFolderReader");this.registryReader=t,this.v2RootFolderReader=t.relativeReader(e.MainPrefix)}async embedMetaContent(t){const a=u(t.id),i=this.metaCache.get(a);if(i&&i.sha256===t.latestManifestSha256)return i.meta;const p=this.v2RootFolderReader.getContentReader(),d=await e.BlockPackMetaEmbedBytes(p).parseAsync(t.latest.meta);return this.metaCache.set(a,{sha256:t.latestManifestSha256,meta:d}),d}async listBlockPacks(){this.v2RootFolderReader.getContentReader();const t=e.GlobalOverviewReg.parse(JSON.parse(Buffer.from(await this.v2RootFolderReader.readFile(e.GlobalOverviewFileName)).toString()));return await Promise.all(t.packages.map(async a=>({id:a.latest.id,meta:await this.embedMetaContent(a),spec:{type:"from-registry-v2",id:a.latest.id,registryUrl:this.registryReader.rootUrl.toString()},otherVersions:a.allVersions})))}async getComponents(t){const a=this.v2RootFolderReader.relativeReader(e.packageContentPrefixInsideV2(t)),i=f.BlockPackManifest.parse(JSON.parse(Buffer.from(await a.readFile(e.ManifestFileName)).toString()));return e.BlockComponentsAbsoluteUrl(a.rootUrl.toString()).parse(i.description.components)}}const R=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 s{constructor(t,a){this.rootUrl=t,this.httpDispatcher=a}async readFile(t){const a=new URL(t,this.rootUrl),i=await g.request(a,{dispatcher:this.httpDispatcher});return Buffer.from(await i.body.arrayBuffer())}relativeReader(t){return t.endsWith("/")||(t=t+"/"),new s(new URL(t,this.rootUrl),this.httpDispatcher)}getContentReader(t){let a=this;return t!==void 0&&(a=a.relativeReader(t)),i=>a.readFile(i)}}class c{constructor(t,a){this.rootUrl=t,this.root=a}async readFile(t){const a=r.join(this.root,...t.split(l.sep));return await P.readFile(a)}relativeReader(t){return t.endsWith("/")||(t=t+"/"),new c(new URL(t,this.rootUrl),r.join(this.root,...t.split(l.sep)))}getContentReader(t){let a=this;return t!==void 0&&(a=a.relativeReader(t)),i=>a.readFile(i)}}function h(o){return o.split(l.sep).join(r.sep)}function m(o){return o.split(r.sep).join(l.sep)}function b(o,t){o.endsWith("/")||(o=o+"/");const a=new URL(o,`file:${m(r.resolve("."))}/`);switch(a.protocol){case"file:":const i=h(a.pathname);return new c(a,i);case"https:":case"http:":return new s(a,t??new g.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=R;exports.RegistryV2Reader=B;exports.folderReaderByUrl=b;
|
|
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 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 packageContentPrefix,\n packageContentPrefixInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport class RegistryV2Reader {\n private readonly metaCache = new Map<\n string,\n { sha256: string; meta: BlockPackMetaEmbeddedBytes }\n >();\n\n private readonly v2RootFolderReader: FolderReader;\n\n constructor(private readonly registryReader: FolderReader) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n }\n\n private async embedMetaContent(\n entry: GlobalOverviewEntryReg\n ): Promise<BlockPackMetaEmbeddedBytes> {\n const id = canonicalize(entry.id)!;\n const fromCache = this.metaCache.get(id);\n if (fromCache && fromCache.sha256 === entry.latestManifestSha256) return fromCache.meta;\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n const meta = await BlockPackMetaEmbedBytes(rootContentReader).parseAsync(entry.latest.meta);\n this.metaCache.set(id, { sha256: entry.latestManifestSha256, meta });\n return meta;\n }\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\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 return 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\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\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","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 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 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":["RegistryV2Reader","registryReader","__publicField","MainPrefix","entry","id","canonicalize","fromCache","rootContentReader","meta","BlockPackMetaEmbedBytes","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","p","packageFolderReader","packageContentPrefixInsideV2","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","posixToLocalPath","localToPosix","folderReaderByUrl","address","url","rootPath","Agent"],"mappings":"6iBAqBO,MAAMA,CAAiB,CAQ5B,YAA6BC,EAA8B,CAP1CC,EAAA,qBAAgB,KAKhBA,EAAA,2BAEY,KAAA,eAAAD,EACtB,KAAA,mBAAqBA,EAAe,eAAeE,EAAU,UAAA,CACpE,CAEA,MAAc,iBACZC,EACqC,CAC/B,MAAAC,EAAKC,EAAaF,EAAM,EAAE,EAC1BG,EAAY,KAAK,UAAU,IAAIF,CAAE,EACvC,GAAIE,GAAaA,EAAU,SAAWH,EAAM,4BAA6BG,EAAU,KAC7E,MAAAC,EAAoB,KAAK,mBAAmB,iBAAiB,EAC7DC,EAAO,MAAMC,E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+
{"version":3,"file":"index.js","sources":["../src/v2/registry/registry_reader.ts","../src/io/folder_reader.ts"],"sourcesContent":["import {\n BlockPackId,\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 packageContentPrefix,\n packageContentPrefixInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport class RegistryV2Reader {\n private readonly metaCache = new Map<\n string,\n { sha256: string; meta: BlockPackMetaEmbeddedBytes }\n >();\n\n private readonly v2RootFolderReader: FolderReader;\n\n constructor(private readonly registryReader: FolderReader) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n }\n\n private async embedMetaContent(\n entry: GlobalOverviewEntryReg\n ): Promise<BlockPackMetaEmbeddedBytes> {\n const id = canonicalize(entry.id)!;\n const fromCache = this.metaCache.get(id);\n if (fromCache && fromCache.sha256 === entry.latestManifestSha256) return fromCache.meta;\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n const meta = await BlockPackMetaEmbedBytes(rootContentReader).parseAsync(entry.latest.meta);\n this.metaCache.set(id, { sha256: entry.latestManifestSha256, meta });\n return meta;\n }\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\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 return 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\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\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","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":["RegistryV2Reader","registryReader","__publicField","MainPrefix","entry","id","canonicalize","fromCache","rootContentReader","meta","BlockPackMetaEmbedBytes","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","p","packageFolderReader","packageContentPrefixInsideV2","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","posixToLocalPath","localToPosix","folderReaderByUrl","address","url","rootPath","Agent"],"mappings":"6iBAqBO,MAAMA,CAAiB,CAQ5B,YAA6BC,EAA8B,CAP1CC,EAAA,qBAAgB,KAKhBA,EAAA,2BAEY,KAAA,eAAAD,EACtB,KAAA,mBAAqBA,EAAe,eAAeE,EAAU,UAAA,CACpE,CAEA,MAAc,iBACZC,EACqC,CAC/B,MAAAC,EAAKC,EAAaF,EAAM,EAAE,EAC1BG,EAAY,KAAK,UAAU,IAAIF,CAAE,EACvC,GAAIE,GAAaA,E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AAC,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,11 +1,11 @@
|
|
|
1
1
|
var d = Object.defineProperty;
|
|
2
2
|
var g = (t, e, a) => e in t ? d(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a;
|
|
3
3
|
var i = (t, e, a) => g(t, typeof e != "symbol" ? e + "" : e, a);
|
|
4
|
-
import { e as f, f as m, G as
|
|
5
|
-
import { Q as te, O as oe, W as
|
|
4
|
+
import { e as f, f as m, G as k, h, p as v, M as R, i as u, j as P, k as w, m as B, n as y, o as C, q as F, r as b, t as M, P as O, u as S, v as x, w as D } from "./config-BbxbO3Iw.mjs";
|
|
5
|
+
import { Q as te, O as oe, W as se, a7 as re, U as ie, V as le, L as ne, a as ce, B as pe, N as de, d as ge, F as fe, a6 as me, a4 as ke, a5 as he, a3 as ve, a9 as Re, a8 as ue, $ as Pe, a1 as we, Z as Be, a0 as ye, T as Ce, R as Fe, x as be, S as Me, A as Oe, C as Se, z as xe, c as De, D as Te, b as Ue, l as Ee, y as Ge, E as Ae, _ as Le, a2 as Ve, X as je, I as Ne, J as Je, K as ze, H as We, s as _e, Y as $e } from "./config-BbxbO3Iw.mjs";
|
|
6
6
|
import { Agent as T, request as U } from "undici";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import s from "node:path";
|
|
8
|
+
import r from "node:path/posix";
|
|
9
9
|
import E from "node:fs/promises";
|
|
10
10
|
import { BlockPackManifest as G } from "@milaboratories/pl-model-middle-layer";
|
|
11
11
|
import A from "canonicalize";
|
|
@@ -27,9 +27,9 @@ class Q {
|
|
|
27
27
|
}
|
|
28
28
|
async listBlockPacks() {
|
|
29
29
|
this.v2RootFolderReader.getContentReader();
|
|
30
|
-
const e =
|
|
30
|
+
const e = k.parse(
|
|
31
31
|
JSON.parse(
|
|
32
|
-
Buffer.from(await this.v2RootFolderReader.readFile(
|
|
32
|
+
Buffer.from(await this.v2RootFolderReader.readFile(h)).toString()
|
|
33
33
|
)
|
|
34
34
|
);
|
|
35
35
|
return await Promise.all(
|
|
@@ -49,18 +49,18 @@ class Q {
|
|
|
49
49
|
}
|
|
50
50
|
async getComponents(e) {
|
|
51
51
|
const a = this.v2RootFolderReader.relativeReader(
|
|
52
|
-
|
|
52
|
+
v(e)
|
|
53
53
|
), o = G.parse(
|
|
54
|
-
JSON.parse(Buffer.from(await a.readFile(
|
|
54
|
+
JSON.parse(Buffer.from(await a.readFile(R)).toString())
|
|
55
55
|
);
|
|
56
|
-
return
|
|
56
|
+
return u(a.rootUrl.toString()).parse(
|
|
57
57
|
o.description.components
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
const X = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
62
62
|
__proto__: null,
|
|
63
|
-
GlobalOverviewPath:
|
|
63
|
+
GlobalOverviewPath: P,
|
|
64
64
|
MetaFile: w,
|
|
65
65
|
PlPackageConfigData: B,
|
|
66
66
|
PlPackageJsonConfigFile: y,
|
|
@@ -84,7 +84,7 @@ class l {
|
|
|
84
84
|
return Buffer.from(await o.body.arrayBuffer());
|
|
85
85
|
}
|
|
86
86
|
relativeReader(e) {
|
|
87
|
-
return new l(new URL(e, this.rootUrl), this.httpDispatcher);
|
|
87
|
+
return e.endsWith("/") || (e = e + "/"), new l(new URL(e, this.rootUrl), this.httpDispatcher);
|
|
88
88
|
}
|
|
89
89
|
getContentReader(e) {
|
|
90
90
|
let a = this;
|
|
@@ -96,13 +96,13 @@ class n {
|
|
|
96
96
|
this.rootUrl = e, this.root = a;
|
|
97
97
|
}
|
|
98
98
|
async readFile(e) {
|
|
99
|
-
const a =
|
|
99
|
+
const a = s.join(this.root, ...e.split(r.sep));
|
|
100
100
|
return await E.readFile(a);
|
|
101
101
|
}
|
|
102
102
|
relativeReader(e) {
|
|
103
|
-
return new n(
|
|
103
|
+
return e.endsWith("/") || (e = e + "/"), new n(
|
|
104
104
|
new URL(e, this.rootUrl),
|
|
105
|
-
|
|
105
|
+
s.join(this.root, ...e.split(r.sep))
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
getContentReader(e) {
|
|
@@ -111,14 +111,14 @@ class n {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
function L(t) {
|
|
114
|
-
return t.split(
|
|
114
|
+
return t.split(r.sep).join(s.sep);
|
|
115
115
|
}
|
|
116
116
|
function V(t) {
|
|
117
|
-
return t.split(
|
|
117
|
+
return t.split(s.sep).join(r.sep);
|
|
118
118
|
}
|
|
119
119
|
function Z(t, e) {
|
|
120
120
|
t.endsWith("/") || (t = t + "/");
|
|
121
|
-
const a = new URL(t, `file:${V(
|
|
121
|
+
const a = new URL(t, `file:${V(s.resolve("."))}/`);
|
|
122
122
|
switch (a.protocol) {
|
|
123
123
|
case "file:":
|
|
124
124
|
const o = L(a.pathname);
|
|
@@ -131,11 +131,11 @@ function Z(t, e) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
export {
|
|
134
|
-
|
|
134
|
+
u as BlockComponentsAbsoluteUrl,
|
|
135
135
|
te as BlockComponentsConsolidate,
|
|
136
136
|
oe as BlockComponentsDescription,
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
se as BlockDescriptionPackageJsonField,
|
|
138
|
+
re as BlockDescriptionToExplicitBinaryBytes,
|
|
139
139
|
ie as BlockPackDescriptionConsolidateToFolder,
|
|
140
140
|
le as BlockPackDescriptionManifestAddRelativePathPrefix,
|
|
141
141
|
ne as BlockPackMetaConsolidate,
|
|
@@ -146,16 +146,16 @@ export {
|
|
|
146
146
|
ge as BlockRegistryV2,
|
|
147
147
|
fe as FSStorage,
|
|
148
148
|
me as GlobalOverview,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
ke as GlobalOverviewEntry,
|
|
150
|
+
he as GlobalOverviewEntryReg,
|
|
151
|
+
h as GlobalOverviewFileName,
|
|
152
|
+
ve as GlobalOverviewPath,
|
|
153
|
+
k as GlobalOverviewReg,
|
|
154
|
+
Re as GlobalOverviewToExplicitBinaryBase64,
|
|
155
|
+
ue as GlobalOverviewToExplicitBinaryBytes,
|
|
156
156
|
f as MainPrefix,
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
R as ManifestFileName,
|
|
158
|
+
Pe as ManifestSuffix,
|
|
159
159
|
we as PackageOverview,
|
|
160
160
|
Be as PackageOverviewFileName,
|
|
161
161
|
ye as PackageOverviewVersionEntry,
|
|
@@ -176,14 +176,14 @@ export {
|
|
|
176
176
|
Ge as mapLocalToAbsolute,
|
|
177
177
|
Ae as packFolderToRelativeTgz,
|
|
178
178
|
Le as packageContentPrefix,
|
|
179
|
-
|
|
179
|
+
v as packageContentPrefixInsideV2,
|
|
180
180
|
Ve as packageOverviewPath,
|
|
181
181
|
je as parsePackageName,
|
|
182
182
|
Ne as relativeToContentString,
|
|
183
183
|
Je as relativeToExplicitBinary64,
|
|
184
184
|
ze as relativeToExplicitBytes,
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
We as relativeToExplicitString,
|
|
186
|
+
_e as storageByUrl,
|
|
187
|
+
$e as tryLoadPackDescription
|
|
188
188
|
};
|
|
189
189
|
//# sourceMappingURL=index.mjs.map
|
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 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 packageContentPrefix,\n packageContentPrefixInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport class RegistryV2Reader {\n private readonly metaCache = new Map<\n string,\n { sha256: string; meta: BlockPackMetaEmbeddedBytes }\n >();\n\n private readonly v2RootFolderReader: FolderReader;\n\n constructor(private readonly registryReader: FolderReader) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n }\n\n private async embedMetaContent(\n entry: GlobalOverviewEntryReg\n ): Promise<BlockPackMetaEmbeddedBytes> {\n const id = canonicalize(entry.id)!;\n const fromCache = this.metaCache.get(id);\n if (fromCache && fromCache.sha256 === entry.latestManifestSha256) return fromCache.meta;\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n const meta = await BlockPackMetaEmbedBytes(rootContentReader).parseAsync(entry.latest.meta);\n this.metaCache.set(id, { sha256: entry.latestManifestSha256, meta });\n return meta;\n }\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\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 return 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\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\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","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 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 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":["RegistryV2Reader","registryReader","__publicField","MainPrefix","entry","id","canonicalize","fromCache","rootContentReader","meta","BlockPackMetaEmbedBytes","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","p","packageFolderReader","packageContentPrefixInsideV2","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","posixToLocalPath","localToPosix","folderReaderByUrl","address","url","rootPath","Agent"],"mappings":";;;;;;;;;;;;;;;AAqBO,MAAMA,EAAiB;AAAA,EAQ5B,YAA6BC,GAA8B;AAP1C,IAAAC,EAAA,uCAAgB;AAKhB,IAAAA,EAAA;AAEY,SAAA,iBAAAD,GACtB,KAAA,qBAAqBA,EAAe,eAAeE,CAAU;AAAA,EACpE;AAAA,EAEA,MAAc,iBACZC,GACqC;AAC/B,UAAAC,IAAKC,EAAaF,EAAM,EAAE,GAC1BG,IAAY,KAAK,UAAU,IAAIF,CAAE;AACvC,QAAIE,KAAaA,EAAU,WAAWH,EAAM,6BAA6BG,EAAU;AAC7E,UAAA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ACnD,UAAMC,IAAY,IAAI,IAAID,GAAM,KAAK,OAAO,GACtCE,IAAW,MAAMC,EAAQF,GAAW;AAAA,MACxC,YAAY,KAAK;AAAA,IAAA,CAClB;AACD,WAAO,OAAO,KAAK,MAAMC,EAAS,KAAK,aAAa;AAAA,EACtD;AAAA,EAEO,eAAeE,GAAwC;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/v2/registry/registry_reader.ts","../src/io/folder_reader.ts"],"sourcesContent":["import {\n BlockPackId,\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 packageContentPrefix,\n packageContentPrefixInsideV2\n} from './schema_public';\nimport { BlockComponentsAbsoluteUrl, BlockPackMetaEmbedBytes } from '../model';\n\nexport type BlockPackOverviewNoRegLabel = Omit<BlockPackOverview, 'registryId'>;\n\nexport class RegistryV2Reader {\n private readonly metaCache = new Map<\n string,\n { sha256: string; meta: BlockPackMetaEmbeddedBytes }\n >();\n\n private readonly v2RootFolderReader: FolderReader;\n\n constructor(private readonly registryReader: FolderReader) {\n this.v2RootFolderReader = registryReader.relativeReader(MainPrefix);\n }\n\n private async embedMetaContent(\n entry: GlobalOverviewEntryReg\n ): Promise<BlockPackMetaEmbeddedBytes> {\n const id = canonicalize(entry.id)!;\n const fromCache = this.metaCache.get(id);\n if (fromCache && fromCache.sha256 === entry.latestManifestSha256) return fromCache.meta;\n const rootContentReader = this.v2RootFolderReader.getContentReader();\n const meta = await BlockPackMetaEmbedBytes(rootContentReader).parseAsync(entry.latest.meta);\n this.metaCache.set(id, { sha256: entry.latestManifestSha256, meta });\n return meta;\n }\n\n public async listBlockPacks(): Promise<BlockPackOverviewNoRegLabel[]> {\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 return 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\n public async getComponents(id: BlockPackId): Promise<BlockComponentsAbsoluteUrl> {\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","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":["RegistryV2Reader","registryReader","__publicField","MainPrefix","entry","id","canonicalize","fromCache","rootContentReader","meta","BlockPackMetaEmbedBytes","globalOverview","GlobalOverviewReg","GlobalOverviewFileName","p","packageFolderReader","packageContentPrefixInsideV2","manifest","BlockPackManifest","ManifestFileName","BlockComponentsAbsoluteUrl","HttpFolderReader","rootUrl","httpDispatcher","file","targetUrl","response","request","relativePath","reader","path","FSFolderReader","root","targetPath","pathPosix","fsp","posixToLocalPath","localToPosix","folderReaderByUrl","address","url","rootPath","Agent"],"mappings":";;;;;;;;;;;;;;;AAqBO,MAAMA,EAAiB;AAAA,EAQ5B,YAA6BC,G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AAG,YAAY,CAAC;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,gBAAgB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAAC;CAChE;
|
|
1
|
+
{"version":3,"file":"folder_reader.d.ts","sourceRoot":"","sources":["../../src/io/folder_reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAW,MAAM,QAAQ,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAK9C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IACtB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,CAAC;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,gBAAgB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAAC;CAChE;AA8DD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,UAAU,GAAG,YAAY,CAa5F"}
|