hyperstack-typescript 0.4.3 → 0.5.1
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 +101 -24
- package/dist/index.esm.js +519 -102
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +529 -102
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -92,7 +92,7 @@ interface ResolvedAccount {
|
|
|
92
92
|
* Result of account resolution.
|
|
93
93
|
*/
|
|
94
94
|
interface AccountResolutionResult {
|
|
95
|
-
/** All resolved accounts */
|
|
95
|
+
/** All resolved accounts in order */
|
|
96
96
|
accounts: ResolvedAccount[];
|
|
97
97
|
/** Accounts that need to be provided by the user */
|
|
98
98
|
missingUserAccounts: string[];
|
|
@@ -105,13 +105,19 @@ interface AccountResolutionOptions {
|
|
|
105
105
|
accounts?: Record<string, string>;
|
|
106
106
|
/** Wallet adapter for signer accounts */
|
|
107
107
|
wallet?: WalletAdapter;
|
|
108
|
+
/** Program ID for PDA derivation (required if any PDAs exist) */
|
|
109
|
+
programId?: string;
|
|
108
110
|
}
|
|
109
111
|
/**
|
|
110
112
|
* Resolves instruction accounts by categorizing and deriving addresses.
|
|
111
113
|
*
|
|
114
|
+
* Resolution order:
|
|
115
|
+
* 1. Non-PDA accounts (signer, known, userProvided) are resolved first
|
|
116
|
+
* 2. PDA accounts are resolved in dependency order (accounts they reference come first)
|
|
117
|
+
*
|
|
112
118
|
* @param accountMetas - Account metadata from the instruction definition
|
|
113
|
-
* @param args - Instruction arguments (used for PDA derivation)
|
|
114
|
-
* @param options - Resolution options including wallet
|
|
119
|
+
* @param args - Instruction arguments (used for PDA derivation with argRef seeds)
|
|
120
|
+
* @param options - Resolution options including wallet, user-provided accounts, and programId
|
|
115
121
|
* @returns Resolved accounts and any missing required accounts
|
|
116
122
|
*/
|
|
117
123
|
declare function resolveAccounts(accountMetas: AccountMeta[], args: Record<string, unknown>, options: AccountResolutionOptions): AccountResolutionResult;
|
|
@@ -124,35 +130,52 @@ declare function resolveAccounts(accountMetas: AccountMeta[], args: Record<strin
|
|
|
124
130
|
declare function validateAccountResolution(result: AccountResolutionResult): void;
|
|
125
131
|
|
|
126
132
|
/**
|
|
127
|
-
*
|
|
133
|
+
* PDA (Program Derived Address) derivation utilities.
|
|
128
134
|
*
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*
|
|
135
|
+
* Implements Solana's PDA derivation algorithm without depending on @solana/web3.js.
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* Decode base58 string to Uint8Array.
|
|
139
|
+
*/
|
|
140
|
+
declare function decodeBase58(str: string): Uint8Array;
|
|
141
|
+
/**
|
|
142
|
+
* Encode Uint8Array to base58 string.
|
|
143
|
+
*/
|
|
144
|
+
declare function encodeBase58(bytes: Uint8Array): string;
|
|
145
|
+
/**
|
|
146
|
+
* Derives a Program-Derived Address (PDA) from seeds and program ID.
|
|
133
147
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
148
|
+
* Algorithm:
|
|
149
|
+
* 1. For bump = 255 down to 0:
|
|
150
|
+
* a. Concatenate: seeds + [bump] + programId + "ProgramDerivedAddress"
|
|
151
|
+
* b. SHA-256 hash the concatenation
|
|
152
|
+
* c. If result is off the ed25519 curve, return it
|
|
153
|
+
* 2. If no valid PDA found after 256 attempts, throw error
|
|
136
154
|
*
|
|
137
|
-
* @param seeds - Array of seed buffers
|
|
138
|
-
* @param programId - The program ID (
|
|
139
|
-
* @returns
|
|
155
|
+
* @param seeds - Array of seed buffers (max 32 bytes each, max 16 seeds)
|
|
156
|
+
* @param programId - The program ID (base58 string)
|
|
157
|
+
* @returns Tuple of [derivedAddress (base58), bumpSeed]
|
|
158
|
+
*/
|
|
159
|
+
declare function findProgramAddress(seeds: Uint8Array[], programId: string): Promise<[string, number]>;
|
|
160
|
+
/**
|
|
161
|
+
* Synchronous version of findProgramAddress.
|
|
162
|
+
* Uses synchronous SHA-256 (Node.js crypto module).
|
|
140
163
|
*/
|
|
141
|
-
declare function
|
|
164
|
+
declare function findProgramAddressSync(seeds: Uint8Array[], programId: string): [string, number];
|
|
142
165
|
/**
|
|
143
166
|
* Creates a seed buffer from various input types.
|
|
144
167
|
*
|
|
145
168
|
* @param value - The value to convert to a seed
|
|
146
|
-
* @returns
|
|
169
|
+
* @returns Uint8Array suitable for PDA derivation
|
|
147
170
|
*/
|
|
148
|
-
declare function createSeed(value: string |
|
|
171
|
+
declare function createSeed(value: string | Uint8Array | bigint | number): Uint8Array;
|
|
149
172
|
/**
|
|
150
173
|
* Creates a public key seed from a base58-encoded address.
|
|
151
174
|
*
|
|
152
175
|
* @param address - Base58-encoded public key
|
|
153
|
-
* @returns 32-byte
|
|
176
|
+
* @returns 32-byte Uint8Array
|
|
154
177
|
*/
|
|
155
|
-
declare function createPublicKeySeed(address: string):
|
|
178
|
+
declare function createPublicKeySeed(address: string): Uint8Array;
|
|
156
179
|
|
|
157
180
|
/**
|
|
158
181
|
* Borsh-compatible instruction data serializer.
|
|
@@ -314,6 +337,8 @@ interface InstructionHandler {
|
|
|
314
337
|
accounts: AccountMeta[];
|
|
315
338
|
/** Error definitions - used by core SDK for error parsing */
|
|
316
339
|
errors: ErrorMetadata[];
|
|
340
|
+
/** Program ID for this instruction (used for PDA derivation) */
|
|
341
|
+
programId?: string;
|
|
317
342
|
}
|
|
318
343
|
/**
|
|
319
344
|
* @deprecated Use InstructionHandler instead. Will be removed in next major version.
|
|
@@ -358,6 +383,40 @@ declare function createInstructionExecutor(wallet: WalletAdapter): {
|
|
|
358
383
|
execute: (handler: InstructionHandler, args: Record<string, unknown>, options?: Omit<ExecuteOptions, "wallet">) => Promise<ExecutionResult>;
|
|
359
384
|
};
|
|
360
385
|
|
|
386
|
+
type SeedDef = {
|
|
387
|
+
type: 'literal';
|
|
388
|
+
value: string;
|
|
389
|
+
} | {
|
|
390
|
+
type: 'bytes';
|
|
391
|
+
value: Uint8Array;
|
|
392
|
+
} | {
|
|
393
|
+
type: 'argRef';
|
|
394
|
+
argName: string;
|
|
395
|
+
argType?: string;
|
|
396
|
+
} | {
|
|
397
|
+
type: 'accountRef';
|
|
398
|
+
accountName: string;
|
|
399
|
+
};
|
|
400
|
+
interface PdaDeriveContext {
|
|
401
|
+
accounts?: Record<string, string>;
|
|
402
|
+
args?: Record<string, unknown>;
|
|
403
|
+
programId?: string;
|
|
404
|
+
}
|
|
405
|
+
interface PdaFactory {
|
|
406
|
+
readonly seeds: readonly SeedDef[];
|
|
407
|
+
readonly programId: string;
|
|
408
|
+
program(programId: string): PdaFactory;
|
|
409
|
+
derive(context: PdaDeriveContext): Promise<string>;
|
|
410
|
+
deriveSync(context: PdaDeriveContext): string;
|
|
411
|
+
}
|
|
412
|
+
declare function literal(value: string): SeedDef;
|
|
413
|
+
declare function account(name: string): SeedDef;
|
|
414
|
+
declare function arg(name: string, type?: string): SeedDef;
|
|
415
|
+
declare function bytes(value: Uint8Array): SeedDef;
|
|
416
|
+
declare function pda(programId: string, ...seeds: SeedDef[]): PdaFactory;
|
|
417
|
+
type ProgramPdas<T extends Record<string, PdaFactory>> = T;
|
|
418
|
+
declare function createProgramPdas<T extends Record<string, PdaFactory>>(pdas: T): ProgramPdas<T>;
|
|
419
|
+
|
|
361
420
|
type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'error';
|
|
362
421
|
type Update<T> = {
|
|
363
422
|
type: 'upsert';
|
|
@@ -395,6 +454,7 @@ interface StackDefinition {
|
|
|
395
454
|
readonly name: string;
|
|
396
455
|
readonly url: string;
|
|
397
456
|
readonly views: Record<string, ViewGroup>;
|
|
457
|
+
readonly schemas?: Record<string, Schema<unknown>>;
|
|
398
458
|
instructions?: Record<string, InstructionHandler>;
|
|
399
459
|
}
|
|
400
460
|
interface ViewGroup {
|
|
@@ -409,16 +469,28 @@ interface Subscription {
|
|
|
409
469
|
take?: number;
|
|
410
470
|
skip?: number;
|
|
411
471
|
}
|
|
412
|
-
|
|
472
|
+
type SchemaResult<T> = {
|
|
473
|
+
success: true;
|
|
474
|
+
data: T;
|
|
475
|
+
} | {
|
|
476
|
+
success: false;
|
|
477
|
+
error: unknown;
|
|
478
|
+
};
|
|
479
|
+
interface Schema<T> {
|
|
480
|
+
safeParse: (input: unknown) => SchemaResult<T>;
|
|
481
|
+
}
|
|
482
|
+
interface WatchOptions<TSchema = unknown> {
|
|
413
483
|
take?: number;
|
|
414
484
|
skip?: number;
|
|
415
485
|
filters?: Record<string, string>;
|
|
486
|
+
schema?: Schema<TSchema>;
|
|
416
487
|
}
|
|
417
488
|
interface HyperStackOptions<TStack extends StackDefinition> {
|
|
418
489
|
stack: TStack;
|
|
419
490
|
autoReconnect?: boolean;
|
|
420
491
|
reconnectIntervals?: number[];
|
|
421
492
|
maxReconnectAttempts?: number;
|
|
493
|
+
validateFrames?: boolean;
|
|
422
494
|
}
|
|
423
495
|
declare const DEFAULT_MAX_ENTRIES_PER_VIEW = 10000;
|
|
424
496
|
interface HyperStackConfig {
|
|
@@ -441,14 +513,14 @@ type TypedViewGroup<TGroup> = {
|
|
|
441
513
|
[K in keyof TGroup]: TGroup[K] extends ViewDef<infer T, 'state'> ? TypedStateView<T> : TGroup[K] extends ViewDef<infer T, 'list'> ? TypedListView<T> : never;
|
|
442
514
|
};
|
|
443
515
|
interface TypedStateView<T> {
|
|
444
|
-
use(key: string, options?: WatchOptions): AsyncIterable<
|
|
516
|
+
use<TSchema = T>(key: string, options?: WatchOptions<TSchema>): AsyncIterable<TSchema>;
|
|
445
517
|
watch(key: string, options?: WatchOptions): AsyncIterable<Update<T>>;
|
|
446
518
|
watchRich(key: string, options?: WatchOptions): AsyncIterable<RichUpdate<T>>;
|
|
447
519
|
get(key: string): Promise<T | null>;
|
|
448
520
|
getSync(key: string): T | null | undefined;
|
|
449
521
|
}
|
|
450
522
|
interface TypedListView<T> {
|
|
451
|
-
use(options?: WatchOptions): AsyncIterable<
|
|
523
|
+
use<TSchema = T>(options?: WatchOptions<TSchema>): AsyncIterable<TSchema>;
|
|
452
524
|
watch(options?: WatchOptions): AsyncIterable<Update<T>>;
|
|
453
525
|
watchRich(options?: WatchOptions): AsyncIterable<RichUpdate<T>>;
|
|
454
526
|
get(): Promise<T[]>;
|
|
@@ -585,6 +657,7 @@ interface ConnectOptions {
|
|
|
585
657
|
reconnectIntervals?: number[];
|
|
586
658
|
maxReconnectAttempts?: number;
|
|
587
659
|
flushIntervalMs?: number;
|
|
660
|
+
validateFrames?: boolean;
|
|
588
661
|
}
|
|
589
662
|
/** @deprecated Use ConnectOptions instead */
|
|
590
663
|
interface HyperStackOptionsWithStorage<TStack extends StackDefinition> extends HyperStackOptions<TStack> {
|
|
@@ -637,15 +710,19 @@ interface FrameProcessorConfig {
|
|
|
637
710
|
* reduce unnecessary re-renders during high-frequency updates.
|
|
638
711
|
*/
|
|
639
712
|
flushIntervalMs?: number;
|
|
713
|
+
schemas?: Record<string, Schema<unknown>>;
|
|
640
714
|
}
|
|
641
715
|
declare class FrameProcessor {
|
|
642
716
|
private storage;
|
|
643
717
|
private maxEntriesPerView;
|
|
644
718
|
private flushIntervalMs;
|
|
719
|
+
private schemas?;
|
|
645
720
|
private pendingUpdates;
|
|
646
721
|
private flushTimer;
|
|
647
722
|
private isProcessing;
|
|
648
723
|
constructor(storage: StorageAdapter, config?: FrameProcessorConfig);
|
|
724
|
+
private getSchema;
|
|
725
|
+
private validateEntity;
|
|
649
726
|
handleFrame<T>(frame: Frame<T>): void;
|
|
650
727
|
/**
|
|
651
728
|
* Immediately flush all pending updates.
|
|
@@ -731,12 +808,12 @@ declare class MemoryAdapter implements StorageAdapter {
|
|
|
731
808
|
}
|
|
732
809
|
|
|
733
810
|
declare function createUpdateStream<T>(storage: StorageAdapter, subscriptionRegistry: SubscriptionRegistry, subscription: Subscription, keyFilter?: string): AsyncIterable<Update<T>>;
|
|
734
|
-
declare function createEntityStream<T>(storage: StorageAdapter, subscriptionRegistry: SubscriptionRegistry, subscription: Subscription, keyFilter?: string): AsyncIterable<T>;
|
|
811
|
+
declare function createEntityStream<T>(storage: StorageAdapter, subscriptionRegistry: SubscriptionRegistry, subscription: Subscription, options?: WatchOptions<any>, keyFilter?: string): AsyncIterable<T>;
|
|
735
812
|
declare function createRichUpdateStream<T>(storage: StorageAdapter, subscriptionRegistry: SubscriptionRegistry, subscription: Subscription, keyFilter?: string): AsyncIterable<RichUpdate<T>>;
|
|
736
813
|
|
|
737
814
|
declare function createTypedStateView<T>(viewDef: ViewDef<T, 'state'>, storage: StorageAdapter, subscriptionRegistry: SubscriptionRegistry): TypedStateView<T>;
|
|
738
815
|
declare function createTypedListView<T>(viewDef: ViewDef<T, 'list'>, storage: StorageAdapter, subscriptionRegistry: SubscriptionRegistry): TypedListView<T>;
|
|
739
816
|
declare function createTypedViews<TStack extends StackDefinition>(stack: TStack, storage: StorageAdapter, subscriptionRegistry: SubscriptionRegistry): TypedViews<TStack['views']>;
|
|
740
817
|
|
|
741
|
-
export { ConnectionManager, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, EntityStore, FrameProcessor, HyperStack, HyperStackError, MemoryAdapter, SubscriptionRegistry, createEntityStream, createInstructionExecutor, createPublicKeySeed, createRichUpdateStream, createSeed, createTypedListView, createTypedStateView, createTypedViews, createUpdateStream, derivePda, executeInstruction, formatProgramError, isEntityFrame, isSnapshotFrame, isSubscribedFrame, isValidFrame, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, serializeInstructionData, validateAccountResolution, waitForConfirmation };
|
|
742
|
-
export type { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, ArgSchema, ArgType, BuiltInstruction, ConfirmationLevel,
|
|
818
|
+
export { ConnectionManager, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, EntityStore, FrameProcessor, HyperStack, HyperStackError, MemoryAdapter, SubscriptionRegistry, account, arg, bytes, createEntityStream, createInstructionExecutor, createProgramPdas, createPublicKeySeed, createRichUpdateStream, createSeed, createTypedListView, createTypedStateView, createTypedViews, createUpdateStream, decodeBase58, findProgramAddress as derivePda, encodeBase58, executeInstruction, findProgramAddress, findProgramAddressSync, formatProgramError, isEntityFrame, isSnapshotFrame, isSubscribedFrame, isValidFrame, literal, parseFrame, parseFrameFromBlob, parseInstructionError, pda, resolveAccounts, serializeInstructionData, validateAccountResolution, waitForConfirmation };
|
|
819
|
+
export type { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, ArgSchema, ArgType, BuiltInstruction, ConfirmationLevel, ConnectionState, ConnectionStateCallback, EntityFrame, EntityStoreConfig, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessorConfig, HyperStackConfig, HyperStackOptions, HyperStackOptionsWithStorage, InstructionDefinition, InstructionExecutor, InstructionExecutorOptions, InstructionHandler, PdaConfig, PdaDeriveContext, PdaFactory, PdaSeed, ProgramError, ProgramPdas, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback$1 as RichUpdateCallback, Schema, SchemaResult, SeedDef, SnapshotEntity, SnapshotFrame, SortConfig, SortOrder, StackDefinition, StorageAdapter, StorageAdapterConfig, SubscribeCallback, SubscribedFrame, Subscription, TypedListView, TypedStateView, TypedViewGroup, TypedViews, UnsubscribeFn, Update, UpdateCallback, ViewConfig, ViewDef, ViewGroup, ViewSortConfig, WalletAdapter, WalletConnectOptions, WalletState, WatchOptions };
|