deepline 0.3.546 → 0.3.547
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/dist/bundling-sources/sdk/src/client-core.ts +13 -0
- package/dist/bundling-sources/sdk/src/index.ts +7 -1
- package/dist/bundling-sources/sdk/src/integrations.ts +17 -7
- package/dist/bundling-sources/sdk/src/play.ts +71 -0
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +13 -4
- package/dist/bundling-sources/sdk/src/types.ts +33 -0
- package/dist/bundling-sources/shared_libs/integration-contracts/calendar-delegation.ts +7 -0
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +2 -0
- package/dist/bundling-sources/shared_libs/monitors/tracking-provider-guidance.ts +1 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +19 -1
- package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +17 -2
- package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +57 -5
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +295 -52
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +10 -1
- package/dist/bundling-sources/shared_libs/play-runtime/docflow-decision-tracker.ts +135 -0
- package/dist/bundling-sources/shared_libs/play-runtime/docflow-fail-open.ts +177 -0
- package/dist/bundling-sources/shared_libs/play-runtime/docflow-node-io.ts +99 -2
- package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +16 -10
- package/dist/bundling-sources/shared_libs/play-runtime/fenced-call-diagnostics.ts +211 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +52 -14
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +21 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +18 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +68 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +11 -3
- package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +9 -1
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +48 -0
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +6 -1
- package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +716 -51
- package/dist/bundling-sources/shared_libs/plays/docflow-decision-arms.ts +146 -0
- package/dist/bundling-sources/shared_libs/plays/docflow-flow-order.ts +94 -0
- package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +10 -1
- package/dist/bundling-sources/shared_libs/plays/docflow.ts +787 -117
- package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +8 -2
- package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +6 -0
- package/dist/bundling-sources/shared_libs/plays/trigger-config-contract.ts +13 -0
- package/dist/bundling-sources/shared_libs/product-notifications/billing-sales.ts +25 -0
- package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +56 -0
- package/dist/cli/auth-AC5277PI.js +43 -0
- package/dist/cli/{auth-KFWG72AZ.mjs → auth-WJEY4IDX.mjs} +5 -5
- package/dist/cli/{billing-OQVOAZ4S.js → billing-IJITDDRQ.js} +96 -96
- package/dist/cli/{billing-MMZ336HO.mjs → billing-PHJUDYF3.mjs} +10 -10
- package/dist/cli/{chunk-TBWYZOSV.js → chunk-2AHY47SI.js} +3 -3
- package/dist/cli/{chunk-MXQP7CXZ.js → chunk-2HPTLBNB.js} +3 -3
- package/dist/cli/{chunk-TI6DTURF.js → chunk-4WAM6TLD.js} +7 -1
- package/dist/cli/{chunk-JARZ47OP.mjs → chunk-56MEAGWA.mjs} +2 -2
- package/dist/cli/{chunk-GYTSDSQD.mjs → chunk-5SFHPMBY.mjs} +11 -11
- package/dist/cli/{chunk-Z3UEBFIN.js → chunk-ABLTVG3J.js} +41 -41
- package/dist/cli/{chunk-LX2TC3HO.mjs → chunk-AEQ5VWZ5.mjs} +4 -4
- package/dist/cli/{chunk-MI7X6V6V.mjs → chunk-CKIRKYW7.mjs} +3 -3
- package/dist/cli/{chunk-2JHYYB3F.js → chunk-CSPHSNBW.js} +3 -3
- package/dist/cli/{chunk-IVWU7SJC.js → chunk-D6OIEH47.js} +5 -5
- package/dist/cli/{chunk-KUK7ARXA.mjs → chunk-DIUNDLSX.mjs} +2 -2
- package/dist/cli/{chunk-RO66FPTS.mjs → chunk-DJI5CLLW.mjs} +1 -1
- package/dist/cli/{chunk-LIJKRDDG.js → chunk-DZC7LMYM.js} +6 -6
- package/dist/cli/{chunk-UQJBV5PM.js → chunk-E2OIYPB4.js} +10 -10
- package/dist/cli/{chunk-JA633HRV.mjs → chunk-ECUD4QPD.mjs} +3 -3
- package/dist/cli/{chunk-VPERQ3U6.mjs → chunk-ESCVHDNY.mjs} +5 -5
- package/dist/cli/{chunk-JVOUQFHT.js → chunk-FFBXLFKV.js} +1 -1
- package/dist/cli/{chunk-3DUNNZB6.mjs → chunk-FMQXAOVE.mjs} +4 -4
- package/dist/cli/{chunk-HXIR3VQL.mjs → chunk-FZHMNK6F.mjs} +7 -1
- package/dist/cli/{chunk-PU3ZAG6V.mjs → chunk-G6KW764N.mjs} +1 -1
- package/dist/cli/{chunk-EEG46QZY.mjs → chunk-G6XTCG3J.mjs} +2 -2
- package/dist/cli/{chunk-EEJHB76U.js → chunk-GIGAYLY6.js} +12 -12
- package/dist/cli/{chunk-BLYW6FFB.js → chunk-GJA2PRHJ.js} +2 -2
- package/dist/cli/{chunk-H7Q5IDO3.js → chunk-GJOGFWX3.js} +20 -20
- package/dist/cli/{chunk-6Y5TU3R7.mjs → chunk-GPAWLXW3.mjs} +1 -1
- package/dist/cli/{chunk-5W4ENHWM.js → chunk-GZFZZQL4.js} +285 -264
- package/dist/cli/{chunk-P7A3H6G5.mjs → chunk-HARZ4AAX.mjs} +1 -1
- package/dist/cli/{chunk-MEGHIX4M.js → chunk-HFIFKP3A.js} +5 -5
- package/dist/cli/{chunk-LHE2TSV6.mjs → chunk-IGAK22XO.mjs} +1 -1
- package/dist/cli/{chunk-VTK3HGMN.mjs → chunk-IKYN6PLO.mjs} +5 -5
- package/dist/cli/{chunk-UREAIHUU.mjs → chunk-ITLZBDSR.mjs} +3 -3
- package/dist/cli/{chunk-6LG7MLJ2.js → chunk-IVFFCAV2.js} +44 -44
- package/dist/cli/{chunk-SYTWWVIQ.js → chunk-K3GMDSUX.js} +5 -5
- package/dist/cli/{chunk-WKHPLBJK.js → chunk-L5J6UJ2X.js} +15 -15
- package/dist/cli/{chunk-X5KOHDJN.mjs → chunk-L6QE2XVM.mjs} +1 -1
- package/dist/cli/{chunk-SH32HL7I.js → chunk-LMLSOHTU.js} +53 -53
- package/dist/cli/{chunk-JCWNF44W.js → chunk-MBQELFL7.js} +22 -22
- package/dist/cli/{chunk-Z7SXGOIQ.mjs → chunk-MF7PCM6C.mjs} +1 -1
- package/dist/cli/{chunk-F2VEFMU5.js → chunk-MO7TGNXB.js} +13 -13
- package/dist/cli/{chunk-7ZW67ME6.mjs → chunk-MOZEAGSR.mjs} +1 -1
- package/dist/cli/{chunk-5VNQMVCU.js → chunk-N63U5CRG.js} +26 -26
- package/dist/cli/{chunk-JCH4UNNS.js → chunk-NBYFQZ6O.js} +2 -2
- package/dist/cli/{chunk-BTFUAGHC.js → chunk-OVYXYTEP.js} +16 -16
- package/dist/cli/{chunk-J65HJCJO.mjs → chunk-PBMO36BP.mjs} +2 -2
- package/dist/cli/{chunk-F5YQXCP3.js → chunk-PVQCX6KQ.js} +50 -7
- package/dist/cli/{chunk-K2XELBPF.mjs → chunk-QLE3QKJ2.mjs} +5 -5
- package/dist/cli/{chunk-VAT2SXFF.js → chunk-QU3K3IY6.js} +12 -12
- package/dist/cli/{chunk-JYG4XZLT.js → chunk-REAFIEV5.js} +99 -99
- package/dist/cli/{chunk-5OEFXAKP.mjs → chunk-RMCCB3XY.mjs} +50 -7
- package/dist/cli/{chunk-HJR2DDJS.mjs → chunk-RXRC2COC.mjs} +2 -2
- package/dist/cli/{chunk-4AZLGNXV.js → chunk-SAJWYN4B.js} +4 -4
- package/dist/cli/{chunk-VXTTAYOT.mjs → chunk-TNJG4ZPN.mjs} +3 -3
- package/dist/cli/{chunk-PMDHY2YK.js → chunk-VNOQEDVC.js} +7 -7
- package/dist/cli/{chunk-GOOF7E2B.mjs → chunk-VPF54TXQ.mjs} +5 -5
- package/dist/cli/{chunk-2HSZCQMT.mjs → chunk-WYT3H6JD.mjs} +1 -1
- package/dist/cli/{chunk-OAKWSLKS.mjs → chunk-XMBVHJPR.mjs} +28 -7
- package/dist/cli/{chunk-7MY7KWJS.mjs → chunk-XNTDTAKC.mjs} +1 -1
- package/dist/cli/{chunk-5V7NZKGG.js → chunk-YURGAKI3.js} +2 -2
- package/dist/cli/{chunk-ND7SFRQL.js → chunk-YVKLF7RW.js} +2 -2
- package/dist/cli/{chunk-6FBDTYR2.mjs → chunk-Z2YGQZWV.mjs} +2 -2
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{concurrent-runs-help-C2O5YKQA.mjs → concurrent-runs-help-ZNGP563R.mjs} +6 -6
- package/dist/cli/concurrent-runs-help-ZYISYOQA.js +21 -0
- package/dist/cli/{csv-Z4DNGR54.mjs → csv-VAHQHYYV.mjs} +4 -4
- package/dist/cli/{csv-MJDNOIQJ.js → csv-X6D4ZELE.js} +13 -13
- package/dist/cli/{db-4RL2BNOF.mjs → db-4G4S2VOV.mjs} +7 -7
- package/dist/cli/{db-S5QVPK5E.js → db-YA5ZGVEX.js} +28 -28
- package/dist/cli/{describe-L4P5SZLQ.mjs → describe-EVXEM2S6.mjs} +19 -19
- package/dist/cli/describe-GYYSLZLV.js +50 -0
- package/dist/cli/describe-core.d.mts +4 -4
- package/dist/cli/describe-core.d.ts +4 -4
- package/dist/cli/{executions-MFZ2Z36O.js → executions-5YC7ABF6.js} +9 -9
- package/dist/cli/{executions-RR6O3XK5.mjs → executions-HR6CTN5M.mjs} +7 -7
- package/dist/cli/{feedback-EQBQ3ABB.mjs → feedback-GEU5SPLR.mjs} +6 -6
- package/dist/cli/{feedback-YDAG7VH2.js → feedback-MJHSYLFF.js} +14 -14
- package/dist/cli/git-FZIQZNI4.js +25 -0
- package/dist/cli/{git-YGLCCU35.mjs → git-NPFF6QUS.mjs} +5 -5
- package/dist/cli/index.js +146 -146
- package/dist/cli/index.mjs +45 -45
- package/dist/cli/{integrations-IQXYMRMW.js → integrations-YPHFI77G.js} +19 -17
- package/dist/cli/{integrations-FWYXSBHK.mjs → integrations-Z7EGVBHF.mjs} +11 -9
- package/dist/cli/{legacy-noops-U7LI7UXC.js → legacy-noops-246E3KKG.js} +9 -9
- package/dist/cli/{legacy-noops-I4YRIX5F.mjs → legacy-noops-5IYCFWWX.mjs} +6 -6
- package/dist/cli/{mcp-QJBMB6VS.mjs → mcp-WUYGZXPI.mjs} +4 -4
- package/dist/cli/{mcp-GX2UKKWU.js → mcp-YTYTW67G.js} +24 -24
- package/dist/cli/{monitors-Z6EGKYJP.mjs → monitors-73DQKCU7.mjs} +26 -8
- package/dist/cli/{monitors-WCJYINGX.js → monitors-SA6ILD6Z.js} +119 -101
- package/dist/cli/{org-NNHICBR2.mjs → org-WVQRB2KX.mjs} +7 -7
- package/dist/cli/{org-7SKG423N.js → org-X7ELDV7B.js} +89 -89
- package/dist/cli/{play-CXDFPJ7Z.mjs → play-QI6V2EUQ.mjs} +295 -67
- package/dist/cli/{play-4P4DTG3Q.js → play-QTYOAJPE.js} +897 -669
- package/dist/cli/{providers-VQLQ7DTR.mjs → providers-DPVMVDS4.mjs} +7 -7
- package/dist/cli/{providers-EE4TUE3O.js → providers-XXFLVREV.js} +10 -10
- package/dist/cli/{quickstart-RVXHK4WA.js → quickstart-33ISXQJU.js} +6 -6
- package/dist/cli/{quickstart-IYNJRB5G.mjs → quickstart-YWGNHULM.mjs} +4 -4
- package/dist/cli/{run-R3F34KU3.js → run-BWHZXLTD.js} +45 -45
- package/dist/cli/{run-VBQPPMEX.mjs → run-J6FCAKQC.mjs} +25 -25
- package/dist/cli/search-JCWJX2XD.js +32 -0
- package/dist/cli/{search-B7R62HX5.mjs → search-Z3UU3WBB.mjs} +8 -8
- package/dist/cli/{search-output-LNQQXIGZ.mjs → search-output-OJYY4J7E.mjs} +4 -4
- package/dist/cli/{search-output-LWHWEPOT.js → search-output-YIPV74ME.js} +6 -6
- package/dist/cli/{secrets-QBOZ7WTD.js → secrets-UXRJCEN4.js} +16 -16
- package/dist/cli/{secrets-NM3VAJLO.mjs → secrets-YZZN2WST.mjs} +7 -7
- package/dist/cli/{sessions-R5BSIJ4I.mjs → sessions-ITCGPD7Z.mjs} +6 -6
- package/dist/cli/sessions-NA4SJH6Q.js +22 -0
- package/dist/cli/{settings-POYWKNRD.js → settings-LAFYMILP.js} +86 -86
- package/dist/cli/{settings-S4PN7WLY.mjs → settings-ZP2LSVNM.mjs} +13 -13
- package/dist/cli/{setup-VHB4Z654.js → setup-4AL3XYM5.js} +49 -49
- package/dist/cli/{setup-PFLXVBTL.mjs → setup-WEQAQSYC.mjs} +9 -9
- package/dist/cli/{skills-W2TELEU7.mjs → skills-NQH4HFW2.mjs} +7 -7
- package/dist/cli/skills-XZ4Y6SZ7.js +36 -0
- package/dist/cli/{tools-M4FA6N3Y.mjs → tools-CXK2GSI4.mjs} +18 -18
- package/dist/cli/tools-WJQ6Y7E4.js +57 -0
- package/dist/cli/{update-W7LIHEA7.mjs → update-3ROF3Z75.mjs} +9 -9
- package/dist/cli/update-ZLRLTBRD.js +34 -0
- package/dist/cli/{views-KTVPV6UP.mjs → views-AOUHVGV2.mjs} +7 -7
- package/dist/cli/{views-DJXAGD7V.js → views-XJFO5CEH.js} +22 -22
- package/dist/cli/{workflow-NVZDJKH2.js → workflow-GY3DBHXX.js} +18 -18
- package/dist/cli/{workflow-LGKCRODX.mjs → workflow-KBS2QJK6.mjs} +8 -8
- package/dist/{client-Tp1LSULB.d.mts → client-D1uWA2Vc.d.mts} +1 -1
- package/dist/{client-CCyWJqAI.d.ts → client-Hz7SsBXs.d.ts} +1 -1
- package/dist/{client-core-BpYiYEfu.d.ts → client-core-D3Ad7Flt.d.ts} +554 -504
- package/dist/{client-core-D8eCZz3O.d.mts → client-core-Db_e63Hb.d.mts} +554 -504
- package/dist/{compiler-manifest-EBWEUj0b.d.ts → compiler-manifest-BqwVrOri.d.mts} +38 -18
- package/dist/{compiler-manifest-EBWEUj0b.d.mts → compiler-manifest-BqwVrOri.d.ts} +38 -18
- package/dist/{errors-CParKUQR.d.mts → errors-BU8FB99X.d.mts} +1 -1
- package/dist/{errors-Qt0OTA7_.d.ts → errors-DfVN_FUG.d.ts} +1 -1
- package/dist/{index-CoqDkIw0.d.ts → index-BGnvtYGc.d.ts} +6 -1
- package/dist/{index-BMUVCNp7.d.mts → index-DjZgwpGw.d.mts} +6 -1
- package/dist/index.d.mts +28 -8
- package/dist/index.d.ts +28 -8
- package/dist/index.js +64 -39
- package/dist/index.mjs +32 -7
- package/dist/install-integrity.json +133 -128
- package/dist/plays/bundle-play-file.d.mts +3 -3
- package/dist/plays/bundle-play-file.d.ts +3 -3
- package/dist/plays/bundle-play-file.mjs +620 -124
- package/dist/plays/play-description.d.mts +3 -3
- package/dist/plays/play-description.d.ts +3 -3
- package/dist/plays/run-request.d.mts +2 -2
- package/dist/plays/run-request.d.ts +2 -2
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +2 -2
- package/dist/release.mjs +1 -1
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +6 -6
- package/dist/server.mjs +4 -4
- package/package.json +1 -1
- package/dist/cli/auth-W32GMYND.js +0 -43
- package/dist/cli/concurrent-runs-help-6QT7ZR4W.js +0 -21
- package/dist/cli/describe-VLU2LUDJ.js +0 -50
- package/dist/cli/git-E6W44F5M.js +0 -25
- package/dist/cli/search-UUVFXZRA.js +0 -32
- package/dist/cli/sessions-K3PD73Q2.js +0 -22
- package/dist/cli/skills-QNE2EYT3.js +0 -36
- package/dist/cli/tools-3RLI4HGF.js +0 -57
- package/dist/cli/update-UT6KIW2W.js +0 -34
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
playRuntimeNames,
|
|
17
17
|
validateScriptPlay,
|
|
18
18
|
wrapScriptPlay
|
|
19
|
-
} from "../cli/chunk-
|
|
19
|
+
} from "../cli/chunk-WYT3H6JD.mjs";
|
|
20
20
|
import {
|
|
21
21
|
resolveExecutionProfile
|
|
22
|
-
} from "../cli/chunk-
|
|
22
|
+
} from "../cli/chunk-MF7PCM6C.mjs";
|
|
23
23
|
import {
|
|
24
24
|
validatePlaySourceFilesHaveNoInlineSecrets
|
|
25
25
|
} from "../cli/chunk-H7HIDGZ7.mjs";
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
UnsupportedToolResponseContractError,
|
|
35
35
|
normalizeToolResponseContract,
|
|
36
36
|
normalizeToolResponseReceiptRevision
|
|
37
|
-
} from "../cli/chunk-
|
|
37
|
+
} from "../cli/chunk-FZHMNK6F.mjs";
|
|
38
38
|
import {
|
|
39
39
|
PLAY_SANDBOX_SIZE_INPUTS,
|
|
40
40
|
SUPPORTED_PLAY_SANDBOX_SIZES
|
|
@@ -2035,7 +2035,14 @@ var FLOW_START = /^\s*(?:flowchart|graph)\s+(LR|RL|TB|TD|BT)\s*$/i;
|
|
|
2035
2035
|
var MERMAID_NODE = /^\s*\/\/\s*@mermaid-node\s+([A-Za-z][\w-]*)(?:\s+(.*))?$/;
|
|
2036
2036
|
var MERMAID_NODE_HINT = /@mermaid-node/;
|
|
2037
2037
|
var ATTRIBUTE = /([A-Za-z][\w-]*)\s*:\s*"([^"\n]*)"/y;
|
|
2038
|
-
var MERMAID_NODE_ATTRIBUTES = [
|
|
2038
|
+
var MERMAID_NODE_ATTRIBUTES = [
|
|
2039
|
+
"label",
|
|
2040
|
+
"type",
|
|
2041
|
+
"in",
|
|
2042
|
+
"out",
|
|
2043
|
+
"arm",
|
|
2044
|
+
"show"
|
|
2045
|
+
];
|
|
2039
2046
|
var MERMAID_NODE_ID = /^[A-Za-z][\w-]*/;
|
|
2040
2047
|
var SKETCH_CLASS = /^\s*class\s+([A-Za-z][\w-]*(?:\s*,\s*[A-Za-z][\w-]*)*)\s+sketch\s*;?\s*$/;
|
|
2041
2048
|
var MERMAID_NODE_SHAPES = [
|
|
@@ -2279,15 +2286,47 @@ function splitBlockExportHeader(body) {
|
|
|
2279
2286
|
function blockLabel(block) {
|
|
2280
2287
|
return block.authoredExportName ? `@mermaid ${block.authoredExportName}` : "@mermaid";
|
|
2281
2288
|
}
|
|
2282
|
-
function
|
|
2289
|
+
function docflowBlockLineLocator(sourceCode, blockStart, blockText) {
|
|
2290
|
+
const firstLine = sourceCode.slice(0, blockStart).split(/\r?\n/).length;
|
|
2291
|
+
const rawLines = blockText.split(/\r?\n/).map(
|
|
2292
|
+
(line) => line.replace(/^\s*\/\*\*/, "").replace(/\*\/\s*$/, "").replace(/^\s*\* ?/, "").trim()
|
|
2293
|
+
);
|
|
2294
|
+
let cursor = 0;
|
|
2295
|
+
return (diagramLine) => {
|
|
2296
|
+
const wanted = diagramLine.trim();
|
|
2297
|
+
if (!wanted) return null;
|
|
2298
|
+
for (let index = cursor; index < rawLines.length; index += 1) {
|
|
2299
|
+
const raw = rawLines[index].replace(/^@mermaid\b\s*/, "");
|
|
2300
|
+
if (raw === wanted || raw.endsWith(` ${wanted}`)) {
|
|
2301
|
+
cursor = index + 1;
|
|
2302
|
+
return firstLine + index;
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
return null;
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
function locateDocflowErrors(errors, from, line) {
|
|
2309
|
+
if (line === null) return;
|
|
2310
|
+
for (let index = from; index < errors.length; index += 1) {
|
|
2311
|
+
errors[index] = `${errors[index]} (line ${line})`;
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
function parseDocflowBlockGraph(mermaidSource, errors, locate = () => null) {
|
|
2283
2315
|
const docLines = mermaidSource.split(/\r?\n/).filter((line) => line.trim() && !line.trim().startsWith("%%"));
|
|
2284
2316
|
const direction = FLOW_START.exec(docLines[0] ?? "")?.[1]?.toUpperCase();
|
|
2285
2317
|
if (!direction) {
|
|
2318
|
+
const firstErrorAt = errors.length;
|
|
2286
2319
|
errors.push(
|
|
2287
|
-
"Docflow must start with `flowchart` or `graph` and direction `LR`, `RL`, `TB`, `TD`, or `BT`."
|
|
2320
|
+
docLines[0] ? `Docflow must start with \`flowchart\` or \`graph\` and direction \`LR\`, \`RL\`, \`TB\`, \`TD\`, or \`BT\`; found: ${docLines[0].trim()}` : "Docflow must start with `flowchart` or `graph` and direction `LR`, `RL`, `TB`, `TD`, or `BT`."
|
|
2321
|
+
);
|
|
2322
|
+
locateDocflowErrors(
|
|
2323
|
+
errors,
|
|
2324
|
+
firstErrorAt,
|
|
2325
|
+
docLines[0] ? locate(docLines[0]) : null
|
|
2288
2326
|
);
|
|
2289
2327
|
return null;
|
|
2290
2328
|
}
|
|
2329
|
+
locate(docLines[0]);
|
|
2291
2330
|
const nodes = /* @__PURE__ */ new Map();
|
|
2292
2331
|
const edges = [];
|
|
2293
2332
|
const subgraphs = /* @__PURE__ */ new Map();
|
|
@@ -2343,83 +2382,97 @@ function parseDocflowBlockGraph(mermaidSource, errors) {
|
|
|
2343
2382
|
}
|
|
2344
2383
|
return sawDeclaration;
|
|
2345
2384
|
};
|
|
2385
|
+
const openedAt = /* @__PURE__ */ new Map();
|
|
2346
2386
|
for (const line of docLines.slice(1)) {
|
|
2347
|
-
const
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
const
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
"Docflow has an `end` with no open `subgraph` above it. Every `end` closes exactly one `subgraph`."
|
|
2367
|
-
);
|
|
2387
|
+
const lineErrorsFrom = errors.length;
|
|
2388
|
+
const fileLine = locate(line);
|
|
2389
|
+
try {
|
|
2390
|
+
const opened = SUBGRAPH_OPEN.exec(line);
|
|
2391
|
+
if (opened) {
|
|
2392
|
+
const id = opened[1];
|
|
2393
|
+
const rawLabel = opened[2]?.trim() ?? "";
|
|
2394
|
+
const label = rawLabel.length >= 2 && (rawLabel.startsWith('"') && rawLabel.endsWith('"') || rawLabel.startsWith("'") && rawLabel.endsWith("'")) ? rawLabel.slice(1, -1) : rawLabel;
|
|
2395
|
+
const parent = subgraphStack[subgraphStack.length - 1];
|
|
2396
|
+
const subgraph = {
|
|
2397
|
+
id,
|
|
2398
|
+
label: label || id,
|
|
2399
|
+
memberIds: [],
|
|
2400
|
+
...parent ? { parentId: parent.id } : {}
|
|
2401
|
+
};
|
|
2402
|
+
subgraphs.set(id, subgraph);
|
|
2403
|
+
subgraphStack.push(subgraph);
|
|
2404
|
+
openedAt.set(subgraph, fileLine);
|
|
2405
|
+
continue;
|
|
2368
2406
|
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
if (isDirective) {
|
|
2375
|
-
const sketch = SKETCH_CLASS.exec(line);
|
|
2376
|
-
if (sketch) {
|
|
2377
|
-
for (const id of sketch[1].split(",")) {
|
|
2378
|
-
const trimmed = id.trim();
|
|
2379
|
-
if (trimmed) sketchIds.add(trimmed);
|
|
2407
|
+
if (SUBGRAPH_END.test(line)) {
|
|
2408
|
+
if (subgraphStack.length === 0) {
|
|
2409
|
+
errors.push(
|
|
2410
|
+
"Docflow has an `end` with no open `subgraph` above it. Every `end` closes exactly one `subgraph`."
|
|
2411
|
+
);
|
|
2380
2412
|
}
|
|
2381
|
-
|
|
2382
|
-
|
|
2413
|
+
subgraphStack.pop();
|
|
2414
|
+
continue;
|
|
2383
2415
|
}
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2416
|
+
let declaredOnThisLine = false;
|
|
2417
|
+
const isDirective = /^\s*(?:direction|classDef|class|style|linkStyle|click)\b/i.test(line);
|
|
2418
|
+
if (isDirective) {
|
|
2419
|
+
const sketch = SKETCH_CLASS.exec(line);
|
|
2420
|
+
if (sketch) {
|
|
2421
|
+
for (const id of sketch[1].split(",")) {
|
|
2422
|
+
const trimmed = id.trim();
|
|
2423
|
+
if (trimmed) sketchIds.add(trimmed);
|
|
2424
|
+
}
|
|
2425
|
+
} else {
|
|
2426
|
+
ignoredDirectives.push(line.trim());
|
|
2427
|
+
}
|
|
2394
2428
|
}
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
addNodes(line, line);
|
|
2398
|
-
for (const node of chain.nodes) {
|
|
2399
|
-
if (subgraphIds.has(node.id)) continue;
|
|
2400
|
-
const existing = nodes.get(node.id);
|
|
2401
|
-
if (!existing) {
|
|
2402
|
-
nodes.set(node.id, node);
|
|
2403
|
-
subgraphStack[subgraphStack.length - 1]?.memberIds.push(node.id);
|
|
2404
|
-
} else if (existing.label === existing.id && node.label !== node.id) {
|
|
2405
|
-
existing.label = node.label;
|
|
2406
|
-
existing.kind = node.kind;
|
|
2429
|
+
if (!isDirective) {
|
|
2430
|
+
declaredOnThisLine = addNodes(line, line);
|
|
2407
2431
|
}
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2432
|
+
const chain = parseEdgeChain(line);
|
|
2433
|
+
if (!chain) {
|
|
2434
|
+
if (!isDirective && !declaredOnThisLine) {
|
|
2435
|
+
errors.push(
|
|
2436
|
+
`Docflow line is not an edge, a node declaration, or a directive this parser understands: ${line.trim()}`
|
|
2437
|
+
);
|
|
2438
|
+
}
|
|
2439
|
+
continue;
|
|
2440
|
+
}
|
|
2441
|
+
addNodes(line, line);
|
|
2442
|
+
for (const node of chain.nodes) {
|
|
2443
|
+
if (subgraphIds.has(node.id)) continue;
|
|
2444
|
+
const existing = nodes.get(node.id);
|
|
2445
|
+
if (!existing) {
|
|
2446
|
+
nodes.set(node.id, node);
|
|
2447
|
+
subgraphStack[subgraphStack.length - 1]?.memberIds.push(node.id);
|
|
2448
|
+
} else if (existing.label === existing.id && node.label !== node.id) {
|
|
2449
|
+
existing.label = node.label;
|
|
2450
|
+
existing.kind = node.kind;
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
for (let index = 0; index < chain.nodes.length - 1; index += 1) {
|
|
2454
|
+
edges.push({
|
|
2455
|
+
from: chain.nodes[index].id,
|
|
2456
|
+
to: chain.nodes[index + 1].id,
|
|
2457
|
+
...chain.labels[index] ? { label: chain.labels[index] } : {}
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
} finally {
|
|
2461
|
+
locateDocflowErrors(errors, lineErrorsFrom, fileLine);
|
|
2415
2462
|
}
|
|
2416
2463
|
}
|
|
2417
2464
|
if (subgraphStack.length > 0) {
|
|
2465
|
+
const unclosedFrom = errors.length;
|
|
2418
2466
|
errors.push(
|
|
2419
2467
|
`Docflow subgraph${subgraphStack.length === 1 ? "" : "s"} ${subgraphStack.map((subgraph) => `"${subgraph.id}"`).join(
|
|
2420
2468
|
", "
|
|
2421
2469
|
)} ${subgraphStack.length === 1 ? "is" : "are"} never closed with \`end\`. Everything below an unclosed subgraph is silently drawn inside it.`
|
|
2422
2470
|
);
|
|
2471
|
+
locateDocflowErrors(
|
|
2472
|
+
errors,
|
|
2473
|
+
unclosedFrom,
|
|
2474
|
+
openedAt.get(subgraphStack[0]) ?? null
|
|
2475
|
+
);
|
|
2423
2476
|
}
|
|
2424
2477
|
for (const node of nodes.values()) {
|
|
2425
2478
|
if (declaredIds.has(node.id) || subgraphIds.has(node.id)) continue;
|
|
@@ -2448,9 +2501,29 @@ function materializeDocflow(block) {
|
|
|
2448
2501
|
syntax: block.syntax,
|
|
2449
2502
|
mermaidSource: block.mermaidSource,
|
|
2450
2503
|
...block.subgraphs.size ? { subgraphs: [...block.subgraphs.values()] } : {},
|
|
2451
|
-
...block.ignoredDirectives.length ? { ignoredDirectives: block.ignoredDirectives } : {}
|
|
2504
|
+
...block.ignoredDirectives.length ? { ignoredDirectives: block.ignoredDirectives } : {},
|
|
2505
|
+
...block.inputShow?.length ? { inputShow: block.inputShow } : {}
|
|
2452
2506
|
};
|
|
2453
2507
|
}
|
|
2508
|
+
var MERMAID_INPUT_SHOW = /^\s*%%\s*@input\b(.*)$/;
|
|
2509
|
+
function parseBlockInputShow(diagram, errors) {
|
|
2510
|
+
const declarations = diagram.split(/\r?\n/).map((line) => MERMAID_INPUT_SHOW.exec(line)?.[1]).filter((rest) => rest !== void 0);
|
|
2511
|
+
if (declarations.length === 0) return void 0;
|
|
2512
|
+
if (declarations.length > 1) {
|
|
2513
|
+
errors.push(
|
|
2514
|
+
"Docflow `%% @input` appears more than once in one diagram. Declare the input's fields once."
|
|
2515
|
+
);
|
|
2516
|
+
return void 0;
|
|
2517
|
+
}
|
|
2518
|
+
const match = /^\s+show:"([^"]*)"\s*$/.exec(declarations[0]);
|
|
2519
|
+
if (!match) {
|
|
2520
|
+
errors.push(
|
|
2521
|
+
'Docflow `%% @input` takes one attribute: show:"field,nested.field", the run input fields a reader sees first.'
|
|
2522
|
+
);
|
|
2523
|
+
return void 0;
|
|
2524
|
+
}
|
|
2525
|
+
return parseContractPaths(match[1], "show", "@input", 0, errors);
|
|
2526
|
+
}
|
|
2454
2527
|
function parsePlayDocflowFile(sourceCode, moduleSources) {
|
|
2455
2528
|
const errors = [];
|
|
2456
2529
|
const rawBlocks = [];
|
|
@@ -2459,9 +2532,14 @@ function parsePlayDocflowFile(sourceCode, moduleSources) {
|
|
|
2459
2532
|
const cleanedBody = cleanBlockBody(match[1]);
|
|
2460
2533
|
const mermaid = /^@mermaid(?:[ \t]+|\r?\n|$)([\s\S]*)$/.exec(cleanedBody);
|
|
2461
2534
|
if (!mermaid) continue;
|
|
2462
|
-
rawBlocks.push({
|
|
2535
|
+
rawBlocks.push({
|
|
2536
|
+
syntax: "mermaid",
|
|
2537
|
+
body: mermaid[1].trim(),
|
|
2538
|
+
locate: docflowBlockLineLocator(sourceCode, match.index, match[0])
|
|
2539
|
+
});
|
|
2463
2540
|
}
|
|
2464
|
-
if (rawBlocks.length === 0)
|
|
2541
|
+
if (rawBlocks.length === 0)
|
|
2542
|
+
return { blocks: [], bindings: [], errors, unreadBlocks: [] };
|
|
2465
2543
|
const rejectedNodeIds = /* @__PURE__ */ new Set();
|
|
2466
2544
|
const annotationSources = [{ sourceCode }];
|
|
2467
2545
|
for (const [sourcePath, moduleCode] of moduleSources ?? []) {
|
|
@@ -2474,12 +2552,22 @@ function parsePlayDocflowFile(sourceCode, moduleSources) {
|
|
|
2474
2552
|
rejectedNodeIds
|
|
2475
2553
|
);
|
|
2476
2554
|
const parsedBlocks = [];
|
|
2555
|
+
const unreadBlocks = [];
|
|
2477
2556
|
for (const raw of rawBlocks) {
|
|
2478
2557
|
const { exportName, diagram } = splitBlockExportHeader(raw.body);
|
|
2479
|
-
const
|
|
2480
|
-
|
|
2558
|
+
const blockErrorsFrom = errors.length;
|
|
2559
|
+
const graph = parseDocflowBlockGraph(diagram, errors, raw.locate);
|
|
2560
|
+
const inputShow = graph ? parseBlockInputShow(diagram, errors) : void 0;
|
|
2561
|
+
if (!graph || errors.length > blockErrorsFrom) {
|
|
2562
|
+
unreadBlocks.push({
|
|
2563
|
+
authoredExportName: exportName,
|
|
2564
|
+
reason: errors[blockErrorsFrom] ?? "the diagram did not parse"
|
|
2565
|
+
});
|
|
2566
|
+
continue;
|
|
2567
|
+
}
|
|
2481
2568
|
parsedBlocks.push({
|
|
2482
2569
|
...graph,
|
|
2570
|
+
...inputShow?.length ? { inputShow } : {},
|
|
2483
2571
|
authoredExportName: exportName,
|
|
2484
2572
|
exportName: null,
|
|
2485
2573
|
syntax: raw.syntax,
|
|
@@ -2493,7 +2581,8 @@ function parsePlayDocflowFile(sourceCode, moduleSources) {
|
|
|
2493
2581
|
parsedBlocks,
|
|
2494
2582
|
bindings,
|
|
2495
2583
|
errors,
|
|
2496
|
-
rejectedNodeIds
|
|
2584
|
+
rejectedNodeIds,
|
|
2585
|
+
unreadBlocks.length > 0
|
|
2497
2586
|
);
|
|
2498
2587
|
return {
|
|
2499
2588
|
blocks: parsedBlocks.filter((block) => block.exportName !== null).map((block) => ({
|
|
@@ -2501,7 +2590,8 @@ function parsePlayDocflowFile(sourceCode, moduleSources) {
|
|
|
2501
2590
|
docflow: materializeDocflow(block)
|
|
2502
2591
|
})),
|
|
2503
2592
|
bindings,
|
|
2504
|
-
errors
|
|
2593
|
+
errors,
|
|
2594
|
+
unreadBlocks
|
|
2505
2595
|
};
|
|
2506
2596
|
}
|
|
2507
2597
|
function resolveBlockExports(sourceCode, blocks, errors) {
|
|
@@ -2641,12 +2731,13 @@ function projectRecordedArms(block, errors) {
|
|
|
2641
2731
|
edge.arm = binding.arm;
|
|
2642
2732
|
}
|
|
2643
2733
|
}
|
|
2644
|
-
function attachBindingsToBlocks(sourceCode, blocks, bindings, errors, rejectedNodeIds) {
|
|
2734
|
+
function attachBindingsToBlocks(sourceCode, blocks, bindings, errors, rejectedNodeIds, someBlockUnread = false) {
|
|
2645
2735
|
const lineStarts = sourceLineStartsForDocflow(sourceCode);
|
|
2646
2736
|
const exportRanges = playExportSourceRanges(sourceCode);
|
|
2647
2737
|
for (const binding of bindings) {
|
|
2648
2738
|
let owners = blocks.filter((block) => block.nodes.has(binding.nodeId));
|
|
2649
|
-
if (owners.length === 0 && binding.sourcePath)
|
|
2739
|
+
if (owners.length === 0 && (binding.sourcePath || someBlockUnread))
|
|
2740
|
+
continue;
|
|
2650
2741
|
if (owners.length === 0) {
|
|
2651
2742
|
errors.push(
|
|
2652
2743
|
`Docflow annotation "${binding.nodeId}" does not name a graph node.`
|
|
@@ -2680,15 +2771,16 @@ function attachBindingsToBlocks(sourceCode, blocks, bindings, errors, rejectedNo
|
|
|
2680
2771
|
owner.bindings.push(binding);
|
|
2681
2772
|
}
|
|
2682
2773
|
for (const block of blocks) {
|
|
2683
|
-
for (const binding of block.bindings) {
|
|
2774
|
+
for (const binding of [...block.bindings]) {
|
|
2684
2775
|
const node = block.nodes.get(binding.nodeId);
|
|
2685
|
-
if (binding.label) node.label = binding.label;
|
|
2686
2776
|
if (block.sketchIds.has(binding.nodeId)) {
|
|
2687
2777
|
errors.push(
|
|
2688
2778
|
`Docflow box "${binding.nodeId}" is declared \`class ${binding.nodeId} sketch\` and also bound by \`// @mermaid-node ${binding.nodeId}\` on line ${binding.line}. It is one or the other: drop it from the class line, or drop the annotation.`
|
|
2689
2779
|
);
|
|
2780
|
+
block.bindings.splice(block.bindings.indexOf(binding), 1);
|
|
2690
2781
|
continue;
|
|
2691
2782
|
}
|
|
2783
|
+
if (binding.label) node.label = binding.label;
|
|
2692
2784
|
if (binding.kind) node.kind = binding.kind;
|
|
2693
2785
|
}
|
|
2694
2786
|
projectRecordedArms(block, errors);
|
|
@@ -2697,7 +2789,7 @@ function attachBindingsToBlocks(sourceCode, blocks, bindings, errors, rejectedNo
|
|
|
2697
2789
|
if (node.sketch || node.kind === "conceptual" || bound.has(node.id) || rejectedNodeIds.has(node.id))
|
|
2698
2790
|
continue;
|
|
2699
2791
|
errors.push(
|
|
2700
|
-
`Docflow box "${node.id}" in \`${blockLabel(block)}\` points at nothing, so the canvas can only draw it and say nothing about it.
|
|
2792
|
+
`Docflow box "${node.id}" in \`${blockLabel(block)}\` points at nothing, so the canvas can only draw it and say nothing about it. Put \`// @mermaid-node ${node.id}\` above the statement it runs, in this file or a module it imports. Only a box no statement runs, such as the event that starts the play, belongs on a \`class ${node.id} sketch\` line.`
|
|
2701
2793
|
);
|
|
2702
2794
|
}
|
|
2703
2795
|
}
|
|
@@ -2777,7 +2869,14 @@ function parseDocflowBindingsInSource(source, errors, rejectedNodeIds) {
|
|
|
2777
2869
|
index + 1,
|
|
2778
2870
|
errors
|
|
2779
2871
|
);
|
|
2780
|
-
|
|
2872
|
+
const show = parseContractPaths(
|
|
2873
|
+
attributes.show,
|
|
2874
|
+
"show",
|
|
2875
|
+
id,
|
|
2876
|
+
index + 1,
|
|
2877
|
+
errors
|
|
2878
|
+
);
|
|
2879
|
+
if (attributes.in !== void 0 && !inputs || attributes.out !== void 0 && !outputs || attributes.show !== void 0 && !show) {
|
|
2781
2880
|
continue;
|
|
2782
2881
|
}
|
|
2783
2882
|
const inferred = inputs || outputs ? {
|
|
@@ -2796,6 +2895,7 @@ function parseDocflowBindingsInSource(source, errors, rejectedNodeIds) {
|
|
|
2796
2895
|
// explicit `undefined` key survives `JSON.stringify` round-trips in some
|
|
2797
2896
|
// callers and would reintroduce the hash drift this omission avoids.
|
|
2798
2897
|
...arm ? { arm } : {},
|
|
2898
|
+
...show?.length ? { show } : {},
|
|
2799
2899
|
...inferred
|
|
2800
2900
|
});
|
|
2801
2901
|
}
|
|
@@ -4246,7 +4346,7 @@ function docflowObservationTarget(statement) {
|
|
|
4246
4346
|
function docflowObservedExpression(input) {
|
|
4247
4347
|
const body = input.throws ? `{throw (${input.expression})}` : `(${input.expression})`;
|
|
4248
4348
|
const callback = input.awaitsResult ? `async()=>${body}` : `()=>${body}`;
|
|
4249
|
-
const observation = `((runtimeContext,inputCaptures,execute)=>typeof runtimeContext.__deeplineObserveDocflowNode==="function"
|
|
4349
|
+
const observation = `((runtimeContext,inputCaptures,execute)=>{let state=0,value,error;const once=()=>{if(state===0){state=1;try{value=execute();state=2}catch(thrown){error=thrown;state=3}}if(state===3)throw error;return value};try{if(runtimeContext!=null&&typeof runtimeContext.__deeplineObserveDocflowNode==="function")runtimeContext.__deeplineObserveDocflowNode(${JSON.stringify(input.nodeId)},inputCaptures,${JSON.stringify(input.outputs)},once)}catch(ignored){}return once()})(${input.contextName},${docflowInputCaptureSource(input.inputs)},${callback})`;
|
|
4250
4350
|
return input.awaitsResult ? `(await ${observation})` : observation;
|
|
4251
4351
|
}
|
|
4252
4352
|
function expressionContainsTopLevelAwait(expression) {
|
|
@@ -4264,53 +4364,321 @@ function expressionContainsTopLevelAwait(expression) {
|
|
|
4264
4364
|
}
|
|
4265
4365
|
return false;
|
|
4266
4366
|
}
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4367
|
+
var DOCFLOW_STORE_CONTEXT_READER = "__deeplineDocflowRunContext";
|
|
4368
|
+
var DOCFLOW_STORE_CONTEXT_BINDER = "__deeplineDocflowBindRunContext";
|
|
4369
|
+
var DOCFLOW_SDK_NAMESPACE = "__deeplineDocflowSdk";
|
|
4370
|
+
function docflowRunContextPrelude(ast, sourceCode) {
|
|
4371
|
+
const isModule = astArray(ast.body).some(
|
|
4372
|
+
(statement) => statement.type === "ImportDeclaration" || statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" || statement.type === "ExportAllDeclaration"
|
|
4373
|
+
);
|
|
4374
|
+
const sdk = DOCFLOW_SDK_NAMESPACE;
|
|
4375
|
+
const binding = isModule ? `import * as ${sdk} from 'deepline';` : `var ${sdk}=require('deepline');`;
|
|
4376
|
+
const value = `${binding}function ${DOCFLOW_STORE_CONTEXT_READER}(){try{return (typeof ${sdk}.__deeplineCurrentDocflowContext==="function"?${sdk}.__deeplineCurrentDocflowContext():null)??{}}catch(ignored){return {}}}function ${DOCFLOW_STORE_CONTEXT_BINDER}(context,body){let entered=false;const run=()=>{entered=true;return body()};try{if(typeof ${sdk}.__deeplineRunWithDocflowContext==="function")return ${sdk}.__deeplineRunWithDocflowContext(context,run)}catch(failure){if(entered)throw failure}return entered?void 0:body()} `;
|
|
4377
|
+
const at = docflowPreludeOffset(ast, sourceCode);
|
|
4378
|
+
return { start: at, end: at, value };
|
|
4379
|
+
}
|
|
4380
|
+
function docflowPreludeOffset(ast, sourceCode) {
|
|
4381
|
+
let at = sourceCode.startsWith("#!") ? sourceCode.indexOf("\n") + 1 : 0;
|
|
4382
|
+
for (const statement of astArray(ast.body)) {
|
|
4383
|
+
if (statement.type !== "ExpressionStatement" || typeof statement.directive !== "string") {
|
|
4384
|
+
break;
|
|
4385
|
+
}
|
|
4386
|
+
at = astNodeBounds(statement)?.end ?? at;
|
|
4387
|
+
}
|
|
4388
|
+
return at;
|
|
4389
|
+
}
|
|
4390
|
+
function docflowPatternNames(pattern, names) {
|
|
4391
|
+
const pending = [pattern];
|
|
4392
|
+
while (pending.length > 0) {
|
|
4393
|
+
const value = pending.pop();
|
|
4394
|
+
if (Array.isArray(value)) {
|
|
4395
|
+
pending.push(...value);
|
|
4396
|
+
continue;
|
|
4397
|
+
}
|
|
4398
|
+
if (!isAstNode(value)) continue;
|
|
4399
|
+
if (value.type === "Identifier" && typeof value.name === "string") {
|
|
4400
|
+
names.add(value.name);
|
|
4401
|
+
}
|
|
4402
|
+
for (const [key, child] of Object.entries(value)) {
|
|
4403
|
+
if (key === "typeAnnotation") continue;
|
|
4404
|
+
if (Array.isArray(child) || isAstNode(child)) pending.push(child);
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4408
|
+
var DOCFLOW_FUNCTION_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
4409
|
+
"FunctionDeclaration",
|
|
4410
|
+
"FunctionExpression",
|
|
4411
|
+
"ArrowFunctionExpression"
|
|
4412
|
+
]);
|
|
4413
|
+
function docflowRunBodyRedeclaresParameter(run) {
|
|
4414
|
+
const parameters = /* @__PURE__ */ new Set();
|
|
4415
|
+
docflowPatternNames(run.params, parameters);
|
|
4416
|
+
if (parameters.size === 0 || !isAstNode(run.body)) return false;
|
|
4417
|
+
const declared = /* @__PURE__ */ new Set();
|
|
4418
|
+
for (const statement of astArray(run.body.body)) {
|
|
4419
|
+
if (statement.type === "FunctionDeclaration" && isAstNode(statement.id)) {
|
|
4420
|
+
docflowPatternNames(statement.id, declared);
|
|
4421
|
+
}
|
|
4422
|
+
}
|
|
4423
|
+
const pending = [run.body];
|
|
4424
|
+
while (pending.length > 0) {
|
|
4425
|
+
const value = pending.pop();
|
|
4426
|
+
if (Array.isArray(value)) {
|
|
4427
|
+
pending.push(...value);
|
|
4428
|
+
continue;
|
|
4429
|
+
}
|
|
4430
|
+
if (!isAstNode(value)) continue;
|
|
4431
|
+
if (DOCFLOW_FUNCTION_NODE_TYPES.has(value.type)) continue;
|
|
4432
|
+
if (value.type === "VariableDeclaration" && value.kind === "var") {
|
|
4433
|
+
for (const declaration of astArray(value.declarations)) {
|
|
4434
|
+
docflowPatternNames(declaration.id, declared);
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
for (const child of Object.values(value)) {
|
|
4438
|
+
if (Array.isArray(child) || isAstNode(child)) pending.push(child);
|
|
4439
|
+
}
|
|
4440
|
+
}
|
|
4441
|
+
return [...declared].some((name) => parameters.has(name));
|
|
4442
|
+
}
|
|
4443
|
+
function docflowRunContextBindings(ast, sourceCode, injectedContextAt, warnings) {
|
|
4444
|
+
const replacements = [];
|
|
4445
|
+
const pending = [ast];
|
|
4446
|
+
while (pending.length > 0) {
|
|
4447
|
+
const value = pending.pop();
|
|
4448
|
+
if (!isAstNode(value)) continue;
|
|
4449
|
+
for (const child of Object.values(value)) {
|
|
4450
|
+
if (Array.isArray(child)) pending.push(...child);
|
|
4451
|
+
else if (isAstNode(child)) pending.push(child);
|
|
4452
|
+
}
|
|
4453
|
+
const context = docflowContextFromCall(value, sourceCode);
|
|
4454
|
+
if (!context || context.kind === "unsupported" || context.kind === "store")
|
|
4455
|
+
continue;
|
|
4456
|
+
const run = definePlayRunFunction(value);
|
|
4457
|
+
if (!run || run.generator === true || !isAstNode(run.body)) continue;
|
|
4458
|
+
if (docflowRunBodyRedeclaresParameter(run)) {
|
|
4459
|
+
warnings.push(
|
|
4460
|
+
"Diagram boxes in imported helper modules are not tracked for this play: its run function redeclares a parameter with `var` or `function`, whose meaning would change if its body were wrapped. The play runs unchanged."
|
|
4461
|
+
);
|
|
4462
|
+
continue;
|
|
4463
|
+
}
|
|
4464
|
+
const body = astNodeBounds(run.body);
|
|
4465
|
+
if (!body) continue;
|
|
4466
|
+
if (context.kind === "inject") injectedContextAt.add(context.at);
|
|
4467
|
+
const contextName = context.kind === "inject" ? DOCFLOW_INJECTED_CONTEXT_NAME : context.name;
|
|
4468
|
+
const arrow = run.async === true ? "async()=>" : "()=>";
|
|
4469
|
+
if (run.body.type === "BlockStatement") {
|
|
4470
|
+
const directives = astArray(run.body.body).filter(
|
|
4471
|
+
(statement) => statement.type === "ExpressionStatement" && typeof statement.directive === "string"
|
|
4472
|
+
);
|
|
4473
|
+
if (directives.length > 0) continue;
|
|
4474
|
+
replacements.push(
|
|
4475
|
+
{
|
|
4476
|
+
start: body.start + 1,
|
|
4477
|
+
end: body.start + 1,
|
|
4478
|
+
value: `return ${DOCFLOW_STORE_CONTEXT_BINDER}(${contextName},${arrow}{`
|
|
4479
|
+
},
|
|
4480
|
+
{ start: body.end - 1, end: body.end - 1, value: "});" }
|
|
4481
|
+
);
|
|
4482
|
+
} else {
|
|
4483
|
+
replacements.push(
|
|
4484
|
+
{
|
|
4485
|
+
start: body.start,
|
|
4486
|
+
end: body.start,
|
|
4487
|
+
value: `${DOCFLOW_STORE_CONTEXT_BINDER}(${contextName},${arrow}(`
|
|
4488
|
+
},
|
|
4489
|
+
{ start: body.end, end: body.end, value: "))" }
|
|
4490
|
+
);
|
|
4491
|
+
}
|
|
4492
|
+
}
|
|
4493
|
+
return replacements;
|
|
4494
|
+
}
|
|
4495
|
+
function instrumentPlayDocflowRuntimeHitsWithReport(sourceCode, options = {}) {
|
|
4496
|
+
const warnings = [];
|
|
4497
|
+
const untouched = (reason) => {
|
|
4498
|
+
if (reason) warnings.push(reason);
|
|
4499
|
+
return { code: sourceCode, instrumented: false, warnings };
|
|
4500
|
+
};
|
|
4501
|
+
let code;
|
|
4502
|
+
try {
|
|
4503
|
+
code = instrumentPlayDocflowRuntimeHitsCore(sourceCode, options, warnings);
|
|
4504
|
+
} catch (error) {
|
|
4505
|
+
return untouched(
|
|
4506
|
+
`Diagram tracking was skipped for this file: instrumentation failed (${boundedInstrumentationReason(error)}). The play runs unchanged.`
|
|
4507
|
+
);
|
|
4508
|
+
}
|
|
4509
|
+
if (code === sourceCode) return untouched();
|
|
4510
|
+
if (!parsePlaySourceAstExact(code)) {
|
|
4511
|
+
return untouched(
|
|
4512
|
+
"Diagram tracking was skipped for this file: the instrumented source did not parse. The play runs unchanged."
|
|
4513
|
+
);
|
|
4514
|
+
}
|
|
4515
|
+
return { code, instrumented: true, warnings };
|
|
4516
|
+
}
|
|
4517
|
+
function boundedInstrumentationReason(error) {
|
|
4518
|
+
let message;
|
|
4519
|
+
try {
|
|
4520
|
+
message = error instanceof Error ? error.message : String(error);
|
|
4521
|
+
} catch {
|
|
4522
|
+
message = "unknown error";
|
|
4523
|
+
}
|
|
4524
|
+
return message.length > 300 ? `${message.slice(0, 300)}\u2026` : message;
|
|
4525
|
+
}
|
|
4526
|
+
function parsePlaySourceAstExact(sourceCode) {
|
|
4527
|
+
try {
|
|
4528
|
+
return TypeScriptParser.parse(sourceCode, {
|
|
4529
|
+
ecmaVersion: "latest",
|
|
4530
|
+
sourceType: "module",
|
|
4531
|
+
allowHashBang: true,
|
|
4532
|
+
// Script plays may end early with a top-level `return`.
|
|
4533
|
+
allowReturnOutsideFunction: true
|
|
4534
|
+
});
|
|
4535
|
+
} catch {
|
|
4536
|
+
return null;
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4539
|
+
function docflowStatementListStarts(ast) {
|
|
4540
|
+
const starts = /* @__PURE__ */ new Set();
|
|
4541
|
+
const pending = [ast];
|
|
4542
|
+
while (pending.length > 0) {
|
|
4543
|
+
const value = pending.pop();
|
|
4544
|
+
if (!isAstNode(value)) continue;
|
|
4545
|
+
const list = value.type === "Program" || value.type === "BlockStatement" || value.type === "StaticBlock" ? value.body : value.type === "SwitchCase" ? value.consequent : null;
|
|
4546
|
+
for (const statement of astArray(list)) {
|
|
4547
|
+
if (statement.type === "ExpressionStatement" && typeof statement.directive === "string") {
|
|
4548
|
+
continue;
|
|
4549
|
+
}
|
|
4550
|
+
if (/^(Import|Export)/.test(statement.type)) continue;
|
|
4551
|
+
const bounds = astNodeBounds(statement);
|
|
4552
|
+
if (bounds) starts.add(bounds.start);
|
|
4553
|
+
}
|
|
4554
|
+
for (const child of Object.values(value)) {
|
|
4555
|
+
if (Array.isArray(child)) pending.push(...child);
|
|
4556
|
+
else if (isAstNode(child)) pending.push(child);
|
|
4557
|
+
}
|
|
4558
|
+
}
|
|
4559
|
+
return starts;
|
|
4560
|
+
}
|
|
4561
|
+
function docflowUnwrappableReason(statement, expression) {
|
|
4562
|
+
const pending = [expression];
|
|
4563
|
+
while (pending.length > 0) {
|
|
4564
|
+
const node = pending.pop();
|
|
4565
|
+
if (node.type === "YieldExpression") {
|
|
4566
|
+
return "the statement contains `yield`, which cannot move into an observation callback";
|
|
4567
|
+
}
|
|
4568
|
+
if (node !== expression && (node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression")) {
|
|
4569
|
+
continue;
|
|
4570
|
+
}
|
|
4571
|
+
for (const child of Object.values(node)) {
|
|
4572
|
+
if (Array.isArray(child)) pending.push(...child.filter(isAstNode));
|
|
4573
|
+
else if (isAstNode(child)) pending.push(child);
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
let inner = expression;
|
|
4577
|
+
while ((inner.type === "TSAsExpression" || inner.type === "TSSatisfiesExpression" || inner.type === "TSNonNullExpression" || inner.type === "TSTypeAssertion" || inner.type === "ParenthesizedExpression") && isAstNode(inner.expression)) {
|
|
4578
|
+
inner = inner.expression;
|
|
4579
|
+
}
|
|
4580
|
+
const anonymousCallable = inner.type === "ArrowFunctionExpression" || (inner.type === "FunctionExpression" || inner.type === "ClassExpression") && !isAstNode(inner.id);
|
|
4581
|
+
if (statement?.type === "VariableDeclaration" && anonymousCallable) {
|
|
4582
|
+
return "the declaration initializes an anonymous function or class, whose name comes from the declaration";
|
|
4583
|
+
}
|
|
4584
|
+
return null;
|
|
4585
|
+
}
|
|
4586
|
+
function instrumentPlayDocflowRuntimeHitsCore(sourceCode, options, warnings) {
|
|
4587
|
+
const helperBindings = options.helperBindings;
|
|
4588
|
+
let fileBindings;
|
|
4589
|
+
if (helperBindings !== void 0) {
|
|
4590
|
+
if (helperBindings.length === 0) return sourceCode;
|
|
4591
|
+
fileBindings = helperBindings;
|
|
4592
|
+
} else {
|
|
4593
|
+
const parsed = parsePlayDocflowFile(sourceCode, options.moduleSources);
|
|
4594
|
+
if (parsed.blocks.length === 0) return sourceCode;
|
|
4595
|
+
if (parsed.errors.length > 0) {
|
|
4596
|
+
warnings.push(
|
|
4597
|
+
`Diagram tracking skipped what did not resolve in this file's @mermaid diagram (${boundedInstrumentationReason(parsed.errors[0])}${parsed.errors.length > 1 ? `, and ${parsed.errors.length - 1} more` : ""}). The play runs unchanged.`
|
|
4598
|
+
);
|
|
4599
|
+
fileBindings = parsed.blocks.flatMap((block) => block.docflow.bindings).filter((binding) => !binding.sourcePath);
|
|
4600
|
+
if (fileBindings.length === 0) return sourceCode;
|
|
4601
|
+
} else {
|
|
4602
|
+
fileBindings = parsed.bindings.filter((binding) => !binding.sourcePath);
|
|
4603
|
+
}
|
|
4604
|
+
}
|
|
4605
|
+
const ast = parsePlaySourceAstExact(sourceCode);
|
|
4606
|
+
if (!ast) {
|
|
4607
|
+
warnings.push(
|
|
4608
|
+
"Diagram tracking was skipped for this file: its source could not be parsed exactly for instrumentation. The play runs unchanged."
|
|
4609
|
+
);
|
|
4610
|
+
return sourceCode;
|
|
4611
|
+
}
|
|
4272
4612
|
const lineStarts = sourceLineStarts(sourceCode);
|
|
4273
4613
|
const replacements = [];
|
|
4614
|
+
let statementListStarts = null;
|
|
4274
4615
|
const targets = [];
|
|
4275
4616
|
const injectedContextAt = /* @__PURE__ */ new Set();
|
|
4276
4617
|
const parents = buildDocflowParentIndex(ast);
|
|
4277
4618
|
const scriptContext = parseScriptPlay(sourceCode)?.contextName ?? null;
|
|
4278
|
-
|
|
4619
|
+
let usesRunContextStore = false;
|
|
4620
|
+
for (const binding of fileBindings) {
|
|
4279
4621
|
const resolution = resolveDocflowBinding(ast, binding, lineStarts, parents);
|
|
4280
|
-
const context = findDocflowContext({
|
|
4622
|
+
const context = (helperBindings === void 0 ? findDocflowContext({
|
|
4281
4623
|
ast,
|
|
4282
4624
|
sourceCode,
|
|
4283
4625
|
statement: resolution.statement,
|
|
4284
4626
|
bindingLine: binding.line,
|
|
4285
4627
|
lineStarts,
|
|
4286
4628
|
parents
|
|
4287
|
-
}) ?? (scriptContext ? { kind: "named", name: scriptContext } : null);
|
|
4288
|
-
if (!context) continue;
|
|
4629
|
+
}) ?? (scriptContext ? { kind: "named", name: scriptContext } : null) : null) ?? { kind: "store" };
|
|
4289
4630
|
if (context.kind === "unsupported") {
|
|
4290
|
-
|
|
4291
|
-
`@mermaid-node ${binding.nodeId} (line ${binding.line}) cannot be observed at runtime: ${context.reason}.`
|
|
4631
|
+
warnings.push(
|
|
4632
|
+
`@mermaid-node ${binding.nodeId} (line ${binding.line}) cannot be observed at runtime: ${context.reason}. The box is drawn but not tracked.`
|
|
4292
4633
|
);
|
|
4634
|
+
continue;
|
|
4293
4635
|
}
|
|
4636
|
+
if (context.kind === "store") usesRunContextStore = true;
|
|
4294
4637
|
if (context.kind === "inject") injectedContextAt.add(context.at);
|
|
4295
|
-
const contextName = context.kind === "inject" ? `(${context.name}??{})` : context.name;
|
|
4638
|
+
const contextName = context.kind === "inject" ? `(${context.name}??{})` : context.kind === "store" ? `${DOCFLOW_STORE_CONTEXT_READER}()` : context.name;
|
|
4296
4639
|
const target = docflowObservationTarget(resolution.statement);
|
|
4297
4640
|
const observedRoot = docflowOutputRoot(binding);
|
|
4298
4641
|
if (target && observedRoot && docflowExpressionWrapsStepBuilder(target.expression, observedRoot)) {
|
|
4299
4642
|
continue;
|
|
4300
4643
|
}
|
|
4301
4644
|
if (target) {
|
|
4645
|
+
const unwrappable = docflowUnwrappableReason(
|
|
4646
|
+
resolution.statement,
|
|
4647
|
+
target.expression
|
|
4648
|
+
);
|
|
4649
|
+
if (unwrappable) {
|
|
4650
|
+
warnings.push(
|
|
4651
|
+
`@mermaid-node ${binding.nodeId} (line ${binding.line}) is not tracked: ${unwrappable}.`
|
|
4652
|
+
);
|
|
4653
|
+
continue;
|
|
4654
|
+
}
|
|
4302
4655
|
targets.push({ ...target, contextName, binding });
|
|
4303
4656
|
continue;
|
|
4304
4657
|
}
|
|
4305
4658
|
const lineStart = lineStarts[binding.line - 1];
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4659
|
+
const statementBounds = resolution.statement ? astNodeBounds(resolution.statement) : null;
|
|
4660
|
+
const indentationLength = lineStart === void 0 ? 0 : /^\s*/.exec(sourceCode.slice(lineStart))?.[0].length ?? 0;
|
|
4661
|
+
statementListStarts ??= docflowStatementListStarts(ast);
|
|
4662
|
+
const listStarts = statementListStarts;
|
|
4663
|
+
const at = [
|
|
4664
|
+
statementBounds?.start,
|
|
4665
|
+
lineStart === void 0 ? void 0 : lineStart + indentationLength
|
|
4666
|
+
].find(
|
|
4667
|
+
(candidate) => candidate !== void 0 && listStarts.has(candidate)
|
|
4668
|
+
);
|
|
4669
|
+
if (at === void 0) {
|
|
4670
|
+
warnings.push(
|
|
4671
|
+
`@mermaid-node ${binding.nodeId} (line ${binding.line}) is not tracked: it binds no expression and does not start a statement.`
|
|
4672
|
+
);
|
|
4673
|
+
continue;
|
|
4313
4674
|
}
|
|
4675
|
+
replacements.push({
|
|
4676
|
+
start: at,
|
|
4677
|
+
end: at,
|
|
4678
|
+
// `void` first: a statement opening with `(` would continue a previous
|
|
4679
|
+
// line written without a semicolon (`f()\n(…)` calls f's result).
|
|
4680
|
+
value: `void ((runtimeContext)=>{try{if(runtimeContext!=null&&typeof runtimeContext.__deeplineDocflowHit==="function"){const pending=runtimeContext.__deeplineDocflowHit(${JSON.stringify(binding.nodeId)});if(pending!=null&&typeof pending.then==="function")pending.then(null,()=>{})}}catch(ignored){}})(${contextName}); `
|
|
4681
|
+
});
|
|
4314
4682
|
}
|
|
4315
4683
|
targets.sort(
|
|
4316
4684
|
(left, right) => left.start - right.start || right.end - left.end
|
|
@@ -4346,12 +4714,27 @@ function instrumentPlayDocflowRuntimeHits(sourceCode) {
|
|
|
4346
4714
|
});
|
|
4347
4715
|
innermost = false;
|
|
4348
4716
|
}
|
|
4717
|
+
statementListStarts ??= docflowStatementListStarts(ast);
|
|
4349
4718
|
replacements.push({
|
|
4350
4719
|
start: group.start,
|
|
4351
4720
|
end: group.end,
|
|
4352
|
-
value: expression
|
|
4721
|
+
value: statementListStarts.has(group.start) ? `void ${expression}` : expression
|
|
4353
4722
|
});
|
|
4354
4723
|
}
|
|
4724
|
+
const bindRunContext = helperBindings === void 0 && !scriptContext && (usesRunContextStore || options.bindRunContext === true);
|
|
4725
|
+
if (bindRunContext) {
|
|
4726
|
+
replacements.push(
|
|
4727
|
+
...docflowRunContextBindings(
|
|
4728
|
+
ast,
|
|
4729
|
+
sourceCode,
|
|
4730
|
+
injectedContextAt,
|
|
4731
|
+
warnings
|
|
4732
|
+
)
|
|
4733
|
+
);
|
|
4734
|
+
}
|
|
4735
|
+
if (usesRunContextStore || bindRunContext) {
|
|
4736
|
+
replacements.push(docflowRunContextPrelude(ast, sourceCode));
|
|
4737
|
+
}
|
|
4355
4738
|
for (const at of injectedContextAt) {
|
|
4356
4739
|
replacements.push({
|
|
4357
4740
|
start: at,
|
|
@@ -4359,27 +4742,53 @@ function instrumentPlayDocflowRuntimeHits(sourceCode) {
|
|
|
4359
4742
|
value: DOCFLOW_INJECTED_CONTEXT_NAME
|
|
4360
4743
|
});
|
|
4361
4744
|
}
|
|
4362
|
-
return replacements.sort((left, right) => right.start - left.start).reduce(
|
|
4745
|
+
return replacements.sort((left, right) => right.start - left.start || right.end - left.end).reduce(
|
|
4363
4746
|
(source, replacement) => `${source.slice(0, replacement.start)}${replacement.value}${source.slice(replacement.end)}`,
|
|
4364
4747
|
sourceCode
|
|
4365
4748
|
);
|
|
4366
4749
|
}
|
|
4367
|
-
function docflowRuntimeInstrumentationPlugin(analyzedSources, scriptEntry) {
|
|
4750
|
+
function docflowRuntimeInstrumentationPlugin(analyzedSources, entryFile, scriptEntry) {
|
|
4368
4751
|
const customerSourceFiles = new Map(
|
|
4369
4752
|
Object.entries(analyzedSources).filter(([path]) => extname(path).toLowerCase() !== ".json").map(([path, contents]) => [resolve(path), contents])
|
|
4370
4753
|
);
|
|
4754
|
+
const entryPath = resolve(entryFile);
|
|
4755
|
+
const planWarnings = [];
|
|
4756
|
+
const plan = docflowHelperInstrumentationPlanFailOpen(
|
|
4757
|
+
entryPath,
|
|
4758
|
+
scriptEntry?.source ?? customerSourceFiles.get(entryPath) ?? null,
|
|
4759
|
+
customerSourceFiles,
|
|
4760
|
+
planWarnings
|
|
4761
|
+
);
|
|
4762
|
+
const entryOptions = {
|
|
4763
|
+
moduleSources: plan.moduleSources,
|
|
4764
|
+
bindRunContext: plan.helperBindings.size > 0
|
|
4765
|
+
};
|
|
4766
|
+
const asWarnings = (path, warnings) => warnings.map((text) => ({
|
|
4767
|
+
text: `${DOCFLOW_INSTRUMENTATION_WARNING_PREFIX}${text}`,
|
|
4768
|
+
location: { file: path }
|
|
4769
|
+
}));
|
|
4371
4770
|
return {
|
|
4372
4771
|
name: "deepline-docflow-runtime-instrumentation",
|
|
4373
4772
|
setup(buildContext) {
|
|
4374
4773
|
buildContext.onLoad({ filter: /./ }, (args) => {
|
|
4375
|
-
|
|
4774
|
+
const path = resolve(args.path);
|
|
4775
|
+
if (scriptEntry && path === resolve(scriptEntry.path)) {
|
|
4776
|
+
const script = scriptEntryModule(
|
|
4777
|
+
scriptEntry.source,
|
|
4778
|
+
args.path,
|
|
4779
|
+
entryOptions
|
|
4780
|
+
);
|
|
4376
4781
|
return {
|
|
4377
|
-
contents:
|
|
4782
|
+
contents: script.contents,
|
|
4378
4783
|
loader: sourceLoaderForPath(args.path),
|
|
4379
|
-
resolveDir: dirname(args.path)
|
|
4784
|
+
resolveDir: dirname(args.path),
|
|
4785
|
+
warnings: asWarnings(args.path, [
|
|
4786
|
+
...planWarnings,
|
|
4787
|
+
...script.warnings
|
|
4788
|
+
])
|
|
4380
4789
|
};
|
|
4381
4790
|
}
|
|
4382
|
-
const contents = customerSourceFiles.get(
|
|
4791
|
+
const contents = customerSourceFiles.get(path);
|
|
4383
4792
|
if (contents === void 0) return void 0;
|
|
4384
4793
|
if (isTextImportFile(args.path)) {
|
|
4385
4794
|
return {
|
|
@@ -4388,27 +4797,98 @@ function docflowRuntimeInstrumentationPlugin(analyzedSources, scriptEntry) {
|
|
|
4388
4797
|
resolveDir: dirname(args.path)
|
|
4389
4798
|
};
|
|
4390
4799
|
}
|
|
4800
|
+
const helperBindings = plan.helperBindings.get(path);
|
|
4801
|
+
const report = instrumentPlayDocflowRuntimeHitsWithReport(
|
|
4802
|
+
contents,
|
|
4803
|
+
path === entryPath ? entryOptions : helperBindings ? { helperBindings } : {}
|
|
4804
|
+
);
|
|
4391
4805
|
return {
|
|
4392
|
-
contents:
|
|
4806
|
+
contents: report.code,
|
|
4393
4807
|
loader: sourceLoaderForPath(args.path),
|
|
4394
|
-
resolveDir: dirname(args.path)
|
|
4808
|
+
resolveDir: dirname(args.path),
|
|
4809
|
+
warnings: asWarnings(args.path, [
|
|
4810
|
+
...path === entryPath ? planWarnings : [],
|
|
4811
|
+
...report.warnings
|
|
4812
|
+
])
|
|
4395
4813
|
};
|
|
4396
4814
|
});
|
|
4397
4815
|
}
|
|
4398
4816
|
};
|
|
4399
4817
|
}
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4818
|
+
var DOCFLOW_INSTRUMENTATION_WARNING_PREFIX = "[diagram tracking] ";
|
|
4819
|
+
function docflowHelperInstrumentationPlanFailOpen(entryPath, entrySource, sources, warnings) {
|
|
4820
|
+
try {
|
|
4821
|
+
return docflowHelperInstrumentationPlan(entryPath, entrySource, sources);
|
|
4822
|
+
} catch (error) {
|
|
4823
|
+
warnings.push(
|
|
4824
|
+
`Diagram tracking in imported helper modules was skipped: ${boundedInstrumentationReason(error)}.`
|
|
4406
4825
|
);
|
|
4826
|
+
return {
|
|
4827
|
+
moduleSources: new Map(
|
|
4828
|
+
[...sources].filter(
|
|
4829
|
+
([path]) => path !== entryPath && !isTextImportFile(path)
|
|
4830
|
+
)
|
|
4831
|
+
),
|
|
4832
|
+
helperBindings: /* @__PURE__ */ new Map()
|
|
4833
|
+
};
|
|
4407
4834
|
}
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4835
|
+
}
|
|
4836
|
+
function docflowHelperInstrumentationPlan(entryPath, entrySource, sources) {
|
|
4837
|
+
const moduleSources = new Map(
|
|
4838
|
+
[...sources].filter(
|
|
4839
|
+
([path]) => path !== entryPath && !isTextImportFile(path)
|
|
4840
|
+
)
|
|
4841
|
+
);
|
|
4842
|
+
const helperBindings = /* @__PURE__ */ new Map();
|
|
4843
|
+
if (entrySource === null || moduleSources.size === 0) {
|
|
4844
|
+
return { moduleSources, helperBindings };
|
|
4845
|
+
}
|
|
4846
|
+
const parsed = parsePlayDocflowFile(entrySource, moduleSources);
|
|
4847
|
+
const drawn = new Set(
|
|
4848
|
+
parsed.blocks.flatMap(
|
|
4849
|
+
(block) => block.docflow.nodes.map((node) => node.id)
|
|
4850
|
+
)
|
|
4851
|
+
);
|
|
4852
|
+
const tracked = parsed.errors.length > 0 ? parsed.blocks.flatMap((block) => block.docflow.bindings) : parsed.bindings;
|
|
4853
|
+
for (const binding of tracked) {
|
|
4854
|
+
if (!binding.sourcePath || !drawn.has(binding.nodeId)) continue;
|
|
4855
|
+
const path = resolve(binding.sourcePath);
|
|
4856
|
+
helperBindings.set(path, [...helperBindings.get(path) ?? [], binding]);
|
|
4857
|
+
}
|
|
4858
|
+
return { moduleSources, helperBindings };
|
|
4859
|
+
}
|
|
4860
|
+
function scriptEntryModule(source, path, options = {}) {
|
|
4861
|
+
const typed = /^tsx?$/.test(sourceLoaderForPath(path));
|
|
4862
|
+
const report = instrumentPlayDocflowRuntimeHitsWithReport(source, options);
|
|
4863
|
+
if (report.instrumented) {
|
|
4864
|
+
try {
|
|
4865
|
+
const script2 = parseScriptPlay(report.code);
|
|
4866
|
+
if (script2) {
|
|
4867
|
+
return {
|
|
4868
|
+
contents: wrapScriptPlay(report.code, script2, {
|
|
4869
|
+
typed,
|
|
4870
|
+
authoredSource: source
|
|
4871
|
+
}),
|
|
4872
|
+
warnings: report.warnings
|
|
4873
|
+
};
|
|
4874
|
+
}
|
|
4875
|
+
} catch {
|
|
4876
|
+
}
|
|
4877
|
+
report.warnings.push(
|
|
4878
|
+
"Diagram tracking was skipped for this script play: the instrumented source is no longer a script play. The play runs unchanged."
|
|
4879
|
+
);
|
|
4880
|
+
}
|
|
4881
|
+
const script = parseScriptPlay(source);
|
|
4882
|
+
if (!script) {
|
|
4883
|
+
throw new Error("Script play entry could not be parsed as a script play.");
|
|
4884
|
+
}
|
|
4885
|
+
return {
|
|
4886
|
+
contents: wrapScriptPlay(source, script, {
|
|
4887
|
+
typed,
|
|
4888
|
+
authoredSource: source
|
|
4889
|
+
}),
|
|
4890
|
+
warnings: report.warnings
|
|
4891
|
+
};
|
|
4412
4892
|
}
|
|
4413
4893
|
function buildImportedPlayProxyModule(playName) {
|
|
4414
4894
|
const serializedName = JSON.stringify(playName);
|
|
@@ -4806,6 +5286,7 @@ async function runEsbuildForCjsNode(entryFile, analyzedSources, entryScript, imp
|
|
|
4806
5286
|
const playProxyPlugin = importedPlayProxyPlugin(importedPlayDependencies);
|
|
4807
5287
|
const docflowPlugin = docflowRuntimeInstrumentationPlugin(
|
|
4808
5288
|
analyzedSources,
|
|
5289
|
+
entryFile,
|
|
4809
5290
|
entryScript === null ? null : { path: entryFile, source: entryScript }
|
|
4810
5291
|
);
|
|
4811
5292
|
const namedExportShim = exportName !== "default" ? `export { ${exportName} as default } from ${JSON.stringify(entryFile)};
|
|
@@ -4850,7 +5331,16 @@ async function runEsbuildForCjsNode(entryFile, analyzedSources, entryScript, imp
|
|
|
4850
5331
|
return {
|
|
4851
5332
|
bundledCode: codeFile.text,
|
|
4852
5333
|
sourceMapText: mapFile.text,
|
|
4853
|
-
outputExtension: "cjs"
|
|
5334
|
+
outputExtension: "cjs",
|
|
5335
|
+
docflowInstrumentationWarnings: [
|
|
5336
|
+
...new Set(
|
|
5337
|
+
result.warnings.map((warning) => warning.text).filter(
|
|
5338
|
+
(text) => text.startsWith(DOCFLOW_INSTRUMENTATION_WARNING_PREFIX)
|
|
5339
|
+
).map(
|
|
5340
|
+
(text) => text.slice(DOCFLOW_INSTRUMENTATION_WARNING_PREFIX.length)
|
|
5341
|
+
)
|
|
5342
|
+
)
|
|
5343
|
+
]
|
|
4854
5344
|
};
|
|
4855
5345
|
}
|
|
4856
5346
|
async function bundlePlayFile(filePath, options) {
|
|
@@ -5002,7 +5492,12 @@ preserved-compatibility:${JSON.stringify(preservedCompatibility)}`}` + // A scri
|
|
|
5002
5492
|
errors: buildOutcome
|
|
5003
5493
|
};
|
|
5004
5494
|
}
|
|
5005
|
-
const {
|
|
5495
|
+
const {
|
|
5496
|
+
bundledCode,
|
|
5497
|
+
sourceMapText,
|
|
5498
|
+
outputExtension,
|
|
5499
|
+
docflowInstrumentationWarnings
|
|
5500
|
+
} = buildOutcome;
|
|
5006
5501
|
const normalizedSourceMap = normalizeSourceMapForRuntime(
|
|
5007
5502
|
sourceMapText,
|
|
5008
5503
|
bundleRoot
|
|
@@ -5065,7 +5560,8 @@ preserved-compatibility:${JSON.stringify(preservedCompatibility)}`}` + // A scri
|
|
|
5065
5560
|
sandboxRuntimeDeclaration: analysis.sandboxRuntimeDeclaration,
|
|
5066
5561
|
packagedFiles: discoveredFiles.files,
|
|
5067
5562
|
unresolvedFileReferences: discoveredFiles.unresolved,
|
|
5068
|
-
importedPlayDependencies: analysis.importedPlayDependencies
|
|
5563
|
+
importedPlayDependencies: analysis.importedPlayDependencies,
|
|
5564
|
+
...docflowInstrumentationWarnings.length > 0 ? { docflowInstrumentationWarnings } : {}
|
|
5069
5565
|
};
|
|
5070
5566
|
} catch (error) {
|
|
5071
5567
|
if (error instanceof AggregateError) {
|