@arcblock/payment-service 1.29.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/drivers.d.ts +144 -0
- package/dist/drivers.js +850 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +76355 -0
- package/package.json +88 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @arcblock/payment-service/drivers — Phase 8 (W2-1a) db / locks slot contracts.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the driver contracts and reference implementations. Same transition
|
|
5
|
+
* boundary as the root module (D4): the implementations physically live in
|
|
6
|
+
* blocklets/core/api/src for now; the package surface is the contract hosts
|
|
7
|
+
* (arc, standalone worker) build their slots against.
|
|
8
|
+
*/
|
|
9
|
+
export type DbDriverKind = 'node' | 'd1';
|
|
10
|
+
export interface DbExecResult {
|
|
11
|
+
changes: number;
|
|
12
|
+
}
|
|
13
|
+
export interface DbBatchOp {
|
|
14
|
+
sql: string;
|
|
15
|
+
params?: any[];
|
|
16
|
+
}
|
|
17
|
+
export interface DbDriver {
|
|
18
|
+
kind: DbDriverKind;
|
|
19
|
+
exec(sql: string, params?: any[]): Promise<DbExecResult>;
|
|
20
|
+
all<T = any>(sql: string, params?: any[]): Promise<T[]>;
|
|
21
|
+
get<T = any>(sql: string, params?: any[]): Promise<T | null>;
|
|
22
|
+
batch(ops: DbBatchOp[]): Promise<any[]>;
|
|
23
|
+
sequelize?: any;
|
|
24
|
+
}
|
|
25
|
+
export interface LockHandle {
|
|
26
|
+
name: string;
|
|
27
|
+
locked: boolean;
|
|
28
|
+
acquire(maxWaitMs?: number): Promise<true>;
|
|
29
|
+
release(): void;
|
|
30
|
+
}
|
|
31
|
+
export type LocksDriverKind = 'memory' | 'd1';
|
|
32
|
+
export interface LocksDriver {
|
|
33
|
+
kind: LocksDriverKind;
|
|
34
|
+
getLock(name: string, options?: {
|
|
35
|
+
ttl?: number;
|
|
36
|
+
}): LockHandle;
|
|
37
|
+
}
|
|
38
|
+
export type LockScope = 'tenant' | 'global';
|
|
39
|
+
export interface SqlMigration {
|
|
40
|
+
name: string;
|
|
41
|
+
sql: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function applySqlMigrations(driver: DbDriver, migrations: SqlMigration[]): Promise<string[]>;
|
|
44
|
+
export declare function applyPaymentCoreMigrations(driver: DbDriver): Promise<string[]>;
|
|
45
|
+
export declare function getPaymentCoreSqlMigrations(): SqlMigration[];
|
|
46
|
+
export declare function createNodeDbDriver(sequelize: any): DbDriver;
|
|
47
|
+
export declare function createD1DbDriver(binding: any): DbDriver;
|
|
48
|
+
export declare function createMemoryLocksDriver(): LocksDriver;
|
|
49
|
+
export declare function createD1LocksDriver(getBinding: () => any): LocksDriver;
|
|
50
|
+
export declare function scopedLockName(name: string, instanceDid: string | null, scope: LockScope): string;
|
|
51
|
+
export declare function createAuthStorage(driver: DbDriver): any;
|
|
52
|
+
export interface QueueOptions<T = any> {
|
|
53
|
+
id?: (job: T) => string;
|
|
54
|
+
concurrency?: number;
|
|
55
|
+
maxRetries?: number;
|
|
56
|
+
maxTimeout?: number;
|
|
57
|
+
retryDelay?: number;
|
|
58
|
+
enableScheduledJob?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface PushParams<T = any> {
|
|
61
|
+
job: T;
|
|
62
|
+
id?: string;
|
|
63
|
+
persist?: boolean;
|
|
64
|
+
delay?: number;
|
|
65
|
+
runAt?: number;
|
|
66
|
+
skipDuplicateCheck?: boolean;
|
|
67
|
+
fromStore?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/** per-job event channel (emits queued/finished/failed/retry/cancelled) */
|
|
70
|
+
export interface JobEvents {
|
|
71
|
+
id?: string;
|
|
72
|
+
on(event: string, listener: (data: any) => void): this;
|
|
73
|
+
once(event: string, listener: (data: any) => void): this;
|
|
74
|
+
emit(event: string, data: any): boolean;
|
|
75
|
+
}
|
|
76
|
+
export type ResolvedQueueOptions = Required<Omit<QueueOptions, 'id'>>;
|
|
77
|
+
export interface QueueHandle<T = any> {
|
|
78
|
+
push(params: PushParams<T>): JobEvents;
|
|
79
|
+
pushAndWait(params: PushParams<T>): Promise<{
|
|
80
|
+
id: string;
|
|
81
|
+
job: T;
|
|
82
|
+
result: any;
|
|
83
|
+
}>;
|
|
84
|
+
get(id: string): Promise<T | null>;
|
|
85
|
+
delete(id: string, knownExists?: boolean): Promise<boolean>;
|
|
86
|
+
cancel(id: string): Promise<T | null>;
|
|
87
|
+
update(id: string, updates: any): Promise<any>;
|
|
88
|
+
options: ResolvedQueueOptions;
|
|
89
|
+
}
|
|
90
|
+
export type QueueFactory = <T = any>(params: {
|
|
91
|
+
name: string;
|
|
92
|
+
onJob: (job: T) => Promise<any>;
|
|
93
|
+
options?: QueueOptions<T>;
|
|
94
|
+
}) => QueueHandle<T> & JobEvents;
|
|
95
|
+
export interface QueueHostHooks {
|
|
96
|
+
flush(): Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
export interface CronJob {
|
|
99
|
+
name: string;
|
|
100
|
+
time: string;
|
|
101
|
+
fn: () => Promise<any> | any;
|
|
102
|
+
options?: {
|
|
103
|
+
runOnInit?: boolean;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export interface CronDriver {
|
|
107
|
+
kind: 'node-cron' | 'cf-cron';
|
|
108
|
+
register(jobs: CronJob[], onError?: (err: Error, name: string) => void): void;
|
|
109
|
+
addJob(name: string, time: string, fn: CronJob['fn'], options?: CronJob['options']): void;
|
|
110
|
+
runDue(now?: Date): Promise<{
|
|
111
|
+
ran: string[];
|
|
112
|
+
skipped: string[];
|
|
113
|
+
}>;
|
|
114
|
+
runJob(name: string): Promise<void>;
|
|
115
|
+
getJobNames(): string[];
|
|
116
|
+
}
|
|
117
|
+
export declare const nodeQueueHostHooks: QueueHostHooks;
|
|
118
|
+
export declare function setQueueHostHooks(hooks: QueueHostHooks): void;
|
|
119
|
+
export declare function getQueueHostHooks(): QueueHostHooks;
|
|
120
|
+
export declare function createCronRegistry(kind: CronDriver['kind']): CronDriver;
|
|
121
|
+
export interface IdentityDriver {
|
|
122
|
+
resolveInstanceDidForHost(host: string | undefined): Promise<string | null> | string | null;
|
|
123
|
+
getAppEk?(instanceDid: string): Promise<string> | string;
|
|
124
|
+
}
|
|
125
|
+
export declare function createDefaultIdentityDriver(): IdentityDriver;
|
|
126
|
+
export declare function setIdentityDriver(driver: IdentityDriver): void;
|
|
127
|
+
export declare function getIdentityDriver(): IdentityDriver;
|
|
128
|
+
export interface SecretsDriver {
|
|
129
|
+
encrypt(instanceDid: string, value: string): Promise<string>;
|
|
130
|
+
decrypt(instanceDid: string, value: string): Promise<string>;
|
|
131
|
+
encryptSync(instanceDid: string, value: string): string;
|
|
132
|
+
decryptSync(instanceDid: string, value: string): string;
|
|
133
|
+
warmup(instanceDid: string): Promise<void>;
|
|
134
|
+
}
|
|
135
|
+
export declare function createDefaultSecretsDriver(): SecretsDriver;
|
|
136
|
+
export declare function createKeyringSecretsDriver(identity: IdentityDriver, opts?: {
|
|
137
|
+
ttlMs?: number;
|
|
138
|
+
}): SecretsDriver;
|
|
139
|
+
export declare function setSecretsDriver(driver: SecretsDriver): void;
|
|
140
|
+
export declare function getSecretsDriver(): SecretsDriver;
|
|
141
|
+
export declare function setCronDriver(driver: CronDriver): void;
|
|
142
|
+
export declare function getCronDriver(): CronDriver;
|
|
143
|
+
export declare function matchesCron(expr: string, date: Date): boolean;
|
|
144
|
+
export declare function shouldRunInWindow(expr: string, date: Date): boolean;
|