arocapi 2.1.0 → 3.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.
Files changed (88) hide show
  1. package/README.md +57 -9
  2. package/dist/app.d.ts +1 -1
  3. package/dist/app.js +5 -1
  4. package/dist/app.js.map +1 -1
  5. package/dist/index.dev.js +11 -1
  6. package/dist/index.dev.js.map +1 -1
  7. package/dist/routes/crate.js +5 -18
  8. package/dist/routes/crate.js.map +1 -1
  9. package/dist/routes/crate.test.js +20 -22
  10. package/dist/routes/crate.test.js.map +1 -1
  11. package/dist/routes/entities.js +12 -10
  12. package/dist/routes/entities.js.map +1 -1
  13. package/dist/routes/entities.test.js +18 -18
  14. package/dist/routes/entities.test.js.map +1 -1
  15. package/dist/routes/entity.js +3 -4
  16. package/dist/routes/entity.js.map +1 -1
  17. package/dist/routes/entity.test.js +11 -16
  18. package/dist/routes/entity.test.js.map +1 -1
  19. package/dist/routes/file.js +5 -18
  20. package/dist/routes/file.js.map +1 -1
  21. package/dist/routes/file.test.js +18 -22
  22. package/dist/routes/file.test.js.map +1 -1
  23. package/dist/routes/files.js +12 -11
  24. package/dist/routes/files.js.map +1 -1
  25. package/dist/routes/files.test.js +5 -34
  26. package/dist/routes/files.test.js.map +1 -1
  27. package/dist/routes/search.js +15 -12
  28. package/dist/routes/search.js.map +1 -1
  29. package/dist/routes/search.test.js +53 -23
  30. package/dist/routes/search.test.js.map +1 -1
  31. package/dist/test/integration.setup.d.ts +2 -4
  32. package/dist/test/integration.setup.js +18 -21
  33. package/dist/test/integration.setup.js.map +1 -1
  34. package/dist/transformers/default.d.ts +11 -18
  35. package/dist/transformers/default.js +5 -18
  36. package/dist/transformers/default.js.map +1 -1
  37. package/dist/transformers/default.test.js +6 -15
  38. package/dist/transformers/default.test.js.map +1 -1
  39. package/dist/transformers/transformer.test.js +2 -6
  40. package/dist/transformers/transformer.test.js.map +1 -1
  41. package/dist/utils/errors.d.ts +7 -1
  42. package/dist/utils/errors.js +2 -1
  43. package/dist/utils/errors.js.map +1 -1
  44. package/dist/utils/headers.d.ts +7 -0
  45. package/dist/utils/headers.js +11 -0
  46. package/dist/utils/headers.js.map +1 -0
  47. package/dist/utils/queryBuilder.d.ts +2 -2
  48. package/dist/utils/queryBuilder.js +2 -3
  49. package/dist/utils/queryBuilder.js.map +1 -1
  50. package/package.json +24 -23
  51. package/prisma/models/entity.prisma +17 -13
  52. package/prisma/models/file.prisma +9 -13
  53. package/prisma.config.ts +0 -2
  54. package/src/app.ts +7 -2
  55. package/src/index.dev.ts +12 -1
  56. package/src/routes/__snapshots__/search.test.ts.snap +2 -2
  57. package/src/routes/crate.test.ts +20 -22
  58. package/src/routes/crate.ts +6 -24
  59. package/src/routes/entities.test.ts +21 -18
  60. package/src/routes/entities.ts +12 -12
  61. package/src/routes/entity.test.ts +13 -16
  62. package/src/routes/entity.ts +3 -4
  63. package/src/routes/file.test.ts +18 -22
  64. package/src/routes/file.ts +6 -24
  65. package/src/routes/files.test.ts +5 -37
  66. package/src/routes/files.ts +12 -13
  67. package/src/routes/search.test.ts +62 -25
  68. package/src/routes/search.ts +19 -12
  69. package/src/test/integration.setup.ts +19 -21
  70. package/src/transformers/default.test.ts +10 -20
  71. package/src/transformers/default.ts +14 -27
  72. package/src/transformers/transformer.test.ts +4 -6
  73. package/src/utils/errors.ts +10 -6
  74. package/src/utils/headers.ts +16 -0
  75. package/src/utils/queryBuilder.ts +3 -5
  76. package/prisma/migrations/20250515034400_entities/migration.sql +0 -14
  77. package/prisma/migrations/20250515050009_extend_entity_fields/migration.sql +0 -7
  78. package/prisma/migrations/20250804225438_add_record_type/migration.sql +0 -8
  79. package/prisma/migrations/20250805040110_add_rocrate_field/migration.sql +0 -2
  80. package/prisma/migrations/20250827033956_record_type_scalar/migration.sql +0 -10
  81. package/prisma/migrations/20250923032753_api_refactor/migration.sql +0 -39
  82. package/prisma/migrations/20250923223119_entity_type_to_string/migration.sql +0 -8
  83. package/prisma/migrations/20251020140329_add_meta_column/migration.sql +0 -2
  84. package/prisma/migrations/20251027010713_add_file_table/migration.sql +0 -17
  85. package/prisma/migrations/20251027221138_add_file_id_to_entity/migration.sql +0 -2
  86. package/prisma/migrations/20251211025510_remove_rocrate_column/migration.sql +0 -8
  87. package/prisma/migrations/migration_lock.toml +0 -3
  88. package/prisma/schema.prisma +0 -17
@@ -5,7 +5,7 @@ import type { ZodTypeProvider } from 'fastify-type-provider-zod';
5
5
  import { z } from 'zod/v4';
6
6
  import { baseEntityTransformer, resolveEntityReferences } from '../transformers/default.js';
7
7
  import type { AccessTransformer, EntityTransformer } from '../types/transformers.js';
8
- import { createInternalError } from '../utils/errors.js';
8
+ import { createInternalError, createInvalidRequestError } from '../utils/errors.js';
9
9
  import { OpensearchQueryBuilder, type QueryBuilderOptions } from '../utils/queryBuilder.js';
10
10
 
11
11
  const boundingBoxSchema = z.object({
@@ -24,7 +24,7 @@ const searchParamsSchema = z.object({
24
24
  query: z.string(),
25
25
  filters: z.record(z.string(), z.array(z.string())).optional(),
26
26
  boundingBox: boundingBoxSchema.optional(),
27
- geohashPrecision: z.number().int().min(0).max(12).default(5),
27
+ geohashPrecision: z.number().int().min(1).max(12).optional(),
28
28
  limit: z.number().int().min(1).max(1000).default(100),
29
29
  offset: z.number().int().min(0).default(0),
30
30
  sort: z.enum(['id', 'name', 'createdAt', 'updatedAt', 'relevance']).default('relevance'),
@@ -80,32 +80,31 @@ const search: FastifyPluginAsync<SearchRouteOptions> = async (fastify, opts) =>
80
80
  throw new Error('Invalid search response: missing hits data');
81
81
  }
82
82
 
83
- const rocrateIds = response.body.hits.hits
84
- .map((hit) => hit._source?.rocrateId as string | undefined)
85
- .filter(Boolean);
83
+ const entityIds = response.body.hits.hits.map((hit) => hit._source?.id as string | undefined).filter(Boolean);
86
84
 
87
85
  const dbEntities = await fastify.prisma.entity.findMany({
88
86
  where: {
89
- rocrateId: {
90
- in: rocrateIds,
87
+ id: {
88
+ in: entityIds,
91
89
  },
92
90
  },
91
+ include: { file: { select: { id: true } } },
93
92
  });
94
93
 
95
- const entityMap = new Map(dbEntities.map((entity) => [entity.rocrateId, entity]));
94
+ const entityMap = new Map(dbEntities.map((entity) => [entity.id, entity]));
96
95
 
97
96
  // Resolve memberOf and rootCollection references
98
97
  const refMap = await resolveEntityReferences(dbEntities, fastify.prisma);
99
98
 
100
99
  const entities = await Promise.all(
101
100
  response.body.hits.hits.map(async (hit) => {
102
- if (!hit._source?.rocrateId) {
103
- throw new Error('Missing rocrateId in search hit');
101
+ if (!hit._source?.id) {
102
+ throw new Error('Missing id in search hit');
104
103
  }
105
104
 
106
- const dbEntity = entityMap.get(hit._source.rocrateId);
105
+ const dbEntity = entityMap.get(hit._source.id);
107
106
  if (!dbEntity) {
108
- fastify.log.warn(`Entity ${hit._source.rocrateId} found in OpenSearch but not in database`);
107
+ fastify.log.warn(`Entity ${hit._source.id} found in OpenSearch but not in database`);
109
108
 
110
109
  return null;
111
110
  }
@@ -183,6 +182,14 @@ const search: FastifyPluginAsync<SearchRouteOptions> = async (fastify, opts) =>
183
182
  return result;
184
183
  } catch (error) {
185
184
  const err = error as Error;
185
+
186
+ // OpenSearch returns 400 for malformed queries (e.g. invalid query_string syntax)
187
+ if ('statusCode' in err && (err as { statusCode: number }).statusCode === 400) {
188
+ fastify.log.warn(`Invalid search query: ${err.message}`);
189
+
190
+ return reply.code(422).send(createInvalidRequestError(err.message));
191
+ }
192
+
186
193
  fastify.log.error(`Search error: ${err.message}`);
187
194
 
188
195
  return reply.code(500).send(createInternalError('Search failed'));
@@ -1,4 +1,5 @@
1
1
  import { Client } from '@opensearch-project/opensearch';
2
+ import { PrismaMariaDb } from '@prisma/adapter-mariadb';
2
3
  import type { FastifyInstance } from 'fastify';
3
4
  import Fastify from 'fastify';
4
5
  import app, { AllPublicAccessTransformer, AllPublicFileAccessTransformer } from '../app.js';
@@ -15,13 +16,17 @@ export async function setupIntegrationTests() {
15
16
  process.env.OPENSEARCH_URL = 'http://localhost:9201';
16
17
  process.env.NODE_ENV = 'test';
17
18
 
18
- prisma = new PrismaClient({
19
- datasources: {
20
- db: {
21
- url: process.env.DATABASE_URL,
22
- },
23
- },
19
+ const adapter = new PrismaMariaDb({
20
+ host: 'localhost',
21
+ user: 'root',
22
+ password: 'password',
23
+ database: 'catalog_test',
24
+ port: 3307,
25
+ connectionLimit: 5,
26
+ // NOTE: This is required when using the default MariaDB server configuration with SSL disabled. In production, you should properly configure SSL and remove this option.
27
+ allowPublicKeyRetrieval: true,
24
28
  });
29
+ prisma = new PrismaClient({ adapter });
25
30
 
26
31
  opensearch = new Client({
27
32
  node: process.env.OPENSEARCH_URL,
@@ -65,6 +70,7 @@ export async function teardownIntegrationTests() {
65
70
  }
66
71
 
67
72
  export async function cleanupTestData() {
73
+ await prisma.file.deleteMany({});
68
74
  await prisma.entity.deleteMany({});
69
75
 
70
76
  await opensearch.indices.delete({
@@ -78,8 +84,7 @@ export async function seedTestData() {
78
84
 
79
85
  const testEntities = [
80
86
  {
81
- id: 1,
82
- rocrateId: 'http://example.com/entity/1',
87
+ id: 'http://example.com/entity/1',
83
88
  name: 'Test Collection',
84
89
  description: 'First test entity',
85
90
  entityType: 'http://pcdm.org/models#Collection',
@@ -91,8 +96,7 @@ export async function seedTestData() {
91
96
  updatedAt: new Date(),
92
97
  },
93
98
  {
94
- id: 2,
95
- rocrateId: 'http://example.com/entity/2',
99
+ id: 'http://example.com/entity/2',
96
100
  name: 'Test Object',
97
101
  description: 'Second test entity',
98
102
  entityType: 'http://pcdm.org/models#Object',
@@ -104,8 +108,7 @@ export async function seedTestData() {
104
108
  updatedAt: new Date(),
105
109
  },
106
110
  {
107
- id: 3,
108
- rocrateId: 'http://example.com/entity/3',
111
+ id: 'http://example.com/entity/3',
109
112
  name: 'Test Person',
110
113
  description: 'Third test entity',
111
114
  entityType: 'http://schema.org/Person',
@@ -117,8 +120,7 @@ export async function seedTestData() {
117
120
  updatedAt: new Date(),
118
121
  },
119
122
  {
120
- id: 4,
121
- rocrateId: 'http://example.com/entity/4',
123
+ id: 'http://example.com/entity/4',
122
124
  name: 'test-audio.wav',
123
125
  description: 'Test audio file',
124
126
  entityType: 'http://schema.org/MediaObject',
@@ -130,8 +132,7 @@ export async function seedTestData() {
130
132
  updatedAt: new Date(),
131
133
  },
132
134
  {
133
- id: 5,
134
- rocrateId: 'http://example.com/entity/5',
135
+ id: 'http://example.com/entity/5',
135
136
  name: 'collection-metadata.csv',
136
137
  description: 'Collection metadata file',
137
138
  entityType: 'http://schema.org/MediaObject',
@@ -153,7 +154,7 @@ export async function seedTestData() {
153
154
  body: {
154
155
  mappings: {
155
156
  properties: {
156
- rocrateId: { type: 'keyword' },
157
+ id: { type: 'keyword' },
157
158
  name: {
158
159
  type: 'text',
159
160
  fields: {
@@ -173,10 +174,7 @@ export async function seedTestData() {
173
174
  },
174
175
  });
175
176
 
176
- const testDocs = testEntities.flatMap((entity, index) => [
177
- { index: { _index: 'entities', _id: `${index + 1}` } },
178
- entity,
179
- ]);
177
+ const testDocs = testEntities.flatMap((entity) => [{ index: { _index: 'entities', _id: entity.id } }, entity]);
180
178
 
181
179
  await opensearch.bulk({
182
180
  body: testDocs,
@@ -4,13 +4,11 @@ import { AllPublicAccessTransformer, baseEntityTransformer } from './default.js'
4
4
 
5
5
  describe('baseEntityTransformer', () => {
6
6
  it('should transform entity to standard entity shape', () => {
7
- const entity: Entity = {
8
- id: 1,
9
- rocrateId: 'http://example.com/entity/123',
7
+ const entity: Entity & { file?: { id: string } | null } = {
8
+ id: 'http://example.com/entity/123',
10
9
  name: 'Test Entity',
11
10
  description: 'A test entity description',
12
11
  entityType: 'http://pcdm.org/models#Collection',
13
- fileId: null,
14
12
  memberOf: 'http://example.com/parent',
15
13
  rootCollection: 'http://example.com/root',
16
14
  metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
@@ -35,13 +33,11 @@ describe('baseEntityTransformer', () => {
35
33
  });
36
34
 
37
35
  it('should handle null memberOf and rootCollection', () => {
38
- const entity: Entity = {
39
- id: 1,
40
- rocrateId: 'http://example.com/collection',
36
+ const entity: Entity & { file?: { id: string } | null } = {
37
+ id: 'http://example.com/collection',
41
38
  name: 'Top Collection',
42
39
  description: 'A top-level collection',
43
40
  entityType: 'http://pcdm.org/models#Collection',
44
- fileId: null,
45
41
  memberOf: null,
46
42
  rootCollection: null,
47
43
  metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
@@ -58,13 +54,11 @@ describe('baseEntityTransformer', () => {
58
54
  });
59
55
 
60
56
  it('should exclude database-specific fields', () => {
61
- const entity: Entity = {
62
- id: 1,
63
- rocrateId: 'http://example.com/entity/456',
57
+ const entity: Entity & { file?: { id: string } | null } = {
58
+ id: 'http://example.com/entity/456',
64
59
  name: 'Test',
65
60
  description: 'Test',
66
61
  entityType: 'http://pcdm.org/models#Object',
67
- fileId: null,
68
62
  memberOf: null,
69
63
  rootCollection: null,
70
64
  metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
@@ -76,7 +70,6 @@ describe('baseEntityTransformer', () => {
76
70
 
77
71
  const result = baseEntityTransformer(entity);
78
72
 
79
- // Result should have 'id' (mapped from rocrateId), but not the numeric database id
80
73
  expect(result.id).toBe('http://example.com/entity/456');
81
74
  expect(result).not.toHaveProperty('createdAt');
82
75
  expect(result).not.toHaveProperty('updatedAt');
@@ -93,14 +86,12 @@ describe('baseEntityTransformer', () => {
93
86
  ]);
94
87
  });
95
88
 
96
- it('should handle File entity (MediaObject) with fileId', () => {
97
- const entity: Entity = {
98
- id: 1,
99
- rocrateId: 'http://example.com/file/audio.wav',
89
+ it('should handle File entity (MediaObject) with file relation', () => {
90
+ const entity: Entity & { file?: { id: string } | null } = {
91
+ id: 'http://example.com/file/audio.wav',
100
92
  name: 'Audio File',
101
93
  description: 'An audio recording',
102
94
  entityType: 'http://schema.org/MediaObject',
103
- fileId: 'http://example.com/files/audio.wav',
104
95
  memberOf: 'http://example.com/collection',
105
96
  rootCollection: 'http://example.com/collection',
106
97
  metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
@@ -108,6 +99,7 @@ describe('baseEntityTransformer', () => {
108
99
  createdAt: new Date(),
109
100
  updatedAt: new Date(),
110
101
  meta: null,
102
+ file: { id: 'http://example.com/files/audio.wav' },
111
103
  };
112
104
 
113
105
  const result = baseEntityTransformer(entity);
@@ -117,13 +109,11 @@ describe('baseEntityTransformer', () => {
117
109
  name: 'Audio File',
118
110
  description: 'An audio recording',
119
111
  entityType: 'http://schema.org/MediaObject',
120
- fileId: 'http://example.com/files/audio.wav',
121
112
  memberOf: 'http://example.com/collection',
122
113
  rootCollection: 'http://example.com/collection',
123
114
  metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
124
115
  contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
125
116
  });
126
- expect(result.fileId).toBe('http://example.com/files/audio.wav');
127
117
  });
128
118
  });
129
119
 
@@ -1,5 +1,7 @@
1
1
  import type { Entity, File, PrismaClient } from '../generated/prisma/client.js';
2
2
 
3
+ type EntityWithFile = Entity & { file?: { id: string } | null };
4
+
3
5
  /**
4
6
  * Entity reference - used for memberOf and rootCollection
5
7
  */
@@ -14,13 +16,14 @@ type EntityReference = {
14
16
  */
15
17
  export type BaseEntity = {
16
18
  id: string;
19
+ entityType: string;
17
20
  name: string;
18
21
  description: string;
19
22
  memberOf: string | null;
20
23
  rootCollection: string | null;
21
24
  metadataLicenseId: string;
22
25
  contentLicenseId: string;
23
- } & ({ entityType: string; fileId?: never } | { entityType: 'http://schema.org/MediaObject'; fileId: string });
26
+ };
24
27
 
25
28
  /**
26
29
  * Standard entity shape - with resolved references
@@ -28,13 +31,14 @@ export type BaseEntity = {
28
31
  */
29
32
  export type StandardEntity = {
30
33
  id: string;
34
+ entityType: string;
31
35
  name: string;
32
36
  description: string;
33
37
  memberOf: EntityReference | null;
34
38
  rootCollection: EntityReference | null;
35
39
  metadataLicenseId: string;
36
40
  contentLicenseId: string;
37
- } & ({ entityType: string; fileId?: never } | { entityType: 'http://schema.org/MediaObject'; fileId: string });
41
+ };
38
42
 
39
43
  /**
40
44
  * Access information for an entity
@@ -42,6 +46,7 @@ export type StandardEntity = {
42
46
  type AccessInfo = {
43
47
  metadata: boolean;
44
48
  content: boolean;
49
+ metadataAuthorizationUrl?: string;
45
50
  contentAuthorizationUrl?: string;
46
51
  };
47
52
 
@@ -65,16 +70,12 @@ type FileAccessInfo = {
65
70
  /**
66
71
  * Standard file shape - output of base file transformation
67
72
  * Does not include access information
68
- * Files only have contentLicenseId (no metadataLicenseId)
69
73
  */
70
74
  export type StandardFile = {
71
75
  id: string;
72
76
  filename: string;
73
77
  mediaType: string;
74
78
  size: number;
75
- memberOf: string;
76
- rootCollection: string;
77
- contentLicenseId: string;
78
79
  };
79
80
 
80
81
  /**
@@ -89,10 +90,11 @@ export type AuthorisedFile = StandardFile & {
89
90
  /**
90
91
  * Base entity transformer - always applied first
91
92
  * Transforms raw database entity to base entity shape with unresolved references
93
+ * Accepts Entity with optional file relation included
92
94
  */
93
- export const baseEntityTransformer = (entity: Entity): BaseEntity => {
95
+ export const baseEntityTransformer = (entity: EntityWithFile): BaseEntity => {
94
96
  const base: BaseEntity = {
95
- id: entity.rocrateId,
97
+ id: entity.id,
96
98
  name: entity.name,
97
99
  description: entity.description,
98
100
  entityType: entity.entityType,
@@ -102,18 +104,6 @@ export const baseEntityTransformer = (entity: Entity): BaseEntity => {
102
104
  contentLicenseId: entity.contentLicenseId,
103
105
  };
104
106
 
105
- if (base.entityType === ('http://schema.org/MediaObject' as const)) {
106
- if (!entity.fileId) {
107
- return base;
108
- }
109
-
110
- return {
111
- ...base,
112
- entityType: base.entityType,
113
- fileId: entity.fileId,
114
- };
115
- }
116
-
117
107
  return base;
118
108
  };
119
109
 
@@ -148,13 +138,10 @@ export const AllPublicAccessTransformer = (entity: StandardEntity): AuthorisedEn
148
138
  * Transforms raw database file to standard file shape (without access)
149
139
  */
150
140
  export const baseFileTransformer = (file: File): StandardFile => ({
151
- id: file.fileId,
141
+ id: file.id,
152
142
  filename: file.filename,
153
143
  mediaType: file.mediaType,
154
144
  size: Number(file.size),
155
- memberOf: file.memberOf,
156
- rootCollection: file.rootCollection,
157
- contentLicenseId: file.contentLicenseId,
158
145
  });
159
146
 
160
147
  /**
@@ -215,9 +202,9 @@ export const resolveEntityReferences = async (
215
202
  }
216
203
 
217
204
  const refs = await prisma.entity.findMany({
218
- where: { rocrateId: { in: [...refIds] } },
219
- select: { rocrateId: true, name: true },
205
+ where: { id: { in: [...refIds] } },
206
+ select: { id: true, name: true },
220
207
  });
221
208
 
222
- return new Map(refs.map((r) => [r.rocrateId, { id: r.rocrateId, name: r.name }]));
209
+ return new Map(refs.map((r) => [r.id, { id: r.id, name: r.name }]));
223
210
  };
@@ -37,12 +37,11 @@ describe('Entity Transformers', () => {
37
37
  describe('baseEntityTransformer', () => {
38
38
  it('should transform raw entity to base shape with unresolved references', () => {
39
39
  const rawEntity = {
40
- id: 1,
41
- rocrateId: 'http://example.com/entity/123',
40
+ id: 'http://example.com/entity/123',
42
41
  name: 'Test Entity',
43
42
  description: 'A test entity',
44
43
  entityType: 'http://schema.org/Person',
45
- fileId: null,
44
+
46
45
  memberOf: 'http://example.com/collection',
47
46
  rootCollection: 'http://example.com/root',
48
47
  metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
@@ -195,12 +194,11 @@ describe('Entity Transformers', () => {
195
194
 
196
195
  it('should demonstrate full pipeline: base -> resolve -> access -> custom', async () => {
197
196
  const rawEntity = {
198
- id: 1,
199
- rocrateId: 'http://example.com/entity/123',
197
+ id: 'http://example.com/entity/123',
200
198
  name: 'Test Entity',
201
199
  description: 'A test entity',
202
200
  entityType: 'http://schema.org/Person',
203
- fileId: null,
201
+
204
202
  memberOf: 'http://example.com/collection',
205
203
  rootCollection: 'http://example.com/root',
206
204
  metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
@@ -29,16 +29,20 @@ const createErrorResponse = (code: ErrorCode, message: string, details?: ErrorDe
29
29
  },
30
30
  });
31
31
 
32
- export const createValidationError = (message: string, issues: string[]): StandardErrorResponse =>
33
- createErrorResponse(ERROR_CODES.VALIDATION_ERROR, message, { issues });
32
+ type ValidationViolation = {
33
+ field: string;
34
+ message: string;
35
+ value?: unknown;
36
+ };
37
+
38
+ export const createValidationError = (message: string, violations: ValidationViolation[]): StandardErrorResponse =>
39
+ createErrorResponse(ERROR_CODES.VALIDATION_ERROR, message, { violations });
34
40
 
35
41
  export const createNotFoundError = (message: string, entityId?: string): StandardErrorResponse =>
36
42
  createErrorResponse(ERROR_CODES.NOT_FOUND, message, entityId ? { entityId } : undefined);
37
43
 
38
- // export const createRateLimitError = (retryAfter: number): StandardErrorResponse =>
39
- // createErrorResponse(ERROR_CODES.RATE_LIMIT_EXCEEDED, 'Rate limit exceeded. Please retry after the specified time.', {
40
- // retryAfter,
41
- // });
44
+ export const createInvalidRequestError = (message: string): StandardErrorResponse =>
45
+ createErrorResponse(ERROR_CODES.INVALID_REQUEST, message);
42
46
 
43
47
  export const createInternalError = (message = 'Internal server error'): StandardErrorResponse => {
44
48
  return createErrorResponse(ERROR_CODES.INTERNAL_ERROR, message);
@@ -0,0 +1,16 @@
1
+ import type { FastifyReply } from 'fastify';
2
+
3
+ export const setFileHeaders = (
4
+ reply: FastifyReply,
5
+ metadata: { contentType: string; contentLength: number; etag?: string; lastModified?: Date },
6
+ ) => {
7
+ reply.header('Content-Type', metadata.contentType);
8
+ reply.header('Content-Length', metadata.contentLength.toString());
9
+
10
+ if (metadata.etag) {
11
+ reply.header('ETag', metadata.etag);
12
+ }
13
+ if (metadata.lastModified) {
14
+ reply.header('Last-Modified', metadata.lastModified.toUTCString());
15
+ }
16
+ };
@@ -92,7 +92,7 @@ export class OpensearchQueryBuilder {
92
92
  };
93
93
  }
94
94
 
95
- buildAggregations(geohashPrecision: number, boundingBox?: BoundingBox) {
95
+ buildAggregations(geohashPrecision?: number, boundingBox?: BoundingBox) {
96
96
  const aggs = { ...this.aggregations };
97
97
 
98
98
  // Add geohash aggregation if precision is specified
@@ -123,12 +123,10 @@ export class OpensearchQueryBuilder {
123
123
  return;
124
124
  }
125
125
 
126
- const sortField = sort === 'id' ? 'rocrateId' : sort;
127
-
128
- if (sortField === 'name') {
126
+ if (sort === 'name') {
129
127
  return [{ 'name.keyword': order }];
130
128
  }
131
129
 
132
- return [{ [sortField]: order }];
130
+ return [{ [sort]: order }];
133
131
  }
134
132
  }
@@ -1,14 +0,0 @@
1
- -- CreateTable
2
- CREATE TABLE `Entity` (
3
- `id` INTEGER NOT NULL AUTO_INCREMENT,
4
- `rocrateId` VARCHAR(191) NOT NULL,
5
- `name` VARCHAR(191) NOT NULL,
6
- `description` VARCHAR(191) NOT NULL,
7
- `conformsTo` VARCHAR(191) NOT NULL,
8
- `memberOf` VARCHAR(191) NULL,
9
- `root` VARCHAR(191) NULL,
10
- `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
11
- `updatedAt` DATETIME(3) NOT NULL,
12
-
13
- PRIMARY KEY (`id`)
14
- ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
@@ -1,7 +0,0 @@
1
- -- AlterTable
2
- ALTER TABLE `Entity` MODIFY `rocrateId` VARCHAR(2048) NOT NULL,
3
- MODIFY `name` VARCHAR(1024) NOT NULL,
4
- MODIFY `description` TEXT NOT NULL,
5
- MODIFY `conformsTo` VARCHAR(2048) NOT NULL,
6
- MODIFY `memberOf` VARCHAR(2048) NULL,
7
- MODIFY `root` VARCHAR(2048) NULL;
@@ -1,8 +0,0 @@
1
- /*
2
- Warnings:
3
-
4
- - Added the required column `recordType` to the `Entity` table without a default value. This is not possible if the table is not empty.
5
-
6
- */
7
- -- AlterTable
8
- ALTER TABLE `Entity` ADD COLUMN `recordType` JSON NOT NULL;
@@ -1,2 +0,0 @@
1
- -- AlterTable
2
- ALTER TABLE `Entity` ADD COLUMN `rocrate` JSON NULL;
@@ -1,10 +0,0 @@
1
- /*
2
- Warnings:
3
-
4
- - You are about to alter the column `recordType` on the `Entity` table. The data in that column could be lost. The data in that column will be cast from `Json` to `Enum(EnumId(0))`.
5
- - Made the column `rocrate` on table `Entity` required. This step will fail if there are existing NULL values in that column.
6
-
7
- */
8
- -- AlterTable
9
- ALTER TABLE `Entity` MODIFY `recordType` ENUM('RepositoryCollection', 'RepositoryObject') NOT NULL,
10
- MODIFY `rocrate` JSON NOT NULL;
@@ -1,39 +0,0 @@
1
- /*
2
- Phased migration to preserve data while renaming and remapping fields:
3
- 1. Add new columns with defaults
4
- 2. Copy and transform data from old columns to new ones
5
- 3. Drop old columns
6
- 4. Remove defaults from new columns where appropriate
7
- */
8
-
9
- -- Step 1: Add new columns with temporary defaults
10
- ALTER TABLE `Entity`
11
- ADD COLUMN `entityType` ENUM('http://pcdm.org/models#Collection', 'http://pcdm.org/models#Object', 'http://schema.org/MediaObject', 'http://schema.org/Person') NOT NULL DEFAULT 'http://pcdm.org/models#Collection',
12
- ADD COLUMN `rootCollection` VARCHAR(2048) NULL,
13
- ADD COLUMN `metadataLicenseId` VARCHAR(2048) NOT NULL DEFAULT 'FIXME',
14
- ADD COLUMN `contentLicenseId` VARCHAR(2048) NOT NULL DEFAULT 'FIXME';
15
-
16
- -- Step 2: Copy and transform data from old columns
17
- -- Map conformsTo URLs to new entityType enum values
18
- UPDATE `Entity` SET `entityType` =
19
- CASE
20
- WHEN `conformsTo` LIKE '%Collection%' THEN 'http://pcdm.org/models#Collection'
21
- WHEN `conformsTo` LIKE '%Object%' THEN 'http://pcdm.org/models#Object'
22
- WHEN `conformsTo` LIKE '%File%' THEN 'http://schema.org/MediaObject'
23
- ELSE 'http://pcdm.org/models#Person' -- Default fallback
24
- END;
25
-
26
- -- Copy root to rootCollection
27
- UPDATE `Entity` SET `rootCollection` = `root`;
28
-
29
- -- Step 3: Drop old columns
30
- ALTER TABLE `Entity`
31
- DROP COLUMN `conformsTo`,
32
- DROP COLUMN `recordType`,
33
- DROP COLUMN `root`;
34
-
35
- -- Step 4: Remove temporary default from entityType (keep defaults for license fields)
36
- ALTER TABLE `Entity`
37
- ALTER COLUMN `entityType` DROP DEFAULT,
38
- ALTER COLUMN `metadataLicenseId` DROP DEFAULT,
39
- ALTER COLUMN `contentLicenseId` DROP DEFAULT;
@@ -1,8 +0,0 @@
1
- /*
2
- Warnings:
3
-
4
- - You are about to alter the column `entityType` on the `Entity` table. The data in that column could be lost. The data in that column will be cast from `Enum(EnumId(0))` to `VarChar(1024)`.
5
-
6
- */
7
- -- AlterTable
8
- ALTER TABLE `Entity` MODIFY `entityType` VARCHAR(1024) NOT NULL;
@@ -1,2 +0,0 @@
1
- -- AlterTable
2
- ALTER TABLE `Entity` ADD COLUMN `meta` JSON NULL;
@@ -1,17 +0,0 @@
1
- -- CreateTable
2
- CREATE TABLE `File` (
3
- `id` INTEGER NOT NULL AUTO_INCREMENT,
4
- `fileId` VARCHAR(2048) NOT NULL,
5
- `filename` VARCHAR(255) NOT NULL,
6
- `mediaType` VARCHAR(127) NOT NULL,
7
- `size` BIGINT NOT NULL,
8
- `memberOf` VARCHAR(2048) NOT NULL,
9
- `rootCollection` VARCHAR(2048) NOT NULL,
10
- `contentLicenseId` VARCHAR(2048) NOT NULL,
11
- `meta` JSON NULL,
12
- `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
13
- `updatedAt` DATETIME(3) NOT NULL,
14
-
15
- UNIQUE INDEX `File_fileId_key`(`fileId`(768)),
16
- PRIMARY KEY (`id`)
17
- ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
@@ -1,2 +0,0 @@
1
- -- AlterTable
2
- ALTER TABLE `Entity` ADD COLUMN `fileId` VARCHAR(2048) NULL;
@@ -1,8 +0,0 @@
1
- /*
2
- Warnings:
3
-
4
- - You are about to drop the column `rocrate` on the `Entity` table. All the data in the column will be lost.
5
-
6
- */
7
- -- AlterTable
8
- ALTER TABLE `Entity` DROP COLUMN `rocrate`;
@@ -1,3 +0,0 @@
1
- # Please do not edit this file manually
2
- # It should be added in your version-control system (e.g., Git)
3
- provider = "mysql"
@@ -1,17 +0,0 @@
1
- // This is your Prisma schema file,
2
- // learn more about it in the docs: https://pris.ly/d/prisma-schema
3
-
4
- generator client {
5
- provider = "prisma-client"
6
- output = "../src/generated/prisma"
7
- importFileExtension = "js"
8
- }
9
-
10
- generator json {
11
- provider = "prisma-json-types-generator"
12
- }
13
-
14
- datasource db {
15
- provider = "mysql"
16
- url = env("DATABASE_URL")
17
- }