UNPKG

realm-object-server

Version:

Realm Object Server

151 lines 4.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const RealmFactory_1 = require("../RealmFactory"); const realmUtil_1 = require("../shared/realmUtil"); var UserStatus; (function (UserStatus) { UserStatus["active"] = "active"; UserStatus["suspended"] = "suspended"; })(UserStatus = exports.UserStatus || (exports.UserStatus = {})); class UserMetadataRow extends realmUtil_1.BaseRealmClass { toJSON() { return { key: this.key, value: this.value, }; } } UserMetadataRow.schema = { name: "UserMetadataRow", properties: { users: { type: "linkingObjects", objectType: "User", property: "metadata" }, key: { type: "string", optional: false }, value: { type: "string", optional: false } } }; exports.UserMetadataRow = UserMetadataRow; class User extends realmUtil_1.BaseRealmClass { constructor() { super(...arguments); this.created = false; } isEmailConfirmed() { const metadataEntry = this.metadata.find(m => m.key === "isEmailConfirmed"); return (metadataEntry && metadataEntry.value === "true") || false; } toJSON() { return { user_id: this.userId, is_admin: this.isAdmin, accounts: this.accounts.slice().map((a) => a.toJSON()), metadata: this.metadata.slice().map((m) => m.toJSON()), status: this.status || UserStatus.active, }; } static fromJSON(json) { return { userId: json.user_id, isAdmin: json.is_admin, accounts: json.accounts.map(Account.fromJSON), metadata: json.metadata }; } } User.schema = { name: "User", primaryKey: "userId", properties: { userId: { type: "string", optional: false }, isAdmin: { type: "bool", optional: false }, accounts: { type: "list", objectType: "Account" }, metadata: { type: "list", objectType: "UserMetadataRow", default: [], optional: false }, status: { type: "string", optional: true }, } }; exports.User = User; class Account extends realmUtil_1.BaseRealmClass { toJSON() { return { provider: this.provider, provider_id: this.providerId, }; } static fromJSON(json) { return { provider: json.provider, providerId: json.provider_id }; } } Account.schema = { name: "Account", properties: { provider: { type: "string", optional: false, indexed: true }, providerId: { type: "string", optional: false, indexed: true }, users: { type: "linkingObjects", objectType: "User", property: "accounts" } } }; exports.Account = Account; class Permission extends realmUtil_1.BaseRealmClass { } Permission.schema = { name: "Permission", properties: { user: "User", realmFile: "RealmFile", mayRead: { type: "bool", optional: false }, mayWrite: { type: "bool", optional: false }, mayManage: { type: "bool", optional: false }, updatedAt: { type: "date", optional: false }, updatedBy: "User", } }; exports.Permission = Permission; class PermissionOffer_Admin extends realmUtil_1.BaseRealmClass { } PermissionOffer_Admin.schema = { name: "PermissionOffer", primaryKey: "id", properties: { id: "string", user: "User", realmFile: "RealmFile", createdAt: "date", mayRead: "bool", mayWrite: "bool", mayManage: "bool", expiresAt: "date?", acceptedUsers: "User[]" } }; exports.PermissionOffer_Admin = PermissionOffer_Admin; class RealmFile extends realmUtil_1.BaseRealmClass { } RealmFile.schema = { name: "RealmFile", primaryKey: "path", properties: { path: "string", realmType: { type: "string", optional: false }, syncLabel: "string", owner: { type: "User", optional: true }, createdAt: { type: "date", optional: false }, permissions: { type: "linkingObjects", objectType: "Permission", property: "realmFile" }, lastVacuumed: "date?" } }; exports.RealmFile = RealmFile; exports.AdminRealm = { remotePath: "/__admin", localPath: "__admin.realm", syncLabel: "default", schema: [ RealmFactory_1.createRealmSchema(User), RealmFactory_1.createRealmSchema(UserMetadataRow), RealmFactory_1.createRealmSchema(Account), RealmFactory_1.createRealmSchema(Permission), RealmFactory_1.createRealmSchema(RealmFile), RealmFactory_1.createRealmSchema(PermissionOffer_Admin), ], }; //# sourceMappingURL=AdminRealm.js.map