@blokjs/runner 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Blok.d.ts +19 -0
- package/dist/Blok.js +184 -0
- package/dist/Blok.js.map +1 -0
- package/dist/BlokResponse.d.ts +16 -0
- package/dist/BlokResponse.js +28 -0
- package/dist/BlokResponse.js.map +1 -0
- package/dist/Configuration.d.ts +37 -0
- package/dist/Configuration.js +248 -0
- package/dist/Configuration.js.map +1 -0
- package/dist/ConfigurationResolver.d.ts +7 -0
- package/dist/ConfigurationResolver.js +15 -0
- package/dist/ConfigurationResolver.js.map +1 -0
- package/dist/DefaultLogger.d.ts +65 -0
- package/dist/DefaultLogger.js +101 -0
- package/dist/DefaultLogger.js.map +1 -0
- package/dist/LocalStorage.d.ts +7 -0
- package/dist/LocalStorage.js +56 -0
- package/dist/LocalStorage.js.map +1 -0
- package/dist/MemoryUsage.d.ts +22 -0
- package/dist/MemoryUsage.js +83 -0
- package/dist/MemoryUsage.js.map +1 -0
- package/dist/NodeMap.d.ts +7 -0
- package/dist/NodeMap.js +13 -0
- package/dist/NodeMap.js.map +1 -0
- package/dist/ResolverBase.d.ts +8 -0
- package/dist/ResolverBase.js +18 -0
- package/dist/ResolverBase.js.map +1 -0
- package/dist/Runner.d.ts +25 -0
- package/dist/Runner.js +32 -0
- package/dist/Runner.js.map +1 -0
- package/dist/RunnerNode.d.ts +9 -0
- package/dist/RunnerNode.js +8 -0
- package/dist/RunnerNode.js.map +1 -0
- package/dist/RunnerNodeBase.d.ts +4 -0
- package/dist/RunnerNodeBase.js +3 -0
- package/dist/RunnerNodeBase.js.map +1 -0
- package/dist/RunnerSteps.d.ts +14 -0
- package/dist/RunnerSteps.js +110 -0
- package/dist/RunnerSteps.js.map +1 -0
- package/dist/RuntimeAdapterNode.d.ts +19 -0
- package/dist/RuntimeAdapterNode.js +87 -0
- package/dist/RuntimeAdapterNode.js.map +1 -0
- package/dist/RuntimeRegistry.d.ts +61 -0
- package/dist/RuntimeRegistry.js +87 -0
- package/dist/RuntimeRegistry.js.map +1 -0
- package/dist/TriggerBase.d.ts +119 -0
- package/dist/TriggerBase.js +413 -0
- package/dist/TriggerBase.js.map +1 -0
- package/dist/adapters/BunRuntimeAdapter.d.ts +38 -0
- package/dist/adapters/BunRuntimeAdapter.js +169 -0
- package/dist/adapters/BunRuntimeAdapter.js.map +1 -0
- package/dist/adapters/DockerRuntimeAdapter.d.ts +85 -0
- package/dist/adapters/DockerRuntimeAdapter.js +298 -0
- package/dist/adapters/DockerRuntimeAdapter.js.map +1 -0
- package/dist/adapters/HttpRuntimeAdapter.d.ts +58 -0
- package/dist/adapters/HttpRuntimeAdapter.js +152 -0
- package/dist/adapters/HttpRuntimeAdapter.js.map +1 -0
- package/dist/adapters/NodeJsRuntimeAdapter.d.ts +23 -0
- package/dist/adapters/NodeJsRuntimeAdapter.js +67 -0
- package/dist/adapters/NodeJsRuntimeAdapter.js.map +1 -0
- package/dist/adapters/RuntimeAdapter.d.ts +42 -0
- package/dist/adapters/RuntimeAdapter.js +2 -0
- package/dist/adapters/RuntimeAdapter.js.map +1 -0
- package/dist/adapters/WasmRuntimeAdapter.d.ts +69 -0
- package/dist/adapters/WasmRuntimeAdapter.js +279 -0
- package/dist/adapters/WasmRuntimeAdapter.js.map +1 -0
- package/dist/cache/NodeResultCache.d.ts +286 -0
- package/dist/cache/NodeResultCache.js +499 -0
- package/dist/cache/NodeResultCache.js.map +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cache/index.js +2 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cost/CostEstimator.d.ts +57 -0
- package/dist/cost/CostEstimator.js +171 -0
- package/dist/cost/CostEstimator.js.map +1 -0
- package/dist/cost/index.d.ts +4 -0
- package/dist/cost/index.js +3 -0
- package/dist/cost/index.js.map +1 -0
- package/dist/cost/pricing.d.ts +24 -0
- package/dist/cost/pricing.js +169 -0
- package/dist/cost/pricing.js.map +1 -0
- package/dist/defineNode.d.ts +155 -0
- package/dist/defineNode.js +191 -0
- package/dist/defineNode.js.map +1 -0
- package/dist/graphql/GraphQLSchemaGenerator.d.ts +129 -0
- package/dist/graphql/GraphQLSchemaGenerator.js +425 -0
- package/dist/graphql/GraphQLSchemaGenerator.js.map +1 -0
- package/dist/hmr/FileWatcher.d.ts +62 -0
- package/dist/hmr/FileWatcher.js +185 -0
- package/dist/hmr/FileWatcher.js.map +1 -0
- package/dist/hmr/HmrDevConsole.d.ts +13 -0
- package/dist/hmr/HmrDevConsole.js +46 -0
- package/dist/hmr/HmrDevConsole.js.map +1 -0
- package/dist/hmr/HotReloadManager.d.ts +84 -0
- package/dist/hmr/HotReloadManager.js +195 -0
- package/dist/hmr/HotReloadManager.js.map +1 -0
- package/dist/hmr/index.d.ts +39 -0
- package/dist/hmr/index.js +38 -0
- package/dist/hmr/index.js.map +1 -0
- package/dist/index.d.ts +107 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/APMIntegration.d.ts +141 -0
- package/dist/integrations/APMIntegration.js +212 -0
- package/dist/integrations/APMIntegration.js.map +1 -0
- package/dist/integrations/AzureMonitorIntegration.d.ts +118 -0
- package/dist/integrations/AzureMonitorIntegration.js +254 -0
- package/dist/integrations/AzureMonitorIntegration.js.map +1 -0
- package/dist/integrations/CloudWatchIntegration.d.ts +135 -0
- package/dist/integrations/CloudWatchIntegration.js +293 -0
- package/dist/integrations/CloudWatchIntegration.js.map +1 -0
- package/dist/integrations/SentryIntegration.d.ts +153 -0
- package/dist/integrations/SentryIntegration.js +200 -0
- package/dist/integrations/SentryIntegration.js.map +1 -0
- package/dist/integrations/index.d.ts +19 -0
- package/dist/integrations/index.js +16 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/marketplace/RuntimeAutoScaler.d.ts +148 -0
- package/dist/marketplace/RuntimeAutoScaler.js +366 -0
- package/dist/marketplace/RuntimeAutoScaler.js.map +1 -0
- package/dist/marketplace/RuntimeCatalog.d.ts +174 -0
- package/dist/marketplace/RuntimeCatalog.js +339 -0
- package/dist/marketplace/RuntimeCatalog.js.map +1 -0
- package/dist/marketplace/RuntimeDiscovery.d.ts +86 -0
- package/dist/marketplace/RuntimeDiscovery.js +219 -0
- package/dist/marketplace/RuntimeDiscovery.js.map +1 -0
- package/dist/marketplace/RuntimeHealthMonitor.d.ts +100 -0
- package/dist/marketplace/RuntimeHealthMonitor.js +241 -0
- package/dist/marketplace/RuntimeHealthMonitor.js.map +1 -0
- package/dist/marketplace/RuntimeMetricsDashboard.d.ts +113 -0
- package/dist/marketplace/RuntimeMetricsDashboard.js +293 -0
- package/dist/marketplace/RuntimeMetricsDashboard.js.map +1 -0
- package/dist/monitoring/CircuitBreaker.d.ts +107 -0
- package/dist/monitoring/CircuitBreaker.js +238 -0
- package/dist/monitoring/CircuitBreaker.js.map +1 -0
- package/dist/monitoring/DistributedTracer.d.ts +125 -0
- package/dist/monitoring/DistributedTracer.js +230 -0
- package/dist/monitoring/DistributedTracer.js.map +1 -0
- package/dist/monitoring/HealthCheck.d.ts +54 -0
- package/dist/monitoring/HealthCheck.js +102 -0
- package/dist/monitoring/HealthCheck.js.map +1 -0
- package/dist/monitoring/PerformanceProfiler.d.ts +63 -0
- package/dist/monitoring/PerformanceProfiler.js +229 -0
- package/dist/monitoring/PerformanceProfiler.js.map +1 -0
- package/dist/monitoring/PrometheusBootstrap.d.ts +30 -0
- package/dist/monitoring/PrometheusBootstrap.js +71 -0
- package/dist/monitoring/PrometheusBootstrap.js.map +1 -0
- package/dist/monitoring/PrometheusMetricsBridge.d.ts +60 -0
- package/dist/monitoring/PrometheusMetricsBridge.js +216 -0
- package/dist/monitoring/PrometheusMetricsBridge.js.map +1 -0
- package/dist/monitoring/RateLimiter.d.ts +58 -0
- package/dist/monitoring/RateLimiter.js +128 -0
- package/dist/monitoring/RateLimiter.js.map +1 -0
- package/dist/monitoring/StructuredLogger.d.ts +131 -0
- package/dist/monitoring/StructuredLogger.js +207 -0
- package/dist/monitoring/StructuredLogger.js.map +1 -0
- package/dist/monitoring/TracingBootstrap.d.ts +69 -0
- package/dist/monitoring/TracingBootstrap.js +129 -0
- package/dist/monitoring/TracingBootstrap.js.map +1 -0
- package/dist/monitoring/TriggerMetricsCollector.d.ts +94 -0
- package/dist/monitoring/TriggerMetricsCollector.js +174 -0
- package/dist/monitoring/TriggerMetricsCollector.js.map +1 -0
- package/dist/monitoring/index.d.ts +9 -0
- package/dist/monitoring/index.js +10 -0
- package/dist/monitoring/index.js.map +1 -0
- package/dist/openapi/OpenAPIGenerator.d.ts +192 -0
- package/dist/openapi/OpenAPIGenerator.js +373 -0
- package/dist/openapi/OpenAPIGenerator.js.map +1 -0
- package/dist/openapi/index.d.ts +20 -0
- package/dist/openapi/index.js +20 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/security/ABAC.d.ts +224 -0
- package/dist/security/ABAC.js +380 -0
- package/dist/security/ABAC.js.map +1 -0
- package/dist/security/AuditLogger.d.ts +242 -0
- package/dist/security/AuditLogger.js +317 -0
- package/dist/security/AuditLogger.js.map +1 -0
- package/dist/security/AuthMiddleware.d.ts +163 -0
- package/dist/security/AuthMiddleware.js +274 -0
- package/dist/security/AuthMiddleware.js.map +1 -0
- package/dist/security/EncryptionAtRest.d.ts +206 -0
- package/dist/security/EncryptionAtRest.js +236 -0
- package/dist/security/EncryptionAtRest.js.map +1 -0
- package/dist/security/OAuthProvider.d.ts +334 -0
- package/dist/security/OAuthProvider.js +719 -0
- package/dist/security/OAuthProvider.js.map +1 -0
- package/dist/security/PIIDetector.d.ts +233 -0
- package/dist/security/PIIDetector.js +354 -0
- package/dist/security/PIIDetector.js.map +1 -0
- package/dist/security/RBAC.d.ts +143 -0
- package/dist/security/RBAC.js +285 -0
- package/dist/security/RBAC.js.map +1 -0
- package/dist/security/SecretManager.d.ts +652 -0
- package/dist/security/SecretManager.js +1146 -0
- package/dist/security/SecretManager.js.map +1 -0
- package/dist/security/TLSConfig.d.ts +305 -0
- package/dist/security/TLSConfig.js +550 -0
- package/dist/security/TLSConfig.js.map +1 -0
- package/dist/security/index.d.ts +79 -0
- package/dist/security/index.js +80 -0
- package/dist/security/index.js.map +1 -0
- package/dist/testing/TestHarness.d.ts +189 -0
- package/dist/testing/TestHarness.js +272 -0
- package/dist/testing/TestHarness.js.map +1 -0
- package/dist/testing/TestLogger.d.ts +103 -0
- package/dist/testing/TestLogger.js +153 -0
- package/dist/testing/TestLogger.js.map +1 -0
- package/dist/testing/WorkflowTestRunner.d.ts +172 -0
- package/dist/testing/WorkflowTestRunner.js +355 -0
- package/dist/testing/WorkflowTestRunner.js.map +1 -0
- package/dist/testing/index.d.ts +21 -0
- package/dist/testing/index.js +22 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tracing/InMemoryRunStore.d.ts +44 -0
- package/dist/tracing/InMemoryRunStore.js +341 -0
- package/dist/tracing/InMemoryRunStore.js.map +1 -0
- package/dist/tracing/PostgresRunStore.d.ts +82 -0
- package/dist/tracing/PostgresRunStore.js +640 -0
- package/dist/tracing/PostgresRunStore.js.map +1 -0
- package/dist/tracing/RunStore.d.ts +38 -0
- package/dist/tracing/RunStore.js +2 -0
- package/dist/tracing/RunStore.js.map +1 -0
- package/dist/tracing/RunTracker.d.ts +75 -0
- package/dist/tracing/RunTracker.js +374 -0
- package/dist/tracing/RunTracker.js.map +1 -0
- package/dist/tracing/SqliteRunStore.d.ts +53 -0
- package/dist/tracing/SqliteRunStore.js +703 -0
- package/dist/tracing/SqliteRunStore.js.map +1 -0
- package/dist/tracing/TraceRouter.d.ts +47 -0
- package/dist/tracing/TraceRouter.js +904 -0
- package/dist/tracing/TraceRouter.js.map +1 -0
- package/dist/tracing/TracingLogger.d.ts +21 -0
- package/dist/tracing/TracingLogger.js +62 -0
- package/dist/tracing/TracingLogger.js.map +1 -0
- package/dist/tracing/createStore.d.ts +30 -0
- package/dist/tracing/createStore.js +75 -0
- package/dist/tracing/createStore.js.map +1 -0
- package/dist/tracing/index.d.ts +13 -0
- package/dist/tracing/index.js +9 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/tracing/sanitize.d.ts +7 -0
- package/dist/tracing/sanitize.js +95 -0
- package/dist/tracing/sanitize.js.map +1 -0
- package/dist/tracing/types.d.ts +178 -0
- package/dist/tracing/types.js +3 -0
- package/dist/tracing/types.js.map +1 -0
- package/dist/types/Average.d.ts +11 -0
- package/dist/types/Average.js +2 -0
- package/dist/types/Average.js.map +1 -0
- package/dist/types/Condition.d.ts +8 -0
- package/dist/types/Condition.js +2 -0
- package/dist/types/Condition.js.map +1 -0
- package/dist/types/Conditions.d.ts +5 -0
- package/dist/types/Conditions.js +2 -0
- package/dist/types/Conditions.js.map +1 -0
- package/dist/types/Config.d.ts +12 -0
- package/dist/types/Config.js +2 -0
- package/dist/types/Config.js.map +1 -0
- package/dist/types/Flow.d.ts +5 -0
- package/dist/types/Flow.js +2 -0
- package/dist/types/Flow.js.map +1 -0
- package/dist/types/GlobalOptions.d.ts +11 -0
- package/dist/types/GlobalOptions.js +2 -0
- package/dist/types/GlobalOptions.js.map +1 -0
- package/dist/types/Inputs.d.ts +5 -0
- package/dist/types/Inputs.js +2 -0
- package/dist/types/Inputs.js.map +1 -0
- package/dist/types/JsonLikeObject.d.ts +3 -0
- package/dist/types/JsonLikeObject.js +2 -0
- package/dist/types/JsonLikeObject.js.map +1 -0
- package/dist/types/Mapper.d.ts +5 -0
- package/dist/types/Mapper.js +2 -0
- package/dist/types/Mapper.js.map +1 -0
- package/dist/types/Node.d.ts +10 -0
- package/dist/types/Node.js +2 -0
- package/dist/types/Node.js.map +1 -0
- package/dist/types/ParamsDictionary.d.ts +3 -0
- package/dist/types/ParamsDictionary.js +2 -0
- package/dist/types/ParamsDictionary.js.map +1 -0
- package/dist/types/Properties.d.ts +5 -0
- package/dist/types/Properties.js +2 -0
- package/dist/types/Properties.js.map +1 -0
- package/dist/types/Targets.d.ts +5 -0
- package/dist/types/Targets.js +2 -0
- package/dist/types/Targets.js.map +1 -0
- package/dist/types/Trigger.d.ts +5 -0
- package/dist/types/Trigger.js +2 -0
- package/dist/types/Trigger.js.map +1 -0
- package/dist/types/TriggerHttp.d.ts +7 -0
- package/dist/types/TriggerHttp.js +2 -0
- package/dist/types/TriggerHttp.js.map +1 -0
- package/dist/types/TriggerResponse.d.ts +6 -0
- package/dist/types/TriggerResponse.js +2 -0
- package/dist/types/TriggerResponse.js.map +1 -0
- package/dist/types/Triggers.d.ts +5 -0
- package/dist/types/Triggers.js +2 -0
- package/dist/types/Triggers.js.map +1 -0
- package/dist/types/TryCatch.d.ts +6 -0
- package/dist/types/TryCatch.js +2 -0
- package/dist/types/TryCatch.js.map +1 -0
- package/dist/visualization/NodeDependencyGraph.d.ts +76 -0
- package/dist/visualization/NodeDependencyGraph.js +418 -0
- package/dist/visualization/NodeDependencyGraph.js.map +1 -0
- package/dist/visualization/WorkflowVisualizer.d.ts +144 -0
- package/dist/visualization/WorkflowVisualizer.js +446 -0
- package/dist/visualization/WorkflowVisualizer.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Module for Blok Framework
|
|
3
|
+
*
|
|
4
|
+
* Provides authentication, authorization, audit logging, and secret management:
|
|
5
|
+
* - AuthMiddleware: Pluggable auth with JWT and API Key providers
|
|
6
|
+
* - OAuthOIDCProvider: OAuth 2.0 / OIDC authentication with JWKS verification
|
|
7
|
+
* - RBAC: Role-based access control with hierarchical roles
|
|
8
|
+
* - ABAC: Attribute-based access control with policy engine
|
|
9
|
+
* - AuditLogger: Comprehensive audit trail with multiple sinks
|
|
10
|
+
* - SecretManager: Unified secret management across multiple providers
|
|
11
|
+
* - EncryptionAtRest: AES-256-GCM encryption/decryption with key rotation
|
|
12
|
+
* - PIIDetector: PII detection and masking for text and structured data
|
|
13
|
+
* - TLSConfig: TLS/SSL configuration with mTLS and certificate management
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import {
|
|
18
|
+
* AuthMiddleware,
|
|
19
|
+
* JWTAuthProvider,
|
|
20
|
+
* APIKeyAuthProvider,
|
|
21
|
+
* OAuthOIDCProvider,
|
|
22
|
+
* RBAC,
|
|
23
|
+
* createDefaultRBAC,
|
|
24
|
+
* AuditLogger,
|
|
25
|
+
* ConsoleAuditSink,
|
|
26
|
+
* FileAuditSink,
|
|
27
|
+
* SecretManager,
|
|
28
|
+
* EnvironmentSecretProvider,
|
|
29
|
+
* } from "@blokjs/runner";
|
|
30
|
+
*
|
|
31
|
+
* // Set up auth
|
|
32
|
+
* const auth = new AuthMiddleware({
|
|
33
|
+
* providers: [
|
|
34
|
+
* new OAuthOIDCProvider({
|
|
35
|
+
* issuerUrl: "https://auth.example.com",
|
|
36
|
+
* clientId: "my-app",
|
|
37
|
+
* }),
|
|
38
|
+
* new JWTAuthProvider({ secret: process.env.JWT_SECRET! }),
|
|
39
|
+
* new APIKeyAuthProvider({
|
|
40
|
+
* keys: new Map([["my-key", { name: "svc", roles: ["service"] }]]),
|
|
41
|
+
* }),
|
|
42
|
+
* ],
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Set up RBAC
|
|
46
|
+
* const rbac = createDefaultRBAC();
|
|
47
|
+
*
|
|
48
|
+
* // Set up audit logging
|
|
49
|
+
* const audit = new AuditLogger({
|
|
50
|
+
* sinks: [new ConsoleAuditSink(), new FileAuditSink({ path: "./audit.log" })],
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Set up secret management
|
|
54
|
+
* const secrets = new SecretManager({
|
|
55
|
+
* providers: [
|
|
56
|
+
* { type: "environment", config: { prefix: "BLOK_SECRET_" } },
|
|
57
|
+
* ],
|
|
58
|
+
* cache: { enabled: true, ttlMs: 60_000, maxSize: 100 },
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
// Authentication
|
|
63
|
+
export { AuthMiddleware, JWTAuthProvider, APIKeyAuthProvider, } from "./AuthMiddleware";
|
|
64
|
+
// Authorization (RBAC)
|
|
65
|
+
export { RBAC, createDefaultRBAC } from "./RBAC";
|
|
66
|
+
// Authorization (ABAC)
|
|
67
|
+
export { ABACEngine, createDefaultABAC } from "./ABAC";
|
|
68
|
+
// OAuth 2.0 / OIDC
|
|
69
|
+
export { OAuthOIDCProvider, TokenCache } from "./OAuthProvider";
|
|
70
|
+
// Audit Logging
|
|
71
|
+
export { AuditLogger, ConsoleAuditSink, FileAuditSink, InMemoryAuditSink, } from "./AuditLogger";
|
|
72
|
+
// Secret Management
|
|
73
|
+
export { SecretManager, EnvironmentSecretProvider, InMemorySecretProvider, VaultSecretProvider, AWSSecretsProvider, GCPSecretProvider, } from "./SecretManager";
|
|
74
|
+
// Encryption at Rest
|
|
75
|
+
export { EncryptionAtRest } from "./EncryptionAtRest";
|
|
76
|
+
// PII Detection
|
|
77
|
+
export { PIIDetector, PIIType } from "./PIIDetector";
|
|
78
|
+
// TLS Configuration
|
|
79
|
+
export { TLSConfig } from "./TLSConfig";
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,iBAAiB;AACjB,OAAO,EACN,cAAc,EACd,eAAe,EACf,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAY1B,uBAAuB;AACvB,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AASjD,uBAAuB;AACvB,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAevD,mBAAmB;AACnB,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAShE,gBAAgB;AAChB,OAAO,EACN,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,iBAAiB,GACjB,MAAM,eAAe,CAAC;AASvB,oBAAoB;AACpB,OAAO,EACN,aAAa,EACb,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,iBAAiB,CAAC;AAezB,qBAAqB;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAOtD,gBAAgB;AAChB,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAQrD,oBAAoB;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { Context, ResponseContext } from "@blokjs/shared";
|
|
2
|
+
import type BlokService from "../Blok";
|
|
3
|
+
import type { FunctionNode } from "../defineNode";
|
|
4
|
+
import { TestLogger } from "./TestLogger";
|
|
5
|
+
/**
|
|
6
|
+
* Partial test context overrides that can be supplied to customize
|
|
7
|
+
* the execution environment for a test run.
|
|
8
|
+
*/
|
|
9
|
+
export interface TestContextOverrides {
|
|
10
|
+
/** Override the context ID */
|
|
11
|
+
id?: string;
|
|
12
|
+
/** Override the request context */
|
|
13
|
+
request?: {
|
|
14
|
+
body?: any;
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
query?: Record<string, string>;
|
|
17
|
+
params?: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
/** Override the response context */
|
|
20
|
+
response?: Partial<ResponseContext>;
|
|
21
|
+
/** Override context vars */
|
|
22
|
+
vars?: Record<string, any>;
|
|
23
|
+
/** Override environment variables */
|
|
24
|
+
env?: Record<string, any>;
|
|
25
|
+
/** Override error context */
|
|
26
|
+
error?: {
|
|
27
|
+
message: string[] | string;
|
|
28
|
+
code?: number;
|
|
29
|
+
};
|
|
30
|
+
/** Provide a custom logger (defaults to TestLogger) */
|
|
31
|
+
logger?: TestLogger;
|
|
32
|
+
/** Override workflow name */
|
|
33
|
+
workflow_name?: string;
|
|
34
|
+
/** Override workflow path */
|
|
35
|
+
workflow_path?: string;
|
|
36
|
+
/** Override config context */
|
|
37
|
+
config?: Record<string, any>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Result of a node test execution.
|
|
41
|
+
*/
|
|
42
|
+
export interface TestResult<O> {
|
|
43
|
+
/** Whether the node executed successfully */
|
|
44
|
+
success: boolean;
|
|
45
|
+
/** The output data from the node, or null on failure */
|
|
46
|
+
data: O | null;
|
|
47
|
+
/** Error information if the node failed */
|
|
48
|
+
error: any;
|
|
49
|
+
/** The context after node execution */
|
|
50
|
+
context: Context;
|
|
51
|
+
/** Execution duration in milliseconds */
|
|
52
|
+
durationMs: number;
|
|
53
|
+
/** Log messages captured during execution */
|
|
54
|
+
logs: string[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Aggregated metrics across multiple test executions.
|
|
58
|
+
*/
|
|
59
|
+
export interface TestMetrics {
|
|
60
|
+
/** Total number of executions */
|
|
61
|
+
totalExecutions: number;
|
|
62
|
+
/** Number of successful executions */
|
|
63
|
+
successCount: number;
|
|
64
|
+
/** Number of failed executions */
|
|
65
|
+
failureCount: number;
|
|
66
|
+
/** Average execution duration in milliseconds */
|
|
67
|
+
avgDurationMs: number;
|
|
68
|
+
/** Duration of the most recent execution in milliseconds */
|
|
69
|
+
lastDurationMs: number;
|
|
70
|
+
}
|
|
71
|
+
/** Union type for anything that can be tested as a node */
|
|
72
|
+
type TestableNode = BlokService<any> | FunctionNode<any, any>;
|
|
73
|
+
/**
|
|
74
|
+
* NodeTestHarness - Main testing utility for Blok nodes.
|
|
75
|
+
*
|
|
76
|
+
* Provides a controlled execution environment for unit testing individual
|
|
77
|
+
* nodes without needing a running server, workflow configuration, or
|
|
78
|
+
* OpenTelemetry metrics infrastructure.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { NodeTestHarness } from "@blokjs/runner";
|
|
83
|
+
* import { defineNode } from "@blokjs/runner";
|
|
84
|
+
* import { z } from "zod";
|
|
85
|
+
*
|
|
86
|
+
* const AddNode = defineNode({
|
|
87
|
+
* name: "add",
|
|
88
|
+
* description: "Adds two numbers",
|
|
89
|
+
* input: z.object({ a: z.number(), b: z.number() }),
|
|
90
|
+
* output: z.object({ sum: z.number() }),
|
|
91
|
+
* async execute(ctx, input) {
|
|
92
|
+
* return { sum: input.a + input.b };
|
|
93
|
+
* },
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* const harness = new NodeTestHarness(AddNode);
|
|
97
|
+
* const result = await harness.execute({ a: 2, b: 3 });
|
|
98
|
+
*
|
|
99
|
+
* harness.assertSuccess(result);
|
|
100
|
+
* harness.assertOutput(result, { sum: 5 });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @typeParam I - Input type for the node
|
|
104
|
+
* @typeParam O - Output type for the node
|
|
105
|
+
*/
|
|
106
|
+
export declare class NodeTestHarness<I = any, O = any> {
|
|
107
|
+
private node;
|
|
108
|
+
private executionHistory;
|
|
109
|
+
constructor(node: TestableNode);
|
|
110
|
+
/**
|
|
111
|
+
* Create a test context with sensible defaults that can be overridden.
|
|
112
|
+
*
|
|
113
|
+
* The returned context is fully compatible with the Blok Context interface
|
|
114
|
+
* and uses a TestLogger for log capture.
|
|
115
|
+
*
|
|
116
|
+
* @param overrides - Partial context fields to customize
|
|
117
|
+
* @returns A fully populated Context object ready for testing
|
|
118
|
+
*/
|
|
119
|
+
createContext(overrides?: TestContextOverrides): Context;
|
|
120
|
+
/**
|
|
121
|
+
* Execute the node with given input and optional context overrides.
|
|
122
|
+
*
|
|
123
|
+
* This method directly invokes the node's handle() method, bypassing
|
|
124
|
+
* the BlokService.run() infrastructure (metrics, schema validation via
|
|
125
|
+
* JSON Schema, config mapping). This provides a clean, fast test
|
|
126
|
+
* execution path focused on the node's business logic.
|
|
127
|
+
*
|
|
128
|
+
* @param input - Input data to pass to the node
|
|
129
|
+
* @param contextOverrides - Optional context customizations
|
|
130
|
+
* @returns A TestResult containing success/failure status, data, error, and timing
|
|
131
|
+
*/
|
|
132
|
+
execute(input: I, contextOverrides?: TestContextOverrides): Promise<TestResult<O>>;
|
|
133
|
+
/**
|
|
134
|
+
* Assert that the output of a test result matches the expected partial object.
|
|
135
|
+
*
|
|
136
|
+
* Uses deep equality for each key in the expected object, so you only need
|
|
137
|
+
* to specify the fields you care about.
|
|
138
|
+
*
|
|
139
|
+
* @param result - The test result to check
|
|
140
|
+
* @param expected - A partial object that should be a subset of the output
|
|
141
|
+
* @throws Error if any expected field does not match
|
|
142
|
+
*/
|
|
143
|
+
assertOutput(result: TestResult<O>, expected: Partial<O>): void;
|
|
144
|
+
/**
|
|
145
|
+
* Assert that the node execution was successful.
|
|
146
|
+
*
|
|
147
|
+
* @param result - The test result to check
|
|
148
|
+
* @throws Error if the node failed
|
|
149
|
+
*/
|
|
150
|
+
assertSuccess(result: TestResult<O>): void;
|
|
151
|
+
/**
|
|
152
|
+
* Assert that the node execution failed, optionally matching the error message.
|
|
153
|
+
*
|
|
154
|
+
* @param result - The test result to check
|
|
155
|
+
* @param errorMatch - Optional string or RegExp to match against the error message
|
|
156
|
+
* @throws Error if the node succeeded or the error message does not match
|
|
157
|
+
*/
|
|
158
|
+
assertError(result: TestResult<O>, errorMatch?: string | RegExp): void;
|
|
159
|
+
/**
|
|
160
|
+
* Assert that a context variable was set to the expected value.
|
|
161
|
+
*
|
|
162
|
+
* @param result - The test result to check
|
|
163
|
+
* @param key - The variable name to check in context.vars
|
|
164
|
+
* @param expected - The expected value
|
|
165
|
+
* @throws Error if the variable is not set or does not match
|
|
166
|
+
*/
|
|
167
|
+
assertContextVar(result: TestResult<O>, key: string, expected: any): void;
|
|
168
|
+
/**
|
|
169
|
+
* Get aggregated execution metrics across all test runs.
|
|
170
|
+
*
|
|
171
|
+
* @returns TestMetrics with execution counts and timing data
|
|
172
|
+
*/
|
|
173
|
+
getMetrics(): TestMetrics;
|
|
174
|
+
/**
|
|
175
|
+
* Get the full execution history.
|
|
176
|
+
*
|
|
177
|
+
* @returns Array of all test results from previous executions
|
|
178
|
+
*/
|
|
179
|
+
getHistory(): TestResult<O>[];
|
|
180
|
+
/**
|
|
181
|
+
* Reset the execution history and metrics.
|
|
182
|
+
*/
|
|
183
|
+
reset(): void;
|
|
184
|
+
/**
|
|
185
|
+
* Format an error value into a readable string.
|
|
186
|
+
*/
|
|
187
|
+
private formatError;
|
|
188
|
+
}
|
|
189
|
+
export {};
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { TestLogger } from "./TestLogger";
|
|
2
|
+
/**
|
|
3
|
+
* NodeTestHarness - Main testing utility for Blok nodes.
|
|
4
|
+
*
|
|
5
|
+
* Provides a controlled execution environment for unit testing individual
|
|
6
|
+
* nodes without needing a running server, workflow configuration, or
|
|
7
|
+
* OpenTelemetry metrics infrastructure.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { NodeTestHarness } from "@blokjs/runner";
|
|
12
|
+
* import { defineNode } from "@blokjs/runner";
|
|
13
|
+
* import { z } from "zod";
|
|
14
|
+
*
|
|
15
|
+
* const AddNode = defineNode({
|
|
16
|
+
* name: "add",
|
|
17
|
+
* description: "Adds two numbers",
|
|
18
|
+
* input: z.object({ a: z.number(), b: z.number() }),
|
|
19
|
+
* output: z.object({ sum: z.number() }),
|
|
20
|
+
* async execute(ctx, input) {
|
|
21
|
+
* return { sum: input.a + input.b };
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* const harness = new NodeTestHarness(AddNode);
|
|
26
|
+
* const result = await harness.execute({ a: 2, b: 3 });
|
|
27
|
+
*
|
|
28
|
+
* harness.assertSuccess(result);
|
|
29
|
+
* harness.assertOutput(result, { sum: 5 });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @typeParam I - Input type for the node
|
|
33
|
+
* @typeParam O - Output type for the node
|
|
34
|
+
*/
|
|
35
|
+
export class NodeTestHarness {
|
|
36
|
+
node;
|
|
37
|
+
executionHistory;
|
|
38
|
+
constructor(node) {
|
|
39
|
+
this.node = node;
|
|
40
|
+
this.executionHistory = [];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a test context with sensible defaults that can be overridden.
|
|
44
|
+
*
|
|
45
|
+
* The returned context is fully compatible with the Blok Context interface
|
|
46
|
+
* and uses a TestLogger for log capture.
|
|
47
|
+
*
|
|
48
|
+
* @param overrides - Partial context fields to customize
|
|
49
|
+
* @returns A fully populated Context object ready for testing
|
|
50
|
+
*/
|
|
51
|
+
createContext(overrides) {
|
|
52
|
+
const logger = overrides?.logger ?? new TestLogger();
|
|
53
|
+
const ctx = {
|
|
54
|
+
id: overrides?.id ?? `test-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
55
|
+
workflow_name: overrides?.workflow_name ?? "test-workflow",
|
|
56
|
+
workflow_path: overrides?.workflow_path ?? "/test",
|
|
57
|
+
request: {
|
|
58
|
+
body: overrides?.request?.body ?? {},
|
|
59
|
+
headers: overrides?.request?.headers ?? {},
|
|
60
|
+
query: overrides?.request?.query ?? {},
|
|
61
|
+
params: overrides?.request?.params ?? {},
|
|
62
|
+
},
|
|
63
|
+
response: {
|
|
64
|
+
data: overrides?.response?.data ?? {},
|
|
65
|
+
error: null,
|
|
66
|
+
success: true,
|
|
67
|
+
contentType: overrides?.response?.contentType ?? "application/json",
|
|
68
|
+
},
|
|
69
|
+
error: overrides?.error ?? { message: [] },
|
|
70
|
+
logger: logger,
|
|
71
|
+
config: overrides?.config ?? {},
|
|
72
|
+
vars: overrides?.vars ?? {},
|
|
73
|
+
env: overrides?.env ?? {},
|
|
74
|
+
eventLogger: logger,
|
|
75
|
+
_PRIVATE_: {},
|
|
76
|
+
};
|
|
77
|
+
return ctx;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Execute the node with given input and optional context overrides.
|
|
81
|
+
*
|
|
82
|
+
* This method directly invokes the node's handle() method, bypassing
|
|
83
|
+
* the BlokService.run() infrastructure (metrics, schema validation via
|
|
84
|
+
* JSON Schema, config mapping). This provides a clean, fast test
|
|
85
|
+
* execution path focused on the node's business logic.
|
|
86
|
+
*
|
|
87
|
+
* @param input - Input data to pass to the node
|
|
88
|
+
* @param contextOverrides - Optional context customizations
|
|
89
|
+
* @returns A TestResult containing success/failure status, data, error, and timing
|
|
90
|
+
*/
|
|
91
|
+
async execute(input, contextOverrides) {
|
|
92
|
+
const ctx = this.createContext(contextOverrides);
|
|
93
|
+
const startTime = performance.now();
|
|
94
|
+
let result;
|
|
95
|
+
try {
|
|
96
|
+
const response = (await this.node.handle(ctx, input));
|
|
97
|
+
const endTime = performance.now();
|
|
98
|
+
const logger = ctx.logger;
|
|
99
|
+
if (response.success === false || response.error) {
|
|
100
|
+
result = {
|
|
101
|
+
success: false,
|
|
102
|
+
data: null,
|
|
103
|
+
error: response.error,
|
|
104
|
+
context: ctx,
|
|
105
|
+
durationMs: endTime - startTime,
|
|
106
|
+
logs: logger.getLogs?.() ?? [],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
result = {
|
|
111
|
+
success: true,
|
|
112
|
+
data: response.data,
|
|
113
|
+
error: null,
|
|
114
|
+
context: ctx,
|
|
115
|
+
durationMs: endTime - startTime,
|
|
116
|
+
logs: logger.getLogs?.() ?? [],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
const endTime = performance.now();
|
|
122
|
+
const logger = ctx.logger;
|
|
123
|
+
result = {
|
|
124
|
+
success: false,
|
|
125
|
+
data: null,
|
|
126
|
+
error,
|
|
127
|
+
context: ctx,
|
|
128
|
+
durationMs: endTime - startTime,
|
|
129
|
+
logs: logger.getLogs?.() ?? [],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
this.executionHistory.push(result);
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Assert that the output of a test result matches the expected partial object.
|
|
137
|
+
*
|
|
138
|
+
* Uses deep equality for each key in the expected object, so you only need
|
|
139
|
+
* to specify the fields you care about.
|
|
140
|
+
*
|
|
141
|
+
* @param result - The test result to check
|
|
142
|
+
* @param expected - A partial object that should be a subset of the output
|
|
143
|
+
* @throws Error if any expected field does not match
|
|
144
|
+
*/
|
|
145
|
+
assertOutput(result, expected) {
|
|
146
|
+
if (!result.success) {
|
|
147
|
+
throw new Error(`Cannot assert output: node execution failed with error: ${this.formatError(result.error)}`);
|
|
148
|
+
}
|
|
149
|
+
if (result.data === null) {
|
|
150
|
+
throw new Error("Cannot assert output: result data is null");
|
|
151
|
+
}
|
|
152
|
+
const data = result.data;
|
|
153
|
+
const expectedRecord = expected;
|
|
154
|
+
for (const key of Object.keys(expectedRecord)) {
|
|
155
|
+
const actual = data[key];
|
|
156
|
+
const exp = expectedRecord[key];
|
|
157
|
+
const actualStr = JSON.stringify(actual);
|
|
158
|
+
const expectedStr = JSON.stringify(exp);
|
|
159
|
+
if (actualStr !== expectedStr) {
|
|
160
|
+
throw new Error(`Output mismatch for key "${key}":\n` + ` expected: ${expectedStr}\n` + ` received: ${actualStr}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Assert that the node execution was successful.
|
|
166
|
+
*
|
|
167
|
+
* @param result - The test result to check
|
|
168
|
+
* @throws Error if the node failed
|
|
169
|
+
*/
|
|
170
|
+
assertSuccess(result) {
|
|
171
|
+
if (!result.success) {
|
|
172
|
+
throw new Error(`Expected node to succeed, but it failed with error: ${this.formatError(result.error)}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Assert that the node execution failed, optionally matching the error message.
|
|
177
|
+
*
|
|
178
|
+
* @param result - The test result to check
|
|
179
|
+
* @param errorMatch - Optional string or RegExp to match against the error message
|
|
180
|
+
* @throws Error if the node succeeded or the error message does not match
|
|
181
|
+
*/
|
|
182
|
+
assertError(result, errorMatch) {
|
|
183
|
+
if (result.success) {
|
|
184
|
+
throw new Error(`Expected node to fail, but it succeeded with data: ${JSON.stringify(result.data)}`);
|
|
185
|
+
}
|
|
186
|
+
if (errorMatch !== undefined) {
|
|
187
|
+
const errorMsg = this.formatError(result.error);
|
|
188
|
+
if (typeof errorMatch === "string") {
|
|
189
|
+
if (!errorMsg.includes(errorMatch)) {
|
|
190
|
+
throw new Error(`Expected error to contain "${errorMatch}", but got: "${errorMsg}"`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
if (!errorMatch.test(errorMsg)) {
|
|
195
|
+
throw new Error(`Expected error to match ${errorMatch}, but got: "${errorMsg}"`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Assert that a context variable was set to the expected value.
|
|
202
|
+
*
|
|
203
|
+
* @param result - The test result to check
|
|
204
|
+
* @param key - The variable name to check in context.vars
|
|
205
|
+
* @param expected - The expected value
|
|
206
|
+
* @throws Error if the variable is not set or does not match
|
|
207
|
+
*/
|
|
208
|
+
assertContextVar(result, key, expected) {
|
|
209
|
+
const vars = result.context.vars;
|
|
210
|
+
if (!vars) {
|
|
211
|
+
throw new Error(`Expected context var "${key}" to be set, but context.vars is undefined`);
|
|
212
|
+
}
|
|
213
|
+
const actual = vars[key];
|
|
214
|
+
const actualStr = JSON.stringify(actual);
|
|
215
|
+
const expectedStr = JSON.stringify(expected);
|
|
216
|
+
if (actualStr !== expectedStr) {
|
|
217
|
+
throw new Error(`Context var "${key}" mismatch:\n` + ` expected: ${expectedStr}\n` + ` received: ${actualStr}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Get aggregated execution metrics across all test runs.
|
|
222
|
+
*
|
|
223
|
+
* @returns TestMetrics with execution counts and timing data
|
|
224
|
+
*/
|
|
225
|
+
getMetrics() {
|
|
226
|
+
const total = this.executionHistory.length;
|
|
227
|
+
const successes = this.executionHistory.filter((r) => r.success).length;
|
|
228
|
+
const failures = total - successes;
|
|
229
|
+
const totalDuration = this.executionHistory.reduce((sum, r) => sum + r.durationMs, 0);
|
|
230
|
+
return {
|
|
231
|
+
totalExecutions: total,
|
|
232
|
+
successCount: successes,
|
|
233
|
+
failureCount: failures,
|
|
234
|
+
avgDurationMs: total > 0 ? totalDuration / total : 0,
|
|
235
|
+
lastDurationMs: total > 0 ? this.executionHistory[total - 1].durationMs : 0,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get the full execution history.
|
|
240
|
+
*
|
|
241
|
+
* @returns Array of all test results from previous executions
|
|
242
|
+
*/
|
|
243
|
+
getHistory() {
|
|
244
|
+
return [...this.executionHistory];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Reset the execution history and metrics.
|
|
248
|
+
*/
|
|
249
|
+
reset() {
|
|
250
|
+
this.executionHistory = [];
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Format an error value into a readable string.
|
|
254
|
+
*/
|
|
255
|
+
formatError(error) {
|
|
256
|
+
if (error === null || error === undefined) {
|
|
257
|
+
return "(no error)";
|
|
258
|
+
}
|
|
259
|
+
if (error instanceof Error) {
|
|
260
|
+
return error.message;
|
|
261
|
+
}
|
|
262
|
+
if (typeof error === "object" && "context" in error) {
|
|
263
|
+
// GlobalError format
|
|
264
|
+
return error.context?.message ?? JSON.stringify(error.context);
|
|
265
|
+
}
|
|
266
|
+
if (typeof error === "object") {
|
|
267
|
+
return JSON.stringify(error);
|
|
268
|
+
}
|
|
269
|
+
return String(error);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=TestHarness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestHarness.js","sourceRoot":"","sources":["../../src/testing/Test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,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACpD,cAAc,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;SAC3E,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,UAAU;QACT,OAAO,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,KAAK;QACJ,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,KAAU;QAC7B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC3C,OAAO,YAAY,CAAC;QACrB,CAAC;QACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;YACrD,qBAAqB;YACrB,OAAO,KAAK,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;CACD"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { GlobalLogger } from "@blokjs/shared";
|
|
2
|
+
/**
|
|
3
|
+
* A log entry captured during test execution.
|
|
4
|
+
*/
|
|
5
|
+
export interface LogEntry {
|
|
6
|
+
/** Log level: "info" | "warn" | "error" | "debug" */
|
|
7
|
+
level: string;
|
|
8
|
+
/** The log message */
|
|
9
|
+
message: string;
|
|
10
|
+
/** Timestamp when the log was recorded (ms since epoch) */
|
|
11
|
+
timestamp: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* TestLogger - A logger that captures log output for testing.
|
|
15
|
+
*
|
|
16
|
+
* Extends GlobalLogger to be compatible with the Context.logger interface
|
|
17
|
+
* while storing all log entries in memory for assertion and inspection.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const logger = new TestLogger();
|
|
22
|
+
* logger.info("User created");
|
|
23
|
+
* logger.warn("Rate limit approaching");
|
|
24
|
+
*
|
|
25
|
+
* // Assert specific messages were logged
|
|
26
|
+
* logger.assertLogged("User created", "info");
|
|
27
|
+
* logger.assertLogged(/rate limit/i, "warn");
|
|
28
|
+
*
|
|
29
|
+
* // Inspect all logs
|
|
30
|
+
* const errors = logger.getLogsByLevel("error");
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class TestLogger extends GlobalLogger {
|
|
34
|
+
private entries;
|
|
35
|
+
constructor();
|
|
36
|
+
/**
|
|
37
|
+
* Log an info-level message.
|
|
38
|
+
*/
|
|
39
|
+
info(message: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Log a warning-level message.
|
|
42
|
+
*/
|
|
43
|
+
warn(message: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Log a debug-level message.
|
|
46
|
+
*/
|
|
47
|
+
debug(message: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Implementation of GlobalLogger.log - logs at info level.
|
|
50
|
+
*/
|
|
51
|
+
log(message: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Implementation of GlobalLogger.logLevel.
|
|
54
|
+
*/
|
|
55
|
+
logLevel(level: string, message: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Implementation of GlobalLogger.error.
|
|
58
|
+
*/
|
|
59
|
+
error(message: string, _stack?: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Get all logged entries.
|
|
62
|
+
*/
|
|
63
|
+
getLogs(): string[];
|
|
64
|
+
/**
|
|
65
|
+
* Get all log entries with full metadata.
|
|
66
|
+
*/
|
|
67
|
+
getEntries(): LogEntry[];
|
|
68
|
+
/**
|
|
69
|
+
* Get log entries filtered by level.
|
|
70
|
+
*
|
|
71
|
+
* @param level - The log level to filter by ("info", "warn", "error", "debug")
|
|
72
|
+
* @returns Array of matching log entries
|
|
73
|
+
*/
|
|
74
|
+
getLogsByLevel(level: string): LogEntry[];
|
|
75
|
+
/**
|
|
76
|
+
* Assert that a specific message was logged.
|
|
77
|
+
*
|
|
78
|
+
* @param message - String or RegExp to match against log messages
|
|
79
|
+
* @param level - Optional level to restrict the search to
|
|
80
|
+
* @throws Error if no matching log entry is found
|
|
81
|
+
*/
|
|
82
|
+
assertLogged(message: string | RegExp, level?: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* Assert that a specific message was NOT logged.
|
|
85
|
+
*
|
|
86
|
+
* @param message - String or RegExp to match against log messages
|
|
87
|
+
* @param level - Optional level to restrict the search to
|
|
88
|
+
* @throws Error if a matching log entry is found
|
|
89
|
+
*/
|
|
90
|
+
assertNotLogged(message: string | RegExp, level?: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Clear all captured log entries.
|
|
93
|
+
*/
|
|
94
|
+
clear(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Get the total number of log entries.
|
|
97
|
+
*/
|
|
98
|
+
get count(): number;
|
|
99
|
+
/**
|
|
100
|
+
* Internal helper to add a log entry.
|
|
101
|
+
*/
|
|
102
|
+
private addEntry;
|
|
103
|
+
}
|