@plyaz/types 1.36.0 → 1.36.2

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.
Files changed (44) hide show
  1. package/dist/api/index.cjs +199 -1
  2. package/dist/api/index.cjs.map +1 -1
  3. package/dist/api/index.js +199 -1
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/auth/index.cjs +1 -2
  6. package/dist/auth/index.cjs.map +1 -1
  7. package/dist/auth/index.js +1 -2
  8. package/dist/auth/index.js.map +1 -1
  9. package/dist/campaign/schemas.d.ts +1 -1
  10. package/dist/core/domain/files/enums.d.ts +36 -0
  11. package/dist/core/domain/files/index.d.ts +4 -1
  12. package/dist/core/domain/files/schemas.d.ts +14 -21
  13. package/dist/core/domain/files/streaming.d.ts +167 -0
  14. package/dist/core/events/index.d.ts +2 -0
  15. package/dist/core/events/streaming/index.d.ts +18 -0
  16. package/dist/core/events/streaming/responses.d.ts +164 -0
  17. package/dist/core/events/streaming/types.d.ts +408 -0
  18. package/dist/core/frontend/index.d.ts +1 -1
  19. package/dist/core/frontend/types.d.ts +179 -5
  20. package/dist/core/index.cjs +221 -0
  21. package/dist/core/index.cjs.map +1 -1
  22. package/dist/core/index.d.ts +1 -1
  23. package/dist/core/index.js +192 -1
  24. package/dist/core/index.js.map +1 -1
  25. package/dist/core/init/index.d.ts +1 -1
  26. package/dist/core/init/types.d.ts +51 -0
  27. package/dist/errors/codes.d.ts +47 -0
  28. package/dist/errors/enums.d.ts +1 -0
  29. package/dist/errors/index.cjs +231 -1
  30. package/dist/errors/index.cjs.map +1 -1
  31. package/dist/errors/index.js +231 -2
  32. package/dist/errors/index.js.map +1 -1
  33. package/dist/errors/types.d.ts +15 -0
  34. package/dist/index.cjs +450 -1
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.js +420 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/store/files/index.d.ts +1 -1
  39. package/dist/store/files/types.d.ts +47 -1
  40. package/dist/store/index.d.ts +1 -0
  41. package/dist/store/stream/index.d.ts +9 -0
  42. package/dist/store/stream/types.d.ts +294 -0
  43. package/dist/store/types.d.ts +3 -0
  44. package/package.json +1 -1
@@ -17,7 +17,7 @@ export declare const formCampaignSchema: ({ maxFunding }: {
17
17
  }) => z.ZodObject<{
18
18
  title: z.ZodString;
19
19
  subtitle: z.ZodString;
20
- campaignImage: z.ZodAny;
20
+ campaignImage: z.ZodAny & z.ZodType<File, any, z.core.$ZodTypeInternals<File, any>>;
21
21
  startDate: z.ZodDate;
22
22
  duration: z.ZodNullable<z.ZodUnion<readonly [z.ZodLiteral<30>, z.ZodLiteral<60>, z.ZodLiteral<90>]>>;
23
23
  story: z.ZodString;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Files Domain Enums and Constants
3
+ *
4
+ * Runtime constants for files/media operations.
5
+ */
6
+ /**
7
+ * System user UUID for uploads without user context.
8
+ * Used for:
9
+ * - Generated documents (no auth context)
10
+ * - System-initiated uploads
11
+ * - Background jobs
12
+ *
13
+ * Must be a valid UUID as media.user_id has FK constraint to users table.
14
+ * This UUID should exist in the users table or FK checks should be disabled.
15
+ */
16
+ export declare const SYSTEM_USER_ID = "00000000-0000-0000-0000-000000000000";
17
+ /**
18
+ * File types supported by the DB ENUM
19
+ * Use these when creating records - 'OTHER' is NOT in the DB ENUM
20
+ */
21
+ export declare const FILE_TYPES: {
22
+ readonly IMAGE: "IMAGE";
23
+ readonly VIDEO: "VIDEO";
24
+ readonly AUDIO: "AUDIO";
25
+ readonly DOCUMENT: "DOCUMENT";
26
+ };
27
+ export type FileTypeValue = (typeof FILE_TYPES)[keyof typeof FILE_TYPES];
28
+ /**
29
+ * Access levels for files
30
+ */
31
+ export declare const FILE_ACCESS_LEVELS: {
32
+ readonly PUBLIC: "public";
33
+ readonly PRIVATE: "private";
34
+ readonly PROTECTED: "protected";
35
+ };
36
+ export type FileAccessLevelValue = (typeof FILE_ACCESS_LEVELS)[keyof typeof FILE_ACCESS_LEVELS];
@@ -4,5 +4,8 @@
4
4
  * Core domain types for files/media service.
5
5
  * Schemas are the single source of truth for DB types.
6
6
  */
7
- export { SYSTEM_USER_ID, MediaTypeSchema, type MediaType, FileTypeSchema, type FileType, MediaAccessLevelSchema, type MediaAccessLevel, FilesDatabaseRowSchema, type FilesDatabaseRow, MediaVariantsDatabaseRowSchema, type MediaVariantsDatabaseRow, CreateMediaSchema, type CreateMediaInput, type CreateMediaOutput, type FilesCreateInput, CreateMediaVariantSchema, type MediaVariantsCreateInput, PatchMediaSchema, type PatchMediaInput, type PatchMediaOutput, } from './schemas';
7
+ export { SYSTEM_USER_ID, FILE_TYPES, type FileTypeValue, FILE_ACCESS_LEVELS, type FileAccessLevelValue, } from './enums';
8
+ export { FILES_STREAM_MESSAGE_TYPE, FILES_STREAM_SUBTYPE, FILES_STREAM_PROGRESS_STATUS, FILES_STREAM_EVENT, FILES_STREAM_CHANNEL_PREFIX, FILES_STREAM_BROADCAST_CHANNEL, FILES_STREAM_CHANNEL, } from './streaming';
9
+ export type { FilesStreamMessageType, FilesStreamSubtype, FilesStreamProgressStatus, FilesStreamEventName, FilesStreamChannelPrefix, FilesStreamBroadcastChannel, FilesStreamChannel, FilesUploadStreamProgress, FilesDownloadStreamProgress, FilesGenerateStreamProgress, FilesStreamProgressData, } from './streaming';
10
+ export { MediaTypeSchema, type MediaType, FileTypeSchema, type FileType, MediaAccessLevelSchema, type MediaAccessLevel, FilesDatabaseRowSchema, type FilesDatabaseRow, MediaVariantsDatabaseRowSchema, type MediaVariantsDatabaseRow, CreateFilesSchema, type FilesCreateInput, type FilesCreateOutput, CreateMediaVariantSchema, type MediaVariantsCreateInput, PatchFilesSchema, type FilesPatchInput, type FilesPatchOutput, } from './schemas';
8
11
  export { type FilesEntity, type FilesFrontendServiceConfig, type FilesDomainServiceConfig, type SingleUploadEventPayload, type BulkUploadEventPayload, type FileUploadedEventPayload, type FileBulkUploadedEventPayload, type FilesUploadEventPayload, type FileDocumentGeneratedEventPayload, } from './types';
@@ -10,8 +10,6 @@
10
10
  * - FilesMapper for transformations
11
11
  */
12
12
  import { z } from 'zod';
13
- /** System user UUID for uploads without user context */
14
- export declare const SYSTEM_USER_ID = "00000000-0000-0000-0000-000000000000";
15
13
  /**
16
14
  * Media type enum - matches media.type DB ENUM
17
15
  * Note: DB only has IMAGE, VIDEO, AUDIO, DOCUMENT (no OTHER)
@@ -26,8 +24,8 @@ export declare const MediaTypeSchema: z.ZodEnum<{
26
24
  export type MediaType = z.infer<typeof MediaTypeSchema>;
27
25
  /**
28
26
  * File type enum - for domain layer (includes OTHER for unknown types)
29
- * Use this for domain entities and frontend display
30
- * @deprecated Prefer MediaTypeSchema for new code - OTHER not in DB
27
+ * Use this for domain entities and frontend display.
28
+ * Note: OTHER is not in the DB ENUM, mapper should convert to DOCUMENT for DB ops.
31
29
  */
32
30
  export declare const FileTypeSchema: z.ZodEnum<{
33
31
  IMAGE: "IMAGE";
@@ -81,13 +79,13 @@ export declare const FilesDatabaseRowSchema: z.ZodObject<{
81
79
  */
82
80
  export type FilesDatabaseRow = z.infer<typeof FilesDatabaseRowSchema>;
83
81
  /**
84
- * Schema for creating a media record in the database
82
+ * Schema for creating a file/media record in the database
85
83
  * Validates data before repository.create()
86
84
  *
87
85
  * Auto-generated fields (id, created_at, updated_at, deleted_at)
88
86
  * are handled by the repository.
89
87
  */
90
- export declare const CreateMediaSchema: z.ZodObject<{
88
+ export declare const CreateFilesSchema: z.ZodObject<{
91
89
  user_id: z.ZodDefault<z.ZodString>;
92
90
  type: z.ZodDefault<z.ZodEnum<{
93
91
  IMAGE: "IMAGE";
@@ -116,20 +114,15 @@ export declare const CreateMediaSchema: z.ZodObject<{
116
114
  protected: "protected";
117
115
  }>>>;
118
116
  }, z.core.$strip>;
119
- /** Input type for creating media (before defaults applied) */
120
- export type CreateMediaInput = z.input<typeof CreateMediaSchema>;
121
- /** Output type for creating media (after defaults applied) */
122
- export type CreateMediaOutput = z.output<typeof CreateMediaSchema>;
117
+ /** Input type for creating files (before defaults applied) */
118
+ export type FilesCreateInput = z.input<typeof CreateFilesSchema>;
119
+ /** Output type for creating files (after defaults applied) */
120
+ export type FilesCreateOutput = z.output<typeof CreateFilesSchema>;
123
121
  /**
124
- * Alias for backward compatibility
125
- * @deprecated Use CreateMediaInput instead
126
- */
127
- export type FilesCreateInput = CreateMediaInput;
128
- /**
129
- * Schema for partial update of a media record
122
+ * Schema for partial update of a file/media record
130
123
  * All fields optional
131
124
  */
132
- export declare const PatchMediaSchema: z.ZodObject<{
125
+ export declare const PatchFilesSchema: z.ZodObject<{
133
126
  user_id: z.ZodOptional<z.ZodDefault<z.ZodString>>;
134
127
  type: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
135
128
  IMAGE: "IMAGE";
@@ -158,8 +151,8 @@ export declare const PatchMediaSchema: z.ZodObject<{
158
151
  protected: "protected";
159
152
  }>>>>;
160
153
  }, z.core.$strip>;
161
- export type PatchMediaInput = z.input<typeof PatchMediaSchema>;
162
- export type PatchMediaOutput = z.output<typeof PatchMediaSchema>;
154
+ export type FilesPatchInput = z.input<typeof PatchFilesSchema>;
155
+ export type FilesPatchOutput = z.output<typeof PatchFilesSchema>;
163
156
  /**
164
157
  * Full media_variants database row schema
165
158
  */
@@ -179,10 +172,10 @@ export type MediaVariantsDatabaseRow = z.infer<typeof MediaVariantsDatabaseRowSc
179
172
  * Schema for creating a media variant record
180
173
  */
181
174
  export declare const CreateMediaVariantSchema: z.ZodObject<{
182
- file_size: z.ZodNullable<z.ZodNumber>;
183
- cdn_url: z.ZodNullable<z.ZodString>;
184
175
  width: z.ZodNullable<z.ZodNumber>;
185
176
  height: z.ZodNullable<z.ZodNumber>;
177
+ file_size: z.ZodNullable<z.ZodNumber>;
178
+ cdn_url: z.ZodNullable<z.ZodString>;
186
179
  media_id: z.ZodString;
187
180
  variant_name: z.ZodString;
188
181
  file_path: z.ZodString;
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Files Domain Streaming Types
3
+ *
4
+ * Stream message types specific to the files domain.
5
+ * These extend from existing storage types and are merged into global streaming types.
6
+ *
7
+ * Architecture:
8
+ * - FilesStreamProgressData extends UploadProgressEvent (from storage)
9
+ * - Constants (FILES_STREAM_*) are domain-specific
10
+ * - Global types in @plyaz/types/core/events/streaming merge these with other domains
11
+ */
12
+ import type { UploadProgressEvent } from '../../../storage';
13
+ /**
14
+ * Message type categories specific to files domain.
15
+ * These get merged into global STREAM_MESSAGE_TYPE.
16
+ */
17
+ export declare const FILES_STREAM_MESSAGE_TYPE: {
18
+ readonly PROGRESS: "progress";
19
+ readonly STATUS: "status";
20
+ readonly ERROR: "error";
21
+ };
22
+ export type FilesStreamMessageType = (typeof FILES_STREAM_MESSAGE_TYPE)[keyof typeof FILES_STREAM_MESSAGE_TYPE];
23
+ /**
24
+ * Stream message subtypes for files domain.
25
+ * Defines the specific operations that can be streamed.
26
+ */
27
+ export declare const FILES_STREAM_SUBTYPE: {
28
+ readonly UPLOAD: "upload";
29
+ readonly DOWNLOAD: "download";
30
+ readonly GENERATE: "generate";
31
+ };
32
+ export type FilesStreamSubtype = (typeof FILES_STREAM_SUBTYPE)[keyof typeof FILES_STREAM_SUBTYPE];
33
+ /**
34
+ * Progress status values for files streaming operations.
35
+ * Aligned with storage UPLOAD_STATUS enum values.
36
+ */
37
+ export declare const FILES_STREAM_PROGRESS_STATUS: {
38
+ readonly PENDING: "pending";
39
+ readonly UPLOADING: "uploading";
40
+ readonly DOWNLOADING: "downloading";
41
+ readonly PROCESSING: "processing";
42
+ readonly GENERATING: "generating";
43
+ readonly COMPLETED: "completed";
44
+ readonly FAILED: "failed";
45
+ readonly CANCELLED: "cancelled";
46
+ };
47
+ export type FilesStreamProgressStatus = (typeof FILES_STREAM_PROGRESS_STATUS)[keyof typeof FILES_STREAM_PROGRESS_STATUS];
48
+ /**
49
+ * SSE/WebSocket event names for files domain.
50
+ * These map to the `event` field in StreamMessage.
51
+ */
52
+ export declare const FILES_STREAM_EVENT: {
53
+ readonly UPLOAD_PROGRESS: "upload:progress";
54
+ readonly UPLOAD_COMPLETED: "upload:completed";
55
+ readonly UPLOAD_FAILED: "upload:failed";
56
+ readonly UPLOAD_CANCELLED: "upload:cancelled";
57
+ readonly DOWNLOAD_PROGRESS: "download:progress";
58
+ readonly DOWNLOAD_COMPLETED: "download:completed";
59
+ readonly DOWNLOAD_FAILED: "download:failed";
60
+ readonly DOWNLOAD_CANCELLED: "download:cancelled";
61
+ readonly GENERATE_PROGRESS: "generate:progress";
62
+ readonly GENERATE_COMPLETED: "generate:completed";
63
+ readonly GENERATE_FAILED: "generate:failed";
64
+ };
65
+ export type FilesStreamEventName = (typeof FILES_STREAM_EVENT)[keyof typeof FILES_STREAM_EVENT];
66
+ /**
67
+ * Channel prefixes for files domain subscriptions.
68
+ * Used for per-resource channels (upload:fileId, download:fileId, etc.)
69
+ */
70
+ export declare const FILES_STREAM_CHANNEL_PREFIX: {
71
+ readonly UPLOAD: "upload:";
72
+ readonly DOWNLOAD: "download:";
73
+ readonly GENERATE: "generate:";
74
+ };
75
+ export type FilesStreamChannelPrefix = (typeof FILES_STREAM_CHANNEL_PREFIX)[keyof typeof FILES_STREAM_CHANNEL_PREFIX];
76
+ /**
77
+ * Broadcast channels for files domain (user-scoped).
78
+ * Used for subscribing to all events of a type.
79
+ */
80
+ export declare const FILES_STREAM_BROADCAST_CHANNEL: {
81
+ readonly UPLOADS: "uploads";
82
+ readonly DOWNLOADS: "downloads";
83
+ readonly GENERATIONS: "generations";
84
+ };
85
+ export type FilesStreamBroadcastChannel = (typeof FILES_STREAM_BROADCAST_CHANNEL)[keyof typeof FILES_STREAM_BROADCAST_CHANNEL];
86
+ /**
87
+ * All files stream channels (prefixes + broadcast).
88
+ */
89
+ export declare const FILES_STREAM_CHANNEL: {
90
+ readonly PREFIX: {
91
+ readonly UPLOAD: "upload:";
92
+ readonly DOWNLOAD: "download:";
93
+ readonly GENERATE: "generate:";
94
+ };
95
+ readonly BROADCAST: {
96
+ readonly UPLOADS: "uploads";
97
+ readonly DOWNLOADS: "downloads";
98
+ readonly GENERATIONS: "generations";
99
+ };
100
+ };
101
+ /**
102
+ * Channel patterns for files domain subscriptions.
103
+ *
104
+ * - `upload:{fileId}` - Per-file upload progress
105
+ * - `download:{fileId}` - Per-file download progress
106
+ * - `generate:{templateId}` - Per-template generation progress
107
+ * - `uploads` - All uploads for current user
108
+ * - `downloads` - All downloads for current user
109
+ * - `generations` - All generations for current user
110
+ */
111
+ export type FilesStreamChannel = `upload:${string}` | `download:${string}` | `generate:${string}` | FilesStreamBroadcastChannel;
112
+ /**
113
+ * Base progress data extending storage's UploadProgressEvent.
114
+ * Used for upload progress streaming.
115
+ */
116
+ export interface FilesUploadStreamProgress extends UploadProgressEvent {
117
+ /** Current status */
118
+ status: FilesStreamProgressStatus;
119
+ /** Error message (if status is 'failed') */
120
+ error?: string;
121
+ }
122
+ /**
123
+ * Download progress data.
124
+ * Similar to upload but for downloads.
125
+ */
126
+ export interface FilesDownloadStreamProgress {
127
+ /** File ID */
128
+ fileId: string;
129
+ /** Filename */
130
+ filename: string;
131
+ /** Bytes downloaded */
132
+ loaded: number;
133
+ /** Total bytes */
134
+ total: number;
135
+ /** Progress percentage (0-100) */
136
+ percentage: number;
137
+ /** Download speed in bytes/second */
138
+ speed?: number;
139
+ /** Estimated time remaining in seconds */
140
+ estimatedTimeRemaining?: number;
141
+ /** Current status */
142
+ status: FilesStreamProgressStatus;
143
+ /** Error message (if status is 'failed') */
144
+ error?: string;
145
+ }
146
+ /**
147
+ * Document generation progress data.
148
+ */
149
+ export interface FilesGenerateStreamProgress {
150
+ /** Template ID being generated */
151
+ templateId: string;
152
+ /** Progress percentage (0-100) */
153
+ percentage: number;
154
+ /** Current status */
155
+ status: FilesStreamProgressStatus;
156
+ /** Error message (if status is 'failed') */
157
+ error?: string;
158
+ /** Output filename (when completed) */
159
+ outputFilename?: string;
160
+ /** Output file ID (when completed) */
161
+ outputFileId?: string;
162
+ }
163
+ /**
164
+ * Union of all files stream progress data types.
165
+ * Use this for generic handling of any files progress message.
166
+ */
167
+ export type FilesStreamProgressData = FilesUploadStreamProgress | FilesDownloadStreamProgress | FilesGenerateStreamProgress;
@@ -20,3 +20,5 @@
20
20
  export { CoreEventScope, SystemEventAction, EntityEventAction, ValidationEventAction, SanitizationEventAction, ApiEventAction, CacheEventAction, AuthEventAction, DatabaseEventAction, FeatureFlagEventAction, StoreEventAction, StorageEventAction, NotificationEventAction, CORE_EVENTS, } from './enums';
21
21
  export type { CoreEventScopeType, SystemEventType, EntityEventType, ValidationEventType, SanitizationEventType, ApiEventType, CacheEventType, AuthEventType, DatabaseEventType, FeatureFlagEventType, StoreEventType, CoreEventType, } from './enums';
22
22
  export type { CoreEvent, CoreCrudOperation, CoreValidationStartedPayload, CoreValidationSuccessPayload, CoreValidationFailedPayload, CoreSanitizationStartedPayload, CoreSanitizationSuccessPayload, CoreSanitizationFailedPayload, CoreEntityCreatedPayload, CoreEntityUpdatedPayload, CoreEntityPatchedPayload, CoreEntityDeletedPayload, CoreEntityCreatingPayload, CoreEntityUpdatingPayload, CoreEntityPatchingPayload, CoreEntityDeletingPayload, CoreEntityErrorPayload, CoreEntityCompletePayload, CoreBulkCreatedPayload, CoreBulkDeletedPayload, CoreSystemInitializedPayload, CoreSystemReadyPayload, CoreSystemShutdownPayload, CoreSystemErrorPayload, CoreSystemWarningPayload, CoreApiRequestStartPayload, CoreApiRequestSuccessPayload, CoreApiRequestErrorPayload, CoreApiRetryPayload, CoreApiTimeoutPayload, CoreCacheHitPayload, CoreCacheMissPayload, CoreCacheSetPayload, CoreCacheDeletePayload, CoreCacheClearPayload, CoreCacheExpiredPayload, CoreCacheErrorPayload, CoreDatabaseConnectedPayload, CoreDatabaseDisconnectedPayload, CoreDatabaseQueryPayload, CoreDatabaseErrorPayload, CoreDatabaseTransactionStartPayload, CoreDatabaseTransactionCommitPayload, CoreDatabaseTransactionRollbackPayload, CoreAuthLoginPayload, CoreAuthLogoutPayload, CoreAuthTokenRefreshPayload, CoreAuthSessionExpiredPayload, CoreAuthUnauthorizedPayload, CoreFeatureFlagChangedPayload, CoreFeatureFlagEvaluatedPayload, CoreFeatureFlagRefreshedPayload, CoreStoreUpdatedPayload, CoreStoreResetPayload, CoreStoreHydratedPayload, CoreOperationRequestPayload, CoreOperationResultPayload, CoreOperationErrorPayload, CoreStorageUploadedPayload, CoreStorageDownloadedPayload, CoreStorageDeletedPayload, CoreStorageErrorPayload, CoreStorageHealthCheckPayload, CoreNotificationSentPayload, CoreNotificationFailedPayload, CoreNotificationDeliveredPayload, CoreNotificationOpenedPayload, CoreNotificationClickedPayload, CoreNotificationErrorPayload, CoreNotificationHealthCheckPayload, CoreEventPayloadMap, EventPersistenceConfig, DomainPersistenceConfig, PersistOperationConfig, FrontendEventHandlerConfig, DomainFrontendEventConfig, } from './payloads';
23
+ export { STREAM_TRANSPORT, SYSTEM_STREAM_MESSAGE_TYPE, SYSTEM_STREAM_SUBTYPE, SYSTEM_STREAM_CHANNEL, SYSTEM_STREAM_EVENT, STREAM_MESSAGE_TYPE, STREAM_SUBTYPE, STREAM_SCOPE, STREAM_EVENT, STREAM_CHANNEL_PREFIX, STREAM_BROADCAST_CHANNEL, STREAM_PROGRESS_STATUS, FILES_STREAM_MESSAGE_TYPE, FILES_STREAM_SUBTYPE, FILES_STREAM_PROGRESS_STATUS, FILES_STREAM_EVENT, FILES_STREAM_CHANNEL_PREFIX, FILES_STREAM_BROADCAST_CHANNEL, FILES_STREAM_CHANNEL, } from './streaming';
24
+ export type { StreamTransportType, StreamConnection, StreamConnectionInfo, SystemStreamMessageType, SystemStreamSubtype, SystemStreamChannel, StreamMessage, StreamMessageType, StreamMessageSubtype, StreamMessageScope, StreamProgressData, StreamProgressStatus, FilesUploadStreamProgress, FilesDownloadStreamProgress, FilesGenerateStreamProgress, StreamChannel, ChannelSubscription, StreamAuthResult, StreamAuthAdapterConfig, TokenAuthAdapterConfig, StreamTransportAdapterConfig, StreamBroadcasterConfig, StreamManagerStats, UseStreamConnectionOptions, UseStreamConnectionResult, UseStreamManagerOptions, UseStreamManagerResult, StreamResponse, StreamErrorEvent, PaginatedStreamResponse, StreamEndpointConfig, StreamEndpointCreateOptions, StreamBroadcasterInterface, ChannelControllerConfig, StreamMiddlewareContext, StreamMiddlewareResult, StreamMiddleware, RateLimitConfig, StreamEndpointEntry, StreamRegistryConfig, FilesStreamMessageType, FilesStreamSubtype, FilesStreamProgressStatus, FilesStreamProgressData, FilesStreamEventName, FilesStreamChannelPrefix, FilesStreamBroadcastChannel, FilesStreamChannel, } from './streaming';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Streaming Types
3
+ *
4
+ * Types for real-time event streaming via SSE/WebSocket.
5
+ *
6
+ * Architecture:
7
+ * - Domain services define their own streaming constants (e.g., FILES_STREAM_SUBTYPE)
8
+ * - Global constants here MERGE domain-specific constants
9
+ * - System constants (heartbeat, connection) are defined here as base
10
+ *
11
+ * Domain-specific streaming types are defined in their domains:
12
+ * - Files: @plyaz/types/core/domain/files (FILES_STREAM_*, FilesStreamSubtype, etc.)
13
+ */
14
+ export { STREAM_TRANSPORT, SYSTEM_STREAM_MESSAGE_TYPE, SYSTEM_STREAM_SUBTYPE, SYSTEM_STREAM_CHANNEL, SYSTEM_STREAM_EVENT, STREAM_MESSAGE_TYPE, STREAM_SUBTYPE, STREAM_SCOPE, STREAM_EVENT, STREAM_CHANNEL_PREFIX, STREAM_BROADCAST_CHANNEL, STREAM_PROGRESS_STATUS, } from './types';
15
+ export type { StreamTransportType, StreamConnection, StreamConnectionInfo, SystemStreamMessageType, SystemStreamSubtype, SystemStreamChannel, StreamMessage, StreamMessageType, StreamMessageSubtype, StreamMessageScope, StreamProgressData, StreamProgressStatus, FilesUploadStreamProgress, FilesDownloadStreamProgress, FilesGenerateStreamProgress, StreamChannel, ChannelSubscription, StreamAuthResult, StreamAuthAdapterConfig, TokenAuthAdapterConfig, StreamTransportAdapterConfig, StreamBroadcasterConfig, StreamManagerStats, UseStreamConnectionOptions, UseStreamConnectionResult, UseStreamManagerOptions, UseStreamManagerResult, } from './types';
16
+ export type { StreamResponse, StreamErrorEvent, PaginatedStreamResponse, StreamEndpointConfig, StreamEndpointCreateOptions, StreamBroadcasterInterface, ChannelControllerConfig, StreamMiddlewareContext, StreamMiddlewareResult, StreamMiddleware, RateLimitConfig, StreamEndpointEntry, StreamRegistryConfig, } from './responses';
17
+ export { FILES_STREAM_MESSAGE_TYPE, FILES_STREAM_SUBTYPE, FILES_STREAM_PROGRESS_STATUS, FILES_STREAM_EVENT, FILES_STREAM_CHANNEL_PREFIX, FILES_STREAM_BROADCAST_CHANNEL, FILES_STREAM_CHANNEL, } from '../../domain/files';
18
+ export type { FilesStreamMessageType, FilesStreamSubtype, FilesStreamProgressStatus, FilesStreamProgressData, FilesStreamEventName, FilesStreamChannelPrefix, FilesStreamBroadcastChannel, FilesStreamChannel, } from '../../domain/files';
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Stream Response Types
3
+ *
4
+ * Response types for real-time streaming that follow the API patterns.
5
+ * Uses standard ErrorResponse from @plyaz/types/errors.
6
+ */
7
+ import type { ErrorResponse, PackageErrorLike } from '../../../errors/types';
8
+ import type { StreamAuthResult, StreamConnection, StreamMessage } from './types';
9
+ /**
10
+ * Stream response wrapper - consistent with API ReturnResponseType
11
+ */
12
+ export interface StreamResponse<T = unknown> {
13
+ /** Whether the operation succeeded */
14
+ success: boolean;
15
+ /** Human-readable message */
16
+ message: string;
17
+ /** Response data payload */
18
+ data?: T;
19
+ /** Channel this response is for */
20
+ channel: string;
21
+ /** Unix timestamp when response was created */
22
+ timestamp: number;
23
+ /** Correlation ID for tracing */
24
+ correlationId?: string;
25
+ }
26
+ /**
27
+ * Stream error event - uses standard ErrorResponse
28
+ */
29
+ export interface StreamErrorEvent {
30
+ /** Always false for errors */
31
+ success: false;
32
+ /** Standard ErrorResponse array from @plyaz/types/errors */
33
+ errors: ErrorResponse;
34
+ /** Channel this error occurred on */
35
+ channel: string;
36
+ /** Unix timestamp when error occurred */
37
+ timestamp: number;
38
+ /** Correlation ID for tracing */
39
+ correlationId?: string;
40
+ }
41
+ /**
42
+ * Paginated stream response for large datasets
43
+ */
44
+ export interface PaginatedStreamResponse<T = unknown> extends StreamResponse<T[]> {
45
+ /** Pagination metadata */
46
+ pagination: {
47
+ /** Total items available */
48
+ total: number;
49
+ /** Current page number */
50
+ page: number;
51
+ /** Items per page */
52
+ pageSize: number;
53
+ /** Whether more items exist */
54
+ hasMore: boolean;
55
+ };
56
+ }
57
+ /**
58
+ * Configuration for stream endpoints
59
+ */
60
+ export interface StreamEndpointConfig {
61
+ /** Unique endpoint key (like serviceKey in domain services) */
62
+ endpointKey: string;
63
+ /** Human-readable name */
64
+ name?: string;
65
+ /** Channels this endpoint manages */
66
+ channels: string[];
67
+ /** Whether endpoint is enabled */
68
+ enabled?: boolean;
69
+ /** Supported runtimes */
70
+ supportedRuntimes?: Array<'node' | 'bun' | 'deno' | 'edge'>;
71
+ }
72
+ /**
73
+ * Options for creating stream endpoints
74
+ */
75
+ export interface StreamEndpointCreateOptions {
76
+ /** Broadcaster interface */
77
+ broadcaster: StreamBroadcasterInterface;
78
+ /** Optional auth adapter */
79
+ auth?: unknown;
80
+ }
81
+ /**
82
+ * Interface for StreamBroadcaster (for dependency injection)
83
+ */
84
+ export interface StreamBroadcasterInterface {
85
+ /** Initialize event subscriptions and cleanup timer */
86
+ initialize(): void;
87
+ /** Broadcast message to a channel (fire-and-forget) */
88
+ broadcastToChannel(channel: string, message: unknown): void;
89
+ /** Send message to a specific connection */
90
+ sendToConnection(connectionId: string, message: unknown): Promise<void>;
91
+ /** Broadcast to all connections (system-wide) */
92
+ broadcastToAll(message: unknown): void;
93
+ }
94
+ /**
95
+ * Configuration for channel controllers
96
+ */
97
+ export interface ChannelControllerConfig {
98
+ /** Channel scope (e.g., 'upload', 'generate', 'system') */
99
+ scope: string;
100
+ /** Channel patterns this controller handles */
101
+ patterns: string[];
102
+ /** Whether controller is enabled */
103
+ enabled?: boolean;
104
+ }
105
+ /**
106
+ * Context passed to stream middleware
107
+ */
108
+ export interface StreamMiddlewareContext {
109
+ /** Active connection */
110
+ connection: StreamConnection;
111
+ /** Auth result for the connection */
112
+ authResult: StreamAuthResult;
113
+ /** Message being processed (if any) */
114
+ message?: StreamMessage;
115
+ /** Target channel (if any) */
116
+ channel?: string;
117
+ }
118
+ /**
119
+ * Result returned by stream middleware
120
+ */
121
+ export interface StreamMiddlewareResult {
122
+ /** Whether to continue to next middleware */
123
+ continue: boolean;
124
+ /** Updated context (merged with current) */
125
+ context?: Partial<StreamMiddlewareContext>;
126
+ /** Error to return (if continue is false) */
127
+ error?: PackageErrorLike;
128
+ }
129
+ /**
130
+ * Stream middleware function signature
131
+ */
132
+ export type StreamMiddleware = (context: StreamMiddlewareContext) => Promise<StreamMiddlewareResult>;
133
+ /**
134
+ * Rate limit middleware configuration
135
+ */
136
+ export interface RateLimitConfig {
137
+ /** Max connections per IP */
138
+ maxConnectionsPerIp?: number;
139
+ /** Max messages per second per connection */
140
+ maxMessagesPerSecond?: number;
141
+ /** Window size in ms */
142
+ windowMs?: number;
143
+ }
144
+ /**
145
+ * Entry for registering stream endpoints
146
+ */
147
+ export interface StreamEndpointEntry {
148
+ /** Endpoint class with static create() */
149
+ endpoint: {
150
+ endpointKey: string;
151
+ create(config: StreamEndpointConfig, options: StreamEndpointCreateOptions): Promise<unknown>;
152
+ };
153
+ /** Endpoint configuration overrides */
154
+ config: Partial<StreamEndpointConfig>;
155
+ }
156
+ /**
157
+ * Configuration for StreamRegistry initialization
158
+ */
159
+ export interface StreamRegistryConfig {
160
+ /** Stream endpoints to register */
161
+ endpoints: StreamEndpointEntry[];
162
+ /** Broadcaster instance */
163
+ broadcaster: StreamBroadcasterInterface;
164
+ }