document-model 1.6.0 → 1.8.0
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.
- package/dist/browser/cjs/document-model.js +2 -2
- package/dist/browser/cjs/document.js +2 -2
- package/dist/browser/cjs/index.js +2 -2
- package/dist/browser/cjs/internal/{index-vlbA6Asd.js → index-UG6TQ_ad.js} +5 -10
- package/dist/browser/{es/internal/index-CuhiYn-8.js.map → cjs/internal/index-UG6TQ_ad.js.map} +1 -1
- package/dist/browser/cjs/internal/{index-BImZF-Wk.js → index-jRdLtWv9.js} +12 -4
- package/dist/browser/cjs/internal/index-jRdLtWv9.js.map +1 -0
- package/dist/browser/cjs/internal/{object-9Wvjprnm.js → object-CCclzskm.js} +640 -2287
- package/dist/browser/cjs/internal/object-CCclzskm.js.map +1 -0
- package/dist/browser/es/document-model.js +2 -2
- package/dist/browser/es/document.js +8 -8
- package/dist/browser/es/index.js +2 -2
- package/dist/browser/es/internal/{index-CuhiYn-8.js → index-CDwXQBxG.js} +5 -10
- package/dist/{node/es/internal/index-BNAE-_Hg.js.map → browser/es/internal/index-CDwXQBxG.js.map} +1 -1
- package/dist/browser/es/internal/index-v4H3kbAF.js +58 -0
- package/dist/browser/es/internal/index-v4H3kbAF.js.map +1 -0
- package/dist/browser/es/internal/{object-CyAog_F_.js → object-CU5T1DpX.js} +664 -2311
- package/dist/browser/es/internal/object-CU5T1DpX.js.map +1 -0
- package/dist/browser/src/document/actions/creators.d.ts +1 -1
- package/dist/browser/src/document/reducer.d.ts +4 -1
- package/dist/browser/src/document/schema/zod.d.ts +18 -18
- package/dist/browser/src/document/types.d.ts +13 -1
- package/dist/browser/src/document/utils/base.d.ts +3 -3
- package/dist/browser/src/document/utils/crypto.d.ts +10 -0
- package/dist/browser/src/document/utils/document-helpers.d.ts +10 -0
- package/dist/browser/src/document/utils/index.d.ts +1 -0
- package/dist/browser/src/document/utils/node.d.ts +3 -2
- package/dist/browser/src/document-model/gen/schema/zod.d.ts +169 -169
- package/dist/browser/src/document-model/index.d.ts +3 -3
- package/dist/node/cjs/document-model.js +2 -2
- package/dist/node/cjs/document.js +2 -2
- package/dist/node/cjs/index.js +2 -2
- package/dist/node/cjs/internal/{index-CJIU8iX-.js → index-5qN282Jw.js} +12 -4
- package/dist/node/cjs/internal/index-5qN282Jw.js.map +1 -0
- package/dist/node/cjs/internal/{index-DWeC8dwW.js → index-Bm-pIfaz.js} +5 -10
- package/dist/node/cjs/internal/{index-DWeC8dwW.js.map → index-Bm-pIfaz.js.map} +1 -1
- package/dist/node/cjs/internal/{object-op6YzhH1.js → object-BMOaYPkd.js} +381 -244
- package/dist/node/cjs/internal/object-BMOaYPkd.js.map +1 -0
- package/dist/node/es/document-model.js +2 -2
- package/dist/node/es/document.js +8 -8
- package/dist/node/es/index.js +2 -2
- package/dist/node/es/internal/{index-BNAE-_Hg.js → index-CAjAt1Xx.js} +5 -10
- package/dist/{browser/cjs/internal/index-vlbA6Asd.js.map → node/es/internal/index-CAjAt1Xx.js.map} +1 -1
- package/dist/node/es/internal/index-CVuLZAmf.js +58 -0
- package/dist/node/es/internal/index-CVuLZAmf.js.map +1 -0
- package/dist/node/es/internal/{object-BuK9PFjs.js → object-COSf2HUT.js} +405 -268
- package/dist/node/es/internal/object-COSf2HUT.js.map +1 -0
- package/dist/node/src/document/actions/creators.d.ts +1 -1
- package/dist/node/src/document/reducer.d.ts +4 -1
- package/dist/node/src/document/schema/zod.d.ts +18 -18
- package/dist/node/src/document/types.d.ts +13 -1
- package/dist/node/src/document/utils/base.d.ts +3 -3
- package/dist/node/src/document/utils/crypto.d.ts +10 -0
- package/dist/node/src/document/utils/document-helpers.d.ts +10 -0
- package/dist/node/src/document/utils/index.d.ts +1 -0
- package/dist/node/src/document/utils/node.d.ts +3 -2
- package/dist/node/src/document-model/gen/schema/zod.d.ts +169 -169
- package/dist/node/src/document-model/index.d.ts +3 -3
- package/package.json +6 -3
- package/dist/browser/cjs/internal/index-BImZF-Wk.js.map +0 -1
- package/dist/browser/cjs/internal/object-9Wvjprnm.js.map +0 -1
- package/dist/browser/es/internal/index-Drp90r05.js +0 -50
- package/dist/browser/es/internal/index-Drp90r05.js.map +0 -1
- package/dist/browser/es/internal/object-CyAog_F_.js.map +0 -1
- package/dist/node/cjs/internal/index-CJIU8iX-.js.map +0 -1
- package/dist/node/cjs/internal/object-op6YzhH1.js.map +0 -1
- package/dist/node/es/internal/index-B_7z_4EV.js +0 -50
- package/dist/node/es/internal/index-B_7z_4EV.js.map +0 -1
- package/dist/node/es/internal/object-BuK9PFjs.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { Action, DocumentFile, LoadStateAction, LoadStateActionInput, LoadStateActionStateInput, Operation, PruneAction, PruneActionInput, RedoAction, SetNameAction, SetNameOperation, UndoAction } from '.';
|
|
2
|
+
import { Action, DocumentFile, Load_State, LoadStateAction, LoadStateActionInput, LoadStateActionStateInput, Operation, Prune, PruneAction, PruneActionInput, Redo, RedoAction, Set_Name, SetNameAction, SetNameOperation, Undo, UndoAction } from '.';
|
|
3
3
|
import { OperationScope } from '../types';
|
|
4
4
|
|
|
5
5
|
type Properties<T> = Required<{
|
|
@@ -7,7 +7,7 @@ type Properties<T> = Required<{
|
|
|
7
7
|
}>;
|
|
8
8
|
type definedNonNullAny = {};
|
|
9
9
|
export declare const isDefinedNonNullAny: (v: any) => v is definedNonNullAny;
|
|
10
|
-
export declare const definedNonNullAnySchema: z.ZodEffects<z.ZodAny,
|
|
10
|
+
export declare const definedNonNullAnySchema: z.ZodEffects<z.ZodAny, definedNonNullAny, any>;
|
|
11
11
|
export declare const Load_StateSchema: z.ZodEnum<["LOAD_STATE"]>;
|
|
12
12
|
export declare const PruneSchema: z.ZodEnum<["PRUNE"]>;
|
|
13
13
|
export declare const RedoSchema: z.ZodEnum<["REDO"]>;
|
|
@@ -21,11 +21,11 @@ export declare function BaseActionSchema(): z.ZodUnion<[z.ZodObject<Required<{
|
|
|
21
21
|
scope: z.ZodType<OperationScope, any, OperationScope>;
|
|
22
22
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
23
23
|
input: LoadStateActionInput;
|
|
24
|
-
type:
|
|
24
|
+
type: Load_State;
|
|
25
25
|
scope: OperationScope;
|
|
26
26
|
}, {
|
|
27
27
|
input: LoadStateActionInput;
|
|
28
|
-
type:
|
|
28
|
+
type: Load_State;
|
|
29
29
|
scope: OperationScope;
|
|
30
30
|
}>, z.ZodObject<Required<{
|
|
31
31
|
input: z.ZodType<PruneActionInput, any, PruneActionInput>;
|
|
@@ -33,47 +33,47 @@ export declare function BaseActionSchema(): z.ZodUnion<[z.ZodObject<Required<{
|
|
|
33
33
|
scope: z.ZodType<OperationScope, any, OperationScope>;
|
|
34
34
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
35
35
|
input: PruneActionInput;
|
|
36
|
-
type:
|
|
36
|
+
type: Prune;
|
|
37
37
|
scope: OperationScope;
|
|
38
38
|
}, {
|
|
39
39
|
input: PruneActionInput;
|
|
40
|
-
type:
|
|
40
|
+
type: Prune;
|
|
41
41
|
scope: OperationScope;
|
|
42
42
|
}>, z.ZodObject<Required<{
|
|
43
43
|
input: z.ZodType<number, any, number>;
|
|
44
44
|
type: z.ZodType<"REDO", any, "REDO">;
|
|
45
45
|
scope: z.ZodType<OperationScope, any, OperationScope>;
|
|
46
46
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
47
|
-
input:
|
|
48
|
-
type:
|
|
47
|
+
input: import('./types').Scalars["Int"]["input"];
|
|
48
|
+
type: Redo;
|
|
49
49
|
scope: OperationScope;
|
|
50
50
|
}, {
|
|
51
|
-
input:
|
|
52
|
-
type:
|
|
51
|
+
input: import('./types').Scalars["Int"]["input"];
|
|
52
|
+
type: Redo;
|
|
53
53
|
scope: OperationScope;
|
|
54
54
|
}>, z.ZodObject<Required<{
|
|
55
55
|
input: z.ZodType<string, any, string>;
|
|
56
56
|
type: z.ZodType<"SET_NAME", any, "SET_NAME">;
|
|
57
57
|
scope: z.ZodType<"global", any, "global">;
|
|
58
58
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
59
|
-
input:
|
|
60
|
-
type:
|
|
59
|
+
input: import('./types').Scalars["String"]["input"];
|
|
60
|
+
type: Set_Name;
|
|
61
61
|
scope: "global";
|
|
62
62
|
}, {
|
|
63
|
-
input:
|
|
64
|
-
type:
|
|
63
|
+
input: import('./types').Scalars["String"]["input"];
|
|
64
|
+
type: Set_Name;
|
|
65
65
|
scope: "global";
|
|
66
66
|
}>, z.ZodObject<Required<{
|
|
67
67
|
input: z.ZodType<number, any, number>;
|
|
68
68
|
type: z.ZodType<"UNDO", any, "UNDO">;
|
|
69
69
|
scope: z.ZodType<OperationScope, any, OperationScope>;
|
|
70
70
|
}>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
71
|
-
input:
|
|
72
|
-
type:
|
|
71
|
+
input: import('./types').Scalars["Int"]["input"];
|
|
72
|
+
type: Undo;
|
|
73
73
|
scope: OperationScope;
|
|
74
74
|
}, {
|
|
75
|
-
input:
|
|
76
|
-
type:
|
|
75
|
+
input: import('./types').Scalars["Int"]["input"];
|
|
76
|
+
type: Undo;
|
|
77
77
|
scope: OperationScope;
|
|
78
78
|
}>]>;
|
|
79
79
|
export declare function DocumentFileSchema(): z.ZodObject<Properties<DocumentFile>>;
|
|
@@ -11,6 +11,7 @@ export type * from './schema/types';
|
|
|
11
11
|
export type { FileInput } from './utils';
|
|
12
12
|
export type { BaseAction } from './actions/types';
|
|
13
13
|
export type { Immutable } from 'mutative';
|
|
14
|
+
export type Signature = [string, string, string, string, string];
|
|
14
15
|
export type ActionSigner = {
|
|
15
16
|
user: {
|
|
16
17
|
address: string;
|
|
@@ -21,7 +22,7 @@ export type ActionSigner = {
|
|
|
21
22
|
name: string;
|
|
22
23
|
key: string;
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
+
signatures: Signature[];
|
|
25
26
|
};
|
|
26
27
|
export type ActionContext = {
|
|
27
28
|
signer?: ActionSigner;
|
|
@@ -170,6 +171,16 @@ export type MappedOperation<A extends Action> = {
|
|
|
170
171
|
operation: Operation<A | BaseAction>;
|
|
171
172
|
};
|
|
172
173
|
export type DocumentOperationsIgnoreMap<A extends Action> = Required<Record<OperationScope, MappedOperation<A>[]>>;
|
|
174
|
+
export type OperationSignatureContext = {
|
|
175
|
+
documentId: string;
|
|
176
|
+
signer: Omit<ActionSigner, 'signatures'> & {
|
|
177
|
+
signatures?: Signature[];
|
|
178
|
+
};
|
|
179
|
+
operation: Operation;
|
|
180
|
+
previousStateHash: string;
|
|
181
|
+
};
|
|
182
|
+
export type OperationSigningHandler = (message: Uint8Array) => Promise<Uint8Array>;
|
|
183
|
+
export type OperationVerificationHandler = (publicKey: string, signature: Uint8Array, data: Uint8Array) => Promise<boolean>;
|
|
173
184
|
/**
|
|
174
185
|
* The base type of a document model.
|
|
175
186
|
*
|
|
@@ -253,6 +264,7 @@ export type UndoRedoProcessResult<T, A extends Action, L> = {
|
|
|
253
264
|
document: Document<T, A, L>;
|
|
254
265
|
action: A | BaseAction;
|
|
255
266
|
skip: number;
|
|
267
|
+
reuseLastOperationIndex: boolean;
|
|
256
268
|
};
|
|
257
269
|
export type ValidationError = {
|
|
258
270
|
message: string;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { baseReducer, mutableBaseReducer } from '../reducer';
|
|
2
|
-
import { Action, BaseAction, UndoRedoAction, Document, ExtendedState, ImmutableStateReducer, Reducer, OperationScope, State, CreateState, PartialState, DocumentOperations, DocumentHeader, DocumentOperationsIgnoreMap, Operation, MappedOperation, ReducerOptions } from '../types';
|
|
2
|
+
import { Action, BaseAction, UndoRedoAction, Document, ExtendedState, ImmutableStateReducer, Reducer, OperationScope, State, CreateState, PartialState, DocumentOperations, DocumentHeader, DocumentOperationsIgnoreMap, Operation, MappedOperation, ReducerOptions, UndoAction } from '../types';
|
|
3
3
|
import { SignalDispatch } from '../signal';
|
|
4
4
|
|
|
5
5
|
export declare function isNoopOperation(op: Partial<Operation>): boolean;
|
|
6
6
|
export declare function isUndoRedo(action: Action): action is UndoRedoAction;
|
|
7
|
+
export declare function isUndo(action: Action): action is UndoAction;
|
|
7
8
|
export declare function isBaseAction(action: Action): action is BaseAction;
|
|
8
9
|
/**
|
|
9
10
|
* Helper function to be used by action creators.
|
|
@@ -61,7 +62,7 @@ export declare const createExtendedState: <S, L>(initialState?: Partial<Extended
|
|
|
61
62
|
* @returns The new document state.
|
|
62
63
|
*/
|
|
63
64
|
export declare const createDocument: <S, A extends Action, L = unknown>(initialState?: Partial<ExtendedState<PartialState<S>, PartialState<L>>>, createState?: (state?: Partial<State<PartialState<S>, PartialState<L>>>) => State<S, L>) => Document<S, A, L>;
|
|
64
|
-
export declare const hashDocument: (document: Pick<Document,
|
|
65
|
+
export declare const hashDocument: (document: Pick<Document, "state">, scope?: OperationScope) => string;
|
|
65
66
|
export declare const hashKey: (date?: Date, randomLimit?: number) => string;
|
|
66
67
|
export declare function readOnly<T>(value: T): Readonly<T>;
|
|
67
68
|
/**
|
|
@@ -73,7 +74,6 @@ export declare function readOnly<T>(value: T): Readonly<T>;
|
|
|
73
74
|
* @throws Error if the operation index is invalid and there are missing operations.
|
|
74
75
|
*/
|
|
75
76
|
export declare function mapSkippedOperations<A extends Action>(operations: Operation<BaseAction | A>[], skippedHeadOperations?: number): MappedOperation<A>[];
|
|
76
|
-
export declare function calculateSkipsLeft<A extends Action>(operations: Operation<BaseAction | A>[], currentIndex: number, skip: number): number;
|
|
77
77
|
export declare function sortOperations<A extends Action>(operations: DocumentOperations<A>): Operation<BaseAction | A>[];
|
|
78
78
|
export declare function sortMappedOperations<A extends Action>(operations: DocumentOperationsIgnoreMap<A>): MappedOperation<A>[];
|
|
79
79
|
export declare function replayOperations<T, A extends Action, L>(initialState: ExtendedState<T, L>, clearedOperations: DocumentOperations<A>, reducer: ImmutableStateReducer<T, A, L>, dispatch?: SignalDispatch, header?: DocumentHeader, documentReducer?: typeof baseReducer, skipHeaderOperations?: SkipHeaderOperations, options?: ReducerOptions): Document<T, A, L>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Action, ActionSigner, BaseAction, Document, Operation, OperationSignatureContext, OperationSigningHandler, OperationVerificationHandler, Reducer, Signature } from '../types';
|
|
2
|
+
|
|
3
|
+
export declare function getUnixTimestamp(date: Date | string): string;
|
|
4
|
+
export declare function buildOperationSignatureParams({ documentId, signer, operation, previousStateHash, }: OperationSignatureContext): [string, string, string, string];
|
|
5
|
+
export declare function buildOperationSignatureMessage(params: [string, string, string, string]): Uint8Array;
|
|
6
|
+
export declare function ab2hex(ab: ArrayBuffer): string;
|
|
7
|
+
export declare function hex2ab(hex: string): Uint8Array;
|
|
8
|
+
export declare function buildOperationSignature(context: OperationSignatureContext, signMethod: OperationSigningHandler): Promise<Signature>;
|
|
9
|
+
export declare function buildSignedOperation<T, A extends Action, L>(action: A | Operation<A>, reducer: Reducer<T, A, L>, document: Document<T, A, L>, context: Omit<OperationSignatureContext, 'operation' | 'previousStateHash'>, signHandler: OperationSigningHandler): Promise<Operation<A | BaseAction>>;
|
|
10
|
+
export declare function verifyOperationSignature<T, A extends Action, L>(signature: Signature, signer: Omit<ActionSigner, 'signatures'>, verifyHandler: OperationVerificationHandler): Promise<boolean>;
|
|
@@ -61,4 +61,14 @@ export declare function garbageCollectDocumentOperations<A extends Action>(docum
|
|
|
61
61
|
*/
|
|
62
62
|
export declare function filterDuplicatedOperations(targetOperations: Operation[], sourceOperations: Operation[]): Operation[];
|
|
63
63
|
export declare function filterDocumentOperationsResultingState<A extends Action>(documentOperations?: DocumentOperations<A>): {};
|
|
64
|
+
/**
|
|
65
|
+
* Calculates the difference between two arrays of operations.
|
|
66
|
+
* Returns an array of operations that are present in `clearedOperationsA` but not in `clearedOperationsB`.
|
|
67
|
+
*
|
|
68
|
+
* @template A - The type of the operations.
|
|
69
|
+
* @param {A[]} clearedOperationsA - The first array of operations.
|
|
70
|
+
* @param {A[]} clearedOperationsB - The second array of operations.
|
|
71
|
+
* @returns {A[]} - The difference between the two arrays of operations.
|
|
72
|
+
*/
|
|
73
|
+
export declare function diffOperations<A extends OperationIndex>(clearedOperationsA: A[], clearedOperationsB: A[]): A[];
|
|
64
74
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './base';
|
|
2
2
|
export { createAction, createDocument, createExtendedState, createReducer, hashDocument, hashKey, isBaseAction, mapSkippedOperations, parseResultingState, readOnly, replayDocument, replayOperations, sortMappedOperations, sortOperations, } from './base';
|
|
3
|
+
export * from './crypto';
|
|
3
4
|
export * from './file';
|
|
4
5
|
export * from './validation';
|
|
5
6
|
export * as documentHelpers from './document-helpers';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { default as crypto } from 'crypto';
|
|
2
|
+
|
|
2
3
|
export declare function writeFile(path: string, name: string, data: Uint8Array): Promise<string>;
|
|
3
4
|
export declare function readFile(path: string): Buffer;
|
|
4
5
|
export declare function fetchFile(url: string): Promise<{
|
|
@@ -6,4 +7,4 @@ export declare function fetchFile(url: string): Promise<{
|
|
|
6
7
|
mimeType?: string;
|
|
7
8
|
}>;
|
|
8
9
|
export declare const getFile: (file: string) => Promise<Buffer>;
|
|
9
|
-
export declare const hash: (data:
|
|
10
|
+
export declare const hash: (data: crypto.BinaryLike, algorithm?: string) => string;
|