arocapi 4.0.1 → 5.0.0-beta.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.
- package/README.md +76 -33
- package/dist/app.d.ts +2 -3
- package/dist/app.js +7 -9
- package/dist/app.js.map +1 -1
- package/dist/app.test.js +0 -7
- package/dist/app.test.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/capabilities.test.d.ts +1 -0
- package/dist/routes/capabilities.test.js +81 -0
- package/dist/routes/capabilities.test.js.map +1 -0
- package/dist/routes/crate.test.js +23 -23
- package/dist/routes/crate.test.js.map +1 -1
- package/dist/routes/entities.js +1 -1
- package/dist/routes/entities.js.map +1 -1
- package/dist/routes/entity.js +1 -1
- package/dist/routes/entity.js.map +1 -1
- package/dist/routes/file.js +1 -1
- package/dist/routes/file.js.map +1 -1
- package/dist/routes/files.js +1 -1
- package/dist/routes/files.js.map +1 -1
- package/dist/routes/{crate.js → metadata.js} +4 -4
- package/dist/routes/metadata.js.map +1 -0
- package/dist/routes/search.d.ts +2 -3
- package/dist/routes/search.js +2 -4
- package/dist/routes/search.js.map +1 -1
- package/dist/routes/search.test.js +8 -1
- package/dist/routes/search.test.js.map +1 -1
- package/dist/test/helpers/fastify.d.ts +1 -1
- package/dist/test/integration.setup.d.ts +1 -1
- package/dist/test/integration.setup.js +0 -1
- package/dist/test/integration.setup.js.map +1 -1
- package/dist/utils/errors.d.ts +7 -7
- package/dist/utils/queryBuilder.d.ts +12 -0
- package/dist/utils/queryBuilder.js +9 -0
- package/dist/utils/queryBuilder.js.map +1 -1
- package/package.json +34 -37
- package/src/app.test.ts +0 -7
- package/src/app.ts +9 -12
- package/src/routes/__snapshots__/capabilities.test.ts.snap +34 -0
- package/src/routes/capabilities.test.ts +102 -0
- package/src/routes/capabilities.ts +22 -0
- package/src/routes/crate.test.ts +23 -23
- package/src/routes/entities.ts +1 -1
- package/src/routes/entity.ts +1 -1
- package/src/routes/file.ts +1 -1
- package/src/routes/files.ts +1 -1
- package/src/routes/{crate.ts → metadata.ts} +3 -3
- package/src/routes/search.test.ts +8 -1
- package/src/routes/search.ts +4 -13
- package/src/test/integration.setup.ts +0 -1
- package/src/utils/errors.ts +1 -1
- package/src/utils/queryBuilder.ts +25 -0
- package/dist/express.d.ts +0 -4
- package/dist/express.js +0 -14
- package/dist/express.js.map +0 -1
- package/dist/routes/crate.js.map +0 -1
- package/src/express.ts +0 -21
- /package/dist/routes/{crate.d.ts → metadata.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "arocapi",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0-beta.2",
|
|
5
5
|
"description": "An RO-Crate API",
|
|
6
6
|
"main": "dist/app.js",
|
|
7
7
|
"exports": {
|
|
8
|
-
".": "./dist/app.js"
|
|
9
|
-
"./express": "./dist/express.js"
|
|
8
|
+
".": "./dist/app.js"
|
|
10
9
|
},
|
|
11
10
|
"keywords": [
|
|
12
11
|
"rocrate",
|
|
@@ -15,41 +14,38 @@
|
|
|
15
14
|
"author": "John Ferlito <johnf@inodes.org>",
|
|
16
15
|
"license": "ISC",
|
|
17
16
|
"dependencies": {
|
|
18
|
-
"@fastify/
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"fastify-type-provider-zod": "^6.1.0",
|
|
26
|
-
"zod": "^4.3.6"
|
|
17
|
+
"@fastify/sensible": "^6.0.7",
|
|
18
|
+
"@opensearch-project/opensearch": "^3.9.0",
|
|
19
|
+
"@prisma/config": "^7.10.0",
|
|
20
|
+
"dotenv": "^18.0.7",
|
|
21
|
+
"fastify": "^5.12.5",
|
|
22
|
+
"fastify-type-provider-zod": "^7.0.0",
|
|
23
|
+
"zod": "^4.6.6"
|
|
27
24
|
},
|
|
28
25
|
"devDependencies": {
|
|
29
|
-
"@biomejs/biome": "^2.
|
|
30
|
-
"@commitlint/cli": "^
|
|
31
|
-
"@commitlint/config-conventional": "^
|
|
32
|
-
"@prisma/adapter-mariadb": "^7.
|
|
33
|
-
"@prisma/client": "^7.
|
|
34
|
-
"@semantic-release/changelog": "^
|
|
35
|
-
"@semantic-release/git": "^
|
|
26
|
+
"@biomejs/biome": "^2.5.15",
|
|
27
|
+
"@commitlint/cli": "^21.2.3",
|
|
28
|
+
"@commitlint/config-conventional": "^21.2.3",
|
|
29
|
+
"@prisma/adapter-mariadb": "^7.10.0",
|
|
30
|
+
"@prisma/client": "^7.10.0",
|
|
31
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
32
|
+
"@semantic-release/git": "^11.0.1",
|
|
36
33
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
37
|
-
"@types/
|
|
38
|
-
"@
|
|
39
|
-
"@vitest/
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"conventional-changelog-conventionalcommits": "^9.3.0",
|
|
34
|
+
"@types/node": "^26.6.5",
|
|
35
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
36
|
+
"@vitest/ui": "^5.0.3",
|
|
37
|
+
"concurrently": "^10.0.6",
|
|
38
|
+
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
43
39
|
"fastify-tsconfig": "^3.0.0",
|
|
44
|
-
"knip": "^6.0
|
|
45
|
-
"lefthook": "^2.1
|
|
46
|
-
"prisma": "^7.
|
|
47
|
-
"prisma-json-types-generator": "^
|
|
48
|
-
"semantic-release": "^25.0.
|
|
49
|
-
"tsx": "^4.
|
|
50
|
-
"typescript": "^
|
|
51
|
-
"vitest": "^
|
|
52
|
-
"vitest-mock-extended": "^
|
|
40
|
+
"knip": "^6.41.0",
|
|
41
|
+
"lefthook": "^2.2.1",
|
|
42
|
+
"prisma": "^7.10.0",
|
|
43
|
+
"prisma-json-types-generator": "^5.1.1",
|
|
44
|
+
"semantic-release": "^25.0.9",
|
|
45
|
+
"tsx": "^4.23.15",
|
|
46
|
+
"typescript": "^7.0.2",
|
|
47
|
+
"vitest": "^5.0.3",
|
|
48
|
+
"vitest-mock-extended": "^5.1.1"
|
|
53
49
|
},
|
|
54
50
|
"peerDependencies": {
|
|
55
51
|
"@prisma/client": ">=6"
|
|
@@ -75,10 +71,11 @@
|
|
|
75
71
|
"lint:types": "tsc --noEmit",
|
|
76
72
|
"lint:knip": "knip",
|
|
77
73
|
"lint": "concurrently -p \"[{name}]\" -n \"biome,types,knip\" -c \"yellow.bold,cyan.bold,magenta.bold\" \"pnpm:lint:biome\" \"pnpm:lint:types\" \"pnpm:lint:knip\"",
|
|
78
|
-
"test": "vitest run",
|
|
74
|
+
"test": "./scripts/setup-integration.sh vitest run",
|
|
75
|
+
"test:ci": "vitest run",
|
|
79
76
|
"test:watch": "./scripts/setup-integration.sh && vitest",
|
|
80
77
|
"test:ui": "./scripts/setup-integration.sh && vitest --ui",
|
|
81
|
-
"test:coverage": "./scripts/setup-integration.sh
|
|
78
|
+
"test:coverage": "./scripts/setup-integration.sh vitest run --coverage",
|
|
82
79
|
"generate": "npx prisma generate",
|
|
83
80
|
"db:generate": "prisma generate",
|
|
84
81
|
"db:migrate": "prisma migrate deploy",
|
|
@@ -92,5 +89,5 @@
|
|
|
92
89
|
"registry": "https://registry.npmjs.org/",
|
|
93
90
|
"provenance": true
|
|
94
91
|
},
|
|
95
|
-
"packageManager": "pnpm@
|
|
92
|
+
"packageManager": "pnpm@12.11.2"
|
|
96
93
|
}
|
package/src/app.test.ts
CHANGED
|
@@ -19,7 +19,6 @@ describe('Entity Route', () => {
|
|
|
19
19
|
// @ts-expect-error we are testing missing options
|
|
20
20
|
fastify.register(app, {
|
|
21
21
|
opensearch,
|
|
22
|
-
disableCors: false,
|
|
23
22
|
});
|
|
24
23
|
|
|
25
24
|
await expect(() => fastify.ready()).rejects.toThrowError('Prisma client is required');
|
|
@@ -31,7 +30,6 @@ describe('Entity Route', () => {
|
|
|
31
30
|
// @ts-expect-error we are testing missing options
|
|
32
31
|
fastify.register(app, {
|
|
33
32
|
prisma,
|
|
34
|
-
disableCors: false,
|
|
35
33
|
});
|
|
36
34
|
|
|
37
35
|
await expect(() => fastify.ready()).rejects.toThrowError('OpenSearch client is required');
|
|
@@ -44,7 +42,6 @@ describe('Entity Route', () => {
|
|
|
44
42
|
fastify.register(app, {
|
|
45
43
|
prisma,
|
|
46
44
|
opensearch,
|
|
47
|
-
disableCors: false,
|
|
48
45
|
});
|
|
49
46
|
|
|
50
47
|
await expect(() => fastify.ready()).rejects.toThrowError('accessTransformer is required');
|
|
@@ -57,7 +54,6 @@ describe('Entity Route', () => {
|
|
|
57
54
|
fastify.register(app, {
|
|
58
55
|
prisma,
|
|
59
56
|
opensearch,
|
|
60
|
-
disableCors: false,
|
|
61
57
|
accessTransformer: AllPublicAccessTransformer,
|
|
62
58
|
});
|
|
63
59
|
|
|
@@ -71,7 +67,6 @@ describe('Entity Route', () => {
|
|
|
71
67
|
fastify.register(app, {
|
|
72
68
|
prisma,
|
|
73
69
|
opensearch,
|
|
74
|
-
disableCors: false,
|
|
75
70
|
accessTransformer: AllPublicAccessTransformer,
|
|
76
71
|
fileAccessTransformer: AllPublicFileAccessTransformer,
|
|
77
72
|
});
|
|
@@ -86,7 +81,6 @@ describe('Entity Route', () => {
|
|
|
86
81
|
fastify.register(app, {
|
|
87
82
|
prisma,
|
|
88
83
|
opensearch,
|
|
89
|
-
disableCors: false,
|
|
90
84
|
accessTransformer: AllPublicAccessTransformer,
|
|
91
85
|
fileAccessTransformer: AllPublicFileAccessTransformer,
|
|
92
86
|
fileHandler: {
|
|
@@ -104,7 +98,6 @@ describe('Entity Route', () => {
|
|
|
104
98
|
await fastify.register(app, {
|
|
105
99
|
prisma,
|
|
106
100
|
opensearch,
|
|
107
|
-
disableCors: false,
|
|
108
101
|
accessTransformer: AllPublicAccessTransformer,
|
|
109
102
|
fileAccessTransformer: AllPublicFileAccessTransformer,
|
|
110
103
|
fileHandler: { get: vi.fn(), head: vi.fn() },
|
package/src/app.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import cors from '@fastify/cors';
|
|
2
1
|
import sensible from '@fastify/sensible';
|
|
3
2
|
import type { Client } from '@opensearch-project/opensearch';
|
|
4
3
|
import type { FastifyInstance, FastifyPluginAsync } from 'fastify';
|
|
5
4
|
import { hasZodFastifySchemaValidationErrors, serializerCompiler, validatorCompiler } from 'fastify-type-provider-zod';
|
|
6
5
|
import type { PrismaClient } from './generated/prisma/client.js';
|
|
7
|
-
import
|
|
6
|
+
import capabilities from './routes/capabilities.js';
|
|
8
7
|
import entities from './routes/entities.js';
|
|
9
8
|
import entity from './routes/entity.js';
|
|
10
9
|
import file from './routes/file.js';
|
|
11
10
|
import files from './routes/files.js';
|
|
11
|
+
import metadata from './routes/metadata.js';
|
|
12
12
|
import search from './routes/search.js';
|
|
13
13
|
import type { FileHandler, RoCrateHandler } from './types/fileHandlers.js';
|
|
14
14
|
import type {
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
FileTransformer,
|
|
19
19
|
} from './types/transformers.js';
|
|
20
20
|
import { createValidationError } from './utils/errors.js';
|
|
21
|
-
import type { QueryBuilderOptions } from './utils/queryBuilder.js';
|
|
21
|
+
import type { FacetCapability, FilterCapability, QueryBuilderOptions, SearchCapability } from './utils/queryBuilder.js';
|
|
22
22
|
import { OpensearchQueryBuilder } from './utils/queryBuilder.js';
|
|
23
23
|
|
|
24
24
|
export type { AuthorisedEntity, AuthorisedFile, StandardEntity, StandardFile } from './transformers/default.js';
|
|
@@ -44,7 +44,7 @@ export type {
|
|
|
44
44
|
FileTransformer,
|
|
45
45
|
TransformerContext,
|
|
46
46
|
} from './types/transformers.js';
|
|
47
|
-
export type { QueryBuilderOptions };
|
|
47
|
+
export type { FacetCapability, FilterCapability, QueryBuilderOptions, SearchCapability };
|
|
48
48
|
export { OpensearchQueryBuilder };
|
|
49
49
|
|
|
50
50
|
const setupValidation = (fastify: FastifyInstance) => {
|
|
@@ -76,7 +76,6 @@ export type Options = {
|
|
|
76
76
|
opensearch: Client;
|
|
77
77
|
queryBuilderClass?: typeof OpensearchQueryBuilder;
|
|
78
78
|
queryBuilderOptions?: QueryBuilderOptions;
|
|
79
|
-
disableCors?: boolean;
|
|
80
79
|
accessTransformer: AccessTransformer;
|
|
81
80
|
entityTransformers?: EntityTransformer[];
|
|
82
81
|
fileAccessTransformer: FileAccessTransformer;
|
|
@@ -90,7 +89,6 @@ const app: FastifyPluginAsync<Options> = async (fastify, options) => {
|
|
|
90
89
|
opensearch,
|
|
91
90
|
queryBuilderClass,
|
|
92
91
|
queryBuilderOptions,
|
|
93
|
-
disableCors = false,
|
|
94
92
|
accessTransformer,
|
|
95
93
|
entityTransformers,
|
|
96
94
|
fileAccessTransformer,
|
|
@@ -124,23 +122,22 @@ const app: FastifyPluginAsync<Options> = async (fastify, options) => {
|
|
|
124
122
|
}
|
|
125
123
|
|
|
126
124
|
fastify.register(sensible);
|
|
127
|
-
if (!disableCors) {
|
|
128
|
-
fastify.register(cors);
|
|
129
|
-
}
|
|
130
125
|
setupValidation(fastify);
|
|
131
126
|
|
|
127
|
+
const queryBuilder = new (queryBuilderClass ?? OpensearchQueryBuilder)(queryBuilderOptions);
|
|
128
|
+
|
|
129
|
+
fastify.register(capabilities, { queryBuilder });
|
|
132
130
|
fastify.register(entities, { prisma, accessTransformer, entityTransformers });
|
|
133
131
|
fastify.register(entity, { prisma, accessTransformer, entityTransformers });
|
|
134
132
|
fastify.register(files, { prisma, fileAccessTransformer, fileTransformers });
|
|
135
133
|
fastify.register(file, { prisma, fileHandler });
|
|
136
|
-
fastify.register(
|
|
134
|
+
fastify.register(metadata, { prisma, roCrateHandler });
|
|
137
135
|
fastify.register(search, {
|
|
138
136
|
prisma,
|
|
139
137
|
opensearch,
|
|
140
138
|
accessTransformer,
|
|
141
139
|
entityTransformers,
|
|
142
|
-
|
|
143
|
-
queryBuilderOptions,
|
|
140
|
+
queryBuilder,
|
|
144
141
|
});
|
|
145
142
|
};
|
|
146
143
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`Capabilities Route > GET /capabilities > should declare the default capabilities 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"apiVersion": "0.4.0",
|
|
6
|
+
"deposit": {
|
|
7
|
+
"supported": false,
|
|
8
|
+
},
|
|
9
|
+
"extensions": {},
|
|
10
|
+
"search": {
|
|
11
|
+
"facets": {
|
|
12
|
+
"communicationMode": {},
|
|
13
|
+
"entityType": {},
|
|
14
|
+
"inLanguage": {},
|
|
15
|
+
"mediaType": {},
|
|
16
|
+
},
|
|
17
|
+
"filters": {
|
|
18
|
+
"communicationMode": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
},
|
|
21
|
+
"entityType": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
},
|
|
24
|
+
"inLanguage": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
},
|
|
27
|
+
"mediaType": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
"tombstonePolicy": "404",
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import app, { AllPublicFileAccessTransformer, type Options } from '../app.js';
|
|
4
|
+
import { fastify, fastifyAfter, fastifyBefore, opensearch, prisma } from '../test/helpers/fastify.js';
|
|
5
|
+
import { AllPublicAccessTransformer } from '../transformers/default.js';
|
|
6
|
+
import { OpensearchQueryBuilder, type SearchCapability } from '../utils/queryBuilder.js';
|
|
7
|
+
|
|
8
|
+
const registerApp = async (options: Partial<Options> = {}) => {
|
|
9
|
+
await fastifyBefore();
|
|
10
|
+
await fastify.register(app, {
|
|
11
|
+
prisma,
|
|
12
|
+
opensearch,
|
|
13
|
+
accessTransformer: AllPublicAccessTransformer,
|
|
14
|
+
fileAccessTransformer: AllPublicFileAccessTransformer,
|
|
15
|
+
fileHandler: { get: vi.fn(), head: vi.fn() },
|
|
16
|
+
roCrateHandler: { get: vi.fn(), head: vi.fn() },
|
|
17
|
+
...options,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getCapabilities = async () => {
|
|
22
|
+
const response = await fastify.inject({ method: 'GET', url: '/capabilities' });
|
|
23
|
+
|
|
24
|
+
return { statusCode: response.statusCode, body: response.json<{ search: SearchCapability }>() };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('Capabilities Route', () => {
|
|
28
|
+
afterEach(async () => {
|
|
29
|
+
await fastifyAfter();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('GET /capabilities', () => {
|
|
33
|
+
it('should declare the default capabilities', async () => {
|
|
34
|
+
await registerApp();
|
|
35
|
+
|
|
36
|
+
const { statusCode, body } = await getCapabilities();
|
|
37
|
+
|
|
38
|
+
expect(statusCode).toBe(200);
|
|
39
|
+
expect(body).toMatchSnapshot();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should declare every facet as a filter', async () => {
|
|
43
|
+
await registerApp();
|
|
44
|
+
|
|
45
|
+
const { body } = await getCapabilities();
|
|
46
|
+
|
|
47
|
+
expect(Object.keys(body.search.filters)).toEqual(expect.arrayContaining(Object.keys(body.search.facets)));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should declare only terms aggregations', async () => {
|
|
51
|
+
await registerApp({
|
|
52
|
+
queryBuilderOptions: {
|
|
53
|
+
aggregations: {
|
|
54
|
+
inLanguage: { terms: { size: 20 } },
|
|
55
|
+
dateCreated: { date_histogram: { field: 'dateCreated', calendar_interval: 'year' } },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const { body } = await getCapabilities();
|
|
61
|
+
|
|
62
|
+
expect(body.search).toEqual({
|
|
63
|
+
filters: { inLanguage: { type: 'string' } },
|
|
64
|
+
facets: { inLanguage: {} },
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should use an overridden searchCapabilities', async () => {
|
|
69
|
+
const labelled: SearchCapability = {
|
|
70
|
+
filters: {
|
|
71
|
+
inLanguage: { type: 'string', label: 'Language' },
|
|
72
|
+
dateCreated: { type: 'date', label: 'Date created' },
|
|
73
|
+
},
|
|
74
|
+
facets: { inLanguage: { label: 'Language' } },
|
|
75
|
+
};
|
|
76
|
+
class LabelledQueryBuilder extends OpensearchQueryBuilder {
|
|
77
|
+
searchCapabilities() {
|
|
78
|
+
return labelled;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
await registerApp({ queryBuilderClass: LabelledQueryBuilder });
|
|
83
|
+
|
|
84
|
+
const { body } = await getCapabilities();
|
|
85
|
+
|
|
86
|
+
expect(body.search).toEqual(labelled);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should not run the access transformer', async () => {
|
|
90
|
+
const accessTransformer = vi.fn(() => {
|
|
91
|
+
throw new Error('Unauthorised');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
await registerApp({ accessTransformer });
|
|
95
|
+
|
|
96
|
+
const { statusCode } = await getCapabilities();
|
|
97
|
+
|
|
98
|
+
expect(statusCode).toBe(200);
|
|
99
|
+
expect(accessTransformer).not.toHaveBeenCalled();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FastifyPluginAsync } from 'fastify';
|
|
2
|
+
import type { OpensearchQueryBuilder } from '../utils/queryBuilder.js';
|
|
3
|
+
|
|
4
|
+
const SPEC_VERSION = '0.4.0';
|
|
5
|
+
|
|
6
|
+
type CapabilitiesRouteOptions = {
|
|
7
|
+
queryBuilder: OpensearchQueryBuilder;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const capabilities: FastifyPluginAsync<CapabilitiesRouteOptions> = async (fastify, opts) => {
|
|
11
|
+
const document = {
|
|
12
|
+
apiVersion: SPEC_VERSION,
|
|
13
|
+
deposit: { supported: false },
|
|
14
|
+
tombstonePolicy: '404',
|
|
15
|
+
extensions: {},
|
|
16
|
+
search: opts.queryBuilder.searchCapabilities(),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
fastify.get('/capabilities', async () => document);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default capabilities;
|
package/src/routes/crate.test.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
4
4
|
import { fastify, fastifyAfter, fastifyBefore, prisma } from '../test/helpers/fastify.js';
|
|
5
5
|
import type { FileResult, RoCrateHandler } from '../types/fileHandlers.js';
|
|
6
6
|
import type { StandardErrorResponse } from '../utils/errors.js';
|
|
7
|
-
import
|
|
7
|
+
import metadataRoute from './metadata.js';
|
|
8
8
|
|
|
9
9
|
vi.mock('node:fs', () => ({
|
|
10
10
|
createReadStream: vi.fn(),
|
|
@@ -18,7 +18,7 @@ describe('Crate Route', () => {
|
|
|
18
18
|
|
|
19
19
|
beforeEach(async () => {
|
|
20
20
|
await fastifyBefore();
|
|
21
|
-
await fastify.register(
|
|
21
|
+
await fastify.register(metadataRoute, { prisma, roCrateHandler: mockRoCrateHandler });
|
|
22
22
|
vi.clearAllMocks();
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -58,7 +58,7 @@ describe('Crate Route', () => {
|
|
|
58
58
|
rootCollection: 'http://example.com/collection',
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
describe('GET /entity/:id/
|
|
61
|
+
describe('GET /entity/:id/metadata', () => {
|
|
62
62
|
it('should stream RO-Crate metadata for File entity', async () => {
|
|
63
63
|
prisma.entity.findUnique.mockResolvedValue(mockFileEntity);
|
|
64
64
|
|
|
@@ -77,7 +77,7 @@ describe('Crate Route', () => {
|
|
|
77
77
|
|
|
78
78
|
const response = await fastify.inject({
|
|
79
79
|
method: 'GET',
|
|
80
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
80
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
expect(response.statusCode).toBe(200);
|
|
@@ -111,7 +111,7 @@ describe('Crate Route', () => {
|
|
|
111
111
|
|
|
112
112
|
const response = await fastify.inject({
|
|
113
113
|
method: 'GET',
|
|
114
|
-
url: `/entity/${encodeURIComponent('http://example.com/collection')}/
|
|
114
|
+
url: `/entity/${encodeURIComponent('http://example.com/collection')}/metadata`,
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
expect(response.statusCode).toBe(200);
|
|
@@ -135,7 +135,7 @@ describe('Crate Route', () => {
|
|
|
135
135
|
|
|
136
136
|
const response = await fastify.inject({
|
|
137
137
|
method: 'GET',
|
|
138
|
-
url: `/entity/${encodeURIComponent('http://example.com/object')}/
|
|
138
|
+
url: `/entity/${encodeURIComponent('http://example.com/object')}/metadata`,
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
expect(response.statusCode).toBe(200);
|
|
@@ -154,7 +154,7 @@ describe('Crate Route', () => {
|
|
|
154
154
|
|
|
155
155
|
const response = await fastify.inject({
|
|
156
156
|
method: 'GET',
|
|
157
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
157
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
158
158
|
});
|
|
159
159
|
|
|
160
160
|
expect(response.statusCode).toBe(302);
|
|
@@ -179,7 +179,7 @@ describe('Crate Route', () => {
|
|
|
179
179
|
|
|
180
180
|
const response = await fastify.inject({
|
|
181
181
|
method: 'GET',
|
|
182
|
-
url: `/entity/${encodeURIComponent('http://example.com/collection')}/
|
|
182
|
+
url: `/entity/${encodeURIComponent('http://example.com/collection')}/metadata`,
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
expect(response.statusCode).toBe(200);
|
|
@@ -205,7 +205,7 @@ describe('Crate Route', () => {
|
|
|
205
205
|
|
|
206
206
|
const response = await fastify.inject({
|
|
207
207
|
method: 'GET',
|
|
208
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
208
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
209
209
|
});
|
|
210
210
|
|
|
211
211
|
expect(response.statusCode).toBe(200);
|
|
@@ -219,7 +219,7 @@ describe('Crate Route', () => {
|
|
|
219
219
|
|
|
220
220
|
const response = await fastify.inject({
|
|
221
221
|
method: 'GET',
|
|
222
|
-
url: `/entity/${encodeURIComponent('http://example.com/nonexistent')}/
|
|
222
|
+
url: `/entity/${encodeURIComponent('http://example.com/nonexistent')}/metadata`,
|
|
223
223
|
});
|
|
224
224
|
const body = JSON.parse(response.body) as { error: { code: string; message: string } };
|
|
225
225
|
|
|
@@ -235,7 +235,7 @@ describe('Crate Route', () => {
|
|
|
235
235
|
|
|
236
236
|
const response = await fastify.inject({
|
|
237
237
|
method: 'GET',
|
|
238
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
238
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
239
239
|
});
|
|
240
240
|
const body = JSON.parse(response.body) as { error: { code: string; message: string } };
|
|
241
241
|
|
|
@@ -249,7 +249,7 @@ describe('Crate Route', () => {
|
|
|
249
249
|
|
|
250
250
|
const response = await fastify.inject({
|
|
251
251
|
method: 'GET',
|
|
252
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
252
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
253
253
|
});
|
|
254
254
|
const body = JSON.parse(response.body) as { error: { code: string } };
|
|
255
255
|
|
|
@@ -263,7 +263,7 @@ describe('Crate Route', () => {
|
|
|
263
263
|
|
|
264
264
|
const response = await fastify.inject({
|
|
265
265
|
method: 'GET',
|
|
266
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
266
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
267
267
|
});
|
|
268
268
|
const body = JSON.parse(response.body) as { error: { code: string } };
|
|
269
269
|
|
|
@@ -274,7 +274,7 @@ describe('Crate Route', () => {
|
|
|
274
274
|
it('should validate ID parameter format', async () => {
|
|
275
275
|
const response = await fastify.inject({
|
|
276
276
|
method: 'GET',
|
|
277
|
-
url: '/entity/invalid-id/
|
|
277
|
+
url: '/entity/invalid-id/metadata',
|
|
278
278
|
});
|
|
279
279
|
const body = JSON.parse(response.body) as StandardErrorResponse;
|
|
280
280
|
|
|
@@ -283,7 +283,7 @@ describe('Crate Route', () => {
|
|
|
283
283
|
});
|
|
284
284
|
});
|
|
285
285
|
|
|
286
|
-
describe('HEAD /entity/:id/
|
|
286
|
+
describe('HEAD /entity/:id/metadata', () => {
|
|
287
287
|
it('should return RO-Crate metadata headers for File entity', async () => {
|
|
288
288
|
prisma.entity.findUnique.mockResolvedValue(mockFileEntity);
|
|
289
289
|
|
|
@@ -297,7 +297,7 @@ describe('Crate Route', () => {
|
|
|
297
297
|
|
|
298
298
|
const response = await fastify.inject({
|
|
299
299
|
method: 'HEAD',
|
|
300
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
300
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
301
301
|
});
|
|
302
302
|
|
|
303
303
|
expect(response.statusCode).toBe(200);
|
|
@@ -326,7 +326,7 @@ describe('Crate Route', () => {
|
|
|
326
326
|
|
|
327
327
|
const response = await fastify.inject({
|
|
328
328
|
method: 'HEAD',
|
|
329
|
-
url: `/entity/${encodeURIComponent('http://example.com/collection')}/
|
|
329
|
+
url: `/entity/${encodeURIComponent('http://example.com/collection')}/metadata`,
|
|
330
330
|
});
|
|
331
331
|
|
|
332
332
|
expect(response.statusCode).toBe(200);
|
|
@@ -346,7 +346,7 @@ describe('Crate Route', () => {
|
|
|
346
346
|
|
|
347
347
|
const response = await fastify.inject({
|
|
348
348
|
method: 'HEAD',
|
|
349
|
-
url: `/entity/${encodeURIComponent('http://example.com/object')}/
|
|
349
|
+
url: `/entity/${encodeURIComponent('http://example.com/object')}/metadata`,
|
|
350
350
|
});
|
|
351
351
|
|
|
352
352
|
expect(response.statusCode).toBe(200);
|
|
@@ -360,7 +360,7 @@ describe('Crate Route', () => {
|
|
|
360
360
|
|
|
361
361
|
const response = await fastify.inject({
|
|
362
362
|
method: 'HEAD',
|
|
363
|
-
url: `/entity/${encodeURIComponent('http://example.com/nonexistent')}/
|
|
363
|
+
url: `/entity/${encodeURIComponent('http://example.com/nonexistent')}/metadata`,
|
|
364
364
|
});
|
|
365
365
|
const body = JSON.parse(response.body) as { error: { code: string } };
|
|
366
366
|
|
|
@@ -375,7 +375,7 @@ describe('Crate Route', () => {
|
|
|
375
375
|
|
|
376
376
|
const response = await fastify.inject({
|
|
377
377
|
method: 'HEAD',
|
|
378
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
378
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
379
379
|
});
|
|
380
380
|
const body = JSON.parse(response.body) as { error: { code: string; message: string } };
|
|
381
381
|
|
|
@@ -390,7 +390,7 @@ describe('Crate Route', () => {
|
|
|
390
390
|
|
|
391
391
|
const response = await fastify.inject({
|
|
392
392
|
method: 'HEAD',
|
|
393
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
393
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
394
394
|
});
|
|
395
395
|
const body = JSON.parse(response.body) as { error: { code: string } };
|
|
396
396
|
|
|
@@ -399,7 +399,7 @@ describe('Crate Route', () => {
|
|
|
399
399
|
});
|
|
400
400
|
});
|
|
401
401
|
|
|
402
|
-
describe('GET /entity/:id/
|
|
402
|
+
describe('GET /entity/:id/metadata - exhaustiveness check', () => {
|
|
403
403
|
it('should handle unexpected RO-Crate result type', async () => {
|
|
404
404
|
prisma.entity.findUnique.mockResolvedValue(mockFileEntity);
|
|
405
405
|
|
|
@@ -412,7 +412,7 @@ describe('Crate Route', () => {
|
|
|
412
412
|
|
|
413
413
|
const response = await fastify.inject({
|
|
414
414
|
method: 'GET',
|
|
415
|
-
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/
|
|
415
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/file.wav')}/metadata`,
|
|
416
416
|
});
|
|
417
417
|
const body = JSON.parse(response.body) as { error: { code: string } };
|
|
418
418
|
|
package/src/routes/entities.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FastifyPluginAsync } from 'fastify';
|
|
2
2
|
import type { ZodTypeProvider } from 'fastify-type-provider-zod';
|
|
3
|
-
import { z } from 'zod
|
|
3
|
+
import { z } from 'zod';
|
|
4
4
|
import type { PrismaClient } from '../generated/prisma/client.js';
|
|
5
5
|
import { baseEntityTransformer, resolveEntityReferences } from '../transformers/default.js';
|
|
6
6
|
import type { AccessTransformer, EntityTransformer } from '../types/transformers.js';
|
package/src/routes/entity.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FastifyPluginAsync } from 'fastify';
|
|
2
2
|
import type { ZodTypeProvider } from 'fastify-type-provider-zod';
|
|
3
|
-
import { z } from 'zod
|
|
3
|
+
import { z } from 'zod';
|
|
4
4
|
import type { PrismaClient } from '../generated/prisma/client.js';
|
|
5
5
|
import { baseEntityTransformer, resolveEntityReferences } from '../transformers/default.js';
|
|
6
6
|
import type { AccessTransformer, EntityTransformer } from '../types/transformers.js';
|
package/src/routes/file.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createReadStream } from 'node:fs';
|
|
2
2
|
import type { FastifyPluginAsync } from 'fastify';
|
|
3
3
|
import type { ZodTypeProvider } from 'fastify-type-provider-zod';
|
|
4
|
-
import { z } from 'zod
|
|
4
|
+
import { z } from 'zod';
|
|
5
5
|
import type { PrismaClient } from '../generated/prisma/client.js';
|
|
6
6
|
import type { FileHandler, FileMetadata } from '../types/fileHandlers.js';
|
|
7
7
|
import { createInternalError, createNotFoundError } from '../utils/errors.js';
|
package/src/routes/files.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FastifyPluginAsync } from 'fastify';
|
|
2
2
|
import type { ZodTypeProvider } from 'fastify-type-provider-zod';
|
|
3
|
-
import { z } from 'zod
|
|
3
|
+
import { z } from 'zod';
|
|
4
4
|
import type { PrismaClient } from '../generated/prisma/client.js';
|
|
5
5
|
import { baseFileTransformer } from '../transformers/default.js';
|
|
6
6
|
import type { FileAccessTransformer, FileTransformer } from '../types/transformers.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createReadStream } from 'node:fs';
|
|
2
2
|
import type { FastifyPluginAsync } from 'fastify';
|
|
3
3
|
import type { ZodTypeProvider } from 'fastify-type-provider-zod';
|
|
4
|
-
import { z } from 'zod
|
|
4
|
+
import { z } from 'zod';
|
|
5
5
|
import type { PrismaClient } from '../generated/prisma/client.js';
|
|
6
6
|
import type { FileMetadata, RoCrateHandler } from '../types/fileHandlers.js';
|
|
7
7
|
import { createInternalError, createNotFoundError } from '../utils/errors.js';
|
|
@@ -20,7 +20,7 @@ const crate: FastifyPluginAsync<CrateRouteOptions> = async (fastify, opts) => {
|
|
|
20
20
|
const { prisma, roCrateHandler } = opts;
|
|
21
21
|
|
|
22
22
|
fastify.withTypeProvider<ZodTypeProvider>().head(
|
|
23
|
-
'/entity/:id/
|
|
23
|
+
'/entity/:id/metadata',
|
|
24
24
|
{
|
|
25
25
|
schema: {
|
|
26
26
|
params: paramsSchema,
|
|
@@ -57,7 +57,7 @@ const crate: FastifyPluginAsync<CrateRouteOptions> = async (fastify, opts) => {
|
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
fastify.withTypeProvider<ZodTypeProvider>().get(
|
|
60
|
-
'/entity/:id/
|
|
60
|
+
'/entity/:id/metadata',
|
|
61
61
|
{
|
|
62
62
|
schema: {
|
|
63
63
|
params: paramsSchema,
|