@plyaz/types 1.39.6 → 1.39.7
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/dist/core/frameworks/express-types.d.ts +94 -0
- package/dist/core/frameworks/file-types.d.ts +34 -0
- package/dist/core/frameworks/index.d.ts +12 -0
- package/dist/core/frameworks/nextjs-types.d.ts +121 -0
- package/dist/core/frameworks/route-types.d.ts +70 -0
- package/dist/core/hooks/files/delete.d.ts +20 -0
- package/dist/core/hooks/files/download.d.ts +36 -0
- package/dist/core/hooks/files/file.d.ts +21 -0
- package/dist/core/hooks/files/index.d.ts +10 -0
- package/dist/core/hooks/files/progress.d.ts +68 -0
- package/dist/core/hooks/files/upload.d.ts +97 -0
- package/dist/core/hooks/index.d.ts +7 -0
- package/dist/core/index.cjs +53 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +50 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/utils/index.d.ts +4 -0
- package/dist/core/utils/types.d.ts +33 -0
- package/dist/index.cjs +53 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Express Framework Types
|
|
3
|
+
*
|
|
4
|
+
* Types for Express route factory in @plyaz/core/frameworks/express.
|
|
5
|
+
*/
|
|
6
|
+
import type { RouteContext, HandlersTypeMap, MethodHandlerTypes } from './route-types';
|
|
7
|
+
import type { CoreInjectedServices } from '../domain/types';
|
|
8
|
+
/**
|
|
9
|
+
* Minimal Express Request interface for compatibility
|
|
10
|
+
* Avoids direct dependency on @types/express
|
|
11
|
+
*/
|
|
12
|
+
export interface CoreExpressRequest {
|
|
13
|
+
params: Record<string, string>;
|
|
14
|
+
query: Record<string, string | string[] | undefined>;
|
|
15
|
+
body: unknown;
|
|
16
|
+
headers: Record<string, string | string[] | undefined>;
|
|
17
|
+
method: string;
|
|
18
|
+
path: string;
|
|
19
|
+
url: string;
|
|
20
|
+
originalUrl: string;
|
|
21
|
+
get(name: string): string | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Minimal Express Response interface for compatibility
|
|
25
|
+
*/
|
|
26
|
+
export interface CoreExpressResponse {
|
|
27
|
+
status(code: number): this;
|
|
28
|
+
json(data: unknown): this;
|
|
29
|
+
send(data?: unknown): this;
|
|
30
|
+
set(name: string, value: string): this;
|
|
31
|
+
setHeader(name: string, value: string): this;
|
|
32
|
+
end(): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Minimal Express NextFunction interface
|
|
36
|
+
*/
|
|
37
|
+
export type CoreExpressNextFunction = (err?: unknown) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Express-specific route context
|
|
40
|
+
*/
|
|
41
|
+
export interface CoreExpressRouteContext<TParams extends Record<string, string> = Record<string, string>, TQuery extends Record<string, string> = Record<string, string>, TBody = unknown> extends RouteContext<TParams, TQuery> {
|
|
42
|
+
/** Parsed request body */
|
|
43
|
+
body: TBody;
|
|
44
|
+
/** Express request object */
|
|
45
|
+
req: CoreExpressRequest;
|
|
46
|
+
/** Express response object */
|
|
47
|
+
res: CoreExpressResponse;
|
|
48
|
+
/** Injected Core services (when injectServices is true) */
|
|
49
|
+
services?: CoreInjectedServices;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Express route handler function type
|
|
53
|
+
*/
|
|
54
|
+
export type CoreExpressRouteHandler<TService, TResult = unknown, TTypes extends MethodHandlerTypes = MethodHandlerTypes> = (service: TService, ctx: CoreExpressRouteContext<TTypes['params'] extends Record<string, string> ? TTypes['params'] : Record<string, string>, TTypes['query'] extends Record<string, string> ? TTypes['query'] : Record<string, string>, TTypes['body']>) => Promise<TResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Configuration for Express route factory
|
|
57
|
+
*/
|
|
58
|
+
export interface CoreExpressRouteConfig<TService, THandlerTypes extends HandlersTypeMap = HandlersTypeMap> {
|
|
59
|
+
/** Service name (registered in ServiceRegistry) or factory function */
|
|
60
|
+
service: string | (() => Promise<TService>);
|
|
61
|
+
/** Handlers for each HTTP method */
|
|
62
|
+
handlers: {
|
|
63
|
+
[K in keyof THandlerTypes & keyof HandlersTypeMap]?: CoreExpressRouteHandler<TService, THandlerTypes[K] extends {
|
|
64
|
+
response: infer R;
|
|
65
|
+
} ? R : unknown, THandlerTypes[K] extends MethodHandlerTypes ? THandlerTypes[K] : MethodHandlerTypes>;
|
|
66
|
+
};
|
|
67
|
+
/** Function to get Core instance (for service resolution) */
|
|
68
|
+
getCore?: () => Promise<unknown>;
|
|
69
|
+
/** Custom success message or function */
|
|
70
|
+
successMessage?: string | ((method: string) => string);
|
|
71
|
+
/** Error source identifier for error handling */
|
|
72
|
+
errorSource?: string;
|
|
73
|
+
/** Whether to inject Core services into context (default: false) */
|
|
74
|
+
injectServices?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Express middleware function type
|
|
78
|
+
*/
|
|
79
|
+
export type CoreExpressMiddleware = (req: CoreExpressRequest, res: CoreExpressResponse, next: CoreExpressNextFunction) => void | Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Return type from createExpressRoute
|
|
82
|
+
*/
|
|
83
|
+
export interface CoreExpressRouteExports {
|
|
84
|
+
/** Express router middleware for all configured methods */
|
|
85
|
+
handler: CoreExpressMiddleware;
|
|
86
|
+
/** Individual method handlers (for manual mounting) */
|
|
87
|
+
GET?: CoreExpressMiddleware;
|
|
88
|
+
POST?: CoreExpressMiddleware;
|
|
89
|
+
PUT?: CoreExpressMiddleware;
|
|
90
|
+
PATCH?: CoreExpressMiddleware;
|
|
91
|
+
DELETE?: CoreExpressMiddleware;
|
|
92
|
+
OPTIONS?: CoreExpressMiddleware;
|
|
93
|
+
HEAD?: CoreExpressMiddleware;
|
|
94
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Operation Types
|
|
3
|
+
*
|
|
4
|
+
* Types for file operation utilities (browser and Node.js).
|
|
5
|
+
* Used by @plyaz/core and @plyaz/storage packages.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Parsed file key components
|
|
9
|
+
*/
|
|
10
|
+
export interface ParsedFileKey {
|
|
11
|
+
/** The entity type (e.g., 'user', 'organization') */
|
|
12
|
+
entityType?: string;
|
|
13
|
+
/** The entity ID */
|
|
14
|
+
entityId?: string;
|
|
15
|
+
/** The file category (e.g., 'documents', 'images') */
|
|
16
|
+
category?: string;
|
|
17
|
+
/** The filename with extension */
|
|
18
|
+
filename?: string;
|
|
19
|
+
/** The full original key */
|
|
20
|
+
raw: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Common MIME types and their extensions
|
|
24
|
+
*/
|
|
25
|
+
export declare const MIME_TYPE_EXTENSIONS: Record<string, string>;
|
|
26
|
+
/**
|
|
27
|
+
* File size units
|
|
28
|
+
*/
|
|
29
|
+
export declare const FILE_SIZE_UNITS: readonly ["Bytes", "KB", "MB", "GB", "TB", "PB"];
|
|
30
|
+
export type FileSizeUnit = (typeof FILE_SIZE_UNITS)[number];
|
|
31
|
+
/**
|
|
32
|
+
* Multipliers for file size units
|
|
33
|
+
*/
|
|
34
|
+
export declare const FILE_SIZE_MULTIPLIERS: Record<string, number>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework Types
|
|
3
|
+
*
|
|
4
|
+
* Types for @plyaz/core framework adapters (Next.js, Express, NestJS).
|
|
5
|
+
* Used by route factories and file operation utilities.
|
|
6
|
+
*/
|
|
7
|
+
export type { RouteContext, RouteHandler, RouteHandlerConfig, MethodHandlerTypes, HandlersTypeMap, HttpMethod, } from './route-types';
|
|
8
|
+
export { DEFAULT_SUCCESS_MESSAGES } from './route-types';
|
|
9
|
+
export type { CoreNextRequestCompat, CoreNextRouteContext, CoreGenericRouteHandler, CoreNextJSRouteContext, CoreGetMethodTypes, CoreNextJSRouteHandler, CoreNextJSRouteConfig, CoreNextJSRouteExports, CorePlyazNextConfigOptions, CorePlyazNextConfig, } from './nextjs-types';
|
|
10
|
+
export type { CoreExpressRequest, CoreExpressResponse, CoreExpressNextFunction, CoreExpressRouteContext, CoreExpressRouteHandler, CoreExpressRouteConfig, CoreExpressMiddleware, CoreExpressRouteExports, } from './express-types';
|
|
11
|
+
export type { ParsedFileKey, FileSizeUnit } from './file-types';
|
|
12
|
+
export { MIME_TYPE_EXTENSIONS, FILE_SIZE_UNITS, FILE_SIZE_MULTIPLIERS } from './file-types';
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js Framework Types
|
|
3
|
+
*
|
|
4
|
+
* Types for @plyaz/core Next.js framework adapters.
|
|
5
|
+
* Used by route factories and config helpers.
|
|
6
|
+
*/
|
|
7
|
+
import type { NextConfig } from 'next';
|
|
8
|
+
import type { RouteContext, MethodHandlerTypes, HandlersTypeMap } from './route-types';
|
|
9
|
+
import type { CoreInjectedServices } from '../domain/types';
|
|
10
|
+
/**
|
|
11
|
+
* NextRequest compatible type - uses global Request to avoid version conflicts between packages.
|
|
12
|
+
* The actual runtime type will be NextRequest from next/server.
|
|
13
|
+
* This avoids issues where different packages have different Next.js versions installed.
|
|
14
|
+
*/
|
|
15
|
+
export type CoreNextRequestCompat = Request & {
|
|
16
|
+
nextUrl: URL & {
|
|
17
|
+
searchParams: URLSearchParams;
|
|
18
|
+
};
|
|
19
|
+
cookies: unknown;
|
|
20
|
+
geo?: unknown;
|
|
21
|
+
ip?: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Next.js App Router route context shape.
|
|
25
|
+
* Params are async (Promise) in Next.js 15+ App Router.
|
|
26
|
+
*/
|
|
27
|
+
export interface CoreNextRouteContext<TParams extends Record<string, string> = Record<string, string>> {
|
|
28
|
+
params: Promise<TParams>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generic handler type for internal factory use.
|
|
32
|
+
* All type params use defaults (Record<string, string> for params/query, unknown for body/response).
|
|
33
|
+
*/
|
|
34
|
+
export type CoreGenericRouteHandler<TService> = CoreNextJSRouteHandler<TService>;
|
|
35
|
+
/**
|
|
36
|
+
* Extended route context for Next.js with full type support
|
|
37
|
+
*/
|
|
38
|
+
export interface CoreNextJSRouteContext<TParams extends Record<string, string> = Record<string, string>, TQuery extends Record<string, string> = Record<string, string>, TBody = unknown> extends RouteContext<TParams, TQuery> {
|
|
39
|
+
/** Parsed request body (for POST/PUT/PATCH) */
|
|
40
|
+
body: TBody;
|
|
41
|
+
/** The original Next.js request (compatible type to avoid version conflicts) */
|
|
42
|
+
request: CoreNextRequestCompat;
|
|
43
|
+
/** Injected Core services (db, cache, storage, notifications) */
|
|
44
|
+
services: CoreInjectedServices;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Extract handler type for a specific method
|
|
48
|
+
*/
|
|
49
|
+
export type CoreGetMethodTypes<TMap extends HandlersTypeMap, TMethod extends keyof HandlersTypeMap> = TMap[TMethod] extends MethodHandlerTypes ? TMap[TMethod] : MethodHandlerTypes;
|
|
50
|
+
/**
|
|
51
|
+
* Next.js specific handler type with full generics
|
|
52
|
+
*/
|
|
53
|
+
export type CoreNextJSRouteHandler<TService, TParams extends Record<string, string> = Record<string, string>, TQuery extends Record<string, string> = Record<string, string>, TBody = unknown, TResponse = unknown> = (service: TService, ctx: CoreNextJSRouteContext<TParams, TQuery, TBody>) => Promise<TResponse>;
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for Next.js route factory with full generic support
|
|
56
|
+
*/
|
|
57
|
+
export interface CoreNextJSRouteConfig<TService, THandlerTypes extends HandlersTypeMap = HandlersTypeMap> {
|
|
58
|
+
/** Service name (registered in ServiceRegistry) or factory function */
|
|
59
|
+
service: string | (() => Promise<TService>);
|
|
60
|
+
/** Handlers for each HTTP method with typed params/body/response */
|
|
61
|
+
handlers: {
|
|
62
|
+
[K in keyof THandlerTypes & keyof HandlersTypeMap]?: CoreNextJSRouteHandler<TService, CoreGetMethodTypes<THandlerTypes, K>['params'] extends Record<string, string> ? CoreGetMethodTypes<THandlerTypes, K>['params'] : Record<string, string>, CoreGetMethodTypes<THandlerTypes, K>['query'] extends Record<string, string> ? CoreGetMethodTypes<THandlerTypes, K>['query'] : Record<string, string>, CoreGetMethodTypes<THandlerTypes, K>['body'], CoreGetMethodTypes<THandlerTypes, K>['response']>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Function to get Core (ensures initialization before handling)
|
|
66
|
+
* If not provided, uses ServiceRegistry directly
|
|
67
|
+
*/
|
|
68
|
+
getCore?: () => Promise<unknown>;
|
|
69
|
+
/** Custom success message template */
|
|
70
|
+
successMessage?: string | ((method: string) => string);
|
|
71
|
+
/** Error handler source name for logging */
|
|
72
|
+
errorSource?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Whether to inject Core services into context.
|
|
75
|
+
* @default true
|
|
76
|
+
*/
|
|
77
|
+
injectServices?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Type for the exported route handlers (uses compatible Request type)
|
|
81
|
+
*/
|
|
82
|
+
export type CoreNextJSRouteExports = {
|
|
83
|
+
GET?: (request: CoreNextRequestCompat, context?: CoreNextRouteContext) => Promise<Response>;
|
|
84
|
+
POST?: (request: CoreNextRequestCompat, context?: CoreNextRouteContext) => Promise<Response>;
|
|
85
|
+
PUT?: (request: CoreNextRequestCompat, context?: CoreNextRouteContext) => Promise<Response>;
|
|
86
|
+
PATCH?: (request: CoreNextRequestCompat, context?: CoreNextRouteContext) => Promise<Response>;
|
|
87
|
+
DELETE?: (request: CoreNextRequestCompat, context?: CoreNextRouteContext) => Promise<Response>;
|
|
88
|
+
OPTIONS?: (request: CoreNextRequestCompat, context?: CoreNextRouteContext) => Promise<Response>;
|
|
89
|
+
HEAD?: (request: CoreNextRequestCompat, context?: CoreNextRouteContext) => Promise<Response>;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Options for configuring Plyaz with Next.js
|
|
93
|
+
*/
|
|
94
|
+
export interface CorePlyazNextConfigOptions {
|
|
95
|
+
/**
|
|
96
|
+
* Additional server external packages to include
|
|
97
|
+
*/
|
|
98
|
+
additionalExternalPackages?: string[];
|
|
99
|
+
/**
|
|
100
|
+
* Additional webpack client fallbacks
|
|
101
|
+
*/
|
|
102
|
+
additionalClientFallbacks?: Record<string, false>;
|
|
103
|
+
/**
|
|
104
|
+
* Additional webpack client aliases
|
|
105
|
+
*/
|
|
106
|
+
additionalClientAliases?: Record<string, false>;
|
|
107
|
+
/**
|
|
108
|
+
* Whether to disable the default external packages (advanced)
|
|
109
|
+
* @default false
|
|
110
|
+
*/
|
|
111
|
+
disableDefaultExternalPackages?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Whether to disable the default client fallbacks (advanced)
|
|
114
|
+
* @default false
|
|
115
|
+
*/
|
|
116
|
+
disableDefaultClientFallbacks?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Type helper for Next.js config with Plyaz types
|
|
120
|
+
*/
|
|
121
|
+
export type CorePlyazNextConfig = NextConfig;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route Handler Types
|
|
3
|
+
*
|
|
4
|
+
* Framework-agnostic types for route handlers used by @plyaz/core framework adapters.
|
|
5
|
+
* These types are used by Next.js, Express, and NestJS route factories.
|
|
6
|
+
*/
|
|
7
|
+
export type { HttpMethod } from '../../api/config/types';
|
|
8
|
+
/**
|
|
9
|
+
* Base route context interface (framework-agnostic)
|
|
10
|
+
*/
|
|
11
|
+
export interface RouteContext<TParams = Record<string, string>, TQuery = Record<string, string>> {
|
|
12
|
+
/** Route parameters (e.g., from /users/:id -> { id: string }) */
|
|
13
|
+
params: TParams;
|
|
14
|
+
/** Query string parameters */
|
|
15
|
+
query: TQuery;
|
|
16
|
+
/** Request headers */
|
|
17
|
+
headers: Record<string, string | undefined>;
|
|
18
|
+
/** HTTP method */
|
|
19
|
+
method: string;
|
|
20
|
+
/** Original request object (framework-specific) */
|
|
21
|
+
request: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Handler function signature for route operations
|
|
25
|
+
*/
|
|
26
|
+
export type RouteHandler<TService, TResult = unknown> = (service: TService, ctx: RouteContext) => Promise<TResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for a route with multiple HTTP method handlers
|
|
29
|
+
*/
|
|
30
|
+
export interface RouteHandlerConfig<TService> {
|
|
31
|
+
/** Service name (registered in ServiceRegistry) or factory function */
|
|
32
|
+
service: string | (() => Promise<TService>);
|
|
33
|
+
/** Handlers for each HTTP method */
|
|
34
|
+
handlers: {
|
|
35
|
+
GET?: RouteHandler<TService>;
|
|
36
|
+
POST?: RouteHandler<TService>;
|
|
37
|
+
PUT?: RouteHandler<TService>;
|
|
38
|
+
PATCH?: RouteHandler<TService>;
|
|
39
|
+
DELETE?: RouteHandler<TService>;
|
|
40
|
+
OPTIONS?: RouteHandler<TService>;
|
|
41
|
+
HEAD?: RouteHandler<TService>;
|
|
42
|
+
};
|
|
43
|
+
/** Custom success message template (default: 'Operation successful') */
|
|
44
|
+
successMessage?: string | ((method: string) => string);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Handler type definitions per HTTP method
|
|
48
|
+
*/
|
|
49
|
+
export interface MethodHandlerTypes {
|
|
50
|
+
params?: Record<string, string>;
|
|
51
|
+
query?: Record<string, string>;
|
|
52
|
+
body?: unknown;
|
|
53
|
+
response?: unknown;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Handler types map for all HTTP methods
|
|
57
|
+
*/
|
|
58
|
+
export interface HandlersTypeMap {
|
|
59
|
+
GET?: MethodHandlerTypes;
|
|
60
|
+
POST?: MethodHandlerTypes;
|
|
61
|
+
PUT?: MethodHandlerTypes;
|
|
62
|
+
PATCH?: MethodHandlerTypes;
|
|
63
|
+
DELETE?: MethodHandlerTypes;
|
|
64
|
+
OPTIONS?: MethodHandlerTypes;
|
|
65
|
+
HEAD?: MethodHandlerTypes;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Default success messages by HTTP method
|
|
69
|
+
*/
|
|
70
|
+
export declare const DEFAULT_SUCCESS_MESSAGES: Record<string, string>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Delete Hook Types
|
|
3
|
+
*
|
|
4
|
+
* Types for useFileDelete hook.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Return type for useFileDelete hook
|
|
8
|
+
*
|
|
9
|
+
* Provides file deletion operations.
|
|
10
|
+
*/
|
|
11
|
+
export interface CoreFileDeleteResult {
|
|
12
|
+
/** Delete a file by ID */
|
|
13
|
+
deleteFile: (fileId: string) => Promise<void>;
|
|
14
|
+
/** Delete multiple files by IDs */
|
|
15
|
+
deleteMultiple: (fileIds: string[], options?: {
|
|
16
|
+
soft?: boolean;
|
|
17
|
+
}) => Promise<unknown>;
|
|
18
|
+
/** Whether currently deleting */
|
|
19
|
+
isDeleting: boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Download Hook Types
|
|
3
|
+
*
|
|
4
|
+
* Types for useFileDownload hook.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Options for useFileDownload hook
|
|
8
|
+
*
|
|
9
|
+
* Note: Progress is tracked via streams (useDownloadProgress, useOverallDownloadProgress).
|
|
10
|
+
* Errors propagate to global error handling (error boundaries, global error store).
|
|
11
|
+
* Results are returned from the Promise - no callbacks needed.
|
|
12
|
+
*/
|
|
13
|
+
export interface CoreFileDownloadOptions {
|
|
14
|
+
/** Auto-trigger browser download when complete (default: true) */
|
|
15
|
+
autoDownload?: boolean;
|
|
16
|
+
/** Custom filename for download */
|
|
17
|
+
filename?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Return type for useFileDownload hook
|
|
21
|
+
*
|
|
22
|
+
* Note: Errors propagate through global error handling (error boundaries,
|
|
23
|
+
* global error alert store). Results are returned from the Promise.
|
|
24
|
+
*/
|
|
25
|
+
export interface CoreFileDownloadResult {
|
|
26
|
+
/** Download a file by ID */
|
|
27
|
+
download: (fileId: string, options?: CoreFileDownloadOptions) => Promise<Blob | null>;
|
|
28
|
+
/** Whether currently downloading */
|
|
29
|
+
isDownloading: boolean;
|
|
30
|
+
/** Current download ID (if any) */
|
|
31
|
+
currentFileId: string | null;
|
|
32
|
+
/** Current progress percentage */
|
|
33
|
+
progress: number;
|
|
34
|
+
/** Cancel current download */
|
|
35
|
+
cancel: () => void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Hook Types
|
|
3
|
+
*
|
|
4
|
+
* Types for useFile hook (metadata operations).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Return type for useFile hook
|
|
8
|
+
*
|
|
9
|
+
* Provides file metadata operations (read-only).
|
|
10
|
+
*/
|
|
11
|
+
export interface CoreFileResult {
|
|
12
|
+
/** Fetch file metadata by ID */
|
|
13
|
+
fetchById: (fileId: string) => Promise<unknown>;
|
|
14
|
+
/** Get signed URL for a file */
|
|
15
|
+
getSignedUrl: (fileId: string) => Promise<{
|
|
16
|
+
url: string;
|
|
17
|
+
expiresAt: string;
|
|
18
|
+
}>;
|
|
19
|
+
/** Check if a file exists */
|
|
20
|
+
exists: (fileId: string) => Promise<boolean>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Hooks Types
|
|
3
|
+
*
|
|
4
|
+
* Types for file-related hooks in @plyaz/core.
|
|
5
|
+
*/
|
|
6
|
+
export type { CoreFileOperationType, CoreFileOperationStatus, CoreFileProgressItem, CoreAllFileProgressOptions, CoreAllFileProgressResult, } from './progress';
|
|
7
|
+
export type { CoreFileDownloadOptions, CoreFileDownloadResult } from './download';
|
|
8
|
+
export type { CoreFileUploadOptions, CoreTemplateUploadOptions, CoreGenerateOptions, CoreBulkTemplateUploadOptions, CoreFileUploadResult, } from './upload';
|
|
9
|
+
export type { CoreFileResult } from './file';
|
|
10
|
+
export type { CoreFileDeleteResult } from './delete';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Progress Hook Types
|
|
3
|
+
*
|
|
4
|
+
* Types for useAllFileProgress and useHasActiveFileOperations hooks.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Operation type for file progress tracking
|
|
8
|
+
*/
|
|
9
|
+
export type CoreFileOperationType = 'upload' | 'download' | 'generate';
|
|
10
|
+
/**
|
|
11
|
+
* Status for file operations
|
|
12
|
+
*/
|
|
13
|
+
export type CoreFileOperationStatus = 'pending' | 'uploading' | 'downloading' | 'processing' | 'generating' | 'completed' | 'failed' | 'cancelled';
|
|
14
|
+
/**
|
|
15
|
+
* Unified file progress item from useAllFileProgress hook.
|
|
16
|
+
* Normalizes upload, download, and generate progress into a single format.
|
|
17
|
+
*/
|
|
18
|
+
export interface CoreFileProgressItem {
|
|
19
|
+
/** Unique identifier (fileId for upload/download, templateId for generate) */
|
|
20
|
+
id: string;
|
|
21
|
+
/** Type of operation */
|
|
22
|
+
type: CoreFileOperationType;
|
|
23
|
+
/** Progress percentage (0-100) */
|
|
24
|
+
percentage: number;
|
|
25
|
+
/** Bytes loaded (for upload/download) */
|
|
26
|
+
loaded: number;
|
|
27
|
+
/** Total bytes (for upload/download) */
|
|
28
|
+
total: number;
|
|
29
|
+
/** Current status */
|
|
30
|
+
status: CoreFileOperationStatus;
|
|
31
|
+
/** Filename if available */
|
|
32
|
+
filename?: string;
|
|
33
|
+
/** Error message if failed */
|
|
34
|
+
error?: string;
|
|
35
|
+
/** Timestamp when operation started */
|
|
36
|
+
startedAt?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Options for useAllFileProgress hook
|
|
40
|
+
*/
|
|
41
|
+
export interface CoreAllFileProgressOptions {
|
|
42
|
+
/** Filter to only show progress for specific IDs */
|
|
43
|
+
filterByIds?: string[];
|
|
44
|
+
/** Include completed operations (default: false) */
|
|
45
|
+
includeCompleted?: boolean;
|
|
46
|
+
/** Include failed operations (default: true) */
|
|
47
|
+
includeFailed?: boolean;
|
|
48
|
+
/** Filter by operation type */
|
|
49
|
+
types?: CoreFileOperationType[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Return type for useAllFileProgress hook
|
|
53
|
+
*/
|
|
54
|
+
export interface CoreAllFileProgressResult {
|
|
55
|
+
/** All active progress items */
|
|
56
|
+
items: CoreFileProgressItem[];
|
|
57
|
+
/** Count by operation type */
|
|
58
|
+
counts: {
|
|
59
|
+
upload: number;
|
|
60
|
+
download: number;
|
|
61
|
+
generate: number;
|
|
62
|
+
total: number;
|
|
63
|
+
};
|
|
64
|
+
/** Whether any operations are active */
|
|
65
|
+
hasActive: boolean;
|
|
66
|
+
/** Overall progress percentage across all operations */
|
|
67
|
+
overallPercentage: number;
|
|
68
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Upload Hook Types
|
|
3
|
+
*
|
|
4
|
+
* Types for useFileUpload hook.
|
|
5
|
+
* Uses Pick to extend from existing API types where applicable.
|
|
6
|
+
*/
|
|
7
|
+
import type { UploadFileRequest, GenerateDocumentRequest } from '../../../api';
|
|
8
|
+
/**
|
|
9
|
+
* Options for useFileUpload hook - direct file upload
|
|
10
|
+
*
|
|
11
|
+
* Note: Progress is tracked via streams (useUploadProgress, useOverallUploadProgress).
|
|
12
|
+
* Errors propagate to global error handling (error boundaries, global error store).
|
|
13
|
+
* Results are returned from the Promise - no callbacks needed.
|
|
14
|
+
*/
|
|
15
|
+
export interface CoreFileUploadOptions {
|
|
16
|
+
/** Entity type for file organization */
|
|
17
|
+
entityType?: string;
|
|
18
|
+
/** Entity ID for file organization */
|
|
19
|
+
entityId?: string;
|
|
20
|
+
/** File category */
|
|
21
|
+
category?: string;
|
|
22
|
+
/** Whether file is public */
|
|
23
|
+
isPublic?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Options for template-based upload (generate document and upload to storage)
|
|
27
|
+
* Extended from UploadFileRequest API type for consistency.
|
|
28
|
+
*/
|
|
29
|
+
export interface CoreTemplateUploadOptions extends Required<Pick<UploadFileRequest, 'templateId'>>, Pick<UploadFileRequest, 'templateData' | 'outputFormat' | 'locale' | 'pdfOptions'> {
|
|
30
|
+
/** Entity type for file organization (default: 'default') */
|
|
31
|
+
entityType?: string;
|
|
32
|
+
/** Entity ID for file organization (default: 'default') */
|
|
33
|
+
entityId?: string;
|
|
34
|
+
/** File category (default: 'documents') */
|
|
35
|
+
category?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Options for generate-only (returns buffer, no upload)
|
|
39
|
+
* Extended from GenerateDocumentRequest API type for consistency.
|
|
40
|
+
*/
|
|
41
|
+
export interface CoreGenerateOptions extends Required<Pick<GenerateDocumentRequest, 'templateId'>>, Pick<GenerateDocumentRequest, 'templateData' | 'outputFormat' | 'locale' | 'pdfOptions'> {
|
|
42
|
+
/** Custom renderer name (optional) */
|
|
43
|
+
rendererName?: string;
|
|
44
|
+
/** Validation options */
|
|
45
|
+
validation?: {
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
strict?: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Options for bulk template upload (generate multiple documents and upload)
|
|
52
|
+
*/
|
|
53
|
+
export interface CoreBulkTemplateUploadOptions {
|
|
54
|
+
/** Array of template upload configs */
|
|
55
|
+
files: Array<CoreTemplateUploadOptions & {
|
|
56
|
+
/** Custom filename for this file */
|
|
57
|
+
filename?: string;
|
|
58
|
+
/** Custom mimeType override */
|
|
59
|
+
mimeType?: string;
|
|
60
|
+
}>;
|
|
61
|
+
/** Bulk upload options */
|
|
62
|
+
options?: {
|
|
63
|
+
/** Max concurrent uploads (default: 2) */
|
|
64
|
+
concurrency?: number;
|
|
65
|
+
/** Continue on error (default: true) */
|
|
66
|
+
continueOnError?: boolean;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return type for useFileUpload hook
|
|
71
|
+
*
|
|
72
|
+
* Note: Errors propagate through global error handling (error boundaries,
|
|
73
|
+
* global error alert store). Results are returned from the Promise.
|
|
74
|
+
*/
|
|
75
|
+
export interface CoreFileUploadResult {
|
|
76
|
+
/** Upload a file directly */
|
|
77
|
+
upload: (file: File, options?: CoreFileUploadOptions) => Promise<unknown>;
|
|
78
|
+
/** Upload multiple files directly */
|
|
79
|
+
uploadMultiple: (files: File[], options?: CoreFileUploadOptions) => Promise<unknown[]>;
|
|
80
|
+
/** Generate document from template and upload to storage */
|
|
81
|
+
uploadFromTemplate: (options: CoreTemplateUploadOptions) => Promise<unknown>;
|
|
82
|
+
/** Generate multiple documents from templates and upload to storage */
|
|
83
|
+
uploadMultipleFromTemplate: (options: CoreBulkTemplateUploadOptions) => Promise<unknown[]>;
|
|
84
|
+
/** Generate document from template (no upload - returns buffer for client download) */
|
|
85
|
+
generate: (options: CoreGenerateOptions) => Promise<{
|
|
86
|
+
buffer: string;
|
|
87
|
+
size: number;
|
|
88
|
+
}>;
|
|
89
|
+
/** Whether currently uploading/generating */
|
|
90
|
+
isUploading: boolean;
|
|
91
|
+
/** Current upload IDs */
|
|
92
|
+
currentFileIds: string[];
|
|
93
|
+
/** Current progress percentage (overall for bulk) */
|
|
94
|
+
progress: number;
|
|
95
|
+
/** Cancel current uploads */
|
|
96
|
+
cancel: () => void;
|
|
97
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Hooks Types
|
|
3
|
+
*
|
|
4
|
+
* Types for composite hooks in @plyaz/core.
|
|
5
|
+
* Organized by domain (files, etc.).
|
|
6
|
+
*/
|
|
7
|
+
export type { CoreFileOperationType, CoreFileOperationStatus, CoreFileProgressItem, CoreAllFileProgressOptions, CoreAllFileProgressResult, CoreFileDownloadOptions, CoreFileDownloadResult, CoreFileUploadOptions, CoreTemplateUploadOptions, CoreGenerateOptions, CoreBulkTemplateUploadOptions, CoreFileUploadResult, CoreFileResult, CoreFileDeleteResult, } from './files';
|