Skip to content

Commit

Permalink
types: Export lock types
Browse files Browse the repository at this point in the history
Signed-off-by: Lewis Marshall <lewis.marshall@ably.com>
  • Loading branch information
lmars committed Aug 11, 2023
1 parent ba509cc commit 86712a5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/locks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions src/Locks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 1 addition & 16 deletions src/Locks.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand All @@ -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<string, string> {
toJSON() {
return Object.fromEntries(this);
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ export type {
SpaceOptions,
ProfileData,
SpaceMember,
Lock,
LockRequest,
LockStatus,
} from './types.js';

export { LockAttributes } from './Locks.js';
16 changes: 15 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Types } from 'ably';
import { LockRequest } from './Locks.js';

export interface CursorsOptions {
outboundBatchInterval: number;
Expand Down Expand Up @@ -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;
};
3 changes: 1 addition & 2 deletions src/utilities/types.d.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down

0 comments on commit 86712a5

Please sign in to comment.