@arcote.tech/arc-workspace 0.4.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/package.json +20 -0
- package/src/aggregates/workspace-member.ts +218 -0
- package/src/aggregates/workspace.ts +123 -0
- package/src/arc.d.ts +6 -0
- package/src/ids/workspace-member.ts +15 -0
- package/src/ids/workspace.ts +12 -0
- package/src/index.ts +18 -0
- package/src/tokens/workspace-token.ts +20 -0
- package/src/workspace-builder.ts +110 -0
- package/tsconfig.json +4 -0
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arcote.tech/arc-workspace",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.4.1",
|
|
5
|
+
"private": false,
|
|
6
|
+
"description": "Reusable workspace module for Arc framework — multi-workspace with dual token architecture",
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"type-check": "tsc --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@arcote.tech/arc": "workspace:*",
|
|
14
|
+
"@arcote.tech/arc-auth": "workspace:*",
|
|
15
|
+
"typescript": "^5.0.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/bun": "latest"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import {
|
|
2
|
+
aggregate,
|
|
3
|
+
date,
|
|
4
|
+
string,
|
|
5
|
+
type AggregateConstructorAny,
|
|
6
|
+
type ArcId,
|
|
7
|
+
} from "@arcote.tech/arc";
|
|
8
|
+
import type { Token } from "@arcote.tech/arc-auth";
|
|
9
|
+
import type { WorkspaceToken } from "../tokens/workspace-token";
|
|
10
|
+
|
|
11
|
+
export type WorkspaceMemberAggregateData = {
|
|
12
|
+
name: string;
|
|
13
|
+
workspaceMemberId: ArcId<any>;
|
|
14
|
+
workspaceId: ArcId<any>;
|
|
15
|
+
accountId: ArcId<any>;
|
|
16
|
+
workspaceToken: WorkspaceToken;
|
|
17
|
+
userToken: Token;
|
|
18
|
+
WorkspaceAggregate: AggregateConstructorAny;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const createWorkspaceMemberAggregate = <
|
|
22
|
+
const Data extends WorkspaceMemberAggregateData,
|
|
23
|
+
>(
|
|
24
|
+
data: Data,
|
|
25
|
+
) => {
|
|
26
|
+
const {
|
|
27
|
+
workspaceMemberId,
|
|
28
|
+
workspaceId,
|
|
29
|
+
accountId,
|
|
30
|
+
workspaceToken,
|
|
31
|
+
userToken,
|
|
32
|
+
WorkspaceAggregate,
|
|
33
|
+
} = data;
|
|
34
|
+
|
|
35
|
+
const workspaceCreatedEvent = WorkspaceAggregate.getEvent("workspaceCreated");
|
|
36
|
+
|
|
37
|
+
const Constructor = aggregate(
|
|
38
|
+
`${data.name}WorkspaceMembers`,
|
|
39
|
+
workspaceMemberId,
|
|
40
|
+
{
|
|
41
|
+
workspaceId,
|
|
42
|
+
accountId,
|
|
43
|
+
role: string(),
|
|
44
|
+
workspaceName: string(),
|
|
45
|
+
workspaceType: string(),
|
|
46
|
+
joinedAt: date(),
|
|
47
|
+
},
|
|
48
|
+
)
|
|
49
|
+
.publicEvent(
|
|
50
|
+
"workspaceMemberAdded",
|
|
51
|
+
{
|
|
52
|
+
workspaceMemberId,
|
|
53
|
+
workspaceId,
|
|
54
|
+
accountId,
|
|
55
|
+
role: string(),
|
|
56
|
+
workspaceName: string(),
|
|
57
|
+
workspaceType: string(),
|
|
58
|
+
},
|
|
59
|
+
async (ctx, event) => {
|
|
60
|
+
const {
|
|
61
|
+
workspaceMemberId: id,
|
|
62
|
+
workspaceId: wsId,
|
|
63
|
+
accountId: accId,
|
|
64
|
+
role,
|
|
65
|
+
workspaceName,
|
|
66
|
+
workspaceType,
|
|
67
|
+
} = event.payload;
|
|
68
|
+
await ctx.set(id, {
|
|
69
|
+
workspaceId: wsId,
|
|
70
|
+
accountId: accId,
|
|
71
|
+
role,
|
|
72
|
+
workspaceName,
|
|
73
|
+
workspaceType,
|
|
74
|
+
joinedAt: event.createdAt,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
.publicEvent(
|
|
80
|
+
"workspaceMemberRemoved",
|
|
81
|
+
{ workspaceMemberId },
|
|
82
|
+
async (ctx, event) => {
|
|
83
|
+
await ctx.remove(event.payload.workspaceMemberId);
|
|
84
|
+
},
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
.publicEvent(
|
|
88
|
+
"workspaceMemberRoleChanged",
|
|
89
|
+
{
|
|
90
|
+
workspaceMemberId,
|
|
91
|
+
role: string(),
|
|
92
|
+
},
|
|
93
|
+
async (ctx, event) => {
|
|
94
|
+
await ctx.modify(event.payload.workspaceMemberId, {
|
|
95
|
+
role: event.payload.role,
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
// Auto-create owner membership when workspace is created
|
|
101
|
+
.handleEvent(workspaceCreatedEvent, async (ctx, event) => {
|
|
102
|
+
await ctx.set(event.payload.ownerMemberId, {
|
|
103
|
+
workspaceId: event.payload.workspaceId,
|
|
104
|
+
accountId: event.payload.ownerId,
|
|
105
|
+
role: "owner",
|
|
106
|
+
workspaceName: event.payload.name,
|
|
107
|
+
workspaceType: event.payload.type,
|
|
108
|
+
joinedAt: event.createdAt,
|
|
109
|
+
});
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
.mutateMethod(
|
|
113
|
+
"addMember",
|
|
114
|
+
{
|
|
115
|
+
params: {
|
|
116
|
+
workspaceId,
|
|
117
|
+
accountId,
|
|
118
|
+
role: string(),
|
|
119
|
+
workspaceName: string(),
|
|
120
|
+
workspaceType: string(),
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
ONLY_SERVER &&
|
|
124
|
+
(async (ctx, params) => {
|
|
125
|
+
const existing = await ctx.$query.findOne({
|
|
126
|
+
workspaceId: params.workspaceId,
|
|
127
|
+
accountId: params.accountId,
|
|
128
|
+
});
|
|
129
|
+
if (existing) {
|
|
130
|
+
return { error: "ALREADY_A_MEMBER" as const };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const id = workspaceMemberId.generate();
|
|
134
|
+
|
|
135
|
+
await ctx.workspaceMemberAdded.emit({
|
|
136
|
+
workspaceMemberId: id,
|
|
137
|
+
workspaceId: params.workspaceId,
|
|
138
|
+
accountId: params.accountId,
|
|
139
|
+
role: params.role,
|
|
140
|
+
workspaceName: params.workspaceName,
|
|
141
|
+
workspaceType: params.workspaceType,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return { workspaceMemberId: id };
|
|
145
|
+
}),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
.mutateMethod(
|
|
149
|
+
"removeMember",
|
|
150
|
+
{ params: { workspaceMemberId } },
|
|
151
|
+
ONLY_SERVER &&
|
|
152
|
+
(async (ctx, params) => {
|
|
153
|
+
await ctx.workspaceMemberRemoved.emit({
|
|
154
|
+
workspaceMemberId: params.workspaceMemberId,
|
|
155
|
+
});
|
|
156
|
+
}),
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
.mutateMethod(
|
|
160
|
+
"changeRole",
|
|
161
|
+
{
|
|
162
|
+
params: {
|
|
163
|
+
workspaceMemberId,
|
|
164
|
+
role: string(),
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
ONLY_SERVER &&
|
|
168
|
+
(async (ctx, params) => {
|
|
169
|
+
await ctx.workspaceMemberRoleChanged.emit({
|
|
170
|
+
workspaceMemberId: params.workspaceMemberId,
|
|
171
|
+
role: params.role,
|
|
172
|
+
});
|
|
173
|
+
}),
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
.mutateMethod(
|
|
177
|
+
"switchWorkspace",
|
|
178
|
+
{ params: { workspaceMemberId } },
|
|
179
|
+
ONLY_SERVER &&
|
|
180
|
+
(async (ctx, params) => {
|
|
181
|
+
const member = await ctx.$query.findOne({
|
|
182
|
+
_id: params.workspaceMemberId,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
if (!member) {
|
|
186
|
+
return { error: "NOT_A_MEMBER" as const };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (
|
|
190
|
+
ctx.$auth.params.accountId &&
|
|
191
|
+
ctx.$auth.params.accountId !== member.accountId
|
|
192
|
+
) {
|
|
193
|
+
return { error: "NOT_A_MEMBER" as const };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const token = workspaceToken.generateJWT({
|
|
197
|
+
accountId: member.accountId,
|
|
198
|
+
workspaceId: member.workspaceId,
|
|
199
|
+
role: member.role,
|
|
200
|
+
workspaceType: member.workspaceType,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
return { token };
|
|
204
|
+
}),
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
.protectBy(userToken, (params: any) => ({ accountId: params.accountId }))
|
|
208
|
+
.clientQuery("getAll", async (ctx) => ctx.$query.find({}))
|
|
209
|
+
.build();
|
|
210
|
+
|
|
211
|
+
class WorkspaceMember extends Constructor {}
|
|
212
|
+
|
|
213
|
+
return WorkspaceMember;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export type WorkspaceMemberAggregate<
|
|
217
|
+
Data extends WorkspaceMemberAggregateData = WorkspaceMemberAggregateData,
|
|
218
|
+
> = ReturnType<typeof createWorkspaceMemberAggregate<Data>>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { aggregate, date, string, type ArcId } from "@arcote.tech/arc";
|
|
2
|
+
import type { WorkspaceToken } from "../tokens/workspace-token";
|
|
3
|
+
|
|
4
|
+
export type WorkspaceAggregateData = {
|
|
5
|
+
name: string;
|
|
6
|
+
workspaceId: ArcId<any>;
|
|
7
|
+
workspaceMemberId: ArcId<any>;
|
|
8
|
+
accountId: ArcId<any>;
|
|
9
|
+
workspaceToken: WorkspaceToken;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const createWorkspaceAggregate = <
|
|
13
|
+
const Data extends WorkspaceAggregateData,
|
|
14
|
+
>(
|
|
15
|
+
data: Data,
|
|
16
|
+
) => {
|
|
17
|
+
const { workspaceId, workspaceMemberId, accountId, workspaceToken } = data;
|
|
18
|
+
|
|
19
|
+
return aggregate(`${data.name}Workspaces`, workspaceId, {
|
|
20
|
+
name: string().minLength(1).maxLength(100),
|
|
21
|
+
type: string(),
|
|
22
|
+
ownerId: accountId,
|
|
23
|
+
createdAt: date(),
|
|
24
|
+
})
|
|
25
|
+
.publicEvent(
|
|
26
|
+
"workspaceCreated",
|
|
27
|
+
{
|
|
28
|
+
workspaceId,
|
|
29
|
+
ownerMemberId: workspaceMemberId,
|
|
30
|
+
name: string().minLength(1).maxLength(100),
|
|
31
|
+
type: string(),
|
|
32
|
+
ownerId: accountId,
|
|
33
|
+
},
|
|
34
|
+
async (ctx, event) => {
|
|
35
|
+
const { workspaceId: id, name, type, ownerId } = event.payload;
|
|
36
|
+
await ctx.set(id, {
|
|
37
|
+
name,
|
|
38
|
+
type,
|
|
39
|
+
ownerId,
|
|
40
|
+
createdAt: event.createdAt,
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
.publicEvent(
|
|
46
|
+
"workspaceRenamed",
|
|
47
|
+
{
|
|
48
|
+
workspaceId,
|
|
49
|
+
name: string().minLength(1).maxLength(100),
|
|
50
|
+
},
|
|
51
|
+
async (ctx, event) => {
|
|
52
|
+
await ctx.modify(event.payload.workspaceId, {
|
|
53
|
+
name: event.payload.name,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
.mutateMethod(
|
|
59
|
+
"create",
|
|
60
|
+
{
|
|
61
|
+
params: {
|
|
62
|
+
name: string().minLength(1).maxLength(100),
|
|
63
|
+
type: string(),
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
ONLY_SERVER &&
|
|
67
|
+
(async (ctx, params) => {
|
|
68
|
+
const id = workspaceId.generate();
|
|
69
|
+
const ownerMemberId = workspaceMemberId.generate();
|
|
70
|
+
const ownerId = ctx.$auth.params.accountId;
|
|
71
|
+
|
|
72
|
+
await ctx.workspaceCreated.emit({
|
|
73
|
+
workspaceId: id,
|
|
74
|
+
ownerMemberId,
|
|
75
|
+
name: params.name,
|
|
76
|
+
type: params.type,
|
|
77
|
+
ownerId,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const token = workspaceToken.generateJWT({
|
|
81
|
+
accountId: ownerId,
|
|
82
|
+
workspaceId: id,
|
|
83
|
+
role: "owner",
|
|
84
|
+
workspaceType: params.type,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return { workspaceId: id, token, accountId: ownerId };
|
|
88
|
+
}),
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
.mutateMethod(
|
|
92
|
+
"rename",
|
|
93
|
+
{
|
|
94
|
+
params: {
|
|
95
|
+
workspaceId,
|
|
96
|
+
name: string().minLength(1).maxLength(100),
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
ONLY_SERVER &&
|
|
100
|
+
(async (ctx, params) => {
|
|
101
|
+
const existing = await ctx.$query.findOne({
|
|
102
|
+
_id: params.workspaceId,
|
|
103
|
+
});
|
|
104
|
+
if (!existing) {
|
|
105
|
+
return { error: "WORKSPACE_NOT_FOUND" as const };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
await ctx.workspaceRenamed.emit({
|
|
109
|
+
workspaceId: params.workspaceId,
|
|
110
|
+
name: params.name,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return { success: true };
|
|
114
|
+
}),
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
.clientQuery("getAll", async (ctx) => ctx.$query.find({}))
|
|
118
|
+
.build();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type WorkspaceAggregate<
|
|
122
|
+
Data extends WorkspaceAggregateData = WorkspaceAggregateData,
|
|
123
|
+
> = ReturnType<typeof createWorkspaceAggregate<Data>>;
|
package/src/arc.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { id } from "@arcote.tech/arc";
|
|
2
|
+
|
|
3
|
+
export type WorkspaceMemberIdData = {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const createWorkspaceMemberId = <
|
|
8
|
+
const Data extends WorkspaceMemberIdData,
|
|
9
|
+
>(
|
|
10
|
+
data: Readonly<Data>,
|
|
11
|
+
) => id(`${data.name}WorkspaceMember`);
|
|
12
|
+
|
|
13
|
+
export type WorkspaceMemberId<
|
|
14
|
+
Data extends WorkspaceMemberIdData = WorkspaceMemberIdData,
|
|
15
|
+
> = ReturnType<typeof createWorkspaceMemberId<Data>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { id } from "@arcote.tech/arc";
|
|
2
|
+
|
|
3
|
+
export type WorkspaceIdData = {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const createWorkspaceId = <const Data extends WorkspaceIdData>(
|
|
8
|
+
data: Readonly<Data>,
|
|
9
|
+
) => id(`${data.name}Workspace`);
|
|
10
|
+
|
|
11
|
+
export type WorkspaceId<Data extends WorkspaceIdData = WorkspaceIdData> =
|
|
12
|
+
ReturnType<typeof createWorkspaceId<Data>>;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// --- Builder API ---
|
|
2
|
+
export { workspace, WorkspaceBuilder } from "./workspace-builder";
|
|
3
|
+
|
|
4
|
+
// --- Aggregate factories & types ---
|
|
5
|
+
export { createWorkspaceAggregate } from "./aggregates/workspace";
|
|
6
|
+
export type { WorkspaceAggregate } from "./aggregates/workspace";
|
|
7
|
+
export { createWorkspaceMemberAggregate } from "./aggregates/workspace-member";
|
|
8
|
+
export type { WorkspaceMemberAggregate } from "./aggregates/workspace-member";
|
|
9
|
+
|
|
10
|
+
// --- ID factories & types ---
|
|
11
|
+
export { createWorkspaceId } from "./ids/workspace";
|
|
12
|
+
export type { WorkspaceId } from "./ids/workspace";
|
|
13
|
+
export { createWorkspaceMemberId } from "./ids/workspace-member";
|
|
14
|
+
export type { WorkspaceMemberId } from "./ids/workspace-member";
|
|
15
|
+
|
|
16
|
+
// --- Token factory & type ---
|
|
17
|
+
export { createWorkspaceToken } from "./tokens/workspace-token";
|
|
18
|
+
export type { WorkspaceToken } from "./tokens/workspace-token";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { string, token } from "@arcote.tech/arc";
|
|
2
|
+
|
|
3
|
+
export type WorkspaceTokenData = {
|
|
4
|
+
name: string;
|
|
5
|
+
secret: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const createWorkspaceToken = <const Data extends WorkspaceTokenData>(
|
|
9
|
+
data: Data,
|
|
10
|
+
) =>
|
|
11
|
+
token(`${data.name}Workspace`, {
|
|
12
|
+
accountId: string(),
|
|
13
|
+
workspaceId: string(),
|
|
14
|
+
role: string(),
|
|
15
|
+
workspaceType: string(),
|
|
16
|
+
}).secret(data.secret);
|
|
17
|
+
|
|
18
|
+
export type WorkspaceToken<
|
|
19
|
+
Data extends WorkspaceTokenData = WorkspaceTokenData,
|
|
20
|
+
> = ReturnType<typeof createWorkspaceToken<Data>>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
aggregateContextElement,
|
|
3
|
+
context,
|
|
4
|
+
type ArcAggregateElement,
|
|
5
|
+
type ArcContextElement,
|
|
6
|
+
type AggregateConstructorAny,
|
|
7
|
+
} from "@arcote.tech/arc";
|
|
8
|
+
import type { AccountId, Token } from "@arcote.tech/arc-auth";
|
|
9
|
+
import { createWorkspaceId } from "./ids/workspace";
|
|
10
|
+
import { createWorkspaceMemberId } from "./ids/workspace-member";
|
|
11
|
+
import { createWorkspaceToken } from "./tokens/workspace-token";
|
|
12
|
+
import { createWorkspaceAggregate } from "./aggregates/workspace";
|
|
13
|
+
import { createWorkspaceMemberAggregate } from "./aggregates/workspace-member";
|
|
14
|
+
|
|
15
|
+
export class WorkspaceBuilder<
|
|
16
|
+
WsId,
|
|
17
|
+
WsMemberId,
|
|
18
|
+
WsToken,
|
|
19
|
+
Workspace extends AggregateConstructorAny,
|
|
20
|
+
WorkspaceEl extends ArcAggregateElement<Workspace>,
|
|
21
|
+
WorkspaceMember extends AggregateConstructorAny,
|
|
22
|
+
WorkspaceMemberEl extends ArcAggregateElement<WorkspaceMember>,
|
|
23
|
+
Types extends readonly string[],
|
|
24
|
+
Elements extends ArcContextElement<any>[],
|
|
25
|
+
> {
|
|
26
|
+
constructor(
|
|
27
|
+
private readonly _name: string,
|
|
28
|
+
readonly workspaceId: WsId,
|
|
29
|
+
readonly workspaceMemberId: WsMemberId,
|
|
30
|
+
readonly workspaceToken: WsToken,
|
|
31
|
+
readonly Workspace: Workspace,
|
|
32
|
+
readonly workspaceElement: WorkspaceEl,
|
|
33
|
+
readonly WorkspaceMember: WorkspaceMember,
|
|
34
|
+
readonly workspaceMemberElement: WorkspaceMemberEl,
|
|
35
|
+
readonly types: Types,
|
|
36
|
+
readonly elements: Elements,
|
|
37
|
+
) {}
|
|
38
|
+
|
|
39
|
+
build() {
|
|
40
|
+
return {
|
|
41
|
+
context: context(this.elements),
|
|
42
|
+
workspaceId: this.workspaceId,
|
|
43
|
+
workspaceMemberId: this.workspaceMemberId,
|
|
44
|
+
workspaceToken: this.workspaceToken,
|
|
45
|
+
Workspace: this.Workspace,
|
|
46
|
+
WorkspaceMember: this.WorkspaceMember,
|
|
47
|
+
types: this.types,
|
|
48
|
+
// Protection helpers
|
|
49
|
+
isOwner: (params: { role: string }) => params.role === "owner",
|
|
50
|
+
isMember: (params: { role: string }) =>
|
|
51
|
+
params.role === "member" || params.role === "owner",
|
|
52
|
+
isType: (type: string) => (params: { workspaceType: string }) =>
|
|
53
|
+
params.workspaceType === type,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function workspace<
|
|
59
|
+
const Name extends string,
|
|
60
|
+
const Types extends readonly string[],
|
|
61
|
+
const Secret extends string | undefined,
|
|
62
|
+
>(config: {
|
|
63
|
+
name: Name;
|
|
64
|
+
types: Types;
|
|
65
|
+
secret: Secret;
|
|
66
|
+
accountId: AccountId;
|
|
67
|
+
userToken: Token;
|
|
68
|
+
}) {
|
|
69
|
+
const workspaceId = createWorkspaceId({ name: config.name });
|
|
70
|
+
const workspaceMemberId = createWorkspaceMemberId({ name: config.name });
|
|
71
|
+
const workspaceToken = createWorkspaceToken({
|
|
72
|
+
name: config.name,
|
|
73
|
+
secret: config.secret,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const Workspace = createWorkspaceAggregate({
|
|
77
|
+
name: config.name,
|
|
78
|
+
workspaceId,
|
|
79
|
+
workspaceMemberId,
|
|
80
|
+
accountId: config.accountId,
|
|
81
|
+
workspaceToken,
|
|
82
|
+
});
|
|
83
|
+
const workspaceElement = aggregateContextElement(Workspace);
|
|
84
|
+
|
|
85
|
+
const WorkspaceMember = createWorkspaceMemberAggregate({
|
|
86
|
+
name: config.name,
|
|
87
|
+
workspaceMemberId,
|
|
88
|
+
workspaceId,
|
|
89
|
+
accountId: config.accountId,
|
|
90
|
+
workspaceToken,
|
|
91
|
+
userToken: config.userToken,
|
|
92
|
+
WorkspaceAggregate: Workspace,
|
|
93
|
+
});
|
|
94
|
+
const workspaceMemberElement = aggregateContextElement(WorkspaceMember);
|
|
95
|
+
|
|
96
|
+
const elements = [workspaceElement, workspaceMemberElement];
|
|
97
|
+
|
|
98
|
+
return new WorkspaceBuilder(
|
|
99
|
+
config.name,
|
|
100
|
+
workspaceId,
|
|
101
|
+
workspaceMemberId,
|
|
102
|
+
workspaceToken,
|
|
103
|
+
Workspace,
|
|
104
|
+
workspaceElement,
|
|
105
|
+
WorkspaceMember,
|
|
106
|
+
workspaceMemberElement,
|
|
107
|
+
config.types,
|
|
108
|
+
elements,
|
|
109
|
+
);
|
|
110
|
+
}
|
package/tsconfig.json
ADDED