document-model 2.4.1 → 2.5.0-test.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/{browser/src → src}/document/actions/creators.d.ts +4 -2
- package/dist/src/document/actions/creators.d.ts.map +1 -0
- package/dist/{node/src/document/actions/creators.d.ts → src/document/actions/creators.js} +18 -8
- package/dist/src/document/actions/creators.js.map +1 -0
- package/dist/src/document/actions/operations.d.ts +23 -0
- package/dist/src/document/actions/operations.d.ts.map +1 -0
- package/dist/src/document/actions/operations.js +131 -0
- package/dist/src/document/actions/operations.js.map +1 -0
- package/dist/src/document/actions/types.d.ts +16 -0
- package/dist/src/document/actions/types.d.ts.map +1 -0
- package/dist/src/document/actions/types.js +7 -0
- package/dist/src/document/actions/types.js.map +1 -0
- package/dist/{browser/src → src}/document/object.d.ts +17 -14
- package/dist/src/document/object.d.ts.map +1 -0
- package/dist/{node/src/document/object.d.ts → src/document/object.js} +93 -29
- package/dist/src/document/object.js.map +1 -0
- package/dist/src/document/reducer.d.ts +49 -0
- package/dist/src/document/reducer.d.ts.map +1 -0
- package/dist/src/document/reducer.js +342 -0
- package/dist/src/document/reducer.js.map +1 -0
- package/dist/{browser/src → src}/document/schema/types.d.ts +2 -1
- package/dist/src/document/schema/types.d.ts.map +1 -0
- package/dist/src/document/schema/types.js +2 -0
- package/dist/src/document/schema/types.js.map +1 -0
- package/dist/{browser/src → src}/document/schema/zod.d.ts +30 -47
- package/dist/src/document/schema/zod.d.ts.map +1 -0
- package/dist/src/document/schema/zod.js +113 -0
- package/dist/src/document/schema/zod.js.map +1 -0
- package/dist/{node/src → src}/document/signal.d.ts +10 -9
- package/dist/src/document/signal.d.ts.map +1 -0
- package/dist/src/document/signal.js +2 -0
- package/dist/src/document/signal.js.map +1 -0
- package/dist/src/document/types.d.ts +345 -0
- package/dist/src/document/types.d.ts.map +1 -0
- package/dist/src/document/types.js +2 -0
- package/dist/src/document/types.js.map +1 -0
- package/dist/src/document/utils/base.d.ts +83 -0
- package/dist/src/document/utils/base.d.ts.map +1 -0
- package/dist/src/document/utils/base.js +331 -0
- package/dist/src/document/utils/base.js.map +1 -0
- package/dist/src/document/utils/browser.d.ts +18 -0
- package/dist/src/document/utils/browser.d.ts.map +1 -0
- package/dist/src/document/utils/browser.js +54 -0
- package/dist/src/document/utils/browser.js.map +1 -0
- package/dist/src/document/utils/crypto.d.ts +11 -0
- package/dist/src/document/utils/crypto.d.ts.map +1 -0
- package/dist/src/document/utils/crypto.js +80 -0
- package/dist/src/document/utils/crypto.js.map +1 -0
- package/dist/src/document/utils/document-helpers.d.ts +78 -0
- package/dist/src/document/utils/document-helpers.d.ts.map +1 -0
- package/dist/src/document/utils/document-helpers.js +411 -0
- package/dist/src/document/utils/document-helpers.js.map +1 -0
- package/dist/src/document/utils/errors.d.ts +10 -0
- package/dist/src/document/utils/errors.d.ts.map +1 -0
- package/dist/src/document/utils/errors.js +19 -0
- package/dist/src/document/utils/errors.js.map +1 -0
- package/dist/{node/src → src}/document/utils/file.d.ts +10 -8
- package/dist/src/document/utils/file.d.ts.map +1 -0
- package/dist/src/document/utils/file.js +158 -0
- package/dist/src/document/utils/file.js.map +1 -0
- package/dist/src/document/utils/node.d.ts +18 -0
- package/dist/src/document/utils/node.d.ts.map +1 -0
- package/dist/src/document/utils/node.js +62 -0
- package/dist/src/document/utils/node.js.map +1 -0
- package/dist/src/document/utils/validation.d.ts +3 -0
- package/dist/src/document/utils/validation.d.ts.map +1 -0
- package/dist/src/document/utils/validation.js +23 -0
- package/dist/src/document/utils/validation.js.map +1 -0
- package/dist/src/document-model/custom/reducers/header.d.ts +3 -0
- package/dist/src/document-model/custom/reducers/header.d.ts.map +1 -0
- package/dist/src/document-model/custom/reducers/header.js +23 -0
- package/dist/src/document-model/custom/reducers/header.js.map +1 -0
- package/dist/src/document-model/custom/reducers/module.d.ts +3 -0
- package/dist/src/document-model/custom/reducers/module.d.ts.map +1 -0
- package/dist/src/document-model/custom/reducers/module.js +41 -0
- package/dist/src/document-model/custom/reducers/module.js.map +1 -0
- package/dist/src/document-model/custom/reducers/operation-error.d.ts +3 -0
- package/dist/src/document-model/custom/reducers/operation-error.d.ts.map +1 -0
- package/dist/src/document-model/custom/reducers/operation-error.js +94 -0
- package/dist/src/document-model/custom/reducers/operation-error.js.map +1 -0
- package/dist/src/document-model/custom/reducers/operation-example.d.ts +3 -0
- package/dist/src/document-model/custom/reducers/operation-example.d.ts.map +1 -0
- package/dist/src/document-model/custom/reducers/operation-example.js +53 -0
- package/dist/src/document-model/custom/reducers/operation-example.js.map +1 -0
- package/dist/src/document-model/custom/reducers/operation.d.ts +3 -0
- package/dist/src/document-model/custom/reducers/operation.d.ts.map +1 -0
- package/dist/src/document-model/custom/reducers/operation.js +125 -0
- package/dist/src/document-model/custom/reducers/operation.js.map +1 -0
- package/dist/src/document-model/custom/reducers/state.d.ts +3 -0
- package/dist/src/document-model/custom/reducers/state.d.ts.map +1 -0
- package/dist/src/document-model/custom/reducers/state.js +71 -0
- package/dist/src/document-model/custom/reducers/state.js.map +1 -0
- package/dist/src/document-model/custom/reducers/versioning.d.ts +8 -0
- package/dist/src/document-model/custom/reducers/versioning.d.ts.map +1 -0
- package/dist/src/document-model/custom/reducers/versioning.js +23 -0
- package/dist/src/document-model/custom/reducers/versioning.js.map +1 -0
- package/dist/{browser/src → src}/document-model/custom/utils.d.ts +4 -3
- package/dist/src/document-model/custom/utils.d.ts.map +1 -0
- package/dist/src/document-model/custom/utils.js +105 -0
- package/dist/src/document-model/custom/utils.js.map +1 -0
- package/dist/src/document-model/gen/actions.d.ts +16 -0
- package/dist/src/document-model/gen/actions.d.ts.map +1 -0
- package/dist/src/document-model/gen/actions.js +8 -0
- package/dist/src/document-model/gen/actions.js.map +1 -0
- package/dist/src/document-model/gen/constants.d.ts +7 -0
- package/dist/src/document-model/gen/constants.d.ts.map +1 -0
- package/dist/src/document-model/gen/constants.js +34 -0
- package/dist/src/document-model/gen/constants.js.map +1 -0
- package/dist/src/document-model/gen/creators.d.ts +8 -0
- package/dist/src/document-model/gen/creators.d.ts.map +1 -0
- package/dist/src/document-model/gen/creators.js +8 -0
- package/dist/src/document-model/gen/creators.js.map +1 -0
- package/dist/src/document-model/gen/document-model.d.ts +3 -0
- package/dist/src/document-model/gen/document-model.d.ts.map +1 -0
- package/dist/src/document-model/gen/document-model.js +542 -0
- package/dist/src/document-model/gen/document-model.js.map +1 -0
- package/dist/src/document-model/gen/header/actions.d.ts +10 -0
- package/dist/src/document-model/gen/header/actions.d.ts.map +1 -0
- package/dist/src/document-model/gen/header/actions.js +2 -0
- package/dist/src/document-model/gen/header/actions.js.map +1 -0
- package/dist/{node/src → src}/document-model/gen/header/creators.d.ts +3 -2
- package/dist/src/document-model/gen/header/creators.d.ts.map +1 -0
- package/dist/src/document-model/gen/header/creators.js +10 -0
- package/dist/src/document-model/gen/header/creators.js.map +1 -0
- package/dist/src/document-model/gen/header/object.d.ts +13 -0
- package/dist/src/document-model/gen/header/object.d.ts.map +1 -0
- package/dist/src/document-model/gen/header/object.js +23 -0
- package/dist/src/document-model/gen/header/object.js.map +1 -0
- package/dist/{node/src → src}/document-model/gen/header/operations.d.ts +3 -2
- package/dist/src/document-model/gen/header/operations.d.ts.map +1 -0
- package/dist/src/document-model/gen/header/operations.js +2 -0
- package/dist/src/document-model/gen/header/operations.js.map +1 -0
- package/dist/src/document-model/gen/module/actions.d.ts +9 -0
- package/dist/src/document-model/gen/module/actions.d.ts.map +1 -0
- package/dist/src/document-model/gen/module/actions.js +2 -0
- package/dist/src/document-model/gen/module/actions.js.map +1 -0
- package/dist/{node/src → src}/document-model/gen/module/creators.d.ts +3 -2
- package/dist/src/document-model/gen/module/creators.d.ts.map +1 -0
- package/dist/src/document-model/gen/module/creators.js +9 -0
- package/dist/src/document-model/gen/module/creators.js.map +1 -0
- package/dist/src/document-model/gen/module/object.d.ts +12 -0
- package/dist/src/document-model/gen/module/object.d.ts.map +1 -0
- package/dist/src/document-model/gen/module/object.js +20 -0
- package/dist/src/document-model/gen/module/object.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/module/operations.d.ts +3 -2
- package/dist/src/document-model/gen/module/operations.d.ts.map +1 -0
- package/dist/src/document-model/gen/module/operations.js +2 -0
- package/dist/src/document-model/gen/module/operations.js.map +1 -0
- package/dist/src/document-model/gen/object.d.ts +29 -0
- package/dist/src/document-model/gen/object.d.ts.map +1 -0
- package/dist/src/document-model/gen/object.js +46 -0
- package/dist/src/document-model/gen/object.js.map +1 -0
- package/dist/src/document-model/gen/operation/actions.d.ts +14 -0
- package/dist/src/document-model/gen/operation/actions.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation/actions.js +2 -0
- package/dist/src/document-model/gen/operation/actions.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/operation/creators.d.ts +3 -2
- package/dist/src/document-model/gen/operation/creators.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation/creators.js +20 -0
- package/dist/src/document-model/gen/operation/creators.js.map +1 -0
- package/dist/{node/src → src}/document-model/gen/operation/object.d.ts +7 -5
- package/dist/src/document-model/gen/operation/object.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation/object.js +35 -0
- package/dist/src/document-model/gen/operation/object.js.map +1 -0
- package/dist/{node/src → src}/document-model/gen/operation/operations.d.ts +3 -2
- package/dist/src/document-model/gen/operation/operations.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation/operations.js +2 -0
- package/dist/src/document-model/gen/operation/operations.js.map +1 -0
- package/dist/src/document-model/gen/operation-error/actions.d.ts +11 -0
- package/dist/src/document-model/gen/operation-error/actions.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation-error/actions.js +2 -0
- package/dist/src/document-model/gen/operation-error/actions.js.map +1 -0
- package/dist/{node/src → src}/document-model/gen/operation-error/creators.d.ts +3 -2
- package/dist/src/document-model/gen/operation-error/creators.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation-error/creators.js +17 -0
- package/dist/src/document-model/gen/operation-error/creators.js.map +1 -0
- package/dist/{node/src → src}/document-model/gen/operation-error/object.d.ts +7 -5
- package/dist/src/document-model/gen/operation-error/object.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation-error/object.js +26 -0
- package/dist/src/document-model/gen/operation-error/object.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/operation-error/operations.d.ts +3 -2
- package/dist/src/document-model/gen/operation-error/operations.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation-error/operations.js +2 -0
- package/dist/src/document-model/gen/operation-error/operations.js.map +1 -0
- package/dist/src/document-model/gen/operation-example/actions.d.ts +8 -0
- package/dist/src/document-model/gen/operation-example/actions.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation-example/actions.js +2 -0
- package/dist/src/document-model/gen/operation-example/actions.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/operation-example/creators.d.ts +3 -2
- package/dist/src/document-model/gen/operation-example/creators.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation-example/creators.js +14 -0
- package/dist/src/document-model/gen/operation-example/creators.js.map +1 -0
- package/dist/src/document-model/gen/operation-example/object.d.ts +12 -0
- package/dist/src/document-model/gen/operation-example/object.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation-example/object.js +17 -0
- package/dist/src/document-model/gen/operation-example/object.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/operation-example/operations.d.ts +3 -2
- package/dist/src/document-model/gen/operation-example/operations.d.ts.map +1 -0
- package/dist/src/document-model/gen/operation-example/operations.js +2 -0
- package/dist/src/document-model/gen/operation-example/operations.js.map +1 -0
- package/dist/src/document-model/gen/reducer.d.ts +5 -0
- package/dist/src/document-model/gen/reducer.d.ts.map +1 -0
- package/dist/src/document-model/gen/reducer.js +193 -0
- package/dist/src/document-model/gen/reducer.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/schema/types.d.ts +6 -1
- package/dist/src/document-model/gen/schema/types.d.ts.map +1 -0
- package/dist/src/document-model/gen/schema/types.js +2 -0
- package/dist/src/document-model/gen/schema/types.js.map +1 -0
- package/dist/src/document-model/gen/schema/zod.d.ts +454 -0
- package/dist/src/document-model/gen/schema/zod.d.ts.map +1 -0
- package/dist/src/document-model/gen/schema/zod.js +394 -0
- package/dist/src/document-model/gen/schema/zod.js.map +1 -0
- package/dist/src/document-model/gen/state/actions.d.ts +10 -0
- package/dist/src/document-model/gen/state/actions.d.ts.map +1 -0
- package/dist/src/document-model/gen/state/actions.js +2 -0
- package/dist/src/document-model/gen/state/actions.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/state/creators.d.ts +3 -2
- package/dist/src/document-model/gen/state/creators.d.ts.map +1 -0
- package/dist/src/document-model/gen/state/creators.js +10 -0
- package/dist/src/document-model/gen/state/creators.js.map +1 -0
- package/dist/src/document-model/gen/state/object.d.ts +13 -0
- package/dist/src/document-model/gen/state/object.d.ts.map +1 -0
- package/dist/src/document-model/gen/state/object.js +23 -0
- package/dist/src/document-model/gen/state/object.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/state/operations.d.ts +3 -2
- package/dist/src/document-model/gen/state/operations.d.ts.map +1 -0
- package/dist/src/document-model/gen/state/operations.js +2 -0
- package/dist/src/document-model/gen/state/operations.js.map +1 -0
- package/dist/src/document-model/gen/types.d.ts +7 -0
- package/dist/src/document-model/gen/types.d.ts.map +1 -0
- package/dist/src/document-model/gen/types.js +2 -0
- package/dist/src/document-model/gen/types.js.map +1 -0
- package/dist/src/document-model/gen/utils.d.ts +11 -0
- package/dist/src/document-model/gen/utils.d.ts.map +1 -0
- package/dist/src/document-model/gen/utils.js +30 -0
- package/dist/src/document-model/gen/utils.js.map +1 -0
- package/dist/src/document-model/gen/versioning/actions.d.ts +9 -0
- package/dist/src/document-model/gen/versioning/actions.d.ts.map +1 -0
- package/dist/src/document-model/gen/versioning/actions.js +2 -0
- package/dist/src/document-model/gen/versioning/actions.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/versioning/creators.d.ts +3 -2
- package/dist/src/document-model/gen/versioning/creators.d.ts.map +1 -0
- package/dist/src/document-model/gen/versioning/creators.js +13 -0
- package/dist/src/document-model/gen/versioning/creators.js.map +1 -0
- package/dist/src/document-model/gen/versioning/object.d.ts +13 -0
- package/dist/src/document-model/gen/versioning/object.d.ts.map +1 -0
- package/dist/src/document-model/gen/versioning/object.js +20 -0
- package/dist/src/document-model/gen/versioning/object.js.map +1 -0
- package/dist/{browser/src → src}/document-model/gen/versioning/operations.d.ts +3 -2
- package/dist/src/document-model/gen/versioning/operations.d.ts.map +1 -0
- package/dist/src/document-model/gen/versioning/operations.js +2 -0
- package/dist/src/document-model/gen/versioning/operations.js.map +1 -0
- package/dist/src/document-model/module.d.ts +3 -0
- package/dist/src/document-model/module.d.ts.map +1 -0
- package/dist/src/document-model/module.js +13 -0
- package/dist/src/document-model/module.js.map +1 -0
- package/dist/src/document-model/types.d.ts +4 -0
- package/dist/src/document-model/types.d.ts.map +1 -0
- package/dist/src/document-model/types.js +2 -0
- package/dist/src/document-model/types.js.map +1 -0
- package/dist/test/document/crypto.test.d.ts +2 -0
- package/dist/test/document/crypto.test.d.ts.map +1 -0
- package/dist/test/document/crypto.test.js +181 -0
- package/dist/test/document/crypto.test.js.map +1 -0
- package/dist/test/document/event-vs-command.test.d.ts +2 -0
- package/dist/test/document/event-vs-command.test.d.ts.map +1 -0
- package/dist/test/document/event-vs-command.test.js +169 -0
- package/dist/test/document/event-vs-command.test.js.map +1 -0
- package/dist/test/document/local.test.d.ts +2 -0
- package/dist/test/document/local.test.d.ts.map +1 -0
- package/dist/test/document/local.test.js +248 -0
- package/dist/test/document/local.test.js.map +1 -0
- package/dist/test/document/object.test.d.ts +2 -0
- package/dist/test/document/object.test.d.ts.map +1 -0
- package/dist/test/document/object.test.js +13 -0
- package/dist/test/document/object.test.js.map +1 -0
- package/dist/test/document/operation-id.test.d.ts +2 -0
- package/dist/test/document/operation-id.test.d.ts.map +1 -0
- package/dist/test/document/operation-id.test.js +159 -0
- package/dist/test/document/operation-id.test.js.map +1 -0
- package/dist/test/document/prune.test.d.ts +2 -0
- package/dist/test/document/prune.test.d.ts.map +1 -0
- package/dist/test/document/prune.test.js +177 -0
- package/dist/test/document/prune.test.js.map +1 -0
- package/dist/test/document/reducer.test.d.ts +2 -0
- package/dist/test/document/reducer.test.d.ts.map +1 -0
- package/dist/test/document/reducer.test.js +270 -0
- package/dist/test/document/reducer.test.js.map +1 -0
- package/dist/test/document/skip-operations.test.d.ts +2 -0
- package/dist/test/document/skip-operations.test.d.ts.map +1 -0
- package/dist/test/document/skip-operations.test.js +442 -0
- package/dist/test/document/skip-operations.test.js.map +1 -0
- package/dist/test/document/undo-redo.test.d.ts +2 -0
- package/dist/test/document/undo-redo.test.d.ts.map +1 -0
- package/dist/test/document/undo-redo.test.js +377 -0
- package/dist/test/document/undo-redo.test.js.map +1 -0
- package/dist/test/document/utils.test.d.ts +2 -0
- package/dist/test/document/utils.test.d.ts.map +1 -0
- package/dist/test/document/utils.test.js +152 -0
- package/dist/test/document/utils.test.js.map +1 -0
- package/dist/test/document-helpers/addUndo.test.d.ts +2 -0
- package/dist/test/document-helpers/addUndo.test.d.ts.map +1 -0
- package/dist/test/document-helpers/addUndo.test.js +120 -0
- package/dist/test/document-helpers/addUndo.test.js.map +1 -0
- package/dist/test/document-helpers/attachBranch.test.d.ts +2 -0
- package/dist/test/document-helpers/attachBranch.test.d.ts.map +1 -0
- package/dist/test/document-helpers/attachBranch.test.js +364 -0
- package/dist/test/document-helpers/attachBranch.test.js.map +1 -0
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +2 -0
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts.map +1 -0
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js +252 -0
- package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js.map +1 -0
- package/dist/test/document-helpers/conflictResolution.test.d.ts +2 -0
- package/dist/test/document-helpers/conflictResolution.test.d.ts.map +1 -0
- package/dist/test/document-helpers/conflictResolution.test.js +109 -0
- package/dist/test/document-helpers/conflictResolution.test.js.map +1 -0
- package/dist/test/document-helpers/filterDuplicatedOperations.test.d.ts +2 -0
- package/dist/test/document-helpers/filterDuplicatedOperations.test.d.ts.map +1 -0
- package/dist/test/document-helpers/filterDuplicatedOperations.test.js +126 -0
- package/dist/test/document-helpers/filterDuplicatedOperations.test.js.map +1 -0
- package/dist/test/document-helpers/garbageCollect.test.d.ts +2 -0
- package/dist/test/document-helpers/garbageCollect.test.d.ts.map +1 -0
- package/dist/test/document-helpers/garbageCollect.test.js +136 -0
- package/dist/test/document-helpers/garbageCollect.test.js.map +1 -0
- package/dist/test/document-helpers/groupOperationsByScope.test.d.ts +2 -0
- package/dist/test/document-helpers/groupOperationsByScope.test.d.ts.map +1 -0
- package/dist/test/document-helpers/groupOperationsByScope.test.js +98 -0
- package/dist/test/document-helpers/groupOperationsByScope.test.js.map +1 -0
- package/dist/test/document-helpers/merge.test.d.ts +2 -0
- package/dist/test/document-helpers/merge.test.d.ts.map +1 -0
- package/dist/test/document-helpers/merge.test.js +906 -0
- package/dist/test/document-helpers/merge.test.js.map +1 -0
- package/dist/test/document-helpers/nextSkipNumber.test.d.ts +2 -0
- package/dist/test/document-helpers/nextSkipNumber.test.d.ts.map +1 -0
- package/dist/test/document-helpers/nextSkipNumber.test.js +135 -0
- package/dist/test/document-helpers/nextSkipNumber.test.js.map +1 -0
- package/dist/test/document-helpers/prepareOperations.test.d.ts +2 -0
- package/dist/test/document-helpers/prepareOperations.test.d.ts.map +1 -0
- package/dist/test/document-helpers/prepareOperations.test.js +304 -0
- package/dist/test/document-helpers/prepareOperations.test.js.map +1 -0
- package/dist/test/document-helpers/removeExistingOperations.test.d.ts +2 -0
- package/dist/test/document-helpers/removeExistingOperations.test.d.ts.map +1 -0
- package/dist/test/document-helpers/removeExistingOperations.test.js +150 -0
- package/dist/test/document-helpers/removeExistingOperations.test.js.map +1 -0
- package/dist/test/document-helpers/reshuffleByTimestamp.test.d.ts +2 -0
- package/dist/test/document-helpers/reshuffleByTimestamp.test.d.ts.map +1 -0
- package/dist/test/document-helpers/reshuffleByTimestamp.test.js +148 -0
- package/dist/test/document-helpers/reshuffleByTimestamp.test.js.map +1 -0
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +2 -0
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts.map +1 -0
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js +200 -0
- package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js.map +1 -0
- package/dist/test/document-helpers/skipHeaderOperations.test.d.ts +2 -0
- package/dist/test/document-helpers/skipHeaderOperations.test.d.ts.map +1 -0
- package/dist/test/document-helpers/skipHeaderOperations.test.js +74 -0
- package/dist/test/document-helpers/skipHeaderOperations.test.js.map +1 -0
- package/dist/test/document-helpers/sortOperations.test.d.ts +2 -0
- package/dist/test/document-helpers/sortOperations.test.d.ts.map +1 -0
- package/dist/test/document-helpers/sortOperations.test.js +101 -0
- package/dist/test/document-helpers/sortOperations.test.js.map +1 -0
- package/dist/test/document-helpers/split.test.d.ts +2 -0
- package/dist/test/document-helpers/split.test.d.ts.map +1 -0
- package/dist/test/document-helpers/split.test.js +121 -0
- package/dist/test/document-helpers/split.test.js.map +1 -0
- package/dist/{browser/test → test}/document-helpers/utils.d.ts +2 -1
- package/dist/test/document-helpers/utils.d.ts.map +1 -0
- package/dist/test/document-helpers/utils.js +22 -0
- package/dist/test/document-helpers/utils.js.map +1 -0
- package/dist/test/document-model/object.test.d.ts +2 -0
- package/dist/test/document-model/object.test.d.ts.map +1 -0
- package/dist/test/document-model/object.test.js +243 -0
- package/dist/test/document-model/object.test.js.map +1 -0
- package/dist/test/document-model/replay.test.d.ts +2 -0
- package/dist/test/document-model/replay.test.d.ts.map +1 -0
- package/dist/test/document-model/replay.test.js +149 -0
- package/dist/test/document-model/replay.test.js.map +1 -0
- package/dist/test/document-model/skip-operations.test.d.ts +2 -0
- package/dist/test/document-model/skip-operations.test.d.ts.map +1 -0
- package/dist/test/document-model/skip-operations.test.js +220 -0
- package/dist/test/document-model/skip-operations.test.js.map +1 -0
- package/dist/test/document-model/validation.test.d.ts +2 -0
- package/dist/test/document-model/validation.test.d.ts.map +1 -0
- package/dist/test/document-model/validation.test.js +258 -0
- package/dist/test/document-model/validation.test.js.map +1 -0
- package/dist/test/document-model/zip.test.d.ts +2 -0
- package/dist/test/document-model/zip.test.d.ts.map +1 -0
- package/dist/test/document-model/zip.test.js +80 -0
- package/dist/test/document-model/zip.test.js.map +1 -0
- package/dist/test/helpers.d.ts +31 -0
- package/dist/test/helpers.d.ts.map +1 -0
- package/dist/test/helpers.js +71 -0
- package/dist/test/helpers.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +13 -0
- package/dist/vitest.config.js.map +1 -0
- package/package.json +27 -53
- package/dist/browser/cjs/document-model.js +0 -20
- package/dist/browser/cjs/document-model.js.map +0 -1
- package/dist/browser/cjs/document.js +0 -15
- package/dist/browser/cjs/document.js.map +0 -1
- package/dist/browser/cjs/index.js +0 -14
- package/dist/browser/cjs/index.js.map +0 -1
- package/dist/browser/cjs/internal/index-DyKphRZa.js +0 -2215
- package/dist/browser/cjs/internal/index-DyKphRZa.js.map +0 -1
- package/dist/browser/cjs/internal/index-y9w_m1Lo.js +0 -57
- package/dist/browser/cjs/internal/index-y9w_m1Lo.js.map +0 -1
- package/dist/browser/cjs/internal/object-Dbc1GbBl.js +0 -2694
- package/dist/browser/cjs/internal/object-Dbc1GbBl.js.map +0 -1
- package/dist/browser/cjs/package.json +0 -1
- package/dist/browser/document-model.d.ts +0 -2
- package/dist/browser/document.d.ts +0 -2
- package/dist/browser/es/document-model.js +0 -20
- package/dist/browser/es/document-model.js.map +0 -1
- package/dist/browser/es/document.js +0 -15
- package/dist/browser/es/document.js.map +0 -1
- package/dist/browser/es/index.js +0 -14
- package/dist/browser/es/index.js.map +0 -1
- package/dist/browser/es/internal/index-BI16PNmr.js +0 -58
- package/dist/browser/es/internal/index-BI16PNmr.js.map +0 -1
- package/dist/browser/es/internal/index-CiQX4huJ.js +0 -2216
- package/dist/browser/es/internal/index-CiQX4huJ.js.map +0 -1
- package/dist/browser/es/internal/object-BTIqCvb-.js +0 -2695
- package/dist/browser/es/internal/object-BTIqCvb-.js.map +0 -1
- package/dist/browser/es/package.json +0 -1
- package/dist/browser/index.d.ts +0 -6
- package/dist/browser/src/document/actions/index.d.ts +0 -14
- package/dist/browser/src/document/actions/types.d.ts +0 -15
- package/dist/browser/src/document/index.d.ts +0 -6
- package/dist/browser/src/document/reducer.d.ts +0 -65
- package/dist/browser/src/document/schema/index.d.ts +0 -2
- package/dist/browser/src/document/signal.d.ts +0 -29
- package/dist/browser/src/document/types.d.ts +0 -271
- package/dist/browser/src/document/utils/base.d.ts +0 -87
- package/dist/browser/src/document/utils/crypto.d.ts +0 -9
- package/dist/browser/src/document/utils/document-helpers.d.ts +0 -73
- package/dist/browser/src/document/utils/file.d.ts +0 -48
- package/dist/browser/src/document/utils/index.d.ts +0 -6
- package/dist/browser/src/document/utils/node.d.ts +0 -9
- package/dist/browser/src/document/utils/validation.d.ts +0 -2
- package/dist/browser/src/document-model/custom/reducers/header.d.ts +0 -2
- package/dist/browser/src/document-model/custom/reducers/module.d.ts +0 -2
- package/dist/browser/src/document-model/custom/reducers/operation-error.d.ts +0 -2
- package/dist/browser/src/document-model/custom/reducers/operation-example.d.ts +0 -2
- package/dist/browser/src/document-model/custom/reducers/operation.d.ts +0 -2
- package/dist/browser/src/document-model/custom/reducers/state.d.ts +0 -2
- package/dist/browser/src/document-model/custom/reducers/versioning.d.ts +0 -2
- package/dist/browser/src/document-model/gen/actions.d.ts +0 -15
- package/dist/browser/src/document-model/gen/creators.d.ts +0 -7
- package/dist/browser/src/document-model/gen/document-model.d.ts +0 -2
- package/dist/browser/src/document-model/gen/header/actions.d.ts +0 -9
- package/dist/browser/src/document-model/gen/header/creators.d.ts +0 -8
- package/dist/browser/src/document-model/gen/header/object.d.ts +0 -12
- package/dist/browser/src/document-model/gen/header/operations.d.ts +0 -10
- package/dist/browser/src/document-model/gen/index.d.ts +0 -5
- package/dist/browser/src/document-model/gen/module/actions.d.ts +0 -8
- package/dist/browser/src/document-model/gen/module/creators.d.ts +0 -7
- package/dist/browser/src/document-model/gen/module/object.d.ts +0 -11
- package/dist/browser/src/document-model/gen/object.d.ts +0 -28
- package/dist/browser/src/document-model/gen/operation/actions.d.ts +0 -13
- package/dist/browser/src/document-model/gen/operation/object.d.ts +0 -16
- package/dist/browser/src/document-model/gen/operation/operations.d.ts +0 -14
- package/dist/browser/src/document-model/gen/operation-error/actions.d.ts +0 -10
- package/dist/browser/src/document-model/gen/operation-error/creators.d.ts +0 -9
- package/dist/browser/src/document-model/gen/operation-error/object.d.ts +0 -13
- package/dist/browser/src/document-model/gen/operation-example/actions.d.ts +0 -7
- package/dist/browser/src/document-model/gen/operation-example/object.d.ts +0 -10
- package/dist/browser/src/document-model/gen/reducer.d.ts +0 -5
- package/dist/browser/src/document-model/gen/schema/index.d.ts +0 -2
- package/dist/browser/src/document-model/gen/schema/zod.d.ts +0 -453
- package/dist/browser/src/document-model/gen/state/actions.d.ts +0 -9
- package/dist/browser/src/document-model/gen/state/object.d.ts +0 -12
- package/dist/browser/src/document-model/gen/types.d.ts +0 -8
- package/dist/browser/src/document-model/gen/utils.d.ts +0 -6
- package/dist/browser/src/document-model/gen/versioning/actions.d.ts +0 -8
- package/dist/browser/src/document-model/gen/versioning/object.d.ts +0 -11
- package/dist/browser/src/document-model/index.d.ts +0 -76
- package/dist/browser/src/index.d.ts +0 -24
- package/dist/browser/test/document/crypto.test.d.ts +0 -1
- package/dist/browser/test/document/event-vs-command.test.d.ts +0 -1
- package/dist/browser/test/document/local.test.d.ts +0 -1
- package/dist/browser/test/document/object.test.d.ts +0 -1
- package/dist/browser/test/document/operation-id.test.d.ts +0 -1
- package/dist/browser/test/document/prune.test.d.ts +0 -1
- package/dist/browser/test/document/reducer.test.d.ts +0 -1
- package/dist/browser/test/document/skip-operations.test.d.ts +0 -1
- package/dist/browser/test/document/undo-redo.test.d.ts +0 -1
- package/dist/browser/test/document/utils.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/addUndo.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/attachBranch.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/conflictResolution.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/filterDuplicatedOperations.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/garbageCollect.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/groupOperationsByScope.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/merge.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/nextSkipNumber.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/prepareOperations.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/removeExistingOperations.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/reshuffleByTimestamp.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/skipHeaderOperations.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/sortOperations.test.d.ts +0 -1
- package/dist/browser/test/document-helpers/split.test.d.ts +0 -1
- package/dist/browser/test/document-model/object.test.d.ts +0 -1
- package/dist/browser/test/document-model/replay.test.d.ts +0 -1
- package/dist/browser/test/document-model/skip-operations.test.d.ts +0 -1
- package/dist/browser/test/document-model/validation.test.d.ts +0 -1
- package/dist/browser/test/document-model/zip.test.d.ts +0 -1
- package/dist/browser/test/helpers.d.ts +0 -39
- package/dist/browser/vite.config.d.ts +0 -2
- package/dist/browser/vitest.config.d.ts +0 -2
- package/dist/node/cjs/document-model.js +0 -24
- package/dist/node/cjs/document-model.js.map +0 -1
- package/dist/node/cjs/document.js +0 -15
- package/dist/node/cjs/document.js.map +0 -1
- package/dist/node/cjs/index.js +0 -14
- package/dist/node/cjs/index.js.map +0 -1
- package/dist/node/cjs/internal/index-CLCVBs4I.js +0 -57
- package/dist/node/cjs/internal/index-CLCVBs4I.js.map +0 -1
- package/dist/node/cjs/internal/index-Cp37sm40.js +0 -2219
- package/dist/node/cjs/internal/index-Cp37sm40.js.map +0 -1
- package/dist/node/cjs/internal/object-ByNZ3G_j.js +0 -2480
- package/dist/node/cjs/internal/object-ByNZ3G_j.js.map +0 -1
- package/dist/node/cjs/package.json +0 -1
- package/dist/node/document-model.d.ts +0 -2
- package/dist/node/document.d.ts +0 -2
- package/dist/node/es/document-model.js +0 -24
- package/dist/node/es/document-model.js.map +0 -1
- package/dist/node/es/document.js +0 -15
- package/dist/node/es/document.js.map +0 -1
- package/dist/node/es/index.js +0 -14
- package/dist/node/es/index.js.map +0 -1
- package/dist/node/es/internal/index-BXfMlE4L.js +0 -58
- package/dist/node/es/internal/index-BXfMlE4L.js.map +0 -1
- package/dist/node/es/internal/index-ppDSDiFU.js +0 -2220
- package/dist/node/es/internal/index-ppDSDiFU.js.map +0 -1
- package/dist/node/es/internal/object-C8sca9DR.js +0 -2481
- package/dist/node/es/internal/object-C8sca9DR.js.map +0 -1
- package/dist/node/es/package.json +0 -1
- package/dist/node/index.d.ts +0 -6
- package/dist/node/src/document/actions/index.d.ts +0 -14
- package/dist/node/src/document/actions/types.d.ts +0 -15
- package/dist/node/src/document/index.d.ts +0 -6
- package/dist/node/src/document/reducer.d.ts +0 -65
- package/dist/node/src/document/schema/index.d.ts +0 -2
- package/dist/node/src/document/schema/types.d.ts +0 -176
- package/dist/node/src/document/schema/zod.d.ts +0 -116
- package/dist/node/src/document/types.d.ts +0 -271
- package/dist/node/src/document/utils/base.d.ts +0 -87
- package/dist/node/src/document/utils/crypto.d.ts +0 -9
- package/dist/node/src/document/utils/document-helpers.d.ts +0 -73
- package/dist/node/src/document/utils/index.d.ts +0 -6
- package/dist/node/src/document/utils/node.d.ts +0 -9
- package/dist/node/src/document/utils/validation.d.ts +0 -2
- package/dist/node/src/document-model/custom/reducers/header.d.ts +0 -2
- package/dist/node/src/document-model/custom/reducers/module.d.ts +0 -2
- package/dist/node/src/document-model/custom/reducers/operation-error.d.ts +0 -2
- package/dist/node/src/document-model/custom/reducers/operation-example.d.ts +0 -2
- package/dist/node/src/document-model/custom/reducers/operation.d.ts +0 -2
- package/dist/node/src/document-model/custom/reducers/state.d.ts +0 -2
- package/dist/node/src/document-model/custom/reducers/versioning.d.ts +0 -2
- package/dist/node/src/document-model/custom/utils.d.ts +0 -7
- package/dist/node/src/document-model/gen/actions.d.ts +0 -15
- package/dist/node/src/document-model/gen/creators.d.ts +0 -7
- package/dist/node/src/document-model/gen/document-model.d.ts +0 -2
- package/dist/node/src/document-model/gen/header/actions.d.ts +0 -9
- package/dist/node/src/document-model/gen/header/object.d.ts +0 -12
- package/dist/node/src/document-model/gen/index.d.ts +0 -5
- package/dist/node/src/document-model/gen/module/actions.d.ts +0 -8
- package/dist/node/src/document-model/gen/module/object.d.ts +0 -11
- package/dist/node/src/document-model/gen/module/operations.d.ts +0 -9
- package/dist/node/src/document-model/gen/object.d.ts +0 -28
- package/dist/node/src/document-model/gen/operation/actions.d.ts +0 -13
- package/dist/node/src/document-model/gen/operation/creators.d.ts +0 -12
- package/dist/node/src/document-model/gen/operation-error/actions.d.ts +0 -10
- package/dist/node/src/document-model/gen/operation-error/operations.d.ts +0 -11
- package/dist/node/src/document-model/gen/operation-example/actions.d.ts +0 -7
- package/dist/node/src/document-model/gen/operation-example/creators.d.ts +0 -6
- package/dist/node/src/document-model/gen/operation-example/object.d.ts +0 -10
- package/dist/node/src/document-model/gen/operation-example/operations.d.ts +0 -8
- package/dist/node/src/document-model/gen/reducer.d.ts +0 -5
- package/dist/node/src/document-model/gen/schema/index.d.ts +0 -2
- package/dist/node/src/document-model/gen/schema/types.d.ts +0 -453
- package/dist/node/src/document-model/gen/schema/zod.d.ts +0 -453
- package/dist/node/src/document-model/gen/state/actions.d.ts +0 -9
- package/dist/node/src/document-model/gen/state/creators.d.ts +0 -8
- package/dist/node/src/document-model/gen/state/object.d.ts +0 -12
- package/dist/node/src/document-model/gen/state/operations.d.ts +0 -10
- package/dist/node/src/document-model/gen/types.d.ts +0 -8
- package/dist/node/src/document-model/gen/utils.d.ts +0 -6
- package/dist/node/src/document-model/gen/versioning/actions.d.ts +0 -8
- package/dist/node/src/document-model/gen/versioning/creators.d.ts +0 -7
- package/dist/node/src/document-model/gen/versioning/object.d.ts +0 -11
- package/dist/node/src/document-model/gen/versioning/operations.d.ts +0 -9
- package/dist/node/src/document-model/index.d.ts +0 -76
- package/dist/node/src/index.d.ts +0 -24
- package/dist/node/test/document/crypto.test.d.ts +0 -1
- package/dist/node/test/document/event-vs-command.test.d.ts +0 -1
- package/dist/node/test/document/local.test.d.ts +0 -1
- package/dist/node/test/document/object.test.d.ts +0 -1
- package/dist/node/test/document/operation-id.test.d.ts +0 -1
- package/dist/node/test/document/prune.test.d.ts +0 -1
- package/dist/node/test/document/reducer.test.d.ts +0 -1
- package/dist/node/test/document/skip-operations.test.d.ts +0 -1
- package/dist/node/test/document/undo-redo.test.d.ts +0 -1
- package/dist/node/test/document/utils.test.d.ts +0 -1
- package/dist/node/test/document-helpers/addUndo.test.d.ts +0 -1
- package/dist/node/test/document-helpers/attachBranch.test.d.ts +0 -1
- package/dist/node/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +0 -1
- package/dist/node/test/document-helpers/conflictResolution.test.d.ts +0 -1
- package/dist/node/test/document-helpers/filterDuplicatedOperations.test.d.ts +0 -1
- package/dist/node/test/document-helpers/garbageCollect.test.d.ts +0 -1
- package/dist/node/test/document-helpers/groupOperationsByScope.test.d.ts +0 -1
- package/dist/node/test/document-helpers/merge.test.d.ts +0 -1
- package/dist/node/test/document-helpers/nextSkipNumber.test.d.ts +0 -1
- package/dist/node/test/document-helpers/prepareOperations.test.d.ts +0 -1
- package/dist/node/test/document-helpers/removeExistingOperations.test.d.ts +0 -1
- package/dist/node/test/document-helpers/reshuffleByTimestamp.test.d.ts +0 -1
- package/dist/node/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +0 -1
- package/dist/node/test/document-helpers/skipHeaderOperations.test.d.ts +0 -1
- package/dist/node/test/document-helpers/sortOperations.test.d.ts +0 -1
- package/dist/node/test/document-helpers/split.test.d.ts +0 -1
- package/dist/node/test/document-helpers/utils.d.ts +0 -7
- package/dist/node/test/document-model/object.test.d.ts +0 -1
- package/dist/node/test/document-model/replay.test.d.ts +0 -1
- package/dist/node/test/document-model/skip-operations.test.d.ts +0 -1
- package/dist/node/test/document-model/validation.test.d.ts +0 -1
- package/dist/node/test/document-model/zip.test.d.ts +0 -1
- package/dist/node/test/helpers.d.ts +0 -39
- package/dist/node/vite.config.d.ts +0 -2
- package/dist/node/vitest.config.d.ts +0 -2
|
@@ -1,2481 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { create, castDraft, unsafe } from "mutative";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
import crypto$1 from "crypto";
|
|
7
|
-
import fs from "fs";
|
|
8
|
-
import https from "https";
|
|
9
|
-
import { join } from "path";
|
|
10
|
-
import JSZip from "jszip";
|
|
11
|
-
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
|
|
12
|
-
const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v));
|
|
13
|
-
const Load_StateSchema = z.enum(["LOAD_STATE"]);
|
|
14
|
-
const PruneSchema = z.enum(["PRUNE"]);
|
|
15
|
-
const RedoSchema = z.enum(["REDO"]);
|
|
16
|
-
const Set_NameSchema = z.enum(["SET_NAME"]);
|
|
17
|
-
const UndoSchema = z.enum(["UNDO"]);
|
|
18
|
-
function ActionSchema() {
|
|
19
|
-
return z.object({
|
|
20
|
-
__typename: z.literal("Action").optional(),
|
|
21
|
-
type: z.string()
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
function OperationScopeSchema() {
|
|
25
|
-
return z.literal("global").or(z.literal("local"));
|
|
26
|
-
}
|
|
27
|
-
function BaseActionSchema() {
|
|
28
|
-
return z.union([
|
|
29
|
-
LoadStateActionSchema(),
|
|
30
|
-
PruneActionSchema(),
|
|
31
|
-
RedoActionSchema(),
|
|
32
|
-
SetNameActionSchema(),
|
|
33
|
-
UndoActionSchema()
|
|
34
|
-
]);
|
|
35
|
-
}
|
|
36
|
-
function DocumentFileSchema() {
|
|
37
|
-
return z.object({
|
|
38
|
-
__typename: z.literal("DocumentFile").optional(),
|
|
39
|
-
data: z.string(),
|
|
40
|
-
extension: z.string().nullable(),
|
|
41
|
-
fileName: z.string().nullable(),
|
|
42
|
-
mimeType: z.string()
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function LoadStateActionSchema() {
|
|
46
|
-
return z.object({
|
|
47
|
-
input: z.lazy(() => LoadStateActionInputSchema()),
|
|
48
|
-
type: Load_StateSchema,
|
|
49
|
-
scope: OperationScopeSchema()
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function LoadStateActionInputSchema() {
|
|
53
|
-
return z.object({
|
|
54
|
-
operations: z.number(),
|
|
55
|
-
state: z.lazy(() => LoadStateActionStateInputSchema())
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
function LoadStateActionStateInputSchema() {
|
|
59
|
-
return z.object({
|
|
60
|
-
data: z.unknown().nullish(),
|
|
61
|
-
name: z.string()
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
function OperationSchema() {
|
|
65
|
-
return z.object({
|
|
66
|
-
__typename: z.literal("Operation").optional(),
|
|
67
|
-
hash: z.string(),
|
|
68
|
-
index: z.number(),
|
|
69
|
-
timestamp: z.string().datetime(),
|
|
70
|
-
type: z.string()
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function PruneActionSchema() {
|
|
74
|
-
return z.object({
|
|
75
|
-
input: z.lazy(() => PruneActionInputSchema()),
|
|
76
|
-
type: PruneSchema,
|
|
77
|
-
scope: OperationScopeSchema()
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function PruneActionInputSchema() {
|
|
81
|
-
return z.object({
|
|
82
|
-
end: z.number().nullish(),
|
|
83
|
-
start: z.number().nullish()
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
const RedoActionInputSchema = z.number;
|
|
87
|
-
function RedoActionSchema() {
|
|
88
|
-
return z.object({
|
|
89
|
-
input: RedoActionInputSchema(),
|
|
90
|
-
type: RedoSchema,
|
|
91
|
-
scope: OperationScopeSchema()
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
const SetNameActionInputSchema = z.string;
|
|
95
|
-
function SetNameActionSchema() {
|
|
96
|
-
return z.object({
|
|
97
|
-
input: SetNameActionInputSchema(),
|
|
98
|
-
type: Set_NameSchema,
|
|
99
|
-
scope: z.literal("global")
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
function SetNameOperationSchema() {
|
|
103
|
-
return z.object({
|
|
104
|
-
__typename: z.literal("SetNameOperation").optional(),
|
|
105
|
-
hash: z.string(),
|
|
106
|
-
index: z.number(),
|
|
107
|
-
input: z.string(),
|
|
108
|
-
timestamp: z.string().datetime(),
|
|
109
|
-
type: z.string()
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
const UndoActionInputSchema = z.number;
|
|
113
|
-
function UndoActionSchema() {
|
|
114
|
-
return z.object({
|
|
115
|
-
input: UndoActionInputSchema(),
|
|
116
|
-
type: UndoSchema,
|
|
117
|
-
scope: OperationScopeSchema()
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
const zod = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
121
|
-
__proto__: null,
|
|
122
|
-
ActionSchema,
|
|
123
|
-
BaseActionSchema,
|
|
124
|
-
DocumentFileSchema,
|
|
125
|
-
LoadStateActionInputSchema,
|
|
126
|
-
LoadStateActionSchema,
|
|
127
|
-
LoadStateActionStateInputSchema,
|
|
128
|
-
Load_StateSchema,
|
|
129
|
-
OperationSchema,
|
|
130
|
-
OperationScopeSchema,
|
|
131
|
-
PruneActionInputSchema,
|
|
132
|
-
PruneActionSchema,
|
|
133
|
-
PruneSchema,
|
|
134
|
-
RedoActionInputSchema,
|
|
135
|
-
RedoActionSchema,
|
|
136
|
-
RedoSchema,
|
|
137
|
-
SetNameActionInputSchema,
|
|
138
|
-
SetNameActionSchema,
|
|
139
|
-
SetNameOperationSchema,
|
|
140
|
-
Set_NameSchema,
|
|
141
|
-
UndoActionInputSchema,
|
|
142
|
-
UndoActionSchema,
|
|
143
|
-
UndoSchema,
|
|
144
|
-
definedNonNullAnySchema,
|
|
145
|
-
isDefinedNonNullAny
|
|
146
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
147
|
-
function getDefaultExportFromCjs(x) {
|
|
148
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
149
|
-
}
|
|
150
|
-
var safeStableStringify = { exports: {} };
|
|
151
|
-
(function(module, exports) {
|
|
152
|
-
const { hasOwnProperty } = Object.prototype;
|
|
153
|
-
const stringify = configure();
|
|
154
|
-
stringify.configure = configure;
|
|
155
|
-
stringify.stringify = stringify;
|
|
156
|
-
stringify.default = stringify;
|
|
157
|
-
exports.stringify = stringify;
|
|
158
|
-
exports.configure = configure;
|
|
159
|
-
module.exports = stringify;
|
|
160
|
-
const strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;
|
|
161
|
-
function strEscape(str) {
|
|
162
|
-
if (str.length < 5e3 && !strEscapeSequencesRegExp.test(str)) {
|
|
163
|
-
return `"${str}"`;
|
|
164
|
-
}
|
|
165
|
-
return JSON.stringify(str);
|
|
166
|
-
}
|
|
167
|
-
function sort(array, comparator) {
|
|
168
|
-
if (array.length > 200 || comparator) {
|
|
169
|
-
return array.sort(comparator);
|
|
170
|
-
}
|
|
171
|
-
for (let i = 1; i < array.length; i++) {
|
|
172
|
-
const currentValue = array[i];
|
|
173
|
-
let position = i;
|
|
174
|
-
while (position !== 0 && array[position - 1] > currentValue) {
|
|
175
|
-
array[position] = array[position - 1];
|
|
176
|
-
position--;
|
|
177
|
-
}
|
|
178
|
-
array[position] = currentValue;
|
|
179
|
-
}
|
|
180
|
-
return array;
|
|
181
|
-
}
|
|
182
|
-
const typedArrayPrototypeGetSymbolToStringTag = Object.getOwnPropertyDescriptor(
|
|
183
|
-
Object.getPrototypeOf(
|
|
184
|
-
Object.getPrototypeOf(
|
|
185
|
-
new Int8Array()
|
|
186
|
-
)
|
|
187
|
-
),
|
|
188
|
-
Symbol.toStringTag
|
|
189
|
-
).get;
|
|
190
|
-
function isTypedArrayWithEntries(value) {
|
|
191
|
-
return typedArrayPrototypeGetSymbolToStringTag.call(value) !== void 0 && value.length !== 0;
|
|
192
|
-
}
|
|
193
|
-
function stringifyTypedArray(array, separator, maximumBreadth) {
|
|
194
|
-
if (array.length < maximumBreadth) {
|
|
195
|
-
maximumBreadth = array.length;
|
|
196
|
-
}
|
|
197
|
-
const whitespace = separator === "," ? "" : " ";
|
|
198
|
-
let res = `"0":${whitespace}${array[0]}`;
|
|
199
|
-
for (let i = 1; i < maximumBreadth; i++) {
|
|
200
|
-
res += `${separator}"${i}":${whitespace}${array[i]}`;
|
|
201
|
-
}
|
|
202
|
-
return res;
|
|
203
|
-
}
|
|
204
|
-
function getCircularValueOption(options) {
|
|
205
|
-
if (hasOwnProperty.call(options, "circularValue")) {
|
|
206
|
-
const circularValue = options.circularValue;
|
|
207
|
-
if (typeof circularValue === "string") {
|
|
208
|
-
return `"${circularValue}"`;
|
|
209
|
-
}
|
|
210
|
-
if (circularValue == null) {
|
|
211
|
-
return circularValue;
|
|
212
|
-
}
|
|
213
|
-
if (circularValue === Error || circularValue === TypeError) {
|
|
214
|
-
return {
|
|
215
|
-
toString() {
|
|
216
|
-
throw new TypeError("Converting circular structure to JSON");
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined');
|
|
221
|
-
}
|
|
222
|
-
return '"[Circular]"';
|
|
223
|
-
}
|
|
224
|
-
function getDeterministicOption(options) {
|
|
225
|
-
let value;
|
|
226
|
-
if (hasOwnProperty.call(options, "deterministic")) {
|
|
227
|
-
value = options.deterministic;
|
|
228
|
-
if (typeof value !== "boolean" && typeof value !== "function") {
|
|
229
|
-
throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return value === void 0 ? true : value;
|
|
233
|
-
}
|
|
234
|
-
function getBooleanOption(options, key) {
|
|
235
|
-
let value;
|
|
236
|
-
if (hasOwnProperty.call(options, key)) {
|
|
237
|
-
value = options[key];
|
|
238
|
-
if (typeof value !== "boolean") {
|
|
239
|
-
throw new TypeError(`The "${key}" argument must be of type boolean`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return value === void 0 ? true : value;
|
|
243
|
-
}
|
|
244
|
-
function getPositiveIntegerOption(options, key) {
|
|
245
|
-
let value;
|
|
246
|
-
if (hasOwnProperty.call(options, key)) {
|
|
247
|
-
value = options[key];
|
|
248
|
-
if (typeof value !== "number") {
|
|
249
|
-
throw new TypeError(`The "${key}" argument must be of type number`);
|
|
250
|
-
}
|
|
251
|
-
if (!Number.isInteger(value)) {
|
|
252
|
-
throw new TypeError(`The "${key}" argument must be an integer`);
|
|
253
|
-
}
|
|
254
|
-
if (value < 1) {
|
|
255
|
-
throw new RangeError(`The "${key}" argument must be >= 1`);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return value === void 0 ? Infinity : value;
|
|
259
|
-
}
|
|
260
|
-
function getItemCount(number) {
|
|
261
|
-
if (number === 1) {
|
|
262
|
-
return "1 item";
|
|
263
|
-
}
|
|
264
|
-
return `${number} items`;
|
|
265
|
-
}
|
|
266
|
-
function getUniqueReplacerSet(replacerArray) {
|
|
267
|
-
const replacerSet = /* @__PURE__ */ new Set();
|
|
268
|
-
for (const value of replacerArray) {
|
|
269
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
270
|
-
replacerSet.add(String(value));
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return replacerSet;
|
|
274
|
-
}
|
|
275
|
-
function getStrictOption(options) {
|
|
276
|
-
if (hasOwnProperty.call(options, "strict")) {
|
|
277
|
-
const value = options.strict;
|
|
278
|
-
if (typeof value !== "boolean") {
|
|
279
|
-
throw new TypeError('The "strict" argument must be of type boolean');
|
|
280
|
-
}
|
|
281
|
-
if (value) {
|
|
282
|
-
return (value2) => {
|
|
283
|
-
let message = `Object can not safely be stringified. Received type ${typeof value2}`;
|
|
284
|
-
if (typeof value2 !== "function") message += ` (${value2.toString()})`;
|
|
285
|
-
throw new Error(message);
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
function configure(options) {
|
|
291
|
-
options = { ...options };
|
|
292
|
-
const fail = getStrictOption(options);
|
|
293
|
-
if (fail) {
|
|
294
|
-
if (options.bigint === void 0) {
|
|
295
|
-
options.bigint = false;
|
|
296
|
-
}
|
|
297
|
-
if (!("circularValue" in options)) {
|
|
298
|
-
options.circularValue = Error;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
const circularValue = getCircularValueOption(options);
|
|
302
|
-
const bigint = getBooleanOption(options, "bigint");
|
|
303
|
-
const deterministic = getDeterministicOption(options);
|
|
304
|
-
const comparator = typeof deterministic === "function" ? deterministic : void 0;
|
|
305
|
-
const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
|
|
306
|
-
const maximumBreadth = getPositiveIntegerOption(options, "maximumBreadth");
|
|
307
|
-
function stringifyFnReplacer(key, parent, stack, replacer, spacer, indentation) {
|
|
308
|
-
let value = parent[key];
|
|
309
|
-
if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
|
|
310
|
-
value = value.toJSON(key);
|
|
311
|
-
}
|
|
312
|
-
value = replacer.call(parent, key, value);
|
|
313
|
-
switch (typeof value) {
|
|
314
|
-
case "string":
|
|
315
|
-
return strEscape(value);
|
|
316
|
-
case "object": {
|
|
317
|
-
if (value === null) {
|
|
318
|
-
return "null";
|
|
319
|
-
}
|
|
320
|
-
if (stack.indexOf(value) !== -1) {
|
|
321
|
-
return circularValue;
|
|
322
|
-
}
|
|
323
|
-
let res = "";
|
|
324
|
-
let join2 = ",";
|
|
325
|
-
const originalIndentation = indentation;
|
|
326
|
-
if (Array.isArray(value)) {
|
|
327
|
-
if (value.length === 0) {
|
|
328
|
-
return "[]";
|
|
329
|
-
}
|
|
330
|
-
if (maximumDepth < stack.length + 1) {
|
|
331
|
-
return '"[Array]"';
|
|
332
|
-
}
|
|
333
|
-
stack.push(value);
|
|
334
|
-
if (spacer !== "") {
|
|
335
|
-
indentation += spacer;
|
|
336
|
-
res += `
|
|
337
|
-
${indentation}`;
|
|
338
|
-
join2 = `,
|
|
339
|
-
${indentation}`;
|
|
340
|
-
}
|
|
341
|
-
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
342
|
-
let i = 0;
|
|
343
|
-
for (; i < maximumValuesToStringify - 1; i++) {
|
|
344
|
-
const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
|
|
345
|
-
res += tmp2 !== void 0 ? tmp2 : "null";
|
|
346
|
-
res += join2;
|
|
347
|
-
}
|
|
348
|
-
const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
|
|
349
|
-
res += tmp !== void 0 ? tmp : "null";
|
|
350
|
-
if (value.length - 1 > maximumBreadth) {
|
|
351
|
-
const removedKeys = value.length - maximumBreadth - 1;
|
|
352
|
-
res += `${join2}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
353
|
-
}
|
|
354
|
-
if (spacer !== "") {
|
|
355
|
-
res += `
|
|
356
|
-
${originalIndentation}`;
|
|
357
|
-
}
|
|
358
|
-
stack.pop();
|
|
359
|
-
return `[${res}]`;
|
|
360
|
-
}
|
|
361
|
-
let keys = Object.keys(value);
|
|
362
|
-
const keyLength = keys.length;
|
|
363
|
-
if (keyLength === 0) {
|
|
364
|
-
return "{}";
|
|
365
|
-
}
|
|
366
|
-
if (maximumDepth < stack.length + 1) {
|
|
367
|
-
return '"[Object]"';
|
|
368
|
-
}
|
|
369
|
-
let whitespace = "";
|
|
370
|
-
let separator = "";
|
|
371
|
-
if (spacer !== "") {
|
|
372
|
-
indentation += spacer;
|
|
373
|
-
join2 = `,
|
|
374
|
-
${indentation}`;
|
|
375
|
-
whitespace = " ";
|
|
376
|
-
}
|
|
377
|
-
const maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
|
|
378
|
-
if (deterministic && !isTypedArrayWithEntries(value)) {
|
|
379
|
-
keys = sort(keys, comparator);
|
|
380
|
-
}
|
|
381
|
-
stack.push(value);
|
|
382
|
-
for (let i = 0; i < maximumPropertiesToStringify; i++) {
|
|
383
|
-
const key2 = keys[i];
|
|
384
|
-
const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
|
|
385
|
-
if (tmp !== void 0) {
|
|
386
|
-
res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
|
|
387
|
-
separator = join2;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (keyLength > maximumBreadth) {
|
|
391
|
-
const removedKeys = keyLength - maximumBreadth;
|
|
392
|
-
res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
|
|
393
|
-
separator = join2;
|
|
394
|
-
}
|
|
395
|
-
if (spacer !== "" && separator.length > 1) {
|
|
396
|
-
res = `
|
|
397
|
-
${indentation}${res}
|
|
398
|
-
${originalIndentation}`;
|
|
399
|
-
}
|
|
400
|
-
stack.pop();
|
|
401
|
-
return `{${res}}`;
|
|
402
|
-
}
|
|
403
|
-
case "number":
|
|
404
|
-
return isFinite(value) ? String(value) : fail ? fail(value) : "null";
|
|
405
|
-
case "boolean":
|
|
406
|
-
return value === true ? "true" : "false";
|
|
407
|
-
case "undefined":
|
|
408
|
-
return void 0;
|
|
409
|
-
case "bigint":
|
|
410
|
-
if (bigint) {
|
|
411
|
-
return String(value);
|
|
412
|
-
}
|
|
413
|
-
default:
|
|
414
|
-
return fail ? fail(value) : void 0;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
function stringifyArrayReplacer(key, value, stack, replacer, spacer, indentation) {
|
|
418
|
-
if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
|
|
419
|
-
value = value.toJSON(key);
|
|
420
|
-
}
|
|
421
|
-
switch (typeof value) {
|
|
422
|
-
case "string":
|
|
423
|
-
return strEscape(value);
|
|
424
|
-
case "object": {
|
|
425
|
-
if (value === null) {
|
|
426
|
-
return "null";
|
|
427
|
-
}
|
|
428
|
-
if (stack.indexOf(value) !== -1) {
|
|
429
|
-
return circularValue;
|
|
430
|
-
}
|
|
431
|
-
const originalIndentation = indentation;
|
|
432
|
-
let res = "";
|
|
433
|
-
let join2 = ",";
|
|
434
|
-
if (Array.isArray(value)) {
|
|
435
|
-
if (value.length === 0) {
|
|
436
|
-
return "[]";
|
|
437
|
-
}
|
|
438
|
-
if (maximumDepth < stack.length + 1) {
|
|
439
|
-
return '"[Array]"';
|
|
440
|
-
}
|
|
441
|
-
stack.push(value);
|
|
442
|
-
if (spacer !== "") {
|
|
443
|
-
indentation += spacer;
|
|
444
|
-
res += `
|
|
445
|
-
${indentation}`;
|
|
446
|
-
join2 = `,
|
|
447
|
-
${indentation}`;
|
|
448
|
-
}
|
|
449
|
-
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
450
|
-
let i = 0;
|
|
451
|
-
for (; i < maximumValuesToStringify - 1; i++) {
|
|
452
|
-
const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
|
|
453
|
-
res += tmp2 !== void 0 ? tmp2 : "null";
|
|
454
|
-
res += join2;
|
|
455
|
-
}
|
|
456
|
-
const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
|
|
457
|
-
res += tmp !== void 0 ? tmp : "null";
|
|
458
|
-
if (value.length - 1 > maximumBreadth) {
|
|
459
|
-
const removedKeys = value.length - maximumBreadth - 1;
|
|
460
|
-
res += `${join2}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
461
|
-
}
|
|
462
|
-
if (spacer !== "") {
|
|
463
|
-
res += `
|
|
464
|
-
${originalIndentation}`;
|
|
465
|
-
}
|
|
466
|
-
stack.pop();
|
|
467
|
-
return `[${res}]`;
|
|
468
|
-
}
|
|
469
|
-
stack.push(value);
|
|
470
|
-
let whitespace = "";
|
|
471
|
-
if (spacer !== "") {
|
|
472
|
-
indentation += spacer;
|
|
473
|
-
join2 = `,
|
|
474
|
-
${indentation}`;
|
|
475
|
-
whitespace = " ";
|
|
476
|
-
}
|
|
477
|
-
let separator = "";
|
|
478
|
-
for (const key2 of replacer) {
|
|
479
|
-
const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
|
|
480
|
-
if (tmp !== void 0) {
|
|
481
|
-
res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
|
|
482
|
-
separator = join2;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
if (spacer !== "" && separator.length > 1) {
|
|
486
|
-
res = `
|
|
487
|
-
${indentation}${res}
|
|
488
|
-
${originalIndentation}`;
|
|
489
|
-
}
|
|
490
|
-
stack.pop();
|
|
491
|
-
return `{${res}}`;
|
|
492
|
-
}
|
|
493
|
-
case "number":
|
|
494
|
-
return isFinite(value) ? String(value) : fail ? fail(value) : "null";
|
|
495
|
-
case "boolean":
|
|
496
|
-
return value === true ? "true" : "false";
|
|
497
|
-
case "undefined":
|
|
498
|
-
return void 0;
|
|
499
|
-
case "bigint":
|
|
500
|
-
if (bigint) {
|
|
501
|
-
return String(value);
|
|
502
|
-
}
|
|
503
|
-
default:
|
|
504
|
-
return fail ? fail(value) : void 0;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
function stringifyIndent(key, value, stack, spacer, indentation) {
|
|
508
|
-
switch (typeof value) {
|
|
509
|
-
case "string":
|
|
510
|
-
return strEscape(value);
|
|
511
|
-
case "object": {
|
|
512
|
-
if (value === null) {
|
|
513
|
-
return "null";
|
|
514
|
-
}
|
|
515
|
-
if (typeof value.toJSON === "function") {
|
|
516
|
-
value = value.toJSON(key);
|
|
517
|
-
if (typeof value !== "object") {
|
|
518
|
-
return stringifyIndent(key, value, stack, spacer, indentation);
|
|
519
|
-
}
|
|
520
|
-
if (value === null) {
|
|
521
|
-
return "null";
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
if (stack.indexOf(value) !== -1) {
|
|
525
|
-
return circularValue;
|
|
526
|
-
}
|
|
527
|
-
const originalIndentation = indentation;
|
|
528
|
-
if (Array.isArray(value)) {
|
|
529
|
-
if (value.length === 0) {
|
|
530
|
-
return "[]";
|
|
531
|
-
}
|
|
532
|
-
if (maximumDepth < stack.length + 1) {
|
|
533
|
-
return '"[Array]"';
|
|
534
|
-
}
|
|
535
|
-
stack.push(value);
|
|
536
|
-
indentation += spacer;
|
|
537
|
-
let res2 = `
|
|
538
|
-
${indentation}`;
|
|
539
|
-
const join3 = `,
|
|
540
|
-
${indentation}`;
|
|
541
|
-
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
542
|
-
let i = 0;
|
|
543
|
-
for (; i < maximumValuesToStringify - 1; i++) {
|
|
544
|
-
const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
|
|
545
|
-
res2 += tmp2 !== void 0 ? tmp2 : "null";
|
|
546
|
-
res2 += join3;
|
|
547
|
-
}
|
|
548
|
-
const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
|
|
549
|
-
res2 += tmp !== void 0 ? tmp : "null";
|
|
550
|
-
if (value.length - 1 > maximumBreadth) {
|
|
551
|
-
const removedKeys = value.length - maximumBreadth - 1;
|
|
552
|
-
res2 += `${join3}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
553
|
-
}
|
|
554
|
-
res2 += `
|
|
555
|
-
${originalIndentation}`;
|
|
556
|
-
stack.pop();
|
|
557
|
-
return `[${res2}]`;
|
|
558
|
-
}
|
|
559
|
-
let keys = Object.keys(value);
|
|
560
|
-
const keyLength = keys.length;
|
|
561
|
-
if (keyLength === 0) {
|
|
562
|
-
return "{}";
|
|
563
|
-
}
|
|
564
|
-
if (maximumDepth < stack.length + 1) {
|
|
565
|
-
return '"[Object]"';
|
|
566
|
-
}
|
|
567
|
-
indentation += spacer;
|
|
568
|
-
const join2 = `,
|
|
569
|
-
${indentation}`;
|
|
570
|
-
let res = "";
|
|
571
|
-
let separator = "";
|
|
572
|
-
let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
|
|
573
|
-
if (isTypedArrayWithEntries(value)) {
|
|
574
|
-
res += stringifyTypedArray(value, join2, maximumBreadth);
|
|
575
|
-
keys = keys.slice(value.length);
|
|
576
|
-
maximumPropertiesToStringify -= value.length;
|
|
577
|
-
separator = join2;
|
|
578
|
-
}
|
|
579
|
-
if (deterministic) {
|
|
580
|
-
keys = sort(keys, comparator);
|
|
581
|
-
}
|
|
582
|
-
stack.push(value);
|
|
583
|
-
for (let i = 0; i < maximumPropertiesToStringify; i++) {
|
|
584
|
-
const key2 = keys[i];
|
|
585
|
-
const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
|
|
586
|
-
if (tmp !== void 0) {
|
|
587
|
-
res += `${separator}${strEscape(key2)}: ${tmp}`;
|
|
588
|
-
separator = join2;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
if (keyLength > maximumBreadth) {
|
|
592
|
-
const removedKeys = keyLength - maximumBreadth;
|
|
593
|
-
res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
|
|
594
|
-
separator = join2;
|
|
595
|
-
}
|
|
596
|
-
if (separator !== "") {
|
|
597
|
-
res = `
|
|
598
|
-
${indentation}${res}
|
|
599
|
-
${originalIndentation}`;
|
|
600
|
-
}
|
|
601
|
-
stack.pop();
|
|
602
|
-
return `{${res}}`;
|
|
603
|
-
}
|
|
604
|
-
case "number":
|
|
605
|
-
return isFinite(value) ? String(value) : fail ? fail(value) : "null";
|
|
606
|
-
case "boolean":
|
|
607
|
-
return value === true ? "true" : "false";
|
|
608
|
-
case "undefined":
|
|
609
|
-
return void 0;
|
|
610
|
-
case "bigint":
|
|
611
|
-
if (bigint) {
|
|
612
|
-
return String(value);
|
|
613
|
-
}
|
|
614
|
-
default:
|
|
615
|
-
return fail ? fail(value) : void 0;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
function stringifySimple(key, value, stack) {
|
|
619
|
-
switch (typeof value) {
|
|
620
|
-
case "string":
|
|
621
|
-
return strEscape(value);
|
|
622
|
-
case "object": {
|
|
623
|
-
if (value === null) {
|
|
624
|
-
return "null";
|
|
625
|
-
}
|
|
626
|
-
if (typeof value.toJSON === "function") {
|
|
627
|
-
value = value.toJSON(key);
|
|
628
|
-
if (typeof value !== "object") {
|
|
629
|
-
return stringifySimple(key, value, stack);
|
|
630
|
-
}
|
|
631
|
-
if (value === null) {
|
|
632
|
-
return "null";
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
if (stack.indexOf(value) !== -1) {
|
|
636
|
-
return circularValue;
|
|
637
|
-
}
|
|
638
|
-
let res = "";
|
|
639
|
-
const hasLength = value.length !== void 0;
|
|
640
|
-
if (hasLength && Array.isArray(value)) {
|
|
641
|
-
if (value.length === 0) {
|
|
642
|
-
return "[]";
|
|
643
|
-
}
|
|
644
|
-
if (maximumDepth < stack.length + 1) {
|
|
645
|
-
return '"[Array]"';
|
|
646
|
-
}
|
|
647
|
-
stack.push(value);
|
|
648
|
-
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
649
|
-
let i = 0;
|
|
650
|
-
for (; i < maximumValuesToStringify - 1; i++) {
|
|
651
|
-
const tmp2 = stringifySimple(String(i), value[i], stack);
|
|
652
|
-
res += tmp2 !== void 0 ? tmp2 : "null";
|
|
653
|
-
res += ",";
|
|
654
|
-
}
|
|
655
|
-
const tmp = stringifySimple(String(i), value[i], stack);
|
|
656
|
-
res += tmp !== void 0 ? tmp : "null";
|
|
657
|
-
if (value.length - 1 > maximumBreadth) {
|
|
658
|
-
const removedKeys = value.length - maximumBreadth - 1;
|
|
659
|
-
res += `,"... ${getItemCount(removedKeys)} not stringified"`;
|
|
660
|
-
}
|
|
661
|
-
stack.pop();
|
|
662
|
-
return `[${res}]`;
|
|
663
|
-
}
|
|
664
|
-
let keys = Object.keys(value);
|
|
665
|
-
const keyLength = keys.length;
|
|
666
|
-
if (keyLength === 0) {
|
|
667
|
-
return "{}";
|
|
668
|
-
}
|
|
669
|
-
if (maximumDepth < stack.length + 1) {
|
|
670
|
-
return '"[Object]"';
|
|
671
|
-
}
|
|
672
|
-
let separator = "";
|
|
673
|
-
let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
|
|
674
|
-
if (hasLength && isTypedArrayWithEntries(value)) {
|
|
675
|
-
res += stringifyTypedArray(value, ",", maximumBreadth);
|
|
676
|
-
keys = keys.slice(value.length);
|
|
677
|
-
maximumPropertiesToStringify -= value.length;
|
|
678
|
-
separator = ",";
|
|
679
|
-
}
|
|
680
|
-
if (deterministic) {
|
|
681
|
-
keys = sort(keys, comparator);
|
|
682
|
-
}
|
|
683
|
-
stack.push(value);
|
|
684
|
-
for (let i = 0; i < maximumPropertiesToStringify; i++) {
|
|
685
|
-
const key2 = keys[i];
|
|
686
|
-
const tmp = stringifySimple(key2, value[key2], stack);
|
|
687
|
-
if (tmp !== void 0) {
|
|
688
|
-
res += `${separator}${strEscape(key2)}:${tmp}`;
|
|
689
|
-
separator = ",";
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
if (keyLength > maximumBreadth) {
|
|
693
|
-
const removedKeys = keyLength - maximumBreadth;
|
|
694
|
-
res += `${separator}"...":"${getItemCount(removedKeys)} not stringified"`;
|
|
695
|
-
}
|
|
696
|
-
stack.pop();
|
|
697
|
-
return `{${res}}`;
|
|
698
|
-
}
|
|
699
|
-
case "number":
|
|
700
|
-
return isFinite(value) ? String(value) : fail ? fail(value) : "null";
|
|
701
|
-
case "boolean":
|
|
702
|
-
return value === true ? "true" : "false";
|
|
703
|
-
case "undefined":
|
|
704
|
-
return void 0;
|
|
705
|
-
case "bigint":
|
|
706
|
-
if (bigint) {
|
|
707
|
-
return String(value);
|
|
708
|
-
}
|
|
709
|
-
default:
|
|
710
|
-
return fail ? fail(value) : void 0;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
function stringify2(value, replacer, space) {
|
|
714
|
-
if (arguments.length > 1) {
|
|
715
|
-
let spacer = "";
|
|
716
|
-
if (typeof space === "number") {
|
|
717
|
-
spacer = " ".repeat(Math.min(space, 10));
|
|
718
|
-
} else if (typeof space === "string") {
|
|
719
|
-
spacer = space.slice(0, 10);
|
|
720
|
-
}
|
|
721
|
-
if (replacer != null) {
|
|
722
|
-
if (typeof replacer === "function") {
|
|
723
|
-
return stringifyFnReplacer("", { "": value }, [], replacer, spacer, "");
|
|
724
|
-
}
|
|
725
|
-
if (Array.isArray(replacer)) {
|
|
726
|
-
return stringifyArrayReplacer("", value, [], getUniqueReplacerSet(replacer), spacer, "");
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
if (spacer.length !== 0) {
|
|
730
|
-
return stringifyIndent("", value, [], spacer, "");
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
return stringifySimple("", value, []);
|
|
734
|
-
}
|
|
735
|
-
return stringify2;
|
|
736
|
-
}
|
|
737
|
-
})(safeStableStringify, safeStableStringify.exports);
|
|
738
|
-
var safeStableStringifyExports = safeStableStringify.exports;
|
|
739
|
-
const cjsModule = /* @__PURE__ */ getDefaultExportFromCjs(safeStableStringifyExports);
|
|
740
|
-
cjsModule.configure;
|
|
741
|
-
let getRandomValues;
|
|
742
|
-
const rnds8 = new Uint8Array(16);
|
|
743
|
-
function rng() {
|
|
744
|
-
if (!getRandomValues) {
|
|
745
|
-
getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
|
746
|
-
if (!getRandomValues) {
|
|
747
|
-
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return getRandomValues(rnds8);
|
|
751
|
-
}
|
|
752
|
-
const byteToHex = [];
|
|
753
|
-
for (let i = 0; i < 256; ++i) {
|
|
754
|
-
byteToHex.push((i + 256).toString(16).slice(1));
|
|
755
|
-
}
|
|
756
|
-
function unsafeStringify(arr, offset = 0) {
|
|
757
|
-
return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
|
|
758
|
-
}
|
|
759
|
-
const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
760
|
-
const native = {
|
|
761
|
-
randomUUID
|
|
762
|
-
};
|
|
763
|
-
function v4(options, buf, offset) {
|
|
764
|
-
if (native.randomUUID && !buf && !options) {
|
|
765
|
-
return native.randomUUID();
|
|
766
|
-
}
|
|
767
|
-
options = options || {};
|
|
768
|
-
const rnds = options.random || (options.rng || rng)();
|
|
769
|
-
rnds[6] = rnds[6] & 15 | 64;
|
|
770
|
-
rnds[8] = rnds[8] & 63 | 128;
|
|
771
|
-
return unsafeStringify(rnds);
|
|
772
|
-
}
|
|
773
|
-
function writeFile(path, name, data) {
|
|
774
|
-
const filePath = join(path, name);
|
|
775
|
-
fs.mkdirSync(path, { recursive: true });
|
|
776
|
-
return new Promise((resolve, reject) => {
|
|
777
|
-
try {
|
|
778
|
-
fs.writeFile(filePath, data, {}, (err) => {
|
|
779
|
-
if (err) {
|
|
780
|
-
reject(err);
|
|
781
|
-
} else {
|
|
782
|
-
resolve(filePath);
|
|
783
|
-
}
|
|
784
|
-
});
|
|
785
|
-
} catch (error) {
|
|
786
|
-
reject(error);
|
|
787
|
-
}
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
|
-
function readFile(path) {
|
|
791
|
-
return fs.readFileSync(path);
|
|
792
|
-
}
|
|
793
|
-
function fetchFile(url) {
|
|
794
|
-
return new Promise((resolve, reject) => {
|
|
795
|
-
https.get(url, (resp) => {
|
|
796
|
-
const data = [];
|
|
797
|
-
const mimeType = resp.headers["content-type"];
|
|
798
|
-
resp.on("data", (chunk) => {
|
|
799
|
-
data.push(chunk);
|
|
800
|
-
});
|
|
801
|
-
resp.on("end", () => {
|
|
802
|
-
resolve({ buffer: Buffer.concat(data), mimeType });
|
|
803
|
-
});
|
|
804
|
-
}).on("error", (err) => {
|
|
805
|
-
reject(err);
|
|
806
|
-
});
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
const getFile = async (file) => {
|
|
810
|
-
return readFile(file);
|
|
811
|
-
};
|
|
812
|
-
const hash = (data, algorithm = "sha1") => {
|
|
813
|
-
return crypto$1.createHash(algorithm).update(data).digest("base64");
|
|
814
|
-
};
|
|
815
|
-
function getUnixTimestamp(date) {
|
|
816
|
-
return (new Date(date).getTime() / 1e3).toFixed(0);
|
|
817
|
-
}
|
|
818
|
-
function buildOperationSignatureParams({
|
|
819
|
-
documentId,
|
|
820
|
-
signer,
|
|
821
|
-
operation,
|
|
822
|
-
previousStateHash
|
|
823
|
-
}) {
|
|
824
|
-
const { timestamp, scope, id, type } = operation;
|
|
825
|
-
return [
|
|
826
|
-
getUnixTimestamp(timestamp),
|
|
827
|
-
// timestamp,
|
|
828
|
-
signer.app.key,
|
|
829
|
-
// signer public key
|
|
830
|
-
hash(
|
|
831
|
-
// hash (docID, scope, operationID, operationName, operationInput)
|
|
832
|
-
[documentId, scope, id, type, cjsModule(operation.input)].join("")
|
|
833
|
-
),
|
|
834
|
-
previousStateHash
|
|
835
|
-
// state hash that the operation was applied to
|
|
836
|
-
];
|
|
837
|
-
}
|
|
838
|
-
const textEncode = new TextEncoder();
|
|
839
|
-
function buildOperationSignatureMessage(params) {
|
|
840
|
-
const message = params.join("");
|
|
841
|
-
const prefix = "Signed Operation:\n" + message.length.toString();
|
|
842
|
-
return textEncode.encode(prefix + message);
|
|
843
|
-
}
|
|
844
|
-
function ab2hex(ab) {
|
|
845
|
-
return Array.prototype.map.call(new Uint8Array(ab), (x) => ("00" + x.toString(16)).slice(-2)).join("");
|
|
846
|
-
}
|
|
847
|
-
function hex2ab(hex) {
|
|
848
|
-
var _a;
|
|
849
|
-
return new Uint8Array(
|
|
850
|
-
((_a = hex.match(/[\da-f]{2}/gi)) == null ? void 0 : _a.map(function(h) {
|
|
851
|
-
return parseInt(h, 16);
|
|
852
|
-
})) ?? []
|
|
853
|
-
);
|
|
854
|
-
}
|
|
855
|
-
async function buildOperationSignature(context, signMethod) {
|
|
856
|
-
const params = buildOperationSignatureParams(context);
|
|
857
|
-
const message = buildOperationSignatureMessage(params);
|
|
858
|
-
const signature = await signMethod(message);
|
|
859
|
-
return [...params, `0x${ab2hex(signature)}`];
|
|
860
|
-
}
|
|
861
|
-
async function buildSignedOperation(action, reducer, document, context, signHandler) {
|
|
862
|
-
var _a, _b;
|
|
863
|
-
const result = reducer(document, action, void 0, {
|
|
864
|
-
reuseHash: true,
|
|
865
|
-
reuseOperationResultingState: true
|
|
866
|
-
});
|
|
867
|
-
const operation = result.operations[action.scope].at(-1);
|
|
868
|
-
if (!operation) {
|
|
869
|
-
throw new Error("Action was not applied");
|
|
870
|
-
}
|
|
871
|
-
const previousStateHash = ((_a = result.operations[action.scope].at(-2)) == null ? void 0 : _a.hash) ?? "";
|
|
872
|
-
const signature = await buildOperationSignature(
|
|
873
|
-
{
|
|
874
|
-
...context,
|
|
875
|
-
operation,
|
|
876
|
-
previousStateHash
|
|
877
|
-
},
|
|
878
|
-
signHandler
|
|
879
|
-
);
|
|
880
|
-
return {
|
|
881
|
-
...operation,
|
|
882
|
-
context: {
|
|
883
|
-
...operation.context,
|
|
884
|
-
signer: {
|
|
885
|
-
...(_b = operation.context) == null ? void 0 : _b.signer,
|
|
886
|
-
...context.signer,
|
|
887
|
-
signatures: [...context.signer.signatures ?? [], signature]
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
async function verifyOperationSignature(signature, signer, verifyHandler) {
|
|
893
|
-
const publicKey = signer.app.key;
|
|
894
|
-
const params = signature.slice(0, 4);
|
|
895
|
-
const signatureBytes = hex2ab(signature[4]);
|
|
896
|
-
const expectedMessage = buildOperationSignatureMessage(params);
|
|
897
|
-
return verifyHandler(publicKey, signatureBytes, expectedMessage);
|
|
898
|
-
}
|
|
899
|
-
const types = { "application/andrew-inset": ["ez"], "application/appinstaller": ["appinstaller"], "application/applixware": ["aw"], "application/appx": ["appx"], "application/appxbundle": ["appxbundle"], "application/atom+xml": ["atom"], "application/atomcat+xml": ["atomcat"], "application/atomdeleted+xml": ["atomdeleted"], "application/atomsvc+xml": ["atomsvc"], "application/atsc-dwd+xml": ["dwd"], "application/atsc-held+xml": ["held"], "application/atsc-rsat+xml": ["rsat"], "application/automationml-aml+xml": ["aml"], "application/automationml-amlx+zip": ["amlx"], "application/bdoc": ["bdoc"], "application/calendar+xml": ["xcs"], "application/ccxml+xml": ["ccxml"], "application/cdfx+xml": ["cdfx"], "application/cdmi-capability": ["cdmia"], "application/cdmi-container": ["cdmic"], "application/cdmi-domain": ["cdmid"], "application/cdmi-object": ["cdmio"], "application/cdmi-queue": ["cdmiq"], "application/cpl+xml": ["cpl"], "application/cu-seeme": ["cu"], "application/cwl": ["cwl"], "application/dash+xml": ["mpd"], "application/dash-patch+xml": ["mpp"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["ecma"], "application/emma+xml": ["emma"], "application/emotionml+xml": ["emotionml"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/express": ["exp"], "application/fdf": ["fdf"], "application/fdt+xml": ["fdt"], "application/font-tdpfr": ["pfr"], "application/geo+json": ["geojson"], "application/gml+xml": ["gml"], "application/gpx+xml": ["gpx"], "application/gxf": ["gxf"], "application/gzip": ["gz"], "application/hjson": ["hjson"], "application/hyperstudio": ["stk"], "application/inkml+xml": ["ink", "inkml"], "application/ipfix": ["ipfix"], "application/its+xml": ["its"], "application/java-archive": ["jar", "war", "ear"], "application/java-serialized-object": ["ser"], "application/java-vm": ["class"], "application/javascript": ["*js"], "application/json": ["json", "map"], "application/json5": ["json5"], "application/jsonml+json": ["jsonml"], "application/ld+json": ["jsonld"], "application/lgr+xml": ["lgr"], "application/lost+xml": ["lostxml"], "application/mac-binhex40": ["hqx"], "application/mac-compactpro": ["cpt"], "application/mads+xml": ["mads"], "application/manifest+json": ["webmanifest"], "application/marc": ["mrc"], "application/marcxml+xml": ["mrcx"], "application/mathematica": ["ma", "nb", "mb"], "application/mathml+xml": ["mathml"], "application/mbox": ["mbox"], "application/media-policy-dataset+xml": ["mpf"], "application/mediaservercontrol+xml": ["mscml"], "application/metalink+xml": ["metalink"], "application/metalink4+xml": ["meta4"], "application/mets+xml": ["mets"], "application/mmt-aei+xml": ["maei"], "application/mmt-usd+xml": ["musd"], "application/mods+xml": ["mods"], "application/mp21": ["m21", "mp21"], "application/mp4": ["*mp4", "*mpg4", "mp4s", "m4p"], "application/msix": ["msix"], "application/msixbundle": ["msixbundle"], "application/msword": ["doc", "dot"], "application/mxf": ["mxf"], "application/n-quads": ["nq"], "application/n-triples": ["nt"], "application/node": ["cjs"], "application/octet-stream": ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"], "application/oda": ["oda"], "application/oebps-package+xml": ["opf"], "application/ogg": ["ogx"], "application/omdoc+xml": ["omdoc"], "application/onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"], "application/oxps": ["oxps"], "application/p2p-overlay+xml": ["relo"], "application/patch-ops-error+xml": ["xer"], "application/pdf": ["pdf"], "application/pgp-encrypted": ["pgp"], "application/pgp-keys": ["asc"], "application/pgp-signature": ["sig", "*asc"], "application/pics-rules": ["prf"], "application/pkcs10": ["p10"], "application/pkcs7-mime": ["p7m", "p7c"], "application/pkcs7-signature": ["p7s"], "application/pkcs8": ["p8"], "application/pkix-attr-cert": ["ac"], "application/pkix-cert": ["cer"], "application/pkix-crl": ["crl"], "application/pkix-pkipath": ["pkipath"], "application/pkixcmp": ["pki"], "application/pls+xml": ["pls"], "application/postscript": ["ai", "eps", "ps"], "application/provenance+xml": ["provx"], "application/pskc+xml": ["pskcxml"], "application/raml+yaml": ["raml"], "application/rdf+xml": ["rdf", "owl"], "application/reginfo+xml": ["rif"], "application/relax-ng-compact-syntax": ["rnc"], "application/resource-lists+xml": ["rl"], "application/resource-lists-diff+xml": ["rld"], "application/rls-services+xml": ["rs"], "application/route-apd+xml": ["rapd"], "application/route-s-tsid+xml": ["sls"], "application/route-usd+xml": ["rusd"], "application/rpki-ghostbusters": ["gbr"], "application/rpki-manifest": ["mft"], "application/rpki-roa": ["roa"], "application/rsd+xml": ["rsd"], "application/rss+xml": ["rss"], "application/rtf": ["rtf"], "application/sbml+xml": ["sbml"], "application/scvp-cv-request": ["scq"], "application/scvp-cv-response": ["scs"], "application/scvp-vp-request": ["spq"], "application/scvp-vp-response": ["spp"], "application/sdp": ["sdp"], "application/senml+xml": ["senmlx"], "application/sensml+xml": ["sensmlx"], "application/set-payment-initiation": ["setpay"], "application/set-registration-initiation": ["setreg"], "application/shf+xml": ["shf"], "application/sieve": ["siv", "sieve"], "application/smil+xml": ["smi", "smil"], "application/sparql-query": ["rq"], "application/sparql-results+xml": ["srx"], "application/sql": ["sql"], "application/srgs": ["gram"], "application/srgs+xml": ["grxml"], "application/sru+xml": ["sru"], "application/ssdl+xml": ["ssdl"], "application/ssml+xml": ["ssml"], "application/swid+xml": ["swidtag"], "application/tei+xml": ["tei", "teicorpus"], "application/thraud+xml": ["tfi"], "application/timestamped-data": ["tsd"], "application/toml": ["toml"], "application/trig": ["trig"], "application/ttml+xml": ["ttml"], "application/ubjson": ["ubj"], "application/urc-ressheet+xml": ["rsheet"], "application/urc-targetdesc+xml": ["td"], "application/voicexml+xml": ["vxml"], "application/wasm": ["wasm"], "application/watcherinfo+xml": ["wif"], "application/widget": ["wgt"], "application/winhlp": ["hlp"], "application/wsdl+xml": ["wsdl"], "application/wspolicy+xml": ["wspolicy"], "application/xaml+xml": ["xaml"], "application/xcap-att+xml": ["xav"], "application/xcap-caps+xml": ["xca"], "application/xcap-diff+xml": ["xdf"], "application/xcap-el+xml": ["xel"], "application/xcap-ns+xml": ["xns"], "application/xenc+xml": ["xenc"], "application/xfdf": ["xfdf"], "application/xhtml+xml": ["xhtml", "xht"], "application/xliff+xml": ["xlf"], "application/xml": ["xml", "xsl", "xsd", "rng"], "application/xml-dtd": ["dtd"], "application/xop+xml": ["xop"], "application/xproc+xml": ["xpl"], "application/xslt+xml": ["*xsl", "xslt"], "application/xspf+xml": ["xspf"], "application/xv+xml": ["mxml", "xhvml", "xvml", "xvm"], "application/yang": ["yang"], "application/yin+xml": ["yin"], "application/zip": ["zip"], "audio/3gpp": ["*3gpp"], "audio/aac": ["adts", "aac"], "audio/adpcm": ["adp"], "audio/amr": ["amr"], "audio/basic": ["au", "snd"], "audio/midi": ["mid", "midi", "kar", "rmi"], "audio/mobile-xmf": ["mxmf"], "audio/mp3": ["*mp3"], "audio/mp4": ["m4a", "mp4a"], "audio/mpeg": ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"], "audio/ogg": ["oga", "ogg", "spx", "opus"], "audio/s3m": ["s3m"], "audio/silk": ["sil"], "audio/wav": ["wav"], "audio/wave": ["*wav"], "audio/webm": ["weba"], "audio/xm": ["xm"], "font/collection": ["ttc"], "font/otf": ["otf"], "font/ttf": ["ttf"], "font/woff": ["woff"], "font/woff2": ["woff2"], "image/aces": ["exr"], "image/apng": ["apng"], "image/avci": ["avci"], "image/avcs": ["avcs"], "image/avif": ["avif"], "image/bmp": ["bmp", "dib"], "image/cgm": ["cgm"], "image/dicom-rle": ["drle"], "image/dpx": ["dpx"], "image/emf": ["emf"], "image/fits": ["fits"], "image/g3fax": ["g3"], "image/gif": ["gif"], "image/heic": ["heic"], "image/heic-sequence": ["heics"], "image/heif": ["heif"], "image/heif-sequence": ["heifs"], "image/hej2k": ["hej2"], "image/hsj2": ["hsj2"], "image/ief": ["ief"], "image/jls": ["jls"], "image/jp2": ["jp2", "jpg2"], "image/jpeg": ["jpeg", "jpg", "jpe"], "image/jph": ["jph"], "image/jphc": ["jhc"], "image/jpm": ["jpm", "jpgm"], "image/jpx": ["jpx", "jpf"], "image/jxr": ["jxr"], "image/jxra": ["jxra"], "image/jxrs": ["jxrs"], "image/jxs": ["jxs"], "image/jxsc": ["jxsc"], "image/jxsi": ["jxsi"], "image/jxss": ["jxss"], "image/ktx": ["ktx"], "image/ktx2": ["ktx2"], "image/png": ["png"], "image/sgi": ["sgi"], "image/svg+xml": ["svg", "svgz"], "image/t38": ["t38"], "image/tiff": ["tif", "tiff"], "image/tiff-fx": ["tfx"], "image/webp": ["webp"], "image/wmf": ["wmf"], "message/disposition-notification": ["disposition-notification"], "message/global": ["u8msg"], "message/global-delivery-status": ["u8dsn"], "message/global-disposition-notification": ["u8mdn"], "message/global-headers": ["u8hdr"], "message/rfc822": ["eml", "mime"], "model/3mf": ["3mf"], "model/gltf+json": ["gltf"], "model/gltf-binary": ["glb"], "model/iges": ["igs", "iges"], "model/jt": ["jt"], "model/mesh": ["msh", "mesh", "silo"], "model/mtl": ["mtl"], "model/obj": ["obj"], "model/prc": ["prc"], "model/step+xml": ["stpx"], "model/step+zip": ["stpz"], "model/step-xml+zip": ["stpxz"], "model/stl": ["stl"], "model/u3d": ["u3d"], "model/vrml": ["wrl", "vrml"], "model/x3d+binary": ["*x3db", "x3dbz"], "model/x3d+fastinfoset": ["x3db"], "model/x3d+vrml": ["*x3dv", "x3dvz"], "model/x3d+xml": ["x3d", "x3dz"], "model/x3d-vrml": ["x3dv"], "text/cache-manifest": ["appcache", "manifest"], "text/calendar": ["ics", "ifb"], "text/coffeescript": ["coffee", "litcoffee"], "text/css": ["css"], "text/csv": ["csv"], "text/html": ["html", "htm", "shtml"], "text/jade": ["jade"], "text/javascript": ["js", "mjs"], "text/jsx": ["jsx"], "text/less": ["less"], "text/markdown": ["md", "markdown"], "text/mathml": ["mml"], "text/mdx": ["mdx"], "text/n3": ["n3"], "text/plain": ["txt", "text", "conf", "def", "list", "log", "in", "ini"], "text/richtext": ["rtx"], "text/rtf": ["*rtf"], "text/sgml": ["sgml", "sgm"], "text/shex": ["shex"], "text/slim": ["slim", "slm"], "text/spdx": ["spdx"], "text/stylus": ["stylus", "styl"], "text/tab-separated-values": ["tsv"], "text/troff": ["t", "tr", "roff", "man", "me", "ms"], "text/turtle": ["ttl"], "text/uri-list": ["uri", "uris", "urls"], "text/vcard": ["vcard"], "text/vtt": ["vtt"], "text/wgsl": ["wgsl"], "text/xml": ["*xml"], "text/yaml": ["yaml", "yml"], "video/3gpp": ["3gp", "3gpp"], "video/3gpp2": ["3g2"], "video/h261": ["h261"], "video/h263": ["h263"], "video/h264": ["h264"], "video/iso.segment": ["m4s"], "video/jpeg": ["jpgv"], "video/jpm": ["*jpm", "*jpgm"], "video/mj2": ["mj2", "mjp2"], "video/mp2t": ["ts"], "video/mp4": ["mp4", "mp4v", "mpg4"], "video/mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v"], "video/ogg": ["ogv"], "video/quicktime": ["qt", "mov"], "video/webm": ["webm"] };
|
|
900
|
-
Object.freeze(types);
|
|
901
|
-
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
902
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
903
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
904
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
905
|
-
};
|
|
906
|
-
var _Mime_extensionToType, _Mime_typeToExtension, _Mime_typeToExtensions;
|
|
907
|
-
class Mime {
|
|
908
|
-
constructor(...args) {
|
|
909
|
-
_Mime_extensionToType.set(this, /* @__PURE__ */ new Map());
|
|
910
|
-
_Mime_typeToExtension.set(this, /* @__PURE__ */ new Map());
|
|
911
|
-
_Mime_typeToExtensions.set(this, /* @__PURE__ */ new Map());
|
|
912
|
-
for (const arg of args) {
|
|
913
|
-
this.define(arg);
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
define(typeMap, force = false) {
|
|
917
|
-
for (let [type, extensions] of Object.entries(typeMap)) {
|
|
918
|
-
type = type.toLowerCase();
|
|
919
|
-
extensions = extensions.map((ext) => ext.toLowerCase());
|
|
920
|
-
if (!__classPrivateFieldGet(this, _Mime_typeToExtensions, "f").has(type)) {
|
|
921
|
-
__classPrivateFieldGet(this, _Mime_typeToExtensions, "f").set(type, /* @__PURE__ */ new Set());
|
|
922
|
-
}
|
|
923
|
-
const allExtensions = __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type);
|
|
924
|
-
let first = true;
|
|
925
|
-
for (let extension of extensions) {
|
|
926
|
-
const starred = extension.startsWith("*");
|
|
927
|
-
extension = starred ? extension.slice(1) : extension;
|
|
928
|
-
allExtensions == null ? void 0 : allExtensions.add(extension);
|
|
929
|
-
if (first) {
|
|
930
|
-
__classPrivateFieldGet(this, _Mime_typeToExtension, "f").set(type, extension);
|
|
931
|
-
}
|
|
932
|
-
first = false;
|
|
933
|
-
if (starred)
|
|
934
|
-
continue;
|
|
935
|
-
const currentType = __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(extension);
|
|
936
|
-
if (currentType && currentType != type && !force) {
|
|
937
|
-
throw new Error(`"${type} -> ${extension}" conflicts with "${currentType} -> ${extension}". Pass \`force=true\` to override this definition.`);
|
|
938
|
-
}
|
|
939
|
-
__classPrivateFieldGet(this, _Mime_extensionToType, "f").set(extension, type);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
return this;
|
|
943
|
-
}
|
|
944
|
-
getType(path) {
|
|
945
|
-
if (typeof path !== "string")
|
|
946
|
-
return null;
|
|
947
|
-
const last = path.replace(/^.*[/\\]/, "").toLowerCase();
|
|
948
|
-
const ext = last.replace(/^.*\./, "").toLowerCase();
|
|
949
|
-
const hasPath = last.length < path.length;
|
|
950
|
-
const hasDot = ext.length < last.length - 1;
|
|
951
|
-
if (!hasDot && hasPath)
|
|
952
|
-
return null;
|
|
953
|
-
return __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(ext) ?? null;
|
|
954
|
-
}
|
|
955
|
-
getExtension(type) {
|
|
956
|
-
var _a;
|
|
957
|
-
if (typeof type !== "string")
|
|
958
|
-
return null;
|
|
959
|
-
type = (_a = type == null ? void 0 : type.split) == null ? void 0 : _a.call(type, ";")[0];
|
|
960
|
-
return (type && __classPrivateFieldGet(this, _Mime_typeToExtension, "f").get(type.trim().toLowerCase())) ?? null;
|
|
961
|
-
}
|
|
962
|
-
getAllExtensions(type) {
|
|
963
|
-
if (typeof type !== "string")
|
|
964
|
-
return null;
|
|
965
|
-
return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type.toLowerCase()) ?? null;
|
|
966
|
-
}
|
|
967
|
-
_freeze() {
|
|
968
|
-
this.define = () => {
|
|
969
|
-
throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
|
|
970
|
-
};
|
|
971
|
-
Object.freeze(this);
|
|
972
|
-
for (const extensions of __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").values()) {
|
|
973
|
-
Object.freeze(extensions);
|
|
974
|
-
}
|
|
975
|
-
return this;
|
|
976
|
-
}
|
|
977
|
-
_getTestState() {
|
|
978
|
-
return {
|
|
979
|
-
types: __classPrivateFieldGet(this, _Mime_extensionToType, "f"),
|
|
980
|
-
extensions: __classPrivateFieldGet(this, _Mime_typeToExtension, "f")
|
|
981
|
-
};
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
_Mime_extensionToType = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtension = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtensions = /* @__PURE__ */ new WeakMap();
|
|
985
|
-
const mime = new Mime(types)._freeze();
|
|
986
|
-
function validateOperations(operations) {
|
|
987
|
-
const errors = [];
|
|
988
|
-
const scopes = Object.keys(operations);
|
|
989
|
-
for (const scope of scopes) {
|
|
990
|
-
const ops = operations[scope].sort((a, b) => a.index - b.index);
|
|
991
|
-
let opIndex = -1;
|
|
992
|
-
for (let i = 0; i < ops.length; i++) {
|
|
993
|
-
opIndex = opIndex + 1 + ops[i].skip;
|
|
994
|
-
if (ops[i].index !== opIndex) {
|
|
995
|
-
errors.push({
|
|
996
|
-
message: `Invalid operation index ${ops[i].index} at position ${i}`,
|
|
997
|
-
details: {
|
|
998
|
-
position: i,
|
|
999
|
-
operation: ops[i],
|
|
1000
|
-
scope: ops[i].scope
|
|
1001
|
-
}
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
return errors;
|
|
1007
|
-
}
|
|
1008
|
-
var IntegrityIssueType = /* @__PURE__ */ ((IntegrityIssueType2) => {
|
|
1009
|
-
IntegrityIssueType2["UNEXPECTED_INDEX"] = "UNEXPECTED_INDEX";
|
|
1010
|
-
return IntegrityIssueType2;
|
|
1011
|
-
})(IntegrityIssueType || {});
|
|
1012
|
-
var IntegrityIssueSubType = /* @__PURE__ */ ((IntegrityIssueSubType2) => {
|
|
1013
|
-
IntegrityIssueSubType2["DUPLICATED_INDEX"] = "DUPLICATED_INDEX";
|
|
1014
|
-
IntegrityIssueSubType2["MISSING_INDEX"] = "MISSING_INDEX";
|
|
1015
|
-
return IntegrityIssueSubType2;
|
|
1016
|
-
})(IntegrityIssueSubType || {});
|
|
1017
|
-
function checkCleanedOperationsIntegrity(sortedOperations) {
|
|
1018
|
-
const result = [];
|
|
1019
|
-
let currentIndex = -1;
|
|
1020
|
-
for (const nextOperation of sortedOperations) {
|
|
1021
|
-
const nextIndex = nextOperation.index - nextOperation.skip;
|
|
1022
|
-
if (nextIndex !== currentIndex + 1) {
|
|
1023
|
-
result.push({
|
|
1024
|
-
operation: {
|
|
1025
|
-
index: nextOperation.index,
|
|
1026
|
-
skip: nextOperation.skip
|
|
1027
|
-
},
|
|
1028
|
-
issue: "UNEXPECTED_INDEX",
|
|
1029
|
-
category: nextIndex > currentIndex + 1 ? "MISSING_INDEX" : "DUPLICATED_INDEX",
|
|
1030
|
-
message: `Expected index ${currentIndex + 1} with skip 0 or equivalent, got index ${nextOperation.index} with skip ${nextOperation.skip}`
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
currentIndex = nextOperation.index;
|
|
1034
|
-
}
|
|
1035
|
-
return result;
|
|
1036
|
-
}
|
|
1037
|
-
function garbageCollect(sortedOperations) {
|
|
1038
|
-
var _a, _b, _c;
|
|
1039
|
-
const result = [];
|
|
1040
|
-
let i = sortedOperations.length - 1;
|
|
1041
|
-
while (i > -1) {
|
|
1042
|
-
result.unshift(sortedOperations[i]);
|
|
1043
|
-
const skipUntil = (((_a = sortedOperations[i]) == null ? void 0 : _a.index) || 0) - (((_b = sortedOperations[i]) == null ? void 0 : _b.skip) || 0) - 1;
|
|
1044
|
-
let j = i - 1;
|
|
1045
|
-
while (j > -1 && (((_c = sortedOperations[j]) == null ? void 0 : _c.index) || 0) > skipUntil) {
|
|
1046
|
-
j--;
|
|
1047
|
-
}
|
|
1048
|
-
i = j;
|
|
1049
|
-
}
|
|
1050
|
-
return result;
|
|
1051
|
-
}
|
|
1052
|
-
function addUndo(sortedOperations) {
|
|
1053
|
-
const operationsCopy = [...sortedOperations];
|
|
1054
|
-
const latestOperation = operationsCopy[operationsCopy.length - 1];
|
|
1055
|
-
if (!latestOperation) return operationsCopy;
|
|
1056
|
-
if (latestOperation.type === "NOOP") {
|
|
1057
|
-
operationsCopy.push({
|
|
1058
|
-
...latestOperation,
|
|
1059
|
-
index: latestOperation.index,
|
|
1060
|
-
type: "NOOP",
|
|
1061
|
-
skip: nextSkipNumber(sortedOperations)
|
|
1062
|
-
});
|
|
1063
|
-
} else {
|
|
1064
|
-
operationsCopy.push({
|
|
1065
|
-
type: "NOOP",
|
|
1066
|
-
index: latestOperation.index + 1,
|
|
1067
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1068
|
-
input: {},
|
|
1069
|
-
skip: 1,
|
|
1070
|
-
scope: latestOperation.scope,
|
|
1071
|
-
hash: latestOperation.hash
|
|
1072
|
-
});
|
|
1073
|
-
}
|
|
1074
|
-
return operationsCopy;
|
|
1075
|
-
}
|
|
1076
|
-
function sortOperations$1(operations) {
|
|
1077
|
-
return operations.slice().sort((a, b) => a.skip - b.skip).sort((a, b) => a.index - b.index);
|
|
1078
|
-
}
|
|
1079
|
-
const reshuffleByTimestamp = (startIndex, opsA, opsB) => {
|
|
1080
|
-
return [...opsA, ...opsB].sort(
|
|
1081
|
-
(a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
|
|
1082
|
-
).map((op, i) => ({
|
|
1083
|
-
...op,
|
|
1084
|
-
index: startIndex.index + i,
|
|
1085
|
-
skip: i === 0 ? startIndex.skip : 0
|
|
1086
|
-
}));
|
|
1087
|
-
};
|
|
1088
|
-
const reshuffleByTimestampAndIndex = (startIndex, opsA, opsB) => {
|
|
1089
|
-
return [...opsA, ...opsB].sort(
|
|
1090
|
-
(a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
|
|
1091
|
-
).sort((a, b) => a.index - b.index).map((op, i) => ({
|
|
1092
|
-
...op,
|
|
1093
|
-
index: startIndex.index + i,
|
|
1094
|
-
skip: i === 0 ? startIndex.skip : 0
|
|
1095
|
-
}));
|
|
1096
|
-
};
|
|
1097
|
-
function operationsAreEqual(op1, op2) {
|
|
1098
|
-
return cjsModule(op1) === cjsModule(op2);
|
|
1099
|
-
}
|
|
1100
|
-
function attachBranch(trunk, newBranch) {
|
|
1101
|
-
const trunkCopy = garbageCollect(sortOperations$1(trunk.slice()));
|
|
1102
|
-
const newOperations = garbageCollect(sortOperations$1(newBranch.slice()));
|
|
1103
|
-
if (trunkCopy.length < 1) {
|
|
1104
|
-
return [newOperations, []];
|
|
1105
|
-
}
|
|
1106
|
-
const result = [];
|
|
1107
|
-
let enteredBranch = false;
|
|
1108
|
-
while (newOperations.length > 0) {
|
|
1109
|
-
const newOperationCandidate = newOperations[0];
|
|
1110
|
-
let nextTrunkOperation = trunkCopy.shift();
|
|
1111
|
-
while (nextTrunkOperation && precedes(nextTrunkOperation, newOperationCandidate)) {
|
|
1112
|
-
result.push(nextTrunkOperation);
|
|
1113
|
-
nextTrunkOperation = trunkCopy.shift();
|
|
1114
|
-
}
|
|
1115
|
-
if (!nextTrunkOperation) {
|
|
1116
|
-
enteredBranch = true;
|
|
1117
|
-
} else if (!enteredBranch) {
|
|
1118
|
-
if (operationsAreEqual(nextTrunkOperation, newOperationCandidate)) {
|
|
1119
|
-
newOperations.shift();
|
|
1120
|
-
result.push(nextTrunkOperation);
|
|
1121
|
-
} else {
|
|
1122
|
-
trunkCopy.unshift(nextTrunkOperation);
|
|
1123
|
-
enteredBranch = true;
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
if (enteredBranch) {
|
|
1127
|
-
let nextAppend = newOperations.shift();
|
|
1128
|
-
while (nextAppend) {
|
|
1129
|
-
result.push(nextAppend);
|
|
1130
|
-
nextAppend = newOperations.shift();
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
if (!enteredBranch) {
|
|
1135
|
-
let nextAppend = trunkCopy.shift();
|
|
1136
|
-
while (nextAppend) {
|
|
1137
|
-
result.push(nextAppend);
|
|
1138
|
-
nextAppend = trunkCopy.shift();
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
return [garbageCollect(result), trunkCopy];
|
|
1142
|
-
}
|
|
1143
|
-
function precedes(op1, op2) {
|
|
1144
|
-
return op1.index < op2.index || op1.index === op2.index && op1.id === op2.id && op1.skip < op2.skip;
|
|
1145
|
-
}
|
|
1146
|
-
function split(sortedTargetOperations, sortedMergeOperations) {
|
|
1147
|
-
const commonOperations = [];
|
|
1148
|
-
const targetDiffOperations = [];
|
|
1149
|
-
const mergeDiffOperations = [];
|
|
1150
|
-
const maxLength = Math.max(
|
|
1151
|
-
sortedTargetOperations.length,
|
|
1152
|
-
sortedMergeOperations.length
|
|
1153
|
-
);
|
|
1154
|
-
let splitHappened = false;
|
|
1155
|
-
for (let i = 0; i < maxLength; i++) {
|
|
1156
|
-
const targetOperation = sortedTargetOperations[i];
|
|
1157
|
-
const mergeOperation = sortedMergeOperations[i];
|
|
1158
|
-
if (targetOperation && mergeOperation) {
|
|
1159
|
-
if (!splitHappened && operationsAreEqual(targetOperation, mergeOperation)) {
|
|
1160
|
-
commonOperations.push(targetOperation);
|
|
1161
|
-
} else {
|
|
1162
|
-
splitHappened = true;
|
|
1163
|
-
targetDiffOperations.push(targetOperation);
|
|
1164
|
-
mergeDiffOperations.push(mergeOperation);
|
|
1165
|
-
}
|
|
1166
|
-
} else if (targetOperation) {
|
|
1167
|
-
targetDiffOperations.push(targetOperation);
|
|
1168
|
-
} else if (mergeOperation) {
|
|
1169
|
-
mergeDiffOperations.push(mergeOperation);
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
return [commonOperations, targetDiffOperations, mergeDiffOperations];
|
|
1173
|
-
}
|
|
1174
|
-
function merge(sortedTargetOperations, sortedMergeOperations, reshuffle) {
|
|
1175
|
-
const [_commonOperations, _targetOperations, _mergeOperations] = split(
|
|
1176
|
-
garbageCollect(sortedTargetOperations),
|
|
1177
|
-
garbageCollect(sortedMergeOperations)
|
|
1178
|
-
);
|
|
1179
|
-
const maxCommonIndex = getMaxIndex(_commonOperations);
|
|
1180
|
-
const nextIndex = 1 + Math.max(
|
|
1181
|
-
maxCommonIndex,
|
|
1182
|
-
getMaxIndex(_targetOperations),
|
|
1183
|
-
getMaxIndex(_mergeOperations)
|
|
1184
|
-
);
|
|
1185
|
-
const filteredMergeOperations = filterDuplicatedOperations(
|
|
1186
|
-
_mergeOperations,
|
|
1187
|
-
_targetOperations
|
|
1188
|
-
);
|
|
1189
|
-
const newOperationHistory = reshuffle(
|
|
1190
|
-
{
|
|
1191
|
-
index: nextIndex,
|
|
1192
|
-
skip: nextIndex - (maxCommonIndex + 1)
|
|
1193
|
-
},
|
|
1194
|
-
_targetOperations,
|
|
1195
|
-
filteredMergeOperations
|
|
1196
|
-
);
|
|
1197
|
-
return _commonOperations.concat(newOperationHistory);
|
|
1198
|
-
}
|
|
1199
|
-
function getMaxIndex(sortedOperations) {
|
|
1200
|
-
const lastElement = sortedOperations[sortedOperations.length - 1];
|
|
1201
|
-
if (!lastElement) {
|
|
1202
|
-
return -1;
|
|
1203
|
-
}
|
|
1204
|
-
return lastElement.index;
|
|
1205
|
-
}
|
|
1206
|
-
function nextSkipNumber(sortedOperations) {
|
|
1207
|
-
var _a, _b, _c;
|
|
1208
|
-
if (sortedOperations.length < 1) {
|
|
1209
|
-
return -1;
|
|
1210
|
-
}
|
|
1211
|
-
const cleanedOperations = garbageCollect(sortedOperations);
|
|
1212
|
-
let nextSkip = (((_a = cleanedOperations[cleanedOperations.length - 1]) == null ? void 0 : _a.skip) || 0) + 1;
|
|
1213
|
-
if (cleanedOperations.length > 1) {
|
|
1214
|
-
nextSkip += ((_b = cleanedOperations[cleanedOperations.length - 2]) == null ? void 0 : _b.skip) || 0;
|
|
1215
|
-
}
|
|
1216
|
-
return (((_c = cleanedOperations[cleanedOperations.length - 1]) == null ? void 0 : _c.index) || -1) < nextSkip ? -1 : nextSkip;
|
|
1217
|
-
}
|
|
1218
|
-
const checkOperationsIntegrity = (operations) => {
|
|
1219
|
-
return checkCleanedOperationsIntegrity(
|
|
1220
|
-
garbageCollect(sortOperations$1(operations))
|
|
1221
|
-
);
|
|
1222
|
-
};
|
|
1223
|
-
const groupOperationsByScope = (operations) => {
|
|
1224
|
-
const result = operations.reduce((acc, operation) => {
|
|
1225
|
-
var _a;
|
|
1226
|
-
if (!acc[operation.scope]) {
|
|
1227
|
-
acc[operation.scope] = [];
|
|
1228
|
-
}
|
|
1229
|
-
(_a = acc[operation.scope]) == null ? void 0 : _a.push(operation);
|
|
1230
|
-
return acc;
|
|
1231
|
-
}, {});
|
|
1232
|
-
return result;
|
|
1233
|
-
};
|
|
1234
|
-
const prepareOperations = (operationsHistory, newOperations) => {
|
|
1235
|
-
var _a;
|
|
1236
|
-
const result = {
|
|
1237
|
-
integrityIssues: [],
|
|
1238
|
-
validOperations: [],
|
|
1239
|
-
invalidOperations: [],
|
|
1240
|
-
duplicatedOperations: []
|
|
1241
|
-
};
|
|
1242
|
-
const sortedOperationsHistory = sortOperations$1(operationsHistory);
|
|
1243
|
-
const sortedOperations = sortOperations$1(newOperations);
|
|
1244
|
-
const integrityErrors = checkCleanedOperationsIntegrity([
|
|
1245
|
-
...sortedOperationsHistory,
|
|
1246
|
-
...sortedOperations
|
|
1247
|
-
]);
|
|
1248
|
-
const missingIndexErrors = integrityErrors.filter(
|
|
1249
|
-
(integrityIssue) => integrityIssue.category === "MISSING_INDEX"
|
|
1250
|
-
/* MISSING_INDEX */
|
|
1251
|
-
);
|
|
1252
|
-
const firstMissingIndexOperation = (_a = [...missingIndexErrors].sort((a, b) => b.operation.index - a.operation.index).pop()) == null ? void 0 : _a.operation;
|
|
1253
|
-
for (const newOperation of sortedOperations) {
|
|
1254
|
-
if (firstMissingIndexOperation && newOperation.index >= firstMissingIndexOperation.index) {
|
|
1255
|
-
result.invalidOperations.push(newOperation);
|
|
1256
|
-
continue;
|
|
1257
|
-
}
|
|
1258
|
-
const isDuplicatedOperation = integrityErrors.some((integrityError) => {
|
|
1259
|
-
return integrityError.operation.index === newOperation.index && integrityError.operation.skip === newOperation.skip && integrityError.category === "DUPLICATED_INDEX";
|
|
1260
|
-
});
|
|
1261
|
-
if (isDuplicatedOperation) {
|
|
1262
|
-
result.duplicatedOperations.push(newOperation);
|
|
1263
|
-
continue;
|
|
1264
|
-
}
|
|
1265
|
-
result.validOperations.push(newOperation);
|
|
1266
|
-
}
|
|
1267
|
-
result.integrityIssues.push(...integrityErrors);
|
|
1268
|
-
return result;
|
|
1269
|
-
};
|
|
1270
|
-
function removeExistingOperations(newOperations, operationsHistory) {
|
|
1271
|
-
return newOperations.filter((newOperation) => {
|
|
1272
|
-
return !operationsHistory.some((historyOperation) => {
|
|
1273
|
-
return newOperation.type === "NOOP" && newOperation.skip === 0 && newOperation.index === historyOperation.index || newOperation.index === historyOperation.index && newOperation.skip === historyOperation.skip && newOperation.scope === historyOperation.scope && newOperation.hash === historyOperation.hash && newOperation.type === historyOperation.type;
|
|
1274
|
-
});
|
|
1275
|
-
});
|
|
1276
|
-
}
|
|
1277
|
-
function skipHeaderOperations(operations, skipHeaderOperation) {
|
|
1278
|
-
const [lastOperation] = sortOperations$1(operations).slice(-1);
|
|
1279
|
-
const lastIndex = (lastOperation == null ? void 0 : lastOperation.index) ?? -1;
|
|
1280
|
-
const nextIndex = lastIndex + 1;
|
|
1281
|
-
const skipOperationIndex = {
|
|
1282
|
-
...skipHeaderOperation,
|
|
1283
|
-
index: skipHeaderOperation.index ?? nextIndex
|
|
1284
|
-
};
|
|
1285
|
-
if (skipOperationIndex.index < lastIndex) {
|
|
1286
|
-
throw new Error(
|
|
1287
|
-
`The skip header operation index must be greater than or equal to ${lastIndex}`
|
|
1288
|
-
);
|
|
1289
|
-
}
|
|
1290
|
-
const clearedOperations = garbageCollect(
|
|
1291
|
-
sortOperations$1([...operations, skipOperationIndex])
|
|
1292
|
-
);
|
|
1293
|
-
return (clearedOperations || []).slice(0, -1);
|
|
1294
|
-
}
|
|
1295
|
-
function garbageCollectDocumentOperations(documentOperations) {
|
|
1296
|
-
const clearedOperations = Object.entries(documentOperations).reduce(
|
|
1297
|
-
(acc, entry) => {
|
|
1298
|
-
const [scope, ops] = entry;
|
|
1299
|
-
return {
|
|
1300
|
-
...acc,
|
|
1301
|
-
[scope]: garbageCollect(sortOperations$1(ops))
|
|
1302
|
-
};
|
|
1303
|
-
},
|
|
1304
|
-
{}
|
|
1305
|
-
);
|
|
1306
|
-
return {
|
|
1307
|
-
...clearedOperations
|
|
1308
|
-
};
|
|
1309
|
-
}
|
|
1310
|
-
function filterDuplicatedOperations(targetOperations, sourceOperations) {
|
|
1311
|
-
return targetOperations.filter((op) => {
|
|
1312
|
-
if (op.id) {
|
|
1313
|
-
return !sourceOperations.some((targetOp) => targetOp.id === op.id);
|
|
1314
|
-
}
|
|
1315
|
-
return true;
|
|
1316
|
-
});
|
|
1317
|
-
}
|
|
1318
|
-
function filterDocumentOperationsResultingState(documentOperations) {
|
|
1319
|
-
if (!documentOperations) {
|
|
1320
|
-
return {};
|
|
1321
|
-
}
|
|
1322
|
-
const entries = Object.entries(documentOperations);
|
|
1323
|
-
return entries.reduce(
|
|
1324
|
-
(acc, [scope, operations]) => ({
|
|
1325
|
-
...acc,
|
|
1326
|
-
[scope]: operations.map((op) => {
|
|
1327
|
-
const { resultingState, ...restProps } = op;
|
|
1328
|
-
return restProps;
|
|
1329
|
-
})
|
|
1330
|
-
}),
|
|
1331
|
-
{}
|
|
1332
|
-
);
|
|
1333
|
-
}
|
|
1334
|
-
function diffOperations(clearedOperationsA, clearedOperationsB) {
|
|
1335
|
-
return clearedOperationsA.filter(
|
|
1336
|
-
(operationA) => !clearedOperationsB.some(
|
|
1337
|
-
(operationB) => operationA.index === operationB.index
|
|
1338
|
-
)
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
1341
|
-
const documentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1342
|
-
__proto__: null,
|
|
1343
|
-
IntegrityIssueSubType,
|
|
1344
|
-
IntegrityIssueType,
|
|
1345
|
-
addUndo,
|
|
1346
|
-
attachBranch,
|
|
1347
|
-
checkCleanedOperationsIntegrity,
|
|
1348
|
-
checkOperationsIntegrity,
|
|
1349
|
-
diffOperations,
|
|
1350
|
-
filterDocumentOperationsResultingState,
|
|
1351
|
-
filterDuplicatedOperations,
|
|
1352
|
-
garbageCollect,
|
|
1353
|
-
garbageCollectDocumentOperations,
|
|
1354
|
-
groupOperationsByScope,
|
|
1355
|
-
merge,
|
|
1356
|
-
nextSkipNumber,
|
|
1357
|
-
operationsAreEqual,
|
|
1358
|
-
precedes,
|
|
1359
|
-
prepareOperations,
|
|
1360
|
-
removeExistingOperations,
|
|
1361
|
-
reshuffleByTimestamp,
|
|
1362
|
-
reshuffleByTimestampAndIndex,
|
|
1363
|
-
skipHeaderOperations,
|
|
1364
|
-
sortOperations: sortOperations$1,
|
|
1365
|
-
split
|
|
1366
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
1367
|
-
const createZip = async (document) => {
|
|
1368
|
-
const zip = new JSZip();
|
|
1369
|
-
const { name, revision, documentType, created, lastModified } = document;
|
|
1370
|
-
const header = {
|
|
1371
|
-
name,
|
|
1372
|
-
revision,
|
|
1373
|
-
documentType,
|
|
1374
|
-
created,
|
|
1375
|
-
lastModified
|
|
1376
|
-
};
|
|
1377
|
-
zip.file("header.json", JSON.stringify(header, null, 2));
|
|
1378
|
-
zip.file("state.json", JSON.stringify(document.initialState || {}, null, 2));
|
|
1379
|
-
zip.file(
|
|
1380
|
-
"operations.json",
|
|
1381
|
-
JSON.stringify(
|
|
1382
|
-
filterDocumentOperationsResultingState(document.operations),
|
|
1383
|
-
null,
|
|
1384
|
-
2
|
|
1385
|
-
)
|
|
1386
|
-
);
|
|
1387
|
-
if (document.attachments) {
|
|
1388
|
-
const attachments = Object.keys(document.attachments);
|
|
1389
|
-
attachments.forEach((key) => {
|
|
1390
|
-
const { data, ...attributes } = document.attachments[key];
|
|
1391
|
-
zip.file(key, data, {
|
|
1392
|
-
base64: true,
|
|
1393
|
-
createFolders: true,
|
|
1394
|
-
comment: JSON.stringify(attributes)
|
|
1395
|
-
});
|
|
1396
|
-
});
|
|
1397
|
-
}
|
|
1398
|
-
return zip;
|
|
1399
|
-
};
|
|
1400
|
-
const saveToFile = async (document, path, extension, name) => {
|
|
1401
|
-
const zip = await createZip(document);
|
|
1402
|
-
const file = await zip.generateAsync({
|
|
1403
|
-
type: "uint8array",
|
|
1404
|
-
streamFiles: true
|
|
1405
|
-
});
|
|
1406
|
-
const fileName = name ?? document.name;
|
|
1407
|
-
const fileExtension = `.${extension}.zip`;
|
|
1408
|
-
return writeFile(
|
|
1409
|
-
path,
|
|
1410
|
-
fileName.endsWith(fileExtension) ? fileName : `${fileName}${fileExtension}`,
|
|
1411
|
-
file
|
|
1412
|
-
);
|
|
1413
|
-
};
|
|
1414
|
-
const saveToFileHandle = async (document, input) => {
|
|
1415
|
-
const zip = await createZip(document);
|
|
1416
|
-
const blob = await zip.generateAsync({ type: "blob" });
|
|
1417
|
-
const writable = await input.createWritable();
|
|
1418
|
-
await writable.write(blob);
|
|
1419
|
-
await writable.close();
|
|
1420
|
-
};
|
|
1421
|
-
const loadFromFile = async (path, reducer, options) => {
|
|
1422
|
-
const file = readFile(path);
|
|
1423
|
-
return loadFromInput(file, reducer, options);
|
|
1424
|
-
};
|
|
1425
|
-
const loadFromInput = async (input, reducer, options) => {
|
|
1426
|
-
const zip = new JSZip();
|
|
1427
|
-
await zip.loadAsync(input);
|
|
1428
|
-
return loadFromZip(zip, reducer, options);
|
|
1429
|
-
};
|
|
1430
|
-
async function loadFromZip(zip, reducer, options) {
|
|
1431
|
-
const initialStateZip = zip.file("state.json");
|
|
1432
|
-
if (!initialStateZip) {
|
|
1433
|
-
throw new Error("Initial state not found");
|
|
1434
|
-
}
|
|
1435
|
-
const initialStateStr = await initialStateZip.async("string");
|
|
1436
|
-
const initialState = JSON.parse(initialStateStr);
|
|
1437
|
-
const headerZip = zip.file("header.json");
|
|
1438
|
-
let header = void 0;
|
|
1439
|
-
if (headerZip) {
|
|
1440
|
-
header = JSON.parse(await headerZip.async("string"));
|
|
1441
|
-
}
|
|
1442
|
-
const operationsZip = zip.file("operations.json");
|
|
1443
|
-
if (!operationsZip) {
|
|
1444
|
-
throw new Error("Operations history not found");
|
|
1445
|
-
}
|
|
1446
|
-
const operations = JSON.parse(
|
|
1447
|
-
await operationsZip.async("string")
|
|
1448
|
-
);
|
|
1449
|
-
const clearedOperations = garbageCollectDocumentOperations(operations);
|
|
1450
|
-
const operationsError = validateOperations(clearedOperations);
|
|
1451
|
-
if (operationsError.length) {
|
|
1452
|
-
const errorMessages = operationsError.map((err) => err.message);
|
|
1453
|
-
throw new Error(errorMessages.join("\n"));
|
|
1454
|
-
}
|
|
1455
|
-
let result = replayDocument(
|
|
1456
|
-
initialState,
|
|
1457
|
-
clearedOperations,
|
|
1458
|
-
reducer,
|
|
1459
|
-
void 0,
|
|
1460
|
-
header,
|
|
1461
|
-
{},
|
|
1462
|
-
options
|
|
1463
|
-
);
|
|
1464
|
-
if (header) {
|
|
1465
|
-
result = {
|
|
1466
|
-
...result,
|
|
1467
|
-
...header
|
|
1468
|
-
};
|
|
1469
|
-
}
|
|
1470
|
-
return result;
|
|
1471
|
-
}
|
|
1472
|
-
function getFileAttributes(file) {
|
|
1473
|
-
const extension = file.replace(/^.*\./, "") || void 0;
|
|
1474
|
-
const fileName = file.replace(/^.*[/\\]/, "") || void 0;
|
|
1475
|
-
return { extension, fileName };
|
|
1476
|
-
}
|
|
1477
|
-
async function getRemoteFile(url) {
|
|
1478
|
-
const { buffer, mimeType = "application/octet-stream" } = await fetchFile(url);
|
|
1479
|
-
const attributes = getFileAttributes(url);
|
|
1480
|
-
const data = buffer.toString("base64");
|
|
1481
|
-
return {
|
|
1482
|
-
data,
|
|
1483
|
-
hash: hash(data),
|
|
1484
|
-
mimeType,
|
|
1485
|
-
...attributes
|
|
1486
|
-
};
|
|
1487
|
-
}
|
|
1488
|
-
async function getLocalFile(path) {
|
|
1489
|
-
const buffer = await getFile(path);
|
|
1490
|
-
const mimeType = mime.getType(path) || "application/octet-stream";
|
|
1491
|
-
const attributes = getFileAttributes(path);
|
|
1492
|
-
const data = buffer.toString("base64");
|
|
1493
|
-
return { data, hash: hash(data), mimeType, ...attributes };
|
|
1494
|
-
}
|
|
1495
|
-
function setNameOperation(document, name) {
|
|
1496
|
-
return { ...document, name };
|
|
1497
|
-
}
|
|
1498
|
-
function undoOperation(document, action, skip) {
|
|
1499
|
-
const { scope, input } = action;
|
|
1500
|
-
const defaultResult = {
|
|
1501
|
-
document,
|
|
1502
|
-
action,
|
|
1503
|
-
skip,
|
|
1504
|
-
reuseLastOperationIndex: false
|
|
1505
|
-
};
|
|
1506
|
-
return create(defaultResult, (draft) => {
|
|
1507
|
-
const operations = [...document.operations[scope]];
|
|
1508
|
-
const sortedOperations = sortOperations$1(operations);
|
|
1509
|
-
draft.action = noop(scope);
|
|
1510
|
-
const lastOperation = sortedOperations.at(-1);
|
|
1511
|
-
let nextIndex = (lastOperation == null ? void 0 : lastOperation.index) ?? -1;
|
|
1512
|
-
const isNewNoop = (lastOperation == null ? void 0 : lastOperation.type) !== "NOOP";
|
|
1513
|
-
if (isNewNoop) {
|
|
1514
|
-
nextIndex = nextIndex + 1;
|
|
1515
|
-
} else {
|
|
1516
|
-
draft.reuseLastOperationIndex = true;
|
|
1517
|
-
}
|
|
1518
|
-
const nextOperationHistory = isNewNoop ? [...sortedOperations, { index: nextIndex, skip: 0 }] : sortedOperations;
|
|
1519
|
-
draft.skip = nextSkipNumber(nextOperationHistory);
|
|
1520
|
-
if (lastOperation && draft.skip > lastOperation.skip + 1) {
|
|
1521
|
-
draft.skip = draft.skip + 1;
|
|
1522
|
-
}
|
|
1523
|
-
if (draft.skip < 0) {
|
|
1524
|
-
throw new Error(
|
|
1525
|
-
`Cannot undo: you can't undo more operations than the ones in the scope history`
|
|
1526
|
-
);
|
|
1527
|
-
}
|
|
1528
|
-
});
|
|
1529
|
-
}
|
|
1530
|
-
function redoOperation(document, action, skip) {
|
|
1531
|
-
const { scope, input } = action;
|
|
1532
|
-
const defaultResult = {
|
|
1533
|
-
document,
|
|
1534
|
-
action,
|
|
1535
|
-
skip,
|
|
1536
|
-
reuseLastOperationIndex: false
|
|
1537
|
-
};
|
|
1538
|
-
return create(defaultResult, (draft) => {
|
|
1539
|
-
if (draft.skip > 0) {
|
|
1540
|
-
throw new Error(
|
|
1541
|
-
`Cannot redo: skip value from reducer cannot be used with REDO action`
|
|
1542
|
-
);
|
|
1543
|
-
}
|
|
1544
|
-
if (input > 1) {
|
|
1545
|
-
throw new Error(`Cannot redo: you can only redo one operation at a time`);
|
|
1546
|
-
}
|
|
1547
|
-
if (input < 1) {
|
|
1548
|
-
throw new Error(`Invalid REDO action: invalid redo input value`);
|
|
1549
|
-
}
|
|
1550
|
-
if (draft.document.clipboard.length < 1) {
|
|
1551
|
-
throw new Error(`Cannot redo: no operations in the clipboard`);
|
|
1552
|
-
}
|
|
1553
|
-
const operationIndex = draft.document.clipboard.findLastIndex(
|
|
1554
|
-
(op) => op.scope === scope
|
|
1555
|
-
);
|
|
1556
|
-
if (operationIndex < 0) {
|
|
1557
|
-
throw new Error(
|
|
1558
|
-
`Cannot redo: no operations in clipboard for scope "${scope}"`
|
|
1559
|
-
);
|
|
1560
|
-
}
|
|
1561
|
-
const operation = draft.document.clipboard.splice(operationIndex, 1)[0];
|
|
1562
|
-
draft.action = castDraft({
|
|
1563
|
-
type: operation.type,
|
|
1564
|
-
scope: operation.scope,
|
|
1565
|
-
input: operation.input
|
|
1566
|
-
});
|
|
1567
|
-
});
|
|
1568
|
-
}
|
|
1569
|
-
function pruneOperation(document, action, wrappedReducer) {
|
|
1570
|
-
const { scope } = action;
|
|
1571
|
-
const operations = document.operations[scope];
|
|
1572
|
-
let {
|
|
1573
|
-
input: { start, end }
|
|
1574
|
-
} = action;
|
|
1575
|
-
start = start || 0;
|
|
1576
|
-
end = end || operations.length;
|
|
1577
|
-
const actionsToPrune = operations.slice(start, end);
|
|
1578
|
-
const actionsToKeepStart = operations.slice(0, start);
|
|
1579
|
-
const actionsToKeepEnd = operations.slice(end);
|
|
1580
|
-
const newDocument = replayOperations(
|
|
1581
|
-
document.initialState,
|
|
1582
|
-
{
|
|
1583
|
-
...document.operations,
|
|
1584
|
-
[scope]: actionsToKeepStart.concat(actionsToPrune)
|
|
1585
|
-
},
|
|
1586
|
-
wrappedReducer
|
|
1587
|
-
);
|
|
1588
|
-
const { name, state: newState } = newDocument;
|
|
1589
|
-
const loadStateIndex = actionsToKeepStart.length;
|
|
1590
|
-
const loadStateTimestamp = actionsToKeepStart.length ? actionsToKeepStart[actionsToKeepStart.length - 1].timestamp : actionsToKeepEnd.length ? actionsToKeepEnd[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
|
|
1591
|
-
return replayOperations(
|
|
1592
|
-
document.initialState,
|
|
1593
|
-
{
|
|
1594
|
-
...document.operations,
|
|
1595
|
-
[scope]: [
|
|
1596
|
-
...actionsToKeepStart,
|
|
1597
|
-
{
|
|
1598
|
-
...loadState({ name, state: newState }, actionsToPrune.length),
|
|
1599
|
-
timestamp: loadStateTimestamp,
|
|
1600
|
-
index: loadStateIndex,
|
|
1601
|
-
hash: hashDocument({ state: newState }, "global")
|
|
1602
|
-
},
|
|
1603
|
-
...actionsToKeepEnd.map((action2, index) => ({
|
|
1604
|
-
...action2,
|
|
1605
|
-
index: loadStateIndex + index + 1
|
|
1606
|
-
}))
|
|
1607
|
-
]
|
|
1608
|
-
},
|
|
1609
|
-
wrappedReducer
|
|
1610
|
-
);
|
|
1611
|
-
}
|
|
1612
|
-
function loadStateOperation(oldDocument, newDocument) {
|
|
1613
|
-
return {
|
|
1614
|
-
...oldDocument,
|
|
1615
|
-
name: newDocument.name,
|
|
1616
|
-
state: newDocument.state ?? { global: {}, local: {} }
|
|
1617
|
-
};
|
|
1618
|
-
}
|
|
1619
|
-
const SET_NAME = "SET_NAME";
|
|
1620
|
-
const UNDO = "UNDO";
|
|
1621
|
-
const REDO = "REDO";
|
|
1622
|
-
const PRUNE = "PRUNE";
|
|
1623
|
-
const LOAD_STATE = "LOAD_STATE";
|
|
1624
|
-
const NOOP = "NOOP";
|
|
1625
|
-
function getNextRevision(document, action) {
|
|
1626
|
-
let latestOperation;
|
|
1627
|
-
if ("index" in action) {
|
|
1628
|
-
latestOperation = { ...action };
|
|
1629
|
-
} else {
|
|
1630
|
-
latestOperation = document.operations[action.scope].at(-1);
|
|
1631
|
-
}
|
|
1632
|
-
return ((latestOperation == null ? void 0 : latestOperation.index) ?? -1) + 1;
|
|
1633
|
-
}
|
|
1634
|
-
function updateHeader(document, action) {
|
|
1635
|
-
return {
|
|
1636
|
-
...document,
|
|
1637
|
-
revision: {
|
|
1638
|
-
...document.revision,
|
|
1639
|
-
[action.scope]: getNextRevision(document, action)
|
|
1640
|
-
},
|
|
1641
|
-
lastModified: (/* @__PURE__ */ new Date()).toISOString()
|
|
1642
|
-
};
|
|
1643
|
-
}
|
|
1644
|
-
function updateOperations(document, action, skip = 0, reuseLastOperationIndex = false) {
|
|
1645
|
-
if ([UNDO, REDO, PRUNE].includes(action.type)) {
|
|
1646
|
-
return document;
|
|
1647
|
-
}
|
|
1648
|
-
const { scope } = action;
|
|
1649
|
-
const operations = document.operations[scope].slice();
|
|
1650
|
-
let operationId;
|
|
1651
|
-
const latestOperation = operations.at(-1);
|
|
1652
|
-
const lastOperationIndex = (latestOperation == null ? void 0 : latestOperation.index) ?? -1;
|
|
1653
|
-
let nextIndex = reuseLastOperationIndex ? lastOperationIndex : lastOperationIndex + 1;
|
|
1654
|
-
if ("index" in action) {
|
|
1655
|
-
if (action.index - skip > nextIndex) {
|
|
1656
|
-
throw new Error(
|
|
1657
|
-
`Missing operations: expected ${nextIndex} with skip 0 or equivalent, got index ${action.index} with skip ${skip}`
|
|
1658
|
-
);
|
|
1659
|
-
}
|
|
1660
|
-
nextIndex = action.index;
|
|
1661
|
-
operationId = action.id;
|
|
1662
|
-
} else {
|
|
1663
|
-
operationId = "id" in action ? action.id : v4();
|
|
1664
|
-
}
|
|
1665
|
-
operations.push({
|
|
1666
|
-
...action,
|
|
1667
|
-
id: operationId,
|
|
1668
|
-
index: nextIndex,
|
|
1669
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1670
|
-
hash: "",
|
|
1671
|
-
scope,
|
|
1672
|
-
skip,
|
|
1673
|
-
error: void 0
|
|
1674
|
-
});
|
|
1675
|
-
return {
|
|
1676
|
-
...document,
|
|
1677
|
-
operations: { ...document.operations, [scope]: operations }
|
|
1678
|
-
};
|
|
1679
|
-
}
|
|
1680
|
-
function updateDocument(document, action, skip = 0, reuseLastOperationIndex = false) {
|
|
1681
|
-
let newDocument = updateOperations(
|
|
1682
|
-
document,
|
|
1683
|
-
action,
|
|
1684
|
-
skip,
|
|
1685
|
-
reuseLastOperationIndex
|
|
1686
|
-
);
|
|
1687
|
-
newDocument = updateHeader(newDocument, action);
|
|
1688
|
-
return newDocument;
|
|
1689
|
-
}
|
|
1690
|
-
function _baseReducer(document, action, wrappedReducer) {
|
|
1691
|
-
BaseActionSchema().parse(action);
|
|
1692
|
-
switch (action.type) {
|
|
1693
|
-
case SET_NAME:
|
|
1694
|
-
return setNameOperation(document, action.input);
|
|
1695
|
-
case PRUNE:
|
|
1696
|
-
return pruneOperation(document, action, wrappedReducer);
|
|
1697
|
-
case LOAD_STATE:
|
|
1698
|
-
return loadStateOperation(document, action.input.state);
|
|
1699
|
-
default:
|
|
1700
|
-
return document;
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
function processUndoRedo(document, action, skip) {
|
|
1704
|
-
switch (action.type) {
|
|
1705
|
-
case UNDO:
|
|
1706
|
-
return undoOperation(document, action, skip);
|
|
1707
|
-
case REDO:
|
|
1708
|
-
return redoOperation(document, action, skip);
|
|
1709
|
-
default:
|
|
1710
|
-
return { document, action, skip, reuseLastOperationIndex: false };
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
function processSkipOperation(document, action, customReducer, skipValue, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
|
|
1714
|
-
const scope = action.scope;
|
|
1715
|
-
const latestOperation = document.operations[scope].at(-1);
|
|
1716
|
-
if (!latestOperation) return document;
|
|
1717
|
-
const documentOperations = garbageCollectDocumentOperations({
|
|
1718
|
-
...document.operations,
|
|
1719
|
-
[scope]: skipHeaderOperations(
|
|
1720
|
-
document.operations[scope],
|
|
1721
|
-
latestOperation
|
|
1722
|
-
)
|
|
1723
|
-
});
|
|
1724
|
-
let scopeState = void 0;
|
|
1725
|
-
const lastRemainingOperation = documentOperations[scope].at(-1);
|
|
1726
|
-
if (reuseOperationResultingState && (lastRemainingOperation == null ? void 0 : lastRemainingOperation.resultingState)) {
|
|
1727
|
-
scopeState = resultingStateParser(lastRemainingOperation.resultingState);
|
|
1728
|
-
} else {
|
|
1729
|
-
const { state } = replayOperations(
|
|
1730
|
-
document.initialState,
|
|
1731
|
-
documentOperations,
|
|
1732
|
-
customReducer,
|
|
1733
|
-
void 0,
|
|
1734
|
-
void 0,
|
|
1735
|
-
void 0,
|
|
1736
|
-
void 0,
|
|
1737
|
-
{
|
|
1738
|
-
reuseHash: true,
|
|
1739
|
-
reuseOperationResultingState,
|
|
1740
|
-
operationResultingStateParser: resultingStateParser
|
|
1741
|
-
}
|
|
1742
|
-
);
|
|
1743
|
-
scopeState = state[scope];
|
|
1744
|
-
}
|
|
1745
|
-
return {
|
|
1746
|
-
...document,
|
|
1747
|
-
state: {
|
|
1748
|
-
...document.state,
|
|
1749
|
-
[scope]: scopeState
|
|
1750
|
-
},
|
|
1751
|
-
operations: garbageCollectDocumentOperations({
|
|
1752
|
-
...document.operations
|
|
1753
|
-
})
|
|
1754
|
-
};
|
|
1755
|
-
}
|
|
1756
|
-
function processUndoOperation(document, scope, customReducer, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
|
|
1757
|
-
const operations = [...document.operations[scope]];
|
|
1758
|
-
const sortedOperations = sortOperations$1(operations);
|
|
1759
|
-
sortedOperations.pop();
|
|
1760
|
-
const documentOperations = garbageCollectDocumentOperations({
|
|
1761
|
-
...document.operations
|
|
1762
|
-
});
|
|
1763
|
-
const clearedOperations = [...documentOperations[scope]];
|
|
1764
|
-
const diff = diffOperations(
|
|
1765
|
-
garbageCollect(sortedOperations),
|
|
1766
|
-
clearedOperations
|
|
1767
|
-
);
|
|
1768
|
-
const doc = replayOperations(
|
|
1769
|
-
document.initialState,
|
|
1770
|
-
documentOperations,
|
|
1771
|
-
customReducer,
|
|
1772
|
-
void 0,
|
|
1773
|
-
void 0,
|
|
1774
|
-
void 0,
|
|
1775
|
-
void 0,
|
|
1776
|
-
{
|
|
1777
|
-
reuseHash: true,
|
|
1778
|
-
reuseOperationResultingState,
|
|
1779
|
-
operationResultingStateParser: resultingStateParser
|
|
1780
|
-
}
|
|
1781
|
-
);
|
|
1782
|
-
const clipboard = sortOperations$1(
|
|
1783
|
-
[...document.clipboard, ...diff].filter((op) => op.type !== "NOOP")
|
|
1784
|
-
).reverse();
|
|
1785
|
-
return { ...doc, clipboard };
|
|
1786
|
-
}
|
|
1787
|
-
function baseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
1788
|
-
const {
|
|
1789
|
-
skip,
|
|
1790
|
-
ignoreSkipOperations = false,
|
|
1791
|
-
reuseHash = false,
|
|
1792
|
-
reuseOperationResultingState = false,
|
|
1793
|
-
operationResultingStateParser
|
|
1794
|
-
} = options;
|
|
1795
|
-
let _action = { ...action };
|
|
1796
|
-
let skipValue = skip || 0;
|
|
1797
|
-
let newDocument = { ...document };
|
|
1798
|
-
let reuseLastOperationIndex = false;
|
|
1799
|
-
const shouldProcessSkipOperation = !ignoreSkipOperations && (skipValue > 0 || "index" in _action && _action.skip > 0);
|
|
1800
|
-
if (isUndoRedo(_action)) {
|
|
1801
|
-
const {
|
|
1802
|
-
skip: calculatedSkip,
|
|
1803
|
-
action: transformedAction,
|
|
1804
|
-
document: processedDocument,
|
|
1805
|
-
reuseLastOperationIndex: reuseIndex
|
|
1806
|
-
} = processUndoRedo(document, _action, skipValue);
|
|
1807
|
-
_action = transformedAction;
|
|
1808
|
-
skipValue = calculatedSkip;
|
|
1809
|
-
newDocument = processedDocument;
|
|
1810
|
-
reuseLastOperationIndex = reuseIndex;
|
|
1811
|
-
} else {
|
|
1812
|
-
newDocument = {
|
|
1813
|
-
...newDocument,
|
|
1814
|
-
clipboard: []
|
|
1815
|
-
};
|
|
1816
|
-
}
|
|
1817
|
-
if (isBaseAction(_action)) {
|
|
1818
|
-
newDocument = _baseReducer(newDocument, _action, customReducer);
|
|
1819
|
-
}
|
|
1820
|
-
newDocument = updateDocument(
|
|
1821
|
-
newDocument,
|
|
1822
|
-
_action,
|
|
1823
|
-
skipValue,
|
|
1824
|
-
reuseLastOperationIndex
|
|
1825
|
-
);
|
|
1826
|
-
const isUndoAction = isUndo(action);
|
|
1827
|
-
if (isUndoAction) {
|
|
1828
|
-
const result = processUndoOperation(
|
|
1829
|
-
newDocument,
|
|
1830
|
-
action.scope,
|
|
1831
|
-
customReducer
|
|
1832
|
-
);
|
|
1833
|
-
return result;
|
|
1834
|
-
}
|
|
1835
|
-
if (shouldProcessSkipOperation) {
|
|
1836
|
-
newDocument = processSkipOperation(
|
|
1837
|
-
newDocument,
|
|
1838
|
-
_action,
|
|
1839
|
-
customReducer,
|
|
1840
|
-
skipValue,
|
|
1841
|
-
reuseOperationResultingState,
|
|
1842
|
-
operationResultingStateParser
|
|
1843
|
-
);
|
|
1844
|
-
}
|
|
1845
|
-
newDocument = create(newDocument, (draft) => {
|
|
1846
|
-
try {
|
|
1847
|
-
const newState = customReducer(draft.state, _action, dispatch);
|
|
1848
|
-
if (newState) {
|
|
1849
|
-
unsafe(() => {
|
|
1850
|
-
draft.state = castDraft(newState);
|
|
1851
|
-
});
|
|
1852
|
-
} else {
|
|
1853
|
-
}
|
|
1854
|
-
} catch (error) {
|
|
1855
|
-
const lastOperationIndex = newDocument.operations[_action.scope].length - 1;
|
|
1856
|
-
draft.operations[_action.scope][lastOperationIndex].error = error.message;
|
|
1857
|
-
draft.operations[_action.scope][lastOperationIndex].skip = 0;
|
|
1858
|
-
if (shouldProcessSkipOperation) {
|
|
1859
|
-
draft.state = castDraft({ ...document.state });
|
|
1860
|
-
draft.operations = castDraft({
|
|
1861
|
-
...document.operations,
|
|
1862
|
-
[_action.scope]: [
|
|
1863
|
-
...document.operations[_action.scope],
|
|
1864
|
-
{
|
|
1865
|
-
...draft.operations[_action.scope][lastOperationIndex]
|
|
1866
|
-
}
|
|
1867
|
-
]
|
|
1868
|
-
});
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
});
|
|
1872
|
-
if ([UNDO, REDO, PRUNE].includes(_action.type)) {
|
|
1873
|
-
return newDocument;
|
|
1874
|
-
}
|
|
1875
|
-
const scope = _action.scope || "global";
|
|
1876
|
-
const hash2 = reuseHash && Object.prototype.hasOwnProperty.call(_action, "hash") ? _action.hash : hashDocument(newDocument, scope);
|
|
1877
|
-
const lastOperation = newDocument.operations[scope].at(-1);
|
|
1878
|
-
if (lastOperation) {
|
|
1879
|
-
lastOperation.hash = hash2;
|
|
1880
|
-
if (reuseOperationResultingState) {
|
|
1881
|
-
lastOperation.resultingState = newDocument.state[scope];
|
|
1882
|
-
}
|
|
1883
|
-
if (!isBaseAction(_action) && _action.attachments) {
|
|
1884
|
-
_action.attachments.forEach((attachment) => {
|
|
1885
|
-
const { hash: hash22, ...file } = attachment;
|
|
1886
|
-
newDocument.attachments[hash22] = {
|
|
1887
|
-
...file
|
|
1888
|
-
};
|
|
1889
|
-
});
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
return newDocument;
|
|
1893
|
-
}
|
|
1894
|
-
function mutableBaseReducer(document, action, customReducer, dispatch, options = {}) {
|
|
1895
|
-
const {
|
|
1896
|
-
skip,
|
|
1897
|
-
ignoreSkipOperations = false,
|
|
1898
|
-
reuseHash = false,
|
|
1899
|
-
reuseOperationResultingState = false,
|
|
1900
|
-
operationResultingStateParser
|
|
1901
|
-
} = options;
|
|
1902
|
-
const _action = { ...action };
|
|
1903
|
-
const skipValue = skip || 0;
|
|
1904
|
-
let newDocument = { ...document };
|
|
1905
|
-
const shouldProcessSkipOperation = !ignoreSkipOperations && (skipValue > 0 || "index" in _action && _action.skip > 0);
|
|
1906
|
-
if (isBaseAction(_action)) {
|
|
1907
|
-
newDocument = _baseReducer(newDocument, _action, customReducer);
|
|
1908
|
-
}
|
|
1909
|
-
newDocument = updateDocument(newDocument, _action, skipValue);
|
|
1910
|
-
if (shouldProcessSkipOperation) {
|
|
1911
|
-
newDocument = processSkipOperation(
|
|
1912
|
-
newDocument,
|
|
1913
|
-
_action,
|
|
1914
|
-
customReducer,
|
|
1915
|
-
skipValue,
|
|
1916
|
-
reuseOperationResultingState,
|
|
1917
|
-
operationResultingStateParser
|
|
1918
|
-
);
|
|
1919
|
-
}
|
|
1920
|
-
try {
|
|
1921
|
-
const newState = customReducer(
|
|
1922
|
-
newDocument.state,
|
|
1923
|
-
_action,
|
|
1924
|
-
dispatch
|
|
1925
|
-
);
|
|
1926
|
-
if (newState) {
|
|
1927
|
-
newDocument.state = newState;
|
|
1928
|
-
}
|
|
1929
|
-
} catch (error) {
|
|
1930
|
-
const lastOperationIndex = newDocument.operations[_action.scope].length - 1;
|
|
1931
|
-
newDocument.operations[_action.scope][lastOperationIndex].error = error.message;
|
|
1932
|
-
newDocument.operations[_action.scope][lastOperationIndex].skip = 0;
|
|
1933
|
-
if (shouldProcessSkipOperation) {
|
|
1934
|
-
newDocument.state = { ...document.state };
|
|
1935
|
-
newDocument.operations = {
|
|
1936
|
-
...document.operations,
|
|
1937
|
-
[_action.scope]: [
|
|
1938
|
-
...document.operations[_action.scope],
|
|
1939
|
-
{
|
|
1940
|
-
...newDocument.operations[_action.scope][lastOperationIndex]
|
|
1941
|
-
}
|
|
1942
|
-
]
|
|
1943
|
-
};
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
if ([UNDO, REDO, PRUNE].includes(_action.type)) {
|
|
1947
|
-
return newDocument;
|
|
1948
|
-
}
|
|
1949
|
-
const scope = _action.scope || "global";
|
|
1950
|
-
const hash2 = reuseHash && Object.prototype.hasOwnProperty.call(_action, "hash") ? _action.hash : hashDocument(newDocument, scope);
|
|
1951
|
-
const lastOperation = newDocument.operations[scope].at(-1);
|
|
1952
|
-
if (lastOperation) {
|
|
1953
|
-
lastOperation.hash = hash2;
|
|
1954
|
-
if (reuseOperationResultingState) {
|
|
1955
|
-
lastOperation.resultingState = newDocument.state[scope];
|
|
1956
|
-
}
|
|
1957
|
-
if (!isBaseAction(_action) && _action.attachments) {
|
|
1958
|
-
_action.attachments.forEach((attachment) => {
|
|
1959
|
-
const { hash: hash22, ...file } = attachment;
|
|
1960
|
-
newDocument.attachments[hash22] = {
|
|
1961
|
-
...file
|
|
1962
|
-
};
|
|
1963
|
-
});
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
return newDocument;
|
|
1967
|
-
}
|
|
1968
|
-
function isNoopOperation(op) {
|
|
1969
|
-
return op.type === NOOP && op.skip !== void 0 && op.skip > 0 && op.hash !== void 0;
|
|
1970
|
-
}
|
|
1971
|
-
function isUndoRedo(action) {
|
|
1972
|
-
return [UNDO, REDO].includes(action.type);
|
|
1973
|
-
}
|
|
1974
|
-
function isUndo(action) {
|
|
1975
|
-
return action.type === UNDO;
|
|
1976
|
-
}
|
|
1977
|
-
function isBaseAction(action) {
|
|
1978
|
-
return [SET_NAME, UNDO, REDO, PRUNE, LOAD_STATE].includes(action.type);
|
|
1979
|
-
}
|
|
1980
|
-
function createAction(type, input, attachments, validator, scope = "global") {
|
|
1981
|
-
if (!type) {
|
|
1982
|
-
throw new Error("Empty action type");
|
|
1983
|
-
}
|
|
1984
|
-
if (typeof type !== "string") {
|
|
1985
|
-
throw new Error(`Invalid action type: ${JSON.stringify(type)}`);
|
|
1986
|
-
}
|
|
1987
|
-
const action = { type, input, scope };
|
|
1988
|
-
if (attachments) {
|
|
1989
|
-
action.attachments = attachments;
|
|
1990
|
-
}
|
|
1991
|
-
try {
|
|
1992
|
-
validator == null ? void 0 : validator().parse(action.input);
|
|
1993
|
-
} catch (error) {
|
|
1994
|
-
throw new Error(`Invalid action input: ${error}`);
|
|
1995
|
-
}
|
|
1996
|
-
return action;
|
|
1997
|
-
}
|
|
1998
|
-
function createReducer(reducer, documentReducer = baseReducer) {
|
|
1999
|
-
return (document, action, dispatch, options) => {
|
|
2000
|
-
return documentReducer(document, action, reducer, dispatch, options);
|
|
2001
|
-
};
|
|
2002
|
-
}
|
|
2003
|
-
function createUnsafeReducer(reducer, documentReducer = mutableBaseReducer) {
|
|
2004
|
-
return (document, action, dispatch, options) => {
|
|
2005
|
-
return documentReducer(document, action, reducer, dispatch, options);
|
|
2006
|
-
};
|
|
2007
|
-
}
|
|
2008
|
-
const createExtendedState = (initialState, createState) => {
|
|
2009
|
-
return {
|
|
2010
|
-
name: "",
|
|
2011
|
-
documentType: "",
|
|
2012
|
-
revision: {
|
|
2013
|
-
global: 0,
|
|
2014
|
-
local: 0
|
|
2015
|
-
},
|
|
2016
|
-
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2017
|
-
lastModified: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2018
|
-
attachments: {},
|
|
2019
|
-
...initialState,
|
|
2020
|
-
state: (createState == null ? void 0 : createState(initialState == null ? void 0 : initialState.state)) ?? ((initialState == null ? void 0 : initialState.state) ?? { global: {}, local: {} })
|
|
2021
|
-
};
|
|
2022
|
-
};
|
|
2023
|
-
const createDocument = (initialState, createState) => {
|
|
2024
|
-
const state = createExtendedState(
|
|
2025
|
-
initialState,
|
|
2026
|
-
createState
|
|
2027
|
-
);
|
|
2028
|
-
return {
|
|
2029
|
-
...state,
|
|
2030
|
-
initialState: state,
|
|
2031
|
-
operations: { global: [], local: [] },
|
|
2032
|
-
clipboard: []
|
|
2033
|
-
};
|
|
2034
|
-
};
|
|
2035
|
-
const hashDocument = (document, scope = "global") => {
|
|
2036
|
-
return hash(cjsModule(document.state[scope] || ""));
|
|
2037
|
-
};
|
|
2038
|
-
const hashKey = (date, randomLimit = 1e3) => {
|
|
2039
|
-
const random = Math.random() * randomLimit;
|
|
2040
|
-
return hash(`${(date ?? /* @__PURE__ */ new Date()).toISOString()}${random}`);
|
|
2041
|
-
};
|
|
2042
|
-
function readOnly(value) {
|
|
2043
|
-
return Object.freeze(value);
|
|
2044
|
-
}
|
|
2045
|
-
function mapSkippedOperations(operations, skippedHeadOperations) {
|
|
2046
|
-
const ops = [...operations];
|
|
2047
|
-
let skipped = skippedHeadOperations || 0;
|
|
2048
|
-
let latestOpIndex = ops.length > 0 ? ops[ops.length - 1].index : 0;
|
|
2049
|
-
const scopeOpsWithIgnore = [];
|
|
2050
|
-
for (const operation of ops.reverse()) {
|
|
2051
|
-
if (skipped > 0) {
|
|
2052
|
-
const operationsDiff = latestOpIndex - operation.index;
|
|
2053
|
-
skipped -= operationsDiff;
|
|
2054
|
-
}
|
|
2055
|
-
if (skipped < 0) {
|
|
2056
|
-
throw new Error("Invalid operation index, missing operations");
|
|
2057
|
-
}
|
|
2058
|
-
const mappedOp = {
|
|
2059
|
-
ignore: skipped > 0,
|
|
2060
|
-
operation
|
|
2061
|
-
};
|
|
2062
|
-
const operationSkip = operation.skip > 0 ? operation.skip + 1 : 0;
|
|
2063
|
-
if (operationSkip > 0 && operationSkip > skipped) {
|
|
2064
|
-
const skipDiff = operationSkip - skipped;
|
|
2065
|
-
skipped = skipped + skipDiff;
|
|
2066
|
-
}
|
|
2067
|
-
latestOpIndex = operation.index;
|
|
2068
|
-
scopeOpsWithIgnore.push(mappedOp);
|
|
2069
|
-
}
|
|
2070
|
-
return scopeOpsWithIgnore.reverse();
|
|
2071
|
-
}
|
|
2072
|
-
function sortOperations(operations) {
|
|
2073
|
-
return Object.values(operations).flatMap((array) => array).sort(
|
|
2074
|
-
(a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
|
|
2075
|
-
);
|
|
2076
|
-
}
|
|
2077
|
-
function sortMappedOperations(operations) {
|
|
2078
|
-
return Object.values(operations).flatMap((array) => array).sort(
|
|
2079
|
-
(a, b) => new Date(a.operation.timestamp).getTime() - new Date(b.operation.timestamp).getTime()
|
|
2080
|
-
);
|
|
2081
|
-
}
|
|
2082
|
-
function replayOperations(initialState, clearedOperations, reducer, dispatch, header, documentReducer = baseReducer, skipHeaderOperations2 = {}, options) {
|
|
2083
|
-
const wrappedReducer = createReducer(reducer, documentReducer);
|
|
2084
|
-
return replayDocument(
|
|
2085
|
-
initialState,
|
|
2086
|
-
clearedOperations,
|
|
2087
|
-
wrappedReducer,
|
|
2088
|
-
dispatch,
|
|
2089
|
-
header,
|
|
2090
|
-
skipHeaderOperations2,
|
|
2091
|
-
options
|
|
2092
|
-
);
|
|
2093
|
-
}
|
|
2094
|
-
function replayDocument(initialState, operations, reducer, dispatch, header, skipHeaderOperations2 = {}, options) {
|
|
2095
|
-
const {
|
|
2096
|
-
checkHashes = true,
|
|
2097
|
-
reuseOperationResultingState,
|
|
2098
|
-
operationResultingStateParser = parseResultingState
|
|
2099
|
-
} = options || {};
|
|
2100
|
-
let documentState = initialState;
|
|
2101
|
-
const operationsToReplay = [];
|
|
2102
|
-
const initialOperations = {
|
|
2103
|
-
global: [],
|
|
2104
|
-
local: []
|
|
2105
|
-
};
|
|
2106
|
-
if (reuseOperationResultingState) {
|
|
2107
|
-
for (const [scope, scopeOperations] of Object.entries(operations)) {
|
|
2108
|
-
const index = scopeOperations.findLastIndex((s) => !!s.resultingState);
|
|
2109
|
-
if (index < 0) {
|
|
2110
|
-
operationsToReplay.push(...scopeOperations);
|
|
2111
|
-
continue;
|
|
2112
|
-
}
|
|
2113
|
-
const opWithState = scopeOperations[index];
|
|
2114
|
-
try {
|
|
2115
|
-
const scopeState = operationResultingStateParser(
|
|
2116
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
|
|
2117
|
-
opWithState.resultingState
|
|
2118
|
-
);
|
|
2119
|
-
documentState = {
|
|
2120
|
-
...documentState,
|
|
2121
|
-
state: {
|
|
2122
|
-
...documentState.state,
|
|
2123
|
-
// TODO how to deal with attachments?
|
|
2124
|
-
[scope]: scopeState
|
|
2125
|
-
}
|
|
2126
|
-
};
|
|
2127
|
-
initialOperations[scope].push(
|
|
2128
|
-
...scopeOperations.slice(0, index + 1)
|
|
2129
|
-
);
|
|
2130
|
-
operationsToReplay.push(...scopeOperations.slice(index + 1));
|
|
2131
|
-
} catch {
|
|
2132
|
-
operationsToReplay.push(...scopeOperations);
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
} else {
|
|
2136
|
-
operationsToReplay.push(...Object.values(operations).flat());
|
|
2137
|
-
}
|
|
2138
|
-
const document = createDocument(documentState);
|
|
2139
|
-
document.initialState = initialState;
|
|
2140
|
-
document.operations = initialOperations;
|
|
2141
|
-
let result = document;
|
|
2142
|
-
if (operationsToReplay.length) {
|
|
2143
|
-
result = operationsToReplay.reduce((document2, operation) => {
|
|
2144
|
-
const doc = reducer(document2, operation, dispatch, {
|
|
2145
|
-
skip: operation.skip,
|
|
2146
|
-
ignoreSkipOperations: true,
|
|
2147
|
-
reuseHash: !checkHashes
|
|
2148
|
-
});
|
|
2149
|
-
return doc;
|
|
2150
|
-
}, document);
|
|
2151
|
-
} else {
|
|
2152
|
-
for (const scopeOperations of Object.values(initialOperations)) {
|
|
2153
|
-
const lastOperation = scopeOperations.at(-1);
|
|
2154
|
-
if (lastOperation) {
|
|
2155
|
-
result = updateHeader(result, lastOperation);
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
if (!checkHashes) {
|
|
2160
|
-
for (const scope of Object.keys(result.state)) {
|
|
2161
|
-
for (let i = operationsToReplay.length - 1; i >= 0; i--) {
|
|
2162
|
-
const operation = operationsToReplay[i];
|
|
2163
|
-
if (operation.scope !== scope) {
|
|
2164
|
-
continue;
|
|
2165
|
-
}
|
|
2166
|
-
if (operation.hash !== hashDocument(result, scope)) {
|
|
2167
|
-
throw new Error(`Hash mismatch for scope ${scope}`);
|
|
2168
|
-
} else {
|
|
2169
|
-
break;
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
|
-
}
|
|
2173
|
-
}
|
|
2174
|
-
const resultOperations = Object.keys(
|
|
2175
|
-
result.operations
|
|
2176
|
-
).reduce(
|
|
2177
|
-
(acc, key) => {
|
|
2178
|
-
const scope = key;
|
|
2179
|
-
return {
|
|
2180
|
-
...acc,
|
|
2181
|
-
[scope]: [
|
|
2182
|
-
...result.operations[scope].map((operation, index) => {
|
|
2183
|
-
var _a;
|
|
2184
|
-
return {
|
|
2185
|
-
...operation,
|
|
2186
|
-
timestamp: ((_a = operations[scope][index]) == null ? void 0 : _a.timestamp) ?? operation.timestamp
|
|
2187
|
-
};
|
|
2188
|
-
})
|
|
2189
|
-
]
|
|
2190
|
-
};
|
|
2191
|
-
},
|
|
2192
|
-
{ global: [], local: [] }
|
|
2193
|
-
);
|
|
2194
|
-
const lastModified = Object.values(resultOperations).reduce((acc, curr) => {
|
|
2195
|
-
const operation = curr.at(-1);
|
|
2196
|
-
if (operation && operation.timestamp > acc) {
|
|
2197
|
-
acc = operation.timestamp;
|
|
2198
|
-
}
|
|
2199
|
-
return acc;
|
|
2200
|
-
}, initialState.lastModified);
|
|
2201
|
-
return { ...result, operations: resultOperations, lastModified };
|
|
2202
|
-
}
|
|
2203
|
-
function isSameDocument(documentA, documentB) {
|
|
2204
|
-
return cjsModule(documentA) === cjsModule(documentB);
|
|
2205
|
-
}
|
|
2206
|
-
function parseResultingState(state) {
|
|
2207
|
-
const stateType = typeof state;
|
|
2208
|
-
if (stateType === "string") {
|
|
2209
|
-
return JSON.parse(state);
|
|
2210
|
-
} else if (stateType === "object") {
|
|
2211
|
-
return state;
|
|
2212
|
-
} else {
|
|
2213
|
-
throw new Error(`Providing resulting state is of type: ${stateType}`);
|
|
2214
|
-
}
|
|
2215
|
-
}
|
|
2216
|
-
const setName = (name) => createAction(
|
|
2217
|
-
"SET_NAME",
|
|
2218
|
-
name,
|
|
2219
|
-
void 0,
|
|
2220
|
-
SetNameActionInputSchema,
|
|
2221
|
-
void 0
|
|
2222
|
-
);
|
|
2223
|
-
const undo = (skip = 1, scope = "global") => createAction(
|
|
2224
|
-
"UNDO",
|
|
2225
|
-
skip,
|
|
2226
|
-
void 0,
|
|
2227
|
-
UndoActionInputSchema,
|
|
2228
|
-
scope
|
|
2229
|
-
);
|
|
2230
|
-
const redo = (count = 1, scope = "global") => createAction(
|
|
2231
|
-
"REDO",
|
|
2232
|
-
count,
|
|
2233
|
-
void 0,
|
|
2234
|
-
RedoActionInputSchema,
|
|
2235
|
-
scope
|
|
2236
|
-
);
|
|
2237
|
-
const prune = (start, end, scope = "global") => createAction(
|
|
2238
|
-
"PRUNE",
|
|
2239
|
-
{ start, end },
|
|
2240
|
-
void 0,
|
|
2241
|
-
PruneActionInputSchema,
|
|
2242
|
-
scope
|
|
2243
|
-
);
|
|
2244
|
-
const loadState = (state, operations) => createAction(
|
|
2245
|
-
"LOAD_STATE",
|
|
2246
|
-
{ state, operations },
|
|
2247
|
-
void 0,
|
|
2248
|
-
LoadStateActionInputSchema
|
|
2249
|
-
);
|
|
2250
|
-
const noop = (scope = "global") => createAction("NOOP", {}, void 0, void 0, scope);
|
|
2251
|
-
const BaseActions = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2252
|
-
__proto__: null,
|
|
2253
|
-
loadState,
|
|
2254
|
-
noop,
|
|
2255
|
-
prune,
|
|
2256
|
-
redo,
|
|
2257
|
-
setName,
|
|
2258
|
-
undo
|
|
2259
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
2260
|
-
class BaseDocument {
|
|
2261
|
-
/**
|
|
2262
|
-
* Constructs a BaseDocument instance with an initial state.
|
|
2263
|
-
* @param reducer - The reducer function that updates the state.
|
|
2264
|
-
* @param document - The initial state of the document.
|
|
2265
|
-
*/
|
|
2266
|
-
constructor(reducer, document, signalDispatch) {
|
|
2267
|
-
__publicField(this, "_document");
|
|
2268
|
-
__publicField(this, "_reducer");
|
|
2269
|
-
__publicField(this, "_signalDispatch");
|
|
2270
|
-
this._reducer = reducer;
|
|
2271
|
-
this._document = document;
|
|
2272
|
-
this._signalDispatch = signalDispatch;
|
|
2273
|
-
}
|
|
2274
|
-
/**
|
|
2275
|
-
* Dispatches an action to update the state of the document.
|
|
2276
|
-
* @param action - The action to dispatch.
|
|
2277
|
-
* @returns The Document instance.
|
|
2278
|
-
*/
|
|
2279
|
-
dispatch(action, options) {
|
|
2280
|
-
this._document = this._reducer(
|
|
2281
|
-
this._document,
|
|
2282
|
-
action,
|
|
2283
|
-
this._signalDispatch,
|
|
2284
|
-
options
|
|
2285
|
-
);
|
|
2286
|
-
return this;
|
|
2287
|
-
}
|
|
2288
|
-
/**
|
|
2289
|
-
* Saves the state of the document to a file.
|
|
2290
|
-
* @param path - The file path where the state should be saved.
|
|
2291
|
-
* @param extension - The file extension to use when saving the state.
|
|
2292
|
-
* @returns The file path where the state was saved.
|
|
2293
|
-
*/
|
|
2294
|
-
saveToFile(path, extension, name) {
|
|
2295
|
-
return saveToFile(this._document, path, extension, name);
|
|
2296
|
-
}
|
|
2297
|
-
/**
|
|
2298
|
-
* Loads the state of the document from a file.
|
|
2299
|
-
* @param path - The file path where the state is stored.
|
|
2300
|
-
*/
|
|
2301
|
-
async loadFromFile(path) {
|
|
2302
|
-
this._document = await loadFromFile(path, this._reducer);
|
|
2303
|
-
}
|
|
2304
|
-
/**
|
|
2305
|
-
* Loads the state of the document from a file and returns it.
|
|
2306
|
-
* @param path - The file path where the state is stored.
|
|
2307
|
-
* @param reducer - The reducer function that updates the state.
|
|
2308
|
-
* @returns The state of the document.
|
|
2309
|
-
*/
|
|
2310
|
-
static async stateFromFile(path, reducer) {
|
|
2311
|
-
const state = await loadFromFile(path, reducer);
|
|
2312
|
-
return state;
|
|
2313
|
-
}
|
|
2314
|
-
/**
|
|
2315
|
-
* Gets the current state of the document.
|
|
2316
|
-
*/
|
|
2317
|
-
get state() {
|
|
2318
|
-
return readOnly(this._document.state);
|
|
2319
|
-
}
|
|
2320
|
-
/**
|
|
2321
|
-
* Gets the list of operations performed on the document.
|
|
2322
|
-
*/
|
|
2323
|
-
get operations() {
|
|
2324
|
-
return readOnly(this._document.operations);
|
|
2325
|
-
}
|
|
2326
|
-
/**
|
|
2327
|
-
* Gets the name of the document.
|
|
2328
|
-
*/
|
|
2329
|
-
get name() {
|
|
2330
|
-
return this._document.name;
|
|
2331
|
-
}
|
|
2332
|
-
/**
|
|
2333
|
-
* Gets the type of document.
|
|
2334
|
-
*/
|
|
2335
|
-
get documentType() {
|
|
2336
|
-
return this._document.documentType;
|
|
2337
|
-
}
|
|
2338
|
-
/**
|
|
2339
|
-
* Gets the timestamp of the date the document was created.
|
|
2340
|
-
*/
|
|
2341
|
-
get created() {
|
|
2342
|
-
return this._document.created;
|
|
2343
|
-
}
|
|
2344
|
-
/**
|
|
2345
|
-
* Gets the timestamp of the date the document was last modified.
|
|
2346
|
-
*/
|
|
2347
|
-
get lastModified() {
|
|
2348
|
-
return this._document.lastModified;
|
|
2349
|
-
}
|
|
2350
|
-
/**
|
|
2351
|
-
* Gets the global revision number of the document.
|
|
2352
|
-
*/
|
|
2353
|
-
get revision() {
|
|
2354
|
-
return this._document.revision.global;
|
|
2355
|
-
}
|
|
2356
|
-
getRevision(scope) {
|
|
2357
|
-
return this._document.revision[scope];
|
|
2358
|
-
}
|
|
2359
|
-
/**
|
|
2360
|
-
* Gets the initial state of the document.
|
|
2361
|
-
*/
|
|
2362
|
-
get initialState() {
|
|
2363
|
-
return readOnly(this._document.initialState);
|
|
2364
|
-
}
|
|
2365
|
-
/**
|
|
2366
|
-
* Returns the current document as an object
|
|
2367
|
-
*/
|
|
2368
|
-
toDocument() {
|
|
2369
|
-
return readOnly(this._document);
|
|
2370
|
-
}
|
|
2371
|
-
/**
|
|
2372
|
-
* Gets the attachment associated with the given key.
|
|
2373
|
-
* @param attachment - The key of the attachment to retrieve.
|
|
2374
|
-
*/
|
|
2375
|
-
getAttachment(attachment) {
|
|
2376
|
-
return this._document.attachments[attachment];
|
|
2377
|
-
}
|
|
2378
|
-
/**
|
|
2379
|
-
* Sets the name of the document.
|
|
2380
|
-
* @param name - The new name of the document.
|
|
2381
|
-
*/
|
|
2382
|
-
setName(name) {
|
|
2383
|
-
this.dispatch(setName(name));
|
|
2384
|
-
return this;
|
|
2385
|
-
}
|
|
2386
|
-
/**
|
|
2387
|
-
* Reverts a number of actions from the document.
|
|
2388
|
-
* @param count - The number of actions to revert.
|
|
2389
|
-
*/
|
|
2390
|
-
undo(count) {
|
|
2391
|
-
this.dispatch(undo(count));
|
|
2392
|
-
return this;
|
|
2393
|
-
}
|
|
2394
|
-
/**
|
|
2395
|
-
* Reapplies a number of actions to the document.
|
|
2396
|
-
* @param count - The number of actions to reapply.
|
|
2397
|
-
*/
|
|
2398
|
-
redo(count) {
|
|
2399
|
-
this.dispatch(redo(count));
|
|
2400
|
-
return this;
|
|
2401
|
-
}
|
|
2402
|
-
/**
|
|
2403
|
-
* Removes a range of operations from the document.
|
|
2404
|
-
* @param start - The starting index of the range to remove.
|
|
2405
|
-
* @param end - The ending index of the range to remove.
|
|
2406
|
-
*/
|
|
2407
|
-
prune(start, end) {
|
|
2408
|
-
this.dispatch(prune(start, end));
|
|
2409
|
-
return this;
|
|
2410
|
-
}
|
|
2411
|
-
/**
|
|
2412
|
-
* Loads a document state and a set of operations.
|
|
2413
|
-
* @param state - The state to load.
|
|
2414
|
-
* @param operations - The operations to apply to the document.
|
|
2415
|
-
*/
|
|
2416
|
-
loadState(state, operations) {
|
|
2417
|
-
this.dispatch(loadState(state, operations));
|
|
2418
|
-
return this;
|
|
2419
|
-
}
|
|
2420
|
-
}
|
|
2421
|
-
function applyMixins(derivedCtor, constructors) {
|
|
2422
|
-
constructors.forEach((baseCtor) => {
|
|
2423
|
-
Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
|
|
2424
|
-
Object.defineProperty(
|
|
2425
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
2426
|
-
derivedCtor.prototype,
|
|
2427
|
-
name,
|
|
2428
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
2429
|
-
Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || /* @__PURE__ */ Object.create(null)
|
|
2430
|
-
);
|
|
2431
|
-
});
|
|
2432
|
-
});
|
|
2433
|
-
}
|
|
2434
|
-
export {
|
|
2435
|
-
isSameDocument as A,
|
|
2436
|
-
BaseDocument as B,
|
|
2437
|
-
isUndo as C,
|
|
2438
|
-
isUndoRedo as D,
|
|
2439
|
-
mapSkippedOperations as E,
|
|
2440
|
-
parseResultingState as F,
|
|
2441
|
-
readOnly as G,
|
|
2442
|
-
replayDocument as H,
|
|
2443
|
-
replayOperations as I,
|
|
2444
|
-
sortMappedOperations as J,
|
|
2445
|
-
sortOperations as K,
|
|
2446
|
-
validateOperations as L,
|
|
2447
|
-
verifyOperationSignature as M,
|
|
2448
|
-
baseReducer as N,
|
|
2449
|
-
mutableBaseReducer as O,
|
|
2450
|
-
processUndoRedo as P,
|
|
2451
|
-
updateDocument as Q,
|
|
2452
|
-
updateHeader as R,
|
|
2453
|
-
zod as S,
|
|
2454
|
-
createExtendedState as a,
|
|
2455
|
-
createDocument as b,
|
|
2456
|
-
createReducer as c,
|
|
2457
|
-
saveToFileHandle as d,
|
|
2458
|
-
loadFromInput as e,
|
|
2459
|
-
createAction as f,
|
|
2460
|
-
applyMixins as g,
|
|
2461
|
-
BaseActions as h,
|
|
2462
|
-
isBaseAction as i,
|
|
2463
|
-
ab2hex as j,
|
|
2464
|
-
buildOperationSignature as k,
|
|
2465
|
-
loadFromFile as l,
|
|
2466
|
-
buildOperationSignatureMessage as m,
|
|
2467
|
-
buildOperationSignatureParams as n,
|
|
2468
|
-
buildSignedOperation as o,
|
|
2469
|
-
createUnsafeReducer as p,
|
|
2470
|
-
createZip as q,
|
|
2471
|
-
documentHelpers as r,
|
|
2472
|
-
saveToFile as s,
|
|
2473
|
-
getLocalFile as t,
|
|
2474
|
-
getRemoteFile as u,
|
|
2475
|
-
getUnixTimestamp as v,
|
|
2476
|
-
hashDocument as w,
|
|
2477
|
-
hashKey as x,
|
|
2478
|
-
hex2ab as y,
|
|
2479
|
-
isNoopOperation as z
|
|
2480
|
-
};
|
|
2481
|
-
//# sourceMappingURL=object-C8sca9DR.js.map
|