Add schema definitions for the permissions types
This commit is contained in:
parent
4722e75eba
commit
ac7f7d9c4e
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit bb559df9237ece49f9c889993f7c1aff619b48f9
|
||||
Subproject commit 39c133a9aff6feaa76e9631696bdf67bc57ed5d5
|
Loading…
Reference in New Issue