@mailwoman/core 11.2.0 → 11.3.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 +2 -2
- package/lib/api/ckan.ts +1 -1
- package/lib/api/disk-storage.ts +2 -2
- package/lib/api/ogc.ts +1 -1
- package/lib/api/retry.ts +7 -2
- package/lib/api/test/transport.ts +1 -1
- package/lib/{binary-frame.ts → asset/binary-frame.ts} +1 -1
- package/lib/async/abort.ts +100 -0
- package/lib/{memoize.ts → async/memoize.ts} +2 -2
- package/lib/{promises.ts → async/promises.ts} +1 -1
- package/lib/cloudflare/tokens.ts +1 -1
- package/lib/cloudflare/wrangler.ts +3 -3
- package/lib/crypto/digest.ts +1 -1
- package/lib/crypto/ed25519.ts +8 -0
- package/lib/crypto/node.ts +1 -1
- package/lib/data-root.ts +16 -3
- package/lib/decoder/containment.ts +4 -1
- package/lib/decoder/serialize/outline.ts +19 -6
- package/lib/decoder/types.ts +9 -1
- package/lib/env/schema.ts +5 -0
- package/lib/fs/deflate64.ts +1 -1
- package/lib/fs/lock.ts +183 -25
- package/lib/fs/readers.ts +1 -1
- package/lib/fs/writers.ts +1 -1
- package/lib/geocode/result.ts +50 -6
- package/lib/html/text.ts +2 -2
- package/lib/index.ts +0 -1
- package/lib/layers/artifact.ts +2 -2
- package/lib/layers/coverage.ts +1 -1
- package/lib/layers/manifest.ts +94 -2
- package/lib/layers/provenance.ts +246 -0
- package/lib/layers/publication.ts +4 -3
- package/lib/layers/selection.ts +2 -2
- package/lib/license/branch.ts +66 -0
- package/lib/license/configured.ts +4 -2
- package/lib/license/declaration.ts +1 -1
- package/lib/license/key/file.ts +1 -1
- package/lib/license/key.ts +148 -201
- package/lib/license/provenance.ts +193 -0
- package/lib/license/register.ts +7 -78
- package/lib/license/stamp.ts +8 -2
- package/lib/license/text-url.ts +55 -0
- package/lib/license/training.ts +67 -0
- package/lib/license.ts +7 -6
- package/lib/locale/registry.ts +1 -1
- package/lib/locale/zh-cn-units.ts +1 -1
- package/lib/module/workspace.ts +1 -1
- package/lib/{routing.ts → network/routing.ts} +1 -1
- package/lib/pipeline/result.ts +6 -25
- package/lib/pipeline/runtime-pipeline.ts +129 -144
- package/lib/pipeline/stage.ts +290 -0
- package/lib/pipeline/types.ts +33 -14
- package/lib/pipeline.ts +14 -2
- package/lib/{git.ts → repo/git.ts} +21 -1
- package/lib/{release-config.ts → repo/release-config.ts} +8 -0
- package/lib/{spdx-header.ts → repo/spdx-header.ts} +8 -0
- package/lib/{workspaces.ts → repo/workspaces.ts} +1 -1
- package/lib/resolver/lookup-types.ts +1 -1
- package/lib/resolver/region-database-provider.ts +33 -0
- package/lib/resolver/synthetic-id-ranges.ts +19 -9
- package/lib/resolver/types.ts +220 -7
- package/lib/resolver.ts +14 -1
- package/lib/state-machine.ts +1 -1
- package/lib/strings/python-json.ts +3 -2
- package/lib/utils/chunk-process.ts +2 -2
- package/lib/utils/geodatabase-archive.ts +1 -1
- package/lib/utils/time.ts +136 -12
- package/lib/utils.ts +4 -4
- package/out/api/ckan.js +1 -1
- package/out/api/ckan.js.map +1 -1
- package/out/api/disk-storage.d.ts.map +1 -1
- package/out/api/disk-storage.js +2 -2
- package/out/api/disk-storage.js.map +1 -1
- package/out/api/ogc.js +1 -1
- package/out/api/ogc.js.map +1 -1
- package/out/api/retry.d.ts.map +1 -1
- package/out/api/retry.js +6 -2
- package/out/api/retry.js.map +1 -1
- package/out/api/test/transport.js +1 -1
- package/out/api/test/transport.js.map +1 -1
- package/out/asset/binary-frame.d.ts.map +1 -0
- package/out/{binary-frame.js → asset/binary-frame.js} +1 -1
- package/out/asset/binary-frame.js.map +1 -0
- package/out/asset/load-ledger.d.ts.map +1 -0
- package/out/asset/load-ledger.js.map +1 -0
- package/out/asset/overture-pins.d.ts.map +1 -0
- package/out/asset/overture-pins.js.map +1 -0
- package/out/asset/postcode-prefix-files.d.ts.map +1 -0
- package/out/asset/postcode-prefix-files.js.map +1 -0
- package/out/async/abort.d.ts +57 -0
- package/out/async/abort.d.ts.map +1 -0
- package/out/async/abort.js +89 -0
- package/out/async/abort.js.map +1 -0
- package/out/async/memoize.d.ts.map +1 -0
- package/out/{memoize.js → async/memoize.js} +2 -2
- package/out/async/memoize.js.map +1 -0
- package/out/{promises.d.ts → async/promises.d.ts} +1 -1
- package/out/async/promises.d.ts.map +1 -0
- package/out/{promises.js → async/promises.js} +1 -1
- package/out/async/promises.js.map +1 -0
- package/out/cloudflare/tokens.js +1 -1
- package/out/cloudflare/tokens.js.map +1 -1
- package/out/cloudflare/wrangler.js +3 -3
- package/out/cloudflare/wrangler.js.map +1 -1
- package/out/crypto/digest.d.ts +1 -1
- package/out/crypto/digest.js +1 -1
- package/out/crypto/ed25519.d.ts +7 -0
- package/out/crypto/ed25519.d.ts.map +1 -1
- package/out/crypto/ed25519.js +7 -0
- package/out/crypto/ed25519.js.map +1 -1
- package/out/crypto/hash.d.ts.map +1 -0
- package/out/crypto/hash.js.map +1 -0
- package/out/crypto/node.js +1 -1
- package/out/crypto/node.js.map +1 -1
- package/out/data-root.d.ts +11 -3
- package/out/data-root.d.ts.map +1 -1
- package/out/data-root.js +14 -3
- package/out/data-root.js.map +1 -1
- package/out/decoder/containment.d.ts.map +1 -1
- package/out/decoder/containment.js +1 -1
- package/out/decoder/containment.js.map +1 -1
- package/out/decoder/serialize/outline.d.ts +9 -0
- package/out/decoder/serialize/outline.d.ts.map +1 -1
- package/out/decoder/serialize/outline.js +16 -6
- package/out/decoder/serialize/outline.js.map +1 -1
- package/out/decoder/types.d.ts +8 -0
- package/out/decoder/types.d.ts.map +1 -1
- package/out/decoder/types.js +1 -1
- package/out/decoder/types.js.map +1 -1
- package/out/env/schema.d.ts +1 -0
- package/out/env/schema.d.ts.map +1 -1
- package/out/env/schema.js +4 -0
- package/out/env/schema.js.map +1 -1
- package/out/env.d.ts +1 -0
- package/out/env.d.ts.map +1 -1
- package/out/fs/deflate64.js +1 -1
- package/out/fs/deflate64.js.map +1 -1
- package/out/fs/lock.d.ts +73 -4
- package/out/fs/lock.d.ts.map +1 -1
- package/out/fs/lock.js +96 -19
- package/out/fs/lock.js.map +1 -1
- package/out/fs/readers.js +1 -1
- package/out/fs/readers.js.map +1 -1
- package/out/fs/writers.d.ts +1 -1
- package/out/fs/writers.d.ts.map +1 -1
- package/out/fs/writers.js +1 -1
- package/out/fs/writers.js.map +1 -1
- package/out/geocode/result.d.ts +25 -1
- package/out/geocode/result.d.ts.map +1 -1
- package/out/geocode/result.js +49 -6
- package/out/geocode/result.js.map +1 -1
- package/out/html/text.js +2 -2
- package/out/html/trust-policies.d.ts.map +1 -0
- package/out/html/trust-policies.js.map +1 -0
- package/out/index.d.ts +0 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +0 -1
- package/out/index.js.map +1 -1
- package/out/layers/artifact.js +2 -2
- package/out/layers/artifact.js.map +1 -1
- package/out/layers/coverage.d.ts.map +1 -1
- package/out/layers/coverage.js +1 -1
- package/out/layers/coverage.js.map +1 -1
- package/out/layers/manifest.d.ts +53 -0
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +68 -2
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/provenance.d.ts +127 -0
- package/out/layers/provenance.d.ts.map +1 -0
- package/out/layers/provenance.js +122 -0
- package/out/layers/provenance.js.map +1 -0
- package/out/layers/publication.d.ts.map +1 -1
- package/out/layers/publication.js +3 -3
- package/out/layers/publication.js.map +1 -1
- package/out/layers/selection.d.ts.map +1 -1
- package/out/layers/selection.js +2 -2
- package/out/layers/selection.js.map +1 -1
- package/out/license/branch.d.ts +33 -0
- package/out/license/branch.d.ts.map +1 -0
- package/out/license/branch.js +52 -0
- package/out/license/branch.js.map +1 -0
- package/out/license/configured.d.ts +1 -1
- package/out/license/configured.d.ts.map +1 -1
- package/out/license/configured.js +1 -9
- package/out/license/configured.js.map +1 -1
- package/out/license/declaration.d.ts +1 -1
- package/out/license/declaration.d.ts.map +1 -1
- package/out/license/key/file.js +1 -1
- package/out/license/key/file.js.map +1 -1
- package/out/license/key.d.ts +27 -115
- package/out/license/key.d.ts.map +1 -1
- package/out/license/key.js +98 -164
- package/out/license/key.js.map +1 -1
- package/out/license/provenance.d.ts +47 -0
- package/out/license/provenance.d.ts.map +1 -0
- package/out/license/provenance.js +134 -0
- package/out/license/provenance.js.map +1 -0
- package/out/license/register.d.ts +6 -47
- package/out/license/register.d.ts.map +1 -1
- package/out/license/register.js +7 -58
- package/out/license/register.js.map +1 -1
- package/out/license/stamp.d.ts +7 -1
- package/out/license/stamp.d.ts.map +1 -1
- package/out/license/stamp.js +2 -2
- package/out/license/stamp.js.map +1 -1
- package/out/license/text-url.d.ts +9 -0
- package/out/license/text-url.d.ts.map +1 -0
- package/out/license/text-url.js +49 -0
- package/out/license/text-url.js.map +1 -0
- package/out/license/training.d.ts +29 -0
- package/out/license/training.d.ts.map +1 -0
- package/out/license/training.js +52 -0
- package/out/license/training.js.map +1 -0
- package/out/license.d.ts +7 -6
- package/out/license.d.ts.map +1 -1
- package/out/license.js +7 -6
- package/out/license.js.map +1 -1
- package/out/locale/registry.d.ts.map +1 -1
- package/out/locale/registry.js +1 -1
- package/out/locale/registry.js.map +1 -1
- package/out/locale/zh-cn-units.js +1 -1
- package/out/locale/zh-cn-units.js.map +1 -1
- package/out/math/numeric.d.ts.map +1 -0
- package/out/math/numeric.js.map +1 -0
- package/out/math/random.d.ts.map +1 -0
- package/out/math/random.js.map +1 -0
- package/out/math/stats.d.ts.map +1 -0
- package/out/math/stats.js.map +1 -0
- package/out/module/workspace.js +1 -1
- package/out/module/workspace.js.map +1 -1
- package/out/network/routing.d.ts.map +1 -0
- package/out/{routing.js → network/routing.js} +1 -1
- package/out/network/routing.js.map +1 -0
- package/out/pipeline/result.d.ts +7 -24
- package/out/pipeline/result.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts +7 -2
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +56 -103
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/stage.d.ts +180 -0
- package/out/pipeline/stage.d.ts.map +1 -0
- package/out/pipeline/stage.js +130 -0
- package/out/pipeline/stage.js.map +1 -0
- package/out/pipeline/types.d.ts +31 -12
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js +0 -8
- package/out/pipeline/types.js.map +1 -1
- package/out/pipeline.d.ts +5 -3
- package/out/pipeline.d.ts.map +1 -1
- package/out/pipeline.js +2 -1
- package/out/pipeline.js.map +1 -1
- package/out/{git.d.ts → repo/git.d.ts} +10 -1
- package/out/repo/git.d.ts.map +1 -0
- package/out/{git.js → repo/git.js} +14 -1
- package/out/repo/git.js.map +1 -0
- package/out/{release-config.d.ts → repo/release-config.d.ts} +8 -0
- package/out/repo/release-config.d.ts.map +1 -0
- package/out/repo/release-config.js.map +1 -0
- package/out/repo/scope-config.d.ts.map +1 -0
- package/out/repo/scope-config.js.map +1 -0
- package/out/repo/spdx-header.d.ts.map +1 -0
- package/out/{spdx-header.js → repo/spdx-header.js} +7 -0
- package/out/repo/spdx-header.js.map +1 -0
- package/out/repo/vale.d.ts.map +1 -0
- package/out/repo/vale.js.map +1 -0
- package/out/repo/workspaces.d.ts.map +1 -0
- package/out/{workspaces.js → repo/workspaces.js} +1 -1
- package/out/repo/workspaces.js.map +1 -0
- package/out/resolver/lookup-types.d.ts +1 -1
- package/out/resolver/region-database-provider.d.ts +30 -0
- package/out/resolver/region-database-provider.d.ts.map +1 -1
- package/out/resolver/synthetic-id-ranges.d.ts +15 -8
- package/out/resolver/synthetic-id-ranges.d.ts.map +1 -1
- package/out/resolver/synthetic-id-ranges.js +18 -9
- package/out/resolver/synthetic-id-ranges.js.map +1 -1
- package/out/resolver/types.d.ts +192 -8
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js +56 -0
- package/out/resolver/types.js.map +1 -1
- package/out/resolver.d.ts +3 -3
- package/out/resolver.d.ts.map +1 -1
- package/out/resolver.js +1 -1
- package/out/resolver.js.map +1 -1
- package/out/scripting/process.d.ts.map +1 -0
- package/out/scripting/process.js.map +1 -0
- package/out/scripting/workers.d.ts.map +1 -0
- package/out/scripting/workers.js.map +1 -0
- package/out/state-machine.d.ts +1 -1
- package/out/strings/python-json.d.ts +2 -1
- package/out/strings/python-json.d.ts.map +1 -1
- package/out/strings/python-json.js +1 -1
- package/out/strings/python-json.js.map +1 -1
- package/out/tools/build-deflate64-wasm.run.js +2 -2
- package/out/tools/build-deflate64-wasm.run.js.map +1 -1
- package/out/tools/coarse-placer/build/dataset.js +1 -1
- package/out/tools/coarse-placer/build/dataset.js.map +1 -1
- package/out/tools/coarse-placer/build/outlier/exposure.js +1 -1
- package/out/tools/coarse-placer/build/outlier/exposure.js.map +1 -1
- package/out/tools/coarse-placer/build/outlier/latin.d.ts.map +1 -1
- package/out/tools/coarse-placer/build/outlier/latin.js +5 -1
- package/out/tools/coarse-placer/build/outlier/latin.js.map +1 -1
- package/out/tools/coarse-placer/country-sets.d.ts +2 -2
- package/out/tools/coarse-placer/country-sets.js +2 -2
- package/out/tools/coarse-placer/outlier-rows.js +2 -2
- package/out/tools/coarse-placer/outlier-rows.js.map +1 -1
- package/out/tools/coarse-placer/train.js +1 -1
- package/out/tools/coarse-placer/train.js.map +1 -1
- package/out/tools/generate-language-types.js +2 -2
- package/out/tools/generate-language-types.js.map +1 -1
- package/out/tools/license/product-fixtures.run.d.ts +2 -0
- package/out/tools/license/product-fixtures.run.d.ts.map +1 -0
- package/out/tools/license/product-fixtures.run.js +350 -0
- package/out/tools/license/product-fixtures.run.js.map +1 -0
- package/out/utils/chunk-process.js +2 -2
- package/out/utils/chunk-process.js.map +1 -1
- package/out/utils/geodatabase-archive.js +1 -1
- package/out/utils/geodatabase-archive.js.map +1 -1
- package/out/utils/time.d.ts +15 -4
- package/out/utils/time.d.ts.map +1 -1
- package/out/utils/time.js +114 -12
- package/out/utils/time.js.map +1 -1
- package/out/utils.d.ts +4 -4
- package/out/utils.d.ts.map +1 -1
- package/out/utils.js +4 -4
- package/out/utils.js.map +1 -1
- package/out/values/identical.d.ts.map +1 -0
- package/out/values/identical.js.map +1 -0
- package/out/values/json.d.ts.map +1 -0
- package/out/values/json.js.map +1 -0
- package/out/values/objects.d.ts.map +1 -0
- package/out/values/objects.js.map +1 -0
- package/package.json +278 -243
- package/tools/build-deflate64-wasm.run.ts +2 -2
- package/tools/coarse-placer/build/dataset.ts +1 -1
- package/tools/coarse-placer/build/outlier/exposure.ts +1 -1
- package/tools/coarse-placer/build/outlier/latin.ts +5 -1
- package/tools/coarse-placer/country-sets.ts +2 -2
- package/tools/coarse-placer/outlier-rows.ts +2 -2
- package/tools/coarse-placer/train.ts +1 -1
- package/tools/generate-language-types.ts +2 -2
- package/tools/license/product-fixtures.run.ts +449 -0
- package/lib/collections.ts +0 -5
- package/lib/license/decision.ts +0 -329
- package/lib/license/obligations.ts +0 -256
- package/lib/license/record.ts +0 -277
- package/lib/scripting/ingest-chunk-script.ts +0 -87
- package/out/binary-frame.d.ts.map +0 -1
- package/out/binary-frame.js.map +0 -1
- package/out/collections.d.ts +0 -2
- package/out/collections.d.ts.map +0 -1
- package/out/collections.js +0 -5
- package/out/collections.js.map +0 -1
- package/out/git.d.ts.map +0 -1
- package/out/git.js.map +0 -1
- package/out/hash.d.ts.map +0 -1
- package/out/hash.js.map +0 -1
- package/out/identical.d.ts.map +0 -1
- package/out/identical.js.map +0 -1
- package/out/json.d.ts.map +0 -1
- package/out/json.js.map +0 -1
- package/out/license/decision.d.ts +0 -179
- package/out/license/decision.d.ts.map +0 -1
- package/out/license/decision.js +0 -169
- package/out/license/decision.js.map +0 -1
- package/out/license/obligations.d.ts +0 -102
- package/out/license/obligations.d.ts.map +0 -1
- package/out/license/obligations.js +0 -188
- package/out/license/obligations.js.map +0 -1
- package/out/license/record.d.ts +0 -136
- package/out/license/record.d.ts.map +0 -1
- package/out/license/record.js +0 -222
- package/out/license/record.js.map +0 -1
- package/out/load-ledger.d.ts.map +0 -1
- package/out/load-ledger.js.map +0 -1
- package/out/memoize.d.ts.map +0 -1
- package/out/memoize.js.map +0 -1
- package/out/numeric.d.ts.map +0 -1
- package/out/numeric.js.map +0 -1
- package/out/objects.d.ts.map +0 -1
- package/out/objects.js.map +0 -1
- package/out/overture-pins.d.ts.map +0 -1
- package/out/overture-pins.js.map +0 -1
- package/out/postcode-prefix-files.d.ts.map +0 -1
- package/out/postcode-prefix-files.js.map +0 -1
- package/out/process.d.ts.map +0 -1
- package/out/process.js.map +0 -1
- package/out/promises.d.ts.map +0 -1
- package/out/promises.js.map +0 -1
- package/out/random.d.ts.map +0 -1
- package/out/random.js.map +0 -1
- package/out/release-config.d.ts.map +0 -1
- package/out/release-config.js.map +0 -1
- package/out/routing.d.ts.map +0 -1
- package/out/routing.js.map +0 -1
- package/out/scope-config.d.ts.map +0 -1
- package/out/scope-config.js.map +0 -1
- package/out/scripting/ingest-chunk-script.d.ts +0 -58
- package/out/scripting/ingest-chunk-script.d.ts.map +0 -1
- package/out/scripting/ingest-chunk-script.js +0 -47
- package/out/scripting/ingest-chunk-script.js.map +0 -1
- package/out/spdx-header.d.ts.map +0 -1
- package/out/spdx-header.js.map +0 -1
- package/out/stats.d.ts.map +0 -1
- package/out/stats.js.map +0 -1
- package/out/trust-policies.d.ts.map +0 -1
- package/out/trust-policies.js.map +0 -1
- package/out/vale.d.ts.map +0 -1
- package/out/vale.js.map +0 -1
- package/out/workers.d.ts.map +0 -1
- package/out/workers.js.map +0 -1
- package/out/workspaces.d.ts.map +0 -1
- package/out/workspaces.js.map +0 -1
- /package/lib/{load-ledger.ts → asset/load-ledger.ts} +0 -0
- /package/lib/{overture-pins.ts → asset/overture-pins.ts} +0 -0
- /package/lib/{postcode-prefix-files.ts → asset/postcode-prefix-files.ts} +0 -0
- /package/lib/{hash.ts → crypto/hash.ts} +0 -0
- /package/lib/{trust-policies.ts → html/trust-policies.ts} +0 -0
- /package/lib/{numeric.ts → math/numeric.ts} +0 -0
- /package/lib/{random.ts → math/random.ts} +0 -0
- /package/lib/{stats.ts → math/stats.ts} +0 -0
- /package/lib/{scope-config.ts → repo/scope-config.ts} +0 -0
- /package/lib/{vale.ts → repo/vale.ts} +0 -0
- /package/lib/{process.ts → scripting/process.ts} +0 -0
- /package/lib/{workers.ts → scripting/workers.ts} +0 -0
- /package/lib/{identical.ts → values/identical.ts} +0 -0
- /package/lib/{json.ts → values/json.ts} +0 -0
- /package/lib/{objects.ts → values/objects.ts} +0 -0
- /package/out/{binary-frame.d.ts → asset/binary-frame.d.ts} +0 -0
- /package/out/{load-ledger.d.ts → asset/load-ledger.d.ts} +0 -0
- /package/out/{load-ledger.js → asset/load-ledger.js} +0 -0
- /package/out/{overture-pins.d.ts → asset/overture-pins.d.ts} +0 -0
- /package/out/{overture-pins.js → asset/overture-pins.js} +0 -0
- /package/out/{postcode-prefix-files.d.ts → asset/postcode-prefix-files.d.ts} +0 -0
- /package/out/{postcode-prefix-files.js → asset/postcode-prefix-files.js} +0 -0
- /package/out/{memoize.d.ts → async/memoize.d.ts} +0 -0
- /package/out/{hash.d.ts → crypto/hash.d.ts} +0 -0
- /package/out/{hash.js → crypto/hash.js} +0 -0
- /package/out/{trust-policies.d.ts → html/trust-policies.d.ts} +0 -0
- /package/out/{trust-policies.js → html/trust-policies.js} +0 -0
- /package/out/{numeric.d.ts → math/numeric.d.ts} +0 -0
- /package/out/{numeric.js → math/numeric.js} +0 -0
- /package/out/{random.d.ts → math/random.d.ts} +0 -0
- /package/out/{random.js → math/random.js} +0 -0
- /package/out/{stats.d.ts → math/stats.d.ts} +0 -0
- /package/out/{stats.js → math/stats.js} +0 -0
- /package/out/{routing.d.ts → network/routing.d.ts} +0 -0
- /package/out/{release-config.js → repo/release-config.js} +0 -0
- /package/out/{scope-config.d.ts → repo/scope-config.d.ts} +0 -0
- /package/out/{scope-config.js → repo/scope-config.js} +0 -0
- /package/out/{spdx-header.d.ts → repo/spdx-header.d.ts} +0 -0
- /package/out/{vale.d.ts → repo/vale.d.ts} +0 -0
- /package/out/{vale.js → repo/vale.js} +0 -0
- /package/out/{workspaces.d.ts → repo/workspaces.d.ts} +0 -0
- /package/out/{process.d.ts → scripting/process.d.ts} +0 -0
- /package/out/{process.js → scripting/process.js} +0 -0
- /package/out/{workers.d.ts → scripting/workers.d.ts} +0 -0
- /package/out/{workers.js → scripting/workers.js} +0 -0
- /package/out/{identical.d.ts → values/identical.d.ts} +0 -0
- /package/out/{identical.js → values/identical.js} +0 -0
- /package/out/{json.d.ts → values/json.d.ts} +0 -0
- /package/out/{json.js → values/json.js} +0 -0
- /package/out/{objects.d.ts → values/objects.d.ts} +0 -0
- /package/out/{objects.js → values/objects.js} +0 -0
|
@@ -10,12 +10,19 @@ import type { ComponentTag } from "@mailwoman/codex/component"
|
|
|
10
10
|
|
|
11
11
|
import { isBareTreeOf } from "#decoder/tree/shape"
|
|
12
12
|
import type { AddressNode, AddressTree } from "#decoder/types"
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
13
|
+
import type { PipelineResult } from "#pipeline/result"
|
|
14
|
+
import {
|
|
15
|
+
createRequestContext,
|
|
16
|
+
type PipelineFaultStage,
|
|
17
|
+
type PipelineStage,
|
|
18
|
+
type RequestContext,
|
|
19
|
+
runStage,
|
|
20
|
+
StageID,
|
|
21
|
+
type StageRecord,
|
|
22
|
+
} from "#pipeline/stage"
|
|
15
23
|
import {
|
|
16
24
|
DEFAULT_CASE_NORMALIZATION,
|
|
17
25
|
DEFAULT_PLACER_COUNTRY_USE,
|
|
18
|
-
PipelineFaultStage,
|
|
19
26
|
WORD_CONSISTENCY_SHIP_DEFAULT,
|
|
20
27
|
deriveInputMode,
|
|
21
28
|
isPostcodeFormat,
|
|
@@ -263,35 +270,49 @@ function buildFastPathTree(text: string, kind: QueryKindResult, shape: QueryShap
|
|
|
263
270
|
/**
|
|
264
271
|
* Runs the configured stages in order and returns the decoded tree with per-stage timings and faults.
|
|
265
272
|
*
|
|
273
|
+
* Each stage runs through {@linkcode runStage}, which times it and checks the abort signal before it.
|
|
266
274
|
* A failing classifier, grouper or resolver records a fault and the run continues.
|
|
267
|
-
*
|
|
275
|
+
*
|
|
276
|
+
* A caller that runs stages of its own around the parse passes its request's `context`.
|
|
277
|
+
* The result's timing and faults are then that context's, and the context's signal cancels the run.
|
|
278
|
+
* Without one, the run builds a context from `opts.signal`.
|
|
268
279
|
*/
|
|
269
|
-
export async function runPipeline(
|
|
280
|
+
export async function runPipeline<FaultStage extends string = PipelineFaultStage>(
|
|
270
281
|
raw: string,
|
|
271
282
|
stages: RuntimePipelineStages,
|
|
272
|
-
opts?: PipelineOpts
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
283
|
+
opts?: PipelineOpts,
|
|
284
|
+
context: RequestContext<StageRecord, FaultStage | PipelineFaultStage> = createRequestContext({
|
|
285
|
+
signal: opts?.signal,
|
|
286
|
+
})
|
|
287
|
+
): Promise<PipelineResult<FaultStage | PipelineFaultStage>> {
|
|
288
|
+
const { timing, faults } = context
|
|
277
289
|
|
|
278
290
|
const normalize = stages.normalize ?? identityNormalize
|
|
279
291
|
const computeQueryShape = stages.computeQueryShape ?? emptyQueryShape
|
|
280
292
|
const detectLocale = stages.detectLocale ?? defaultDetectLocale
|
|
281
293
|
const classifyKind = stages.classifyKind ?? defaultClassifyKind
|
|
282
294
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
295
|
+
const normalized = await runStage(
|
|
296
|
+
{
|
|
297
|
+
id: StageID.Normalize,
|
|
298
|
+
run: (text: string) => rewriteLineBreaks(normalize(text, { locale: opts?.locale }), opts?.lineBreaks ?? "keep"),
|
|
299
|
+
},
|
|
300
|
+
raw,
|
|
301
|
+
context
|
|
302
|
+
)
|
|
286
303
|
|
|
287
304
|
// The coarse placer adds a country prior unless the caller already supplied one.
|
|
288
305
|
let effectiveOpts = opts
|
|
289
306
|
let placerAnchorApplied = false
|
|
290
307
|
|
|
291
308
|
if (stages.placeCountry) {
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
309
|
+
const placeCountry = stages.placeCountry
|
|
310
|
+
|
|
311
|
+
const placed = await runStage(
|
|
312
|
+
{ id: StageID.PlaceCountry, run: (text: string) => placeCountry(text) },
|
|
313
|
+
normalized.normalized,
|
|
314
|
+
context
|
|
315
|
+
)
|
|
295
316
|
|
|
296
317
|
if (placed.country && placed.country !== "OTHER" && !opts?.resolveOpts?.anchorPosterior) {
|
|
297
318
|
const hardCountry = hardCountryFor(
|
|
@@ -319,30 +340,39 @@ export async function runPipeline(
|
|
|
319
340
|
}
|
|
320
341
|
}
|
|
321
342
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
343
|
+
const queryShape = await runStage(
|
|
344
|
+
{ id: StageID.QueryShape, run: (input: NormalizedInputLite) => computeQueryShape(input) },
|
|
345
|
+
normalized,
|
|
346
|
+
context
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
const locale = await runStage(
|
|
350
|
+
{
|
|
351
|
+
id: StageID.LocaleHint,
|
|
352
|
+
run: (input: NormalizedInputLite) => detectLocale(input, queryShape, { hint: opts?.locale }),
|
|
353
|
+
},
|
|
354
|
+
normalized,
|
|
355
|
+
context
|
|
356
|
+
)
|
|
331
357
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
358
|
+
const kind = await runStage(
|
|
359
|
+
{ id: StageID.KindClassifier, run: (input: NormalizedInputLite) => classifyKind(input, queryShape, locale) },
|
|
360
|
+
normalized,
|
|
361
|
+
context
|
|
362
|
+
)
|
|
336
363
|
|
|
337
364
|
const intentMarkers: QueryIntentMarker[] = [...(kind.intentMarkers ?? [])]
|
|
338
365
|
|
|
339
366
|
// A POI-shaped query goes to the intent stage first.
|
|
340
367
|
// A null result falls through to parsing.
|
|
341
368
|
if ((kind.kind === "poi_query" || kind.kind === "poi_category") && stages.poiIntent) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const poiOutcome = await
|
|
345
|
-
|
|
369
|
+
const poiIntent = stages.poiIntent
|
|
370
|
+
|
|
371
|
+
const poiOutcome = await runStage(
|
|
372
|
+
{ id: StageID.POIIntent, run: (input: NormalizedInputLite) => poiIntent(input, locale, effectiveOpts) },
|
|
373
|
+
normalized,
|
|
374
|
+
context
|
|
375
|
+
)
|
|
346
376
|
|
|
347
377
|
if (poiOutcome) {
|
|
348
378
|
const emptyTree: AddressTree = { raw: normalized.normalized, roots: [] }
|
|
@@ -369,10 +399,7 @@ export async function runPipeline(
|
|
|
369
399
|
let tree = buildFastPathTree(normalized.normalized, kind, queryShape)
|
|
370
400
|
|
|
371
401
|
if (stages.resolver) {
|
|
372
|
-
|
|
373
|
-
const tResolve = performance.now()
|
|
374
|
-
tree = await safeResolve(faults, stages.resolver, tree, effectiveOpts)
|
|
375
|
-
timing["resolve"] = performance.now() - tResolve
|
|
402
|
+
tree = await runStage(resolveStage(stages.resolver, effectiveOpts), tree, context)
|
|
376
403
|
}
|
|
377
404
|
|
|
378
405
|
return {
|
|
@@ -394,50 +421,57 @@ export async function runPipeline(
|
|
|
394
421
|
let phraseProposals: PhraseProposal[] = []
|
|
395
422
|
|
|
396
423
|
if (stages.groupPhrases) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
phraseProposals = await
|
|
400
|
-
|
|
424
|
+
const groupPhrases = stages.groupPhrases
|
|
425
|
+
|
|
426
|
+
phraseProposals = await runStage(
|
|
427
|
+
{
|
|
428
|
+
id: StageID.PhraseGrouper,
|
|
429
|
+
run: (input: NormalizedInputLite) => groupPhrases(input, queryShape, locale),
|
|
430
|
+
recover: (): PhraseProposal[] => [],
|
|
431
|
+
},
|
|
432
|
+
normalized,
|
|
433
|
+
context
|
|
434
|
+
)
|
|
401
435
|
}
|
|
402
436
|
|
|
403
437
|
let tree: AddressTree = { raw: normalized.normalized, roots: [] }
|
|
404
438
|
|
|
405
439
|
if (stages.classifier) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
timing["token-classify"] = performance.now() - tClassify
|
|
440
|
+
tree = await runStage(
|
|
441
|
+
classifyStage(stages.classifier, queryShape, {
|
|
442
|
+
fst: stages.fst ?? null,
|
|
443
|
+
caseNormalization: opts?.caseNormalization ?? DEFAULT_CASE_NORMALIZATION,
|
|
444
|
+
placetypePair: opts?.placetypePair ?? "inherit",
|
|
445
|
+
streetMorphology: stages.streetMorphology ?? null,
|
|
446
|
+
streetMorphologyPrior: stages.streetMorphologyPrior ?? false,
|
|
447
|
+
anchorRegions: stages.anchorRegions ?? null,
|
|
448
|
+
venueHead: stages.venueHead?.(locale) ?? null,
|
|
449
|
+
inputMode: deriveInputMode(opts?.inputMode ?? "auto", kind.kind),
|
|
450
|
+
localeHint: opts?.localeHint ?? null,
|
|
451
|
+
}),
|
|
452
|
+
normalized.normalized,
|
|
453
|
+
context
|
|
454
|
+
)
|
|
422
455
|
}
|
|
423
456
|
|
|
424
457
|
if (phraseProposals.length && tree.roots.length >= 0) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
458
|
+
tree = await runStage(
|
|
459
|
+
{
|
|
460
|
+
id: StageID.GrouperAudit,
|
|
461
|
+
run: (decoded: AddressTree) => grouperAudit(decoded, phraseProposals, normalized.normalized),
|
|
462
|
+
},
|
|
463
|
+
tree,
|
|
464
|
+
context
|
|
465
|
+
)
|
|
428
466
|
}
|
|
429
467
|
|
|
430
468
|
if (stages.resolver) {
|
|
431
|
-
throwIfAborted(opts)
|
|
432
|
-
const tResolve = performance.now()
|
|
433
|
-
|
|
434
469
|
// A bare locality or postcode query resolves without the placer's prior.
|
|
435
470
|
if (placerAnchorApplied && (isBareLocalityTree(tree) || isBarePostcodeTree(tree))) {
|
|
436
471
|
effectiveOpts = opts
|
|
437
472
|
}
|
|
438
473
|
|
|
439
|
-
tree = await
|
|
440
|
-
timing["resolve"] = performance.now() - tResolve
|
|
474
|
+
tree = await runStage(resolveStage(stages.resolver, effectiveOpts), tree, context)
|
|
441
475
|
}
|
|
442
476
|
|
|
443
477
|
return {
|
|
@@ -457,36 +491,12 @@ export async function runPipeline(
|
|
|
457
491
|
}
|
|
458
492
|
|
|
459
493
|
/**
|
|
460
|
-
*
|
|
494
|
+
* The stage that runs the classifier over the normalized text.
|
|
461
495
|
*
|
|
462
|
-
*
|
|
463
|
-
*/
|
|
464
|
-
function throwIfAborted(opts?: PipelineOpts): void {
|
|
465
|
-
if (opts?.signal?.aborted) {
|
|
466
|
-
throw opts.signal.reason ?? new DOMException("Pipeline aborted", "AbortError")
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Records a stage failure so callers can tell degraded output from a clean result.
|
|
496
|
+
* When the classifier throws, the run continues with an empty tree.
|
|
472
497
|
*/
|
|
473
|
-
function
|
|
474
|
-
faults.push({
|
|
475
|
-
stage,
|
|
476
|
-
name: cause instanceof Error ? cause.name : "Error",
|
|
477
|
-
message: errorMessage(cause),
|
|
478
|
-
cause,
|
|
479
|
-
})
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* Runs the classifier.
|
|
484
|
-
* On failure it records a fault and returns an empty tree.
|
|
485
|
-
*/
|
|
486
|
-
async function safeClassify(
|
|
487
|
-
faults: PipelineFault[],
|
|
498
|
+
function classifyStage(
|
|
488
499
|
classifier: AddressClassifier,
|
|
489
|
-
text: string,
|
|
490
500
|
queryShape: QueryShapeLite,
|
|
491
501
|
knobs: {
|
|
492
502
|
fst: FSTMatcherLike | null
|
|
@@ -499,7 +509,7 @@ async function safeClassify(
|
|
|
499
509
|
inputMode: InputMode
|
|
500
510
|
localeHint: string | null
|
|
501
511
|
}
|
|
502
|
-
):
|
|
512
|
+
): PipelineStage<string, AddressTree> {
|
|
503
513
|
const {
|
|
504
514
|
fst,
|
|
505
515
|
caseNormalization,
|
|
@@ -512,25 +522,24 @@ async function safeClassify(
|
|
|
512
522
|
localeHint,
|
|
513
523
|
} = knobs
|
|
514
524
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
return { raw: text, roots: [] }
|
|
525
|
+
return {
|
|
526
|
+
id: StageID.TokenClassify,
|
|
527
|
+
run: (text) =>
|
|
528
|
+
classifier.parse(text, {
|
|
529
|
+
queryShape,
|
|
530
|
+
inputMode,
|
|
531
|
+
...(localeHint ? { localeHint } : {}),
|
|
532
|
+
fst,
|
|
533
|
+
postcodeRepair: true,
|
|
534
|
+
caseNormalization,
|
|
535
|
+
enforceWordConsistency: WORD_CONSISTENCY_SHIP_DEFAULT,
|
|
536
|
+
placetypePair,
|
|
537
|
+
...streetContextRequirementFor({ fst, streetMorphology }, { streetMorphologyPrior }),
|
|
538
|
+
...(fst && anchorRegions ? { anchorRegions } : {}),
|
|
539
|
+
...(venueHead ? { venueHead: venueHead.venueHead } : {}),
|
|
540
|
+
...(venueHead?.venueHeadOpts ? { venueHeadOpts: venueHead.venueHeadOpts } : {}),
|
|
541
|
+
}),
|
|
542
|
+
recover: (text) => ({ raw: text, roots: [] }),
|
|
534
543
|
}
|
|
535
544
|
}
|
|
536
545
|
|
|
@@ -585,26 +594,6 @@ export function streetContextRequirementFor(
|
|
|
585
594
|
: {}
|
|
586
595
|
}
|
|
587
596
|
|
|
588
|
-
/**
|
|
589
|
-
* Runs the phrase grouper.
|
|
590
|
-
* On failure it records a fault and returns no proposals.
|
|
591
|
-
*/
|
|
592
|
-
async function safeGroupPhrases(
|
|
593
|
-
faults: PipelineFault[],
|
|
594
|
-
groupPhrases: NonNullable<RuntimePipelineStages["groupPhrases"]>,
|
|
595
|
-
normalized: NormalizedInputLite,
|
|
596
|
-
shape: QueryShapeLite,
|
|
597
|
-
locale: LocaleHint
|
|
598
|
-
): Promise<PhraseProposal[]> {
|
|
599
|
-
try {
|
|
600
|
-
return await groupPhrases(normalized, shape, locale)
|
|
601
|
-
} catch (error) {
|
|
602
|
-
recordFault(faults, PipelineFaultStage.PhraseGrouper, error)
|
|
603
|
-
|
|
604
|
-
return []
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
597
|
// MARK: Grouper-audit pass
|
|
609
598
|
|
|
610
599
|
/**
|
|
@@ -681,21 +670,17 @@ export function grouperAudit(tree: AddressTree, proposals: PhraseProposal[], tex
|
|
|
681
670
|
}
|
|
682
671
|
|
|
683
672
|
/**
|
|
684
|
-
*
|
|
673
|
+
* The stage that resolves the decoded tree.
|
|
685
674
|
*
|
|
686
|
-
*
|
|
675
|
+
* When the resolver throws, the run continues with the unresolved tree.
|
|
687
676
|
*/
|
|
688
|
-
|
|
689
|
-
faults: PipelineFault[],
|
|
677
|
+
function resolveStage(
|
|
690
678
|
resolver: NonNullable<RuntimePipelineStages["resolver"]>,
|
|
691
|
-
tree: AddressTree,
|
|
692
679
|
opts?: PipelineOpts
|
|
693
|
-
):
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
return tree
|
|
680
|
+
): PipelineStage<AddressTree, AddressTree> {
|
|
681
|
+
return {
|
|
682
|
+
id: StageID.Resolve,
|
|
683
|
+
run: (tree) => resolver.resolveTree(tree, opts?.resolveOpts),
|
|
684
|
+
recover: (tree) => tree,
|
|
700
685
|
}
|
|
701
686
|
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A pipeline stage, the context every stage of one request reads, and the runner.
|
|
6
|
+
*
|
|
7
|
+
* A stage is an object with an `id` and a `run` function.
|
|
8
|
+
* The runner checks the abort signal, times the stage and captures its fault,
|
|
9
|
+
* so a stage does none of the three.
|
|
10
|
+
*
|
|
11
|
+
* The parse pipeline and the geocode path run their stages through {@linkcode runStage}.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { decodeAsOutlineLines } from "#decoder/serialize/outline"
|
|
15
|
+
import type { AddressTree } from "#decoder/types"
|
|
16
|
+
import { errorMessage } from "#errors/schema"
|
|
17
|
+
import type { PipelineTiming } from "#pipeline/types"
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The identifier of each stage of the parse pipeline, spelled as its timing keys were first published.
|
|
21
|
+
* A timing record keys a stage's duration by its identifier.
|
|
22
|
+
*
|
|
23
|
+
* A package that runs stages of its own declares their identifiers beside them,
|
|
24
|
+
* as `GeocodeStageID` in `mailwoman` does, so a new stage there changes zero lines here.
|
|
25
|
+
*/
|
|
26
|
+
export const StageID = {
|
|
27
|
+
Normalize: "normalize",
|
|
28
|
+
PlaceCountry: "place-country",
|
|
29
|
+
QueryShape: "query-shape",
|
|
30
|
+
LocaleHint: "locale-hint",
|
|
31
|
+
KindClassifier: "kind-classifier",
|
|
32
|
+
POIIntent: "poi-intent",
|
|
33
|
+
PhraseGrouper: "phrase-grouper",
|
|
34
|
+
TokenClassify: "token-classify",
|
|
35
|
+
GrouperAudit: "grouper-audit",
|
|
36
|
+
Resolve: "resolve",
|
|
37
|
+
} as const
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* One of the {@link StageID} values.
|
|
41
|
+
*/
|
|
42
|
+
export type StageID = (typeof StageID)[keyof typeof StageID]
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The two stages a fault spells differently from the stage's identifier.
|
|
46
|
+
*
|
|
47
|
+
* `mailwoman parse` prints a fault's `stage`, so each spelling stays as it was first published.
|
|
48
|
+
*/
|
|
49
|
+
const FAULT_STAGE_SPELLINGS: Readonly<Record<string, string>> = {
|
|
50
|
+
[StageID.TokenClassify]: "classifier",
|
|
51
|
+
[StageID.Resolve]: "resolver",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A stage of the parse pipeline as a fault spells it: `classifier` for the decode,
|
|
56
|
+
* `resolver` for the resolve, and the stage's identifier for every other stage.
|
|
57
|
+
*/
|
|
58
|
+
export type PipelineFaultStage =
|
|
59
|
+
| Exclude<StageID, typeof StageID.TokenClassify | typeof StageID.Resolve>
|
|
60
|
+
| "classifier"
|
|
61
|
+
| "resolver"
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* One failure that a request caught and degraded past.
|
|
65
|
+
*
|
|
66
|
+
* `runPipeline` still resolves.
|
|
67
|
+
* `tree` contains whatever the remaining stages could prove.
|
|
68
|
+
*
|
|
69
|
+
* @typeParam Stage The spellings of the stages that can fault.
|
|
70
|
+
* The parse pipeline's result states {@link PipelineFaultStage}, and a context with stages of another package states `string`.
|
|
71
|
+
*/
|
|
72
|
+
export interface PipelineFault<Stage extends string = string> {
|
|
73
|
+
/**
|
|
74
|
+
* The stage that threw, as a fault spells it.
|
|
75
|
+
*/
|
|
76
|
+
stage: Stage
|
|
77
|
+
/**
|
|
78
|
+
* The thrown value's `name`, or `"Error"` when something that isn't an `Error` was thrown.
|
|
79
|
+
*
|
|
80
|
+
* It is machine-stable enough to branch on, with the `cause` carrying the rest.
|
|
81
|
+
*/
|
|
82
|
+
name: string
|
|
83
|
+
message: string
|
|
84
|
+
/**
|
|
85
|
+
* The value the stage threw, verbatim: not JSON-serializable in the useful sense,
|
|
86
|
+
* so serialize `stage`/`name`/`message` when you need this on a wire.
|
|
87
|
+
*/
|
|
88
|
+
cause: unknown
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* What a stage that rewrites the parse tree changed, as outline lines of the tree.
|
|
93
|
+
*
|
|
94
|
+
* A line reads `tag [start, end): "value"` with the node's metadata after it, indented two
|
|
95
|
+
* spaces for each level, so a node that only moved under another parent appears in both lists.
|
|
96
|
+
*/
|
|
97
|
+
export interface TreeRewriteRecord {
|
|
98
|
+
kind: "tree-rewrite"
|
|
99
|
+
/**
|
|
100
|
+
* The identifier of the stage that rewrote the tree.
|
|
101
|
+
*/
|
|
102
|
+
stage: string
|
|
103
|
+
/**
|
|
104
|
+
* The lines the tree had before the stage and lacks after it.
|
|
105
|
+
*/
|
|
106
|
+
removed: string[]
|
|
107
|
+
/**
|
|
108
|
+
* The lines the tree has after the stage and lacked before it.
|
|
109
|
+
*/
|
|
110
|
+
added: string[]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A record that a stage of this package writes to a request's trace.
|
|
115
|
+
*/
|
|
116
|
+
export type StageRecord = TreeRewriteRecord
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* What every stage of one request reads and writes.
|
|
120
|
+
*
|
|
121
|
+
* @typeParam Trace The records the request's stages write.
|
|
122
|
+
* @typeParam FaultStage The spellings of the stages whose failures the request records.
|
|
123
|
+
*/
|
|
124
|
+
export interface RequestContext<Trace = StageRecord, FaultStage extends string = string> {
|
|
125
|
+
/**
|
|
126
|
+
* The signal that cancels the request, or null for a request that can't be cancelled.
|
|
127
|
+
*/
|
|
128
|
+
readonly signal: AbortSignal | null
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Receives each record a stage writes, or null when the request records none.
|
|
132
|
+
*
|
|
133
|
+
* A stage builds a record only after it has read a sink here.
|
|
134
|
+
*/
|
|
135
|
+
readonly trace: ((record: Trace) => void) | null
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Whether a stage also writes the records that cost work to build, such as the
|
|
139
|
+
* outlines of a tree rewrite or the decoder's trace.
|
|
140
|
+
*
|
|
141
|
+
* A stage writes a record it already holds, such as a decision it made, whenever {@link trace} is set.
|
|
142
|
+
*/
|
|
143
|
+
readonly detail: boolean
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The milliseconds each stage has taken, summed when a stage runs more than once.
|
|
147
|
+
*/
|
|
148
|
+
readonly timing: PipelineTiming
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Every failure the request caught and degraded past, in order.
|
|
152
|
+
*/
|
|
153
|
+
readonly faults: PipelineFault<FaultStage>[]
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Builds the context of one request.
|
|
158
|
+
*
|
|
159
|
+
* `detail` defaults to whether the request has a trace, so a caller states it only to
|
|
160
|
+
* receive the records a stage already holds without the costly ones.
|
|
161
|
+
*/
|
|
162
|
+
export function createRequestContext<Trace = StageRecord, FaultStage extends string = string>(
|
|
163
|
+
init: { signal?: AbortSignal | null; trace?: ((record: Trace) => void) | null; detail?: boolean } = {}
|
|
164
|
+
): RequestContext<Trace, FaultStage> {
|
|
165
|
+
const trace = init.trace ?? null
|
|
166
|
+
|
|
167
|
+
return { signal: init.signal ?? null, trace, detail: init.detail ?? trace != null, timing: {}, faults: [] }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Records a failure the request degrades past, under `stage`.
|
|
172
|
+
*
|
|
173
|
+
* The runner calls it for a stage that declares `recover`.
|
|
174
|
+
* A stage calls it for a failure of work the answer doesn't depend on, such as building a trace.
|
|
175
|
+
*/
|
|
176
|
+
export function recordFault(context: Pick<RequestContext<never>, "faults">, stage: string, cause: unknown): void {
|
|
177
|
+
context.faults.push({
|
|
178
|
+
stage,
|
|
179
|
+
name: cause instanceof Error ? cause.name : "Error",
|
|
180
|
+
message: errorMessage(cause),
|
|
181
|
+
cause,
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* One step of a pipeline.
|
|
187
|
+
*
|
|
188
|
+
* @typeParam Input What the stage reads.
|
|
189
|
+
* @typeParam Output What the stage returns.
|
|
190
|
+
* @typeParam Trace The records the stage writes.
|
|
191
|
+
* @typeParam ID The stage identifiers of the pipeline the stage belongs to.
|
|
192
|
+
*/
|
|
193
|
+
export interface PipelineStage<Input, Output, Trace = StageRecord, ID extends string = string> {
|
|
194
|
+
/**
|
|
195
|
+
* The stage's identifier.
|
|
196
|
+
* The context's timing keys the stage's duration by it.
|
|
197
|
+
*/
|
|
198
|
+
readonly id: ID
|
|
199
|
+
run(input: Input, context: RequestContext<Trace>): Output | Promise<Output>
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The output the pipeline continues with when `run` throws.
|
|
203
|
+
*
|
|
204
|
+
* The runner records a fault for a stage that declares it, and rethrows for a stage that leaves it out.
|
|
205
|
+
*/
|
|
206
|
+
recover?(input: Input): Output
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Runs one stage: checks the abort signal, runs the stage, and adds its duration to the context's timing.
|
|
211
|
+
*
|
|
212
|
+
* An aborted request rejects with the signal's reason, the value the cancelling code aborted with.
|
|
213
|
+
* `abortKindOf` in `#async/abort` reads that reason's kind.
|
|
214
|
+
*
|
|
215
|
+
* The signal is checked before the stage, so a running stage finishes first.
|
|
216
|
+
*
|
|
217
|
+
* A stage that declares `recover` and throws has a fault recorded, and the run
|
|
218
|
+
* continues with the recovered output.
|
|
219
|
+
*/
|
|
220
|
+
export async function runStage<Input, Output, Trace>(
|
|
221
|
+
stage: PipelineStage<Input, Output, Trace>,
|
|
222
|
+
input: Input,
|
|
223
|
+
context: RequestContext<Trace>
|
|
224
|
+
): Promise<Output> {
|
|
225
|
+
if (context.signal?.aborted) {
|
|
226
|
+
throw context.signal.reason ?? new DOMException("Pipeline aborted", "AbortError")
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const startedAt = performance.now()
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
return await stage.run(input, context)
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (!stage.recover) throw error
|
|
235
|
+
|
|
236
|
+
recordFault(context, FAULT_STAGE_SPELLINGS[stage.id] ?? stage.id, error)
|
|
237
|
+
|
|
238
|
+
return stage.recover(input)
|
|
239
|
+
} finally {
|
|
240
|
+
context.timing[stage.id] = (context.timing[stage.id] ?? 0) + (performance.now() - startedAt)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Runs stages in order, each reading the output of the stage before it.
|
|
246
|
+
*/
|
|
247
|
+
export async function runStages<Value, Trace>(
|
|
248
|
+
stages: readonly PipelineStage<Value, Value, Trace>[],
|
|
249
|
+
input: Value,
|
|
250
|
+
context: RequestContext<Trace>
|
|
251
|
+
): Promise<Value> {
|
|
252
|
+
let value = input
|
|
253
|
+
|
|
254
|
+
for (const stage of stages) {
|
|
255
|
+
value = await runStage(stage, value, context)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return value
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* A stage that rewrites the parse tree and writes what it changed to the trace.
|
|
263
|
+
*
|
|
264
|
+
* It writes a {@linkcode TreeRewriteRecord} only when the request traces in detail
|
|
265
|
+
* and the tree's outline changed.
|
|
266
|
+
* The rewrite may change the tree in place, so the stage reads the outline before the rewrite runs.
|
|
267
|
+
*/
|
|
268
|
+
export function treeRewriteStage<ID extends string>(
|
|
269
|
+
id: ID,
|
|
270
|
+
rewrite: (tree: AddressTree) => AddressTree
|
|
271
|
+
): PipelineStage<AddressTree, AddressTree, TreeRewriteRecord, ID> {
|
|
272
|
+
return {
|
|
273
|
+
id,
|
|
274
|
+
run(tree, context) {
|
|
275
|
+
if (!context.trace || !context.detail) return rewrite(tree)
|
|
276
|
+
|
|
277
|
+
const before = decodeAsOutlineLines(tree, { metadata: true })
|
|
278
|
+
const rewritten = rewrite(tree)
|
|
279
|
+
const after = decodeAsOutlineLines(rewritten, { metadata: true })
|
|
280
|
+
const removed = before.filter((line) => !after.includes(line))
|
|
281
|
+
const added = after.filter((line) => !before.includes(line))
|
|
282
|
+
|
|
283
|
+
if (removed.length || added.length) {
|
|
284
|
+
context.trace({ kind: "tree-rewrite", stage: id, removed, added })
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return rewritten
|
|
288
|
+
},
|
|
289
|
+
}
|
|
290
|
+
}
|