UNPKG

@accounts/mikro-orm

Version:
64 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSessionSchema = exports.getSessionCtor = exports.Session = void 0; const core_1 = require("@mikro-orm/core"); class Session { id; createdAt = new Date(); updatedAt = new Date(); user; token; valid; userAgent; ip; extra; constructor({ user, token, valid, userAgent, ip, extra }) { this.user = (0, core_1.ref)(user); this.token = token; this.valid = valid; if (userAgent) { this.userAgent = userAgent; } if (ip) { this.ip = ip; } if (extra) { this.extra = extra; } } } exports.Session = Session; const getSessionCtor = ({ abstract = false, } = {}) => { if (abstract) { Object.defineProperty(Session, 'name', { value: 'AccountsSession' }); } return Session; }; exports.getSessionCtor = getSessionCtor; const getSessionSchema = ({ UserEntity, abstract = false, } = {}) => { if (abstract) { Object.defineProperty(Session, 'name', { value: 'AccountsSession' }); } return new core_1.EntitySchema({ class: Session, abstract, properties: { id: { type: 'number', primary: true }, createdAt: { type: 'Date', onCreate: () => new Date(), nullable: true }, updatedAt: { type: 'Date', onCreate: () => new Date(), onUpdate: () => new Date(), nullable: true, }, user: { kind: 'm:1', ref: true, type: UserEntity?.name ?? 'User' }, token: { type: 'string' }, valid: { type: 'boolean' }, userAgent: { type: 'string', nullable: true }, ip: { type: 'string', nullable: true }, extra: { type: 'json', nullable: true }, }, }); }; exports.getSessionSchema = getSessionSchema; //# sourceMappingURL=Session.js.map