@solana/options 2.0.0-20241006045741
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/LICENSE +20 -0
- package/README.md +234 -0
- package/dist/index.browser.cjs +128 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.mjs +116 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.native.mjs +116 -0
- package/dist/index.native.mjs.map +1 -0
- package/dist/index.node.cjs +128 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +116 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/option-codec.d.ts +96 -0
- package/dist/types/option-codec.d.ts.map +1 -0
- package/dist/types/option.d.ts +55 -0
- package/dist/types/option.d.ts.map +1 -0
- package/dist/types/unwrap-option-recursively.d.ts +30 -0
- package/dist/types/unwrap-option-recursively.d.ts.map +1 -0
- package/dist/types/unwrap-option.d.ts +12 -0
- package/dist/types/unwrap-option.d.ts.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An implementation of the Rust Option type in JavaScript.
|
|
3
|
+
* It can be one of the following:
|
|
4
|
+
* - <code>{@link Some}<T></code>: Meaning there is a value of type T.
|
|
5
|
+
* - <code>{@link None}</code>: Meaning there is no value.
|
|
6
|
+
*/
|
|
7
|
+
export type Option<T> = None | Some<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Defines a looser type that can be used when serializing an {@link Option}.
|
|
10
|
+
* This allows us to pass null or the Option value directly whilst still
|
|
11
|
+
* supporting the Option type for use-cases that need more type safety.
|
|
12
|
+
*/
|
|
13
|
+
export type OptionOrNullable<T> = Option<T> | T | null;
|
|
14
|
+
/**
|
|
15
|
+
* Represents an option of type `T` that has a value.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link Option}
|
|
18
|
+
*/
|
|
19
|
+
export type Some<T> = Readonly<{
|
|
20
|
+
__option: 'Some';
|
|
21
|
+
value: T;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Represents an option of type `T` that has no value.
|
|
25
|
+
*
|
|
26
|
+
* @see {@link Option}
|
|
27
|
+
*/
|
|
28
|
+
export type None = Readonly<{
|
|
29
|
+
__option: 'None';
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new {@link Option} of type `T` that has a value.
|
|
33
|
+
*
|
|
34
|
+
* @see {@link Option}
|
|
35
|
+
*/
|
|
36
|
+
export declare const some: <T>(value: T) => Option<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new {@link Option} of type `T` that has no value.
|
|
39
|
+
*
|
|
40
|
+
* @see {@link Option}
|
|
41
|
+
*/
|
|
42
|
+
export declare const none: <T>() => Option<T>;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the given data is an {@link Option}.
|
|
45
|
+
*/
|
|
46
|
+
export declare const isOption: <T = unknown>(input: unknown) => input is Option<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the given {@link Option} is a {@link Some}.
|
|
49
|
+
*/
|
|
50
|
+
export declare const isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the given {@link Option} is a {@link None}.
|
|
53
|
+
*/
|
|
54
|
+
export declare const isNone: <T>(option: Option<T>) => option is None;
|
|
55
|
+
//# sourceMappingURL=option.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option.d.ts","sourceRoot":"","sources":["../../src/option.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAEvC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,CAAC,KAAG,MAAM,CAAC,CAAC,CAAkC,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,OAAK,MAAM,CAAC,CAAC,CAA2B,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,mBAAmB,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,CAAC,CAMnE,CAAC;AAEN;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,UAAU,MAAM,CAAC,CAAC,CAAC,KAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAA+B,CAAC;AAE9F;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,UAAU,MAAM,CAAC,CAAC,CAAC,KAAG,MAAM,IAAI,IAAkC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { None, Some } from './option';
|
|
2
|
+
/**
|
|
3
|
+
* Lists all types that should not be recursively unwrapped.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link UnwrappedOption}
|
|
6
|
+
*/
|
|
7
|
+
type UnUnwrappables = Date | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | bigint | boolean | number | string | symbol | null | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* A type that defines the recursive unwrapping of a type `T`
|
|
10
|
+
* such that all nested {@link Option} types are unwrapped.
|
|
11
|
+
*
|
|
12
|
+
* For each nested {@link Option} type, if the option is a {@link Some},
|
|
13
|
+
* it returns the type of its value, otherwise, it returns the provided
|
|
14
|
+
* fallback type `U` which defaults to `null`.
|
|
15
|
+
*/
|
|
16
|
+
export type UnwrappedOption<T, U = null> = T extends Some<infer TValue> ? UnwrappedOption<TValue, U> : T extends None ? U : T extends UnUnwrappables ? T : T extends object ? {
|
|
17
|
+
[key in keyof T]: UnwrappedOption<T[key], U>;
|
|
18
|
+
} : T extends Array<infer TItem> ? Array<UnwrappedOption<TItem, U>> : T;
|
|
19
|
+
/**
|
|
20
|
+
* Recursively go through a type `T` such that all
|
|
21
|
+
* nested {@link Option} types are unwrapped.
|
|
22
|
+
*
|
|
23
|
+
* For each nested {@link Option} type, if the option is a {@link Some},
|
|
24
|
+
* it returns its value, otherwise, it returns the provided fallback value
|
|
25
|
+
* which defaults to `null`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function unwrapOptionRecursively<T>(input: T): UnwrappedOption<T>;
|
|
28
|
+
export declare function unwrapOptionRecursively<T, U>(input: T, fallback: () => U): UnwrappedOption<T, U>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=unwrap-option-recursively.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrap-option-recursively.d.ts","sourceRoot":"","sources":["../../src/unwrap-option-recursively.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAExD;;;;GAIG;AACH,KAAK,cAAc,GACb,IAAI,GACJ,SAAS,GACT,UAAU,GACV,UAAU,GACV,UAAU,GACV,WAAW,GACX,WAAW,GACX,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,GACN,IAAI,GACJ,SAAS,CAAC;AAEhB;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,IACnC,CAAC,SAAS,IAAI,CAAC,MAAM,MAAM,CAAC,GACtB,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,GAC1B,CAAC,SAAS,IAAI,GACZ,CAAC,GACD,CAAC,SAAS,cAAc,GACtB,CAAC,GACD,CAAC,SAAS,MAAM,GACd;KAAG,GAAG,IAAI,MAAM,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;CAAE,GAChD,CAAC,SAAS,KAAK,CAAC,MAAM,KAAK,CAAC,GAC1B,KAAK,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,GAChC,CAAC,CAAC;AAEpB;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;AACzE,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Option } from './option';
|
|
2
|
+
/**
|
|
3
|
+
* Unwraps the value of an {@link Option} of type `T`
|
|
4
|
+
* or returns a fallback value that defaults to `null`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function unwrapOption<T>(option: Option<T>): T | null;
|
|
7
|
+
export declare function unwrapOption<T, U>(option: Option<T>, fallback: () => U): T | U;
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a nullable value into an {@link Option}.
|
|
10
|
+
*/
|
|
11
|
+
export declare const wrapNullable: <T>(nullable: T | null) => Option<T>;
|
|
12
|
+
//# sourceMappingURL=unwrap-option.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrap-option.d.ts","sourceRoot":"","sources":["../../src/unwrap-option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAQ,MAAM,UAAU,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AAC7D,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAMhF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,YAAY,CAAC,GAAG,IAAI,KAAG,MAAM,CAAC,CAAC,CAAqD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solana/options",
|
|
3
|
+
"version": "2.0.0-20241006045741",
|
|
4
|
+
"description": "Managing and serializing Rust-like Option types in JavaScript",
|
|
5
|
+
"exports": {
|
|
6
|
+
"edge-light": {
|
|
7
|
+
"import": "./dist/index.node.mjs",
|
|
8
|
+
"require": "./dist/index.node.cjs"
|
|
9
|
+
},
|
|
10
|
+
"workerd": {
|
|
11
|
+
"import": "./dist/index.node.mjs",
|
|
12
|
+
"require": "./dist/index.node.cjs"
|
|
13
|
+
},
|
|
14
|
+
"browser": {
|
|
15
|
+
"import": "./dist/index.browser.mjs",
|
|
16
|
+
"require": "./dist/index.browser.cjs"
|
|
17
|
+
},
|
|
18
|
+
"node": {
|
|
19
|
+
"import": "./dist/index.node.mjs",
|
|
20
|
+
"require": "./dist/index.node.cjs"
|
|
21
|
+
},
|
|
22
|
+
"react-native": "./dist/index.native.mjs",
|
|
23
|
+
"types": "./dist/types/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"browser": {
|
|
26
|
+
"./dist/index.node.cjs": "./dist/index.browser.cjs",
|
|
27
|
+
"./dist/index.node.mjs": "./dist/index.browser.mjs"
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.node.cjs",
|
|
30
|
+
"module": "./dist/index.node.mjs",
|
|
31
|
+
"react-native": "./dist/index.native.mjs",
|
|
32
|
+
"types": "./dist/types/index.d.ts",
|
|
33
|
+
"type": "commonjs",
|
|
34
|
+
"files": [
|
|
35
|
+
"./dist/"
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"keywords": [
|
|
39
|
+
"blockchain",
|
|
40
|
+
"solana",
|
|
41
|
+
"web3"
|
|
42
|
+
],
|
|
43
|
+
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/solana-labs/solana-web3.js"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "http://github.com/solana-labs/solana-web3.js/issues"
|
|
51
|
+
},
|
|
52
|
+
"browserslist": [
|
|
53
|
+
"supports bigint and not dead",
|
|
54
|
+
"maintained node versions"
|
|
55
|
+
],
|
|
56
|
+
"engine": {
|
|
57
|
+
"node": ">=17.4"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@solana/codecs-core": "2.0.0-20241006045741",
|
|
61
|
+
"@solana/codecs-data-structures": "2.0.0-20241006045741",
|
|
62
|
+
"@solana/codecs-numbers": "2.0.0-20241006045741",
|
|
63
|
+
"@solana/codecs-strings": "2.0.0-20241006045741",
|
|
64
|
+
"@solana/errors": "2.0.0-20241006045741"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"typescript": ">=5"
|
|
68
|
+
},
|
|
69
|
+
"bundlewatch": {
|
|
70
|
+
"defaultCompression": "gzip",
|
|
71
|
+
"files": [
|
|
72
|
+
{
|
|
73
|
+
"path": "./dist/index*.js"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
79
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
80
|
+
"dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
81
|
+
"publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag ${PUBLISH_TAG:-canary} --access public --no-git-checks",
|
|
82
|
+
"publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
|
|
83
|
+
"style:fix": "pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*",
|
|
84
|
+
"test:lint": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
85
|
+
"test:prettier": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
86
|
+
"test:treeshakability:browser": "agadoo dist/index.browser.mjs",
|
|
87
|
+
"test:treeshakability:native": "agadoo dist/index.node.mjs",
|
|
88
|
+
"test:treeshakability:node": "agadoo dist/index.native.mjs",
|
|
89
|
+
"test:typecheck": "tsc --noEmit",
|
|
90
|
+
"test:unit:browser": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
91
|
+
"test:unit:node": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
92
|
+
}
|
|
93
|
+
}
|