@prisma/orm-framework 8.0.0-rc.2-dev.3 → 8.0.0-rc.20-dev.1
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 +1 -5
- package/dist/{apply-specifier-default-control-policy-CAxiXxKg.d.mts → apply-specifier-default-control-policy-Dlz0iwnK.d.mts} +2 -2
- package/dist/apply-specifier-default-control-policy-Dlz0iwnK.d.mts.map +1 -0
- package/dist/{assertions-Cz-GWH8P.mjs → assertions-Dw1lZz_Q.mjs} +2 -2
- package/dist/{assertions-Cz-GWH8P.mjs.map → assertions-Dw1lZz_Q.mjs.map} +1 -1
- package/dist/authoring-CNUti739.mjs +764 -0
- package/dist/authoring-CNUti739.mjs.map +1 -0
- package/dist/authoring-CjwinhU5.d.mts +206 -0
- package/dist/authoring-CjwinhU5.d.mts.map +1 -0
- package/dist/binder-D_4RBHbt-BJ6VKwEZ.d.mts +515 -0
- package/dist/binder-D_4RBHbt-BJ6VKwEZ.d.mts.map +1 -0
- package/dist/{canonicalization-DFpB09nP-4OdB2nsy.d.mts → canonicalization-CyrrXGmj-CeKUkht1.d.mts} +3 -3
- package/dist/{canonicalization-DFpB09nP-4OdB2nsy.d.mts.map → canonicalization-CyrrXGmj-CeKUkht1.d.mts.map} +1 -1
- package/dist/{hashing-utils-DQgS3nOe.mjs → canonicalization-path-match-D88xLEq6-BFQC39ZG.mjs} +23 -3
- package/dist/canonicalization-path-match-D88xLEq6-BFQC39ZG.mjs.map +1 -0
- package/dist/{utils-DMAM0unR.mjs → canonicalize-json-ZPawceQR-Dua1VNEB.mjs} +2 -2
- package/dist/canonicalize-json-ZPawceQR-Dua1VNEB.mjs.map +1 -0
- package/dist/codec-B4ypaota.d.mts +289 -0
- package/dist/codec-B4ypaota.d.mts.map +1 -0
- package/dist/codec-Do8tfXqk.mjs +457 -0
- package/dist/codec-Do8tfXqk.mjs.map +1 -0
- package/dist/codec-descriptor-D0oY-hgs-C5e11ola.mjs +93 -0
- package/dist/codec-descriptor-D0oY-hgs-C5e11ola.mjs.map +1 -0
- package/dist/codec-types-BXLUbk-Y-DpGfKGK0.mjs +22 -0
- package/dist/codec-types-BXLUbk-Y-DpGfKGK0.mjs.map +1 -0
- package/dist/codec-types-CPgEZoIq-BL9hisr8.d.mts +384 -0
- package/dist/codec-types-CPgEZoIq-BL9hisr8.d.mts.map +1 -0
- package/dist/{components-dZRz3T5y.mjs → components-BaV9iCkq.mjs} +34 -3
- package/dist/components-BaV9iCkq.mjs.map +1 -0
- package/dist/components-CRBcIta_.d.mts +86 -0
- package/dist/components-CRBcIta_.d.mts.map +1 -0
- package/dist/components.d.mts +19 -17
- package/dist/components.mjs +16 -12
- package/dist/components__authoring.d.mts +4 -3
- package/dist/components__authoring.mjs +3 -2
- package/dist/components__codec.d.mts +3 -3
- package/dist/components__codec.mjs +6 -4
- package/dist/components__components.d.mts +6 -4
- package/dist/components__components.mjs +4 -3
- package/dist/components__control.d.mts +5 -4
- package/dist/components__control.mjs +3 -2
- package/dist/components__emission.d.mts +4 -4
- package/dist/components__execution.d.mts +1 -1
- package/dist/components__ir.d.mts +1 -1
- package/dist/components__ir.mjs +2 -1
- package/dist/components__psl-ast.d.mts +4 -4
- package/dist/components__psl-ast.mjs +2 -2
- package/dist/components__runtime.d.mts +3 -2
- package/dist/components__runtime.mjs +2 -2
- package/dist/components__utils.mjs +1 -1
- package/dist/{config-types-CW4PDwMC.d.mts → config-types-BTFT7QfJ.d.mts} +73 -41
- package/dist/config-types-BTFT7QfJ.d.mts.map +1 -0
- package/dist/config-types-D0mYyP62.mjs +61 -0
- package/dist/config-types-D0mYyP62.mjs.map +1 -0
- package/dist/config.d.mts +2 -3
- package/dist/config.mjs +2 -3
- package/dist/config__config-types.d.mts +2 -2
- package/dist/config__config-types.mjs +2 -2
- package/dist/contract-authoring.d.mts +152 -17
- package/dist/contract-authoring.d.mts.map +1 -1
- package/dist/contract-authoring.mjs +190 -9
- package/dist/contract-authoring.mjs.map +1 -1
- package/dist/{contract-types-CkdMH7F7-9EHXSwbH.d.mts → contract-types-DEIEpzU_-DvAVuBr5.d.mts} +14 -8
- package/dist/contract-types-DEIEpzU_-DvAVuBr5.d.mts.map +1 -0
- package/dist/{contract-validation-error-DEiWp_EI-CRwtUgRw.mjs → contract-validation-error-CAnTGhkt-DSnujRaK.mjs} +6 -3
- package/dist/contract-validation-error-CAnTGhkt-DSnujRaK.mjs.map +1 -0
- package/dist/{contract-validation-error-R7cMoK04.d.mts → contract-validation-error-D1QAeOh5.d.mts} +4 -2
- package/dist/contract-validation-error-D1QAeOh5.d.mts.map +1 -0
- package/dist/contract.d.mts +13 -12
- package/dist/contract.mjs +9 -9
- package/dist/contract__apply-specifier-default-control-policy.d.mts +1 -1
- package/dist/contract__contract-validation-error.d.mts +1 -1
- package/dist/contract__contract-validation-error.mjs +1 -1
- package/dist/contract__default-namespace.mjs +1 -1
- package/dist/contract__enum-accessor.d.mts +2 -2
- package/dist/contract__enum-accessor.mjs +1 -1
- package/dist/contract__hashing-utils.d.mts +2 -2
- package/dist/contract__hashing-utils.mjs +2 -3
- package/dist/contract__hashing.d.mts +3 -3
- package/dist/contract__hashing.mjs +2 -2
- package/dist/contract__resolve-domain-model.d.mts +1 -1
- package/dist/contract__types.d.mts +5 -5
- package/dist/contract__types.mjs +3 -3
- package/dist/contract__validate-domain.d.mts +1 -1
- package/dist/contract__validate-domain.mjs +1 -1
- package/dist/contract__validate-once.d.mts +2 -0
- package/dist/contract__validate-once.mjs +2 -0
- package/dist/{control-ql9N9u4f-r3Vv41kZ.d.mts → control-B5ezUWD2-BIAYxeSk.d.mts} +34 -6
- package/dist/control-B5ezUWD2-BIAYxeSk.d.mts.map +1 -0
- package/dist/{control-DLEm6u5m.mjs → control-DMJqhnwU.mjs} +309 -36
- package/dist/control-DMJqhnwU.mjs.map +1 -0
- package/dist/control-DrDTlxCS.d.mts +1 -0
- package/dist/{control-BD96JZi8-NUhO5Kkw.mjs → control-KsXr4fYD-D2Ows0NI.mjs} +70 -24
- package/dist/control-KsXr4fYD-D2Ows0NI.mjs.map +1 -0
- package/dist/{control-BF8qzdnM.d.mts → control-s5ECUABR.d.mts} +635 -156
- package/dist/control-s5ECUABR.d.mts.map +1 -0
- package/dist/data-type-V6mcDhcG-DVQAPOQT.mjs +275 -0
- package/dist/data-type-V6mcDhcG-DVQAPOQT.mjs.map +1 -0
- package/dist/declarations-BgUAq1RG-Dz_-EI1Q.mjs +459 -0
- package/dist/declarations-BgUAq1RG-Dz_-EI1Q.mjs.map +1 -0
- package/dist/{default-namespace-D4vCwkXg-lzVN7gSc.mjs → default-namespace-D4vCwkXg-BEZbN38y.mjs} +2 -2
- package/dist/{default-namespace-D4vCwkXg-lzVN7gSc.mjs.map → default-namespace-D4vCwkXg-BEZbN38y.mjs.map} +1 -1
- package/dist/{dist-Dqbo77p7.mjs → dist-D1f6xr7F.mjs} +51 -24
- package/dist/dist-D1f6xr7F.mjs.map +1 -0
- package/dist/{domain-envelope-D6Wn9AmZ-BqZKTT9U.d.mts → domain-envelope-CN721GnP-4huRt7Wc.d.mts} +27 -13
- package/dist/domain-envelope-CN721GnP-4huRt7Wc.d.mts.map +1 -0
- package/dist/emission-BtJvV97M.d.mts +2 -0
- package/dist/{emission-types-DLXP34Ki-CFms3VrX.d.mts → emission-types-B-jKEbjI-D7BW8Gk1.d.mts} +17 -16
- package/dist/emission-types-B-jKEbjI-D7BW8Gk1.d.mts.map +1 -0
- package/dist/enum-accessor-2OZgavDX.d.mts +104 -0
- package/dist/enum-accessor-2OZgavDX.d.mts.map +1 -0
- package/dist/enum-accessor-B-A2wNok.mjs +122 -0
- package/dist/enum-accessor-B-A2wNok.mjs.map +1 -0
- package/dist/errors.d.mts +5 -4
- package/dist/errors.mjs +4 -4
- package/dist/errors__control.d.mts +3 -2
- package/dist/errors__control.mjs +2 -2
- package/dist/errors__execution.d.mts +2 -2
- package/dist/errors__execution.mjs +2 -2
- package/dist/errors__migration.d.mts +2 -2
- package/dist/errors__migration.mjs +2 -2
- package/dist/execution-CjX5CCTb.d.mts +76 -0
- package/dist/execution-CjX5CCTb.d.mts.map +1 -0
- package/dist/{execution-CSnQT8EX.d.mts → execution-lMPVFj5o.d.mts} +2 -2
- package/dist/{execution-CSnQT8EX.d.mts.map → execution-lMPVFj5o.d.mts.map} +1 -1
- package/dist/execution-vfY4d-SZ.mjs +138 -0
- package/dist/execution-vfY4d-SZ.mjs.map +1 -0
- package/dist/{declarations-DR6To8_k-BFwkCGeP.mjs → expressions-CMQzbnHk-BL2zN0Iv.mjs} +199 -350
- package/dist/expressions-CMQzbnHk-BL2zN0Iv.mjs.map +1 -0
- package/dist/framework-authoring-DDxddXZm-uZYdhoE0.d.mts +1096 -0
- package/dist/framework-authoring-DDxddXZm-uZYdhoE0.d.mts.map +1 -0
- package/dist/{framework-components-hZ2tO-KH-CdRXBOYd.d.mts → framework-components-DKoQnPdB-lax1COaf.d.mts} +28 -91
- package/dist/framework-components-DKoQnPdB-lax1COaf.d.mts.map +1 -0
- package/dist/generator-functions-CXbQfvYu-BIFU1Ryx.mjs +271 -0
- package/dist/generator-functions-CXbQfvYu-BIFU1Ryx.mjs.map +1 -0
- package/dist/{hash-content-DwEUh-Rx.d.mts → hash-content-Bde14N2-.d.mts} +2 -2
- package/dist/{hash-content-DwEUh-Rx.d.mts.map → hash-content-Bde14N2-.d.mts.map} +1 -1
- package/dist/{hash-content-Bugg_nZn.mjs → hash-content-Bdl-HSfq.mjs} +2 -2
- package/dist/hash-content-Bdl-HSfq.mjs.map +1 -0
- package/dist/{hashing-BtIZVNYX.mjs → hashing-CLRfNAxh.mjs} +28 -9
- package/dist/hashing-CLRfNAxh.mjs.map +1 -0
- package/dist/hashing-D-DHz0zl.d.mts +36 -0
- package/dist/hashing-D-DHz0zl.d.mts.map +1 -0
- package/dist/{hashing-utils-qKu59RSC.d.mts → hashing-utils-DiGHKd3b.d.mts} +4 -3
- package/dist/{hashing-utils-qKu59RSC.d.mts.map → hashing-utils-DiGHKd3b.d.mts.map} +1 -1
- package/dist/ids.d.mts +90 -13
- package/dist/ids.d.mts.map +1 -1
- package/dist/ids.mjs +45 -59
- package/dist/ids.mjs.map +1 -1
- package/dist/ids__runtime.d.mts +1 -1
- package/dist/ids__runtime.mjs +1 -1
- package/dist/{index-CDk9yEbw.d.mts → index-MU-ksXsh.d.mts} +23 -6
- package/dist/index-MU-ksXsh.d.mts.map +1 -0
- package/dist/{internal-error-kK8QvlDE.d.mts → internal-error-2fJ9fcZX.d.mts} +2 -2
- package/dist/{internal-error-kK8QvlDE.d.mts.map → internal-error-2fJ9fcZX.d.mts.map} +1 -1
- package/dist/{internal-error-BIc-ehme-ouBQPoEL.mjs → internal-error-ChGYPVpq-DhUD05u0.mjs} +3 -3
- package/dist/internal-error-ChGYPVpq-DhUD05u0.mjs.map +1 -0
- package/dist/{ir-BvE7L9FK.d.mts → ir-LV4tXsw3.d.mts} +6 -5
- package/dist/{ir-BvE7L9FK.d.mts.map → ir-LV4tXsw3.d.mts.map} +1 -1
- package/dist/{ir-ChmSSAhX.mjs → ir-uDGU9vaj.mjs} +7 -53
- package/dist/ir-uDGU9vaj.mjs.map +1 -0
- package/dist/{migration-BvrgDZXw.d.mts → migration-Dluwnqe9.d.mts} +20 -3
- package/dist/migration-Dluwnqe9.d.mts.map +1 -0
- package/dist/{migration-C57VKLUY.mjs → migration-uC-bSKA4.mjs} +30 -4
- package/dist/migration-uC-bSKA4.mjs.map +1 -0
- package/dist/namespace-VUH2dgnS-By5y75h9.mjs +53 -0
- package/dist/namespace-VUH2dgnS-By5y75h9.mjs.map +1 -0
- package/dist/operations.mjs +1 -1
- package/dist/{parse-GbZGfMUj-BFSrD2AN.mjs → parse-bZgfjovA-BNgYhylT.mjs} +311 -55
- package/dist/parse-bZgfjovA-BNgYhylT.mjs.map +1 -0
- package/dist/{parse-0ZJjj_2N-DhQpSVmQ.d.mts → parse-djL5wker-B610mXG4.d.mts} +181 -52
- package/dist/parse-djL5wker-B610mXG4.d.mts.map +1 -0
- package/dist/psl-ast-COcYtLlz.d.mts +2 -0
- package/dist/psl-ast-CyvE6CR-.mjs +116 -0
- package/dist/psl-ast-CyvE6CR-.mjs.map +1 -0
- package/dist/{psl-ast-CWJQF8LA-Vr5JNPdn.d.mts → psl-ast-rY25o3Ze-ClLY3CYt.d.mts} +10 -40
- package/dist/psl-ast-rY25o3Ze-ClLY3CYt.d.mts.map +1 -0
- package/dist/psl-parser.d.mts +415 -101
- package/dist/psl-parser.d.mts.map +1 -1
- package/dist/psl-parser.mjs +2451 -537
- package/dist/psl-parser.mjs.map +1 -1
- package/dist/psl-parser__format.d.mts +8 -2
- package/dist/psl-parser__format.d.mts.map +1 -1
- package/dist/psl-parser__format.mjs +65 -34
- package/dist/psl-parser__format.mjs.map +1 -1
- package/dist/psl-parser__interpret.d.mts +98 -10
- package/dist/psl-parser__interpret.d.mts.map +1 -1
- package/dist/psl-parser__interpret.mjs +393 -2
- package/dist/psl-parser__interpret.mjs.map +1 -1
- package/dist/psl-parser__syntax.d.mts +3 -3
- package/dist/psl-parser__syntax.mjs +4 -43
- package/dist/psl-parser__tokenizer.d.mts +1 -1
- package/dist/psl-parser__tokenizer.mjs +1 -1
- package/dist/psl-printer.d.mts +7 -17
- package/dist/psl-printer.d.mts.map +1 -1
- package/dist/psl-printer.mjs +35 -104
- package/dist/psl-printer.mjs.map +1 -1
- package/dist/resolve-codec-qqMjZrmn-Cok8elAo.mjs +74 -0
- package/dist/resolve-codec-qqMjZrmn-Cok8elAo.mjs.map +1 -0
- package/dist/{resolve-domain-model-BVSb5wS5-C6Yq0dsD.d.mts → resolve-domain-model-BNr1glea-BLuR-phK.d.mts} +3 -3
- package/dist/resolve-domain-model-BNr1glea-BLuR-phK.d.mts.map +1 -0
- package/dist/{result-CBZ8X9mU.mjs → result-8OXF26MN.mjs} +14 -3
- package/dist/{result-CBZ8X9mU.mjs.map → result-8OXF26MN.mjs.map} +1 -1
- package/dist/{result-Bpupv5vO.d.mts → result-BYCOANWy.d.mts} +4 -2
- package/dist/result-BYCOANWy.d.mts.map +1 -0
- package/dist/runtime-B-YYuWy2.d.mts +899 -0
- package/dist/runtime-B-YYuWy2.d.mts.map +1 -0
- package/dist/runtime-DSYSc98Y.mjs +1059 -0
- package/dist/runtime-DSYSc98Y.mjs.map +1 -0
- package/dist/runtime-error-CO4MA3Px-YW5SCUcH.d.mts +19 -0
- package/dist/runtime-error-CO4MA3Px-YW5SCUcH.d.mts.map +1 -0
- package/dist/{structured-error-CgiSMpdU.mjs → structured-error-BXbihKQ-.mjs} +3 -3
- package/dist/{structured-error-CgiSMpdU.mjs.map → structured-error-BXbihKQ-.mjs.map} +1 -1
- package/dist/{structured-error-BsNT4Hun.d.mts → structured-error-Cc7AIRsp.d.mts} +19 -5
- package/dist/structured-error-Cc7AIRsp.d.mts.map +1 -0
- package/dist/suppress-idle-connection-errors-CKrTbp5P.d.mts +18 -0
- package/dist/suppress-idle-connection-errors-CKrTbp5P.d.mts.map +1 -0
- package/dist/suppress-idle-connection-errors-DzApeUb3.mjs +22 -0
- package/dist/suppress-idle-connection-errors-DzApeUb3.mjs.map +1 -0
- package/dist/temporal-presets-5TK1pTYJ-DmhrnMP1.mjs +1276 -0
- package/dist/temporal-presets-5TK1pTYJ-DmhrnMP1.mjs.map +1 -0
- package/dist/temporal-presets-BuMqk7h8-DZSuu4Z_.d.mts +258 -0
- package/dist/temporal-presets-BuMqk7h8-DZSuu4Z_.d.mts.map +1 -0
- package/dist/text-C3TTEtgd.mjs +35 -0
- package/dist/text-C3TTEtgd.mjs.map +1 -0
- package/dist/text-C8_-rheN.d.mts +15 -0
- package/dist/text-C8_-rheN.d.mts.map +1 -0
- package/dist/{tokenizer-1hAHZzmp-QGPORvmA.mjs → tokenizer-C-GTKKjR-B1vOzJy0.mjs} +54 -10
- package/dist/tokenizer-C-GTKKjR-B1vOzJy0.mjs.map +1 -0
- package/dist/{tokenizer-DcYI0Xrq-C-nNE9mE.d.mts → tokenizer-i8RaVWVa-7fRwlCPP.d.mts} +9 -4
- package/dist/tokenizer-i8RaVWVa-7fRwlCPP.d.mts.map +1 -0
- package/dist/ts-render.d.mts +2 -2
- package/dist/ts-render.mjs +2 -2
- package/dist/type-constructor-calls-BLf-HsFy-D_jbIqj8.mjs +261 -0
- package/dist/type-constructor-calls-BLf-HsFy-D_jbIqj8.mjs.map +1 -0
- package/dist/{types-BnH4zYvN.mjs → types-B8ULzMAX.mjs} +36 -3
- package/dist/types-B8ULzMAX.mjs.map +1 -0
- package/dist/types-GNXJ7xW2.d.mts +131 -0
- package/dist/types-GNXJ7xW2.d.mts.map +1 -0
- package/dist/{types-import-spec-3mjbVBhI-DQI6BvKU.d.mts → types-import-spec-DQjfX-gM-zVncuzs0.d.mts} +6 -6
- package/dist/types-import-spec-DQjfX-gM-zVncuzs0.d.mts.map +1 -0
- package/dist/utils.d.mts +7 -5
- package/dist/utils.mjs +9 -7
- package/dist/utils__assertions.mjs +1 -1
- package/dist/utils__hash-content.d.mts +1 -1
- package/dist/utils__hash-content.mjs +1 -1
- package/dist/utils__internal-error.d.mts +1 -1
- package/dist/utils__internal-error.mjs +1 -1
- package/dist/utils__result.d.mts +2 -2
- package/dist/utils__result.mjs +2 -2
- package/dist/utils__structured-error.d.mts +2 -2
- package/dist/utils__structured-error.mjs +1 -1
- package/dist/utils__suppress-idle-connection-errors.d.mts +2 -0
- package/dist/utils__suppress-idle-connection-errors.mjs +2 -0
- package/dist/utils__text.d.mts +2 -0
- package/dist/utils__text.mjs +2 -0
- package/dist/{validate-domain-BNBs-TVv.d.mts → validate-domain-B5kmlBFB.d.mts} +10 -6
- package/dist/validate-domain-B5kmlBFB.d.mts.map +1 -0
- package/dist/{validate-domain-BkvFlY3B.mjs → validate-domain-CbXHDYpF.mjs} +43 -22
- package/dist/validate-domain-CbXHDYpF.mjs.map +1 -0
- package/dist/validate-once-D-IwXHYP.mjs +42 -0
- package/dist/validate-once-D-IwXHYP.mjs.map +1 -0
- package/dist/validate-once-gfCOHsDh.d.mts +16 -0
- package/dist/validate-once-gfCOHsDh.d.mts.map +1 -0
- package/package.json +24 -20
- package/dist/apply-specifier-default-control-policy-CAxiXxKg.d.mts.map +0 -1
- package/dist/authoring-B2H-9qCv.d.mts +0 -1
- package/dist/canonicalization-path-match-CNgHuwM_-CCPBeUuk.mjs +0 -25
- package/dist/canonicalization-path-match-CNgHuwM_-CCPBeUuk.mjs.map +0 -1
- package/dist/capabilities-BCEONw9w-C-lo3rF8.mjs +0 -120
- package/dist/capabilities-BCEONw9w-C-lo3rF8.mjs.map +0 -1
- package/dist/codec-Cd0QcxAx.mjs +0 -63
- package/dist/codec-Cd0QcxAx.mjs.map +0 -1
- package/dist/codec-Ce07W3Mz.d.mts +0 -112
- package/dist/codec-Ce07W3Mz.d.mts.map +0 -1
- package/dist/codec-types-D6VRj2RE-BLElXc-O.d.mts +0 -223
- package/dist/codec-types-D6VRj2RE-BLElXc-O.d.mts.map +0 -1
- package/dist/codec-types-DcNvNeY1-BO6kUiH0.mjs +0 -30
- package/dist/codec-types-DcNvNeY1-BO6kUiH0.mjs.map +0 -1
- package/dist/components-CGA_WwEG.d.mts +0 -50
- package/dist/components-CGA_WwEG.d.mts.map +0 -1
- package/dist/components-dZRz3T5y.mjs.map +0 -1
- package/dist/config-types-BqhNxw0z.mjs +0 -67
- package/dist/config-types-BqhNxw0z.mjs.map +0 -1
- package/dist/config-types-CW4PDwMC.d.mts.map +0 -1
- package/dist/config-validation-DPt5hwQx.mjs +0 -168
- package/dist/config-validation-DPt5hwQx.mjs.map +0 -1
- package/dist/config-validation-Wiqew2J9.d.mts +0 -21
- package/dist/config-validation-Wiqew2J9.d.mts.map +0 -1
- package/dist/config__config-validation.d.mts +0 -2
- package/dist/config__config-validation.mjs +0 -2
- package/dist/contract-types-CkdMH7F7-9EHXSwbH.d.mts.map +0 -1
- package/dist/contract-validation-error-DEiWp_EI-CRwtUgRw.mjs.map +0 -1
- package/dist/contract-validation-error-R7cMoK04.d.mts.map +0 -1
- package/dist/control-BD96JZi8-NUhO5Kkw.mjs.map +0 -1
- package/dist/control-BF8qzdnM.d.mts.map +0 -1
- package/dist/control-DLEm6u5m.mjs.map +0 -1
- package/dist/control-ql9N9u4f-r3Vv41kZ.d.mts.map +0 -1
- package/dist/declarations-DR6To8_k-BFwkCGeP.mjs.map +0 -1
- package/dist/dist-Dqbo77p7.mjs.map +0 -1
- package/dist/domain-envelope-D6Wn9AmZ-BqZKTT9U.d.mts.map +0 -1
- package/dist/emission-CmUO03gQ.d.mts +0 -2
- package/dist/emission-types-DLXP34Ki-CFms3VrX.d.mts.map +0 -1
- package/dist/enum-accessor-Db5DaTNX.mjs +0 -35
- package/dist/enum-accessor-Db5DaTNX.mjs.map +0 -1
- package/dist/enum-accessor-PH5vjghI.d.mts +0 -85
- package/dist/enum-accessor-PH5vjghI.d.mts.map +0 -1
- package/dist/execution-Crk6IfTs.mjs +0 -218
- package/dist/execution-Crk6IfTs.mjs.map +0 -1
- package/dist/execution-Cyl2dXxX.d.mts +0 -115
- package/dist/execution-Cyl2dXxX.d.mts.map +0 -1
- package/dist/framework-authoring-BhctBwih-DQ_6noDM.d.mts +0 -777
- package/dist/framework-authoring-BhctBwih-DQ_6noDM.d.mts.map +0 -1
- package/dist/framework-authoring-CDEvlouU-DKklu-fL.mjs +0 -698
- package/dist/framework-authoring-CDEvlouU-DKklu-fL.mjs.map +0 -1
- package/dist/framework-components-hZ2tO-KH-CdRXBOYd.d.mts.map +0 -1
- package/dist/hash-content-Bugg_nZn.mjs.map +0 -1
- package/dist/hashing-BtIZVNYX.mjs.map +0 -1
- package/dist/hashing-CccSPELN.d.mts +0 -25
- package/dist/hashing-CccSPELN.d.mts.map +0 -1
- package/dist/hashing-utils-DQgS3nOe.mjs.map +0 -1
- package/dist/index-CDk9yEbw.d.mts.map +0 -1
- package/dist/internal-error-BIc-ehme-ouBQPoEL.mjs.map +0 -1
- package/dist/ir-ChmSSAhX.mjs.map +0 -1
- package/dist/migration-BvrgDZXw.d.mts.map +0 -1
- package/dist/migration-C57VKLUY.mjs.map +0 -1
- package/dist/parse-0ZJjj_2N-DhQpSVmQ.d.mts.map +0 -1
- package/dist/parse-GbZGfMUj-BFSrD2AN.mjs.map +0 -1
- package/dist/psl-ast-BXZoFQBk.d.mts +0 -37
- package/dist/psl-ast-BXZoFQBk.d.mts.map +0 -1
- package/dist/psl-ast-CWJQF8LA-Vr5JNPdn.d.mts.map +0 -1
- package/dist/psl-ast-DUCvVXbB.mjs +0 -239
- package/dist/psl-ast-DUCvVXbB.mjs.map +0 -1
- package/dist/psl-parser__syntax.mjs.map +0 -1
- package/dist/resolve-codec-BZF8TZh_-D-xORT9Q.mjs +0 -59
- package/dist/resolve-codec-BZF8TZh_-D-xORT9Q.mjs.map +0 -1
- package/dist/resolve-domain-model-BVSb5wS5-C6Yq0dsD.d.mts.map +0 -1
- package/dist/result-Bpupv5vO.d.mts.map +0 -1
- package/dist/runtime-BqzioOmU.mjs +0 -670
- package/dist/runtime-BqzioOmU.mjs.map +0 -1
- package/dist/runtime-Cuxw8obj.d.mts +0 -1038
- package/dist/runtime-Cuxw8obj.d.mts.map +0 -1
- package/dist/structured-error-BsNT4Hun.d.mts.map +0 -1
- package/dist/symbol-table-CZ7EVCTL-CR-ncCpD.d.mts +0 -125
- package/dist/symbol-table-CZ7EVCTL-CR-ncCpD.d.mts.map +0 -1
- package/dist/tokenizer-1hAHZzmp-QGPORvmA.mjs.map +0 -1
- package/dist/tokenizer-DcYI0Xrq-C-nNE9mE.d.mts.map +0 -1
- package/dist/types-BnH4zYvN.mjs.map +0 -1
- package/dist/types-ByeQhU9p.d.mts +0 -17
- package/dist/types-ByeQhU9p.d.mts.map +0 -1
- package/dist/types-import-spec-3mjbVBhI-DQI6BvKU.d.mts.map +0 -1
- package/dist/utils-DMAM0unR.mjs.map +0 -1
- package/dist/validate-domain-BNBs-TVv.d.mts.map +0 -1
- package/dist/validate-domain-BkvFlY3B.mjs.map +0 -1
package/dist/psl-parser.mjs
CHANGED
|
@@ -1,88 +1,1507 @@
|
|
|
1
1
|
import { t as blindCast } from "./casts-DpaahrlC-Bd5n2coI.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { t as InternalError } from "./internal-error-ChGYPVpq-DhUD05u0.mjs";
|
|
3
|
+
import { a as or, i as okVoid, n as notOk, r as ok, t as and } from "./result-8OXF26MN.mjs";
|
|
4
|
+
import { c as createDataTypeLookup } from "./data-type-V6mcDhcG-DVQAPOQT.mjs";
|
|
5
|
+
import { D as isAuthoringModelAttributeDescriptor, O as isAuthoringPslBlockDescriptor, g as describeTaggedLiteralFailure, x as instantiateAuthoringTypeAlias } from "./temporal-presets-5TK1pTYJ-DmhrnMP1.mjs";
|
|
6
|
+
import { r as UNBOUND_NAMESPACE_ID } from "./namespace-VUH2dgnS-By5y75h9.mjs";
|
|
7
|
+
import { E as tagForm, n as admittedTags, s as describeAdmittedForms, y as findAuthoringTypeConstructorCall } from "./authoring-CNUti739.mjs";
|
|
8
|
+
import { a as flatPslModels, c as namespacePslExtensionBlocks, n as UNBOUND_PSL_NAMESPACE_NAME } from "./psl-ast-CyvE6CR-.mjs";
|
|
9
|
+
import { n as isPslIdentifier } from "./tokenizer-C-GTKKjR-B1vOzJy0.mjs";
|
|
10
|
+
import { C as printSyntax, a as IdentifierAst, c as ObjectLiteralExprAst, d as StringLiteralExprAst, i as FunctionCallAst, l as PathExprAst, m as TaggedLiteralExprAst, o as NumberLiteralExprAst, r as BooleanLiteralExprAst, t as ArrayLiteralAst } from "./expressions-CMQzbnHk-BL2zN0Iv.mjs";
|
|
11
|
+
import { a as diagnosticFromSpan, c as mapPslDiagnostics, d as readResolvedAttributes, f as readResolvedConstructorCall, i as createPslDiagnosticCollector, l as nodePslSpan, n as readExpressionAs, o as diagnosticSource, p as readWrittenScalar, s as keywordPslSpan, t as isBareTypeConstructor, u as readResolvedAttribute } from "./type-constructor-calls-BLf-HsFy-D_jbIqj8.mjs";
|
|
12
|
+
import { a as FieldDeclarationAst, c as MixinDeclarationAst, d as ModelDeclarationAst, g as isTrivia, h as TypesBlockAst, n as CompositeTypeDeclarationAst, o as GenericBlockDeclarationAst, p as NamespaceDeclarationAst, s as KeyValuePairAst, u as ModelAttributeAst } from "./declarations-BgUAq1RG-Dz_-EI1Q.mjs";
|
|
13
|
+
//#region ../../../1-framework/2-authoring/psl-parser/dist/binder-MH8x-Dk-.mjs
|
|
14
|
+
function* modelAttributeDescriptors(namespace) {
|
|
15
|
+
for (const value of Object.values(namespace)) {
|
|
16
|
+
if (isAuthoringModelAttributeDescriptor(value)) {
|
|
17
|
+
yield value;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
yield* modelAttributeDescriptors(value);
|
|
21
|
+
}
|
|
9
22
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
function assembleAttributeSpecs(contributions) {
|
|
24
|
+
const entries = Object.entries(contributions.attributeSpecs.model);
|
|
25
|
+
const claimed = new Set(entries.map(([attribute]) => attribute));
|
|
26
|
+
for (const descriptor of modelAttributeDescriptors(contributions.modelAttributes)) {
|
|
27
|
+
if (claimed.has(descriptor.attribute)) throw new InternalError(`Duplicate attribute spec registration for "${descriptor.attribute}". Each model attribute name may be registered once across family built-ins and model-attribute descriptors.`);
|
|
28
|
+
claimed.add(descriptor.attribute);
|
|
29
|
+
entries.push([descriptor.attribute, descriptor.spec]);
|
|
30
|
+
}
|
|
31
|
+
return Object.freeze(blindCast({
|
|
32
|
+
model: Object.freeze(Object.fromEntries(entries)),
|
|
33
|
+
field: Object.freeze({ ...contributions.attributeSpecs.field })
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
function resolveDescribeUnsupportedAttribute(pslDiagnostics) {
|
|
37
|
+
if (pslDiagnostics?.describeUnsupportedAttribute === void 0) return;
|
|
38
|
+
return blindCast(pslDiagnostics.describeUnsupportedAttribute);
|
|
39
|
+
}
|
|
40
|
+
function resolveDescribeUnresolvedType(pslDiagnostics) {
|
|
41
|
+
if (pslDiagnostics?.describeUnresolvedType === void 0) return;
|
|
42
|
+
return blindCast(pslDiagnostics.describeUnresolvedType);
|
|
43
|
+
}
|
|
44
|
+
function writtenEntityReference(node) {
|
|
45
|
+
const name = IdentifierAst.cast(node)?.name();
|
|
46
|
+
if (name !== void 0) return {
|
|
47
|
+
namespace: void 0,
|
|
48
|
+
name
|
|
49
|
+
};
|
|
50
|
+
const path = PathExprAst.cast(node)?.path();
|
|
51
|
+
if (path === void 0 || path.length !== 2) return void 0;
|
|
52
|
+
const [namespace, member] = path;
|
|
53
|
+
return namespace === void 0 || member === void 0 ? void 0 : {
|
|
54
|
+
namespace,
|
|
55
|
+
name: member
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function describeWrittenEntityReference(reference) {
|
|
59
|
+
return reference.namespace === void 0 ? reference.name : `${reference.namespace}.${reference.name}`;
|
|
60
|
+
}
|
|
61
|
+
const references = /* @__PURE__ */ new WeakMap();
|
|
62
|
+
function entityReference(resolution) {
|
|
63
|
+
switch (resolution.kind) {
|
|
64
|
+
case "model":
|
|
65
|
+
case "compositeType":
|
|
66
|
+
case "namedType":
|
|
67
|
+
case "block": return interned(resolution.symbol, resolution.namespace);
|
|
68
|
+
default: return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function interned(declaration, namespace) {
|
|
72
|
+
const existing = references.get(declaration);
|
|
73
|
+
if (existing !== void 0) return existing;
|
|
74
|
+
const reference = {
|
|
75
|
+
declaration,
|
|
76
|
+
namespace
|
|
77
|
+
};
|
|
78
|
+
references.set(declaration, reference);
|
|
79
|
+
return reference;
|
|
80
|
+
}
|
|
81
|
+
function matchesSelector(reference, expected) {
|
|
82
|
+
const declaration = reference.declaration;
|
|
83
|
+
if (declaration.kind !== expected.kind) return false;
|
|
84
|
+
return expected.kind !== "block" || declaration.kind === "block" && declaration.keyword === expected.keyword;
|
|
85
|
+
}
|
|
86
|
+
function describeResolution(resolution) {
|
|
87
|
+
switch (resolution.kind) {
|
|
88
|
+
case "block": return resolution.symbol.keyword;
|
|
89
|
+
case "contributedType": return "scalar type";
|
|
90
|
+
case "crossSpace": return "cross-space reference";
|
|
91
|
+
case "unresolved": return "unresolved name";
|
|
92
|
+
default: return resolution.kind;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function isContributedTypeDescriptor(value) {
|
|
96
|
+
return "kind" in value && (value.kind === "typeConstructor" || value.kind === "typeAlias" || value.kind === "fieldPreset");
|
|
97
|
+
}
|
|
98
|
+
/** The codec a column typed by `descriptor` is stored with. */
|
|
99
|
+
function contributedTypeCodecId(descriptor) {
|
|
100
|
+
return descriptor.kind === "typeAlias" ? descriptor.output.type.codecId : descriptor.output.codecId;
|
|
101
|
+
}
|
|
102
|
+
function mergeContributedTypes(...namespaces) {
|
|
103
|
+
const merged = {};
|
|
104
|
+
for (const namespace of namespaces) for (const [name, value] of Object.entries(namespace)) {
|
|
105
|
+
const existing = Object.hasOwn(merged, name) ? merged[name] : void 0;
|
|
106
|
+
merged[name] = existing !== void 0 && !isContributedTypeDescriptor(existing) && !isContributedTypeDescriptor(value) ? mergeContributedTypes(existing, value) : value;
|
|
107
|
+
}
|
|
108
|
+
return merged;
|
|
109
|
+
}
|
|
110
|
+
function contributedTypeScope(contributedTypes) {
|
|
111
|
+
const members = collect(contributedTypes, []);
|
|
112
|
+
return {
|
|
113
|
+
lookup(name) {
|
|
114
|
+
return members.get(name);
|
|
115
|
+
},
|
|
116
|
+
entries() {
|
|
117
|
+
return members.entries();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function collect(namespace, prefix) {
|
|
122
|
+
const members = /* @__PURE__ */ new Map();
|
|
123
|
+
for (const [name, value] of Object.entries(namespace)) {
|
|
124
|
+
const path = [...prefix, name];
|
|
125
|
+
members.set(name, isContributedTypeDescriptor(value) ? {
|
|
126
|
+
kind: "contributedType",
|
|
127
|
+
name,
|
|
128
|
+
path,
|
|
129
|
+
descriptor: value
|
|
130
|
+
} : {
|
|
131
|
+
kind: "contributedNamespace",
|
|
132
|
+
name,
|
|
133
|
+
path,
|
|
134
|
+
members: collect(value, path)
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return members;
|
|
138
|
+
}
|
|
139
|
+
function blockSpecFactoryOf(descriptor) {
|
|
140
|
+
return blindCast(descriptor.spec);
|
|
141
|
+
}
|
|
142
|
+
/** The context a block spec factory and a block-attribute spec factory are built from. ADR 262. */
|
|
143
|
+
function blockSpecContext(input) {
|
|
144
|
+
return {
|
|
145
|
+
symbols: input.symbols,
|
|
146
|
+
dataTypes: input.dataTypes
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function findBlockDescriptor(descriptors, keyword) {
|
|
150
|
+
if (descriptors === void 0) return void 0;
|
|
151
|
+
for (const value of Object.values(descriptors)) {
|
|
152
|
+
if (value === void 0) continue;
|
|
153
|
+
if (isAuthoringPslBlockDescriptor(value)) {
|
|
154
|
+
if (value.keyword === keyword) return value;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const nested = findBlockDescriptor(value, keyword);
|
|
158
|
+
if (nested !== void 0) return nested;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function namespaceIdOfPslName(name) {
|
|
162
|
+
return name === "unbound" ? UNBOUND_NAMESPACE_ID : name;
|
|
163
|
+
}
|
|
164
|
+
function pslNameOfNamespaceId(id) {
|
|
165
|
+
return id === "__unbound__" ? UNBOUND_PSL_NAMESPACE_NAME : id;
|
|
166
|
+
}
|
|
167
|
+
function pslNamesOfNamespaceId(id) {
|
|
168
|
+
return id === "__unbound__" ? [UNBOUND_PSL_NAMESPACE_NAME, UNBOUND_NAMESPACE_ID] : [id];
|
|
169
|
+
}
|
|
170
|
+
function* recordNames(...records) {
|
|
171
|
+
for (const record of records) yield* Object.keys(record);
|
|
172
|
+
}
|
|
173
|
+
var Scope = class {
|
|
174
|
+
parent;
|
|
175
|
+
constructor(parent) {
|
|
176
|
+
this.parent = parent;
|
|
177
|
+
}
|
|
178
|
+
*entries() {
|
|
179
|
+
const seen = /* @__PURE__ */ new Set();
|
|
180
|
+
for (const name of this.ownNames()) {
|
|
181
|
+
if (seen.has(name)) continue;
|
|
182
|
+
seen.add(name);
|
|
183
|
+
const resolution = this.lookup(name);
|
|
184
|
+
if (resolution !== void 0) yield [name, resolution];
|
|
185
|
+
}
|
|
186
|
+
for (const entry of this.parent?.entries() ?? []) if (!seen.has(entry[0])) yield entry;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
function contributedResolution(member) {
|
|
190
|
+
return member.kind === "contributedType" ? {
|
|
191
|
+
kind: "contributedType",
|
|
192
|
+
symbol: member
|
|
193
|
+
} : {
|
|
194
|
+
kind: "contributedNamespace",
|
|
195
|
+
symbol: member
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function namespaceMember(namespace, name) {
|
|
199
|
+
const model = namespace.models[name];
|
|
200
|
+
if (model !== void 0) return {
|
|
201
|
+
kind: "model",
|
|
202
|
+
symbol: model,
|
|
203
|
+
namespace
|
|
204
|
+
};
|
|
205
|
+
const compositeType = namespace.compositeTypes[name];
|
|
206
|
+
if (compositeType !== void 0) return {
|
|
207
|
+
kind: "compositeType",
|
|
208
|
+
symbol: compositeType,
|
|
209
|
+
namespace
|
|
210
|
+
};
|
|
211
|
+
const block = namespace.blocks[name];
|
|
212
|
+
if (block !== void 0) return {
|
|
213
|
+
kind: "block",
|
|
214
|
+
symbol: block,
|
|
215
|
+
namespace
|
|
216
|
+
};
|
|
217
|
+
const mixin = namespace.mixins[name];
|
|
218
|
+
if (mixin !== void 0) return {
|
|
219
|
+
kind: "mixin",
|
|
220
|
+
symbol: mixin,
|
|
221
|
+
namespace
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
var ContributedScope = class extends Scope {
|
|
225
|
+
#registry;
|
|
226
|
+
constructor(registry) {
|
|
227
|
+
super(void 0);
|
|
228
|
+
this.#registry = registry;
|
|
229
|
+
}
|
|
230
|
+
lookup(name) {
|
|
231
|
+
const member = this.#registry.lookup(name);
|
|
232
|
+
return member === void 0 ? void 0 : contributedResolution(member);
|
|
233
|
+
}
|
|
234
|
+
*ownNames() {
|
|
235
|
+
for (const [name] of this.#registry.entries()) yield name;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var DocumentScope = class extends Scope {
|
|
239
|
+
#symbols;
|
|
240
|
+
constructor(symbols, parent) {
|
|
241
|
+
super(parent);
|
|
242
|
+
this.#symbols = symbols;
|
|
243
|
+
}
|
|
244
|
+
lookup(name) {
|
|
245
|
+
const { defaultNamespace, namedTypes, namespaces } = this.#symbols;
|
|
246
|
+
const member = namespaceMember(defaultNamespace, name);
|
|
247
|
+
if (member !== void 0) return member;
|
|
248
|
+
const namedType = namedTypes[name];
|
|
249
|
+
if (namedType !== void 0) return {
|
|
250
|
+
kind: "namedType",
|
|
251
|
+
symbol: namedType
|
|
252
|
+
};
|
|
253
|
+
const namespace = namespaces[namespaceIdOfPslName(name)];
|
|
254
|
+
if (namespace !== void 0) return {
|
|
255
|
+
kind: "namespace",
|
|
256
|
+
symbol: namespace
|
|
257
|
+
};
|
|
258
|
+
return this.parent?.lookup(name);
|
|
259
|
+
}
|
|
260
|
+
*ownNames() {
|
|
261
|
+
const { defaultNamespace, namedTypes, namespaces } = this.#symbols;
|
|
262
|
+
yield* recordNames(defaultNamespace.models, defaultNamespace.compositeTypes, namedTypes, defaultNamespace.blocks, defaultNamespace.mixins);
|
|
263
|
+
for (const namespace of Object.values(namespaces)) yield namespace.name;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
var NamespaceScope = class extends Scope {
|
|
267
|
+
#namespace;
|
|
268
|
+
constructor(namespace, parent) {
|
|
269
|
+
super(parent);
|
|
270
|
+
this.#namespace = namespace;
|
|
271
|
+
}
|
|
272
|
+
lookup(name) {
|
|
273
|
+
return namespaceMember(this.#namespace, name) ?? this.parent?.lookup(name);
|
|
274
|
+
}
|
|
275
|
+
ownNames() {
|
|
276
|
+
const namespace = this.#namespace;
|
|
277
|
+
return recordNames(namespace.models, namespace.compositeTypes, namespace.blocks, namespace.mixins);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
function contributedScope(registry) {
|
|
281
|
+
return new ContributedScope(registry);
|
|
282
|
+
}
|
|
283
|
+
function documentScope(symbols, parent) {
|
|
284
|
+
return new DocumentScope(symbols, parent);
|
|
285
|
+
}
|
|
286
|
+
function namedTypeBaseScope(symbols, parent) {
|
|
287
|
+
return new DocumentScope({
|
|
288
|
+
...symbols,
|
|
289
|
+
namedTypes: {}
|
|
290
|
+
}, parent);
|
|
291
|
+
}
|
|
292
|
+
function namespaceScope(namespace, parent) {
|
|
293
|
+
return new NamespaceScope(namespace, parent);
|
|
294
|
+
}
|
|
295
|
+
function isNamespaceLike(resolution) {
|
|
296
|
+
return resolution.kind === "namespace" || resolution.kind === "contributedNamespace";
|
|
297
|
+
}
|
|
298
|
+
function* memberEntries(qualifier) {
|
|
299
|
+
if (qualifier.kind === "contributedNamespace") {
|
|
300
|
+
for (const [name, member] of qualifier.symbol.members) yield [name, contributedResolution(member)];
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
yield* new NamespaceScope(qualifier.symbol, void 0).entries();
|
|
304
|
+
}
|
|
305
|
+
function lookupMember(qualifier, name) {
|
|
306
|
+
if (qualifier.kind === "contributedNamespace") {
|
|
307
|
+
const member = qualifier.symbol.members.get(name);
|
|
308
|
+
return member === void 0 ? void 0 : contributedResolution(member);
|
|
309
|
+
}
|
|
310
|
+
return namespaceMember(qualifier.symbol, name);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Owns duplicate-declaration detection for all PSL scopes; downstream consumers
|
|
314
|
+
* should consume first-wins symbols rather than re-emitting duplicate diagnostics.
|
|
315
|
+
*/
|
|
316
|
+
function buildSymbolTable(options) {
|
|
317
|
+
const { documents, sources, defaultNamespaceId } = options;
|
|
318
|
+
const diagnostics = [];
|
|
319
|
+
const namespaces = Object.create(null);
|
|
320
|
+
const namedTypes = Object.create(null);
|
|
321
|
+
const blocks = Object.create(null);
|
|
322
|
+
const models = Object.create(null);
|
|
323
|
+
const compositeTypes = Object.create(null);
|
|
324
|
+
const mixins = Object.create(null);
|
|
325
|
+
const topLevelNames = new Set(pslNamesOfNamespaceId(defaultNamespaceId));
|
|
326
|
+
const defaultNamespace = {
|
|
327
|
+
kind: "namespace",
|
|
328
|
+
id: defaultNamespaceId,
|
|
329
|
+
name: pslNameOfNamespaceId(defaultNamespaceId),
|
|
330
|
+
declarations: [],
|
|
331
|
+
models,
|
|
332
|
+
compositeTypes,
|
|
333
|
+
blocks,
|
|
334
|
+
mixins
|
|
335
|
+
};
|
|
336
|
+
namespaces[defaultNamespaceId] = defaultNamespace;
|
|
337
|
+
for (const document of documents) {
|
|
338
|
+
const sourceFile = sources.sourceFileFor(document.syntax);
|
|
339
|
+
const claim = (taken, name) => {
|
|
340
|
+
const text = name?.name();
|
|
341
|
+
if (text === void 0) return void 0;
|
|
342
|
+
if (taken.has(text)) {
|
|
343
|
+
const range = nameRange(name, sources);
|
|
344
|
+
if (range) diagnostics.push({
|
|
345
|
+
code: "PSL_DUPLICATE_DECLARATION",
|
|
346
|
+
message: `Duplicate declaration of "${text}"`,
|
|
347
|
+
filename: sourceFile.filename,
|
|
348
|
+
range
|
|
349
|
+
});
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
taken.add(text);
|
|
353
|
+
return text;
|
|
354
|
+
};
|
|
355
|
+
for (const declaration of document.declarations()) if (declaration instanceof ModelDeclarationAst) {
|
|
356
|
+
const name = claim(topLevelNames, declaration.name());
|
|
357
|
+
if (name !== void 0) models[name] = buildModel(name, declaration, sources, diagnostics);
|
|
358
|
+
} else if (declaration instanceof CompositeTypeDeclarationAst) {
|
|
359
|
+
const name = claim(topLevelNames, declaration.name());
|
|
360
|
+
if (name !== void 0) compositeTypes[name] = buildCompositeType(name, declaration, sources, diagnostics);
|
|
361
|
+
} else if (declaration instanceof GenericBlockDeclarationAst) {
|
|
362
|
+
const name = claim(topLevelNames, declaration.name());
|
|
363
|
+
if (name !== void 0) blocks[name] = buildBlock(name, declaration, sources);
|
|
364
|
+
} else if (declaration instanceof MixinDeclarationAst) {
|
|
365
|
+
const name = claim(topLevelNames, declaration.name());
|
|
366
|
+
if (name !== void 0) mixins[name] = buildMixin(name, declaration, sources, diagnostics);
|
|
367
|
+
} else if (declaration instanceof NamespaceDeclarationAst) {
|
|
368
|
+
const declaredName = declaration.name()?.name();
|
|
369
|
+
if (declaredName === void 0) continue;
|
|
370
|
+
const id = namespaceIdOfPslName(declaredName);
|
|
371
|
+
let namespace = namespaces[id];
|
|
372
|
+
if (namespace === void 0) {
|
|
373
|
+
const names = pslNamesOfNamespaceId(id);
|
|
374
|
+
if (claim(names.some((name) => topLevelNames.has(name)) ? new Set(names) : topLevelNames, declaration.name()) === void 0) continue;
|
|
375
|
+
for (const name of names) topLevelNames.add(name);
|
|
376
|
+
namespace = {
|
|
377
|
+
kind: "namespace",
|
|
378
|
+
id,
|
|
379
|
+
name: pslNameOfNamespaceId(id),
|
|
380
|
+
declarations: [{
|
|
381
|
+
node: declaration,
|
|
382
|
+
span: nodePslSpan(declaration.syntax, sources)
|
|
383
|
+
}],
|
|
384
|
+
models: Object.create(null),
|
|
385
|
+
compositeTypes: Object.create(null),
|
|
386
|
+
blocks: Object.create(null),
|
|
387
|
+
mixins: Object.create(null)
|
|
388
|
+
};
|
|
389
|
+
namespaces[id] = namespace;
|
|
390
|
+
} else namespace.declarations.push({
|
|
391
|
+
node: declaration,
|
|
392
|
+
span: nodePslSpan(declaration.syntax, sources)
|
|
393
|
+
});
|
|
394
|
+
extendNamespace(namespace, declaration, diagnostics, sources, namespace === defaultNamespace ? topLevelNames : /* @__PURE__ */ new Set());
|
|
395
|
+
} else if (declaration instanceof TypesBlockAst) for (const binding of declaration.declarations()) {
|
|
396
|
+
const name = claim(topLevelNames, binding.name());
|
|
397
|
+
if (name === void 0) continue;
|
|
398
|
+
const resolved = resolveNamedTypeBinding(binding, sources);
|
|
399
|
+
namedTypes[name] = {
|
|
400
|
+
kind: "namedType",
|
|
401
|
+
name,
|
|
402
|
+
node: binding,
|
|
403
|
+
span: nodePslSpan(binding.syntax, sources),
|
|
404
|
+
...resolved
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
symbolTable: {
|
|
410
|
+
defaultNamespace,
|
|
411
|
+
namespaces,
|
|
412
|
+
namedTypes
|
|
413
|
+
},
|
|
414
|
+
diagnostics
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function buildModel(name, node, sources, diagnostics) {
|
|
418
|
+
return {
|
|
419
|
+
kind: "model",
|
|
420
|
+
name,
|
|
421
|
+
node,
|
|
422
|
+
span: nodePslSpan(node.syntax, sources),
|
|
423
|
+
fields: buildFields(name, node.fields(), sources, diagnostics),
|
|
424
|
+
attributes: readResolvedAttributes(node.attributes(), sources)
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function buildCompositeType(name, node, sources, diagnostics) {
|
|
428
|
+
return {
|
|
429
|
+
kind: "compositeType",
|
|
430
|
+
name,
|
|
431
|
+
node,
|
|
432
|
+
span: nodePslSpan(node.syntax, sources),
|
|
433
|
+
fields: buildFields(name, node.fields(), sources, diagnostics),
|
|
434
|
+
attributes: readResolvedAttributes(node.attributes(), sources)
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function buildBlock(name, node, sources) {
|
|
438
|
+
return {
|
|
439
|
+
kind: "block",
|
|
440
|
+
name,
|
|
441
|
+
keyword: node.keyword()?.text ?? "",
|
|
442
|
+
node,
|
|
443
|
+
span: nodePslSpan(node.syntax, sources),
|
|
444
|
+
entries: Array.from(node.entries()),
|
|
445
|
+
attributes: readResolvedAttributes(node.attributes(), sources)
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
const FIELD_BLOCK_KEYWORDS = /* @__PURE__ */ new Set(["model", "type"]);
|
|
449
|
+
function buildMixin(name, node, sources, diagnostics) {
|
|
450
|
+
const keyword = node.keyword()?.text ?? "";
|
|
451
|
+
const hasFields = FIELD_BLOCK_KEYWORDS.has(keyword);
|
|
452
|
+
return {
|
|
453
|
+
kind: "mixin",
|
|
454
|
+
name,
|
|
455
|
+
keyword,
|
|
456
|
+
node,
|
|
457
|
+
span: nodePslSpan(node.syntax, sources),
|
|
458
|
+
fields: hasFields ? buildFields(name, node.fields(), sources, diagnostics) : Object.create(null),
|
|
459
|
+
entries: hasFields ? [] : Array.from(node.entries()),
|
|
460
|
+
attributes: readResolvedAttributes(node.attributes(), sources)
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function extendNamespace(namespace, node, diagnostics, sources, documentNames) {
|
|
464
|
+
const { models, compositeTypes, blocks, mixins } = namespace;
|
|
465
|
+
for (const member of node.declarations()) {
|
|
466
|
+
const memberName = member.name()?.name();
|
|
467
|
+
if (memberName === void 0) continue;
|
|
468
|
+
if (Object.hasOwn(models, memberName) || Object.hasOwn(compositeTypes, memberName) || Object.hasOwn(blocks, memberName) || Object.hasOwn(mixins, memberName) || documentNames.has(memberName)) {
|
|
469
|
+
const range = nameRange(member.name(), sources);
|
|
470
|
+
if (range) diagnostics.push({
|
|
471
|
+
code: "PSL_DUPLICATE_DECLARATION",
|
|
472
|
+
message: `Duplicate declaration of "${memberName}"`,
|
|
473
|
+
filename: sources.sourceFileFor(member.syntax).filename,
|
|
474
|
+
range
|
|
475
|
+
});
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
documentNames.add(memberName);
|
|
479
|
+
if (member instanceof ModelDeclarationAst) models[memberName] = buildModel(memberName, member, sources, diagnostics);
|
|
480
|
+
else if (member instanceof CompositeTypeDeclarationAst) compositeTypes[memberName] = buildCompositeType(memberName, member, sources, diagnostics);
|
|
481
|
+
else if (member instanceof GenericBlockDeclarationAst) blocks[memberName] = buildBlock(memberName, member, sources);
|
|
482
|
+
else if (member instanceof MixinDeclarationAst) mixins[memberName] = buildMixin(memberName, member, sources, diagnostics);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function placeMixinMembers(input) {
|
|
486
|
+
const diagnostics = [];
|
|
487
|
+
for (const records of Object.values(input.symbolTable.namespaces)) {
|
|
488
|
+
for (const symbol of Object.values(records.models)) placeFields(symbol, input, diagnostics);
|
|
489
|
+
for (const symbol of Object.values(records.compositeTypes)) placeFields(symbol, input, diagnostics);
|
|
490
|
+
for (const symbol of Object.values(records.blocks)) placeEntries(symbol, input, diagnostics);
|
|
491
|
+
}
|
|
492
|
+
return diagnostics;
|
|
493
|
+
}
|
|
494
|
+
function includesMixin(symbol, input) {
|
|
495
|
+
for (const inclusion of symbol.node.inclusions()) if (input.mixinOf(inclusion) !== void 0) return true;
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
function inclusionDiagnostic(code, message, inclusion, sources) {
|
|
499
|
+
return {
|
|
500
|
+
code,
|
|
501
|
+
message,
|
|
502
|
+
filename: sources.sourceFileFor(inclusion.syntax).filename,
|
|
503
|
+
range: nodeRange(inclusion.syntax, sources)
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function mixinToPlace(inclusion, symbol, placed, input, diagnostics) {
|
|
507
|
+
const mixin = input.mixinOf(inclusion);
|
|
508
|
+
if (mixin === void 0) return void 0;
|
|
509
|
+
if (placed.has(mixin)) {
|
|
510
|
+
diagnostics.push(inclusionDiagnostic(symbol.kind === "block" ? "PSL_INVALID_EXTENSION_BLOCK_MEMBER" : "PSL_INVALID_MODEL_MEMBER", `Mixin "${mixin.name}" is already included in this block`, inclusion, input.sources));
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
placed.add(mixin);
|
|
514
|
+
return mixin;
|
|
515
|
+
}
|
|
516
|
+
function alreadyProvided(mixin, member, symbol, inclusion, sources) {
|
|
517
|
+
return inclusionDiagnostic("PSL_DUPLICATE_DECLARATION", `Mixin "${mixin.name}" provides "${member}", which "${symbol.name}" already has`, inclusion, sources);
|
|
518
|
+
}
|
|
519
|
+
function writtenAttributes(symbol) {
|
|
520
|
+
return new Map(symbol.attributes.map((attribute) => [attribute.node.syntax, attribute]));
|
|
521
|
+
}
|
|
522
|
+
function placeFields(symbol, input, diagnostics) {
|
|
523
|
+
if (!includesMixin(symbol, input)) return;
|
|
524
|
+
const { sources } = input;
|
|
525
|
+
const ownFields = new Map(Object.values(symbol.fields).map((field) => [field.node.syntax, field]));
|
|
526
|
+
const ownAttributes = writtenAttributes(symbol);
|
|
527
|
+
const fields = Object.create(null);
|
|
528
|
+
const attributes = [];
|
|
529
|
+
const placed = /* @__PURE__ */ new Set();
|
|
530
|
+
for (const member of symbol.node.members()) if (member instanceof FieldDeclarationAst) {
|
|
531
|
+
const field = ownFields.get(member.syntax);
|
|
532
|
+
if (field === void 0) continue;
|
|
533
|
+
if (Object.hasOwn(fields, field.name)) {
|
|
534
|
+
const diagnostic = duplicateDeclaration(field.name, member.name(), sources);
|
|
535
|
+
if (diagnostic !== void 0) diagnostics.push(diagnostic);
|
|
536
|
+
} else fields[field.name] = field;
|
|
537
|
+
} else if (member instanceof ModelAttributeAst) {
|
|
538
|
+
const attribute = ownAttributes.get(member.syntax);
|
|
539
|
+
if (attribute !== void 0) attributes.push(attribute);
|
|
540
|
+
} else {
|
|
541
|
+
const mixin = mixinToPlace(member, symbol, placed, input, diagnostics);
|
|
542
|
+
if (mixin === void 0) continue;
|
|
543
|
+
for (const field of Object.values(mixin.fields)) if (Object.hasOwn(fields, field.name)) diagnostics.push(alreadyProvided(mixin, field.name, symbol, member, sources));
|
|
544
|
+
else fields[field.name] = field;
|
|
545
|
+
attributes.push(...mixin.attributes);
|
|
546
|
+
}
|
|
547
|
+
symbol.fields = fields;
|
|
548
|
+
symbol.attributes = attributes;
|
|
549
|
+
}
|
|
550
|
+
function placeEntries(symbol, input, diagnostics) {
|
|
551
|
+
if (!includesMixin(symbol, input)) return;
|
|
552
|
+
const ownAttributes = writtenAttributes(symbol);
|
|
553
|
+
const entries = [];
|
|
554
|
+
const attributes = [];
|
|
555
|
+
const placed = /* @__PURE__ */ new Set();
|
|
556
|
+
for (const member of symbol.node.members()) if (member instanceof KeyValuePairAst) entries.push(member);
|
|
557
|
+
else if (member instanceof ModelAttributeAst) {
|
|
558
|
+
const attribute = ownAttributes.get(member.syntax);
|
|
559
|
+
if (attribute !== void 0) attributes.push(attribute);
|
|
560
|
+
} else {
|
|
561
|
+
const mixin = mixinToPlace(member, symbol, placed, input, diagnostics);
|
|
562
|
+
if (mixin === void 0) continue;
|
|
563
|
+
const present = new Set(entries.map((entry) => entry.key()?.name()));
|
|
564
|
+
for (const entry of mixin.entries) {
|
|
565
|
+
const key = entry.key()?.name();
|
|
566
|
+
if (key !== void 0 && present.has(key)) diagnostics.push(alreadyProvided(mixin, key, symbol, member, input.sources));
|
|
567
|
+
else entries.push(entry);
|
|
568
|
+
}
|
|
569
|
+
attributes.push(...mixin.attributes);
|
|
570
|
+
}
|
|
571
|
+
symbol.entries = entries;
|
|
572
|
+
symbol.attributes = attributes;
|
|
573
|
+
}
|
|
574
|
+
function duplicateDeclaration(name, nameNode, sources) {
|
|
575
|
+
const range = nameRange(nameNode, sources);
|
|
576
|
+
if (nameNode === void 0 || range === void 0) return void 0;
|
|
577
|
+
return {
|
|
578
|
+
code: "PSL_DUPLICATE_DECLARATION",
|
|
579
|
+
message: `Duplicate declaration of "${name}"`,
|
|
580
|
+
filename: sources.sourceFileFor(nameNode.syntax).filename,
|
|
581
|
+
range
|
|
582
|
+
};
|
|
14
583
|
}
|
|
15
|
-
function
|
|
584
|
+
function buildFields(ownerName, fields, sources, diagnostics) {
|
|
585
|
+
const result = Object.create(null);
|
|
586
|
+
for (const field of fields) {
|
|
587
|
+
const nameNode = field.name();
|
|
588
|
+
const name = nameNode?.name();
|
|
589
|
+
if (name === void 0) continue;
|
|
590
|
+
if (Object.hasOwn(result, name)) {
|
|
591
|
+
const diagnostic = duplicateDeclaration(name, nameNode, sources);
|
|
592
|
+
if (diagnostic !== void 0) diagnostics.push(diagnostic);
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
result[name] = buildField(ownerName, name, field, sources, diagnostics);
|
|
596
|
+
}
|
|
597
|
+
return result;
|
|
598
|
+
}
|
|
599
|
+
function buildField(ownerName, name, node, sources, diagnostics) {
|
|
600
|
+
const attributes = readResolvedAttributes(node.attributes(), sources);
|
|
601
|
+
const span = nodePslSpan(node.syntax, sources);
|
|
602
|
+
const annotation = node.typeAnnotation();
|
|
603
|
+
const typeName = annotation?.name();
|
|
604
|
+
if (typeName?.isOverQualified()) {
|
|
605
|
+
const path = typeName.path();
|
|
606
|
+
diagnostics.push({
|
|
607
|
+
code: "PSL_INVALID_QUALIFIED_TYPE",
|
|
608
|
+
message: `Field "${ownerName}.${name}" has an invalid qualified type "${path.join(".")}"; use at most one namespace qualifier (e.g. "ns.TypeName")`,
|
|
609
|
+
filename: sources.sourceFileFor(typeName.syntax).filename,
|
|
610
|
+
range: nodeRange(typeName.syntax, sources)
|
|
611
|
+
});
|
|
612
|
+
return {
|
|
613
|
+
kind: "field",
|
|
614
|
+
name,
|
|
615
|
+
node,
|
|
616
|
+
span,
|
|
617
|
+
typeName: path[path.length - 1] ?? "",
|
|
618
|
+
optional: false,
|
|
619
|
+
list: false,
|
|
620
|
+
elementOptional: false,
|
|
621
|
+
malformedType: true,
|
|
622
|
+
attributes
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
const typeConstructor = annotation?.isConstructor() ? readResolvedConstructorCall(annotation, sources) : void 0;
|
|
626
|
+
const typeNamespaceId = typeName?.namespace()?.name();
|
|
627
|
+
const typeContractSpaceId = typeName?.space()?.name();
|
|
628
|
+
return {
|
|
629
|
+
kind: "field",
|
|
630
|
+
name,
|
|
631
|
+
node,
|
|
632
|
+
span,
|
|
633
|
+
typeName: typeName?.identifier()?.name() ?? "",
|
|
634
|
+
...typeNamespaceId !== void 0 ? { typeNamespaceId } : {},
|
|
635
|
+
...typeContractSpaceId !== void 0 ? { typeContractSpaceId } : {},
|
|
636
|
+
optional: annotation?.isOptional() ?? false,
|
|
637
|
+
list: annotation?.isList() ?? false,
|
|
638
|
+
elementOptional: annotation?.isElementOptional() ?? false,
|
|
639
|
+
...typeConstructor !== void 0 ? { typeConstructor } : {},
|
|
640
|
+
attributes
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
function resolveNamedTypeBinding(node, sources) {
|
|
644
|
+
const annotation = node.typeAnnotation();
|
|
645
|
+
const isConstructor = annotation?.isConstructor() ?? false;
|
|
646
|
+
const baseType = annotation?.name()?.identifier()?.name();
|
|
647
|
+
const typeConstructor = readResolvedConstructorCall(annotation, sources);
|
|
648
|
+
return {
|
|
649
|
+
isConstructor,
|
|
650
|
+
...!isConstructor && baseType !== void 0 ? { baseType } : {},
|
|
651
|
+
...typeConstructor !== void 0 ? { typeConstructor } : {},
|
|
652
|
+
attributes: readResolvedAttributes(node.attributes(), sources)
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
function nameRange(name, sources) {
|
|
656
|
+
if (name === void 0) return void 0;
|
|
657
|
+
const sourceFile = sources.sourceFileFor(name.syntax);
|
|
658
|
+
for (const token of name.syntax.tokens()) if (token.kind === "Ident") return {
|
|
659
|
+
start: sourceFile.positionAt(token.offset),
|
|
660
|
+
end: sourceFile.positionAt(token.offset + token.text.length)
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
function nodeRange(node, sources) {
|
|
664
|
+
const sourceFile = sources.sourceFileFor(node);
|
|
665
|
+
const start = node.offset;
|
|
666
|
+
const end = start + node.green.textLength;
|
|
667
|
+
return {
|
|
668
|
+
start: sourceFile.positionAt(start),
|
|
669
|
+
end: sourceFile.positionAt(end)
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
const PSL_UNRESOLVED_REFERENCE = "PSL_UNRESOLVED_REFERENCE";
|
|
673
|
+
function typeReferenceNode(symbol) {
|
|
674
|
+
return symbol.node.typeAnnotation()?.name()?.syntax;
|
|
675
|
+
}
|
|
676
|
+
function contributedTypeOf(resolution, binder) {
|
|
677
|
+
return contributedTypeOfResolution(resolution, (base) => binder.symbolForNode(base));
|
|
678
|
+
}
|
|
679
|
+
function contributedTypeOfResolution(resolution, resolve) {
|
|
680
|
+
const base = resolution?.kind === "namedType" ? typeReferenceNode(resolution.symbol) : void 0;
|
|
681
|
+
const target = base === void 0 ? resolution : resolve(base);
|
|
682
|
+
return target?.kind === "contributedType" ? target.symbol : void 0;
|
|
683
|
+
}
|
|
684
|
+
var PslBinder = class {
|
|
685
|
+
#declarations;
|
|
686
|
+
#references;
|
|
687
|
+
#documentScope;
|
|
688
|
+
#scopes;
|
|
689
|
+
constructor(declarations, references, documentScope, scopes) {
|
|
690
|
+
this.#declarations = declarations;
|
|
691
|
+
this.#references = references;
|
|
692
|
+
this.#documentScope = documentScope;
|
|
693
|
+
this.#scopes = scopes;
|
|
694
|
+
}
|
|
695
|
+
declaredSymbol(node) {
|
|
696
|
+
return this.#declarations.get(node);
|
|
697
|
+
}
|
|
698
|
+
symbolForNode(node) {
|
|
699
|
+
return this.#references.get(node);
|
|
700
|
+
}
|
|
701
|
+
scopeAt(node) {
|
|
702
|
+
return node.findAncestor((ancestor) => this.#scopes.get(ancestor)) ?? this.#documentScope;
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
var ScopeStack = class {
|
|
706
|
+
#base;
|
|
707
|
+
#scopes;
|
|
708
|
+
constructor(base) {
|
|
709
|
+
this.#base = base;
|
|
710
|
+
this.#scopes = [base];
|
|
711
|
+
}
|
|
712
|
+
current() {
|
|
713
|
+
return this.#scopes[this.#scopes.length - 1] ?? this.#base;
|
|
714
|
+
}
|
|
715
|
+
push(scope) {
|
|
716
|
+
this.#scopes.push(scope);
|
|
717
|
+
}
|
|
718
|
+
pop() {
|
|
719
|
+
this.#scopes.pop();
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
const FIELD_MIXIN_KEYWORDS = /* @__PURE__ */ new Set(["model", "type"]);
|
|
723
|
+
function hasFields(mixin) {
|
|
724
|
+
return FIELD_MIXIN_KEYWORDS.has(mixin.keyword);
|
|
725
|
+
}
|
|
726
|
+
function walkFieldOwners(symbolTable, stack, binder, visit) {
|
|
727
|
+
const visitAll = (records, namespace) => {
|
|
728
|
+
for (const entity of Object.values(records.models)) visit(entity, namespace);
|
|
729
|
+
for (const entity of Object.values(records.compositeTypes)) visit(entity, namespace);
|
|
730
|
+
for (const mixin of Object.values(records.mixins)) if (hasFields(mixin)) visit(mixin, namespace);
|
|
731
|
+
};
|
|
732
|
+
for (const namespace of Object.values(symbolTable.namespaces)) {
|
|
733
|
+
const [declaration] = namespace.declarations;
|
|
734
|
+
if (declaration !== void 0) stack.push(binder.scopeAt(declaration.node.syntax));
|
|
735
|
+
visitAll(namespace, namespace);
|
|
736
|
+
if (declaration !== void 0) stack.pop();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
function isWrittenIn(member, holder) {
|
|
740
|
+
return member.parent === holder.node.syntax;
|
|
741
|
+
}
|
|
742
|
+
function ownFields(owner) {
|
|
743
|
+
return Object.values(owner.fields).filter((field) => isWrittenIn(field.node.syntax, owner));
|
|
744
|
+
}
|
|
745
|
+
function ownAttributes(holder) {
|
|
746
|
+
return holder.attributes.filter((attribute) => isWrittenIn(attribute.node.syntax, holder));
|
|
747
|
+
}
|
|
748
|
+
function declarationResolution(entity, namespace) {
|
|
749
|
+
return entity.kind === "model" ? {
|
|
750
|
+
kind: "model",
|
|
751
|
+
symbol: entity,
|
|
752
|
+
namespace
|
|
753
|
+
} : {
|
|
754
|
+
kind: "compositeType",
|
|
755
|
+
symbol: entity,
|
|
756
|
+
namespace
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
function createBinder(input) {
|
|
760
|
+
const { symbolTable, sources, context } = input;
|
|
761
|
+
const contributions = context.authoringContributions;
|
|
762
|
+
const describeUnsupportedAttributeFactory = resolveDescribeUnsupportedAttribute(context.pslDiagnostics);
|
|
763
|
+
const describeUnresolvedTypeFactory = resolveDescribeUnresolvedType(context.pslDiagnostics);
|
|
764
|
+
return bind({
|
|
765
|
+
sources,
|
|
766
|
+
symbolTable,
|
|
767
|
+
contributedTypes: mergeContributedTypes(contributions.field, contributions.type),
|
|
768
|
+
attributeSpecs: assembleAttributeSpecs(contributions),
|
|
769
|
+
pslBlockDescriptors: contributions.pslBlockDescriptors,
|
|
770
|
+
defaultFunctionRegistry: context.controlMutationDefaults.defaultFunctionRegistry,
|
|
771
|
+
generatorFunctions: context.generatorFunctions,
|
|
772
|
+
dataTypes: context.dataTypes,
|
|
773
|
+
...describeUnsupportedAttributeFactory !== void 0 ? { describeUnsupportedAttribute: describeUnsupportedAttributeFactory(sources) } : {},
|
|
774
|
+
...describeUnresolvedTypeFactory !== void 0 ? { describeUnresolvedType: describeUnresolvedTypeFactory(contributions) } : {}
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
function bind(options) {
|
|
778
|
+
const { sources, symbolTable, contributedTypes, attributeSpecs, defaultFunctionRegistry, generatorFunctions, dataTypes, describeUnsupportedAttribute, describeUnresolvedType } = options;
|
|
779
|
+
const pslBlockDescriptors = options.pslBlockDescriptors ?? {};
|
|
780
|
+
const contributed = contributedScope(contributedTypeScope(contributedTypes));
|
|
781
|
+
const document = documentScope(symbolTable, contributed);
|
|
782
|
+
const stack = new ScopeStack(document);
|
|
783
|
+
const scopes = /* @__PURE__ */ new WeakMap();
|
|
784
|
+
const declarations = /* @__PURE__ */ new WeakMap();
|
|
785
|
+
const references = /* @__PURE__ */ new WeakMap();
|
|
786
|
+
const diagnostics = [];
|
|
787
|
+
const binder = new PslBinder(declarations, references, document, scopes);
|
|
788
|
+
const baseScope = namedTypeBaseScope(symbolTable, contributed);
|
|
789
|
+
for (const symbol of Object.values(symbolTable.namedTypes)) {
|
|
790
|
+
declarations.set(symbol.node.syntax, symbol);
|
|
791
|
+
const declaredName = symbol.node.name()?.syntax;
|
|
792
|
+
if (declaredName !== void 0) references.set(declaredName, {
|
|
793
|
+
kind: "namedType",
|
|
794
|
+
symbol
|
|
795
|
+
});
|
|
796
|
+
const name = symbol.node.typeAnnotation()?.name();
|
|
797
|
+
const outcome = resolveTypeReference(name, baseScope, references);
|
|
798
|
+
if (name === void 0 || outcome === void 0) continue;
|
|
799
|
+
references.set(name.syntax, outcome.resolution);
|
|
800
|
+
bindEntityConstructorArgument(symbol, outcome.resolution, {
|
|
801
|
+
scope: baseScope,
|
|
802
|
+
sources,
|
|
803
|
+
references,
|
|
804
|
+
diagnostics
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
for (const namespace of Object.values(symbolTable.namespaces)) {
|
|
808
|
+
const scope = namespace === symbolTable.defaultNamespace ? document : namespaceScope(namespace, document);
|
|
809
|
+
for (const declaration of namespace.declarations) {
|
|
810
|
+
declarations.set(declaration.node.syntax, namespace);
|
|
811
|
+
scopes.set(declaration.node.syntax, scope);
|
|
812
|
+
const declaredName = declaration.node.name()?.syntax;
|
|
813
|
+
if (declaredName !== void 0) references.set(declaredName, {
|
|
814
|
+
kind: "namespace",
|
|
815
|
+
symbol: namespace
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
for (const symbol of Object.values(namespace.blocks)) {
|
|
819
|
+
declarations.set(symbol.node.syntax, symbol);
|
|
820
|
+
const declaredName = symbol.node.name()?.syntax;
|
|
821
|
+
if (declaredName !== void 0) references.set(declaredName, {
|
|
822
|
+
kind: "block",
|
|
823
|
+
symbol,
|
|
824
|
+
namespace
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
for (const symbol of Object.values(namespace.mixins)) {
|
|
828
|
+
declarations.set(symbol.node.syntax, symbol);
|
|
829
|
+
const declaredName = symbol.node.name()?.syntax;
|
|
830
|
+
if (declaredName !== void 0) references.set(declaredName, {
|
|
831
|
+
kind: "mixin",
|
|
832
|
+
symbol,
|
|
833
|
+
namespace
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
const included = /* @__PURE__ */ new Map();
|
|
838
|
+
const inclusionContext = {
|
|
839
|
+
sources,
|
|
840
|
+
references,
|
|
841
|
+
diagnostics,
|
|
842
|
+
included
|
|
843
|
+
};
|
|
844
|
+
for (const namespace of Object.values(symbolTable.namespaces)) {
|
|
845
|
+
const [declaration] = namespace.declarations;
|
|
846
|
+
bindInclusions(namespace, declaration === void 0 ? document : binder.scopeAt(declaration.node.syntax), inclusionContext);
|
|
847
|
+
}
|
|
848
|
+
diagnostics.push(...placeMixinMembers({
|
|
849
|
+
symbolTable,
|
|
850
|
+
sources,
|
|
851
|
+
mixinOf: (inclusion) => included.get(inclusion.syntax)
|
|
852
|
+
}));
|
|
853
|
+
walkFieldOwners(symbolTable, stack, binder, (entity, namespace) => {
|
|
854
|
+
if (entity.kind !== "mixin") {
|
|
855
|
+
declarations.set(entity.node.syntax, entity);
|
|
856
|
+
const declaredName = entity.node.name()?.syntax;
|
|
857
|
+
if (declaredName !== void 0) references.set(declaredName, declarationResolution(entity, namespace));
|
|
858
|
+
}
|
|
859
|
+
for (const field of ownFields(entity)) {
|
|
860
|
+
declarations.set(field.node.syntax, field);
|
|
861
|
+
const fieldName = field.node.name()?.syntax;
|
|
862
|
+
if (fieldName !== void 0) references.set(fieldName, {
|
|
863
|
+
kind: "field",
|
|
864
|
+
symbol: field
|
|
865
|
+
});
|
|
866
|
+
const node = typeReferenceNode(field);
|
|
867
|
+
if (node === void 0) continue;
|
|
868
|
+
const name = field.node.typeAnnotation()?.name();
|
|
869
|
+
const outcome = resolveTypeReference(name, stack.current(), references, (written) => describeUnresolvedType?.({
|
|
870
|
+
field,
|
|
871
|
+
owner: entity,
|
|
872
|
+
written
|
|
873
|
+
}));
|
|
874
|
+
if (outcome === void 0) continue;
|
|
875
|
+
references.set(node, outcome.resolution);
|
|
876
|
+
bindEntityConstructorArgument(field, outcome.resolution, {
|
|
877
|
+
scope: stack.current(),
|
|
878
|
+
sources,
|
|
879
|
+
references,
|
|
880
|
+
diagnostics
|
|
881
|
+
});
|
|
882
|
+
if (outcome.message !== void 0) diagnostics.push({
|
|
883
|
+
code: PSL_UNRESOLVED_REFERENCE,
|
|
884
|
+
message: outcome.message,
|
|
885
|
+
data: {
|
|
886
|
+
reference: "type",
|
|
887
|
+
name: outcome.name,
|
|
888
|
+
constructorCall: field.typeConstructor !== void 0
|
|
889
|
+
},
|
|
890
|
+
...diagnosticSource(sources, node).at()
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
walkFieldOwners(symbolTable, stack, binder, (entity) => {
|
|
895
|
+
const context = {
|
|
896
|
+
owner: entity,
|
|
897
|
+
scope: stack.current(),
|
|
898
|
+
references,
|
|
899
|
+
diagnostics,
|
|
900
|
+
symbolTable,
|
|
901
|
+
sources,
|
|
902
|
+
describeUnsupportedAttribute
|
|
903
|
+
};
|
|
904
|
+
const specContext = entity.kind === "model" || entity.kind === "mixin" && entity.keyword === "model" ? {
|
|
905
|
+
symbols: symbolTable,
|
|
906
|
+
model: entity,
|
|
907
|
+
defaultFunctionRegistry,
|
|
908
|
+
generatorFunctions,
|
|
909
|
+
dataTypes
|
|
910
|
+
} : void 0;
|
|
911
|
+
bindAttributes(entity, ownAttributes(entity), attributeSpecs.model, (factory) => specContext === void 0 ? void 0 : factory(specContext), {
|
|
912
|
+
...context,
|
|
913
|
+
field: void 0
|
|
914
|
+
});
|
|
915
|
+
for (const field of ownFields(entity)) bindAttributes(field, field.attributes, attributeSpecs.field, (factory) => {
|
|
916
|
+
if (specContext === void 0) return void 0;
|
|
917
|
+
const node = typeReferenceNode(field);
|
|
918
|
+
const typeResolution = node === void 0 ? void 0 : references.get(node);
|
|
919
|
+
const typeConstructor = contributedTypeOfResolution(typeResolution, (base) => references.get(base));
|
|
920
|
+
return factory({
|
|
921
|
+
...specContext,
|
|
922
|
+
field,
|
|
923
|
+
typeResolution,
|
|
924
|
+
typeConstructor
|
|
925
|
+
});
|
|
926
|
+
}, {
|
|
927
|
+
...context,
|
|
928
|
+
field
|
|
929
|
+
});
|
|
930
|
+
});
|
|
931
|
+
const blockContext = {
|
|
932
|
+
pslBlockDescriptors,
|
|
933
|
+
symbolTable,
|
|
934
|
+
dataTypes,
|
|
935
|
+
sources,
|
|
936
|
+
references,
|
|
937
|
+
diagnostics
|
|
938
|
+
};
|
|
939
|
+
const bindBlocks = (records) => {
|
|
940
|
+
const context = {
|
|
941
|
+
...blockContext,
|
|
942
|
+
scope: stack.current()
|
|
943
|
+
};
|
|
944
|
+
for (const block of Object.values(records.blocks)) bindBlock({
|
|
945
|
+
keyword: block.keyword,
|
|
946
|
+
entries: block.entries.filter((entry) => isWrittenIn(entry.syntax, block)),
|
|
947
|
+
attributes: ownAttributes(block)
|
|
948
|
+
}, context);
|
|
949
|
+
for (const mixin of Object.values(records.mixins)) if (!hasFields(mixin)) bindBlock(mixin, context);
|
|
950
|
+
};
|
|
951
|
+
for (const namespace of Object.values(symbolTable.namespaces)) {
|
|
952
|
+
const [declaration] = namespace.declarations;
|
|
953
|
+
if (declaration !== void 0) stack.push(binder.scopeAt(declaration.node.syntax));
|
|
954
|
+
bindBlocks(namespace);
|
|
955
|
+
if (declaration !== void 0) stack.pop();
|
|
956
|
+
}
|
|
957
|
+
return {
|
|
958
|
+
binder,
|
|
959
|
+
diagnostics
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
function bindInclusions(records, scope, ctx) {
|
|
963
|
+
const report = (code, message, inclusion) => {
|
|
964
|
+
ctx.diagnostics.push({
|
|
965
|
+
code,
|
|
966
|
+
message,
|
|
967
|
+
...diagnosticSource(ctx.sources, inclusion.syntax).at()
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
for (const mixin of Object.values(records.mixins)) for (const inclusion of mixin.node.inclusions()) {
|
|
971
|
+
if (inclusion.name() === void 0) continue;
|
|
972
|
+
report(hasFields(mixin) ? "PSL_INVALID_MODEL_MEMBER" : "PSL_INVALID_EXTENSION_BLOCK_MEMBER", "A mixin cannot include another mixin", inclusion);
|
|
973
|
+
}
|
|
974
|
+
const holders = [
|
|
975
|
+
...Object.values(records.models),
|
|
976
|
+
...Object.values(records.compositeTypes),
|
|
977
|
+
...Object.values(records.blocks)
|
|
978
|
+
];
|
|
979
|
+
for (const holder of holders) {
|
|
980
|
+
const keyword = holder.kind === "model" ? "model" : holder.kind === "compositeType" ? "type" : holder.keyword;
|
|
981
|
+
for (const inclusion of holder.node.inclusions()) {
|
|
982
|
+
const reference = inclusion.name();
|
|
983
|
+
const outcome = resolveTypeReference(reference, scope, ctx.references);
|
|
984
|
+
if (reference === void 0 || outcome === void 0) continue;
|
|
985
|
+
const { resolution } = outcome;
|
|
986
|
+
if (resolution.kind !== "mixin") {
|
|
987
|
+
const name = printSyntax(reference.syntax);
|
|
988
|
+
ctx.references.set(reference.syntax, {
|
|
989
|
+
kind: "unresolved",
|
|
990
|
+
name
|
|
991
|
+
});
|
|
992
|
+
report(PSL_UNRESOLVED_REFERENCE, `Cannot find mixin "${name}"`, inclusion);
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
ctx.references.set(reference.syntax, resolution);
|
|
996
|
+
const mixin = resolution.symbol;
|
|
997
|
+
if (mixin.keyword === keyword) {
|
|
998
|
+
ctx.included.set(inclusion.syntax, mixin);
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
report(holder.kind === "block" ? "PSL_INVALID_EXTENSION_BLOCK_MEMBER" : "PSL_INVALID_MODEL_MEMBER", `Mixin "${mixin.name}" is for "${mixin.keyword}" blocks, not "${keyword}" blocks`, inclusion);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
function bindBlock(block, ctx) {
|
|
1006
|
+
const descriptor = findBlockDescriptor(ctx.pslBlockDescriptors, block.keyword);
|
|
1007
|
+
if (descriptor === void 0) return;
|
|
1008
|
+
const specContext = blockSpecContext({
|
|
1009
|
+
symbols: ctx.symbolTable,
|
|
1010
|
+
dataTypes: ctx.dataTypes
|
|
1011
|
+
});
|
|
1012
|
+
const spec = blockSpecFactoryOf(descriptor)(specContext);
|
|
1013
|
+
for (const entry of block.entries) {
|
|
1014
|
+
const key = entry.key()?.name();
|
|
1015
|
+
if (key === void 0) continue;
|
|
1016
|
+
const parameter = spec.mode === "struct" && Object.hasOwn(spec.parameters, key) ? spec.parameters[key] : void 0;
|
|
1017
|
+
const rule = spec.mode === "struct" ? parameter?.type : spec.value.type;
|
|
1018
|
+
if (parameter !== void 0) {
|
|
1019
|
+
const keyNode = entry.key()?.syntax;
|
|
1020
|
+
if (keyNode !== void 0) ctx.references.set(keyNode, {
|
|
1021
|
+
kind: "parameter",
|
|
1022
|
+
symbol: {
|
|
1023
|
+
kind: "parameter",
|
|
1024
|
+
name: key,
|
|
1025
|
+
param: parameter
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
const value = entry.value();
|
|
1030
|
+
if (rule === void 0 || value === void 0) continue;
|
|
1031
|
+
bindExpression(rule, value, ctx);
|
|
1032
|
+
}
|
|
1033
|
+
const attributeSpecs = descriptor.attributes ?? {};
|
|
1034
|
+
if (Object.keys(attributeSpecs).length === 0) return;
|
|
1035
|
+
for (const attribute of block.attributes) {
|
|
1036
|
+
const factory = attributeSpecs[attribute.name];
|
|
1037
|
+
if (factory === void 0) continue;
|
|
1038
|
+
const attributeSpec = blindCast(factory)(specContext);
|
|
1039
|
+
const attributeSymbol = {
|
|
1040
|
+
kind: "attribute",
|
|
1041
|
+
name: attribute.name,
|
|
1042
|
+
level: "block",
|
|
1043
|
+
spec: attributeSpec
|
|
1044
|
+
};
|
|
1045
|
+
const nameNode = attribute.node.name()?.syntax;
|
|
1046
|
+
if (nameNode !== void 0) ctx.references.set(nameNode, {
|
|
1047
|
+
kind: "attribute",
|
|
1048
|
+
symbol: attributeSymbol
|
|
1049
|
+
});
|
|
1050
|
+
bindArguments(attribute, attributeSpec, ctx);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
function bindExpression(rule, expression, ctx, modelContext) {
|
|
1054
|
+
const trial = tryBindExpression(rule, expression, ctx, modelContext);
|
|
1055
|
+
for (const [node, resolution] of trial.references) ctx.references.set(node, resolution);
|
|
1056
|
+
ctx.diagnostics.push(...trial.diagnostics.values());
|
|
1057
|
+
}
|
|
1058
|
+
function tryBindExpression(rule, expression, ctx, modelContext) {
|
|
1059
|
+
const references = /* @__PURE__ */ new Map();
|
|
1060
|
+
const diagnostics = /* @__PURE__ */ new Map();
|
|
1061
|
+
switch (rule.kind) {
|
|
1062
|
+
case "oneOf":
|
|
1063
|
+
for (const alternative of rule.alternatives) {
|
|
1064
|
+
const trial = tryBindExpression(alternative, expression, ctx, modelContext);
|
|
1065
|
+
if (trial.matched) return trial;
|
|
1066
|
+
for (const [node, diagnostic] of trial.diagnostics) diagnostics.set(node, diagnostic);
|
|
1067
|
+
for (const [node, resolution] of trial.references) if (resolution.kind === "unresolved") references.set(node, resolution);
|
|
1068
|
+
}
|
|
1069
|
+
return {
|
|
1070
|
+
matched: false,
|
|
1071
|
+
references,
|
|
1072
|
+
diagnostics
|
|
1073
|
+
};
|
|
1074
|
+
case "list":
|
|
1075
|
+
case "record": {
|
|
1076
|
+
const children = rule.kind === "list" ? ArrayLiteralAst.cast(expression.syntax)?.elements() : recordValues(expression);
|
|
1077
|
+
if (children === void 0) return {
|
|
1078
|
+
matched: false,
|
|
1079
|
+
references,
|
|
1080
|
+
diagnostics
|
|
1081
|
+
};
|
|
1082
|
+
let matched = true;
|
|
1083
|
+
for (const child of children) {
|
|
1084
|
+
const trial = tryBindExpression(rule.of, child, ctx, modelContext);
|
|
1085
|
+
matched = trial.matched && matched;
|
|
1086
|
+
for (const [node, resolution] of trial.references) references.set(node, resolution);
|
|
1087
|
+
for (const [node, diagnostic] of trial.diagnostics) diagnostics.set(node, diagnostic);
|
|
1088
|
+
}
|
|
1089
|
+
return {
|
|
1090
|
+
matched,
|
|
1091
|
+
references,
|
|
1092
|
+
diagnostics
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
case "funcCall": {
|
|
1096
|
+
const call = FunctionCallAst.cast(expression.syntax);
|
|
1097
|
+
const name = call?.name();
|
|
1098
|
+
if (call === void 0 || name === void 0 || name.dot() !== void 0 || name.colon() !== void 0 || name.identifier()?.name() !== rule.name) return {
|
|
1099
|
+
matched: false,
|
|
1100
|
+
references,
|
|
1101
|
+
diagnostics
|
|
1102
|
+
};
|
|
1103
|
+
const functionSymbol = {
|
|
1104
|
+
kind: "function",
|
|
1105
|
+
name: rule.name,
|
|
1106
|
+
signature: rule.signature
|
|
1107
|
+
};
|
|
1108
|
+
references.set(name.syntax, {
|
|
1109
|
+
kind: "function",
|
|
1110
|
+
symbol: functionSymbol
|
|
1111
|
+
});
|
|
1112
|
+
let matched = true;
|
|
1113
|
+
let positional = 0;
|
|
1114
|
+
for (const arg of call.args()) {
|
|
1115
|
+
const key = arg.name()?.name();
|
|
1116
|
+
const parameter = argumentParameter(rule.signature, key, key === void 0 ? positional++ : positional);
|
|
1117
|
+
if (parameter === void 0) {
|
|
1118
|
+
matched = false;
|
|
1119
|
+
continue;
|
|
1120
|
+
}
|
|
1121
|
+
if (key !== void 0) {
|
|
1122
|
+
const keyNode = arg.name()?.syntax;
|
|
1123
|
+
if (keyNode !== void 0) references.set(keyNode, {
|
|
1124
|
+
kind: "parameter",
|
|
1125
|
+
symbol: {
|
|
1126
|
+
kind: "parameter",
|
|
1127
|
+
name: key,
|
|
1128
|
+
param: parameter
|
|
1129
|
+
}
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
const value = arg.value();
|
|
1133
|
+
if (value === void 0) {
|
|
1134
|
+
matched = false;
|
|
1135
|
+
continue;
|
|
1136
|
+
}
|
|
1137
|
+
const trial = tryBindExpression(parameter.type, value, ctx, modelContext);
|
|
1138
|
+
matched = trial.matched && matched;
|
|
1139
|
+
for (const [node, resolution] of trial.references) references.set(node, resolution);
|
|
1140
|
+
for (const [node, diagnostic] of trial.diagnostics) diagnostics.set(node, diagnostic);
|
|
1141
|
+
}
|
|
1142
|
+
return {
|
|
1143
|
+
matched,
|
|
1144
|
+
references,
|
|
1145
|
+
diagnostics
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
case "identifier": {
|
|
1149
|
+
if (rule.name === void 0) return {
|
|
1150
|
+
matched: true,
|
|
1151
|
+
references,
|
|
1152
|
+
diagnostics
|
|
1153
|
+
};
|
|
1154
|
+
const node = expression.syntax;
|
|
1155
|
+
if (IdentifierAst.cast(node)?.name() !== rule.name) return {
|
|
1156
|
+
matched: false,
|
|
1157
|
+
references,
|
|
1158
|
+
diagnostics
|
|
1159
|
+
};
|
|
1160
|
+
references.set(node, {
|
|
1161
|
+
kind: "constant",
|
|
1162
|
+
symbol: {
|
|
1163
|
+
kind: "constant",
|
|
1164
|
+
name: rule.name,
|
|
1165
|
+
documentation: rule.documentation
|
|
1166
|
+
}
|
|
1167
|
+
});
|
|
1168
|
+
return {
|
|
1169
|
+
matched: true,
|
|
1170
|
+
references,
|
|
1171
|
+
diagnostics
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
case "entityRef": {
|
|
1175
|
+
const node = expression.syntax;
|
|
1176
|
+
const written = writtenEntityReference(node);
|
|
1177
|
+
if (written === void 0) return {
|
|
1178
|
+
matched: false,
|
|
1179
|
+
references,
|
|
1180
|
+
diagnostics
|
|
1181
|
+
};
|
|
1182
|
+
const failures = [];
|
|
1183
|
+
const resolution = resolveEntity(written, node, {
|
|
1184
|
+
...ctx,
|
|
1185
|
+
diagnostics: failures
|
|
1186
|
+
});
|
|
1187
|
+
references.set(node, resolution);
|
|
1188
|
+
for (const diagnostic of failures) diagnostics.set(node, diagnostic);
|
|
1189
|
+
return {
|
|
1190
|
+
matched: resolution.kind !== "unresolved",
|
|
1191
|
+
references,
|
|
1192
|
+
diagnostics
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
case "fieldRef": {
|
|
1196
|
+
const node = expression.syntax;
|
|
1197
|
+
const name = IdentifierAst.cast(node)?.name();
|
|
1198
|
+
if (name === void 0 || modelContext === void 0) return {
|
|
1199
|
+
matched: false,
|
|
1200
|
+
references,
|
|
1201
|
+
diagnostics
|
|
1202
|
+
};
|
|
1203
|
+
const failures = [];
|
|
1204
|
+
const resolution = resolveOwnerField(name, node, {
|
|
1205
|
+
...modelContext,
|
|
1206
|
+
diagnostics: failures
|
|
1207
|
+
});
|
|
1208
|
+
references.set(node, resolution);
|
|
1209
|
+
for (const diagnostic of failures) diagnostics.set(node, diagnostic);
|
|
1210
|
+
return {
|
|
1211
|
+
matched: resolution.kind !== "unresolved",
|
|
1212
|
+
references,
|
|
1213
|
+
diagnostics
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
case "referencedFieldRef": {
|
|
1217
|
+
const node = expression.syntax;
|
|
1218
|
+
const name = IdentifierAst.cast(node)?.name();
|
|
1219
|
+
if (name === void 0 || modelContext === void 0) return {
|
|
1220
|
+
matched: false,
|
|
1221
|
+
references,
|
|
1222
|
+
diagnostics
|
|
1223
|
+
};
|
|
1224
|
+
const failures = [];
|
|
1225
|
+
const resolution = resolveReferencedField(name, node, {
|
|
1226
|
+
...modelContext,
|
|
1227
|
+
diagnostics: failures
|
|
1228
|
+
});
|
|
1229
|
+
references.set(node, resolution);
|
|
1230
|
+
for (const diagnostic of failures) diagnostics.set(node, diagnostic);
|
|
1231
|
+
return {
|
|
1232
|
+
matched: resolution.kind !== "unresolved",
|
|
1233
|
+
references,
|
|
1234
|
+
diagnostics
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
case "str":
|
|
1238
|
+
case "json": return {
|
|
1239
|
+
matched: StringLiteralExprAst.cast(expression.syntax) !== void 0,
|
|
1240
|
+
references,
|
|
1241
|
+
diagnostics
|
|
1242
|
+
};
|
|
1243
|
+
case "num":
|
|
1244
|
+
case "int": return {
|
|
1245
|
+
matched: NumberLiteralExprAst.cast(expression.syntax) !== void 0,
|
|
1246
|
+
references,
|
|
1247
|
+
diagnostics
|
|
1248
|
+
};
|
|
1249
|
+
case "bool": return {
|
|
1250
|
+
matched: BooleanLiteralExprAst.cast(expression.syntax) !== void 0,
|
|
1251
|
+
references,
|
|
1252
|
+
diagnostics
|
|
1253
|
+
};
|
|
1254
|
+
case "null": return {
|
|
1255
|
+
matched: IdentifierAst.cast(expression.syntax)?.name() === "null",
|
|
1256
|
+
references,
|
|
1257
|
+
diagnostics
|
|
1258
|
+
};
|
|
1259
|
+
case "taggedLiteral": return {
|
|
1260
|
+
matched: TaggedLiteralExprAst.cast(expression.syntax) !== void 0,
|
|
1261
|
+
references,
|
|
1262
|
+
diagnostics
|
|
1263
|
+
};
|
|
1264
|
+
case "dataTypeValue": {
|
|
1265
|
+
const literal = readWrittenScalar(expression);
|
|
1266
|
+
return {
|
|
1267
|
+
matched: literal.ok || literal.reason !== "not-a-literal",
|
|
1268
|
+
references,
|
|
1269
|
+
diagnostics
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
case "rejecting": return {
|
|
1273
|
+
matched: false,
|
|
1274
|
+
references,
|
|
1275
|
+
diagnostics
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
function recordValues(expression) {
|
|
1280
|
+
const record = ObjectLiteralExprAst.cast(expression.syntax);
|
|
1281
|
+
if (record === void 0) return void 0;
|
|
1282
|
+
return (function* () {
|
|
1283
|
+
for (const field of record.fields()) {
|
|
1284
|
+
const value = field.value();
|
|
1285
|
+
if (value !== void 0) yield value;
|
|
1286
|
+
}
|
|
1287
|
+
})();
|
|
1288
|
+
}
|
|
1289
|
+
function bindAttributes(holder, attributes, specs, instantiate, ctx) {
|
|
1290
|
+
const level = holder.kind === "field" ? "field" : "model";
|
|
1291
|
+
attributes.forEach((attribute) => {
|
|
1292
|
+
const factory = own(specs, attribute.name);
|
|
1293
|
+
if (factory === void 0) {
|
|
1294
|
+
const diagnostic = ctx.describeUnsupportedAttribute?.({
|
|
1295
|
+
attribute,
|
|
1296
|
+
level,
|
|
1297
|
+
owner: ctx.owner,
|
|
1298
|
+
field: level === "field" ? ctx.field : void 0
|
|
1299
|
+
});
|
|
1300
|
+
if (diagnostic !== void 0) ctx.diagnostics.push(diagnostic);
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
const spec = instantiate(factory);
|
|
1304
|
+
if (spec === void 0) return;
|
|
1305
|
+
const attributeSymbol = {
|
|
1306
|
+
kind: "attribute",
|
|
1307
|
+
name: attribute.name,
|
|
1308
|
+
level,
|
|
1309
|
+
spec
|
|
1310
|
+
};
|
|
1311
|
+
const nameNode = attribute.node.name()?.syntax;
|
|
1312
|
+
if (nameNode !== void 0) ctx.references.set(nameNode, {
|
|
1313
|
+
kind: "attribute",
|
|
1314
|
+
symbol: attributeSymbol
|
|
1315
|
+
});
|
|
1316
|
+
bindArguments(attribute, spec, ctx, ctx);
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
function bindArguments(attribute, spec, ctx, modelContext) {
|
|
1320
|
+
const rawArgs = Array.from(attribute.node.argList()?.args() ?? []);
|
|
1321
|
+
let positional = 0;
|
|
1322
|
+
attribute.args.forEach((arg, index) => {
|
|
1323
|
+
const parameter = argumentParameter(spec, arg.name, arg.name === void 0 ? positional++ : positional);
|
|
1324
|
+
if (parameter === void 0) return;
|
|
1325
|
+
if (arg.name !== void 0) {
|
|
1326
|
+
const keyNode = rawArgs[index]?.name()?.syntax;
|
|
1327
|
+
if (keyNode !== void 0) ctx.references.set(keyNode, {
|
|
1328
|
+
kind: "parameter",
|
|
1329
|
+
symbol: {
|
|
1330
|
+
kind: "parameter",
|
|
1331
|
+
name: arg.name,
|
|
1332
|
+
param: parameter
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
if (arg.expression === void 0) return;
|
|
1337
|
+
bindExpression(parameter.type, arg.expression, ctx, modelContext);
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
function argumentParameter(spec, name, position) {
|
|
1341
|
+
if (name === void 0) return spec.positional?.[position];
|
|
1342
|
+
return spec.named === void 0 ? void 0 : own(spec.named, name);
|
|
1343
|
+
}
|
|
1344
|
+
function resolveOwnerField(name, node, ctx) {
|
|
1345
|
+
const field = ctx.owner.fields[name];
|
|
1346
|
+
if (field !== void 0) return {
|
|
1347
|
+
kind: "field",
|
|
1348
|
+
symbol: field
|
|
1349
|
+
};
|
|
1350
|
+
report(`Cannot find field "${name}" on "${ctx.owner.name}"`, node, ctx, "field");
|
|
16
1351
|
return {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
span: nodePslSpan(attribute.syntax, sourceFile)
|
|
1352
|
+
kind: "unresolved",
|
|
1353
|
+
name
|
|
20
1354
|
};
|
|
21
1355
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1356
|
+
function resolveReferencedField(name, node, ctx) {
|
|
1357
|
+
const declaring = ctx.field;
|
|
1358
|
+
if (declaring === void 0) return {
|
|
1359
|
+
kind: "unresolved",
|
|
1360
|
+
name
|
|
1361
|
+
};
|
|
1362
|
+
if (declaring.typeContractSpaceId !== void 0) return { kind: "crossSpace" };
|
|
1363
|
+
const typeNode = typeReferenceNode(declaring);
|
|
1364
|
+
const field = targetFields(typeNode === void 0 ? void 0 : ctx.references.get(typeNode))?.[name];
|
|
1365
|
+
if (field !== void 0) return {
|
|
1366
|
+
kind: "field",
|
|
1367
|
+
symbol: field
|
|
1368
|
+
};
|
|
1369
|
+
report(`Cannot find field "${name}" on the type of "${ctx.owner.name}.${declaring.name}"`, node, ctx, "field");
|
|
28
1370
|
return {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
span: nodePslSpan(annotation.syntax, sourceFile)
|
|
1371
|
+
kind: "unresolved",
|
|
1372
|
+
name
|
|
32
1373
|
};
|
|
33
1374
|
}
|
|
34
|
-
function
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1375
|
+
function targetFields(target) {
|
|
1376
|
+
if (target === void 0) return void 0;
|
|
1377
|
+
if (target.kind === "model" || target.kind === "compositeType") return target.symbol.fields;
|
|
1378
|
+
}
|
|
1379
|
+
function bindEntityConstructorArgument(symbol, type, ctx) {
|
|
1380
|
+
if (type.kind !== "contributedType") return;
|
|
1381
|
+
const descriptor = type.symbol.descriptor;
|
|
1382
|
+
const index = descriptor.kind === "typeConstructor" ? descriptor.entityRefArg?.index : void 0;
|
|
1383
|
+
if (index === void 0) return;
|
|
1384
|
+
const node = (symbol.typeConstructor?.args.filter((arg) => arg.kind === "positional"))?.[index]?.expression?.syntax;
|
|
1385
|
+
const written = node === void 0 ? void 0 : writtenEntityReference(node);
|
|
1386
|
+
if (node === void 0 || written === void 0) return;
|
|
1387
|
+
ctx.references.set(node, resolveEntity(written, node, ctx));
|
|
1388
|
+
}
|
|
1389
|
+
function resolveEntity(written, node, ctx) {
|
|
1390
|
+
const found = written.namespace === void 0 ? ctx.scope.lookup(written.name) : qualifiedMember(written.namespace, written.name, bindQualifier(entityQualifier(node), ctx.scope, ctx.references));
|
|
1391
|
+
if (found === void 0) {
|
|
1392
|
+
const name = describeWrittenEntityReference(written);
|
|
1393
|
+
if (written.name !== "") report(`Cannot find entity "${name}"`, node, ctx, "entity");
|
|
1394
|
+
return {
|
|
1395
|
+
kind: "unresolved",
|
|
1396
|
+
name
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
if ("badQualifier" in found) {
|
|
1400
|
+
report(found.badQualifier, node, ctx, "entity");
|
|
1401
|
+
return {
|
|
1402
|
+
kind: "unresolved",
|
|
1403
|
+
name: found.qualifier
|
|
1404
|
+
};
|
|
47
1405
|
}
|
|
48
|
-
return
|
|
1406
|
+
return found;
|
|
49
1407
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
1408
|
+
function report(message, node, ctx, reference) {
|
|
1409
|
+
ctx.diagnostics.push({
|
|
1410
|
+
code: PSL_UNRESOLVED_REFERENCE,
|
|
1411
|
+
message,
|
|
1412
|
+
data: { reference },
|
|
1413
|
+
...diagnosticSource(ctx.sources, node).at()
|
|
1414
|
+
});
|
|
52
1415
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
1416
|
+
function entityQualifier(node) {
|
|
1417
|
+
const path = PathExprAst.cast(node);
|
|
1418
|
+
if (path === void 0) return void 0;
|
|
1419
|
+
const [qualifier] = path.segments();
|
|
1420
|
+
return qualifier;
|
|
56
1421
|
}
|
|
57
|
-
function
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
1422
|
+
function bindQualifier(qualifier, scope, references) {
|
|
1423
|
+
const id = qualifier?.name();
|
|
1424
|
+
if (qualifier === void 0 || id === void 0) return void 0;
|
|
1425
|
+
const resolution = scope.lookup(id);
|
|
1426
|
+
if (resolution !== void 0 && isNamespaceLike(resolution)) references.set(qualifier.syntax, resolution);
|
|
1427
|
+
return resolution;
|
|
64
1428
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
1429
|
+
function resolveTypeReference(reference, scope, references, describeUnresolved) {
|
|
1430
|
+
if (reference === void 0 || reference.isOverQualified()) return void 0;
|
|
1431
|
+
if (reference.space() !== void 0) return { resolution: { kind: "crossSpace" } };
|
|
1432
|
+
const name = reference.identifier()?.name();
|
|
1433
|
+
if (name === void 0 || name === "") return void 0;
|
|
1434
|
+
const qualifier = reference.namespace();
|
|
1435
|
+
const namespaceId = qualifier?.name();
|
|
1436
|
+
const found = namespaceId === void 0 ? scope.lookup(name) : qualifiedMember(namespaceId, name, bindQualifier(qualifier, scope, references));
|
|
1437
|
+
if (found === void 0) {
|
|
1438
|
+
const written = namespaceId === void 0 ? name : `${namespaceId}.${name}`;
|
|
1439
|
+
const message = describeUnresolved?.(written) ?? `Cannot find type "${written}"`;
|
|
1440
|
+
return {
|
|
1441
|
+
resolution: {
|
|
1442
|
+
kind: "unresolved",
|
|
1443
|
+
name: written
|
|
1444
|
+
},
|
|
1445
|
+
message,
|
|
1446
|
+
name: written
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
if ("badQualifier" in found) return {
|
|
1450
|
+
resolution: {
|
|
1451
|
+
kind: "unresolved",
|
|
1452
|
+
name: found.qualifier
|
|
1453
|
+
},
|
|
1454
|
+
message: found.badQualifier,
|
|
1455
|
+
name: found.qualifier
|
|
72
1456
|
};
|
|
1457
|
+
if (found.kind === "namespace" || found.kind === "contributedNamespace" || found.kind === "mixin") {
|
|
1458
|
+
const written = namespaceId === void 0 ? name : `${namespaceId}.${name}`;
|
|
1459
|
+
return {
|
|
1460
|
+
resolution: found,
|
|
1461
|
+
message: `"${written}" is a ${found.kind === "mixin" ? "mixin" : "namespace"}; a type reference must name a model, composite type, enum, or type alias`,
|
|
1462
|
+
name: written
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
return { resolution: found };
|
|
73
1466
|
}
|
|
74
|
-
function
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
1467
|
+
function qualifiedMember(namespaceId, name, qualifier) {
|
|
1468
|
+
if (qualifier === void 0) return void 0;
|
|
1469
|
+
if (!isNamespaceLike(qualifier)) return {
|
|
1470
|
+
badQualifier: `"${namespaceId}" is ${describeQualifier(qualifier)}, not a namespace`,
|
|
1471
|
+
qualifier: namespaceId
|
|
78
1472
|
};
|
|
1473
|
+
return lookupMember(qualifier, name);
|
|
1474
|
+
}
|
|
1475
|
+
function describeQualifier(resolution) {
|
|
1476
|
+
switch (resolution.kind) {
|
|
1477
|
+
case "model": return "a model";
|
|
1478
|
+
case "compositeType": return "a composite type";
|
|
1479
|
+
case "namedType": return "a type alias";
|
|
1480
|
+
case "block": return `${resolution.symbol.keyword === "enum" ? "an" : "a"} ${resolution.symbol.keyword}`;
|
|
1481
|
+
default: return "a scalar type";
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
function own(record, name) {
|
|
1485
|
+
return Object.hasOwn(record, name) ? record[name] : void 0;
|
|
1486
|
+
}
|
|
1487
|
+
//#endregion
|
|
1488
|
+
//#region ../../../1-framework/2-authoring/psl-parser/dist/index.mjs
|
|
1489
|
+
function getPositionalArgument(attribute, index = 0) {
|
|
1490
|
+
return attribute.args.filter((arg) => arg.kind === "positional")[index]?.value;
|
|
1491
|
+
}
|
|
1492
|
+
function parseQuotedStringLiteral(value) {
|
|
1493
|
+
const match = value.trim().match(/^(['"])(.*)\1$/);
|
|
1494
|
+
if (!match) return void 0;
|
|
1495
|
+
return match[2] ?? "";
|
|
79
1496
|
}
|
|
80
|
-
function
|
|
81
|
-
const position = sourceFile.positionAt(offset);
|
|
1497
|
+
function blockAttribute(name, config) {
|
|
82
1498
|
return {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1499
|
+
level: "block",
|
|
1500
|
+
name,
|
|
1501
|
+
documentation: config.documentation,
|
|
1502
|
+
positional: config.positional ?? [],
|
|
1503
|
+
named: config.named ?? {},
|
|
1504
|
+
...config.refine !== void 0 ? { refine: config.refine } : {}
|
|
86
1505
|
};
|
|
87
1506
|
}
|
|
88
1507
|
const ATTRIBUTE_DIAGNOSTIC_CODE = "PSL_INVALID_ATTRIBUTE_SYNTAX";
|
|
@@ -90,8 +1509,7 @@ function leafDiagnostic(ctx, node, message, code = ATTRIBUTE_DIAGNOSTIC_CODE) {
|
|
|
90
1509
|
return {
|
|
91
1510
|
code,
|
|
92
1511
|
message,
|
|
93
|
-
|
|
94
|
-
span: nodePslSpan(node.syntax, ctx.sourceFile)
|
|
1512
|
+
...diagnosticSource(ctx.sources, node.syntax).at(nodePslSpan(node.syntax, ctx.sources))
|
|
95
1513
|
};
|
|
96
1514
|
}
|
|
97
1515
|
function bool() {
|
|
@@ -99,43 +1517,254 @@ function bool() {
|
|
|
99
1517
|
kind: "bool",
|
|
100
1518
|
label: "boolean",
|
|
101
1519
|
parse: (arg, ctx) => {
|
|
102
|
-
|
|
103
|
-
|
|
1520
|
+
const literal = BooleanLiteralExprAst.cast(arg.syntax);
|
|
1521
|
+
if (literal !== void 0) {
|
|
1522
|
+
const value = literal.value();
|
|
104
1523
|
if (value !== void 0) return ok(value);
|
|
105
1524
|
}
|
|
106
1525
|
return notOk([leafDiagnostic(ctx, arg, "Expected a boolean literal")]);
|
|
107
1526
|
}
|
|
108
1527
|
};
|
|
109
1528
|
}
|
|
110
|
-
|
|
1529
|
+
/** An argument typed by a data type: any literal, admitted by the ADR 254 cast rule. Used as a parameter of an attribute, a block or a `funcCall`; `oneOf` refuses it as an arm. ADR 231, ADR 254, ADR 268. */
|
|
1530
|
+
function dataTypeValue(dataType, support, options = {}) {
|
|
1531
|
+
const tags = admittedTags(support, dataType);
|
|
1532
|
+
const [firstTag] = tags;
|
|
1533
|
+
return {
|
|
1534
|
+
kind: "dataTypeValue",
|
|
1535
|
+
label: options.label ?? (firstTag === void 0 ? describeAdmittedForms(support, dataType) : tagForm(firstTag).phrase),
|
|
1536
|
+
dataType,
|
|
1537
|
+
tags,
|
|
1538
|
+
documentation: support.entries[dataType]?.documentation ?? "",
|
|
1539
|
+
suggestions: options.suggestions ?? [],
|
|
1540
|
+
parse: (arg, ctx) => parseDataTypeValue(arg, ctx, dataType, support)
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
function parseDataTypeValue(arg, ctx, dataType, support) {
|
|
1544
|
+
const read = readExpressionAs(support, dataType, arg);
|
|
1545
|
+
if (!read.ok) return notOk([leafDiagnostic(ctx, arg, read.failure.message, read.failure.code)]);
|
|
1546
|
+
return ok({
|
|
1547
|
+
value: read.value,
|
|
1548
|
+
span: nodePslSpan(arg.syntax, ctx.sources)
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
function entityRef(expected) {
|
|
1552
|
+
const label = `${expected.kind === "block" ? expected.keyword : expected.kind} reference`;
|
|
111
1553
|
return {
|
|
112
1554
|
kind: "entityRef",
|
|
113
|
-
label
|
|
1555
|
+
label,
|
|
1556
|
+
expected,
|
|
114
1557
|
parse: (arg, ctx) => {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
1558
|
+
const written = writtenEntityReference(arg.syntax);
|
|
1559
|
+
if (written === void 0) return notOk([leafDiagnostic(ctx, arg, `Expected ${label}`)]);
|
|
1560
|
+
const name = describeWrittenEntityReference(written);
|
|
1561
|
+
const resolution = ctx.binder.symbolForNode(arg.syntax);
|
|
1562
|
+
if (resolution === void 0 || resolution.kind === "unresolved") return notOk([]);
|
|
1563
|
+
const reference = entityReference(resolution);
|
|
1564
|
+
if (reference === void 0 || !matchesSelector(reference, expected)) return notOk([leafDiagnostic(ctx, arg, `Expected ${label} "${name}", found ${describeResolution(resolution)}`)]);
|
|
1565
|
+
return ok(reference);
|
|
119
1566
|
}
|
|
120
1567
|
};
|
|
121
1568
|
}
|
|
122
|
-
function
|
|
1569
|
+
function list(of, opts) {
|
|
1570
|
+
const allowEmpty = opts?.allowEmpty ?? true;
|
|
1571
|
+
const unique = opts?.unique ?? false;
|
|
123
1572
|
return {
|
|
124
|
-
kind: "
|
|
125
|
-
label: "
|
|
126
|
-
|
|
1573
|
+
kind: "list",
|
|
1574
|
+
label: opts?.label ?? (of.label.includes(" | ") ? `(${of.label})[]` : `${of.label}[]`),
|
|
1575
|
+
of,
|
|
1576
|
+
allowEmpty,
|
|
1577
|
+
unique,
|
|
1578
|
+
parse: (arg, ctx) => {
|
|
1579
|
+
const literal = ArrayLiteralAst.cast(arg.syntax);
|
|
1580
|
+
if (literal === void 0) return notOk([leafDiagnostic(ctx, arg, `Expected a list of ${of.label}`)]);
|
|
1581
|
+
const parsed = [];
|
|
1582
|
+
let outcome = okVoid();
|
|
1583
|
+
let count = 0;
|
|
1584
|
+
for (const element of literal.elements()) {
|
|
1585
|
+
count += 1;
|
|
1586
|
+
const result = of.parse(element, ctx);
|
|
1587
|
+
if (result.ok) parsed.push({
|
|
1588
|
+
node: element,
|
|
1589
|
+
value: result.value
|
|
1590
|
+
});
|
|
1591
|
+
outcome = and(outcome, result);
|
|
1592
|
+
}
|
|
1593
|
+
if (!allowEmpty && count === 0) outcome = and(outcome, notOk([leafDiagnostic(ctx, arg, "Expected a non-empty list")]));
|
|
1594
|
+
if (unique) {
|
|
1595
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1596
|
+
for (const { node, value } of parsed) if (seen.has(value)) outcome = and(outcome, notOk([leafDiagnostic(ctx, node, "Duplicate list entry")]));
|
|
1597
|
+
else seen.add(value);
|
|
1598
|
+
}
|
|
1599
|
+
if (!outcome.ok) return notOk(outcome.failure);
|
|
1600
|
+
return ok(parsed.map((entry) => entry.value));
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
function num(value) {
|
|
1605
|
+
if (value === void 0) return {
|
|
1606
|
+
kind: "num",
|
|
1607
|
+
label: "number",
|
|
1608
|
+
value: void 0,
|
|
1609
|
+
parse: (arg, ctx) => {
|
|
1610
|
+
const literal = NumberLiteralExprAst.cast(arg.syntax);
|
|
1611
|
+
if (literal !== void 0) {
|
|
1612
|
+
const parsed = literal.value();
|
|
1613
|
+
if (parsed !== void 0) return ok(parsed);
|
|
1614
|
+
}
|
|
1615
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected a number literal")]);
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
return {
|
|
1619
|
+
kind: "num",
|
|
1620
|
+
label: String(value),
|
|
1621
|
+
value,
|
|
127
1622
|
parse: (arg, ctx) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return ok(name);
|
|
1623
|
+
const literal = NumberLiteralExprAst.cast(arg.syntax);
|
|
1624
|
+
if (literal !== void 0) {
|
|
1625
|
+
if (literal.value() === value) return ok(value);
|
|
1626
|
+
}
|
|
1627
|
+
return notOk([leafDiagnostic(ctx, arg, `Expected ${value}`)]);
|
|
134
1628
|
}
|
|
135
1629
|
};
|
|
136
1630
|
}
|
|
137
|
-
|
|
138
|
-
|
|
1631
|
+
/**
|
|
1632
|
+
* The first alternative that accepts the argument. When exactly one alternative claims the argument's shape, its result, success or failure, so its diagnostics about the argument are kept.
|
|
1633
|
+
*/
|
|
1634
|
+
function oneOf(...alts) {
|
|
1635
|
+
for (const alt of alts) if (alt.kind === "dataTypeValue") throw new InternalError(`oneOf was given an arm typed by data type "${alt.dataType}" (${alt.label}). A value of a data type is a parameter of an attribute, a block or a function call, never an arm of oneOf.`);
|
|
1636
|
+
const label = alts.map((alt) => alt.label).join(" | ");
|
|
1637
|
+
return {
|
|
1638
|
+
kind: "oneOf",
|
|
1639
|
+
label,
|
|
1640
|
+
alternatives: alts,
|
|
1641
|
+
parse: (arg, ctx) => {
|
|
1642
|
+
const [head, ...tail] = blindCast(alts);
|
|
1643
|
+
const claiming = [head, ...tail].filter((alt) => alt.claims?.(arg) === true);
|
|
1644
|
+
const [only] = claiming;
|
|
1645
|
+
if (only !== void 0 && claiming.length === 1) return only.parse(arg, ctx);
|
|
1646
|
+
let rejection = head.parse(arg, ctx);
|
|
1647
|
+
if (rejection.ok) return rejection;
|
|
1648
|
+
for (const alt of tail) {
|
|
1649
|
+
const result = alt.parse(arg, ctx);
|
|
1650
|
+
if (result.ok) return result;
|
|
1651
|
+
rejection = or(rejection, result);
|
|
1652
|
+
}
|
|
1653
|
+
if (!rejection.ok && rejection.failure.length === 0) return notOk([]);
|
|
1654
|
+
return notOk([leafDiagnostic(ctx, arg, `Expected one of: ${label}`)]);
|
|
1655
|
+
}
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
function str(value) {
|
|
1659
|
+
if (value === void 0) return {
|
|
1660
|
+
kind: "str",
|
|
1661
|
+
label: "string",
|
|
1662
|
+
value: void 0,
|
|
1663
|
+
parse: (arg, ctx) => {
|
|
1664
|
+
const literal = StringLiteralExprAst.cast(arg.syntax);
|
|
1665
|
+
if (literal !== void 0) {
|
|
1666
|
+
const parsed = literal.value();
|
|
1667
|
+
if (parsed !== void 0) return ok(parsed);
|
|
1668
|
+
}
|
|
1669
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected a string literal")]);
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
return {
|
|
1673
|
+
kind: "str",
|
|
1674
|
+
label: JSON.stringify(value),
|
|
1675
|
+
value,
|
|
1676
|
+
parse: (arg, ctx) => {
|
|
1677
|
+
const literal = StringLiteralExprAst.cast(arg.syntax);
|
|
1678
|
+
if (literal !== void 0) {
|
|
1679
|
+
if (literal.value() === value) return ok(value);
|
|
1680
|
+
}
|
|
1681
|
+
return notOk([leafDiagnostic(ctx, arg, `Expected ${JSON.stringify(value)}`)]);
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
/**
|
|
1686
|
+
* A `` tag`...` ``, `tag"..."`, or `tag'...'` argument. `tags` and `documentation` describe the
|
|
1687
|
+
* registered tags for tooling; parsing accepts any tag.
|
|
1688
|
+
*/
|
|
1689
|
+
function taggedLiteral(tags, options) {
|
|
1690
|
+
return {
|
|
1691
|
+
kind: "taggedLiteral",
|
|
1692
|
+
label: `${tags[0] ?? "tag"}\`...\``,
|
|
1693
|
+
tags,
|
|
1694
|
+
documentation: options.documentation,
|
|
1695
|
+
parse: (arg, ctx) => {
|
|
1696
|
+
const literal = TaggedLiteralExprAst.cast(arg.syntax);
|
|
1697
|
+
if (literal === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a tagged literal")]);
|
|
1698
|
+
return ok({
|
|
1699
|
+
tag: literal.tagName(),
|
|
1700
|
+
canonicalization: literal.canonicalization(),
|
|
1701
|
+
span: nodePslSpan(literal.syntax, ctx.sources)
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
const TAGGED_LITERAL_FAILURE_CODES = {
|
|
1707
|
+
nul: "PSL_TAGGED_LITERAL_NUL",
|
|
1708
|
+
"too-large": "PSL_TAGGED_LITERAL_TOO_LARGE"
|
|
1709
|
+
};
|
|
1710
|
+
/** A tagged literal as the written value it holds, refused when its text cannot be canonicalized. */
|
|
1711
|
+
function writtenTaggedLiteral() {
|
|
1712
|
+
const arm = taggedLiteral([], { documentation: "A value written with its data type's tag." });
|
|
1713
|
+
const parse = (arg, ctx) => {
|
|
1714
|
+
const parsed = arm.parse(arg, ctx);
|
|
1715
|
+
if (!parsed.ok) return parsed;
|
|
1716
|
+
const { tag, canonicalization } = parsed.value;
|
|
1717
|
+
return canonicalization.ok ? ok({
|
|
1718
|
+
kind: "tag",
|
|
1719
|
+
tag,
|
|
1720
|
+
text: canonicalization.text
|
|
1721
|
+
}) : notOk([leafDiagnostic(ctx, arg, describeTaggedLiteralFailure(canonicalization.reason), TAGGED_LITERAL_FAILURE_CODES[canonicalization.reason])]);
|
|
1722
|
+
};
|
|
1723
|
+
return blindCast({
|
|
1724
|
+
...arm,
|
|
1725
|
+
parse,
|
|
1726
|
+
claims: (arg) => TaggedLiteralExprAst.cast(arg.syntax) !== void 0
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
function scalarMemberValue() {
|
|
1730
|
+
return oneOf(str(), num(), bool(), writtenTaggedLiteral());
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* An enum member's written value: a string, a number, a boolean, a tagged literal, which it yields as the written value, its tag and canonical text, or a list of those. A tagged literal whose text cannot be canonicalized is refused. The block also records each member as written in `writtenValues`, from which the member reader takes it by the cast rule. ADR 254.
|
|
1734
|
+
*/
|
|
1735
|
+
function enumMemberValue() {
|
|
1736
|
+
return oneOf(str(), num(), bool(), writtenTaggedLiteral(), {
|
|
1737
|
+
...list(scalarMemberValue(), { label: "[...]" }),
|
|
1738
|
+
claims: (arg) => ArrayLiteralAst.cast(arg.syntax) !== void 0
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
function parseFieldName(arg, ctx) {
|
|
1742
|
+
const identifier = IdentifierAst.cast(arg.syntax);
|
|
1743
|
+
if (identifier === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a field name")]);
|
|
1744
|
+
const name = identifier.name();
|
|
1745
|
+
if (name === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a field name")]);
|
|
1746
|
+
const resolution = ctx.binder.symbolForNode(arg.syntax);
|
|
1747
|
+
if (resolution === void 0) return notOk([]);
|
|
1748
|
+
if (resolution.kind === "field") return ok(resolution.symbol.name);
|
|
1749
|
+
if (resolution.kind === "crossSpace") return ok(name);
|
|
1750
|
+
return notOk([]);
|
|
1751
|
+
}
|
|
1752
|
+
function fieldRef() {
|
|
1753
|
+
return {
|
|
1754
|
+
kind: "fieldRef",
|
|
1755
|
+
label: "field name",
|
|
1756
|
+
parse: parseFieldName
|
|
1757
|
+
};
|
|
1758
|
+
}
|
|
1759
|
+
function referencedFieldRef() {
|
|
1760
|
+
return {
|
|
1761
|
+
kind: "referencedFieldRef",
|
|
1762
|
+
label: "field name",
|
|
1763
|
+
parse: parseFieldName
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
1766
|
+
function interpretArgs(args, spec, ctx, span, sourceNode) {
|
|
1767
|
+
let outcome = okVoid();
|
|
139
1768
|
const output = {};
|
|
140
1769
|
const seen = /* @__PURE__ */ new Set();
|
|
141
1770
|
let positionalSlot = 0;
|
|
@@ -148,7 +1777,7 @@ function interpretArgs(args, spec, ctx, span) {
|
|
|
148
1777
|
const posParam = spec.positional[positionalSlot];
|
|
149
1778
|
if (posParam === void 0) {
|
|
150
1779
|
if (!reportedExcess) {
|
|
151
|
-
|
|
1780
|
+
outcome = and(outcome, notOk([diagnostic(`${spec.label} received too many positional arguments`, ctx, span, sourceNode)]));
|
|
152
1781
|
reportedExcess = true;
|
|
153
1782
|
}
|
|
154
1783
|
continue;
|
|
@@ -159,19 +1788,20 @@ function interpretArgs(args, spec, ctx, span) {
|
|
|
159
1788
|
} else {
|
|
160
1789
|
const namedParam = Object.hasOwn(spec.named, name) ? spec.named[name] : void 0;
|
|
161
1790
|
if (namedParam === void 0) {
|
|
162
|
-
|
|
1791
|
+
outcome = and(outcome, notOk([diagnostic(`${spec.label} received unknown argument "${name}"`, ctx, nodePslSpan(arg.syntax, ctx.sources), arg.syntax)]));
|
|
163
1792
|
continue;
|
|
164
1793
|
}
|
|
165
1794
|
key = name;
|
|
166
|
-
param = namedParam;
|
|
1795
|
+
param = namedParam.type;
|
|
167
1796
|
}
|
|
168
1797
|
if (seen.has(key)) {
|
|
169
|
-
|
|
1798
|
+
outcome = and(outcome, notOk([diagnostic(`${spec.label} received duplicate argument "${key}"`, ctx, nodePslSpan(arg.syntax, ctx.sources), arg.syntax)]));
|
|
170
1799
|
continue;
|
|
171
1800
|
}
|
|
172
1801
|
seen.add(key);
|
|
173
|
-
const result = parseArgValue(arg, param, ctx
|
|
1802
|
+
const result = parseArgValue(arg, param, ctx);
|
|
174
1803
|
if (result.ok) output[key] = result.value;
|
|
1804
|
+
outcome = and(outcome, result);
|
|
175
1805
|
}
|
|
176
1806
|
const finalized = /* @__PURE__ */ new Set();
|
|
177
1807
|
const finalizeAbsentKey = (key, positionalParam, namedParam) => {
|
|
@@ -183,19 +1813,22 @@ function interpretArgs(args, spec, ctx, span) {
|
|
|
183
1813
|
if (effective.hasDefault) output[key] = effective.defaultValue;
|
|
184
1814
|
return;
|
|
185
1815
|
}
|
|
186
|
-
|
|
1816
|
+
outcome = and(outcome, notOk([diagnostic(`${spec.label} is missing required argument "${key}"`, ctx, span, sourceNode)]));
|
|
187
1817
|
};
|
|
188
1818
|
for (const param of spec.positional) {
|
|
189
1819
|
const namedParam = Object.hasOwn(spec.named, param.key) ? spec.named[param.key] : void 0;
|
|
190
|
-
finalizeAbsentKey(param.key, param.type, namedParam);
|
|
1820
|
+
finalizeAbsentKey(param.key, param.type, namedParam?.type);
|
|
191
1821
|
}
|
|
192
|
-
for (const key of Object.keys(spec.named)) finalizeAbsentKey(key, void 0, spec.named[key]);
|
|
193
|
-
if (
|
|
1822
|
+
for (const key of Object.keys(spec.named)) finalizeAbsentKey(key, void 0, spec.named[key]?.type);
|
|
1823
|
+
if (!outcome.ok) return notOk(outcome.failure);
|
|
194
1824
|
return ok(output);
|
|
195
1825
|
}
|
|
196
1826
|
function interpretAttribute(attrNode, spec, ctx) {
|
|
197
|
-
const attributeSpan = nodePslSpan(attrNode.syntax, ctx.
|
|
198
|
-
const bound = interpretArgs(attrNode.argList()?.args() ?? [],
|
|
1827
|
+
const attributeSpan = nodePslSpan(attrNode.syntax, ctx.sources);
|
|
1828
|
+
const bound = interpretArgs(attrNode.argList()?.args() ?? [], {
|
|
1829
|
+
...spec,
|
|
1830
|
+
label: `Attribute "${spec.name}"`
|
|
1831
|
+
}, ctx, attributeSpan, attrNode.syntax);
|
|
199
1832
|
if (!bound.ok) return notOk(bound.failure);
|
|
200
1833
|
const value = blindCast(bound.value);
|
|
201
1834
|
if (spec.refine !== void 0) {
|
|
@@ -204,41 +1837,37 @@ function interpretAttribute(attrNode, spec, ctx) {
|
|
|
204
1837
|
}
|
|
205
1838
|
return ok(value);
|
|
206
1839
|
}
|
|
207
|
-
function parseArgValue(arg, argType, ctx
|
|
1840
|
+
function parseArgValue(arg, argType, ctx) {
|
|
208
1841
|
const value = arg.value();
|
|
209
|
-
if (value === void 0)
|
|
210
|
-
|
|
211
|
-
diagnostics.push(missing);
|
|
212
|
-
return notOk([missing]);
|
|
213
|
-
}
|
|
214
|
-
const result = argType.parse(value, ctx);
|
|
215
|
-
if (!result.ok) for (const failure of result.failure) diagnostics.push(failure);
|
|
216
|
-
return result;
|
|
1842
|
+
if (value === void 0) return notOk([diagnostic("Attribute argument is missing a value", ctx, nodePslSpan(arg.syntax, ctx.sources), arg.syntax)]);
|
|
1843
|
+
return argType.parse(value, ctx);
|
|
217
1844
|
}
|
|
218
1845
|
function isOptionalArgType(param) {
|
|
219
1846
|
return "optional" in param && param.optional === true;
|
|
220
1847
|
}
|
|
221
|
-
function diagnostic(message, ctx, span) {
|
|
1848
|
+
function diagnostic(message, ctx, span, sourceNode) {
|
|
222
1849
|
return {
|
|
223
1850
|
code: ATTRIBUTE_DIAGNOSTIC_CODE,
|
|
224
1851
|
message,
|
|
225
|
-
|
|
226
|
-
span
|
|
1852
|
+
...diagnosticSource(ctx.sources, sourceNode).at(span)
|
|
227
1853
|
};
|
|
228
1854
|
}
|
|
229
|
-
function funcCall(name, sig) {
|
|
1855
|
+
function funcCall(name, sig, options = {}) {
|
|
230
1856
|
return {
|
|
231
1857
|
kind: "funcCall",
|
|
232
|
-
label:
|
|
1858
|
+
label: `${name}()`,
|
|
1859
|
+
name,
|
|
1860
|
+
signature: sig,
|
|
1861
|
+
claims: (arg) => plainCallee(arg)?.name === name,
|
|
233
1862
|
parse: (arg, ctx) => {
|
|
234
1863
|
const guard = matchCallee(arg, name, ctx);
|
|
235
1864
|
if (!guard.ok) return guard;
|
|
236
|
-
const span = nodePslSpan(guard.value.syntax, ctx.
|
|
1865
|
+
const span = nodePslSpan(guard.value.syntax, ctx.sources);
|
|
237
1866
|
const bound = interpretArgs(guard.value.args(), {
|
|
238
|
-
name
|
|
1867
|
+
label: options.label ?? `Attribute "${name}"`,
|
|
239
1868
|
positional: sig.positional ?? [],
|
|
240
1869
|
named: sig.named ?? {}
|
|
241
|
-
}, ctx, span);
|
|
1870
|
+
}, ctx, span, guard.value.syntax);
|
|
242
1871
|
if (!bound.ok) return notOk(bound.failure);
|
|
243
1872
|
return ok({
|
|
244
1873
|
fn: name,
|
|
@@ -248,22 +1877,34 @@ function funcCall(name, sig) {
|
|
|
248
1877
|
}
|
|
249
1878
|
};
|
|
250
1879
|
}
|
|
1880
|
+
function plainCallee(arg) {
|
|
1881
|
+
const call = FunctionCallAst.cast(arg.syntax);
|
|
1882
|
+
const qname = call?.name();
|
|
1883
|
+
if (call === void 0 || qname === void 0) return void 0;
|
|
1884
|
+
if (qname.dot() !== void 0 || qname.colon() !== void 0) return void 0;
|
|
1885
|
+
const name = qname.identifier()?.token()?.text;
|
|
1886
|
+
return name === void 0 ? void 0 : {
|
|
1887
|
+
call,
|
|
1888
|
+
name
|
|
1889
|
+
};
|
|
1890
|
+
}
|
|
251
1891
|
function matchCallee(arg, name, ctx) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
if (calleeName === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a function call")]);
|
|
257
|
-
if (calleeName !== name) return notOk([leafDiagnostic(ctx, arg, `Expected ${name}()`)]);
|
|
258
|
-
return ok(arg);
|
|
1892
|
+
const callee = plainCallee(arg);
|
|
1893
|
+
if (callee === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a function call")]);
|
|
1894
|
+
if (callee.name !== name) return notOk([leafDiagnostic(ctx, arg, `Expected ${name}()`)]);
|
|
1895
|
+
return ok(callee.call);
|
|
259
1896
|
}
|
|
260
|
-
function identifier(name) {
|
|
1897
|
+
function identifier(name, options) {
|
|
1898
|
+
const label = name ?? "identifier";
|
|
261
1899
|
return {
|
|
262
1900
|
kind: "identifier",
|
|
263
|
-
label
|
|
1901
|
+
label,
|
|
1902
|
+
name,
|
|
1903
|
+
documentation: options?.documentation ?? "",
|
|
264
1904
|
parse: (arg, ctx) => {
|
|
265
|
-
|
|
266
|
-
|
|
1905
|
+
const value = IdentifierAst.cast(arg.syntax)?.name();
|
|
1906
|
+
if (value !== void 0 && (name === void 0 || value === name)) return ok(value);
|
|
1907
|
+
return notOk([leafDiagnostic(ctx, arg, `Expected ${label}`)]);
|
|
267
1908
|
}
|
|
268
1909
|
};
|
|
269
1910
|
}
|
|
@@ -273,9 +1914,12 @@ function int(opts) {
|
|
|
273
1914
|
return {
|
|
274
1915
|
kind: "int",
|
|
275
1916
|
label: "integer",
|
|
1917
|
+
...min === void 0 ? {} : { min },
|
|
1918
|
+
...max === void 0 ? {} : { max },
|
|
276
1919
|
parse: (arg, ctx) => {
|
|
277
|
-
|
|
278
|
-
|
|
1920
|
+
const literal = NumberLiteralExprAst.cast(arg.syntax);
|
|
1921
|
+
if (literal !== void 0) {
|
|
1922
|
+
const value = literal.value();
|
|
279
1923
|
if (value !== void 0 && Number.isInteger(value)) {
|
|
280
1924
|
if ((min === void 0 || value >= min) && (max === void 0 || value <= max)) return ok(value);
|
|
281
1925
|
return notOk([leafDiagnostic(ctx, arg, rangeMessage(min, max))]);
|
|
@@ -290,59 +1934,24 @@ function rangeMessage(min, max) {
|
|
|
290
1934
|
if (min !== void 0) return `Expected an integer greater than or equal to ${min}`;
|
|
291
1935
|
return `Expected an integer less than or equal to ${max}`;
|
|
292
1936
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const diagnostics = [];
|
|
300
|
-
const parsed = [];
|
|
301
|
-
let count = 0;
|
|
302
|
-
for (const element of arg.elements()) {
|
|
303
|
-
count += 1;
|
|
304
|
-
const result = of.parse(element, ctx);
|
|
305
|
-
if (result.ok) parsed.push({
|
|
306
|
-
node: element,
|
|
307
|
-
value: result.value
|
|
308
|
-
});
|
|
309
|
-
else diagnostics.push(...result.failure);
|
|
310
|
-
}
|
|
311
|
-
if (opts?.nonEmpty === true && count === 0) diagnostics.push(leafDiagnostic(ctx, arg, "Expected a non-empty list"));
|
|
312
|
-
if (opts?.unique === true) {
|
|
313
|
-
const seen = /* @__PURE__ */ new Set();
|
|
314
|
-
for (const { node, value } of parsed) if (seen.has(value)) diagnostics.push(leafDiagnostic(ctx, node, "Duplicate list entry"));
|
|
315
|
-
else seen.add(value);
|
|
316
|
-
}
|
|
317
|
-
if (diagnostics.length > 0) return notOk(diagnostics);
|
|
318
|
-
return ok(parsed.map((entry) => entry.value));
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
function num(value) {
|
|
323
|
-
return {
|
|
324
|
-
kind: "num",
|
|
325
|
-
label: value === void 0 ? "number" : String(value),
|
|
326
|
-
parse: (arg, ctx) => {
|
|
327
|
-
if (arg instanceof NumberLiteralExprAst) {
|
|
328
|
-
const parsed = arg.value();
|
|
329
|
-
if (parsed !== void 0 && (value === void 0 || parsed === value)) return ok(parsed);
|
|
330
|
-
}
|
|
331
|
-
return notOk([leafDiagnostic(ctx, arg, value === void 0 ? "Expected a number literal" : `Expected ${value}`)]);
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
function oneOf(...alts) {
|
|
336
|
-
const label = alts.map((alt) => alt.label).join(" | ");
|
|
1937
|
+
/**
|
|
1938
|
+
* Reads an opaque JSON object from a quoted JSON string — the ADR's one text-encoded surface
|
|
1939
|
+
* exception (e.g. an index `filter` / `weights` argument). The string is decoded by the parser,
|
|
1940
|
+
* then JSON-parsed; a non-object (array/scalar) or invalid JSON is a diagnostic.
|
|
1941
|
+
*/
|
|
1942
|
+
function json() {
|
|
337
1943
|
return {
|
|
338
|
-
kind: "
|
|
339
|
-
label,
|
|
1944
|
+
kind: "json",
|
|
1945
|
+
label: "JSON object",
|
|
340
1946
|
parse: (arg, ctx) => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
1947
|
+
const literal = StringLiteralExprAst.cast(arg.syntax);
|
|
1948
|
+
if (literal === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a JSON object string")]);
|
|
1949
|
+
const raw = literal.value();
|
|
1950
|
+
if (raw !== void 0) try {
|
|
1951
|
+
const parsed = JSON.parse(raw);
|
|
1952
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return ok(blindCast(parsed));
|
|
1953
|
+
} catch {}
|
|
1954
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected a valid JSON object")]);
|
|
346
1955
|
}
|
|
347
1956
|
};
|
|
348
1957
|
}
|
|
@@ -350,65 +1959,266 @@ function record(of) {
|
|
|
350
1959
|
return {
|
|
351
1960
|
kind: "record",
|
|
352
1961
|
label: `{ [key]: ${of.label} }`,
|
|
1962
|
+
of,
|
|
353
1963
|
parse: (arg, ctx) => {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
|
|
1964
|
+
const literal = ObjectLiteralExprAst.cast(arg.syntax);
|
|
1965
|
+
if (literal === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected an object literal")]);
|
|
1966
|
+
const entries = [];
|
|
1967
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1968
|
+
let outcome = okVoid();
|
|
1969
|
+
for (const field of Array.from(literal.fields())) {
|
|
358
1970
|
const key = field.keyName();
|
|
359
1971
|
if (key === void 0) {
|
|
360
|
-
|
|
1972
|
+
outcome = and(outcome, notOk([leafDiagnostic(ctx, field, "Expected a key")]));
|
|
361
1973
|
continue;
|
|
362
1974
|
}
|
|
363
1975
|
const value = field.value();
|
|
364
1976
|
if (value === void 0) {
|
|
365
|
-
|
|
1977
|
+
outcome = and(outcome, notOk([leafDiagnostic(ctx, field, `Expected a value for key "${key}"`)]));
|
|
366
1978
|
continue;
|
|
367
1979
|
}
|
|
368
1980
|
const parsed = of.parse(value, ctx);
|
|
369
1981
|
if (!parsed.ok) {
|
|
370
|
-
|
|
1982
|
+
outcome = and(outcome, parsed);
|
|
371
1983
|
continue;
|
|
372
1984
|
}
|
|
373
|
-
if (
|
|
374
|
-
|
|
1985
|
+
if (keys.has(key)) {
|
|
1986
|
+
outcome = and(outcome, notOk([leafDiagnostic(ctx, field, `Duplicate key "${key}"`)]));
|
|
375
1987
|
continue;
|
|
376
1988
|
}
|
|
377
|
-
|
|
1989
|
+
keys.add(key);
|
|
1990
|
+
entries.push([key, parsed.value]);
|
|
378
1991
|
}
|
|
379
|
-
if (
|
|
380
|
-
return ok(
|
|
1992
|
+
if (!outcome.ok) return notOk(outcome.failure);
|
|
1993
|
+
return ok(Object.fromEntries(entries));
|
|
1994
|
+
}
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
function jsonValue() {
|
|
1998
|
+
const self = {
|
|
1999
|
+
kind: "oneOf",
|
|
2000
|
+
label: "JSON value",
|
|
2001
|
+
get alternatives() {
|
|
2002
|
+
return composed.alternatives;
|
|
2003
|
+
},
|
|
2004
|
+
parse: (arg, ctx) => composed.parse(arg, ctx)
|
|
2005
|
+
};
|
|
2006
|
+
const composed = oneOf(str(), finiteNumber(), bool(), jsonNull(), list(self), record(self));
|
|
2007
|
+
return self;
|
|
2008
|
+
}
|
|
2009
|
+
function finiteNumber() {
|
|
2010
|
+
return {
|
|
2011
|
+
kind: "num",
|
|
2012
|
+
value: void 0,
|
|
2013
|
+
label: "number",
|
|
2014
|
+
parse: (arg, ctx) => {
|
|
2015
|
+
const value = NumberLiteralExprAst.cast(arg.syntax)?.value();
|
|
2016
|
+
if (value === void 0 || Number.isNaN(value) || !Number.isFinite(value)) return notOk([leafDiagnostic(ctx, arg, "Expected a finite number literal")]);
|
|
2017
|
+
return ok(value);
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
2021
|
+
function jsonNull() {
|
|
2022
|
+
return {
|
|
2023
|
+
kind: "null",
|
|
2024
|
+
label: "null",
|
|
2025
|
+
parse: (arg, ctx) => {
|
|
2026
|
+
if (IdentifierAst.cast(arg.syntax)?.name() === "null") return ok(null);
|
|
2027
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected null")]);
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
/**
|
|
2032
|
+
* `arm`, with the value it parses passed through `map`. The result keeps the arm's `kind`, `label`
|
|
2033
|
+
* and metadata, which describe the syntax it accepts for tooling, not its output. A refusal passes
|
|
2034
|
+
* through unchanged.
|
|
2035
|
+
*/
|
|
2036
|
+
function mapArg(arm, map) {
|
|
2037
|
+
const parse = (arg, ctx) => {
|
|
2038
|
+
const parsed = arm.parse(arg, ctx);
|
|
2039
|
+
return parsed.ok ? ok(map(parsed.value, arg, ctx)) : parsed;
|
|
2040
|
+
};
|
|
2041
|
+
return blindCast({
|
|
2042
|
+
...arm,
|
|
2043
|
+
parse
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* `arm`, with the value it parses passed through `refine`, which may refuse it. The result keeps the arm's `kind`, `label` and metadata, as `mapArg` does. A refusal of the arm passes through without running `refine`.
|
|
2048
|
+
*/
|
|
2049
|
+
function refineArg(arm, refine) {
|
|
2050
|
+
const parse = (arg, ctx) => {
|
|
2051
|
+
const parsed = arm.parse(arg, ctx);
|
|
2052
|
+
return parsed.ok ? refine(parsed.value, arg, ctx) : parsed;
|
|
2053
|
+
};
|
|
2054
|
+
return blindCast({
|
|
2055
|
+
...arm,
|
|
2056
|
+
parse
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
/** A number literal kept as its source text, for consumers that must not round it through a JS number. */
|
|
2060
|
+
function numLiteral() {
|
|
2061
|
+
return {
|
|
2062
|
+
kind: "num",
|
|
2063
|
+
label: "number",
|
|
2064
|
+
value: void 0,
|
|
2065
|
+
parse: (arg, ctx) => {
|
|
2066
|
+
const text = NumberLiteralExprAst.cast(arg.syntax)?.token()?.text;
|
|
2067
|
+
if (text !== void 0) return ok({ text });
|
|
2068
|
+
return notOk([leafDiagnostic(ctx, arg, "Expected a number literal")]);
|
|
381
2069
|
}
|
|
382
2070
|
};
|
|
383
|
-
}
|
|
384
|
-
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* `arm`, yielding the literal it accepts as a written scalar with its span, so a consumer that reads
|
|
2074
|
+
* the value by the cast rule reports at the value. `arm` must accept only literals. The result keeps
|
|
2075
|
+
* the arm's `kind` and metadata, which describe the syntax it accepts for tooling, not its output.
|
|
2076
|
+
* ADR 231, ADR 254.
|
|
2077
|
+
*/
|
|
2078
|
+
function writtenScalar(arm) {
|
|
2079
|
+
return mapArg(arm, (_accepted, arg, ctx) => {
|
|
2080
|
+
const span = nodePslSpan(arg.syntax, ctx.sources);
|
|
2081
|
+
const literal = readWrittenScalar(arg);
|
|
2082
|
+
if (literal.ok) return {
|
|
2083
|
+
kind: "scalar",
|
|
2084
|
+
written: literal.written,
|
|
2085
|
+
span
|
|
2086
|
+
};
|
|
2087
|
+
if (literal.reason === "not-a-literal") throw new InternalError(`writtenScalar wraps an arm that accepted ${literal.found}.`);
|
|
2088
|
+
return {
|
|
2089
|
+
kind: "scalar",
|
|
2090
|
+
written: void 0,
|
|
2091
|
+
reason: literal.reason,
|
|
2092
|
+
span
|
|
2093
|
+
};
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
/** A list of the elements `of` yields, with the span of the whole list. ADR 254. */
|
|
2097
|
+
function writtenList(of) {
|
|
2098
|
+
return mapArg(list(of, { label: `list of (${of.label})` }), (elements, arg, ctx) => ({
|
|
2099
|
+
kind: "list",
|
|
2100
|
+
elements,
|
|
2101
|
+
span: nodePslSpan(arg.syntax, ctx.sources)
|
|
2102
|
+
}));
|
|
2103
|
+
}
|
|
2104
|
+
function fieldAttribute(name, config) {
|
|
2105
|
+
return fieldLevelAttribute(name, config);
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* A field attribute that reads only its type, never the field it is written on, so a type alias can carry it too.
|
|
2109
|
+
*/
|
|
2110
|
+
function typeAttribute(name, config) {
|
|
2111
|
+
return fieldLevelAttribute(name, config);
|
|
2112
|
+
}
|
|
2113
|
+
function fieldLevelAttribute(name, config) {
|
|
2114
|
+
return {
|
|
2115
|
+
level: "field",
|
|
2116
|
+
name,
|
|
2117
|
+
documentation: config.documentation,
|
|
2118
|
+
positional: config.positional ?? [],
|
|
2119
|
+
named: Object.assign(Object.create(null), config.named),
|
|
2120
|
+
...config.refine !== void 0 ? { refine: config.refine } : {}
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
/** The data types of a stack that registers none. */
|
|
2124
|
+
const EMPTY_DATA_TYPES = {
|
|
2125
|
+
entries: {},
|
|
2126
|
+
lookup: createDataTypeLookup([]),
|
|
2127
|
+
dataTypeOfCodec: () => void 0
|
|
2128
|
+
};
|
|
2129
|
+
/** How a diagnostic names a subject, as in `Field "Post.slug"` or `Type alias "Slug"`. */
|
|
2130
|
+
function typeAttributeSubjectLabel(subject) {
|
|
2131
|
+
return `${subject.kind === "field" ? "Field" : "Type alias"} "${subject.name}"`;
|
|
2132
|
+
}
|
|
2133
|
+
function typeAttributeSpecContextOfField(ctx) {
|
|
2134
|
+
return {
|
|
2135
|
+
symbols: ctx.symbols,
|
|
2136
|
+
defaultFunctionRegistry: ctx.defaultFunctionRegistry,
|
|
2137
|
+
generatorFunctions: ctx.generatorFunctions,
|
|
2138
|
+
dataTypes: ctx.dataTypes,
|
|
2139
|
+
subject: {
|
|
2140
|
+
kind: "field",
|
|
2141
|
+
name: `${ctx.model.name}.${ctx.field.name}`
|
|
2142
|
+
},
|
|
2143
|
+
list: ctx.field.list,
|
|
2144
|
+
typeName: ctx.field.typeName,
|
|
2145
|
+
typeResolution: ctx.typeResolution,
|
|
2146
|
+
typeConstructor: ctx.typeConstructor
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
const GENERATOR_PHASE_DOCUMENTATION = {
|
|
2150
|
+
onCreate: "Generates a value in the client when a row is created without one.",
|
|
2151
|
+
onUpdate: "Generates a value in the client every time a row is updated."
|
|
2152
|
+
};
|
|
2153
|
+
/** The source text of a node, as the author wrote it. */
|
|
2154
|
+
function nodeSourceText(node, ctx) {
|
|
2155
|
+
return ctx.sources.sourceFileFor(node.syntax).text.slice(node.syntax.offset, node.syntax.endOffset).trim();
|
|
2156
|
+
}
|
|
2157
|
+
function calleeName(node) {
|
|
2158
|
+
return FunctionCallAst.cast(node.syntax)?.path().join(".");
|
|
2159
|
+
}
|
|
2160
|
+
function functionListText(functions, codecKnown) {
|
|
2161
|
+
if (functions.length > 0) return `Functions that apply: ${functions.map(({ name }) => `${name}()`).join(", ")}.`;
|
|
2162
|
+
return codecKnown ? "No generator function applies to this codec." : "No generator function applies to it.";
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* A call to the generator function `name`, with its signature built from the stack's data types when it is written as a function of them. Its binding diagnostics name it as a generator function.
|
|
2166
|
+
*/
|
|
2167
|
+
function generatorFunctionCall(name, signature, dataTypes) {
|
|
2168
|
+
const declared = blindCast(signature);
|
|
2169
|
+
return funcCall(name, typeof declared === "function" ? declared(dataTypes) : declared, { label: `Generator function "${name}"` });
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* The generator function arms for a field's codec. A call to a function that does not apply to the codec, or that no component declares, is refused before the arms are tried, so the author is told which functions do apply.
|
|
2173
|
+
*/
|
|
2174
|
+
function generatorCallArm(ctx) {
|
|
2175
|
+
const codecId = ctx.typeConstructor === void 0 ? void 0 : contributedTypeCodecId(ctx.typeConstructor.descriptor);
|
|
2176
|
+
const functions = codecId === void 0 ? [] : ctx.generatorFunctions.functionsFor(codecId);
|
|
2177
|
+
const subject = typeAttributeSubjectLabel(ctx.subject);
|
|
2178
|
+
const target = codecId === void 0 ? "the field's type" : `codec "${codecId}"`;
|
|
2179
|
+
const refuse = (arg, attributeCtx) => {
|
|
2180
|
+
const name = calleeName(arg);
|
|
2181
|
+
return notOk([name !== void 0 && !ctx.generatorFunctions.has(name) ? leafDiagnostic(attributeCtx, arg, `${subject}: unknown generator function "${name}". ${functionListText(functions, codecId !== void 0)}`, "PSL_UNKNOWN_GENERATOR_FUNCTION") : leafDiagnostic(attributeCtx, arg, `${subject}: ${nodeSourceText(arg, attributeCtx)} does not apply to ${target}. ${functionListText(functions, codecId !== void 0)}`, "PSL_GENERATOR_NOT_APPLICABLE")]);
|
|
2182
|
+
};
|
|
2183
|
+
const [first, ...rest] = functions.map(({ name, signature }) => generatorFunctionCall(name, signature, ctx.dataTypes));
|
|
2184
|
+
if (first === void 0) return {
|
|
2185
|
+
kind: "rejecting",
|
|
2186
|
+
label: "generator function",
|
|
2187
|
+
message: `No generator function applies to ${target}`,
|
|
2188
|
+
parse: refuse
|
|
2189
|
+
};
|
|
2190
|
+
const value = oneOf(first, ...rest);
|
|
2191
|
+
const bound = new Set(functions.map(({ name }) => name));
|
|
385
2192
|
return {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const value = arg.value();
|
|
391
|
-
if (value !== void 0) return ok(value);
|
|
392
|
-
}
|
|
393
|
-
return notOk([leafDiagnostic(ctx, arg, "Expected a string literal")]);
|
|
2193
|
+
...value,
|
|
2194
|
+
parse: (arg, attributeCtx) => {
|
|
2195
|
+
const name = calleeName(arg);
|
|
2196
|
+
return name !== void 0 && !bound.has(name) ? refuse(arg, attributeCtx) : value.parse(arg, attributeCtx);
|
|
394
2197
|
}
|
|
395
2198
|
};
|
|
396
2199
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
positional:
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
2200
|
+
/** The spec of `@onCreate(fn())` or `@onUpdate(fn())` on a field or type alias, offering the generator functions bound to its codec. */
|
|
2201
|
+
function typeGeneratorAttributeSpec(phase, ctx) {
|
|
2202
|
+
return typeAttribute(phase, {
|
|
2203
|
+
documentation: GENERATOR_PHASE_DOCUMENTATION[phase],
|
|
2204
|
+
positional: [{
|
|
2205
|
+
key: "value",
|
|
2206
|
+
type: generatorCallArm(ctx),
|
|
2207
|
+
documentation: "A generator function that applies to the field's codec."
|
|
2208
|
+
}]
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
/** The spec of `@onCreate(fn())` or `@onUpdate(fn())`, offering the generator functions bound to the field's codec. */
|
|
2212
|
+
function generatorAttributeSpec(phase) {
|
|
2213
|
+
return (ctx) => typeGeneratorAttributeSpec(phase, typeAttributeSpecContextOfField(ctx));
|
|
405
2214
|
}
|
|
406
2215
|
function modelAttribute(name, config) {
|
|
407
2216
|
return {
|
|
408
2217
|
level: "model",
|
|
409
2218
|
name,
|
|
2219
|
+
documentation: config.documentation,
|
|
410
2220
|
positional: config.positional ?? [],
|
|
411
|
-
named: config.named
|
|
2221
|
+
named: Object.assign(Object.create(null), config.named),
|
|
412
2222
|
...config.refine !== void 0 ? { refine: config.refine } : {}
|
|
413
2223
|
};
|
|
414
2224
|
}
|
|
@@ -425,380 +2235,484 @@ function optional(type, ...rest) {
|
|
|
425
2235
|
defaultValue: rest[0]
|
|
426
2236
|
};
|
|
427
2237
|
}
|
|
428
|
-
function
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
if (value.keyword === keyword) return value;
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
const nested = findBlockDescriptor(value, keyword);
|
|
437
|
-
if (nested !== void 0) return nested;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
function validateExtensionBlockFromSymbol(input) {
|
|
441
|
-
const refCtx = buildRefResolutionContext(input.symbolTable, input.block);
|
|
442
|
-
return validateExtensionBlock(input.block.block, input.descriptor, input.sourceId, input.codecLookup, refCtx);
|
|
2238
|
+
function structBlock(config) {
|
|
2239
|
+
return {
|
|
2240
|
+
mode: "struct",
|
|
2241
|
+
parameters: config.parameters
|
|
2242
|
+
};
|
|
443
2243
|
}
|
|
444
|
-
|
|
445
|
-
start: {
|
|
446
|
-
offset: 0,
|
|
447
|
-
line: 1,
|
|
448
|
-
column: 1
|
|
449
|
-
},
|
|
450
|
-
end: {
|
|
451
|
-
offset: 0,
|
|
452
|
-
line: 1,
|
|
453
|
-
column: 1
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
function buildRefResolutionContext(symbolTable, block) {
|
|
457
|
-
const unspecifiedNamespace = makeNamespace(UNSPECIFIED_PSL_NAMESPACE_ID, Object.values(symbolTable.topLevel.models));
|
|
458
|
-
const allNamespaces = [unspecifiedNamespace, ...Object.values(symbolTable.topLevel.namespaces).map((namespace) => makeNamespace(namespace.name, Object.values(namespace.models)))];
|
|
459
|
-
const ownerNamespaceName = findOwnerNamespaceName(symbolTable, block);
|
|
2244
|
+
function mapBlock(config) {
|
|
460
2245
|
return {
|
|
461
|
-
|
|
462
|
-
|
|
2246
|
+
mode: "map",
|
|
2247
|
+
value: config.value,
|
|
2248
|
+
allowBare: config.allowBare ?? false
|
|
463
2249
|
};
|
|
464
2250
|
}
|
|
465
|
-
function
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
2251
|
+
function interpretExtensionBlock(input) {
|
|
2252
|
+
const { block, descriptor, spec, symbols, sources, binder, dataTypes } = input;
|
|
2253
|
+
const ctx = {
|
|
2254
|
+
sources,
|
|
2255
|
+
symbols,
|
|
2256
|
+
binder,
|
|
2257
|
+
selfBlock: block
|
|
2258
|
+
};
|
|
2259
|
+
const entries = spec.mode === "struct" ? interpretStructBlock(block, spec, ctx) : interpretMapBlock(block, spec, ctx);
|
|
2260
|
+
const diagnostics = [...entries.diagnostics];
|
|
2261
|
+
const interpretedAttributes = interpretExtensionBlockAttributes({
|
|
2262
|
+
block,
|
|
2263
|
+
descriptor,
|
|
2264
|
+
symbols,
|
|
2265
|
+
sources,
|
|
2266
|
+
binder,
|
|
2267
|
+
dataTypes
|
|
2268
|
+
});
|
|
2269
|
+
diagnostics.push(...interpretedAttributes.diagnostics);
|
|
2270
|
+
if (entries.failed || diagnostics.length > 0) return notOk(diagnostics);
|
|
2271
|
+
return ok({
|
|
2272
|
+
kind: descriptor.discriminator,
|
|
2273
|
+
keyword: block.keyword,
|
|
2274
|
+
name: block.name,
|
|
2275
|
+
values: blindCast(entries.values),
|
|
2276
|
+
parameterSpans: entries.parameterSpans,
|
|
2277
|
+
writtenValues: entries.writtenValues,
|
|
2278
|
+
attributes: interpretedAttributes.attributes,
|
|
2279
|
+
span: block.span
|
|
477
2280
|
});
|
|
478
2281
|
}
|
|
479
|
-
function
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
function reconstructExtensionBlock(node, descriptor, sourceFile, diagnostics) {
|
|
488
|
-
const keyword = node.keyword()?.text ?? "";
|
|
489
|
-
const blockName = node.name()?.name() ?? "";
|
|
490
|
-
const blockAttributes = [];
|
|
491
|
-
for (const attribute of node.attributes()) {
|
|
492
|
-
const name = attribute.name()?.path().join(".") ?? "";
|
|
493
|
-
const args = Array.from(attribute.argList()?.args() ?? [], (arg) => {
|
|
494
|
-
const value = arg.value();
|
|
495
|
-
return {
|
|
496
|
-
kind: "positional",
|
|
497
|
-
value: value === void 0 ? "" : printSyntax(value.syntax).trim(),
|
|
498
|
-
span: nodePslSpan(arg.syntax, sourceFile)
|
|
499
|
-
};
|
|
500
|
-
});
|
|
501
|
-
blockAttributes.push({
|
|
502
|
-
name,
|
|
503
|
-
args,
|
|
504
|
-
span: nodePslSpan(attribute.syntax, sourceFile)
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
const parameters = {};
|
|
508
|
-
for (const entry of node.entries()) {
|
|
2282
|
+
function interpretStructBlock(block, spec, ctx) {
|
|
2283
|
+
const diagnostics = [];
|
|
2284
|
+
let failed = false;
|
|
2285
|
+
const values = Object.create(null);
|
|
2286
|
+
const parameterSpans = Object.create(null);
|
|
2287
|
+
const writtenValues = Object.create(null);
|
|
2288
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2289
|
+
for (const entry of block.entries) {
|
|
509
2290
|
const key = entry.key()?.name();
|
|
510
2291
|
if (key === void 0) continue;
|
|
511
|
-
const span = nodePslSpan(entry.syntax,
|
|
512
|
-
if (
|
|
513
|
-
diagnostics.push(
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
2292
|
+
const span = nodePslSpan(entry.syntax, ctx.sources);
|
|
2293
|
+
if (seen.has(key)) {
|
|
2294
|
+
diagnostics.push(duplicateParameterDiagnostic(block, key, ctx, entry, span));
|
|
2295
|
+
continue;
|
|
2296
|
+
}
|
|
2297
|
+
seen.add(key);
|
|
2298
|
+
const rule = Object.hasOwn(spec.parameters, key) ? spec.parameters[key]?.type : void 0;
|
|
2299
|
+
if (rule === void 0) {
|
|
2300
|
+
diagnostics.push(entryDiagnostic("PSL_EXTENSION_UNKNOWN_PARAMETER", `Unknown parameter "${key}" in "${block.keyword}" block "${block.name}". The block does not declare this parameter.`, ctx, entry, span));
|
|
2301
|
+
continue;
|
|
2302
|
+
}
|
|
2303
|
+
parameterSpans[key] = span;
|
|
2304
|
+
const value = entry.value();
|
|
2305
|
+
if (value === void 0) {
|
|
2306
|
+
diagnostics.push(bareEntryDiagnostic(block, key, ctx, entry, span));
|
|
2307
|
+
continue;
|
|
2308
|
+
}
|
|
2309
|
+
const parsed = rule.parse(value, ctx);
|
|
2310
|
+
if (parsed.ok) {
|
|
2311
|
+
values[key] = parsed.value;
|
|
2312
|
+
recordWrittenValue(writtenValues, key, value);
|
|
2313
|
+
} else {
|
|
2314
|
+
failed = true;
|
|
2315
|
+
diagnostics.push(...parsed.failure);
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
for (const [key, param] of Object.entries(spec.parameters)) {
|
|
2319
|
+
if (seen.has(key)) continue;
|
|
2320
|
+
if (isOptionalArgType(param.type)) {
|
|
2321
|
+
if (param.type.hasDefault) values[key] = param.type.defaultValue;
|
|
521
2322
|
continue;
|
|
522
2323
|
}
|
|
523
|
-
|
|
2324
|
+
diagnostics.push(entryDiagnostic("PSL_EXTENSION_MISSING_REQUIRED_PARAMETER", `Required parameter "${key}" is missing from "${block.keyword}" block "${block.name}".`, ctx, block.node, block.span));
|
|
524
2325
|
}
|
|
525
2326
|
return {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
span: nodePslSpan(node.syntax, sourceFile)
|
|
2327
|
+
values,
|
|
2328
|
+
parameterSpans,
|
|
2329
|
+
writtenValues,
|
|
2330
|
+
diagnostics,
|
|
2331
|
+
failed
|
|
532
2332
|
};
|
|
533
2333
|
}
|
|
534
|
-
function
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
2334
|
+
function interpretMapBlock(block, spec, ctx) {
|
|
2335
|
+
const diagnostics = [];
|
|
2336
|
+
let failed = false;
|
|
2337
|
+
const values = Object.create(null);
|
|
2338
|
+
const parameterSpans = Object.create(null);
|
|
2339
|
+
const writtenValues = Object.create(null);
|
|
2340
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2341
|
+
for (const entry of block.entries) {
|
|
2342
|
+
const key = entry.key()?.name();
|
|
2343
|
+
if (key === void 0) continue;
|
|
2344
|
+
const span = nodePslSpan(entry.syntax, ctx.sources);
|
|
2345
|
+
if (seen.has(key)) {
|
|
2346
|
+
diagnostics.push(duplicateParameterDiagnostic(block, key, ctx, entry, span));
|
|
2347
|
+
continue;
|
|
2348
|
+
}
|
|
2349
|
+
seen.add(key);
|
|
2350
|
+
parameterSpans[key] = span;
|
|
2351
|
+
const value = entry.value();
|
|
2352
|
+
if (value === void 0) {
|
|
2353
|
+
if (spec.allowBare) {
|
|
2354
|
+
values[key] = void 0;
|
|
2355
|
+
continue;
|
|
2356
|
+
}
|
|
2357
|
+
diagnostics.push(bareEntryDiagnostic(block, key, ctx, entry, span));
|
|
2358
|
+
continue;
|
|
2359
|
+
}
|
|
2360
|
+
const parsed = spec.value.type.parse(value, ctx);
|
|
2361
|
+
if (parsed.ok) {
|
|
2362
|
+
values[key] = parsed.value;
|
|
2363
|
+
recordWrittenValue(writtenValues, key, value);
|
|
2364
|
+
} else {
|
|
2365
|
+
failed = true;
|
|
2366
|
+
diagnostics.push(...parsed.failure);
|
|
560
2367
|
}
|
|
561
|
-
const items = [];
|
|
562
|
-
for (const element of array.elements()) items.push(reconstructFromExpression(element, param.of, nodePslSpan(element.syntax, sourceFile), sourceFile, diagnostics));
|
|
563
|
-
return {
|
|
564
|
-
kind: "list",
|
|
565
|
-
items,
|
|
566
|
-
span
|
|
567
|
-
};
|
|
568
2368
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
2369
|
+
return {
|
|
2370
|
+
values,
|
|
2371
|
+
parameterSpans,
|
|
2372
|
+
writtenValues,
|
|
2373
|
+
diagnostics,
|
|
2374
|
+
failed
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
function recordWrittenValue(writtenValues, key, value) {
|
|
2378
|
+
const written = writtenValueOf(value);
|
|
2379
|
+
if (written !== void 0) writtenValues[key] = written;
|
|
2380
|
+
}
|
|
2381
|
+
/** A literal as it is written, or a list of literals; `undefined` for anything else. */
|
|
2382
|
+
function writtenValueOf(value) {
|
|
2383
|
+
const array = ArrayLiteralAst.cast(value.syntax);
|
|
2384
|
+
if (array === void 0) {
|
|
2385
|
+
const literal = readWrittenScalar(value);
|
|
2386
|
+
return literal.ok ? literal.written : void 0;
|
|
585
2387
|
}
|
|
2388
|
+
const elements = [];
|
|
2389
|
+
for (const element of array.elements()) {
|
|
2390
|
+
const literal = readWrittenScalar(element);
|
|
2391
|
+
if (!literal.ok) return void 0;
|
|
2392
|
+
elements.push(literal.written);
|
|
2393
|
+
}
|
|
2394
|
+
return {
|
|
2395
|
+
kind: "list",
|
|
2396
|
+
elements
|
|
2397
|
+
};
|
|
586
2398
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
2399
|
+
function duplicateParameterDiagnostic(block, key, ctx, node, span) {
|
|
2400
|
+
return entryDiagnostic("PSL_EXTENSION_DUPLICATE_PARAMETER", `Duplicate parameter "${key}" in "${block.keyword}" block "${block.name}"; first occurrence wins`, ctx, node, span);
|
|
2401
|
+
}
|
|
2402
|
+
function bareEntryDiagnostic(block, key, ctx, node, span) {
|
|
2403
|
+
return entryDiagnostic("PSL_INVALID_EXTENSION_BLOCK_MEMBER", `Parameter "${key}" in "${block.keyword}" block "${block.name}" must be written as "${key} = <value>".`, ctx, node, span);
|
|
2404
|
+
}
|
|
2405
|
+
function interpretExtensionBlockAttributes(input) {
|
|
2406
|
+
const { block, descriptor, symbols, sources, binder, dataTypes } = input;
|
|
2407
|
+
const declared = descriptor.attributes ?? {};
|
|
2408
|
+
const attributes = Object.create(null);
|
|
593
2409
|
const diagnostics = [];
|
|
594
|
-
const
|
|
595
|
-
const
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
if (text === void 0) return void 0;
|
|
603
|
-
if (taken.has(text)) {
|
|
604
|
-
const range = nameRange(name, sourceFile);
|
|
605
|
-
if (range) diagnostics.push({
|
|
606
|
-
code: "PSL_DUPLICATE_DECLARATION",
|
|
607
|
-
message: `Duplicate declaration of "${text}"`,
|
|
608
|
-
range
|
|
2410
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
2411
|
+
for (const attribute of block.attributes) {
|
|
2412
|
+
const { name, span } = attribute;
|
|
2413
|
+
if (!Object.hasOwn(declared, name)) {
|
|
2414
|
+
diagnostics.push({
|
|
2415
|
+
code: "PSL_EXTENSION_UNKNOWN_BLOCK_ATTRIBUTE",
|
|
2416
|
+
message: `Unknown attribute "@@${name}" in "${block.keyword}" block "${block.name}"`,
|
|
2417
|
+
...diagnosticSource(sources, attribute.node.syntax).at(span)
|
|
609
2418
|
});
|
|
610
|
-
|
|
2419
|
+
continue;
|
|
611
2420
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
2421
|
+
if (seenNames.has(name)) {
|
|
2422
|
+
diagnostics.push({
|
|
2423
|
+
code: "PSL_INVALID_EXTENSION_BLOCK_ATTRIBUTE",
|
|
2424
|
+
message: `Duplicate attribute "@@${name}" in "${block.keyword}" block "${block.name}"; first occurrence wins`,
|
|
2425
|
+
...diagnosticSource(sources, attribute.node.syntax).at(span)
|
|
2426
|
+
});
|
|
2427
|
+
continue;
|
|
2428
|
+
}
|
|
2429
|
+
seenNames.add(name);
|
|
2430
|
+
const spec = blindCast(declared[name])(blockSpecContext({
|
|
2431
|
+
symbols,
|
|
2432
|
+
dataTypes
|
|
2433
|
+
}));
|
|
2434
|
+
const result = interpretAttribute(attribute.node, spec, {
|
|
2435
|
+
sources,
|
|
2436
|
+
symbols,
|
|
2437
|
+
binder,
|
|
2438
|
+
selfBlock: block
|
|
2439
|
+
});
|
|
2440
|
+
if (result.ok) {
|
|
2441
|
+
const argSpans = Object.create(null);
|
|
2442
|
+
let positionalSlot = 0;
|
|
2443
|
+
for (const arg of attribute.args) {
|
|
2444
|
+
const key = arg.name ?? spec.positional[positionalSlot++]?.key;
|
|
2445
|
+
if (key !== void 0) argSpans[key] = arg.span;
|
|
2446
|
+
}
|
|
2447
|
+
attributes[name] = {
|
|
2448
|
+
args: result.value,
|
|
2449
|
+
argSpans,
|
|
2450
|
+
span
|
|
2451
|
+
};
|
|
2452
|
+
} else diagnostics.push(...result.failure);
|
|
638
2453
|
}
|
|
639
2454
|
return {
|
|
640
|
-
|
|
641
|
-
namespaces,
|
|
642
|
-
namedTypes,
|
|
643
|
-
blocks,
|
|
644
|
-
models,
|
|
645
|
-
compositeTypes
|
|
646
|
-
} },
|
|
2455
|
+
attributes,
|
|
647
2456
|
diagnostics
|
|
648
2457
|
};
|
|
649
2458
|
}
|
|
650
|
-
function
|
|
2459
|
+
function entryDiagnostic(code, message, ctx, node, span) {
|
|
651
2460
|
return {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
node
|
|
655
|
-
span: nodePslSpan(node.syntax, sourceFile),
|
|
656
|
-
fields: buildFields(name, node.fields(), sourceFile, diagnostics),
|
|
657
|
-
attributes: readResolvedAttributes(node.attributes(), sourceFile)
|
|
2461
|
+
code,
|
|
2462
|
+
message,
|
|
2463
|
+
...diagnosticSource(ctx.sources, node.syntax).at(span)
|
|
658
2464
|
};
|
|
659
2465
|
}
|
|
660
|
-
function
|
|
2466
|
+
function interpretExtensionBlocks(input) {
|
|
2467
|
+
const { symbolTable, sources, pslBlockDescriptors, binder, dataTypes } = input;
|
|
2468
|
+
const parsedBlocks = /* @__PURE__ */ new Map();
|
|
2469
|
+
const diagnostics = [];
|
|
2470
|
+
for (const namespace of Object.values(symbolTable.namespaces)) for (const block of Object.values(namespace.blocks)) {
|
|
2471
|
+
const descriptor = findBlockDescriptor(pslBlockDescriptors, block.keyword);
|
|
2472
|
+
if (descriptor === void 0) continue;
|
|
2473
|
+
const parsed = interpretExtensionBlock({
|
|
2474
|
+
block,
|
|
2475
|
+
descriptor,
|
|
2476
|
+
spec: blockSpecFactoryOf(descriptor)(blockSpecContext({
|
|
2477
|
+
symbols: symbolTable,
|
|
2478
|
+
dataTypes
|
|
2479
|
+
})),
|
|
2480
|
+
symbols: symbolTable,
|
|
2481
|
+
sources,
|
|
2482
|
+
binder,
|
|
2483
|
+
dataTypes
|
|
2484
|
+
});
|
|
2485
|
+
if (parsed.ok) parsedBlocks.set(block, parsed.value);
|
|
2486
|
+
else diagnostics.push(...parsed.failure);
|
|
2487
|
+
}
|
|
661
2488
|
return {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
node,
|
|
665
|
-
span: nodePslSpan(node.syntax, sourceFile),
|
|
666
|
-
fields: buildFields(name, node.fields(), sourceFile, diagnostics),
|
|
667
|
-
attributes: readResolvedAttributes(node.attributes(), sourceFile)
|
|
2489
|
+
parsedBlocks,
|
|
2490
|
+
diagnostics
|
|
668
2491
|
};
|
|
669
2492
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
span: nodePslSpan(node.syntax, sourceFile),
|
|
679
|
-
block: reconstructExtensionBlock(node, descriptor, sourceFile, diagnostics)
|
|
680
|
-
};
|
|
2493
|
+
/**
|
|
2494
|
+
* A name that is lost when a PSL file is read. The parser keeps block members, and the PSL contract sources keep other names, as keys of plain objects, where assigning this key sets the object's prototype instead of adding a key. Code that writes PSL must not write this name anywhere a PSL source reads a name, including inside `@map` and `@@map`.
|
|
2495
|
+
*/
|
|
2496
|
+
const NAME_THE_PSL_SOURCE_LOSES = "__proto__";
|
|
2497
|
+
const DIRECTIVE = /^(\s*\/\/ *use +)(prisma-8|prisma-next)( *)(?!\S)/;
|
|
2498
|
+
const LEGACY_NAME = "prisma-next";
|
|
2499
|
+
function isPrismaNextSchema(text) {
|
|
2500
|
+
return DIRECTIVE.test(text);
|
|
681
2501
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
2502
|
+
/** The document with the directive earlier releases wrote replaced by the current one. */
|
|
2503
|
+
function renameLegacyDirective(text) {
|
|
2504
|
+
return text.replace(DIRECTIVE, (whole, lead, name, trail) => name === LEGACY_NAME ? `${lead}prisma-8${trail}` : whole);
|
|
2505
|
+
}
|
|
2506
|
+
/** The attributes a type alias may carry. Every field typed by the alias takes them. */
|
|
2507
|
+
const TYPE_ALIAS_ATTRIBUTE_NAMES = /* @__PURE__ */ new Set([
|
|
2508
|
+
"default",
|
|
2509
|
+
"onCreate",
|
|
2510
|
+
"onUpdate"
|
|
2511
|
+
]);
|
|
2512
|
+
function writtenBase(declaration, sources) {
|
|
2513
|
+
const node = typeReferenceNode(declaration);
|
|
2514
|
+
if (node === void 0) return declaration.baseType ?? "";
|
|
2515
|
+
return sources.sourceFileFor(node).text.slice(node.offset, node.endOffset).trim();
|
|
2516
|
+
}
|
|
2517
|
+
/** A node's text without its comments, each run of whitespace and comments written as one space. */
|
|
2518
|
+
function writtenText(node) {
|
|
2519
|
+
let text = "";
|
|
2520
|
+
let pendingSpace = false;
|
|
2521
|
+
for (const token of node.tokens()) {
|
|
2522
|
+
if (isTrivia(token)) {
|
|
2523
|
+
pendingSpace = text.length > 0;
|
|
697
2524
|
continue;
|
|
698
2525
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
else if (member instanceof CompositeTypeDeclarationAst) compositeTypes[memberName] = buildCompositeType(memberName, member, sourceFile, diagnostics);
|
|
702
|
-
else if (member instanceof GenericBlockDeclarationAst) blocks[memberName] = buildBlock(memberName, member, sourceFile, pslBlockDescriptors, diagnostics);
|
|
2526
|
+
text += `${pendingSpace ? " " : ""}${token.text}`;
|
|
2527
|
+
pendingSpace = false;
|
|
703
2528
|
}
|
|
704
|
-
return
|
|
705
|
-
kind: "namespace",
|
|
706
|
-
name,
|
|
707
|
-
node,
|
|
708
|
-
span: nodePslSpan(node.syntax, sourceFile),
|
|
709
|
-
models,
|
|
710
|
-
compositeTypes,
|
|
711
|
-
blocks
|
|
712
|
-
};
|
|
2529
|
+
return text;
|
|
713
2530
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
result[name] = buildField(ownerName, name, field, sourceFile, diagnostics);
|
|
2531
|
+
/** The alias `declaration` is written as, if it is written as another `types {}` declaration. */
|
|
2532
|
+
function declaredBaseOf(declaration, declarations, sources) {
|
|
2533
|
+
const base = writtenBase(declaration, sources);
|
|
2534
|
+
return declarations.find((other) => other !== declaration && other.name === base);
|
|
2535
|
+
}
|
|
2536
|
+
/**
|
|
2537
|
+
* What `declaration` stands for, written as one alias with a base that is not an alias: the type of the last alias of the chain, and the attributes of every alias in it, a nearer alias's attribute replacing a farther one's. `undefined` when the chain loops or ends at a contributed alias.
|
|
2538
|
+
*/
|
|
2539
|
+
function expandedDefinition(declaration, declarations, sources, binder) {
|
|
2540
|
+
const chain = [declaration];
|
|
2541
|
+
let next = declaredBaseOf(declaration, declarations, sources);
|
|
2542
|
+
while (next !== void 0) {
|
|
2543
|
+
if (chain.includes(next)) return void 0;
|
|
2544
|
+
chain.push(next);
|
|
2545
|
+
next = declaredBaseOf(next, declarations, sources);
|
|
730
2546
|
}
|
|
731
|
-
|
|
2547
|
+
const last = chain.at(-1) ?? declaration;
|
|
2548
|
+
const reference = typeReferenceNode(last);
|
|
2549
|
+
const annotation = last.node.typeAnnotation()?.syntax;
|
|
2550
|
+
if (annotation === void 0 || reference === void 0) return void 0;
|
|
2551
|
+
if (contributedTypeAliasOf(binder.symbolForNode(reference)) !== void 0) return void 0;
|
|
2552
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
2553
|
+
for (const alias of [...chain].reverse()) for (const attribute of alias.attributes) attributes.set(attribute.name, writtenText(attribute.node.syntax));
|
|
2554
|
+
return [writtenText(annotation), ...attributes.values()].join(" ");
|
|
732
2555
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
const
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
2556
|
+
/** `path`, called with `args` when it takes any; `undefined` when an argument is not a number, string or boolean. */
|
|
2557
|
+
function writtenCall(path, args) {
|
|
2558
|
+
const written = [];
|
|
2559
|
+
for (const arg of args) if (typeof arg === "string") written.push(JSON.stringify(arg));
|
|
2560
|
+
else if (typeof arg === "number" || typeof arg === "boolean") written.push(String(arg));
|
|
2561
|
+
else return void 0;
|
|
2562
|
+
const name = path.join(".");
|
|
2563
|
+
return written.length === 0 ? name : `${name}(${written.join(", ")})`;
|
|
2564
|
+
}
|
|
2565
|
+
/** The refusal of an alias written as another alias, saying what to write instead; `undefined` when its base is not an alias. */
|
|
2566
|
+
function aliasBaseMessage(declaration, resolution, input) {
|
|
2567
|
+
const refusal = (base) => `Type alias "${declaration.name}" is written as the type alias "${base}", and a type alias cannot be written as another one.`;
|
|
2568
|
+
const declared = declaredBaseOf(declaration, input.declarations, input.sources);
|
|
2569
|
+
if (declared !== void 0) {
|
|
2570
|
+
const expanded = expandedDefinition(declaration, input.declarations, input.sources, input.binder);
|
|
2571
|
+
if (expanded === void 0) return refusal(declared.name);
|
|
2572
|
+
const meaning = declaredBaseOf(declared, input.declarations, input.sources) === void 0 ? "is written as" : "stands for";
|
|
2573
|
+
return `${refusal(declared.name)} Write what "${declared.name}" ${meaning} instead: ${declaration.name} = ${expanded}`;
|
|
2574
|
+
}
|
|
2575
|
+
const contributed = contributedTypeAliasOf(resolution);
|
|
2576
|
+
if (contributed === void 0) return void 0;
|
|
2577
|
+
const { onCreate, onUpdate } = contributed.descriptor.output;
|
|
2578
|
+
const attributes = Object.entries({
|
|
2579
|
+
onCreate,
|
|
2580
|
+
onUpdate
|
|
2581
|
+
}).flatMap(([phase, call]) => call === void 0 ? [] : [`@${phase}(${call.name}())`]);
|
|
2582
|
+
const insteadOfAlias = `${refusal(contributed.name)} Type the fields ${contributed.name} instead`;
|
|
2583
|
+
const call = input.authoringTypes === void 0 ? void 0 : findAuthoringTypeConstructorCall(input.authoringTypes, instantiateAuthoringTypeAlias(contributed.descriptor).type);
|
|
2584
|
+
const type = call === void 0 ? void 0 : writtenCall(call.path, call.args);
|
|
2585
|
+
if (type !== void 0) return `${insteadOfAlias}, or write: ${[`${declaration.name} = ${type}`, ...attributes].join(" ")}`;
|
|
2586
|
+
const written = attributes.length === 0 ? "" : ` with ${attributes.join(" ")}`;
|
|
2587
|
+
return `${insteadOfAlias}, or write ${declaration.name} as a type constructor${written}.`;
|
|
2588
|
+
}
|
|
2589
|
+
function baseOf(declaration, resolution) {
|
|
2590
|
+
if (resolution?.kind === "block" && !declaration.isConstructor) return {
|
|
2591
|
+
kind: "block",
|
|
2592
|
+
symbol: resolution.symbol
|
|
2593
|
+
};
|
|
2594
|
+
if (resolution?.kind !== "contributedType") return void 0;
|
|
2595
|
+
const { descriptor } = resolution.symbol;
|
|
2596
|
+
if (descriptor.kind !== "typeConstructor") return void 0;
|
|
2597
|
+
if (declaration.isConstructor) return {
|
|
2598
|
+
kind: "typeConstructor",
|
|
2599
|
+
descriptor,
|
|
2600
|
+
call: declaration.typeConstructor
|
|
2601
|
+
};
|
|
2602
|
+
return isBareTypeConstructor(descriptor) ? {
|
|
2603
|
+
kind: "typeConstructor",
|
|
2604
|
+
descriptor,
|
|
2605
|
+
call: void 0
|
|
2606
|
+
} : void 0;
|
|
2607
|
+
}
|
|
2608
|
+
function fieldOnlyAttributeMessage(attribute, declaration) {
|
|
2609
|
+
return attribute.name === "id" || attribute.name === "unique" ? `Type alias "${declaration.name}" cannot carry @${attribute.name}. @id and @unique belong to a model's field, not to its type; write them on the field.` : void 0;
|
|
2610
|
+
}
|
|
2611
|
+
/**
|
|
2612
|
+
* Reads each `types {}` declaration as a type alias. A base must be a type constructor or a block; another alias, a field preset or anything else is refused, as is an alias with no base. Of the attributes, those the family accepts are kept and every other one is refused and dropped, keeping the alias, so its fields are not refused for it too.
|
|
2613
|
+
*/
|
|
2614
|
+
function resolveTypeAliases(input) {
|
|
2615
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
2616
|
+
const accepted = input.acceptedAttributes ?? TYPE_ALIAS_ATTRIBUTE_NAMES;
|
|
2617
|
+
for (const declaration of input.declarations) {
|
|
2618
|
+
const source = diagnosticSource(input.sources, declaration.node.syntax);
|
|
2619
|
+
const refuseBase = (code, message, span = declaration.span) => input.diagnostics.push({
|
|
2620
|
+
code,
|
|
2621
|
+
message,
|
|
2622
|
+
...source.at(span)
|
|
744
2623
|
});
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
2624
|
+
const reference = typeReferenceNode(declaration);
|
|
2625
|
+
const resolution = reference === void 0 ? void 0 : input.binder.symbolForNode(reference);
|
|
2626
|
+
if ((declaration.isConstructor ? declaration.typeConstructor : declaration.baseType) === void 0) {
|
|
2627
|
+
refuseBase("PSL_UNSUPPORTED_NAMED_TYPE_BASE", `Type alias "${declaration.name}" must declare a base type or constructor`);
|
|
2628
|
+
continue;
|
|
2629
|
+
}
|
|
2630
|
+
const base = baseOf(declaration, resolution);
|
|
2631
|
+
if (base === void 0 || resolution === void 0) {
|
|
2632
|
+
if (declaration.typeConstructor !== void 0) refuseBase("PSL_UNSUPPORTED_NAMED_TYPE_CONSTRUCTOR", `Type alias "${declaration.name}" references unsupported constructor "${declaration.typeConstructor.path.join(".")}"`, declaration.typeConstructor.span);
|
|
2633
|
+
else refuseBase("PSL_UNSUPPORTED_NAMED_TYPE_BASE", aliasBaseMessage(declaration, resolution, input) ?? `Type alias "${declaration.name}" references unsupported base type "${writtenBase(declaration, input.sources)}"`);
|
|
2634
|
+
continue;
|
|
2635
|
+
}
|
|
2636
|
+
const attributes = [];
|
|
2637
|
+
for (const attribute of declaration.attributes) {
|
|
2638
|
+
if (accepted.has(attribute.name)) {
|
|
2639
|
+
attributes.push(attribute);
|
|
2640
|
+
continue;
|
|
2641
|
+
}
|
|
2642
|
+
const message = fieldOnlyAttributeMessage(attribute, declaration) ?? input.describeUnsupportedAttribute?.(attribute, declaration) ?? `Type alias "${declaration.name}" uses unsupported attribute "${attribute.name}"`;
|
|
2643
|
+
input.diagnostics.push({
|
|
2644
|
+
code: "PSL_UNSUPPORTED_NAMED_TYPE_ATTRIBUTE",
|
|
2645
|
+
message,
|
|
2646
|
+
...source.at(attribute.span)
|
|
2647
|
+
});
|
|
2648
|
+
}
|
|
2649
|
+
aliases.set(declaration, {
|
|
2650
|
+
symbol: declaration,
|
|
2651
|
+
base,
|
|
2652
|
+
baseName: declaration.baseType ?? writtenBase(declaration, input.sources),
|
|
2653
|
+
baseResolution: resolution,
|
|
754
2654
|
attributes
|
|
755
|
-
};
|
|
2655
|
+
});
|
|
756
2656
|
}
|
|
757
|
-
|
|
758
|
-
const typeNamespaceId = typeName?.namespace()?.name();
|
|
759
|
-
const typeContractSpaceId = typeName?.space()?.name();
|
|
760
|
-
return {
|
|
761
|
-
kind: "field",
|
|
762
|
-
name,
|
|
763
|
-
node,
|
|
764
|
-
span,
|
|
765
|
-
typeName: typeName?.identifier()?.name() ?? "",
|
|
766
|
-
...typeNamespaceId !== void 0 ? { typeNamespaceId } : {},
|
|
767
|
-
...typeContractSpaceId !== void 0 ? { typeContractSpaceId } : {},
|
|
768
|
-
optional: annotation?.isOptional() ?? false,
|
|
769
|
-
list: annotation?.isList() ?? false,
|
|
770
|
-
...typeConstructor !== void 0 ? { typeConstructor } : {},
|
|
771
|
-
attributes
|
|
772
|
-
};
|
|
2657
|
+
return aliases;
|
|
773
2658
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
...typeConstructor !== void 0 ? { typeConstructor } : {},
|
|
783
|
-
attributes: readResolvedAttributes(node.attributes(), sourceFile)
|
|
784
|
-
};
|
|
2659
|
+
/** The contributed type alias a type reference resolves to, if it resolves to one. */
|
|
2660
|
+
function contributedTypeAliasOf(resolution) {
|
|
2661
|
+
if (resolution?.kind !== "contributedType") return void 0;
|
|
2662
|
+
const { descriptor, path } = resolution.symbol;
|
|
2663
|
+
return descriptor.kind === "typeAlias" ? {
|
|
2664
|
+
name: path.join("."),
|
|
2665
|
+
descriptor
|
|
2666
|
+
} : void 0;
|
|
785
2667
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
2668
|
+
/** The names of the attributes a type alias sets for every field typed by it. */
|
|
2669
|
+
function typeAliasAttributeNames(alias) {
|
|
2670
|
+
if ("symbol" in alias) return new Set(alias.attributes.map(({ name }) => name));
|
|
2671
|
+
const { onCreate, onUpdate } = alias.descriptor.output;
|
|
2672
|
+
return new Set(Object.entries({
|
|
2673
|
+
onCreate,
|
|
2674
|
+
onUpdate
|
|
2675
|
+
}).flatMap(([name, value]) => value === void 0 ? [] : [name]));
|
|
792
2676
|
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
const
|
|
2677
|
+
/** The type alias a field is typed by, if it is typed by one. */
|
|
2678
|
+
function typeAliasOfField(field, binder, aliases) {
|
|
2679
|
+
const node = typeReferenceNode(field);
|
|
2680
|
+
const resolution = node === void 0 ? void 0 : binder.symbolForNode(node);
|
|
2681
|
+
return resolution?.kind === "namedType" ? aliases.get(resolution.symbol) : void 0;
|
|
2682
|
+
}
|
|
2683
|
+
/** The spec context the attributes a type alias carries are read in, as a field's are read in its own. */
|
|
2684
|
+
function typeAliasSpecContext(alias, input) {
|
|
796
2685
|
return {
|
|
797
|
-
|
|
798
|
-
|
|
2686
|
+
symbols: input.symbols,
|
|
2687
|
+
defaultFunctionRegistry: input.defaultFunctionRegistry,
|
|
2688
|
+
generatorFunctions: input.generatorFunctions,
|
|
2689
|
+
dataTypes: input.dataTypes,
|
|
2690
|
+
subject: {
|
|
2691
|
+
kind: "type alias",
|
|
2692
|
+
name: alias.symbol.name
|
|
2693
|
+
},
|
|
2694
|
+
list: false,
|
|
2695
|
+
typeName: alias.baseName,
|
|
2696
|
+
typeResolution: alias.baseResolution,
|
|
2697
|
+
typeConstructor: contributedTypeOf(alias.baseResolution, input.binder)
|
|
799
2698
|
};
|
|
800
2699
|
}
|
|
2700
|
+
/**
|
|
2701
|
+
* Refuses each attribute a field writes that its type alias already carries, at the field's attribute. Returns whether it refused any.
|
|
2702
|
+
*/
|
|
2703
|
+
function refuseRepeatedTypeAliasAttributes(input) {
|
|
2704
|
+
const carried = typeAliasAttributeNames(input.alias);
|
|
2705
|
+
const aliasName = "symbol" in input.alias ? input.alias.symbol.name : input.alias.name;
|
|
2706
|
+
const repeated = input.field.attributes.filter(({ name }) => carried.has(name));
|
|
2707
|
+
const source = diagnosticSource(input.sources, input.field.node.syntax);
|
|
2708
|
+
for (const attribute of repeated) input.diagnostics.push({
|
|
2709
|
+
code: "PSL_DUPLICATE_ATTRIBUTE",
|
|
2710
|
+
message: `Field "${input.fieldPath}" writes @${attribute.name}, which its type alias "${aliasName}" already sets. Remove one of them.`,
|
|
2711
|
+
...source.at(attribute.span)
|
|
2712
|
+
});
|
|
2713
|
+
return repeated.length > 0;
|
|
2714
|
+
}
|
|
801
2715
|
//#endregion
|
|
802
|
-
export { bool, buildSymbolTable, entityRef, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, keywordPslSpan, leafDiagnostic, list, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, num, oneOf, optional, parseQuotedStringLiteral,
|
|
2716
|
+
export { EMPTY_DATA_TYPES, NAME_THE_PSL_SOURCE_LOSES, PSL_UNRESOLVED_REFERENCE, TYPE_ALIAS_ATTRIBUTE_NAMES, assembleAttributeSpecs, blockAttribute, blockSpecContext, blockSpecFactoryOf, bool, buildSymbolTable, contributedTypeAliasOf, contributedTypeCodecId, contributedTypeOf, createBinder, createPslDiagnosticCollector, dataTypeValue, diagnosticFromSpan, diagnosticSource, entityRef, entityReference, enumMemberValue, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, generatorAttributeSpec, generatorFunctionCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, interpretExtensionBlock, interpretExtensionBlockAttributes, interpretExtensionBlocks, isNamespaceLike, isPrismaNextSchema, isPslIdentifier, json, jsonValue, keywordPslSpan, leafDiagnostic, list, mapArg, mapBlock, mapPslDiagnostics, matchesSelector, memberEntries, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, nodeSourceText, num, numLiteral, oneOf, optional, parseQuotedStringLiteral, readExpressionAs, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, readWrittenScalar, record, referencedFieldRef, refineArg, refuseRepeatedTypeAliasAttributes, renameLegacyDirective, resolveTypeAliases, str, structBlock, taggedLiteral, typeAliasAttributeNames, typeAliasOfField, typeAliasSpecContext, typeAttribute, typeAttributeSpecContextOfField, typeAttributeSubjectLabel, typeGeneratorAttributeSpec, typeReferenceNode, writtenList, writtenScalar };
|
|
803
2717
|
|
|
804
2718
|
//# sourceMappingURL=psl-parser.mjs.map
|