@antelopejs/dms-media 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +18 -3
  2. package/dist/acl/entries.js +1 -2
  3. package/dist/acl/entries.js.map +1 -1
  4. package/dist/bindings.js +1 -3
  5. package/dist/bindings.js.map +1 -1
  6. package/dist/declared/folders.js +3 -2
  7. package/dist/declared/folders.js.map +1 -1
  8. package/dist/declared/records.d.ts +2 -2
  9. package/dist/declared/records.js +3 -2
  10. package/dist/declared/records.js.map +1 -1
  11. package/dist/derivatives.js +9 -6
  12. package/dist/derivatives.js.map +1 -1
  13. package/dist/guards.d.ts +4 -0
  14. package/dist/guards.js +19 -0
  15. package/dist/guards.js.map +1 -0
  16. package/dist/library/activity.js +7 -5
  17. package/dist/library/activity.js.map +1 -1
  18. package/dist/library/batches.js +6 -3
  19. package/dist/library/batches.js.map +1 -1
  20. package/dist/library/events.js +4 -4
  21. package/dist/library/events.js.map +1 -1
  22. package/dist/library/module-readout.js +5 -2
  23. package/dist/library/module-readout.js.map +1 -1
  24. package/dist/library/realtime.js.map +1 -1
  25. package/dist/pages/activity.js +1 -1
  26. package/dist/pages/activity.js.map +1 -1
  27. package/dist/routes/media/assets.d.ts +1 -1
  28. package/dist/routes/media/assets.js +5 -5
  29. package/dist/routes/media/assets.js.map +1 -1
  30. package/dist/routes/media/bulk.js +17 -13
  31. package/dist/routes/media/bulk.js.map +1 -1
  32. package/dist/routes/media/delivery-headers.js +9 -9
  33. package/dist/routes/media/delivery-headers.js.map +1 -1
  34. package/dist/routes/media/delivery-stream.js.map +1 -1
  35. package/dist/routes/media/delivery.js.map +1 -1
  36. package/dist/routes/media/manage.js.map +1 -1
  37. package/dist/routes/media/transform.js +13 -8
  38. package/dist/routes/media/transform.js.map +1 -1
  39. package/dist/test/antelope.test.js +13 -12
  40. package/dist/test/antelope.test.js.map +1 -1
  41. package/dist/test/helpers/folders.d.ts +27 -0
  42. package/dist/test/helpers/folders.js +15 -0
  43. package/dist/test/helpers/folders.js.map +1 -1
  44. package/dist/test/helpers/pages.js +10 -6
  45. package/dist/test/helpers/pages.js.map +1 -1
  46. package/dist/test/helpers/permissions-world.d.ts +98 -0
  47. package/dist/test/helpers/permissions-world.js +205 -0
  48. package/dist/test/helpers/permissions-world.js.map +1 -0
  49. package/dist/test/helpers/prototype.d.ts +1 -0
  50. package/dist/test/helpers/prototype.js +11 -0
  51. package/dist/test/helpers/prototype.js.map +1 -0
  52. package/dist/test/integration/derivative-sweep-query.test.js +13 -16
  53. package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
  54. package/dist/test/integration/folder-query.test.js +5 -9
  55. package/dist/test/integration/folder-query.test.js.map +1 -1
  56. package/dist/test/integration/media-bindings.test.js +2 -2
  57. package/dist/test/integration/media-bindings.test.js.map +1 -1
  58. package/dist/test/integration/media-cleanup.test.js +14 -17
  59. package/dist/test/integration/media-cleanup.test.js.map +1 -1
  60. package/dist/test/integration/media-declared-content.test.js +2 -1
  61. package/dist/test/integration/media-declared-content.test.js.map +1 -1
  62. package/dist/test/integration/media-delivery-editing.test.js +7 -5
  63. package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
  64. package/dist/test/integration/media-delivery.test.js +19 -5
  65. package/dist/test/integration/media-delivery.test.js.map +1 -1
  66. package/dist/test/integration/media-explorer-writes.test.js +2 -2
  67. package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
  68. package/dist/test/integration/media-guards.test.js +18 -7
  69. package/dist/test/integration/media-guards.test.js.map +1 -1
  70. package/dist/test/integration/media-library.test.js +1 -1
  71. package/dist/test/integration/media-library.test.js.map +1 -1
  72. package/dist/test/integration/media-linked-subfolders.test.js +5 -5
  73. package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
  74. package/dist/test/integration/media-member-access.test.js +2 -5
  75. package/dist/test/integration/media-member-access.test.js.map +1 -1
  76. package/dist/test/integration/media-permissions.test.js +142 -473
  77. package/dist/test/integration/media-permissions.test.js.map +1 -1
  78. package/dist/test/integration/media-project-field.test.js +3 -5
  79. package/dist/test/integration/media-project-field.test.js.map +1 -1
  80. package/dist/test/integration/media-search-query.test.js +11 -16
  81. package/dist/test/integration/media-search-query.test.js.map +1 -1
  82. package/dist/test/integration/media-storage-origin-unreachable.test.js +1 -0
  83. package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
  84. package/dist/test/integration/media-upload-policy.test.js +2 -2
  85. package/dist/test/integration/media-upload-policy.test.js.map +1 -1
  86. package/dist/test/integration/permissions-management.d.ts +2 -0
  87. package/dist/test/integration/permissions-management.js +189 -0
  88. package/dist/test/integration/permissions-management.js.map +1 -0
  89. package/dist/test/unit/acl/entries.test.js +2 -1
  90. package/dist/test/unit/acl/entries.test.js.map +1 -1
  91. package/dist/test/unit/acl/resolver.test.js +10 -3
  92. package/dist/test/unit/acl/resolver.test.js.map +1 -1
  93. package/dist/test/unit/library/fixtures.d.ts +1 -1
  94. package/dist/test/unit/library/fixtures.js +6 -1
  95. package/dist/test/unit/library/fixtures.js.map +1 -1
  96. package/dist/test/unit/library/library.test.js +0 -1
  97. package/dist/test/unit/library/library.test.js.map +1 -1
  98. package/dist/test/unit/library/realtime.test.js.map +1 -1
  99. package/dist/test/unit/library/search-facets.test.js +2 -2
  100. package/dist/test/unit/library/search-facets.test.js.map +1 -1
  101. package/dist/test/unit/pages/toolbar.test.js +24 -7
  102. package/dist/test/unit/pages/toolbar.test.js.map +1 -1
  103. package/dist/test/unit/routes/dto.test.js +7 -6
  104. package/dist/test/unit/routes/dto.test.js.map +1 -1
  105. package/dist/test/unit/routes/file-page.test.js +5 -7
  106. package/dist/test/unit/routes/file-page.test.js.map +1 -1
  107. package/dist/test/unit/routes/preset-row.test.js +2 -1
  108. package/dist/test/unit/routes/preset-row.test.js.map +1 -1
  109. package/dist/transform.js +6 -6
  110. package/dist/transform.js.map +1 -1
  111. package/dist/upload-checks.d.ts +8 -2
  112. package/dist/upload-checks.js.map +1 -1
  113. package/dist/upload-policy.js +8 -8
  114. package/dist/upload-policy.js.map +1 -1
  115. package/dist/validation/declared.schema.js +14 -8
  116. package/dist/validation/declared.schema.js.map +1 -1
  117. package/dist/validation/media.schema.d.ts +1 -1
  118. package/dist/validation/media.schema.js +2 -2
  119. package/dist/validation/media.schema.js.map +1 -1
  120. package/frontend-vue/app/build/imageEditor/editorShapes.ts +118 -0
  121. package/frontend-vue/app/build/imageEditor/useEditorSaving.ts +87 -0
  122. package/frontend-vue/app/build/library/libraryActions.ts +444 -0
  123. package/frontend-vue/app/build/library/libraryCore.ts +137 -0
  124. package/frontend-vue/app/components/FirstRun.vue +2 -1
  125. package/frontend-vue/app/components/ImageEditor.vue +22 -179
  126. package/frontend-vue/app/components/dialogs/DestinationDialog.vue +3 -3
  127. package/frontend-vue/app/components/field/FieldAltPopover.vue +2 -1
  128. package/frontend-vue/app/composables/library/useMediaLibrary.ts +3 -575
  129. package/frontend-vue/app/composables/useAssetFieldUploads.ts +9 -1
  130. package/frontend-vue/app/composables/useAssetLink.ts +33 -13
  131. package/frontend-vue/app/composables/useFileDetails.ts +6 -5
  132. package/frontend-vue/app/composables/useMediaApi.ts +21 -5
  133. package/frontend-vue/app/composables/useUploadFailureText.ts +24 -5
  134. package/frontend-vue/app/composables/useUploadQueue.ts +178 -44
  135. package/frontend-vue/app/composables/useUploadToasts.ts +81 -19
  136. package/frontend-vue/build/backend-boundary.ts +122 -0
  137. package/frontend-vue/dms.frontend.build.ts +3 -0
  138. package/frontend-vue/eslint.config.mjs +13 -0
  139. package/frontend-vue/package.json +4 -2
  140. package/frontend-vue/pnpm-lock.yaml +217 -61
  141. package/frontend-vue/tests/api-error-presentation.test.ts +183 -0
  142. package/frontend-vue/tests/backend-boundary.test.ts +203 -0
  143. package/frontend-vue/tests/fixtures/serverRender.ts +1 -1
  144. package/frontend-vue/tests/mediaPreviews.test.ts +39 -0
  145. package/package.json +5 -11
  146. package/skills/dms-media/SKILL.md +3 -2
  147. package/skills/dms-media/cases.json +38 -0
  148. package/src/acl/entries.ts +6 -4
  149. package/src/bindings.ts +3 -3
  150. package/src/declared/folders.ts +3 -3
  151. package/src/declared/records.ts +9 -8
  152. package/src/derivatives.ts +10 -6
  153. package/src/guards.ts +19 -0
  154. package/src/library/activity.ts +17 -9
  155. package/src/library/batches.ts +12 -9
  156. package/src/library/events.ts +7 -4
  157. package/src/library/module-readout.ts +6 -2
  158. package/src/library/realtime.ts +5 -1
  159. package/src/library/zip.ts +1 -1
  160. package/src/pages/activity.ts +6 -2
  161. package/src/routes/media/assets.ts +4 -3
  162. package/src/routes/media/bulk.ts +16 -14
  163. package/src/routes/media/delivery-headers.ts +9 -12
  164. package/src/routes/media/delivery-stream.ts +3 -2
  165. package/src/routes/media/delivery.ts +4 -2
  166. package/src/routes/media/manage.ts +4 -6
  167. package/src/routes/media/transform.ts +27 -23
  168. package/src/test/antelope.test.ts +21 -17
  169. package/src/test/helpers/folders.ts +22 -0
  170. package/src/test/helpers/pages.ts +12 -5
  171. package/src/test/helpers/permissions-world.ts +326 -0
  172. package/src/test/helpers/prototype.ts +12 -0
  173. package/src/test/integration/derivative-sweep-query.test.ts +19 -21
  174. package/src/test/integration/folder-query.test.ts +11 -11
  175. package/src/test/integration/media-bindings.test.ts +7 -7
  176. package/src/test/integration/media-cleanup.test.ts +25 -37
  177. package/src/test/integration/media-declared-content.test.ts +18 -19
  178. package/src/test/integration/media-delivery-editing.test.ts +11 -7
  179. package/src/test/integration/media-delivery.test.ts +29 -8
  180. package/src/test/integration/media-explorer-writes.test.ts +2 -7
  181. package/src/test/integration/media-guards.test.ts +21 -7
  182. package/src/test/integration/media-library.test.ts +1 -1
  183. package/src/test/integration/media-linked-subfolders.test.ts +11 -20
  184. package/src/test/integration/media-member-access.test.ts +5 -9
  185. package/src/test/integration/media-permissions.test.ts +56 -570
  186. package/src/test/integration/media-project-field.test.ts +5 -7
  187. package/src/test/integration/media-search-query.test.ts +16 -20
  188. package/src/test/integration/media-storage-origin-unreachable.test.ts +3 -2
  189. package/src/test/integration/media-upload-policy.test.ts +2 -8
  190. package/src/test/integration/permissions-management.ts +292 -0
  191. package/src/test/unit/acl/entries.test.ts +2 -1
  192. package/src/test/unit/acl/resolver.test.ts +19 -7
  193. package/src/test/unit/library/fixtures.ts +9 -3
  194. package/src/test/unit/library/library.test.ts +1 -7
  195. package/src/test/unit/library/realtime.test.ts +1 -1
  196. package/src/test/unit/library/search-facets.test.ts +2 -2
  197. package/src/test/unit/pages/toolbar.test.ts +42 -17
  198. package/src/test/unit/routes/dto.test.ts +7 -6
  199. package/src/test/unit/routes/file-page.test.ts +10 -9
  200. package/src/test/unit/routes/preset-row.test.ts +2 -2
  201. package/src/transform.ts +6 -6
  202. package/src/upload-checks.ts +12 -3
  203. package/src/upload-policy.ts +8 -8
  204. package/src/validation/declared.schema.ts +17 -12
  205. package/src/validation/media.schema.ts +6 -6
  206. package/frontend-vue/tests/engines.test.ts +0 -20
  207. package/frontend-vue/tests/locales.test.ts +0 -61
@@ -1,9 +1,15 @@
1
1
  import { expect } from "chai";
2
- import type { ComponentBuilder } from "@antelopejs/interface-dms/component";
2
+ import { GetMetadata } from "@antelopejs/interface-core";
3
+ import {
4
+ ComponentBuilder,
5
+ type ComponentInfoSerialized,
6
+ } from "@antelopejs/interface-dms/component";
7
+ import { PageMetadata } from "@antelopejs/interface-dms/page";
3
8
  import { MEDIA_LIBRARY_TOPIC } from "../../../constants";
9
+ import { isObject } from "../../../guards";
4
10
  import { MediaActivityPage } from "../../../pages/activity";
5
11
  import { MediaOverviewPage } from "../../../pages/overview";
6
- import { MEDIA_LIVE, mediaPageToolbar } from "../../../pages/toolbar";
12
+ import { mediaPageToolbar } from "../../../pages/toolbar";
7
13
  import { MediaUploadsPage } from "../../../pages/uploads";
8
14
 
9
15
  const TOOLBAR_COMPONENT = "dms-page-toolbar-block";
@@ -17,29 +23,39 @@ type LivePage = (typeof LIVE_PAGES)[keyof typeof LIVE_PAGES];
17
23
 
18
24
  /** The blocks a page declares, in the order it renders them. */
19
25
  function pageBlocks(page: LivePage): ComponentBuilder<unknown>[] {
20
- return Object.values(page) as ComponentBuilder<unknown>[];
26
+ return Object.values(page).filter(
27
+ (value): value is ComponentBuilder<unknown> =>
28
+ value instanceof ComponentBuilder,
29
+ );
21
30
  }
22
31
 
23
- /** What a block serializes to, as far as reading its data goes. */
24
- interface SerializedBlock {
32
+ /** What a block reads, as its serialized options say. */
33
+ interface BlockReads {
25
34
  componentName: string;
26
- options?: Record<string, unknown>;
27
- children?: { id: string; component: SerializedBlock }[];
35
+ fetchUrl?: unknown;
36
+ realtimeTopic?: unknown;
28
37
  }
29
38
 
30
39
  /**
31
40
  * The blocks under `block` that read data, `block` included: a `fetchUrl`, or
32
41
  * a table, which reads through a route of its own and only says its topic.
33
42
  */
34
- function fetchingBlocks(block: SerializedBlock): SerializedBlock[] {
43
+ function fetchingBlocks(block: ComponentInfoSerialized): BlockReads[] {
44
+ const { options } = block;
35
45
  const own =
36
- block.options &&
37
- ("fetchUrl" in block.options || "realtimeTopic" in block.options)
38
- ? [block]
46
+ isObject(options) && ("fetchUrl" in options || "realtimeTopic" in options)
47
+ ? [
48
+ {
49
+ componentName: block.componentName,
50
+ fetchUrl: "fetchUrl" in options ? options.fetchUrl : undefined,
51
+ realtimeTopic:
52
+ "realtimeTopic" in options ? options.realtimeTopic : undefined,
53
+ },
54
+ ]
39
55
  : [];
40
56
  return [
41
57
  ...own,
42
- ...(block.children ?? []).flatMap((child: { component: SerializedBlock }) =>
58
+ ...(block.children ?? []).flatMap((child) =>
43
59
  fetchingBlocks(child.component),
44
60
  ),
45
61
  ];
@@ -58,8 +74,17 @@ describe("[unit] pages — toolbar", () => {
58
74
  });
59
75
 
60
76
  it("shares one Direct / Pause choice between the media pages", () => {
61
- expect(MEDIA_LIVE.rememberKey).to.equal("media");
62
- expect(MEDIA_LIVE.maxRate).to.be.greaterThan(0);
77
+ const lives = Object.values(LIVE_PAGES).map(
78
+ (page) => GetMetadata(page, PageMetadata).pageInfo?.live,
79
+ );
80
+ const rememberKeys = new Set(lives.map((live) => live?.rememberKey));
81
+ const [rememberKey] = rememberKeys;
82
+ expect([...rememberKeys]).to.have.length(1);
83
+ expect(rememberKey).to.be.a("string");
84
+ expect(rememberKey).to.not.equal("");
85
+ for (const live of lives) {
86
+ expect(live?.maxRate).to.be.greaterThan(0);
87
+ }
63
88
  });
64
89
 
65
90
  for (const [name, page] of Object.entries(LIVE_PAGES)) {
@@ -72,13 +97,13 @@ describe("[unit] pages — toolbar", () => {
72
97
  for (const [name, page] of Object.entries(LIVE_PAGES)) {
73
98
  it(`reads every block of the ${name} page again on library changes`, () => {
74
99
  const blocks = pageBlocks(page).flatMap((block) =>
75
- fetchingBlocks(block.serializeSync() as SerializedBlock),
100
+ fetchingBlocks(block.serializeSync()),
76
101
  );
77
102
  expect(blocks).to.have.length.greaterThan(0);
78
103
  for (const block of blocks) {
79
104
  expect(
80
- block.options?.realtimeTopic,
81
- `${block.componentName} ${JSON.stringify(block.options?.fetchUrl)}`,
105
+ block.realtimeTopic,
106
+ `${block.componentName} ${JSON.stringify(block.fetchUrl)}`,
82
107
  ).to.equal(MEDIA_LIBRARY_TOPIC);
83
108
  }
84
109
  });
@@ -5,13 +5,14 @@ import {
5
5
  resolveEffectiveVisibility,
6
6
  } from "../../../routes/media/dto";
7
7
  import type { AssetVisibility, FolderVisibility } from "../../../types";
8
+ import { asset, folder } from "../library/fixtures";
8
9
 
9
10
  function assetWithVisibility(visibility: AssetVisibility): MediaAsset {
10
- return { visibility } as MediaAsset;
11
+ return asset("asset", { visibility });
11
12
  }
12
13
 
13
14
  function folderWithVisibility(visibility: FolderVisibility): MediaFolder {
14
- return { visibility } as MediaFolder;
15
+ return folder("folder", undefined, [], { visibility });
15
16
  }
16
17
 
17
18
  describe("[unit] routes/dto — resolveEffectiveVisibility", () => {
@@ -54,12 +55,12 @@ describe("[unit] routes/dto — resolveEffectiveVisibility", () => {
54
55
 
55
56
  describe("[unit] routes/dto — buildDeliveryPath", () => {
56
57
  it("builds the stable delivery URL from id and name", () => {
57
- const asset = { _id: "a1", name: "photo.png" } as MediaAsset;
58
- expect(buildDeliveryPath(asset)).to.equal("/media/a1/photo.png");
58
+ const photo = asset("a1", { name: "photo.png" });
59
+ expect(buildDeliveryPath(photo)).to.equal("/media/a1/photo.png");
59
60
  });
60
61
 
61
62
  it("escapes unsafe characters in the filename", () => {
62
- const asset = { _id: "a1", name: "my file#1.png" } as MediaAsset;
63
- expect(buildDeliveryPath(asset)).to.equal("/media/a1/my%20file%231.png");
63
+ const spaced = asset("a1", { name: "my file#1.png" });
64
+ expect(buildDeliveryPath(spaced)).to.equal("/media/a1/my%20file%231.png");
64
65
  });
65
66
  });
@@ -1,4 +1,4 @@
1
- import { expect } from "chai";
1
+ import { assert, expect } from "chai";
2
2
  import type { KeyValueListItem } from "@antelopejs/interface-dms/base/key-value-list";
3
3
  import type { MediaAsset, MediaFolder } from "../../../db";
4
4
  import { buildDeliveryPath } from "../../../routes/media/dto";
@@ -7,31 +7,32 @@ import {
7
7
  buildDeliveryNotice,
8
8
  buildFileInformation,
9
9
  } from "../../../routes/media/file";
10
+ import {
11
+ asset as buildAsset,
12
+ folder as buildFolder,
13
+ } from "../library/fixtures";
10
14
 
11
15
  const ORIGIN = "https://api.example.com";
12
16
  const ASSET_ID = "7554eb0a-c6fb-4518-a8b9-65c6e8a3e6a9";
13
17
 
14
18
  function jpeg(overrides: Partial<MediaAsset> = {}): MediaAsset {
15
- return {
16
- _id: ASSET_ID,
19
+ return buildAsset(ASSET_ID, {
17
20
  name: "Été à Liège.jpg",
18
- mimetype: "image/jpeg",
19
- visibility: "inherit",
20
21
  folderId: "folder",
21
22
  createdAt: new Date("2026-10-01T10:00:00Z"),
22
23
  updatedAt: new Date("2026-10-02T10:00:00Z"),
23
24
  ...overrides,
24
- } as MediaAsset;
25
+ });
25
26
  }
26
27
 
27
28
  function folder(visibility: MediaFolder["visibility"]): MediaFolder {
28
- return { visibility } as MediaFolder;
29
+ return buildFolder("folder", undefined, [], { visibility });
29
30
  }
30
31
 
31
32
  function row(items: KeyValueListItem[], id: string): KeyValueListItem {
32
33
  const found = items.find((item) => item.id === id);
33
- expect(found, id).to.not.equal(undefined);
34
- return found as KeyValueListItem;
34
+ assert.isDefined(found, id);
35
+ return found;
35
36
  }
36
37
 
37
38
  describe("[unit] routes/file — delivery links", () => {
@@ -1,12 +1,12 @@
1
1
  import { expect } from "chai";
2
- import type { MediaAsset } from "../../../db";
3
2
  import type { MediaPresetConfig } from "../../../presets";
4
3
  import { presetRow } from "../../../routes/media/manage";
4
+ import { asset } from "../library/fixtures";
5
5
 
6
6
  const ORIGIN = "http://127.0.0.1:5010";
7
7
  const ASSET_ID = "7554eb0a-c6fb-4518-a8b9-65c6e8a3e6a9";
8
8
  const THUMB: MediaPresetConfig = { id: "thumb", width: 300, height: 300 };
9
- const EXAMPLE = { _id: ASSET_ID, name: "Été à Liège.jpg" } as MediaAsset;
9
+ const EXAMPLE = asset(ASSET_ID, { name: "Été à Liège.jpg" });
10
10
  const EXAMPLE_PATH = `/media/${ASSET_ID}/thumb/%C3%89t%C3%A9%20%C3%A0%20Li%C3%A8ge.jpg`;
11
11
 
12
12
  describe("[unit] routes/manage — image size cards", () => {
package/src/transform.ts CHANGED
@@ -28,11 +28,11 @@ type EditOutputOptions =
28
28
  | sharp.WebpOptions
29
29
  | sharp.AvifOptions;
30
30
 
31
- const EDIT_OUTPUT_OPTIONS: Record<string, EditOutputOptions> = {
32
- jpeg: { quality: 92, mozjpeg: true },
33
- webp: { quality: 92 },
34
- avif: { quality: 80 },
35
- };
31
+ const EDIT_OUTPUT_OPTIONS = new Map<keyof sharp.FormatEnum, EditOutputOptions>([
32
+ ["jpeg", { quality: 92, mozjpeg: true }],
33
+ ["webp", { quality: 92 }],
34
+ ["avif", { quality: 80 }],
35
+ ]);
36
36
 
37
37
  export class AnimatedImageTransformError extends Error {}
38
38
  /** Someone else changed the image while this edit was being rendered. */
@@ -123,7 +123,7 @@ function encodeLikeSource(
123
123
  metadata: sharp.Metadata,
124
124
  ): sharp.Sharp {
125
125
  const kept = pipeline.keepMetadata();
126
- const options = metadata.format && EDIT_OUTPUT_OPTIONS[metadata.format];
126
+ const options = metadata.format && EDIT_OUTPUT_OPTIONS.get(metadata.format);
127
127
  if (!options || !metadata.format) return kept;
128
128
  return kept.toFormat(metadata.format, options);
129
129
  }
@@ -13,8 +13,10 @@ const HTTP_PAYLOAD_TOO_LARGE = 413;
13
13
  const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
14
14
  const HTTP_UNPROCESSABLE_ENTITY = 422;
15
15
  const FIRST_SWAPPED_ORIENTATION = 5;
16
- // Dimension probing buffers the file in memory, so skip files too large to
17
- // hold in the heap; they simply stay without width/height metadata.
16
+ /**
17
+ * Dimension probing buffers the file in memory, so files too large to hold in
18
+ * the heap are skipped; they simply stay without width/height metadata.
19
+ */
18
20
  const MAX_PROBE_SIZE_BYTES = 32 * 1024 * 1024;
19
21
 
20
22
  /** Why an upload is refused, for the queue to explain it in the member's language. */
@@ -24,6 +26,13 @@ export type UploadRefusal =
24
26
  | "quota"
25
27
  | "invalid_image";
26
28
 
29
+ /** What a refusal tells the member besides its reason: the accepted types of the field, or the quota left. */
30
+ interface UploadRefusalDetails {
31
+ accepted?: string[];
32
+ remaining?: number;
33
+ quota?: number;
34
+ }
35
+
27
36
  /**
28
37
  * A file the library refuses, whoever adds it: the upload routes answer it as
29
38
  * an HTTP error, declared content throws it to the calling module.
@@ -33,7 +42,7 @@ export class UploadRefusedError extends Error {
33
42
  readonly status: number,
34
43
  readonly reason: UploadRefusal,
35
44
  message: string,
36
- readonly details: Record<string, unknown> = {},
45
+ readonly details: UploadRefusalDetails = {},
37
46
  ) {
38
47
  super(message);
39
48
  }
@@ -46,13 +46,13 @@ const DECODABLE_IMAGE_MIMETYPES: Record<string, string> = {
46
46
  };
47
47
 
48
48
  /** Mimetype of what sharp actually read, to store instead of the claim. */
49
- const MIMETYPES_BY_FORMAT: Record<string, string> = {
50
- jpeg: "image/jpeg",
51
- png: "image/png",
52
- webp: "image/webp",
53
- gif: "image/gif",
54
- tiff: "image/tiff",
55
- };
49
+ const MIMETYPES_BY_FORMAT = new Map([
50
+ ["jpeg", "image/jpeg"],
51
+ ["png", "image/png"],
52
+ ["webp", "image/webp"],
53
+ ["gif", "image/gif"],
54
+ ["tiff", "image/tiff"],
55
+ ]);
56
56
 
57
57
  function normalizeMimetype(mimetype: string): string {
58
58
  return (mimetype.split(PARAMETER_SEPARATOR)[0] ?? "").trim().toLowerCase();
@@ -96,5 +96,5 @@ export function expectedImageFormat(mimetype: string): string | undefined {
96
96
  export function mimetypeOfFormat(
97
97
  format: string | undefined,
98
98
  ): string | undefined {
99
- return format ? MIMETYPES_BY_FORMAT[format] : undefined;
99
+ return format ? MIMETYPES_BY_FORMAT.get(format) : undefined;
100
100
  }
@@ -1,4 +1,5 @@
1
1
  import { z, ZodError } from "zod";
2
+ import { isCallable } from "../guards";
2
3
  import {
3
4
  altSchema,
4
5
  fileNameSchema,
@@ -11,13 +12,15 @@ import {
11
12
  * The dashboard answers with i18n keys its pages translate; a module declaring
12
13
  * content reads the error in its logs, so it gets the English text.
13
14
  */
14
- const DECLARATION_ERROR_TEXTS: Record<string, string> = {
15
- [MEDIA_ERRORS.nameRequired]: "a name is required",
16
- [MEDIA_ERRORS.nameTooLong]: "the name is limited to 255 characters",
17
- [MEDIA_ERRORS.nameForbidden]:
15
+ const DECLARATION_ERROR_TEXTS = new Map<string, string>([
16
+ [MEDIA_ERRORS.nameRequired, "a name is required"],
17
+ [MEDIA_ERRORS.nameTooLong, "the name is limited to 255 characters"],
18
+ [
19
+ MEDIA_ERRORS.nameForbidden,
18
20
  "a name can't contain / \\ < > : \" | ? * or control characters",
19
- [MEDIA_ERRORS.altTooLong]: "the alt text is limited to 255 characters",
20
- };
21
+ ],
22
+ [MEDIA_ERRORS.altTooLong, "the alt text is limited to 255 characters"],
23
+ ]);
21
24
 
22
25
  const keySchema = z.string().trim().min(1).max(255);
23
26
  const tenantSchema = z.string().trim().min(1);
@@ -44,16 +47,18 @@ export const declaredFolderSchema = z.object({
44
47
  tenantId: tenantSchema,
45
48
  });
46
49
 
50
+ /**
51
+ * Where a declared file's bytes come from. `load` is checked as a function
52
+ * only: wrapping it in `z.function()` would replace the caller's loader.
53
+ */
47
54
  const sourceSchema = z.union([
48
55
  z.object({ bytes: z.instanceof(Uint8Array) }).strict(),
49
56
  z.object({ filePath: z.string().min(1) }).strict(),
50
- // Checked as a function only: wrapping it in z.function() would replace the caller's loader.
51
57
  z
52
58
  .object({
53
- load: z.custom<() => Uint8Array | Promise<Uint8Array>>(
54
- (value) => typeof value === "function",
55
- { message: "load must be a function" },
56
- ),
59
+ load: z.custom<() => Uint8Array | Promise<Uint8Array>>(isCallable, {
60
+ message: "load must be a function",
61
+ }),
57
62
  })
58
63
  .strict(),
59
64
  ]);
@@ -85,7 +90,7 @@ export function describeDeclarationIssues(error: ZodError): string {
85
90
  return error.issues
86
91
  .map((issue) => {
87
92
  const field = issue.path.join(".") || "declaration";
88
- return `${field}: ${DECLARATION_ERROR_TEXTS[issue.message] ?? issue.message}`;
93
+ return `${field}: ${DECLARATION_ERROR_TEXTS.get(issue.message) ?? issue.message}`;
89
94
  })
90
95
  .join("; ");
91
96
  }
@@ -67,13 +67,13 @@ export function describeValidationError(error: unknown): string {
67
67
  }
68
68
 
69
69
  /** Parses a request body, answering 400 with a translatable message. */
70
- export function parseBody<Schema extends z.ZodTypeAny>(
70
+ export function parseBody<Output>(
71
71
  body: unknown,
72
- schema: Schema,
73
- ): z.output<Schema> {
72
+ schema: z.ZodType<Output, z.ZodTypeDef, unknown>,
73
+ ): Output {
74
74
  return assertValidation(
75
75
  body,
76
- (value) => schema.parse(value) as z.output<Schema>,
76
+ (value) => schema.parse(value),
77
77
  describeValidationError,
78
78
  );
79
79
  }
@@ -131,7 +131,7 @@ export const assetVisibilitySchema = z.object({
131
131
  const MAX_PREVIEW_BATCH = 200;
132
132
 
133
133
  export const previewIdsSchema = z.object({
134
- ids: z.array(z.string().min(1)).max(MAX_PREVIEW_BATCH),
134
+ ids: z.array(z.string().uuid()).min(1).max(MAX_PREVIEW_BATCH),
135
135
  });
136
136
 
137
137
  const normalizedRatio = z.number().min(0).max(1);
@@ -154,7 +154,7 @@ export const transformSchema = z
154
154
  rotate: z
155
155
  .number()
156
156
  .refine((value) =>
157
- ALLOWED_ROTATIONS.includes(value as (typeof ALLOWED_ROTATIONS)[number]),
157
+ ALLOWED_ROTATIONS.some((rotation) => rotation === value),
158
158
  )
159
159
  .optional(),
160
160
  })
@@ -1,20 +0,0 @@
1
- import { readFileSync } from 'node:fs'
2
- import { join } from 'node:path'
3
- import { describe, expect, it } from 'vitest'
4
-
5
- type Manifest = { engines?: Record<string, string> }
6
-
7
- function rendererRange(dir: string): string | undefined {
8
- const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as Manifest
9
- return manifest.engines?.['@antelopejs/dms-frontend']
10
- }
11
-
12
- // `ajs dms dev` refuses to start when a frontend module's range excludes the
13
- // installed renderer, so the playground's own frontend must follow this layer.
14
- describe('renderer range', () => {
15
- it('is the same for the playground frontend as for this layer', () => {
16
- const layer = rendererRange(join(__dirname, '..'))
17
- expect(layer).toBeDefined()
18
- expect(rendererRange(join(__dirname, '../../playground/frontend-vue'))).toBe(layer)
19
- })
20
- })
@@ -1,61 +0,0 @@
1
- import { readdirSync, readFileSync, statSync } from 'node:fs'
2
- import { join } from 'node:path'
3
- import { describe, expect, it } from 'vitest'
4
-
5
- type Messages = { [key: string]: string | Messages }
6
-
7
- const LOCALES_DIR = join(__dirname, '../i18n/locales')
8
- const APP_DIR = join(__dirname, '../app')
9
- const KEY_PATTERN = /\bt\(\s*'(dms_media\.[a-z0-9_.-]+)'/g
10
- // What one line of an overview KPI card holds at four columns (183px of 12px
11
- // text at 1440px wide): a detail on two lines makes the cards taller than their
12
- // skeleton, and every block below moves when they land.
13
- const KPI_DETAIL_MAX_LENGTH = 32
14
- const KPI_DETAILS = ['files_detail', 'storage_detail', 'storage_quota_detail', 'public_share', 'missing_alt_none', 'missing_alt_public']
15
- // The widest values a detail is written with.
16
- const WIDEST_PARAMS: Record<string, string> = { files: '99,999', percent: '100', quota: '100 GB' }
17
-
18
- function load(file: string): Messages {
19
- return JSON.parse(readFileSync(join(LOCALES_DIR, file), 'utf8')) as Messages
20
- }
21
-
22
- function leaves(messages: Messages, prefix = ''): string[] {
23
- return Object.entries(messages).flatMap(([key, value]) =>
24
- typeof value === 'string' ? [`${prefix}${key}`] : leaves(value, `${prefix}${key}.`),
25
- )
26
- }
27
-
28
- function sources(dir: string): string[] {
29
- return readdirSync(dir).flatMap((entry) => {
30
- const path = join(dir, entry)
31
- if (statSync(path).isDirectory()) return sources(path)
32
- return /\.(vue|ts)$/.test(entry) ? [path] : []
33
- })
34
- }
35
-
36
- describe('media locales', () => {
37
- const english = load('media-en-GB.json')
38
- const french = load('media-fr-FR.json')
39
-
40
- it('declares the same keys in English and French', () => {
41
- expect(leaves(french).sort()).toEqual(leaves(english).sort())
42
- })
43
-
44
- it('keeps each overview KPI detail on one line of its card', () => {
45
- for (const messages of [english, french]) {
46
- const kpis = ((messages.dms_media as Messages).overview as Messages).kpis as Messages
47
- const written = KPI_DETAILS.flatMap((key) =>
48
- (kpis[key] as string).split(' | ').map((form) => form.replace(/\{(\w+)\}/g, (_, name: string) => WIDEST_PARAMS[name] ?? name)),
49
- )
50
- expect(written.filter((text) => text.length > KPI_DETAIL_MAX_LENGTH)).toEqual([])
51
- }
52
- })
53
-
54
- it('translates every literal key the layer uses', () => {
55
- const known = new Set(leaves(english))
56
- const used = sources(APP_DIR).flatMap((file) =>
57
- [...readFileSync(file, 'utf8').matchAll(KEY_PATTERN)].map((match) => match[1]!),
58
- )
59
- expect(used.filter((key) => !known.has(key))).toEqual([])
60
- })
61
- })