tetherdb 0.1.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/LICENSE +21 -0
- package/README.md +277 -0
- package/bin/tetherdb.js +7 -0
- package/dist/cli/args.d.cts +20 -0
- package/dist/cli/args.d.ts +20 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/backend.d.cts +15 -0
- package/dist/cli/backend.d.ts +15 -0
- package/dist/cli/backend.d.ts.map +1 -0
- package/dist/cli/cli.d.cts +8 -0
- package/dist/cli/cli.d.ts +8 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/commands/apps.d.cts +9 -0
- package/dist/cli/commands/apps.d.ts +9 -0
- package/dist/cli/commands/apps.d.ts.map +1 -0
- package/dist/cli/commands/help.d.cts +5 -0
- package/dist/cli/commands/help.d.ts +5 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/index.d.cts +8 -0
- package/dist/cli/commands/index.d.ts +8 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/maintenance.d.cts +9 -0
- package/dist/cli/commands/maintenance.d.ts +9 -0
- package/dist/cli/commands/maintenance.d.ts.map +1 -0
- package/dist/cli/commands/serve.d.cts +14 -0
- package/dist/cli/commands/serve.d.ts +14 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/status.d.cts +9 -0
- package/dist/cli/commands/status.d.ts +9 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/tables.d.cts +9 -0
- package/dist/cli/commands/tables.d.ts +9 -0
- package/dist/cli/commands/tables.d.ts.map +1 -0
- package/dist/cli/commands/users.d.cts +9 -0
- package/dist/cli/commands/users.d.ts +9 -0
- package/dist/cli/commands/users.d.ts.map +1 -0
- package/dist/cli/index.cjs +3999 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +7 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +3958 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/auth.d.cts +155 -0
- package/dist/client/auth.d.ts +155 -0
- package/dist/client/auth.d.ts.map +1 -0
- package/dist/client/client.d.cts +122 -0
- package/dist/client/client.d.ts +122 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/errors.d.cts +39 -0
- package/dist/client/errors.d.ts +39 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/index.cjs +1742 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +12 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1707 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/shared/event.d.cts +29 -0
- package/dist/client/shared/event.d.ts +29 -0
- package/dist/client/shared/event.d.ts.map +1 -0
- package/dist/client/shared/id.d.cts +5 -0
- package/dist/client/shared/id.d.ts +5 -0
- package/dist/client/shared/id.d.ts.map +1 -0
- package/dist/client/storage.d.cts +183 -0
- package/dist/client/storage.d.ts +183 -0
- package/dist/client/storage.d.ts.map +1 -0
- package/dist/client/sync.d.cts +126 -0
- package/dist/client/sync.d.ts +126 -0
- package/dist/client/sync.d.ts.map +1 -0
- package/dist/client/table.d.cts +146 -0
- package/dist/client/table.d.ts +146 -0
- package/dist/client/table.d.ts.map +1 -0
- package/dist/index.cjs +1742 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1707 -0
- package/dist/index.js.map +1 -0
- package/dist/server/crypto.d.cts +55 -0
- package/dist/server/crypto.d.ts +55 -0
- package/dist/server/crypto.d.ts.map +1 -0
- package/dist/server/errors.d.cts +39 -0
- package/dist/server/errors.d.ts +39 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/index.cjs +3621 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +10 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3569 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/lock.d.cts +56 -0
- package/dist/server/lock.d.ts +56 -0
- package/dist/server/lock.d.ts.map +1 -0
- package/dist/server/rate-limiter.d.cts +81 -0
- package/dist/server/rate-limiter.d.ts +81 -0
- package/dist/server/rate-limiter.d.ts.map +1 -0
- package/dist/server/server.d.cts +206 -0
- package/dist/server/server.d.ts +206 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/storage/app.d.cts +70 -0
- package/dist/server/storage/app.d.ts +70 -0
- package/dist/server/storage/app.d.ts.map +1 -0
- package/dist/server/storage/base/app.d.cts +42 -0
- package/dist/server/storage/base/app.d.ts +42 -0
- package/dist/server/storage/base/app.d.ts.map +1 -0
- package/dist/server/storage/base/index.d.cts +5 -0
- package/dist/server/storage/base/index.d.ts +5 -0
- package/dist/server/storage/base/index.d.ts.map +1 -0
- package/dist/server/storage/base/storage.d.cts +40 -0
- package/dist/server/storage/base/storage.d.ts +40 -0
- package/dist/server/storage/base/storage.d.ts.map +1 -0
- package/dist/server/storage/base/table.d.cts +32 -0
- package/dist/server/storage/base/table.d.ts +32 -0
- package/dist/server/storage/base/table.d.ts.map +1 -0
- package/dist/server/storage/base/user.d.cts +31 -0
- package/dist/server/storage/base/user.d.ts +31 -0
- package/dist/server/storage/base/user.d.ts.map +1 -0
- package/dist/server/storage/file/app.d.cts +50 -0
- package/dist/server/storage/file/app.d.ts +50 -0
- package/dist/server/storage/file/app.d.ts.map +1 -0
- package/dist/server/storage/file/index.d.cts +5 -0
- package/dist/server/storage/file/index.d.ts +5 -0
- package/dist/server/storage/file/index.d.ts.map +1 -0
- package/dist/server/storage/file/storage.d.cts +67 -0
- package/dist/server/storage/file/storage.d.ts +67 -0
- package/dist/server/storage/file/storage.d.ts.map +1 -0
- package/dist/server/storage/file/table.d.cts +14 -0
- package/dist/server/storage/file/table.d.ts +14 -0
- package/dist/server/storage/file/table.d.ts.map +1 -0
- package/dist/server/storage/file/user.d.cts +14 -0
- package/dist/server/storage/file/user.d.ts +14 -0
- package/dist/server/storage/file/user.d.ts.map +1 -0
- package/dist/server/storage/index.d.cts +14 -0
- package/dist/server/storage/index.d.ts +14 -0
- package/dist/server/storage/index.d.ts.map +1 -0
- package/dist/server/storage/memory/app.d.cts +29 -0
- package/dist/server/storage/memory/app.d.ts +29 -0
- package/dist/server/storage/memory/app.d.ts.map +1 -0
- package/dist/server/storage/memory/index.d.cts +5 -0
- package/dist/server/storage/memory/index.d.ts +5 -0
- package/dist/server/storage/memory/index.d.ts.map +1 -0
- package/dist/server/storage/memory/storage.d.cts +47 -0
- package/dist/server/storage/memory/storage.d.ts +47 -0
- package/dist/server/storage/memory/storage.d.ts.map +1 -0
- package/dist/server/storage/memory/table.d.cts +17 -0
- package/dist/server/storage/memory/table.d.ts +17 -0
- package/dist/server/storage/memory/table.d.ts.map +1 -0
- package/dist/server/storage/memory/user.d.cts +21 -0
- package/dist/server/storage/memory/user.d.ts +21 -0
- package/dist/server/storage/memory/user.d.ts.map +1 -0
- package/dist/server/storage/sqlite/app.d.cts +31 -0
- package/dist/server/storage/sqlite/app.d.ts +31 -0
- package/dist/server/storage/sqlite/app.d.ts.map +1 -0
- package/dist/server/storage/sqlite/index.d.cts +5 -0
- package/dist/server/storage/sqlite/index.d.ts +5 -0
- package/dist/server/storage/sqlite/index.d.ts.map +1 -0
- package/dist/server/storage/sqlite/storage.d.cts +92 -0
- package/dist/server/storage/sqlite/storage.d.ts +92 -0
- package/dist/server/storage/sqlite/storage.d.ts.map +1 -0
- package/dist/server/storage/sqlite/table.d.cts +15 -0
- package/dist/server/storage/sqlite/table.d.ts +15 -0
- package/dist/server/storage/sqlite/table.d.ts.map +1 -0
- package/dist/server/storage/sqlite/user.d.cts +14 -0
- package/dist/server/storage/sqlite/user.d.ts +14 -0
- package/dist/server/storage/sqlite/user.d.ts.map +1 -0
- package/dist/server/storage/storage.d.cts +152 -0
- package/dist/server/storage/storage.d.ts +152 -0
- package/dist/server/storage/storage.d.ts.map +1 -0
- package/dist/server/storage/table.d.cts +45 -0
- package/dist/server/storage/table.d.ts +45 -0
- package/dist/server/storage/table.d.ts.map +1 -0
- package/dist/server/storage/user.d.cts +45 -0
- package/dist/server/storage/user.d.ts +45 -0
- package/dist/server/storage/user.d.ts.map +1 -0
- package/dist/server/sync.d.cts +67 -0
- package/dist/server/sync.d.ts +67 -0
- package/dist/server/sync.d.ts.map +1 -0
- package/dist/server/validate.d.cts +113 -0
- package/dist/server/validate.d.ts +113 -0
- package/dist/server/validate.d.ts.map +1 -0
- package/dist/shared/clock.d.cts +22 -0
- package/dist/shared/clock.d.ts +22 -0
- package/dist/shared/clock.d.ts.map +1 -0
- package/dist/shared/path.d.cts +12 -0
- package/dist/shared/path.d.ts +12 -0
- package/dist/shared/path.d.ts.map +1 -0
- package/dist/shared/types.d.cts +234 -0
- package/dist/shared/types.d.ts +234 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/package.json +133 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { AppStorage } from './app.js';
|
|
2
|
+
import type { UserStorage } from './user.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options and resource limits for storage engines.
|
|
5
|
+
*/
|
|
6
|
+
export interface StorageOptions {
|
|
7
|
+
/** Maximum number of active records allowed per table (default: 10,000). */
|
|
8
|
+
maxRecordsPerTable?: number;
|
|
9
|
+
/** Maximum allowed payload size in bytes for an individual record (default: 512 KB). */
|
|
10
|
+
maxRecordSizeBytes?: number;
|
|
11
|
+
/** Maximum allowed size in bytes for a single change batch payload (default: 5 MB). */
|
|
12
|
+
maxBatchSizeBytes?: number;
|
|
13
|
+
/** Maximum number of changelog entries retained per user before compaction (default: 1,000). */
|
|
14
|
+
maxChangelogEntries?: number;
|
|
15
|
+
/** Secret key used for signing session tokens. */
|
|
16
|
+
secret?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Summary status information describing the storage engine and its contents.
|
|
20
|
+
*/
|
|
21
|
+
export interface StorageStatus {
|
|
22
|
+
/** Storage persistence type ('sqlite', 'file', or 'memory'). */
|
|
23
|
+
backend: string;
|
|
24
|
+
/** Storage base directory if disk-backed. */
|
|
25
|
+
baseDir?: string;
|
|
26
|
+
/** Number of registered user accounts. */
|
|
27
|
+
usersCount: number;
|
|
28
|
+
/** Number of registered applications. */
|
|
29
|
+
appsCount: number;
|
|
30
|
+
/** Detailed statistics per application if queried or available. */
|
|
31
|
+
apps?: Array<{
|
|
32
|
+
id: string;
|
|
33
|
+
tables: string[];
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Result returned by a storage maintenance operation.
|
|
38
|
+
*/
|
|
39
|
+
export interface MaintenanceResult {
|
|
40
|
+
/** Maintenance action performed ('checkpoint', 'vacuum', 'prune'). */
|
|
41
|
+
action: 'checkpoint' | 'vacuum' | 'prune';
|
|
42
|
+
/** Target backend name. */
|
|
43
|
+
backend: string;
|
|
44
|
+
/** Optional target application ID. */
|
|
45
|
+
appId?: string;
|
|
46
|
+
/** Number of entries or database files affected, if applicable. */
|
|
47
|
+
affectedCount?: number;
|
|
48
|
+
/** Human-readable status message. */
|
|
49
|
+
message: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Top-level storage coordinator managing application namespaces and user accounts.
|
|
53
|
+
*/
|
|
54
|
+
export interface Storage {
|
|
55
|
+
/** Storage configuration options and resource limits. */
|
|
56
|
+
readonly options?: StorageOptions;
|
|
57
|
+
/**
|
|
58
|
+
* Creates/registers a new application namespace.
|
|
59
|
+
* Throws an error if an application with the specified ID already exists.
|
|
60
|
+
*
|
|
61
|
+
* @param id - Unique application identifier.
|
|
62
|
+
* @returns Created AppStorage handle.
|
|
63
|
+
* @throws Error if the application already exists.
|
|
64
|
+
*/
|
|
65
|
+
createApp(id: string): Promise<AppStorage>;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves an application handle if it exists.
|
|
68
|
+
*
|
|
69
|
+
* @param id - Unique application identifier.
|
|
70
|
+
* @returns AppStorage handle or `undefined` if not found.
|
|
71
|
+
*/
|
|
72
|
+
getApp(id: string): Promise<AppStorage | undefined>;
|
|
73
|
+
/**
|
|
74
|
+
* Lists all registered application handles.
|
|
75
|
+
*
|
|
76
|
+
* @returns Array of AppStorage handles.
|
|
77
|
+
*/
|
|
78
|
+
getApps(): Promise<AppStorage[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new user account with credentials.
|
|
81
|
+
* Throws an error if a user with the same username already exists.
|
|
82
|
+
*
|
|
83
|
+
* @param username - Username for the account.
|
|
84
|
+
* @param password - Account password.
|
|
85
|
+
* @returns Created UserStorage handle.
|
|
86
|
+
* @throws Error if the username is already registered.
|
|
87
|
+
*/
|
|
88
|
+
createUser(username: string, password: string): Promise<UserStorage>;
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves a user handle by user account ID.
|
|
91
|
+
*
|
|
92
|
+
* @param id - Unique user identifier.
|
|
93
|
+
* @returns UserStorage handle or `undefined` if not found.
|
|
94
|
+
*/
|
|
95
|
+
getUser(id: string): Promise<UserStorage | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* Retrieves a user handle by username.
|
|
98
|
+
*
|
|
99
|
+
* @param username - User account username.
|
|
100
|
+
* @returns UserStorage handle or `undefined` if not found.
|
|
101
|
+
*/
|
|
102
|
+
getUserByUsername(username: string): Promise<UserStorage | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* Retrieves a user handle by validating a session token.
|
|
105
|
+
*
|
|
106
|
+
* @param token - Signed session token.
|
|
107
|
+
* @returns UserStorage handle if token is valid and active, or `undefined`.
|
|
108
|
+
*/
|
|
109
|
+
getUserByToken(token: string): Promise<UserStorage | undefined>;
|
|
110
|
+
/**
|
|
111
|
+
* Lists all user accounts.
|
|
112
|
+
*
|
|
113
|
+
* @returns Array of UserStorage handles.
|
|
114
|
+
*/
|
|
115
|
+
getUsers(): Promise<UserStorage[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves summary operational status of the storage backend.
|
|
118
|
+
*
|
|
119
|
+
* @param appId - Optional application identifier filter.
|
|
120
|
+
* @returns StorageStatus object.
|
|
121
|
+
*/
|
|
122
|
+
getStatus(appId?: string): Promise<StorageStatus>;
|
|
123
|
+
/**
|
|
124
|
+
* Performs a WAL checkpoint on SQLite databases to truncate WAL files.
|
|
125
|
+
*
|
|
126
|
+
* @param appId - Optional target application identifier.
|
|
127
|
+
* @returns MaintenanceResult describing checkpoint outcome.
|
|
128
|
+
* @throws TetherServerError if checkpoint is not supported by this backend.
|
|
129
|
+
*/
|
|
130
|
+
checkpoint(appId?: string): Promise<MaintenanceResult>;
|
|
131
|
+
/**
|
|
132
|
+
* Performs database vacuuming to reclaim disk space and defragment storage.
|
|
133
|
+
*
|
|
134
|
+
* @param appId - Optional target application identifier.
|
|
135
|
+
* @returns MaintenanceResult describing vacuum outcome.
|
|
136
|
+
* @throws TetherServerError if vacuum is not supported by this backend.
|
|
137
|
+
*/
|
|
138
|
+
vacuum(appId?: string): Promise<MaintenanceResult>;
|
|
139
|
+
/**
|
|
140
|
+
* Prunes changelog history entries older than the retention threshold.
|
|
141
|
+
*
|
|
142
|
+
* @param appId - Optional target application identifier.
|
|
143
|
+
* @param keepCount - Optional maximum entries to retain per table/user (defaults to configured limit).
|
|
144
|
+
* @returns MaintenanceResult describing prune outcome.
|
|
145
|
+
*/
|
|
146
|
+
prune(appId?: string, keepCount?: number): Promise<MaintenanceResult>;
|
|
147
|
+
/**
|
|
148
|
+
* Optional cleanup callback invoked when shutting down the storage engine.
|
|
149
|
+
*/
|
|
150
|
+
close?(): Promise<void>;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/server/storage/storage.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ChangeRecord, SnapshotRecord, StoredRecord } from '../../shared/types.cjs';
|
|
2
|
+
import type { AppStorage } from './app.cjs';
|
|
3
|
+
import type { UserStorage } from './user.cjs';
|
|
4
|
+
/**
|
|
5
|
+
* Table-scoped storage interface for record CRUD and batch mutation processing.
|
|
6
|
+
*/
|
|
7
|
+
export interface TableStorage {
|
|
8
|
+
/** Table name identifier. */
|
|
9
|
+
readonly name: string;
|
|
10
|
+
/** Parent application storage handle. */
|
|
11
|
+
readonly app: AppStorage;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves a single stored record by ID for a user.
|
|
14
|
+
*
|
|
15
|
+
* @param user - Target user handle.
|
|
16
|
+
* @param id - Record identifier.
|
|
17
|
+
* @returns Stored record or `undefined` if not found or deleted.
|
|
18
|
+
*/
|
|
19
|
+
getRecord(user: UserStorage, id: string): Promise<StoredRecord | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves all active (non-deleted) records in this table for a user.
|
|
22
|
+
*
|
|
23
|
+
* @param user - Target user handle.
|
|
24
|
+
* @returns Array of snapshot items.
|
|
25
|
+
*/
|
|
26
|
+
getAllRecords(user: UserStorage): Promise<SnapshotRecord[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Applies an array of mutation change operations to this table for a user.
|
|
29
|
+
*
|
|
30
|
+
* @param user - Target user handle.
|
|
31
|
+
* @param changes - Array of change records.
|
|
32
|
+
* @returns Applied changes and new sequence number.
|
|
33
|
+
*/
|
|
34
|
+
applyChanges(user: UserStorage, changes: ChangeRecord[]): Promise<{
|
|
35
|
+
applied: ChangeRecord[];
|
|
36
|
+
newSeq: number;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Deletes this table and its data across all.
|
|
40
|
+
*
|
|
41
|
+
* @returns True if deleted successfully.
|
|
42
|
+
*/
|
|
43
|
+
delete(): Promise<boolean>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ChangeRecord, SnapshotRecord, StoredRecord } from '../../shared/types.js';
|
|
2
|
+
import type { AppStorage } from './app.js';
|
|
3
|
+
import type { UserStorage } from './user.js';
|
|
4
|
+
/**
|
|
5
|
+
* Table-scoped storage interface for record CRUD and batch mutation processing.
|
|
6
|
+
*/
|
|
7
|
+
export interface TableStorage {
|
|
8
|
+
/** Table name identifier. */
|
|
9
|
+
readonly name: string;
|
|
10
|
+
/** Parent application storage handle. */
|
|
11
|
+
readonly app: AppStorage;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves a single stored record by ID for a user.
|
|
14
|
+
*
|
|
15
|
+
* @param user - Target user handle.
|
|
16
|
+
* @param id - Record identifier.
|
|
17
|
+
* @returns Stored record or `undefined` if not found or deleted.
|
|
18
|
+
*/
|
|
19
|
+
getRecord(user: UserStorage, id: string): Promise<StoredRecord | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves all active (non-deleted) records in this table for a user.
|
|
22
|
+
*
|
|
23
|
+
* @param user - Target user handle.
|
|
24
|
+
* @returns Array of snapshot items.
|
|
25
|
+
*/
|
|
26
|
+
getAllRecords(user: UserStorage): Promise<SnapshotRecord[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Applies an array of mutation change operations to this table for a user.
|
|
29
|
+
*
|
|
30
|
+
* @param user - Target user handle.
|
|
31
|
+
* @param changes - Array of change records.
|
|
32
|
+
* @returns Applied changes and new sequence number.
|
|
33
|
+
*/
|
|
34
|
+
applyChanges(user: UserStorage, changes: ChangeRecord[]): Promise<{
|
|
35
|
+
applied: ChangeRecord[];
|
|
36
|
+
newSeq: number;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Deletes this table and its data across all.
|
|
40
|
+
*
|
|
41
|
+
* @returns True if deleted successfully.
|
|
42
|
+
*/
|
|
43
|
+
delete(): Promise<boolean>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/server/storage/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IAEzB;;;;;;OAMG;IACH,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IAE5E;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAE5D;;;;;;OAMG;IACH,YAAY,CACV,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,YAAY,EAAE,GACtB,OAAO,CAAC;QAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAExD;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User storage handle managing account identity, credentials, tokens, and data lifecycles.
|
|
3
|
+
*/
|
|
4
|
+
export interface UserStorage {
|
|
5
|
+
/** Unique user account identifier. */
|
|
6
|
+
readonly id: string;
|
|
7
|
+
/** Normalized username. */
|
|
8
|
+
readonly username: string;
|
|
9
|
+
/** Epoch timestamp when the user account was created. */
|
|
10
|
+
readonly createdAt: number;
|
|
11
|
+
/**
|
|
12
|
+
* Verifies if the provided plaintext password matches the stored credentials.
|
|
13
|
+
*
|
|
14
|
+
* @param password - Plaintext password to verify.
|
|
15
|
+
* @returns True if password matches.
|
|
16
|
+
*/
|
|
17
|
+
verifyPassword(password: string): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Changes the user's password.
|
|
20
|
+
*
|
|
21
|
+
* @param newPassword - New plaintext password.
|
|
22
|
+
*/
|
|
23
|
+
changePassword(newPassword: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a signed session token for this user.
|
|
26
|
+
*
|
|
27
|
+
* @param expiresInSeconds - Optional duration before token expires.
|
|
28
|
+
* @returns Signed token string.
|
|
29
|
+
*/
|
|
30
|
+
createToken(expiresInSeconds?: number): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Verifies if a session token is valid for this user.
|
|
33
|
+
*
|
|
34
|
+
* @param token - Token string to verify.
|
|
35
|
+
* @returns True if valid and not expired.
|
|
36
|
+
*/
|
|
37
|
+
verifyToken(token: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Deletes this user account and all of their data across all applications.
|
|
40
|
+
*
|
|
41
|
+
* @returns True if deleted successfully.
|
|
42
|
+
*/
|
|
43
|
+
delete(): Promise<boolean>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User storage handle managing account identity, credentials, tokens, and data lifecycles.
|
|
3
|
+
*/
|
|
4
|
+
export interface UserStorage {
|
|
5
|
+
/** Unique user account identifier. */
|
|
6
|
+
readonly id: string;
|
|
7
|
+
/** Normalized username. */
|
|
8
|
+
readonly username: string;
|
|
9
|
+
/** Epoch timestamp when the user account was created. */
|
|
10
|
+
readonly createdAt: number;
|
|
11
|
+
/**
|
|
12
|
+
* Verifies if the provided plaintext password matches the stored credentials.
|
|
13
|
+
*
|
|
14
|
+
* @param password - Plaintext password to verify.
|
|
15
|
+
* @returns True if password matches.
|
|
16
|
+
*/
|
|
17
|
+
verifyPassword(password: string): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Changes the user's password.
|
|
20
|
+
*
|
|
21
|
+
* @param newPassword - New plaintext password.
|
|
22
|
+
*/
|
|
23
|
+
changePassword(newPassword: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a signed session token for this user.
|
|
26
|
+
*
|
|
27
|
+
* @param expiresInSeconds - Optional duration before token expires.
|
|
28
|
+
* @returns Signed token string.
|
|
29
|
+
*/
|
|
30
|
+
createToken(expiresInSeconds?: number): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Verifies if a session token is valid for this user.
|
|
33
|
+
*
|
|
34
|
+
* @param token - Token string to verify.
|
|
35
|
+
* @returns True if valid and not expired.
|
|
36
|
+
*/
|
|
37
|
+
verifyToken(token: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Deletes this user account and all of their data across all applications.
|
|
40
|
+
*
|
|
41
|
+
* @returns True if deleted successfully.
|
|
42
|
+
*/
|
|
43
|
+
delete(): Promise<boolean>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/server/storage/user.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,sCAAsC;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,2BAA2B;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,yDAAyD;IACzD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;;;;OAKG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnD;;;;OAIG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD;;;;;OAKG;IACH,WAAW,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAExD;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7C;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { WebSocket } from 'ws';
|
|
2
|
+
import { type ClientMessage } from '../shared/types.cjs';
|
|
3
|
+
import type { RateLimiter } from './rate-limiter.cjs';
|
|
4
|
+
import type { TetherLogger } from './server.cjs';
|
|
5
|
+
import type { Storage } from './storage/storage.cjs';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for the WebSocket synchronization coordinator.
|
|
8
|
+
*/
|
|
9
|
+
export interface SyncOptions {
|
|
10
|
+
/** Maximum number of concurrent active connections allowed per user channel (defaults to 20). */
|
|
11
|
+
maxConcurrentConnectionsPerUser?: number;
|
|
12
|
+
/** Maximum duration in milliseconds to wait for authentication before terminating socket (defaults to 10,000ms). */
|
|
13
|
+
authTimeoutMs?: number;
|
|
14
|
+
/** Optional rate limiter for connection handshakes and invalid token tracking. */
|
|
15
|
+
rateLimiter?: RateLimiter | null;
|
|
16
|
+
/** Optional logger instance (or null to suppress internal error logs). */
|
|
17
|
+
logger?: TetherLogger | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Real-time WebSocket synchronization coordinator managing authentication handshakes,
|
|
21
|
+
* snapshot/diff delivery, change ingestion, acknowledgments, and peer broadcasts per application and user.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Sync {
|
|
24
|
+
private readonly storage;
|
|
25
|
+
private readonly maxConcurrentConnectionsPerUser;
|
|
26
|
+
private readonly authTimeoutMs;
|
|
27
|
+
private readonly rateLimiter;
|
|
28
|
+
private readonly logger;
|
|
29
|
+
private readonly userClients;
|
|
30
|
+
private readonly webSocketToClient;
|
|
31
|
+
private readonly pendingAuthTimers;
|
|
32
|
+
private readonly webSocketToIp;
|
|
33
|
+
/**
|
|
34
|
+
* Initializes a new Sync coordinator instance.
|
|
35
|
+
*
|
|
36
|
+
* @param storage - Pluggable backend storage engine.
|
|
37
|
+
* @param options - Configuration options for concurrency limits, auth timeout, and rate limiting.
|
|
38
|
+
*/
|
|
39
|
+
constructor(storage: Storage, options?: SyncOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Total number of currently active authenticated WebSocket client connections.
|
|
42
|
+
*/
|
|
43
|
+
get connectedClientsCount(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Handles an incoming WebSocket connection, binding message, error, and disconnection events.
|
|
46
|
+
*
|
|
47
|
+
* @param webSocket - Active WebSocket connection.
|
|
48
|
+
* @param clientIp - Remote client IP address.
|
|
49
|
+
*/
|
|
50
|
+
handleConnection(webSocket: WebSocket, clientIp?: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Routes and executes incoming client protocol messages.
|
|
53
|
+
*
|
|
54
|
+
* @param webSocket - The connection that sent the message.
|
|
55
|
+
* @param msg - Parsed client protocol message.
|
|
56
|
+
*/
|
|
57
|
+
handleMessage(webSocket: WebSocket, msg: ClientMessage): Promise<void>;
|
|
58
|
+
private handleAuthMessage;
|
|
59
|
+
private handleChangeBatchMessage;
|
|
60
|
+
private handlePingMessage;
|
|
61
|
+
private cleanupConnection;
|
|
62
|
+
private send;
|
|
63
|
+
private performSync;
|
|
64
|
+
private getAppSnapshot;
|
|
65
|
+
private broadcastToAppUser;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { WebSocket } from 'ws';
|
|
2
|
+
import { type ClientMessage } from '../shared/types.js';
|
|
3
|
+
import type { RateLimiter } from './rate-limiter.js';
|
|
4
|
+
import type { TetherLogger } from './server.js';
|
|
5
|
+
import type { Storage } from './storage/storage.js';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for the WebSocket synchronization coordinator.
|
|
8
|
+
*/
|
|
9
|
+
export interface SyncOptions {
|
|
10
|
+
/** Maximum number of concurrent active connections allowed per user channel (defaults to 20). */
|
|
11
|
+
maxConcurrentConnectionsPerUser?: number;
|
|
12
|
+
/** Maximum duration in milliseconds to wait for authentication before terminating socket (defaults to 10,000ms). */
|
|
13
|
+
authTimeoutMs?: number;
|
|
14
|
+
/** Optional rate limiter for connection handshakes and invalid token tracking. */
|
|
15
|
+
rateLimiter?: RateLimiter | null;
|
|
16
|
+
/** Optional logger instance (or null to suppress internal error logs). */
|
|
17
|
+
logger?: TetherLogger | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Real-time WebSocket synchronization coordinator managing authentication handshakes,
|
|
21
|
+
* snapshot/diff delivery, change ingestion, acknowledgments, and peer broadcasts per application and user.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Sync {
|
|
24
|
+
private readonly storage;
|
|
25
|
+
private readonly maxConcurrentConnectionsPerUser;
|
|
26
|
+
private readonly authTimeoutMs;
|
|
27
|
+
private readonly rateLimiter;
|
|
28
|
+
private readonly logger;
|
|
29
|
+
private readonly userClients;
|
|
30
|
+
private readonly webSocketToClient;
|
|
31
|
+
private readonly pendingAuthTimers;
|
|
32
|
+
private readonly webSocketToIp;
|
|
33
|
+
/**
|
|
34
|
+
* Initializes a new Sync coordinator instance.
|
|
35
|
+
*
|
|
36
|
+
* @param storage - Pluggable backend storage engine.
|
|
37
|
+
* @param options - Configuration options for concurrency limits, auth timeout, and rate limiting.
|
|
38
|
+
*/
|
|
39
|
+
constructor(storage: Storage, options?: SyncOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Total number of currently active authenticated WebSocket client connections.
|
|
42
|
+
*/
|
|
43
|
+
get connectedClientsCount(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Handles an incoming WebSocket connection, binding message, error, and disconnection events.
|
|
46
|
+
*
|
|
47
|
+
* @param webSocket - Active WebSocket connection.
|
|
48
|
+
* @param clientIp - Remote client IP address.
|
|
49
|
+
*/
|
|
50
|
+
handleConnection(webSocket: WebSocket, clientIp?: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Routes and executes incoming client protocol messages.
|
|
53
|
+
*
|
|
54
|
+
* @param webSocket - The connection that sent the message.
|
|
55
|
+
* @param msg - Parsed client protocol message.
|
|
56
|
+
*/
|
|
57
|
+
handleMessage(webSocket: WebSocket, msg: ClientMessage): Promise<void>;
|
|
58
|
+
private handleAuthMessage;
|
|
59
|
+
private handleChangeBatchMessage;
|
|
60
|
+
private handlePingMessage;
|
|
61
|
+
private cleanupConnection;
|
|
62
|
+
private send;
|
|
63
|
+
private performSync;
|
|
64
|
+
private getAppSnapshot;
|
|
65
|
+
private broadcastToAppUser;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/server/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAGL,KAAK,aAAa,EAMnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAQpD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,iGAAiG;IACjG,+BAA+B,CAAC,EAAE,MAAM,CAAC;IACzC,oHAAoH;IACpH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kFAAkF;IAClF,WAAW,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACjC,0EAA0E;IAC1E,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CAC9B;AAED;;;GAGG;AACH,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,+BAA+B,CAAS;IACzD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwC;IACpE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAsC;IACxE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAwC;IAC1E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgC;IAE9D;;;;;OAKG;IACH,YAAY,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,WAAgB,EAOtD;IAED;;OAEG;IACH,IAAI,qBAAqB,IAAI,MAAM,CAElC;IAED;;;;;OAKG;IACH,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,SAAc,GAAG,IAAI,CA2EnE;IAED;;;;;OAKG;IACG,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CA2B3E;YAIa,iBAAiB;YA0HjB,wBAAwB;IA+DtC,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,iBAAiB;IAsBzB,OAAO,CAAC,IAAI;YAME,WAAW;YA8CX,cAAc;IAa5B,OAAO,CAAC,kBAAkB;CAgB3B"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security, input validation, and sanitization utilities for the TetherDB server.
|
|
3
|
+
* Protects server-side storage and synchronization from injection and traversal attacks.
|
|
4
|
+
*
|
|
5
|
+
* @module tetherdb/server/validate
|
|
6
|
+
*/
|
|
7
|
+
/** Minimum allowed username character length. */
|
|
8
|
+
export declare const MIN_USERNAME_LENGTH = 4;
|
|
9
|
+
/** Maximum allowed username character length. */
|
|
10
|
+
export declare const MAX_USERNAME_LENGTH = 128;
|
|
11
|
+
/** Minimum allowed password character length. */
|
|
12
|
+
export declare const MIN_PASSWORD_LENGTH = 4;
|
|
13
|
+
/** Maximum allowed password character length. */
|
|
14
|
+
export declare const MAX_PASSWORD_LENGTH = 512;
|
|
15
|
+
/** Maximum allowable future timestamp drift in milliseconds (5 minutes). */
|
|
16
|
+
export declare const MAX_FUTURE_TIMESTAMP_DRIFT_MS: number;
|
|
17
|
+
/**
|
|
18
|
+
* Validates a change timestamp, ensuring it is a valid finite epoch number
|
|
19
|
+
* and does not exceed the maximum allowable future drift.
|
|
20
|
+
*
|
|
21
|
+
* @param timestamp - The epoch timestamp in milliseconds.
|
|
22
|
+
* @param maxFutureDriftMs - Optional maximum allowable future drift in ms (defaults to 5 minutes).
|
|
23
|
+
* @returns The validated timestamp.
|
|
24
|
+
* @throws TetherServerError if timestamp is not finite, is non-positive, or exceeds drift bounds.
|
|
25
|
+
*/
|
|
26
|
+
export declare function validateTimestamp(timestamp: number, maxFutureDriftMs?: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Validates a user ID string ensuring it is safe for filesystem use.
|
|
29
|
+
*
|
|
30
|
+
* @param userId - The user ID to validate.
|
|
31
|
+
* @returns The validated user ID.
|
|
32
|
+
* @throws TetherServerError if the user ID is invalid or contains unsafe characters.
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateUserId(userId: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Validates an application namespace identifier.
|
|
37
|
+
*
|
|
38
|
+
* @param appId - The application ID to validate.
|
|
39
|
+
* @returns The validated application ID.
|
|
40
|
+
* @throws TetherServerError if the application ID is invalid.
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateAppId(appId: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Validates a table name ensuring it is safe for filesystem use.
|
|
45
|
+
*
|
|
46
|
+
* @param tableName - The table name to validate.
|
|
47
|
+
* @returns The validated table name.
|
|
48
|
+
* @throws TetherServerError if the table name is invalid.
|
|
49
|
+
*/
|
|
50
|
+
export declare function validateTableName(tableName: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Validates a record ID ensuring it is a non-empty string within size limits.
|
|
53
|
+
*
|
|
54
|
+
* @param id - The record identifier to validate.
|
|
55
|
+
* @returns The validated record ID.
|
|
56
|
+
* @throws TetherServerError if the record ID is invalid or exceeds max length.
|
|
57
|
+
*/
|
|
58
|
+
export declare function validateRecordId(id: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Normalizes a username by trimming whitespace and converting to lowercase.
|
|
61
|
+
*
|
|
62
|
+
* @param username - The raw username string.
|
|
63
|
+
* @returns The normalized username (lowercase and trimmed).
|
|
64
|
+
*/
|
|
65
|
+
export declare function normalizeUsername(username: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Validates and normalizes a username for account creation or authentication.
|
|
68
|
+
* Usernames must be between 4 and 128 characters long.
|
|
69
|
+
*
|
|
70
|
+
* @param username - The username to validate.
|
|
71
|
+
* @returns The validated and normalized username (trimmed and lowercase).
|
|
72
|
+
* @throws TetherServerError if the username is invalid or out of length bounds.
|
|
73
|
+
*/
|
|
74
|
+
export declare function validateUsername(username: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Normalizes a password by trimming surrounding whitespace.
|
|
77
|
+
*
|
|
78
|
+
* @param password - The raw password string.
|
|
79
|
+
* @returns The normalized password (trimmed).
|
|
80
|
+
*/
|
|
81
|
+
export declare function normalizePassword(password: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* Validates a password for user account creation or authentication.
|
|
84
|
+
*
|
|
85
|
+
* @param password - The password string to validate.
|
|
86
|
+
* @returns The validated password.
|
|
87
|
+
* @throws TetherServerError if the password is not a string, is empty, or exceeds length bounds.
|
|
88
|
+
*/
|
|
89
|
+
export declare function validatePassword(password: string): string;
|
|
90
|
+
/**
|
|
91
|
+
* Validates a client correlation or batch ID.
|
|
92
|
+
*
|
|
93
|
+
* @param id - The batch or client identifier.
|
|
94
|
+
* @param name - Identifier type description (e.g. 'batchId', 'clientId').
|
|
95
|
+
* @returns The validated ID.
|
|
96
|
+
* @throws TetherServerError if the identifier format is invalid.
|
|
97
|
+
*/
|
|
98
|
+
export declare function validateIdentifier(id: string, name?: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Estimates the byte size of an arbitrary JavaScript value or object when serialized.
|
|
101
|
+
*
|
|
102
|
+
* @param value - The value to measure.
|
|
103
|
+
* @returns Size in bytes.
|
|
104
|
+
*/
|
|
105
|
+
export declare function calculateByteSize(value: unknown): number;
|
|
106
|
+
/**
|
|
107
|
+
* Calculates a 2-character hex/hash bucket for directory partitioning by user ID.
|
|
108
|
+
*
|
|
109
|
+
* @param userId - Unique user identifier.
|
|
110
|
+
* @returns 2-character bucket string (e.g. 'f4', '0a').
|
|
111
|
+
*/
|
|
112
|
+
export declare function getUserBucket(userId: string): string;
|
|
113
|
+
//# sourceMappingURL=validate.d.ts.map
|