@plyaz/types 1.35.4 → 1.36.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.
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
* Files Domain Types
|
|
3
3
|
*
|
|
4
4
|
* Core domain types for files/media service.
|
|
5
|
+
* Schemas are the single source of truth for DB types.
|
|
5
6
|
*/
|
|
6
|
-
export {
|
|
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';
|
|
8
|
+
export { type FilesEntity, type FilesFrontendServiceConfig, type FilesDomainServiceConfig, type SingleUploadEventPayload, type BulkUploadEventPayload, type FileUploadedEventPayload, type FileBulkUploadedEventPayload, type FilesUploadEventPayload, type FileDocumentGeneratedEventPayload, } from './types';
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Files Domain Schemas
|
|
3
|
+
*
|
|
4
|
+
* Zod validation schemas for files/media operations.
|
|
5
|
+
* Single source of truth - types are inferred from schemas.
|
|
6
|
+
*
|
|
7
|
+
* Used by:
|
|
8
|
+
* - FilesValidator in @plyaz/core for validation
|
|
9
|
+
* - FilesRepository for type safety
|
|
10
|
+
* - FilesMapper for transformations
|
|
11
|
+
*/
|
|
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
|
+
/**
|
|
16
|
+
* Media type enum - matches media.type DB ENUM
|
|
17
|
+
* Note: DB only has IMAGE, VIDEO, AUDIO, DOCUMENT (no OTHER)
|
|
18
|
+
* Use this for DB operations and validation
|
|
19
|
+
*/
|
|
20
|
+
export declare const MediaTypeSchema: z.ZodEnum<{
|
|
21
|
+
IMAGE: "IMAGE";
|
|
22
|
+
VIDEO: "VIDEO";
|
|
23
|
+
AUDIO: "AUDIO";
|
|
24
|
+
DOCUMENT: "DOCUMENT";
|
|
25
|
+
}>;
|
|
26
|
+
export type MediaType = z.infer<typeof MediaTypeSchema>;
|
|
27
|
+
/**
|
|
28
|
+
* 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
|
|
31
|
+
*/
|
|
32
|
+
export declare const FileTypeSchema: z.ZodEnum<{
|
|
33
|
+
IMAGE: "IMAGE";
|
|
34
|
+
VIDEO: "VIDEO";
|
|
35
|
+
AUDIO: "AUDIO";
|
|
36
|
+
DOCUMENT: "DOCUMENT";
|
|
37
|
+
OTHER: "OTHER";
|
|
38
|
+
}>;
|
|
39
|
+
export type FileType = z.infer<typeof FileTypeSchema>;
|
|
40
|
+
/**
|
|
41
|
+
* Access level schema - matches DB constraints
|
|
42
|
+
*/
|
|
43
|
+
export declare const MediaAccessLevelSchema: z.ZodNullable<z.ZodEnum<{
|
|
44
|
+
public: "public";
|
|
45
|
+
private: "private";
|
|
46
|
+
protected: "protected";
|
|
47
|
+
}>>;
|
|
48
|
+
export type MediaAccessLevel = z.infer<typeof MediaAccessLevelSchema>;
|
|
49
|
+
/**
|
|
50
|
+
* Full media database row schema
|
|
51
|
+
* Includes all fields including auto-generated ones
|
|
52
|
+
* Used by FilesRepository for query results
|
|
53
|
+
*/
|
|
54
|
+
export declare const FilesDatabaseRowSchema: z.ZodObject<{
|
|
55
|
+
id: z.ZodString;
|
|
56
|
+
created_at: z.ZodString;
|
|
57
|
+
updated_at: z.ZodString;
|
|
58
|
+
deleted_at: z.ZodNullable<z.ZodString>;
|
|
59
|
+
user_id: z.ZodString;
|
|
60
|
+
type: z.ZodString;
|
|
61
|
+
filename: z.ZodString;
|
|
62
|
+
original_filename: z.ZodString;
|
|
63
|
+
mime_type: z.ZodString;
|
|
64
|
+
file_size: z.ZodUnion<readonly [z.ZodBigInt, z.ZodNumber]>;
|
|
65
|
+
storage_path: z.ZodString;
|
|
66
|
+
cdn_url: z.ZodNullable<z.ZodString>;
|
|
67
|
+
width: z.ZodNullable<z.ZodNumber>;
|
|
68
|
+
height: z.ZodNullable<z.ZodNumber>;
|
|
69
|
+
duration: z.ZodNullable<z.ZodNumber>;
|
|
70
|
+
is_virus_scanned: z.ZodBoolean;
|
|
71
|
+
virus_scan_result: z.ZodNullable<z.ZodString>;
|
|
72
|
+
metadata: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
73
|
+
variants: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
74
|
+
entity_type: z.ZodNullable<z.ZodString>;
|
|
75
|
+
entity_id: z.ZodNullable<z.ZodString>;
|
|
76
|
+
access_level: z.ZodNullable<z.ZodString>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
/**
|
|
79
|
+
* Database row type - inferred from schema
|
|
80
|
+
* Used by FilesRepository, mapped to FilesEntity by FilesMapper
|
|
81
|
+
*/
|
|
82
|
+
export type FilesDatabaseRow = z.infer<typeof FilesDatabaseRowSchema>;
|
|
83
|
+
/**
|
|
84
|
+
* Schema for creating a media record in the database
|
|
85
|
+
* Validates data before repository.create()
|
|
86
|
+
*
|
|
87
|
+
* Auto-generated fields (id, created_at, updated_at, deleted_at)
|
|
88
|
+
* are handled by the repository.
|
|
89
|
+
*/
|
|
90
|
+
export declare const CreateMediaSchema: z.ZodObject<{
|
|
91
|
+
user_id: z.ZodDefault<z.ZodString>;
|
|
92
|
+
type: z.ZodDefault<z.ZodEnum<{
|
|
93
|
+
IMAGE: "IMAGE";
|
|
94
|
+
VIDEO: "VIDEO";
|
|
95
|
+
AUDIO: "AUDIO";
|
|
96
|
+
DOCUMENT: "DOCUMENT";
|
|
97
|
+
}>>;
|
|
98
|
+
filename: z.ZodString;
|
|
99
|
+
original_filename: z.ZodString;
|
|
100
|
+
mime_type: z.ZodString;
|
|
101
|
+
file_size: z.ZodUnion<readonly [z.ZodBigInt, z.ZodNumber]>;
|
|
102
|
+
storage_path: z.ZodString;
|
|
103
|
+
cdn_url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
104
|
+
width: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
105
|
+
height: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
106
|
+
duration: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
107
|
+
is_virus_scanned: z.ZodDefault<z.ZodBoolean>;
|
|
108
|
+
virus_scan_result: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
109
|
+
metadata: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
110
|
+
variants: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
111
|
+
entity_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
112
|
+
entity_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
113
|
+
access_level: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
|
|
114
|
+
public: "public";
|
|
115
|
+
private: "private";
|
|
116
|
+
protected: "protected";
|
|
117
|
+
}>>>;
|
|
118
|
+
}, 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>;
|
|
123
|
+
/**
|
|
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
|
|
130
|
+
* All fields optional
|
|
131
|
+
*/
|
|
132
|
+
export declare const PatchMediaSchema: z.ZodObject<{
|
|
133
|
+
user_id: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
134
|
+
type: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
135
|
+
IMAGE: "IMAGE";
|
|
136
|
+
VIDEO: "VIDEO";
|
|
137
|
+
AUDIO: "AUDIO";
|
|
138
|
+
DOCUMENT: "DOCUMENT";
|
|
139
|
+
}>>>;
|
|
140
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
141
|
+
original_filename: z.ZodOptional<z.ZodString>;
|
|
142
|
+
mime_type: z.ZodOptional<z.ZodString>;
|
|
143
|
+
file_size: z.ZodOptional<z.ZodUnion<readonly [z.ZodBigInt, z.ZodNumber]>>;
|
|
144
|
+
storage_path: z.ZodOptional<z.ZodString>;
|
|
145
|
+
cdn_url: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodString>>>;
|
|
146
|
+
width: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodNumber>>>;
|
|
147
|
+
height: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodNumber>>>;
|
|
148
|
+
duration: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodNumber>>>;
|
|
149
|
+
is_virus_scanned: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
150
|
+
virus_scan_result: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodString>>>;
|
|
151
|
+
metadata: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
152
|
+
variants: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
153
|
+
entity_type: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodString>>>;
|
|
154
|
+
entity_id: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodString>>>;
|
|
155
|
+
access_level: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodEnum<{
|
|
156
|
+
public: "public";
|
|
157
|
+
private: "private";
|
|
158
|
+
protected: "protected";
|
|
159
|
+
}>>>>;
|
|
160
|
+
}, z.core.$strip>;
|
|
161
|
+
export type PatchMediaInput = z.input<typeof PatchMediaSchema>;
|
|
162
|
+
export type PatchMediaOutput = z.output<typeof PatchMediaSchema>;
|
|
163
|
+
/**
|
|
164
|
+
* Full media_variants database row schema
|
|
165
|
+
*/
|
|
166
|
+
export declare const MediaVariantsDatabaseRowSchema: z.ZodObject<{
|
|
167
|
+
id: z.ZodString;
|
|
168
|
+
media_id: z.ZodString;
|
|
169
|
+
variant_name: z.ZodString;
|
|
170
|
+
file_path: z.ZodString;
|
|
171
|
+
cdn_url: z.ZodNullable<z.ZodString>;
|
|
172
|
+
width: z.ZodNullable<z.ZodNumber>;
|
|
173
|
+
height: z.ZodNullable<z.ZodNumber>;
|
|
174
|
+
file_size: z.ZodNullable<z.ZodNumber>;
|
|
175
|
+
created_at: z.ZodString;
|
|
176
|
+
}, z.core.$strip>;
|
|
177
|
+
export type MediaVariantsDatabaseRow = z.infer<typeof MediaVariantsDatabaseRowSchema>;
|
|
178
|
+
/**
|
|
179
|
+
* Schema for creating a media variant record
|
|
180
|
+
*/
|
|
181
|
+
export declare const CreateMediaVariantSchema: z.ZodObject<{
|
|
182
|
+
file_size: z.ZodNullable<z.ZodNumber>;
|
|
183
|
+
cdn_url: z.ZodNullable<z.ZodString>;
|
|
184
|
+
width: z.ZodNullable<z.ZodNumber>;
|
|
185
|
+
height: z.ZodNullable<z.ZodNumber>;
|
|
186
|
+
media_id: z.ZodString;
|
|
187
|
+
variant_name: z.ZodString;
|
|
188
|
+
file_path: z.ZodString;
|
|
189
|
+
}, z.core.$strip>;
|
|
190
|
+
export type MediaVariantsCreateInput = z.input<typeof CreateMediaVariantSchema>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Files Domain Types
|
|
3
3
|
*
|
|
4
|
-
* Domain entity, service config, and
|
|
4
|
+
* Domain entity, service config, and event types for files/media.
|
|
5
|
+
*
|
|
6
|
+
* Database types and validation schemas are in ./schemas.ts (single source of truth)
|
|
5
7
|
* Store types are in @plyaz/types/store/files.
|
|
6
8
|
* API types are in @plyaz/types/api/endpoints/files.
|
|
7
9
|
*/
|
|
@@ -10,18 +12,8 @@ import type { CoreServiceInitConfig } from '../../init';
|
|
|
10
12
|
import type { CoreInjectedServices } from '../types';
|
|
11
13
|
import type { CoreBaseFrontendServiceConfig } from '../../frontend';
|
|
12
14
|
import type { FilesFrontendStoreData, FilesFrontendStoreSlice } from '../../../store/files';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* File type enum - for categorization in domain
|
|
16
|
-
*/
|
|
17
|
-
export declare const FileTypeSchema: z.ZodEnum<{
|
|
18
|
-
IMAGE: "IMAGE";
|
|
19
|
-
VIDEO: "VIDEO";
|
|
20
|
-
DOCUMENT: "DOCUMENT";
|
|
21
|
-
AUDIO: "AUDIO";
|
|
22
|
-
OTHER: "OTHER";
|
|
23
|
-
}>;
|
|
24
|
-
export type FileType = z.infer<typeof FileTypeSchema>;
|
|
15
|
+
export type { FileType, MediaType, FilesDatabaseRow, FilesCreateInput, MediaVariantsDatabaseRow, MediaVariantsCreateInput, } from './schemas';
|
|
16
|
+
import type { FileType } from './schemas';
|
|
25
17
|
/**
|
|
26
18
|
* Files domain entity - maps from API response + additional domain properties
|
|
27
19
|
*/
|
|
@@ -76,60 +68,6 @@ export interface FilesDomainServiceConfig extends CoreServiceInitConfig {
|
|
|
76
68
|
throwOnRepositoryError?: boolean;
|
|
77
69
|
emitEvents?: boolean;
|
|
78
70
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Database row from media table
|
|
81
|
-
* Used by FilesRepository, mapped to FilesEntity by FilesMapper
|
|
82
|
-
*/
|
|
83
|
-
export interface FilesDatabaseRow {
|
|
84
|
-
id: string;
|
|
85
|
-
user_id: string;
|
|
86
|
-
type: string;
|
|
87
|
-
filename: string;
|
|
88
|
-
original_filename: string;
|
|
89
|
-
mime_type: string;
|
|
90
|
-
file_size: bigint | number;
|
|
91
|
-
storage_path: string;
|
|
92
|
-
cdn_url: string | null;
|
|
93
|
-
width: number | null;
|
|
94
|
-
height: number | null;
|
|
95
|
-
duration: number | null;
|
|
96
|
-
is_virus_scanned: boolean;
|
|
97
|
-
virus_scan_result: string | null;
|
|
98
|
-
metadata: Record<string, unknown> | null;
|
|
99
|
-
variants: Record<string, unknown> | null;
|
|
100
|
-
entity_type: string | null;
|
|
101
|
-
entity_id: string | null;
|
|
102
|
-
access_level: string | null;
|
|
103
|
-
created_at: string;
|
|
104
|
-
updated_at: string;
|
|
105
|
-
deleted_at: string | null;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Create input for Files entity (excludes auto-generated fields)
|
|
109
|
-
* Used internally by repository when creating records from upload responses
|
|
110
|
-
*/
|
|
111
|
-
export type FilesCreateInput = Omit<FilesDatabaseRow, 'id' | 'created_at' | 'updated_at' | 'deleted_at'>;
|
|
112
|
-
/**
|
|
113
|
-
* Database row from media_variants table
|
|
114
|
-
* Used by MediaVariantsRepository for normalized variant storage
|
|
115
|
-
*
|
|
116
|
-
* Variant names: 'thumbnail', 'mobile', 'desktop', '4k'
|
|
117
|
-
*/
|
|
118
|
-
export interface MediaVariantsDatabaseRow {
|
|
119
|
-
id: string;
|
|
120
|
-
media_id: string;
|
|
121
|
-
variant_name: string;
|
|
122
|
-
file_path: string;
|
|
123
|
-
cdn_url: string | null;
|
|
124
|
-
width: number | null;
|
|
125
|
-
height: number | null;
|
|
126
|
-
file_size: number | null;
|
|
127
|
-
created_at: string;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Create input for media variant (excludes auto-generated fields)
|
|
131
|
-
*/
|
|
132
|
-
export type MediaVariantsCreateInput = Omit<MediaVariantsDatabaseRow, 'id' | 'created_at'>;
|
|
133
71
|
/**
|
|
134
72
|
* Event payload for single file upload
|
|
135
73
|
* Used by files:upload:uploaded event
|
|
@@ -47,9 +47,9 @@ export declare const QueryExampleSchema: z.ZodObject<{
|
|
|
47
47
|
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
48
48
|
sort_by: z.ZodDefault<z.ZodEnum<{
|
|
49
49
|
name: "name";
|
|
50
|
-
amount: "amount";
|
|
51
50
|
created_at: "created_at";
|
|
52
51
|
updated_at: "updated_at";
|
|
52
|
+
amount: "amount";
|
|
53
53
|
}>>;
|
|
54
54
|
sort_order: z.ZodDefault<z.ZodEnum<{
|
|
55
55
|
asc: "asc";
|
package/package.json
CHANGED