@tinycloud/sdk-core 1.0.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.md +320 -0
- package/dist/TinyCloud.d.ts +206 -0
- package/dist/TinyCloud.d.ts.map +1 -0
- package/dist/TinyCloud.js +244 -0
- package/dist/TinyCloud.js.map +1 -0
- package/dist/TinyCloud.schema.d.ts +173 -0
- package/dist/TinyCloud.schema.d.ts.map +1 -0
- package/dist/TinyCloud.schema.js +136 -0
- package/dist/TinyCloud.schema.js.map +1 -0
- package/dist/TinyCloud.schema.test.d.ts +5 -0
- package/dist/TinyCloud.schema.test.d.ts.map +1 -0
- package/dist/TinyCloud.schema.test.js +286 -0
- package/dist/TinyCloud.schema.test.js.map +1 -0
- package/dist/authorization/CapabilityKeyRegistry.d.ts +317 -0
- package/dist/authorization/CapabilityKeyRegistry.d.ts.map +1 -0
- package/dist/authorization/CapabilityKeyRegistry.js +509 -0
- package/dist/authorization/CapabilityKeyRegistry.js.map +1 -0
- package/dist/authorization/authorization.schema.d.ts +233 -0
- package/dist/authorization/authorization.schema.d.ts.map +1 -0
- package/dist/authorization/authorization.schema.js +220 -0
- package/dist/authorization/authorization.schema.js.map +1 -0
- package/dist/authorization/authorization.schema.test.d.ts +5 -0
- package/dist/authorization/authorization.schema.test.d.ts.map +1 -0
- package/dist/authorization/authorization.schema.test.js +618 -0
- package/dist/authorization/authorization.schema.test.js.map +1 -0
- package/dist/authorization/index.d.ts +38 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +52 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/spaceCreation.d.ts +96 -0
- package/dist/authorization/spaceCreation.d.ts.map +1 -0
- package/dist/authorization/spaceCreation.js +35 -0
- package/dist/authorization/spaceCreation.js.map +1 -0
- package/dist/authorization/spaceCreation.schema.d.ts +67 -0
- package/dist/authorization/spaceCreation.schema.d.ts.map +1 -0
- package/dist/authorization/spaceCreation.schema.js +95 -0
- package/dist/authorization/spaceCreation.schema.js.map +1 -0
- package/dist/authorization/spaceCreation.schema.test.d.ts +5 -0
- package/dist/authorization/spaceCreation.schema.test.d.ts.map +1 -0
- package/dist/authorization/spaceCreation.schema.test.js +168 -0
- package/dist/authorization/spaceCreation.schema.test.js.map +1 -0
- package/dist/authorization/strategies.d.ts +134 -0
- package/dist/authorization/strategies.d.ts.map +1 -0
- package/dist/authorization/strategies.js +15 -0
- package/dist/authorization/strategies.js.map +1 -0
- package/dist/authorization/strategies.schema.d.ts +185 -0
- package/dist/authorization/strategies.schema.d.ts.map +1 -0
- package/dist/authorization/strategies.schema.js +147 -0
- package/dist/authorization/strategies.schema.js.map +1 -0
- package/dist/authorization/strategies.schema.test.d.ts +5 -0
- package/dist/authorization/strategies.schema.test.d.ts.map +1 -0
- package/dist/authorization/strategies.schema.test.js +253 -0
- package/dist/authorization/strategies.schema.test.js.map +1 -0
- package/dist/delegations/DelegationManager.d.ts +164 -0
- package/dist/delegations/DelegationManager.d.ts.map +1 -0
- package/dist/delegations/DelegationManager.js +428 -0
- package/dist/delegations/DelegationManager.js.map +1 -0
- package/dist/delegations/SharingService.d.ts +279 -0
- package/dist/delegations/SharingService.d.ts.map +1 -0
- package/dist/delegations/SharingService.js +558 -0
- package/dist/delegations/SharingService.js.map +1 -0
- package/dist/delegations/SharingService.schema.d.ts +401 -0
- package/dist/delegations/SharingService.schema.d.ts.map +1 -0
- package/dist/delegations/SharingService.schema.js +211 -0
- package/dist/delegations/SharingService.schema.js.map +1 -0
- package/dist/delegations/index.d.ts +38 -0
- package/dist/delegations/index.d.ts.map +1 -0
- package/dist/delegations/index.js +42 -0
- package/dist/delegations/index.js.map +1 -0
- package/dist/delegations/types.d.ts +13 -0
- package/dist/delegations/types.d.ts.map +1 -0
- package/dist/delegations/types.js +42 -0
- package/dist/delegations/types.js.map +1 -0
- package/dist/delegations/types.schema.d.ts +1641 -0
- package/dist/delegations/types.schema.d.ts.map +1 -0
- package/dist/delegations/types.schema.js +535 -0
- package/dist/delegations/types.schema.js.map +1 -0
- package/dist/delegations/types.schema.test.d.ts +5 -0
- package/dist/delegations/types.schema.test.d.ts.map +1 -0
- package/dist/delegations/types.schema.test.js +627 -0
- package/dist/delegations/types.schema.test.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schema.d.ts +327 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +703 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/json-schema.test.d.ts +7 -0
- package/dist/json-schema.test.d.ts.map +1 -0
- package/dist/json-schema.test.js +365 -0
- package/dist/json-schema.test.js.map +1 -0
- package/dist/signer.d.ts +28 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +2 -0
- package/dist/signer.js.map +1 -0
- package/dist/space.d.ts +53 -0
- package/dist/space.d.ts.map +1 -0
- package/dist/space.js +67 -0
- package/dist/space.js.map +1 -0
- package/dist/space.schema.d.ts +65 -0
- package/dist/space.schema.d.ts.map +1 -0
- package/dist/space.schema.js +65 -0
- package/dist/space.schema.js.map +1 -0
- package/dist/space.schema.test.d.ts +5 -0
- package/dist/space.schema.test.d.ts.map +1 -0
- package/dist/space.schema.test.js +148 -0
- package/dist/space.schema.test.js.map +1 -0
- package/dist/spaces/Space.d.ts +175 -0
- package/dist/spaces/Space.d.ts.map +1 -0
- package/dist/spaces/Space.js +84 -0
- package/dist/spaces/Space.js.map +1 -0
- package/dist/spaces/SpaceService.d.ts +271 -0
- package/dist/spaces/SpaceService.d.ts.map +1 -0
- package/dist/spaces/SpaceService.js +715 -0
- package/dist/spaces/SpaceService.js.map +1 -0
- package/dist/spaces/index.d.ts +11 -0
- package/dist/spaces/index.d.ts.map +1 -0
- package/dist/spaces/index.js +20 -0
- package/dist/spaces/index.js.map +1 -0
- package/dist/spaces/spaces.schema.d.ts +421 -0
- package/dist/spaces/spaces.schema.d.ts.map +1 -0
- package/dist/spaces/spaces.schema.js +342 -0
- package/dist/spaces/spaces.schema.js.map +1 -0
- package/dist/spaces/spaces.schema.test.d.ts +5 -0
- package/dist/spaces/spaces.schema.test.d.ts.map +1 -0
- package/dist/spaces/spaces.schema.test.js +471 -0
- package/dist/spaces/spaces.schema.test.js.map +1 -0
- package/dist/storage.d.ts +47 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +14 -0
- package/dist/storage.js.map +1 -0
- package/dist/storage.schema.d.ts +277 -0
- package/dist/storage.schema.d.ts.map +1 -0
- package/dist/storage.schema.js +185 -0
- package/dist/storage.schema.js.map +1 -0
- package/dist/storage.schema.test.d.ts +5 -0
- package/dist/storage.schema.test.d.ts.map +1 -0
- package/dist/storage.schema.test.js +346 -0
- package/dist/storage.schema.test.js.map +1 -0
- package/dist/userAuthorization.d.ts +99 -0
- package/dist/userAuthorization.d.ts.map +1 -0
- package/dist/userAuthorization.js +3 -0
- package/dist/userAuthorization.js.map +1 -0
- package/dist/userAuthorization.schema.d.ts +259 -0
- package/dist/userAuthorization.schema.d.ts.map +1 -0
- package/dist/userAuthorization.schema.js +175 -0
- package/dist/userAuthorization.schema.js.map +1 -0
- package/dist/userAuthorization.schema.test.d.ts +5 -0
- package/dist/userAuthorization.schema.test.d.ts.map +1 -0
- package/dist/userAuthorization.schema.test.js +356 -0
- package/dist/userAuthorization.schema.test.js.map +1 -0
- package/dist/version.d.ts +30 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +54 -0
- package/dist/version.js.map +1 -0
- package/dist/wasm-validation.d.ts +287 -0
- package/dist/wasm-validation.d.ts.map +1 -0
- package/dist/wasm-validation.js +219 -0
- package/dist/wasm-validation.js.map +1 -0
- package/dist/wasm-validation.test.d.ts +5 -0
- package/dist/wasm-validation.test.d.ts.map +1 -0
- package/dist/wasm-validation.test.js +233 -0
- package/dist/wasm-validation.test.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { ServiceContext, KVService, } from "@tinycloud/sdk-services";
|
|
2
|
+
/**
|
|
3
|
+
* TinyCloud SDK - Unified entry point for web and node.
|
|
4
|
+
*
|
|
5
|
+
* This class provides the main SDK interface. Platform-specific behavior
|
|
6
|
+
* is injected through the IUserAuthorization implementation:
|
|
7
|
+
* - WebUserAuthorization for browser environments
|
|
8
|
+
* - NodeUserAuthorization for Node.js environments
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Web usage
|
|
13
|
+
* import { TinyCloud } from '@tinycloud/sdk-core';
|
|
14
|
+
* import { WebUserAuthorization } from '@tinycloud/web-sdk';
|
|
15
|
+
*
|
|
16
|
+
* const auth = new WebUserAuthorization({ ... });
|
|
17
|
+
* const tc = new TinyCloud(auth);
|
|
18
|
+
* await tc.signIn();
|
|
19
|
+
* const result = await tc.kv.put('key', 'value');
|
|
20
|
+
*
|
|
21
|
+
* // Node usage
|
|
22
|
+
* import { TinyCloud } from '@tinycloud/sdk-core';
|
|
23
|
+
* import { NodeUserAuthorization, PrivateKeySigner } from '@tinycloud/node-sdk';
|
|
24
|
+
*
|
|
25
|
+
* const signer = new PrivateKeySigner(process.env.PRIVATE_KEY);
|
|
26
|
+
* const auth = new NodeUserAuthorization({
|
|
27
|
+
* signStrategy: { type: 'auto-sign' },
|
|
28
|
+
* signer,
|
|
29
|
+
* domain: 'api.myapp.com'
|
|
30
|
+
* });
|
|
31
|
+
* const tc = new TinyCloud(auth);
|
|
32
|
+
* await tc.signIn();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class TinyCloud {
|
|
36
|
+
/**
|
|
37
|
+
* Create a new TinyCloud SDK instance.
|
|
38
|
+
*
|
|
39
|
+
* @param userAuthorization - Platform-specific authorization implementation
|
|
40
|
+
* @param config - Optional SDK configuration
|
|
41
|
+
*/
|
|
42
|
+
constructor(userAuthorization, config) {
|
|
43
|
+
/**
|
|
44
|
+
* Registered extensions.
|
|
45
|
+
*/
|
|
46
|
+
this.extensions = [];
|
|
47
|
+
/**
|
|
48
|
+
* Registered services by name.
|
|
49
|
+
*/
|
|
50
|
+
this._services = new Map();
|
|
51
|
+
/**
|
|
52
|
+
* Whether services have been initialized.
|
|
53
|
+
*/
|
|
54
|
+
this._servicesInitialized = false;
|
|
55
|
+
this.userAuthorization = userAuthorization;
|
|
56
|
+
this.config = config || {};
|
|
57
|
+
}
|
|
58
|
+
// === Service Management ===
|
|
59
|
+
/**
|
|
60
|
+
* Initialize services with platform dependencies.
|
|
61
|
+
* Must be called before using services.
|
|
62
|
+
*
|
|
63
|
+
* @param invoke - Platform-specific invoke function from WASM binding
|
|
64
|
+
* @param hosts - TinyCloud host URLs (optional, uses config.hosts)
|
|
65
|
+
* @param fetchFn - Custom fetch implementation (optional)
|
|
66
|
+
*/
|
|
67
|
+
initializeServices(invoke, hosts, fetchFn) {
|
|
68
|
+
const effectiveInvoke = invoke ?? this.config.invoke;
|
|
69
|
+
const effectiveHosts = hosts ?? this.config.hosts;
|
|
70
|
+
if (!effectiveInvoke) {
|
|
71
|
+
throw new Error("invoke function is required to initialize services. " +
|
|
72
|
+
"Provide it via config.invoke or initializeServices().");
|
|
73
|
+
}
|
|
74
|
+
if (!effectiveHosts || effectiveHosts.length === 0) {
|
|
75
|
+
throw new Error("hosts are required to initialize services. " +
|
|
76
|
+
"Provide them via config.hosts or initializeServices().");
|
|
77
|
+
}
|
|
78
|
+
// Create service context
|
|
79
|
+
this._serviceContext = new ServiceContext({
|
|
80
|
+
invoke: effectiveInvoke,
|
|
81
|
+
fetch: fetchFn ?? this.config.fetch ?? globalThis.fetch.bind(globalThis),
|
|
82
|
+
hosts: effectiveHosts,
|
|
83
|
+
retryPolicy: this.config.retryPolicy,
|
|
84
|
+
});
|
|
85
|
+
// Register default services (can be overridden via config.services)
|
|
86
|
+
const serviceConstructors = {
|
|
87
|
+
kv: KVService,
|
|
88
|
+
...this.config.services,
|
|
89
|
+
};
|
|
90
|
+
// Create and register services
|
|
91
|
+
for (const [name, ServiceClass] of Object.entries(serviceConstructors)) {
|
|
92
|
+
const serviceConfig = this.config.serviceConfigs?.[name] ?? {};
|
|
93
|
+
const service = new ServiceClass(serviceConfig);
|
|
94
|
+
service.initialize(this._serviceContext);
|
|
95
|
+
this._serviceContext.registerService(name, service);
|
|
96
|
+
this._services.set(name, service);
|
|
97
|
+
}
|
|
98
|
+
this._servicesInitialized = true;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the service context.
|
|
102
|
+
* @throws Error if services are not initialized
|
|
103
|
+
*/
|
|
104
|
+
get serviceContext() {
|
|
105
|
+
if (!this._serviceContext) {
|
|
106
|
+
throw new Error("Services not initialized. Call initializeServices() first.");
|
|
107
|
+
}
|
|
108
|
+
return this._serviceContext;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get a registered service by name.
|
|
112
|
+
*
|
|
113
|
+
* @param name - Service name (e.g., 'kv')
|
|
114
|
+
* @returns The service instance or undefined
|
|
115
|
+
*/
|
|
116
|
+
getService(name) {
|
|
117
|
+
return this._services.get(name);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the KV service.
|
|
121
|
+
* @throws Error if services are not initialized
|
|
122
|
+
*/
|
|
123
|
+
get kv() {
|
|
124
|
+
if (!this._servicesInitialized) {
|
|
125
|
+
throw new Error("Services not initialized. Call initializeServices() first, " +
|
|
126
|
+
"or use TinyCloudWeb/TinyCloudNode which handles this automatically.");
|
|
127
|
+
}
|
|
128
|
+
const service = this._services.get("kv");
|
|
129
|
+
if (!service) {
|
|
130
|
+
throw new Error("KV service is not registered.");
|
|
131
|
+
}
|
|
132
|
+
return service;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Notify services of session change.
|
|
136
|
+
* Called internally after sign-in and sign-out.
|
|
137
|
+
*
|
|
138
|
+
* @param session - The new session, or null if signed out
|
|
139
|
+
*/
|
|
140
|
+
notifyServicesOfSessionChange(session) {
|
|
141
|
+
if (this._serviceContext) {
|
|
142
|
+
this._serviceContext.setSession(session);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Abort all pending service operations.
|
|
147
|
+
* Called internally before sign-out.
|
|
148
|
+
*/
|
|
149
|
+
abortServiceOperations() {
|
|
150
|
+
if (this._serviceContext) {
|
|
151
|
+
this._serviceContext.abort();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Convert ClientSession to ServiceSession.
|
|
156
|
+
* Returns null if session lacks required fields.
|
|
157
|
+
*/
|
|
158
|
+
toServiceSession(clientSession) {
|
|
159
|
+
if (!clientSession)
|
|
160
|
+
return null;
|
|
161
|
+
// TinyCloudSession contains the required fields
|
|
162
|
+
const tcSession = clientSession.tinycloudSession;
|
|
163
|
+
if (!tcSession)
|
|
164
|
+
return null;
|
|
165
|
+
return {
|
|
166
|
+
delegationHeader: tcSession.delegationHeader,
|
|
167
|
+
delegationCid: tcSession.delegationCid,
|
|
168
|
+
spaceId: tcSession.spaceId,
|
|
169
|
+
verificationMethod: tcSession.verificationMethod,
|
|
170
|
+
jwk: tcSession.jwk,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Add an extension to the SDK.
|
|
175
|
+
* Extensions can add capabilities and lifecycle hooks.
|
|
176
|
+
*/
|
|
177
|
+
extend(extension) {
|
|
178
|
+
this.extensions.push(extension);
|
|
179
|
+
this.userAuthorization.extend(extension);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Check if an extension is enabled.
|
|
183
|
+
* @param namespace - The extension namespace to check
|
|
184
|
+
*/
|
|
185
|
+
isExtensionEnabled(namespace) {
|
|
186
|
+
return this.extensions.some((ext) => ext.namespace === namespace);
|
|
187
|
+
}
|
|
188
|
+
// === Authentication Methods (delegate to userAuthorization) ===
|
|
189
|
+
/**
|
|
190
|
+
* Get the current session, if signed in.
|
|
191
|
+
*/
|
|
192
|
+
get session() {
|
|
193
|
+
return this.userAuthorization.session;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Check if the user is signed in.
|
|
197
|
+
*/
|
|
198
|
+
get isSignedIn() {
|
|
199
|
+
return !!this.userAuthorization.session;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Sign in and create a new session.
|
|
203
|
+
* Notifies services of the new session after successful sign-in.
|
|
204
|
+
* @returns The new session
|
|
205
|
+
*/
|
|
206
|
+
async signIn() {
|
|
207
|
+
const session = await this.userAuthorization.signIn();
|
|
208
|
+
// Notify services of the new session
|
|
209
|
+
const serviceSession = this.toServiceSession(session);
|
|
210
|
+
this.notifyServicesOfSessionChange(serviceSession);
|
|
211
|
+
return session;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Sign out and clear the current session.
|
|
215
|
+
* Aborts pending service operations and notifies services.
|
|
216
|
+
*/
|
|
217
|
+
async signOut() {
|
|
218
|
+
// Abort all pending operations before sign-out
|
|
219
|
+
this.abortServiceOperations();
|
|
220
|
+
await this.userAuthorization.signOut();
|
|
221
|
+
// Clear session from services
|
|
222
|
+
this.notifyServicesOfSessionChange(null);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get the current wallet address.
|
|
226
|
+
*/
|
|
227
|
+
address() {
|
|
228
|
+
return this.userAuthorization.address();
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get the current chain ID.
|
|
232
|
+
*/
|
|
233
|
+
chainId() {
|
|
234
|
+
return this.userAuthorization.chainId();
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Sign a message with the connected wallet.
|
|
238
|
+
* @param message - Message to sign
|
|
239
|
+
*/
|
|
240
|
+
async signMessage(message) {
|
|
241
|
+
return this.userAuthorization.signMessage(message);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=TinyCloud.js.map
|
|
@@ -0,0 +1 @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validation for TinyCloud configuration.
|
|
5
|
+
* Types are derived from schemas using z.infer<>.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import type { Result } from "./delegations/types.schema";
|
|
11
|
+
import type { ValidationError } from "./storage.schema";
|
|
12
|
+
import type { InvokeFunction, FetchFunction, ServiceConstructor } from "@tinycloud/sdk-services";
|
|
13
|
+
/**
|
|
14
|
+
* Schema for backoff strategy.
|
|
15
|
+
*/
|
|
16
|
+
export declare const BackoffStrategySchema: z.ZodEnum<["none", "linear", "exponential"]>;
|
|
17
|
+
export type BackoffStrategy = z.infer<typeof BackoffStrategySchema>;
|
|
18
|
+
/**
|
|
19
|
+
* Schema for retry policy configuration.
|
|
20
|
+
*/
|
|
21
|
+
export declare const RetryPolicySchema: z.ZodObject<{
|
|
22
|
+
/** Maximum number of attempts (including initial) */
|
|
23
|
+
maxAttempts: z.ZodNumber;
|
|
24
|
+
/** Backoff strategy between retries */
|
|
25
|
+
backoff: z.ZodEnum<["none", "linear", "exponential"]>;
|
|
26
|
+
/** Base delay in milliseconds for backoff calculation */
|
|
27
|
+
baseDelayMs: z.ZodNumber;
|
|
28
|
+
/** Maximum delay in milliseconds between retries */
|
|
29
|
+
maxDelayMs: z.ZodNumber;
|
|
30
|
+
/** Error codes that should trigger a retry */
|
|
31
|
+
retryableErrors: z.ZodArray<z.ZodString, "many">;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
maxAttempts: number;
|
|
34
|
+
backoff: "none" | "linear" | "exponential";
|
|
35
|
+
baseDelayMs: number;
|
|
36
|
+
maxDelayMs: number;
|
|
37
|
+
retryableErrors: string[];
|
|
38
|
+
}, {
|
|
39
|
+
maxAttempts: number;
|
|
40
|
+
backoff: "none" | "linear" | "exponential";
|
|
41
|
+
baseDelayMs: number;
|
|
42
|
+
maxDelayMs: number;
|
|
43
|
+
retryableErrors: string[];
|
|
44
|
+
}>;
|
|
45
|
+
export type RetryPolicy = z.infer<typeof RetryPolicySchema>;
|
|
46
|
+
/**
|
|
47
|
+
* Schema for partial retry policy (all fields optional).
|
|
48
|
+
*/
|
|
49
|
+
export declare const PartialRetryPolicySchema: z.ZodObject<{
|
|
50
|
+
maxAttempts: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
backoff: z.ZodOptional<z.ZodEnum<["none", "linear", "exponential"]>>;
|
|
52
|
+
baseDelayMs: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
maxDelayMs: z.ZodOptional<z.ZodNumber>;
|
|
54
|
+
retryableErrors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
55
|
+
}, "strip", z.ZodTypeAny, {
|
|
56
|
+
maxAttempts?: number | undefined;
|
|
57
|
+
backoff?: "none" | "linear" | "exponential" | undefined;
|
|
58
|
+
baseDelayMs?: number | undefined;
|
|
59
|
+
maxDelayMs?: number | undefined;
|
|
60
|
+
retryableErrors?: string[] | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
maxAttempts?: number | undefined;
|
|
63
|
+
backoff?: "none" | "linear" | "exponential" | undefined;
|
|
64
|
+
baseDelayMs?: number | undefined;
|
|
65
|
+
maxDelayMs?: number | undefined;
|
|
66
|
+
retryableErrors?: string[] | undefined;
|
|
67
|
+
}>;
|
|
68
|
+
export type PartialRetryPolicy = z.infer<typeof PartialRetryPolicySchema>;
|
|
69
|
+
/**
|
|
70
|
+
* Schema for TinyCloud SDK configuration.
|
|
71
|
+
*/
|
|
72
|
+
export declare const TinyCloudConfigSchema: z.ZodObject<{
|
|
73
|
+
/** Whether to automatically resolve ENS names */
|
|
74
|
+
resolveEns: z.ZodOptional<z.ZodBoolean>;
|
|
75
|
+
/**
|
|
76
|
+
* TinyCloud host URLs.
|
|
77
|
+
* Required when using services.
|
|
78
|
+
*/
|
|
79
|
+
hosts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
80
|
+
/**
|
|
81
|
+
* Platform-specific invoke function from WASM binding.
|
|
82
|
+
* Required when using services.
|
|
83
|
+
*/
|
|
84
|
+
invoke: z.ZodOptional<z.ZodEffects<z.ZodUnknown, InvokeFunction, unknown>>;
|
|
85
|
+
/**
|
|
86
|
+
* Custom fetch implementation.
|
|
87
|
+
* Defaults to globalThis.fetch.
|
|
88
|
+
*/
|
|
89
|
+
fetch: z.ZodOptional<z.ZodEffects<z.ZodUnknown, FetchFunction, unknown>>;
|
|
90
|
+
/**
|
|
91
|
+
* Service constructors to register.
|
|
92
|
+
* Built-in services (like KVService) are registered by default unless overridden.
|
|
93
|
+
*/
|
|
94
|
+
services: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodUnknown, ServiceConstructor<Record<string, unknown>, import("@tinycloud/sdk-services").IService>, unknown>>>;
|
|
95
|
+
/**
|
|
96
|
+
* Per-service configuration.
|
|
97
|
+
*/
|
|
98
|
+
serviceConfigs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
99
|
+
/**
|
|
100
|
+
* Retry policy for service operations.
|
|
101
|
+
*/
|
|
102
|
+
retryPolicy: z.ZodOptional<z.ZodObject<{
|
|
103
|
+
maxAttempts: z.ZodOptional<z.ZodNumber>;
|
|
104
|
+
backoff: z.ZodOptional<z.ZodEnum<["none", "linear", "exponential"]>>;
|
|
105
|
+
baseDelayMs: z.ZodOptional<z.ZodNumber>;
|
|
106
|
+
maxDelayMs: z.ZodOptional<z.ZodNumber>;
|
|
107
|
+
retryableErrors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
maxAttempts?: number | undefined;
|
|
110
|
+
backoff?: "none" | "linear" | "exponential" | undefined;
|
|
111
|
+
baseDelayMs?: number | undefined;
|
|
112
|
+
maxDelayMs?: number | undefined;
|
|
113
|
+
retryableErrors?: string[] | undefined;
|
|
114
|
+
}, {
|
|
115
|
+
maxAttempts?: number | undefined;
|
|
116
|
+
backoff?: "none" | "linear" | "exponential" | undefined;
|
|
117
|
+
baseDelayMs?: number | undefined;
|
|
118
|
+
maxDelayMs?: number | undefined;
|
|
119
|
+
retryableErrors?: string[] | undefined;
|
|
120
|
+
}>>;
|
|
121
|
+
}, "strip", z.ZodTypeAny, {
|
|
122
|
+
hosts?: string[] | undefined;
|
|
123
|
+
invoke?: InvokeFunction | undefined;
|
|
124
|
+
fetch?: FetchFunction | undefined;
|
|
125
|
+
resolveEns?: boolean | undefined;
|
|
126
|
+
services?: Record<string, ServiceConstructor<Record<string, unknown>, import("@tinycloud/sdk-services").IService>> | undefined;
|
|
127
|
+
serviceConfigs?: Record<string, Record<string, unknown>> | undefined;
|
|
128
|
+
retryPolicy?: {
|
|
129
|
+
maxAttempts?: number | undefined;
|
|
130
|
+
backoff?: "none" | "linear" | "exponential" | undefined;
|
|
131
|
+
baseDelayMs?: number | undefined;
|
|
132
|
+
maxDelayMs?: number | undefined;
|
|
133
|
+
retryableErrors?: string[] | undefined;
|
|
134
|
+
} | undefined;
|
|
135
|
+
}, {
|
|
136
|
+
hosts?: string[] | undefined;
|
|
137
|
+
invoke?: unknown;
|
|
138
|
+
fetch?: unknown;
|
|
139
|
+
resolveEns?: boolean | undefined;
|
|
140
|
+
services?: Record<string, unknown> | undefined;
|
|
141
|
+
serviceConfigs?: Record<string, Record<string, unknown>> | undefined;
|
|
142
|
+
retryPolicy?: {
|
|
143
|
+
maxAttempts?: number | undefined;
|
|
144
|
+
backoff?: "none" | "linear" | "exponential" | undefined;
|
|
145
|
+
baseDelayMs?: number | undefined;
|
|
146
|
+
maxDelayMs?: number | undefined;
|
|
147
|
+
retryableErrors?: string[] | undefined;
|
|
148
|
+
} | undefined;
|
|
149
|
+
}>;
|
|
150
|
+
export type TinyCloudConfig = z.infer<typeof TinyCloudConfigSchema>;
|
|
151
|
+
/**
|
|
152
|
+
* Validates a TinyCloudConfig object and returns a Result.
|
|
153
|
+
*
|
|
154
|
+
* @param data - Unknown data to validate
|
|
155
|
+
* @returns Result with validated data or validation error
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const result = validateTinyCloudConfig(rawConfig);
|
|
160
|
+
* if (result.ok) {
|
|
161
|
+
* // result.data is typed as TinyCloudConfig
|
|
162
|
+
* console.log(result.data.hosts);
|
|
163
|
+
* } else {
|
|
164
|
+
* console.error(result.error.message);
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function validateTinyCloudConfig(data: unknown): Result<TinyCloudConfig, ValidationError>;
|
|
169
|
+
/**
|
|
170
|
+
* Validates a RetryPolicy object and returns a Result.
|
|
171
|
+
*/
|
|
172
|
+
export declare function validateRetryPolicy(data: unknown): Result<RetryPolicy, ValidationError>;
|
|
173
|
+
//# sourceMappingURL=TinyCloud.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TinyCloud.schema.d.ts","sourceRoot":"","sources":["../src/TinyCloud.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAMjC;;GAEG;AACH,eAAO,MAAM,qBAAqB,8CAA4C,CAAC;AAC/E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,iBAAiB;IAC5B,qDAAqD;;IAErD,uCAAuC;;IAEvC,yDAAyD;;IAEzD,oDAAoD;;IAEpD,8CAA8C;;;;;;;;;;;;;;EAE9C,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;EAA8B,CAAC;AACpE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAM1E;;GAEG;AACH,eAAO,MAAM,qBAAqB;IAChC,iDAAiD;;IAKjD;;;OAGG;;IAGH;;;OAGG;;IAUH;;;OAGG;;IAUH;;;OAGG;;IAWH;;OAEG;;IAGH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEH,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAMpE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,eAAe,EAAE,eAAe,CAAC,CAc1C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,WAAW,EAAE,eAAe,CAAC,CActC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for TinyCloud SDK configuration types.
|
|
3
|
+
*
|
|
4
|
+
* These schemas provide runtime validation for TinyCloud configuration.
|
|
5
|
+
* Types are derived from schemas using z.infer<>.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// Retry Policy Schema
|
|
12
|
+
// =============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Schema for backoff strategy.
|
|
15
|
+
*/
|
|
16
|
+
export const BackoffStrategySchema = z.enum(["none", "linear", "exponential"]);
|
|
17
|
+
/**
|
|
18
|
+
* Schema for retry policy configuration.
|
|
19
|
+
*/
|
|
20
|
+
export const RetryPolicySchema = z.object({
|
|
21
|
+
/** Maximum number of attempts (including initial) */
|
|
22
|
+
maxAttempts: z.number().int().positive(),
|
|
23
|
+
/** Backoff strategy between retries */
|
|
24
|
+
backoff: BackoffStrategySchema,
|
|
25
|
+
/** Base delay in milliseconds for backoff calculation */
|
|
26
|
+
baseDelayMs: z.number().int().nonnegative(),
|
|
27
|
+
/** Maximum delay in milliseconds between retries */
|
|
28
|
+
maxDelayMs: z.number().int().nonnegative(),
|
|
29
|
+
/** Error codes that should trigger a retry */
|
|
30
|
+
retryableErrors: z.array(z.string()),
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Schema for partial retry policy (all fields optional).
|
|
34
|
+
*/
|
|
35
|
+
export const PartialRetryPolicySchema = RetryPolicySchema.partial();
|
|
36
|
+
// =============================================================================
|
|
37
|
+
// TinyCloud Config Schema
|
|
38
|
+
// =============================================================================
|
|
39
|
+
/**
|
|
40
|
+
* Schema for TinyCloud SDK configuration.
|
|
41
|
+
*/
|
|
42
|
+
export const TinyCloudConfigSchema = z.object({
|
|
43
|
+
/** Whether to automatically resolve ENS names */
|
|
44
|
+
resolveEns: z.boolean().optional(),
|
|
45
|
+
// === Service Configuration ===
|
|
46
|
+
/**
|
|
47
|
+
* TinyCloud host URLs.
|
|
48
|
+
* Required when using services.
|
|
49
|
+
*/
|
|
50
|
+
hosts: z.array(z.string()).optional(),
|
|
51
|
+
/**
|
|
52
|
+
* Platform-specific invoke function from WASM binding.
|
|
53
|
+
* Required when using services.
|
|
54
|
+
*/
|
|
55
|
+
invoke: z
|
|
56
|
+
.unknown()
|
|
57
|
+
.refine((val) => val === undefined || typeof val === "function", { message: "Expected an invoke function or undefined" })
|
|
58
|
+
.optional(),
|
|
59
|
+
/**
|
|
60
|
+
* Custom fetch implementation.
|
|
61
|
+
* Defaults to globalThis.fetch.
|
|
62
|
+
*/
|
|
63
|
+
fetch: z
|
|
64
|
+
.unknown()
|
|
65
|
+
.refine((val) => val === undefined || typeof val === "function", { message: "Expected a fetch function or undefined" })
|
|
66
|
+
.optional(),
|
|
67
|
+
/**
|
|
68
|
+
* Service constructors to register.
|
|
69
|
+
* Built-in services (like KVService) are registered by default unless overridden.
|
|
70
|
+
*/
|
|
71
|
+
services: z
|
|
72
|
+
.record(z.string(), z.unknown().refine((val) => typeof val === "function", { message: "Expected a service constructor" }))
|
|
73
|
+
.optional(),
|
|
74
|
+
/**
|
|
75
|
+
* Per-service configuration.
|
|
76
|
+
*/
|
|
77
|
+
serviceConfigs: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
|
|
78
|
+
/**
|
|
79
|
+
* Retry policy for service operations.
|
|
80
|
+
*/
|
|
81
|
+
retryPolicy: PartialRetryPolicySchema.optional(),
|
|
82
|
+
});
|
|
83
|
+
// =============================================================================
|
|
84
|
+
// Validation Helpers
|
|
85
|
+
// =============================================================================
|
|
86
|
+
/**
|
|
87
|
+
* Validates a TinyCloudConfig object and returns a Result.
|
|
88
|
+
*
|
|
89
|
+
* @param data - Unknown data to validate
|
|
90
|
+
* @returns Result with validated data or validation error
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const result = validateTinyCloudConfig(rawConfig);
|
|
95
|
+
* if (result.ok) {
|
|
96
|
+
* // result.data is typed as TinyCloudConfig
|
|
97
|
+
* console.log(result.data.hosts);
|
|
98
|
+
* } else {
|
|
99
|
+
* console.error(result.error.message);
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export function validateTinyCloudConfig(data) {
|
|
104
|
+
const result = TinyCloudConfigSchema.safeParse(data);
|
|
105
|
+
if (!result.success) {
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
error: {
|
|
109
|
+
code: "VALIDATION_ERROR",
|
|
110
|
+
message: result.error.message,
|
|
111
|
+
service: "tinycloud",
|
|
112
|
+
meta: { issues: result.error.issues },
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return { ok: true, data: result.data };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Validates a RetryPolicy object and returns a Result.
|
|
120
|
+
*/
|
|
121
|
+
export function validateRetryPolicy(data) {
|
|
122
|
+
const result = RetryPolicySchema.safeParse(data);
|
|
123
|
+
if (!result.success) {
|
|
124
|
+
return {
|
|
125
|
+
ok: false,
|
|
126
|
+
error: {
|
|
127
|
+
code: "VALIDATION_ERROR",
|
|
128
|
+
message: result.error.message,
|
|
129
|
+
service: "tinycloud",
|
|
130
|
+
meta: { issues: result.error.issues },
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return { ok: true, data: result.data };
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=TinyCloud.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TinyCloud.schema.js","sourceRoot":"","sources":["../src/TinyCloud.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC;AAG/E;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,qDAAqD;IACrD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACxC,uCAAuC;IACvC,OAAO,EAAE,qBAAqB;IAC9B,yDAAyD;IACzD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IAC3C,oDAAoD;IACpD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,C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