Skip to content

Commit

Permalink
Merge pull request #255 from Telegram-Mini-Apps/bugfix/tests
Browse files Browse the repository at this point in the history
Get rid of barrel files
  • Loading branch information
heyqbnk authored Mar 13, 2024
2 parents 896411c + c4c3b45 commit 27e477b
Show file tree
Hide file tree
Showing 172 changed files with 687 additions and 764 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-wolves-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tma.js/sdk": patch
---

Get rid of barrel files
2 changes: 0 additions & 2 deletions packages/sdk/src/back-button/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/sdk/src/bridge/env/hasExternalNotify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isRecord } from '../../misc/index.js';
import { isRecord } from '../../misc/isRecord.js';

type WithExternalNotify<T> = T & {
external: {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/bridge/env/hasWebviewProxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isRecord } from '../../misc/index.js';
import { isRecord } from '../../misc/isRecord.js';

type WithWebviewProxy<T> = T & {
TelegramWebviewProxy: {
Expand Down
2 changes: 0 additions & 2 deletions packages/sdk/src/bridge/env/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/sdk/src/bridge/errors/MethodUnsupportedError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Version } from '../../version/index.js';
import type { MiniAppsMethodName } from '../methods/index.js';
import type { Version } from '../../version/types.js';
import type { MiniAppsMethodName } from '../methods/methods.js';

/**
* Error thrown in case, unsupported method was called.
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/bridge/errors/ParameterUnsupportedError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Version } from '../../version/index.js';
import type { MiniAppsMethodName } from '../methods/index.js';
import type { Version } from '../../version/types.js';
import type { MiniAppsMethodName } from '../methods/methods.js';

/**
* Error thrown in case, unsupported parameter was used.
Expand Down
2 changes: 0 additions & 2 deletions packages/sdk/src/bridge/errors/index.ts

This file was deleted.

24 changes: 11 additions & 13 deletions packages/sdk/src/bridge/events/createEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import type { MiniAppsEventEmitter, MiniAppsEventName } from './events.js';
import { onTelegramEvent } from './onTelegramEvent.js';
import {
clipboardTextReceived,
customMethodInvoked,
invoiceClosed,
phoneRequested,
popupClosed,
qrTextReceived,
themeChanged,
viewportChanged,
writeAccessRequested,
} from './parsers/index.js';
import { EventEmitter } from '../../event-emitter/index.js';
import { clipboardTextReceived } from './parsers/clipboardTextReceived.js';
import { customMethodInvoked } from './parsers/customMethodInvoked.js';
import { invoiceClosed } from './parsers/invoiceClosed.js';
import { phoneRequested } from './parsers/phoneRequested.js';
import { popupClosed } from './parsers/popupClosed.js';
import { qrTextReceived } from './parsers/qrTextReceived.js';
import { themeChanged } from './parsers/theme-changed.js';
import { viewportChanged } from './parsers/viewportChanged.js';
import { writeAccessRequested } from './parsers/writeAccessRequested.js';
import { EventEmitter } from '../../event-emitter/EventEmitter.js';
import { logger } from '../../globals.js';
import { string } from '../../parsing/index.js';
import { string } from '../../parsing/parsers/string.js';

/**
* Returns event emitter which could be safely used, to process events from
Expand Down
31 changes: 13 additions & 18 deletions packages/sdk/src/bridge/events/events.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import type {
ClipboardTextReceivedPayload,
CustomMethodInvokedPayload,
InvoiceClosedPayload,
PhoneRequestedPayload,
PopupClosedPayload,
QrTextReceivedPayload,
ThemeChangedPayload,
ViewportChangedPayload,
WriteAccessRequestedPayload,
} from './parsers/index.js';
import type {
AnySubscribeListener,
EventEmitter,
EventListener,
EventParams,
} from '../../event-emitter/index.js';
import type { IsNever, Not } from '../../types/index.js';
import type { ClipboardTextReceivedPayload } from './parsers/clipboardTextReceived.js';
import type { CustomMethodInvokedPayload } from './parsers/customMethodInvoked.js';
import type { InvoiceClosedPayload } from './parsers/invoiceClosed.js';
import type { PhoneRequestedPayload } from './parsers/phoneRequested.js';
import type { PopupClosedPayload } from './parsers/popupClosed.js';
import type { QrTextReceivedPayload } from './parsers/qrTextReceived.js';
import type { ThemeChangedPayload } from './parsers/theme-changed.js';
import type { ViewportChangedPayload } from './parsers/viewportChanged.js';
import type { WriteAccessRequestedPayload } from './parsers/writeAccessRequested.js';
import type { EventEmitter } from '../../event-emitter/EventEmitter.js';
import type { AnySubscribeListener, EventListener, EventParams } from '../../event-emitter/types.js';
import type { Not } from '../../types/logical.js';
import type { IsNever } from '../../types/utils.js';

/**
* Map where key is known event name, and value is its listener.
Expand Down
9 changes: 0 additions & 9 deletions packages/sdk/src/bridge/events/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/sdk/src/bridge/events/onTelegramEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseMessage } from '../../bridge/parseMessage.js';
import { parseMessage } from '../parseMessage.js';

/**
* Emits event sent from Telegram native application like it was sent in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { json, string } from '../../../parsing/index.js';
import type { RequestId } from '../../../types/index.js';
import { json } from '../../../parsing/parsers/json.js';
import { string } from '../../../parsing/parsers/string.js';
import type { RequestId } from '../../../types/request-id.js';

export interface ClipboardTextReceivedPayload {
/**
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/bridge/events/parsers/customMethodInvoked.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { json, string } from '../../../parsing/index.js';
import type { RequestId } from '../../../types/index.js';
import { json } from '../../../parsing/parsers/json.js';
import { string } from '../../../parsing/parsers/string.js';
import type { RequestId } from '../../../types/request-id.js';

export interface CustomMethodInvokedPayload<R = unknown> {
/**
Expand Down
9 changes: 0 additions & 9 deletions packages/sdk/src/bridge/events/parsers/index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/sdk/src/bridge/events/parsers/invoiceClosed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { json, string } from '../../../parsing/index.js';
import { json } from '../../../parsing/parsers/json.js';
import { string } from '../../../parsing/parsers/string.js';

export type InvoiceStatus =
| 'paid'
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/bridge/events/parsers/phoneRequested.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { json, string } from '../../../parsing/index.js';
import { json } from '../../../parsing/parsers/json.js';
import { string } from '../../../parsing/parsers/string.js';

export type PhoneRequestedStatus = 'sent' | 'cancelled' | string;

Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/bridge/events/parsers/popupClosed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { json, string } from '../../../parsing/index.js';
import { json } from '../../../parsing/parsers/json.js';
import { string } from '../../../parsing/parsers/string.js';

export interface PopupClosedPayload {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/bridge/events/parsers/qrTextReceived.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { json, string } from '../../../parsing/index.js';
import { json } from '../../../parsing/parsers/json.js';
import { string } from '../../../parsing/parsers/string.js';

export interface QrTextReceivedPayload {
/**
Expand Down
6 changes: 4 additions & 2 deletions packages/sdk/src/bridge/events/parsers/theme-changed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { RGB } from '../../../colors/index.js';
import { json, rgb, toRecord } from '../../../parsing/index.js';
import type { RGB } from '../../../colors/types.js';
import { json } from '../../../parsing/parsers/json.js';
import { rgb } from '../../../parsing/parsers/rgb.js';
import { toRecord } from '../../../parsing/toRecord.js';

export interface ThemeChangedPayload {
/**
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/src/bridge/events/parsers/viewportChanged.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { boolean, json, number } from '../../../parsing/index.js';
import { boolean } from '../../../parsing/parsers/boolean.js';
import { json } from '../../../parsing/parsers/json.js';
import { number } from '../../../parsing/parsers/number.js';

export interface ViewportChangedPayload {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { json, string } from '../../../parsing/index.js';
import { json } from '../../../parsing/parsers/json.js';
import { string } from '../../../parsing/parsers/string.js';

export type WriteAccessRequestedStatus = 'allowed' | string;

Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/bridge/events/singletonEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createEmitter } from '../../bridge/events/createEmitter.js';
import type { MiniAppsEventEmitter } from '../../bridge/index.js';
import { createEmitter } from './createEmitter.js';
import type { MiniAppsEventEmitter } from './events.js';

const CACHED_EMITTER = 'telegram-mini-apps-cached-emitter';

Expand Down
7 changes: 0 additions & 7 deletions packages/sdk/src/bridge/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/sdk/src/bridge/invokeCustomMethod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CustomMethodName, CustomMethodParams } from './methods/index.js';
import type { CustomMethodName, CustomMethodParams } from './methods/custom-methods.js';
import { request } from './request.js';
import type { ExecuteWithOptions } from '../types/index.js';
import type { ExecuteWithOptions } from '../types/methods.js';

/**
* Invokes known custom method. Returns method execution result.
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/bridge/methods/__tests__/createPostEvent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, it, vi } from 'vitest';

import { createPostEvent } from '../../index';
import { createPostEvent } from '../createPostEvent';
import * as postEventModule from '../postEvent';

vi.mock('../../bridge/methods/postEvent.js', () => ({
vi.mock('../postEvent', () => ({
postEvent: vi.fn(),
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/bridge/methods/__tests__/postEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'vitest';

import { setTargetOrigin } from '../../../globals';
import { postEvent } from '../../index';
import { postEvent } from '../postEvent';

let windowSpy: SpyInstance<[], Window & typeof globalThis>;

Expand Down
9 changes: 5 additions & 4 deletions packages/sdk/src/bridge/methods/createPostEvent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { type PostEvent, postEvent } from './postEvent.js';
import { isRecord } from '../../misc/index.js';
import { supports } from '../../supports/index.js';
import type { Version } from '../../version/index.js';
import { MethodUnsupportedError, ParameterUnsupportedError } from '../errors/index.js';
import { isRecord } from '../../misc/isRecord.js';
import { supports } from '../../supports/supports.js';
import type { Version } from '../../version/types.js';
import { MethodUnsupportedError } from '../errors/MethodUnsupportedError.js';
import { ParameterUnsupportedError } from '../errors/ParameterUnsupportedError.js';

/**
* Creates function which checks if specified method and parameters are supported. In case,
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/bridge/methods/custom-methods.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RequestId } from '../../types/index.js';
import type { RequestId } from '../../types/request-id.js';

interface CreateInvokeCustomMethodParams<M extends string, Params extends object> {
/**
Expand Down
6 changes: 0 additions & 6 deletions packages/sdk/src/bridge/methods/index.ts

This file was deleted.

7 changes: 5 additions & 2 deletions packages/sdk/src/bridge/methods/methods.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { AnyInvokeCustomMethodParams } from './custom-methods.js';
import type { AnyHapticFeedbackParams } from './haptic.js';
import type { PopupParams } from './popup.js';
import type { RGB } from '../../colors/index.js';
import type { IsNever, Not, RequestId, UnionKeys } from '../../types/index.js';
import type { RGB } from '../../colors/types.js';
import type { Not } from '../../types/logical.js';
import type { RequestId } from '../../types/request-id.js';
import type { UnionKeys } from '../../types/unions.js';
import type { IsNever } from '../../types/utils.js';

/**
* Color key which could be used to update header color.
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk/src/bridge/methods/postEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import type {
} from './methods.js';
import { logger, targetOrigin as globalTargetOrigin } from '../../globals.js';
import { isIframe } from '../../misc/isIframe.js';
import {
hasExternalNotify,
hasWebviewProxy,
} from '../env/index.js';
import { hasExternalNotify } from '../env/hasExternalNotify.js';
import { hasWebviewProxy } from '../env/hasWebviewProxy.js';

interface PostEventOptions {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/bridge/parseMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { json, string } from '../parsing/index.js';
import { json } from '../parsing/parsers/json.js';
import { string } from '../parsing/parsers/string.js';

/**
* Message format used in communication between client and Telegram applications.
Expand Down
35 changes: 18 additions & 17 deletions packages/sdk/src/bridge/request.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import {
type MiniAppsEventHasParams,
type MiniAppsEventName,
type MiniAppsEventParams,
on,
} from './events/index.js';
import {
type MiniAppsEmptyMethodName,
type MiniAppsMethodAcceptParams,
type MiniAppsMethodName,
type MiniAppsMethodParams,
type MiniAppsNonEmptyMethodName,
postEvent as defaultPostEvent,
} from './methods/index.js';
import { isRecord } from '../misc/index.js';
import { withTimeout } from '../timeout/index.js';
import type { And, ExecuteWithOptions, If, IsNever } from '../types/index.js';
import type {
MiniAppsEventHasParams,
MiniAppsEventName,
MiniAppsEventParams,
} from './events/events.js';
import { on } from './events/on.js';
import type {
MiniAppsEmptyMethodName,
MiniAppsMethodAcceptParams,
MiniAppsMethodName,
MiniAppsMethodParams, MiniAppsNonEmptyMethodName,
} from './methods/methods.js';
import { postEvent as defaultPostEvent } from './methods/postEvent.js';
import { isRecord } from '../misc/isRecord.js';
import { withTimeout } from '../timeout/withTimeout.js';
import type { And, If } from '../types/logical.js';
import type { ExecuteWithOptions } from '../types/methods.js';
import type { IsNever } from '../types/utils.js';

/**
* Names of methods, which require passing "req_id" parameter.
Expand Down
2 changes: 0 additions & 2 deletions packages/sdk/src/classnames/index.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/sdk/src/classnames/mergeClassNames.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { classNames } from './classNames.js';
import { isRecord } from '../misc/index.js';
import type { UnionOptionalKeys, UnionRequiredKeys } from '../types/index.js';
import { isRecord } from '../misc/isRecord.js';
import type { UnionOptionalKeys, UnionRequiredKeys } from '../types/unions.js';

type MergeClassNames<Tuple extends any[]> =
export type MergeClassNames<Tuple extends any[]> =
// Removes all types from union which will be ignored by the mergeClassNames function.
Exclude<Tuple[number], number | string | null | undefined | any[] | boolean> extends infer Union
? {
Expand Down
2 changes: 0 additions & 2 deletions packages/sdk/src/closing-behavior/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/sdk/src/cloud-storage/index.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/sdk/src/colors/index.ts

This file was deleted.

Loading

0 comments on commit 27e477b

Please sign in to comment.