New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@internetarchive/search-service

Package Overview
Dependencies
Maintainers
0
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@internetarchive/search-service - npm Package Compare versions

Comparing version 1.4.1-alpha.0 to 1.4.1-alpha.1

11

dist/src/responses/page-elements.d.ts

@@ -10,3 +10,3 @@ import { Aggregation } from '../models/aggregation';

}
export declare type FederatedServiceName = 'item_metadata' | 'fts' | 'tvs' | 'rcs' | 'whisper';
export declare type FederatedServiceName = 'service___fts' | 'service___tvs' | 'service___rcs' | 'service___whisper';
/**

@@ -84,7 +84,6 @@ * Valid page element names recognized & returned by the PPS

forum_posts?: ForumPostsPageElement;
item_metadata?: FederatedPageElement;
fts?: FederatedPageElement;
tvs?: FederatedPageElement;
rcs?: FederatedPageElement;
whisper?: FederatedPageElement;
service___fts?: FederatedPageElement;
service___tvs?: FederatedPageElement;
service___rcs?: FederatedPageElement;
service___whisper?: FederatedPageElement;
}

@@ -91,0 +90,0 @@ /**

@@ -161,2 +161,10 @@ import { Aggregation } from '../models/aggregation';

/**
* Utility method to remove 'service___' from the beginning of federated service names,
* so that output will be cleaner.
*
* @param {FederatedServiceName} service Original service name
* @returns {string} Service name with prefix removed
*/
private removeServicePrefix;
/**
* Returns a correctly-typed search result depending on the schema's hit_type.

@@ -163,0 +171,0 @@ */

@@ -15,3 +15,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

constructor(body, schema) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
this.schema = schema;

@@ -29,18 +29,17 @@ this.schemaHitType = schema === null || schema === void 0 ? void 0 : schema.hit_type;

this.returnedCount = (_e = (_d = body === null || body === void 0 ? void 0 : body.hits) === null || _d === void 0 ? void 0 : _d.returned) !== null && _e !== void 0 ? _e : 0;
// Use hits from federated search metadata if available
if (!(hits === null || hits === void 0 ? void 0 : hits.length) && ((_f = this.pageElements) === null || _f === void 0 ? void 0 : _f.fts)) {
hits = (_h = (_g = this.pageElements.item_metadata) === null || _g === void 0 ? void 0 : _g.hits) === null || _h === void 0 ? void 0 : _h.hits;
this.totalResults = (_l = (_k = (_j = this.pageElements.item_metadata) === null || _j === void 0 ? void 0 : _j.hits) === null || _k === void 0 ? void 0 : _k.total) !== null && _l !== void 0 ? _l : 0;
this.returnedCount = (_p = (_o = (_m = this.pageElements.item_metadata) === null || _m === void 0 ? void 0 : _m.hits) === null || _o === void 0 ? void 0 : _o.returned) !== null && _p !== void 0 ? _p : 0;
// Use total hits from search services if federated search
if (!(hits === null || hits === void 0 ? void 0 : hits.length) && ((_f = this.pageElements) === null || _f === void 0 ? void 0 : _f.service___fts)) {
this.totalResults = 0;
this.returnedCount = 0;
this.handleFederatedPageElements();
}
else if (!(hits === null || hits === void 0 ? void 0 : hits.length) && ((_q = firstPageElement === null || firstPageElement === void 0 ? void 0 : firstPageElement.hits) === null || _q === void 0 ? void 0 : _q.hits)) {
else if (!(hits === null || hits === void 0 ? void 0 : hits.length) && ((_g = firstPageElement === null || firstPageElement === void 0 ? void 0 : firstPageElement.hits) === null || _g === void 0 ? void 0 : _g.hits)) {
hits = firstPageElement.hits.hits;
this.totalResults = (_r = firstPageElement.hits.total) !== null && _r !== void 0 ? _r : 0;
this.returnedCount = (_s = firstPageElement.hits.returned) !== null && _s !== void 0 ? _s : 0;
this.totalResults = (_h = firstPageElement.hits.total) !== null && _h !== void 0 ? _h : 0;
this.returnedCount = (_j = firstPageElement.hits.returned) !== null && _j !== void 0 ? _j : 0;
}
else if ((_t = this.pageElements) === null || _t === void 0 ? void 0 : _t.lending) {
else if ((_k = this.pageElements) === null || _k === void 0 ? void 0 : _k.lending) {
hits = this.handleLendingPageElement();
}
else if ((_u = this.pageElements) === null || _u === void 0 ? void 0 : _u.web_archives) {
else if ((_l = this.pageElements) === null || _l === void 0 ? void 0 : _l.web_archives) {
hits = this.handleWebArchivesPageElement();

@@ -61,9 +60,9 @@ }

if (body === null || body === void 0 ? void 0 : body.collection_titles) {
this.collectionTitles = (_v = body.collection_titles) !== null && _v !== void 0 ? _v : {};
this.collectionTitles = (_m = body.collection_titles) !== null && _m !== void 0 ? _m : {};
}
if (body === null || body === void 0 ? void 0 : body.collection_extra_info) {
this.collectionExtraInfo = (_w = body.collection_extra_info) !== null && _w !== void 0 ? _w : null;
this.collectionExtraInfo = (_o = body.collection_extra_info) !== null && _o !== void 0 ? _o : null;
}
if (body === null || body === void 0 ? void 0 : body.account_extra_info) {
this.accountExtraInfo = (_x = body.account_extra_info) !== null && _x !== void 0 ? _x : null;
this.accountExtraInfo = (_p = body.account_extra_info) !== null && _p !== void 0 ? _p : null;
}

@@ -129,15 +128,17 @@ }

const SEARCH_SERVICES = [
'fts',
'tvs',
'rcs',
'whisper',
'service___fts',
'service___tvs',
'service___rcs',
'service___whisper',
];
for (const service of SEARCH_SERVICES) {
// Add federated results for service
const simpleServiceName = this.removeServicePrefix(service);
// Add service name to federated results section
this.federatedResults
? (this.federatedResults[service] = [])
: (this.federatedResults = { [service]: [] });
: (this.federatedResults = { [simpleServiceName]: [] });
// Add hits to service
const serviceElementHits = (_b = (_a = this.pageElements) === null || _a === void 0 ? void 0 : _a[service]) === null || _b === void 0 ? void 0 : _b.hits;
if (serviceElementHits === null || serviceElementHits === void 0 ? void 0 : serviceElementHits.hits) {
this.federatedResults[service] = this.formatHits(serviceElementHits === null || serviceElementHits === void 0 ? void 0 : serviceElementHits.hits);
this.federatedResults[simpleServiceName] = this.formatHits(serviceElementHits === null || serviceElementHits === void 0 ? void 0 : serviceElementHits.hits);
}

@@ -150,2 +151,12 @@ // Update totals with counts from this service

/**
* Utility method to remove 'service___' from the beginning of federated service names,
* so that output will be cleaner.
*
* @param {FederatedServiceName} service Original service name
* @returns {string} Service name with prefix removed
*/
removeServicePrefix(service) {
return service.split('___')[1];
}
/**
* Returns a correctly-typed search result depending on the schema's hit_type.

@@ -152,0 +163,0 @@ */

@@ -209,20 +209,5 @@ import { expect } from '@open-wc/testing';

page_elements: {
item_metadata: {
service___fts: {
hits: {
total: 2,
returned: 1,
hits: [
{
hit_type: 'text',
fields: {
identifier: 'first_metadata',
mediatype: 'texts',
},
},
],
},
},
fts: {
hits: {
total: 2,
returned: 2,

@@ -247,3 +232,3 @@ hits: [

},
tvs: {
service___tvs: {
hits: {

@@ -265,3 +250,3 @@ total: 1,

},
rcs: {
service___rcs: {
hits: {

@@ -281,5 +266,5 @@ total: 1,

},
whisper: {
service___whisper: {
hits: {
total: 1,
total: 2,
returned: 1,

@@ -487,33 +472,25 @@ hits: [

it('provides access to the hits from federated search', () => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
const details = new SearchResponseDetails(federatedSearchResponseBody, {});
expect((_c = (_b = (_a = details.pageElements) === null || _a === void 0 ? void 0 : _a.item_metadata) === null || _b === void 0 ? void 0 : _b.hits) === null || _c === void 0 ? void 0 : _c.hits).to.exist;
expect((_f = (_e = (_d = details.pageElements) === null || _d === void 0 ? void 0 : _d.fts) === null || _e === void 0 ? void 0 : _e.hits) === null || _f === void 0 ? void 0 : _f.hits).to.exist;
expect((_j = (_h = (_g = details.pageElements) === null || _g === void 0 ? void 0 : _g.tvs) === null || _h === void 0 ? void 0 : _h.hits) === null || _j === void 0 ? void 0 : _j.hits).to.exist;
expect((_m = (_l = (_k = details.pageElements) === null || _k === void 0 ? void 0 : _k.rcs) === null || _l === void 0 ? void 0 : _l.hits) === null || _m === void 0 ? void 0 : _m.hits).to.exist;
expect((_q = (_p = (_o = details.pageElements) === null || _o === void 0 ? void 0 : _o.whisper) === null || _p === void 0 ? void 0 : _p.hits) === null || _q === void 0 ? void 0 : _q.hits).to.exist;
expect((_c = (_b = (_a = details.pageElements) === null || _a === void 0 ? void 0 : _a.service___fts) === null || _b === void 0 ? void 0 : _b.hits) === null || _c === void 0 ? void 0 : _c.hits).to.exist;
expect((_f = (_e = (_d = details.pageElements) === null || _d === void 0 ? void 0 : _d.service___tvs) === null || _e === void 0 ? void 0 : _e.hits) === null || _f === void 0 ? void 0 : _f.hits).to.exist;
expect((_j = (_h = (_g = details.pageElements) === null || _g === void 0 ? void 0 : _g.service___rcs) === null || _h === void 0 ? void 0 : _h.hits) === null || _j === void 0 ? void 0 : _j.hits).to.exist;
expect((_m = (_l = (_k = details.pageElements) === null || _k === void 0 ? void 0 : _k.service___whisper) === null || _l === void 0 ? void 0 : _l.hits) === null || _m === void 0 ? void 0 : _m.hits).to.exist;
});
it('provides access to the hit counts from each federated search service', () => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
const details = new SearchResponseDetails(federatedSearchResponseBody, {});
expect((_c = (_b = (_a = details.pageElements) === null || _a === void 0 ? void 0 : _a.item_metadata) === null || _b === void 0 ? void 0 : _b.hits) === null || _c === void 0 ? void 0 : _c.total).to.equal(2);
expect((_f = (_e = (_d = details.pageElements) === null || _d === void 0 ? void 0 : _d.fts) === null || _e === void 0 ? void 0 : _e.hits) === null || _f === void 0 ? void 0 : _f.total).to.equal(2);
expect((_j = (_h = (_g = details.pageElements) === null || _g === void 0 ? void 0 : _g.tvs) === null || _h === void 0 ? void 0 : _h.hits) === null || _j === void 0 ? void 0 : _j.total).to.equal(1);
expect((_m = (_l = (_k = details.pageElements) === null || _k === void 0 ? void 0 : _k.rcs) === null || _l === void 0 ? void 0 : _l.hits) === null || _m === void 0 ? void 0 : _m.total).to.equal(1);
expect((_q = (_p = (_o = details.pageElements) === null || _o === void 0 ? void 0 : _o.whisper) === null || _p === void 0 ? void 0 : _p.hits) === null || _q === void 0 ? void 0 : _q.total).to.equal(1);
expect((_c = (_b = (_a = details.pageElements) === null || _a === void 0 ? void 0 : _a.service___fts) === null || _b === void 0 ? void 0 : _b.hits) === null || _c === void 0 ? void 0 : _c.total).to.equal(2);
expect((_f = (_e = (_d = details.pageElements) === null || _d === void 0 ? void 0 : _d.service___tvs) === null || _e === void 0 ? void 0 : _e.hits) === null || _f === void 0 ? void 0 : _f.total).to.equal(1);
expect((_j = (_h = (_g = details.pageElements) === null || _g === void 0 ? void 0 : _g.service___rcs) === null || _h === void 0 ? void 0 : _h.hits) === null || _j === void 0 ? void 0 : _j.total).to.equal(1);
expect((_m = (_l = (_k = details.pageElements) === null || _k === void 0 ? void 0 : _k.service___whisper) === null || _l === void 0 ? void 0 : _l.hits) === null || _m === void 0 ? void 0 : _m.total).to.equal(2);
});
it('adds each service result count to total', () => {
const details = new SearchResponseDetails(federatedSearchResponseBody, {});
expect(details.totalResults).to.equal(7);
expect(details.totalResults).to.equal(6);
});
it('adds each service returned count to total', () => {
const details = new SearchResponseDetails(federatedSearchResponseBody, {});
expect(details.returnedCount).to.equal(6);
expect(details.returnedCount).to.equal(5);
});
it('uses the metadata results to populate the main results', () => {
const details = new SearchResponseDetails(federatedSearchResponseBody, {});
expect(details.results[0]).to.exist;
expect(details.results[0].identifier).to.equal('first_metadata');
expect(details.results[0]).to.be.instanceOf(TextHit);
});
it('constructs text hits from federated full-text search', () => {

@@ -520,0 +497,0 @@ var _a;

{
"name": "@internetarchive/search-service",
"version": "1.4.1-alpha.0",
"version": "1.4.1-alpha.1",
"description": "A search service for the Internet Archive",

@@ -5,0 +5,0 @@ "license": "AGPL-3.0-only",

@@ -13,7 +13,6 @@ import { Aggregation } from '../models/aggregation';

export type FederatedServiceName =
| 'item_metadata'
| 'fts'
| 'tvs'
| 'rcs'
| 'whisper';
| 'service___fts'
| 'service___tvs'
| 'service___rcs'
| 'service___whisper';

@@ -123,7 +122,6 @@ /**

forum_posts?: ForumPostsPageElement;
item_metadata?: FederatedPageElement;
fts?: FederatedPageElement;
tvs?: FederatedPageElement;
rcs?: FederatedPageElement;
whisper?: FederatedPageElement;
service___fts?: FederatedPageElement;
service___tvs?: FederatedPageElement;
service___rcs?: FederatedPageElement;
service___whisper?: FederatedPageElement;
}

@@ -130,0 +128,0 @@

@@ -186,9 +186,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

// Use hits from federated search metadata if available
if (!hits?.length && this.pageElements?.fts) {
hits = this.pageElements.item_metadata?.hits?.hits;
// Use total hits from search services if federated search
if (!hits?.length && this.pageElements?.service___fts) {
this.totalResults = 0;
this.returnedCount = 0;
this.totalResults = this.pageElements.item_metadata?.hits?.total ?? 0;
this.returnedCount = this.pageElements.item_metadata?.hits?.returned ?? 0;
this.handleFederatedPageElements();

@@ -307,17 +305,20 @@ } else if (!hits?.length && firstPageElement?.hits?.hits) {

const SEARCH_SERVICES: FederatedServiceName[] = [
'fts',
'tvs',
'rcs',
'whisper',
'service___fts',
'service___tvs',
'service___rcs',
'service___whisper',
];
for (const service of SEARCH_SERVICES) {
// Add federated results for service
const simpleServiceName: string = this.removeServicePrefix(service);
// Add service name to federated results section
this.federatedResults
? (this.federatedResults[service] = [])
: (this.federatedResults = { [service]: [] });
: (this.federatedResults = { [simpleServiceName]: [] });
// Add hits to service
const serviceElementHits = this.pageElements?.[service]?.hits;
if (serviceElementHits?.hits) {
this.federatedResults[service] = this.formatHits(
this.federatedResults[simpleServiceName] = this.formatHits(
serviceElementHits?.hits

@@ -334,2 +335,13 @@ );

/**
* Utility method to remove 'service___' from the beginning of federated service names,
* so that output will be cleaner.
*
* @param {FederatedServiceName} service Original service name
* @returns {string} Service name with prefix removed
*/
private removeServicePrefix(service: FederatedServiceName): string {
return service.split('___')[1];
}
/**
* Returns a correctly-typed search result depending on the schema's hit_type.

@@ -336,0 +348,0 @@ */

@@ -225,20 +225,5 @@ import { expect } from '@open-wc/testing';

page_elements: {
item_metadata: {
service___fts: {
hits: {
total: 2,
returned: 1,
hits: [
{
hit_type: 'text',
fields: {
identifier: 'first_metadata',
mediatype: 'texts',
},
},
],
},
},
fts: {
hits: {
total: 2,
returned: 2,

@@ -263,3 +248,3 @@ hits: [

},
tvs: {
service___tvs: {
hits: {

@@ -281,3 +266,3 @@ total: 1,

},
rcs: {
service___rcs: {
hits: {

@@ -297,5 +282,5 @@ total: 1,

},
whisper: {
service___whisper: {
hits: {
total: 1,
total: 2,
returned: 1,

@@ -576,7 +561,6 @@ hits: [

expect(details.pageElements?.item_metadata?.hits?.hits).to.exist;
expect(details.pageElements?.fts?.hits?.hits).to.exist;
expect(details.pageElements?.tvs?.hits?.hits).to.exist;
expect(details.pageElements?.rcs?.hits?.hits).to.exist;
expect(details.pageElements?.whisper?.hits?.hits).to.exist;
expect(details.pageElements?.service___fts?.hits?.hits).to.exist;
expect(details.pageElements?.service___tvs?.hits?.hits).to.exist;
expect(details.pageElements?.service___rcs?.hits?.hits).to.exist;
expect(details.pageElements?.service___whisper?.hits?.hits).to.exist;
});

@@ -590,7 +574,6 @@

expect(details.pageElements?.item_metadata?.hits?.total).to.equal(2);
expect(details.pageElements?.fts?.hits?.total).to.equal(2);
expect(details.pageElements?.tvs?.hits?.total).to.equal(1);
expect(details.pageElements?.rcs?.hits?.total).to.equal(1);
expect(details.pageElements?.whisper?.hits?.total).to.equal(1);
expect(details.pageElements?.service___fts?.hits?.total).to.equal(2);
expect(details.pageElements?.service___tvs?.hits?.total).to.equal(1);
expect(details.pageElements?.service___rcs?.hits?.total).to.equal(1);
expect(details.pageElements?.service___whisper?.hits?.total).to.equal(2);
});

@@ -604,3 +587,3 @@

expect(details.totalResults).to.equal(7);
expect(details.totalResults).to.equal(6);
});

@@ -614,16 +597,5 @@

expect(details.returnedCount).to.equal(6);
expect(details.returnedCount).to.equal(5);
});
it('uses the metadata results to populate the main results', () => {
const details = new SearchResponseDetails(
federatedSearchResponseBody,
{} as SearchHitSchema
);
expect(details.results[0]).to.exist;
expect(details.results[0].identifier).to.equal('first_metadata');
expect(details.results[0]).to.be.instanceOf(TextHit);
});
it('constructs text hits from federated full-text search', () => {

@@ -630,0 +602,0 @@ const details = new SearchResponseDetails(

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc