@or-sdk/files-sync-node 0.0.6 → 0.0.7-beta.3996.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var z=Object.create;var m=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var A=(s,t)=>{for(var i in t)m(s,i,{get:t[i],enumerable:!0})},x=(s,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of M(t))!q.call(s,e)&&e!==i&&m(s,e,{get:()=>t[e],enumerable:!(o=O(t,e))||o.enumerable});return s};var j=(s,t,i)=>(i=s!=null?z(N(s)):{},x(t||!s||!s.__esModule?m(i,"default",{value:s,enumerable:!0}):i,s)),I=s=>x(m({},"__esModule",{value:!0}),s),k=(s,t,i,o)=>{for(var e=o>1?void 0:o?O(t,i):t,r=s.length-1,n;r>=0;r--)(n=s[r])&&(e=(o?n(t,i,e):n(e))||e);return o&&e&&m(t,i,e),e};var $={};A($,{FilesSyncNode:()=>u});module.exports=I($);var T=require("@or-sdk/files"),U=j(require("debug"),1),S=require("mime-types"),h=j(require("fs/promises"),1),a=require("path");var v=require("typescript-memoize");var f=class{async pLimit(){return await this.importDefault("p-limit")}async importDefault(t){return(await import(t)).default}};k([(0,v.Memoize)()],f.prototype,"importDefault",1);var P=new f;var d=(0,U.default)("files-sync"),u=class{filesClient;constructor({token:t,discoveryUrl:i,filesApiUrl:o,accountId:e}){this.filesClient=new T.Files({token:t,discoveryUrl:i,filesApiUrl:o,accountId:e})}async pushLocalPathToFiles(t,i,o={}){let e=await this.listLocalObjects(t);if(e.files.length){let r=Date.now();d("Found %d local files. Starting upload.",e.files.length),await this.uploadFiles({remotePathPrefix:i,localFiles:e.files},o),d("Finished uploading local files (%d ms)",Date.now()-r)}}async uploadFiles({localFiles:t,remotePathPrefix:i},o={}){let{concurrencyLimit:e=5,isPublic:r=!1,...n}=o,C=(await P.pLimit())(e),D=t.map(l=>C(async()=>{var b;let R=Date.now();d("Starting upload: %s",l.relative);let F=await h.default.open(l.full,"r"),w=await F.stat();try{let p=(0,a.basename)(l.relative),c=(0,a.join)(i??"",(0,a.dirname)(l.relative)),g={...n,name:p,type:(0,S.lookup)(p)||"application/octet-stream",maxFileSize:w.size,prefix:c==="."?"":`${c}/`,isPublic:r,fileModel:F.createReadStream({autoClose:!0}),knownLength:w.size};await this.filesClient.uploadFile(g),d("Finished upload: %s (%d ms)",l.relative,Date.now()-R)}catch(p){let c=p,g=((b=c.response)==null?void 0:b.data)??c.stack;throw d("Failed to upload: %s. Error: %j",l.relative,g),p}})),L=(await Promise.allSettled(D)).find(l=>l.status==="rejected");if(L)throw L.reason}async listLocalObjects(t){let{dirs:i,files:o}=await this.walkLocal(t);return{dirs:i.map(e=>({full:e,relative:(0,a.relative)(t,e)})),files:o.map(e=>({full:e,relative:(0,a.relative)(t,e)}))}}async walkLocal(t){let i=await h.default.readdir(t,{withFileTypes:!0}),o=[],e=[];for(let r of i){let n=(0,a.join)(t,r.name);if(r.isDirectory()){o.push((0,a.join)(t,r.name));let y=await this.walkLocal(n);e.push(...y.files),o.push(...y.dirs)}else r.isFile()&&e.push(n)}return{dirs:o,files:e}}};0&&(module.exports={FilesSyncNode});
1
+ "use strict";var U=Object.create;var m=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var V=(o,t)=>{for(var i in t)m(o,i,{get:t[i],enumerable:!0})},j=(o,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of M(t))!R.call(o,e)&&e!==i&&m(o,e,{get:()=>t[e],enumerable:!(s=k(t,e))||s.enumerable});return o};var x=(o,t,i)=>(i=o!=null?U(q(o)):{},j(t||!o||!o.__esModule?m(i,"default",{value:o,enumerable:!0}):i,o)),$=o=>j(m({},"__esModule",{value:!0}),o),O=(o,t,i,s)=>{for(var e=s>1?void 0:s?k(t,i):t,a=o.length-1,n;a>=0;a--)(n=o[a])&&(e=(s?n(t,i,e):n(e))||e);return s&&e&&m(t,i,e),e};var B={};V(B,{FilesSyncNode:()=>d});module.exports=$(B);var y=require("@or-sdk/files"),T=x(require("debug"),1),D=require("mime-types"),g=x(require("fs/promises"),1),r=require("path");var P=require("typescript-memoize");var f=class{async pLimit(){return await this.importDefault("p-limit")}async importDefault(t){return(await import(t)).default}};O([(0,P.Memoize)()],f.prototype,"importDefault",1);var C=new f;var u=(0,T.default)("files-sync"),d=class{filesClient;constructor({token:t,discoveryUrl:i,filesApiUrl:s,accountId:e}){let a={token:t,accountId:e};this.filesClient=s==null?new y.Files({...a,discoveryUrl:i}):new y.Files({...a,filesApiUrl:s})}async pushLocalPathToFiles(t,i,s={}){let e=await this.listLocalObjects(t);if(e.files.length){let a=Date.now();u("Found %d local files. Starting upload.",e.files.length),await this.uploadFiles({remotePathPrefix:i,localFiles:e.files},s),u("Finished uploading local files (%d ms)",Date.now()-a)}}async uploadFiles({localFiles:t,remotePathPrefix:i},s={}){let{concurrencyLimit:e=5,isPublic:a=!1,...n}=s,S=(await C.pLimit())(e),z=t.map(l=>S(async()=>{var b;let N=Date.now();u("Starting upload: %s",l.relative);let F=await g.default.open(l.full,"r"),v=await F.stat();try{let p=(0,r.basename)(l.relative),c=(0,r.join)(i??"",(0,r.dirname)(l.relative)),h={...n,fileName:p,prefix:c==="."?"":`${c}/`,fileContent:F.createReadStream({autoClose:!0}),contentType:(0,D.lookup)(p)||"application/octet-stream",maxFileSize:v.size,knownLength:v.size,isPublic:a};await this.filesClient.uploadFileV2(h),u("Finished upload: %s (%d ms)",l.relative,Date.now()-N)}catch(p){let c=p,h=((b=c.response)==null?void 0:b.data)??c.stack;throw u("Failed to upload: %s. Error: %j",l.relative,h),p}})),L=(await Promise.allSettled(z)).find(l=>l.status==="rejected");if(L)throw L.reason}async listLocalObjects(t){let{dirs:i,files:s}=await this.walkLocal(t);return{dirs:i.map(e=>({full:e,relative:(0,r.relative)(t,e)})),files:s.map(e=>({full:e,relative:(0,r.relative)(t,e)}))}}async walkLocal(t){let i=await g.default.readdir(t,{withFileTypes:!0}),s=[],e=[];for(let a of i){let n=(0,r.join)(t,a.name);if(a.isDirectory()){s.push((0,r.join)(t,a.name));let w=await this.walkLocal(n);e.push(...w.files),s.push(...w.dirs)}else a.isFile()&&e.push(n)}return{dirs:s,files:e}}};0&&(module.exports={FilesSyncNode});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/FilesSyncNode.ts","../../src/esm-factory.ts"],"sourcesContent":["export { FilesSyncNode } from './FilesSyncNode.ts';\nexport * from './types.ts';\n","import { Files } from '@or-sdk/files';\nimport debug from 'debug';\nimport { lookup as mimeLookup } from 'mime-types';\nimport fs from 'node:fs/promises';\nimport { basename, dirname, join, relative } from 'node:path';\n\nimport { esmFactory } from './esm-factory.ts';\nimport type {\n FilesSyncNodeConfig,\n FileUploadOptions,\n LocalObjects,\n PushLocalPathToFilesOptions,\n UploadFilesParameters,\n} from './types.ts';\n\nconst log = debug('files-sync');\n\n/**\n * SDK for synchronizing local directory and directory in Onereach Files service.\n * This SDK is designed to be used with Node.js\n *\n * @example\n * Create client instance with service discovery URL\n *\n * ```typescript\n * const client = new FilesSyncNode({\n * token: process.env.OR_TOKEN,\n * discoveryUrl: process.env.OR_DISCOVERY_URL\n * });\n * ```\n *\n * @example\n * Create client instance with files service URL\n *\n * ```typescript\n * const client = new FilesSyncNode({\n * token: process.env.OR_TOKEN,\n * filesApiUrl: process.env.OR_FILES_API_URL\n * });\n * ```\n *\n * To see debug logs of synching define environment variable `DEBUG` with value `files-sync`:\n *\n * ```sh\n * DEBUG='files-sync' node ./run_logic.js\n * ```\n*/\nexport class FilesSyncNode {\n private readonly filesClient: Files;\n\n public constructor({\n token,\n discoveryUrl,\n filesApiUrl,\n accountId,\n }: FilesSyncNodeConfig) {\n this.filesClient = new Files({\n token,\n discoveryUrl,\n filesApiUrl,\n accountId,\n });\n }\n\n /**\n * Push local directory to Files service.\n * - All local files would be remote directory;\n * - Extra files in remote directory will remain;\n * - If remote file has the same name as local file, it would be replaced.\n * - Any required remote subdirectories would be created automatically.\n *\n * @param localPath local directory path\n * @param remotePathPrefix path in Files service where to push files. If not set would be synched into root directory.\n * @param options upload params\n * @param options.ttl Timestamp in ms when file should expire\n * @param options.isPublic if `true` uploaded files would be publicly available\n * (access without authentication). Default `false`.\n * @param options.concurrencyLimit how many files can be uploaded at the same time. Default `5`.\n *\n * @example\n * Push local directory `./my-data` (path relative to current working directory of the process)\n * into remote directory `sync-local`\n * ```typescript\n * await client.pushLocalPathToFiles('./my-data', 'sync-local')\n * ```\n */\n public async pushLocalPathToFiles(\n localPath: string,\n remotePathPrefix?: string,\n options: PushLocalPathToFilesOptions = {},\n ) {\n const localObjects = await this.listLocalObjects(localPath);\n\n if (localObjects.files.length) {\n const start = Date.now();\n log('Found %d local files. Starting upload.', localObjects.files.length);\n await this.uploadFiles({\n remotePathPrefix,\n localFiles: localObjects.files,\n }, options);\n log('Finished uploading local files (%d ms)', Date.now() - start);\n }\n }\n\n // private getDiff(localObjects: LocalObjects, remoteObjects: RemoteObjects) {\n // const uploadLocalFiles = localObjects.files.filter(localFile => {\n // return !remoteObjects.files.some(file => file.relative === localFile.relative);\n // });\n\n // const deleteRemoteFiles = remoteObjects.files.filter(remoteFile => {\n // return !localObjects.files.some(file => file.relative === remoteFile.relative);\n // });\n\n // const createRemoteDirs = localObjects.dirs.filter(localDir => {\n // return !remoteObjects.dirs.some(dir => dir.relative === localDir.relative);\n // })\n // const deleteRemoteDirs = remoteObjects.dirs.filter(remoteDir => {\n // return !localObjects.dirs.some(dir => dir.relative === remoteDir.relative);\n // })\n\n // return { uploadLocalFiles, deleteRemoteFiles, createRemoteDirs, deleteRemoteDirs };\n // }\n\n // private async listRemoteObjects(remotePathPrefix?: string): Promise<RemoteObjects> {\n // const result: RemoteObjects = { files: [], dirs: [] }\n // const objects = await this.filesClient.getItemsList(remotePathPrefix ?? '');\n\n // for (const object of objects) {\n // // TODO: test if it works with objects in root without prefix\n // const relativePath = relative(object.parentFolder, object.key)\n // if (object.key.endsWith('/')) result.dirs.push({ relative: relativePath, key: object.key })\n // else result.files.push({ relative: relativePath, key: object.key })\n // }\n\n // return result;\n // }\n\n private async uploadFiles(\n { localFiles, remotePathPrefix }: UploadFilesParameters,\n uploadOptions: FileUploadOptions = {},\n ) {\n const { concurrencyLimit = 5, isPublic = false, ...options } = uploadOptions;\n\n const pLimit = await esmFactory.pLimit();\n const limit = pLimit(concurrencyLimit);\n const uploadTasks = localFiles.map(localFile => limit(async () => {\n const start = Date.now();\n log('Starting upload: %s', localFile.relative);\n\n const handle = await fs.open(localFile.full, 'r');\n const stats = await handle.stat();\n try {\n const name = basename(localFile.relative);\n const prefix = join(remotePathPrefix ?? '', dirname(localFile.relative));\n const request = {\n ...options,\n name,\n type: mimeLookup(name) || 'application/octet-stream',\n maxFileSize: stats.size,\n prefix: prefix === '.' ? '' : `${prefix}/`,\n isPublic,\n fileModel: handle.createReadStream({ autoClose: true }),\n knownLength: stats.size,\n };\n\n await this.filesClient.uploadFile(request);\n log('Finished upload: %s (%d ms)', localFile.relative, Date.now() - start);\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const err: any = error;\n const errorMessage = err.response?.data ?? err.stack;\n log('Failed to upload: %s. Error: %j', localFile.relative, errorMessage);\n throw error;\n }\n }));\n\n const result = await Promise.allSettled(uploadTasks);\n const rejected = result.find(item => item.status === 'rejected');\n\n if (rejected) throw rejected.reason;\n }\n\n private async listLocalObjects(localPath: string): Promise<LocalObjects> {\n const { dirs, files } = await this.walkLocal(localPath);\n\n return {\n dirs: dirs.map(full => ({\n full,\n relative: relative(localPath, full),\n })),\n files: files.map(full => ({\n full,\n relative: relative(localPath, full),\n })),\n };\n }\n\n /**\n * Recursively collect all file paths under a directory.\n */\n private async walkLocal(localPath: string) {\n const entries = await fs.readdir(localPath, { withFileTypes: true });\n const dirs: string[] = [];\n const files: string[] = [];\n\n for (const entry of entries) {\n const fullPath = join(localPath, entry.name);\n if (entry.isDirectory()) {\n dirs.push(join(localPath, entry.name));\n const child = await this.walkLocal(fullPath);\n files.push(...child.files);\n dirs.push(...child.dirs);\n } else if (entry.isFile()) {\n files.push(fullPath);\n // } else {\n // files.push(fullPath);\n }\n }\n return {\n dirs,\n files,\n };\n }\n}\n","import type { LimitFunction } from 'p-limit';\nimport { Memoize } from 'typescript-memoize';\n\nexport class EsmFactory {\n public async pLimit(): Promise<pLimit> {\n return await this.importDefault('p-limit');\n }\n\n @Memoize()\n private async importDefault<T>(esmPackage: string): Promise<T> {\n const pkg = await import(esmPackage);\n return pkg.default;\n }\n}\n\nexport const esmFactory = new EsmFactory();\n\nexport type pLimit = (concurrency: number) => LimitFunction;\n"],"mappings":"4rBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAsB,yBACtBC,EAAkB,sBAClBC,EAAqC,sBACrCC,EAAe,4BACfC,EAAkD,gBCHlD,IAAAC,EAAwB,8BAEjB,IAAMC,EAAN,KAAiB,CACtB,MAAa,QAA0B,CACrC,OAAO,MAAM,KAAK,cAAc,SAAS,CAC3C,CAGA,MAAc,cAAiBC,EAAgC,CAE7D,OADY,MAAM,OAAOA,IACd,OACb,CACF,EAJgBC,EAAA,IADb,WAAQ,GALEF,EAMG,6BAMT,IAAMG,EAAa,IAAIH,EDA9B,IAAMI,KAAM,EAAAC,SAAM,YAAY,EAgCjBC,EAAN,KAAoB,CACR,YAEV,YAAY,CACjB,MAAAC,EACA,aAAAC,EACA,YAAAC,EACA,UAAAC,CACF,EAAwB,CACtB,KAAK,YAAc,IAAI,QAAM,CAC3B,MAAAH,EACA,aAAAC,EACA,YAAAC,EACA,UAAAC,CACF,CAAC,CACH,CAwBA,MAAa,qBAC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IAAMC,EAAWD,EACXE,IAAeV,EAAAS,EAAI,WAAJ,YAAAT,EAAc,OAAQS,EAAI,MAC/C,MAAA7B,EAAI,kCAAmCmB,EAAU,SAAUW,CAAY,EACjEF,CACR,CACF,CAAC,CAAC,EAGIG,GADS,MAAM,QAAQ,WAAWb,CAAW,GAC3B,KAAKc,GAAQA,EAAK,SAAW,UAAU,EAE/D,GAAID,EAAU,MAAMA,EAAS,MAC/B,CAEA,MAAc,iBAAiBxB,EAA0C,CACvE,GAAM,CAAE,KAAA0B,EAAM,MAAAC,CAAM,EAAI,MAAM,KAAK,UAAU3B,CAAS,EAEtD,MAAO,CACL,KAAM0B,EAAK,IAAIE,IAAS,CACtB,KAAAA,EACA,YAAU,YAAS5B,EAAW4B,CAAI,CACpC,EAAE,EACF,MAAOD,EAAM,IAAIC,IAAS,CACxB,KAAAA,EACA,YAAU,YAAS5B,EAAW4B,CAAI,CACpC,EAAE,CACJ,CACF,CAKA,MAAc,UAAU5B,EAAmB,CACzC,IAAM6B,EAAU,MAAM,EAAAd,QAAG,QAAQf,EAAW,CAAE,cAAe,EAAK,CAAC,EAC7D0B,EAAiB,CAAC,EAClBC,EAAkB,CAAC,EAEzB,QAAWG,KAASD,EAAS,CAC3B,IAAME,KAAW,QAAK/B,EAAW8B,EAAM,IAAI,EAC3C,GAAIA,EAAM,YAAY,EAAG,CACvBJ,EAAK,QAAK,QAAK1B,EAAW8B,EAAM,IAAI,CAAC,EACrC,IAAME,EAAQ,MAAM,KAAK,UAAUD,CAAQ,EAC3CJ,EAAM,KAAK,GAAGK,EAAM,KAAK,EACzBN,EAAK,KAAK,GAAGM,EAAM,IAAI,CACzB,MAAWF,EAAM,OAAO,GACtBH,EAAM,KAAKI,CAAQ,CAIvB,CACA,MAAO,CACL,KAAAL,EACA,MAAAC,CACF,CACF,CACF","names":["index_exports","__export","FilesSyncNode","__toCommonJS","import_files","import_debug","import_mime_types","import_promises","import_node_path","import_typescript_memoize","EsmFactory","esmPackage","__decorateClass","esmFactory","log","debug","FilesSyncNode","token","discoveryUrl","filesApiUrl","accountId","localPath","remotePathPrefix","options","localObjects","start","localFiles","uploadOptions","concurrencyLimit","isPublic","limit","esmFactory","uploadTasks","localFile","_a","handle","fs","stats","name","prefix","request","mimeLookup","error","err","errorMessage","rejected","item","dirs","files","full","entries","entry","fullPath","child"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/FilesSyncNode.ts","../../src/esm-factory.ts"],"sourcesContent":["export { FilesSyncNode } from './FilesSyncNode.ts';\nexport * from './types.ts';\n","import { Files } from '@or-sdk/files';\nimport debug from 'debug';\nimport { lookup as mimeLookup } from 'mime-types';\nimport fs from 'node:fs/promises';\nimport { basename, dirname, join, relative } from 'node:path';\n\nimport { esmFactory } from './esm-factory.ts';\nimport type {\n FilesSyncNodeConfig,\n FileUploadOptions,\n LocalObjects,\n PushLocalPathToFilesOptions,\n UploadFilesParameters,\n} from './types.ts';\n\nconst log = debug('files-sync');\n\n/**\n * SDK for synchronizing local directory and directory in Onereach Files service.\n * This SDK is designed to be used with Node.js\n *\n * @example\n * Create client instance with service discovery URL\n *\n * ```typescript\n * const client = new FilesSyncNode({\n * token: process.env.OR_TOKEN,\n * discoveryUrl: process.env.OR_DISCOVERY_URL\n * });\n * ```\n *\n * @example\n * Create client instance with files service URL\n *\n * ```typescript\n * const client = new FilesSyncNode({\n * token: process.env.OR_TOKEN,\n * filesApiUrl: process.env.OR_FILES_API_URL\n * });\n * ```\n *\n * To see debug logs of synching define environment variable `DEBUG` with value `files-sync`:\n *\n * ```sh\n * DEBUG='files-sync' node ./run_logic.js\n * ```\n*/\nexport class FilesSyncNode {\n private readonly filesClient: Files;\n\n public constructor({\n token,\n discoveryUrl,\n filesApiUrl,\n accountId,\n }: FilesSyncNodeConfig) {\n const filesConfig = {\n token,\n accountId,\n };\n this.filesClient = filesApiUrl == undefined\n ? new Files({\n ...filesConfig,\n discoveryUrl,\n })\n : new Files({\n ...filesConfig,\n filesApiUrl,\n });\n }\n\n /**\n * Push local directory to Files service.\n * - All local files would be remote directory;\n * - Extra files in remote directory will remain;\n * - If remote file has the same name as local file, it would be replaced.\n * - Any required remote subdirectories would be created automatically.\n *\n * @param localPath local directory path\n * @param remotePathPrefix path in Files service where to push files. If not set would be synched into root directory.\n * @param options upload params\n * @param options.ttl Timestamp in ms when file should expire\n * @param options.isPublic if `true` uploaded files would be publicly available\n * (access without authentication). Default `false`.\n * @param options.concurrencyLimit how many files can be uploaded at the same time. Default `5`.\n *\n * @example\n * Push local directory `./my-data` (path relative to current working directory of the process)\n * into remote directory `sync-local`\n * ```typescript\n * await client.pushLocalPathToFiles('./my-data', 'sync-local')\n * ```\n */\n public async pushLocalPathToFiles(\n localPath: string,\n remotePathPrefix?: string,\n options: PushLocalPathToFilesOptions = {},\n ) {\n const localObjects = await this.listLocalObjects(localPath);\n\n if (localObjects.files.length) {\n const start = Date.now();\n log('Found %d local files. Starting upload.', localObjects.files.length);\n await this.uploadFiles({\n remotePathPrefix,\n localFiles: localObjects.files,\n }, options);\n log('Finished uploading local files (%d ms)', Date.now() - start);\n }\n }\n\n // private getDiff(localObjects: LocalObjects, remoteObjects: RemoteObjects) {\n // const uploadLocalFiles = localObjects.files.filter(localFile => {\n // return !remoteObjects.files.some(file => file.relative === localFile.relative);\n // });\n\n // const deleteRemoteFiles = remoteObjects.files.filter(remoteFile => {\n // return !localObjects.files.some(file => file.relative === remoteFile.relative);\n // });\n\n // const createRemoteDirs = localObjects.dirs.filter(localDir => {\n // return !remoteObjects.dirs.some(dir => dir.relative === localDir.relative);\n // })\n // const deleteRemoteDirs = remoteObjects.dirs.filter(remoteDir => {\n // return !localObjects.dirs.some(dir => dir.relative === remoteDir.relative);\n // })\n\n // return { uploadLocalFiles, deleteRemoteFiles, createRemoteDirs, deleteRemoteDirs };\n // }\n\n // private async listRemoteObjects(remotePathPrefix?: string): Promise<RemoteObjects> {\n // const result: RemoteObjects = { files: [], dirs: [] }\n // const objects = await this.filesClient.getItemsList(remotePathPrefix ?? '');\n\n // for (const object of objects) {\n // // TODO: test if it works with objects in root without prefix\n // const relativePath = relative(object.parentFolder, object.key)\n // if (object.key.endsWith('/')) result.dirs.push({ relative: relativePath, key: object.key })\n // else result.files.push({ relative: relativePath, key: object.key })\n // }\n\n // return result;\n // }\n\n private async uploadFiles(\n { localFiles, remotePathPrefix }: UploadFilesParameters,\n uploadOptions: FileUploadOptions = {},\n ) {\n const { concurrencyLimit = 5, isPublic = false, ...options } = uploadOptions;\n\n const pLimit = await esmFactory.pLimit();\n const limit = pLimit(concurrencyLimit);\n const uploadTasks = localFiles.map(localFile => limit(async () => {\n const start = Date.now();\n log('Starting upload: %s', localFile.relative);\n\n const handle = await fs.open(localFile.full, 'r');\n const stats = await handle.stat();\n try {\n const name = basename(localFile.relative);\n const prefix = join(remotePathPrefix ?? '', dirname(localFile.relative));\n const request = {\n ...options,\n fileName: name,\n prefix: prefix === '.' ? '' : `${prefix}/`,\n fileContent: handle.createReadStream({ autoClose: true }),\n contentType: mimeLookup(name) || 'application/octet-stream',\n maxFileSize: stats.size,\n knownLength: stats.size,\n isPublic,\n };\n\n await this.filesClient.uploadFileV2(request);\n log('Finished upload: %s (%d ms)', localFile.relative, Date.now() - start);\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const err: any = error;\n const errorMessage = err.response?.data ?? err.stack;\n log('Failed to upload: %s. Error: %j', localFile.relative, errorMessage);\n throw error;\n }\n }));\n\n const result = await Promise.allSettled(uploadTasks);\n const rejected = result.find(item => item.status === 'rejected');\n\n if (rejected) throw rejected.reason;\n }\n\n private async listLocalObjects(localPath: string): Promise<LocalObjects> {\n const { dirs, files } = await this.walkLocal(localPath);\n\n return {\n dirs: dirs.map(full => ({\n full,\n relative: relative(localPath, full),\n })),\n files: files.map(full => ({\n full,\n relative: relative(localPath, full),\n })),\n };\n }\n\n /**\n * Recursively collect all file paths under a directory.\n */\n private async walkLocal(localPath: string) {\n const entries = await fs.readdir(localPath, { withFileTypes: true });\n const dirs: string[] = [];\n const files: string[] = [];\n\n for (const entry of entries) {\n const fullPath = join(localPath, entry.name);\n if (entry.isDirectory()) {\n dirs.push(join(localPath, entry.name));\n const child = await this.walkLocal(fullPath);\n files.push(...child.files);\n dirs.push(...child.dirs);\n } else if (entry.isFile()) {\n files.push(fullPath);\n // } else {\n // files.push(fullPath);\n }\n }\n return {\n dirs,\n files,\n };\n }\n}\n","import type { LimitFunction } from 'p-limit';\nimport { Memoize } from 'typescript-memoize';\n\nexport class EsmFactory {\n public async pLimit(): Promise<pLimit> {\n return await this.importDefault('p-limit');\n }\n\n @Memoize()\n private async importDefault<T>(esmPackage: string): Promise<T> {\n const pkg = await import(esmPackage);\n return pkg.default;\n }\n}\n\nexport const esmFactory = new EsmFactory();\n\nexport type pLimit = (concurrency: number) => LimitFunction;\n"],"mappings":"4rBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAsB,yBACtBC,EAAkB,sBAClBC,EAAqC,sBACrCC,EAAe,4BACfC,EAAkD,gBCHlD,IAAAC,EAAwB,8BAEjB,IAAMC,EAAN,KAAiB,CACtB,MAAa,QAA0B,CACrC,OAAO,MAAM,KAAK,cAAc,SAAS,CAC3C,CAGA,MAAc,cAAiBC,EAAgC,CAE7D,OADY,MAAM,OAAOA,IACd,OACb,CACF,EAJgBC,EAAA,IADb,WAAQ,GALEF,EAMG,6BAMT,IAAMG,EAAa,IAAIH,EDA9B,IAAMI,KAAM,EAAAC,SAAM,YAAY,EAgCjBC,EAAN,KAAoB,CACR,YAEV,YAAY,CACjB,MAAAC,EACA,aAAAC,EACA,YAAAC,EACA,UAAAC,CACF,EAAwB,CACtB,IAAMC,EAAc,CAClB,MAAAJ,EACA,UAAAG,CACF,EACA,KAAK,YAAcD,GAAe,KAC9B,IAAI,QAAM,CACV,GAAGE,EACH,aAAAH,CACF,CAAC,EACC,IAAI,QAAM,CACV,GAAGG,EACH,YAAAF,CACF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CAAK,CAC3E,OAASiB,EAAO,CAEd,IAAMC,EAAWD,EACXE,IAAeV,EAAAS,EAAI,WAAJ,YAAAT,EAAc,OAAQS,EAAI,MAC/C,MAAA9B,EAAI,kCAAmCoB,EAAU,SAAUW,CAAY,EACjEF,CACR,CACF,CAAC,CAAC,EAGIG,GADS,MAAM,QAAQ,WAAWb,CAAW,GAC3B,KAAKc,GAAQA,EAAK,SAAW,UAAU,EAE/D,GAAID,EAAU,MAAMA,EAAS,MAC/B,CAEA,MAAc,iBAAiBxB,EAA0C,CACvE,GAAM,CAAE,KAAA0B,EAAM,MAAAC,CAAM,EAAI,MAAM,KAAK,UAAU3B,CAAS,EAEtD,MAAO,CACL,KAAM0B,EAAK,IAAIE,IAAS,CACtB,KAAAA,EACA,YAAU,YAAS5B,EAAW4B,CAAI,CACpC,EAAE,EACF,MAAOD,EAAM,IAAIC,IAAS,CACxB,KAAAA,EACA,YAAU,YAAS5B,EAAW4B,CAAI,CACpC,EAAE,CACJ,CACF,CAKA,MAAc,UAAU5B,EAAmB,CACzC,IAAM6B,EAAU,MAAM,EAAAd,QAAG,QAAQf,EAAW,CAAE,cAAe,EAAK,CAAC,EAC7D0B,EAAiB,CAAC,EAClBC,EAAkB,CAAC,EAEzB,QAAWG,KAASD,EAAS,CAC3B,IAAME,KAAW,QAAK/B,EAAW8B,EAAM,IAAI,EAC3C,GAAIA,EAAM,YAAY,EAAG,CACvBJ,EAAK,QAAK,QAAK1B,EAAW8B,EAAM,IAAI,CAAC,EACrC,IAAME,EAAQ,MAAM,KAAK,UAAUD,CAAQ,EAC3CJ,EAAM,KAAK,GAAGK,EAAM,KAAK,EACzBN,EAAK,KAAK,GAAGM,EAAM,IAAI,CACzB,MAAWF,EAAM,OAAO,GACtBH,EAAM,KAAKI,CAAQ,CAIvB,CACA,MAAO,CACL,KAAAL,EACA,MAAAC,CACF,CACF,CACF","names":["index_exports","__export","FilesSyncNode","__toCommonJS","import_files","import_debug","import_mime_types","import_promises","import_node_path","import_typescript_memoize","EsmFactory","esmPackage","__decorateClass","esmFactory","log","debug","FilesSyncNode","token","discoveryUrl","filesApiUrl","accountId","filesConfig","localPath","remotePathPrefix","options","localObjects","start","localFiles","uploadOptions","concurrencyLimit","isPublic","limit","esmFactory","uploadTasks","localFile","_a","handle","fs","stats","name","prefix","request","mimeLookup","error","err","errorMessage","rejected","item","dirs","files","full","entries","entry","fullPath","child"]}
@@ -2,16 +2,53 @@ import { Token } from '@or-sdk/base';
2
2
  export { Token } from '@or-sdk/base';
3
3
  import { UploadFileProps } from '@or-sdk/files';
4
4
 
5
- type FilesSyncNodeConfig = {
6
- /** OneReach authentication token or token factory */
5
+ type FilesSyncNodeConfigBase = {
6
+ /**
7
+ * token
8
+ */
7
9
  token: Token;
8
- /** URL of OneReach service discovery api */
9
- discoveryUrl?: string;
10
- /** Account ID for cross-account requests (super admin only) */
10
+ /**
11
+ * Account ID for cross-account requests (super admin only)
12
+ */
11
13
  accountId?: string;
12
- /** Files service URL, can be used to avoid discovery API call */
13
- filesApiUrl?: string;
14
14
  };
15
+ type FilesSyncNodeConfigWithDiscovery = FilesSyncNodeConfigBase & {
16
+ /**
17
+ * URL of OneReach service discovery API.
18
+ *
19
+ * Allows to fetch URLs of needed API's instead of defining them in the constructor.
20
+ *
21
+ * @example 'https://discovery.<env>.api.onereach.ai'
22
+ */
23
+ discoveryUrl: string;
24
+ /**
25
+ * Direct service url, can be used to avoid discovery api call
26
+ *
27
+ * Not needed if {@link FilesSyncNodeConfig.discoveryUrl} is defined.
28
+ *
29
+ * @example 'https://files-api.svc.<env>.api.onereach.ai'
30
+ */
31
+ filesApiUrl?: never;
32
+ };
33
+ type FilesSyncNodeConfigWithExplicitUrls = FilesSyncNodeConfigBase & {
34
+ /**
35
+ * Direct service url, can be used to avoid discovery api call
36
+ *
37
+ * Not needed if {@link FilesSyncNodeConfig.discoveryUrl} is defined.
38
+ *
39
+ * @example 'https://files-api.svc.<env>.api.onereach.ai'
40
+ */
41
+ filesApiUrl: string;
42
+ /**
43
+ * URL of OneReach service discovery API.
44
+ *
45
+ * Not needed if {@link FilesSyncNodeConfig.filesApiUrl} is defined.
46
+ *
47
+ * @example 'https://discovery.<env>.api.onereach.ai'
48
+ */
49
+ discoveryUrl?: never;
50
+ };
51
+ type FilesSyncNodeConfig = FilesSyncNodeConfigWithDiscovery | FilesSyncNodeConfigWithExplicitUrls;
15
52
  type LocalObject = {
16
53
  full: string;
17
54
  relative: string;
@@ -101,4 +138,4 @@ declare class FilesSyncNode {
101
138
  private walkLocal;
102
139
  }
103
140
 
104
- export { type FileUploadOptions, FilesSyncNode, type FilesSyncNodeConfig, type LocalObject, type LocalObjects, type PushLocalPathToFilesOptions, type RemoteObject, type RemoteObjects, type UploadFilesParameters };
141
+ export { type FileUploadOptions, FilesSyncNode, type FilesSyncNodeConfig, type FilesSyncNodeConfigBase, type FilesSyncNodeConfigWithDiscovery, type FilesSyncNodeConfigWithExplicitUrls, type LocalObject, type LocalObjects, type PushLocalPathToFilesOptions, type RemoteObject, type RemoteObjects, type UploadFilesParameters };
@@ -2,16 +2,53 @@ import { Token } from '@or-sdk/base';
2
2
  export { Token } from '@or-sdk/base';
3
3
  import { UploadFileProps } from '@or-sdk/files';
4
4
 
5
- type FilesSyncNodeConfig = {
6
- /** OneReach authentication token or token factory */
5
+ type FilesSyncNodeConfigBase = {
6
+ /**
7
+ * token
8
+ */
7
9
  token: Token;
8
- /** URL of OneReach service discovery api */
9
- discoveryUrl?: string;
10
- /** Account ID for cross-account requests (super admin only) */
10
+ /**
11
+ * Account ID for cross-account requests (super admin only)
12
+ */
11
13
  accountId?: string;
12
- /** Files service URL, can be used to avoid discovery API call */
13
- filesApiUrl?: string;
14
14
  };
15
+ type FilesSyncNodeConfigWithDiscovery = FilesSyncNodeConfigBase & {
16
+ /**
17
+ * URL of OneReach service discovery API.
18
+ *
19
+ * Allows to fetch URLs of needed API's instead of defining them in the constructor.
20
+ *
21
+ * @example 'https://discovery.<env>.api.onereach.ai'
22
+ */
23
+ discoveryUrl: string;
24
+ /**
25
+ * Direct service url, can be used to avoid discovery api call
26
+ *
27
+ * Not needed if {@link FilesSyncNodeConfig.discoveryUrl} is defined.
28
+ *
29
+ * @example 'https://files-api.svc.<env>.api.onereach.ai'
30
+ */
31
+ filesApiUrl?: never;
32
+ };
33
+ type FilesSyncNodeConfigWithExplicitUrls = FilesSyncNodeConfigBase & {
34
+ /**
35
+ * Direct service url, can be used to avoid discovery api call
36
+ *
37
+ * Not needed if {@link FilesSyncNodeConfig.discoveryUrl} is defined.
38
+ *
39
+ * @example 'https://files-api.svc.<env>.api.onereach.ai'
40
+ */
41
+ filesApiUrl: string;
42
+ /**
43
+ * URL of OneReach service discovery API.
44
+ *
45
+ * Not needed if {@link FilesSyncNodeConfig.filesApiUrl} is defined.
46
+ *
47
+ * @example 'https://discovery.<env>.api.onereach.ai'
48
+ */
49
+ discoveryUrl?: never;
50
+ };
51
+ type FilesSyncNodeConfig = FilesSyncNodeConfigWithDiscovery | FilesSyncNodeConfigWithExplicitUrls;
15
52
  type LocalObject = {
16
53
  full: string;
17
54
  relative: string;
@@ -101,4 +138,4 @@ declare class FilesSyncNode {
101
138
  private walkLocal;
102
139
  }
103
140
 
104
- export { type FileUploadOptions, FilesSyncNode, type FilesSyncNodeConfig, type LocalObject, type LocalObjects, type PushLocalPathToFilesOptions, type RemoteObject, type RemoteObjects, type UploadFilesParameters };
141
+ export { type FileUploadOptions, FilesSyncNode, type FilesSyncNodeConfig, type FilesSyncNodeConfigBase, type FilesSyncNodeConfigWithDiscovery, type FilesSyncNodeConfigWithExplicitUrls, type LocalObject, type LocalObjects, type PushLocalPathToFilesOptions, type RemoteObject, type RemoteObjects, type UploadFilesParameters };
@@ -1,2 +1,2 @@
1
- var v=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var F=(c,e,s,i)=>{for(var t=i>1?void 0:i?P(e,s):e,o=c.length-1,r;o>=0;o--)(r=c[o])&&(t=(i?r(e,s,t):r(t))||t);return i&&t&&v(e,s,t),t};import{Files as U}from"@or-sdk/files";import S from"debug";import{lookup as C}from"mime-types";import b from"fs/promises";import{basename as D,dirname as R,join as u,relative as O}from"path";import{Memoize as T}from"typescript-memoize";var m=class{async pLimit(){return await this.importDefault("p-limit")}async importDefault(e){return(await import(e)).default}};F([T()],m.prototype,"importDefault",1);var w=new m;var p=S("files-sync"),y=class{filesClient;constructor({token:e,discoveryUrl:s,filesApiUrl:i,accountId:t}){this.filesClient=new U({token:e,discoveryUrl:s,filesApiUrl:i,accountId:t})}async pushLocalPathToFiles(e,s,i={}){let t=await this.listLocalObjects(e);if(t.files.length){let o=Date.now();p("Found %d local files. Starting upload.",t.files.length),await this.uploadFiles({remotePathPrefix:s,localFiles:t.files},i),p("Finished uploading local files (%d ms)",Date.now()-o)}}async uploadFiles({localFiles:e,remotePathPrefix:s},i={}){let{concurrencyLimit:t=5,isPublic:o=!1,...r}=i,x=(await w.pLimit())(t),j=e.map(a=>x(async()=>{let k=Date.now();p("Starting upload: %s",a.relative);let h=await b.open(a.full,"r"),L=await h.stat();try{let n=D(a.relative),l=u(s??"",R(a.relative)),f={...r,name:n,type:C(n)||"application/octet-stream",maxFileSize:L.size,prefix:l==="."?"":`${l}/`,isPublic:o,fileModel:h.createReadStream({autoClose:!0}),knownLength:L.size};await this.filesClient.uploadFile(f),p("Finished upload: %s (%d ms)",a.relative,Date.now()-k)}catch(n){let l=n,f=l.response?.data??l.stack;throw p("Failed to upload: %s. Error: %j",a.relative,f),n}})),g=(await Promise.allSettled(j)).find(a=>a.status==="rejected");if(g)throw g.reason}async listLocalObjects(e){let{dirs:s,files:i}=await this.walkLocal(e);return{dirs:s.map(t=>({full:t,relative:O(e,t)})),files:i.map(t=>({full:t,relative:O(e,t)}))}}async walkLocal(e){let s=await b.readdir(e,{withFileTypes:!0}),i=[],t=[];for(let o of s){let r=u(e,o.name);if(o.isDirectory()){i.push(u(e,o.name));let d=await this.walkLocal(r);t.push(...d.files),i.push(...d.dirs)}else o.isFile()&&t.push(r)}return{dirs:i,files:t}}};export{y as FilesSyncNode};
1
+ var P=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var L=(c,e,o,i)=>{for(var t=i>1?void 0:i?C(e,o):e,s=c.length-1,a;s>=0;s--)(a=c[s])&&(t=(i?a(e,o,t):a(t))||t);return i&&t&&P(e,o,t),t};import{Files as v}from"@or-sdk/files";import D from"debug";import{lookup as S}from"mime-types";import b from"fs/promises";import{basename as z,dirname as N,join as d,relative as k}from"path";import{Memoize as T}from"typescript-memoize";var m=class{async pLimit(){return await this.importDefault("p-limit")}async importDefault(e){return(await import(e)).default}};L([T()],m.prototype,"importDefault",1);var F=new m;var p=D("files-sync"),w=class{filesClient;constructor({token:e,discoveryUrl:o,filesApiUrl:i,accountId:t}){let s={token:e,accountId:t};this.filesClient=i==null?new v({...s,discoveryUrl:o}):new v({...s,filesApiUrl:i})}async pushLocalPathToFiles(e,o,i={}){let t=await this.listLocalObjects(e);if(t.files.length){let s=Date.now();p("Found %d local files. Starting upload.",t.files.length),await this.uploadFiles({remotePathPrefix:o,localFiles:t.files},i),p("Finished uploading local files (%d ms)",Date.now()-s)}}async uploadFiles({localFiles:e,remotePathPrefix:o},i={}){let{concurrencyLimit:t=5,isPublic:s=!1,...a}=i,j=(await F.pLimit())(t),x=e.map(r=>j(async()=>{let O=Date.now();p("Starting upload: %s",r.relative);let y=await b.open(r.full,"r"),g=await y.stat();try{let n=z(r.relative),l=d(o??"",N(r.relative)),f={...a,fileName:n,prefix:l==="."?"":`${l}/`,fileContent:y.createReadStream({autoClose:!0}),contentType:S(n)||"application/octet-stream",maxFileSize:g.size,knownLength:g.size,isPublic:s};await this.filesClient.uploadFileV2(f),p("Finished upload: %s (%d ms)",r.relative,Date.now()-O)}catch(n){let l=n,f=l.response?.data??l.stack;throw p("Failed to upload: %s. Error: %j",r.relative,f),n}})),h=(await Promise.allSettled(x)).find(r=>r.status==="rejected");if(h)throw h.reason}async listLocalObjects(e){let{dirs:o,files:i}=await this.walkLocal(e);return{dirs:o.map(t=>({full:t,relative:k(e,t)})),files:i.map(t=>({full:t,relative:k(e,t)}))}}async walkLocal(e){let o=await b.readdir(e,{withFileTypes:!0}),i=[],t=[];for(let s of o){let a=d(e,s.name);if(s.isDirectory()){i.push(d(e,s.name));let u=await this.walkLocal(a);t.push(...u.files),i.push(...u.dirs)}else s.isFile()&&t.push(a)}return{dirs:i,files:t}}};export{w as FilesSyncNode};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/FilesSyncNode.ts","../../src/esm-factory.ts"],"sourcesContent":["import { Files } from '@or-sdk/files';\nimport debug from 'debug';\nimport { lookup as mimeLookup } from 'mime-types';\nimport fs from 'node:fs/promises';\nimport { basename, dirname, join, relative } from 'node:path';\n\nimport { esmFactory } from './esm-factory.ts';\nimport type {\n FilesSyncNodeConfig,\n FileUploadOptions,\n LocalObjects,\n PushLocalPathToFilesOptions,\n UploadFilesParameters,\n} from './types.ts';\n\nconst log = debug('files-sync');\n\n/**\n * SDK for synchronizing local directory and directory in Onereach Files service.\n * This SDK is designed to be used with Node.js\n *\n * @example\n * Create client instance with service discovery URL\n *\n * ```typescript\n * const client = new FilesSyncNode({\n * token: process.env.OR_TOKEN,\n * discoveryUrl: process.env.OR_DISCOVERY_URL\n * });\n * ```\n *\n * @example\n * Create client instance with files service URL\n *\n * ```typescript\n * const client = new FilesSyncNode({\n * token: process.env.OR_TOKEN,\n * filesApiUrl: process.env.OR_FILES_API_URL\n * });\n * ```\n *\n * To see debug logs of synching define environment variable `DEBUG` with value `files-sync`:\n *\n * ```sh\n * DEBUG='files-sync' node ./run_logic.js\n * ```\n*/\nexport class FilesSyncNode {\n private readonly filesClient: Files;\n\n public constructor({\n token,\n discoveryUrl,\n filesApiUrl,\n accountId,\n }: FilesSyncNodeConfig) {\n this.filesClient = new Files({\n token,\n discoveryUrl,\n filesApiUrl,\n accountId,\n });\n }\n\n /**\n * Push local directory to Files service.\n * - All local files would be remote directory;\n * - Extra files in remote directory will remain;\n * - If remote file has the same name as local file, it would be replaced.\n * - Any required remote subdirectories would be created automatically.\n *\n * @param localPath local directory path\n * @param remotePathPrefix path in Files service where to push files. If not set would be synched into root directory.\n * @param options upload params\n * @param options.ttl Timestamp in ms when file should expire\n * @param options.isPublic if `true` uploaded files would be publicly available\n * (access without authentication). Default `false`.\n * @param options.concurrencyLimit how many files can be uploaded at the same time. Default `5`.\n *\n * @example\n * Push local directory `./my-data` (path relative to current working directory of the process)\n * into remote directory `sync-local`\n * ```typescript\n * await client.pushLocalPathToFiles('./my-data', 'sync-local')\n * ```\n */\n public async pushLocalPathToFiles(\n localPath: string,\n remotePathPrefix?: string,\n options: PushLocalPathToFilesOptions = {},\n ) {\n const localObjects = await this.listLocalObjects(localPath);\n\n if (localObjects.files.length) {\n const start = Date.now();\n log('Found %d local files. Starting upload.', localObjects.files.length);\n await this.uploadFiles({\n remotePathPrefix,\n localFiles: localObjects.files,\n }, options);\n log('Finished uploading local files (%d ms)', Date.now() - start);\n }\n }\n\n // private getDiff(localObjects: LocalObjects, remoteObjects: RemoteObjects) {\n // const uploadLocalFiles = localObjects.files.filter(localFile => {\n // return !remoteObjects.files.some(file => file.relative === localFile.relative);\n // });\n\n // const deleteRemoteFiles = remoteObjects.files.filter(remoteFile => {\n // return !localObjects.files.some(file => file.relative === remoteFile.relative);\n // });\n\n // const createRemoteDirs = localObjects.dirs.filter(localDir => {\n // return !remoteObjects.dirs.some(dir => dir.relative === localDir.relative);\n // })\n // const deleteRemoteDirs = remoteObjects.dirs.filter(remoteDir => {\n // return !localObjects.dirs.some(dir => dir.relative === remoteDir.relative);\n // })\n\n // return { uploadLocalFiles, deleteRemoteFiles, createRemoteDirs, deleteRemoteDirs };\n // }\n\n // private async listRemoteObjects(remotePathPrefix?: string): Promise<RemoteObjects> {\n // const result: RemoteObjects = { files: [], dirs: [] }\n // const objects = await this.filesClient.getItemsList(remotePathPrefix ?? '');\n\n // for (const object of objects) {\n // // TODO: test if it works with objects in root without prefix\n // const relativePath = relative(object.parentFolder, object.key)\n // if (object.key.endsWith('/')) result.dirs.push({ relative: relativePath, key: object.key })\n // else result.files.push({ relative: relativePath, key: object.key })\n // }\n\n // return result;\n // }\n\n private async uploadFiles(\n { localFiles, remotePathPrefix }: UploadFilesParameters,\n uploadOptions: FileUploadOptions = {},\n ) {\n const { concurrencyLimit = 5, isPublic = false, ...options } = uploadOptions;\n\n const pLimit = await esmFactory.pLimit();\n const limit = pLimit(concurrencyLimit);\n const uploadTasks = localFiles.map(localFile => limit(async () => {\n const start = Date.now();\n log('Starting upload: %s', localFile.relative);\n\n const handle = await fs.open(localFile.full, 'r');\n const stats = await handle.stat();\n try {\n const name = basename(localFile.relative);\n const prefix = join(remotePathPrefix ?? '', dirname(localFile.relative));\n const request = {\n ...options,\n name,\n type: mimeLookup(name) || 'application/octet-stream',\n maxFileSize: stats.size,\n prefix: prefix === '.' ? '' : `${prefix}/`,\n isPublic,\n fileModel: handle.createReadStream({ autoClose: true }),\n knownLength: stats.size,\n };\n\n await this.filesClient.uploadFile(request);\n log('Finished upload: %s (%d ms)', localFile.relative, Date.now() - start);\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const err: any = error;\n const errorMessage = err.response?.data ?? err.stack;\n log('Failed to upload: %s. Error: %j', localFile.relative, errorMessage);\n throw error;\n }\n }));\n\n const result = await Promise.allSettled(uploadTasks);\n const rejected = result.find(item => item.status === 'rejected');\n\n if (rejected) throw rejected.reason;\n }\n\n private async listLocalObjects(localPath: string): Promise<LocalObjects> {\n const { dirs, files } = await this.walkLocal(localPath);\n\n return {\n dirs: dirs.map(full => ({\n full,\n relative: relative(localPath, full),\n })),\n files: files.map(full => ({\n full,\n relative: relative(localPath, full),\n })),\n };\n }\n\n /**\n * Recursively collect all file paths under a directory.\n */\n private async walkLocal(localPath: string) {\n const entries = await fs.readdir(localPath, { withFileTypes: true });\n const dirs: string[] = [];\n const files: string[] = [];\n\n for (const entry of entries) {\n const fullPath = join(localPath, entry.name);\n if (entry.isDirectory()) {\n dirs.push(join(localPath, entry.name));\n const child = await this.walkLocal(fullPath);\n files.push(...child.files);\n dirs.push(...child.dirs);\n } else if (entry.isFile()) {\n files.push(fullPath);\n // } else {\n // files.push(fullPath);\n }\n }\n return {\n dirs,\n files,\n };\n }\n}\n","import type { LimitFunction } from 'p-limit';\nimport { Memoize } from 'typescript-memoize';\n\nexport class EsmFactory {\n public async pLimit(): Promise<pLimit> {\n return await this.importDefault('p-limit');\n }\n\n @Memoize()\n private async importDefault<T>(esmPackage: string): Promise<T> {\n const pkg = await import(esmPackage);\n return pkg.default;\n }\n}\n\nexport const esmFactory = new EsmFactory();\n\nexport type pLimit = (concurrency: number) => LimitFunction;\n"],"mappings":"wMAAA,OAAS,SAAAA,MAAa,gBACtB,OAAOC,MAAW,QAClB,OAAS,UAAUC,MAAkB,aACrC,OAAOC,MAAQ,cACf,OAAS,YAAAC,EAAU,WAAAC,EAAS,QAAAC,EAAM,YAAAC,MAAgB,OCHlD,OAAS,WAAAC,MAAe,qBAEjB,IAAMC,EAAN,KAAiB,CACtB,MAAa,QAA0B,CACrC,OAAO,MAAM,KAAK,cAAc,SAAS,CAC3C,CAGA,MAAc,cAAiBC,EAAgC,CAE7D,OADY,MAAM,OAAOA,IACd,OACb,CACF,EAJgBC,EAAA,CADbC,EAAQ,GALEH,EAMG,6BAMT,IAAMI,EAAa,IAAIJ,EDA9B,IAAMK,EAAMC,EAAM,YAAY,EAgCjBC,EAAN,KAAoB,CACR,YAEV,YAAY,CACjB,MAAAC,EACA,aAAAC,EACA,YAAAC,EACA,UAAAC,CACF,EAAwB,CACtB,KAAK,YAAc,IAAIC,EAAM,CAC3B,MAAAJ,EACA,aAAAC,EACA,YAAAC,EACA,UAAAC,CACF,CAAC,CACH,CAwBA,MAAa,qBACXE,EACAC,EACAC,EAAuC,CAAC,EACxC,CACA,IAAMC,EAAe,MAAM,KAAK,iBAAiBH,CAAS,EAE1D,GA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,CACF,CAAC,CAAC,EAGIG,GADS,MAAM,QAAQ,WAAWf,CAAW,GAC3B,KAAKgB,GAAQA,EAAK,SAAW,UAAU,EAE/D,GAAID,EAAU,MAAMA,EAAS,MAC/B,CAEA,MAAc,iBAAiB1B,EAA0C,CACvE,GAAM,CAAE,KAAA4B,EAAM,MAAAC,CAAM,EAAI,MAAM,KAAK,UAAU7B,CAAS,EAEtD,MAAO,CACL,KAAM4B,EAAK,IAAIE,IAAS,CACtB,KAAAA,EACA,SAAUC,EAAS/B,EAAW8B,CAAI,CACpC,EAAE,EACF,MAAOD,EAAM,IAAIC,IAAS,CACxB,KAAAA,EACA,SAAUC,EAAS/B,EAAW8B,CAAI,CACpC,EAAE,CACJ,CACF,CAKA,MAAc,UAAU9B,EAAmB,CACzC,IAAMgC,EAAU,MAAMlB,EAAG,QAAQd,EAAW,CAAE,cAAe,EAAK,CAAC,EAC7D4B,EAAiB,CAAC,EAClBC,EAAkB,CAAC,EAEzB,QAAWI,KAASD,EAAS,CAC3B,IAAME,EAAWf,EAAKnB,EAAWiC,EAAM,IAAI,EAC3C,GAAIA,EAAM,YAAY,EAAG,CACvBL,EAAK,KAAKT,EAAKnB,EAAWiC,EAAM,IAAI,CAAC,EACrC,IAAME,EAAQ,MAAM,KAAK,UAAUD,CAAQ,EAC3CL,EAAM,KAAK,GAAGM,EAAM,KAAK,EACzBP,EAAK,KAAK,GAAGO,EAAM,IAAI,CACzB,MAAWF,EAAM,OAAO,GACtBJ,EAAM,KAAKK,CAAQ,CAIvB,CACA,MAAO,CACL,KAAAN,EACA,MAAAC,CACF,CACF,CACF","names":["Files","debug","mimeLookup","fs","basename","dirname","join","relative","Memoize","EsmFactory","esmPackage","__decorateClass","Memoize","esmFactory","log","debug","FilesSyncNode","token","discoveryUrl","filesApiUrl","accountId","Files","localPath","remotePathPrefix","options","localObjects","start","localFiles","uploadOptions","concurrencyLimit","isPublic","limit","esmFactory","uploadTasks","localFile","handle","fs","stats","name","basename","prefix","join","dirname","request","mimeLookup","error","err","errorMessage","rejected","item","dirs","files","full","relative","entries","entry","fullPath","child"]}
1
+ {"version":3,"sources":["../../src/FilesSyncNode.ts","../../src/esm-factory.ts"],"sourcesContent":["import { Files } from '@or-sdk/files';\nimport debug from 'debug';\nimport { lookup as mimeLookup } from 'mime-types';\nimport fs from 'node:fs/promises';\nimport { basename, dirname, join, relative } from 'node:path';\n\nimport { esmFactory } from './esm-factory.ts';\nimport type {\n FilesSyncNodeConfig,\n FileUploadOptions,\n LocalObjects,\n PushLocalPathToFilesOptions,\n UploadFilesParameters,\n} from './types.ts';\n\nconst log = debug('files-sync');\n\n/**\n * SDK for synchronizing local directory and directory in Onereach Files service.\n * This SDK is designed to be used with Node.js\n *\n * @example\n * Create client instance with service discovery URL\n *\n * ```typescript\n * const client = new FilesSyncNode({\n * token: process.env.OR_TOKEN,\n * discoveryUrl: process.env.OR_DISCOVERY_URL\n * });\n * ```\n *\n * @example\n * Create client instance with files service URL\n *\n * ```typescript\n * const client = new FilesSyncNode({\n * token: process.env.OR_TOKEN,\n * filesApiUrl: process.env.OR_FILES_API_URL\n * });\n * ```\n *\n * To see debug logs of synching define environment variable `DEBUG` with value `files-sync`:\n *\n * ```sh\n * DEBUG='files-sync' node ./run_logic.js\n * ```\n*/\nexport class FilesSyncNode {\n private readonly filesClient: Files;\n\n public constructor({\n token,\n discoveryUrl,\n filesApiUrl,\n accountId,\n }: FilesSyncNodeConfig) {\n const filesConfig = {\n token,\n accountId,\n };\n this.filesClient = filesApiUrl == undefined\n ? new Files({\n ...filesConfig,\n discoveryUrl,\n })\n : new Files({\n ...filesConfig,\n filesApiUrl,\n });\n }\n\n /**\n * Push local directory to Files service.\n * - All local files would be remote directory;\n * - Extra files in remote directory will remain;\n * - If remote file has the same name as local file, it would be replaced.\n * - Any required remote subdirectories would be created automatically.\n *\n * @param localPath local directory path\n * @param remotePathPrefix path in Files service where to push files. If not set would be synched into root directory.\n * @param options upload params\n * @param options.ttl Timestamp in ms when file should expire\n * @param options.isPublic if `true` uploaded files would be publicly available\n * (access without authentication). Default `false`.\n * @param options.concurrencyLimit how many files can be uploaded at the same time. Default `5`.\n *\n * @example\n * Push local directory `./my-data` (path relative to current working directory of the process)\n * into remote directory `sync-local`\n * ```typescript\n * await client.pushLocalPathToFiles('./my-data', 'sync-local')\n * ```\n */\n public async pushLocalPathToFiles(\n localPath: string,\n remotePathPrefix?: string,\n options: PushLocalPathToFilesOptions = {},\n ) {\n const localObjects = await this.listLocalObjects(localPath);\n\n if (localObjects.files.length) {\n const start = Date.now();\n log('Found %d local files. Starting upload.', localObjects.files.length);\n await this.uploadFiles({\n remotePathPrefix,\n localFiles: localObjects.files,\n }, options);\n log('Finished uploading local files (%d ms)', Date.now() - start);\n }\n }\n\n // private getDiff(localObjects: LocalObjects, remoteObjects: RemoteObjects) {\n // const uploadLocalFiles = localObjects.files.filter(localFile => {\n // return !remoteObjects.files.some(file => file.relative === localFile.relative);\n // });\n\n // const deleteRemoteFiles = remoteObjects.files.filter(remoteFile => {\n // return !localObjects.files.some(file => file.relative === remoteFile.relative);\n // });\n\n // const createRemoteDirs = localObjects.dirs.filter(localDir => {\n // return !remoteObjects.dirs.some(dir => dir.relative === localDir.relative);\n // })\n // const deleteRemoteDirs = remoteObjects.dirs.filter(remoteDir => {\n // return !localObjects.dirs.some(dir => dir.relative === remoteDir.relative);\n // })\n\n // return { uploadLocalFiles, deleteRemoteFiles, createRemoteDirs, deleteRemoteDirs };\n // }\n\n // private async listRemoteObjects(remotePathPrefix?: string): Promise<RemoteObjects> {\n // const result: RemoteObjects = { files: [], dirs: [] }\n // const objects = await this.filesClient.getItemsList(remotePathPrefix ?? '');\n\n // for (const object of objects) {\n // // TODO: test if it works with objects in root without prefix\n // const relativePath = relative(object.parentFolder, object.key)\n // if (object.key.endsWith('/')) result.dirs.push({ relative: relativePath, key: object.key })\n // else result.files.push({ relative: relativePath, key: object.key })\n // }\n\n // return result;\n // }\n\n private async uploadFiles(\n { localFiles, remotePathPrefix }: UploadFilesParameters,\n uploadOptions: FileUploadOptions = {},\n ) {\n const { concurrencyLimit = 5, isPublic = false, ...options } = uploadOptions;\n\n const pLimit = await esmFactory.pLimit();\n const limit = pLimit(concurrencyLimit);\n const uploadTasks = localFiles.map(localFile => limit(async () => {\n const start = Date.now();\n log('Starting upload: %s', localFile.relative);\n\n const handle = await fs.open(localFile.full, 'r');\n const stats = await handle.stat();\n try {\n const name = basename(localFile.relative);\n const prefix = join(remotePathPrefix ?? '', dirname(localFile.relative));\n const request = {\n ...options,\n fileName: name,\n prefix: prefix === '.' ? '' : `${prefix}/`,\n fileContent: handle.createReadStream({ autoClose: true }),\n contentType: mimeLookup(name) || 'application/octet-stream',\n maxFileSize: stats.size,\n knownLength: stats.size,\n isPublic,\n };\n\n await this.filesClient.uploadFileV2(request);\n log('Finished upload: %s (%d ms)', localFile.relative, Date.now() - start);\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const err: any = error;\n const errorMessage = err.response?.data ?? err.stack;\n log('Failed to upload: %s. Error: %j', localFile.relative, errorMessage);\n throw error;\n }\n }));\n\n const result = await Promise.allSettled(uploadTasks);\n const rejected = result.find(item => item.status === 'rejected');\n\n if (rejected) throw rejected.reason;\n }\n\n private async listLocalObjects(localPath: string): Promise<LocalObjects> {\n const { dirs, files } = await this.walkLocal(localPath);\n\n return {\n dirs: dirs.map(full => ({\n full,\n relative: relative(localPath, full),\n })),\n files: files.map(full => ({\n full,\n relative: relative(localPath, full),\n })),\n };\n }\n\n /**\n * Recursively collect all file paths under a directory.\n */\n private async walkLocal(localPath: string) {\n const entries = await fs.readdir(localPath, { withFileTypes: true });\n const dirs: string[] = [];\n const files: string[] = [];\n\n for (const entry of entries) {\n const fullPath = join(localPath, entry.name);\n if (entry.isDirectory()) {\n dirs.push(join(localPath, entry.name));\n const child = await this.walkLocal(fullPath);\n files.push(...child.files);\n dirs.push(...child.dirs);\n } else if (entry.isFile()) {\n files.push(fullPath);\n // } else {\n // files.push(fullPath);\n }\n }\n return {\n dirs,\n files,\n };\n }\n}\n","import type { LimitFunction } from 'p-limit';\nimport { Memoize } from 'typescript-memoize';\n\nexport class EsmFactory {\n public async pLimit(): Promise<pLimit> {\n return await this.importDefault('p-limit');\n }\n\n @Memoize()\n private async importDefault<T>(esmPackage: string): Promise<T> {\n const pkg = await import(esmPackage);\n return pkg.default;\n }\n}\n\nexport const esmFactory = new EsmFactory();\n\nexport type pLimit = (concurrency: number) => LimitFunction;\n"],"mappings":"wMAAA,OAAS,SAAAA,MAAa,gBACtB,OAAOC,MAAW,QAClB,OAAS,UAAUC,MAAkB,aACrC,OAAOC,MAAQ,cACf,OAAS,YAAAC,EAAU,WAAAC,EAAS,QAAAC,EAAM,YAAAC,MAAgB,OCHlD,OAAS,WAAAC,MAAe,qBAEjB,IAAMC,EAAN,KAAiB,CACtB,MAAa,QAA0B,CACrC,OAAO,MAAM,KAAK,cAAc,SAAS,CAC3C,CAGA,MAAc,cAAiBC,EAAgC,CAE7D,OADY,MAAM,OAAOA,IACd,OACb,CACF,EAJgBC,EAAA,CADbC,EAAQ,GALEH,EAMG,6BAMT,IAAMI,EAAa,IAAIJ,EDA9B,IAAMK,EAAMC,EAAM,YAAY,EAgCjBC,EAAN,KAAoB,CACR,YAEV,YAAY,CACjB,MAAAC,EACA,aAAAC,EACA,YAAAC,EACA,UAAAC,CACF,EAAwB,CACtB,IAAMC,EAAc,CAClB,MAAAJ,EACA,UAAAG,CACF,EACA,KAAK,YAAcD,GAAe,KAC9B,IAAIG,EAAM,CACV,GAAGD,EACH,aAAAH,CACF,CAAC,EACC,IAAII,EAAM,CACV,GAAGD,EACH,YAAAF,CACF,CAAC,CACL,CAwBA,MAAa,qBACXI,EACAC,EACAC,EAAuC,CAAC,EACxC,CACA,IAAMC,EAAe,MAAM,KAAK,iBAAiBH,CAAS,EAE1D,GAAIG,EAAa,MAAM,OAAQ,CAC7B,IAAMC,EAAQ,KAAK,IAAI,EACvBb,EAAI,yCAA0CY,EA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SAAW,UAAU,EAE/D,GAAID,EAAU,MAAMA,EAAS,MAC/B,CAEA,MAAc,iBAAiB1B,EAA0C,CACvE,GAAM,CAAE,KAAA4B,EAAM,MAAAC,CAAM,EAAI,MAAM,KAAK,UAAU7B,CAAS,EAEtD,MAAO,CACL,KAAM4B,EAAK,IAAIE,IAAS,CACtB,KAAAA,EACA,SAAUC,EAAS/B,EAAW8B,CAAI,CACpC,EAAE,EACF,MAAOD,EAAM,IAAIC,IAAS,CACxB,KAAAA,EACA,SAAUC,EAAS/B,EAAW8B,CAAI,CACpC,EAAE,CACJ,CACF,CAKA,MAAc,UAAU9B,EAAmB,CACzC,IAAMgC,EAAU,MAAMlB,EAAG,QAAQd,EAAW,CAAE,cAAe,EAAK,CAAC,EAC7D4B,EAAiB,CAAC,EAClBC,EAAkB,CAAC,EAEzB,QAAWI,KAASD,EAAS,CAC3B,IAAME,EAAWf,EAAKnB,EAAWiC,EAAM,IAAI,EAC3C,GAAIA,EAAM,YAAY,EAAG,CACvBL,EAAK,KAAKT,EAAKnB,EAAWiC,EAAM,IAAI,CAAC,EACrC,IAAME,EAAQ,MAAM,KAAK,UAAUD,CAAQ,EAC3CL,EAAM,KAAK,GAAGM,EAAM,KAAK,EACzBP,EAAK,KAAK,GAAGO,EAAM,IAAI,CACzB,MAAWF,EAAM,OAAO,GACtBJ,EAAM,KAAKK,CAAQ,CAIvB,CACA,MAAO,CACL,KAAAN,EACA,MAAAC,CACF,CACF,CACF","names":["Files","debug","mimeLookup","fs","basename","dirname","join","relative","Memoize","EsmFactory","esmPackage","__decorateClass","Memoize","esmFactory","log","debug","FilesSyncNode","token","discoveryUrl","filesApiUrl","accountId","filesConfig","Files","localPath","remotePathPrefix","options","localObjects","start","localFiles","uploadOptions","concurrencyLimit","isPublic","limit","esmFactory","uploadTasks","localFile","handle","fs","stats","name","basename","prefix","join","dirname","request","mimeLookup","error","err","errorMessage","rejected","item","dirs","files","full","relative","entries","entry","fullPath","child"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@or-sdk/files-sync-node",
3
- "version": "0.0.6",
3
+ "version": "0.0.7-beta.3996.0",
4
4
  "description": "SDK for synchronization of local directory with Files service",
5
5
  "keywords": [],
6
6
  "license": "Apache-2.0",
@@ -30,7 +30,7 @@
30
30
  "typecheck": "tsc --noEmit"
31
31
  },
32
32
  "dependencies": {
33
- "@or-sdk/files": "^3.8.2",
33
+ "@or-sdk/files": "^3.8.3-beta.3996.0",
34
34
  "debug": "^4.4.3",
35
35
  "mime-types": "^3.0.1",
36
36
  "p-limit": "^7.2.0",
@@ -38,7 +38,7 @@
38
38
  "typescript-memoize": "^1.1.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@or-sdk/base": "^0.42.5",
41
+ "@or-sdk/base": "^0.42.6-beta.3996.0",
42
42
  "@types/debug": "^4.1.12",
43
43
  "@types/mime-types": "^3.0.1",
44
44
  "tsup": "^8.5.0",
@@ -46,6 +46,5 @@
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public"
49
- },
50
- "gitHead": "c6887f491665f09fe3588ef5384d0d3f2d42412d"
49
+ }
51
50
  }