Skip to content

Commit

Permalink
Made Url Witness Browser Friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Nov 21, 2023
1 parent e4fbe4a commit 23b90bb
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 22 deletions.
28 changes: 28 additions & 0 deletions .yarn/versions/d46db447.yml
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 12 additions & 12 deletions packages/payloadset/packages/url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -64,4 +64,4 @@
"sideEffects": false,
"version": "2.81.5",
"type": "module"
}
}
16 changes: 16 additions & 0 deletions packages/payloadset/packages/url/src/PluginNode.ts
Original file line number Diff line number Diff line change
@@ -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<UrlWitness>(
{ required: { [UrlSchema]: 1 }, schema: PayloadSetSchema },
{
witness: async (params) => {
const result = await UrlWitness.create(params)
return result
},
},
)
4 changes: 4 additions & 0 deletions packages/payloadset/packages/url/src/Witness/Witness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import { UrlWitnessParams } from './Params'

export class UrlWitness<TParams extends UrlWitnessParams = UrlWitnessParams> extends AbstractWitness<TParams> {
static override configSchemas = [UrlWitnessConfigSchema]
static hashUrl: ((url: string) => Promise<string>) | undefined = undefined

get urls() {
return this.config?.urls
}

protected override async observeHandler(payloads: Payload[] = []): Promise<Payload[]> {
if (UrlWitness.hashUrl === undefined) {
throw Error('Set UrlWitness.hashUrl before using')
}
const urls: UrlPayload[] =
this.urls?.map((url) => ({ schema: UrlSchema, url })) ??
payloads
Expand Down
8 changes: 0 additions & 8 deletions packages/payloadset/packages/url/src/index.ts

This file was deleted.

7 changes: 7 additions & 0 deletions packages/payloadset/packages/url/src/indexBrowser.ts
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions packages/payloadset/packages/url/src/indexNode.ts
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions packages/payloadset/packages/url/xy.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
},
},
}
Expand Down

0 comments on commit 23b90bb

Please sign in to comment.