spec-3nweb-server 1.8.4 → 1.8.6
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/.gitlab-ci-linux.yml +50 -0
- package/.gitlab-ci-mac.yml +29 -0
- package/.gitlab-ci-windows.yml +29 -0
- package/.gitlab-ci.yml +63 -0
- package/build/3nstorage/routes/owner/archive-obj-version.js +2 -2
- package/build/3nstorage/routes/owner/cancel-trans.js +2 -2
- package/build/3nstorage/routes/owner/delete-obj.js +2 -2
- package/build/3nstorage/routes/owner/get-current-obj.js +3 -4
- package/build/3nstorage/routes/owner/param-setter.js +2 -6
- package/build/asmail/routes/config/param-setter.js +2 -2
- package/build/asmail/routes/delivery/finalize-delivery.js +2 -2
- package/build/asmail/routes/delivery/put-obj.js +2 -2
- package/build/asmail/routes/delivery/sender-authorization.js +2 -2
- package/build/asmail/routes/retrieval/remove-message.js +2 -2
- package/build/cli/signup-cmd.js +0 -1
- package/build/lib-server/routes/sessions/close.js +2 -2
- package/build/lib-server/routes/sessions/mid-auth.js +2 -5
- package/build/main.js +12 -15
- package/build/mock/tls-options.js +46 -44
- package/build/signup/routes/add.js +4 -4
- package/build/tests/admin-proto/signup.d.ts +1 -0
- package/build/tests/admin-proto/signup.js +235 -0
- package/build/tests/jasmine.d.ts +1 -0
- package/build/tests/jasmine.js +32 -0
- package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
- package/build/tests/libs-for-tests/3nstorage.js +123 -0
- package/build/tests/libs-for-tests/asmail.d.ts +22 -0
- package/build/tests/libs-for-tests/asmail.js +179 -0
- package/build/tests/libs-for-tests/assert.d.ts +1 -0
- package/build/tests/libs-for-tests/assert.js +26 -0
- package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
- package/build/tests/libs-for-tests/async-jasmine.js +77 -0
- package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/bytes-equal.js +34 -0
- package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
- package/build/tests/libs-for-tests/json-copy.js +45 -0
- package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
- package/build/tests/libs-for-tests/json-equal.js +67 -0
- package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
- package/build/tests/libs-for-tests/mailerid.js +114 -0
- package/build/tests/libs-for-tests/pkl.d.ts +28 -0
- package/build/tests/libs-for-tests/pkl.js +89 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
- package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
- package/build/tests/libs-for-tests/server-components/admin.js +43 -0
- package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
- package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
- package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
- package/build/tests/libs-for-tests/server-components/component.js +77 -0
- package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
- package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
- package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
- package/build/tests/libs-for-tests/server-runner.js +69 -0
- package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
- package/build/tests/libs-for-tests/spec-assembly.js +55 -0
- package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
- package/build/tests/libs-for-tests/ws-utils.js +59 -0
- package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
- package/build/tests/libs-for-tests/xhr-utils.js +154 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
- package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
- package/build/tests/protocols/3nstorage/owner.js +138 -0
- package/build/tests/protocols/asmail/config.d.ts +1 -0
- package/build/tests/protocols/asmail/config.js +117 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
- package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
- package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
- package/build/tests/protocols/asmail/delivery.d.ts +1 -0
- package/build/tests/protocols/asmail/delivery.js +46 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
- package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
- package/build/tests/protocols/asmail/retrieval.js +92 -0
- package/build/tests/protocols/mailerid.d.ts +1 -0
- package/build/tests/protocols/mailerid.js +210 -0
- package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
- package/build/tests/shared-checks/check-mid-login.js +131 -0
- package/build/tests/shared-checks/requests.d.ts +20 -0
- package/build/tests/shared-checks/requests.js +123 -0
- package/package.json +1 -1
- package/packing/create-deb.sh +57 -0
- package/packing/deb/lib/systemd/system/3nweb.service +11 -0
- package/packing/deb/postinst +44 -0
- package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
- package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
- package/publish-task.sh +10 -0
- package/push-to-github.sh +105 -0
- package/ts-code/3nstorage/3nstorage-app.ts +99 -0
- package/ts-code/3nstorage/owner.ts +178 -0
- package/ts-code/3nstorage/resources/sessions.ts +37 -0
- package/ts-code/3nstorage/resources/store.ts +896 -0
- package/ts-code/3nstorage/resources/users.ts +258 -0
- package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +73 -0
- package/ts-code/3nstorage/routes/owner/cancel-trans.ts +58 -0
- package/ts-code/3nstorage/routes/owner/delete-obj.ts +103 -0
- package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +111 -0
- package/ts-code/3nstorage/routes/owner/get-current-obj.ts +122 -0
- package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
- package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
- package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
- package/ts-code/3nstorage/routes/owner/put-current-obj.ts +284 -0
- package/ts-code/3nstorage/routes/owner/session-params.ts +49 -0
- package/ts-code/3nstorage/shared.ts +43 -0
- package/ts-code/asmail/asmail-app.ts +91 -0
- package/ts-code/asmail/config.ts +96 -0
- package/ts-code/asmail/delivery.ts +94 -0
- package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
- package/ts-code/asmail/resources/inbox.ts +696 -0
- package/ts-code/asmail/resources/recipients.ts +495 -0
- package/ts-code/asmail/resources/sessions.ts +37 -0
- package/ts-code/asmail/retrieval.ts +96 -0
- package/ts-code/asmail/routes/config/param-getter.ts +49 -0
- package/ts-code/asmail/routes/config/param-setter.ts +49 -0
- package/ts-code/asmail/routes/delivery/finalize-delivery.ts +50 -0
- package/ts-code/asmail/routes/delivery/pre-flight.ts +132 -0
- package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
- package/ts-code/asmail/routes/delivery/put-metadata.ts +94 -0
- package/ts-code/asmail/routes/delivery/put-obj.ts +166 -0
- package/ts-code/asmail/routes/delivery/restart-session.ts +130 -0
- package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
- package/ts-code/asmail/routes/delivery/start-session.ts +151 -0
- package/ts-code/asmail/routes/retrieval/get-message-meta.ts +53 -0
- package/ts-code/asmail/routes/retrieval/get-message-obj.ts +109 -0
- package/ts-code/asmail/routes/retrieval/list-messages.ts +70 -0
- package/ts-code/asmail/routes/retrieval/remove-message.ts +47 -0
- package/ts-code/cli/index.ts +82 -0
- package/ts-code/cli/run-cmd.ts +81 -0
- package/ts-code/cli/show-sample-config.ts +78 -0
- package/ts-code/cli/signup-cmd.ts +229 -0
- package/ts-code/cli/user-cmd.ts +68 -0
- package/ts-code/cli/utils.ts +105 -0
- package/ts-code/config/default-confs.ts +22 -0
- package/ts-code/config/from-yaml.ts +35 -0
- package/ts-code/config/letsencrypt.ts +77 -0
- package/ts-code/config/signup.ts +137 -0
- package/ts-code/lib-common/admin-api/signup.ts +120 -0
- package/ts-code/lib-common/assert.ts +22 -0
- package/ts-code/lib-common/async-fs-node.ts +656 -0
- package/ts-code/lib-common/buffer-utils.ts +124 -0
- package/ts-code/lib-common/byte-streaming/common.ts +166 -0
- package/ts-code/lib-common/bytes-equal.ts +25 -0
- package/ts-code/lib-common/canonical-address.ts +92 -0
- package/ts-code/lib-common/exceptions/error.ts +44 -0
- package/ts-code/lib-common/exceptions/file.ts +84 -0
- package/ts-code/lib-common/exceptions/http.ts +69 -0
- package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
- package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
- package/ts-code/lib-common/json-equal.ts +55 -0
- package/ts-code/lib-common/json-utils.ts +130 -0
- package/ts-code/lib-common/jwkeys.ts +246 -0
- package/ts-code/lib-common/map-of-sets.ts +60 -0
- package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
- package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
- package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
- package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
- package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
- package/ts-code/lib-common/processes.ts +501 -0
- package/ts-code/lib-common/random-node.ts +79 -0
- package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
- package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
- package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
- package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
- package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
- package/ts-code/lib-common/service-api/locker.ts +44 -0
- package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
- package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
- package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
- package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
- package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
- package/ts-code/lib-common/session-encryptor.ts +54 -0
- package/ts-code/lib-common/time-window-cache.ts +74 -0
- package/ts-code/lib-common/transferable.d.ts +30 -0
- package/ts-code/lib-server/conf-util.ts +35 -0
- package/ts-code/lib-server/mid-access.ts +45 -0
- package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
- package/ts-code/lib-server/middleware/error-handler.ts +79 -0
- package/ts-code/lib-server/pkl-access.ts +46 -0
- package/ts-code/lib-server/resources/dns.ts +151 -0
- package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
- package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
- package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
- package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
- package/ts-code/lib-server/resources/sessions.ts +232 -0
- package/ts-code/lib-server/resources/user-files.ts +147 -0
- package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
- package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
- package/ts-code/lib-server/routes/sessions/close.ts +27 -0
- package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
- package/ts-code/lib-server/routes/sessions/start.ts +116 -0
- package/ts-code/lib-server/web-sockets/app.ts +339 -0
- package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
- package/ts-code/lib.ts +29 -0
- package/ts-code/locker/locker-app.ts +60 -0
- package/ts-code/locker/resources/lockers.ts +17 -0
- package/ts-code/locker/resources/sessions.ts +37 -0
- package/ts-code/locker/routes/create-locker.ts +47 -0
- package/ts-code/mailerId/mailerId-app.ts +107 -0
- package/ts-code/mailerId/resources/certifier.ts +181 -0
- package/ts-code/mailerId/resources/sessions.ts +44 -0
- package/ts-code/mailerId/resources/users.ts +88 -0
- package/ts-code/mailerId/routes/certify.ts +68 -0
- package/ts-code/main.ts +304 -0
- package/ts-code/mock/dns.ts +106 -0
- package/ts-code/mock/mock-as-child-proc.ts +130 -0
- package/ts-code/mock/node-child-ipc.ts +69 -0
- package/ts-code/mock/run-in-proc.ts +111 -0
- package/ts-code/mock/tls-options.ts +73 -0
- package/ts-code/services.ts +138 -0
- package/ts-code/signup/resources/users.ts +429 -0
- package/ts-code/signup/routes/add.ts +65 -0
- package/ts-code/signup/routes/get-available-addresses.ts +49 -0
- package/ts-code/signup/routes/get-available-domains.ts +45 -0
- package/ts-code/signup/signup-app.ts +54 -0
- package/ts-code/signup/signup-tokens.ts +148 -0
- package/ts-code/tests/admin-proto/signup.ts +277 -0
- package/ts-code/tests/jasmine.ts +37 -0
- package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
- package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
- package/ts-code/tests/libs-for-tests/assert.ts +22 -0
- package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
- package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
- package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
- package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
- package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
- package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
- package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
- package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
- package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
- package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
- package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
- package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
- package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
- package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
- package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
- package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
- package/ts-code/tests/protocols/asmail/config.ts +172 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
- package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
- package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
- package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
- package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
- package/ts-code/tests/protocols/mailerid.ts +271 -0
- package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
- package/ts-code/tests/shared-checks/requests.ts +135 -0
- package/ts-code/tsconfig.json +11 -0
- package/ts-code/web3n.d.ts +1068 -0
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2019 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { V1_FILE_START, layoutV1 } from "./v1-obj-file-format";
|
|
19
|
+
import { assert } from "../assert";
|
|
20
|
+
import { Layout, LayoutBaseSection, LayoutNewSection } from "xsp-files";
|
|
21
|
+
import { copy as copyJSON } from '../json-utils';
|
|
22
|
+
|
|
23
|
+
export interface HeaderChunkInfo {
|
|
24
|
+
len: number;
|
|
25
|
+
fileOfs: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type NotOnDiskFiniteChunk = NewSegsChunk | BaseSegsChunk;
|
|
29
|
+
|
|
30
|
+
export type OnDiskChunk = NewSegsChunkOnDisk | BaseSegsChunkOnDisk;
|
|
31
|
+
|
|
32
|
+
export type FiniteSegsChunk = OnDiskChunk | NotOnDiskFiniteChunk;
|
|
33
|
+
|
|
34
|
+
export type SegsChunk =
|
|
35
|
+
OnDiskChunk | NotOnDiskFiniteChunk | NewEndlessSegsChunk;
|
|
36
|
+
|
|
37
|
+
export interface FiniteChunk {
|
|
38
|
+
thisVerOfs: number;
|
|
39
|
+
len: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface BaseSegsChunk extends FiniteChunk {
|
|
43
|
+
type: 'base';
|
|
44
|
+
baseVerOfs: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface BaseSegsChunkOnDisk extends FiniteChunk {
|
|
48
|
+
type: 'base-on-disk';
|
|
49
|
+
baseVerOfs: number;
|
|
50
|
+
fileOfs: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface NewSegsChunk extends FiniteChunk {
|
|
54
|
+
type: 'new';
|
|
55
|
+
len: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface NewEndlessSegsChunk {
|
|
59
|
+
type: 'new-endless';
|
|
60
|
+
thisVerOfs: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface NewSegsChunkOnDisk extends FiniteChunk {
|
|
64
|
+
type: 'new-on-disk';
|
|
65
|
+
fileOfs: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface NewSegsChunk extends FiniteChunk {}
|
|
69
|
+
|
|
70
|
+
export class ObjVersionBytesLayout {
|
|
71
|
+
|
|
72
|
+
private headerChunk: HeaderChunkInfo|undefined = undefined;
|
|
73
|
+
private segsChunks: SegsChunk[] = [];
|
|
74
|
+
private baseVersion: number|undefined = undefined;
|
|
75
|
+
private segsLayoutFrozen = false;
|
|
76
|
+
|
|
77
|
+
private constructor(
|
|
78
|
+
private bytesEnd: number
|
|
79
|
+
) {
|
|
80
|
+
Object.seal(this);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static forNewFile(): ObjVersionBytesLayout {
|
|
84
|
+
return new ObjVersionBytesLayout(V1_FILE_START.length + 8);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static fromV1Bytes(layoutOfs: number, layoutBytes: Buffer):
|
|
88
|
+
ObjVersionBytesLayout {
|
|
89
|
+
const attrs = layoutV1.fromBytes(layoutBytes, 0);
|
|
90
|
+
const layout = new ObjVersionBytesLayout(layoutOfs);
|
|
91
|
+
layout.headerChunk = attrs.headerChunk;
|
|
92
|
+
layout.segsChunks = attrs.segsChunks;
|
|
93
|
+
if (attrs.baseVersion !== undefined) {
|
|
94
|
+
layout.baseVersion = attrs.baseVersion;
|
|
95
|
+
}
|
|
96
|
+
layout.segsLayoutFrozen = attrs.segsLayoutFrozen;
|
|
97
|
+
return layout;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
toBytes(): Buffer {
|
|
101
|
+
return layoutV1.toBytes({
|
|
102
|
+
segsLayoutFrozen: this.segsLayoutFrozen,
|
|
103
|
+
headerChunk: this.headerChunk,
|
|
104
|
+
segsChunks: this.segsChunks,
|
|
105
|
+
baseVersion: this.baseVersion,
|
|
106
|
+
allBaseBytesInFile: this.areAllBaseBytesInThisFile(),
|
|
107
|
+
sizeUnknown: this.isLayoutEndless(),
|
|
108
|
+
fileComplete: this.isFileComplete()
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getTotalSegsLen(): number {
|
|
113
|
+
if (this.segsChunks.length === 0) { return 0; }
|
|
114
|
+
let lastChunk = this.segsChunks[this.segsChunks.length-1];
|
|
115
|
+
if (lastChunk.type === 'new-endless') {
|
|
116
|
+
if (this.segsChunks.length === 1) { return 0; }
|
|
117
|
+
lastChunk = this.segsChunks[this.segsChunks.length-2];
|
|
118
|
+
if (lastChunk.type === 'new-endless') { throw new Error(
|
|
119
|
+
`Obj file layout has two endless segments`); }
|
|
120
|
+
}
|
|
121
|
+
return (lastChunk.thisVerOfs + lastChunk.len);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
isLayoutEndless(): boolean {
|
|
125
|
+
if (this.segsChunks.length === 0) { return false; }
|
|
126
|
+
const lastChunk = this.segsChunks[this.segsChunks.length-1];
|
|
127
|
+
return (lastChunk.type === 'new-endless');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
isLayoutFrozen(): boolean {
|
|
131
|
+
return this.segsLayoutFrozen;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
isFileComplete(): boolean {
|
|
135
|
+
return !this.segsChunks.find(
|
|
136
|
+
chunk => ((chunk.type === 'new') || (chunk.type === 'new-endless')));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getLayoutOfs(): number {
|
|
140
|
+
return this.bytesEnd;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
headerLocation(): HeaderChunkInfo|undefined {
|
|
144
|
+
return this.headerChunk;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
segsLocations(thisVerOfs: number, len: number): FiniteSegsChunk[] {
|
|
148
|
+
assert(Number.isInteger(thisVerOfs) && (thisVerOfs >= 0));
|
|
149
|
+
assert(Number.isInteger(len) && (len >= 0));
|
|
150
|
+
const segInfos: FiniteSegsChunk[] = [];
|
|
151
|
+
const end = thisVerOfs + len;
|
|
152
|
+
for (let i=0; (i<this.segsChunks.length)&&(len>0); i+=1) {
|
|
153
|
+
const chunk = this.segsChunks[i];
|
|
154
|
+
const chunkEnd = chunk.thisVerOfs + ((chunk.type === 'new-endless') ?
|
|
155
|
+
Number.MAX_SAFE_INTEGER : chunk.len);
|
|
156
|
+
if (chunkEnd <= thisVerOfs) { continue; }
|
|
157
|
+
if (end <= chunk.thisVerOfs) { break; }
|
|
158
|
+
if (thisVerOfs < chunk.thisVerOfs) {
|
|
159
|
+
if (this.segsLayoutFrozen) { throw new Error(
|
|
160
|
+
`File contains a hole, while segs layout is frozen`); }
|
|
161
|
+
const chop: NewSegsChunk = {
|
|
162
|
+
type: 'new',
|
|
163
|
+
thisVerOfs,
|
|
164
|
+
len: chunk.thisVerOfs - thisVerOfs
|
|
165
|
+
};
|
|
166
|
+
segInfos.push(chop);
|
|
167
|
+
thisVerOfs += chop.len;
|
|
168
|
+
len -= chop.len;
|
|
169
|
+
} else {
|
|
170
|
+
const chop = copyJSON(chunk) as FiniteSegsChunk;
|
|
171
|
+
chop.thisVerOfs = thisVerOfs;
|
|
172
|
+
if (chunk.type === 'new-endless') {
|
|
173
|
+
chop.type = 'new';
|
|
174
|
+
chop.len = end - chop.thisVerOfs;
|
|
175
|
+
} else {
|
|
176
|
+
chop.len = Math.min(end, chunkEnd) - chop.thisVerOfs;
|
|
177
|
+
}
|
|
178
|
+
const chopOfs = thisVerOfs - chunk.thisVerOfs;
|
|
179
|
+
if ((chop.type === 'base') || (chop.type == 'base-on-disk')) {
|
|
180
|
+
chop.baseVerOfs = (chunk as typeof chop).baseVerOfs + chopOfs;
|
|
181
|
+
}
|
|
182
|
+
if ((chop.type === 'new-on-disk')
|
|
183
|
+
|| (chop.type == 'base-on-disk')) {
|
|
184
|
+
chop.fileOfs = (chunk as typeof chop).fileOfs + chopOfs;
|
|
185
|
+
}
|
|
186
|
+
segInfos.push(chop);
|
|
187
|
+
thisVerOfs += chop.len;
|
|
188
|
+
len -= chop.len;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if ((len > 0) && !this.segsLayoutFrozen) {
|
|
192
|
+
segInfos.push({ type: 'new', thisVerOfs, len });
|
|
193
|
+
}
|
|
194
|
+
return segInfos;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private areAllBaseBytesInThisFile(): boolean {
|
|
198
|
+
if (this.baseVersion === undefined) { return false; }
|
|
199
|
+
for (const chunk of this.segsChunks) {
|
|
200
|
+
if (chunk.type === 'base') { return false; }
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
setAndFreezeWith(layout: Layout): void {
|
|
206
|
+
if (this.segsLayoutFrozen) { throw new Error(
|
|
207
|
+
`Obj segments layout is frozen, and can't be set to new value`); }
|
|
208
|
+
this.segsChunks = combineChunksOnDiskWithLayout(
|
|
209
|
+
layoutSectionsToSegsChunks(layout.sections), this.segsChunks);
|
|
210
|
+
ensureNoHolesIn(this.segsChunks);
|
|
211
|
+
this.baseVersion = layout.base;
|
|
212
|
+
this.segsLayoutFrozen = true;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
truncateIfEndless(): void {
|
|
216
|
+
if (!this.isLayoutEndless()) { return; }
|
|
217
|
+
this.segsChunks.pop();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private ensureExpectedFileOfs(fileOfs: number): void {
|
|
221
|
+
if (fileOfs !== this.bytesEnd) { throw new Error(
|
|
222
|
+
`Given file offset ${fileOfs} does not equal expected value ${this.bytesEnd}`); }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
addHeader(len: number, fileOfs: number): void {
|
|
226
|
+
this.ensureExpectedFileOfs(fileOfs);
|
|
227
|
+
assert(Number.isInteger(len) && (len >= 0));
|
|
228
|
+
if (this.headerChunk) { throw new Error(
|
|
229
|
+
`Header added second time to obj version bytes layout`); }
|
|
230
|
+
this.headerChunk = { len, fileOfs };
|
|
231
|
+
Object.freeze(this.headerChunk); // we share it, so better in frozen form
|
|
232
|
+
this.bytesEnd += len;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
addSegsOnFile(thisVerOfs: number, len: number, fileOfs: number): void {
|
|
236
|
+
this.ensureExpectedFileOfs(fileOfs);
|
|
237
|
+
assert(Number.isInteger(thisVerOfs) && (thisVerOfs >= 0));
|
|
238
|
+
assert(Number.isInteger(len) && (len >= 0));
|
|
239
|
+
const s: NewSegsChunkOnDisk = {
|
|
240
|
+
type: 'new-on-disk', thisVerOfs, len, fileOfs };
|
|
241
|
+
addNewSegsChunkTo(this.segsChunks, s);
|
|
242
|
+
this.bytesEnd += len;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
addBaseSegsOnFile(thisVerOfs: number, baseVerOfs: number, len: number,
|
|
246
|
+
fileOfs: number): void {
|
|
247
|
+
this.ensureExpectedFileOfs(fileOfs);
|
|
248
|
+
assert(Number.isInteger(thisVerOfs) && (thisVerOfs >= 0));
|
|
249
|
+
assert(Number.isInteger(baseVerOfs) && (baseVerOfs >= 0));
|
|
250
|
+
assert(Number.isInteger(len) && (len >= 0));
|
|
251
|
+
const s: BaseSegsChunkOnDisk = {
|
|
252
|
+
type: 'base-on-disk', thisVerOfs, baseVerOfs, len, fileOfs };
|
|
253
|
+
addBaseSegsChunkTo(this.segsChunks, s);
|
|
254
|
+
this.bytesEnd += len;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
getBaseVersion(): number|undefined {
|
|
258
|
+
return this.baseVersion;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
Object.freeze(ObjVersionBytesLayout.prototype);
|
|
263
|
+
Object.freeze(ObjVersionBytesLayout);
|
|
264
|
+
|
|
265
|
+
function layoutSectionsToSegsChunks(sections: Layout['sections']):
|
|
266
|
+
SegsChunk[] {
|
|
267
|
+
let expectedThisVerOfs = 0;
|
|
268
|
+
const chunks: SegsChunk[] = [];
|
|
269
|
+
for (const section of sections) {
|
|
270
|
+
if (section.ofs !== expectedThisVerOfs) { throw new Error(
|
|
271
|
+
`Layout section has offset ${section.ofs}, while expected value is ${expectedThisVerOfs}`); }
|
|
272
|
+
const chunk = layoutSectionToSegsChunk(section);
|
|
273
|
+
if (chunk.type === 'new-endless') {
|
|
274
|
+
assert(sections[sections.length-1] === section,
|
|
275
|
+
`Infinite layout section must be the last section`);
|
|
276
|
+
} else {
|
|
277
|
+
chunks.push(chunk);
|
|
278
|
+
expectedThisVerOfs += chunk.len;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return chunks;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function layoutSectionToSegsChunk(section: LayoutBaseSection|LayoutNewSection):
|
|
285
|
+
SegsChunk {
|
|
286
|
+
if (section.src === 'base') {
|
|
287
|
+
return {
|
|
288
|
+
type: 'base',
|
|
289
|
+
thisVerOfs: section.ofs,
|
|
290
|
+
len: section.len,
|
|
291
|
+
baseVerOfs: section.baseOfs
|
|
292
|
+
};
|
|
293
|
+
} else if (section.src === 'new') {
|
|
294
|
+
if (section.len === undefined){
|
|
295
|
+
return {
|
|
296
|
+
type: 'new-endless',
|
|
297
|
+
thisVerOfs: section.ofs,
|
|
298
|
+
};
|
|
299
|
+
} else {
|
|
300
|
+
return {
|
|
301
|
+
type: 'new',
|
|
302
|
+
thisVerOfs: section.ofs,
|
|
303
|
+
len: section.len
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
throw new Error(`Layout section has unknown src`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function combineChunksOnDiskWithLayout(
|
|
312
|
+
layout: SegsChunk[], chunks: SegsChunk[]): SegsChunk[] {
|
|
313
|
+
for (const chunk of chunks) {
|
|
314
|
+
if (chunk.type === 'new-on-disk') {
|
|
315
|
+
addNewSegsChunkTo(layout, chunk);
|
|
316
|
+
} else if (chunk.type === 'base-on-disk') {
|
|
317
|
+
addBaseSegsChunkTo(layout, chunk);
|
|
318
|
+
} else {
|
|
319
|
+
throw new Error(`Have chunk type ${chunk.type} before layout is set`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return layout;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function addNewSegsChunkTo(segsChunks: SegsChunk[],
|
|
326
|
+
newChunk: NewSegsChunkOnDisk): void {
|
|
327
|
+
const newChunkEnd = newChunk.thisVerOfs + newChunk.len;
|
|
328
|
+
// find insertion index
|
|
329
|
+
let insertInd = 0;
|
|
330
|
+
for (let i=(segsChunks.length-1); i>=0; i-=1) {
|
|
331
|
+
const chunk = segsChunks[i];
|
|
332
|
+
if (newChunkEnd <= chunk.thisVerOfs) { continue; }
|
|
333
|
+
if (chunk.type !== 'new-endless') {
|
|
334
|
+
const chunkEnd = chunk.thisVerOfs + chunk.len;
|
|
335
|
+
if (chunkEnd <= newChunk.thisVerOfs) {
|
|
336
|
+
insertInd = i+1;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// here chunks overlap
|
|
341
|
+
if ((chunk.type !== 'new')
|
|
342
|
+
&& (chunk.type !== 'new-endless')) { throw new Error(
|
|
343
|
+
`Have a non-merging overlap of new section ${JSON.stringify(newChunk)}, and an existing one ${JSON.stringify(chunk)}`); }
|
|
344
|
+
// cut and insert left non-overlapping side of chunk
|
|
345
|
+
if (chunk.thisVerOfs < newChunk.thisVerOfs) {
|
|
346
|
+
const leftSide: NewSegsChunk = {
|
|
347
|
+
type: 'new',
|
|
348
|
+
thisVerOfs: chunk.thisVerOfs,
|
|
349
|
+
len: newChunk.thisVerOfs - chunk.thisVerOfs
|
|
350
|
+
};
|
|
351
|
+
segsChunks.splice(i, 0, leftSide);
|
|
352
|
+
i += 1;
|
|
353
|
+
}
|
|
354
|
+
// cut and insert right non-overlapping side of chunk
|
|
355
|
+
if (chunk.type === 'new') {
|
|
356
|
+
const chunkEnd = chunk.thisVerOfs + chunk.len;
|
|
357
|
+
if (newChunkEnd < chunkEnd) {
|
|
358
|
+
const rightSide: NewSegsChunk = {
|
|
359
|
+
type: 'new',
|
|
360
|
+
thisVerOfs: newChunkEnd,
|
|
361
|
+
len: chunkEnd - newChunkEnd
|
|
362
|
+
};
|
|
363
|
+
segsChunks.splice(i+1, 0, rightSide);
|
|
364
|
+
}
|
|
365
|
+
} else if (chunk.type === 'new-endless') {
|
|
366
|
+
const rightSide: NewEndlessSegsChunk = {
|
|
367
|
+
type: 'new-endless',
|
|
368
|
+
thisVerOfs: newChunkEnd
|
|
369
|
+
};
|
|
370
|
+
segsChunks.splice(i+1, 0, rightSide);
|
|
371
|
+
}
|
|
372
|
+
// cut chunk, and insert newChunk in following common logic,
|
|
373
|
+
// cause it checks for possible merges
|
|
374
|
+
segsChunks.splice(i, 1);
|
|
375
|
+
insertInd = i;
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
insertOrMergeChunkAt(segsChunks, insertInd, newChunk);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function insertOrMergeChunkAt(segsChunks: SegsChunk[], insertInd: number,
|
|
382
|
+
chunk: OnDiskChunk): void {
|
|
383
|
+
let left = ((insertInd > 0) ? segsChunks[insertInd-1] : undefined);
|
|
384
|
+
let right = ((insertInd < segsChunks.length) ?
|
|
385
|
+
segsChunks[insertInd] : undefined);
|
|
386
|
+
if (left && canMergeChunks(left, chunk)) {
|
|
387
|
+
(left as OnDiskChunk).len += chunk.len;
|
|
388
|
+
if (right && canMergeChunks(left, right)) {
|
|
389
|
+
(left as OnDiskChunk).len += (right as OnDiskChunk).len;
|
|
390
|
+
segsChunks.splice(insertInd, 1);
|
|
391
|
+
}
|
|
392
|
+
} else if (right && canMergeChunks(chunk, right)) {
|
|
393
|
+
chunk.len += (right as OnDiskChunk).len;
|
|
394
|
+
segsChunks[insertInd] = chunk;
|
|
395
|
+
} else {
|
|
396
|
+
segsChunks.splice(insertInd, 0, chunk);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function canMergeChunks(a: SegsChunk, b: SegsChunk): boolean {
|
|
401
|
+
if (a.type !== b.type) { return false; }
|
|
402
|
+
if (a.type === 'new-endless') { throw new Error(
|
|
403
|
+
`Attepmt to place segs chunk after an endless chunk`); }
|
|
404
|
+
if ((a.thisVerOfs + a.len) !== b.thisVerOfs) { return false; }
|
|
405
|
+
if ((a.type === 'new-on-disk') || (a.type === 'base-on-disk')) {
|
|
406
|
+
if ((a.fileOfs + a.len) !== (b as OnDiskChunk).fileOfs) { return false; }
|
|
407
|
+
}
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function addBaseSegsChunkTo(segsChunks: SegsChunk[],
|
|
412
|
+
baseChunk: BaseSegsChunkOnDisk): void {
|
|
413
|
+
const baseChunkEnd = baseChunk.thisVerOfs + baseChunk.len;
|
|
414
|
+
// find insertion index
|
|
415
|
+
let insertInd = 0;
|
|
416
|
+
for (let i=(segsChunks.length-1); i>=0; i-=1) {
|
|
417
|
+
const chunk = segsChunks[i];
|
|
418
|
+
if (baseChunkEnd <= chunk.thisVerOfs) { continue; }
|
|
419
|
+
if (chunk.type !== 'new-endless') {
|
|
420
|
+
const chunkEnd = chunk.thisVerOfs + chunk.len;
|
|
421
|
+
if (chunkEnd <= baseChunk.thisVerOfs) {
|
|
422
|
+
insertInd = i+1;
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
// here chunks overlap
|
|
427
|
+
if (chunk.type !== 'base') { throw new Error(
|
|
428
|
+
`Have a non-merging overlap of new section ${JSON.stringify(baseChunk)}, and an existing one ${JSON.stringify(chunk)}`); }
|
|
429
|
+
// cut and insert left non-overlapping side of chunk
|
|
430
|
+
if (chunk.thisVerOfs < baseChunk.thisVerOfs) {
|
|
431
|
+
const leftSide: BaseSegsChunk = {
|
|
432
|
+
type: 'base',
|
|
433
|
+
thisVerOfs: chunk.thisVerOfs,
|
|
434
|
+
baseVerOfs: chunk.baseVerOfs,
|
|
435
|
+
len: baseChunk.thisVerOfs - chunk.thisVerOfs
|
|
436
|
+
};
|
|
437
|
+
segsChunks.splice(i, 0, leftSide);
|
|
438
|
+
i += 1;
|
|
439
|
+
}
|
|
440
|
+
// cut and insert right non-overlapping side of chunk
|
|
441
|
+
const chunkEnd = chunk.thisVerOfs + chunk.len;
|
|
442
|
+
if (baseChunkEnd < chunkEnd) {
|
|
443
|
+
const rightSide: BaseSegsChunk = {
|
|
444
|
+
type: 'base',
|
|
445
|
+
thisVerOfs: baseChunkEnd,
|
|
446
|
+
baseVerOfs: baseChunk.baseVerOfs + baseChunk.len,
|
|
447
|
+
len: chunkEnd - baseChunkEnd
|
|
448
|
+
};
|
|
449
|
+
segsChunks.splice(i+1, 0, rightSide);
|
|
450
|
+
}
|
|
451
|
+
// cut chunk, and insert newChunk in following common logic,
|
|
452
|
+
// cause it checks for possible merges
|
|
453
|
+
segsChunks.splice(i, 1);
|
|
454
|
+
insertInd = 1;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
insertOrMergeChunkAt(segsChunks, insertInd, baseChunk);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function ensureNoHolesIn(segsChunks: SegsChunk[]): void {
|
|
461
|
+
let thisVerOfs = 0;
|
|
462
|
+
for (let i=0; i<segsChunks.length; i+=1) {
|
|
463
|
+
const chunk = segsChunks[i];
|
|
464
|
+
if (chunk.thisVerOfs === thisVerOfs) {
|
|
465
|
+
if (chunk.type === 'new-endless') {
|
|
466
|
+
if (chunk !== segsChunks[segsChunks.length-1]) {
|
|
467
|
+
throw new Error(`Endless segs chunk is at index ${i} in ${segsChunks.length} chunks chain`);
|
|
468
|
+
}
|
|
469
|
+
} else {
|
|
470
|
+
thisVerOfs += chunk.len;
|
|
471
|
+
}
|
|
472
|
+
} else if (chunk.thisVerOfs > thisVerOfs) {
|
|
473
|
+
throw new Error(`There is a hole in segs chunks from position ${thisVerOfs} to start of chunk ${i} with position ${chunk.thisVerOfs}`);
|
|
474
|
+
} else {
|
|
475
|
+
throw new Error(`Segs chunk ${i} has offset ${chunk.thisVerOfs} that is smaller than expected ${thisVerOfs}`);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
Object.freeze(exports);
|