@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.
Files changed (105) hide show
  1. package/CHANGELOG.md +381 -0
  2. package/dist/builders/action.d.ts +22 -0
  3. package/dist/builders/action.d.ts.map +1 -0
  4. package/dist/builders/mod.d.ts +5 -0
  5. package/dist/builders/mod.d.ts.map +1 -0
  6. package/dist/builders/namespace.d.ts +47 -0
  7. package/dist/builders/namespace.d.ts.map +1 -0
  8. package/dist/builders/provider.d.ts +37 -0
  9. package/dist/builders/provider.d.ts.map +1 -0
  10. package/dist/builders/types.d.ts +23 -0
  11. package/dist/builders/types.d.ts.map +1 -0
  12. package/dist/hub/helpers.d.ts +6 -0
  13. package/dist/hub/helpers.d.ts.map +1 -0
  14. package/dist/hub/hub.d.ts +44 -0
  15. package/dist/hub/hub.d.ts.map +1 -0
  16. package/dist/hub/mod.d.ts +11 -0
  17. package/dist/hub/mod.d.ts.map +1 -0
  18. package/dist/hub/namespaces/errors.d.ts +5 -0
  19. package/dist/hub/namespaces/errors.d.ts.map +1 -0
  20. package/dist/hub/namespaces/mod.d.ts +3 -0
  21. package/dist/hub/namespaces/mod.d.ts.map +1 -0
  22. package/dist/hub/namespaces/namespace.d.ts +148 -0
  23. package/dist/hub/namespaces/namespace.d.ts.map +1 -0
  24. package/dist/hub/namespaces/types.d.ts +36 -0
  25. package/dist/hub/namespaces/types.d.ts.map +1 -0
  26. package/dist/hub/provider/mod.d.ts +3 -0
  27. package/dist/hub/provider/mod.d.ts.map +1 -0
  28. package/dist/hub/provider/provider.d.ts +102 -0
  29. package/dist/hub/provider/provider.d.ts.map +1 -0
  30. package/dist/hub/provider/types.d.ts +28 -0
  31. package/dist/hub/provider/types.d.ts.map +1 -0
  32. package/dist/hub/store/events.d.ts +54 -0
  33. package/dist/hub/store/events.d.ts.map +1 -0
  34. package/dist/hub/store/extend.d.ts +14 -0
  35. package/dist/hub/store/extend.d.ts.map +1 -0
  36. package/dist/hub/store/hub.d.ts +11 -0
  37. package/dist/hub/store/hub.d.ts.map +1 -0
  38. package/dist/hub/store/mod.d.ts +8 -0
  39. package/dist/hub/store/mod.d.ts.map +1 -0
  40. package/dist/hub/store/mod.js +2 -0
  41. package/dist/hub/store/mod.js.map +7 -0
  42. package/dist/hub/store/namespaces.d.ts +38 -0
  43. package/dist/hub/store/namespaces.d.ts.map +1 -0
  44. package/dist/hub/store/providers.d.ts +84 -0
  45. package/dist/hub/store/providers.d.ts.map +1 -0
  46. package/dist/hub/store/selectors.d.ts +18 -0
  47. package/dist/hub/store/selectors.d.ts.map +1 -0
  48. package/dist/hub/store/store.d.ts +14 -0
  49. package/dist/hub/store/store.d.ts.map +1 -0
  50. package/dist/hub/types.d.ts +5 -0
  51. package/dist/hub/types.d.ts.map +1 -0
  52. package/dist/mod.d.ts +5 -0
  53. package/dist/mod.d.ts.map +1 -0
  54. package/dist/mod.js +2 -0
  55. package/dist/mod.js.map +7 -0
  56. package/dist/test-utils/fixtures.d.ts +4 -0
  57. package/dist/test-utils/fixtures.d.ts.map +1 -0
  58. package/dist/test-utils/mod.d.ts +2 -0
  59. package/dist/test-utils/mod.d.ts.map +1 -0
  60. package/dist/test-utils/mod.js +2 -0
  61. package/dist/test-utils/mod.js.map +7 -0
  62. package/dist/utils/mod.d.ts +3 -0
  63. package/dist/utils/mod.d.ts.map +1 -0
  64. package/dist/utils/mod.js +2 -0
  65. package/dist/utils/mod.js.map +7 -0
  66. package/dist/utils/versions.d.ts +50 -0
  67. package/dist/utils/versions.d.ts.map +1 -0
  68. package/package.json +49 -0
  69. package/readme.md +4 -0
  70. package/src/builders/action.test.ts +225 -0
  71. package/src/builders/action.ts +86 -0
  72. package/src/builders/mod.ts +5 -0
  73. package/src/builders/namespace.ts +258 -0
  74. package/src/builders/provider.ts +101 -0
  75. package/src/builders/types.ts +28 -0
  76. package/src/hub/helpers.ts +11 -0
  77. package/src/hub/hub.test.ts +108 -0
  78. package/src/hub/hub.ts +145 -0
  79. package/src/hub/mod.ts +21 -0
  80. package/src/hub/namespaces/errors.ts +11 -0
  81. package/src/hub/namespaces/mod.ts +10 -0
  82. package/src/hub/namespaces/namespace.test.ts +443 -0
  83. package/src/hub/namespaces/namespace.ts +470 -0
  84. package/src/hub/namespaces/types.ts +58 -0
  85. package/src/hub/provider/mod.ts +9 -0
  86. package/src/hub/provider/provider.test.ts +277 -0
  87. package/src/hub/provider/provider.ts +286 -0
  88. package/src/hub/provider/types.ts +37 -0
  89. package/src/hub/store/events.ts +89 -0
  90. package/src/hub/store/extend.ts +125 -0
  91. package/src/hub/store/hub.ts +18 -0
  92. package/src/hub/store/mod.ts +26 -0
  93. package/src/hub/store/namespaces.ts +177 -0
  94. package/src/hub/store/providers.ts +183 -0
  95. package/src/hub/store/selectors.ts +59 -0
  96. package/src/hub/store/store.test.ts +50 -0
  97. package/src/hub/store/store.ts +30 -0
  98. package/src/hub/types.ts +13 -0
  99. package/src/mod.ts +27 -0
  100. package/src/test-utils/fixtures.ts +13 -0
  101. package/src/test-utils/mod.ts +1 -0
  102. package/src/utils/mod.ts +2 -0
  103. package/src/utils/versions.test.ts +23 -0
  104. package/src/utils/versions.ts +91 -0
  105. 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';
@@ -0,0 +1,2 @@
1
+ export type { VersionedProvider, VersionedProviders } from './versions.js';
2
+ export { defineVersions, pickVersion } from './versions.js';
@@ -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
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@hub3js/core/store",
3
+ "type": "module",
4
+ "main": "../dist/hub/store/mod.js",
5
+ "module": "../dist/hub/store/mod.js",
6
+ "types": "../dist/hub/store/mod.d.ts",
7
+ "sideEffects": false
8
+ }