insite-users-client 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/UsersSubscriptionGroup.d.ts +24 -0
- package/dist/UsersSubscriptionGroup.d.ts.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +7 -0
- package/dist/orgs.d.ts +40 -0
- package/dist/orgs.d.ts.map +1 -0
- package/dist/roles.d.ts +12 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/user.d.ts +16 -0
- package/dist/user.d.ts.map +1 -0
- package/dist/users.d.ts +36 -0
- package/dist/users.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/UsersSubscriptionGroup.ts +0 -75
- package/src/orgs.ts +0 -110
- package/src/roles.ts +0 -35
- package/src/user.ts +0 -53
- package/src/users.ts +0 -125
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SubscriptionGroup, type SubscriptionGroupOptions, type SubscriptionMapWithSubscription, type SubscriptionObjectWithSubscription } from "insite-subscriptions-client";
|
|
2
|
+
import { handleExtendedOrgs, handleOrgs, handleOrgsBeforeSubscribe } from "./orgs";
|
|
3
|
+
import { handleRoles } from "./roles";
|
|
4
|
+
import { handleUser } from "./user";
|
|
5
|
+
import { handleExtendedUsers, handleUsers } from "./users";
|
|
6
|
+
declare const basisDefinitions: ((string | typeof handleOrgs | typeof handleOrgsBeforeSubscribe)[] | (string | typeof handleUsers)[] | (string | boolean[] | typeof handleUser)[])[];
|
|
7
|
+
declare const extendedDefinitions: ((string | typeof handleRoles)[] | (string | boolean | typeof handleExtendedUsers)[] | (string | boolean | typeof handleExtendedOrgs)[])[];
|
|
8
|
+
export declare class UsersSubscriptionGroup extends SubscriptionGroup<typeof basisDefinitions | typeof extendedDefinitions> {
|
|
9
|
+
constructor(options: SubscriptionGroupOptions);
|
|
10
|
+
isExtended: boolean | null;
|
|
11
|
+
extend(): Promise<void> | null;
|
|
12
|
+
unextend(): void;
|
|
13
|
+
static handleValues({ orgs, users, user }: {
|
|
14
|
+
orgs: SubscriptionMapWithSubscription;
|
|
15
|
+
users: SubscriptionMapWithSubscription;
|
|
16
|
+
user: SubscriptionObjectWithSubscription;
|
|
17
|
+
}, options: SubscriptionGroupOptions): SubscriptionGroup<((string | typeof handleOrgs | typeof handleOrgsBeforeSubscribe | SubscriptionMapWithSubscription<({
|
|
18
|
+
_id: string;
|
|
19
|
+
} & Record<string, any>) | import("insite-subscriptions-client/dist/SubscriptionMap").SubscriptionMapItem>)[] | (string | typeof handleUsers | SubscriptionMapWithSubscription<({
|
|
20
|
+
_id: string;
|
|
21
|
+
} & Record<string, any>) | import("insite-subscriptions-client/dist/SubscriptionMap").SubscriptionMapItem>)[] | (string | typeof handleUser | SubscriptionObjectWithSubscription)[])[]>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=UsersSubscriptionGroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsersSubscriptionGroup.d.ts","sourceRoot":"","sources":["../src/UsersSubscriptionGroup.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,EACpC,KAAK,kCAAkC,EACvC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3D,QAAA,MAAM,gBAAgB,sJAIrB,CAAC;AAEF,QAAA,MAAM,mBAAmB,4IAIxB,CAAC;AAEF,qBAAa,sBAAuB,SAAQ,iBAAiB,CAAC,OAAO,gBAAgB,GAAG,OAAO,mBAAmB,CAAC;gBACtG,OAAO,EAAE,wBAAwB;IAK7C,UAAU,EAAE,OAAO,GAAG,IAAI,CAAS;IAEnC,MAAM;IAeN,QAAQ;IAWR,MAAM,CAAC,YAAY,CAAC,EACnB,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,EAAE;QACF,IAAI,EAAE,+BAA+B,CAAC;QACtC,KAAK,EAAE,+BAA+B,CAAC;QACvC,IAAI,EAAE,kCAAkC,CAAC;KACzC,EAAE,OAAO,EAAE,wBAAwB;;;;;CAQpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC5E,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxE,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var v=Object.defineProperty;var y=(e,r,s)=>r in e?v(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var f=(e,r,s)=>y(e,typeof r!="symbol"?r+"":r,s);import{SubscriptionGroup as O}from"insite-subscriptions-client";import{getAll as E}from"@nesvet/n";function u(e){e.null={_id:null,title:"",isOrg:!0,users:Object.assign(new Set,{sorted:[]})}}function a(e){if(e)for(let r of e.added)r.isOrg=!0,r.users=Object.assign(new Set,{sorted:[]});else this.values.orgs.null.users.clear(),this.values.orgs.null.users.sorted.length=0}function h(e){let r=this.values.orgs;if(e){let{users:s,extendedOrgs:o}=this.values;for(let p of e){let n=r.get(p._id);n.owners=p.owners.map(l=>s.get(l)||r.get(l)),n.slaveOrgs=E(r,p.slaveOrgs,!0),n.note=p.note,n._l=0}let i=[];for(let p of o.sorted){let n=r.get(p._id);for(let l of n.slaveOrgs)l._l=n._l+1;i.push(n)}r.sortedHierarchically=i,this.isLoaded&&(this.items.users.emitUpdate(),this.items.orgs.emitUpdate(e))}else{for(let s of r.sorted)delete s.owners,delete s.slaveOrgs,delete s.note,delete s._l;delete r.sortedHierarchically}}import{getAll as x}from"@nesvet/n";function U(e){if(e){let r=this.values.roles;for(let s of e)s.ownInvolves=x(r,s.ownInvolves,!0),s.involves=x(r,s.involves,!0),s._l=0;for(let s of r.sorted)for(let o of s.ownInvolves)o._l=s._l+1;this.isLoaded&&this.items.users.emitUpdate(e)}}function g(e){if(e){let r=e.slaveIds.join(",");if(e.slavesSnapshot!==r){e.slavesSnapshot=r;let s=[],o=[],i=[],{users:p,orgs:n}=this.values;for(let l of e.slaveIds){let t=p.get(l);t?(s.push(t),o.push(t)):(t=n.get(l),t&&(s.push(t),i.push(t)))}e.slaves=s,e.slaveUsers=o,e.slaveOrgs=i}}}import{removeOne as m}from"@nesvet/n";function c(e){if(e){let r=this.values.users,s=this.values.user,o=this.values.orgs;r.get(s._id)!==s&&(r.set(s._id,s),r.sorted[r.sorted.findIndex(t=>t._id===s._id)]=s);let i=e.findIndex(t=>t._id===s._id);~i&&(e[i]=s),~e.added.findIndex(t=>t._id===s._id)&&(e.added[i]=s);for(let t of e.added)t.isUser=!0;let n,l=new Set;for(let t of e){let d=o.get(t.orgId)??o.null;t.org!==d&&(t.org&&(t.org.users.delete(t),m(t.org.users.sorted,t)),t.org=d,t.org.users.add(t),t.org.users.sorted.push(t),l.add(t.org)),t===s&&(n=!0)}for(let t of l)t.users.sorted.sort(r.sortCompareFunction);if(e.deleted.length)for(let t of[...o.sorted,o.null])for(let d of t.users)r.has(d._id)||(t.users.delete(d),m(t.users.sorted,d));this.isLoaded&&(n&&this.items.user.emitUpdate(),this.items.orgs.emitUpdate())}}function b(e){let r=this.values.users;if(e){let{roles:s}=this.values;for(let o of e){let i=r.get(o._id);i.roles=s.getAll(o.roleIds)}}else for(let s of r.sorted)delete s.roles}var _=[["orgs","map",a,u],["users","map",c],["user",[!0],g]],M=[["roles","map",U],["extendedUsers","map","users.extended",b,!0],["extendedOrgs","map","orgs.extended",h,!0]],S=class extends O{constructor(s){super(_,s);f(this,"isExtended",!1)}extend(){return this.isExtended===!1?(this.isExtended=null,this.attach(M).then(()=>{this.isExtended=!0})):null}unextend(){this.isExtended&&(this.isExtended=!1,this.detach(["roles","extendedUsers","extendedOrgs"]))}static handleValues({orgs:s,users:o,user:i},p){return new O([["orgs",s,a,u],["users",o,c],["user",i,g]],p)}};export{S as UsersSubscriptionGroup};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/UsersSubscriptionGroup.ts", "../src/orgs.ts", "../src/roles.ts", "../src/user.ts", "../src/users.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n\tSubscriptionGroup,\n\ttype SubscriptionGroupOptions,\n\ttype SubscriptionMapWithSubscription,\n\ttype SubscriptionObjectWithSubscription\n} from \"insite-subscriptions-client\";\nimport { handleExtendedOrgs, handleOrgs, handleOrgsBeforeSubscribe } from \"./orgs\";\nimport { handleRoles } from \"./roles\";\nimport { handleUser } from \"./user\";\nimport { handleExtendedUsers, handleUsers } from \"./users\";\n\n\nconst basisDefinitions = [\n\t[ \"orgs\", \"map\", handleOrgs, handleOrgsBeforeSubscribe ],\n\t[ \"users\", \"map\", handleUsers ],\n\t[ \"user\", [ true ], handleUser ]\n];\n\nconst extendedDefinitions = [\n\t[ \"roles\", \"map\", handleRoles ],\n\t[ \"extendedUsers\", \"map\", \"users.extended\", handleExtendedUsers, true ],\n\t[ \"extendedOrgs\", \"map\", \"orgs.extended\", handleExtendedOrgs, true ]\n];\n\nexport class UsersSubscriptionGroup extends SubscriptionGroup<typeof basisDefinitions | typeof extendedDefinitions> {\n\tconstructor(options: SubscriptionGroupOptions) {\n\t\tsuper(basisDefinitions, options);\n\t\t\n\t}\n\t\n\tisExtended: boolean | null = false;\n\t\n\textend() {\n\t\t\n\t\tif (this.isExtended === false) {\n\t\t\tthis.isExtended = null;\n\t\t\t\n\t\t\treturn this.attach(extendedDefinitions).then(() => {\n\t\t\t\t\n\t\t\t\tthis.isExtended = true;\n\t\t\t\t\n\t\t\t});\n\t\t}\n\t\t\n\t\treturn null;\n\t}\n\t\n\tunextend() {\n\t\t\n\t\tif (this.isExtended) {\n\t\t\tthis.isExtended = false;\n\t\t\t\n\t\t\tthis.detach([ \"roles\", \"extendedUsers\", \"extendedOrgs\" ]);\n\t\t}\n\t\t\n\t}\n\t\n\t\n\tstatic handleValues({\n\t\torgs,\n\t\tusers,\n\t\tuser\n\t}: {\n\t\torgs: SubscriptionMapWithSubscription;\n\t\tusers: SubscriptionMapWithSubscription;\n\t\tuser: SubscriptionObjectWithSubscription;\n\t}, options: SubscriptionGroupOptions) {\n\t\treturn new SubscriptionGroup([\n\t\t\t[ \"orgs\", orgs, handleOrgs, handleOrgsBeforeSubscribe ],\n\t\t\t[ \"users\", users, handleUsers ],\n\t\t\t[ \"user\", user, handleUser ]\n\t\t], options);\n\t}\n\t\n}\n", "import { getAll } from \"@nesvet/n\";\nimport type { SubscriptionMapUpdated, SubscriptionMapWithSubscription } from \"insite-subscriptions-client\";\nimport type { User } from \"./users\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\nexport type Org = {\n\t_id: string;\n\ttitle: string;\n\tisOrg: true;\n\tusers: { sorted: User[] } & Set<User>;\n};\n\nexport type NullOrg = { _id: null } & Omit<Org, \"_id\">;\n\ntype OrgExtension = {\n\t_id: string;\n\towners: string[];\n\tslaveOrgs: string[];\n\tnote: string;\n};\n\nexport type OrgExtended = {\n\towners?: (OrgExtended | User)[];\n\tslaveOrgs?: OrgExtended[];\n\tnote?: string;\n\t_l?: number;\n} & Org;\n\ntype OrgsExtra = {\n\tnull: NullOrg;\n};\n\nexport type Orgs = OrgsExtra & SubscriptionMapWithSubscription<Org>;\n\nexport type OrgsExtended = {\n\tsortedHierarchically?: OrgExtended[];\n} & OrgsExtra & SubscriptionMapWithSubscription<OrgExtended>;\n\n\nexport function handleOrgsBeforeSubscribe(orgs: Orgs) {\n\torgs.null = {\n\t\t_id: null,\n\t\ttitle: \"\",\n\t\tisOrg: true,\n\t\tusers: Object.assign(new Set<User>(), { sorted: [] })\n\t};\n\t\n}\n\n/** @this UsersSubscriptionGroup */\nexport function handleOrgs(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<Org>) {\n\tif (updated)\n\t\tfor (const org of updated.added) {\n\t\t\torg.isOrg = true;\n\t\t\t\n\t\t\torg.users = Object.assign(new Set<User>(), { sorted: [] });\n\t\t}\n\telse {\n\t\tthis.values.orgs.null.users.clear();\n\t\tthis.values.orgs.null.users.sorted.length = 0;\n\t}\n\t\n}\n\n/** @this UsersSubscriptionGroup */\nexport function handleExtendedOrgs(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<OrgExtension>) {\n\t\n\tconst orgs = this.values.orgs as OrgsExtended;\n\t\n\tif (updated) {\n\t\tconst { users, extendedOrgs } = this.values;\n\t\t\n\t\tfor (const orgExtension of updated) {\n\t\t\tconst org = orgs.get(orgExtension._id)!;\n\t\t\t\n\t\t\torg.owners = orgExtension.owners.map(_id => users.get(_id) || orgs.get(_id));\n\t\t\torg.slaveOrgs = getAll(orgs, orgExtension.slaveOrgs, true);\n\t\t\torg.note = orgExtension.note;\n\t\t\torg._l = 0;\n\t\t}\n\t\t\n\t\tconst sortedHierarchically = [];\n\t\t\n\t\tfor (const orgExtension of extendedOrgs.sorted) {\n\t\t\tconst org = orgs.get(orgExtension._id)!;\n\t\t\t\n\t\t\tfor (const slaveOrg of org.slaveOrgs!)\n\t\t\t\tslaveOrg._l = org._l! + 1;\n\t\t\t\n\t\t\tsortedHierarchically.push(org);\n\t\t}\n\t\t\n\t\torgs.sortedHierarchically = sortedHierarchically;\n\t\t\n\t\tif (this.isLoaded) {\n\t\t\tthis.items.users.emitUpdate();\n\t\t\tthis.items.orgs.emitUpdate(updated);\n\t\t}\n\t} else {\n\t\tfor (const org of orgs.sorted) {\n\t\t\tdelete org.owners;\n\t\t\tdelete org.slaveOrgs;\n\t\t\tdelete org.note;\n\t\t\tdelete org._l;\n\t\t}\n\t\tdelete orgs.sortedHierarchically;\n\t}\n\t\n}\n", "import { getAll } from \"@nesvet/n\";\nimport type { SubscriptionMapUpdated, SubscriptionMapWithSubscription } from \"insite-subscriptions-client\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\nexport type Role = {\n\t_id: string;\n\townInvolves: Role[];\n\tinvolves: Role[];\n\t_l: number;\n};\n\nexport type Roles = SubscriptionMapWithSubscription<Role>;\n\n\n/** @this UsersSubscriptionGroup */\nexport function handleRoles(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<Role>) {\n\tif (updated) {\n\t\tconst roles = this.values.roles as Roles;\n\t\t\n\t\tfor (const role of updated) {\n\t\t\trole.ownInvolves = getAll(roles, role.ownInvolves as unknown as string[], true);\n\t\t\trole.involves = getAll(roles, role.involves as unknown as string[], true);\n\t\t\trole._l = 0;\n\t\t}\n\t\t\n\t\tfor (const role of roles.sorted)\n\t\t\tfor (const involvedRole of role.ownInvolves)\n\t\t\t\tinvolvedRole._l = role._l + 1;\n\t\t\n\t\tif (this.isLoaded)\n\t\t\tthis.items.users.emitUpdate(updated);\n\t}\n\t\n}\n", "import type { Abilities, AbilitiesSchema } from \"insite-common\";\nimport type { Org } from \"./orgs\";\nimport type { User, UserExtended } from \"./users\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\nexport type CurrentUser<AS extends AbilitiesSchema = AbilitiesSchema> = {\n\tabilities: Abilities<AS>;\n\tsessionId?: string;\n\tslaveIds: string[];\n\tslavesSnapshot: string;\n\tslaves: (Org | User)[];\n\tslaveUsers: User[];\n\tslaveOrgs: Org[];\n} & UserExtended;\n\n\n/** @this UsersSubscriptionGroup */\nexport function handleUser(this: UsersSubscriptionGroup, user: CurrentUser) {\n\tif (user) {\n\t\t\n\t\tconst slavesSnapshot = user.slaveIds.join(\",\");\n\t\t\n\t\tif (user.slavesSnapshot !== slavesSnapshot) {\n\t\t\tuser.slavesSnapshot = slavesSnapshot;\n\t\t\t\n\t\t\tconst slaves = [];\n\t\t\tconst slaveUsers = [];\n\t\t\tconst slaveOrgs = [];\n\t\t\t\n\t\t\tconst { users, orgs } = this.values;\n\t\t\t\n\t\t\tfor (const _id of user.slaveIds) {\n\t\t\t\tlet slave = users.get(_id);\n\t\t\t\tif (slave) {\n\t\t\t\t\tslaves.push(slave);\n\t\t\t\t\tslaveUsers.push(slave);\n\t\t\t\t} else {\n\t\t\t\t\tslave = orgs.get(_id);\n\t\t\t\t\tif (slave) {\n\t\t\t\t\t\tslaves.push(slave);\n\t\t\t\t\t\tslaveOrgs.push(slave);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tuser.slaves = slaves;\n\t\t\tuser.slaveUsers = slaveUsers;\n\t\t\tuser.slaveOrgs = slaveOrgs;\n\t\t}\n\t}\n\t\n}\n", "import { removeOne } from \"@nesvet/n\";\nimport type { SubscriptionMapUpdated, SubscriptionMapWithSubscription } from \"insite-subscriptions-client\";\nimport type { NullOrg, Org, Orgs } from \"./orgs\";\nimport type { Role } from \"./roles\";\nimport type { CurrentUser } from \"./user\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\nexport type User = {\n\t_id: string;\n\tisUser: true;\n\temail: string;\n\tname: {\n\t\tfirst: string;\n\t\tmiddle: string;\n\t\tlast: string;\n\t};\n\torgId: string;\n\tjob: string;\n\tinitials: string;\n\tdisplayLabel: string;\n\tavatarUrl: string;\n\tisOnline: boolean;\n\torg: NullOrg | Org;\n};\n\ntype UserExtension = {\n\t_id: string;\n\troleIds: string[];\n};\n\nexport type UserExtended = {\n\troles?: Role;\n} & User;\n\nexport type Users = SubscriptionMapWithSubscription<User>;\n\nexport type UsersExtended = SubscriptionMapWithSubscription<UserExtended>;\n\n\n/** @this UsersSubscriptionGroup */\nexport function handleUsers(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<User>) {\n\tif (updated) {\n\t\tconst users = this.values.users as Users;\n\t\tconst currentUser = this.values.user as CurrentUser;\n\t\tconst orgs = this.values.orgs as Orgs;\n\t\t\n\t\tif (users.get(currentUser._id) !== currentUser) {\n\t\t\tusers.set(currentUser._id, currentUser);\n\t\t\tusers.sorted[users.sorted.findIndex(user => user._id === currentUser._id)] = currentUser;\n\t\t}\n\t\tconst updatedUserIndex = updated.findIndex(user => user._id === currentUser._id);\n\t\t\n\t\tif (~updatedUserIndex)\n\t\t\tupdated[updatedUserIndex] = currentUser;\n\t\t\n\t\tconst addedUserIndex = updated.added.findIndex(user => user._id === currentUser._id);\n\t\t\n\t\tif (~addedUserIndex)\n\t\t\tupdated.added[updatedUserIndex] = currentUser;\n\t\t\n\t\tfor (const user of updated.added)\n\t\t\tuser.isUser = true;\n\t\t\n\t\tlet shouldUpdateUser;\n\t\tconst orgsToSortUsers = new Set<NullOrg | Org>();\n\t\t\n\t\tfor (const user of updated) {\n\t\t\tconst org = orgs.get(user.orgId) ?? orgs.null;\n\t\t\t\n\t\t\tif (user.org !== org) {\n\t\t\t\tif (user.org) {\n\t\t\t\t\tuser.org.users.delete(user);\n\t\t\t\t\tremoveOne(user.org.users.sorted, user);\n\t\t\t\t}\n\t\t\t\tuser.org = org;\n\t\t\t\tuser.org.users.add(user);\n\t\t\t\tuser.org.users.sorted.push(user);\n\t\t\t\t\n\t\t\t\torgsToSortUsers.add(user.org);\n\t\t\t}\n\t\t\t\n\t\t\tif (user === currentUser)\n\t\t\t\tshouldUpdateUser = true;\n\t\t\t\n\t\t}\n\t\t\n\t\tfor (const org of orgsToSortUsers)\n\t\t\torg.users.sorted.sort(users.sortCompareFunction!);\n\t\t\n\t\tif (updated.deleted.length)\n\t\t\tfor (const org of [ ...orgs.sorted, orgs.null ])\n\t\t\t\tfor (const user of org.users)\n\t\t\t\t\tif (!users.has(user._id)) {\n\t\t\t\t\t\torg.users.delete(user);\n\t\t\t\t\t\tremoveOne(org.users.sorted, user);\n\t\t\t\t\t}\n\t\t\n\t\tif (this.isLoaded) {\n\t\t\tif (shouldUpdateUser)\n\t\t\t\tthis.items.user.emitUpdate();\n\t\t\tthis.items.orgs.emitUpdate();\n\t\t}\n\t}\n\t\n}\n\n/** @this UsersSubscriptionGroup */\nexport function handleExtendedUsers(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<UserExtension>) {\n\t\n\tconst users = this.values.users as UsersExtended;\n\t\n\tif (updated) {\n\t\tconst { roles } = this.values;\n\t\t\n\t\tfor (const userExtension of updated) {\n\t\t\tconst user = users.get(userExtension._id)!;\n\t\t\t\n\t\t\tuser.roles = roles.getAll(userExtension.roleIds);\n\t\t}\n\t} else\n\t\tfor (const user of users.sorted)\n\t\t\tdelete user.roles;\n\t\n}\n"],
|
|
5
|
+
"mappings": "oKAAA,OACC,qBAAAA,MAIM,8BCLP,OAAS,UAAAC,MAAc,YAwChB,SAASC,EAA0BC,EAAY,CACrDA,EAAK,KAAO,CACX,IAAK,KACL,MAAO,GACP,MAAO,GACP,MAAO,OAAO,OAAO,IAAI,IAAa,CAAE,OAAQ,CAAC,CAAE,CAAC,CACrD,CAED,CAGO,SAASC,EAAyCC,EAA6C,CACrG,GAAIA,EACH,QAAWC,KAAOD,EAAQ,MACzBC,EAAI,MAAQ,GAEZA,EAAI,MAAQ,OAAO,OAAO,IAAI,IAAa,CAAE,OAAQ,CAAC,CAAE,CAAC,OAG1D,KAAK,OAAO,KAAK,KAAK,MAAM,MAAM,EAClC,KAAK,OAAO,KAAK,KAAK,MAA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GC,CAAW,CAChC,EAEMC,EAAsB,CAC3B,CAAE,QAAS,MAAOC,CAAY,EAC9B,CAAE,gBAAiB,MAAO,iBAAkBC,EAAqB,EAAK,EACtE,CAAE,eAAgB,MAAO,gBAAiBC,EAAoB,EAAK,CACpE,EAEaC,EAAN,cAAqCC,CAAwE,CACnH,YAAYC,EAAmC,CAC9C,MAAMX,EAAkBW,CAAO,EAIhCC,EAAA,kBAA6B,GAF7B,CAIA,QAAS,CAER,OAAI,KAAK,aAAe,IACvB,KAAK,WAAa,KAEX,KAAK,OAAOP,CAAmB,EAAE,KAAK,IAAM,CAElD,KAAK,WAAa,EAEnB,CAAC,GAGK,IACR,CAEA,UAAW,CAEN,KAAK,aACR,KAAK,WAAa,GAElB,KAAK,OAAO,CAAE,QAAS,gBAAiB,cAAe,CAAC,EAG1D,CAGA,OAAO,aAAa,CACnB,KAAAQ,EACA,MAAAC,EACA,KAAAC,CACD,EAIGJ,EAAmC,CACrC,OAAO,IAAID,EAAkB,CAC5B,CAAE,OAAQG,EAAMZ,EAAYC,CAA0B,EACtD,CAAE,QAASY,EAAOX,CAAY,EAC9B,CAAE,OAAQY,EAAMX,CAAW,CAC5B,EAAGO,CAAO,CACX,CAED",
|
|
6
|
+
"names": ["SubscriptionGroup", "getAll", "handleOrgsBeforeSubscribe", "orgs", "handleOrgs", "updated", "org", "handleExtendedOrgs", "users", "extendedOrgs", "orgExtension", "_id", "sortedHierarchically", "slaveOrg", "getAll", "handleRoles", "updated", "roles", "role", "involvedRole", "handleUser", "user", "slavesSnapshot", "slaves", "slaveUsers", "slaveOrgs", "users", "orgs", "_id", "slave", "removeOne", "handleUsers", "updated", "users", "currentUser", "orgs", "user", "updatedUserIndex", "shouldUpdateUser", "orgsToSortUsers", "org", "handleExtendedUsers", "roles", "userExtension", "basisDefinitions", "handleOrgs", "handleOrgsBeforeSubscribe", "handleUsers", "handleUser", "extendedDefinitions", "handleRoles", "handleExtendedUsers", "handleExtendedOrgs", "UsersSubscriptionGroup", "SubscriptionGroup", "options", "__publicField", "orgs", "users", "user"]
|
|
7
|
+
}
|
package/dist/orgs.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SubscriptionMapUpdated, SubscriptionMapWithSubscription } from "insite-subscriptions-client";
|
|
2
|
+
import type { User } from "./users";
|
|
3
|
+
import type { UsersSubscriptionGroup } from "./UsersSubscriptionGroup";
|
|
4
|
+
export type Org = {
|
|
5
|
+
_id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
isOrg: true;
|
|
8
|
+
users: {
|
|
9
|
+
sorted: User[];
|
|
10
|
+
} & Set<User>;
|
|
11
|
+
};
|
|
12
|
+
export type NullOrg = {
|
|
13
|
+
_id: null;
|
|
14
|
+
} & Omit<Org, "_id">;
|
|
15
|
+
type OrgExtension = {
|
|
16
|
+
_id: string;
|
|
17
|
+
owners: string[];
|
|
18
|
+
slaveOrgs: string[];
|
|
19
|
+
note: string;
|
|
20
|
+
};
|
|
21
|
+
export type OrgExtended = {
|
|
22
|
+
owners?: (OrgExtended | User)[];
|
|
23
|
+
slaveOrgs?: OrgExtended[];
|
|
24
|
+
note?: string;
|
|
25
|
+
_l?: number;
|
|
26
|
+
} & Org;
|
|
27
|
+
type OrgsExtra = {
|
|
28
|
+
null: NullOrg;
|
|
29
|
+
};
|
|
30
|
+
export type Orgs = OrgsExtra & SubscriptionMapWithSubscription<Org>;
|
|
31
|
+
export type OrgsExtended = {
|
|
32
|
+
sortedHierarchically?: OrgExtended[];
|
|
33
|
+
} & OrgsExtra & SubscriptionMapWithSubscription<OrgExtended>;
|
|
34
|
+
export declare function handleOrgsBeforeSubscribe(orgs: Orgs): void;
|
|
35
|
+
/** @this UsersSubscriptionGroup */
|
|
36
|
+
export declare function handleOrgs(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<Org>): void;
|
|
37
|
+
/** @this UsersSubscriptionGroup */
|
|
38
|
+
export declare function handleExtendedOrgs(this: UsersSubscriptionGroup, updated: null | Subscri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,GAAG,CAAC,CAAC;AAEpE,MAAM,MAAM,YAAY,GAAG;IAC1B,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC;CACrC,GAAG,SAAS,GAAG,+BAA+B,CAAC,WAAW,CAAC,CAAC;AAG7D,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,IAAI,QAQnD;AAED,mCAAmC;AACnC,wBAAgB,UAAU,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,IAAI,GAAG,sBAAsB,CAAC,GAAG,CAAC,QAYnG;AAED,mCAAmC;AACnC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,IAAI,GAAG,sBAAsB,CAAC,YAAY,CAAC,QA2CpH"}
|
package/dist/roles.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SubscriptionMapUpdated, SubscriptionMapWithSubscription } from "insite-subscriptions-client";
|
|
2
|
+
import type { UsersSubscriptionGroup } from "./UsersSubscriptionGroup";
|
|
3
|
+
export type Role = {
|
|
4
|
+
_id: string;
|
|
5
|
+
ownInvolves: Role[];
|
|
6
|
+
involves: Role[];
|
|
7
|
+
_l: number;
|
|
8
|
+
};
|
|
9
|
+
export type Roles = SubscriptionMapWithSubscription<Role>;
|
|
10
|
+
/** @this UsersSubscriptionGroup */
|
|
11
|
+
export declare function handleRoles(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<Role>): void;
|
|
12
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../src/roles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,MAAM,6BAA6B,CAAC;AAC3G,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGvE,MAAM,MAAM,IAAI,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,IAAI,EAAE,CAAC;IACpB,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,+BAA+B,CAAC,IAAI,CAAC,CAAC;AAG1D,mCAAmC;AACnC,wBAAgB,WAAW,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,IAAI,GAAG,sBAAsB,CAAC,IAAI,CAAC,QAkBrG"}
|
package/dist/user.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Abilities, AbilitiesSchema } from "insite-common";
|
|
2
|
+
import type { Org } from "./orgs";
|
|
3
|
+
import type { User, UserExtended } from "./users";
|
|
4
|
+
import type { UsersSubscriptionGroup } from "./UsersSubscriptionGroup";
|
|
5
|
+
export type CurrentUser<AS extends AbilitiesSchema = AbilitiesSchema> = {
|
|
6
|
+
abilities: Abilities<AS>;
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
slaveIds: string[];
|
|
9
|
+
slavesSnapshot: string;
|
|
10
|
+
slaves: (Org | User)[];
|
|
11
|
+
slaveUsers: User[];
|
|
12
|
+
slaveOrgs: Org[];
|
|
13
|
+
} & UserExtended;
|
|
14
|
+
/** @this UsersSubscriptionGroup */
|
|
15
|
+
export declare function handleUser(this: UsersSubscriptionGroup, user: CurrentUser): void;
|
|
16
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGvE,MAAM,MAAM,WAAW,CAAC,EAAE,SAAS,eAAe,GAAG,eAAe,IAAI;IACvE,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC;IACvB,UAAU,EAAE,IAAI,EAAE,CAAC;IACnB,SAAS,EAAE,GAAG,EAAE,CAAC;CACjB,GAAG,YAAY,CAAC;AAGjB,mCAAmC;AACnC,wBAAgB,UAAU,CAAC,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE,WAAW,QAkCzE"}
|
package/dist/users.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SubscriptionMapUpdated, SubscriptionMapWithSubscription } from "insite-subscriptions-client";
|
|
2
|
+
import type { NullOrg, Org } from "./orgs";
|
|
3
|
+
import type { Role } from "./roles";
|
|
4
|
+
import type { UsersSubscriptionGroup } from "./UsersSubscriptionGroup";
|
|
5
|
+
export type User = {
|
|
6
|
+
_id: string;
|
|
7
|
+
isUser: true;
|
|
8
|
+
email: string;
|
|
9
|
+
name: {
|
|
10
|
+
first: string;
|
|
11
|
+
middle: string;
|
|
12
|
+
last: string;
|
|
13
|
+
};
|
|
14
|
+
orgId: string;
|
|
15
|
+
job: string;
|
|
16
|
+
initials: string;
|
|
17
|
+
displayLabel: string;
|
|
18
|
+
avatarUrl: string;
|
|
19
|
+
isOnline: boolean;
|
|
20
|
+
org: NullOrg | Org;
|
|
21
|
+
};
|
|
22
|
+
type UserExtension = {
|
|
23
|
+
_id: string;
|
|
24
|
+
roleIds: string[];
|
|
25
|
+
};
|
|
26
|
+
export type UserExtended = {
|
|
27
|
+
roles?: Role;
|
|
28
|
+
} & User;
|
|
29
|
+
export type Users = SubscriptionMapWithSubscription<User>;
|
|
30
|
+
export type UsersExtended = SubscriptionMapWithSubscription<UserExtended>;
|
|
31
|
+
/** @this UsersSubscriptionGroup */
|
|
32
|
+
export declare function handleUsers(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<User>): void;
|
|
33
|
+
/** @this UsersSubscriptionGroup */
|
|
34
|
+
export declare function handleExtendedUsers(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<UserExtension>): void;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=users.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../src/users.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,MAAM,6BAA6B,CAAC;AAC3G,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAQ,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGvE,MAAM,MAAM,IAAI,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACb,CAAC;IACF,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,EAAE,OAAO,GAAG,GAAG,CAAC;CACnB,CAAC;AAEF,KAAK,aAAa,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAC1B,KAAK,CAAC,EAAE,IAAI,CAAC;CACb,GAAG,IAAI,CAAC;AAET,MAAM,MAAM,KAAK,GAAG,+BAA+B,CAAC,IAAI,CAAC,CAAC;AAE1D,MAAM,MAAM,aAAa,GAAG,+BAA+B,CAAC,YAAY,CAAC,CAAC;AAG1E,mCAAmC;AACnC,wBAAgB,WAAW,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,IAAI,GAAG,sBAAsB,CAAC,IAAI,CAAC,QAgErG;AAED,mCAAmC;AACnC,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,IAAI,GAAG,sBAAsB,CAAC,aAAa,CAAC,QAgBtH"}
|
package/package.json
CHANGED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SubscriptionGroup,
|
|
3
|
-
type SubscriptionGroupOptions,
|
|
4
|
-
type SubscriptionMapWithSubscription,
|
|
5
|
-
type SubscriptionObjectWithSubscription
|
|
6
|
-
} from "insite-subscriptions-client";
|
|
7
|
-
import { handleExtendedOrgs, handleOrgs, handleOrgsBeforeSubscribe } from "./orgs";
|
|
8
|
-
import { handleRoles } from "./roles";
|
|
9
|
-
import { handleUser } from "./user";
|
|
10
|
-
import { handleExtendedUsers, handleUsers } from "./users";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const basisDefinitions = [
|
|
14
|
-
[ "orgs", "map", handleOrgs, handleOrgsBeforeSubscribe ],
|
|
15
|
-
[ "users", "map", handleUsers ],
|
|
16
|
-
[ "user", [ true ], handleUser ]
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
const extendedDefinitions = [
|
|
20
|
-
[ "roles", "map", handleRoles ],
|
|
21
|
-
[ "extendedUsers", "map", "users.extended", handleExtendedUsers, true ],
|
|
22
|
-
[ "extendedOrgs", "map", "orgs.extended", handleExtendedOrgs, true ]
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
export class UsersSubscriptionGroup extends SubscriptionGroup<typeof basisDefinitions | typeof extendedDefinitions> {
|
|
26
|
-
constructor(options: SubscriptionGroupOptions) {
|
|
27
|
-
super(basisDefinitions, options);
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
isExtended: boolean | null = false;
|
|
32
|
-
|
|
33
|
-
extend() {
|
|
34
|
-
|
|
35
|
-
if (this.isExtended === false) {
|
|
36
|
-
this.isExtended = null;
|
|
37
|
-
|
|
38
|
-
return this.attach(extendedDefinitions).then(() => {
|
|
39
|
-
|
|
40
|
-
this.isExtended = true;
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
unextend() {
|
|
49
|
-
|
|
50
|
-
if (this.isExtended) {
|
|
51
|
-
this.isExtended = false;
|
|
52
|
-
|
|
53
|
-
this.detach([ "roles", "extendedUsers", "extendedOrgs" ]);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
static handleValues({
|
|
60
|
-
orgs,
|
|
61
|
-
users,
|
|
62
|
-
user
|
|
63
|
-
}: {
|
|
64
|
-
orgs: SubscriptionMapWithSubscription;
|
|
65
|
-
users: SubscriptionMapWithSubscription;
|
|
66
|
-
user: SubscriptionObjectWithSubscription;
|
|
67
|
-
}, options: SubscriptionGroupOptions) {
|
|
68
|
-
return new SubscriptionGroup([
|
|
69
|
-
[ "orgs", orgs, handleOrgs, handleOrgsBeforeSubscribe ],
|
|
70
|
-
[ "users", users, handleUsers ],
|
|
71
|
-
[ "user", user, handleUser ]
|
|
72
|
-
], options);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
}
|
package/src/orgs.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { getAll } from "@nesvet/n";
|
|
2
|
-
import type { SubscriptionMapUpdated, SubscriptionMapWithSubscription } from "insite-subscriptions-client";
|
|
3
|
-
import type { User } from "./users";
|
|
4
|
-
import type { UsersSubscriptionGroup } from "./UsersSubscriptionGroup";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type Org = {
|
|
8
|
-
_id: string;
|
|
9
|
-
title: string;
|
|
10
|
-
isOrg: true;
|
|
11
|
-
users: { sorted: User[] } & Set<User>;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type NullOrg = { _id: null } & Omit<Org, "_id">;
|
|
15
|
-
|
|
16
|
-
type OrgExtension = {
|
|
17
|
-
_id: string;
|
|
18
|
-
owners: string[];
|
|
19
|
-
slaveOrgs: string[];
|
|
20
|
-
note: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type OrgExtended = {
|
|
24
|
-
owners?: (OrgExtended | User)[];
|
|
25
|
-
slaveOrgs?: OrgExtended[];
|
|
26
|
-
note?: string;
|
|
27
|
-
_l?: number;
|
|
28
|
-
} & Org;
|
|
29
|
-
|
|
30
|
-
type OrgsExtra = {
|
|
31
|
-
null: NullOrg;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type Orgs = OrgsExtra & SubscriptionMapWithSubscription<Org>;
|
|
35
|
-
|
|
36
|
-
export type OrgsExtended = {
|
|
37
|
-
sortedHierarchically?: OrgExtended[];
|
|
38
|
-
} & OrgsExtra & SubscriptionMapWithSubscription<OrgExtended>;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export function handleOrgsBeforeSubscribe(orgs: Orgs) {
|
|
42
|
-
orgs.null = {
|
|
43
|
-
_id: null,
|
|
44
|
-
title: "",
|
|
45
|
-
isOrg: true,
|
|
46
|
-
users: Object.assign(new Set<User>(), { sorted: [] })
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** @this UsersSubscriptionGroup */
|
|
52
|
-
export function handleOrgs(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<Org>) {
|
|
53
|
-
if (updated)
|
|
54
|
-
for (const org of updated.added) {
|
|
55
|
-
org.isOrg = true;
|
|
56
|
-
|
|
57
|
-
org.users = Object.assign(new Set<User>(), { sorted: [] });
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
this.values.orgs.null.users.clear();
|
|
61
|
-
this.values.orgs.null.users.sorted.length = 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** @this UsersSubscriptionGroup */
|
|
67
|
-
export function handleExtendedOrgs(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<OrgExtension>) {
|
|
68
|
-
|
|
69
|
-
const orgs = this.values.orgs as OrgsExtended;
|
|
70
|
-
|
|
71
|
-
if (updated) {
|
|
72
|
-
const { users, extendedOrgs } = this.values;
|
|
73
|
-
|
|
74
|
-
for (const orgExtension of updated) {
|
|
75
|
-
const org = orgs.get(orgExtension._id)!;
|
|
76
|
-
|
|
77
|
-
org.owners = orgExtension.owners.map(_id => users.get(_id) || orgs.get(_id));
|
|
78
|
-
org.slaveOrgs = getAll(orgs, orgExtension.slaveOrgs, true);
|
|
79
|
-
org.note = orgExtension.note;
|
|
80
|
-
org._l = 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const sortedHierarchically = [];
|
|
84
|
-
|
|
85
|
-
for (const orgExtension of extendedOrgs.sorted) {
|
|
86
|
-
const org = orgs.get(orgExtension._id)!;
|
|
87
|
-
|
|
88
|
-
for (const slaveOrg of org.slaveOrgs!)
|
|
89
|
-
slaveOrg._l = org._l! + 1;
|
|
90
|
-
|
|
91
|
-
sortedHierarchically.push(org);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
orgs.sortedHierarchically = sortedHierarchically;
|
|
95
|
-
|
|
96
|
-
if (this.isLoaded) {
|
|
97
|
-
this.items.users.emitUpdate();
|
|
98
|
-
this.items.orgs.emitUpdate(updated);
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
for (const org of orgs.sorted) {
|
|
102
|
-
delete org.owners;
|
|
103
|
-
delete org.slaveOrgs;
|
|
104
|
-
delete org.note;
|
|
105
|
-
delete org._l;
|
|
106
|
-
}
|
|
107
|
-
delete orgs.sortedHierarchically;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
}
|
package/src/roles.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { getAll } from "@nesvet/n";
|
|
2
|
-
import type { SubscriptionMapUpdated, SubscriptionMapWithSubscription } from "insite-subscriptions-client";
|
|
3
|
-
import type { UsersSubscriptionGroup } from "./UsersSubscriptionGroup";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type Role = {
|
|
7
|
-
_id: string;
|
|
8
|
-
ownInvolves: Role[];
|
|
9
|
-
involves: Role[];
|
|
10
|
-
_l: number;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type Roles = SubscriptionMapWithSubscription<Role>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/** @this UsersSubscriptionGroup */
|
|
17
|
-
export function handleRoles(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<Role>) {
|
|
18
|
-
if (updated) {
|
|
19
|
-
const roles = this.values.roles as Roles;
|
|
20
|
-
|
|
21
|
-
for (const role of updated) {
|
|
22
|
-
role.ownInvolves = getAll(roles, role.ownInvolves as unknown as string[], true);
|
|
23
|
-
role.involves = getAll(roles, role.involves as unknown as string[], true);
|
|
24
|
-
role._l = 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
for (const role of roles.sorted)
|
|
28
|
-
for (const involvedRole of role.ownInvolves)
|
|
29
|
-
involvedRole._l = role._l + 1;
|
|
30
|
-
|
|
31
|
-
if (this.isLoaded)
|
|
32
|
-
this.items.users.emitUpdate(updated);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}
|
package/src/user.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { Abilities, AbilitiesSchema } from "insite-common";
|
|
2
|
-
import type { Org } from "./orgs";
|
|
3
|
-
import type { User, UserExtended } from "./users";
|
|
4
|
-
import type { UsersSubscriptionGroup } from "./UsersSubscriptionGroup";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type CurrentUser<AS extends AbilitiesSchema = AbilitiesSchema> = {
|
|
8
|
-
abilities: Abilities<AS>;
|
|
9
|
-
sessionId?: string;
|
|
10
|
-
slaveIds: string[];
|
|
11
|
-
slavesSnapshot: string;
|
|
12
|
-
slaves: (Org | User)[];
|
|
13
|
-
slaveUsers: User[];
|
|
14
|
-
slaveOrgs: Org[];
|
|
15
|
-
} & UserExtended;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/** @this UsersSubscriptionGroup */
|
|
19
|
-
export function handleUser(this: UsersSubscriptionGroup, user: CurrentUser) {
|
|
20
|
-
if (user) {
|
|
21
|
-
|
|
22
|
-
const slavesSnapshot = user.slaveIds.join(",");
|
|
23
|
-
|
|
24
|
-
if (user.slavesSnapshot !== slavesSnapshot) {
|
|
25
|
-
user.slavesSnapshot = slavesSnapshot;
|
|
26
|
-
|
|
27
|
-
const slaves = [];
|
|
28
|
-
const slaveUsers = [];
|
|
29
|
-
const slaveOrgs = [];
|
|
30
|
-
|
|
31
|
-
const { users, orgs } = this.values;
|
|
32
|
-
|
|
33
|
-
for (const _id of user.slaveIds) {
|
|
34
|
-
let slave = users.get(_id);
|
|
35
|
-
if (slave) {
|
|
36
|
-
slaves.push(slave);
|
|
37
|
-
slaveUsers.push(slave);
|
|
38
|
-
} else {
|
|
39
|
-
slave = orgs.get(_id);
|
|
40
|
-
if (slave) {
|
|
41
|
-
slaves.push(slave);
|
|
42
|
-
slaveOrgs.push(slave);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
user.slaves = slaves;
|
|
48
|
-
user.slaveUsers = slaveUsers;
|
|
49
|
-
user.slaveOrgs = slaveOrgs;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
package/src/users.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { removeOne } from "@nesvet/n";
|
|
2
|
-
import type { SubscriptionMapUpdated, SubscriptionMapWithSubscription } from "insite-subscriptions-client";
|
|
3
|
-
import type { NullOrg, Org, Orgs } from "./orgs";
|
|
4
|
-
import type { Role } from "./roles";
|
|
5
|
-
import type { CurrentUser } from "./user";
|
|
6
|
-
import type { UsersSubscriptionGroup } from "./UsersSubscriptionGroup";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export type User = {
|
|
10
|
-
_id: string;
|
|
11
|
-
isUser: true;
|
|
12
|
-
email: string;
|
|
13
|
-
name: {
|
|
14
|
-
first: string;
|
|
15
|
-
middle: string;
|
|
16
|
-
last: string;
|
|
17
|
-
};
|
|
18
|
-
orgId: string;
|
|
19
|
-
job: string;
|
|
20
|
-
initials: string;
|
|
21
|
-
displayLabel: string;
|
|
22
|
-
avatarUrl: string;
|
|
23
|
-
isOnline: boolean;
|
|
24
|
-
org: NullOrg | Org;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type UserExtension = {
|
|
28
|
-
_id: string;
|
|
29
|
-
roleIds: string[];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type UserExtended = {
|
|
33
|
-
roles?: Role;
|
|
34
|
-
} & User;
|
|
35
|
-
|
|
36
|
-
export type Users = SubscriptionMapWithSubscription<User>;
|
|
37
|
-
|
|
38
|
-
export type UsersExtended = SubscriptionMapWithSubscription<UserExtended>;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/** @this UsersSubscriptionGroup */
|
|
42
|
-
export function handleUsers(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<User>) {
|
|
43
|
-
if (updated) {
|
|
44
|
-
const users = this.values.users as Users;
|
|
45
|
-
const currentUser = this.values.user as CurrentUser;
|
|
46
|
-
const orgs = this.values.orgs as Orgs;
|
|
47
|
-
|
|
48
|
-
if (users.get(currentUser._id) !== currentUser) {
|
|
49
|
-
users.set(currentUser._id, currentUser);
|
|
50
|
-
users.sorted[users.sorted.findIndex(user => user._id === currentUser._id)] = currentUser;
|
|
51
|
-
}
|
|
52
|
-
const updatedUserIndex = updated.findIndex(user => user._id === currentUser._id);
|
|
53
|
-
|
|
54
|
-
if (~updatedUserIndex)
|
|
55
|
-
updated[updatedUserIndex] = currentUser;
|
|
56
|
-
|
|
57
|
-
const addedUserIndex = updated.added.findIndex(user => user._id === currentUser._id);
|
|
58
|
-
|
|
59
|
-
if (~addedUserIndex)
|
|
60
|
-
updated.added[updatedUserIndex] = currentUser;
|
|
61
|
-
|
|
62
|
-
for (const user of updated.added)
|
|
63
|
-
user.isUser = true;
|
|
64
|
-
|
|
65
|
-
let shouldUpdateUser;
|
|
66
|
-
const orgsToSortUsers = new Set<NullOrg | Org>();
|
|
67
|
-
|
|
68
|
-
for (const user of updated) {
|
|
69
|
-
const org = orgs.get(user.orgId) ?? orgs.null;
|
|
70
|
-
|
|
71
|
-
if (user.org !== org) {
|
|
72
|
-
if (user.org) {
|
|
73
|
-
user.org.users.delete(user);
|
|
74
|
-
removeOne(user.org.users.sorted, user);
|
|
75
|
-
}
|
|
76
|
-
user.org = org;
|
|
77
|
-
user.org.users.add(user);
|
|
78
|
-
user.org.users.sorted.push(user);
|
|
79
|
-
|
|
80
|
-
orgsToSortUsers.add(user.org);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (user === currentUser)
|
|
84
|
-
shouldUpdateUser = true;
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
for (const org of orgsToSortUsers)
|
|
89
|
-
org.users.sorted.sort(users.sortCompareFunction!);
|
|
90
|
-
|
|
91
|
-
if (updated.deleted.length)
|
|
92
|
-
for (const org of [ ...orgs.sorted, orgs.null ])
|
|
93
|
-
for (const user of org.users)
|
|
94
|
-
if (!users.has(user._id)) {
|
|
95
|
-
org.users.delete(user);
|
|
96
|
-
removeOne(org.users.sorted, user);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (this.isLoaded) {
|
|
100
|
-
if (shouldUpdateUser)
|
|
101
|
-
this.items.user.emitUpdate();
|
|
102
|
-
this.items.orgs.emitUpdate();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** @this UsersSubscriptionGroup */
|
|
109
|
-
export function handleExtendedUsers(this: UsersSubscriptionGroup, updated: null | SubscriptionMapUpdated<UserExtension>) {
|
|
110
|
-
|
|
111
|
-
const users = this.values.users as UsersExtended;
|
|
112
|
-
|
|
113
|
-
if (updated) {
|
|
114
|
-
const { roles } = this.values;
|
|
115
|
-
|
|
116
|
-
for (const userExtension of updated) {
|
|
117
|
-
const user = users.get(userExtension._id)!;
|
|
118
|
-
|
|
119
|
-
user.roles = roles.getAll(userExtension.roleIds);
|
|
120
|
-
}
|
|
121
|
-
} else
|
|
122
|
-
for (const user of users.sorted)
|
|
123
|
-
delete user.roles;
|
|
124
|
-
|
|
125
|
-
}
|