@celerity-sdk/types 0.3.0 → 0.4.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/README.md CHANGED
@@ -20,6 +20,9 @@ pnpm add @celerity-sdk/types
20
20
  | **Modules** | `ModuleMetadata`, `FunctionHandlerDefinition` |
21
21
  | **Validation** | `Schema` |
22
22
  | **Telemetry** | `LogLevel`, `CelerityLogger`, `CelerityTracer`, `CeleritySpan` |
23
+ | **WebSocket** | `WebSocketRequest`, `WebSocketResponse`, `WebSocketHandlerContext` |
24
+ | **Consumer** | `ConsumerMessage`, `ConsumerHandlerContext`, `ConsumerResult` |
25
+ | **Schedule** | `ScheduleEvent`, `ScheduleHandlerContext` |
23
26
 
24
27
  ## Conventions
25
28
 
package/dist/index.cjs CHANGED
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -15,5 +19,39 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
15
19
 
16
20
  // src/index.ts
17
21
  var index_exports = {};
22
+ __export(index_exports, {
23
+ BucketEventType: () => BucketEventType,
24
+ DatastoreEventType: () => DatastoreEventType,
25
+ SourceType: () => SourceType,
26
+ WebSocketSender: () => WebSocketSender
27
+ });
18
28
  module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/websocket.ts
31
+ var WebSocketSender = /* @__PURE__ */ Symbol.for("celerity:websocket-sender");
32
+
33
+ // src/consumer.ts
34
+ var SourceType = {
35
+ Bucket: "bucket",
36
+ Datastore: "datastore",
37
+ Queue: "queue",
38
+ Topic: "topic"
39
+ };
40
+ var BucketEventType = {
41
+ Created: "created",
42
+ Deleted: "deleted",
43
+ MetadataUpdated: "metadataUpdated"
44
+ };
45
+ var DatastoreEventType = {
46
+ Inserted: "inserted",
47
+ Modified: "modified",
48
+ Removed: "removed"
49
+ };
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ BucketEventType,
53
+ DatastoreEventType,
54
+ SourceType,
55
+ WebSocketSender
56
+ });
19
57
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type {\n Type,\n InjectionToken,\n Closeable,\n ClassProvider,\n FactoryProvider,\n ValueProvider,\n Provider,\n} from \"./common\";\n\nexport type {\n HttpMethod,\n HttpRequest,\n HttpResponse,\n HandlerMetadata,\n HandlerContext,\n} from \"./http\";\n\nexport type { ServiceContainer } from \"./container\";\n\nexport type { HandlerResponse, NextFunction, CelerityLayer } from \"./layer\";\n\nexport type { Schema } from \"./validation\";\n\nexport type { FunctionHandlerDefinition, ModuleMetadata } from \"./module\";\n\nexport type { LogLevel, CelerityLogger, CelerityTracer, CeleritySpan } from \"./telemetry\";\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA;;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/websocket.ts","../src/consumer.ts"],"sourcesContent":["export type {\n Type,\n InjectionToken,\n Closeable,\n ClassProvider,\n FactoryProvider,\n ValueProvider,\n Provider,\n} from \"./common\";\n\nexport type { HandlerType, BaseHandlerContext } from \"./handler\";\n\nexport type {\n HttpMethod,\n HttpRequest,\n HttpResponse,\n HandlerMetadata,\n HttpHandlerContext,\n GuardHandlerRequest,\n GuardHandlerContext,\n} from \"./http\";\n\nexport type { ServiceContainer } from \"./container\";\n\nexport type { HandlerResponse, NextFunction, CelerityLayer } from \"./layer\";\n\nexport type { Schema } from \"./validation\";\n\nexport type { FunctionHandlerDefinition, GuardDefinition, ModuleMetadata } from \"./module\";\n\nexport type { LogLevel, CelerityLogger, CelerityTracer, CeleritySpan } from \"./telemetry\";\n\nexport type {\n WebSocketEventType,\n WebSocketMessageType,\n WebSocketMessage,\n WebSocketRequestContext,\n WebSocketHandlerContext,\n WebSocketSendOptions,\n} from \"./websocket\";\n\n// WebSocketSender is both a type (interface) and a value (DI token symbol).\n// The regular export allows both to be re-exported.\nexport { WebSocketSender } from \"./websocket\";\n\nexport type {\n MessageAttributeValue,\n MessageAttributes,\n ConsumerMessage,\n ConsumerEventInput,\n ConsumerHandlerContext,\n MessageProcessingFailure,\n EventResult,\n ValidatedConsumerMessage,\n BucketEvent,\n DatastoreEvent,\n} from \"./consumer\";\n\nexport { SourceType, BucketEventType, DatastoreEventType } from \"./consumer\";\n\nexport type { ScheduleEventInput, ScheduleHandlerContext } from \"./schedule\";\n","import type { BaseHandlerContext } from \"./handler\";\n\nexport type WebSocketEventType = \"connect\" | \"message\" | \"disconnect\";\nexport type WebSocketMessageType = \"json\" | \"binary\";\n\n/** SDK representation of a WebSocket message from the runtime. */\nexport type WebSocketMessage = {\n messageType: WebSocketMessageType;\n eventType: WebSocketEventType;\n connectionId: string;\n messageId: string;\n jsonBody?: unknown;\n binaryBody?: Buffer;\n requestContext?: WebSocketRequestContext;\n traceContext?: Record<string, string> | null;\n};\n\n/** HTTP context from the original WebSocket upgrade request. */\nexport type WebSocketRequestContext = {\n requestId: string;\n requestTime: number;\n path: string;\n protocolVersion: string;\n headers: Record<string, string | string[]>;\n userAgent?: string;\n clientIp: string;\n query: Record<string, string | string[]>;\n cookies: Record<string, string>;\n auth?: Record<string, unknown>;\n traceContext?: Record<string, string>;\n};\n\n/** Context for WebSocket handlers. */\nexport type WebSocketHandlerContext = BaseHandlerContext & {\n message: WebSocketMessage;\n};\n\nexport type WebSocketSendOptions = {\n messageId?: string;\n messageType?: \"json\" | \"binary\";\n};\n\n/** Platform-agnostic abstraction for sending WebSocket messages. */\nexport interface WebSocketSender {\n /** Send a message to a specific WebSocket connection. */\n sendMessage(connectionId: string, data: unknown, options?: WebSocketSendOptions): Promise<void>;\n}\n\n/**\n * DI token for WebSocketSender.\n * TypeScript uses the interface in type position and the symbol in value position.\n */\nexport const WebSocketSender: unique symbol = Symbol.for(\"celerity:websocket-sender\");\n","import type { BaseHandlerContext } from \"./handler\";\n\n/**\n * A single attribute value in the SQS-compatible format used by all consumers.\n * `stringValue` is optional because binary-typed attributes may omit it.\n */\nexport type MessageAttributeValue = {\n dataType: string;\n stringValue?: string;\n binaryValue?: string;\n};\n\n/** Key-value map of message attributes attached to a consumer message. */\nexport type MessageAttributes = Record<string, MessageAttributeValue>;\n\n/** A single message from an event source. */\nexport type ConsumerMessage = {\n messageId: string;\n body: string;\n source: string;\n sourceType?: string;\n sourceName?: string;\n eventType?: string;\n messageAttributes: MessageAttributes;\n vendor: unknown;\n};\n\n/** Consumer source types corresponding to Celerity resource kinds. */\nexport const SourceType = {\n Bucket: \"bucket\",\n Datastore: \"datastore\",\n Queue: \"queue\",\n Topic: \"topic\",\n} as const;\nexport type SourceType = (typeof SourceType)[keyof typeof SourceType];\n\n/** Celerity-standard bucket event types (mapped from cloud-specific names). */\nexport const BucketEventType = {\n Created: \"created\",\n Deleted: \"deleted\",\n MetadataUpdated: \"metadataUpdated\",\n} as const;\nexport type BucketEventType = (typeof BucketEventType)[keyof typeof BucketEventType];\n\n/** Celerity-standard datastore event types (mapped from cloud-specific names). */\nexport const DatastoreEventType = {\n Inserted: \"inserted\",\n Modified: \"modified\",\n Removed: \"removed\",\n} as const;\nexport type DatastoreEventType = (typeof DatastoreEventType)[keyof typeof DatastoreEventType];\n\n/** Celerity-standard bucket event body shape. */\nexport type BucketEvent = {\n key: string;\n size?: number;\n eTag?: string;\n};\n\n/** Celerity-standard datastore event body shape. */\nexport type DatastoreEvent = {\n keys: Record<string, unknown>;\n newItem?: Record<string, unknown>;\n oldItem?: Record<string, unknown>;\n};\n\n/** Input provided to a consumer handler — a batch of messages. */\nexport type ConsumerEventInput = {\n handlerTag: string;\n messages: ConsumerMessage[];\n vendor: unknown;\n traceContext?: Record<string, string> | null;\n};\n\n/** Context for consumer event handlers. */\nexport type ConsumerHandlerContext = BaseHandlerContext & {\n event: ConsumerEventInput;\n};\n\n/** Individual message processing failure for partial failure reporting. */\nexport type MessageProcessingFailure = {\n messageId: string;\n errorMessage?: string;\n};\n\n/** Result returned from consumer and schedule handlers. */\nexport type EventResult = {\n success: boolean;\n failures?: MessageProcessingFailure[];\n errorMessage?: string;\n};\n\n/**\n * A consumer message with a schema-validated parsed body.\n * Returned by @Messages(schema) and createConsumerHandler({ messageSchema }).\n * Retains all original ConsumerMessage fields so the handler can\n * correlate parsed bodies with message metadata (messageId, source, etc.).\n */\nexport type ValidatedConsumerMessage<T> = ConsumerMessage & {\n parsedBody: T;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyCA;;;;;;;;;;ACWO,IAAMA,kBAAiCC,uBAAOC,IAAI,2BAAA;;;ACxBlD,IAAMC,aAAa;EACxBC,QAAQ;EACRC,WAAW;EACXC,OAAO;EACPC,OAAO;AACT;AAIO,IAAMC,kBAAkB;EAC7BC,SAAS;EACTC,SAAS;EACTC,iBAAiB;AACnB;AAIO,IAAMC,qBAAqB;EAChCC,UAAU;EACVC,UAAU;EACVC,SAAS;AACX;","names":["WebSocketSender","Symbol","for","SourceType","Bucket","Datastore","Queue","Topic","BucketEventType","Created","Deleted","MetadataUpdated","DatastoreEventType","Inserted","Modified","Removed"]}
package/dist/index.d.cts CHANGED
@@ -84,18 +84,51 @@ interface HandlerMetadata {
84
84
  /** Check if key exists (either scope). */
85
85
  has(key: string): boolean;
86
86
  }
87
- type HandlerContext = {
87
+ type HttpHandlerContext = BaseHandlerContext & {
88
88
  request: HttpRequest;
89
+ };
90
+ /** Request data available to guard handlers from the runtime. */
91
+ type GuardHandlerRequest = {
92
+ method: string;
93
+ path: string;
94
+ headers: Record<string, string | string[]>;
95
+ query: Record<string, string | string[]>;
96
+ cookies: Record<string, string>;
97
+ body: unknown;
98
+ requestId: string;
99
+ clientIp: string;
100
+ };
101
+ /** Context passed to guard `check()` methods. */
102
+ type GuardHandlerContext = {
103
+ /** Auth token extracted by the runtime (using the configured token source and auth scheme). */
104
+ token: string;
105
+ /** Accumulated auth from preceding guards, keyed by guard name. */
106
+ auth: Record<string, unknown>;
107
+ /** Request data available from the runtime. */
108
+ request: GuardHandlerRequest;
109
+ /** Handler metadata from decorators (e.g. `@Action`). */
89
110
  metadata: HandlerMetadata;
111
+ /** DI container for resolving services. */
90
112
  container: ServiceContainer;
91
- /** Request-scoped logger set by TelemetryLayer. Enriched with requestId, method, path. */
113
+ /** Request-scoped logger, when available. */
92
114
  logger?: CelerityLogger;
93
115
  };
94
116
 
95
- type HandlerResponse = HttpResponse;
96
- type NextFunction = () => Promise<HandlerResponse>;
97
- interface CelerityLayer<TContext extends HandlerContext = HandlerContext> {
98
- handle(context: TContext, next: NextFunction): Promise<HandlerResponse>;
117
+ type HandlerType = "http" | "websocket" | "consumer" | "schedule" | "custom";
118
+ /** Shared fields present in every handler context. */
119
+ type BaseHandlerContext = {
120
+ metadata: HandlerMetadata;
121
+ container: ServiceContainer;
122
+ /** Request-scoped logger set by TelemetryLayer. */
123
+ logger?: CelerityLogger;
124
+ };
125
+
126
+ type HandlerResponse = unknown;
127
+ type NextFunction = () => Promise<unknown>;
128
+ interface CelerityLayer<TContext extends BaseHandlerContext = HttpHandlerContext> {
129
+ /** When defined, the layer only executes for the returned handler types. Omit to run for all types. */
130
+ supports?(handlerType: HandlerType): boolean;
131
+ handle(context: TContext, next: NextFunction): Promise<unknown>;
99
132
  dispose?(): Promise<void> | void;
100
133
  }
101
134
 
@@ -106,13 +139,20 @@ interface Schema<T = unknown> {
106
139
  type FunctionHandlerDefinition = {
107
140
  __celerity_handler: true;
108
141
  id?: string;
109
- type: "http" | "consumer" | "schedule" | "websocket";
142
+ type: "http" | "consumer" | "schedule" | "websocket" | "workflow" | "custom";
110
143
  metadata: Record<string, unknown>;
111
144
  handler: (...args: unknown[]) => unknown;
112
145
  };
146
+ type GuardDefinition = {
147
+ __celerity_guard: true;
148
+ name?: string;
149
+ handler: (...args: unknown[]) => unknown;
150
+ metadata?: Record<string, unknown>;
151
+ };
113
152
  type ModuleMetadata = {
114
153
  controllers?: Type[];
115
154
  functionHandlers?: FunctionHandlerDefinition[];
155
+ guards?: (Type | GuardDefinition)[];
116
156
  providers?: (Type | (Provider & {
117
157
  provide: InjectionToken;
118
158
  }))[];
@@ -120,4 +160,153 @@ type ModuleMetadata = {
120
160
  exports?: InjectionToken[];
121
161
  };
122
162
 
123
- export type { CelerityLayer, CelerityLogger, CeleritySpan, CelerityTracer, ClassProvider, Closeable, FactoryProvider, FunctionHandlerDefinition, HandlerContext, HandlerMetadata, HandlerResponse, HttpMethod, HttpRequest, HttpResponse, InjectionToken, LogLevel, ModuleMetadata, NextFunction, Provider, Schema, ServiceContainer, Type, ValueProvider };
163
+ type WebSocketEventType = "connect" | "message" | "disconnect";
164
+ type WebSocketMessageType = "json" | "binary";
165
+ /** SDK representation of a WebSocket message from the runtime. */
166
+ type WebSocketMessage = {
167
+ messageType: WebSocketMessageType;
168
+ eventType: WebSocketEventType;
169
+ connectionId: string;
170
+ messageId: string;
171
+ jsonBody?: unknown;
172
+ binaryBody?: Buffer;
173
+ requestContext?: WebSocketRequestContext;
174
+ traceContext?: Record<string, string> | null;
175
+ };
176
+ /** HTTP context from the original WebSocket upgrade request. */
177
+ type WebSocketRequestContext = {
178
+ requestId: string;
179
+ requestTime: number;
180
+ path: string;
181
+ protocolVersion: string;
182
+ headers: Record<string, string | string[]>;
183
+ userAgent?: string;
184
+ clientIp: string;
185
+ query: Record<string, string | string[]>;
186
+ cookies: Record<string, string>;
187
+ auth?: Record<string, unknown>;
188
+ traceContext?: Record<string, string>;
189
+ };
190
+ /** Context for WebSocket handlers. */
191
+ type WebSocketHandlerContext = BaseHandlerContext & {
192
+ message: WebSocketMessage;
193
+ };
194
+ type WebSocketSendOptions = {
195
+ messageId?: string;
196
+ messageType?: "json" | "binary";
197
+ };
198
+ /** Platform-agnostic abstraction for sending WebSocket messages. */
199
+ interface WebSocketSender {
200
+ /** Send a message to a specific WebSocket connection. */
201
+ sendMessage(connectionId: string, data: unknown, options?: WebSocketSendOptions): Promise<void>;
202
+ }
203
+ /**
204
+ * DI token for WebSocketSender.
205
+ * TypeScript uses the interface in type position and the symbol in value position.
206
+ */
207
+ declare const WebSocketSender: unique symbol;
208
+
209
+ /**
210
+ * A single attribute value in the SQS-compatible format used by all consumers.
211
+ * `stringValue` is optional because binary-typed attributes may omit it.
212
+ */
213
+ type MessageAttributeValue = {
214
+ dataType: string;
215
+ stringValue?: string;
216
+ binaryValue?: string;
217
+ };
218
+ /** Key-value map of message attributes attached to a consumer message. */
219
+ type MessageAttributes = Record<string, MessageAttributeValue>;
220
+ /** A single message from an event source. */
221
+ type ConsumerMessage = {
222
+ messageId: string;
223
+ body: string;
224
+ source: string;
225
+ sourceType?: string;
226
+ sourceName?: string;
227
+ eventType?: string;
228
+ messageAttributes: MessageAttributes;
229
+ vendor: unknown;
230
+ };
231
+ /** Consumer source types corresponding to Celerity resource kinds. */
232
+ declare const SourceType: {
233
+ readonly Bucket: "bucket";
234
+ readonly Datastore: "datastore";
235
+ readonly Queue: "queue";
236
+ readonly Topic: "topic";
237
+ };
238
+ type SourceType = (typeof SourceType)[keyof typeof SourceType];
239
+ /** Celerity-standard bucket event types (mapped from cloud-specific names). */
240
+ declare const BucketEventType: {
241
+ readonly Created: "created";
242
+ readonly Deleted: "deleted";
243
+ readonly MetadataUpdated: "metadataUpdated";
244
+ };
245
+ type BucketEventType = (typeof BucketEventType)[keyof typeof BucketEventType];
246
+ /** Celerity-standard datastore event types (mapped from cloud-specific names). */
247
+ declare const DatastoreEventType: {
248
+ readonly Inserted: "inserted";
249
+ readonly Modified: "modified";
250
+ readonly Removed: "removed";
251
+ };
252
+ type DatastoreEventType = (typeof DatastoreEventType)[keyof typeof DatastoreEventType];
253
+ /** Celerity-standard bucket event body shape. */
254
+ type BucketEvent = {
255
+ key: string;
256
+ size?: number;
257
+ eTag?: string;
258
+ };
259
+ /** Celerity-standard datastore event body shape. */
260
+ type DatastoreEvent = {
261
+ keys: Record<string, unknown>;
262
+ newItem?: Record<string, unknown>;
263
+ oldItem?: Record<string, unknown>;
264
+ };
265
+ /** Input provided to a consumer handler — a batch of messages. */
266
+ type ConsumerEventInput = {
267
+ handlerTag: string;
268
+ messages: ConsumerMessage[];
269
+ vendor: unknown;
270
+ traceContext?: Record<string, string> | null;
271
+ };
272
+ /** Context for consumer event handlers. */
273
+ type ConsumerHandlerContext = BaseHandlerContext & {
274
+ event: ConsumerEventInput;
275
+ };
276
+ /** Individual message processing failure for partial failure reporting. */
277
+ type MessageProcessingFailure = {
278
+ messageId: string;
279
+ errorMessage?: string;
280
+ };
281
+ /** Result returned from consumer and schedule handlers. */
282
+ type EventResult = {
283
+ success: boolean;
284
+ failures?: MessageProcessingFailure[];
285
+ errorMessage?: string;
286
+ };
287
+ /**
288
+ * A consumer message with a schema-validated parsed body.
289
+ * Returned by @Messages(schema) and createConsumerHandler({ messageSchema }).
290
+ * Retains all original ConsumerMessage fields so the handler can
291
+ * correlate parsed bodies with message metadata (messageId, source, etc.).
292
+ */
293
+ type ValidatedConsumerMessage<T> = ConsumerMessage & {
294
+ parsedBody: T;
295
+ };
296
+
297
+ /** Input provided to a schedule handler. */
298
+ type ScheduleEventInput = {
299
+ handlerTag: string;
300
+ scheduleId: string;
301
+ messageId: string;
302
+ schedule: string;
303
+ input?: unknown;
304
+ vendor: unknown;
305
+ traceContext?: Record<string, string> | null;
306
+ };
307
+ /** Context for schedule event handlers. */
308
+ type ScheduleHandlerContext = BaseHandlerContext & {
309
+ event: ScheduleEventInput;
310
+ };
311
+
312
+ export { type BaseHandlerContext, type BucketEvent, BucketEventType, type CelerityLayer, type CelerityLogger, type CeleritySpan, type CelerityTracer, type ClassProvider, type Closeable, type ConsumerEventInput, type ConsumerHandlerContext, type ConsumerMessage, type DatastoreEvent, DatastoreEventType, type EventResult, type FactoryProvider, type FunctionHandlerDefinition, type GuardDefinition, type GuardHandlerContext, type GuardHandlerRequest, type HandlerMetadata, type HandlerResponse, type HandlerType, type HttpHandlerContext, type HttpMethod, type HttpRequest, type HttpResponse, type InjectionToken, type LogLevel, type MessageAttributeValue, type MessageAttributes, type MessageProcessingFailure, type ModuleMetadata, type NextFunction, type Provider, type ScheduleEventInput, type ScheduleHandlerContext, type Schema, type ServiceContainer, SourceType, type Type, type ValidatedConsumerMessage, type ValueProvider, type WebSocketEventType, type WebSocketHandlerContext, type WebSocketMessage, type WebSocketMessageType, type WebSocketRequestContext, type WebSocketSendOptions, WebSocketSender };
package/dist/index.d.ts CHANGED
@@ -84,18 +84,51 @@ interface HandlerMetadata {
84
84
  /** Check if key exists (either scope). */
85
85
  has(key: string): boolean;
86
86
  }
87
- type HandlerContext = {
87
+ type HttpHandlerContext = BaseHandlerContext & {
88
88
  request: HttpRequest;
89
+ };
90
+ /** Request data available to guard handlers from the runtime. */
91
+ type GuardHandlerRequest = {
92
+ method: string;
93
+ path: string;
94
+ headers: Record<string, string | string[]>;
95
+ query: Record<string, string | string[]>;
96
+ cookies: Record<string, string>;
97
+ body: unknown;
98
+ requestId: string;
99
+ clientIp: string;
100
+ };
101
+ /** Context passed to guard `check()` methods. */
102
+ type GuardHandlerContext = {
103
+ /** Auth token extracted by the runtime (using the configured token source and auth scheme). */
104
+ token: string;
105
+ /** Accumulated auth from preceding guards, keyed by guard name. */
106
+ auth: Record<string, unknown>;
107
+ /** Request data available from the runtime. */
108
+ request: GuardHandlerRequest;
109
+ /** Handler metadata from decorators (e.g. `@Action`). */
89
110
  metadata: HandlerMetadata;
111
+ /** DI container for resolving services. */
90
112
  container: ServiceContainer;
91
- /** Request-scoped logger set by TelemetryLayer. Enriched with requestId, method, path. */
113
+ /** Request-scoped logger, when available. */
92
114
  logger?: CelerityLogger;
93
115
  };
94
116
 
95
- type HandlerResponse = HttpResponse;
96
- type NextFunction = () => Promise<HandlerResponse>;
97
- interface CelerityLayer<TContext extends HandlerContext = HandlerContext> {
98
- handle(context: TContext, next: NextFunction): Promise<HandlerResponse>;
117
+ type HandlerType = "http" | "websocket" | "consumer" | "schedule" | "custom";
118
+ /** Shared fields present in every handler context. */
119
+ type BaseHandlerContext = {
120
+ metadata: HandlerMetadata;
121
+ container: ServiceContainer;
122
+ /** Request-scoped logger set by TelemetryLayer. */
123
+ logger?: CelerityLogger;
124
+ };
125
+
126
+ type HandlerResponse = unknown;
127
+ type NextFunction = () => Promise<unknown>;
128
+ interface CelerityLayer<TContext extends BaseHandlerContext = HttpHandlerContext> {
129
+ /** When defined, the layer only executes for the returned handler types. Omit to run for all types. */
130
+ supports?(handlerType: HandlerType): boolean;
131
+ handle(context: TContext, next: NextFunction): Promise<unknown>;
99
132
  dispose?(): Promise<void> | void;
100
133
  }
101
134
 
@@ -106,13 +139,20 @@ interface Schema<T = unknown> {
106
139
  type FunctionHandlerDefinition = {
107
140
  __celerity_handler: true;
108
141
  id?: string;
109
- type: "http" | "consumer" | "schedule" | "websocket";
142
+ type: "http" | "consumer" | "schedule" | "websocket" | "workflow" | "custom";
110
143
  metadata: Record<string, unknown>;
111
144
  handler: (...args: unknown[]) => unknown;
112
145
  };
146
+ type GuardDefinition = {
147
+ __celerity_guard: true;
148
+ name?: string;
149
+ handler: (...args: unknown[]) => unknown;
150
+ metadata?: Record<string, unknown>;
151
+ };
113
152
  type ModuleMetadata = {
114
153
  controllers?: Type[];
115
154
  functionHandlers?: FunctionHandlerDefinition[];
155
+ guards?: (Type | GuardDefinition)[];
116
156
  providers?: (Type | (Provider & {
117
157
  provide: InjectionToken;
118
158
  }))[];
@@ -120,4 +160,153 @@ type ModuleMetadata = {
120
160
  exports?: InjectionToken[];
121
161
  };
122
162
 
123
- export type { CelerityLayer, CelerityLogger, CeleritySpan, CelerityTracer, ClassProvider, Closeable, FactoryProvider, FunctionHandlerDefinition, HandlerContext, HandlerMetadata, HandlerResponse, HttpMethod, HttpRequest, HttpResponse, InjectionToken, LogLevel, ModuleMetadata, NextFunction, Provider, Schema, ServiceContainer, Type, ValueProvider };
163
+ type WebSocketEventType = "connect" | "message" | "disconnect";
164
+ type WebSocketMessageType = "json" | "binary";
165
+ /** SDK representation of a WebSocket message from the runtime. */
166
+ type WebSocketMessage = {
167
+ messageType: WebSocketMessageType;
168
+ eventType: WebSocketEventType;
169
+ connectionId: string;
170
+ messageId: string;
171
+ jsonBody?: unknown;
172
+ binaryBody?: Buffer;
173
+ requestContext?: WebSocketRequestContext;
174
+ traceContext?: Record<string, string> | null;
175
+ };
176
+ /** HTTP context from the original WebSocket upgrade request. */
177
+ type WebSocketRequestContext = {
178
+ requestId: string;
179
+ requestTime: number;
180
+ path: string;
181
+ protocolVersion: string;
182
+ headers: Record<string, string | string[]>;
183
+ userAgent?: string;
184
+ clientIp: string;
185
+ query: Record<string, string | string[]>;
186
+ cookies: Record<string, string>;
187
+ auth?: Record<string, unknown>;
188
+ traceContext?: Record<string, string>;
189
+ };
190
+ /** Context for WebSocket handlers. */
191
+ type WebSocketHandlerContext = BaseHandlerContext & {
192
+ message: WebSocketMessage;
193
+ };
194
+ type WebSocketSendOptions = {
195
+ messageId?: string;
196
+ messageType?: "json" | "binary";
197
+ };
198
+ /** Platform-agnostic abstraction for sending WebSocket messages. */
199
+ interface WebSocketSender {
200
+ /** Send a message to a specific WebSocket connection. */
201
+ sendMessage(connectionId: string, data: unknown, options?: WebSocketSendOptions): Promise<void>;
202
+ }
203
+ /**
204
+ * DI token for WebSocketSender.
205
+ * TypeScript uses the interface in type position and the symbol in value position.
206
+ */
207
+ declare const WebSocketSender: unique symbol;
208
+
209
+ /**
210
+ * A single attribute value in the SQS-compatible format used by all consumers.
211
+ * `stringValue` is optional because binary-typed attributes may omit it.
212
+ */
213
+ type MessageAttributeValue = {
214
+ dataType: string;
215
+ stringValue?: string;
216
+ binaryValue?: string;
217
+ };
218
+ /** Key-value map of message attributes attached to a consumer message. */
219
+ type MessageAttributes = Record<string, MessageAttributeValue>;
220
+ /** A single message from an event source. */
221
+ type ConsumerMessage = {
222
+ messageId: string;
223
+ body: string;
224
+ source: string;
225
+ sourceType?: string;
226
+ sourceName?: string;
227
+ eventType?: string;
228
+ messageAttributes: MessageAttributes;
229
+ vendor: unknown;
230
+ };
231
+ /** Consumer source types corresponding to Celerity resource kinds. */
232
+ declare const SourceType: {
233
+ readonly Bucket: "bucket";
234
+ readonly Datastore: "datastore";
235
+ readonly Queue: "queue";
236
+ readonly Topic: "topic";
237
+ };
238
+ type SourceType = (typeof SourceType)[keyof typeof SourceType];
239
+ /** Celerity-standard bucket event types (mapped from cloud-specific names). */
240
+ declare const BucketEventType: {
241
+ readonly Created: "created";
242
+ readonly Deleted: "deleted";
243
+ readonly MetadataUpdated: "metadataUpdated";
244
+ };
245
+ type BucketEventType = (typeof BucketEventType)[keyof typeof BucketEventType];
246
+ /** Celerity-standard datastore event types (mapped from cloud-specific names). */
247
+ declare const DatastoreEventType: {
248
+ readonly Inserted: "inserted";
249
+ readonly Modified: "modified";
250
+ readonly Removed: "removed";
251
+ };
252
+ type DatastoreEventType = (typeof DatastoreEventType)[keyof typeof DatastoreEventType];
253
+ /** Celerity-standard bucket event body shape. */
254
+ type BucketEvent = {
255
+ key: string;
256
+ size?: number;
257
+ eTag?: string;
258
+ };
259
+ /** Celerity-standard datastore event body shape. */
260
+ type DatastoreEvent = {
261
+ keys: Record<string, unknown>;
262
+ newItem?: Record<string, unknown>;
263
+ oldItem?: Record<string, unknown>;
264
+ };
265
+ /** Input provided to a consumer handler — a batch of messages. */
266
+ type ConsumerEventInput = {
267
+ handlerTag: string;
268
+ messages: ConsumerMessage[];
269
+ vendor: unknown;
270
+ traceContext?: Record<string, string> | null;
271
+ };
272
+ /** Context for consumer event handlers. */
273
+ type ConsumerHandlerContext = BaseHandlerContext & {
274
+ event: ConsumerEventInput;
275
+ };
276
+ /** Individual message processing failure for partial failure reporting. */
277
+ type MessageProcessingFailure = {
278
+ messageId: string;
279
+ errorMessage?: string;
280
+ };
281
+ /** Result returned from consumer and schedule handlers. */
282
+ type EventResult = {
283
+ success: boolean;
284
+ failures?: MessageProcessingFailure[];
285
+ errorMessage?: string;
286
+ };
287
+ /**
288
+ * A consumer message with a schema-validated parsed body.
289
+ * Returned by @Messages(schema) and createConsumerHandler({ messageSchema }).
290
+ * Retains all original ConsumerMessage fields so the handler can
291
+ * correlate parsed bodies with message metadata (messageId, source, etc.).
292
+ */
293
+ type ValidatedConsumerMessage<T> = ConsumerMessage & {
294
+ parsedBody: T;
295
+ };
296
+
297
+ /** Input provided to a schedule handler. */
298
+ type ScheduleEventInput = {
299
+ handlerTag: string;
300
+ scheduleId: string;
301
+ messageId: string;
302
+ schedule: string;
303
+ input?: unknown;
304
+ vendor: unknown;
305
+ traceContext?: Record<string, string> | null;
306
+ };
307
+ /** Context for schedule event handlers. */
308
+ type ScheduleHandlerContext = BaseHandlerContext & {
309
+ event: ScheduleEventInput;
310
+ };
311
+
312
+ export { type BaseHandlerContext, type BucketEvent, BucketEventType, type CelerityLayer, type CelerityLogger, type CeleritySpan, type CelerityTracer, type ClassProvider, type Closeable, type ConsumerEventInput, type ConsumerHandlerContext, type ConsumerMessage, type DatastoreEvent, DatastoreEventType, type EventResult, type FactoryProvider, type FunctionHandlerDefinition, type GuardDefinition, type GuardHandlerContext, type GuardHandlerRequest, type HandlerMetadata, type HandlerResponse, type HandlerType, type HttpHandlerContext, type HttpMethod, type HttpRequest, type HttpResponse, type InjectionToken, type LogLevel, type MessageAttributeValue, type MessageAttributes, type MessageProcessingFailure, type ModuleMetadata, type NextFunction, type Provider, type ScheduleEventInput, type ScheduleHandlerContext, type Schema, type ServiceContainer, SourceType, type Type, type ValidatedConsumerMessage, type ValueProvider, type WebSocketEventType, type WebSocketHandlerContext, type WebSocketMessage, type WebSocketMessageType, type WebSocketRequestContext, type WebSocketSendOptions, WebSocketSender };
package/dist/index.js CHANGED
@@ -1 +1,27 @@
1
+ // src/websocket.ts
2
+ var WebSocketSender = /* @__PURE__ */ Symbol.for("celerity:websocket-sender");
3
+
4
+ // src/consumer.ts
5
+ var SourceType = {
6
+ Bucket: "bucket",
7
+ Datastore: "datastore",
8
+ Queue: "queue",
9
+ Topic: "topic"
10
+ };
11
+ var BucketEventType = {
12
+ Created: "created",
13
+ Deleted: "deleted",
14
+ MetadataUpdated: "metadataUpdated"
15
+ };
16
+ var DatastoreEventType = {
17
+ Inserted: "inserted",
18
+ Modified: "modified",
19
+ Removed: "removed"
20
+ };
21
+ export {
22
+ BucketEventType,
23
+ DatastoreEventType,
24
+ SourceType,
25
+ WebSocketSender
26
+ };
1
27
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../src/websocket.ts","../src/consumer.ts"],"sourcesContent":["import type { BaseHandlerContext } from \"./handler\";\n\nexport type WebSocketEventType = \"connect\" | \"message\" | \"disconnect\";\nexport type WebSocketMessageType = \"json\" | \"binary\";\n\n/** SDK representation of a WebSocket message from the runtime. */\nexport type WebSocketMessage = {\n messageType: WebSocketMessageType;\n eventType: WebSocketEventType;\n connectionId: string;\n messageId: string;\n jsonBody?: unknown;\n binaryBody?: Buffer;\n requestContext?: WebSocketRequestContext;\n traceContext?: Record<string, string> | null;\n};\n\n/** HTTP context from the original WebSocket upgrade request. */\nexport type WebSocketRequestContext = {\n requestId: string;\n requestTime: number;\n path: string;\n protocolVersion: string;\n headers: Record<string, string | string[]>;\n userAgent?: string;\n clientIp: string;\n query: Record<string, string | string[]>;\n cookies: Record<string, string>;\n auth?: Record<string, unknown>;\n traceContext?: Record<string, string>;\n};\n\n/** Context for WebSocket handlers. */\nexport type WebSocketHandlerContext = BaseHandlerContext & {\n message: WebSocketMessage;\n};\n\nexport type WebSocketSendOptions = {\n messageId?: string;\n messageType?: \"json\" | \"binary\";\n};\n\n/** Platform-agnostic abstraction for sending WebSocket messages. */\nexport interface WebSocketSender {\n /** Send a message to a specific WebSocket connection. */\n sendMessage(connectionId: string, data: unknown, options?: WebSocketSendOptions): Promise<void>;\n}\n\n/**\n * DI token for WebSocketSender.\n * TypeScript uses the interface in type position and the symbol in value position.\n */\nexport const WebSocketSender: unique symbol = Symbol.for(\"celerity:websocket-sender\");\n","import type { BaseHandlerContext } from \"./handler\";\n\n/**\n * A single attribute value in the SQS-compatible format used by all consumers.\n * `stringValue` is optional because binary-typed attributes may omit it.\n */\nexport type MessageAttributeValue = {\n dataType: string;\n stringValue?: string;\n binaryValue?: string;\n};\n\n/** Key-value map of message attributes attached to a consumer message. */\nexport type MessageAttributes = Record<string, MessageAttributeValue>;\n\n/** A single message from an event source. */\nexport type ConsumerMessage = {\n messageId: string;\n body: string;\n source: string;\n sourceType?: string;\n sourceName?: string;\n eventType?: string;\n messageAttributes: MessageAttributes;\n vendor: unknown;\n};\n\n/** Consumer source types corresponding to Celerity resource kinds. */\nexport const SourceType = {\n Bucket: \"bucket\",\n Datastore: \"datastore\",\n Queue: \"queue\",\n Topic: \"topic\",\n} as const;\nexport type SourceType = (typeof SourceType)[keyof typeof SourceType];\n\n/** Celerity-standard bucket event types (mapped from cloud-specific names). */\nexport const BucketEventType = {\n Created: \"created\",\n Deleted: \"deleted\",\n MetadataUpdated: \"metadataUpdated\",\n} as const;\nexport type BucketEventType = (typeof BucketEventType)[keyof typeof BucketEventType];\n\n/** Celerity-standard datastore event types (mapped from cloud-specific names). */\nexport const DatastoreEventType = {\n Inserted: \"inserted\",\n Modified: \"modified\",\n Removed: \"removed\",\n} as const;\nexport type DatastoreEventType = (typeof DatastoreEventType)[keyof typeof DatastoreEventType];\n\n/** Celerity-standard bucket event body shape. */\nexport type BucketEvent = {\n key: string;\n size?: number;\n eTag?: string;\n};\n\n/** Celerity-standard datastore event body shape. */\nexport type DatastoreEvent = {\n keys: Record<string, unknown>;\n newItem?: Record<string, unknown>;\n oldItem?: Record<string, unknown>;\n};\n\n/** Input provided to a consumer handler — a batch of messages. */\nexport type ConsumerEventInput = {\n handlerTag: string;\n messages: ConsumerMessage[];\n vendor: unknown;\n traceContext?: Record<string, string> | null;\n};\n\n/** Context for consumer event handlers. */\nexport type ConsumerHandlerContext = BaseHandlerContext & {\n event: ConsumerEventInput;\n};\n\n/** Individual message processing failure for partial failure reporting. */\nexport type MessageProcessingFailure = {\n messageId: string;\n errorMessage?: string;\n};\n\n/** Result returned from consumer and schedule handlers. */\nexport type EventResult = {\n success: boolean;\n failures?: MessageProcessingFailure[];\n errorMessage?: string;\n};\n\n/**\n * A consumer message with a schema-validated parsed body.\n * Returned by @Messages(schema) and createConsumerHandler({ messageSchema }).\n * Retains all original ConsumerMessage fields so the handler can\n * correlate parsed bodies with message metadata (messageId, source, etc.).\n */\nexport type ValidatedConsumerMessage<T> = ConsumerMessage & {\n parsedBody: T;\n};\n"],"mappings":";AAoDO,IAAMA,kBAAiCC,uBAAOC,IAAI,2BAAA;;;ACxBlD,IAAMC,aAAa;EACxBC,QAAQ;EACRC,WAAW;EACXC,OAAO;EACPC,OAAO;AACT;AAIO,IAAMC,kBAAkB;EAC7BC,SAAS;EACTC,SAAS;EACTC,iBAAiB;AACnB;AAIO,IAAMC,qBAAqB;EAChCC,UAAU;EACVC,UAAU;EACVC,SAAS;AACX;","names":["WebSocketSender","Symbol","for","SourceType","Bucket","Datastore","Queue","Topic","BucketEventType","Created","Deleted","MetadataUpdated","DatastoreEventType","Inserted","Modified","Removed"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celerity-sdk/types",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Shared TypeScript interfaces and types for the Celerity Node SDK",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {