@plyaz/types 1.31.1 → 1.33.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.
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Core domain types for files/media service.
|
|
5
5
|
*/
|
|
6
|
-
export { FileTypeSchema, type FileType, type FilesEntity, type FilesFrontendServiceConfig, type FilesDomainServiceConfig, type FilesDatabaseRow, type FilesCreateInput, type MediaVariantsDatabaseRow, type MediaVariantsCreateInput, type SingleUploadEventPayload, type BulkUploadEventPayload, } from './types';
|
|
6
|
+
export { FileTypeSchema, type FileType, type FilesEntity, type FilesFrontendServiceConfig, type FilesDomainServiceConfig, type FilesDatabaseRow, type FilesCreateInput, type MediaVariantsDatabaseRow, type MediaVariantsCreateInput, type SingleUploadEventPayload, type BulkUploadEventPayload, type FileUploadedEventPayload, type FileBulkUploadedEventPayload, type FilesUploadEventPayload, type FileDocumentGeneratedEventPayload, } from './types';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Store types are in @plyaz/types/store/files.
|
|
6
6
|
* API types are in @plyaz/types/api/endpoints/files.
|
|
7
7
|
*/
|
|
8
|
-
import type { FileVariant } from '../../../api/endpoints/files
|
|
8
|
+
import type { FileVariant, UploadFileResponse, UploadFilesResponse, GenerateDocumentRequest, GenerateDocumentResponse } from '../../../api/endpoints/files';
|
|
9
9
|
import type { CoreServiceInitConfig } from '../../init';
|
|
10
10
|
import type { CoreInjectedServices } from '../types';
|
|
11
11
|
import type { CoreBaseFrontendServiceConfig } from '../../frontend';
|
|
@@ -165,3 +165,31 @@ export interface BulkUploadEventPayload {
|
|
|
165
165
|
results?: SingleUploadEventPayload['result'][];
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Frontend event payload for single file upload
|
|
170
|
+
* Used by files:upload:uploaded event (when bulk=false)
|
|
171
|
+
*/
|
|
172
|
+
export interface FileUploadedEventPayload {
|
|
173
|
+
result: UploadFileResponse;
|
|
174
|
+
bulk?: false;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Frontend event payload for bulk file upload
|
|
178
|
+
* Used by files:upload:uploaded event (when bulk=true)
|
|
179
|
+
*/
|
|
180
|
+
export interface FileBulkUploadedEventPayload {
|
|
181
|
+
result: UploadFilesResponse;
|
|
182
|
+
bulk: true;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Union type for files:upload:uploaded event payload
|
|
186
|
+
*/
|
|
187
|
+
export type FilesUploadEventPayload = FileUploadedEventPayload | FileBulkUploadedEventPayload;
|
|
188
|
+
/**
|
|
189
|
+
* Frontend event payload for document generation
|
|
190
|
+
* Used by files:document:generated event
|
|
191
|
+
*/
|
|
192
|
+
export interface FileDocumentGeneratedEventPayload {
|
|
193
|
+
result: GenerateDocumentResponse;
|
|
194
|
+
request: GenerateDocumentRequest;
|
|
195
|
+
}
|
|
@@ -19,4 +19,4 @@
|
|
|
19
19
|
*/
|
|
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
|
-
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, } from './payloads';
|
|
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';
|
|
@@ -694,6 +694,25 @@ export interface EventPersistenceConfig<TPayload = unknown, TItem = unknown> {
|
|
|
694
694
|
/** Optional: validate item before persisting */
|
|
695
695
|
validate?: (item: TItem) => boolean;
|
|
696
696
|
}
|
|
697
|
+
/**
|
|
698
|
+
* Configuration for persist operations (internal to BackendEventPersistenceHandler)
|
|
699
|
+
* Reduces parameter count by grouping related options
|
|
700
|
+
*
|
|
701
|
+
* @typeParam TRepository - Repository type for database operations
|
|
702
|
+
* @typeParam TMapper - Mapper type for transforming items to DB rows
|
|
703
|
+
* @typeParam TItem - Item type extracted from event payload
|
|
704
|
+
* @typeParam TDbRow - Database row type
|
|
705
|
+
*/
|
|
706
|
+
export interface PersistOperationConfig<TRepository, TMapper, TItem, TDbRow> {
|
|
707
|
+
repository: TRepository;
|
|
708
|
+
mapper: TMapper;
|
|
709
|
+
mapToDbRow: (mapper: TMapper, item: TItem) => TDbRow;
|
|
710
|
+
createRecord: (repository: TRepository, dbRow: TDbRow) => Promise<unknown>;
|
|
711
|
+
validate?: (item: TItem) => boolean;
|
|
712
|
+
getUniqueKey?: (item: TItem) => string;
|
|
713
|
+
eventName: string;
|
|
714
|
+
verbose?: boolean;
|
|
715
|
+
}
|
|
697
716
|
/**
|
|
698
717
|
* Domain persistence handler configuration
|
|
699
718
|
* Used by BackendEventPersistenceHandler to register event-to-DB persistence
|
|
@@ -738,3 +757,74 @@ export interface DomainPersistenceConfig<TRepository = unknown, TMapper = unknow
|
|
|
738
757
|
/** Enable verbose logging */
|
|
739
758
|
verbose?: boolean;
|
|
740
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Frontend event handler configuration
|
|
762
|
+
* Defines how to extract payload and update store for a specific event
|
|
763
|
+
*
|
|
764
|
+
* @typeParam TStore - Store slice type
|
|
765
|
+
* @typeParam TItem - Item type extracted from payload
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```typescript
|
|
769
|
+
* const uploadedHandler: FrontendEventHandlerConfig<FilesStoreSlice, FilesEntity> = {
|
|
770
|
+
* extractPayload: (payload) => payload.result,
|
|
771
|
+
* updateStore: async (store, item) => {
|
|
772
|
+
* if (Array.isArray(item)) {
|
|
773
|
+
* store.addUploads(item);
|
|
774
|
+
* } else {
|
|
775
|
+
* store.addUpload(item);
|
|
776
|
+
* }
|
|
777
|
+
* },
|
|
778
|
+
* isBulk: false,
|
|
779
|
+
* };
|
|
780
|
+
* ```
|
|
781
|
+
*/
|
|
782
|
+
/**
|
|
783
|
+
* Frontend event handler configuration
|
|
784
|
+
*
|
|
785
|
+
* Simple: just a callback that receives store and payload.
|
|
786
|
+
* Do whatever you need - set loading state, add data, etc.
|
|
787
|
+
*
|
|
788
|
+
* @typeParam TStore - Store slice type
|
|
789
|
+
* @typeParam TPayload - Event payload type
|
|
790
|
+
*/
|
|
791
|
+
export interface FrontendEventHandlerConfig<TStore = unknown, TPayload = unknown> {
|
|
792
|
+
/** Handle the event - receives store and typed payload */
|
|
793
|
+
handler: (store: TStore, payload: TPayload) => void | Promise<void>;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Domain frontend event handler configuration
|
|
797
|
+
* Used by FrontendEventPersistenceHandler to register event handlers
|
|
798
|
+
*
|
|
799
|
+
* @typeParam TStore - Store slice type (e.g., FilesFrontendStoreSlice)
|
|
800
|
+
* @typeParam TPayload - Event payload type
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* ```typescript
|
|
804
|
+
* FrontendEventPersistenceHandler.register<FilesFrontendStoreSlice, FilesUploadEventPayload>({
|
|
805
|
+
* domain: 'files',
|
|
806
|
+
* events: {
|
|
807
|
+
* 'files:upload:uploading': {
|
|
808
|
+
* handler: (store) => store.setUploading(true),
|
|
809
|
+
* },
|
|
810
|
+
* 'files:upload:uploaded': {
|
|
811
|
+
* handler: (store, payload) => {
|
|
812
|
+
* store.setUploading(false);
|
|
813
|
+
* store.addUpload(FilesMapper.toDomain(payload.result));
|
|
814
|
+
* },
|
|
815
|
+
* },
|
|
816
|
+
* },
|
|
817
|
+
* getStore: () => Core._rootStore?.getState().files,
|
|
818
|
+
* });
|
|
819
|
+
* ```
|
|
820
|
+
*/
|
|
821
|
+
export interface DomainFrontendEventConfig<TStore = unknown, TPayload = unknown> {
|
|
822
|
+
/** Domain name (e.g., 'files', 'notifications') */
|
|
823
|
+
domain: string;
|
|
824
|
+
/** Event configurations keyed by event name */
|
|
825
|
+
events: Record<string, FrontendEventHandlerConfig<TStore, TPayload>>;
|
|
826
|
+
/** Get store slice from root store (called per event, safe for SSR) */
|
|
827
|
+
getStore: () => TStore | undefined;
|
|
828
|
+
/** Enable verbose logging */
|
|
829
|
+
verbose?: boolean;
|
|
830
|
+
}
|
|
@@ -73,13 +73,13 @@ export interface FilesFrontendStoreData {
|
|
|
73
73
|
* Files are immutable once uploaded - only metadata changes via storage service.
|
|
74
74
|
*/
|
|
75
75
|
export interface FilesFrontendStoreActions extends CoreBaseFrontendStore<FilesFrontendStoreData> {
|
|
76
|
-
addFile: (file: FilesEntity) => void;
|
|
76
|
+
addFile: (file: FilesEntity | FilesEntity[]) => void;
|
|
77
77
|
removeFile: (id: string) => void;
|
|
78
78
|
clearFiles: () => void;
|
|
79
|
-
addUpload: (upload: FilesEntity) => void;
|
|
79
|
+
addUpload: (upload: FilesEntity | FilesEntity[]) => void;
|
|
80
80
|
removeUpload: (id: string) => void;
|
|
81
81
|
clearUploads: () => void;
|
|
82
|
-
addGenerated: (file: GeneratedFileItem) => void;
|
|
82
|
+
addGenerated: (file: GeneratedFileItem | GeneratedFileItem[]) => void;
|
|
83
83
|
removeGenerated: (id: string) => void;
|
|
84
84
|
clearGenerated: () => void;
|
|
85
85
|
setLoading: (isLoading: boolean) => void;
|
package/package.json
CHANGED