arocapi 1.1.0 → 1.2.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.
Files changed (128) hide show
  1. package/LICENSE.md +5 -0
  2. package/README.md +459 -36
  3. package/dist/app.d.ts +19 -1
  4. package/dist/app.js +37 -29
  5. package/dist/app.js.map +1 -1
  6. package/dist/app.test.js +124 -0
  7. package/dist/app.test.js.map +1 -0
  8. package/dist/index.dev.js +146 -0
  9. package/dist/index.dev.js.map +1 -0
  10. package/dist/routes/crate.d.ts +7 -0
  11. package/dist/routes/crate.js +101 -0
  12. package/dist/routes/crate.js.map +1 -0
  13. package/dist/routes/crate.test.d.ts +1 -0
  14. package/dist/routes/crate.test.js +360 -0
  15. package/dist/routes/crate.test.js.map +1 -0
  16. package/dist/routes/entities.d.ts +6 -1
  17. package/dist/routes/entities.js +52 -39
  18. package/dist/routes/entities.js.map +1 -1
  19. package/dist/routes/entities.test.d.ts +1 -0
  20. package/dist/routes/entities.test.js +245 -0
  21. package/dist/routes/entities.test.js.map +1 -0
  22. package/dist/routes/entity.d.ts +6 -1
  23. package/dist/routes/entity.js +30 -8
  24. package/dist/routes/entity.js.map +1 -1
  25. package/dist/routes/entity.test.d.ts +1 -0
  26. package/dist/routes/entity.test.js +109 -0
  27. package/dist/routes/entity.test.js.map +1 -0
  28. package/dist/routes/file.d.ts +7 -0
  29. package/dist/routes/file.js +113 -0
  30. package/dist/routes/file.js.map +1 -0
  31. package/dist/routes/file.test.d.ts +1 -0
  32. package/dist/routes/file.test.js +319 -0
  33. package/dist/routes/file.test.js.map +1 -0
  34. package/dist/routes/files.d.ts +8 -0
  35. package/dist/routes/files.js +62 -0
  36. package/dist/routes/files.js.map +1 -0
  37. package/dist/routes/files.test.d.ts +1 -0
  38. package/dist/routes/files.test.js +244 -0
  39. package/dist/routes/files.test.js.map +1 -0
  40. package/dist/routes/search.d.ts +6 -1
  41. package/dist/routes/search.js +44 -19
  42. package/dist/routes/search.js.map +1 -1
  43. package/dist/routes/search.test.d.ts +1 -0
  44. package/dist/routes/search.test.js +698 -0
  45. package/dist/routes/search.test.js.map +1 -0
  46. package/dist/test/helpers/fastify.d.ts +9 -0
  47. package/dist/test/helpers/fastify.js +24 -0
  48. package/dist/test/helpers/fastify.js.map +1 -0
  49. package/dist/test/integration.setup.d.ts +58 -0
  50. package/dist/test/integration.setup.js +181 -0
  51. package/dist/test/integration.setup.js.map +1 -0
  52. package/dist/test/integration.test.d.ts +1 -0
  53. package/dist/test/integration.test.js +337 -0
  54. package/dist/test/integration.test.js.map +1 -0
  55. package/dist/transformers/default.d.ts +45 -0
  56. package/dist/transformers/default.js +46 -0
  57. package/dist/transformers/default.js.map +1 -0
  58. package/dist/transformers/default.test.d.ts +1 -0
  59. package/dist/transformers/default.test.js +177 -0
  60. package/dist/transformers/default.test.js.map +1 -0
  61. package/dist/transformers/transformer.test.d.ts +1 -0
  62. package/dist/transformers/transformer.test.js +176 -0
  63. package/dist/transformers/transformer.test.js.map +1 -0
  64. package/dist/types/fileHandlers.d.ts +41 -0
  65. package/dist/types/fileHandlers.js +2 -0
  66. package/dist/types/fileHandlers.js.map +1 -0
  67. package/dist/types/transformers.d.ts +10 -0
  68. package/dist/types/transformers.js +2 -0
  69. package/dist/types/transformers.js.map +1 -0
  70. package/dist/utils/errors.d.ts +23 -0
  71. package/dist/utils/errors.js +21 -0
  72. package/dist/utils/errors.js.map +1 -0
  73. package/dist/utils/errors.test.d.ts +1 -0
  74. package/dist/utils/errors.test.js +66 -0
  75. package/dist/utils/errors.test.js.map +1 -0
  76. package/package.json +35 -28
  77. package/prisma/migrations/20250827033956_record_type_scalar/migration.sql +10 -0
  78. package/prisma/migrations/20250923032753_api_refactor/migration.sql +39 -0
  79. package/prisma/migrations/20250923223119_entity_type_to_string/migration.sql +8 -0
  80. package/prisma/migrations/20251020140329_add_meta_column/migration.sql +2 -0
  81. package/prisma/migrations/20251027010713_add_file_table/migration.sql +17 -0
  82. package/prisma/migrations/20251027221138_add_file_id_to_entity/migration.sql +2 -0
  83. package/prisma/models/entity.prisma +16 -12
  84. package/prisma/models/file.prisma +20 -0
  85. package/prisma.config.ts +6 -1
  86. package/src/__snapshots__/app.test.ts.snap +8 -0
  87. package/src/app.test.ts +158 -0
  88. package/src/app.ts +99 -36
  89. package/src/index.dev.ts +196 -0
  90. package/src/reset.d.ts +1 -0
  91. package/src/routes/__snapshots__/entities.test.ts.snap +68 -0
  92. package/src/routes/__snapshots__/entity.test.ts.snap +57 -0
  93. package/src/routes/__snapshots__/search.test.ts.snap +139 -0
  94. package/src/routes/crate.test.ts +441 -0
  95. package/src/routes/crate.ts +145 -0
  96. package/src/routes/entities.test.ts +284 -0
  97. package/src/routes/entities.ts +69 -48
  98. package/src/routes/entity.test.ts +132 -0
  99. package/src/routes/entity.ts +59 -22
  100. package/src/routes/file.test.ts +399 -0
  101. package/src/routes/file.ts +157 -0
  102. package/src/routes/files.test.ts +303 -0
  103. package/src/routes/files.ts +89 -0
  104. package/src/routes/search.test.ts +807 -0
  105. package/src/routes/search.ts +67 -25
  106. package/src/test/__snapshots__/integration.test.ts.snap +18 -0
  107. package/src/test/helpers/fastify.ts +39 -0
  108. package/src/test/integration.setup.ts +200 -0
  109. package/src/test/integration.test.ts +411 -0
  110. package/src/transformers/default.test.ts +199 -0
  111. package/src/transformers/default.ts +165 -0
  112. package/src/transformers/transformer.test.ts +233 -0
  113. package/src/types/fileHandlers.ts +65 -0
  114. package/src/types/transformers.ts +52 -0
  115. package/src/utils/errors.test.ts +75 -0
  116. package/src/utils/errors.ts +45 -0
  117. package/dist/index.js +0 -25
  118. package/dist/index.js.map +0 -1
  119. package/dist/scripts/loadEntities.js +0 -170
  120. package/dist/scripts/loadEntities.js.map +0 -1
  121. package/dist/type.d.ts +0 -6
  122. package/dist/type.js +0 -2
  123. package/dist/type.js.map +0 -1
  124. package/src/index.ts +0 -35
  125. package/src/scripts/loadEntities.ts +0 -223
  126. package/src/type.ts +0 -7
  127. /package/dist/{scripts/loadEntities.d.ts → app.test.d.ts} +0 -0
  128. /package/dist/{index.d.ts → index.dev.d.ts} +0 -0
package/src/app.ts CHANGED
@@ -1,50 +1,68 @@
1
1
  import cors from '@fastify/cors';
2
2
  import sensible from '@fastify/sensible';
3
3
  import type { Client } from '@opensearch-project/opensearch';
4
- import type { PrismaClient } from '@prisma/client/extension';
5
4
  import type { FastifyInstance, FastifyPluginAsync } from 'fastify';
6
5
  import fp from 'fastify-plugin';
7
- import {
8
- hasZodFastifySchemaValidationErrors,
9
- isResponseSerializationError,
10
- serializerCompiler,
11
- validatorCompiler,
12
- } from 'fastify-type-provider-zod';
6
+ import { hasZodFastifySchemaValidationErrors, serializerCompiler, validatorCompiler } from 'fastify-type-provider-zod';
7
+ import type { PrismaClient } from './generated/prisma/client.js';
8
+ import crate from './routes/crate.js';
13
9
  import entities from './routes/entities.js';
14
10
  import entity from './routes/entity.js';
11
+ import file from './routes/file.js';
12
+ import files from './routes/files.js';
15
13
  import search from './routes/search.js';
14
+ import type { FileHandler, RoCrateHandler } from './types/fileHandlers.js';
15
+ import type {
16
+ AccessTransformer,
17
+ EntityTransformer,
18
+ FileAccessTransformer,
19
+ FileTransformer,
20
+ } from './types/transformers.js';
21
+ import { createValidationError } from './utils/errors.js';
22
+
23
+ export type { AuthorisedEntity, AuthorisedFile, StandardEntity, StandardFile } from './transformers/default.js';
24
+ export { AllPublicAccessTransformer, AllPublicFileAccessTransformer } from './transformers/default.js';
25
+ export type {
26
+ FileHandler,
27
+ FileHandlerContext,
28
+ FileMetadata,
29
+ FilePathResult,
30
+ FileRedirectResult,
31
+ FileResult,
32
+ FileStreamResult,
33
+ GetFileHandler,
34
+ GetRoCrateHandler,
35
+ HeadFileHandler,
36
+ HeadRoCrateHandler,
37
+ RoCrateHandler,
38
+ } from './types/fileHandlers.js';
39
+ export type {
40
+ AccessTransformer,
41
+ EntityTransformer,
42
+ FileAccessTransformer,
43
+ FileTransformer,
44
+ TransformerContext,
45
+ } from './types/transformers.js';
46
+
47
+ declare module 'fastify' {
48
+ interface FastifyInstance {
49
+ prisma: PrismaClient;
50
+ opensearch: Client;
51
+ }
52
+ }
16
53
 
17
54
  const setupValidation = (fastify: FastifyInstance) => {
18
55
  fastify.setValidatorCompiler(validatorCompiler);
19
56
  fastify.setSerializerCompiler(serializerCompiler);
20
57
 
21
- fastify.setErrorHandler((err, req, reply) => {
22
- if (hasZodFastifySchemaValidationErrors(err)) {
23
- return reply.code(400).send({
24
- error: 'Response Validation Error',
25
- message: "Request doesn't match the schema",
26
- details: {
27
- issues: err.validation,
28
- method: req.method,
29
- url: req.url,
30
- },
31
- });
32
- }
33
-
34
- if (isResponseSerializationError(err)) {
35
- return reply.code(500).send({
36
- error: 'Internal Server Error',
37
- message: "Response doesn't match the schema",
38
- details: {
39
- issues: err.cause.issues,
40
- method: err.method,
41
- url: err.url,
42
- },
43
- });
58
+ fastify.setErrorHandler((error, _req, reply) => {
59
+ if (hasZodFastifySchemaValidationErrors(error)) {
60
+ return reply.code(400).send(createValidationError('The request parameters are invalid', error.validation));
44
61
  }
45
62
 
46
63
  // NOTE: We are exposing the error message here for development purposes.
47
64
  // In production, consider hiding error details to avoid leaking sensitive information.
65
+ const err = error as Error;
48
66
  return reply.code(500).send({
49
67
  error: 'Internal Server Error',
50
68
  message: err.message,
@@ -54,9 +72,11 @@ const setupValidation = (fastify: FastifyInstance) => {
54
72
 
55
73
  const setupDatabase = async (fastify: FastifyInstance, prisma: PrismaClient) => {
56
74
  await prisma.$connect();
75
+
57
76
  fastify.decorate('prisma', prisma);
58
- fastify.addHook('onClose', async (server) => {
59
- await server.prisma.$disconnect();
77
+
78
+ fastify.addHook('onClose', async () => {
79
+ await prisma.$disconnect();
60
80
  });
61
81
  };
62
82
 
@@ -78,9 +98,49 @@ export type Options = {
78
98
  prisma: PrismaClient;
79
99
  opensearch: Client;
80
100
  disableCors?: boolean;
101
+ accessTransformer: AccessTransformer;
102
+ entityTransformers?: EntityTransformer[];
103
+ fileAccessTransformer: FileAccessTransformer;
104
+ fileTransformers?: FileTransformer[];
105
+ fileHandler: FileHandler;
106
+ roCrateHandler: RoCrateHandler;
81
107
  };
82
108
  const app: FastifyPluginAsync<Options> = async (fastify, options) => {
83
- const { prisma, opensearch, disableCors = false } = options || {};
109
+ const {
110
+ prisma,
111
+ opensearch,
112
+ disableCors = false,
113
+ accessTransformer,
114
+ entityTransformers,
115
+ fileAccessTransformer,
116
+ fileTransformers,
117
+ fileHandler,
118
+ roCrateHandler,
119
+ } = options;
120
+
121
+ if (!prisma) {
122
+ throw new Error('Prisma client is required');
123
+ }
124
+
125
+ if (!opensearch) {
126
+ throw new Error('OpenSearch client is required');
127
+ }
128
+
129
+ if (!accessTransformer) {
130
+ throw new Error('accessTransformer is required');
131
+ }
132
+
133
+ if (!fileAccessTransformer) {
134
+ throw new Error('fileAccessTransformer is required');
135
+ }
136
+
137
+ if (!fileHandler) {
138
+ throw new Error('fileHandler is required');
139
+ }
140
+
141
+ if (!roCrateHandler) {
142
+ throw new Error('roCrateHandler is required');
143
+ }
84
144
 
85
145
  fastify.register(sensible);
86
146
  if (!disableCors) {
@@ -90,9 +150,12 @@ const app: FastifyPluginAsync<Options> = async (fastify, options) => {
90
150
  await setupDatabase(fastify, prisma);
91
151
  await setupSearch(fastify, opensearch);
92
152
 
93
- fastify.register(entities);
94
- fastify.register(entity);
95
- fastify.register(search);
153
+ fastify.register(entities, { accessTransformer, entityTransformers });
154
+ fastify.register(entity, { accessTransformer, entityTransformers });
155
+ fastify.register(files, { fileAccessTransformer, fileTransformers });
156
+ fastify.register(file, { fileHandler });
157
+ fastify.register(crate, { roCrateHandler });
158
+ fastify.register(search, { accessTransformer, entityTransformers });
96
159
  };
97
160
 
98
161
  export default fp(app);
@@ -0,0 +1,196 @@
1
+ import { createReadStream, existsSync, readFileSync, statSync } from 'node:fs';
2
+ import { Readable } from 'node:stream';
3
+ import { Client } from '@opensearch-project/opensearch';
4
+ import Fastify from 'fastify';
5
+
6
+ import arocapi, {
7
+ AllPublicAccessTransformer,
8
+ AllPublicFileAccessTransformer,
9
+ type EntityTransformer,
10
+ type FileHandler,
11
+ type RoCrateHandler,
12
+ } from './app.js';
13
+ import type { Entity, File } from './generated/prisma/client.js';
14
+ import { PrismaClient } from './generated/prisma/client.js';
15
+
16
+ declare module 'fastify' {
17
+ interface FastifyInstance {
18
+ prisma: PrismaClient;
19
+ opensearch: Client;
20
+ }
21
+ }
22
+
23
+ const prisma = new PrismaClient();
24
+
25
+ if (!process.env.OPENSEARCH_URL) {
26
+ throw new Error('OPENSEARCH_URL environment variable is not set');
27
+ }
28
+ const opensearchUrl = process.env.OPENSEARCH_URL;
29
+ const opensearch = new Client({ node: opensearchUrl });
30
+
31
+ const fileHandler: FileHandler = {
32
+ head: async (file: File) => {
33
+ const filePath = (file.meta as { storagePath: string }).storagePath;
34
+
35
+ if (!existsSync(filePath)) {
36
+ return false;
37
+ }
38
+
39
+ const stats = statSync(filePath);
40
+
41
+ return {
42
+ contentType: file.mediaType,
43
+ contentLength: Number(file.size),
44
+ lastModified: stats.mtime,
45
+ };
46
+ },
47
+ get: async (file: File) => {
48
+ const filePath = (file.meta as { storagePath: string }).storagePath;
49
+
50
+ if (!existsSync(filePath)) {
51
+ return false;
52
+ }
53
+
54
+ const stats = statSync(filePath);
55
+
56
+ return {
57
+ type: 'stream',
58
+ stream: createReadStream(filePath),
59
+ metadata: {
60
+ contentType: file.mediaType,
61
+ contentLength: Number(file.size),
62
+ lastModified: stats.mtime,
63
+ },
64
+ };
65
+ },
66
+ };
67
+
68
+ const transformRoCrate = (filePath: string, remapRootTo: string): { rocrate: unknown; jsonString: string } | false => {
69
+ const fileContents = readFileSync(filePath, 'utf-8');
70
+ const rocrate = JSON.parse(fileContents) as {
71
+ '@context'?: unknown;
72
+ '@graph'?: Array<{ '@id': string; [key: string]: unknown }>;
73
+ [key: string]: unknown;
74
+ };
75
+
76
+ const graph = rocrate['@graph'] || [];
77
+ const rootNode = graph.find((node) => node['@id'] === 'ro-crate-metadata.json') as
78
+ | { about: { '@id': string } }
79
+ | undefined;
80
+
81
+ if (!rootNode) {
82
+ return false;
83
+ }
84
+
85
+ rootNode.about['@id'] = remapRootTo;
86
+
87
+ const jsonString = JSON.stringify(rocrate);
88
+
89
+ return { rocrate, jsonString };
90
+ };
91
+
92
+ const roCrateHandler: RoCrateHandler = {
93
+ head: async (entity: Entity) => {
94
+ const meta = entity.meta as { storagePath: string; remapRootTo: string };
95
+ const filePath = meta.storagePath;
96
+
97
+ if (!existsSync(filePath)) {
98
+ return false;
99
+ }
100
+
101
+ if (meta.remapRootTo) {
102
+ const result = transformRoCrate(filePath, meta.remapRootTo);
103
+
104
+ if (!result) {
105
+ return false;
106
+ }
107
+
108
+ return {
109
+ contentType: 'application/ld+json',
110
+ contentLength: Buffer.byteLength(result.jsonString),
111
+ lastModified: statSync(filePath).mtime,
112
+ };
113
+ }
114
+
115
+ const stats = statSync(filePath);
116
+
117
+ return {
118
+ contentType: 'application/ld+json',
119
+ contentLength: stats.size,
120
+ lastModified: stats.mtime,
121
+ };
122
+ },
123
+ get: async (entity: Entity) => {
124
+ const meta = entity.meta as { storagePath: string; remapRootTo: string };
125
+ const filePath = meta.storagePath;
126
+
127
+ if (!existsSync(filePath)) {
128
+ return false;
129
+ }
130
+
131
+ if (meta.remapRootTo) {
132
+ const result = transformRoCrate(filePath, meta.remapRootTo);
133
+
134
+ if (!result) {
135
+ return false;
136
+ }
137
+
138
+ return {
139
+ type: 'stream',
140
+ stream: Readable.from(result.jsonString),
141
+ metadata: {
142
+ contentType: 'application/ld+json',
143
+ contentLength: Buffer.byteLength(result.jsonString),
144
+ lastModified: statSync(filePath).mtime,
145
+ },
146
+ };
147
+ }
148
+
149
+ const stats = statSync(filePath);
150
+
151
+ return {
152
+ type: 'stream',
153
+ stream: createReadStream(filePath),
154
+ metadata: {
155
+ contentType: 'application/ld+json',
156
+ contentLength: stats.size,
157
+ lastModified: stats.mtime,
158
+ },
159
+ };
160
+ },
161
+ };
162
+
163
+ const oniTransformer: EntityTransformer = (entity, { request: _r, fastify: _f }) => {
164
+ return {
165
+ ...entity,
166
+ accessControl: 'Public',
167
+ counts: {
168
+ collections: 0,
169
+ objects: 0,
170
+ files: 0,
171
+ },
172
+ };
173
+ };
174
+
175
+ const fastify = Fastify({
176
+ logger: true,
177
+ });
178
+ fastify.register(arocapi, {
179
+ prisma,
180
+ opensearch,
181
+ fileHandler,
182
+ roCrateHandler,
183
+ accessTransformer: AllPublicAccessTransformer,
184
+ entityTransformers: [oniTransformer],
185
+ fileAccessTransformer: AllPublicFileAccessTransformer,
186
+ });
187
+
188
+ const start = async () => {
189
+ try {
190
+ await fastify.listen({ port: 9000 });
191
+ } catch (err) {
192
+ fastify.log.error(err);
193
+ process.exit(1);
194
+ }
195
+ };
196
+ start();
package/src/reset.d.ts ADDED
@@ -0,0 +1 @@
1
+ import '@total-typescript/ts-reset';
@@ -0,0 +1,68 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Entities Route > GET /entities > should apply custom entity transformers 1`] = `
4
+ {
5
+ "entities": [
6
+ {
7
+ "access": {
8
+ "content": true,
9
+ "metadata": true,
10
+ },
11
+ "contentLicenseId": "https://creativecommons.org/licenses/by/4.0/",
12
+ "description": "First test entity",
13
+ "entityType": "http://pcdm.org/models#Collection",
14
+ "id": "http://example.com/entity/1",
15
+ "memberOf": null,
16
+ "metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
17
+ "name": "Test Entity 1",
18
+ "rootCollection": null,
19
+ "tested": true,
20
+ },
21
+ ],
22
+ }
23
+ `;
24
+
25
+ exports[`Entities Route > GET /entities > should return 500 when database error occurs 1`] = `
26
+ {
27
+ "error": {
28
+ "code": "INTERNAL_ERROR",
29
+ "message": "Internal server error",
30
+ },
31
+ }
32
+ `;
33
+
34
+ exports[`Entities Route > GET /entities > should return entities with default pagination 1`] = `
35
+ {
36
+ "entities": [
37
+ {
38
+ "access": {
39
+ "content": true,
40
+ "metadata": true,
41
+ },
42
+ "contentLicenseId": "https://creativecommons.org/licenses/by/4.0/",
43
+ "description": "First test entity",
44
+ "entityType": "http://pcdm.org/models#Collection",
45
+ "id": "http://example.com/entity/1",
46
+ "memberOf": null,
47
+ "metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
48
+ "name": "Test Entity 1",
49
+ "rootCollection": null,
50
+ },
51
+ {
52
+ "access": {
53
+ "content": true,
54
+ "metadata": true,
55
+ },
56
+ "contentLicenseId": "https://creativecommons.org/licenses/by/4.0/",
57
+ "description": "Second test entity",
58
+ "entityType": "http://pcdm.org/models#Object",
59
+ "id": "http://example.com/entity/2",
60
+ "memberOf": "http://example.com/entity/1",
61
+ "metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
62
+ "name": "Test Entity 2",
63
+ "rootCollection": "http://example.com/entity/1",
64
+ },
65
+ ],
66
+ "total": 2,
67
+ }
68
+ `;
@@ -0,0 +1,57 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Entity Route > GET /entity/:id > should apply custom entity transformers 1`] = `
4
+ {
5
+ "access": {
6
+ "content": true,
7
+ "metadata": true,
8
+ },
9
+ "contentLicenseId": "https://creativecommons.org/licenses/by/4.0/",
10
+ "description": "A test entity",
11
+ "entityType": "http://pcdm.org/models#Collection",
12
+ "id": "http://example.com/entity/123",
13
+ "memberOf": null,
14
+ "metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
15
+ "name": "Test Entity",
16
+ "rootCollection": null,
17
+ "tested": true,
18
+ }
19
+ `;
20
+
21
+ exports[`Entity Route > GET /entity/:id > should return 404 when entity not found 1`] = `
22
+ {
23
+ "error": {
24
+ "code": "NOT_FOUND",
25
+ "details": {
26
+ "entityId": "http://example.com/entity/nonexistent",
27
+ },
28
+ "message": "The requested entity was not found",
29
+ },
30
+ }
31
+ `;
32
+
33
+ exports[`Entity Route > GET /entity/:id > should return 500 when database error occurs 1`] = `
34
+ {
35
+ "error": {
36
+ "code": "INTERNAL_ERROR",
37
+ "message": "Internal server error",
38
+ },
39
+ }
40
+ `;
41
+
42
+ exports[`Entity Route > GET /entity/:id > should return entity when found 1`] = `
43
+ {
44
+ "access": {
45
+ "content": true,
46
+ "metadata": true,
47
+ },
48
+ "contentLicenseId": "https://creativecommons.org/licenses/by/4.0/",
49
+ "description": "A test entity",
50
+ "entityType": "http://schema.org/Person",
51
+ "id": "http://example.com/entity/123",
52
+ "memberOf": null,
53
+ "metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
54
+ "name": "Test Entity",
55
+ "rootCollection": null,
56
+ }
57
+ `;
@@ -0,0 +1,139 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Search Route > POST /search > should apply custom entity transformers 1`] = `
4
+ {
5
+ "entities": [
6
+ {
7
+ "access": {
8
+ "content": true,
9
+ "metadata": true,
10
+ },
11
+ "contentLicenseId": null,
12
+ "description": "A test entity",
13
+ "entityType": "http://pcdm.org/models#Collection",
14
+ "id": "http://example.com/entity/1",
15
+ "memberOf": null,
16
+ "metadataLicenseId": null,
17
+ "name": "Test Entity 1",
18
+ "rootCollection": null,
19
+ "searchExtra": {
20
+ "highlight": {},
21
+ "score": 1.5,
22
+ },
23
+ "tested": true,
24
+ },
25
+ ],
26
+ "searchTime": 10,
27
+ "total": 1,
28
+ }
29
+ `;
30
+
31
+ exports[`Search Route > POST /search > should handle opensearch errors 1`] = `
32
+ {
33
+ "error": {
34
+ "code": "INTERNAL_ERROR",
35
+ "message": "Search failed",
36
+ },
37
+ }
38
+ `;
39
+
40
+ exports[`Search Route > POST /search > should handle rocrateId explicitly set to undefined 1`] = `
41
+ {
42
+ "error": {
43
+ "code": "INTERNAL_ERROR",
44
+ "message": "Search failed",
45
+ },
46
+ }
47
+ `;
48
+
49
+ exports[`Search Route > POST /search > should perform basic search successfully 1`] = `
50
+ {
51
+ "entities": [
52
+ {
53
+ "access": {
54
+ "content": true,
55
+ "metadata": true,
56
+ },
57
+ "contentLicenseId": null,
58
+ "description": "A test entity",
59
+ "entityType": "http://pcdm.org/models#Collection",
60
+ "id": "http://example.com/entity/1",
61
+ "memberOf": null,
62
+ "metadataLicenseId": null,
63
+ "name": "Test Entity 1",
64
+ "rootCollection": null,
65
+ "searchExtra": {
66
+ "highlight": {
67
+ "name": [
68
+ "<em>Test</em> Entity 1",
69
+ ],
70
+ },
71
+ "score": 1.5,
72
+ },
73
+ },
74
+ {
75
+ "access": {
76
+ "content": true,
77
+ "metadata": true,
78
+ },
79
+ "contentLicenseId": null,
80
+ "description": "Another test entity",
81
+ "entityType": "http://pcdm.org/models#Object",
82
+ "id": "http://example.com/entity/2",
83
+ "memberOf": null,
84
+ "metadataLicenseId": null,
85
+ "name": "Test Entity 2",
86
+ "rootCollection": null,
87
+ "searchExtra": {
88
+ "highlight": {
89
+ "description": [
90
+ "Another <em>test</em> entity",
91
+ ],
92
+ },
93
+ "score": 1.2,
94
+ },
95
+ },
96
+ ],
97
+ "facets": {
98
+ "entityType": [
99
+ {
100
+ "count": 1,
101
+ "name": "http://pcdm.org/models#Collection",
102
+ },
103
+ {
104
+ "count": 1,
105
+ "name": "http://pcdm.org/models#Object",
106
+ },
107
+ ],
108
+ },
109
+ "searchTime": 10,
110
+ "total": 2,
111
+ }
112
+ `;
113
+
114
+ exports[`Search Route > POST /search > should skip entities not found in database and log warning 1`] = `
115
+ {
116
+ "entities": [
117
+ {
118
+ "access": {
119
+ "content": true,
120
+ "metadata": true,
121
+ },
122
+ "contentLicenseId": null,
123
+ "description": "A test entity",
124
+ "entityType": "http://pcdm.org/models#Collection",
125
+ "id": "http://example.com/entity/1",
126
+ "memberOf": null,
127
+ "metadataLicenseId": null,
128
+ "name": "Test Entity 1",
129
+ "rootCollection": null,
130
+ "searchExtra": {
131
+ "highlight": {},
132
+ "score": 1.5,
133
+ },
134
+ },
135
+ ],
136
+ "searchTime": 10,
137
+ "total": 2,
138
+ }
139
+ `;