@valentinkolb/sync 2.1.1 → 2.2.0
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/README.md +69 -5
- package/index.d.ts +2 -1
- package/index.js +1633 -16
- package/package.json +1 -1
- package/src/registry.d.ts +130 -0
- package/src/scheduler.d.ts +23 -0
package/package.json
CHANGED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
export declare class RegistryCapacityError extends Error {
|
|
3
|
+
constructor(message?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class RegistryPayloadTooLargeError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export type RegistryConfig<TSchema extends z.ZodTypeAny> = {
|
|
9
|
+
id: string;
|
|
10
|
+
schema: TSchema;
|
|
11
|
+
tenantId?: string;
|
|
12
|
+
prefix?: string;
|
|
13
|
+
limits?: {
|
|
14
|
+
maxEntries?: number;
|
|
15
|
+
maxPayloadBytes?: number;
|
|
16
|
+
eventRetentionMs?: number;
|
|
17
|
+
eventMaxLen?: number;
|
|
18
|
+
tombstoneRetentionMs?: number;
|
|
19
|
+
reconcileBatchSize?: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type RegistryUpsertConfig<T> = {
|
|
23
|
+
key: string;
|
|
24
|
+
value: T;
|
|
25
|
+
ttlMs?: number;
|
|
26
|
+
tenantId?: string;
|
|
27
|
+
};
|
|
28
|
+
export type RegistryTouchConfig = {
|
|
29
|
+
key: string;
|
|
30
|
+
tenantId?: string;
|
|
31
|
+
};
|
|
32
|
+
export type RegistryRemoveConfig = {
|
|
33
|
+
key: string;
|
|
34
|
+
reason?: string;
|
|
35
|
+
tenantId?: string;
|
|
36
|
+
};
|
|
37
|
+
export type RegistryGetConfig = {
|
|
38
|
+
key: string;
|
|
39
|
+
tenantId?: string;
|
|
40
|
+
includeExpired?: boolean;
|
|
41
|
+
};
|
|
42
|
+
export type RegistryListConfig = {
|
|
43
|
+
prefix?: string;
|
|
44
|
+
status?: "active" | "expired";
|
|
45
|
+
tenantId?: string;
|
|
46
|
+
limit?: number;
|
|
47
|
+
afterKey?: string;
|
|
48
|
+
};
|
|
49
|
+
export type RegistryCasConfig<T> = {
|
|
50
|
+
key: string;
|
|
51
|
+
version: string;
|
|
52
|
+
value: T;
|
|
53
|
+
tenantId?: string;
|
|
54
|
+
};
|
|
55
|
+
export type RegistryEntry<T> = {
|
|
56
|
+
key: string;
|
|
57
|
+
value: T;
|
|
58
|
+
version: string;
|
|
59
|
+
status: "active" | "expired";
|
|
60
|
+
createdAt: number;
|
|
61
|
+
updatedAt: number;
|
|
62
|
+
ttlMs: number | null;
|
|
63
|
+
expiresAt: number | null;
|
|
64
|
+
};
|
|
65
|
+
export type RegistrySnapshot<T> = {
|
|
66
|
+
entries: RegistryEntry<T>[];
|
|
67
|
+
cursor: string;
|
|
68
|
+
nextKey?: string;
|
|
69
|
+
};
|
|
70
|
+
export type RegistryRecvConfig = {
|
|
71
|
+
wait?: boolean;
|
|
72
|
+
timeoutMs?: number;
|
|
73
|
+
signal?: AbortSignal;
|
|
74
|
+
};
|
|
75
|
+
export type RegistryEvent<T> = {
|
|
76
|
+
type: "upsert";
|
|
77
|
+
cursor: string;
|
|
78
|
+
entry: RegistryEntry<T>;
|
|
79
|
+
} | {
|
|
80
|
+
type: "touch";
|
|
81
|
+
cursor: string;
|
|
82
|
+
key: string;
|
|
83
|
+
version: string;
|
|
84
|
+
updatedAt: number;
|
|
85
|
+
expiresAt: number;
|
|
86
|
+
} | {
|
|
87
|
+
type: "delete";
|
|
88
|
+
cursor: string;
|
|
89
|
+
key: string;
|
|
90
|
+
version: string;
|
|
91
|
+
removedAt: number;
|
|
92
|
+
reason?: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: "expire";
|
|
95
|
+
cursor: string;
|
|
96
|
+
key: string;
|
|
97
|
+
version: string;
|
|
98
|
+
removedAt: number;
|
|
99
|
+
} | {
|
|
100
|
+
type: "overflow";
|
|
101
|
+
cursor: string;
|
|
102
|
+
after: string;
|
|
103
|
+
firstAvailable: string;
|
|
104
|
+
};
|
|
105
|
+
export type RegistryReader<T> = {
|
|
106
|
+
recv(cfg?: RegistryRecvConfig): Promise<RegistryEvent<T> | null>;
|
|
107
|
+
stream(cfg?: RegistryRecvConfig): AsyncIterable<RegistryEvent<T>>;
|
|
108
|
+
};
|
|
109
|
+
export type Registry<T> = {
|
|
110
|
+
upsert(cfg: RegistryUpsertConfig<T>): Promise<RegistryEntry<T>>;
|
|
111
|
+
touch(cfg: RegistryTouchConfig): Promise<{
|
|
112
|
+
ok: boolean;
|
|
113
|
+
version?: string;
|
|
114
|
+
expiresAt?: number;
|
|
115
|
+
}>;
|
|
116
|
+
remove(cfg: RegistryRemoveConfig): Promise<boolean>;
|
|
117
|
+
get(cfg: RegistryGetConfig): Promise<RegistryEntry<T> | null>;
|
|
118
|
+
list(cfg?: RegistryListConfig): Promise<RegistrySnapshot<T>>;
|
|
119
|
+
cas(cfg: RegistryCasConfig<T>): Promise<{
|
|
120
|
+
ok: boolean;
|
|
121
|
+
entry?: RegistryEntry<T>;
|
|
122
|
+
}>;
|
|
123
|
+
reader(cfg?: {
|
|
124
|
+
key?: string;
|
|
125
|
+
prefix?: string;
|
|
126
|
+
after?: string;
|
|
127
|
+
tenantId?: string;
|
|
128
|
+
}): RegistryReader<T>;
|
|
129
|
+
};
|
|
130
|
+
export declare const registry: <TSchema extends z.ZodTypeAny>(config: RegistryConfig<TSchema>) => Registry<z.infer<TSchema>>;
|
package/src/scheduler.d.ts
CHANGED
|
@@ -63,6 +63,21 @@ export type SchedulerMetric = {
|
|
|
63
63
|
scheduleId: string;
|
|
64
64
|
slotTs: number;
|
|
65
65
|
failures: number;
|
|
66
|
+
} | {
|
|
67
|
+
type: "trigger_submitted";
|
|
68
|
+
ts: number;
|
|
69
|
+
scheduleId: string;
|
|
70
|
+
jobId: string;
|
|
71
|
+
} | {
|
|
72
|
+
type: "trigger_rejected";
|
|
73
|
+
ts: number;
|
|
74
|
+
scheduleId: string;
|
|
75
|
+
reason: "missing_schedule" | "missing_handler" | "invalid_schedule";
|
|
76
|
+
} | {
|
|
77
|
+
type: "trigger_failed";
|
|
78
|
+
ts: number;
|
|
79
|
+
scheduleId: string;
|
|
80
|
+
message: string;
|
|
66
81
|
};
|
|
67
82
|
export type SchedulerConfig = {
|
|
68
83
|
id: string;
|
|
@@ -98,6 +113,10 @@ export type SchedulerRegisterConfig = {
|
|
|
98
113
|
export type SchedulerUnregisterConfig = {
|
|
99
114
|
id: string;
|
|
100
115
|
};
|
|
116
|
+
export type SchedulerTriggerNowConfig = {
|
|
117
|
+
id: string;
|
|
118
|
+
key?: string;
|
|
119
|
+
};
|
|
101
120
|
export type SchedulerGetConfig = {
|
|
102
121
|
id: string;
|
|
103
122
|
};
|
|
@@ -121,6 +140,9 @@ export type SchedulerMetricsSnapshot = {
|
|
|
121
140
|
dispatchRetried: number;
|
|
122
141
|
dispatchSkipped: number;
|
|
123
142
|
dispatchDlq: number;
|
|
143
|
+
triggerSubmitted: number;
|
|
144
|
+
triggerFailed: number;
|
|
145
|
+
triggerRejected: number;
|
|
124
146
|
tickErrors: number;
|
|
125
147
|
lastTickAt: number | null;
|
|
126
148
|
};
|
|
@@ -133,6 +155,7 @@ export type Scheduler = {
|
|
|
133
155
|
updated: boolean;
|
|
134
156
|
}>;
|
|
135
157
|
unregister(cfg: SchedulerUnregisterConfig): Promise<void>;
|
|
158
|
+
triggerNow(cfg: SchedulerTriggerNowConfig): Promise<string>;
|
|
136
159
|
get(cfg: SchedulerGetConfig): Promise<SchedulerInfo | null>;
|
|
137
160
|
list(): Promise<SchedulerInfo[]>;
|
|
138
161
|
metrics(): SchedulerMetricsSnapshot;
|