insite-users-client 2.3.5 → 2.5.0
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/LICENSE +1 -1
- package/README.md +252 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/package.json +47 -33
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,261 @@
|
|
|
1
|
-
#
|
|
1
|
+
# insite-users-client
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/insite-users-client)
|
|
4
|
+
|
|
5
|
+
Client-side library for users, organizations, and roles in inSite. Subscribes to publications over WebSocket and wires data into reactive structures (orgs, users, current user) with automatic cross-linking and sync.
|
|
6
|
+
|
|
7
|
+
Part of [inSite](../../README.md) — requires [insite-ws](../ws/README.md) and [insite-subscriptions-client](../subscriptions-client/README.md).
|
|
2
8
|
|
|
3
9
|
## Installation
|
|
4
10
|
|
|
5
11
|
```sh
|
|
6
|
-
|
|
12
|
+
npm install insite-users-client
|
|
7
13
|
```
|
|
8
14
|
|
|
9
|
-
Or
|
|
15
|
+
Or:
|
|
10
16
|
|
|
11
17
|
```sh
|
|
12
|
-
|
|
18
|
+
bun add insite-users-client
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Setup
|
|
22
|
+
|
|
23
|
+
Before using this package, bind the subscription protocol to your WebSocket instance:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { WS } from "insite-ws/client";
|
|
27
|
+
import { Subscription } from "insite-subscriptions-client";
|
|
28
|
+
|
|
29
|
+
const ws = new WS({ url: "wss://example.com" });
|
|
30
|
+
Subscription.bindTo(ws);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`Subscription.bindTo(ws)` wires subscriptions to the given `WS` instance. Without it, creating a `UsersSubscriptionGroup` will throw.
|
|
34
|
+
|
|
35
|
+
## Overview
|
|
36
|
+
|
|
37
|
+
**UsersSubscriptionGroup** — Main class extending `SubscriptionGroup`. Manages three base subscriptions: `orgs`, `users`, and `user` (current user). Optionally extends to `roles`, `extendedUsers`, and `extendedOrgs` for role-based and hierarchical data.
|
|
38
|
+
|
|
39
|
+
**Types** — `User`, `Org`, `Role`, `CurrentUser`, `Orgs`, `Users`, `Roles` and their extended variants describe the data shapes.
|
|
40
|
+
|
|
41
|
+
## Basic Usage
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { UsersSubscriptionGroup } from "insite-users-client";
|
|
45
|
+
|
|
46
|
+
const target = { orgs: null, users: null, user: null };
|
|
47
|
+
const group = new UsersSubscriptionGroup({ target });
|
|
48
|
+
|
|
49
|
+
group.on("load", (values) => {
|
|
50
|
+
console.log("Loaded:", values.orgs, values.users, values.user);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Optional: load roles and extended org/user data
|
|
54
|
+
group.extend().then(() => {
|
|
55
|
+
console.log("Extended:", target.orgs.sortedHierarchically, target.users);
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Public API
|
|
60
|
+
|
|
61
|
+
### Exports
|
|
62
|
+
|
|
63
|
+
| Export | Description |
|
|
64
|
+
|--------|-------------|
|
|
65
|
+
| `UsersSubscriptionGroup` | Class for managing users-related subscriptions |
|
|
66
|
+
| `CurrentUser`, `NullOrg`, `Org`, `OrgExtended`, `Orgs`, `OrgsExtended` | Types |
|
|
67
|
+
| `Role`, `Roles` | Types |
|
|
68
|
+
| `User`, `UserExtended`, `Users`, `UsersExtended` | Types |
|
|
69
|
+
| `UsersSubscriptionGroupOptions` | Constructor options type |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### UsersSubscriptionGroup
|
|
74
|
+
|
|
75
|
+
Extends `SubscriptionGroup` from [insite-subscriptions-client](../subscriptions-client/README.md). Manages subscriptions to `orgs`, `users`, `user`, and optionally `roles`, `users.extended`, `orgs.extended`.
|
|
76
|
+
|
|
77
|
+
#### Constructor
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
new UsersSubscriptionGroup(options: UsersSubscriptionGroupOptions)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Options:**
|
|
84
|
+
|
|
85
|
+
| Option | Type | Description |
|
|
86
|
+
|--------|------|-------------|
|
|
87
|
+
| `values` | `{ orgs?, users?, user? }` | Pre-created subscription containers (defaults to new maps/object) |
|
|
88
|
+
| `target` | `object` | Object to bind values to (`target.orgs`, `target.users`, `target.user`) |
|
|
89
|
+
| `debounce` | `number` | Debounce ms for `update` events (default: 8) |
|
|
90
|
+
| `immediately` | `boolean` | Subscribe immediately on attach (default `true`) |
|
|
91
|
+
|
|
92
|
+
#### Properties
|
|
93
|
+
|
|
94
|
+
| Property | Type | Description |
|
|
95
|
+
|----------|------|-------------|
|
|
96
|
+
| `values` | `{ orgs, users, user }` | Subscription values (maps/object) |
|
|
97
|
+
| `items` | `Record<string, SubscriptionGroupItem>` | Per-subscription items |
|
|
98
|
+
| `isLoaded` | `boolean` | `true` when all base subscriptions loaded |
|
|
99
|
+
| `isInited` | `boolean` | `true` when all subscriptions inited |
|
|
100
|
+
| `isExtended` | `boolean \| null` | `false` = base only, `null` = extending, `true` = extended |
|
|
101
|
+
| `target` | `object \| undefined` | Bound target object |
|
|
102
|
+
| `emitUpdate` | `() => void` | Emits debounced `update` event |
|
|
103
|
+
|
|
104
|
+
#### Methods
|
|
105
|
+
|
|
106
|
+
| Method | Description |
|
|
107
|
+
|--------|-------------|
|
|
108
|
+
| `extend()` | Attaches `roles`, `extendedUsers`, `extendedOrgs`. Returns `Promise<void>` or `undefined` if already extended/extending |
|
|
109
|
+
| `unextend()` | Detaches extended subscriptions |
|
|
110
|
+
| `loaded()` | Returns `StatefulPromise` resolving when all items loaded |
|
|
111
|
+
| `inited()` | Returns `StatefulPromise` resolving when all items inited |
|
|
112
|
+
| `unloaded()` | Returns `StatefulPromise` resolving when all items unloaded |
|
|
113
|
+
| `subscribe()` | Subscribes all items |
|
|
114
|
+
| `unsubscribe()` | Unsubscribes all items |
|
|
115
|
+
| `attach(definitions, shouldReload?, immediately?)` | Attach definitions (inherited) |
|
|
116
|
+
| `detach(names, shouldUpdate?)` | Detach subscriptions by name (inherited) |
|
|
117
|
+
| `redefine(definitions)` | Replace definitions (inherited) |
|
|
118
|
+
| `applyOptions({ target?, debounceLimit? })` | Update target or debounce (inherited) |
|
|
119
|
+
|
|
120
|
+
#### Events
|
|
121
|
+
|
|
122
|
+
| Event | Payload | Description |
|
|
123
|
+
|-------|---------|-------------|
|
|
124
|
+
| `load` | `values` | All base subscriptions loaded |
|
|
125
|
+
| `init` | `values` | All subscriptions inited |
|
|
126
|
+
| `unload` | `values` | All subscriptions unloaded |
|
|
127
|
+
| `update` | `values` | Data changed (debounced) |
|
|
128
|
+
| `update.{name}` | — | Specific subscription updated |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### Types
|
|
133
|
+
|
|
134
|
+
#### User
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
type User = {
|
|
138
|
+
_id: string;
|
|
139
|
+
isUser: true;
|
|
140
|
+
email: string;
|
|
141
|
+
name: { first: string; middle: string; last: string };
|
|
142
|
+
orgId: string;
|
|
143
|
+
job: string;
|
|
144
|
+
initials: string;
|
|
145
|
+
displayLabel: string;
|
|
146
|
+
avatarUrl: string;
|
|
147
|
+
isOnline: boolean;
|
|
148
|
+
org: NullOrg | Org;
|
|
149
|
+
};
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### UserExtended
|
|
153
|
+
|
|
154
|
+
`User` with optional `roles?: Role[]`.
|
|
155
|
+
|
|
156
|
+
#### CurrentUser\<AS\>
|
|
157
|
+
|
|
158
|
+
`UserExtended` plus:
|
|
159
|
+
|
|
160
|
+
| Field | Type | Description |
|
|
161
|
+
|-------|------|-------------|
|
|
162
|
+
| `abilities` | `Abilities<AS>` | Typed abilities from schema (from `insite-common`) |
|
|
163
|
+
| `sessionId` | `string \| undefined` | Session identifier |
|
|
164
|
+
| `slaveIds` | `string[]` | IDs of subordinate orgs/users |
|
|
165
|
+
| `slavesSnapshot` | `string` | Cached join of `slaveIds` |
|
|
166
|
+
| `slaves` | `(Org \| User)[]` | Resolved slave entities |
|
|
167
|
+
| `slaveUsers` | `User[]` | Slaves that are users |
|
|
168
|
+
| `slaveOrgs` | `Org[]` | Slaves that are orgs |
|
|
169
|
+
|
|
170
|
+
`AS` extends `AbilitiesSchema` from [insite-common](../common/README.md); omit for default schema.
|
|
171
|
+
|
|
172
|
+
#### Org
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
type Org = {
|
|
176
|
+
_id: string;
|
|
177
|
+
title: string;
|
|
178
|
+
initials: string;
|
|
179
|
+
displayLabel: string;
|
|
180
|
+
isOrg: true;
|
|
181
|
+
users: Set<User> & { sorted: User[] };
|
|
182
|
+
};
|
|
13
183
|
```
|
|
184
|
+
|
|
185
|
+
#### NullOrg
|
|
186
|
+
|
|
187
|
+
`Org` with `_id: null`. Used for users without an organization (`orgs.null`).
|
|
188
|
+
|
|
189
|
+
#### OrgExtended
|
|
190
|
+
|
|
191
|
+
`Org` plus optional: `owners?: (OrgExtended | User)[]`, `slaveOrgs?: OrgExtended[]`, `note?: string`, `_l?: number`.
|
|
192
|
+
|
|
193
|
+
#### Role
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
type Role = {
|
|
197
|
+
_id: string;
|
|
198
|
+
ownInvolves: Role[];
|
|
199
|
+
involves: Role[];
|
|
200
|
+
_l: number;
|
|
201
|
+
};
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### Orgs
|
|
205
|
+
|
|
206
|
+
`SubscriptionMapWithSubscription<Org>` plus `null: NullOrg`. Keys are org IDs; `orgs.null` holds users without org.
|
|
207
|
+
|
|
208
|
+
#### OrgsExtended
|
|
209
|
+
|
|
210
|
+
`Orgs` with `OrgExtended` items, plus `sortedHierarchically?: OrgExtended[]`.
|
|
211
|
+
|
|
212
|
+
#### Users
|
|
213
|
+
|
|
214
|
+
`SubscriptionMapWithSubscription<User>`. Keys are user IDs.
|
|
215
|
+
|
|
216
|
+
#### UsersExtended
|
|
217
|
+
|
|
218
|
+
`SubscriptionMapWithSubscription<UserExtended>`.
|
|
219
|
+
|
|
220
|
+
#### Roles
|
|
221
|
+
|
|
222
|
+
`SubscriptionMapWithSubscription<Role>`.
|
|
223
|
+
|
|
224
|
+
#### UsersSubscriptionGroupOptions
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
type UsersSubscriptionGroupOptions = SubscriptionGroupOptions & {
|
|
228
|
+
values?: {
|
|
229
|
+
orgs?: SubscriptionMapWithSubscription;
|
|
230
|
+
users?: SubscriptionMapWithSubscription;
|
|
231
|
+
user?: SubscriptionObjectWithSubscription;
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Extends `SubscriptionGroupOptions` (`target`, `debounce`, `immediately`) from [insite-subscriptions-client](../subscriptions-client/README.md).
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Subscriptions
|
|
241
|
+
|
|
242
|
+
| Name | Publication | Type | Description |
|
|
243
|
+
|------|--------------|------|-------------|
|
|
244
|
+
| `orgs` | `orgs` | map | Organizations |
|
|
245
|
+
| `users` | `users` | map | Users |
|
|
246
|
+
| `user` | `user` | object | Current user (params: `[true]`) |
|
|
247
|
+
| `roles` | `roles` | map | Roles (extended only) |
|
|
248
|
+
| `extendedUsers` | `users.extended` | map | User extensions with roles (extended only) |
|
|
249
|
+
| `extendedOrgs` | `orgs.extended` | map | Org extensions with owners, slaveOrgs (extended only) |
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Related
|
|
254
|
+
|
|
255
|
+
- [insite-ws](../ws/README.md), [insite-subscriptions-client](../subscriptions-client/README.md), [insite-common](../common/README.md)
|
|
256
|
+
- [insite-users-server-ws](../users-server-ws/README.md) — server counterpart
|
|
257
|
+
- [insite-client](../client/README.md) — includes UsersSubscriptionGroup
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var S=Object.defineProperty;var v=(e,r,s)=>r in e?S(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var u=(e,r,s)=>v(e,typeof r!="symbol"?r+"":r,s);import{SubscriptionGroup as _}from"insite-subscriptions-client";import{getAll as y}from"@nesvet/n";function a(e){e.null={_id:null,title:"",initials:"\u2014",displayLabel:"\u2014",isOrg:!0,users:Object.assign(new Set,{sorted:[]})}}function c(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 f(e){let r=this.values.orgs;if(e){let{users:s,extendedOrgs:o}=this.values;for(let l of e){let i=r.get(l._id);i.owners=l.owners.map(d=>s.get(d)||r.get(d)),i.slaveOrgs=y(r,l.slaveOrgs,!0),i.note=l.note,i._l=0}let n=[];for(let l of o.sorted){let i=r.get(l._id);for(let d of i.slaveOrgs)d._l=i._l+1;n.push(i)}r.sortedHierarchically=n,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 g}from"@nesvet/n";function h(e){if(e){let r=this.values.roles;for(let s of e)s.ownInvolves=g(r,s.ownInvolves,!0),s.involves=g(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 U(e){if(e){let r=e.slaveIds.join(",");if(e.slavesSnapshot!==r){e.slavesSnapshot=r;let s=[],o=[],n=[],{users:l,orgs:i}=this.values;for(let d of e.slaveIds){let t=l.get(d);t?(s.push(t),o.push(t)):(t=i.get(d),t&&(s.push(t),n.push(t)))}e.slaves=s,e.slaveUsers=o,e.slaveOrgs=n}}}import{getAll as E,removeOne as m}from"@nesvet/n";function x(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 n=e.findIndex(t=>t._id===s._id);~n&&(e[n]=s),~e.added.findIndex(t=>t._id===s._id)&&(e.added[n]=s);for(let t of e.added)t.isUser=!0;let i,d=new Set;for(let t of e){let p=o.get(t.orgId)??o.null;t.org!==p&&(t.org&&(t.org.users.delete(t),m(t.org.users.sorted,t)),t.org=p,t.org.users.add(t),t.org.users.sorted.push(t)),d.add(t.org),t===s&&(i=!0)}for(let t of d)t.users.sorted.sort(r.sortCompareFunction);if(e.deleted.length)for(let t of[...o.sorted,o.null])for(let p of t.users)r.has(p._id)||(t.users.delete(p),m(t.users.sorted,p));this.isLoaded&&(i&&this.items.user.emitUpdate(),this.items.orgs.emitUpdate())}}function b(e){let r=this.values.users;if(e){let s=this.values.roles;for(let o of e){let n=r.get(o._id);n.roles=E(s,o.roleIds,!0)}}else for(let s of r.sorted)delete s.roles}var O=class extends _{constructor({values:s,...o}){super([["orgs",s?.orgs??"map",c,a],["users",s?.users??"map",x],["user",s?.user??[!0],U]],o);u(this,"isExtended",!1)}extend(){if(this.isExtended===!1)return this.isExtended=null,this.attach([["roles","map",h],["extendedUsers","map","users.extended",b,!0],["extendedOrgs","map","orgs.extended",f,!0]]).then(()=>{this.isExtended=!0})}unextend(){this.isExtended&&(this.isExtended=!1,this.detach(["roles","extendedUsers","extendedOrgs"]))}};export{O as UsersSubscriptionGroup};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/UsersSubscriptionGroup.ts", "
|
|
4
|
-
"sourcesContent": ["import {\n\tSubscriptionGroup,\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\";\nimport type { UsersSubscriptionGroupOptions } from \"./types\";\n\n\nexport class UsersSubscriptionGroup extends SubscriptionGroup<[\n\t[ \"orgs\", SubscriptionMapWithSubscription | \"map\", typeof handleOrgs, typeof handleOrgsBeforeSubscribe ],\n\t[ \"users\", SubscriptionMapWithSubscription | \"map\", typeof handleUsers ],\n\t[ \"user\", SubscriptionObjectWithSubscription | [ true ], typeof handleUser ]\n] | [\n\t[ \"roles\", \"map\", typeof handleRoles ],\n\t[ \"extendedUsers\", \"map\", \"users.extended\", typeof handleExtendedUsers, true ],\n\t[ \"extendedOrgs\", \"map\", \"orgs.extended\", typeof handleExtendedOrgs, true ]\n]> {\n\tconstructor({ values, ...options }: UsersSubscriptionGroupOptions) {\n\t\tsuper([\n\t\t\t[ \"orgs\", values?.orgs ?? \"map\", handleOrgs, handleOrgsBeforeSubscribe ],\n\t\t\t[ \"users\", values?.users ?? \"map\", handleUsers ],\n\t\t\t[ \"user\", values?.user ?? [ true ], handleUser ]\n\t\t], options);\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([\n\t\t\t\t[ \"roles\", \"map\", handleRoles ],\n\t\t\t\t[ \"extendedUsers\", \"map\", \"users.extended\", handleExtendedUsers, true ],\n\t\t\t\t[ \"extendedOrgs\", \"map\", \"orgs.extended\", handleExtendedOrgs, true ]\n\t\t\t]).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}\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}\n", "export function noop() { /**/ }\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype Value<T> = PromiseLike<T> | T;\ntype Resolve<T> = (value: Value<T>) => void;\ntype Reject = (reason?: any) => void;\n\ntype Options = {\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n};\n\nconst nativesMap = new WeakMap<StatefulPromise<any>, { resolve: Resolve<any>; reject: Reject }>();\n\n\nexport class StatefulPromise<T> extends Promise<T> {\n\tconstructor(\n\t\texecutor?: (resolve: Resolve<T>, reject: Reject) => void,\n\t\toptions?: Options\n\t) {\n\t\tlet nativeResolve: Resolve<T>;\n\t\tlet nativeReject: Reject;\n\t\t\n\t\tsuper((resolve, reject) => {\n\t\t\tnativeResolve = resolve;\n\t\t\tnativeReject = reject;\n\t\t\t\n\t\t});\n\t\t\n\t\tnativesMap.set(this, { resolve: nativeResolve!, reject: nativeReject! });\n\t\t\n\t\tif (options?.signal)\n\t\t\tif (options.signal.aborted)\n\t\t\t\tthis.reject(new DOMException(\"Aborted\", \"AbortError\"));\n\t\t\telse {\n\t\t\t\tconst abortListener = () => this.reject(new DOMException(\"Aborted\", \"AbortError\"));\n\t\t\t\t\n\t\t\t\toptions.signal.addEventListener(\"abort\", abortListener);\n\t\t\t\t\n\t\t\t\tthis.finally(() => options.signal?.removeEventListener(\"abort\", abortListener));\n\t\t\t}\n\t\t\n\t\tif (typeof options?.timeout === \"number\" && Number.isFinite(options.timeout)) {\n\t\t\tconst timeout = setTimeout(() => this.reject(new DOMException(\"Timeout exceeded\", \"TimeoutError\")), options.timeout);\n\t\t\t\n\t\t\tthis.finally(() => clearTimeout(timeout));\n\t\t}\n\t\t\n\t\texecutor?.(this.resolve, this.reject);\n\t\t\n\t}\n\t\n\tisPending = true;\n\tisFulfilled = false;\n\tisRejected = false;\n\t\n\tstate: \"fulfilled\" | \"pending\" | \"rejected\" = \"pending\";\n\t\n\tresult?: T | unknown;\n\t\n\treadonly resolve = (value: Value<T>) => {\n\t\t\n\t\tif (this.isPending) {\n\t\t\tthis.isPending = false;\n\t\t\tthis.isFulfilled = true;\n\t\t\tthis.state = \"fulfilled\";\n\t\t\tthis.result = value;\n\t\t\t\n\t\t\tconst native = nativesMap.get(this);\n\t\t\t\n\t\t\tif (native) {\n\t\t\t\tnative.resolve.call(this, value);\n\t\t\t\tnativesMap.delete(this);\n\t\t\t}\n\t\t}\n\t\t\n\t};\n\t\n\treadonly reject = (reason?: any) => {\n\t\t\n\t\tif (this.isPending) {\n\t\t\tthis.isPending = false;\n\t\t\tthis.isRejected = true;\n\t\t\tthis.state = \"rejected\";\n\t\t\tthis.result = reason;\n\t\t\t\n\t\t\tconst native = nativesMap.get(this);\n\t\t\t\n\t\t\tif (native) {\n\t\t\t\tnative.reject.call(this, reason);\n\t\t\t\tnativesMap.delete(this);\n\t\t\t}\n\t\t}\n\t\t\n\t};\n\t\n\t\n\tstatic resolved<U>(value: U): StatefulPromise<U> {\n\t\treturn new StatefulPromise<U>(resolve => resolve(value));\n\t}\n\t\n\tstatic rejected(reason: unknown): StatefulPromise<never> {\n\t\treturn new StatefulPromise((_, reject) => reject(reason));\n\t}\n\t\n}\n", "import { noop } from \"./noop.js\";\nimport { StatefulPromise } from \"./StatefulPromise.js\";\n\n\ntype Callback = (...args: any[]) => unknown;// eslint-disable-line @typescript-eslint/no-explicit-any\ntype FunctionOrBoolean = (() => unknown) | boolean;\ntype Options = { leading?: FunctionOrBoolean; maxWait?: number; trailing?: FunctionOrBoolean };\n\ntype DebouncedFunction<C extends Callback> = {\n\t(this: ThisParameterType<C>, ...args: Parameters<C>): Promise<Awaited<ReturnType<C>>>;\n};\n\nexport type Debounced<C extends Callback, R extends ReturnType<C>> = DebouncedFunction<C> & {\n\tcallback: C;\n\tpromise: StatefulPromise<R>;\n\tresolve: (value: R) => void;\n\treject: (reason?: unknown) => void;\n\trun(): Promise<R>;\n\tclear(shouldRun?: boolean): Promise<void>;\n};\n\n\nexport function debounce<C extends Callback, R extends ReturnType<C>>(callback: C, limit = 0, options: Options = {}) {\n\tlet { leading = false, trailing = true } = options;\n\tconst { maxWait = Infinity } = options;\n\t\n\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\tlet maxWaitTimeout: ReturnType<typeof setTimeout> | undefined;\n\tlet end: number | undefined;\n\tlet context: ThisParameterType<C>;\n\tlet args: unknown[];\n\tlet initial: FunctionOrBoolean;\n\tlet final: FunctionOrBoolean;\n\tlet result: R;\n\t\n\tconst expired = async () => {\n\t\t\n\t\tconst n = Date.now();\n\t\t\n\t\tif (n >= end!) {\n\t\t\ttimeout = undefined;\n\t\t\tend = undefined;\n\t\t\t\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\tmaxWaitTimeout = undefined;\n\t\t\t\n\t\t\tif (typeof final == \"function\")\n\t\t\t\tawait final();\n\t\t\t\n\t\t\tdebounced.resolve(result);\n\t\t\t\n\t\t\tinitial = leading;\n\t\t} else {\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = setTimeout(expired, end! - n);\n\t\t}\n\t\t\n\t};\n\t\n\tconst maxWaitExpired = Number.isFinite(maxWait) ? () => {\n\t\t\n\t\tif (final === run)\n\t\t\tfinal = false;\n\t\t\n\t\trun();\n\t\t\n\t\tmaxWaitTimeout = setTimeout(maxWaitExpired as TimerHandler, maxWait);\n\t\t\n\t} : null;\n\t\n\tasync function run() {\n\t\ttry {\n\t\t\tresult = await callback.apply(context, args) as R;\n\t\t\t\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tdebounced.reject(error);\n\t\t\t\n\t\t\tthrow error;\n\t\t}\n\t}\n\t\n\tif (leading && typeof leading == \"boolean\")\n\t\tleading = run;\n\tinitial = leading;\n\t\n\tif (trailing && typeof trailing == \"boolean\")\n\t\ttrailing = run;\n\tfinal = trailing;\n\t\n\tconst debounced: Debounced<C, R> = Object.assign(function (..._args) {\n\t\targs = _args;\n\t\tcontext = this;// eslint-disable-line no-invalid-this\n\t\t\n\t\tend = Date.now() + limit;\n\t\tfinal = trailing;\n\t\t\n\t\tif (!debounced.promise.isPending)\n\t\t\tdebounced.promise = new StatefulPromise<R>((resolve, reject) => {\n\t\t\t\tdebounced.resolve = resolve;\n\t\t\t\tdebounced.reject = reject;\n\t\t\t\t\n\t\t\t\tif (typeof initial == \"function\") {\n\t\t\t\t\tinitial();\n\t\t\t\t\t\n\t\t\t\t\tinitial = false;\n\t\t\t\t\t\n\t\t\t\t\tif (final === run)\n\t\t\t\t\t\tfinal = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (!timeout) {\n\t\t\t\t\ttimeout = setTimeout(expired, limit);\n\t\t\t\t\t\n\t\t\t\t\tif (maxWaitExpired)\n\t\t\t\t\t\tmaxWaitTimeout = setTimeout(maxWaitExpired, maxWait);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t});\n\t\t\n\t\treturn debounced.promise;\n\t} as DebouncedFunction<C>, {\n\t\tcallback,\n\t\tpromise: StatefulPromise.resolved(undefined as unknown as R),\n\t\tresolve: noop,\n\t\treject: noop,\n\t\trun,\n\t\tclear: async (shouldRun?: boolean) => {\n\t\t\t\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = undefined;\n\t\t\t\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\tmaxWaitTimeout = undefined;\n\t\t\t\n\t\t\tdebounced.resolve(shouldRun ? await run() : result);\n\t\t\t\n\t\t}\n\t});\n\t\n\treturn debounced;\n}\n\n\ndebounce.noop = Object.assign(() => { /**/ }, {\n\tcallback: noop,\n\tpromise: StatefulPromise.resolved(undefined), // eslint-disable-line unicorn/no-useless-undefined\n\tresolve: noop,\n\treject: noop,\n\trun: noop,\n\tclear: noop\n}) as Debounced<() => void, void>;\n\n\nexport function throttle(callback: Callback, limit?: number, options?: Options) {\n\treturn debounce(callback, limit, {\n\t\tmaxWait: limit,\n\t\tleading: true,\n\t\ttrailing: true,\n\t\t...options\n\t});\n}\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport function getAll<V>(map: Map<any, V>, keys: any[], onlyExisting: true): V[];\nexport function getAll<V>(map: Map<any, V>, keys: any[], onlyExisting?: false): (V | undefined)[];\nexport function getAll<V>(map: Map<any, V>, keys: any[], onlyExisting = false) {\n\t\n\tconst items = [];\n\t\n\tif (onlyExisting)\n\t\tfor (const key of keys) {\n\t\t\tconst item = map.get(key);\n\t\t\tif (item !== undefined)\n\t\t\t\titems.push(item);\n\t\t}\n\telse\n\t\tfor (const key of keys)\n\t\t\titems.push(map.get(key));\n\t\n\treturn items;\n}\n", "export function howmuch(number: [] | number, one: string, two: string, five: boolean | string, shouldPrintNumber = true) {\n\tif (Array.isArray(number))\n\t\tnumber = number.length;\n\t\n\tif (typeof five != \"string\") {\n\t\tshouldPrintNumber = five ?? true;\n\t\tfive = two;\n\t}\n\t\n\t\n\treturn (shouldPrintNumber ? `${number}\u00A0` : \"\") + howmuch.raw(number, one, two, five);\n}\n\nhowmuch.raw = (number: number, one: string, two: string, five = two) => {\n\tnumber = Math.abs(number);\n\tconst u = number % 10;\n\tconst d = number % 100;\n\t\n\treturn (\n\t\t(u === 1 && d !== 11) ?\n\t\t\tone :\n\t\t\t((u >= 2 && u <= 4) && !(d >= 12 && d <= 15)) ?\n\t\t\t\ttwo :\n\t\t\t\tfive\n\t);\n};\n", "export function removeOne<T>(array: T[], item: T): boolean {\n\tconst i = array.indexOf(item);\n\tif (i > -1) {\n\t\tarray.splice(i, 1);\n\t\t\n\t\treturn true;\n\t}\n\t\n\treturn false;\n}\n", "import { getAll } from \"@nesvet/n\";\nimport type { SubscriptionMapUpdated } from \"insite-subscriptions-client\";\nimport type {\n\tOrg,\n\tOrgExtension,\n\tOrgs,\n\tOrgsExtended,\n\tUser\n} from \"./types\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\nexport function handleOrgsBeforeSubscribe(orgs: Orgs) {\n\torgs.null = {\n\t\t_id: null,\n\t\ttitle: \"\",\n\t\tinitials: \"\u2014\",\n\t\tdisplayLabel: \"\u2014\",\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: SubscriptionMapUpdated<Org> | null) {\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: SubscriptionMapUpdated<OrgExtension> | null) {\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 } from \"insite-subscriptions-client\";\nimport type { Role, Roles } from \"./types\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\n/** @this UsersSubscriptionGroup */\nexport function handleRoles(this: UsersSubscriptionGroup, updated: SubscriptionMapUpdated<Role> | null) {\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 { CurrentUser } from \"./types\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\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 { getAll, removeOne } from \"@nesvet/n\";\nimport type { SubscriptionMapUpdated } from \"insite-subscriptions-client\";\nimport type {\n\tCurrentUser,\n\tNullOrg,\n\tOrg,\n\tOrgs,\n\tRoles,\n\tUser,\n\tUserExtension,\n\tUsers,\n\tUsersExtended\n} from \"./types\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\n/** @this UsersSubscriptionGroup */\nexport function handleUsers(this: UsersSubscriptionGroup, updated: SubscriptionMapUpdated<User> | null) {\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}\n\t\t\t\n\t\t\torgsToSortUsers.add(user.org);\n\t\t\t\n\t\t\tif (user === currentUser)\n\t\t\t\tshouldUpdateUser = true;\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: SubscriptionMapUpdated<UserExtension> | null) {\n\t\n\tconst users = this.values.users as UsersExtended;\n\t\n\tif (updated) {\n\t\tconst roles = this.values.roles as Roles;\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 = getAll(roles, userExtension.roleIds, true);\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,MAGM,
|
|
6
|
-
"names": ["SubscriptionGroup", "
|
|
3
|
+
"sources": ["../src/UsersSubscriptionGroup.ts", "../src/orgs.ts", "../src/roles.ts", "../src/user.ts", "../src/users.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n\tSubscriptionGroup,\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\";\nimport type { UsersSubscriptionGroupOptions } from \"./types\";\n\n\nexport class UsersSubscriptionGroup extends SubscriptionGroup<[\n\t[ \"orgs\", SubscriptionMapWithSubscription | \"map\", typeof handleOrgs, typeof handleOrgsBeforeSubscribe ],\n\t[ \"users\", SubscriptionMapWithSubscription | \"map\", typeof handleUsers ],\n\t[ \"user\", SubscriptionObjectWithSubscription | [ true ], typeof handleUser ]\n] | [\n\t[ \"roles\", \"map\", typeof handleRoles ],\n\t[ \"extendedUsers\", \"map\", \"users.extended\", typeof handleExtendedUsers, true ],\n\t[ \"extendedOrgs\", \"map\", \"orgs.extended\", typeof handleExtendedOrgs, true ]\n]> {\n\tconstructor({ values, ...options }: UsersSubscriptionGroupOptions) {\n\t\tsuper([\n\t\t\t[ \"orgs\", values?.orgs ?? \"map\", handleOrgs, handleOrgsBeforeSubscribe ],\n\t\t\t[ \"users\", values?.users ?? \"map\", handleUsers ],\n\t\t\t[ \"user\", values?.user ?? [ true ], handleUser ]\n\t\t], options);\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([\n\t\t\t\t[ \"roles\", \"map\", handleRoles ],\n\t\t\t\t[ \"extendedUsers\", \"map\", \"users.extended\", handleExtendedUsers, true ],\n\t\t\t\t[ \"extendedOrgs\", \"map\", \"orgs.extended\", handleExtendedOrgs, true ]\n\t\t\t]).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}\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}\n", "import { getAll } from \"@nesvet/n\";\nimport type { SubscriptionMapUpdated } from \"insite-subscriptions-client\";\nimport type {\n\tOrg,\n\tOrgExtension,\n\tOrgs,\n\tOrgsExtended,\n\tUser\n} from \"./types\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\nexport function handleOrgsBeforeSubscribe(orgs: Orgs) {\n\torgs.null = {\n\t\t_id: null,\n\t\ttitle: \"\",\n\t\tinitials: \"\u2014\",\n\t\tdisplayLabel: \"\u2014\",\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: SubscriptionMapUpdated<Org> | null) {\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: SubscriptionMapUpdated<OrgExtension> | null) {\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 } from \"insite-subscriptions-client\";\nimport type { Role, Roles } from \"./types\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\n/** @this UsersSubscriptionGroup */\nexport function handleRoles(this: UsersSubscriptionGroup, updated: SubscriptionMapUpdated<Role> | null) {\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 { CurrentUser } from \"./types\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\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 { getAll, removeOne } from \"@nesvet/n\";\nimport type { SubscriptionMapUpdated } from \"insite-subscriptions-client\";\nimport type {\n\tCurrentUser,\n\tNullOrg,\n\tOrg,\n\tOrgs,\n\tRoles,\n\tUser,\n\tUserExtension,\n\tUsers,\n\tUsersExtended\n} from \"./types\";\nimport type { UsersSubscriptionGroup } from \"./UsersSubscriptionGroup\";\n\n\n/** @this UsersSubscriptionGroup */\nexport function handleUsers(this: UsersSubscriptionGroup, updated: SubscriptionMapUpdated<User> | null) {\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}\n\t\t\t\n\t\t\torgsToSortUsers.add(user.org);\n\t\t\t\n\t\t\tif (user === currentUser)\n\t\t\t\tshouldUpdateUser = true;\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: SubscriptionMapUpdated<UserExtension> | null) {\n\t\n\tconst users = this.values.users as UsersExtended;\n\t\n\tif (updated) {\n\t\tconst roles = this.values.roles as Roles;\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 = getAll(roles, userExtension.roleIds, true);\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,MAGM,8BCJP,OAAS,UAAAC,MAAc,YAYhB,SAASC,EAA0BC,EAAY,CACrDA,EAAK,KAAO,CACX,IAAK,KACL,MAAO,GACP,SAAU,SACV,aAAc,SACd,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,MAAM,OAAO,OAAS,CAG9C,CAGO,SAASC,EAAiDF,EAAsD,CAEtH,IAAMF,EAAO,KAAK,OAAO,KAEzB,GAAIE,EAAS,CACZ,GAAM,CAAE,MAAAG,EAAO,aAAAC,CAAa,EAAI,KAAK,OAErC,QAAWC,KAAgBL,EAAS,CACnC,IAAMC,EAAMH,EAAK,IAAIO,EAAa,GAAG,EAErCJ,EAAI,OAASI,EAAa,OAAO,IAAIC,GAAOH,EAAM,IAAIG,CAAG,GAAKR,EAAK,IAAIQ,CAAG,CAAC,EAC3EL,EAAI,UAAYL,EAAOE,EAAMO,EAAa,UAAW,EAAI,EACzDJ,EAAI,KAAOI,EAAa,KACxBJ,EAAI,GAAK,CACV,CAEA,IAAMM,EAAuB,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AEA,UAAW,CAEN,KAAK,aACR,KAAK,WAAa,GAElB,KAAK,OAAO,CAAE,QAAS,gBAAiB,cAAe,CAAC,EAG1D,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", "getAll", "removeOne", "handleUsers", "updated", "users", "currentUser", "orgs", "user", "updatedUserIndex", "shouldUpdateUser", "orgsToSortUsers", "org", "handleExtendedUsers", "roles", "userExtension", "UsersSubscriptionGroup", "SubscriptionGroup", "values", "options", "handleOrgs", "handleOrgsBeforeSubscribe", "handleUsers", "handleUser", "__publicField", "handleRoles", "handleExtendedUsers", "handleExtendedOrgs"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,35 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
2
|
+
"name": "insite-users-client",
|
|
3
|
+
"version": "2.5.0",
|
|
4
|
+
"description": "Client-side users API for inSite",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"insite",
|
|
7
|
+
"users",
|
|
8
|
+
"client",
|
|
9
|
+
"auth"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/nesvet/insite#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/nesvet/insite/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/nesvet/insite.git",
|
|
18
|
+
"directory": "packages/users-client"
|
|
19
|
+
},
|
|
20
|
+
"funding": {
|
|
21
|
+
"type": "patreon",
|
|
22
|
+
"url": "https://www.patreon.com/nesvet"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "bun .conveyer.js",
|
|
36
|
+
"postbuild": "tsc -p .",
|
|
37
|
+
"clean": "rm -rf dist",
|
|
38
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
39
|
+
"typecheck": "tsc --noEmit"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@nesvet/n": "^1.2.1",
|
|
43
|
+
"insite-common": "^2.5.0",
|
|
44
|
+
"insite-subscriptions-client": "^2.5.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20.0.0"
|
|
48
|
+
}
|
|
35
49
|
}
|