Skip to content

Commit 8d6f59f

Browse files
committed
Testing ContentConnection
1 parent b022b11 commit 8d6f59f

File tree

16 files changed

+210
-104
lines changed

16 files changed

+210
-104
lines changed

src/implementation/Auth.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,24 @@ import {Server} from './Server';
3131
import { UserWithProfile } from './auth/UserWithProfile';
3232

3333

34-
export declare type GroupNode = Node<{
34+
export declare interface GroupNodeData {
3535
description?: string
3636
displayName: string
3737
principalType: 'GROUP'
3838
userStoreKey: string
3939
member?: GroupKey | UserKey | (GroupKey | UserKey)[]
40-
}>
40+
}
41+
42+
export declare type GroupNode = Node<GroupNodeData>
4143

42-
export declare type RoleNode = Node<{
44+
export declare interface RoleNodeData {
4345
description?: string
4446
displayName: string
4547
principalType: 'ROLE'
4648
member?: GroupKey | UserKey | (GroupKey | UserKey)[]
47-
}>
49+
}
50+
51+
export declare type RoleNode = Node<RoleNodeData>
4852

4953
export declare interface UserData<
5054
Profile extends Record<string, unknown> = Record<string, unknown>
@@ -104,7 +108,7 @@ export class Auth {
104108
idProvider,
105109
name,
106110
}: CreateGroupParams): Group {
107-
const groupNode = this.systemRepoConnection.create({
111+
const groupNode = this.systemRepoConnection.create<GroupNodeData>({
108112
_name: name,
109113
_parentPath: `/identity/${idProvider}/groups`,
110114
description: description,
@@ -125,13 +129,13 @@ export class Auth {
125129
displayName,
126130
description
127131
}: CreateRoleParams): Role {
128-
const roleNode = this.systemRepoConnection.create({
132+
const roleNode = this.systemRepoConnection.create<RoleNodeData>({
129133
_name: name,
130134
_parentPath: '/identity/roles',
131135
description,
132136
displayName,
133137
principalType: 'ROLE',
134-
}) as RoleNode;
138+
});
135139
return new Role({
136140
displayName,
137141
key: `role:${name}`,
@@ -163,7 +167,7 @@ export class Auth {
163167
profile,
164168
userStoreKey: idProvider,
165169
};
166-
const userNode = this.systemRepoConnection.create(createParams) as unknown as UserNode;
170+
const userNode = this.systemRepoConnection.create<UserData>(createParams);
167171
return new User({
168172
displayName,
169173
key: `user:${idProvider}:${name}`,

src/implementation/Branch.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import type {
55
} from '@enonic-types/core';
66
import type {
77
BooleanFilter,
8+
CreateNodeParams,
89
HasValueFilter,
910
MoveNodeParams,
11+
Node,
1012
QueryNodeParams,
1113
} from '@enonic-types/lib-node';
1214
import type {
1315
GetActiveVersionParamObject,
1416
GetActiveVersionResponse,
1517
Log,
16-
NodeCreateParams,
1718
NodeModifyParams,
1819
NodeQueryResponse,
1920
NodeRefreshParams,
@@ -166,7 +167,7 @@ export class Branch {
166167
// this.log.debug('in Branch constructor');
167168
}
168169

169-
_createNodeInternal({
170+
_createNodeInternal<NodeData = unknown>({
170171
// _childOrder,
171172
_id = this.repo.generateId(),
172173
_indexConfig = DEFAULT_INDEX_CONFIG,
@@ -178,19 +179,17 @@ export class Branch {
178179
_ts = Branch.generateInstantString(),
179180
_versionKey = this.repo.generateId(),
180181
...rest // contains _nodeType
181-
}: NodeCreateParams & {
182+
}: CreateNodeParams<NodeData> & {
182183
_id?: string
183-
_ts?: string
184-
_versionKey?: string
185-
}): RepoNodeWithData {
184+
}): Node<NodeData> {
186185
for (const k of IGNORED_ON_CREATE) {
187186
if (rest.hasOwnProperty(k)) { delete rest[k]; }
188187
}
188+
if (!_name) { _name = _id as string; }
189189
if (!rest._nodeType) {
190+
// @ts-expect-error Too complex to waste time on making perfect!
190191
rest._nodeType = 'default';
191192
}
192-
if (!_name) { _name = _id as string; }
193-
194193
if(!_parentPath.endsWith('/')) {
195194
_parentPath += '/'
196195
}
@@ -213,17 +212,18 @@ export class Branch {
213212
throw new NodeAlreadyExistAtPathException(`Node already exists at ${_path} repository: ${this.repo.id} branch: ${this.id}`);
214213
}
215214

216-
const node: RepoNodeWithData = {
215+
const node: Node<NodeData> = {
217216
_id,
218217
_indexConfig,
219218
_name,
219+
// _nodeType,
220220
_path,
221221
_state: 'DEFAULT',
222222
_ts,
223223
_versionKey,
224224
...(enonify(rest) as Object)
225-
} as unknown as RepoNodeWithData;
226-
this.nodes[_id] = node;
225+
} as unknown as Node<NodeData>;
226+
this.nodes[_id] = node as RepoNodeWithData;
227227
this.pathIndex[_path] = _id;
228228

229229
const restKeys = Object.keys(rest).filter(k => !SEARCH_INDEX_BLACKLIST.includes(k));
@@ -263,8 +263,8 @@ export class Branch {
263263
return deref(node);
264264
} // _createNodeInternal
265265

266-
createNode(params: NodeCreateParams): RepoNodeWithData {
267-
return this._createNodeInternal(params); // already dereffed
266+
createNode<NodeData = unknown>(params: CreateNodeParams<NodeData>): Node<NodeData> {
267+
return this._createNodeInternal<NodeData>(params); // already dereffed
268268
}
269269

270270
private keyToId(key: string): string | undefined {
@@ -650,7 +650,7 @@ export class Branch {
650650
}
651651

652652
if (isQueryDsl(query)) {
653-
this.log.info('query: Search Index: %s', this.searchIndex);
653+
this.log.info('query:%s Search Index: %s', query, this.searchIndex);
654654
const mustSets: string[][] = [];
655655
const mustNotSets: string[][] = [];
656656

0 commit comments

Comments
 (0)