@prisma/orm-framework 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +27 -0
- package/dist/abortable-CQO6uG9F.mjs +39 -0
- package/dist/abortable-CQO6uG9F.mjs.map +1 -0
- package/dist/abortable-DBbAaT_4.d.mts +29 -0
- package/dist/abortable-DBbAaT_4.d.mts.map +1 -0
- package/dist/apply-specifier-default-control-policy-CAxiXxKg.d.mts +7 -0
- package/dist/apply-specifier-default-control-policy-CAxiXxKg.d.mts.map +1 -0
- package/dist/apply-specifier-default-control-policy-CsYHsfTF.mjs +12 -0
- package/dist/apply-specifier-default-control-policy-CsYHsfTF.mjs.map +1 -0
- package/dist/array-equal-28xupwIB.mjs +26 -0
- package/dist/array-equal-28xupwIB.mjs.map +1 -0
- package/dist/array-equal-dUd-VPlk.d.mts +22 -0
- package/dist/array-equal-dUd-VPlk.d.mts.map +1 -0
- package/dist/assertions-BEQnOIQd.d.mts +31 -0
- package/dist/assertions-BEQnOIQd.d.mts.map +1 -0
- package/dist/assertions-Cz-GWH8P.mjs +36 -0
- package/dist/assertions-Cz-GWH8P.mjs.map +1 -0
- package/dist/authoring-Dd7p6pTS.d.mts +1 -0
- package/dist/canonical-stringify-Bl6agy_g.d.mts +51 -0
- package/dist/canonical-stringify-Bl6agy_g.d.mts.map +1 -0
- package/dist/canonical-stringify-DY4NaAJi.mjs +104 -0
- package/dist/canonical-stringify-DY4NaAJi.mjs.map +1 -0
- package/dist/canonicalization-DFpB09nP-4OdB2nsy.d.mts +69 -0
- package/dist/canonicalization-DFpB09nP-4OdB2nsy.d.mts.map +1 -0
- package/dist/canonicalization-path-match-CNgHuwM_-CCPBeUuk.mjs +25 -0
- package/dist/canonicalization-path-match-CNgHuwM_-CCPBeUuk.mjs.map +1 -0
- package/dist/capabilities-CPj7MfXO-GRkp0Q_D.mjs +64 -0
- package/dist/capabilities-CPj7MfXO-GRkp0Q_D.mjs.map +1 -0
- package/dist/capabilities-Cupq4-1--C71ORI3N.d.mts +34 -0
- package/dist/capabilities-Cupq4-1--C71ORI3N.d.mts.map +1 -0
- package/dist/casts-D29CHGrr.d.mts +78 -0
- package/dist/casts-D29CHGrr.d.mts.map +1 -0
- package/dist/casts-DpaahrlC-Bd5n2coI.mjs +82 -0
- package/dist/casts-DpaahrlC-Bd5n2coI.mjs.map +1 -0
- package/dist/codec-Cly9VPoA.mjs +78 -0
- package/dist/codec-Cly9VPoA.mjs.map +1 -0
- package/dist/codec-D3GVAkR_.d.mts +116 -0
- package/dist/codec-D3GVAkR_.d.mts.map +1 -0
- package/dist/codec-types-XJO6eC9U-B_K2q0zm.d.mts +221 -0
- package/dist/codec-types-XJO6eC9U-B_K2q0zm.d.mts.map +1 -0
- package/dist/components-CawuxTia.d.mts +1 -0
- package/dist/components.d.mts +20 -0
- package/dist/components.mjs +15 -0
- package/dist/components__authoring.d.mts +3 -0
- package/dist/components__authoring.mjs +2 -0
- package/dist/components__codec.d.mts +3 -0
- package/dist/components__codec.mjs +3 -0
- package/dist/components__components.d.mts +4 -0
- package/dist/components__components.mjs +3 -0
- package/dist/components__control.d.mts +4 -0
- package/dist/components__control.mjs +2 -0
- package/dist/components__emission.d.mts +4 -0
- package/dist/components__emission.mjs +2 -0
- package/dist/components__execution.d.mts +2 -0
- package/dist/components__execution.mjs +2 -0
- package/dist/components__ir.d.mts +3 -0
- package/dist/components__ir.mjs +3 -0
- package/dist/components__psl-ast.d.mts +4 -0
- package/dist/components__psl-ast.mjs +2 -0
- package/dist/components__runtime.d.mts +2 -0
- package/dist/components__runtime.mjs +3 -0
- package/dist/components__utils.d.mts +2 -0
- package/dist/components__utils.mjs +2 -0
- package/dist/config-errors-CBdiX587-DwIyJIX9.mjs +9 -0
- package/dist/config-errors-CBdiX587-DwIyJIX9.mjs.map +1 -0
- package/dist/config-types-Cf9lVsHR.mjs +62 -0
- package/dist/config-types-Cf9lVsHR.mjs.map +1 -0
- package/dist/config-types-W-87vhZ4-BgYaH8YO.d.mts +162 -0
- package/dist/config-types-W-87vhZ4-BgYaH8YO.d.mts.map +1 -0
- package/dist/config-types-zrHI32Om.d.mts +1 -0
- package/dist/config-validation-ByGTw6zQ.mjs +99 -0
- package/dist/config-validation-ByGTw6zQ.mjs.map +1 -0
- package/dist/config-validation-DXggMTZf.d.mts +14 -0
- package/dist/config-validation-DXggMTZf.d.mts.map +1 -0
- package/dist/config.d.mts +4 -0
- package/dist/config.mjs +3 -0
- package/dist/config__config-types.d.mts +3 -0
- package/dist/config__config-types.mjs +2 -0
- package/dist/config__config-validation.d.mts +2 -0
- package/dist/config__config-validation.mjs +2 -0
- package/dist/contract-authoring.d.mts +213 -0
- package/dist/contract-authoring.d.mts.map +1 -0
- package/dist/contract-authoring.mjs +133 -0
- package/dist/contract-authoring.mjs.map +1 -0
- package/dist/contract-types-CkdMH7F7-9EHXSwbH.d.mts +77 -0
- package/dist/contract-types-CkdMH7F7-9EHXSwbH.d.mts.map +1 -0
- package/dist/contract-validation-error-DEiWp_EI-CRwtUgRw.mjs +14 -0
- package/dist/contract-validation-error-DEiWp_EI-CRwtUgRw.mjs.map +1 -0
- package/dist/contract-validation-error-R7cMoK04.d.mts +11 -0
- package/dist/contract-validation-error-R7cMoK04.d.mts.map +1 -0
- package/dist/contract.d.mts +14 -0
- package/dist/contract.mjs +13 -0
- package/dist/contract__apply-specifier-default-control-policy.d.mts +2 -0
- package/dist/contract__apply-specifier-default-control-policy.mjs +2 -0
- package/dist/contract__contract-validation-error.d.mts +2 -0
- package/dist/contract__contract-validation-error.mjs +2 -0
- package/dist/contract__default-namespace.d.mts +2 -0
- package/dist/contract__default-namespace.mjs +2 -0
- package/dist/contract__enum-accessor.d.mts +2 -0
- package/dist/contract__enum-accessor.mjs +2 -0
- package/dist/contract__hashing-utils.d.mts +2 -0
- package/dist/contract__hashing-utils.mjs +3 -0
- package/dist/contract__hashing.d.mts +3 -0
- package/dist/contract__hashing.mjs +2 -0
- package/dist/contract__is-plain-record.d.mts +2 -0
- package/dist/contract__is-plain-record.mjs +2 -0
- package/dist/contract__resolve-domain-model.d.mts +2 -0
- package/dist/contract__resolve-domain-model.mjs +2 -0
- package/dist/contract__types.d.mts +6 -0
- package/dist/contract__types.mjs +5 -0
- package/dist/contract__validate-domain.d.mts +2 -0
- package/dist/contract__validate-domain.mjs +2 -0
- package/dist/control-B87KWI_K-C_R8WfEr.d.mts +213 -0
- package/dist/control-B87KWI_K-C_R8WfEr.d.mts.map +1 -0
- package/dist/control-CBvTj7Ia.d.mts +1383 -0
- package/dist/control-CBvTj7Ia.d.mts.map +1 -0
- package/dist/control-DTouE89s.mjs +621 -0
- package/dist/control-DTouE89s.mjs.map +1 -0
- package/dist/control-Ftiau058-CCeJcAVQ.mjs +284 -0
- package/dist/control-Ftiau058-CCeJcAVQ.mjs.map +1 -0
- package/dist/declarations-DR6To8_k-BFwkCGeP.mjs +1046 -0
- package/dist/declarations-DR6To8_k-BFwkCGeP.mjs.map +1 -0
- package/dist/default-namespace-D4vCwkXg-BaiW8LNK.mjs +39 -0
- package/dist/default-namespace-D4vCwkXg-BaiW8LNK.mjs.map +1 -0
- package/dist/default-namespace-D5X_k6hJ-GH8P1ror.d.mts +26 -0
- package/dist/default-namespace-D5X_k6hJ-GH8P1ror.d.mts.map +1 -0
- package/dist/defined-BQWA85QH-BRSBMULx.mjs +31 -0
- package/dist/defined-BQWA85QH-BRSBMULx.mjs.map +1 -0
- package/dist/defined-BSXuxrnl.d.mts +28 -0
- package/dist/defined-BSXuxrnl.d.mts.map +1 -0
- package/dist/domain-envelope-D6Wn9AmZ-BqZKTT9U.d.mts +359 -0
- package/dist/domain-envelope-D6Wn9AmZ-BqZKTT9U.d.mts.map +1 -0
- package/dist/emission-CeoAV9mj.mjs +26 -0
- package/dist/emission-CeoAV9mj.mjs.map +1 -0
- package/dist/emission-DeoQufVd.d.mts +1 -0
- package/dist/emission-types-hfRVB_Yw-DpQ3hISB.d.mts +75 -0
- package/dist/emission-types-hfRVB_Yw-DpQ3hISB.d.mts.map +1 -0
- package/dist/enum-accessor-Db5DaTNX.mjs +35 -0
- package/dist/enum-accessor-Db5DaTNX.mjs.map +1 -0
- package/dist/enum-accessor-PH5vjghI.d.mts +85 -0
- package/dist/enum-accessor-PH5vjghI.d.mts.map +1 -0
- package/dist/errors.d.mts +4 -0
- package/dist/errors.mjs +4 -0
- package/dist/errors__control.d.mts +2 -0
- package/dist/errors__control.mjs +2 -0
- package/dist/errors__execution.d.mts +2 -0
- package/dist/errors__execution.mjs +2 -0
- package/dist/errors__migration.d.mts +2 -0
- package/dist/errors__migration.mjs +2 -0
- package/dist/execution-BNwBzmRd.mjs +40 -0
- package/dist/execution-BNwBzmRd.mjs.map +1 -0
- package/dist/execution-BbOD4GyR.mjs +164 -0
- package/dist/execution-BbOD4GyR.mjs.map +1 -0
- package/dist/execution-Bo5Bu2Ys.d.mts +79 -0
- package/dist/execution-Bo5Bu2Ys.d.mts.map +1 -0
- package/dist/execution-MOde1lmD.d.mts +98 -0
- package/dist/execution-MOde1lmD.d.mts.map +1 -0
- package/dist/framework-authoring-7YMP9TwM-C9P-N6_a.d.mts +777 -0
- package/dist/framework-authoring-7YMP9TwM-C9P-N6_a.d.mts.map +1 -0
- package/dist/framework-authoring-CDEvlouU-mlMWSksD.mjs +698 -0
- package/dist/framework-authoring-CDEvlouU-mlMWSksD.mjs.map +1 -0
- package/dist/framework-components-D6j4Y5K7-RW9H184y.mjs +27 -0
- package/dist/framework-components-D6j4Y5K7-RW9H184y.mjs.map +1 -0
- package/dist/framework-components-MFoo0sYx-G_6k9jt4.d.mts +388 -0
- package/dist/framework-components-MFoo0sYx-G_6k9jt4.d.mts.map +1 -0
- package/dist/hash-content-Bugg_nZn.mjs +63 -0
- package/dist/hash-content-Bugg_nZn.mjs.map +1 -0
- package/dist/hash-content-DwEUh-Rx.d.mts +59 -0
- package/dist/hash-content-DwEUh-Rx.d.mts.map +1 -0
- package/dist/hashing-BtIZVNYX.mjs +199 -0
- package/dist/hashing-BtIZVNYX.mjs.map +1 -0
- package/dist/hashing-CccSPELN.d.mts +25 -0
- package/dist/hashing-CccSPELN.d.mts.map +1 -0
- package/dist/hashing-utils-DQgS3nOe.mjs +48 -0
- package/dist/hashing-utils-DQgS3nOe.mjs.map +1 -0
- package/dist/hashing-utils-qKu59RSC.d.mts +19 -0
- package/dist/hashing-utils-qKu59RSC.d.mts.map +1 -0
- package/dist/ids.d.mts +44 -0
- package/dist/ids.d.mts.map +1 -0
- package/dist/ids.mjs +96 -0
- package/dist/ids.mjs.map +1 -0
- package/dist/ids__runtime.d.mts +7 -0
- package/dist/ids__runtime.d.mts.map +1 -0
- package/dist/ids__runtime.mjs +31 -0
- package/dist/ids__runtime.mjs.map +1 -0
- package/dist/index-GY2oGH9L.d.mts +120 -0
- package/dist/index-GY2oGH9L.d.mts.map +1 -0
- package/dist/internal-error-BIc-ehme-ouBQPoEL.mjs +24 -0
- package/dist/internal-error-BIc-ehme-ouBQPoEL.mjs.map +1 -0
- package/dist/internal-error-kK8QvlDE.d.mts +19 -0
- package/dist/internal-error-kK8QvlDE.d.mts.map +1 -0
- package/dist/ir-BvE7L9FK.d.mts +359 -0
- package/dist/ir-BvE7L9FK.d.mts.map +1 -0
- package/dist/ir-ChmSSAhX.mjs +200 -0
- package/dist/ir-ChmSSAhX.mjs.map +1 -0
- package/dist/is-plain-record-C9BWiqcw.d.mts +12 -0
- package/dist/is-plain-record-C9BWiqcw.d.mts.map +1 -0
- package/dist/is-plain-record-CUofyVQ7-DWEzdhIx.mjs +16 -0
- package/dist/is-plain-record-CUofyVQ7-DWEzdhIx.mjs.map +1 -0
- package/dist/json-Dkqr3say.d.mts +26 -0
- package/dist/json-Dkqr3say.d.mts.map +1 -0
- package/dist/migration-4VOHVEzx.mjs +118 -0
- package/dist/migration-4VOHVEzx.mjs.map +1 -0
- package/dist/migration-DKbDzBwy.d.mts +74 -0
- package/dist/migration-DKbDzBwy.d.mts.map +1 -0
- package/dist/namespace-id-asbWpwMw-3yxn-tRe.mjs +9 -0
- package/dist/namespace-id-asbWpwMw-3yxn-tRe.mjs.map +1 -0
- package/dist/operations.d.mts +46 -0
- package/dist/operations.d.mts.map +1 -0
- package/dist/operations.mjs +28 -0
- package/dist/operations.mjs.map +1 -0
- package/dist/parse-0ZJjj_2N-WZZ1nlrv.d.mts +427 -0
- package/dist/parse-0ZJjj_2N-WZZ1nlrv.d.mts.map +1 -0
- package/dist/parse-GbZGfMUj-BFSrD2AN.mjs +621 -0
- package/dist/parse-GbZGfMUj-BFSrD2AN.mjs.map +1 -0
- package/dist/promise-D8meygPf.mjs +13 -0
- package/dist/promise-D8meygPf.mjs.map +1 -0
- package/dist/promise-DHJWZv49.d.mts +11 -0
- package/dist/promise-DHJWZv49.d.mts.map +1 -0
- package/dist/psl-ast-BEwO80EH.d.mts +37 -0
- package/dist/psl-ast-BEwO80EH.d.mts.map +1 -0
- package/dist/psl-ast-Chgi8e4o-rSlBk1UV.d.mts +259 -0
- package/dist/psl-ast-Chgi8e4o-rSlBk1UV.d.mts.map +1 -0
- package/dist/psl-ast-DUCvVXbB.mjs +239 -0
- package/dist/psl-ast-DUCvVXbB.mjs.map +1 -0
- package/dist/psl-parser.d.mts +158 -0
- package/dist/psl-parser.d.mts.map +1 -0
- package/dist/psl-parser.mjs +804 -0
- package/dist/psl-parser.mjs.map +1 -0
- package/dist/psl-parser__format.d.mts +12 -0
- package/dist/psl-parser__format.d.mts.map +1 -0
- package/dist/psl-parser__format.mjs +464 -0
- package/dist/psl-parser__format.mjs.map +1 -0
- package/dist/psl-parser__interpret.d.mts +40 -0
- package/dist/psl-parser__interpret.d.mts.map +1 -0
- package/dist/psl-parser__interpret.mjs +25 -0
- package/dist/psl-parser__interpret.mjs.map +1 -0
- package/dist/psl-parser__syntax.d.mts +31 -0
- package/dist/psl-parser__syntax.d.mts.map +1 -0
- package/dist/psl-parser__syntax.mjs +43 -0
- package/dist/psl-parser__syntax.mjs.map +1 -0
- package/dist/psl-parser__tokenizer.d.mts +2 -0
- package/dist/psl-parser__tokenizer.mjs +2 -0
- package/dist/psl-printer.d.mts +37 -0
- package/dist/psl-printer.d.mts.map +1 -0
- package/dist/psl-printer.mjs +393 -0
- package/dist/psl-printer.mjs.map +1 -0
- package/dist/redact-db-url-BlaloOwt.d.mts +22 -0
- package/dist/redact-db-url-BlaloOwt.d.mts.map +1 -0
- package/dist/redact-db-url-CRWJWdB1.mjs +26 -0
- package/dist/redact-db-url-CRWJWdB1.mjs.map +1 -0
- package/dist/resolve-codec-BZF8TZh_-D-xORT9Q.mjs +59 -0
- package/dist/resolve-codec-BZF8TZh_-D-xORT9Q.mjs.map +1 -0
- package/dist/resolve-domain-model-BVSb5wS5-C6Yq0dsD.d.mts +17 -0
- package/dist/resolve-domain-model-BVSb5wS5-C6Yq0dsD.d.mts.map +1 -0
- package/dist/resolve-domain-model-BovPAsW2-8rwyzjxp.mjs +20 -0
- package/dist/resolve-domain-model-BovPAsW2-8rwyzjxp.mjs.map +1 -0
- package/dist/result-Bpupv5vO.d.mts +54 -0
- package/dist/result-Bpupv5vO.d.mts.map +1 -0
- package/dist/result-CBZ8X9mU.mjs +92 -0
- package/dist/result-CBZ8X9mU.mjs.map +1 -0
- package/dist/runtime--RZXG1zP.d.mts +901 -0
- package/dist/runtime--RZXG1zP.d.mts.map +1 -0
- package/dist/runtime-DYTFHGwh.mjs +516 -0
- package/dist/runtime-DYTFHGwh.mjs.map +1 -0
- package/dist/runtime-error-BA9d7XjZ-BlT8t6LB.mjs +40 -0
- package/dist/runtime-error-BA9d7XjZ-BlT8t6LB.mjs.map +1 -0
- package/dist/simplify-deep-Dw9I_ZUl.d.mts +6 -0
- package/dist/simplify-deep-Dw9I_ZUl.d.mts.map +1 -0
- package/dist/structured-error-BVmv2aPB.d.mts +34 -0
- package/dist/structured-error-BVmv2aPB.d.mts.map +1 -0
- package/dist/structured-error-H6WU9Kjt.mjs +31 -0
- package/dist/structured-error-H6WU9Kjt.mjs.map +1 -0
- package/dist/symbol-table-CZ7EVCTL-oYQtrmzq.d.mts +125 -0
- package/dist/symbol-table-CZ7EVCTL-oYQtrmzq.d.mts.map +1 -0
- package/dist/tokenizer-1hAHZzmp-QGPORvmA.mjs +228 -0
- package/dist/tokenizer-1hAHZzmp-QGPORvmA.mjs.map +1 -0
- package/dist/tokenizer-DcYI0Xrq-C-nNE9mE.d.mts +16 -0
- package/dist/tokenizer-DcYI0Xrq-C-nNE9mE.d.mts.map +1 -0
- package/dist/ts-render.d.mts +2 -0
- package/dist/ts-render.mjs +240 -0
- package/dist/ts-render.mjs.map +1 -0
- package/dist/types-ByeQhU9p.d.mts +17 -0
- package/dist/types-ByeQhU9p.d.mts.map +1 -0
- package/dist/types-DGxlljKG.d.mts +7 -0
- package/dist/types-DGxlljKG.d.mts.map +1 -0
- package/dist/types-DgdgskBY.mjs +96 -0
- package/dist/types-DgdgskBY.mjs.map +1 -0
- package/dist/types-import-spec-DRKzrJ20-WYwyCtil.d.mts +14 -0
- package/dist/types-import-spec-DRKzrJ20-WYwyCtil.d.mts.map +1 -0
- package/dist/utils-DMAM0unR.mjs +20 -0
- package/dist/utils-DMAM0unR.mjs.map +1 -0
- package/dist/utils-DeWL_zD9.d.mts +11 -0
- package/dist/utils-DeWL_zD9.d.mts.map +1 -0
- package/dist/utils.d.mts +16 -0
- package/dist/utils.mjs +13 -0
- package/dist/utils__abortable.d.mts +2 -0
- package/dist/utils__abortable.mjs +2 -0
- package/dist/utils__array-equal.d.mts +2 -0
- package/dist/utils__array-equal.mjs +2 -0
- package/dist/utils__assertions.d.mts +2 -0
- package/dist/utils__assertions.mjs +2 -0
- package/dist/utils__canonical-stringify.d.mts +2 -0
- package/dist/utils__canonical-stringify.mjs +2 -0
- package/dist/utils__casts.d.mts +2 -0
- package/dist/utils__casts.mjs +2 -0
- package/dist/utils__defined.d.mts +2 -0
- package/dist/utils__defined.mjs +2 -0
- package/dist/utils__hash-content.d.mts +2 -0
- package/dist/utils__hash-content.mjs +2 -0
- package/dist/utils__internal-error.d.mts +2 -0
- package/dist/utils__internal-error.mjs +2 -0
- package/dist/utils__json.d.mts +2 -0
- package/dist/utils__json.mjs +1 -0
- package/dist/utils__promise.d.mts +2 -0
- package/dist/utils__promise.mjs +2 -0
- package/dist/utils__redact-db-url.d.mts +2 -0
- package/dist/utils__redact-db-url.mjs +2 -0
- package/dist/utils__result.d.mts +2 -0
- package/dist/utils__result.mjs +2 -0
- package/dist/utils__simplify-deep.d.mts +2 -0
- package/dist/utils__simplify-deep.mjs +1 -0
- package/dist/utils__structured-error.d.mts +2 -0
- package/dist/utils__structured-error.mjs +2 -0
- package/dist/utils__types.d.mts +2 -0
- package/dist/utils__types.mjs +1 -0
- package/dist/validate-domain-BNBs-TVv.d.mts +22 -0
- package/dist/validate-domain-BNBs-TVv.d.mts.map +1 -0
- package/dist/validate-domain-BkvFlY3B.mjs +143 -0
- package/dist/validate-domain-BkvFlY3B.mjs.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,901 @@
|
|
|
1
|
+
import { U as PlanMeta } from "./domain-envelope-D6Wn9AmZ-BqZKTT9U.mjs";
|
|
2
|
+
import { r as CodecCallContext } from "./codec-types-XJO6eC9U-B_K2q0zm.mjs";
|
|
3
|
+
//#region ../../../1-framework/1-core/framework-components/dist/runtime.d.mts
|
|
4
|
+
//#region src/annotations.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The kinds of operations an annotation may apply to.
|
|
7
|
+
*
|
|
8
|
+
* - `'read'` — `SELECT` / `find` / `first` / `all` / `count` / aggregates.
|
|
9
|
+
* - `'write'` — `INSERT` / `UPDATE` / `DELETE` / `create` / `update` / `delete` / `upsert`.
|
|
10
|
+
*
|
|
11
|
+
* Annotations declare which kinds they apply to via `defineAnnotation`'s
|
|
12
|
+
* `applicableTo` option; lane terminals enforce the constraint at both the
|
|
13
|
+
* type level (via `ValidAnnotations`) and at runtime (via
|
|
14
|
+
* `assertAnnotationsApplicable`).
|
|
15
|
+
*
|
|
16
|
+
* Finer-grained kinds (`'select' | 'insert' | 'update' | 'delete' | 'upsert'`)
|
|
17
|
+
* are deliberately deferred. The binary covers the common case (the cache
|
|
18
|
+
* middleware applies to reads; an audit annotation would apply to writes;
|
|
19
|
+
* tracing/OTel applies to both). When a real annotation surfaces that needs
|
|
20
|
+
* a finer split, the union widens and existing handles remain typecheckable.
|
|
21
|
+
*/
|
|
22
|
+
type OperationKind = 'read' | 'write';
|
|
23
|
+
/**
|
|
24
|
+
* An applied annotation. Carries the namespace, the typed payload, and the
|
|
25
|
+
* `applicableTo` set the underlying handle declared. The `__annotation`
|
|
26
|
+
* brand lets `read` distinguish branded user annotations from arbitrary
|
|
27
|
+
* data that may happen to live under the same namespace key in
|
|
28
|
+
* `plan.meta.annotations` (e.g. framework-internal metadata such as
|
|
29
|
+
* `meta.annotations.codecs`).
|
|
30
|
+
*
|
|
31
|
+
* Constructed by calling an `AnnotationHandle` directly (e.g.
|
|
32
|
+
* `cacheAnnotation({ ttl: 60 })`); never instantiated by hand.
|
|
33
|
+
*/
|
|
34
|
+
interface AnnotationValue<Payload, Kinds extends OperationKind> {
|
|
35
|
+
readonly __annotation: true;
|
|
36
|
+
readonly namespace: string;
|
|
37
|
+
readonly value: Payload;
|
|
38
|
+
readonly applicableTo: ReadonlySet<Kinds>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Handle returned by `defineAnnotation`. The handle is **callable**: the
|
|
42
|
+
* call signature wraps a `Payload` into an `AnnotationValue` ready to
|
|
43
|
+
* pass to a lane terminal's variadic `annotations` argument. The handle
|
|
44
|
+
* also carries static metadata as own properties:
|
|
45
|
+
*
|
|
46
|
+
* - `namespace` — the namespace string the handle was declared with.
|
|
47
|
+
* - `applicableTo` — the frozen `ReadonlySet<Kinds>` consumed by both
|
|
48
|
+
* the type-level `ValidAnnotations` gate and the runtime
|
|
49
|
+
* `assertAnnotationsApplicable` gate.
|
|
50
|
+
* - `read(plan)` — extract the `Payload` from a plan's `meta.annotations`
|
|
51
|
+
* if a value was previously written under this handle's namespace.
|
|
52
|
+
* Returns `undefined` when the annotation is absent or when the stored
|
|
53
|
+
* value is not a branded `AnnotationValue` (e.g. framework-internal
|
|
54
|
+
* metadata under the same namespace key).
|
|
55
|
+
*
|
|
56
|
+
* Handles are the only supported public entry point for reading and
|
|
57
|
+
* writing annotations. Direct mutation of `plan.meta.annotations` is not
|
|
58
|
+
* part of the public API.
|
|
59
|
+
*
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const cacheAnnotation = defineAnnotation<{ ttl: number }>()({
|
|
62
|
+
* namespace: 'cache',
|
|
63
|
+
* applicableTo: ['read'],
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Call the handle to construct a value:
|
|
67
|
+
* const applied = cacheAnnotation({ ttl: 60 });
|
|
68
|
+
*
|
|
69
|
+
* // Read a stored value off a plan:
|
|
70
|
+
* const payload = cacheAnnotation.read(plan);
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* Note on the inherited `Function.prototype.apply`: because the handle is
|
|
74
|
+
* a function, the property name `apply` resolves to JavaScript's built-in
|
|
75
|
+
* `Function.prototype.apply` (which lets you invoke a function with an
|
|
76
|
+
* array of arguments). This is **not** the construction entry point — to
|
|
77
|
+
* build an `AnnotationValue`, call the handle directly. The
|
|
78
|
+
* `AnnotationHandle` interface deliberately does not declare an `apply`
|
|
79
|
+
* member of its own.
|
|
80
|
+
*/
|
|
81
|
+
interface AnnotationHandle<Payload, Kinds extends OperationKind> {
|
|
82
|
+
(value: Payload): AnnotationValue<Payload, Kinds>;
|
|
83
|
+
readonly namespace: string;
|
|
84
|
+
readonly applicableTo: ReadonlySet<Kinds>;
|
|
85
|
+
read(plan: {
|
|
86
|
+
readonly meta: {
|
|
87
|
+
readonly annotations?: Record<string, unknown>;
|
|
88
|
+
};
|
|
89
|
+
}): Payload | undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Options accepted by `defineAnnotation`.
|
|
93
|
+
*
|
|
94
|
+
* `namespace` is the string key under which the annotation is stored in
|
|
95
|
+
* `plan.meta.annotations`. **Reserved namespaces** include framework-
|
|
96
|
+
* internal metadata keys; user handles must not use them:
|
|
97
|
+
*
|
|
98
|
+
* - `codecs` — used by the SQL emitter to record per-alias codec ids
|
|
99
|
+
* (`meta.annotations.codecs[alias] = 'pg/text@1'`); the SQL runtime's
|
|
100
|
+
* `decodeRow` reads from this key. A user `defineAnnotation('codecs')`
|
|
101
|
+
* handle is not structurally prevented, but its behavior with the
|
|
102
|
+
* emitter and the runtime is undefined and we make no compatibility
|
|
103
|
+
* guarantees about it.
|
|
104
|
+
* - Target-specific keys such as `pg` (and equivalents on other
|
|
105
|
+
* targets) are similarly reserved for adapter / target use.
|
|
106
|
+
*
|
|
107
|
+
* `applicableTo` declares which operation kinds the annotation may attach
|
|
108
|
+
* to. The lane terminals' type-level `ValidAnnotations<K, As>` gate rejects
|
|
109
|
+
* annotations whose `Kinds` does not include the terminal's `K`; the
|
|
110
|
+
* runtime helper `assertAnnotationsApplicable` does the equivalent at
|
|
111
|
+
* runtime so casts and `any` cannot bypass the gate.
|
|
112
|
+
*/
|
|
113
|
+
interface DefineAnnotationOptions<Kinds extends OperationKind> {
|
|
114
|
+
readonly namespace: string;
|
|
115
|
+
readonly applicableTo: readonly Kinds[];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Defines a typed annotation handle.
|
|
119
|
+
*
|
|
120
|
+
* Two-step call form. The first step takes the `Payload` type argument
|
|
121
|
+
* (TypeScript cannot infer `Payload` from anything in the options, so it
|
|
122
|
+
* must be supplied explicitly); the second step takes the runtime options
|
|
123
|
+
* and infers `Kinds` from the `applicableTo` array via a `const` type
|
|
124
|
+
* parameter, so the operation kinds appear exactly once at the call site.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Read-only annotation. Lane terminals like `db.User.first(...)` accept
|
|
129
|
+
* // it; `db.User.create(...)` rejects it at the type level.
|
|
130
|
+
* const cacheAnnotation = defineAnnotation<{ ttl?: number; skip?: boolean }>()({
|
|
131
|
+
* namespace: 'cache',
|
|
132
|
+
* applicableTo: ['read'],
|
|
133
|
+
* }); // Kinds inferred as 'read'
|
|
134
|
+
*
|
|
135
|
+
* // Write-only annotation. Mirror image.
|
|
136
|
+
* const auditAnnotation = defineAnnotation<{ actor: string }>()({
|
|
137
|
+
* namespace: 'audit',
|
|
138
|
+
* applicableTo: ['write'],
|
|
139
|
+
* }); // Kinds inferred as 'write'
|
|
140
|
+
*
|
|
141
|
+
* // Annotation applicable to both kinds (e.g. tracing).
|
|
142
|
+
* const otelAnnotation = defineAnnotation<{ traceId: string }>()({
|
|
143
|
+
* namespace: 'otel',
|
|
144
|
+
* applicableTo: ['read', 'write'],
|
|
145
|
+
* }); // Kinds inferred as 'read' | 'write'
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* **Reserved namespaces.** See `DefineAnnotationOptions.namespace` for the
|
|
149
|
+
* list of framework-internal namespaces (`codecs`, target-specific keys).
|
|
150
|
+
* `defineAnnotation` does not structurally prevent a user from naming a
|
|
151
|
+
* reserved namespace, but the framework makes no compatibility guarantee
|
|
152
|
+
* about handles that do.
|
|
153
|
+
*/
|
|
154
|
+
declare function defineAnnotation<Payload>(): <const Kinds extends OperationKind>(options: DefineAnnotationOptions<Kinds>) => AnnotationHandle<Payload, Kinds>;
|
|
155
|
+
/**
|
|
156
|
+
* Type-level applicability gate consumed by lane terminals.
|
|
157
|
+
*
|
|
158
|
+
* Maps a tuple of `AnnotationValue`s to a tuple where each element either
|
|
159
|
+
* keeps its annotation type (when the annotation's declared `Kinds`
|
|
160
|
+
* includes the terminal's operation kind `K`) or resolves to `never`
|
|
161
|
+
* (when the kinds are incompatible). A `never` element makes the entire
|
|
162
|
+
* tuple unassignable, surfacing the mismatch as a type error at the call
|
|
163
|
+
* site of the terminal.
|
|
164
|
+
*
|
|
165
|
+
* The SQL DSL builders constrain their variadic `...annotations`
|
|
166
|
+
* parameter via `As & ValidAnnotations<K, As>`. **The intersection is
|
|
167
|
+
* load-bearing** — see the note below. The ORM terminals deliberately
|
|
168
|
+
* sidestep this trick by taking one annotation per `meta.annotate(...)`
|
|
169
|
+
* call (no variadic-tuple inference involved), so `ValidAnnotations` is
|
|
170
|
+
* consumed only by the SQL DSL today.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* class SelectQuery<Row> {
|
|
175
|
+
* annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(
|
|
176
|
+
* ...annotations: As & ValidAnnotations<'read', As>
|
|
177
|
+
* ): SelectQuery<Row>;
|
|
178
|
+
* }
|
|
179
|
+
*
|
|
180
|
+
* class InsertQuery<Row> {
|
|
181
|
+
* annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(
|
|
182
|
+
* ...annotations: As & ValidAnnotations<'write', As>
|
|
183
|
+
* ): InsertQuery<Row>;
|
|
184
|
+
* }
|
|
185
|
+
*
|
|
186
|
+
* db.users.select('id').annotate(cacheAnnotation({ ttl: 60 }));
|
|
187
|
+
* // ✓ cacheAnnotation declares 'read'; SelectQuery.annotate requires 'read'.
|
|
188
|
+
*
|
|
189
|
+
* db.users.insert([{ name: 'Alice' }]).annotate(cacheAnnotation({ ttl: 60 }));
|
|
190
|
+
* // ✗ cacheAnnotation declares 'read'; InsertQuery.annotate requires 'write'.
|
|
191
|
+
* // Element resolves to `never` → tuple unassignable → type error.
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* **Why `As & ValidAnnotations<K, As>` and not `ValidAnnotations<K, As>`
|
|
195
|
+
* alone.** TypeScript's variadic-tuple inference is too forgiving when
|
|
196
|
+
* the parameter type refers to `As` only through `ValidAnnotations`: it
|
|
197
|
+
* will pick an `As` that makes the call valid even when the gated tuple
|
|
198
|
+
* would contain `never` for an inapplicable element. The intersection
|
|
199
|
+
* pins `As` to the actual call-site tuple AND requires it to be
|
|
200
|
+
* assignable to the gated form. A `never` element in the gated tuple
|
|
201
|
+
* then collapses the corresponding intersection position to `never`,
|
|
202
|
+
* and the inapplicable argument fails to assign — surfacing the mismatch
|
|
203
|
+
* as a type error at the call site.
|
|
204
|
+
*
|
|
205
|
+
* The runtime helper `assertAnnotationsApplicable` covers the equivalent
|
|
206
|
+
* check at runtime so casts and `any` cannot bypass this gate.
|
|
207
|
+
*/
|
|
208
|
+
type ValidAnnotations<K extends OperationKind, As extends readonly AnnotationValue<unknown, OperationKind>[]> = { readonly [I in keyof As]: As[I] extends AnnotationValue<infer P, infer Kinds> ? K extends Kinds ? AnnotationValue<P, Kinds> : never : never; };
|
|
209
|
+
/**
|
|
210
|
+
* Runtime applicability gate. Throws `RUNTIME.ANNOTATION_INAPPLICABLE` if
|
|
211
|
+
* any annotation in `annotations` declares an `applicableTo` set that does
|
|
212
|
+
* not include `kind`. Used by lane terminals (SQL DSL builders' `.build()`,
|
|
213
|
+
* ORM `Collection` terminals) to fail closed when the type-level
|
|
214
|
+
* `ValidAnnotations` gate is bypassed via cast / `any` / dynamic
|
|
215
|
+
* invocation.
|
|
216
|
+
*
|
|
217
|
+
* Passes silently on:
|
|
218
|
+
* - empty arrays
|
|
219
|
+
* - annotations whose `applicableTo` includes `kind`
|
|
220
|
+
*
|
|
221
|
+
* Throws on:
|
|
222
|
+
* - any annotation whose `applicableTo` does not include `kind`. The
|
|
223
|
+
* error names the offending annotation's `namespace` and the
|
|
224
|
+
* `terminalName` so users can locate the misuse.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* // Inside an ORM read terminal:
|
|
229
|
+
* assertAnnotationsApplicable(annotations, 'read', 'first');
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
declare function assertAnnotationsApplicable(annotations: readonly AnnotationValue<unknown, OperationKind>[], kind: OperationKind, terminalName: string): void;
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/execution/async-iterable-result.d.ts
|
|
235
|
+
declare class AsyncIterableResult<Row> implements AsyncIterable<Row>, PromiseLike<Row[]> {
|
|
236
|
+
private readonly generator;
|
|
237
|
+
private consumed;
|
|
238
|
+
private consumedBy;
|
|
239
|
+
private bufferedArrayPromise;
|
|
240
|
+
constructor(generator: AsyncGenerator<Row, void, unknown>);
|
|
241
|
+
[Symbol.asyncIterator](): AsyncIterator<Row>;
|
|
242
|
+
toArray(): Promise<Row[]>;
|
|
243
|
+
first(): Promise<Row | null>;
|
|
244
|
+
firstOrThrow(): Promise<Row>;
|
|
245
|
+
then<TResult1 = Row[], TResult2 = never>(onfulfilled?: ((value: Row[]) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/execution/query-plan.d.ts
|
|
249
|
+
/**
|
|
250
|
+
* Family-agnostic plan marker.
|
|
251
|
+
*
|
|
252
|
+
* Carries only `meta` (the family-agnostic plan metadata) and the optional
|
|
253
|
+
* phantom `_row` parameter that lets type-level utilities recover the row
|
|
254
|
+
* type from a plan value. SQL and Mongo extend this marker with their own
|
|
255
|
+
* concrete shapes (`SqlQueryPlan`, `MongoQueryPlan`).
|
|
256
|
+
*
|
|
257
|
+
* `QueryPlan` is the *pre-lowering* marker — i.e. the surface a builder
|
|
258
|
+
* produces before family-specific lowering turns it into an executable
|
|
259
|
+
* plan (`ExecutionPlan`).
|
|
260
|
+
*/
|
|
261
|
+
interface QueryPlan<Row = unknown> {
|
|
262
|
+
readonly meta: PlanMeta;
|
|
263
|
+
/**
|
|
264
|
+
* Phantom property to carry the Row generic for type-level utilities.
|
|
265
|
+
* Not set at runtime; used only for `ResultType` extraction.
|
|
266
|
+
*/
|
|
267
|
+
readonly _row?: Row;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Family-agnostic execution-plan marker.
|
|
271
|
+
*
|
|
272
|
+
* Extends `QueryPlan` with no additional structural fields — the marker
|
|
273
|
+
* exists to nominally distinguish executable plans from pre-lowering plans
|
|
274
|
+
* in the type system. Family-specific execution plans (`SqlExecutionPlan`,
|
|
275
|
+
* `MongoExecutionPlan`) extend this marker with their concrete shapes
|
|
276
|
+
* (e.g. `sql + params` for SQL, `wireCommand` for Mongo).
|
|
277
|
+
*/
|
|
278
|
+
interface ExecutionPlan<Row = unknown> extends QueryPlan<Row> {}
|
|
279
|
+
/**
|
|
280
|
+
* Extracts the `Row` type from a plan via the phantom `_row` property.
|
|
281
|
+
*
|
|
282
|
+
* Works with any plan that extends `QueryPlan<Row>` — including
|
|
283
|
+
* `ExecutionPlan<Row>`, `SqlQueryPlan<Row>`, `SqlExecutionPlan<Row>`,
|
|
284
|
+
* `MongoQueryPlan<Row>`, and `MongoExecutionPlan<Row>`.
|
|
285
|
+
*
|
|
286
|
+
* The `_row` property must be present in the plan's static type for the
|
|
287
|
+
* conditional to bind `R`; objects whose type lacks `_row` resolve to
|
|
288
|
+
* `never`. Without the `keyof` guard, `extends { _row?: infer R }` would
|
|
289
|
+
* silently match any object and infer `unknown`.
|
|
290
|
+
*
|
|
291
|
+
* Example: `type Row = ResultType<typeof plan>`.
|
|
292
|
+
*/
|
|
293
|
+
type ResultType<P> = '_row' extends keyof P ? P extends {
|
|
294
|
+
readonly _row?: infer R;
|
|
295
|
+
} ? R : never : never;
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/execution/runtime-middleware.d.ts
|
|
298
|
+
interface RuntimeLog {
|
|
299
|
+
info(event: unknown): void;
|
|
300
|
+
warn(event: unknown): void;
|
|
301
|
+
error(event: unknown): void;
|
|
302
|
+
debug?(event: unknown): void;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Per-execute context threaded through every middleware phase
|
|
306
|
+
* (`beforeExecute`, `onRow`, `afterExecute`). Allocated once per
|
|
307
|
+
* `runtime.execute()` call and shared by reference across all
|
|
308
|
+
* middleware in the chain.
|
|
309
|
+
*
|
|
310
|
+
* - `signal` carries the per-query `AbortSignal` -- the same
|
|
311
|
+
* reference that `runtime.execute(plan, { signal })` was invoked
|
|
312
|
+
* with, and the same reference threaded into the per-call
|
|
313
|
+
* `CodecCallContext` (ADR 207). Middleware that wraps a
|
|
314
|
+
* network-backed SDK forwards `ctx.signal` into that SDK to
|
|
315
|
+
* propagate caller cancellation; pure-CPU middleware ignores it.
|
|
316
|
+
*
|
|
317
|
+
* Symmetric plumbing across all middleware phases (rather than only
|
|
318
|
+
* `beforeExecute`) is a deliberate choice: a middleware that wraps a
|
|
319
|
+
* downstream observability hook or post-processor in `afterExecute` /
|
|
320
|
+
* `onRow` needs the same cancellation reach as its `beforeExecute`
|
|
321
|
+
* counterpart.
|
|
322
|
+
*/
|
|
323
|
+
interface RuntimeMiddlewareContext {
|
|
324
|
+
readonly contract: unknown;
|
|
325
|
+
readonly mode: 'strict' | 'permissive';
|
|
326
|
+
readonly now: () => number;
|
|
327
|
+
readonly log: RuntimeLog;
|
|
328
|
+
/**
|
|
329
|
+
* Returns a stable string identifying the (storage, statement, params)
|
|
330
|
+
* tuple of an execution. Two semantically equivalent executions return
|
|
331
|
+
* the same string. Used by middleware that need per-execution identity
|
|
332
|
+
* (caching, request coalescing).
|
|
333
|
+
*
|
|
334
|
+
* The family runtime owns the implementation:
|
|
335
|
+
* - SQL: `meta.storageHash` + `exec.sql` + `canonicalStringify(exec.params)`
|
|
336
|
+
* - Mongo: `meta.storageHash` + `canonicalStringify({ ...exec.command })`
|
|
337
|
+
*
|
|
338
|
+
* The method is `async` because the underlying digest helper
|
|
339
|
+
* (`hashContent`) uses the WebCrypto API, whose `crypto.subtle.digest`
|
|
340
|
+
* primitive is asynchronous by design.
|
|
341
|
+
*
|
|
342
|
+
* The returned string is intended to be consumed directly as a `Map` key
|
|
343
|
+
* — it is not (and should not be) further hashed by callers.
|
|
344
|
+
*/
|
|
345
|
+
contentHash(exec: ExecutionPlan): Promise<string>;
|
|
346
|
+
/**
|
|
347
|
+
* Per-execute cancellation signal threaded through every middleware
|
|
348
|
+
* phase. Middleware that wraps async work or downstream cancellable
|
|
349
|
+
* primitives should observe this and abort early when the consumer
|
|
350
|
+
* cancels.
|
|
351
|
+
*/
|
|
352
|
+
readonly signal?: AbortSignal;
|
|
353
|
+
/**
|
|
354
|
+
* Identifies the queryable scope this execution is running under.
|
|
355
|
+
*
|
|
356
|
+
* - `'runtime'` — top-level `runtime.execute(plan)`. The default scope
|
|
357
|
+
* used by the standard read/write paths.
|
|
358
|
+
* - `'connection'` — `connection.execute(plan)` after
|
|
359
|
+
* `runtime.connection()` checked out a connection from the pool.
|
|
360
|
+
* - `'transaction'` — `transaction.execute(plan)` inside an explicit
|
|
361
|
+
* transaction, or a query routed through `withTransaction`.
|
|
362
|
+
*
|
|
363
|
+
* Middleware that should only act at the top level read this field to
|
|
364
|
+
* bypass non-runtime scopes. The cache middleware uses it to skip
|
|
365
|
+
* caching inside transactions (where read-after-write coherence is the
|
|
366
|
+
* caller's expectation) and dedicated connections (where the user has
|
|
367
|
+
* explicitly stepped outside the shared cache surface). Observers that
|
|
368
|
+
* don't care about the scope can ignore the field.
|
|
369
|
+
*
|
|
370
|
+
* Family runtimes populate this at context-construction time per
|
|
371
|
+
* scope. Existing middleware that ignore the field are unaffected.
|
|
372
|
+
*/
|
|
373
|
+
readonly scope: 'runtime' | 'connection' | 'transaction';
|
|
374
|
+
/**
|
|
375
|
+
* Identity for one `execute()` call. The runtime mints a fresh value via
|
|
376
|
+
* `crypto.randomUUID()` when it constructs the per-execute context, and
|
|
377
|
+
* the same context reference is threaded through every middleware phase
|
|
378
|
+
* (`beforeExecute`, `intercept`, `onRow`, `afterExecute`). Every hook in
|
|
379
|
+
* one execute call therefore observes the same `planExecutionId`; two
|
|
380
|
+
* executions of the same plan observe distinct values. Use this to
|
|
381
|
+
* correlate observations across the lifecycle of a single execute call
|
|
382
|
+
* (tracing, timing, audit). See ADR 220.
|
|
383
|
+
*/
|
|
384
|
+
readonly planExecutionId: string;
|
|
385
|
+
}
|
|
386
|
+
interface AfterExecuteResult {
|
|
387
|
+
readonly rowCount: number;
|
|
388
|
+
readonly latencyMs: number;
|
|
389
|
+
readonly completed: boolean;
|
|
390
|
+
/**
|
|
391
|
+
* Indicates where the rows observed during this execution came from.
|
|
392
|
+
*
|
|
393
|
+
* - `'driver'` — the default. Rows came from the underlying driver via
|
|
394
|
+
* `runDriver` / `runWithMiddleware`'s normal path.
|
|
395
|
+
* - `'middleware'` — a `RuntimeMiddleware.intercept` hook short-circuited
|
|
396
|
+
* execution and supplied the rows directly. The driver was not invoked.
|
|
397
|
+
*
|
|
398
|
+
* Observers (telemetry, lints, budgets) that need to distinguish between
|
|
399
|
+
* driver-served and middleware-served executions read this field.
|
|
400
|
+
* Observers that don't care can ignore it.
|
|
401
|
+
*/
|
|
402
|
+
readonly source: 'driver' | 'middleware';
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Result of a successful `RuntimeMiddleware.intercept` hook.
|
|
406
|
+
*
|
|
407
|
+
* Carries the rows that the middleware wishes to return in place of
|
|
408
|
+
* invoking the driver. The runtime iterates `rows` in order and yields
|
|
409
|
+
* each row to the consumer; `beforeExecute`, `runDriver`, and `onRow` are
|
|
410
|
+
* all skipped on the hit path. `afterExecute` still fires with
|
|
411
|
+
* `source: 'middleware'`.
|
|
412
|
+
*
|
|
413
|
+
* `rows` accepts both `Iterable` (arrays, sync generators) and
|
|
414
|
+
* `AsyncIterable` (async generators). `for await` natively handles both
|
|
415
|
+
* via `Symbol.asyncIterator` / `Symbol.iterator` fallback, so the
|
|
416
|
+
* orchestrator does not need to branch on the variant. Cached arrays in
|
|
417
|
+
* the cache middleware are the common case; streaming variants support
|
|
418
|
+
* future use cases like mock layers replaying recordings.
|
|
419
|
+
*
|
|
420
|
+
* Row shape is `Record<string, unknown>` — the same untyped shape
|
|
421
|
+
* `onRow` receives. The SQL runtime decodes intercepted rows through its
|
|
422
|
+
* normal codec pass, so interceptors cache and return raw (undecoded)
|
|
423
|
+
* rows.
|
|
424
|
+
*/
|
|
425
|
+
interface InterceptResult {
|
|
426
|
+
readonly rows: AsyncIterable<Record<string, unknown>> | Iterable<Record<string, unknown>>;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Marker interface for family-specific param-ref mutators threaded into
|
|
430
|
+
* `beforeExecute` as the third argument. The framework treats the mutator
|
|
431
|
+
* opaquely — it allocates and forwards the family's mutator instance so
|
|
432
|
+
* `runWithMiddleware` can stay family-agnostic. SQL extends this with
|
|
433
|
+
* `SqlParamRefMutator` (over `ParamRef`); Mongo extends with
|
|
434
|
+
* `MongoParamRefMutator` (over `MongoParamRef`).
|
|
435
|
+
*
|
|
436
|
+
* Extension authors target the family-specific mutator type, not this
|
|
437
|
+
* marker.
|
|
438
|
+
*/
|
|
439
|
+
declare const PARAM_REF_MUTATOR_BRAND: unique symbol;
|
|
440
|
+
type ParamRefMutator = {
|
|
441
|
+
readonly [PARAM_REF_MUTATOR_BRAND]?: never;
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* Family-agnostic middleware SPI parameterized over the plan marker.
|
|
445
|
+
*
|
|
446
|
+
* `TPlan` defaults to the framework `QueryPlan` marker so a generic
|
|
447
|
+
* middleware (e.g. cross-family telemetry) can be authored without
|
|
448
|
+
* naming a family. Family-specific middleware (`SqlMiddleware`,
|
|
449
|
+
* `MongoMiddleware`) narrow `TPlan` to their concrete plan type.
|
|
450
|
+
*
|
|
451
|
+
* `TMutator` is the family-specific {@link ParamRefMutator} the runtime
|
|
452
|
+
* threads into `beforeExecute(plan, ctx, params)` as a third argument.
|
|
453
|
+
* Existing `(plan)` / `(plan, ctx)` middleware bodies continue to compile
|
|
454
|
+
* — TypeScript permits assigning a function with fewer parameters to a
|
|
455
|
+
* function-typed slot that declares more. The third arg is additive.
|
|
456
|
+
*/
|
|
457
|
+
interface RuntimeMiddleware<TPlan extends QueryPlan = QueryPlan, TMutator extends ParamRefMutator = ParamRefMutator> {
|
|
458
|
+
readonly name: string;
|
|
459
|
+
readonly familyId?: string;
|
|
460
|
+
readonly targetId?: string;
|
|
461
|
+
/**
|
|
462
|
+
* Optional short-circuit hook. Runs inside `runWithMiddleware`, after
|
|
463
|
+
* the orchestrator receives the lowered plan and before any
|
|
464
|
+
* `beforeExecute` hook fires. Middleware run in registration order; the
|
|
465
|
+
* first to return a non-`undefined` `InterceptResult` wins, and
|
|
466
|
+
* subsequent middleware's `intercept` does not fire.
|
|
467
|
+
*
|
|
468
|
+
* On a hit, `beforeExecute`, `runDriver`, and `onRow` are all skipped.
|
|
469
|
+
* `afterExecute` still fires with `source: 'middleware'`.
|
|
470
|
+
*
|
|
471
|
+
* Returning `undefined` (or omitting the hook entirely) signals
|
|
472
|
+
* passthrough — execution proceeds through the normal driver path.
|
|
473
|
+
*
|
|
474
|
+
* Errors thrown inside `intercept` are rethrown by `runWithMiddleware`
|
|
475
|
+
* as the original `Error` — no envelope is guaranteed at this layer.
|
|
476
|
+
* Before rethrowing, `afterExecute` fires with `completed: false` and
|
|
477
|
+
* `source: 'middleware'`. Errors thrown by `afterExecute` during the
|
|
478
|
+
* error path remain swallowed (existing semantics, unchanged).
|
|
479
|
+
*
|
|
480
|
+
* Used by middleware that need to short-circuit execution and supply
|
|
481
|
+
* rows directly: caching, mocks, rate limiting, circuit breaking.
|
|
482
|
+
*/
|
|
483
|
+
intercept?(plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<InterceptResult | undefined>;
|
|
484
|
+
/**
|
|
485
|
+
* Fires after the family runtime has produced a draft execution
|
|
486
|
+
* plan from the AST, but before the family encodes parameter values
|
|
487
|
+
* to driver wire format. Mutations applied via the
|
|
488
|
+
* family-specific `params` mutator are visible to the subsequent
|
|
489
|
+
* encode step.
|
|
490
|
+
*
|
|
491
|
+
* Lifecycle position (SQL example):
|
|
492
|
+
* `runBeforeCompile → lowerSqlPlan → beforeExecute → encodeParams → intercept → driver`.
|
|
493
|
+
*
|
|
494
|
+
* The `params` argument is a family-specific {@link ParamRefMutator}
|
|
495
|
+
* scoped to the value slots of `ParamRef` nodes in the plan's AST.
|
|
496
|
+
* Middleware that doesn't need to mutate params can ignore the
|
|
497
|
+
* argument; existing `(plan)` / `(plan, ctx)` bodies stay compatible.
|
|
498
|
+
*
|
|
499
|
+
* `ctx.signal` carries the per-query `AbortSignal`; middleware that
|
|
500
|
+
* wraps a network SDK forwards it. Cooperative cancellation
|
|
501
|
+
* surfaces a `RUNTIME.ABORTED { phase: 'beforeExecute' }` envelope
|
|
502
|
+
* promptly even when the body ignores the signal.
|
|
503
|
+
*
|
|
504
|
+
* Intercept ordering: `intercept` runs *after* this hook; an
|
|
505
|
+
* interceptor that short-circuits the driver path still observes
|
|
506
|
+
* the post-`beforeExecute`, fully-encoded plan. The trade-off is
|
|
507
|
+
* that any `beforeExecute` SDK round-trips happen even when a
|
|
508
|
+
* downstream interceptor would have skipped the driver entirely.
|
|
509
|
+
*/
|
|
510
|
+
beforeExecute?(plan: TPlan, ctx: RuntimeMiddlewareContext, params?: TMutator): void | Promise<void>;
|
|
511
|
+
onRow?(row: Record<string, unknown>, plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<void>;
|
|
512
|
+
afterExecute?(plan: TPlan, result: AfterExecuteResult, ctx: RuntimeMiddlewareContext): Promise<void>;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Cross-family middleware — one that doesn't constrain `familyId` or
|
|
516
|
+
* `targetId` and is therefore compatible with any family runtime's
|
|
517
|
+
* middleware array (`SqlMiddleware[]`, `MongoMiddleware[]`, etc.).
|
|
518
|
+
*
|
|
519
|
+
* The intersection `RuntimeMiddleware & { familyId?: undefined; targetId?: undefined }`
|
|
520
|
+
* pins both optional properties to exactly `undefined` (intersecting
|
|
521
|
+
* `string | undefined` with `undefined` collapses to `undefined`). Under
|
|
522
|
+
* `exactOptionalPropertyTypes: true`, the plain `RuntimeMiddleware` shape
|
|
523
|
+
* — with `familyId?: string` — is *not* assignable to `SqlMiddleware`
|
|
524
|
+
* (which narrows `familyId?: 'sql'`) because `string` is wider than
|
|
525
|
+
* `'sql'`. Pinning the property to `undefined` makes the value a subtype
|
|
526
|
+
* of every narrowed variant: `undefined` extends both `'sql' | undefined`
|
|
527
|
+
* and `'mongo' | undefined`, so a `CrossFamilyMiddleware` value drops
|
|
528
|
+
* into a SQL or Mongo middleware slot without a cast.
|
|
529
|
+
*
|
|
530
|
+
* Cross-family middleware factories (`createCacheMiddleware`, future
|
|
531
|
+
* `audit` / OTel middleware) declare this as their return type so the
|
|
532
|
+
* cross-family typing is named once rather than re-spelled at every call
|
|
533
|
+
* site.
|
|
534
|
+
*/
|
|
535
|
+
type CrossFamilyMiddleware<TPlan extends QueryPlan = QueryPlan> = RuntimeMiddleware<TPlan> & {
|
|
536
|
+
readonly familyId?: undefined;
|
|
537
|
+
readonly targetId?: undefined;
|
|
538
|
+
};
|
|
539
|
+
/**
|
|
540
|
+
* Optional per-`execute` options accepted by every family runtime.
|
|
541
|
+
*
|
|
542
|
+
* `signal` is the per-query cancellation signal. The runtime threads the
|
|
543
|
+
* signal through to every codec call for the query and uses it to short-
|
|
544
|
+
* circuit the row stream with `RUNTIME.ABORTED` when the caller aborts.
|
|
545
|
+
* Omitting the option (or passing `undefined`) preserves today's behavior
|
|
546
|
+
* bit-for-bit.
|
|
547
|
+
*/
|
|
548
|
+
interface RuntimeExecuteOptions {
|
|
549
|
+
readonly signal?: AbortSignal;
|
|
550
|
+
readonly scope?: 'runtime' | 'connection' | 'transaction';
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Cross-family SPI for any runtime that can execute plans and be shut down.
|
|
554
|
+
* Each family runtime (SQL, Mongo) satisfies this interface — SQL nominally,
|
|
555
|
+
* Mongo structurally (due to its phantom Row parameter using a unique symbol).
|
|
556
|
+
*
|
|
557
|
+
* The `_row` intersection on `execute` connects the `Row` type parameter to the
|
|
558
|
+
* plan, mirroring how `QueryPlan<Row>` carries a phantom `_row?: Row`.
|
|
559
|
+
*/
|
|
560
|
+
interface RuntimeExecutor<TPlan extends QueryPlan> {
|
|
561
|
+
execute<Row>(plan: TPlan & {
|
|
562
|
+
readonly _row?: Row;
|
|
563
|
+
}, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
|
|
564
|
+
close(): Promise<void>;
|
|
565
|
+
}
|
|
566
|
+
declare function checkMiddlewareCompatibility(middleware: RuntimeMiddleware, runtimeFamilyId: string, runtimeTargetId: string): void;
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region src/execution/before-execute-chain.d.ts
|
|
569
|
+
/**
|
|
570
|
+
* Runs every middleware's `beforeExecute` hook in registration order,
|
|
571
|
+
* threading through the (optional) family-specific `paramsMutator`.
|
|
572
|
+
*
|
|
573
|
+
* Why this lives outside {@link runWithMiddleware}: middleware that
|
|
574
|
+
* mutates parameter values (e.g. cipherstash's bulk-encrypt SDK
|
|
575
|
+
* round-trip) must run *before* the family runtime encodes those
|
|
576
|
+
* parameters to driver wire format. Family runtimes call
|
|
577
|
+
* `runBeforeExecuteChain` between the AST → plan lowering step and
|
|
578
|
+
* the parameter encode step; the encode then observes the mutator's
|
|
579
|
+
* `currentParams()` view. `runWithMiddleware` retains the rest of
|
|
580
|
+
* the lifecycle (`intercept`, driver/row source loop, `onRow`,
|
|
581
|
+
* `afterExecute`) but no longer fires `beforeExecute` itself.
|
|
582
|
+
*
|
|
583
|
+
* Lifecycle within this helper:
|
|
584
|
+
*
|
|
585
|
+
* 1. For each middleware in registration order, if `beforeExecute`
|
|
586
|
+
* is implemented:
|
|
587
|
+
* - `checkAborted(ctx, 'beforeExecute')` short-circuits if the
|
|
588
|
+
* caller already aborted at entry.
|
|
589
|
+
* - The hook is invoked with `(plan, ctx, paramsMutator)`. A
|
|
590
|
+
* middleware body that ignores the mutator stays compatible —
|
|
591
|
+
* JavaScript allows extra positional arguments.
|
|
592
|
+
* - If the hook returns a Promise, it is raced against
|
|
593
|
+
* `ctx.signal` via {@link raceAgainstAbort} so cooperative
|
|
594
|
+
* cancellation surfaces a `RUNTIME.ABORTED { phase:
|
|
595
|
+
* 'beforeExecute' }` envelope even when the body itself
|
|
596
|
+
* ignores the signal.
|
|
597
|
+
*
|
|
598
|
+
* Error propagation: any error thrown by a `beforeExecute` body
|
|
599
|
+
* (or surfaced by the abort race) propagates out of this helper
|
|
600
|
+
* unchanged. The family runtime is responsible for converting it
|
|
601
|
+
* into the appropriate `afterExecute(completed: false)` notification
|
|
602
|
+
* once `runWithMiddleware` runs.
|
|
603
|
+
*
|
|
604
|
+
* Relationship to {@link runWithMiddleware}: the framework's
|
|
605
|
+
* `RuntimeCore.execute` template calls this helper between
|
|
606
|
+
* `lower(plan)` and `runWithMiddleware(...)`. Family runtimes that
|
|
607
|
+
* override `execute` (e.g. SQL, which inlines lower + encode for
|
|
608
|
+
* direct mutator threading) call this helper themselves at the
|
|
609
|
+
* equivalent point — between the family's AST → draft-plan
|
|
610
|
+
* lowering and the parameter-encode step.
|
|
611
|
+
*
|
|
612
|
+
* Intercept ordering: this helper fires unconditionally before
|
|
613
|
+
* `runWithMiddleware`. `intercept` (inside `runWithMiddleware`)
|
|
614
|
+
* therefore observes the post-`beforeExecute` plan — mutator
|
|
615
|
+
* mutations are visible in the params interceptors see. The
|
|
616
|
+
* trade-off is documented on `RuntimeMiddleware.intercept`.
|
|
617
|
+
*/
|
|
618
|
+
declare function runBeforeExecuteChain<TExec extends ExecutionPlan, TMutator extends ParamRefMutator = ParamRefMutator>(plan: TExec, middleware: ReadonlyArray<RuntimeMiddleware<TExec, TMutator>>, ctx: RuntimeMiddlewareContext, paramsMutator?: TMutator): Promise<void>;
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region src/shared/runtime-error.d.ts
|
|
621
|
+
interface RuntimeErrorEnvelope extends Error {
|
|
622
|
+
readonly code: string;
|
|
623
|
+
readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME' | 'DRIVER' | 'MIGRATION' | 'ORM';
|
|
624
|
+
readonly severity: 'error';
|
|
625
|
+
readonly details?: Record<string, unknown>;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Type guard for the runtime-error envelope produced by `runtimeError`.
|
|
629
|
+
*
|
|
630
|
+
* Prefer this over duck-typing on `error.code` directly so consumers stay
|
|
631
|
+
* insulated from the envelope's internal shape.
|
|
632
|
+
*/
|
|
633
|
+
declare function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope;
|
|
634
|
+
declare function runtimeError(code: string, message: string, details?: Record<string, unknown>): RuntimeErrorEnvelope;
|
|
635
|
+
//#endregion
|
|
636
|
+
//#region src/execution/runtime-error.d.ts
|
|
637
|
+
/**
|
|
638
|
+
* Stable code emitted by the runtime when an in-flight `execute()`
|
|
639
|
+
* is cancelled via the per-query `AbortSignal`. The envelope's
|
|
640
|
+
* `details.phase` distinguishes where the abort was observed:
|
|
641
|
+
*
|
|
642
|
+
* - `'encode'` — abort fired during `encodeParams` (SQL) or
|
|
643
|
+
* `resolveValue` (Mongo).
|
|
644
|
+
* - `'decode'` — abort fired during `decodeRow` / `decodeField`.
|
|
645
|
+
* - `'stream'` — abort fired between rows or before any codec call
|
|
646
|
+
* (already-aborted at entry).
|
|
647
|
+
* - `'beforeExecute'` / `'afterExecute'` / `'onRow'` — abort fired
|
|
648
|
+
* on entry to or during the corresponding middleware phase
|
|
649
|
+
* (cooperative cancellation per the param-transform seam).
|
|
650
|
+
*/
|
|
651
|
+
declare const RUNTIME_ABORTED: "RUNTIME.ABORTED";
|
|
652
|
+
/** Discriminator placed in `details.phase` of a `RUNTIME.ABORTED` envelope. */
|
|
653
|
+
type RuntimeAbortedPhase = 'encode' | 'decode' | 'stream' | 'beforeExecute' | 'afterExecute' | 'onRow';
|
|
654
|
+
/**
|
|
655
|
+
* Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the
|
|
656
|
+
* abort was observed — codec call sites (`encode` / `decode` / `stream`)
|
|
657
|
+
* or middleware seams (`beforeExecute` / `afterExecute` / `onRow`), as
|
|
658
|
+
* enumerated on {@link RuntimeAbortedPhase}. Cause carries
|
|
659
|
+
* `signal.reason` verbatim from the platform — native abort produces a
|
|
660
|
+
* `DOMException`, explicit `controller.abort(reason)` produces whatever
|
|
661
|
+
* the caller passed. No synthesis happens here.
|
|
662
|
+
*/
|
|
663
|
+
declare function runtimeAborted(phase: RuntimeAbortedPhase, cause?: unknown): RuntimeErrorEnvelope;
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region src/execution/race-against-abort.d.ts
|
|
666
|
+
/**
|
|
667
|
+
* Throw a phase-tagged `RUNTIME.ABORTED` envelope if the supplied
|
|
668
|
+
* context is already aborted at the precheck site. Centralises the
|
|
669
|
+
* `if (ctx.signal?.aborted) throw runtimeAborted(...)` pattern that
|
|
670
|
+
* every codec dispatch site (and the `beforeExecute` middleware phase)
|
|
671
|
+
* repeats. Accepts both the framework `CodecCallContext` and the
|
|
672
|
+
* `RuntimeMiddlewareContext`; both expose `signal?: AbortSignal`.
|
|
673
|
+
*/
|
|
674
|
+
declare function checkAborted(ctx: {
|
|
675
|
+
readonly signal?: AbortSignal;
|
|
676
|
+
}, phase: RuntimeAbortedPhase): void;
|
|
677
|
+
/**
|
|
678
|
+
* Race a per-cell `Promise.all` (or any other in-flight work promise) against
|
|
679
|
+
* the supplied abort signal so the runtime returns `RUNTIME.ABORTED` promptly
|
|
680
|
+
* even when codec bodies ignore the signal. In-flight bodies that ignore the
|
|
681
|
+
* signal are abandoned and run to completion in the background — the
|
|
682
|
+
* cooperative-cancellation contract documented in ADR 204.
|
|
683
|
+
*
|
|
684
|
+
* Call sites still SHOULD pre-check `signal.aborted` and short-circuit with
|
|
685
|
+
* a phase-tagged `RUNTIME.ABORTED` envelope before invoking this helper —
|
|
686
|
+
* that path is the canonical "aborted at entry" surface and avoids
|
|
687
|
+
* scheduling the work promise. As a defensive belt-and-braces, this helper
|
|
688
|
+
* also handles the already-aborted case internally: `AbortSignal` does not
|
|
689
|
+
* replay past abort events to listeners registered after the abort, so we
|
|
690
|
+
* inspect `signal.aborted` synchronously and reject with the sentinel
|
|
691
|
+
* before installing the listener. The rejection is still attributed to the
|
|
692
|
+
* abort path via the sentinel-identity check.
|
|
693
|
+
*
|
|
694
|
+
* Distinguishing the rejection source is load-bearing for AC-ERR4
|
|
695
|
+
* (`RUNTIME.ENCODE_FAILED` / `RUNTIME.DECODE_FAILED` pass through unchanged).
|
|
696
|
+
* The semantically equivalent `abortable(signal)` helper in
|
|
697
|
+
* `@internal/utils` rejects with `signal.reason ?? new DOMException(...)`,
|
|
698
|
+
* which is not stably distinguishable from a codec-thrown error by identity
|
|
699
|
+
* alone (a fresh fallback DOMException is allocated per call). We instead
|
|
700
|
+
* track abort attribution with a unique sentinel: only the `onAbort` listener
|
|
701
|
+
* installed here ever rejects with the sentinel, so an `error === sentinel`
|
|
702
|
+
* identity check after the race is unambiguous.
|
|
703
|
+
*
|
|
704
|
+
* Lives in `framework-components` (rather than the SQL family, where it
|
|
705
|
+
* originated in m2) so every family runtime that needs cooperative
|
|
706
|
+
* cancellation around a codec-dispatch `Promise.all` (SQL encode + decode
|
|
707
|
+
* today, Mongo encode in m3) shares the same attribution logic.
|
|
708
|
+
*/
|
|
709
|
+
declare function raceAgainstAbort<T>(work: Promise<T>, signal: AbortSignal | undefined, phase: RuntimeAbortedPhase): Promise<T>;
|
|
710
|
+
//#endregion
|
|
711
|
+
//#region src/execution/run-with-middleware.d.ts
|
|
712
|
+
/**
|
|
713
|
+
* Drives a single execution of `runDriver()` through the middleware
|
|
714
|
+
* lifecycle's intercept + row-source + termination phases.
|
|
715
|
+
*
|
|
716
|
+
* Lifecycle, in order:
|
|
717
|
+
* 1. For each middleware in registration order: `intercept(exec, ctx)`. The
|
|
718
|
+
* first non-`undefined` result wins; subsequent middleware's `intercept`
|
|
719
|
+
* does not fire. On a hit, the runtime emits a `middleware.intercept`
|
|
720
|
+
* debug event naming the winning middleware, switches the row source to
|
|
721
|
+
* the intercepted rows, and proceeds with `source: 'middleware'`. On
|
|
722
|
+
* all-passthrough (every `intercept` returns `undefined` or is omitted),
|
|
723
|
+
* `source: 'driver'` is used and the row source is `runDriver()`.
|
|
724
|
+
* 2. Iterate the row source. On the driver path, for each row, for each
|
|
725
|
+
* middleware in registration order: `onRow(row, exec, ctx)`; then yield
|
|
726
|
+
* the row. On the intercepted hit path, `onRow` is skipped — intercepted
|
|
727
|
+
* rows did not originate from a driver row stream — but rows are still
|
|
728
|
+
* yielded to the consumer in order.
|
|
729
|
+
* 3. On successful completion: for each middleware in registration order:
|
|
730
|
+
* `afterExecute(exec, { rowCount, latencyMs, completed: true, source },
|
|
731
|
+
* ctx)`.
|
|
732
|
+
* 4. On any error thrown during steps 1–2: for each middleware in
|
|
733
|
+
* registration order: `afterExecute(exec, { rowCount, latencyMs,
|
|
734
|
+
* completed: false, source }, ctx)`. Errors thrown by `afterExecute`
|
|
735
|
+
* during the error path are swallowed so they do not mask the original
|
|
736
|
+
* error. The original error is then rethrown.
|
|
737
|
+
*
|
|
738
|
+
* `beforeExecute` is **not** fired here — see
|
|
739
|
+
* {@link runBeforeExecuteChain} in `before-execute-chain.ts`. Family
|
|
740
|
+
* runtimes call that helper between the AST → plan lowering step and
|
|
741
|
+
* the parameter encode step so middleware that mutates ParamRef
|
|
742
|
+
* values (e.g. cipherstash bulk-encrypt) can have its mutations
|
|
743
|
+
* visible to encode. `runWithMiddleware` operates on the fully-
|
|
744
|
+
* encoded plan; interceptors therefore observe a fully-mutated,
|
|
745
|
+
* encoded plan.
|
|
746
|
+
*
|
|
747
|
+
* The `source` field on `AfterExecuteResult` lets observers (telemetry,
|
|
748
|
+
* lints, budgets) distinguish driver-served from middleware-served
|
|
749
|
+
* executions without needing their own out-of-band signal.
|
|
750
|
+
*
|
|
751
|
+
* This helper is the single canonical implementation of the
|
|
752
|
+
* intercept-and-row-source loop; family runtimes should not
|
|
753
|
+
* reimplement it.
|
|
754
|
+
*/
|
|
755
|
+
declare function runWithMiddleware<TExec extends ExecutionPlan, Row>(exec: TExec, middleware: ReadonlyArray<RuntimeMiddleware<TExec>>, ctx: RuntimeMiddlewareContext, runDriver: () => AsyncIterable<Row>): AsyncIterableResult<Row>;
|
|
756
|
+
//#endregion
|
|
757
|
+
//#region src/execution/runtime-core.d.ts
|
|
758
|
+
/**
|
|
759
|
+
* Constructor options shared by every concrete `RuntimeCore` subclass.
|
|
760
|
+
*
|
|
761
|
+
* Family runtimes typically build the middleware list and the
|
|
762
|
+
* `RuntimeMiddlewareContext` themselves (running compatibility checks,
|
|
763
|
+
* narrowing the context's `contract` field, etc.) before calling `super`.
|
|
764
|
+
*/
|
|
765
|
+
interface RuntimeCoreOptions<TMiddleware extends RuntimeMiddleware<ExecutionPlan>> {
|
|
766
|
+
readonly middleware: ReadonlyArray<TMiddleware>;
|
|
767
|
+
readonly ctx: RuntimeMiddlewareContext;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Family-agnostic abstract runtime base.
|
|
771
|
+
*
|
|
772
|
+
* Defines the entire `execute(plan)` template in one place:
|
|
773
|
+
*
|
|
774
|
+
* 1. `runBeforeCompile(plan)` — concrete; defaults to identity. SQL overrides
|
|
775
|
+
* this to run its `beforeCompile` middleware-hook chain.
|
|
776
|
+
* 2. `lower(plan)` — abstract. Each family produces its `*ExecutionPlan`
|
|
777
|
+
* (SQL via `lowerSqlPlan`, Mongo via `adapter.lower`).
|
|
778
|
+
* 3. `runBeforeExecuteChain(exec, this.middleware, this.ctx)` — concrete;
|
|
779
|
+
* runs every middleware's `beforeExecute` hook after lowering but
|
|
780
|
+
* before the row source is opened. Family runtimes that need a
|
|
781
|
+
* params mutator visible to a downstream encode step (SQL) override
|
|
782
|
+
* `execute` and call this helper themselves at the equivalent
|
|
783
|
+
* pre-encode point.
|
|
784
|
+
* 4. `runWithMiddleware(exec, this.middleware, this.ctx,
|
|
785
|
+
* () => runDriver(exec))` — concrete; runs the intercept chain,
|
|
786
|
+
* drives the row source, fires `onRow` / `afterExecute`. Does
|
|
787
|
+
* **not** fire `beforeExecute` — see step 3.
|
|
788
|
+
*
|
|
789
|
+
* Concrete subclasses must implement `lower`, `runDriver`, and `close`.
|
|
790
|
+
*
|
|
791
|
+
* The class is generic over:
|
|
792
|
+
* - `TPlan` — the family's pre-lowering plan type.
|
|
793
|
+
* - `TExec` — the family's post-lowering (executable) plan type.
|
|
794
|
+
* - `TMiddleware` — the family's middleware type. Constrained to
|
|
795
|
+
* `RuntimeMiddleware<TExec>` because `runWithMiddleware` invokes the
|
|
796
|
+
* `beforeExecute` / `onRow` / `afterExecute` hooks with the lowered
|
|
797
|
+
* `TExec`. (The spec/plan wording "RuntimeMiddleware<TPlan>" is
|
|
798
|
+
* tightened to `<TExec>` here so the helper call typechecks; the
|
|
799
|
+
* intent is unchanged — middleware sees the post-lowering plan.)
|
|
800
|
+
*/
|
|
801
|
+
declare abstract class RuntimeCore<TPlan extends QueryPlan, TExec extends ExecutionPlan, TMiddleware extends RuntimeMiddleware<TExec>> implements RuntimeExecutor<TPlan> {
|
|
802
|
+
protected readonly middleware: ReadonlyArray<TMiddleware>;
|
|
803
|
+
protected readonly ctx: RuntimeMiddlewareContext;
|
|
804
|
+
constructor(options: RuntimeCoreOptions<TMiddleware>);
|
|
805
|
+
/**
|
|
806
|
+
* Pre-lowering hook for plan rewriting. Defaults to identity. Subclasses
|
|
807
|
+
* may override to run a `beforeCompile` middleware chain (SQL does this
|
|
808
|
+
* to support typed AST rewrites — see `before-compile-chain.ts`).
|
|
809
|
+
*/
|
|
810
|
+
protected runBeforeCompile(plan: TPlan): TPlan | Promise<TPlan>;
|
|
811
|
+
/**
|
|
812
|
+
* Lower a pre-lowering `TPlan` into the family's executable `TExec`.
|
|
813
|
+
* Family-specific: SQL produces `{ sql, params, ast?, ... }`; Mongo
|
|
814
|
+
* produces `{ command, ... }`.
|
|
815
|
+
*
|
|
816
|
+
* `ctx` carries per-query cancellation (and any future fields on
|
|
817
|
+
* `CodecCallContext`); concrete subclasses forward it to the
|
|
818
|
+
* encode-side codec dispatch site (e.g. SQL's `encodeParams` in m2,
|
|
819
|
+
* Mongo's `resolveValue` in m3). The runtime allocates one ctx per
|
|
820
|
+
* `execute()` call and threads the same reference everywhere; the
|
|
821
|
+
* `signal` field inside may be `undefined`, but the ctx object itself
|
|
822
|
+
* is always present.
|
|
823
|
+
*/
|
|
824
|
+
protected abstract lower(plan: TPlan, ctx: CodecCallContext): TExec | Promise<TExec>;
|
|
825
|
+
/**
|
|
826
|
+
* Drive the underlying transport for a lowered `TExec`. Yields raw rows
|
|
827
|
+
* directly from the driver as `Record<string, unknown>`; codec decoding
|
|
828
|
+
* (if any) is the subclass's responsibility, applied by wrapping
|
|
829
|
+
* `execute()` rather than living inside this hook.
|
|
830
|
+
*
|
|
831
|
+
* The `Row` type parameter on `execute()` is satisfied by the caller via
|
|
832
|
+
* the plan's phantom `_row`; the runtime treats rows as opaque records
|
|
833
|
+
* here and trusts the caller's row typing.
|
|
834
|
+
*/
|
|
835
|
+
protected abstract runDriver(exec: TExec): AsyncIterable<Record<string, unknown>>;
|
|
836
|
+
abstract close(): Promise<void>;
|
|
837
|
+
execute<Row>(plan: TPlan & {
|
|
838
|
+
readonly _row?: Row;
|
|
839
|
+
}, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
|
|
840
|
+
}
|
|
841
|
+
//#endregion
|
|
842
|
+
//#region src/meta-builder.d.ts
|
|
843
|
+
/**
|
|
844
|
+
* Per-terminal meta configurator handed to user callbacks. The terminal's
|
|
845
|
+
* operation kind `K` is fixed by the terminal that constructed the builder;
|
|
846
|
+
* `annotate(...)` accepts only annotations whose declared `Kinds` include
|
|
847
|
+
* `K`.
|
|
848
|
+
*
|
|
849
|
+
* The conditional parameter type
|
|
850
|
+
* `K extends Kinds ? AnnotationValue<P, Kinds> : never` collapses to `never`
|
|
851
|
+
* for inapplicable annotations, surfacing the mismatch as a type error at
|
|
852
|
+
* the call site of `meta.annotate(...)`. No variadic-tuple inference is
|
|
853
|
+
* involved — TypeScript infers `Kinds` from the annotation argument and
|
|
854
|
+
* checks the conditional directly.
|
|
855
|
+
*
|
|
856
|
+
* The runtime gate inside `annotate` (via
|
|
857
|
+
* `assertAnnotationsApplicable`) catches cast / `any` / dynamic bypasses
|
|
858
|
+
* and throws `RUNTIME.ANNOTATION_INAPPLICABLE`.
|
|
859
|
+
*
|
|
860
|
+
* `annotate` returns the builder for chaining; the return value of the
|
|
861
|
+
* configurator callback is unused, so both block-body and expression-body
|
|
862
|
+
* callbacks compile.
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```typescript
|
|
866
|
+
* await db.User.find({ id }, (meta) => meta.annotate(cacheAnnotation({ ttl: 60 })));
|
|
867
|
+
* await db.User.create(input, (meta) => {
|
|
868
|
+
* meta.annotate(auditAnnotation({ actor: 'system' }));
|
|
869
|
+
* meta.annotate(otelAnnotation({ traceId }));
|
|
870
|
+
* });
|
|
871
|
+
* ```
|
|
872
|
+
*/
|
|
873
|
+
interface MetaBuilder<K extends OperationKind> {
|
|
874
|
+
annotate<P, Kinds extends OperationKind>(annotation: K extends Kinds ? AnnotationValue<P, Kinds> : never): this;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Lane-side view of a meta builder. Extends the public `MetaBuilder<K>`
|
|
878
|
+
* surface with `annotations` so lane terminals can read the recorded map
|
|
879
|
+
* after invoking the user configurator.
|
|
880
|
+
*
|
|
881
|
+
* Lane terminals construct one of these via `createMetaBuilder(kind, terminalName)`,
|
|
882
|
+
* pass it to the user callback as `MetaBuilder<K>` (the narrower public
|
|
883
|
+
* view), then read `meta.annotations` to thread the recorded values into
|
|
884
|
+
* `plan.meta.annotations`.
|
|
885
|
+
*/
|
|
886
|
+
interface LaneMetaBuilder<K extends OperationKind> extends MetaBuilder<K> {
|
|
887
|
+
readonly annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Construct a lane-side meta builder for a terminal of operation kind `K`.
|
|
891
|
+
*
|
|
892
|
+
* Lane terminals call this with their `kind` (`'read'` or `'write'`) and a
|
|
893
|
+
* `terminalName` for error messages, hand the resulting builder to the
|
|
894
|
+
* user-supplied configurator callback (typed as `MetaBuilder<K>`, the
|
|
895
|
+
* narrower public view), and read `meta.annotations` afterwards to thread
|
|
896
|
+
* the recorded values into `plan.meta.annotations`.
|
|
897
|
+
*/
|
|
898
|
+
declare function createMetaBuilder<K extends OperationKind>(kind: K, terminalName: string): LaneMetaBuilder<K>;
|
|
899
|
+
//#endregion
|
|
900
|
+
export { defineAnnotation as A, RuntimeMiddleware as C, checkAborted as D, assertAnnotationsApplicable as E, runtimeAborted as F, runtimeError as I, raceAgainstAbort as M, runBeforeExecuteChain as N, checkMiddlewareCompatibility as O, runWithMiddleware as P, RuntimeLog as S, ValidAnnotations as T, RuntimeCore as _, CrossFamilyMiddleware as a, RuntimeExecuteOptions as b, InterceptResult as c, OperationKind as d, ParamRefMutator as f, RuntimeAbortedPhase as g, ResultType as h, AsyncIterableResult as i, isRuntimeError as j, createMetaBuilder as k, LaneMetaBuilder as l, RUNTIME_ABORTED as m, AnnotationHandle as n, DefineAnnotationOptions as o, QueryPlan as p, AnnotationValue as r, ExecutionPlan as s, AfterExecuteResult as t, MetaBuilder as u, RuntimeCoreOptions as v, RuntimeMiddlewareContext as w, RuntimeExecutor as x, RuntimeErrorEnvelope as y };
|
|
901
|
+
//# sourceMappingURL=runtime--RZXG1zP.d.mts.map
|