From 23b90bb33ffd9070d4b83344007b5d3dc54df90a Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Tue, 21 Nov 2023 13:47:52 -0800 Subject: [PATCH] Made Url Witness Browser Friendly --- .yarn/versions/d46db447.yml | 28 +++++++++++++++++++ packages/payloadset/packages/url/package.json | 24 ++++++++-------- .../url/src/{Plugin.ts => PluginBrowser.ts} | 0 .../payloadset/packages/url/src/PluginNode.ts | 16 +++++++++++ .../packages/url/src/Witness/Witness.ts | 4 +++ packages/payloadset/packages/url/src/index.ts | 8 ------ .../packages/url/src/indexBrowser.ts | 7 +++++ .../payloadset/packages/url/src/indexNode.ts | 10 +++++++ packages/payloadset/packages/url/xy.config.ts | 8 ++++-- 9 files changed, 83 insertions(+), 22 deletions(-) create mode 100644 .yarn/versions/d46db447.yml rename packages/payloadset/packages/url/src/{Plugin.ts => PluginBrowser.ts} (100%) create mode 100644 packages/payloadset/packages/url/src/PluginNode.ts delete mode 100644 packages/payloadset/packages/url/src/index.ts create mode 100644 packages/payloadset/packages/url/src/indexBrowser.ts create mode 100644 packages/payloadset/packages/url/src/indexNode.ts diff --git a/.yarn/versions/d46db447.yml b/.yarn/versions/d46db447.yml new file mode 100644 index 000000000..2635117ce --- /dev/null +++ b/.yarn/versions/d46db447.yml @@ -0,0 +1,28 @@ +releases: + "@xyo-network/address-payload-plugin": patch + "@xyo-network/blockchain-payload-plugins": patch + "@xyo-network/blocknative-ethereum-gas-payload-plugin": patch + "@xyo-network/coingecko-crypto-market-payload-plugin": patch + "@xyo-network/config-payload-plugin": patch + "@xyo-network/crypto-asset-payload-plugin": patch + "@xyo-network/crypto-cards-game-payload-plugin": patch + "@xyo-network/crypto-cards-move-payload-plugin": patch + "@xyo-network/crypto-cards-payload-plugins": patch + "@xyo-network/crypto-market-payload-plugins": patch + "@xyo-network/crypto-nft-collection-payload-plugin": patch + "@xyo-network/crypto-nft-payload-plugins": patch + "@xyo-network/crypto-payload-plugins": patch + "@xyo-network/etherchain-ethereum-gas-v2-payload-plugin": patch + "@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins": patch + "@xyo-network/ethereum-blockchain-payload-plugins": patch + "@xyo-network/ethers-ethereum-gas-payload-plugin": patch + "@xyo-network/etherscan-ethereum-gas-payload-plugin": patch + "@xyo-network/ethgasstation-ethereum-gas-payload-plugin": patch + "@xyo-network/gas-ethereum-blockchain-payload-plugins": patch + "@xyo-network/gas-price-payload-plugin": patch + "@xyo-network/payload-plugins": patch + "@xyo-network/plugins": patch + "@xyo-network/uniswap-crypto-market-payload-plugin": patch + +undecided: + - "@xyo-network/url-plugin" diff --git a/packages/payloadset/packages/url/package.json b/packages/payloadset/packages/url/package.json index 907014ea6..eafa54f7c 100644 --- a/packages/payloadset/packages/url/package.json +++ b/packages/payloadset/packages/url/package.json @@ -28,30 +28,30 @@ ".": { "browser": { "require": { - "types": "./dist/browser/index.d.cts", - "default": "./dist/browser/index.cjs" + "types": "./dist/browser/indexBrowser.d.cts", + "default": "./dist/browser/indexBrowser.cjs" }, "import": { - "types": "./dist/browser/index.d.mts", - "default": "./dist/browser/index.js" + "types": "./dist/browser/indexBrowser.d.mts", + "default": "./dist/browser/indexBrowser.js" } }, "node": { "require": { - "types": "./dist/node/index.d.cts", - "default": "./dist/node/index.cjs" + "types": "./dist/node/indexNode.d.cts", + "default": "./dist/node/indexNode.cjs" }, "import": { - "types": "./dist/node/index.d.mts", - "default": "./dist/node/index.js" + "types": "./dist/node/indexNode.d.mts", + "default": "./dist/node/indexNode.js" } } }, "./package.json": "./package.json" }, - "main": "dist/node/index.cjs", - "module": "dist/node/index.js", - "types": "dist/node/index.d.mts", + "main": "dist/node/indexNode.cjs", + "module": "dist/node/indexNode.js", + "types": "dist/node/indexNode.d.mts", "homepage": "https://xyo.network", "license": "LGPL-3.0-only", "publishConfig": { @@ -64,4 +64,4 @@ "sideEffects": false, "version": "2.81.5", "type": "module" -} +} \ No newline at end of file diff --git a/packages/payloadset/packages/url/src/Plugin.ts b/packages/payloadset/packages/url/src/PluginBrowser.ts similarity index 100% rename from packages/payloadset/packages/url/src/Plugin.ts rename to packages/payloadset/packages/url/src/PluginBrowser.ts diff --git a/packages/payloadset/packages/url/src/PluginNode.ts b/packages/payloadset/packages/url/src/PluginNode.ts new file mode 100644 index 000000000..1980ca617 --- /dev/null +++ b/packages/payloadset/packages/url/src/PluginNode.ts @@ -0,0 +1,16 @@ +import { PayloadSetSchema } from '@xyo-network/payload-model' +import { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin' +import { UrlSchema } from '@xyo-network/url-payload-plugin' + +import { UrlWitness } from './Witness' + +export const UrlPlugin = () => + createPayloadSetWitnessPlugin( + { required: { [UrlSchema]: 1 }, schema: PayloadSetSchema }, + { + witness: async (params) => { + const result = await UrlWitness.create(params) + return result + }, + }, + ) diff --git a/packages/payloadset/packages/url/src/Witness/Witness.ts b/packages/payloadset/packages/url/src/Witness/Witness.ts index 478389088..7f8b824df 100644 --- a/packages/payloadset/packages/url/src/Witness/Witness.ts +++ b/packages/payloadset/packages/url/src/Witness/Witness.ts @@ -8,12 +8,16 @@ import { UrlWitnessParams } from './Params' export class UrlWitness extends AbstractWitness { static override configSchemas = [UrlWitnessConfigSchema] + static hashUrl: ((url: string) => Promise) | undefined = undefined get urls() { return this.config?.urls } protected override async observeHandler(payloads: Payload[] = []): Promise { + if (UrlWitness.hashUrl === undefined) { + throw Error('Set UrlWitness.hashUrl before using') + } const urls: UrlPayload[] = this.urls?.map((url) => ({ schema: UrlSchema, url })) ?? payloads diff --git a/packages/payloadset/packages/url/src/index.ts b/packages/payloadset/packages/url/src/index.ts deleted file mode 100644 index 265e52ca1..000000000 --- a/packages/payloadset/packages/url/src/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { UrlPlugin } from './Plugin' - -export * from './Witness' - -export { UrlPlugin } - -// eslint-disable-next-line import/no-default-export -export default UrlPlugin diff --git a/packages/payloadset/packages/url/src/indexBrowser.ts b/packages/payloadset/packages/url/src/indexBrowser.ts new file mode 100644 index 000000000..22dfd526c --- /dev/null +++ b/packages/payloadset/packages/url/src/indexBrowser.ts @@ -0,0 +1,7 @@ +import { UrlPlugin } from './PluginNode' +import { UrlWitness } from './Witness' + +export { UrlPlugin, UrlWitness } + +// eslint-disable-next-line import/no-default-export +export default UrlPlugin diff --git a/packages/payloadset/packages/url/src/indexNode.ts b/packages/payloadset/packages/url/src/indexNode.ts new file mode 100644 index 000000000..e8fce35e6 --- /dev/null +++ b/packages/payloadset/packages/url/src/indexNode.ts @@ -0,0 +1,10 @@ +import { UrlPlugin } from './PluginNode' +import { hashUrl } from './util' +import { UrlWitness } from './Witness' + +UrlWitness.hashUrl = hashUrl + +export { UrlPlugin, UrlWitness } + +// eslint-disable-next-line import/no-default-export +export default UrlPlugin diff --git a/packages/payloadset/packages/url/xy.config.ts b/packages/payloadset/packages/url/xy.config.ts index 84f712184..891175378 100644 --- a/packages/payloadset/packages/url/xy.config.ts +++ b/packages/payloadset/packages/url/xy.config.ts @@ -2,10 +2,14 @@ import { XyTsupConfig } from '@xylabs/ts-scripts-yarn3' const config: XyTsupConfig = { compile: { browser: { - src: true, + src: { + entry: ['src/indexBrowser.ts'], + }, }, node: { - src: true, + src: { + entry: ['src/indexNode.ts'], + }, }, }, }