Skip to content

Commit

Permalink
Merge pull request #547 from xmtp/rygine/path-aliases
Browse files Browse the repository at this point in the history
Add path aliases, update imports
  • Loading branch information
rygine authored Mar 13, 2024
2 parents 2ea26a3 + 5d76d3f commit 054a86e
Show file tree
Hide file tree
Showing 99 changed files with 658 additions and 657 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.test.js
*.test.ts
dist
coverage
docs
tmp
24 changes: 15 additions & 9 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ module.exports = {
fixMixedExportsWithInlineTypeSpecifier: false,
},
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
ignoreRestSiblings: true,
varsIgnorePattern: '^_',
},
],
'prettier/prettier': 'error',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-description': 'off',
Expand All @@ -36,16 +46,12 @@ module.exports = {
message:
'Do not import directly from `crypto`, use `src/crypto/crypto` instead.',
},
{
selector: 'ImportDeclaration[source.value=/^\\.\\./]',
message:
'Relative parent imports are not allowed, use path aliases instead.',
},
],
},
plugins: ['@typescript-eslint', 'prettier', 'jsdoc'],
ignorePatterns: [
'dist',
'node_modules',
'examples',
'scripts',
'src/types',
'docs',
'tmp',
],
}
13 changes: 5 additions & 8 deletions bench/decode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import {
ConversationV1,
ConversationV2,
} from './../src/conversations/Conversation'
import { MessageV1 } from '../src/Message'
import { newLocalHostClient } from '../test/helpers'
import { SignedPublicKeyBundle } from '../src/crypto'
import { ConversationV1, ConversationV2 } from '@/conversations/Conversation'
import { MessageV1 } from '@/Message'
import { newLocalHostClient } from '@test/helpers'
import {
MESSAGE_SIZES,
newPrivateKeyBundle,
Expand All @@ -13,7 +9,8 @@ import {
} from './helpers'
import { add } from 'benny'
import { fetcher } from '@xmtp/proto'
import { dateToNs } from '../src/utils'
import { dateToNs } from '@/utils/date'
import { SignedPublicKeyBundle } from '@/crypto/PublicKeyBundle'

const decodeV1 = () => {
return MESSAGE_SIZES.map((size) =>
Expand Down
11 changes: 6 additions & 5 deletions bench/encode.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ConversationV2 } from './../src/conversations/Conversation'
import { MessageV1 } from '../src/Message'
import { ConversationV2 } from '@/conversations/Conversation'
import { MessageV1 } from '@/Message'
import { add } from 'benny'
import { Client, dateToNs } from '../src'
import { newWallet, newLocalHostClient } from '../test/helpers'
import { SignedPublicKeyBundle } from '../src/crypto'
import { newWallet, newLocalHostClient } from '@test/helpers'
import {
MESSAGE_SIZES,
newPrivateKeyBundle,
randomBytes,
wrapSuite,
} from './helpers'
import Client from '@/Client'
import { dateToNs } from '@/utils/date'
import { SignedPublicKeyBundle } from '@/crypto/PublicKeyBundle'

const encodeV1 = () => {
return MESSAGE_SIZES.map((size) =>
Expand Down
6 changes: 3 additions & 3 deletions bench/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type Benchmark from 'benchmark'
import { suite, save, cycle } from 'benny'
import type { Config } from 'benny/lib/internal/common-types'
import crypto from '../src/crypto/crypto'
import { PrivateKeyBundleV1 } from '../src/crypto/PrivateKeyBundle'
import { newWallet } from '../test/helpers'
import crypto from '@/crypto/crypto'
import { PrivateKeyBundleV1 } from '@/crypto/PrivateKeyBundle'
import { newWallet } from '@test/helpers'

const MAX_RANDOM_BYTES_SIZE = 65536

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@
"rollup": "^4.12.1",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-filesize": "^10.0.0",
"rollup-plugin-tsconfig-paths": "^1.5.2",
"semantic-release": "^21.1.2",
"typedoc": "^0.25.12",
"typescript": "^5.4.2",
"vite": "5.1.4",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.3.1"
},
"packageManager": "[email protected]",
Expand Down
3 changes: 3 additions & 0 deletions rollup.config.bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from 'rollup'
import typescript from '@rollup/plugin-typescript'
import json from '@rollup/plugin-json'
import tsConfigPaths from 'rollup-plugin-tsconfig-paths'

const external = [
'@noble/secp256k1',
Expand All @@ -11,11 +12,13 @@ const external = [
'benny',
'crypto',
'elliptic',
'ethers',
'long',
'viem',
]

const plugins = [
tsConfigPaths(),
typescript({
declaration: false,
declarationMap: false,
Expand Down
4 changes: 3 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import filesize from 'rollup-plugin-filesize'
import json from '@rollup/plugin-json'
import terser from '@rollup/plugin-terser'
import { resolveExtensions } from '@xmtp/rollup-plugin-resolve-extensions'
import tsConfigPaths from 'rollup-plugin-tsconfig-paths'

const external = [
'@noble/secp256k1',
Expand All @@ -20,6 +21,7 @@ const external = [
]

const plugins = [
tsConfigPaths(),
typescript({
declaration: false,
declarationMap: false,
Expand Down Expand Up @@ -59,7 +61,7 @@ export default defineConfig([
file: 'dist/index.d.ts',
format: 'es',
},
plugins: [dts()],
plugins: [tsConfigPaths(), dts()],
},
{
input: 'src/index.ts',
Expand Down
7 changes: 5 additions & 2 deletions src/ApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { messageApi } from '@xmtp/proto'
import type { NotifyStreamEntityArrival } from '@xmtp/proto/ts/dist/types/fetch.pb'
import { b64Decode, retry, sleep, toNanoString } from './utils'
import AuthCache from './authn/AuthCache'
import type { Authenticator } from './authn'
import type { Authenticator } from '@/authn/interfaces'
// eslint-disable-next-line no-restricted-syntax
import { version } from '../package.json'
import { XMTP_DEV_WARNING } from './constants'
import type { Flatten } from './utils/typedefs'
import { b64Decode } from '@/utils/bytes'
import { retry, sleep } from '@/utils/async'
import { toNanoString } from '@/utils/date'
export const { MessageApi, SortDirection } = messageApi

const RETRY_SLEEP_TIME = 100
Expand Down
52 changes: 24 additions & 28 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import { PrivateKeyBundleV1 } from './crypto/PrivateKeyBundle'
import { PublicKeyBundle, SignedPublicKeyBundle } from './crypto'
import type {
EnvelopeMapper,
EnvelopeMapperWithMessage,
EnvelopeWithMessage,
} from './utils'
import {
buildUserContactTopic,
mapPaginatedStream,
buildUserInviteTopic,
isBrowser,
getSigner,
} from './utils'
import type { Signer } from './types/Signer'
import { Conversations } from './conversations'
import Conversations from '@/conversations/Conversations'
import { ContentTypeText, TextCodec } from './codecs/Text'
import type { ContentCodec, EncodedContent } from './MessageContent'
import { ContentTypeId } from './MessageContent'
Expand All @@ -22,30 +9,39 @@ import { content as proto, messageApi } from '@xmtp/proto'
import { decodeContactBundle, encodeContactBundle } from './ContactBundle'
import type { ApiClient, PublishParams } from './ApiClient'
import HttpApiClient, { ApiUrls, SortDirection } from './ApiClient'
import { KeystoreAuthenticator } from './authn'
import KeystoreAuthenticator from '@/authn/KeystoreAuthenticator'
import type { Flatten } from './utils/typedefs'
import type BackupClient from './message-backup/BackupClient'
import { BackupType } from './message-backup/BackupClient'
import { createBackupClient } from './message-backup/BackupClientFactory'
import type { KeystoreProvider } from './keystore/providers'
import {
KeyGeneratorKeystoreProvider,
KeystoreProviderUnavailableError,
NetworkKeystoreProvider,
SnapProvider,
StaticKeystoreProvider,
} from './keystore/providers'
import type { Persistence } from './keystore/persistence'
import {
BrowserStoragePersistence,
InMemoryPersistence,
} from './keystore/persistence'
import type { KeystoreProvider } from './keystore/providers/interfaces'
import { hasMetamaskWithSnaps } from './keystore/snapHelpers'
import { packageName, version } from './snapInfo.json'
import type { ExtractDecodedType } from './types/client'
import { getAddress, type WalletClient } from 'viem'
import { Contacts } from './Contacts'
import type { KeystoreInterfaces } from './keystore/rpcDefinitions'
import { isBrowser } from '@/utils/browser'
import { getSigner } from '@/utils/viem'
import { buildUserContactTopic, buildUserInviteTopic } from '@/utils/topic'
import { mapPaginatedStream } from '@/utils/async'
import type {
EnvelopeMapperWithMessage,
EnvelopeMapper,
EnvelopeWithMessage,
} from '@/utils/async'
import type { Persistence } from '@/keystore/persistence/interface'
import BrowserStoragePersistence from '@/keystore/persistence/BrowserStoragePersistence'
import InMemoryPersistence from '@/keystore/persistence/InMemoryPersistence'
import SnapProvider from '@/keystore/providers/SnapProvider'
import StaticKeystoreProvider from '@/keystore/providers/StaticKeystoreProvider'
import NetworkKeystoreProvider from '@/keystore/providers/NetworkKeystoreProvider'
import KeyGeneratorKeystoreProvider from '@/keystore/providers/KeyGeneratorKeystoreProvider'
import { KeystoreProviderUnavailableError } from '@/keystore/providers/errors'
import {
PublicKeyBundle,
SignedPublicKeyBundle,
} from '@/crypto/PublicKeyBundle'
const { Compression } = proto

// eslint-disable @typescript-eslint/explicit-module-boundary-types
Expand Down
5 changes: 4 additions & 1 deletion src/ContactBundle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {
PublicKeyBundle,
SignedPublicKeyBundle,
} from '@/crypto/PublicKeyBundle'
import { contact, publicKey } from '@xmtp/proto'
import { PublicKeyBundle, SignedPublicKeyBundle } from './crypto'

// Decodes contact bundles from the contact topic.
export function decodeContactBundle(
Expand Down
5 changes: 3 additions & 2 deletions src/Contacts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type Client from './Client'
import { privatePreferences } from '@xmtp/proto'
import type { EnvelopeWithMessage } from './utils'
import { buildUserPrivatePreferencesTopic, fromNanoString } from './utils'
import Stream from './Stream'
import type { OnConnectionLostCallback } from './ApiClient'
import JobRunner from './conversations/JobRunner'
import type { EnvelopeWithMessage } from '@/utils/async'
import { fromNanoString } from '@/utils/date'
import { buildUserPrivatePreferencesTopic } from '@/utils/topic'

export type ConsentState = 'allowed' | 'denied' | 'unknown'

Expand Down
5 changes: 3 additions & 2 deletions src/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import type { messageApi } from '@xmtp/proto'
import { invitation } from '@xmtp/proto'
import crypto from './crypto/crypto'
import Ciphertext from './crypto/Ciphertext'
import { decrypt, encrypt } from './crypto'
import { decrypt, encrypt } from './crypto/encryption'
import type { PrivateKeyBundleV2 } from './crypto/PrivateKeyBundle'
import { dateToNs, buildDirectMessageTopicV2 } from './utils'
import { buildDirectMessageTopicV2 } from '@/utils/topic'
import { dateToNs } from '@/utils/date'

export type InvitationContext = {
conversationId: string
Expand Down
5 changes: 3 additions & 2 deletions src/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import type { conversationReference } from '@xmtp/proto'
import { message as proto } from '@xmtp/proto'
import Long from 'long'
import Ciphertext from './crypto/Ciphertext'
import { PublicKeyBundle, PublicKey } from './crypto'
import { bytesToHex } from './crypto/utils'
import { sha256 } from './crypto/encryption'
import type { ContentTypeId } from './MessageContent'
import { dateToNs, nsToDate } from './utils'
import { dateToNs, nsToDate } from './utils/date'
import { buildDecryptV1Request, getResultOrThrow } from './utils/keystore'
import type { KeystoreInterfaces } from './keystore/rpcDefinitions'
import { PublicKeyBundle } from '@/crypto/PublicKeyBundle'
import { PublicKey } from '@/crypto/PublicKey'

const headerBytesAndCiphertext = (
msg: proto.Message
Expand Down
2 changes: 1 addition & 1 deletion src/authn/AuthData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authn as authnProto } from '@xmtp/proto'
import type Long from 'long'
import { dateToNs } from '../utils/date'
import { dateToNs } from '@/utils/date'

export default class AuthData implements authnProto.AuthData {
walletAddr: string
Expand Down
4 changes: 2 additions & 2 deletions src/authn/KeystoreAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { authn } from '@xmtp/proto'
import { dateToNs } from '../utils'
import { dateToNs } from '@/utils/date'
import Token from './Token'
import type {
KeystoreInterface,
KeystoreInterfaces,
} from '../keystore/rpcDefinitions'
} from '@/keystore/rpcDefinitions'

const wrapToken = (token: authn.Token): Token => {
if (token instanceof Token) {
Expand Down
2 changes: 1 addition & 1 deletion src/authn/LocalAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { authn, signature, publicKey } from '@xmtp/proto'
import AuthData from './AuthData'
import type { PrivateKey } from '../crypto'
import Token from './Token'
import { hexToBytes, keccak256 } from 'viem'
import type { PrivateKey } from '@/crypto/PrivateKey'

export default class LocalAuthenticator {
private identityKey: PrivateKey
Expand Down
6 changes: 0 additions & 6 deletions src/authn/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/codecs/Composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type {
ContentCodec,
EncodedContent,
CodecRegistry,
} from '../MessageContent'
import { ContentTypeId } from '../MessageContent'
} from '@/MessageContent'
import { ContentTypeId } from '@/MessageContent'
import { composite as proto } from '@xmtp/proto'

// xmtp.org/composite
Expand Down
4 changes: 2 additions & 2 deletions src/codecs/Text.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ContentCodec, EncodedContent } from '../MessageContent'
import { ContentTypeId } from '../MessageContent'
import type { ContentCodec, EncodedContent } from '@/MessageContent'
import { ContentTypeId } from '@/MessageContent'

// xmtp.org/text
//
Expand Down
Loading

0 comments on commit 054a86e

Please sign in to comment.