document-model 4.1.0-dev.1 → 4.1.0-dev.100
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/README.md +24 -24
- package/dist/src/core/actions.d.ts +79 -0
- package/dist/src/core/actions.d.ts.map +1 -0
- package/dist/src/core/actions.js +183 -0
- package/dist/src/core/actions.js.map +1 -0
- package/dist/src/core/crypto.d.ts +17 -0
- package/dist/src/core/crypto.d.ts.map +1 -0
- package/dist/src/core/crypto.js +87 -0
- package/dist/src/core/crypto.js.map +1 -0
- package/dist/src/core/documents.d.ts +128 -0
- package/dist/src/core/documents.d.ts.map +1 -0
- package/dist/src/{document/utils/document-helpers.js → core/documents.js} +364 -26
- package/dist/src/core/documents.js.map +1 -0
- package/dist/src/core/errors.d.ts +21 -0
- package/dist/src/core/errors.d.ts.map +1 -0
- package/dist/src/core/errors.js +47 -0
- package/dist/src/core/errors.js.map +1 -0
- package/dist/src/core/files.d.ts +14 -0
- package/dist/src/core/files.d.ts.map +1 -0
- package/dist/src/core/files.js +74 -0
- package/dist/src/core/files.js.map +1 -0
- package/dist/src/{document/utils → core}/header.d.ts +3 -35
- package/dist/src/core/header.d.ts.map +1 -0
- package/dist/src/{document/utils → core}/header.js +6 -19
- package/dist/src/core/header.js.map +1 -0
- package/dist/src/core/index.d.ts +12 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +12 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/{document/utils/file.d.ts → core/node.d.ts} +40 -29
- package/dist/src/core/node.d.ts.map +1 -0
- package/dist/src/core/node.js +149 -0
- package/dist/src/core/node.js.map +1 -0
- package/dist/src/core/operations.d.ts +32 -0
- package/dist/src/core/operations.d.ts.map +1 -0
- package/dist/src/{document/actions → core}/operations.js +11 -59
- package/dist/src/core/operations.js.map +1 -0
- package/dist/src/core/ph-types.d.ts +259 -0
- package/dist/src/core/ph-types.d.ts.map +1 -0
- package/dist/src/core/ph-types.js +15 -0
- package/dist/src/core/ph-types.js.map +1 -0
- package/dist/src/core/reducer.d.ts +61 -0
- package/dist/src/core/reducer.d.ts.map +1 -0
- package/dist/src/core/reducer.js +416 -0
- package/dist/src/core/reducer.js.map +1 -0
- package/dist/src/{document/schema/zod.d.ts → core/schemas.d.ts} +50 -24
- package/dist/src/core/schemas.d.ts.map +1 -0
- package/dist/src/{document/schema/zod.js → core/schemas.js} +24 -27
- package/dist/src/core/schemas.js.map +1 -0
- package/dist/src/core/state.d.ts +26 -0
- package/dist/src/core/state.d.ts.map +1 -0
- package/dist/src/core/state.js +56 -0
- package/dist/src/core/state.js.map +1 -0
- package/dist/src/core/types.d.ts +500 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/{document → core}/types.js.map +1 -1
- package/dist/src/core/validation.d.ts +4 -0
- package/dist/src/core/validation.d.ts.map +1 -0
- package/dist/src/{document/utils → core}/validation.js +6 -2
- package/dist/src/core/validation.js.map +1 -0
- package/dist/src/document-model/actions.d.ts +158 -0
- package/dist/src/document-model/actions.d.ts.map +1 -0
- package/dist/src/document-model/actions.js +109 -0
- package/dist/src/document-model/actions.js.map +1 -0
- package/dist/src/document-model/constants.d.ts +7 -0
- package/dist/src/document-model/constants.d.ts.map +1 -0
- package/dist/src/document-model/{gen/document-model.js → constants.js} +171 -139
- package/dist/src/document-model/constants.js.map +1 -0
- package/dist/src/document-model/files.d.ts +5 -0
- package/dist/src/document-model/files.d.ts.map +1 -0
- package/dist/src/document-model/files.js +9 -0
- package/dist/src/document-model/files.js.map +1 -0
- package/dist/src/document-model/index.d.ts +9 -0
- package/dist/src/document-model/index.d.ts.map +1 -0
- package/dist/src/document-model/index.js +9 -0
- package/dist/src/document-model/index.js.map +1 -0
- package/dist/src/document-model/module.d.ts +1 -1
- package/dist/src/document-model/module.d.ts.map +1 -1
- package/dist/src/document-model/module.js +17 -10
- package/dist/src/document-model/module.js.map +1 -1
- package/dist/src/document-model/reducers.d.ts +11 -0
- package/dist/src/document-model/reducers.d.ts.map +1 -0
- package/dist/src/document-model/reducers.js +588 -0
- package/dist/src/document-model/reducers.js.map +1 -0
- package/dist/src/document-model/schemas.d.ts +449 -0
- package/dist/src/document-model/schemas.d.ts.map +1 -0
- package/dist/src/document-model/{gen/schema/zod.js → schemas.js} +9 -15
- package/dist/src/document-model/schemas.js.map +1 -0
- package/dist/src/document-model/state.d.ts +11 -0
- package/dist/src/document-model/state.d.ts.map +1 -0
- package/dist/src/document-model/state.js +61 -0
- package/dist/src/document-model/state.js.map +1 -0
- package/dist/src/document-model/types.d.ts +671 -3
- package/dist/src/document-model/types.d.ts.map +1 -1
- package/dist/src/document-model/validation.d.ts +7 -0
- package/dist/src/document-model/validation.d.ts.map +1 -0
- package/dist/src/document-model/{custom/utils.js → validation.js} +1 -1
- package/dist/src/document-model/validation.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/test/document/crypto.test.js +39 -61
- package/dist/test/document/crypto.test.js.map +1 -1
- package/dist/test/document/event-vs-command.test.js +81 -51
- package/dist/test/document/event-vs-command.test.js.map +1 -1
- package/dist/test/document/local.test.js +27 -45
- package/dist/test/document/local.test.js.map +1 -1
- package/dist/test/document/operation-id.test.js +4 -7
- package/dist/test/document/operation-id.test.js.map +1 -1
- package/dist/test/document/prune.test.js +23 -36
- package/dist/test/document/prune.test.js.map +1 -1
- package/dist/test/document/reducer.test.js +101 -81
- package/dist/test/document/reducer.test.js.map +1 -1
- package/dist/test/document/skip-operations.test.js +67 -87
- package/dist/test/document/skip-operations.test.js.map +1 -1
- package/dist/test/document/undo-redo.test.js +64 -40
- package/dist/test/document/undo-redo.test.js.map +1 -1
- package/dist/test/document/utils.test.js +51 -41
- package/dist/test/document/utils.test.js.map +1 -1
- package/dist/test/document-helpers/addUndo.test.js +2 -2
- package/dist/test/document-helpers/addUndo.test.js.map +1 -1
- package/dist/test/document-helpers/attachBranch.test.js +21 -21
- package/dist/test/document-helpers/attachBranch.test.js.map +1 -1
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js +1 -1
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js.map +1 -1
- package/dist/test/document-helpers/conflictResolution.test.js +11 -11
- package/dist/test/document-helpers/conflictResolution.test.js.map +1 -1
- package/dist/test/document-helpers/filterDuplicatedOperations.test.js +1 -1
- package/dist/test/document-helpers/filterDuplicatedOperations.test.js.map +1 -1
- package/dist/test/document-helpers/garbageCollect.test.js +1 -1
- package/dist/test/document-helpers/garbageCollect.test.js.map +1 -1
- package/dist/test/document-helpers/groupOperationsByScope.test.js +71 -71
- package/dist/test/document-helpers/groupOperationsByScope.test.js.map +1 -1
- package/dist/test/document-helpers/merge.test.js +126 -126
- package/dist/test/document-helpers/merge.test.js.map +1 -1
- package/dist/test/document-helpers/nextSkipNumber.test.js +1 -1
- package/dist/test/document-helpers/nextSkipNumber.test.js.map +1 -1
- package/dist/test/document-helpers/prepareOperations.test.js +1 -1
- package/dist/test/document-helpers/prepareOperations.test.js.map +1 -1
- package/dist/test/document-helpers/removeExistingOperations.test.js +38 -26
- package/dist/test/document-helpers/removeExistingOperations.test.js.map +1 -1
- package/dist/test/document-helpers/reshuffleByTimestamp.test.js +16 -16
- package/dist/test/document-helpers/reshuffleByTimestamp.test.js.map +1 -1
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js +22 -22
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js.map +1 -1
- package/dist/test/document-helpers/skipHeaderOperations.test.js +34 -41
- package/dist/test/document-helpers/skipHeaderOperations.test.js.map +1 -1
- package/dist/test/document-helpers/sortOperations.test.js +1 -1
- package/dist/test/document-helpers/sortOperations.test.js.map +1 -1
- package/dist/test/document-helpers/split.test.js +3 -3
- package/dist/test/document-helpers/split.test.js.map +1 -1
- package/dist/test/document-helpers/utils.d.ts +2 -1
- package/dist/test/document-helpers/utils.d.ts.map +1 -1
- package/dist/test/document-helpers/utils.js +13 -8
- package/dist/test/document-helpers/utils.js.map +1 -1
- package/dist/test/document-model/replay.test.js +21 -25
- package/dist/test/document-model/replay.test.js.map +1 -1
- package/dist/test/document-model/skip-operations.test.js +93 -96
- package/dist/test/document-model/skip-operations.test.js.map +1 -1
- package/dist/test/document-model/validation.test.js +10 -13
- package/dist/test/document-model/validation.test.js.map +1 -1
- package/dist/test/document-model/zip.test.js +20 -21
- package/dist/test/document-model/zip.test.js.map +1 -1
- package/dist/test/helpers.d.ts +59 -13
- package/dist/test/helpers.d.ts.map +1 -1
- package/dist/test/helpers.js +58 -11
- package/dist/test/helpers.js.map +1 -1
- package/dist/test/index.d.ts +4 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +3 -0
- package/dist/test/index.js.map +1 -0
- package/dist/test/types.d.ts +6 -0
- package/dist/test/types.d.ts.map +1 -0
- package/dist/{src/document/schema → test}/types.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/vitest.config.d.ts +1 -1
- package/dist/vitest.config.d.ts.map +1 -1
- package/dist/vitest.config.js +2 -8
- package/dist/vitest.config.js.map +1 -1
- package/package.json +27 -21
- package/dist/index.d.ts +0 -20
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -14
- package/dist/index.js.map +0 -1
- package/dist/src/document/actions/creators.d.ts +0 -51
- package/dist/src/document/actions/creators.d.ts.map +0 -1
- package/dist/src/document/actions/creators.js +0 -57
- package/dist/src/document/actions/creators.js.map +0 -1
- package/dist/src/document/actions/operations.d.ts +0 -36
- package/dist/src/document/actions/operations.d.ts.map +0 -1
- package/dist/src/document/actions/operations.js.map +0 -1
- package/dist/src/document/actions/types.d.ts +0 -16
- package/dist/src/document/actions/types.d.ts.map +0 -1
- package/dist/src/document/actions/types.js +0 -7
- package/dist/src/document/actions/types.js.map +0 -1
- package/dist/src/document/object.d.ts +0 -124
- package/dist/src/document/object.d.ts.map +0 -1
- package/dist/src/document/object.js +0 -183
- package/dist/src/document/object.js.map +0 -1
- package/dist/src/document/ph-types.d.ts +0 -68
- package/dist/src/document/ph-types.d.ts.map +0 -1
- package/dist/src/document/ph-types.js +0 -2
- package/dist/src/document/ph-types.js.map +0 -1
- package/dist/src/document/reducer.d.ts +0 -49
- package/dist/src/document/reducer.d.ts.map +0 -1
- package/dist/src/document/reducer.js +0 -346
- package/dist/src/document/reducer.js.map +0 -1
- package/dist/src/document/schema/types.d.ts +0 -177
- package/dist/src/document/schema/types.d.ts.map +0 -1
- package/dist/src/document/schema/types.js +0 -2
- package/dist/src/document/schema/zod.d.ts.map +0 -1
- package/dist/src/document/schema/zod.js.map +0 -1
- package/dist/src/document/signal.d.ts +0 -36
- package/dist/src/document/signal.d.ts.map +0 -1
- package/dist/src/document/signal.js +0 -2
- package/dist/src/document/signal.js.map +0 -1
- package/dist/src/document/types.d.ts +0 -336
- package/dist/src/document/types.d.ts.map +0 -1
- package/dist/src/document/types.js +0 -2
- package/dist/src/document/utils/base.d.ts +0 -88
- package/dist/src/document/utils/base.d.ts.map +0 -1
- package/dist/src/document/utils/base.js +0 -335
- package/dist/src/document/utils/base.js.map +0 -1
- package/dist/src/document/utils/browser.d.ts +0 -18
- package/dist/src/document/utils/browser.d.ts.map +0 -1
- package/dist/src/document/utils/browser.js +0 -54
- package/dist/src/document/utils/browser.js.map +0 -1
- package/dist/src/document/utils/crypto.d.ts +0 -11
- package/dist/src/document/utils/crypto.d.ts.map +0 -1
- package/dist/src/document/utils/crypto.js +0 -80
- package/dist/src/document/utils/crypto.js.map +0 -1
- package/dist/src/document/utils/document-helpers.d.ts +0 -78
- package/dist/src/document/utils/document-helpers.d.ts.map +0 -1
- package/dist/src/document/utils/document-helpers.js.map +0 -1
- package/dist/src/document/utils/errors.d.ts +0 -10
- package/dist/src/document/utils/errors.d.ts.map +0 -1
- package/dist/src/document/utils/errors.js +0 -19
- package/dist/src/document/utils/errors.js.map +0 -1
- package/dist/src/document/utils/file.d.ts.map +0 -1
- package/dist/src/document/utils/file.js +0 -152
- package/dist/src/document/utils/file.js.map +0 -1
- package/dist/src/document/utils/header.d.ts.map +0 -1
- package/dist/src/document/utils/header.js.map +0 -1
- package/dist/src/document/utils/node.d.ts +0 -18
- package/dist/src/document/utils/node.d.ts.map +0 -1
- package/dist/src/document/utils/node.js +0 -62
- package/dist/src/document/utils/node.js.map +0 -1
- package/dist/src/document/utils/validation.d.ts +0 -3
- package/dist/src/document/utils/validation.d.ts.map +0 -1
- package/dist/src/document/utils/validation.js.map +0 -1
- package/dist/src/document-model/custom/reducers/header.d.ts +0 -3
- package/dist/src/document-model/custom/reducers/header.d.ts.map +0 -1
- package/dist/src/document-model/custom/reducers/header.js +0 -23
- package/dist/src/document-model/custom/reducers/header.js.map +0 -1
- package/dist/src/document-model/custom/reducers/module.d.ts +0 -3
- package/dist/src/document-model/custom/reducers/module.d.ts.map +0 -1
- package/dist/src/document-model/custom/reducers/module.js +0 -41
- package/dist/src/document-model/custom/reducers/module.js.map +0 -1
- package/dist/src/document-model/custom/reducers/operation-error.d.ts +0 -3
- package/dist/src/document-model/custom/reducers/operation-error.d.ts.map +0 -1
- package/dist/src/document-model/custom/reducers/operation-error.js +0 -94
- package/dist/src/document-model/custom/reducers/operation-error.js.map +0 -1
- package/dist/src/document-model/custom/reducers/operation-example.d.ts +0 -3
- package/dist/src/document-model/custom/reducers/operation-example.d.ts.map +0 -1
- package/dist/src/document-model/custom/reducers/operation-example.js +0 -53
- package/dist/src/document-model/custom/reducers/operation-example.js.map +0 -1
- package/dist/src/document-model/custom/reducers/operation.d.ts +0 -3
- package/dist/src/document-model/custom/reducers/operation.d.ts.map +0 -1
- package/dist/src/document-model/custom/reducers/operation.js +0 -125
- package/dist/src/document-model/custom/reducers/operation.js.map +0 -1
- package/dist/src/document-model/custom/reducers/state.d.ts +0 -3
- package/dist/src/document-model/custom/reducers/state.d.ts.map +0 -1
- package/dist/src/document-model/custom/reducers/state.js +0 -71
- package/dist/src/document-model/custom/reducers/state.js.map +0 -1
- package/dist/src/document-model/custom/reducers/versioning.d.ts +0 -8
- package/dist/src/document-model/custom/reducers/versioning.d.ts.map +0 -1
- package/dist/src/document-model/custom/reducers/versioning.js +0 -23
- package/dist/src/document-model/custom/reducers/versioning.js.map +0 -1
- package/dist/src/document-model/custom/utils.d.ts +0 -8
- package/dist/src/document-model/custom/utils.d.ts.map +0 -1
- package/dist/src/document-model/custom/utils.js.map +0 -1
- package/dist/src/document-model/gen/actions.d.ts +0 -16
- package/dist/src/document-model/gen/actions.d.ts.map +0 -1
- package/dist/src/document-model/gen/actions.js +0 -8
- package/dist/src/document-model/gen/actions.js.map +0 -1
- package/dist/src/document-model/gen/constants.d.ts +0 -7
- package/dist/src/document-model/gen/constants.d.ts.map +0 -1
- package/dist/src/document-model/gen/constants.js +0 -34
- package/dist/src/document-model/gen/constants.js.map +0 -1
- package/dist/src/document-model/gen/creators.d.ts +0 -8
- package/dist/src/document-model/gen/creators.d.ts.map +0 -1
- package/dist/src/document-model/gen/creators.js +0 -8
- package/dist/src/document-model/gen/creators.js.map +0 -1
- package/dist/src/document-model/gen/document-model.d.ts +0 -3
- package/dist/src/document-model/gen/document-model.d.ts.map +0 -1
- package/dist/src/document-model/gen/document-model.js.map +0 -1
- package/dist/src/document-model/gen/header/actions.d.ts +0 -10
- package/dist/src/document-model/gen/header/actions.d.ts.map +0 -1
- package/dist/src/document-model/gen/header/actions.js +0 -2
- package/dist/src/document-model/gen/header/actions.js.map +0 -1
- package/dist/src/document-model/gen/header/creators.d.ts +0 -9
- package/dist/src/document-model/gen/header/creators.d.ts.map +0 -1
- package/dist/src/document-model/gen/header/creators.js +0 -10
- package/dist/src/document-model/gen/header/creators.js.map +0 -1
- package/dist/src/document-model/gen/header/object.d.ts +0 -13
- package/dist/src/document-model/gen/header/object.d.ts.map +0 -1
- package/dist/src/document-model/gen/header/object.js +0 -23
- package/dist/src/document-model/gen/header/object.js.map +0 -1
- package/dist/src/document-model/gen/header/operations.d.ts +0 -11
- package/dist/src/document-model/gen/header/operations.d.ts.map +0 -1
- package/dist/src/document-model/gen/header/operations.js +0 -2
- package/dist/src/document-model/gen/header/operations.js.map +0 -1
- package/dist/src/document-model/gen/module/actions.d.ts +0 -9
- package/dist/src/document-model/gen/module/actions.d.ts.map +0 -1
- package/dist/src/document-model/gen/module/actions.js +0 -2
- package/dist/src/document-model/gen/module/actions.js.map +0 -1
- package/dist/src/document-model/gen/module/creators.d.ts +0 -8
- package/dist/src/document-model/gen/module/creators.d.ts.map +0 -1
- package/dist/src/document-model/gen/module/creators.js +0 -9
- package/dist/src/document-model/gen/module/creators.js.map +0 -1
- package/dist/src/document-model/gen/module/object.d.ts +0 -12
- package/dist/src/document-model/gen/module/object.d.ts.map +0 -1
- package/dist/src/document-model/gen/module/object.js +0 -20
- package/dist/src/document-model/gen/module/object.js.map +0 -1
- package/dist/src/document-model/gen/module/operations.d.ts +0 -10
- package/dist/src/document-model/gen/module/operations.d.ts.map +0 -1
- package/dist/src/document-model/gen/module/operations.js +0 -2
- package/dist/src/document-model/gen/module/operations.js.map +0 -1
- package/dist/src/document-model/gen/object.d.ts +0 -29
- package/dist/src/document-model/gen/object.d.ts.map +0 -1
- package/dist/src/document-model/gen/object.js +0 -46
- package/dist/src/document-model/gen/object.js.map +0 -1
- package/dist/src/document-model/gen/operation/actions.d.ts +0 -14
- package/dist/src/document-model/gen/operation/actions.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation/actions.js +0 -2
- package/dist/src/document-model/gen/operation/actions.js.map +0 -1
- package/dist/src/document-model/gen/operation/creators.d.ts +0 -13
- package/dist/src/document-model/gen/operation/creators.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation/creators.js +0 -20
- package/dist/src/document-model/gen/operation/creators.js.map +0 -1
- package/dist/src/document-model/gen/operation/object.d.ts +0 -18
- package/dist/src/document-model/gen/operation/object.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation/object.js +0 -35
- package/dist/src/document-model/gen/operation/object.js.map +0 -1
- package/dist/src/document-model/gen/operation/operations.d.ts +0 -15
- package/dist/src/document-model/gen/operation/operations.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation/operations.js +0 -2
- package/dist/src/document-model/gen/operation/operations.js.map +0 -1
- package/dist/src/document-model/gen/operation-error/actions.d.ts +0 -11
- package/dist/src/document-model/gen/operation-error/actions.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation-error/actions.js +0 -2
- package/dist/src/document-model/gen/operation-error/actions.js.map +0 -1
- package/dist/src/document-model/gen/operation-error/creators.d.ts +0 -10
- package/dist/src/document-model/gen/operation-error/creators.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation-error/creators.js +0 -17
- package/dist/src/document-model/gen/operation-error/creators.js.map +0 -1
- package/dist/src/document-model/gen/operation-error/object.d.ts +0 -15
- package/dist/src/document-model/gen/operation-error/object.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation-error/object.js +0 -26
- package/dist/src/document-model/gen/operation-error/object.js.map +0 -1
- package/dist/src/document-model/gen/operation-error/operations.d.ts +0 -12
- package/dist/src/document-model/gen/operation-error/operations.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation-error/operations.js +0 -2
- package/dist/src/document-model/gen/operation-error/operations.js.map +0 -1
- package/dist/src/document-model/gen/operation-example/actions.d.ts +0 -8
- package/dist/src/document-model/gen/operation-example/actions.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation-example/actions.js +0 -2
- package/dist/src/document-model/gen/operation-example/actions.js.map +0 -1
- package/dist/src/document-model/gen/operation-example/creators.d.ts +0 -7
- package/dist/src/document-model/gen/operation-example/creators.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation-example/creators.js +0 -14
- package/dist/src/document-model/gen/operation-example/creators.js.map +0 -1
- package/dist/src/document-model/gen/operation-example/object.d.ts +0 -12
- package/dist/src/document-model/gen/operation-example/object.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation-example/object.js +0 -17
- package/dist/src/document-model/gen/operation-example/object.js.map +0 -1
- package/dist/src/document-model/gen/operation-example/operations.d.ts +0 -9
- package/dist/src/document-model/gen/operation-example/operations.d.ts.map +0 -1
- package/dist/src/document-model/gen/operation-example/operations.js +0 -2
- package/dist/src/document-model/gen/operation-example/operations.js.map +0 -1
- package/dist/src/document-model/gen/reducer.d.ts +0 -5
- package/dist/src/document-model/gen/reducer.d.ts.map +0 -1
- package/dist/src/document-model/gen/reducer.js +0 -193
- package/dist/src/document-model/gen/reducer.js.map +0 -1
- package/dist/src/document-model/gen/schema/types.d.ts +0 -458
- package/dist/src/document-model/gen/schema/types.d.ts.map +0 -1
- package/dist/src/document-model/gen/schema/types.js.map +0 -1
- package/dist/src/document-model/gen/schema/zod.d.ts +0 -454
- package/dist/src/document-model/gen/schema/zod.d.ts.map +0 -1
- package/dist/src/document-model/gen/schema/zod.js.map +0 -1
- package/dist/src/document-model/gen/state/actions.d.ts +0 -10
- package/dist/src/document-model/gen/state/actions.d.ts.map +0 -1
- package/dist/src/document-model/gen/state/actions.js +0 -2
- package/dist/src/document-model/gen/state/actions.js.map +0 -1
- package/dist/src/document-model/gen/state/creators.d.ts +0 -9
- package/dist/src/document-model/gen/state/creators.d.ts.map +0 -1
- package/dist/src/document-model/gen/state/creators.js +0 -10
- package/dist/src/document-model/gen/state/creators.js.map +0 -1
- package/dist/src/document-model/gen/state/object.d.ts +0 -13
- package/dist/src/document-model/gen/state/object.d.ts.map +0 -1
- package/dist/src/document-model/gen/state/object.js +0 -23
- package/dist/src/document-model/gen/state/object.js.map +0 -1
- package/dist/src/document-model/gen/state/operations.d.ts +0 -11
- package/dist/src/document-model/gen/state/operations.d.ts.map +0 -1
- package/dist/src/document-model/gen/state/operations.js +0 -2
- package/dist/src/document-model/gen/state/operations.js.map +0 -1
- package/dist/src/document-model/gen/types.d.ts +0 -7
- package/dist/src/document-model/gen/types.d.ts.map +0 -1
- package/dist/src/document-model/gen/types.js.map +0 -1
- package/dist/src/document-model/gen/utils.d.ts +0 -11
- package/dist/src/document-model/gen/utils.d.ts.map +0 -1
- package/dist/src/document-model/gen/utils.js +0 -33
- package/dist/src/document-model/gen/utils.js.map +0 -1
- package/dist/src/document-model/gen/versioning/actions.d.ts +0 -9
- package/dist/src/document-model/gen/versioning/actions.d.ts.map +0 -1
- package/dist/src/document-model/gen/versioning/actions.js +0 -2
- package/dist/src/document-model/gen/versioning/actions.js.map +0 -1
- package/dist/src/document-model/gen/versioning/creators.d.ts +0 -8
- package/dist/src/document-model/gen/versioning/creators.d.ts.map +0 -1
- package/dist/src/document-model/gen/versioning/creators.js +0 -13
- package/dist/src/document-model/gen/versioning/creators.js.map +0 -1
- package/dist/src/document-model/gen/versioning/object.d.ts +0 -13
- package/dist/src/document-model/gen/versioning/object.d.ts.map +0 -1
- package/dist/src/document-model/gen/versioning/object.js +0 -20
- package/dist/src/document-model/gen/versioning/object.js.map +0 -1
- package/dist/src/document-model/gen/versioning/operations.d.ts +0 -10
- package/dist/src/document-model/gen/versioning/operations.d.ts.map +0 -1
- package/dist/src/document-model/gen/versioning/operations.js +0 -2
- package/dist/src/document-model/gen/versioning/operations.js.map +0 -1
- package/dist/test/document/object.test.d.ts +0 -2
- package/dist/test/document/object.test.d.ts.map +0 -1
- package/dist/test/document/object.test.js +0 -13
- package/dist/test/document/object.test.js.map +0 -1
- package/dist/test/document-model/object.test.d.ts +0 -2
- package/dist/test/document-model/object.test.d.ts.map +0 -1
- package/dist/test/document-model/object.test.js +0 -243
- package/dist/test/document-model/object.test.js.map +0 -1
- /package/dist/src/{document-model/gen/schema → core}/types.js +0 -0
- /package/dist/{src/document-model/gen → test}/types.js +0 -0
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { loadState, prune, redo, setName, undo } from "./actions/creators.js";
|
|
2
|
-
import { readOnly } from "./utils/base.js";
|
|
3
|
-
import { baseLoadFromFile, baseSaveToFile } from "./utils/file.js";
|
|
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 class BaseDocumentClass {
|
|
11
|
-
_document;
|
|
12
|
-
_reducer;
|
|
13
|
-
_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, document, signalDispatch) {
|
|
20
|
-
this._reducer = reducer;
|
|
21
|
-
this._document = document;
|
|
22
|
-
this._signalDispatch = signalDispatch;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Dispatches an action to update the state of the document.
|
|
26
|
-
* @param action - The action to dispatch.
|
|
27
|
-
* @returns The Document instance.
|
|
28
|
-
*/
|
|
29
|
-
dispatch(action, options) {
|
|
30
|
-
this._document = this._reducer(this._document, action, this._signalDispatch, options);
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Saves the state of the document to a file.
|
|
35
|
-
* @param path - The file path where the state should be saved.
|
|
36
|
-
* @param extension - The file extension to use when saving the state.
|
|
37
|
-
* @returns The file path where the state was saved.
|
|
38
|
-
*/
|
|
39
|
-
saveToFile(path, extension, name) {
|
|
40
|
-
return baseSaveToFile(this._document, path, extension, name);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Loads the state of the document from a file.
|
|
44
|
-
* @param path - The file path where the state is stored.
|
|
45
|
-
*/
|
|
46
|
-
async loadFromFile(path) {
|
|
47
|
-
this._document = await baseLoadFromFile(path, this._reducer);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Loads the state of the document from a file and returns it.
|
|
51
|
-
* @param path - The file path where the state is stored.
|
|
52
|
-
* @param reducer - The reducer function that updates the state.
|
|
53
|
-
* @returns The state of the document.
|
|
54
|
-
*/
|
|
55
|
-
static async stateFromFile(path, reducer) {
|
|
56
|
-
const state = await baseLoadFromFile(path, reducer);
|
|
57
|
-
return state;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Gets the current state of the document.
|
|
61
|
-
*/
|
|
62
|
-
get state() {
|
|
63
|
-
return readOnly(this._document.state);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Gets the list of operations performed on the document.
|
|
67
|
-
*/
|
|
68
|
-
get operations() {
|
|
69
|
-
return readOnly(this._document.operations);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Gets the name of the document.
|
|
73
|
-
*/
|
|
74
|
-
get name() {
|
|
75
|
-
return this._document.header.name;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Gets the type of document.
|
|
79
|
-
*/
|
|
80
|
-
get documentType() {
|
|
81
|
-
return this._document.header.documentType;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Gets the timestamp of the date the document was created.
|
|
85
|
-
*/
|
|
86
|
-
get created() {
|
|
87
|
-
return this._document.header.createdAtUtcIso;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Gets the timestamp of the date the document was last modified.
|
|
91
|
-
*/
|
|
92
|
-
get lastModified() {
|
|
93
|
-
return this._document.header.lastModifiedAtUtcIso;
|
|
94
|
-
}
|
|
95
|
-
getRevision(scope) {
|
|
96
|
-
return this._document.header.revision[scope] || 0;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Gets the initial state of the document.
|
|
100
|
-
*/
|
|
101
|
-
get initialState() {
|
|
102
|
-
return readOnly(this._document.initialState);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Returns the current document as an object
|
|
106
|
-
*/
|
|
107
|
-
toDocument() {
|
|
108
|
-
return readOnly(this._document);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Gets the attachment associated with the given key.
|
|
112
|
-
* @param attachment - The key of the attachment to retrieve.
|
|
113
|
-
*/
|
|
114
|
-
getAttachment(attachment) {
|
|
115
|
-
return this._document.attachments?.[attachment];
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Sets the name of the document.
|
|
119
|
-
* @param name - The new name of the document.
|
|
120
|
-
*/
|
|
121
|
-
setName(name) {
|
|
122
|
-
this.dispatch(setName(name));
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Reverts a number of actions from the document.
|
|
127
|
-
* @param count - The number of actions to revert.
|
|
128
|
-
*/
|
|
129
|
-
undo(count) {
|
|
130
|
-
this.dispatch(undo(count));
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Reapplies a number of actions to the document.
|
|
135
|
-
* @param count - The number of actions to reapply.
|
|
136
|
-
*/
|
|
137
|
-
redo(count) {
|
|
138
|
-
this.dispatch(redo(count));
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Removes a range of operations from the document.
|
|
143
|
-
* @param start - The starting index of the range to remove.
|
|
144
|
-
* @param end - The ending index of the range to remove.
|
|
145
|
-
*/
|
|
146
|
-
prune(start, end) {
|
|
147
|
-
this.dispatch(prune(start, end));
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Loads a document state and a set of operations.
|
|
152
|
-
* @param state - The state to load.
|
|
153
|
-
* @param operations - The operations to apply to the document.
|
|
154
|
-
*/
|
|
155
|
-
loadState(state, operations) {
|
|
156
|
-
this.dispatch(loadState(state, operations));
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Applies multiple mixins to a base class.
|
|
162
|
-
* Used to have separate mixins to group methods by actions.
|
|
163
|
-
*
|
|
164
|
-
* @remarks
|
|
165
|
-
* {@link https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern}
|
|
166
|
-
*
|
|
167
|
-
* @param derivedCtor - The class to apply the mixins to.
|
|
168
|
-
* @param constructors - The constructors of the mixins.
|
|
169
|
-
*/
|
|
170
|
-
export function applyMixins(derivedCtor, constructors) {
|
|
171
|
-
constructors.forEach((baseCtor) => {
|
|
172
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
173
|
-
Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
|
|
174
|
-
Object.defineProperty(
|
|
175
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
176
|
-
derivedCtor.prototype, name,
|
|
177
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
178
|
-
Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
|
|
179
|
-
Object.create(null));
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
//# sourceMappingURL=object.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/document/object.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
export type JsonSerializable = string | number | boolean | null | undefined | JsonSerializable[] | {
|
|
2
|
-
[key: string]: JsonSerializable;
|
|
3
|
-
};
|
|
4
|
-
export type PHDocumentSignatureInfo = {
|
|
5
|
-
/**
|
|
6
|
-
* The public key of the document creator.
|
|
7
|
-
**/
|
|
8
|
-
publicKey: JsonWebKey;
|
|
9
|
-
/** The nonce that was appended to the message to create the signature. */
|
|
10
|
-
nonce: string;
|
|
11
|
-
};
|
|
12
|
-
/** Meta information about the document. */
|
|
13
|
-
export type PHDocumentMeta = {
|
|
14
|
-
/** The preferred editor for the document. */
|
|
15
|
-
preferredEditor?: string;
|
|
16
|
-
};
|
|
17
|
-
export type PHDocumentHeader = {
|
|
18
|
-
/**
|
|
19
|
-
* The id of the document.
|
|
20
|
-
*
|
|
21
|
-
* This is a Ed25519 signature and is immutable.
|
|
22
|
-
**/
|
|
23
|
-
id: string;
|
|
24
|
-
/**
|
|
25
|
-
* Information to verify the document creator.
|
|
26
|
-
*
|
|
27
|
-
* This is immutable.
|
|
28
|
-
**/
|
|
29
|
-
sig: PHDocumentSignatureInfo;
|
|
30
|
-
/**
|
|
31
|
-
* The type of the document.
|
|
32
|
-
*
|
|
33
|
-
* This is used as part of the signature payload and thus, cannot be changed
|
|
34
|
-
* after the document header has been created.
|
|
35
|
-
**/
|
|
36
|
-
documentType: string;
|
|
37
|
-
/**
|
|
38
|
-
* The timestamp of the creation date of the document, in UTC ISO format.
|
|
39
|
-
*
|
|
40
|
-
* This is used as part of the signature payload and thus, cannot be changed
|
|
41
|
-
* after the document header has been created.
|
|
42
|
-
**/
|
|
43
|
-
createdAtUtcIso: string;
|
|
44
|
-
/** The slug of the document. */
|
|
45
|
-
slug: string;
|
|
46
|
-
/** The name of the document. */
|
|
47
|
-
name: string;
|
|
48
|
-
/** The branch of this document. */
|
|
49
|
-
branch: string;
|
|
50
|
-
/**
|
|
51
|
-
* The revision of each scope of the document. This object is updated every
|
|
52
|
-
* time any _other_ scope is updated.
|
|
53
|
-
*/
|
|
54
|
-
revision: {
|
|
55
|
-
[scope: string]: number;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* The timestamp of the last change in the document, in UTC ISO format.
|
|
59
|
-
**/
|
|
60
|
-
lastModifiedAtUtcIso: string;
|
|
61
|
-
/** Meta information about the document. */
|
|
62
|
-
meta?: PHDocumentMeta;
|
|
63
|
-
};
|
|
64
|
-
export type PHBaseState<TDocumentState = JsonSerializable> = {
|
|
65
|
-
document?: TDocumentState;
|
|
66
|
-
};
|
|
67
|
-
export type PHDocumentHistory = {};
|
|
68
|
-
//# sourceMappingURL=ph-types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ph-types.d.ts","sourceRoot":"","sources":["../../../src/document/ph-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,gBAAgB,EAAE,GAClB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,CAAC;AAExC,MAAM,MAAM,uBAAuB,GAAG;IACpC;;QAEI;IACJ,SAAS,EAAE,UAAU,CAAC;IAEtB,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,2CAA2C;AAC3C,MAAM,MAAM,cAAc,GAAG;IAC3B,6CAA6C;IAC7C,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;QAII;IACJ,EAAE,EAAE,MAAM,CAAC;IAEX;;;;QAII;IACJ,GAAG,EAAE,uBAAuB,CAAC;IAE7B;;;;;QAKI;IACJ,YAAY,EAAE,MAAM,CAAC;IAErB;;;;;QAKI;IACJ,eAAe,EAAE,MAAM,CAAC;IAExB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IAEb,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IAEb,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,QAAQ,EAAE;QACR,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;KACzB,CAAC;IAEF;;QAEI;IACJ,oBAAoB,EAAE,MAAM,CAAC;IAE7B,2CAA2C;IAC3C,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,cAAc,GAAG,gBAAgB,IAAI;IAE3D,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ph-types.js","sourceRoot":"","sources":["../../../src/document/ph-types.ts"],"names":[],"mappings":""}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { type SignalDispatch } from "./signal.js";
|
|
2
|
-
import { type Action, type ActionFromDocument, type DefaultAction, type Operation, type OperationFromDocument, type PHDocument, type ReducerOptions, type StateReducer } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Updates the document header with the latest revision number and
|
|
5
|
-
* date of last modification.
|
|
6
|
-
*
|
|
7
|
-
* @param state The current state of the document.
|
|
8
|
-
* @param operation The action being applied to the document.
|
|
9
|
-
* @returns The updated document state.
|
|
10
|
-
*/
|
|
11
|
-
export declare function updateHeader<TDocument extends PHDocument>(document: TDocument, action: Action | DefaultAction | Operation): TDocument;
|
|
12
|
-
/**
|
|
13
|
-
* Updates the document state based on the provided action.
|
|
14
|
-
*
|
|
15
|
-
* @param state The current state of the document.
|
|
16
|
-
* @param action The action being applied to the document.
|
|
17
|
-
* @param skip The number of operations to skip before applying the action.
|
|
18
|
-
* @param reuseLastOperationIndex Whether to reuse the last operation index (used when a an UNDO operation is performed after an existing one).
|
|
19
|
-
* @returns The updated document state.
|
|
20
|
-
*/
|
|
21
|
-
export declare function updateDocument<TDocument extends PHDocument>(document: TDocument, action: Action | Operation, skip?: number, reuseLastOperationIndex?: boolean): TDocument;
|
|
22
|
-
/**
|
|
23
|
-
* Processes an UNDO or REDO action.
|
|
24
|
-
*
|
|
25
|
-
* @param document The current state of the document.
|
|
26
|
-
* @param action The action being applied to the document.
|
|
27
|
-
* @param skip The number of operations to skip before applying the action.
|
|
28
|
-
* @returns The updated document, calculated skip value and transformed action (if applied).
|
|
29
|
-
*/
|
|
30
|
-
export declare function processUndoRedo<TDocument extends PHDocument>(document: TDocument, action: ActionFromDocument<TDocument> | OperationFromDocument<TDocument> | DefaultAction, skip: number): {
|
|
31
|
-
document: TDocument;
|
|
32
|
-
action: ActionFromDocument<TDocument> | OperationFromDocument<TDocument>;
|
|
33
|
-
skip: number;
|
|
34
|
-
reuseLastOperationIndex: boolean;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Base document reducer that wraps a custom document reducer and handles
|
|
38
|
-
* document-level actions such as undo, redo, prune, and set name.
|
|
39
|
-
*
|
|
40
|
-
* @template TGlobalState - The type of the state of the custom reducer.
|
|
41
|
-
* @template TAction - The type of the actions of the custom reducer.
|
|
42
|
-
* @param state - The current state of the document.
|
|
43
|
-
* @param action - The action object to apply to the state.
|
|
44
|
-
* @param customReducer - The custom reducer that implements the application logic
|
|
45
|
-
* specific to the document's state.
|
|
46
|
-
* @returns The new state of the document.
|
|
47
|
-
*/
|
|
48
|
-
export declare function baseReducer<TDocument extends PHDocument>(document: TDocument, action: Action | Operation, customReducer: StateReducer<TDocument>, dispatch?: SignalDispatch, options?: ReducerOptions): TDocument;
|
|
49
|
-
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../../src/document/reducer.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,KAAK,MAAM,EACX,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAE1B,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AA0CpB;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,SAAS,SAAS,UAAU,EACvD,QAAQ,EAAE,SAAS,EACnB,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,GACzC,SAAS,CAcX;AA4ED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,SAAS,SAAS,UAAU,EACzD,QAAQ,EAAE,SAAS,EACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,SAAI,EACR,uBAAuB,UAAQ,GAC9B,SAAS,CASX;AAiCD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,SAAS,SAAS,UAAU,EAC1D,QAAQ,EAAE,SAAS,EACnB,MAAM,EACF,kBAAkB,CAAC,SAAS,CAAC,GAC7B,qBAAqB,CAAC,SAAS,CAAC,GAChC,aAAa,EACjB,IAAI,EAAE,MAAM,GACX;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,kBAAkB,CAAC,SAAS,CAAC,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB,EAAE,OAAO,CAAC;CAClC,CASA;AAuGD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,SAAS,SAAS,UAAU,EACtD,QAAQ,EAAE,SAAS,EACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,aAAa,EAAE,YAAY,CAAC,SAAS,CAAC,EACtC,QAAQ,CAAC,EAAE,cAAc,EACzB,OAAO,GAAE,cAAmB,GAC3B,SAAS,CA2KX"}
|
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
import { castDraft, create, unsafe } from "mutative";
|
|
2
|
-
import { loadStateOperation, pruneOperation, redoOperation, setNameOperation, undoOperation, } from "./actions/operations.js";
|
|
3
|
-
import { LOAD_STATE, PRUNE, REDO, SET_NAME, UNDO } from "./actions/types.js";
|
|
4
|
-
import { DocumentActionSchema } from "./schema/zod.js";
|
|
5
|
-
import { getDocumentLastModified, hashDocumentStateForScope, isDocumentAction, isUndo, isUndoRedo, parseResultingState, replayOperations, } from "./utils/base.js";
|
|
6
|
-
import { generateId } from "./utils/crypto.js";
|
|
7
|
-
import { diffOperations, garbageCollect, garbageCollectDocumentOperations, skipHeaderOperations, sortOperations, } from "./utils/document-helpers.js";
|
|
8
|
-
/**
|
|
9
|
-
* Gets the next revision number based on the provided action.
|
|
10
|
-
*
|
|
11
|
-
* @param state The current state of the document.
|
|
12
|
-
* @param operation The action being applied to the document.
|
|
13
|
-
* @returns The next revision number.
|
|
14
|
-
*/
|
|
15
|
-
function getNextRevision(document, operation) {
|
|
16
|
-
let latestOperationIndex;
|
|
17
|
-
if ("index" in operation) {
|
|
18
|
-
latestOperationIndex = operation.index;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
latestOperationIndex =
|
|
22
|
-
document.operations[operation.scope].at(-1)?.index ?? -1;
|
|
23
|
-
}
|
|
24
|
-
return (latestOperationIndex ?? -1) + 1;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Updates the document header with the latest revision number and
|
|
28
|
-
* date of last modification.
|
|
29
|
-
*
|
|
30
|
-
* @param state The current state of the document.
|
|
31
|
-
* @param operation The action being applied to the document.
|
|
32
|
-
* @returns The updated document state.
|
|
33
|
-
*/
|
|
34
|
-
export function updateHeader(document, action) {
|
|
35
|
-
const header = {
|
|
36
|
-
...document.header,
|
|
37
|
-
revision: {
|
|
38
|
-
...document.header.revision,
|
|
39
|
-
[action.scope]: getNextRevision(document, action),
|
|
40
|
-
},
|
|
41
|
-
lastModifiedAtUtcIso: getDocumentLastModified(document),
|
|
42
|
-
};
|
|
43
|
-
return {
|
|
44
|
-
...document,
|
|
45
|
-
header,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Updates the operations history of the document based on the provided action.
|
|
50
|
-
*
|
|
51
|
-
* @param state The current state of the document.
|
|
52
|
-
* @param actionOrOperation The action being applied to the document.
|
|
53
|
-
* @param skip The number of operations to skip before applying the action.
|
|
54
|
-
* @param reuseLastOperationIndex Whether to reuse the last operation index (used when a an UNDO operation is performed after an existing one).
|
|
55
|
-
* @returns The updated document state.
|
|
56
|
-
*/
|
|
57
|
-
function updateOperations(document, actionOrOperation, skip = 0, reuseLastOperationIndex = false) {
|
|
58
|
-
// UNDO, REDO and PRUNE are meta operations
|
|
59
|
-
// that alter the operations history themselves
|
|
60
|
-
if ("type" in actionOrOperation &&
|
|
61
|
-
[UNDO, REDO, PRUNE].includes(actionOrOperation.type)) {
|
|
62
|
-
return document;
|
|
63
|
-
}
|
|
64
|
-
const { scope } = actionOrOperation;
|
|
65
|
-
const operations = document.operations[scope].slice();
|
|
66
|
-
let operationId;
|
|
67
|
-
const latestOperation = operations.sort((a, b) => a.index - b.index).at(-1);
|
|
68
|
-
const lastOperationIndex = latestOperation?.index ?? -1;
|
|
69
|
-
let nextIndex = reuseLastOperationIndex
|
|
70
|
-
? lastOperationIndex
|
|
71
|
-
: lastOperationIndex + 1;
|
|
72
|
-
let timestamp = new Date().toISOString();
|
|
73
|
-
if ("index" in actionOrOperation) {
|
|
74
|
-
if (actionOrOperation.index - skip > nextIndex) {
|
|
75
|
-
throw new Error(`Missing operations: expected ${nextIndex} with skip 0 or equivalent, got index ${actionOrOperation.index} with skip ${skip}`);
|
|
76
|
-
}
|
|
77
|
-
nextIndex = actionOrOperation.index;
|
|
78
|
-
operationId = actionOrOperation.id;
|
|
79
|
-
timestamp = actionOrOperation.timestamp;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
operationId =
|
|
83
|
-
"id" in actionOrOperation
|
|
84
|
-
? actionOrOperation.id
|
|
85
|
-
: generateId();
|
|
86
|
-
}
|
|
87
|
-
operations.push({
|
|
88
|
-
...actionOrOperation,
|
|
89
|
-
id: operationId,
|
|
90
|
-
index: nextIndex,
|
|
91
|
-
timestamp,
|
|
92
|
-
hash: "",
|
|
93
|
-
scope,
|
|
94
|
-
skip,
|
|
95
|
-
error: undefined,
|
|
96
|
-
});
|
|
97
|
-
// adds the action to the operations history with
|
|
98
|
-
// the latest index and current timestamp
|
|
99
|
-
return {
|
|
100
|
-
...document,
|
|
101
|
-
operations: { ...document.operations, [scope]: operations },
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Updates the document state based on the provided action.
|
|
106
|
-
*
|
|
107
|
-
* @param state The current state of the document.
|
|
108
|
-
* @param action The action being applied to the document.
|
|
109
|
-
* @param skip The number of operations to skip before applying the action.
|
|
110
|
-
* @param reuseLastOperationIndex Whether to reuse the last operation index (used when a an UNDO operation is performed after an existing one).
|
|
111
|
-
* @returns The updated document state.
|
|
112
|
-
*/
|
|
113
|
-
export function updateDocument(document, action, skip = 0, reuseLastOperationIndex = false) {
|
|
114
|
-
let newDocument = updateOperations(document, action, skip, reuseLastOperationIndex);
|
|
115
|
-
newDocument = updateHeader(newDocument, action);
|
|
116
|
-
return newDocument;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* The base document reducer function that wraps a custom reducer function.
|
|
120
|
-
*
|
|
121
|
-
* @param state The current state of the document.
|
|
122
|
-
* @param action The action being applied to the document.
|
|
123
|
-
* @param wrappedReducer The custom reducer function being wrapped by the base reducer.
|
|
124
|
-
* @returns The updated document state.
|
|
125
|
-
*/
|
|
126
|
-
function _baseReducer(document, action, wrappedReducer) {
|
|
127
|
-
// throws if action is not valid base action
|
|
128
|
-
const parsedAction = DocumentActionSchema().parse(action);
|
|
129
|
-
switch (parsedAction.type) {
|
|
130
|
-
case SET_NAME:
|
|
131
|
-
return setNameOperation(document, parsedAction.input);
|
|
132
|
-
case PRUNE:
|
|
133
|
-
return pruneOperation(document, parsedAction.input, wrappedReducer);
|
|
134
|
-
case LOAD_STATE:
|
|
135
|
-
return loadStateOperation(document, parsedAction.input.state);
|
|
136
|
-
default:
|
|
137
|
-
return document;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Processes an UNDO or REDO action.
|
|
142
|
-
*
|
|
143
|
-
* @param document The current state of the document.
|
|
144
|
-
* @param action The action being applied to the document.
|
|
145
|
-
* @param skip The number of operations to skip before applying the action.
|
|
146
|
-
* @returns The updated document, calculated skip value and transformed action (if applied).
|
|
147
|
-
*/
|
|
148
|
-
export function processUndoRedo(document, action, skip) {
|
|
149
|
-
switch (action.type) {
|
|
150
|
-
case UNDO:
|
|
151
|
-
return undoOperation(document, action, skip);
|
|
152
|
-
case REDO:
|
|
153
|
-
return redoOperation(document, action, skip);
|
|
154
|
-
default:
|
|
155
|
-
return { document, action, skip, reuseLastOperationIndex: false };
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function processSkipOperation(document, action, customReducer, skipValue, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
|
|
159
|
-
const scope = action.scope;
|
|
160
|
-
const latestOperation = document.operations[scope].at(-1);
|
|
161
|
-
if (!latestOperation)
|
|
162
|
-
return document;
|
|
163
|
-
const documentOperations = garbageCollectDocumentOperations({
|
|
164
|
-
...document.operations,
|
|
165
|
-
[scope]: skipHeaderOperations(document.operations[scope], latestOperation),
|
|
166
|
-
});
|
|
167
|
-
let scopeState = undefined;
|
|
168
|
-
const lastRemainingOperation = documentOperations[scope].at(-1);
|
|
169
|
-
// if the last operation has the resulting state and
|
|
170
|
-
// reuseOperationResultingState is true then reuses it
|
|
171
|
-
// instead of replaying the operations from the beginning
|
|
172
|
-
if (reuseOperationResultingState && lastRemainingOperation?.resultingState) {
|
|
173
|
-
scopeState = resultingStateParser(lastRemainingOperation.resultingState);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
const { state } = replayOperations(document.initialState, documentOperations, customReducer, undefined, undefined, undefined, undefined, {
|
|
177
|
-
reuseHash: true,
|
|
178
|
-
reuseOperationResultingState,
|
|
179
|
-
operationResultingStateParser: resultingStateParser,
|
|
180
|
-
});
|
|
181
|
-
scopeState = state[scope];
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
...document,
|
|
185
|
-
state: {
|
|
186
|
-
...document.state,
|
|
187
|
-
[scope]: scopeState,
|
|
188
|
-
},
|
|
189
|
-
operations: garbageCollectDocumentOperations({
|
|
190
|
-
...document.operations,
|
|
191
|
-
}),
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
function processUndoOperation(document, scope, customReducer, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
|
|
195
|
-
const operations = [...document.operations[scope]];
|
|
196
|
-
const sortedOperations = sortOperations(operations);
|
|
197
|
-
sortedOperations.pop();
|
|
198
|
-
const documentOperations = garbageCollectDocumentOperations({
|
|
199
|
-
...document.operations,
|
|
200
|
-
});
|
|
201
|
-
const clearedOperations = [...documentOperations[scope]];
|
|
202
|
-
const diff = diffOperations(garbageCollect(sortedOperations), clearedOperations);
|
|
203
|
-
const doc = replayOperations(document.initialState, documentOperations, customReducer, undefined, undefined, undefined, undefined, {
|
|
204
|
-
reuseHash: true,
|
|
205
|
-
reuseOperationResultingState,
|
|
206
|
-
operationResultingStateParser: resultingStateParser,
|
|
207
|
-
});
|
|
208
|
-
const clipboard = sortOperations([...document.clipboard, ...diff].filter((op) => op.type !== "NOOP")).reverse();
|
|
209
|
-
return { ...doc, clipboard };
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Base document reducer that wraps a custom document reducer and handles
|
|
213
|
-
* document-level actions such as undo, redo, prune, and set name.
|
|
214
|
-
*
|
|
215
|
-
* @template TGlobalState - The type of the state of the custom reducer.
|
|
216
|
-
* @template TAction - The type of the actions of the custom reducer.
|
|
217
|
-
* @param state - The current state of the document.
|
|
218
|
-
* @param action - The action object to apply to the state.
|
|
219
|
-
* @param customReducer - The custom reducer that implements the application logic
|
|
220
|
-
* specific to the document's state.
|
|
221
|
-
* @returns The new state of the document.
|
|
222
|
-
*/
|
|
223
|
-
export function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
224
|
-
const { skip, ignoreSkipOperations = false, reuseHash = false, reuseOperationResultingState = false, operationResultingStateParser, } = options;
|
|
225
|
-
let _action = { ...action };
|
|
226
|
-
let skipValue = skip || 0;
|
|
227
|
-
let newDocument = {
|
|
228
|
-
...document,
|
|
229
|
-
};
|
|
230
|
-
let reuseLastOperationIndex = false;
|
|
231
|
-
const shouldProcessSkipOperation = !ignoreSkipOperations &&
|
|
232
|
-
(skipValue > 0 ||
|
|
233
|
-
("index" in _action &&
|
|
234
|
-
"skip" in _action &&
|
|
235
|
-
typeof _action.skip === "number" &&
|
|
236
|
-
_action.skip > 0));
|
|
237
|
-
if (isUndoRedo(_action)) {
|
|
238
|
-
const { skip: calculatedSkip, action: transformedAction, document: processedDocument, reuseLastOperationIndex: reuseIndex, } = processUndoRedo(document, _action, skipValue);
|
|
239
|
-
_action = transformedAction;
|
|
240
|
-
skipValue = calculatedSkip;
|
|
241
|
-
newDocument = processedDocument;
|
|
242
|
-
reuseLastOperationIndex = reuseIndex;
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
newDocument = {
|
|
246
|
-
...newDocument,
|
|
247
|
-
clipboard: [],
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
// if the action is one the base document actions (SET_NAME, UNDO, REDO, PRUNE)
|
|
251
|
-
// then runs the base reducer first
|
|
252
|
-
if (isDocumentAction(_action)) {
|
|
253
|
-
newDocument = _baseReducer(newDocument, _action, customReducer);
|
|
254
|
-
}
|
|
255
|
-
// updates the document revision number, last modified date
|
|
256
|
-
// and operation history
|
|
257
|
-
newDocument = updateDocument(newDocument, _action, skipValue, reuseLastOperationIndex);
|
|
258
|
-
const isUndoAction = isUndo(action);
|
|
259
|
-
if (isUndoAction) {
|
|
260
|
-
const result = processUndoOperation(newDocument, action.scope, customReducer);
|
|
261
|
-
return result;
|
|
262
|
-
}
|
|
263
|
-
if (shouldProcessSkipOperation) {
|
|
264
|
-
newDocument = processSkipOperation(newDocument, _action, customReducer, skipValue, reuseOperationResultingState, operationResultingStateParser);
|
|
265
|
-
}
|
|
266
|
-
// wraps the custom reducer with Mutative to avoid
|
|
267
|
-
// mutation bugs and allow writing reducers with
|
|
268
|
-
// mutating code
|
|
269
|
-
newDocument = create(newDocument, (draft) => {
|
|
270
|
-
// the reducer runs on a immutable version of
|
|
271
|
-
// provided state
|
|
272
|
-
try {
|
|
273
|
-
const newState = customReducer(draft.state, _action, dispatch);
|
|
274
|
-
// const clipboardValue = isUndoRedo(action) ? [...clipboard] : [];
|
|
275
|
-
// if the reducer creates a new state object instead
|
|
276
|
-
// of mutating the draft then returns the new state
|
|
277
|
-
if (newState) {
|
|
278
|
-
// Object.assign(draft.state, newState);
|
|
279
|
-
unsafe(() => {
|
|
280
|
-
// casts new state as draft to comply with typescript
|
|
281
|
-
draft.state = castDraft(newState);
|
|
282
|
-
// clipboard: [...clipboardValue],
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
// unsafe(() => {
|
|
287
|
-
// draft.clipboard = castDraft([...clipboardValue]);
|
|
288
|
-
// });
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
catch (error) {
|
|
292
|
-
// if the reducer throws an error then we should keep the previous state (before replayOperations)
|
|
293
|
-
// and remove skip number from action/operation
|
|
294
|
-
const lastOperationIndex = newDocument.operations[_action.scope].length - 1;
|
|
295
|
-
draft.operations[_action.scope][lastOperationIndex].error = error.message;
|
|
296
|
-
draft.operations[_action.scope][lastOperationIndex].skip = 0;
|
|
297
|
-
if (shouldProcessSkipOperation) {
|
|
298
|
-
draft.state = castDraft({
|
|
299
|
-
...document.state,
|
|
300
|
-
});
|
|
301
|
-
draft.operations = castDraft({
|
|
302
|
-
...document.operations,
|
|
303
|
-
[_action.scope]: [
|
|
304
|
-
...document.operations[_action.scope],
|
|
305
|
-
{
|
|
306
|
-
...draft.operations[_action.scope][lastOperationIndex],
|
|
307
|
-
},
|
|
308
|
-
],
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
// updates the document history
|
|
314
|
-
// meta operations are not added to the operations history
|
|
315
|
-
if ([UNDO, REDO, PRUNE].includes(_action.type)) {
|
|
316
|
-
return newDocument;
|
|
317
|
-
}
|
|
318
|
-
// if reuseHash is true, checks if the action has
|
|
319
|
-
// an hash and uses it instead of generating it
|
|
320
|
-
const scope = _action.scope || "global";
|
|
321
|
-
const hash = reuseHash && Object.prototype.hasOwnProperty.call(_action, "hash")
|
|
322
|
-
? _action.hash
|
|
323
|
-
: hashDocumentStateForScope(newDocument, scope);
|
|
324
|
-
// updates the last operation with the hash of the resulting state
|
|
325
|
-
const lastOperation = newDocument.operations[scope].at(-1);
|
|
326
|
-
if (lastOperation) {
|
|
327
|
-
lastOperation.hash = hash;
|
|
328
|
-
if (reuseOperationResultingState) {
|
|
329
|
-
lastOperation.resultingState = JSON.stringify(newDocument.state[scope]);
|
|
330
|
-
}
|
|
331
|
-
// if the action has attachments then adds them to the document
|
|
332
|
-
if (!isDocumentAction(_action) && _action.attachments) {
|
|
333
|
-
_action.attachments.forEach((attachment) => {
|
|
334
|
-
const { hash, ...file } = attachment;
|
|
335
|
-
if (!newDocument.attachments) {
|
|
336
|
-
newDocument.attachments = {};
|
|
337
|
-
}
|
|
338
|
-
newDocument.attachments[hash] = {
|
|
339
|
-
...file,
|
|
340
|
-
};
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
return newDocument;
|
|
345
|
-
}
|
|
346
|
-
//# sourceMappingURL=reducer.js.map
|