@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
148 lines (145 loc) • 4.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PinejsSessionStore = exports.Store = void 0;
const express_session_1 = require("express-session");
Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return express_session_1.Store; } });
const permissions = require("../sbvr-api/permissions");
const sbvr_utils_1 = require("../sbvr-api/sbvr-utils");
const sessionModel = `
Vocabulary: session
Term: session id
Concept Type: Short Text (Type)
Term: data
Concept Type: JSON (Type)
Term: expiry time
Concept type: Date Time (Type)
Term: session
Database ID Field: session id
Reference Scheme: session id
Fact type: session has data
Necessity: Each session has exactly 1 data
Fact type: session has session id
Necessity: Each session has exactly 1 session id
Necessity: Each session id is of exactly 1 session
Fact type: session has expiry time
Necessity: Each session has at most 1 expiry time
`;
class PinejsSessionStore extends express_session_1.Store {
constructor() {
super(...arguments);
this.get = ((sid, callback) => {
sbvr_utils_1.api.session
.get({
resource: 'session',
id: sid,
passthrough: {
req: permissions.rootRead,
},
options: {
$select: 'data',
},
})
.then((session) => {
if (session != null) {
return session.data;
}
})
.asCallback(callback);
});
this.set = ((sid, data, callback) => {
var _a, _b;
const body = {
session_id: sid,
data,
expiry_time: (_b = (_a = data === null || data === void 0 ? void 0 : data.cookie) === null || _a === void 0 ? void 0 : _a.expires) !== null && _b !== void 0 ? _b : null,
};
sbvr_utils_1.api.session
.put({
resource: 'session',
id: sid,
passthrough: {
req: permissions.root,
},
body,
})
.asCallback(callback);
});
this.destroy = ((sid, callback) => {
sbvr_utils_1.api.session
.delete({
resource: 'session',
id: sid,
passthrough: {
req: permissions.root,
},
})
.asCallback(callback);
});
this.all = ((callback) => {
sbvr_utils_1.api.session
.get({
resource: 'session',
passthrough: {
req: permissions.root,
},
options: {
$select: 'session_id',
$filter: {
expiry_time: { $ge: Date.now() },
},
},
})
.then((sessions) => sessions.map((s) => s.session_id))
.asCallback(callback);
});
this.clear = ((callback) => {
sbvr_utils_1.api.session
.delete({
resource: 'session',
passthrough: {
req: permissions.root,
},
})
.asCallback(callback);
});
this.length = ((callback) => {
sbvr_utils_1.api.session
.get({
resource: 'session/$count',
passthrough: {
req: permissions.rootRead,
},
options: {
$select: 'session_id',
$filter: {
expiry_time: {
$ge: Date.now(),
},
},
},
})
.asCallback(callback);
});
}
}
exports.PinejsSessionStore = PinejsSessionStore;
PinejsSessionStore.config = {
models: [
{
modelName: 'session',
modelText: sessionModel,
apiRoot: 'session',
logging: {
default: false,
error: true,
},
migrations: {
'11.0.0-modified-at': `
ALTER TABLE "session"
ADD COLUMN IF NOT EXISTS "modified at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;
`,
},
},
],
};
//# sourceMappingURL=pinejs-session-store.js.map