arocapi 1.2.0 → 2.0.0
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 +5 -0
- package/README.md +134 -37
- package/dist/app.js +4 -3
- package/dist/app.js.map +1 -1
- package/dist/routes/crate.js +4 -2
- package/dist/routes/crate.js.map +1 -1
- package/dist/routes/crate.test.js +0 -16
- package/dist/routes/crate.test.js.map +1 -1
- package/dist/routes/entities.js +10 -3
- package/dist/routes/entities.js.map +1 -1
- package/dist/routes/entities.test.js +29 -2
- package/dist/routes/entities.test.js.map +1 -1
- package/dist/routes/entity.js +10 -3
- package/dist/routes/entity.js.map +1 -1
- package/dist/routes/entity.test.js +26 -1
- package/dist/routes/entity.test.js.map +1 -1
- package/dist/routes/file.js +4 -2
- package/dist/routes/file.js.map +1 -1
- package/dist/routes/files.js +2 -1
- package/dist/routes/files.js.map +1 -1
- package/dist/routes/search.js +9 -4
- package/dist/routes/search.js.map +1 -1
- package/dist/routes/search.test.js +49 -0
- package/dist/routes/search.test.js.map +1 -1
- package/dist/test/integration.setup.d.ts +0 -27
- package/dist/test/integration.setup.js +0 -13
- package/dist/test/integration.setup.js.map +1 -1
- package/dist/test/integration.test.js +4 -4
- package/dist/test/integration.test.js.map +1 -1
- package/dist/transformers/default.d.ts +26 -3
- package/dist/transformers/default.js +19 -0
- package/dist/transformers/default.js.map +1 -1
- package/dist/transformers/default.test.js +2 -7
- package/dist/transformers/default.test.js.map +1 -1
- package/dist/transformers/transformer.test.js +23 -8
- package/dist/transformers/transformer.test.js.map +1 -1
- package/package.json +18 -20
- package/prisma/migrations/20251211025510_remove_rocrate_column/migration.sql +8 -0
- package/prisma/models/entity.prisma +0 -1
- package/src/app.ts +4 -3
- package/src/routes/__snapshots__/entities.test.ts.snap +30 -2
- package/src/routes/__snapshots__/entity.test.ts.snap +13 -5
- package/src/routes/__snapshots__/search.test.ts.snap +26 -0
- package/src/routes/crate.test.ts +0 -16
- package/src/routes/crate.ts +6 -2
- package/src/routes/entities.test.ts +34 -2
- package/src/routes/entities.ts +13 -3
- package/src/routes/entity.test.ts +31 -1
- package/src/routes/entity.ts +13 -3
- package/src/routes/file.ts +6 -2
- package/src/routes/files.ts +3 -1
- package/src/routes/search.test.ts +56 -0
- package/src/routes/search.ts +11 -4
- package/src/test/integration.setup.ts +0 -13
- package/src/test/integration.test.ts +4 -4
- package/src/transformers/default.test.ts +2 -7
- package/src/transformers/default.ts +65 -7
- package/src/transformers/transformer.test.ts +30 -9
|
@@ -15,7 +15,6 @@ describe('baseEntityTransformer', () => {
|
|
|
15
15
|
contentLicenseId: 'https://creativecommons.org/licenses/by-sa/4.0/',
|
|
16
16
|
createdAt: new Date('2025-01-01'),
|
|
17
17
|
updatedAt: new Date('2025-01-02'),
|
|
18
|
-
rocrate: { '@context': 'test' },
|
|
19
18
|
meta: { test: 'data' },
|
|
20
19
|
};
|
|
21
20
|
const result = baseEntityTransformer(entity);
|
|
@@ -44,7 +43,6 @@ describe('baseEntityTransformer', () => {
|
|
|
44
43
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
45
44
|
createdAt: new Date(),
|
|
46
45
|
updatedAt: new Date(),
|
|
47
|
-
rocrate: {},
|
|
48
46
|
meta: null,
|
|
49
47
|
};
|
|
50
48
|
const result = baseEntityTransformer(entity);
|
|
@@ -65,14 +63,12 @@ describe('baseEntityTransformer', () => {
|
|
|
65
63
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
66
64
|
createdAt: new Date(),
|
|
67
65
|
updatedAt: new Date(),
|
|
68
|
-
rocrate: { test: 'value' },
|
|
69
66
|
meta: { storage: 'path' },
|
|
70
67
|
};
|
|
71
68
|
const result = baseEntityTransformer(entity);
|
|
72
69
|
expect(result.id).toBe('http://example.com/entity/456');
|
|
73
70
|
expect(result).not.toHaveProperty('createdAt');
|
|
74
71
|
expect(result).not.toHaveProperty('updatedAt');
|
|
75
|
-
expect(result).not.toHaveProperty('rocrate');
|
|
76
72
|
expect(result).not.toHaveProperty('meta');
|
|
77
73
|
expect(Object.keys(result)).toEqual([
|
|
78
74
|
'id',
|
|
@@ -99,7 +95,6 @@ describe('baseEntityTransformer', () => {
|
|
|
99
95
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
100
96
|
createdAt: new Date(),
|
|
101
97
|
updatedAt: new Date(),
|
|
102
|
-
rocrate: {},
|
|
103
98
|
meta: null,
|
|
104
99
|
};
|
|
105
100
|
const result = baseEntityTransformer(entity);
|
|
@@ -124,8 +119,8 @@ describe('AllPublicAccessTransformer', () => {
|
|
|
124
119
|
name: 'Test Entity',
|
|
125
120
|
description: 'A test entity',
|
|
126
121
|
entityType: 'http://schema.org/MediaObject',
|
|
127
|
-
memberOf: 'http://example.com/parent',
|
|
128
|
-
rootCollection: 'http://example.com/root',
|
|
122
|
+
memberOf: { id: 'http://example.com/parent', name: 'Parent Entity' },
|
|
123
|
+
rootCollection: { id: 'http://example.com/root', name: 'Root Collection' },
|
|
129
124
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
130
125
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
131
126
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.test.js","sourceRoot":"","sources":["../../src/transformers/default.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEjF,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,MAAM,GAAW;YACrB,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,+BAA+B;YAC1C,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,2BAA2B;YACxC,UAAU,EAAE,mCAA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1D,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,aAAa,EAAE,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -10,8 +10,8 @@ describe('Entity Transformers', () => {
|
|
|
10
10
|
name: 'Test Entity',
|
|
11
11
|
description: 'A test entity',
|
|
12
12
|
entityType: 'http://schema.org/Person',
|
|
13
|
-
memberOf: 'http://example.com/collection',
|
|
14
|
-
rootCollection: 'http://example.com/root',
|
|
13
|
+
memberOf: { id: 'http://example.com/collection', name: 'Test Collection' },
|
|
14
|
+
rootCollection: { id: 'http://example.com/root', name: 'Root Collection' },
|
|
15
15
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
16
16
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
17
17
|
};
|
|
@@ -23,7 +23,7 @@ describe('Entity Transformers', () => {
|
|
|
23
23
|
},
|
|
24
24
|
};
|
|
25
25
|
describe('baseEntityTransformer', () => {
|
|
26
|
-
it('should transform raw entity to
|
|
26
|
+
it('should transform raw entity to base shape with unresolved references', () => {
|
|
27
27
|
const rawEntity = {
|
|
28
28
|
id: 1,
|
|
29
29
|
rocrateId: 'http://example.com/entity/123',
|
|
@@ -35,13 +35,22 @@ describe('Entity Transformers', () => {
|
|
|
35
35
|
rootCollection: 'http://example.com/root',
|
|
36
36
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
37
37
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
38
|
-
rocrate: {},
|
|
39
38
|
meta: {},
|
|
40
39
|
createdAt: new Date(),
|
|
41
40
|
updatedAt: new Date(),
|
|
42
41
|
};
|
|
43
42
|
const result = baseEntityTransformer(rawEntity);
|
|
44
|
-
|
|
43
|
+
const expectedBaseEntity = {
|
|
44
|
+
id: 'http://example.com/entity/123',
|
|
45
|
+
name: 'Test Entity',
|
|
46
|
+
description: 'A test entity',
|
|
47
|
+
entityType: 'http://schema.org/Person',
|
|
48
|
+
memberOf: 'http://example.com/collection',
|
|
49
|
+
rootCollection: 'http://example.com/root',
|
|
50
|
+
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
51
|
+
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
52
|
+
};
|
|
53
|
+
expect(result).toEqual(expectedBaseEntity);
|
|
45
54
|
});
|
|
46
55
|
});
|
|
47
56
|
describe('AllPublicAccessTransformer', () => {
|
|
@@ -128,7 +137,7 @@ describe('Entity Transformers', () => {
|
|
|
128
137
|
upperName: 'TEST ENTITY',
|
|
129
138
|
});
|
|
130
139
|
});
|
|
131
|
-
it('should demonstrate full pipeline: base -> access -> custom', async () => {
|
|
140
|
+
it('should demonstrate full pipeline: base -> resolve -> access -> custom', async () => {
|
|
132
141
|
const rawEntity = {
|
|
133
142
|
id: 1,
|
|
134
143
|
rocrateId: 'http://example.com/entity/123',
|
|
@@ -140,7 +149,6 @@ describe('Entity Transformers', () => {
|
|
|
140
149
|
rootCollection: 'http://example.com/root',
|
|
141
150
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
142
151
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
143
|
-
rocrate: {},
|
|
144
152
|
meta: {},
|
|
145
153
|
createdAt: new Date(),
|
|
146
154
|
updatedAt: new Date(),
|
|
@@ -157,12 +165,19 @@ describe('Entity Transformers', () => {
|
|
|
157
165
|
...entity,
|
|
158
166
|
processed: true,
|
|
159
167
|
});
|
|
160
|
-
const
|
|
168
|
+
const base = baseEntityTransformer(rawEntity);
|
|
169
|
+
const standard = {
|
|
170
|
+
...base,
|
|
171
|
+
memberOf: base.memberOf ? { id: base.memberOf, name: 'Parent Collection' } : null,
|
|
172
|
+
rootCollection: base.rootCollection ? { id: base.rootCollection, name: 'Root Collection' } : null,
|
|
173
|
+
};
|
|
161
174
|
const authorised = await customAccessTransformer(standard, mockContext);
|
|
162
175
|
const final = await addMetadata(authorised, mockContext);
|
|
163
176
|
expect(final).toMatchObject({
|
|
164
177
|
id: 'http://example.com/entity/123',
|
|
165
178
|
name: 'Test Entity',
|
|
179
|
+
memberOf: { id: 'http://example.com/collection', name: 'Parent Collection' },
|
|
180
|
+
rootCollection: { id: 'http://example.com/root', name: 'Root Collection' },
|
|
166
181
|
access: {
|
|
167
182
|
metadata: true,
|
|
168
183
|
content: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.test.js","sourceRoot":"","sources":["../../src/transformers/transformer.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EACL,0BAA0B,
|
|
1
|
+
{"version":3,"file":"transformer.test.js","sourceRoot":"","sources":["../../src/transformers/transformer.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EACL,0BAA0B,EAG1B,qBAAqB,GAEtB,MAAM,cAAc,CAAC;AAEtB,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,MAAM,WAAW,GAAuB;QACtC,OAAO,EAAE,EAAoB;QAC7B,OAAO,EAAE,EAAqB;KAC/B,CAAC;IAEF,MAAM,kBAAkB,GAAmB;QACzC,EAAE,EAAE,+BAA+B;QACnC,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,eAAe;QAC5B,UAAU,EAAE,0BAA0B;QACtC,QAAQ,EAAE,EAAE,EAAE,EAAE,+BAA+B,EAAE,IAAI,EAAE,iBAAiB,EAAE;QAC1E,cAAc,EAAE,EAAE,EAAE,EAAE,yBAAyB,EAAE,IAAI,EAAE,iBAAiB,EAAE;QAC1E,iBAAiB,EAAE,8CAA8C;QACjE,gBAAgB,EAAE,8CAA8C;KACjE,CAAC;IAEF,MAAM,oBAAoB,GAAqB;QAC7C,GAAG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CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "arocapi",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"description": "An RO-Crate API",
|
|
6
6
|
"main": "dist/app.js",
|
|
7
7
|
"exports": {
|
|
@@ -16,36 +16,36 @@
|
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@fastify/cors": "^11.1.0",
|
|
19
|
-
"@fastify/sensible": "^6.0.
|
|
19
|
+
"@fastify/sensible": "^6.0.4",
|
|
20
20
|
"@opensearch-project/opensearch": "^3.5.1",
|
|
21
|
-
"@prisma/config": "^6.
|
|
21
|
+
"@prisma/config": "^6.19.0",
|
|
22
22
|
"dotenv": "^17.2.3",
|
|
23
|
-
"express": "^5.1
|
|
24
|
-
"fastify": "^5.6.
|
|
23
|
+
"express": "^5.2.1",
|
|
24
|
+
"fastify": "^5.6.2",
|
|
25
25
|
"fastify-plugin": "^5.1.0",
|
|
26
26
|
"fastify-type-provider-zod": "^6.1.0",
|
|
27
|
-
"zod": "^4.1.
|
|
27
|
+
"zod": "^4.1.13"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@biomejs/biome": "^2.3.
|
|
31
|
-
"@prisma/client": "^6.
|
|
30
|
+
"@biomejs/biome": "^2.3.8",
|
|
31
|
+
"@prisma/client": "^6.19.0",
|
|
32
32
|
"@semantic-release/changelog": "^6.0.3",
|
|
33
33
|
"@semantic-release/git": "^10.0.1",
|
|
34
34
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
35
|
-
"@types/express": "^5.0.
|
|
36
|
-
"@types/node": "^22.
|
|
37
|
-
"@vitest/coverage-v8": "^4.0.
|
|
38
|
-
"@vitest/ui": "^4.0.
|
|
35
|
+
"@types/express": "^5.0.6",
|
|
36
|
+
"@types/node": "^22.19.1",
|
|
37
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
38
|
+
"@vitest/ui": "^4.0.15",
|
|
39
39
|
"concurrently": "^9.2.1",
|
|
40
40
|
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
41
41
|
"fastify-tsconfig": "^3.0.0",
|
|
42
|
-
"knip": "^5.
|
|
43
|
-
"prisma": "^6.
|
|
42
|
+
"knip": "^5.71.0",
|
|
43
|
+
"prisma": "^6.19.0",
|
|
44
44
|
"prisma-json-types-generator": "^3.6.2",
|
|
45
|
-
"semantic-release": "^25.0.
|
|
46
|
-
"tsx": "^4.
|
|
45
|
+
"semantic-release": "^25.0.2",
|
|
46
|
+
"tsx": "^4.21.0",
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
|
-
"vitest": "^4.0.
|
|
48
|
+
"vitest": "^4.0.15",
|
|
49
49
|
"vitest-mock-extended": "^3.1.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
@@ -76,9 +76,7 @@
|
|
|
76
76
|
"test:watch": "./scripts/setup-integration.sh && vitest",
|
|
77
77
|
"test:ui": "./scripts/setup-integration.sh && vitest --ui",
|
|
78
78
|
"test:coverage": "./scripts/setup-integration.sh && vitest run --coverage",
|
|
79
|
-
"prepublishOnly": "pnpm run lint:biome && pnpm run lint:types && pnpm run build:ts",
|
|
80
79
|
"generate": "npx prisma generate",
|
|
81
|
-
"postinstall": "pnpm run generate",
|
|
82
80
|
"db:generate": "prisma generate",
|
|
83
81
|
"db:migrate": "prisma migrate deploy",
|
|
84
82
|
"seed": "rm -rf dist && pnpm run build:ts && node --env-file=.env example/data/seed.ts"
|
|
@@ -91,5 +89,5 @@
|
|
|
91
89
|
"registry": "https://registry.npmjs.org/",
|
|
92
90
|
"provenance": true
|
|
93
91
|
},
|
|
94
|
-
"packageManager": "pnpm@10.
|
|
92
|
+
"packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a"
|
|
95
93
|
}
|
package/src/app.ts
CHANGED
|
@@ -55,13 +55,14 @@ const setupValidation = (fastify: FastifyInstance) => {
|
|
|
55
55
|
fastify.setValidatorCompiler(validatorCompiler);
|
|
56
56
|
fastify.setSerializerCompiler(serializerCompiler);
|
|
57
57
|
|
|
58
|
-
fastify.setErrorHandler((
|
|
59
|
-
if (hasZodFastifySchemaValidationErrors(
|
|
60
|
-
return reply.code(400).send(createValidationError('The request parameters are invalid',
|
|
58
|
+
fastify.setErrorHandler((error, _req, reply) => {
|
|
59
|
+
if (hasZodFastifySchemaValidationErrors(error)) {
|
|
60
|
+
return reply.code(400).send(createValidationError('The request parameters are invalid', error.validation));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// NOTE: We are exposing the error message here for development purposes.
|
|
64
64
|
// In production, consider hiding error details to avoid leaking sensitive information.
|
|
65
|
+
const err = error as Error;
|
|
65
66
|
return reply.code(500).send({
|
|
66
67
|
error: 'Internal Server Error',
|
|
67
68
|
message: err.message,
|
|
@@ -57,12 +57,40 @@ exports[`Entities Route > GET /entities > should return entities with default pa
|
|
|
57
57
|
"description": "Second test entity",
|
|
58
58
|
"entityType": "http://pcdm.org/models#Object",
|
|
59
59
|
"id": "http://example.com/entity/2",
|
|
60
|
-
"memberOf":
|
|
60
|
+
"memberOf": {
|
|
61
|
+
"id": "http://example.com/entity/1",
|
|
62
|
+
"name": "Test Entity 1",
|
|
63
|
+
},
|
|
61
64
|
"metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
|
|
62
65
|
"name": "Test Entity 2",
|
|
63
|
-
"rootCollection":
|
|
66
|
+
"rootCollection": {
|
|
67
|
+
"id": "http://example.com/entity/1",
|
|
68
|
+
"name": "Test Entity 1",
|
|
69
|
+
},
|
|
64
70
|
},
|
|
65
71
|
],
|
|
66
72
|
"total": 2,
|
|
67
73
|
}
|
|
68
74
|
`;
|
|
75
|
+
|
|
76
|
+
exports[`Entities Route > GET /entities > should return null for memberOf/rootCollection when parent entity not found 1`] = `
|
|
77
|
+
{
|
|
78
|
+
"entities": [
|
|
79
|
+
{
|
|
80
|
+
"access": {
|
|
81
|
+
"content": true,
|
|
82
|
+
"metadata": true,
|
|
83
|
+
},
|
|
84
|
+
"contentLicenseId": "https://creativecommons.org/licenses/by/4.0/",
|
|
85
|
+
"description": "Entity with missing parent",
|
|
86
|
+
"entityType": "http://pcdm.org/models#Object",
|
|
87
|
+
"id": "http://example.com/entity/1",
|
|
88
|
+
"memberOf": null,
|
|
89
|
+
"metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
|
|
90
|
+
"name": "Test Entity 1",
|
|
91
|
+
"rootCollection": null,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
"total": 1,
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
@@ -56,11 +56,19 @@ exports[`Entity Route > GET /entity/:id > should return entity when found 1`] =
|
|
|
56
56
|
}
|
|
57
57
|
`;
|
|
58
58
|
|
|
59
|
-
exports[`Entity Route > GET /entity/:id > should
|
|
59
|
+
exports[`Entity Route > GET /entity/:id > should return null for memberOf/rootCollection when parent entity not found 1`] = `
|
|
60
60
|
{
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
"access": {
|
|
62
|
+
"content": true,
|
|
63
|
+
"metadata": true,
|
|
64
|
+
},
|
|
65
|
+
"contentLicenseId": "https://creativecommons.org/licenses/by/4.0/",
|
|
66
|
+
"description": "A test entity",
|
|
67
|
+
"entityType": "http://pcdm.org/models#Object",
|
|
68
|
+
"id": "http://example.com/entity/123",
|
|
69
|
+
"memberOf": null,
|
|
70
|
+
"metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
|
|
71
|
+
"name": "Test Entity",
|
|
72
|
+
"rootCollection": null,
|
|
65
73
|
}
|
|
66
74
|
`;
|
|
@@ -111,6 +111,32 @@ exports[`Search Route > POST /search > should perform basic search successfully
|
|
|
111
111
|
}
|
|
112
112
|
`;
|
|
113
113
|
|
|
114
|
+
exports[`Search Route > POST /search > should return null for memberOf/rootCollection when parent entity not found 1`] = `
|
|
115
|
+
{
|
|
116
|
+
"entities": [
|
|
117
|
+
{
|
|
118
|
+
"access": {
|
|
119
|
+
"content": true,
|
|
120
|
+
"metadata": true,
|
|
121
|
+
},
|
|
122
|
+
"contentLicenseId": "https://creativecommons.org/licenses/by/4.0/",
|
|
123
|
+
"description": "Entity with missing parent",
|
|
124
|
+
"entityType": "http://pcdm.org/models#Object",
|
|
125
|
+
"id": "http://example.com/entity/1",
|
|
126
|
+
"memberOf": null,
|
|
127
|
+
"metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
|
|
128
|
+
"name": "Test Entity 1",
|
|
129
|
+
"rootCollection": null,
|
|
130
|
+
"searchExtra": {
|
|
131
|
+
"score": 1.5,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
"searchTime": 10,
|
|
136
|
+
"total": 1,
|
|
137
|
+
}
|
|
138
|
+
`;
|
|
139
|
+
|
|
114
140
|
exports[`Search Route > POST /search > should skip entities not found in database and log warning 1`] = `
|
|
115
141
|
{
|
|
116
142
|
"entities": [
|
package/src/routes/crate.test.ts
CHANGED
|
@@ -39,22 +39,6 @@ describe('Crate Route', () => {
|
|
|
39
39
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
40
40
|
createdAt: new Date(),
|
|
41
41
|
updatedAt: new Date(),
|
|
42
|
-
rocrate: {
|
|
43
|
-
'@context': 'https://w3id.org/ro/crate/1.1/context',
|
|
44
|
-
'@graph': [
|
|
45
|
-
{
|
|
46
|
-
'@id': 'ro-crate-metadata.json',
|
|
47
|
-
'@type': 'CreativeWork',
|
|
48
|
-
conformsTo: { '@id': 'https://w3id.org/ro/crate/1.1' },
|
|
49
|
-
about: { '@id': './' },
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
'@id': './',
|
|
53
|
-
'@type': 'Dataset',
|
|
54
|
-
name: 'Test RO-Crate',
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
42
|
meta: {},
|
|
59
43
|
};
|
|
60
44
|
|
package/src/routes/crate.ts
CHANGED
|
@@ -65,7 +65,9 @@ const crate: FastifyPluginAsync<CrateRouteOptions> = async (fastify, opts) => {
|
|
|
65
65
|
|
|
66
66
|
return reply.code(200).send();
|
|
67
67
|
} catch (error) {
|
|
68
|
-
|
|
68
|
+
const err = error as Error;
|
|
69
|
+
fastify.log.error(`RO-Crate metadata retrieval error: ${err}`);
|
|
70
|
+
|
|
69
71
|
return reply.code(500).send(createInternalError());
|
|
70
72
|
}
|
|
71
73
|
},
|
|
@@ -131,7 +133,9 @@ const crate: FastifyPluginAsync<CrateRouteOptions> = async (fastify, opts) => {
|
|
|
131
133
|
// Exhaustiveness check - should never reach here with proper types
|
|
132
134
|
throw new Error(`Unexpected RO-Crate result type: ${(result as { type: string }).type}`);
|
|
133
135
|
} catch (error) {
|
|
134
|
-
|
|
136
|
+
const err = error as Error;
|
|
137
|
+
fastify.log.error(`RO-Crate retrieval error: ${err.message}`);
|
|
138
|
+
|
|
135
139
|
return reply.code(500).send(createInternalError());
|
|
136
140
|
}
|
|
137
141
|
},
|
|
@@ -30,7 +30,6 @@ describe('Entities Route', () => {
|
|
|
30
30
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
31
31
|
createdAt: new Date(),
|
|
32
32
|
updatedAt: new Date(),
|
|
33
|
-
rocrate: {},
|
|
34
33
|
meta: {},
|
|
35
34
|
},
|
|
36
35
|
{
|
|
@@ -46,7 +45,6 @@ describe('Entities Route', () => {
|
|
|
46
45
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
47
46
|
createdAt: new Date(),
|
|
48
47
|
updatedAt: new Date(),
|
|
49
|
-
rocrate: {},
|
|
50
48
|
meta: {},
|
|
51
49
|
},
|
|
52
50
|
];
|
|
@@ -280,5 +278,39 @@ describe('Entities Route', () => {
|
|
|
280
278
|
expect(response.statusCode).toBe(200);
|
|
281
279
|
expect(body).toMatchSnapshot();
|
|
282
280
|
});
|
|
281
|
+
|
|
282
|
+
it('should return null for memberOf/rootCollection when parent entity not found', async () => {
|
|
283
|
+
const mockEntities = [
|
|
284
|
+
{
|
|
285
|
+
id: 1,
|
|
286
|
+
rocrateId: 'http://example.com/entity/1',
|
|
287
|
+
name: 'Test Entity 1',
|
|
288
|
+
description: 'Entity with missing parent',
|
|
289
|
+
entityType: 'http://pcdm.org/models#Object',
|
|
290
|
+
fileId: null,
|
|
291
|
+
memberOf: 'http://example.com/entity/deleted',
|
|
292
|
+
rootCollection: 'http://example.com/entity/deleted',
|
|
293
|
+
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
294
|
+
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
295
|
+
createdAt: new Date(),
|
|
296
|
+
updatedAt: new Date(),
|
|
297
|
+
meta: {},
|
|
298
|
+
},
|
|
299
|
+
];
|
|
300
|
+
|
|
301
|
+
// First call returns entities, second call (for reference resolution) returns empty
|
|
302
|
+
prisma.entity.findMany.mockResolvedValueOnce(mockEntities);
|
|
303
|
+
prisma.entity.findMany.mockResolvedValueOnce([]);
|
|
304
|
+
prisma.entity.count.mockResolvedValue(1);
|
|
305
|
+
|
|
306
|
+
const response = await fastify.inject({
|
|
307
|
+
method: 'GET',
|
|
308
|
+
url: '/entities',
|
|
309
|
+
});
|
|
310
|
+
const body = JSON.parse(response.body);
|
|
311
|
+
|
|
312
|
+
expect(response.statusCode).toBe(200);
|
|
313
|
+
expect(body).toMatchSnapshot();
|
|
314
|
+
});
|
|
283
315
|
});
|
|
284
316
|
});
|
package/src/routes/entities.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FastifyPluginAsync } from 'fastify';
|
|
2
2
|
import type { ZodTypeProvider } from 'fastify-type-provider-zod';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
|
-
import { baseEntityTransformer } from '../transformers/default.js';
|
|
4
|
+
import { baseEntityTransformer, resolveEntityReferences } from '../transformers/default.js';
|
|
5
5
|
import type { AccessTransformer, EntityTransformer } from '../types/transformers.js';
|
|
6
6
|
import { createInternalError } from '../utils/errors.js';
|
|
7
7
|
|
|
@@ -65,10 +65,18 @@ const entities: FastifyPluginAsync<EntitiesRouteOptions> = async (fastify, opts)
|
|
|
65
65
|
|
|
66
66
|
const total = await fastify.prisma.entity.count({ where });
|
|
67
67
|
|
|
68
|
+
// Resolve memberOf and rootCollection references
|
|
69
|
+
const refMap = await resolveEntityReferences(dbEntities, fastify.prisma);
|
|
70
|
+
|
|
68
71
|
// Apply transformers to each entity: base -> access -> additional
|
|
69
72
|
const entities = await Promise.all(
|
|
70
73
|
dbEntities.map(async (dbEntity) => {
|
|
71
|
-
const
|
|
74
|
+
const base = baseEntityTransformer(dbEntity);
|
|
75
|
+
const standardEntity = {
|
|
76
|
+
...base,
|
|
77
|
+
memberOf: base.memberOf ? (refMap.get(base.memberOf) ?? null) : null,
|
|
78
|
+
rootCollection: base.rootCollection ? (refMap.get(base.rootCollection) ?? null) : null,
|
|
79
|
+
};
|
|
72
80
|
const authorisedEntity = await accessTransformer(standardEntity, {
|
|
73
81
|
request,
|
|
74
82
|
fastify,
|
|
@@ -91,7 +99,9 @@ const entities: FastifyPluginAsync<EntitiesRouteOptions> = async (fastify, opts)
|
|
|
91
99
|
entities,
|
|
92
100
|
};
|
|
93
101
|
} catch (error) {
|
|
94
|
-
|
|
102
|
+
const err = error as Error;
|
|
103
|
+
fastify.log.error(`Database error: ${err.message}`);
|
|
104
|
+
|
|
95
105
|
return reply.code(500).send(createInternalError());
|
|
96
106
|
}
|
|
97
107
|
},
|
|
@@ -30,7 +30,6 @@ describe('Entity Route', () => {
|
|
|
30
30
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
31
31
|
createdAt: new Date(),
|
|
32
32
|
updatedAt: new Date(),
|
|
33
|
-
rocrate: {},
|
|
34
33
|
meta: {},
|
|
35
34
|
};
|
|
36
35
|
|
|
@@ -128,5 +127,36 @@ describe('Entity Route', () => {
|
|
|
128
127
|
expect(response.statusCode).toBe(200);
|
|
129
128
|
expect(body).toMatchSnapshot();
|
|
130
129
|
});
|
|
130
|
+
|
|
131
|
+
it('should return null for memberOf/rootCollection when parent entity not found', async () => {
|
|
132
|
+
const mockEntity = {
|
|
133
|
+
id: 1,
|
|
134
|
+
rocrateId: 'http://example.com/entity/123',
|
|
135
|
+
name: 'Test Entity',
|
|
136
|
+
description: 'A test entity',
|
|
137
|
+
entityType: 'http://pcdm.org/models#Object',
|
|
138
|
+
fileId: null,
|
|
139
|
+
memberOf: 'http://example.com/entity/deleted',
|
|
140
|
+
rootCollection: 'http://example.com/entity/deleted',
|
|
141
|
+
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
142
|
+
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
143
|
+
createdAt: new Date(),
|
|
144
|
+
updatedAt: new Date(),
|
|
145
|
+
meta: {},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// First call returns the entity, second call (for reference resolution) returns empty
|
|
149
|
+
prisma.entity.findFirst.mockResolvedValue(mockEntity);
|
|
150
|
+
prisma.entity.findMany.mockResolvedValue([]);
|
|
151
|
+
|
|
152
|
+
const response = await fastify.inject({
|
|
153
|
+
method: 'GET',
|
|
154
|
+
url: `/entity/${encodeURIComponent('http://example.com/entity/123')}`,
|
|
155
|
+
});
|
|
156
|
+
const body = JSON.parse(response.body);
|
|
157
|
+
|
|
158
|
+
expect(response.statusCode).toBe(200);
|
|
159
|
+
expect(body).toMatchSnapshot();
|
|
160
|
+
});
|
|
131
161
|
});
|
|
132
162
|
});
|
package/src/routes/entity.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FastifyPluginAsync } from 'fastify';
|
|
2
2
|
import type { ZodTypeProvider } from 'fastify-type-provider-zod';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
|
-
import { baseEntityTransformer } from '../transformers/default.js';
|
|
4
|
+
import { baseEntityTransformer, resolveEntityReferences } from '../transformers/default.js';
|
|
5
5
|
import type { AccessTransformer, EntityTransformer } from '../types/transformers.js';
|
|
6
6
|
import { createInternalError, createNotFoundError } from '../utils/errors.js';
|
|
7
7
|
|
|
@@ -37,7 +37,15 @@ const entity: FastifyPluginAsync<EntityRouteOptions> = async (fastify, opts) =>
|
|
|
37
37
|
return reply.code(404).send(createNotFoundError('The requested entity was not found', id));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
// Resolve memberOf and rootCollection references
|
|
41
|
+
const refMap = await resolveEntityReferences([entity], fastify.prisma);
|
|
42
|
+
|
|
43
|
+
const base = baseEntityTransformer(entity);
|
|
44
|
+
const standardEntity = {
|
|
45
|
+
...base,
|
|
46
|
+
memberOf: base.memberOf ? (refMap.get(base.memberOf) ?? null) : null,
|
|
47
|
+
rootCollection: base.rootCollection ? (refMap.get(base.rootCollection) ?? null) : null,
|
|
48
|
+
};
|
|
41
49
|
const authorisedEntity = await accessTransformer(standardEntity, {
|
|
42
50
|
request,
|
|
43
51
|
fastify,
|
|
@@ -53,7 +61,9 @@ const entity: FastifyPluginAsync<EntityRouteOptions> = async (fastify, opts) =>
|
|
|
53
61
|
|
|
54
62
|
return result;
|
|
55
63
|
} catch (error) {
|
|
56
|
-
|
|
64
|
+
const err = error as Error;
|
|
65
|
+
fastify.log.error(`Database error: ${err.message}`);
|
|
66
|
+
|
|
57
67
|
return reply.code(500).send(createInternalError());
|
|
58
68
|
}
|
|
59
69
|
},
|