@tinycloud/sdk-services 2.3.0-beta.6 → 2.3.0-beta.8
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/dist/{BaseService-DZ2hBJeD.d.cts → BaseService-BdRvNm2s.d.cts} +34 -2
- package/dist/{BaseService-DZ2hBJeD.d.ts → BaseService-BdRvNm2s.d.ts} +34 -2
- package/dist/encryption/index.cjs +30 -6
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.d.cts +1 -1
- package/dist/encryption/index.d.ts +1 -1
- package/dist/encryption/index.js +30 -6
- package/dist/encryption/index.js.map +1 -1
- package/dist/index.cjs +109 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -7
- package/dist/index.d.ts +96 -7
- package/dist/index.js +107 -9
- package/dist/index.js.map +1 -1
- package/dist/kv/index.cjs +30 -6
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.d.cts +1 -1
- package/dist/kv/index.d.ts +1 -1
- package/dist/kv/index.js +30 -6
- package/dist/kv/index.js.map +1 -1
- package/dist/sql/index.cjs +68 -9
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.d.cts +3 -1
- package/dist/sql/index.d.ts +3 -1
- package/dist/sql/index.js +68 -9
- package/dist/sql/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as IServiceContext, a as InvokeFunction, b as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, R as RetryPolicy, c as IService, d as ServiceError, e as Result, B as BaseService, f as StorageQuotaInfo } from './BaseService-
|
|
2
|
-
export {
|
|
1
|
+
import { I as IServiceContext, a as InvokeFunction, b as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, R as RetryPolicy, T as TelemetryConfig, c as IService, E as EventHandler, d as ServiceError, e as Result, B as BaseService, f as StorageQuotaInfo } from './BaseService-BdRvNm2s.cjs';
|
|
2
|
+
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './BaseService-BdRvNm2s.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { IKVService } from './kv/index.cjs';
|
|
5
5
|
export { DEFAULT_SIGNED_READ_URL_EXPIRY_MS, IPrefixedKVService, KVAction, KVActionType, KVBatchPutItem, KVBatchPutOptions, KVBatchPutResponse, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, PrefixedKVService } from './kv/index.cjs';
|
|
@@ -416,17 +416,20 @@ type KVListResultType = z.infer<typeof KVListResultSchema>;
|
|
|
416
416
|
declare const ServiceRequestEventSchema: z.ZodObject<{
|
|
417
417
|
service: z.ZodString;
|
|
418
418
|
action: z.ZodString;
|
|
419
|
+
span: z.ZodOptional<z.ZodString>;
|
|
419
420
|
key: z.ZodOptional<z.ZodString>;
|
|
420
421
|
timestamp: z.ZodNumber;
|
|
421
422
|
}, "strip", z.ZodTypeAny, {
|
|
422
423
|
service: string;
|
|
423
424
|
action: string;
|
|
424
425
|
timestamp: number;
|
|
426
|
+
span?: string | undefined;
|
|
425
427
|
key?: string | undefined;
|
|
426
428
|
}, {
|
|
427
429
|
service: string;
|
|
428
430
|
action: string;
|
|
429
431
|
timestamp: number;
|
|
432
|
+
span?: string | undefined;
|
|
430
433
|
key?: string | undefined;
|
|
431
434
|
}>;
|
|
432
435
|
type ServiceRequestEventType = z.infer<typeof ServiceRequestEventSchema>;
|
|
@@ -436,8 +439,10 @@ type ServiceRequestEventType = z.infer<typeof ServiceRequestEventSchema>;
|
|
|
436
439
|
declare const ServiceResponseEventSchema: z.ZodObject<{
|
|
437
440
|
service: z.ZodString;
|
|
438
441
|
action: z.ZodString;
|
|
442
|
+
span: z.ZodOptional<z.ZodString>;
|
|
439
443
|
ok: z.ZodBoolean;
|
|
440
444
|
duration: z.ZodNumber;
|
|
445
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
441
446
|
status: z.ZodOptional<z.ZodNumber>;
|
|
442
447
|
}, "strip", z.ZodTypeAny, {
|
|
443
448
|
service: string;
|
|
@@ -445,12 +450,16 @@ declare const ServiceResponseEventSchema: z.ZodObject<{
|
|
|
445
450
|
action: string;
|
|
446
451
|
duration: number;
|
|
447
452
|
status?: number | undefined;
|
|
453
|
+
span?: string | undefined;
|
|
454
|
+
durationMs?: number | undefined;
|
|
448
455
|
}, {
|
|
449
456
|
service: string;
|
|
450
457
|
ok: boolean;
|
|
451
458
|
action: string;
|
|
452
459
|
duration: number;
|
|
453
460
|
status?: number | undefined;
|
|
461
|
+
span?: string | undefined;
|
|
462
|
+
durationMs?: number | undefined;
|
|
454
463
|
}>;
|
|
455
464
|
type ServiceResponseEventType = z.infer<typeof ServiceResponseEventSchema>;
|
|
456
465
|
/**
|
|
@@ -458,6 +467,7 @@ type ServiceResponseEventType = z.infer<typeof ServiceResponseEventSchema>;
|
|
|
458
467
|
*/
|
|
459
468
|
declare const ServiceErrorEventSchema: z.ZodObject<{
|
|
460
469
|
service: z.ZodString;
|
|
470
|
+
span: z.ZodOptional<z.ZodString>;
|
|
461
471
|
error: z.ZodObject<{
|
|
462
472
|
/** Error code for programmatic handling (e.g., 'KV_NOT_FOUND', 'AUTH_EXPIRED') */
|
|
463
473
|
code: z.ZodString;
|
|
@@ -491,6 +501,7 @@ declare const ServiceErrorEventSchema: z.ZodObject<{
|
|
|
491
501
|
meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
492
502
|
};
|
|
493
503
|
service: string;
|
|
504
|
+
span?: string | undefined;
|
|
494
505
|
}, {
|
|
495
506
|
error: {
|
|
496
507
|
code: string;
|
|
@@ -500,6 +511,7 @@ declare const ServiceErrorEventSchema: z.ZodObject<{
|
|
|
500
511
|
meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
501
512
|
};
|
|
502
513
|
service: string;
|
|
514
|
+
span?: string | undefined;
|
|
503
515
|
}>;
|
|
504
516
|
type ServiceErrorEventType = z.infer<typeof ServiceErrorEventSchema>;
|
|
505
517
|
/**
|
|
@@ -557,6 +569,70 @@ declare const ServiceRetryEventSchema: z.ZodObject<{
|
|
|
557
569
|
maxAttempts: number;
|
|
558
570
|
}>;
|
|
559
571
|
type ServiceRetryEventType = z.infer<typeof ServiceRetryEventSchema>;
|
|
572
|
+
/**
|
|
573
|
+
* Schema for generic named span event.
|
|
574
|
+
*/
|
|
575
|
+
declare const TelemetrySpanEventSchema: z.ZodObject<{
|
|
576
|
+
span: z.ZodString;
|
|
577
|
+
ok: z.ZodBoolean;
|
|
578
|
+
durationMs: z.ZodNumber;
|
|
579
|
+
service: z.ZodOptional<z.ZodString>;
|
|
580
|
+
action: z.ZodOptional<z.ZodString>;
|
|
581
|
+
status: z.ZodOptional<z.ZodNumber>;
|
|
582
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
583
|
+
/** Error code for programmatic handling (e.g., 'KV_NOT_FOUND', 'AUTH_EXPIRED') */
|
|
584
|
+
code: z.ZodString;
|
|
585
|
+
/** Human-readable error message */
|
|
586
|
+
message: z.ZodString;
|
|
587
|
+
/** Service that produced the error (e.g., 'kv', 'sql') */
|
|
588
|
+
service: z.ZodString;
|
|
589
|
+
/** Original error if this wraps another error - not validated since Error is a class */
|
|
590
|
+
cause: z.ZodOptional<z.ZodUnknown>;
|
|
591
|
+
/** Additional metadata about the error - passthrough allows any object properties */
|
|
592
|
+
meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
|
593
|
+
}, "strip", z.ZodTypeAny, {
|
|
594
|
+
code: string;
|
|
595
|
+
message: string;
|
|
596
|
+
service: string;
|
|
597
|
+
cause?: unknown;
|
|
598
|
+
meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
599
|
+
}, {
|
|
600
|
+
code: string;
|
|
601
|
+
message: string;
|
|
602
|
+
service: string;
|
|
603
|
+
cause?: unknown;
|
|
604
|
+
meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
605
|
+
}>>;
|
|
606
|
+
}, "strip", z.ZodTypeAny, {
|
|
607
|
+
ok: boolean;
|
|
608
|
+
span: string;
|
|
609
|
+
durationMs: number;
|
|
610
|
+
error?: {
|
|
611
|
+
code: string;
|
|
612
|
+
message: string;
|
|
613
|
+
service: string;
|
|
614
|
+
cause?: unknown;
|
|
615
|
+
meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
616
|
+
} | undefined;
|
|
617
|
+
service?: string | undefined;
|
|
618
|
+
status?: number | undefined;
|
|
619
|
+
action?: string | undefined;
|
|
620
|
+
}, {
|
|
621
|
+
ok: boolean;
|
|
622
|
+
span: string;
|
|
623
|
+
durationMs: number;
|
|
624
|
+
error?: {
|
|
625
|
+
code: string;
|
|
626
|
+
message: string;
|
|
627
|
+
service: string;
|
|
628
|
+
cause?: unknown;
|
|
629
|
+
meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
630
|
+
} | undefined;
|
|
631
|
+
service?: string | undefined;
|
|
632
|
+
status?: number | undefined;
|
|
633
|
+
action?: string | undefined;
|
|
634
|
+
}>;
|
|
635
|
+
type TelemetrySpanEventType = z.infer<typeof TelemetrySpanEventSchema>;
|
|
560
636
|
/**
|
|
561
637
|
* Schema for retry policy configuration.
|
|
562
638
|
*/
|
|
@@ -718,16 +794,25 @@ declare function validateServiceResponseEvent(data: unknown): {
|
|
|
718
794
|
ok: false;
|
|
719
795
|
error: ValidationError;
|
|
720
796
|
};
|
|
797
|
+
/**
|
|
798
|
+
* Validate named telemetry span event against the schema.
|
|
799
|
+
*
|
|
800
|
+
* @param data - Unknown data to validate
|
|
801
|
+
* @returns Result with validated data or validation error
|
|
802
|
+
*/
|
|
803
|
+
declare function validateTelemetrySpanEvent(data: unknown): {
|
|
804
|
+
ok: true;
|
|
805
|
+
data: TelemetrySpanEventType;
|
|
806
|
+
} | {
|
|
807
|
+
ok: false;
|
|
808
|
+
error: ValidationError;
|
|
809
|
+
};
|
|
721
810
|
|
|
722
811
|
/**
|
|
723
812
|
* ServiceContext implementation for TinyCloud SDK Services
|
|
724
813
|
* @module @tinycloud/sdk-services
|
|
725
814
|
*/
|
|
726
815
|
|
|
727
|
-
/**
|
|
728
|
-
* Event handler type for telemetry events.
|
|
729
|
-
*/
|
|
730
|
-
type EventHandler = (data: unknown) => void;
|
|
731
816
|
/**
|
|
732
817
|
* Configuration options for ServiceContext.
|
|
733
818
|
*/
|
|
@@ -744,6 +829,8 @@ interface ServiceContextConfig {
|
|
|
744
829
|
session?: ServiceSession | null;
|
|
745
830
|
/** Retry policy configuration */
|
|
746
831
|
retryPolicy?: Partial<RetryPolicy>;
|
|
832
|
+
/** Default-off telemetry event delivery. */
|
|
833
|
+
telemetry?: TelemetryConfig;
|
|
747
834
|
}
|
|
748
835
|
/**
|
|
749
836
|
* ServiceContext provides platform dependencies and cross-service access to services.
|
|
@@ -776,6 +863,8 @@ declare class ServiceContext implements IServiceContext {
|
|
|
776
863
|
private readonly _fetch;
|
|
777
864
|
private readonly _hosts;
|
|
778
865
|
private readonly _retryPolicy;
|
|
866
|
+
private readonly _telemetryEnabled;
|
|
867
|
+
private readonly _telemetryHandler?;
|
|
779
868
|
constructor(config: ServiceContextConfig);
|
|
780
869
|
/**
|
|
781
870
|
* Get the current session.
|
|
@@ -2010,4 +2099,4 @@ declare class SecretsService implements ISecretsService {
|
|
|
2010
2099
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2011
2100
|
}
|
|
2012
2101
|
|
|
2013
|
-
export { BaseService, type BaseServiceOptions, type ColumnInfo, type DataVaultConfig, DataVaultService, DecryptCapabilityProof, DuckDbAction, type DuckDbActionType, type DuckDbBatchOptions, type BatchResponse as DuckDbBatchResponse, DuckDbDatabaseHandle, type DuckDbExecuteOptions, type ExecuteResponse as DuckDbExecuteResponse, type DuckDbOptions, type DuckDbQueryOptions, type QueryResponse as DuckDbQueryResponse, DuckDbService, type DuckDbServiceConfig, type DuckDbStatement, type DuckDbValue, FetchFunction, GenericKVResponseSchema, type GenericKVResponseType, GenericResultSchema, type HookEvent, type HookServiceName, type HookStreamEvent, type HookSubscription, type HookWebhookListOptions, type HookWebhookRecord, type HookWebhookRegistration, type HookWebhookScope, type HookWebhookUnregisterOptions, HooksService, type HooksServiceConfig, type IDataVaultService, type IDuckDbDatabaseHandle, type IDuckDbService, IEncryptionService, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, type SchemaInfo, type SecretPayload, type SecretScopeOptions, type SecretsError, SecretsService, type ServiceConstructor, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, type ServiceRegistration, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, type TableInfo, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, authExpiredError, authRequiredError, authUnauthorizedError, canonicalizeSecretScope, createKVResponseSchema, createResultSchema, createVaultCrypto, errorResult, networkError, notFoundError, parseAuthError, permissionDeniedError, resolveSecretListPrefix, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, timeoutError, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, wrapError };
|
|
2102
|
+
export { BaseService, type BaseServiceOptions, type ColumnInfo, type DataVaultConfig, DataVaultService, DecryptCapabilityProof, DuckDbAction, type DuckDbActionType, type DuckDbBatchOptions, type BatchResponse as DuckDbBatchResponse, DuckDbDatabaseHandle, type DuckDbExecuteOptions, type ExecuteResponse as DuckDbExecuteResponse, type DuckDbOptions, type DuckDbQueryOptions, type QueryResponse as DuckDbQueryResponse, DuckDbService, type DuckDbServiceConfig, type DuckDbStatement, type DuckDbValue, EventHandler, FetchFunction, GenericKVResponseSchema, type GenericKVResponseType, GenericResultSchema, type HookEvent, type HookServiceName, type HookStreamEvent, type HookSubscription, type HookWebhookListOptions, type HookWebhookRecord, type HookWebhookRegistration, type HookWebhookScope, type HookWebhookUnregisterOptions, HooksService, type HooksServiceConfig, type IDataVaultService, type IDuckDbDatabaseHandle, type IDuckDbService, IEncryptionService, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, type SchemaInfo, type SecretPayload, type SecretScopeOptions, type SecretsError, SecretsService, type ServiceConstructor, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, type ServiceRegistration, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, type TableInfo, TelemetryConfig, TelemetrySpanEventSchema, type TelemetrySpanEventType, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, authExpiredError, authRequiredError, authUnauthorizedError, canonicalizeSecretScope, createKVResponseSchema, createResultSchema, createVaultCrypto, errorResult, networkError, notFoundError, parseAuthError, permissionDeniedError, resolveSecretListPrefix, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, timeoutError, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, validateTelemetrySpanEvent, wrapError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as IServiceContext, a as InvokeFunction, b as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, R as RetryPolicy, c as IService, d as ServiceError, e as Result, B as BaseService, f as StorageQuotaInfo } from './BaseService-
|
|
2
|
-
export {
|
|
1
|
+
import { I as IServiceContext, a as InvokeFunction, b as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, R as RetryPolicy, T as TelemetryConfig, c as IService, E as EventHandler, d as ServiceError, e as Result, B as BaseService, f as StorageQuotaInfo } from './BaseService-BdRvNm2s.js';
|
|
2
|
+
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './BaseService-BdRvNm2s.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { IKVService } from './kv/index.js';
|
|
5
5
|
export { DEFAULT_SIGNED_READ_URL_EXPIRY_MS, IPrefixedKVService, KVAction, KVActionType, KVBatchPutItem, KVBatchPutOptions, KVBatchPutResponse, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, PrefixedKVService } from './kv/index.js';
|
|
@@ -416,17 +416,20 @@ type KVListResultType = z.infer<typeof KVListResultSchema>;
|
|
|
416
416
|
declare const ServiceRequestEventSchema: z.ZodObject<{
|
|
417
417
|
service: z.ZodString;
|
|
418
418
|
action: z.ZodString;
|
|
419
|
+
span: z.ZodOptional<z.ZodString>;
|
|
419
420
|
key: z.ZodOptional<z.ZodString>;
|
|
420
421
|
timestamp: z.ZodNumber;
|
|
421
422
|
}, "strip", z.ZodTypeAny, {
|
|
422
423
|
service: string;
|
|
423
424
|
action: string;
|
|
424
425
|
timestamp: number;
|
|
426
|
+
span?: string | undefined;
|
|
425
427
|
key?: string | undefined;
|
|
426
428
|
}, {
|
|
427
429
|
service: string;
|
|
428
430
|
action: string;
|
|
429
431
|
timestamp: number;
|
|
432
|
+
span?: string | undefined;
|
|
430
433
|
key?: string | undefined;
|
|
431
434
|
}>;
|
|
432
435
|
type ServiceRequestEventType = z.infer<typeof ServiceRequestEventSchema>;
|
|
@@ -436,8 +439,10 @@ type ServiceRequestEventType = z.infer<typeof ServiceRequestEventSchema>;
|
|
|
436
439
|
declare const ServiceResponseEventSchema: z.ZodObject<{
|
|
437
440
|
service: z.ZodString;
|
|
438
441
|
action: z.ZodString;
|
|
442
|
+
span: z.ZodOptional<z.ZodString>;
|
|
439
443
|
ok: z.ZodBoolean;
|
|
440
444
|
duration: z.ZodNumber;
|
|
445
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
441
446
|
status: z.ZodOptional<z.ZodNumber>;
|
|
442
447
|
}, "strip", z.ZodTypeAny, {
|
|
443
448
|
service: string;
|
|
@@ -445,12 +450,16 @@ declare const ServiceResponseEventSchema: z.ZodObject<{
|
|
|
445
450
|
action: string;
|
|
446
451
|
duration: number;
|
|
447
452
|
status?: number | undefined;
|
|
453
|
+
span?: string | undefined;
|
|
454
|
+
durationMs?: number | undefined;
|
|
448
455
|
}, {
|
|
449
456
|
service: string;
|
|
450
457
|
ok: boolean;
|
|
451
458
|
action: string;
|
|
452
459
|
duration: number;
|
|
453
460
|
status?: number | undefined;
|
|
461
|
+
span?: string | undefined;
|
|
462
|
+
durationMs?: number | undefined;
|
|
454
463
|
}>;
|
|
455
464
|
type ServiceResponseEventType = z.infer<typeof ServiceResponseEventSchema>;
|
|
456
465
|
/**
|
|
@@ -458,6 +467,7 @@ type ServiceResponseEventType = z.infer<typeof ServiceResponseEventSchema>;
|
|
|
458
467
|
*/
|
|
459
468
|
declare const ServiceErrorEventSchema: z.ZodObject<{
|
|
460
469
|
service: z.ZodString;
|
|
470
|
+
span: z.ZodOptional<z.ZodString>;
|
|
461
471
|
error: z.ZodObject<{
|
|
462
472
|
/** Error code for programmatic handling (e.g., 'KV_NOT_FOUND', 'AUTH_EXPIRED') */
|
|
463
473
|
code: z.ZodString;
|
|
@@ -491,6 +501,7 @@ declare const ServiceErrorEventSchema: z.ZodObject<{
|
|
|
491
501
|
meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
492
502
|
};
|
|
493
503
|
service: string;
|
|
504
|
+
span?: string | undefined;
|
|
494
505
|
}, {
|
|
495
506
|
error: {
|
|
496
507
|
code: string;
|
|
@@ -500,6 +511,7 @@ declare const ServiceErrorEventSchema: z.ZodObject<{
|
|
|
500
511
|
meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
501
512
|
};
|
|
502
513
|
service: string;
|
|
514
|
+
span?: string | undefined;
|
|
503
515
|
}>;
|
|
504
516
|
type ServiceErrorEventType = z.infer<typeof ServiceErrorEventSchema>;
|
|
505
517
|
/**
|
|
@@ -557,6 +569,70 @@ declare const ServiceRetryEventSchema: z.ZodObject<{
|
|
|
557
569
|
maxAttempts: number;
|
|
558
570
|
}>;
|
|
559
571
|
type ServiceRetryEventType = z.infer<typeof ServiceRetryEventSchema>;
|
|
572
|
+
/**
|
|
573
|
+
* Schema for generic named span event.
|
|
574
|
+
*/
|
|
575
|
+
declare const TelemetrySpanEventSchema: z.ZodObject<{
|
|
576
|
+
span: z.ZodString;
|
|
577
|
+
ok: z.ZodBoolean;
|
|
578
|
+
durationMs: z.ZodNumber;
|
|
579
|
+
service: z.ZodOptional<z.ZodString>;
|
|
580
|
+
action: z.ZodOptional<z.ZodString>;
|
|
581
|
+
status: z.ZodOptional<z.ZodNumber>;
|
|
582
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
583
|
+
/** Error code for programmatic handling (e.g., 'KV_NOT_FOUND', 'AUTH_EXPIRED') */
|
|
584
|
+
code: z.ZodString;
|
|
585
|
+
/** Human-readable error message */
|
|
586
|
+
message: z.ZodString;
|
|
587
|
+
/** Service that produced the error (e.g., 'kv', 'sql') */
|
|
588
|
+
service: z.ZodString;
|
|
589
|
+
/** Original error if this wraps another error - not validated since Error is a class */
|
|
590
|
+
cause: z.ZodOptional<z.ZodUnknown>;
|
|
591
|
+
/** Additional metadata about the error - passthrough allows any object properties */
|
|
592
|
+
meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
|
593
|
+
}, "strip", z.ZodTypeAny, {
|
|
594
|
+
code: string;
|
|
595
|
+
message: string;
|
|
596
|
+
service: string;
|
|
597
|
+
cause?: unknown;
|
|
598
|
+
meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
599
|
+
}, {
|
|
600
|
+
code: string;
|
|
601
|
+
message: string;
|
|
602
|
+
service: string;
|
|
603
|
+
cause?: unknown;
|
|
604
|
+
meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
605
|
+
}>>;
|
|
606
|
+
}, "strip", z.ZodTypeAny, {
|
|
607
|
+
ok: boolean;
|
|
608
|
+
span: string;
|
|
609
|
+
durationMs: number;
|
|
610
|
+
error?: {
|
|
611
|
+
code: string;
|
|
612
|
+
message: string;
|
|
613
|
+
service: string;
|
|
614
|
+
cause?: unknown;
|
|
615
|
+
meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
616
|
+
} | undefined;
|
|
617
|
+
service?: string | undefined;
|
|
618
|
+
status?: number | undefined;
|
|
619
|
+
action?: string | undefined;
|
|
620
|
+
}, {
|
|
621
|
+
ok: boolean;
|
|
622
|
+
span: string;
|
|
623
|
+
durationMs: number;
|
|
624
|
+
error?: {
|
|
625
|
+
code: string;
|
|
626
|
+
message: string;
|
|
627
|
+
service: string;
|
|
628
|
+
cause?: unknown;
|
|
629
|
+
meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
630
|
+
} | undefined;
|
|
631
|
+
service?: string | undefined;
|
|
632
|
+
status?: number | undefined;
|
|
633
|
+
action?: string | undefined;
|
|
634
|
+
}>;
|
|
635
|
+
type TelemetrySpanEventType = z.infer<typeof TelemetrySpanEventSchema>;
|
|
560
636
|
/**
|
|
561
637
|
* Schema for retry policy configuration.
|
|
562
638
|
*/
|
|
@@ -718,16 +794,25 @@ declare function validateServiceResponseEvent(data: unknown): {
|
|
|
718
794
|
ok: false;
|
|
719
795
|
error: ValidationError;
|
|
720
796
|
};
|
|
797
|
+
/**
|
|
798
|
+
* Validate named telemetry span event against the schema.
|
|
799
|
+
*
|
|
800
|
+
* @param data - Unknown data to validate
|
|
801
|
+
* @returns Result with validated data or validation error
|
|
802
|
+
*/
|
|
803
|
+
declare function validateTelemetrySpanEvent(data: unknown): {
|
|
804
|
+
ok: true;
|
|
805
|
+
data: TelemetrySpanEventType;
|
|
806
|
+
} | {
|
|
807
|
+
ok: false;
|
|
808
|
+
error: ValidationError;
|
|
809
|
+
};
|
|
721
810
|
|
|
722
811
|
/**
|
|
723
812
|
* ServiceContext implementation for TinyCloud SDK Services
|
|
724
813
|
* @module @tinycloud/sdk-services
|
|
725
814
|
*/
|
|
726
815
|
|
|
727
|
-
/**
|
|
728
|
-
* Event handler type for telemetry events.
|
|
729
|
-
*/
|
|
730
|
-
type EventHandler = (data: unknown) => void;
|
|
731
816
|
/**
|
|
732
817
|
* Configuration options for ServiceContext.
|
|
733
818
|
*/
|
|
@@ -744,6 +829,8 @@ interface ServiceContextConfig {
|
|
|
744
829
|
session?: ServiceSession | null;
|
|
745
830
|
/** Retry policy configuration */
|
|
746
831
|
retryPolicy?: Partial<RetryPolicy>;
|
|
832
|
+
/** Default-off telemetry event delivery. */
|
|
833
|
+
telemetry?: TelemetryConfig;
|
|
747
834
|
}
|
|
748
835
|
/**
|
|
749
836
|
* ServiceContext provides platform dependencies and cross-service access to services.
|
|
@@ -776,6 +863,8 @@ declare class ServiceContext implements IServiceContext {
|
|
|
776
863
|
private readonly _fetch;
|
|
777
864
|
private readonly _hosts;
|
|
778
865
|
private readonly _retryPolicy;
|
|
866
|
+
private readonly _telemetryEnabled;
|
|
867
|
+
private readonly _telemetryHandler?;
|
|
779
868
|
constructor(config: ServiceContextConfig);
|
|
780
869
|
/**
|
|
781
870
|
* Get the current session.
|
|
@@ -2010,4 +2099,4 @@ declare class SecretsService implements ISecretsService {
|
|
|
2010
2099
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2011
2100
|
}
|
|
2012
2101
|
|
|
2013
|
-
export { BaseService, type BaseServiceOptions, type ColumnInfo, type DataVaultConfig, DataVaultService, DecryptCapabilityProof, DuckDbAction, type DuckDbActionType, type DuckDbBatchOptions, type BatchResponse as DuckDbBatchResponse, DuckDbDatabaseHandle, type DuckDbExecuteOptions, type ExecuteResponse as DuckDbExecuteResponse, type DuckDbOptions, type DuckDbQueryOptions, type QueryResponse as DuckDbQueryResponse, DuckDbService, type DuckDbServiceConfig, type DuckDbStatement, type DuckDbValue, FetchFunction, GenericKVResponseSchema, type GenericKVResponseType, GenericResultSchema, type HookEvent, type HookServiceName, type HookStreamEvent, type HookSubscription, type HookWebhookListOptions, type HookWebhookRecord, type HookWebhookRegistration, type HookWebhookScope, type HookWebhookUnregisterOptions, HooksService, type HooksServiceConfig, type IDataVaultService, type IDuckDbDatabaseHandle, type IDuckDbService, IEncryptionService, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, type SchemaInfo, type SecretPayload, type SecretScopeOptions, type SecretsError, SecretsService, type ServiceConstructor, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, type ServiceRegistration, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, type TableInfo, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, authExpiredError, authRequiredError, authUnauthorizedError, canonicalizeSecretScope, createKVResponseSchema, createResultSchema, createVaultCrypto, errorResult, networkError, notFoundError, parseAuthError, permissionDeniedError, resolveSecretListPrefix, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, timeoutError, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, wrapError };
|
|
2102
|
+
export { BaseService, type BaseServiceOptions, type ColumnInfo, type DataVaultConfig, DataVaultService, DecryptCapabilityProof, DuckDbAction, type DuckDbActionType, type DuckDbBatchOptions, type BatchResponse as DuckDbBatchResponse, DuckDbDatabaseHandle, type DuckDbExecuteOptions, type ExecuteResponse as DuckDbExecuteResponse, type DuckDbOptions, type DuckDbQueryOptions, type QueryResponse as DuckDbQueryResponse, DuckDbService, type DuckDbServiceConfig, type DuckDbStatement, type DuckDbValue, EventHandler, FetchFunction, GenericKVResponseSchema, type GenericKVResponseType, GenericResultSchema, type HookEvent, type HookServiceName, type HookStreamEvent, type HookSubscription, type HookWebhookListOptions, type HookWebhookRecord, type HookWebhookRegistration, type HookWebhookScope, type HookWebhookUnregisterOptions, HooksService, type HooksServiceConfig, type IDataVaultService, type IDuckDbDatabaseHandle, type IDuckDbService, IEncryptionService, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, type SchemaInfo, type SecretPayload, type SecretScopeOptions, type SecretsError, SecretsService, type ServiceConstructor, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, type ServiceRegistration, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, type TableInfo, TelemetryConfig, TelemetrySpanEventSchema, type TelemetrySpanEventType, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, authExpiredError, authRequiredError, authUnauthorizedError, canonicalizeSecretScope, createKVResponseSchema, createResultSchema, createVaultCrypto, errorResult, networkError, notFoundError, parseAuthError, permissionDeniedError, resolveSecretListPrefix, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, timeoutError, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, validateTelemetrySpanEvent, wrapError };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ var defaultRetryPolicy = {
|
|
|
43
43
|
retryableErrors: [ErrorCodes.NETWORK_ERROR, ErrorCodes.TIMEOUT]
|
|
44
44
|
};
|
|
45
45
|
var TelemetryEvents = {
|
|
46
|
+
SPAN: "telemetry.span",
|
|
46
47
|
SERVICE_REQUEST: "service.request",
|
|
47
48
|
SERVICE_RESPONSE: "service.response",
|
|
48
49
|
SERVICE_ERROR: "service.error",
|
|
@@ -120,18 +121,22 @@ var KVListResultSchema = createResultSchema(KVListResponseSchema);
|
|
|
120
121
|
var ServiceRequestEventSchema = z.object({
|
|
121
122
|
service: z.string(),
|
|
122
123
|
action: z.string(),
|
|
124
|
+
span: z.string().optional(),
|
|
123
125
|
key: z.string().optional(),
|
|
124
126
|
timestamp: z.number()
|
|
125
127
|
});
|
|
126
128
|
var ServiceResponseEventSchema = z.object({
|
|
127
129
|
service: z.string(),
|
|
128
130
|
action: z.string(),
|
|
131
|
+
span: z.string().optional(),
|
|
129
132
|
ok: z.boolean(),
|
|
130
133
|
duration: z.number(),
|
|
134
|
+
durationMs: z.number().optional(),
|
|
131
135
|
status: z.number().optional()
|
|
132
136
|
});
|
|
133
137
|
var ServiceErrorEventSchema = z.object({
|
|
134
138
|
service: z.string(),
|
|
139
|
+
span: z.string().optional(),
|
|
135
140
|
error: ServiceErrorSchema
|
|
136
141
|
});
|
|
137
142
|
var ServiceRetryEventSchema = z.object({
|
|
@@ -140,6 +145,15 @@ var ServiceRetryEventSchema = z.object({
|
|
|
140
145
|
maxAttempts: z.number().int().positive(),
|
|
141
146
|
error: ServiceErrorSchema
|
|
142
147
|
});
|
|
148
|
+
var TelemetrySpanEventSchema = z.object({
|
|
149
|
+
span: z.string(),
|
|
150
|
+
ok: z.boolean(),
|
|
151
|
+
durationMs: z.number(),
|
|
152
|
+
service: z.string().optional(),
|
|
153
|
+
action: z.string().optional(),
|
|
154
|
+
status: z.number().optional(),
|
|
155
|
+
error: ServiceErrorSchema.optional()
|
|
156
|
+
});
|
|
143
157
|
var RetryPolicySchema = z.object({
|
|
144
158
|
/** Maximum number of attempts (including initial) */
|
|
145
159
|
maxAttempts: z.number().int().positive(),
|
|
@@ -271,6 +285,21 @@ function validateServiceResponseEvent(data) {
|
|
|
271
285
|
}
|
|
272
286
|
return { ok: true, data: result.data };
|
|
273
287
|
}
|
|
288
|
+
function validateTelemetrySpanEvent(data) {
|
|
289
|
+
const result = TelemetrySpanEventSchema.safeParse(data);
|
|
290
|
+
if (!result.success) {
|
|
291
|
+
return {
|
|
292
|
+
ok: false,
|
|
293
|
+
error: {
|
|
294
|
+
code: "VALIDATION_ERROR",
|
|
295
|
+
message: result.error.message,
|
|
296
|
+
service: "telemetry",
|
|
297
|
+
meta: { issues: result.error.issues }
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
return { ok: true, data: result.data };
|
|
302
|
+
}
|
|
274
303
|
|
|
275
304
|
// src/context.ts
|
|
276
305
|
var ServiceContext = class {
|
|
@@ -288,6 +317,8 @@ var ServiceContext = class {
|
|
|
288
317
|
...defaultRetryPolicy,
|
|
289
318
|
...config.retryPolicy
|
|
290
319
|
};
|
|
320
|
+
this._telemetryEnabled = typeof config.telemetry === "boolean" ? config.telemetry : config.telemetry?.enabled === true;
|
|
321
|
+
this._telemetryHandler = typeof config.telemetry === "object" ? config.telemetry.onEvent : void 0;
|
|
291
322
|
}
|
|
292
323
|
// ============================================================
|
|
293
324
|
// Session Management
|
|
@@ -382,6 +413,13 @@ var ServiceContext = class {
|
|
|
382
413
|
* @param data - Event data
|
|
383
414
|
*/
|
|
384
415
|
emit(event, data) {
|
|
416
|
+
if (this._telemetryEnabled && this._telemetryHandler) {
|
|
417
|
+
try {
|
|
418
|
+
this._telemetryHandler(event, data);
|
|
419
|
+
} catch (error) {
|
|
420
|
+
console.error(`Error in telemetry handler for "${event}":`, error);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
385
423
|
const handlers = this._eventHandlers.get(event);
|
|
386
424
|
if (handlers) {
|
|
387
425
|
for (const handler of handlers) {
|
|
@@ -660,9 +698,11 @@ var BaseService = class {
|
|
|
660
698
|
* @param key - Optional key/path being accessed
|
|
661
699
|
*/
|
|
662
700
|
emitRequest(action, key) {
|
|
701
|
+
const service = this.getServiceName();
|
|
663
702
|
this.emit(TelemetryEvents.SERVICE_REQUEST, {
|
|
664
|
-
service
|
|
703
|
+
service,
|
|
665
704
|
action,
|
|
705
|
+
span: this.spanName(action),
|
|
666
706
|
key,
|
|
667
707
|
timestamp: Date.now()
|
|
668
708
|
});
|
|
@@ -676,11 +716,24 @@ var BaseService = class {
|
|
|
676
716
|
* @param status - Optional HTTP status code
|
|
677
717
|
*/
|
|
678
718
|
emitResponse(action, ok2, startTime, status) {
|
|
719
|
+
const service = this.getServiceName();
|
|
720
|
+
const durationMs = Date.now() - startTime;
|
|
721
|
+
const span = this.spanName(action);
|
|
679
722
|
this.emit(TelemetryEvents.SERVICE_RESPONSE, {
|
|
680
|
-
service
|
|
723
|
+
service,
|
|
681
724
|
action,
|
|
725
|
+
span,
|
|
682
726
|
ok: ok2,
|
|
683
|
-
duration:
|
|
727
|
+
duration: durationMs,
|
|
728
|
+
durationMs,
|
|
729
|
+
status
|
|
730
|
+
});
|
|
731
|
+
this.emit(TelemetryEvents.SPAN, {
|
|
732
|
+
span,
|
|
733
|
+
service,
|
|
734
|
+
action,
|
|
735
|
+
ok: ok2,
|
|
736
|
+
durationMs,
|
|
684
737
|
status
|
|
685
738
|
});
|
|
686
739
|
}
|
|
@@ -689,9 +742,11 @@ var BaseService = class {
|
|
|
689
742
|
*
|
|
690
743
|
* @param error - The service error
|
|
691
744
|
*/
|
|
692
|
-
emitError(error) {
|
|
745
|
+
emitError(error, action) {
|
|
746
|
+
const span = action ? this.spanName(action) : void 0;
|
|
693
747
|
this.emit(TelemetryEvents.SERVICE_ERROR, {
|
|
694
748
|
service: this.getServiceName(),
|
|
749
|
+
...span ? { span } : {},
|
|
695
750
|
error
|
|
696
751
|
});
|
|
697
752
|
}
|
|
@@ -702,6 +757,12 @@ var BaseService = class {
|
|
|
702
757
|
getServiceName() {
|
|
703
758
|
return this.constructor.serviceName;
|
|
704
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Stable span name used by SDK telemetry sinks.
|
|
762
|
+
*/
|
|
763
|
+
spanName(action) {
|
|
764
|
+
return `sdk.${this.getServiceName()}.${action}`;
|
|
765
|
+
}
|
|
705
766
|
/**
|
|
706
767
|
* Create a combined abort signal from multiple sources.
|
|
707
768
|
*
|
|
@@ -739,13 +800,13 @@ var BaseService = class {
|
|
|
739
800
|
this.emitResponse(action, true, startTime);
|
|
740
801
|
} else {
|
|
741
802
|
this.emitResponse(action, false, startTime);
|
|
742
|
-
this.emitError(result.error);
|
|
803
|
+
this.emitError(result.error, action);
|
|
743
804
|
}
|
|
744
805
|
return result;
|
|
745
806
|
} catch (error) {
|
|
746
807
|
const serviceError3 = wrapError(this.getServiceName(), error);
|
|
747
808
|
this.emitResponse(action, false, startTime);
|
|
748
|
-
this.emitError(serviceError3);
|
|
809
|
+
this.emitError(serviceError3, action);
|
|
749
810
|
return err(serviceError3);
|
|
750
811
|
}
|
|
751
812
|
}
|
|
@@ -1670,7 +1731,7 @@ var SQLService = class extends BaseService {
|
|
|
1670
1731
|
try {
|
|
1671
1732
|
const response = await this.invokeSQL(
|
|
1672
1733
|
dbName,
|
|
1673
|
-
SQLAction.READ,
|
|
1734
|
+
this.actionForSql(sql, SQLAction.READ),
|
|
1674
1735
|
{ action: "query", sql, params: params ?? [] },
|
|
1675
1736
|
options?.signal
|
|
1676
1737
|
);
|
|
@@ -1700,7 +1761,7 @@ var SQLService = class extends BaseService {
|
|
|
1700
1761
|
}
|
|
1701
1762
|
const response = await this.invokeSQL(
|
|
1702
1763
|
dbName,
|
|
1703
|
-
SQLAction.WRITE,
|
|
1764
|
+
this.actionForSql(sql, SQLAction.WRITE),
|
|
1704
1765
|
body,
|
|
1705
1766
|
options?.signal
|
|
1706
1767
|
);
|
|
@@ -1722,7 +1783,7 @@ var SQLService = class extends BaseService {
|
|
|
1722
1783
|
try {
|
|
1723
1784
|
const response = await this.invokeSQL(
|
|
1724
1785
|
dbName,
|
|
1725
|
-
|
|
1786
|
+
this.actionForSqlBatch(statements),
|
|
1726
1787
|
{ action: "batch", statements },
|
|
1727
1788
|
options?.signal
|
|
1728
1789
|
);
|
|
@@ -1799,6 +1860,14 @@ var SQLService = class extends BaseService {
|
|
|
1799
1860
|
signal: this.combineSignals(signal)
|
|
1800
1861
|
});
|
|
1801
1862
|
}
|
|
1863
|
+
actionForSql(sql, fallback) {
|
|
1864
|
+
return firstSqlToken(sql) === "pragma" ? SQLAction.ADMIN : fallback;
|
|
1865
|
+
}
|
|
1866
|
+
actionForSqlBatch(statements) {
|
|
1867
|
+
return statements.some(
|
|
1868
|
+
(statement) => this.actionForSql(statement.sql, SQLAction.WRITE) === SQLAction.ADMIN
|
|
1869
|
+
) ? SQLAction.ADMIN : SQLAction.WRITE;
|
|
1870
|
+
}
|
|
1802
1871
|
async handleErrorResponse(response, operation) {
|
|
1803
1872
|
const errorText = await response.text();
|
|
1804
1873
|
let errorBody = {};
|
|
@@ -1844,6 +1913,33 @@ var SQLService = class extends BaseService {
|
|
|
1844
1913
|
}
|
|
1845
1914
|
};
|
|
1846
1915
|
SQLService.serviceName = "sql";
|
|
1916
|
+
function firstSqlToken(sql) {
|
|
1917
|
+
let index = 0;
|
|
1918
|
+
while (index < sql.length) {
|
|
1919
|
+
while (index < sql.length && /\s/.test(sql[index])) {
|
|
1920
|
+
index++;
|
|
1921
|
+
}
|
|
1922
|
+
if (sql.startsWith("--", index)) {
|
|
1923
|
+
const newline = sql.indexOf("\n", index + 2);
|
|
1924
|
+
if (newline === -1) {
|
|
1925
|
+
return void 0;
|
|
1926
|
+
}
|
|
1927
|
+
index = newline + 1;
|
|
1928
|
+
continue;
|
|
1929
|
+
}
|
|
1930
|
+
if (sql.startsWith("/*", index)) {
|
|
1931
|
+
const end = sql.indexOf("*/", index + 2);
|
|
1932
|
+
if (end === -1) {
|
|
1933
|
+
return void 0;
|
|
1934
|
+
}
|
|
1935
|
+
index = end + 2;
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
break;
|
|
1939
|
+
}
|
|
1940
|
+
const match = /^[A-Za-z_]+/.exec(sql.slice(index));
|
|
1941
|
+
return match?.[0].toLowerCase();
|
|
1942
|
+
}
|
|
1847
1943
|
|
|
1848
1944
|
// src/duckdb/DuckDbDatabaseHandle.ts
|
|
1849
1945
|
var DuckDbDatabaseHandle = class {
|
|
@@ -5521,6 +5617,7 @@ export {
|
|
|
5521
5617
|
ServiceRetryEventSchema,
|
|
5522
5618
|
ServiceSessionSchema,
|
|
5523
5619
|
TelemetryEvents,
|
|
5620
|
+
TelemetrySpanEventSchema,
|
|
5524
5621
|
TinyCloudQuota,
|
|
5525
5622
|
VaultHeaders,
|
|
5526
5623
|
VaultPublicSpaceKVActions,
|
|
@@ -5580,6 +5677,7 @@ export {
|
|
|
5580
5677
|
validateServiceRequestEvent,
|
|
5581
5678
|
validateServiceResponseEvent,
|
|
5582
5679
|
validateServiceSession,
|
|
5680
|
+
validateTelemetrySpanEvent,
|
|
5583
5681
|
verifyDecryptResponse,
|
|
5584
5682
|
wrapError
|
|
5585
5683
|
};
|