document-model 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import type { BaseAction } from './actions/types';
2
- import type { Signal } from './signal';
2
+ import type { SignalDispatch } from './signal';
3
3
  import type { Action, AttachmentRef, Document, ExtendedState, Reducer } from './types';
4
4
  /**
5
5
  * This is an abstract class representing a document and provides methods
@@ -16,7 +16,7 @@ export declare abstract class BaseDocument<T, A extends Action> {
16
16
  * @param reducer - The reducer function that updates the state.
17
17
  * @param document - The initial state of the document.
18
18
  */
19
- constructor(reducer: Reducer<T, A>, document: Document<T, A>, dispatch?: (signal: Signal) => void);
19
+ constructor(reducer: Reducer<T, A>, document: Document<T, A>, dispatch?: SignalDispatch);
20
20
  /**
21
21
  * Dispatches an action to update the state of the document.
22
22
  * @param action - The action to dispatch.
@@ -90,9 +90,7 @@ export declare abstract class BaseDocument<T, A extends Action> {
90
90
  readonly hash: string;
91
91
  } | import("immer").Immutable<A & {
92
92
  index: number;
93
- timestamp: string; /**
94
- * Gets the timestamp of the date the document was created.
95
- */
93
+ timestamp: string;
96
94
  hash: string;
97
95
  }>)[];
98
96
  /**
@@ -193,9 +191,7 @@ export declare abstract class BaseDocument<T, A extends Action> {
193
191
  readonly hash: string;
194
192
  } | import("immer").Immutable<A & {
195
193
  index: number;
196
- timestamp: string; /**
197
- * Gets the timestamp of the date the document was created.
198
- */
194
+ timestamp: string;
199
195
  hash: string;
200
196
  }>)[];
201
197
  readonly initialState: {
@@ -1,6 +1,6 @@
1
1
  import { BaseAction } from './actions/types';
2
2
  import { Action, Document, ImmutableStateReducer } from './types';
3
- import { Signal } from './signal';
3
+ import { SignalDispatch } from './signal';
4
4
  /**
5
5
  * Base document reducer that wraps a custom document reducer and handles
6
6
  * document-level actions such as undo, redo, prune, and set name.
@@ -13,4 +13,4 @@ import { Signal } from './signal';
13
13
  * specific to the document's state.
14
14
  * @returns The new state of the document.
15
15
  */
16
- export declare function baseReducer<T, A extends Action>(document: Document<T, A>, action: A | BaseAction, customReducer: ImmutableStateReducer<T, A>, dispatch?: (signal: Signal) => void): Document<T, A>;
16
+ export declare function baseReducer<T, A extends Action>(document: Document<T, A>, action: A | BaseAction, customReducer: ImmutableStateReducer<T, A>, dispatch?: SignalDispatch): Document<T, A>;
@@ -13,3 +13,4 @@ export type DeleteChildDocumentInput = {
13
13
  };
14
14
  export type DeleteChildDocumentSignal = ISignal<'DELETE_CHILD_DOCUMENT', DeleteChildDocumentInput>;
15
15
  export type Signal = CreateChildDocumentSignal | DeleteChildDocumentSignal;
16
+ export type SignalDispatch = (signal: Signal) => void;
@@ -4,7 +4,7 @@ import type { DocumentModelState } from '../document-model/';
4
4
  import type { BaseAction } from './actions/types';
5
5
  import { BaseDocument } from './object';
6
6
  import { FileInput } from './utils';
7
- import { Signal } from './signal';
7
+ import { SignalDispatch } from './signal';
8
8
  export { z } from './schema';
9
9
  export type * from './schema/types';
10
10
  export type { FileInput } from './utils';
@@ -34,7 +34,7 @@ export type ActionWithAttachment<T extends string = string, I = unknown> = Actio
34
34
  * @typeParam State - The type of the document data.
35
35
  * @typeParam A - The type of the actions supported by the reducer.
36
36
  */
37
- export type Reducer<State, A extends Action> = (state: Document<State, A>, action: A | BaseAction, dispatch?: (signal: Signal) => void) => Document<State, A>;
37
+ export type Reducer<State, A extends Action> = (state: Document<State, A>, action: A | BaseAction, dispatch?: SignalDispatch) => Document<State, A>;
38
38
  /**
39
39
  * A {@link Reducer} that prevents mutable code from changing the previous state.
40
40
  *
@@ -47,8 +47,8 @@ export type Reducer<State, A extends Action> = (state: Document<State, A>, actio
47
47
  * @typeParam State - The type of the document data.
48
48
  * @typeParam A - The type of the actions supported by the reducer.
49
49
  */
50
- export type ImmutableReducer<State, A extends Action> = (state: Draft<Document<State, A>>, action: A | BaseAction, dispatch?: (signal: Signal) => void) => Document<State, A> | void;
51
- export type ImmutableStateReducer<State, A extends Action> = (state: Draft<State>, action: A, dispatch?: (signal: Signal) => void) => State | void;
50
+ export type ImmutableReducer<State, A extends Action> = (state: Draft<Document<State, A>>, action: A | BaseAction, dispatch?: SignalDispatch) => Document<State, A> | void;
51
+ export type ImmutableStateReducer<State, A extends Action> = (state: Draft<State>, action: A, dispatch?: SignalDispatch) => State | void;
52
52
  /**
53
53
  * Scope of an operation.
54
54
  * Global: The operation is synchronized everywhere in the network. This is the default document operation.
@@ -1,5 +1,5 @@
1
1
  import { DocumentModelState } from './types';
2
- import { ExtendedState, Signal } from '../../document';
2
+ import { ExtendedState, SignalDispatch } from '../../document';
3
3
  import { BaseDocument } from '../../document/object';
4
4
  import { DocumentModelAction } from './actions';
5
5
  import DocumentModel_Header from './header/object';
@@ -20,7 +20,7 @@ interface DocumentModel extends DocumentModel_Header, DocumentModel_Versioning,
20
20
  }
21
21
  declare class DocumentModel extends BaseDocument<DocumentModelState, DocumentModelAction> {
22
22
  static fileExtension: string;
23
- constructor(initialState?: Partial<ExtendedState<Partial<DocumentModelState>>>, dispatch?: (signal: Signal) => void);
23
+ constructor(initialState?: Partial<ExtendedState<Partial<DocumentModelState>>>, dispatch?: SignalDispatch);
24
24
  saveToFile(path: string, name?: string): Promise<string>;
25
25
  loadFromFile(path: string): Promise<void>;
26
26
  static fromFile(path: string): Promise<DocumentModel>;
@@ -1,5 +1,5 @@
1
1
  import type { BaseAction } from './actions/types';
2
- import type { Signal } from './signal';
2
+ import type { SignalDispatch } from './signal';
3
3
  import type { Action, AttachmentRef, Document, ExtendedState, Reducer } from './types';
4
4
  /**
5
5
  * This is an abstract class representing a document and provides methods
@@ -16,7 +16,7 @@ export declare abstract class BaseDocument<T, A extends Action> {
16
16
  * @param reducer - The reducer function that updates the state.
17
17
  * @param document - The initial state of the document.
18
18
  */
19
- constructor(reducer: Reducer<T, A>, document: Document<T, A>, dispatch?: (signal: Signal) => void);
19
+ constructor(reducer: Reducer<T, A>, document: Document<T, A>, dispatch?: SignalDispatch);
20
20
  /**
21
21
  * Dispatches an action to update the state of the document.
22
22
  * @param action - The action to dispatch.
@@ -90,9 +90,7 @@ export declare abstract class BaseDocument<T, A extends Action> {
90
90
  readonly hash: string;
91
91
  } | import("immer").Immutable<A & {
92
92
  index: number;
93
- timestamp: string; /**
94
- * Gets the timestamp of the date the document was created.
95
- */
93
+ timestamp: string;
96
94
  hash: string;
97
95
  }>)[];
98
96
  /**
@@ -193,9 +191,7 @@ export declare abstract class BaseDocument<T, A extends Action> {
193
191
  readonly hash: string;
194
192
  } | import("immer").Immutable<A & {
195
193
  index: number;
196
- timestamp: string; /**
197
- * Gets the timestamp of the date the document was created.
198
- */
194
+ timestamp: string;
199
195
  hash: string;
200
196
  }>)[];
201
197
  readonly initialState: {
@@ -1,6 +1,6 @@
1
1
  import { BaseAction } from './actions/types';
2
2
  import { Action, Document, ImmutableStateReducer } from './types';
3
- import { Signal } from './signal';
3
+ import { SignalDispatch } from './signal';
4
4
  /**
5
5
  * Base document reducer that wraps a custom document reducer and handles
6
6
  * document-level actions such as undo, redo, prune, and set name.
@@ -13,4 +13,4 @@ import { Signal } from './signal';
13
13
  * specific to the document's state.
14
14
  * @returns The new state of the document.
15
15
  */
16
- export declare function baseReducer<T, A extends Action>(document: Document<T, A>, action: A | BaseAction, customReducer: ImmutableStateReducer<T, A>, dispatch?: (signal: Signal) => void): Document<T, A>;
16
+ export declare function baseReducer<T, A extends Action>(document: Document<T, A>, action: A | BaseAction, customReducer: ImmutableStateReducer<T, A>, dispatch?: SignalDispatch): Document<T, A>;
@@ -13,3 +13,4 @@ export type DeleteChildDocumentInput = {
13
13
  };
14
14
  export type DeleteChildDocumentSignal = ISignal<'DELETE_CHILD_DOCUMENT', DeleteChildDocumentInput>;
15
15
  export type Signal = CreateChildDocumentSignal | DeleteChildDocumentSignal;
16
+ export type SignalDispatch = (signal: Signal) => void;
@@ -4,7 +4,7 @@ import type { DocumentModelState } from '../document-model/';
4
4
  import type { BaseAction } from './actions/types';
5
5
  import { BaseDocument } from './object';
6
6
  import { FileInput } from './utils';
7
- import { Signal } from './signal';
7
+ import { SignalDispatch } from './signal';
8
8
  export { z } from './schema';
9
9
  export type * from './schema/types';
10
10
  export type { FileInput } from './utils';
@@ -34,7 +34,7 @@ export type ActionWithAttachment<T extends string = string, I = unknown> = Actio
34
34
  * @typeParam State - The type of the document data.
35
35
  * @typeParam A - The type of the actions supported by the reducer.
36
36
  */
37
- export type Reducer<State, A extends Action> = (state: Document<State, A>, action: A | BaseAction, dispatch?: (signal: Signal) => void) => Document<State, A>;
37
+ export type Reducer<State, A extends Action> = (state: Document<State, A>, action: A | BaseAction, dispatch?: SignalDispatch) => Document<State, A>;
38
38
  /**
39
39
  * A {@link Reducer} that prevents mutable code from changing the previous state.
40
40
  *
@@ -47,8 +47,8 @@ export type Reducer<State, A extends Action> = (state: Document<State, A>, actio
47
47
  * @typeParam State - The type of the document data.
48
48
  * @typeParam A - The type of the actions supported by the reducer.
49
49
  */
50
- export type ImmutableReducer<State, A extends Action> = (state: Draft<Document<State, A>>, action: A | BaseAction, dispatch?: (signal: Signal) => void) => Document<State, A> | void;
51
- export type ImmutableStateReducer<State, A extends Action> = (state: Draft<State>, action: A, dispatch?: (signal: Signal) => void) => State | void;
50
+ export type ImmutableReducer<State, A extends Action> = (state: Draft<Document<State, A>>, action: A | BaseAction, dispatch?: SignalDispatch) => Document<State, A> | void;
51
+ export type ImmutableStateReducer<State, A extends Action> = (state: Draft<State>, action: A, dispatch?: SignalDispatch) => State | void;
52
52
  /**
53
53
  * Scope of an operation.
54
54
  * Global: The operation is synchronized everywhere in the network. This is the default document operation.
@@ -1,5 +1,5 @@
1
1
  import { DocumentModelState } from './types';
2
- import { ExtendedState, Signal } from '../../document';
2
+ import { ExtendedState, SignalDispatch } from '../../document';
3
3
  import { BaseDocument } from '../../document/object';
4
4
  import { DocumentModelAction } from './actions';
5
5
  import DocumentModel_Header from './header/object';
@@ -20,7 +20,7 @@ interface DocumentModel extends DocumentModel_Header, DocumentModel_Versioning,
20
20
  }
21
21
  declare class DocumentModel extends BaseDocument<DocumentModelState, DocumentModelAction> {
22
22
  static fileExtension: string;
23
- constructor(initialState?: Partial<ExtendedState<Partial<DocumentModelState>>>, dispatch?: (signal: Signal) => void);
23
+ constructor(initialState?: Partial<ExtendedState<Partial<DocumentModelState>>>, dispatch?: SignalDispatch);
24
24
  saveToFile(path: string, name?: string): Promise<string>;
25
25
  loadFromFile(path: string): Promise<void>;
26
26
  static fromFile(path: string): Promise<DocumentModel>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-model",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "license": "AGPL-3.0-only",
5
5
  "private": false,
6
6
  "files": [