document-model 6.0.2-staging.1 → 6.0.2-staging.10
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/index.d.ts +81 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +229 -0
- package/dist/index.js.map +1 -0
- package/dist/{src/core/node.d.ts → node.d.mts} +25 -23
- package/dist/node.d.mts.map +1 -0
- package/dist/node.mjs +145 -0
- package/dist/node.mjs.map +1 -0
- package/package.json +22 -18
- package/dist/src/core/actions.d.ts +0 -87
- package/dist/src/core/actions.d.ts.map +0 -1
- package/dist/src/core/actions.js +0 -187
- package/dist/src/core/actions.js.map +0 -1
- package/dist/src/core/controller.d.ts +0 -30
- package/dist/src/core/controller.d.ts.map +0 -1
- package/dist/src/core/controller.js +0 -60
- package/dist/src/core/controller.js.map +0 -1
- package/dist/src/core/crypto.d.ts +0 -8
- package/dist/src/core/crypto.d.ts.map +0 -1
- package/dist/src/core/crypto.js +0 -68
- package/dist/src/core/crypto.js.map +0 -1
- package/dist/src/core/documents.d.ts +0 -147
- package/dist/src/core/documents.d.ts.map +0 -1
- package/dist/src/core/documents.js +0 -845
- package/dist/src/core/documents.js.map +0 -1
- package/dist/src/core/errors.d.ts +0 -21
- package/dist/src/core/errors.d.ts.map +0 -1
- package/dist/src/core/errors.js +0 -46
- package/dist/src/core/errors.js.map +0 -1
- package/dist/src/core/files.d.ts +0 -27
- package/dist/src/core/files.d.ts.map +0 -1
- package/dist/src/core/files.js +0 -90
- package/dist/src/core/files.js.map +0 -1
- package/dist/src/core/header.d.ts +0 -63
- package/dist/src/core/header.d.ts.map +0 -1
- package/dist/src/core/header.js +0 -173
- package/dist/src/core/header.js.map +0 -1
- package/dist/src/core/index.d.ts +0 -16
- package/dist/src/core/index.d.ts.map +0 -1
- package/dist/src/core/index.js +0 -16
- package/dist/src/core/index.js.map +0 -1
- package/dist/src/core/logger-types.d.ts +0 -12
- package/dist/src/core/logger-types.d.ts.map +0 -1
- package/dist/src/core/logger-types.js +0 -2
- package/dist/src/core/logger-types.js.map +0 -1
- package/dist/src/core/logger.d.ts +0 -27
- package/dist/src/core/logger.d.ts.map +0 -1
- package/dist/src/core/logger.js +0 -127
- package/dist/src/core/logger.js.map +0 -1
- package/dist/src/core/node.d.ts.map +0 -1
- package/dist/src/core/node.js +0 -155
- package/dist/src/core/node.js.map +0 -1
- package/dist/src/core/operations.d.ts +0 -50
- package/dist/src/core/operations.d.ts.map +0 -1
- package/dist/src/core/operations.js +0 -126
- package/dist/src/core/operations.js.map +0 -1
- package/dist/src/core/ph-types.d.ts +0 -2
- package/dist/src/core/ph-types.d.ts.map +0 -1
- package/dist/src/core/ph-types.js +0 -2
- package/dist/src/core/ph-types.js.map +0 -1
- package/dist/src/core/reducer.d.ts +0 -63
- package/dist/src/core/reducer.d.ts.map +0 -1
- package/dist/src/core/reducer.js +0 -446
- package/dist/src/core/reducer.js.map +0 -1
- package/dist/src/core/schemas.d.ts +0 -75
- package/dist/src/core/schemas.d.ts.map +0 -1
- package/dist/src/core/schemas.js +0 -116
- package/dist/src/core/schemas.js.map +0 -1
- package/dist/src/core/state.d.ts +0 -26
- package/dist/src/core/state.d.ts.map +0 -1
- package/dist/src/core/state.js +0 -56
- package/dist/src/core/state.js.map +0 -1
- package/dist/src/core/types.d.ts +0 -2
- package/dist/src/core/types.d.ts.map +0 -1
- package/dist/src/core/types.js +0 -2
- package/dist/src/core/types.js.map +0 -1
- package/dist/src/core/utils.d.ts +0 -6
- package/dist/src/core/utils.d.ts.map +0 -1
- package/dist/src/core/utils.js +0 -15
- package/dist/src/core/utils.js.map +0 -1
- package/dist/src/core/validation.d.ts +0 -4
- package/dist/src/core/validation.d.ts.map +0 -1
- package/dist/src/core/validation.js +0 -27
- package/dist/src/core/validation.js.map +0 -1
- package/dist/src/document-model/actions.d.ts +0 -164
- package/dist/src/document-model/actions.d.ts.map +0 -1
- package/dist/src/document-model/actions.js +0 -111
- package/dist/src/document-model/actions.js.map +0 -1
- package/dist/src/document-model/constants.d.ts +0 -6
- package/dist/src/document-model/constants.d.ts.map +0 -1
- package/dist/src/document-model/constants.js +0 -584
- package/dist/src/document-model/constants.js.map +0 -1
- package/dist/src/document-model/controller.d.ts +0 -5
- package/dist/src/document-model/controller.d.ts.map +0 -1
- package/dist/src/document-model/controller.js +0 -5
- package/dist/src/document-model/controller.js.map +0 -1
- package/dist/src/document-model/document-schema.d.ts +0 -69
- package/dist/src/document-model/document-schema.d.ts.map +0 -1
- package/dist/src/document-model/document-schema.js +0 -43
- package/dist/src/document-model/document-schema.js.map +0 -1
- package/dist/src/document-model/document-type.d.ts +0 -2
- package/dist/src/document-model/document-type.d.ts.map +0 -1
- package/dist/src/document-model/document-type.js +0 -2
- package/dist/src/document-model/document-type.js.map +0 -1
- package/dist/src/document-model/files.d.ts +0 -5
- package/dist/src/document-model/files.d.ts.map +0 -1
- package/dist/src/document-model/files.js +0 -9
- package/dist/src/document-model/files.js.map +0 -1
- package/dist/src/document-model/index.d.ts +0 -12
- package/dist/src/document-model/index.d.ts.map +0 -1
- package/dist/src/document-model/index.js +0 -12
- package/dist/src/document-model/index.js.map +0 -1
- package/dist/src/document-model/module.d.ts +0 -3
- package/dist/src/document-model/module.d.ts.map +0 -1
- package/dist/src/document-model/module.js +0 -24
- package/dist/src/document-model/module.js.map +0 -1
- package/dist/src/document-model/reducers.d.ts +0 -11
- package/dist/src/document-model/reducers.d.ts.map +0 -1
- package/dist/src/document-model/reducers.js +0 -618
- package/dist/src/document-model/reducers.js.map +0 -1
- package/dist/src/document-model/schemas.d.ts +0 -189
- package/dist/src/document-model/schemas.d.ts.map +0 -1
- package/dist/src/document-model/schemas.js +0 -388
- package/dist/src/document-model/schemas.js.map +0 -1
- package/dist/src/document-model/state.d.ts +0 -15
- package/dist/src/document-model/state.d.ts.map +0 -1
- package/dist/src/document-model/state.js +0 -75
- package/dist/src/document-model/state.js.map +0 -1
- package/dist/src/document-model/types.d.ts +0 -584
- package/dist/src/document-model/types.d.ts.map +0 -1
- package/dist/src/document-model/types.js +0 -2
- package/dist/src/document-model/types.js.map +0 -1
- package/dist/src/document-model/validation.d.ts +0 -32
- package/dist/src/document-model/validation.d.ts.map +0 -1
- package/dist/src/document-model/validation.js +0 -166
- package/dist/src/document-model/validation.js.map +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -3
- package/dist/src/index.js.map +0 -1
- package/dist/test/document/crypto.test.d.ts +0 -2
- package/dist/test/document/crypto.test.d.ts.map +0 -1
- package/dist/test/document/crypto.test.js +0 -192
- package/dist/test/document/crypto.test.js.map +0 -1
- package/dist/test/document/event-vs-command.test.d.ts +0 -2
- package/dist/test/document/event-vs-command.test.d.ts.map +0 -1
- package/dist/test/document/event-vs-command.test.js +0 -202
- package/dist/test/document/event-vs-command.test.js.map +0 -1
- package/dist/test/document/local.test.d.ts +0 -2
- package/dist/test/document/local.test.d.ts.map +0 -1
- package/dist/test/document/local.test.js +0 -226
- package/dist/test/document/local.test.js.map +0 -1
- package/dist/test/document/operation-id.test.d.ts +0 -2
- package/dist/test/document/operation-id.test.d.ts.map +0 -1
- package/dist/test/document/operation-id.test.js +0 -118
- package/dist/test/document/operation-id.test.js.map +0 -1
- package/dist/test/document/prune.test.d.ts +0 -2
- package/dist/test/document/prune.test.d.ts.map +0 -1
- package/dist/test/document/prune.test.js +0 -159
- package/dist/test/document/prune.test.js.map +0 -1
- package/dist/test/document/reducer.test.d.ts +0 -2
- package/dist/test/document/reducer.test.d.ts.map +0 -1
- package/dist/test/document/reducer.test.js +0 -284
- package/dist/test/document/reducer.test.js.map +0 -1
- package/dist/test/document/skip-operations.test.d.ts +0 -2
- package/dist/test/document/skip-operations.test.d.ts.map +0 -1
- package/dist/test/document/skip-operations.test.js +0 -495
- package/dist/test/document/skip-operations.test.js.map +0 -1
- package/dist/test/document/undo-redo-v2.test.d.ts +0 -2
- package/dist/test/document/undo-redo-v2.test.d.ts.map +0 -1
- package/dist/test/document/undo-redo-v2.test.js +0 -207
- package/dist/test/document/undo-redo-v2.test.js.map +0 -1
- package/dist/test/document/undo-redo.test.d.ts +0 -2
- package/dist/test/document/undo-redo.test.d.ts.map +0 -1
- package/dist/test/document/undo-redo.test.js +0 -413
- package/dist/test/document/undo-redo.test.js.map +0 -1
- package/dist/test/document/utils.test.d.ts +0 -2
- package/dist/test/document/utils.test.d.ts.map +0 -1
- package/dist/test/document/utils.test.js +0 -172
- package/dist/test/document/utils.test.js.map +0 -1
- package/dist/test/document-helpers/addUndo.test.d.ts +0 -2
- package/dist/test/document-helpers/addUndo.test.d.ts.map +0 -1
- package/dist/test/document-helpers/addUndo.test.js +0 -120
- package/dist/test/document-helpers/addUndo.test.js.map +0 -1
- package/dist/test/document-helpers/attachBranch.test.d.ts +0 -2
- package/dist/test/document-helpers/attachBranch.test.d.ts.map +0 -1
- package/dist/test/document-helpers/attachBranch.test.js +0 -364
- package/dist/test/document-helpers/attachBranch.test.js.map +0 -1
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +0 -2
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts.map +0 -1
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js +0 -252
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js.map +0 -1
- package/dist/test/document-helpers/conflictResolution.test.d.ts +0 -2
- package/dist/test/document-helpers/conflictResolution.test.d.ts.map +0 -1
- package/dist/test/document-helpers/conflictResolution.test.js +0 -109
- package/dist/test/document-helpers/conflictResolution.test.js.map +0 -1
- package/dist/test/document-helpers/filterDuplicatedOperations.test.d.ts +0 -2
- package/dist/test/document-helpers/filterDuplicatedOperations.test.d.ts.map +0 -1
- package/dist/test/document-helpers/filterDuplicatedOperations.test.js +0 -126
- package/dist/test/document-helpers/filterDuplicatedOperations.test.js.map +0 -1
- package/dist/test/document-helpers/garbageCollect.test.d.ts +0 -2
- package/dist/test/document-helpers/garbageCollect.test.d.ts.map +0 -1
- package/dist/test/document-helpers/garbageCollect.test.js +0 -136
- package/dist/test/document-helpers/garbageCollect.test.js.map +0 -1
- package/dist/test/document-helpers/groupOperationsByScope.test.d.ts +0 -2
- package/dist/test/document-helpers/groupOperationsByScope.test.d.ts.map +0 -1
- package/dist/test/document-helpers/groupOperationsByScope.test.js +0 -102
- package/dist/test/document-helpers/groupOperationsByScope.test.js.map +0 -1
- package/dist/test/document-helpers/headerRevision.test.d.ts +0 -2
- package/dist/test/document-helpers/headerRevision.test.d.ts.map +0 -1
- package/dist/test/document-helpers/headerRevision.test.js +0 -203
- package/dist/test/document-helpers/headerRevision.test.js.map +0 -1
- package/dist/test/document-helpers/merge.test.d.ts +0 -2
- package/dist/test/document-helpers/merge.test.d.ts.map +0 -1
- package/dist/test/document-helpers/merge.test.js +0 -906
- package/dist/test/document-helpers/merge.test.js.map +0 -1
- package/dist/test/document-helpers/nextSkipNumber.test.d.ts +0 -2
- package/dist/test/document-helpers/nextSkipNumber.test.d.ts.map +0 -1
- package/dist/test/document-helpers/nextSkipNumber.test.js +0 -135
- package/dist/test/document-helpers/nextSkipNumber.test.js.map +0 -1
- package/dist/test/document-helpers/prepareOperations.test.d.ts +0 -2
- package/dist/test/document-helpers/prepareOperations.test.d.ts.map +0 -1
- package/dist/test/document-helpers/prepareOperations.test.js +0 -304
- package/dist/test/document-helpers/prepareOperations.test.js.map +0 -1
- package/dist/test/document-helpers/removeExistingOperations.test.d.ts +0 -2
- package/dist/test/document-helpers/removeExistingOperations.test.d.ts.map +0 -1
- package/dist/test/document-helpers/removeExistingOperations.test.js +0 -177
- package/dist/test/document-helpers/removeExistingOperations.test.js.map +0 -1
- package/dist/test/document-helpers/reshuffleByTimestamp.test.d.ts +0 -2
- package/dist/test/document-helpers/reshuffleByTimestamp.test.d.ts.map +0 -1
- package/dist/test/document-helpers/reshuffleByTimestamp.test.js +0 -148
- package/dist/test/document-helpers/reshuffleByTimestamp.test.js.map +0 -1
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +0 -2
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts.map +0 -1
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js +0 -200
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js.map +0 -1
- package/dist/test/document-helpers/skipHeaderOperations.test.d.ts +0 -2
- package/dist/test/document-helpers/skipHeaderOperations.test.d.ts.map +0 -1
- package/dist/test/document-helpers/skipHeaderOperations.test.js +0 -72
- package/dist/test/document-helpers/skipHeaderOperations.test.js.map +0 -1
- package/dist/test/document-helpers/sortOperations.test.d.ts +0 -2
- package/dist/test/document-helpers/sortOperations.test.d.ts.map +0 -1
- package/dist/test/document-helpers/sortOperations.test.js +0 -101
- package/dist/test/document-helpers/sortOperations.test.js.map +0 -1
- package/dist/test/document-helpers/split.test.d.ts +0 -2
- package/dist/test/document-helpers/split.test.d.ts.map +0 -1
- package/dist/test/document-helpers/split.test.js +0 -121
- package/dist/test/document-helpers/split.test.js.map +0 -1
- package/dist/test/document-helpers/utils.d.ts +0 -15
- package/dist/test/document-helpers/utils.d.ts.map +0 -1
- package/dist/test/document-helpers/utils.js +0 -61
- package/dist/test/document-helpers/utils.js.map +0 -1
- package/dist/test/document-model/replay.test.d.ts +0 -2
- package/dist/test/document-model/replay.test.d.ts.map +0 -1
- package/dist/test/document-model/replay.test.js +0 -139
- package/dist/test/document-model/replay.test.js.map +0 -1
- package/dist/test/document-model/skip-operations.test.d.ts +0 -2
- package/dist/test/document-model/skip-operations.test.d.ts.map +0 -1
- package/dist/test/document-model/skip-operations.test.js +0 -214
- package/dist/test/document-model/skip-operations.test.js.map +0 -1
- package/dist/test/document-model/validation.test.d.ts +0 -2
- package/dist/test/document-model/validation.test.d.ts.map +0 -1
- package/dist/test/document-model/validation.test.js +0 -451
- package/dist/test/document-model/validation.test.js.map +0 -1
- package/dist/test/document-model/versioning.test.d.ts +0 -2
- package/dist/test/document-model/versioning.test.d.ts.map +0 -1
- package/dist/test/document-model/versioning.test.js +0 -93
- package/dist/test/document-model/versioning.test.js.map +0 -1
- package/dist/test/document-model/zip.test.d.ts +0 -2
- package/dist/test/document-model/zip.test.d.ts.map +0 -1
- package/dist/test/document-model/zip.test.js +0 -79
- package/dist/test/document-model/zip.test.js.map +0 -1
- package/dist/test/helpers.d.ts +0 -79
- package/dist/test/helpers.d.ts.map +0 -1
- package/dist/test/helpers.js +0 -121
- package/dist/test/helpers.js.map +0 -1
- package/dist/test/index.d.ts +0 -4
- package/dist/test/index.d.ts.map +0 -1
- package/dist/test/index.js +0 -3
- package/dist/test/index.js.map +0 -1
- package/dist/test/types.d.ts +0 -6
- package/dist/test/types.d.ts.map +0 -1
- package/dist/test/types.js +0 -2
- package/dist/test/types.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/vitest.config.d.ts +0 -3
- package/dist/vitest.config.d.ts.map +0 -1
- package/dist/vitest.config.js +0 -7
- package/dist/vitest.config.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-model",
|
|
3
|
-
"version": "6.0.2-staging.
|
|
3
|
+
"version": "6.0.2-staging.10",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"private": false,
|
|
6
6
|
"files": [
|
|
@@ -13,45 +13,49 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"./core": {
|
|
20
|
-
"import": "./dist/src/core/index.js",
|
|
21
|
-
"types": "./dist/src/core/index.d.ts"
|
|
16
|
+
"source": "./index.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
22
19
|
},
|
|
23
20
|
"./test": {
|
|
21
|
+
"source": "./test/index.ts",
|
|
24
22
|
"import": "./dist/test/index.js",
|
|
25
23
|
"types": "./dist/test/index.d.ts"
|
|
26
24
|
},
|
|
27
25
|
"./node": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
26
|
+
"source": "./node.mts",
|
|
27
|
+
"node": "./dist/node.mjs",
|
|
28
|
+
"types": "./dist/node.d.mts"
|
|
29
|
+
},
|
|
30
|
+
"./core": {
|
|
31
|
+
"source": "./index.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts"
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
|
-
"types": "./dist/src/index.d.ts",
|
|
33
36
|
"sideEffects": false,
|
|
34
37
|
"devDependencies": {
|
|
35
38
|
"@types/jest": "^29.5.14",
|
|
36
39
|
"@types/mime": "^4.0.0",
|
|
37
40
|
"@types/node": "25.2.3",
|
|
41
|
+
"change-case": "5.4.4",
|
|
38
42
|
"jest": "^30.0.5",
|
|
39
|
-
"
|
|
43
|
+
"mutative": "^1.0.5",
|
|
44
|
+
"tsdown": "0.21.1",
|
|
45
|
+
"tsx": "4.21.0",
|
|
46
|
+
"vitest": "4.1.1",
|
|
47
|
+
"zod": "4.3.6"
|
|
40
48
|
},
|
|
41
49
|
"dependencies": {
|
|
42
|
-
"change-case": "5.4.4",
|
|
43
50
|
"jszip": "^3.10.1",
|
|
44
51
|
"mime": "^4.0.4",
|
|
45
|
-
"
|
|
46
|
-
"safe-stable-stringify": "^2.4.3",
|
|
47
|
-
"sha1-uint8array": "^0.10.7",
|
|
48
|
-
"zod": "4.3.6",
|
|
49
|
-
"@powerhousedao/shared": "6.0.2-staging.1"
|
|
52
|
+
"@powerhousedao/shared": "6.0.2-staging.10"
|
|
50
53
|
},
|
|
51
54
|
"scripts": {
|
|
52
55
|
"tsc": "tsc",
|
|
53
56
|
"lint": "eslint",
|
|
54
57
|
"test": "vitest --run",
|
|
55
|
-
"test:watch": "vitest watch"
|
|
58
|
+
"test:watch": "vitest watch",
|
|
59
|
+
"build": "tsx ./build.ts"
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { Action, ActionContext, ActionSigner, AppActionSigner, Operation, PHBaseState, PHDocument, Signature, UserActionSigner } from "./ph-types.js";
|
|
2
|
-
import type { ActionSignatureContext, ActionSigningHandler, ActionVerificationHandler, LoadStateAction, NOOPAction, RedoAction, Reducer, SchemaPruneAction, UndoAction } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Context required to derive a deterministic operation ID.
|
|
5
|
-
*/
|
|
6
|
-
export type OperationContext = {
|
|
7
|
-
documentId: string;
|
|
8
|
-
scope: string;
|
|
9
|
-
branch: string;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Cancels the last `count` operations.
|
|
13
|
-
*
|
|
14
|
-
* @param count - Number of operations to cancel
|
|
15
|
-
* @category Actions
|
|
16
|
-
*/
|
|
17
|
-
export declare const undo: (count?: number, scope?: string) => UndoAction;
|
|
18
|
-
/**
|
|
19
|
-
* Cancels the last `count` {@link undo | UNDO} operations.
|
|
20
|
-
*
|
|
21
|
-
* @param count - Number of UNDO operations to cancel
|
|
22
|
-
* @category Actions
|
|
23
|
-
*/
|
|
24
|
-
export declare const redo: (count?: number, scope?: string) => RedoAction;
|
|
25
|
-
/**
|
|
26
|
-
* Joins multiple operations into a single {@link loadState | LOAD_STATE} operation.
|
|
27
|
-
*
|
|
28
|
-
* @remarks
|
|
29
|
-
* Useful to keep operations history smaller. Operations to prune are selected by index,
|
|
30
|
-
* similar to the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | slice} method in Arrays.
|
|
31
|
-
*
|
|
32
|
-
* @param start - Index of the first operation to prune
|
|
33
|
-
* @param end - Index of the last operation to prune
|
|
34
|
-
* @category Actions
|
|
35
|
-
*/
|
|
36
|
-
export declare const prune: (start?: number, end?: number, scope?: string) => SchemaPruneAction;
|
|
37
|
-
/**
|
|
38
|
-
* Replaces the state of the document.
|
|
39
|
-
*
|
|
40
|
-
* @remarks
|
|
41
|
-
* This action shouldn't be used directly. It is dispatched by the {@link prune} action.
|
|
42
|
-
*
|
|
43
|
-
* @param state - State to be set in the document.
|
|
44
|
-
* @param operations - Number of operations that were removed from the previous state.
|
|
45
|
-
* @category Actions
|
|
46
|
-
*/
|
|
47
|
-
export declare const loadState: <TState extends PHBaseState = PHBaseState>(state: TState & {
|
|
48
|
-
name: string;
|
|
49
|
-
}, operations: number) => LoadStateAction;
|
|
50
|
-
export declare const noop: (scope?: string) => NOOPAction;
|
|
51
|
-
/**
|
|
52
|
-
* Helper function to be used by action creators.
|
|
53
|
-
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* Creates an action with the given type and input properties. The input
|
|
56
|
-
* properties default to an empty object.
|
|
57
|
-
*
|
|
58
|
-
* @typeParam A - Type of the action to be returned.
|
|
59
|
-
*
|
|
60
|
-
* @param type - The type of the action.
|
|
61
|
-
* @param input - The input properties of the action.
|
|
62
|
-
* @param attachments - The attachments included in the action.
|
|
63
|
-
* @param validator - The validator to use for the input properties.
|
|
64
|
-
* @param scope - The scope of the action, can either be 'global' or 'local'.
|
|
65
|
-
* @param skip - The number of operations to skip before this new action is applied.
|
|
66
|
-
*
|
|
67
|
-
* @throws Error if the type is empty or not a string.
|
|
68
|
-
*
|
|
69
|
-
* @returns The new action.
|
|
70
|
-
*/
|
|
71
|
-
export declare function createAction<TAction extends Action>(type: TAction["type"], input?: TAction["input"], attachments?: TAction["attachments"], validator?: () => {
|
|
72
|
-
parse(v: unknown): TAction["input"];
|
|
73
|
-
}, scope?: Action["scope"]): TAction;
|
|
74
|
-
/**
|
|
75
|
-
* This function should be used instead of { ...action } to ensure
|
|
76
|
-
* that extra properties are not included in the action.
|
|
77
|
-
*/
|
|
78
|
-
export declare const actionFromAction: (action: Action) => Action;
|
|
79
|
-
export declare const operationFromAction: (action: Action, index: number, skip: number, context: OperationContext) => Operation;
|
|
80
|
-
export declare const operationFromOperation: (operation: Operation, index: number, skip: number, context: OperationContext) => Operation;
|
|
81
|
-
export declare const operationWithContext: (operation: Operation, context: ActionContext) => Operation;
|
|
82
|
-
export declare const actionContext: () => ActionContext;
|
|
83
|
-
export declare const actionSigner: (user: UserActionSigner, app: AppActionSigner, signatures?: Signature[]) => ActionSigner;
|
|
84
|
-
export declare function buildOperationSignature(context: ActionSignatureContext, signMethod: ActionSigningHandler): Promise<Signature>;
|
|
85
|
-
export declare function buildSignedAction<TState extends PHBaseState = PHBaseState>(action: Action, reducer: Reducer<TState>, document: PHDocument<TState>, signer: ActionSigner, signHandler: ActionSigningHandler): Promise<Operation>;
|
|
86
|
-
export declare function verifyOperationSignature(signature: Signature, signer: Omit<ActionSigner, "signatures">, verifyHandler: ActionVerificationHandler): Promise<boolean>;
|
|
87
|
-
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/core/actions.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,YAAY,EACZ,eAAe,EACf,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAOvB,OAAO,KAAK,EACV,sBAAsB,EACtB,oBAAoB,EACpB,yBAAyB,EACzB,eAAe,EACf,UAAU,EACV,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,UAAU,EACX,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,cAAS,EAAE,cAAgB,eAO7C,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,cAAS,EAAE,cAAgB,eAO7C,CAAC;AAEJ;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GA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AsB,uBAAuB,CAC3C,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,oBAAoB,GAC/B,OAAO,CAAC,SAAS,CAAC,CAKpB;AAED,wBAAsB,iBAAiB,CACrC,MAAM,SAAS,WAAW,GAAG,WAAW,EAExC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EACxB,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,EAC5B,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,oBAAoB,sBAkClC;AAED,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,EACxC,aAAa,EAAE,yBAAyB,oBAOzC"}
|
package/dist/src/core/actions.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { ZodError } from "zod";
|
|
2
|
-
import { ab2hex, buildOperationSignatureMessage, buildOperationSignatureParams, hex2ab, } from "./crypto.js";
|
|
3
|
-
import { InvalidActionInputError, InvalidActionInputZodError, } from "./errors.js";
|
|
4
|
-
import { LoadStateActionInputSchema, PruneActionInputSchema, RedoActionInputSchema, UndoActionInputSchema, } from "./schemas.js";
|
|
5
|
-
import { deriveOperationId, generateId } from "./utils.js";
|
|
6
|
-
/**
|
|
7
|
-
* Cancels the last `count` operations.
|
|
8
|
-
*
|
|
9
|
-
* @param count - Number of operations to cancel
|
|
10
|
-
* @category Actions
|
|
11
|
-
*/
|
|
12
|
-
export const undo = (count = 1, scope = "global") => createAction("UNDO", { count }, undefined, UndoActionInputSchema, scope);
|
|
13
|
-
/**
|
|
14
|
-
* Cancels the last `count` {@link undo | UNDO} operations.
|
|
15
|
-
*
|
|
16
|
-
* @param count - Number of UNDO operations to cancel
|
|
17
|
-
* @category Actions
|
|
18
|
-
*/
|
|
19
|
-
export const redo = (count = 1, scope = "global") => createAction("REDO", { count }, undefined, RedoActionInputSchema, scope);
|
|
20
|
-
/**
|
|
21
|
-
* Joins multiple operations into a single {@link loadState | LOAD_STATE} operation.
|
|
22
|
-
*
|
|
23
|
-
* @remarks
|
|
24
|
-
* Useful to keep operations history smaller. Operations to prune are selected by index,
|
|
25
|
-
* similar to the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | slice} method in Arrays.
|
|
26
|
-
*
|
|
27
|
-
* @param start - Index of the first operation to prune
|
|
28
|
-
* @param end - Index of the last operation to prune
|
|
29
|
-
* @category Actions
|
|
30
|
-
*/
|
|
31
|
-
export const prune = (start, end, scope = "global") => createAction("PRUNE", { start, end }, undefined, PruneActionInputSchema, scope);
|
|
32
|
-
/**
|
|
33
|
-
* Replaces the state of the document.
|
|
34
|
-
*
|
|
35
|
-
* @remarks
|
|
36
|
-
* This action shouldn't be used directly. It is dispatched by the {@link prune} action.
|
|
37
|
-
*
|
|
38
|
-
* @param state - State to be set in the document.
|
|
39
|
-
* @param operations - Number of operations that were removed from the previous state.
|
|
40
|
-
* @category Actions
|
|
41
|
-
*/
|
|
42
|
-
export const loadState = (state, operations) => createAction("LOAD_STATE", { state, operations }, undefined, LoadStateActionInputSchema);
|
|
43
|
-
export const noop = (scope = "global") => createAction("NOOP", {}, undefined, undefined, scope);
|
|
44
|
-
// TODO improve base actions type
|
|
45
|
-
/**
|
|
46
|
-
* Helper function to be used by action creators.
|
|
47
|
-
*
|
|
48
|
-
* @remarks
|
|
49
|
-
* Creates an action with the given type and input properties. The input
|
|
50
|
-
* properties default to an empty object.
|
|
51
|
-
*
|
|
52
|
-
* @typeParam A - Type of the action to be returned.
|
|
53
|
-
*
|
|
54
|
-
* @param type - The type of the action.
|
|
55
|
-
* @param input - The input properties of the action.
|
|
56
|
-
* @param attachments - The attachments included in the action.
|
|
57
|
-
* @param validator - The validator to use for the input properties.
|
|
58
|
-
* @param scope - The scope of the action, can either be 'global' or 'local'.
|
|
59
|
-
* @param skip - The number of operations to skip before this new action is applied.
|
|
60
|
-
*
|
|
61
|
-
* @throws Error if the type is empty or not a string.
|
|
62
|
-
*
|
|
63
|
-
* @returns The new action.
|
|
64
|
-
*/
|
|
65
|
-
export function createAction(type, input, attachments, validator, scope = "global") {
|
|
66
|
-
if (!type)
|
|
67
|
-
throw new Error("Empty action type");
|
|
68
|
-
if (typeof type !== "string")
|
|
69
|
-
throw new Error(`Invalid action type: ${JSON.stringify(type)}`);
|
|
70
|
-
const action = {
|
|
71
|
-
id: generateId(),
|
|
72
|
-
timestampUtcMs: new Date().toISOString(),
|
|
73
|
-
type,
|
|
74
|
-
input,
|
|
75
|
-
scope,
|
|
76
|
-
};
|
|
77
|
-
if (attachments)
|
|
78
|
-
action.attachments = attachments;
|
|
79
|
-
try {
|
|
80
|
-
validator?.().parse(action.input);
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
if (error instanceof ZodError) {
|
|
84
|
-
throw new InvalidActionInputZodError(error.issues);
|
|
85
|
-
}
|
|
86
|
-
throw new InvalidActionInputError(error);
|
|
87
|
-
}
|
|
88
|
-
return action;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* This function should be used instead of { ...action } to ensure
|
|
92
|
-
* that extra properties are not included in the action.
|
|
93
|
-
*/
|
|
94
|
-
export const actionFromAction = (action) => {
|
|
95
|
-
return {
|
|
96
|
-
id: action.id,
|
|
97
|
-
timestampUtcMs: action.timestampUtcMs,
|
|
98
|
-
type: action.type,
|
|
99
|
-
input: action.input,
|
|
100
|
-
scope: action.scope,
|
|
101
|
-
context: action.context,
|
|
102
|
-
attachments: action.attachments,
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
export const operationFromAction = (action, index, skip, context) => {
|
|
106
|
-
return {
|
|
107
|
-
...action,
|
|
108
|
-
action,
|
|
109
|
-
id: deriveOperationId(context.documentId, context.scope, context.branch, action.id),
|
|
110
|
-
timestampUtcMs: action.timestampUtcMs,
|
|
111
|
-
hash: "",
|
|
112
|
-
error: undefined,
|
|
113
|
-
index,
|
|
114
|
-
skip,
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
export const operationFromOperation = (operation, index, skip, context) => {
|
|
118
|
-
const id = deriveOperationId(context.documentId, context.scope, context.branch, operation.action.id);
|
|
119
|
-
return {
|
|
120
|
-
...operation,
|
|
121
|
-
hash: "",
|
|
122
|
-
error: undefined,
|
|
123
|
-
index,
|
|
124
|
-
skip,
|
|
125
|
-
id,
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
export const operationWithContext = (operation, context) => {
|
|
129
|
-
if (!operation.action) {
|
|
130
|
-
throw new Error("Operation has no action");
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
...operation,
|
|
134
|
-
action: {
|
|
135
|
-
...operation.action,
|
|
136
|
-
context,
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
export const actionContext = () => ({});
|
|
141
|
-
export const actionSigner = (user, app, signatures = []) => ({
|
|
142
|
-
user,
|
|
143
|
-
app,
|
|
144
|
-
signatures,
|
|
145
|
-
});
|
|
146
|
-
export async function buildOperationSignature(context, signMethod) {
|
|
147
|
-
const params = buildOperationSignatureParams(context);
|
|
148
|
-
const message = buildOperationSignatureMessage(params);
|
|
149
|
-
const signature = await signMethod(message);
|
|
150
|
-
return [...params, `0x${ab2hex(signature)}`];
|
|
151
|
-
}
|
|
152
|
-
export async function buildSignedAction(action, reducer, document, signer, signHandler) {
|
|
153
|
-
const result = reducer(document, action, undefined, {
|
|
154
|
-
//reuseHash: true,
|
|
155
|
-
reuseOperationResultingState: true,
|
|
156
|
-
});
|
|
157
|
-
const scopeOperations = result.operations[action.scope];
|
|
158
|
-
if (!scopeOperations) {
|
|
159
|
-
throw new Error(`No operations found for scope: ${action.scope}`);
|
|
160
|
-
}
|
|
161
|
-
const operation = scopeOperations.at(-1);
|
|
162
|
-
if (!operation) {
|
|
163
|
-
throw new Error("Action was not applied");
|
|
164
|
-
}
|
|
165
|
-
const previousStateHash = scopeOperations.at(-2)?.hash ?? "";
|
|
166
|
-
const signature = await buildOperationSignature({
|
|
167
|
-
documentId: document.header.id,
|
|
168
|
-
signer,
|
|
169
|
-
action,
|
|
170
|
-
previousStateHash,
|
|
171
|
-
}, signHandler);
|
|
172
|
-
const actionContext = {
|
|
173
|
-
signer: actionSigner(signer.user, signer.app, [
|
|
174
|
-
...signer.signatures,
|
|
175
|
-
signature,
|
|
176
|
-
]),
|
|
177
|
-
};
|
|
178
|
-
return operationWithContext(operation, actionContext);
|
|
179
|
-
}
|
|
180
|
-
export async function verifyOperationSignature(signature, signer, verifyHandler) {
|
|
181
|
-
const publicKey = signer.app.key;
|
|
182
|
-
const params = signature.slice(0, 4);
|
|
183
|
-
const signatureBytes = hex2ab(signature[4]);
|
|
184
|
-
const expectedMessage = buildOperationSignatureMessage(params);
|
|
185
|
-
return verifyHandler(publicKey, signatureBytes, expectedMessage);
|
|
186
|
-
}
|
|
187
|
-
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../src/core/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EACL,MAAM,EACN,8BAA8B,EAC9B,6BAA6B,EAC7B,MAAM,GACP,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAYrB,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAYtB,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAW3D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,EAAE,EAAE,CAClD,YAAY,CACV,MAAM,EACN,EAAE,KAAK,EAAE,EACT,SAAS,EACT,qBAAq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EACxC,aAAwC;IAExC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;IACjC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAqC,CAAC;IACzE,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,eAAe,GAAG,8BAA8B,CAAC,MAAM,CAAC,CAAC;IAC/D,OAAO,aAAa,CAAC,SAAS,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { DocumentModelModule } from "@powerhousedao/shared/document-model";
|
|
2
|
-
import type { Action, DocumentOperations, Operation, PHBaseState, PHDocument, PHDocumentHeader } from "./ph-types.js";
|
|
3
|
-
import type { DocumentAction } from "./types.js";
|
|
4
|
-
type ScreamingSnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Lowercase<Head>}${Capitalize<ScreamingSnakeToCamel<Tail>>}` : Lowercase<S>;
|
|
5
|
-
export type DocumentChangeEvent<TState extends PHBaseState = PHBaseState> = {
|
|
6
|
-
document: PHDocument<TState>;
|
|
7
|
-
};
|
|
8
|
-
export type DocumentChangeListener<TState extends PHBaseState = PHBaseState> = (event: DocumentChangeEvent<TState>) => void;
|
|
9
|
-
export type ActionMap<TAction extends Action, TReturn = void> = {
|
|
10
|
-
[K in (TAction | DocumentAction)["type"] as ScreamingSnakeToCamel<K>]: (input: Extract<TAction | DocumentAction, {
|
|
11
|
-
type: K;
|
|
12
|
-
}>["input"]) => TReturn & ActionMap<TAction, TReturn>;
|
|
13
|
-
};
|
|
14
|
-
export declare class PHDocumentController<TState extends PHBaseState> implements PHDocument<TState> {
|
|
15
|
-
readonly module: DocumentModelModule<TState>;
|
|
16
|
-
protected _document: PHDocument<TState>;
|
|
17
|
-
private listeners;
|
|
18
|
-
constructor(module: DocumentModelModule<TState>, initialDocument?: PHDocument<TState>);
|
|
19
|
-
get document(): PHDocument<TState>;
|
|
20
|
-
get header(): PHDocumentHeader;
|
|
21
|
-
get state(): TState;
|
|
22
|
-
get initialState(): TState;
|
|
23
|
-
get operations(): DocumentOperations;
|
|
24
|
-
get clipboard(): Operation[];
|
|
25
|
-
onChange(listener: DocumentChangeListener<TState>): () => void;
|
|
26
|
-
private notifyListeners;
|
|
27
|
-
static forDocumentModel<TState extends PHBaseState, TAction extends Action>(module: DocumentModelModule<TState>): new (initialDocument?: PHDocument<TState>) => PHDocumentController<TState> & ActionMap<TAction, PHDocumentController<TState>>;
|
|
28
|
-
}
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/core/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,KAAK,EACV,MAAM,EACN,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,UAAU,EACV,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,KAAK,qBAAqB,CAAC,CAAC,SAAS,MAAM,IACzC,CAAC,SAAS,GAAG,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE,GACnC,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,EAAE,GAC9D,SAAS,CAAC,CAAC,CAAC,CAAC;AAEnB,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,IAAI;IAC1E,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,IAAI,CAC7E,KAAK,EAAE,mB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Ae,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,KACjC,oBAAoB,CAAC,MAAM,CAAC,GAC/B,SAAS,CAAC,OAAO,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;CAErD"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export class PHDocumentController {
|
|
2
|
-
module;
|
|
3
|
-
_document;
|
|
4
|
-
listeners = [];
|
|
5
|
-
constructor(module, initialDocument) {
|
|
6
|
-
this.module = module;
|
|
7
|
-
this._document = initialDocument ?? module.utils.createDocument();
|
|
8
|
-
// dynamically add action methods to the controller
|
|
9
|
-
for (const actionType in this.module.actions) {
|
|
10
|
-
Object.defineProperty(this, actionType, {
|
|
11
|
-
value: (input) => {
|
|
12
|
-
const action = this.module.actions[actionType](input);
|
|
13
|
-
this._document = this.module.reducer(this._document, action);
|
|
14
|
-
this.notifyListeners();
|
|
15
|
-
return this;
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
get document() {
|
|
21
|
-
return this._document;
|
|
22
|
-
}
|
|
23
|
-
get header() {
|
|
24
|
-
return this.document.header;
|
|
25
|
-
}
|
|
26
|
-
get state() {
|
|
27
|
-
return this.document.state;
|
|
28
|
-
}
|
|
29
|
-
get initialState() {
|
|
30
|
-
return this.document.initialState;
|
|
31
|
-
}
|
|
32
|
-
get operations() {
|
|
33
|
-
return this.document.operations;
|
|
34
|
-
}
|
|
35
|
-
get clipboard() {
|
|
36
|
-
return this.document.clipboard;
|
|
37
|
-
}
|
|
38
|
-
onChange(listener) {
|
|
39
|
-
this.listeners.push(listener);
|
|
40
|
-
return () => {
|
|
41
|
-
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
notifyListeners() {
|
|
45
|
-
if (this.listeners.length === 0)
|
|
46
|
-
return;
|
|
47
|
-
const event = { document: this._document };
|
|
48
|
-
for (const listener of this.listeners) {
|
|
49
|
-
listener(event);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
static forDocumentModel(module) {
|
|
53
|
-
return class extends PHDocumentController {
|
|
54
|
-
constructor(initialDocument) {
|
|
55
|
-
super(module, initialDocument);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=controller.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/core/controller.ts"],"names":[],"mappings":"AA8BA,MAAM,OAAO,oBAAoB;IAGtB,MAAM,CAA8B;IACnC,SAAS,CAAqB;IAChC,SAAS,GAAqC,EAAE,CAAC;IAEzD,YACE,MAAmC,EACnC,eAAoC;QAEpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,eAAe,IAAI,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;QAElE,mDAAmD;QACnD,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC7C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE;gBACtC,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;oBACxB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC;oBACtD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;oBAC7D,IAAI,CAAC,eAAe,EAAE,CAAC;oBACvB,OAAO,IAAI,CAAC;gBACd,CAAC;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IACD,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;IAC7B,CAAC;IACD,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IACpC,CAAC;IACD,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;IAClC,CAAC;IACD,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;IACjC,CAAC;IAED,QAAQ,CAAC,QAAwC;QAC/C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC;QAChE,CAAC,CAAC;IACJ,CAAC;IAEO,eAAe;QACrB,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QACxC,MAAM,KAAK,GAAgC,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;QACxE,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,gBAAgB,CACrB,MAAmC;QAEnC,OAAO,KAAM,SAAQ,oBAA4B;YAC/C,YAAY,eAAoC;gBAC9C,KAAK,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;YACjC,CAAC;SAI+C,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ActionSignatureContext } from "./types.js";
|
|
2
|
-
export declare const hashBrowser: (data: string | Uint8Array | ArrayBufferView | DataView, algorithm?: string, encoding?: string, _params?: Record<string, unknown>) => string;
|
|
3
|
-
export declare function getUnixTimestamp(date: Date | string): string;
|
|
4
|
-
export declare function buildOperationSignatureParams({ documentId, signer, action, previousStateHash, }: ActionSignatureContext): [string, string, string, string];
|
|
5
|
-
export declare function buildOperationSignatureMessage(params: [string, string, string, string]): Uint8Array;
|
|
6
|
-
export declare function ab2hex(ab: ArrayBuffer | ArrayBufferView): string;
|
|
7
|
-
export declare function hex2ab(hex: string): Uint8Array<ArrayBuffer>;
|
|
8
|
-
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/core/crypto.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,eAAO,MAAM,WAAW,GACtB,MAAM,MAAM,GAAG,UAAU,GAAG,eAAe,GAAG,QAAQ,EACtD,kBAAkB,EAClB,iBAAmB,EACnB,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAqBlC,CAAC;AAgCF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAE5D;AAED,wBAAgB,6BAA6B,CAAC,EAC5C,UAAU,EACV,MAAM,EACN,MAAM,EACN,iBAAiB,GAClB,EAAE,sBAAsB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAU3D;AAID,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GACvC,UAAU,CAIZ;AAED,wBAAgB,MAAM,CAAC,EAAE,EAAE,WAAW,GAAG,eAAe,GAAG,MAAM,CAKhE;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,2BAMjC"}
|
package/dist/src/core/crypto.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import stringifyJson from "safe-stable-stringify";
|
|
2
|
-
import { createHash as createSha1Hash } from "sha1-uint8array";
|
|
3
|
-
export const hashBrowser = (data, algorithm = "sha1", encoding = "base64", _params) => {
|
|
4
|
-
if (!["sha1"].includes(algorithm)) {
|
|
5
|
-
throw new Error(`Hashing algorithm not supported: "${algorithm}". Available: sha1`);
|
|
6
|
-
}
|
|
7
|
-
if (!["base64", "hex"].includes(encoding)) {
|
|
8
|
-
throw new Error(`Hash encoding not supported: "${encoding}". Available: base64, hex`);
|
|
9
|
-
}
|
|
10
|
-
const hash = hashUIntArray(data, algorithm);
|
|
11
|
-
if (encoding === "hex") {
|
|
12
|
-
return uint8ArrayToHex(hash);
|
|
13
|
-
}
|
|
14
|
-
return uint8ArrayToBase64(hash);
|
|
15
|
-
};
|
|
16
|
-
function uint8ArrayToBase64(uint8Array) {
|
|
17
|
-
// Convert the Uint8Array to a binary string
|
|
18
|
-
let binaryString = "";
|
|
19
|
-
for (let i = 0; i < uint8Array.length; i++) {
|
|
20
|
-
binaryString += String.fromCharCode(uint8Array[i]);
|
|
21
|
-
}
|
|
22
|
-
// Encode the binary string to base64
|
|
23
|
-
const base64String = btoa(binaryString);
|
|
24
|
-
return base64String;
|
|
25
|
-
}
|
|
26
|
-
function uint8ArrayToHex(uint8Array) {
|
|
27
|
-
return Array.from(uint8Array)
|
|
28
|
-
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
29
|
-
.join("");
|
|
30
|
-
}
|
|
31
|
-
function hashUIntArray(data, algorithm = "sha1") {
|
|
32
|
-
if (!["sha1"].includes(algorithm)) {
|
|
33
|
-
throw new Error("Hashing algorithm not supported: Available: sha1");
|
|
34
|
-
}
|
|
35
|
-
return createSha1Hash("sha1")
|
|
36
|
-
.update(data)
|
|
37
|
-
.digest();
|
|
38
|
-
}
|
|
39
|
-
export function getUnixTimestamp(date) {
|
|
40
|
-
return (new Date(date).getTime() / 1000).toFixed(0);
|
|
41
|
-
}
|
|
42
|
-
export function buildOperationSignatureParams({ documentId, signer, action, previousStateHash, }) {
|
|
43
|
-
const { /*id, timestamp,*/ scope, type } = action;
|
|
44
|
-
return [
|
|
45
|
-
/*getUnixTimestamp(timestamp)*/ getUnixTimestamp(new Date()),
|
|
46
|
-
signer.app.key,
|
|
47
|
-
hashBrowser([documentId, scope, /*id,*/ type, stringifyJson(action.input)].join("")),
|
|
48
|
-
previousStateHash,
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
const textEncode = new TextEncoder();
|
|
52
|
-
export function buildOperationSignatureMessage(params) {
|
|
53
|
-
const message = params.join("");
|
|
54
|
-
const prefix = "\x19Signed Operation:\n" + message.length.toString();
|
|
55
|
-
return textEncode.encode(prefix + message);
|
|
56
|
-
}
|
|
57
|
-
export function ab2hex(ab) {
|
|
58
|
-
const view = ArrayBuffer.isView(ab) ? ab : new Uint8Array(ab);
|
|
59
|
-
return Array.prototype.map
|
|
60
|
-
.call(view, (x) => ("00" + x.toString(16)).slice(-2))
|
|
61
|
-
.join("");
|
|
62
|
-
}
|
|
63
|
-
export function hex2ab(hex) {
|
|
64
|
-
return new Uint8Array(hex.match(/[\da-f]{2}/gi)?.map(function (h) {
|
|
65
|
-
return parseInt(h, 16);
|
|
66
|
-
}) ?? []);
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=crypto.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/core/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAG/D,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAsD,EACtD,SAAS,GAAG,MAAM,EAClB,QAAQ,GAAG,QAAQ,EACnB,OAAiC,EACjC,EAAE;IACF,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,qCAAqC,SAAS,oBAAoB,CACn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