@metamask/snaps-utils 9.0.0 → 9.0.1
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/CHANGELOG.md +8 -1
- package/dist/eval-worker.cjs +1 -1
- package/dist/eval-worker.cjs.map +1 -1
- package/dist/eval-worker.mjs +1 -1
- package/dist/eval-worker.mjs.map +1 -1
- package/dist/fs.cjs +1 -1
- package/dist/fs.cjs.map +1 -1
- package/dist/fs.mjs +1 -1
- package/dist/fs.mjs.map +1 -1
- package/dist/iframe.cjs +0 -1
- package/dist/iframe.cjs.map +1 -1
- package/dist/iframe.d.cts +0 -1
- package/dist/iframe.d.cts.map +1 -1
- package/dist/iframe.d.mts +0 -1
- package/dist/iframe.d.mts.map +1 -1
- package/dist/iframe.mjs +0 -1
- package/dist/iframe.mjs.map +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/json-rpc.cjs +2 -6
- package/dist/json-rpc.cjs.map +1 -1
- package/dist/json-rpc.d.cts.map +1 -1
- package/dist/json-rpc.d.mts.map +1 -1
- package/dist/json-rpc.mjs +2 -6
- package/dist/json-rpc.mjs.map +1 -1
- package/dist/manifest/manifest.cjs +1 -1
- package/dist/manifest/manifest.cjs.map +1 -1
- package/dist/manifest/manifest.d.cts +2 -2
- package/dist/manifest/manifest.d.cts.map +1 -1
- package/dist/manifest/manifest.d.mts +2 -2
- package/dist/manifest/manifest.d.mts.map +1 -1
- package/dist/manifest/manifest.mjs +1 -1
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs.map +1 -1
- package/dist/manifest/validator-types.d.cts +1 -1
- package/dist/manifest/validator-types.d.cts.map +1 -1
- package/dist/manifest/validator-types.d.mts +1 -1
- package/dist/manifest/validator-types.d.mts.map +1 -1
- package/dist/manifest/validator-types.mjs.map +1 -1
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.d.cts +1 -1
- package/dist/manifest/validator.d.cts.map +1 -1
- package/dist/manifest/validator.d.mts +1 -1
- package/dist/manifest/validator.d.mts.map +1 -1
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/platform-version.cjs +1 -1
- package/dist/manifest/validators/platform-version.cjs.map +1 -1
- package/dist/manifest/validators/platform-version.mjs +1 -1
- package/dist/manifest/validators/platform-version.mjs.map +1 -1
- package/dist/mock.cjs +0 -3
- package/dist/mock.cjs.map +1 -1
- package/dist/mock.d.cts.map +1 -1
- package/dist/mock.d.mts.map +1 -1
- package/dist/mock.mjs +0 -3
- package/dist/mock.mjs.map +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.mjs +1 -1
- package/dist/node.mjs.map +1 -1
- package/dist/post-process.cjs.map +1 -1
- package/dist/post-process.d.cts.map +1 -1
- package/dist/post-process.d.mts.map +1 -1
- package/dist/post-process.mjs.map +1 -1
- package/dist/snaps.cjs +21 -3
- package/dist/snaps.cjs.map +1 -1
- package/dist/snaps.d.cts +2 -1
- package/dist/snaps.d.cts.map +1 -1
- package/dist/snaps.d.mts +2 -1
- package/dist/snaps.d.mts.map +1 -1
- package/dist/snaps.mjs +22 -4
- package/dist/snaps.mjs.map +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +3 -3
- package/dist/types.mjs.map +1 -1
- package/dist/ui.cjs +7 -5
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts.map +1 -1
- package/dist/ui.d.mts.map +1 -1
- package/dist/ui.mjs +7 -5
- package/dist/ui.mjs.map +1 -1
- package/dist/virtual-file/VirtualFile.cjs.map +1 -1
- package/dist/virtual-file/VirtualFile.mjs.map +1 -1
- package/package.json +8 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualFile.cjs","sourceRoot":"","sources":["../../src/virtual-file/VirtualFile.ts"],"names":[],"mappings":";;;AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;AACtD,2CAAqD;AACrD,sCAAqC;AAErC,kDAA0C;AA+B1C,MAAa,WAAW;IACtB,YAAY,KAA0B;QACpC,IAAI,OAA4B,CAAC;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;YAC7D,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;QAClC,wDAAwD;QACxD,gEAAgE;QAChE,4DAA4D;QAC5D,EAAE;QACF,wEAAwE;QACxE,4EAA4E;QAC5E,8EAA8E;QAC9E,EAAE;QACF,iDAAiD;QACjD,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAK,SAAiB,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,GAAG,CAAC;IACnC,CAAC;IAUD,IAAI,IAAI;QACN,OAAO,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;YACnC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM;YACnB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IAC5B,CAAC;IAED,QAAQ,CAAC,QAAiB;QACxB,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACnC,IAAA,cAAM,EAAC,QAAQ,KAAK,SAAS,EAAE,yBAAyB,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;aAAM,IAAI,IAAI,CAAC,KAAK,YAAY,UAAU,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;YAClE,OAAO,IAAA,kBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;aAAM,IAAI,IAAI,CAAC,KAAK,YAAY,UAAU,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACrE,oEAAoE;YACpE,qCAAqC;YACrC,OAAO,aAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,KAAK;QACH,MAAM,KAAK,GAAG,IAAI,WAAW,EAAU,CAAC;QACxC,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACnC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,mFAAmF;YACnF,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;QACD,KAAK,CAAC,MAAM,GAAG,IAAA,sBAAS,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,KAAK,CAAC,IAAI,GAAG,IAAA,sBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlED,kCAkEC","sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert, bytesToHex } from '@metamask/utils';\nimport { base64 } from '@scure/base';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-
|
|
1
|
+
{"version":3,"file":"VirtualFile.cjs","sourceRoot":"","sources":["../../src/virtual-file/VirtualFile.ts"],"names":[],"mappings":";;;AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;AACtD,2CAAqD;AACrD,sCAAqC;AAErC,kDAA0C;AA+B1C,MAAa,WAAW;IACtB,YAAY,KAA0B;QACpC,IAAI,OAA4B,CAAC;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;YAC7D,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;QAClC,wDAAwD;QACxD,gEAAgE;QAChE,4DAA4D;QAC5D,EAAE;QACF,wEAAwE;QACxE,4EAA4E;QAC5E,8EAA8E;QAC9E,EAAE;QACF,iDAAiD;QACjD,I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,KAAK,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,mFAAmF;YACnF,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;QACD,KAAK,CAAC,MAAM,GAAG,IAAA,sBAAS,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,KAAK,CAAC,IAAI,GAAG,IAAA,sBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlED,kCAkEC","sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert, bytesToHex } from '@metamask/utils';\nimport { base64 } from '@scure/base';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-object-type\nexport interface DataMap {}\n\nexport type Value = string | Uint8Array;\nexport type Compatible<Result = unknown> =\n | string\n | Uint8Array\n | Options<Result>;\nexport type Data = Record<string, unknown> & Partial<DataMap>;\nexport type Options<Result = unknown> = {\n value: Value;\n path?: string;\n data?: Data;\n result?: Result;\n};\n\nexport class VirtualFile<Result = unknown> {\n constructor(value?: Compatible<Result>) {\n let options: Options | undefined;\n if (typeof value === 'string' || value instanceof Uint8Array) {\n options = { value };\n } else {\n options = value;\n }\n\n this.value = options?.value ?? '';\n // This situations happens when there's no .result used,\n // we expect the file to have default generic in that situation:\n // VirtualFile<unknown> which will handle undefined properly\n //\n // While not 100% type safe, it'll be way less frustrating to work with.\n // The alternative would be to have VirtualFile.result be Result | undefined\n // and that would result in needing to branch out and check in all situations.\n //\n // In short, optimizing for most common use case.\n this.result = options?.result ?? (undefined as any);\n this.data = options?.data ?? {};\n this.path = options?.path ?? '/';\n }\n\n value: Value;\n\n result: Result;\n\n data: Data;\n\n path: string;\n\n get size() {\n return typeof this.value === 'string'\n ? this.value.length\n : this.value.byteLength;\n }\n\n toString(encoding?: string) {\n if (typeof this.value === 'string') {\n assert(encoding === undefined, 'Tried to encode string.');\n return this.value;\n } else if (this.value instanceof Uint8Array && encoding === 'hex') {\n return bytesToHex(this.value);\n } else if (this.value instanceof Uint8Array && encoding === 'base64') {\n // For large files, this is quite slow, instead use `encodeBase64()`\n // TODO: Use @metamask/utils for this\n return base64.encode(this.value);\n }\n const decoder = new TextDecoder(encoding);\n return decoder.decode(this.value);\n }\n\n clone() {\n const vfile = new VirtualFile<Result>();\n if (typeof this.value === 'string') {\n vfile.value = this.value;\n } else {\n // deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array\n vfile.value = this.value.slice(0);\n }\n vfile.result = deepClone(this.result);\n vfile.data = deepClone(this.data);\n vfile.path = this.path;\n return vfile;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualFile.mjs","sourceRoot":"","sources":["../../src/virtual-file/VirtualFile.ts"],"names":[],"mappings":"AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;AACtD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,wBAAwB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AAK,CAAC,CAAC;QAChC,CAAC;aAAM,IAAI,IAAI,CAAC,KAAK,YAAY,UAAU,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACrE,oEAAoE;YACpE,qCAAqC;YACrC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,KAAK;QACH,MAAM,KAAK,GAAG,IAAI,WAAW,EAAU,CAAC;QACxC,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACnC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,mFAAmF;YACnF,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;QACD,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert, bytesToHex } from '@metamask/utils';\nimport { base64 } from '@scure/base';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-
|
|
1
|
+
{"version":3,"file":"VirtualFile.mjs","sourceRoot":"","sources":["../../src/virtual-file/VirtualFile.ts"],"names":[],"mappings":"AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;AACtD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,wBAAwB;AACrD,OAAO,EAAE,MAAM,EAAE,oBAAoB;AAErC,OAAO,EAAE,SAAS,EAAE,0BAAsB;AA+B1C,MAAM,OAAO,WAAW;IACtB,YAAY,KAA0B;QACpC,IAAI,OAA4B,CAAC;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;YAC7D,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;QAClC,wDAAwD;QACxD,gEAAgE;QAChE,4DAA4D;QAC5D,EAAE;QACF,wEAAwE;QACxE,4EAA4E;QAC5E,8EAA8E;QAC9E,EAAE;QACF,iDAAiD;QACjD,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAK,SAAiB,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI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C,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert, bytesToHex } from '@metamask/utils';\nimport { base64 } from '@scure/base';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-object-type\nexport interface DataMap {}\n\nexport type Value = string | Uint8Array;\nexport type Compatible<Result = unknown> =\n | string\n | Uint8Array\n | Options<Result>;\nexport type Data = Record<string, unknown> & Partial<DataMap>;\nexport type Options<Result = unknown> = {\n value: Value;\n path?: string;\n data?: Data;\n result?: Result;\n};\n\nexport class VirtualFile<Result = unknown> {\n constructor(value?: Compatible<Result>) {\n let options: Options | undefined;\n if (typeof value === 'string' || value instanceof Uint8Array) {\n options = { value };\n } else {\n options = value;\n }\n\n this.value = options?.value ?? '';\n // This situations happens when there's no .result used,\n // we expect the file to have default generic in that situation:\n // VirtualFile<unknown> which will handle undefined properly\n //\n // While not 100% type safe, it'll be way less frustrating to work with.\n // The alternative would be to have VirtualFile.result be Result | undefined\n // and that would result in needing to branch out and check in all situations.\n //\n // In short, optimizing for most common use case.\n this.result = options?.result ?? (undefined as any);\n this.data = options?.data ?? {};\n this.path = options?.path ?? '/';\n }\n\n value: Value;\n\n result: Result;\n\n data: Data;\n\n path: string;\n\n get size() {\n return typeof this.value === 'string'\n ? this.value.length\n : this.value.byteLength;\n }\n\n toString(encoding?: string) {\n if (typeof this.value === 'string') {\n assert(encoding === undefined, 'Tried to encode string.');\n return this.value;\n } else if (this.value instanceof Uint8Array && encoding === 'hex') {\n return bytesToHex(this.value);\n } else if (this.value instanceof Uint8Array && encoding === 'base64') {\n // For large files, this is quite slow, instead use `encodeBase64()`\n // TODO: Use @metamask/utils for this\n return base64.encode(this.value);\n }\n const decoder = new TextDecoder(encoding);\n return decoder.decode(this.value);\n }\n\n clone() {\n const vfile = new VirtualFile<Result>();\n if (typeof this.value === 'string') {\n vfile.value = this.value;\n } else {\n // deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array\n vfile.value = this.value.slice(0);\n }\n vfile.result = deepClone(this.result);\n vfile.data = deepClone(this.data);\n vfile.path = this.path;\n return vfile;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-utils",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"description": "A collection of utilities for MetaMask Snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn changelog:validate && yarn lint:dependencies",
|
|
65
65
|
"lint:ci": "yarn lint",
|
|
66
66
|
"lint:dependencies": "depcheck",
|
|
67
|
-
"lint:eslint": "eslint . --cache
|
|
67
|
+
"lint:eslint": "eslint . --cache",
|
|
68
68
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
|
|
69
|
-
"lint:misc": "prettier --no-error-on-unmatched-pattern --
|
|
69
|
+
"lint:misc": "prettier --no-error-on-unmatched-pattern --log-level warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
|
|
70
70
|
"publish:preview": "yarn npm publish --tag preview",
|
|
71
71
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
72
72
|
"test": "jest --reporters=jest-silent-reporter && yarn test:browser",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"@metamask/rpc-errors": "^7.0.2",
|
|
86
86
|
"@metamask/slip44": "^4.1.0",
|
|
87
87
|
"@metamask/snaps-registry": "^3.2.3",
|
|
88
|
-
"@metamask/snaps-sdk": "^6.
|
|
88
|
+
"@metamask/snaps-sdk": "^6.19.0",
|
|
89
89
|
"@metamask/superstruct": "^3.1.0",
|
|
90
90
|
"@metamask/utils": "^11.2.0",
|
|
91
91
|
"@noble/hashes": "^1.3.1",
|
|
@@ -105,11 +105,7 @@
|
|
|
105
105
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
|
106
106
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
107
107
|
"@lavamoat/allow-scripts": "^3.0.4",
|
|
108
|
-
"@metamask/auto-changelog": "^
|
|
109
|
-
"@metamask/eslint-config": "^12.1.0",
|
|
110
|
-
"@metamask/eslint-config-jest": "^12.1.0",
|
|
111
|
-
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
112
|
-
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
108
|
+
"@metamask/auto-changelog": "^4.1.0",
|
|
113
109
|
"@metamask/post-message-stream": "^9.0.0",
|
|
114
110
|
"@swc/core": "1.3.78",
|
|
115
111
|
"@swc/jest": "^0.2.26",
|
|
@@ -119,8 +115,6 @@
|
|
|
119
115
|
"@types/node": "18.14.2",
|
|
120
116
|
"@types/semver": "^7.5.0",
|
|
121
117
|
"@types/validate-npm-package-name": "^4.0.0",
|
|
122
|
-
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
123
|
-
"@typescript-eslint/parser": "^6.21.0",
|
|
124
118
|
"@wdio/browser-runner": "^8.19.0",
|
|
125
119
|
"@wdio/cli": "^8.19.0",
|
|
126
120
|
"@wdio/globals": "^8.19.0",
|
|
@@ -131,14 +125,7 @@
|
|
|
131
125
|
"deepmerge": "^4.2.2",
|
|
132
126
|
"depcheck": "^1.4.7",
|
|
133
127
|
"esbuild": "^0.18.10",
|
|
134
|
-
"eslint": "^
|
|
135
|
-
"eslint-config-prettier": "^8.5.0",
|
|
136
|
-
"eslint-plugin-import": "^2.26.0",
|
|
137
|
-
"eslint-plugin-jest": "^27.1.5",
|
|
138
|
-
"eslint-plugin-jsdoc": "^41.1.2",
|
|
139
|
-
"eslint-plugin-n": "^15.7.0",
|
|
140
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
141
|
-
"eslint-plugin-promise": "^6.1.1",
|
|
128
|
+
"eslint": "^9.11.0",
|
|
142
129
|
"expect-webdriverio": "^4.4.1",
|
|
143
130
|
"istanbul-lib-coverage": "^3.2.0",
|
|
144
131
|
"istanbul-lib-report": "^3.0.0",
|
|
@@ -146,12 +133,11 @@
|
|
|
146
133
|
"jest": "^29.0.2",
|
|
147
134
|
"jest-silent-reporter": "^0.6.0",
|
|
148
135
|
"memfs": "^3.4.13",
|
|
149
|
-
"prettier": "^
|
|
150
|
-
"prettier-plugin-packagejson": "^2.5.2",
|
|
136
|
+
"prettier": "^3.3.3",
|
|
151
137
|
"rimraf": "^4.1.2",
|
|
152
138
|
"ts-node": "^10.9.1",
|
|
153
139
|
"typescript": "~5.3.3",
|
|
154
|
-
"vite": "^4.
|
|
140
|
+
"vite": "^4.5.6",
|
|
155
141
|
"vite-tsconfig-paths": "^4.0.5",
|
|
156
142
|
"wdio-chromedriver-service": "^8.1.1",
|
|
157
143
|
"wdio-geckodriver-service": "^5.0.2",
|