@loopstack/quota 0.20.7
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/calculators/__tests__/ai-generate-text-quota.calculator.spec.d.ts +2 -0
- package/dist/calculators/__tests__/ai-generate-text-quota.calculator.spec.d.ts.map +1 -0
- package/dist/calculators/__tests__/ai-generate-text-quota.calculator.spec.js +63 -0
- package/dist/calculators/__tests__/ai-generate-text-quota.calculator.spec.js.map +1 -0
- package/dist/calculators/__tests__/processing-time-quota.calculator.spec.d.ts +2 -0
- package/dist/calculators/__tests__/processing-time-quota.calculator.spec.d.ts.map +1 -0
- package/dist/calculators/__tests__/processing-time-quota.calculator.spec.js +52 -0
- package/dist/calculators/__tests__/processing-time-quota.calculator.spec.js.map +1 -0
- package/dist/calculators/ai-generate-text-quota.calculator.d.ts +8 -0
- package/dist/calculators/ai-generate-text-quota.calculator.d.ts.map +1 -0
- package/dist/calculators/ai-generate-text-quota.calculator.js +17 -0
- package/dist/calculators/ai-generate-text-quota.calculator.js.map +1 -0
- package/dist/calculators/index.d.ts +3 -0
- package/dist/calculators/index.d.ts.map +1 -0
- package/dist/calculators/index.js +19 -0
- package/dist/calculators/index.js.map +1 -0
- package/dist/calculators/processing-time-quota.calculator.d.ts +8 -0
- package/dist/calculators/processing-time-quota.calculator.d.ts.map +1 -0
- package/dist/calculators/processing-time-quota.calculator.js +14 -0
- package/dist/calculators/processing-time-quota.calculator.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +4 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +20 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/quota-client.interface.d.ts +11 -0
- package/dist/interfaces/quota-client.interface.d.ts.map +1 -0
- package/dist/interfaces/quota-client.interface.js +5 -0
- package/dist/interfaces/quota-client.interface.js.map +1 -0
- package/dist/interfaces/quota.interface.d.ts +5 -0
- package/dist/interfaces/quota.interface.d.ts.map +1 -0
- package/dist/interfaces/quota.interface.js +3 -0
- package/dist/interfaces/quota.interface.js.map +1 -0
- package/dist/interfaces/tool-quota-calculator.interface.d.ts +7 -0
- package/dist/interfaces/tool-quota-calculator.interface.d.ts.map +1 -0
- package/dist/interfaces/tool-quota-calculator.interface.js +3 -0
- package/dist/interfaces/tool-quota-calculator.interface.js.map +1 -0
- package/dist/quota.module.d.ts +16 -0
- package/dist/quota.module.d.ts.map +1 -0
- package/dist/quota.module.js +88 -0
- package/dist/quota.module.js.map +1 -0
- package/dist/services/__tests__/quota-calculator-registry.service.spec.d.ts +2 -0
- package/dist/services/__tests__/quota-calculator-registry.service.spec.d.ts.map +1 -0
- package/dist/services/__tests__/quota-calculator-registry.service.spec.js +45 -0
- package/dist/services/__tests__/quota-calculator-registry.service.spec.js.map +1 -0
- package/dist/services/__tests__/quota-client.service.spec.d.ts +2 -0
- package/dist/services/__tests__/quota-client.service.spec.d.ts.map +1 -0
- package/dist/services/__tests__/quota-client.service.spec.js +83 -0
- package/dist/services/__tests__/quota-client.service.spec.js.map +1 -0
- package/dist/services/__tests__/quota.interceptor.spec.d.ts +2 -0
- package/dist/services/__tests__/quota.interceptor.spec.d.ts.map +1 -0
- package/dist/services/__tests__/quota.interceptor.spec.js +117 -0
- package/dist/services/__tests__/quota.interceptor.spec.js.map +1 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +20 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/quota-calculator-registry.service.d.ts +9 -0
- package/dist/services/quota-calculator-registry.service.d.ts.map +1 -0
- package/dist/services/quota-calculator-registry.service.js +33 -0
- package/dist/services/quota-calculator-registry.service.js.map +1 -0
- package/dist/services/quota-client.service.d.ts +12 -0
- package/dist/services/quota-client.service.d.ts.map +1 -0
- package/dist/services/quota-client.service.js +74 -0
- package/dist/services/quota-client.service.js.map +1 -0
- package/dist/services/quota.interceptor.d.ts +14 -0
- package/dist/services/quota.interceptor.d.ts.map +1 -0
- package/dist/services/quota.interceptor.js +66 -0
- package/dist/services/quota.interceptor.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-generate-text-quota.calculator.spec.d.ts","sourceRoot":"","sources":["../../../src/calculators/__tests__/ai-generate-text-quota.calculator.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ai_generate_text_quota_calculator_1 = require("../ai-generate-text-quota.calculator");
|
|
4
|
+
describe('AiGenerateTextQuotaCalculator', () => {
|
|
5
|
+
let calculator;
|
|
6
|
+
const context = {
|
|
7
|
+
tool: {},
|
|
8
|
+
args: undefined,
|
|
9
|
+
runContext: { userId: 'user-1' },
|
|
10
|
+
};
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
calculator = new ai_generate_text_quota_calculator_1.AiGenerateTextQuotaCalculator();
|
|
13
|
+
});
|
|
14
|
+
it('should have quotaType "default-token"', () => {
|
|
15
|
+
expect(calculator.quotaType).toBe('default-token');
|
|
16
|
+
});
|
|
17
|
+
it('should calculate total tokens from usage metadata', () => {
|
|
18
|
+
const result = {
|
|
19
|
+
data: {},
|
|
20
|
+
metadata: { usage: { inputTokens: 100, outputTokens: 50 } },
|
|
21
|
+
};
|
|
22
|
+
expect(calculator.calculateQuotaUsage(context, result)).toEqual({
|
|
23
|
+
quotaType: 'default-token',
|
|
24
|
+
actualAmount: 150,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('should return null when metadata is missing', () => {
|
|
28
|
+
const result = { data: {} };
|
|
29
|
+
expect(calculator.calculateQuotaUsage(context, result)).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
it('should return null when usage is missing from metadata', () => {
|
|
32
|
+
const result = { data: {}, metadata: {} };
|
|
33
|
+
expect(calculator.calculateQuotaUsage(context, result)).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
it('should return null when both token counts are zero', () => {
|
|
36
|
+
const result = {
|
|
37
|
+
data: {},
|
|
38
|
+
metadata: { usage: { inputTokens: 0, outputTokens: 0 } },
|
|
39
|
+
};
|
|
40
|
+
expect(calculator.calculateQuotaUsage(context, result)).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
it('should handle missing inputTokens', () => {
|
|
43
|
+
const result = {
|
|
44
|
+
data: {},
|
|
45
|
+
metadata: { usage: { outputTokens: 200 } },
|
|
46
|
+
};
|
|
47
|
+
expect(calculator.calculateQuotaUsage(context, result)).toEqual({
|
|
48
|
+
quotaType: 'default-token',
|
|
49
|
+
actualAmount: 200,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it('should handle missing outputTokens', () => {
|
|
53
|
+
const result = {
|
|
54
|
+
data: {},
|
|
55
|
+
metadata: { usage: { inputTokens: 300 } },
|
|
56
|
+
};
|
|
57
|
+
expect(calculator.calculateQuotaUsage(context, result)).toEqual({
|
|
58
|
+
quotaType: 'default-token',
|
|
59
|
+
actualAmount: 300,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=ai-generate-text-quota.calculator.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-generate-text-quota.calculator.spec.js","sourceRoot":"","sources":["../../../src/calculators/__tests__/ai-generate-text-quota.calculator.spec.ts"],"names":[],"mappings":";;AACA,4FAAqF;AAErF,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,IAAI,UAAyC,CAAC;IAC9C,MAAM,OAAO,GAAyB;QACpC,IAAI,EAAE,EAAE;QACR,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAgB;KAC/C,CAAC;IAEF,UAAU,CAAC,GAAG,EAAE;Q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,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE;SACzD,CAAC;QAEF,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACrE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,MAAM,GAAe;YACzB,IAAI,EAAE,EAAE;YACR,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE;SAC3C,CAAC;QAEF,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9D,SAAS,EAAE,eAAe;YAC1B,YAAY,EAAE,GAAG;SAClB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,MAAM,GAAe;YACzB,IAAI,EAAE,EAAE;YACR,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE;SAC1C,CAAC;QAEF,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9D,SAAS,EAAE,eAAe;YAC1B,YAAY,EAAE,GAAG;SAClB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processing-time-quota.calculator.spec.d.ts","sourceRoot":"","sources":["../../../src/calculators/__tests__/processing-time-quota.calculator.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const processing_time_quota_calculator_1 = require("../processing-time-quota.calculator");
|
|
4
|
+
describe('ProcessingTimeQuotaCalculator', () => {
|
|
5
|
+
let calculator;
|
|
6
|
+
const result = { data: {} };
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
calculator = new processing_time_quota_calculator_1.ProcessingTimeQuotaCalculator();
|
|
9
|
+
});
|
|
10
|
+
it('should have quotaType "processing-time-ms"', () => {
|
|
11
|
+
expect(calculator.quotaType).toBe('processing-time-ms');
|
|
12
|
+
});
|
|
13
|
+
it('should return duration from context metrics', () => {
|
|
14
|
+
const context = {
|
|
15
|
+
tool: {},
|
|
16
|
+
args: undefined,
|
|
17
|
+
runContext: { userId: 'user-1' },
|
|
18
|
+
metrics: { durationMs: 1500 },
|
|
19
|
+
};
|
|
20
|
+
expect(calculator.calculateQuotaUsage(context, result)).toEqual({
|
|
21
|
+
quotaType: 'processing-time-ms',
|
|
22
|
+
actualAmount: 1500,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it('should return null when metrics is undefined', () => {
|
|
26
|
+
const context = {
|
|
27
|
+
tool: {},
|
|
28
|
+
args: undefined,
|
|
29
|
+
runContext: { userId: 'user-1' },
|
|
30
|
+
};
|
|
31
|
+
expect(calculator.calculateQuotaUsage(context, result)).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
it('should return null when durationMs is undefined', () => {
|
|
34
|
+
const context = {
|
|
35
|
+
tool: {},
|
|
36
|
+
args: undefined,
|
|
37
|
+
runContext: { userId: 'user-1' },
|
|
38
|
+
metrics: {},
|
|
39
|
+
};
|
|
40
|
+
expect(calculator.calculateQuotaUsage(context, result)).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
it('should return null when durationMs is zero', () => {
|
|
43
|
+
const context = {
|
|
44
|
+
tool: {},
|
|
45
|
+
args: undefined,
|
|
46
|
+
runContext: { userId: 'user-1' },
|
|
47
|
+
metrics: { durationMs: 0 },
|
|
48
|
+
};
|
|
49
|
+
expect(calculator.calculateQuotaUsage(context, result)).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=processing-time-quota.calculator.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processing-time-quota.calculator.spec.js","sourceRoot":"","sources":["../../../src/calculators/__tests__/processing-time-quota.calculator.spec.ts"],"names":[],"mappings":";;AACA,0FAAoF;AAEpF,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,IAAI,UAAyC,CAAC;IAC9C,MAAM,MAAM,GAAe,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAExC,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG,IAAI,gEAA6B,EAAE,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,OAAO,GAAyB;YACpC,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAgB;YAC9C,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;SAC9B,CAAC;QAEF,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9D,SAAS,EAAE,oBAAoB;YAC/B,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,OAAO,GAAyB;YACpC,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAgB;SAC/C,CAAC;QAEF,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACrE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,OAAO,GAAyB;YACpC,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAgB;YAC9C,OAAO,EAAE,EAAE;SACZ,CAAC;QAEF,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACrE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,OAAO,GAAyB;YACpC,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAgB;YAC9C,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE;SAC3B,CAAC;QAEF,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACrE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ToolExecutionContext, ToolResult } from '@loopstack/common';
|
|
2
|
+
import { QuotaUsage } from '../interfaces/quota.interface';
|
|
3
|
+
import { ToolQuotaCalculator } from '../interfaces/tool-quota-calculator.interface';
|
|
4
|
+
export declare class AiGenerateTextQuotaCalculator implements ToolQuotaCalculator {
|
|
5
|
+
quotaType: string;
|
|
6
|
+
calculateQuotaUsage(_context: ToolExecutionContext, result: ToolResult): QuotaUsage | null;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=ai-generate-text-quota.calculator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-generate-text-quota.calculator.d.ts","sourceRoot":"","sources":["../../src/calculators/ai-generate-text-quota.calculator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAEpF,qBAAa,6BAA8B,YAAW,mBAAmB;IACvE,SAAS,SAAmB;IAE5B,mBAAmB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI;CAS3F"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AiGenerateTextQuotaCalculator = void 0;
|
|
4
|
+
class AiGenerateTextQuotaCalculator {
|
|
5
|
+
quotaType = 'default-token';
|
|
6
|
+
calculateQuotaUsage(_context, result) {
|
|
7
|
+
const usage = result.metadata?.usage;
|
|
8
|
+
if (!usage)
|
|
9
|
+
return null;
|
|
10
|
+
const totalTokens = (usage.inputTokens ?? 0) + (usage.outputTokens ?? 0);
|
|
11
|
+
if (totalTokens === 0)
|
|
12
|
+
return null;
|
|
13
|
+
return { quotaType: this.quotaType, actualAmount: totalTokens };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.AiGenerateTextQuotaCalculator = AiGenerateTextQuotaCalculator;
|
|
17
|
+
//# sourceMappingURL=ai-generate-text-quota.calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-generate-text-quota.calculator.js","sourceRoot":"","sources":["../../src/calculators/ai-generate-text-quota.calculator.ts"],"names":[],"mappings":";;;AAIA,MAAa,6BAA6B;IACxC,SAAS,GAAG,eAAe,CAAC;IAE5B,mBAAmB,CAAC,QAA8B,EAAE,MAAkB;QACpE,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,KAAoE,CAAC;QACpG,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,CAAC,CAAC;QACzE,IAAI,WAAW,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAEnC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC;IAClE,CAAC;CACF;AAZD,sEAYC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/calculators/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ai-generate-text-quota.calculator"), exports);
|
|
18
|
+
__exportStar(require("./processing-time-quota.calculator"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/calculators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,qEAAmD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ToolExecutionContext, ToolResult } from '@loopstack/common';
|
|
2
|
+
import { QuotaUsage } from '../interfaces/quota.interface';
|
|
3
|
+
import { ToolQuotaCalculator } from '../interfaces/tool-quota-calculator.interface';
|
|
4
|
+
export declare class ProcessingTimeQuotaCalculator implements ToolQuotaCalculator {
|
|
5
|
+
quotaType: string;
|
|
6
|
+
calculateQuotaUsage(context: ToolExecutionContext, _result: ToolResult): QuotaUsage | null;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=processing-time-quota.calculator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processing-time-quota.calculator.d.ts","sourceRoot":"","sources":["../../src/calculators/processing-time-quota.calculator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAEpF,qBAAa,6BAA8B,YAAW,mBAAmB;IACvE,SAAS,SAAwB;IAEjC,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI;CAK3F"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProcessingTimeQuotaCalculator = void 0;
|
|
4
|
+
class ProcessingTimeQuotaCalculator {
|
|
5
|
+
quotaType = 'processing-time-ms';
|
|
6
|
+
calculateQuotaUsage(context, _result) {
|
|
7
|
+
const durationMs = context.metrics?.durationMs;
|
|
8
|
+
if (typeof durationMs !== 'number' || durationMs === 0)
|
|
9
|
+
return null;
|
|
10
|
+
return { quotaType: this.quotaType, actualAmount: durationMs };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ProcessingTimeQuotaCalculator = ProcessingTimeQuotaCalculator;
|
|
14
|
+
//# sourceMappingURL=processing-time-quota.calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processing-time-quota.calculator.js","sourceRoot":"","sources":["../../src/calculators/processing-time-quota.calculator.ts"],"names":[],"mappings":";;;AAIA,MAAa,6BAA6B;IACxC,SAAS,GAAG,oBAAoB,CAAC;IAEjC,mBAAmB,CAAC,OAA6B,EAAE,OAAmB;QACpE,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC;QAC/C,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACpE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;IACjE,CAAC;CACF;AARD,sEAQC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./calculators"), exports);
|
|
18
|
+
__exportStar(require("./interfaces"), exports);
|
|
19
|
+
__exportStar(require("./services"), exports);
|
|
20
|
+
__exportStar(require("./quota.module"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,+CAA6B;AAC7B,6CAA2B;AAC3B,iDAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./quota-client.interface"), exports);
|
|
18
|
+
__exportStar(require("./quota.interface"), exports);
|
|
19
|
+
__exportStar(require("./tool-quota-calculator.interface"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,oDAAkC;AAClC,oEAAkD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type QuotaCheckResult = {
|
|
2
|
+
exceeded: boolean;
|
|
3
|
+
used: number;
|
|
4
|
+
limit: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const QUOTA_CLIENT_SERVICE = "QUOTA_CLIENT_SERVICE";
|
|
7
|
+
export interface QuotaClientServiceInterface {
|
|
8
|
+
checkQuota(userId: string, quotaType: string): Promise<QuotaCheckResult>;
|
|
9
|
+
report(userId: string, quotaType: string, amount: number): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=quota-client.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota-client.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/quota-client.interface.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAE3D,MAAM,WAAW,2BAA2B;IAC1C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACzE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota-client.interface.js","sourceRoot":"","sources":["../../src/interfaces/quota-client.interface.ts"],"names":[],"mappings":";;;AAMa,QAAA,oBAAoB,GAAG,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/quota.interface.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota.interface.js","sourceRoot":"","sources":["../../src/interfaces/quota.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ToolExecutionContext, ToolResult } from '@loopstack/common';
|
|
2
|
+
import { QuotaUsage } from './quota.interface';
|
|
3
|
+
export interface ToolQuotaCalculator {
|
|
4
|
+
quotaType: string;
|
|
5
|
+
calculateQuotaUsage(context: ToolExecutionContext, result: ToolResult): QuotaUsage | null;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=tool-quota-calculator.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-quota-calculator.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/tool-quota-calculator.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,WAAW,mBAAmB;IAIlC,SAAS,EAAE,MAAM,CAAC;IAMlB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAAC;CAC3F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-quota-calculator.interface.js","sourceRoot":"","sources":["../../src/interfaces/tool-quota-calculator.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DynamicModule, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { QuotaCalculatorRegistry } from './services';
|
|
3
|
+
export interface QuotaModuleOptions {
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
redisHost?: string;
|
|
6
|
+
redisPort?: number;
|
|
7
|
+
redisPassword?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class QuotaModule implements OnModuleInit {
|
|
10
|
+
private readonly calculatorRegistry;
|
|
11
|
+
constructor(calculatorRegistry: QuotaCalculatorRegistry);
|
|
12
|
+
onModuleInit(): void;
|
|
13
|
+
static forRoot(options?: QuotaModuleOptions): DynamicModule;
|
|
14
|
+
static forRootAsync(): DynamicModule;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=quota.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota.module.d.ts","sourceRoot":"","sources":["../src/quota.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAKrE,OAAO,EAAe,uBAAuB,EAAwC,MAAM,YAAY,CAAC;AAExG,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBACa,WAAY,YAAW,YAAY;IAClC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;gBAAlB,kBAAkB,EAAE,uBAAuB;IAExE,YAAY;IAOZ,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,aAAa;IA2C3D,MAAM,CAAC,YAAY,IAAI,aAAa;CAQrC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
var QuotaModule_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.QuotaModule = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const ioredis_1 = __importDefault(require("ioredis"));
|
|
19
|
+
const common_2 = require("@loopstack/common");
|
|
20
|
+
const calculators_1 = require("./calculators");
|
|
21
|
+
const interfaces_1 = require("./interfaces");
|
|
22
|
+
const services_1 = require("./services");
|
|
23
|
+
let QuotaModule = QuotaModule_1 = class QuotaModule {
|
|
24
|
+
calculatorRegistry;
|
|
25
|
+
constructor(calculatorRegistry) {
|
|
26
|
+
this.calculatorRegistry = calculatorRegistry;
|
|
27
|
+
}
|
|
28
|
+
onModuleInit() {
|
|
29
|
+
const aiTokenCalculator = new calculators_1.AiGenerateTextQuotaCalculator();
|
|
30
|
+
this.calculatorRegistry.register('AiGenerateText', aiTokenCalculator);
|
|
31
|
+
this.calculatorRegistry.register('AiGenerateObject', aiTokenCalculator);
|
|
32
|
+
this.calculatorRegistry.register('AiGenerateDocument', aiTokenCalculator);
|
|
33
|
+
}
|
|
34
|
+
static forRoot(options) {
|
|
35
|
+
const enabled = options?.enabled ?? false;
|
|
36
|
+
const redisProvider = {
|
|
37
|
+
provide: services_1.QUOTA_REDIS,
|
|
38
|
+
useFactory: () => {
|
|
39
|
+
if (!enabled) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return new ioredis_1.default({
|
|
43
|
+
host: options?.redisHost ?? 'localhost',
|
|
44
|
+
port: options?.redisPort ?? 6379,
|
|
45
|
+
password: options?.redisPassword,
|
|
46
|
+
family: 0,
|
|
47
|
+
maxRetriesPerRequest: 3,
|
|
48
|
+
retryStrategy(times) {
|
|
49
|
+
return Math.min(times * 200, 2000);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
module: QuotaModule_1,
|
|
56
|
+
global: true,
|
|
57
|
+
providers: [
|
|
58
|
+
redisProvider,
|
|
59
|
+
services_1.QuotaClientService,
|
|
60
|
+
{
|
|
61
|
+
provide: interfaces_1.QUOTA_CLIENT_SERVICE,
|
|
62
|
+
useExisting: services_1.QuotaClientService,
|
|
63
|
+
},
|
|
64
|
+
services_1.QuotaCalculatorRegistry,
|
|
65
|
+
services_1.QuotaInterceptor,
|
|
66
|
+
{
|
|
67
|
+
provide: common_2.TOOL_EXECUTION_INTERCEPTORS,
|
|
68
|
+
useExisting: services_1.QuotaInterceptor,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
exports: [interfaces_1.QUOTA_CLIENT_SERVICE, services_1.QuotaClientService, services_1.QuotaCalculatorRegistry, common_2.TOOL_EXECUTION_INTERCEPTORS],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
static forRootAsync() {
|
|
75
|
+
return QuotaModule_1.forRoot({
|
|
76
|
+
enabled: process.env.QUOTA_ENABLED === 'true',
|
|
77
|
+
redisHost: process.env.QUOTA_REDIS_HOST ?? process.env.REDIS_HOST,
|
|
78
|
+
redisPort: parseInt(process.env.QUOTA_REDIS_PORT ?? process.env.REDIS_PORT ?? '6379', 10),
|
|
79
|
+
redisPassword: process.env.QUOTA_REDIS_PASSWORD ?? process.env.REDIS_PASSWORD,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.QuotaModule = QuotaModule;
|
|
84
|
+
exports.QuotaModule = QuotaModule = QuotaModule_1 = __decorate([
|
|
85
|
+
(0, common_1.Module)({}),
|
|
86
|
+
__metadata("design:paramtypes", [services_1.QuotaCalculatorRegistry])
|
|
87
|
+
], QuotaModule);
|
|
88
|
+
//# sourceMappingURL=quota.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota.module.js","sourceRoot":"","sources":["../src/quota.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAqE;AACrE,sDAA4B;AAC5B,8CAAgE;AAChE,+CAA8D;AAC9D,6CAAoD;AACpD,yCAAwG;AAUjG,IAAM,WAAW,mBAAjB,MAAM,WAAW;IACO;IAA7B,YAA6B,kBAA2C;QAA3C,uBAAkB,GAAlB,kBAAkB,CAAyB;IAAG,CAAC;IAE5E,YAAY;QACV,MAAM,iBAAiB,GAAG,IAAI,2CAA6B,EAAE,CAAC;QAC9D,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;QACtE,IAAI,CAAC,k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,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,MAAM;YAC7C,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU;YACjE,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,MAAM,EAAE,EAAE,CAAC;YACzF,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc;SAC9E,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA7DY,kCAAW;sBAAX,WAAW;IADvB,IAAA,eAAM,EAAC,EAAE,CAAC;qCAEwC,kCAAuB;GAD7D,WAAW,CA6DvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota-calculator-registry.service.spec.d.ts","sourceRoot":"","sources":["../../../src/services/__tests__/quota-calculator-registry.service.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const quota_calculator_registry_service_1 = require("../quota-calculator-registry.service");
|
|
4
|
+
class MockCalculator {
|
|
5
|
+
quotaType = 'test-type';
|
|
6
|
+
calculateQuotaUsage(_context, _result) {
|
|
7
|
+
return { quotaType: this.quotaType, actualAmount: 42 };
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
describe('QuotaCalculatorRegistry', () => {
|
|
11
|
+
let registry;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
registry = new quota_calculator_registry_service_1.QuotaCalculatorRegistry();
|
|
14
|
+
});
|
|
15
|
+
it('should register and retrieve a calculator', () => {
|
|
16
|
+
const calculator = new MockCalculator();
|
|
17
|
+
registry.register('TestTool', calculator);
|
|
18
|
+
expect(registry.get('TestTool')).toBe(calculator);
|
|
19
|
+
});
|
|
20
|
+
it('should return undefined for unregistered tools', () => {
|
|
21
|
+
expect(registry.get('UnknownTool')).toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
it('should report has correctly', () => {
|
|
24
|
+
const calculator = new MockCalculator();
|
|
25
|
+
registry.register('TestTool', calculator);
|
|
26
|
+
expect(registry.has('TestTool')).toBe(true);
|
|
27
|
+
expect(registry.has('UnknownTool')).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
it('should override a previously registered calculator', () => {
|
|
30
|
+
const calculator1 = new MockCalculator();
|
|
31
|
+
const calculator2 = new MockCalculator();
|
|
32
|
+
calculator2.quotaType = 'overridden-type';
|
|
33
|
+
registry.register('TestTool', calculator1);
|
|
34
|
+
registry.register('TestTool', calculator2);
|
|
35
|
+
expect(registry.get('TestTool')).toBe(calculator2);
|
|
36
|
+
});
|
|
37
|
+
it('should allow registering the same calculator for multiple tools', () => {
|
|
38
|
+
const calculator = new MockCalculator();
|
|
39
|
+
registry.register('ToolA', calculator);
|
|
40
|
+
registry.register('ToolB', calculator);
|
|
41
|
+
expect(registry.get('ToolA')).toBe(calculator);
|
|
42
|
+
expect(registry.get('ToolB')).toBe(calculator);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=quota-calculator-registry.service.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota-calculator-registry.service.spec.js","sourceRoot":"","sources":["../../../src/services/__tests__/quota-calculator-registry.service.spec.ts"],"names":[],"mappings":";;AAEA,4FAA+E;AAE/E,MAAM,cAAc;IAClB,SAAS,GAAG,WAAW,CAAC;IACxB,mBAAmB,CAAC,QAA8B,EAAE,OAAmB;QACrE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IACzD,CAAC;CACF;AAED,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,IAAI,QAAiC,CAAC;IAEtC,UAAU,CAAC,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