@schematichq/schematic-typescript-node 1.4.0 → 1.4.1

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.
@@ -1,6 +1,6 @@
1
- import { EventEmitter } from 'events';
2
1
  import * as Schematic from '../api/types';
3
2
  import { Logger } from '../logger';
3
+ import { LazyEmitter } from './emitter';
4
4
  import type { CacheProvider } from '../cache/types';
5
5
  import { type RedisClient } from '../cache/redis';
6
6
  /**
@@ -36,7 +36,7 @@ export interface DataStreamClientOptions {
36
36
  * DataStreamClient provides a comprehensive client for Schematic's datastream
37
37
  * with caching, flag evaluation, and entity management matching the Go implementation
38
38
  */
39
- export declare class DataStreamClient extends EventEmitter {
39
+ export declare class DataStreamClient extends LazyEmitter {
40
40
  private readonly apiKey;
41
41
  private readonly baseURL?;
42
42
  private readonly logger;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Minimal interface for the subset of EventEmitter we use.
3
+ * Avoids importing the Node.js `events` module at the top level
4
+ * so that edge runtimes (Cloudflare Workers, etc.) can load the
5
+ * module graph without error.
6
+ */
7
+ export interface Emitter {
8
+ on(event: string, listener: (...args: any[]) => void): void;
9
+ emit(event: string, ...args: any[]): boolean;
10
+ removeAllListeners(event?: string): void;
11
+ }
12
+ /**
13
+ * Mixin base class that provides lazy-loaded EventEmitter composition.
14
+ * The Node.js `events` module is only required the first time a listener
15
+ * is registered or an event is emitted, keeping the import out of the
16
+ * module-level dependency graph.
17
+ */
18
+ export declare class LazyEmitter {
19
+ private _emitter;
20
+ private ensureEmitter;
21
+ on(event: string, listener: (...args: any[]) => void): this;
22
+ emit(event: string, ...args: any[]): boolean;
23
+ removeAllListeners(event?: string): this;
24
+ }
@@ -1,6 +1,6 @@
1
- import { EventEmitter } from 'events';
2
1
  import { DataStreamResp, DataStreamBaseReq } from './types';
3
2
  import { Logger } from '../logger';
3
+ import { LazyEmitter } from './emitter';
4
4
  /**
5
5
  * MessageHandlerFunc is a function type for handling incoming datastream messages
6
6
  * Expects parsed DataStreamResp messages
@@ -34,7 +34,7 @@ export interface ClientOptions {
34
34
  /**
35
35
  * DatastreamWSClient represents a Schematic datastream websocket client with automatic reconnection
36
36
  */
37
- export declare class DatastreamWSClient extends EventEmitter {
37
+ export declare class DatastreamWSClient extends LazyEmitter {
38
38
  private readonly url;
39
39
  private readonly headers;
40
40
  private readonly logger;