Skip to content

Commit f82700c

Browse files
Merge branch 'develop' into quote-messages
2 parents 1d31bb4 + 8c951f8 commit f82700c

File tree

43 files changed

+3541
-2255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3541
-2255
lines changed

apps/meteor/app/api/server/ApiClass.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Logger } from '@rocket.chat/logger';
55
import { Users } from '@rocket.chat/models';
66
import { Random } from '@rocket.chat/random';
77
import type { JoinPathPattern, Method } from '@rocket.chat/rest-typings';
8-
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
8+
import { ajv } from '@rocket.chat/rest-typings';
99
import { wrapExceptions } from '@rocket.chat/tools';
1010
import type { ValidateFunction } from 'ajv';
1111
import { Accounts } from 'meteor/accounts-base';
@@ -66,8 +66,13 @@ export type Prettify<T> = {
6666

6767
type ExtractValidation<T> = T extends ValidateFunction<infer TSchema> ? TSchema : never;
6868

69-
export type ExtractRoutesFromAPI<T> =
70-
T extends APIClass<any, infer TOperations> ? (TOperations extends MinimalRoute ? Prettify<ConvertToRoute<TOperations>> : never) : never;
69+
type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (x: infer I) => any ? I : never;
70+
71+
export type ExtractRoutesFromAPI<T> = Prettify<
72+
UnionToIntersection<
73+
T extends APIClass<any, infer TOperations> ? (TOperations extends MinimalRoute ? Prettify<ConvertToRoute<TOperations>> : never) : never
74+
>
75+
>;
7176

7277
type ConvertToRoute<TRoute extends MinimalRoute> = {
7378
[K in TRoute['path']]: {
@@ -578,7 +583,7 @@ export class APIClass<
578583
TSubPathPattern extends string,
579584
TOptions extends TypedOptions,
580585
TPathPattern extends `${TBasePath}/${TSubPathPattern}`,
581-
>(method: Method, subpath: TSubPathPattern, options: TOptions): void {
586+
>(method: MinimalRoute['method'], subpath: TSubPathPattern, options: TOptions): void {
582587
const path = `/${this.apiPath}/${subpath}`.replaceAll('//', '/') as TPathPattern;
583588
this.typedRoutes = this.typedRoutes || {};
584589
this.typedRoutes[path] = this.typedRoutes[subpath] || {};
@@ -629,7 +634,7 @@ export class APIClass<
629634
}
630635

631636
private method<TSubPathPattern extends string, TOptions extends TypedOptions, TPathPattern extends `${TBasePath}/${TSubPathPattern}`>(
632-
method: Method,
637+
method: MinimalRoute['method'],
633638
subpath: TSubPathPattern,
634639
options: TOptions,
635640
action: TypedAction<TOptions, TSubPathPattern>,

apps/meteor/app/api/server/default/openApi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { schemas } from '@rocket.chat/core-typings';
12
import type { Route } from '@rocket.chat/http-router';
23
import { isOpenAPIJSONEndpoint } from '@rocket.chat/rest-typings';
34
import express from 'express';
@@ -65,8 +66,9 @@ const makeOpenAPIResponse = (paths: Record<string, Record<string, Route>>) => ({
6566
name: 'X-Auth-Token',
6667
},
6768
},
68-
schemas: {},
69+
schemas: schemas.components.schemas,
6970
},
71+
schemas: schemas.components.schemas,
7072
paths,
7173
});
7274

apps/meteor/app/api/server/definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export type NonEnterpriseTwoFactorOptions = {
8888
twoFactorOptions: ITwoFactorOptions;
8989
};
9090

91-
export type Options = SharedOptions<Method>;
91+
export type Options = SharedOptions<'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'>;
9292

9393
export type SharedOptions<TMethod extends string> = (
9494
| {

apps/meteor/app/api/server/v1/custom-sounds.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ICustomSound } from '@rocket.chat/core-typings';
22
import { CustomSounds } from '@rocket.chat/models';
33
import type { PaginatedRequest, PaginatedResult } from '@rocket.chat/rest-typings';
4-
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
4+
import { ajv } from '@rocket.chat/rest-typings';
55
import { escapeRegExp } from '@rocket.chat/string-helpers';
66

77
import type { ExtractRoutesFromAPI } from '../ApiClass';

apps/meteor/app/api/server/v1/federation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Federation, FederationEE } from '@rocket.chat/core-services';
22
import { License } from '@rocket.chat/license';
3-
import { isFederationVerifyMatrixIdProps } from '@rocket.chat/rest-typings';
4-
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
3+
import { ajv, isFederationVerifyMatrixIdProps } from '@rocket.chat/rest-typings';
54

65
import { API } from '../api';
76

apps/meteor/app/api/server/v1/invites.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { IInvite } from '@rocket.chat/core-typings';
22
import {
3+
ajv,
34
isFindOrCreateInviteParams,
45
isUseInviteTokenProps,
56
isValidateInviteTokenProps,
67
isSendInvitationEmailParams,
78
} from '@rocket.chat/rest-typings';
8-
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
99

1010
import { findOrCreateInvite } from '../../../invites/server/functions/findOrCreateInvite';
1111
import { listInvites } from '../../../invites/server/functions/listInvites';

apps/meteor/app/api/server/v1/webdav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { api } from '@rocket.chat/core-services';
22
import type { IWebdavAccount, IWebdavAccountIntegration } from '@rocket.chat/core-typings';
33
import { WebdavAccounts } from '@rocket.chat/models';
4-
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
4+
import { ajv } from '@rocket.chat/rest-typings';
55
import type { DeleteResult } from 'mongodb';
66

77
import type { ExtractRoutesFromAPI } from '../ApiClass';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { schemas } from '@rocket.chat/core-typings';
2+
import Ajv from 'ajv';
3+
4+
const ajv = new Ajv({
5+
coerceTypes: true,
6+
allowUnionTypes: true,
7+
code: { source: true },
8+
});
9+
10+
export { ajv };
11+
12+
const components = schemas.components?.schemas;
13+
14+
if (components) {
15+
for (const key in components) {
16+
if (Object.prototype.hasOwnProperty.call(components, key)) {
17+
ajv.addSchema(components[key], `#/components/schemas/${key}`);
18+
}
19+
}
20+
}

apps/meteor/app/livechat/server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './ajv';
12
import './livechat';
23
import './startup';
34
import '../lib/messageTypes';

apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { IMessage, IRoom } from '@rocket.chat/core-typings';
22
import { Emitter } from '@rocket.chat/emitter';
33
import { createPredicateFromFilter } from '@rocket.chat/mongo-adapter';
4-
import type { Filter } from '@rocket.chat/mongo-adapter';
4+
import type { Filter } from 'mongodb';
55

66
import { upsertMessage, RoomHistoryManager } from './RoomHistoryManager';
77
import { RoomManager } from '../../../../client/lib/RoomManager';

0 commit comments

Comments
 (0)