Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEBDEV-7246: Extract item metadata #63

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
23 changes: 1 addition & 22 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { Metadata } from './src/models/metadata';
export { ItemHit } from './src/models/hit-types/item-hit';
export { TextHit } from './src/models/hit-types/text-hit';
export { SearchResult, HitType } from './src/models/hit-types/hit';
Expand All @@ -8,27 +7,7 @@ export {
Bucket,
} from './src/models/aggregation';

export { DateField } from './src/models/metadata-fields/field-types/date';

export { NumberField } from './src/models/metadata-fields/field-types/number';

export { StringField } from './src/models/metadata-fields/field-types/string';

export { BooleanField } from './src/models/metadata-fields/field-types/boolean';

export { ByteField } from './src/models/metadata-fields/field-types/byte';

export { DurationField } from './src/models/metadata-fields/field-types/duration';

export { PageProgressionField } from './src/models/metadata-fields/field-types/page-progression';

export { MediaTypeField } from './src/models/metadata-fields/field-types/mediatype';

export {
MetadataFieldInterface,
MetadataField,
} from './src/models/metadata-fields/metadata-field';

export { SearchMetadata } from './src/models/search-metadata';
export { SearchResponse } from './src/responses/search-response';
export { SearchResponseHeader } from './src/responses/search-response-header';
export { SearchResponseSessionContext } from './src/responses/search-response-session-context';
Expand Down
6,276 changes: 3,981 additions & 2,295 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internetarchive/search-service",
"version": "1.4.1",
"version": "2.0.0",
"description": "A search service for the Internet Archive",
"license": "AGPL-3.0-only",
"main": "dist/index.js",
Expand Down Expand Up @@ -30,13 +30,15 @@
"ghpages:generate": "gh-pages -t -d ghpages -m \"Build for $(git log --pretty=format:\"%h %an %ai %s\" -n1) [skip ci]\""
},
"devDependencies": {
"@internetarchive/field-parsers": "^0.1.4",
"@open-wc/eslint-config": "^4.2.0",
"@open-wc/testing": "^2.0.0",
"@open-wc/testing": "^4.0.0",
"@types/mocha": "^10.0.10",
"@types/node": "13.11.1",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"@web/dev-server": "^0.0.12",
"@web/test-runner": "^0.13.23",
"@web/test-runner": "^0.19.0",
"concurrently": "^5.1.0",
"eslint": "^7.21.0",
"eslint-config-prettier": "^6.11.0",
Expand Down Expand Up @@ -75,7 +77,7 @@
]
},
"dependencies": {
"@internetarchive/field-parsers": "^0.1.4",
"@internetarchive/iaux-item-metadata": "^1.0.0",
"@internetarchive/result-type": "^0.0.1",
"decorator-cache-getter": "^1.0.0",
"typescript-memoize": "^1.1.0"
Expand Down
14 changes: 7 additions & 7 deletions src/models/hit-types/favorited-search-hit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { DateField, StringField } from '@internetarchive/iaux-item-metadata';
import { Memoize } from 'typescript-memoize';
import type { Metadata } from '../metadata';
import { DateField } from '../metadata-fields/field-types/date';
import { StringField } from '../metadata-fields/field-types/string';
import { SearchMetadata } from '../search-metadata';

/**
* A model that describes an item hit from a Metadata Search via the PPS endpoint.
Expand Down Expand Up @@ -31,7 +30,7 @@ export class FavoritedSearchHit {
* _Note_: This is a plain string instead of a `MetadataField` since it's
* the primary key of the item.
*/
get identifier(): typeof Metadata.prototype.identifier {
get identifier(): typeof SearchMetadata.prototype.identifier {
return this.rawMetadata?.fields.query;
}

Expand All @@ -43,7 +42,7 @@ export class FavoritedSearchHit {
}

/** Optional. */
@Memoize() get query(): typeof Metadata.prototype.query {
@Memoize() get query(): typeof SearchMetadata.prototype.query {
return this.rawMetadata?.fields?.query
? new StringField(this.rawMetadata.fields.query)
: undefined;
Expand All @@ -52,7 +51,8 @@ export class FavoritedSearchHit {
/**
* Optional.
*/
@Memoize() get date_favorited(): typeof Metadata.prototype.date_favorited {
@Memoize()
get date_favorited(): typeof SearchMetadata.prototype.date_favorited {
return this.rawMetadata?.fields?.date_favorited
? new DateField(this.rawMetadata.fields.date_favorited)
: undefined;
Expand All @@ -61,7 +61,7 @@ export class FavoritedSearchHit {
/**
* Optional.
*/
@Memoize() get __href__(): typeof Metadata.prototype.__href__ {
@Memoize() get __href__(): typeof SearchMetadata.prototype.__href__ {
return this.rawMetadata?.fields?.__href__
? new StringField(this.rawMetadata.fields.__href__)
: undefined;
Expand Down
70 changes: 37 additions & 33 deletions src/models/hit-types/item-hit.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
BooleanField,
ByteField,
DateField,
MediaTypeField,
NumberField,
StringField,
} from '@internetarchive/iaux-item-metadata';
import { Memoize } from 'typescript-memoize';
import type { Metadata } from '../metadata';
import { BooleanField } from '../metadata-fields/field-types/boolean';
import { ByteField } from '../metadata-fields/field-types/byte';
import { DateField } from '../metadata-fields/field-types/date';
import { MediaTypeField } from '../metadata-fields/field-types/mediatype';
import { NumberField } from '../metadata-fields/field-types/number';
import { StringField } from '../metadata-fields/field-types/string';
import { Review } from '../../responses/page-elements';
import { SearchMetadata } from '../search-metadata';

/**
* A model that describes an item hit from a Metadata Search via the PPS endpoint.
Expand Down Expand Up @@ -36,19 +38,19 @@ export class ItemHit {
* _Note_: This is a plain string instead of a `MetadataField` since it's
* the primary key of the item.
*/
get identifier(): typeof Metadata.prototype.identifier {
get identifier(): typeof SearchMetadata.prototype.identifier {
return this.rawMetadata?.fields?.identifier;
}

/** Optional. */
@Memoize() get addeddate(): typeof Metadata.prototype.addeddate {
@Memoize() get addeddate(): typeof SearchMetadata.prototype.addeddate {
return this.rawMetadata?.fields?.addeddate
? new DateField(this.rawMetadata.fields.addeddate)
: undefined;
}

/** Optional. */
@Memoize() get avg_rating(): typeof Metadata.prototype.avg_rating {
@Memoize() get avg_rating(): typeof SearchMetadata.prototype.avg_rating {
return this.rawMetadata?.fields?.avg_rating != null
? new NumberField(this.rawMetadata.fields.avg_rating)
: undefined;
Expand All @@ -58,7 +60,7 @@ export class ItemHit {
* May be a superset of metadata collection field.
* Multivalued.
*/
@Memoize() get collection(): typeof Metadata.prototype.collection {
@Memoize() get collection(): typeof SearchMetadata.prototype.collection {
return this.rawMetadata?.fields?.collection
? new StringField(this.rawMetadata.fields.collection)
: undefined;
Expand All @@ -78,7 +80,8 @@ export class ItemHit {
* In bytes; computed during document construction, for collection items only.
* Optional.
*/
@Memoize() get collection_size(): typeof Metadata.prototype.collection_size {
@Memoize()
get collection_size(): typeof SearchMetadata.prototype.collection_size {
return this.rawMetadata?.fields?.collection_size != null
? new ByteField(this.rawMetadata.fields.collection_size)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through these, it occurs to me that some of these fields are properties of search documents and not necessarily of actual item metadata. The distinction is probably not super meaningful given the way these are used, but figured it might be worth mentioning in case there's a desire to more clearly document the difference where these properties exist in the new item-metadata repo. (num_favorites is perhaps another example)

: undefined;
Expand All @@ -88,7 +91,7 @@ export class ItemHit {
* Optional.
* Multivalued.
*/
@Memoize() get creator(): typeof Metadata.prototype.creator {
@Memoize() get creator(): typeof SearchMetadata.prototype.creator {
return this.rawMetadata?.fields?.creator
? new StringField(this.rawMetadata.fields.creator)
: undefined;
Expand All @@ -97,14 +100,14 @@ export class ItemHit {
/**
* Optional.
*/
@Memoize() get date(): typeof Metadata.prototype.date {
@Memoize() get date(): typeof SearchMetadata.prototype.date {
return this.rawMetadata?.fields?.date
? new DateField(this.rawMetadata.fields.date)
: undefined;
}

/** Optional. */
@Memoize() get description(): typeof Metadata.prototype.description {
@Memoize() get description(): typeof SearchMetadata.prototype.description {
return this.rawMetadata?.fields?.description
? new StringField(this.rawMetadata.fields.description)
: undefined;
Expand All @@ -114,7 +117,7 @@ export class ItemHit {
* Total views over item lifetime, updated by audit consultation with Views API.
* Optional.
*/
@Memoize() get downloads(): typeof Metadata.prototype.downloads {
@Memoize() get downloads(): typeof SearchMetadata.prototype.downloads {
return this.rawMetadata?.fields?.downloads != null
? new NumberField(this.rawMetadata.fields.downloads)
: undefined;
Expand All @@ -123,7 +126,7 @@ export class ItemHit {
/**
* Computed during document construction.
*/
@Memoize() get files_count(): typeof Metadata.prototype.files_count {
@Memoize() get files_count(): typeof SearchMetadata.prototype.files_count {
return this.rawMetadata?.fields?.files_count != null
? new NumberField(this.rawMetadata.fields.files_count)
: undefined;
Expand Down Expand Up @@ -153,7 +156,7 @@ export class ItemHit {
* Format varies.
* Optional.
*/
@Memoize() get issue(): typeof Metadata.prototype.issue {
@Memoize() get issue(): typeof SearchMetadata.prototype.issue {
return this.rawMetadata?.fields?.issue
? new StringField(this.rawMetadata.fields.issue)
: undefined;
Expand All @@ -163,7 +166,7 @@ export class ItemHit {
* Computed during document construction.
* Optional.
*/
@Memoize() get item_count(): typeof Metadata.prototype.item_count {
@Memoize() get item_count(): typeof SearchMetadata.prototype.item_count {
return this.rawMetadata?.fields?.item_count != null
? new NumberField(this.rawMetadata.fields.item_count)
: undefined;
Expand All @@ -172,7 +175,7 @@ export class ItemHit {
/**
* In bytes; computed during document construction.
*/
@Memoize() get item_size(): typeof Metadata.prototype.item_size {
@Memoize() get item_size(): typeof SearchMetadata.prototype.item_size {
return this.rawMetadata?.fields?.item_size != null
? new ByteField(this.rawMetadata.fields.item_size)
: undefined;
Expand All @@ -182,7 +185,7 @@ export class ItemHit {
* Optional.
* Multivalued.
*/
@Memoize() get language(): typeof Metadata.prototype.language {
@Memoize() get language(): typeof SearchMetadata.prototype.language {
return this.rawMetadata?.fields?.language
? new StringField(this.rawMetadata.fields.language)
: undefined;
Expand Down Expand Up @@ -237,7 +240,7 @@ export class ItemHit {
: undefined;
}

@Memoize() get mediatype(): typeof Metadata.prototype.mediatype {
@Memoize() get mediatype(): typeof SearchMetadata.prototype.mediatype {
return this.rawMetadata?.fields?.mediatype
? new MediaTypeField(this.rawMetadata.fields.mediatype)
: undefined;
Expand All @@ -247,14 +250,14 @@ export class ItemHit {
* Views over a month, updated by audit consultation with Views API.
* Optional.
*/
@Memoize() get month(): typeof Metadata.prototype.month {
@Memoize() get month(): typeof SearchMetadata.prototype.month {
return this.rawMetadata?.fields?.month != null
? new NumberField(this.rawMetadata.fields.month)
: undefined;
}

/** Optional. */
@Memoize() get noindex(): typeof Metadata.prototype.noindex {
@Memoize() get noindex(): typeof SearchMetadata.prototype.noindex {
return this.rawMetadata?.fields?.noindex != null
? new BooleanField(this.rawMetadata.fields.noindex)
: undefined;
Expand All @@ -264,7 +267,8 @@ export class ItemHit {
* Computed during document construction.
* Optional.
*/
@Memoize() get num_favorites(): typeof Metadata.prototype.num_favorites {
@Memoize()
get num_favorites(): typeof SearchMetadata.prototype.num_favorites {
return this.rawMetadata?.fields?.num_favorites != null
? new NumberField(this.rawMetadata.fields.num_favorites)
: undefined;
Expand All @@ -274,21 +278,21 @@ export class ItemHit {
* Computed during document construction.
* Optional.
*/
@Memoize() get num_reviews(): typeof Metadata.prototype.num_reviews {
@Memoize() get num_reviews(): typeof SearchMetadata.prototype.num_reviews {
return this.rawMetadata?.fields?.num_reviews != null
? new NumberField(this.rawMetadata.fields.num_reviews)
: undefined;
}

/** Optional. */
@Memoize() get publicdate(): typeof Metadata.prototype.publicdate {
@Memoize() get publicdate(): typeof SearchMetadata.prototype.publicdate {
return this.rawMetadata?.fields?.publicdate
? new DateField(this.rawMetadata.fields.publicdate)
: undefined;
}

/** Optional. */
@Memoize() get reviewdate(): typeof Metadata.prototype.reviewdate {
@Memoize() get reviewdate(): typeof SearchMetadata.prototype.reviewdate {
return this.rawMetadata?.fields?.reviewdate
? new DateField(this.rawMetadata.fields.reviewdate)
: undefined;
Expand Down Expand Up @@ -320,7 +324,7 @@ export class ItemHit {
* Format varies.
* Optional.
*/
@Memoize() get source(): typeof Metadata.prototype.source {
@Memoize() get source(): typeof SearchMetadata.prototype.source {
return this.rawMetadata?.fields?.source
? new StringField(this.rawMetadata.fields.source)
: undefined;
Expand All @@ -337,21 +341,21 @@ export class ItemHit {
}

/** Optional. */
@Memoize() get title(): typeof Metadata.prototype.title {
@Memoize() get title(): typeof SearchMetadata.prototype.title {
return this.rawMetadata?.fields?.title
? new StringField(this.rawMetadata.fields.title)
: undefined;
}

/** Optional. */
@Memoize() get type(): typeof Metadata.prototype.type {
@Memoize() get type(): typeof SearchMetadata.prototype.type {
return this.rawMetadata?.fields?.type
? new StringField(this.rawMetadata.fields.type)
: undefined;
}

/** Optional. */
@Memoize() get volume(): typeof Metadata.prototype.volume {
@Memoize() get volume(): typeof SearchMetadata.prototype.volume {
return this.rawMetadata?.fields?.volume
? new StringField(this.rawMetadata.fields.volume)
: undefined;
Expand All @@ -361,7 +365,7 @@ export class ItemHit {
* Views over a seven-day period, updated by audit consultation with Views API.
* Optional.
*/
@Memoize() get week(): typeof Metadata.prototype.week {
@Memoize() get week(): typeof SearchMetadata.prototype.week {
return this.rawMetadata?.fields?.week != null
? new NumberField(this.rawMetadata.fields.week)
: undefined;
Expand Down
Loading
Loading