h1v3 0.2.1 → 0.3.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "h1v3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./src/index.js",
|
|
10
10
|
"./schema": "./src/schema.js",
|
|
11
|
-
"./client": "./src/client/index.js"
|
|
11
|
+
"./client": "./src/client/index.js",
|
|
12
|
+
"./membership": "./src/membership/index.js"
|
|
12
13
|
},
|
|
13
14
|
"bin": {
|
|
14
15
|
"eventstore": "./src/exec-eventstore.js"
|
package/src/exec-eventstore.js
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ifUserIdExists } from "h1v3";
|
|
2
|
+
|
|
3
|
+
const membershipStorePath = rootPath => `${rootPath}/teams/$tid/membership`;
|
|
4
|
+
|
|
5
|
+
export const ifMyTeam = rootPath =>
|
|
6
|
+
ifUserIdExists(`${membershipStorePath(rootPath)}/projections/members`);
|
|
7
|
+
|
|
8
|
+
export const ifAdminInThisTeam = rootPath =>
|
|
9
|
+
ifUserIdExists(`${membershipStorePath(rootPath)}/projections/details/admins`);
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const membershipDetails = {
|
|
13
|
+
|
|
14
|
+
"BECAME_MEMBER": (view, { payload }) => {
|
|
15
|
+
|
|
16
|
+
const found = purgeUser(view, payload);
|
|
17
|
+
view.members = { ...view.members, [payload.uid]: { name: payload.name || found?.name || "" }};
|
|
18
|
+
return view;
|
|
19
|
+
|
|
20
|
+
},
|
|
21
|
+
"BECAME_ADMIN": (view, { payload }) => {
|
|
22
|
+
|
|
23
|
+
const found = purgeUser(view, payload);
|
|
24
|
+
view.admins = { ...view.admins, [payload.uid]: { name: payload.name || found?.name || "" }};
|
|
25
|
+
return view;
|
|
26
|
+
|
|
27
|
+
},
|
|
28
|
+
"LEFT_TEAM": (view, { payload }) => {
|
|
29
|
+
|
|
30
|
+
purgeUser(view, payload);
|
|
31
|
+
return view;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const members = {
|
|
38
|
+
|
|
39
|
+
"BECAME_MEMBER": (view, { payload }) => {
|
|
40
|
+
|
|
41
|
+
if (!payload?.uid) return view;
|
|
42
|
+
view[payload.uid] = true;
|
|
43
|
+
return view;
|
|
44
|
+
|
|
45
|
+
},
|
|
46
|
+
"BECAME_ADMIN": (view, { payload }) => {
|
|
47
|
+
|
|
48
|
+
if (!payload?.uid) return view;
|
|
49
|
+
view[payload.uid] = true;
|
|
50
|
+
return view;
|
|
51
|
+
|
|
52
|
+
},
|
|
53
|
+
"LEFT_TEAM": (view, { payload }) => {
|
|
54
|
+
|
|
55
|
+
if (!payload?.uid) return view;
|
|
56
|
+
delete view[payload.uid];
|
|
57
|
+
return view;
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function purgeUser(view, { uid }) {
|
|
64
|
+
|
|
65
|
+
let found = view.members?.[uid] || view.admins?.[uid] || view.owners?.[uid];
|
|
66
|
+
if (view.members && (uid in view.members))
|
|
67
|
+
delete view.members[uid];
|
|
68
|
+
if (view.admins && (uid in view.admins))
|
|
69
|
+
delete view.admins[uid];
|
|
70
|
+
if (view.owners && (uid in view.owners))
|
|
71
|
+
delete view.owners[uid];
|
|
72
|
+
return found;
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function membershipStore(rootPath) {
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
ref: membershipStorePath(rootPath),
|
|
80
|
+
projections: {
|
|
81
|
+
"details": membershipDetails,
|
|
82
|
+
members
|
|
83
|
+
},
|
|
84
|
+
write: ifAdminInThisTeam,
|
|
85
|
+
read: ifAdminInThisTeam
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { deleteByPath, filterBySchema, schemaAllowsPath } from "h1v3/schema";
|
|
2
|
+
|
|
3
|
+
const current = schema => ({
|
|
4
|
+
|
|
5
|
+
"DETAILS_UPDATED": (view, { payload }) => {
|
|
6
|
+
|
|
7
|
+
if (!payload || typeof payload !== "object") return view;
|
|
8
|
+
view = Object.assign(view, filterBySchema(schema, payload));
|
|
9
|
+
if(payload?.unset)
|
|
10
|
+
payload.unset.forEach(path => {
|
|
11
|
+
|
|
12
|
+
if (schemaAllowsPath(schema, path))
|
|
13
|
+
deleteByPath(view, path);
|
|
14
|
+
else
|
|
15
|
+
console.warn("Unset path not allowed by schema", path);
|
|
16
|
+
|
|
17
|
+
});
|
|
18
|
+
return view;
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const ifMe = "$uid == auth.uid";
|
|
25
|
+
|
|
26
|
+
export function userProfileStore(rootPath, schema) {
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
|
|
30
|
+
ref: `${rootPath}/users/$uid/profile`,
|
|
31
|
+
projections: {
|
|
32
|
+
current: current(schema)
|
|
33
|
+
},
|
|
34
|
+
write: ifMe,
|
|
35
|
+
read: ifMe
|
|
36
|
+
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
}
|