@driftsys/markspec 0.4.0 → 0.6.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 +74 -20
- package/esm/ast/build.d.ts +60 -0
- package/esm/ast/build.d.ts.map +1 -0
- package/esm/ast/build.js +516 -0
- package/esm/ast/equivalence.d.ts +18 -0
- package/esm/ast/equivalence.d.ts.map +1 -0
- package/esm/ast/equivalence.js +56 -0
- package/esm/ast/nodes.d.ts +189 -0
- package/esm/ast/nodes.d.ts.map +1 -0
- package/esm/ast/nodes.js +17 -0
- package/esm/ast/normalize.d.ts +58 -0
- package/esm/ast/normalize.d.ts.map +1 -0
- package/esm/ast/normalize.js +197 -0
- package/esm/ast/render.d.ts +34 -0
- package/esm/ast/render.d.ts.map +1 -0
- package/esm/ast/render.js +215 -0
- package/esm/compiler/constants.d.ts +16 -0
- package/esm/compiler/constants.d.ts.map +1 -0
- package/esm/compiler/constants.js +26 -0
- package/esm/compiler/discipline_classifier.d.ts +55 -0
- package/esm/compiler/discipline_classifier.d.ts.map +1 -0
- package/esm/compiler/discipline_classifier.js +191 -0
- package/esm/compiler/inverses.d.ts +2 -1
- package/esm/compiler/inverses.d.ts.map +1 -1
- package/esm/compiler/inverses.js +33 -14
- package/esm/compiler/manifest.d.ts +59 -0
- package/esm/compiler/manifest.d.ts.map +1 -0
- package/esm/compiler/manifest.js +48 -0
- package/esm/compiler/mod.d.ts +38 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +202 -50
- package/esm/compiler/ndjson_writer.d.ts +50 -0
- package/esm/compiler/ndjson_writer.d.ts.map +1 -0
- package/esm/compiler/ndjson_writer.js +73 -0
- package/esm/compiler/schema.d.ts +33 -1
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +30 -9
- package/esm/config/markspec.d.ts +5 -0
- package/esm/config/markspec.d.ts.map +1 -1
- package/esm/config/markspec.js +17 -2
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +54 -0
- package/esm/formatter/mod.d.ts +55 -4
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +423 -46
- package/esm/formatter/synth_ulid.d.ts +21 -0
- package/esm/formatter/synth_ulid.d.ts.map +1 -0
- package/esm/formatter/synth_ulid.js +64 -0
- package/esm/lexicons/loader.d.ts +35 -0
- package/esm/lexicons/loader.d.ts.map +1 -0
- package/esm/lexicons/loader.js +51 -0
- package/esm/lexicons/mod.d.ts +13 -0
- package/esm/lexicons/mod.d.ts.map +1 -0
- package/esm/lexicons/mod.js +12 -0
- package/esm/lint/glossary.d.ts +45 -0
- package/esm/lint/glossary.d.ts.map +1 -0
- package/esm/lint/glossary.js +85 -0
- package/esm/lint/mod.d.ts +14 -0
- package/esm/lint/mod.d.ts.map +1 -0
- package/esm/lint/mod.js +9 -0
- package/esm/lint/range_util.d.ts +25 -0
- package/esm/lint/range_util.d.ts.map +1 -0
- package/esm/lint/range_util.js +50 -0
- package/esm/lint/rules/ears.d.ts +39 -0
- package/esm/lint/rules/ears.d.ts.map +1 -0
- package/esm/lint/rules/ears.js +316 -0
- package/esm/lint/rules/incose_sentence.d.ts +46 -0
- package/esm/lint/rules/incose_sentence.d.ts.map +1 -0
- package/esm/lint/rules/incose_sentence.js +417 -0
- package/esm/lint/rules/lexicon.d.ts +24 -0
- package/esm/lint/rules/lexicon.d.ts.map +1 -0
- package/esm/lint/rules/lexicon.js +236 -0
- package/esm/lint/rules/modal_sentence.d.ts +46 -0
- package/esm/lint/rules/modal_sentence.d.ts.map +1 -0
- package/esm/lint/rules/modal_sentence.js +146 -0
- package/esm/lint/rules/passive.d.ts +64 -0
- package/esm/lint/rules/passive.d.ts.map +1 -0
- package/esm/lint/rules/passive.js +282 -0
- package/esm/lint/rules/struct.d.ts +17 -0
- package/esm/lint/rules/struct.d.ts.map +1 -0
- package/esm/lint/rules/struct.js +55 -0
- package/esm/lint/rules/suppression.d.ts +54 -0
- package/esm/lint/rules/suppression.d.ts.map +1 -0
- package/esm/lint/rules/suppression.js +129 -0
- package/esm/lint/rules/xref.d.ts +19 -0
- package/esm/lint/rules/xref.d.ts.map +1 -0
- package/esm/lint/rules/xref.js +248 -0
- package/esm/lint/runner.d.ts +59 -0
- package/esm/lint/runner.d.ts.map +1 -0
- package/esm/lint/runner.js +153 -0
- package/esm/lint/score.d.ts +64 -0
- package/esm/lint/score.d.ts.map +1 -0
- package/esm/lint/score.js +163 -0
- package/esm/lint/segmenter.d.ts +32 -0
- package/esm/lint/segmenter.d.ts.map +1 -0
- package/esm/lint/segmenter.js +79 -0
- package/esm/lint/types.d.ts +31 -0
- package/esm/lint/types.d.ts.map +1 -0
- package/esm/lint/types.js +9 -0
- package/esm/lock/canonical_edges.d.ts +31 -0
- package/esm/lock/canonical_edges.d.ts.map +1 -0
- package/esm/lock/canonical_edges.js +57 -0
- package/esm/lock/check.d.ts +24 -0
- package/esm/lock/check.d.ts.map +1 -0
- package/esm/lock/check.js +127 -0
- package/esm/lock/hash.d.ts +12 -0
- package/esm/lock/hash.d.ts.map +1 -0
- package/esm/lock/hash.js +32 -0
- package/esm/lock/mod.d.ts +19 -0
- package/esm/lock/mod.d.ts.map +1 -0
- package/esm/lock/mod.js +14 -0
- package/esm/lock/model.d.ts +81 -0
- package/esm/lock/model.d.ts.map +1 -0
- package/esm/lock/model.js +7 -0
- package/esm/lock/parser.d.ts +26 -0
- package/esm/lock/parser.d.ts.map +1 -0
- package/esm/lock/parser.js +195 -0
- package/esm/lock/resolve.d.ts +142 -0
- package/esm/lock/resolve.d.ts.map +1 -0
- package/esm/lock/resolve.js +389 -0
- package/esm/lock/serializer.d.ts +14 -0
- package/esm/lock/serializer.d.ts.map +1 -0
- package/esm/lock/serializer.js +104 -0
- package/esm/mod.d.ts +28 -8
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +23 -4
- package/esm/model/attributes.d.ts +6 -0
- package/esm/model/attributes.d.ts.map +1 -1
- package/esm/model/attributes.js +200 -2
- package/esm/model/discipline.d.ts +53 -0
- package/esm/model/discipline.d.ts.map +1 -0
- package/esm/model/discipline.js +50 -0
- package/esm/model/discriminating_attr.d.ts +33 -0
- package/esm/model/discriminating_attr.d.ts.map +1 -0
- package/esm/model/discriminating_attr.js +74 -0
- package/esm/model/mod.d.ts +267 -14
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +99 -3
- package/esm/model/profile.d.ts +102 -27
- package/esm/model/profile.d.ts.map +1 -1
- package/esm/model/source_introspection.d.ts +26 -0
- package/esm/model/source_introspection.d.ts.map +1 -0
- package/esm/model/source_introspection.js +77 -0
- package/esm/model/type_hierarchy.d.ts +51 -0
- package/esm/model/type_hierarchy.d.ts.map +1 -0
- package/esm/model/type_hierarchy.js +126 -0
- package/esm/model/uri_scheme_map.d.ts +21 -0
- package/esm/model/uri_scheme_map.d.ts.map +1 -0
- package/esm/model/uri_scheme_map.js +66 -0
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +10 -16
- package/esm/parser/body_tokens.d.ts +35 -0
- package/esm/parser/body_tokens.d.ts.map +1 -0
- package/esm/parser/body_tokens.js +232 -0
- package/esm/parser/glossary.d.ts +51 -0
- package/esm/parser/glossary.d.ts.map +1 -0
- package/esm/parser/glossary.js +219 -0
- package/esm/parser/grammars.d.ts +5 -3
- package/esm/parser/grammars.d.ts.map +1 -1
- package/esm/parser/grammars.js +12 -4
- package/esm/parser/language_spec.d.ts +55 -0
- package/esm/parser/language_spec.d.ts.map +1 -0
- package/esm/parser/language_spec.js +419 -0
- package/esm/parser/line_map.d.ts +60 -0
- package/esm/parser/line_map.d.ts.map +1 -0
- package/esm/parser/line_map.js +41 -0
- package/esm/parser/markdown.d.ts +9 -0
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +317 -25
- package/esm/parser/mod.d.ts +5 -0
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +31 -8
- package/esm/parser/source.d.ts +53 -2
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +158 -68
- package/esm/parser/translate.d.ts +24 -0
- package/esm/parser/translate.d.ts.map +1 -0
- package/esm/parser/translate.js +99 -0
- package/esm/profile/chain.d.ts +8 -0
- package/esm/profile/chain.d.ts.map +1 -1
- package/esm/profile/chain.js +32 -14
- package/esm/profile/colors.js +1 -1
- package/esm/profile/default_profile.d.ts +25 -0
- package/esm/profile/default_profile.d.ts.map +1 -0
- package/esm/profile/default_profile.js +43 -0
- package/esm/profile/discipline_mode.d.ts +64 -0
- package/esm/profile/discipline_mode.d.ts.map +1 -0
- package/esm/profile/discipline_mode.js +133 -0
- package/esm/profile/discipline_registry.d.ts +41 -0
- package/esm/profile/discipline_registry.d.ts.map +1 -0
- package/esm/profile/discipline_registry.js +67 -0
- package/esm/profile/introspect.d.ts +135 -0
- package/esm/profile/introspect.d.ts.map +1 -0
- package/esm/profile/introspect.js +378 -0
- package/esm/profile/load.d.ts +3 -1
- package/esm/profile/load.d.ts.map +1 -1
- package/esm/profile/load.js +91 -5
- package/esm/profile/manifest.d.ts.map +1 -1
- package/esm/profile/manifest.js +512 -90
- package/esm/profile/merge.d.ts.map +1 -1
- package/esm/profile/merge.js +251 -39
- package/esm/profile/mod.d.ts +4 -4
- package/esm/profile/mod.d.ts.map +1 -1
- package/esm/profile/mod.js +7 -2
- package/esm/reporter/mod.js +4 -4
- package/esm/sync/locked_attributes.d.ts +19 -0
- package/esm/sync/locked_attributes.d.ts.map +1 -0
- package/esm/sync/locked_attributes.js +27 -0
- package/esm/sync/log.d.ts +34 -0
- package/esm/sync/log.d.ts.map +1 -0
- package/esm/sync/log.js +48 -0
- package/esm/sync/mapping.d.ts +66 -0
- package/esm/sync/mapping.d.ts.map +1 -0
- package/esm/sync/mapping.js +165 -0
- package/esm/sync/mod.d.ts +16 -0
- package/esm/sync/mod.d.ts.map +1 -0
- package/esm/sync/mod.js +12 -0
- package/esm/sync/status.d.ts +23 -0
- package/esm/sync/status.d.ts.map +1 -0
- package/esm/sync/status.js +21 -0
- package/esm/typl/ast.d.ts +87 -0
- package/esm/typl/ast.d.ts.map +1 -0
- package/esm/typl/ast.js +21 -0
- package/esm/typl/bridge.d.ts +32 -0
- package/esm/typl/bridge.d.ts.map +1 -0
- package/esm/typl/bridge.js +27 -0
- package/esm/typl/bullet.d.ts +34 -0
- package/esm/typl/bullet.d.ts.map +1 -0
- package/esm/typl/bullet.js +44 -0
- package/esm/typl/diagnostics.d.ts +43 -0
- package/esm/typl/diagnostics.d.ts.map +1 -0
- package/esm/typl/diagnostics.js +61 -0
- package/esm/typl/fence.d.ts +31 -0
- package/esm/typl/fence.d.ts.map +1 -0
- package/esm/typl/fence.js +24 -0
- package/esm/typl/grammar.d.ts +20 -0
- package/esm/typl/grammar.d.ts.map +1 -0
- package/esm/typl/grammar.js +471 -0
- package/esm/typl/inline.d.ts +34 -0
- package/esm/typl/inline.d.ts.map +1 -0
- package/esm/typl/inline.js +48 -0
- package/esm/typl/lexer.d.ts +37 -0
- package/esm/typl/lexer.d.ts.map +1 -0
- package/esm/typl/lexer.js +234 -0
- package/esm/typl/mod.d.ts +23 -0
- package/esm/typl/mod.d.ts.map +1 -0
- package/esm/typl/mod.js +16 -0
- package/esm/typl/registry.d.ts +42 -0
- package/esm/typl/registry.d.ts.map +1 -0
- package/esm/typl/registry.js +26 -0
- package/esm/typl/validator.d.ts +29 -0
- package/esm/typl/validator.d.ts.map +1 -0
- package/esm/typl/validator.js +141 -0
- package/esm/util/fence.d.ts +30 -0
- package/esm/util/fence.d.ts.map +1 -0
- package/esm/util/fence.js +40 -0
- package/esm/util/line_endings.d.ts +33 -0
- package/esm/util/line_endings.d.ts.map +1 -0
- package/esm/util/line_endings.js +53 -0
- package/esm/util/modals.d.ts +29 -0
- package/esm/util/modals.d.ts.map +1 -0
- package/esm/util/modals.js +38 -0
- package/esm/validator/attributes.d.ts +3 -3
- package/esm/validator/attributes.d.ts.map +1 -1
- package/esm/validator/attributes.js +1 -18
- package/esm/validator/body_blocks.d.ts +38 -0
- package/esm/validator/body_blocks.d.ts.map +1 -0
- package/esm/validator/body_blocks.js +218 -0
- package/esm/validator/caption_convention.d.ts +29 -0
- package/esm/validator/caption_convention.d.ts.map +1 -0
- package/esm/validator/caption_convention.js +58 -0
- package/esm/validator/captions.d.ts +22 -0
- package/esm/validator/captions.d.ts.map +1 -0
- package/esm/validator/captions.js +137 -0
- package/esm/validator/component_schemes.d.ts +73 -0
- package/esm/validator/component_schemes.d.ts.map +1 -0
- package/esm/validator/component_schemes.js +375 -0
- package/esm/validator/discipline.d.ts +35 -0
- package/esm/validator/discipline.d.ts.map +1 -0
- package/esm/validator/discipline.js +204 -0
- package/esm/validator/feature_ac.d.ts +28 -0
- package/esm/validator/feature_ac.d.ts.map +1 -0
- package/esm/validator/feature_ac.js +102 -0
- package/esm/validator/listing.d.ts +42 -0
- package/esm/validator/listing.d.ts.map +1 -0
- package/esm/validator/listing.js +295 -0
- package/esm/validator/mod.d.ts +3 -1
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +275 -13
- package/esm/validator/modal_keywords.d.ts +25 -0
- package/esm/validator/modal_keywords.d.ts.map +1 -0
- package/esm/validator/modal_keywords.js +54 -0
- package/esm/validator/pattern.d.ts +15 -8
- package/esm/validator/pattern.d.ts.map +1 -1
- package/esm/validator/pattern.js +42 -19
- package/esm/validator/per_type_attrs.d.ts +29 -0
- package/esm/validator/per_type_attrs.d.ts.map +1 -0
- package/esm/validator/per_type_attrs.js +75 -0
- package/esm/validator/pipeline.d.ts +18 -2
- package/esm/validator/pipeline.d.ts.map +1 -1
- package/esm/validator/pipeline.js +76 -21
- package/esm/validator/trace_types.d.ts +26 -0
- package/esm/validator/trace_types.d.ts.map +1 -0
- package/esm/validator/trace_types.js +232 -0
- package/esm/validator/traceability.d.ts +3 -4
- package/esm/validator/traceability.d.ts.map +1 -1
- package/esm/validator/traceability.js +5 -10
- package/esm/validator/type_resolution.d.ts +67 -0
- package/esm/validator/type_resolution.d.ts.map +1 -0
- package/esm/validator/type_resolution.js +162 -0
- package/esm/validator/types.d.ts +45 -0
- package/esm/validator/types.d.ts.map +1 -1
- package/esm/validator/types.js +128 -16
- package/esm/validator/value_types.d.ts +8 -0
- package/esm/validator/value_types.d.ts.map +1 -1
- package/esm/validator/value_types.js +8 -1
- package/package.json +2 -2
- package/script/ast/build.d.ts +60 -0
- package/script/ast/build.d.ts.map +1 -0
- package/script/ast/build.js +521 -0
- package/script/ast/equivalence.d.ts +18 -0
- package/script/ast/equivalence.d.ts.map +1 -0
- package/script/ast/equivalence.js +59 -0
- package/script/ast/nodes.d.ts +189 -0
- package/script/ast/nodes.d.ts.map +1 -0
- package/script/ast/nodes.js +18 -0
- package/script/ast/normalize.d.ts +58 -0
- package/script/ast/normalize.d.ts.map +1 -0
- package/script/ast/normalize.js +200 -0
- package/script/ast/render.d.ts +34 -0
- package/script/ast/render.d.ts.map +1 -0
- package/script/ast/render.js +218 -0
- package/script/compiler/constants.d.ts +16 -0
- package/script/compiler/constants.d.ts.map +1 -0
- package/script/compiler/constants.js +29 -0
- package/script/compiler/discipline_classifier.d.ts +55 -0
- package/script/compiler/discipline_classifier.d.ts.map +1 -0
- package/script/compiler/discipline_classifier.js +196 -0
- package/script/compiler/inverses.d.ts +2 -1
- package/script/compiler/inverses.d.ts.map +1 -1
- package/script/compiler/inverses.js +33 -14
- package/script/compiler/manifest.d.ts +59 -0
- package/script/compiler/manifest.d.ts.map +1 -0
- package/script/compiler/manifest.js +51 -0
- package/script/compiler/mod.d.ts +38 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +206 -54
- package/script/compiler/ndjson_writer.d.ts +50 -0
- package/script/compiler/ndjson_writer.d.ts.map +1 -0
- package/script/compiler/ndjson_writer.js +78 -0
- package/script/compiler/schema.d.ts +33 -1
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +30 -8
- package/script/config/markspec.d.ts +5 -0
- package/script/config/markspec.d.ts.map +1 -1
- package/script/config/markspec.js +17 -2
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +54 -0
- package/script/formatter/mod.d.ts +55 -4
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +426 -46
- package/script/formatter/synth_ulid.d.ts +21 -0
- package/script/formatter/synth_ulid.d.ts.map +1 -0
- package/script/formatter/synth_ulid.js +67 -0
- package/script/lexicons/loader.d.ts +35 -0
- package/script/lexicons/loader.d.ts.map +1 -0
- package/script/lexicons/loader.js +55 -0
- package/script/lexicons/mod.d.ts +13 -0
- package/script/lexicons/mod.d.ts.map +1 -0
- package/script/lexicons/mod.js +17 -0
- package/script/lint/glossary.d.ts +45 -0
- package/script/lint/glossary.d.ts.map +1 -0
- package/script/lint/glossary.js +88 -0
- package/script/lint/mod.d.ts +14 -0
- package/script/lint/mod.d.ts.map +1 -0
- package/script/lint/mod.js +17 -0
- package/script/lint/range_util.d.ts +25 -0
- package/script/lint/range_util.d.ts.map +1 -0
- package/script/lint/range_util.js +53 -0
- package/script/lint/rules/ears.d.ts +39 -0
- package/script/lint/rules/ears.d.ts.map +1 -0
- package/script/lint/rules/ears.js +320 -0
- package/script/lint/rules/incose_sentence.d.ts +46 -0
- package/script/lint/rules/incose_sentence.d.ts.map +1 -0
- package/script/lint/rules/incose_sentence.js +421 -0
- package/script/lint/rules/lexicon.d.ts +24 -0
- package/script/lint/rules/lexicon.d.ts.map +1 -0
- package/script/lint/rules/lexicon.js +240 -0
- package/script/lint/rules/modal_sentence.d.ts +46 -0
- package/script/lint/rules/modal_sentence.d.ts.map +1 -0
- package/script/lint/rules/modal_sentence.js +150 -0
- package/script/lint/rules/passive.d.ts +64 -0
- package/script/lint/rules/passive.d.ts.map +1 -0
- package/script/lint/rules/passive.js +286 -0
- package/script/lint/rules/struct.d.ts +17 -0
- package/script/lint/rules/struct.d.ts.map +1 -0
- package/script/lint/rules/struct.js +59 -0
- package/script/lint/rules/suppression.d.ts +54 -0
- package/script/lint/rules/suppression.d.ts.map +1 -0
- package/script/lint/rules/suppression.js +136 -0
- package/script/lint/rules/xref.d.ts +19 -0
- package/script/lint/rules/xref.d.ts.map +1 -0
- package/script/lint/rules/xref.js +251 -0
- package/script/lint/runner.d.ts +59 -0
- package/script/lint/runner.d.ts.map +1 -0
- package/script/lint/runner.js +157 -0
- package/script/lint/score.d.ts +64 -0
- package/script/lint/score.d.ts.map +1 -0
- package/script/lint/score.js +167 -0
- package/script/lint/segmenter.d.ts +32 -0
- package/script/lint/segmenter.d.ts.map +1 -0
- package/script/lint/segmenter.js +82 -0
- package/script/lint/types.d.ts +31 -0
- package/script/lint/types.d.ts.map +1 -0
- package/script/lint/types.js +10 -0
- package/script/lock/canonical_edges.d.ts +31 -0
- package/script/lock/canonical_edges.d.ts.map +1 -0
- package/script/lock/canonical_edges.js +61 -0
- package/script/lock/check.d.ts +24 -0
- package/script/lock/check.d.ts.map +1 -0
- package/script/lock/check.js +130 -0
- package/script/lock/hash.d.ts +12 -0
- package/script/lock/hash.d.ts.map +1 -0
- package/script/lock/hash.js +36 -0
- package/script/lock/mod.d.ts +19 -0
- package/script/lock/mod.d.ts.map +1 -0
- package/script/lock/mod.js +31 -0
- package/script/lock/model.d.ts +81 -0
- package/script/lock/model.d.ts.map +1 -0
- package/script/lock/model.js +10 -0
- package/script/lock/parser.d.ts +26 -0
- package/script/lock/parser.d.ts.map +1 -0
- package/script/lock/parser.js +198 -0
- package/script/lock/resolve.d.ts +142 -0
- package/script/lock/resolve.d.ts.map +1 -0
- package/script/lock/resolve.js +397 -0
- package/script/lock/serializer.d.ts +14 -0
- package/script/lock/serializer.d.ts.map +1 -0
- package/script/lock/serializer.js +107 -0
- package/script/mod.d.ts +28 -8
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +129 -32
- package/script/model/attributes.d.ts +6 -0
- package/script/model/attributes.d.ts.map +1 -1
- package/script/model/attributes.js +201 -3
- package/script/model/discipline.d.ts +53 -0
- package/script/model/discipline.d.ts.map +1 -0
- package/script/model/discipline.js +53 -0
- package/script/model/discriminating_attr.d.ts +33 -0
- package/script/model/discriminating_attr.d.ts.map +1 -0
- package/script/model/discriminating_attr.js +77 -0
- package/script/model/mod.d.ts +267 -14
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +111 -3
- package/script/model/profile.d.ts +102 -27
- package/script/model/profile.d.ts.map +1 -1
- package/script/model/source_introspection.d.ts +26 -0
- package/script/model/source_introspection.d.ts.map +1 -0
- package/script/model/source_introspection.js +80 -0
- package/script/model/type_hierarchy.d.ts +51 -0
- package/script/model/type_hierarchy.d.ts.map +1 -0
- package/script/model/type_hierarchy.js +130 -0
- package/script/model/uri_scheme_map.d.ts +21 -0
- package/script/model/uri_scheme_map.d.ts.map +1 -0
- package/script/model/uri_scheme_map.js +69 -0
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +10 -16
- package/script/parser/body_tokens.d.ts +35 -0
- package/script/parser/body_tokens.d.ts.map +1 -0
- package/script/parser/body_tokens.js +235 -0
- package/script/parser/glossary.d.ts +51 -0
- package/script/parser/glossary.d.ts.map +1 -0
- package/script/parser/glossary.js +224 -0
- package/script/parser/grammars.d.ts +5 -3
- package/script/parser/grammars.d.ts.map +1 -1
- package/script/parser/grammars.js +15 -8
- package/script/parser/language_spec.d.ts +55 -0
- package/script/parser/language_spec.d.ts.map +1 -0
- package/script/parser/language_spec.js +423 -0
- package/script/parser/line_map.d.ts +60 -0
- package/script/parser/line_map.d.ts.map +1 -0
- package/script/parser/line_map.js +44 -0
- package/script/parser/markdown.d.ts +9 -0
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +315 -23
- package/script/parser/mod.d.ts +5 -0
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +36 -7
- package/script/parser/source.d.ts +53 -2
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +159 -69
- package/script/parser/translate.d.ts +24 -0
- package/script/parser/translate.d.ts.map +1 -0
- package/script/parser/translate.js +102 -0
- package/script/profile/chain.d.ts +8 -0
- package/script/profile/chain.d.ts.map +1 -1
- package/script/profile/chain.js +32 -14
- package/script/profile/colors.js +1 -1
- package/script/profile/default_profile.d.ts +25 -0
- package/script/profile/default_profile.d.ts.map +1 -0
- package/script/profile/default_profile.js +46 -0
- package/script/profile/discipline_mode.d.ts +64 -0
- package/script/profile/discipline_mode.d.ts.map +1 -0
- package/script/profile/discipline_mode.js +138 -0
- package/script/profile/discipline_registry.d.ts +41 -0
- package/script/profile/discipline_registry.d.ts.map +1 -0
- package/script/profile/discipline_registry.js +70 -0
- package/script/profile/introspect.d.ts +135 -0
- package/script/profile/introspect.d.ts.map +1 -0
- package/script/profile/introspect.js +381 -0
- package/script/profile/load.d.ts +3 -1
- package/script/profile/load.d.ts.map +1 -1
- package/script/profile/load.js +91 -5
- package/script/profile/manifest.d.ts.map +1 -1
- package/script/profile/manifest.js +511 -89
- package/script/profile/merge.d.ts.map +1 -1
- package/script/profile/merge.js +251 -39
- package/script/profile/mod.d.ts +4 -4
- package/script/profile/mod.d.ts.map +1 -1
- package/script/profile/mod.js +12 -6
- package/script/reporter/mod.js +4 -4
- package/script/sync/locked_attributes.d.ts +19 -0
- package/script/sync/locked_attributes.d.ts.map +1 -0
- package/script/sync/locked_attributes.js +30 -0
- package/script/sync/log.d.ts +34 -0
- package/script/sync/log.d.ts.map +1 -0
- package/script/sync/log.js +52 -0
- package/script/sync/mapping.d.ts +66 -0
- package/script/sync/mapping.d.ts.map +1 -0
- package/script/sync/mapping.js +169 -0
- package/script/sync/mod.d.ts +16 -0
- package/script/sync/mod.d.ts.map +1 -0
- package/script/sync/mod.js +21 -0
- package/script/sync/status.d.ts +23 -0
- package/script/sync/status.d.ts.map +1 -0
- package/script/sync/status.js +24 -0
- package/script/typl/ast.d.ts +87 -0
- package/script/typl/ast.d.ts.map +1 -0
- package/script/typl/ast.js +24 -0
- package/script/typl/bridge.d.ts +32 -0
- package/script/typl/bridge.d.ts.map +1 -0
- package/script/typl/bridge.js +30 -0
- package/script/typl/bullet.d.ts +34 -0
- package/script/typl/bullet.d.ts.map +1 -0
- package/script/typl/bullet.js +47 -0
- package/script/typl/diagnostics.d.ts +43 -0
- package/script/typl/diagnostics.d.ts.map +1 -0
- package/script/typl/diagnostics.js +65 -0
- package/script/typl/fence.d.ts +31 -0
- package/script/typl/fence.d.ts.map +1 -0
- package/script/typl/fence.js +27 -0
- package/script/typl/grammar.d.ts +20 -0
- package/script/typl/grammar.d.ts.map +1 -0
- package/script/typl/grammar.js +474 -0
- package/script/typl/inline.d.ts +34 -0
- package/script/typl/inline.d.ts.map +1 -0
- package/script/typl/inline.js +51 -0
- package/script/typl/lexer.d.ts +37 -0
- package/script/typl/lexer.d.ts.map +1 -0
- package/script/typl/lexer.js +237 -0
- package/script/typl/mod.d.ts +23 -0
- package/script/typl/mod.d.ts.map +1 -0
- package/script/typl/mod.js +29 -0
- package/script/typl/registry.d.ts +42 -0
- package/script/typl/registry.d.ts.map +1 -0
- package/script/typl/registry.js +29 -0
- package/script/typl/validator.d.ts +29 -0
- package/script/typl/validator.d.ts.map +1 -0
- package/script/typl/validator.js +144 -0
- package/script/util/fence.d.ts +30 -0
- package/script/util/fence.d.ts.map +1 -0
- package/script/util/fence.js +44 -0
- package/script/util/line_endings.d.ts +33 -0
- package/script/util/line_endings.d.ts.map +1 -0
- package/script/util/line_endings.js +58 -0
- package/script/util/modals.d.ts +29 -0
- package/script/util/modals.d.ts.map +1 -0
- package/script/util/modals.js +42 -0
- package/script/validator/attributes.d.ts +3 -3
- package/script/validator/attributes.d.ts.map +1 -1
- package/script/validator/attributes.js +1 -18
- package/script/validator/body_blocks.d.ts +38 -0
- package/script/validator/body_blocks.d.ts.map +1 -0
- package/script/validator/body_blocks.js +221 -0
- package/script/validator/caption_convention.d.ts +29 -0
- package/script/validator/caption_convention.d.ts.map +1 -0
- package/script/validator/caption_convention.js +61 -0
- package/script/validator/captions.d.ts +22 -0
- package/script/validator/captions.d.ts.map +1 -0
- package/script/validator/captions.js +140 -0
- package/script/validator/component_schemes.d.ts +73 -0
- package/script/validator/component_schemes.d.ts.map +1 -0
- package/script/validator/component_schemes.js +384 -0
- package/script/validator/discipline.d.ts +35 -0
- package/script/validator/discipline.d.ts.map +1 -0
- package/script/validator/discipline.js +207 -0
- package/script/validator/feature_ac.d.ts +28 -0
- package/script/validator/feature_ac.d.ts.map +1 -0
- package/script/validator/feature_ac.js +105 -0
- package/script/validator/listing.d.ts +42 -0
- package/script/validator/listing.d.ts.map +1 -0
- package/script/validator/listing.js +298 -0
- package/script/validator/mod.d.ts +3 -1
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +278 -14
- package/script/validator/modal_keywords.d.ts +25 -0
- package/script/validator/modal_keywords.d.ts.map +1 -0
- package/script/validator/modal_keywords.js +57 -0
- package/script/validator/pattern.d.ts +15 -8
- package/script/validator/pattern.d.ts.map +1 -1
- package/script/validator/pattern.js +42 -19
- package/script/validator/per_type_attrs.d.ts +29 -0
- package/script/validator/per_type_attrs.d.ts.map +1 -0
- package/script/validator/per_type_attrs.js +78 -0
- package/script/validator/pipeline.d.ts +18 -2
- package/script/validator/pipeline.d.ts.map +1 -1
- package/script/validator/pipeline.js +78 -22
- package/script/validator/trace_types.d.ts +26 -0
- package/script/validator/trace_types.d.ts.map +1 -0
- package/script/validator/trace_types.js +235 -0
- package/script/validator/traceability.d.ts +3 -4
- package/script/validator/traceability.d.ts.map +1 -1
- package/script/validator/traceability.js +5 -10
- package/script/validator/type_resolution.d.ts +67 -0
- package/script/validator/type_resolution.d.ts.map +1 -0
- package/script/validator/type_resolution.js +168 -0
- package/script/validator/types.d.ts +45 -0
- package/script/validator/types.d.ts.map +1 -1
- package/script/validator/types.js +131 -16
- package/script/validator/value_types.d.ts +8 -0
- package/script/validator/value_types.d.ts.map +1 -1
- package/script/validator/value_types.js +10 -2
package/esm/formatter/mod.js
CHANGED
|
@@ -7,20 +7,62 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { ulid as defaultUlid } from "@std/ulid";
|
|
9
9
|
import { stringify as stringifyYaml } from "@std/yaml";
|
|
10
|
-
import { attributeSpec, IDENTITY_KEY } from "../model/mod.js";
|
|
10
|
+
import { attributeSpec, CSV_SPLITTABLE_TYPES, IDENTITY_KEY, } from "../model/mod.js";
|
|
11
11
|
import { ATTR_LINE_RE } from "../parser/attributes.js";
|
|
12
12
|
import { extractFrontMatter } from "../parser/frontmatter.js";
|
|
13
13
|
import { parseMarkdown } from "../parser/markdown.js";
|
|
14
|
+
import { FENCE_RE, walkProseLines } from "../util/fence.js";
|
|
15
|
+
import { applyLineEnding, detectLineEnding, normalizeLineEndings, } from "../util/line_endings.js";
|
|
16
|
+
import { EARS_KEYWORD_RE, isSentenceInitial as _isSentenceInitial, RFC2119_MODAL_RE, } from "../util/modals.js";
|
|
17
|
+
import { synthesizedUlid } from "./synth_ulid.js";
|
|
18
|
+
import { buildBodyAst } from "../ast/build.js";
|
|
19
|
+
import { render as renderBodyAst } from "../ast/render.js";
|
|
20
|
+
import { normalizeBodyAst } from "../ast/normalize.js";
|
|
21
|
+
import { astEquivalent } from "../ast/equivalence.js";
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
23
|
+
* Decide whether the EARS keyword at `offset` in `line` is at sentence
|
|
24
|
+
* start (return value true). Delegates to the shared implementation in
|
|
25
|
+
* `core/util/modals.ts`; re-exported here for backward compatibility with
|
|
26
|
+
* existing callers and tests that import from `formatter/mod.ts`.
|
|
18
27
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
export function isSentenceInitial(line, offset) {
|
|
29
|
+
return _isSentenceInitial(line, offset);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Normalise modal keywords to canonical case in body prose (§3.4.1):
|
|
33
|
+
*
|
|
34
|
+
* - RFC 2119 (`SHALL`, `SHOULD`, `MAY`, `MUST`, optionally `… NOT`) —
|
|
35
|
+
* always lowercased.
|
|
36
|
+
* - EARS (`When`, `While`, `Where`, `Unless`) — lowercased mid-sentence,
|
|
37
|
+
* preserved sentence-initial.
|
|
38
|
+
*
|
|
39
|
+
* The pass skips:
|
|
40
|
+
*
|
|
41
|
+
* - Fenced code blocks (between paired ``` or ~~~ markers) — code is
|
|
42
|
+
* verbatim per round-trip invariants (spec §5.1).
|
|
43
|
+
* - Lines indented by four or more spaces (or a tab) — conservatively
|
|
44
|
+
* captures indented code blocks and attribute trailers, both of which
|
|
45
|
+
* are not prose.
|
|
46
|
+
*
|
|
47
|
+
* @remarks Not called by `format()` as of SP3 Task 5 — body modal
|
|
48
|
+
* normalization moved to `normalizeBodyAst` in the AST pass (spec-correct
|
|
49
|
+
* verbatim-boundary handling). Retained as an exported symbol because
|
|
50
|
+
* `mod_test.ts` tests it directly and `core/ast/normalize.ts` documents
|
|
51
|
+
* the intentional duplication until a follow-up collapses the two. Do NOT
|
|
52
|
+
* delete — external callers may depend on this export.
|
|
53
|
+
*/
|
|
54
|
+
export function normalizeModalKeywords(markdown) {
|
|
55
|
+
const lines = markdown.split("\n");
|
|
56
|
+
walkProseLines(markdown, (line, i) => {
|
|
57
|
+
// Indented-code / attribute-trailer lines aren't prose either.
|
|
58
|
+
if (/^( {4}|\t)/.test(line))
|
|
59
|
+
return;
|
|
60
|
+
let normalized = line.replace(RFC2119_MODAL_RE, (m) => m.toLowerCase());
|
|
61
|
+
normalized = normalized.replace(EARS_KEYWORD_RE, (m, _g1, offset) => isSentenceInitial(normalized, offset) ? m : m.toLowerCase());
|
|
62
|
+
lines[i] = normalized;
|
|
63
|
+
});
|
|
64
|
+
return lines.join("\n");
|
|
65
|
+
}
|
|
24
66
|
/**
|
|
25
67
|
* Canonical front-matter key order per ADR-007. Core keys first, then
|
|
26
68
|
* `metadata` (reserved free-form map), then `extra` (allowlisted ecosystem
|
|
@@ -36,29 +78,228 @@ const FRONT_MATTER_CORE_ORDER = [
|
|
|
36
78
|
"references",
|
|
37
79
|
];
|
|
38
80
|
/**
|
|
39
|
-
* Canonical
|
|
81
|
+
* Canonical trailer ordering per spec §3.3.2 (six-group rule).
|
|
40
82
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
83
|
+
* Groups, top → bottom:
|
|
84
|
+
* 1. Identity & classification — `Id`, `Type`, `Source`, `Origin`.
|
|
85
|
+
* 2. Reference-shape navigation — `Reference-document`, `Reference-url`.
|
|
86
|
+
* 3. Trace upstream relations — authored trace edges (`Part-of`,
|
|
87
|
+
* `Derived-from`, `Satisfies`, …).
|
|
88
|
+
* 4. Type-specific data — payload attributes per concrete type
|
|
89
|
+
* (`Schema-language`, `License`, `Manufacturer`, …).
|
|
90
|
+
* 5. Universal trailing — `References`, `External-id`, `Labels`,
|
|
91
|
+
* `Supersedes`, `Deprecated`.
|
|
92
|
+
* 6. Profile-declared / unknown attributes — preserved in source order
|
|
93
|
+
* at the bottom (§3.3.6: fmt never deletes a key it doesn't own).
|
|
46
94
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
95
|
+
* Generated-origin attributes (`Superseded-by`, every inverse from ADR-003
|
|
96
|
+
* §Part 3) are stripped from this list; the formatter rejects them with
|
|
97
|
+
* MSL-A030 when found in source (current code keeps `Superseded-by:` to
|
|
98
|
+
* round-trip historical fixtures — that hardening lands in a later slice).
|
|
50
99
|
*/
|
|
51
100
|
const CANONICAL_ORDER = [
|
|
101
|
+
// Group 1 — identity & classification
|
|
52
102
|
"Id",
|
|
53
|
-
|
|
54
|
-
|
|
103
|
+
"Type",
|
|
104
|
+
"Source",
|
|
105
|
+
"Origin",
|
|
106
|
+
// Group 2 — reference-shape navigation
|
|
107
|
+
"Reference-document",
|
|
108
|
+
"Reference-url",
|
|
109
|
+
// Group 3 — trace upstream (authored relations)
|
|
110
|
+
"Part-of",
|
|
111
|
+
"Derived-from",
|
|
112
|
+
"Satisfies",
|
|
113
|
+
"Verifies",
|
|
114
|
+
"Tests",
|
|
115
|
+
"Realizes",
|
|
116
|
+
"Provides",
|
|
117
|
+
"Requires",
|
|
118
|
+
"Depends-on",
|
|
119
|
+
"Caused-by",
|
|
120
|
+
"Mitigated-by",
|
|
121
|
+
"Allocated-to",
|
|
122
|
+
"Affects",
|
|
123
|
+
// Group 4 — type-specific data
|
|
124
|
+
"Schema-language",
|
|
125
|
+
"License",
|
|
126
|
+
"Build-manifest",
|
|
127
|
+
"Package-manager",
|
|
128
|
+
"Manufacturer",
|
|
129
|
+
"Part-number",
|
|
130
|
+
"Datasheet",
|
|
131
|
+
"Bus-protocol",
|
|
132
|
+
"Connector-type",
|
|
133
|
+
"Voltage-level",
|
|
134
|
+
"Signal-direction",
|
|
135
|
+
"Symbol",
|
|
136
|
+
"Language",
|
|
137
|
+
"Footprint",
|
|
138
|
+
"Value",
|
|
139
|
+
"Aliases",
|
|
140
|
+
"See-also",
|
|
141
|
+
// Group 5 — universal trailing
|
|
55
142
|
"References",
|
|
56
|
-
"Labels",
|
|
57
143
|
"External-id",
|
|
144
|
+
"Labels",
|
|
58
145
|
"Supersedes",
|
|
59
146
|
"Superseded-by",
|
|
60
147
|
"Deprecated",
|
|
148
|
+
// Group 6 — profile-declared / unknown keys are appended in source order
|
|
149
|
+
// after this list by sortAttributes().
|
|
61
150
|
];
|
|
151
|
+
/**
|
|
152
|
+
* Post-pass: route each entry's body through the canonical body-AST
|
|
153
|
+
* (the load-bearing §5.2 emission path — SP3 Task 5 cutover).
|
|
154
|
+
*
|
|
155
|
+
* Called on the post-collapse `lines` array (after attribute-block
|
|
156
|
+
* splicing and `collapseBlankLines`). The body modal-keyword §3.4.1
|
|
157
|
+
* pass is NO LONGER applied as a pre-parse whole-body string pass; it
|
|
158
|
+
* is now AST-native via `normalizeBodyAst` here (more spec-correct:
|
|
159
|
+
* the AST pass respects §2.5 verbatim boundaries and per-node
|
|
160
|
+
* sentence-initial context that the whole-body string pass could get
|
|
161
|
+
* wrong inside Code/Math blocks). Re-parses the lines to get entries
|
|
162
|
+
* with correct post-collapse line numbers, then for each entry:
|
|
163
|
+
*
|
|
164
|
+
* 1. Takes `entry.body` — the body string from the parser
|
|
165
|
+
* (indent-stripped, trimmed, attrs split off).
|
|
166
|
+
* 2. Builds the body AST, applies `normalizeBodyAst` (the §3.4.1 /
|
|
167
|
+
* §5.2 canonicalization pass), and emits via `render`.
|
|
168
|
+
* 3. Guards the emit with the formal §5 `astEquivalent` relation:
|
|
169
|
+
* `render`-ing the emitted body and re-building must be AST-equal
|
|
170
|
+
* to the canonical AST. If not, this is an SP3 residual — keep
|
|
171
|
+
* the original body lines untouched and raise a LOUD diagnostic
|
|
172
|
+
* (MSL-F900). This branch is RETAINED for safety; over the
|
|
173
|
+
* idempotence corpus and real project docs it never fires.
|
|
174
|
+
* 4. Reconstructs the body segment in `lines` from the emitted
|
|
175
|
+
* string, preserving the leading/trailing blank-line delimiters
|
|
176
|
+
* that separate the body from the title and attr block.
|
|
177
|
+
*
|
|
178
|
+
* Returns `true` when any entry body was rewritten (so `format()` can
|
|
179
|
+
* keep `changed` accurate for `--check` mode); `false` when every body
|
|
180
|
+
* was already §5.2-canonical.
|
|
181
|
+
*
|
|
182
|
+
* `Entry.body` stays `string`; no other module is affected.
|
|
183
|
+
* `normalizeBodyAst` is FORMATTER-ONLY — the validate/parse path must
|
|
184
|
+
* never call it.
|
|
185
|
+
*/
|
|
186
|
+
function emitBodyViaAst(lines, file, diagnostics, cachedEntries) {
|
|
187
|
+
// When the caller supplies pre-parsed entries whose line numbers are still
|
|
188
|
+
// valid in `lines` (i.e., no line-count-changing operations occurred before
|
|
189
|
+
// this call), skip the re-parse entirely — the common hot path for files
|
|
190
|
+
// that are already in canonical form. When the caller passes undefined the
|
|
191
|
+
// re-parse is performed as before.
|
|
192
|
+
let entries;
|
|
193
|
+
if (cachedEntries !== undefined) {
|
|
194
|
+
entries = cachedEntries;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// Diagnostics from this re-parse are intentionally discarded: the
|
|
198
|
+
// input is already canonical (post-collapse) output.
|
|
199
|
+
({ entries } = parseMarkdown(lines.join("\n"), { file }));
|
|
200
|
+
}
|
|
201
|
+
if (entries.length === 0)
|
|
202
|
+
return false;
|
|
203
|
+
let bodyChanged = false;
|
|
204
|
+
// Process bottom-to-top so splices don't shift earlier entry positions.
|
|
205
|
+
const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
|
|
206
|
+
for (const entry of sorted) {
|
|
207
|
+
if (!entry.body.trim())
|
|
208
|
+
continue; // empty or whitespace-only body
|
|
209
|
+
const indent = (entry.location.column - 1) + 2; // marker column (0-based) + 2 spaces = list-item continuation indent
|
|
210
|
+
const indentStr = " ".repeat(indent);
|
|
211
|
+
const titleLineIdx = entry.location.line - 1; // 0-based
|
|
212
|
+
// Locate the body segment in `lines` — between the title line and
|
|
213
|
+
// the attr block start (or item end when there is no attr block).
|
|
214
|
+
const range = findAttributeBlockRange(lines, entry.location.line, indent);
|
|
215
|
+
const bodyStart = titleLineIdx + 1;
|
|
216
|
+
const bodyEnd = range
|
|
217
|
+
? range.start
|
|
218
|
+
: findItemEnd(lines, titleLineIdx, indent);
|
|
219
|
+
if (bodyEnd <= bodyStart)
|
|
220
|
+
continue; // no body lines to replace
|
|
221
|
+
// Route the body through the canonical AST: build → normalize
|
|
222
|
+
// (§3.4.1 / §5.2) → render. The §5 equivalence relation guards the
|
|
223
|
+
// emit; `render`+`build` is the inverse on canonical input for
|
|
224
|
+
// every body shape under the equivalence gate.
|
|
225
|
+
const ast0 = buildBodyAst(entry.body);
|
|
226
|
+
const canonical = normalizeBodyAst(ast0);
|
|
227
|
+
const emittedBody = renderBodyAst(canonical);
|
|
228
|
+
if (!astEquivalent(buildBodyAst(emittedBody), canonical)) {
|
|
229
|
+
// SP3 residual. The build/render inverse is not yet total over
|
|
230
|
+
// every valid Markdown body construct; for a body where the
|
|
231
|
+
// emitted form does not re-build AST-equivalent to the canonical
|
|
232
|
+
// AST we cannot guarantee a lossless §5.2 re-emission. Keep the
|
|
233
|
+
// original body lines EXACTLY as-is — zero corruption, zero
|
|
234
|
+
// spurious rewrites — and raise a LOUD diagnostic so the residual
|
|
235
|
+
// is visible (it never fires over the idempotence corpus or real
|
|
236
|
+
// project docs). This safe-fallback branch is RETAINED by design;
|
|
237
|
+
// only its criterion changed (byte-identity → astEquivalent) and
|
|
238
|
+
// it now diagnoses instead of silently degrading.
|
|
239
|
+
diagnostics.push({
|
|
240
|
+
code: "MSL-F900",
|
|
241
|
+
severity: "error",
|
|
242
|
+
message: `${entry.displayId}: body not AST-equivalent after ` +
|
|
243
|
+
`canonicalization (SP3 residual — formatter kept the ` +
|
|
244
|
+
`original body)`,
|
|
245
|
+
location: entry.location,
|
|
246
|
+
});
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
// The emitted body is the §5.2-canonical body and re-builds
|
|
250
|
+
// AST-equivalent to the canonical AST. Splice it back into the
|
|
251
|
+
// document — the AST is the load-bearing emission path.
|
|
252
|
+
// Reconstruct the body segment: re-add the continuation indent to
|
|
253
|
+
// each non-blank line, preserving the blank-line delimiters that
|
|
254
|
+
// separate the body from the title and attr block.
|
|
255
|
+
const rawSegment = lines.slice(bodyStart, bodyEnd);
|
|
256
|
+
// Preserve the blank delimiter lines at the start/end of the segment.
|
|
257
|
+
const leadBlanks = [];
|
|
258
|
+
const trailBlanks = [];
|
|
259
|
+
let si = 0;
|
|
260
|
+
while (si < rawSegment.length && rawSegment[si].trim() === "") {
|
|
261
|
+
leadBlanks.push(rawSegment[si++]);
|
|
262
|
+
}
|
|
263
|
+
let ei = rawSegment.length - 1;
|
|
264
|
+
while (ei >= si && rawSegment[ei].trim() === "") {
|
|
265
|
+
trailBlanks.unshift(rawSegment[ei--]);
|
|
266
|
+
}
|
|
267
|
+
const emittedLines = emittedBody.split("\n").map((l) => l ? `${indentStr}${l}` : l);
|
|
268
|
+
const newSegment = [...leadBlanks, ...emittedLines, ...trailBlanks];
|
|
269
|
+
// `changed` accuracy: only flag a body rewrite when the spliced
|
|
270
|
+
// segment actually differs from the original lines (a §5.2-canonical
|
|
271
|
+
// body splices back byte-identically — a pure no-op).
|
|
272
|
+
if (newSegment.length !== rawSegment.length ||
|
|
273
|
+
newSegment.some((l, i) => l !== rawSegment[i])) {
|
|
274
|
+
bodyChanged = true;
|
|
275
|
+
}
|
|
276
|
+
lines.splice(bodyStart, bodyEnd - bodyStart, ...newSegment);
|
|
277
|
+
}
|
|
278
|
+
return bodyChanged;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* UTC `YYYY-MM-DD` for today. Used as the default for the
|
|
282
|
+
* Discipline-frozen: stamper.
|
|
283
|
+
*/
|
|
284
|
+
function todayUtc() {
|
|
285
|
+
return new Date().toISOString().slice(0, 10);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* If `value` is a bare discipline kind (no `@`), return
|
|
289
|
+
* `<kind> @ <today>`. Otherwise return the value unchanged. Used by
|
|
290
|
+
* `format()` to auto-stamp `Discipline-frozen:` lines per ADR-017 Slice 3.
|
|
291
|
+
*
|
|
292
|
+
* The bare-kind regex deliberately matches the same shape the validator
|
|
293
|
+
* accepts in {@linkcode parseFrozenValue}; anything that doesn't match
|
|
294
|
+
* (e.g. uppercase kinds, already-dated forms) is left alone — the
|
|
295
|
+
* validator handles malformed values via MSL-T026.
|
|
296
|
+
*/
|
|
297
|
+
function stampDisciplineFrozen(value, today) {
|
|
298
|
+
if (/^[a-z][a-z0-9-]*\s*$/.test(value)) {
|
|
299
|
+
return `${value.trim()} @ ${today}`;
|
|
300
|
+
}
|
|
301
|
+
return value;
|
|
302
|
+
}
|
|
62
303
|
/**
|
|
63
304
|
* Format a Markdown string — normalize attribute blocks,
|
|
64
305
|
* fix indentation, enforce canonical ordering.
|
|
@@ -69,13 +310,30 @@ const CANONICAL_ORDER = [
|
|
|
69
310
|
*/
|
|
70
311
|
export function format(markdown, options) {
|
|
71
312
|
const file = options?.file ?? "<unknown>";
|
|
313
|
+
// Detect the source file's line-ending convention up front so we can
|
|
314
|
+
// restore it on write-back. The rest of the formatter operates on a
|
|
315
|
+
// pure-LF buffer; any `\r` characters from a CRLF (or legacy Mac CR)
|
|
316
|
+
// source would otherwise leak into trailers and AST nodes.
|
|
317
|
+
const sourceLineEnding = detectLineEnding(markdown);
|
|
318
|
+
const normalisedMarkdown = sourceLineEnding === "lf"
|
|
319
|
+
? markdown
|
|
320
|
+
: normalizeLineEndings(markdown);
|
|
72
321
|
// Extract any YAML front matter first so entries are parsed against the
|
|
73
322
|
// body only (front-matter `---` could be confused with horizontal rules).
|
|
74
|
-
const fm = extractFrontMatter(
|
|
75
|
-
const
|
|
323
|
+
const fm = extractFrontMatter(normalisedMarkdown, { file });
|
|
324
|
+
const rawBody = fm.hadFrontMatter ? fm.markdown : normalisedMarkdown;
|
|
325
|
+
// The §3.4.1 modal-keyword pass is NO LONGER a pre-parse whole-body
|
|
326
|
+
// string pass. It is AST-native in `emitBodyViaAst` via
|
|
327
|
+
// `normalizeBodyAst` (more spec-correct: respects §2.5 verbatim
|
|
328
|
+
// boundaries and per-node sentence-initial context). `normalizeModalKeywords`
|
|
329
|
+
// stays exported/defined for other callers/tests but is not invoked here.
|
|
330
|
+
const body = rawBody;
|
|
76
331
|
const { entries } = parseMarkdown(body, { file });
|
|
77
332
|
const diagnostics = [...fm.diagnostics];
|
|
78
333
|
if (entries.length === 0 && !fm.hadFrontMatter) {
|
|
334
|
+
// No entries and no front matter — nothing to format. Returning the
|
|
335
|
+
// original `markdown` preserves the source's exact byte sequence,
|
|
336
|
+
// including its line-ending convention.
|
|
79
337
|
return { output: markdown, diagnostics, changed: false };
|
|
80
338
|
}
|
|
81
339
|
const lines = body.split("\n");
|
|
@@ -86,12 +344,37 @@ export function format(markdown, options) {
|
|
|
86
344
|
for (const entry of sorted) {
|
|
87
345
|
const indent = (entry.location.column - 1) + 2;
|
|
88
346
|
let attrs = [...entry.rawAttributes];
|
|
347
|
+
// Title-line bullet canonicalisation per spec §3.2: rewrite `*`
|
|
348
|
+
// or `+` to `-`. The list-item position from the parser is the
|
|
349
|
+
// line carrying the bullet marker; we only touch the marker
|
|
350
|
+
// character itself, leaving the rest of the title alone.
|
|
351
|
+
const titleLineIdx = entry.location.line - 1;
|
|
352
|
+
if (titleLineIdx >= 0 && titleLineIdx < lines.length) {
|
|
353
|
+
const titleLine = lines[titleLineIdx];
|
|
354
|
+
const markerCol = entry.location.column - 1;
|
|
355
|
+
const markerChar = titleLine.charAt(markerCol);
|
|
356
|
+
if (markerChar === "*" || markerChar === "+") {
|
|
357
|
+
lines[titleLineIdx] = titleLine.slice(0, markerCol) +
|
|
358
|
+
"-" + titleLine.slice(markerCol + 1);
|
|
359
|
+
changed = true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
89
362
|
// Assign a bare ULID `Id:` to identified entries that carry no
|
|
90
363
|
// identity yet. Referenced entries are left alone — their `Id:` is a
|
|
91
364
|
// URI that must be author-provided.
|
|
365
|
+
//
|
|
366
|
+
// For `Origin: synthesized` entries (spec §3.5), derive the ULID
|
|
367
|
+
// deterministically from `Source:` so re-running `fmt` on the same
|
|
368
|
+
// input reproduces the same identity. Falls back to fresh random
|
|
369
|
+
// when `Source:` is missing — synthesizing without a source pointer
|
|
370
|
+
// makes no sense, but the formatter never fails a stamp.
|
|
92
371
|
const hasIdentity = attrs.some((a) => a.key === IDENTITY_KEY);
|
|
93
|
-
if (!hasIdentity && entry.shape === "
|
|
94
|
-
const
|
|
372
|
+
if (!hasIdentity && entry.shape === "Authored") {
|
|
373
|
+
const origin = attrs.find((a) => a.key === "Origin")?.value.trim();
|
|
374
|
+
const source = attrs.find((a) => a.key === "Source")?.value.trim();
|
|
375
|
+
const newId = origin === "synthesized" && source && source.length > 0
|
|
376
|
+
? synthesizedUlid(source)
|
|
377
|
+
: genUlid();
|
|
95
378
|
attrs = [{ key: IDENTITY_KEY, value: newId }, ...attrs];
|
|
96
379
|
diagnostics.push({
|
|
97
380
|
code: "MSL-F001",
|
|
@@ -100,6 +383,31 @@ export function format(markdown, options) {
|
|
|
100
383
|
location: entry.location,
|
|
101
384
|
});
|
|
102
385
|
}
|
|
386
|
+
// Discipline-frozen: date stamping (ADR-017 Slice 3). Walk attrs;
|
|
387
|
+
// if any Discipline-frozen: value is a bare kind, rewrite it with
|
|
388
|
+
// today's UTC date. Idempotent on already-dated values.
|
|
389
|
+
const todayFn = options?.today ?? todayUtc;
|
|
390
|
+
const todayStr = todayFn();
|
|
391
|
+
let stampedCount = 0;
|
|
392
|
+
attrs = attrs.map((a) => {
|
|
393
|
+
if (a.key !== "Discipline-frozen")
|
|
394
|
+
return a;
|
|
395
|
+
const newValue = stampDisciplineFrozen(a.value, todayStr);
|
|
396
|
+
if (newValue !== a.value) {
|
|
397
|
+
stampedCount++;
|
|
398
|
+
return { key: a.key, value: newValue };
|
|
399
|
+
}
|
|
400
|
+
return a;
|
|
401
|
+
});
|
|
402
|
+
if (stampedCount > 0) {
|
|
403
|
+
diagnostics.push({
|
|
404
|
+
code: "MSL-F001",
|
|
405
|
+
severity: "info",
|
|
406
|
+
message: `stamped Discipline-frozen: with ${todayStr} on ${entry.displayId}`,
|
|
407
|
+
location: entry.location,
|
|
408
|
+
});
|
|
409
|
+
changed = true;
|
|
410
|
+
}
|
|
103
411
|
if (attrs.length === 0)
|
|
104
412
|
continue;
|
|
105
413
|
const normalized = sortAttributes(expandCsvValues(attrs));
|
|
@@ -121,15 +429,41 @@ export function format(markdown, options) {
|
|
|
121
429
|
changed = true;
|
|
122
430
|
}
|
|
123
431
|
}
|
|
124
|
-
|
|
432
|
+
// Spec §3.4.3 / §5.2 — collapse consecutive blank lines to one.
|
|
433
|
+
// Runs after entry-block splicing so the in-progress line indices
|
|
434
|
+
// stay aligned with parser-reported positions. Operates inside
|
|
435
|
+
// fenced code regions only outside-code; verbatim regions keep
|
|
436
|
+
// their blank-line counts.
|
|
437
|
+
const collapsedLines = collapseBlankLines(lines);
|
|
438
|
+
if (collapsedLines.length !== lines.length)
|
|
439
|
+
changed = true;
|
|
440
|
+
// SP3 §5.2-via-AST cutover: route each entry's body through the
|
|
441
|
+
// canonical AST — build → normalizeBodyAst (§3.4.1 / §5.2) → render,
|
|
442
|
+
// guarded by the formal §5 `astEquivalent` relation. This is the
|
|
443
|
+
// load-bearing body-emission path AND the body modal-keyword pass
|
|
444
|
+
// (the pre-parse whole-body string pass was removed above). It
|
|
445
|
+
// returns whether any body was rewritten so `changed` stays accurate
|
|
446
|
+
// for `--check`.
|
|
447
|
+
//
|
|
448
|
+
// D6 optimization: when neither attribute-block splicing nor blank-line
|
|
449
|
+
// collapse altered any line positions, the first-parse entry line numbers
|
|
450
|
+
// are still valid in `collapsedLines` — pass the cached entries so
|
|
451
|
+
// emitBodyViaAst skips its re-parse (the hot path for already-formatted
|
|
452
|
+
// files). When `changed` is true, any splicing or collapse may have
|
|
453
|
+
// shifted positions, so pass undefined to trigger the normal re-parse.
|
|
454
|
+
if (emitBodyViaAst(collapsedLines, file, diagnostics, changed ? undefined : entries))
|
|
455
|
+
changed = true;
|
|
456
|
+
const formattedBody = collapsedLines.join("\n");
|
|
125
457
|
if (fm.hadFrontMatter) {
|
|
126
458
|
const canonicalFm = renderFrontMatter(fm.attributes);
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
459
|
+
const outputLf = canonicalFm + formattedBody;
|
|
460
|
+
if (outputLf !== normalisedMarkdown)
|
|
129
461
|
changed = true;
|
|
462
|
+
const output = applyLineEnding(outputLf, sourceLineEnding);
|
|
130
463
|
return { output, diagnostics, changed };
|
|
131
464
|
}
|
|
132
|
-
|
|
465
|
+
const output = applyLineEnding(formattedBody, sourceLineEnding);
|
|
466
|
+
return { output, diagnostics, changed };
|
|
133
467
|
}
|
|
134
468
|
/**
|
|
135
469
|
* Render {@linkcode DocumentAttributes} as a canonical YAML front matter
|
|
@@ -157,6 +491,36 @@ function renderFrontMatter(attrs) {
|
|
|
157
491
|
const yaml = stringifyYaml(ordered).trimEnd();
|
|
158
492
|
return `---\n${yaml}\n---\n\n`;
|
|
159
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Collapse consecutive blank lines to a single blank line per spec
|
|
496
|
+
* §3.4.3 (caption boundary) / §5.2 (general body rule). Fenced code
|
|
497
|
+
* regions are preserved verbatim — blank-line counts inside fenced
|
|
498
|
+
* blocks are author intent, not noise.
|
|
499
|
+
*/
|
|
500
|
+
function collapseBlankLines(lines) {
|
|
501
|
+
const out = [];
|
|
502
|
+
let inFence = false;
|
|
503
|
+
let prevBlank = false;
|
|
504
|
+
for (const line of lines) {
|
|
505
|
+
if (FENCE_RE.test(line)) {
|
|
506
|
+
out.push(line);
|
|
507
|
+
inFence = !inFence;
|
|
508
|
+
prevBlank = false;
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
if (inFence) {
|
|
512
|
+
out.push(line);
|
|
513
|
+
prevBlank = false;
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
const isBlank = line.trim() === "";
|
|
517
|
+
if (isBlank && prevBlank)
|
|
518
|
+
continue;
|
|
519
|
+
out.push(line);
|
|
520
|
+
prevBlank = isBlank;
|
|
521
|
+
}
|
|
522
|
+
return out;
|
|
523
|
+
}
|
|
160
524
|
/**
|
|
161
525
|
* Expand CSV values on repeatable-type attributes into one entry per value
|
|
162
526
|
* per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
|
|
@@ -183,43 +547,56 @@ export function expandCsvValues(attrs) {
|
|
|
183
547
|
return result;
|
|
184
548
|
}
|
|
185
549
|
/**
|
|
186
|
-
*
|
|
550
|
+
* Canonicalise a trailer key to TitleCase-Hyphenated per spec §3.3.4.
|
|
551
|
+
* First character of the key uppercase, every other character
|
|
552
|
+
* lowercase; hyphens preserved. Examples (from the spec):
|
|
553
|
+
*
|
|
554
|
+
* `Id`, `Derived-from`, `Reference-url`, `Bus-protocol`.
|
|
555
|
+
*
|
|
556
|
+
* Inputs like `ID`, `BUS-PROTOCOL`, `reference-URL`, `Derived-From`
|
|
557
|
+
* all canonicalise to the spec form regardless of casing in source.
|
|
558
|
+
*/
|
|
559
|
+
export function canonicalizeKey(key) {
|
|
560
|
+
if (key.length === 0)
|
|
561
|
+
return key;
|
|
562
|
+
return key[0].toUpperCase() + key.slice(1).toLowerCase();
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Sort attributes to canonical trailer order per spec §3.3.2 and
|
|
566
|
+
* re-case each key per spec §3.3.4.
|
|
187
567
|
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
568
|
+
* Known core keys appear in their {@linkcode CANONICAL_ORDER} slot
|
|
569
|
+
* (lookup is case-insensitive via {@linkcode canonicalizeKey}).
|
|
570
|
+
* Unknown / profile-declared keys (group 6) are appended at the end
|
|
571
|
+
* in source order — `fmt` never deletes a key it doesn't own
|
|
572
|
+
* (§3.3.6). Every emitted attribute carries the canonical key form.
|
|
191
573
|
*/
|
|
192
574
|
export function sortAttributes(attributes) {
|
|
193
575
|
const known = new Array(CANONICAL_ORDER.length);
|
|
194
576
|
const unknown = [];
|
|
195
577
|
for (const attr of attributes) {
|
|
196
|
-
const
|
|
578
|
+
const canonical = canonicalizeKey(attr.key);
|
|
579
|
+
const recased = canonical === attr.key
|
|
580
|
+
? attr
|
|
581
|
+
: { ...attr, key: canonical };
|
|
582
|
+
const idx = CANONICAL_ORDER.indexOf(canonical);
|
|
197
583
|
if (idx >= 0) {
|
|
198
584
|
// Preserve duplicates — keep all occurrences of the same key.
|
|
199
585
|
if (!known[idx])
|
|
200
586
|
known[idx] = [];
|
|
201
|
-
known[idx].push(
|
|
587
|
+
known[idx].push(recased);
|
|
202
588
|
}
|
|
203
589
|
else {
|
|
204
|
-
unknown.push(
|
|
590
|
+
unknown.push(recased);
|
|
205
591
|
}
|
|
206
592
|
}
|
|
207
593
|
const result = [];
|
|
208
|
-
const labelsIdx = CANONICAL_ORDER.indexOf("Labels");
|
|
209
|
-
const hasLabels = known[labelsIdx] != null;
|
|
210
594
|
for (let i = 0; i < known.length; i++) {
|
|
211
|
-
// Insert unknown attributes just before Labels (or at end if no Labels).
|
|
212
|
-
if (i === labelsIdx && hasLabels) {
|
|
213
|
-
result.push(...unknown);
|
|
214
|
-
}
|
|
215
595
|
if (known[i] != null) {
|
|
216
596
|
result.push(...known[i]);
|
|
217
597
|
}
|
|
218
598
|
}
|
|
219
|
-
|
|
220
|
-
if (!hasLabels) {
|
|
221
|
-
result.push(...unknown);
|
|
222
|
-
}
|
|
599
|
+
result.push(...unknown);
|
|
223
600
|
return result;
|
|
224
601
|
}
|
|
225
602
|
/**
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/formatter/synth_ulid
|
|
3
|
+
*
|
|
4
|
+
* Deterministic synthesized-ULID derivation per spec §3.5:
|
|
5
|
+
*
|
|
6
|
+
* ULID(timestamp=0, randomness=truncate(SHA-256(canonical(Source)), 80))
|
|
7
|
+
*
|
|
8
|
+
* Used by the formatter when an Authored entry carries `Origin:
|
|
9
|
+
* synthesized` — the ULID becomes a content-addressed fingerprint of the
|
|
10
|
+
* source pointer, so re-running `fmt` against an already-synthesized
|
|
11
|
+
* entry reproduces the same `Id:`. Authored (default) origin keeps using
|
|
12
|
+
* a fresh random ULID.
|
|
13
|
+
*
|
|
14
|
+
* Uses `node:crypto` rather than Web Crypto so the function stays
|
|
15
|
+
* synchronous; the formatter's public API is sync and threading async
|
|
16
|
+
* through every call site would be a much larger change for no benefit
|
|
17
|
+
* (the hash is bounded by a single short string).
|
|
18
|
+
*/
|
|
19
|
+
/** Derive a deterministic ULID from a `Source:` value. */
|
|
20
|
+
export declare function synthesizedUlid(source: string): string;
|
|
21
|
+
//# sourceMappingURL=synth_ulid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synth_ulid.d.ts","sourceRoot":"","sources":["../../src/formatter/synth_ulid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAgDH,0DAA0D;AAC1D,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKtD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/formatter/synth_ulid
|
|
3
|
+
*
|
|
4
|
+
* Deterministic synthesized-ULID derivation per spec §3.5:
|
|
5
|
+
*
|
|
6
|
+
* ULID(timestamp=0, randomness=truncate(SHA-256(canonical(Source)), 80))
|
|
7
|
+
*
|
|
8
|
+
* Used by the formatter when an Authored entry carries `Origin:
|
|
9
|
+
* synthesized` — the ULID becomes a content-addressed fingerprint of the
|
|
10
|
+
* source pointer, so re-running `fmt` against an already-synthesized
|
|
11
|
+
* entry reproduces the same `Id:`. Authored (default) origin keeps using
|
|
12
|
+
* a fresh random ULID.
|
|
13
|
+
*
|
|
14
|
+
* Uses `node:crypto` rather than Web Crypto so the function stays
|
|
15
|
+
* synchronous; the formatter's public API is sync and threading async
|
|
16
|
+
* through every call site would be a much larger change for no benefit
|
|
17
|
+
* (the hash is bounded by a single short string).
|
|
18
|
+
*/
|
|
19
|
+
import { createHash } from "node:crypto";
|
|
20
|
+
/** Crockford base32 alphabet (no I, L, O, U). */
|
|
21
|
+
const CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
22
|
+
/** Timestamp half of a `ULID(timestamp=0)` — 10 zero chars. */
|
|
23
|
+
const ZERO_TIMESTAMP = "0000000000";
|
|
24
|
+
/**
|
|
25
|
+
* Canonicalize a `Source:` value before hashing.
|
|
26
|
+
*
|
|
27
|
+
* Currently: trim leading/trailing whitespace. The canonical form is
|
|
28
|
+
* intentionally minimal — `Source:` is already author-typed and not
|
|
29
|
+
* subject to encoding ambiguity beyond stray surrounding whitespace
|
|
30
|
+
* that the parser may not have stripped (e.g. trailing `\n` from
|
|
31
|
+
* line-joined trailers).
|
|
32
|
+
*/
|
|
33
|
+
function canonical(source) {
|
|
34
|
+
return source.trim();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Encode an 80-bit (10-byte) buffer as a 16-char Crockford base32
|
|
38
|
+
* string. Bit order matches the ULID spec (most-significant bit first
|
|
39
|
+
* in the output). Each Crockford symbol carries 5 bits; 80 / 5 = 16.
|
|
40
|
+
*/
|
|
41
|
+
function encodeBase32_80(bytes) {
|
|
42
|
+
if (bytes.length !== 10) {
|
|
43
|
+
throw new Error(`expected 10 bytes for 80-bit encoding, got ${bytes.length}`);
|
|
44
|
+
}
|
|
45
|
+
// Accumulate bits into a buffer and pull 5 at a time, MSB-first.
|
|
46
|
+
let bits = 0n;
|
|
47
|
+
for (const b of bytes) {
|
|
48
|
+
bits = (bits << 8n) | BigInt(b);
|
|
49
|
+
}
|
|
50
|
+
let out = "";
|
|
51
|
+
for (let i = 15; i >= 0; i--) {
|
|
52
|
+
const shift = BigInt(i * 5);
|
|
53
|
+
const idx = Number((bits >> shift) & 0x1fn);
|
|
54
|
+
out += CROCKFORD[idx];
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/** Derive a deterministic ULID from a `Source:` value. */
|
|
59
|
+
export function synthesizedUlid(source) {
|
|
60
|
+
const canonicalSource = canonical(source);
|
|
61
|
+
const hash = createHash("sha256").update(canonicalSource, "utf8").digest();
|
|
62
|
+
const truncated = new Uint8Array(hash.buffer, hash.byteOffset, 10);
|
|
63
|
+
return ZERO_TIMESTAMP + encodeBase32_80(truncated);
|
|
64
|
+
}
|