UNPKG

data-api-local-serverless

Version:

Serverless plugin to start an Aurora Serverless Data API emulator for local development.

50 lines 2.29 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()); }); }; const chalk = require("chalk"); const data_api_local_1 = require("data-api-local"); class DataAPILocalServerless { constructor(serverless) { this.serverless = serverless; const startHandler = this.startHandler.bind(this); const endHandler = this.endHandler.bind(this); this.hooks = { 'before:offline:start:init': startHandler, 'before:offline:start:end': endHandler, 'before:migrations:status:init': startHandler, 'after:migrations:status:end': endHandler, 'before:migrations:apply:init': startHandler, 'after:migrations:apply:end': endHandler, 'before:migrations:rollback:init': startHandler, 'after:migrations:rollback:end': endHandler }; } get config() { const custom = this.serverless.service.custom; return Object.assign(Object.assign({}, (custom['data-api-local'] || custom['DataAPILocal'])), { logger: this.log.bind(this) }); } startHandler() { return __awaiter(this, void 0, void 0, function* () { this.log('Starting server...'); this.server = yield data_api_local_1.dataApiLocal(this.config); }); } endHandler() { return __awaiter(this, void 0, void 0, function* () { this.log('Stopping server...'); yield this.server.stop(); }); } log(message) { this.serverless.cli.log(`${chalk.blueBright('Data API Local:')} ${message}`); } } module.exports = DataAPILocalServerless; //# sourceMappingURL=index.js.map