document-model 1.5.0 → 1.7.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/{node/cjs/internal/index-RX6RcsNg.js → browser/cjs/internal/index-BllCzBc9.js} +11 -3
- package/dist/browser/cjs/internal/index-BllCzBc9.js.map +1 -0
- package/dist/browser/cjs/internal/{index-BoiSedJ2.js → index-DTRXQ2Nf.js} +5 -10
- package/dist/browser/{es/internal/index-B7idSyw8.js.map → cjs/internal/index-DTRXQ2Nf.js.map} +1 -1
- package/dist/browser/cjs/internal/{object-DldjPOTT.js → object-Bf9_woMQ.js} +327 -321
- package/dist/browser/cjs/internal/object-Bf9_woMQ.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-B7idSyw8.js → index-BAvDobTr.js} +5 -10
- package/dist/{node/es/internal/index-BFRJ-0Rp.js.map → browser/es/internal/index-BAvDobTr.js.map} +1 -1
- package/dist/browser/es/internal/index-Db40bdYP.js +58 -0
- package/dist/browser/es/internal/index-Db40bdYP.js.map +1 -0
- package/dist/browser/es/internal/{object-I6vKsK3r.js → object-CY74acQg.js} +352 -346
- package/dist/browser/es/internal/object-CY74acQg.js.map +1 -0
- package/dist/browser/src/document/actions/creators.d.ts +1 -1
- package/dist/browser/src/document/schema/zod.d.ts +18 -18
- package/dist/browser/src/document/types.d.ts +12 -1
- package/dist/browser/src/document/utils/base.d.ts +1 -1
- package/dist/browser/src/document/utils/crypto.d.ts +10 -0
- package/dist/browser/src/document/utils/document-helpers.d.ts +1 -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 +177 -177
- 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-WVYoLyly.js → index-aABa-Hb0.js} +5 -10
- package/dist/node/cjs/internal/{index-WVYoLyly.js.map → index-aABa-Hb0.js.map} +1 -1
- package/dist/{browser/cjs/internal/index-frw-qprx.js → node/cjs/internal/index-kI4cPPpE.js} +11 -3
- package/dist/node/cjs/internal/index-kI4cPPpE.js.map +1 -0
- package/dist/node/cjs/internal/{object-7GplcYr4.js → object-BMm0OLWL.js} +173 -60
- package/dist/node/cjs/internal/object-BMm0OLWL.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-BFRJ-0Rp.js → index-B0WPutmO.js} +5 -10
- package/dist/{browser/cjs/internal/index-BoiSedJ2.js.map → node/es/internal/index-B0WPutmO.js.map} +1 -1
- package/dist/node/es/internal/index-MkEgGMJR.js +58 -0
- package/dist/node/es/internal/index-MkEgGMJR.js.map +1 -0
- package/dist/node/es/internal/{object-Cu2Dz-iF.js → object-VZ_AS47_.js} +198 -85
- package/dist/node/es/internal/object-VZ_AS47_.js.map +1 -0
- package/dist/node/src/document/actions/creators.d.ts +1 -1
- package/dist/node/src/document/schema/zod.d.ts +18 -18
- package/dist/node/src/document/types.d.ts +12 -1
- package/dist/node/src/document/utils/base.d.ts +1 -1
- package/dist/node/src/document/utils/crypto.d.ts +10 -0
- package/dist/node/src/document/utils/document-helpers.d.ts +1 -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 +177 -177
- package/dist/node/src/document-model/index.d.ts +3 -3
- package/package.json +2 -1
- package/dist/browser/cjs/internal/index-frw-qprx.js.map +0 -1
- package/dist/browser/cjs/internal/object-DldjPOTT.js.map +0 -1
- package/dist/browser/es/internal/index-D2kKzCXD.js +0 -50
- package/dist/browser/es/internal/index-D2kKzCXD.js.map +0 -1
- package/dist/browser/es/internal/object-I6vKsK3r.js.map +0 -1
- package/dist/node/cjs/internal/index-RX6RcsNg.js.map +0 -1
- package/dist/node/cjs/internal/object-7GplcYr4.js.map +0 -1
- package/dist/node/es/internal/index-NWZKlhKu.js +0 -50
- package/dist/node/es/internal/index-NWZKlhKu.js.map +0 -1
- package/dist/node/es/internal/object-Cu2Dz-iF.js.map +0 -1
|
@@ -44,5 +44,5 @@ export declare const prune: (start?: number | undefined, end?: number | undefine
|
|
|
44
44
|
* @param operations - Number of operations that were removed from the previous state.
|
|
45
45
|
* @category Actions
|
|
46
46
|
*/
|
|
47
|
-
export declare const loadState: <S, T>(state: Pick<ExtendedState<S, T>,
|
|
47
|
+
export declare const loadState: <S, T>(state: Pick<ExtendedState<S, T>, "state" | "name">, operations: number) => LoadStateAction;
|
|
48
48
|
export declare const noop: (scope?: OperationScope) => NOOPAction;
|
|
@@ -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
|
*
|
|
@@ -61,7 +61,7 @@ export declare const createExtendedState: <S, L>(initialState?: Partial<Extended
|
|
|
61
61
|
* @returns The new document state.
|
|
62
62
|
*/
|
|
63
63
|
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,
|
|
64
|
+
export declare const hashDocument: (document: Pick<Document, "state">, scope?: OperationScope) => string;
|
|
65
65
|
export declare const hashKey: (date?: Date, randomLimit?: number) => string;
|
|
66
66
|
export declare function readOnly<T>(value: T): Readonly<T>;
|
|
67
67
|
/**
|
|
@@ -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>;
|
|
@@ -60,4 +60,5 @@ export declare function garbageCollectDocumentOperations<A extends Action>(docum
|
|
|
60
60
|
* @returns An array of operations with duplicates filtered out.
|
|
61
61
|
*/
|
|
62
62
|
export declare function filterDuplicatedOperations(targetOperations: Operation[], sourceOperations: Operation[]): Operation[];
|
|
63
|
+
export declare function filterDocumentOperationsResultingState<A extends Action>(documentOperations?: DocumentOperations<A>): {};
|
|
63
64
|
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;
|