@venizia/ignis 0.4.8-11 → 0.4.8-13

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 (96) hide show
  1. package/dist/esm/components/mail/common/types/queue.d.ts +8 -4
  2. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  3. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +1 -1
  4. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +2 -16
  5. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  6. package/dist/esm/components/static-asset/common/constants.d.ts +25 -11
  7. package/dist/esm/components/static-asset/common/constants.js +40 -20
  8. package/dist/esm/components/static-asset/common/constants.js.map +1 -1
  9. package/dist/esm/components/static-asset/common/errors.d.ts +16 -39
  10. package/dist/esm/components/static-asset/common/errors.js +16 -36
  11. package/dist/esm/components/static-asset/common/errors.js.map +1 -1
  12. package/dist/esm/components/static-asset/common/index.d.ts +1 -0
  13. package/dist/esm/components/static-asset/common/index.js +1 -0
  14. package/dist/esm/components/static-asset/common/index.js.map +1 -1
  15. package/dist/esm/components/static-asset/common/keys.d.ts +1 -1
  16. package/dist/esm/components/static-asset/common/keys.js +1 -1
  17. package/dist/esm/components/static-asset/common/keys.js.map +1 -1
  18. package/dist/esm/components/static-asset/common/types.d.ts +203 -140
  19. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  20. package/dist/esm/components/static-asset/common/validation.d.ts +10 -0
  21. package/dist/esm/components/static-asset/common/validation.js +8 -0
  22. package/dist/esm/components/static-asset/common/validation.js.map +1 -0
  23. package/dist/esm/components/static-asset/component.d.ts +1 -1
  24. package/dist/esm/components/static-asset/component.js +13 -55
  25. package/dist/esm/components/static-asset/component.js.map +1 -1
  26. package/dist/esm/components/static-asset/controller/factory.d.ts +185 -67
  27. package/dist/esm/components/static-asset/controller/factory.js +32 -821
  28. package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
  29. package/dist/esm/components/static-asset/controller/routes/context.d.ts +61 -0
  30. package/dist/esm/components/static-asset/controller/routes/context.js +45 -0
  31. package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -0
  32. package/dist/esm/components/static-asset/controller/routes/definition.d.ts +40 -0
  33. package/dist/esm/components/static-asset/controller/routes/definition.js +74 -0
  34. package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -0
  35. package/dist/esm/components/static-asset/controller/routes/direct-upload.d.ts +3 -0
  36. package/dist/esm/components/static-asset/controller/routes/direct-upload.js +131 -0
  37. package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -0
  38. package/dist/esm/components/static-asset/controller/routes/labels.d.ts +16 -0
  39. package/dist/esm/components/static-asset/controller/routes/labels.js +19 -0
  40. package/dist/esm/components/static-asset/controller/routes/labels.js.map +1 -0
  41. package/dist/esm/components/static-asset/controller/routes/objects.d.ts +7 -0
  42. package/dist/esm/components/static-asset/controller/routes/objects.js +193 -0
  43. package/dist/esm/components/static-asset/controller/routes/objects.js.map +1 -0
  44. package/dist/esm/components/static-asset/controller/routes/serve.d.ts +17 -0
  45. package/dist/esm/components/static-asset/controller/routes/serve.js +127 -0
  46. package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -0
  47. package/dist/esm/components/static-asset/controller/routes/table.d.ts +12 -0
  48. package/dist/esm/components/static-asset/controller/routes/table.js +52 -0
  49. package/dist/esm/components/static-asset/controller/routes/table.js.map +1 -0
  50. package/dist/esm/components/static-asset/controller/routes/upload.d.ts +10 -0
  51. package/dist/esm/components/static-asset/controller/routes/upload.js +174 -0
  52. package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
  53. package/dist/esm/components/static-asset/models/base.model.d.ts +4 -4
  54. package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
  55. package/dist/esm/components/static-asset/services/commitment.service.d.ts +53 -16
  56. package/dist/esm/components/static-asset/services/commitment.service.js +114 -35
  57. package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -1
  58. package/dist/esm/components/static-asset/services/policy.service.d.ts +7 -3
  59. package/dist/esm/components/static-asset/services/policy.service.js +29 -7
  60. package/dist/esm/components/static-asset/services/policy.service.js.map +1 -1
  61. package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +5 -1
  62. package/dist/esm/components/static-asset/utilities/commit-token.utility.js +58 -2
  63. package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -1
  64. package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
  65. package/dist/esm/components/static-asset/utilities/entry.utility.js +153 -0
  66. package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
  67. package/dist/esm/components/static-asset/utilities/index.d.ts +3 -0
  68. package/dist/esm/components/static-asset/utilities/index.js +3 -0
  69. package/dist/esm/components/static-asset/utilities/index.js.map +1 -1
  70. package/dist/esm/components/static-asset/utilities/ingest.utility.js +2 -4
  71. package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -1
  72. package/dist/esm/components/static-asset/utilities/key-scope.utility.d.ts +6 -2
  73. package/dist/esm/components/static-asset/utilities/key-scope.utility.js +24 -6
  74. package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -1
  75. package/dist/esm/components/static-asset/utilities/meta-link.utility.d.ts +2 -2
  76. package/dist/esm/components/static-asset/utilities/meta-link.utility.js +6 -6
  77. package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -1
  78. package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +2 -2
  79. package/dist/esm/components/static-asset/utilities/object-link.utility.js +4 -5
  80. package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -1
  81. package/dist/esm/components/static-asset/utilities/pinned-file.utility.d.ts +39 -0
  82. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js +53 -0
  83. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js.map +1 -0
  84. package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +20 -5
  85. package/dist/esm/components/static-asset/utilities/route-options.utility.js +44 -6
  86. package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -1
  87. package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +13 -0
  88. package/dist/esm/components/static-asset/utilities/toggle.utility.js +16 -0
  89. package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
  90. package/dist/presets/app/preset.json +4 -4
  91. package/dist/presets/lib/preset.json +3 -3
  92. package/dist/presets/shared/preset.json +1 -1
  93. package/package.json +6 -6
  94. package/dist/esm/components/static-asset/controller/base.definition.d.ts +0 -30
  95. package/dist/esm/components/static-asset/controller/base.definition.js +0 -307
  96. package/dist/esm/components/static-asset/controller/base.definition.js.map +0 -1
@@ -9,7 +9,7 @@ export class StaticAssetKeyScopeUtility {
9
9
  const segments = trimmed ? trimmed.split('/') : [];
10
10
  if (segments.length === 0 || segments.some((segment) => !helper.isValidSegment({ segment }))) {
11
11
  throw getError({
12
- message: `[${scope}] controller.keyPrefix must be one or more valid key segments | value: ${keyPrefix}`,
12
+ message: `[${scope}] keyPrefix must be one or more valid key segments | value: ${keyPrefix}`,
13
13
  });
14
14
  }
15
15
  return { keyPrefix: `${trimmed}/`, depth: segments.length };
@@ -18,15 +18,33 @@ export class StaticAssetKeyScopeUtility {
18
18
  * The two prefixes of a direct upload, in ONE place: the policy signs `policyKeyPrefix`, and the
19
19
  * commit strips `pendingPrefix` from the key it reads back, so the two have to be computed alike.
20
20
  * The scope rides inside the pending key, so a commit lands inside it.
21
+ *
22
+ * A pending object must never be readable through the entry's own routes, so `pendingPrefix` is
23
+ * refused unless it is a valid key prefix of its own, disjoint from `keyPrefix`: neither starts
24
+ * with the other. Both are checked once, at boot, with the entry's name.
21
25
  */
22
26
  static resolveDirectUploadPrefixes(opts) {
23
27
  const { helper, scope } = opts;
24
- const keyPrefix = opts.keyPrefix === undefined
25
- ? undefined
26
- : StaticAssetKeyScopeUtility.normalizePrefix({ keyPrefix: opts.keyPrefix, helper, scope })
27
- .keyPrefix;
28
+ const { keyPrefix } = StaticAssetKeyScopeUtility.normalizePrefix({
29
+ keyPrefix: opts.keyPrefix,
30
+ helper,
31
+ scope,
32
+ });
28
33
  const pendingPrefix = opts.pendingPrefix ?? StaticAssetDefaults.PENDING_PREFIX;
29
- return { keyPrefix, pendingPrefix, policyKeyPrefix: `${pendingPrefix}${keyPrefix ?? ''}` };
34
+ const segments = pendingPrefix.slice(0, -1).split('/');
35
+ if (pendingPrefix.length < 2 ||
36
+ !pendingPrefix.endsWith('/') ||
37
+ segments.some((segment) => !helper.isValidSegment({ segment }))) {
38
+ throw getError({
39
+ message: `[${scope}] directUpload.pendingPrefix must be one or more valid key segments, each followed by a slash | value: '${pendingPrefix}'`,
40
+ });
41
+ }
42
+ if (pendingPrefix.startsWith(keyPrefix) || keyPrefix.startsWith(pendingPrefix)) {
43
+ throw getError({
44
+ message: `[${scope}] directUpload.pendingPrefix and keyPrefix must not contain one another | pendingPrefix: '${pendingPrefix}' | keyPrefix: '${keyPrefix}' | a pending object would be readable through this entry's routes`,
45
+ });
46
+ }
47
+ return { keyPrefix, pendingPrefix, policyKeyPrefix: `${pendingPrefix}${keyPrefix}` };
30
48
  }
31
49
  static isInScope(opts) {
32
50
  return opts.keyPrefix === undefined || opts.key.startsWith(opts.keyPrefix);
@@ -1 +1 @@
1
- {"version":3,"file":"key-scope.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/key-scope.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,OAAO,0BAA0B;IACrC,iIAAiI;IACjI,MAAM,CAAC,eAAe,CAAC,IAAkE;QAIvF,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAC1C,MAAM,OAAO,GAAG,S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AC;IAC7E,CAAC;IAED,uHAAuH;IACvH,MAAM,CAAC,aAAa,CAAC,IAAyC;QAC5D,IAAI,0BAA0B,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/C,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,KAAK,EAAE,aAAa,CAAC,gBAAgB;YACrC,OAAO,EAAE,2BAA2B,IAAI,CAAC,GAAG,EAAE;SAC/C,CAAC,CAAC;IACL,CAAC;IAED,mGAAmG;IACnG,MAAM,CAAC,iBAAiB,CAAC,IAA6C;QAIpE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAEnC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;QACzC,CAAC;QAED,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;QACpD,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;IACjE,CAAC;CACF","sourcesContent":["import { StorageErrors, type IStorageHelper } from '@venizia/ignis-helpers';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { StaticAssetDefaults } from '../common';\n\nexport class StaticAssetKeyScopeUtility {\n /** `tenant-a`, `/tenant-a` and `tenant-a/` all become `tenant-a/`: without the slash, `tenant-a` would also own `tenant-ab/`. */\n static normalizePrefix(opts: { keyPrefix: string; helper: IStorageHelper; scope: string }): {\n keyPrefix: string;\n depth: number;\n } {\n const { keyPrefix, helper, scope } = opts;\n const trimmed = keyPrefix.replace(/^\\/+|\\/+$/g, '');\n const segments = trimmed ? trimmed.split('/') : [];\n\n if (segments.length === 0 || segments.some((segment) => !helper.isValidSegment({ segment }))) {\n throw getError({\n message: `[${scope}] controller.keyPrefix must be one or more valid key segments | value: ${keyPrefix}`,\n });\n }\n\n return { keyPrefix: `${trimmed}/`, depth: segments.length };\n }\n\n /**\n * The two prefixes of a direct upload, in ONE place: the policy signs `policyKeyPrefix`, and the\n * commit strips `pendingPrefix` from the key it reads back, so the two have to be computed alike.\n * The scope rides inside the pending key, so a commit lands inside it.\n */\n static resolveDirectUploadPrefixes(opts: {\n keyPrefix?: string;\n pendingPrefix?: string;\n helper: IStorageHelper;\n scope: string;\n }): { keyPrefix?: string; pendingPrefix: string; policyKeyPrefix: string } {\n const { helper, scope } = opts;\n const keyPrefix =\n opts.keyPrefix === undefined\n ? undefined\n : StaticAssetKeyScopeUtility.normalizePrefix({ keyPrefix: opts.keyPrefix, helper, scope })\n .keyPrefix;\n const pendingPrefix = opts.pendingPrefix ?? StaticAssetDefaults.PENDING_PREFIX;\n\n return { keyPrefix, pendingPrefix, policyKeyPrefix: `${pendingPrefix}${keyPrefix ?? ''}` };\n }\n\n static isInScope(opts: { key: string; keyPrefix?: string }): boolean {\n return opts.keyPrefix === undefined || opts.key.startsWith(opts.keyPrefix);\n }\n\n /** A key outside the scope answers as a missing object does, so a caller learns nothing about keys it does not own. */\n static assertInScope(opts: { key: string; keyPrefix?: string }): void {\n if (StaticAssetKeyScopeUtility.isInScope(opts)) {\n return;\n }\n\n throw getError({\n error: StorageErrors.OBJECT_NOT_FOUND,\n message: `Object not found | key: ${opts.key}`,\n });\n }\n\n /** A caller prefix wider than the scope is narrowed to it; one wholly outside it lists nothing. */\n static resolveListPrefix(opts: { prefix?: string; keyPrefix?: string }): {\n prefix?: string;\n isOutOfScope: boolean;\n } {\n const { prefix, keyPrefix } = opts;\n\n if (keyPrefix === undefined) {\n return { prefix, isOutOfScope: false };\n }\n\n if (!prefix || keyPrefix.startsWith(prefix)) {\n return { prefix: keyPrefix, isOutOfScope: false };\n }\n\n return { prefix, isOutOfScope: !prefix.startsWith(keyPrefix) };\n }\n}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,gBAAgB;YACrC,OAAO,EAAE,2BAA2B,IAAI,CAAC,GAAG,EAAE;SAC/C,CAAC,CAAC;IACL,CAAC;IAED,mGAAmG;IACnG,MAAM,CAAC,iBAAiB,CAAC,IAA6C;QAIpE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAEnC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;QACzC,CAAC;QAED,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;QACpD,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;IACjE,CAAC;CACF","sourcesContent":["import { StorageErrors, type IStorageHelper } from '@venizia/ignis-helpers';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { StaticAssetDefaults } from '../common';\n\nexport class StaticAssetKeyScopeUtility {\n /** `tenant-a`, `/tenant-a` and `tenant-a/` all become `tenant-a/`: without the slash, `tenant-a` would also own `tenant-ab/`. */\n static normalizePrefix(opts: { keyPrefix: string; helper: IStorageHelper; scope: string }): {\n keyPrefix: string;\n depth: number;\n } {\n const { keyPrefix, helper, scope } = opts;\n const trimmed = keyPrefix.replace(/^\\/+|\\/+$/g, '');\n const segments = trimmed ? trimmed.split('/') : [];\n\n if (segments.length === 0 || segments.some((segment) => !helper.isValidSegment({ segment }))) {\n throw getError({\n message: `[${scope}] keyPrefix must be one or more valid key segments | value: ${keyPrefix}`,\n });\n }\n\n return { keyPrefix: `${trimmed}/`, depth: segments.length };\n }\n\n /**\n * The two prefixes of a direct upload, in ONE place: the policy signs `policyKeyPrefix`, and the\n * commit strips `pendingPrefix` from the key it reads back, so the two have to be computed alike.\n * The scope rides inside the pending key, so a commit lands inside it.\n *\n * A pending object must never be readable through the entry's own routes, so `pendingPrefix` is\n * refused unless it is a valid key prefix of its own, disjoint from `keyPrefix`: neither starts\n * with the other. Both are checked once, at boot, with the entry's name.\n */\n static resolveDirectUploadPrefixes(opts: {\n keyPrefix: string;\n pendingPrefix?: string;\n helper: IStorageHelper;\n scope: string;\n }): { keyPrefix: string; pendingPrefix: string; policyKeyPrefix: string } {\n const { helper, scope } = opts;\n const { keyPrefix } = StaticAssetKeyScopeUtility.normalizePrefix({\n keyPrefix: opts.keyPrefix,\n helper,\n scope,\n });\n const pendingPrefix = opts.pendingPrefix ?? StaticAssetDefaults.PENDING_PREFIX;\n const segments = pendingPrefix.slice(0, -1).split('/');\n\n if (\n pendingPrefix.length < 2 ||\n !pendingPrefix.endsWith('/') ||\n segments.some((segment) => !helper.isValidSegment({ segment }))\n ) {\n throw getError({\n message: `[${scope}] directUpload.pendingPrefix must be one or more valid key segments, each followed by a slash | value: '${pendingPrefix}'`,\n });\n }\n\n if (pendingPrefix.startsWith(keyPrefix) || keyPrefix.startsWith(pendingPrefix)) {\n throw getError({\n message: `[${scope}] directUpload.pendingPrefix and keyPrefix must not contain one another | pendingPrefix: '${pendingPrefix}' | keyPrefix: '${keyPrefix}' | a pending object would be readable through this entry's routes`,\n });\n }\n\n return { keyPrefix, pendingPrefix, policyKeyPrefix: `${pendingPrefix}${keyPrefix}` };\n }\n\n static isInScope(opts: { key: string; keyPrefix?: string }): boolean {\n return opts.keyPrefix === undefined || opts.key.startsWith(opts.keyPrefix);\n }\n\n /** A key outside the scope answers as a missing object does, so a caller learns nothing about keys it does not own. */\n static assertInScope(opts: { key: string; keyPrefix?: string }): void {\n if (StaticAssetKeyScopeUtility.isInScope(opts)) {\n return;\n }\n\n throw getError({\n error: StorageErrors.OBJECT_NOT_FOUND,\n message: `Object not found | key: ${opts.key}`,\n });\n }\n\n /** A caller prefix wider than the scope is narrowed to it; one wholly outside it lists nothing. */\n static resolveListPrefix(opts: { prefix?: string; keyPrefix?: string }): {\n prefix?: string;\n isOutOfScope: boolean;\n } {\n const { prefix, keyPrefix } = opts;\n\n if (keyPrefix === undefined) {\n return { prefix, isOutOfScope: false };\n }\n\n if (!prefix || keyPrefix.startsWith(prefix)) {\n return { prefix: keyPrefix, isOutOfScope: false };\n }\n\n return { prefix, isOutOfScope: !prefix.startsWith(keyPrefix) };\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { IBucketRef, IFileStat, IObjectRef, IStorageHelper, IUploadResult } from '@venizia/ignis-helpers';
2
2
  import type { AnyType } from '@venizia/ignis-helpers/common';
3
- import type { TMetaLinkConfig, TStaticAssetStorageType, TStaticAssetUploadQuery } from '../common/index.js';
3
+ import type { TMetaLinkConfig, TStaticAssetStorageType, TStaticAssetUploadLabels } from '../common/index.js';
4
4
  export declare class StaticAssetMetaLinkUtility {
5
5
  /** What a stat says about one stored object: the columns a refresh rewrites and a new row starts from. */
6
6
  private static buildStoredObjectFacts;
@@ -19,7 +19,7 @@ export declare class StaticAssetMetaLinkUtility {
19
19
  storage: TStaticAssetStorageType;
20
20
  uploadResult: IUploadResult;
21
21
  fileStat: IFileStat;
22
- query: TStaticAssetUploadQuery;
22
+ labels: TStaticAssetUploadLabels;
23
23
  }): Promise<AnyType>;
24
24
  /**
25
25
  * Rewrites the stored-object facts on every row of the pair. Rows per pair are deliberately not
@@ -28,9 +28,9 @@ export class StaticAssetMetaLinkUtility {
28
28
  }
29
29
  /** The MetaLink row for one stored object. Every path that creates a row goes through here, so each lands exactly the row an ordinary upload does. */
30
30
  static async createRow(opts) {
31
- const { metaLink, helper, storage, uploadResult, fileStat, query } = opts;
31
+ const { metaLink, helper, storage, uploadResult, fileStat, labels } = opts;
32
32
  if (metaLink.createMetaLink) {
33
- const created = await metaLink.createMetaLink({ uploadResult, fileStat, query });
33
+ const created = await metaLink.createMetaLink({ uploadResult, fileStat, labels });
34
34
  return created.data;
35
35
  }
36
36
  // Resolved per call so an application that swaps the repository is not pinned to the first one.
@@ -46,12 +46,12 @@ export class StaticAssetMetaLinkUtility {
46
46
  fileStat,
47
47
  }),
48
48
  storageType: storage,
49
- principalId: query.principalId ? String(query.principalId) : undefined,
50
- principalType: query.principalType ? String(query.principalType) : undefined,
51
- variant: query.variant ? String(query.variant) : undefined,
49
+ principalId: labels.principalId,
50
+ principalType: labels.principalType,
51
+ variant: labels.variant,
52
52
  // Absent leaves the column default rather than writing 0, so a row the caller never
53
53
  // ordered is indistinguishable from a legacy one.
54
- sequence: query.sequence === undefined ? undefined : Number(query.sequence),
54
+ sequence: labels.sequence,
55
55
  },
56
56
  });
57
57
  return created.data;
@@ -1 +1 @@
1
- {"version":3,"file":"meta-link.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/meta-link.utility.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAIhE,MAAM,OAAO,0BAA0B;IACrC,0GAA0G;IAClG,MAAM,CAAC,sBAAsB,CAAC,IAKrC;QACC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAEhD,OAAO;YACL,IAAI;YACJ,2DAA2D;YAC3D,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,IAAI,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;YACrF,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;IAED,0HAA0H;IAC1H,MAAM,CAAC,uBAAuB,CAAC,IAM9B;QACC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAExD,OAAO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AAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,GAAG,EAAE;SAC3D,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;QAEhC,IAAI,QAAQ,CAAC,cAAc,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAClD,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC9C,CAAC;QAED,4FAA4F;QAC5F,6FAA6F;QAC7F,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9B,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACf,UAAU,CAAC,UAAU,CAAC;YACpB,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE;SAC9D,CAAC,CACH,CACF,CAAC;QAEF,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;IAC7E,CAAC;CACF","sourcesContent":["import type {\n IBucketRef,\n IFileStat,\n IObjectRef,\n IStorageHelper,\n IUploadResult,\n} from '@venizia/ignis-helpers';\nimport { ResolverUtility } from '@venizia/ignis-helpers/common';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport type { TMetaLinkConfig, TStaticAssetStorageType, TStaticAssetUploadQuery } from '../common';\n\nexport class StaticAssetMetaLinkUtility {\n /** What a stat says about one stored object: the columns a refresh rewrites and a new row starts from. */\n private static buildStoredObjectFacts(opts: {\n helper: IStorageHelper;\n object: IObjectRef;\n link: string;\n fileStat: IFileStat;\n }) {\n const { helper, object, link, fileStat } = opts;\n\n return {\n link,\n // The column is NOT NULL and a backend may report nothing.\n mimetype: fileStat.metadata?.mimetype ?? helper.getMimeType({ filename: object.key }),\n size: fileStat.size,\n etag: fileStat.etag,\n metadata: fileStat.metadata,\n isSynced: true,\n };\n }\n\n /** The upload result of an object already in storage, so a commit or a recreate writes its row the way an upload does. */\n static buildStoredUploadResult(opts: {\n helper: IStorageHelper;\n bucket: IBucketRef;\n object: IObjectRef;\n link: string;\n fileStat: IFileStat;\n }): IUploadResult {\n const { helper, bucket, object, link, fileStat } = opts;\n\n return {\n bucket,\n object: {\n key: object.key,\n size: fileStat.size,\n contentType: fileStat.metadata?.mimetype ?? helper.getMimeType({ filename: object.key }),\n },\n link,\n };\n }\n\n /** The MetaLink row for one stored object. Every path that creates a row goes through here, so each lands exactly the row an ordinary upload does. */\n static async createRow(opts: {\n metaLink: TMetaLinkConfig<AnyType>;\n helper: IStorageHelper;\n storage: TStaticAssetStorageType;\n uploadResult: IUploadResult;\n fileStat: IFileStat;\n query: TStaticAssetUploadQuery;\n }): Promise<AnyType> {\n const { metaLink, helper, storage, uploadResult, fileStat, query } = opts;\n\n if (metaLink.createMetaLink) {\n const created = await metaLink.createMetaLink({ uploadResult, fileStat, query });\n\n return created.data;\n }\n\n // Resolved per call so an application that swaps the repository is not pinned to the first one.\n const repository = await ResolverUtility.resolveValueAsync({ value: metaLink.repository });\n const created = await repository.create({\n data: {\n bucketName: uploadResult.bucket.name,\n objectName: uploadResult.object.key,\n ...StaticAssetMetaLinkUtility.buildStoredObjectFacts({\n helper,\n object: uploadResult.object,\n link: uploadResult.link,\n fileStat,\n }),\n storageType: storage,\n principalId: query.principalId ? String(query.principalId) : undefined,\n principalType: query.principalType ? String(query.principalType) : undefined,\n variant: query.variant ? String(query.variant) : undefined,\n // Absent leaves the column default rather than writing 0, so a row the caller never\n // ordered is indistinguishable from a legacy one.\n sequence: query.sequence === undefined ? undefined : Number(query.sequence),\n },\n });\n\n return created.data;\n }\n\n /**\n * Rewrites the stored-object facts on every row of the pair. Rows per pair are deliberately not\n * unique, and each keeps its own labels and storage type. A `createMetaLink` hook owns `link` and\n * `metadata`, so with one only the stat columns change; without one, `metadata` is merged per row.\n */\n static async refreshRows(opts: {\n metaLink: TMetaLinkConfig<AnyType>;\n helper: IStorageHelper;\n bucket: IBucketRef;\n object: IObjectRef;\n link: string;\n fileStat: IFileStat;\n }): Promise<{ count: number; data: AnyType[] }> {\n const { metaLink, helper, bucket, object, link, fileStat } = opts;\n\n const repository = await ResolverUtility.resolveValueAsync({ value: metaLink.repository });\n const { mimetype, size, etag, isSynced } = StaticAssetMetaLinkUtility.buildStoredObjectFacts({\n helper,\n object,\n link,\n fileStat,\n });\n const statColumns = { mimetype, size, etag, isSynced };\n\n const updated = await repository.updateBy({\n data: metaLink.createMetaLink ? statColumns : { ...statColumns, link },\n where: { bucketName: bucket.name, objectName: object.key },\n });\n const rows = updated.data ?? [];\n\n if (metaLink.createMetaLink || !fileStat.metadata) {\n return { count: updated.count, data: rows };\n }\n\n // One UPDATE per row: each merge starts from that row's own keys, which the statement above\n // returned untouched and which no single engine-neutral statement over the pair can express.\n const merged = await Promise.all(\n rows.map((row) =>\n repository.updateById({\n id: row.id,\n data: { metadata: { ...row.metadata, ...fileStat.metadata } },\n }),\n ),\n );\n\n return { count: updated.count, data: merged.map((result) => result.data) };\n }\n}\n"]}
1
+ {"version":3,"file":"meta-link.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/meta-link.utility.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAIhE,MAAM,OAAO,0BAA0B;IACrC,0GAA0G;IAClG,MAAM,CAAC,sBAAsB,CAAC,IAKrC;QACC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAEhD,OAAO;YACL,IAAI;YACJ,2DAA2D;YAC3D,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,IAAI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AE,GAAG,WAAW,EAAE,IAAI,EAAE;YACtE,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,GAAG,EAAE;SAC3D,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;QAEhC,IAAI,QAAQ,CAAC,cAAc,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAClD,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC9C,CAAC;QAED,4FAA4F;QAC5F,6FAA6F;QAC7F,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9B,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACf,UAAU,CAAC,UAAU,CAAC;YACpB,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE;SAC9D,CAAC,CACH,CACF,CAAC;QAEF,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;IAC7E,CAAC;CACF","sourcesContent":["import type {\n IBucketRef,\n IFileStat,\n IObjectRef,\n IStorageHelper,\n IUploadResult,\n} from '@venizia/ignis-helpers';\nimport { ResolverUtility } from '@venizia/ignis-helpers/common';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport type { TMetaLinkConfig, TStaticAssetStorageType, TStaticAssetUploadLabels } from '../common';\n\nexport class StaticAssetMetaLinkUtility {\n /** What a stat says about one stored object: the columns a refresh rewrites and a new row starts from. */\n private static buildStoredObjectFacts(opts: {\n helper: IStorageHelper;\n object: IObjectRef;\n link: string;\n fileStat: IFileStat;\n }) {\n const { helper, object, link, fileStat } = opts;\n\n return {\n link,\n // The column is NOT NULL and a backend may report nothing.\n mimetype: fileStat.metadata?.mimetype ?? helper.getMimeType({ filename: object.key }),\n size: fileStat.size,\n etag: fileStat.etag,\n metadata: fileStat.metadata,\n isSynced: true,\n };\n }\n\n /** The upload result of an object already in storage, so a commit or a recreate writes its row the way an upload does. */\n static buildStoredUploadResult(opts: {\n helper: IStorageHelper;\n bucket: IBucketRef;\n object: IObjectRef;\n link: string;\n fileStat: IFileStat;\n }): IUploadResult {\n const { helper, bucket, object, link, fileStat } = opts;\n\n return {\n bucket,\n object: {\n key: object.key,\n size: fileStat.size,\n contentType: fileStat.metadata?.mimetype ?? helper.getMimeType({ filename: object.key }),\n },\n link,\n };\n }\n\n /** The MetaLink row for one stored object. Every path that creates a row goes through here, so each lands exactly the row an ordinary upload does. */\n static async createRow(opts: {\n metaLink: TMetaLinkConfig<AnyType>;\n helper: IStorageHelper;\n storage: TStaticAssetStorageType;\n uploadResult: IUploadResult;\n fileStat: IFileStat;\n labels: TStaticAssetUploadLabels;\n }): Promise<AnyType> {\n const { metaLink, helper, storage, uploadResult, fileStat, labels } = opts;\n\n if (metaLink.createMetaLink) {\n const created = await metaLink.createMetaLink({ uploadResult, fileStat, labels });\n\n return created.data;\n }\n\n // Resolved per call so an application that swaps the repository is not pinned to the first one.\n const repository = await ResolverUtility.resolveValueAsync({ value: metaLink.repository });\n const created = await repository.create({\n data: {\n bucketName: uploadResult.bucket.name,\n objectName: uploadResult.object.key,\n ...StaticAssetMetaLinkUtility.buildStoredObjectFacts({\n helper,\n object: uploadResult.object,\n link: uploadResult.link,\n fileStat,\n }),\n storageType: storage,\n principalId: labels.principalId,\n principalType: labels.principalType,\n variant: labels.variant,\n // Absent leaves the column default rather than writing 0, so a row the caller never\n // ordered is indistinguishable from a legacy one.\n sequence: labels.sequence,\n },\n });\n\n return created.data;\n }\n\n /**\n * Rewrites the stored-object facts on every row of the pair. Rows per pair are deliberately not\n * unique, and each keeps its own labels and storage type. A `createMetaLink` hook owns `link` and\n * `metadata`, so with one only the stat columns change; without one, `metadata` is merged per row.\n */\n static async refreshRows(opts: {\n metaLink: TMetaLinkConfig<AnyType>;\n helper: IStorageHelper;\n bucket: IBucketRef;\n object: IObjectRef;\n link: string;\n fileStat: IFileStat;\n }): Promise<{ count: number; data: AnyType[] }> {\n const { metaLink, helper, bucket, object, link, fileStat } = opts;\n\n const repository = await ResolverUtility.resolveValueAsync({ value: metaLink.repository });\n const { mimetype, size, etag, isSynced } = StaticAssetMetaLinkUtility.buildStoredObjectFacts({\n helper,\n object,\n link,\n fileStat,\n });\n const statColumns = { mimetype, size, etag, isSynced };\n\n const updated = await repository.updateBy({\n data: metaLink.createMetaLink ? statColumns : { ...statColumns, link },\n where: { bucketName: bucket.name, objectName: object.key },\n });\n const rows = updated.data ?? [];\n\n if (metaLink.createMetaLink || !fileStat.metadata) {\n return { count: updated.count, data: rows };\n }\n\n // One UPDATE per row: each merge starts from that row's own keys, which the statement above\n // returned untouched and which no single engine-neutral statement over the pair can express.\n const merged = await Promise.all(\n rows.map((row) =>\n repository.updateById({\n id: row.id,\n data: { metadata: { ...row.metadata, ...fileStat.metadata } },\n }),\n ),\n );\n\n return { count: updated.count, data: merged.map((result) => result.data) };\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { IObjectLocation } from '@venizia/ignis-helpers';
2
+ /** Builds the URL of an object in the shape its controller serves. */
2
3
  export declare class StaticAssetObjectLinkUtility {
3
4
  /** The mount path may be declared with or without a leading slash; a link must carry exactly one. */
4
5
  static normalizeBasePath(opts: {
@@ -6,10 +7,9 @@ export declare class StaticAssetObjectLinkUtility {
6
7
  }): string;
7
8
  /** Encodes an object path into a SINGLE url segment: `{objectName}` matches one segment only, so `/` must be percent-encoded too (Hono decodes it back before the handler reads the param). */
8
9
  private static encodeObjectPath;
9
- /** The URL of one object, in the shape its controller serves: no `/buckets/<name>` with a configured bucket, and a raw path with `rawObjectPath`. */
10
+ /** The URL of one object, in the shape its controller serves: a raw path with `rawObjectPath`, a percent-encoded one without. */
10
11
  static build(opts: IObjectLocation & {
11
12
  basePath: string;
12
- hasConfiguredBucket?: boolean;
13
13
  rawObjectPath?: boolean;
14
14
  }): string;
15
15
  }
@@ -1,3 +1,4 @@
1
+ /** Builds the URL of an object in the shape its controller serves. */
1
2
  export class StaticAssetObjectLinkUtility {
2
3
  /** The mount path may be declared with or without a leading slash; a link must carry exactly one. */
3
4
  static normalizeBasePath(opts) {
@@ -7,15 +8,13 @@ export class StaticAssetObjectLinkUtility {
7
8
  static encodeObjectPath(opts) {
8
9
  return encodeURIComponent(opts.objectPath);
9
10
  }
10
- /** The URL of one object, in the shape its controller serves: no `/buckets/<name>` with a configured bucket, and a raw path with `rawObjectPath`. */
11
+ /** The URL of one object, in the shape its controller serves: a raw path with `rawObjectPath`, a percent-encoded one without. */
11
12
  static build(opts) {
12
- const { basePath, bucket, object } = opts;
13
- const { hasConfiguredBucket = false, rawObjectPath = false } = opts;
14
- const bucketSegment = hasConfiguredBucket ? '' : `/buckets/${bucket.name}`;
13
+ const { basePath, object, rawObjectPath = false } = opts;
15
14
  const objectSegment = rawObjectPath
16
15
  ? object.key
17
16
  : StaticAssetObjectLinkUtility.encodeObjectPath({ objectPath: object.key });
18
- return `${basePath}${bucketSegment}/objects/${objectSegment}`;
17
+ return `${basePath}/objects/${objectSegment}`;
19
18
  }
20
19
  }
21
20
  //# sourceMappingURL=object-link.utility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"object-link.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/object-link.utility.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,4BAA4B;IACvC,qGAAqG;IACrG,MAAM,CAAC,iBAAiB,CAAC,IAA0B;QACjD,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC7E,CAAC;IAED,+LAA+L;IACvL,MAAM,CAAC,gBAAgB,CAAC,IAA4B;QAC1D,OAAO,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED,qJAAqJ;IACrJ,MAAM,CAAC,KAAK,CACV,IAIC;QAED,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAC1C,MAAM,EAAE,mBAAmB,GAAG,KAAK,EAAE,aAAa,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;QAEpE,MAAM,aAAa,GAAG,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3E,MAAM,aAAa,GAAG,aAAa;YACjC,CAAC,CAAC,MAAM,CAAC,GAAG;YACZ,CAAC,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QAE9E,OAAO,GAAG,QAAQ,GAAG,aAAa,YAAY,aAAa,EAAE,CAAC;IAChE,CAAC;CACF","sourcesContent":["import type { IObjectLocation } from '@venizia/ignis-helpers';\n\nexport class StaticAssetObjectLinkUtility {\n /** The mount path may be declared with or without a leading slash; a link must carry exactly one. */\n static normalizeBasePath(opts: { basePath: string }): string {\n return opts.basePath.startsWith('/') ? opts.basePath : `/${opts.basePath}`;\n }\n\n /** Encodes an object path into a SINGLE url segment: `{objectName}` matches one segment only, so `/` must be percent-encoded too (Hono decodes it back before the handler reads the param). */\n private static encodeObjectPath(opts: { objectPath: string }): string {\n return encodeURIComponent(opts.objectPath);\n }\n\n /** The URL of one object, in the shape its controller serves: no `/buckets/<name>` with a configured bucket, and a raw path with `rawObjectPath`. */\n static build(\n opts: IObjectLocation & {\n basePath: string;\n hasConfiguredBucket?: boolean;\n rawObjectPath?: boolean;\n },\n ): string {\n const { basePath, bucket, object } = opts;\n const { hasConfiguredBucket = false, rawObjectPath = false } = opts;\n\n const bucketSegment = hasConfiguredBucket ? '' : `/buckets/${bucket.name}`;\n const objectSegment = rawObjectPath\n ? object.key\n : StaticAssetObjectLinkUtility.encodeObjectPath({ objectPath: object.key });\n\n return `${basePath}${bucketSegment}/objects/${objectSegment}`;\n }\n}\n"]}
1
+ {"version":3,"file":"object-link.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/object-link.utility.ts"],"names":[],"mappings":"AAEA,sEAAsE;AACtE,MAAM,OAAO,4BAA4B;IACvC,qGAAqG;IACrG,MAAM,CAAC,iBAAiB,CAAC,IAA0B;QACjD,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC7E,CAAC;IAED,+LAA+L;IACvL,MAAM,CAAC,gBAAgB,CAAC,IAA4B;QAC1D,OAAO,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED,iIAAiI;IACjI,MAAM,CAAC,KAAK,CAAC,IAAqE;QAChF,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;QACzD,MAAM,aAAa,GAAG,aAAa;YACjC,CAAC,CAAC,MAAM,CAAC,GAAG;YACZ,CAAC,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QAE9E,OAAO,GAAG,QAAQ,YAAY,aAAa,EAAE,CAAC;IAChD,CAAC;CACF","sourcesContent":["import type { IObjectLocation } from '@venizia/ignis-helpers';\n\n/** Builds the URL of an object in the shape its controller serves. */\nexport class StaticAssetObjectLinkUtility {\n /** The mount path may be declared with or without a leading slash; a link must carry exactly one. */\n static normalizeBasePath(opts: { basePath: string }): string {\n return opts.basePath.startsWith('/') ? opts.basePath : `/${opts.basePath}`;\n }\n\n /** Encodes an object path into a SINGLE url segment: `{objectName}` matches one segment only, so `/` must be percent-encoded too (Hono decodes it back before the handler reads the param). */\n private static encodeObjectPath(opts: { objectPath: string }): string {\n return encodeURIComponent(opts.objectPath);\n }\n\n /** The URL of one object, in the shape its controller serves: a raw path with `rawObjectPath`, a percent-encoded one without. */\n static build(opts: IObjectLocation & { basePath: string; rawObjectPath?: boolean }): string {\n const { basePath, object, rawObjectPath = false } = opts;\n const objectSegment = rawObjectPath\n ? object.key\n : StaticAssetObjectLinkUtility.encodeObjectPath({ objectPath: object.key });\n\n return `${basePath}/objects/${objectSegment}`;\n }\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import { type IFileStat, type IObjectLocation, type IStorageHelper } from '@venizia/ignis-helpers';
2
+ import { type IStaticAssetPin } from '../common/index.js';
3
+ /**
4
+ * The pending file as `validation.handler` sees it. Every read asks the storage for exactly the
5
+ * content that was pinned, so a handler cannot parse bytes that are not the ones `commit` will copy:
6
+ * a read that finds other content or no object throws `UPLOAD_CHANGED`.
7
+ */
8
+ export declare class StaticAssetPinnedFile {
9
+ readonly key: string;
10
+ readonly size: number;
11
+ private readonly helper;
12
+ private readonly location;
13
+ private readonly pin;
14
+ constructor(opts: {
15
+ helper: IStorageHelper;
16
+ location: IObjectLocation;
17
+ pin: IStaticAssetPin;
18
+ size: number;
19
+ });
20
+ /** What a read or a copy requires of the object: the exact version when the pin has one, else the ETag. */
21
+ static conditionOf(opts: {
22
+ pin: IStaticAssetPin;
23
+ }): {
24
+ ifMatch?: string;
25
+ versionId?: string;
26
+ };
27
+ /** The pin of what the storage holds now. An object with no ETag cannot be pinned. */
28
+ static pinOf(opts: {
29
+ stat: IFileStat;
30
+ scope: string;
31
+ }): IStaticAssetPin;
32
+ stream(opts?: {
33
+ range?: {
34
+ start: number;
35
+ end?: number;
36
+ };
37
+ }): Promise<ReadableStream<Uint8Array>>;
38
+ }
39
+ //# sourceMappingURL=pinned-file.utility.d.ts.map
@@ -0,0 +1,53 @@
1
+ import { StorageUtility, } from '@venizia/ignis-helpers';
2
+ import { getError } from '@venizia/ignis-helpers/core';
3
+ import { StaticAssetErrors } from '../common/index.js';
4
+ /**
5
+ * The pending file as `validation.handler` sees it. Every read asks the storage for exactly the
6
+ * content that was pinned, so a handler cannot parse bytes that are not the ones `commit` will copy:
7
+ * a read that finds other content or no object throws `UPLOAD_CHANGED`.
8
+ */
9
+ export class StaticAssetPinnedFile {
10
+ constructor(opts) {
11
+ this.helper = opts.helper;
12
+ this.location = opts.location;
13
+ this.pin = opts.pin;
14
+ this.key = opts.location.object.key;
15
+ this.size = opts.size;
16
+ }
17
+ /** What a read or a copy requires of the object: the exact version when the pin has one, else the ETag. */
18
+ static conditionOf(opts) {
19
+ const { pin } = opts;
20
+ return pin.versionId === undefined ? { ifMatch: pin.etag } : { versionId: pin.versionId };
21
+ }
22
+ /** The pin of what the storage holds now. An object with no ETag cannot be pinned. */
23
+ static pinOf(opts) {
24
+ const { stat, scope } = opts;
25
+ if (!stat.etag) {
26
+ throw getError({
27
+ message: `[${scope}] The storage reported no ETag for the pending object | a pinned validation needs one`,
28
+ });
29
+ }
30
+ return {
31
+ etag: stat.etag,
32
+ versionId: StorageUtility.realVersionId({ value: stat.versionId }),
33
+ };
34
+ }
35
+ async stream(opts) {
36
+ try {
37
+ const stream = await this.helper.getObjectStream({
38
+ ...this.location,
39
+ range: opts?.range,
40
+ ...StaticAssetPinnedFile.conditionOf({ pin: this.pin }),
41
+ });
42
+ return stream;
43
+ }
44
+ catch (error) {
45
+ if (StorageUtility.isPreconditionFailedError({ error }) ||
46
+ StorageUtility.isNotFoundError({ error })) {
47
+ throw getError({ error: StaticAssetErrors.UPLOAD_CHANGED, cause: error });
48
+ }
49
+ throw error;
50
+ }
51
+ }
52
+ }
53
+ //# sourceMappingURL=pinned-file.utility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pinned-file.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/pinned-file.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAIf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAwB,MAAM,WAAW,CAAC;AAEpE;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IAQhC,YAAY,IAKX;QACC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAED,2GAA2G;IAC3G,MAAM,CAAC,WAAW,CAAC,IAA8B;QAC/C,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAErB,OAAO,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC;IAC5F,CAAC;IAED,sFAAsF;IACtF,MAAM,CAAC,KAAK,CAAC,IAAwC;QACnD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAE7B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,IAAI,KAAK,uFAAuF;aAC1G,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,cAAc,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;SACnE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAEZ;QACC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;gBAC/C,GAAG,IAAI,CAAC,QAAQ;gBAChB,KAAK,EAAE,IAAI,EAAE,KAAK;gBAClB,GAAG,qBAAqB,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;aACxD,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IACE,cAAc,CAAC,yBAAyB,CAAC,EAAE,KAAK,EAAE,CAAC;gBACnD,cAAc,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,CAAC,EACzC,CAAC;gBACD,MAAM,QAAQ,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YAC5E,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n StorageUtility,\n type IFileStat,\n type IObjectLocation,\n type IStorageHelper,\n} from '@venizia/ignis-helpers';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { StaticAssetErrors, type IStaticAssetPin } from '../common';\n\n/**\n * The pending file as `validation.handler` sees it. Every read asks the storage for exactly the\n * content that was pinned, so a handler cannot parse bytes that are not the ones `commit` will copy:\n * a read that finds other content or no object throws `UPLOAD_CHANGED`.\n */\nexport class StaticAssetPinnedFile {\n readonly key: string;\n readonly size: number;\n\n private readonly helper: IStorageHelper;\n private readonly location: IObjectLocation;\n private readonly pin: IStaticAssetPin;\n\n constructor(opts: {\n helper: IStorageHelper;\n location: IObjectLocation;\n pin: IStaticAssetPin;\n size: number;\n }) {\n this.helper = opts.helper;\n this.location = opts.location;\n this.pin = opts.pin;\n this.key = opts.location.object.key;\n this.size = opts.size;\n }\n\n /** What a read or a copy requires of the object: the exact version when the pin has one, else the ETag. */\n static conditionOf(opts: { pin: IStaticAssetPin }): { ifMatch?: string; versionId?: string } {\n const { pin } = opts;\n\n return pin.versionId === undefined ? { ifMatch: pin.etag } : { versionId: pin.versionId };\n }\n\n /** The pin of what the storage holds now. An object with no ETag cannot be pinned. */\n static pinOf(opts: { stat: IFileStat; scope: string }): IStaticAssetPin {\n const { stat, scope } = opts;\n\n if (!stat.etag) {\n throw getError({\n message: `[${scope}] The storage reported no ETag for the pending object | a pinned validation needs one`,\n });\n }\n\n return {\n etag: stat.etag,\n versionId: StorageUtility.realVersionId({ value: stat.versionId }),\n };\n }\n\n async stream(opts?: {\n range?: { start: number; end?: number };\n }): Promise<ReadableStream<Uint8Array>> {\n try {\n const stream = await this.helper.getObjectStream({\n ...this.location,\n range: opts?.range,\n ...StaticAssetPinnedFile.conditionOf({ pin: this.pin }),\n });\n\n return stream;\n } catch (error) {\n if (\n StorageUtility.isPreconditionFailedError({ error }) ||\n StorageUtility.isNotFoundError({ error })\n ) {\n throw getError({ error: StaticAssetErrors.UPLOAD_CHANGED, cause: error });\n }\n\n throw error;\n }\n }\n}\n"]}
@@ -1,15 +1,30 @@
1
- import { type TStaticAssetRouteConfig } from '../common/index.js';
1
+ import type { IAuthRouteConfig } from '../../../base/index.js';
2
+ import { type TStaticAssetRouteConfig, type TStaticAssetRouteKey } from '../common/index.js';
3
+ import type { IStaticAssetResolvedEntry, IStaticAssetResolvedRoute } from './entry.utility.js';
4
+ /** What a route is registered with: the application's overrides, and the auth it ends up with. */
5
+ export type TStaticAssetRouteOverride = Omit<TStaticAssetRouteConfig, 'authenticate' | 'authorize'> & Pick<IAuthRouteConfig, 'authenticate' | 'authorize'>;
2
6
  export declare class StaticAssetRouteOptionsUtility {
3
7
  /** Multipart framing of one file (boundary, `Content-Disposition` with a file name, `Content-Type`), allowed on top of its `maxBytes` in the route's body limit. */
4
8
  static readonly ENVELOPE_BYTES_PER_FILE: number;
5
9
  /** The non-file parts of an upload (policy fields, the closing boundary), allowed once in the route's body limit. */
6
10
  static readonly ENVELOPE_BYTES_BASE: number;
7
- /** Splits the `enabled` switch off the route config: it is this component's field, never a Hono one. */
8
- static readOverride(opts: {
9
- route?: TStaticAssetRouteConfig;
11
+ /** The routes `auth.publicRead` leaves open: reading ONE object. Listing is not reading an object. */
12
+ private static readonly PUBLIC_READ_ROUTES;
13
+ /**
14
+ * Reads one built-in route's configuration: whether it is registered, the Hono overrides, and the
15
+ * authentication and authorization it ends up with.
16
+ *
17
+ * Auth is resolved by the same resolver the CRUD factory uses: a route's own config beats the
18
+ * entry's `auth`, and `{ skip: true }` opens the route. `publicRead` is the entry's default for
19
+ * the two read routes and loses to any auth the route sets itself.
20
+ */
21
+ static readRoute(opts: {
22
+ key: TStaticAssetRouteKey;
23
+ route?: IStaticAssetResolvedRoute;
24
+ auth?: IStaticAssetResolvedEntry<never>['auth'];
10
25
  }): {
11
26
  isEnabled: boolean;
12
- override: Omit<TStaticAssetRouteConfig, 'enabled'>;
27
+ override: TStaticAssetRouteOverride;
13
28
  };
14
29
  /**
15
30
  * The route's body validator reads the whole multipart body, so a declared length checked in the
@@ -1,16 +1,54 @@
1
1
  import { HTTP } from '@venizia/ignis-helpers/common';
2
2
  import { getError } from '@venizia/ignis-helpers/core';
3
- import { BodyLimits } from '@venizia/ignis-kernel';
4
- import { StaticAssetErrors } from '../common/index.js';
3
+ import { BodyLimits, RouteConfigResolver } from '@venizia/ignis-kernel';
4
+ import { StaticAssetErrors, StaticAssetRouteKeys, } from '../common/index.js';
5
5
  export class StaticAssetRouteOptionsUtility {
6
6
  /** Multipart framing of one file (boundary, `Content-Disposition` with a file name, `Content-Type`), allowed on top of its `maxBytes` in the route's body limit. */
7
7
  static { this.ENVELOPE_BYTES_PER_FILE = 4 * 1024; }
8
8
  /** The non-file parts of an upload (policy fields, the closing boundary), allowed once in the route's body limit. */
9
9
  static { this.ENVELOPE_BYTES_BASE = 64 * 1024; }
10
- /** Splits the `enabled` switch off the route config: it is this component's field, never a Hono one. */
11
- static readOverride(opts) {
12
- const { enabled, ...override } = opts.route ?? {};
13
- return { isEnabled: enabled !== false, override };
10
+ /** The routes `auth.publicRead` leaves open: reading ONE object. Listing is not reading an object. */
11
+ static { this.PUBLIC_READ_ROUTES = new Set([
12
+ StaticAssetRouteKeys.GET_OBJECT_BY_NAME,
13
+ StaticAssetRouteKeys.DOWNLOAD_OBJECT_BY_NAME,
14
+ ]); }
15
+ /**
16
+ * Reads one built-in route's configuration: whether it is registered, the Hono overrides, and the
17
+ * authentication and authorization it ends up with.
18
+ *
19
+ * Auth is resolved by the same resolver the CRUD factory uses: a route's own config beats the
20
+ * entry's `auth`, and `{ skip: true }` opens the route. `publicRead` is the entry's default for
21
+ * the two read routes and loses to any auth the route sets itself.
22
+ */
23
+ static readRoute(opts) {
24
+ const { key, route, auth } = opts;
25
+ const { authenticate, authorize, ...override } = route?.override ?? {};
26
+ const isPublicRead = auth?.isPublicRead === true &&
27
+ StaticAssetRouteOptionsUtility.PUBLIC_READ_ROUTES.has(key) &&
28
+ authenticate == null &&
29
+ authorize == null;
30
+ const endpoint = isPublicRead
31
+ ? { authenticate: { skip: true } }
32
+ : { authenticate, authorize };
33
+ // An entry-level `skip` is no default at all: nothing to inherit.
34
+ const entryAuthenticate = auth?.authenticate == null || auth.authenticate.skip === true ? undefined : auth.authenticate;
35
+ const entryAuthorize = auth?.authorize == null || (!Array.isArray(auth.authorize) && 'skip' in auth.authorize)
36
+ ? undefined
37
+ : auth.authorize;
38
+ return {
39
+ isEnabled: route?.isEnabled ?? true,
40
+ override: {
41
+ ...override,
42
+ authenticate: RouteConfigResolver.resolveAuthenticate({
43
+ controller: entryAuthenticate,
44
+ endpoint: endpoint.authenticate,
45
+ }),
46
+ authorize: RouteConfigResolver.resolveAuthorize({
47
+ controller: entryAuthorize,
48
+ endpoint,
49
+ }),
50
+ },
51
+ };
14
52
  }
15
53
  /**
16
54
  * The route's body validator reads the whole multipart body, so a declared length checked in the
@@ -1 +1 @@
1
- {"version":3,"file":"route-options.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/route-options.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAgC,MAAM,WAAW,CAAC;AAE5E,MAAM,OAAO,8BAA8B;IACzC,oKAAoK;aACpJ,4BAAuB,GAAG,CAAC,GAAG,IAAI,CAAC;IAEnD,qHAAqH;aACrG,wBAAmB,GAAG,EAAE,GAAG,IAAI,CAAC;IAEhD,wGAAwG;IACxG,MAAM,CAAC,YAAY,CAAC,IAAyC;QAI3D,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAElD,OAAO,EAAE,SAAS,EAAE,OAAO,KAAK,KAAK,EAAE,QAAQ,EAAE,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAIxB;QACC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAEhD,MAAM,KAAK,GAAsB,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;YACvD,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;YAE/E,kHAAkH;YAClH,IAAI,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,cAAc,GAAG,QAAQ,EAAE,CAAC;gBACjE,MAAM,QAAQ,CAAC;oBACb,KAAK,EAAE,iBAAiB,CAAC,gBAAgB;oBACzC,OAAO,EAAE,mBAAmB,cAAc,iCAAiC,QAAQ,EAAE;iBACtF,CAAC,CAAC;YACL,CAAC;YAED,MAAM,IAAI,EAAE,CAAC;QACf,CAAC,CAAC;QAEF,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;YAC7B,OAAO,EACL,QAAQ,GAAG,CAAC,QAAQ,GAAG,8BAA8B,CAAC,uBAAuB,CAAC;gBAC9E,8BAA8B,CAAC,mBAAmB;SACrD,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAChG,CAAC","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { BodyLimits } from '@venizia/ignis-kernel';\nimport type { MiddlewareHandler } from 'hono';\nimport { StaticAssetErrors, type TStaticAssetRouteConfig } from '../common';\n\nexport class StaticAssetRouteOptionsUtility {\n /** Multipart framing of one file (boundary, `Content-Disposition` with a file name, `Content-Type`), allowed on top of its `maxBytes` in the route's body limit. */\n static readonly ENVELOPE_BYTES_PER_FILE = 4 * 1024;\n\n /** The non-file parts of an upload (policy fields, the closing boundary), allowed once in the route's body limit. */\n static readonly ENVELOPE_BYTES_BASE = 64 * 1024;\n\n /** Splits the `enabled` switch off the route config: it is this component's field, never a Hono one. */\n static readOverride(opts: { route?: TStaticAssetRouteConfig }): {\n isEnabled: boolean;\n override: Omit<TStaticAssetRouteConfig, 'enabled'>;\n } {\n const { enabled, ...override } = opts.route ?? {};\n\n return { isEnabled: enabled !== false, override };\n }\n\n /**\n * The route's body validator reads the whole multipart body, so a declared length checked in the\n * handler arrives too late to save any memory. Appended after the application's own middleware, so\n * a check of its own still answers first.\n *\n * The route also sets its own body limit: `maxFiles` files of `maxBytes` each, plus their multipart framing. An\n * upload route that accepts more than the 5 MiB default would otherwise be held to the default, and a chunked body,\n * which has no declared length, is counted too. The per-file check in the handler still decides each file.\n */\n static appendLengthGuard(opts: {\n middleware: TStaticAssetRouteConfig['middleware'];\n maxBytes: number;\n maxFiles: number;\n }): NonNullable<TStaticAssetRouteConfig['middleware']> {\n const { middleware, maxBytes, maxFiles } = opts;\n\n const guard: MiddlewareHandler = async (context, next) => {\n const declaredLength = Number(context.req.header(HTTP.Headers.CONTENT_LENGTH));\n\n // Not authoritative: a multipart envelope is larger than its files, so the per-file check in the handler decides.\n if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {\n throw getError({\n error: StaticAssetErrors.UPLOAD_TOO_LARGE,\n message: `Request body of ${declaredLength} bytes exceeds the maximum of ${maxBytes}`,\n });\n }\n\n await next();\n };\n\n const limit = BodyLimits.route({\n maxSize:\n maxFiles * (maxBytes + StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_PER_FILE) +\n StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_BASE,\n });\n\n if (!middleware) {\n return [guard, limit];\n }\n\n return Array.isArray(middleware) ? [...middleware, guard, limit] : [middleware, guard, limit];\n }\n}\n"]}
1
+ {"version":3,"file":"route-options.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/route-options.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAGxE,OAAO,EACL,iBAAiB,EACjB,oBAAoB,GAGrB,MAAM,WAAW,CAAC;AAUnB,MAAM,OAAO,8BAA8B;IACzC,oKAAoK;aACpJ,4BAAuB,GAAG,C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OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAChG,CAAC","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { BodyLimits, RouteConfigResolver } from '@venizia/ignis-kernel';\nimport type { MiddlewareHandler } from 'hono';\nimport type { IAuthRouteConfig, TRouteAuthConfig } from '@/base';\nimport {\n StaticAssetErrors,\n StaticAssetRouteKeys,\n type TStaticAssetRouteConfig,\n type TStaticAssetRouteKey,\n} from '../common';\nimport type { IStaticAssetResolvedEntry, IStaticAssetResolvedRoute } from './entry.utility';\n\n/** What a route is registered with: the application's overrides, and the auth it ends up with. */\nexport type TStaticAssetRouteOverride = Omit<\n TStaticAssetRouteConfig,\n 'authenticate' | 'authorize'\n> &\n Pick<IAuthRouteConfig, 'authenticate' | 'authorize'>;\n\nexport class StaticAssetRouteOptionsUtility {\n /** Multipart framing of one file (boundary, `Content-Disposition` with a file name, `Content-Type`), allowed on top of its `maxBytes` in the route's body limit. */\n static readonly ENVELOPE_BYTES_PER_FILE = 4 * 1024;\n\n /** The non-file parts of an upload (policy fields, the closing boundary), allowed once in the route's body limit. */\n static readonly ENVELOPE_BYTES_BASE = 64 * 1024;\n\n /** The routes `auth.publicRead` leaves open: reading ONE object. Listing is not reading an object. */\n private static readonly PUBLIC_READ_ROUTES: ReadonlySet<TStaticAssetRouteKey> = new Set([\n StaticAssetRouteKeys.GET_OBJECT_BY_NAME,\n StaticAssetRouteKeys.DOWNLOAD_OBJECT_BY_NAME,\n ]);\n\n /**\n * Reads one built-in route's configuration: whether it is registered, the Hono overrides, and the\n * authentication and authorization it ends up with.\n *\n * Auth is resolved by the same resolver the CRUD factory uses: a route's own config beats the\n * entry's `auth`, and `{ skip: true }` opens the route. `publicRead` is the entry's default for\n * the two read routes and loses to any auth the route sets itself.\n */\n static readRoute(opts: {\n key: TStaticAssetRouteKey;\n route?: IStaticAssetResolvedRoute;\n auth?: IStaticAssetResolvedEntry<never>['auth'];\n }): { isEnabled: boolean; override: TStaticAssetRouteOverride } {\n const { key, route, auth } = opts;\n const { authenticate, authorize, ...override } = route?.override ?? {};\n\n const isPublicRead =\n auth?.isPublicRead === true &&\n StaticAssetRouteOptionsUtility.PUBLIC_READ_ROUTES.has(key) &&\n authenticate == null &&\n authorize == null;\n const endpoint: TRouteAuthConfig = isPublicRead\n ? { authenticate: { skip: true } }\n : { authenticate, authorize };\n\n // An entry-level `skip` is no default at all: nothing to inherit.\n const entryAuthenticate =\n auth?.authenticate == null || auth.authenticate.skip === true ? undefined : auth.authenticate;\n const entryAuthorize =\n auth?.authorize == null || (!Array.isArray(auth.authorize) && 'skip' in auth.authorize)\n ? undefined\n : auth.authorize;\n\n return {\n isEnabled: route?.isEnabled ?? true,\n override: {\n ...override,\n authenticate: RouteConfigResolver.resolveAuthenticate({\n controller: entryAuthenticate,\n endpoint: endpoint.authenticate,\n }),\n authorize: RouteConfigResolver.resolveAuthorize({\n controller: entryAuthorize,\n endpoint,\n }),\n },\n };\n }\n\n /**\n * The route's body validator reads the whole multipart body, so a declared length checked in the\n * handler arrives too late to save any memory. Appended after the application's own middleware, so\n * a check of its own still answers first.\n *\n * The route also sets its own body limit: `maxFiles` files of `maxBytes` each, plus their multipart framing. An\n * upload route that accepts more than the 5 MiB default would otherwise be held to the default, and a chunked body,\n * which has no declared length, is counted too. The per-file check in the handler still decides each file.\n */\n static appendLengthGuard(opts: {\n middleware: TStaticAssetRouteConfig['middleware'];\n maxBytes: number;\n maxFiles: number;\n }): NonNullable<TStaticAssetRouteConfig['middleware']> {\n const { middleware, maxBytes, maxFiles } = opts;\n\n const guard: MiddlewareHandler = async (context, next) => {\n const declaredLength = Number(context.req.header(HTTP.Headers.CONTENT_LENGTH));\n\n // Not authoritative: a multipart envelope is larger than its files, so the per-file check in the handler decides.\n if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {\n throw getError({\n error: StaticAssetErrors.UPLOAD_TOO_LARGE,\n message: `Request body of ${declaredLength} bytes exceeds the maximum of ${maxBytes}`,\n });\n }\n\n await next();\n };\n\n const limit = BodyLimits.route({\n maxSize:\n maxFiles * (maxBytes + StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_PER_FILE) +\n StaticAssetRouteOptionsUtility.ENVELOPE_BYTES_BASE,\n });\n\n if (!middleware) {\n return [guard, limit];\n }\n\n return Array.isArray(middleware) ? [...middleware, guard, limit] : [middleware, guard, limit];\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { TToggle } from '../common/index.js';
2
+ /** Reads the `{ use }` switches an entry is written with. */
3
+ export declare class StaticAssetToggleUtility {
4
+ /** The only place a toggle's `use` is read. Narrowing here is what lets every caller reach the options without a cast. */
5
+ static isUsed<Options extends object>(toggle: TToggle<Options> | undefined): toggle is Extract<TToggle<Options>, {
6
+ use: true;
7
+ }>;
8
+ /** The options of a toggle that is on, without `use`; `undefined` when it is off or absent. */
9
+ static pick<Options extends object>(toggle: TToggle<Options> | undefined): Omit<Extract<TToggle<Options>, {
10
+ use: true;
11
+ }>, 'use'> | undefined;
12
+ }
13
+ //# sourceMappingURL=toggle.utility.d.ts.map
@@ -0,0 +1,16 @@
1
+ /** Reads the `{ use }` switches an entry is written with. */
2
+ export class StaticAssetToggleUtility {
3
+ /** The only place a toggle's `use` is read. Narrowing here is what lets every caller reach the options without a cast. */
4
+ static isUsed(toggle) {
5
+ return toggle !== undefined && toggle.use;
6
+ }
7
+ /** The options of a toggle that is on, without `use`; `undefined` when it is off or absent. */
8
+ static pick(toggle) {
9
+ if (!StaticAssetToggleUtility.isUsed(toggle)) {
10
+ return undefined;
11
+ }
12
+ const { use: _use, ...options } = toggle;
13
+ return options;
14
+ }
15
+ }
16
+ //# sourceMappingURL=toggle.utility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toggle.utility.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/utilities/toggle.utility.ts"],"names":[],"mappings":"AAEA,6DAA6D;AAC7D,MAAM,OAAO,wBAAwB;IACnC,0HAA0H;IAC1H,MAAM,CAAC,MAAM,CACX,MAAoC;QAEpC,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC;IAC5C,CAAC;IAED,+FAA+F;IAC/F,MAAM,CAAC,IAAI,CACT,MAAoC;QAEpC,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7C,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC;QAEzC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import type { TToggle } from '../common';\n\n/** Reads the `{ use }` switches an entry is written with. */\nexport class StaticAssetToggleUtility {\n /** The only place a toggle's `use` is read. Narrowing here is what lets every caller reach the options without a cast. */\n static isUsed<Options extends object>(\n toggle: TToggle<Options> | undefined,\n ): toggle is Extract<TToggle<Options>, { use: true }> {\n return toggle !== undefined && toggle.use;\n }\n\n /** The options of a toggle that is on, without `use`; `undefined` when it is off or absent. */\n static pick<Options extends object>(\n toggle: TToggle<Options> | undefined,\n ): Omit<Extract<TToggle<Options>, { use: true }>, 'use'> | undefined {\n if (!StaticAssetToggleUtility.isUsed(toggle)) {\n return undefined;\n }\n\n const { use: _use, ...options } = toggle;\n\n return options;\n }\n}\n"]}
@@ -14,9 +14,9 @@
14
14
  "dependencies": {
15
15
  "@hono/zod-openapi": "^1.6.3",
16
16
  "@scalar/hono-api-reference": "^0.12.13",
17
- "@venizia/ignis": "0.4.8-11",
18
- "@venizia/ignis-boot": "0.4.8-8",
19
- "@venizia/ignis-helpers": "0.4.8-8",
17
+ "@venizia/ignis": "0.4.8-13",
18
+ "@venizia/ignis-boot": "0.4.8-10",
19
+ "@venizia/ignis-helpers": "0.4.8-10",
20
20
  "hono": "^4.13.13",
21
21
  "winston": "^3.19.0",
22
22
  "winston-daily-rotate-file": "^5.0.0",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/bun": "^1.4.3",
27
- "@venizia/dev-configs": "0.4.8-6",
27
+ "@venizia/dev-configs": "0.4.8-7",
28
28
  "eslint": "^10.13.0",
29
29
  "oxlint": "1.89.0",
30
30
  "oxlint-tsgolint": "7.0.2004",
@@ -4,15 +4,15 @@
4
4
  "dependencies": {},
5
5
  "devDependencies": {
6
6
  "@types/bun": "^1.4.3",
7
- "@venizia/dev-configs": "0.4.8-6",
8
- "@venizia/ignis": "0.4.8-11",
7
+ "@venizia/dev-configs": "0.4.8-7",
8
+ "@venizia/ignis": "0.4.8-13",
9
9
  "eslint": "^10.13.0",
10
10
  "oxlint": "1.89.0",
11
11
  "oxlint-tsgolint": "7.0.2004",
12
12
  "typescript": "^6.0.3"
13
13
  },
14
14
  "peerDependencies": {
15
- "@venizia/ignis": "0.4.8-11"
15
+ "@venizia/ignis": "0.4.8-13"
16
16
  },
17
17
  "scripts": {
18
18
  "typecheck": "bun check",
@@ -4,7 +4,7 @@
4
4
  "dependencies": {},
5
5
  "devDependencies": {
6
6
  "@types/bun": "^1.4.3",
7
- "@venizia/dev-configs": "0.4.8-6",
7
+ "@venizia/dev-configs": "0.4.8-7",
8
8
  "eslint": "^10.13.0",
9
9
  "oxlint": "1.89.0",
10
10
  "oxlint-tsgolint": "7.0.2004",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/ignis",
3
- "version": "0.4.8-11",
3
+ "version": "0.4.8-13",
4
4
  "description": "TypeScript server framework with decorator-based DI, the repository pattern and a component system, on Hono. Features auto-generated OpenAPI docs, Drizzle ORM type-safe SQL, JWT/Basic authentication, Casbin authorization, convention-based bootstrapping, and pluggable components for health checks, Swagger UI, mail, Socket.IO, and static assets. Built for Bun.",
5
5
  "keywords": [
6
6
  "access-control",
@@ -134,11 +134,11 @@
134
134
  "force-update": "sh ../../scripts/build/force-update.sh"
135
135
  },
136
136
  "dependencies": {
137
- "@venizia/ignis-connectors": "0.4.8-10",
137
+ "@venizia/ignis-connectors": "0.4.8-12",
138
138
  "@venizia/ignis-filter": "0.4.7-4",
139
- "@venizia/ignis-helpers": "0.4.8-8",
139
+ "@venizia/ignis-helpers": "0.4.8-10",
140
140
  "@venizia/ignis-inversion": "0.4.7-3",
141
- "@venizia/ignis-kernel": "0.4.8-10",
141
+ "@venizia/ignis-kernel": "0.4.8-12",
142
142
  "reflect-metadata": "^0.2.2"
143
143
  },
144
144
  "devDependencies": {
@@ -151,8 +151,8 @@
151
151
  "@types/bun": "^1.4.3",
152
152
  "@types/nodemailer": "^8.0.2",
153
153
  "@types/pg": "^8.23.1",
154
- "@venizia/dev-configs": "0.4.8-6",
155
- "@venizia/ignis-boot": "0.4.8-8",
154
+ "@venizia/dev-configs": "0.4.8-7",
155
+ "@venizia/ignis-boot": "0.4.8-10",
156
156
  "casbin": "^5.51.1",
157
157
  "eslint": "^10.13.0",
158
158
  "meilisearch": "^0.62.0",