arocapi 4.0.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 (242) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +37 -781
  3. package/dist/app.d.ts +38 -21
  4. package/dist/app.js +63 -45
  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 +38 -58
  11. package/dist/routes/entities.js.map +1 -1
  12. package/dist/routes/entity.d.ts +7 -2
  13. package/dist/routes/entity.js +14 -30
  14. package/dist/routes/entity.js.map +1 -1
  15. package/dist/routes/file.d.ts +8 -2
  16. package/dist/routes/file.js +38 -73
  17. package/dist/routes/file.js.map +1 -1
  18. package/dist/routes/files.d.ts +5 -2
  19. package/dist/routes/files.js +25 -40
  20. package/dist/routes/files.js.map +1 -1
  21. package/dist/routes/metadata.d.ts +15 -0
  22. package/dist/routes/metadata.js +38 -0
  23. package/dist/routes/metadata.js.map +1 -0
  24. package/dist/routes/search.d.ts +8 -7
  25. package/dist/routes/search.js +91 -120
  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 +84 -45
  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 +169 -102
  126. package/src/routes/capabilities.ts +22 -0
  127. package/src/routes/entities.ts +49 -68
  128. package/src/routes/entity.ts +22 -36
  129. package/src/routes/file.ts +54 -104
  130. package/src/routes/files.ts +32 -48
  131. package/src/routes/metadata.ts +67 -0
  132. package/src/routes/search.ts +132 -152
  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 -89
  167. package/dist/app.test.js.map +0 -1
  168. package/dist/express.d.ts +0 -4
  169. package/dist/express.js +0 -14
  170. package/dist/express.js.map +0 -1
  171. package/dist/index.dev.d.ts +0 -1
  172. package/dist/index.dev.js +0 -156
  173. package/dist/index.dev.js.map +0 -1
  174. package/dist/routes/crate.d.ts +0 -9
  175. package/dist/routes/crate.js +0 -82
  176. package/dist/routes/crate.js.map +0 -1
  177. package/dist/routes/crate.test.d.ts +0 -1
  178. package/dist/routes/crate.test.js +0 -342
  179. package/dist/routes/crate.test.js.map +0 -1
  180. package/dist/routes/entities.test.d.ts +0 -1
  181. package/dist/routes/entities.test.js +0 -273
  182. package/dist/routes/entities.test.js.map +0 -1
  183. package/dist/routes/entity.test.d.ts +0 -1
  184. package/dist/routes/entity.test.js +0 -130
  185. package/dist/routes/entity.test.js.map +0 -1
  186. package/dist/routes/file.test.d.ts +0 -1
  187. package/dist/routes/file.test.js +0 -315
  188. package/dist/routes/file.test.js.map +0 -1
  189. package/dist/routes/files.test.d.ts +0 -1
  190. package/dist/routes/files.test.js +0 -222
  191. package/dist/routes/files.test.js.map +0 -1
  192. package/dist/routes/search.test.d.ts +0 -1
  193. package/dist/routes/search.test.js +0 -780
  194. package/dist/routes/search.test.js.map +0 -1
  195. package/dist/test/helpers/fastify.d.ts +0 -9
  196. package/dist/test/helpers/fastify.js +0 -18
  197. package/dist/test/helpers/fastify.js.map +0 -1
  198. package/dist/test/integration.setup.d.ts +0 -29
  199. package/dist/test/integration.setup.js +0 -188
  200. package/dist/test/integration.setup.js.map +0 -1
  201. package/dist/test/integration.test.d.ts +0 -1
  202. package/dist/test/integration.test.js +0 -396
  203. package/dist/test/integration.test.js.map +0 -1
  204. package/dist/transformers/default.test.d.ts +0 -1
  205. package/dist/transformers/default.test.js +0 -163
  206. package/dist/transformers/default.test.js.map +0 -1
  207. package/dist/transformers/transformer.test.d.ts +0 -1
  208. package/dist/transformers/transformer.test.js +0 -187
  209. package/dist/transformers/transformer.test.js.map +0 -1
  210. package/dist/types/fileHandlers.d.ts +0 -41
  211. package/dist/types/fileHandlers.js +0 -2
  212. package/dist/types/fileHandlers.js.map +0 -1
  213. package/dist/utils/errors.test.d.ts +0 -1
  214. package/dist/utils/errors.test.js +0 -66
  215. package/dist/utils/errors.test.js.map +0 -1
  216. package/dist/utils/queryBuilder.d.ts +0 -35
  217. package/dist/utils/queryBuilder.js +0 -98
  218. package/dist/utils/queryBuilder.js.map +0 -1
  219. package/prisma.config.ts +0 -9
  220. package/src/app.test.ts +0 -119
  221. package/src/express.ts +0 -21
  222. package/src/index.dev.ts +0 -200
  223. package/src/reset.d.ts +0 -1
  224. package/src/routes/__snapshots__/entities.test.ts.snap +0 -96
  225. package/src/routes/__snapshots__/entity.test.ts.snap +0 -74
  226. package/src/routes/__snapshots__/search.test.ts.snap +0 -165
  227. package/src/routes/crate.test.ts +0 -423
  228. package/src/routes/crate.ts +0 -123
  229. package/src/routes/entities.test.ts +0 -320
  230. package/src/routes/entity.test.ts +0 -160
  231. package/src/routes/file.test.ts +0 -395
  232. package/src/routes/files.test.ts +0 -278
  233. package/src/routes/search.test.ts +0 -903
  234. package/src/test/__snapshots__/integration.test.ts.snap +0 -18
  235. package/src/test/helpers/fastify.ts +0 -27
  236. package/src/test/integration.setup.ts +0 -210
  237. package/src/test/integration.test.ts +0 -482
  238. package/src/transformers/default.test.ts +0 -184
  239. package/src/transformers/transformer.test.ts +0 -252
  240. package/src/types/fileHandlers.ts +0 -65
  241. package/src/utils/errors.test.ts +0 -75
  242. package/src/utils/queryBuilder.ts +0 -132
@@ -1,252 +0,0 @@
1
- import type { FastifyInstance, FastifyRequest } from 'fastify';
2
- import { describe, expect, it } from 'vitest';
3
- import type { AccessTransformer, EntityTransformer, TransformerContext } from '../types/transformers.js';
4
- import {
5
- AllPublicAccessTransformer,
6
- type AuthorisedEntity,
7
- type BaseEntity,
8
- baseEntityTransformer,
9
- type StandardEntity,
10
- } from './default.js';
11
-
12
- describe('Entity Transformers', () => {
13
- const mockContext: TransformerContext = {
14
- request: {} as FastifyRequest,
15
- fastify: {} as FastifyInstance,
16
- };
17
-
18
- const mockStandardEntity: StandardEntity = {
19
- id: 'http://example.com/entity/123',
20
- name: 'Test Entity',
21
- description: 'A test entity',
22
- entityType: 'http://schema.org/Person',
23
- memberOf: { id: 'http://example.com/collection', name: 'Test Collection' },
24
- rootCollection: { id: 'http://example.com/root', name: 'Root Collection' },
25
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
26
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
27
- };
28
-
29
- const mockAuthorisedEntity: AuthorisedEntity = {
30
- ...mockStandardEntity,
31
- access: {
32
- metadata: true,
33
- content: true,
34
- },
35
- };
36
-
37
- describe('baseEntityTransformer', () => {
38
- it('should transform raw entity to base shape with unresolved references', () => {
39
- const rawEntity = {
40
- id: 'http://example.com/entity/123',
41
- name: 'Test Entity',
42
- description: 'A test entity',
43
- entityType: 'http://schema.org/Person',
44
-
45
- memberOf: 'http://example.com/collection',
46
- rootCollection: 'http://example.com/root',
47
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
48
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
49
- meta: {},
50
- createdAt: new Date(),
51
- updatedAt: new Date(),
52
- };
53
-
54
- const result = baseEntityTransformer(rawEntity);
55
-
56
- // baseEntityTransformer returns BaseEntity with string references
57
- const expectedBaseEntity: BaseEntity = {
58
- id: 'http://example.com/entity/123',
59
- name: 'Test Entity',
60
- description: 'A test entity',
61
- entityType: 'http://schema.org/Person',
62
- memberOf: 'http://example.com/collection',
63
- rootCollection: 'http://example.com/root',
64
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
65
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
66
- };
67
-
68
- expect(result).toEqual(expectedBaseEntity);
69
- });
70
- });
71
-
72
- describe('AllPublicAccessTransformer', () => {
73
- it('should add full access to standard entity', () => {
74
- const result = AllPublicAccessTransformer(mockStandardEntity);
75
-
76
- expect(result).toEqual({
77
- ...mockStandardEntity,
78
- access: {
79
- metadata: true,
80
- content: true,
81
- },
82
- });
83
- });
84
-
85
- it('should grant metadata and content access', () => {
86
- const result = AllPublicAccessTransformer(mockStandardEntity);
87
-
88
- expect(result.access.metadata).toBe(true);
89
- expect(result.access.content).toBe(true);
90
- expect(result.access.contentAuthorizationUrl).toBeUndefined();
91
- });
92
- });
93
-
94
- describe('Custom transformers', () => {
95
- it('should allow custom transformer to add computed fields', () => {
96
- const customTransformer: EntityTransformer<AuthorisedEntity, { id: string; displayName: string; uri: string }> = (
97
- entity,
98
- ) => ({
99
- id: entity.id,
100
- displayName: entity.name.toUpperCase(),
101
- uri: entity.id,
102
- });
103
-
104
- const result = customTransformer(mockAuthorisedEntity, mockContext);
105
-
106
- expect(result).toEqual({
107
- id: 'http://example.com/entity/123',
108
- displayName: 'TEST ENTITY',
109
- uri: 'http://example.com/entity/123',
110
- });
111
- });
112
-
113
- it('should support async transformers for fetching related data', async () => {
114
- const asyncTransformer: EntityTransformer<
115
- AuthorisedEntity,
116
- { id: string; name: string; relatedData: string }
117
- > = async (entity) => {
118
- // Simulate async operation
119
- await new Promise((resolve) => setTimeout(resolve, 1));
120
-
121
- return {
122
- id: entity.id,
123
- name: entity.name,
124
- relatedData: 'fetched-data',
125
- };
126
- };
127
-
128
- const result = await asyncTransformer(mockAuthorisedEntity, mockContext);
129
-
130
- expect(result).toEqual({
131
- id: 'http://example.com/entity/123',
132
- name: 'Test Entity',
133
- relatedData: 'fetched-data',
134
- });
135
- });
136
-
137
- it('should allow transformer to access context', async () => {
138
- const contextAwareTransformer: EntityTransformer<
139
- AuthorisedEntity,
140
- {
141
- id: string;
142
- name: string;
143
- requestUrl: string;
144
- }
145
- > = async (entity, context) => ({
146
- id: entity.id,
147
- name: entity.name,
148
- requestUrl: context.request.url || 'unknown',
149
- });
150
-
151
- const contextWithUrl: TransformerContext = {
152
- request: { url: '/test-url' } as FastifyRequest,
153
- fastify: {} as FastifyInstance,
154
- };
155
-
156
- const result = await contextAwareTransformer(mockAuthorisedEntity, contextWithUrl);
157
-
158
- expect(result).toEqual({
159
- id: 'http://example.com/entity/123',
160
- name: 'Test Entity',
161
- requestUrl: '/test-url',
162
- });
163
- });
164
-
165
- it('should support transformer pipeline', async () => {
166
- const addDisplayName: EntityTransformer<AuthorisedEntity, AuthorisedEntity & { displayName: string }> = (
167
- entity,
168
- ) => ({
169
- ...entity,
170
- displayName: `${entity.name} [${entity.entityType.split('/').pop()}]`,
171
- });
172
-
173
- const addUpperCase: EntityTransformer<
174
- AuthorisedEntity & { displayName: string },
175
- AuthorisedEntity & { displayName: string; upperName: string }
176
- > = (entity) => ({
177
- ...entity,
178
- upperName: entity.name.toUpperCase(),
179
- });
180
-
181
- // Simulate pipeline
182
- // biome-ignore lint/suspicious/noExplicitAny: fine in tests
183
- let result: any = mockAuthorisedEntity;
184
- result = await addDisplayName(result, mockContext);
185
- result = await addUpperCase(result, mockContext);
186
-
187
- expect(result).toMatchObject({
188
- id: 'http://example.com/entity/123',
189
- name: 'Test Entity',
190
- displayName: 'Test Entity [Person]',
191
- upperName: 'TEST ENTITY',
192
- });
193
- });
194
-
195
- it('should demonstrate full pipeline: base -> resolve -> access -> custom', async () => {
196
- const rawEntity = {
197
- id: 'http://example.com/entity/123',
198
- name: 'Test Entity',
199
- description: 'A test entity',
200
- entityType: 'http://schema.org/Person',
201
-
202
- memberOf: 'http://example.com/collection',
203
- rootCollection: 'http://example.com/root',
204
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
205
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
206
- meta: {},
207
- createdAt: new Date(),
208
- updatedAt: new Date(),
209
- };
210
-
211
- const customAccessTransformer: AccessTransformer = (entity) => ({
212
- ...entity,
213
- access: {
214
- metadata: true,
215
- content: false,
216
- contentAuthorizationUrl: 'https://example.com/auth',
217
- },
218
- });
219
-
220
- const addMetadata: EntityTransformer<AuthorisedEntity, AuthorisedEntity & { processed: boolean }> = (entity) => ({
221
- ...entity,
222
- processed: true,
223
- });
224
-
225
- // Full pipeline: base -> resolve references -> access -> custom
226
- const base = baseEntityTransformer(rawEntity);
227
-
228
- // Simulate reference resolution (in real code, this uses resolveEntityReferences)
229
- const standard: StandardEntity = {
230
- ...base,
231
- memberOf: base.memberOf ? { id: base.memberOf, name: 'Parent Collection' } : null,
232
- rootCollection: base.rootCollection ? { id: base.rootCollection, name: 'Root Collection' } : null,
233
- };
234
-
235
- const authorised = await customAccessTransformer(standard, mockContext);
236
- const final = await addMetadata(authorised, mockContext);
237
-
238
- expect(final).toMatchObject({
239
- id: 'http://example.com/entity/123',
240
- name: 'Test Entity',
241
- memberOf: { id: 'http://example.com/collection', name: 'Parent Collection' },
242
- rootCollection: { id: 'http://example.com/root', name: 'Root Collection' },
243
- access: {
244
- metadata: true,
245
- content: false,
246
- contentAuthorizationUrl: 'https://example.com/auth',
247
- },
248
- processed: true,
249
- });
250
- });
251
- });
252
- });
@@ -1,65 +0,0 @@
1
- import type { Readable } from 'node:stream';
2
- import type { FastifyInstance, FastifyRequest } from 'fastify';
3
- import type { Entity, File } from '../generated/prisma/client.js';
4
-
5
- export type FileHandlerContext = {
6
- request: FastifyRequest;
7
- fastify: FastifyInstance;
8
- };
9
-
10
- export type FileMetadata = {
11
- contentType: string;
12
- contentLength: number;
13
- etag?: string;
14
- lastModified?: Date;
15
- };
16
-
17
- export type FileRedirectResult = {
18
- type: 'redirect';
19
- url: string;
20
- };
21
-
22
- export type FileStreamResult = {
23
- type: 'stream';
24
- stream: Readable | ReadableStream;
25
- metadata: FileMetadata;
26
- };
27
-
28
- export type FilePathResult = {
29
- type: 'file';
30
- path: string; // Absolute file path on disk
31
- metadata: FileMetadata;
32
- accelPath?: string; // Optional nginx internal path for X-Accel-Redirect
33
- };
34
-
35
- export type FileResult = FileRedirectResult | FileStreamResult | FilePathResult;
36
-
37
- export type GetFileHandler = (
38
- file: File,
39
- context: FileHandlerContext,
40
- ) => Promise<FileResult | false> | FileResult | false;
41
-
42
- export type HeadFileHandler = (
43
- file: File,
44
- context: FileHandlerContext,
45
- ) => Promise<FileMetadata | false> | FileMetadata | false;
46
-
47
- export type FileHandler = {
48
- get: GetFileHandler;
49
- head: HeadFileHandler;
50
- };
51
-
52
- export type GetRoCrateHandler = (
53
- entity: Entity,
54
- context: FileHandlerContext,
55
- ) => Promise<FileResult | false> | FileResult | false;
56
-
57
- export type HeadRoCrateHandler = (
58
- entity: Entity,
59
- context: FileHandlerContext,
60
- ) => Promise<FileMetadata | false> | FileMetadata | false;
61
-
62
- export type RoCrateHandler = {
63
- get: GetRoCrateHandler;
64
- head: HeadRoCrateHandler;
65
- };
@@ -1,75 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { createInternalError, createNotFoundError } from './errors.js';
3
-
4
- describe('Error Utilities', () => {
5
- describe('createInternalError', () => {
6
- it('should create a default internal error', () => {
7
- const error = createInternalError();
8
-
9
- expect(error).toEqual({
10
- error: {
11
- code: 'INTERNAL_ERROR',
12
- message: 'Internal server error',
13
- details: undefined,
14
- },
15
- });
16
- });
17
-
18
- it('should create an internal error with custom message', () => {
19
- const customMessage = 'Database connection failed';
20
- const error = createInternalError(customMessage);
21
-
22
- expect(error).toEqual({
23
- error: {
24
- code: 'INTERNAL_ERROR',
25
- message: customMessage,
26
- details: undefined,
27
- },
28
- });
29
- });
30
- });
31
-
32
- describe('createNotFoundError', () => {
33
- it('should create a not found error with message', () => {
34
- const message = 'Entity not found';
35
- const error = createNotFoundError(message);
36
-
37
- expect(error).toEqual({
38
- error: {
39
- code: 'NOT_FOUND',
40
- message,
41
- details: undefined,
42
- },
43
- });
44
- });
45
-
46
- it('should create a not found error with message and entityId', () => {
47
- const message = 'Entity not found';
48
- const entityId = 'http://example.com/entity/123';
49
- const error = createNotFoundError(message, entityId);
50
-
51
- expect(error).toEqual({
52
- error: {
53
- code: 'NOT_FOUND',
54
- message,
55
- details: {
56
- entityId,
57
- },
58
- },
59
- });
60
- });
61
-
62
- it('should handle undefined entityId', () => {
63
- const message = 'Entity not found';
64
- const error = createNotFoundError(message, undefined);
65
-
66
- expect(error).toEqual({
67
- error: {
68
- code: 'NOT_FOUND',
69
- message,
70
- details: undefined,
71
- },
72
- });
73
- });
74
- });
75
- });
@@ -1,132 +0,0 @@
1
- import type { SortOrder } from '@opensearch-project/opensearch/api/_types/_common.js';
2
- import type { BoolQuery } from '@opensearch-project/opensearch/api/_types/_common.query_dsl.js';
3
- import type { Search_RequestBody } from '@opensearch-project/opensearch/api/index.js';
4
-
5
- type Aggregations = Required<Search_RequestBody>['aggs'];
6
-
7
- type BoundingBox = {
8
- topRight: {
9
- lat: number;
10
- lng: number;
11
- };
12
- bottomLeft: {
13
- lat: number;
14
- lng: number;
15
- };
16
- };
17
-
18
- export type QueryBuilderOptions = {
19
- aggregations?: Aggregations;
20
- };
21
-
22
- export class OpensearchQueryBuilder {
23
- aggregations: Aggregations;
24
-
25
- constructor(opts?: QueryBuilderOptions) {
26
- this.aggregations =
27
- opts?.aggregations ||
28
- Object.fromEntries(
29
- ['inLanguage', 'mediaType', 'communicationMode', 'entityType'].map((name) => [
30
- name,
31
- { terms: { field: `${name}.keyword`, size: 20 } },
32
- ]),
33
- );
34
- }
35
-
36
- buildQuery(searchType: string, query: string, filters?: Record<string, string[]>, boundingBox?: BoundingBox) {
37
- const must: BoolQuery['must'] = [];
38
- const filter: BoolQuery['filter'] = [];
39
-
40
- if (searchType === 'basic') {
41
- must.push({
42
- multi_match: {
43
- query,
44
- fields: ['name^2', 'description'],
45
- type: 'best_fields',
46
- fuzziness: 'AUTO',
47
- zero_terms_query: 'all',
48
- },
49
- });
50
- } else {
51
- must.push({
52
- query_string: {
53
- query,
54
- fields: ['name^2', 'description'],
55
- default_operator: 'AND',
56
- },
57
- });
58
- }
59
-
60
- if (filters) {
61
- Object.entries(filters).forEach(([field, values]) => {
62
- filter.push({
63
- terms: {
64
- [field]: values,
65
- },
66
- });
67
- });
68
- }
69
-
70
- if (boundingBox) {
71
- filter.push({
72
- geo_bounding_box: {
73
- location: {
74
- top_left: {
75
- lat: boundingBox.topRight.lat,
76
- lon: boundingBox.bottomLeft.lng,
77
- },
78
- bottom_right: {
79
- lat: boundingBox.bottomLeft.lat,
80
- lon: boundingBox.topRight.lng,
81
- },
82
- },
83
- },
84
- });
85
- }
86
-
87
- return {
88
- bool: {
89
- must,
90
- filter,
91
- },
92
- };
93
- }
94
-
95
- buildAggregations(geohashPrecision?: number, boundingBox?: BoundingBox) {
96
- const aggs = { ...this.aggregations };
97
-
98
- // Add geohash aggregation if precision is specified
99
- if (geohashPrecision && boundingBox) {
100
- aggs.geohash_grid = {
101
- geohash_grid: {
102
- field: 'location',
103
- precision: geohashPrecision,
104
- bounds: {
105
- top_left: {
106
- lat: boundingBox.topRight.lat,
107
- lon: boundingBox.bottomLeft.lng,
108
- },
109
- bottom_right: {
110
- lat: boundingBox.bottomLeft.lat,
111
- lon: boundingBox.topRight.lng,
112
- },
113
- },
114
- },
115
- };
116
- }
117
-
118
- return aggs;
119
- }
120
-
121
- buildSort(sort: string, order: SortOrder) {
122
- if (sort === 'relevance') {
123
- return;
124
- }
125
-
126
- if (sort === 'name') {
127
- return [{ 'name.keyword': order }];
128
- }
129
-
130
- return [{ [sort]: order }];
131
- }
132
- }