@goodpeanuts/dsh-sui 0.0.0-stage → 0.1.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/README.md +100 -3
- package/THIRD_PARTY_NOTICES.txt +1064 -0
- package/apps/cli/dist/_virtual/_rolldown/runtime.mjs +35 -0
- package/apps/cli/dist/args.mjs +204 -0
- package/apps/cli/dist/cli.mjs +392 -0
- package/apps/cli/dist/errors.mjs +32 -0
- package/apps/cli/dist/help.mjs +73 -0
- package/apps/cli/dist/io.mjs +37 -0
- package/apps/cli/dist/main.mjs +10 -0
- package/apps/cli/dist/node_modules/.pnpm/@keyv_serialize@1.1.1/node_modules/@keyv/serialize/dist/index.mjs +37 -0
- package/apps/cli/dist/node_modules/.pnpm/@sec-ant_readable-stream@0.4.1/node_modules/@sec-ant/readable-stream/dist/ponyfill/asyncIterator.mjs +81 -0
- package/apps/cli/dist/node_modules/.pnpm/@sec-ant_readable-stream@0.4.1/node_modules/@sec-ant/readable-stream/dist/ponyfill/index.mjs +1 -0
- package/apps/cli/dist/node_modules/.pnpm/@sindresorhus_is@7.2.0/node_modules/@sindresorhus/is/distribution/index.mjs +1015 -0
- package/apps/cli/dist/node_modules/.pnpm/@sindresorhus_is@7.2.0/node_modules/@sindresorhus/is/distribution/utilities.mjs +6 -0
- package/apps/cli/dist/node_modules/.pnpm/boolbase@1.0.0/node_modules/boolbase/index.mjs +15 -0
- package/apps/cli/dist/node_modules/.pnpm/byte-counter@0.1.0/node_modules/byte-counter/utilities.mjs +9 -0
- package/apps/cli/dist/node_modules/.pnpm/cacheable-lookup@7.0.0/node_modules/cacheable-lookup/source/index.mjs +279 -0
- package/apps/cli/dist/node_modules/.pnpm/cacheable-request@13.0.19/node_modules/cacheable-request/dist/index.mjs +274 -0
- package/apps/cli/dist/node_modules/.pnpm/cacheable-request@13.0.19/node_modules/cacheable-request/dist/types.mjs +15 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio-select@2.1.0/node_modules/cheerio-select/lib/esm/helpers.mjs +15 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio-select@2.1.0/node_modules/cheerio-select/lib/esm/index.mjs +159 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio-select@2.1.0/node_modules/cheerio-select/lib/esm/positionals.mjs +33 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/attributes.mjs +465 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/css.mjs +94 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/extract.mjs +39 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/forms.mjs +63 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/manipulation.mjs +731 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/traversing.mjs +828 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/cheerio.mjs +53 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/index.mjs +11 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/load-parse.mjs +25 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/load.mjs +73 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/options.mjs +27 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/parse.mjs +53 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/parsers/parse5-adapter.mjs +42 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/static.mjs +165 -0
- package/apps/cli/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/utils.mjs +78 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/attributes.mjs +187 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/compile.mjs +77 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/general.mjs +89 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/index.mjs +43 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/aliases.mjs +32 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/filters.mjs +114 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/index.mjs +35 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/pseudos.mjs +53 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/subselects.mjs +68 -0
- package/apps/cli/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/sort.mjs +60 -0
- package/apps/cli/dist/node_modules/.pnpm/css-what@6.2.2/node_modules/css-what/lib/commonjs/index.mjs +50 -0
- package/apps/cli/dist/node_modules/.pnpm/css-what@6.2.2/node_modules/css-what/lib/commonjs/parse.mjs +320 -0
- package/apps/cli/dist/node_modules/.pnpm/css-what@6.2.2/node_modules/css-what/lib/commonjs/stringify.mjs +102 -0
- package/apps/cli/dist/node_modules/.pnpm/css-what@6.2.2/node_modules/css-what/lib/commonjs/types.mjs +45 -0
- package/apps/cli/dist/node_modules/.pnpm/decompress-response@10.0.0/node_modules/decompress-response/index.mjs +59 -0
- package/apps/cli/dist/node_modules/.pnpm/dom-serializer@2.0.0/node_modules/dom-serializer/lib/esm/foreignNames.mjs +103 -0
- package/apps/cli/dist/node_modules/.pnpm/dom-serializer@2.0.0/node_modules/dom-serializer/lib/esm/index.mjs +144 -0
- package/apps/cli/dist/node_modules/.pnpm/domelementtype@2.3.0/node_modules/domelementtype/lib/esm/index.mjs +51 -0
- package/apps/cli/dist/node_modules/.pnpm/domhandler@5.0.3/node_modules/domhandler/lib/esm/index.mjs +128 -0
- package/apps/cli/dist/node_modules/.pnpm/domhandler@5.0.3/node_modules/domhandler/lib/esm/node.mjs +312 -0
- package/apps/cli/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/feeds.mjs +161 -0
- package/apps/cli/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/helpers.mjs +113 -0
- package/apps/cli/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/index.mjs +56 -0
- package/apps/cli/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/legacy.mjs +141 -0
- package/apps/cli/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/manipulation.mjs +117 -0
- package/apps/cli/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/querying.mjs +124 -0
- package/apps/cli/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/stringify.mjs +69 -0
- package/apps/cli/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/traversal.mjs +109 -0
- package/apps/cli/dist/node_modules/.pnpm/encoding-sniffer@0.2.1/node_modules/encoding-sniffer/dist/esm/index.mjs +7 -0
- package/apps/cli/dist/node_modules/.pnpm/encoding-sniffer@0.2.1/node_modules/encoding-sniffer/dist/esm/sniffer.mjs +112 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/escape.mjs +83 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@6.0.1/node_modules/entities/dist/esm/decode-codepoint.mjs +43 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@6.0.1/node_modules/entities/dist/esm/decode.mjs +330 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@6.0.1/node_modules/entities/dist/esm/escape.mjs +49 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@6.0.1/node_modules/entities/dist/esm/generated/decode-data-html.mjs +4 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/decode-codepoint.mjs +57 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/decode.mjs +351 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/generated/decode-data-html.mjs +5 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/generated/decode-data-xml.mjs +5 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/internal/bin-trie-flags.mjs +20 -0
- package/apps/cli/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/internal/decode-shared.mjs +14 -0
- package/apps/cli/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/index.mjs +871 -0
- package/apps/cli/dist/node_modules/.pnpm/form-data-encoder@4.1.0/node_modules/form-data-encoder/lib/index.mjs +279 -0
- package/apps/cli/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/array-buffer.mjs +54 -0
- package/apps/cli/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/buffer.mjs +14 -0
- package/apps/cli/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/contents.mjs +80 -0
- package/apps/cli/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/stream.mjs +41 -0
- package/apps/cli/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/utils.mjs +8 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/as-promise/index.mjs +154 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/as-promise/types.mjs +20 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/calculate-retry-delay.mjs +20 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/diagnostics-channel.mjs +38 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/errors.mjs +132 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/index.mjs +923 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/options.mjs +1622 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/parse-link-header.mjs +27 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/response.mjs +36 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/timed-out.mjs +107 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/defer-to-connect.mjs +28 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/get-body-size.mjs +23 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/is-client-request.mjs +6 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/is-form-data.mjs +7 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/is-unix-socket-url.mjs +25 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/proxy-events.mjs +16 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/timer.mjs +114 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/unhandle.mjs +23 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/url-to-options.mjs +20 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/weakable-map.mjs +19 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/create.mjs +166 -0
- package/apps/cli/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/index.mjs +17 -0
- package/apps/cli/dist/node_modules/.pnpm/htmlparser2@10.1.0/node_modules/htmlparser2/dist/esm/Parser.mjs +441 -0
- package/apps/cli/dist/node_modules/.pnpm/htmlparser2@10.1.0/node_modules/htmlparser2/dist/esm/Tokenizer.mjs +661 -0
- package/apps/cli/dist/node_modules/.pnpm/htmlparser2@10.1.0/node_modules/htmlparser2/dist/esm/index.mjs +19 -0
- package/apps/cli/dist/node_modules/.pnpm/http-cache-semantics@4.3.0/node_modules/http-cache-semantics/index.mjs +608 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/agent.mjs +441 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/auto.mjs +145 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/client-request.mjs +318 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/incoming-message.mjs +58 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/index.mjs +51 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/get-auth-headers.mjs +19 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/h1-over-h2.mjs +84 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/h2-over-h1.mjs +49 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/h2-over-h2.mjs +38 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/h2-over-hx.mjs +39 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/initialize.mjs +23 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/unexpected-status-code-error.mjs +15 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/calculate-server-name.mjs +24 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/check-type.mjs +17 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/delay-async-destroy.mjs +28 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/errors.mjs +30 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/is-request-pseudo-header.mjs +16 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/js-stream-socket.mjs +9 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/proxy-events.mjs +10 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/proxy-socket-handler.mjs +77 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/validate-header-name.mjs +15 -0
- package/apps/cli/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/validate-header-value.mjs +14 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/dbcs-codec.mjs +355 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/dbcs-data.mjs +191 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/index.mjs +31 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/internal.mjs +140 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/sbcs-codec.mjs +50 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/sbcs-data-generated.mjs +455 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/sbcs-data.mjs +151 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/big5-added.mjs +169 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/cp936.mjs +2584 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/cp949.mjs +2220 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/cp950.mjs +227 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/eucjp.mjs +425 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/gb18030-ranges.mjs +427 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/gbk-added.mjs +230 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/shiftjis.mjs +292 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/utf16.mjs +123 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/utf32.mjs +197 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/utf7.mjs +182 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/bom-handling.mjs +42 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/index.mjs +108 -0
- package/apps/cli/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/streams.mjs +90 -0
- package/apps/cli/dist/node_modules/.pnpm/is-stream@4.0.1/node_modules/is-stream/index.mjs +9 -0
- package/apps/cli/dist/node_modules/.pnpm/js-sha256@0.11.1/node_modules/js-sha256/src/sha256.mjs +495 -0
- package/apps/cli/dist/node_modules/.pnpm/keyv@5.6.0/node_modules/keyv/dist/index.mjs +740 -0
- package/apps/cli/dist/node_modules/.pnpm/lowercase-keys@3.0.0/node_modules/lowercase-keys/index.mjs +6 -0
- package/apps/cli/dist/node_modules/.pnpm/mimic-response@4.0.0/node_modules/mimic-response/index.mjs +53 -0
- package/apps/cli/dist/node_modules/.pnpm/normalize-url@8.1.1/node_modules/normalize-url/index.mjs +145 -0
- package/apps/cli/dist/node_modules/.pnpm/nth-check@2.1.1/node_modules/nth-check/lib/esm/compile.mjs +37 -0
- package/apps/cli/dist/node_modules/.pnpm/nth-check@2.1.1/node_modules/nth-check/lib/esm/index.mjs +31 -0
- package/apps/cli/dist/node_modules/.pnpm/nth-check@2.1.1/node_modules/nth-check/lib/esm/parse.mjs +60 -0
- package/apps/cli/dist/node_modules/.pnpm/p-cancelable@4.0.1/node_modules/p-cancelable/index.mjs +86 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5-htmlparser2-tree-adapter@7.1.0/node_modules/parse5-htmlparser2-tree-adapter/dist/index.mjs +187 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5-parser-stream@7.1.2/node_modules/parse5-parser-stream/dist/index.mjs +2 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/doctype.mjs +101 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/error-codes.mjs +66 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/foreign-content.mjs +259 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/html.mjs +544 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/token.mjs +19 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/unicode.mjs +91 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/index.mjs +41 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/parser/formatting-element-list.mjs +91 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/parser/index.mjs +2492 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/parser/open-element-stack.mjs +292 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/serializer/index.mjs +111 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/tokenizer/index.mjs +2067 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/tokenizer/preprocessor.mjs +154 -0
- package/apps/cli/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/tree-adapters/default.mjs +164 -0
- package/apps/cli/dist/node_modules/.pnpm/quick-lru@5.1.1/node_modules/quick-lru/index.mjs +77 -0
- package/apps/cli/dist/node_modules/.pnpm/resolve-alpn@1.2.1/node_modules/resolve-alpn/index.mjs +47 -0
- package/apps/cli/dist/node_modules/.pnpm/responselike@4.0.2/node_modules/responselike/index.mjs +32 -0
- package/apps/cli/dist/node_modules/.pnpm/safer-buffer@2.1.2/node_modules/safer-buffer/safer.mjs +45 -0
- package/apps/cli/dist/node_modules/.pnpm/tldts@7.4.18/node_modules/tldts/dist/cjs/index.mjs +22542 -0
- package/apps/cli/dist/node_modules/.pnpm/tough-cookie@6.0.0/node_modules/tough-cookie/dist/index.mjs +1761 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/index.mjs +221 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/abort-signal.mjs +44 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-connect.mjs +85 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-pipeline.mjs +174 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-request.mjs +155 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-stream.mjs +136 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-upgrade.mjs +88 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/index.mjs +17 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/readable.mjs +418 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/cache/memory-cache-store.mjs +190 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/cache/sqlite-cache-store.mjs +324 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/connect.mjs +115 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/constants.mjs +134 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/diagnostics.mjs +114 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/errors.mjs +412 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/request.mjs +282 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/socks5-client.mjs +288 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/socks5-utils.mjs +166 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/symbols.mjs +80 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/tree.mjs +124 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/util.mjs +940 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/agent.mjs +119 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/balanced-pool.mjs +129 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/client-h1.mjs +1091 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/client-h2.mjs +588 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/client.mjs +385 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/dispatcher-base.mjs +121 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/dispatcher.mjs +35 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/env-http-proxy-agent.mjs +105 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/fixed-queue.mjs +75 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/h2c-client.mjs +31 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/pool-base.mjs +155 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/pool.mjs +76 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/proxy-agent.mjs +233 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/retry-agent.mjs +37 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/round-robin-pool.mjs +94 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/socks5-proxy-agent.mjs +194 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/encoding/index.mjs +18 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/global.mjs +48 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/cache-handler.mjs +457 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/cache-revalidation-handler.mjs +82 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/decorator-handler.mjs +57 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/deduplication-handler.mjs +341 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/redirect-handler.mjs +131 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/retry-handler.mjs +332 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/unwrap-handler.mjs +88 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/wrap-handler.mjs +68 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/cache.mjs +350 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/decompress.mjs +416 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/deduplicate.mjs +69 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/dns.mjs +323 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/dump.mjs +65 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/redirect.mjs +20 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/response-error.mjs +73 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/retry.mjs +25 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/llhttp/constants.mjs +590 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/llhttp/llhttp-wasm.mjs +13 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/llhttp/llhttp_simd-wasm.mjs +13 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/llhttp/utils.mjs +16 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-agent.mjs +154 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-call-history.mjs +159 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-client.mjs +59 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-errors.mjs +28 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-interceptor.mjs +150 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-pool.mjs +59 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-symbols.mjs +37 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-utils.mjs +302 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/pending-interceptors-formatter.mjs +38 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/snapshot-agent.mjs +268 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/snapshot-recorder.mjs +424 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/snapshot-utils.mjs +121 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/cache.mjs +440 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/date.mjs +332 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/promise.mjs +31 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/runtime-features.mjs +101 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/stats.mjs +31 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/timers.mjs +341 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cache/cache.mjs +462 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cache/cachestorage.mjs +103 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cache/util.mjs +39 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cookies/constants.mjs +11 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cookies/index.mjs +169 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cookies/parse.mjs +108 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cookies/util.mjs +239 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/eventsource/eventsource-stream.mjs +317 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/eventsource/eventsource.mjs +345 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/eventsource/util.mjs +29 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/body.mjs +271 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/constants.mjs +224 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/data-url.mjs +247 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/formdata-parser.mjs +255 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/formdata.mjs +153 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/global.mjs +34 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/headers.mjs +400 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/index.mjs +776 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/request.mjs +602 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/response.mjs +358 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/util.mjs +795 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/infra/index.mjs +154 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.mjs +170 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/webidl/index.mjs +505 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/connection.mjs +166 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/constants.mjs +47 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/events.mjs +268 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/frame.mjs +105 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/permessage-deflate.mjs +85 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/receiver.mjs +323 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/sender.mjs +90 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/stream/websocketerror.mjs +78 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/stream/websocketstream.mjs +270 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/util.mjs +212 -0
- package/apps/cli/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/websocket.mjs +432 -0
- package/apps/cli/dist/node_modules/.pnpm/whatwg-encoding@3.1.1/node_modules/whatwg-encoding/lib/labels-to-names.mjs +224 -0
- package/apps/cli/dist/node_modules/.pnpm/whatwg-encoding@3.1.1/node_modules/whatwg-encoding/lib/supported-names.mjs +45 -0
- package/apps/cli/dist/node_modules/.pnpm/whatwg-encoding@3.1.1/node_modules/whatwg-encoding/lib/whatwg-encoding.mjs +40 -0
- package/apps/cli/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/mime-type-parameters.mjs +54 -0
- package/apps/cli/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/mime-type.mjs +92 -0
- package/apps/cli/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/parser.mjs +62 -0
- package/apps/cli/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/serializer.mjs +24 -0
- package/apps/cli/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/utils.mjs +47 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.mjs +26 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/iso.mjs +35 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/parse.mjs +17 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/schemas.mjs +800 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/api.mjs +508 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/checks.mjs +366 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.mjs +60 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/doc.mjs +32 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.mjs +63 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.mjs +253 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/parse.mjs +118 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/regexes.mjs +65 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/registries.mjs +48 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/schemas.mjs +1235 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.mjs +297 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.mjs +316 -0
- package/apps/cli/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/versions.mjs +8 -0
- package/apps/cli/dist/packages/data-maintenance/src/archive.mjs +143 -0
- package/apps/cli/dist/packages/data-maintenance/src/contracts.mjs +17 -0
- package/apps/cli/dist/packages/data-maintenance/src/files.mjs +121 -0
- package/apps/cli/dist/packages/data-maintenance/src/index.mjs +494 -0
- package/apps/cli/dist/packages/data-maintenance/src/lease.mjs +53 -0
- package/apps/cli/dist/packages/data-maintenance/src/migration-backup.mjs +57 -0
- package/apps/cli/dist/packages/data-maintenance/src/paths.mjs +15 -0
- package/apps/cli/dist/packages/feidee/src/client.mjs +635 -0
- package/apps/cli/dist/packages/feidee/src/hash.mjs +10 -0
- package/apps/cli/dist/packages/feidee/src/index.mjs +8 -0
- package/apps/cli/dist/packages/feidee/src/mutation-gateway.mjs +165 -0
- package/apps/cli/dist/packages/feidee/src/parsers.mjs +634 -0
- package/apps/cli/dist/packages/feidee/src/transaction-text.mjs +39 -0
- package/apps/cli/dist/packages/feidee/src/write-contract.mjs +273 -0
- package/apps/cli/dist/packages/finance/src/date-range.mjs +74 -0
- package/apps/cli/dist/packages/finance/src/domain.mjs +18 -0
- package/apps/cli/dist/packages/finance/src/errors.mjs +221 -0
- package/apps/cli/dist/packages/finance/src/index.mjs +16 -0
- package/apps/cli/dist/packages/finance/src/metadata-query.mjs +32 -0
- package/apps/cli/dist/packages/finance/src/sync/progress.mjs +27 -0
- package/apps/cli/dist/packages/finance/src/sync/service.mjs +282 -0
- package/apps/cli/dist/packages/finance/src/transactions/audit.mjs +104 -0
- package/apps/cli/dist/packages/finance/src/transactions/canary.mjs +85 -0
- package/apps/cli/dist/packages/finance/src/transactions/compare.mjs +76 -0
- package/apps/cli/dist/packages/finance/src/transactions/contracts.mjs +92 -0
- package/apps/cli/dist/packages/finance/src/transactions/memo-policy.mjs +79 -0
- package/apps/cli/dist/packages/finance/src/transactions/mutation.mjs +656 -0
- package/apps/cli/dist/packages/finance/src/transactions/query.mjs +59 -0
- package/apps/cli/dist/packages/finance/src/transactions/statistics.mjs +67 -0
- package/apps/cli/dist/packages/finance/src/write-policy.mjs +4 -0
- package/apps/cli/dist/packages/finance-module/src/balance-preview.mjs +4 -0
- package/apps/cli/dist/packages/finance-module/src/contracts.mjs +13 -0
- package/apps/cli/dist/packages/finance-module/src/database.mjs +1292 -0
- package/apps/cli/dist/packages/finance-module/src/draft-entries.mjs +89 -0
- package/apps/cli/dist/packages/finance-module/src/draft-receipts.mjs +8 -0
- package/apps/cli/dist/packages/finance-module/src/historical-task-archives.mjs +24 -0
- package/apps/cli/dist/packages/finance-module/src/node.mjs +76 -0
- package/apps/cli/dist/packages/finance-module/src/personal-preferences.mjs +29 -0
- package/apps/cli/dist/packages/finance-module/src/route-contracts.mjs +11 -0
- package/apps/cli/dist/packages/finance-module/src/schema-compatibility.mjs +142 -0
- package/apps/cli/dist/packages/finance-module/src/service-record-domain.mjs +16 -0
- package/apps/cli/dist/packages/finance-module/src/service-record-store.mjs +119 -0
- package/apps/cli/dist/packages/finance-module/src/shared-draft-migration.mjs +39 -0
- package/apps/cli/dist/packages/finance-module/src/single-draft-migration.mjs +70 -0
- package/apps/cli/dist/packages/finance-module/src/storage.mjs +282 -0
- package/apps/cli/dist/packages/finance-module/src/web-contracts.mjs +38 -0
- package/apps/cli/dist/packages/local-store/src/checkpoint-backup.mjs +40 -0
- package/apps/cli/dist/packages/local-store/src/checkpoint-history.mjs +77 -0
- package/apps/cli/dist/packages/local-store/src/database.mjs +1523 -0
- package/apps/cli/dist/packages/local-store/src/exchange-rates.mjs +169 -0
- package/apps/cli/dist/packages/local-store/src/node.mjs +71 -0
- package/apps/cli/dist/packages/sdk/src/account-snapshot-service.mjs +582 -0
- package/apps/cli/dist/packages/sdk/src/auth.mjs +89 -0
- package/apps/cli/dist/packages/sdk/src/cache-analysis.mjs +393 -0
- package/apps/cli/dist/packages/sdk/src/config.mjs +64 -0
- package/apps/cli/dist/packages/sdk/src/credential-identity.mjs +8 -0
- package/apps/cli/dist/packages/sdk/src/credentials.mjs +86 -0
- package/apps/cli/dist/packages/sdk/src/exchange-rate-service.mjs +253 -0
- package/apps/cli/dist/packages/sdk/src/finance-cookie-cache.mjs +93 -0
- package/apps/cli/dist/packages/sdk/src/finance-session.mjs +215 -0
- package/apps/cli/dist/packages/sdk/src/frankfurter.mjs +125 -0
- package/apps/cli/dist/packages/sdk/src/node.mjs +53 -0
- package/apps/cli/dist/packages/sdk/src/probe.mjs +65 -0
- package/apps/cli/dist/packages/sdk/src/resource-lease-node.mjs +27 -0
- package/apps/cli/dist/packages/sdk/src/resource-lease-owner-node.mjs +68 -0
- package/apps/cli/dist/packages/sdk/src/resource-lease.mjs +143 -0
- package/apps/cli/dist/packages/sdk/src/runtime.mjs +643 -0
- package/apps/cli/dist/storage.mjs +11 -0
- package/bundles/sui-ledger/dist/_virtual/_rolldown/runtime.mjs +35 -0
- package/bundles/sui-ledger/dist/capabilities/tools.mjs +32 -0
- package/bundles/sui-ledger/dist/client.js +23511 -0
- package/bundles/sui-ledger/dist/finance-prompt.mjs +30 -0
- package/bundles/sui-ledger/dist/finance-state-context.mjs +38 -0
- package/bundles/sui-ledger/dist/index.mjs +198 -0
- package/bundles/sui-ledger/dist/maintenance-cli.mjs +76 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/@deepseek-ai_dsh-home-paths_159c15e70066431314381a350c2ee56a/node_modules/@deepseek-ai/dsh-home-paths/lib/index.mjs +67 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/@keyv_serialize@1.1.1/node_modules/@keyv/serialize/dist/index.mjs +37 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/@sec-ant_readable-stream@0.4.1/node_modules/@sec-ant/readable-stream/dist/ponyfill/asyncIterator.mjs +81 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/@sec-ant_readable-stream@0.4.1/node_modules/@sec-ant/readable-stream/dist/ponyfill/index.mjs +1 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/@sindresorhus_is@7.2.0/node_modules/@sindresorhus/is/distribution/index.mjs +1015 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/@sindresorhus_is@7.2.0/node_modules/@sindresorhus/is/distribution/utilities.mjs +6 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/boolbase@1.0.0/node_modules/boolbase/index.mjs +15 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/byte-counter@0.1.0/node_modules/byte-counter/utilities.mjs +9 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cacheable-lookup@7.0.0/node_modules/cacheable-lookup/source/index.mjs +279 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cacheable-request@13.0.19/node_modules/cacheable-request/dist/index.mjs +274 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cacheable-request@13.0.19/node_modules/cacheable-request/dist/types.mjs +15 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio-select@2.1.0/node_modules/cheerio-select/lib/esm/helpers.mjs +15 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio-select@2.1.0/node_modules/cheerio-select/lib/esm/index.mjs +159 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio-select@2.1.0/node_modules/cheerio-select/lib/esm/positionals.mjs +33 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/attributes.mjs +465 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/css.mjs +94 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/extract.mjs +39 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/forms.mjs +63 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/manipulation.mjs +731 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/api/traversing.mjs +828 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/cheerio.mjs +53 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/index.mjs +11 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/load-parse.mjs +25 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/load.mjs +73 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/options.mjs +27 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/parse.mjs +53 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/parsers/parse5-adapter.mjs +42 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/static.mjs +165 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/cheerio@1.1.2/node_modules/cheerio/dist/esm/utils.mjs +78 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/attributes.mjs +187 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/compile.mjs +77 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/general.mjs +89 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/index.mjs +43 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/aliases.mjs +32 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/filters.mjs +114 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/index.mjs +35 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/pseudos.mjs +53 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/pseudo-selectors/subselects.mjs +68 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-select@5.2.2/node_modules/css-select/lib/esm/sort.mjs +60 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-what@6.2.2/node_modules/css-what/lib/commonjs/index.mjs +50 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-what@6.2.2/node_modules/css-what/lib/commonjs/parse.mjs +320 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-what@6.2.2/node_modules/css-what/lib/commonjs/stringify.mjs +102 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/css-what@6.2.2/node_modules/css-what/lib/commonjs/types.mjs +45 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/decompress-response@10.0.0/node_modules/decompress-response/index.mjs +59 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/dom-serializer@2.0.0/node_modules/dom-serializer/lib/esm/foreignNames.mjs +103 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/dom-serializer@2.0.0/node_modules/dom-serializer/lib/esm/index.mjs +144 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domelementtype@2.3.0/node_modules/domelementtype/lib/esm/index.mjs +51 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domhandler@5.0.3/node_modules/domhandler/lib/esm/index.mjs +128 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domhandler@5.0.3/node_modules/domhandler/lib/esm/node.mjs +312 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/feeds.mjs +161 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/helpers.mjs +113 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/index.mjs +56 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/legacy.mjs +141 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/manipulation.mjs +117 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/querying.mjs +124 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/stringify.mjs +69 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/domutils@3.2.2/node_modules/domutils/lib/esm/traversal.mjs +109 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/encoding-sniffer@0.2.1/node_modules/encoding-sniffer/dist/esm/index.mjs +7 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/encoding-sniffer@0.2.1/node_modules/encoding-sniffer/dist/esm/sniffer.mjs +112 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/escape.mjs +83 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@6.0.1/node_modules/entities/dist/esm/decode-codepoint.mjs +43 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@6.0.1/node_modules/entities/dist/esm/decode.mjs +330 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@6.0.1/node_modules/entities/dist/esm/escape.mjs +49 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@6.0.1/node_modules/entities/dist/esm/generated/decode-data-html.mjs +4 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/decode-codepoint.mjs +57 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/decode.mjs +351 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/generated/decode-data-html.mjs +5 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/generated/decode-data-xml.mjs +5 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/internal/bin-trie-flags.mjs +20 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/esm/internal/decode-shared.mjs +14 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/index.mjs +871 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/form-data-encoder@4.1.0/node_modules/form-data-encoder/lib/index.mjs +279 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/array-buffer.mjs +54 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/buffer.mjs +14 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/contents.mjs +80 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/stream.mjs +41 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/get-stream@9.0.1/node_modules/get-stream/source/utils.mjs +8 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/as-promise/index.mjs +154 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/as-promise/types.mjs +20 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/calculate-retry-delay.mjs +20 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/diagnostics-channel.mjs +38 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/errors.mjs +132 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/index.mjs +923 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/options.mjs +1622 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/parse-link-header.mjs +27 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/response.mjs +36 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/timed-out.mjs +107 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/defer-to-connect.mjs +28 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/get-body-size.mjs +23 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/is-client-request.mjs +6 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/is-form-data.mjs +7 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/is-unix-socket-url.mjs +25 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/proxy-events.mjs +16 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/timer.mjs +114 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/unhandle.mjs +23 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/url-to-options.mjs +20 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/core/utils/weakable-map.mjs +19 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/create.mjs +166 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/got@14.6.5/node_modules/got/dist/source/index.mjs +17 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/htmlparser2@10.1.0/node_modules/htmlparser2/dist/esm/Parser.mjs +441 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/htmlparser2@10.1.0/node_modules/htmlparser2/dist/esm/Tokenizer.mjs +661 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/htmlparser2@10.1.0/node_modules/htmlparser2/dist/esm/index.mjs +19 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http-cache-semantics@4.3.0/node_modules/http-cache-semantics/index.mjs +608 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/agent.mjs +441 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/auto.mjs +145 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/client-request.mjs +318 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/incoming-message.mjs +58 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/index.mjs +51 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/get-auth-headers.mjs +19 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/h1-over-h2.mjs +84 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/h2-over-h1.mjs +49 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/h2-over-h2.mjs +38 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/h2-over-hx.mjs +39 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/initialize.mjs +23 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/proxies/unexpected-status-code-error.mjs +15 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/calculate-server-name.mjs +24 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/check-type.mjs +17 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/delay-async-destroy.mjs +28 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/errors.mjs +30 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/is-request-pseudo-header.mjs +16 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/js-stream-socket.mjs +9 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/proxy-events.mjs +10 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/proxy-socket-handler.mjs +77 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/validate-header-name.mjs +15 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/http2-wrapper@2.2.1/node_modules/http2-wrapper/source/utils/validate-header-value.mjs +14 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/dbcs-codec.mjs +355 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/dbcs-data.mjs +191 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/index.mjs +31 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/internal.mjs +140 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/sbcs-codec.mjs +50 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/sbcs-data-generated.mjs +455 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/sbcs-data.mjs +151 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/big5-added.mjs +169 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/cp936.mjs +2584 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/cp949.mjs +2220 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/cp950.mjs +227 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/eucjp.mjs +425 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/gb18030-ranges.mjs +427 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/gbk-added.mjs +230 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/tables/shiftjis.mjs +292 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/utf16.mjs +123 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/utf32.mjs +197 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/encodings/utf7.mjs +182 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/bom-handling.mjs +42 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/index.mjs +108 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/streams.mjs +90 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/is-stream@4.0.1/node_modules/is-stream/index.mjs +9 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/js-sha256@0.11.1/node_modules/js-sha256/src/sha256.mjs +495 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/keyv@5.6.0/node_modules/keyv/dist/index.mjs +740 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/lowercase-keys@3.0.0/node_modules/lowercase-keys/index.mjs +6 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/mimic-response@4.0.0/node_modules/mimic-response/index.mjs +53 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/normalize-url@8.1.1/node_modules/normalize-url/index.mjs +145 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/nth-check@2.1.1/node_modules/nth-check/lib/esm/compile.mjs +37 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/nth-check@2.1.1/node_modules/nth-check/lib/esm/index.mjs +31 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/nth-check@2.1.1/node_modules/nth-check/lib/esm/parse.mjs +60 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/p-cancelable@4.0.1/node_modules/p-cancelable/index.mjs +86 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5-htmlparser2-tree-adapter@7.1.0/node_modules/parse5-htmlparser2-tree-adapter/dist/index.mjs +187 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5-parser-stream@7.1.2/node_modules/parse5-parser-stream/dist/index.mjs +2 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/doctype.mjs +101 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/error-codes.mjs +66 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/foreign-content.mjs +259 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/html.mjs +544 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/token.mjs +19 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/common/unicode.mjs +91 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/index.mjs +41 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/parser/formatting-element-list.mjs +91 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/parser/index.mjs +2492 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/parser/open-element-stack.mjs +292 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/serializer/index.mjs +111 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/tokenizer/index.mjs +2067 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/tokenizer/preprocessor.mjs +154 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/parse5@7.3.0/node_modules/parse5/dist/tree-adapters/default.mjs +164 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/quick-lru@5.1.1/node_modules/quick-lru/index.mjs +77 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/resolve-alpn@1.2.1/node_modules/resolve-alpn/index.mjs +47 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/responselike@4.0.2/node_modules/responselike/index.mjs +32 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/safer-buffer@2.1.2/node_modules/safer-buffer/safer.mjs +45 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/tldts@7.4.18/node_modules/tldts/dist/cjs/index.mjs +22542 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/tough-cookie@6.0.0/node_modules/tough-cookie/dist/index.mjs +1761 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/index.mjs +221 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/abort-signal.mjs +44 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-connect.mjs +85 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-pipeline.mjs +174 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-request.mjs +155 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-stream.mjs +136 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/api-upgrade.mjs +88 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/index.mjs +17 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/api/readable.mjs +418 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/cache/memory-cache-store.mjs +190 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/cache/sqlite-cache-store.mjs +324 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/connect.mjs +115 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/constants.mjs +134 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/diagnostics.mjs +114 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/errors.mjs +412 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/request.mjs +282 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/socks5-client.mjs +288 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/socks5-utils.mjs +166 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/symbols.mjs +80 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/tree.mjs +124 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/core/util.mjs +940 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/agent.mjs +119 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/balanced-pool.mjs +129 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/client-h1.mjs +1091 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/client-h2.mjs +588 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/client.mjs +385 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/dispatcher-base.mjs +121 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/dispatcher.mjs +35 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/env-http-proxy-agent.mjs +105 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/fixed-queue.mjs +75 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/h2c-client.mjs +31 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/pool-base.mjs +155 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/pool.mjs +76 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/proxy-agent.mjs +233 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/retry-agent.mjs +37 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/round-robin-pool.mjs +94 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/dispatcher/socks5-proxy-agent.mjs +194 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/encoding/index.mjs +18 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/global.mjs +48 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/cache-handler.mjs +457 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/cache-revalidation-handler.mjs +82 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/decorator-handler.mjs +57 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/deduplication-handler.mjs +341 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/redirect-handler.mjs +131 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/retry-handler.mjs +332 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/unwrap-handler.mjs +88 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/handler/wrap-handler.mjs +68 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/cache.mjs +350 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/decompress.mjs +416 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/deduplicate.mjs +69 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/dns.mjs +323 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/dump.mjs +65 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/redirect.mjs +20 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/response-error.mjs +73 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/interceptor/retry.mjs +25 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/llhttp/constants.mjs +590 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/llhttp/llhttp-wasm.mjs +13 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/llhttp/llhttp_simd-wasm.mjs +13 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/llhttp/utils.mjs +16 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-agent.mjs +154 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-call-history.mjs +159 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-client.mjs +59 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-errors.mjs +28 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-interceptor.mjs +150 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-pool.mjs +59 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-symbols.mjs +37 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/mock-utils.mjs +302 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/pending-interceptors-formatter.mjs +38 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/snapshot-agent.mjs +268 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/snapshot-recorder.mjs +424 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/mock/snapshot-utils.mjs +121 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/cache.mjs +440 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/date.mjs +332 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/promise.mjs +31 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/runtime-features.mjs +101 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/stats.mjs +31 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/util/timers.mjs +341 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cache/cache.mjs +462 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cache/cachestorage.mjs +103 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cache/util.mjs +39 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cookies/constants.mjs +11 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cookies/index.mjs +169 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cookies/parse.mjs +108 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/cookies/util.mjs +239 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/eventsource/eventsource-stream.mjs +317 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/eventsource/eventsource.mjs +345 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/eventsource/util.mjs +29 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/body.mjs +271 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/constants.mjs +224 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/data-url.mjs +247 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/formdata-parser.mjs +255 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/formdata.mjs +153 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/global.mjs +34 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/headers.mjs +400 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/index.mjs +776 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/request.mjs +602 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/response.mjs +358 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/fetch/util.mjs +795 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/infra/index.mjs +154 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.mjs +170 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/webidl/index.mjs +505 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/connection.mjs +166 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/constants.mjs +47 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/events.mjs +268 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/frame.mjs +105 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/permessage-deflate.mjs +85 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/receiver.mjs +323 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/sender.mjs +90 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/stream/websocketerror.mjs +78 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/stream/websocketstream.mjs +270 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/util.mjs +212 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/undici@7.30.0/node_modules/undici/lib/web/websocket/websocket.mjs +432 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/whatwg-encoding@3.1.1/node_modules/whatwg-encoding/lib/labels-to-names.mjs +224 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/whatwg-encoding@3.1.1/node_modules/whatwg-encoding/lib/supported-names.mjs +45 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/whatwg-encoding@3.1.1/node_modules/whatwg-encoding/lib/whatwg-encoding.mjs +40 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/mime-type-parameters.mjs +54 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/mime-type.mjs +92 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/parser.mjs +62 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/serializer.mjs +24 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/whatwg-mimetype@4.0.0/node_modules/whatwg-mimetype/lib/utils.mjs +47 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/xlsx@0.18.5/node_modules/xlsx/dist/cpexcel.mjs +3348 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/xlsx@0.18.5/node_modules/xlsx/xlsx.mjs +26473 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.mjs +26 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/iso.mjs +35 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/parse.mjs +17 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/schemas.mjs +800 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/api.mjs +508 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/checks.mjs +366 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.mjs +60 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/doc.mjs +32 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.mjs +63 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.mjs +253 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/parse.mjs +118 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/regexes.mjs +65 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/registries.mjs +48 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/schemas.mjs +1235 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.mjs +297 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.mjs +316 -0
- package/bundles/sui-ledger/dist/node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/versions.mjs +8 -0
- package/bundles/sui-ledger/dist/packages/data-maintenance/src/archive.mjs +143 -0
- package/bundles/sui-ledger/dist/packages/data-maintenance/src/contracts.mjs +17 -0
- package/bundles/sui-ledger/dist/packages/data-maintenance/src/files.mjs +158 -0
- package/bundles/sui-ledger/dist/packages/data-maintenance/src/index.mjs +494 -0
- package/bundles/sui-ledger/dist/packages/data-maintenance/src/lease.mjs +53 -0
- package/bundles/sui-ledger/dist/packages/data-maintenance/src/migration-backup.mjs +57 -0
- package/bundles/sui-ledger/dist/packages/data-maintenance/src/paths.mjs +15 -0
- package/bundles/sui-ledger/dist/packages/data-maintenance/src/runtime.mjs +132 -0
- package/bundles/sui-ledger/dist/packages/feidee/src/client.mjs +635 -0
- package/bundles/sui-ledger/dist/packages/feidee/src/hash.mjs +10 -0
- package/bundles/sui-ledger/dist/packages/feidee/src/index.mjs +8 -0
- package/bundles/sui-ledger/dist/packages/feidee/src/mutation-gateway.mjs +165 -0
- package/bundles/sui-ledger/dist/packages/feidee/src/parsers.mjs +634 -0
- package/bundles/sui-ledger/dist/packages/feidee/src/transaction-text.mjs +39 -0
- package/bundles/sui-ledger/dist/packages/feidee/src/write-contract.mjs +273 -0
- package/bundles/sui-ledger/dist/packages/finance/src/date-range.mjs +74 -0
- package/bundles/sui-ledger/dist/packages/finance/src/domain.mjs +18 -0
- package/bundles/sui-ledger/dist/packages/finance/src/errors.mjs +221 -0
- package/bundles/sui-ledger/dist/packages/finance/src/index.mjs +17 -0
- package/bundles/sui-ledger/dist/packages/finance/src/json-schema.mjs +212 -0
- package/bundles/sui-ledger/dist/packages/finance/src/metadata-query.mjs +32 -0
- package/bundles/sui-ledger/dist/packages/finance/src/money.mjs +39 -0
- package/bundles/sui-ledger/dist/packages/finance/src/public-error.mjs +10 -0
- package/bundles/sui-ledger/dist/packages/finance/src/sync/progress.mjs +27 -0
- package/bundles/sui-ledger/dist/packages/finance/src/sync/service.mjs +282 -0
- package/bundles/sui-ledger/dist/packages/finance/src/transactions/audit.mjs +104 -0
- package/bundles/sui-ledger/dist/packages/finance/src/transactions/canary.mjs +85 -0
- package/bundles/sui-ledger/dist/packages/finance/src/transactions/compare.mjs +76 -0
- package/bundles/sui-ledger/dist/packages/finance/src/transactions/contracts.mjs +83 -0
- package/bundles/sui-ledger/dist/packages/finance/src/transactions/memo-policy.mjs +79 -0
- package/bundles/sui-ledger/dist/packages/finance/src/transactions/mutation.mjs +656 -0
- package/bundles/sui-ledger/dist/packages/finance/src/transactions/query.mjs +59 -0
- package/bundles/sui-ledger/dist/packages/finance/src/transactions/statistics.mjs +67 -0
- package/bundles/sui-ledger/dist/packages/finance/src/write-policy.mjs +4 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/balance-preview.mjs +119 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/capabilities.mjs +1306 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/checkpoint-review.mjs +75 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/commit-failure.mjs +161 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/commit-recovery.mjs +41 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/contracts.mjs +13 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/data-version.mjs +8 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/database.mjs +1292 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/draft-entries.mjs +216 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/draft-receipts.mjs +16 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/finance-guidance.mjs +23 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/historical-task-archives.mjs +24 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/index.mjs +17 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/interactions.mjs +229 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/model-pages.mjs +61 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/model-views.mjs +206 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/node.mjs +76 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/personal-preferences.mjs +103 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/route-contracts.mjs +11 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/routes.mjs +427 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/schema-compatibility.mjs +142 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/sdk-adapter.mjs +100 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/service-record-domain.mjs +207 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/service-record-routes.mjs +91 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/service-record-store.mjs +119 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/service-record-tools.mjs +283 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/service-records.mjs +626 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/service.mjs +2525 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/shared-draft-migration.mjs +39 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/single-draft-migration.mjs +70 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/source-reader.mjs +354 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/storage.mjs +282 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/tool-contracts.mjs +42 -0
- package/bundles/sui-ledger/dist/packages/finance-module/src/web-contracts.mjs +74 -0
- package/bundles/sui-ledger/dist/packages/interaction/src/registry.mjs +36 -0
- package/bundles/sui-ledger/dist/packages/interaction/src/service.mjs +424 -0
- package/bundles/sui-ledger/dist/packages/local-store/src/checkpoint-backup.mjs +40 -0
- package/bundles/sui-ledger/dist/packages/local-store/src/checkpoint-history.mjs +77 -0
- package/bundles/sui-ledger/dist/packages/local-store/src/database.mjs +1523 -0
- package/bundles/sui-ledger/dist/packages/local-store/src/exchange-rates.mjs +169 -0
- package/bundles/sui-ledger/dist/packages/local-store/src/node.mjs +71 -0
- package/bundles/sui-ledger/dist/packages/local-store/src/readonly-node.mjs +486 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/account-snapshot-service.mjs +582 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/cache-analysis.mjs +597 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/config.mjs +64 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/credential-identity.mjs +7 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/credentials.mjs +86 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/exchange-rate-service.mjs +253 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/finance-cookie-cache.mjs +93 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/finance-session.mjs +215 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/frankfurter.mjs +125 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/ledger-money.mjs +183 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/node-readonly.mjs +381 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/node.mjs +53 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/probe.mjs +65 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/resource-lease-node.mjs +27 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/resource-lease-owner-node.mjs +68 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/resource-lease.mjs +143 -0
- package/bundles/sui-ledger/dist/packages/sdk/src/runtime.mjs +643 -0
- package/bundles/sui-ledger/dist/preferences-context.mjs +21 -0
- package/bundles/sui-ledger/dist/remote-write-policy.mjs +51 -0
- package/bundles/sui-ledger/dist/routes/finance-api.mjs +380 -0
- package/bundles/sui-ledger/dist/session/attachment-ownership.mjs +53 -0
- package/bundles/sui-ledger/dist/session/call-context.mjs +14 -0
- package/bundles/sui-ledger/dist/session/source-ports.mjs +74 -0
- package/bundles/sui-ledger/dist/storage/business-runtime.mjs +116 -0
- package/bundles/sui-ledger/dist/storage/maintenance-http.mjs +159 -0
- package/bundles/sui-ledger/dist/storage/paths.mjs +15 -0
- package/bundles/sui-ledger/dist/style.css +15416 -0
- package/bundles/sui-ledger/icon.svg +1 -0
- package/bundles/sui-ledger/locale/en.json +6 -0
- package/bundles/sui-ledger/locale/zh-CN.json +6 -0
- package/cordis.patch.yml +4 -0
- package/package.json +111 -3
|
@@ -0,0 +1,2525 @@
|
|
|
1
|
+
import { createInputFinancialPayload, financialPayloadEquals, mergeTransactionPatch, transactionFinancialPayload } from "../../finance/src/transactions/compare.mjs";
|
|
2
|
+
import { isTransactionCategory } from "../../finance/src/domain.mjs";
|
|
3
|
+
import { financialMonthRange } from "../../finance/src/date-range.mjs";
|
|
4
|
+
import { FeideeError, WriteBoundaryError, WriteDisabledError, assertMemoPolicy } from "../../finance/src/errors.mjs";
|
|
5
|
+
import { syncFailureMessage } from "../../finance/src/sync/progress.mjs";
|
|
6
|
+
import { createTransactionInputSchema, deleteTransactionInputSchema, updateTransactionInputSchema, updateTransactionPatchSchema } from "../../finance/src/transactions/contracts.mjs";
|
|
7
|
+
import { assertWriteTimePrecision, validateTransactionMetadata } from "../../finance/src/transactions/mutation.mjs";
|
|
8
|
+
import "../../finance/src/index.mjs";
|
|
9
|
+
import { buildBalancePreview, calculateAccountImpacts, snapshotAccounts } from "./balance-preview.mjs";
|
|
10
|
+
import { commitCanResume, draftEntryNeedsCompletion, operationCanContinue, operationIsVerified, sanitizeLedgerSyncProgress } from "./web-contracts.mjs";
|
|
11
|
+
import { draftMutationReceiptKey } from "./draft-receipts.mjs";
|
|
12
|
+
import { FinanceDraftFieldError, draftFields, prepareDraftEntry, projectDraftEntry, reviseEntry } from "./draft-entries.mjs";
|
|
13
|
+
import { ServiceRecordsApplication } from "./service-records.mjs";
|
|
14
|
+
import { FinanceCheckError, commitFailure, failureBlocksIndependentWrites } from "./commit-failure.mjs";
|
|
15
|
+
import { effectiveRecoveryOperation, recoveryHash, verificationInput } from "./commit-recovery.mjs";
|
|
16
|
+
import { remoteVersion } from "./data-version.mjs";
|
|
17
|
+
import { checkpointBalance, checkpointDelta, checkpointThrough, reviewCheckpoint } from "./checkpoint-review.mjs";
|
|
18
|
+
import { offsetPage } from "./model-pages.mjs";
|
|
19
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
20
|
+
//#region ../../packages/finance-module/src/service.ts
|
|
21
|
+
const DEFAULT_BOOK_SETTING_KEY = "default_book_id";
|
|
22
|
+
const FINANCE_REMOTE_WRITES_DISABLED_ERROR = "finance_remote_writes_disabled";
|
|
23
|
+
const FINANCE_GRANT_MISSING_HINT = "finance_grant_missing: no active BookReadGrant for this subject. Call finance_books_list to inspect the books and the active grant, then create the finance.book_grant.selection interaction so the user can bind a book; do not retry other book tools.";
|
|
24
|
+
function knownBook(ledger, bookId) {
|
|
25
|
+
const books = ledger.cachedBooks();
|
|
26
|
+
return Array.isArray(books) && books.some((book) => book?.id === bookId);
|
|
27
|
+
}
|
|
28
|
+
var FinanceApplicationService = class {
|
|
29
|
+
options;
|
|
30
|
+
serviceRecords;
|
|
31
|
+
id;
|
|
32
|
+
now;
|
|
33
|
+
readbackTimers = /* @__PURE__ */ new Map();
|
|
34
|
+
readbackRuns = /* @__PURE__ */ new Map();
|
|
35
|
+
commitRuns = /* @__PURE__ */ new Map();
|
|
36
|
+
maintenancePaused = false;
|
|
37
|
+
async pauseMaintenance() {
|
|
38
|
+
this.maintenancePaused = true;
|
|
39
|
+
for (const timer of this.readbackTimers.values()) clearTimeout(timer);
|
|
40
|
+
this.readbackTimers.clear();
|
|
41
|
+
await Promise.allSettled([...this.commitRuns.values(), ...this.readbackRuns.values()]);
|
|
42
|
+
}
|
|
43
|
+
resumeMaintenance() {
|
|
44
|
+
this.maintenancePaused = false;
|
|
45
|
+
for (const commit of this.options.store.listCommits()) if (commit.operations.some((op) => op.nextReadbackAt)) this.scheduleReadback(commit.id);
|
|
46
|
+
}
|
|
47
|
+
constructor(options) {
|
|
48
|
+
this.options = options;
|
|
49
|
+
this.id = options.id ?? randomUUID;
|
|
50
|
+
this.now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
51
|
+
this.serviceRecords = options.store.serviceRecords ? new ServiceRecordsApplication({
|
|
52
|
+
store: options.store.serviceRecords,
|
|
53
|
+
ledger: options.ledger,
|
|
54
|
+
now: this.now,
|
|
55
|
+
id: this.id,
|
|
56
|
+
authorize: (subjectId, bookId) => {
|
|
57
|
+
this.requireGrantedBook(subjectId, bookId);
|
|
58
|
+
}
|
|
59
|
+
}) : void 0;
|
|
60
|
+
}
|
|
61
|
+
close() {
|
|
62
|
+
for (const timer of this.readbackTimers.values()) clearTimeout(timer);
|
|
63
|
+
this.readbackTimers.clear();
|
|
64
|
+
this.options.store.close();
|
|
65
|
+
}
|
|
66
|
+
remoteWritePolicy() {
|
|
67
|
+
return this.options.remoteWritesDisabled ? {
|
|
68
|
+
enabled: false,
|
|
69
|
+
reason: "environment"
|
|
70
|
+
} : { enabled: true };
|
|
71
|
+
}
|
|
72
|
+
deleteSubjectResources(subjectId) {
|
|
73
|
+
this.options.store.deleteSubjectResources(subjectId);
|
|
74
|
+
}
|
|
75
|
+
listSubjectResourceOwners() {
|
|
76
|
+
return this.options.store.listSubjectResourceOwners();
|
|
77
|
+
}
|
|
78
|
+
bindSubjectGrant(input) {
|
|
79
|
+
if ("subjectType" in input) throw new Error("finance_grant_role_unsupported");
|
|
80
|
+
this.options.assertSubjectAvailable?.(input.subjectId);
|
|
81
|
+
return this.options.store.bindSubjectGrant({
|
|
82
|
+
id: this.id(),
|
|
83
|
+
subjectId: input.subjectId,
|
|
84
|
+
bookId: input.bookId,
|
|
85
|
+
...input.expectedRevision !== void 0 ? { expectedRevision: input.expectedRevision } : {},
|
|
86
|
+
now: this.now()
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
getGrant(subjectId) {
|
|
90
|
+
return this.options.store.getActiveGrant(subjectId);
|
|
91
|
+
}
|
|
92
|
+
/** Prompt assembly is a pure read: it must not auto-bind the default book. */
|
|
93
|
+
getModelFinanceContext(subjectId) {
|
|
94
|
+
const grant = this.options.store.getActiveGrant(subjectId);
|
|
95
|
+
if (!grant) return { status: "unbound" };
|
|
96
|
+
const summaries = this.options.store.describeWorksets?.(grant.bookId);
|
|
97
|
+
if (!summaries) throw new Error("finance_workset_summary_unavailable");
|
|
98
|
+
const state = this.options.ledger.peekLedgerBookState?.(grant.bookId);
|
|
99
|
+
const row = this.options.store.getOpenDraftRow(subjectId);
|
|
100
|
+
const draft = !row ? { status: "empty" } : row.bookId !== grant.bookId || row.grantId !== grant.id ? { status: "grant_changed" } : {
|
|
101
|
+
status: "open",
|
|
102
|
+
id: row.id,
|
|
103
|
+
entryCount: row.entries.length,
|
|
104
|
+
fingerprint: remoteVersion({
|
|
105
|
+
id: row.id,
|
|
106
|
+
entries: row.entries
|
|
107
|
+
})
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
status: "available",
|
|
111
|
+
bookId: grant.bookId,
|
|
112
|
+
grantRevision: grant.revision,
|
|
113
|
+
ledger: state ? {
|
|
114
|
+
revision: state.revision,
|
|
115
|
+
timezone: state.timezone
|
|
116
|
+
} : null,
|
|
117
|
+
pending: {
|
|
118
|
+
changed: summaries.reduce((total, summary) => total + (summary.counts.changed ?? 0), 0),
|
|
119
|
+
staged: summaries.reduce((total, summary) => total + (summary.counts.staged ?? 0), 0),
|
|
120
|
+
fingerprint: remoteVersion(summaries.map(({ id, version }) => ({
|
|
121
|
+
id,
|
|
122
|
+
version
|
|
123
|
+
})))
|
|
124
|
+
},
|
|
125
|
+
draft
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
getDefaultBook() {
|
|
129
|
+
const value = this.options.store.getSetting(DEFAULT_BOOK_SETTING_KEY);
|
|
130
|
+
return typeof value === "string" && value.trim() ? value : null;
|
|
131
|
+
}
|
|
132
|
+
setDefaultBook(bookId) {
|
|
133
|
+
if (!knownBook(this.options.ledger, bookId)) throw new Error("finance_book_not_found");
|
|
134
|
+
this.options.store.setSetting(DEFAULT_BOOK_SETTING_KEY, bookId, this.now());
|
|
135
|
+
return { bookId };
|
|
136
|
+
}
|
|
137
|
+
describeBooks(subject) {
|
|
138
|
+
const grant = this.options.store.getActiveGrant(subject.subjectId);
|
|
139
|
+
return {
|
|
140
|
+
books: this.options.ledger.cachedBooks(),
|
|
141
|
+
activeGrant: grant ? {
|
|
142
|
+
bookId: grant.bookId,
|
|
143
|
+
revision: grant.revision,
|
|
144
|
+
boundAt: grant.boundAt
|
|
145
|
+
} : null,
|
|
146
|
+
defaultBookId: this.getDefaultBook()
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** Bind the configured default book when the subject has no grant yet; the user approved this default up front. */
|
|
150
|
+
ensureDefaultBookGrant(subjectId) {
|
|
151
|
+
this.options.assertSubjectAvailable?.(subjectId);
|
|
152
|
+
const existing = this.options.store.getActiveGrant(subjectId);
|
|
153
|
+
if (existing) return existing;
|
|
154
|
+
const bookId = this.getDefaultBook();
|
|
155
|
+
if (!bookId || !knownBook(this.options.ledger, bookId)) return void 0;
|
|
156
|
+
return this.options.store.bindSubjectGrant({
|
|
157
|
+
id: this.id(),
|
|
158
|
+
subjectId,
|
|
159
|
+
bookId,
|
|
160
|
+
now: this.now()
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
requireGrantedBook(subjectId, bookId) {
|
|
164
|
+
return this.requireGrant(subjectId, bookId);
|
|
165
|
+
}
|
|
166
|
+
async readSourceRows(input) {
|
|
167
|
+
if (!this.options.sourceReader?.readRows) throw new Error("finance_source_rows_unavailable");
|
|
168
|
+
return this.options.sourceReader.readRows(input);
|
|
169
|
+
}
|
|
170
|
+
async inspectSource(input) {
|
|
171
|
+
if (!this.options.sourceReader) throw new Error("finance_source_reader_unavailable");
|
|
172
|
+
return this.options.sourceReader.inspect(input);
|
|
173
|
+
}
|
|
174
|
+
getDraftForSubject(subject) {
|
|
175
|
+
if ("subjectType" in subject) throw new Error("finance_draft_role_unsupported");
|
|
176
|
+
const row = this.options.store.getOpenDraftRow(subject.subjectId);
|
|
177
|
+
if (!row) return null;
|
|
178
|
+
this.requireGrant(row.subjectId, row.bookId, row.grantId);
|
|
179
|
+
return this.draftView(row);
|
|
180
|
+
}
|
|
181
|
+
getBookedDraftsForSubject(subject) {
|
|
182
|
+
if ("subjectType" in subject) throw new Error("finance_draft_role_unsupported");
|
|
183
|
+
return this.options.store.listBookedDraftRows(subject.subjectId);
|
|
184
|
+
}
|
|
185
|
+
/** 模型在便签上追加条目;同一会话永远落在唯一 open 行上。 */
|
|
186
|
+
addDraftEntries(context, input) {
|
|
187
|
+
assertMutationContext(context);
|
|
188
|
+
return this.draftMutationOnce(context, "add", input, () => {
|
|
189
|
+
if ("subjectType" in input) throw new Error("finance_draft_role_unsupported");
|
|
190
|
+
if (!input.entries.length) throw new Error("finance_draft_batch_empty");
|
|
191
|
+
const existing = this.options.store.getOpenDraftRow(context.subjectId);
|
|
192
|
+
if (existing) this.requireGrant(existing.subjectId, existing.bookId, existing.grantId);
|
|
193
|
+
const bookId = existing?.bookId ?? input.bookId;
|
|
194
|
+
if (!bookId) throw new FinanceDraftFieldError([{
|
|
195
|
+
field: "bookId",
|
|
196
|
+
message: "The first batch requires the authorized bookId"
|
|
197
|
+
}]);
|
|
198
|
+
if (existing && input.bookId !== void 0 && input.bookId !== existing.bookId) throw new Error("finance_draft_book_mismatch");
|
|
199
|
+
const grant = this.requireGrantedBook(context.subjectId, bookId);
|
|
200
|
+
const metadata = financeBookMetadata(this.options.ledger.cachedMetadata(bookId));
|
|
201
|
+
const now = this.now();
|
|
202
|
+
const additions = this.prepareDraftEntries(input.entries.map((draft) => ({
|
|
203
|
+
id: this.id(),
|
|
204
|
+
draft: structuredClone(draft),
|
|
205
|
+
requiredFields: [],
|
|
206
|
+
createdAt: now
|
|
207
|
+
})), bookId, true);
|
|
208
|
+
const row = existing ? {
|
|
209
|
+
...existing,
|
|
210
|
+
entries: [...existing.entries, ...additions],
|
|
211
|
+
updatedAt: now
|
|
212
|
+
} : {
|
|
213
|
+
id: this.id(),
|
|
214
|
+
subjectId: context.subjectId,
|
|
215
|
+
grantId: grant.id,
|
|
216
|
+
bookId,
|
|
217
|
+
status: "open",
|
|
218
|
+
entries: additions,
|
|
219
|
+
referenceData: draftReferenceData(metadata),
|
|
220
|
+
createdAt: now,
|
|
221
|
+
updatedAt: now
|
|
222
|
+
};
|
|
223
|
+
const saved = this.options.store.saveDraftRowWithEvent(row, {
|
|
224
|
+
kind: "finance_draft_entry_added",
|
|
225
|
+
subjectId: row.subjectId,
|
|
226
|
+
domainReference: row.id,
|
|
227
|
+
correlationId: context.callId,
|
|
228
|
+
idempotencyKey: `finance-draft-add:${row.id}:${context.callId}`,
|
|
229
|
+
now
|
|
230
|
+
});
|
|
231
|
+
return this.draftView(saved);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/** 模型修订便签上的某条条目(改目标、补字段)。 */
|
|
235
|
+
updateDraftEntry(context, input) {
|
|
236
|
+
assertMutationContext(context);
|
|
237
|
+
return this.draftMutationOnce(context, "update", input, () => {
|
|
238
|
+
if (Object.keys(input).some((key) => ![
|
|
239
|
+
"entryId",
|
|
240
|
+
"operation",
|
|
241
|
+
"remoteId",
|
|
242
|
+
"set"
|
|
243
|
+
].includes(key))) throw new FinanceDraftFieldError([{
|
|
244
|
+
field: "input",
|
|
245
|
+
message: "Unsupported draft update field"
|
|
246
|
+
}]);
|
|
247
|
+
const row = this.requireOpenDraftRow(context.subjectId);
|
|
248
|
+
const target = row.entries.find((entry) => entry.id === input.entryId);
|
|
249
|
+
if (!target) throw new Error("finance_draft_entry_not_found");
|
|
250
|
+
const edited = reviseEntry(target, {
|
|
251
|
+
...input.operation !== void 0 ? { operation: input.operation } : {},
|
|
252
|
+
...input.remoteId !== void 0 ? { remoteId: input.remoteId } : {},
|
|
253
|
+
...input.set !== void 0 ? { set: input.set } : {}
|
|
254
|
+
});
|
|
255
|
+
const prepared = this.prepareDraftEntries([edited], row.bookId)[0];
|
|
256
|
+
const now = this.now();
|
|
257
|
+
const saved = this.options.store.saveDraftRowWithEvent({
|
|
258
|
+
...row,
|
|
259
|
+
entries: row.entries.map((entry) => entry.id === input.entryId ? prepared : entry),
|
|
260
|
+
updatedAt: now
|
|
261
|
+
}, {
|
|
262
|
+
kind: "finance_draft_entry_updated",
|
|
263
|
+
subjectId: row.subjectId,
|
|
264
|
+
domainReference: row.id,
|
|
265
|
+
correlationId: context.callId,
|
|
266
|
+
idempotencyKey: `finance-draft-update:${row.id}:${input.entryId}:${context.callId}`,
|
|
267
|
+
now
|
|
268
|
+
});
|
|
269
|
+
return this.draftView(saved);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/** 删除便签上的某条条目(模型「不要了」与可信 UI 共用)。 */
|
|
273
|
+
removeDraftEntry(context, input) {
|
|
274
|
+
assertMutationContext(context);
|
|
275
|
+
return this.draftMutationOnce(context, "remove", input, () => {
|
|
276
|
+
const row = this.requireOpenDraftRow(context.subjectId);
|
|
277
|
+
if (!row.entries.some((entry) => entry.id === input.entryId)) throw new Error("finance_draft_entry_not_found");
|
|
278
|
+
const now = this.now();
|
|
279
|
+
const saved = this.options.store.saveDraftRowWithEvent({
|
|
280
|
+
...row,
|
|
281
|
+
entries: row.entries.filter((entry) => entry.id !== input.entryId),
|
|
282
|
+
updatedAt: now
|
|
283
|
+
}, {
|
|
284
|
+
kind: "finance_draft_entry_removed",
|
|
285
|
+
subjectId: row.subjectId,
|
|
286
|
+
domainReference: row.id,
|
|
287
|
+
correlationId: context.callId,
|
|
288
|
+
idempotencyKey: `finance-draft-remove:${row.id}:${input.entryId}:${context.callId}`,
|
|
289
|
+
now
|
|
290
|
+
});
|
|
291
|
+
return this.draftView(saved);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
/** 入账三步一体(可信入口专用):完整条目复制进 workset → 行冻结 booked → 待补齐开新 open 行。 */
|
|
295
|
+
moveDraftToWorkset(context) {
|
|
296
|
+
assertMutationContext(context);
|
|
297
|
+
return this.options.store.transaction(() => {
|
|
298
|
+
const row = this.requireOpenDraftRow(context.subjectId);
|
|
299
|
+
this.requireGrant(row.subjectId, row.bookId, row.grantId);
|
|
300
|
+
const metadata = financeBookMetadata(this.options.ledger.cachedMetadata(row.bookId));
|
|
301
|
+
const currentEntries = this.analyzeDraftEntries(row.entries, row.bookId);
|
|
302
|
+
const movable = currentEntries.filter((entry) => !draftEntryNeedsCompletion(entry) && entry.proposal && entry.draft?.operation !== "matched");
|
|
303
|
+
if (!movable.length) throw new Error("finance_draft_no_complete_entries");
|
|
304
|
+
assertDraftProposalsValid(movable, metadata, row.bookId, this.options.ledger);
|
|
305
|
+
const now = this.now();
|
|
306
|
+
let version = this.options.store.getCanonicalWorkset(row.bookId) ?? this.options.store.ensureCanonicalWorkset({
|
|
307
|
+
id: this.id(),
|
|
308
|
+
bookId: row.bookId,
|
|
309
|
+
createdAt: now,
|
|
310
|
+
title: "待入账"
|
|
311
|
+
});
|
|
312
|
+
for (const entry of movable) version = this.options.store.addEntry({
|
|
313
|
+
id: draftEntryId(row.id, entry.id),
|
|
314
|
+
worksetId: version.id,
|
|
315
|
+
bookId: row.bookId,
|
|
316
|
+
proposal: validateProposal(entry.proposal),
|
|
317
|
+
evidence: draftEvidence(row, entry, now),
|
|
318
|
+
subjectId: row.subjectId,
|
|
319
|
+
expectedVersion: version.version,
|
|
320
|
+
now
|
|
321
|
+
});
|
|
322
|
+
const leftovers = currentEntries.filter(draftEntryNeedsCompletion);
|
|
323
|
+
const booked = this.options.store.saveDraftRowWithEvent({
|
|
324
|
+
...row,
|
|
325
|
+
status: "booked",
|
|
326
|
+
bookedAt: now,
|
|
327
|
+
bookedSummary: {
|
|
328
|
+
moved: movable.length,
|
|
329
|
+
left: leftovers.length
|
|
330
|
+
},
|
|
331
|
+
updatedAt: now
|
|
332
|
+
}, {
|
|
333
|
+
kind: "finance_draft_moved",
|
|
334
|
+
subjectId: row.subjectId,
|
|
335
|
+
domainReference: row.id,
|
|
336
|
+
correlationId: context.callId,
|
|
337
|
+
idempotencyKey: `finance-draft-move:${row.id}:${context.callId}`,
|
|
338
|
+
now
|
|
339
|
+
});
|
|
340
|
+
let leftover;
|
|
341
|
+
if (leftovers.length) leftover = this.options.store.saveDraftRow({
|
|
342
|
+
id: this.id(),
|
|
343
|
+
subjectId: row.subjectId,
|
|
344
|
+
grantId: row.grantId,
|
|
345
|
+
bookId: row.bookId,
|
|
346
|
+
status: "open",
|
|
347
|
+
entries: leftovers,
|
|
348
|
+
...row.referenceData ? { referenceData: row.referenceData } : {},
|
|
349
|
+
...row.source ? { source: row.source } : {},
|
|
350
|
+
createdAt: now,
|
|
351
|
+
updatedAt: now
|
|
352
|
+
});
|
|
353
|
+
return {
|
|
354
|
+
booked,
|
|
355
|
+
...leftover ? { leftover } : {}
|
|
356
|
+
};
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
/** 清空便签(可信入口专用):删除 open 行,无任何残留。 */
|
|
360
|
+
clearDraft(context) {
|
|
361
|
+
assertMutationContext(context);
|
|
362
|
+
this.options.store.transaction(() => {
|
|
363
|
+
const row = this.requireOpenDraftRow(context.subjectId);
|
|
364
|
+
this.options.store.recordDraftEvent({
|
|
365
|
+
kind: "finance_draft_cleared",
|
|
366
|
+
subjectId: row.subjectId,
|
|
367
|
+
domainReference: row.id,
|
|
368
|
+
correlationId: context.callId,
|
|
369
|
+
idempotencyKey: `finance-draft-clear:${row.id}:${context.callId}`,
|
|
370
|
+
now: this.now()
|
|
371
|
+
});
|
|
372
|
+
this.options.store.deleteDraftRow(row.id);
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
requireOpenDraftRow(subjectId) {
|
|
376
|
+
const row = this.options.store.getOpenDraftRow(subjectId);
|
|
377
|
+
if (!row) throw new Error("finance_draft_not_found");
|
|
378
|
+
this.requireGrant(row.subjectId, row.bookId, row.grantId);
|
|
379
|
+
return row;
|
|
380
|
+
}
|
|
381
|
+
prepareDraftEntries(entries, bookId, includeEntryIndex = false) {
|
|
382
|
+
const metadata = financeBookMetadata(this.options.ledger.cachedMetadata(bookId));
|
|
383
|
+
const issues = [];
|
|
384
|
+
const prepared = entries.map((entry, entryIndex) => {
|
|
385
|
+
const remoteId = entry.draft?.remoteId;
|
|
386
|
+
try {
|
|
387
|
+
return prepareDraftEntry(entry, metadata, remoteId ? this.options.ledger.getTransaction(bookId, remoteId) : void 0);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
if (!(error instanceof FinanceDraftFieldError)) throw error;
|
|
390
|
+
issues.push(...error.issues.map((issue) => includeEntryIndex ? {
|
|
391
|
+
...issue,
|
|
392
|
+
entryIndex
|
|
393
|
+
} : issue));
|
|
394
|
+
return entry;
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
if (issues.length) throw new FinanceDraftFieldError(issues);
|
|
398
|
+
assertDraftProposalsValid(prepared, metadata, bookId, this.options.ledger);
|
|
399
|
+
return prepared;
|
|
400
|
+
}
|
|
401
|
+
analyzeDraftEntries(entries, bookId) {
|
|
402
|
+
const metadata = financeBookMetadata(this.options.ledger.cachedMetadata(bookId));
|
|
403
|
+
return entries.map((entry) => {
|
|
404
|
+
const current = entry.draft?.remoteId ? this.options.ledger.getTransaction(bookId, entry.draft.remoteId) : void 0;
|
|
405
|
+
try {
|
|
406
|
+
const prepared = prepareDraftEntry(entry, metadata, current);
|
|
407
|
+
const validationProposal = prepared.proposal ?? (prepared.draft?.operation === "matched" ? projectDraftEntry({
|
|
408
|
+
...prepared,
|
|
409
|
+
draft: {
|
|
410
|
+
operation: "create",
|
|
411
|
+
fields: draftFields(prepared)
|
|
412
|
+
}
|
|
413
|
+
}).proposal : void 0);
|
|
414
|
+
return {
|
|
415
|
+
...prepared,
|
|
416
|
+
validationIssues: validationProposal ? proposalValidation(entry.id, validationProposal, metadata, current).issues : []
|
|
417
|
+
};
|
|
418
|
+
} catch (error) {
|
|
419
|
+
if (!(error instanceof FinanceDraftFieldError)) throw error;
|
|
420
|
+
return {
|
|
421
|
+
...projectDraftEntry(entry),
|
|
422
|
+
validationIssues: error.issues.map((issue) => ({
|
|
423
|
+
entryId: entry.id,
|
|
424
|
+
code: "draft_fields_invalid",
|
|
425
|
+
field: issue.field,
|
|
426
|
+
message: issue.message
|
|
427
|
+
}))
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
draftView(row) {
|
|
433
|
+
const metadata = financeBookMetadata(this.options.ledger.cachedMetadata(row.bookId));
|
|
434
|
+
const entries = enrichDraftEntries(this.analyzeDraftEntries(row.entries, row.bookId), row.bookId, this.options.ledger);
|
|
435
|
+
return {
|
|
436
|
+
row: {
|
|
437
|
+
...row,
|
|
438
|
+
entries,
|
|
439
|
+
referenceData: draftReferenceData(metadata)
|
|
440
|
+
},
|
|
441
|
+
validation: {
|
|
442
|
+
valid: entries.every((entry) => !entry.validationIssues?.length),
|
|
443
|
+
issues: entries.flatMap((entry) => entry.validationIssues ?? [])
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
createWorkset(context, input) {
|
|
448
|
+
assertMutationContext(context);
|
|
449
|
+
this.requireGrantedBook(context.subjectId, input.bookId);
|
|
450
|
+
return this.idempotent(context, "finance.worksets.create", input.bookId, () => this.options.store.createWorkset({
|
|
451
|
+
id: this.id(),
|
|
452
|
+
bookId: input.bookId,
|
|
453
|
+
...input.title ? { title: input.title } : {},
|
|
454
|
+
...input.description ? { description: input.description } : {},
|
|
455
|
+
...input.source !== void 0 ? { source: validateSourceReference(input.source) } : {},
|
|
456
|
+
createdBySubjectId: context.subjectId,
|
|
457
|
+
createdAt: this.now()
|
|
458
|
+
}));
|
|
459
|
+
}
|
|
460
|
+
describeWorksetsForSubject(subject, input) {
|
|
461
|
+
const summaries = this.options.store.describeWorksets?.(input.bookId, input.worksetId);
|
|
462
|
+
if (!summaries) throw new Error("finance_workset_summary_unavailable");
|
|
463
|
+
if (input.bookId) this.requireSubjectBook(subject, input.bookId);
|
|
464
|
+
for (const summary of summaries) this.requireSubjectBook(subject, summary.bookId);
|
|
465
|
+
if (input.worksetId && !summaries.length) throw new Error("finance_workset_not_found");
|
|
466
|
+
return summaries;
|
|
467
|
+
}
|
|
468
|
+
listWorksetsForSubject(subject, bookId) {
|
|
469
|
+
this.requireSubjectBook(subject, bookId);
|
|
470
|
+
return this.options.store.listWorksets(bookId);
|
|
471
|
+
}
|
|
472
|
+
getWorksetForSubject(subject, worksetId) {
|
|
473
|
+
const workset = this.options.store.getWorkset(worksetId);
|
|
474
|
+
if (!workset) throw new Error("finance_workset_not_found");
|
|
475
|
+
this.requireSubjectBook(subject, workset.bookId);
|
|
476
|
+
return workset;
|
|
477
|
+
}
|
|
478
|
+
getWorkset(worksetId) {
|
|
479
|
+
const workset = this.options.store.getWorkset(worksetId);
|
|
480
|
+
if (!workset) throw new Error("finance_workset_not_found");
|
|
481
|
+
return workset;
|
|
482
|
+
}
|
|
483
|
+
getWorksetView(worksetId, options = {}) {
|
|
484
|
+
const workset = this.getWorkset(worksetId);
|
|
485
|
+
const ledgerState = this.options.ledger.ledgerBookState?.(workset.bookId);
|
|
486
|
+
const bookMetadata = financeBookMetadata(this.options.ledger.cachedMetadata(workset.bookId));
|
|
487
|
+
const metadata = objectRecord(bookMetadata);
|
|
488
|
+
const referenceData = draftReferenceData(bookMetadata);
|
|
489
|
+
const changed = workset.entries.filter((entry) => entry.state === "changed");
|
|
490
|
+
const stagedEntries = workset.entries.filter((entry) => entry.state === "staged" || entry.state === "commit_locked" || entry.state === "readback_pending" || entry.state === "unknown");
|
|
491
|
+
const requestedLimit = options.entryLimit;
|
|
492
|
+
const partial = requestedLimit !== void 0 && (changed.length > requestedLimit || stagedEntries.length > requestedLimit);
|
|
493
|
+
const visibleIds = requestedLimit === void 0 ? void 0 : new Set([...changed.slice(0, requestedLimit), ...stagedEntries.slice(0, requestedLimit)].map((entry) => entry.id));
|
|
494
|
+
const visibleEntries = visibleIds ? workset.entries.filter((entry) => visibleIds.has(entry.id)) : workset.entries;
|
|
495
|
+
const approvedTimes = /* @__PURE__ */ new Map();
|
|
496
|
+
for (const id of new Set(visibleEntries.flatMap((entry) => entry.lockedCommitId ? [entry.lockedCommitId] : []))) {
|
|
497
|
+
const commit = this.options.store.getCommit(id);
|
|
498
|
+
if (!commit?.recovery?.approvedAt || commit.endedAt) continue;
|
|
499
|
+
for (const correction of commit.recovery.corrections.filter((item) => item.mode === "unsent")) {
|
|
500
|
+
const operation = commit.operations.find((item) => item.id === correction.operationId);
|
|
501
|
+
if (operation) approvedTimes.set(operation.entryId, correction.occurredAt);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
const staged = workset.entries.filter((entry) => entry.state === "staged" && !entry.lockedCommitId).sort(compareCommitEntries);
|
|
505
|
+
const operations = (partial ? [] : staged).flatMap((entry, sequence) => {
|
|
506
|
+
const current = entry.proposal.operation === "create" ? void 0 : this.options.ledger.getTransaction(entry.bookId, entry.proposal.remoteId);
|
|
507
|
+
try {
|
|
508
|
+
return [freezeOperation("workset-preview", `preview:${entry.id}`, sequence, entry.proposal, entry.id, entry.bookId, bookMetadata, current)];
|
|
509
|
+
} catch {
|
|
510
|
+
return [];
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
const entries = visibleEntries.map((entry) => {
|
|
514
|
+
const current = entry.proposal.operation === "create" ? void 0 : this.options.ledger.getTransaction(entry.bookId, entry.proposal.remoteId);
|
|
515
|
+
const occurredAt = approvedTimes.get(entry.id);
|
|
516
|
+
const proposal = occurredAt && entry.proposal.operation === "create" ? {
|
|
517
|
+
...entry.proposal,
|
|
518
|
+
transaction: {
|
|
519
|
+
...entry.proposal.transaction,
|
|
520
|
+
occurredAt
|
|
521
|
+
}
|
|
522
|
+
} : occurredAt && entry.proposal.operation === "update" ? {
|
|
523
|
+
...entry.proposal,
|
|
524
|
+
patch: {
|
|
525
|
+
...entry.proposal.patch,
|
|
526
|
+
occurredAt
|
|
527
|
+
}
|
|
528
|
+
} : entry.proposal;
|
|
529
|
+
return entryPresentation({
|
|
530
|
+
...entry,
|
|
531
|
+
proposal
|
|
532
|
+
}, current, metadata);
|
|
533
|
+
});
|
|
534
|
+
const balancePreview = partial ? void 0 : operations.length === 0 ? {
|
|
535
|
+
asOf: calendarDateInTimeZone(this.now(), ledgerState?.timezone ?? "Asia/Shanghai"),
|
|
536
|
+
calculationComplete: staged.length === 0,
|
|
537
|
+
accounts: []
|
|
538
|
+
} : this.worksetBalancePreview(workset.bookId, operations, bookMetadata, operations.length === staged.length, ledgerState);
|
|
539
|
+
return {
|
|
540
|
+
...workset,
|
|
541
|
+
entries: visibleEntries,
|
|
542
|
+
presentation: {
|
|
543
|
+
entries,
|
|
544
|
+
referenceData,
|
|
545
|
+
validation: entryCategoryValidation(visibleEntries, entries, bookMetadata),
|
|
546
|
+
stagedAccountImpacts: calculateAccountImpacts(operations, metadata),
|
|
547
|
+
...balancePreview ? { balancePreview } : {},
|
|
548
|
+
...requestedLimit !== void 0 ? { window: {
|
|
549
|
+
complete: !partial,
|
|
550
|
+
changedCount: changed.length,
|
|
551
|
+
stagedCount: stagedEntries.length,
|
|
552
|
+
loadedChangedCount: visibleEntries.filter((entry) => entry.state === "changed").length,
|
|
553
|
+
loadedStagedCount: visibleEntries.filter((entry) => entry.state !== "changed").length
|
|
554
|
+
} } : {}
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
worksetBalancePreview(bookId, operations, metadata, calculationComplete, state) {
|
|
559
|
+
const asOf = calendarDateInTimeZone(this.now(), state?.timezone ?? "Asia/Shanghai");
|
|
560
|
+
let snapshot;
|
|
561
|
+
try {
|
|
562
|
+
snapshot = objectRecord(this.options.ledger.accountSnapshot(bookId, asOf));
|
|
563
|
+
} catch {}
|
|
564
|
+
const observedAt = typeof snapshot?.observedAt === "string" ? snapshot.observedAt : state?.lastStableObservedAt;
|
|
565
|
+
const consistent = !state || this.options.ledger.ledgerBookState(bookId).revision === state.revision;
|
|
566
|
+
return buildBalancePreview({
|
|
567
|
+
operations,
|
|
568
|
+
metadata: objectRecord(metadata),
|
|
569
|
+
snapshot,
|
|
570
|
+
asOf,
|
|
571
|
+
observedAt,
|
|
572
|
+
ledgerRevision: state?.revision,
|
|
573
|
+
calculationComplete,
|
|
574
|
+
consistent
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
listAllWorksets(bookId) {
|
|
578
|
+
return this.options.store.listWorksets(bookId);
|
|
579
|
+
}
|
|
580
|
+
listCommits(worksetId) {
|
|
581
|
+
const commits = this.options.store.listCommits();
|
|
582
|
+
return worksetId ? commits.filter((commit) => commit.worksetId === worksetId) : commits;
|
|
583
|
+
}
|
|
584
|
+
searchEntriesForSubject(subject, input) {
|
|
585
|
+
this.requireSubjectBook(subject, input.bookId);
|
|
586
|
+
const state = this.options.ledger.ledgerBookState(input.bookId);
|
|
587
|
+
const result = this.options.store.searchEntries(input, {
|
|
588
|
+
ledgerRevision: state.revision,
|
|
589
|
+
timezone: state.timezone,
|
|
590
|
+
facts: (entry) => this.entryWithFacts(entry).facts
|
|
591
|
+
});
|
|
592
|
+
if (this.options.ledger.ledgerBookState(input.bookId).revision !== state.revision) throw new Error("finance_transaction_revision_changed");
|
|
593
|
+
return result;
|
|
594
|
+
}
|
|
595
|
+
entryWithFacts(entry) {
|
|
596
|
+
const proposal = entry.proposal;
|
|
597
|
+
if (proposal.operation === "create") return {
|
|
598
|
+
...entry,
|
|
599
|
+
facts: { ...proposal.transaction }
|
|
600
|
+
};
|
|
601
|
+
const { rawSource: _raw, contentHash: _hash, ...facts } = this.options.ledger.getTransaction(entry.bookId, proposal.remoteId) ?? {};
|
|
602
|
+
return {
|
|
603
|
+
...entry,
|
|
604
|
+
facts: {
|
|
605
|
+
...facts,
|
|
606
|
+
...proposal.operation === "update" ? proposal.patch : {}
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
getEntryForSubject(subject, bookId, entryId) {
|
|
611
|
+
this.requireSubjectBook(subject, bookId);
|
|
612
|
+
const entry = this.options.store.getEntry(bookId, entryId);
|
|
613
|
+
if (!entry) throw new Error("finance_entry_not_found");
|
|
614
|
+
return entry;
|
|
615
|
+
}
|
|
616
|
+
requireSubjectBook(subject, bookId) {
|
|
617
|
+
this.requireGrantedBook(subject.subjectId, bookId);
|
|
618
|
+
}
|
|
619
|
+
addEntry(context, input) {
|
|
620
|
+
assertMutationContext(context);
|
|
621
|
+
this.requireGrantedBook(context.subjectId, input.bookId);
|
|
622
|
+
const proposal = validateProposal(input.proposal);
|
|
623
|
+
const current = proposal.operation !== "create" ? this.options.ledger.getTransaction(input.bookId, proposal.remoteId) : void 0;
|
|
624
|
+
assertProposalValid(proposal, financeBookMetadata(this.options.ledger.cachedMetadata(input.bookId)), current);
|
|
625
|
+
return this.idempotent(context, "finance.entries.add", input.bookId, () => this.options.store.addEntry({
|
|
626
|
+
id: this.id(),
|
|
627
|
+
worksetId: input.worksetId,
|
|
628
|
+
bookId: input.bookId,
|
|
629
|
+
expectedVersion: input.expectedVersion,
|
|
630
|
+
proposal,
|
|
631
|
+
evidence: evidenceFor(context, input.evidence, this.now()),
|
|
632
|
+
subjectId: context.subjectId,
|
|
633
|
+
now: this.now()
|
|
634
|
+
}));
|
|
635
|
+
}
|
|
636
|
+
updateEntry(context, input) {
|
|
637
|
+
assertMutationContext(context);
|
|
638
|
+
this.requireGrantedBook(context.subjectId, input.bookId);
|
|
639
|
+
const proposal = validateProposal(input.proposal);
|
|
640
|
+
const current = proposal.operation !== "create" ? this.options.ledger.getTransaction(input.bookId, proposal.remoteId) : void 0;
|
|
641
|
+
assertProposalValid(proposal, financeBookMetadata(this.options.ledger.cachedMetadata(input.bookId)), current);
|
|
642
|
+
return this.idempotent(context, "finance.entries.update", input.bookId, () => this.options.store.updateEntry({
|
|
643
|
+
entryId: input.entryId,
|
|
644
|
+
bookId: input.bookId,
|
|
645
|
+
expectedVersion: input.expectedVersion,
|
|
646
|
+
proposal,
|
|
647
|
+
evidence: evidenceFor(context, input.evidence, this.now()),
|
|
648
|
+
subjectId: context.subjectId,
|
|
649
|
+
now: this.now()
|
|
650
|
+
}));
|
|
651
|
+
}
|
|
652
|
+
removeEntry(context, input) {
|
|
653
|
+
assertMutationContext(context);
|
|
654
|
+
this.requireGrantedBook(context.subjectId, input.bookId);
|
|
655
|
+
return this.idempotent(context, "finance.entries.remove", input.bookId, () => this.options.store.removeEntry({
|
|
656
|
+
...input,
|
|
657
|
+
subjectId: context.subjectId,
|
|
658
|
+
now: this.now()
|
|
659
|
+
}));
|
|
660
|
+
}
|
|
661
|
+
async readSourceForSubject(subjectId, input) {
|
|
662
|
+
if (!this.options.sourceReader?.readForSubject) throw new Error("finance_source_reader_unavailable");
|
|
663
|
+
return this.options.sourceReader.readForSubject({
|
|
664
|
+
subjectId,
|
|
665
|
+
...input
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
patchWorkset(worksetId, input) {
|
|
669
|
+
const workset = this.getWorkset(worksetId);
|
|
670
|
+
if (input.expectedReviewVersion !== void 0) {
|
|
671
|
+
if (input.changes.some((change) => change.operation !== "edit" && change.operation !== "remove")) throw new Error("finance_workset_review_scope_invalid");
|
|
672
|
+
if (workset.reviewVersion !== input.expectedReviewVersion) throw new Error("finance_workset_review_version_conflict");
|
|
673
|
+
} else if (workset.version !== input.expectedVersion) throw new Error("finance_workset_version_conflict");
|
|
674
|
+
const metadata = financeBookMetadata(this.options.ledger.cachedMetadata(workset.bookId));
|
|
675
|
+
const changes = input.changes.map((change) => {
|
|
676
|
+
if (change.operation === "edit") {
|
|
677
|
+
const proposal = validateProposal(change.proposal);
|
|
678
|
+
const current = proposal.operation !== "create" ? this.options.ledger.getTransaction(workset.bookId, proposal.remoteId) : void 0;
|
|
679
|
+
assertProposalValid(proposal, metadata, current);
|
|
680
|
+
return {
|
|
681
|
+
...change,
|
|
682
|
+
proposal
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
if (change.operation === "stage") {
|
|
686
|
+
const entry = workset.entries.find((candidate) => candidate.id === change.entryId);
|
|
687
|
+
if (!entry) throw new Error("finance_entry_not_found");
|
|
688
|
+
assertEntryProposalValid(entry, metadata, this.options.ledger);
|
|
689
|
+
}
|
|
690
|
+
return change;
|
|
691
|
+
});
|
|
692
|
+
validateTrustedWorksetMutationScope(workset, changes, (entry) => {
|
|
693
|
+
if (entry.proposal.operation === "create") return entry.proposal.transaction.accountId;
|
|
694
|
+
if (entry.proposal.operation === "update" && typeof entry.proposal.patch.accountId === "string") return entry.proposal.patch.accountId;
|
|
695
|
+
return this.options.ledger.getTransaction(entry.bookId, entry.proposal.remoteId)?.accountId;
|
|
696
|
+
});
|
|
697
|
+
return this.options.store.patchWorkset(worksetId, input.expectedVersion, changes, this.now(), input.expectedReviewVersion);
|
|
698
|
+
}
|
|
699
|
+
async prepareCommit(worksetId, input) {
|
|
700
|
+
this.assertRemoteWritesEnabled();
|
|
701
|
+
const workset = this.getWorkset(worksetId);
|
|
702
|
+
const operation = {
|
|
703
|
+
id: this.id(),
|
|
704
|
+
kind: "prepare",
|
|
705
|
+
scopeId: worksetId,
|
|
706
|
+
bookId: workset.bookId,
|
|
707
|
+
status: "running",
|
|
708
|
+
startedAt: this.now(),
|
|
709
|
+
progress: { stage: "queued" }
|
|
710
|
+
};
|
|
711
|
+
this.options.store.createReadOperation(operation);
|
|
712
|
+
try {
|
|
713
|
+
const commit = await this.prepareCommitInsideOperation(worksetId, input, this.readAttempt(operation), operation.id);
|
|
714
|
+
Object.assign(operation, {
|
|
715
|
+
status: "succeeded",
|
|
716
|
+
commitId: commit.id,
|
|
717
|
+
completedAt: this.now()
|
|
718
|
+
});
|
|
719
|
+
this.options.store.saveReadOperation(operation);
|
|
720
|
+
await this.options.ensureCommitConfirmation?.(commit);
|
|
721
|
+
return commit;
|
|
722
|
+
} catch (error) {
|
|
723
|
+
if (operation.status === "succeeded") throw error;
|
|
724
|
+
const failure = commitFailure(error, "checking", "not_sent", { progress: operation.progress });
|
|
725
|
+
Object.assign(operation, {
|
|
726
|
+
status: "failed",
|
|
727
|
+
failure,
|
|
728
|
+
completedAt: this.now()
|
|
729
|
+
});
|
|
730
|
+
this.options.store.saveReadOperation(operation);
|
|
731
|
+
if (error instanceof Error && /^finance_[a-z_]+$/.test(error.message)) throw error;
|
|
732
|
+
throw new FinanceCheckError(failure);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
getPreparation(worksetId) {
|
|
736
|
+
this.getWorkset(worksetId);
|
|
737
|
+
return this.options.store.listReadOperations("prepare", worksetId)[0] ?? null;
|
|
738
|
+
}
|
|
739
|
+
getSyncOperation(bookId, operationId) {
|
|
740
|
+
const operation = this.options.store.listReadOperations("sync", "ledger").find((item) => item.bookId === bookId && (!operationId || item.id === operationId));
|
|
741
|
+
if (!operation?.mode) return null;
|
|
742
|
+
const progress = sanitizeLedgerSyncProgress(operation.progress);
|
|
743
|
+
return {
|
|
744
|
+
operationId: operation.id,
|
|
745
|
+
bookId,
|
|
746
|
+
mode: operation.mode,
|
|
747
|
+
status: operation.status,
|
|
748
|
+
startedAt: operation.startedAt,
|
|
749
|
+
...progress ? { progress } : {},
|
|
750
|
+
...operation.progressSequence !== void 0 ? { progressSequence: operation.progressSequence } : {},
|
|
751
|
+
...operation.completedAt ? { completedAt: operation.completedAt } : {},
|
|
752
|
+
...operation.result ? { result: operation.result } : {},
|
|
753
|
+
...operation.failure ? { error: {
|
|
754
|
+
status: 502,
|
|
755
|
+
code: operation.failure.code,
|
|
756
|
+
message: syncFailureMessage(operation.failure.message, {
|
|
757
|
+
...operation.progress,
|
|
758
|
+
...operation.failure.month ? { month: operation.failure.month } : {}
|
|
759
|
+
})
|
|
760
|
+
} } : {}
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
async syncBook(input) {
|
|
764
|
+
const previous = this.options.store.listReadOperations("sync").find((item) => item.id === input.operationId);
|
|
765
|
+
if (previous) {
|
|
766
|
+
if (previous.bookId !== input.bookId || previous.mode !== input.mode) throw new Error("finance_sync_operation_conflict");
|
|
767
|
+
return this.getSyncOperation(input.bookId, input.operationId);
|
|
768
|
+
}
|
|
769
|
+
const operation = {
|
|
770
|
+
id: input.operationId,
|
|
771
|
+
kind: "sync",
|
|
772
|
+
scopeId: "ledger",
|
|
773
|
+
bookId: input.bookId,
|
|
774
|
+
mode: input.mode,
|
|
775
|
+
status: "running",
|
|
776
|
+
startedAt: this.now(),
|
|
777
|
+
progress: { stage: "queued" }
|
|
778
|
+
};
|
|
779
|
+
this.options.store.createReadOperation(operation);
|
|
780
|
+
try {
|
|
781
|
+
const result = await this.options.ledger.sync({
|
|
782
|
+
mode: input.mode,
|
|
783
|
+
bookIds: [input.bookId]
|
|
784
|
+
}, this.readAttempt(operation));
|
|
785
|
+
if (result.books !== 1) throw new FeideeError("Remote book access is unavailable", "BOOK_ACCESS_DENIED");
|
|
786
|
+
Object.assign(operation, {
|
|
787
|
+
status: "succeeded",
|
|
788
|
+
result,
|
|
789
|
+
completedAt: this.now()
|
|
790
|
+
});
|
|
791
|
+
} catch (error) {
|
|
792
|
+
Object.assign(operation, {
|
|
793
|
+
status: "failed",
|
|
794
|
+
completedAt: this.now(),
|
|
795
|
+
failure: commitFailure(error, "checking", "not_sent", { progress: operation.progress })
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
this.options.store.saveReadOperation(operation);
|
|
799
|
+
return this.getSyncOperation(input.bookId, input.operationId);
|
|
800
|
+
}
|
|
801
|
+
readAttempt(operation) {
|
|
802
|
+
return {
|
|
803
|
+
autoLoginUsed: false,
|
|
804
|
+
onProgress: (progress) => {
|
|
805
|
+
operation.progress = progress;
|
|
806
|
+
operation.progressSequence = (operation.progressSequence ?? 0) + 1;
|
|
807
|
+
this.options.store.saveReadOperation(operation);
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
async prepareCommitInsideOperation(worksetId, input, attempt, preparationId) {
|
|
812
|
+
const workset = this.getWorkset(worksetId);
|
|
813
|
+
if (workset.version !== input.expectedVersion) throw new Error("finance_workset_version_conflict");
|
|
814
|
+
const requestedIds = workset.entries.filter((entry) => entry.state === "staged" && !entry.lockedCommitId).map((entry) => entry.id);
|
|
815
|
+
const selected = requestedIds.map((id) => {
|
|
816
|
+
const entry = workset.entries.find((candidate) => candidate.id === id);
|
|
817
|
+
if (!entry) throw new Error("finance_entry_not_found");
|
|
818
|
+
if (entry.state !== "staged" || entry.lockedCommitId) throw new Error("finance_commit_entry_not_available");
|
|
819
|
+
return entry;
|
|
820
|
+
}).sort(compareCommitEntries);
|
|
821
|
+
if (!selected.length || new Set(requestedIds).size !== requestedIds.length) throw new Error("finance_commit_entries_invalid");
|
|
822
|
+
const metadata = financeBookMetadata(this.options.ledger.cachedMetadata(workset.bookId));
|
|
823
|
+
for (const entry of selected) {
|
|
824
|
+
assertEntryProposalValid(entry, metadata, this.options.ledger);
|
|
825
|
+
const current = entry.proposal.operation === "update" ? this.options.ledger.getTransaction(entry.bookId, entry.proposal.remoteId) : void 0;
|
|
826
|
+
const target = proposalFinancialPayload(entry.proposal, current);
|
|
827
|
+
if (target) assertMemoPolicy(target.memo);
|
|
828
|
+
}
|
|
829
|
+
const remoteIds = selected.flatMap((entry) => entry.proposal.operation === "create" ? [] : [entry.proposal.remoteId]);
|
|
830
|
+
const readScope = [...new Map(selected.flatMap((entry) => {
|
|
831
|
+
const proposal = entry.proposal;
|
|
832
|
+
const before = proposal.operation === "create" ? void 0 : this.options.ledger.getTransaction(entry.bookId, proposal.remoteId);
|
|
833
|
+
if (proposal.operation !== "create" && !before) throw new Error("finance_commit_remote_transaction_changed");
|
|
834
|
+
const after = proposal.operation === "create" ? proposal.transaction.occurredAt : proposal.operation === "update" ? proposal.patch.occurredAt : void 0;
|
|
835
|
+
return [before?.occurredAt, after].filter((date) => Boolean(date)).map((date) => financialMonthRange(date));
|
|
836
|
+
}).map((range) => [range.beginDate, range])).values()].sort((a, b) => a.beginDate.localeCompare(b.beginDate));
|
|
837
|
+
const localTransactions = new Map(remoteIds.map((id) => [id, this.options.ledger.getTransaction(workset.bookId, id)]));
|
|
838
|
+
const commitId = this.id();
|
|
839
|
+
const operations = [];
|
|
840
|
+
for (const [sequence, entry] of selected.entries()) {
|
|
841
|
+
const operationId = this.id();
|
|
842
|
+
const current = entry.proposal.operation === "create" ? void 0 : localTransactions.get(entry.proposal.remoteId);
|
|
843
|
+
const frozen = freezeOperation(commitId, operationId, sequence, entry.proposal, entry.id, entry.bookId, metadata, current);
|
|
844
|
+
operations.push(frozen);
|
|
845
|
+
}
|
|
846
|
+
const unresolved = this.options.store.listCommits().flatMap((item) => item.operations).filter((operation) => operation.status === "unknown" || operation.status === "readback_pending");
|
|
847
|
+
if (operations.some((operation) => unresolved.some((other) => operationsOverlap(operation, other)))) throw new Error("finance_commit_unknown_dependency");
|
|
848
|
+
const operationsHash = sha256(stableStringify(operations.map((operation) => ({
|
|
849
|
+
entryId: operation.entryId,
|
|
850
|
+
sequence: operation.sequence,
|
|
851
|
+
operation: operation.operation,
|
|
852
|
+
bookId: operation.bookId,
|
|
853
|
+
targetRemoteId: operation.targetRemoteId ?? null,
|
|
854
|
+
request: operation.request,
|
|
855
|
+
before: operation.before ?? null
|
|
856
|
+
}))));
|
|
857
|
+
const ledgerState = this.options.ledger.ledgerBookState(workset.bookId);
|
|
858
|
+
attempt.onProgress?.({ stage: "balances" });
|
|
859
|
+
if (input.expectedLedgerRevision !== void 0 && input.expectedLedgerRevision !== ledgerState.revision) throw new Error("finance_ledger_revision_conflict");
|
|
860
|
+
const metadataRecord = objectRecord(metadata);
|
|
861
|
+
const accountImpacts = calculateAccountImpacts(operations, metadataRecord);
|
|
862
|
+
const activeCheckpoints = this.options.ledger.activeCheckpoints(workset.bookId);
|
|
863
|
+
const checkpointImpacts = activeCheckpoints.map((checkpoint) => {
|
|
864
|
+
const cumulativeDeviationCents = checkpointBalance(this.options.ledger, checkpoint) - checkpoint.balanceCents;
|
|
865
|
+
const commitDeltaCents = checkpointDelta(operations, metadataRecord, checkpoint);
|
|
866
|
+
const projectedDeviationCents = cumulativeDeviationCents + commitDeltaCents;
|
|
867
|
+
return {
|
|
868
|
+
checkpointId: checkpoint.id,
|
|
869
|
+
checkpointRevision: checkpoint.revision,
|
|
870
|
+
accountId: checkpoint.accountId,
|
|
871
|
+
currency: checkpoint.currency,
|
|
872
|
+
baselineBalanceCents: checkpoint.balanceCents,
|
|
873
|
+
cumulativeDeviationCents,
|
|
874
|
+
commitDeltaCents,
|
|
875
|
+
projectedDeviationCents,
|
|
876
|
+
overrideRequired: projectedDeviationCents !== 0
|
|
877
|
+
};
|
|
878
|
+
});
|
|
879
|
+
return this.options.store.createCommit({
|
|
880
|
+
id: commitId,
|
|
881
|
+
worksetId,
|
|
882
|
+
worksetVersion: this.getWorkset(worksetId).version,
|
|
883
|
+
status: "awaiting_confirmation",
|
|
884
|
+
autoLoginUsed: attempt.autoLoginUsed,
|
|
885
|
+
operationsHash,
|
|
886
|
+
ledgerRevision: ledgerState.revision,
|
|
887
|
+
checkpointRevision: activeCheckpoints.reduce((highest, checkpoint) => Math.max(highest, checkpoint.revision), 0),
|
|
888
|
+
accountImpacts,
|
|
889
|
+
checkpointImpacts,
|
|
890
|
+
readScope,
|
|
891
|
+
operations,
|
|
892
|
+
createdAt: this.now()
|
|
893
|
+
}, preparationId);
|
|
894
|
+
}
|
|
895
|
+
getCommit(commitId) {
|
|
896
|
+
const commit = this.options.store.getCommit(commitId);
|
|
897
|
+
if (!commit) throw new Error("finance_commit_not_found");
|
|
898
|
+
return commit;
|
|
899
|
+
}
|
|
900
|
+
async ensureCommitConfirmation(commitId) {
|
|
901
|
+
let commit = this.getCommit(commitId);
|
|
902
|
+
if (commit.status === "prepared") commit = this.options.store.setCommitStatus(commit.id, "awaiting_confirmation", {}, this.now());
|
|
903
|
+
if (commit.status === "awaiting_confirmation") await this.options.ensureCommitConfirmation?.(commit);
|
|
904
|
+
}
|
|
905
|
+
sessionStatus() {
|
|
906
|
+
if (!this.options.ledger.sessionStatus) throw new Error("finance_session_unavailable");
|
|
907
|
+
return this.options.ledger.sessionStatus();
|
|
908
|
+
}
|
|
909
|
+
checkSession() {
|
|
910
|
+
if (!this.options.ledger.checkSession) throw new Error("finance_session_unavailable");
|
|
911
|
+
return this.options.ledger.checkSession();
|
|
912
|
+
}
|
|
913
|
+
loginSession(credential) {
|
|
914
|
+
if (!this.options.ledger.loginSession) throw new Error("finance_session_unavailable");
|
|
915
|
+
return this.options.ledger.loginSession(credential);
|
|
916
|
+
}
|
|
917
|
+
async respondCommit(commitId, decision, overrideCheckpointIds = [], background = false) {
|
|
918
|
+
const commit = this.getCommit(commitId);
|
|
919
|
+
if (commit.status !== "awaiting_confirmation") return commit;
|
|
920
|
+
if (decision === "cancel") return this.options.store.cancelCommit(commit.id, this.now());
|
|
921
|
+
this.assertRemoteWritesEnabled();
|
|
922
|
+
if (!this.options.store.claimCommit(commitId, this.now())) return this.getCommit(commitId);
|
|
923
|
+
const run = this.runCommit(commit, overrideCheckpointIds, false);
|
|
924
|
+
return background ? this.getCommit(commitId) : run;
|
|
925
|
+
}
|
|
926
|
+
assertRecoveryIdle(commit) {
|
|
927
|
+
if (this.commitRuns.has(commit.id) || this.readbackRuns.has(commit.id) || commit.readback?.status === "running") throw new Error("finance_commit_busy");
|
|
928
|
+
if (commit.endedAt || ![
|
|
929
|
+
"paused",
|
|
930
|
+
"outcome_unknown",
|
|
931
|
+
"awaiting_readback"
|
|
932
|
+
].includes(commit.status)) throw new Error("finance_commit_not_resumable");
|
|
933
|
+
}
|
|
934
|
+
assertRecoveryReceipts(commit, recovery) {
|
|
935
|
+
if (!this.options.ledger.hasMutationReceipt) throw new Error("finance_recovery_receipt_unavailable");
|
|
936
|
+
const claimedRemoteIds = new Set(commit.operations.filter(operationIsVerified).flatMap((operation) => typeof operation.result?.remoteId === "string" ? [operation.result.remoteId] : operation.targetRemoteId ? [operation.targetRemoteId] : []));
|
|
937
|
+
for (const correction of recovery.corrections) {
|
|
938
|
+
const operation = commit.operations.find((item) => item.id === correction.operationId);
|
|
939
|
+
if (!operation || recoveryHash(operation.request) !== correction.originalRequestHash) throw new Error("finance_recovery_request_changed");
|
|
940
|
+
const hasReceipt = this.options.ledger.hasMutationReceipt(operation.bookId, verificationInput(operation));
|
|
941
|
+
if (correction.mode === "unsent") {
|
|
942
|
+
const revised = effectiveRecoveryOperation({
|
|
943
|
+
...commit,
|
|
944
|
+
recovery: {
|
|
945
|
+
...recovery,
|
|
946
|
+
approvedAt: this.now()
|
|
947
|
+
}
|
|
948
|
+
}, operation);
|
|
949
|
+
if (!operationCanContinue(operation) || operation.startedAt || hasReceipt || this.options.ledger.hasMutationReceipt(operation.bookId, verificationInput(revised))) throw new Error("finance_recovery_already_sent");
|
|
950
|
+
} else if (!hasReceipt || !["unknown", "readback_pending"].includes(operation.status)) throw new Error("finance_recovery_receipt_unavailable");
|
|
951
|
+
if (correction.mode === "external") {
|
|
952
|
+
if (!correction.remoteId || claimedRemoteIds.has(correction.remoteId)) throw new Error("finance_recovery_identity_conflict");
|
|
953
|
+
claimedRemoteIds.add(correction.remoteId);
|
|
954
|
+
}
|
|
955
|
+
const before = Date.parse(correction.originalOccurredAt);
|
|
956
|
+
const after = Date.parse(correction.occurredAt);
|
|
957
|
+
if (this.options.ledger.activeCheckpoints(operation.bookId).some((checkpoint) => Date.parse(checkpointThrough(checkpoint)) >= Math.min(before, after) && Date.parse(checkpointThrough(checkpoint)) < Math.max(before, after))) throw new Error("finance_commit_checkpoint_changed");
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
confirmCommitRecovery(commitId, operationsHash, hash, confirmedRemoteIds) {
|
|
961
|
+
const commit = this.getCommit(commitId);
|
|
962
|
+
this.assertRecoveryIdle(commit);
|
|
963
|
+
const recovery = commit.recovery;
|
|
964
|
+
if (!recovery || recovery.hash !== hash || commit.operationsHash !== operationsHash) throw new Error("finance_recovery_approval_changed");
|
|
965
|
+
const expectedIds = recovery.corrections.filter((item) => item.mode === "external").map((item) => item.remoteId).sort();
|
|
966
|
+
if (JSON.stringify([...confirmedRemoteIds].sort()) !== JSON.stringify(expectedIds)) throw new Error("finance_recovery_identity_required");
|
|
967
|
+
if (recovery.approvedAt) return commit;
|
|
968
|
+
this.assertRecoveryReceipts(commit, recovery);
|
|
969
|
+
this.options.store.appendRecoveryEvent(commitId, "approval", {
|
|
970
|
+
kind: "approved",
|
|
971
|
+
hash,
|
|
972
|
+
authority: "trusted-ui",
|
|
973
|
+
at: this.now()
|
|
974
|
+
});
|
|
975
|
+
return this.getCommit(commitId);
|
|
976
|
+
}
|
|
977
|
+
/** Offline maintenance only. No HTTP route or Agent capability exposes this operation. */
|
|
978
|
+
replaceDeletedCreation(input) {
|
|
979
|
+
const commit = this.getCommit(input.commitId);
|
|
980
|
+
if (commit.operationsHash !== input.operationsHash || !input.authorityReference.trim()) throw new Error("finance_recovery_request_changed");
|
|
981
|
+
if (this.options.store.recoveryEvents(commit.id).find((event) => event.kind === "creation_replaced" && event.previousHash === input.recoveryHash && event.deletedRemoteId === input.deletedRemoteId)) return commit;
|
|
982
|
+
this.assertRecoveryIdle(commit);
|
|
983
|
+
const recovery = commit.recovery;
|
|
984
|
+
if (!recovery?.approvedAt || recovery.hash !== input.recoveryHash) throw new Error("finance_recovery_approval_changed");
|
|
985
|
+
this.assertRecoveryReceipts(commit, recovery);
|
|
986
|
+
const correction = recovery.corrections.find((item) => item.mode === "external" && item.remoteId === input.deletedRemoteId);
|
|
987
|
+
const operation = commit.operations.find((item) => item.id === correction?.operationId);
|
|
988
|
+
if (!correction || !operation || operation.operation !== "create") throw new Error("finance_recovery_request_changed");
|
|
989
|
+
const replacementId = `finance-replacement:${commit.id}:${operation.id}:${recoveryHash({
|
|
990
|
+
previous: recovery.hash,
|
|
991
|
+
deleted: input.deletedRemoteId
|
|
992
|
+
}).slice(0, 24)}`;
|
|
993
|
+
if (!this.options.ledger.assertDeletedCreationReplaceable) throw new Error("finance_recovery_receipt_unavailable");
|
|
994
|
+
this.options.ledger.assertDeletedCreationReplaceable(operation.bookId, operation.request, input.deletedRemoteId, replacementId);
|
|
995
|
+
const corrections = recovery.corrections.map((item) => item.operationId === operation.id ? {
|
|
996
|
+
...item,
|
|
997
|
+
mode: "replacement",
|
|
998
|
+
clientRequestId: replacementId
|
|
999
|
+
} : item);
|
|
1000
|
+
const revised = {
|
|
1001
|
+
...recovery,
|
|
1002
|
+
corrections,
|
|
1003
|
+
hash: recoveryHash({
|
|
1004
|
+
previous: recovery.hash,
|
|
1005
|
+
corrections
|
|
1006
|
+
}),
|
|
1007
|
+
approvedAt: this.now(),
|
|
1008
|
+
authority: "trusted-maintenance"
|
|
1009
|
+
};
|
|
1010
|
+
if (!input.apply) return {
|
|
1011
|
+
...commit,
|
|
1012
|
+
recovery: revised
|
|
1013
|
+
};
|
|
1014
|
+
this.options.store.appendRecoveryEvent(commit.id, `replacement:${revised.hash}`, {
|
|
1015
|
+
kind: "creation_replaced",
|
|
1016
|
+
recovery: revised,
|
|
1017
|
+
previousHash: recovery.hash,
|
|
1018
|
+
originalOperation: operation,
|
|
1019
|
+
deletedRemoteId: input.deletedRemoteId,
|
|
1020
|
+
authorityReference: input.authorityReference,
|
|
1021
|
+
at: this.now()
|
|
1022
|
+
});
|
|
1023
|
+
return this.getCommit(commit.id);
|
|
1024
|
+
}
|
|
1025
|
+
resumeCommit(commitId, operationsHash, recoveryApprovalHash) {
|
|
1026
|
+
this.assertRemoteWritesEnabled();
|
|
1027
|
+
const commit = this.getCommit(commitId);
|
|
1028
|
+
if (commit.operationsHash !== operationsHash) throw new Error("finance_commit_operations_changed");
|
|
1029
|
+
if (commit.recovery && (!commit.recovery.approvedAt || commit.recovery.hash !== recoveryApprovalHash)) throw new Error("finance_recovery_approval_required");
|
|
1030
|
+
if (this.commitRuns.has(commitId)) return commit;
|
|
1031
|
+
if (this.readbackRuns.has(commitId) || commit.readback?.status === "running") throw new Error("finance_commit_busy");
|
|
1032
|
+
if (!commitCanResume(commit)) throw new Error("finance_commit_not_resumable");
|
|
1033
|
+
return this.resumeUnchangedCommit(commit, recoveryApprovalHash);
|
|
1034
|
+
}
|
|
1035
|
+
resumeUnchangedCommit(commit, recoveryApprovalHash) {
|
|
1036
|
+
const commitId = commit.id;
|
|
1037
|
+
const operationsHash = commit.operationsHash;
|
|
1038
|
+
const workset = this.getWorkset(commit.worksetId);
|
|
1039
|
+
const metadata = financeBookMetadata(this.options.ledger.cachedMetadata(workset.bookId));
|
|
1040
|
+
for (const operation of commit.operations.filter(operationCanContinue)) {
|
|
1041
|
+
const entry = workset.entries.find((item) => item.id === operation.entryId);
|
|
1042
|
+
if (!entry || !["staged", "commit_locked"].includes(entry.state)) throw new Error("finance_commit_entry_not_available");
|
|
1043
|
+
const frozen = freezeOperation(commit.id, operation.id, operation.sequence, entry.proposal, entry.id, entry.bookId, metadata, operation.before);
|
|
1044
|
+
if (frozen.operation !== operation.operation || frozen.targetRemoteId !== operation.targetRemoteId || stableStringify(frozen.request) !== stableStringify(operation.request)) throw new Error("finance_commit_operations_changed");
|
|
1045
|
+
}
|
|
1046
|
+
if (!this.options.store.claimCommitResume(commitId, operationsHash, workset.version, this.now(), recoveryApprovalHash)) {
|
|
1047
|
+
const current = this.getCommit(commitId);
|
|
1048
|
+
if (["checking", "executing"].includes(current.status)) return current;
|
|
1049
|
+
throw new Error("finance_commit_busy");
|
|
1050
|
+
}
|
|
1051
|
+
this.runCommit(this.getCommit(commitId), commit.overrideCheckpointIds ?? [], true);
|
|
1052
|
+
return this.getCommit(commitId);
|
|
1053
|
+
}
|
|
1054
|
+
async endCommit(commitId, operationsHash) {
|
|
1055
|
+
if (this.getCommit(commitId).operationsHash !== operationsHash) throw new Error("finance_commit_operations_changed");
|
|
1056
|
+
if (this.commitRuns.has(commitId) || this.readbackRuns.has(commitId)) throw new Error("finance_commit_busy");
|
|
1057
|
+
const ended = this.options.store.endPausedCommit(commitId, this.now());
|
|
1058
|
+
await this.options.closeCommitConfirmation?.(ended);
|
|
1059
|
+
return ended;
|
|
1060
|
+
}
|
|
1061
|
+
runCommit(commit, overrides, resuming) {
|
|
1062
|
+
const run = this.executeCommit(commit, overrides, resuming).catch((error) => {
|
|
1063
|
+
const current = this.getCommit(commit.id);
|
|
1064
|
+
if (current.endedAt) return current;
|
|
1065
|
+
return this.options.store.pauseCommit(commit.id, this.now(), this.executionFailure(commit.id, error, current.status === "checking" ? "checking" : "writing", current.status === "checking" ? "not_sent" : "sent_unknown", current.operations.find((operation) => operation.status === "executing")));
|
|
1066
|
+
}).finally(() => {
|
|
1067
|
+
this.commitRuns.delete(commit.id);
|
|
1068
|
+
this.scheduleReadback(commit.id);
|
|
1069
|
+
});
|
|
1070
|
+
this.commitRuns.set(commit.id, run);
|
|
1071
|
+
run.then((result) => this.options.closeCommitConfirmation?.(result)).catch(() => void 0);
|
|
1072
|
+
return run;
|
|
1073
|
+
}
|
|
1074
|
+
commitAttempt(commit) {
|
|
1075
|
+
return {
|
|
1076
|
+
autoLoginUsed: commit.autoLoginUsed ?? false,
|
|
1077
|
+
evidenceScope: commit.id,
|
|
1078
|
+
onAutoLogin: () => this.options.store.consumeCommitAutoLogin(commit.id),
|
|
1079
|
+
onProgress: (progress) => this.options.store.saveCommitProgress(commit.id, progress)
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
executionFailure(commitId, error, phase, boundary, operation) {
|
|
1083
|
+
const progress = this.getCommit(commitId).progress;
|
|
1084
|
+
return commitFailure(error, phase, boundary, {
|
|
1085
|
+
...progress ? { progress } : {},
|
|
1086
|
+
...operation ? { operationSequence: operation.sequence } : {},
|
|
1087
|
+
now: this.now()
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
async executeCommit(commit, overrideCheckpointIds, resuming) {
|
|
1091
|
+
const commitId = commit.id;
|
|
1092
|
+
const attempt = this.commitAttempt(commit);
|
|
1093
|
+
let expectedRevision = commit.ledgerRevision;
|
|
1094
|
+
const completedOperations = commit.operations.filter(operationIsVerified).map((operation) => effectiveRecoveryOperation(commit, operation));
|
|
1095
|
+
let failure;
|
|
1096
|
+
try {
|
|
1097
|
+
if (resuming) {
|
|
1098
|
+
const unresolved = commit.operations.filter((item) => item.status === "unknown" || item.status === "readback_pending");
|
|
1099
|
+
if (unresolved.length) completedOperations.push(...await this.verifyCommitOperations(commitId, unresolved, attempt));
|
|
1100
|
+
if (commit.recovery?.corrections.some((item) => item.mode === "external" && this.getCommit(commitId).operations.find((operation) => operation.id === item.operationId)?.status !== "externally_verified")) throw new Error("finance_recovery_external_unresolved");
|
|
1101
|
+
expectedRevision = this.options.ledger.ledgerBookState(commit.operations[0].bookId).revision;
|
|
1102
|
+
}
|
|
1103
|
+
const bookId = commit.operations[0].bookId;
|
|
1104
|
+
const remaining = this.getCommit(commitId).operations.filter(operationCanContinue).map((operation) => effectiveRecoveryOperation(commit, operation));
|
|
1105
|
+
for (const operation of remaining) if (operation.operation === "create") assertMemoPolicy(operation.request.memo);
|
|
1106
|
+
else if (operation.operation === "update") {
|
|
1107
|
+
if (!operation.before) throw new Error("finance_commit_remote_transaction_changed");
|
|
1108
|
+
assertMemoPolicy(mergeTransactionPatch(operation.before, operation.request.patch).memo);
|
|
1109
|
+
}
|
|
1110
|
+
const readScope = !resuming && commit.readScope ? commit.readScope : [...new Map(remaining.flatMap((operation) => {
|
|
1111
|
+
const patch = objectRecord(operation.request.patch);
|
|
1112
|
+
return [
|
|
1113
|
+
operation.before?.occurredAt,
|
|
1114
|
+
operation.request.occurredAt,
|
|
1115
|
+
patch?.occurredAt
|
|
1116
|
+
].filter((date) => typeof date === "string").map((date) => financialMonthRange(date));
|
|
1117
|
+
}).map((range) => [range.beginDate, range])).values()];
|
|
1118
|
+
const preflight = await this.options.ledger.preflightMutation(bookId, remaining.flatMap((operation) => operation.targetRemoteId ? [operation.targetRemoteId] : []), attempt, readScope);
|
|
1119
|
+
for (const correction of commit.recovery?.corrections ?? []) {
|
|
1120
|
+
if (correction.mode !== "replacement") continue;
|
|
1121
|
+
const replacement = remaining.find((operation) => operation.id === correction.operationId);
|
|
1122
|
+
if (!replacement) continue;
|
|
1123
|
+
const target = createInputFinancialPayload(replacement.request);
|
|
1124
|
+
if (preflight.transactions.some((transaction) => transaction.remoteId === correction.remoteId || transaction.type !== "other" && financialPayloadEquals({
|
|
1125
|
+
...transactionFinancialPayload(transaction),
|
|
1126
|
+
occurredAt: target.occurredAt
|
|
1127
|
+
}, target))) throw new FinanceCheckError({
|
|
1128
|
+
code: "REMOTE_CONFLICT",
|
|
1129
|
+
phase: "checking",
|
|
1130
|
+
boundary: "not_sent",
|
|
1131
|
+
recovery: "review",
|
|
1132
|
+
operationSequence: replacement.sequence,
|
|
1133
|
+
message: "原流水或可能重复的流水仍存在,尚未发送重新创建请求。"
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
for (const operation of remaining) {
|
|
1137
|
+
if (operation.operation === "create") continue;
|
|
1138
|
+
const current = preflight.transactions.find((transaction) => transaction.remoteId === operation.targetRemoteId);
|
|
1139
|
+
if (!current || current.contentHash !== operation.request.expectedContentHash) throw new FinanceCheckError(this.executionFailure(commitId, /* @__PURE__ */ new Error("finance_commit_remote_transaction_changed"), "checking", "not_sent", operation));
|
|
1140
|
+
}
|
|
1141
|
+
attempt.onProgress?.({ stage: "balances" });
|
|
1142
|
+
this.assertCommitConsentCurrent(commit, expectedRevision, completedOperations);
|
|
1143
|
+
const authorized = this.options.store.authorizeCommitOverrides({
|
|
1144
|
+
commitId,
|
|
1145
|
+
checkpointIds: overrideCheckpointIds,
|
|
1146
|
+
now: this.now()
|
|
1147
|
+
});
|
|
1148
|
+
for (const impact of resuming ? [] : authorized.checkpointImpacts ?? []) {
|
|
1149
|
+
if (!impact.overrideRequired) continue;
|
|
1150
|
+
this.options.ledger.appendCheckpointOverride({
|
|
1151
|
+
checkpointId: impact.checkpointId,
|
|
1152
|
+
checkpointRevision: impact.checkpointRevision,
|
|
1153
|
+
commitId,
|
|
1154
|
+
operationsHash: authorized.operationsHash,
|
|
1155
|
+
deviationCents: impact.projectedDeviationCents,
|
|
1156
|
+
authority: "trusted-ui",
|
|
1157
|
+
now: this.now()
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
} catch (error) {
|
|
1161
|
+
const failure = this.executionFailure(commitId, error, "checking", "not_sent");
|
|
1162
|
+
if (resuming) return this.options.store.pauseCommit(commitId, this.now(), failure);
|
|
1163
|
+
return this.options.store.finishCommit(commitId, this.now(), failure);
|
|
1164
|
+
}
|
|
1165
|
+
this.options.store.setCommitStatus(commit.id, "executing", { startedAt: this.now() }, this.now());
|
|
1166
|
+
attempt.onProgress?.({ stage: "queued" });
|
|
1167
|
+
attempt.afterAutoLogin = () => this.assertCommitConsentCurrent(commit, expectedRevision, completedOperations);
|
|
1168
|
+
attempt.beforeWrite = attempt.afterAutoLogin;
|
|
1169
|
+
for (const originalOperation of this.getCommit(commit.id).operations) {
|
|
1170
|
+
const due = this.getCommit(commit.id).operations.filter((item) => ["unknown", "readback_pending"].includes(item.status) && item.nextReadbackAt && Date.parse(item.nextReadbackAt) <= Date.parse(this.now()) && (item.readbackAttempt ?? 0) < READBACK_DELAYS_SECONDS.length);
|
|
1171
|
+
if (due.length) try {
|
|
1172
|
+
await this.verifyCommitOperations(commitId, due, attempt, (verified) => {
|
|
1173
|
+
completedOperations.push(effectiveRecoveryOperation(commit, verified));
|
|
1174
|
+
const revision = objectRecord(verified.result?.cache)?.ledgerRevision;
|
|
1175
|
+
expectedRevision = typeof revision === "number" ? revision : this.options.ledger.ledgerBookState(verified.bookId).revision;
|
|
1176
|
+
});
|
|
1177
|
+
} catch (error) {
|
|
1178
|
+
return this.options.store.pauseCommit(commitId, this.now(), this.executionFailure(commitId, error, "readback", "not_sent", due[0]));
|
|
1179
|
+
}
|
|
1180
|
+
const operation = effectiveRecoveryOperation(commit, originalOperation);
|
|
1181
|
+
if (!operationCanContinue(operation)) continue;
|
|
1182
|
+
const unresolved = this.getCommit(commit.id).operations.filter((item) => item.status === "unknown" || item.status === "readback_pending");
|
|
1183
|
+
if (unresolved.length && commit.checkpointImpacts?.some((impact) => impact.overrideRequired)) return this.options.store.pauseCommit(commitId, this.now(), {
|
|
1184
|
+
code: "CHECKPOINT_OUTCOME_UNRESOLVED",
|
|
1185
|
+
phase: "writing",
|
|
1186
|
+
boundary: "not_sent",
|
|
1187
|
+
occurredAt: this.now(),
|
|
1188
|
+
operationSequence: operation.sequence,
|
|
1189
|
+
message: "尚有写入结果未核实,不能继续沿用余额偏差授权。",
|
|
1190
|
+
recovery: "verify"
|
|
1191
|
+
});
|
|
1192
|
+
if (unresolved.some((other) => operationsOverlap(operation, other))) {
|
|
1193
|
+
failure = {
|
|
1194
|
+
code: "UNRESOLVED_DEPENDENCY",
|
|
1195
|
+
phase: "writing",
|
|
1196
|
+
boundary: "not_sent",
|
|
1197
|
+
occurredAt: this.now(),
|
|
1198
|
+
operationSequence: operation.sequence,
|
|
1199
|
+
message: "这笔流水与结果未知的操作重叠,已跳过,未发送写入。",
|
|
1200
|
+
recovery: "verify"
|
|
1201
|
+
};
|
|
1202
|
+
this.options.store.setCommitOperationStatus(commitId, operation.id, "not_executed", {
|
|
1203
|
+
result: {
|
|
1204
|
+
boundary: "not_sent",
|
|
1205
|
+
failure
|
|
1206
|
+
},
|
|
1207
|
+
endedAt: this.now()
|
|
1208
|
+
}, this.now());
|
|
1209
|
+
continue;
|
|
1210
|
+
}
|
|
1211
|
+
const startedAt = this.now();
|
|
1212
|
+
this.options.store.setCommitOperationStatus(commit.id, operation.id, "executing", {
|
|
1213
|
+
startedAt,
|
|
1214
|
+
result: {
|
|
1215
|
+
dispatchProtocol: 1,
|
|
1216
|
+
boundary: "not_sent"
|
|
1217
|
+
}
|
|
1218
|
+
}, startedAt);
|
|
1219
|
+
attempt.beforeDispatch = () => {
|
|
1220
|
+
this.options.store.setCommitOperationStatus(commit.id, operation.id, "executing", { result: {
|
|
1221
|
+
dispatchProtocol: 1,
|
|
1222
|
+
boundary: "sent_unknown"
|
|
1223
|
+
} }, this.now());
|
|
1224
|
+
};
|
|
1225
|
+
try {
|
|
1226
|
+
try {
|
|
1227
|
+
this.assertCommitConsentCurrent(commit, expectedRevision, completedOperations);
|
|
1228
|
+
} catch (error) {
|
|
1229
|
+
throw new WriteBoundaryError("not_sent", error);
|
|
1230
|
+
}
|
|
1231
|
+
const result = await executeOperation(this.options.ledger, operation, attempt);
|
|
1232
|
+
const record = {
|
|
1233
|
+
...asRecord(result),
|
|
1234
|
+
boundary: result.outcome === "uncertain" ? "sent_unknown" : "verified"
|
|
1235
|
+
};
|
|
1236
|
+
const succeeded = result.outcome === "succeeded" || result.outcome === "already_applied" || result.outcome === "remote_succeeded_cache_stale";
|
|
1237
|
+
if (succeeded) {
|
|
1238
|
+
completedOperations.push(operation);
|
|
1239
|
+
expectedRevision = result.cache.ledgerRevision ?? this.options.ledger.ledgerBookState(operation.bookId).revision;
|
|
1240
|
+
}
|
|
1241
|
+
const unknown = result.outcome === "uncertain";
|
|
1242
|
+
if (unknown) {
|
|
1243
|
+
const cause = new FeideeError("Remote outcome is unresolved", result.failure?.code ?? "REMOTE_OUTCOME_UNCERTAIN");
|
|
1244
|
+
if (result.failure?.diagnostic) cause.diagnostic = result.failure.diagnostic;
|
|
1245
|
+
failure = this.executionFailure(commitId, cause, "writing", "sent_unknown", operation);
|
|
1246
|
+
record.failure = failure;
|
|
1247
|
+
}
|
|
1248
|
+
const nextReadbackAt = readbackAt(this.now(), 0);
|
|
1249
|
+
this.options.store.setCommitOperationStatus(commit.id, operation.id, result.outcome === "remote_succeeded_cache_stale" ? "readback_pending" : succeeded ? "succeeded" : unknown ? "unknown" : "failed", {
|
|
1250
|
+
result: record,
|
|
1251
|
+
verification: {
|
|
1252
|
+
outcome: result.outcome,
|
|
1253
|
+
retrySafe: result.retrySafe
|
|
1254
|
+
},
|
|
1255
|
+
receiptRef: mutationReceiptReference(operation, result),
|
|
1256
|
+
...succeeded ? { readbackVerificationRef: mutationReceiptReference(operation, result) } : {},
|
|
1257
|
+
readbackAttempt: 0,
|
|
1258
|
+
...unknown ? { nextReadbackAt } : {},
|
|
1259
|
+
endedAt: this.now()
|
|
1260
|
+
}, this.now());
|
|
1261
|
+
if (unknown && failure && failureBlocksIndependentWrites(failure)) return this.options.store.pauseCommit(commitId, this.now(), failure);
|
|
1262
|
+
if (result.outcome === "remote_succeeded_cache_stale") {
|
|
1263
|
+
failure = {
|
|
1264
|
+
code: "STORAGE_UNAVAILABLE",
|
|
1265
|
+
phase: "writing",
|
|
1266
|
+
boundary: "verified",
|
|
1267
|
+
occurredAt: this.now(),
|
|
1268
|
+
operationSequence: operation.sequence,
|
|
1269
|
+
message: "远端写入已核验,但本地余额更新失败;请重试核验以修复本地投影,其余流水保持暂停。",
|
|
1270
|
+
recovery: "storage"
|
|
1271
|
+
};
|
|
1272
|
+
return this.options.store.pauseCommit(commitId, this.now(), failure);
|
|
1273
|
+
}
|
|
1274
|
+
} catch (error) {
|
|
1275
|
+
const boundary = error instanceof FeideeError ? error.boundary ?? "sent_unknown" : "sent_unknown";
|
|
1276
|
+
failure = this.executionFailure(commitId, error, "writing", boundary, operation);
|
|
1277
|
+
const isolatedFailure = (boundary === "not_sent" || boundary === "rejected") && [
|
|
1278
|
+
"REMOTE_REJECTED",
|
|
1279
|
+
"INVALID_ARGUMENT",
|
|
1280
|
+
"NOT_FOUND"
|
|
1281
|
+
].includes(failure.code) && !commit.checkpointImpacts?.some((impact) => impact.overrideRequired);
|
|
1282
|
+
this.options.store.setCommitOperationStatus(commit.id, operation.id, boundary === "sent_unknown" ? "unknown" : boundary === "not_sent" ? "not_executed" : "failed", {
|
|
1283
|
+
result: {
|
|
1284
|
+
failure,
|
|
1285
|
+
boundary
|
|
1286
|
+
},
|
|
1287
|
+
...boundary === "sent_unknown" ? {
|
|
1288
|
+
readbackAttempt: 0,
|
|
1289
|
+
nextReadbackAt: readbackAt(this.now(), 0)
|
|
1290
|
+
} : {},
|
|
1291
|
+
endedAt: this.now()
|
|
1292
|
+
}, this.now());
|
|
1293
|
+
if (boundary !== "sent_unknown" && !isolatedFailure || boundary === "sent_unknown" && failureBlocksIndependentWrites(failure)) return this.options.store.pauseCommit(commitId, this.now(), failure);
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
const finished = this.options.store.finishCommit(commit.id, this.now(), failure);
|
|
1297
|
+
if (finished.status === "awaiting_readback" || finished.status === "outcome_unknown") this.scheduleReadback(finished.id);
|
|
1298
|
+
this.options.notify?.({
|
|
1299
|
+
severity: finished.status === "succeeded" ? "info" : "warning",
|
|
1300
|
+
title: finished.status === "succeeded" ? "财务提交完成" : "财务提交存在未完成操作",
|
|
1301
|
+
body: commitResultSummary(finished),
|
|
1302
|
+
resourceType: "finance.workset",
|
|
1303
|
+
resourceId: finished.worksetId,
|
|
1304
|
+
dedupeKey: `finance.commit.result:${finished.id}`
|
|
1305
|
+
});
|
|
1306
|
+
return finished;
|
|
1307
|
+
}
|
|
1308
|
+
async verifyCommitOperation(commitId, operation, attempt) {
|
|
1309
|
+
const commit = this.getCommit(commitId);
|
|
1310
|
+
const nextReadbackAt = commit.operations.find((item) => item.id === operation.id)?.nextReadbackAt;
|
|
1311
|
+
const schedule = nextReadbackAt ? { nextReadbackAt } : {};
|
|
1312
|
+
const correction = commit.recovery?.corrections.find((item) => item.operationId === operation.id && item.mode === "external");
|
|
1313
|
+
if (correction) {
|
|
1314
|
+
if (!commit.recovery?.approvedAt) throw new Error("finance_recovery_approval_required");
|
|
1315
|
+
if (!this.options.ledger.readExternalCorrection || !this.options.ledger.refreshExternalCorrection) throw new Error("finance_recovery_receipt_unavailable");
|
|
1316
|
+
const transaction = await this.options.ledger.readExternalCorrection(operation.bookId, verificationInput(operation), correction.remoteId, correction.occurredAt, attempt);
|
|
1317
|
+
const { rawSource: _rawSource, ...evidence } = transaction;
|
|
1318
|
+
const key = `observation:${operation.id}:${recoveryHash(evidence)}`;
|
|
1319
|
+
if (!this.options.store.recoveryEvents(commitId).some((event) => event.kind === "observed" && event.operationId === operation.id && recoveryHash(event.transaction) === recoveryHash(evidence))) this.options.store.appendRecoveryEvent(commitId, key, {
|
|
1320
|
+
kind: "observed",
|
|
1321
|
+
hash: commit.recovery.hash,
|
|
1322
|
+
operationId: operation.id,
|
|
1323
|
+
at: this.now(),
|
|
1324
|
+
transaction: evidence
|
|
1325
|
+
});
|
|
1326
|
+
try {
|
|
1327
|
+
await this.options.ledger.refreshExternalCorrection(evidence);
|
|
1328
|
+
} catch {
|
|
1329
|
+
throw new FinanceCheckError({
|
|
1330
|
+
code: "STORAGE_UNAVAILABLE",
|
|
1331
|
+
phase: "readback",
|
|
1332
|
+
boundary: "verified",
|
|
1333
|
+
recovery: "storage",
|
|
1334
|
+
message: "人工修正后的远端记录已核实,但本地投影保存失败;请重试核验,不会重新写入。"
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
this.options.store.setCommitOperationStatus(commitId, operation.id, operation.status, {
|
|
1338
|
+
...schedule,
|
|
1339
|
+
verification: {
|
|
1340
|
+
outcome: "externally_verified",
|
|
1341
|
+
recoveryHash: commit.recovery.hash,
|
|
1342
|
+
remoteId: transaction.remoteId,
|
|
1343
|
+
checkedAt: this.now()
|
|
1344
|
+
}
|
|
1345
|
+
}, this.now());
|
|
1346
|
+
this.options.store.settleCommitOperation({
|
|
1347
|
+
commitId,
|
|
1348
|
+
operationId: operation.id,
|
|
1349
|
+
outcome: "externally_verified",
|
|
1350
|
+
attempt: (operation.readbackAttempt ?? 0) + 1,
|
|
1351
|
+
verificationRef: `external-correction:${commit.recovery.hash}:${operation.id}`,
|
|
1352
|
+
now: this.now()
|
|
1353
|
+
});
|
|
1354
|
+
return true;
|
|
1355
|
+
}
|
|
1356
|
+
operation = effectiveRecoveryOperation(commit, operation);
|
|
1357
|
+
const proven = operation.result?.boundary === "verified" && [
|
|
1358
|
+
"succeeded",
|
|
1359
|
+
"already_applied",
|
|
1360
|
+
"remote_succeeded_cache_stale"
|
|
1361
|
+
].includes(String(operation.result?.outcome));
|
|
1362
|
+
const result = proven && operation.result?.outcome !== "remote_succeeded_cache_stale" ? void 0 : await verifyOperation(this.options.ledger, operation, attempt);
|
|
1363
|
+
const verified = result ? result.outcome === "succeeded" || result.outcome === "already_applied" || result.outcome === "remote_succeeded_cache_stale" : proven;
|
|
1364
|
+
const count = (operation.readbackAttempt ?? 0) + 1;
|
|
1365
|
+
if (verified && result) this.options.store.setCommitOperationStatus(commitId, operation.id, operation.status, {
|
|
1366
|
+
...schedule,
|
|
1367
|
+
result: {
|
|
1368
|
+
...asRecord(result),
|
|
1369
|
+
boundary: "verified",
|
|
1370
|
+
...operation.result ? { originalResult: operation.result.originalResult ?? operation.result } : {}
|
|
1371
|
+
}
|
|
1372
|
+
}, this.now());
|
|
1373
|
+
const { diagnostic: _previousDiagnostic, failure: _previousFailure, ...previousVerification } = operation.verification ?? {};
|
|
1374
|
+
this.options.store.setCommitOperationStatus(commitId, operation.id, operation.status, {
|
|
1375
|
+
...schedule,
|
|
1376
|
+
verification: {
|
|
1377
|
+
...previousVerification,
|
|
1378
|
+
outcome: verified ? "succeeded" : "uncertain",
|
|
1379
|
+
checkedAt: this.now(),
|
|
1380
|
+
...!verified && result?.verificationDiagnostic ? { diagnostic: result.verificationDiagnostic } : {}
|
|
1381
|
+
}
|
|
1382
|
+
}, this.now());
|
|
1383
|
+
if ((result?.outcome ?? operation.result?.outcome) === "remote_succeeded_cache_stale") {
|
|
1384
|
+
this.options.store.setCommitOperationStatus(commitId, operation.id, "readback_pending", {
|
|
1385
|
+
...schedule,
|
|
1386
|
+
verification: {
|
|
1387
|
+
outcome: "remote_succeeded_cache_stale",
|
|
1388
|
+
checkedAt: this.now()
|
|
1389
|
+
},
|
|
1390
|
+
readbackAttempt: count
|
|
1391
|
+
}, this.now());
|
|
1392
|
+
throw new FinanceCheckError({
|
|
1393
|
+
code: "STORAGE_UNAVAILABLE",
|
|
1394
|
+
phase: "readback",
|
|
1395
|
+
boundary: "verified",
|
|
1396
|
+
message: "远端写入已核验,但本地缓存未更新;请重试核验以修复本地投影,不会重发流水。",
|
|
1397
|
+
recovery: "storage"
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
this.options.store.settleCommitOperation({
|
|
1401
|
+
commitId,
|
|
1402
|
+
operationId: operation.id,
|
|
1403
|
+
outcome: verified ? "succeeded" : "unknown",
|
|
1404
|
+
attempt: count,
|
|
1405
|
+
verificationRef: `remote-receipt-readback:${operation.bookId}:${operation.id}:${count}`,
|
|
1406
|
+
...!verified && count < READBACK_DELAYS_SECONDS.length ? { nextReadbackAt: readbackAt(this.now(), count) } : {},
|
|
1407
|
+
now: this.now()
|
|
1408
|
+
});
|
|
1409
|
+
return verified;
|
|
1410
|
+
}
|
|
1411
|
+
async verifyCommitOperations(commitId, operations, attempt, onVerified) {
|
|
1412
|
+
const startedAt = this.now();
|
|
1413
|
+
let checked = 0;
|
|
1414
|
+
let failure;
|
|
1415
|
+
let current;
|
|
1416
|
+
this.options.store.saveCommitReadback(commitId, {
|
|
1417
|
+
status: "running",
|
|
1418
|
+
startedAt,
|
|
1419
|
+
total: operations.length,
|
|
1420
|
+
checked: 0,
|
|
1421
|
+
verified: 0,
|
|
1422
|
+
unresolved: operations.length
|
|
1423
|
+
});
|
|
1424
|
+
try {
|
|
1425
|
+
for (const operation of operations) {
|
|
1426
|
+
current = operation;
|
|
1427
|
+
attempt.onProgress?.({ stage: "readback" });
|
|
1428
|
+
const count = (operation.readbackAttempt ?? 0) + 1;
|
|
1429
|
+
this.options.store.setCommitOperationStatus(commitId, operation.id, operation.status, {
|
|
1430
|
+
readbackAttempt: count,
|
|
1431
|
+
...count < READBACK_DELAYS_SECONDS.length ? { nextReadbackAt: readbackAt(this.now(), count) } : {}
|
|
1432
|
+
}, this.now());
|
|
1433
|
+
if (await this.verifyCommitOperation(commitId, operation, attempt)) onVerified?.(this.getCommit(commitId).operations.find((item) => item.id === operation.id));
|
|
1434
|
+
checked++;
|
|
1435
|
+
const verified = operations.filter((item) => this.getCommit(commitId).operations.some((latest) => latest.id === item.id && operationIsVerified(latest))).length;
|
|
1436
|
+
this.options.store.saveCommitReadback(commitId, {
|
|
1437
|
+
status: "running",
|
|
1438
|
+
startedAt,
|
|
1439
|
+
total: operations.length,
|
|
1440
|
+
checked,
|
|
1441
|
+
verified,
|
|
1442
|
+
unresolved: operations.length - verified
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
return this.getCommit(commitId).operations.filter((operation) => operations.some((item) => item.id === operation.id) && operationIsVerified(operation));
|
|
1446
|
+
} catch (error) {
|
|
1447
|
+
failure = this.executionFailure(commitId, error, "readback", "not_sent", current);
|
|
1448
|
+
if (["VERIFICATION_TARGET_ABSENT", "EXTERNAL_CORRECTION_MISMATCH"].includes(failure.code)) checked++;
|
|
1449
|
+
if (current) {
|
|
1450
|
+
const latest = this.getCommit(commitId).operations.find((item) => item.id === current.id);
|
|
1451
|
+
const count = latest.readbackAttempt ?? 1;
|
|
1452
|
+
const { diagnostic: previousDiagnostic, ...previousVerification } = latest.verification ?? {};
|
|
1453
|
+
this.options.store.setCommitOperationStatus(commitId, latest.id, latest.status, {
|
|
1454
|
+
verification: {
|
|
1455
|
+
...previousVerification,
|
|
1456
|
+
...previousDiagnostic ? { previousDiagnostic } : {},
|
|
1457
|
+
failure,
|
|
1458
|
+
checkedAt: this.now()
|
|
1459
|
+
},
|
|
1460
|
+
readbackAttempt: count,
|
|
1461
|
+
...failure.recovery === "check" && count < READBACK_DELAYS_SECONDS.length ? { nextReadbackAt: readbackAt(this.now(), count) } : {}
|
|
1462
|
+
}, this.now());
|
|
1463
|
+
}
|
|
1464
|
+
throw new FinanceCheckError(failure);
|
|
1465
|
+
} finally {
|
|
1466
|
+
const verified = operations.filter((operation) => this.getCommit(commitId).operations.some((item) => item.id === operation.id && operationIsVerified(item))).length;
|
|
1467
|
+
this.options.store.saveCommitReadback(commitId, {
|
|
1468
|
+
status: "completed",
|
|
1469
|
+
startedAt,
|
|
1470
|
+
completedAt: this.now(),
|
|
1471
|
+
total: operations.length,
|
|
1472
|
+
checked: Math.max(checked, verified),
|
|
1473
|
+
verified,
|
|
1474
|
+
unresolved: operations.length - verified,
|
|
1475
|
+
...failure ? { failure } : {}
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
assertCommitConsentCurrent(commit, expectedRevision = commit.ledgerRevision, completedOperations = []) {
|
|
1480
|
+
const bookId = commit.operations[0].bookId;
|
|
1481
|
+
if (expectedRevision !== this.options.ledger.ledgerBookState(bookId).revision) throw new Error("finance_commit_ledger_revision_changed");
|
|
1482
|
+
const currentCheckpoints = new Map(this.options.ledger.activeCheckpoints(bookId).map((item) => [item.id, item]));
|
|
1483
|
+
if (currentCheckpoints.size !== (commit.checkpointImpacts ?? []).length) throw new Error("finance_commit_checkpoint_changed");
|
|
1484
|
+
const metadata = objectRecord(financeBookMetadata(this.options.ledger.cachedMetadata(bookId)));
|
|
1485
|
+
for (const impact of commit.checkpointImpacts ?? []) {
|
|
1486
|
+
const checkpoint = currentCheckpoints.get(impact.checkpointId);
|
|
1487
|
+
if (!checkpoint || checkpoint.revision !== impact.checkpointRevision) throw new Error("finance_commit_checkpoint_changed");
|
|
1488
|
+
const balance = checkpointBalance(this.options.ledger, checkpoint);
|
|
1489
|
+
const appliedDelta = checkpointDelta(completedOperations, metadata, checkpoint);
|
|
1490
|
+
if (balance - checkpoint.balanceCents !== impact.cumulativeDeviationCents + appliedDelta) throw new Error("finance_commit_checkpoint_changed");
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
assertRemoteWritesEnabled() {
|
|
1494
|
+
this.options.assertRemoteWriteAllowed?.();
|
|
1495
|
+
if (this.options.remoteWritesDisabled) throw new WriteDisabledError(FINANCE_REMOTE_WRITES_DISABLED_ERROR);
|
|
1496
|
+
}
|
|
1497
|
+
async recoverOnStartup() {
|
|
1498
|
+
for (const operation of this.options.store.listReadOperations()) {
|
|
1499
|
+
if (operation.status !== "running") continue;
|
|
1500
|
+
this.options.store.saveReadOperation({
|
|
1501
|
+
...operation,
|
|
1502
|
+
status: "failed",
|
|
1503
|
+
completedAt: this.now(),
|
|
1504
|
+
failure: {
|
|
1505
|
+
code: "CHECK_INTERRUPTED",
|
|
1506
|
+
phase: "checking",
|
|
1507
|
+
boundary: "not_sent",
|
|
1508
|
+
checkStage: operation.progress.stage,
|
|
1509
|
+
message: operation.kind === "sync" ? "同步被后台重启中断,可能已更新部分缓存,请重新同步。" : "提交前检查被后台重启中断,尚未写入,请重新检查。",
|
|
1510
|
+
recovery: "check"
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
let confirmationsEnsured = 0;
|
|
1515
|
+
for (const commit of [...this.options.store.listCommits("prepared"), ...this.options.store.listCommits("awaiting_confirmation")]) {
|
|
1516
|
+
await this.ensureCommitConfirmation(commit.id);
|
|
1517
|
+
confirmationsEnsured += 1;
|
|
1518
|
+
}
|
|
1519
|
+
let interrupted = 0;
|
|
1520
|
+
for (const commit of this.options.store.listCommits("checking")) {
|
|
1521
|
+
interrupted += 1;
|
|
1522
|
+
const failure = {
|
|
1523
|
+
code: "CHECK_INTERRUPTED",
|
|
1524
|
+
phase: "checking",
|
|
1525
|
+
boundary: "not_sent",
|
|
1526
|
+
occurredAt: this.now(),
|
|
1527
|
+
...commit.progress ? { checkStage: commit.progress.stage } : {},
|
|
1528
|
+
message: "本轮检查已中断,没有继续发送写入。",
|
|
1529
|
+
recovery: "check"
|
|
1530
|
+
};
|
|
1531
|
+
if (commit.operations.every((operation) => operation.status === "pending")) this.options.store.finishCommit(commit.id, this.now(), failure);
|
|
1532
|
+
else this.options.store.pauseCommit(commit.id, this.now(), failure);
|
|
1533
|
+
await this.options.closeCommitConfirmation?.(commit);
|
|
1534
|
+
}
|
|
1535
|
+
for (const commit of this.options.store.listCommits("executing")) {
|
|
1536
|
+
interrupted += 1;
|
|
1537
|
+
await this.options.closeCommitConfirmation?.(commit);
|
|
1538
|
+
for (const operation of commit.operations) if (operation.status === "executing") {
|
|
1539
|
+
if (operation.result?.dispatchProtocol === 1 && await this.options.ledger.hasNoDispatchReceipt?.(operation.bookId, verificationInput(effectiveRecoveryOperation(commit, operation)), operation.result.boundary === "not_sent")) {
|
|
1540
|
+
this.options.store.setCommitOperationStatus(commit.id, operation.id, "not_executed", {
|
|
1541
|
+
result: {
|
|
1542
|
+
...operation.result,
|
|
1543
|
+
boundary: "not_sent"
|
|
1544
|
+
},
|
|
1545
|
+
endedAt: this.now()
|
|
1546
|
+
}, this.now());
|
|
1547
|
+
continue;
|
|
1548
|
+
}
|
|
1549
|
+
this.options.store.setCommitOperationStatus(commit.id, operation.id, "unknown", {
|
|
1550
|
+
readbackAttempt: 0,
|
|
1551
|
+
nextReadbackAt: readbackAt(this.now(), 0),
|
|
1552
|
+
endedAt: this.now()
|
|
1553
|
+
}, this.now());
|
|
1554
|
+
}
|
|
1555
|
+
this.options.store.pauseCommit(commit.id, this.now(), {
|
|
1556
|
+
code: "EXECUTION_INTERRUPTED",
|
|
1557
|
+
phase: "writing",
|
|
1558
|
+
boundary: "sent_unknown",
|
|
1559
|
+
occurredAt: this.now(),
|
|
1560
|
+
message: "执行被后台中断。已发送项先核验,未发送项等待恢复本批次。",
|
|
1561
|
+
recovery: "verify"
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
for (const commit of this.options.store.listCommits()) if (commit.readback?.status === "running") this.options.store.saveCommitReadback(commit.id, {
|
|
1565
|
+
...commit.readback,
|
|
1566
|
+
status: "completed",
|
|
1567
|
+
completedAt: this.now(),
|
|
1568
|
+
failure: {
|
|
1569
|
+
code: "CHECK_INTERRUPTED",
|
|
1570
|
+
phase: "readback",
|
|
1571
|
+
boundary: "not_sent",
|
|
1572
|
+
message: "核验被后台中断,尚未取得新的核验结论。",
|
|
1573
|
+
recovery: "check"
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1576
|
+
for (const status of [
|
|
1577
|
+
"paused",
|
|
1578
|
+
"awaiting_readback",
|
|
1579
|
+
"outcome_unknown"
|
|
1580
|
+
]) for (const commit of this.options.store.listCommits(status)) if (commit.operations.some((operation) => operation.nextReadbackAt)) this.scheduleReadback(commit.id);
|
|
1581
|
+
for (const status of [
|
|
1582
|
+
"succeeded",
|
|
1583
|
+
"partial_failed",
|
|
1584
|
+
"failed",
|
|
1585
|
+
"cancelled"
|
|
1586
|
+
]) for (const commit of this.options.store.listCommits(status)) await this.options.closeCommitConfirmation?.(commit);
|
|
1587
|
+
return {
|
|
1588
|
+
confirmationsEnsured,
|
|
1589
|
+
interrupted
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
recoverCommitReadback(commitId, force = false) {
|
|
1593
|
+
if (this.commitRuns.has(commitId) || ["checking", "executing"].includes(this.getCommit(commitId).status)) {
|
|
1594
|
+
if (force) return Promise.reject(/* @__PURE__ */ new Error("finance_commit_busy"));
|
|
1595
|
+
return Promise.resolve(this.getCommit(commitId));
|
|
1596
|
+
}
|
|
1597
|
+
const existing = this.readbackRuns.get(commitId);
|
|
1598
|
+
if (existing) return existing;
|
|
1599
|
+
const run = this.readCommitReceipts(commitId, force).finally(() => this.readbackRuns.delete(commitId));
|
|
1600
|
+
this.readbackRuns.set(commitId, run);
|
|
1601
|
+
return run;
|
|
1602
|
+
}
|
|
1603
|
+
async readCommitReceipts(commitId, force) {
|
|
1604
|
+
let commit = this.getCommit(commitId);
|
|
1605
|
+
if (![
|
|
1606
|
+
"paused",
|
|
1607
|
+
"awaiting_readback",
|
|
1608
|
+
"outcome_unknown"
|
|
1609
|
+
].includes(commit.status)) return commit;
|
|
1610
|
+
const eligible = commit.operations.filter((operation) => ["readback_pending", "unknown"].includes(operation.status) && (force || operation.nextReadbackAt && Date.parse(operation.nextReadbackAt) <= Date.parse(this.now())));
|
|
1611
|
+
if (!eligible.length) return commit;
|
|
1612
|
+
try {
|
|
1613
|
+
const attempt = force ? this.commitAttempt(commit) : { autoLoginUsed: true };
|
|
1614
|
+
await this.verifyCommitOperations(commitId, eligible, attempt);
|
|
1615
|
+
} catch (error) {
|
|
1616
|
+
if (!(error instanceof FinanceCheckError)) throw error;
|
|
1617
|
+
}
|
|
1618
|
+
commit = this.getCommit(commitId);
|
|
1619
|
+
this.scheduleReadback(commit.id);
|
|
1620
|
+
return commit;
|
|
1621
|
+
}
|
|
1622
|
+
createCheckpoint(input) {
|
|
1623
|
+
const requestHash = remoteVersion({
|
|
1624
|
+
bookId: input.bookId,
|
|
1625
|
+
accountId: input.accountId,
|
|
1626
|
+
balanceCents: input.balanceCents,
|
|
1627
|
+
currency: input.currency,
|
|
1628
|
+
ledgerRevision: input.ledgerRevision,
|
|
1629
|
+
lastStableSyncAt: input.lastStableSyncAt,
|
|
1630
|
+
timezone: input.timezone,
|
|
1631
|
+
authority: input.authority,
|
|
1632
|
+
expectedCheckpoint: input.expectedCheckpoint ? {
|
|
1633
|
+
id: input.expectedCheckpoint.id,
|
|
1634
|
+
revision: input.expectedCheckpoint.revision
|
|
1635
|
+
} : input.expectedCheckpoint
|
|
1636
|
+
});
|
|
1637
|
+
if (input.confirmationId) {
|
|
1638
|
+
const receipt = this.options.ledger.checkpointConfirmation?.(input.confirmationId);
|
|
1639
|
+
if (receipt) {
|
|
1640
|
+
if (receipt.requestHash !== requestHash) throw new Error("finance_checkpoint_request_conflict");
|
|
1641
|
+
return receipt.checkpoint;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
const now = this.now();
|
|
1645
|
+
const state = this.options.ledger.ledgerBookState(input.bookId);
|
|
1646
|
+
if (state.revision !== input.ledgerRevision || state.lastStableObservedAt !== input.lastStableSyncAt || state.timezone !== input.timezone) throw new Error("finance_checkpoint_observation_changed");
|
|
1647
|
+
if (!state.lastStableObservedAt || Date.parse(now) - Date.parse(state.lastStableObservedAt) > 18e5) throw new Error("finance_checkpoint_sync_stale");
|
|
1648
|
+
const metadata = objectRecord(this.options.ledger.cachedMetadata(input.bookId));
|
|
1649
|
+
const account = (Array.isArray(metadata?.accounts) ? metadata.accounts.map(objectRecord) : []).find((candidate) => candidate?.id === input.accountId);
|
|
1650
|
+
if (!account || account.currency !== input.currency) throw new Error("finance_checkpoint_account_currency_mismatch");
|
|
1651
|
+
if (accountBalanceFromSnapshot(this.options.ledger.accountSnapshotAt?.(input.bookId, now) ?? this.options.ledger.accountSnapshot(input.bookId, calendarDateInTimeZone(now, state.timezone)), input.accountId) !== input.balanceCents) throw new Error("finance_checkpoint_balance_changed");
|
|
1652
|
+
return this.options.ledger.createCheckpoint({
|
|
1653
|
+
id: this.id(),
|
|
1654
|
+
bookId: input.bookId,
|
|
1655
|
+
accountId: input.accountId,
|
|
1656
|
+
balanceCents: input.balanceCents,
|
|
1657
|
+
currency: input.currency,
|
|
1658
|
+
cutoff: now,
|
|
1659
|
+
lastStableSyncAt: input.lastStableSyncAt,
|
|
1660
|
+
ledgerRevision: input.ledgerRevision,
|
|
1661
|
+
timezone: input.timezone,
|
|
1662
|
+
createdBy: input.authority,
|
|
1663
|
+
now,
|
|
1664
|
+
balanceBasis: this.options.ledger.accountSnapshotAt ? "instant" : "day",
|
|
1665
|
+
...input.confirmationId ? {
|
|
1666
|
+
confirmationId: input.confirmationId,
|
|
1667
|
+
requestHash
|
|
1668
|
+
} : {},
|
|
1669
|
+
...input.expectedCheckpoint !== void 0 ? { expectedCheckpoint: input.expectedCheckpoint } : {}
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
deleteCheckpoint(input) {
|
|
1673
|
+
if (!input.confirmed) throw new Error("finance_checkpoint_delete_confirmation_required");
|
|
1674
|
+
this.options.ledger.deleteCheckpoint({
|
|
1675
|
+
checkpointId: input.checkpointId,
|
|
1676
|
+
expectedRevision: input.expectedRevision,
|
|
1677
|
+
authority: input.authority,
|
|
1678
|
+
now: this.now()
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
checkpointContext(bookId) {
|
|
1682
|
+
const state = this.options.ledger.ledgerBookState(bookId);
|
|
1683
|
+
const historyCounts = {};
|
|
1684
|
+
for (const event of this.options.ledger.checkpointAudit(bookId)) if (event.eventType === "CheckpointCreated") historyCounts[event.accountId] = (historyCounts[event.accountId] ?? 0) + 1;
|
|
1685
|
+
return {
|
|
1686
|
+
state,
|
|
1687
|
+
historyCounts,
|
|
1688
|
+
checkpoints: this.options.ledger.activeCheckpoints(bookId),
|
|
1689
|
+
accounts: this.options.ledger.accountSnapshotAt?.(bookId, this.now()) ?? this.options.ledger.accountSnapshot(bookId, calendarDateInTimeZone(this.now(), state.timezone))
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
queryCheckpoints(input) {
|
|
1693
|
+
if (input.subjectId) this.requireGrantedBook(input.subjectId, input.bookId);
|
|
1694
|
+
const view = input.view ?? "latest";
|
|
1695
|
+
if (input.includeDraftImpact && (!input.subjectId || view !== "latest")) throw new Error("finance_checkpoint_draft_context_required");
|
|
1696
|
+
if (view === "history" && input.accountIds?.length !== 1) throw new Error("finance_checkpoint_history_account_required");
|
|
1697
|
+
const draft = () => input.includeDraftImpact ? this.options.store.getOpenDraftRow(input.subjectId) : void 0;
|
|
1698
|
+
const version = () => remoteVersion({
|
|
1699
|
+
ledger: this.options.ledger.ledgerBookState(input.bookId),
|
|
1700
|
+
checkpoints: this.options.ledger.checkpointAudit(input.bookId),
|
|
1701
|
+
draft: draft()
|
|
1702
|
+
});
|
|
1703
|
+
const dataVersion = version();
|
|
1704
|
+
if ((input.offset ?? 0) > 0 && !input.expectedVersion) throw new Error("finance_page_version_required");
|
|
1705
|
+
if (input.expectedVersion && input.expectedVersion !== dataVersion) throw new Error("finance_checkpoint_page_version_changed");
|
|
1706
|
+
const state = this.options.ledger.ledgerBookState(input.bookId);
|
|
1707
|
+
const metadata = financeBookMetadata(this.options.ledger.cachedMetadata(input.bookId));
|
|
1708
|
+
const names = new Map(metadata.accounts.map((account) => [account.id, account.name]));
|
|
1709
|
+
const active = this.options.ledger.activeCheckpoints(input.bookId);
|
|
1710
|
+
const byAccount = new Map(active.map((checkpoint) => [checkpoint.accountId, checkpoint]));
|
|
1711
|
+
const operations = [], unresolved = [];
|
|
1712
|
+
if (input.includeDraftImpact) {
|
|
1713
|
+
const row = draft();
|
|
1714
|
+
if (row && row.bookId !== input.bookId) throw new Error("finance_draft_book_mismatch");
|
|
1715
|
+
for (const entry of row ? this.analyzeDraftEntries(row.entries, input.bookId) : []) {
|
|
1716
|
+
if (entry.draft?.operation === "matched") continue;
|
|
1717
|
+
try {
|
|
1718
|
+
if (draftEntryNeedsCompletion(entry) || !entry.proposal) throw new Error("incomplete");
|
|
1719
|
+
const current = entry.proposal.operation === "create" ? void 0 : this.options.ledger.getTransaction(input.bookId, entry.proposal.remoteId);
|
|
1720
|
+
const operation = freezeOperation("checkpoint-preview", entry.id, operations.length, entry.proposal, entry.id, input.bookId, metadata, current);
|
|
1721
|
+
if (operation.request.type === "other" || operation.before?.type === "other") throw new Error("unsupported_balance_adjustment");
|
|
1722
|
+
operations.push(operation);
|
|
1723
|
+
} catch {
|
|
1724
|
+
unresolved.push(entry.id);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
let records, total;
|
|
1729
|
+
if (view === "history") {
|
|
1730
|
+
if (!this.options.ledger.checkpointHistory) throw new Error("finance_checkpoint_history_unavailable");
|
|
1731
|
+
const page = this.options.ledger.checkpointHistory(input.bookId, input.accountIds[0], input.offset ?? 0, input.limit ?? 50);
|
|
1732
|
+
records = page.items;
|
|
1733
|
+
total = page.total;
|
|
1734
|
+
} else records = [...new Set(input.accountIds ?? [...names.keys(), ...byAccount.keys()])].sort().map((accountId) => {
|
|
1735
|
+
if (!names.has(accountId) && !byAccount.has(accountId)) throw new Error("finance_checkpoint_account_not_found");
|
|
1736
|
+
const point = byAccount.get(accountId);
|
|
1737
|
+
return {
|
|
1738
|
+
id: point?.id ?? "",
|
|
1739
|
+
accountId,
|
|
1740
|
+
bookId: input.bookId,
|
|
1741
|
+
revision: point?.revision ?? 0,
|
|
1742
|
+
confirmedAt: point?.createdAt ?? "",
|
|
1743
|
+
status: "active",
|
|
1744
|
+
snapshot: point ?? null
|
|
1745
|
+
};
|
|
1746
|
+
});
|
|
1747
|
+
const project = (record) => {
|
|
1748
|
+
let row = reviewCheckpoint(this.options.ledger, record, names.get(record.accountId) ?? record.accountId);
|
|
1749
|
+
if (view === "latest" && !record.snapshot) row = {
|
|
1750
|
+
...row,
|
|
1751
|
+
id: null,
|
|
1752
|
+
revision: null,
|
|
1753
|
+
confirmedAt: null,
|
|
1754
|
+
currency: metadata.accounts.find((account) => account.id === record.accountId)?.currency ?? null,
|
|
1755
|
+
status: "unconfirmed",
|
|
1756
|
+
verification: "no_checkpoint",
|
|
1757
|
+
reason: "no_checkpoint"
|
|
1758
|
+
};
|
|
1759
|
+
if (input.includeDraftImpact) {
|
|
1760
|
+
const delta = !unresolved.length && record.snapshot ? checkpointDelta(operations, metadata, record.snapshot) : null;
|
|
1761
|
+
row = {
|
|
1762
|
+
...row,
|
|
1763
|
+
draftDeltaCents: delta,
|
|
1764
|
+
projectedDeviationCents: delta !== null && row.deviationCents !== null ? row.deviationCents + delta : null
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
return row;
|
|
1768
|
+
};
|
|
1769
|
+
const result = offsetPage({
|
|
1770
|
+
items: records,
|
|
1771
|
+
offset: input.offset ?? 0,
|
|
1772
|
+
limit: input.limit ?? 50,
|
|
1773
|
+
...total !== void 0 ? { total } : {},
|
|
1774
|
+
project,
|
|
1775
|
+
base: {
|
|
1776
|
+
bookId: input.bookId,
|
|
1777
|
+
view,
|
|
1778
|
+
dataVersion,
|
|
1779
|
+
ledgerRevision: state.revision,
|
|
1780
|
+
observedAt: state.lastStableObservedAt ?? null,
|
|
1781
|
+
...input.includeDraftImpact ? { projection: {
|
|
1782
|
+
scope: "current-open-draft",
|
|
1783
|
+
complete: !unresolved.length,
|
|
1784
|
+
unresolvedEntryIds: unresolved
|
|
1785
|
+
} } : {}
|
|
1786
|
+
}
|
|
1787
|
+
});
|
|
1788
|
+
if (version() !== dataVersion) throw new Error("finance_checkpoint_page_version_changed");
|
|
1789
|
+
return result;
|
|
1790
|
+
}
|
|
1791
|
+
scheduleReadback(commitId) {
|
|
1792
|
+
if (this.maintenancePaused) return;
|
|
1793
|
+
const existing = this.readbackTimers.get(commitId);
|
|
1794
|
+
if (existing) clearTimeout(existing);
|
|
1795
|
+
this.readbackTimers.delete(commitId);
|
|
1796
|
+
const commit = this.getCommit(commitId);
|
|
1797
|
+
if (![
|
|
1798
|
+
"paused",
|
|
1799
|
+
"awaiting_readback",
|
|
1800
|
+
"outcome_unknown"
|
|
1801
|
+
].includes(commit.status)) return;
|
|
1802
|
+
const dates = commit.operations.filter((item) => ["unknown", "readback_pending"].includes(item.status) && item.nextReadbackAt && (item.readbackAttempt ?? 0) < READBACK_DELAYS_SECONDS.length).map((item) => Date.parse(item.nextReadbackAt)).filter(Number.isFinite);
|
|
1803
|
+
if (!dates.length) return;
|
|
1804
|
+
const delay = Math.max(0, Math.min(...dates) - Date.parse(this.now()));
|
|
1805
|
+
const timer = setTimeout(() => {
|
|
1806
|
+
this.readbackTimers.delete(commitId);
|
|
1807
|
+
this.recoverCommitReadback(commitId).catch(() => void 0);
|
|
1808
|
+
}, delay);
|
|
1809
|
+
timer.unref?.();
|
|
1810
|
+
this.readbackTimers.set(commitId, timer);
|
|
1811
|
+
}
|
|
1812
|
+
requireGrant(subjectId, bookId, grantId) {
|
|
1813
|
+
const grant = this.ensureDefaultBookGrant(subjectId);
|
|
1814
|
+
if (!grant) throw new Error(FINANCE_GRANT_MISSING_HINT);
|
|
1815
|
+
if (grant.bookId !== bookId || grantId && grant.id !== grantId) throw new Error(`finance_grant_book_mismatch: the active BookReadGrant covers book ${grant.bookId}, not ${bookId}. Rebind the book via the finance.book_grant.selection interaction instead of retrying other book tools.`);
|
|
1816
|
+
return grant;
|
|
1817
|
+
}
|
|
1818
|
+
draftMutationOnce(context, operation, input, mutate) {
|
|
1819
|
+
const inputHash = sha256(stableStringify(JSON.parse(JSON.stringify(input))));
|
|
1820
|
+
return this.options.store.transaction(() => {
|
|
1821
|
+
const key = draftMutationReceiptKey(context.subjectId, operation, context.callId);
|
|
1822
|
+
const existing = this.options.store.getWorkspaceReceipt(key);
|
|
1823
|
+
if (existing !== void 0) {
|
|
1824
|
+
const receipt = objectRecord(existing);
|
|
1825
|
+
if (!receipt || typeof receipt.bookId !== "string" || typeof receipt.grantId !== "string" || typeof receipt.inputHash !== "string" || !objectRecord(receipt.value)) throw new Error("finance_draft_receipt_invalid");
|
|
1826
|
+
this.options.assertSubjectAvailable?.(context.subjectId);
|
|
1827
|
+
const grant = this.options.store.getActiveGrant(context.subjectId);
|
|
1828
|
+
if (!grant) throw new Error(FINANCE_GRANT_MISSING_HINT);
|
|
1829
|
+
if (grant.bookId !== receipt.bookId || grant.id !== receipt.grantId) throw new Error("finance_grant_book_mismatch");
|
|
1830
|
+
if (receipt.inputHash !== inputHash) throw new Error("finance_call_input_mismatch");
|
|
1831
|
+
return receipt.value;
|
|
1832
|
+
}
|
|
1833
|
+
const value = mutate();
|
|
1834
|
+
this.options.store.saveWorkspaceReceipt(key, {
|
|
1835
|
+
bookId: value.row.bookId,
|
|
1836
|
+
grantId: value.row.grantId,
|
|
1837
|
+
inputHash,
|
|
1838
|
+
value
|
|
1839
|
+
}, this.now());
|
|
1840
|
+
return value;
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
idempotent(context, capability, bookId, operation) {
|
|
1844
|
+
return this.options.store.transaction(() => {
|
|
1845
|
+
this.requireGrantedBook(context.subjectId, bookId);
|
|
1846
|
+
const key = JSON.stringify([
|
|
1847
|
+
"subject-write-v1",
|
|
1848
|
+
context.subjectId,
|
|
1849
|
+
capability,
|
|
1850
|
+
context.callId
|
|
1851
|
+
]);
|
|
1852
|
+
const existing = this.options.store.getWorkspaceReceipt(key);
|
|
1853
|
+
if (existing !== void 0) {
|
|
1854
|
+
const receipt = objectRecord(existing);
|
|
1855
|
+
if (!receipt || receipt.bookId !== bookId) throw new Error("finance_call_book_mismatch");
|
|
1856
|
+
return receipt.value;
|
|
1857
|
+
}
|
|
1858
|
+
const result = operation();
|
|
1859
|
+
this.options.store.saveWorkspaceReceipt(key, {
|
|
1860
|
+
bookId,
|
|
1861
|
+
value: result
|
|
1862
|
+
}, this.now());
|
|
1863
|
+
return result;
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
/** 读侧富化:条目投影 + 账本名称解析 + update/delete/matched 目标的 original 快照。 */
|
|
1868
|
+
function enrichDraftEntries(entries, bookId, ledger) {
|
|
1869
|
+
const metadata = objectRecord(ledger.cachedMetadata(bookId));
|
|
1870
|
+
const indexes = {
|
|
1871
|
+
accounts: metadataNameIndex(metadata?.accounts),
|
|
1872
|
+
categories: metadataNameIndex(metadata?.categories),
|
|
1873
|
+
projects: metadataNameIndex(metadata?.projects),
|
|
1874
|
+
members: metadataNameIndex(metadata?.members),
|
|
1875
|
+
stores: metadataNameIndex(metadata?.stores)
|
|
1876
|
+
};
|
|
1877
|
+
const name = (index, id) => id ? index.get(id) : void 0;
|
|
1878
|
+
return entries.map((entry) => {
|
|
1879
|
+
const projected = {
|
|
1880
|
+
...projectDraftEntry(entry),
|
|
1881
|
+
validationIssues: entry.validationIssues ?? []
|
|
1882
|
+
};
|
|
1883
|
+
const presentation = projected.presentation ?? {
|
|
1884
|
+
title: entry.id,
|
|
1885
|
+
direction: "neutral"
|
|
1886
|
+
};
|
|
1887
|
+
const accountName = name(indexes.accounts, presentation.accountId);
|
|
1888
|
+
const destinationAccountName = name(indexes.accounts, presentation.destinationAccountId);
|
|
1889
|
+
const categoryName = name(indexes.categories, presentation.categoryId);
|
|
1890
|
+
const projectName = name(indexes.projects, presentation.projectId);
|
|
1891
|
+
const memberName = name(indexes.members, presentation.memberId);
|
|
1892
|
+
const storeName = name(indexes.stores, presentation.storeId);
|
|
1893
|
+
const remoteId = entry.draft?.operation === "update" || entry.draft?.operation === "delete" || entry.draft?.operation === "matched" ? entry.draft.remoteId : void 0;
|
|
1894
|
+
const original = remoteId ? ledger.getTransaction(bookId, remoteId) : void 0;
|
|
1895
|
+
const originalAccountName = original?.accountName ?? name(indexes.accounts, original?.accountId);
|
|
1896
|
+
const originalDestinationAccountName = original?.destinationAccountName ?? name(indexes.accounts, original?.destinationAccountId);
|
|
1897
|
+
const originalCategoryName = original?.categoryName ?? name(indexes.categories, original?.categoryId);
|
|
1898
|
+
const originalProjectName = original?.projectName ?? name(indexes.projects, original?.projectId);
|
|
1899
|
+
const originalMemberName = original?.memberName ?? name(indexes.members, original?.memberId);
|
|
1900
|
+
const originalStoreName = name(indexes.stores, original?.storeId);
|
|
1901
|
+
return {
|
|
1902
|
+
...projected,
|
|
1903
|
+
presentation: {
|
|
1904
|
+
...presentation,
|
|
1905
|
+
...accountName ? { accountName } : {},
|
|
1906
|
+
...destinationAccountName ? { destinationAccountName } : {},
|
|
1907
|
+
...categoryName ? { categoryName } : {},
|
|
1908
|
+
...projectName ? { projectName } : {},
|
|
1909
|
+
...memberName ? { memberName } : {},
|
|
1910
|
+
...storeName ? { storeName } : {},
|
|
1911
|
+
...original ? { original: {
|
|
1912
|
+
occurredAt: original.occurredAt,
|
|
1913
|
+
type: original.type,
|
|
1914
|
+
amountCents: original.amountCents,
|
|
1915
|
+
...original.accountId ? { accountId: original.accountId } : {},
|
|
1916
|
+
...originalAccountName ? { accountName: originalAccountName } : {},
|
|
1917
|
+
...original.destinationAccountId ? { destinationAccountId: original.destinationAccountId } : {},
|
|
1918
|
+
...originalDestinationAccountName ? { destinationAccountName: originalDestinationAccountName } : {},
|
|
1919
|
+
...original.categoryId ? { categoryId: original.categoryId } : {},
|
|
1920
|
+
...originalCategoryName ? { categoryName: originalCategoryName } : {},
|
|
1921
|
+
...original.projectId ? { projectId: original.projectId } : {},
|
|
1922
|
+
...originalProjectName ? { projectName: originalProjectName } : {},
|
|
1923
|
+
...original.memberId ? { memberId: original.memberId } : {},
|
|
1924
|
+
...originalMemberName ? { memberName: originalMemberName } : {},
|
|
1925
|
+
...original.storeId ? { storeId: original.storeId } : {},
|
|
1926
|
+
...originalStoreName ? { storeName: originalStoreName } : {},
|
|
1927
|
+
...original.transactionName ?? original.content ? { merchant: original.transactionName ?? original.content } : {},
|
|
1928
|
+
...original.memo ? { memo: original.memo } : {}
|
|
1929
|
+
} } : {}
|
|
1930
|
+
}
|
|
1931
|
+
};
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
function metadataNameIndex(value) {
|
|
1935
|
+
return new Map((Array.isArray(value) ? value : []).flatMap((item) => {
|
|
1936
|
+
const record = objectRecord(item);
|
|
1937
|
+
return typeof record?.id === "string" && typeof record.name === "string" ? [[record.id, record.name]] : [];
|
|
1938
|
+
}));
|
|
1939
|
+
}
|
|
1940
|
+
function draftReferenceData(value) {
|
|
1941
|
+
const metadata = objectRecord(value);
|
|
1942
|
+
const collection = (key) => (Array.isArray(metadata?.[key]) ? metadata[key] : []).flatMap((item) => {
|
|
1943
|
+
const record = objectRecord(item);
|
|
1944
|
+
return typeof record?.id === "string" && typeof record.name === "string" ? [{
|
|
1945
|
+
id: record.id,
|
|
1946
|
+
name: record.name
|
|
1947
|
+
}] : [];
|
|
1948
|
+
});
|
|
1949
|
+
const categoryRecords = (Array.isArray(metadata?.categories) ? metadata.categories : []).map(objectRecord).filter((item) => Boolean(item)).filter((item) => typeof item.id === "string" && typeof item.name === "string");
|
|
1950
|
+
const byId = new Map(categoryRecords.map((item) => [String(item.id), item]));
|
|
1951
|
+
const childrenOf = (id) => categoryRecords.filter((item) => item.parentId === id);
|
|
1952
|
+
const categories = categoryRecords.map((item) => {
|
|
1953
|
+
const id = String(item.id);
|
|
1954
|
+
const name = String(item.name);
|
|
1955
|
+
const parentId = typeof item.parentId === "string" ? item.parentId : void 0;
|
|
1956
|
+
const parent = parentId ? byId.get(parentId) : void 0;
|
|
1957
|
+
const parentName = typeof parent?.name === "string" ? parent.name : void 0;
|
|
1958
|
+
const selectableForTransaction = Boolean(parentId && parent && !parent.parentId && childrenOf(id).length === 0);
|
|
1959
|
+
return {
|
|
1960
|
+
id,
|
|
1961
|
+
name,
|
|
1962
|
+
...parentId ? { parentId } : {},
|
|
1963
|
+
...parentName ? { parentName } : {},
|
|
1964
|
+
level: parentId ? 2 : 1,
|
|
1965
|
+
path: parentName ? [parentName, name] : [name],
|
|
1966
|
+
selectableForTransaction,
|
|
1967
|
+
...!parentId ? { children: childrenOf(id).flatMap((child) => {
|
|
1968
|
+
if (typeof child.id !== "string" || typeof child.name !== "string" || childrenOf(child.id).length > 0) return [];
|
|
1969
|
+
return [{
|
|
1970
|
+
id: child.id,
|
|
1971
|
+
name: child.name,
|
|
1972
|
+
path: [name, child.name],
|
|
1973
|
+
selectableForTransaction: true
|
|
1974
|
+
}];
|
|
1975
|
+
}) } : {}
|
|
1976
|
+
};
|
|
1977
|
+
});
|
|
1978
|
+
return {
|
|
1979
|
+
accounts: collection("accounts"),
|
|
1980
|
+
categories,
|
|
1981
|
+
projects: collection("projects"),
|
|
1982
|
+
members: collection("members"),
|
|
1983
|
+
stores: collection("stores")
|
|
1984
|
+
};
|
|
1985
|
+
}
|
|
1986
|
+
function validateTrustedWorksetMutationScope(workset, changes, accountFor) {
|
|
1987
|
+
if (changes.length <= 1) return;
|
|
1988
|
+
const operation = changes[0]?.operation;
|
|
1989
|
+
if (changes.some((change) => change.operation !== operation)) throw new Error("finance_workset_batch_scope_invalid");
|
|
1990
|
+
const requested = new Set(changes.map((change) => change.entryId));
|
|
1991
|
+
const exact = (entries) => entries.length === requested.size && entries.every((entry) => requested.has(entry.id));
|
|
1992
|
+
if (operation === "remove") {
|
|
1993
|
+
if (!exact(workset.entries.filter((entry) => entry.state === "changed" && !entry.lockedCommitId))) throw new Error("finance_workset_batch_scope_invalid");
|
|
1994
|
+
return;
|
|
1995
|
+
}
|
|
1996
|
+
if (operation !== "stage" && operation !== "unstage") throw new Error("finance_workset_batch_scope_invalid");
|
|
1997
|
+
const targetState = operation === "stage" ? "changed" : "staged";
|
|
1998
|
+
const eligible = workset.entries.filter((entry) => entry.state === targetState && !entry.lockedCommitId);
|
|
1999
|
+
if (exact(eligible)) return;
|
|
2000
|
+
const byAccount = /* @__PURE__ */ new Map();
|
|
2001
|
+
for (const entry of eligible) {
|
|
2002
|
+
const account = accountFor(entry) ?? `__unresolved__:${entry.id}`;
|
|
2003
|
+
const group = byAccount.get(account) ?? [];
|
|
2004
|
+
group.push(entry);
|
|
2005
|
+
byAccount.set(account, group);
|
|
2006
|
+
}
|
|
2007
|
+
if (![...byAccount.values()].some(exact)) throw new Error("finance_workset_batch_scope_invalid");
|
|
2008
|
+
}
|
|
2009
|
+
function draftEvidence(row, entry, recordedAt) {
|
|
2010
|
+
return {
|
|
2011
|
+
subjectId: row.subjectId,
|
|
2012
|
+
callId: `draft:${row.id}:${entry.id}`,
|
|
2013
|
+
source: {
|
|
2014
|
+
type: "conversation",
|
|
2015
|
+
runId: row.subjectId
|
|
2016
|
+
},
|
|
2017
|
+
summary: "",
|
|
2018
|
+
recordedAt
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
2021
|
+
function draftEntryId(rowId, entryId) {
|
|
2022
|
+
return `draft-entry-${sha256(`${rowId}\u0000${entryId}`).slice(0, 32)}`;
|
|
2023
|
+
}
|
|
2024
|
+
function evidenceFor(context, evidence, recordedAt) {
|
|
2025
|
+
if ([
|
|
2026
|
+
"taskId",
|
|
2027
|
+
"runId",
|
|
2028
|
+
"subjectId",
|
|
2029
|
+
"callId"
|
|
2030
|
+
].some((key) => key in evidence)) throw new Error("finance_evidence_actor_forbidden");
|
|
2031
|
+
if (!evidence.summary.trim()) throw new Error("finance_evidence_summary_required");
|
|
2032
|
+
return {
|
|
2033
|
+
...evidence,
|
|
2034
|
+
source: validateSourceReference(evidence.source),
|
|
2035
|
+
subjectId: context.subjectId,
|
|
2036
|
+
callId: context.callId,
|
|
2037
|
+
recordedAt
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
function assertMutationContext(context) {
|
|
2041
|
+
if ("taskId" in context || "runId" in context || "subjectType" in context || typeof context.subjectId !== "string" || !context.subjectId.trim() || typeof context.callId !== "string" || !context.callId.trim()) throw new Error("finance_write_context_invalid");
|
|
2042
|
+
}
|
|
2043
|
+
function validateSourceReference(value) {
|
|
2044
|
+
const source = objectRecord(value);
|
|
2045
|
+
if (!source || typeof source.type !== "string") throw new Error("finance_source_reference_invalid");
|
|
2046
|
+
if (source.type === "task-attachment") throw new Error("finance_legacy_source_not_writable");
|
|
2047
|
+
const result = source.type === "conversation" && nonEmpty(source.runId) ? {
|
|
2048
|
+
type: "conversation",
|
|
2049
|
+
runId: source.runId
|
|
2050
|
+
} : source.type === "conversation-attachment" && nonEmpty(source.runId) && nonEmpty(source.attachmentId) ? {
|
|
2051
|
+
type: "conversation-attachment",
|
|
2052
|
+
runId: source.runId,
|
|
2053
|
+
attachmentId: source.attachmentId
|
|
2054
|
+
} : source.type === "message" && nonEmpty(source.messageId) ? {
|
|
2055
|
+
type: "message",
|
|
2056
|
+
messageId: source.messageId
|
|
2057
|
+
} : source.type === "message-attachment" && nonEmpty(source.messageId) && nonEmpty(source.attachmentId) ? {
|
|
2058
|
+
type: "message-attachment",
|
|
2059
|
+
messageId: source.messageId,
|
|
2060
|
+
attachmentId: source.attachmentId
|
|
2061
|
+
} : void 0;
|
|
2062
|
+
if (!result || Object.keys(source).length !== Object.keys(result).length) throw new Error("finance_source_reference_invalid");
|
|
2063
|
+
return result;
|
|
2064
|
+
}
|
|
2065
|
+
function nonEmpty(value) {
|
|
2066
|
+
return typeof value === "string" && Boolean(value.trim());
|
|
2067
|
+
}
|
|
2068
|
+
function objectRecord(value) {
|
|
2069
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
2070
|
+
}
|
|
2071
|
+
function validateProposal(proposal) {
|
|
2072
|
+
if (!proposal || typeof proposal !== "object" || ![
|
|
2073
|
+
"create",
|
|
2074
|
+
"update",
|
|
2075
|
+
"delete"
|
|
2076
|
+
].includes(proposal.operation)) throw new Error("finance_proposal_invalid");
|
|
2077
|
+
if (proposal.operation === "create") {
|
|
2078
|
+
const transaction = objectRecord(proposal.transaction);
|
|
2079
|
+
if (transaction?.type === "transfer" && transaction.categoryId !== void 0 && transaction.categoryId !== null) throw new Error("finance_transfer_category_forbidden");
|
|
2080
|
+
assertKnownTransactionFields(proposal.transaction, "finance_create_proposal_invalid");
|
|
2081
|
+
validateTransactionShape(proposal.transaction, "finance_create_proposal_invalid");
|
|
2082
|
+
} else if (typeof proposal.remoteId !== "string" || !proposal.remoteId.trim()) throw new Error("finance_remote_id_required");
|
|
2083
|
+
else if (proposal.operation === "update") validateUpdatePatch(proposal.patch);
|
|
2084
|
+
return proposal;
|
|
2085
|
+
}
|
|
2086
|
+
const TRANSACTION_PATCH_KEYS = /* @__PURE__ */ new Set([
|
|
2087
|
+
"occurredAt",
|
|
2088
|
+
"type",
|
|
2089
|
+
"amountCents",
|
|
2090
|
+
"secondaryAmountCents",
|
|
2091
|
+
"currency",
|
|
2092
|
+
"secondaryCurrency",
|
|
2093
|
+
"accountId",
|
|
2094
|
+
"destinationAccountId",
|
|
2095
|
+
"categoryId",
|
|
2096
|
+
"projectId",
|
|
2097
|
+
"memberId",
|
|
2098
|
+
"storeId",
|
|
2099
|
+
"memo"
|
|
2100
|
+
]);
|
|
2101
|
+
function assertKnownTransactionFields(value, error) {
|
|
2102
|
+
const transaction = objectRecord(value);
|
|
2103
|
+
if (!transaction || Object.keys(transaction).some((key) => !TRANSACTION_PATCH_KEYS.has(key))) throw new Error(error);
|
|
2104
|
+
}
|
|
2105
|
+
function validateUpdatePatch(value) {
|
|
2106
|
+
const patch = objectRecord(value);
|
|
2107
|
+
if (!patch || Object.keys(patch).length === 0) throw new Error("finance_update_patch_required");
|
|
2108
|
+
if (Object.keys(patch).some((key) => !TRANSACTION_PATCH_KEYS.has(key))) throw new Error("finance_update_proposal_invalid");
|
|
2109
|
+
normalizeUpdatePatch(patch, "finance_update_proposal_invalid");
|
|
2110
|
+
}
|
|
2111
|
+
function validateTransactionShape(value, error) {
|
|
2112
|
+
const transaction = objectRecord(value);
|
|
2113
|
+
if (!transaction) throw new Error(error);
|
|
2114
|
+
strictCreateRequest(transaction, "finance:proposal-validation", error);
|
|
2115
|
+
for (const field of ["currency", "secondaryCurrency"]) if (transaction[field] !== void 0 && (typeof transaction[field] !== "string" || !transaction[field].trim())) throw new Error(error);
|
|
2116
|
+
if (transaction.type === "transfer" && transaction.currency && transaction.secondaryCurrency && transaction.currency !== transaction.secondaryCurrency && transaction.secondaryAmountCents === void 0) throw new Error("finance_cross_currency_transfer_amount_required");
|
|
2117
|
+
}
|
|
2118
|
+
function strictCreateRequest(value, clientRequestId, error) {
|
|
2119
|
+
if (typeof value.occurredAt === "string") assertWriteTimePrecision(value.occurredAt);
|
|
2120
|
+
const { currency: _currency, secondaryCurrency: _secondaryCurrency, ...writeFields } = value;
|
|
2121
|
+
const parsed = createTransactionInputSchema.safeParse({
|
|
2122
|
+
...writeFields,
|
|
2123
|
+
clientRequestId
|
|
2124
|
+
});
|
|
2125
|
+
if (!parsed.success) throw new Error(error);
|
|
2126
|
+
return parsed.data;
|
|
2127
|
+
}
|
|
2128
|
+
function normalizeUpdatePatch(value, error) {
|
|
2129
|
+
const patch = objectRecord(value);
|
|
2130
|
+
if (!patch) throw new Error(error);
|
|
2131
|
+
if (typeof patch.occurredAt === "string") assertWriteTimePrecision(patch.occurredAt);
|
|
2132
|
+
const { currency: _currency, secondaryCurrency: _secondaryCurrency, ...writeFields } = patch;
|
|
2133
|
+
const parsed = updateTransactionPatchSchema.safeParse(writeFields);
|
|
2134
|
+
if (!parsed.success) throw new Error(error);
|
|
2135
|
+
return parsed.data;
|
|
2136
|
+
}
|
|
2137
|
+
function validateFrozenTransaction(input, metadata, error) {
|
|
2138
|
+
assertWriteTimePrecision(input.occurredAt);
|
|
2139
|
+
if (!createTransactionInputSchema.safeParse({
|
|
2140
|
+
...input,
|
|
2141
|
+
clientRequestId: "finance:prepare-validation"
|
|
2142
|
+
}).success) throw new Error(error);
|
|
2143
|
+
try {
|
|
2144
|
+
validateTransactionMetadata(input, metadata);
|
|
2145
|
+
} catch {
|
|
2146
|
+
throw new Error(error);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
function financeBookMetadata(value) {
|
|
2150
|
+
const metadata = objectRecord(value);
|
|
2151
|
+
const collection = (key) => Array.isArray(metadata?.[key]) ? metadata[key] : [];
|
|
2152
|
+
return {
|
|
2153
|
+
accounts: collection("accounts"),
|
|
2154
|
+
categories: collection("categories"),
|
|
2155
|
+
projects: collection("projects"),
|
|
2156
|
+
members: collection("members"),
|
|
2157
|
+
stores: collection("stores")
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
function proposalCategoryId(proposal) {
|
|
2161
|
+
if (proposal.operation === "create") return proposal.transaction.type === "transfer" ? void 0 : proposal.transaction.categoryId;
|
|
2162
|
+
if (proposal.operation === "update" && typeof proposal.patch.categoryId === "string") return proposal.patch.categoryId;
|
|
2163
|
+
}
|
|
2164
|
+
function proposalCategoryValidation(items, metadata) {
|
|
2165
|
+
const categoriesById = new Map(metadata.categories.map((category) => [category.id, category]));
|
|
2166
|
+
const issues = items.flatMap((item) => {
|
|
2167
|
+
if (!item.proposal || item.proposal.operation === "delete") return [];
|
|
2168
|
+
const explicitCategoryId = item.proposal.operation === "create" ? item.proposal.transaction.categoryId : item.proposal.operation === "update" && typeof item.proposal.patch.categoryId === "string" ? item.proposal.patch.categoryId : void 0;
|
|
2169
|
+
if (item.effectiveType === "transfer") {
|
|
2170
|
+
if (!explicitCategoryId) return [];
|
|
2171
|
+
return [{
|
|
2172
|
+
entryId: item.id,
|
|
2173
|
+
code: "transaction_category_not_leaf",
|
|
2174
|
+
categoryId: explicitCategoryId,
|
|
2175
|
+
message: "转账不能设置分类;请只提供来源账户和目标账户。"
|
|
2176
|
+
}];
|
|
2177
|
+
}
|
|
2178
|
+
const categoryId = proposalCategoryId(item.proposal) ?? item.effectiveCategoryId;
|
|
2179
|
+
if (!categoryId && item.effectiveType !== "expense" && item.effectiveType !== "income") return [];
|
|
2180
|
+
if (categoryId && isTransactionCategory(metadata.categories, categoryId)) return [];
|
|
2181
|
+
const category = categoryId ? categoriesById.get(categoryId) : void 0;
|
|
2182
|
+
return [{
|
|
2183
|
+
entryId: item.id,
|
|
2184
|
+
code: "transaction_category_not_leaf",
|
|
2185
|
+
categoryId: categoryId ?? "",
|
|
2186
|
+
...category?.name ? { categoryName: category.name } : {},
|
|
2187
|
+
message: category ? `“${category.name}”是一级分类或分类层级不完整,请选择具体的二级分类。` : categoryId ? "这项分类已不存在或分类资料不完整,请重新选择具体的二级分类。" : "收入和支出必须选择具体的二级分类。"
|
|
2188
|
+
}];
|
|
2189
|
+
});
|
|
2190
|
+
return {
|
|
2191
|
+
valid: issues.length === 0,
|
|
2192
|
+
issues
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
function proposalFinancialPayload(proposal, current) {
|
|
2196
|
+
if (proposal.operation === "delete") return void 0;
|
|
2197
|
+
if (proposal.operation === "create") return createInputFinancialPayload(strictCreateRequest(proposal.transaction, "finance:proposal-validation", "finance_create_proposal_invalid"));
|
|
2198
|
+
if (!current) throw new Error("finance_transaction_target_missing");
|
|
2199
|
+
return mergeTransactionPatch(current, normalizeUpdatePatch(proposal.patch, "finance_update_proposal_invalid"));
|
|
2200
|
+
}
|
|
2201
|
+
function proposalValidation(id, proposal, metadata, current) {
|
|
2202
|
+
const invalid = (code, message) => ({
|
|
2203
|
+
valid: false,
|
|
2204
|
+
issues: [{
|
|
2205
|
+
entryId: id,
|
|
2206
|
+
code,
|
|
2207
|
+
message
|
|
2208
|
+
}]
|
|
2209
|
+
});
|
|
2210
|
+
if (proposal.operation !== "create" && !current) return invalid("transaction_target_missing", "原流水已不存在,请重新核对修改目标。");
|
|
2211
|
+
let effective;
|
|
2212
|
+
try {
|
|
2213
|
+
validateProposal(proposal);
|
|
2214
|
+
effective = proposalFinancialPayload(proposal, current);
|
|
2215
|
+
if (effective) assertWriteTimePrecision(effective.occurredAt);
|
|
2216
|
+
} catch (error) {
|
|
2217
|
+
if (error instanceof WriteBoundaryError && error.cause instanceof FeideeError && error.cause.code === "INVALID_TIME_PRECISION") return invalid("transaction_time_precision_invalid", "流水时间必须带明确时区并精确到秒;请修正非零小数秒,不会自动截断时间。");
|
|
2218
|
+
return invalid("transaction_proposal_invalid", "流水修改内容不完整或格式不合法,请重新核对。");
|
|
2219
|
+
}
|
|
2220
|
+
if (!effective) return {
|
|
2221
|
+
valid: true,
|
|
2222
|
+
issues: []
|
|
2223
|
+
};
|
|
2224
|
+
const category = proposalCategoryValidation([{
|
|
2225
|
+
id,
|
|
2226
|
+
proposal,
|
|
2227
|
+
effectiveType: effective.type,
|
|
2228
|
+
...effective.categoryId ? { effectiveCategoryId: effective.categoryId } : {}
|
|
2229
|
+
}], metadata);
|
|
2230
|
+
if (!category.valid) return category;
|
|
2231
|
+
const fields = proposal.operation === "create" ? proposal.transaction : proposal.operation === "update" ? proposal.patch : {};
|
|
2232
|
+
if (effective.type !== "transfer" && fields.secondaryCurrency !== void 0) return invalid("transaction_currency_mismatch", "非转账流水不能设置目标币种。");
|
|
2233
|
+
const accounts = [{
|
|
2234
|
+
id: effective.accountId,
|
|
2235
|
+
currency: fields.currency
|
|
2236
|
+
}, ...effective.type === "transfer" ? [{
|
|
2237
|
+
id: effective.destinationAccountId,
|
|
2238
|
+
currency: fields.secondaryCurrency
|
|
2239
|
+
}] : []];
|
|
2240
|
+
for (const selection of accounts) {
|
|
2241
|
+
const account = metadata.accounts.find((item) => item.id === selection.id);
|
|
2242
|
+
if (!account || account.hidden || account.accountKind === "multiCurrencyParent") return invalid("transaction_account_unavailable", "流水账户不存在、已隐藏或不是可用的币种子账户。");
|
|
2243
|
+
if (selection.currency !== void 0 && (typeof selection.currency !== "string" || !selection.currency.trim() || !account.currency || selection.currency !== account.currency)) return invalid("transaction_currency_mismatch", "流水币种与所选账户币种不一致,请核对金额和账户。");
|
|
2244
|
+
}
|
|
2245
|
+
try {
|
|
2246
|
+
validateTransactionMetadata(effective, metadata);
|
|
2247
|
+
} catch {
|
|
2248
|
+
return invalid("transaction_proposal_invalid", "流水字段与当前账本不一致,请核对分类、转账两端、金额及关联资料。");
|
|
2249
|
+
}
|
|
2250
|
+
return {
|
|
2251
|
+
valid: true,
|
|
2252
|
+
issues: []
|
|
2253
|
+
};
|
|
2254
|
+
}
|
|
2255
|
+
function draftProposalValidation(entries, metadata, bookId, ledger) {
|
|
2256
|
+
const issues = entries.flatMap((entry) => {
|
|
2257
|
+
if (!entry.proposal) return [];
|
|
2258
|
+
const current = entry.proposal.operation !== "create" ? ledger.getTransaction(bookId, entry.proposal.remoteId) : void 0;
|
|
2259
|
+
return proposalValidation(entry.id, entry.proposal, metadata, current).issues;
|
|
2260
|
+
});
|
|
2261
|
+
return {
|
|
2262
|
+
valid: issues.length === 0,
|
|
2263
|
+
issues
|
|
2264
|
+
};
|
|
2265
|
+
}
|
|
2266
|
+
function entryCategoryValidation(entries, presentations, metadata) {
|
|
2267
|
+
const byEntryId = new Map(presentations.map((presentation) => [presentation.entryId, presentation]));
|
|
2268
|
+
return proposalCategoryValidation(entries.map((entry) => {
|
|
2269
|
+
const presentation = byEntryId.get(entry.id);
|
|
2270
|
+
return {
|
|
2271
|
+
id: entry.id,
|
|
2272
|
+
proposal: entry.proposal,
|
|
2273
|
+
...presentation?.type ? { effectiveType: presentation.type } : {},
|
|
2274
|
+
...presentation?.categoryId ? { effectiveCategoryId: presentation.categoryId } : {}
|
|
2275
|
+
};
|
|
2276
|
+
}), metadata);
|
|
2277
|
+
}
|
|
2278
|
+
function assertProposalValid(proposal, metadata, current) {
|
|
2279
|
+
assertProposalValidation(proposalValidation("proposal", proposal, metadata, current));
|
|
2280
|
+
}
|
|
2281
|
+
function assertEntryProposalValid(entry, metadata, ledger) {
|
|
2282
|
+
const current = entry.proposal.operation !== "create" ? ledger.getTransaction(entry.bookId, entry.proposal.remoteId) : void 0;
|
|
2283
|
+
assertProposalValidation(proposalValidation(entry.id, entry.proposal, metadata, current));
|
|
2284
|
+
}
|
|
2285
|
+
function assertProposalValidation(validation) {
|
|
2286
|
+
const issue = validation.issues[0];
|
|
2287
|
+
if (issue) throw new Error(`finance_${issue.code}`);
|
|
2288
|
+
}
|
|
2289
|
+
function assertDraftProposalsValid(entries, metadata, bookId, ledger) {
|
|
2290
|
+
assertProposalValidation(draftProposalValidation(entries, metadata, bookId, ledger));
|
|
2291
|
+
}
|
|
2292
|
+
function freezeOperation(commitId, id, sequence, proposal, entryId, bookId, metadata, current) {
|
|
2293
|
+
if (proposal.operation === "create") {
|
|
2294
|
+
const request = strictCreateRequest(proposal.transaction, `finance:${commitId}:${id}`, "finance_create_proposal_invalid");
|
|
2295
|
+
validateFrozenTransaction(createInputFinancialPayload(request), metadata, "finance_create_proposal_invalid");
|
|
2296
|
+
return {
|
|
2297
|
+
id,
|
|
2298
|
+
commitId,
|
|
2299
|
+
entryId,
|
|
2300
|
+
sequence,
|
|
2301
|
+
operation: "create",
|
|
2302
|
+
bookId,
|
|
2303
|
+
request,
|
|
2304
|
+
status: "pending"
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
if (!current) throw new Error(`finance_transaction_not_found:${proposal.remoteId}`);
|
|
2308
|
+
const before = transactionRecord(current);
|
|
2309
|
+
if (proposal.operation === "update") {
|
|
2310
|
+
const patch = normalizeUpdatePatch(proposal.patch, "finance_update_proposal_invalid");
|
|
2311
|
+
const request = {
|
|
2312
|
+
expectedContentHash: current.contentHash,
|
|
2313
|
+
patch
|
|
2314
|
+
};
|
|
2315
|
+
if (!updateTransactionInputSchema.safeParse(request).success) throw new Error("finance_update_proposal_invalid");
|
|
2316
|
+
validateFrozenTransaction(mergeTransactionPatch(current, patch), metadata, "finance_update_proposal_invalid");
|
|
2317
|
+
return {
|
|
2318
|
+
id,
|
|
2319
|
+
commitId,
|
|
2320
|
+
entryId,
|
|
2321
|
+
sequence,
|
|
2322
|
+
operation: "update",
|
|
2323
|
+
bookId,
|
|
2324
|
+
targetRemoteId: proposal.remoteId,
|
|
2325
|
+
request,
|
|
2326
|
+
before,
|
|
2327
|
+
status: "pending"
|
|
2328
|
+
};
|
|
2329
|
+
}
|
|
2330
|
+
return {
|
|
2331
|
+
id,
|
|
2332
|
+
commitId,
|
|
2333
|
+
entryId,
|
|
2334
|
+
sequence,
|
|
2335
|
+
operation: "delete",
|
|
2336
|
+
bookId,
|
|
2337
|
+
targetRemoteId: proposal.remoteId,
|
|
2338
|
+
request: { expectedContentHash: current.contentHash },
|
|
2339
|
+
before,
|
|
2340
|
+
status: "pending"
|
|
2341
|
+
};
|
|
2342
|
+
}
|
|
2343
|
+
function entryPresentation(entry, current, metadata) {
|
|
2344
|
+
const originalRecord = entry.proposal.operation === "update" && current ? transactionRecord(current) : void 0;
|
|
2345
|
+
let value;
|
|
2346
|
+
if (entry.proposal.operation === "create") value = entry.proposal.transaction;
|
|
2347
|
+
else {
|
|
2348
|
+
if (!current) throw new Error(`finance_transaction_not_found:${entry.proposal.remoteId}`);
|
|
2349
|
+
value = transactionRecord(current);
|
|
2350
|
+
if (entry.proposal.operation === "update") value = { ...mergeTransactionPatch(current, normalizeUpdatePatch(entry.proposal.patch, "finance_update_proposal_invalid")) };
|
|
2351
|
+
}
|
|
2352
|
+
const snapshot = (record) => {
|
|
2353
|
+
const type = record.type === "expense" || record.type === "income" || record.type === "transfer" ? record.type : "other";
|
|
2354
|
+
const optionalString = (field) => typeof record[field] === "string" && record[field] ? String(record[field]) : void 0;
|
|
2355
|
+
const optionalInteger = (field) => Number.isSafeInteger(record[field]) ? Number(record[field]) : void 0;
|
|
2356
|
+
const accountId = optionalString("accountId");
|
|
2357
|
+
const destinationAccountId = optionalString("destinationAccountId");
|
|
2358
|
+
const secondaryAmountCents = optionalInteger("secondaryAmountCents");
|
|
2359
|
+
const metadataAccounts = Array.isArray(metadata?.accounts) ? metadata.accounts.map(objectRecord).filter(Boolean) : [];
|
|
2360
|
+
const accountCurrency = (account) => {
|
|
2361
|
+
if (!account) return void 0;
|
|
2362
|
+
const definition = metadataAccounts.find((item) => item.id === account);
|
|
2363
|
+
return typeof definition?.currency === "string" ? definition.currency : void 0;
|
|
2364
|
+
};
|
|
2365
|
+
const currency = optionalString("currency") ?? accountCurrency(accountId);
|
|
2366
|
+
const secondaryCurrency = optionalString("secondaryCurrency") ?? accountCurrency(destinationAccountId);
|
|
2367
|
+
const categoryId = optionalString("categoryId");
|
|
2368
|
+
const projectId = optionalString("projectId");
|
|
2369
|
+
const memberId = optionalString("memberId");
|
|
2370
|
+
const storeId = optionalString("storeId");
|
|
2371
|
+
const memo = optionalString("memo");
|
|
2372
|
+
const named = (collection, id) => {
|
|
2373
|
+
if (!id || !Array.isArray(collection)) return void 0;
|
|
2374
|
+
const match = collection.map(objectRecord).find((item) => item?.id === id);
|
|
2375
|
+
return typeof match?.name === "string" ? match.name : void 0;
|
|
2376
|
+
};
|
|
2377
|
+
const accountName = named(metadata?.accounts, accountId);
|
|
2378
|
+
const destinationAccountName = named(metadata?.accounts, destinationAccountId);
|
|
2379
|
+
const categoryName = named(metadata?.categories, categoryId);
|
|
2380
|
+
const projectName = named(metadata?.projects, projectId);
|
|
2381
|
+
const memberName = named(metadata?.members, memberId);
|
|
2382
|
+
const storeName = named(metadata?.stores, storeId);
|
|
2383
|
+
return {
|
|
2384
|
+
...accountId ? { accountId } : {},
|
|
2385
|
+
...accountName ? { accountName } : {},
|
|
2386
|
+
...destinationAccountId ? { destinationAccountId } : {},
|
|
2387
|
+
...destinationAccountName ? { destinationAccountName } : {},
|
|
2388
|
+
occurredAt: optionalString("occurredAt") ?? entry.updatedAt,
|
|
2389
|
+
type,
|
|
2390
|
+
amountCents: optionalInteger("amountCents") ?? 0,
|
|
2391
|
+
...secondaryAmountCents !== void 0 ? { secondaryAmountCents } : {},
|
|
2392
|
+
...currency ? { currency } : {},
|
|
2393
|
+
...secondaryCurrency ? { secondaryCurrency } : {},
|
|
2394
|
+
...categoryId ? { categoryId } : {},
|
|
2395
|
+
...categoryName ? { categoryName } : {},
|
|
2396
|
+
...projectId ? { projectId } : {},
|
|
2397
|
+
...projectName ? { projectName } : {},
|
|
2398
|
+
...memberId ? { memberId } : {},
|
|
2399
|
+
...memberName ? { memberName } : {},
|
|
2400
|
+
...storeId ? { storeId } : {},
|
|
2401
|
+
...storeName ? { storeName } : {},
|
|
2402
|
+
...memo ? { memo } : {}
|
|
2403
|
+
};
|
|
2404
|
+
};
|
|
2405
|
+
const original = originalRecord ? snapshot(originalRecord) : void 0;
|
|
2406
|
+
return {
|
|
2407
|
+
entryId: entry.id,
|
|
2408
|
+
...snapshot(value),
|
|
2409
|
+
...original ? { original } : {}
|
|
2410
|
+
};
|
|
2411
|
+
}
|
|
2412
|
+
async function executeOperation(ledger, operation, attempt) {
|
|
2413
|
+
if (operation.operation === "create") {
|
|
2414
|
+
const request = createTransactionInputSchema.safeParse(operation.request);
|
|
2415
|
+
if (!request.success) throw new Error("finance_commit_request_invalid");
|
|
2416
|
+
return ledger.createTransaction(operation.bookId, request.data, attempt);
|
|
2417
|
+
}
|
|
2418
|
+
if (!operation.targetRemoteId) throw new Error("finance_commit_target_missing");
|
|
2419
|
+
if (operation.operation === "update") {
|
|
2420
|
+
const request = updateTransactionInputSchema.safeParse(operation.request);
|
|
2421
|
+
if (!request.success) throw new Error("finance_commit_request_invalid");
|
|
2422
|
+
return ledger.updateTransaction(operation.bookId, operation.targetRemoteId, request.data, attempt, operation.before);
|
|
2423
|
+
}
|
|
2424
|
+
const request = deleteTransactionInputSchema.safeParse(operation.request);
|
|
2425
|
+
if (!request.success) throw new Error("finance_commit_request_invalid");
|
|
2426
|
+
return ledger.deleteTransaction(operation.bookId, operation.targetRemoteId, request.data, attempt);
|
|
2427
|
+
}
|
|
2428
|
+
function transactionRecord(transaction) {
|
|
2429
|
+
return JSON.parse(JSON.stringify(transaction));
|
|
2430
|
+
}
|
|
2431
|
+
function asRecord(value) {
|
|
2432
|
+
return JSON.parse(JSON.stringify(value));
|
|
2433
|
+
}
|
|
2434
|
+
function sha256(value) {
|
|
2435
|
+
return createHash("sha256").update(value).digest("hex");
|
|
2436
|
+
}
|
|
2437
|
+
function stableStringify(value) {
|
|
2438
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
2439
|
+
if (value && typeof value === "object") {
|
|
2440
|
+
const record = value;
|
|
2441
|
+
return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`).join(",")}}`;
|
|
2442
|
+
}
|
|
2443
|
+
return JSON.stringify(value);
|
|
2444
|
+
}
|
|
2445
|
+
function commitResultSummary(commit) {
|
|
2446
|
+
return `${commit.operations.filter(operationIsVerified).length} 项成功,${commit.operations.filter((operation) => operation.status === "failed").length} 项失败,${commit.operations.filter((operation) => operation.status === "not_executed" || operation.status === "skipped").length} 项未执行,${commit.operations.filter((operation) => operation.status === "unknown" || operation.status === "readback_pending").length} 项结果确认中。`;
|
|
2447
|
+
}
|
|
2448
|
+
const READBACK_DELAYS_SECONDS = [
|
|
2449
|
+
2,
|
|
2450
|
+
10,
|
|
2451
|
+
30,
|
|
2452
|
+
120
|
|
2453
|
+
];
|
|
2454
|
+
function compareCommitEntries(left, right) {
|
|
2455
|
+
const rank = {
|
|
2456
|
+
create: 0,
|
|
2457
|
+
update: 1,
|
|
2458
|
+
delete: 2
|
|
2459
|
+
};
|
|
2460
|
+
return rank[left.proposal.operation] - rank[right.proposal.operation] || left.createdAt.localeCompare(right.createdAt) || left.id.localeCompare(right.id);
|
|
2461
|
+
}
|
|
2462
|
+
function accountBalanceFromSnapshot(value, accountId) {
|
|
2463
|
+
const account = snapshotAccounts(value).find((item) => item.id === accountId);
|
|
2464
|
+
if (Number.isSafeInteger(account?.balanceCents)) return Number(account.balanceCents);
|
|
2465
|
+
throw new Error("finance_account_balance_unavailable");
|
|
2466
|
+
}
|
|
2467
|
+
function calendarDateInTimeZone(instant, timezone) {
|
|
2468
|
+
const date = new Date(instant);
|
|
2469
|
+
if (Number.isNaN(date.getTime())) throw new Error("finance_invalid_instant");
|
|
2470
|
+
try {
|
|
2471
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
2472
|
+
timeZone: timezone,
|
|
2473
|
+
year: "numeric",
|
|
2474
|
+
month: "2-digit",
|
|
2475
|
+
day: "2-digit"
|
|
2476
|
+
}).formatToParts(date);
|
|
2477
|
+
const value = (type) => parts.find((part) => part.type === type)?.value;
|
|
2478
|
+
const year = value("year");
|
|
2479
|
+
const month = value("month");
|
|
2480
|
+
const day = value("day");
|
|
2481
|
+
if (!year || !month || !day) throw new Error("missing date part");
|
|
2482
|
+
return `${year}-${month}-${day}`;
|
|
2483
|
+
} catch {
|
|
2484
|
+
throw new Error("finance_book_timezone_invalid");
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
function readbackAt(now, attempt) {
|
|
2488
|
+
const seconds = READBACK_DELAYS_SECONDS[Math.min(attempt, READBACK_DELAYS_SECONDS.length - 1)];
|
|
2489
|
+
return new Date(Date.parse(now) + seconds * 1e3).toISOString();
|
|
2490
|
+
}
|
|
2491
|
+
function mutationReceiptReference(operation, result) {
|
|
2492
|
+
const operationIdentity = operation.operation === "create" ? String(operation.request.clientRequestId ?? operation.id) : operation.targetRemoteId ?? operation.id;
|
|
2493
|
+
return `ledger-receipt:${operation.bookId}:${operationIdentity}:${result.remoteId ?? "pending"}`;
|
|
2494
|
+
}
|
|
2495
|
+
function operationsOverlap(left, right) {
|
|
2496
|
+
if (left.bookId !== right.bookId) return false;
|
|
2497
|
+
if (left.entryId === right.entryId) return true;
|
|
2498
|
+
const leftId = left.targetRemoteId ?? left.result?.remoteId;
|
|
2499
|
+
const rightId = right.targetRemoteId ?? right.result?.remoteId;
|
|
2500
|
+
if (leftId && leftId === rightId) return true;
|
|
2501
|
+
return left.operation === "create" && right.operation === "create" && financialPayloadEquals(createInputFinancialPayload(left.request), createInputFinancialPayload(right.request));
|
|
2502
|
+
}
|
|
2503
|
+
async function verifyOperation(ledger, operation, attempt) {
|
|
2504
|
+
if (!ledger.verifyTransaction) return void 0;
|
|
2505
|
+
if (operation.operation === "create") return ledger.verifyTransaction(operation.bookId, {
|
|
2506
|
+
operation: "create",
|
|
2507
|
+
request: createTransactionInputSchema.parse(operation.request)
|
|
2508
|
+
}, attempt);
|
|
2509
|
+
if (!operation.before || !operation.targetRemoteId) return void 0;
|
|
2510
|
+
const common = {
|
|
2511
|
+
remoteId: operation.targetRemoteId,
|
|
2512
|
+
before: operation.before
|
|
2513
|
+
};
|
|
2514
|
+
return operation.operation === "update" ? ledger.verifyTransaction(operation.bookId, {
|
|
2515
|
+
...common,
|
|
2516
|
+
operation: "update",
|
|
2517
|
+
request: updateTransactionInputSchema.parse(operation.request)
|
|
2518
|
+
}, attempt) : ledger.verifyTransaction(operation.bookId, {
|
|
2519
|
+
...common,
|
|
2520
|
+
operation: "delete",
|
|
2521
|
+
request: deleteTransactionInputSchema.parse(operation.request)
|
|
2522
|
+
}, attempt);
|
|
2523
|
+
}
|
|
2524
|
+
//#endregion
|
|
2525
|
+
export { FINANCE_REMOTE_WRITES_DISABLED_ERROR, FinanceApplicationService, calendarDateInTimeZone };
|