openalex-client
Version:
TypeScript SDK for OpenAlex academic database API
158 lines • 4.44 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorksService = void 0;
const base_1 = require("./base");
class WorksService extends base_1.BaseService {
constructor() {
super(...arguments);
this.endpoint = "works";
}
/**
* Get works cited by a specific work
*/
async getCitedBy(workId, params) {
const cleanId = this.cleanId(workId);
const response = await this.client.get(`/works/${cleanId}/cited-by`, this.buildParams(params));
return response.data;
}
/**
* Get works that cite a specific work
*/
async getCitations(workId, params) {
const cleanId = this.cleanId(workId);
const response = await this.client.get(`/works/${cleanId}/citations`, this.buildParams(params));
return response.data;
}
/**
* Get works related to a specific work
*/
async getRelated(workId, params) {
const cleanId = this.cleanId(workId);
const response = await this.client.get(`/works/${cleanId}/related`, this.buildParams(params));
return response.data;
}
/**
* Search works by DOI
*/
async getByDoi(doi, params) {
// Clean DOI - remove URL prefix if present
const cleanDoi = doi.replace(/^https?:\/\/(www\.)?doi\.org\//, "");
return this.get(`https://doi.org/${cleanDoi}`, params);
}
/**
* Search works by multiple DOIs
*/
async getByDois(dois, params) {
const cleanDois = dois.map((doi) => doi.replace(/^https?:\/\/(www\.)?doi\.org\//, ""));
const filterParams = {
...params,
filter: {
...params?.filter,
doi: cleanDois,
},
};
return this.list(filterParams);
}
/**
* Get works by author
*/
async getByAuthor(authorId, params) {
const cleanId = this.cleanId(authorId);
const filterParams = {
...params,
filter: {
...params?.filter,
"authorships.author.id": cleanId,
},
};
return this.list(filterParams);
}
/**
* Get works by institution
*/
async getByInstitution(institutionId, params) {
const cleanId = this.cleanId(institutionId);
const filterParams = {
...params,
filter: {
...params?.filter,
"authorships.institutions.id": cleanId,
},
};
return this.list(filterParams);
}
/**
* Get works by source (journal/venue)
*/
async getBySource(sourceId, params) {
const cleanId = this.cleanId(sourceId);
const filterParams = {
...params,
filter: {
...params?.filter,
"primary_location.source.id": cleanId,
},
};
return this.list(filterParams);
}
/**
* Get works by concept
*/
async getByConcept(conceptId, params) {
const cleanId = this.cleanId(conceptId);
const filterParams = {
...params,
filter: {
...params?.filter,
"concepts.id": cleanId,
},
};
return this.list(filterParams);
}
/**
* Get open access works
*/
async getOpenAccess(params) {
const filterParams = {
...params,
filter: {
...params?.filter,
"open_access.is_oa": true,
},
};
return this.list(filterParams);
}
/**
* Get works published in a specific year range
*/
async getByYearRange(startYear, endYear, params) {
const filterParams = {
...params,
filter: {
...params?.filter,
publication_year: `${startYear}-${endYear}`,
},
};
return this.list(filterParams);
}
/**
* Get highly cited works (top percentile)
*/
async getHighlyCited(params) {
return this.list({
...params,
sort: "cited_by_count:desc",
});
}
/**
* Get recent works
*/
async getRecent(params) {
return this.list({
...params,
sort: "publication_date:desc",
});
}
}
exports.WorksService = WorksService;
//# sourceMappingURL=works.js.map