@ductape/sdk 0.0.4-v55 → 0.0.4-v56
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/brokers/brokers.service.d.ts +24 -0
- package/dist/brokers/brokers.service.js +72 -0
- package/dist/brokers/brokers.service.js.map +1 -1
- package/dist/graph/graphs.service.d.ts +1 -1
- package/dist/graph/graphs.service.js +1 -1
- package/dist/graph/graphs.service.js.map +1 -1
- package/dist/index.d.ts +542 -58
- package/dist/index.js +773 -97
- package/dist/index.js.map +1 -1
- package/dist/resilience/fallback.service.d.ts +60 -11
- package/dist/resilience/fallback.service.js +278 -23
- package/dist/resilience/fallback.service.js.map +1 -1
- package/dist/resilience/healthcheck.service.d.ts +48 -0
- package/dist/resilience/healthcheck.service.js +556 -1
- package/dist/resilience/healthcheck.service.js.map +1 -1
- package/dist/resilience/quota.service.d.ts +42 -53
- package/dist/resilience/quota.service.js +364 -369
- package/dist/resilience/quota.service.js.map +1 -1
- package/dist/resilience/resilience.service.js +38 -3
- package/dist/resilience/resilience.service.js.map +1 -1
- package/dist/resilience/types/index.d.ts +35 -1
- package/dist/resilience/types/index.js +3 -0
- package/dist/resilience/types/index.js.map +1 -1
- package/dist/storage/storage.service.d.ts +25 -0
- package/dist/storage/storage.service.js +39 -0
- package/dist/storage/storage.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
* Quota Service
|
|
3
3
|
*
|
|
4
4
|
* Code-first API for defining and managing quotas with weighted distribution.
|
|
5
|
+
* Uses ProductBuilder for CRUD operations and ProcessorService for execution.
|
|
6
|
+
* Implements health-aware weighted selection with minimal latency.
|
|
5
7
|
*/
|
|
6
8
|
import { IQuotaDefineOptions, IQuotaSchema, IQuotaRunOptions, IQuotaDispatchOptions, IDefinedQuota, IResilienceServiceConfig } from './types';
|
|
9
|
+
import { IProductQuota } from '../types/productsBuilder.types';
|
|
7
10
|
/**
|
|
8
11
|
* Error class for quota operations
|
|
9
12
|
*/
|
|
@@ -13,75 +16,61 @@ export declare class QuotaError extends Error {
|
|
|
13
16
|
constructor(message: string, code: string, details?: unknown);
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* Provides code-first API for defining, creating, and managing quotas.
|
|
19
|
+
* Result of a quota run with provider information
|
|
19
20
|
*/
|
|
21
|
+
export interface IQuotaRunResult<T = unknown> {
|
|
22
|
+
data: T;
|
|
23
|
+
provider: string;
|
|
24
|
+
latency: number;
|
|
25
|
+
wasHealthy: boolean;
|
|
26
|
+
retriesUsed: number;
|
|
27
|
+
}
|
|
20
28
|
export declare class QuotaService {
|
|
21
|
-
private
|
|
29
|
+
private config;
|
|
30
|
+
private productBuilders;
|
|
31
|
+
private processorCache;
|
|
22
32
|
constructor(config: IResilienceServiceConfig);
|
|
23
33
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* const quota = await quotaService.define({
|
|
29
|
-
* product: 'my-product',
|
|
30
|
-
* tag: 'sms-quota',
|
|
31
|
-
* name: 'SMS Provider Quota',
|
|
32
|
-
* input: {
|
|
33
|
-
* phone: { type: 'string', required: true },
|
|
34
|
-
* message: { type: 'string', required: true },
|
|
35
|
-
* },
|
|
36
|
-
* handler: async (ctx) => {
|
|
37
|
-
* ctx.provider('twilio')
|
|
38
|
-
* .weight(70)
|
|
39
|
-
* .healthcheck('twilio-health')
|
|
40
|
-
* .app('twilio-app')
|
|
41
|
-
* .action('send-sms')
|
|
42
|
-
* .mapInput((input) => ({ body: { to: input.phone, body: input.message } }))
|
|
43
|
-
* .mapOutput((res) => ({ messageId: res.sid }))
|
|
44
|
-
* .retries(2);
|
|
45
|
-
*
|
|
46
|
-
* ctx.provider('nexmo')
|
|
47
|
-
* .weight(30)
|
|
48
|
-
* .healthcheck('nexmo-health')
|
|
49
|
-
* .app('nexmo-app')
|
|
50
|
-
* .action('send-sms')
|
|
51
|
-
* .mapInput((input) => ({ body: { to: input.phone, text: input.message } }))
|
|
52
|
-
* .mapOutput((res) => ({ messageId: res['message-id'] }))
|
|
53
|
-
* .retries(2);
|
|
54
|
-
* },
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
34
|
+
* Gets or creates a cached ProductBuilder
|
|
57
35
|
*/
|
|
58
|
-
|
|
36
|
+
private getProductBuilder;
|
|
59
37
|
/**
|
|
60
|
-
*
|
|
38
|
+
* Gets or creates a cached ProcessorService for minimal latency
|
|
61
39
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
40
|
+
private getProcessor;
|
|
41
|
+
define<TInput = Record<string, unknown>>(options: IQuotaDefineOptions<TInput>): Promise<IDefinedQuota>;
|
|
42
|
+
create(product: string, quota: IDefinedQuota | IQuotaSchema): Promise<IProductQuota>;
|
|
43
|
+
fetch(product: string, tag: string): Promise<IProductQuota | null>;
|
|
44
|
+
fetchAll(product: string): Promise<IProductQuota[]>;
|
|
45
|
+
update(product: string, tag: string, data: Partial<IProductQuota>): Promise<void>;
|
|
46
|
+
delete(product: string, tag: string): Promise<void>;
|
|
67
47
|
/**
|
|
68
|
-
*
|
|
48
|
+
* Run a quota with health-aware weighted provider selection
|
|
49
|
+
*
|
|
50
|
+
* Optimization strategies:
|
|
51
|
+
* 1. Parallel health status lookups from Redis (O(1) per provider)
|
|
52
|
+
* 2. Cached processor instances to avoid re-initialization
|
|
53
|
+
* 3. Pre-computed weighted selection for O(n) provider selection
|
|
54
|
+
* 4. Exponential backoff only on failures
|
|
69
55
|
*/
|
|
70
|
-
|
|
56
|
+
run<TOutput = unknown>(options: IQuotaRunOptions): Promise<IQuotaRunResult<TOutput>>;
|
|
71
57
|
/**
|
|
72
|
-
*
|
|
58
|
+
* Parallel health status lookup from Redis - O(n) with parallel I/O
|
|
73
59
|
*/
|
|
74
|
-
|
|
60
|
+
private getHealthStatusesParallel;
|
|
75
61
|
/**
|
|
76
|
-
*
|
|
62
|
+
* Fast weighted selection with health-aware prioritization
|
|
77
63
|
*/
|
|
78
|
-
|
|
64
|
+
private selectHealthyProvider;
|
|
79
65
|
/**
|
|
80
|
-
*
|
|
66
|
+
* Execute provider action with exponential backoff retries
|
|
81
67
|
*/
|
|
82
|
-
|
|
68
|
+
private executeWithRetries;
|
|
83
69
|
/**
|
|
84
|
-
* Dispatch
|
|
70
|
+
* Dispatch quota for deferred execution via job queue
|
|
71
|
+
*
|
|
72
|
+
* Note: For immediate execution, use run() instead.
|
|
73
|
+
* Dispatch schedules the quota for background processing.
|
|
85
74
|
*/
|
|
86
75
|
dispatch(options: IQuotaDispatchOptions): Promise<{
|
|
87
76
|
jobId: string;
|