UNPKG

neogma

Version:

Object-Graph-Mapping neo4j framework, Fully-typed with TypeScript, for easy and flexible node and relationship creation

121 lines 5.22 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.Neogma = void 0; const neo4j_driver = __importStar(require("neo4j-driver")); const NeogmaConnectivityError_1 = require("./Errors/NeogmaConnectivityError"); const QueryBuilder_1 = require("./Queries/QueryBuilder"); const QueryRunner_1 = require("./Queries/QueryRunner"); const Sessions_1 = require("./Sessions/Sessions"); const temp_1 = require("./utils/temp"); const neo4j = neo4j_driver; class Neogma { /** * * @param {ConnectParamsI} params - the connection params * @param {ConnectOptionsI} options - additional options for the QueryRunner */ constructor(params, options) { /** a map between each Model's modelName and the Model itself */ this.modelsByName = {}; this.clearTempDatabase = async (database) => (0, temp_1.clearTempDatabase)(this.driver, database); this.clearAllTempDatabases = async () => (0, temp_1.clearAllTempDatabases)(this.driver); this.clearTempDatabasesOlderThan = async (seconds) => (0, temp_1.clearTempDatabasesOlderThan)(this.driver, seconds); this.verifyConnectivity = async () => { try { await this.driver.verifyConnectivity(); } catch (err) { throw new NeogmaConnectivityError_1.NeogmaConnectivityError(err); } }; this.getSession = (runInSession, callback, /** * Override the configuration of the session. * By default, the "database" param used in the constructor is always passed. */ sessionConfig) => { return (0, Sessions_1.getSession)(runInSession, callback, this.driver, Object.assign({ database: this.database }, sessionConfig)); }; this.getTransaction = (runInTransaction, callback, /** * Override the configuration of the session. * By default, the "database" param used in the constructor is always passed. */ sessionConfig) => { return (0, Sessions_1.getTransaction)(runInTransaction, callback, this.driver, Object.assign({ database: this.database }, sessionConfig)); }; this.getRunnable = (runInExisting, callback, /** * Override the configuration of the session. * By default, the "database" param used in the constructor is always passed. */ sessionConfig) => { return (0, Sessions_1.getRunnable)(runInExisting, callback, this.driver, Object.assign({ database: this.database }, sessionConfig)); }; const { url, username, password } = params; try { this.driver = neo4j.driver(url, neo4j.auth.basic(username, password), options); this.database = params.database; } catch (err) { throw new NeogmaConnectivityError_1.NeogmaConnectivityError(err); } this.queryRunner = new QueryRunner_1.QueryRunner({ driver: this.driver, logger: options === null || options === void 0 ? void 0 : options.logger, sessionParams: { database: this.database, }, }); QueryBuilder_1.QueryBuilder.queryRunner = this.queryRunner; } } exports.Neogma = Neogma; _a = Neogma; /** * * @param {ConnectParamsI} params - the connection params * @param {ConnectOptionsI} options - additional options for the QueryRunner */ Neogma.fromTempDatabase = async (params, options) => { const { url, username, password } = params; const driver = neo4j.driver(url, neo4j.auth.basic(username, password), options); const database = await (0, temp_1.createTempDatabase)(driver); await driver.close(); return new _a(Object.assign(Object.assign({}, params), { database })); }; //# sourceMappingURL=Neogma.js.map