Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter errors after turning on strict mode #10719

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions modules/lib/lib-admin/src/main/resources/lib/xp/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,34 @@ declare global {
* @module admin
*/

const i18n = require('/lib/xp/i18n');
const portal = require('/lib/xp/portal');
interface ApiUrlParams {
application: string;
api?: string;
type?: 'server' | 'absolute' | 'websocket';
params?: object;
path?: string | string[];
}

interface Portal {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the types from the source, which is available in the same code repo?

apiUrl(options: ApiUrlParams): string;
assetUrl(options: { application: string; path: string }): string;
url(options: { path: string; type?: string }): string;
}

interface I18n {
getPhrases(locale: string[], bundles: string[]): Record<string, string>;
}

const i18n: I18n = require('/lib/xp/i18n');
const portal: Portal = require('/lib/xp/portal');

function checkRequired<T extends object>(obj: T, name: keyof T): void {
if (obj == null || obj[name] == null) {
throw `Parameter '${String(name)}' is required`;
}
}

const helper = __.newBean<AdminLibHelper>('com.enonic.xp.lib.admin.AdminLibHelper');
const helper: AdminLibHelper = __.newBean<AdminLibHelper>('com.enonic.xp.lib.admin.AdminLibHelper');

interface AdminLibHelper {
getHomeAppName(): string;
Expand Down
14 changes: 7 additions & 7 deletions modules/lib/lib-app/src/main/resources/lib/xp/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface CreateVirtualApplicationHandler {
export function createVirtualApplication(params: CreateVirtualApplicationParams): Application {
checkRequired(params, 'key');

const bean = __.newBean<CreateVirtualApplicationHandler>('com.enonic.xp.lib.app.CreateVirtualApplicationHandler');
const bean: CreateVirtualApplicationHandler = __.newBean<CreateVirtualApplicationHandler>('com.enonic.xp.lib.app.CreateVirtualApplicationHandler');
bean.setKey(params.key);
return __.toNativeObject(bean.execute());
}
Expand All @@ -85,7 +85,7 @@ interface DeleteVirtualApplicationHandler {
export function deleteVirtualApplication(params: DeleteVirtualApplicationParams): boolean {
checkRequired(params, 'key');

const bean = __.newBean<DeleteVirtualApplicationHandler>('com.enonic.xp.lib.app.DeleteVirtualApplicationHandler');
const bean: DeleteVirtualApplicationHandler = __.newBean<DeleteVirtualApplicationHandler>('com.enonic.xp.lib.app.DeleteVirtualApplicationHandler');
bean.setKey(params.key);
return __.toNativeObject(bean.execute());
}
Expand All @@ -111,7 +111,7 @@ interface GetApplicationHandler {
export function get(params: GetApplicationParams): Application {
checkRequired(params, 'key');

const bean = __.newBean<GetApplicationHandler>('com.enonic.xp.lib.app.GetApplicationHandler');
const bean: GetApplicationHandler = __.newBean<GetApplicationHandler>('com.enonic.xp.lib.app.GetApplicationHandler');
bean.setKey(params.key);
return __.toNativeObject(bean.execute());
}
Expand All @@ -126,7 +126,7 @@ interface ListApplicationsHandler {
* @returns {object[]} applications list.
*/
export function list(): Application[] {
const bean = __.newBean<ListApplicationsHandler>('com.enonic.xp.lib.app.ListApplicationsHandler');
const bean: ListApplicationsHandler = __.newBean<ListApplicationsHandler>('com.enonic.xp.lib.app.ListApplicationsHandler');
return __.toNativeObject(bean.execute());
}

Expand Down Expand Up @@ -161,7 +161,7 @@ interface GetApplicationDescriptorHandler {
* @returns {object} fetched application descriptor.
*/
export function getDescriptor(params: GetApplicationDescriptorParams): ApplicationDescriptor {
const bean = __.newBean<GetApplicationDescriptorHandler>('com.enonic.xp.lib.app.GetApplicationDescriptorHandler');
const bean: GetApplicationDescriptorHandler = __.newBean<GetApplicationDescriptorHandler>('com.enonic.xp.lib.app.GetApplicationDescriptorHandler');
bean.setKey(params.key);
return __.toNativeObject(bean.execute());
}
Expand All @@ -187,7 +187,7 @@ interface HasVirtualApplicationHandler {
export function hasVirtual(params: HasVirtualApplicationParams): boolean {
checkRequired(params, 'key');

const bean = __.newBean<HasVirtualApplicationHandler>('com.enonic.xp.lib.app.HasVirtualApplicationHandler');
const bean: HasVirtualApplicationHandler = __.newBean<HasVirtualApplicationHandler>('com.enonic.xp.lib.app.HasVirtualApplicationHandler');
bean.setKey(params.key);
return __.toNativeObject(bean.execute());
}
Expand All @@ -213,7 +213,7 @@ interface GetApplicationModeHandler {
export function getApplicationMode(params: GetApplicationModeParams): string | null {
checkRequired(params, 'key');

const bean = __.newBean<GetApplicationModeHandler>('com.enonic.xp.lib.app.GetApplicationModeHandler');
const bean: GetApplicationModeHandler = __.newBean<GetApplicationModeHandler>('com.enonic.xp.lib.app.GetApplicationModeHandler');
bean.setKey(params.key);
return __.toNativeObject(bean.execute());
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ interface CreateAuditLogHandler<Data extends Record<string, unknown>> {
export function log<Data extends Record<string, unknown> = Record<string, unknown>>(params: AuditLogParams<Data>): AuditLog<Data> {
checkRequired(params, 'type');

const bean = __.newBean<CreateAuditLogHandler<Data>>('com.enonic.xp.lib.audit.CreateAuditLogHandler');
const bean: CreateAuditLogHandler<Data> = __.newBean<CreateAuditLogHandler<Data>>('com.enonic.xp.lib.audit.CreateAuditLogHandler');
bean.setType(params.type);
bean.setTime(__.nullOrValue(params.time));
bean.setSource(params.source ?? app.name);
Expand Down Expand Up @@ -112,7 +112,7 @@ interface GetAuditLogHandler {
export function get(params: GetAuditLogParams): AuditLog | null {
checkRequired(params, 'id');

const bean = __.newBean<GetAuditLogHandler>('com.enonic.xp.lib.audit.GetAuditLogHandler');
const bean: GetAuditLogHandler = __.newBean<GetAuditLogHandler>('com.enonic.xp.lib.audit.GetAuditLogHandler');
bean.setId(params.id);
return __.toNativeObject(bean.execute());
}
Expand Down Expand Up @@ -191,7 +191,7 @@ export function find(params: FindAuditLogParams): AuditLogs {
objects,
} = params ?? {};

const bean = __.newBean<FindAuditLogHandler>('com.enonic.xp.lib.audit.FindAuditLogHandler');
const bean: FindAuditLogHandler = __.newBean<FindAuditLogHandler>('com.enonic.xp.lib.audit.FindAuditLogHandler');
bean.setStart(start);
bean.setCount(count);
bean.setIds(__.toScriptValue(ids));
Expand Down
46 changes: 23 additions & 23 deletions modules/lib/lib-auth/src/main/resources/lib/xp/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function login(params: LoginParams): LoginResult {
sessionTimeout,
} = params ?? {};

const bean = __.newBean<LoginHandler>('com.enonic.xp.lib.auth.LoginHandler');
const bean: LoginHandler = __.newBean<LoginHandler>('com.enonic.xp.lib.auth.LoginHandler');

bean.setUser(user);

Expand Down Expand Up @@ -125,7 +125,7 @@ interface LogoutHandler {
* @example-ref examples/auth/logout.js
*/
export function logout(): void {
const bean = __.newBean<LogoutHandler>('com.enonic.xp.lib.auth.LogoutHandler');
const bean: LogoutHandler = __.newBean<LogoutHandler>('com.enonic.xp.lib.auth.LogoutHandler');

bean.logout();
}
Expand Down Expand Up @@ -157,7 +157,7 @@ export function getUser(params?: GetUserParams): User | null {
includeProfile = false,
} = params ?? {};

const bean = __.newBean<GetUserHandler>('com.enonic.xp.lib.auth.GetUserHandler');
const bean: GetUserHandler = __.newBean<GetUserHandler>('com.enonic.xp.lib.auth.GetUserHandler');

bean.setIncludeProfile(includeProfile);

Expand All @@ -179,7 +179,7 @@ interface HasRoleHandler {
* @returns {boolean} True if the user has specified role, false otherwise.
*/
export function hasRole(role: string): boolean {
const bean = __.newBean<HasRoleHandler>('com.enonic.xp.lib.auth.HasRoleHandler');
const bean: HasRoleHandler = __.newBean<HasRoleHandler>('com.enonic.xp.lib.auth.HasRoleHandler');

bean.setRole(__.nullOrValue(role));

Expand All @@ -198,7 +198,7 @@ interface GeneratePasswordHandler {
* @returns {string} A secure generated password.
*/
export function generatePassword(): string {
const bean = __.newBean<GeneratePasswordHandler>('com.enonic.xp.lib.auth.GeneratePasswordHandler');
const bean: GeneratePasswordHandler = __.newBean<GeneratePasswordHandler>('com.enonic.xp.lib.auth.GeneratePasswordHandler');

return __.toNativeObject(bean.generatePassword());
}
Expand Down Expand Up @@ -226,7 +226,7 @@ interface ChangePasswordHandler {
* @param {string} params.password New password to set.
*/
export function changePassword(params: ChangePasswordParams): void {
const bean = __.newBean<ChangePasswordHandler>('com.enonic.xp.lib.auth.ChangePasswordHandler');
const bean: ChangePasswordHandler = __.newBean<ChangePasswordHandler>('com.enonic.xp.lib.auth.ChangePasswordHandler');

checkRequired(params, 'userKey');
checkRequired(params, 'password');
Expand Down Expand Up @@ -259,7 +259,7 @@ export function getPrincipal(roleKey: RoleKey): Role | null;
export function getPrincipal(principalKey: PrincipalKey): Principal | null {
checkRequiredValue(principalKey, 'principalKey');

const bean = __.newBean<GetPrincipalHandler>('com.enonic.xp.lib.auth.GetPrincipalHandler');
const bean: GetPrincipalHandler = __.newBean<GetPrincipalHandler>('com.enonic.xp.lib.auth.GetPrincipalHandler');

bean.setPrincipalKey(principalKey);

Expand All @@ -286,7 +286,7 @@ interface GetMembershipsHandler {
export function getMemberships(principalKey: UserKey | GroupKey, transitive = false): (Group | Role)[] {
checkRequiredValue(principalKey, 'principalKey');

const bean = __.newBean<GetMembershipsHandler>('com.enonic.xp.lib.auth.GetMembershipsHandler');
const bean: GetMembershipsHandler = __.newBean<GetMembershipsHandler>('com.enonic.xp.lib.auth.GetMembershipsHandler');

bean.setPrincipalKey(principalKey);
bean.setTransitive(transitive);
Expand All @@ -311,7 +311,7 @@ interface GetMembersHandler {
export function getMembers(principalKey: GroupKey | RoleKey): (User | Group)[] {
checkRequiredValue(principalKey, 'principalKey');

const bean = __.newBean<GetMembersHandler>('com.enonic.xp.lib.auth.GetMembersHandler');
const bean: GetMembersHandler = __.newBean<GetMembersHandler>('com.enonic.xp.lib.auth.GetMembersHandler');

bean.setPrincipalKey(principalKey);

Expand Down Expand Up @@ -352,7 +352,7 @@ export function createUser(params: CreateUserParams): User {
checkRequired(params, 'name');
checkRequired(params, 'idProvider');

const bean = __.newBean<CreateUserHandler>('com.enonic.xp.lib.auth.CreateUserHandler');
const bean: CreateUserHandler = __.newBean<CreateUserHandler>('com.enonic.xp.lib.auth.CreateUserHandler');

bean.setIdProvider(params.idProvider);
bean.setName(params.name);
Expand Down Expand Up @@ -389,7 +389,7 @@ export function modifyUser(params: ModifyUserParams): User | null {
checkRequired(params, 'key');
checkRequired(params, 'editor');

const bean = __.newBean<ModifyUserHandler>('com.enonic.xp.lib.auth.ModifyUserHandler');
const bean: ModifyUserHandler = __.newBean<ModifyUserHandler>('com.enonic.xp.lib.auth.ModifyUserHandler');

bean.setPrincipalKey(params.key);
bean.setEditor(__.toScriptValue(params.editor));
Expand Down Expand Up @@ -431,7 +431,7 @@ export function createGroup(params: CreateGroupParams): Group {
checkRequired(params, 'idProvider');
checkRequired(params, 'name');

const bean = __.newBean<CreateGroupHandler>('com.enonic.xp.lib.auth.CreateGroupHandler');
const bean: CreateGroupHandler = __.newBean<CreateGroupHandler>('com.enonic.xp.lib.auth.CreateGroupHandler');

bean.setIdProvider(params.idProvider);
bean.setName(params.name);
Expand Down Expand Up @@ -468,7 +468,7 @@ export function modifyGroup(params: ModifyGroupParams): Group | null {
checkRequired(params, 'key');
checkRequired(params, 'editor');

const bean = __.newBean<ModifyGroupHandler>('com.enonic.xp.lib.auth.ModifyGroupHandler');
const bean: ModifyGroupHandler = __.newBean<ModifyGroupHandler>('com.enonic.xp.lib.auth.ModifyGroupHandler');

bean.setPrincipalKey(params.key);
bean.setEditor(__.toScriptValue(params.editor));
Expand All @@ -495,7 +495,7 @@ interface AddMembersHandler {
export function addMembers(principalKey: GroupKey | RoleKey, members: (UserKey | GroupKey)[]): void {
checkRequiredValue(principalKey, 'principalKey');

const bean = __.newBean<AddMembersHandler>('com.enonic.xp.lib.auth.AddMembersHandler');
const bean: AddMembersHandler = __.newBean<AddMembersHandler>('com.enonic.xp.lib.auth.AddMembersHandler');

bean.setPrincipalKey(principalKey);
bean.setMembers(([] as (UserKey | GroupKey)[]).concat(members));
Expand All @@ -522,7 +522,7 @@ interface RemoveMembersHandler {
export function removeMembers(principalKey: GroupKey | RoleKey, members: (UserKey | GroupKey)[]): void {
checkRequiredValue(principalKey, 'principalKey');

const bean = __.newBean<RemoveMembersHandler>('com.enonic.xp.lib.auth.RemoveMembersHandler');
const bean: RemoveMembersHandler = __.newBean<RemoveMembersHandler>('com.enonic.xp.lib.auth.RemoveMembersHandler');

bean.setPrincipalKey(principalKey);
bean.setMembers(([] as (UserKey | GroupKey)[]).concat(members));
Expand Down Expand Up @@ -576,7 +576,7 @@ interface FindPrincipalsHandler {
* @returns {FindPrincipalsResult} The "total" number of principals matching the search, the "count" of principals included, and an array of "hits" containing the principals.
*/
export function findPrincipals(params: FindPrincipalsParams): FindPrincipalsResult {
const bean = __.newBean<FindPrincipalsHandler>('com.enonic.xp.lib.auth.FindPrincipalsHandler');
const bean: FindPrincipalsHandler = __.newBean<FindPrincipalsHandler>('com.enonic.xp.lib.auth.FindPrincipalsHandler');

const {
type,
Expand Down Expand Up @@ -614,7 +614,7 @@ interface DeletePrincipalHandler {
export function deletePrincipal(principalKey: PrincipalKey): boolean {
checkRequiredValue(principalKey, 'principalKey');

const bean = __.newBean<DeletePrincipalHandler>('com.enonic.xp.lib.auth.DeletePrincipalHandler');
const bean: DeletePrincipalHandler = __.newBean<DeletePrincipalHandler>('com.enonic.xp.lib.auth.DeletePrincipalHandler');
bean.setPrincipalKey(principalKey);
return __.toNativeObject(bean.deletePrincipal());
}
Expand All @@ -632,7 +632,7 @@ interface GetIdProviderConfigHandler<IdProviderConfig extends Record<string, unk
* @returns {object} The ID provider configuration as JSON.
*/
export function getIdProviderConfig<IdProviderConfig extends Record<string, unknown>>(): IdProviderConfig | null {
const bean = __.newBean<GetIdProviderConfigHandler<IdProviderConfig>>('com.enonic.xp.lib.auth.GetIdProviderConfigHandler');
const bean: GetIdProviderConfigHandler<IdProviderConfig> = __.newBean<GetIdProviderConfigHandler<IdProviderConfig>>('com.enonic.xp.lib.auth.GetIdProviderConfigHandler');
return __.toNativeObject(bean.execute());
}

Expand Down Expand Up @@ -662,7 +662,7 @@ interface GetProfileHandler<Profile extends Record<string, unknown>> {
export function getProfile<Profile extends Record<string, unknown> = Record<string, unknown>>(params: GetProfileParams): Profile | null {
checkRequired(params, 'key');

const bean = __.newBean<GetProfileHandler<Profile>>('com.enonic.xp.lib.auth.GetProfileHandler');
const bean: GetProfileHandler<Profile> = __.newBean<GetProfileHandler<Profile>>('com.enonic.xp.lib.auth.GetProfileHandler');

bean.setKey(params.key);
bean.setScope(__.nullOrValue(params.scope));
Expand Down Expand Up @@ -701,7 +701,7 @@ export function modifyProfile<Profile extends Record<string, unknown> = Record<s
checkRequired(params, 'key');
checkRequired(params, 'editor');

const bean = __.newBean<ModifyProfileHandler<Profile>>('com.enonic.xp.lib.auth.ModifyProfileHandler');
const bean: ModifyProfileHandler<Profile> = __.newBean<ModifyProfileHandler<Profile>>('com.enonic.xp.lib.auth.ModifyProfileHandler');

bean.setKey(params.key);
bean.setScope(__.nullOrValue(params.scope));
Expand Down Expand Up @@ -757,7 +757,7 @@ export function findUsers(params: FindUsersParams): FindPrincipalsResult<User |
includeProfile = false,
} = params ?? {};

const bean = __.newBean<FindUsersHandler>('com.enonic.xp.lib.auth.FindUsersHandler');
const bean: FindUsersHandler = __.newBean<FindUsersHandler>('com.enonic.xp.lib.auth.FindUsersHandler');

bean.setStart(start);
bean.setCount(count);
Expand Down Expand Up @@ -795,7 +795,7 @@ interface CreateRoleHandler {
export function createRole(params: CreateRoleParams): Role {
checkRequired(params, 'name');

const bean = __.newBean<CreateRoleHandler>('com.enonic.xp.lib.auth.CreateRoleHandler');
const bean: CreateRoleHandler = __.newBean<CreateRoleHandler>('com.enonic.xp.lib.auth.CreateRoleHandler');

bean.setName(params.name);
bean.setDisplayName(__.nullOrValue(params.displayName));
Expand Down Expand Up @@ -831,7 +831,7 @@ export function modifyRole(params: ModifyRoleParams): Role | null {
checkRequired(params, 'key');
checkRequired(params, 'editor');

const bean = __.newBean<ModifyRoleHandler>('com.enonic.xp.lib.auth.ModifyRoleHandler');
const bean: ModifyRoleHandler = __.newBean<ModifyRoleHandler>('com.enonic.xp.lib.auth.ModifyRoleHandler');

bean.setPrincipalKey(params.key);
bean.setEditor(__.toScriptValue(params.editor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ interface ClusterIsMasterHandler {
* @returns {boolean} true if the current node is master; false otherwise.
*/
export function isMaster(): boolean {
const bean = __.newBean<ClusterIsMasterHandler>('com.enonic.xp.lib.cluster.ClusterIsMasterHandler');
const bean: ClusterIsMasterHandler = __.newBean<ClusterIsMasterHandler>('com.enonic.xp.lib.cluster.ClusterIsMasterHandler');
return __.toNativeObject(bean.isMaster());
}
2 changes: 1 addition & 1 deletion modules/lib/lib-common/src/main/resources/lib/xp/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface NamePrettyfier {
* @module common
*/

const NamePrettyfier = __.newBean<NamePrettyfier>('com.enonic.xp.lib.common.NamePrettyfierHandler');
const NamePrettyfier: NamePrettyfier = __.newBean<NamePrettyfier>('com.enonic.xp.lib.common.NamePrettyfierHandler');

/**
* Transform a text string so that it can be safely used in cases where the range of accepted characters is restricted.
Expand Down
Loading
Loading