@guren/server 2.15.0 → 2.16.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/{DocsViewerServiceProvider-qFCaeiUv.js → DocsViewerServiceProvider-D2cuVgtN.js} +7 -12
- package/dist/{Hash-C8aejmi8.js → Hash-D2DFd8xX.js} +7 -57
- package/dist/{HttpException-BkS3euNG.js → HttpException-BlQ2yEmT.js} +2 -79
- package/dist/{Job-BVT813DO.js → Job-DxQK8h3P.js} +24 -179
- package/dist/{McpServiceProvider-BawsYjgN.js → McpServiceProvider-nNcbCIQX.js} +11 -20
- package/dist/{Random-DbIJ22KQ.js → Random-S0OvCuR8.js} +9 -106
- package/dist/agent/AgentApprovalRequested.d.ts +11 -39
- package/dist/agent/approval.d.ts +76 -187
- package/dist/agent/audit-emitter.d.ts +16 -44
- package/dist/agent/audit.d.ts +20 -56
- package/dist/agent/derive.d.ts +32 -66
- package/dist/agent/dispatch.d.ts +38 -90
- package/dist/agent/events.d.ts +11 -19
- package/dist/agent/meta-tools.d.ts +18 -46
- package/dist/agent/public.d.ts +6 -25
- package/dist/agent/public.js +1 -1
- package/dist/agent/redact.d.ts +16 -38
- package/dist/agent/scopes.d.ts +23 -69
- package/dist/auth/AuthManager.d.ts +19 -40
- package/dist/auth/AuthenticatableModel.d.ts +2 -2
- package/dist/auth/SessionGuard.d.ts +0 -1
- package/dist/auth/TokenGuard.d.ts +6 -26
- package/dist/auth/api-token.d.ts +16 -148
- package/dist/auth/context.d.ts +5 -10
- package/dist/auth/email-verification.d.ts +29 -127
- package/dist/auth/index.js +1 -1
- package/dist/auth/oauth/index.d.ts +35 -57
- package/dist/auth/password/DefaultHasher.d.ts +5 -14
- package/dist/auth/password/PasswordHasher.d.ts +5 -13
- package/dist/auth/password/hash-format.d.ts +5 -13
- package/dist/auth/password-reset.d.ts +16 -42
- package/dist/auth/providers/ModelUserProvider.d.ts +3 -4
- package/dist/auth/providers/UserProvider.d.ts +4 -4
- package/dist/auth/signed-token.d.ts +18 -0
- package/dist/auth/types.d.ts +9 -32
- package/dist/auth/utils.d.ts +6 -27
- package/dist/{auth-DkYoAPVn.js → auth-CbdPH4Cd.js} +169 -502
- package/dist/authorization/Gate.d.ts +9 -145
- package/dist/authorization/Policy.d.ts +6 -53
- package/dist/authorization/index.js +1 -1
- package/dist/authorization/middleware.d.ts +16 -62
- package/dist/authorization/types.d.ts +8 -64
- package/dist/{authorization-CdfbCj8J.js → authorization-CdEWZZw3.js} +44 -309
- package/dist/broadcasting/BroadcastManager.d.ts +29 -149
- package/dist/broadcasting/channels/Channel.d.ts +1 -19
- package/dist/broadcasting/channels/PresenceChannel.d.ts +1 -55
- package/dist/broadcasting/channels/PrivateChannel.d.ts +1 -23
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +18 -70
- package/dist/broadcasting/drivers/RedisDriver.d.ts +3 -80
- package/dist/broadcasting/drivers/index.d.ts +1 -1
- package/dist/broadcasting/index.d.ts +1 -1
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/types.d.ts +7 -88
- package/dist/{broadcasting-BwodCA4q.js → broadcasting-B5RzB0A2.js} +87 -414
- package/dist/cache/CacheManager.d.ts +8 -62
- package/dist/cache/TaggedCache.d.ts +2 -35
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +2 -36
- package/dist/cache/stores/MemoryStore.d.ts +2 -26
- package/dist/cache/stores/RedisStore.d.ts +1 -29
- package/dist/cache/types.d.ts +21 -128
- package/dist/{cache-BYnZf2FR.js → cache-BOOIr324.js} +19 -198
- package/dist/client-C4TEr_Dd.js +9 -0
- package/dist/console/Command.d.ts +17 -126
- package/dist/console/ConsoleKernel.d.ts +2 -74
- package/dist/console/Input.d.ts +5 -113
- package/dist/console/Output.d.ts +3 -99
- package/dist/console/types.d.ts +3 -33
- package/dist/container/Container.d.ts +12 -103
- package/dist/container/ServiceProvider.d.ts +17 -61
- package/dist/container/bindings.d.ts +5 -26
- package/dist/container/defineModule.d.ts +16 -54
- package/dist/container/definePlugin.d.ts +12 -45
- package/dist/container/types.d.ts +2 -34
- package/dist/context-CXk_umpT.js +21 -0
- package/dist/database/Factory.d.ts +4 -57
- package/dist/database/Seeder.d.ts +8 -46
- package/dist/database/SeederRunner.d.ts +3 -33
- package/dist/database/types.d.ts +3 -24
- package/dist/discovery/AutoDiscovery.d.ts +10 -82
- package/dist/{dispatch-erOS9epZ.js → dispatch-BAwzftws.js} +32 -79
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +2 -5
- package/dist/docs-viewer/endpoint.d.ts +5 -11
- package/dist/encryption/Encrypter.d.ts +5 -71
- package/dist/encryption/Hash.d.ts +7 -57
- package/dist/encryption/Random.d.ts +6 -99
- package/dist/encryption/index.js +3 -3
- package/dist/encryption/types.d.ts +10 -72
- package/dist/{encryption-D99Vmls3.js → encryption-uwP3Di4D.js} +9 -78
- package/dist/{endpoint-D6GIqOpe.js → endpoint-BXipU2Jj.js} +6 -12
- package/dist/endpoint-Dsw3Acvq.js +26 -0
- package/dist/errors/ExceptionHandler.d.ts +3 -90
- package/dist/errors/HttpException.d.ts +2 -79
- package/dist/errors/debug-page.d.ts +3 -17
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +2 -24
- package/dist/errors/exceptions/AuthorizationException.d.ts +1 -24
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +1 -23
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +1 -27
- package/dist/errors/exceptions/ValidationException.d.ts +2 -43
- package/dist/errors/types.d.ts +1 -25
- package/dist/{errors-BgeOl_DC.js → errors-JpkcCjjn.js} +3 -41
- package/dist/events/Event.d.ts +1 -28
- package/dist/events/EventManager.d.ts +5 -107
- package/dist/events/Listener.d.ts +7 -55
- package/dist/events/builtin.d.ts +0 -24
- package/dist/events/index.js +1 -1
- package/dist/events/types.d.ts +4 -22
- package/dist/{events-aIH_bWRx.js → events-DOmAHDeP.js} +11 -191
- package/dist/facades/index.d.ts +2 -14
- package/dist/health/HealthCheck.d.ts +0 -24
- package/dist/health/HealthManager.d.ts +0 -36
- package/dist/health/checks/CacheCheck.d.ts +2 -17
- package/dist/health/checks/CustomCheck.d.ts +0 -9
- package/dist/health/checks/DatabaseCheck.d.ts +2 -17
- package/dist/health/checks/MemoryCheck.d.ts +3 -12
- package/dist/health/checks/RedisCheck.d.ts +1 -13
- package/dist/health/checks/StorageCheck.d.ts +2 -17
- package/dist/health/index.js +1 -1
- package/dist/health/types.d.ts +4 -24
- package/dist/{health-VWdWXRwh.js → health-DQSvUplL.js} +1 -76
- package/dist/hot-disposables-B5BXqaIH.js +167 -0
- package/dist/hot-reload/hot-disposables.d.ts +22 -74
- package/dist/hot-reload/testing.d.ts +4 -9
- package/dist/http/Application.d.ts +62 -208
- package/dist/http/FormRequest.d.ts +4 -55
- package/dist/http/dev-assets.d.ts +13 -31
- package/dist/http/dev-banner.d.ts +2 -5
- package/dist/http/inertia-assets.d.ts +3 -6
- package/dist/http/middleware/capabilities.d.ts +27 -50
- package/dist/http/middleware/cors.d.ts +4 -29
- package/dist/http/middleware/csp.d.ts +2 -25
- package/dist/http/middleware/csrf.d.ts +20 -95
- package/dist/http/middleware/detect-locale.d.ts +7 -27
- package/dist/http/middleware/force-https.d.ts +6 -24
- package/dist/http/middleware/host-authorization.d.ts +2 -12
- package/dist/http/middleware/loopback-guard.d.ts +15 -33
- package/dist/http/middleware/rate-limit.d.ts +29 -126
- package/dist/http/middleware/redirect-safety.d.ts +2 -20
- package/dist/http/middleware/request-id.d.ts +1 -14
- package/dist/http/middleware/request-logging.d.ts +2 -13
- package/dist/http/middleware/response-headers.d.ts +5 -13
- package/dist/http/middleware/security-headers.d.ts +2 -16
- package/dist/http/middleware/session.d.ts +15 -34
- package/dist/http/middleware/validation-errors-cookie.d.ts +7 -18
- package/dist/http/middleware/validation.d.ts +8 -63
- package/dist/http/public-assets.d.ts +11 -7
- package/dist/http/request.d.ts +32 -118
- package/dist/http/resources/CursorPaginator.d.ts +5 -64
- package/dist/http/resources/Paginator.d.ts +7 -84
- package/dist/http/resources/Resource.d.ts +9 -65
- package/dist/http/resources/ResourceCollection.d.ts +5 -39
- package/dist/http/resources/types.d.ts +10 -30
- package/dist/http/static-documents.d.ts +10 -20
- package/dist/http/validation/Validator.d.ts +25 -85
- package/dist/http/validation/rules.d.ts +48 -147
- package/dist/http/validation/types.d.ts +16 -61
- package/dist/http/vite-assets.d.ts +5 -28
- package/dist/http/vite-dev-server.d.ts +6 -9
- package/dist/http/vite-manifest.d.ts +19 -33
- package/dist/i18n/I18nManager.d.ts +12 -78
- package/dist/i18n/Translator.d.ts +3 -54
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/loaders/JsonLoader.d.ts +4 -31
- package/dist/i18n/loaders/MemoryLoader.d.ts +1 -21
- package/dist/i18n/pluralization.d.ts +4 -13
- package/dist/i18n/types.d.ts +17 -69
- package/dist/{i18n-mcWi7LCd.js → i18n-Cg1aajRP.js} +31 -225
- package/dist/index.d.ts +2 -1
- package/dist/index.js +714 -3011
- package/dist/internal/agent-preflight.d.ts +9 -21
- package/dist/internal/request.d.ts +6 -19
- package/dist/internal/request.js +1 -1
- package/dist/internal/route-path.d.ts +9 -21
- package/dist/internal/route-path.js +9 -21
- package/dist/internal/zod-compat.d.ts +55 -122
- package/dist/internal/zod-compat.js +39 -70
- package/dist/internal/zod-json-schema.d.ts +18 -54
- package/dist/internal/zod-json-schema.js +46 -123
- package/dist/jsx-runtime.d.ts +3 -8
- package/dist/lambda/index.d.ts +17 -79
- package/dist/lambda/index.js +11 -59
- package/dist/logging/LogManager.d.ts +1 -51
- package/dist/logging/Logger.d.ts +8 -47
- package/dist/logging/channels/ConsoleChannel.d.ts +1 -3
- package/dist/logging/channels/DailyFileChannel.d.ts +1 -3
- package/dist/logging/channels/FileChannel.d.ts +1 -3
- package/dist/logging/daily-file-path.d.ts +7 -16
- package/dist/logging/index.js +1 -1
- package/dist/logging/types.d.ts +13 -45
- package/dist/{logging-B-kngi3q.js → logging-zOY1XCtq.js} +52 -141
- package/dist/{loopback-guard-D0Kc7-xc.js → loopback-guard-DT9gHF0F.js} +41 -92
- package/dist/mail/Mail.d.ts +10 -106
- package/dist/mail/MailManager.d.ts +2 -60
- package/dist/mail/index.js +1 -1
- package/dist/mail/transports/LogTransport.d.ts +1 -4
- package/dist/mail/transports/MemoryTransport.d.ts +1 -63
- package/dist/mail/transports/ResendTransport.d.ts +1 -23
- package/dist/mail/transports/SmtpTransport.d.ts +1 -31
- package/dist/mail/types.d.ts +28 -150
- package/dist/{mail-DfEfSQEr.js → mail-76DWy9lj.js} +31 -289
- package/dist/mcp/McpServiceProvider.d.ts +4 -10
- package/dist/mcp/create-mcp-server.d.ts +25 -57
- package/dist/mcp/endpoint.d.ts +12 -36
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +46 -227
- package/dist/mvc/Router.d.ts +50 -129
- package/dist/mvc/inertia/InertiaEngine.d.ts +18 -48
- package/dist/mvc/inertia/shared.d.ts +6 -19
- package/dist/mvc/mount-route.d.ts +2 -6
- package/dist/mvc/view.d.ts +1 -2
- package/dist/notifications/Notification.d.ts +8 -75
- package/dist/notifications/NotificationManager.d.ts +15 -88
- package/dist/notifications/channels/DatabaseChannel.d.ts +1 -41
- package/dist/notifications/channels/MailChannel.d.ts +2 -31
- package/dist/notifications/channels/MemoryChannel.d.ts +2 -62
- package/dist/notifications/channels/SlackChannel.d.ts +3 -48
- package/dist/notifications/index.js +1 -1
- package/dist/notifications/notifiable-type.d.ts +3 -6
- package/dist/notifications/registry.d.ts +8 -27
- package/dist/notifications/types.d.ts +16 -53
- package/dist/{notifications-BGqmUNZ8.js → notifications-okWFs9ly.js} +37 -335
- package/dist/providers/AuthServiceProvider.d.ts +1 -3
- package/dist/providers/AuthorizationServiceProvider.d.ts +2 -3
- package/dist/providers/BroadcastServiceProvider.d.ts +1 -3
- package/dist/providers/CacheServiceProvider.d.ts +1 -3
- package/dist/providers/EncryptionServiceProvider.d.ts +1 -3
- package/dist/providers/ErrorServiceProvider.d.ts +1 -4
- package/dist/providers/EventServiceProvider.d.ts +1 -3
- package/dist/providers/HealthServiceProvider.d.ts +1 -3
- package/dist/providers/I18nServiceProvider.d.ts +6 -10
- package/dist/providers/InertiaServiceProvider.d.ts +1 -4
- package/dist/providers/LogServiceProvider.d.ts +1 -3
- package/dist/providers/MailServiceProvider.d.ts +1 -3
- package/dist/providers/NotificationServiceProvider.d.ts +1 -3
- package/dist/providers/OAuthServiceProvider.d.ts +1 -3
- package/dist/providers/QueueServiceProvider.d.ts +1 -3
- package/dist/providers/SchedulingServiceProvider.d.ts +1 -3
- package/dist/providers/StorageServiceProvider.d.ts +1 -3
- package/dist/queue/FailedJobReporter.d.ts +1 -24
- package/dist/queue/Job.d.ts +12 -99
- package/dist/queue/QueueManager.d.ts +6 -57
- package/dist/queue/Worker.d.ts +4 -65
- package/dist/queue/drivers/MemoryDriver.d.ts +3 -44
- package/dist/queue/drivers/RedisDriver.d.ts +7 -65
- package/dist/queue/drivers/SqsDriver.d.ts +6 -57
- package/dist/queue/drivers/SyncDriver.d.ts +10 -13
- package/dist/queue/index.js +2 -2
- package/dist/queue/types.d.ts +10 -92
- package/dist/{queue-CXrRK85G.js → queue-CcXCjuJI.js} +32 -260
- package/dist/redis/RedisApiTokenStore.d.ts +4 -56
- package/dist/redis/RedisEmailVerificationStore.d.ts +4 -37
- package/dist/redis/RedisOAuthStateStore.d.ts +2 -10
- package/dist/redis/RedisPasswordResetStore.d.ts +4 -37
- package/dist/redis/RedisRateLimitStore.d.ts +16 -49
- package/dist/redis/RedisSessionStore.d.ts +3 -44
- package/dist/redis/client.d.ts +2 -32
- package/dist/redis/index.js +47 -232
- package/dist/redis/redis-values.d.ts +6 -12
- package/dist/redis/scan-keys.d.ts +1 -4
- package/dist/request-CLOYytGP.js +68 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +50 -92
- package/dist/scheduling/CronParser.d.ts +0 -29
- package/dist/scheduling/Schedule.d.ts +1 -153
- package/dist/scheduling/ScheduledTask.d.ts +0 -31
- package/dist/scheduling/Scheduler.d.ts +0 -70
- package/dist/scheduling/index.js +1 -1
- package/dist/scheduling/types.d.ts +4 -65
- package/dist/{scheduling-CPiEdtQd.js → scheduling-C6tcOtUl.js} +2 -287
- package/dist/storage/StorageManager.d.ts +0 -48
- package/dist/storage/drivers/LocalDriver.d.ts +1 -25
- package/dist/storage/drivers/MemoryDriver.d.ts +5 -35
- package/dist/storage/drivers/S3Driver.d.ts +6 -36
- package/dist/storage/drivers/s3-acl.d.ts +5 -10
- package/dist/storage/index.js +1 -1
- package/dist/storage/types.d.ts +27 -265
- package/dist/{storage-TLD9t0Q2.js → storage-BB59f07j.js} +17 -157
- package/dist/support/contained-path.d.ts +10 -20
- package/dist/support/error-polyfill.d.ts +4 -6
- package/dist/support/expiry.d.ts +17 -33
- package/dist/support/expiry.js +17 -33
- package/dist/support/import-map.d.ts +3 -7
- package/dist/support/inertia-defaults.d.ts +5 -10
- package/dist/support/redirect-target.d.ts +4 -6
- package/dist/support/stack-frames.d.ts +11 -50
- package/dist/support/trim-slashes.d.ts +4 -7
- package/dist/support/warn-once.d.ts +2 -6
- package/dist/{trim-slashes-ZJ_VsY5s.js → trim-slashes-BLY9hKAa.js} +4 -7
- package/dist/{vite-manifest-w_RSOvQW.js → vite-manifest-CTQp-SOo.js} +34 -58
- package/package.json +2 -2
- package/dist/client-Dd7vLcqp.js +0 -27
- package/dist/context-DoD0c7J_.js +0 -26
- package/dist/endpoint-D-20PiHY.js +0 -46
- package/dist/hot-disposables-WsTX2ySN.js +0 -281
- package/dist/request-CVQwpu2J.js +0 -129
package/dist/http/request.d.ts
CHANGED
|
@@ -1,130 +1,54 @@
|
|
|
1
1
|
import type { HonoRequest } from 'hono';
|
|
2
2
|
import type { Context } from './Application.js';
|
|
3
3
|
/**
|
|
4
|
-
* What {@link parseRequestBody}
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* real `Context` always carries one, so against `Context` that guard reads as
|
|
10
|
-
* dead code. It is not: `@guren/testing`'s controller mock reaches this parser
|
|
11
|
-
* through a `HonoRequest` built from a plain `Request`, and this is the
|
|
12
|
-
* declaration that lets it do so without casting its way past the signature.
|
|
13
|
-
*
|
|
14
|
-
* Narrowing a parameter accepts strictly more callers, so every existing one —
|
|
15
|
-
* `Router`, `Controller`, the validation middleware, `FormRequest`,
|
|
16
|
-
* `BroadcastManager` — keeps passing a real `Context` unchanged.
|
|
4
|
+
* What {@link parseRequestBody} reads, not a whole Hono context. `parseBody` is
|
|
5
|
+
* optional here so `@guren/testing`'s controller mock — a `HonoRequest` built
|
|
6
|
+
* from a plain `Request` — satisfies it without a cast; that is also what makes
|
|
7
|
+
* the `typeof` guard below live rather than dead code. Narrowing accepts
|
|
8
|
+
* strictly more callers, so existing ones keep passing a real `Context`.
|
|
17
9
|
*/
|
|
18
10
|
export interface RequestBodyContext {
|
|
19
11
|
req: Pick<HonoRequest, 'header' | 'json'> & Partial<Pick<HonoRequest, 'parseBody'>>;
|
|
20
12
|
}
|
|
21
13
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* Falls back to an empty object when the body cannot be parsed (malformed
|
|
28
|
-
* JSON, a form body the parser cannot decode, an empty POST, an unsupported
|
|
29
|
-
* content type). That fallback is load bearing: an all-optional object schema
|
|
30
|
-
* has to keep passing on an empty body, which `undefined` would break. The
|
|
31
|
-
* cost is that a non-object schema sees `{}` there and fails validation,
|
|
32
|
-
* rather than receiving nothing.
|
|
33
|
-
*
|
|
34
|
-
* The fallback does not distinguish whose fault the failure was: a body the
|
|
35
|
-
* client could never have sent correctly and a body already consumed upstream
|
|
36
|
-
* (middleware reading `ctx.req.raw` directly, bypassing Hono's cache) both read
|
|
37
|
-
* as `{}` here. That is deliberate — the JSON branch above has always behaved
|
|
38
|
-
* this way, and telling the two apart means matching runtime-specific error
|
|
39
|
-
* codes, which would answer differently on Bun, Node and Workers. A parser
|
|
40
|
-
* error is a poor signal for a middleware-ordering bug either way.
|
|
41
|
-
*
|
|
42
|
-
* Form submissions have no non-object shape to preserve, so they normalize to
|
|
43
|
-
* a record exactly as {@link parseRequestPayload} does.
|
|
14
|
+
* Returns the parsed body as-is (a JSON array stays an array), for callers that
|
|
15
|
+
* hand it to a schema. Any unparseable body falls back to `{}` so an all-optional
|
|
16
|
+
* object schema still passes on an empty POST; a non-object schema then fails
|
|
17
|
+
* validation instead of receiving nothing. A malformed body and one consumed
|
|
18
|
+
* upstream both read as `{}`: telling them apart means matching error codes that differ on Bun, Node and Workers.
|
|
44
19
|
*/
|
|
45
20
|
export declare function parseRequestBody(ctx: RequestBodyContext): Promise<unknown>;
|
|
46
21
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* `parseBody` is required here where the body parser makes it optional. That
|
|
52
|
-
* parser has a fallback for a context without one; this has none, because
|
|
53
|
-
* there is no second way to read an upload. A caller that cannot supply
|
|
54
|
-
* `parseBody` should fail to compile rather than silently answer "no files".
|
|
22
|
+
* The same narrowing as {@link RequestBodyContext}, but `parseBody` is required:
|
|
23
|
+
* there is no second way to read an upload, so a caller that cannot supply one
|
|
24
|
+
* should fail to compile rather than silently answer "no files".
|
|
55
25
|
*/
|
|
56
26
|
export interface RequestUploadsContext {
|
|
57
27
|
req: Pick<HonoRequest, 'parseBody'>;
|
|
58
28
|
}
|
|
59
|
-
/**
|
|
60
|
-
* The shape an upload read answers with: Hono's `{ all: true }` record, where a
|
|
61
|
-
* field repeated in the body is an array and a single one is not.
|
|
62
|
-
*/
|
|
29
|
+
/** Hono's `{ all: true }` record: a repeated field is an array, a single one is not. */
|
|
63
30
|
export type RequestUploads = Record<string, string | File | (string | File)[]>;
|
|
64
31
|
/**
|
|
65
|
-
* The one multipart read behind `Controller.file()`
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* a stack, the defect {@link parseRequestBody} fixes for the validation paths.
|
|
71
|
-
*
|
|
72
|
-
* Deliberately *not* routed through {@link parseRequestBody}, which looks like
|
|
73
|
-
* the same rule and is not: it parses without `{ all: true }` and flattens a
|
|
74
|
-
* repeated field to its first value, so sharing it would silently reduce
|
|
75
|
-
* `files()` to one file per field. `{ all: true }` is the contract here, and a
|
|
76
|
-
* malformed-body test cannot see its loss — hence the separate function.
|
|
77
|
-
*
|
|
78
|
-
* There is no media-type gate, deliberately: Hono decides the media type inside
|
|
79
|
-
* `parseBody()`, having lowercased it first. A caller that gates before calling
|
|
80
|
-
* — or that reads uploads through `Request.formData()`, whose handling of the
|
|
81
|
-
* media type is not Hono's — answers `null` for an uppercase
|
|
82
|
-
* `MULTIPART/FORM-DATA` body this returns the file for.
|
|
83
|
-
*
|
|
84
|
-
* That was measured on Bun 1.3.14, and the host half of it has already moved:
|
|
85
|
-
* Bun 1.4.0 accepts the same header `1.3.14` rejects, and Node always did. The
|
|
86
|
-
* divergence is therefore a property of *where the media type is decided*, not
|
|
87
|
-
* of any one runtime — which is the argument for deciding it in one place, and
|
|
88
|
-
* why `@guren/testing`'s controller mock reaches this function rather than
|
|
89
|
-
* restating it.
|
|
90
|
-
*
|
|
91
|
-
* try/catch rather than `.catch()`, for the reason given on the shared
|
|
92
|
-
* fallback: `parseBody` may throw synchronously as well as reject, and only one
|
|
93
|
-
* of those two shapes reaches a `.catch()`.
|
|
94
|
-
*
|
|
95
|
-
* It fails open in one direction, deliberately and for the same reason
|
|
96
|
-
* {@link parseRequestBody} does: a body already consumed upstream reads as
|
|
97
|
-
* "no upload" rather than throwing, so a middleware-ordering bug loses the 500
|
|
98
|
-
* that used to announce it. Telling that apart from a client's malformed body
|
|
99
|
-
* means matching runtime-specific error codes, which answer differently on Bun,
|
|
100
|
-
* Node and Workers.
|
|
32
|
+
* The one multipart read behind `Controller.file()`/`files()`; `{ all: true }` is
|
|
33
|
+
* the contract, which {@link parseRequestBody} (first value of a repeated field) breaks.
|
|
34
|
+
* No media-type gate: Hono lowercases it in `parseBody()`, so uppercase
|
|
35
|
+
* `MULTIPART/FORM-DATA` works here while `Request.formData()` answers `null`
|
|
36
|
+
* (Bun 1.3.14; 1.4.0 and Node accept it). try/catch as `parseBody` may throw synchronously: a bad or consumed body is no files, not a 500.
|
|
101
37
|
*/
|
|
102
38
|
export declare function parseRequestUploads(ctx: RequestUploadsContext): Promise<RequestUploads>;
|
|
103
39
|
/**
|
|
104
|
-
* The record-shaped view of {@link parseRequestBody}, for callers
|
|
105
|
-
* payload field by field
|
|
106
|
-
* `Controller.input()`/`only()`/`except()`/`has()`). A body that is not a plain
|
|
107
|
-
* object — an array, a string, `null` — becomes `{}`, because there is no
|
|
108
|
-
* field to read on one.
|
|
40
|
+
* The record-shaped view of {@link parseRequestBody}, for callers reading the
|
|
41
|
+
* payload field by field. A body that is not a plain object becomes `{}`.
|
|
109
42
|
*/
|
|
110
43
|
export declare function parseRequestPayload(ctx: Context): Promise<Record<string, unknown>>;
|
|
111
44
|
/** Narrow a parsed body to the record view described on {@link parseRequestPayload}. */
|
|
112
45
|
export declare function asRecord(body: unknown): Record<string, unknown>;
|
|
113
46
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* preference. `HonoRequest.queries` is *overloaded* (`queries(key)` returning
|
|
120
|
-
* `string[] | undefined`, `queries()` returning the record), and a `Pick` keeps
|
|
121
|
-
* both signatures, so the plain `() => Record<string, string[]>` that
|
|
122
|
-
* `@guren/testing`'s `ControllerContext` declares cannot satisfy it. Naming the
|
|
123
|
-
* one signature this function calls admits both: an overloaded member is
|
|
124
|
-
* assignable to any of its own signatures, so a real `HonoRequest` still passes.
|
|
125
|
-
*
|
|
126
|
-
* Narrowing a parameter accepts strictly more callers, so every existing one
|
|
127
|
-
* keeps passing a real `Context` unchanged.
|
|
47
|
+
* Spelled as the call shape rather than `Pick<HonoRequest, 'queries'>`, which
|
|
48
|
+
* would keep both overloads and so reject the plain
|
|
49
|
+
* `() => Record<string, string[]>` `@guren/testing` declares. Naming the one
|
|
50
|
+
* signature admits both, since an overloaded member is assignable to any of its
|
|
51
|
+
* own signatures.
|
|
128
52
|
*/
|
|
129
53
|
export interface RequestQueryContext {
|
|
130
54
|
req: {
|
|
@@ -132,19 +56,11 @@ export interface RequestQueryContext {
|
|
|
132
56
|
};
|
|
133
57
|
}
|
|
134
58
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* Materialized with `Object.fromEntries`, never by assigning into an object
|
|
141
|
-
* literal — the same rule, and for the same reason, as the form branch of
|
|
142
|
-
* {@link parseRequestBody} above. Query keys are attacker-controlled, and
|
|
143
|
-
* `flat['__proto__'] = …` hits `Object.prototype`'s inherited setter instead
|
|
144
|
-
* of defining a field: `?__proto__=one` silently vanished before reaching the
|
|
145
|
-
* schema, and `?__proto__=one&__proto__=two` set the returned record's own
|
|
146
|
-
* prototype to that array. Hono hands over a null-prototype object, so the
|
|
147
|
-
* key arrives here intact; only this last step could lose it.
|
|
59
|
+
* Query parameters with repeated keys kept as arrays and single ones as strings.
|
|
60
|
+
* Use instead of `ctx.req.query()` when feeding a validation schema.
|
|
61
|
+
* Must be materialized with `Object.fromEntries`, never by assigning into an
|
|
62
|
+
* object literal: query keys are attacker-controlled, and `flat['__proto__'] = …`
|
|
63
|
+
* hits `Object.prototype`'s inherited setter instead of defining a field.
|
|
148
64
|
*/
|
|
149
65
|
export declare function flattenRequestQueries(ctx: RequestQueryContext): Record<string, unknown>;
|
|
150
66
|
export interface ValidationIssueLike {
|
|
@@ -154,7 +70,5 @@ export interface ValidationIssueLike {
|
|
|
154
70
|
export interface ValidationErrorLike {
|
|
155
71
|
issues: ValidationIssueLike[];
|
|
156
72
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Converts a Zod-style validation error into a flat record usable by forms.
|
|
159
|
-
*/
|
|
73
|
+
/** Converts a Zod-style validation error into a flat record usable by forms. */
|
|
160
74
|
export declare function formatValidationErrors(error: ValidationErrorLike, fallbackMessage?: string): Record<string, string>;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { CursorPaginationMeta, CursorPaginatedResponse, CursorPaginatorOptions, ResourceData, ResourceClass } from './types.js';
|
|
2
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
|
-
*/
|
|
3
|
+
/** Cursor-based pagination, for infinite scroll and real-time data. */
|
|
7
4
|
export declare class CursorPaginator<T> {
|
|
8
5
|
protected _items: T[];
|
|
9
6
|
protected _perPage: number;
|
|
@@ -17,88 +14,32 @@ export declare class CursorPaginator<T> {
|
|
|
17
14
|
nextCursor?: string | null;
|
|
18
15
|
prevCursor?: string | null;
|
|
19
16
|
});
|
|
20
|
-
/**
|
|
21
|
-
* Get the paginated items.
|
|
22
|
-
*/
|
|
23
17
|
items(): T[];
|
|
24
|
-
/**
|
|
25
|
-
* Get items per page.
|
|
26
|
-
*/
|
|
27
18
|
perPage(): number;
|
|
28
|
-
/**
|
|
29
|
-
* Get the current cursor.
|
|
30
|
-
*/
|
|
31
19
|
currentCursor(): string | null;
|
|
32
|
-
/**
|
|
33
|
-
* Get the next cursor.
|
|
34
|
-
*/
|
|
35
20
|
nextCursor(): string | null;
|
|
36
|
-
/**
|
|
37
|
-
* Get the previous cursor.
|
|
38
|
-
*/
|
|
39
21
|
prevCursor(): string | null;
|
|
40
|
-
/**
|
|
41
|
-
* Check if there are more items.
|
|
42
|
-
*/
|
|
43
22
|
hasMorePages(): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Check if there are previous items.
|
|
46
|
-
*/
|
|
47
23
|
hasPreviousPages(): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Get the number of items.
|
|
50
|
-
*/
|
|
51
24
|
count(): number;
|
|
52
|
-
/**
|
|
53
|
-
* Check if empty.
|
|
54
|
-
*/
|
|
55
25
|
isEmpty(): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Check if not empty.
|
|
58
|
-
*/
|
|
59
26
|
isNotEmpty(): boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Get cursor pagination meta.
|
|
62
|
-
*/
|
|
63
27
|
meta(): CursorPaginationMeta;
|
|
64
|
-
/**
|
|
65
|
-
* Transform items to resources.
|
|
66
|
-
*/
|
|
67
28
|
toResource<R extends Resource<T>>(resourceClass: ResourceClass<T, R>): CursorPaginatedResponse<ResourceData>;
|
|
68
|
-
/**
|
|
69
|
-
* Transform to JSON.
|
|
70
|
-
*/
|
|
71
29
|
toJSON(): CursorPaginatedResponse<T>;
|
|
72
|
-
/**
|
|
73
|
-
* Map over items.
|
|
74
|
-
*/
|
|
75
30
|
map<U>(callback: (item: T, index: number) => U): CursorPaginator<U>;
|
|
76
|
-
/**
|
|
77
|
-
* Get items as array.
|
|
78
|
-
*/
|
|
79
31
|
toArray(): T[];
|
|
80
|
-
/**
|
|
81
|
-
* Iterate over items.
|
|
82
|
-
*/
|
|
83
32
|
[Symbol.iterator](): Iterator<T>;
|
|
84
|
-
/**
|
|
85
|
-
* Create cursor paginator from array with ID-based cursor.
|
|
86
|
-
*/
|
|
33
|
+
/** The cursor is the id of the last item on the previous page. */
|
|
87
34
|
static fromArray<T extends {
|
|
88
35
|
id: string | number;
|
|
89
36
|
}>(items: T[], cursor: string | null, perPage: number, options?: CursorPaginatorOptions): CursorPaginator<T>;
|
|
90
37
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Encode a cursor value.
|
|
93
|
-
*/
|
|
38
|
+
/** Encode a cursor value. */
|
|
94
39
|
export declare function encodeCursor(value: string | number | Date): string;
|
|
95
|
-
/**
|
|
96
|
-
* Decode a cursor value.
|
|
97
|
-
*/
|
|
40
|
+
/** Returns the cursor unchanged when it is not valid base64url. */
|
|
98
41
|
export declare function decodeCursor(cursor: string): string;
|
|
99
|
-
/**
|
|
100
|
-
* Create a cursor paginator.
|
|
101
|
-
*/
|
|
42
|
+
/** Create a cursor paginator. */
|
|
102
43
|
export declare function cursorPaginate<T>(items: T[], perPage: number, hasMore: boolean, options?: CursorPaginatorOptions & {
|
|
103
44
|
currentCursor?: string | null;
|
|
104
45
|
nextCursor?: string | null;
|
|
@@ -8,9 +8,7 @@ export interface PaginatedResultLike<T> {
|
|
|
8
8
|
currentPage: number;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Paginator for offset-based pagination.
|
|
13
|
-
*/
|
|
11
|
+
/** Paginator for offset-based pagination. */
|
|
14
12
|
export declare class Paginator<T> {
|
|
15
13
|
protected _items: T[];
|
|
16
14
|
protected _total: number;
|
|
@@ -18,113 +16,38 @@ export declare class Paginator<T> {
|
|
|
18
16
|
protected _currentPage: number;
|
|
19
17
|
protected _options: PaginatorOptions;
|
|
20
18
|
constructor(items: T[], total: number, perPage: number, currentPage: number, options?: PaginatorOptions);
|
|
21
|
-
/**
|
|
22
|
-
* Get the paginated items.
|
|
23
|
-
*/
|
|
24
19
|
items(): T[];
|
|
25
|
-
/**
|
|
26
|
-
* Get total number of items.
|
|
27
|
-
*/
|
|
28
20
|
total(): number;
|
|
29
|
-
/**
|
|
30
|
-
* Get items per page.
|
|
31
|
-
*/
|
|
32
21
|
perPage(): number;
|
|
33
|
-
/**
|
|
34
|
-
* Get current page number.
|
|
35
|
-
*/
|
|
36
22
|
currentPage(): number;
|
|
37
|
-
/**
|
|
38
|
-
* Get last page number.
|
|
39
|
-
*/
|
|
40
23
|
lastPage(): number;
|
|
41
|
-
/**
|
|
42
|
-
* Check if there are more pages.
|
|
43
|
-
*/
|
|
44
24
|
hasMorePages(): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Check if on first page.
|
|
47
|
-
*/
|
|
48
25
|
onFirstPage(): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Check if on last page.
|
|
51
|
-
*/
|
|
52
26
|
onLastPage(): boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Get the "from" index (1-based).
|
|
55
|
-
*/
|
|
27
|
+
/** The 1-based index of the first item on this page. */
|
|
56
28
|
firstItem(): number | null;
|
|
57
|
-
/**
|
|
58
|
-
* Get the "to" index (1-based).
|
|
59
|
-
*/
|
|
29
|
+
/** The 1-based index of the last item on this page. */
|
|
60
30
|
lastItem(): number | null;
|
|
61
|
-
/**
|
|
62
|
-
* Get the number of items on current page.
|
|
63
|
-
*/
|
|
64
31
|
count(): number;
|
|
65
|
-
/**
|
|
66
|
-
* Check if the paginator is empty.
|
|
67
|
-
*/
|
|
68
32
|
isEmpty(): boolean;
|
|
69
|
-
/**
|
|
70
|
-
* Check if the paginator is not empty.
|
|
71
|
-
*/
|
|
72
33
|
isNotEmpty(): boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Get pagination meta information.
|
|
75
|
-
*/
|
|
76
34
|
meta(): PaginationMeta;
|
|
77
|
-
/**
|
|
78
|
-
* Build URL for a page.
|
|
79
|
-
*/
|
|
80
35
|
protected url(page: number): string;
|
|
81
|
-
/**
|
|
82
|
-
* Get pagination links.
|
|
83
|
-
*/
|
|
36
|
+
/** Every URL is null until a base path is set with {@link withPath}. */
|
|
84
37
|
links(): PaginationLinks;
|
|
85
|
-
/**
|
|
86
|
-
* Set the base path for pagination links.
|
|
87
|
-
*/
|
|
88
38
|
withPath(path: string): this;
|
|
89
|
-
/**
|
|
90
|
-
* Set query parameters for pagination links.
|
|
91
|
-
*/
|
|
92
39
|
withQuery(query: Record<string, string>): this;
|
|
93
|
-
/**
|
|
94
|
-
* Set fragment for pagination links.
|
|
95
|
-
*/
|
|
96
40
|
fragment(fragment: string): this;
|
|
97
|
-
/**
|
|
98
|
-
* Transform items to resources.
|
|
99
|
-
*/
|
|
100
41
|
toResource<R extends Resource<T>>(resourceClass: ResourceClass<T, R>): PaginatedResponse<ResourceData>;
|
|
101
|
-
/**
|
|
102
|
-
* Transform to JSON.
|
|
103
|
-
*/
|
|
104
42
|
toJSON(): PaginatedResponse<T>;
|
|
105
|
-
/**
|
|
106
|
-
* Map over items.
|
|
107
|
-
*/
|
|
108
43
|
map<U>(callback: (item: T, index: number) => U): Paginator<U>;
|
|
109
|
-
/**
|
|
110
|
-
* Get items as array.
|
|
111
|
-
*/
|
|
112
44
|
toArray(): T[];
|
|
113
|
-
/**
|
|
114
|
-
* Iterate over items.
|
|
115
|
-
*/
|
|
116
45
|
[Symbol.iterator](): Iterator<T>;
|
|
117
|
-
/**
|
|
118
|
-
* Create paginator from array (slices the array).
|
|
119
|
-
*/
|
|
46
|
+
/** Slices `items` itself; `total` is the full array length. */
|
|
120
47
|
static fromArray<T>(items: T[], page: number, perPage: number, options?: PaginatorOptions): Paginator<T>;
|
|
121
|
-
/**
|
|
122
|
-
* Create paginator from an ORM-style paginated result.
|
|
123
|
-
*/
|
|
48
|
+
/** Create a paginator from an ORM-style paginated result. */
|
|
124
49
|
static fromPaginatedResult<T>(result: PaginatedResultLike<T>, options?: PaginatorOptions): Paginator<T>;
|
|
125
50
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Create a paginator.
|
|
128
|
-
*/
|
|
51
|
+
/** Create a paginator. */
|
|
129
52
|
export declare function paginate<T>(result: PaginatedResultLike<T>, options?: PaginatorOptions): Paginator<T>;
|
|
130
53
|
export declare function paginate<T>(items: T[], total: number, perPage: number, currentPage: number, options?: PaginatorOptions): Paginator<T>;
|
|
@@ -1,87 +1,31 @@
|
|
|
1
1
|
import type { ResourceData, ResourceClass } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Abstract base class for API resources
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `TData`
|
|
7
|
-
*
|
|
8
|
-
* it every subclass had to restate the payload in an override whose only body
|
|
9
|
-
* was `return super.toJSON() as PostResourceData` — a cast that says nothing a
|
|
10
|
-
* type parameter cannot, and one nothing checks against the `toArray()` right
|
|
11
|
-
* above it.
|
|
12
|
-
*
|
|
13
|
-
* It defaults to `ResourceData` so `Resource<T>` and those overrides keep
|
|
14
|
-
* compiling: an override narrowing the return type stays assignable to the
|
|
15
|
-
* base. The polymorphic alternative (`toJSON(): ReturnType<this['toArray']>`)
|
|
16
|
-
* needs no parameter at all but rejects every existing override, which is a
|
|
17
|
-
* breaking change for code the scaffolds have been emitting all along.
|
|
18
|
-
*
|
|
19
|
-
* `TData` is a claim about `toArray()`, not about `toJSON()`'s every key:
|
|
20
|
-
* `additional()` takes arbitrary `ResourceData` and is spread *after* the
|
|
21
|
-
* payload, so a key that collides overwrites a typed field while the return
|
|
22
|
-
* type still reads `TData`. That hole is not new — it is what the
|
|
23
|
-
* `super.toJSON() as PostResourceData` override asserted past — but the type
|
|
24
|
-
* parameter does not close it. `additional()` is for keys beside the payload.
|
|
3
|
+
* Abstract base class for API resources: transforms model data into an API
|
|
4
|
+
* response payload. `TData` names what `toArray()` builds, so `toJSON()` reports
|
|
5
|
+
* it too; it defaults to `ResourceData` so `Resource<T>` and narrowing overrides
|
|
6
|
+
* keep compiling. `TData` is a claim about `toArray()` only — `additional()` is
|
|
7
|
+
* spread *after* the payload, so a colliding key overwrites a typed field.
|
|
25
8
|
*/
|
|
26
9
|
export declare abstract class Resource<T, TData extends ResourceData = ResourceData> {
|
|
27
|
-
/**
|
|
28
|
-
* The underlying resource.
|
|
29
|
-
*/
|
|
30
10
|
protected resource: T;
|
|
31
|
-
/**
|
|
32
|
-
* Additional data to merge with the resource.
|
|
33
|
-
*/
|
|
34
11
|
protected additionalData: ResourceData;
|
|
35
12
|
constructor(resource: T);
|
|
36
|
-
/**
|
|
37
|
-
* Transform the resource into an array/object.
|
|
38
|
-
* Must be implemented by subclasses.
|
|
39
|
-
*/
|
|
40
13
|
abstract toArray(): TData;
|
|
41
|
-
/**
|
|
42
|
-
* Transform the resource to JSON.
|
|
43
|
-
*/
|
|
44
14
|
toJSON(): TData;
|
|
45
|
-
/**
|
|
46
|
-
* Add additional data to the resource.
|
|
47
|
-
*/
|
|
15
|
+
/** Keys merged beside the payload, overriding colliding `toArray()` keys. */
|
|
48
16
|
additional(data: ResourceData): this;
|
|
49
|
-
/**
|
|
50
|
-
* Conditionally include a value.
|
|
51
|
-
*/
|
|
52
17
|
when<V>(condition: boolean, value: V | (() => V)): V | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* Conditionally include a value with a default.
|
|
55
|
-
*/
|
|
56
18
|
whenOr<V>(condition: boolean, value: V | (() => V), defaultValue: V): V;
|
|
57
|
-
/**
|
|
58
|
-
* Include a value only if a relation is loaded.
|
|
59
|
-
*/
|
|
19
|
+
/** Loaded means the relation key is present and not `undefined`. */
|
|
60
20
|
whenLoaded<V>(relation: string, value: V | (() => V), defaultValue?: V): V | undefined;
|
|
61
|
-
/**
|
|
62
|
-
* Include a value only if it's not null/undefined.
|
|
63
|
-
*/
|
|
64
21
|
whenNotNull<V>(value: V | null | undefined): V | undefined;
|
|
65
|
-
/**
|
|
66
|
-
* Merge another resource's data.
|
|
67
|
-
*/
|
|
68
22
|
merge(data: ResourceData): ResourceData;
|
|
69
|
-
/**
|
|
70
|
-
* Create a new resource instance.
|
|
71
|
-
*/
|
|
72
23
|
static make<T, R extends Resource<T>>(this: new (resource: T) => R, resource: T): R;
|
|
73
|
-
/**
|
|
74
|
-
* Create a collection of resources.
|
|
75
|
-
*/
|
|
76
24
|
static collection<T, R extends Resource<T>>(this: new (resource: T) => R, resources: T[]): ResourceData[];
|
|
77
25
|
}
|
|
78
|
-
/**
|
|
79
|
-
* Create a resource collection from a resource class.
|
|
80
|
-
*/
|
|
26
|
+
/** Create a resource collection from a resource class. */
|
|
81
27
|
export declare function collect<T, R extends Resource<T>>(resources: T[], resourceClass: ResourceClass<T, R>): ResourceData[];
|
|
82
|
-
/**
|
|
83
|
-
* Simple resource wrapper for objects without transformation.
|
|
84
|
-
*/
|
|
28
|
+
/** Simple resource wrapper for objects that need no transformation. */
|
|
85
29
|
export declare class JsonResource<T extends Record<string, unknown>> extends Resource<T> {
|
|
86
30
|
toArray(): ResourceData;
|
|
87
31
|
}
|
|
@@ -1,60 +1,26 @@
|
|
|
1
1
|
import type { ResourceData, ResourceClass } from './types.js';
|
|
2
2
|
import type { Resource } from './Resource.js';
|
|
3
|
-
/**
|
|
4
|
-
* Collection of resources with additional metadata.
|
|
5
|
-
*/
|
|
3
|
+
/** Collection of resources with additional metadata. */
|
|
6
4
|
export declare class ResourceCollection<T, R extends Resource<T>> {
|
|
7
5
|
protected resources: T[];
|
|
8
6
|
protected resourceClass: ResourceClass<T, R>;
|
|
9
7
|
protected additionalData: ResourceData;
|
|
10
8
|
protected wrapKey: string | null;
|
|
11
9
|
constructor(resources: T[], resourceClass: ResourceClass<T, R>);
|
|
12
|
-
/**
|
|
13
|
-
* Transform all resources to an array.
|
|
14
|
-
*/
|
|
15
10
|
toArray(): ResourceData[];
|
|
16
|
-
/**
|
|
17
|
-
* Add additional data to the collection response.
|
|
18
|
-
*/
|
|
11
|
+
/** Keys merged beside the wrapped list. */
|
|
19
12
|
additional(data: ResourceData): this;
|
|
20
|
-
/**
|
|
21
|
-
* Set the wrapper key for the collection.
|
|
22
|
-
*/
|
|
13
|
+
/** Defaults to `'data'`; `null` disables wrapping. */
|
|
23
14
|
wrap(key: string | null): this;
|
|
24
|
-
/**
|
|
25
|
-
* Disable wrapping.
|
|
26
|
-
*/
|
|
27
15
|
withoutWrapping(): this;
|
|
28
|
-
/**
|
|
29
|
-
* Get the number of resources.
|
|
30
|
-
*/
|
|
31
16
|
count(): number;
|
|
32
|
-
/**
|
|
33
|
-
* Check if collection is empty.
|
|
34
|
-
*/
|
|
35
17
|
isEmpty(): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Check if collection is not empty.
|
|
38
|
-
*/
|
|
39
18
|
isNotEmpty(): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Transform to JSON response.
|
|
42
|
-
*/
|
|
19
|
+
/** Unwrapped with additional data, the list moves under an `items` key. */
|
|
43
20
|
toJSON(): ResourceData;
|
|
44
|
-
/**
|
|
45
|
-
* Map over the resources.
|
|
46
|
-
*/
|
|
47
21
|
map<U>(callback: (resource: T, index: number) => U): U[];
|
|
48
|
-
/**
|
|
49
|
-
* Filter resources.
|
|
50
|
-
*/
|
|
51
22
|
filter(callback: (resource: T, index: number) => boolean): ResourceCollection<T, R>;
|
|
52
|
-
/**
|
|
53
|
-
* Get the underlying resources.
|
|
54
|
-
*/
|
|
23
|
+
/** The untransformed records. */
|
|
55
24
|
all(): T[];
|
|
56
|
-
/**
|
|
57
|
-
* Create a resource collection.
|
|
58
|
-
*/
|
|
59
25
|
static make<T, R extends Resource<T>>(resources: T[], resourceClass: ResourceClass<T, R>): ResourceCollection<T, R>;
|
|
60
26
|
}
|