arocapi 2.0.4 → 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.
- package/README.md +81 -9
- package/dist/app.d.ts +6 -0
- package/dist/app.js +9 -3
- package/dist/app.js.map +1 -1
- package/dist/index.dev.js +11 -1
- package/dist/index.dev.js.map +1 -1
- package/dist/routes/crate.js +5 -18
- package/dist/routes/crate.js.map +1 -1
- package/dist/routes/crate.test.js +20 -22
- package/dist/routes/crate.test.js.map +1 -1
- package/dist/routes/entities.js +12 -10
- package/dist/routes/entities.js.map +1 -1
- package/dist/routes/entities.test.js +18 -18
- package/dist/routes/entities.test.js.map +1 -1
- package/dist/routes/entity.js +3 -4
- package/dist/routes/entity.js.map +1 -1
- package/dist/routes/entity.test.js +11 -16
- package/dist/routes/entity.test.js.map +1 -1
- package/dist/routes/file.js +5 -18
- package/dist/routes/file.js.map +1 -1
- package/dist/routes/file.test.js +18 -22
- package/dist/routes/file.test.js.map +1 -1
- package/dist/routes/files.js +12 -11
- package/dist/routes/files.js.map +1 -1
- package/dist/routes/files.test.js +5 -34
- package/dist/routes/files.test.js.map +1 -1
- package/dist/routes/search.d.ts +3 -0
- package/dist/routes/search.js +22 -128
- package/dist/routes/search.js.map +1 -1
- package/dist/routes/search.test.js +53 -23
- package/dist/routes/search.test.js.map +1 -1
- package/dist/test/integration.setup.d.ts +2 -4
- package/dist/test/integration.setup.js +18 -21
- package/dist/test/integration.setup.js.map +1 -1
- package/dist/transformers/default.d.ts +12 -19
- package/dist/transformers/default.js +5 -18
- package/dist/transformers/default.js.map +1 -1
- package/dist/transformers/default.test.js +6 -15
- package/dist/transformers/default.test.js.map +1 -1
- package/dist/transformers/transformer.test.js +2 -6
- package/dist/transformers/transformer.test.js.map +1 -1
- package/dist/utils/errors.d.ts +7 -1
- package/dist/utils/errors.js +2 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/headers.d.ts +7 -0
- package/dist/utils/headers.js +11 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/queryBuilder.d.ts +35 -0
- package/dist/utils/queryBuilder.js +98 -0
- package/dist/utils/queryBuilder.js.map +1 -0
- package/package.json +27 -23
- package/prisma/models/entity.prisma +17 -13
- package/prisma/models/file.prisma +9 -13
- package/prisma.config.ts +0 -2
- package/src/app.ts +15 -2
- package/src/index.dev.ts +12 -1
- package/src/routes/__snapshots__/search.test.ts.snap +2 -2
- package/src/routes/crate.test.ts +20 -22
- package/src/routes/crate.ts +6 -24
- package/src/routes/entities.test.ts +21 -18
- package/src/routes/entities.ts +12 -12
- package/src/routes/entity.test.ts +13 -16
- package/src/routes/entity.ts +3 -4
- package/src/routes/file.test.ts +18 -22
- package/src/routes/file.ts +6 -24
- package/src/routes/files.test.ts +5 -37
- package/src/routes/files.ts +12 -13
- package/src/routes/search.test.ts +62 -25
- package/src/routes/search.ts +34 -153
- package/src/test/integration.setup.ts +19 -21
- package/src/transformers/default.test.ts +10 -20
- package/src/transformers/default.ts +15 -28
- package/src/transformers/transformer.test.ts +4 -6
- package/src/utils/errors.ts +10 -6
- package/src/utils/headers.ts +16 -0
- package/src/utils/queryBuilder.ts +132 -0
- package/prisma/migrations/20250515034400_entities/migration.sql +0 -14
- package/prisma/migrations/20250515050009_extend_entity_fields/migration.sql +0 -7
- package/prisma/migrations/20250804225438_add_record_type/migration.sql +0 -8
- package/prisma/migrations/20250805040110_add_rocrate_field/migration.sql +0 -2
- package/prisma/migrations/20250827033956_record_type_scalar/migration.sql +0 -10
- package/prisma/migrations/20250923032753_api_refactor/migration.sql +0 -39
- package/prisma/migrations/20250923223119_entity_type_to_string/migration.sql +0 -8
- package/prisma/migrations/20251020140329_add_meta_column/migration.sql +0 -2
- package/prisma/migrations/20251027010713_add_file_table/migration.sql +0 -17
- package/prisma/migrations/20251027221138_add_file_id_to_entity/migration.sql +0 -2
- package/prisma/migrations/20251211025510_remove_rocrate_column/migration.sql +0 -8
- package/prisma/migrations/migration_lock.toml +0 -3
- package/prisma/schema.prisma +0 -17
|
@@ -3,12 +3,10 @@ import { AllPublicAccessTransformer, baseEntityTransformer } from './default.js'
|
|
|
3
3
|
describe('baseEntityTransformer', () => {
|
|
4
4
|
it('should transform entity to standard entity shape', () => {
|
|
5
5
|
const entity = {
|
|
6
|
-
id:
|
|
7
|
-
rocrateId: 'http://example.com/entity/123',
|
|
6
|
+
id: 'http://example.com/entity/123',
|
|
8
7
|
name: 'Test Entity',
|
|
9
8
|
description: 'A test entity description',
|
|
10
9
|
entityType: 'http://pcdm.org/models#Collection',
|
|
11
|
-
fileId: null,
|
|
12
10
|
memberOf: 'http://example.com/parent',
|
|
13
11
|
rootCollection: 'http://example.com/root',
|
|
14
12
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -31,12 +29,10 @@ describe('baseEntityTransformer', () => {
|
|
|
31
29
|
});
|
|
32
30
|
it('should handle null memberOf and rootCollection', () => {
|
|
33
31
|
const entity = {
|
|
34
|
-
id:
|
|
35
|
-
rocrateId: 'http://example.com/collection',
|
|
32
|
+
id: 'http://example.com/collection',
|
|
36
33
|
name: 'Top Collection',
|
|
37
34
|
description: 'A top-level collection',
|
|
38
35
|
entityType: 'http://pcdm.org/models#Collection',
|
|
39
|
-
fileId: null,
|
|
40
36
|
memberOf: null,
|
|
41
37
|
rootCollection: null,
|
|
42
38
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -51,12 +47,10 @@ describe('baseEntityTransformer', () => {
|
|
|
51
47
|
});
|
|
52
48
|
it('should exclude database-specific fields', () => {
|
|
53
49
|
const entity = {
|
|
54
|
-
id:
|
|
55
|
-
rocrateId: 'http://example.com/entity/456',
|
|
50
|
+
id: 'http://example.com/entity/456',
|
|
56
51
|
name: 'Test',
|
|
57
52
|
description: 'Test',
|
|
58
53
|
entityType: 'http://pcdm.org/models#Object',
|
|
59
|
-
fileId: null,
|
|
60
54
|
memberOf: null,
|
|
61
55
|
rootCollection: null,
|
|
62
56
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -81,14 +75,12 @@ describe('baseEntityTransformer', () => {
|
|
|
81
75
|
'contentLicenseId',
|
|
82
76
|
]);
|
|
83
77
|
});
|
|
84
|
-
it('should handle File entity (MediaObject) with
|
|
78
|
+
it('should handle File entity (MediaObject) with file relation', () => {
|
|
85
79
|
const entity = {
|
|
86
|
-
id:
|
|
87
|
-
rocrateId: 'http://example.com/file/audio.wav',
|
|
80
|
+
id: 'http://example.com/file/audio.wav',
|
|
88
81
|
name: 'Audio File',
|
|
89
82
|
description: 'An audio recording',
|
|
90
83
|
entityType: 'http://schema.org/MediaObject',
|
|
91
|
-
fileId: 'http://example.com/files/audio.wav',
|
|
92
84
|
memberOf: 'http://example.com/collection',
|
|
93
85
|
rootCollection: 'http://example.com/collection',
|
|
94
86
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -96,6 +88,7 @@ describe('baseEntityTransformer', () => {
|
|
|
96
88
|
createdAt: new Date(),
|
|
97
89
|
updatedAt: new Date(),
|
|
98
90
|
meta: null,
|
|
91
|
+
file: { id: 'http://example.com/files/audio.wav' },
|
|
99
92
|
};
|
|
100
93
|
const result = baseEntityTransformer(entity);
|
|
101
94
|
expect(result).toEqual({
|
|
@@ -103,13 +96,11 @@ describe('baseEntityTransformer', () => {
|
|
|
103
96
|
name: 'Audio File',
|
|
104
97
|
description: 'An audio recording',
|
|
105
98
|
entityType: 'http://schema.org/MediaObject',
|
|
106
|
-
fileId: 'http://example.com/files/audio.wav',
|
|
107
99
|
memberOf: 'http://example.com/collection',
|
|
108
100
|
rootCollection: 'http://example.com/collection',
|
|
109
101
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
110
102
|
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
111
103
|
});
|
|
112
|
-
expect(result.fileId).toBe('http://example.com/files/audio.wav');
|
|
113
104
|
});
|
|
114
105
|
});
|
|
115
106
|
describe('AllPublicAccessTransformer', () => {
|
|
@@ -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,
|
|
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,GAA8C;YACxD,EAAE,EAAE,+BAA+B;YACnC,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,2BAA2B;YACxC,UAAU,EAAE,mCAAmC;YAC/C,QAAQ,EAAE,2BAA2B;YACrC,cAAc,EAAE,yBAAyB;YACzC,iBAAiB,EAAE,8CAA8C;YACjE,gBAAgB,EAAE,iDAAiD;YACnE,SAAS,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC;YACjC,SAAS,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC;YACjC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;SACvB,CAAC;QAEF,MAAM,MAAM,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAE7C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,EAAE,EAAE,+BAA+B;Y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CAAC,CAAC,CAAC"}
|
|
@@ -25,12 +25,10 @@ describe('Entity Transformers', () => {
|
|
|
25
25
|
describe('baseEntityTransformer', () => {
|
|
26
26
|
it('should transform raw entity to base shape with unresolved references', () => {
|
|
27
27
|
const rawEntity = {
|
|
28
|
-
id:
|
|
29
|
-
rocrateId: 'http://example.com/entity/123',
|
|
28
|
+
id: 'http://example.com/entity/123',
|
|
30
29
|
name: 'Test Entity',
|
|
31
30
|
description: 'A test entity',
|
|
32
31
|
entityType: 'http://schema.org/Person',
|
|
33
|
-
fileId: null,
|
|
34
32
|
memberOf: 'http://example.com/collection',
|
|
35
33
|
rootCollection: 'http://example.com/root',
|
|
36
34
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -139,12 +137,10 @@ describe('Entity Transformers', () => {
|
|
|
139
137
|
});
|
|
140
138
|
it('should demonstrate full pipeline: base -> resolve -> access -> custom', async () => {
|
|
141
139
|
const rawEntity = {
|
|
142
|
-
id:
|
|
143
|
-
rocrateId: 'http://example.com/entity/123',
|
|
140
|
+
id: 'http://example.com/entity/123',
|
|
144
141
|
name: 'Test Entity',
|
|
145
142
|
description: 'A test entity',
|
|
146
143
|
entityType: 'http://schema.org/Person',
|
|
147
|
-
fileId: null,
|
|
148
144
|
memberOf: 'http://example.com/collection',
|
|
149
145
|
rootCollection: 'http://example.com/root',
|
|
150
146
|
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
@@ -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,EAG1B,qBAAqB,GAEtB,MAAM,cAAc,CAAC;AAEtB,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,MAAM,WAAW,GAAuB;QACtC,OAAO,EA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,uBAAuB,EAAE,0BAA0B;iBACpD;gBACD,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -17,7 +17,13 @@ export type StandardErrorResponse = {
|
|
|
17
17
|
details?: ErrorDetails;
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
type ValidationViolation = {
|
|
21
|
+
field: string;
|
|
22
|
+
message: string;
|
|
23
|
+
value?: unknown;
|
|
24
|
+
};
|
|
25
|
+
export declare const createValidationError: (message: string, violations: ValidationViolation[]) => StandardErrorResponse;
|
|
21
26
|
export declare const createNotFoundError: (message: string, entityId?: string) => StandardErrorResponse;
|
|
27
|
+
export declare const createInvalidRequestError: (message: string) => StandardErrorResponse;
|
|
22
28
|
export declare const createInternalError: (message?: string) => StandardErrorResponse;
|
|
23
29
|
export {};
|
package/dist/utils/errors.js
CHANGED
|
@@ -13,8 +13,9 @@ const createErrorResponse = (code, message, details) => ({
|
|
|
13
13
|
details,
|
|
14
14
|
},
|
|
15
15
|
});
|
|
16
|
-
export const createValidationError = (message,
|
|
16
|
+
export const createValidationError = (message, violations) => createErrorResponse(ERROR_CODES.VALIDATION_ERROR, message, { violations });
|
|
17
17
|
export const createNotFoundError = (message, entityId) => createErrorResponse(ERROR_CODES.NOT_FOUND, message, entityId ? { entityId } : undefined);
|
|
18
|
+
export const createInvalidRequestError = (message) => createErrorResponse(ERROR_CODES.INVALID_REQUEST, message);
|
|
18
19
|
export const createInternalError = (message = 'Internal server error') => {
|
|
19
20
|
return createErrorResponse(ERROR_CODES.INTERNAL_ERROR, message);
|
|
20
21
|
};
|
package/dist/utils/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG;I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F,mBAAmB,CAAC,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAO,GAAG,uBAAuB,EAAyB,EAAE;IAC9F,OAAO,mBAAmB,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const setFileHeaders = (reply, metadata) => {
|
|
2
|
+
reply.header('Content-Type', metadata.contentType);
|
|
3
|
+
reply.header('Content-Length', metadata.contentLength.toString());
|
|
4
|
+
if (metadata.etag) {
|
|
5
|
+
reply.header('ETag', metadata.etag);
|
|
6
|
+
}
|
|
7
|
+
if (metadata.lastModified) {
|
|
8
|
+
reply.header('Last-Modified', metadata.lastModified.toUTCString());
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=headers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/utils/headers.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAmB,EACnB,QAA4F,EAC5F,EAAE;IACF,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACnD,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,QAAQ,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;IAElE,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;QAC1B,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SortOrder } from '@opensearch-project/opensearch/api/_types/_common.js';
|
|
2
|
+
import type { Search_RequestBody } from '@opensearch-project/opensearch/api/index.js';
|
|
3
|
+
type Aggregations = Required<Search_RequestBody>['aggs'];
|
|
4
|
+
type BoundingBox = {
|
|
5
|
+
topRight: {
|
|
6
|
+
lat: number;
|
|
7
|
+
lng: number;
|
|
8
|
+
};
|
|
9
|
+
bottomLeft: {
|
|
10
|
+
lat: number;
|
|
11
|
+
lng: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type QueryBuilderOptions = {
|
|
15
|
+
aggregations?: Aggregations;
|
|
16
|
+
};
|
|
17
|
+
export declare class OpensearchQueryBuilder {
|
|
18
|
+
aggregations: Aggregations;
|
|
19
|
+
constructor(opts?: QueryBuilderOptions);
|
|
20
|
+
buildQuery(searchType: string, query: string, filters?: Record<string, string[]>, boundingBox?: BoundingBox): {
|
|
21
|
+
bool: {
|
|
22
|
+
must: import("@opensearch-project/opensearch/api/_types/_common.query_dsl.js").QueryContainer[];
|
|
23
|
+
filter: import("@opensearch-project/opensearch/api/_types/_common.query_dsl.js").QueryContainer[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
buildAggregations(geohashPrecision?: number, boundingBox?: BoundingBox): {
|
|
27
|
+
[x: string]: import("@opensearch-project/opensearch/api/_types/_common.aggregations.js").AggregationContainer;
|
|
28
|
+
};
|
|
29
|
+
buildSort(sort: string, order: SortOrder): {
|
|
30
|
+
'name.keyword': SortOrder;
|
|
31
|
+
}[] | {
|
|
32
|
+
[sort]: SortOrder;
|
|
33
|
+
}[] | undefined;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export class OpensearchQueryBuilder {
|
|
2
|
+
aggregations;
|
|
3
|
+
constructor(opts) {
|
|
4
|
+
this.aggregations =
|
|
5
|
+
opts?.aggregations ||
|
|
6
|
+
Object.fromEntries(['inLanguage', 'mediaType', 'communicationMode', 'entityType'].map((name) => [
|
|
7
|
+
name,
|
|
8
|
+
{ terms: { field: `${name}.keyword`, size: 20 } },
|
|
9
|
+
]));
|
|
10
|
+
}
|
|
11
|
+
buildQuery(searchType, query, filters, boundingBox) {
|
|
12
|
+
const must = [];
|
|
13
|
+
const filter = [];
|
|
14
|
+
if (searchType === 'basic') {
|
|
15
|
+
must.push({
|
|
16
|
+
multi_match: {
|
|
17
|
+
query,
|
|
18
|
+
fields: ['name^2', 'description'],
|
|
19
|
+
type: 'best_fields',
|
|
20
|
+
fuzziness: 'AUTO',
|
|
21
|
+
zero_terms_query: 'all',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
must.push({
|
|
27
|
+
query_string: {
|
|
28
|
+
query,
|
|
29
|
+
fields: ['name^2', 'description'],
|
|
30
|
+
default_operator: 'AND',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (filters) {
|
|
35
|
+
Object.entries(filters).forEach(([field, values]) => {
|
|
36
|
+
filter.push({
|
|
37
|
+
terms: {
|
|
38
|
+
[field]: values,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (boundingBox) {
|
|
44
|
+
filter.push({
|
|
45
|
+
geo_bounding_box: {
|
|
46
|
+
location: {
|
|
47
|
+
top_left: {
|
|
48
|
+
lat: boundingBox.topRight.lat,
|
|
49
|
+
lon: boundingBox.bottomLeft.lng,
|
|
50
|
+
},
|
|
51
|
+
bottom_right: {
|
|
52
|
+
lat: boundingBox.bottomLeft.lat,
|
|
53
|
+
lon: boundingBox.topRight.lng,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
bool: {
|
|
61
|
+
must,
|
|
62
|
+
filter,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
buildAggregations(geohashPrecision, boundingBox) {
|
|
67
|
+
const aggs = { ...this.aggregations };
|
|
68
|
+
if (geohashPrecision && boundingBox) {
|
|
69
|
+
aggs.geohash_grid = {
|
|
70
|
+
geohash_grid: {
|
|
71
|
+
field: 'location',
|
|
72
|
+
precision: geohashPrecision,
|
|
73
|
+
bounds: {
|
|
74
|
+
top_left: {
|
|
75
|
+
lat: boundingBox.topRight.lat,
|
|
76
|
+
lon: boundingBox.bottomLeft.lng,
|
|
77
|
+
},
|
|
78
|
+
bottom_right: {
|
|
79
|
+
lat: boundingBox.bottomLeft.lat,
|
|
80
|
+
lon: boundingBox.topRight.lng,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return aggs;
|
|
87
|
+
}
|
|
88
|
+
buildSort(sort, order) {
|
|
89
|
+
if (sort === 'relevance') {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (sort === 'name') {
|
|
93
|
+
return [{ 'name.keyword': order }];
|
|
94
|
+
}
|
|
95
|
+
return [{ [sort]: order }];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=queryBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryBuilder.js","sourceRoot":"","sources":["../../src/utils/queryBuilder.ts"],"names":[],"mappings":"AAqBA,MAAM,OAAO,sBAAsB;IACjC,YAAY,CAAe;IAE3B,YAAY,IAA0B;QACpC,IAAI,CAAC,YAAY;YACf,IAAI,EAAE,YAAY;gBAClB,MAAM,CAAC,WAAW,CAChB,CAAC,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;oBAC3E,IAAI;oBACJ,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,IAAI,UAAU,EAAE,IAAI,EAAE,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O-Crate API",
|
|
6
6
|
"main": "dist/app.js",
|
|
7
7
|
"exports": {
|
|
@@ -15,37 +15,41 @@
|
|
|
15
15
|
"author": "John Ferlito <johnf@inodes.org>",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@fastify/cors": "^11.
|
|
18
|
+
"@fastify/cors": "^11.2.0",
|
|
19
19
|
"@fastify/sensible": "^6.0.4",
|
|
20
20
|
"@opensearch-project/opensearch": "^3.5.1",
|
|
21
|
-
"@prisma/config": "^
|
|
22
|
-
"dotenv": "^17.
|
|
21
|
+
"@prisma/config": "^7.5.0",
|
|
22
|
+
"dotenv": "^17.3.1",
|
|
23
23
|
"express": "^5.2.1",
|
|
24
|
-
"fastify": "^5.
|
|
24
|
+
"fastify": "^5.8.4",
|
|
25
25
|
"fastify-plugin": "^5.1.0",
|
|
26
26
|
"fastify-type-provider-zod": "^6.1.0",
|
|
27
|
-
"zod": "^4.
|
|
27
|
+
"zod": "^4.3.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@biomejs/biome": "^2.
|
|
31
|
-
"@
|
|
30
|
+
"@biomejs/biome": "^2.4.9",
|
|
31
|
+
"@commitlint/cli": "^20.5.0",
|
|
32
|
+
"@commitlint/config-conventional": "^20.5.0",
|
|
33
|
+
"@prisma/adapter-mariadb": "^7.5.0",
|
|
34
|
+
"@prisma/client": "^7.5.0",
|
|
32
35
|
"@semantic-release/changelog": "^6.0.3",
|
|
33
36
|
"@semantic-release/git": "^10.0.1",
|
|
34
37
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
35
38
|
"@types/express": "^5.0.6",
|
|
36
|
-
"@types/node": "^
|
|
37
|
-
"@vitest/coverage-v8": "^4.
|
|
38
|
-
"@vitest/ui": "^4.
|
|
39
|
+
"@types/node": "^24.12.0",
|
|
40
|
+
"@vitest/coverage-v8": "^4.1.1",
|
|
41
|
+
"@vitest/ui": "^4.1.1",
|
|
39
42
|
"concurrently": "^9.2.1",
|
|
40
|
-
"conventional-changelog-conventionalcommits": "^9.
|
|
43
|
+
"conventional-changelog-conventionalcommits": "^9.3.0",
|
|
41
44
|
"fastify-tsconfig": "^3.0.0",
|
|
42
|
-
"knip": "^
|
|
43
|
-
"
|
|
44
|
-
"prisma
|
|
45
|
-
"
|
|
45
|
+
"knip": "^6.0.5",
|
|
46
|
+
"lefthook": "^2.1.4",
|
|
47
|
+
"prisma": "^7.5.0",
|
|
48
|
+
"prisma-json-types-generator": "^4.1.1",
|
|
49
|
+
"semantic-release": "^25.0.3",
|
|
46
50
|
"tsx": "^4.21.0",
|
|
47
|
-
"typescript": "^
|
|
48
|
-
"vitest": "^4.
|
|
51
|
+
"typescript": "^6.0.2",
|
|
52
|
+
"vitest": "^4.1.1",
|
|
49
53
|
"vitest-mock-extended": "^3.1.0"
|
|
50
54
|
},
|
|
51
55
|
"peerDependencies": {
|
|
@@ -57,13 +61,13 @@
|
|
|
57
61
|
"dist",
|
|
58
62
|
"!dist/generated",
|
|
59
63
|
"README.md",
|
|
60
|
-
"prisma",
|
|
64
|
+
"prisma/models",
|
|
61
65
|
"prisma.config.ts"
|
|
62
66
|
],
|
|
63
67
|
"scripts": {
|
|
64
|
-
"build
|
|
65
|
-
"watch
|
|
66
|
-
"dev": "pnpm run dev:clean && pnpm run build
|
|
68
|
+
"build": "tsc",
|
|
69
|
+
"watch": "tsc -w",
|
|
70
|
+
"dev": "pnpm run dev:clean && pnpm run build && concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"yellow.bold,cyan.bold\" \"pnpm:dev:start\" \"pnpm:watch\" ",
|
|
67
71
|
"dev:start": "node --watch --env-file=.env dist/index.dev.js",
|
|
68
72
|
"dev:clean": "rm -rf dist",
|
|
69
73
|
"dbconsole": "docker compose exec db mysql --password=password catalog",
|
|
@@ -79,7 +83,7 @@
|
|
|
79
83
|
"generate": "npx prisma generate",
|
|
80
84
|
"db:generate": "prisma generate",
|
|
81
85
|
"db:migrate": "prisma migrate deploy",
|
|
82
|
-
"seed": "rm -rf dist && pnpm run build
|
|
86
|
+
"seed": "rm -rf dist && pnpm run build && node --env-file=.env example/data/seed.ts"
|
|
83
87
|
},
|
|
84
88
|
"repository": {
|
|
85
89
|
"type": "git",
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
model Entity {
|
|
2
|
-
id
|
|
2
|
+
id String @id @db.VarChar(768)
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
name String @db.VarChar(512)
|
|
5
|
+
description String @db.Text
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
entityType String @db.VarChar(255)
|
|
8
|
+
memberOf String? @db.VarChar(768)
|
|
9
|
+
rootCollection String? @db.VarChar(768)
|
|
10
|
+
metadataLicenseId String @db.VarChar(255)
|
|
11
|
+
contentLicenseId String @db.VarChar(255)
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
memberOf String? @db.VarChar(2048)
|
|
11
|
-
rootCollection String? @db.VarChar(2048)
|
|
12
|
-
metadataLicenseId String @db.VarChar(2048)
|
|
13
|
-
contentLicenseId String @db.VarChar(2048)
|
|
14
|
-
fileId String? @db.VarChar(2048)
|
|
13
|
+
meta Json?
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
createdAt DateTime @default(now())
|
|
16
|
+
updatedAt DateTime @updatedAt
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
file File?
|
|
19
|
+
|
|
20
|
+
@@index([memberOf])
|
|
21
|
+
@@index([rootCollection])
|
|
22
|
+
@@index([entityType])
|
|
23
|
+
@@map("entity")
|
|
20
24
|
}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
model File {
|
|
2
|
-
id
|
|
2
|
+
id String @id @db.VarChar(768)
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
filename String @db.VarChar(255)
|
|
5
|
+
mediaType String @db.VarChar(127)
|
|
6
|
+
size BigInt
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
mediaType String @db.VarChar(127)
|
|
8
|
-
size BigInt
|
|
8
|
+
meta Json?
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
contentLicenseId String @db.VarChar(2048)
|
|
10
|
+
createdAt DateTime @default(now())
|
|
11
|
+
updatedAt DateTime @updatedAt
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
entity Entity @relation(fields: [id], references: [id])
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
updatedAt DateTime @updatedAt
|
|
18
|
-
|
|
19
|
-
@@unique([fileId])
|
|
15
|
+
@@map("file")
|
|
20
16
|
}
|
package/prisma.config.ts
CHANGED
package/src/app.ts
CHANGED
|
@@ -19,6 +19,8 @@ import type {
|
|
|
19
19
|
FileTransformer,
|
|
20
20
|
} from './types/transformers.js';
|
|
21
21
|
import { createValidationError } from './utils/errors.js';
|
|
22
|
+
import type { QueryBuilderOptions } from './utils/queryBuilder.js';
|
|
23
|
+
import { OpensearchQueryBuilder } from './utils/queryBuilder.js';
|
|
22
24
|
|
|
23
25
|
export type { AuthorisedEntity, AuthorisedFile, StandardEntity, StandardFile } from './transformers/default.js';
|
|
24
26
|
export { AllPublicAccessTransformer, AllPublicFileAccessTransformer } from './transformers/default.js';
|
|
@@ -43,6 +45,8 @@ export type {
|
|
|
43
45
|
FileTransformer,
|
|
44
46
|
TransformerContext,
|
|
45
47
|
} from './types/transformers.js';
|
|
48
|
+
export type { QueryBuilderOptions };
|
|
49
|
+
export { OpensearchQueryBuilder };
|
|
46
50
|
|
|
47
51
|
declare module 'fastify' {
|
|
48
52
|
interface FastifyInstance {
|
|
@@ -57,7 +61,12 @@ const setupValidation = (fastify: FastifyInstance) => {
|
|
|
57
61
|
|
|
58
62
|
fastify.setErrorHandler((error, _req, reply) => {
|
|
59
63
|
if (hasZodFastifySchemaValidationErrors(error)) {
|
|
60
|
-
|
|
64
|
+
const violations = error.validation.map((v) => ({
|
|
65
|
+
field: v.instancePath,
|
|
66
|
+
message: v.message,
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
return reply.code(400).send(createValidationError('The request parameters are invalid', violations));
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
// NOTE: We are exposing the error message here for development purposes.
|
|
@@ -97,6 +106,8 @@ const setupSearch = async (fastify: FastifyInstance, opensearch: Client) => {
|
|
|
97
106
|
export type Options = {
|
|
98
107
|
prisma: PrismaClient;
|
|
99
108
|
opensearch: Client;
|
|
109
|
+
queryBuilderClass?: typeof OpensearchQueryBuilder;
|
|
110
|
+
queryBuilderOptions?: QueryBuilderOptions;
|
|
100
111
|
disableCors?: boolean;
|
|
101
112
|
accessTransformer: AccessTransformer;
|
|
102
113
|
entityTransformers?: EntityTransformer[];
|
|
@@ -109,6 +120,8 @@ const app: FastifyPluginAsync<Options> = async (fastify, options) => {
|
|
|
109
120
|
const {
|
|
110
121
|
prisma,
|
|
111
122
|
opensearch,
|
|
123
|
+
queryBuilderClass,
|
|
124
|
+
queryBuilderOptions,
|
|
112
125
|
disableCors = false,
|
|
113
126
|
accessTransformer,
|
|
114
127
|
entityTransformers,
|
|
@@ -155,7 +168,7 @@ const app: FastifyPluginAsync<Options> = async (fastify, options) => {
|
|
|
155
168
|
fastify.register(files, { fileAccessTransformer, fileTransformers });
|
|
156
169
|
fastify.register(file, { fileHandler });
|
|
157
170
|
fastify.register(crate, { roCrateHandler });
|
|
158
|
-
fastify.register(search, { accessTransformer, entityTransformers });
|
|
171
|
+
fastify.register(search, { accessTransformer, entityTransformers, queryBuilderClass, queryBuilderOptions });
|
|
159
172
|
};
|
|
160
173
|
|
|
161
174
|
export default fp(app);
|
package/src/index.dev.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createReadStream, existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
3
|
import { Client } from '@opensearch-project/opensearch';
|
|
4
|
+
import { PrismaMariaDb } from '@prisma/adapter-mariadb';
|
|
4
5
|
import Fastify from 'fastify';
|
|
5
6
|
|
|
6
7
|
import arocapi, {
|
|
@@ -20,7 +21,17 @@ declare module 'fastify' {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
+
const adapter = new PrismaMariaDb({
|
|
25
|
+
host: 'localhost',
|
|
26
|
+
user: 'root',
|
|
27
|
+
password: 'password',
|
|
28
|
+
database: 'catalog',
|
|
29
|
+
port: 3306,
|
|
30
|
+
connectionLimit: 5,
|
|
31
|
+
// 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.
|
|
32
|
+
allowPublicKeyRetrieval: true,
|
|
33
|
+
});
|
|
34
|
+
const prisma = new PrismaClient({ adapter });
|
|
24
35
|
|
|
25
36
|
if (!process.env.OPENSEARCH_URL) {
|
|
26
37
|
throw new Error('OPENSEARCH_URL environment variable is not set');
|