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.
- package/LICENSE.md +1 -1
- package/README.md +37 -802
- package/dist/app.d.ts +38 -20
- package/dist/app.js +62 -40
- package/dist/app.js.map +1 -1
- package/dist/routes/capabilities.d.ts +7 -0
- package/dist/routes/capabilities.js +13 -0
- package/dist/routes/capabilities.js.map +1 -0
- package/dist/routes/entities.d.ts +5 -2
- package/dist/routes/entities.js +37 -57
- package/dist/routes/entities.js.map +1 -1
- package/dist/routes/entity.d.ts +7 -2
- package/dist/routes/entity.js +13 -29
- package/dist/routes/entity.js.map +1 -1
- package/dist/routes/file.d.ts +8 -2
- package/dist/routes/file.js +37 -72
- package/dist/routes/file.js.map +1 -1
- package/dist/routes/files.d.ts +5 -2
- package/dist/routes/files.js +24 -39
- package/dist/routes/files.js.map +1 -1
- package/dist/routes/metadata.d.ts +11 -5
- package/dist/routes/metadata.js +24 -68
- package/dist/routes/metadata.js.map +1 -1
- package/dist/routes/search.d.ts +8 -7
- package/dist/routes/search.js +90 -119
- package/dist/routes/search.js.map +1 -1
- package/dist/search/advanced.d.ts +8 -0
- package/dist/search/advanced.js +198 -0
- package/dist/search/advanced.js.map +1 -0
- package/dist/search/backend.d.ts +95 -0
- package/dist/search/backend.js +5 -0
- package/dist/search/backend.js.map +1 -0
- package/dist/search/fields.d.ts +63 -0
- package/dist/search/fields.js +203 -0
- package/dist/search/fields.js.map +1 -0
- package/dist/search/opensearch/advanced.d.ts +4 -0
- package/dist/search/opensearch/advanced.js +28 -0
- package/dist/search/opensearch/advanced.js.map +1 -0
- package/dist/search/opensearch/opensearch.d.ts +16 -0
- package/dist/search/opensearch/opensearch.js +187 -0
- package/dist/search/opensearch/opensearch.js.map +1 -0
- package/dist/search/opensearch/visibility.d.ts +3 -0
- package/dist/search/opensearch/visibility.js +27 -0
- package/dist/search/opensearch/visibility.js.map +1 -0
- package/dist/search/postgres/advanced.d.ts +7 -0
- package/dist/search/postgres/advanced.js +54 -0
- package/dist/search/postgres/advanced.js.map +1 -0
- package/dist/search/postgres/facets.d.ts +2 -0
- package/dist/search/postgres/facets.js +27 -0
- package/dist/search/postgres/facets.js.map +1 -0
- package/dist/search/postgres/geo.d.ts +6 -0
- package/dist/search/postgres/geo.js +42 -0
- package/dist/search/postgres/geo.js.map +1 -0
- package/dist/search/postgres/postgres.d.ts +19 -0
- package/dist/search/postgres/postgres.js +157 -0
- package/dist/search/postgres/postgres.js.map +1 -0
- package/dist/search/postgres/values.d.ts +8 -0
- package/dist/search/postgres/values.js +20 -0
- package/dist/search/postgres/values.js.map +1 -0
- package/dist/search/postgres/visibility.d.ts +4 -0
- package/dist/search/postgres/visibility.js +38 -0
- package/dist/search/postgres/visibility.js.map +1 -0
- package/dist/search/requestFilters.d.ts +39 -0
- package/dist/search/requestFilters.js +125 -0
- package/dist/search/requestFilters.js.map +1 -0
- package/dist/search/visibility.d.ts +51 -0
- package/dist/search/visibility.js +100 -0
- package/dist/search/visibility.js.map +1 -0
- package/dist/storage/backend.d.ts +58 -0
- package/dist/storage/backend.js +2 -0
- package/dist/storage/backend.js.map +1 -0
- package/dist/storage/deliver.d.ts +12 -0
- package/dist/storage/deliver.js +34 -0
- package/dist/storage/deliver.js.map +1 -0
- package/dist/storage/directory/directory.d.ts +6 -0
- package/dist/storage/directory/directory.js +24 -0
- package/dist/storage/directory/directory.js.map +1 -0
- package/dist/storage/entity-meta/entity-meta.d.ts +5 -0
- package/dist/storage/entity-meta/entity-meta.js +14 -0
- package/dist/storage/entity-meta/entity-meta.js.map +1 -0
- package/dist/storage/location.d.ts +19 -0
- package/dist/storage/location.js +36 -0
- package/dist/storage/location.js.map +1 -0
- package/dist/storage/ocfl/ocfl.d.ts +6 -0
- package/dist/storage/ocfl/ocfl.js +45 -0
- package/dist/storage/ocfl/ocfl.js.map +1 -0
- package/dist/storage/results.d.ts +7 -0
- package/dist/storage/results.js +22 -0
- package/dist/storage/results.js.map +1 -0
- package/dist/storage/s3/s3.d.ts +10 -0
- package/dist/storage/s3/s3.js +47 -0
- package/dist/storage/s3/s3.js.map +1 -0
- package/dist/transformers/default.d.ts +11 -22
- package/dist/transformers/default.js +41 -15
- package/dist/transformers/default.js.map +1 -1
- package/dist/types/access.d.ts +9 -0
- package/dist/types/access.js +2 -0
- package/dist/types/access.js.map +1 -0
- package/dist/types/context.d.ts +6 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/transformers.d.ts +4 -10
- package/dist/types/visibility.d.ts +6 -0
- package/dist/types/visibility.js +2 -0
- package/dist/types/visibility.js.map +1 -0
- package/dist/utils/access.d.ts +17 -0
- package/dist/utils/access.js +41 -0
- package/dist/utils/access.js.map +1 -0
- package/dist/utils/errors.d.ts +19 -10
- package/dist/utils/errors.js +44 -8
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/headers.d.ts +1 -1
- package/dist/utils/headers.js +10 -1
- package/dist/utils/headers.js.map +1 -1
- package/dist/utils/validation.d.ts +2 -0
- package/dist/utils/validation.js +8 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils/visibility.d.ts +18 -0
- package/dist/utils/visibility.js +16 -0
- package/dist/utils/visibility.js.map +1 -0
- package/package.json +82 -40
- package/prisma/models/entity.prisma +9 -8
- package/prisma/models/entitySearch.prisma +21 -0
- package/prisma/models/file.prisma +3 -3
- package/src/app.ts +168 -95
- package/src/routes/capabilities.ts +22 -0
- package/src/routes/entities.ts +48 -67
- package/src/routes/entity.ts +21 -35
- package/src/routes/file.ts +53 -103
- package/src/routes/files.ts +31 -47
- package/src/routes/metadata.ts +42 -98
- package/src/routes/search.ts +131 -151
- package/src/search/advanced.ts +258 -0
- package/src/search/backend.ts +91 -0
- package/src/search/fields.ts +320 -0
- package/src/search/opensearch/advanced.ts +36 -0
- package/src/search/opensearch/opensearch.ts +290 -0
- package/src/search/opensearch/visibility.ts +38 -0
- package/src/search/postgres/advanced.ts +76 -0
- package/src/search/postgres/facets.ts +34 -0
- package/src/search/postgres/geo.ts +58 -0
- package/src/search/postgres/postgres.ts +232 -0
- package/src/search/postgres/values.ts +33 -0
- package/src/search/postgres/visibility.ts +54 -0
- package/src/search/requestFilters.ts +178 -0
- package/src/search/visibility.ts +193 -0
- package/src/storage/backend.ts +75 -0
- package/src/storage/deliver.ts +65 -0
- package/src/storage/directory/directory.ts +39 -0
- package/src/storage/entity-meta/entity-meta.ts +25 -0
- package/src/storage/location.ts +78 -0
- package/src/storage/ocfl/ocfl.ts +71 -0
- package/src/storage/results.ts +32 -0
- package/src/storage/s3/s3.ts +79 -0
- package/src/transformers/default.ts +115 -85
- package/src/types/access.ts +25 -0
- package/src/types/context.ts +15 -0
- package/src/types/transformers.ts +8 -34
- package/src/types/visibility.ts +21 -0
- package/src/utils/access.ts +80 -0
- package/src/utils/errors.ts +68 -11
- package/src/utils/headers.ts +22 -2
- package/src/utils/validation.ts +11 -0
- package/src/utils/visibility.ts +56 -0
- package/dist/app.test.d.ts +0 -1
- package/dist/app.test.js +0 -82
- package/dist/app.test.js.map +0 -1
- package/dist/index.dev.d.ts +0 -1
- package/dist/index.dev.js +0 -156
- package/dist/index.dev.js.map +0 -1
- package/dist/routes/crate.test.d.ts +0 -1
- package/dist/routes/crate.test.js +0 -342
- package/dist/routes/crate.test.js.map +0 -1
- package/dist/routes/entities.test.d.ts +0 -1
- package/dist/routes/entities.test.js +0 -273
- package/dist/routes/entities.test.js.map +0 -1
- package/dist/routes/entity.test.d.ts +0 -1
- package/dist/routes/entity.test.js +0 -130
- package/dist/routes/entity.test.js.map +0 -1
- package/dist/routes/file.test.d.ts +0 -1
- package/dist/routes/file.test.js +0 -315
- package/dist/routes/file.test.js.map +0 -1
- package/dist/routes/files.test.d.ts +0 -1
- package/dist/routes/files.test.js +0 -222
- package/dist/routes/files.test.js.map +0 -1
- package/dist/routes/search.test.d.ts +0 -1
- package/dist/routes/search.test.js +0 -780
- package/dist/routes/search.test.js.map +0 -1
- package/dist/test/helpers/fastify.d.ts +0 -9
- package/dist/test/helpers/fastify.js +0 -18
- package/dist/test/helpers/fastify.js.map +0 -1
- package/dist/test/integration.setup.d.ts +0 -29
- package/dist/test/integration.setup.js +0 -187
- package/dist/test/integration.setup.js.map +0 -1
- package/dist/test/integration.test.d.ts +0 -1
- package/dist/test/integration.test.js +0 -396
- package/dist/test/integration.test.js.map +0 -1
- package/dist/transformers/default.test.d.ts +0 -1
- package/dist/transformers/default.test.js +0 -163
- package/dist/transformers/default.test.js.map +0 -1
- package/dist/transformers/transformer.test.d.ts +0 -1
- package/dist/transformers/transformer.test.js +0 -187
- package/dist/transformers/transformer.test.js.map +0 -1
- package/dist/types/fileHandlers.d.ts +0 -41
- package/dist/types/fileHandlers.js +0 -2
- package/dist/types/fileHandlers.js.map +0 -1
- package/dist/utils/errors.test.d.ts +0 -1
- package/dist/utils/errors.test.js +0 -66
- package/dist/utils/errors.test.js.map +0 -1
- package/dist/utils/queryBuilder.d.ts +0 -35
- package/dist/utils/queryBuilder.js +0 -98
- package/dist/utils/queryBuilder.js.map +0 -1
- package/prisma.config.ts +0 -9
- package/src/app.test.ts +0 -112
- package/src/index.dev.ts +0 -200
- package/src/reset.d.ts +0 -1
- package/src/routes/__snapshots__/entities.test.ts.snap +0 -96
- package/src/routes/__snapshots__/entity.test.ts.snap +0 -74
- package/src/routes/__snapshots__/search.test.ts.snap +0 -165
- package/src/routes/crate.test.ts +0 -423
- package/src/routes/entities.test.ts +0 -320
- package/src/routes/entity.test.ts +0 -160
- package/src/routes/file.test.ts +0 -395
- package/src/routes/files.test.ts +0 -278
- package/src/routes/search.test.ts +0 -903
- package/src/test/__snapshots__/integration.test.ts.snap +0 -18
- package/src/test/helpers/fastify.ts +0 -27
- package/src/test/integration.setup.ts +0 -209
- package/src/test/integration.test.ts +0 -482
- package/src/transformers/default.test.ts +0 -184
- package/src/transformers/transformer.test.ts +0 -252
- package/src/types/fileHandlers.ts +0 -65
- package/src/utils/errors.test.ts +0 -75
- 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
|
-
};
|
package/src/utils/errors.test.ts
DELETED
|
@@ -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
|
-
}
|