@venizia/ignis 0.4.8-9 → 0.5.0-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/esm/base/applications/base.js +5 -2
- package/dist/esm/base/applications/base.js.map +1 -1
- package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js +1 -1
- package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js.map +1 -1
- package/dist/esm/components/api-reference/common/keys.d.ts +2 -1
- package/dist/esm/components/api-reference/common/keys.js +4 -1
- package/dist/esm/components/api-reference/common/keys.js.map +1 -1
- package/dist/esm/components/api-reference/common/types.d.ts +7 -4
- package/dist/esm/components/api-reference/common/types.js.map +1 -1
- package/dist/esm/components/api-reference/component.js +8 -3
- package/dist/esm/components/api-reference/component.js.map +1 -1
- package/dist/esm/components/auth/authenticate/component.js +13 -18
- package/dist/esm/components/auth/authenticate/component.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +3 -3
- package/dist/esm/components/auth/authenticate/controllers/factory.js +1 -1
- package/dist/esm/components/auth/authenticate/controllers/factory.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/jwks/controller.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/jwks/definitions.d.ts +2 -2
- package/dist/esm/components/auth/authenticate/controllers/service-certs/controller.js.map +1 -1
- package/dist/esm/components/auth/authenticate/controllers/service-certs/definitions.d.ts +2 -2
- package/dist/esm/components/auth/authenticate/services/basic/service.js +1 -1
- package/dist/esm/components/auth/authenticate/services/basic/service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +5 -3
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +19 -2
- package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.d.ts +3 -3
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.d.ts +3 -3
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js +2 -2
- package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jws.service.d.ts +3 -3
- package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js +1 -1
- package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/jwks-url-policy.d.ts +10 -22
- package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js +16 -112
- package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/service/signer.service.d.ts +11 -0
- package/dist/esm/components/auth/authenticate/services/service/signer.service.js +18 -0
- package/dist/esm/components/auth/authenticate/services/service/signer.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/services/service/verifier.service.js +1 -1
- package/dist/esm/components/auth/authenticate/services/service/verifier.service.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/basic.strategy.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/jwks/issuer.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/jwks/verifier.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/jws.strategy.js.map +1 -1
- package/dist/esm/components/auth/authenticate/strategies/service.strategy.js.map +1 -1
- package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +1 -2
- package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
- package/dist/esm/components/auth/authorize/component.js.map +1 -1
- package/dist/esm/components/controller/grpc/common/types.d.ts +1 -1
- package/dist/esm/components/controller/grpc/common/types.js +4 -1
- package/dist/esm/components/controller/grpc/common/types.js.map +1 -1
- package/dist/esm/components/controller/grpc/grpc.component.js.map +1 -1
- package/dist/esm/components/health-check/common/keys.d.ts +4 -2
- package/dist/esm/components/health-check/common/keys.js +7 -2
- package/dist/esm/components/health-check/common/keys.js.map +1 -1
- package/dist/esm/components/health-check/common/types.d.ts +1 -1
- package/dist/esm/components/health-check/common/types.js.map +1 -1
- package/dist/esm/components/health-check/component.js +1 -3
- package/dist/esm/components/health-check/component.js.map +1 -1
- package/dist/esm/components/mail/common/constants.d.ts +32 -14
- package/dist/esm/components/mail/common/constants.js +25 -32
- package/dist/esm/components/mail/common/constants.js.map +1 -1
- package/dist/esm/components/mail/common/errors.d.ts +19 -1
- package/dist/esm/components/mail/common/errors.js +13 -1
- package/dist/esm/components/mail/common/errors.js.map +1 -1
- package/dist/esm/components/mail/common/keys.d.ts +14 -11
- package/dist/esm/components/mail/common/keys.js +34 -11
- package/dist/esm/components/mail/common/keys.js.map +1 -1
- package/dist/esm/components/mail/common/types/message.d.ts +7 -4
- package/dist/esm/components/mail/common/types/message.js.map +1 -1
- package/dist/esm/components/mail/common/types/options.d.ts +54 -10
- package/dist/esm/components/mail/common/types/options.js.map +1 -1
- package/dist/esm/components/mail/common/types/queue.d.ts +25 -12
- package/dist/esm/components/mail/common/types/queue.js.map +1 -1
- package/dist/esm/components/mail/common/types/template.d.ts +8 -4
- package/dist/esm/components/mail/common/types/template.js.map +1 -1
- package/dist/esm/components/mail/common/types/verification.d.ts +1 -0
- package/dist/esm/components/mail/common/types/verification.js.map +1 -1
- package/dist/esm/components/mail/component.js +11 -2
- package/dist/esm/components/mail/component.js.map +1 -1
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +3 -1
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +27 -33
- package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
- package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +11 -6
- package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.d.ts +2 -3
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
- package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.d.ts +2 -3
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
- package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
- package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
- package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
- package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
- package/dist/esm/components/mail/services/generators/numeric-code.d.ts +1 -6
- package/dist/esm/components/mail/services/generators/numeric-code.js +3 -31
- package/dist/esm/components/mail/services/generators/numeric-code.js.map +1 -1
- package/dist/esm/components/mail/services/generators/random-token.d.ts +4 -1
- package/dist/esm/components/mail/services/generators/random-token.js +9 -6
- package/dist/esm/components/mail/services/generators/random-token.js.map +1 -1
- package/dist/esm/components/mail/services/mail.service.d.ts +1 -2
- package/dist/esm/components/mail/services/mail.service.js +22 -19
- package/dist/esm/components/mail/services/mail.service.js.map +1 -1
- package/dist/esm/components/mail/services/template.service.d.ts +8 -6
- package/dist/esm/components/mail/services/template.service.js +34 -33
- package/dist/esm/components/mail/services/template.service.js.map +1 -1
- package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
- package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
- package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
- package/dist/esm/components/mail/utilities/header.utility.js +44 -0
- package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
- package/dist/esm/components/mail/utilities/index.d.ts +2 -0
- package/dist/esm/components/mail/utilities/index.js +2 -0
- package/dist/esm/components/mail/utilities/index.js.map +1 -1
- package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
- package/dist/esm/components/mail/utilities/mime.utility.js +12 -58
- package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
- package/dist/esm/components/mail/utilities/template-renderer.utility.d.ts +31 -0
- package/dist/esm/components/mail/utilities/template-renderer.utility.js +184 -0
- package/dist/esm/components/mail/utilities/template-renderer.utility.js.map +1 -0
- package/dist/esm/components/mail/utilities/type.utility.d.ts +2 -3
- package/dist/esm/components/mail/utilities/type.utility.js +6 -7
- package/dist/esm/components/mail/utilities/type.utility.js.map +1 -1
- package/dist/esm/components/request-tracker/component.d.ts +2 -1
- package/dist/esm/components/request-tracker/component.js +5 -5
- package/dist/esm/components/request-tracker/component.js.map +1 -1
- package/dist/esm/components/server-info/common/keys.d.ts +2 -1
- package/dist/esm/components/server-info/common/keys.js +4 -1
- package/dist/esm/components/server-info/common/keys.js.map +1 -1
- package/dist/esm/components/server-info/common/types.d.ts +1 -1
- package/dist/esm/components/server-info/common/types.js.map +1 -1
- package/dist/esm/components/server-info/component.js +1 -3
- package/dist/esm/components/server-info/component.js.map +1 -1
- package/dist/esm/components/socket-io/common/keys.d.ts +9 -6
- package/dist/esm/components/socket-io/common/keys.js +19 -6
- package/dist/esm/components/socket-io/common/keys.js.map +1 -1
- package/dist/esm/components/socket-io/component.js +1 -1
- package/dist/esm/components/socket-io/component.js.map +1 -1
- package/dist/esm/components/socket-io/handlers/bun.handler.d.ts +13 -3
- package/dist/esm/components/socket-io/handlers/bun.handler.js.map +1 -1
- package/dist/esm/components/static-asset/common/constants.d.ts +51 -24
- package/dist/esm/components/static-asset/common/constants.js +75 -47
- package/dist/esm/components/static-asset/common/constants.js.map +1 -1
- package/dist/esm/components/static-asset/common/errors.d.ts +30 -35
- package/dist/esm/components/static-asset/common/errors.js +31 -33
- package/dist/esm/components/static-asset/common/errors.js.map +1 -1
- package/dist/esm/components/static-asset/common/index.d.ts +1 -1
- package/dist/esm/components/static-asset/common/index.js +1 -1
- package/dist/esm/components/static-asset/common/index.js.map +1 -1
- package/dist/esm/components/static-asset/common/keys.d.ts +14 -2
- package/dist/esm/components/static-asset/common/keys.js +17 -2
- package/dist/esm/components/static-asset/common/keys.js.map +1 -1
- package/dist/esm/components/static-asset/common/types.d.ts +267 -147
- package/dist/esm/components/static-asset/common/types.js.map +1 -1
- package/dist/esm/components/static-asset/common/validation.d.ts +10 -0
- package/dist/esm/components/static-asset/common/validation.js +8 -0
- package/dist/esm/components/static-asset/common/validation.js.map +1 -0
- package/dist/esm/components/static-asset/component.d.ts +4 -2
- package/dist/esm/components/static-asset/component.js +27 -31
- package/dist/esm/components/static-asset/component.js.map +1 -1
- package/dist/esm/components/static-asset/controller/factory.d.ts +37 -79
- package/dist/esm/components/static-asset/controller/factory.js +26 -917
- package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
- package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
- package/dist/esm/components/static-asset/controller/index.js +1 -0
- package/dist/esm/components/static-asset/controller/index.js.map +1 -1
- package/dist/esm/components/static-asset/controller/routes/context.d.ts +62 -0
- package/dist/esm/components/static-asset/controller/routes/context.js +45 -0
- package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/definition.d.ts +40 -0
- package/dist/esm/components/static-asset/controller/routes/definition.js +83 -0
- package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/direct-upload.d.ts +3 -0
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js +153 -0
- package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/labels.d.ts +16 -0
- package/dist/esm/components/static-asset/controller/routes/labels.js +19 -0
- package/dist/esm/components/static-asset/controller/routes/labels.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/objects.d.ts +7 -0
- package/dist/esm/components/static-asset/controller/routes/objects.js +193 -0
- package/dist/esm/components/static-asset/controller/routes/objects.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/serve.d.ts +29 -0
- package/dist/esm/components/static-asset/controller/routes/serve.js +152 -0
- package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/table.d.ts +12 -0
- package/dist/esm/components/static-asset/controller/routes/table.js +52 -0
- package/dist/esm/components/static-asset/controller/routes/table.js.map +1 -0
- package/dist/esm/components/static-asset/controller/routes/upload.d.ts +10 -0
- package/dist/esm/components/static-asset/controller/routes/upload.js +175 -0
- package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
- package/dist/esm/components/static-asset/index.d.ts +2 -1
- package/dist/esm/components/static-asset/index.js +2 -1
- package/dist/esm/components/static-asset/index.js.map +1 -1
- package/dist/esm/components/static-asset/models/base.model.d.ts +4 -4
- package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
- package/dist/esm/components/static-asset/services/commitment.service.d.ts +103 -0
- package/dist/esm/components/static-asset/services/commitment.service.js +252 -0
- package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -0
- package/dist/esm/components/static-asset/services/index.d.ts +3 -0
- package/dist/esm/components/static-asset/services/index.js +3 -0
- package/dist/esm/components/static-asset/services/index.js.map +1 -0
- package/dist/esm/components/static-asset/services/policy.service.d.ts +45 -0
- package/dist/esm/components/static-asset/services/policy.service.js +104 -0
- package/dist/esm/components/static-asset/services/policy.service.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +28 -0
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js +112 -0
- package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.js +160 -0
- package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/index.d.ts +6 -0
- package/dist/esm/components/static-asset/utilities/index.js +6 -0
- package/dist/esm/components/static-asset/utilities/index.js.map +1 -0
- package/dist/esm/components/static-asset/{ingest.d.ts → utilities/ingest.utility.d.ts} +8 -8
- package/dist/esm/components/static-asset/{ingest.js → utilities/ingest.utility.js} +21 -23
- package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -0
- package/dist/esm/components/static-asset/{controller/key-scope.d.ts → utilities/key-scope.utility.d.ts} +21 -2
- package/dist/esm/components/static-asset/utilities/key-scope.utility.js +74 -0
- package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -0
- package/dist/esm/components/static-asset/{controller/meta-link.d.ts → utilities/meta-link.utility.d.ts} +9 -9
- package/dist/esm/components/static-asset/{controller/meta-link.js → utilities/meta-link.utility.js} +10 -10
- package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +16 -0
- package/dist/esm/components/static-asset/utilities/object-link.utility.js +20 -0
- package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.d.ts +39 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.js +53 -0
- package/dist/esm/components/static-asset/utilities/pinned-file.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +43 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.js +71 -0
- package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +5 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.js +5 -0
- package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
- package/dist/esm/components/websocket/common/keys.d.ts +12 -10
- package/dist/esm/components/websocket/common/keys.js +31 -10
- package/dist/esm/components/websocket/common/keys.js.map +1 -1
- package/dist/esm/components/websocket/component.js.map +1 -1
- package/dist/esm/testing/assert-application-boots.d.ts +2 -2
- package/dist/esm/testing/assert-application-boots.js +6 -2
- package/dist/esm/testing/assert-application-boots.js.map +1 -1
- package/dist/presets/app/preset.json +4 -4
- package/dist/presets/lib/preset.json +3 -3
- package/dist/presets/shared/preset.json +1 -1
- package/package.json +8 -8
- package/dist/esm/components/static-asset/common/commit-token.d.ts +0 -28
- package/dist/esm/components/static-asset/common/commit-token.js +0 -48
- package/dist/esm/components/static-asset/common/commit-token.js.map +0 -1
- package/dist/esm/components/static-asset/controller/base.definition.d.ts +0 -30
- package/dist/esm/components/static-asset/controller/base.definition.js +0 -307
- package/dist/esm/components/static-asset/controller/base.definition.js.map +0 -1
- package/dist/esm/components/static-asset/controller/key-scope.js +0 -41
- package/dist/esm/components/static-asset/controller/key-scope.js.map +0 -1
- package/dist/esm/components/static-asset/controller/meta-link.js.map +0 -1
- package/dist/esm/components/static-asset/controller/route-options.d.ts +0 -29
- package/dist/esm/components/static-asset/controller/route-options.js +0 -47
- package/dist/esm/components/static-asset/controller/route-options.js.map +0 -1
- package/dist/esm/components/static-asset/ingest.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IBucketRef, IFileStat, IObjectRef, IStorageHelper, IUploadResult } from '@venizia/ignis-helpers';
|
|
2
|
-
import type {
|
|
3
|
-
import type { TMetaLinkConfig, TStaticAssetStorageType,
|
|
4
|
-
export declare class
|
|
2
|
+
import type { TMetaLink, TMetaLinkCompatibleSchema } from '../models/index.js';
|
|
3
|
+
import type { TMetaLinkConfig, TStaticAssetStorageType, TStaticAssetUploadLabels } from '../common/index.js';
|
|
4
|
+
export declare class StaticAssetMetaLinkUtility {
|
|
5
5
|
/** What a stat says about one stored object: the columns a refresh rewrites and a new row starts from. */
|
|
6
6
|
private static buildStoredObjectFacts;
|
|
7
7
|
/** The upload result of an object already in storage, so a commit or a recreate writes its row the way an upload does. */
|
|
@@ -14,20 +14,20 @@ export declare class AssetMetaLink {
|
|
|
14
14
|
}): IUploadResult;
|
|
15
15
|
/** The MetaLink row for one stored object. Every path that creates a row goes through here, so each lands exactly the row an ordinary upload does. */
|
|
16
16
|
static createRow(opts: {
|
|
17
|
-
metaLink: TMetaLinkConfig<
|
|
17
|
+
metaLink: TMetaLinkConfig<TMetaLinkCompatibleSchema>;
|
|
18
18
|
helper: IStorageHelper;
|
|
19
19
|
storage: TStaticAssetStorageType;
|
|
20
20
|
uploadResult: IUploadResult;
|
|
21
21
|
fileStat: IFileStat;
|
|
22
|
-
|
|
23
|
-
}): Promise<
|
|
22
|
+
labels: TStaticAssetUploadLabels;
|
|
23
|
+
}): Promise<TMetaLink>;
|
|
24
24
|
/**
|
|
25
25
|
* Rewrites the stored-object facts on every row of the pair. Rows per pair are deliberately not
|
|
26
26
|
* unique, and each keeps its own labels and storage type. A `createMetaLink` hook owns `link` and
|
|
27
27
|
* `metadata`, so with one only the stat columns change; without one, `metadata` is merged per row.
|
|
28
28
|
*/
|
|
29
29
|
static refreshRows(opts: {
|
|
30
|
-
metaLink: TMetaLinkConfig<
|
|
30
|
+
metaLink: TMetaLinkConfig<TMetaLinkCompatibleSchema>;
|
|
31
31
|
helper: IStorageHelper;
|
|
32
32
|
bucket: IBucketRef;
|
|
33
33
|
object: IObjectRef;
|
|
@@ -35,7 +35,7 @@ export declare class AssetMetaLink {
|
|
|
35
35
|
fileStat: IFileStat;
|
|
36
36
|
}): Promise<{
|
|
37
37
|
count: number;
|
|
38
|
-
data:
|
|
38
|
+
data: TMetaLink[];
|
|
39
39
|
}>;
|
|
40
40
|
}
|
|
41
|
-
//# sourceMappingURL=meta-link.d.ts.map
|
|
41
|
+
//# sourceMappingURL=meta-link.utility.d.ts.map
|
package/dist/esm/components/static-asset/{controller/meta-link.js → utilities/meta-link.utility.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ResolverUtility } from '@venizia/ignis-helpers/common';
|
|
2
|
-
export class
|
|
2
|
+
export class StaticAssetMetaLinkUtility {
|
|
3
3
|
/** What a stat says about one stored object: the columns a refresh rewrites and a new row starts from. */
|
|
4
4
|
static buildStoredObjectFacts(opts) {
|
|
5
5
|
const { helper, object, link, fileStat } = opts;
|
|
@@ -28,9 +28,9 @@ export class AssetMetaLink {
|
|
|
28
28
|
}
|
|
29
29
|
/** The MetaLink row for one stored object. Every path that creates a row goes through here, so each lands exactly the row an ordinary upload does. */
|
|
30
30
|
static async createRow(opts) {
|
|
31
|
-
const { metaLink, helper, storage, uploadResult, fileStat,
|
|
31
|
+
const { metaLink, helper, storage, uploadResult, fileStat, labels } = opts;
|
|
32
32
|
if (metaLink.createMetaLink) {
|
|
33
|
-
const created = await metaLink.createMetaLink({ uploadResult, fileStat,
|
|
33
|
+
const created = await metaLink.createMetaLink({ uploadResult, fileStat, labels });
|
|
34
34
|
return created.data;
|
|
35
35
|
}
|
|
36
36
|
// Resolved per call so an application that swaps the repository is not pinned to the first one.
|
|
@@ -39,19 +39,19 @@ export class AssetMetaLink {
|
|
|
39
39
|
data: {
|
|
40
40
|
bucketName: uploadResult.bucket.name,
|
|
41
41
|
objectName: uploadResult.object.key,
|
|
42
|
-
...
|
|
42
|
+
...StaticAssetMetaLinkUtility.buildStoredObjectFacts({
|
|
43
43
|
helper,
|
|
44
44
|
object: uploadResult.object,
|
|
45
45
|
link: uploadResult.link,
|
|
46
46
|
fileStat,
|
|
47
47
|
}),
|
|
48
48
|
storageType: storage,
|
|
49
|
-
principalId:
|
|
50
|
-
principalType:
|
|
51
|
-
variant:
|
|
49
|
+
principalId: labels.principalId,
|
|
50
|
+
principalType: labels.principalType,
|
|
51
|
+
variant: labels.variant,
|
|
52
52
|
// Absent leaves the column default rather than writing 0, so a row the caller never
|
|
53
53
|
// ordered is indistinguishable from a legacy one.
|
|
54
|
-
sequence:
|
|
54
|
+
sequence: labels.sequence,
|
|
55
55
|
},
|
|
56
56
|
});
|
|
57
57
|
return created.data;
|
|
@@ -64,7 +64,7 @@ export class AssetMetaLink {
|
|
|
64
64
|
static async refreshRows(opts) {
|
|
65
65
|
const { metaLink, helper, bucket, object, link, fileStat } = opts;
|
|
66
66
|
const repository = await ResolverUtility.resolveValueAsync({ value: metaLink.repository });
|
|
67
|
-
const { mimetype, size, etag, isSynced } =
|
|
67
|
+
const { mimetype, size, etag, isSynced } = StaticAssetMetaLinkUtility.buildStoredObjectFacts({
|
|
68
68
|
helper,
|
|
69
69
|
object,
|
|
70
70
|
link,
|
|
@@ -88,4 +88,4 @@ export class AssetMetaLink {
|
|
|
88
88
|
return { count: updated.count, data: merged.map((result) => result.data) };
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
//# sourceMappingURL=meta-link.js.map
|
|
91
|
+
//# sourceMappingURL=meta-link.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta-link.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/meta-link.utility.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAIhE,MAAM,OAAO,0BAA0B;IACrC,0GAA0G;IAClG,MAAM,CAAC,sBAAsB,CAAC,IAKrC;QACC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAEhD,OAAO;YACL,IAAI;YACJ,2DAA2D;YAC3D,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,IAAI,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;YACrF,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;IAED,0HAA0H;IAC1H,MAAM,CAAC,uBAAuB,CAAC,IAM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D,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC9C,CAAC;QAED,4FAA4F;QAC5F,6FAA6F;QAC7F,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9B,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACf,UAAU,CAAC,UAAU,CAAC;YACpB,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE;SAC9D,CAAC,CACH,CACF,CAAC;QAEF,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;IAC7E,CAAC;CACF","sourcesContent":["import type {\n IBucketRef,\n IFileStat,\n IObjectRef,\n IStorageHelper,\n IUploadResult,\n} from '@venizia/ignis-helpers';\nimport { ResolverUtility } from '@venizia/ignis-helpers/common';\nimport type { TMetaLink, TMetaLinkCompatibleSchema } from '../models';\nimport type { TMetaLinkConfig, TStaticAssetStorageType, TStaticAssetUploadLabels } from '../common';\n\nexport class StaticAssetMetaLinkUtility {\n /** What a stat says about one stored object: the columns a refresh rewrites and a new row starts from. */\n private static buildStoredObjectFacts(opts: {\n helper: IStorageHelper;\n object: IObjectRef;\n link: string;\n fileStat: IFileStat;\n }) {\n const { helper, object, link, fileStat } = opts;\n\n return {\n link,\n // The column is NOT NULL and a backend may report nothing.\n mimetype: fileStat.metadata?.mimetype ?? helper.getMimeType({ filename: object.key }),\n size: fileStat.size,\n etag: fileStat.etag,\n metadata: fileStat.metadata,\n isSynced: true,\n };\n }\n\n /** The upload result of an object already in storage, so a commit or a recreate writes its row the way an upload does. */\n static buildStoredUploadResult(opts: {\n helper: IStorageHelper;\n bucket: IBucketRef;\n object: IObjectRef;\n link: string;\n fileStat: IFileStat;\n }): IUploadResult {\n const { helper, bucket, object, link, fileStat } = opts;\n\n return {\n bucket,\n object: {\n key: object.key,\n size: fileStat.size,\n contentType: fileStat.metadata?.mimetype ?? helper.getMimeType({ filename: object.key }),\n },\n link,\n };\n }\n\n /** The MetaLink row for one stored object. Every path that creates a row goes through here, so each lands exactly the row an ordinary upload does. */\n static async createRow(opts: {\n metaLink: TMetaLinkConfig<TMetaLinkCompatibleSchema>;\n helper: IStorageHelper;\n storage: TStaticAssetStorageType;\n uploadResult: IUploadResult;\n fileStat: IFileStat;\n labels: TStaticAssetUploadLabels;\n }): Promise<TMetaLink> {\n const { metaLink, helper, storage, uploadResult, fileStat, labels } = opts;\n\n if (metaLink.createMetaLink) {\n const created = await metaLink.createMetaLink({ uploadResult, fileStat, labels });\n\n return created.data;\n }\n\n // Resolved per call so an application that swaps the repository is not pinned to the first one.\n const repository = await ResolverUtility.resolveValueAsync({ value: metaLink.repository });\n const created = await repository.create({\n data: {\n bucketName: uploadResult.bucket.name,\n objectName: uploadResult.object.key,\n ...StaticAssetMetaLinkUtility.buildStoredObjectFacts({\n helper,\n object: uploadResult.object,\n link: uploadResult.link,\n fileStat,\n }),\n storageType: storage,\n principalId: labels.principalId,\n principalType: labels.principalType,\n variant: labels.variant,\n // Absent leaves the column default rather than writing 0, so a row the caller never\n // ordered is indistinguishable from a legacy one.\n sequence: labels.sequence,\n },\n });\n\n return created.data;\n }\n\n /**\n * Rewrites the stored-object facts on every row of the pair. Rows per pair are deliberately not\n * unique, and each keeps its own labels and storage type. A `createMetaLink` hook owns `link` and\n * `metadata`, so with one only the stat columns change; without one, `metadata` is merged per row.\n */\n static async refreshRows(opts: {\n metaLink: TMetaLinkConfig<TMetaLinkCompatibleSchema>;\n helper: IStorageHelper;\n bucket: IBucketRef;\n object: IObjectRef;\n link: string;\n fileStat: IFileStat;\n }): Promise<{ count: number; data: TMetaLink[] }> {\n const { metaLink, helper, bucket, object, link, fileStat } = opts;\n\n const repository = await ResolverUtility.resolveValueAsync({ value: metaLink.repository });\n const { mimetype, size, etag, isSynced } = StaticAssetMetaLinkUtility.buildStoredObjectFacts({\n helper,\n object,\n link,\n fileStat,\n });\n const statColumns = { mimetype, size, etag, isSynced };\n\n const updated = await repository.updateBy({\n data: metaLink.createMetaLink ? statColumns : { ...statColumns, link },\n where: { bucketName: bucket.name, objectName: object.key },\n });\n const rows = updated.data ?? [];\n\n if (metaLink.createMetaLink || !fileStat.metadata) {\n return { count: updated.count, data: rows };\n }\n\n // One UPDATE per row: each merge starts from that row's own keys, which the statement above\n // returned untouched and which no single engine-neutral statement over the pair can express.\n const merged = await Promise.all(\n rows.map((row) =>\n repository.updateById({\n id: row.id,\n data: { metadata: { ...row.metadata, ...fileStat.metadata } },\n }),\n ),\n );\n\n return { count: updated.count, data: merged.map((result) => result.data) };\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IObjectLocation } from '@venizia/ignis-helpers';
|
|
2
|
+
/** Builds the URL of an object in the shape its controller serves. */
|
|
3
|
+
export declare class StaticAssetObjectLinkUtility {
|
|
4
|
+
/** The mount path may be declared with or without a leading slash; a link must carry exactly one. */
|
|
5
|
+
static normalizeBasePath(opts: {
|
|
6
|
+
basePath: string;
|
|
7
|
+
}): string;
|
|
8
|
+
/** Encodes an object path into a SINGLE url segment: `{objectName}` matches one segment only, so `/` must be percent-encoded too (Hono decodes it back before the handler reads the param). */
|
|
9
|
+
private static encodeObjectPath;
|
|
10
|
+
/** The URL of one object, in the shape its controller serves: a raw path with `rawObjectPath`, a percent-encoded one without. */
|
|
11
|
+
static build(opts: IObjectLocation & {
|
|
12
|
+
basePath: string;
|
|
13
|
+
rawObjectPath?: boolean;
|
|
14
|
+
}): string;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=object-link.utility.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Builds the URL of an object in the shape its controller serves. */
|
|
2
|
+
export class StaticAssetObjectLinkUtility {
|
|
3
|
+
/** The mount path may be declared with or without a leading slash; a link must carry exactly one. */
|
|
4
|
+
static normalizeBasePath(opts) {
|
|
5
|
+
return opts.basePath.startsWith('/') ? opts.basePath : `/${opts.basePath}`;
|
|
6
|
+
}
|
|
7
|
+
/** Encodes an object path into a SINGLE url segment: `{objectName}` matches one segment only, so `/` must be percent-encoded too (Hono decodes it back before the handler reads the param). */
|
|
8
|
+
static encodeObjectPath(opts) {
|
|
9
|
+
return encodeURIComponent(opts.objectPath);
|
|
10
|
+
}
|
|
11
|
+
/** The URL of one object, in the shape its controller serves: a raw path with `rawObjectPath`, a percent-encoded one without. */
|
|
12
|
+
static build(opts) {
|
|
13
|
+
const { basePath, object, rawObjectPath = false } = opts;
|
|
14
|
+
const objectSegment = rawObjectPath
|
|
15
|
+
? object.key
|
|
16
|
+
: StaticAssetObjectLinkUtility.encodeObjectPath({ objectPath: object.key });
|
|
17
|
+
return `${basePath}/objects/${objectSegment}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=object-link.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-link.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/object-link.utility.ts"],"names":[],"mappings":"AAEA,sEAAsE;AACtE,MAAM,OAAO,4BAA4B;IACvC,qGAAqG;IACrG,MAAM,CAAC,iBAAiB,CAAC,IAA0B;QACjD,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC7E,CAAC;IAED,+LAA+L;IACvL,MAAM,CAAC,gBAAgB,CAAC,IAA4B;QAC1D,OAAO,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED,iIAAiI;IACjI,MAAM,CAAC,KAAK,CAAC,IAAqE;QAChF,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;QACzD,MAAM,aAAa,GAAG,aAAa;YACjC,CAAC,CAAC,MAAM,CAAC,GAAG;YACZ,CAAC,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QAE9E,OAAO,GAAG,QAAQ,YAAY,aAAa,EAAE,CAAC;IAChD,CAAC;CACF","sourcesContent":["import type { IObjectLocation } from '@venizia/ignis-helpers';\n\n/** Builds the URL of an object in the shape its controller serves. */\nexport class StaticAssetObjectLinkUtility {\n /** The mount path may be declared with or without a leading slash; a link must carry exactly one. */\n static normalizeBasePath(opts: { basePath: string }): string {\n return opts.basePath.startsWith('/') ? opts.basePath : `/${opts.basePath}`;\n }\n\n /** Encodes an object path into a SINGLE url segment: `{objectName}` matches one segment only, so `/` must be percent-encoded too (Hono decodes it back before the handler reads the param). */\n private static encodeObjectPath(opts: { objectPath: string }): string {\n return encodeURIComponent(opts.objectPath);\n }\n\n /** The URL of one object, in the shape its controller serves: a raw path with `rawObjectPath`, a percent-encoded one without. */\n static build(opts: IObjectLocation & { basePath: string; rawObjectPath?: boolean }): string {\n const { basePath, object, rawObjectPath = false } = opts;\n const objectSegment = rawObjectPath\n ? object.key\n : StaticAssetObjectLinkUtility.encodeObjectPath({ objectPath: object.key });\n\n return `${basePath}/objects/${objectSegment}`;\n }\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type IFileStat, type IObjectLocation, type IStorageHelper } from '@venizia/ignis-helpers';
|
|
2
|
+
import { type IStaticAssetPin } from '../common/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* The pending file as `validation.handler` sees it. Every read asks the storage for exactly the
|
|
5
|
+
* content that was pinned, so a handler cannot parse bytes that are not the ones `commit` will copy:
|
|
6
|
+
* a read that finds other content or no object throws `UPLOAD_CHANGED`.
|
|
7
|
+
*/
|
|
8
|
+
export declare class StaticAssetPinnedFile {
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly size: number;
|
|
11
|
+
private readonly helper;
|
|
12
|
+
private readonly location;
|
|
13
|
+
private readonly pin;
|
|
14
|
+
constructor(opts: {
|
|
15
|
+
helper: IStorageHelper;
|
|
16
|
+
location: IObjectLocation;
|
|
17
|
+
pin: IStaticAssetPin;
|
|
18
|
+
size: number;
|
|
19
|
+
});
|
|
20
|
+
/** What a read or a copy requires of the object: the exact version when the pin has one, else the ETag. */
|
|
21
|
+
static conditionOf(opts: {
|
|
22
|
+
pin: IStaticAssetPin;
|
|
23
|
+
}): {
|
|
24
|
+
ifMatch?: string;
|
|
25
|
+
versionId?: string;
|
|
26
|
+
};
|
|
27
|
+
/** The pin of what the storage holds now. An object with no ETag cannot be pinned. */
|
|
28
|
+
static pinOf(opts: {
|
|
29
|
+
stat: IFileStat;
|
|
30
|
+
scope: string;
|
|
31
|
+
}): IStaticAssetPin;
|
|
32
|
+
stream(opts?: {
|
|
33
|
+
range?: {
|
|
34
|
+
start: number;
|
|
35
|
+
end?: number;
|
|
36
|
+
};
|
|
37
|
+
}): Promise<ReadableStream<Uint8Array>>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=pinned-file.utility.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { StorageUtility, } from '@venizia/ignis-helpers';
|
|
2
|
+
import { getError } from '@venizia/ignis-helpers/core';
|
|
3
|
+
import { StaticAssetErrors } from '../common/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* The pending file as `validation.handler` sees it. Every read asks the storage for exactly the
|
|
6
|
+
* content that was pinned, so a handler cannot parse bytes that are not the ones `commit` will copy:
|
|
7
|
+
* a read that finds other content or no object throws `UPLOAD_CHANGED`.
|
|
8
|
+
*/
|
|
9
|
+
export class StaticAssetPinnedFile {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
this.helper = opts.helper;
|
|
12
|
+
this.location = opts.location;
|
|
13
|
+
this.pin = opts.pin;
|
|
14
|
+
this.key = opts.location.object.key;
|
|
15
|
+
this.size = opts.size;
|
|
16
|
+
}
|
|
17
|
+
/** What a read or a copy requires of the object: the exact version when the pin has one, else the ETag. */
|
|
18
|
+
static conditionOf(opts) {
|
|
19
|
+
const { pin } = opts;
|
|
20
|
+
return pin.versionId === undefined ? { ifMatch: pin.etag } : { versionId: pin.versionId };
|
|
21
|
+
}
|
|
22
|
+
/** The pin of what the storage holds now. An object with no ETag cannot be pinned. */
|
|
23
|
+
static pinOf(opts) {
|
|
24
|
+
const { stat, scope } = opts;
|
|
25
|
+
if (!stat.etag) {
|
|
26
|
+
throw getError({
|
|
27
|
+
message: `[${scope}] The storage reported no ETag for the pending object | a pinned validation needs one`,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
etag: stat.etag,
|
|
32
|
+
versionId: StorageUtility.realVersionId({ value: stat.versionId }),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async stream(opts) {
|
|
36
|
+
try {
|
|
37
|
+
const stream = await this.helper.getObjectStream({
|
|
38
|
+
...this.location,
|
|
39
|
+
range: opts?.range,
|
|
40
|
+
...StaticAssetPinnedFile.conditionOf({ pin: this.pin }),
|
|
41
|
+
});
|
|
42
|
+
return stream;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (StorageUtility.isPreconditionFailedError({ error }) ||
|
|
46
|
+
StorageUtility.isNotFoundError({ error })) {
|
|
47
|
+
throw getError({ error: StaticAssetErrors.UPLOAD_CHANGED, cause: error });
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=pinned-file.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinned-file.utility.js","sourceRoot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AAC,SAAS,EAAE,CAAC;SACnE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAEZ;QACC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;gBAC/C,GAAG,IAAI,CAAC,QAAQ;gBAChB,KAAK,EAAE,IAAI,EAAE,KAAK;gBAClB,GAAG,qBAAqB,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;aACxD,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IACE,cAAc,CAAC,yBAAyB,CAAC,EAAE,KAAK,EAAE,CAAC;gBACnD,cAAc,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,CAAC,EACzC,CAAC;gBACD,MAAM,QAAQ,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YAC5E,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n StorageUtility,\n type IFileStat,\n type IObjectLocation,\n type IStorageHelper,\n} from '@venizia/ignis-helpers';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { StaticAssetErrors, type IStaticAssetPin } from '../common';\n\n/**\n * The pending file as `validation.handler` sees it. Every read asks the storage for exactly the\n * content that was pinned, so a handler cannot parse bytes that are not the ones `commit` will copy:\n * a read that finds other content or no object throws `UPLOAD_CHANGED`.\n */\nexport class StaticAssetPinnedFile {\n readonly key: string;\n readonly size: number;\n\n private readonly helper: IStorageHelper;\n private readonly location: IObjectLocation;\n private readonly pin: IStaticAssetPin;\n\n constructor(opts: {\n helper: IStorageHelper;\n location: IObjectLocation;\n pin: IStaticAssetPin;\n size: number;\n }) {\n this.helper = opts.helper;\n this.location = opts.location;\n this.pin = opts.pin;\n this.key = opts.location.object.key;\n this.size = opts.size;\n }\n\n /** What a read or a copy requires of the object: the exact version when the pin has one, else the ETag. */\n static conditionOf(opts: { pin: IStaticAssetPin }): { ifMatch?: string; versionId?: string } {\n const { pin } = opts;\n\n return pin.versionId === undefined ? { ifMatch: pin.etag } : { versionId: pin.versionId };\n }\n\n /** The pin of what the storage holds now. An object with no ETag cannot be pinned. */\n static pinOf(opts: { stat: IFileStat; scope: string }): IStaticAssetPin {\n const { stat, scope } = opts;\n\n if (!stat.etag) {\n throw getError({\n message: `[${scope}] The storage reported no ETag for the pending object | a pinned validation needs one`,\n });\n }\n\n return {\n etag: stat.etag,\n versionId: StorageUtility.realVersionId({ value: stat.versionId }),\n };\n }\n\n async stream(opts?: {\n range?: { start: number; end?: number };\n }): Promise<ReadableStream<Uint8Array>> {\n try {\n const stream = await this.helper.getObjectStream({\n ...this.location,\n range: opts?.range,\n ...StaticAssetPinnedFile.conditionOf({ pin: this.pin }),\n });\n\n return stream;\n } catch (error) {\n if (\n StorageUtility.isPreconditionFailedError({ error }) ||\n StorageUtility.isNotFoundError({ error })\n ) {\n throw getError({ error: StaticAssetErrors.UPLOAD_CHANGED, cause: error });\n }\n\n throw error;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { IAuthRouteConfig } from '../../../base/index.js';
|
|
2
|
+
import { type TStaticAssetRouteConfig, type TStaticAssetRouteKey } from '../common/index.js';
|
|
3
|
+
import type { IStaticAssetResolvedEntry, IStaticAssetResolvedRoute } from './entry.utility.js';
|
|
4
|
+
/** What a route is registered with: the application's overrides, and the auth it ends up with. */
|
|
5
|
+
export type TStaticAssetRouteOverride = Omit<TStaticAssetRouteConfig, 'authenticate' | 'authorize'> & Pick<IAuthRouteConfig, 'authenticate' | 'authorize'>;
|
|
6
|
+
export declare class StaticAssetRouteOptionsUtility {
|
|
7
|
+
/** Multipart framing of one file (boundary, `Content-Disposition` with a file name, `Content-Type`), allowed on top of its `maxBytes` in the route's body limit. */
|
|
8
|
+
static readonly ENVELOPE_BYTES_PER_FILE: number;
|
|
9
|
+
/** The non-file parts of an upload (policy fields, the closing boundary), allowed once in the route's body limit. */
|
|
10
|
+
static readonly ENVELOPE_BYTES_BASE: number;
|
|
11
|
+
/** The routes `auth.publicRead` leaves open: reading ONE object. Listing is not reading an object. */
|
|
12
|
+
private static readonly PUBLIC_READ_ROUTES;
|
|
13
|
+
/**
|
|
14
|
+
* Reads one built-in route's configuration: whether it is registered, the Hono overrides, and the
|
|
15
|
+
* authentication and authorization it ends up with.
|
|
16
|
+
*
|
|
17
|
+
* Auth is resolved by the same resolver the CRUD factory uses: a route's own config beats the
|
|
18
|
+
* entry's `auth`, and `{ skip: true }` opens the route. `publicRead` is the entry's default for
|
|
19
|
+
* the two read routes and loses to any auth the route sets itself.
|
|
20
|
+
*/
|
|
21
|
+
static readRoute(opts: {
|
|
22
|
+
key: TStaticAssetRouteKey;
|
|
23
|
+
route?: IStaticAssetResolvedRoute;
|
|
24
|
+
auth?: IStaticAssetResolvedEntry<never>['auth'];
|
|
25
|
+
}): {
|
|
26
|
+
isEnabled: boolean;
|
|
27
|
+
override: TStaticAssetRouteOverride;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The route's body validator reads the whole multipart body, so a limit checked in the handler arrives
|
|
31
|
+
* too late to save any memory. Appended after the application's own middleware, so a check of its own
|
|
32
|
+
* still answers first.
|
|
33
|
+
*
|
|
34
|
+
* The limit is `maxFiles` files of `maxBytes` each, plus their multipart framing. A chunked body, which
|
|
35
|
+
* has no declared length, is counted too. The per-file check in the handler still decides each file.
|
|
36
|
+
*/
|
|
37
|
+
static appendBodyLimit(opts: {
|
|
38
|
+
middleware: TStaticAssetRouteConfig['middleware'];
|
|
39
|
+
maxBytes: number;
|
|
40
|
+
maxFiles: number;
|
|
41
|
+
}): NonNullable<TStaticAssetRouteConfig['middleware']>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=route-options.utility.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BodyLimits, RouteConfigResolver } from '@venizia/ignis-kernel';
|
|
2
|
+
import { StaticAssetRouteKeys, } from '../common/index.js';
|
|
3
|
+
export class StaticAssetRouteOptionsUtility {
|
|
4
|
+
/** Multipart framing of one file (boundary, `Content-Disposition` with a file name, `Content-Type`), allowed on top of its `maxBytes` in the route's body limit. */
|
|
5
|
+
static { this.ENVELOPE_BYTES_PER_FILE = 4 * 1024; }
|
|
6
|
+
/** The non-file parts of an upload (policy fields, the closing boundary), allowed once in the route's body limit. */
|
|
7
|
+
static { this.ENVELOPE_BYTES_BASE = 64 * 1024; }
|
|
8
|
+
/** The routes `auth.publicRead` leaves open: reading ONE object. Listing is not reading an object. */
|
|
9
|
+
static { this.PUBLIC_READ_ROUTES = new Set([
|
|
10
|
+
StaticAssetRouteKeys.GET_OBJECT_BY_NAME,
|
|
11
|
+
StaticAssetRouteKeys.DOWNLOAD_OBJECT_BY_NAME,
|
|
12
|
+
]); }
|
|
13
|
+
/**
|
|
14
|
+
* Reads one built-in route's configuration: whether it is registered, the Hono overrides, and the
|
|
15
|
+
* authentication and authorization it ends up with.
|
|
16
|
+
*
|
|
17
|
+
* Auth is resolved by the same resolver the CRUD factory uses: a route's own config beats the
|
|
18
|
+
* entry's `auth`, and `{ skip: true }` opens the route. `publicRead` is the entry's default for
|
|
19
|
+
* the two read routes and loses to any auth the route sets itself.
|
|
20
|
+
*/
|
|
21
|
+
static readRoute(opts) {
|
|
22
|
+
const { key, route, auth } = opts;
|
|
23
|
+
const { authenticate, authorize, ...override } = route?.override ?? {};
|
|
24
|
+
const isPublicRead = auth?.isPublicRead === true &&
|
|
25
|
+
StaticAssetRouteOptionsUtility.PUBLIC_READ_ROUTES.has(key) &&
|
|
26
|
+
authenticate == null &&
|
|
27
|
+
authorize == null;
|
|
28
|
+
const endpoint = isPublicRead
|
|
29
|
+
? { authenticate: { skip: true } }
|
|
30
|
+
: { authenticate, authorize };
|
|
31
|
+
// An entry-level `skip` is no default at all: nothing to inherit.
|
|
32
|
+
const entryAuthenticate = auth?.authenticate == null || auth.authenticate.skip === true ? undefined : auth.authenticate;
|
|
33
|
+
const entryAuthorize = auth?.authorize == null || (!Array.isArray(auth.authorize) && 'skip' in auth.authorize)
|
|
34
|
+
? undefined
|
|
35
|
+
: auth.authorize;
|
|
36
|
+
return {
|
|
37
|
+
isEnabled: route?.isEnabled ?? true,
|
|
38
|
+
override: {
|
|
39
|
+
...override,
|
|
40
|
+
authenticate: RouteConfigResolver.resolveAuthenticate({
|
|
41
|
+
controller: entryAuthenticate,
|
|
42
|
+
endpoint: endpoint.authenticate,
|
|
43
|
+
}),
|
|
44
|
+
authorize: RouteConfigResolver.resolveAuthorize({
|
|
45
|
+
controller: entryAuthorize,
|
|
46
|
+
endpoint,
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The route's body validator reads the whole multipart body, so a limit checked in the handler arrives
|
|
53
|
+
* too late to save any memory. Appended after the application's own middleware, so a check of its own
|
|
54
|
+
* still answers first.
|
|
55
|
+
*
|
|
56
|
+
* The limit is `maxFiles` files of `maxBytes` each, plus their multipart framing. A chunked body, which
|
|
57
|
+
* has no declared length, is counted too. The per-file check in the handler still decides each file.
|
|
58
|
+
*/
|
|
59
|
+
static appendBodyLimit(opts) {
|
|
60
|
+
const { middleware, maxBytes, maxFiles } = opts;
|
|
61
|
+
const limit = BodyLimits.route({
|
|
62
|
+
maxSize: maxFiles * (maxBytes + StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_PER_FILE) +
|
|
63
|
+
StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_BASE,
|
|
64
|
+
});
|
|
65
|
+
if (!middleware) {
|
|
66
|
+
return [limit];
|
|
67
|
+
}
|
|
68
|
+
return Array.isArray(middleware) ? [...middleware, limit] : [middleware, limit];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=route-options.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-options.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/route-options.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAExE,OAAO,EACL,oBAAoB,GAGrB,MAAM,WAAW,CAAC;AAUnB,MAAM,OAAO,8BAA8B;IACzC,oKAAoK;aACpJ,4BAAuB,GAAG,CAAC,GAAG,IAAI,CAAC;IAEnD,qHAAqH;aACrG,wBAAmB,GAAG,EAAE,GAAG,IAAI,CAAC;IAEhD,sGAAsG;aAC9E,uBAAkB,GAAsC,IAAI,GAAG,CAAC;QACtF,oBAAoB,CAAC,kBAAkB;QACvC,oBAAoB,CAAC,uBAAuB;KAC7C,CAAC,CAAC;IAEH;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAC,IAIhB;QACC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAClC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,QAAQ,IAAI,EAAE,CAAC;QAEvE,MAAM,YAAY,GAChB,IAAI,EAAE,YAAY,KAAK,IAAI;YAC3B,8BAA8B,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC;YAC1D,YAAY,IAAI,IAAI;YACpB,SAAS,IAAI,IAAI,CAAC;QACpB,MAAM,QAAQ,GAAqB,YAAY;YAC7C,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;YAClC,CAAC,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;QAEhC,kEAAkE;QAClE,MAAM,iBAAiB,GACrB,IAAI,EAAE,YAAY,IAAI,IAAI,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,SA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el';\nimport type { IAuthRouteConfig, TRouteAuthConfig } from '@/base';\nimport {\n StaticAssetRouteKeys,\n type TStaticAssetRouteConfig,\n type TStaticAssetRouteKey,\n} from '../common';\nimport type { IStaticAssetResolvedEntry, IStaticAssetResolvedRoute } from './entry.utility';\n\n/** What a route is registered with: the application's overrides, and the auth it ends up with. */\nexport type TStaticAssetRouteOverride = Omit<\n TStaticAssetRouteConfig,\n 'authenticate' | 'authorize'\n> &\n Pick<IAuthRouteConfig, 'authenticate' | 'authorize'>;\n\nexport class StaticAssetRouteOptionsUtility {\n /** Multipart framing of one file (boundary, `Content-Disposition` with a file name, `Content-Type`), allowed on top of its `maxBytes` in the route's body limit. */\n static readonly ENVELOPE_BYTES_PER_FILE = 4 * 1024;\n\n /** The non-file parts of an upload (policy fields, the closing boundary), allowed once in the route's body limit. */\n static readonly ENVELOPE_BYTES_BASE = 64 * 1024;\n\n /** The routes `auth.publicRead` leaves open: reading ONE object. Listing is not reading an object. */\n private static readonly PUBLIC_READ_ROUTES: ReadonlySet<TStaticAssetRouteKey> = new Set([\n StaticAssetRouteKeys.GET_OBJECT_BY_NAME,\n StaticAssetRouteKeys.DOWNLOAD_OBJECT_BY_NAME,\n ]);\n\n /**\n * Reads one built-in route's configuration: whether it is registered, the Hono overrides, and the\n * authentication and authorization it ends up with.\n *\n * Auth is resolved by the same resolver the CRUD factory uses: a route's own config beats the\n * entry's `auth`, and `{ skip: true }` opens the route. `publicRead` is the entry's default for\n * the two read routes and loses to any auth the route sets itself.\n */\n static readRoute(opts: {\n key: TStaticAssetRouteKey;\n route?: IStaticAssetResolvedRoute;\n auth?: IStaticAssetResolvedEntry<never>['auth'];\n }): { isEnabled: boolean; override: TStaticAssetRouteOverride } {\n const { key, route, auth } = opts;\n const { authenticate, authorize, ...override } = route?.override ?? {};\n\n const isPublicRead =\n auth?.isPublicRead === true &&\n StaticAssetRouteOptionsUtility.PUBLIC_READ_ROUTES.has(key) &&\n authenticate == null &&\n authorize == null;\n const endpoint: TRouteAuthConfig = isPublicRead\n ? { authenticate: { skip: true } }\n : { authenticate, authorize };\n\n // An entry-level `skip` is no default at all: nothing to inherit.\n const entryAuthenticate =\n auth?.authenticate == null || auth.authenticate.skip === true ? undefined : auth.authenticate;\n const entryAuthorize =\n auth?.authorize == null || (!Array.isArray(auth.authorize) && 'skip' in auth.authorize)\n ? undefined\n : auth.authorize;\n\n return {\n isEnabled: route?.isEnabled ?? true,\n override: {\n ...override,\n authenticate: RouteConfigResolver.resolveAuthenticate({\n controller: entryAuthenticate,\n endpoint: endpoint.authenticate,\n }),\n authorize: RouteConfigResolver.resolveAuthorize({\n controller: entryAuthorize,\n endpoint,\n }),\n },\n };\n }\n\n /**\n * The route's body validator reads the whole multipart body, so a limit checked in the handler arrives\n * too late to save any memory. Appended after the application's own middleware, so a check of its own\n * still answers first.\n *\n * The limit is `maxFiles` files of `maxBytes` each, plus their multipart framing. A chunked body, which\n * has no declared length, is counted too. The per-file check in the handler still decides each file.\n */\n static appendBodyLimit(opts: {\n middleware: TStaticAssetRouteConfig['middleware'];\n maxBytes: number;\n maxFiles: number;\n }): NonNullable<TStaticAssetRouteConfig['middleware']> {\n const { middleware, maxBytes, maxFiles } = opts;\n\n const limit = BodyLimits.route({\n maxSize:\n maxFiles * (maxBytes + StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_PER_FILE) +\n StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_BASE,\n });\n\n if (!middleware) {\n return [limit];\n }\n\n return Array.isArray(middleware) ? [...middleware, limit] : [middleware, limit];\n }\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ToggleUtility } from '@venizia/ignis-kernel';
|
|
2
|
+
/** Reads the `{ use }` switches an entry is written with. The logic lives in the kernel's `ToggleUtility`, shared with controllers. */
|
|
3
|
+
export declare class StaticAssetToggleUtility extends ToggleUtility {
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=toggle.utility.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ToggleUtility } from '@venizia/ignis-kernel';
|
|
2
|
+
/** Reads the `{ use }` switches an entry is written with. The logic lives in the kernel's `ToggleUtility`, shared with controllers. */
|
|
3
|
+
export class StaticAssetToggleUtility extends ToggleUtility {
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=toggle.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/toggle.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,uIAAuI;AACvI,MAAM,OAAO,wBAAyB,SAAQ,aAAa;CAAG","sourcesContent":["import { ToggleUtility } from '@venizia/ignis-kernel';\n\n/** Reads the `{ use }` switches an entry is written with. The logic lives in the kernel's `ToggleUtility`, shared with controllers. */\nexport class StaticAssetToggleUtility extends ToggleUtility {}\n"]}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import type { AbstractRedisHelper, TWebSocketAuthenticateFn, TWebSocketClientConnectedFn, TWebSocketClientDisconnectedFn, TWebSocketHandshakeFn, TWebSocketMessageHandler, TWebSocketOutboundTransformer, TWebSocketValidateRoomFn, WebSocketServerHelper } from '@venizia/ignis-helpers';
|
|
2
|
+
import type { IServerOptions } from './types.js';
|
|
1
3
|
/** Container keys of the WebSocket component: the server instance, its options, the Redis connection and the handlers an application binds. */
|
|
2
4
|
export declare class WebSocketBindingKeys {
|
|
3
|
-
static readonly WEBSOCKET_INSTANCE
|
|
4
|
-
static readonly SERVER_OPTIONS
|
|
5
|
-
static readonly REDIS_CONNECTION
|
|
6
|
-
static readonly AUTHENTICATE_HANDLER
|
|
7
|
-
static readonly VALIDATE_ROOM_HANDLER
|
|
8
|
-
static readonly CLIENT_CONNECTED_HANDLER
|
|
9
|
-
static readonly CLIENT_DISCONNECTED_HANDLER
|
|
10
|
-
static readonly MESSAGE_HANDLER
|
|
11
|
-
static readonly OUTBOUND_TRANSFORMER
|
|
12
|
-
static readonly HANDSHAKE_HANDLER
|
|
5
|
+
static readonly WEBSOCKET_INSTANCE: import("@venizia/ignis-inversion").TBindingKey<WebSocketServerHelper<Record<string, unknown>, Record<string, unknown>>>;
|
|
6
|
+
static readonly SERVER_OPTIONS: import("@venizia/ignis-inversion").TBindingKey<Partial<IServerOptions>>;
|
|
7
|
+
static readonly REDIS_CONNECTION: import("@venizia/ignis-inversion").TBindingKey<AbstractRedisHelper<import("@venizia/ignis-helpers").TRedisClient> | null>;
|
|
8
|
+
static readonly AUTHENTICATE_HANDLER: import("@venizia/ignis-inversion").TBindingKey<TWebSocketAuthenticateFn | null>;
|
|
9
|
+
static readonly VALIDATE_ROOM_HANDLER: import("@venizia/ignis-inversion").TBindingKey<TWebSocketValidateRoomFn | null>;
|
|
10
|
+
static readonly CLIENT_CONNECTED_HANDLER: import("@venizia/ignis-inversion").TBindingKey<TWebSocketClientConnectedFn | null>;
|
|
11
|
+
static readonly CLIENT_DISCONNECTED_HANDLER: import("@venizia/ignis-inversion").TBindingKey<TWebSocketClientDisconnectedFn | null>;
|
|
12
|
+
static readonly MESSAGE_HANDLER: import("@venizia/ignis-inversion").TBindingKey<TWebSocketMessageHandler | null>;
|
|
13
|
+
static readonly OUTBOUND_TRANSFORMER: import("@venizia/ignis-inversion").TBindingKey<TWebSocketOutboundTransformer | null>;
|
|
14
|
+
static readonly HANDSHAKE_HANDLER: import("@venizia/ignis-inversion").TBindingKey<TWebSocketHandshakeFn | null>;
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -1,14 +1,35 @@
|
|
|
1
|
+
import { BindingKeys } from '@venizia/ignis-inversion';
|
|
1
2
|
/** Container keys of the WebSocket component: the server instance, its options, the Redis connection and the handlers an application binds. */
|
|
2
3
|
export class WebSocketBindingKeys {
|
|
3
|
-
static { this.WEBSOCKET_INSTANCE =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
static { this.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
static { this.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
static { this.
|
|
4
|
+
static { this.WEBSOCKET_INSTANCE = BindingKeys.build({
|
|
5
|
+
key: '@app/websocket/instance',
|
|
6
|
+
}); }
|
|
7
|
+
static { this.SERVER_OPTIONS = BindingKeys.build({
|
|
8
|
+
key: '@app/websocket/server-options',
|
|
9
|
+
}); }
|
|
10
|
+
static { this.REDIS_CONNECTION = BindingKeys.build({
|
|
11
|
+
key: '@app/websocket/redis-connection',
|
|
12
|
+
}); }
|
|
13
|
+
static { this.AUTHENTICATE_HANDLER = BindingKeys.build({
|
|
14
|
+
key: '@app/websocket/authenticate-handler',
|
|
15
|
+
}); }
|
|
16
|
+
static { this.VALIDATE_ROOM_HANDLER = BindingKeys.build({
|
|
17
|
+
key: '@app/websocket/validate-room-handler',
|
|
18
|
+
}); }
|
|
19
|
+
static { this.CLIENT_CONNECTED_HANDLER = BindingKeys.build({
|
|
20
|
+
key: '@app/websocket/client-connected-handler',
|
|
21
|
+
}); }
|
|
22
|
+
static { this.CLIENT_DISCONNECTED_HANDLER = BindingKeys.build({
|
|
23
|
+
key: '@app/websocket/client-disconnected-handler',
|
|
24
|
+
}); }
|
|
25
|
+
static { this.MESSAGE_HANDLER = BindingKeys.build({
|
|
26
|
+
key: '@app/websocket/message-handler',
|
|
27
|
+
}); }
|
|
28
|
+
static { this.OUTBOUND_TRANSFORMER = BindingKeys.build({
|
|
29
|
+
key: '@app/websocket/outbound-transformer',
|
|
30
|
+
}); }
|
|
31
|
+
static { this.HANDSHAKE_HANDLER = BindingKeys.build({
|
|
32
|
+
key: '@app/websocket/handshake-handler',
|
|
33
|
+
}); }
|
|
13
34
|
}
|
|
14
35
|
//# sourceMappingURL=keys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../../../src/components/websocket/common/keys.ts"],"names":[],"mappings":"AAAA,+IAA+I;AAC/I,MAAM,OAAO,oBAAoB;aACf,uBAAkB,GAAG,
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../../../src/components/websocket/common/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAcvD,+IAA+I;AAC/I,MAAM,OAAO,oBAAoB;aACf,uBAAkB,GAAG,WAAW,CAAC,KAAK,CAAwB;QAC5E,GAAG,EAAE,yBAAyB;KAC/B,CAAC,CAAC;aAEa,mBAAc,GAAG,WAAW,CAAC,KAAK,CAA0B;QAC1E,GAAG,EAAE,+BAA+B;KACrC,CAAC,CAAC;aAEa,qBAAgB,GAAG,WAAW,CAAC,KAAK,CAA6B;QAC/E,GAAG,EAAE,iCAAiC;KACvC,CAAC,CAAC;aAEa,yBAAoB,GAAG,WAAW,CAAC,KAAK,CAAkC;QACxF,GAAG,EAAE,qCAAqC;KAC3C,CAAC,CAAC;aAEa,0BAAqB,GAAG,WAAW,CAAC,KAAK,CAAkC;QACzF,GAAG,EAAE,sCAAsC;KAC5C,CAAC,CAAC;aAEa,6BAAwB,GAAG,WAAW,CAAC,KAAK,CAAqC;QAC/F,GAAG,EAAE,yCAAyC;KAC/C,CAAC,CAAC;aAEa,gCAA2B,GACzC,WAAW,CAAC,KAAK,CAAwC;QACvD,GAAG,EAAE,4CAA4C;KAClD,CAAC,CAAC;aAEW,oBAAe,GAAG,WAAW,CAAC,KAAK,CAAkC;QACnF,GAAG,EAAE,gCAAgC;KACtC,CAAC,CAAC;aAEa,yBAAoB,GAAG,WAAW,CAAC,KAAK,CAAuC;QAC7F,GAAG,EAAE,qCAAqC;KAC3C,CAAC,CAAC;aAEa,sBAAiB,GAAG,WAAW,CAAC,KAAK,CAA+B;QAClF,GAAG,EAAE,kCAAkC;KACxC,CAAC,CAAC","sourcesContent":["import { BindingKeys } from '@venizia/ignis-inversion';\nimport type {\n AbstractRedisHelper,\n TWebSocketAuthenticateFn,\n TWebSocketClientConnectedFn,\n TWebSocketClientDisconnectedFn,\n TWebSocketHandshakeFn,\n TWebSocketMessageHandler,\n TWebSocketOutboundTransformer,\n TWebSocketValidateRoomFn,\n WebSocketServerHelper,\n} from '@venizia/ignis-helpers';\nimport type { IServerOptions } from './types';\n\n/** Container keys of the WebSocket component: the server instance, its options, the Redis connection and the handlers an application binds. */\nexport class WebSocketBindingKeys {\n static readonly WEBSOCKET_INSTANCE = BindingKeys.build<WebSocketServerHelper>({\n key: '@app/websocket/instance',\n });\n\n static readonly SERVER_OPTIONS = BindingKeys.build<Partial<IServerOptions>>({\n key: '@app/websocket/server-options',\n });\n\n static readonly REDIS_CONNECTION = BindingKeys.build<AbstractRedisHelper | null>({\n key: '@app/websocket/redis-connection',\n });\n\n static readonly AUTHENTICATE_HANDLER = BindingKeys.build<TWebSocketAuthenticateFn | null>({\n key: '@app/websocket/authenticate-handler',\n });\n\n static readonly VALIDATE_ROOM_HANDLER = BindingKeys.build<TWebSocketValidateRoomFn | null>({\n key: '@app/websocket/validate-room-handler',\n });\n\n static readonly CLIENT_CONNECTED_HANDLER = BindingKeys.build<TWebSocketClientConnectedFn | null>({\n key: '@app/websocket/client-connected-handler',\n });\n\n static readonly CLIENT_DISCONNECTED_HANDLER =\n BindingKeys.build<TWebSocketClientDisconnectedFn | null>({\n key: '@app/websocket/client-disconnected-handler',\n });\n\n static readonly MESSAGE_HANDLER = BindingKeys.build<TWebSocketMessageHandler | null>({\n key: '@app/websocket/message-handler',\n });\n\n static readonly OUTBOUND_TRANSFORMER = BindingKeys.build<TWebSocketOutboundTransformer | null>({\n key: '@app/websocket/outbound-transformer',\n });\n\n static readonly HANDSHAKE_HANDLER = BindingKeys.build<TWebSocketHandshakeFn | null>({\n key: '@app/websocket/handshake-handler',\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../src/components/websocket/component.ts"],"names":[],"mappings":";;;;;;;;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,CAAC,CAAC;IACjC,CAAC;CACF,CAAA;AAtMY,kBAAkB;IAI1B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAJ1C,kBAAkB,CAsM9B","sourcesContent":["import { type BaseApplication, type TBunServerInstance } from '@/base/applications';\nimport { BaseComponent } from '@venizia/ignis-kernel';\nimport { inject } from '@/base/metadata';\nimport { CoreBindings } from '@venizia/ignis-kernel';\nimport { Binding } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport {\n type AbstractRedisHelper,\n isRedisHelper,\n type TWebSocketAuthenticateFn,\n type TWebSocketClientConnectedFn,\n type TWebSocketClientDisconnectedFn,\n type TWebSocketMessageHandler,\n type TWebSocketHandshakeFn,\n type TWebSocketOutboundTransformer,\n type TWebSocketValidateRoomFn,\n WebSocketDefaults,\n WebSocketServerHelper,\n} from '@venizia/ignis-helpers';\nimport {\n WebSocketBindingKeys,\n DEFAULT_SERVER_OPTIONS,\n type IResolvedBindings,\n type IServerOptions,\n} from './common';\nimport { WebSocketBunHandler } from './handlers';\n\n/** Starts a WebSocket server on Bun after the application starts. Requires a Redis helper at `WebSocketBindingKeys.REDIS_CONNECTION` and an authenticate handler at `AUTHENTICATE_HANDLER`; binding throws without them. */\nexport class WebSocketComponent extends BaseComponent {\n protected serverOptions: IServerOptions;\n\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: WebSocketComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [WebSocketBindingKeys.SERVER_OPTIONS]: Binding.bind<Partial<IServerOptions>>({\n key: WebSocketBindingKeys.SERVER_OPTIONS,\n }).toValue(DEFAULT_SERVER_OPTIONS),\n\n [WebSocketBindingKeys.REDIS_CONNECTION]: Binding.bind<AbstractRedisHelper | null>({\n key: WebSocketBindingKeys.REDIS_CONNECTION,\n }).toValue(null),\n\n [WebSocketBindingKeys.AUTHENTICATE_HANDLER]: Binding.bind<TWebSocketAuthenticateFn | null>({\n key: WebSocketBindingKeys.AUTHENTICATE_HANDLER,\n }).toValue(null),\n\n [WebSocketBindingKeys.VALIDATE_ROOM_HANDLER]: Binding.bind<TWebSocketValidateRoomFn | null>(\n {\n key: WebSocketBindingKeys.VALIDATE_ROOM_HANDLER,\n },\n ).toValue(null),\n\n [WebSocketBindingKeys.CLIENT_CONNECTED_HANDLER]:\n Binding.bind<TWebSocketClientConnectedFn | null>({\n key: WebSocketBindingKeys.CLIENT_CONNECTED_HANDLER,\n }).toValue(null),\n\n [WebSocketBindingKeys.CLIENT_DISCONNECTED_HANDLER]:\n Binding.bind<TWebSocketClientDisconnectedFn | null>({\n key: WebSocketBindingKeys.CLIENT_DISCONNECTED_HANDLER,\n }).toValue(null),\n\n [WebSocketBindingKeys.MESSAGE_HANDLER]: Binding.bind<TWebSocketMessageHandler | null>({\n key: WebSocketBindingKeys.MESSAGE_HANDLER,\n }).toValue(null),\n\n [WebSocketBindingKeys.OUTBOUND_TRANSFORMER]:\n Binding.bind<TWebSocketOutboundTransformer | null>({\n key: WebSocketBindingKeys.OUTBOUND_TRANSFORMER,\n }).toValue(null),\n\n [WebSocketBindingKeys.HANDSHAKE_HANDLER]: Binding.bind<TWebSocketHandshakeFn | null>({\n key: WebSocketBindingKeys.HANDSHAKE_HANDLER,\n }).toValue(null),\n },\n });\n }\n\n private resolveBindings(): IResolvedBindings {\n const extraServerOptions =\n this.application.get<Partial<IServerOptions>>({\n key: WebSocketBindingKeys.SERVER_OPTIONS,\n isOptional: true,\n }) ?? {};\n this.serverOptions = Object.assign({}, DEFAULT_SERVER_OPTIONS, extraServerOptions);\n\n const redisConnection = this.application.get<AbstractRedisHelper>({\n key: WebSocketBindingKeys.REDIS_CONNECTION,\n });\n\n if (!isRedisHelper(redisConnection)) {\n throw getError({\n message:\n '[WebSocketComponent][resolveBindings] Invalid instance of redisConnection | Please init connection with RedisSingleHelper (single), RedisClusterHelper (cluster), or RedisSentinelHelper (sentinel)!',\n });\n }\n\n const authenticateFn = this.application.get<TWebSocketAuthenticateFn>({\n key: WebSocketBindingKeys.AUTHENTICATE_HANDLER,\n });\n\n if (!authenticateFn) {\n throw getError({\n message: '[WebSocketComponent] Invalid authenticateFn to setup WebSocket server!',\n });\n }\n\n const validateRoomFn =\n this.application.get<TWebSocketValidateRoomFn | null>({\n key: WebSocketBindingKeys.VALIDATE_ROOM_HANDLER,\n }) ?? undefined;\n const clientConnectedFn =\n this.application.get<TWebSocketClientConnectedFn | null>({\n key: WebSocketBindingKeys.CLIENT_CONNECTED_HANDLER,\n }) ?? undefined;\n const clientDisconnectedFn =\n this.application.get<TWebSocketClientDisconnectedFn | null>({\n key: WebSocketBindingKeys.CLIENT_DISCONNECTED_HANDLER,\n }) ?? undefined;\n const messageHandler =\n this.application.get<TWebSocketMessageHandler | null>({\n key: WebSocketBindingKeys.MESSAGE_HANDLER,\n }) ?? undefined;\n const outboundTransformer =\n this.application.get<TWebSocketOutboundTransformer | null>({\n key: WebSocketBindingKeys.OUTBOUND_TRANSFORMER,\n }) ?? undefined;\n const handshakeFn =\n this.application.get<TWebSocketHandshakeFn | null>({\n key: WebSocketBindingKeys.HANDSHAKE_HANDLER,\n }) ?? undefined;\n\n return {\n redisConnection,\n authenticateFn,\n validateRoomFn,\n clientConnectedFn,\n clientDisconnectedFn,\n messageHandler,\n outboundTransformer,\n handshakeFn,\n };\n }\n\n private registerBunHook(opts: IResolvedBindings) {\n const {\n redisConnection,\n authenticateFn,\n validateRoomFn,\n clientConnectedFn,\n clientDisconnectedFn,\n messageHandler,\n outboundTransformer,\n handshakeFn,\n } = opts;\n const serverOptions = this.serverOptions;\n\n const logger = this.logger.for(this.registerBunHook.name);\n\n this.application.registerPostStartHook({\n identifier: 'websocket-initialize',\n hook: async () => {\n const serverInstance = this.application.getServerInstance<TBunServerInstance>();\n const honoServer = this.application.getServer();\n\n if (!serverInstance) {\n throw getError({\n message: '[WebSocketComponent] Bun server instance not available!',\n });\n }\n\n const wsHelper = new WebSocketServerHelper({\n identifier: serverOptions.identifier,\n path: serverOptions.path,\n defaultRooms: serverOptions.defaultRooms,\n serverOptions: serverOptions.serverOptions,\n heartbeatInterval: serverOptions.heartbeatInterval,\n heartbeatTimeout: serverOptions.heartbeatTimeout,\n server: serverInstance,\n redisConnection,\n authenticateFn,\n validateRoomFn,\n clientConnectedFn,\n clientDisconnectedFn,\n messageHandler,\n outboundTransformer,\n handshakeFn,\n requireEncryption: serverOptions.requireEncryption,\n });\n await wsHelper.configure();\n\n this.application.bind({ key: WebSocketBindingKeys.WEBSOCKET_INSTANCE }).toValue(wsHelper);\n\n const wsPath = serverOptions.path ?? WebSocketDefaults.PATH;\n\n serverInstance.reload({\n fetch: WebSocketBunHandler.createFetchHandler({ wsPath, honoServer }),\n websocket: wsHelper.getBunWebSocketHandler(),\n });\n\n logger.info('WebSocket initialized for Bun runtime');\n },\n });\n }\n\n override binding(): ValueOrPromise<void> {\n const logger = this.logger.for(this.binding.name);\n\n if (!this.application) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[binding] Invalid application to bind WebSocketComponent',\n });\n }\n\n logger.info('Binding WebSocket for application...');\n\n const resolved = this.resolveBindings();\n logger.debug('WebSocket Server Options: %j', this.serverOptions);\n\n this.registerBunHook(resolved);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../src/components/websocket/component.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CA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G,EAAE,oBAAoB,CAAC,kBAAkB,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAE1F,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,IAAI,iBAAiB,CAAC,IAAI,CAAC;gBAE5D,cAAc,CAAC,MAAM,CAAC;oBACpB,KAAK,EAAE,mBAAmB,CAAC,kBAAkB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;oBACrE,SAAS,EAAE,QAAQ,CAAC,sBAAsB,EAAE;iBAC7C,CAAC,CAAC;gBAEH,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;YACvD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAEQ,OAAO;QACd,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAElD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,0DAA0D;aACpE,CAAC,CAAC;QACL,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QAEpD,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAEjE,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;CACF,CAAA;AAnMY,kBAAkB;IAI1B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAJ1C,kBAAkB,CAmM9B","sourcesContent":["import { type BaseApplication, type TBunServerInstance } from '@/base/applications';\nimport { BaseComponent } from '@venizia/ignis-kernel';\nimport { inject } from '@/base/metadata';\nimport { CoreBindings } from '@venizia/ignis-kernel';\nimport { Binding } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport {\n isRedisHelper,\n type TWebSocketValidateRoomFn,\n WebSocketDefaults,\n WebSocketServerHelper,\n} from '@venizia/ignis-helpers';\nimport {\n WebSocketBindingKeys,\n DEFAULT_SERVER_OPTIONS,\n type IResolvedBindings,\n type IServerOptions,\n} from './common';\nimport { WebSocketBunHandler } from './handlers';\n\n/** Starts a WebSocket server on Bun after the application starts. Requires a Redis helper at `WebSocketBindingKeys.REDIS_CONNECTION` and an authenticate handler at `AUTHENTICATE_HANDLER`; binding throws without them. */\nexport class WebSocketComponent extends BaseComponent {\n protected serverOptions: IServerOptions;\n\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: WebSocketComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [WebSocketBindingKeys.SERVER_OPTIONS]: Binding.bind({\n key: WebSocketBindingKeys.SERVER_OPTIONS,\n }).toValue(DEFAULT_SERVER_OPTIONS),\n\n [WebSocketBindingKeys.REDIS_CONNECTION]: Binding.bind({\n key: WebSocketBindingKeys.REDIS_CONNECTION,\n }).toValue(null),\n\n [WebSocketBindingKeys.AUTHENTICATE_HANDLER]: Binding.bind({\n key: WebSocketBindingKeys.AUTHENTICATE_HANDLER,\n }).toValue(null),\n\n [WebSocketBindingKeys.VALIDATE_ROOM_HANDLER]: Binding.bind<TWebSocketValidateRoomFn | null>(\n {\n key: WebSocketBindingKeys.VALIDATE_ROOM_HANDLER,\n },\n ).toValue(null),\n\n [WebSocketBindingKeys.CLIENT_CONNECTED_HANDLER]: Binding.bind({\n key: WebSocketBindingKeys.CLIENT_CONNECTED_HANDLER,\n }).toValue(null),\n\n [WebSocketBindingKeys.CLIENT_DISCONNECTED_HANDLER]: Binding.bind({\n key: WebSocketBindingKeys.CLIENT_DISCONNECTED_HANDLER,\n }).toValue(null),\n\n [WebSocketBindingKeys.MESSAGE_HANDLER]: Binding.bind({\n key: WebSocketBindingKeys.MESSAGE_HANDLER,\n }).toValue(null),\n\n [WebSocketBindingKeys.OUTBOUND_TRANSFORMER]: Binding.bind({\n key: WebSocketBindingKeys.OUTBOUND_TRANSFORMER,\n }).toValue(null),\n\n [WebSocketBindingKeys.HANDSHAKE_HANDLER]: Binding.bind({\n key: WebSocketBindingKeys.HANDSHAKE_HANDLER,\n }).toValue(null),\n },\n });\n }\n\n private resolveBindings(): IResolvedBindings {\n const extraServerOptions =\n this.application.get({\n key: WebSocketBindingKeys.SERVER_OPTIONS,\n isOptional: true,\n }) ?? {};\n this.serverOptions = Object.assign({}, DEFAULT_SERVER_OPTIONS, extraServerOptions);\n\n const redisConnection = this.application.get({\n key: WebSocketBindingKeys.REDIS_CONNECTION,\n });\n\n if (!isRedisHelper(redisConnection)) {\n throw getError({\n message:\n '[WebSocketComponent][resolveBindings] Invalid instance of redisConnection | Please init connection with RedisSingleHelper (single), RedisClusterHelper (cluster), or RedisSentinelHelper (sentinel)!',\n });\n }\n\n const authenticateFn = this.application.get({\n key: WebSocketBindingKeys.AUTHENTICATE_HANDLER,\n });\n\n if (!authenticateFn) {\n throw getError({\n message: '[WebSocketComponent] Invalid authenticateFn to setup WebSocket server!',\n });\n }\n\n const validateRoomFn =\n this.application.get({\n key: WebSocketBindingKeys.VALIDATE_ROOM_HANDLER,\n }) ?? undefined;\n const clientConnectedFn =\n this.application.get({\n key: WebSocketBindingKeys.CLIENT_CONNECTED_HANDLER,\n }) ?? undefined;\n const clientDisconnectedFn =\n this.application.get({\n key: WebSocketBindingKeys.CLIENT_DISCONNECTED_HANDLER,\n }) ?? undefined;\n const messageHandler =\n this.application.get({\n key: WebSocketBindingKeys.MESSAGE_HANDLER,\n }) ?? undefined;\n const outboundTransformer =\n this.application.get({\n key: WebSocketBindingKeys.OUTBOUND_TRANSFORMER,\n }) ?? undefined;\n const handshakeFn =\n this.application.get({\n key: WebSocketBindingKeys.HANDSHAKE_HANDLER,\n }) ?? undefined;\n\n return {\n redisConnection,\n authenticateFn,\n validateRoomFn,\n clientConnectedFn,\n clientDisconnectedFn,\n messageHandler,\n outboundTransformer,\n handshakeFn,\n };\n }\n\n private registerBunHook(opts: IResolvedBindings) {\n const {\n redisConnection,\n authenticateFn,\n validateRoomFn,\n clientConnectedFn,\n clientDisconnectedFn,\n messageHandler,\n outboundTransformer,\n handshakeFn,\n } = opts;\n const serverOptions = this.serverOptions;\n\n const logger = this.logger.for(this.registerBunHook.name);\n\n this.application.registerPostStartHook({\n identifier: 'websocket-initialize',\n hook: async () => {\n const serverInstance = this.application.getServerInstance<TBunServerInstance>();\n const honoServer = this.application.getServer();\n\n if (!serverInstance) {\n throw getError({\n message: '[WebSocketComponent] Bun server instance not available!',\n });\n }\n\n const wsHelper = new WebSocketServerHelper({\n identifier: serverOptions.identifier,\n path: serverOptions.path,\n defaultRooms: serverOptions.defaultRooms,\n serverOptions: serverOptions.serverOptions,\n heartbeatInterval: serverOptions.heartbeatInterval,\n heartbeatTimeout: serverOptions.heartbeatTimeout,\n server: serverInstance,\n redisConnection,\n authenticateFn,\n validateRoomFn,\n clientConnectedFn,\n clientDisconnectedFn,\n messageHandler,\n outboundTransformer,\n handshakeFn,\n requireEncryption: serverOptions.requireEncryption,\n });\n await wsHelper.configure();\n\n this.application.bind({ key: WebSocketBindingKeys.WEBSOCKET_INSTANCE }).toValue(wsHelper);\n\n const wsPath = serverOptions.path ?? WebSocketDefaults.PATH;\n\n serverInstance.reload({\n fetch: WebSocketBunHandler.createFetchHandler({ wsPath, honoServer }),\n websocket: wsHelper.getBunWebSocketHandler(),\n });\n\n logger.info('WebSocket initialized for Bun runtime');\n },\n });\n }\n\n override binding(): ValueOrPromise<void> {\n const logger = this.logger.for(this.binding.name);\n\n if (!this.application) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[binding] Invalid application to bind WebSocketComponent',\n });\n }\n\n logger.info('Binding WebSocket for application...');\n\n const resolved = this.resolveBindings();\n logger.debug('WebSocket Server Options: %j', this.serverOptions);\n\n this.registerBunHook(resolved);\n }\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { BaseApplication } from '../base/applications/index.js';
|
|
2
2
|
import { type TServerBootStep } from '../base/applications/index.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TClass } from '@venizia/ignis-helpers/common';
|
|
4
4
|
/** A class (matched against the instance's constructor) or a string (matched against the binding key or the class name). */
|
|
5
|
-
export type TBootProbeTarget = TClass<
|
|
5
|
+
export type TBootProbeTarget = TClass<unknown> | string;
|
|
6
6
|
/** Options of `ApplicationBootAssertion.assert`; each field narrows or relaxes what the boot probe runs and verifies. */
|
|
7
7
|
export interface IAssertApplicationBootsOptions {
|
|
8
8
|
/**
|