UNPKG

@resin/pinejs

Version:

Pine.js is a sophisticated rules-driven API engine that enables you to define rules in a structured subset of English. Those rules are used in order for Pine.js to generate a database schema and the associated [OData](http://www.odata.org/) API. This make

138 lines (117 loc) 4.16 kB
// Generated by CoffeeScript 1.12.7 (function() { var PinejsSessionStore, _, expressSession, permissions, sessionAPI, sessionModel, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; _ = require('lodash'); expressSession = require('express-session'); permissions = require('../sbvr-api/permissions'); sessionAPI = null; sessionModel = 'Vocabulary: session\n\nTerm: session id\n Concept Type: Short Text (Type)\nTerm: data\n Concept Type: JSON (Type)\nTerm: expiry time\n Concept type: Date Time (Type)\n\nTerm: session\n Database ID Field: session id\n Reference Scheme: session id\n\nFact type: session has data\n Necessity: Each session has exactly 1 data\nFact type: session has session id\n Necessity: Each session has exactly 1 session id\n Necessity: Each session id is of exactly 1 session\nFact type: session has expiry time\n Necessity: Each session has at most 1 expiry time'; PinejsSessionStore = (function(superClass) { extend(PinejsSessionStore, superClass); function PinejsSessionStore() {} PinejsSessionStore.prototype.get = function(sid, callback) { return sessionAPI.get({ resource: 'session', id: sid, passthrough: { req: permissions.rootRead }, options: { $select: 'data' } }).then(function(session) { return session != null ? session.data : void 0; }).nodeify(callback); }; PinejsSessionStore.prototype.set = function(sid, data, callback) { var body, ref, ref1; body = { session_id: sid, data: data, expiry_time: (ref = data != null ? (ref1 = data.cookie) != null ? ref1.expires : void 0 : void 0) != null ? ref : null }; return sessionAPI.put({ resource: 'session', id: sid, passthrough: { req: permissions.root }, body: body }).nodeify(callback); }; PinejsSessionStore.prototype.destroy = function(sid, callback) { return sessionAPI["delete"]({ resource: 'session', id: sid, passthrough: { req: permissions.root } }).nodeify(callback); }; PinejsSessionStore.prototype.all = function(callback) { return sessionAPI.get({ resource: 'session', passthrough: { req: permissions.root }, options: { $select: 'session_id', $filter: { expiry_time: { $ge: Date.now() } } } }).then(function(sessions) { return _.map(sessions, 'session_id'); }).nodeify(callback); }; PinejsSessionStore.prototype.clear = function(callback) { return sessionAPI["delete"]({ resource: 'session', passthrough: { req: permissions.root } }).nodeify(callback); }; PinejsSessionStore.prototype.length = function(callback) { return sessionAPI.get({ resource: 'session/$count', passthrough: { req: permissions.rootRead }, options: { $select: 'session_id', $filter: { expiry_time: { $ge: Date.now() } } } }).nodeify(callback); }; return PinejsSessionStore; })(expressSession.Store); PinejsSessionStore.config = { models: [ { modelName: 'session', modelText: sessionModel, apiRoot: 'session', logging: { "default": false, error: true }, customServerCode: PinejsSessionStore } ] }; PinejsSessionStore.setup = function(app, sbvrUtils, db, callback) { sessionAPI = sbvrUtils.api.session; return callback(); }; module.exports = PinejsSessionStore; }).call(this); //# sourceMappingURL=pinejs-session-store.js.map