Skip to content

Commit a4691b2

Browse files
committed
feat: use MediaWiki Action API directly
1 parent 61a7781 commit a4691b2

17 files changed

Lines changed: 1076 additions & 1867 deletions

backend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"@elysiajs/eden": "catalog:",
2222
"@elysiajs/swagger": "^1.3.1",
2323
"elysia": "catalog:",
24-
"nodemw": "^0.24.1",
2524
"wikibase-sdk": "^10.2.3"
2625
},
2726
"devDependencies": {

backend/src/api/wikibase/handlers.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { WikibaseService } from '@backend/services/wikibase.service'
12
import type { ItemId, PropertyId } from 'wikibase-sdk'
23

34
// Property handlers
@@ -8,7 +9,7 @@ export const searchProperties = async ({
89
limit = '10',
910
offset = '0',
1011
language = 'en',
11-
dataType,
12+
datatype,
1213
autocomplete = 'true',
1314
},
1415
wikibase,
@@ -19,16 +20,16 @@ export const searchProperties = async ({
1920
limit?: string
2021
offset?: string
2122
language?: string
22-
dataType?: string
23+
datatype?: string
2324
autocomplete?: string
2425
}
25-
wikibase: any
26+
wikibase: WikibaseService
2627
}) => {
2728
const results = await wikibase.searchProperties(instance, q, {
2829
limit: Number(limit),
2930
offset: Number(offset),
3031
language,
31-
dataType,
32+
datatype,
3233
autocomplete: autocomplete === 'true',
3334
})
3435
return { data: results }
@@ -41,7 +42,7 @@ export const getPropertyDetails = async ({
4142
}: {
4243
params: { propertyId: string }
4344
query: { instance?: string }
44-
wikibase: any
45+
wikibase: WikibaseService
4546
}) => {
4647
const property = await wikibase.getProperty(instance, propertyId as PropertyId)
4748
return { data: property }
@@ -67,7 +68,7 @@ export const searchItems = async ({
6768
language?: string
6869
autocomplete?: string
6970
}
70-
wikibase: any
71+
wikibase: WikibaseService
7172
}) => {
7273
const results = await wikibase.searchItems(instance, q, {
7374
limit: Number(limit),
@@ -85,7 +86,7 @@ export const getItemDetails = async ({
8586
}: {
8687
params: { itemId: string }
8788
query: { instance?: string }
88-
wikibase: any
89+
wikibase: WikibaseService
8990
}) => {
9091
const item = await wikibase.getItem(instance, itemId as ItemId)
9192
return { data: item }

backend/src/api/wikibase/instances.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const wikibaseInstanceApi = new Elysia({ prefix: '/api/wikibase' })
5858
// Enhanced response formatting for frontend compatibility
5959
const enhancedResults = {
6060
...results,
61-
results: results.results.map((property: any) => ({
61+
results: results.results.map((property) => ({
6262
...property,
6363
// Add relevance indicators
6464
relevanceScore: property.match?.type === 'label' ? 1.0 : 0.8,
@@ -123,7 +123,7 @@ export const wikibaseInstanceApi = new Elysia({ prefix: '/api/wikibase' })
123123
'/:instanceId/properties/:propertyId',
124124
async ({
125125
params: { instanceId, propertyId },
126-
query: { includeConstraints = false },
126+
query: { includeConstraints = false, language: _language = 'en' },
127127
wikibase,
128128
}) => {
129129
const property = await wikibase.getProperty(instanceId, propertyId)

backend/src/api/wikibase/schemas.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export const PropertyDetailsSchema = t.Object({
2323
modified: t.Optional(t.String()),
2424
type: t.Literal('property'),
2525
datatype: t.String(),
26-
labels: t.Optional(t.Object({})),
27-
descriptions: t.Optional(t.Object({})),
28-
aliases: t.Optional(t.Object({})),
29-
claims: t.Optional(t.Object({})),
26+
labels: t.Optional(t.Record(t.String(), t.String())),
27+
descriptions: t.Optional(t.Record(t.String(), t.String())),
28+
aliases: t.Optional(t.Record(t.String(), t.Array(t.String()))),
29+
claims: t.Optional(t.Record(t.String(), t.Array(t.Any()))),
3030
})
3131

3232
export const ItemSearchResultSchema = t.Object({
@@ -53,11 +53,11 @@ export const ItemDetailsSchema = t.Object({
5353
lastrevid: t.Optional(t.Number()),
5454
modified: t.Optional(t.String()),
5555
type: t.Literal('item'),
56-
labels: t.Optional(t.Object({})),
57-
descriptions: t.Optional(t.Object({})),
58-
aliases: t.Optional(t.Object({})),
59-
claims: t.Optional(t.Object({})),
60-
sitelinks: t.Optional(t.Object({})),
56+
labels: t.Optional(t.Record(t.String(), t.String())),
57+
descriptions: t.Optional(t.Record(t.String(), t.String())),
58+
aliases: t.Optional(t.Record(t.String(), t.Array(t.String()))),
59+
claims: t.Optional(t.Record(t.String(), t.Array(t.Any()))),
60+
sitelinks: t.Optional(t.Record(t.String(), t.Any())),
6161
})
6262

6363
// Response schemas

backend/src/plugins/wikibase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { nodemwWikibaseService } from '@backend/services/nodemw-wikibase.service'
1+
import { wikibaseService } from '@backend/services/wikibase.service'
22
import { Elysia } from 'elysia'
33

44
export const wikibasePlugin = new Elysia({ name: 'wikibase', seed: 'wikibase-plugin' }).decorate(
55
'wikibase',
6-
nodemwWikibaseService,
6+
wikibaseService,
77
)

backend/src/services/__tests__/constraint-validation.service.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import { beforeEach, describe, expect, mock, test } from 'bun:test'
55
const mockConstraints: PropertyConstraint[] = [
66
{
77
type: 'format constraint',
8-
parameters: { pattern: '^[A-Z]{2}$' },
8+
parameters: {
9+
pattern: { type: 'string', value: '^[A-Z]{2}$' } as any,
10+
},
911
description: 'Format constraint for country codes',
1012
violationMessage: 'Value must be a two-letter country code',
1113
},
1214
{
1315
type: 'allowed values constraint',
14-
parameters: { allowedValues: ['Q30', 'Q142', 'Q183'] },
16+
parameters: {
17+
allowedValues: { type: 'wikibase-entityid', value: ['Q30', 'Q142', 'Q183'] } as any,
18+
},
1519
description: 'Allowed values constraint',
1620
violationMessage: 'Value must be one of the allowed values',
1721
},

0 commit comments

Comments
 (0)