@venizia/ignis 0.4.8-13 → 0.4.8-15

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.
Files changed (89) hide show
  1. package/dist/esm/components/mail/common/constants.d.ts +24 -14
  2. package/dist/esm/components/mail/common/constants.js +19 -32
  3. package/dist/esm/components/mail/common/constants.js.map +1 -1
  4. package/dist/esm/components/mail/common/errors.d.ts +10 -1
  5. package/dist/esm/components/mail/common/errors.js +7 -1
  6. package/dist/esm/components/mail/common/errors.js.map +1 -1
  7. package/dist/esm/components/mail/common/types/queue.d.ts +15 -8
  8. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  9. package/dist/esm/components/mail/common/types/template.d.ts +3 -2
  10. package/dist/esm/components/mail/common/types/template.js.map +1 -1
  11. package/dist/esm/components/mail/component.js +11 -2
  12. package/dist/esm/components/mail/component.js.map +1 -1
  13. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +13 -12
  14. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  15. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
  16. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
  17. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
  18. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +4 -4
  19. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
  20. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
  21. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
  22. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
  23. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
  24. package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
  25. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
  26. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
  27. package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
  28. package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
  29. package/dist/esm/components/mail/services/mail.service.js +21 -19
  30. package/dist/esm/components/mail/services/mail.service.js.map +1 -1
  31. package/dist/esm/components/mail/services/template.service.d.ts +4 -1
  32. package/dist/esm/components/mail/services/template.service.js +24 -16
  33. package/dist/esm/components/mail/services/template.service.js.map +1 -1
  34. package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
  35. package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
  36. package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
  37. package/dist/esm/components/mail/utilities/header.utility.js +44 -0
  38. package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
  39. package/dist/esm/components/mail/utilities/index.d.ts +1 -0
  40. package/dist/esm/components/mail/utilities/index.js +1 -0
  41. package/dist/esm/components/mail/utilities/index.js.map +1 -1
  42. package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
  43. package/dist/esm/components/mail/utilities/mime.utility.js +9 -55
  44. package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
  45. package/dist/esm/components/static-asset/common/constants.d.ts +5 -4
  46. package/dist/esm/components/static-asset/common/constants.js +5 -9
  47. package/dist/esm/components/static-asset/common/constants.js.map +1 -1
  48. package/dist/esm/components/static-asset/common/errors.d.ts +18 -0
  49. package/dist/esm/components/static-asset/common/errors.js +18 -0
  50. package/dist/esm/components/static-asset/common/errors.js.map +1 -1
  51. package/dist/esm/components/static-asset/common/types.d.ts +47 -18
  52. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  53. package/dist/esm/components/static-asset/component.js +1 -1
  54. package/dist/esm/components/static-asset/component.js.map +1 -1
  55. package/dist/esm/components/static-asset/controller/factory.d.ts +2 -166
  56. package/dist/esm/components/static-asset/controller/factory.js +7 -20
  57. package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
  58. package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
  59. package/dist/esm/components/static-asset/controller/index.js +1 -0
  60. package/dist/esm/components/static-asset/controller/index.js.map +1 -1
  61. package/dist/esm/components/static-asset/controller/routes/context.d.ts +1 -1
  62. package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -1
  63. package/dist/esm/components/static-asset/controller/routes/definition.js +15 -6
  64. package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -1
  65. package/dist/esm/components/static-asset/controller/routes/direct-upload.js +24 -2
  66. package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -1
  67. package/dist/esm/components/static-asset/controller/routes/serve.d.ts +14 -2
  68. package/dist/esm/components/static-asset/controller/routes/serve.js +40 -15
  69. package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -1
  70. package/dist/esm/components/static-asset/controller/routes/upload.js +11 -10
  71. package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -1
  72. package/dist/esm/components/static-asset/services/commitment.service.d.ts +35 -16
  73. package/dist/esm/components/static-asset/services/commitment.service.js +92 -30
  74. package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -1
  75. package/dist/esm/components/static-asset/services/policy.service.d.ts +7 -3
  76. package/dist/esm/components/static-asset/services/policy.service.js +21 -2
  77. package/dist/esm/components/static-asset/services/policy.service.js.map +1 -1
  78. package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +2 -1
  79. package/dist/esm/components/static-asset/utilities/commit-token.utility.js +14 -5
  80. package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -1
  81. package/dist/esm/components/static-asset/utilities/entry.utility.js +9 -2
  82. package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -1
  83. package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +6 -7
  84. package/dist/esm/components/static-asset/utilities/route-options.utility.js +9 -23
  85. package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -1
  86. package/dist/presets/app/preset.json +4 -4
  87. package/dist/presets/lib/preset.json +3 -3
  88. package/dist/presets/shared/preset.json +1 -1
  89. package/package.json +8 -8
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { BaseRestController, IAuthRouteConfig, TRouteAuthConfig, TRouteContext } from '@/base';\nimport type { z } from '@hono/zod-openapi';\nimport type { IDuration } from '@venizia/ignis-helpers/common';\nimport type { DefaultCRUDRepository, TTableObject } from '@venizia/ignis-connectors/postgres';\nimport type {\n DiskHelper,\n IBucketRef,\n IFileStat,\n IObjectLocation,\n IObjectRef,\n IStorageHelper,\n IUploadResult,\n StorageTypes,\n TUploadNaming,\n} from '@venizia/ignis-helpers';\nimport type { BunS3Helper } from '@venizia/ignis-helpers/bun-s3';\nimport type {\n TConstValue,\n TValueOrAsyncResolver,\n ValueOrPromise,\n} from '@venizia/ignis-helpers/common';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models';\nimport type { StaticAssetRouteKeys, TStaticAssetTokenStage } from './constants';\nimport type { StaticAssetPinnedFile } from '../utilities/pinned-file.utility';\n\n/**\n * A feature that is on or off. `{ use: false }` is the whole off state; `{ use: true, ... }` carries\n * the options. One shape for every switch, so an option is never read from a feature that is off.\n */\nexport type TToggle<Options extends object = Record<never, never>> =\n | { use: false }\n | ({ use: true } & Options);\n\n/** The storage backends a static asset entry can serve from: the helpers that declare one. */\nexport type TStaticAssetStorageType = typeof StorageTypes.DISK | typeof StorageTypes.BUN_S3;\n\n/** Decides the key one uploaded file is stored under. `defaultKey` is what IGNIS would have written - the scope and the default naming - so the hook may keep it, extend it or ignore it. */\nexport type TStaticAssetObjectKeyResolver = (opts: {\n bucket: IBucketRef;\n file: TUploadNaming;\n defaultKey: string;\n}) => string;\n\n/** Adds routes of the application's own. Registration order decides a path collision, so the same shape serves both the before and the after hook. */\nexport type TStaticAssetDefineExtraRoutes = (opts: {\n controller: BaseRestController;\n helper: IStorageHelper;\n basePath: string;\n}) => void;\n\n/** Path parameters of the object routes. */\nexport type TStaticAssetObjectParams = { objectName: string };\n\n/** Labels recorded on the MetaLink row of an uploaded object. */\nexport type TStaticAssetUploadLabels = {\n principalType?: string;\n principalId?: string;\n variant?: string;\n /** Display order within the principal. Caller-supplied: deriving it would be a non-atomic read of `max(sequence)` then a write of `max + 1`. */\n sequence?: number;\n};\n\n/** Enables the signed-policy upload flow, where the client posts bytes straight to the storage and IGNIS only signs the permission and verifies the commit. */\nexport type TStaticAssetDirectUploadOptions = {\n /**\n * Who may use direct upload. Guards every direct-upload route. There is no safe default for a\n * route that hands out a write credential, so leaving it out is allowed only when the entry's\n * `auth` already authenticates or authorizes: then `auth` is the gate. With neither, the\n * component refuses to start.\n */\n authorize?: (opts: { context: TRouteContext }) => ValueOrPromise<boolean>;\n\n /**\n * Who the upload belongs to. Called on every direct-upload route: the policy route signs the\n * answer into the commit token, and the other routes refuse a token whose owner differs. Absent,\n * a token commits for whoever holds it.\n */\n resolveOwner?: (opts: { context: TRouteContext }) => ValueOrPromise<string>;\n\n /** Signs the commit token. Keep it out of the repository and out of the client. */\n secretKey: string;\n\n /** The ceiling the policy carries as `content-length-range`. A signed PUT cannot express this at all, which is why this is a POST policy. */\n maxBytes: number;\n\n /**\n * The most files one upload-policy request may name; more is a 422.\n *\n * @default StaticAssetDefaults.MAX_UPLOAD_FILES (20)\n */\n maxFiles?: number;\n\n /**\n * Where a policy may write: not empty, ends with `/`, made of valid key segments, and neither\n * inside the entry's `keyPrefix` nor containing it - a pending object must never be readable\n * through the entry's own routes. The final key is NEVER in a policy, so content cannot be\n * replaced after the commit. The lifecycle rule that collects abandoned uploads targets this prefix.\n *\n * @default 'pending/'\n */\n pendingPrefix?: string;\n\n expires?: {\n /**\n * How long the browser may post the bytes: the POST policy's lifetime.\n *\n * @default StoragePresignDefaults.POST_EXPIRES_IN\n */\n upload?: IDuration;\n\n /**\n * How long the commit token stays good, for validating and committing after the upload. The\n * pending object must outlive it, so the lifecycle rule on `pendingPrefix` has to be longer still.\n *\n * @default `upload`\n */\n commit?: IDuration;\n };\n\n /**\n * Checks the pending file. On, the component registers `POST {base}/upload-validate`, which\n * answers the token `commit` takes, and `commit` accepts no other.\n * Build it with `StaticAssetValidation.define`.\n */\n validation: TToggle<IStaticAssetValidation<z.ZodType>>;\n};\n\n/** What a validation answers: whether the file may be committed, and the problems the user should see. */\nexport interface IStaticAssetValidationResult<Issue> {\n isValid: boolean;\n issues: Issue[];\n}\n\n/**\n * The application's own check of an uploaded file, run on the PENDING object before anything is\n * committed. The component owns the route and the refusal; the application owns only this logic.\n * Build it with `StaticAssetValidation.define` so the handler is typed by `issueSchema`.\n */\nexport interface IStaticAssetValidation<IssueSchema extends z.ZodType> {\n /** The shape of ONE issue. It types the handler's answer and documents the route's response. */\n issueSchema: IssueSchema;\n\n /** Runs once per `upload-validate`. Read the file through `file`: every read is pinned to the content `commit` will copy. */\n handler: (opts: {\n file: StaticAssetPinnedFile;\n owner?: string;\n }) => ValueOrPromise<IStaticAssetValidationResult<z.infer<IssueSchema>>>;\n}\n\n/** What `validate` answers. `commitToken` is present only when the file is valid: it is the token `commit` takes. */\nexport interface IStaticAssetValidateResult<Issue> extends IStaticAssetValidationResult<Issue> {\n commitToken?: string;\n}\n\n/** Body of the upload policy route: the files the client intends to upload. */\nexport type TStaticAssetUploadPolicyRequest = {\n files: Array<{ fileName: string; contentType?: string; size?: number }>;\n};\n\n/** The MetaLink table belongs to the application. `Schema` defaults to the table IGNIS ships, and widens to any table whose row carries the same fields. */\nexport type TMetaLinkConfig<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {\n repository: TValueOrAsyncResolver<DefaultCRUDRepository<Schema>>;\n createMetaLink?: (opts: {\n uploadResult: IUploadResult;\n fileStat: IFileStat;\n /** The caller's labels: form fields on an upload, beside the commit token on a direct one. */\n labels: TStaticAssetUploadLabels;\n }) => ValueOrPromise<{ count: number; data: TTableObject<Schema> }>;\n};\n\n/** The part of a built-in route an application may change. `authenticate` and `authorize` replace the entry's `auth` for this route, and `{ skip: true }` leaves it open. */\nexport type TStaticAssetRouteConfig = Partial<\n Omit<IAuthRouteConfig, 'method' | 'request' | 'responses' | 'authenticate' | 'authorize'>\n> &\n TRouteAuthConfig;\n\n/** Authentication and authorization for every built-in route of an entry; a route's own `authenticate`/`authorize` replaces it for that route. */\nexport type TStaticAssetAuth = TRouteAuthConfig & {\n /**\n * `{ use: true }` leaves `getObjectByName` and `downloadObjectByName` unauthenticated, so a\n * browser can show an image without a token. `listObjects` is NOT public: listing a bucket is not\n * reading an object.\n *\n * @default { use: false }\n */\n publicRead?: TToggle;\n};\n\n/** The name of a built-in route, the key of `routes`. */\nexport type TStaticAssetRouteKey = TConstValue<typeof StaticAssetRouteKeys>;\n\n/**\n * What each built-in route does: `{ use: false }` turns it off, `{ use: true, ... }` turns it on\n * with those overrides. A route left out is on as built.\n */\nexport type TStaticAssetRoutes = Partial<\n Record<TStaticAssetRouteKey, TToggle<TStaticAssetRouteConfig>>\n>;\n\n/** Uploading through the application: the browser sends the bytes to `POST /objects` and the application writes them to the storage. */\nexport type TStaticAssetServerUploadOptions = {\n /** Largest file the route accepts. Absent means no ceiling. Checked against `content-length` before the body is read, then per file after parsing. */\n maxBytes?: number;\n\n /**\n * The most file parts one request may carry; more is refused with 413 before anything is written.\n *\n * @default StaticAssetDefaults.MAX_UPLOAD_FILES (20)\n */\n maxFiles?: number;\n\n /** The one hook that decides the key an uploaded file is stored under. Absent keeps the default naming. Under a `keyPrefix` a key outside the scope is refused, never rewritten. */\n objectKey?: TStaticAssetObjectKeyResolver;\n};\n\n/** Direct upload is a POST policy, which only S3 can sign, and its pending objects stay out of the served scope only when the entry has a `keyPrefix`. */\ntype TStaticAssetDirectUploadScope =\n | { keyPrefix?: string; directUpload: { use: false } }\n | { keyPrefix: string; directUpload: { use: true } & TStaticAssetDirectUploadOptions };\n\n/** The storage helper decides which direct upload shapes are possible. */\ntype TStaticAssetStorage =\n | ({ helper: BunS3Helper } & TStaticAssetDirectUploadScope)\n | { helper: DiskHelper; keyPrefix?: string; directUpload: { use: false } };\n\n/** One storage backend with its generated controller. Every switch is a toggle; a toggle left out is a type error, so nothing is on or off by accident. */\nexport type TStaticAssetEntry<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {\n basePath: string;\n\n /** The controller's name. Absent, it is derived from the entry's key. */\n name?: string;\n\n /** The single bucket every route uses. The function form is read per request, so an environment variable can be read lazily. */\n bucket: TValueOrAsyncResolver<string>;\n\n /**\n * The key scope this entry owns, e.g. `inventory/`. Every route refuses a key outside it as a\n * 404 without calling the storage, `listObjects` lists only inside it, and an upload key must\n * land inside it. `maxFolderDepth` counts the folders below it. Required with\n * `directUpload`: it keeps the pending prefix outside everything the routes serve.\n *\n * @default every key in the bucket\n */\n keyPrefix?: string;\n\n /**\n * Folders a key may nest below the `keyPrefix`, for every route of the entry: reads and deletes\n * too, so it holds for keys that arrive by direct upload or ingest.\n *\n * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH\n */\n maxFolderDepth?: number;\n\n /**\n * `true` serves a raw nested object path (`/objects/photos/2024/f.jpg`) - a URL shape change; a percent-encoded path keeps working either way.\n *\n * @default false\n */\n rawObjectPath?: boolean;\n\n /** The link stored and returned for an object. Absent builds the URL of this controller's own object route. */\n link?: (opts: IObjectLocation) => string;\n\n /** Authentication and authorization of every built-in route of this entry. Absent leaves every route open; `publicRead` is the only way a read route is public on purpose. */\n auth?: TStaticAssetAuth;\n\n serverUpload: TToggle<TStaticAssetServerUploadOptions>;\n\n /** Every upload also writes a MetaLink row, and the object's deletion removes it. */\n metaLink: TToggle<TMetaLinkConfig<Schema>>;\n\n routes?: TStaticAssetRoutes;\n\n extend?: {\n /** Registered BEFORE every built-in route, so a literal path wins over the catch-all `rawObjectPath` produces. Hono matches in registration order. */\n before?: TStaticAssetDefineExtraRoutes;\n /** Registered after every built-in route. */\n after?: TStaticAssetDefineExtraRoutes;\n };\n} & TStaticAssetStorage;\n\n/** Static asset entries keyed by an application-chosen name; each key becomes one controller. */\nexport type TStaticAssetComponentOptions<\n Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema,\n> = Record<string, TStaticAssetEntry<Schema>>;\n\n/** The content a validation read: the ETag, and the version id when the storage has real versions. */\nexport interface IStaticAssetPin {\n etag: string;\n versionId?: string;\n}\n\n/**\n * What a commit token binds: the pending object a policy was issued for, when the grant dies and,\n * when the application supplies one, who it was issued to. Other business fields are deliberately\n * absent - which order or tenant an upload belongs to is the application's.\n */\nexport interface IStaticAssetCommitTokenPayload {\n bucket: IBucketRef;\n object: IObjectRef;\n expiresAt: number;\n /** Absent when `directUpload.resolveOwner` is not set; present, the token commits only for that owner. */\n owner?: string;\n stage: TStaticAssetTokenStage;\n /** Present from `VALIDATED` on: `commit` copies only content that still matches it. */\n pin?: IStaticAssetPin;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { BaseRestController, IAuthRouteConfig, TRouteAuthConfig, TRouteContext } from '@/base';\nimport type { z } from '@hono/zod-openapi';\nimport type { IDuration } from '@venizia/ignis-helpers/common';\nimport type { DefaultCRUDRepository, TTableObject } from '@venizia/ignis-connectors/postgres';\nimport type {\n DiskHelper,\n IBucketRef,\n IFileStat,\n IObjectLocation,\n IObjectRef,\n IStorageHelper,\n IUploadResult,\n StorageTypes,\n TUploadNaming,\n} from '@venizia/ignis-helpers';\nimport type { BunS3Helper } from '@venizia/ignis-helpers/bun-s3';\nimport type {\n TConstValue,\n TValueOrAsyncResolver,\n ValueOrPromise,\n} from '@venizia/ignis-helpers/common';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models';\nimport type { StaticAssetRouteKeys, TStaticAssetTokenStage } from './constants';\nimport type { StaticAssetPinnedFile } from '../utilities/pinned-file.utility';\n\n/**\n * A feature that is on or off. `{ use: false }` is the whole off state; `{ use: true, ... }` carries\n * the options. One shape for every switch, so an option is never read from a feature that is off.\n */\nexport type TToggle<Options extends object = Record<never, never>> =\n | { use: false }\n | ({ use: true } & Options);\n\n/** The storage backends a static asset entry can serve from: the helpers that declare one. */\nexport type TStaticAssetStorageType = typeof StorageTypes.DISK | typeof StorageTypes.BUN_S3;\n\n/** Decides the key one uploaded file is stored under. `defaultKey` is what IGNIS would have written - the scope and the default naming - so the hook may keep it, extend it or ignore it. */\nexport type TStaticAssetObjectKeyResolver = (opts: {\n bucket: IBucketRef;\n file: TUploadNaming;\n defaultKey: string;\n}) => string;\n\n/** Adds routes of the application's own. Registration order decides a path collision, so the same shape serves both the before and the after hook. */\nexport type TStaticAssetDefineExtraRoutes = (opts: {\n controller: BaseRestController;\n helper: IStorageHelper;\n basePath: string;\n}) => void;\n\n/** Path parameters of the object routes. */\nexport type TStaticAssetObjectParams = { objectName: string };\n\n/** Labels recorded on the MetaLink row of an uploaded object. */\nexport type TStaticAssetUploadLabels = {\n principalType?: string;\n principalId?: string;\n variant?: string;\n /** Display order within the principal. Caller-supplied: deriving it would be a non-atomic read of `max(sequence)` then a write of `max + 1`. */\n sequence?: number;\n};\n\n/** Application-chosen strings the commit token signs for one file. The token is signed, not encrypted: no secrets. */\nexport type TStaticAssetTokenMetadata = Record<string, string>;\n\n/** One file of an upload-policy request. `metadata` is the client's hint: `resolvers.metadata` reads it, and only what that returns is signed. */\nexport type TStaticAssetUploadPolicyFile = {\n fileName: string;\n contentType?: string;\n size?: number;\n metadata?: TStaticAssetTokenMetadata;\n};\n\n/** The decisions of a direct upload that belong to the application, each made on a different call. */\nexport type TStaticAssetDirectUploadResolvers = {\n /**\n * Who the upload belongs to. Called on every direct-upload route: the policy route signs the\n * answer into the commit token, and the other routes refuse a token whose owner differs.\n */\n owner: (opts: { context: TRouteContext }) => ValueOrPromise<string>;\n\n /** Per file, at policy time: what the token signs for it, readable again at validate and commit. Absent, a client that sends `metadata` is refused. */\n metadata?: (opts: {\n context: TRouteContext;\n file: TStaticAssetUploadPolicyFile;\n }) => ValueOrPromise<TStaticAssetTokenMetadata>;\n\n commit?: {\n /** At commit time: the final key, in the same bucket and inside the `keyPrefix`. Absent keeps `defaultKey`. */\n destination?: (opts: {\n owner: string;\n metadata: TStaticAssetTokenMetadata;\n file: { fileName: string };\n defaultKey: string;\n }) => ValueOrPromise<{ key: string }>;\n };\n};\n\n/** Enables the signed-policy upload flow, where the client posts bytes straight to the storage and IGNIS only signs the permission and verifies the commit. */\nexport type TStaticAssetDirectUploadOptions = {\n /**\n * Who may use direct upload. Guards every direct-upload route. There is no safe default for a\n * route that hands out a write credential, so leaving it out is allowed only when the entry's\n * `auth` already authenticates or authorizes: then `auth` is the gate. With neither, the\n * component refuses to start.\n */\n authorize?: (opts: { context: TRouteContext }) => ValueOrPromise<boolean>;\n\n /** What the application decides about an upload; `owner` is required, the rest is optional. */\n resolvers: TStaticAssetDirectUploadResolvers;\n\n /** Signs the commit token. Keep it out of the repository and out of the client. */\n secretKey: string;\n\n /** The ceiling the policy carries as `content-length-range`. A signed PUT cannot express this at all, which is why this is a POST policy. */\n maxBytes: number;\n\n /**\n * The most files one upload-policy request may name; more is a 422.\n *\n * @default StaticAssetDefaults.MAX_UPLOAD_FILES (20)\n */\n maxFiles?: number;\n\n /**\n * Where a policy may write: not empty, ends with `/`, made of valid key segments, and neither\n * inside the entry's `keyPrefix` nor containing it - a pending object must never be readable\n * through the entry's own routes. The final key is NEVER in a policy, so content cannot be\n * replaced after the commit. The lifecycle rule that collects abandoned uploads targets this prefix.\n *\n * @default 'pending/'\n */\n pendingPrefix?: string;\n\n expires?: {\n /**\n * How long the browser may post the bytes: the POST policy's lifetime.\n *\n * @default StoragePresignDefaults.POST_EXPIRES_IN\n */\n upload?: IDuration;\n\n /**\n * How long the commit token stays good, for validating and committing after the upload. The\n * pending object must outlive it, so the lifecycle rule on `pendingPrefix` has to be longer still.\n *\n * @default `upload`\n */\n commit?: IDuration;\n };\n\n /**\n * Checks the pending file. On, the component registers `POST {base}/upload-validate`, which\n * answers the token `commit` takes, and `commit` accepts no other.\n * Build it with `StaticAssetValidation.define`.\n */\n validation: TToggle<IStaticAssetValidation<z.ZodType>>;\n};\n\n/** What a validation answers: whether the file may be committed, and the problems the user should see. */\nexport interface IStaticAssetValidationResult<Issue> {\n isValid: boolean;\n issues: Issue[];\n}\n\n/**\n * The application's own check of an uploaded file, run on the PENDING object before anything is\n * committed. The component owns the route and the refusal; the application owns only this logic.\n * Build it with `StaticAssetValidation.define` so the handler is typed by `issueSchema`.\n */\nexport interface IStaticAssetValidation<IssueSchema extends z.ZodType> {\n /** The shape of ONE issue. It types the handler's answer and documents the route's response. */\n issueSchema: IssueSchema;\n\n /** Runs once per `upload-validate`. Read the file through `file`: every read is pinned to the content `commit` will copy. */\n handler: (opts: {\n file: StaticAssetPinnedFile;\n owner: string;\n metadata: TStaticAssetTokenMetadata;\n }) => ValueOrPromise<IStaticAssetValidationResult<z.infer<IssueSchema>>>;\n}\n\n/** What `validate` answers. `commitToken` is present only when the file is valid: it is the token `commit` takes. */\nexport interface IStaticAssetValidateResult<Issue> extends IStaticAssetValidationResult<Issue> {\n commitToken?: string;\n}\n\n/** Body of the upload policy route: the files the client intends to upload. */\nexport type TStaticAssetUploadPolicyRequest = { files: TStaticAssetUploadPolicyFile[] };\n\n/** The MetaLink table belongs to the application. `Schema` defaults to the table IGNIS ships, and widens to any table whose row carries the same fields. */\nexport type TMetaLinkConfig<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {\n repository: TValueOrAsyncResolver<DefaultCRUDRepository<Schema>>;\n createMetaLink?: (opts: {\n uploadResult: IUploadResult;\n fileStat: IFileStat;\n /** The caller's labels: form fields on an upload, beside the commit token on a direct one. */\n labels: TStaticAssetUploadLabels;\n }) => ValueOrPromise<{ count: number; data: TTableObject<Schema> }>;\n};\n\n/** The part of a built-in route an application may change. `authenticate` and `authorize` replace the entry's `auth` for this route, and `{ skip: true }` leaves it open. */\nexport type TStaticAssetRouteConfig = Partial<\n Omit<IAuthRouteConfig, 'method' | 'request' | 'responses' | 'authenticate' | 'authorize'>\n> &\n TRouteAuthConfig;\n\n/** Authentication and authorization for every built-in route of an entry; a route's own `authenticate`/`authorize` replaces it for that route. */\nexport type TStaticAssetAuth = TRouteAuthConfig & {\n /**\n * `{ use: true }` leaves `getObjectByName` and `downloadObjectByName` unauthenticated, so a\n * browser can show an image without a token. `listObjects` is NOT public: listing a bucket is not\n * reading an object.\n *\n * @default { use: false }\n */\n publicRead?: TToggle;\n};\n\n/** The name of a built-in route, the key of `routes`. */\nexport type TStaticAssetRouteKey = TConstValue<typeof StaticAssetRouteKeys>;\n\n/**\n * What each built-in route does: `{ use: false }` turns it off, `{ use: true, ... }` turns it on\n * with those overrides. A route left out is on as built.\n */\nexport type TStaticAssetRoutes = Partial<\n Record<TStaticAssetRouteKey, TToggle<TStaticAssetRouteConfig>>\n>;\n\n/** Uploading through the application: the browser sends the bytes to `POST /objects` and the application writes them to the storage. */\nexport type TStaticAssetServerUploadOptions = {\n /** Largest file the route accepts. Absent means no ceiling. Checked against `content-length` before the body is read, then per file after parsing. */\n maxBytes?: number;\n\n /**\n * The most file parts one request may carry; more is refused with 413 before anything is written.\n *\n * @default StaticAssetDefaults.MAX_UPLOAD_FILES (20)\n */\n maxFiles?: number;\n\n /** The one hook that decides the key an uploaded file is stored under. Absent keeps the default naming. Under a `keyPrefix` a key outside the scope is refused, never rewritten. */\n objectKey?: TStaticAssetObjectKeyResolver;\n};\n\n/** Direct upload is a POST policy, which only S3 can sign, and its pending objects stay out of the served scope only when the entry has a `keyPrefix`. */\ntype TStaticAssetDirectUploadScope =\n | { keyPrefix?: string; directUpload: { use: false } }\n | { keyPrefix: string; directUpload: { use: true } & TStaticAssetDirectUploadOptions };\n\n/** The storage helper decides which direct upload shapes are possible. */\ntype TStaticAssetStorage =\n | ({ helper: BunS3Helper } & TStaticAssetDirectUploadScope)\n | { helper: DiskHelper; keyPrefix?: string; directUpload: { use: false } };\n\n/** One storage backend with its generated controller. Every switch is a toggle; a toggle left out is a type error, so nothing is on or off by accident. */\nexport type TStaticAssetEntry<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {\n basePath: string;\n\n /** The controller's name. Absent, it is derived from the entry's key. */\n name?: string;\n\n /** The single bucket every route uses. The function form is read per request, so an environment variable can be read lazily. */\n bucket: TValueOrAsyncResolver<string>;\n\n /**\n * The key scope this entry owns, e.g. `inventory/`. Every route refuses a key outside it as a\n * 404 without calling the storage, `listObjects` lists only inside it, and an upload key must\n * land inside it. `maxFolderDepth` counts the folders below it. Required with\n * `directUpload`: it keeps the pending prefix outside everything the routes serve.\n *\n * @default every key in the bucket\n */\n keyPrefix?: string;\n\n /**\n * Folders a key may nest below the `keyPrefix`, for every route of the entry: reads and deletes\n * too, so it holds for keys that arrive by direct upload or ingest.\n *\n * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH\n */\n maxFolderDepth?: number;\n\n /**\n * `true` serves a raw nested object path (`/objects/photos/2024/f.jpg`) - a URL shape change; a percent-encoded path keeps working either way.\n *\n * @default false\n */\n rawObjectPath?: boolean;\n\n /** The link stored and returned for an object. Absent builds the URL of this controller's own object route. */\n link?: (opts: IObjectLocation) => string;\n\n /** Authentication and authorization of every built-in route of this entry. Absent leaves every route open; `publicRead` is the only way a read route is public on purpose. */\n auth?: TStaticAssetAuth;\n\n serverUpload: TToggle<TStaticAssetServerUploadOptions>;\n\n /** Every upload also writes a MetaLink row, and the object's deletion removes it. */\n metaLink: TToggle<TMetaLinkConfig<Schema>>;\n\n routes?: TStaticAssetRoutes;\n\n extend?: {\n /** Registered BEFORE every built-in route, so a literal path wins over the catch-all `rawObjectPath` produces. Hono matches in registration order. */\n before?: TStaticAssetDefineExtraRoutes;\n /** Registered after every built-in route. */\n after?: TStaticAssetDefineExtraRoutes;\n };\n} & TStaticAssetStorage;\n\n/** Static asset entries keyed by an application-chosen name; each key becomes one controller. */\nexport type TStaticAssetComponentOptions<\n Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema,\n> = Record<string, TStaticAssetEntry<Schema>>;\n\n/** The content a validation read: the ETag, and the version id when the storage has real versions. */\nexport interface IStaticAssetPin {\n etag: string;\n versionId?: string;\n}\n\n/**\n * What a commit token binds: the pending object a policy was issued for, when the grant dies and,\n * who it was issued to and the application's own metadata for the file.\n */\nexport interface IStaticAssetCommitTokenPayload {\n bucket: IBucketRef;\n object: IObjectRef;\n expiresAt: number;\n /** The token commits only for this owner. */\n owner: string;\n /** What `resolvers.metadata` returned for the file; `{}` without one. Signed, not encrypted. */\n metadata: TStaticAssetTokenMetadata;\n stage: TStaticAssetTokenStage;\n /** Present from `VALIDATED` on: `commit` copies only content that still matches it. */\n pin?: IStaticAssetPin;\n}\n"]}
@@ -42,7 +42,7 @@ let StaticAssetComponent = StaticAssetComponent_1 = class StaticAssetComponent e
42
42
  for (const [key, entry] of Object.entries(componentOptions)) {
43
43
  const resolved = StaticAssetEntryUtility.resolve({ key, entry });
44
44
  const services = this.bindDirectUploadServices({ key, resolved });
45
- this.application.controller(StaticAssetControllerFactory.buildResolved({ resolved, ...services }));
45
+ this.application.controller(StaticAssetControllerFactory.build({ key, entry, ...services }));
46
46
  this.application.logger.info(`[binding] Asset storage is bound | Key: %s | Mount: %s | Storage type: %s | Direct upload: %s | MetaLink: %s`, key, resolved.basePath, resolved.storage, resolved.directUpload !== undefined, resolved.metaLink !== undefined);
47
47
  }
48
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../src/components/static-asset/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;AAEhD,O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;YAEF,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAC1B,8GAA8G,EAC9G,GAAG,EACH,QAAQ,CAAC,QAAQ,EACjB,QAAQ,CAAC,OAAO,EAChB,QAAQ,CAAC,YAAY,KAAK,SAAS,EACnC,QAAQ,CAAC,QAAQ,KAAK,SAAS,CAChC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,mJAAmJ;IAC3I,wBAAwB,CAAC,IAGhC;QACC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC/B,MAAM,QAAQ,GAAG,uBAAuB,CAAC,yBAAyB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEjF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,CAAC,WAAW;aACb,IAAI,CAAC,EAAE,GAAG,EAAE,sBAAsB,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;aAClE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QACnC,IAAI,CAAC,WAAW;aACb,IAAI,CAAC,EAAE,GAAG,EAAE,sBAAsB,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;aAClE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAEnC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AAlEY,oBAAoB;IAI5B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAJ1C,oBAAoB,CAkEhC","sourcesContent":["import { type BaseApplication } 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 { type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { StaticAssetBindingKeys, type TStaticAssetComponentOptions } from './common';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from './models';\nimport { StaticAssetControllerFactory } from './controller';\nimport { StaticAssetEntryUtility, type IStaticAssetResolvedEntry } from './utilities/entry.utility';\n\n/** `Schema` is the MetaLink table the application binds. It has to live on the CLASS, not only on the options: `component(Ctor, { options })` infers the options from the class, so a class pinned to the shipped table can only carry options for that table. */\nexport class StaticAssetComponent<\n Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema,\n> extends BaseComponent<TStaticAssetComponentOptions<Schema>> {\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: StaticAssetComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [StaticAssetBindingKeys.STATIC_ASSET_OPTIONS]: Binding.bind<TStaticAssetComponentOptions>({\n key: StaticAssetBindingKeys.STATIC_ASSET_OPTIONS,\n }).toValue({}),\n },\n });\n }\n\n override binding(): ValueOrPromise<void> {\n // Direct options win. The key is the path for an application that registers this component\n // through `configs.artifacts`, where an index carries classes and no options.\n const componentOptions =\n this.options ??\n this.application.get<TStaticAssetComponentOptions<Schema>>({\n key: StaticAssetBindingKeys.STATIC_ASSET_OPTIONS,\n });\n\n for (const [key, entry] of Object.entries(componentOptions)) {\n const resolved = StaticAssetEntryUtility.resolve({ key, entry });\n const services = this.bindDirectUploadServices({ key, resolved });\n\n this.application.controller(\n StaticAssetControllerFactory.buildResolved<Schema>({ resolved, ...services }),\n );\n\n this.application.logger.info(\n `[binding] Asset storage is bound | Key: %s | Mount: %s | Storage type: %s | Direct upload: %s | MetaLink: %s`,\n key,\n resolved.basePath,\n resolved.storage,\n resolved.directUpload !== undefined,\n resolved.metaLink !== undefined,\n );\n }\n }\n\n /** One pair of services per entry that turns direct upload on. The routes run the very objects an application's service resolves from the keys. */\n private bindDirectUploadServices(opts: {\n key: string;\n resolved: IStaticAssetResolvedEntry<Schema>;\n }) {\n const { key, resolved } = opts;\n const services = StaticAssetEntryUtility.buildDirectUploadServices({ resolved });\n\n if (!services) {\n return undefined;\n }\n\n this.application\n .bind({ key: StaticAssetBindingKeys.policyService({ name: key }) })\n .toValue(services.policyService);\n this.application\n .bind({ key: StaticAssetBindingKeys.commitService({ name: key }) })\n .toValue(services.commitService);\n\n return services;\n }\n}\n"]}
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../src/components/static-asset/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;AAEhD,OAAO,EAAE,sBAAsB,EAAqC,MAAM,UAAU,CAAC;AAErF,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAkC,MAAM,2BAA2B,CAAC;AAEpG,kQAAkQ;AAClQ,IAAa,oBAAoB,4BAAjC,MAAa,oBAEX,SAAQ,aAAmD;IAC3D,YAC8D,WAA4B;QAExF,KAAK,CAAC;YACJ,KAAK,EAAE,sBAAoB,CAAC,IAAI;YAChC,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE;YACrD,QAAQ,EAAE;gBACR,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,IAAI,CAA+B;oBACxF,GAAG,EAAE,sBAAsB,CAAC,oBAAoB;iBACjD,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;aACf;SACF,CAAC,CAAC;QAVyD,gBAAW,GAAX,WAAW,CAAiB;IAW1F,CAAC;IAEQ,OAAO;QACd,2FAA2F;QAC3F,8EAA8E;QAC9E,MAAM,gBAAgB,GACpB,IAAI,CAAC,OAA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CAAC,WAAW;aACb,IAAI,CAAC,EAAE,GAAG,EAAE,sBAAsB,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;aAClE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAEnC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AAlEY,oBAAoB;IAI5B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAJ1C,oBAAoB,CAkEhC","sourcesContent":["import { type BaseApplication } 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 { type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { StaticAssetBindingKeys, type TStaticAssetComponentOptions } from './common';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from './models';\nimport { StaticAssetControllerFactory } from './controller';\nimport { StaticAssetEntryUtility, type IStaticAssetResolvedEntry } from './utilities/entry.utility';\n\n/** `Schema` is the MetaLink table the application binds. It has to live on the CLASS, not only on the options: `component(Ctor, { options })` infers the options from the class, so a class pinned to the shipped table can only carry options for that table. */\nexport class StaticAssetComponent<\n Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema,\n> extends BaseComponent<TStaticAssetComponentOptions<Schema>> {\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: StaticAssetComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [StaticAssetBindingKeys.STATIC_ASSET_OPTIONS]: Binding.bind<TStaticAssetComponentOptions>({\n key: StaticAssetBindingKeys.STATIC_ASSET_OPTIONS,\n }).toValue({}),\n },\n });\n }\n\n override binding(): ValueOrPromise<void> {\n // Direct options win. The key is the path for an application that registers this component\n // through `configs.artifacts`, where an index carries classes and no options.\n const componentOptions =\n this.options ??\n this.application.get<TStaticAssetComponentOptions<Schema>>({\n key: StaticAssetBindingKeys.STATIC_ASSET_OPTIONS,\n });\n\n for (const [key, entry] of Object.entries(componentOptions)) {\n const resolved = StaticAssetEntryUtility.resolve({ key, entry });\n const services = this.bindDirectUploadServices({ key, resolved });\n\n this.application.controller(\n StaticAssetControllerFactory.build<Schema>({ key, entry, ...services }),\n );\n\n this.application.logger.info(\n `[binding] Asset storage is bound | Key: %s | Mount: %s | Storage type: %s | Direct upload: %s | MetaLink: %s`,\n key,\n resolved.basePath,\n resolved.storage,\n resolved.directUpload !== undefined,\n resolved.metaLink !== undefined,\n );\n }\n }\n\n /** One pair of services per entry that turns direct upload on. The routes run the very objects an application's service resolves from the keys. */\n private bindDirectUploadServices(opts: {\n key: string;\n resolved: IStaticAssetResolvedEntry<Schema>;\n }) {\n const { key, resolved } = opts;\n const services = StaticAssetEntryUtility.buildDirectUploadServices({ resolved });\n\n if (!services) {\n return undefined;\n }\n\n this.application\n .bind({ key: StaticAssetBindingKeys.policyService({ name: key }) })\n .toValue(services.policyService);\n this.application\n .bind({ key: StaticAssetBindingKeys.commitService({ name: key }) })\n .toValue(services.commitService);\n\n return services;\n }\n}\n"]}
@@ -1,9 +1,7 @@
1
- import type { IObjectRef, IStorageHelper } from '@venizia/ignis-helpers';
2
1
  import type { ValueOrPromise } from '@venizia/ignis-helpers/common';
3
2
  import type { TStaticAssetEntry } from '../common/index.js';
4
3
  import type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models/index.js';
5
4
  import type { StaticAssetUploadCommitService, StaticAssetUploadPolicyService } from '../services/index.js';
6
- import { type IStaticAssetResolvedEntry } from '../utilities/entry.utility.js';
7
5
  /** Input of `StaticAssetControllerFactory.build`: one entry of `TStaticAssetComponentOptions` and its key. */
8
6
  export interface IStaticAssetControllerOptions<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> {
9
7
  /** The entry's key in the options object: the controller's name is derived from it. */
@@ -13,21 +11,9 @@ export interface IStaticAssetControllerOptions<Schema extends TMetaLinkCompatibl
13
11
  policyService?: Pick<StaticAssetUploadPolicyService, 'issuePolicies'>;
14
12
  commitService?: Pick<StaticAssetUploadCommitService<Schema>, 'commit' | 'validate'>;
15
13
  }
16
- /** Builds the REST controller class for a static asset entry, and decides the served content type. */
14
+ /** Builds the REST controller class for a static asset entry. */
17
15
  export declare class StaticAssetControllerFactory {
18
- /**
19
- * The served type comes from the object NAME, never the backend or the uploader: a renderable type on
20
- * the API origin is stored XSS. Public so a hand-written route makes the same decision - the
21
- * backend's own content-type is dropped by `StaticAssetHeaders.ALLOWED`.
22
- */
23
- static resolveServedContentType(opts: {
24
- helper: IStorageHelper;
25
- object: IObjectRef;
26
- }): {
27
- contentType: string;
28
- isRenderable: boolean;
29
- };
30
- /** Resolves the entry, then builds its controller. A caller that already holds the resolved entry uses `buildResolved`. */
16
+ /** Resolves the entry, then builds its controller. */
31
17
  static build<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema>(opts: IStaticAssetControllerOptions<Schema>): {
32
18
  new (): {
33
19
  binding(): ValueOrPromise<void>;
@@ -174,155 +160,5 @@ export declare class StaticAssetControllerFactory {
174
160
  getLogger(): import("@venizia/ignis-helpers").ILogger;
175
161
  };
176
162
  };
177
- static buildResolved<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema>(opts: {
178
- resolved: IStaticAssetResolvedEntry<Schema>;
179
- policyService?: Pick<StaticAssetUploadPolicyService, 'issuePolicies'>;
180
- commitService?: Pick<StaticAssetUploadCommitService<Schema>, 'commit' | 'validate'>;
181
- }): {
182
- new (): {
183
- binding(): ValueOrPromise<void>;
184
- measure<R>(opts: {
185
- scope: string;
186
- args: unknown;
187
- task: () => Promise<R>;
188
- }): Promise<any>;
189
- normalizeCountData<ResponseSchema extends unknown, RequestContext extends import("@venizia/ignis-kernel").TRouteContext<import("hono").Env> = import("@venizia/ignis-kernel").TRouteContext<import("hono").Env>, ResponseData extends {
190
- count: number;
191
- data?: import("@venizia/ignis-helpers").TNullable<ResponseSchema>;
192
- } = {
193
- count: number;
194
- data?: import("@venizia/ignis-helpers").TNullable<ResponseSchema>;
195
- }>(opts: {
196
- context: RequestContext;
197
- payload: ResponseData;
198
- }): ResponseData | import("@venizia/ignis-helpers").TNullable<ResponseSchema>;
199
- getRequestedExtras(opts: {
200
- context: import("@venizia/ignis-kernel").TRouteContext<import("hono").Env>;
201
- }): Array<import("@venizia/ignis-kernel").IRequestedExtra>;
202
- respond<R>(opts: {
203
- context: import("@venizia/ignis-kernel").TRouteContext<import("hono").Env>;
204
- format: import("@venizia/ignis-kernel").TResponseFormat;
205
- payload: {
206
- count: number;
207
- data?: import("@venizia/ignis-helpers").TNullable<R>;
208
- };
209
- range?: import("@venizia/ignis-kernel").TDataRange;
210
- extra?: never;
211
- }): R | {
212
- count: number;
213
- data?: import("@venizia/ignis-helpers").TNullable<R>;
214
- } | null | undefined;
215
- respond<R, Extra extends Record<string, import("@venizia/ignis-kernel").TResponseExtra>>(opts: {
216
- context: import("@venizia/ignis-kernel").TRouteContext<import("hono").Env>;
217
- format: import("@venizia/ignis-kernel").TResponseFormat;
218
- payload: {
219
- count: number;
220
- data?: import("@venizia/ignis-helpers").TNullable<R>;
221
- };
222
- range?: import("@venizia/ignis-kernel").TDataRange;
223
- extra: Extra;
224
- }): Promise<R | {
225
- count: number;
226
- data?: import("@venizia/ignis-helpers").TNullable<R>;
227
- } | {
228
- count?: number;
229
- data?: import("@venizia/ignis-helpers").TNullable<R>;
230
- extra: Partial<Record<keyof Extra, unknown>>;
231
- } | null | undefined>;
232
- respond<R>(opts: {
233
- context: import("@venizia/ignis-kernel").TRouteContext<import("hono").Env>;
234
- format: import("@venizia/ignis-kernel").TResponseFormat;
235
- payload: {
236
- count: number;
237
- data?: import("@venizia/ignis-helpers").TNullable<R>;
238
- };
239
- range?: import("@venizia/ignis-kernel").TDataRange;
240
- extra?: Record<string, import("@venizia/ignis-kernel").TResponseExtra>;
241
- }): ValueOrPromise<R | {
242
- count?: number;
243
- data?: import("@venizia/ignis-helpers").TNullable<R>;
244
- extra?: Record<string, unknown>;
245
- } | null | undefined>;
246
- respondWithExtra<R>(opts: {
247
- context: import("@venizia/ignis-kernel").TRouteContext<import("hono").Env>;
248
- payload: {
249
- count: number;
250
- data?: import("@venizia/ignis-helpers").TNullable<R>;
251
- };
252
- extra: Record<string, import("@venizia/ignis-kernel").TResponseExtra>;
253
- }): Promise<R | {
254
- count: number;
255
- data?: import("@venizia/ignis-helpers").TNullable<R>;
256
- } | {
257
- count: number;
258
- data: import("@venizia/ignis-helpers").TNullable<R>;
259
- extra: Record<string, unknown>;
260
- } | {
261
- data: import("@venizia/ignis-helpers").TNullable<R>;
262
- extra: Record<string, unknown>;
263
- count?: undefined;
264
- } | null | undefined>;
265
- setListHeaders(opts: {
266
- context: import("@venizia/ignis-kernel").TRouteContext<import("hono").Env>;
267
- count: number;
268
- } & ({
269
- range: import("@venizia/ignis-kernel").TDataRange;
270
- } | {
271
- offset: number;
272
- total: number;
273
- })): void;
274
- toHonoHandler<ResponseType = unknown>(opts: {
275
- handler: import("@venizia/ignis-kernel").TRouteHandler<ResponseType, import("hono").Env>;
276
- }): import("hono").Handler<import("hono").Env, string, import("hono").Input, (Response | Promise<Response>) | (import("@hono/zod-openapi").RouteConfigToTypedResponse<import("@hono/zod-openapi").RouteConfig> | Promise<import("@hono/zod-openapi").RouteConfigToTypedResponse<import("@hono/zod-openapi").RouteConfig>>)>;
277
- bindRoute<RouteConfig extends import("@venizia/ignis-kernel").IAuthRouteConfig>(opts: {
278
- configs: RouteConfig;
279
- }): import("@venizia/ignis-kernel").IBindRouteOptions<RouteConfig, import("hono").Env, {}, "/">;
280
- defineRoute<RouteConfig extends import("@venizia/ignis-kernel").IAuthRouteConfig, ResponseType = unknown>(opts: {
281
- configs: RouteConfig;
282
- handler: import("@venizia/ignis-kernel").TRouteHandler<ResponseType, import("hono").Env>;
283
- hook?: import("@hono/zod-openapi").Hook<any, import("hono").Env, string, any> | undefined;
284
- }): import("@venizia/ignis-kernel").IDefineRouteOptions<RouteConfig, import("hono").Env, {}, "/">;
285
- defineJSXRoute<RouteConfig extends import("@venizia/ignis-kernel").IAuthRouteConfig, ResponseType = unknown>(opts: {
286
- configs: RouteConfig;
287
- handler: import("@venizia/ignis-kernel").TRouteHandler<ResponseType, import("hono").Env>;
288
- hook?: import("@hono/zod-openapi").Hook<any, import("hono").Env, string, any> | undefined;
289
- }): import("@venizia/ignis-kernel").IDefineRouteOptions<RouteConfig, import("hono").Env, {}, "/">;
290
- isConfigured: boolean;
291
- router: import("@hono/zod-openapi").OpenAPIHono<import("hono").Env, {}, "/">;
292
- path: string;
293
- definitions: Record<string, import("@venizia/ignis-kernel").IAuthRouteConfig>;
294
- getRouter(): import("@hono/zod-openapi").OpenAPIHono<import("hono").Env, {}, "/">;
295
- registerRoutesFromRegistry(opts?: {
296
- paths?: import("@venizia/ignis-kernel").TRoutePathScope;
297
- }): void;
298
- configure(opts?: {} | undefined): Promise<import("@hono/zod-openapi").OpenAPIHono<import("hono").Env, {}, "/">>;
299
- buildRouteMiddlewares<RouteConfig extends import("@venizia/ignis-kernel").IAuthRouteConfig>(opts: {
300
- configs: RouteConfig;
301
- }): {
302
- restConfig: Omit<RouteConfig, "authenticate" | "authorize">;
303
- security: {
304
- [x: string]: never[];
305
- }[];
306
- mws: import("hono").MiddlewareHandler<import("hono").Env>[];
307
- };
308
- getRouteConfigs<RouteConfig extends import("@venizia/ignis-kernel").IAuthRouteConfig>(opts: {
309
- configs: RouteConfig;
310
- }): RouteConfig & {
311
- getRoutingPath(): RouteConfig["path"] extends infer T ? T extends RouteConfig["path"] ? T extends `${infer Start}/{${infer Param}}${infer Rest}` ? `${Start}/:${Param}${Rest extends `${infer Start_1}/{${infer Param_1}}${infer Rest_1}` ? `${Start_1}/:${Param_1}${Rest_1 extends `${infer Start_2}/{${infer Param_2}}${infer Rest_2}` ? `${Start_2}/:${Param_2}${Rest_2 extends `${infer Start_3}/{${infer Param_3}}${infer Rest_3}` ? `${Start_3}/:${Param_3}${Rest_3 extends `${infer Start_4}/{${infer Param_4}}${infer Rest_4}` ? `${Start_4}/:${Param_4}${Rest_4 extends `${infer Start_5}/{${infer Param_5}}${infer Rest_5}` ? `${Start_5}/:${Param_5}${Rest_5 extends `${infer Start_6}/{${infer Param_6}}${infer Rest_6}` ? `${Start_6}/:${Param_6}${Rest_6 extends `${infer Start_7}/{${infer Param_7}}${infer Rest_7}` ? `${Start_7}/:${Param_7}${Rest_7 extends `${infer Start_8}/{${infer Param_8}}${infer Rest_8}` ? `${Start_8}/:${Param_8}${Rest_8 extends `${infer Start_9}/{${infer Param_9}}${infer Rest_9}` ? `${Start_9}/:${Param_9}${Rest_9 extends `${infer Start_10}/{${infer Param_10}}${infer Rest_10}` ? `${Start_10}/:${Param_10}${any}` : Rest_9}` : Rest_8}` : Rest_7}` : Rest_6}` : Rest_5}` : Rest_4}` : Rest_3}` : Rest_2}` : Rest_1}` : Rest}` : T : never : never;
312
- };
313
- getJSXRouteConfigs<RouteConfig extends import("@venizia/ignis-kernel").IAuthRouteConfig>(opts: {
314
- configs: RouteConfig;
315
- }): RouteConfig & {
316
- getRoutingPath(): RouteConfig["path"] extends infer T ? T extends RouteConfig["path"] ? T extends `${infer Start}/{${infer Param}}${infer Rest}` ? `${Start}/:${Param}${Rest extends `${infer Start_1}/{${infer Param_1}}${infer Rest_1}` ? `${Start_1}/:${Param_1}${Rest_1 extends `${infer Start_2}/{${infer Param_2}}${infer Rest_2}` ? `${Start_2}/:${Param_2}${Rest_2 extends `${infer Start_3}/{${infer Param_3}}${infer Rest_3}` ? `${Start_3}/:${Param_3}${Rest_3 extends `${infer Start_4}/{${infer Param_4}}${infer Rest_4}` ? `${Start_4}/:${Param_4}${Rest_4 extends `${infer Start_5}/{${infer Param_5}}${infer Rest_5}` ? `${Start_5}/:${Param_5}${Rest_5 extends `${infer Start_6}/{${infer Param_6}}${infer Rest_6}` ? `${Start_6}/:${Param_6}${Rest_6 extends `${infer Start_7}/{${infer Param_7}}${infer Rest_7}` ? `${Start_7}/:${Param_7}${Rest_7 extends `${infer Start_8}/{${infer Param_8}}${infer Rest_8}` ? `${Start_8}/:${Param_8}${Rest_8 extends `${infer Start_9}/{${infer Param_9}}${infer Rest_9}` ? `${Start_9}/:${Param_9}${Rest_9 extends `${infer Start_10}/{${infer Param_10}}${infer Rest_10}` ? `${Start_10}/:${Param_10}${any}` : Rest_9}` : Rest_8}` : Rest_7}` : Rest_6}` : Rest_5}` : Rest_4}` : Rest_3}` : Rest_2}` : Rest_1}` : Rest}` : T : never : never;
317
- };
318
- bindDefaultRoutes(): ValueOrPromise<void>;
319
- scope: string;
320
- identifier: string;
321
- get logger(): import("@venizia/ignis-helpers").ILogger;
322
- set logger(value: import("@venizia/ignis-helpers").ILogger);
323
- getIdentifier(): string;
324
- getLogger(): import("@venizia/ignis-helpers").ILogger;
325
- };
326
- };
327
163
  }
328
164
  //# sourceMappingURL=factory.d.ts.map
@@ -10,30 +10,17 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { BaseRestController } from '../../../base/controllers/index.js';
11
11
  import { controller as controllerDecorator } from '../../../base/metadata/index.js';
12
12
  import { getError } from '@venizia/ignis-helpers/core';
13
- import { StaticAssetEntryUtility, } from '../utilities/entry.utility.js';
14
- import { StaticAssetServe } from './routes/serve.js';
13
+ import { StaticAssetEntryUtility } from '../utilities/entry.utility.js';
15
14
  import { StaticAssetRouteTable } from './routes/table.js';
16
- /** Builds the REST controller class for a static asset entry, and decides the served content type. */
15
+ /** Builds the REST controller class for a static asset entry. */
17
16
  export class StaticAssetControllerFactory {
18
- /**
19
- * The served type comes from the object NAME, never the backend or the uploader: a renderable type on
20
- * the API origin is stored XSS. Public so a hand-written route makes the same decision - the
21
- * backend's own content-type is dropped by `StaticAssetHeaders.ALLOWED`.
22
- */
23
- static resolveServedContentType(opts) {
24
- return StaticAssetServe.resolveServedContentType(opts);
25
- }
26
- /** Resolves the entry, then builds its controller. A caller that already holds the resolved entry uses `buildResolved`. */
17
+ /** Resolves the entry, then builds its controller. */
27
18
  static build(opts) {
28
- return StaticAssetControllerFactory.buildResolved({
29
- resolved: StaticAssetEntryUtility.resolve({ key: opts.key, entry: opts.entry }),
30
- policyService: opts.policyService,
31
- commitService: opts.commitService,
32
- });
33
- }
34
- static buildResolved(opts) {
35
19
  const { policyService, commitService } = opts;
36
- const { directUpload, ...resolved } = opts.resolved;
20
+ const { directUpload, ...resolved } = StaticAssetEntryUtility.resolve({
21
+ key: opts.key,
22
+ entry: opts.entry,
23
+ });
37
24
  const { name, basePath, helper, extend } = resolved;
38
25
  if (directUpload && (!policyService || !commitService)) {
39
26
  throw getError({
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/controller/factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAIvD,OAAO,EACL,uBAAuB,GAExB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAevD,sGAAsG;AACtG,MAAM,OAAO,4BAA4B;IACvC;;;;OAIG;IACH,MAAM,CAAC,wBAAwB,CAAC,IAAoD;QAIlF,OAAO,gBAAgB,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,2HAA2H;IAC3H,MAAM,CAAC,KAAK,CACV,IAA2C;QAE3C,OAAO,4BAA4B,CAAC,aAAa,CAAS;YACxD,QAAQ,EAAE,uBAAuB,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAA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AE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC1D,CAAC;SACF,CAAA;QAjBK,8BAA8B;YADnC,mBAAmB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;WAClC,8BAA8B,CAiBnC;QAED,MAAM,CAAC,cAAc,CAAC,8BAA8B,EAAE,MAAM,EAAE;YAC5D,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QAEH,OAAO,8BAA8B,CAAC;IACxC,CAAC;CACF","sourcesContent":["import { BaseRestController } from '@/base/controllers';\nimport { controller as controllerDecorator } from '@/base/metadata';\nimport type { IObjectRef, IStorageHelper } from '@venizia/ignis-helpers';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { TStaticAssetEntry } from '../common';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models';\nimport type { StaticAssetUploadCommitService, StaticAssetUploadPolicyService } from '../services';\nimport {\n StaticAssetEntryUtility,\n type IStaticAssetResolvedEntry,\n} from '../utilities/entry.utility';\nimport { StaticAssetServe } from './routes/serve';\nimport { StaticAssetRouteTable } from './routes/table';\n\n/** Input of `StaticAssetControllerFactory.build`: one entry of `TStaticAssetComponentOptions` and its key. */\nexport interface IStaticAssetControllerOptions<\n Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema,\n> {\n /** The entry's key in the options object: the controller's name is derived from it. */\n key: string;\n entry: TStaticAssetEntry<Schema>;\n\n /** What the direct upload routes run: the instances the component bound, so an application service resolving them from the container and the routes share them. Required when the entry turns `directUpload` on. */\n policyService?: Pick<StaticAssetUploadPolicyService, 'issuePolicies'>;\n commitService?: Pick<StaticAssetUploadCommitService<Schema>, 'commit' | 'validate'>;\n}\n\n/** Builds the REST controller class for a static asset entry, and decides the served content type. */\nexport class StaticAssetControllerFactory {\n /**\n * The served type comes from the object NAME, never the backend or the uploader: a renderable type on\n * the API origin is stored XSS. Public so a hand-written route makes the same decision - the\n * backend's own content-type is dropped by `StaticAssetHeaders.ALLOWED`.\n */\n static resolveServedContentType(opts: { helper: IStorageHelper; object: IObjectRef }): {\n contentType: string;\n isRenderable: boolean;\n } {\n return StaticAssetServe.resolveServedContentType(opts);\n }\n\n /** Resolves the entry, then builds its controller. A caller that already holds the resolved entry uses `buildResolved`. */\n static build<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema>(\n opts: IStaticAssetControllerOptions<Schema>,\n ) {\n return StaticAssetControllerFactory.buildResolved<Schema>({\n resolved: StaticAssetEntryUtility.resolve({ key: opts.key, entry: opts.entry }),\n policyService: opts.policyService,\n commitService: opts.commitService,\n });\n }\n\n static buildResolved<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema>(opts: {\n resolved: IStaticAssetResolvedEntry<Schema>;\n policyService?: Pick<StaticAssetUploadPolicyService, 'issuePolicies'>;\n commitService?: Pick<StaticAssetUploadCommitService<Schema>, 'commit' | 'validate'>;\n }) {\n const { policyService, commitService } = opts;\n const { directUpload, ...resolved } = opts.resolved;\n const { name, basePath, helper, extend } = resolved;\n\n if (directUpload && (!policyService || !commitService)) {\n throw getError({\n message: `[${name}] directUpload needs policyService and commitService | the component builds and binds them; a caller of StaticAssetControllerFactory.build passes its own`,\n });\n }\n\n const env = {\n ...resolved,\n directUpload: directUpload &&\n policyService &&\n commitService && { ...directUpload, policyService, commitService },\n };\n\n @controllerDecorator({ path: basePath })\n class GeneratedStaticAssetController extends BaseRestController {\n constructor() {\n super({ scope: name, path: basePath });\n }\n\n override binding(): ValueOrPromise<void> {\n // First, so a literal path can win over the built-in catch-all `rawObjectPath` registers.\n extend?.before?.({ controller: this, helper, basePath });\n\n StaticAssetRouteTable.register({\n controller: this,\n env: { ...env, logger: this.logger },\n });\n\n // Last, so a built-in route always wins a path collision with an application's own.\n extend?.after?.({ controller: this, helper, basePath });\n }\n }\n\n Object.defineProperty(GeneratedStaticAssetController, 'name', {\n value: name,\n configurable: true,\n });\n\n return GeneratedStaticAssetController;\n }\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/controller/factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAIvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAevD,iEAAiE;AACjE,MAAM,OAAO,4BAA4B;IACvC,sDAAsD;IAC/C,AAAP,MAAM,CAAC,KAAK,CACV,IAA2C;QAE3C,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;QAC9C,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,EAAE,GAAG,uBAAuB,CAAC,OAAO,CAAC;YACpE,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;QAEpD,IAAI,YAAY,IAAI,CAAC,CAAC,aAAa,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YACvD,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,IAAI,IAAI,2JAA2J;aAC7K,CAAC,CAAC;QACL,CAAC;QAED,MAAM,GAAG,GAAG;YACV,GAAG,QAAQ;YACX,YAAY,EAAE,YAAY;gBACxB,aAAa;gBACb,aAAa,IAAI,EAAE,GAAG,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE;SACrE,CAAC;QAEF,IACM,8BAA8B,GADpC,MACM,8BAA+B,SAAQ,kBAAkB;YAC7D;gBACE,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YACzC,CAAC;YAEQ,OAAO;gBACd,0FAA0F;gBAC1F,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAEzD,qBAAqB,CAAC,QAAQ,CAAC;oBAC7B,UAAU,EAAE,IAAI;oBAChB,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;iBACrC,CAAC,CAAC;gBAEH,oFAAoF;gBACpF,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC1D,CAAC;SACF,CAAA;QAjBK,8BAA8B;YADnC,mBAAmB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;WAClC,8BAA8B,CAiBnC;QAED,MAAM,CAAC,cAAc,CAAC,8BAA8B,EAAE,MAAM,EAAE;YAC5D,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QAEH,OAAO,8BAA8B,CAAC;IACxC,CAAC;CACF","sourcesContent":["import { BaseRestController } from '@/base/controllers';\nimport { controller as controllerDecorator } from '@/base/metadata';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { TStaticAssetEntry } from '../common';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models';\nimport type { StaticAssetUploadCommitService, StaticAssetUploadPolicyService } from '../services';\nimport { StaticAssetEntryUtility } from '../utilities/entry.utility';\nimport { StaticAssetRouteTable } from './routes/table';\n\n/** Input of `StaticAssetControllerFactory.build`: one entry of `TStaticAssetComponentOptions` and its key. */\nexport interface IStaticAssetControllerOptions<\n Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema,\n> {\n /** The entry's key in the options object: the controller's name is derived from it. */\n key: string;\n entry: TStaticAssetEntry<Schema>;\n\n /** What the direct upload routes run: the instances the component bound, so an application service resolving them from the container and the routes share them. Required when the entry turns `directUpload` on. */\n policyService?: Pick<StaticAssetUploadPolicyService, 'issuePolicies'>;\n commitService?: Pick<StaticAssetUploadCommitService<Schema>, 'commit' | 'validate'>;\n}\n\n/** Builds the REST controller class for a static asset entry. */\nexport class StaticAssetControllerFactory {\n /** Resolves the entry, then builds its controller. */\n static build<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema>(\n opts: IStaticAssetControllerOptions<Schema>,\n ) {\n const { policyService, commitService } = opts;\n const { directUpload, ...resolved } = StaticAssetEntryUtility.resolve({\n key: opts.key,\n entry: opts.entry,\n });\n const { name, basePath, helper, extend } = resolved;\n\n if (directUpload && (!policyService || !commitService)) {\n throw getError({\n message: `[${name}] directUpload needs policyService and commitService | the component builds and binds them; a caller of StaticAssetControllerFactory.build passes its own`,\n });\n }\n\n const env = {\n ...resolved,\n directUpload: directUpload &&\n policyService &&\n commitService && { ...directUpload, policyService, commitService },\n };\n\n @controllerDecorator({ path: basePath })\n class GeneratedStaticAssetController extends BaseRestController {\n constructor() {\n super({ scope: name, path: basePath });\n }\n\n override binding(): ValueOrPromise<void> {\n // First, so a literal path can win over the built-in catch-all `rawObjectPath` registers.\n extend?.before?.({ controller: this, helper, basePath });\n\n StaticAssetRouteTable.register({\n controller: this,\n env: { ...env, logger: this.logger },\n });\n\n // Last, so a built-in route always wins a path collision with an application's own.\n extend?.after?.({ controller: this, helper, basePath });\n }\n }\n\n Object.defineProperty(GeneratedStaticAssetController, 'name', {\n value: name,\n configurable: true,\n });\n\n return GeneratedStaticAssetController;\n }\n}\n"]}
@@ -1,2 +1,3 @@
1
1
  export * from './factory.js';
2
+ export { StaticAssetServe } from './routes/serve.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export * from './factory.js';
2
+ export { StaticAssetServe } from './routes/serve.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/controller/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC","sourcesContent":["export * from './factory';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/controller/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export * from './factory';\nexport { StaticAssetServe } from './routes/serve';\n"]}
@@ -30,7 +30,7 @@ export interface IStaticAssetRoute {
30
30
  /** The OpenAPI definition and the handler of one route, side by side. */
31
31
  build: (env: IStaticAssetRouteEnv) => {
32
32
  config: IAuthRouteConfig;
33
- handler: TRouteHandler<AnyType>;
33
+ handler: TRouteHandler;
34
34
  };
35
35
  /** Middleware the route adds after the application's own. */
36
36
  middleware?: (opts: {
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../../../src/components/static-asset/controller/routes/context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,iBAAiB,GAGlB,MAAM,cAAc,CAAC;AAMtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAG/E,kGAAkG;AAClG,MAAM,OAAO,mBAAmB;aACd,WAAM,GAAG,QAAQ,CAAC;aAClB,kBAAa,GAAG,cAAc,CAAC;aAC/B,kBAAa,GAAG,cAAc,CAAC;aAC/B,eAAU,GAAG,YAAY,CAAC;aAC1B,cAAS,GAAG,UAAU,CAAC;;AAmCzC,MAAM,OAAO,uBAAuB;IAClC,sHAAsH;IACtH,MAAM,CAAC,cAAc,CAAI,IAA4D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E,CAAC,CAAC;QACnE,CAAC;QAED,0BAA0B,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;QAE5E,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC;IAC3D,CAAC;CACF","sourcesContent":["import type { BaseRestController, TRouteContext, TRouteHandler } from '@/base/controllers';\nimport type { IAuthRouteConfig } from '@/base';\nimport type { IBucketRef, IObjectRef } from '@venizia/ignis-helpers';\nimport { ResolverUtility } from '@venizia/ignis-helpers/common';\nimport type { AnyType, TConstValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport {\n StaticAssetErrors,\n type TStaticAssetObjectParams,\n type TStaticAssetRouteKey,\n} from '../../common';\nimport type {\n StaticAssetUploadCommitService,\n StaticAssetUploadPolicyService,\n} from '../../services';\nimport type { IStaticAssetResolvedEntry } from '../../utilities/entry.utility';\nimport { StaticAssetKeyScopeUtility } from '../../utilities/key-scope.utility';\nimport type { TStaticAssetRouteOverride } from '../../utilities/route-options.utility';\n\n/** The part of an entry a route belongs to: a route is registered only when its feature is on. */\nexport class StaticAssetFeatures {\n static readonly OBJECT = 'object';\n static readonly SERVER_UPLOAD = 'serverUpload';\n static readonly DIRECT_UPLOAD = 'directUpload';\n static readonly VALIDATION = 'validation';\n static readonly META_LINK = 'metaLink';\n}\n\nexport type TStaticAssetFeature = TConstValue<typeof StaticAssetFeatures>;\n\n/** What every route reads: the entry, resolved once, plus what only the running controller has. The table is erased at this seam on purpose: inside the routes every read and write is on MetaLink COLUMNS. */\nexport interface IStaticAssetRouteEnv extends Omit<\n IStaticAssetResolvedEntry<AnyType>,\n 'directUpload'\n> {\n logger: BaseRestController['logger'];\n /** The resolved options with the services the component bound: the instances an application resolves from the container. */\n directUpload?: NonNullable<IStaticAssetResolvedEntry<AnyType>['directUpload']> & {\n policyService: Pick<StaticAssetUploadPolicyService, 'issuePolicies'>;\n commitService: Pick<StaticAssetUploadCommitService, 'commit' | 'validate'>;\n };\n}\n\nexport interface IStaticAssetRoute {\n key: TStaticAssetRouteKey;\n feature: TStaticAssetFeature;\n\n /** The OpenAPI definition and the handler of one route, side by side. */\n build: (env: IStaticAssetRouteEnv) => {\n config: IAuthRouteConfig;\n handler: TRouteHandler<AnyType>;\n };\n\n /** Middleware the route adds after the application's own. */\n middleware?: (opts: {\n env: IStaticAssetRouteEnv;\n own: TStaticAssetRouteOverride['middleware'];\n }) => TStaticAssetRouteOverride['middleware'];\n}\n\nexport class StaticAssetRouteUtility {\n /** A route builder reaches for an option its feature guarantees; a miss is a bug in the table, never in the input. */\n static requireFeature<T>(opts: { value: T | undefined; feature: TStaticAssetFeature }): T {\n if (opts.value === undefined) {\n throw getError({\n message: `[static-asset] a ${opts.feature} route was built without its ${opts.feature} option`,\n });\n }\n\n return opts.value;\n }\n\n /**\n * The bucket, and for an object route the key, one request names - checked and scoped before any\n * storage call, so a key outside the scope is never even probed.\n */\n static async resolveTarget(opts: {\n ctx: TRouteContext;\n env: IStaticAssetRouteEnv;\n /** An object route also names a key. */\n isObject?: boolean;\n }): Promise<{ bucket: IBucketRef; object: IObjectRef }> {\n const { ctx, env, isObject = false } = opts;\n // Read per request: an application may read an environment variable lazily.\n const bucketName = await ResolverUtility.resolveValueAsync({ value: env.bucket });\n\n if (!env.helper.isValidBucketName({ bucket: { name: bucketName } })) {\n throw getError({ error: StaticAssetErrors.BUCKET_NAME_INVALID });\n }\n\n if (!isObject) {\n return { bucket: { name: bucketName }, object: { key: '' } };\n }\n\n const { objectName: key } = ctx.req.valid<TStaticAssetObjectParams>('param');\n\n if (!env.helper.isValidObjectKey({ object: { key }, maxDepth: env.objectKeyMaxDepth })) {\n throw getError({ error: StaticAssetErrors.OBJECT_NAME_INVALID });\n }\n\n StaticAssetKeyScopeUtility.assertInScope({ key, keyPrefix: env.keyPrefix });\n\n return { bucket: { name: bucketName }, object: { key } };\n }\n}\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../../../src/components/static-asset/controller/routes/context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,iBAAiB,GAGlB,MAAM,cAAc,CAAC;AAMtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAG/E,kGAAkG;AAClG,MAAM,OAAO,mBAAmB;aACd,WAAM,GAAG,QAAQ,CAAC;aAClB,kBAAa,GAAG,cAAc,CAAC;aAC/B,kBAAa,GAAG,cAAc,CAAC;aAC/B,eAAU,GAAG,YAAY,CAAC;aAC1B,cAAS,GAAG,UAAU,CAAC;;AAmCzC,MAAM,OAAO,uBAAuB;IAClC,sHAAsH;IACtH,MAAM,CAAC,cAAc,CAAI,IAA4D;QACnF,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,oBAAoB,IAAI,CAAC,OAAO,gCAAgC,IAAI,CAAC,OAAO,SAAS;aAC/F,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,IAK1B;QACC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;QAC5C,4EAA4E;QAC5E,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAElF,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC;YACpE,MAAM,QAAQ,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,mBAAmB,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC;QAC/D,CAAC;QAED,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAA2B,OAAO,CAAC,CAAC;QAE7E,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,iBAAiB,EAAE,CAAC,EAAE,CAAC;YACvF,MAAM,QAAQ,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,mBAAmB,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,0BAA0B,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;QAE5E,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC;IAC3D,CAAC;CACF","sourcesContent":["import type { BaseRestController, TRouteContext, TRouteHandler } from '@/base/controllers';\nimport type { IAuthRouteConfig } from '@/base';\nimport type { IBucketRef, IObjectRef } from '@venizia/ignis-helpers';\nimport { ResolverUtility } from '@venizia/ignis-helpers/common';\nimport type { AnyType, TConstValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport {\n StaticAssetErrors,\n type TStaticAssetObjectParams,\n type TStaticAssetRouteKey,\n} from '../../common';\nimport type {\n StaticAssetUploadCommitService,\n StaticAssetUploadPolicyService,\n} from '../../services';\nimport type { IStaticAssetResolvedEntry } from '../../utilities/entry.utility';\nimport { StaticAssetKeyScopeUtility } from '../../utilities/key-scope.utility';\nimport type { TStaticAssetRouteOverride } from '../../utilities/route-options.utility';\n\n/** The part of an entry a route belongs to: a route is registered only when its feature is on. */\nexport class StaticAssetFeatures {\n static readonly OBJECT = 'object';\n static readonly SERVER_UPLOAD = 'serverUpload';\n static readonly DIRECT_UPLOAD = 'directUpload';\n static readonly VALIDATION = 'validation';\n static readonly META_LINK = 'metaLink';\n}\n\nexport type TStaticAssetFeature = TConstValue<typeof StaticAssetFeatures>;\n\n/** What every route reads: the entry, resolved once, plus what only the running controller has. The table is erased at this seam on purpose: inside the routes every read and write is on MetaLink COLUMNS. */\nexport interface IStaticAssetRouteEnv extends Omit<\n IStaticAssetResolvedEntry<AnyType>,\n 'directUpload'\n> {\n logger: BaseRestController['logger'];\n /** The resolved options with the services the component bound: the instances an application resolves from the container. */\n directUpload?: NonNullable<IStaticAssetResolvedEntry<AnyType>['directUpload']> & {\n policyService: Pick<StaticAssetUploadPolicyService, 'issuePolicies'>;\n commitService: Pick<StaticAssetUploadCommitService, 'commit' | 'validate'>;\n };\n}\n\nexport interface IStaticAssetRoute {\n key: TStaticAssetRouteKey;\n feature: TStaticAssetFeature;\n\n /** The OpenAPI definition and the handler of one route, side by side. */\n build: (env: IStaticAssetRouteEnv) => {\n config: IAuthRouteConfig;\n handler: TRouteHandler;\n };\n\n /** Middleware the route adds after the application's own. */\n middleware?: (opts: {\n env: IStaticAssetRouteEnv;\n own: TStaticAssetRouteOverride['middleware'];\n }) => TStaticAssetRouteOverride['middleware'];\n}\n\nexport class StaticAssetRouteUtility {\n /** A route builder reaches for an option its feature guarantees; a miss is a bug in the table, never in the input. */\n static requireFeature<T>(opts: { value: T | undefined; feature: TStaticAssetFeature }): T {\n if (opts.value === undefined) {\n throw getError({\n message: `[static-asset] a ${opts.feature} route was built without its ${opts.feature} option`,\n });\n }\n\n return opts.value;\n }\n\n /**\n * The bucket, and for an object route the key, one request names - checked and scoped before any\n * storage call, so a key outside the scope is never even probed.\n */\n static async resolveTarget(opts: {\n ctx: TRouteContext;\n env: IStaticAssetRouteEnv;\n /** An object route also names a key. */\n isObject?: boolean;\n }): Promise<{ bucket: IBucketRef; object: IObjectRef }> {\n const { ctx, env, isObject = false } = opts;\n // Read per request: an application may read an environment variable lazily.\n const bucketName = await ResolverUtility.resolveValueAsync({ value: env.bucket });\n\n if (!env.helper.isValidBucketName({ bucket: { name: bucketName } })) {\n throw getError({ error: StaticAssetErrors.BUCKET_NAME_INVALID });\n }\n\n if (!isObject) {\n return { bucket: { name: bucketName }, object: { key: '' } };\n }\n\n const { objectName: key } = ctx.req.valid<TStaticAssetObjectParams>('param');\n\n if (!env.helper.isValidObjectKey({ object: { key }, maxDepth: env.objectKeyMaxDepth })) {\n throw getError({ error: StaticAssetErrors.OBJECT_NAME_INVALID });\n }\n\n StaticAssetKeyScopeUtility.assertInScope({ key, keyPrefix: env.keyPrefix });\n\n return { bucket: { name: bucketName }, object: { key } };\n }\n}\n"]}
@@ -3,12 +3,21 @@ import { OpenApiResponses } from '@venizia/ignis-kernel';
3
3
  import { HTTP } from '@venizia/ignis-helpers/common';
4
4
  const assemble = (opts) => {
5
5
  const { method, path, params, query, contentType, body, responses } = opts;
6
- const request = {
7
- ...(params ? { params } : {}),
8
- ...(query ? { query } : {}),
9
- ...(body && contentType ? { body: { content: { [contentType]: { schema: body } } } } : {}),
10
- };
11
- return { method, path, ...(Object.keys(request).length > 0 ? { request } : {}), responses };
6
+ const request = {};
7
+ const config = { method, path, responses };
8
+ if (params) {
9
+ request.params = params;
10
+ }
11
+ if (query) {
12
+ request.query = query;
13
+ }
14
+ if (body && contentType) {
15
+ request.body = { content: { [contentType]: { schema: body } } };
16
+ }
17
+ if (Object.keys(request).length > 0) {
18
+ config.request = request;
19
+ }
20
+ return config;
12
21
  };
13
22
  /** The one place a route definition is assembled: no route writes `request.body.content[...]` by hand. */
14
23
  export class StaticAssetDefinition {
@@ -1 +1 @@
1
- {"version":3,"file":"definition.js","sourceRoot":"","sources":["../../../../../../src/components/static-asset/controller/routes/definition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAarD,MAAM,QAAQ,GAAG,CACf,IAIC,EACiB,EAAE;IACpB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAC3E,MAAM,OAAO,GAAa;QACxB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7B,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,IAAI,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3F,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC;AAC9F,CAAC,CAAC;AAEF,0GAA0G;AAC1G,MAAM,OAAO,qBAAqB;IAChC,yBAAyB;IACzB,MAAM,CAAC,IAAI,CACT,IAAuF;QAEvF,OAAO,QAAQ,CAAC;YACd,GAAG,IAAI;YACP,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC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,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,cAAc,CAAC;IACtE,CAAC;IAED,8CAA8C;IAC9C,MAAM,CAAC,YAAY;QACjB,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,eAAe,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;CACF","sourcesContent":["import type { IAuthRouteConfig } from '@/base';\nimport { z } from '@hono/zod-openapi';\nimport { OpenApiResponses } from '@venizia/ignis-kernel';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { IStaticAssetRouteEnv } from './context';\n\ntype TRequest = NonNullable<IAuthRouteConfig['request']>;\ntype TMethod = IAuthRouteConfig['method'];\n\ninterface IDefinitionOpts {\n method: TMethod;\n path: string;\n params?: z.ZodObject;\n query?: z.ZodObject;\n}\n\nconst assemble = (\n opts: IDefinitionOpts & {\n contentType?: string;\n body?: z.ZodType;\n responses: IAuthRouteConfig['responses'];\n },\n): IAuthRouteConfig => {\n const { method, path, params, query, contentType, body, responses } = opts;\n const request: TRequest = {\n ...(params ? { params } : {}),\n ...(query ? { query } : {}),\n ...(body && contentType ? { body: { content: { [contentType]: { schema: body } } } } : {}),\n };\n\n return { method, path, ...(Object.keys(request).length > 0 ? { request } : {}), responses };\n};\n\n/** The one place a route definition is assembled: no route writes `request.body.content[...]` by hand. */\nexport class StaticAssetDefinition {\n /** JSON in, JSON out. */\n static json(\n opts: IDefinitionOpts & { body?: z.ZodType; response: z.ZodType; description?: string },\n ): IAuthRouteConfig {\n return assemble({\n ...opts,\n contentType: HTTP.HeaderValues.APPLICATION_JSON,\n responses: OpenApiResponses.jsonResponse({\n schema: opts.response,\n description: opts.description,\n }),\n });\n }\n\n /** A multipart form in, JSON out. */\n static multipart(\n opts: IDefinitionOpts & { body: z.ZodType; response: z.ZodType },\n ): IAuthRouteConfig {\n return assemble({\n ...opts,\n contentType: HTTP.HeaderValues.MULTIPART_FORM_DATA,\n responses: OpenApiResponses.jsonResponse({ schema: opts.response }),\n });\n }\n\n /** A file stream out. */\n static stream(opts: IDefinitionOpts): IAuthRouteConfig {\n return assemble({\n ...opts,\n responses: {\n [HTTP.ResultCodes.RS_2.Ok]: {\n description: 'File stream response',\n content: {\n [HTTP.HeaderValues.APPLICATION_OCTET_STREAM]: {\n schema: { type: 'string', format: 'binary' },\n },\n },\n },\n ...OpenApiResponses.errorResponses(),\n },\n });\n }\n}\n\nconst objectNameParam = () =>\n z.string().openapi({\n param: {\n name: 'objectName',\n in: 'path',\n description: 'Object name or path (e.g., \"photo.jpg\" or \"photos/2024/photo.jpg\")',\n },\n example: 'photos/2024/photo.jpg',\n });\n\n/** Where a route sits in the URL and which path params it carries. */\nexport class StaticAssetPaths {\n /**\n * `{objectName}` is ONE segment: a folder path travels percent-encoded (`photos%2F2024%2Ff.jpg`).\n * `rawObjectPath` adds the `{.+}` catch-all, the spelling `@hono/zod-openapi` translates.\n */\n static object(opts: { env: IStaticAssetRouteEnv }): string {\n return opts.env.rawObjectPath ? '{objectName}{.+}' : '{objectName}';\n }\n\n /** Params of a route that names an object. */\n static objectParams(): z.ZodObject {\n return z.object({ objectName: objectNameParam() });\n }\n}\n"]}
1
+ {"version":3,"file":"definition.js","sourceRoot":"","sources":["../../../../../../src/components/static-asset/controller/routes/definition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAarD,MAAM,QAAQ,GAAG,CACf,IAIC,EACiB,EAAE;IACpB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAC3E,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAqB,EAAE,MAAM,EAAE,IAA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,CAAC;YACd,GAAG,IAAI;YACP,SAAS,EAAE;gBACT,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;oBAC1B,WAAW,EAAE,sBAAsB;oBACnC,OAAO,EAAE;wBACP,CAAC,IAAI,CAAC,YAAY,CAAC,wBAAwB,CAAC,EAAE;4BAC5C,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE;yBAC7C;qBACF;iBACF;gBACD,GAAG,gBAAgB,CAAC,cAAc,EAAE;aACrC;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,eAAe,GAAG,GAAG,EAAE,CAC3B,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC;IACjB,KAAK,EAAE;QACL,IAAI,EAAE,YAAY;QAClB,EAAE,EAAE,MAAM;QACV,WAAW,EAAE,oEAAoE;KAClF;IACD,OAAO,EAAE,uBAAuB;CACjC,CAAC,CAAC;AAEL,sEAAsE;AACtE,MAAM,OAAO,gBAAgB;IAC3B;;;OAGG;IACH,MAAM,CAAC,MAAM,CAAC,IAAmC;QAC/C,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,cAAc,CAAC;IACtE,CAAC;IAED,8CAA8C;IAC9C,MAAM,CAAC,YAAY;QACjB,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,eAAe,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;CACF","sourcesContent":["import type { IAuthRouteConfig } from '@/base';\nimport { z } from '@hono/zod-openapi';\nimport { OpenApiResponses } from '@venizia/ignis-kernel';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { IStaticAssetRouteEnv } from './context';\n\ntype TRequest = NonNullable<IAuthRouteConfig['request']>;\ntype TMethod = IAuthRouteConfig['method'];\n\ninterface IDefinitionOpts {\n method: TMethod;\n path: string;\n params?: z.ZodObject;\n query?: z.ZodObject;\n}\n\nconst assemble = (\n opts: IDefinitionOpts & {\n contentType?: string;\n body?: z.ZodType;\n responses: IAuthRouteConfig['responses'];\n },\n): IAuthRouteConfig => {\n const { method, path, params, query, contentType, body, responses } = opts;\n const request: TRequest = {};\n const config: IAuthRouteConfig = { method, path, responses };\n\n if (params) {\n request.params = params;\n }\n\n if (query) {\n request.query = query;\n }\n\n if (body && contentType) {\n request.body = { content: { [contentType]: { schema: body } } };\n }\n\n if (Object.keys(request).length > 0) {\n config.request = request;\n }\n\n return config;\n};\n\n/** The one place a route definition is assembled: no route writes `request.body.content[...]` by hand. */\nexport class StaticAssetDefinition {\n /** JSON in, JSON out. */\n static json(\n opts: IDefinitionOpts & { body?: z.ZodType; response: z.ZodType; description?: string },\n ): IAuthRouteConfig {\n return assemble({\n ...opts,\n contentType: HTTP.HeaderValues.APPLICATION_JSON,\n responses: OpenApiResponses.jsonResponse({\n schema: opts.response,\n description: opts.description,\n }),\n });\n }\n\n /** A multipart form in, JSON out. */\n static multipart(\n opts: IDefinitionOpts & { body: z.ZodType; response: z.ZodType },\n ): IAuthRouteConfig {\n return assemble({\n ...opts,\n contentType: HTTP.HeaderValues.MULTIPART_FORM_DATA,\n responses: OpenApiResponses.jsonResponse({ schema: opts.response }),\n });\n }\n\n /** A file stream out. */\n static stream(opts: IDefinitionOpts): IAuthRouteConfig {\n return assemble({\n ...opts,\n responses: {\n [HTTP.ResultCodes.RS_2.Ok]: {\n description: 'File stream response',\n content: {\n [HTTP.HeaderValues.APPLICATION_OCTET_STREAM]: {\n schema: { type: 'string', format: 'binary' },\n },\n },\n },\n ...OpenApiResponses.errorResponses(),\n },\n });\n }\n}\n\nconst objectNameParam = () =>\n z.string().openapi({\n param: {\n name: 'objectName',\n in: 'path',\n description: 'Object name or path (e.g., \"photo.jpg\" or \"photos/2024/photo.jpg\")',\n },\n example: 'photos/2024/photo.jpg',\n });\n\n/** Where a route sits in the URL and which path params it carries. */\nexport class StaticAssetPaths {\n /**\n * `{objectName}` is ONE segment: a folder path travels percent-encoded (`photos%2F2024%2Ff.jpg`).\n * `rawObjectPath` adds the `{.+}` catch-all, the spelling `@hono/zod-openapi` translates.\n */\n static object(opts: { env: IStaticAssetRouteEnv }): string {\n return opts.env.rawObjectPath ? '{objectName}{.+}' : '{objectName}';\n }\n\n /** Params of a route that names an object. */\n static objectParams(): z.ZodObject {\n return z.object({ objectName: objectNameParam() });\n }\n}\n"]}
@@ -20,7 +20,25 @@ class StaticAssetDirectUploadGuard {
20
20
  if (!isAuthorized) {
21
21
  throw getError({ error: StaticAssetErrors.UPLOAD_NOT_AUTHORIZED });
22
22
  }
23
- return direct.resolveOwner?.({ context: ctx });
23
+ return direct.resolvers.owner({ context: ctx });
24
+ }
25
+ /** What the token signs for each file: only what the application's resolver returns, never the client's hint itself. */
26
+ static resolveFiles(opts) {
27
+ const { ctx, direct, files } = opts;
28
+ const resolve = direct.resolvers.metadata;
29
+ return Promise.all(files.map(async (file) => {
30
+ if (!resolve) {
31
+ if (file.metadata) {
32
+ throw getError({
33
+ error: StaticAssetErrors.UPLOAD_METADATA_INVALID,
34
+ message: 'This upload takes no metadata from the client',
35
+ });
36
+ }
37
+ return { ...file, metadata: {} };
38
+ }
39
+ const metadata = await resolve({ context: ctx, file });
40
+ return { ...file, metadata };
41
+ }));
24
42
  }
25
43
  }
26
44
  const CommitTokenSchema = z.object({ commitToken: z.string().min(1) });
@@ -39,6 +57,7 @@ const uploadPolicy = {
39
57
  fileName: z.string().min(1),
40
58
  contentType: z.string().optional(),
41
59
  size: z.number().int().nonnegative().optional(),
60
+ metadata: z.record(z.string(), z.string()).optional(),
42
61
  }))
43
62
  .max(direct.maxFiles ?? StaticAssetDefaults.MAX_UPLOAD_FILES),
44
63
  }),
@@ -54,7 +73,8 @@ const uploadPolicy = {
54
73
  handler: async (ctx) => {
55
74
  const owner = await StaticAssetDirectUploadGuard.guard({ ctx, direct });
56
75
  const { files } = ctx.req.valid('json');
57
- const policies = await direct.policyService.issuePolicies({ files, owner });
76
+ const resolved = await StaticAssetDirectUploadGuard.resolveFiles({ ctx, direct, files });
77
+ const policies = await direct.policyService.issuePolicies({ files: resolved, owner });
58
78
  return ctx.json(policies, HTTP.ResultCodes.RS_2.Ok);
59
79
  },
60
80
  };
@@ -75,6 +95,8 @@ const uploadCommit = {
75
95
  response: z.object({
76
96
  bucket: z.object({ name: z.string() }),
77
97
  object: z.object({ key: z.string() }),
98
+ owner: z.string(),
99
+ metadata: z.record(z.string(), z.string()),
78
100
  link: z.string(),
79
101
  metaLink: MetaLinkOutcomeSchema,
80
102
  }),