@ledgerhq/device-management-kit 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +1 -1
- package/lib/cjs/src/api/device-action/task/PredictOutOfMemoryTask.js +1 -1
- package/lib/cjs/src/api/device-action/task/PredictOutOfMemoryTask.js.map +3 -3
- package/lib/cjs/src/api/device-action/task/PredictOutOfMemoryTask.test.js +1 -1
- package/lib/cjs/src/api/device-action/task/PredictOutOfMemoryTask.test.js.map +3 -3
- package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.js +1 -1
- package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.js.map +3 -3
- package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.test.js +1 -1
- package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.test.js.map +3 -3
- package/lib/cjs/src/api/device-model/model/DeviceModel.js +1 -1
- package/lib/cjs/src/api/device-model/model/DeviceModel.js.map +3 -3
- package/lib/cjs/src/api/device-model/model/DeviceModel.stub.js +1 -1
- package/lib/cjs/src/api/device-model/model/DeviceModel.stub.js.map +2 -2
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/api/device-action/task/PredictOutOfMemoryTask.js +1 -1
- package/lib/esm/src/api/device-action/task/PredictOutOfMemoryTask.js.map +3 -3
- package/lib/esm/src/api/device-action/task/PredictOutOfMemoryTask.test.js +1 -1
- package/lib/esm/src/api/device-action/task/PredictOutOfMemoryTask.test.js.map +3 -3
- package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.js +1 -1
- package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.js.map +3 -3
- package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.test.js +1 -1
- package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.test.js.map +3 -3
- package/lib/esm/src/api/device-model/model/DeviceModel.js +1 -1
- package/lib/esm/src/api/device-model/model/DeviceModel.js.map +3 -3
- package/lib/esm/src/api/device-model/model/DeviceModel.stub.js +1 -1
- package/lib/esm/src/api/device-model/model/DeviceModel.stub.js.map +2 -2
- package/lib/types/src/api/device-action/task/PredictOutOfMemoryTask.d.ts +4 -3
- package/lib/types/src/api/device-action/task/PredictOutOfMemoryTask.d.ts.map +1 -1
- package/lib/types/src/api/device-model/data/StaticDeviceModelDataSource.d.ts.map +1 -1
- package/lib/types/src/api/device-model/model/DeviceModel.d.ts +44 -20
- package/lib/types/src/api/device-model/model/DeviceModel.d.ts.map +1 -1
- package/lib/types/src/api/device-model/model/DeviceModel.stub.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/lib/cjs/src/api/device-model/model/DeviceModel.test.js +0 -2
- package/lib/cjs/src/api/device-model/model/DeviceModel.test.js.map +0 -7
- package/lib/esm/src/api/device-model/model/DeviceModel.test.js +0 -2
- package/lib/esm/src/api/device-model/model/DeviceModel.test.js.map +0 -7
- package/lib/types/src/api/device-model/model/DeviceModel.test.d.ts +0 -2
- package/lib/types/src/api/device-model/model/DeviceModel.test.d.ts.map +0 -1
package/lib/cjs/package.json
CHANGED
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
65
65
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
66
66
|
},
|
|
67
|
-
"version": "0.
|
|
67
|
+
"version": "0.13.0"
|
|
68
68
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var v=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},b=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of M(e))!f.call(n,r)&&r!==t&&u(n,r,{get:()=>e[r],enumerable:!(o=k(e,r))||o.enumerable});return n};var B=n=>b(u({},"__esModule",{value:!0}),n);var A={};v(A,{PredictOutOfMemoryTask:()=>w});module.exports=B(A);var g=require("../../device-action/os/Errors"),y=require("../../device-session/DeviceSessionState");class w{constructor(e,t){this.api=e;this.args=t;this.deviceModel=e.getDeviceModel()}deviceModel;run(){const e=this.api.getDeviceSessionState();if(e.sessionStateType===y.DeviceSessionStateType.Connected)return{error:new g.UnknownDAError("Invalid device state")};const{firmwareUpdateContext:t,customImage:o,firmwareVersion:r,installedLanguages:a,installedApps:s}=e;if(t===void 0||o===void 0||r===void 0||a===void 0)return{error:new g.UnknownDAError("Device metadata not fetched")};const{blockSize:l,totalMemoryBlocks:c}=this.getMemoryConstants(r),m=this.getCurrentMemoryBlocksUsage({firmwareUpdateContext:t,customImage:o,installedApps:s,installedLanguages:a,blockSize:l}),p=this.getInstallPlanMemoryBlocksUsage(this.args.installPlan,l);return{outOfMemory:m+p>c}}getMemoryConstants(e){const t=this.deviceModel.getBlockSize({firmwareVersion:e.os}),o=Math.floor(this.deviceModel.memorySize/t);return{blockSize:t,totalMemoryBlocks:o}}getCurrentMemoryBlocksUsage({firmwareUpdateContext:e,customImage:t,installedApps:o,installedLanguages:r,blockSize:a}){const s=i=>Math.ceil(i/a),l=s(e.currentFirmware.bytes||0),c=s(t.size||0),m=o.reduce((i,d)=>i+s(d.bytes||0),0),p=r.reduce((i,d)=>i+s(d.size),0);return l+c+m+p}getInstallPlanMemoryBlocksUsage(e,t){const o=r=>Math.ceil(r/t);return e.reduce((r,a)=>r+o(a.bytes||0),0)}}0&&(module.exports={PredictOutOfMemoryTask});
|
|
2
2
|
//# sourceMappingURL=PredictOutOfMemoryTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-action/task/PredictOutOfMemoryTask.ts"],
|
|
4
|
-
"sourcesContent": ["import type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nexport type PredictOutOfMemoryTaskArgs = {\n installPlan: Application[];\n};\n\nexport type PredictOutOfMemoryTaskResult =\n | {\n outOfMemory: boolean;\n }\n | {\n error: UnknownDAError;\n };\n\nexport class PredictOutOfMemoryTask {\n private readonly
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAA+B,
|
|
6
|
-
"names": ["PredictOutOfMemoryTask_exports", "__export", "PredictOutOfMemoryTask", "__toCommonJS", "import_Errors", "import_DeviceSessionState", "api", "args", "
|
|
4
|
+
"sourcesContent": ["import type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { type TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport {\n type CustomImage,\n DeviceSessionStateType,\n type FirmwareUpdateContext,\n type FirmwareVersion,\n type InstalledLanguagePackage,\n} from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nexport type PredictOutOfMemoryTaskArgs = {\n installPlan: Application[];\n};\n\nexport type PredictOutOfMemoryTaskResult =\n | {\n outOfMemory: boolean;\n }\n | {\n error: UnknownDAError;\n };\n\nexport class PredictOutOfMemoryTask {\n private readonly deviceModel: TransportDeviceModel;\n\n constructor(\n private readonly api: InternalApi,\n private readonly args: PredictOutOfMemoryTaskArgs,\n ) {\n this.deviceModel = api.getDeviceModel();\n }\n\n run(): PredictOutOfMemoryTaskResult {\n const deviceState = this.api.getDeviceSessionState();\n\n if (deviceState.sessionStateType === DeviceSessionStateType.Connected) {\n return { error: new UnknownDAError(\"Invalid device state\") };\n }\n\n const {\n firmwareUpdateContext,\n customImage,\n firmwareVersion,\n installedLanguages,\n installedApps,\n } = deviceState;\n\n if (\n firmwareUpdateContext === undefined ||\n customImage === undefined ||\n firmwareVersion === undefined ||\n installedLanguages === undefined\n ) {\n return { error: new UnknownDAError(\"Device metadata not fetched\") };\n }\n\n const { blockSize, totalMemoryBlocks } =\n this.getMemoryConstants(firmwareVersion);\n\n const currentMemoryBlocksUsage = this.getCurrentMemoryBlocksUsage({\n firmwareUpdateContext,\n customImage,\n installedApps,\n installedLanguages,\n blockSize,\n });\n\n const installPlanBlocksUsage = this.getInstallPlanMemoryBlocksUsage(\n this.args.installPlan,\n blockSize,\n );\n\n return {\n outOfMemory:\n currentMemoryBlocksUsage + installPlanBlocksUsage > totalMemoryBlocks,\n };\n }\n\n private getMemoryConstants(firmwareVersion: FirmwareVersion): {\n blockSize: number;\n totalMemoryBlocks: number;\n } {\n const blockSize = this.deviceModel.getBlockSize({\n firmwareVersion: firmwareVersion.os,\n });\n const totalMemoryBlocks = Math.floor(\n this.deviceModel.memorySize / blockSize,\n );\n return { blockSize, totalMemoryBlocks };\n }\n\n private getCurrentMemoryBlocksUsage({\n firmwareUpdateContext,\n customImage,\n installedApps,\n installedLanguages,\n blockSize,\n }: {\n firmwareUpdateContext: FirmwareUpdateContext;\n customImage: CustomImage;\n installedApps: Application[];\n installedLanguages: InstalledLanguagePackage[];\n blockSize: number;\n }): number {\n const bytesToBlocks = (size: number) => Math.ceil(size / blockSize);\n const firmwareBlocks = bytesToBlocks(\n firmwareUpdateContext.currentFirmware.bytes || 0,\n );\n const customImageBlocks = bytesToBlocks(customImage.size || 0);\n const applicationsBlocks = installedApps.reduce(\n (size, app) => size + bytesToBlocks(app.bytes || 0),\n 0,\n );\n const languagesBlocks = installedLanguages.reduce(\n (size, lang) => size + bytesToBlocks(lang.size),\n 0,\n );\n return (\n firmwareBlocks + customImageBlocks + applicationsBlocks + languagesBlocks\n );\n }\n\n private getInstallPlanMemoryBlocksUsage(\n installPlan: Application[],\n blockSize: number,\n ): number {\n const bytesToBlocks = (size: number) => Math.ceil(size / blockSize);\n return installPlan.reduce(\n (size, app) => size + bytesToBlocks(app.bytes || 0),\n 0,\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAA+B,wCAE/BC,EAMO,kDAeA,MAAMH,CAAuB,CAGlC,YACmBI,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,EAEjB,KAAK,YAAcD,EAAI,eAAe,CACxC,CAPiB,YASjB,KAAoC,CAClC,MAAME,EAAc,KAAK,IAAI,sBAAsB,EAEnD,GAAIA,EAAY,mBAAqB,yBAAuB,UAC1D,MAAO,CAAE,MAAO,IAAI,iBAAe,sBAAsB,CAAE,EAG7D,KAAM,CACJ,sBAAAC,EACA,YAAAC,EACA,gBAAAC,EACA,mBAAAC,EACA,cAAAC,CACF,EAAIL,EAEJ,GACEC,IAA0B,QAC1BC,IAAgB,QAChBC,IAAoB,QACpBC,IAAuB,OAEvB,MAAO,CAAE,MAAO,IAAI,iBAAe,6BAA6B,CAAE,EAGpE,KAAM,CAAE,UAAAE,EAAW,kBAAAC,CAAkB,EACnC,KAAK,mBAAmBJ,CAAe,EAEnCK,EAA2B,KAAK,4BAA4B,CAChE,sBAAAP,EACA,YAAAC,EACA,cAAAG,EACA,mBAAAD,EACA,UAAAE,CACF,CAAC,EAEKG,EAAyB,KAAK,gCAClC,KAAK,KAAK,YACVH,CACF,EAEA,MAAO,CACL,YACEE,EAA2BC,EAAyBF,CACxD,CACF,CAEQ,mBAAmBJ,EAGzB,CACA,MAAMG,EAAY,KAAK,YAAY,aAAa,CAC9C,gBAAiBH,EAAgB,EACnC,CAAC,EACKI,EAAoB,KAAK,MAC7B,KAAK,YAAY,WAAaD,CAChC,EACA,MAAO,CAAE,UAAAA,EAAW,kBAAAC,CAAkB,CACxC,CAEQ,4BAA4B,CAClC,sBAAAN,EACA,YAAAC,EACA,cAAAG,EACA,mBAAAD,EACA,UAAAE,CACF,EAMW,CACT,MAAMI,EAAiBC,GAAiB,KAAK,KAAKA,EAAOL,CAAS,EAC5DM,EAAiBF,EACrBT,EAAsB,gBAAgB,OAAS,CACjD,EACMY,EAAoBH,EAAcR,EAAY,MAAQ,CAAC,EACvDY,EAAqBT,EAAc,OACvC,CAACM,EAAMI,IAAQJ,EAAOD,EAAcK,EAAI,OAAS,CAAC,EAClD,CACF,EACMC,EAAkBZ,EAAmB,OACzC,CAACO,EAAMM,IAASN,EAAOD,EAAcO,EAAK,IAAI,EAC9C,CACF,EACA,OACEL,EAAiBC,EAAoBC,EAAqBE,CAE9D,CAEQ,gCACNE,EACAZ,EACQ,CACR,MAAMI,EAAiBC,GAAiB,KAAK,KAAKA,EAAOL,CAAS,EAClE,OAAOY,EAAY,OACjB,CAACP,EAAMI,IAAQJ,EAAOD,EAAcK,EAAI,OAAS,CAAC,EAClD,CACF,CACF,CACF",
|
|
6
|
+
"names": ["PredictOutOfMemoryTask_exports", "__export", "PredictOutOfMemoryTask", "__toCommonJS", "import_Errors", "import_DeviceSessionState", "api", "args", "deviceState", "firmwareUpdateContext", "customImage", "firmwareVersion", "installedLanguages", "installedApps", "blockSize", "totalMemoryBlocks", "currentMemoryBlocksUsage", "installPlanBlocksUsage", "bytesToBlocks", "size", "firmwareBlocks", "customImageBlocks", "applicationsBlocks", "app", "languagesBlocks", "lang", "installPlan"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var n=require("../../device/DeviceStatus"),
|
|
1
|
+
"use strict";var p=Object.create;var u=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var k=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!w.call(e,o)&&o!==n&&u(e,o,{get:()=>t[o],enumerable:!(l=S(t,o))||l.enumerable});return e};var v=(e,t,n)=>(n=e!=null?p(y(e)):{},k(t||!e||!e.__esModule?u(n,"default",{value:e,enumerable:!0}):n,e));var r=v(require("semver")),s=require("../../device/DeviceStatus"),m=require("../../device-action/__test-utils__/makeInternalApi"),c=require("../../device-action/os/Errors"),a=require("../../device-session/DeviceSessionState"),i=require("./PredictOutOfMemoryTask");describe("PredictOutOfMemoryTask",()=>{const e=(0,m.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.clearAllMocks(),e.getDeviceModel.mockReturnValue({memorySize:1569792,getBlockSize:()=>32})}),it("Success enough memory",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:s.DeviceStatus.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:397824}},customImage:{size:51893},installedApps:[{bytes:305442},{bytes:514598},{bytes:271583}],installedLanguages:[{id:1,size:20480}],firmwareVersion:{os:"2.0.0"}});const t=new i.PredictOutOfMemoryTask(e,{installPlan:[{bytes:1324},{bytes:6559}]}).run();expect(t).toStrictEqual({outOfMemory:!1})}),it("Success not enough memory",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:s.DeviceStatus.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:397824}},customImage:{size:51893},installedApps:[{bytes:305442},{bytes:514598},{bytes:271583}],installedLanguages:[{id:1,size:20480}],firmwareVersion:{os:"2.0.0"}});const t=new i.PredictOutOfMemoryTask(e,{installPlan:[{bytes:1324},{bytes:6559},{bytes:1}]}).run();expect(t).toStrictEqual({outOfMemory:!0})}),it("Success enough memory (recent Nano S, 2kB block size)",()=>{e.getDeviceModel.mockReturnValueOnce({memorySize:12*1024,getBlockSize:({firmwareVersion:n})=>r.default.lt(r.default.coerce(n)??"","2.0.0")?4*1024:2*1024}),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:s.DeviceStatus.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:6*1024}},customImage:{size:0},installedApps:[],installedLanguages:[],firmwareVersion:{os:"2.0.0"}});const t=new i.PredictOutOfMemoryTask(e,{installPlan:[{bytes:6*1024}]}).run();expect(t).toStrictEqual({outOfMemory:!1})}),it("Success not enough memory (old Nano S, 4kB block size)",()=>{e.getDeviceModel.mockReturnValueOnce({memorySize:12*1024,getBlockSize:({firmwareVersion:n})=>r.default.lt(r.default.coerce(n)??"","2.0.0")?4*1024:2*1024}),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:s.DeviceStatus.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:6*1024}},customImage:{size:0},installedApps:[],installedLanguages:[],firmwareVersion:{os:"1.0.0"}});const t=new i.PredictOutOfMemoryTask(e,{installPlan:[{bytes:6*1024}]}).run();expect(t).toStrictEqual({outOfMemory:!0})}),it("Success undefined sizes",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:s.DeviceStatus.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:397824}},customImage:{},installedApps:[{bytes:305442},{bytes:null},{bytes:271583}],installedLanguages:[],firmwareVersion:{os:"2.0.0"}});const t=new i.PredictOutOfMemoryTask(e,{installPlan:[{bytes:1324},{bytes:6559}]}).run();expect(t).toStrictEqual({outOfMemory:!1})}),it("Error when device is in incorrect state",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.Connected,deviceStatus:s.DeviceStatus.CONNECTED});const t=new i.PredictOutOfMemoryTask(e,{installPlan:[{bytes:1324}]}).run();expect(t).toStrictEqual({error:new c.UnknownDAError("Invalid device state")})}),it("Error when device session was not populated",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:a.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:s.DeviceStatus.CONNECTED,installedApps:[]});const t=new i.PredictOutOfMemoryTask(e,{installPlan:[{bytes:1324}]}).run();expect(t).toStrictEqual({error:new c.UnknownDAError("Device metadata not fetched")})})});
|
|
2
2
|
//# sourceMappingURL=PredictOutOfMemoryTask.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-action/task/PredictOutOfMemoryTask.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport type { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport type { DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\nimport type { FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport { PredictOutOfMemoryTask } from \"./PredictOutOfMemoryTask\";\n\ndescribe(\"PredictOutOfMemoryTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.clearAllMocks();\n apiMock.getDeviceModel.mockReturnValue({\n memorySize: 1569792,\n
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["import_DeviceStatus", "import_makeInternalApi", "import_Errors", "import_DeviceSessionState", "import_PredictOutOfMemoryTask", "apiMock", "result"]
|
|
4
|
+
"sourcesContent": ["import semver from \"semver\";\n\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport type { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport type { DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\nimport type { FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport { PredictOutOfMemoryTask } from \"./PredictOutOfMemoryTask\";\n\ndescribe(\"PredictOutOfMemoryTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.clearAllMocks();\n apiMock.getDeviceModel.mockReturnValue({\n memorySize: 1569792,\n getBlockSize: () => 32,\n } as unknown as TransportDeviceModel);\n });\n\n it(\"Success enough memory\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 397824 } as FinalFirmware,\n },\n customImage: { size: 51893 },\n installedApps: [\n { bytes: 305442 },\n { bytes: 514598 },\n { bytes: 271583 },\n ] as unknown as Application[],\n installedLanguages: [{ id: 1, size: 20480 }],\n firmwareVersion: { os: \"2.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [\n { bytes: 1324 },\n { bytes: 6559 },\n ] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n outOfMemory: false,\n });\n });\n\n it(\"Success not enough memory\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 397824 } as FinalFirmware,\n },\n customImage: { size: 51893 },\n installedApps: [\n { bytes: 305442 },\n { bytes: 514598 },\n { bytes: 271583 },\n ] as unknown as Application[],\n installedLanguages: [{ id: 1, size: 20480 }],\n firmwareVersion: { os: \"2.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [\n { bytes: 1324 },\n { bytes: 6559 },\n { bytes: 1 },\n ] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n outOfMemory: true,\n });\n });\n\n it(\"Success enough memory (recent Nano S, 2kB block size)\", () => {\n // GIVEN\n apiMock.getDeviceModel.mockReturnValueOnce({\n memorySize: 12 * 1024,\n getBlockSize: ({ firmwareVersion }: { firmwareVersion: string }) => {\n return semver.lt(semver.coerce(firmwareVersion) ?? \"\", \"2.0.0\")\n ? 4 * 1024\n : 2 * 1024;\n },\n } as unknown as TransportDeviceModel);\n\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 6 * 1024 } as FinalFirmware,\n },\n customImage: { size: 0 },\n installedApps: [],\n installedLanguages: [],\n firmwareVersion: { os: \"2.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [{ bytes: 6 * 1024 }] as unknown as Application[],\n }).run();\n\n // THEN\n // 6x2kB blocks of total memory (12kB total)\n // -3*2kB block for firmware (to fit 6kB)\n // -3*2kB block for install plan (to fit 6kB)\n // = 0 blocks left, enough memory\n expect(result).toStrictEqual({\n outOfMemory: false,\n });\n });\n\n it(\"Success not enough memory (old Nano S, 4kB block size)\", () => {\n // GIVEN\n apiMock.getDeviceModel.mockReturnValueOnce({\n memorySize: 12 * 1024,\n getBlockSize: ({ firmwareVersion }: { firmwareVersion: string }) => {\n return semver.lt(semver.coerce(firmwareVersion) ?? \"\", \"2.0.0\")\n ? 4 * 1024\n : 2 * 1024;\n },\n } as unknown as TransportDeviceModel);\n\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 6 * 1024 } as FinalFirmware,\n },\n customImage: { size: 0 },\n installedApps: [],\n installedLanguages: [],\n firmwareVersion: { os: \"1.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [{ bytes: 6 * 1024 }] as unknown as Application[],\n }).run();\n\n // THEN\n // 3x4kB blocks of total memory (12kB total)\n // -2x4kB block for firmware (to fit 6kB)\n // -2x4kB blocks for install plan (to fit 6kB)\n // = -1 block left, not enough memory\n expect(result).toStrictEqual({\n outOfMemory: true,\n });\n });\n\n it(\"Success undefined sizes\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 397824 } as FinalFirmware,\n },\n customImage: {},\n installedApps: [\n { bytes: 305442 },\n { bytes: null },\n { bytes: 271583 },\n ] as unknown as Application[],\n installedLanguages: [],\n firmwareVersion: { os: \"2.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [\n { bytes: 1324 },\n { bytes: 6559 },\n ] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n outOfMemory: false,\n });\n });\n\n it(\"Error when device is in incorrect state\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n } as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [{ bytes: 1324 }] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Invalid device state\"),\n });\n });\n\n it(\"Error when device session was not populated\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [{ bytes: 1324 }] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Device metadata not fetched\"),\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "wdAAA,IAAAA,EAAmB,qBAEnBC,EAA6B,oCAC7BC,EAAgD,6DAChDC,EAA+B,wCAG/BC,EAAuC,kDAIvCC,EAAuC,oCAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,KAAU,mCAAgC,EAEhD,WAAW,IAAM,CACf,GAAG,cAAc,EACjBA,EAAQ,eAAe,gBAAgB,CACrC,WAAY,QACZ,aAAc,IAAM,EACtB,CAAoC,CACtC,CAAC,EAED,GAAG,wBAAyB,IAAM,CAEhCA,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,sBAAuB,CACrB,gBAAiB,CAAE,MAAO,MAAO,CACnC,EACA,YAAa,CAAE,KAAM,KAAM,EAC3B,cAAe,CACb,CAAE,MAAO,MAAO,EAChB,CAAE,MAAO,MAAO,EAChB,CAAE,MAAO,MAAO,CAClB,EACA,mBAAoB,CAAC,CAAE,GAAI,EAAG,KAAM,KAAM,CAAC,EAC3C,gBAAiB,CAAE,GAAI,OAAQ,CACjC,CAAkC,EAGlC,MAAMC,EAAS,IAAI,yBAAuBD,EAAS,CACjD,YAAa,CACX,CAAE,MAAO,IAAK,EACd,CAAE,MAAO,IAAK,CAChB,CACF,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,YAAa,EACf,CAAC,CACH,CAAC,EAED,GAAG,4BAA6B,IAAM,CAEpCD,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,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,YAAa,CAAC,CAAE,MAAO,IAAK,CAAC,CAC/B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,MAAO,IAAI,iBAAe,sBAAsB,CAClD,CAAC,CACH,CAAC,EAED,GAAG,8CAA+C,IAAM,CAEtDD,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,CAClB,CAAkC,EAGlC,MAAMC,EAAS,IAAI,yBAAuBD,EAAS,CACjD,YAAa,CAAC,CAAE,MAAO,IAAK,CAAC,CAC/B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,MAAO,IAAI,iBAAe,6BAA6B,CACzD,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_semver", "import_DeviceStatus", "import_makeInternalApi", "import_Errors", "import_DeviceSessionState", "import_PredictOutOfMemoryTask", "apiMock", "result", "firmwareVersion", "semver"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var l=Object.defineProperty;var
|
|
1
|
+
"use strict";var I=Object.create;var l=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var N=(r,e,d)=>e in r?l(r,e,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[e]=d;var w=(r,e)=>{for(var d in e)l(r,d,{get:e[d],enumerable:!0})},v=(r,e,d,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of a(e))!x.call(r,o)&&o!==d&&l(r,o,{get:()=>e[o],enumerable:!(t=b(e,o))||t.enumerable});return r};var P=(r,e,d)=>(d=r!=null?I(g(r)):{},v(e||!r||!r.__esModule?l(d,"default",{value:r,enumerable:!0}):d,r)),B=r=>v(l({},"__esModule",{value:!0}),r),f=(r,e,d,t)=>{for(var o=t>1?void 0:t?b(e,d):e,c=r.length-1,n;c>=0;c--)(n=r[c])&&(o=(t?n(e,d,o):n(o))||o);return t&&o&&l(e,d,o),o};var U=(r,e,d)=>N(r,typeof e!="symbol"?e+"":e,d);var O={};w(O,{StaticDeviceModelDataSource:()=>s});module.exports=B(O);var p=require("inversify"),m=P(require("semver")),i=require("../../device/DeviceModel"),y=require("../../device-model/model/BleDeviceInfos"),u=require("../../device-model/model/DeviceModel");let s=class{getAllDeviceModels(){return Object.values(s.deviceModelByIds)}getDeviceModel(e){return s.deviceModelByIds[e.id]}filterDeviceModels(e){return this.getAllDeviceModels().filter(d=>Object.entries(e).every(([t,o])=>d[t]===o))}getBluetoothServicesInfos(){return Object.values(s.deviceModelByIds).reduce((e,d)=>{const{bluetoothSpec:t}=d;return t?{...e,...t.reduce((o,c)=>({...o,[c.serviceUuid]:new y.BleDeviceInfos(d,c.serviceUuid,c.writeUuid,c.writeCmdUuid,c.notifyUuid)}),{})}:e},{})}getBluetoothServices(){return Object.values(s.deviceModelByIds).map(e=>(e.bluetoothSpec||[]).map(d=>d.serviceUuid)).flat().filter(e=>!!e)}};U(s,"deviceModelByIds",{[i.DeviceModelId.NANO_S]:new u.TransportDeviceModel({id:i.DeviceModelId.NANO_S,productName:"Ledger Nano S",usbProductId:16,bootloaderUsbProductId:1,usbOnly:!0,memorySize:320*1024,getBlockSize:e=>m.default.lt(m.default.coerce(e.firmwareVersion)??"","2.0.0")?4*1024:2*1024,masks:[823132160]}),[i.DeviceModelId.NANO_SP]:new u.TransportDeviceModel({id:i.DeviceModelId.NANO_SP,productName:"Ledger Nano S Plus",usbProductId:80,bootloaderUsbProductId:5,usbOnly:!0,memorySize:1533*1024,getBlockSize:()=>32,masks:[856686592]}),[i.DeviceModelId.NANO_X]:new u.TransportDeviceModel({id:i.DeviceModelId.NANO_X,productName:"Ledger Nano X",usbProductId:64,bootloaderUsbProductId:4,usbOnly:!1,memorySize:2*1024*1024,getBlockSize:()=>4*1024,masks:[855638016],bluetoothSpec:[{serviceUuid:"13d63400-2c97-0004-0000-4c6564676572",notifyUuid:"13d63400-2c97-0004-0001-4c6564676572",writeUuid:"13d63400-2c97-0004-0002-4c6564676572",writeCmdUuid:"13d63400-2c97-0004-0003-4c6564676572"}]}),[i.DeviceModelId.STAX]:new u.TransportDeviceModel({id:i.DeviceModelId.STAX,productName:"Ledger Stax",usbProductId:96,bootloaderUsbProductId:6,usbOnly:!1,memorySize:1533*1024,getBlockSize:()=>32,masks:[857735168],bluetoothSpec:[{serviceUuid:"13d63400-2c97-6004-0000-4c6564676572",notifyUuid:"13d63400-2c97-6004-0001-4c6564676572",writeUuid:"13d63400-2c97-6004-0002-4c6564676572",writeCmdUuid:"13d63400-2c97-6004-0003-4c6564676572"}]}),[i.DeviceModelId.FLEX]:new u.TransportDeviceModel({id:i.DeviceModelId.FLEX,productName:"Ledger Flex",usbProductId:112,bootloaderUsbProductId:7,usbOnly:!1,memorySize:1533*1024,getBlockSize:()=>32,masks:[858783744],bluetoothSpec:[{serviceUuid:"13d63400-2c97-3004-0000-4c6564676572",notifyUuid:"13d63400-2c97-3004-0001-4c6564676572",writeUuid:"13d63400-2c97-3004-0002-4c6564676572",writeCmdUuid:"13d63400-2c97-3004-0003-4c6564676572"}]}),[i.DeviceModelId.APEX]:new u.TransportDeviceModel({id:i.DeviceModelId.APEX,productName:"Ledger Apex",usbProductId:128,bootloaderUsbProductId:8,usbOnly:!1,memorySize:1533*1024,getBlockSize:()=>32,masks:[859832320],bluetoothSpec:[{serviceUuid:"13d63400-2c97-8004-0000-4c6564676572",notifyUuid:"13d63400-2c97-8004-0001-4c6564676572",writeUuid:"13d63400-2c97-8004-0002-4c6564676572",writeCmdUuid:"13d63400-2c97-8004-0003-4c6564676572"}]})}),s=f([(0,p.injectable)()],s);0&&(module.exports={StaticDeviceModelDataSource});
|
|
2
2
|
//# sourceMappingURL=StaticDeviceModelDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-model/data/StaticDeviceModelDataSource.ts"],
|
|
4
|
-
"sourcesContent": ["import { injectable } from \"inversify\";\n\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceModelDataSource } from \"@api/device-model/data/DeviceModelDataSource\";\nimport { BleDeviceInfos } from \"@api/device-model/model/BleDeviceInfos\";\nimport { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\n\n/**\n * Static/in memory implementation of the device model data source\n */\n@injectable()\nexport class StaticDeviceModelDataSource implements DeviceModelDataSource {\n private static deviceModelByIds: {\n [_key in DeviceModelId]: TransportDeviceModel;\n } = {\n [DeviceModelId.NANO_S]: new TransportDeviceModel({\n id: DeviceModelId.NANO_S,\n productName: \"Ledger Nano S\",\n usbProductId: 0x10,\n bootloaderUsbProductId: 0x0001,\n usbOnly: true,\n memorySize: 320 * 1024,\n
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["StaticDeviceModelDataSource_exports", "__export", "StaticDeviceModelDataSource", "__toCommonJS", "import_inversify", "import_DeviceModel", "import_BleDeviceInfos", "StaticDeviceModelDataSource", "params", "deviceModel", "key", "value", "acc", "bluetoothSpec", "serviceToModel", "bleSpec", "spec", "uuid", "__publicField", "__decorateClass"]
|
|
4
|
+
"sourcesContent": ["import { injectable } from \"inversify\";\nimport semver from \"semver\";\n\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceModelDataSource } from \"@api/device-model/data/DeviceModelDataSource\";\nimport { BleDeviceInfos } from \"@api/device-model/model/BleDeviceInfos\";\nimport { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\n\n/**\n * Static/in memory implementation of the device model data source\n */\n@injectable()\nexport class StaticDeviceModelDataSource implements DeviceModelDataSource {\n private static deviceModelByIds: {\n [_key in DeviceModelId]: TransportDeviceModel;\n } = {\n [DeviceModelId.NANO_S]: new TransportDeviceModel({\n id: DeviceModelId.NANO_S,\n productName: \"Ledger Nano S\",\n usbProductId: 0x10,\n bootloaderUsbProductId: 0x0001,\n usbOnly: true,\n memorySize: 320 * 1024,\n getBlockSize: (p: { firmwareVersion: string }) =>\n semver.lt(semver.coerce(p.firmwareVersion) ?? \"\", \"2.0.0\")\n ? 4 * 1024\n : 2 * 1024,\n masks: [0x31100000],\n }),\n [DeviceModelId.NANO_SP]: new TransportDeviceModel({\n id: DeviceModelId.NANO_SP,\n productName: \"Ledger Nano S Plus\",\n usbProductId: 0x50,\n bootloaderUsbProductId: 0x0005,\n usbOnly: true,\n memorySize: 1533 * 1024,\n getBlockSize: () => 32,\n masks: [0x33100000],\n }),\n [DeviceModelId.NANO_X]: new TransportDeviceModel({\n id: DeviceModelId.NANO_X,\n productName: \"Ledger Nano X\",\n usbProductId: 0x40,\n bootloaderUsbProductId: 0x0004,\n usbOnly: false,\n memorySize: 2 * 1024 * 1024,\n getBlockSize: () => 4 * 1024,\n masks: [0x33000000],\n bluetoothSpec: [\n {\n serviceUuid: \"13d63400-2c97-0004-0000-4c6564676572\",\n notifyUuid: \"13d63400-2c97-0004-0001-4c6564676572\",\n writeUuid: \"13d63400-2c97-0004-0002-4c6564676572\",\n writeCmdUuid: \"13d63400-2c97-0004-0003-4c6564676572\",\n },\n ],\n }),\n [DeviceModelId.STAX]: new TransportDeviceModel({\n id: DeviceModelId.STAX,\n productName: \"Ledger Stax\",\n usbProductId: 0x60,\n bootloaderUsbProductId: 0x0006,\n usbOnly: false,\n memorySize: 1533 * 1024,\n getBlockSize: () => 32,\n masks: [0x33200000],\n bluetoothSpec: [\n {\n serviceUuid: \"13d63400-2c97-6004-0000-4c6564676572\",\n notifyUuid: \"13d63400-2c97-6004-0001-4c6564676572\",\n writeUuid: \"13d63400-2c97-6004-0002-4c6564676572\",\n writeCmdUuid: \"13d63400-2c97-6004-0003-4c6564676572\",\n },\n ],\n }),\n [DeviceModelId.FLEX]: new TransportDeviceModel({\n id: DeviceModelId.FLEX,\n productName: \"Ledger Flex\",\n usbProductId: 0x70,\n bootloaderUsbProductId: 0x0007,\n usbOnly: false,\n memorySize: 1533 * 1024,\n getBlockSize: () => 32,\n masks: [0x33300000],\n bluetoothSpec: [\n {\n serviceUuid: \"13d63400-2c97-3004-0000-4c6564676572\",\n notifyUuid: \"13d63400-2c97-3004-0001-4c6564676572\",\n writeUuid: \"13d63400-2c97-3004-0002-4c6564676572\",\n writeCmdUuid: \"13d63400-2c97-3004-0003-4c6564676572\",\n },\n ],\n }),\n [DeviceModelId.APEX]: new TransportDeviceModel({\n id: DeviceModelId.APEX,\n productName: \"Ledger Apex\",\n usbProductId: 0x80,\n bootloaderUsbProductId: 0x0008,\n usbOnly: false,\n memorySize: 1533 * 1024,\n getBlockSize: () => 32,\n masks: [0x33400000],\n bluetoothSpec: [\n {\n serviceUuid: \"13d63400-2c97-8004-0000-4c6564676572\",\n notifyUuid: \"13d63400-2c97-8004-0001-4c6564676572\",\n writeUuid: \"13d63400-2c97-8004-0002-4c6564676572\",\n writeCmdUuid: \"13d63400-2c97-8004-0003-4c6564676572\",\n },\n ],\n }),\n };\n\n getAllDeviceModels(): TransportDeviceModel[] {\n return Object.values(StaticDeviceModelDataSource.deviceModelByIds);\n }\n\n getDeviceModel(params: { id: DeviceModelId }): TransportDeviceModel {\n return StaticDeviceModelDataSource.deviceModelByIds[params.id];\n }\n\n /**\n * Returns the list of device models that match all the given parameters\n */\n filterDeviceModels(\n params: Partial<TransportDeviceModel>,\n ): TransportDeviceModel[] {\n return this.getAllDeviceModels().filter((deviceModel) => {\n return Object.entries(params).every(([key, value]) => {\n return deviceModel[key as keyof TransportDeviceModel] === value;\n });\n });\n }\n\n getBluetoothServicesInfos(): Record<string, BleDeviceInfos> {\n return Object.values(StaticDeviceModelDataSource.deviceModelByIds).reduce<\n Record<string, BleDeviceInfos>\n >((acc, deviceModel) => {\n const { bluetoothSpec } = deviceModel;\n if (bluetoothSpec) {\n return {\n ...acc,\n ...bluetoothSpec.reduce<Record<string, BleDeviceInfos>>(\n (serviceToModel, bleSpec) => ({\n ...serviceToModel,\n [bleSpec.serviceUuid]: new BleDeviceInfos(\n deviceModel,\n bleSpec.serviceUuid,\n bleSpec.writeUuid,\n bleSpec.writeCmdUuid,\n bleSpec.notifyUuid,\n ),\n }),\n {},\n ),\n };\n }\n return acc;\n }, {});\n }\n\n getBluetoothServices(): string[] {\n return Object.values(StaticDeviceModelDataSource.deviceModelByIds)\n .map((deviceModel) =>\n (deviceModel.bluetoothSpec || []).map((spec) => spec.serviceUuid),\n )\n .flat()\n .filter((uuid) => !!uuid);\n }\n}\n"],
|
|
5
|
+
"mappings": "o0BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA2B,qBAC3BC,EAAmB,qBAEnBC,EAA8B,mCAE9BC,EAA+B,kDAC/BD,EAAqC,+CAM9B,IAAME,EAAN,KAAmE,CAqGxE,oBAA6C,CAC3C,OAAO,OAAO,OAAOA,EAA4B,gBAAgB,CACnE,CAEA,eAAeC,EAAqD,CAClE,OAAOD,EAA4B,iBAAiBC,EAAO,EAAE,CAC/D,CAKA,mBACEA,EACwB,CACxB,OAAO,KAAK,mBAAmB,EAAE,OAAQC,GAChC,OAAO,QAAQD,CAAM,EAAE,MAAM,CAAC,CAACE,EAAKC,CAAK,IACvCF,EAAYC,CAAiC,IAAMC,CAC3D,CACF,CACH,CAEA,2BAA4D,CAC1D,OAAO,OAAO,OAAOJ,EAA4B,gBAAgB,EAAE,OAEjE,CAACK,EAAKH,IAAgB,CACtB,KAAM,CAAE,cAAAI,CAAc,EAAIJ,EAC1B,OAAII,EACK,CACL,GAAGD,EACH,GAAGC,EAAc,OACf,CAACC,EAAgBC,KAAa,CAC5B,GAAGD,EACH,CAACC,EAAQ,WAAW,EAAG,IAAI,iBACzBN,EACAM,EAAQ,YACRA,EAAQ,UACRA,EAAQ,aACRA,EAAQ,UACV,CACF,GACA,CAAC,CACH,CACF,EAEKH,CACT,EAAG,CAAC,CAAC,CACP,CAEA,sBAAiC,CAC/B,OAA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,CAC7C,GAAI,gBAAc,KAClB,YAAa,cACb,aAAc,IACd,uBAAwB,EACxB,QAAS,GACT,WAAY,KAAO,KACnB,aAAc,IAAM,GACpB,MAAO,CAAC,SAAU,EAClB,cAAe,CACb,CACE,YAAa,uCACb,WAAY,uCACZ,UAAW,uCACX,aAAc,sCAChB,CACF,CACF,CAAC,EACD,CAAC,gBAAc,IAAI,EAAG,IAAI,uBAAqB,CAC7C,GAAI,gBAAc,KAClB,YAAa,cACb,aAAc,IACd,uBAAwB,EACxB,QAAS,GACT,WAAY,KAAO,KACnB,aAAc,IAAM,GACpB,MAAO,CAAC,SAAU,EAClB,cAAe,CACb,CACE,YAAa,uCACb,WAAY,uCACZ,UAAW,uCACX,aAAc,sCAChB,CACF,CACF,CAAC,CACH,GAnGWZ,EAANc,EAAA,IADN,cAAW,GACCd",
|
|
6
|
+
"names": ["StaticDeviceModelDataSource_exports", "__export", "StaticDeviceModelDataSource", "__toCommonJS", "import_inversify", "import_semver", "import_DeviceModel", "import_BleDeviceInfos", "StaticDeviceModelDataSource", "params", "deviceModel", "key", "value", "acc", "bluetoothSpec", "serviceToModel", "bleSpec", "spec", "uuid", "__publicField", "p", "semver", "__decorateClass"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../../device/DeviceModel"),
|
|
1
|
+
"use strict";var e=require("../../device/DeviceModel"),r=require("../../device-model/model/BleDeviceInfos"),d=require("./StaticDeviceModelDataSource");describe("StaticDeviceModelDataSource",()=>{describe("getAllDeviceModels",()=>{it("should return all device models",()=>{const c=new d.StaticDeviceModelDataSource().getAllDeviceModels();expect(c.length).toEqual(6),expect(c).toContainEqual(expect.objectContaining({id:e.DeviceModelId.APEX})),expect(c).toContainEqual(expect.objectContaining({id:e.DeviceModelId.NANO_S})),expect(c).toContainEqual(expect.objectContaining({id:e.DeviceModelId.NANO_SP})),expect(c).toContainEqual(expect.objectContaining({id:e.DeviceModelId.NANO_X})),expect(c).toContainEqual(expect.objectContaining({id:e.DeviceModelId.STAX})),expect(c).toContainEqual(expect.objectContaining({id:e.DeviceModelId.FLEX}))})}),describe("getDeviceModel",()=>{it("should return the associated device model",()=>{const t=new d.StaticDeviceModelDataSource,c=t.getDeviceModel({id:e.DeviceModelId.NANO_S});expect(c).toEqual(expect.objectContaining({id:e.DeviceModelId.NANO_S}));const o=t.getDeviceModel({id:e.DeviceModelId.NANO_SP});expect(o).toEqual(expect.objectContaining({id:e.DeviceModelId.NANO_SP}));const i=t.getDeviceModel({id:e.DeviceModelId.NANO_X});expect(i).toEqual(expect.objectContaining({id:e.DeviceModelId.NANO_X}));const n=t.getDeviceModel({id:e.DeviceModelId.STAX});expect(n).toEqual(expect.objectContaining({id:e.DeviceModelId.STAX}));const l=t.getDeviceModel({id:e.DeviceModelId.FLEX});expect(l).toEqual(expect.objectContaining({id:e.DeviceModelId.FLEX}))})}),describe("filterDeviceModels",()=>{it("should return the device models that match the given single parameter",()=>{const t=new d.StaticDeviceModelDataSource,c=t.filterDeviceModels({usbOnly:!0});expect(c.length).toEqual(2),expect(c).toContainEqual(expect.objectContaining({id:e.DeviceModelId.NANO_SP})),expect(c).toContainEqual(expect.objectContaining({id:e.DeviceModelId.NANO_S}));const o=t.filterDeviceModels({usbProductId:16});expect(o.length).toEqual(1),expect(o[0]).toEqual(expect.objectContaining({id:e.DeviceModelId.NANO_S}));const i=t.filterDeviceModels({usbProductId:64});expect(i.length).toEqual(1),expect(i[0]).toEqual(expect.objectContaining({id:e.DeviceModelId.NANO_X}));const n=t.filterDeviceModels({usbProductId:80});expect(n.length).toEqual(1),expect(n[0]).toEqual(expect.objectContaining({id:e.DeviceModelId.NANO_SP}));const l=t.filterDeviceModels({usbProductId:96});expect(l.length).toEqual(1),expect(l[0]).toEqual(expect.objectContaining({id:e.DeviceModelId.STAX}));const s=t.filterDeviceModels({usbProductId:0});expect(s.length).toEqual(0)}),it("should return the device models that match the given multiple parameters",()=>{const t=new d.StaticDeviceModelDataSource,c=t.filterDeviceModels({usbOnly:!1,usbProductId:64});expect(c.length).toEqual(1),expect(c[0]).toEqual(expect.objectContaining({id:e.DeviceModelId.NANO_X}));const o=t.filterDeviceModels({usbOnly:!0,usbProductId:80});expect(o.length).toEqual(1),expect(o[0]).toEqual(expect.objectContaining({id:e.DeviceModelId.NANO_SP}));const i=t.filterDeviceModels({usbOnly:!1,usbProductId:16});expect(i.length).toEqual(0)})}),describe("getBluetoothServicesInfos",()=>{it("should return the ble service infos record",()=>{const t=new d.StaticDeviceModelDataSource,c=t.getBluetoothServicesInfos();expect(c).toStrictEqual({"13d63400-2c97-0004-0000-4c6564676572":new r.BleDeviceInfos(t.getDeviceModel({id:e.DeviceModelId.NANO_X}),"13d63400-2c97-0004-0000-4c6564676572","13d63400-2c97-0004-0002-4c6564676572","13d63400-2c97-0004-0003-4c6564676572","13d63400-2c97-0004-0001-4c6564676572"),"13d63400-2c97-6004-0000-4c6564676572":new r.BleDeviceInfos(t.getDeviceModel({id:e.DeviceModelId.STAX}),"13d63400-2c97-6004-0000-4c6564676572","13d63400-2c97-6004-0002-4c6564676572","13d63400-2c97-6004-0003-4c6564676572","13d63400-2c97-6004-0001-4c6564676572"),"13d63400-2c97-3004-0000-4c6564676572":new r.BleDeviceInfos(t.getDeviceModel({id:e.DeviceModelId.FLEX}),"13d63400-2c97-3004-0000-4c6564676572","13d63400-2c97-3004-0002-4c6564676572","13d63400-2c97-3004-0003-4c6564676572","13d63400-2c97-3004-0001-4c6564676572"),"13d63400-2c97-8004-0000-4c6564676572":new r.BleDeviceInfos(t.getDeviceModel({id:e.DeviceModelId.APEX}),"13d63400-2c97-8004-0000-4c6564676572","13d63400-2c97-8004-0002-4c6564676572","13d63400-2c97-8004-0003-4c6564676572","13d63400-2c97-8004-0001-4c6564676572")})})}),describe("getBluetoothServices",()=>{it("should return the bluetooth services",()=>{const c=new d.StaticDeviceModelDataSource().getBluetoothServices();expect(c).toStrictEqual(["13d63400-2c97-0004-0000-4c6564676572","13d63400-2c97-6004-0000-4c6564676572","13d63400-2c97-3004-0000-4c6564676572","13d63400-2c97-8004-0000-4c6564676572"])})}),describe("getBlockSize",()=>{const t={[e.DeviceModelId.NANO_S]:[{firmwareVersion:"1.0.0",expectedBlockSize:4096},{firmwareVersion:"1.0.0-rc1",expectedBlockSize:4096},{firmwareVersion:"2.0.0",expectedBlockSize:2048},{firmwareVersion:"2.0.0-rc1",expectedBlockSize:2048}],[e.DeviceModelId.NANO_SP]:[{firmwareVersion:"1.0.0",expectedBlockSize:32}],[e.DeviceModelId.NANO_X]:[{firmwareVersion:"1.0.0",expectedBlockSize:4096}],[e.DeviceModelId.STAX]:[{firmwareVersion:"1.0.0",expectedBlockSize:32}],[e.DeviceModelId.FLEX]:[{firmwareVersion:"1.0.0",expectedBlockSize:32}],[e.DeviceModelId.APEX]:[{firmwareVersion:"1.0.0",expectedBlockSize:32}]};describe.each(Object.entries(t))("Device Model: %s",(c,o)=>{it.each(o)("should return $expectedBlockSize for firmware version $firmwareVersion",({firmwareVersion:i,expectedBlockSize:n})=>{const l=new d.StaticDeviceModelDataSource().getDeviceModel({id:c});expect(l.getBlockSize({firmwareVersion:i})).toBe(n)})})})});
|
|
2
2
|
//# sourceMappingURL=StaticDeviceModelDataSource.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-model/data/StaticDeviceModelDataSource.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { BleDeviceInfos } from \"@api/device-model/model/BleDeviceInfos\";\n\nimport { StaticDeviceModelDataSource } from \"./StaticDeviceModelDataSource\";\n\ndescribe(\"StaticDeviceModelDataSource\", () => {\n describe(\"getAllDeviceModels\", () => {\n it(\"should return all device models\", () => {\n const dataSource = new StaticDeviceModelDataSource();\n const deviceModels = dataSource.getAllDeviceModels();\n\n expect(deviceModels.length).toEqual(6);\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.APEX }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_S }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_X }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.STAX }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.FLEX }),\n );\n });\n });\n\n describe(\"getDeviceModel\", () => {\n it(\"should return the associated device model\", () => {\n const dataSource = new StaticDeviceModelDataSource();\n\n const deviceModel1 = dataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n });\n expect(deviceModel1).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_S }),\n );\n\n const deviceModel2 = dataSource.getDeviceModel({\n id: DeviceModelId.NANO_SP,\n });\n expect(deviceModel2).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n\n const deviceModel3 = dataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n });\n expect(deviceModel3).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_X }),\n );\n\n const deviceModel4 = dataSource.getDeviceModel({\n id: DeviceModelId.STAX,\n });\n expect(deviceModel4).toEqual(\n expect.objectContaining({ id: DeviceModelId.STAX }),\n );\n\n const deviceModel5 = dataSource.getDeviceModel({\n id: DeviceModelId.FLEX,\n });\n expect(deviceModel5).toEqual(\n expect.objectContaining({ id: DeviceModelId.FLEX }),\n );\n });\n });\n\n describe(\"filterDeviceModels\", () => {\n it(\"should return the device models that match the given single parameter\", () => {\n const dataSource = new StaticDeviceModelDataSource();\n\n const deviceModels1 = dataSource.filterDeviceModels({ usbOnly: true });\n expect(deviceModels1.length).toEqual(2);\n expect(deviceModels1).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n expect(deviceModels1).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_S }),\n );\n\n const deviceModels2 = dataSource.filterDeviceModels({\n usbProductId: 0x10,\n });\n expect(deviceModels2.length).toEqual(1);\n expect(deviceModels2[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_S }),\n );\n\n const deviceModels3 = dataSource.filterDeviceModels({\n usbProductId: 0x40,\n });\n expect(deviceModels3.length).toEqual(1);\n expect(deviceModels3[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_X }),\n );\n\n const deviceModels4 = dataSource.filterDeviceModels({\n usbProductId: 0x50,\n });\n expect(deviceModels4.length).toEqual(1);\n expect(deviceModels4[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n\n const deviceModels5 = dataSource.filterDeviceModels({\n usbProductId: 0x60,\n });\n expect(deviceModels5.length).toEqual(1);\n expect(deviceModels5[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.STAX }),\n );\n\n const deviceModels6 = dataSource.filterDeviceModels({\n usbProductId: 0x00,\n });\n expect(deviceModels6.length).toEqual(0);\n });\n\n it(\"should return the device models that match the given multiple parameters\", () => {\n const dataSource = new StaticDeviceModelDataSource();\n\n const deviceModels1 = dataSource.filterDeviceModels({\n usbOnly: false,\n usbProductId: 0x40,\n });\n expect(deviceModels1.length).toEqual(1);\n expect(deviceModels1[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_X }),\n );\n\n const deviceModels2 = dataSource.filterDeviceModels({\n usbOnly: true,\n usbProductId: 0x50,\n });\n expect(deviceModels2.length).toEqual(1);\n expect(deviceModels2[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n\n // Nano S is usbOnly\n const deviceModels3 = dataSource.filterDeviceModels({\n usbOnly: false,\n usbProductId: 0x10,\n });\n expect(deviceModels3.length).toEqual(0);\n });\n });\n describe(\"getBluetoothServicesInfos\", () => {\n it(\"should return the ble service infos record\", () => {\n // given\n const dataSource = new StaticDeviceModelDataSource();\n // when\n const bleServiceInfos = dataSource.getBluetoothServicesInfos();\n // then\n expect(bleServiceInfos).toStrictEqual({\n \"13d63400-2c97-0004-0000-4c6564676572\": new BleDeviceInfos(\n dataSource.getDeviceModel({ id: DeviceModelId.NANO_X }),\n \"13d63400-2c97-0004-0000-4c6564676572\",\n \"13d63400-2c97-0004-0002-4c6564676572\",\n \"13d63400-2c97-0004-0003-4c6564676572\",\n \"13d63400-2c97-0004-0001-4c6564676572\",\n ),\n \"13d63400-2c97-6004-0000-4c6564676572\": new BleDeviceInfos(\n dataSource.getDeviceModel({ id: DeviceModelId.STAX }),\n \"13d63400-2c97-6004-0000-4c6564676572\",\n \"13d63400-2c97-6004-0002-4c6564676572\",\n \"13d63400-2c97-6004-0003-4c6564676572\",\n \"13d63400-2c97-6004-0001-4c6564676572\",\n ),\n \"13d63400-2c97-3004-0000-4c6564676572\": new BleDeviceInfos(\n dataSource.getDeviceModel({ id: DeviceModelId.FLEX }),\n \"13d63400-2c97-3004-0000-4c6564676572\",\n \"13d63400-2c97-3004-0002-4c6564676572\",\n \"13d63400-2c97-3004-0003-4c6564676572\",\n \"13d63400-2c97-3004-0001-4c6564676572\",\n ),\n \"13d63400-2c97-8004-0000-4c6564676572\": new BleDeviceInfos(\n dataSource.getDeviceModel({ id: DeviceModelId.APEX }),\n \"13d63400-2c97-8004-0000-4c6564676572\",\n \"13d63400-2c97-8004-0002-4c6564676572\",\n \"13d63400-2c97-8004-0003-4c6564676572\",\n \"13d63400-2c97-8004-0001-4c6564676572\",\n ),\n });\n });\n });\n describe(\"getBluetoothServices\", () => {\n it(\"should return the bluetooth services\", () => {\n // given\n const dataSource = new StaticDeviceModelDataSource();\n // when\n const bleServices = dataSource.getBluetoothServices();\n // then\n expect(bleServices).toStrictEqual([\n \"13d63400-2c97-0004-0000-4c6564676572\",\n \"13d63400-2c97-6004-0000-4c6564676572\",\n \"13d63400-2c97-3004-0000-4c6564676572\",\n \"13d63400-2c97-8004-0000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c,MAAO,CAAC,EACtD,uCACA,uCACA,uCACA,sCACF,EACA,uCAAwC,IAAI,iBAC1CA,EAAW,eAAe,CAAE,GAAI,gBAAc,IAAK,CAAC,EACpD,uCACA,uCACA,uCACA,sCACF,EACA,uCAAwC,IAAI,iBAC1CA,EAAW,eAAe,CAAE,GAAI,gBAAc,IAAK,CAAC,EACpD,uCACA,uCACA,uCACA,sCACF,EACA,uCAAwC,IAAI,iBAC1CA,EAAW,eAAe,CAAE,GAAI,gBAAc,IAAK,CAAC,EACpD,uCACA,uCACA,uCACA,sCACF,CACF,CAAC,CACH,CAAC,CACH,CAAC,EACD,SAAS,uBAAwB,IAAM,CACrC,GAAG,uCAAwC,IAAM,CAI/C,MAAMa,EAFa,IAAI,8BAA4B,EAEpB,qBAAqB,EAEpD,OAAOA,CAAW,EAAE,cAAc,CAChC,uCACA,uCACA,uCACA,sCACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
-
"names": ["import_DeviceModel", "import_BleDeviceInfos", "import_StaticDeviceModelDataSource", "deviceModels", "dataSource", "deviceModel1", "deviceModel2", "deviceModel3", "deviceModel4", "deviceModel5", "deviceModels1", "deviceModels2", "deviceModels3", "deviceModels4", "deviceModels5", "deviceModels6", "bleServiceInfos", "bleServices"]
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { BleDeviceInfos } from \"@api/device-model/model/BleDeviceInfos\";\n\nimport { StaticDeviceModelDataSource } from \"./StaticDeviceModelDataSource\";\n\ndescribe(\"StaticDeviceModelDataSource\", () => {\n describe(\"getAllDeviceModels\", () => {\n it(\"should return all device models\", () => {\n const dataSource = new StaticDeviceModelDataSource();\n const deviceModels = dataSource.getAllDeviceModels();\n\n expect(deviceModels.length).toEqual(6);\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.APEX }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_S }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_X }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.STAX }),\n );\n expect(deviceModels).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.FLEX }),\n );\n });\n });\n\n describe(\"getDeviceModel\", () => {\n it(\"should return the associated device model\", () => {\n const dataSource = new StaticDeviceModelDataSource();\n\n const deviceModel1 = dataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n });\n expect(deviceModel1).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_S }),\n );\n\n const deviceModel2 = dataSource.getDeviceModel({\n id: DeviceModelId.NANO_SP,\n });\n expect(deviceModel2).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n\n const deviceModel3 = dataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n });\n expect(deviceModel3).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_X }),\n );\n\n const deviceModel4 = dataSource.getDeviceModel({\n id: DeviceModelId.STAX,\n });\n expect(deviceModel4).toEqual(\n expect.objectContaining({ id: DeviceModelId.STAX }),\n );\n\n const deviceModel5 = dataSource.getDeviceModel({\n id: DeviceModelId.FLEX,\n });\n expect(deviceModel5).toEqual(\n expect.objectContaining({ id: DeviceModelId.FLEX }),\n );\n });\n });\n\n describe(\"filterDeviceModels\", () => {\n it(\"should return the device models that match the given single parameter\", () => {\n const dataSource = new StaticDeviceModelDataSource();\n\n const deviceModels1 = dataSource.filterDeviceModels({ usbOnly: true });\n expect(deviceModels1.length).toEqual(2);\n expect(deviceModels1).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n expect(deviceModels1).toContainEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_S }),\n );\n\n const deviceModels2 = dataSource.filterDeviceModels({\n usbProductId: 0x10,\n });\n expect(deviceModels2.length).toEqual(1);\n expect(deviceModels2[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_S }),\n );\n\n const deviceModels3 = dataSource.filterDeviceModels({\n usbProductId: 0x40,\n });\n expect(deviceModels3.length).toEqual(1);\n expect(deviceModels3[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_X }),\n );\n\n const deviceModels4 = dataSource.filterDeviceModels({\n usbProductId: 0x50,\n });\n expect(deviceModels4.length).toEqual(1);\n expect(deviceModels4[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n\n const deviceModels5 = dataSource.filterDeviceModels({\n usbProductId: 0x60,\n });\n expect(deviceModels5.length).toEqual(1);\n expect(deviceModels5[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.STAX }),\n );\n\n const deviceModels6 = dataSource.filterDeviceModels({\n usbProductId: 0x00,\n });\n expect(deviceModels6.length).toEqual(0);\n });\n\n it(\"should return the device models that match the given multiple parameters\", () => {\n const dataSource = new StaticDeviceModelDataSource();\n\n const deviceModels1 = dataSource.filterDeviceModels({\n usbOnly: false,\n usbProductId: 0x40,\n });\n expect(deviceModels1.length).toEqual(1);\n expect(deviceModels1[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_X }),\n );\n\n const deviceModels2 = dataSource.filterDeviceModels({\n usbOnly: true,\n usbProductId: 0x50,\n });\n expect(deviceModels2.length).toEqual(1);\n expect(deviceModels2[0]).toEqual(\n expect.objectContaining({ id: DeviceModelId.NANO_SP }),\n );\n\n // Nano S is usbOnly\n const deviceModels3 = dataSource.filterDeviceModels({\n usbOnly: false,\n usbProductId: 0x10,\n });\n expect(deviceModels3.length).toEqual(0);\n });\n });\n describe(\"getBluetoothServicesInfos\", () => {\n it(\"should return the ble service infos record\", () => {\n // given\n const dataSource = new StaticDeviceModelDataSource();\n // when\n const bleServiceInfos = dataSource.getBluetoothServicesInfos();\n // then\n expect(bleServiceInfos).toStrictEqual({\n \"13d63400-2c97-0004-0000-4c6564676572\": new BleDeviceInfos(\n dataSource.getDeviceModel({ id: DeviceModelId.NANO_X }),\n \"13d63400-2c97-0004-0000-4c6564676572\",\n \"13d63400-2c97-0004-0002-4c6564676572\",\n \"13d63400-2c97-0004-0003-4c6564676572\",\n \"13d63400-2c97-0004-0001-4c6564676572\",\n ),\n \"13d63400-2c97-6004-0000-4c6564676572\": new BleDeviceInfos(\n dataSource.getDeviceModel({ id: DeviceModelId.STAX }),\n \"13d63400-2c97-6004-0000-4c6564676572\",\n \"13d63400-2c97-6004-0002-4c6564676572\",\n \"13d63400-2c97-6004-0003-4c6564676572\",\n \"13d63400-2c97-6004-0001-4c6564676572\",\n ),\n \"13d63400-2c97-3004-0000-4c6564676572\": new BleDeviceInfos(\n dataSource.getDeviceModel({ id: DeviceModelId.FLEX }),\n \"13d63400-2c97-3004-0000-4c6564676572\",\n \"13d63400-2c97-3004-0002-4c6564676572\",\n \"13d63400-2c97-3004-0003-4c6564676572\",\n \"13d63400-2c97-3004-0001-4c6564676572\",\n ),\n \"13d63400-2c97-8004-0000-4c6564676572\": new BleDeviceInfos(\n dataSource.getDeviceModel({ id: DeviceModelId.APEX }),\n \"13d63400-2c97-8004-0000-4c6564676572\",\n \"13d63400-2c97-8004-0002-4c6564676572\",\n \"13d63400-2c97-8004-0003-4c6564676572\",\n \"13d63400-2c97-8004-0001-4c6564676572\",\n ),\n });\n });\n });\n describe(\"getBluetoothServices\", () => {\n it(\"should return the bluetooth services\", () => {\n // given\n const dataSource = new StaticDeviceModelDataSource();\n // when\n const bleServices = dataSource.getBluetoothServices();\n // then\n expect(bleServices).toStrictEqual([\n \"13d63400-2c97-0004-0000-4c6564676572\",\n \"13d63400-2c97-6004-0000-4c6564676572\",\n \"13d63400-2c97-3004-0000-4c6564676572\",\n \"13d63400-2c97-8004-0000-4c6564676572\",\n ]);\n });\n });\n\n describe(\"getBlockSize\", () => {\n const testData: Record<\n DeviceModelId,\n Array<{ firmwareVersion: string; expectedBlockSize: number }>\n > = {\n [DeviceModelId.NANO_S]: [\n { firmwareVersion: \"1.0.0\", expectedBlockSize: 4 * 1024 },\n { firmwareVersion: \"1.0.0-rc1\", expectedBlockSize: 4 * 1024 },\n { firmwareVersion: \"2.0.0\", expectedBlockSize: 2 * 1024 },\n { firmwareVersion: \"2.0.0-rc1\", expectedBlockSize: 2 * 1024 },\n ],\n [DeviceModelId.NANO_SP]: [\n { firmwareVersion: \"1.0.0\", expectedBlockSize: 32 },\n ],\n [DeviceModelId.NANO_X]: [\n { firmwareVersion: \"1.0.0\", expectedBlockSize: 4 * 1024 },\n ],\n [DeviceModelId.STAX]: [\n { firmwareVersion: \"1.0.0\", expectedBlockSize: 32 },\n ],\n [DeviceModelId.FLEX]: [\n { firmwareVersion: \"1.0.0\", expectedBlockSize: 32 },\n ],\n [DeviceModelId.APEX]: [\n { firmwareVersion: \"1.0.0\", expectedBlockSize: 32 },\n ],\n };\n\n describe.each(Object.entries(testData))(\n \"Device Model: %s\",\n (deviceModelId, scenarios) => {\n it.each(scenarios)(\n \"should return $expectedBlockSize for firmware version $firmwareVersion\",\n ({ firmwareVersion, expectedBlockSize }) => {\n const deviceModel =\n new StaticDeviceModelDataSource().getDeviceModel({\n id: deviceModelId as DeviceModelId,\n });\n expect(deviceModel.getBlockSize({ firmwareVersion })).toBe(\n expectedBlockSize,\n );\n },\n );\n },\n );\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAA8B,mCAC9BC,EAA+B,kDAE/BC,EAA4C,yCAE5C,SAAS,8BAA+B,IAAM,CAC5C,SAAS,qBAAsB,IAAM,CACnC,GAAG,kCAAmC,IAAM,CAE1C,MAAMC,EADa,IAAI,8BAA4B,EACnB,mBAAmB,EAEnD,OAAOA,EAAa,MAAM,EAAE,QAAQ,CAAC,EACrC,OAAOA,CAAY,EAAE,eACnB,OAAO,iBAAiB,CAAE,GAAI,gBAAc,IAAK,CAAC,CACpD,EACA,OAAOA,CAAY,EAAE,eACnB,OAAO,iBAAiB,C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C,GAAG,uCAAwC,IAAM,CAI/C,MAAMa,EAFa,IAAI,8BAA4B,EAEpB,qBAAqB,EAEpD,OAAOA,CAAW,EAAE,cAAc,CAChC,uCACA,uCACA,uCACA,sCACF,CAAC,CACH,CAAC,CACH,CAAC,EAED,SAAS,eAAgB,IAAM,CAC7B,MAAMC,EAGF,CACF,CAAC,gBAAc,MAAM,EAAG,CACtB,CAAE,gBAAiB,QAAS,kBAAmB,IAAS,EACxD,CAAE,gBAAiB,YAAa,kBAAmB,IAAS,EAC5D,CAAE,gBAAiB,QAAS,kBAAmB,IAAS,EACxD,CAAE,gBAAiB,YAAa,kBAAmB,IAAS,CAC9D,EACA,CAAC,gBAAc,OAAO,EAAG,CACvB,CAAE,gBAAiB,QAAS,kBAAmB,EAAG,CACpD,EACA,CAAC,gBAAc,MAAM,EAAG,CACtB,CAAE,gBAAiB,QAAS,kBAAmB,IAAS,CAC1D,EACA,CAAC,gBAAc,IAAI,EAAG,CACpB,CAAE,gBAAiB,QAAS,kBAAmB,EAAG,CACpD,EACA,CAAC,gBAAc,IAAI,EAAG,CACpB,CAAE,gBAAiB,QAAS,kBAAmB,EAAG,CACpD,EACA,CAAC,gBAAc,IAAI,EAAG,CACpB,CAAE,gBAAiB,QAAS,kBAAmB,EAAG,CACpD,CACF,EAEA,SAAS,KAAK,OAAO,QAAQA,CAAQ,CAAC,EACpC,mBACA,CAACC,EAAeC,IAAc,CAC5B,GAAG,KAAKA,CAAS,EACf,yEACA,CAAC,CAAE,gBAAAC,EAAiB,kBAAAC,CAAkB,IAAM,CAC1C,MAAMC,EACJ,IAAI,8BAA4B,EAAE,eAAe,CAC/C,GAAIJ,CACN,CAAC,EACH,OAAOI,EAAY,aAAa,CAAE,gBAAAF,CAAgB,CAAC,CAAC,EAAE,KACpDC,CACF,CACF,CACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_DeviceModel", "import_BleDeviceInfos", "import_StaticDeviceModelDataSource", "deviceModels", "dataSource", "deviceModel1", "deviceModel2", "deviceModel3", "deviceModel4", "deviceModel5", "deviceModels1", "deviceModels2", "deviceModels3", "deviceModels4", "deviceModels5", "deviceModels6", "bleServiceInfos", "bleServices", "testData", "deviceModelId", "scenarios", "firmwareVersion", "expectedBlockSize", "deviceModel"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var o in e)r(t,o,{get:e[o],enumerable:!0})},b=(t,e,o,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of s(e))!n.call(t,i)&&i!==o&&r(t,i,{get:()=>e[i],enumerable:!(d=u(e,i))||d.enumerable});return t};var c=t=>b(r({},"__esModule",{value:!0}),t);var a={};m(a,{TransportDeviceModel:()=>l});module.exports=c(a);class l{id;productName;usbProductId;bootloaderUsbProductId;usbOnly;memorySize;getBlockSize;masks;bluetoothSpec;constructor(e){this.id=e.id,this.productName=e.productName,this.usbProductId=e.usbProductId,this.bootloaderUsbProductId=e.bootloaderUsbProductId,this.usbOnly=e.usbOnly,this.memorySize=e.memorySize,this.getBlockSize=e.getBlockSize,this.masks=e.masks,this.bluetoothSpec=e.bluetoothSpec}}0&&(module.exports={TransportDeviceModel});
|
|
2
2
|
//# sourceMappingURL=DeviceModel.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-model/model/DeviceModel.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["DeviceModel_exports", "__export", "TransportDeviceModel", "__toCommonJS", "
|
|
4
|
+
"sourcesContent": ["import { type DeviceModelId } from \"@api/device/DeviceModel\";\n\ntype DeviceModel = {\n /** Identifier of the device model */\n id: DeviceModelId;\n\n /** Displayed name of the device model */\n productName: string;\n\n /** USB product ID of the device model */\n usbProductId: number;\n\n /** USB product ID of the device model, in bootloader mode */\n bootloaderUsbProductId: number;\n\n /** Whether the device model is only USB-based */\n usbOnly: boolean;\n\n /** Memory size of the device model, in bytes */\n memorySize: number;\n\n /**\n * Function to get the block size of the device model, in bytes\n * Blocks are the smallest units of memory that can be written to the device.\n * The block size can be different for different firmware versions.\n */\n getBlockSize: (p: { firmwareVersion: string }) => number;\n\n /**\n * When applying 0xffff0000 to a device target id (obtained from the getOSVersion command),\n * the result will be one of the masks for the device model.\n */\n masks: number[];\n\n /**\n * Bluetooth specifications for the device model.\n * Only available for devices that support Bluetooth.\n */\n bluetoothSpec?: {\n serviceUuid: string;\n writeUuid: string;\n writeCmdUuid: string;\n notifyUuid: string;\n }[];\n};\n\n/**\n * The info of a device model\n */\nexport class TransportDeviceModel implements DeviceModel {\n id: DeviceModelId;\n productName: string;\n usbProductId: number;\n bootloaderUsbProductId: number;\n usbOnly: boolean;\n memorySize: number;\n getBlockSize: (p: { firmwareVersion: string }) => number;\n masks: number[];\n bluetoothSpec?: {\n serviceUuid: string;\n writeUuid: string;\n writeCmdUuid: string;\n notifyUuid: string;\n }[];\n\n constructor(props: DeviceModel) {\n this.id = props.id;\n this.productName = props.productName;\n this.usbProductId = props.usbProductId;\n this.bootloaderUsbProductId = props.bootloaderUsbProductId;\n this.usbOnly = props.usbOnly;\n this.memorySize = props.memorySize;\n this.getBlockSize = props.getBlockSize;\n this.masks = props.masks;\n this.bluetoothSpec = props.bluetoothSpec;\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAiDO,MAAME,CAA4C,CACvD,GACA,YACA,aACA,uBACA,QACA,WACA,aACA,MACA,cAOA,YAAYE,EAAoB,CAC9B,KAAK,GAAKA,EAAM,GAChB,KAAK,YAAcA,EAAM,YACzB,KAAK,aAAeA,EAAM,aAC1B,KAAK,uBAAyBA,EAAM,uBACpC,KAAK,QAAUA,EAAM,QACrB,KAAK,WAAaA,EAAM,WACxB,KAAK,aAAeA,EAAM,aAC1B,KAAK,MAAQA,EAAM,MACnB,KAAK,cAAgBA,EAAM,aAC7B,CACF",
|
|
6
|
+
"names": ["DeviceModel_exports", "__export", "TransportDeviceModel", "__toCommonJS", "props"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var s=(e,o)=>{for(var r in o)i(e,r,{get:o[r],enumerable:!0})},m=(e,o,r,
|
|
1
|
+
"use strict";var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var s=(e,o)=>{for(var r in o)i(e,r,{get:o[r],enumerable:!0})},m=(e,o,r,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let d of l(o))!a.call(e,d)&&d!==r&&i(e,d,{get:()=>o[d],enumerable:!(t=u(o,d))||t.enumerable});return e};var n=e=>m(i({},"__esModule",{value:!0}),e);var b={};s(b,{deviceModelStubBuilder:()=>p});module.exports=n(b);var c=require("../../device/DeviceModel");function p(e={}){return{id:c.DeviceModelId.NANO_X,productName:"Ledger Nano X",usbProductId:64,bootloaderUsbProductId:4,usbOnly:!1,memorySize:2*1024*1024,getBlockSize:()=>4*1024,masks:[855638016],bluetoothSpec:[{serviceUuid:"13d63400-2c97-0004-0000-4c6564676572",notifyUuid:"13d63400-2c97-0004-0001-4c6564676572",writeUuid:"13d63400-2c97-0004-0002-4c6564676572",writeCmdUuid:"13d63400-2c97-0004-0003-4c6564676572"}],...e}}0&&(module.exports={deviceModelStubBuilder});
|
|
2
2
|
//# sourceMappingURL=DeviceModel.stub.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-model/model/DeviceModel.stub.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { type TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\n\nexport function deviceModelStubBuilder(\n props: Partial<TransportDeviceModel> = {},\n): TransportDeviceModel {\n return {\n id: DeviceModelId.NANO_X,\n productName: \"Ledger Nano X\",\n usbProductId: 0x40,\n bootloaderUsbProductId: 0x0004,\n usbOnly: false,\n memorySize: 2 * 1024 * 1024,\n
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA8B,mCAGvB,SAASF,EACdG,EAAuC,CAAC,EAClB,CACtB,MAAO,CACL,GAAI,gBAAc,OAClB,YAAa,gBACb,aAAc,GACd,uBAAwB,EACxB,QAAS,GACT,WAAY,EAAI,KAAO,KACvB,
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { type TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\n\nexport function deviceModelStubBuilder(\n props: Partial<TransportDeviceModel> = {},\n): TransportDeviceModel {\n return {\n id: DeviceModelId.NANO_X,\n productName: \"Ledger Nano X\",\n usbProductId: 0x40,\n bootloaderUsbProductId: 0x0004,\n usbOnly: false,\n memorySize: 2 * 1024 * 1024,\n getBlockSize: () => 4 * 1024,\n masks: [0x33000000],\n bluetoothSpec: [\n {\n serviceUuid: \"13d63400-2c97-0004-0000-4c6564676572\",\n notifyUuid: \"13d63400-2c97-0004-0001-4c6564676572\",\n writeUuid: \"13d63400-2c97-0004-0002-4c6564676572\",\n writeCmdUuid: \"13d63400-2c97-0004-0003-4c6564676572\",\n },\n ],\n ...props,\n };\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA8B,mCAGvB,SAASF,EACdG,EAAuC,CAAC,EAClB,CACtB,MAAO,CACL,GAAI,gBAAc,OAClB,YAAa,gBACb,aAAc,GACd,uBAAwB,EACxB,QAAS,GACT,WAAY,EAAI,KAAO,KACvB,aAAc,IAAM,EAAI,KACxB,MAAO,CAAC,SAAU,EAClB,cAAe,CACb,CACE,YAAa,uCACb,WAAY,uCACZ,UAAW,uCACX,aAAc,sCAChB,CACF,EACA,GAAGA,CACL,CACF",
|
|
6
6
|
"names": ["DeviceModel_stub_exports", "__export", "deviceModelStubBuilder", "__toCommonJS", "import_DeviceModel", "props"]
|
|
7
7
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
65
65
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
66
66
|
},
|
|
67
|
-
"version": "0.
|
|
67
|
+
"version": "0.13.0"
|
|
68
68
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{UnknownDAError as
|
|
1
|
+
import{UnknownDAError as d}from"../../device-action/os/Errors";import{DeviceSessionStateType as u}from"../../device-session/DeviceSessionState";class M{constructor(e,t){this.api=e;this.args=t;this.deviceModel=e.getDeviceModel()}deviceModel;run(){const e=this.api.getDeviceSessionState();if(e.sessionStateType===u.Connected)return{error:new d("Invalid device state")};const{firmwareUpdateContext:t,customImage:r,firmwareVersion:o,installedLanguages:n,installedApps:a}=e;if(t===void 0||r===void 0||o===void 0||n===void 0)return{error:new d("Device metadata not fetched")};const{blockSize:i,totalMemoryBlocks:l}=this.getMemoryConstants(o),c=this.getCurrentMemoryBlocksUsage({firmwareUpdateContext:t,customImage:r,installedApps:a,installedLanguages:n,blockSize:i}),m=this.getInstallPlanMemoryBlocksUsage(this.args.installPlan,i);return{outOfMemory:c+m>l}}getMemoryConstants(e){const t=this.deviceModel.getBlockSize({firmwareVersion:e.os}),r=Math.floor(this.deviceModel.memorySize/t);return{blockSize:t,totalMemoryBlocks:r}}getCurrentMemoryBlocksUsage({firmwareUpdateContext:e,customImage:t,installedApps:r,installedLanguages:o,blockSize:n}){const a=s=>Math.ceil(s/n),i=a(e.currentFirmware.bytes||0),l=a(t.size||0),c=r.reduce((s,p)=>s+a(p.bytes||0),0),m=o.reduce((s,p)=>s+a(p.size),0);return i+l+c+m}getInstallPlanMemoryBlocksUsage(e,t){const r=o=>Math.ceil(o/t);return e.reduce((o,n)=>o+r(n.bytes||0),0)}}export{M as PredictOutOfMemoryTask};
|
|
2
2
|
//# sourceMappingURL=PredictOutOfMemoryTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-action/task/PredictOutOfMemoryTask.ts"],
|
|
4
|
-
"sourcesContent": ["import type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nexport type PredictOutOfMemoryTaskArgs = {\n installPlan: Application[];\n};\n\nexport type PredictOutOfMemoryTaskResult =\n | {\n outOfMemory: boolean;\n }\n | {\n error: UnknownDAError;\n };\n\nexport class PredictOutOfMemoryTask {\n private readonly
|
|
5
|
-
"mappings": "AACA,OAAS,kBAAAA,MAAsB,+
|
|
6
|
-
"names": ["UnknownDAError", "DeviceSessionStateType", "PredictOutOfMemoryTask", "api", "args", "
|
|
4
|
+
"sourcesContent": ["import type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { type TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport {\n type CustomImage,\n DeviceSessionStateType,\n type FirmwareUpdateContext,\n type FirmwareVersion,\n type InstalledLanguagePackage,\n} from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nexport type PredictOutOfMemoryTaskArgs = {\n installPlan: Application[];\n};\n\nexport type PredictOutOfMemoryTaskResult =\n | {\n outOfMemory: boolean;\n }\n | {\n error: UnknownDAError;\n };\n\nexport class PredictOutOfMemoryTask {\n private readonly deviceModel: TransportDeviceModel;\n\n constructor(\n private readonly api: InternalApi,\n private readonly args: PredictOutOfMemoryTaskArgs,\n ) {\n this.deviceModel = api.getDeviceModel();\n }\n\n run(): PredictOutOfMemoryTaskResult {\n const deviceState = this.api.getDeviceSessionState();\n\n if (deviceState.sessionStateType === DeviceSessionStateType.Connected) {\n return { error: new UnknownDAError(\"Invalid device state\") };\n }\n\n const {\n firmwareUpdateContext,\n customImage,\n firmwareVersion,\n installedLanguages,\n installedApps,\n } = deviceState;\n\n if (\n firmwareUpdateContext === undefined ||\n customImage === undefined ||\n firmwareVersion === undefined ||\n installedLanguages === undefined\n ) {\n return { error: new UnknownDAError(\"Device metadata not fetched\") };\n }\n\n const { blockSize, totalMemoryBlocks } =\n this.getMemoryConstants(firmwareVersion);\n\n const currentMemoryBlocksUsage = this.getCurrentMemoryBlocksUsage({\n firmwareUpdateContext,\n customImage,\n installedApps,\n installedLanguages,\n blockSize,\n });\n\n const installPlanBlocksUsage = this.getInstallPlanMemoryBlocksUsage(\n this.args.installPlan,\n blockSize,\n );\n\n return {\n outOfMemory:\n currentMemoryBlocksUsage + installPlanBlocksUsage > totalMemoryBlocks,\n };\n }\n\n private getMemoryConstants(firmwareVersion: FirmwareVersion): {\n blockSize: number;\n totalMemoryBlocks: number;\n } {\n const blockSize = this.deviceModel.getBlockSize({\n firmwareVersion: firmwareVersion.os,\n });\n const totalMemoryBlocks = Math.floor(\n this.deviceModel.memorySize / blockSize,\n );\n return { blockSize, totalMemoryBlocks };\n }\n\n private getCurrentMemoryBlocksUsage({\n firmwareUpdateContext,\n customImage,\n installedApps,\n installedLanguages,\n blockSize,\n }: {\n firmwareUpdateContext: FirmwareUpdateContext;\n customImage: CustomImage;\n installedApps: Application[];\n installedLanguages: InstalledLanguagePackage[];\n blockSize: number;\n }): number {\n const bytesToBlocks = (size: number) => Math.ceil(size / blockSize);\n const firmwareBlocks = bytesToBlocks(\n firmwareUpdateContext.currentFirmware.bytes || 0,\n );\n const customImageBlocks = bytesToBlocks(customImage.size || 0);\n const applicationsBlocks = installedApps.reduce(\n (size, app) => size + bytesToBlocks(app.bytes || 0),\n 0,\n );\n const languagesBlocks = installedLanguages.reduce(\n (size, lang) => size + bytesToBlocks(lang.size),\n 0,\n );\n return (\n firmwareBlocks + customImageBlocks + applicationsBlocks + languagesBlocks\n );\n }\n\n private getInstallPlanMemoryBlocksUsage(\n installPlan: Application[],\n blockSize: number,\n ): number {\n const bytesToBlocks = (size: number) => Math.ceil(size / blockSize);\n return installPlan.reduce(\n (size, app) => size + bytesToBlocks(app.bytes || 0),\n 0,\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAAS,kBAAAA,MAAsB,+BAE/B,OAEE,0BAAAC,MAIK,yCAeA,MAAMC,CAAuB,CAGlC,YACmBC,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,EAEjB,KAAK,YAAcD,EAAI,eAAe,CACxC,CAPiB,YASjB,KAAoC,CAClC,MAAME,EAAc,KAAK,IAAI,sBAAsB,EAEnD,GAAIA,EAAY,mBAAqBJ,EAAuB,UAC1D,MAAO,CAAE,MAAO,IAAID,EAAe,sBAAsB,CAAE,EAG7D,KAAM,CACJ,sBAAAM,EACA,YAAAC,EACA,gBAAAC,EACA,mBAAAC,EACA,cAAAC,CACF,EAAIL,EAEJ,GACEC,IAA0B,QAC1BC,IAAgB,QAChBC,IAAoB,QACpBC,IAAuB,OAEvB,MAAO,CAAE,MAAO,IAAIT,EAAe,6BAA6B,CAAE,EAGpE,KAAM,CAAE,UAAAW,EAAW,kBAAAC,CAAkB,EACnC,KAAK,mBAAmBJ,CAAe,EAEnCK,EAA2B,KAAK,4BAA4B,CAChE,sBAAAP,EACA,YAAAC,EACA,cAAAG,EACA,mBAAAD,EACA,UAAAE,CACF,CAAC,EAEKG,EAAyB,KAAK,gCAClC,KAAK,KAAK,YACVH,CACF,EAEA,MAAO,CACL,YACEE,EAA2BC,EAAyBF,CACxD,CACF,CAEQ,mBAAmBJ,EAGzB,CACA,MAAMG,EAAY,KAAK,YAAY,aAAa,CAC9C,gBAAiBH,EAAgB,EACnC,CAAC,EACKI,EAAoB,KAAK,MAC7B,KAAK,YAAY,WAAaD,CAChC,EACA,MAAO,CAAE,UAAAA,EAAW,kBAAAC,CAAkB,CACxC,CAEQ,4BAA4B,CAClC,sBAAAN,EACA,YAAAC,EACA,cAAAG,EACA,mBAAAD,EACA,UAAAE,CACF,EAMW,CACT,MAAMI,EAAiBC,GAAiB,KAAK,KAAKA,EAAOL,CAAS,EAC5DM,EAAiBF,EACrBT,EAAsB,gBAAgB,OAAS,CACjD,EACMY,EAAoBH,EAAcR,EAAY,MAAQ,CAAC,EACvDY,EAAqBT,EAAc,OACvC,CAACM,EAAMI,IAAQJ,EAAOD,EAAcK,EAAI,OAAS,CAAC,EAClD,CACF,EACMC,EAAkBZ,EAAmB,OACzC,CAACO,EAAMM,IAASN,EAAOD,EAAcO,EAAK,IAAI,EAC9C,CACF,EACA,OACEL,EAAiBC,EAAoBC,EAAqBE,CAE9D,CAEQ,gCACNE,EACAZ,EACQ,CACR,MAAMI,EAAiBC,GAAiB,KAAK,KAAKA,EAAOL,CAAS,EAClE,OAAOY,EAAY,OACjB,CAACP,EAAMI,IAAQJ,EAAOD,EAAcK,EAAI,OAAS,CAAC,EAClD,CACF,CACF,CACF",
|
|
6
|
+
"names": ["UnknownDAError", "DeviceSessionStateType", "PredictOutOfMemoryTask", "api", "args", "deviceState", "firmwareUpdateContext", "customImage", "firmwareVersion", "installedLanguages", "installedApps", "blockSize", "totalMemoryBlocks", "currentMemoryBlocksUsage", "installPlanBlocksUsage", "bytesToBlocks", "size", "firmwareBlocks", "customImageBlocks", "applicationsBlocks", "app", "languagesBlocks", "lang", "installPlan"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DeviceStatus as n}from"../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as
|
|
1
|
+
import i from"semver";import{DeviceStatus as n}from"../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as c}from"../../device-action/__test-utils__/makeInternalApi";import{UnknownDAError as r}from"../../device-action/os/Errors";import{DeviceSessionStateType as s}from"../../device-session/DeviceSessionState";import{PredictOutOfMemoryTask as a}from"./PredictOutOfMemoryTask";describe("PredictOutOfMemoryTask",()=>{const e=c();beforeEach(()=>{vi.clearAllMocks(),e.getDeviceModel.mockReturnValue({memorySize:1569792,getBlockSize:()=>32})}),it("Success enough memory",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:n.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:397824}},customImage:{size:51893},installedApps:[{bytes:305442},{bytes:514598},{bytes:271583}],installedLanguages:[{id:1,size:20480}],firmwareVersion:{os:"2.0.0"}});const t=new a(e,{installPlan:[{bytes:1324},{bytes:6559}]}).run();expect(t).toStrictEqual({outOfMemory:!1})}),it("Success not enough memory",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:n.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:397824}},customImage:{size:51893},installedApps:[{bytes:305442},{bytes:514598},{bytes:271583}],installedLanguages:[{id:1,size:20480}],firmwareVersion:{os:"2.0.0"}});const t=new a(e,{installPlan:[{bytes:1324},{bytes:6559},{bytes:1}]}).run();expect(t).toStrictEqual({outOfMemory:!0})}),it("Success enough memory (recent Nano S, 2kB block size)",()=>{e.getDeviceModel.mockReturnValueOnce({memorySize:12*1024,getBlockSize:({firmwareVersion:o})=>i.lt(i.coerce(o)??"","2.0.0")?4*1024:2*1024}),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:n.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:6*1024}},customImage:{size:0},installedApps:[],installedLanguages:[],firmwareVersion:{os:"2.0.0"}});const t=new a(e,{installPlan:[{bytes:6*1024}]}).run();expect(t).toStrictEqual({outOfMemory:!1})}),it("Success not enough memory (old Nano S, 4kB block size)",()=>{e.getDeviceModel.mockReturnValueOnce({memorySize:12*1024,getBlockSize:({firmwareVersion:o})=>i.lt(i.coerce(o)??"","2.0.0")?4*1024:2*1024}),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:n.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:6*1024}},customImage:{size:0},installedApps:[],installedLanguages:[],firmwareVersion:{os:"1.0.0"}});const t=new a(e,{installPlan:[{bytes:6*1024}]}).run();expect(t).toStrictEqual({outOfMemory:!0})}),it("Success undefined sizes",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:n.CONNECTED,firmwareUpdateContext:{currentFirmware:{bytes:397824}},customImage:{},installedApps:[{bytes:305442},{bytes:null},{bytes:271583}],installedLanguages:[],firmwareVersion:{os:"2.0.0"}});const t=new a(e,{installPlan:[{bytes:1324},{bytes:6559}]}).run();expect(t).toStrictEqual({outOfMemory:!1})}),it("Error when device is in incorrect state",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:s.Connected,deviceStatus:n.CONNECTED});const t=new a(e,{installPlan:[{bytes:1324}]}).run();expect(t).toStrictEqual({error:new r("Invalid device state")})}),it("Error when device session was not populated",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:n.CONNECTED,installedApps:[]});const t=new a(e,{installPlan:[{bytes:1324}]}).run();expect(t).toStrictEqual({error:new r("Device metadata not fetched")})})});
|
|
2
2
|
//# sourceMappingURL=PredictOutOfMemoryTask.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-action/task/PredictOutOfMemoryTask.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport type { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport type { DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\nimport type { FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport { PredictOutOfMemoryTask } from \"./PredictOutOfMemoryTask\";\n\ndescribe(\"PredictOutOfMemoryTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.clearAllMocks();\n apiMock.getDeviceModel.mockReturnValue({\n memorySize: 1569792,\n
|
|
5
|
-
"mappings": "AAAA,OAAS,
|
|
6
|
-
"names": ["DeviceStatus", "makeDeviceActionInternalApiMock", "UnknownDAError", "DeviceSessionStateType", "PredictOutOfMemoryTask", "apiMock", "result"]
|
|
4
|
+
"sourcesContent": ["import semver from \"semver\";\n\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport type { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport type { DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\nimport type { FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport { PredictOutOfMemoryTask } from \"./PredictOutOfMemoryTask\";\n\ndescribe(\"PredictOutOfMemoryTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.clearAllMocks();\n apiMock.getDeviceModel.mockReturnValue({\n memorySize: 1569792,\n getBlockSize: () => 32,\n } as unknown as TransportDeviceModel);\n });\n\n it(\"Success enough memory\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 397824 } as FinalFirmware,\n },\n customImage: { size: 51893 },\n installedApps: [\n { bytes: 305442 },\n { bytes: 514598 },\n { bytes: 271583 },\n ] as unknown as Application[],\n installedLanguages: [{ id: 1, size: 20480 }],\n firmwareVersion: { os: \"2.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [\n { bytes: 1324 },\n { bytes: 6559 },\n ] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n outOfMemory: false,\n });\n });\n\n it(\"Success not enough memory\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 397824 } as FinalFirmware,\n },\n customImage: { size: 51893 },\n installedApps: [\n { bytes: 305442 },\n { bytes: 514598 },\n { bytes: 271583 },\n ] as unknown as Application[],\n installedLanguages: [{ id: 1, size: 20480 }],\n firmwareVersion: { os: \"2.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [\n { bytes: 1324 },\n { bytes: 6559 },\n { bytes: 1 },\n ] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n outOfMemory: true,\n });\n });\n\n it(\"Success enough memory (recent Nano S, 2kB block size)\", () => {\n // GIVEN\n apiMock.getDeviceModel.mockReturnValueOnce({\n memorySize: 12 * 1024,\n getBlockSize: ({ firmwareVersion }: { firmwareVersion: string }) => {\n return semver.lt(semver.coerce(firmwareVersion) ?? \"\", \"2.0.0\")\n ? 4 * 1024\n : 2 * 1024;\n },\n } as unknown as TransportDeviceModel);\n\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 6 * 1024 } as FinalFirmware,\n },\n customImage: { size: 0 },\n installedApps: [],\n installedLanguages: [],\n firmwareVersion: { os: \"2.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [{ bytes: 6 * 1024 }] as unknown as Application[],\n }).run();\n\n // THEN\n // 6x2kB blocks of total memory (12kB total)\n // -3*2kB block for firmware (to fit 6kB)\n // -3*2kB block for install plan (to fit 6kB)\n // = 0 blocks left, enough memory\n expect(result).toStrictEqual({\n outOfMemory: false,\n });\n });\n\n it(\"Success not enough memory (old Nano S, 4kB block size)\", () => {\n // GIVEN\n apiMock.getDeviceModel.mockReturnValueOnce({\n memorySize: 12 * 1024,\n getBlockSize: ({ firmwareVersion }: { firmwareVersion: string }) => {\n return semver.lt(semver.coerce(firmwareVersion) ?? \"\", \"2.0.0\")\n ? 4 * 1024\n : 2 * 1024;\n },\n } as unknown as TransportDeviceModel);\n\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 6 * 1024 } as FinalFirmware,\n },\n customImage: { size: 0 },\n installedApps: [],\n installedLanguages: [],\n firmwareVersion: { os: \"1.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [{ bytes: 6 * 1024 }] as unknown as Application[],\n }).run();\n\n // THEN\n // 3x4kB blocks of total memory (12kB total)\n // -2x4kB block for firmware (to fit 6kB)\n // -2x4kB blocks for install plan (to fit 6kB)\n // = -1 block left, not enough memory\n expect(result).toStrictEqual({\n outOfMemory: true,\n });\n });\n\n it(\"Success undefined sizes\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: { bytes: 397824 } as FinalFirmware,\n },\n customImage: {},\n installedApps: [\n { bytes: 305442 },\n { bytes: null },\n { bytes: 271583 },\n ] as unknown as Application[],\n installedLanguages: [],\n firmwareVersion: { os: \"2.0.0\" },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [\n { bytes: 1324 },\n { bytes: 6559 },\n ] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n outOfMemory: false,\n });\n });\n\n it(\"Error when device is in incorrect state\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n } as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [{ bytes: 1324 }] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Invalid device state\"),\n });\n });\n\n it(\"Error when device session was not populated\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new PredictOutOfMemoryTask(apiMock, {\n installPlan: [{ bytes: 1324 }] as unknown as Application[],\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Device metadata not fetched\"),\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAY,SAEnB,OAAS,gBAAAC,MAAoB,2BAC7B,OAAS,mCAAAC,MAAuC,oDAChD,OAAS,kBAAAC,MAAsB,+BAG/B,OAAS,0BAAAC,MAA8B,yCAIvC,OAAS,0BAAAC,MAA8B,2BAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,EAAUJ,EAAgC,EAEhD,WAAW,IAAM,CACf,GAAG,cAAc,EACjBI,EAAQ,eAAe,gBAAgB,CACrC,WAAY,QACZ,aAAc,IAAM,EACtB,CAAoC,CACtC,CAAC,EAED,GAAG,wBAAyB,IAAM,CAEhCA,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBF,EAAuB,0BACzC,aAAcH,EAAa,UAC3B,sBAAuB,CACrB,gBAAiB,CAAE,MAAO,MAAO,CACnC,EACA,YAAa,CAAE,KAAM,KAAM,EAC3B,cAAe,CACb,CAAE,MAAO,MAAO,EAChB,CAAE,MAAO,MAAO,EAChB,CAAE,MAAO,MAAO,CAClB,EACA,mBAAoB,CAAC,CAAE,GAAI,EAAG,KAAM,KAAM,CAAC,EAC3C,gBAAiB,CAAE,GAAI,OAAQ,CACjC,CAAkC,EAGlC,MAAMM,EAAS,IAAIF,EAAuBC,EAAS,CACjD,YAAa,CACX,CAAE,MAAO,IAAK,EACd,CAAE,MAAO,IAAK,CAChB,CACF,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,YAAa,EACf,CAAC,CACH,CAAC,EAED,GAAG,4BAA6B,IAAM,CAEpCD,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBF,EAAuB,0BACzC,aAAcH,EAAa,UAC3B,sBAAuB,CACrB,gBAAiB,CAAE,MAAO,MAAO,CACnC,EACA,YAAa,CAAE,KAAM,KAAM,EA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AC3B,MAAO,IAAIJ,EAAe,sBAAsB,CAClD,CAAC,CACH,CAAC,EAED,GAAG,8CAA+C,IAAM,CAEtDG,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBF,EAAuB,0BACzC,aAAcH,EAAa,UAC3B,cAAe,CAAC,CAClB,CAAkC,EAGlC,MAAMM,EAAS,IAAIF,EAAuBC,EAAS,CACjD,YAAa,CAAC,CAAE,MAAO,IAAK,CAAC,CAC/B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,MAAO,IAAIJ,EAAe,6BAA6B,CACzD,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["semver", "DeviceStatus", "makeDeviceActionInternalApiMock", "UnknownDAError", "DeviceSessionStateType", "PredictOutOfMemoryTask", "apiMock", "result", "firmwareVersion"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var n=Object.defineProperty;var
|
|
1
|
+
var n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var U=(c,e,d)=>e in c?n(c,e,{enumerable:!0,configurable:!0,writable:!0,value:d}):c[e]=d;var m=(c,e,d,t)=>{for(var o=t>1?void 0:t?f(e,d):e,s=c.length-1,l;s>=0;s--)(l=c[s])&&(o=(t?l(e,d,o):l(o))||o);return t&&o&&n(e,d,o),o};var b=(c,e,d)=>U(c,typeof e!="symbol"?e+"":e,d);import{injectable as p}from"inversify";import v from"semver";import{DeviceModelId as r}from"../../device/DeviceModel";import{BleDeviceInfos as y}from"../../device-model/model/BleDeviceInfos";import{TransportDeviceModel as u}from"../../device-model/model/DeviceModel";let i=class{getAllDeviceModels(){return Object.values(i.deviceModelByIds)}getDeviceModel(e){return i.deviceModelByIds[e.id]}filterDeviceModels(e){return this.getAllDeviceModels().filter(d=>Object.entries(e).every(([t,o])=>d[t]===o))}getBluetoothServicesInfos(){return Object.values(i.deviceModelByIds).reduce((e,d)=>{const{bluetoothSpec:t}=d;return t?{...e,...t.reduce((o,s)=>({...o,[s.serviceUuid]:new y(d,s.serviceUuid,s.writeUuid,s.writeCmdUuid,s.notifyUuid)}),{})}:e},{})}getBluetoothServices(){return Object.values(i.deviceModelByIds).map(e=>(e.bluetoothSpec||[]).map(d=>d.serviceUuid)).flat().filter(e=>!!e)}};b(i,"deviceModelByIds",{[r.NANO_S]:new u({id:r.NANO_S,productName:"Ledger Nano S",usbProductId:16,bootloaderUsbProductId:1,usbOnly:!0,memorySize:320*1024,getBlockSize:e=>v.lt(v.coerce(e.firmwareVersion)??"","2.0.0")?4*1024:2*1024,masks:[823132160]}),[r.NANO_SP]:new u({id:r.NANO_SP,productName:"Ledger Nano S Plus",usbProductId:80,bootloaderUsbProductId:5,usbOnly:!0,memorySize:1533*1024,getBlockSize:()=>32,masks:[856686592]}),[r.NANO_X]:new u({id:r.NANO_X,productName:"Ledger Nano X",usbProductId:64,bootloaderUsbProductId:4,usbOnly:!1,memorySize:2*1024*1024,getBlockSize:()=>4*1024,masks:[855638016],bluetoothSpec:[{serviceUuid:"13d63400-2c97-0004-0000-4c6564676572",notifyUuid:"13d63400-2c97-0004-0001-4c6564676572",writeUuid:"13d63400-2c97-0004-0002-4c6564676572",writeCmdUuid:"13d63400-2c97-0004-0003-4c6564676572"}]}),[r.STAX]:new u({id:r.STAX,productName:"Ledger Stax",usbProductId:96,bootloaderUsbProductId:6,usbOnly:!1,memorySize:1533*1024,getBlockSize:()=>32,masks:[857735168],bluetoothSpec:[{serviceUuid:"13d63400-2c97-6004-0000-4c6564676572",notifyUuid:"13d63400-2c97-6004-0001-4c6564676572",writeUuid:"13d63400-2c97-6004-0002-4c6564676572",writeCmdUuid:"13d63400-2c97-6004-0003-4c6564676572"}]}),[r.FLEX]:new u({id:r.FLEX,productName:"Ledger Flex",usbProductId:112,bootloaderUsbProductId:7,usbOnly:!1,memorySize:1533*1024,getBlockSize:()=>32,masks:[858783744],bluetoothSpec:[{serviceUuid:"13d63400-2c97-3004-0000-4c6564676572",notifyUuid:"13d63400-2c97-3004-0001-4c6564676572",writeUuid:"13d63400-2c97-3004-0002-4c6564676572",writeCmdUuid:"13d63400-2c97-3004-0003-4c6564676572"}]}),[r.APEX]:new u({id:r.APEX,productName:"Ledger Apex",usbProductId:128,bootloaderUsbProductId:8,usbOnly:!1,memorySize:1533*1024,getBlockSize:()=>32,masks:[859832320],bluetoothSpec:[{serviceUuid:"13d63400-2c97-8004-0000-4c6564676572",notifyUuid:"13d63400-2c97-8004-0001-4c6564676572",writeUuid:"13d63400-2c97-8004-0002-4c6564676572",writeCmdUuid:"13d63400-2c97-8004-0003-4c6564676572"}]})}),i=m([p()],i);export{i as StaticDeviceModelDataSource};
|
|
2
2
|
//# sourceMappingURL=StaticDeviceModelDataSource.js.map
|