UNPKG

@commitspark/graphql-api

Version:

GraphQL API to store and manage structured data with Git

63 lines 2.98 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTypeById = getTypeById; exports.findById = findById; exports.findByType = findByType; exports.findByTypeId = findByTypeId; const errors_1 = require("../graphql/errors"); function getTypeById(gitAdapter, commitHash, id) { return __awaiter(this, void 0, void 0, function* () { const allEntries = yield gitAdapter.getEntries(commitHash); const requestedEntry = allEntries.find((entry) => entry.id === id); if (requestedEntry === undefined) { throw (0, errors_1.createError)(`No entry with id "${id}" exists.`, errors_1.ErrorCode.NOT_FOUND, { argumentName: 'id', argumentValue: id, }); } return requestedEntry.metadata.type; }); } function findById(gitAdapter, commitHash, id) { return __awaiter(this, void 0, void 0, function* () { const allEntries = yield gitAdapter.getEntries(commitHash); const requestedEntry = allEntries.find((entry) => entry.id === id); if (requestedEntry === undefined) { throw (0, errors_1.createError)(`No entry with id "${id}" exists.`, errors_1.ErrorCode.NOT_FOUND, { argumentName: 'id', argumentValue: id, }); } return requestedEntry; }); } function findByType(gitAdapter, commitHash, type) { return __awaiter(this, void 0, void 0, function* () { const allEntries = yield gitAdapter.getEntries(commitHash); return allEntries.filter((entry) => entry.metadata.type === type); }); } function findByTypeId(gitAdapter, commitHash, type, id) { return __awaiter(this, void 0, void 0, function* () { const allEntries = yield gitAdapter.getEntries(commitHash); const requestedEntry = allEntries.find((entry) => entry.id === id && entry.metadata.type === type); if (requestedEntry === undefined) { throw (0, errors_1.createError)(`No entry of type "${type}" with id "${id}" exists.`, errors_1.ErrorCode.NOT_FOUND, { typeName: type, argumentName: 'id', argumentValue: id, }); } return requestedEntry; }); } //# sourceMappingURL=persistence.js.map