@valentinkolb/sync 2.1.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valentinkolb/sync",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "Distributed synchronization primitives for Bun and TypeScript",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -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>>;