@guren/server 2.1.1 → 2.2.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/dist/{McpServiceProvider-7BB5FPF3.js → McpServiceProvider-GRDYNEQG.js} +1 -1
- package/dist/auth/AuthManager.d.ts +30 -0
- package/dist/auth/AuthenticatableModel.d.ts +25 -0
- package/dist/auth/RequestAuthContext.d.ts +24 -0
- package/dist/auth/SessionGuard.d.ts +31 -0
- package/dist/auth/api-token.d.ts +299 -0
- package/dist/auth/email-verification.d.ts +203 -0
- package/dist/auth/index.d.ts +18 -110
- package/dist/auth/index.js +3 -1
- package/dist/auth/oauth/index.d.ts +239 -0
- package/dist/auth/password/DefaultHasher.d.ts +13 -0
- package/dist/auth/password/NodeHasher.d.ts +22 -0
- package/dist/auth/password/PasswordHasher.d.ts +5 -0
- package/dist/auth/password/ScryptHasher.d.ts +26 -0
- package/dist/auth/password-reset.d.ts +91 -0
- package/dist/auth/providers/ModelUserProvider.d.ts +36 -0
- package/dist/auth/providers/UserProvider.d.ts +9 -0
- package/dist/auth/types.d.ts +102 -0
- package/dist/auth/utils.d.ts +39 -0
- package/dist/{Gate-CynjZCtS.d.ts → authorization/Gate.d.ts} +30 -111
- package/dist/authorization/Policy.d.ts +77 -0
- package/dist/authorization/index.d.ts +5 -129
- package/dist/authorization/index.js +3 -1
- package/dist/authorization/middleware.d.ts +49 -0
- package/dist/authorization/types.d.ts +108 -0
- package/dist/broadcasting/BroadcastManager.d.ts +205 -0
- package/dist/broadcasting/channels/Channel.d.ts +28 -0
- package/dist/broadcasting/channels/PresenceChannel.d.ts +72 -0
- package/dist/broadcasting/channels/PrivateChannel.d.ts +32 -0
- package/dist/broadcasting/channels/index.d.ts +3 -0
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +93 -0
- package/dist/broadcasting/drivers/RedisDriver.d.ts +112 -0
- package/dist/broadcasting/drivers/index.d.ts +2 -0
- package/dist/broadcasting/index.d.ts +6 -233
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/typed.d.ts +23 -0
- package/dist/broadcasting/types.d.ts +155 -0
- package/dist/cache/CacheManager.d.ts +87 -0
- package/dist/cache/TaggedCache.d.ts +62 -0
- package/dist/cache/index.d.ts +6 -233
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +64 -0
- package/dist/cache/stores/MemoryStore.d.ts +52 -0
- package/dist/cache/stores/RedisStore.d.ts +53 -0
- package/dist/{CacheManager-BmDzUKrF.d.ts → cache/types.d.ts} +26 -99
- package/dist/{chunk-TVY72CLV.js → chunk-4VE3LYOM.js} +3 -2
- package/dist/{chunk-FZD2AKJI.js → chunk-7OB2YXRE.js} +56 -28
- package/dist/{chunk-J6ETA476.js → chunk-BUQXOZCT.js} +93 -5
- package/dist/{chunk-DSDX3ASM.js → chunk-CDZUNKI6.js} +65 -83
- package/dist/{chunk-CWI4AJ47.js → chunk-HPET6XY5.js} +13 -9
- package/dist/{chunk-A3ISJVEV.js → chunk-HR2KZ3WL.js} +23 -5
- package/dist/{chunk-5SZTEZ22.js → chunk-PZKUDFMW.js} +11 -8
- package/dist/console/Command.d.ts +179 -0
- package/dist/{ConsoleKernel-CJg975mp.d.ts → console/ConsoleKernel.d.ts} +4 -6
- package/dist/console/Input.d.ts +140 -0
- package/dist/console/Output.d.ts +161 -0
- package/dist/console/index.d.ts +5 -0
- package/dist/console/types.d.ts +106 -0
- package/dist/container/Container.d.ts +148 -0
- package/dist/container/ServiceProvider.d.ts +103 -0
- package/dist/container/bindings.d.ts +55 -0
- package/dist/container/defineModule.d.ts +88 -0
- package/dist/container/definePlugin.d.ts +62 -0
- package/dist/container/index.d.ts +8 -0
- package/dist/container/types.d.ts +73 -0
- package/dist/database/Factory.d.ts +82 -0
- package/dist/database/Seeder.d.ts +35 -0
- package/dist/database/SeederRunner.d.ts +41 -0
- package/dist/database/index.d.ts +4 -0
- package/dist/database/types.d.ts +49 -0
- package/dist/discovery/AutoDiscovery.d.ts +113 -0
- package/dist/discovery/index.d.ts +2 -0
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +12 -0
- package/dist/docs-viewer/endpoint.d.ts +19 -0
- package/dist/encryption/Encrypter.d.ts +96 -0
- package/dist/encryption/Hash.d.ts +69 -0
- package/dist/encryption/MessageSigner.d.ts +21 -0
- package/dist/encryption/Random.d.ts +119 -0
- package/dist/encryption/app-key.d.ts +12 -0
- package/dist/encryption/index.d.ts +10 -222
- package/dist/encryption/signed-url.d.ts +9 -0
- package/dist/encryption/types.d.ts +103 -0
- package/dist/errors/ExceptionHandler.d.ts +118 -0
- package/dist/errors/HttpException.d.ts +106 -0
- package/dist/errors/debug-page.d.ts +22 -0
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +32 -0
- package/dist/errors/exceptions/AuthorizationException.d.ts +32 -0
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +31 -0
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +36 -0
- package/dist/errors/exceptions/ValidationException.d.ts +60 -0
- package/dist/errors/exceptions/index.d.ts +5 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/types.d.ts +43 -0
- package/dist/events/Event.d.ts +33 -0
- package/dist/{EventManager-CmIoLt7r.d.ts → events/EventManager.d.ts} +4 -86
- package/dist/events/Listener.d.ts +79 -0
- package/dist/events/builtin.d.ts +73 -0
- package/dist/events/index.d.ts +6 -155
- package/dist/events/types.d.ts +48 -0
- package/dist/facades/index.d.ts +31 -0
- package/dist/health/HealthCheck.d.ts +34 -0
- package/dist/health/HealthManager.d.ts +53 -0
- package/dist/health/checks/CacheCheck.d.ts +35 -0
- package/dist/health/checks/CustomCheck.d.ts +23 -0
- package/dist/health/checks/DatabaseCheck.d.ts +33 -0
- package/dist/health/checks/MemoryCheck.d.ts +32 -0
- package/dist/health/checks/RedisCheck.d.ts +27 -0
- package/dist/health/checks/StorageCheck.d.ts +35 -0
- package/dist/health/checks/index.d.ts +12 -0
- package/dist/health/index.d.ts +5 -185
- package/dist/health/types.d.ts +52 -0
- package/dist/hot-reload/hot-disposables.d.ts +96 -0
- package/dist/hot-reload/testing.d.ts +14 -0
- package/dist/http/Application.d.ts +187 -0
- package/dist/http/FormRequest.d.ts +73 -0
- package/dist/http/dev-assets.d.ts +51 -0
- package/dist/http/dev-banner.d.ts +7 -0
- package/dist/http/inertia-assets.d.ts +22 -0
- package/dist/http/middleware/auth.d.ts +13 -0
- package/dist/http/middleware/capabilities.d.ts +22 -0
- package/dist/http/middleware/cors.d.ts +40 -0
- package/dist/http/middleware/csp.d.ts +59 -0
- package/dist/http/middleware/csrf.d.ts +121 -0
- package/dist/http/middleware/detect-locale.d.ts +65 -0
- package/dist/http/middleware/force-https.d.ts +34 -0
- package/dist/http/middleware/host-authorization.d.ts +24 -0
- package/dist/http/middleware/index.d.ts +19 -0
- package/dist/http/middleware/loopback-guard.d.ts +38 -0
- package/dist/{rate-limit-D9J2b4S1.d.ts → http/middleware/rate-limit.d.ts} +22 -50
- package/dist/http/middleware/redirect-safety.d.ts +29 -0
- package/dist/http/middleware/request-id.d.ts +19 -0
- package/dist/http/middleware/request-logging.d.ts +16 -0
- package/dist/http/middleware/security-headers.d.ts +49 -0
- package/dist/http/middleware/session.d.ts +93 -0
- package/dist/http/middleware/validation.d.ts +94 -0
- package/dist/http/public-assets.d.ts +15 -0
- package/dist/http/request.d.ts +24 -0
- package/dist/http/resources/CursorPaginator.d.ts +106 -0
- package/dist/http/resources/Paginator.d.ts +130 -0
- package/dist/http/resources/Resource.d.ts +67 -0
- package/dist/http/resources/ResourceCollection.d.ts +60 -0
- package/dist/http/resources/index.d.ts +6 -0
- package/dist/http/resources/types.d.ts +91 -0
- package/dist/http/validation/Validator.d.ts +128 -0
- package/dist/http/validation/index.d.ts +3 -0
- package/dist/http/validation/rules.d.ts +196 -0
- package/dist/http/validation/types.d.ts +96 -0
- package/dist/http/vite-dev-server.d.ts +27 -0
- package/dist/i18n/I18nManager.d.ts +114 -0
- package/dist/i18n/Translator.d.ts +80 -0
- package/dist/i18n/index.d.ts +6 -101
- package/dist/i18n/index.js +5 -3
- package/dist/i18n/loaders/JsonLoader.d.ts +47 -0
- package/dist/i18n/loaders/MemoryLoader.d.ts +37 -0
- package/dist/i18n/pluralization.d.ts +19 -0
- package/dist/i18n/types.d.ts +106 -0
- package/dist/index.d.ts +69 -2605
- package/dist/index.js +332 -152
- package/dist/lambda/index.d.ts +17 -37
- package/dist/logging/LogManager.d.ts +83 -0
- package/dist/logging/Logger.d.ts +76 -0
- package/dist/logging/channels/ConsoleChannel.d.ts +11 -0
- package/dist/logging/channels/DailyFileChannel.d.ts +20 -0
- package/dist/logging/channels/FileChannel.d.ts +15 -0
- package/dist/logging/index.d.ts +8 -50
- package/dist/logging/types.d.ts +96 -0
- package/dist/mail/Mail.d.ts +138 -0
- package/dist/mail/MailManager.d.ts +79 -0
- package/dist/mail/address.d.ts +8 -0
- package/dist/mail/index.d.ts +7 -316
- package/dist/mail/transports/LogTransport.d.ts +19 -0
- package/dist/mail/transports/MemoryTransport.d.ts +84 -0
- package/dist/mail/transports/ResendTransport.d.ts +32 -0
- package/dist/mail/transports/SmtpTransport.d.ts +40 -0
- package/dist/{MailManager-DpMvYiP9.d.ts → mail/types.d.ts} +11 -92
- package/dist/mcp/McpServiceProvider.d.ts +17 -0
- package/dist/mcp/create-mcp-server.d.ts +144 -0
- package/dist/mcp/endpoint.d.ts +29 -0
- package/dist/mcp/index.d.ts +3 -185
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +326 -0
- package/dist/mvc/Router.d.ts +239 -0
- package/dist/mvc/ViewEngine.d.ts +11 -0
- package/dist/mvc/inertia/InertiaEngine.d.ts +114 -0
- package/dist/mvc/inertia/shared.d.ts +90 -0
- package/dist/mvc/mount-route.d.ts +10 -0
- package/dist/notifications/Notification.d.ts +99 -0
- package/dist/notifications/NotificationManager.d.ts +150 -0
- package/dist/notifications/channels/DatabaseChannel.d.ts +55 -0
- package/dist/notifications/channels/MailChannel.d.ts +45 -0
- package/dist/notifications/channels/MemoryChannel.d.ts +85 -0
- package/dist/notifications/channels/SlackChannel.d.ts +73 -0
- package/dist/notifications/channels/index.d.ts +4 -0
- package/dist/notifications/index.d.ts +6 -322
- package/dist/notifications/notifiable-type.d.ts +10 -0
- package/dist/notifications/registry.d.ts +39 -0
- package/dist/notifications/types.d.ts +162 -0
- package/dist/providers/AuthServiceProvider.d.ts +7 -0
- package/dist/providers/AuthorizationServiceProvider.d.ts +9 -0
- package/dist/providers/BroadcastServiceProvider.d.ts +7 -0
- package/dist/providers/CacheServiceProvider.d.ts +7 -0
- package/dist/providers/EncryptionServiceProvider.d.ts +7 -0
- package/dist/providers/ErrorServiceProvider.d.ts +9 -0
- package/dist/providers/EventServiceProvider.d.ts +7 -0
- package/dist/providers/HealthServiceProvider.d.ts +7 -0
- package/dist/providers/I18nServiceProvider.d.ts +27 -0
- package/dist/providers/InertiaServiceProvider.d.ts +20 -0
- package/dist/providers/LogServiceProvider.d.ts +7 -0
- package/dist/providers/MailServiceProvider.d.ts +7 -0
- package/dist/providers/NotificationServiceProvider.d.ts +8 -0
- package/dist/providers/OAuthServiceProvider.d.ts +7 -0
- package/dist/providers/QueueServiceProvider.d.ts +7 -0
- package/dist/providers/SchedulingServiceProvider.d.ts +7 -0
- package/dist/providers/StorageServiceProvider.d.ts +7 -0
- package/dist/providers/index.d.ts +17 -0
- package/dist/queue/FailedJobReporter.d.ts +40 -0
- package/dist/queue/Job.d.ts +140 -0
- package/dist/queue/QueueManager.d.ts +79 -0
- package/dist/queue/Worker.d.ts +99 -0
- package/dist/queue/drivers/MemoryDriver.d.ts +60 -0
- package/dist/queue/drivers/RedisDriver.d.ts +96 -0
- package/dist/queue/drivers/SqsDriver.d.ts +108 -0
- package/dist/queue/drivers/SyncDriver.d.ts +28 -0
- package/dist/queue/index.d.ts +9 -453
- package/dist/queue/types.d.ts +171 -0
- package/dist/redis/RedisApiTokenStore.d.ts +78 -0
- package/dist/redis/RedisEmailVerificationStore.d.ts +54 -0
- package/dist/redis/RedisOAuthStateStore.d.ts +26 -0
- package/dist/redis/RedisPasswordResetStore.d.ts +57 -0
- package/dist/redis/RedisRateLimitStore.d.ts +77 -0
- package/dist/redis/RedisSessionStore.d.ts +61 -0
- package/dist/redis/client.d.ts +41 -0
- package/dist/redis/index.d.ts +14 -356
- package/dist/redis/index.js +5 -2
- package/dist/redis/scan-keys.d.ts +6 -0
- package/dist/runtime/index.d.ts +8 -95
- package/dist/runtime/index.js +1 -1
- package/dist/scheduling/CronParser.d.ts +37 -0
- package/dist/scheduling/Schedule.d.ts +229 -0
- package/dist/scheduling/ScheduledTask.d.ts +47 -0
- package/dist/scheduling/Scheduler.d.ts +99 -0
- package/dist/scheduling/index.d.ts +5 -41
- package/dist/scheduling/types.d.ts +97 -0
- package/dist/storage/StorageManager.d.ts +65 -0
- package/dist/storage/drivers/LocalDriver.d.ts +55 -0
- package/dist/storage/drivers/MemoryDriver.d.ts +66 -0
- package/dist/storage/drivers/S3Driver.d.ts +72 -0
- package/dist/storage/index.d.ts +5 -197
- package/dist/{StorageManager-oZTHqaza.d.ts → storage/types.d.ts} +10 -77
- package/dist/support/error-polyfill.d.ts +9 -0
- package/dist/support/import-map.d.ts +13 -0
- package/dist/support/redirect-target.d.ts +11 -0
- package/dist/support/stack-frames.d.ts +56 -0
- package/dist/support/trim-slashes.d.ts +11 -0
- package/dist/vite/index.d.ts +2 -35
- package/dist/vite/index.js +0 -3
- package/dist/vite/plugin.d.ts +34 -0
- package/package.json +3 -3
- package/dist/AuthManager-DBP4KYsx.d.ts +0 -79
- package/dist/BroadcastManager-D8KoJxiV.d.ts +0 -492
- package/dist/HealthManager-DUyMIzsZ.d.ts +0 -141
- package/dist/I18nManager-BiSoczfV.d.ts +0 -275
- package/dist/LogManager-7mxnkaPM.d.ts +0 -256
- package/dist/Scheduler-pZiT8i57.d.ts +0 -471
- package/dist/api-token-D24VPr_E.d.ts +0 -663
- package/dist/app-key-CsBfRC_Q.d.ts +0 -214
- package/dist/email-verification-Dx426KLn.d.ts +0 -336
- package/dist/index-9_Jzj5jo.d.ts +0 -7
- package/dist/validation-yAL53e1S.d.ts +0 -2610
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { CursorPaginationMeta, CursorPaginatedResponse, CursorPaginatorOptions, ResourceData, ResourceClass } from './types.js';
|
|
2
|
+
import type { Resource } from './Resource.js';
|
|
3
|
+
/**
|
|
4
|
+
* Cursor paginator for cursor-based pagination.
|
|
5
|
+
* Ideal for infinite scroll and real-time data.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CursorPaginator<T> {
|
|
8
|
+
protected _items: T[];
|
|
9
|
+
protected _perPage: number;
|
|
10
|
+
protected _currentCursor: string | null;
|
|
11
|
+
protected _nextCursor: string | null;
|
|
12
|
+
protected _prevCursor: string | null;
|
|
13
|
+
protected _hasMore: boolean;
|
|
14
|
+
protected _options: CursorPaginatorOptions;
|
|
15
|
+
constructor(items: T[], perPage: number, hasMore: boolean, options?: CursorPaginatorOptions & {
|
|
16
|
+
currentCursor?: string | null;
|
|
17
|
+
nextCursor?: string | null;
|
|
18
|
+
prevCursor?: string | null;
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Get the paginated items.
|
|
22
|
+
*/
|
|
23
|
+
items(): T[];
|
|
24
|
+
/**
|
|
25
|
+
* Get items per page.
|
|
26
|
+
*/
|
|
27
|
+
perPage(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Get the current cursor.
|
|
30
|
+
*/
|
|
31
|
+
currentCursor(): string | null;
|
|
32
|
+
/**
|
|
33
|
+
* Get the next cursor.
|
|
34
|
+
*/
|
|
35
|
+
nextCursor(): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Get the previous cursor.
|
|
38
|
+
*/
|
|
39
|
+
prevCursor(): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Check if there are more items.
|
|
42
|
+
*/
|
|
43
|
+
hasMorePages(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Check if there are previous items.
|
|
46
|
+
*/
|
|
47
|
+
hasPreviousPages(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get the number of items.
|
|
50
|
+
*/
|
|
51
|
+
count(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Check if empty.
|
|
54
|
+
*/
|
|
55
|
+
isEmpty(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Check if not empty.
|
|
58
|
+
*/
|
|
59
|
+
isNotEmpty(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get cursor pagination meta.
|
|
62
|
+
*/
|
|
63
|
+
meta(): CursorPaginationMeta;
|
|
64
|
+
/**
|
|
65
|
+
* Transform items to resources.
|
|
66
|
+
*/
|
|
67
|
+
toResource<R extends Resource<T>>(resourceClass: ResourceClass<T, R>): CursorPaginatedResponse<ResourceData>;
|
|
68
|
+
/**
|
|
69
|
+
* Transform to JSON.
|
|
70
|
+
*/
|
|
71
|
+
toJSON(): CursorPaginatedResponse<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Map over items.
|
|
74
|
+
*/
|
|
75
|
+
map<U>(callback: (item: T, index: number) => U): CursorPaginator<U>;
|
|
76
|
+
/**
|
|
77
|
+
* Get items as array.
|
|
78
|
+
*/
|
|
79
|
+
toArray(): T[];
|
|
80
|
+
/**
|
|
81
|
+
* Iterate over items.
|
|
82
|
+
*/
|
|
83
|
+
[Symbol.iterator](): Iterator<T>;
|
|
84
|
+
/**
|
|
85
|
+
* Create cursor paginator from array with ID-based cursor.
|
|
86
|
+
*/
|
|
87
|
+
static fromArray<T extends {
|
|
88
|
+
id: string | number;
|
|
89
|
+
}>(items: T[], cursor: string | null, perPage: number, options?: CursorPaginatorOptions): CursorPaginator<T>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Encode a cursor value.
|
|
93
|
+
*/
|
|
94
|
+
export declare function encodeCursor(value: string | number | Date): string;
|
|
95
|
+
/**
|
|
96
|
+
* Decode a cursor value.
|
|
97
|
+
*/
|
|
98
|
+
export declare function decodeCursor(cursor: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Create a cursor paginator.
|
|
101
|
+
*/
|
|
102
|
+
export declare function cursorPaginate<T>(items: T[], perPage: number, hasMore: boolean, options?: CursorPaginatorOptions & {
|
|
103
|
+
currentCursor?: string | null;
|
|
104
|
+
nextCursor?: string | null;
|
|
105
|
+
prevCursor?: string | null;
|
|
106
|
+
}): CursorPaginator<T>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { PaginationMeta, PaginationLinks, PaginatedResponse, PaginatorOptions, ResourceData, ResourceClass } from './types.js';
|
|
2
|
+
import type { Resource } from './Resource.js';
|
|
3
|
+
export interface PaginatedResultLike<T> {
|
|
4
|
+
data: T[];
|
|
5
|
+
meta: {
|
|
6
|
+
total: number;
|
|
7
|
+
perPage: number;
|
|
8
|
+
currentPage: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Paginator for offset-based pagination.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Paginator<T> {
|
|
15
|
+
protected _items: T[];
|
|
16
|
+
protected _total: number;
|
|
17
|
+
protected _perPage: number;
|
|
18
|
+
protected _currentPage: number;
|
|
19
|
+
protected _options: PaginatorOptions;
|
|
20
|
+
constructor(items: T[], total: number, perPage: number, currentPage: number, options?: PaginatorOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Get the paginated items.
|
|
23
|
+
*/
|
|
24
|
+
items(): T[];
|
|
25
|
+
/**
|
|
26
|
+
* Get total number of items.
|
|
27
|
+
*/
|
|
28
|
+
total(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Get items per page.
|
|
31
|
+
*/
|
|
32
|
+
perPage(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Get current page number.
|
|
35
|
+
*/
|
|
36
|
+
currentPage(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Get last page number.
|
|
39
|
+
*/
|
|
40
|
+
lastPage(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Check if there are more pages.
|
|
43
|
+
*/
|
|
44
|
+
hasMorePages(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Check if on first page.
|
|
47
|
+
*/
|
|
48
|
+
onFirstPage(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Check if on last page.
|
|
51
|
+
*/
|
|
52
|
+
onLastPage(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Get the "from" index (1-based).
|
|
55
|
+
*/
|
|
56
|
+
firstItem(): number | null;
|
|
57
|
+
/**
|
|
58
|
+
* Get the "to" index (1-based).
|
|
59
|
+
*/
|
|
60
|
+
lastItem(): number | null;
|
|
61
|
+
/**
|
|
62
|
+
* Get the number of items on current page.
|
|
63
|
+
*/
|
|
64
|
+
count(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Check if the paginator is empty.
|
|
67
|
+
*/
|
|
68
|
+
isEmpty(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Check if the paginator is not empty.
|
|
71
|
+
*/
|
|
72
|
+
isNotEmpty(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Get pagination meta information.
|
|
75
|
+
*/
|
|
76
|
+
meta(): PaginationMeta;
|
|
77
|
+
/**
|
|
78
|
+
* Build URL for a page.
|
|
79
|
+
*/
|
|
80
|
+
protected url(page: number): string;
|
|
81
|
+
/**
|
|
82
|
+
* Get pagination links.
|
|
83
|
+
*/
|
|
84
|
+
links(): PaginationLinks;
|
|
85
|
+
/**
|
|
86
|
+
* Set the base path for pagination links.
|
|
87
|
+
*/
|
|
88
|
+
withPath(path: string): this;
|
|
89
|
+
/**
|
|
90
|
+
* Set query parameters for pagination links.
|
|
91
|
+
*/
|
|
92
|
+
withQuery(query: Record<string, string>): this;
|
|
93
|
+
/**
|
|
94
|
+
* Set fragment for pagination links.
|
|
95
|
+
*/
|
|
96
|
+
fragment(fragment: string): this;
|
|
97
|
+
/**
|
|
98
|
+
* Transform items to resources.
|
|
99
|
+
*/
|
|
100
|
+
toResource<R extends Resource<T>>(resourceClass: ResourceClass<T, R>): PaginatedResponse<ResourceData>;
|
|
101
|
+
/**
|
|
102
|
+
* Transform to JSON.
|
|
103
|
+
*/
|
|
104
|
+
toJSON(): PaginatedResponse<T>;
|
|
105
|
+
/**
|
|
106
|
+
* Map over items.
|
|
107
|
+
*/
|
|
108
|
+
map<U>(callback: (item: T, index: number) => U): Paginator<U>;
|
|
109
|
+
/**
|
|
110
|
+
* Get items as array.
|
|
111
|
+
*/
|
|
112
|
+
toArray(): T[];
|
|
113
|
+
/**
|
|
114
|
+
* Iterate over items.
|
|
115
|
+
*/
|
|
116
|
+
[Symbol.iterator](): Iterator<T>;
|
|
117
|
+
/**
|
|
118
|
+
* Create paginator from array (slices the array).
|
|
119
|
+
*/
|
|
120
|
+
static fromArray<T>(items: T[], page: number, perPage: number, options?: PaginatorOptions): Paginator<T>;
|
|
121
|
+
/**
|
|
122
|
+
* Create paginator from an ORM-style paginated result.
|
|
123
|
+
*/
|
|
124
|
+
static fromPaginatedResult<T>(result: PaginatedResultLike<T>, options?: PaginatorOptions): Paginator<T>;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a paginator.
|
|
128
|
+
*/
|
|
129
|
+
export declare function paginate<T>(result: PaginatedResultLike<T>, options?: PaginatorOptions): Paginator<T>;
|
|
130
|
+
export declare function paginate<T>(items: T[], total: number, perPage: number, currentPage: number, options?: PaginatorOptions): Paginator<T>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ResourceData, ResourceClass } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for API resources.
|
|
4
|
+
* Transforms model data into API response format.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class Resource<T> {
|
|
7
|
+
/**
|
|
8
|
+
* The underlying resource.
|
|
9
|
+
*/
|
|
10
|
+
protected resource: T;
|
|
11
|
+
/**
|
|
12
|
+
* Additional data to merge with the resource.
|
|
13
|
+
*/
|
|
14
|
+
protected additionalData: ResourceData;
|
|
15
|
+
constructor(resource: T);
|
|
16
|
+
/**
|
|
17
|
+
* Transform the resource into an array/object.
|
|
18
|
+
* Must be implemented by subclasses.
|
|
19
|
+
*/
|
|
20
|
+
abstract toArray(): ResourceData;
|
|
21
|
+
/**
|
|
22
|
+
* Transform the resource to JSON.
|
|
23
|
+
*/
|
|
24
|
+
toJSON(): ResourceData;
|
|
25
|
+
/**
|
|
26
|
+
* Add additional data to the resource.
|
|
27
|
+
*/
|
|
28
|
+
additional(data: ResourceData): this;
|
|
29
|
+
/**
|
|
30
|
+
* Conditionally include a value.
|
|
31
|
+
*/
|
|
32
|
+
when<V>(condition: boolean, value: V | (() => V)): V | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Conditionally include a value with a default.
|
|
35
|
+
*/
|
|
36
|
+
whenOr<V>(condition: boolean, value: V | (() => V), defaultValue: V): V;
|
|
37
|
+
/**
|
|
38
|
+
* Include a value only if a relation is loaded.
|
|
39
|
+
*/
|
|
40
|
+
whenLoaded<V>(relation: string, value: V | (() => V), defaultValue?: V): V | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Include a value only if it's not null/undefined.
|
|
43
|
+
*/
|
|
44
|
+
whenNotNull<V>(value: V | null | undefined): V | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Merge another resource's data.
|
|
47
|
+
*/
|
|
48
|
+
merge(data: ResourceData): ResourceData;
|
|
49
|
+
/**
|
|
50
|
+
* Create a new resource instance.
|
|
51
|
+
*/
|
|
52
|
+
static make<T, R extends Resource<T>>(this: new (resource: T) => R, resource: T): R;
|
|
53
|
+
/**
|
|
54
|
+
* Create a collection of resources.
|
|
55
|
+
*/
|
|
56
|
+
static collection<T, R extends Resource<T>>(this: new (resource: T) => R, resources: T[]): ResourceData[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a resource collection from a resource class.
|
|
60
|
+
*/
|
|
61
|
+
export declare function collect<T, R extends Resource<T>>(resources: T[], resourceClass: ResourceClass<T, R>): ResourceData[];
|
|
62
|
+
/**
|
|
63
|
+
* Simple resource wrapper for objects without transformation.
|
|
64
|
+
*/
|
|
65
|
+
export declare class JsonResource<T extends Record<string, unknown>> extends Resource<T> {
|
|
66
|
+
toArray(): ResourceData;
|
|
67
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ResourceData, ResourceClass } from './types.js';
|
|
2
|
+
import type { Resource } from './Resource.js';
|
|
3
|
+
/**
|
|
4
|
+
* Collection of resources with additional metadata.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ResourceCollection<T, R extends Resource<T>> {
|
|
7
|
+
protected resources: T[];
|
|
8
|
+
protected resourceClass: ResourceClass<T, R>;
|
|
9
|
+
protected additionalData: ResourceData;
|
|
10
|
+
protected wrapKey: string | null;
|
|
11
|
+
constructor(resources: T[], resourceClass: ResourceClass<T, R>);
|
|
12
|
+
/**
|
|
13
|
+
* Transform all resources to an array.
|
|
14
|
+
*/
|
|
15
|
+
toArray(): ResourceData[];
|
|
16
|
+
/**
|
|
17
|
+
* Add additional data to the collection response.
|
|
18
|
+
*/
|
|
19
|
+
additional(data: ResourceData): this;
|
|
20
|
+
/**
|
|
21
|
+
* Set the wrapper key for the collection.
|
|
22
|
+
*/
|
|
23
|
+
wrap(key: string | null): this;
|
|
24
|
+
/**
|
|
25
|
+
* Disable wrapping.
|
|
26
|
+
*/
|
|
27
|
+
withoutWrapping(): this;
|
|
28
|
+
/**
|
|
29
|
+
* Get the number of resources.
|
|
30
|
+
*/
|
|
31
|
+
count(): number;
|
|
32
|
+
/**
|
|
33
|
+
* Check if collection is empty.
|
|
34
|
+
*/
|
|
35
|
+
isEmpty(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Check if collection is not empty.
|
|
38
|
+
*/
|
|
39
|
+
isNotEmpty(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Transform to JSON response.
|
|
42
|
+
*/
|
|
43
|
+
toJSON(): ResourceData;
|
|
44
|
+
/**
|
|
45
|
+
* Map over the resources.
|
|
46
|
+
*/
|
|
47
|
+
map<U>(callback: (resource: T, index: number) => U): U[];
|
|
48
|
+
/**
|
|
49
|
+
* Filter resources.
|
|
50
|
+
*/
|
|
51
|
+
filter(callback: (resource: T, index: number) => boolean): ResourceCollection<T, R>;
|
|
52
|
+
/**
|
|
53
|
+
* Get the underlying resources.
|
|
54
|
+
*/
|
|
55
|
+
all(): T[];
|
|
56
|
+
/**
|
|
57
|
+
* Create a resource collection.
|
|
58
|
+
*/
|
|
59
|
+
static make<T, R extends Resource<T>>(resources: T[], resourceClass: ResourceClass<T, R>): ResourceCollection<T, R>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { ResourceData, ValidationErrors, PaginationMeta, PaginationLinks, PaginationPageLink, PaginatedResponse, PaginatedPageProps, PaginatorOptions, CursorPaginationMeta, CursorPaginatedResponse, CursorPaginatorOptions, ResourceClass, BaseResource, InferResourceData, } from './types.js';
|
|
2
|
+
export type { PaginatedResultLike } from './Paginator.js';
|
|
3
|
+
export { Resource, JsonResource, collect } from './Resource.js';
|
|
4
|
+
export { ResourceCollection } from './ResourceCollection.js';
|
|
5
|
+
export { Paginator, paginate } from './Paginator.js';
|
|
6
|
+
export { CursorPaginator, encodeCursor, decodeCursor, cursorPaginate, } from './CursorPaginator.js';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource data type.
|
|
3
|
+
*/
|
|
4
|
+
export type ResourceData = Record<string, unknown>;
|
|
5
|
+
export type ValidationErrors<TField extends string = string> = Partial<Record<TField | 'message', string>>;
|
|
6
|
+
/**
|
|
7
|
+
* Pagination meta information.
|
|
8
|
+
*/
|
|
9
|
+
export interface PaginationMeta {
|
|
10
|
+
currentPage: number;
|
|
11
|
+
lastPage: number;
|
|
12
|
+
perPage: number;
|
|
13
|
+
total: number;
|
|
14
|
+
from: number | null;
|
|
15
|
+
to: number | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Pagination links.
|
|
19
|
+
*/
|
|
20
|
+
export interface PaginationPageLink {
|
|
21
|
+
page: number;
|
|
22
|
+
url: string | null;
|
|
23
|
+
active: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface PaginationLinks {
|
|
26
|
+
first: string | null;
|
|
27
|
+
last: string | null;
|
|
28
|
+
prev: string | null;
|
|
29
|
+
next: string | null;
|
|
30
|
+
pages: PaginationPageLink[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Paginated response structure.
|
|
34
|
+
*/
|
|
35
|
+
export interface PaginatedResponse<T> {
|
|
36
|
+
data: T[];
|
|
37
|
+
meta: PaginationMeta;
|
|
38
|
+
links: PaginationLinks;
|
|
39
|
+
}
|
|
40
|
+
export interface PaginatedPageProps<T> extends Record<string, unknown> {
|
|
41
|
+
data: T[];
|
|
42
|
+
pagination: {
|
|
43
|
+
meta: PaginationMeta;
|
|
44
|
+
links: PaginationLinks;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Cursor pagination meta information.
|
|
49
|
+
*/
|
|
50
|
+
export interface CursorPaginationMeta {
|
|
51
|
+
perPage: number;
|
|
52
|
+
nextCursor: string | null;
|
|
53
|
+
prevCursor: string | null;
|
|
54
|
+
hasMore: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Cursor paginated response structure.
|
|
58
|
+
*/
|
|
59
|
+
export interface CursorPaginatedResponse<T> {
|
|
60
|
+
data: T[];
|
|
61
|
+
meta: CursorPaginationMeta;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Paginator options.
|
|
65
|
+
*/
|
|
66
|
+
export interface PaginatorOptions {
|
|
67
|
+
path?: string;
|
|
68
|
+
query?: Record<string, string>;
|
|
69
|
+
fragment?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Cursor paginator options.
|
|
73
|
+
*/
|
|
74
|
+
export interface CursorPaginatorOptions {
|
|
75
|
+
cursorName?: string;
|
|
76
|
+
parameters?: Record<string, string>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Resource class type.
|
|
80
|
+
*/
|
|
81
|
+
export interface ResourceClass<T, R extends BaseResource<T>> {
|
|
82
|
+
new (resource: T): R;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Base resource interface.
|
|
86
|
+
*/
|
|
87
|
+
export interface BaseResource<T> {
|
|
88
|
+
toArray(): ResourceData;
|
|
89
|
+
toJSON(): ResourceData;
|
|
90
|
+
}
|
|
91
|
+
export type InferResourceData<TResource extends BaseResource<unknown>> = ReturnType<TResource['toJSON']>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { ValidationRule, ValidationResult, ValidatorOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Field validator builder.
|
|
4
|
+
*/
|
|
5
|
+
export declare class FieldValidator {
|
|
6
|
+
private field;
|
|
7
|
+
private _rules;
|
|
8
|
+
private isNullable;
|
|
9
|
+
private isSometimes;
|
|
10
|
+
private bailOnFirstError;
|
|
11
|
+
private conditions;
|
|
12
|
+
constructor(field: string);
|
|
13
|
+
/**
|
|
14
|
+
* Add a validation rule.
|
|
15
|
+
*/
|
|
16
|
+
rule(rule: ValidationRule): this;
|
|
17
|
+
/**
|
|
18
|
+
* Add multiple validation rules.
|
|
19
|
+
*/
|
|
20
|
+
rules(...rules: ValidationRule[]): this;
|
|
21
|
+
/**
|
|
22
|
+
* Mark field as nullable (allows null values).
|
|
23
|
+
*/
|
|
24
|
+
nullable(): this;
|
|
25
|
+
/**
|
|
26
|
+
* Only validate if field is present.
|
|
27
|
+
*/
|
|
28
|
+
sometimes(): this;
|
|
29
|
+
/**
|
|
30
|
+
* Stop validation on first error.
|
|
31
|
+
*/
|
|
32
|
+
bail(): this;
|
|
33
|
+
/**
|
|
34
|
+
* Continue validation even after errors.
|
|
35
|
+
*/
|
|
36
|
+
continueOnError(): this;
|
|
37
|
+
/**
|
|
38
|
+
* Add a condition - only validate if condition is true.
|
|
39
|
+
*/
|
|
40
|
+
when(condition: (data: Record<string, unknown>) => boolean): this;
|
|
41
|
+
/**
|
|
42
|
+
* Add a condition - only validate if condition is false.
|
|
43
|
+
*/
|
|
44
|
+
unless(condition: (data: Record<string, unknown>) => boolean): this;
|
|
45
|
+
/**
|
|
46
|
+
* Validate the field.
|
|
47
|
+
*/
|
|
48
|
+
validate(value: unknown, data: Record<string, unknown>, options?: ValidatorOptions): Promise<string[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Format error message.
|
|
51
|
+
*/
|
|
52
|
+
private formatMessage;
|
|
53
|
+
/**
|
|
54
|
+
* Get the field name.
|
|
55
|
+
*/
|
|
56
|
+
getField(): string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Validator class for validating data against rules.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { Validator, required, email, min } from '@guren/server'
|
|
64
|
+
*
|
|
65
|
+
* const validator = new Validator()
|
|
66
|
+
* .field('name', required(), min(2))
|
|
67
|
+
* .field('email', required(), email())
|
|
68
|
+
* .field('password', required(), min(8))
|
|
69
|
+
* .field('password_confirmation', required())
|
|
70
|
+
*
|
|
71
|
+
* const result = await validator.validate(data)
|
|
72
|
+
* if (!result.success) {
|
|
73
|
+
* console.log(result.errors)
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare class Validator {
|
|
78
|
+
private fields;
|
|
79
|
+
private options;
|
|
80
|
+
/**
|
|
81
|
+
* Create a new validator.
|
|
82
|
+
*/
|
|
83
|
+
constructor(options?: ValidatorOptions);
|
|
84
|
+
/**
|
|
85
|
+
* Add a field with rules.
|
|
86
|
+
*/
|
|
87
|
+
field(name: string, ...rules: ValidationRule[]): this;
|
|
88
|
+
/**
|
|
89
|
+
* Add a field validator.
|
|
90
|
+
*/
|
|
91
|
+
addField(validator: FieldValidator): this;
|
|
92
|
+
/**
|
|
93
|
+
* Get a field validator for fluent configuration.
|
|
94
|
+
*/
|
|
95
|
+
for(name: string): FieldValidator;
|
|
96
|
+
/**
|
|
97
|
+
* Set custom error messages.
|
|
98
|
+
*/
|
|
99
|
+
messages(messages: Record<string, string>): this;
|
|
100
|
+
/**
|
|
101
|
+
* Set custom attribute names.
|
|
102
|
+
*/
|
|
103
|
+
attributes(attributes: Record<string, string>): this;
|
|
104
|
+
/**
|
|
105
|
+
* Validate data.
|
|
106
|
+
*/
|
|
107
|
+
validate(data: Record<string, unknown>): Promise<ValidationResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Validate and throw if invalid.
|
|
110
|
+
*/
|
|
111
|
+
validateOrThrow(data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
112
|
+
/**
|
|
113
|
+
* Create a new validator from rules object.
|
|
114
|
+
*/
|
|
115
|
+
static make(rules: Record<string, ValidationRule[]>, options?: ValidatorOptions): Validator;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create a new validator.
|
|
119
|
+
*/
|
|
120
|
+
export declare function createValidator(options?: ValidatorOptions): Validator;
|
|
121
|
+
/**
|
|
122
|
+
* Quick validate function.
|
|
123
|
+
*/
|
|
124
|
+
export declare function quickValidate(data: Record<string, unknown>, rules: Record<string, ValidationRule[]>, options?: ValidatorOptions): Promise<ValidationResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Quick validate and throw function.
|
|
127
|
+
*/
|
|
128
|
+
export declare function quickValidateOrThrow(data: Record<string, unknown>, rules: Record<string, ValidationRule[]>, options?: ValidatorOptions): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { ValidationRule, RuleDefinition, ValidationResult, FileValidationOptions, ImageValidationOptions, ValidatorOptions, FileLike, } from './types.js';
|
|
2
|
+
export { Validator, FieldValidator, createValidator, quickValidate, quickValidateOrThrow, } from './Validator.js';
|
|
3
|
+
export { required, nullable, requiredIf, requiredUnless, requiredWith, requiredWithout, string, numeric, integer, boolean, array, object, email, url, uuid, ip, ipv4, ipv6, json, alpha, alphaNum, alphaDash, regex, min, max, between, size, inValues, notIn, confirmed, same, different, date, dateFormat, after, afterOrEqual, before, beforeOrEqual, startsWith, endsWith, file, image, mimes, maxFileSize, minFileSize, custom, unique, exists, } from './rules.js';
|