diff --git a/lib/extensions.js b/lib/extensions.js index 5c793e34..033d305c 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -167,6 +167,68 @@ module.exports = function(realmConstructor) { Complete: 1, // The subscription has been processed by the sync server and data is being synced to the device. Invalidated: 3, // The subscription has been removed. }; + + // Define the permission schemas as constructors so that they can be + // passed into directly to functions which want object type names + const permissionsSchema = Object.freeze({ + Class: function() {}, + Permission: function() {}, + Realm: function() {}, + Role: function() {}, + User: function() {}, + }); + permissionsSchema.Permission.schema = Object.freeze({ + name: '__Permission', + properties: { + role: '__Role', + canRead: {type: 'bool', default: false}, + canUpdate: {type: 'bool', default: false}, + canDelete: {type: 'bool', default: false}, + canSetPermissions: {type: 'bool', default: false}, + canQuery: {type: 'bool', default: false}, + canCreate: {type: 'bool', default: false}, + canModifySchema: {type: 'bool', default: false}, + } + }); + + permissionsSchema.User.schema = Object.freeze({ + name: '__User', + primaryKey: 'id', + properties: { + id: 'string' + } + }); + + permissionsSchema.Role.schema = Object.freeze({ + name: '__Role', + primaryKey: 'name', + properties: { + name: 'string', + members: '__User[]' + } + }); + + permissionsSchema.Class.schema = Object.freeze({ + name: '__Class', + primaryKey: 'class_name', + properties: { + class_name: 'string', + permissions: '__Permission[]' + } + }); + + permissionsSchema.Realm.schema = Object.freeze({ + name: '__Realm', + primaryKey: 'id', + properties: { + id: 'int', + permissions: '__Permission[]' + } + }); + Object.defineProperty(realmConstructor, 'Permissions', { + value: permissionsSchema, + configurable: false + }); } // TODO: Remove this now useless object. diff --git a/lib/index.d.ts b/lib/index.d.ts index 76cd5432..490b43fa 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -622,6 +622,33 @@ declare class Realm { compact(): boolean; } +declare namespace Realm.Permissions { + interface Permission { + identity: string; + canRead: boolean; + canUpdate: boolean; + canDelete: boolean; + canSetPermissions: boolean; + canQuery: boolean; + canCreate: boolean; + canModifySchema: boolean; + } + interface User { + identity: string; + } + interface Role { + name: string; + members: User[]; + } + interface Class { + class_name: string; + permissions: Permission[]; + } + interface Realm { + permissions: Permission[]; + } +} + declare module 'realm' { export = Realm } diff --git a/src/object-store b/src/object-store index bb559df9..39c133a9 160000 --- a/src/object-store +++ b/src/object-store @@ -1 +1 @@ -Subproject commit bb559df9237ece49f9c889993f7c1aff619b48f9 +Subproject commit 39c133a9aff6feaa76e9631696bdf67bc57ed5d5