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
13
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 0.1.0 to 0.1.1-alpha.1

3

dist/src/responses/result.d.ts

@@ -14,6 +14,5 @@ /**

*/
export declare class Result<T, E extends Error> {
export interface Result<T, E extends Error> {
success?: T;
error?: E;
constructor(success?: T, error?: E);
}

@@ -1,20 +0,2 @@

/**
* The Result is a container for a response.
*
* It contains an optional success result which is generic
* and can be anything depending on the context,
* or an Error or subclass of an error.
*
* This allows us to return rich, typed errors instead of
* an untyped Promise rejection.
*
* This is modeled after Swift's Result type:
* https://developer.apple.com/documentation/swift/result
*/
export class Result {
constructor(success, error) {
this.success = success;
this.error = error;
}
}
export {};
//# sourceMappingURL=result.js.map
import { SearchBackendInterface } from './search-backend-interface';
import { SearchParams } from '../search-params';
import { Result } from '../responses/result';
import { Result } from '@internetarchive/result-type';
import { SearchServiceError } from '../search-service-error';

@@ -5,0 +5,0 @@ /**

@@ -1,2 +0,1 @@

import { Result } from '../responses/result';
import { SearchServiceError, SearchServiceErrorType, } from '../search-service-error';

@@ -42,3 +41,3 @@ /**

// success
return new Result(json, undefined);
return { success: json };
}

@@ -53,3 +52,3 @@ }

const error = new SearchServiceError(errorType, message, details);
const result = new Result(undefined, error);
const result = { error };
return result;

@@ -56,0 +55,0 @@ }

@@ -1,2 +0,2 @@

import { Result } from '../responses/result';
import { Result } from '@internetarchive/result-type';
import { SearchParams } from '../search-params';

@@ -3,0 +3,0 @@ import { SearchServiceError } from '../search-service-error';

export declare enum SearchServiceErrorType {
networkError = 0,
itemNotFound = 1,
decodingError = 2,
searchEngineError = 3
networkError = "SearchService.NetworkError",
itemNotFound = "SearchService.ItemNotFound",
decodingError = "SearchService.DecodingError",
searchEngineError = "SearchService.SearchEngineError"
}

@@ -7,0 +7,0 @@ export declare class SearchServiceError extends Error {

@@ -5,6 +5,6 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */

(function (SearchServiceErrorType) {
SearchServiceErrorType[SearchServiceErrorType["networkError"] = 0] = "networkError";
SearchServiceErrorType[SearchServiceErrorType["itemNotFound"] = 1] = "itemNotFound";
SearchServiceErrorType[SearchServiceErrorType["decodingError"] = 2] = "decodingError";
SearchServiceErrorType[SearchServiceErrorType["searchEngineError"] = 3] = "searchEngineError";
SearchServiceErrorType["networkError"] = "SearchService.NetworkError";
SearchServiceErrorType["itemNotFound"] = "SearchService.ItemNotFound";
SearchServiceErrorType["decodingError"] = "SearchService.DecodingError";
SearchServiceErrorType["searchEngineError"] = "SearchService.SearchEngineError";
})(SearchServiceErrorType || (SearchServiceErrorType = {}));

@@ -14,2 +14,3 @@ export class SearchServiceError extends Error {

super(message);
this.name = type;
this.type = type;

@@ -16,0 +17,0 @@ this.details = details;

import { MetadataResponse } from './responses/metadata/metadata-response';
import { Result } from './responses/result';
import { Result } from '@internetarchive/result-type';
import { SearchResponse } from './responses/search/search-response';

@@ -4,0 +4,0 @@ import { SearchParams } from './search-params';

import { SearchResponse } from './responses/search/search-response';
import { SearchParams } from './search-params';
import { MetadataResponse } from './responses/metadata/metadata-response';
import { Result } from './responses/result';
import { SearchServiceError } from './search-service-error';
import { SearchServiceInterface } from './search-service-interface';
import { SearchBackendInterface } from './search-backend/search-backend-interface';
import { Result } from '@internetarchive/result-type';
/**

@@ -9,0 +9,0 @@ * The Search Service is responsible for taking the raw response provided by

import { SearchResponse } from './responses/search/search-response';
import { MetadataResponse } from './responses/metadata/metadata-response';
import { DefaultSearchBackend } from './search-backend/default-search-backend';
import { Result } from './responses/result';
import { SearchServiceError, SearchServiceErrorType, } from './search-service-error';

@@ -22,3 +21,3 @@ /**

const modeledResponse = new SearchResponse(rawResponse.success);
return new Result(modeledResponse);
return { success: modeledResponse };
}

@@ -33,6 +32,8 @@ /** @inheritdoc */

if (((_a = rawResponse.success) === null || _a === void 0 ? void 0 : _a.metadata) === undefined) {
return new Result(undefined, new SearchServiceError(SearchServiceErrorType.itemNotFound));
return {
error: new SearchServiceError(SearchServiceErrorType.itemNotFound),
};
}
const modeledResponse = new MetadataResponse(rawResponse.success);
return new Result(modeledResponse);
return { success: modeledResponse };
}

@@ -39,0 +40,0 @@ }

@@ -7,3 +7,2 @@ /* eslint-disable @typescript-eslint/no-unused-vars */

import { MockResponseGenerator } from './mock-response-generator';
import { Result } from '../src/responses/result';
import { SearchServiceError, SearchServiceErrorType, } from '../src/search-service-error';

@@ -20,3 +19,3 @@ describe('SearchService', () => {

const mockResponse = responseGenerator.generateMockSearchResponse(params);
return new Result(mockResponse);
return { success: mockResponse };
}

@@ -40,3 +39,3 @@ }

const mockResponse = responseGenerator.generateMockMetadataResponse(identifier);
return new Result(mockResponse);
return { success: mockResponse };
}

@@ -58,3 +57,3 @@ }

// we get an empty JSON object when an item is not found
return new Result({});
return { success: {} };
}

@@ -73,7 +72,7 @@ }

const error = new SearchServiceError(SearchServiceErrorType.networkError, 'network error');
return new Result(undefined, error);
return { error };
}
async fetchMetadata(identifier) {
const error = new SearchServiceError(SearchServiceErrorType.networkError, 'network error');
return new Result(undefined, error);
return { error };
}

@@ -98,7 +97,7 @@ }

const error = new SearchServiceError(SearchServiceErrorType.decodingError, 'decoding error');
return new Result(undefined, error);
return { error };
}
async fetchMetadata(identifier) {
const error = new SearchServiceError(SearchServiceErrorType.decodingError, 'decoding error');
return new Result(undefined, error);
return { error };
}

@@ -105,0 +104,0 @@ }

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

@@ -70,3 +70,6 @@ "license": "AGPL-3.0-only",

]
},
"dependencies": {
"@internetarchive/result-type": "^0.0.1-alpha.1"
}
}
/* eslint-disable @typescript-eslint/no-explicit-any */
import { SearchBackendInterface } from './search-backend-interface';
import { SearchParams } from '../search-params';
import { Result } from '../responses/result';
import { Result } from '@internetarchive/result-type';
import {

@@ -63,3 +63,3 @@ SearchServiceError,

// success
return new Result<any, SearchServiceError>(json, undefined);
return { success: json };
}

@@ -78,5 +78,5 @@ } catch (err) {

const error = new SearchServiceError(errorType, message, details);
const result = new Result<any, SearchServiceError>(undefined, error);
const result = { error };
return result;
}
}
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Result } from '../responses/result';
import { Result } from '@internetarchive/result-type';
import { SearchParams } from '../search-params';

@@ -4,0 +4,0 @@ import { SearchServiceError } from '../search-service-error';

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
export enum SearchServiceErrorType {
networkError,
itemNotFound,
decodingError,
searchEngineError,
networkError = 'SearchService.NetworkError',
itemNotFound = 'SearchService.ItemNotFound',
decodingError = 'SearchService.DecodingError',
searchEngineError = 'SearchService.SearchEngineError',
}

@@ -17,2 +17,3 @@

super(message);
this.name = type;
this.type = type;

@@ -19,0 +20,0 @@ this.details = details;

import { MetadataResponse } from './responses/metadata/metadata-response';
import { Result } from './responses/result';
import { Result } from '@internetarchive/result-type';
import { SearchResponse } from './responses/search/search-response';

@@ -4,0 +4,0 @@ import { SearchParams } from './search-params';

@@ -5,3 +5,2 @@ import { SearchResponse } from './responses/search/search-response';

import { DefaultSearchBackend } from './search-backend/default-search-backend';
import { Result } from './responses/result';
import {

@@ -13,2 +12,3 @@ SearchServiceError,

import { SearchBackendInterface } from './search-backend/search-backend-interface';
import { Result } from '@internetarchive/result-type';

@@ -41,3 +41,3 @@ /**

const modeledResponse = new SearchResponse(rawResponse.success);
return new Result<SearchResponse, SearchServiceError>(modeledResponse);
return { success: modeledResponse };
}

@@ -55,11 +55,10 @@

if (rawResponse.success?.metadata === undefined) {
return new Result<MetadataResponse, SearchServiceError>(
undefined,
new SearchServiceError(SearchServiceErrorType.itemNotFound)
);
return {
error: new SearchServiceError(SearchServiceErrorType.itemNotFound),
};
}
const modeledResponse = new MetadataResponse(rawResponse.success);
return new Result<MetadataResponse, SearchServiceError>(modeledResponse);
return { success: modeledResponse };
}
}

@@ -11,3 +11,3 @@ /* eslint-disable @typescript-eslint/no-unused-vars */

import { MetadataResponse } from '../src/responses/metadata/metadata-response';
import { Result } from '../src/responses/result';
import { Result } from '@internetarchive/result-type';
import {

@@ -35,3 +35,3 @@ SearchServiceError,

);
return new Result<SearchResponse, SearchServiceError>(mockResponse);
return { success: mockResponse };
}

@@ -62,3 +62,3 @@ }

);
return new Result<MetadataResponse, SearchServiceError>(mockResponse);
return { success: mockResponse };
}

@@ -85,3 +85,3 @@ }

// we get an empty JSON object when an item is not found
return new Result<MetadataResponse, SearchServiceError>({} as any);
return { success: {} as any };
}

@@ -106,3 +106,3 @@ }

);
return new Result<SearchResponse, SearchServiceError>(undefined, error);
return { error };
}

@@ -116,6 +116,3 @@ async fetchMetadata(

);
return new Result<MetadataResponse, SearchServiceError>(
undefined,
error
);
return { error };
}

@@ -151,3 +148,3 @@ }

);
return new Result<SearchResponse, SearchServiceError>(undefined, error);
return { error };
}

@@ -161,6 +158,3 @@ async fetchMetadata(

);
return new Result<MetadataResponse, SearchServiceError>(
undefined,
error
);
return { error };
}

@@ -167,0 +161,0 @@ }

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

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