UNPKG

@atomist/sdm-core

Version:

Atomist Software Delivery Machine - Implementation

97 lines 4.23 kB
"use strict"; /* * Copyright © 2019 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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 }); const automation_client_1 = require("@atomist/automation-client"); const AbstractPreferenceStore_1 = require("./AbstractPreferenceStore"); /** * Factory to create a new GraphQLPreferenceStore instance * @deprecated use TeamConfigurationPreferenceStoreFactory */ // tslint:disable-next-line:deprecation exports.GraphQLPreferenceStoreFactory = ctx => new GraphQLPreferenceStore(ctx); /** * PreferenceStore implementation that stores preferences in the backend GraphQL store. * @deprecated use TeamConfigurationPreferenceStore */ class GraphQLPreferenceStore extends AbstractPreferenceStore_1.AbstractPreferenceStore { constructor(context) { super(context); this.context = context; } doGet(name, namespace) { return __awaiter(this, void 0, void 0, function* () { const key = this.scopeKey(name, namespace); const result = yield this.context.graphClient.query({ name: "SdmPreferenceByKey", variables: { key: [key], }, options: automation_client_1.QueryNoCacheOptions, }); if (!!result.SdmPreference && result.SdmPreference.length === 1) { return { name, namespace, value: result.SdmPreference[0].value, ttl: result.SdmPreference[0].ttl, }; } return undefined; }); } doPut(pref) { const key = this.scopeKey(pref.name, pref.namespace); return this.context.messageClient.send({ key, value: pref.value, ttl: typeof pref.ttl === "number" ? Date.now() + pref.ttl : undefined, }, automation_client_1.addressEvent("SdmPreference")); } doList(namespace) { return __awaiter(this, void 0, void 0, function* () { const result = yield this.context.graphClient.query({ name: "SdmPreferenceByKey", options: automation_client_1.QueryNoCacheOptions, }); if (!!result.SdmPreference) { return result.SdmPreference.filter(p => !namespace || p.key.startsWith(`${namespace}_$_`)).map(p => ({ name: p.key.includes("_$_") ? p.key.split("_$_")[1] : p.key, namespace: p.key.includes("_$_") ? p.key.split("_$_")[0] : undefined, value: p.value, ttl: p.ttl, })); } return []; }); } doDelete(name, namespace) { return __awaiter(this, void 0, void 0, function* () { return this.doPut({ name, namespace, value: undefined, ttl: -100 }); }); } } exports.GraphQLPreferenceStore = GraphQLPreferenceStore; //# sourceMappingURL=GraphQLPreferenceStore.js.map