arocapi 5.0.0-beta.1 → 5.0.0-beta.10

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 (234) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +37 -802
  3. package/dist/app.d.ts +38 -20
  4. package/dist/app.js +62 -40
  5. package/dist/app.js.map +1 -1
  6. package/dist/routes/capabilities.d.ts +7 -0
  7. package/dist/routes/capabilities.js +13 -0
  8. package/dist/routes/capabilities.js.map +1 -0
  9. package/dist/routes/entities.d.ts +5 -2
  10. package/dist/routes/entities.js +37 -57
  11. package/dist/routes/entities.js.map +1 -1
  12. package/dist/routes/entity.d.ts +7 -2
  13. package/dist/routes/entity.js +13 -29
  14. package/dist/routes/entity.js.map +1 -1
  15. package/dist/routes/file.d.ts +8 -2
  16. package/dist/routes/file.js +37 -72
  17. package/dist/routes/file.js.map +1 -1
  18. package/dist/routes/files.d.ts +5 -2
  19. package/dist/routes/files.js +24 -39
  20. package/dist/routes/files.js.map +1 -1
  21. package/dist/routes/metadata.d.ts +11 -5
  22. package/dist/routes/metadata.js +24 -68
  23. package/dist/routes/metadata.js.map +1 -1
  24. package/dist/routes/search.d.ts +8 -7
  25. package/dist/routes/search.js +90 -119
  26. package/dist/routes/search.js.map +1 -1
  27. package/dist/search/advanced.d.ts +8 -0
  28. package/dist/search/advanced.js +198 -0
  29. package/dist/search/advanced.js.map +1 -0
  30. package/dist/search/backend.d.ts +95 -0
  31. package/dist/search/backend.js +5 -0
  32. package/dist/search/backend.js.map +1 -0
  33. package/dist/search/fields.d.ts +63 -0
  34. package/dist/search/fields.js +203 -0
  35. package/dist/search/fields.js.map +1 -0
  36. package/dist/search/opensearch/advanced.d.ts +4 -0
  37. package/dist/search/opensearch/advanced.js +28 -0
  38. package/dist/search/opensearch/advanced.js.map +1 -0
  39. package/dist/search/opensearch/opensearch.d.ts +16 -0
  40. package/dist/search/opensearch/opensearch.js +187 -0
  41. package/dist/search/opensearch/opensearch.js.map +1 -0
  42. package/dist/search/opensearch/visibility.d.ts +3 -0
  43. package/dist/search/opensearch/visibility.js +27 -0
  44. package/dist/search/opensearch/visibility.js.map +1 -0
  45. package/dist/search/postgres/advanced.d.ts +7 -0
  46. package/dist/search/postgres/advanced.js +54 -0
  47. package/dist/search/postgres/advanced.js.map +1 -0
  48. package/dist/search/postgres/facets.d.ts +2 -0
  49. package/dist/search/postgres/facets.js +27 -0
  50. package/dist/search/postgres/facets.js.map +1 -0
  51. package/dist/search/postgres/geo.d.ts +6 -0
  52. package/dist/search/postgres/geo.js +42 -0
  53. package/dist/search/postgres/geo.js.map +1 -0
  54. package/dist/search/postgres/postgres.d.ts +19 -0
  55. package/dist/search/postgres/postgres.js +157 -0
  56. package/dist/search/postgres/postgres.js.map +1 -0
  57. package/dist/search/postgres/values.d.ts +8 -0
  58. package/dist/search/postgres/values.js +20 -0
  59. package/dist/search/postgres/values.js.map +1 -0
  60. package/dist/search/postgres/visibility.d.ts +4 -0
  61. package/dist/search/postgres/visibility.js +38 -0
  62. package/dist/search/postgres/visibility.js.map +1 -0
  63. package/dist/search/requestFilters.d.ts +39 -0
  64. package/dist/search/requestFilters.js +125 -0
  65. package/dist/search/requestFilters.js.map +1 -0
  66. package/dist/search/visibility.d.ts +51 -0
  67. package/dist/search/visibility.js +100 -0
  68. package/dist/search/visibility.js.map +1 -0
  69. package/dist/storage/backend.d.ts +58 -0
  70. package/dist/storage/backend.js +2 -0
  71. package/dist/storage/backend.js.map +1 -0
  72. package/dist/storage/deliver.d.ts +12 -0
  73. package/dist/storage/deliver.js +34 -0
  74. package/dist/storage/deliver.js.map +1 -0
  75. package/dist/storage/directory/directory.d.ts +6 -0
  76. package/dist/storage/directory/directory.js +24 -0
  77. package/dist/storage/directory/directory.js.map +1 -0
  78. package/dist/storage/entity-meta/entity-meta.d.ts +5 -0
  79. package/dist/storage/entity-meta/entity-meta.js +14 -0
  80. package/dist/storage/entity-meta/entity-meta.js.map +1 -0
  81. package/dist/storage/location.d.ts +19 -0
  82. package/dist/storage/location.js +36 -0
  83. package/dist/storage/location.js.map +1 -0
  84. package/dist/storage/ocfl/ocfl.d.ts +6 -0
  85. package/dist/storage/ocfl/ocfl.js +45 -0
  86. package/dist/storage/ocfl/ocfl.js.map +1 -0
  87. package/dist/storage/results.d.ts +7 -0
  88. package/dist/storage/results.js +22 -0
  89. package/dist/storage/results.js.map +1 -0
  90. package/dist/storage/s3/s3.d.ts +10 -0
  91. package/dist/storage/s3/s3.js +47 -0
  92. package/dist/storage/s3/s3.js.map +1 -0
  93. package/dist/transformers/default.d.ts +11 -22
  94. package/dist/transformers/default.js +41 -15
  95. package/dist/transformers/default.js.map +1 -1
  96. package/dist/types/access.d.ts +9 -0
  97. package/dist/types/access.js +2 -0
  98. package/dist/types/access.js.map +1 -0
  99. package/dist/types/context.d.ts +6 -0
  100. package/dist/types/context.js +2 -0
  101. package/dist/types/context.js.map +1 -0
  102. package/dist/types/transformers.d.ts +4 -10
  103. package/dist/types/visibility.d.ts +6 -0
  104. package/dist/types/visibility.js +2 -0
  105. package/dist/types/visibility.js.map +1 -0
  106. package/dist/utils/access.d.ts +17 -0
  107. package/dist/utils/access.js +41 -0
  108. package/dist/utils/access.js.map +1 -0
  109. package/dist/utils/errors.d.ts +19 -10
  110. package/dist/utils/errors.js +44 -8
  111. package/dist/utils/errors.js.map +1 -1
  112. package/dist/utils/headers.d.ts +1 -1
  113. package/dist/utils/headers.js +10 -1
  114. package/dist/utils/headers.js.map +1 -1
  115. package/dist/utils/validation.d.ts +2 -0
  116. package/dist/utils/validation.js +8 -0
  117. package/dist/utils/validation.js.map +1 -0
  118. package/dist/utils/visibility.d.ts +18 -0
  119. package/dist/utils/visibility.js +16 -0
  120. package/dist/utils/visibility.js.map +1 -0
  121. package/package.json +82 -40
  122. package/prisma/models/entity.prisma +9 -8
  123. package/prisma/models/entitySearch.prisma +21 -0
  124. package/prisma/models/file.prisma +3 -3
  125. package/src/app.ts +168 -95
  126. package/src/routes/capabilities.ts +22 -0
  127. package/src/routes/entities.ts +48 -67
  128. package/src/routes/entity.ts +21 -35
  129. package/src/routes/file.ts +53 -103
  130. package/src/routes/files.ts +31 -47
  131. package/src/routes/metadata.ts +42 -98
  132. package/src/routes/search.ts +131 -151
  133. package/src/search/advanced.ts +258 -0
  134. package/src/search/backend.ts +91 -0
  135. package/src/search/fields.ts +320 -0
  136. package/src/search/opensearch/advanced.ts +36 -0
  137. package/src/search/opensearch/opensearch.ts +290 -0
  138. package/src/search/opensearch/visibility.ts +38 -0
  139. package/src/search/postgres/advanced.ts +76 -0
  140. package/src/search/postgres/facets.ts +34 -0
  141. package/src/search/postgres/geo.ts +58 -0
  142. package/src/search/postgres/postgres.ts +232 -0
  143. package/src/search/postgres/values.ts +33 -0
  144. package/src/search/postgres/visibility.ts +54 -0
  145. package/src/search/requestFilters.ts +178 -0
  146. package/src/search/visibility.ts +193 -0
  147. package/src/storage/backend.ts +75 -0
  148. package/src/storage/deliver.ts +65 -0
  149. package/src/storage/directory/directory.ts +39 -0
  150. package/src/storage/entity-meta/entity-meta.ts +25 -0
  151. package/src/storage/location.ts +78 -0
  152. package/src/storage/ocfl/ocfl.ts +71 -0
  153. package/src/storage/results.ts +32 -0
  154. package/src/storage/s3/s3.ts +79 -0
  155. package/src/transformers/default.ts +115 -85
  156. package/src/types/access.ts +25 -0
  157. package/src/types/context.ts +15 -0
  158. package/src/types/transformers.ts +8 -34
  159. package/src/types/visibility.ts +21 -0
  160. package/src/utils/access.ts +80 -0
  161. package/src/utils/errors.ts +68 -11
  162. package/src/utils/headers.ts +22 -2
  163. package/src/utils/validation.ts +11 -0
  164. package/src/utils/visibility.ts +56 -0
  165. package/dist/app.test.d.ts +0 -1
  166. package/dist/app.test.js +0 -82
  167. package/dist/app.test.js.map +0 -1
  168. package/dist/index.dev.d.ts +0 -1
  169. package/dist/index.dev.js +0 -156
  170. package/dist/index.dev.js.map +0 -1
  171. package/dist/routes/crate.test.d.ts +0 -1
  172. package/dist/routes/crate.test.js +0 -342
  173. package/dist/routes/crate.test.js.map +0 -1
  174. package/dist/routes/entities.test.d.ts +0 -1
  175. package/dist/routes/entities.test.js +0 -273
  176. package/dist/routes/entities.test.js.map +0 -1
  177. package/dist/routes/entity.test.d.ts +0 -1
  178. package/dist/routes/entity.test.js +0 -130
  179. package/dist/routes/entity.test.js.map +0 -1
  180. package/dist/routes/file.test.d.ts +0 -1
  181. package/dist/routes/file.test.js +0 -315
  182. package/dist/routes/file.test.js.map +0 -1
  183. package/dist/routes/files.test.d.ts +0 -1
  184. package/dist/routes/files.test.js +0 -222
  185. package/dist/routes/files.test.js.map +0 -1
  186. package/dist/routes/search.test.d.ts +0 -1
  187. package/dist/routes/search.test.js +0 -780
  188. package/dist/routes/search.test.js.map +0 -1
  189. package/dist/test/helpers/fastify.d.ts +0 -9
  190. package/dist/test/helpers/fastify.js +0 -18
  191. package/dist/test/helpers/fastify.js.map +0 -1
  192. package/dist/test/integration.setup.d.ts +0 -29
  193. package/dist/test/integration.setup.js +0 -187
  194. package/dist/test/integration.setup.js.map +0 -1
  195. package/dist/test/integration.test.d.ts +0 -1
  196. package/dist/test/integration.test.js +0 -396
  197. package/dist/test/integration.test.js.map +0 -1
  198. package/dist/transformers/default.test.d.ts +0 -1
  199. package/dist/transformers/default.test.js +0 -163
  200. package/dist/transformers/default.test.js.map +0 -1
  201. package/dist/transformers/transformer.test.d.ts +0 -1
  202. package/dist/transformers/transformer.test.js +0 -187
  203. package/dist/transformers/transformer.test.js.map +0 -1
  204. package/dist/types/fileHandlers.d.ts +0 -41
  205. package/dist/types/fileHandlers.js +0 -2
  206. package/dist/types/fileHandlers.js.map +0 -1
  207. package/dist/utils/errors.test.d.ts +0 -1
  208. package/dist/utils/errors.test.js +0 -66
  209. package/dist/utils/errors.test.js.map +0 -1
  210. package/dist/utils/queryBuilder.d.ts +0 -35
  211. package/dist/utils/queryBuilder.js +0 -98
  212. package/dist/utils/queryBuilder.js.map +0 -1
  213. package/prisma.config.ts +0 -9
  214. package/src/app.test.ts +0 -112
  215. package/src/index.dev.ts +0 -200
  216. package/src/reset.d.ts +0 -1
  217. package/src/routes/__snapshots__/entities.test.ts.snap +0 -96
  218. package/src/routes/__snapshots__/entity.test.ts.snap +0 -74
  219. package/src/routes/__snapshots__/search.test.ts.snap +0 -165
  220. package/src/routes/crate.test.ts +0 -423
  221. package/src/routes/entities.test.ts +0 -320
  222. package/src/routes/entity.test.ts +0 -160
  223. package/src/routes/file.test.ts +0 -395
  224. package/src/routes/files.test.ts +0 -278
  225. package/src/routes/search.test.ts +0 -903
  226. package/src/test/__snapshots__/integration.test.ts.snap +0 -18
  227. package/src/test/helpers/fastify.ts +0 -27
  228. package/src/test/integration.setup.ts +0 -209
  229. package/src/test/integration.test.ts +0 -482
  230. package/src/transformers/default.test.ts +0 -184
  231. package/src/transformers/transformer.test.ts +0 -252
  232. package/src/types/fileHandlers.ts +0 -65
  233. package/src/utils/errors.test.ts +0 -75
  234. package/src/utils/queryBuilder.ts +0 -132
@@ -1,482 +0,0 @@
1
- import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
2
- import type { AuthorisedEntity, AuthorisedFile } from '../transformers/default.js';
3
- import type { StandardErrorResponse } from '../utils/errors.js';
4
- import {
5
- cleanupTestData,
6
- getTestApp,
7
- seedTestData,
8
- setupIntegrationTests,
9
- teardownIntegrationTests,
10
- } from './integration.setup.js';
11
-
12
- describe('Integration Tests', () => {
13
- beforeAll(async () => {
14
- await setupIntegrationTests();
15
- });
16
-
17
- afterAll(async () => {
18
- await teardownIntegrationTests();
19
- });
20
-
21
- beforeEach(async () => {
22
- await seedTestData();
23
- });
24
-
25
- afterEach(async () => {
26
- await cleanupTestData();
27
- });
28
-
29
- describe('GET /entity/:id', () => {
30
- it('should return entity from database', async () => {
31
- const app = getTestApp();
32
-
33
- const response = await app.inject({
34
- method: 'GET',
35
- url: `/entity/${encodeURIComponent('http://example.com/entity/1')}`,
36
- });
37
- const body = JSON.parse(response.body);
38
-
39
- expect(response.statusCode).toBe(200);
40
- expect(body).toMatchSnapshot();
41
- });
42
-
43
- it('should return File entity from database', async () => {
44
- const app = getTestApp();
45
-
46
- const response = await app.inject({
47
- method: 'GET',
48
- url: `/entity/${encodeURIComponent('http://example.com/entity/4')}`,
49
- });
50
- const body = JSON.parse(response.body) as AuthorisedEntity;
51
-
52
- expect(response.statusCode).toBe(200);
53
- expect(body.id).toBe('http://example.com/entity/4');
54
- expect(body.name).toBe('test-audio.wav');
55
- expect(body.entityType).toBe('http://schema.org/MediaObject');
56
- expect(body.memberOf?.id).toBe('http://example.com/entity/2');
57
- expect(body.rootCollection?.id).toBe('http://example.com/entity/1');
58
- });
59
-
60
- it('should return 404 for non-existent entity', async () => {
61
- const app = getTestApp();
62
-
63
- const response = await app.inject({
64
- method: 'GET',
65
- url: '/entity/http://example.com/entity/nonexistent',
66
- });
67
- const body = JSON.parse(response.body) as StandardErrorResponse;
68
-
69
- expect(response.statusCode).toBe(404);
70
- expect(body.error).toBe('Not Found');
71
- });
72
- });
73
-
74
- describe('GET /entities', () => {
75
- it('should return all entities with pagination', async () => {
76
- const app = getTestApp();
77
-
78
- const response = await app.inject({
79
- method: 'GET',
80
- url: '/entities',
81
- });
82
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
83
-
84
- expect(response.statusCode).toBe(200);
85
- expect(body.total).toBe(5);
86
- expect(body.entities).toHaveLength(5);
87
- expect(body.entities[0]).toEqual({
88
- id: 'http://example.com/entity/1',
89
- name: 'Test Collection',
90
- description: 'First test entity',
91
- entityType: 'http://pcdm.org/models#Collection',
92
- memberOf: null,
93
- rootCollection: null,
94
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
95
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
96
- access: {
97
- metadata: true,
98
- content: true,
99
- },
100
- });
101
- });
102
-
103
- it('should filter entities by memberOf', async () => {
104
- const app = getTestApp();
105
-
106
- const response = await app.inject({
107
- method: 'GET',
108
- url: '/entities',
109
- query: {
110
- memberOf: 'http://example.com/entity/1',
111
- },
112
- });
113
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
114
-
115
- expect(response.statusCode).toBe(200);
116
- expect(body.total).toBe(3);
117
- expect(body.entities).toHaveLength(3);
118
- expect(body.entities[0].id).toBe('http://example.com/entity/2');
119
- });
120
-
121
- it('should filter entities by entityType', async () => {
122
- const app = getTestApp();
123
-
124
- const response = await app.inject({
125
- method: 'GET',
126
- url: '/entities',
127
- query: {
128
- entityType: 'http://schema.org/Person',
129
- },
130
- });
131
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
132
-
133
- expect(response.statusCode).toBe(200);
134
- expect(body.total).toBe(1);
135
- expect(body.entities).toHaveLength(1);
136
- expect(body.entities[0].id).toBe('http://example.com/entity/3');
137
- });
138
-
139
- it('should filter entities by File entityType', async () => {
140
- const app = getTestApp();
141
-
142
- const response = await app.inject({
143
- method: 'GET',
144
- url: '/entities',
145
- query: {
146
- entityType: 'http://schema.org/MediaObject',
147
- },
148
- });
149
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
150
-
151
- expect(response.statusCode).toBe(200);
152
- expect(body.total).toBe(2);
153
- expect(body.entities).toHaveLength(2);
154
- expect(body.entities[0].entityType).toBe('http://schema.org/MediaObject');
155
- expect(body.entities[1].entityType).toBe('http://schema.org/MediaObject');
156
- });
157
-
158
- it('should filter File entities by memberOf (Object parent)', async () => {
159
- const app = getTestApp();
160
-
161
- const response = await app.inject({
162
- method: 'GET',
163
- url: '/entities',
164
- query: {
165
- memberOf: 'http://example.com/entity/2',
166
- entityType: 'http://schema.org/MediaObject',
167
- },
168
- });
169
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
170
-
171
- expect(response.statusCode).toBe(200);
172
- expect(body.total).toBe(1);
173
- expect(body.entities).toHaveLength(1);
174
- expect(body.entities[0].id).toBe('http://example.com/entity/4');
175
- expect(body.entities[0].name).toBe('test-audio.wav');
176
- expect(body.entities[0].memberOf?.id).toBe('http://example.com/entity/2');
177
- });
178
-
179
- it('should filter File entities by memberOf (Collection parent)', async () => {
180
- const app = getTestApp();
181
-
182
- const response = await app.inject({
183
- method: 'GET',
184
- url: '/entities',
185
- query: {
186
- memberOf: 'http://example.com/entity/1',
187
- entityType: 'http://schema.org/MediaObject',
188
- },
189
- });
190
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
191
-
192
- expect(response.statusCode).toBe(200);
193
- expect(body.total).toBe(1);
194
- expect(body.entities).toHaveLength(1);
195
- expect(body.entities[0].id).toBe('http://example.com/entity/5');
196
- expect(body.entities[0].name).toBe('collection-metadata.csv');
197
- expect(body.entities[0].memberOf?.id).toBe('http://example.com/entity/1');
198
- });
199
-
200
- it('should handle pagination', async () => {
201
- const app = getTestApp();
202
-
203
- const response = await app.inject({
204
- method: 'GET',
205
- url: '/entities',
206
- query: {
207
- limit: '2',
208
- offset: '1',
209
- },
210
- });
211
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
212
-
213
- expect(response.statusCode).toBe(200);
214
- expect(body.total).toBe(5);
215
- expect(body.entities).toHaveLength(2);
216
- });
217
-
218
- it('should sort entities by name', async () => {
219
- const app = getTestApp();
220
-
221
- const response = await app.inject({
222
- method: 'GET',
223
- url: '/entities',
224
- query: {
225
- sort: 'name',
226
- order: 'desc',
227
- },
228
- });
229
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
230
-
231
- expect(response.statusCode).toBe(200);
232
- expect(body.entities[0].name).toBe('test-audio.wav');
233
- expect(body.entities[1].name).toBe('Test Person');
234
- expect(body.entities[2].name).toBe('Test Object');
235
- });
236
- });
237
-
238
- describe('GET /files', () => {
239
- it('should return all files', async () => {
240
- const app = getTestApp();
241
-
242
- const response = await app.inject({
243
- method: 'GET',
244
- url: '/files',
245
- });
246
- const body = JSON.parse(response.body) as { total: number; files: AuthorisedFile[] };
247
-
248
- expect(response.statusCode).toBe(200);
249
- expect(body.total).toBe(2);
250
- expect(body.files).toHaveLength(2);
251
- });
252
-
253
- it('should filter files by memberOf (Object parent)', async () => {
254
- const app = getTestApp();
255
-
256
- const response = await app.inject({
257
- method: 'GET',
258
- url: '/files',
259
- query: {
260
- memberOf: 'http://example.com/entity/2',
261
- },
262
- });
263
- const body = JSON.parse(response.body) as { total: number; files: AuthorisedFile[] };
264
-
265
- expect(response.statusCode).toBe(200);
266
- expect(body.total).toBe(1);
267
- expect(body.files).toHaveLength(1);
268
- expect(body.files[0].id).toBe('http://example.com/entity/4');
269
- expect(body.files[0].filename).toBe('test-audio.wav');
270
- });
271
-
272
- it('should filter files by memberOf (Collection parent)', async () => {
273
- const app = getTestApp();
274
-
275
- const response = await app.inject({
276
- method: 'GET',
277
- url: '/files',
278
- query: {
279
- memberOf: 'http://example.com/entity/1',
280
- },
281
- });
282
- const body = JSON.parse(response.body) as { total: number; files: AuthorisedFile[] };
283
-
284
- expect(response.statusCode).toBe(200);
285
- expect(body.total).toBe(1);
286
- expect(body.files).toHaveLength(1);
287
- expect(body.files[0].id).toBe('http://example.com/entity/5');
288
- expect(body.files[0].filename).toBe('collection-metadata.csv');
289
- });
290
-
291
- it('should return empty list when memberOf matches no entity', async () => {
292
- const app = getTestApp();
293
-
294
- const response = await app.inject({
295
- method: 'GET',
296
- url: '/files',
297
- query: {
298
- memberOf: 'http://example.com/entity/does-not-exist',
299
- },
300
- });
301
- const body = JSON.parse(response.body) as { total: number; files: AuthorisedFile[] };
302
-
303
- expect(response.statusCode).toBe(200);
304
- expect(body.total).toBe(0);
305
- expect(body.files).toHaveLength(0);
306
- });
307
- });
308
-
309
- describe('POST /search', () => {
310
- it('should perform basic search', async () => {
311
- const app = getTestApp();
312
-
313
- const response = await app.inject({
314
- method: 'POST',
315
- url: '/search',
316
- payload: {
317
- query: 'test',
318
- searchType: 'basic',
319
- },
320
- });
321
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
322
-
323
- expect(response.statusCode).toBe(200);
324
- expect(body.total).toBeGreaterThan(0);
325
- expect(body.entities).toBeDefined();
326
- expect(Array.isArray(body.entities)).toBe(true);
327
- });
328
-
329
- it('should handle search with no results', async () => {
330
- const app = getTestApp();
331
-
332
- const response = await app.inject({
333
- method: 'POST',
334
- url: '/search',
335
- payload: {
336
- query: 'nonexistentterm',
337
- searchType: 'basic',
338
- },
339
- });
340
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
341
-
342
- expect(response.statusCode).toBe(200);
343
- expect(body.total).toBe(0);
344
- expect(body.entities).toHaveLength(0);
345
- });
346
-
347
- it('should return aggregations', async () => {
348
- const app = getTestApp();
349
-
350
- const response = await app.inject({
351
- method: 'POST',
352
- url: '/search',
353
- payload: {
354
- query: 'test',
355
- searchType: 'basic',
356
- },
357
- });
358
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[]; facets: null };
359
-
360
- expect(response.statusCode).toBe(200);
361
- expect(body.facets).toBeDefined();
362
- });
363
-
364
- it('should handle search pagination', async () => {
365
- const app = getTestApp();
366
-
367
- const response = await app.inject({
368
- method: 'POST',
369
- url: '/search',
370
- payload: {
371
- query: 'test',
372
- limit: 1,
373
- offset: 0,
374
- },
375
- });
376
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
377
-
378
- expect(response.statusCode).toBe(200);
379
- expect(body.entities.length).toBeLessThanOrEqual(1);
380
- });
381
-
382
- it('should sort entities by id', async () => {
383
- const app = getTestApp();
384
-
385
- const response = await app.inject({
386
- method: 'POST',
387
- url: '/search',
388
- payload: {
389
- query: 'test',
390
- sort: 'id',
391
- },
392
- });
393
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
394
-
395
- expect(response.statusCode).toBe(200);
396
- expect(body.entities[0].name).toBe('Test Collection');
397
- expect(body.entities[1].name).toBe('Test Object');
398
- expect(body.entities[2].name).toBe('Test Person');
399
- });
400
-
401
- it('should filter search results by File entityType', async () => {
402
- const app = getTestApp();
403
-
404
- const response = await app.inject({
405
- method: 'POST',
406
- url: '/search',
407
- payload: {
408
- query: 'test',
409
- searchType: 'basic',
410
- filters: {
411
- entityType: ['http://schema.org/MediaObject'],
412
- },
413
- },
414
- });
415
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
416
-
417
- expect(response.statusCode).toBe(200);
418
- expect(body.entities.every((e) => e.entityType === 'http://schema.org/MediaObject')).toBe(true);
419
- });
420
-
421
- it('should search for File entities by name', async () => {
422
- const app = getTestApp();
423
-
424
- const response = await app.inject({
425
- method: 'POST',
426
- url: '/search',
427
- payload: {
428
- query: 'audio',
429
- searchType: 'basic',
430
- },
431
- });
432
- const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
433
-
434
- expect(response.statusCode).toBe(200);
435
- expect(body.total).toBeGreaterThan(0);
436
- const audioFile = body.entities.find((e) => e.name === 'test-audio.wav');
437
- expect(audioFile).toBeDefined();
438
- expect(audioFile?.entityType).toBe('http://schema.org/MediaObject');
439
- });
440
- });
441
-
442
- describe('Error Handling', () => {
443
- it('should handle invalid entity ID format', async () => {
444
- const app = getTestApp();
445
-
446
- const response = await app.inject({
447
- method: 'GET',
448
- url: '/entity/invalid-id',
449
- });
450
- const body = JSON.parse(response.body) as StandardErrorResponse;
451
-
452
- expect(response.statusCode).toBe(400);
453
- expect(body.error.code).toBe('VALIDATION_ERROR');
454
- });
455
-
456
- it('should handle invalid query parameters for entities', async () => {
457
- const app = getTestApp();
458
-
459
- const response = await app.inject({
460
- method: 'GET',
461
- url: '/entities',
462
- query: {
463
- limit: '-1',
464
- },
465
- });
466
-
467
- expect(response.statusCode).toBe(400);
468
- });
469
-
470
- it('should handle missing search query', async () => {
471
- const app = getTestApp();
472
-
473
- const response = await app.inject({
474
- method: 'POST',
475
- url: '/search',
476
- payload: {},
477
- });
478
-
479
- expect(response.statusCode).toBe(400);
480
- });
481
- });
482
- });
@@ -1,184 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { Entity } from '../generated/prisma/client.js';
3
- import { AllPublicAccessTransformer, baseEntityTransformer } from './default.js';
4
-
5
- describe('baseEntityTransformer', () => {
6
- it('should transform entity to standard entity shape', () => {
7
- const entity: Entity & { file?: { id: string } | null } = {
8
- id: 'http://example.com/entity/123',
9
- name: 'Test Entity',
10
- description: 'A test entity description',
11
- entityType: 'http://pcdm.org/models#Collection',
12
- memberOf: 'http://example.com/parent',
13
- rootCollection: 'http://example.com/root',
14
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
15
- contentLicenseId: 'https://creativecommons.org/licenses/by-sa/4.0/',
16
- createdAt: new Date('2025-01-01'),
17
- updatedAt: new Date('2025-01-02'),
18
- meta: { test: 'data' },
19
- };
20
-
21
- const result = baseEntityTransformer(entity);
22
-
23
- expect(result).toEqual({
24
- id: 'http://example.com/entity/123',
25
- name: 'Test Entity',
26
- description: 'A test entity description',
27
- entityType: 'http://pcdm.org/models#Collection',
28
- memberOf: 'http://example.com/parent',
29
- rootCollection: 'http://example.com/root',
30
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
31
- contentLicenseId: 'https://creativecommons.org/licenses/by-sa/4.0/',
32
- });
33
- });
34
-
35
- it('should handle null memberOf and rootCollection', () => {
36
- const entity: Entity & { file?: { id: string } | null } = {
37
- id: 'http://example.com/collection',
38
- name: 'Top Collection',
39
- description: 'A top-level collection',
40
- entityType: 'http://pcdm.org/models#Collection',
41
- memberOf: null,
42
- rootCollection: null,
43
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
44
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
45
- createdAt: new Date(),
46
- updatedAt: new Date(),
47
- meta: null,
48
- };
49
-
50
- const result = baseEntityTransformer(entity);
51
-
52
- expect(result.memberOf).toBeNull();
53
- expect(result.rootCollection).toBeNull();
54
- });
55
-
56
- it('should exclude database-specific fields', () => {
57
- const entity: Entity & { file?: { id: string } | null } = {
58
- id: 'http://example.com/entity/456',
59
- name: 'Test',
60
- description: 'Test',
61
- entityType: 'http://pcdm.org/models#Object',
62
- memberOf: null,
63
- rootCollection: null,
64
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
65
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
66
- createdAt: new Date(),
67
- updatedAt: new Date(),
68
- meta: { storage: 'path' },
69
- };
70
-
71
- const result = baseEntityTransformer(entity);
72
-
73
- expect(result.id).toBe('http://example.com/entity/456');
74
- expect(result).not.toHaveProperty('createdAt');
75
- expect(result).not.toHaveProperty('updatedAt');
76
- expect(result).not.toHaveProperty('meta');
77
- expect(Object.keys(result)).toEqual([
78
- 'id',
79
- 'name',
80
- 'description',
81
- 'entityType',
82
- 'memberOf',
83
- 'rootCollection',
84
- 'metadataLicenseId',
85
- 'contentLicenseId',
86
- ]);
87
- });
88
-
89
- it('should handle File entity (MediaObject) with file relation', () => {
90
- const entity: Entity & { file?: { id: string } | null } = {
91
- id: 'http://example.com/file/audio.wav',
92
- name: 'Audio File',
93
- description: 'An audio recording',
94
- entityType: 'http://schema.org/MediaObject',
95
- memberOf: 'http://example.com/collection',
96
- rootCollection: 'http://example.com/collection',
97
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
98
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
99
- createdAt: new Date(),
100
- updatedAt: new Date(),
101
- meta: null,
102
- file: { id: 'http://example.com/files/audio.wav' },
103
- };
104
-
105
- const result = baseEntityTransformer(entity);
106
-
107
- expect(result).toEqual({
108
- id: 'http://example.com/file/audio.wav',
109
- name: 'Audio File',
110
- description: 'An audio recording',
111
- entityType: 'http://schema.org/MediaObject',
112
- memberOf: 'http://example.com/collection',
113
- rootCollection: 'http://example.com/collection',
114
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
115
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
116
- });
117
- });
118
- });
119
-
120
- describe('AllPublicAccessTransformer', () => {
121
- it('should grant full access to metadata and content', () => {
122
- const standardEntity = {
123
- id: 'http://example.com/entity/123',
124
- name: 'Test Entity',
125
- description: 'A test entity',
126
- entityType: 'http://schema.org/MediaObject',
127
- memberOf: { id: 'http://example.com/parent', name: 'Parent Entity' },
128
- rootCollection: { id: 'http://example.com/root', name: 'Root Collection' },
129
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
130
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
131
- };
132
-
133
- const result = AllPublicAccessTransformer(standardEntity);
134
-
135
- expect(result).toEqual({
136
- ...standardEntity,
137
- access: {
138
- metadata: true,
139
- content: true,
140
- },
141
- });
142
- });
143
-
144
- it('should preserve all standard entity fields', () => {
145
- const standardEntity = {
146
- id: 'http://example.com/entity/789',
147
- name: 'Another Entity',
148
- description: 'Another description',
149
- entityType: 'http://schema.org/Person',
150
- memberOf: null,
151
- rootCollection: null,
152
- metadataLicenseId: 'https://creativecommons.org/publicdomain/zero/1.0/',
153
- contentLicenseId: 'https://creativecommons.org/publicdomain/zero/1.0/',
154
- };
155
-
156
- const result = AllPublicAccessTransformer(standardEntity);
157
-
158
- expect(result.id).toBe(standardEntity.id);
159
- expect(result.name).toBe(standardEntity.name);
160
- expect(result.description).toBe(standardEntity.description);
161
- expect(result.entityType).toBe(standardEntity.entityType);
162
- expect(result.memberOf).toBe(standardEntity.memberOf);
163
- expect(result.rootCollection).toBe(standardEntity.rootCollection);
164
- expect(result.metadataLicenseId).toBe(standardEntity.metadataLicenseId);
165
- expect(result.contentLicenseId).toBe(standardEntity.contentLicenseId);
166
- });
167
-
168
- it('should not add contentAuthorizationUrl for public access', () => {
169
- const standardEntity = {
170
- id: 'http://example.com/entity/public',
171
- name: 'Public Entity',
172
- description: 'Fully public',
173
- entityType: 'http://pcdm.org/models#Collection',
174
- memberOf: null,
175
- rootCollection: null,
176
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
177
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
178
- };
179
-
180
- const result = AllPublicAccessTransformer(standardEntity);
181
-
182
- expect(result.access.contentAuthorizationUrl).toBeUndefined();
183
- });
184
- });