arocapi 5.0.0-beta.4 → 5.0.0-beta.6

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 (160) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +3 -3
  3. package/dist/app.d.ts +19 -13
  4. package/dist/app.js +13 -10
  5. package/dist/app.js.map +1 -1
  6. package/dist/routes/capabilities.d.ts +2 -2
  7. package/dist/routes/capabilities.js +2 -2
  8. package/dist/routes/capabilities.js.map +1 -1
  9. package/dist/routes/entities.js +8 -9
  10. package/dist/routes/entities.js.map +1 -1
  11. package/dist/routes/file.js +5 -1
  12. package/dist/routes/file.js.map +1 -1
  13. package/dist/routes/search.d.ts +2 -4
  14. package/dist/routes/search.js +75 -97
  15. package/dist/routes/search.js.map +1 -1
  16. package/dist/search/advanced.d.ts +8 -0
  17. package/dist/search/advanced.js +198 -0
  18. package/dist/search/advanced.js.map +1 -0
  19. package/dist/search/backend.d.ts +95 -0
  20. package/dist/search/backend.js +5 -0
  21. package/dist/search/backend.js.map +1 -0
  22. package/dist/search/fields.d.ts +63 -0
  23. package/dist/search/fields.js +203 -0
  24. package/dist/search/fields.js.map +1 -0
  25. package/dist/search/opensearch/advanced.d.ts +4 -0
  26. package/dist/search/opensearch/advanced.js +28 -0
  27. package/dist/search/opensearch/advanced.js.map +1 -0
  28. package/dist/search/opensearch/opensearch.d.ts +16 -0
  29. package/dist/search/opensearch/opensearch.js +187 -0
  30. package/dist/search/opensearch/opensearch.js.map +1 -0
  31. package/dist/search/opensearch/visibility.d.ts +3 -0
  32. package/dist/search/opensearch/visibility.js +27 -0
  33. package/dist/search/opensearch/visibility.js.map +1 -0
  34. package/dist/search/postgres/advanced.d.ts +7 -0
  35. package/dist/search/postgres/advanced.js +54 -0
  36. package/dist/search/postgres/advanced.js.map +1 -0
  37. package/dist/search/postgres/facets.d.ts +2 -0
  38. package/dist/search/postgres/facets.js +27 -0
  39. package/dist/search/postgres/facets.js.map +1 -0
  40. package/dist/search/postgres/geo.d.ts +6 -0
  41. package/dist/search/postgres/geo.js +42 -0
  42. package/dist/search/postgres/geo.js.map +1 -0
  43. package/dist/search/postgres/postgres.d.ts +19 -0
  44. package/dist/search/postgres/postgres.js +157 -0
  45. package/dist/search/postgres/postgres.js.map +1 -0
  46. package/dist/search/postgres/values.d.ts +8 -0
  47. package/dist/search/postgres/values.js +20 -0
  48. package/dist/search/postgres/values.js.map +1 -0
  49. package/dist/search/postgres/visibility.d.ts +4 -0
  50. package/dist/search/postgres/visibility.js +38 -0
  51. package/dist/search/postgres/visibility.js.map +1 -0
  52. package/dist/search/requestFilters.d.ts +39 -0
  53. package/dist/search/requestFilters.js +125 -0
  54. package/dist/search/requestFilters.js.map +1 -0
  55. package/dist/search/visibility.d.ts +51 -0
  56. package/dist/search/visibility.js +100 -0
  57. package/dist/search/visibility.js.map +1 -0
  58. package/dist/types/visibility.d.ts +3 -2
  59. package/dist/utils/visibility.js +1 -1
  60. package/dist/utils/visibility.js.map +1 -1
  61. package/package.json +46 -26
  62. package/prisma/models/entity.prisma +9 -8
  63. package/prisma/models/entitySearch.prisma +21 -0
  64. package/prisma/models/file.prisma +3 -3
  65. package/src/app.ts +53 -24
  66. package/src/routes/capabilities.ts +4 -4
  67. package/src/routes/entities.ts +10 -9
  68. package/src/routes/file.ts +5 -1
  69. package/src/routes/search.ts +104 -118
  70. package/src/search/advanced.ts +258 -0
  71. package/src/search/backend.ts +91 -0
  72. package/src/search/fields.ts +320 -0
  73. package/src/search/opensearch/advanced.ts +36 -0
  74. package/src/search/opensearch/opensearch.ts +290 -0
  75. package/src/search/opensearch/visibility.ts +38 -0
  76. package/src/search/postgres/advanced.ts +76 -0
  77. package/src/search/postgres/facets.ts +34 -0
  78. package/src/search/postgres/geo.ts +58 -0
  79. package/src/search/postgres/postgres.ts +232 -0
  80. package/src/search/postgres/values.ts +33 -0
  81. package/src/search/postgres/visibility.ts +54 -0
  82. package/src/search/requestFilters.ts +178 -0
  83. package/src/search/visibility.ts +193 -0
  84. package/src/types/visibility.ts +6 -3
  85. package/src/utils/visibility.ts +1 -1
  86. package/dist/app.test.d.ts +0 -1
  87. package/dist/app.test.js +0 -67
  88. package/dist/app.test.js.map +0 -1
  89. package/dist/errorHandling.test.d.ts +0 -1
  90. package/dist/errorHandling.test.js +0 -222
  91. package/dist/errorHandling.test.js.map +0 -1
  92. package/dist/index.dev.d.ts +0 -1
  93. package/dist/index.dev.js +0 -157
  94. package/dist/index.dev.js.map +0 -1
  95. package/dist/routes/capabilities.test.d.ts +0 -1
  96. package/dist/routes/capabilities.test.js +0 -81
  97. package/dist/routes/capabilities.test.js.map +0 -1
  98. package/dist/routes/crate.test.d.ts +0 -1
  99. package/dist/routes/crate.test.js +0 -390
  100. package/dist/routes/crate.test.js.map +0 -1
  101. package/dist/routes/entities.test.d.ts +0 -1
  102. package/dist/routes/entities.test.js +0 -277
  103. package/dist/routes/entities.test.js.map +0 -1
  104. package/dist/routes/entity.test.d.ts +0 -1
  105. package/dist/routes/entity.test.js +0 -136
  106. package/dist/routes/entity.test.js.map +0 -1
  107. package/dist/routes/file.test.d.ts +0 -1
  108. package/dist/routes/file.test.js +0 -425
  109. package/dist/routes/file.test.js.map +0 -1
  110. package/dist/routes/files.test.d.ts +0 -1
  111. package/dist/routes/files.test.js +0 -245
  112. package/dist/routes/files.test.js.map +0 -1
  113. package/dist/routes/search.test.d.ts +0 -1
  114. package/dist/routes/search.test.js +0 -833
  115. package/dist/routes/search.test.js.map +0 -1
  116. package/dist/test/helpers/fastify.d.ts +0 -9
  117. package/dist/test/helpers/fastify.js +0 -17
  118. package/dist/test/helpers/fastify.js.map +0 -1
  119. package/dist/test/integration.setup.d.ts +0 -47
  120. package/dist/test/integration.setup.js +0 -195
  121. package/dist/test/integration.setup.js.map +0 -1
  122. package/dist/test/integration.test.d.ts +0 -1
  123. package/dist/test/integration.test.js +0 -762
  124. package/dist/test/integration.test.js.map +0 -1
  125. package/dist/transformers/default.test.d.ts +0 -1
  126. package/dist/transformers/default.test.js +0 -225
  127. package/dist/transformers/default.test.js.map +0 -1
  128. package/dist/transformers/transformer.test.d.ts +0 -1
  129. package/dist/transformers/transformer.test.js +0 -165
  130. package/dist/transformers/transformer.test.js.map +0 -1
  131. package/dist/utils/errors.test.d.ts +0 -1
  132. package/dist/utils/errors.test.js +0 -79
  133. package/dist/utils/errors.test.js.map +0 -1
  134. package/dist/utils/queryBuilder.d.ts +0 -47
  135. package/dist/utils/queryBuilder.js +0 -107
  136. package/dist/utils/queryBuilder.js.map +0 -1
  137. package/prisma.config.ts +0 -9
  138. package/src/app.test.ts +0 -91
  139. package/src/errorHandling.test.ts +0 -288
  140. package/src/index.dev.ts +0 -202
  141. package/src/reset.d.ts +0 -1
  142. package/src/routes/__snapshots__/capabilities.test.ts.snap +0 -34
  143. package/src/routes/__snapshots__/entities.test.ts.snap +0 -96
  144. package/src/routes/__snapshots__/entity.test.ts.snap +0 -74
  145. package/src/routes/__snapshots__/search.test.ts.snap +0 -165
  146. package/src/routes/capabilities.test.ts +0 -102
  147. package/src/routes/crate.test.ts +0 -484
  148. package/src/routes/entities.test.ts +0 -324
  149. package/src/routes/entity.test.ts +0 -166
  150. package/src/routes/file.test.ts +0 -526
  151. package/src/routes/files.test.ts +0 -304
  152. package/src/routes/search.test.ts +0 -959
  153. package/src/test/__snapshots__/integration.test.ts.snap +0 -18
  154. package/src/test/helpers/fastify.ts +0 -26
  155. package/src/test/integration.setup.ts +0 -220
  156. package/src/test/integration.test.ts +0 -953
  157. package/src/transformers/default.test.ts +0 -276
  158. package/src/transformers/transformer.test.ts +0 -226
  159. package/src/utils/errors.test.ts +0 -90
  160. package/src/utils/queryBuilder.ts +0 -157
@@ -1,18 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`Integration Tests > GET /entity/:id > should return entity from database 1`] = `
4
- {
5
- "access": {
6
- "content": true,
7
- "metadata": true,
8
- },
9
- "contentLicenseId": "https://creativecommons.org/licenses/by/4.0/",
10
- "description": "First test entity",
11
- "entityType": "http://pcdm.org/models#Collection",
12
- "id": "http://example.com/entity/1",
13
- "memberOf": null,
14
- "metadataLicenseId": "https://creativecommons.org/licenses/by/4.0/",
15
- "name": "Test Collection",
16
- "rootCollection": null,
17
- }
18
- `;
@@ -1,26 +0,0 @@
1
- import type { Client } from '@opensearch-project/opensearch';
2
- import type { FastifyInstance } from 'fastify';
3
- import Fastify from 'fastify';
4
- import { mockDeep, mockReset } from 'vitest-mock-extended';
5
-
6
- import type { PrismaClient } from '../../generated/prisma/client.js';
7
- import { setupValidation } from '../../utils/validation.js';
8
-
9
- export let fastify: FastifyInstance;
10
- export const prisma = mockDeep<PrismaClient>();
11
- export const opensearch = mockDeep<Client>();
12
-
13
- export const fastifyBefore = async () => {
14
- mockReset(prisma);
15
- mockReset(opensearch);
16
-
17
- fastify = Fastify({ logger: false });
18
-
19
- setupValidation(fastify);
20
-
21
- return fastify;
22
- };
23
-
24
- export const fastifyAfter = async () => {
25
- await fastify.close();
26
- };
@@ -1,220 +0,0 @@
1
- import { Client } from '@opensearch-project/opensearch';
2
- import { PrismaMariaDb } from '@prisma/adapter-mariadb';
3
- import type { FastifyInstance } from 'fastify';
4
- import Fastify from 'fastify';
5
- import type { Options } from '../app.js';
6
- import app, { AllPublicAccess, AllVisibleEntityFilter, AllVisibleSearchFilter } from '../app.js';
7
- import { PrismaClient } from '../generated/prisma/client.js';
8
-
9
- let fastify: FastifyInstance;
10
- let prisma: PrismaClient;
11
- let opensearch: Client;
12
-
13
- export const getTestApp = () => fastify;
14
-
15
- export async function setupIntegrationTests() {
16
- process.env.DATABASE_URL = 'mysql://root:password@localhost:3307/catalog_test';
17
- process.env.OPENSEARCH_URL = 'http://localhost:9201';
18
- process.env.NODE_ENV = 'test';
19
-
20
- const adapter = new PrismaMariaDb({
21
- host: 'localhost',
22
- user: 'root',
23
- password: 'password',
24
- database: 'catalog_test',
25
- port: 3307,
26
- connectionLimit: 5,
27
- // 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.
28
- allowPublicKeyRetrieval: true,
29
- });
30
- prisma = new PrismaClient({ adapter });
31
-
32
- opensearch = new Client({
33
- node: process.env.OPENSEARCH_URL,
34
- });
35
-
36
- fastify = await buildTestApp();
37
- }
38
-
39
- export async function buildTestApp(overrides: Partial<Options> = {}) {
40
- const instance = Fastify({ logger: false });
41
-
42
- await instance.register(app, {
43
- prisma,
44
- opensearch,
45
- access: AllPublicAccess,
46
- entityVisibilityFilter: AllVisibleEntityFilter,
47
- searchVisibilityFilter: AllVisibleSearchFilter,
48
- fileHandler: {
49
- get: async () => {
50
- throw new Error('File handler not implemented in integration tests');
51
- },
52
- head: async () => {
53
- throw new Error('File handler not implemented in integration tests');
54
- },
55
- },
56
- roCrateHandler: {
57
- get: async () => {
58
- throw new Error('RO-Crate handler not implemented in integration tests');
59
- },
60
- head: async () => {
61
- throw new Error('RO-Crate head handler not implemented in integration tests');
62
- },
63
- },
64
- ...overrides,
65
- });
66
-
67
- await instance.ready();
68
-
69
- return instance;
70
- }
71
-
72
- export async function teardownIntegrationTests() {
73
- await cleanupTestData();
74
-
75
- await fastify.close();
76
- await prisma.$disconnect();
77
- opensearch.close();
78
- }
79
-
80
- export async function cleanupTestData() {
81
- await prisma.file.deleteMany({});
82
- await prisma.entity.deleteMany({});
83
-
84
- await opensearch.indices.delete({
85
- index: 'entities',
86
- ignore_unavailable: true,
87
- });
88
- }
89
-
90
- export async function seedTestData() {
91
- await cleanupTestData();
92
-
93
- const testEntities = [
94
- {
95
- id: 'http://example.com/entity/1',
96
- name: 'Test Collection',
97
- description: 'First test entity',
98
- entityType: 'http://pcdm.org/models#Collection',
99
- memberOf: null,
100
- rootCollection: null,
101
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
102
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
103
- createdAt: new Date(),
104
- updatedAt: new Date(),
105
- },
106
- {
107
- id: 'http://example.com/entity/2',
108
- name: 'Test Object',
109
- description: 'Second test entity',
110
- entityType: 'http://pcdm.org/models#Object',
111
- memberOf: 'http://example.com/entity/1',
112
- rootCollection: 'http://example.com/entity/1',
113
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
114
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
115
- meta: { draft: true },
116
- createdAt: new Date(),
117
- updatedAt: new Date(),
118
- },
119
- {
120
- id: 'http://example.com/entity/3',
121
- name: 'Test Person',
122
- description: 'Third test entity',
123
- entityType: 'http://schema.org/Person',
124
- memberOf: 'http://example.com/entity/1',
125
- rootCollection: 'http://example.com/entity/1',
126
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
127
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
128
- createdAt: new Date(),
129
- updatedAt: new Date(),
130
- },
131
- {
132
- id: 'http://example.com/entity/4',
133
- name: 'test-audio.wav',
134
- description: 'Test audio file',
135
- entityType: 'http://schema.org/MediaObject',
136
- memberOf: 'http://example.com/entity/2',
137
- rootCollection: 'http://example.com/entity/1',
138
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
139
- contentLicenseId: 'https://example.com/licences/restricted',
140
- createdAt: new Date(),
141
- updatedAt: new Date(),
142
- },
143
- {
144
- id: 'http://example.com/entity/5',
145
- name: 'collection-metadata.csv',
146
- description: 'Collection metadata file',
147
- entityType: 'http://schema.org/MediaObject',
148
- memberOf: 'http://example.com/entity/1',
149
- rootCollection: 'http://example.com/entity/1',
150
- metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
151
- contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
152
- meta: { draft: true },
153
- createdAt: new Date(),
154
- updatedAt: new Date(),
155
- },
156
- ];
157
-
158
- await prisma.entity.createMany({
159
- data: testEntities,
160
- });
161
-
162
- const testFiles = [
163
- {
164
- id: 'http://example.com/entity/4',
165
- filename: 'test-audio.wav',
166
- mediaType: 'audio/wav',
167
- size: BigInt(2048),
168
- meta: {},
169
- createdAt: new Date(),
170
- updatedAt: new Date(),
171
- },
172
- {
173
- id: 'http://example.com/entity/5',
174
- filename: 'collection-metadata.csv',
175
- mediaType: 'text/csv',
176
- size: BigInt(512),
177
- meta: {},
178
- createdAt: new Date(),
179
- updatedAt: new Date(),
180
- },
181
- ];
182
-
183
- await prisma.file.createMany({
184
- data: testFiles,
185
- });
186
-
187
- await opensearch.indices.create({
188
- index: 'entities',
189
- body: {
190
- mappings: {
191
- properties: {
192
- id: { type: 'keyword' },
193
- name: {
194
- type: 'text',
195
- fields: {
196
- keyword: { type: 'keyword' },
197
- },
198
- },
199
- description: { type: 'text' },
200
- entityType: { type: 'keyword' },
201
- memberOf: { type: 'keyword' },
202
- rootCollection: { type: 'keyword' },
203
- location: { type: 'geo_point' },
204
- inLanguage: { type: 'keyword' },
205
- mediaType: { type: 'keyword' },
206
- communicationMode: { type: 'keyword' },
207
- },
208
- },
209
- },
210
- });
211
-
212
- const testDocs = testEntities.flatMap((entity) => [{ index: { _index: 'entities', _id: entity.id } }, entity]);
213
-
214
- await opensearch.bulk({
215
- body: testDocs,
216
- refresh: true,
217
- });
218
-
219
- return testEntities;
220
- }