@goatlab/node-backend 1.2.0 → 1.3.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.
@@ -43,11 +43,6 @@ export declare class LazyRedisStore {
43
43
  * if multiple operations are called simultaneously.
44
44
  */
45
45
  getStore(): Promise<KeyvRedis>;
46
- /**
47
- * Get the store synchronously if already connected.
48
- * Returns undefined if not yet connected.
49
- */
50
- private getStoreSync;
51
46
  get(key: string): Promise<any>;
52
47
  getMany(keys: string[]): Promise<any[]>;
53
48
  set(key: string, value: any, ttl?: number): Promise<any>;
@@ -88,13 +88,6 @@ class LazyRedisStore {
88
88
  });
89
89
  return this._connecting;
90
90
  }
91
- /**
92
- * Get the store synchronously if already connected.
93
- * Returns undefined if not yet connected.
94
- */
95
- getStoreSync() {
96
- return this._store;
97
- }
98
91
  // Keyv store interface methods - all lazily connect
99
92
  async get(key) {
100
93
  const store = await this.getStore();
@@ -1 +1 @@
1
- {"version":3,"file":"LazyRedisStore.js","sourceRoot":"","sources":["../../src/cache/LazyRedisStore.ts"],"names":[],"mappings":";;;AACA,+DAA2D;AAE3D;;;;;;;;;;;;;GAaG;AACH,MAAa,cAAc;IACjB,gBAAgB,CAAQ;IACxB,IAAI,CAAqB;IACzB,MAAM,CAAuB;IAC7B,WAAW,CAAgC;IAC3C,UAAU,CAAoB;IAEtC;;;;;OAKG;IACa,IAAI,CAAkC;IAEtD,YAAY,gBAAwB;QAClC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,yCAAmB,CAAC,WAAW,EAAE,CAAA;QAE7C,uCAAuC;QACvC,+EAA+E;QAC/E,mDAAmD;QACnD,IAAI,CAAC,IAAI,GAAG;YACV,OAAO,EAAE,OAAO;YAChB,GAAG,EAAE,gBAAgB;SACtB,CAAA;QAED,4DAA4D;QAC5D,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,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,CAAC,CAAA;QAClC,OAAO,KAAK,KAAK,SAAS,CAAA;IAC5B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,CAAC,QAAQ,CAAC,SAAkB;QAChC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAA;QACnC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACnB,KAAK,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAkC,CAAA;QACnE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAA;IAClC,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,OAAO,IAAI,CAAC,gBAAgB,CAAA;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;YACjD,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;YACvB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;QAC9B,CAAC;IACH,CAAC;CACF;AA1KD,wCA0KC"}
@@ -86,6 +86,22 @@ export declare class Container<Defs extends Record<string, unknown>, TenantMetad
86
86
  * Lazy-allocated to save memory for unused services
87
87
  */
88
88
  private readonly managers;
89
+ /**
90
+ * Kill switch: Set of blocked tenant IDs
91
+ * Blocked tenants are rejected immediately at bootstrap without initialization
92
+ */
93
+ private readonly blockedTenants;
94
+ /**
95
+ * Cooldown tracker: tenants whose initializer recently failed
96
+ * Maps tenant cache key -> expiry timestamp (Date.now() + cooldown)
97
+ * Prevents retry storms when a tenant's initializer is broken
98
+ */
99
+ private readonly initializerCooldowns;
100
+ /**
101
+ * Bootstrap call counter for sampled heap checks
102
+ * Only check memory every N calls to minimize overhead
103
+ */
104
+ private bootstrapCounter;
89
105
  /**
90
106
  * AsyncLocalStorage provides automatic tenant context isolation
91
107
  * Each async call tree gets its own isolated service instances
@@ -110,6 +126,12 @@ export declare class Container<Defs extends Record<string, unknown>, TenantMetad
110
126
  * Prevents concurrent bootstrap for same tenant from running initializer twice
111
127
  */
112
128
  private readonly initializerPromises;
129
+ /**
130
+ * Tracks in-flight disposal operations per tenant
131
+ * Bootstrap waits for pending disposal to complete before re-initializing
132
+ * Prevents duplicate live instances when invalidation overlaps with re-bootstrap
133
+ */
134
+ private readonly disposalPromises;
113
135
  /**
114
136
  * Proxy object cache: reuses proxy objects for the same paths
115
137
  * Reduces memory allocation and improves performance
@@ -123,16 +145,9 @@ export declare class Container<Defs extends Record<string, unknown>, TenantMetad
123
145
  /**
124
146
  * Initializer cache: stores initialized instances per tenant with LRU eviction
125
147
  * Avoids re-running the expensive initializer function for the same tenant
126
- * Key is a serialized version of tenant metadata, value is the initialized instances
127
- * Uses accessOrder to track LRU for eviction when cache exceeds maxInitializerCacheSize
148
+ * Uses tiny-lru for O(1) eviction instead of hand-rolled linear scan
128
149
  */
129
150
  private readonly initializerCache;
130
- /**
131
- * Tracks access order for LRU eviction of initializerCache entries
132
- * Key is cache key, value is access timestamp (incrementing counter)
133
- */
134
- private readonly initializerAccessOrder;
135
- private initializerAccessCounter;
136
151
  /**
137
152
  * High-performance metrics using Uint32Array for better JIT optimization
138
153
  * Indices: [hits, misses, creates, ctx, proxy, initHits, resets, batchOps, batchErrors]
@@ -153,6 +168,11 @@ export declare class Container<Defs extends Record<string, unknown>, TenantMetad
153
168
  * Uint32Array automatically wraps at 2^32, but we maintain compatibility for tests
154
169
  */
155
170
  private inc;
171
+ /**
172
+ * Emit a structured event if an event handler is configured
173
+ * No-op if onEvent is not set, keeping zero overhead when unused
174
+ */
175
+ private emit;
156
176
  /**
157
177
  * Create a new Container instance
158
178
  *
@@ -257,11 +277,6 @@ export declare class Container<Defs extends Record<string, unknown>, TenantMetad
257
277
  * Uses common tenant properties or hashed JSON as fallback
258
278
  */
259
279
  private createTenantCacheKey;
260
- /**
261
- * Evict the least recently used entry from initializerCache if at capacity
262
- * Called before adding a new entry when cache is at maxInitializerCacheSize
263
- */
264
- private evictLruFromInitializerCache;
265
280
  /**
266
281
  * Get or create initialized instances for a tenant with race condition protection
267
282
  * Uses both result caching and inflight promise deduplication
@@ -554,4 +569,21 @@ export declare class Container<Defs extends Record<string, unknown>, TenantMetad
554
569
  * Helper method for getAvailableServices()
555
570
  */
556
571
  private collectServices;
572
+ /**
573
+ * Block a tenant from bootstrapping. Blocked tenants are rejected immediately.
574
+ * Use this for: runaway crons, infinite loops, compromised keys, legal holds.
575
+ */
576
+ blockTenant(tenantId: string): void;
577
+ /**
578
+ * Unblock a previously blocked tenant, restoring normal bootstrap behavior.
579
+ */
580
+ unblockTenant(tenantId: string): void;
581
+ /**
582
+ * Check if a tenant is currently blocked.
583
+ */
584
+ isTenantBlocked(tenantId: string): boolean;
585
+ /**
586
+ * Get the set of all currently blocked tenant IDs.
587
+ */
588
+ getBlockedTenants(): ReadonlySet<string>;
557
589
  }