From d18614e0ecc00535cbac13d02e99541fd04d23f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 14:05:16 +0100 Subject: [PATCH 01/10] Fixes types for auth package Removes baseUrl configuration value from tsconfig.json which shows the bug of non-resolvable imports when package is used in dist --- packages/auth/src/connection/Connection.ts | 30 +++++++++---------- .../auth/src/connection/deriveSharedKey.ts | 2 +- .../src/connection/getDeviceUserFromGraph.ts | 6 ++-- packages/auth/src/connection/helpers.ts | 4 +-- packages/auth/src/connection/identity.ts | 4 +-- packages/auth/src/connection/message.ts | 2 +- .../connection/test/authentication.test.ts | 8 ++--- .../src/connection/test/connection.test.ts | 2 +- .../src/connection/test/encryption.test.ts | 2 +- .../auth/src/connection/test/identity.test.ts | 6 ++-- .../auth/src/connection/test/sync.test.ts | 4 +-- packages/auth/src/connection/types.ts | 8 ++--- packages/auth/src/device/createDevice.ts | 2 +- packages/auth/src/device/redact.ts | 2 +- packages/auth/src/invitation/create.ts | 6 ++-- packages/auth/src/invitation/deriveId.ts | 2 +- packages/auth/src/invitation/generateProof.ts | 4 +-- packages/auth/src/invitation/randomSeed.ts | 2 +- .../src/invitation/test/invitation.test.ts | 2 +- packages/auth/src/invitation/validate.ts | 4 +-- packages/auth/src/lockbox/create.ts | 2 +- packages/auth/src/lockbox/index.ts | 8 ++--- packages/auth/src/lockbox/open.ts | 2 +- packages/auth/src/lockbox/rotate.ts | 6 ++-- .../auth/src/lockbox/test/lockbox.test.ts | 8 ++--- packages/auth/src/role/index.ts | 4 +-- packages/auth/src/server/castServer.ts | 4 +-- packages/auth/src/team/Team.ts | 26 ++++++++-------- packages/auth/src/team/bySeniority.ts | 2 +- packages/auth/src/team/constants.ts | 4 +-- packages/auth/src/team/context.ts | 4 +-- packages/auth/src/team/createTeam.ts | 4 +-- packages/auth/src/team/load.ts | 4 +-- packages/auth/src/team/membershipResolver.ts | 10 +++---- packages/auth/src/team/reducer.ts | 4 +-- packages/auth/src/team/selectors/device.ts | 4 +-- .../src/team/selectors/deviceWasRemoved.ts | 2 +- packages/auth/src/team/selectors/hasMember.ts | 2 +- packages/auth/src/team/selectors/hasRole.ts | 2 +- packages/auth/src/team/selectors/hasServer.ts | 4 +-- .../auth/src/team/selectors/invitation.ts | 2 +- packages/auth/src/team/selectors/keyMap.ts | 2 +- packages/auth/src/team/selectors/keyring.ts | 2 +- packages/auth/src/team/selectors/keys.ts | 6 ++-- .../src/team/selectors/lockboxesInScope.ts | 4 +-- packages/auth/src/team/selectors/member.ts | 2 +- .../src/team/selectors/memberByDeviceId.ts | 2 +- .../auth/src/team/selectors/memberHasRole.ts | 6 ++-- .../src/team/selectors/memberWasRemoved.ts | 2 +- .../auth/src/team/selectors/membersInRole.ts | 4 +-- packages/auth/src/team/selectors/messages.ts | 2 +- packages/auth/src/team/selectors/role.ts | 2 +- packages/auth/src/team/selectors/server.ts | 4 +-- .../src/team/selectors/serverWasRemoved.ts | 4 +-- .../auth/src/team/selectors/teamKeyring.ts | 4 +-- .../team/selectors/test/visibleKeys.test.ts | 6 ++-- .../team/selectors/test/visibleScopes.test.ts | 6 ++-- .../auth/src/team/selectors/visibleKeys.ts | 4 +-- .../auth/src/team/selectors/visibleScopes.ts | 4 +-- .../auth/src/team/test/createTeam.test.ts | 4 +-- packages/auth/src/team/test/crypto.test.ts | 4 +-- packages/auth/src/team/test/devices.test.ts | 4 +-- .../auth/src/team/test/invitations.test.ts | 14 ++++----- packages/auth/src/team/test/keys.test.ts | 8 ++--- packages/auth/src/team/test/members.test.ts | 4 +-- .../src/team/test/membershipResolver.test.ts | 6 ++-- packages/auth/src/team/test/messages.test.ts | 2 +- packages/auth/src/team/test/roles.test.ts | 8 ++--- packages/auth/src/team/test/servers.test.ts | 8 ++--- .../auth/src/team/transforms/addDevice.ts | 4 +-- .../auth/src/team/transforms/addMember.ts | 4 +-- .../src/team/transforms/addMemberRoles.ts | 2 +- .../auth/src/team/transforms/addMessage.ts | 2 +- packages/auth/src/team/transforms/addRole.ts | 4 +-- .../auth/src/team/transforms/addServer.ts | 6 ++-- .../src/team/transforms/changeMemberKeys.ts | 2 +- .../src/team/transforms/changeServerKeys.ts | 2 +- .../src/team/transforms/collectLockboxes.ts | 4 +-- .../src/team/transforms/postInvitation.ts | 4 +-- .../auth/src/team/transforms/removeDevice.ts | 8 ++--- .../auth/src/team/transforms/removeMember.ts | 2 +- .../src/team/transforms/removeMemberRole.ts | 4 +-- .../auth/src/team/transforms/removeRole.ts | 4 +-- .../auth/src/team/transforms/removeServer.ts | 4 +-- .../src/team/transforms/revokeInvitation.ts | 2 +- .../auth/src/team/transforms/rotateKeys.ts | 2 +- .../auth/src/team/transforms/setTeamName.ts | 2 +- .../auth/src/team/transforms/useInvitation.ts | 4 +-- packages/auth/src/team/types.ts | 14 ++++----- packages/auth/src/team/validate.ts | 4 +-- packages/auth/src/util/actionFingerprint.ts | 2 +- packages/auth/src/util/composeTransforms.ts | 2 +- packages/auth/src/util/constants.ts | 2 +- packages/auth/src/util/graphSummary.ts | 4 +-- packages/auth/src/util/lockboxSummary.ts | 2 +- packages/auth/src/util/scopesMatch.ts | 6 ++-- .../src/util/testing/connectionHelpers.ts | 4 +-- .../auth/src/util/testing/expect/toBeValid.ts | 2 +- packages/auth/src/util/testing/index.ts | 8 ++--- .../auth/src/util/testing/joinTestChannel.ts | 4 +-- packages/auth/src/util/testing/setup.ts | 16 +++++----- packages/auth/tsconfig.json | 10 ++----- 102 files changed, 240 insertions(+), 244 deletions(-) diff --git a/packages/auth/src/connection/Connection.ts b/packages/auth/src/connection/Connection.ts index 3532318f..ceb256a4 100644 --- a/packages/auth/src/connection/Connection.ts +++ b/packages/auth/src/connection/Connection.ts @@ -10,7 +10,7 @@ import { } from '@localfirst/crdx' import { asymmetric, base58, randomKeyBytes, symmetric, type Hash } from '@localfirst/crypto' import { assert, debug } from '@localfirst/shared' -import { deriveSharedKey } from 'connection/deriveSharedKey.js' +import { deriveSharedKey } from './deriveSharedKey.js' import { DEVICE_REMOVED, DEVICE_UNKNOWN, @@ -25,19 +25,19 @@ import { UNHANDLED, createErrorMessage, type ConnectionErrorType, -} from 'connection/errors.js' -import { getDeviceUserFromGraph } from 'connection/getDeviceUserFromGraph.js' -import * as identity from 'connection/identity.js' -import type { ConnectionMessage, DisconnectMessage } from 'connection/message.js' -import { redactDevice } from 'device/index.js' -import * as invitations from 'invitation/index.js' +} from './errors.js' +import { getDeviceUserFromGraph } from './getDeviceUserFromGraph.js' +import * as identity from './identity.js' +import type { ConnectionMessage, DisconnectMessage } from './message.js' +import { redactDevice } from '../device/index.js' +import * as invitations from '../invitation/index.js' import { pack, unpack } from 'msgpackr' -import { getTeamState } from 'team/getTeamState.js' -import { Team, decryptTeamGraph, type TeamAction, type TeamContext } from 'team/index.js' -import * as select from 'team/selectors/index.js' -import { arraysAreEqual } from 'util/arraysAreEqual.js' -import { KeyType } from 'util/index.js' -import { syncMessageSummary } from 'util/testing/messageSummary.js' +import { getTeamState } from '../team/getTeamState.js' +import { Team, decryptTeamGraph, type TeamAction, type TeamContext } from '../team/index.js' +import * as select from '../team/selectors/index.js' +import { arraysAreEqual } from '../util/arraysAreEqual.js' +import { KeyType } from '../util/index.js' +import { syncMessageSummary } from '../util/testing/messageSummary.js' import { and, assertEvent, assign, createActor, setup } from 'xstate' import { MessageQueue, type NumberedMessage } from './MessageQueue.js' import { extendServerContext, getUserName, messageSummary, stateSummary } from './helpers.js' @@ -64,7 +64,7 @@ himself told me it's OK. So https://github.com/statelyai/xstate/discussions/4783#discussioncomment-8673350 The bulk of this class is an XState state machine. It's instantiated in the constructor. It looks -something like this: +something like this: ```ts const machine = setup({ @@ -80,7 +80,7 @@ const machine = setup({ ``` To understand the way this flows, the best place to start is the state machine definition passed to -`createMachine`. +`createMachine`. You can also visualize this machine in the Stately visualizer - here's a link that's current at time of writing this: diff --git a/packages/auth/src/connection/deriveSharedKey.ts b/packages/auth/src/connection/deriveSharedKey.ts index 791f1656..75f75dcb 100644 --- a/packages/auth/src/connection/deriveSharedKey.ts +++ b/packages/auth/src/connection/deriveSharedKey.ts @@ -1,5 +1,5 @@ import { hash, hashBytes, type Base58, base58 } from '@localfirst/crypto' -import { HashPurpose } from 'util/index.js' +import { HashPurpose } from '../util/index.js' /** * Takes two seeds (in this case, provided by each of two peers that are connecting) and diff --git a/packages/auth/src/connection/getDeviceUserFromGraph.ts b/packages/auth/src/connection/getDeviceUserFromGraph.ts index 4d80b16b..7dd21123 100644 --- a/packages/auth/src/connection/getDeviceUserFromGraph.ts +++ b/packages/auth/src/connection/getDeviceUserFromGraph.ts @@ -1,8 +1,8 @@ import { getLatestGeneration, type Keyring, type UserWithSecrets } from '@localfirst/crdx' import { assert } from '@localfirst/shared' -import { generateProof } from 'invitation/generateProof.js' -import { generateStarterKeys } from 'invitation/generateStarterKeys.js' -import { KeyType } from 'util/index.js' +import { generateProof } from '../invitation/generateProof.js' +import { generateStarterKeys } from '../invitation/generateStarterKeys.js' +import { KeyType } from '../util/index.js' import { getTeamState } from '../team/getTeamState.js' import * as select from '../team/selectors/index.js' diff --git a/packages/auth/src/connection/helpers.ts b/packages/auth/src/connection/helpers.ts index 04ff2959..fcf14aba 100644 --- a/packages/auth/src/connection/helpers.ts +++ b/packages/auth/src/connection/helpers.ts @@ -1,5 +1,5 @@ -import type { ConnectionMessage } from 'connection/message.js' -import { syncMessageSummary } from 'util/testing/messageSummary.js' +import type { ConnectionMessage } from './message.js' +import { syncMessageSummary } from '../util/testing/messageSummary.js' import type { Context, ServerContext } from './types.js' // HELPERS diff --git a/packages/auth/src/connection/identity.ts b/packages/auth/src/connection/identity.ts index 08868acf..dad02b23 100644 --- a/packages/auth/src/connection/identity.ts +++ b/packages/auth/src/connection/identity.ts @@ -6,8 +6,8 @@ import { type UnixTimestamp, } from '@localfirst/crdx' import { signatures, randomKey } from '@localfirst/crypto' -import { type Challenge } from 'connection/types.js' -import { VALID, type ValidationResult } from 'util/index.js' +import { type Challenge } from './types.js' +import { VALID, type ValidationResult } from '../util/index.js' export const challenge = (identityClaim: KeyScope): Challenge => ({ ...identityClaim, diff --git a/packages/auth/src/connection/message.ts b/packages/auth/src/connection/message.ts index d9ab62eb..f419458c 100644 --- a/packages/auth/src/connection/message.ts +++ b/packages/auth/src/connection/message.ts @@ -1,5 +1,5 @@ import type { Base58, Hash, Keyring, SyncMessage as SyncPayload } from '@localfirst/crdx' -import type { Challenge, IdentityClaim } from 'connection/types.js' +import type { Challenge, IdentityClaim } from './types.js' import type { ErrorMessage, LocalErrorMessage } from './errors.js' export type ReadyMessage = { diff --git a/packages/auth/src/connection/test/authentication.test.ts b/packages/auth/src/connection/test/authentication.test.ts index 533ebde0..4041371c 100644 --- a/packages/auth/src/connection/test/authentication.test.ts +++ b/packages/auth/src/connection/test/authentication.test.ts @@ -1,7 +1,7 @@ import { eventPromise, pause } from '@localfirst/shared' import { cloneDeep } from 'lodash-es' -import { ADMIN } from 'role/index.js' -import * as teams from 'team/index.js' +import { ADMIN } from '../../role/index.js' +import * as teams from '../../team/index.js' import { TestChannel, all, @@ -14,10 +14,10 @@ import { joinTestChannel, setup, tryToConnect, -} from 'util/testing/index.js' +} from '../../util/testing/index.js' import { describe, expect, it } from 'vitest' import type { InviteeDeviceContext } from '../types.js' -import { createDevice } from 'device/createDevice.js' +import { createDevice } from '../../device/createDevice.js' describe('connection', () => { describe('authentication', () => { diff --git a/packages/auth/src/connection/test/connection.test.ts b/packages/auth/src/connection/test/connection.test.ts index 5e5fe251..7f7ddda0 100644 --- a/packages/auth/src/connection/test/connection.test.ts +++ b/packages/auth/src/connection/test/connection.test.ts @@ -1,4 +1,4 @@ -import { TestChannel, all, connect, joinTestChannel, setup } from 'util/testing/index.js' +import { TestChannel, all, connect, joinTestChannel, setup } from '../../util/testing/index.js' import { pause } from '@localfirst/shared' import { describe, it } from 'vitest' diff --git a/packages/auth/src/connection/test/encryption.test.ts b/packages/auth/src/connection/test/encryption.test.ts index 5af8437e..ea309367 100644 --- a/packages/auth/src/connection/test/encryption.test.ts +++ b/packages/auth/src/connection/test/encryption.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { connect, setup } from 'util/testing/index.js' +import { connect, setup } from '../../util/testing/index.js' import { eventPromise } from '@localfirst/shared' import { randomKeyBytes } from '@localfirst/crypto' diff --git a/packages/auth/src/connection/test/identity.test.ts b/packages/auth/src/connection/test/identity.test.ts index d946d1ee..f006c7ab 100644 --- a/packages/auth/src/connection/test/identity.test.ts +++ b/packages/auth/src/connection/test/identity.test.ts @@ -1,6 +1,6 @@ -import { challenge, prove, verify } from 'connection/identity.js' -import { ADMIN_SCOPE, TEAM_SCOPE } from 'team/index.js' -import { setup } from 'util/testing/index.js' +import { challenge, prove, verify } from '../identity.js' +import { ADMIN_SCOPE, TEAM_SCOPE } from '../../team/index.js' +import { setup } from '../../util/testing/index.js' import 'util/testing/expect/toBeValid.js' import { type KeyScope, KeyType, createKeyset, redactKeys } from '@localfirst/crdx' import { describe, expect, it } from 'vitest' diff --git a/packages/auth/src/connection/test/sync.test.ts b/packages/auth/src/connection/test/sync.test.ts index 6f010ac0..7b501232 100644 --- a/packages/auth/src/connection/test/sync.test.ts +++ b/packages/auth/src/connection/test/sync.test.ts @@ -1,4 +1,4 @@ -import { ADMIN } from 'role/index.js' +import { ADMIN } from '../../role/index.js' import { TestChannel, any, @@ -13,7 +13,7 @@ import { joinTestChannel, setup, updated, -} from 'util/testing/index.js' +} from '../../util/testing/index.js' import { pause } from '@localfirst/shared' import { describe, expect, it } from 'vitest' import { type MemberContext } from '../types.js' diff --git a/packages/auth/src/connection/types.ts b/packages/auth/src/connection/types.ts index 5f70d56d..2e1e105b 100644 --- a/packages/auth/src/connection/types.ts +++ b/packages/auth/src/connection/types.ts @@ -15,10 +15,10 @@ import type { DeviceWithSecrets, FirstUseDevice, FirstUseDeviceWithSecrets, -} from 'device/index.js' -import type { ProofOfInvitation } from 'invitation/index.js' -import type { ServerWithSecrets } from 'server/index.js' -import type { Member, Team } from 'team/index.js' +} from '../device/index.js' +import type { ProofOfInvitation } from '../invitation/index.js' +import type { ServerWithSecrets } from '../server/index.js' +import type { Member, Team } from '../team/index.js' import type { ConnectionErrorPayload } from './errors.js' import type { ConnectionMessage } from './message.js' diff --git a/packages/auth/src/device/createDevice.ts b/packages/auth/src/device/createDevice.ts index f594cd75..cd394957 100644 --- a/packages/auth/src/device/createDevice.ts +++ b/packages/auth/src/device/createDevice.ts @@ -2,7 +2,7 @@ import { createKeyset, type UnixTimestamp } from '@localfirst/crdx' import { createId } from '@paralleldrive/cuid2' import { randomKey } from '@localfirst/crypto' import type { DeviceWithSecrets } from './types.js' -import { KeyType } from 'util/index.js' +import { KeyType } from '../util/index.js' export const createDevice = ({ userId, diff --git a/packages/auth/src/device/redact.ts b/packages/auth/src/device/redact.ts index 20c4d0a1..ec1e1fe9 100644 --- a/packages/auth/src/device/redact.ts +++ b/packages/auth/src/device/redact.ts @@ -1,5 +1,5 @@ import { redactKeys } from '@localfirst/crdx' -import { type DeviceWithSecrets, type Device } from 'device/types.js' +import { type DeviceWithSecrets, type Device } from './types.js' export const redactDevice = (device: DeviceWithSecrets): Device => ({ ...device, diff --git a/packages/auth/src/invitation/create.ts b/packages/auth/src/invitation/create.ts index 91bdd0dd..2c3c69b2 100644 --- a/packages/auth/src/invitation/create.ts +++ b/packages/auth/src/invitation/create.ts @@ -1,8 +1,8 @@ import { type UnixTimestamp } from '@localfirst/crdx' import { generateStarterKeys } from './generateStarterKeys.js' -import { deriveId } from 'invitation/deriveId.js' -import { normalize } from 'invitation/normalize.js' -import { type Invitation } from 'invitation/types.js' +import { deriveId } from './deriveId.js' +import { normalize } from './normalize.js' +import { type Invitation } from './types.js' export const IKEY_LENGTH = 16 diff --git a/packages/auth/src/invitation/deriveId.ts b/packages/auth/src/invitation/deriveId.ts index 6b3c2fbf..f968d16c 100644 --- a/packages/auth/src/invitation/deriveId.ts +++ b/packages/auth/src/invitation/deriveId.ts @@ -1,5 +1,5 @@ import { type Hash, hash, stretch } from '@localfirst/crypto' -import { HashPurpose } from 'util/index.js' +import { HashPurpose } from '../util/constants.js' export function deriveId(seed: string) { // ## Step 1b diff --git a/packages/auth/src/invitation/generateProof.ts b/packages/auth/src/invitation/generateProof.ts index 60ba191c..ee3ec77e 100644 --- a/packages/auth/src/invitation/generateProof.ts +++ b/packages/auth/src/invitation/generateProof.ts @@ -1,7 +1,7 @@ import { memoize } from '@localfirst/shared' import { signatures } from '@localfirst/crypto' -import { deriveId } from 'invitation/deriveId.js' -import { type ProofOfInvitation } from 'invitation/types.js' +import { deriveId } from './deriveId.js' +import { type ProofOfInvitation } from './types.js' import { generateStarterKeys } from './generateStarterKeys.js' import { normalize } from './normalize.js' diff --git a/packages/auth/src/invitation/randomSeed.ts b/packages/auth/src/invitation/randomSeed.ts index 95976345..ef08c5d7 100644 --- a/packages/auth/src/invitation/randomSeed.ts +++ b/packages/auth/src/invitation/randomSeed.ts @@ -1,5 +1,5 @@ import { randomKey } from '@localfirst/crypto' -import { IKEY_LENGTH } from 'invitation/create.js' +import { IKEY_LENGTH } from './create.js' /** * Randomly generates a 16-character base58 string, for example `4kgd5mwq5z4fmfwq`, to be used as diff --git a/packages/auth/src/invitation/test/invitation.test.ts b/packages/auth/src/invitation/test/invitation.test.ts index 911b4133..0b307387 100644 --- a/packages/auth/src/invitation/test/invitation.test.ts +++ b/packages/auth/src/invitation/test/invitation.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from 'vitest' -import { create, generateProof, randomSeed, validate } from 'invitation/index.js' +import { create, generateProof, randomSeed, validate } from '../index.js' describe('invitations', () => { test('create invitation', () => { diff --git a/packages/auth/src/invitation/validate.ts b/packages/auth/src/invitation/validate.ts index 842af632..d393c819 100644 --- a/packages/auth/src/invitation/validate.ts +++ b/packages/auth/src/invitation/validate.ts @@ -1,7 +1,7 @@ import { memoize } from '@localfirst/shared' import { signatures } from '@localfirst/crypto' -import { type Invitation, type InvitationState, type ProofOfInvitation } from 'invitation/types.js' -import { VALID, type ValidationResult } from 'util/index.js' +import { type Invitation, type InvitationState, type ProofOfInvitation } from './types.js' +import { VALID, type ValidationResult } from '../util/index.js' export const invitationCanBeUsed = (invitation: InvitationState, timeOfUse: number) => { const { revoked, maxUses, uses, expiration } = invitation diff --git a/packages/auth/src/lockbox/create.ts b/packages/auth/src/lockbox/create.ts index 44f30c69..7ed7b5cf 100644 --- a/packages/auth/src/lockbox/create.ts +++ b/packages/auth/src/lockbox/create.ts @@ -1,6 +1,6 @@ import { EPHEMERAL_SCOPE, type Keyset, type KeysetWithSecrets, redactKeys } from '@localfirst/crdx' import { asymmetric } from '@localfirst/crypto' -import { isKeyManifest, type KeyManifest, type Lockbox } from 'lockbox/types.js' +import { isKeyManifest, type KeyManifest, type Lockbox } from './types.js' /** Creates a new lockbox that can be opened using the recipient's private key. */ export const create = ( diff --git a/packages/auth/src/lockbox/index.ts b/packages/auth/src/lockbox/index.ts index ac05333e..d78e3ca0 100644 --- a/packages/auth/src/lockbox/index.ts +++ b/packages/auth/src/lockbox/index.ts @@ -1,4 +1,4 @@ -export * from 'lockbox/create.js' -export * from 'lockbox/open.js' -export * from 'lockbox/rotate.js' -export * from 'lockbox/types.js' +export * from './create.js' +export * from './open.js' +export * from './rotate.js' +export * from './types.js' diff --git a/packages/auth/src/lockbox/open.ts b/packages/auth/src/lockbox/open.ts index 5189ff6e..546b12f9 100644 --- a/packages/auth/src/lockbox/open.ts +++ b/packages/auth/src/lockbox/open.ts @@ -1,7 +1,7 @@ import { memoize } from '@localfirst/shared' import { type KeysetWithSecrets } from '@localfirst/crdx' import { asymmetric } from '@localfirst/crypto' -import { type Lockbox } from 'lockbox/types.js' +import { type Lockbox } from './types.js' export const open = memoize( (lockbox: Lockbox, decryptionKeys: KeysetWithSecrets): KeysetWithSecrets => { diff --git a/packages/auth/src/lockbox/rotate.ts b/packages/auth/src/lockbox/rotate.ts index 5d5361a5..442b98b2 100644 --- a/packages/auth/src/lockbox/rotate.ts +++ b/packages/auth/src/lockbox/rotate.ts @@ -1,7 +1,7 @@ import { type Keyset, type KeysetWithSecrets } from '@localfirst/crdx' -import { create } from 'lockbox/create.js' -import { type Lockbox } from 'lockbox/types.js' -import { assertScopesMatch } from 'util/index.js' +import { create } from './create.js' +import { type Lockbox } from './types.js' +import { assertScopesMatch } from '../util/index.js' /** * "Rotating" a lockbox means replacing the keys it contains with new ones. diff --git a/packages/auth/src/lockbox/test/lockbox.test.ts b/packages/auth/src/lockbox/test/lockbox.test.ts index afe93c37..6b0c97e7 100644 --- a/packages/auth/src/lockbox/test/lockbox.test.ts +++ b/packages/auth/src/lockbox/test/lockbox.test.ts @@ -1,9 +1,9 @@ import { createKeyset } from '@localfirst/crdx' import { describe, expect, it } from 'vitest' -import { create, open, rotate } from 'lockbox/index.js' -import { ADMIN } from 'role/index.js' -import { KeyType } from 'util/index.js' -import { setup } from 'util/testing/index.js' +import { create, open, rotate } from '../index.js' +import { KeyType } from '../../util/types.js' +import { setup } from '../../util/testing/setup.js' +import { ADMIN } from '../../role/constants.js' const { bob, eve } = setup('alice', 'bob', { user: 'eve', member: false }) const MANAGERS = 'managers' diff --git a/packages/auth/src/role/index.ts b/packages/auth/src/role/index.ts index e64eb85a..384fc2bc 100644 --- a/packages/auth/src/role/index.ts +++ b/packages/auth/src/role/index.ts @@ -1,2 +1,2 @@ -export * from 'role/constants.js' -export * from 'role/types.js' +export * from './constants.js' +export * from './types.js' diff --git a/packages/auth/src/server/castServer.ts b/packages/auth/src/server/castServer.ts index 4957eed8..95e60775 100644 --- a/packages/auth/src/server/castServer.ts +++ b/packages/auth/src/server/castServer.ts @@ -1,7 +1,7 @@ import type { User, UserWithSecrets } from '@localfirst/crdx' import type { Server, ServerWithSecrets } from './types.js' -import type { Device, DeviceWithSecrets } from 'device/index.js' -import type { Member } from 'team/index.js' +import type { Device, DeviceWithSecrets } from '../device/index.js' +import type { Member } from '../team/index.js' const toMember = (server: Server): Member => ({ userId: server.host, diff --git a/packages/auth/src/team/Team.ts b/packages/auth/src/team/Team.ts index d2fbbb51..237a3067 100644 --- a/packages/auth/src/team/Team.ts +++ b/packages/auth/src/team/Team.ts @@ -21,19 +21,19 @@ import { } from '@localfirst/crdx' import { randomKey, signatures, symmetric, type Base58 } from '@localfirst/crypto' import { assert, debug } from '@localfirst/shared' -import * as identity from 'connection/identity.js' -import { type Challenge } from 'connection/types.js' -import * as devices from 'device/index.js' -import { redactDevice, type Device } from 'device/index.js' -import * as invitations from 'invitation/index.js' -import { type ProofOfInvitation } from 'invitation/index.js' -import { normalize } from 'invitation/normalize.js' -import * as lockbox from 'lockbox/index.js' -import { ADMIN, type Role } from 'role/index.js' -import { castServer } from 'server/castServer.js' -import { type Host, type Server } from 'server/types.js' -import { type LocalUserContext } from 'team/context.js' -import { KeyType, VALID, scopesMatch } from 'util/index.js' +import * as identity from '../connection/identity.js' +import { type Challenge } from '../connection/types.js' +import * as devices from '../device/index.js' +import { redactDevice, type Device } from '../device/index.js' +import * as invitations from '../invitation/index.js' +import { type ProofOfInvitation } from '../invitation/index.js' +import { normalize } from '../invitation/normalize.js' +import * as lockbox from '../lockbox/index.js' +import { ADMIN, type Role } from '../role/index.js' +import { castServer } from '../server/castServer.js' +import { type Host, type Server } from '../server/types.js' +import { type LocalUserContext } from './context.js' +import { KeyType, VALID, scopesMatch } from '../util/index.js' import { ADMIN_SCOPE, ALL, TEAM_SCOPE, initialState } from './constants.js' import { membershipResolver as resolver } from './membershipResolver.js' import { redactUser } from './redactUser.js' diff --git a/packages/auth/src/team/bySeniority.ts b/packages/auth/src/team/bySeniority.ts index db4e8353..d45fd24f 100644 --- a/packages/auth/src/team/bySeniority.ts +++ b/packages/auth/src/team/bySeniority.ts @@ -1,5 +1,5 @@ import { isPredecessor } from '@localfirst/crdx' -import { type TeamGraph, type TeamLink } from 'team/types.js' +import { type TeamGraph, type TeamLink } from './types.js' import { assert } from '@localfirst/shared' export const bySeniority = (chain: TeamGraph) => (a: string, b: string) => { diff --git a/packages/auth/src/team/constants.ts b/packages/auth/src/team/constants.ts index 80f9b762..d9f3bfb9 100644 --- a/packages/auth/src/team/constants.ts +++ b/packages/auth/src/team/constants.ts @@ -1,7 +1,7 @@ import { type KeyScope } from '@localfirst/crdx' import { type TeamState } from './types.js' -import { ADMIN } from 'role/index.js' -import { KeyType } from 'util/index.js' +import { ADMIN } from '../role/index.js' +import { KeyType } from '../util/index.js' export const ALL = 'ALL' diff --git a/packages/auth/src/team/context.ts b/packages/auth/src/team/context.ts index 3c852740..604479f9 100644 --- a/packages/auth/src/team/context.ts +++ b/packages/auth/src/team/context.ts @@ -1,6 +1,6 @@ import { type UserWithSecrets } from '@localfirst/crdx' -import { type DeviceWithSecrets } from 'device/index.js' -import { type ServerWithSecrets } from 'server/index.js' +import { type DeviceWithSecrets } from '../device/index.js' +import { type ServerWithSecrets } from '../server/index.js' export type LocalContext = LocalUserContext | LocalServerContext diff --git a/packages/auth/src/team/createTeam.ts b/packages/auth/src/team/createTeam.ts index b596a238..8f56e92d 100644 --- a/packages/auth/src/team/createTeam.ts +++ b/packages/auth/src/team/createTeam.ts @@ -1,7 +1,7 @@ import { createKeyset } from '@localfirst/crdx' import { TEAM_SCOPE } from './constants.js' -import { type LocalContext } from 'team/context.js' -import { Team } from 'team/Team.js' +import { type LocalContext } from './context.js' +import { Team } from './Team.js' export function createTeam(teamName: string, context: LocalContext, seed?: string) { const teamKeys = createKeyset(TEAM_SCOPE, seed) diff --git a/packages/auth/src/team/load.ts b/packages/auth/src/team/load.ts index 16fcc0ac..e680d312 100644 --- a/packages/auth/src/team/load.ts +++ b/packages/auth/src/team/load.ts @@ -1,7 +1,7 @@ import { type Keyring, type KeysetWithSecrets, createKeyring } from '@localfirst/crdx' import { type TeamGraph } from './types.js' -import { type LocalContext } from 'team/context.js' -import { Team } from 'team/Team.js' +import { type LocalContext } from '../team/context.js' +import { Team } from '../team/Team.js' export const load = ( source: Uint8Array | TeamGraph, diff --git a/packages/auth/src/team/membershipResolver.ts b/packages/auth/src/team/membershipResolver.ts index c8091979..8ee8e06f 100644 --- a/packages/auth/src/team/membershipResolver.ts +++ b/packages/auth/src/team/membershipResolver.ts @@ -1,8 +1,8 @@ import { getConcurrentBubbles, type Link, type Resolver } from '@localfirst/crdx' import { isAdminOnlyAction } from './isAdminOnlyAction.js' -import { type Invitation } from 'invitation/index.js' -import { ADMIN } from 'role/index.js' -import { bySeniority } from 'team/bySeniority.js' +import { type Invitation } from '../invitation/index.js' +import { ADMIN } from '../role/index.js' +import { bySeniority } from './bySeniority.js' import { type MembershipRuleEnforcer, type AddMemberAction, @@ -14,8 +14,8 @@ import { type TeamLink, type TeamGraph, type AdmitMemberAction, -} from 'team/types.js' -import { arraysAreEqual } from 'util/arraysAreEqual.js' +} from './types.js' +import { arraysAreEqual } from '../util/arraysAreEqual.js' /** * This is a custom resolver, used to flatten a graph of team membership operations into a strictly diff --git a/packages/auth/src/team/reducer.ts b/packages/auth/src/team/reducer.ts index 83065a0a..7e1e40a9 100644 --- a/packages/auth/src/team/reducer.ts +++ b/packages/auth/src/team/reducer.ts @@ -1,6 +1,6 @@ import { ROOT, type Reducer } from '@localfirst/crdx' -import { ADMIN } from 'role/index.js' -import { clone, composeTransforms } from 'util/index.js' +import { ADMIN } from '../role/index.js' +import { clone, composeTransforms } from '../util/index.js' import { invalidLinkReducer } from './invalidLinkReducer.js' import { setHead } from './setHead.js' import { diff --git a/packages/auth/src/team/selectors/device.ts b/packages/auth/src/team/selectors/device.ts index 14c6b877..57f994e8 100644 --- a/packages/auth/src/team/selectors/device.ts +++ b/packages/auth/src/team/selectors/device.ts @@ -1,8 +1,8 @@ -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' import { assert } from '@localfirst/shared' import { server } from './server.js' import { hasServer } from './hasServer.js' -import { castServer } from 'server/castServer.js' +import { castServer } from '../../server/castServer.js' export const hasDevice = ( state: TeamState, diff --git a/packages/auth/src/team/selectors/deviceWasRemoved.ts b/packages/auth/src/team/selectors/deviceWasRemoved.ts index 223f76bd..8f1ef97e 100644 --- a/packages/auth/src/team/selectors/deviceWasRemoved.ts +++ b/packages/auth/src/team/selectors/deviceWasRemoved.ts @@ -1,4 +1,4 @@ -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' import { hasDevice } from './device.js' export const deviceWasRemoved = (state: TeamState, deviceId: string) => { diff --git a/packages/auth/src/team/selectors/hasMember.ts b/packages/auth/src/team/selectors/hasMember.ts index 3343c80d..ff2bed9a 100644 --- a/packages/auth/src/team/selectors/hasMember.ts +++ b/packages/auth/src/team/selectors/hasMember.ts @@ -1,4 +1,4 @@ -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' export const hasMember = (state: TeamState, userId: string) => state.members.find(m => m.userId === userId) !== undefined diff --git a/packages/auth/src/team/selectors/hasRole.ts b/packages/auth/src/team/selectors/hasRole.ts index 21cf7fca..8ce45c99 100644 --- a/packages/auth/src/team/selectors/hasRole.ts +++ b/packages/auth/src/team/selectors/hasRole.ts @@ -1,4 +1,4 @@ -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' export const hasRole = (state: TeamState, roleName: string) => state.roles.find(r => r.roleName === roleName) !== undefined diff --git a/packages/auth/src/team/selectors/hasServer.ts b/packages/auth/src/team/selectors/hasServer.ts index 3ac1ab8e..2ce06f7d 100644 --- a/packages/auth/src/team/selectors/hasServer.ts +++ b/packages/auth/src/team/selectors/hasServer.ts @@ -1,5 +1,5 @@ -import { type Host } from 'server/index.js' -import { type TeamState } from 'team/types.js' +import { type Host } from '../../server/index.js' +import { type TeamState } from '../types.js' export const hasServer = (state: TeamState, host: Host) => state.servers.find(s => s.host === host) !== undefined diff --git a/packages/auth/src/team/selectors/invitation.ts b/packages/auth/src/team/selectors/invitation.ts index 3ed0a276..ed267cb2 100644 --- a/packages/auth/src/team/selectors/invitation.ts +++ b/packages/auth/src/team/selectors/invitation.ts @@ -1,5 +1,5 @@ import { type Base58 } from '@localfirst/crdx' -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' import { assert } from '@localfirst/shared' export function hasInvitation(state: TeamState, id: Base58): boolean { diff --git a/packages/auth/src/team/selectors/keyMap.ts b/packages/auth/src/team/selectors/keyMap.ts index 6552c753..b9ff4a9c 100644 --- a/packages/auth/src/team/selectors/keyMap.ts +++ b/packages/auth/src/team/selectors/keyMap.ts @@ -1,6 +1,6 @@ import { type KeysetWithSecrets } from '@localfirst/crdx' import { visibleKeys } from './visibleKeys.js' -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' /** Returns all keysets from the current device's lockboxes in a structure that looks like this: * ```js diff --git a/packages/auth/src/team/selectors/keyring.ts b/packages/auth/src/team/selectors/keyring.ts index b523b01c..9a55bafa 100644 --- a/packages/auth/src/team/selectors/keyring.ts +++ b/packages/auth/src/team/selectors/keyring.ts @@ -1,5 +1,5 @@ import { type KeysetWithSecrets, createKeyring, type KeyScope } from '@localfirst/crdx' -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' import { keyMap } from './keyMap.js' /** diff --git a/packages/auth/src/team/selectors/keys.ts b/packages/auth/src/team/selectors/keys.ts index 4eb1b1f5..5b07d826 100644 --- a/packages/auth/src/team/selectors/keys.ts +++ b/packages/auth/src/team/selectors/keys.ts @@ -1,8 +1,8 @@ import { type KeyMetadata, type KeyScope, type KeysetWithSecrets } from '@localfirst/crdx' import { keyMap } from './keyMap.js' -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' import { assert } from '@localfirst/shared' -import { lockboxSummary } from 'util/lockboxSummary.js' +import { lockboxSummary } from '../../util/lockboxSummary.js' /** Returns the keys for the given scope, if they are in a lockbox that the current device has access to */ export const keys = ( @@ -19,7 +19,7 @@ export const keys = ( keys, `Couldn't find keys: ${JSON.stringify(scope)} Device: ${deviceKeys.name} - Available lockboxes: \n- ${state.lockboxes.map(lockboxSummary).join('\n- ')} + Available lockboxes: \n- ${state.lockboxes.map(lockboxSummary).join('\n- ')} Keymap: ${JSON.stringify(keysFromLockboxes, null, 2)}` ) diff --git a/packages/auth/src/team/selectors/lockboxesInScope.ts b/packages/auth/src/team/selectors/lockboxesInScope.ts index 41da272d..37cc9ae0 100644 --- a/packages/auth/src/team/selectors/lockboxesInScope.ts +++ b/packages/auth/src/team/selectors/lockboxesInScope.ts @@ -1,6 +1,6 @@ import { type KeyScope } from '@localfirst/crdx' -import { type Lockbox } from 'lockbox/index.js' -import { type TeamState } from 'team/types.js' +import { type Lockbox } from '../../lockbox/index.js' +import { type TeamState } from '../types.js' /** Returns all lockboxes *containing* keys for the given scope */ export const lockboxesInScope = (state: TeamState, scope: KeyScope): Lockbox[] => { diff --git a/packages/auth/src/team/selectors/member.ts b/packages/auth/src/team/selectors/member.ts index 7cbe6517..f2bc221c 100644 --- a/packages/auth/src/team/selectors/member.ts +++ b/packages/auth/src/team/selectors/member.ts @@ -1,4 +1,4 @@ -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' export const member = (state: TeamState, userId: string, options = { includeRemoved: false }) => { const membersToSearch = [ diff --git a/packages/auth/src/team/selectors/memberByDeviceId.ts b/packages/auth/src/team/selectors/memberByDeviceId.ts index 0931089d..3ce08bdc 100644 --- a/packages/auth/src/team/selectors/memberByDeviceId.ts +++ b/packages/auth/src/team/selectors/memberByDeviceId.ts @@ -1,4 +1,4 @@ -import { castServer } from 'server/castServer.js' +import { castServer } from '../../server/castServer.js' import type { TeamState } from '../index.js' import { member, device, server, hasServer } from './index.js' diff --git a/packages/auth/src/team/selectors/memberHasRole.ts b/packages/auth/src/team/selectors/memberHasRole.ts index ede1437e..90dde319 100644 --- a/packages/auth/src/team/selectors/memberHasRole.ts +++ b/packages/auth/src/team/selectors/memberHasRole.ts @@ -1,6 +1,6 @@ -import { ADMIN } from 'role/index.js' -import * as select from 'team/selectors/index.js' -import { type TeamState } from 'team/types.js' +import { ADMIN } from '../../role/index.js' +import * as select from '../selectors/index.js' +import { type TeamState } from '../types.js' export const memberHasRole = (state: TeamState, userId: string, role: string) => { if (!select.hasMember(state, userId)) { diff --git a/packages/auth/src/team/selectors/memberWasRemoved.ts b/packages/auth/src/team/selectors/memberWasRemoved.ts index 37fc9324..94d34e56 100644 --- a/packages/auth/src/team/selectors/memberWasRemoved.ts +++ b/packages/auth/src/team/selectors/memberWasRemoved.ts @@ -1,4 +1,4 @@ -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' export const memberWasRemoved = (state: TeamState, userId: string) => { return state.removedMembers.some(m => m.userId === userId) diff --git a/packages/auth/src/team/selectors/membersInRole.ts b/packages/auth/src/team/selectors/membersInRole.ts index c327a4f1..ebdba860 100644 --- a/packages/auth/src/team/selectors/membersInRole.ts +++ b/packages/auth/src/team/selectors/membersInRole.ts @@ -1,5 +1,5 @@ -import { ADMIN } from 'role/index.js' -import { type TeamState } from 'team/types.js' +import { ADMIN } from '../../role/index.js' +import { type TeamState } from '../types.js' export const membersInRole = (state: TeamState, roleName: string) => state.members.filter(member => member.roles?.includes(roleName)) diff --git a/packages/auth/src/team/selectors/messages.ts b/packages/auth/src/team/selectors/messages.ts index 7ce4d35d..015e6ddd 100644 --- a/packages/auth/src/team/selectors/messages.ts +++ b/packages/auth/src/team/selectors/messages.ts @@ -1,3 +1,3 @@ -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' export const messages = (state: TeamState) => state.messages diff --git a/packages/auth/src/team/selectors/role.ts b/packages/auth/src/team/selectors/role.ts index cf86df00..855792da 100644 --- a/packages/auth/src/team/selectors/role.ts +++ b/packages/auth/src/team/selectors/role.ts @@ -1,4 +1,4 @@ -import { type TeamState } from 'team/types.js' +import { type TeamState } from '../types.js' export const role = (state: TeamState, roleName: string) => { const role = state.roles.find(r => r.roleName === roleName) diff --git a/packages/auth/src/team/selectors/server.ts b/packages/auth/src/team/selectors/server.ts index e3759f0c..6659dbc0 100644 --- a/packages/auth/src/team/selectors/server.ts +++ b/packages/auth/src/team/selectors/server.ts @@ -1,5 +1,5 @@ -import { type Host } from 'server/index.js' -import { type TeamState } from 'team/types.js' +import { type Host } from '../../server/index.js' +import { type TeamState } from '../types.js' export const server = (state: TeamState, host: Host, options = { includeRemoved: false }) => { const serversToSearch = [ diff --git a/packages/auth/src/team/selectors/serverWasRemoved.ts b/packages/auth/src/team/selectors/serverWasRemoved.ts index e77ab5f2..c43d9c8c 100644 --- a/packages/auth/src/team/selectors/serverWasRemoved.ts +++ b/packages/auth/src/team/selectors/serverWasRemoved.ts @@ -1,5 +1,5 @@ -import { type Host } from 'server/index.js' -import { type TeamState } from 'team/types.js' +import { type Host } from '../../server/index.js' +import { type TeamState } from '../types.js' export const serverWasRemoved = (state: TeamState, host: Host) => state.removedServers.some(s => s.host === host) diff --git a/packages/auth/src/team/selectors/teamKeyring.ts b/packages/auth/src/team/selectors/teamKeyring.ts index f8b168aa..9dacfc8e 100644 --- a/packages/auth/src/team/selectors/teamKeyring.ts +++ b/packages/auth/src/team/selectors/teamKeyring.ts @@ -1,6 +1,6 @@ import { type KeysetWithSecrets } from '@localfirst/crdx' -import { type TeamState } from 'team/types.js' -import { KeyType } from 'util/types.js' +import { type TeamState } from '../types.js' +import { KeyType } from '../../util/types.js' import { keyring } from './keyring.js' const { TEAM } = KeyType diff --git a/packages/auth/src/team/selectors/test/visibleKeys.test.ts b/packages/auth/src/team/selectors/test/visibleKeys.test.ts index 0455a9cb..95aa0b12 100644 --- a/packages/auth/src/team/selectors/test/visibleKeys.test.ts +++ b/packages/auth/src/team/selectors/test/visibleKeys.test.ts @@ -1,9 +1,9 @@ import { createKeyset } from '@localfirst/crdx' import { describe, expect, it } from 'vitest' import * as select from '../index.js' -import { ADMIN } from 'role/index.js' -import { KeyType, getScope } from 'util/index.js' -import { setup } from 'util/testing/index.js' +import { ADMIN } from '../../../role/index.js' +import { KeyType, getScope } from '../../../util/index.js' +import { setup } from '../../../util/testing/index.js' const { USER, TEAM, ROLE } = KeyType diff --git a/packages/auth/src/team/selectors/test/visibleScopes.test.ts b/packages/auth/src/team/selectors/test/visibleScopes.test.ts index 40bd98dd..d3c6df17 100644 --- a/packages/auth/src/team/selectors/test/visibleScopes.test.ts +++ b/packages/auth/src/team/selectors/test/visibleScopes.test.ts @@ -1,7 +1,7 @@ import { createKeyset } from '@localfirst/crdx' -import { ADMIN } from 'role/index.js' -import { KeyType } from 'util/index.js' -import { setup } from 'util/testing/index.js' +import { ADMIN } from '../../../role/index.js' +import { KeyType } from '../../../util/index.js' +import { setup } from '../../../util/testing/index.js' import { describe, expect, it } from 'vitest' import * as select from '../index.js' diff --git a/packages/auth/src/team/selectors/visibleKeys.ts b/packages/auth/src/team/selectors/visibleKeys.ts index 5745f6b3..e27425f0 100644 --- a/packages/auth/src/team/selectors/visibleKeys.ts +++ b/packages/auth/src/team/selectors/visibleKeys.ts @@ -1,6 +1,6 @@ import { type KeysetWithSecrets } from '@localfirst/crdx' -import { open } from 'lockbox/index.js' -import { type TeamState } from 'team/types.js' +import { open } from '../../lockbox/index.js' +import { type TeamState } from '../types.js' /** * Returns all keys that can be accessed directly or indirectly (via lockboxes) by the given keyset diff --git a/packages/auth/src/team/selectors/visibleScopes.ts b/packages/auth/src/team/selectors/visibleScopes.ts index 41cf2db6..bd943388 100644 --- a/packages/auth/src/team/selectors/visibleScopes.ts +++ b/packages/auth/src/team/selectors/visibleScopes.ts @@ -1,6 +1,6 @@ import { type KeyScope } from '@localfirst/crdx' -import { type TeamState } from 'team/types.js' -import { unique } from 'util/unique.js' +import { type TeamState } from '../types.js' +import { unique } from '../../util/unique.js' export const visibleScopes = (state: TeamState, { type, name }: KeyScope): KeyScope[] => { // Find the keys that the given key can see diff --git a/packages/auth/src/team/test/createTeam.test.ts b/packages/auth/src/team/test/createTeam.test.ts index 36eaf9c8..25dd6005 100644 --- a/packages/auth/src/team/test/createTeam.test.ts +++ b/packages/auth/src/team/test/createTeam.test.ts @@ -1,8 +1,8 @@ import { createUser } from '@localfirst/crdx' import { describe, expect, it } from 'vitest' import { createTeam } from '../createTeam.js' -import { createDevice } from 'device/index.js' -import { setup } from 'util/testing/index.js' +import { createDevice } from '../../device/index.js' +import { setup } from '../../util/testing/index.js' import { load } from '../load.js' describe('Team', () => { diff --git a/packages/auth/src/team/test/crypto.test.ts b/packages/auth/src/team/test/crypto.test.ts index 1d9579b0..f7372c0e 100644 --- a/packages/auth/src/team/test/crypto.test.ts +++ b/packages/auth/src/team/test/crypto.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' -import { ADMIN } from 'role/index.js' -import { setup } from 'util/testing/index.js' +import { ADMIN } from '../../role/index.js' +import { setup } from '../../util/testing/index.js' describe('Team', () => { describe('crypto', () => { diff --git a/packages/auth/src/team/test/devices.test.ts b/packages/auth/src/team/test/devices.test.ts index 9be6444c..d39f4b2a 100644 --- a/packages/auth/src/team/test/devices.test.ts +++ b/packages/auth/src/team/test/devices.test.ts @@ -1,5 +1,5 @@ -import { createDevice, redactDevice } from 'index.js' -import { setup as setupUsers } from 'util/testing/index.js' +import { createDevice, redactDevice } from '../../index.js' +import { setup as setupUsers } from '../../util/testing/index.js' import { describe, expect, it } from 'vitest' describe('Team', () => { diff --git a/packages/auth/src/team/test/invitations.test.ts b/packages/auth/src/team/test/invitations.test.ts index e08f8d26..beb116f1 100644 --- a/packages/auth/src/team/test/invitations.test.ts +++ b/packages/auth/src/team/test/invitations.test.ts @@ -1,10 +1,10 @@ import { createKeyring, createKeyset, type UnixTimestamp } from '@localfirst/crdx' import { signatures } from '@localfirst/crypto' -import { redactDevice, Team, type FirstUseDevice } from 'index.js' -import { generateProof } from 'invitation/index.js' -import * as teams from 'team/index.js' -import { KeyType } from 'util/index.js' -import { setup } from 'util/testing/index.js' +import { redactDevice, Team, type FirstUseDevice } from '../../index.js' +import { generateProof } from '../../invitation/index.js' +import * as teams from '../index.js' +import { KeyType } from '../../util/index.js' +import { setup } from '../../util/testing/index.js' import { describe, expect, it } from 'vitest' const { USER } = KeyType @@ -154,8 +154,8 @@ describe('Team', () => { // A bunch of people use the same invitation and πŸ‘©πŸΎ Alice admits them all const invitees = ` - amanda, bob, charlie, dwight, edwin, frida, gertrude, herbert, - ignaszi, joΓ£o, krishna, lashawn, mary, ngunda, oprah, phil, quΓ’n, + amanda, bob, charlie, dwight, edwin, frida, gertrude, herbert, + ignaszi, joΓ£o, krishna, lashawn, mary, ngunda, oprah, phil, quΓ’n, rainbow, steve, thad, uriah, vanessa, wade, xerxes, yazmin, zelda` .replaceAll(/\s/g, '') .split(',') diff --git a/packages/auth/src/team/test/keys.test.ts b/packages/auth/src/team/test/keys.test.ts index 03f8230c..d85b8df2 100644 --- a/packages/auth/src/team/test/keys.test.ts +++ b/packages/auth/src/team/test/keys.test.ts @@ -1,8 +1,8 @@ import { createKeyset, redactKeys } from '@localfirst/crdx' -import { ADMIN } from 'role/index.js' -import { KeyType } from 'util/index.js' -import 'util/testing/expect/toLookLikeKeyset.js' -import { setup } from 'util/testing/index.js' +import { ADMIN } from '../../role/index.js' +import { KeyType } from '../../util/index.js' +import '../../util/testing/expect/toLookLikeKeyset.js' +import { setup } from '../../util/testing/index.js' import { describe, expect, it } from 'vitest' const { USER, DEVICE } = KeyType diff --git a/packages/auth/src/team/test/members.test.ts b/packages/auth/src/team/test/members.test.ts index cd187b88..2d96a540 100644 --- a/packages/auth/src/team/test/members.test.ts +++ b/packages/auth/src/team/test/members.test.ts @@ -1,5 +1,5 @@ -import { ADMIN } from 'role/index.js' -import { setup } from 'util/testing/index.js' +import { ADMIN } from '../../role/index.js' +import { setup } from '../../util/testing/index.js' import 'util/testing/expect/toLookLikeKeyset.js' import { describe, expect, it } from 'vitest' diff --git a/packages/auth/src/team/test/membershipResolver.test.ts b/packages/auth/src/team/test/membershipResolver.test.ts index 35c08ff9..74ee8c0f 100644 --- a/packages/auth/src/team/test/membershipResolver.test.ts +++ b/packages/auth/src/team/test/membershipResolver.test.ts @@ -3,9 +3,9 @@ import { describe, expect, it } from 'vitest' import { createTeam } from '../createTeam.js' import { redactUser } from '../redactUser.js' import { type TeamAction, type TeamGraph } from '../types.js' -import { ADMIN } from 'role/index.js' -import { clone, graphSummary } from 'util/index.js' -import { setup as userSetup } from 'util/testing/index.js' +import { ADMIN } from '../../role/index.js' +import { clone, graphSummary } from '../../util/index.js' +import { setup as userSetup } from '../../util/testing/index.js' describe('membershipResolver', () => { const setup = () => { diff --git a/packages/auth/src/team/test/messages.test.ts b/packages/auth/src/team/test/messages.test.ts index c8be6b4a..98b9839e 100644 --- a/packages/auth/src/team/test/messages.test.ts +++ b/packages/auth/src/team/test/messages.test.ts @@ -1,4 +1,4 @@ -import { setup } from 'util/testing/index.js' +import { setup } from '../../util/testing/index.js' import { describe, expect, it } from 'vitest' describe('Team', () => { diff --git a/packages/auth/src/team/test/roles.test.ts b/packages/auth/src/team/test/roles.test.ts index 2f89b33e..002e5183 100644 --- a/packages/auth/src/team/test/roles.test.ts +++ b/packages/auth/src/team/test/roles.test.ts @@ -1,7 +1,7 @@ -import { ADMIN } from 'role/index.js' -import * as teams from 'team/index.js' -import { setup } from 'util/testing/index.js' -import 'util/testing/expect/toLookLikeKeyset.js' +import { ADMIN } from '../../role/index.js' +import * as teams from '../index.js' +import { setup } from '../../util/testing/index.js' +import '../../util/testing/expect/toLookLikeKeyset.js' import { symmetric } from '@localfirst/crypto' import { describe, expect, it } from 'vitest' diff --git a/packages/auth/src/team/test/servers.test.ts b/packages/auth/src/team/test/servers.test.ts index 14e9e4d5..89377c82 100644 --- a/packages/auth/src/team/test/servers.test.ts +++ b/packages/auth/src/team/test/servers.test.ts @@ -1,6 +1,6 @@ import { createKeyset, redactKeys } from '@localfirst/crdx' -import type { Host, Server, ServerWithSecrets } from 'server/index.js' -import { KeyType } from 'util/index.js' +import type { Host, Server, ServerWithSecrets } from '../../server/index.js' +import { KeyType } from '../../util/index.js' import { eventPromise } from '@localfirst/shared' import { TestChannel, @@ -9,7 +9,7 @@ import { setup as setupHumans, type SetupConfig, type UserStuff, -} from 'util/testing/index.js' +} from '../../util/testing/index.js' import { describe, expect, it } from 'vitest' import { createTeam, @@ -20,7 +20,7 @@ import { type InviteeDeviceContext, type MemberContext, type Team, -} from 'index.js' +} from '../../index.js' describe('Team', () => { describe('a server', () => { diff --git a/packages/auth/src/team/transforms/addDevice.ts b/packages/auth/src/team/transforms/addDevice.ts index fd8783be..03523d41 100644 --- a/packages/auth/src/team/transforms/addDevice.ts +++ b/packages/auth/src/team/transforms/addDevice.ts @@ -1,5 +1,5 @@ -import { type Device } from 'device/index.js' -import { type Transform } from 'team/types.js' +import { type Device } from '../../device/index.js' +import { type Transform } from '../types.js' export const addDevice = (device: Device): Transform => diff --git a/packages/auth/src/team/transforms/addMember.ts b/packages/auth/src/team/transforms/addMember.ts index ca3e39a3..21ebd927 100644 --- a/packages/auth/src/team/transforms/addMember.ts +++ b/packages/auth/src/team/transforms/addMember.ts @@ -1,5 +1,5 @@ -import { type Member } from 'team/index.js' -import { type Transform } from 'team/types.js' +import { type Member } from '../index.js' +import { type Transform } from '../types.js' export const addMember = (newMember: Member): Transform => diff --git a/packages/auth/src/team/transforms/addMemberRoles.ts b/packages/auth/src/team/transforms/addMemberRoles.ts index 7d36fcfc..2841c844 100644 --- a/packages/auth/src/team/transforms/addMemberRoles.ts +++ b/packages/auth/src/team/transforms/addMemberRoles.ts @@ -1,4 +1,4 @@ -import { type Transform } from 'team/types.js' +import { type Transform } from '../types.js' export const addMemberRoles = (userId: string, roles: string[] = []): Transform[] => roles.map(roleName => state => ({ diff --git a/packages/auth/src/team/transforms/addMessage.ts b/packages/auth/src/team/transforms/addMessage.ts index a8d798be..bceb2e37 100644 --- a/packages/auth/src/team/transforms/addMessage.ts +++ b/packages/auth/src/team/transforms/addMessage.ts @@ -1,4 +1,4 @@ -import { type Transform } from 'team/types.js' +import { type Transform } from '../types.js' export const addMessage = (message: unknown): Transform => diff --git a/packages/auth/src/team/transforms/addRole.ts b/packages/auth/src/team/transforms/addRole.ts index 5f820271..c36d858b 100644 --- a/packages/auth/src/team/transforms/addRole.ts +++ b/packages/auth/src/team/transforms/addRole.ts @@ -1,5 +1,5 @@ -import { type Role } from 'role/index.js' -import { type Transform } from 'team/types.js' +import { type Role } from '../../role/index.js' +import { type Transform } from '../types.js' export const addRole = (newRole: Role): Transform => diff --git a/packages/auth/src/team/transforms/addServer.ts b/packages/auth/src/team/transforms/addServer.ts index 27e71ff5..5505a682 100644 --- a/packages/auth/src/team/transforms/addServer.ts +++ b/packages/auth/src/team/transforms/addServer.ts @@ -1,6 +1,6 @@ -import type { Server } from 'server/index.js' -import type { TeamState, Transform } from 'team/types.js' -import { unique } from 'util/unique.js' +import type { Server } from '../../server/index.js' +import type { TeamState, Transform } from '../types.js' +import { unique } from '../../util/unique.js' export const addServer = (newServer: Server): Transform => diff --git a/packages/auth/src/team/transforms/changeMemberKeys.ts b/packages/auth/src/team/transforms/changeMemberKeys.ts index b5a551bf..c9117569 100644 --- a/packages/auth/src/team/transforms/changeMemberKeys.ts +++ b/packages/auth/src/team/transforms/changeMemberKeys.ts @@ -1,5 +1,5 @@ import { type Keyset } from '@localfirst/crdx' -import { type Transform } from 'team/types.js' +import { type Transform } from '../types.js' export const changeMemberKeys = (keys: Keyset): Transform => diff --git a/packages/auth/src/team/transforms/changeServerKeys.ts b/packages/auth/src/team/transforms/changeServerKeys.ts index e8a706e5..d640a29a 100644 --- a/packages/auth/src/team/transforms/changeServerKeys.ts +++ b/packages/auth/src/team/transforms/changeServerKeys.ts @@ -1,5 +1,5 @@ import { type Keyset } from '@localfirst/crdx' -import { type Transform } from 'team/types.js' +import { type Transform } from '../types.js' export const changeServerKeys = (keys: Keyset): Transform => diff --git a/packages/auth/src/team/transforms/collectLockboxes.ts b/packages/auth/src/team/transforms/collectLockboxes.ts index 9c094bca..d10792f9 100644 --- a/packages/auth/src/team/transforms/collectLockboxes.ts +++ b/packages/auth/src/team/transforms/collectLockboxes.ts @@ -1,5 +1,5 @@ -import { type Lockbox } from 'lockbox/index.js' -import { type Transform } from 'team/types.js' +import { type Lockbox } from '../../lockbox/index.js' +import { type Transform } from '../types.js' export const collectLockboxes = (newLockboxes?: Lockbox[]): Transform => diff --git a/packages/auth/src/team/transforms/postInvitation.ts b/packages/auth/src/team/transforms/postInvitation.ts index e72b88df..95215efb 100644 --- a/packages/auth/src/team/transforms/postInvitation.ts +++ b/packages/auth/src/team/transforms/postInvitation.ts @@ -1,5 +1,5 @@ -import { type Invitation } from 'invitation/index.js' -import { type Transform } from 'team/types.js' +import { type Invitation } from '../../invitation/index.js' +import { type Transform } from '../types.js' export const postInvitation = (invitation: Invitation): Transform => diff --git a/packages/auth/src/team/transforms/removeDevice.ts b/packages/auth/src/team/transforms/removeDevice.ts index f67830a1..8fd3ad1e 100644 --- a/packages/auth/src/team/transforms/removeDevice.ts +++ b/packages/auth/src/team/transforms/removeDevice.ts @@ -1,8 +1,8 @@ import { type Keyset } from '@localfirst/crdx' -import { type Lockbox } from 'lockbox/index.js' -import * as select from 'team/selectors/index.js' -import { type Member, type Transform } from 'team/types.js' -import { KeyType } from 'util/types.js' +import { type Lockbox } from '../../lockbox/index.js' +import * as select from '../selectors/index.js' +import { type Member, type Transform } from '../types.js' +import { KeyType } from '../../util/types.js' export const removeDevice = (deviceId: string, lockboxes: Lockbox[] = []): Transform => diff --git a/packages/auth/src/team/transforms/removeMember.ts b/packages/auth/src/team/transforms/removeMember.ts index 0d2a0d7e..24356e68 100644 --- a/packages/auth/src/team/transforms/removeMember.ts +++ b/packages/auth/src/team/transforms/removeMember.ts @@ -1,4 +1,4 @@ -import { type Transform } from 'team/types.js' +import { type Transform } from '../types.js' export const removeMember = (userId: string): Transform => diff --git a/packages/auth/src/team/transforms/removeMemberRole.ts b/packages/auth/src/team/transforms/removeMemberRole.ts index dff1ff72..f02f549c 100644 --- a/packages/auth/src/team/transforms/removeMemberRole.ts +++ b/packages/auth/src/team/transforms/removeMemberRole.ts @@ -1,5 +1,5 @@ -import { type Transform } from 'team/types.js' -import { KeyType } from 'util/index.js' +import { type Transform } from '../types.js' +import { KeyType } from '../../util/index.js' export const removeMemberRole = (userId: string, roleName: string): Transform => diff --git a/packages/auth/src/team/transforms/removeRole.ts b/packages/auth/src/team/transforms/removeRole.ts index ca11e5f9..20d9648a 100644 --- a/packages/auth/src/team/transforms/removeRole.ts +++ b/packages/auth/src/team/transforms/removeRole.ts @@ -1,5 +1,5 @@ -import { type Transform } from 'team/types.js' -import { KeyType } from 'util/index.js' +import { type Transform } from '../types.js' +import { KeyType } from '../../util/index.js' export const removeRole = (roleName: string): Transform => diff --git a/packages/auth/src/team/transforms/removeServer.ts b/packages/auth/src/team/transforms/removeServer.ts index 83eb341b..6e5c1293 100644 --- a/packages/auth/src/team/transforms/removeServer.ts +++ b/packages/auth/src/team/transforms/removeServer.ts @@ -1,5 +1,5 @@ -import { type Host } from 'server/index.js' -import { type Transform } from 'team/types.js' +import { type Host } from '../../server/index.js' +import { type Transform } from '../types.js' export const removeServer = (host: Host): Transform => diff --git a/packages/auth/src/team/transforms/revokeInvitation.ts b/packages/auth/src/team/transforms/revokeInvitation.ts index 67f00a6f..fcd2fffa 100644 --- a/packages/auth/src/team/transforms/revokeInvitation.ts +++ b/packages/auth/src/team/transforms/revokeInvitation.ts @@ -1,4 +1,4 @@ -import { type Transform } from 'team/types.js' +import { type Transform } from '../types.js' export const revokeInvitation = (id: string): Transform => diff --git a/packages/auth/src/team/transforms/rotateKeys.ts b/packages/auth/src/team/transforms/rotateKeys.ts index 1c403370..bf5b870f 100644 --- a/packages/auth/src/team/transforms/rotateKeys.ts +++ b/packages/auth/src/team/transforms/rotateKeys.ts @@ -1,4 +1,4 @@ -import { type Transform } from 'team/types.js' +import { type Transform } from '../types.js' export const rotateKeys = (userId: string): Transform => diff --git a/packages/auth/src/team/transforms/setTeamName.ts b/packages/auth/src/team/transforms/setTeamName.ts index b3a39bdc..8b862719 100644 --- a/packages/auth/src/team/transforms/setTeamName.ts +++ b/packages/auth/src/team/transforms/setTeamName.ts @@ -1,4 +1,4 @@ -import { type Transform } from 'team/types.js' +import { type Transform } from '../types.js' export const setTeamName = (teamName: string): Transform => diff --git a/packages/auth/src/team/transforms/useInvitation.ts b/packages/auth/src/team/transforms/useInvitation.ts index d9131922..7f79d82e 100644 --- a/packages/auth/src/team/transforms/useInvitation.ts +++ b/packages/auth/src/team/transforms/useInvitation.ts @@ -1,5 +1,5 @@ -import { type InvitationState } from 'invitation/index.js' -import { type Transform } from 'team/types.js' +import { type InvitationState } from '../../invitation/index.js' +import { type Transform } from '../types.js' export const useInvitation = (id: string): Transform => diff --git a/packages/auth/src/team/types.ts b/packages/auth/src/team/types.ts index 337a66c2..94af6e92 100644 --- a/packages/auth/src/team/types.ts +++ b/packages/auth/src/team/types.ts @@ -12,13 +12,13 @@ import type { ROOT, Sequence, } from '@localfirst/crdx' -import type { Client, LocalContext } from 'team/context.js' -import type { Device } from 'device/index.js' -import type { Invitation, InvitationState } from 'invitation/types.js' -import type { Lockbox } from 'lockbox/index.js' -import type { PermissionsMap, Role } from 'role/index.js' -import type { Host, Server } from 'server/index.js' -import type { ValidationResult } from 'util/index.js' +import type { Client, LocalContext } from './context.js' +import type { Device } from '../device/index.js' +import type { Invitation, InvitationState } from '../invitation/types.js' +import type { Lockbox } from '../lockbox/index.js' +import type { PermissionsMap, Role } from '../role/index.js' +import type { Host, Server } from '../server/index.js' +import type { ValidationResult } from '../util/index.js' // ********* MEMBER diff --git a/packages/auth/src/team/validate.ts b/packages/auth/src/team/validate.ts index b65232d5..39325e0c 100644 --- a/packages/auth/src/team/validate.ts +++ b/packages/auth/src/team/validate.ts @@ -1,7 +1,7 @@ import { debug, truncateHashes } from '@localfirst/shared' import { ROOT } from '@localfirst/crdx' -import { invitationCanBeUsed } from 'invitation/index.js' -import { VALID, ValidationError, actionFingerprint } from 'util/index.js' +import { invitationCanBeUsed } from '../invitation/index.js' +import { VALID, ValidationError, actionFingerprint } from '../util/index.js' import { isAdminOnlyAction } from './isAdminOnlyAction.js' import * as select from './selectors/index.js' import { diff --git a/packages/auth/src/util/actionFingerprint.ts b/packages/auth/src/util/actionFingerprint.ts index d01db867..570de4d0 100644 --- a/packages/auth/src/util/actionFingerprint.ts +++ b/packages/auth/src/util/actionFingerprint.ts @@ -1,5 +1,5 @@ // ignore file coverage -import type { TeamAction, TeamLink } from 'team/types.js' +import type { TeamAction, TeamLink } from '../team/types.js' /** Identifies a unique action for the purpose of detecting duplicates; * e.g. ADD_MEMBER:bob diff --git a/packages/auth/src/util/composeTransforms.ts b/packages/auth/src/util/composeTransforms.ts index 30ebdac4..dd6d0ca5 100644 --- a/packages/auth/src/util/composeTransforms.ts +++ b/packages/auth/src/util/composeTransforms.ts @@ -1,4 +1,4 @@ -import { type Transform } from 'team/types.js' +import { type Transform } from '../team/types.js' export const composeTransforms = (transforms: Transform[]): Transform => diff --git a/packages/auth/src/util/constants.ts b/packages/auth/src/util/constants.ts index 5b65ad69..6b72a77f 100644 --- a/packages/auth/src/util/constants.ts +++ b/packages/auth/src/util/constants.ts @@ -1,4 +1,4 @@ -import { type ValidationResult } from 'util/types.js' +import { type ValidationResult } from './types.js' // avoiding enums export const SIGNATURE = 'SIGNATURE' diff --git a/packages/auth/src/util/graphSummary.ts b/packages/auth/src/util/graphSummary.ts index 2a5066a0..d8d403a4 100644 --- a/packages/auth/src/util/graphSummary.ts +++ b/packages/auth/src/util/graphSummary.ts @@ -1,7 +1,7 @@ import { getSequence } from '@localfirst/crdx' import { actionFingerprint } from './actionFingerprint.js' -import { membershipResolver as resolver } from 'team/membershipResolver.js' -import { type TeamAction, type TeamContext, type TeamGraph } from 'team/types.js' +import { membershipResolver as resolver } from '../team/membershipResolver.js' +import { type TeamAction, type TeamContext, type TeamGraph } from '../team/types.js' export const graphSummary = (graph: TeamGraph) => { const links = getSequence(graph, resolver) diff --git a/packages/auth/src/util/lockboxSummary.ts b/packages/auth/src/util/lockboxSummary.ts index 2e6511ec..c2cae0ff 100644 --- a/packages/auth/src/util/lockboxSummary.ts +++ b/packages/auth/src/util/lockboxSummary.ts @@ -1,4 +1,4 @@ -import { type Lockbox } from 'lockbox/index.js' +import type { Lockbox } from '../lockbox/index.js' export const lockboxSummary = (l: Lockbox) => `${l.recipient.name}(${trunc(l.recipient.publicKey)}):${l.contents.name}#${l.contents.generation}` diff --git a/packages/auth/src/util/scopesMatch.ts b/packages/auth/src/util/scopesMatch.ts index 77eaa3d3..6d217587 100644 --- a/packages/auth/src/util/scopesMatch.ts +++ b/packages/auth/src/util/scopesMatch.ts @@ -1,6 +1,6 @@ import { type KeyScope } from '@localfirst/crdx' import { assert } from '@localfirst/shared' -import { getScope } from 'util/getScope.js' +import { getScope } from './getScope.js' export const scopesMatch = (a: KeyScope, b: KeyScope) => { return a.type === b.type && a.name === b.name @@ -9,8 +9,8 @@ export const scopesMatch = (a: KeyScope, b: KeyScope) => { export const assertScopesMatch = (a: KeyScope, b: KeyScope) => { assert( scopesMatch(a, b), - `The scope of the new keys must match those of the old lockbox. - New scope: ${JSON.stringify(getScope(a))} + `The scope of the new keys must match those of the old lockbox. + New scope: ${JSON.stringify(getScope(a))} Old scope: ${JSON.stringify(getScope(b))}` ) } diff --git a/packages/auth/src/util/testing/connectionHelpers.ts b/packages/auth/src/util/testing/connectionHelpers.ts index 23a22ab0..46ff777e 100644 --- a/packages/auth/src/util/testing/connectionHelpers.ts +++ b/packages/auth/src/util/testing/connectionHelpers.ts @@ -1,7 +1,7 @@ // ignore file coverage import { eventPromise } from '@localfirst/shared' -import { type Connection, type ConnectionEvents } from 'connection/index.js' -import { type InviteeDeviceContext, type InviteeMemberContext } from 'connection/types.js' +import { type Connection, type ConnectionEvents } from '../../connection/index.js' +import { type InviteeDeviceContext, type InviteeMemberContext } from '../../connection/types.js' import { expect } from 'vitest' import { TestChannel } from './TestChannel.js' import { joinTestChannel } from './joinTestChannel.js' diff --git a/packages/auth/src/util/testing/expect/toBeValid.ts b/packages/auth/src/util/testing/expect/toBeValid.ts index 4e7e11f7..ccf7c9c4 100644 --- a/packages/auth/src/util/testing/expect/toBeValid.ts +++ b/packages/auth/src/util/testing/expect/toBeValid.ts @@ -1,5 +1,5 @@ import { expect } from 'vitest' -import { type ValidationResult } from 'util/types.js' +import { type ValidationResult } from '../../types.js' // ignore coverage expect.extend({ diff --git a/packages/auth/src/util/testing/index.ts b/packages/auth/src/util/testing/index.ts index 30d4c952..3c5296dc 100644 --- a/packages/auth/src/util/testing/index.ts +++ b/packages/auth/src/util/testing/index.ts @@ -1,4 +1,4 @@ -export * from 'util/testing/connectionHelpers.js' -export * from 'util/testing/joinTestChannel.js' -export * from 'util/testing/setup.js' -export * from 'util/testing/TestChannel.js' +export * from './connectionHelpers.js' +export * from './joinTestChannel.js' +export * from './setup.js' +export * from './TestChannel.js' diff --git a/packages/auth/src/util/testing/joinTestChannel.ts b/packages/auth/src/util/testing/joinTestChannel.ts index 62ba9d97..0bb57b0a 100644 --- a/packages/auth/src/util/testing/joinTestChannel.ts +++ b/packages/auth/src/util/testing/joinTestChannel.ts @@ -1,5 +1,5 @@ -import { Connection } from 'connection/Connection.js' -import { isServerContext, type Context } from 'connection/types.js' +import { Connection } from '../../connection/Connection.js' +import { isServerContext, type Context } from '../../connection/types.js' import { type TestChannel } from './TestChannel.js' import { pause } from '@localfirst/shared' diff --git a/packages/auth/src/util/testing/setup.ts b/packages/auth/src/util/testing/setup.ts index 22918f11..13108c76 100644 --- a/packages/auth/src/util/testing/setup.ts +++ b/packages/auth/src/util/testing/setup.ts @@ -1,14 +1,14 @@ import { assert } from '@localfirst/shared' import { createKeyring, createUser, type UserWithSecrets } from '@localfirst/crdx' import { createId } from '@paralleldrive/cuid2' -import type { Connection, Context, InviteeContext, MemberContext } from 'connection/index.js' -import type { DeviceWithSecrets } from 'device/index.js' -import * as devices from 'device/index.js' -import { ADMIN } from 'role/index.js' -import type { LocalUserContext } from 'team/context.js' -import type { Team, TeamContext } from 'team/index.js' -import * as teams from 'team/index.js' -import { arrayToMap } from 'util/index.js' +import type { Connection, Context, InviteeContext, MemberContext } from '../../connection/index.js' +import type { DeviceWithSecrets } from '../../device/index.js' +import * as devices from '../../device/index.js' +import { ADMIN } from '../../role/index.js' +import type { LocalUserContext } from '../../team/context.js' +import type { Team, TeamContext } from '../../team/index.js' +import * as teams from '../../team/index.js' +import { arrayToMap } from '../index.js' import { phoneInfo, laptopInfo } from './constants.js' export type SetupConfig = Array | TestUserSettings | string> diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index 55f7ac81..17633295 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -1,12 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "baseUrl": "src", "outDir": "dist", - "rootDir": "src", + "rootDir": "src" }, - "include": [ - "src", - "@types", - ] -} \ No newline at end of file + "include": ["src", "@types"] +} From 94e68f91fd29eeb22ef4d0955820092819a614d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 14:07:15 +0100 Subject: [PATCH 02/10] Removes baseUrl options from shared package --- packages/shared/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index b647822b..17633295 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "baseUrl": "src", "outDir": "dist", "rootDir": "src" }, From 4eeb7d7761413fa3e76ac8bd5677b9bed6207444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 14:08:21 +0100 Subject: [PATCH 03/10] Removes baseUrl option from crypto package and fixes --- packages/crypto/src/randomKey.ts | 2 +- packages/crypto/tsconfig.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/crypto/src/randomKey.ts b/packages/crypto/src/randomKey.ts index ae6665d2..410fbd20 100644 --- a/packages/crypto/src/randomKey.ts +++ b/packages/crypto/src/randomKey.ts @@ -1,6 +1,6 @@ import sodium from 'libsodium-wrappers-sumo' import { base58 } from './util/index.js' -import { type Base58 } from 'types.js' +import { type Base58 } from './types.js' /** Returns an unpredictable key with the given length (32 bytes by default), as a byte array. */ export const randomKeyBytes = (length = 32) => sodium.randombytes_buf(length) diff --git a/packages/crypto/tsconfig.json b/packages/crypto/tsconfig.json index b647822b..17633295 100644 --- a/packages/crypto/tsconfig.json +++ b/packages/crypto/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "baseUrl": "src", "outDir": "dist", "rootDir": "src" }, From 1b8f4c0893b5e013ab892f376897c6ac1d920351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 14:22:21 +0100 Subject: [PATCH 04/10] Removes baseUrl option from crdx package and fixes imports --- packages/crdx/src/graph/append.ts | 6 ++--- packages/crdx/src/graph/children.ts | 4 ++-- packages/crdx/src/graph/concurrency.ts | 2 +- packages/crdx/src/graph/createGraph.ts | 6 ++--- packages/crdx/src/graph/decrypt.ts | 6 ++--- packages/crdx/src/graph/getEncryptedLinks.ts | 2 +- packages/crdx/src/graph/getHashes.ts | 2 +- packages/crdx/src/graph/getLink.ts | 2 +- packages/crdx/src/graph/getParentMap.ts | 2 +- packages/crdx/src/graph/getParents.ts | 2 +- packages/crdx/src/graph/getPredecessors.ts | 2 +- packages/crdx/src/graph/getSuccessors.ts | 2 +- packages/crdx/src/graph/hashLink.ts | 2 +- packages/crdx/src/graph/headsAreEqual.ts | 2 +- packages/crdx/src/graph/isPredecessor.ts | 2 +- packages/crdx/src/graph/isSuccessor.ts | 2 +- packages/crdx/src/graph/merge.ts | 2 +- packages/crdx/src/graph/serialize.ts | 2 +- packages/crdx/src/graph/test/append.test.ts | 6 ++--- packages/crdx/src/graph/test/create.test.ts | 6 ++--- packages/crdx/src/graph/test/decrypt.test.ts | 10 ++++---- .../crdx/src/graph/test/getChildren.test.ts | 8 +++---- .../src/graph/test/getConcurrentLinks.test.ts | 6 ++--- .../crdx/src/graph/test/getParentMap.test.ts | 10 ++++---- .../src/graph/test/getPredecessors.test.ts | 8 +++---- .../crdx/src/graph/test/getSequence.test.ts | 20 ++++++++-------- .../crdx/src/graph/test/getSuccessors.test.ts | 8 +++---- packages/crdx/src/graph/test/merge.test.ts | 4 ++-- packages/crdx/src/graph/test/topoSort.test.ts | 18 +++++++------- packages/crdx/src/graph/topoSort.ts | 2 +- packages/crdx/src/graph/types.ts | 2 +- packages/crdx/src/keyset/createKeyring.ts | 2 +- packages/crdx/src/keyset/createKeyset.ts | 4 ++-- packages/crdx/src/keyset/redactKeys.ts | 2 +- .../crdx/src/keyset/test/createKeyset.test.ts | 6 ++--- .../keyset/test/getLatestGeneration.test.ts | 2 +- .../crdx/src/keyset/test/redactKeys.test.ts | 4 ++-- packages/crdx/src/store/Store.ts | 12 +++++----- packages/crdx/src/store/StoreOptions.ts | 8 +++---- packages/crdx/src/store/compose.ts | 2 +- packages/crdx/src/store/createStore.ts | 2 +- packages/crdx/src/store/makeMachine.ts | 4 ++-- packages/crdx/src/store/test/counter.test.ts | 8 +++---- .../crdx/src/store/test/createStore.test.ts | 8 +++---- .../crdx/src/store/test/scheduler.test.ts | 12 +++++----- packages/crdx/src/store/test/scrabble.test.ts | 16 ++++++------- .../src/store/test/shared/counterReducer.ts | 4 ++-- packages/crdx/src/store/types.ts | 2 +- packages/crdx/src/sync/generateMessage.ts | 4 ++-- packages/crdx/src/sync/getMissingLinks.ts | 2 +- packages/crdx/src/sync/receiveMessage.ts | 8 +++---- packages/crdx/src/sync/test/sync.test.ts | 10 ++++---- packages/crdx/src/sync/types.ts | 6 ++--- packages/crdx/src/user/createUser.ts | 4 ++-- packages/crdx/src/user/redact.ts | 4 ++-- packages/crdx/src/user/test/user.test.ts | 2 +- packages/crdx/src/user/types.ts | 2 +- packages/crdx/src/util/index.ts | 4 ++-- packages/crdx/src/util/messageSummary.ts | 4 ++-- packages/crdx/src/util/testing/Network.ts | 16 ++++++------- .../crdx/src/util/testing/expect/toBeValid.ts | 2 +- .../util/testing/expect/toLookLikeKeyset.ts | 2 +- packages/crdx/src/util/testing/graph.ts | 24 +++++++++---------- packages/crdx/src/util/testing/setup.ts | 8 +++---- packages/crdx/src/validator/types.ts | 2 +- packages/crdx/src/validator/validate.ts | 6 ++--- packages/crdx/src/validator/validators.ts | 6 ++--- packages/crdx/tsconfig.json | 10 +++----- 68 files changed, 189 insertions(+), 193 deletions(-) diff --git a/packages/crdx/src/graph/append.ts b/packages/crdx/src/graph/append.ts index 48ab5766..d449db43 100644 --- a/packages/crdx/src/graph/append.ts +++ b/packages/crdx/src/graph/append.ts @@ -2,9 +2,9 @@ import { type EMPTY_GRAPH } from './createGraph.js' import { hashEncryptedLink } from './hashLink.js' import type { Action, EncryptedLink, Graph, Link, LinkBody } from './types.js' -import type { KeysetWithSecrets } from 'keyset/index.js' -import type { UserWithSecrets } from 'user/index.js' -import type { UnixTimestamp } from 'util/index.js' +import type { KeysetWithSecrets } from '../keyset/index.js' +import type { UserWithSecrets } from '../user/index.js' +import type { UnixTimestamp } from '../util/index.js' export const append = ({ graph, diff --git a/packages/crdx/src/graph/children.ts b/packages/crdx/src/graph/children.ts index c2eb0ec9..80763ae3 100644 --- a/packages/crdx/src/graph/children.ts +++ b/packages/crdx/src/graph/children.ts @@ -1,6 +1,6 @@ import { memoize } from '@localfirst/shared' -import type { Action, Graph, Link } from 'graph/types.js' -import { type Hash } from 'util/index.js' +import type { Action, Graph, Link } from './types.js' +import { type Hash } from '../util/index.js' import { getLink } from './getLink.js' /** diff --git a/packages/crdx/src/graph/concurrency.ts b/packages/crdx/src/graph/concurrency.ts index c0dc61f7..ed588a58 100644 --- a/packages/crdx/src/graph/concurrency.ts +++ b/packages/crdx/src/graph/concurrency.ts @@ -1,5 +1,5 @@ import { memoize } from '@localfirst/shared' -import { type Hash } from 'util/index.js' +import { type Hash } from '../util/index.js' import { getHashes } from './getHashes.js' import { getLink } from './getLink.js' import { isPredecessorHash } from './isPredecessor.js' diff --git a/packages/crdx/src/graph/createGraph.ts b/packages/crdx/src/graph/createGraph.ts index 4a50cdad..c3256a2d 100644 --- a/packages/crdx/src/graph/createGraph.ts +++ b/packages/crdx/src/graph/createGraph.ts @@ -1,7 +1,7 @@ ο»Ώimport { createId } from '@paralleldrive/cuid2' -import { ROOT } from 'constants.js' -import type { KeysetWithSecrets } from 'keyset/index.js' -import type { UserWithSecrets } from 'user/index.js' +import { ROOT } from '../constants.js' +import type { KeysetWithSecrets } from '../keyset/index.js' +import type { UserWithSecrets } from '../user/index.js' import { append } from './append.js' import type { Action, Graph } from './types.js' diff --git a/packages/crdx/src/graph/decrypt.ts b/packages/crdx/src/graph/decrypt.ts index bb4e26c4..04664039 100644 --- a/packages/crdx/src/graph/decrypt.ts +++ b/packages/crdx/src/graph/decrypt.ts @@ -8,9 +8,9 @@ import { type LinkBody, type MaybePartlyDecryptedGraph, } from './types.js' -import { createKeyring } from 'keyset/createKeyring.js' -import { type Keyring, type KeysetWithSecrets } from 'keyset/index.js' -import { type Hash } from 'util/index.js' +import { createKeyring } from '../keyset/createKeyring.js' +import { type Keyring, type KeysetWithSecrets } from '../keyset/index.js' +import { type Hash } from '../util/index.js' import { assert } from '@localfirst/shared' /** diff --git a/packages/crdx/src/graph/getEncryptedLinks.ts b/packages/crdx/src/graph/getEncryptedLinks.ts index b37337f7..99c42be8 100644 --- a/packages/crdx/src/graph/getEncryptedLinks.ts +++ b/packages/crdx/src/graph/getEncryptedLinks.ts @@ -1,4 +1,4 @@ -import type { Hash } from 'util/index.js' +import type { Hash } from '../util/index.js' import type { Graph } from './types.js' export const getEncryptedLinks = (graph: Graph, hashes: Hash[]) => diff --git a/packages/crdx/src/graph/getHashes.ts b/packages/crdx/src/graph/getHashes.ts index 389d32c3..de484830 100644 --- a/packages/crdx/src/graph/getHashes.ts +++ b/packages/crdx/src/graph/getHashes.ts @@ -1,4 +1,4 @@ import type { Graph } from './types.js' -import type { Hash } from 'util/index.js' +import type { Hash } from '../util/index.js' export const getHashes = (graph: Graph) => Object.keys(graph.links) as Hash[] diff --git a/packages/crdx/src/graph/getLink.ts b/packages/crdx/src/graph/getLink.ts index 0980f068..11204396 100644 --- a/packages/crdx/src/graph/getLink.ts +++ b/packages/crdx/src/graph/getLink.ts @@ -1,5 +1,5 @@ import type { Action, Link, Graph } from './types.js' -import type { Hash } from 'util/index.js' +import type { Hash } from '../util/index.js' export const getLink = (graph: Graph, hash: Hash): Link => graph.links[hash] diff --git a/packages/crdx/src/graph/getParentMap.ts b/packages/crdx/src/graph/getParentMap.ts index 27c3be86..dd3d5a39 100644 --- a/packages/crdx/src/graph/getParentMap.ts +++ b/packages/crdx/src/graph/getParentMap.ts @@ -1,7 +1,7 @@ import { getHashes } from './getHashes.js' import { getParents } from './getParents.js' import { type Action, type Graph, type LinkMap } from './types.js' -import { type Hash } from 'util/index.js' +import { type Hash } from '../util/index.js' export const EMPTY: LinkMap = {} diff --git a/packages/crdx/src/graph/getParents.ts b/packages/crdx/src/graph/getParents.ts index 5c7c5bd9..42b7f256 100644 --- a/packages/crdx/src/graph/getParents.ts +++ b/packages/crdx/src/graph/getParents.ts @@ -1,5 +1,5 @@ import type { Action, Link, Graph } from './types.js' -import type { Hash } from 'util/index.js' +import type { Hash } from '../util/index.js' import { getLink } from './getLink.js' // prettier-ignore diff --git a/packages/crdx/src/graph/getPredecessors.ts b/packages/crdx/src/graph/getPredecessors.ts index c8190c9c..0b4913e8 100644 --- a/packages/crdx/src/graph/getPredecessors.ts +++ b/packages/crdx/src/graph/getPredecessors.ts @@ -1,6 +1,6 @@ import { assert, memoize } from '@localfirst/shared' import { uniq } from 'lodash-es' -import { type Hash } from 'util/index.js' +import { type Hash } from '../util/index.js' import { getLink } from './getLink.js' import type { Action, Graph, Link } from './types.js' diff --git a/packages/crdx/src/graph/getSuccessors.ts b/packages/crdx/src/graph/getSuccessors.ts index dc4ecdc3..08547206 100644 --- a/packages/crdx/src/graph/getSuccessors.ts +++ b/packages/crdx/src/graph/getSuccessors.ts @@ -1,6 +1,6 @@ ο»Ώimport { memoize } from '@localfirst/shared' import { uniq } from 'lodash-es' -import { type Hash } from 'util/index.js' +import { type Hash } from '../util/index.js' import { getChildrenHashes } from './children.js' import type { Action, Graph, Link } from './types.js' diff --git a/packages/crdx/src/graph/hashLink.ts b/packages/crdx/src/graph/hashLink.ts index d9e34ba8..d3628da4 100644 --- a/packages/crdx/src/graph/hashLink.ts +++ b/packages/crdx/src/graph/hashLink.ts @@ -1,5 +1,5 @@ import { hash, type Hash } from '@localfirst/crypto' -import { HashPurpose } from 'constants.js' +import { HashPurpose } from '../constants.js' const { LINK_HASH } = HashPurpose diff --git a/packages/crdx/src/graph/headsAreEqual.ts b/packages/crdx/src/graph/headsAreEqual.ts index 15465967..61234987 100644 --- a/packages/crdx/src/graph/headsAreEqual.ts +++ b/packages/crdx/src/graph/headsAreEqual.ts @@ -1,4 +1,4 @@ -import { type Hash } from 'util/index.js' +import { type Hash } from '../util/index.js' export const headsAreEqual = (a: Hash[] | undefined, b: Hash[] | undefined) => { if (a === undefined || b === undefined) return false diff --git a/packages/crdx/src/graph/isPredecessor.ts b/packages/crdx/src/graph/isPredecessor.ts index d4cdf7f4..865153df 100644 --- a/packages/crdx/src/graph/isPredecessor.ts +++ b/packages/crdx/src/graph/isPredecessor.ts @@ -1,5 +1,5 @@ ο»Ώimport { type Graph, type Link } from './types.js' -import { type Hash } from 'util/index.js' +import { type Hash } from '../util/index.js' import { getPredecessorHashes } from './getPredecessors.js' /** Returns true if `a` is a predecessor of `b` */ diff --git a/packages/crdx/src/graph/isSuccessor.ts b/packages/crdx/src/graph/isSuccessor.ts index 7f5eb924..a496a695 100644 --- a/packages/crdx/src/graph/isSuccessor.ts +++ b/packages/crdx/src/graph/isSuccessor.ts @@ -1,5 +1,5 @@ import { type Action, type Link, type Graph } from './types.js' -import { type Hash } from 'util/index.js' +import { type Hash } from '../util/index.js' import { getSuccessorHashes } from './getSuccessors.js' /** Returns true if `a` is a successor of `b` */ diff --git a/packages/crdx/src/graph/merge.ts b/packages/crdx/src/graph/merge.ts index 0a60f323..61d32b5b 100644 --- a/packages/crdx/src/graph/merge.ts +++ b/packages/crdx/src/graph/merge.ts @@ -1,6 +1,6 @@ ο»Ώimport { uniq } from 'lodash-es' import { type Action, type EncryptedLink, type Link, type Graph } from './types.js' -import { type Hash } from 'util/index.js' +import { type Hash } from '../util/index.js' /** * Returns a new graph that contains all the information in the two graphs provided. diff --git a/packages/crdx/src/graph/serialize.ts b/packages/crdx/src/graph/serialize.ts index b83d5d21..c3b84328 100644 --- a/packages/crdx/src/graph/serialize.ts +++ b/packages/crdx/src/graph/serialize.ts @@ -2,7 +2,7 @@ import { pack, unpack } from 'msgpackr' import { decryptGraph } from './decrypt.js' import { redactGraph } from './redactGraph.js' import { type MaybePartlyDecryptedGraph, type Action, type Graph } from './types.js' -import { type Keyring, type KeysetWithSecrets } from 'keyset/index.js' +import { type Keyring, type KeysetWithSecrets } from '../keyset/index.js' export const serialize = (graph: Graph) => { return pack(redactGraph(graph)) diff --git a/packages/crdx/src/graph/test/append.test.ts b/packages/crdx/src/graph/test/append.test.ts index 89d382d4..f4fb4f3a 100644 --- a/packages/crdx/src/graph/test/append.test.ts +++ b/packages/crdx/src/graph/test/append.test.ts @@ -1,7 +1,7 @@ -import { TEST_GRAPH_KEYS as keys, setup } from 'util/testing/setup.js' +import { TEST_GRAPH_KEYS as keys, setup } from '../../util/testing/setup.js' import { describe, expect, test } from 'vitest' -import { append, createGraph, getHead, getRoot } from 'graph/index.js' -import { validate } from 'validator/index.js' +import { append, createGraph, getHead, getRoot } from '../index.js' +import { validate } from '../../validator/index.js' import 'util/testing/expect/toBeValid' const { alice } = setup('alice') diff --git a/packages/crdx/src/graph/test/create.test.ts b/packages/crdx/src/graph/test/create.test.ts index 605d167a..095eccf8 100644 --- a/packages/crdx/src/graph/test/create.test.ts +++ b/packages/crdx/src/graph/test/create.test.ts @@ -1,7 +1,7 @@ -import { TEST_GRAPH_KEYS as keys, setup } from 'util/testing/setup.js' +import { TEST_GRAPH_KEYS as keys, setup } from '../../util/testing/setup.js' import { describe, expect, test } from 'vitest' -import { createGraph, deserialize, getHead, getRoot, serialize } from 'graph/index.js' -import { validate } from 'validator/index.js' +import { createGraph, deserialize, getHead, getRoot, serialize } from '../index.js' +import { validate } from '../../validator/index.js' import 'util/testing/expect/toBeValid.js' const { alice } = setup('alice') diff --git a/packages/crdx/src/graph/test/decrypt.test.ts b/packages/crdx/src/graph/test/decrypt.test.ts index 70e7917b..a55acd1a 100644 --- a/packages/crdx/src/graph/test/decrypt.test.ts +++ b/packages/crdx/src/graph/test/decrypt.test.ts @@ -1,9 +1,9 @@ -import { TEST_GRAPH_KEYS } from 'util/testing/setup.js' +import { TEST_GRAPH_KEYS } from '../../util/testing/setup.js' import { describe, expect, it } from 'vitest' -import { append, createGraph, decryptGraph, decryptLink, redactGraph } from 'graph/index.js' -import { createKeyset } from 'keyset/index.js' -import { createUser } from 'user/index.js' -import { type Hash } from 'util/index.js' +import { append, createGraph, decryptGraph, decryptLink, redactGraph } from '../index.js' +import { createKeyset } from '../../keyset/index.js' +import { createUser } from '../../user/index.js' +import { type Hash } from '../../util/index.js' const keys = TEST_GRAPH_KEYS diff --git a/packages/crdx/src/graph/test/getChildren.test.ts b/packages/crdx/src/graph/test/getChildren.test.ts index 8ae1d2ee..9aead88d 100644 --- a/packages/crdx/src/graph/test/getChildren.test.ts +++ b/packages/crdx/src/graph/test/getChildren.test.ts @@ -1,14 +1,14 @@ import { describe, expect, test } from 'vitest' -import { buildGraph, findByPayload } from 'util/testing/graph.js' -import { getChildren, getRoot } from 'graph/index.js' +import { buildGraph, findByPayload } from '../../util/testing/graph.js' +import { getChildren, getRoot } from '../index.js' describe('getChildren', () => { const graph = buildGraph(` β”Œβ”€ e ─ g ─┐ β”Œβ”€ c ─ d ── β”œβ”€ o ─┐ a ─ b ── └─── f ──── β”œβ”€ n - β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ - └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ + β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ + └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ `) test('root has 1 child', () => expect(getChildren(graph, getRoot(graph))).toHaveLength(1)) test('b has 3 children', () => diff --git a/packages/crdx/src/graph/test/getConcurrentLinks.test.ts b/packages/crdx/src/graph/test/getConcurrentLinks.test.ts index 45231366..f061dfee 100644 --- a/packages/crdx/src/graph/test/getConcurrentLinks.test.ts +++ b/packages/crdx/src/graph/test/getConcurrentLinks.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from 'vitest' -import { buildGraph, byPayload, findByPayload, getPayloads } from 'util/testing/graph.js' -import { type Graph, getConcurrentBubbles, getConcurrentLinks } from 'graph/index.js' +import { buildGraph, byPayload, findByPayload, getPayloads } from '../../util/testing/graph.js' +import { type Graph, getConcurrentBubbles, getConcurrentLinks } from '../index.js' describe('graphs', () => { describe('getConcurrentLinks', () => { @@ -37,7 +37,7 @@ describe('graphs', () => { }) describe('simple open graph', () => { - const graph = buildGraph(` + const graph = buildGraph(` β”Œβ”€ b a ── └─ c diff --git a/packages/crdx/src/graph/test/getParentMap.test.ts b/packages/crdx/src/graph/test/getParentMap.test.ts index d2381da7..7d0e9c47 100644 --- a/packages/crdx/src/graph/test/getParentMap.test.ts +++ b/packages/crdx/src/graph/test/getParentMap.test.ts @@ -1,15 +1,15 @@ -import { buildGraph, findByPayload } from 'util/testing/graph.js' +import { buildGraph, findByPayload } from '../../util/testing/graph.js' import { describe, expect, it } from 'vitest' -import { getLink, getParentMap, type Graph, type Action } from 'graph/index.js' -import { type Hash } from 'util/index.js' +import { getLink, getParentMap, type Graph, type Action } from '../index.js' +import { type Hash } from '../../util/index.js' describe('getParentMap', () => { const graph = buildGraph(` β”Œβ”€ e ─ g ─┐ β”Œβ”€ c ─ d ── β”œβ”€ o ─┐ a ─ b ── └─── f ──── β”œβ”€ n - β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ - └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ + β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ + └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ `) describe('recent hashes', () => { diff --git a/packages/crdx/src/graph/test/getPredecessors.test.ts b/packages/crdx/src/graph/test/getPredecessors.test.ts index 95ce42b3..66a54096 100644 --- a/packages/crdx/src/graph/test/getPredecessors.test.ts +++ b/packages/crdx/src/graph/test/getPredecessors.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from 'vitest' -import { buildGraph, byPayload, findByPayload, getPayloads } from 'util/testing/graph.js' -import { getHead, getParents, getPredecessors, isPredecessor } from 'graph/index.js' +import { buildGraph, byPayload, findByPayload, getPayloads } from '../../util/testing/graph.js' +import { getHead, getParents, getPredecessors, isPredecessor } from '../index.js' describe('graphs', () => { describe('predecessors', () => { @@ -8,8 +8,8 @@ describe('graphs', () => { β”Œβ”€ e ─ g ─┐ β”Œβ”€ c ─ d ── β”œβ”€ o ─┐ a ─ b ── └─── f ──── β”œβ”€ n - β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ - └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ + β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ + └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ `) describe('getParents', () => { diff --git a/packages/crdx/src/graph/test/getSequence.test.ts b/packages/crdx/src/graph/test/getSequence.test.ts index a843a681..f77a7b88 100644 --- a/packages/crdx/src/graph/test/getSequence.test.ts +++ b/packages/crdx/src/graph/test/getSequence.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from 'vitest' -import { type XAction, buildGraph, getPayloads } from 'util/testing/graph.js' -import { type Resolver, getConcurrentLinks, getSequence } from 'graph/index.js' -import { type Hash } from 'util/index.js' +import { type XAction, buildGraph, getPayloads } from '../../util/testing/graph.js' +import { type Resolver, getConcurrentLinks, getSequence } from '../index.js' +import { type Hash } from '../../util/index.js' describe('graphs', () => { describe('getSequence', () => { @@ -64,7 +64,7 @@ describe('graphs', () => { }) test('simple graph', () => { - const graph = buildGraph(` + const graph = buildGraph(` β”Œβ”€ b a ── └─ c @@ -80,8 +80,8 @@ describe('graphs', () => { β”Œβ”€ e ─ g ─┐ β”Œβ”€ c ─ d ── β”œβ”€ o ─┐ a ─ b ── └─── f ──── β”œβ”€ n - β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ - └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ + β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ + └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ `) const sequence = getSequence(graph, resolver) const payloads = getPayloads(sequence) @@ -109,10 +109,10 @@ describe('graphs', () => { test('multiple heads', () => { const graph = buildGraph(` β”Œβ”€ e ─ g ─┐ - β”Œβ”€ c ─ d ── β”œβ”€ o - a ─ b ── └─── f β”€β”€β”€β”˜ - β”œβ”€ h ─ i - └─ j + β”Œβ”€ c ─ d ── β”œβ”€ o + a ─ b ── └─── f β”€β”€β”€β”˜ + β”œβ”€ h ─ i + └─ j `) const sequence = getSequence(graph, resolver) const payloads = getPayloads(sequence) diff --git a/packages/crdx/src/graph/test/getSuccessors.test.ts b/packages/crdx/src/graph/test/getSuccessors.test.ts index 8e10b8b2..d78a1ad1 100644 --- a/packages/crdx/src/graph/test/getSuccessors.test.ts +++ b/packages/crdx/src/graph/test/getSuccessors.test.ts @@ -1,6 +1,6 @@ ο»Ώimport { describe, expect, it, test } from 'vitest' -import { type XLink, buildGraph, findByPayload, getPayloads } from 'util/testing/graph.js' -import { getRoot, getSuccessors, isSuccessor } from 'graph/index.js' +import { type XLink, buildGraph, findByPayload, getPayloads } from '../../util/testing/graph.js' +import { getRoot, getSuccessors, isSuccessor } from '../index.js' describe('graphs', () => { describe('successors', () => { @@ -8,8 +8,8 @@ describe('graphs', () => { β”Œβ”€ e ─ g ─┐ β”Œβ”€ c ─ d ── β”œβ”€ o ─┐ a ─ b ── └─── f ──── β”œβ”€ n - β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ - └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ + β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ + └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ `) describe('getSuccessors', () => { diff --git a/packages/crdx/src/graph/test/merge.test.ts b/packages/crdx/src/graph/test/merge.test.ts index 8c48f2f1..1ea47f3f 100644 --- a/packages/crdx/src/graph/test/merge.test.ts +++ b/packages/crdx/src/graph/test/merge.test.ts @@ -1,8 +1,8 @@ -import { TEST_GRAPH_KEYS as keys, setup } from 'util/testing/setup.js' +import { TEST_GRAPH_KEYS as keys, setup } from '../../util/testing/setup.js' import { clone } from 'lodash-es' import 'util/testing/expect/toBeValid' import { describe, expect, test } from 'vitest' -import { append, createGraph, merge } from 'graph/index.js' +import { append, createGraph, merge } from '../index.js' const { alice, bob } = setup('alice', 'bob') const defaultUser = alice diff --git a/packages/crdx/src/graph/test/topoSort.test.ts b/packages/crdx/src/graph/test/topoSort.test.ts index 81d76dd1..602db8c1 100644 --- a/packages/crdx/src/graph/test/topoSort.test.ts +++ b/packages/crdx/src/graph/test/topoSort.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from 'vitest' -import { buildGraph, byPayload, getPayloads } from 'util/testing/graph.js' -import { topoSort } from 'graph/index.js' +import { buildGraph, byPayload, getPayloads } from '../../util/testing/graph.js' +import { topoSort } from '../index.js' describe('graphs', () => { describe('topoSort', () => { @@ -20,7 +20,7 @@ describe('graphs', () => { }) describe('simple graph', () => { - const graph = buildGraph(` + const graph = buildGraph(` β”Œβ”€ b a ── └─ c @@ -44,8 +44,8 @@ describe('graphs', () => { β”Œβ”€ e ─ g ─┐ β”Œβ”€ c ─ d ── β”œβ”€ o ─┐ a ─ b ── └─── f ──── β”œβ”€ n - β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ - └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ + β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ + └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ `) test('sorted by payload', () => { const sequence = topoSort(graph, { comparator: byPayload }) @@ -110,10 +110,10 @@ describe('graphs', () => { describe('multiple heads', () => { const graph = buildGraph(` β”Œβ”€ e ─ g ─┐ - β”Œβ”€ c ─ d ── β”œβ”€ o - a ─ b ── └─── f β”€β”€β”€β”˜ - β”œβ”€ h ─ i - └─ j + β”Œβ”€ c ─ d ── β”œβ”€ o + a ─ b ── └─── f β”€β”€β”€β”˜ + β”œβ”€ h ─ i + └─ j `) test('sorted by payload', () => { const sequence = topoSort(graph, { comparator: byPayload }) diff --git a/packages/crdx/src/graph/topoSort.ts b/packages/crdx/src/graph/topoSort.ts index 4c08213a..b51394b3 100644 --- a/packages/crdx/src/graph/topoSort.ts +++ b/packages/crdx/src/graph/topoSort.ts @@ -1,6 +1,6 @@ ο»Ώimport { getChildrenHashes } from './children.js' import { type Action, type Link, type LinkComparator, type Graph } from './types.js' -import { type Hash } from 'util/index.js' +import { type Hash } from '../util/index.js' /** Flattens a hash graph into a sequence */ export const topoSort = ( diff --git a/packages/crdx/src/graph/types.ts b/packages/crdx/src/graph/types.ts index 76f4e5db..d7a9d3cc 100644 --- a/packages/crdx/src/graph/types.ts +++ b/packages/crdx/src/graph/types.ts @@ -1,4 +1,4 @@ -ο»Ώimport type { Base58, Hash, Optional, UnixTimestamp } from 'util/types.js' +ο»Ώimport type { Base58, Hash, Optional, UnixTimestamp } from '../util/types.js' /** * A hash graph is an acyclic directed graph of links. Each link is **asymmetrically encrypted and diff --git a/packages/crdx/src/keyset/createKeyring.ts b/packages/crdx/src/keyset/createKeyring.ts index ead951b8..02ba850d 100644 --- a/packages/crdx/src/keyset/createKeyring.ts +++ b/packages/crdx/src/keyset/createKeyring.ts @@ -1,4 +1,4 @@ -import { arrayToMap } from 'util/index.js' +import { arrayToMap } from '../util/index.js' import { isKeyring, isKeyset, type Keyring, type KeysetWithSecrets } from './types.js' export const createKeyring = (keys: Keyring | KeysetWithSecrets | KeysetWithSecrets[]): Keyring => { diff --git a/packages/crdx/src/keyset/createKeyset.ts b/packages/crdx/src/keyset/createKeyset.ts index 975bc8d0..195d0abd 100644 --- a/packages/crdx/src/keyset/createKeyset.ts +++ b/packages/crdx/src/keyset/createKeyset.ts @@ -1,7 +1,7 @@ ο»Ώimport { hash, asymmetric, signatures, stretch, randomKey } from '@localfirst/crypto' import { type KeyScope, type KeysetWithSecrets } from './types.js' -import { HashPurpose } from 'constants.js' -import { type Optional } from 'util/index.js' +import { HashPurpose } from '../constants.js' +import { type Optional } from '../util/index.js' const { SIGNATURE, ENCRYPTION, SYMMETRIC } = HashPurpose diff --git a/packages/crdx/src/keyset/redactKeys.ts b/packages/crdx/src/keyset/redactKeys.ts index 7d115e99..eb00f0ea 100644 --- a/packages/crdx/src/keyset/redactKeys.ts +++ b/packages/crdx/src/keyset/redactKeys.ts @@ -1,4 +1,4 @@ -ο»Ώimport { hasSecrets, type Keyset, type KeysetWithSecrets } from 'keyset/types.js' +ο»Ώimport { hasSecrets, type Keyset, type KeysetWithSecrets } from '../keyset/types.js' /** * There are two kinds of keysets: diff --git a/packages/crdx/src/keyset/test/createKeyset.test.ts b/packages/crdx/src/keyset/test/createKeyset.test.ts index 3a23227b..095eb1a9 100644 --- a/packages/crdx/src/keyset/test/createKeyset.test.ts +++ b/packages/crdx/src/keyset/test/createKeyset.test.ts @@ -1,8 +1,8 @@ import { asymmetric, keyToBytes, signatures } from '@localfirst/crypto' import { describe, expect, it } from 'vitest' -import { EPHEMERAL_SCOPE } from 'constants.js' -import { createKeyset } from 'keyset/createKeyset.js' -import { KeyType } from 'keyset/types.js' +import { EPHEMERAL_SCOPE } from '../../constants.js' +import { createKeyset } from '../createKeyset.js' +import { KeyType } from '../types.js' const { USER } = KeyType diff --git a/packages/crdx/src/keyset/test/getLatestGeneration.test.ts b/packages/crdx/src/keyset/test/getLatestGeneration.test.ts index 09ae1490..5e199657 100644 --- a/packages/crdx/src/keyset/test/getLatestGeneration.test.ts +++ b/packages/crdx/src/keyset/test/getLatestGeneration.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest' import { getLatestGeneration } from '../getLatestGeneration.js' -import { createKeyring, createKeyset } from 'index.js' +import { createKeyring, createKeyset } from '../../index.js' const TEAM_SCOPE = { type: 'TEAM', name: 'TEAM' } diff --git a/packages/crdx/src/keyset/test/redactKeys.test.ts b/packages/crdx/src/keyset/test/redactKeys.test.ts index 640102c3..5d7be750 100644 --- a/packages/crdx/src/keyset/test/redactKeys.test.ts +++ b/packages/crdx/src/keyset/test/redactKeys.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' -import { EPHEMERAL_SCOPE } from 'constants.js' -import { KeyType, type KeysetWithSecrets, createKeyset, redactKeys } from 'keyset/index.js' +import { EPHEMERAL_SCOPE } from '../../constants.js' +import { KeyType, type KeysetWithSecrets, createKeyset, redactKeys } from '../index.js' describe('redact', () => { it('should redact secrets from a random keyset', () => { diff --git a/packages/crdx/src/store/Store.ts b/packages/crdx/src/store/Store.ts index 132c889b..05bccbde 100644 --- a/packages/crdx/src/store/Store.ts +++ b/packages/crdx/src/store/Store.ts @@ -11,12 +11,12 @@ import { type Action, type Graph, type Resolver, -} from 'graph/index.js' -import { createKeyring } from 'keyset/createKeyring.js' -import { isKeyset, type Keyring, type KeysetWithSecrets } from 'keyset/index.js' -import { type UserWithSecrets } from 'user/index.js' -import { type Hash, type Optional } from 'util/index.js' -import { validate, type ValidatorSet } from 'validator/index.js' +} from '../graph/index.js' +import { createKeyring } from '../keyset/createKeyring.js' +import { isKeyset, type Keyring, type KeysetWithSecrets } from '../keyset/index.js' +import { type UserWithSecrets } from '../user/index.js' +import { type Hash, type Optional } from '../util/index.js' +import { validate, type ValidatorSet } from '../validator/index.js' import { type StoreOptions } from './StoreOptions.js' import { makeMachine } from './makeMachine.js' import { type Reducer } from './types.js' diff --git a/packages/crdx/src/store/StoreOptions.ts b/packages/crdx/src/store/StoreOptions.ts index 613646e7..dee1c86a 100644 --- a/packages/crdx/src/store/StoreOptions.ts +++ b/packages/crdx/src/store/StoreOptions.ts @@ -1,8 +1,8 @@ import { type Reducer } from './types.js' -import { type Action, type Graph, type Resolver } from 'graph/index.js' -import { type Keyring, type KeysetWithSecrets } from 'keyset/index.js' -import { type UserWithSecrets } from 'user/index.js' -import { type ValidatorSet } from 'validator/index.js' +import { type Action, type Graph, type Resolver } from '../graph/index.js' +import { type Keyring, type KeysetWithSecrets } from '../keyset/index.js' +import { type UserWithSecrets } from '../user/index.js' +import { type ValidatorSet } from '../validator/index.js' export type StoreOptions = { /** The user local user, along with their secret keys for signing, encrypting, etc. */ diff --git a/packages/crdx/src/store/compose.ts b/packages/crdx/src/store/compose.ts index fcecf1df..d40a7568 100644 --- a/packages/crdx/src/store/compose.ts +++ b/packages/crdx/src/store/compose.ts @@ -1,5 +1,5 @@ import { type Reducer } from './types.js' -import { type Action } from 'graph/index.js' +import { type Action } from '../graph/index.js' export const compose = (reducers: Array>): Reducer => diff --git a/packages/crdx/src/store/createStore.ts b/packages/crdx/src/store/createStore.ts index 41ffc19e..ad96481f 100644 --- a/packages/crdx/src/store/createStore.ts +++ b/packages/crdx/src/store/createStore.ts @@ -1,6 +1,6 @@ import { Store } from './Store.js' import { type StoreOptions } from './StoreOptions.js' -import { type Action } from 'graph/index.js' +import { type Action } from '../graph/index.js' export const createStore = (options: StoreOptions) => { return new Store(options) diff --git a/packages/crdx/src/store/makeMachine.ts b/packages/crdx/src/store/makeMachine.ts index 8f17ed59..afd9a5ff 100644 --- a/packages/crdx/src/store/makeMachine.ts +++ b/packages/crdx/src/store/makeMachine.ts @@ -1,6 +1,6 @@ import { type Reducer } from './types.js' -import { type Action, getSequence, type Graph, type Resolver } from 'graph/index.js' -import { validate, type ValidatorSet } from 'validator/index.js' +import { type Action, getSequence, type Graph, type Resolver } from '../graph/index.js' +import { validate, type ValidatorSet } from '../validator/index.js' export const makeMachine = ({ initialState, diff --git a/packages/crdx/src/store/test/counter.test.ts b/packages/crdx/src/store/test/counter.test.ts index b16812bb..17b3523f 100644 --- a/packages/crdx/src/store/test/counter.test.ts +++ b/packages/crdx/src/store/test/counter.test.ts @@ -1,12 +1,12 @@ -import { TEST_GRAPH_KEYS as keys } from 'util/testing/setup.js' +import { TEST_GRAPH_KEYS as keys } from '../../util/testing/setup.js' import { describe, expect, test } from 'vitest' -import { createStore } from 'store/index.js' -import { createUser } from 'user/index.js' +import { createStore } from '../index.js' +import { createUser } from '../../user/index.js' import { counterReducer } from './shared/counterReducer.js' /* This is intended to be the simplest possible proof of concept: An increment-only counter. There is -no custom resolver because there are no conflicts possible. +no custom resolver because there are no conflicts possible. */ const alice = createUser('alice') diff --git a/packages/crdx/src/store/test/createStore.test.ts b/packages/crdx/src/store/test/createStore.test.ts index b454549a..b02efd13 100644 --- a/packages/crdx/src/store/test/createStore.test.ts +++ b/packages/crdx/src/store/test/createStore.test.ts @@ -1,9 +1,9 @@ import { asymmetric } from '@localfirst/crypto' -import { createGraph, getRoot, serialize } from 'graph/index.js' -import { createStore } from 'store/index.js' -import { createUser } from 'user/index.js' +import { createGraph, getRoot, serialize } from '../../graph/index.js' +import { createStore } from '../index.js' +import { createUser } from '../../user/index.js' import 'util/testing/expect/toBeValid' -import { TEST_GRAPH_KEYS as keys } from 'util/testing/setup.js' +import { TEST_GRAPH_KEYS as keys } from '../../util/testing/setup.js' import { describe, expect, test } from 'vitest' import { counterReducer, diff --git a/packages/crdx/src/store/test/scheduler.test.ts b/packages/crdx/src/store/test/scheduler.test.ts index 6af3b67b..ee7e36a1 100644 --- a/packages/crdx/src/store/test/scheduler.test.ts +++ b/packages/crdx/src/store/test/scheduler.test.ts @@ -1,10 +1,10 @@ -import { TEST_GRAPH_KEYS as keys } from 'util/testing/setup.js' +import { TEST_GRAPH_KEYS as keys } from '../../util/testing/setup.js' import { describe, expect, it } from 'vitest' -import { createGraph, type Link, type Resolver, type RootAction } from 'graph/index.js' -import { createStore } from 'store/index.js' -import { type Reducer } from 'store/types.js' -import { createUser } from 'user/index.js' -import { type UnixTimestamp } from 'util/index.js' +import { createGraph, type Link, type Resolver, type RootAction } from '../../graph/index.js' +import { createStore } from '../index.js' +import { type Reducer } from '../types.js' +import { createUser } from '../../user/index.js' +import { type UnixTimestamp } from '../../util/index.js' /** * This example simulates a meeting room scheduler and demonstrates a custom resolver implementing diff --git a/packages/crdx/src/store/test/scrabble.test.ts b/packages/crdx/src/store/test/scrabble.test.ts index 7dea50c7..5cbf1a14 100644 --- a/packages/crdx/src/store/test/scrabble.test.ts +++ b/packages/crdx/src/store/test/scrabble.test.ts @@ -1,18 +1,18 @@ import { makeRandom } from '@herbcaudill/random' -import { TEST_GRAPH_KEYS as keys } from 'util/testing/setup.js' +import { TEST_GRAPH_KEYS as keys } from '../../util/testing/setup.js' import { describe, expect, test } from 'vitest' -import { type RootAction, createGraph } from 'graph/index.js' -import { type Store, createStore } from 'store/index.js' -import { type Reducer } from 'store/types.js' -import { createUser } from 'user/index.js' -import { arrayToMap } from 'util/index.js' +import { type RootAction, createGraph } from '../../graph/index.js' +import { type Store, createStore } from '../index.js' +import { type Reducer } from '../types.js' +import { createUser } from '../../user/index.js' +import { arrayToMap } from '../../util/index.js' /* This is a somewhat more complicated example, modeling the game Scrabble Attacks (created by Nancy -Hawa). See https://github.com/HerbCaudill/scrabbleattacks for rules. +Hawa). See https://github.com/HerbCaudill/scrabbleattacks for rules. This store doesn't have a custom resolver; any conflicting actions (e.g. concurrent attempts to take -the same letter) are ordered arbitrarily and dealt with in the reducer. +the same letter) are ordered arbitrarily and dealt with in the reducer. */ const alice = createUser('alice', 'alice') diff --git a/packages/crdx/src/store/test/shared/counterReducer.ts b/packages/crdx/src/store/test/shared/counterReducer.ts index 64c26ab5..0d225b03 100644 --- a/packages/crdx/src/store/test/shared/counterReducer.ts +++ b/packages/crdx/src/store/test/shared/counterReducer.ts @@ -1,5 +1,5 @@ -import { type RootAction } from 'graph/index.js' -import { type Reducer } from 'store/types.js' +import { type RootAction } from '../../../graph/index.js' +import { type Reducer } from '../../types.js' // Counter diff --git a/packages/crdx/src/store/types.ts b/packages/crdx/src/store/types.ts index c3e423e1..62c5ab9c 100644 --- a/packages/crdx/src/store/types.ts +++ b/packages/crdx/src/store/types.ts @@ -1,4 +1,4 @@ -import { type Action, type Link } from 'graph/index.js' +import { type Action, type Link } from '../graph/index.js' export type Reducer> = ( state: S, diff --git a/packages/crdx/src/sync/generateMessage.ts b/packages/crdx/src/sync/generateMessage.ts index 5a35caf0..9e7c6af1 100644 --- a/packages/crdx/src/sync/generateMessage.ts +++ b/packages/crdx/src/sync/generateMessage.ts @@ -7,8 +7,8 @@ import { getPredecessorHashes, type Graph, headsAreEqual, -} from 'graph/index.js' -import { type Hash } from 'util/index.js' +} from '../graph/index.js' +import { type Hash } from '../util/index.js' /** * Generates a new sync message for a peer based on our current graph and our sync state with them. diff --git a/packages/crdx/src/sync/getMissingLinks.ts b/packages/crdx/src/sync/getMissingLinks.ts index 5d555326..b4f027e0 100644 --- a/packages/crdx/src/sync/getMissingLinks.ts +++ b/packages/crdx/src/sync/getMissingLinks.ts @@ -1,4 +1,4 @@ -import type { Action, Graph } from 'graph/types.js' +import type { Action, Graph } from '../graph/types.js' export function getMissingLinks(graph: Graph) { // collect all the `prev` hashes from all of the links in the graph diff --git a/packages/crdx/src/sync/receiveMessage.ts b/packages/crdx/src/sync/receiveMessage.ts index 69edffce..fd5a3541 100644 --- a/packages/crdx/src/sync/receiveMessage.ts +++ b/packages/crdx/src/sync/receiveMessage.ts @@ -1,8 +1,8 @@ import { assert } from '@localfirst/shared' -import { decryptGraph, type DecryptFn } from 'graph/decrypt.js' -import { getChildMap, invertLinkMap, merge, type Action, type Graph } from 'graph/index.js' -import { createKeyring, type Keyring, type KeysetWithSecrets } from 'keyset/index.js' -import { validate } from 'validator/index.js' +import { decryptGraph, type DecryptFn } from '../graph/decrypt.js' +import { getChildMap, invertLinkMap, merge, type Action, type Graph } from '../graph/index.js' +import { createKeyring, type Keyring, type KeysetWithSecrets } from '../keyset/index.js' +import { validate } from '../validator/index.js' import { type SyncMessage, type SyncState } from './types.js' /** diff --git a/packages/crdx/src/sync/test/sync.test.ts b/packages/crdx/src/sync/test/sync.test.ts index 069802a1..3298b4a5 100644 --- a/packages/crdx/src/sync/test/sync.test.ts +++ b/packages/crdx/src/sync/test/sync.test.ts @@ -1,14 +1,14 @@ import { assert } from '@localfirst/shared' -import { append, createGraph, headsAreEqual, type Graph } from 'graph/index.js' -import { generateMessage, initSyncState, receiveMessage } from 'sync/index.js' -import { createUser, type UserWithSecrets } from 'user/index.js' +import { append, createGraph, headsAreEqual, type Graph } from '../../graph/index.js' +import { generateMessage, initSyncState, receiveMessage } from '../index.js' +import { createUser, type UserWithSecrets } from '../../user/index.js' import { expectNotToBeSynced, expectToBeSynced, setupWithNetwork, type Network, -} from 'util/testing/Network.js' -import { TEST_GRAPH_KEYS as keys } from 'util/testing/setup.js' +} from '../../util/testing/Network.js' +import { TEST_GRAPH_KEYS as keys } from '../../util/testing/setup.js' import { describe, expect, it, vitest } from 'vitest' const { setSystemTime } = vitest.useFakeTimers() diff --git a/packages/crdx/src/sync/types.ts b/packages/crdx/src/sync/types.ts index 875893c1..b9a2e042 100644 --- a/packages/crdx/src/sync/types.ts +++ b/packages/crdx/src/sync/types.ts @@ -1,6 +1,6 @@ -import { type EncryptedLink, type LinkMap } from 'graph/index.js' -import { type Hash } from 'util/index.js' -import { type ValidationError } from 'validator/index.js' +import { type EncryptedLink, type LinkMap } from '../graph/index.js' +import { type Hash } from '../util/index.js' +import { type ValidationError } from '../validator/index.js' export type SyncState = { their: { diff --git a/packages/crdx/src/user/createUser.ts b/packages/crdx/src/user/createUser.ts index a78bbead..db54bb55 100644 --- a/packages/crdx/src/user/createUser.ts +++ b/packages/crdx/src/user/createUser.ts @@ -1,7 +1,7 @@ ο»Ώimport { randomKey } from '@localfirst/crypto' import { createId } from '@paralleldrive/cuid2' -import { createKeyset, KeyType } from 'keyset/index.js' -import { type UserWithSecrets } from 'user/types.js' +import { createKeyset, KeyType } from '../keyset/index.js' +import { type UserWithSecrets } from './types.js' /** * Creates a new local user, with randomly-generated keys. diff --git a/packages/crdx/src/user/redact.ts b/packages/crdx/src/user/redact.ts index 13f6439e..5c36e9e0 100644 --- a/packages/crdx/src/user/redact.ts +++ b/packages/crdx/src/user/redact.ts @@ -1,6 +1,6 @@ ο»Ώimport { type UserWithSecrets } from './types.js' -import { redactKeys } from 'keyset/index.js' -import { type User } from 'user/index.js' +import { redactKeys } from '../keyset/index.js' +import { type User } from '../index.js' export const redactUser = (user: User | UserWithSecrets): User => { const { userId, userName } = user diff --git a/packages/crdx/src/user/test/user.test.ts b/packages/crdx/src/user/test/user.test.ts index 2aab9244..70ccb152 100644 --- a/packages/crdx/src/user/test/user.test.ts +++ b/packages/crdx/src/user/test/user.test.ts @@ -1,7 +1,7 @@ import { asymmetric, signatures, symmetric } from '@localfirst/crypto' import { describe, expect, it } from 'vitest' import 'util/testing/expect/toLookLikeKeyset' -import { createUser, redactUser } from 'user/index.js' +import { createUser, redactUser } from '../index.js' describe('user', () => { it('creates a new user', () => { diff --git a/packages/crdx/src/user/types.ts b/packages/crdx/src/user/types.ts index 1b1cd7f8..28d6ab41 100644 --- a/packages/crdx/src/user/types.ts +++ b/packages/crdx/src/user/types.ts @@ -1,4 +1,4 @@ -ο»Ώimport { type Keyset, type KeysetWithSecrets } from 'keyset/index.js' +ο»Ώimport { type Keyset, type KeysetWithSecrets } from '../keyset/index.js' export type User = { /** Unique ID populated on creation. */ diff --git a/packages/crdx/src/util/index.ts b/packages/crdx/src/util/index.ts index afe547e8..5379e74a 100644 --- a/packages/crdx/src/util/index.ts +++ b/packages/crdx/src/util/index.ts @@ -1,2 +1,2 @@ -export * from 'util/arrayToMap.js' -export * from 'util/types.js' +export * from '../util/arrayToMap.js' +export * from '../util/types.js' diff --git a/packages/crdx/src/util/messageSummary.ts b/packages/crdx/src/util/messageSummary.ts index 75e4281d..8ed5ed47 100644 --- a/packages/crdx/src/util/messageSummary.ts +++ b/packages/crdx/src/util/messageSummary.ts @@ -1,6 +1,6 @@ -import { type NetworkMessage } from 'util/testing/Network.js' +import { type NetworkMessage } from '../util/testing/Network.js' import { truncateHashes } from '@localfirst/shared' -import { type SyncMessage } from 'sync/index.js' +import { type SyncMessage } from '../sync/index.js' export const logMessages = (msgs: NetworkMessage[]) => { const result = msgs.map(m => JSON.stringify(networkMessageSummary(m))).join('\n') diff --git a/packages/crdx/src/util/testing/Network.ts b/packages/crdx/src/util/testing/Network.ts index 73a9ce36..a18c0231 100644 --- a/packages/crdx/src/util/testing/Network.ts +++ b/packages/crdx/src/util/testing/Network.ts @@ -1,14 +1,14 @@ // ignore file coverage -import { TEST_GRAPH_KEYS as keys } from 'util/testing/setup.js' +import { TEST_GRAPH_KEYS as keys } from './setup.js' import { expect } from 'vitest' import { setup } from './setup.js' -import { createGraph, type Graph, headsAreEqual } from 'graph/index.js' -import { type KeysetWithSecrets } from 'keyset/index.js' -import { generateMessage } from 'sync/generateMessage.js' -import { initSyncState } from 'sync/initSyncState.js' -import { receiveMessage } from 'sync/receiveMessage.js' -import { type SyncMessage, type SyncState } from 'sync/types.js' -import { type UserWithSecrets } from 'user/index.js' +import { createGraph, type Graph, headsAreEqual } from '../../graph/index.js' +import { type KeysetWithSecrets } from '../../keyset/index.js' +import { generateMessage } from '../../sync/generateMessage.js' +import { initSyncState } from '../../sync/initSyncState.js' +import { receiveMessage } from '../../sync/receiveMessage.js' +import { type SyncMessage, type SyncState } from '../../sync/types.js' +import { type UserWithSecrets } from '../../user/index.js' /** Simulates a peer-to-peer network. */ export class Network { diff --git a/packages/crdx/src/util/testing/expect/toBeValid.ts b/packages/crdx/src/util/testing/expect/toBeValid.ts index 6b1770e4..4adff992 100644 --- a/packages/crdx/src/util/testing/expect/toBeValid.ts +++ b/packages/crdx/src/util/testing/expect/toBeValid.ts @@ -1,5 +1,5 @@ ο»Ώimport { expect } from 'vitest' -import { type ValidationResult } from 'validator/index.js' +import { type ValidationResult } from '../../../validator/index.js' // ignore coverage expect.extend({ diff --git a/packages/crdx/src/util/testing/expect/toLookLikeKeyset.ts b/packages/crdx/src/util/testing/expect/toLookLikeKeyset.ts index 7841012b..ea4f6bd8 100644 --- a/packages/crdx/src/util/testing/expect/toLookLikeKeyset.ts +++ b/packages/crdx/src/util/testing/expect/toLookLikeKeyset.ts @@ -1,5 +1,5 @@ ο»Ώimport { expect } from 'vitest' -import { type Keyset } from 'keyset/index.js' +import { type Keyset } from '../../../keyset/index.js' // ignore file coverage expect.extend({ toLookLikeKeyset(maybeKeyset: Keyset | Record) { diff --git a/packages/crdx/src/util/testing/graph.ts b/packages/crdx/src/util/testing/graph.ts index 05a25b34..4fcf128a 100644 --- a/packages/crdx/src/util/testing/graph.ts +++ b/packages/crdx/src/util/testing/graph.ts @@ -1,9 +1,9 @@ -ο»Ώimport { TEST_GRAPH_KEYS as keys, setup } from 'util/testing/setup.js' -import { append } from 'graph/append.js' -import { createGraph } from 'graph/createGraph.js' -import { merge } from 'graph/merge.js' -import { type Action, type Graph, type Link } from 'graph/types.js' -import { type KeysetWithSecrets } from 'keyset/index.js' +ο»Ώimport { TEST_GRAPH_KEYS as keys, setup } from './setup.js' +import { append } from '../../graph/append.js' +import { createGraph } from '../../graph/createGraph.js' +import { merge } from '../../graph/merge.js' +import { type Action, type Graph, type Link } from '../../graph/types.js' +import { type KeysetWithSecrets } from '../../keyset/index.js' const { alice } = setup('alice') @@ -56,7 +56,7 @@ export const buildGraph = (type: string) => { // simple closed case trim(` β”Œβ”€ b ─ c ─┐ - a ── β”œβ”€ e + a ── β”œβ”€ e └─── d β”€β”€β”€β”˜ `): { @@ -71,7 +71,7 @@ export const buildGraph = (type: string) => { // double closed case trim(` β”Œβ”€ b ─ c ─┐ β”Œβ”€ f ─ g ─┐ - a ── β”œβ”€ e ── β”œβ”€ i + a ── β”œβ”€ e ── β”œβ”€ i └─── d β”€β”€β”€β”˜ └─── h β”€β”€β”€β”˜ `): { @@ -142,10 +142,10 @@ export const buildGraph = (type: string) => { // multiple heads case trim(` β”Œβ”€ e ─ g ─┐ - β”Œβ”€ c ─ d ── β”œβ”€ o - a ─ b ── └─── f β”€β”€β”€β”˜ - β”œβ”€ h ─ i - └─ j + β”Œβ”€ c ─ d ── β”œβ”€ o + a ─ b ── └─── f β”€β”€β”€β”˜ + β”œβ”€ h ─ i + └─ j `): { const a = appendLink(root, 'a', keys) const b = appendLink(a, 'b', keys) diff --git a/packages/crdx/src/util/testing/setup.ts b/packages/crdx/src/util/testing/setup.ts index 65f46ee0..5dc652f6 100644 --- a/packages/crdx/src/util/testing/setup.ts +++ b/packages/crdx/src/util/testing/setup.ts @@ -1,12 +1,12 @@ ο»Ώimport { type Base58 } from '@localfirst/crypto' import { arrayToMap } from './arrayToMap.js' -import { type KeysetWithSecrets } from 'keyset/index.js' -import * as users from 'user/index.js' -import { type UserWithSecrets } from 'user/index.js' +import { type KeysetWithSecrets } from '../../keyset/index.js' +import * as users from '../../user/index.js' +import { type UserWithSecrets } from '../../user/index.js' import { assert } from '@localfirst/shared' /** -Usage: +Usage: ```ts const {alice, bob} = setup(['alice', 'bob']) diff --git a/packages/crdx/src/validator/types.ts b/packages/crdx/src/validator/types.ts index db5c8c00..27f0f4f2 100644 --- a/packages/crdx/src/validator/types.ts +++ b/packages/crdx/src/validator/types.ts @@ -1,4 +1,4 @@ -import { type Action, type Link, type Graph } from 'graph/index.js' +import { type Action, type Link, type Graph } from '../graph/index.js' export type InvalidResult = { isValid: false diff --git a/packages/crdx/src/validator/validate.ts b/packages/crdx/src/validator/validate.ts index 306f20a4..8613e276 100644 --- a/packages/crdx/src/validator/validate.ts +++ b/packages/crdx/src/validator/validate.ts @@ -1,9 +1,9 @@ ο»Ώimport { memoize } from '@localfirst/shared' import { type ValidationResult, type ValidatorSet } from './types.js' import { fail, validators } from './validators.js' -import { VALID } from 'constants.js' -import { hashEncryptedLink } from 'graph/hashLink.js' -import { type Action, type Link, type Graph } from 'graph/types.js' +import { VALID } from '../constants.js' +import { hashEncryptedLink } from '../graph/hashLink.js' +import { type Action, type Link, type Graph } from '../graph/types.js' import { hash } from '@localfirst/crypto' /** diff --git a/packages/crdx/src/validator/validators.ts b/packages/crdx/src/validator/validators.ts index fbacffde..885d464e 100644 --- a/packages/crdx/src/validator/validators.ts +++ b/packages/crdx/src/validator/validators.ts @@ -1,6 +1,6 @@ -ο»Ώimport { ROOT, VALID } from 'constants.js' -import { getRoot } from 'graph/getRoot.js' -import { hashEncryptedLink } from 'graph/hashLink.js' +ο»Ώimport { ROOT, VALID } from '../constants.js' +import { getRoot } from '../graph/getRoot.js' +import { hashEncryptedLink } from '../graph/hashLink.js' import { ValidationError, type ValidatorSet } from './types.js' export const validators: ValidatorSet = { diff --git a/packages/crdx/tsconfig.json b/packages/crdx/tsconfig.json index ae3ea476..17633295 100644 --- a/packages/crdx/tsconfig.json +++ b/packages/crdx/tsconfig.json @@ -1,12 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "baseUrl": "src", "outDir": "dist", - "rootDir": "src", + "rootDir": "src" }, - "include": [ - "src", - "@types" - ] -} \ No newline at end of file + "include": ["src", "@types"] +} From f5650253dc9b31094d405a05cc8cec1f3ccdac06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 16:08:48 +0100 Subject: [PATCH 05/10] Remove baseUrl option from auth-provider-automerge-repo package and fix types --- .../src/AnonymousConnection.ts | 4 ++-- .../auth-provider-automerge-repo/src/AuthProvider.ts | 10 +++++----- .../src/AuthenticatedNetworkAdapter.ts | 2 +- .../src/test/AuthProvider.test.ts | 4 ++-- packages/auth-provider-automerge-repo/tsconfig.json | 10 +++------- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/auth-provider-automerge-repo/src/AnonymousConnection.ts b/packages/auth-provider-automerge-repo/src/AnonymousConnection.ts index 53c44849..9a3e4bb5 100644 --- a/packages/auth-provider-automerge-repo/src/AnonymousConnection.ts +++ b/packages/auth-provider-automerge-repo/src/AnonymousConnection.ts @@ -1,8 +1,8 @@ import { type Message } from '@automerge/automerge-repo' import { debug } from '@localfirst/shared' -import { AbstractConnection, type StateValue } from 'AbstractConnection.js' +import { AbstractConnection, type StateValue } from './AbstractConnection.js' import { pack, unpack } from 'msgpackr' -import { type ShareId } from 'types.js' +import { type ShareId } from './types.js' export class AnonymousConnection extends AbstractConnection { readonly #log: debug.Debugger diff --git a/packages/auth-provider-automerge-repo/src/AuthProvider.ts b/packages/auth-provider-automerge-repo/src/AuthProvider.ts index 011c16dc..058e2c29 100644 --- a/packages/auth-provider-automerge-repo/src/AuthProvider.ts +++ b/packages/auth-provider-automerge-repo/src/AuthProvider.ts @@ -9,12 +9,12 @@ import { EventEmitter } from '@herbcaudill/eventemitter42' import * as Auth from '@localfirst/auth' import { hash } from '@localfirst/crypto' import { debug, memoize, pause } from '@localfirst/shared' -import { type AbstractConnection } from 'AbstractConnection.js' -import { AnonymousConnection } from 'AnonymousConnection.js' -import { buildServerUrl } from 'buildServerUrl.js' -import { getShareId } from 'getShareId.js' +import { type AbstractConnection } from './AbstractConnection.js' +import { AnonymousConnection } from './AnonymousConnection.js' +import { buildServerUrl } from './buildServerUrl.js' +import { getShareId } from './getShareId.js' import { pack, unpack } from 'msgpackr' -import { isJoinMessage, type JoinMessage } from 'types.js' +import { isJoinMessage, type JoinMessage } from './types.js' import { AuthenticatedNetworkAdapter as AuthNetworkAdapter } from './AuthenticatedNetworkAdapter.js' import { CompositeMap } from './CompositeMap.js' import type { diff --git a/packages/auth-provider-automerge-repo/src/AuthenticatedNetworkAdapter.ts b/packages/auth-provider-automerge-repo/src/AuthenticatedNetworkAdapter.ts index dadeeca0..339bdcbc 100644 --- a/packages/auth-provider-automerge-repo/src/AuthenticatedNetworkAdapter.ts +++ b/packages/auth-provider-automerge-repo/src/AuthenticatedNetworkAdapter.ts @@ -1,5 +1,5 @@ import { NetworkAdapter, type Message } from '@automerge/automerge-repo' -import { type ShareId } from 'types.js' +import { type ShareId } from './types.js' /** * An AuthenticatedNetworkAdapter is a NetworkAdapter that wraps another NetworkAdapter and diff --git a/packages/auth-provider-automerge-repo/src/test/AuthProvider.test.ts b/packages/auth-provider-automerge-repo/src/test/AuthProvider.test.ts index b380460c..4b789c06 100644 --- a/packages/auth-provider-automerge-repo/src/test/AuthProvider.test.ts +++ b/packages/auth-provider-automerge-repo/src/test/AuthProvider.test.ts @@ -3,8 +3,8 @@ import { MessageChannelNetworkAdapter } from '@automerge/automerge-repo-network- import { NodeFSStorageAdapter } from '@automerge/automerge-repo-storage-nodefs' import * as Auth from '@localfirst/auth' import { eventPromise } from '@localfirst/shared' -import { getShareId } from 'getShareId.js' -import { type ShareId } from 'types.js' +import { getShareId } from '../getShareId.js' +import { type ShareId } from '../types.js' import { describe, expect, it } from 'vitest' import { AuthProvider } from '../AuthProvider.js' import { authenticated, authenticatedInTime } from './helpers/authenticated.js' diff --git a/packages/auth-provider-automerge-repo/tsconfig.json b/packages/auth-provider-automerge-repo/tsconfig.json index ae3ea476..17633295 100644 --- a/packages/auth-provider-automerge-repo/tsconfig.json +++ b/packages/auth-provider-automerge-repo/tsconfig.json @@ -1,12 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "baseUrl": "src", "outDir": "dist", - "rootDir": "src", + "rootDir": "src" }, - "include": [ - "src", - "@types" - ] -} \ No newline at end of file + "include": ["src", "@types"] +} From 352bab8dfbbb42f9958e9f87ffbc3589e9fa2e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 16:10:08 +0100 Subject: [PATCH 06/10] Remove baseUrl option from auth-syncserver package and fix types --- packages/auth-syncserver/tsconfig.json | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/auth-syncserver/tsconfig.json b/packages/auth-syncserver/tsconfig.json index ae3ea476..17633295 100644 --- a/packages/auth-syncserver/tsconfig.json +++ b/packages/auth-syncserver/tsconfig.json @@ -1,12 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "baseUrl": "src", "outDir": "dist", - "rootDir": "src", + "rootDir": "src" }, - "include": [ - "src", - "@types" - ] -} \ No newline at end of file + "include": ["src", "@types"] +} From dadd53c92a427576f0b9e6b0b2450efbc5426df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 16:53:17 +0100 Subject: [PATCH 07/10] Make decrypt function generic Previous incorrect types surfaced problem with defined DecryptFn declaration --- packages/auth/src/connection/Connection.ts | 12 +++++++++--- packages/crdx/src/graph/decrypt.ts | 11 ++++------- packages/crdx/src/sync/receiveMessage.ts | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/auth/src/connection/Connection.ts b/packages/auth/src/connection/Connection.ts index ceb256a4..8f4456d0 100644 --- a/packages/auth/src/connection/Connection.ts +++ b/packages/auth/src/connection/Connection.ts @@ -1,6 +1,6 @@ /* eslint-disable object-shorthand */ import { EventEmitter } from '@herbcaudill/eventemitter42' -import type { DecryptFnParams } from '@localfirst/crdx' +import type { DecryptFn, DecryptFnParams, Graph } from '@localfirst/crdx' import { generateMessage, headsAreEqual, @@ -33,7 +33,13 @@ import { redactDevice } from '../device/index.js' import * as invitations from '../invitation/index.js' import { pack, unpack } from 'msgpackr' import { getTeamState } from '../team/getTeamState.js' -import { Team, decryptTeamGraph, type TeamAction, type TeamContext } from '../team/index.js' +import { + Team, + TeamGraph, + decryptTeamGraph, + type TeamAction, + type TeamContext, +} from '../team/index.js' import * as select from '../team/selectors/index.js' import { arraysAreEqual } from '../util/arraysAreEqual.js' import { KeyType } from '../util/index.js' @@ -308,7 +314,7 @@ export class Connection extends EventEmitter { const deviceKeys = device.keys // handle errors here - const decrypt = ({ encryptedGraph, keys }: DecryptFnParams) => + const decrypt: DecryptFn = ({ encryptedGraph, keys }) => decryptTeamGraph({ encryptedGraph, teamKeys: keys, deviceKeys }) const [newChain, syncState] = receiveMessage( diff --git a/packages/crdx/src/graph/decrypt.ts b/packages/crdx/src/graph/decrypt.ts index 04664039..73bbf6e6 100644 --- a/packages/crdx/src/graph/decrypt.ts +++ b/packages/crdx/src/graph/decrypt.ts @@ -43,13 +43,10 @@ export const decryptLink = ( /** * Decrypts a graph using a one or more keys. */ -export const decryptGraph: DecryptFn = ({ +export const decryptGraph = (({ encryptedGraph, keys, -}: { - encryptedGraph: MaybePartlyDecryptedGraph - keys: KeysetWithSecrets | KeysetWithSecrets[] | Keyring -}): Graph => { +}: DecryptFnParams): Graph => { const { encryptedLinks, root, childMap = {} } = encryptedGraph const links = encryptedGraph.links ?? {} @@ -83,14 +80,14 @@ export const decryptGraph: DecryptFn = ({ ...encryptedGraph, links: decryptedLinks, } -} +}) satisfies DecryptFn export type DecryptFnParams = { encryptedGraph: MaybePartlyDecryptedGraph keys: KeysetWithSecrets | KeysetWithSecrets[] | Keyring } -export type DecryptFn = ({ +export type DecryptFn = ({ encryptedGraph, keys, }: DecryptFnParams) => Graph diff --git a/packages/crdx/src/sync/receiveMessage.ts b/packages/crdx/src/sync/receiveMessage.ts index fd5a3541..6a330d5b 100644 --- a/packages/crdx/src/sync/receiveMessage.ts +++ b/packages/crdx/src/sync/receiveMessage.ts @@ -25,7 +25,7 @@ export const receiveMessage = ( keys: KeysetWithSecrets | Keyring, - decrypt: DecryptFn = decryptGraph + decrypt: DecryptFn = decryptGraph ): [Graph, SyncState] => { // if a keyset was provided, wrap it in a keyring const keyring = createKeyring(keys) From de089a52a94781116c836ef5fa692cb38ed69d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 16:57:00 +0100 Subject: [PATCH 08/10] Updates version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 96eda800..59cae0fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@localfirst/auth-monorepo", - "version": "6.0.0", + "version": "6.0.1", "private": true, "description": "Monorepo for @localfirst/auth", "repository": "http://github.com/local-first-web/auth", From 608cb85e1a0d3c398d47fc56862bbd4933ceec09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 17:22:39 +0100 Subject: [PATCH 09/10] Adds correct checks after types has been fixed --- demos/taco-chat/src/hooks/useTeam.tsx | 2 +- .../src/AuthProvider.ts | 19 +++++++++++++++---- .../auth-provider-automerge-repo/src/types.ts | 7 ++++++- .../src/connection/getDeviceUserFromGraph.ts | 7 ++++++- .../auth/src/connection/test/identity.test.ts | 2 +- packages/auth/src/team/test/members.test.ts | 2 +- packages/crdx/src/graph/test/append.test.ts | 2 +- packages/crdx/src/graph/test/create.test.ts | 2 +- packages/crdx/src/graph/test/merge.test.ts | 2 +- .../crdx/src/store/test/createStore.test.ts | 2 +- packages/crdx/src/user/test/user.test.ts | 2 +- .../crdx/src/validator/test/validate.test.ts | 18 +++++++++--------- 12 files changed, 44 insertions(+), 23 deletions(-) diff --git a/demos/taco-chat/src/hooks/useTeam.tsx b/demos/taco-chat/src/hooks/useTeam.tsx index 9a9d4767..cf9d2690 100644 --- a/demos/taco-chat/src/hooks/useTeam.tsx +++ b/demos/taco-chat/src/hooks/useTeam.tsx @@ -5,7 +5,7 @@ import { type AlertInfo, type PeerState } from '../types.js' import { assert } from '@localfirst/shared' import { ConnectionManager } from 'ConnectionManager.js' import { teamContext } from 'components/TeamProvider.js' -import { randomTeamName } from 'util/randomTeamName.js' +import { randomTeamName } from '../util/randomTeamName.js' // TODO: make this an environment var const relayUrls = ['ws://localhost:8080'] diff --git a/packages/auth-provider-automerge-repo/src/AuthProvider.ts b/packages/auth-provider-automerge-repo/src/AuthProvider.ts index 058e2c29..188cfc1a 100644 --- a/packages/auth-provider-automerge-repo/src/AuthProvider.ts +++ b/packages/auth-provider-automerge-repo/src/AuthProvider.ts @@ -8,7 +8,7 @@ import type { import { EventEmitter } from '@herbcaudill/eventemitter42' import * as Auth from '@localfirst/auth' import { hash } from '@localfirst/crypto' -import { debug, memoize, pause } from '@localfirst/shared' +import { assert, debug, memoize, pause } from '@localfirst/shared' import { type AbstractConnection } from './AbstractConnection.js' import { AnonymousConnection } from './AnonymousConnection.js' import { buildServerUrl } from './buildServerUrl.js' @@ -211,7 +211,11 @@ export class AuthProvider extends EventEmitter { * Creates a team and registers it with all of our sync servers. */ public async createTeam(teamName: string) { - const team = await Auth.createTeam(teamName, { + if (!this.#user) { + throw new Error('Cannot create team as user is missing on AuthProvider') + } + + const team = Auth.createTeam(teamName, { device: this.#device, user: this.#user, }) @@ -661,6 +665,10 @@ export class AuthProvider extends EventEmitter { const savedShares = unpack(serializedState) as SerializedState + if (!this.#user) { + throw new Error('Cannot load state as user is missing on AuthProvider') + } + await Promise.all( Object.values(savedShares).map(async share => { if ('encryptedTeam' in share) { @@ -672,9 +680,12 @@ export class AuthProvider extends EventEmitter { this.#device.keys.secretKey ) as Auth.KeysetWithSecrets - const context = { device: this.#device, user: this.#user } + // By this point it is defined + assert(this.#user) + + const context: Auth.LocalContext = { device: this.#device, user: this.#user } - const team = await Auth.loadTeam(encryptedTeam, context, teamKeys) + const team = Auth.loadTeam(encryptedTeam, context, teamKeys) return this.addTeam(team) } else { return this.joinPublicShare(share.shareId) diff --git a/packages/auth-provider-automerge-repo/src/types.ts b/packages/auth-provider-automerge-repo/src/types.ts index c00387eb..b4a81dc2 100644 --- a/packages/auth-provider-automerge-repo/src/types.ts +++ b/packages/auth-provider-automerge-repo/src/types.ts @@ -134,7 +134,12 @@ export type AuthProviderEvents = { * this is how we get the user's keys.) This event gives the application a chance to persist the * team graph and the user's info. */ - joined: (payload: { shareId: ShareId; peerId: PeerId; team: Auth.Team; user: Auth.User }) => void + joined: (payload: { + shareId: ShareId + peerId: PeerId + team: Auth.Team + user: Auth.UserWithSecrets + }) => void /** * We're connected to a peer and have been mutually authenticated. diff --git a/packages/auth/src/connection/getDeviceUserFromGraph.ts b/packages/auth/src/connection/getDeviceUserFromGraph.ts index 7dd21123..7dbf1267 100644 --- a/packages/auth/src/connection/getDeviceUserFromGraph.ts +++ b/packages/auth/src/connection/getDeviceUserFromGraph.ts @@ -42,7 +42,12 @@ export const getDeviceUserFromGraph = ({ const userKeyring = select.keyring(state, { type: USER, name: userId }, starterKeys) const keys = getLatestGeneration(userKeyring) - const user = { userName, userId, keys } + + if (!keys) { + throw new Error('Failed to get device user from graph as there are no keys for user keyring') + } + + const user: UserWithSecrets = { userName, userId, keys } return { user, userKeyring } } diff --git a/packages/auth/src/connection/test/identity.test.ts b/packages/auth/src/connection/test/identity.test.ts index f006c7ab..13d5240e 100644 --- a/packages/auth/src/connection/test/identity.test.ts +++ b/packages/auth/src/connection/test/identity.test.ts @@ -1,7 +1,7 @@ import { challenge, prove, verify } from '../identity.js' import { ADMIN_SCOPE, TEAM_SCOPE } from '../../team/index.js' import { setup } from '../../util/testing/index.js' -import 'util/testing/expect/toBeValid.js' +import '../../util/testing/expect/toBeValid.js' import { type KeyScope, KeyType, createKeyset, redactKeys } from '@localfirst/crdx' import { describe, expect, it } from 'vitest' diff --git a/packages/auth/src/team/test/members.test.ts b/packages/auth/src/team/test/members.test.ts index 2d96a540..0d0da791 100644 --- a/packages/auth/src/team/test/members.test.ts +++ b/packages/auth/src/team/test/members.test.ts @@ -1,6 +1,6 @@ import { ADMIN } from '../../role/index.js' import { setup } from '../../util/testing/index.js' -import 'util/testing/expect/toLookLikeKeyset.js' +import '../../util/testing/expect/toLookLikeKeyset.js' import { describe, expect, it } from 'vitest' describe('Team', () => { diff --git a/packages/crdx/src/graph/test/append.test.ts b/packages/crdx/src/graph/test/append.test.ts index f4fb4f3a..930ef09e 100644 --- a/packages/crdx/src/graph/test/append.test.ts +++ b/packages/crdx/src/graph/test/append.test.ts @@ -2,7 +2,7 @@ import { TEST_GRAPH_KEYS as keys, setup } from '../../util/testing/setup.js' import { describe, expect, test } from 'vitest' import { append, createGraph, getHead, getRoot } from '../index.js' import { validate } from '../../validator/index.js' -import 'util/testing/expect/toBeValid' +import '../../util/testing/expect/toBeValid' const { alice } = setup('alice') const defaultUser = alice diff --git a/packages/crdx/src/graph/test/create.test.ts b/packages/crdx/src/graph/test/create.test.ts index 095eccf8..ecf9fd8e 100644 --- a/packages/crdx/src/graph/test/create.test.ts +++ b/packages/crdx/src/graph/test/create.test.ts @@ -2,7 +2,7 @@ import { TEST_GRAPH_KEYS as keys, setup } from '../../util/testing/setup.js' import { describe, expect, test } from 'vitest' import { createGraph, deserialize, getHead, getRoot, serialize } from '../index.js' import { validate } from '../../validator/index.js' -import 'util/testing/expect/toBeValid.js' +import '../../util/testing/expect/toBeValid.js' const { alice } = setup('alice') const defaultUser = alice diff --git a/packages/crdx/src/graph/test/merge.test.ts b/packages/crdx/src/graph/test/merge.test.ts index 1ea47f3f..c9bfa137 100644 --- a/packages/crdx/src/graph/test/merge.test.ts +++ b/packages/crdx/src/graph/test/merge.test.ts @@ -1,6 +1,6 @@ import { TEST_GRAPH_KEYS as keys, setup } from '../../util/testing/setup.js' import { clone } from 'lodash-es' -import 'util/testing/expect/toBeValid' +import '../../util/testing/expect/toBeValid' import { describe, expect, test } from 'vitest' import { append, createGraph, merge } from '../index.js' diff --git a/packages/crdx/src/store/test/createStore.test.ts b/packages/crdx/src/store/test/createStore.test.ts index b02efd13..151697e3 100644 --- a/packages/crdx/src/store/test/createStore.test.ts +++ b/packages/crdx/src/store/test/createStore.test.ts @@ -2,7 +2,7 @@ import { asymmetric } from '@localfirst/crypto' import { createGraph, getRoot, serialize } from '../../graph/index.js' import { createStore } from '../index.js' import { createUser } from '../../user/index.js' -import 'util/testing/expect/toBeValid' +import '../../util/testing/expect/toBeValid' import { TEST_GRAPH_KEYS as keys } from '../../util/testing/setup.js' import { describe, expect, test } from 'vitest' import { diff --git a/packages/crdx/src/user/test/user.test.ts b/packages/crdx/src/user/test/user.test.ts index 70ccb152..7133bfce 100644 --- a/packages/crdx/src/user/test/user.test.ts +++ b/packages/crdx/src/user/test/user.test.ts @@ -1,6 +1,6 @@ import { asymmetric, signatures, symmetric } from '@localfirst/crypto' import { describe, expect, it } from 'vitest' -import 'util/testing/expect/toLookLikeKeyset' +import '../../util/testing/expect/toLookLikeKeyset' import { createUser, redactUser } from '../index.js' describe('user', () => { diff --git a/packages/crdx/src/validator/test/validate.test.ts b/packages/crdx/src/validator/test/validate.test.ts index c65589aa..45dc752e 100644 --- a/packages/crdx/src/validator/test/validate.test.ts +++ b/packages/crdx/src/validator/test/validate.test.ts @@ -1,13 +1,13 @@ ο»Ώ/* eslint-disable @typescript-eslint/ban-ts-comment */ import { asymmetric } from '@localfirst/crypto' -import { buildGraph } from 'util/testing/graph.js' -import { TEST_GRAPH_KEYS as keys, setup } from 'util/testing/setup.js' +import { buildGraph } from '../../util/testing/graph.js' +import { TEST_GRAPH_KEYS as keys, setup } from '../../util/testing/setup.js' import { describe, expect, test, vitest } from 'vitest' -import { hashEncryptedLink } from 'graph/hashLink.js' -import { append, createGraph, getHead, getLink, getRoot } from 'graph/index.js' -import { type Hash } from 'util/index.js' -import { validate } from 'validator/validate.js' -import 'util/testing/expect/toBeValid' +import { hashEncryptedLink } from '../../graph/hashLink.js' +import { append, createGraph, getHead, getLink, getRoot } from '../../graph/index.js' +import { type Hash } from '../../util/index.js' +import { validate } from '../validate.js' +import '../../util/testing/expect/toBeValid' const { setSystemTime } = vitest.useFakeTimers() @@ -35,8 +35,8 @@ describe('graphs', () => { β”Œβ”€ e ─ g ─┐ β”Œβ”€ c ─ d ── β”œβ”€ o ─┐ a ─ b ── └─── f ──── β”œβ”€ n - β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ - └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ + β”œβ”€β”€β”€β”€ h ──── i β”€β”€β”€β”€β”€β”˜ β”‚ + └───── j ─── k ── l β”€β”€β”€β”€β”€β”€β”˜ `) expect(validate(graph)).toBeValid() return graph From c2a7c1b41e7db6632bfc0d132d5a38777cb531f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Langr?= Date: Sat, 28 Dec 2024 20:28:12 +0100 Subject: [PATCH 10/10] use assert instead of new error --- packages/auth-provider-automerge-repo/src/AuthProvider.ts | 8 ++------ packages/auth/src/connection/getDeviceUserFromGraph.ts | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/auth-provider-automerge-repo/src/AuthProvider.ts b/packages/auth-provider-automerge-repo/src/AuthProvider.ts index 188cfc1a..81491a4d 100644 --- a/packages/auth-provider-automerge-repo/src/AuthProvider.ts +++ b/packages/auth-provider-automerge-repo/src/AuthProvider.ts @@ -211,9 +211,7 @@ export class AuthProvider extends EventEmitter { * Creates a team and registers it with all of our sync servers. */ public async createTeam(teamName: string) { - if (!this.#user) { - throw new Error('Cannot create team as user is missing on AuthProvider') - } + assert(this.#user, 'Cannot create team as user is missing on AuthProvider') const team = Auth.createTeam(teamName, { device: this.#device, @@ -665,9 +663,7 @@ export class AuthProvider extends EventEmitter { const savedShares = unpack(serializedState) as SerializedState - if (!this.#user) { - throw new Error('Cannot load state as user is missing on AuthProvider') - } + assert(this.#user, 'Cannot load state as user is missing on AuthProvider') await Promise.all( Object.values(savedShares).map(async share => { diff --git a/packages/auth/src/connection/getDeviceUserFromGraph.ts b/packages/auth/src/connection/getDeviceUserFromGraph.ts index 7dbf1267..4b6dfcf0 100644 --- a/packages/auth/src/connection/getDeviceUserFromGraph.ts +++ b/packages/auth/src/connection/getDeviceUserFromGraph.ts @@ -43,9 +43,7 @@ export const getDeviceUserFromGraph = ({ const userKeyring = select.keyring(state, { type: USER, name: userId }, starterKeys) const keys = getLatestGeneration(userKeyring) - if (!keys) { - throw new Error('Failed to get device user from graph as there are no keys for user keyring') - } + assert(keys, 'Failed to get device user from graph as there are no keys for user keyring') const user: UserWithSecrets = { userName, userId, keys }