@hub3js/core 0.0.0-experimental-03bf1f89-20260602
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 +381 -0
- package/dist/builders/action.d.ts +22 -0
- package/dist/builders/action.d.ts.map +1 -0
- package/dist/builders/mod.d.ts +5 -0
- package/dist/builders/mod.d.ts.map +1 -0
- package/dist/builders/namespace.d.ts +47 -0
- package/dist/builders/namespace.d.ts.map +1 -0
- package/dist/builders/provider.d.ts +37 -0
- package/dist/builders/provider.d.ts.map +1 -0
- package/dist/builders/types.d.ts +23 -0
- package/dist/builders/types.d.ts.map +1 -0
- package/dist/hub/helpers.d.ts +6 -0
- package/dist/hub/helpers.d.ts.map +1 -0
- package/dist/hub/hub.d.ts +44 -0
- package/dist/hub/hub.d.ts.map +1 -0
- package/dist/hub/mod.d.ts +11 -0
- package/dist/hub/mod.d.ts.map +1 -0
- package/dist/hub/namespaces/errors.d.ts +5 -0
- package/dist/hub/namespaces/errors.d.ts.map +1 -0
- package/dist/hub/namespaces/mod.d.ts +3 -0
- package/dist/hub/namespaces/mod.d.ts.map +1 -0
- package/dist/hub/namespaces/namespace.d.ts +148 -0
- package/dist/hub/namespaces/namespace.d.ts.map +1 -0
- package/dist/hub/namespaces/types.d.ts +36 -0
- package/dist/hub/namespaces/types.d.ts.map +1 -0
- package/dist/hub/provider/mod.d.ts +3 -0
- package/dist/hub/provider/mod.d.ts.map +1 -0
- package/dist/hub/provider/provider.d.ts +102 -0
- package/dist/hub/provider/provider.d.ts.map +1 -0
- package/dist/hub/provider/types.d.ts +28 -0
- package/dist/hub/provider/types.d.ts.map +1 -0
- package/dist/hub/store/events.d.ts +54 -0
- package/dist/hub/store/events.d.ts.map +1 -0
- package/dist/hub/store/extend.d.ts +14 -0
- package/dist/hub/store/extend.d.ts.map +1 -0
- package/dist/hub/store/hub.d.ts +11 -0
- package/dist/hub/store/hub.d.ts.map +1 -0
- package/dist/hub/store/mod.d.ts +8 -0
- package/dist/hub/store/mod.d.ts.map +1 -0
- package/dist/hub/store/mod.js +2 -0
- package/dist/hub/store/mod.js.map +7 -0
- package/dist/hub/store/namespaces.d.ts +38 -0
- package/dist/hub/store/namespaces.d.ts.map +1 -0
- package/dist/hub/store/providers.d.ts +84 -0
- package/dist/hub/store/providers.d.ts.map +1 -0
- package/dist/hub/store/selectors.d.ts +18 -0
- package/dist/hub/store/selectors.d.ts.map +1 -0
- package/dist/hub/store/store.d.ts +14 -0
- package/dist/hub/store/store.d.ts.map +1 -0
- package/dist/hub/types.d.ts +5 -0
- package/dist/hub/types.d.ts.map +1 -0
- package/dist/mod.d.ts +5 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +2 -0
- package/dist/mod.js.map +7 -0
- package/dist/test-utils/fixtures.d.ts +4 -0
- package/dist/test-utils/fixtures.d.ts.map +1 -0
- package/dist/test-utils/mod.d.ts +2 -0
- package/dist/test-utils/mod.d.ts.map +1 -0
- package/dist/test-utils/mod.js +2 -0
- package/dist/test-utils/mod.js.map +7 -0
- package/dist/utils/mod.d.ts +3 -0
- package/dist/utils/mod.d.ts.map +1 -0
- package/dist/utils/mod.js +2 -0
- package/dist/utils/mod.js.map +7 -0
- package/dist/utils/versions.d.ts +50 -0
- package/dist/utils/versions.d.ts.map +1 -0
- package/package.json +49 -0
- package/readme.md +4 -0
- package/src/builders/action.test.ts +225 -0
- package/src/builders/action.ts +86 -0
- package/src/builders/mod.ts +5 -0
- package/src/builders/namespace.ts +258 -0
- package/src/builders/provider.ts +101 -0
- package/src/builders/types.ts +28 -0
- package/src/hub/helpers.ts +11 -0
- package/src/hub/hub.test.ts +108 -0
- package/src/hub/hub.ts +145 -0
- package/src/hub/mod.ts +21 -0
- package/src/hub/namespaces/errors.ts +11 -0
- package/src/hub/namespaces/mod.ts +10 -0
- package/src/hub/namespaces/namespace.test.ts +443 -0
- package/src/hub/namespaces/namespace.ts +470 -0
- package/src/hub/namespaces/types.ts +58 -0
- package/src/hub/provider/mod.ts +9 -0
- package/src/hub/provider/provider.test.ts +277 -0
- package/src/hub/provider/provider.ts +286 -0
- package/src/hub/provider/types.ts +37 -0
- package/src/hub/store/events.ts +89 -0
- package/src/hub/store/extend.ts +125 -0
- package/src/hub/store/hub.ts +18 -0
- package/src/hub/store/mod.ts +26 -0
- package/src/hub/store/namespaces.ts +177 -0
- package/src/hub/store/providers.ts +183 -0
- package/src/hub/store/selectors.ts +59 -0
- package/src/hub/store/store.test.ts +50 -0
- package/src/hub/store/store.ts +30 -0
- package/src/hub/types.ts +13 -0
- package/src/mod.ts +27 -0
- package/src/test-utils/fixtures.ts +13 -0
- package/src/test-utils/mod.ts +1 -0
- package/src/utils/mod.ts +2 -0
- package/src/utils/versions.test.ts +23 -0
- package/src/utils/versions.ts +91 -0
- package/store/package.json +8 -0
package/src/mod.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
Actions,
|
|
3
|
+
RegisteredNamespaces,
|
|
4
|
+
Store,
|
|
5
|
+
State,
|
|
6
|
+
ProviderMetadata,
|
|
7
|
+
Subscriber,
|
|
8
|
+
SubscriberCleanUp,
|
|
9
|
+
Context,
|
|
10
|
+
CanEagerConnect,
|
|
11
|
+
FunctionWithContext,
|
|
12
|
+
} from './hub/mod.js';
|
|
13
|
+
export {
|
|
14
|
+
Hub,
|
|
15
|
+
Provider,
|
|
16
|
+
Namespace,
|
|
17
|
+
createStore,
|
|
18
|
+
guessProviderStateSelector,
|
|
19
|
+
namespaceStateSelector,
|
|
20
|
+
} from './hub/mod.js';
|
|
21
|
+
|
|
22
|
+
export type { ProxiedNamespace, FindProxiedNamespace } from './builders/mod.js';
|
|
23
|
+
export {
|
|
24
|
+
NamespaceBuilder,
|
|
25
|
+
ProviderBuilder,
|
|
26
|
+
ActionBuilder,
|
|
27
|
+
} from './builders/mod.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProviderConfig, ProviderInfo } from '../hub/store/mod.js';
|
|
2
|
+
|
|
3
|
+
export const garbageWalletMetaData: ProviderConfig['metadata'] = {
|
|
4
|
+
name: 'Garbage Wallet',
|
|
5
|
+
icon: 'https://somewhereininternet.com/icon.svg',
|
|
6
|
+
extensions: {
|
|
7
|
+
homepage: 'https://app.rango.exchange',
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const garbageWalletInfo: ProviderInfo = {
|
|
12
|
+
metadata: garbageWalletMetaData,
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { garbageWalletMetaData, garbageWalletInfo } from './fixtures.js';
|
package/src/utils/mod.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { defineVersions, pickVersion } from './versions.js';
|
|
4
|
+
|
|
5
|
+
describe('Picking versions should work correctly', () => {
|
|
6
|
+
test("Error on picking a version doesn't exist", () => {
|
|
7
|
+
const versions = defineVersions().build();
|
|
8
|
+
expect(() => pickVersion(versions, '1.0.0')).toThrowError();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('Pick the correct version if it exist', () => {
|
|
12
|
+
const versions = defineVersions()
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
.version('0.0.0', {} as any)
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
.version('1.0.0', {} as any)
|
|
17
|
+
.build();
|
|
18
|
+
|
|
19
|
+
const target = pickVersion(versions, '1.0.0');
|
|
20
|
+
expect(target).toBeDefined();
|
|
21
|
+
expect(target[0]).toBe('1.0.0');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `[semver, value]` tuple describing one version of a provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Generic over both the version string and the value so consumers can use this
|
|
5
|
+
* for any kind of versioned provider, not just the `@hub3js/core` Hub.
|
|
6
|
+
*/
|
|
7
|
+
export type VersionedProvider<
|
|
8
|
+
V extends string = string,
|
|
9
|
+
T = unknown,
|
|
10
|
+
> = readonly [V, T];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A list of `VersionedProvider` tuples — i.e., the full set of versions one
|
|
14
|
+
* provider exposes. Kept as a public alias so downstream consumers porting
|
|
15
|
+
* from `@rango-dev/wallets-core/utils` can keep their existing imports.
|
|
16
|
+
*/
|
|
17
|
+
export type VersionedProviders = readonly VersionedProvider[];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Allowed `targetVersion` values for a given list. When the list is empty
|
|
21
|
+
* (`T[number][0]` is `never`), fall back to `string` so the runtime
|
|
22
|
+
* "version not found" guard remains reachable.
|
|
23
|
+
*/
|
|
24
|
+
type AllowedVersion<T extends readonly VersionedProvider[]> = [
|
|
25
|
+
T[number][0],
|
|
26
|
+
] extends [never]
|
|
27
|
+
? string
|
|
28
|
+
: T[number][0];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Look up a specific version in a `VersionedProviders` list.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const versions = defineVersions()
|
|
36
|
+
* .version('1.0.0', myProvider)
|
|
37
|
+
* .build();
|
|
38
|
+
*
|
|
39
|
+
* const [, provider] = pickVersion(versions, '1.0.0');
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function pickVersion<
|
|
43
|
+
T extends readonly VersionedProvider[],
|
|
44
|
+
V extends AllowedVersion<T>,
|
|
45
|
+
>(list: T, targetVersion: V): Extract<T[number], readonly [V, unknown]> {
|
|
46
|
+
if (!targetVersion) {
|
|
47
|
+
throw new Error(`You should provide a valid semver, e.g 1.0.0.`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const target = list.find(([version]) => version === targetVersion);
|
|
51
|
+
|
|
52
|
+
if (!target) {
|
|
53
|
+
const available = list.map(([version]) => version).join(', ');
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Target version "${targetVersion}" hasn't been found. Available versions: ${available}`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return target as Extract<T[number], readonly [V, unknown]>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface VersionsBuilder<T extends readonly VersionedProvider[]> {
|
|
63
|
+
/**
|
|
64
|
+
* Register a `[semver, value]` pair. The version string is preserved as a
|
|
65
|
+
* literal in the resulting type so `pickVersion` can return precise types.
|
|
66
|
+
*/
|
|
67
|
+
version<const V extends string, P>(
|
|
68
|
+
semver: V,
|
|
69
|
+
value: P,
|
|
70
|
+
): VersionsBuilder<readonly [...T, readonly [V, P]]>;
|
|
71
|
+
build(): T;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Fluent builder for a `VersionedProviders` list. Each `.version()` call
|
|
76
|
+
* accumulates into the inferred type so the final `build()` returns a
|
|
77
|
+
* precisely-typed tuple of tuples.
|
|
78
|
+
*/
|
|
79
|
+
export function defineVersions(): VersionsBuilder<readonly []> {
|
|
80
|
+
const make = <T extends readonly VersionedProvider[]>(
|
|
81
|
+
acc: T,
|
|
82
|
+
): VersionsBuilder<T> => ({
|
|
83
|
+
version: <const V extends string, P>(semver: V, value: P) =>
|
|
84
|
+
make<readonly [...T, readonly [V, P]]>([
|
|
85
|
+
...acc,
|
|
86
|
+
[semver, value] as const,
|
|
87
|
+
] as const),
|
|
88
|
+
build: () => acc,
|
|
89
|
+
});
|
|
90
|
+
return make([] as const);
|
|
91
|
+
}
|