@antelopejs/dms-media 0.6.1 → 0.6.2

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 (196) hide show
  1. package/README.md +16 -1
  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 +86 -0
  122. package/frontend-vue/app/build/library/libraryActions.ts +444 -0
  123. package/frontend-vue/app/build/library/libraryCore.ts +136 -0
  124. package/frontend-vue/app/components/ImageEditor.vue +22 -179
  125. package/frontend-vue/app/composables/library/useMediaLibrary.ts +3 -575
  126. package/frontend-vue/app/composables/useMediaApi.ts +21 -5
  127. package/frontend-vue/build/backend-boundary.ts +122 -0
  128. package/frontend-vue/dms.frontend.build.ts +3 -0
  129. package/frontend-vue/eslint.config.mjs +13 -0
  130. package/frontend-vue/package.json +3 -1
  131. package/frontend-vue/pnpm-lock.yaml +217 -61
  132. package/frontend-vue/tests/backend-boundary.test.ts +203 -0
  133. package/frontend-vue/tests/mediaPreviews.test.ts +39 -0
  134. package/package.json +4 -10
  135. package/skills/dms-media/SKILL.md +1 -0
  136. package/skills/dms-media/cases.json +38 -0
  137. package/src/acl/entries.ts +6 -4
  138. package/src/bindings.ts +3 -3
  139. package/src/declared/folders.ts +3 -3
  140. package/src/declared/records.ts +9 -8
  141. package/src/derivatives.ts +10 -6
  142. package/src/guards.ts +19 -0
  143. package/src/library/activity.ts +17 -9
  144. package/src/library/batches.ts +12 -9
  145. package/src/library/events.ts +7 -4
  146. package/src/library/module-readout.ts +6 -2
  147. package/src/library/realtime.ts +5 -1
  148. package/src/library/zip.ts +1 -1
  149. package/src/pages/activity.ts +6 -2
  150. package/src/routes/media/assets.ts +4 -3
  151. package/src/routes/media/bulk.ts +16 -14
  152. package/src/routes/media/delivery-headers.ts +9 -12
  153. package/src/routes/media/delivery-stream.ts +3 -2
  154. package/src/routes/media/delivery.ts +4 -2
  155. package/src/routes/media/manage.ts +4 -6
  156. package/src/routes/media/transform.ts +27 -23
  157. package/src/test/antelope.test.ts +21 -17
  158. package/src/test/helpers/folders.ts +22 -0
  159. package/src/test/helpers/pages.ts +12 -5
  160. package/src/test/helpers/permissions-world.ts +326 -0
  161. package/src/test/helpers/prototype.ts +12 -0
  162. package/src/test/integration/derivative-sweep-query.test.ts +19 -21
  163. package/src/test/integration/folder-query.test.ts +11 -11
  164. package/src/test/integration/media-bindings.test.ts +7 -7
  165. package/src/test/integration/media-cleanup.test.ts +25 -37
  166. package/src/test/integration/media-declared-content.test.ts +18 -19
  167. package/src/test/integration/media-delivery-editing.test.ts +11 -7
  168. package/src/test/integration/media-delivery.test.ts +29 -8
  169. package/src/test/integration/media-explorer-writes.test.ts +2 -7
  170. package/src/test/integration/media-guards.test.ts +21 -7
  171. package/src/test/integration/media-library.test.ts +1 -1
  172. package/src/test/integration/media-linked-subfolders.test.ts +11 -20
  173. package/src/test/integration/media-member-access.test.ts +5 -9
  174. package/src/test/integration/media-permissions.test.ts +56 -570
  175. package/src/test/integration/media-project-field.test.ts +5 -7
  176. package/src/test/integration/media-search-query.test.ts +16 -20
  177. package/src/test/integration/media-storage-origin-unreachable.test.ts +3 -2
  178. package/src/test/integration/media-upload-policy.test.ts +2 -8
  179. package/src/test/integration/permissions-management.ts +292 -0
  180. package/src/test/unit/acl/entries.test.ts +2 -1
  181. package/src/test/unit/acl/resolver.test.ts +19 -7
  182. package/src/test/unit/library/fixtures.ts +9 -3
  183. package/src/test/unit/library/library.test.ts +1 -7
  184. package/src/test/unit/library/realtime.test.ts +1 -1
  185. package/src/test/unit/library/search-facets.test.ts +2 -2
  186. package/src/test/unit/pages/toolbar.test.ts +42 -17
  187. package/src/test/unit/routes/dto.test.ts +7 -6
  188. package/src/test/unit/routes/file-page.test.ts +10 -9
  189. package/src/test/unit/routes/preset-row.test.ts +2 -2
  190. package/src/transform.ts +6 -6
  191. package/src/upload-checks.ts +12 -3
  192. package/src/upload-policy.ts +8 -8
  193. package/src/validation/declared.schema.ts +17 -12
  194. package/src/validation/media.schema.ts +6 -6
  195. package/frontend-vue/tests/engines.test.ts +0 -20
  196. package/frontend-vue/tests/locales.test.ts +0 -61
@@ -0,0 +1,203 @@
1
+ import {
2
+ mkdirSync,
3
+ mkdtempSync,
4
+ realpathSync,
5
+ rmSync,
6
+ symlinkSync,
7
+ writeFileSync,
8
+ } from 'node:fs'
9
+ import { tmpdir } from 'node:os'
10
+ import { dirname, join } from 'node:path'
11
+ import { build as viteBuild, type Plugin } from 'vite'
12
+ import { afterAll, beforeAll, describe, expect, it } from 'vitest'
13
+ import { backendBoundary } from '../build/backend-boundary'
14
+
15
+ /** A scratch repository: the backend package, another package, and the frontend module inside the backend package. */
16
+ let repository: string
17
+ let frontend: string
18
+
19
+ function write(file: string, text: string): void {
20
+ mkdirSync(dirname(file), { recursive: true })
21
+ writeFileSync(file, text)
22
+ }
23
+
24
+ beforeAll(() => {
25
+ repository = realpathSync(
26
+ mkdtempSync(join(tmpdir(), 'dms-media-boundary-')),
27
+ )
28
+ const backend = join(repository, 'packages/dms-media')
29
+ frontend = join(backend, 'frontend-vue')
30
+ write(
31
+ join(backend, 'package.json'),
32
+ JSON.stringify({ name: '@antelopejs/dms-media' }),
33
+ )
34
+ write(join(backend, 'src/backend.ts'), 'export const secret = 1\n')
35
+ write(join(backend, 'src/nested/deep.ts'), 'export const deep = 6\n')
36
+ write(join(backend, 'dist/built.js'), 'export const built = 2\n')
37
+ write(join(backend, 'dist/src/nested.js'), 'export const nested = 4\n')
38
+ write(join(backend, 'srcx/sibling.ts'), 'export const sibling = 5\n')
39
+ write(
40
+ join(repository, 'packages/other/package.json'),
41
+ JSON.stringify({ name: 'other' }),
42
+ )
43
+ write(
44
+ join(repository, 'packages/other/src/shared.ts'),
45
+ 'export const shared = 3\n',
46
+ )
47
+ mkdirSync(frontend, { recursive: true })
48
+ symlinkSync(join(backend, 'src/backend.ts'), join(frontend, 'linked.ts'))
49
+ })
50
+
51
+ afterAll(() => {
52
+ rmSync(repository, { recursive: true, force: true })
53
+ })
54
+
55
+ interface BuildOptions {
56
+ extra?: Plugin[]
57
+ alias?: Record<string, string>
58
+ preserveSymlinks?: boolean
59
+ external?: string[]
60
+ }
61
+
62
+ /** Builds a frontend entry made of `source` with the boundary plugin, and returns the bundled code. */
63
+ async function build(
64
+ source: string,
65
+ options: BuildOptions = {},
66
+ ): Promise<string> {
67
+ write(join(frontend, 'entry.ts'), source)
68
+ const result = await viteBuild({
69
+ root: frontend,
70
+ configFile: false,
71
+ logLevel: 'silent',
72
+ plugins: [backendBoundary(), ...(options.extra ?? [])],
73
+ resolve: {
74
+ alias: options.alias ?? {},
75
+ preserveSymlinks: options.preserveSymlinks ?? false,
76
+ },
77
+ build: {
78
+ write: false,
79
+ rollupOptions: { external: options.external ?? [] },
80
+ lib: { entry: join(frontend, 'entry.ts'), formats: ['es'] },
81
+ },
82
+ })
83
+ return JSON.stringify(result)
84
+ }
85
+
86
+ /** A plugin that answers the import `request` with the module id `id`. */
87
+ function resolver(request: string, id: string): Plugin {
88
+ return {
89
+ name: 'test-resolver',
90
+ resolveId: (source) => (source === request ? { id } : null),
91
+ load: (loaded) =>
92
+ loaded === id || loaded.startsWith('\0') ? 'export default 1\n' : null,
93
+ }
94
+ }
95
+
96
+ const backendFile = () =>
97
+ join(repository, 'packages/dms-media/src/backend.ts')
98
+
99
+ describe('the backend boundary of the frontend build', () => {
100
+ it('fails on an import of the backend source, naming both files', async () => {
101
+ const failure = build(
102
+ 'import { secret } from "../src/backend.ts"\nexport { secret }\n',
103
+ )
104
+ await expect(failure).rejects.toThrow(/Backend boundary/)
105
+ await expect(failure).rejects.toThrow(join(frontend, 'entry.ts'))
106
+ await expect(failure).rejects.toThrow(backendFile())
107
+ })
108
+
109
+ it('fails on a file deeper under the backend source', async () => {
110
+ await expect(
111
+ build('import { deep } from "../src/nested/deep.ts"\nexport { deep }\n'),
112
+ ).rejects.toThrow(/Backend boundary/)
113
+ })
114
+
115
+ it('fails on an alias that points into the backend source', async () => {
116
+ await expect(
117
+ build(
118
+ 'import { secret } from "@backend/backend.ts"\nexport { secret }\n',
119
+ {
120
+ alias: { '@backend': join(repository, 'packages/dms-media/src') },
121
+ },
122
+ ),
123
+ ).rejects.toThrow(/Backend boundary/)
124
+ })
125
+
126
+ it('fails on a symlink to the backend source that the resolver returns', async () => {
127
+ await expect(
128
+ build('import { secret } from "./linked.ts"\nexport { secret }\n', {
129
+ extra: [resolver('./linked.ts', join(frontend, 'linked.ts'))],
130
+ preserveSymlinks: true,
131
+ }),
132
+ ).rejects.toThrow(/Backend boundary/)
133
+ })
134
+
135
+ it('fails on an id that names the backend source with a query or a hash', async () => {
136
+ for (const suffix of ['?raw', '#fragment']) {
137
+ await expect(
138
+ build('import secret from "virtual-backend"\nexport { secret }\n', {
139
+ extra: [resolver('virtual-backend', `${backendFile()}${suffix}`)],
140
+ }),
141
+ ).rejects.toThrow(/Backend boundary/)
142
+ }
143
+ })
144
+
145
+ it('fails on a backend source import declared external', async () => {
146
+ await expect(
147
+ build('import { secret } from "../src/backend.ts"\nexport { secret }\n', {
148
+ external: [backendFile()],
149
+ }),
150
+ ).rejects.toThrow(/Backend boundary/)
151
+ })
152
+
153
+ it('fails on a worker entry under the backend source', async () => {
154
+ await expect(
155
+ build(
156
+ 'export const worker = new Worker(new URL("../src/backend.ts", import.meta.url), { type: "module" })\n',
157
+ ),
158
+ ).rejects.toThrow(/Backend boundary/)
159
+ })
160
+
161
+ it('fails on a worker of the frontend that imports the backend source', async () => {
162
+ write(
163
+ join(frontend, 'worker.ts'),
164
+ 'import { secret } from "../src/backend.ts"\npostMessage(secret)\n',
165
+ )
166
+ await expect(
167
+ build(
168
+ 'export const worker = new Worker(new URL("./worker.ts", import.meta.url), { type: "module" })\n',
169
+ ),
170
+ ).rejects.toThrow(/Backend boundary/)
171
+ })
172
+
173
+ it('passes the built output, a virtual module and the source of another package', async () => {
174
+ expect(
175
+ await build(
176
+ 'import { built } from "../dist/built.js"\nexport { built }\n',
177
+ ),
178
+ ).toMatch(/built/)
179
+ expect(
180
+ await build('import value from "virtual:thing"\nexport { value }\n', {
181
+ extra: [resolver('virtual:thing', '\0virtual:thing')],
182
+ }),
183
+ ).toMatch(/value/)
184
+ expect(
185
+ await build(
186
+ 'import { shared } from "../../other/src/shared.ts"\nexport { shared }\n',
187
+ ),
188
+ ).toMatch(/shared/)
189
+ })
190
+
191
+ it('passes a sibling folder named like src and a src folder inside dist', async () => {
192
+ expect(
193
+ await build(
194
+ 'import { sibling } from "../srcx/sibling.ts"\nexport { sibling }\n',
195
+ ),
196
+ ).toMatch(/sibling/)
197
+ expect(
198
+ await build(
199
+ 'import { nested } from "../dist/src/nested.js"\nexport { nested }\n',
200
+ ),
201
+ ).toMatch(/nested/)
202
+ })
203
+ })
@@ -0,0 +1,39 @@
1
+ import { afterEach, expect, it, vi } from 'vitest'
2
+ import { useMediaApi } from '../app/composables/useMediaApi'
3
+
4
+ interface PreviewRequest {
5
+ method: string
6
+ query: { ids: string[] }
7
+ }
8
+
9
+ afterEach(() => vi.unstubAllGlobals())
10
+
11
+ it('reads 150 previews in GET batches of 100 and 50 and merges both responses', async () => {
12
+ const ids = Array.from(
13
+ { length: 150 },
14
+ (_, index) => `00000000-0000-4000-8000-${String(index).padStart(12, '0')}`,
15
+ )
16
+ const authFetch = vi.fn((_url: string, request: PreviewRequest) =>
17
+ Promise.resolve({
18
+ previews: Object.fromEntries(
19
+ request.query.ids.map((id) => [id, `https://media.test/${id}`]),
20
+ ),
21
+ }),
22
+ )
23
+ vi.stubGlobal('useAuthFetch', () => ({ $authFetch: authFetch }))
24
+
25
+ const result = await useMediaApi().previews(ids)
26
+
27
+ expect(authFetch).toHaveBeenCalledTimes(2)
28
+ expect(authFetch).toHaveBeenNthCalledWith(1, '/api/media/previews', {
29
+ method: 'GET',
30
+ query: { ids: ids.slice(0, 100) },
31
+ })
32
+ expect(authFetch).toHaveBeenNthCalledWith(2, '/api/media/previews', {
33
+ method: 'GET',
34
+ query: { ids: ids.slice(100) },
35
+ })
36
+ expect(result.previews).toEqual(
37
+ Object.fromEntries(ids.map((id) => [id, `https://media.test/${id}`])),
38
+ )
39
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/dms-media",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Media library for the AntelopeJS DMS: uploads, folders with per-folder permissions, image sizes and light editing, with a Finder-style explorer.",
5
5
  "keywords": [
6
6
  "antelopejs",
@@ -47,10 +47,7 @@
47
47
  "dev:frontend": "pnpm frontend:dev",
48
48
  "frontend:dev": "cd playground && pnpm frontend:dev",
49
49
  "dev": "ajs project run -w -p playground",
50
- "lint:fix": "oxlint --fix --max-warnings=1000000 && oxfmt . && pnpm --dir frontend-vue lint:fix",
51
- "lint": "oxlint && oxfmt --check . && pnpm --dir frontend-vue lint && antelopejs-check-interface-ranges",
52
- "typecheck": "tsc --noEmit",
53
- "format": "oxfmt . && pnpm --dir frontend-vue format",
50
+ "typecheck": "pnpm --filter @antelopejs/interface-dms-media build && tsc --noEmit",
54
51
  "test": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && ajs module test .",
55
52
  "test:unit": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && DMS_MEDIA_TEST_DIR=dist/test/unit ajs module test .",
56
53
  "test:integration": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && DMS_MEDIA_TEST_DIR=dist/test/integration ajs module test .",
@@ -78,8 +75,8 @@
78
75
  "devDependencies": {
79
76
  "@antelopejs/core": ">=1.17.1 <2",
80
77
  "@antelopejs/dms": ">=0.11.0 <1.0.0",
81
- "@antelopejs/dms-frontend": "0.9.0",
82
- "@antelopejs/tooling-configs": ">=0.0.9 <1.0.0",
78
+ "@antelopejs/dms-frontend": "0.9.1",
79
+ "@antelopejs/tooling-configs": "^0.2.12",
83
80
  "@types/chai": "^4.3.20",
84
81
  "@types/mocha": "^10",
85
82
  "@types/node": "^24.0.0",
@@ -88,9 +85,6 @@
88
85
  "chai": "^4.5.0",
89
86
  "knip": "^6.34.0",
90
87
  "mongodb-memory-server-core": "^11.0.1",
91
- "oxfmt": "^0.66.0",
92
- "oxlint": "1.81.0",
93
- "oxlint-tsgolint": "^7.0.2001",
94
88
  "release-it": "^19.2.4",
95
89
  "release-it-changelogen": "^0.1.0",
96
90
  "rimraf": "^6.1.3",
@@ -32,6 +32,7 @@ Every data block carries `realtimeTopic: MEDIA_LIBRARY_TOPIC`; custom components
32
32
  Put the field in a DMS `Form` block of a backend-declared page; no custom Vue is needed.
33
33
 
34
34
  ```typescript
35
+ import { Form } from "@antelopejs/interface-dms/base";
35
36
  import { AssetType } from "@antelopejs/interface-dms-media"; // in the module's dependencies
36
37
 
37
38
  static form = Form({
@@ -0,0 +1,38 @@
1
+ {
2
+ "version": 1,
3
+ "cases": [
4
+ {
5
+ "id": "media-image-field",
6
+ "area": "modules",
7
+ "style": "clean",
8
+ "prompt": "Add an image upload field for the product photos in the product form.",
9
+ "expect": {
10
+ "skills": ["dms-media"],
11
+ "acceptable": ["dms-pages", "dms", "dms-best-practices"],
12
+ "mustMention": ["AssetType"]
13
+ }
14
+ },
15
+ {
16
+ "id": "media-upload-refused-casual",
17
+ "area": "modules",
18
+ "style": "casual",
19
+ "prompt": "uploads get refused on the media folder, cors maybe?",
20
+ "expect": {
21
+ "skills": ["dms-media"],
22
+ "acceptable": ["dms"]
23
+ }
24
+ },
25
+ {
26
+ "id": "dms-media-avoid-form-page",
27
+ "area": "modules",
28
+ "style": "clean",
29
+ "prompt": "Build an articles admin page with a Form block for the title and body and a TableView listing the articles.",
30
+ "expect": {
31
+ "skills": ["dms-pages"],
32
+ "acceptable": ["dms-best-practices", "dms"],
33
+ "mustMention": ["RegisterPage", "TableView"],
34
+ "avoid": ["dms-media"]
35
+ }
36
+ }
37
+ ]
38
+ }
@@ -2,15 +2,17 @@ import { Logging } from "@antelopejs/interface-core/logging";
2
2
  import type { MediaFolder } from "../db/tables";
3
3
  import type { AclEntry } from "../types";
4
4
 
5
- /** Fails closed: an unreadable stored ACL grants nothing instead of inheriting. */
5
+ /**
6
+ * Fails closed: an unreadable stored ACL grants nothing instead of inheriting.
7
+ * A stored ACL that is not JSON is handled like one that is not an array:
8
+ * logged, then read as empty.
9
+ */
6
10
  export function parseFolderAcl(folder: MediaFolder): AclEntry[] | undefined {
7
11
  if (!folder.json_acl) return undefined;
8
12
  try {
9
13
  const parsed = JSON.parse(folder.json_acl);
10
14
  if (Array.isArray(parsed)) return parsed as AclEntry[];
11
- } catch {
12
- // Handled below with the non-array case.
13
- }
15
+ } catch {}
14
16
  Logging.Warn(
15
17
  `Media folder '${folder._id}' has an unreadable ACL; treating it as empty.`,
16
18
  );
package/src/bindings.ts CHANGED
@@ -149,9 +149,9 @@ async function provisionTenant(
149
149
  if (registeredBindings.size > 0) {
150
150
  const folders = await folderModel.getAll();
151
151
  const foldersByBinding = new Map(
152
- folders
153
- .filter((folder) => folder.binding)
154
- .map((folder) => [folder.binding as string, folder]),
152
+ folders.flatMap((folder): [string, MediaFolder][] =>
153
+ folder.binding ? [[folder.binding, folder]] : [],
154
+ ),
155
155
  );
156
156
  const contentRootId = await ensureContentRoot(
157
157
  folderModel,
@@ -21,12 +21,13 @@ import {
21
21
  settlePendingDeclaration,
22
22
  withDeclarationLock,
23
23
  } from "./records";
24
+ import { isString } from "../guards";
24
25
 
25
26
  type ParentTarget = NonNullable<DeclaredFolderInput["parent"]>;
26
27
 
27
28
  /** The declared folder key a parent names, written as a string or as `{ key }`. */
28
29
  function parentKeyOf(parent: ParentTarget | undefined): string | undefined {
29
- if (typeof parent === "string") return parent;
30
+ if (isString(parent)) return parent;
30
31
  return parent && "key" in parent ? parent.key : undefined;
31
32
  }
32
33
 
@@ -70,8 +71,7 @@ async function findParentFolder(
70
71
  parent: ParentTarget,
71
72
  fail: (reason: string) => never,
72
73
  ): Promise<MediaFolder> {
73
- if (typeof parent === "string")
74
- return findDeclaredFolder(models, parent, fail);
74
+ if (isString(parent)) return findDeclaredFolder(models, parent, fail);
75
75
  if ("key" in parent) return findDeclaredFolder(models, parent.key, fail);
76
76
  const { binding } = parent;
77
77
  const folder = await findBoundFolder(models, binding, fail);
@@ -1,5 +1,6 @@
1
1
  import { GetModel } from "@antelopejs/interface-database-decorators";
2
- import type { ZodError, ZodType } from "zod";
2
+ import type { ZodType, ZodTypeDef } from "zod";
3
+ import { isObjectLike, isString } from "../guards";
3
4
  import {
4
5
  MediaAssetModel,
5
6
  type MediaDeclarationKind,
@@ -45,18 +46,18 @@ export function declaredModels(tenantId: string): DeclaredModels {
45
46
  }
46
47
 
47
48
  /** Validates a declaration, naming every refused field. */
48
- export function parseDeclaration<Schema extends ZodType>(
49
+ export function parseDeclaration<Output>(
49
50
  kind: MediaDeclarationKind,
50
51
  input: unknown,
51
- schema: Schema,
52
- ): ReturnType<Schema["parse"]> {
52
+ schema: ZodType<Output, ZodTypeDef, unknown>,
53
+ ): Output {
53
54
  const parsed = schema.safeParse(input);
54
- if (parsed.success) return parsed.data as ReturnType<Schema["parse"]>;
55
- const key = (input as { key?: unknown } | undefined)?.key;
55
+ if (parsed.success) return parsed.data;
56
+ const key = isObjectLike(input) && "key" in input ? input.key : undefined;
56
57
  throw new MediaDeclarationError(
57
58
  kind,
58
- typeof key === "string" ? key : "?",
59
- describeDeclarationIssues(parsed.error as ZodError),
59
+ isString(key) ? key : "?",
60
+ describeDeclarationIssues(parsed.error),
60
61
  );
61
62
  }
62
63
 
@@ -32,7 +32,8 @@ export class UnreadableImageError extends Error {}
32
32
 
33
33
  interface GenerationFailure {
34
34
  failedAt: number;
35
- error: unknown;
35
+ /** Set when the stored bytes could not be decoded: that error is rethrown while the failure is remembered. */
36
+ unreadable?: UnreadableImageError;
36
37
  }
37
38
 
38
39
  const generationLocks = new Map<string, Promise<string>>();
@@ -241,15 +242,15 @@ export function partitionDerivatives(
241
242
  return { fresh, stale };
242
243
  }
243
244
 
244
- function failureRetryDelay(error: unknown): number {
245
- return error instanceof UnreadableImageError
245
+ function failureRetryDelay(failure: GenerationFailure): number {
246
+ return failure.unreadable
246
247
  ? UNREADABLE_IMAGE_RETRY_MS
247
248
  : GENERATION_FAILURE_RETRY_MS;
248
249
  }
249
250
 
250
251
  function pruneExpiredGenerationFailures(now: number): void {
251
252
  for (const [lockKey, failure] of generationFailures) {
252
- if (now - failure.failedAt >= failureRetryDelay(failure.error)) {
253
+ if (now - failure.failedAt >= failureRetryDelay(failure)) {
253
254
  generationFailures.delete(lockKey);
254
255
  }
255
256
  }
@@ -259,7 +260,7 @@ function assertNoRecentGenerationFailure(lockKey: string): void {
259
260
  pruneExpiredGenerationFailures(Date.now());
260
261
  const failure = generationFailures.get(lockKey);
261
262
  if (!failure) return;
262
- if (failure.error instanceof UnreadableImageError) throw failure.error;
263
+ if (failure.unreadable) throw failure.unreadable;
263
264
  throw new Error("Derivative generation recently failed");
264
265
  }
265
266
 
@@ -284,7 +285,10 @@ export async function ensureDerivative(
284
285
  return storageKey;
285
286
  })
286
287
  .catch((error: unknown) => {
287
- generationFailures.set(lockKey, { failedAt: Date.now(), error });
288
+ generationFailures.set(lockKey, {
289
+ failedAt: Date.now(),
290
+ unreadable: error instanceof UnreadableImageError ? error : undefined,
291
+ });
288
292
  throw error;
289
293
  })
290
294
  .finally(() => generationLocks.delete(lockKey));
package/src/guards.ts ADDED
@@ -0,0 +1,19 @@
1
+ /** Whether `value` is a string. */
2
+ export function isString(value: unknown): value is string {
3
+ return typeof value === "string";
4
+ }
5
+
6
+ /** Whether `value` is a non-null object, arrays included. */
7
+ export function isObject(value: unknown): value is object {
8
+ return typeof value === "object" && value !== null;
9
+ }
10
+
11
+ /** Whether `value` can carry properties of its own: a non-null object or a function. */
12
+ export function isObjectLike(value: unknown): value is object {
13
+ return isObject(value) || isCallable(value);
14
+ }
15
+
16
+ /** Whether `typeof` reports `value` as a function: classes included, as TypeScript narrows it. */
17
+ export function isCallable(value: unknown): value is Function {
18
+ return typeof value === "function";
19
+ }
@@ -1,5 +1,4 @@
1
1
  import type { ActivityFeedItem } from "@antelopejs/interface-dms/base/activity-feed";
2
- import type { ComposedTextParam } from "@antelopejs/interface-dms/base/types";
3
2
  import type { Tone } from "@antelopejs/interface-dms/base/types/tone";
4
3
  import type { MediaEvent, MediaFolder } from "../db";
5
4
  import { countParam } from "./composed-text";
@@ -67,6 +66,11 @@ const EVENT_PRESENTATIONS: Record<MediaEventKind, EventPresentation> = {
67
66
  "folder.visibility": { icon: "i-ph-globe", tone: "success" },
68
67
  };
69
68
 
69
+ /** Whether a stored event kind is one this release records and presents. */
70
+ function isMediaEventKind(kind: string): kind is MediaEventKind {
71
+ return Object.hasOwn(EVENT_PRESENTATIONS, kind);
72
+ }
73
+
70
74
  const NEUTRAL_PRESENTATION: EventPresentation = {
71
75
  icon: "i-ph-clock-counter-clockwise",
72
76
  tone: "neutral",
@@ -163,9 +167,12 @@ function visibleDetails(details: MediaEventDetails): MediaEventDetails {
163
167
  );
164
168
  }
165
169
 
166
- function toParams(entry: ActivityEntry): Record<string, ComposedTextParam> {
170
+ /** The parameters of a feed item's title and meta texts. */
171
+ type FeedParams = NonNullable<ActivityFeedItem["params"]>;
172
+
173
+ function toParams(entry: ActivityEntry): FeedParams {
167
174
  const details = visibleDetails(readEventDetails(entry.event));
168
- const params: Record<string, ComposedTextParam> = {
175
+ const params: FeedParams = {
169
176
  actor: entry.event.actorName,
170
177
  name: entry.event.targetName,
171
178
  count: countParam(entry.count),
@@ -186,7 +193,7 @@ function titleSuffix(event: MediaEvent): string {
186
193
  return `_${visibility.replace(VISIBILITY_KEY_PREFIX, "")}`;
187
194
  }
188
195
 
189
- function batchParams(event: MediaEvent): Record<string, ComposedTextParam> {
196
+ function batchParams(event: MediaEvent): FeedParams {
190
197
  const details = readEventDetails(event);
191
198
  return {
192
199
  uploaded: countParam(event.count ?? 0),
@@ -200,11 +207,12 @@ function presentEntry(
200
207
  context: ActivityContext,
201
208
  ): ActivityFeedItem {
202
209
  const { event } = entry;
203
- const kind = event.kind as MediaEventKind;
210
+ const { kind } = event;
211
+ const known = isMediaEventKind(kind) ? kind : undefined;
204
212
  const isReport = kind === BATCH_REPORT_KIND;
205
213
  const presentation = isReport
206
214
  ? BATCH_PRESENTATIONS[batchOutcome(event)]
207
- : (EVENT_PRESENTATIONS[kind] ?? NEUTRAL_PRESENTATION);
215
+ : ((known && EVENT_PRESENTATIONS[known]) ?? NEUTRAL_PRESENTATION);
208
216
  const path = folderPath(subjectFolderId(event), context.foldersById);
209
217
  const isGone = Boolean(
210
218
  event.assetId && context.deletedAssetIds.has(event.assetId),
@@ -300,9 +308,9 @@ function foldBulkActions(entries: ActivityEntry[]): ActivityEntry[] {
300
308
 
301
309
  function deletedAssets(events: MediaEvent[]): Set<string> {
302
310
  return new Set(
303
- events
304
- .filter((event) => event.kind === "asset.delete" && event.assetId)
305
- .map((event) => event.assetId as string),
311
+ events.flatMap((event) =>
312
+ event.kind === "asset.delete" && event.assetId ? [event.assetId] : [],
313
+ ),
306
314
  );
307
315
  }
308
316
 
@@ -8,6 +8,8 @@ import {
8
8
  readEventDetails,
9
9
  UPLOAD_KIND,
10
10
  } from "./events";
11
+ import { z } from "zod";
12
+ import { isString } from "../guards";
11
13
 
12
14
  export interface UploadBatchRow {
13
15
  _id: string;
@@ -33,10 +35,11 @@ type BatchAttention = "yes" | "no";
33
35
  /** How long a failed upload keeps asking for attention. */
34
36
  export const FAILURE_WINDOW_MS = 24 * 60 * 60 * 1000;
35
37
 
36
- interface UploadFailure {
37
- name: string;
38
- reason?: string;
39
- }
38
+ const uploadFailuresSchema = z.array(
39
+ z.object({ name: z.string(), reason: z.string().optional() }),
40
+ );
41
+
42
+ type UploadFailures = z.infer<typeof uploadFailuresSchema>;
40
43
 
41
44
  const HISTORY_TEXTS = "dms_media.uploads.history";
42
45
  const FAILURES_SHOWN = 3;
@@ -51,7 +54,7 @@ interface BatchAccumulator {
51
54
  by: string;
52
55
  files: number;
53
56
  failed: number;
54
- failures: UploadFailure[];
57
+ failures: UploadFailures;
55
58
  size: number;
56
59
  finishedAt: Date;
57
60
  reportedAt?: Date;
@@ -71,12 +74,12 @@ function newBatch(key: string, event: MediaEvent): BatchAccumulator {
71
74
  }
72
75
 
73
76
  /** The files a batch report names as failed, with their reasons. */
74
- function readBatchFailures(event: MediaEvent): UploadFailure[] {
77
+ function readBatchFailures(event: MediaEvent): UploadFailures {
75
78
  const raw = readEventDetails(event).failures;
76
- if (typeof raw !== "string") return [];
79
+ if (!isString(raw)) return [];
77
80
  try {
78
- const parsed: unknown = JSON.parse(raw);
79
- return Array.isArray(parsed) ? (parsed as UploadFailure[]) : [];
81
+ const parsed = uploadFailuresSchema.safeParse(JSON.parse(raw));
82
+ return parsed.success ? parsed.data : [];
80
83
  } catch {
81
84
  return [];
82
85
  }
@@ -2,6 +2,7 @@ import { GetModel } from "@antelopejs/interface-database-decorators";
2
2
  import { Logging } from "@antelopejs/interface-core/logging";
3
3
  import type { User } from "@antelopejs/interface-dms/auth/db";
4
4
  import { type MediaEvent, MediaEventModel } from "../db";
5
+ import { z } from "zod";
5
6
  import { announceLibraryChange, UPLOAD_ANNOUNCE_WINDOW_MS } from "./realtime";
6
7
 
7
8
  const MEDIA_EVENT_KINDS = [
@@ -25,6 +26,10 @@ export type MediaEventKind = (typeof MEDIA_EVENT_KINDS)[number];
25
26
 
26
27
  export type MediaEventDetails = Record<string, string | number>;
27
28
 
29
+ const eventDetailsSchema: z.ZodType<MediaEventDetails> = z.record(
30
+ z.union([z.string(), z.number()]),
31
+ );
32
+
28
33
  export interface MediaEventInput {
29
34
  kind: MediaEventKind;
30
35
  targetName: string;
@@ -77,10 +82,8 @@ export async function recordMediaEvent(
77
82
  export function readEventDetails(event: MediaEvent): MediaEventDetails {
78
83
  if (!event.json_details) return {};
79
84
  try {
80
- const parsed: unknown = JSON.parse(event.json_details);
81
- return parsed && typeof parsed === "object"
82
- ? (parsed as MediaEventDetails)
83
- : {};
85
+ const parsed = eventDetailsSchema.safeParse(JSON.parse(event.json_details));
86
+ return parsed.success ? parsed.data : {};
84
87
  } catch {
85
88
  return {};
86
89
  }
@@ -13,6 +13,7 @@ import { loadAssetsInFolders } from "./listing";
13
13
  import { storedSize } from "./overview";
14
14
  import { isDescribableImage } from "./type-groups";
15
15
  import { loadUploadHistoryEvents } from "./upload-history";
16
+ import { isObject, isString } from "../guards";
16
17
 
17
18
  const TEXTS = "$dms_media.readout";
18
19
  const DEFAULT_LANGUAGE = "en";
@@ -38,8 +39,11 @@ export function readModuleVersion(): string | undefined {
38
39
  const manifest: unknown = JSON.parse(
39
40
  readFileSync(PACKAGE_MANIFEST, "utf8"),
40
41
  );
41
- const version = (manifest as Record<string, unknown>).version;
42
- return typeof version === "string" ? version : undefined;
42
+ const version =
43
+ isObject(manifest) && "version" in manifest
44
+ ? manifest.version
45
+ : undefined;
46
+ return isString(version) ? version : undefined;
43
47
  } catch {
44
48
  return undefined;
45
49
  }