@venizia/ignis 0.4.8-10 → 0.4.8-12

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 (115) hide show
  1. package/dist/esm/components/auth/authenticate/component.js +1 -1
  2. package/dist/esm/components/auth/authenticate/component.js.map +1 -1
  3. package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +1 -1
  4. package/dist/esm/components/auth/authenticate/controllers/factory.js +1 -1
  5. package/dist/esm/components/auth/authenticate/controllers/factory.js.map +1 -1
  6. package/dist/esm/components/mail/common/types/queue.d.ts +8 -4
  7. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  8. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +1 -1
  9. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +2 -16
  10. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  11. package/dist/esm/components/static-asset/common/constants.d.ts +43 -24
  12. package/dist/esm/components/static-asset/common/constants.js +74 -47
  13. package/dist/esm/components/static-asset/common/constants.js.map +1 -1
  14. package/dist/esm/components/static-asset/common/errors.d.ts +11 -43
  15. package/dist/esm/components/static-asset/common/errors.js +11 -40
  16. package/dist/esm/components/static-asset/common/errors.js.map +1 -1
  17. package/dist/esm/components/static-asset/common/index.d.ts +1 -1
  18. package/dist/esm/components/static-asset/common/index.js +1 -1
  19. package/dist/esm/components/static-asset/common/index.js.map +1 -1
  20. package/dist/esm/components/static-asset/common/keys.d.ts +10 -2
  21. package/dist/esm/components/static-asset/common/keys.js +10 -2
  22. package/dist/esm/components/static-asset/common/keys.js.map +1 -1
  23. package/dist/esm/components/static-asset/common/types.d.ts +196 -141
  24. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  25. package/dist/esm/components/static-asset/common/validation.d.ts +10 -0
  26. package/dist/esm/components/static-asset/common/validation.js +8 -0
  27. package/dist/esm/components/static-asset/common/validation.js.map +1 -0
  28. package/dist/esm/components/static-asset/component.d.ts +4 -2
  29. package/dist/esm/components/static-asset/component.js +26 -31
  30. package/dist/esm/components/static-asset/component.js.map +1 -1
  31. package/dist/esm/components/static-asset/controller/factory.d.ts +188 -66
  32. package/dist/esm/components/static-asset/controller/factory.js +34 -912
  33. package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
  34. package/dist/esm/components/static-asset/controller/routes/context.d.ts +61 -0
  35. package/dist/esm/components/static-asset/controller/routes/context.js +45 -0
  36. package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -0
  37. package/dist/esm/components/static-asset/controller/routes/definition.d.ts +40 -0
  38. package/dist/esm/components/static-asset/controller/routes/definition.js +74 -0
  39. package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -0
  40. package/dist/esm/components/static-asset/controller/routes/direct-upload.d.ts +3 -0
  41. package/dist/esm/components/static-asset/controller/routes/direct-upload.js +125 -0
  42. package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -0
  43. package/dist/esm/components/static-asset/controller/routes/labels.d.ts +16 -0
  44. package/dist/esm/components/static-asset/controller/routes/labels.js +19 -0
  45. package/dist/esm/components/static-asset/controller/routes/labels.js.map +1 -0
  46. package/dist/esm/components/static-asset/controller/routes/objects.d.ts +7 -0
  47. package/dist/esm/components/static-asset/controller/routes/objects.js +193 -0
  48. package/dist/esm/components/static-asset/controller/routes/objects.js.map +1 -0
  49. package/dist/esm/components/static-asset/controller/routes/serve.d.ts +17 -0
  50. package/dist/esm/components/static-asset/controller/routes/serve.js +127 -0
  51. package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -0
  52. package/dist/esm/components/static-asset/controller/routes/table.d.ts +12 -0
  53. package/dist/esm/components/static-asset/controller/routes/table.js +52 -0
  54. package/dist/esm/components/static-asset/controller/routes/table.js.map +1 -0
  55. package/dist/esm/components/static-asset/controller/routes/upload.d.ts +10 -0
  56. package/dist/esm/components/static-asset/controller/routes/upload.js +174 -0
  57. package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
  58. package/dist/esm/components/static-asset/index.d.ts +2 -1
  59. package/dist/esm/components/static-asset/index.js +2 -1
  60. package/dist/esm/components/static-asset/index.js.map +1 -1
  61. package/dist/esm/components/static-asset/models/base.model.d.ts +4 -4
  62. package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
  63. package/dist/esm/components/static-asset/services/commitment.service.d.ts +73 -0
  64. package/dist/esm/components/static-asset/services/commitment.service.js +141 -0
  65. package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -0
  66. package/dist/esm/components/static-asset/services/index.d.ts +3 -0
  67. package/dist/esm/components/static-asset/services/index.js +3 -0
  68. package/dist/esm/components/static-asset/services/index.js.map +1 -0
  69. package/dist/esm/components/static-asset/services/policy.service.d.ts +41 -0
  70. package/dist/esm/components/static-asset/services/policy.service.js +84 -0
  71. package/dist/esm/components/static-asset/services/policy.service.js.map +1 -0
  72. package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +26 -0
  73. package/dist/esm/components/static-asset/utilities/commit-token.utility.js +78 -0
  74. package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -0
  75. package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
  76. package/dist/esm/components/static-asset/utilities/entry.utility.js +153 -0
  77. package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
  78. package/dist/esm/components/static-asset/utilities/index.d.ts +5 -0
  79. package/dist/esm/components/static-asset/utilities/index.js +5 -0
  80. package/dist/esm/components/static-asset/utilities/index.js.map +1 -0
  81. package/dist/esm/components/static-asset/{ingest.d.ts → utilities/ingest.utility.d.ts} +5 -5
  82. package/dist/esm/components/static-asset/{ingest.js → utilities/ingest.utility.js} +12 -10
  83. package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -0
  84. package/dist/esm/components/static-asset/{controller/key-scope.d.ts → utilities/key-scope.utility.d.ts} +21 -2
  85. package/dist/esm/components/static-asset/utilities/key-scope.utility.js +74 -0
  86. package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -0
  87. package/dist/esm/components/static-asset/{controller/meta-link.d.ts → utilities/meta-link.utility.d.ts} +4 -4
  88. package/dist/esm/components/static-asset/{controller/meta-link.js → utilities/meta-link.utility.js} +10 -10
  89. package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -0
  90. package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +16 -0
  91. package/dist/esm/components/static-asset/utilities/object-link.utility.js +20 -0
  92. package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -0
  93. package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +44 -0
  94. package/dist/esm/components/static-asset/utilities/route-options.utility.js +85 -0
  95. package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -0
  96. package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +13 -0
  97. package/dist/esm/components/static-asset/utilities/toggle.utility.js +16 -0
  98. package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
  99. package/dist/presets/app/preset.json +4 -4
  100. package/dist/presets/lib/preset.json +3 -3
  101. package/dist/presets/shared/preset.json +1 -1
  102. package/package.json +6 -6
  103. package/dist/esm/components/static-asset/common/commit-token.d.ts +0 -28
  104. package/dist/esm/components/static-asset/common/commit-token.js +0 -48
  105. package/dist/esm/components/static-asset/common/commit-token.js.map +0 -1
  106. package/dist/esm/components/static-asset/controller/base.definition.d.ts +0 -30
  107. package/dist/esm/components/static-asset/controller/base.definition.js +0 -307
  108. package/dist/esm/components/static-asset/controller/base.definition.js.map +0 -1
  109. package/dist/esm/components/static-asset/controller/key-scope.js +0 -41
  110. package/dist/esm/components/static-asset/controller/key-scope.js.map +0 -1
  111. package/dist/esm/components/static-asset/controller/meta-link.js.map +0 -1
  112. package/dist/esm/components/static-asset/controller/route-options.d.ts +0 -29
  113. package/dist/esm/components/static-asset/controller/route-options.js +0 -47
  114. package/dist/esm/components/static-asset/controller/route-options.js.map +0 -1
  115. package/dist/esm/components/static-asset/ingest.js.map +0 -1
@@ -1,107 +1,127 @@
1
- import type { BaseRestController, IAuthRouteConfig, TRouteContext } from '../../../base/index.js';
1
+ import type { BaseRestController, IAuthRouteConfig, TRouteAuthConfig, TRouteContext } from '../../../base/index.js';
2
+ import type { z } from '@hono/zod-openapi';
2
3
  import type { IDuration } from '@venizia/ignis-helpers/common';
3
- import type { BaseRelationalEntity, DefaultCRUDRepository, TTableObject } from '@venizia/ignis-connectors/postgres';
4
- import type { DiskHelper, IBucketRef, IFileStat, IObjectLocation, IObjectRef, IStorageHelper, IUploadResult, TUploadNaming } from '@venizia/ignis-helpers';
4
+ import type { DefaultCRUDRepository, TTableObject } from '@venizia/ignis-connectors/postgres';
5
+ import type { DiskHelper, IBucketRef, IFileStat, IObjectLocation, IObjectRef, IStorageHelper, IUploadResult, StorageTypes, TUploadNaming } from '@venizia/ignis-helpers';
5
6
  import type { BunS3Helper } from '@venizia/ignis-helpers/bun-s3';
6
- import type { AnyType, TValueOrAsyncResolver, ValueOrPromise } from '@venizia/ignis-helpers/common';
7
- import type { TMultipartStorage } from '@venizia/ignis-helpers';
7
+ import type { TConstValue, TValueOrAsyncResolver, ValueOrPromise } from '@venizia/ignis-helpers/common';
8
8
  import type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models/index.js';
9
- import type { StaticAssetStorageTypes } from './constants.js';
10
- /** Per-controller upload tuning: multipart parsing, name and link normalization, folder depth and size ceiling. */
11
- export type TStaticAssetExtraOptions = {
12
- parseMultipartBody?: {
13
- storage?: TMultipartStorage;
14
- uploadDir?: string;
15
- /**
16
- * The most file parts one upload request may carry; more is refused with 413 before anything is written. The upload-policy request is bounded by the same number (more is a 422).
17
- *
18
- * @default DEFAULT_MAX_UPLOAD_FILES (20)
19
- */
20
- maxFiles?: number;
21
- };
22
- /** `folderPath` carries the upload query's target folder - dropping it flattens nested uploads. */
23
- normalizeNameFn?: (opts: {
24
- file: TUploadNaming;
25
- }) => string;
26
- normalizeLinkFn?: (opts: IObjectLocation) => string;
27
- /**
28
- * Maximum folder nesting depth allowed in object paths.
29
- *
30
- * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH
31
- */
32
- maxFolderDepth?: number;
33
- /** Largest file the UPLOAD route accepts. Absent means no ceiling. Checked against `content-length` before spooling, then per file after parsing. */
34
- maxBytes?: number;
35
- [key: string]: AnyType;
36
- };
37
- /** Decides the key one uploaded file is stored under. `defaultKey` is what IGNIS would have written. */
38
- export type TObjectNameResolver = (opts: {
9
+ import type { StaticAssetRouteKeys } from './constants.js';
10
+ /**
11
+ * A feature that is on or off. `{ use: false }` is the whole off state; `{ use: true, ... }` carries
12
+ * the options. One shape for every switch, so an option is never read from a feature that is off.
13
+ */
14
+ export type TToggle<Options extends object = Record<never, never>> = {
15
+ use: false;
16
+ } | ({
17
+ use: true;
18
+ } & Options);
19
+ /** The storage backends a static asset entry can serve from: the helpers that declare one. */
20
+ export type TStaticAssetStorageType = typeof StorageTypes.DISK | typeof StorageTypes.BUN_S3;
21
+ /** 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. */
22
+ export type TStaticAssetObjectKeyResolver = (opts: {
39
23
  bucket: IBucketRef;
40
24
  file: TUploadNaming;
41
25
  defaultKey: string;
42
26
  }) => string;
43
- /** Adds routes of the application's own to a generated asset controller. Runs after every built-in route, so a built-in route always wins a path collision. `basePath` is the mount path with exactly one leading slash. */
44
27
  /** 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. */
45
- export type TDefineExtraRoutes = (opts: {
28
+ export type TStaticAssetDefineExtraRoutes = (opts: {
46
29
  controller: BaseRestController;
47
30
  helper: IStorageHelper;
48
31
  basePath: string;
49
32
  }) => void;
50
- /** Path parameters of the bucket routes. */
51
- export type TBucketParams = {
52
- bucketName: string;
53
- };
54
33
  /** Path parameters of the object routes. */
55
- export type TObjectParams = {
56
- bucketName: string;
34
+ export type TStaticAssetObjectParams = {
57
35
  objectName: string;
58
36
  };
59
37
  /** Labels recorded on the MetaLink row of an uploaded object. */
60
- export type TUploadQuery = {
38
+ export type TStaticAssetUploadLabels = {
61
39
  principalType?: string;
62
40
  principalId?: string;
63
41
  variant?: string;
64
42
  /** Display order within the principal. Caller-supplied: deriving it would be a non-atomic read of `max(sequence)` then a write of `max + 1`. */
65
43
  sequence?: number;
66
- folderPath?: string;
67
- };
68
- /** Query of the list objects route. Every value arrives as a string. */
69
- export type TListQuery = {
70
- prefix?: string;
71
- recursive?: string;
72
- maxKeys?: string;
73
44
  };
74
45
  /** 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. */
75
- export type TDirectUploadOptions = {
76
- /** Who may ask for a policy. REQUIRED, not defaulted: this route hands out a write credential, and there is no safe default for that. */
77
- authorize: (opts: {
46
+ export type TStaticAssetDirectUploadOptions = {
47
+ /**
48
+ * Who may use direct upload. Guards every direct-upload route. There is no safe default for a
49
+ * route that hands out a write credential, so leaving it out is allowed only when the entry's
50
+ * `auth` already authenticates or authorizes: then `auth` is the gate. With neither, the
51
+ * component refuses to start.
52
+ */
53
+ authorize?: (opts: {
78
54
  context: TRouteContext;
79
55
  }) => ValueOrPromise<boolean>;
56
+ /**
57
+ * Who the upload belongs to. Called on every direct-upload route: the policy route signs the
58
+ * answer into the commit token, and the other routes refuse a token whose owner differs. Absent,
59
+ * a token commits for whoever holds it.
60
+ */
61
+ resolveOwner?: (opts: {
62
+ context: TRouteContext;
63
+ }) => ValueOrPromise<string>;
80
64
  /** Signs the commit token. Keep it out of the repository and out of the client. */
81
65
  secretKey: string;
82
66
  /** 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. */
83
67
  maxBytes: number;
84
68
  /**
85
- * Where a policy may write. The final key is NEVER in a policy, so content cannot be replaced after the commit.
69
+ * The most files one upload-policy request may name; more is a 422.
70
+ *
71
+ * @default StaticAssetDefaults.MAX_UPLOAD_FILES (20)
72
+ */
73
+ maxFiles?: number;
74
+ /**
75
+ * Where a policy may write: not empty, ends with `/`, made of valid key segments, and neither
76
+ * inside the entry's `keyPrefix` nor containing it - a pending object must never be readable
77
+ * through the entry's own routes. The final key is NEVER in a policy, so content cannot be
78
+ * replaced after the commit. The lifecycle rule that collects abandoned uploads targets this prefix.
86
79
  *
87
80
  * @default 'pending/'
88
81
  */
89
82
  pendingPrefix?: string;
83
+ expires?: {
84
+ /**
85
+ * How long the browser may post the bytes: the POST policy's lifetime.
86
+ *
87
+ * @default StoragePresignDefaults.POST_EXPIRES_IN
88
+ */
89
+ upload?: IDuration;
90
+ /**
91
+ * How long the commit token stays good, for validating and committing after the upload. The
92
+ * pending object must outlive it, so the lifecycle rule on `pendingPrefix` has to be longer still.
93
+ *
94
+ * @default `upload`
95
+ */
96
+ commit?: IDuration;
97
+ };
90
98
  /**
91
- * How long a policy and its commit token stay good.
92
- *
93
- * @default StoragePresignDefaults.POST_EXPIRES_IN
99
+ * Checks the pending file. On, the component registers `POST {base}/upload-validate`, and
100
+ * `commit` runs the same check first and refuses an invalid file with `UPLOAD_INVALID`.
101
+ * Build it with `StaticAssetValidation.define`.
94
102
  */
95
- expiresIn?: IDuration;
96
- /** Runs BEFORE the copy to the final key, so a hook that throws leaves the object under the pending prefix for a lifecycle rule to collect, rather than stranding it at the final key. */
97
- onCommit?: (opts: {
98
- bucket: IBucketRef;
99
- pendingObject: IObjectRef;
100
- object: IObjectRef;
101
- }) => ValueOrPromise<void>;
103
+ validation: TToggle<IStaticAssetValidation<z.ZodType>>;
102
104
  };
105
+ /** What a validation answers: whether the file may be committed, and the problems the user should see. */
106
+ export interface IStaticAssetValidationResult<Issue> {
107
+ isValid: boolean;
108
+ issues: Issue[];
109
+ }
110
+ /**
111
+ * The application's own check of an uploaded file, run on the PENDING object before anything is
112
+ * committed. The component owns the route and the refusal; the application owns only this logic.
113
+ * Build it with `StaticAssetValidation.define` so the handler is typed by `issueSchema`.
114
+ */
115
+ export interface IStaticAssetValidation<IssueSchema extends z.ZodType> {
116
+ /** The shape of ONE issue. It types the handler's answer and documents the route's response. */
117
+ issueSchema: IssueSchema;
118
+ handler: (opts: IObjectLocation & {
119
+ owner?: string;
120
+ helper: IStorageHelper;
121
+ }) => ValueOrPromise<IStaticAssetValidationResult<z.infer<IssueSchema>>>;
122
+ }
103
123
  /** Body of the upload policy route: the files the client intends to upload. */
104
- export type TUploadPolicyRequest = {
124
+ export type TStaticAssetUploadPolicyRequest = {
105
125
  files: Array<{
106
126
  fileName: string;
107
127
  contentType?: string;
@@ -110,94 +130,129 @@ export type TUploadPolicyRequest = {
110
130
  };
111
131
  /** 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. */
112
132
  export type TMetaLinkConfig<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {
113
- model: TValueOrAsyncResolver<typeof BaseRelationalEntity<Schema>>;
114
133
  repository: TValueOrAsyncResolver<DefaultCRUDRepository<Schema>>;
115
134
  createMetaLink?: (opts: {
116
135
  uploadResult: IUploadResult;
117
136
  fileStat: IFileStat;
118
- /** The caller's labels. Named for where they used to travel - they arrive in the request BODY now, as form fields on an upload and beside the commit token on a direct one. */
119
- query: TUploadQuery;
137
+ /** The caller's labels: form fields on an upload, beside the commit token on a direct one. */
138
+ labels: TStaticAssetUploadLabels;
120
139
  }) => ValueOrPromise<{
121
140
  count: number;
122
141
  data: TTableObject<Schema>;
123
142
  }>;
124
143
  };
125
- /** The part of a built-in route an application may change. */
126
- export type TStaticAssetRouteConfig = Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>> & {
144
+ /** 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. */
145
+ export type TStaticAssetRouteConfig = Partial<Omit<IAuthRouteConfig, 'method' | 'request' | 'responses' | 'authenticate' | 'authorize'>> & TRouteAuthConfig;
146
+ /** Authentication and authorization for every built-in route of an entry; a route's own `authenticate`/`authorize` replaces it for that route. */
147
+ export type TStaticAssetAuth = TRouteAuthConfig & {
127
148
  /**
128
- * Whether this route is registered.
149
+ * `{ use: true }` leaves `getObjectByName` and `downloadObjectByName` unauthenticated, so a
150
+ * browser can show an image without a token. `listObjects` is NOT public: listing a bucket is not
151
+ * reading an object.
129
152
  *
130
- * @default true
153
+ * @default { use: false }
131
154
  */
132
- enabled?: boolean;
155
+ publicRead?: TToggle;
133
156
  };
134
- /** Per-route overrides for the built-in routes of a generated asset controller. A key left out keeps that route as built. */
135
- export type TStaticAssetRoutes = {
136
- getBuckets?: TStaticAssetRouteConfig;
137
- getBucketByName?: TStaticAssetRouteConfig;
138
- createBucket?: TStaticAssetRouteConfig;
139
- deleteBucket?: TStaticAssetRouteConfig;
140
- upload?: TStaticAssetRouteConfig;
141
- listObjects?: TStaticAssetRouteConfig;
142
- deleteObject?: TStaticAssetRouteConfig;
143
- getObjectByName?: TStaticAssetRouteConfig;
144
- downloadObjectByName?: TStaticAssetRouteConfig;
145
- uploadPolicy?: TStaticAssetRouteConfig;
146
- uploadCommit?: TStaticAssetRouteConfig;
147
- recreateMetaLink?: TStaticAssetRouteConfig;
157
+ /** The name of a built-in route, the key of `routes`. */
158
+ export type TStaticAssetRouteKey = TConstValue<typeof StaticAssetRouteKeys>;
159
+ /**
160
+ * What each built-in route does: `{ use: false }` turns it off, `{ use: true, ... }` turns it on
161
+ * with those overrides. A route left out is on as built.
162
+ */
163
+ export type TStaticAssetRoutes = Partial<Record<TStaticAssetRouteKey, TToggle<TStaticAssetRouteConfig>>>;
164
+ /** Uploading through the application: the browser sends the bytes to `POST /objects` and the application writes them to the storage. */
165
+ export type TStaticAssetServerUploadOptions = {
166
+ /** Largest file the route accepts. Absent means no ceiling. Checked against `content-length` before the body is read, then per file after parsing. */
167
+ maxBytes?: number;
168
+ /**
169
+ * The most file parts one request may carry; more is refused with 413 before anything is written.
170
+ *
171
+ * @default StaticAssetDefaults.MAX_UPLOAD_FILES (20)
172
+ */
173
+ maxFiles?: number;
174
+ /** 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. */
175
+ objectKey?: TStaticAssetObjectKeyResolver;
176
+ };
177
+ /** 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`. */
178
+ type TStaticAssetDirectUploadScope = {
179
+ keyPrefix?: string;
180
+ directUpload: {
181
+ use: false;
182
+ };
183
+ } | {
184
+ keyPrefix: string;
185
+ directUpload: {
186
+ use: true;
187
+ } & TStaticAssetDirectUploadOptions;
148
188
  };
149
- /** Static asset controllers keyed by an application-chosen name. Each entry pairs a storage type with its matching helper, and `useMetaLink: true` requires a `metaLink` config. */
150
- export type TStaticAssetsComponentOptions<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {
151
- [key: string]: {
152
- controller: {
153
- name: string;
154
- basePath: string;
155
- /**
156
- * Whether `/path` and `/path/` are different routes on this controller.
157
- *
158
- * @default true
159
- */
160
- isStrict?: boolean;
161
- /**
162
- * `true` serves a raw nested object path (`/objects/photos/2024/f.jpg`) - a URL shape change; a percent-encoded path keeps working either way.
163
- *
164
- * @default false
165
- */
166
- rawObjectPath?: boolean;
167
- /** The single bucket every object route uses. It leaves the URL (`/objects/{objectName}`) and the four bucket-management routes are not registered. The function form is read per request, so an environment variable can be read lazily. */
168
- bucket?: TValueOrAsyncResolver<string>;
169
- /**
170
- * The key scope this controller owns, e.g. `inventory/`. Every route refuses a key outside it
171
- * as a 404 without calling the storage, `listObjects` lists only inside it, and an upload key
172
- * must land inside it: the default name is placed there, a `resolveObjectName` or
173
- * `extra.normalizeNameFn` key outside it is refused. `maxFolderDepth` counts the folders below
174
- * it.
175
- *
176
- * @default every key in the bucket
177
- */
178
- keyPrefix?: string;
179
- routes?: TStaticAssetRoutes;
180
- /** Direct upload: the browser posts the bytes to the storage and IGNIS only signs the permission. Absent leaves both routes unregistered. Requires `bucket` - a policy names one bucket, and a bucket in the URL is a bucket the caller chooses. */
181
- directUpload?: TDirectUploadOptions;
182
- };
183
- extra?: TStaticAssetExtraOptions;
184
- /** Decides the stored object name of each uploaded file; absent keeps the storage helper's own naming. */
185
- resolveObjectName?: TObjectNameResolver;
186
- /** Registers the application's own routes BEFORE every built-in one, so a literal path wins over the catch-all `rawObjectPath` produces. Hono matches in registration order. */
187
- defineRoutesBefore?: TDefineExtraRoutes;
188
- /** Registers the application's own routes on the generated controller, after every built-in one. */
189
- defineExtraRoutes?: TDefineExtraRoutes;
190
- } & ({
191
- storage: typeof StaticAssetStorageTypes.BUN_S3;
192
- helper: BunS3Helper;
193
- } | {
194
- storage: typeof StaticAssetStorageTypes.DISK;
195
- helper: DiskHelper;
196
- }) & ({
197
- useMetaLink?: false | undefined;
198
- } | {
199
- useMetaLink: true;
200
- metaLink: TMetaLinkConfig<Schema>;
201
- });
189
+ /** The storage helper decides which direct upload shapes are possible. */
190
+ type TStaticAssetStorage = ({
191
+ helper: BunS3Helper;
192
+ } & TStaticAssetDirectUploadScope) | {
193
+ helper: DiskHelper;
194
+ keyPrefix?: string;
195
+ directUpload: {
196
+ use: false;
197
+ };
202
198
  };
199
+ /** 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. */
200
+ export type TStaticAssetEntry<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = {
201
+ basePath: string;
202
+ /** The controller's name. Absent, it is derived from the entry's key. */
203
+ name?: string;
204
+ /** The single bucket every route uses. The function form is read per request, so an environment variable can be read lazily. */
205
+ bucket: TValueOrAsyncResolver<string>;
206
+ /**
207
+ * The key scope this entry owns, e.g. `inventory/`. Every route refuses a key outside it as a
208
+ * 404 without calling the storage, `listObjects` lists only inside it, and an upload key must
209
+ * land inside it. `maxFolderDepth` counts the folders below it. Required with
210
+ * `directUpload`: it keeps the pending prefix outside everything the routes serve.
211
+ *
212
+ * @default every key in the bucket
213
+ */
214
+ keyPrefix?: string;
215
+ /**
216
+ * Folders a key may nest below the `keyPrefix`, for every route of the entry: reads and deletes
217
+ * too, so it holds for keys that arrive by direct upload or ingest.
218
+ *
219
+ * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH
220
+ */
221
+ maxFolderDepth?: number;
222
+ /**
223
+ * `true` serves a raw nested object path (`/objects/photos/2024/f.jpg`) - a URL shape change; a percent-encoded path keeps working either way.
224
+ *
225
+ * @default false
226
+ */
227
+ rawObjectPath?: boolean;
228
+ /** The link stored and returned for an object. Absent builds the URL of this controller's own object route. */
229
+ link?: (opts: IObjectLocation) => string;
230
+ /** 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. */
231
+ auth?: TStaticAssetAuth;
232
+ serverUpload: TToggle<TStaticAssetServerUploadOptions>;
233
+ /** Every upload also writes a MetaLink row, and the object's deletion removes it. */
234
+ metaLink: TToggle<TMetaLinkConfig<Schema>>;
235
+ routes?: TStaticAssetRoutes;
236
+ extend?: {
237
+ /** Registered BEFORE every built-in route, so a literal path wins over the catch-all `rawObjectPath` produces. Hono matches in registration order. */
238
+ before?: TStaticAssetDefineExtraRoutes;
239
+ /** Registered after every built-in route. */
240
+ after?: TStaticAssetDefineExtraRoutes;
241
+ };
242
+ } & TStaticAssetStorage;
243
+ /** Static asset entries keyed by an application-chosen name; each key becomes one controller. */
244
+ export type TStaticAssetComponentOptions<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> = Record<string, TStaticAssetEntry<Schema>>;
245
+ /**
246
+ * What a commit token binds: the pending object a policy was issued for, when the grant dies and,
247
+ * when the application supplies one, who it was issued to. Other business fields are deliberately
248
+ * absent - which order or tenant an upload belongs to is the application's.
249
+ */
250
+ export interface IStaticAssetCommitTokenPayload {
251
+ bucket: IBucketRef;
252
+ object: IObjectRef;
253
+ expiresAt: number;
254
+ /** Absent when `directUpload.resolveOwner` is not set; present, the token commits only for that owner. */
255
+ owner?: string;
256
+ }
257
+ export {};
203
258
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { BaseRestController, IAuthRouteConfig, TRouteContext } from '@/base';\nimport type { IDuration } from '@venizia/ignis-helpers/common';\nimport type {\n BaseRelationalEntity,\n DefaultCRUDRepository,\n TTableObject,\n} from '@venizia/ignis-connectors/postgres';\nimport type {\n DiskHelper,\n IBucketRef,\n IFileStat,\n IObjectLocation,\n IObjectRef,\n IStorageHelper,\n IUploadResult,\n TUploadNaming,\n} from '@venizia/ignis-helpers';\nimport type { BunS3Helper } from '@venizia/ignis-helpers/bun-s3';\nimport type { AnyType, TValueOrAsyncResolver, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport type { TMultipartStorage } from '@venizia/ignis-helpers';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models';\nimport type { StaticAssetStorageTypes } from './constants';\n\n/** Per-controller upload tuning: multipart parsing, name and link normalization, folder depth and size ceiling. */\nexport type TStaticAssetExtraOptions = {\n parseMultipartBody?: {\n storage?: TMultipartStorage;\n uploadDir?: string;\n /**\n * The most file parts one upload request may carry; more is refused with 413 before anything is written. The upload-policy request is bounded by the same number (more is a 422).\n *\n * @default DEFAULT_MAX_UPLOAD_FILES (20)\n */\n maxFiles?: number;\n };\n\n /** `folderPath` carries the upload query's target folder - dropping it flattens nested uploads. */\n normalizeNameFn?: (opts: { file: TUploadNaming }) => string;\n normalizeLinkFn?: (opts: IObjectLocation) => string;\n\n /**\n * Maximum folder nesting depth allowed in object paths.\n *\n * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH\n */\n maxFolderDepth?: number;\n\n /** Largest file the UPLOAD route accepts. Absent means no ceiling. Checked against `content-length` before spooling, then per file after parsing. */\n maxBytes?: number;\n [key: string]: AnyType;\n};\n\n/** Decides the key one uploaded file is stored under. `defaultKey` is what IGNIS would have written. */\nexport type TObjectNameResolver = (opts: {\n bucket: IBucketRef;\n file: TUploadNaming;\n defaultKey: string;\n}) => string;\n\n/** Adds routes of the application's own to a generated asset controller. Runs after every built-in route, so a built-in route always wins a path collision. `basePath` is the mount path with exactly one leading slash. */\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 TDefineExtraRoutes = (opts: {\n controller: BaseRestController;\n helper: IStorageHelper;\n basePath: string;\n}) => void;\n\n// Declared by hand rather than inferred: RouteHandler inference here is heavy.\n/** Path parameters of the bucket routes. */\nexport type TBucketParams = { bucketName: string };\n/** Path parameters of the object routes. */\nexport type TObjectParams = { bucketName: string; objectName: string };\n/** Labels recorded on the MetaLink row of an uploaded object. */\nexport type TUploadQuery = {\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 folderPath?: string;\n};\n/** Query of the list objects route. Every value arrives as a string. */\nexport type TListQuery = { prefix?: string; recursive?: string; maxKeys?: string };\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 TDirectUploadOptions = {\n /** Who may ask for a policy. REQUIRED, not defaulted: this route hands out a write credential, and there is no safe default for that. */\n authorize: (opts: { context: TRouteContext }) => ValueOrPromise<boolean>;\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 * Where a policy may write. The final key is NEVER in a policy, so content cannot be replaced after the commit.\n *\n * @default 'pending/'\n */\n pendingPrefix?: string;\n\n /**\n * How long a policy and its commit token stay good.\n *\n * @default StoragePresignDefaults.POST_EXPIRES_IN\n */\n expiresIn?: IDuration;\n\n /** Runs BEFORE the copy to the final key, so a hook that throws leaves the object under the pending prefix for a lifecycle rule to collect, rather than stranding it at the final key. */\n onCommit?: (opts: {\n bucket: IBucketRef;\n pendingObject: IObjectRef;\n object: IObjectRef;\n }) => ValueOrPromise<void>;\n};\n\n/** Body of the upload policy route: the files the client intends to upload. */\nexport type TUploadPolicyRequest = {\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 model: TValueOrAsyncResolver<typeof BaseRelationalEntity<Schema>>;\n repository: TValueOrAsyncResolver<DefaultCRUDRepository<Schema>>;\n createMetaLink?: (opts: {\n uploadResult: IUploadResult;\n fileStat: IFileStat;\n /** The caller's labels. Named for where they used to travel - they arrive in the request BODY now, as form fields on an upload and beside the commit token on a direct one. */\n query: TUploadQuery;\n }) => ValueOrPromise<{ count: number; data: TTableObject<Schema> }>;\n};\n\n/** The part of a built-in route an application may change. */\nexport type TStaticAssetRouteConfig = Partial<\n Omit<IAuthRouteConfig, 'method' | 'request' | 'responses'>\n> & {\n /**\n * Whether this route is registered.\n *\n * @default true\n */\n enabled?: boolean;\n};\n\n/** Per-route overrides for the built-in routes of a generated asset controller. A key left out keeps that route as built. */\nexport type TStaticAssetRoutes = {\n getBuckets?: TStaticAssetRouteConfig;\n getBucketByName?: TStaticAssetRouteConfig;\n createBucket?: TStaticAssetRouteConfig;\n deleteBucket?: TStaticAssetRouteConfig;\n\n upload?: TStaticAssetRouteConfig;\n listObjects?: TStaticAssetRouteConfig;\n deleteObject?: TStaticAssetRouteConfig;\n getObjectByName?: TStaticAssetRouteConfig;\n downloadObjectByName?: TStaticAssetRouteConfig;\n\n uploadPolicy?: TStaticAssetRouteConfig;\n uploadCommit?: TStaticAssetRouteConfig;\n\n recreateMetaLink?: TStaticAssetRouteConfig;\n};\n\n/** Static asset controllers keyed by an application-chosen name. Each entry pairs a storage type with its matching helper, and `useMetaLink: true` requires a `metaLink` config. */\nexport type TStaticAssetsComponentOptions<\n Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema,\n> = {\n [key: string]: {\n controller: {\n name: string;\n basePath: string;\n\n /**\n * Whether `/path` and `/path/` are different routes on this controller.\n *\n * @default true\n */\n isStrict?: boolean;\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 single bucket every object route uses. It leaves the URL (`/objects/{objectName}`) and the four bucket-management routes are not registered. 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 controller owns, e.g. `inventory/`. Every route refuses a key outside it\n * as a 404 without calling the storage, `listObjects` lists only inside it, and an upload key\n * must land inside it: the default name is placed there, a `resolveObjectName` or\n * `extra.normalizeNameFn` key outside it is refused. `maxFolderDepth` counts the folders below\n * it.\n *\n * @default every key in the bucket\n */\n keyPrefix?: string;\n\n routes?: TStaticAssetRoutes;\n\n /** Direct upload: the browser posts the bytes to the storage and IGNIS only signs the permission. Absent leaves both routes unregistered. Requires `bucket` - a policy names one bucket, and a bucket in the URL is a bucket the caller chooses. */\n directUpload?: TDirectUploadOptions;\n };\n extra?: TStaticAssetExtraOptions;\n\n /** Decides the stored object name of each uploaded file; absent keeps the storage helper's own naming. */\n resolveObjectName?: TObjectNameResolver;\n\n /** Registers the application's own routes BEFORE every built-in one, so a literal path wins over the catch-all `rawObjectPath` produces. Hono matches in registration order. */\n defineRoutesBefore?: TDefineExtraRoutes;\n\n /** Registers the application's own routes on the generated controller, after every built-in one. */\n defineExtraRoutes?: TDefineExtraRoutes;\n } & (\n | { storage: typeof StaticAssetStorageTypes.BUN_S3; helper: BunS3Helper }\n | { storage: typeof StaticAssetStorageTypes.DISK; helper: DiskHelper }\n ) &\n (\n | { useMetaLink?: false | undefined }\n | { useMetaLink: true; metaLink: TMetaLinkConfig<Schema> }\n );\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 } from './constants';\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`, and\n * `commit` runs the same check first and refuses an invalid file with `UPLOAD_INVALID`.\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 handler: (\n opts: IObjectLocation & { owner?: string; helper: IStorageHelper },\n ) => ValueOrPromise<IStaticAssetValidationResult<z.infer<IssueSchema>>>;\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/**\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}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { z } from '@hono/zod-openapi';
2
+ import type { IStaticAssetValidation } from './types.js';
3
+ /** Defines the application's check of an uploaded file; see `directUpload.validation`. */
4
+ export declare class StaticAssetValidation {
5
+ /** Returns `opts` switched on. It exists to infer `IssueSchema`, so a handler that answers another shape of issue fails type-checking. */
6
+ static define<IssueSchema extends z.ZodType>(opts: IStaticAssetValidation<IssueSchema>): IStaticAssetValidation<IssueSchema> & {
7
+ use: true;
8
+ };
9
+ }
10
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1,8 @@
1
+ /** Defines the application's check of an uploaded file; see `directUpload.validation`. */
2
+ export class StaticAssetValidation {
3
+ /** Returns `opts` switched on. It exists to infer `IssueSchema`, so a handler that answers another shape of issue fails type-checking. */
4
+ static define(opts) {
5
+ return { use: true, ...opts };
6
+ }
7
+ }
8
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/common/validation.ts"],"names":[],"mappings":"AAGA,0FAA0F;AAC1F,MAAM,OAAO,qBAAqB;IAChC,0IAA0I;IAC1I,MAAM,CAAC,MAAM,CACX,IAAyC;QAEzC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type { z } from '@hono/zod-openapi';\nimport type { IStaticAssetValidation } from './types';\n\n/** Defines the application's check of an uploaded file; see `directUpload.validation`. */\nexport class StaticAssetValidation {\n /** Returns `opts` switched on. It exists to infer `IssueSchema`, so a handler that answers another shape of issue fails type-checking. */\n static define<IssueSchema extends z.ZodType>(\n opts: IStaticAssetValidation<IssueSchema>,\n ): IStaticAssetValidation<IssueSchema> & { use: true } {\n return { use: true, ...opts };\n }\n}\n"]}
@@ -1,12 +1,14 @@
1
1
  import { type BaseApplication } from '../../base/applications/index.js';
2
2
  import { BaseComponent } from '@venizia/ignis-kernel';
3
3
  import { type ValueOrPromise } from '@venizia/ignis-helpers/common';
4
- import { type TStaticAssetsComponentOptions } from './common/index.js';
4
+ import { type TStaticAssetComponentOptions } from './common/index.js';
5
5
  import type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from './models/index.js';
6
6
  /** `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. */
7
- export declare class StaticAssetComponent<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> extends BaseComponent<TStaticAssetsComponentOptions<Schema>> {
7
+ export declare class StaticAssetComponent<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> extends BaseComponent<TStaticAssetComponentOptions<Schema>> {
8
8
  private application;
9
9
  constructor(application: BaseApplication);
10
10
  binding(): ValueOrPromise<void>;
11
+ /** 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. */
12
+ private bindDirectUploadServices;
11
13
  }
12
14
  //# sourceMappingURL=component.d.ts.map
@@ -15,8 +15,9 @@ import { BaseComponent } from '@venizia/ignis-kernel';
15
15
  import { inject } from '../../base/metadata/index.js';
16
16
  import { CoreBindings } from '@venizia/ignis-kernel';
17
17
  import { Binding } from '@venizia/ignis-kernel';
18
- import { StaticAssetComponentBindingKeys } from './common/index.js';
19
- import { AssetControllerFactory } from './controller/index.js';
18
+ import { StaticAssetBindingKeys } from './common/index.js';
19
+ import { StaticAssetControllerFactory } from './controller/index.js';
20
+ import { StaticAssetEntryUtility } from './utilities/entry.utility.js';
20
21
  /** `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. */
21
22
  let StaticAssetComponent = StaticAssetComponent_1 = class StaticAssetComponent extends BaseComponent {
22
23
  constructor(application) {
@@ -24,8 +25,8 @@ let StaticAssetComponent = StaticAssetComponent_1 = class StaticAssetComponent e
24
25
  scope: StaticAssetComponent_1.name,
25
26
  initDefault: { enable: true, container: application },
26
27
  bindings: {
27
- [StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS]: Binding.bind({
28
- key: StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS,
28
+ [StaticAssetBindingKeys.STATIC_ASSET_OPTIONS]: Binding.bind({
29
+ key: StaticAssetBindingKeys.STATIC_ASSET_OPTIONS,
29
30
  }).toValue({}),
30
31
  },
31
32
  });
@@ -36,36 +37,30 @@ let StaticAssetComponent = StaticAssetComponent_1 = class StaticAssetComponent e
36
37
  // through `configs.artifacts`, where an index carries classes and no options.
37
38
  const componentOptions = this.options ??
38
39
  this.application.get({
39
- key: StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS,
40
+ key: StaticAssetBindingKeys.STATIC_ASSET_OPTIONS,
40
41
  });
41
- const componentOptionsEntries = Object.entries(componentOptions);
42
- for (const [key, opt] of componentOptionsEntries) {
43
- const { storage, controller, helper, extra, resolveObjectName, defineRoutesBefore, defineExtraRoutes, } = opt;
44
- this.application.controller(AssetControllerFactory.defineAssetController({
45
- controller,
46
- storage,
47
- helper,
48
- useMetaLink: opt.useMetaLink,
49
- metaLink: opt.useMetaLink ? opt.metaLink : undefined,
50
- resolveObjectName,
51
- defineRoutesBefore,
52
- defineExtraRoutes,
53
- options: {
54
- ...extra,
55
- normalizeLinkFn: extra?.normalizeLinkFn ??
56
- // The link follows the URL shape the controller serves: `{objectName}` is one Hono path segment unless `rawObjectPath` widens it, and a configured bucket leaves the path.
57
- ((linkOptions) => AssetControllerFactory.buildObjectLink({
58
- basePath: controller.basePath,
59
- bucket: linkOptions.bucket,
60
- object: linkOptions.object,
61
- hasConfiguredBucket: controller.bucket !== undefined,
62
- rawObjectPath: controller.rawObjectPath,
63
- })),
64
- },
65
- }));
66
- this.application.logger.info(`[binding] Asset storage is bound | Key: %s | Storage type: %s | UseMetaLink: %s`, key, storage, Boolean(opt.useMetaLink));
42
+ for (const [key, entry] of Object.entries(componentOptions)) {
43
+ const resolved = StaticAssetEntryUtility.resolve({ key, entry });
44
+ const services = this.bindDirectUploadServices({ key, resolved });
45
+ this.application.controller(StaticAssetControllerFactory.buildResolved({ resolved, ...services }));
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);
67
47
  }
68
48
  }
49
+ /** 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. */
50
+ bindDirectUploadServices(opts) {
51
+ const { key, resolved } = opts;
52
+ const services = StaticAssetEntryUtility.buildDirectUploadServices({ resolved });
53
+ if (!services) {
54
+ return undefined;
55
+ }
56
+ this.application
57
+ .bind({ key: StaticAssetBindingKeys.policyService({ name: key }) })
58
+ .toValue(services.policyService);
59
+ this.application
60
+ .bind({ key: StaticAssetBindingKeys.commitService({ name: key }) })
61
+ .toValue(services.commitService);
62
+ return services;
63
+ }
69
64
  };
70
65
  StaticAssetComponent = StaticAssetComponent_1 = __decorate([
71
66
  __param(0, inject({ key: CoreBindings.APPLICATION_INSTANCE })),
@@ -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,OAAO,EAAE,+BAA+B,EAAsC,MAAM,UAAU,CAAC;AAE/F,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,kQAAkQ;AAClQ,IAAa,oBAAoB,4BAAjC,MAAa,oBAEX,SAAQ,aAAoD;IAC5D,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,+BAA+B,CAAC,8BAA8B,CAAC,EAC9D,OAAO,CAAC,IAAI,CAAgC;oBAC1C,GAAG,EAAE,+BAA+B,CAAC,8BAA8B;iBACpE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;aACjB;SACF,CAAC,CAAC;QAXyD,gBAAW,GAAX,WAAW,CAAiB;IAY1F,CAAC;IAEQ,OAAO;QACd,2FAA2F;QAC3F,8EAA8E;QAC9E,MAAM,gBAAgB,GACpB,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,WAAW,CAAC,GAAG,CAAwC;gBAC1D,GAAG,EAAE,+BAA+B,CAAC,8BAA8B;aACpE,CAAC,CAAC;QAEL,MAAM,uBAAuB,GAAG,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAEjE,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,uBAAuB,EAAE,CAAC;YACjD,MAAM,EACJ,OAAO,EACP,UAAU,EACV,MAAM,EACN,KAAK,EACL,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,GAClB,GAAG,GAAG,CAAC;YAER,IAAI,CAAC,WAAW,CAAC,UAAU,CACzB,sBAAsB,CAAC,qBAAqB,CAAC;gBAC3C,UAAU;gBACV,OAAO;gBACP,MAAM;gBACN,WAAW,EAAE,GAAG,CAAC,WAAW;gBAC5B,QAAQ,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;gBACpD,iBAAiB;gBACjB,kBAAkB;gBAClB,iBAAiB;gBACjB,OAAO,EAAE;oBACP,GAAG,KAAK;oBACR,eAAe,EACb,KAAK,EAAE,eAAe;wBACtB,2KAA2K;wBAC3K,CAAC,CAAC,WAAW,EAAE,EAAE,CACf,sBAAsB,CAAC,eAAe,CAAC;4BACrC,QAAQ,EAAE,UAAU,CAAC,QAAQ;4BAC7B,MAAM,EAAE,WAAW,CAAC,MAAM;4BAC1B,MAAM,EAAE,WAAW,CAAC,MAAM;4BAC1B,mBAAmB,EAAE,UAAU,CAAC,MAAM,KAAK,SAAS;4BACpD,aAAa,EAAE,UAAU,CAAC,aAAa;yBACxC,CAAC,CAAC;iBACR;aACF,CAAC,CACH,CAAC;YAEF,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAC1B,iFAAiF,EACjF,GAAG,EACH,OAAO,EACP,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CACzB,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AA3EY,oBAAoB;IAI5B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAJ1C,oBAAoB,CA2EhC","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 { StaticAssetComponentBindingKeys, type TStaticAssetsComponentOptions } from './common';\nimport type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from './models';\nimport { AssetControllerFactory } from './controller';\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<TStaticAssetsComponentOptions<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 [StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS]:\n Binding.bind<TStaticAssetsComponentOptions>({\n key: StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_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<TStaticAssetsComponentOptions<Schema>>({\n key: StaticAssetComponentBindingKeys.STATIC_ASSET_COMPONENT_OPTIONS,\n });\n\n const componentOptionsEntries = Object.entries(componentOptions);\n\n for (const [key, opt] of componentOptionsEntries) {\n const {\n storage,\n controller,\n helper,\n extra,\n resolveObjectName,\n defineRoutesBefore,\n defineExtraRoutes,\n } = opt;\n\n this.application.controller(\n AssetControllerFactory.defineAssetController({\n controller,\n storage,\n helper,\n useMetaLink: opt.useMetaLink,\n metaLink: opt.useMetaLink ? opt.metaLink : undefined,\n resolveObjectName,\n defineRoutesBefore,\n defineExtraRoutes,\n options: {\n ...extra,\n normalizeLinkFn:\n extra?.normalizeLinkFn ??\n // The link follows the URL shape the controller serves: `{objectName}` is one Hono path segment unless `rawObjectPath` widens it, and a configured bucket leaves the path.\n ((linkOptions) =>\n AssetControllerFactory.buildObjectLink({\n basePath: controller.basePath,\n bucket: linkOptions.bucket,\n object: linkOptions.object,\n hasConfiguredBucket: controller.bucket !== undefined,\n rawObjectPath: controller.rawObjectPath,\n })),\n },\n }),\n );\n\n this.application.logger.info(\n `[binding] Asset storage is bound | Key: %s | Storage type: %s | UseMetaLink: %s`,\n key,\n storage,\n Boolean(opt.useMetaLink),\n );\n }\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,OAAO;YACZ,IAAI,CAAC,WAAW,CAAC,GAAG,CAAuC;gBACzD,GAAG,EAAE,sBAAsB,CAAC,oBAAoB;aACjD,CAAC,CAAC;QAEL,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC5D,MAAM,QAAQ,GAAG,uBAAuB,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;YACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,wBAAwB,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;YAElE,IAAI,CAAC,WAAW,CAAC,UAAU,CACzB,4BAA4B,CAAC,aAAa,CAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAAC,CAC9E,CAAC;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"]}