From 86712a549a1c8704c852a06faed889c844c73f6c Mon Sep 17 00:00:00 2001 From: Lewis Marshall Date: Fri, 11 Aug 2023 10:19:06 +0100 Subject: [PATCH] types: Export lock types Signed-off-by: Lewis Marshall --- examples/locks.ts | 2 +- src/Locks.test.ts | 4 ++-- src/Locks.ts | 17 +---------------- src/index.ts | 5 +++++ src/types.d.ts | 16 +++++++++++++++- src/utilities/types.d.ts | 3 +-- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/examples/locks.ts b/examples/locks.ts index 872725ee..81c685df 100644 --- a/examples/locks.ts +++ b/examples/locks.ts @@ -2,7 +2,7 @@ // application. import Ably from 'ably/promises'; import Spaces from '../dist/cjs/Spaces.js'; -import { Lock, LockAttributes } from '../dist/cjs/Locks.js'; +import { Lock, LockAttributes } from '../dist/cjs/index.js'; // SlideElement represents an element on a slide which a member can both be // located at and attempt to lock (e.g. an editable text box). diff --git a/src/Locks.test.ts b/src/Locks.test.ts index a4ce6256..8702995c 100644 --- a/src/Locks.test.ts +++ b/src/Locks.test.ts @@ -2,8 +2,8 @@ import { it, describe, expect, vi, beforeEach } from 'vitest'; import { Realtime, Types } from 'ably/promises'; import Space from './Space.js'; -import type { SpaceMember } from './types.js'; -import { LockAttributes, LockStatus } from './Locks.js'; +import type { SpaceMember, LockStatus } from './types.js'; +import { LockAttributes } from './Locks.js'; import { createPresenceMessage } from './utilities/test/fakes.js'; interface SpaceTestContext { diff --git a/src/Locks.ts b/src/Locks.ts index c3527c54..04d2bc3f 100644 --- a/src/Locks.ts +++ b/src/Locks.ts @@ -1,7 +1,7 @@ import { Types } from 'ably'; import Space from './Space.js'; -import type { SpaceMember } from './types.js'; +import type { Lock, LockRequest, SpaceMember } from './types.js'; import type { PresenceMember } from './utilities/types.js'; import { ERR_LOCK_IS_LOCKED, ERR_LOCK_INVALIDATED, ERR_LOCK_REQUEST_EXISTS, ERR_LOCK_RELEASED } from './Errors.js'; import EventEmitter, { @@ -11,21 +11,6 @@ import EventEmitter, { type EventListener, } from './utilities/EventEmitter.js'; -export type LockStatus = 'pending' | 'locked' | 'unlocked'; - -export type Lock = { - member: SpaceMember; - request: LockRequest; -}; - -export type LockRequest = { - id: string; - status: LockStatus; - timestamp: number; - attributes?: LockAttributes; - reason?: Types.ErrorInfo; -}; - export class LockAttributes extends Map { toJSON() { return Object.fromEntries(this); diff --git a/src/index.ts b/src/index.ts index bdeaa15a..4b47cb95 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,4 +14,9 @@ export type { SpaceOptions, ProfileData, SpaceMember, + Lock, + LockRequest, + LockStatus, } from './types.js'; + +export { LockAttributes } from './Locks.js'; diff --git a/src/types.d.ts b/src/types.d.ts index 33a9760c..97331e98 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,5 +1,4 @@ import { Types } from 'ably'; -import { LockRequest } from './Locks.js'; export interface CursorsOptions { outboundBatchInterval: number; @@ -39,3 +38,18 @@ export interface SpaceMember { timestamp: number; }; } + +export type LockStatus = 'pending' | 'locked' | 'unlocked'; + +export type Lock = { + member: SpaceMember; + request: LockRequest; +}; + +export type LockRequest = { + id: string; + status: LockStatus; + timestamp: number; + attributes?: LockAttributes; + reason?: Types.ErrorInfo; +}; diff --git a/src/utilities/types.d.ts b/src/utilities/types.d.ts index f5f9c5f3..455faed2 100644 --- a/src/utilities/types.d.ts +++ b/src/utilities/types.d.ts @@ -1,8 +1,7 @@ import { Types } from 'ably'; import { EventKey, EventListener, EventMap } from './EventEmitter.js'; -import { ProfileData } from '../types.js'; -import { LockRequest } from '../Locks.js'; +import { ProfileData, LockRequest } from '../types.js'; export type PresenceMember = { data: {