document-model 1.0.22 → 1.0.24

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.
Files changed (153) hide show
  1. package/dist/browser/document-model.cjs +1 -1
  2. package/dist/browser/document-model.js +2 -2
  3. package/dist/browser/document.cjs +1 -1
  4. package/dist/browser/document.js +4 -4
  5. package/dist/browser/index.cjs +1 -1
  6. package/dist/browser/index.js +3 -3
  7. package/dist/browser/internal/index-Xpydy6AU.js +22 -0
  8. package/dist/browser/internal/index-e4O5HJBs.js +1 -0
  9. package/dist/browser/internal/{index-k0_xGFJa.js → index-sfNIE5tQ.js} +400 -398
  10. package/dist/browser/internal/index-v3lMuqpK.js +36 -0
  11. package/dist/browser/internal/object-U8CbkcSV.js +6 -0
  12. package/dist/browser/internal/{object-wtPuW7QY.js → object-YlWt1S0J.js} +407 -357
  13. package/dist/browser/src/document/actions/creators.d.ts +3 -2
  14. package/dist/browser/src/document/actions/types.d.ts +1 -1
  15. package/dist/browser/src/document/object.d.ts +58 -2
  16. package/dist/browser/src/document/reducer.d.ts +2 -2
  17. package/dist/browser/src/document/schema/types.d.ts +9 -3
  18. package/dist/browser/src/document/signal.d.ts +7 -1
  19. package/dist/browser/src/document/types.d.ts +12 -1
  20. package/dist/browser/src/document/utils/base.d.ts +15 -2
  21. package/dist/browser/src/document-model/gen/header/object.d.ts +7 -6
  22. package/dist/browser/src/document-model/gen/module/object.d.ts +6 -5
  23. package/dist/browser/src/document-model/gen/operation/object.d.ts +11 -10
  24. package/dist/browser/src/document-model/gen/operation-error/object.d.ts +8 -7
  25. package/dist/browser/src/document-model/gen/operation-example/object.d.ts +5 -4
  26. package/dist/browser/src/document-model/gen/reducer.d.ts +2 -0
  27. package/dist/browser/src/document-model/gen/state/object.d.ts +7 -6
  28. package/dist/browser/src/document-model/gen/versioning/object.d.ts +6 -5
  29. package/dist/browser/src/document-model/index.d.ts +2 -1
  30. package/dist/browser/test/document/skip-operations.test.d.ts +1 -0
  31. package/dist/browser/test/document-model/skip-operations.test.d.ts +1 -0
  32. package/dist/browser/test/helpers.d.ts +5 -2
  33. package/dist/jest.config.d.ts +8 -0
  34. package/dist/node/document-model.cjs +1 -1
  35. package/dist/node/document-model.js +2 -2
  36. package/dist/node/document.cjs +1 -1
  37. package/dist/node/document.js +4 -4
  38. package/dist/node/index.cjs +1 -1
  39. package/dist/node/index.js +3 -3
  40. package/dist/node/internal/index-HgkfWSZk.js +36 -0
  41. package/dist/node/internal/index-PkGY1BML.js +22 -0
  42. package/dist/node/internal/index-aihhQ-ya.js +1 -0
  43. package/dist/node/internal/{index-vqhz-N10.js → index-sNi-u40H.js} +400 -398
  44. package/dist/node/internal/object-Nz1iEXFy.js +1 -0
  45. package/dist/node/internal/{object-yzJ3jRpE.js → object-T2hpMYZ4.js} +317 -267
  46. package/dist/node/src/document/actions/creators.d.ts +3 -2
  47. package/dist/node/src/document/actions/types.d.ts +1 -1
  48. package/dist/node/src/document/object.d.ts +58 -2
  49. package/dist/node/src/document/reducer.d.ts +2 -2
  50. package/dist/node/src/document/schema/types.d.ts +9 -3
  51. package/dist/node/src/document/signal.d.ts +7 -1
  52. package/dist/node/src/document/types.d.ts +12 -1
  53. package/dist/node/src/document/utils/base.d.ts +15 -2
  54. package/dist/node/src/document-model/gen/header/object.d.ts +7 -6
  55. package/dist/node/src/document-model/gen/module/object.d.ts +6 -5
  56. package/dist/node/src/document-model/gen/operation/object.d.ts +11 -10
  57. package/dist/node/src/document-model/gen/operation-error/object.d.ts +8 -7
  58. package/dist/node/src/document-model/gen/operation-example/object.d.ts +5 -4
  59. package/dist/node/src/document-model/gen/reducer.d.ts +2 -0
  60. package/dist/node/src/document-model/gen/state/object.d.ts +7 -6
  61. package/dist/node/src/document-model/gen/versioning/object.d.ts +6 -5
  62. package/dist/node/src/document-model/index.d.ts +2 -1
  63. package/dist/node/test/document/skip-operations.test.d.ts +1 -0
  64. package/dist/node/test/document-model/skip-operations.test.d.ts +1 -0
  65. package/dist/node/test/helpers.d.ts +5 -2
  66. package/dist/src/document/actions/creators.d.ts +47 -0
  67. package/dist/src/document/actions/index.d.ts +10 -0
  68. package/dist/src/document/actions/types.d.ts +8 -0
  69. package/dist/src/document/index.d.ts +6 -0
  70. package/dist/src/document/object.d.ts +447 -0
  71. package/dist/src/document/reducer.d.ts +16 -0
  72. package/dist/src/document/schema/index.d.ts +2 -0
  73. package/dist/src/document/schema/types.d.ts +180 -0
  74. package/dist/src/document/schema/zod.d.ts +113 -0
  75. package/dist/src/document/signal.d.ts +28 -0
  76. package/dist/src/document/types.d.ts +201 -0
  77. package/dist/src/document/utils/base.d.ts +74 -0
  78. package/dist/src/document/utils/browser.d.ts +10 -0
  79. package/dist/src/document/utils/file.d.ts +47 -0
  80. package/dist/src/document/utils/index.d.ts +2 -0
  81. package/dist/src/document/utils/node.d.ts +9 -0
  82. package/dist/src/document-model/custom/reducers/header.d.ts +2 -0
  83. package/dist/src/document-model/custom/reducers/module.d.ts +2 -0
  84. package/dist/src/document-model/custom/reducers/operation-error.d.ts +2 -0
  85. package/dist/src/document-model/custom/reducers/operation-example.d.ts +2 -0
  86. package/dist/src/document-model/custom/reducers/operation.d.ts +2 -0
  87. package/dist/src/document-model/custom/reducers/state.d.ts +2 -0
  88. package/dist/src/document-model/custom/reducers/versioning.d.ts +7 -0
  89. package/dist/src/document-model/custom/utils.d.ts +1 -0
  90. package/dist/src/document-model/gen/actions.d.ts +15 -0
  91. package/dist/src/document-model/gen/creators.d.ts +7 -0
  92. package/dist/src/document-model/gen/document-model.d.ts +2 -0
  93. package/dist/src/document-model/gen/header/actions.d.ts +9 -0
  94. package/dist/src/document-model/gen/header/creators.d.ts +8 -0
  95. package/dist/src/document-model/gen/header/object.d.ts +12 -0
  96. package/dist/src/document-model/gen/header/operations.d.ts +10 -0
  97. package/dist/src/document-model/gen/index.d.ts +5 -0
  98. package/dist/src/document-model/gen/module/actions.d.ts +8 -0
  99. package/dist/src/document-model/gen/module/creators.d.ts +7 -0
  100. package/dist/src/document-model/gen/module/object.d.ts +11 -0
  101. package/dist/src/document-model/gen/module/operations.d.ts +9 -0
  102. package/dist/src/document-model/gen/object.d.ts +28 -0
  103. package/dist/src/document-model/gen/operation/actions.d.ts +13 -0
  104. package/dist/src/document-model/gen/operation/creators.d.ts +12 -0
  105. package/dist/src/document-model/gen/operation/object.d.ts +16 -0
  106. package/dist/src/document-model/gen/operation/operations.d.ts +14 -0
  107. package/dist/src/document-model/gen/operation-error/actions.d.ts +10 -0
  108. package/dist/src/document-model/gen/operation-error/creators.d.ts +9 -0
  109. package/dist/src/document-model/gen/operation-error/object.d.ts +13 -0
  110. package/dist/src/document-model/gen/operation-error/operations.d.ts +11 -0
  111. package/dist/src/document-model/gen/operation-example/actions.d.ts +7 -0
  112. package/dist/src/document-model/gen/operation-example/creators.d.ts +6 -0
  113. package/dist/src/document-model/gen/operation-example/object.d.ts +10 -0
  114. package/dist/src/document-model/gen/operation-example/operations.d.ts +8 -0
  115. package/dist/src/document-model/gen/reducer.d.ts +5 -0
  116. package/dist/src/document-model/gen/schema/index.d.ts +2 -0
  117. package/dist/src/document-model/gen/schema/types.d.ts +453 -0
  118. package/dist/src/document-model/gen/schema/zod.d.ts +453 -0
  119. package/dist/src/document-model/gen/state/actions.d.ts +9 -0
  120. package/dist/src/document-model/gen/state/creators.d.ts +8 -0
  121. package/dist/src/document-model/gen/state/object.d.ts +12 -0
  122. package/dist/src/document-model/gen/state/operations.d.ts +10 -0
  123. package/dist/src/document-model/gen/types.d.ts +8 -0
  124. package/dist/src/document-model/gen/utils.d.ts +6 -0
  125. package/dist/src/document-model/gen/versioning/actions.d.ts +8 -0
  126. package/dist/src/document-model/gen/versioning/creators.d.ts +7 -0
  127. package/dist/src/document-model/gen/versioning/object.d.ts +11 -0
  128. package/dist/src/document-model/gen/versioning/operations.d.ts +9 -0
  129. package/dist/src/document-model/index.d.ts +75 -0
  130. package/dist/src/index.d.ts +25 -0
  131. package/dist/test/document/local.test.d.ts +1 -0
  132. package/dist/test/document/object.test.d.ts +1 -0
  133. package/dist/test/document/prune.test.d.ts +1 -0
  134. package/dist/test/document/redo.test.d.ts +1 -0
  135. package/dist/test/document/reducer.test.d.ts +1 -0
  136. package/dist/test/document/skip-operations.test.d.ts +1 -0
  137. package/dist/test/document/undo.test.d.ts +1 -0
  138. package/dist/test/document/utils.test.d.ts +1 -0
  139. package/dist/test/document-model/object.test.d.ts +1 -0
  140. package/dist/test/document-model/skip-operations.test.d.ts +1 -0
  141. package/dist/test/document-model/zip.test.d.ts +1 -0
  142. package/dist/test/helpers.d.ts +32 -0
  143. package/dist/vite.config.d.ts +2 -0
  144. package/dist/vitest.config.d.ts +2 -0
  145. package/package.json +1 -1
  146. package/dist/browser/internal/index-BGvdUwMj.js +0 -1
  147. package/dist/browser/internal/index-ZaSXpgfR.js +0 -22
  148. package/dist/browser/internal/index-vHDbgY8i.js +0 -34
  149. package/dist/browser/internal/object-fIfH8K9b.js +0 -6
  150. package/dist/node/internal/index-3_D7m254.js +0 -34
  151. package/dist/node/internal/index-ffEJwj4v.js +0 -22
  152. package/dist/node/internal/index-frYzO4l6.js +0 -1
  153. package/dist/node/internal/object-Vf10stKL.js +0 -1
@@ -0,0 +1,10 @@
1
+ import { Action, Document, ImmutableStateReducer, PruneAction, RedoAction, State, UndoAction } from '../types';
2
+ export declare function setNameOperation<T>(document: T, name: string): T;
3
+ export declare function undoOperation<T, A extends Action, L>(document: Document<T, A, L>, action: UndoAction, wrappedReducer: ImmutableStateReducer<T, A, L>): Document<T, A, L>;
4
+ export declare function redoOperation<T, A extends Action, L>(document: Document<T, A, L>, action: RedoAction, wrappedReducer: ImmutableStateReducer<T, A, L>): Document<T, A, L>;
5
+ export declare function pruneOperation<T, A extends Action, L>(document: Document<T, A, L>, action: PruneAction, wrappedReducer: ImmutableStateReducer<T, A, L>): Document<T, A, L>;
6
+ export declare function loadStateOperation<T, A extends Action, L>(oldDocument: Document<T, A, L>, newDocument: {
7
+ name: string;
8
+ state?: State<T, L>;
9
+ }): Document<T, A, L>;
10
+ export * from './creators';
@@ -0,0 +1,8 @@
1
+ import { BaseAction } from '../types';
2
+ export declare const SET_NAME = "SET_NAME";
3
+ export declare const UNDO = "UNDO";
4
+ export declare const REDO = "REDO";
5
+ export declare const PRUNE = "PRUNE";
6
+ export declare const LOAD_STATE = "LOAD_STATE";
7
+ export { LoadStateAction, PruneAction, RedoAction, SetNameAction, UndoAction, NOOPAction, } from '../types';
8
+ export type { BaseAction };
@@ -0,0 +1,6 @@
1
+ export * as actions from './actions/creators';
2
+ export * from './object';
3
+ export * from './reducer';
4
+ export * from './signal';
5
+ export * from './types';
6
+ export * as utils from './utils';
@@ -0,0 +1,447 @@
1
+ import type { BaseAction } from './actions/types';
2
+ import type { SignalDispatch } from './signal';
3
+ import type { Action, AttachmentRef, Document, ExtendedState, OperationScope, Reducer, ReducerOptions } from './types';
4
+ /**
5
+ * This is an abstract class representing a document and provides methods
6
+ * for creating and manipulating documents.
7
+ * @typeparam T - The type of data stored in the document.
8
+ * @typeparam A - The type of action the document can take.
9
+ */
10
+ export declare abstract class BaseDocument<T, A extends Action, L = unknown> {
11
+ protected _document: Document<T, A, L>;
12
+ private _reducer;
13
+ private _signalDispatch?;
14
+ /**
15
+ * Constructs a BaseDocument instance with an initial state.
16
+ * @param reducer - The reducer function that updates the state.
17
+ * @param document - The initial state of the document.
18
+ */
19
+ constructor(reducer: Reducer<T, A, L>, document: Document<T, A, L>, signalDispatch?: SignalDispatch);
20
+ /**
21
+ * Dispatches an action to update the state of the document.
22
+ * @param action - The action to dispatch.
23
+ * @returns The Document instance.
24
+ */
25
+ protected dispatch(action: A | BaseAction, options?: ReducerOptions): this;
26
+ /**
27
+ * Saves the state of the document to a file.
28
+ * @param path - The file path where the state should be saved.
29
+ * @param extension - The file extension to use when saving the state.
30
+ * @returns The file path where the state was saved.
31
+ */
32
+ protected saveToFile(path: string, extension: string, name?: string): Promise<string>;
33
+ /**
34
+ * Loads the state of the document from a file.
35
+ * @param path - The file path where the state is stored.
36
+ */
37
+ loadFromFile(path: string): Promise<void>;
38
+ /**
39
+ * Loads the state of the document from a file and returns it.
40
+ * @param path - The file path where the state is stored.
41
+ * @param reducer - The reducer function that updates the state.
42
+ * @returns The state of the document.
43
+ */
44
+ protected static stateFromFile<T, A extends Action, L>(path: string, reducer: Reducer<T, A, L>): Promise<Document<T, A, L>>;
45
+ /**
46
+ * Gets the current state of the document.
47
+ */
48
+ get state(): {
49
+ readonly global: import("immer").Immutable<T>;
50
+ readonly local: import("immer").Immutable<L>;
51
+ };
52
+ /**
53
+ * Gets the list of operations performed on the document.
54
+ */
55
+ get operations(): {
56
+ readonly global: readonly ({
57
+ readonly input: {
58
+ readonly operations: number;
59
+ readonly state: {
60
+ readonly data?: unknown;
61
+ readonly name: string;
62
+ };
63
+ };
64
+ readonly type: "LOAD_STATE";
65
+ readonly scope: OperationScope;
66
+ readonly index: number;
67
+ readonly timestamp: string;
68
+ readonly hash: string;
69
+ readonly skip: number;
70
+ } | {
71
+ readonly input: {
72
+ readonly end?: import("./types").InputMaybe<number>;
73
+ readonly start?: import("./types").InputMaybe<number>;
74
+ };
75
+ readonly type: "PRUNE";
76
+ readonly scope: OperationScope;
77
+ readonly index: number;
78
+ readonly timestamp: string;
79
+ readonly hash: string;
80
+ readonly skip: number;
81
+ } | {
82
+ readonly input: number;
83
+ readonly type: "REDO";
84
+ readonly scope: OperationScope;
85
+ readonly index: number;
86
+ readonly timestamp: string;
87
+ readonly hash: string;
88
+ readonly skip: number;
89
+ } | {
90
+ readonly input: string;
91
+ readonly type: "SET_NAME";
92
+ readonly scope: "global";
93
+ readonly index: number;
94
+ readonly timestamp: string;
95
+ readonly hash: string;
96
+ readonly skip: number;
97
+ } | {
98
+ readonly input: number;
99
+ readonly type: "UNDO";
100
+ readonly scope: OperationScope;
101
+ readonly index: number;
102
+ readonly timestamp: string;
103
+ readonly hash: string;
104
+ readonly skip: number;
105
+ } | {
106
+ readonly input: unknown;
107
+ readonly type: "NOOP";
108
+ readonly scope: OperationScope;
109
+ readonly index: number;
110
+ readonly timestamp: string;
111
+ readonly hash: string;
112
+ readonly skip: number;
113
+ } | import("immer").Immutable<A & {
114
+ index: number;
115
+ timestamp: string;
116
+ hash: string;
117
+ skip: number;
118
+ }>)[];
119
+ readonly local: readonly ({
120
+ readonly input: {
121
+ readonly operations: number;
122
+ readonly state: {
123
+ readonly data?: unknown;
124
+ readonly name: string;
125
+ };
126
+ };
127
+ readonly type: "LOAD_STATE";
128
+ readonly scope: OperationScope;
129
+ readonly index: number;
130
+ readonly timestamp: string;
131
+ readonly hash: string;
132
+ readonly skip: number;
133
+ } | {
134
+ readonly input: {
135
+ readonly end?: import("./types").InputMaybe<number>;
136
+ readonly start?: import("./types").InputMaybe<number>;
137
+ };
138
+ readonly type: "PRUNE";
139
+ readonly scope: OperationScope;
140
+ readonly index: number;
141
+ readonly timestamp: string;
142
+ readonly hash: string;
143
+ readonly skip: number;
144
+ } | {
145
+ readonly input: number;
146
+ readonly type: "REDO";
147
+ readonly scope: OperationScope;
148
+ readonly index: number;
149
+ readonly timestamp: string;
150
+ readonly hash: string;
151
+ readonly skip: number;
152
+ } | {
153
+ readonly input: string;
154
+ readonly type: "SET_NAME";
155
+ readonly scope: "global";
156
+ readonly index: number;
157
+ readonly timestamp: string;
158
+ readonly hash: string;
159
+ readonly skip: number;
160
+ } | {
161
+ readonly input: number;
162
+ readonly type: "UNDO";
163
+ readonly scope: OperationScope;
164
+ readonly index: number;
165
+ readonly timestamp: string;
166
+ readonly hash: string;
167
+ readonly skip: number;
168
+ } | {
169
+ readonly input: unknown;
170
+ readonly type: "NOOP";
171
+ readonly scope: OperationScope;
172
+ readonly index: number;
173
+ readonly timestamp: string;
174
+ readonly hash: string;
175
+ readonly skip: number;
176
+ } | import("immer").Immutable<A & {
177
+ index: number;
178
+ timestamp: string;
179
+ hash: string;
180
+ skip: number;
181
+ }>)[];
182
+ };
183
+ /**
184
+ * Gets the name of the document.
185
+ */
186
+ get name(): string;
187
+ /**
188
+ * Gets the type of document.
189
+ */
190
+ get documentType(): string;
191
+ /**
192
+ * Gets the timestamp of the date the document was created.
193
+ */
194
+ get created(): string;
195
+ /**
196
+ * Gets the timestamp of the date the document was last modified.
197
+ */
198
+ get lastModified(): string;
199
+ /**
200
+ * Gets the global revision number of the document.
201
+ */
202
+ get revision(): number;
203
+ getRevision(scope: OperationScope): number;
204
+ /**
205
+ * Gets the initial state of the document.
206
+ */
207
+ get initialState(): {
208
+ readonly name: string;
209
+ readonly revision: {
210
+ readonly global: number;
211
+ readonly local: number;
212
+ };
213
+ readonly documentType: string;
214
+ readonly created: string;
215
+ readonly lastModified: string;
216
+ readonly state: {
217
+ readonly global: import("immer").Immutable<T>;
218
+ readonly local: import("immer").Immutable<L>;
219
+ };
220
+ readonly attachments: {
221
+ readonly [x: string]: {
222
+ readonly data: string;
223
+ readonly mimeType: string;
224
+ readonly extension?: string | null | undefined;
225
+ readonly fileName?: string | null | undefined;
226
+ };
227
+ };
228
+ };
229
+ /**
230
+ * Returns the current document as an object
231
+ */
232
+ toDocument(): {
233
+ readonly name: string;
234
+ readonly revision: {
235
+ readonly global: number;
236
+ readonly local: number;
237
+ };
238
+ readonly documentType: string;
239
+ readonly created: string;
240
+ readonly lastModified: string;
241
+ readonly state: {
242
+ readonly global: import("immer").Immutable<T>;
243
+ readonly local: import("immer").Immutable<L>;
244
+ };
245
+ readonly attachments: {
246
+ readonly [x: string]: {
247
+ readonly data: string;
248
+ readonly mimeType: string;
249
+ readonly extension?: string | null | undefined;
250
+ readonly fileName?: string | null | undefined;
251
+ };
252
+ };
253
+ readonly operations: {
254
+ readonly global: readonly ({
255
+ readonly input: {
256
+ readonly operations: number;
257
+ readonly state: {
258
+ readonly data?: unknown;
259
+ readonly name: string;
260
+ };
261
+ };
262
+ readonly type: "LOAD_STATE";
263
+ readonly scope: OperationScope;
264
+ readonly index: number;
265
+ readonly timestamp: string;
266
+ readonly hash: string;
267
+ readonly skip: number;
268
+ } | {
269
+ readonly input: {
270
+ readonly end?: import("./types").InputMaybe<number>;
271
+ readonly start?: import("./types").InputMaybe<number>;
272
+ };
273
+ readonly type: "PRUNE";
274
+ readonly scope: OperationScope;
275
+ readonly index: number;
276
+ readonly timestamp: string;
277
+ readonly hash: string;
278
+ readonly skip: number;
279
+ } | {
280
+ readonly input: number;
281
+ readonly type: "REDO";
282
+ readonly scope: OperationScope;
283
+ readonly index: number;
284
+ readonly timestamp: string;
285
+ readonly hash: string;
286
+ readonly skip: number;
287
+ } | {
288
+ readonly input: string;
289
+ readonly type: "SET_NAME";
290
+ readonly scope: "global";
291
+ readonly index: number;
292
+ readonly timestamp: string;
293
+ readonly hash: string;
294
+ readonly skip: number;
295
+ } | {
296
+ readonly input: number;
297
+ readonly type: "UNDO";
298
+ readonly scope: OperationScope;
299
+ readonly index: number;
300
+ readonly timestamp: string;
301
+ readonly hash: string;
302
+ readonly skip: number;
303
+ } | {
304
+ readonly input: unknown;
305
+ readonly type: "NOOP";
306
+ readonly scope: OperationScope;
307
+ readonly index: number;
308
+ readonly timestamp: string;
309
+ readonly hash: string;
310
+ readonly skip: number;
311
+ } | import("immer").Immutable<A & {
312
+ index: number;
313
+ timestamp: string;
314
+ hash: string;
315
+ skip: number;
316
+ }>)[];
317
+ readonly local: readonly ({
318
+ readonly input: {
319
+ readonly operations: number;
320
+ readonly state: {
321
+ readonly data?: unknown;
322
+ readonly name: string;
323
+ };
324
+ };
325
+ readonly type: "LOAD_STATE";
326
+ readonly scope: OperationScope;
327
+ readonly index: number;
328
+ readonly timestamp: string;
329
+ readonly hash: string;
330
+ readonly skip: number;
331
+ } | {
332
+ readonly input: {
333
+ readonly end?: import("./types").InputMaybe<number>;
334
+ readonly start?: import("./types").InputMaybe<number>;
335
+ };
336
+ readonly type: "PRUNE";
337
+ readonly scope: OperationScope;
338
+ readonly index: number;
339
+ readonly timestamp: string;
340
+ readonly hash: string;
341
+ readonly skip: number;
342
+ } | {
343
+ readonly input: number;
344
+ readonly type: "REDO";
345
+ readonly scope: OperationScope;
346
+ readonly index: number;
347
+ readonly timestamp: string;
348
+ readonly hash: string;
349
+ readonly skip: number;
350
+ } | {
351
+ readonly input: string;
352
+ readonly type: "SET_NAME";
353
+ readonly scope: "global";
354
+ readonly index: number;
355
+ readonly timestamp: string;
356
+ readonly hash: string;
357
+ readonly skip: number;
358
+ } | {
359
+ readonly input: number;
360
+ readonly type: "UNDO";
361
+ readonly scope: OperationScope;
362
+ readonly index: number;
363
+ readonly timestamp: string;
364
+ readonly hash: string;
365
+ readonly skip: number;
366
+ } | {
367
+ readonly input: unknown;
368
+ readonly type: "NOOP";
369
+ readonly scope: OperationScope;
370
+ readonly index: number;
371
+ readonly timestamp: string;
372
+ readonly hash: string;
373
+ readonly skip: number;
374
+ } | import("immer").Immutable<A & {
375
+ index: number;
376
+ timestamp: string;
377
+ hash: string;
378
+ skip: number;
379
+ }>)[];
380
+ };
381
+ readonly initialState: {
382
+ readonly name: string;
383
+ readonly revision: {
384
+ readonly global: number;
385
+ readonly local: number;
386
+ };
387
+ readonly documentType: string;
388
+ readonly created: string;
389
+ readonly lastModified: string;
390
+ readonly state: {
391
+ readonly global: import("immer").Immutable<T>;
392
+ readonly local: import("immer").Immutable<L>;
393
+ };
394
+ readonly attachments: {
395
+ readonly [x: string]: {
396
+ readonly data: string;
397
+ readonly mimeType: string;
398
+ readonly extension?: string | null | undefined;
399
+ readonly fileName?: string | null | undefined;
400
+ };
401
+ };
402
+ };
403
+ };
404
+ /**
405
+ * Gets the attachment associated with the given key.
406
+ * @param attachment - The key of the attachment to retrieve.
407
+ */
408
+ getAttachment(attachment: AttachmentRef): import("./types").Attachment;
409
+ /**
410
+ * Sets the name of the document.
411
+ * @param name - The new name of the document.
412
+ */
413
+ setName(name: string): this;
414
+ /**
415
+ * Reverts a number of actions from the document.
416
+ * @param count - The number of actions to revert.
417
+ */
418
+ undo(count: number): this;
419
+ /**
420
+ * Reapplies a number of actions to the document.
421
+ * @param count - The number of actions to reapply.
422
+ */
423
+ redo(count: number): this;
424
+ /**
425
+ * Removes a range of operations from the document.
426
+ * @param start - The starting index of the range to remove.
427
+ * @param end - The ending index of the range to remove.
428
+ */
429
+ prune(start?: number | undefined, end?: number | undefined): this;
430
+ /**
431
+ * Loads a document state and a set of operations.
432
+ * @param state - The state to load.
433
+ * @param operations - The operations to apply to the document.
434
+ */
435
+ loadState(state: Pick<ExtendedState<T, L>, 'state' | 'name'>, operations: number): this;
436
+ }
437
+ /**
438
+ * Applies multiple mixins to a base class.
439
+ * Used to have separate mixins to group methods by actions.
440
+ *
441
+ * @remarks
442
+ * {@link https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern}
443
+ *
444
+ * @param derivedCtor - The class to apply the mixins to.
445
+ * @param constructors - The constructors of the mixins.
446
+ */
447
+ export declare function applyMixins(derivedCtor: any, constructors: any[]): void;
@@ -0,0 +1,16 @@
1
+ import { BaseAction } from './actions/types';
2
+ import { Action, Document, ImmutableStateReducer, ReducerOptions } from './types';
3
+ import { SignalDispatch } from './signal';
4
+ /**
5
+ * Base document reducer that wraps a custom document reducer and handles
6
+ * document-level actions such as undo, redo, prune, and set name.
7
+ *
8
+ * @template T - The type of the state of the custom reducer.
9
+ * @template A - The type of the actions of the custom reducer.
10
+ * @param state - The current state of the document.
11
+ * @param action - The action object to apply to the state.
12
+ * @param customReducer - The custom reducer that implements the application logic
13
+ * specific to the document's state.
14
+ * @returns The new state of the document.
15
+ */
16
+ export declare function baseReducer<T, A extends Action, L>(document: Document<T, A, L>, action: A | BaseAction, customReducer: ImmutableStateReducer<T, A, L>, dispatch?: SignalDispatch, options?: ReducerOptions): Document<T, A, L>;
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * as z from './zod';
@@ -0,0 +1,180 @@
1
+ import { OperationScope } from '..';
2
+ export type Maybe<T> = T | null;
3
+ export type InputMaybe<T> = T | null | undefined;
4
+ export type Exact<T extends {
5
+ [key: string]: unknown;
6
+ }> = {
7
+ [K in keyof T]: T[K];
8
+ };
9
+ export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
10
+ [SubKey in K]?: Maybe<T[SubKey]>;
11
+ };
12
+ export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
13
+ [SubKey in K]: Maybe<T[SubKey]>;
14
+ };
15
+ export type MakeEmpty<T extends {
16
+ [key: string]: unknown;
17
+ }, K extends keyof T> = {
18
+ [_ in K]?: never;
19
+ };
20
+ export type Incremental<T> = T | {
21
+ [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never;
22
+ };
23
+ /** All built-in and custom scalars, mapped to their actual values */
24
+ export type Scalars = {
25
+ ID: {
26
+ input: string;
27
+ output: string;
28
+ };
29
+ String: {
30
+ input: string;
31
+ output: string;
32
+ };
33
+ Boolean: {
34
+ input: boolean;
35
+ output: boolean;
36
+ };
37
+ Int: {
38
+ input: number;
39
+ output: number;
40
+ };
41
+ Float: {
42
+ input: number;
43
+ output: number;
44
+ };
45
+ Address: {
46
+ input: `${string}:0x${string}`;
47
+ output: `${string}:0x${string}`;
48
+ };
49
+ Attachment: {
50
+ input: string;
51
+ output: string;
52
+ };
53
+ DateTime: {
54
+ input: string;
55
+ output: string;
56
+ };
57
+ Unknown: {
58
+ input: unknown;
59
+ output: unknown;
60
+ };
61
+ };
62
+ export type Action = IAction & {
63
+ __typename?: 'Action';
64
+ type: Scalars['String']['output'];
65
+ };
66
+ export type BaseAction = LoadStateAction | PruneAction | RedoAction | SetNameAction | UndoAction | NOOPAction;
67
+ export type DocumentFile = {
68
+ __typename?: 'DocumentFile';
69
+ data: Scalars['String']['output'];
70
+ extension: Maybe<Scalars['String']['output']>;
71
+ fileName: Maybe<Scalars['String']['output']>;
72
+ mimeType: Scalars['String']['output'];
73
+ };
74
+ export type IAction = {
75
+ type: Scalars['String']['output'];
76
+ };
77
+ export type IDocument = {
78
+ created: Scalars['DateTime']['output'];
79
+ documentType: Scalars['String']['output'];
80
+ lastModified: Scalars['DateTime']['output'];
81
+ name: Scalars['String']['output'];
82
+ operations: Array<IOperation>;
83
+ revision: Scalars['Int']['output'];
84
+ };
85
+ export type IOperation = {
86
+ hash: Scalars['String']['output'];
87
+ index: Scalars['Int']['output'];
88
+ timestamp: Scalars['DateTime']['output'];
89
+ type: Scalars['String']['output'];
90
+ };
91
+ export type Load_State = 'LOAD_STATE';
92
+ export type LoadStateAction = {
93
+ input: LoadStateActionInput;
94
+ type: Load_State | `${Load_State}`;
95
+ scope: OperationScope;
96
+ };
97
+ export type LoadStateActionInput = {
98
+ operations: Scalars['Int']['input'];
99
+ state: LoadStateActionStateInput;
100
+ };
101
+ export type LoadStateActionStateInput = {
102
+ data?: InputMaybe<Scalars['Unknown']['input']>;
103
+ name: Scalars['String']['input'];
104
+ };
105
+ export type Mutation = {
106
+ __typename?: 'Mutation';
107
+ loadState: Maybe<IDocument>;
108
+ prune: Maybe<IDocument>;
109
+ redo: Maybe<IDocument>;
110
+ setName: Maybe<IDocument>;
111
+ undo: Maybe<IDocument>;
112
+ };
113
+ export type MutationLoadStateArgs = {
114
+ input: LoadStateAction;
115
+ };
116
+ export type MutationPruneArgs = {
117
+ input: PruneAction;
118
+ };
119
+ export type MutationRedoArgs = {
120
+ input: RedoAction;
121
+ };
122
+ export type MutationSetNameArgs = {
123
+ input: SetNameAction;
124
+ };
125
+ export type MutationUndoArgs = {
126
+ input: UndoAction;
127
+ };
128
+ export type Operation = IOperation & {
129
+ __typename?: 'Operation';
130
+ hash: Scalars['String']['output'];
131
+ index: Scalars['Int']['output'];
132
+ timestamp: Scalars['DateTime']['output'];
133
+ type: Scalars['String']['output'];
134
+ };
135
+ export type Prune = 'PRUNE';
136
+ export type PruneAction = {
137
+ input: PruneActionInput;
138
+ type: Prune | `${Prune}`;
139
+ scope: OperationScope;
140
+ };
141
+ export type PruneActionInput = {
142
+ end?: InputMaybe<Scalars['Int']['input']>;
143
+ start?: InputMaybe<Scalars['Int']['input']>;
144
+ };
145
+ export type Query = {
146
+ __typename?: 'Query';
147
+ document: Maybe<IDocument>;
148
+ };
149
+ export type Redo = 'REDO';
150
+ export type RedoAction = {
151
+ input: Scalars['Int']['input'];
152
+ type: Redo | `${Redo}`;
153
+ scope: OperationScope;
154
+ };
155
+ export type Set_Name = 'SET_NAME';
156
+ export type SetNameAction = {
157
+ input: Scalars['String']['input'];
158
+ type: Set_Name | `${Set_Name}`;
159
+ scope: 'global';
160
+ };
161
+ export type SetNameOperation = IOperation & {
162
+ __typename?: 'SetNameOperation';
163
+ hash: Scalars['String']['output'];
164
+ index: Scalars['Int']['output'];
165
+ input: Scalars['String']['output'];
166
+ timestamp: Scalars['DateTime']['output'];
167
+ type: Scalars['String']['output'];
168
+ };
169
+ export type Undo = 'UNDO';
170
+ export type UndoAction = {
171
+ input: Scalars['Int']['input'];
172
+ type: Undo | `${Undo}`;
173
+ scope: OperationScope;
174
+ };
175
+ export type NOOP = 'NOOP';
176
+ export type NOOPAction = {
177
+ input: Scalars['Unknown']['input'];
178
+ type: NOOP | `${NOOP}`;
179
+ scope: OperationScope;
180
+ };