From de817012ebe38d9ee805b933db197895a1274d25 Mon Sep 17 00:00:00 2001 From: Gordon Bockus Date: Mon, 28 Feb 2022 13:50:04 -0600 Subject: [PATCH 1/2] feat: implement readFileSync in ZipTreeContainer --- package.json | 2 ++ src/resolve/treeContainers.ts | 19 ++++++++++++++++-- test/resolve/treeContainers.test.ts | 15 +++++++++++++-- yarn.lock | 30 +++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fb164cd730..84e54aed1b 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@salesforce/kit": "^1.5.32", "@salesforce/ts-types": "^1.4.2", "archiver": "^5.3.0", + "deasync": "^0.1.24", "fast-xml-parser": "^3.17.4", "graceful-fs": "^4.2.8", "ignore": "^5.1.8", @@ -41,6 +42,7 @@ "@salesforce/prettier-config": "^0.0.2", "@salesforce/ts-sinon": "^1.1.2", "@types/archiver": "^5.1.1", + "@types/deasync": "^0.1.2", "@types/deep-equal-in-any-order": "^1.0.1", "@types/jsforce": "^1.9.38", "@types/mime": "2.0.3", diff --git a/src/resolve/treeContainers.ts b/src/resolve/treeContainers.ts index c9d8bdd1c5..a45d888f37 100644 --- a/src/resolve/treeContainers.ts +++ b/src/resolve/treeContainers.ts @@ -8,6 +8,7 @@ import { join, dirname, basename, normalize, sep } from 'path'; import { Readable } from 'stream'; import { statSync, existsSync, readdirSync, createReadStream, readFileSync } from 'graceful-fs'; import * as unzipper from 'unzipper'; +import deasync = require('deasync'); import { baseName, parseMetadataXml } from '../utils'; import { LibraryError } from '../errors'; import { SourcePath } from '../common'; @@ -166,9 +167,23 @@ export class ZipTreeContainer extends TreeContainer { throw new LibraryError('error_expected_file_path', fsPath); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars public readFileSync(fsPath: string): Buffer { - throw new Error('Method not implemented'); + let done = false; + let dataBuffer: Buffer; + this.readFile(fsPath) + .then((buffer) => { + dataBuffer = buffer; + done = true; + }) + .catch((error) => { + done = true; + throw error; + }); + + deasync.loopWhile(() => { + return !done; + }); + return dataBuffer; } public stream(fsPath: string): Readable { diff --git a/test/resolve/treeContainers.test.ts b/test/resolve/treeContainers.test.ts index dd5e9bed1d..e41fd6873c 100644 --- a/test/resolve/treeContainers.test.ts +++ b/test/resolve/treeContainers.test.ts @@ -229,8 +229,19 @@ describe('Tree Containers', () => { }); describe('readFileSync', () => { - it('should throw an error because it is not implemented yet', () => { - assert.throws(() => tree.readFileSync(join(filesRoot, 'test.txt')), Error, 'Method not implemented'); + it('should syncrounsly read contents of zip entry into buffer.', () => { + const path = join(filesRoot, 'test.txt'); + const contents = tree.readFileSync(path).toString(); + expect(contents).to.equal('test text'); + }); + + it('should throw a library error if readFile throws', () => { + assert.throws( + // eslint-disable-next-line @typescript-eslint/no-misused-promises + () => tree.readFileSync(filesRoot), + LibraryError, + nls.localize('error_expected_file_path', filesRoot) + ); }); }); diff --git a/yarn.lock b/yarn.lock index 01ad1525d6..6757634344 100644 --- a/yarn.lock +++ b/yarn.lock @@ -784,6 +784,11 @@ resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== +"@types/deasync@^0.1.2": + version "0.1.2" + resolved "https://registry.yarnpkg.com/@types/deasync/-/deasync-0.1.2.tgz#a64b68d6ebc145d0a5fe004a53e8e0f4e6d2ec7e" + integrity sha512-sCBFlGCEmZMPS06wdnQELcYzyUYio2K1Hp6g0fjJSKP1jkGKQpIdjRNUQAvdSCCJCWxIMCkX2CL7pi4BCm8Ydg== + "@types/deep-equal-in-any-order@^1.0.1": version "1.0.1" resolved "https://registry.npmjs.org/@types/deep-equal-in-any-order/-/deep-equal-in-any-order-1.0.1.tgz#0559d855797a5034e187f248b23a4490e5444f2e" @@ -1367,6 +1372,13 @@ binary@~0.3.0: buffers "~0.1.1" chainsaw "~0.1.0" +bindings@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" + integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== + dependencies: + file-uri-to-path "1.0.0" + bl@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/bl/-/bl-4.0.3.tgz#12d6287adc29080e22a705e5764b2a9522cdc489" @@ -2048,6 +2060,14 @@ dayjs@^1.8.16: resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.36.tgz#be36e248467afabf8f5a86bae0de0cdceecced50" integrity sha512-3VmRXEtw7RZKAf+4Tv1Ym9AGeo8r8+CjDi26x+7SYQil1UqtqdaokhzoEJohqlzt0m5kacJSDhJQkG/LWhpRBw== +deasync@^0.1.24: + version "0.1.24" + resolved "https://registry.yarnpkg.com/deasync/-/deasync-0.1.24.tgz#6ecc9c6ff9eba64a4f4572ae3c4db77fed09268a" + integrity sha512-i98vg42xNfRZCymummMAN0rIcQ1gZFinSe3btvPIvy6JFTaeHcumeKybRo2HTv86nasfmT0nEgAn2ggLZhOCVA== + dependencies: + bindings "^1.5.0" + node-addon-api "^1.7.1" + debug@4.3.1: version "4.3.1" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" @@ -2780,6 +2800,11 @@ file-entry-cache@^6.0.1: dependencies: flat-cache "^3.0.4" +file-uri-to-path@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" + integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== + fill-range@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" @@ -4752,6 +4777,11 @@ nise@^4.1.0: just-extend "^4.0.2" path-to-regexp "^1.7.0" +node-addon-api@^1.7.1: + version "1.7.2" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-1.7.2.tgz#3df30b95720b53c24e59948b49532b662444f54d" + integrity sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg== + node-preload@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/node-preload/-/node-preload-0.2.1.tgz#c03043bb327f417a18fee7ab7ee57b408a144301" From 395f02323400807614606601967f7dfa586ba493 Mon Sep 17 00:00:00 2001 From: Gordon Bockus Date: Mon, 28 Feb 2022 14:05:10 -0600 Subject: [PATCH 2/2] chore: adding types for SDR --- METADATA_SUPPORT.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/METADATA_SUPPORT.md b/METADATA_SUPPORT.md index e225e58006..81a4705c57 100644 --- a/METADATA_SUPPORT.md +++ b/METADATA_SUPPORT.md @@ -483,15 +483,19 @@ v55 introduces the following new types. Here's their current level of support |Metadata Type|Support|Notes| |:---|:---|:---| +|AssessmentQuestion|❌|Not supported, but support could be added| |BotTemplate|❌|Not supported, but support could be added| +|ConvReasonReportSegment|❌|Not supported, but support could be added| |Experience|undefined|undefined| +|ExperienceMetadataResource|undefined|undefined| +|ExperienceSpace|undefined|undefined| |ExternalDataSrcDescriptor|❌|Not supported, but support could be added| |ExternalDataTranField|❌|Not supported, but support could be added| |ExternalDataTranObject|❌|Not supported, but support could be added| |FavoriteTransferDestination|❌|Not supported, but support could be added| |IndustriesAutomotiveSettings|✅|| -|IndustriesMfgServiceSettings|✅|| |InvLatePymntRiskCalcSettings|✅|| +|MarketingAppExtAction|❌|Not supported, but support could be added| |PaymentsManagementEnabledSettings|✅|| |RegisteredExternalService|❌|Not supported, but support could be added| |StreamingAppDataConnector|❌|Not supported, but support could be added| @@ -516,6 +520,7 @@ v55 introduces the following new types. Here's their current level of support - FormSection - Portal - EmbeddedServiceFieldService +- FlowTest - EventType - EventSubscription - EventDelivery