@polymarket/types 0.1.0-beta.2 → 0.1.0-beta.4
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/dist/index.d.ts +6 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Result, ResultAsync } from 'neverthrow';
|
|
2
2
|
export * from 'neverthrow';
|
|
3
3
|
import { Tagged } from 'type-fest';
|
|
4
|
+
export { Tagged } from 'type-fest';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A tuple type representing a non-empty array.
|
|
@@ -130,6 +131,10 @@ declare function expectNonEmptyArray<T>(value: readonly T[], message?: string):
|
|
|
130
131
|
* Refines a string to a hex string or throws when the value is invalid.
|
|
131
132
|
*/
|
|
132
133
|
declare function expectHexString(value: string, message?: string): HexString;
|
|
134
|
+
/**
|
|
135
|
+
* Refines a string to a private key or throws when the value is invalid.
|
|
136
|
+
*/
|
|
137
|
+
declare function expectPrivateKey(value: unknown, message?: string): PrivateKey;
|
|
133
138
|
/**
|
|
134
139
|
* Refines a string to an EVM address or throws when the value is invalid.
|
|
135
140
|
*/
|
|
@@ -166,4 +171,4 @@ declare function expectTxHash(value: unknown, message?: string): TxHash;
|
|
|
166
171
|
declare function unwrap<T, E>(result: Result<T, E>): T;
|
|
167
172
|
declare function unwrap<T, E>(result: ResultAsync<T, E>): Promise<T>;
|
|
168
173
|
|
|
169
|
-
export { type Erc1271Signature, type EvmAddress, type EvmSignature, type HexString, InvariantError, type NonEmptyArray, PolymarketError, type Prettify, type PrivateKey, type TxHash, ZERO_ADDRESS, delay, expectErc1271Signature, expectEvmAddress, expectEvmSignature, expectHexString, expectNonEmptyArray, expectPresent, expectTxHash, invariant, isHexString, isNonEmptyArray, isNullish, isPresent, isPrivateKey, isSameEvmAddress, never, setNonBlockingInterval, setNonBlockingTimeout, unwrap };
|
|
174
|
+
export { type Erc1271Signature, type EvmAddress, type EvmSignature, type HexString, InvariantError, type NonEmptyArray, PolymarketError, type Prettify, type PrivateKey, type TxHash, ZERO_ADDRESS, delay, expectErc1271Signature, expectEvmAddress, expectEvmSignature, expectHexString, expectNonEmptyArray, expectPresent, expectPrivateKey, expectTxHash, invariant, isHexString, isNonEmptyArray, isNullish, isPresent, isPrivateKey, isSameEvmAddress, never, setNonBlockingInterval, setNonBlockingTimeout, unwrap };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {ResultAsync}from'neverthrow';export*from'neverthrow';var
|
|
1
|
+
import {ResultAsync}from'neverthrow';export*from'neverthrow';var m="0x0000000000000000000000000000000000000000";var s=class e extends Error{static isError(t){return t instanceof e}},i=class extends s{name="InvariantError"};function y(e){return e.length>0}function x(e){return e==null}function E(e){return !x(e)}function r(e,t){if(!e)throw new i(t)}function l(e="Unexpected call to never()"){throw new i(e)}function v(e){return new Promise(t=>setTimeout(t,e))}function p(e){let t=e.unref;typeof t=="function"&&t.call(e);}function S(e,t){let o=setInterval(e,t);return p(o),o}function w(e,t){let o=setTimeout(e,t);return p(o),o}function n(e){return typeof e=="string"&&/^0x[a-fA-F0-9]+$/.test(e)}function A(e,t){return e.toLowerCase()===t.toLowerCase()}function u(e){return n(e)&&e.length===66}function R(e,t="Expected value to be present"){return r(e!=null,t),e}function K(e,t="Expected a non-empty array"){return r(e.length>0,t),e}function N(e,t="Expected a hex string"){return r(n(e),t),e}function b(e,t="Expected a private key"){return r(u(e),t),e}function I(e,t="Expected an EVM address"){return r(n(e)&&e.length===42,t),e}function C(e,t="Expected an EVM signature"){return r(n(e)&&e.length===132,t),e}function B(e,t="Expected an ERC-1271 signature payload"){return r(n(e),t),e}function D(e,t="Expected a transaction hash"){return r(n(e)&&e.length===66,t),e}function a(e){throw e}function U(e){return e instanceof ResultAsync?e.match(t=>t,a):e.match(t=>t,a)}export{i as InvariantError,s as PolymarketError,m as ZERO_ADDRESS,v as delay,B as expectErc1271Signature,I as expectEvmAddress,C as expectEvmSignature,N as expectHexString,K as expectNonEmptyArray,R as expectPresent,b as expectPrivateKey,D as expectTxHash,r as invariant,n as isHexString,y as isNonEmptyArray,x as isNullish,E as isPresent,u as isPrivateKey,A as isSameEvmAddress,l as never,S as setNonBlockingInterval,w as setNonBlockingTimeout,U as unwrap};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/errors.ts","../src/guards.ts","../src/helpers.ts","../src/hex.ts","../src/refinements.ts","../src/result.ts"],"names":["ZERO_ADDRESS","PolymarketError","_PolymarketError","error","InvariantError","isNonEmptyArray","value","isNullish","isPresent","invariant","condition","message","never","delay","ms","resolve","unrefTimer","timer","maybeUnref","setNonBlockingInterval","callback","setNonBlockingTimeout","isHexString","isSameEvmAddress","left","right","isPrivateKey","expectPresent","expectNonEmptyArray","expectHexString","expectEvmAddress","expectEvmSignature","expectErc1271Signature","expectTxHash","throwError","unwrap","result","ResultAsync"],"mappings":"6DAKO,IAAMA,CAAAA,CACX,6CCHK,IAAeC,EAAf,MAAeC,CAAAA,SAAwB,KAAM,CAIlD,OAAO,OAAA,CAAQC,CAAAA,CAA0C,CACvD,OAAOA,aAAiBD,CAC1B,CACF,CAAA,CAKaE,CAAAA,CAAN,cAA6BH,CAAgB,CACzC,IAAA,CAAO,gBAClB,ECZO,SAASI,CAAAA,CACdC,CAAAA,CAC2B,CAC3B,OAAOA,CAAAA,CAAM,MAAA,CAAS,CACxB,CAKO,SAASC,CAAAA,CAAUD,CAAAA,CAA2C,CACnE,OAAOA,GAAU,IACnB,CAKO,SAASE,CAAAA,CAAaF,EAAiD,CAC5E,OAAO,CAACC,CAAAA,CAAUD,CAAK,CACzB,CCNO,SAASG,CAAAA,CACdC,EACAC,CAAAA,CACmB,CACnB,GAAI,CAACD,EACH,M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":["import type { EvmAddress } from './hex';\n\n/**\n * The all-zero EVM address used to indicate the absence of a specific account.\n */\nexport const ZERO_ADDRESS =\n '0x0000000000000000000000000000000000000000' as EvmAddress;\n","/**\n * Base class for errors thrown by the Polymarket SDK.\n */\nexport abstract class PolymarketError extends Error {\n /**\n * Returns `true` when the provided value is a `PolymarketError`.\n */\n static isError(error: unknown): error is PolymarketError {\n return error instanceof PolymarketError;\n }\n}\n\n/**\n * Error thrown when code reaches a state that should be impossible.\n */\nexport class InvariantError extends PolymarketError {\n override name = 'InvariantError' as const;\n}\n","import type { NonEmptyArray } from './array';\n\n/**\n * Returns `true` if the array contains at least one element.\n */\nexport function isNonEmptyArray<T>(\n value: readonly T[],\n): value is NonEmptyArray<T> {\n return value.length > 0;\n}\n\n/**\n * Returns `true` if the value is `null` or `undefined`.\n */\nexport function isNullish(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * Returns `true` if the value is not `null` or `undefined`.\n */\nexport function isPresent<T>(value: T): value is Exclude<T, null | undefined> {\n return !isNullish(value);\n}\n","import { InvariantError } from './errors';\n\n/**\n * Flattens an object type for clearer IDE hovers and inferred signatures.\n */\nexport type Prettify<T> = {\n [K in keyof T]: T[K];\n} & {};\n\n/**\n * Asserts that a condition is truthy.\n *\n * @internal\n *\n * @param condition - Value expected to be truthy.\n * @param message - Message used for the thrown `InvariantError`.\n */\nexport function invariant(\n condition: unknown,\n message: string,\n): asserts condition {\n if (!condition) {\n throw new InvariantError(message);\n }\n}\n\n/**\n * Throws an `InvariantError` and narrows the current code path to `never`.\n *\n * Useful for unreachable branches and exhaustive checks.\n *\n * @param message - Message used for the thrown `InvariantError`.\n */\nexport function never(message = 'Unexpected call to never()'): never {\n throw new InvariantError(message);\n}\n\n/**\n * Resolves after the provided delay in milliseconds.\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction unrefTimer(timer: unknown): void {\n const maybeUnref = (timer as { unref?: () => void }).unref;\n if (typeof maybeUnref === 'function') maybeUnref.call(timer);\n}\n\n/**\n * Runs `callback` on an interval without forcing Node processes to stay alive\n * solely because the timer exists. In browsers, this behaves exactly like\n * `setInterval`.\n */\nexport function setNonBlockingInterval(\n callback: () => void,\n ms: number,\n): ReturnType<typeof setInterval> {\n const timer = setInterval(callback, ms);\n unrefTimer(timer);\n return timer;\n}\n\n/**\n * Runs `callback` after a timeout without forcing Node processes to stay alive\n * solely because the timer exists. In browsers, this behaves exactly like\n * `setTimeout`.\n */\nexport function setNonBlockingTimeout(\n callback: () => void,\n ms: number,\n): ReturnType<typeof setTimeout> {\n const timer = setTimeout(callback, ms);\n unrefTimer(timer);\n return timer;\n}\n","import type { Tagged } from 'type-fest';\n\n/**\n * A string encoded as hexadecimal and prefixed with `0x`.\n */\nexport type HexString = `0x${string}`;\n\n/**\n * A hex-encoded 32-byte private key prefixed with `0x`.\n */\nexport type PrivateKey = Tagged<HexString, 'PrivateKey'>;\n\n/**\n * An EVM account or contract address.\n */\nexport type EvmAddress = Tagged<HexString, 'EvmAddress'>;\n\n/**\n * A hex-encoded EVM signature.\n */\nexport type EvmSignature = Tagged<HexString, 'EvmSignature'>;\n\n/**\n * A hex-encoded ERC-1271 contract signature payload.\n */\nexport type Erc1271Signature = Tagged<HexString, 'Erc1271Signature'>;\n\n/**\n * A transaction hash returned by an EVM-compatible network.\n */\nexport type TxHash = Tagged<HexString, 'TxHash'>;\n\n/**\n * Checks whether a value is a hex string prefixed with `0x`.\n */\nexport function isHexString(value: unknown): value is HexString {\n return typeof value === 'string' && /^0x[a-fA-F0-9]+$/.test(value);\n}\n\n/**\n * Returns `true` when two EVM addresses are equal, ignoring checksum casing.\n */\nexport function isSameEvmAddress(left: EvmAddress, right: EvmAddress): boolean {\n return left.toLowerCase() === right.toLowerCase();\n}\n\n/**\n * Checks whether a value is a hex-encoded 32-byte private key.\n */\nexport function isPrivateKey(value: unknown): value is PrivateKey {\n return isHexString(value) && value.length === 66;\n}\n","import type { NonEmptyArray } from './array';\nimport { invariant } from './helpers';\nimport {\n type Erc1271Signature,\n type EvmAddress,\n type EvmSignature,\n type HexString,\n isHexString,\n type TxHash,\n} from './hex';\n\n/**\n * Refines a value to exclude `null` and `undefined`.\n */\nexport function expectPresent<T>(\n value: T,\n message = 'Expected value to be present',\n): Exclude<T, null | undefined> {\n invariant(value !== null && value !== undefined, message);\n return value as Exclude<T, null | undefined>;\n}\n\n/**\n * Refines an array to a non-empty tuple or throws when the array is empty.\n */\nexport function expectNonEmptyArray<T>(\n value: readonly T[],\n message = 'Expected a non-empty array',\n): NonEmptyArray<T> {\n invariant(value.length > 0, message);\n\n return value as NonEmptyArray<T>;\n}\n\n/**\n * Refines a string to a hex string or throws when the value is invalid.\n */\nexport function expectHexString(\n value: string,\n message = 'Expected a hex string',\n): HexString {\n invariant(isHexString(value), message);\n return value;\n}\n\n/**\n * Refines a string to an EVM address or throws when the value is invalid.\n */\nexport function expectEvmAddress(\n value: unknown,\n message = 'Expected an EVM address',\n): EvmAddress {\n invariant(isHexString(value) && value.length === 42, message);\n return value as EvmAddress;\n}\n\n/**\n * Refines a string to an EVM signature or throws when the value is invalid.\n */\nexport function expectEvmSignature(\n value: unknown,\n message = 'Expected an EVM signature',\n): EvmSignature {\n invariant(isHexString(value) && value.length === 132, message);\n return value as EvmSignature;\n}\n\n/**\n * Refines a string to an ERC-1271 signature payload or throws when the value is invalid.\n */\nexport function expectErc1271Signature(\n value: unknown,\n message = 'Expected an ERC-1271 signature payload',\n): Erc1271Signature {\n invariant(isHexString(value), message);\n return value as Erc1271Signature;\n}\n\n/**\n * Refines a string to a transaction hash or throws when the value is invalid.\n */\nexport function expectTxHash(\n value: unknown,\n message = 'Expected a transaction hash',\n): TxHash {\n invariant(isHexString(value) && value.length === 66, message);\n return value as TxHash;\n}\n","import { type Result, ResultAsync } from 'neverthrow';\n\nfunction throwError(error: unknown): never {\n throw error;\n}\n\n/**\n * Extracts the success value from a {@link Result} or {@link ResultAsync}, or\n * throws the error branch.\n *\n * @example\n * ```ts\n * const value = unwrap(result.andThen(step1).andThen(step2));\n *\n * // value === 42\n * ```\n *\n * @internal\n *\n * @param result - Result to unwrap.\n * @returns The success value of the `result`.\n */\nexport function unwrap<T, E>(result: Result<T, E>): T;\nexport function unwrap<T, E>(result: ResultAsync<T, E>): Promise<T>;\nexport function unwrap<T, E>(\n result: Result<T, E> | ResultAsync<T, E>,\n): T | Promise<T> {\n if (result instanceof ResultAsync) {\n return result.match((value) => value, throwError);\n }\n\n return result.match((value) => value, throwError);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/errors.ts","../src/guards.ts","../src/helpers.ts","../src/hex.ts","../src/refinements.ts","../src/result.ts"],"names":["ZERO_ADDRESS","PolymarketError","_PolymarketError","error","InvariantError","isNonEmptyArray","value","isNullish","isPresent","invariant","condition","message","never","delay","ms","resolve","unrefTimer","timer","maybeUnref","setNonBlockingInterval","callback","setNonBlockingTimeout","isHexString","isSameEvmAddress","left","right","isPrivateKey","expectPresent","expectNonEmptyArray","expectHexString","expectPrivateKey","expectEvmAddress","expectEvmSignature","expectErc1271Signature","expectTxHash","throwError","unwrap","result","ResultAsync"],"mappings":"6DAKO,IAAMA,CAAAA,CACX,6CCHK,IAAeC,EAAf,MAAeC,CAAAA,SAAwB,KAAM,CAIlD,OAAO,OAAA,CAAQC,CAAAA,CAA0C,CACvD,OAAOA,CAAAA,YAAiBD,CAC1B,CACF,CAAA,CAKaE,CAAAA,CAAN,cAA6BH,CAAgB,CACzC,IAAA,CAAO,gBAClB,ECZO,SAASI,CAAAA,CACdC,CAAAA,CAC2B,CAC3B,OAAOA,EAAM,MAAA,CAAS,CACxB,CAKO,SAASC,CAAAA,CAAUD,EAA2C,CACnE,OAAOA,CAAAA,EAAU,IACnB,CAKO,SAASE,CAAAA,CAAaF,CAAAA,CAAiD,CAC5E,OAAO,CAACC,CAAAA,CAAUD,CAAK,CACzB,CCJO,SAASG,CAAAA,CACdC,EACAC,C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G3CE,CAAAA,CAAO,MAAO/B,CAAAA,EAAUA,CAAAA,CAAO6B,CAAU,CAClD","file":"index.js","sourcesContent":["import type { EvmAddress } from './hex';\n\n/**\n * The all-zero EVM address used to indicate the absence of a specific account.\n */\nexport const ZERO_ADDRESS =\n '0x0000000000000000000000000000000000000000' as EvmAddress;\n","/**\n * Base class for errors thrown by the Polymarket SDK.\n */\nexport abstract class PolymarketError extends Error {\n /**\n * Returns `true` when the provided value is a `PolymarketError`.\n */\n static isError(error: unknown): error is PolymarketError {\n return error instanceof PolymarketError;\n }\n}\n\n/**\n * Error thrown when code reaches a state that should be impossible.\n */\nexport class InvariantError extends PolymarketError {\n override name = 'InvariantError' as const;\n}\n","import type { NonEmptyArray } from './array';\n\n/**\n * Returns `true` if the array contains at least one element.\n */\nexport function isNonEmptyArray<T>(\n value: readonly T[],\n): value is NonEmptyArray<T> {\n return value.length > 0;\n}\n\n/**\n * Returns `true` if the value is `null` or `undefined`.\n */\nexport function isNullish(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * Returns `true` if the value is not `null` or `undefined`.\n */\nexport function isPresent<T>(value: T): value is Exclude<T, null | undefined> {\n return !isNullish(value);\n}\n","import { InvariantError } from './errors';\n\nexport type { Tagged } from 'type-fest';\n\n/**\n * Flattens an object type for clearer IDE hovers and inferred signatures.\n */\nexport type Prettify<T> = {\n [K in keyof T]: T[K];\n} & {};\n\n/**\n * Asserts that a condition is truthy.\n *\n * @internal\n *\n * @param condition - Value expected to be truthy.\n * @param message - Message used for the thrown `InvariantError`.\n */\nexport function invariant(\n condition: unknown,\n message: string,\n): asserts condition {\n if (!condition) {\n throw new InvariantError(message);\n }\n}\n\n/**\n * Throws an `InvariantError` and narrows the current code path to `never`.\n *\n * Useful for unreachable branches and exhaustive checks.\n *\n * @param message - Message used for the thrown `InvariantError`.\n */\nexport function never(message = 'Unexpected call to never()'): never {\n throw new InvariantError(message);\n}\n\n/**\n * Resolves after the provided delay in milliseconds.\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction unrefTimer(timer: unknown): void {\n const maybeUnref = (timer as { unref?: () => void }).unref;\n if (typeof maybeUnref === 'function') maybeUnref.call(timer);\n}\n\n/**\n * Runs `callback` on an interval without forcing Node processes to stay alive\n * solely because the timer exists. In browsers, this behaves exactly like\n * `setInterval`.\n */\nexport function setNonBlockingInterval(\n callback: () => void,\n ms: number,\n): ReturnType<typeof setInterval> {\n const timer = setInterval(callback, ms);\n unrefTimer(timer);\n return timer;\n}\n\n/**\n * Runs `callback` after a timeout without forcing Node processes to stay alive\n * solely because the timer exists. In browsers, this behaves exactly like\n * `setTimeout`.\n */\nexport function setNonBlockingTimeout(\n callback: () => void,\n ms: number,\n): ReturnType<typeof setTimeout> {\n const timer = setTimeout(callback, ms);\n unrefTimer(timer);\n return timer;\n}\n","import type { Tagged } from 'type-fest';\n\n/**\n * A string encoded as hexadecimal and prefixed with `0x`.\n */\nexport type HexString = `0x${string}`;\n\n/**\n * A hex-encoded 32-byte private key prefixed with `0x`.\n */\nexport type PrivateKey = Tagged<HexString, 'PrivateKey'>;\n\n/**\n * An EVM account or contract address.\n */\nexport type EvmAddress = Tagged<HexString, 'EvmAddress'>;\n\n/**\n * A hex-encoded EVM signature.\n */\nexport type EvmSignature = Tagged<HexString, 'EvmSignature'>;\n\n/**\n * A hex-encoded ERC-1271 contract signature payload.\n */\nexport type Erc1271Signature = Tagged<HexString, 'Erc1271Signature'>;\n\n/**\n * A transaction hash returned by an EVM-compatible network.\n */\nexport type TxHash = Tagged<HexString, 'TxHash'>;\n\n/**\n * Checks whether a value is a hex string prefixed with `0x`.\n */\nexport function isHexString(value: unknown): value is HexString {\n return typeof value === 'string' && /^0x[a-fA-F0-9]+$/.test(value);\n}\n\n/**\n * Returns `true` when two EVM addresses are equal, ignoring checksum casing.\n */\nexport function isSameEvmAddress(left: EvmAddress, right: EvmAddress): boolean {\n return left.toLowerCase() === right.toLowerCase();\n}\n\n/**\n * Checks whether a value is a hex-encoded 32-byte private key.\n */\nexport function isPrivateKey(value: unknown): value is PrivateKey {\n return isHexString(value) && value.length === 66;\n}\n","import type { NonEmptyArray } from './array';\nimport { invariant } from './helpers';\nimport {\n type Erc1271Signature,\n type EvmAddress,\n type EvmSignature,\n type HexString,\n isHexString,\n isPrivateKey,\n type PrivateKey,\n type TxHash,\n} from './hex';\n\n/**\n * Refines a value to exclude `null` and `undefined`.\n */\nexport function expectPresent<T>(\n value: T,\n message = 'Expected value to be present',\n): Exclude<T, null | undefined> {\n invariant(value !== null && value !== undefined, message);\n return value as Exclude<T, null | undefined>;\n}\n\n/**\n * Refines an array to a non-empty tuple or throws when the array is empty.\n */\nexport function expectNonEmptyArray<T>(\n value: readonly T[],\n message = 'Expected a non-empty array',\n): NonEmptyArray<T> {\n invariant(value.length > 0, message);\n\n return value as NonEmptyArray<T>;\n}\n\n/**\n * Refines a string to a hex string or throws when the value is invalid.\n */\nexport function expectHexString(\n value: string,\n message = 'Expected a hex string',\n): HexString {\n invariant(isHexString(value), message);\n return value;\n}\n\n/**\n * Refines a string to a private key or throws when the value is invalid.\n */\nexport function expectPrivateKey(\n value: unknown,\n message = 'Expected a private key',\n): PrivateKey {\n invariant(isPrivateKey(value), message);\n return value;\n}\n\n/**\n * Refines a string to an EVM address or throws when the value is invalid.\n */\nexport function expectEvmAddress(\n value: unknown,\n message = 'Expected an EVM address',\n): EvmAddress {\n invariant(isHexString(value) && value.length === 42, message);\n return value as EvmAddress;\n}\n\n/**\n * Refines a string to an EVM signature or throws when the value is invalid.\n */\nexport function expectEvmSignature(\n value: unknown,\n message = 'Expected an EVM signature',\n): EvmSignature {\n invariant(isHexString(value) && value.length === 132, message);\n return value as EvmSignature;\n}\n\n/**\n * Refines a string to an ERC-1271 signature payload or throws when the value is invalid.\n */\nexport function expectErc1271Signature(\n value: unknown,\n message = 'Expected an ERC-1271 signature payload',\n): Erc1271Signature {\n invariant(isHexString(value), message);\n return value as Erc1271Signature;\n}\n\n/**\n * Refines a string to a transaction hash or throws when the value is invalid.\n */\nexport function expectTxHash(\n value: unknown,\n message = 'Expected a transaction hash',\n): TxHash {\n invariant(isHexString(value) && value.length === 66, message);\n return value as TxHash;\n}\n","import { type Result, ResultAsync } from 'neverthrow';\n\nfunction throwError(error: unknown): never {\n throw error;\n}\n\n/**\n * Extracts the success value from a {@link Result} or {@link ResultAsync}, or\n * throws the error branch.\n *\n * @example\n * ```ts\n * const value = unwrap(result.andThen(step1).andThen(step2));\n *\n * // value === 42\n * ```\n *\n * @internal\n *\n * @param result - Result to unwrap.\n * @returns The success value of the `result`.\n */\nexport function unwrap<T, E>(result: Result<T, E>): T;\nexport function unwrap<T, E>(result: ResultAsync<T, E>): Promise<T>;\nexport function unwrap<T, E>(\n result: Result<T, E> | ResultAsync<T, E>,\n): T | Promise<T> {\n if (result instanceof ResultAsync) {\n return result.match((value) => value, throwError);\n }\n\n return result.match((value) => value, throwError);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polymarket/types",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.4",
|
|
4
4
|
"description": "Shared TypeScript types for the Polymarket SDK.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Polymarket/ts-sdk",
|
|
8
|
+
"directory": "packages/types"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24"
|
|
13
|
+
},
|
|
6
14
|
"main": "dist/index.js",
|
|
7
15
|
"types": "dist/index.d.ts",
|
|
8
16
|
"exports": {
|