UNPKG

@neurosity/notion

Version:
40 lines (39 loc) 1.91 kB
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()); }); }; import { createNotionOnDevice } from "./NotionOnDevice"; export function createSkill(app) { return { subscribe: (options) => __awaiter(this, void 0, void 0, function* () { const [notion, skill] = yield createNotionOnDevice(Object.assign({}, options)); yield notion .enableLocalMode(true) .catch((error) => console.error(error.message)); const teardown = app(notion, skill); return { unsubscribe: () => __awaiter(this, void 0, void 0, function* () { yield notion.disconnect(); if (teardown && "then" in teardown) { const cleanUp = yield teardown; if (typeof cleanUp === "function") { cleanUp(); } } if (typeof teardown === "function" && "then" in teardown()) { return yield teardown(); } if (typeof teardown === "function") { return teardown(); } return teardown; }) }; }) }; }