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
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { SortOrder } from '@opensearch-project/opensearch/api/_types/_common.js';
|
|
2
|
+
import type { BoolQuery } from '@opensearch-project/opensearch/api/_types/_common.query_dsl.js';
|
|
3
|
+
import type { Search_RequestBody } from '@opensearch-project/opensearch/api/index.js';
|
|
4
|
+
|
|
5
|
+
type Aggregations = Required<Search_RequestBody>['aggs'];
|
|
6
|
+
|
|
7
|
+
type BoundingBox = {
|
|
8
|
+
topRight: {
|
|
9
|
+
lat: number;
|
|
10
|
+
lng: number;
|
|
11
|
+
};
|
|
12
|
+
bottomLeft: {
|
|
13
|
+
lat: number;
|
|
14
|
+
lng: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type QueryBuilderOptions = {
|
|
19
|
+
aggregations?: Aggregations;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export class OpensearchQueryBuilder {
|
|
23
|
+
aggregations: Aggregations;
|
|
24
|
+
|
|
25
|
+
constructor(opts?: QueryBuilderOptions) {
|
|
26
|
+
this.aggregations =
|
|
27
|
+
opts?.aggregations ||
|
|
28
|
+
Object.fromEntries(
|
|
29
|
+
['inLanguage', 'mediaType', 'communicationMode', 'entityType'].map((name) => [
|
|
30
|
+
name,
|
|
31
|
+
{ terms: { field: `${name}.keyword`, size: 20 } },
|
|
32
|
+
]),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
buildQuery(searchType: string, query: string, filters?: Record<string, string[]>, boundingBox?: BoundingBox) {
|
|
37
|
+
const must: BoolQuery['must'] = [];
|
|
38
|
+
const filter: BoolQuery['filter'] = [];
|
|
39
|
+
|
|
40
|
+
if (searchType === 'basic') {
|
|
41
|
+
must.push({
|
|
42
|
+
multi_match: {
|
|
43
|
+
query,
|
|
44
|
+
fields: ['name^2', 'description'],
|
|
45
|
+
type: 'best_fields',
|
|
46
|
+
fuzziness: 'AUTO',
|
|
47
|
+
zero_terms_query: 'all',
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
must.push({
|
|
52
|
+
query_string: {
|
|
53
|
+
query,
|
|
54
|
+
fields: ['name^2', 'description'],
|
|
55
|
+
default_operator: 'AND',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (filters) {
|
|
61
|
+
Object.entries(filters).forEach(([field, values]) => {
|
|
62
|
+
filter.push({
|
|
63
|
+
terms: {
|
|
64
|
+
[field]: values,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (boundingBox) {
|
|
71
|
+
filter.push({
|
|
72
|
+
geo_bounding_box: {
|
|
73
|
+
location: {
|
|
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
|
+
|
|
87
|
+
return {
|
|
88
|
+
bool: {
|
|
89
|
+
must,
|
|
90
|
+
filter,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
buildAggregations(geohashPrecision?: number, boundingBox?: BoundingBox) {
|
|
96
|
+
const aggs = { ...this.aggregations };
|
|
97
|
+
|
|
98
|
+
// Add geohash aggregation if precision is specified
|
|
99
|
+
if (geohashPrecision && boundingBox) {
|
|
100
|
+
aggs.geohash_grid = {
|
|
101
|
+
geohash_grid: {
|
|
102
|
+
field: 'location',
|
|
103
|
+
precision: geohashPrecision,
|
|
104
|
+
bounds: {
|
|
105
|
+
top_left: {
|
|
106
|
+
lat: boundingBox.topRight.lat,
|
|
107
|
+
lon: boundingBox.bottomLeft.lng,
|
|
108
|
+
},
|
|
109
|
+
bottom_right: {
|
|
110
|
+
lat: boundingBox.bottomLeft.lat,
|
|
111
|
+
lon: boundingBox.topRight.lng,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return aggs;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
buildSort(sort: string, order: SortOrder) {
|
|
122
|
+
if (sort === 'relevance') {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (sort === 'name') {
|
|
127
|
+
return [{ 'name.keyword': order }];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return [{ [sort]: order }];
|
|
131
|
+
}
|
|
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,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,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;
|
package/prisma/schema.prisma
DELETED
|
@@ -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
|
-
}
|