@tinycloudlabs/sdk-services 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.
Files changed (57) hide show
  1. package/dist/base/BaseService.d.ts +151 -0
  2. package/dist/base/BaseService.d.ts.map +1 -0
  3. package/dist/base/BaseService.js +221 -0
  4. package/dist/base/BaseService.js.map +1 -0
  5. package/dist/base/index.d.ts +6 -0
  6. package/dist/base/index.d.ts.map +1 -0
  7. package/dist/base/index.js +6 -0
  8. package/dist/base/index.js.map +1 -0
  9. package/dist/base/types.d.ts +36 -0
  10. package/dist/base/types.d.ts.map +1 -0
  11. package/dist/base/types.js +7 -0
  12. package/dist/base/types.js.map +1 -0
  13. package/dist/context.d.ts +142 -0
  14. package/dist/context.d.ts.map +1 -0
  15. package/dist/context.js +218 -0
  16. package/dist/context.js.map +1 -0
  17. package/dist/errors.d.ts +43 -0
  18. package/dist/errors.d.ts.map +1 -0
  19. package/dist/errors.js +111 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.d.ts +47 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +53 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/kv/IKVService.d.ts +148 -0
  26. package/dist/kv/IKVService.d.ts.map +1 -0
  27. package/dist/kv/IKVService.js +8 -0
  28. package/dist/kv/IKVService.js.map +1 -0
  29. package/dist/kv/KVService.d.ts +153 -0
  30. package/dist/kv/KVService.d.ts.map +1 -0
  31. package/dist/kv/KVService.js +337 -0
  32. package/dist/kv/KVService.js.map +1 -0
  33. package/dist/kv/PrefixedKVService.d.ts +246 -0
  34. package/dist/kv/PrefixedKVService.d.ts.map +1 -0
  35. package/dist/kv/PrefixedKVService.js +145 -0
  36. package/dist/kv/PrefixedKVService.js.map +1 -0
  37. package/dist/kv/index.d.ts +10 -0
  38. package/dist/kv/index.d.ts.map +1 -0
  39. package/dist/kv/index.js +12 -0
  40. package/dist/kv/index.js.map +1 -0
  41. package/dist/kv/types.d.ts +204 -0
  42. package/dist/kv/types.d.ts.map +1 -0
  43. package/dist/kv/types.js +16 -0
  44. package/dist/kv/types.js.map +1 -0
  45. package/dist/types.d.ts +259 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js +72 -0
  48. package/dist/types.js.map +1 -0
  49. package/dist/types.schema.d.ts +652 -0
  50. package/dist/types.schema.d.ts.map +1 -0
  51. package/dist/types.schema.js +342 -0
  52. package/dist/types.schema.js.map +1 -0
  53. package/dist/types.schema.test.d.ts +5 -0
  54. package/dist/types.schema.test.d.ts.map +1 -0
  55. package/dist/types.schema.test.js +677 -0
  56. package/dist/types.schema.test.js.map +1 -0
  57. package/package.json +42 -0
@@ -0,0 +1,259 @@
1
+ /**
2
+ * SDK Services - Core Types
3
+ *
4
+ * These types define the service architecture for TinyCloud SDK.
5
+ * Services use dependency injection via IServiceContext for platform independence.
6
+ */
7
+ /**
8
+ * Result type for service operations.
9
+ * Services return Result instead of throwing, making error handling explicit.
10
+ *
11
+ * @template T - The success data type
12
+ * @template E - The error type (defaults to ServiceError)
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const result = await kv.get('key');
17
+ * if (result.ok) {
18
+ * console.log(result.data);
19
+ * } else {
20
+ * console.error(result.error.code);
21
+ * }
22
+ * ```
23
+ */
24
+ export type Result<T, E = ServiceError> = {
25
+ ok: true;
26
+ data: T;
27
+ } | {
28
+ ok: false;
29
+ error: E;
30
+ };
31
+ /**
32
+ * Service error with structured information.
33
+ */
34
+ export interface ServiceError {
35
+ /** Error code for programmatic handling (e.g., 'KV_NOT_FOUND', 'AUTH_EXPIRED') */
36
+ code: string;
37
+ /** Human-readable error message */
38
+ message: string;
39
+ /** Service that produced the error (e.g., 'kv', 'sql') */
40
+ service: string;
41
+ /** Original error if this wraps another error */
42
+ cause?: Error;
43
+ /** Additional metadata about the error */
44
+ meta?: Record<string, unknown>;
45
+ }
46
+ /**
47
+ * Standard error codes used across services.
48
+ */
49
+ export declare const ErrorCodes: {
50
+ readonly NOT_FOUND: "NOT_FOUND";
51
+ readonly AUTH_EXPIRED: "AUTH_EXPIRED";
52
+ readonly AUTH_REQUIRED: "AUTH_REQUIRED";
53
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
54
+ readonly TIMEOUT: "TIMEOUT";
55
+ readonly ABORTED: "ABORTED";
56
+ readonly INVALID_INPUT: "INVALID_INPUT";
57
+ readonly PERMISSION_DENIED: "PERMISSION_DENIED";
58
+ readonly KV_NOT_FOUND: "KV_NOT_FOUND";
59
+ readonly KV_WRITE_FAILED: "KV_WRITE_FAILED";
60
+ };
61
+ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
62
+ /**
63
+ * Session data required for authenticated service operations.
64
+ * Both TinyCloudSession and web-sdk Session can be cast to this interface.
65
+ */
66
+ export interface ServiceSession {
67
+ /** The delegation header containing the UCAN */
68
+ delegationHeader: {
69
+ Authorization: string;
70
+ };
71
+ /** The delegation CID */
72
+ delegationCid: string;
73
+ /** The space ID for this session */
74
+ spaceId: string;
75
+ /** The verification method DID */
76
+ verificationMethod: string;
77
+ /** The session key JWK (required for invoke) */
78
+ jwk: object;
79
+ }
80
+ /**
81
+ * Headers type - compatible with both browser and Node.js.
82
+ */
83
+ export type ServiceHeaders = Record<string, string> | [string, string][];
84
+ /**
85
+ * A single fact object to include in the UCAN invocation.
86
+ * Facts are key-value objects that the server reads from the UCAN facts field.
87
+ */
88
+ export interface InvocationFact {
89
+ [key: string]: unknown;
90
+ }
91
+ /**
92
+ * Facts to include in the UCAN invocation.
93
+ * This is an array of fact objects per the UCAN spec.
94
+ * Used to pass additional parameters that the server reads from the UCAN facts field.
95
+ */
96
+ export type InvocationFacts = InvocationFact[];
97
+ /**
98
+ * Invoke function signature - platform-specific implementation injected via DI.
99
+ * Both node-sdk-wasm and web-sdk-wasm export this with identical signature.
100
+ *
101
+ * @param session - The service session with delegation data
102
+ * @param service - Service name (e.g., "kv")
103
+ * @param path - Resource path or key
104
+ * @param action - Action to perform (e.g., "tinycloud.kv/get")
105
+ * @param facts - Optional facts to include in the UCAN (e.g., for capabilities/read params)
106
+ * @returns Headers to include in the request
107
+ */
108
+ export type InvokeFunction = (session: ServiceSession, service: string, path: string, action: string, facts?: InvocationFacts) => ServiceHeaders;
109
+ /**
110
+ * Fetch request options - compatible with standard fetch API.
111
+ */
112
+ export interface FetchRequestInit {
113
+ method?: string;
114
+ headers?: ServiceHeaders;
115
+ body?: Blob | string;
116
+ signal?: AbortSignal;
117
+ }
118
+ /**
119
+ * Fetch response interface - compatible with standard Response.
120
+ */
121
+ export interface FetchResponse {
122
+ ok: boolean;
123
+ status: number;
124
+ statusText: string;
125
+ headers: {
126
+ get(name: string): string | null;
127
+ };
128
+ json(): Promise<unknown>;
129
+ text(): Promise<string>;
130
+ }
131
+ /**
132
+ * Fetch function signature - allows for custom fetch implementations.
133
+ * Compatible with both browser fetch and Node.js fetch.
134
+ */
135
+ export type FetchFunction = (url: string, init?: FetchRequestInit) => Promise<FetchResponse>;
136
+ /**
137
+ * Configuration for automatic retry of failed requests.
138
+ */
139
+ export interface RetryPolicy {
140
+ /** Maximum number of attempts (including initial) */
141
+ maxAttempts: number;
142
+ /** Backoff strategy between retries */
143
+ backoff: "none" | "linear" | "exponential";
144
+ /** Base delay in milliseconds for backoff calculation */
145
+ baseDelayMs: number;
146
+ /** Maximum delay in milliseconds between retries */
147
+ maxDelayMs: number;
148
+ /** Error codes that should trigger a retry */
149
+ retryableErrors: string[];
150
+ }
151
+ /**
152
+ * Default retry policy.
153
+ */
154
+ export declare const defaultRetryPolicy: RetryPolicy;
155
+ /**
156
+ * Event handler function type.
157
+ */
158
+ export type EventHandler = (data: unknown) => void;
159
+ /**
160
+ * Service interface - base contract for all services.
161
+ */
162
+ export interface IService {
163
+ /** Initialize service with context */
164
+ initialize(context: IServiceContext): void;
165
+ /** Called when session changes (sign-in, sign-out, refresh) */
166
+ onSessionChange(session: ServiceSession | null): void;
167
+ /** Called when SDK signs out - should abort pending operations */
168
+ onSignOut(): void;
169
+ /** Service-specific configuration */
170
+ readonly config: Record<string, unknown>;
171
+ }
172
+ /**
173
+ * Context provided to services for accessing platform dependencies.
174
+ * The SDK creates this context and passes it to services during initialization.
175
+ */
176
+ export interface IServiceContext {
177
+ /** Current active session, or null if not authenticated */
178
+ readonly session: ServiceSession | null;
179
+ /** Whether there is an active authenticated session */
180
+ readonly isAuthenticated: boolean;
181
+ /** Platform-specific invoke function from WASM binding */
182
+ readonly invoke: InvokeFunction;
183
+ /** Fetch function (defaults to globalThis.fetch) */
184
+ readonly fetch: FetchFunction;
185
+ /** Available TinyCloud host URLs */
186
+ readonly hosts: string[];
187
+ /** Get another registered service by name */
188
+ getService<T extends IService>(name: string): T | undefined;
189
+ /** Emit a telemetry event */
190
+ emit(event: string, data: unknown): void;
191
+ /** Subscribe to events */
192
+ on(event: string, handler: EventHandler): () => void;
193
+ /** Abort signal that fires when SDK signs out */
194
+ readonly abortSignal: AbortSignal;
195
+ /** Retry policy for failed requests */
196
+ readonly retryPolicy: RetryPolicy;
197
+ }
198
+ /**
199
+ * Event emitted before a service request.
200
+ */
201
+ export interface ServiceRequestEvent {
202
+ service: string;
203
+ action: string;
204
+ key?: string;
205
+ timestamp: number;
206
+ }
207
+ /**
208
+ * Event emitted after a service response.
209
+ */
210
+ export interface ServiceResponseEvent {
211
+ service: string;
212
+ action: string;
213
+ ok: boolean;
214
+ duration: number;
215
+ status?: number;
216
+ }
217
+ /**
218
+ * Event emitted on service error.
219
+ */
220
+ export interface ServiceErrorEvent {
221
+ service: string;
222
+ error: ServiceError;
223
+ }
224
+ /**
225
+ * Event emitted on retry attempt.
226
+ */
227
+ export interface ServiceRetryEvent {
228
+ service: string;
229
+ attempt: number;
230
+ maxAttempts: number;
231
+ error: ServiceError;
232
+ }
233
+ /**
234
+ * Telemetry event names.
235
+ */
236
+ export declare const TelemetryEvents: {
237
+ readonly SERVICE_REQUEST: "service.request";
238
+ readonly SERVICE_RESPONSE: "service.response";
239
+ readonly SERVICE_ERROR: "service.error";
240
+ readonly SERVICE_RETRY: "service.retry";
241
+ readonly SESSION_CHANGED: "session.changed";
242
+ readonly SESSION_EXPIRED: "session.expired";
243
+ };
244
+ /**
245
+ * Create a success result.
246
+ */
247
+ export declare function ok<T>(data: T): Result<T>;
248
+ /**
249
+ * Create an error result.
250
+ */
251
+ export declare function err<E = ServiceError>(error: E): Result<never, E>;
252
+ /**
253
+ * Create a ServiceError.
254
+ */
255
+ export declare function serviceError(code: string, message: string, service: string, options?: {
256
+ cause?: Error;
257
+ meta?: Record<string, unknown>;
258
+ }): ServiceError;
259
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,YAAY,IAClC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACrB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAE5B;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;CAcb,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAMrE;;;GAGG;AACH,MAAM,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AC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAExC;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,CAAC,GAAG,YAAY,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAEhE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAC1D,YAAY,CAQd"}
package/dist/types.js ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * SDK Services - Core Types
3
+ *
4
+ * These types define the service architecture for TinyCloud SDK.
5
+ * Services use dependency injection via IServiceContext for platform independence.
6
+ */
7
+ /**
8
+ * Standard error codes used across services.
9
+ */
10
+ export const ErrorCodes = {
11
+ // Common errors
12
+ NOT_FOUND: "NOT_FOUND",
13
+ AUTH_EXPIRED: "AUTH_EXPIRED",
14
+ AUTH_REQUIRED: "AUTH_REQUIRED",
15
+ NETWORK_ERROR: "NETWORK_ERROR",
16
+ TIMEOUT: "TIMEOUT",
17
+ ABORTED: "ABORTED",
18
+ INVALID_INPUT: "INVALID_INPUT",
19
+ PERMISSION_DENIED: "PERMISSION_DENIED",
20
+ // KV-specific errors
21
+ KV_NOT_FOUND: "KV_NOT_FOUND",
22
+ KV_WRITE_FAILED: "KV_WRITE_FAILED",
23
+ };
24
+ /**
25
+ * Default retry policy.
26
+ */
27
+ export const defaultRetryPolicy = {
28
+ maxAttempts: 3,
29
+ backoff: "exponential",
30
+ baseDelayMs: 1000,
31
+ maxDelayMs: 10000,
32
+ retryableErrors: [ErrorCodes.NETWORK_ERROR, ErrorCodes.TIMEOUT],
33
+ };
34
+ /**
35
+ * Telemetry event names.
36
+ */
37
+ export const TelemetryEvents = {
38
+ SERVICE_REQUEST: "service.request",
39
+ SERVICE_RESPONSE: "service.response",
40
+ SERVICE_ERROR: "service.error",
41
+ SERVICE_RETRY: "service.retry",
42
+ SESSION_CHANGED: "session.changed",
43
+ SESSION_EXPIRED: "session.expired",
44
+ };
45
+ // =============================================================================
46
+ // Helper Functions
47
+ // =============================================================================
48
+ /**
49
+ * Create a success result.
50
+ */
51
+ export function ok(data) {
52
+ return { ok: true, data };
53
+ }
54
+ /**
55
+ * Create an error result.
56
+ */
57
+ export function err(error) {
58
+ return { ok: false, error };
59
+ }
60
+ /**
61
+ * Create a ServiceError.
62
+ */
63
+ export function serviceError(code, message, service, options) {
64
+ return {
65
+ code,
66
+ message,
67
+ service,
68
+ cause: options?.cause,
69
+ meta: options?.meta,
70
+ };
71
+ }
72
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA2CH;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,gBAAgB;IAChB,SAAS,EAAE,WAAW;IACtB,YAAY,EAAE,cAAc;IAC5B,aAAa,EAAE,eAAe;IAC9B,aAAa,EAAE,eAAe;IAC9B,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,aAAa,EAAE,eAAe;IAC9B,iBAAiB,EAAE,mBAAmB;IAEtC,qBAAqB;IACrB,YAAY,EAAE,cAAc;IAC5B,eAAe,EAAE,iBAAiB;CAC1B,CAAC;AAyHX;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAgB;IAC7C,WAAW,EAAE,CAAC;IACd,OAAO,EAAE,aAAa;IACtB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,KAAK;IACjB,eAAe,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,UAAU,CAAC,OAAO,CAAC;CAChE,CAAC;AA6GF;;GAEG;AACH,MAAM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