deepline 0.3.545 → 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/errors.ts +1 -1
- package/dist/bundling-sources/sdk/src/http-core.ts +41 -12
- 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 +21 -3
- package/dist/bundling-sources/shared_libs/play-data-plane/contracts.ts +5 -0
- package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +17 -2
- package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +27 -0
- package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +57 -5
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +299 -52
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +18 -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/fleet-sandbox-sweep.ts +40 -3
- package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +19 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +18 -4
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +441 -103
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox-egress.ts +322 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/early-sandbox.ts +200 -64
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +52 -14
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-speed-profile.ts +65 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +5 -3
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +53 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/early-sandbox-lane.ts +206 -12
- 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/scheduler-backends/runtime-worker-wake.ts +30 -2
- 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 +36 -2
- 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 +41 -2
- 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/email-blacklist.ts +35 -1
- package/dist/bundling-sources/shared_libs/security/email-domain.ts +19 -0
- package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +58 -0
- package/dist/cli/auth-AC5277PI.js +43 -0
- package/dist/cli/{auth-VZAMAMFW.mjs → auth-WJEY4IDX.mjs} +6 -6
- package/dist/cli/{billing-ASZJDFH2.js → billing-IJITDDRQ.js} +99 -99
- package/dist/cli/{billing-DADQUQEZ.mjs → billing-PHJUDYF3.mjs} +11 -11
- package/dist/cli/{chunk-FB7UPZ6M.js → chunk-2AHY47SI.js} +3 -3
- package/dist/cli/{chunk-CJ7DBYEQ.js → chunk-2HPTLBNB.js} +8 -8
- package/dist/cli/{chunk-TI6DTURF.js → chunk-4WAM6TLD.js} +7 -1
- package/dist/cli/{chunk-LTCEZWPZ.mjs → chunk-56MEAGWA.mjs} +2 -2
- package/dist/cli/{chunk-YWTRCKGD.mjs → chunk-5SFHPMBY.mjs} +11 -11
- package/dist/cli/{chunk-D3SXB2NX.js → chunk-ABLTVG3J.js} +41 -41
- package/dist/cli/{chunk-KRW727W6.mjs → chunk-AEQ5VWZ5.mjs} +4 -4
- package/dist/cli/{chunk-Z7QM244Q.mjs → chunk-CKIRKYW7.mjs} +3 -3
- package/dist/cli/{chunk-2JHYYB3F.js → chunk-CSPHSNBW.js} +3 -3
- package/dist/cli/{chunk-OGQYAJSO.js → chunk-D6OIEH47.js} +5 -5
- package/dist/cli/{chunk-2HFSYH7V.mjs → chunk-DIUNDLSX.mjs} +2 -2
- package/dist/cli/{chunk-3M2QH3KA.mjs → chunk-DJI5CLLW.mjs} +22 -12
- package/dist/cli/{chunk-N4LADLCO.js → chunk-DZC7LMYM.js} +6 -6
- package/dist/cli/{chunk-CXETRZ3G.js → chunk-E2OIYPB4.js} +10 -10
- package/dist/cli/{chunk-Z4Y4BLW7.mjs → chunk-ECUD4QPD.mjs} +3 -3
- package/dist/cli/{chunk-2GJZLIKW.js → chunk-EITMD3A5.js} +1 -1
- package/dist/cli/{chunk-NAN3A4IF.mjs → chunk-ESCVHDNY.mjs} +5 -5
- package/dist/cli/{chunk-C6XYSTBW.js → chunk-FFBXLFKV.js} +1 -1
- package/dist/cli/{chunk-HLUNTJBO.mjs → chunk-FMQXAOVE.mjs} +4 -4
- package/dist/cli/{chunk-HXIR3VQL.mjs → chunk-FZHMNK6F.mjs} +7 -1
- package/dist/cli/{chunk-4NZ3OZNO.mjs → chunk-G6KW764N.mjs} +1 -1
- package/dist/cli/{chunk-LWPFMYSO.mjs → chunk-G6XTCG3J.mjs} +2 -2
- package/dist/cli/{chunk-NCX2JH2F.js → chunk-GIGAYLY6.js} +12 -12
- package/dist/cli/{chunk-BLYW6FFB.js → chunk-GJA2PRHJ.js} +2 -2
- package/dist/cli/{chunk-G5TV6WLV.js → chunk-GJOGFWX3.js} +20 -20
- package/dist/cli/{chunk-7MFATEUC.mjs → chunk-GPAWLXW3.mjs} +2 -2
- package/dist/cli/{chunk-DZTVDL2X.js → chunk-GZFZZQL4.js} +289 -268
- package/dist/cli/{chunk-XBYQZEUE.mjs → chunk-HARZ4AAX.mjs} +1 -1
- package/dist/cli/{chunk-QI57XUGA.js → chunk-HFIFKP3A.js} +5 -5
- package/dist/cli/{chunk-WP36UBRY.mjs → chunk-IGAK22XO.mjs} +1 -1
- package/dist/cli/{chunk-XMUPZINS.mjs → chunk-IKYN6PLO.mjs} +5 -5
- package/dist/cli/{chunk-HPX7LLAM.mjs → chunk-ITLZBDSR.mjs} +3 -3
- package/dist/cli/{chunk-QM7PHHYZ.js → chunk-IVFFCAV2.js} +44 -44
- package/dist/cli/{chunk-IYJO3RWR.js → chunk-K3GMDSUX.js} +5 -5
- package/dist/cli/{chunk-EK5C2R7S.js → chunk-L5J6UJ2X.js} +15 -15
- package/dist/cli/{chunk-EWA3M54M.mjs → chunk-L6QE2XVM.mjs} +1 -1
- package/dist/cli/{chunk-3NG43NXB.js → chunk-LMLSOHTU.js} +53 -53
- package/dist/cli/{chunk-7MHBJU73.js → chunk-MBQELFL7.js} +22 -22
- package/dist/cli/{chunk-Z7SXGOIQ.mjs → chunk-MF7PCM6C.mjs} +1 -1
- package/dist/cli/{chunk-DGKDCZGC.js → chunk-MO7TGNXB.js} +13 -13
- package/dist/cli/{chunk-7P72EGLK.mjs → chunk-MOZEAGSR.mjs} +1 -1
- package/dist/cli/{chunk-34UKDHRL.js → chunk-N63U5CRG.js} +26 -26
- package/dist/cli/{chunk-5YYWZ43J.js → chunk-NBYFQZ6O.js} +2 -2
- package/dist/cli/{chunk-CQBIO6HW.mjs → chunk-NURW5XH4.mjs} +1 -1
- package/dist/cli/{chunk-TQKHXMV3.js → chunk-OVYXYTEP.js} +16 -16
- package/dist/cli/{chunk-XGEUPU3L.mjs → chunk-PBMO36BP.mjs} +2 -2
- package/dist/cli/{chunk-4JQEAYN3.js → chunk-PVQCX6KQ.js} +55 -8
- package/dist/cli/{chunk-KYO2FICL.mjs → chunk-QLE3QKJ2.mjs} +5 -5
- package/dist/cli/{chunk-2FF3O2Y2.js → chunk-QU3K3IY6.js} +12 -12
- package/dist/cli/{chunk-HR5BT42R.js → chunk-REAFIEV5.js} +99 -99
- package/dist/cli/{chunk-Y3T5GWYK.mjs → chunk-RMCCB3XY.mjs} +55 -8
- package/dist/cli/{chunk-3TCHX7YK.mjs → chunk-RXRC2COC.mjs} +2 -2
- package/dist/cli/{chunk-YRQKRQDU.js → chunk-SAJWYN4B.js} +36 -26
- package/dist/cli/{chunk-JL5JU3LD.mjs → chunk-TNJG4ZPN.mjs} +3 -3
- package/dist/cli/{chunk-NZDZGK35.js → chunk-VNOQEDVC.js} +7 -7
- package/dist/cli/{chunk-2CBX43LP.mjs → chunk-VPF54TXQ.mjs} +5 -5
- package/dist/cli/{chunk-2HSZCQMT.mjs → chunk-WYT3H6JD.mjs} +1 -1
- package/dist/cli/{chunk-GWDPNOA7.mjs → chunk-XMBVHJPR.mjs} +29 -8
- package/dist/cli/{chunk-52C6W7FG.mjs → chunk-XNTDTAKC.mjs} +1 -1
- package/dist/cli/{chunk-ERLW6RPA.js → chunk-YURGAKI3.js} +2 -2
- package/dist/cli/{chunk-GFRJU2KB.js → chunk-YVKLF7RW.js} +2 -2
- package/dist/cli/{chunk-7JZ27AFH.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-YP7ALTDB.mjs → concurrent-runs-help-ZNGP563R.mjs} +7 -7
- package/dist/cli/concurrent-runs-help-ZYISYOQA.js +21 -0
- package/dist/cli/{csv-D5ITFSYI.mjs → csv-VAHQHYYV.mjs} +5 -5
- package/dist/cli/{csv-67WT5EGR.js → csv-X6D4ZELE.js} +14 -14
- package/dist/cli/{db-SZYBRFYG.mjs → db-4G4S2VOV.mjs} +8 -8
- package/dist/cli/{db-GZS76X7R.js → db-YA5ZGVEX.js} +33 -33
- package/dist/cli/{describe-YJ7ZLLLI.mjs → describe-EVXEM2S6.mjs} +20 -20
- 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/describe-core.js +1 -1
- package/dist/cli/describe-core.mjs +1 -1
- package/dist/cli/{executions-O5USTYGL.js → executions-5YC7ABF6.js} +10 -10
- package/dist/cli/{executions-HMYGR32E.mjs → executions-HR6CTN5M.mjs} +8 -8
- package/dist/cli/{feedback-Z3NXWYUO.mjs → feedback-GEU5SPLR.mjs} +7 -7
- package/dist/cli/{feedback-RHLFDCRS.js → feedback-MJHSYLFF.js} +15 -15
- package/dist/cli/git-FZIQZNI4.js +25 -0
- package/dist/cli/{git-CLFKXELB.mjs → git-NPFF6QUS.mjs} +6 -6
- package/dist/cli/index.js +150 -150
- package/dist/cli/index.mjs +46 -46
- package/dist/cli/{integrations-TZ4QEQGV.js → integrations-YPHFI77G.js} +20 -18
- package/dist/cli/{integrations-FOACOBQB.mjs → integrations-Z7EGVBHF.mjs} +12 -10
- package/dist/cli/{legacy-noops-QRDOS33V.js → legacy-noops-246E3KKG.js} +10 -10
- package/dist/cli/{legacy-noops-6F6Y3BV7.mjs → legacy-noops-5IYCFWWX.mjs} +7 -7
- package/dist/cli/{mcp-UXRCWOZU.mjs → mcp-WUYGZXPI.mjs} +5 -5
- package/dist/cli/{mcp-ETMMDDGB.js → mcp-YTYTW67G.js} +25 -25
- package/dist/cli/{monitors-6XEWR46R.mjs → monitors-73DQKCU7.mjs} +27 -9
- package/dist/cli/{monitors-DITT7QTV.js → monitors-SA6ILD6Z.js} +121 -103
- package/dist/cli/{org-CVSSH73G.mjs → org-WVQRB2KX.mjs} +8 -8
- package/dist/cli/{org-4DE37X3L.js → org-X7ELDV7B.js} +90 -90
- package/dist/cli/{play-Y5NCHOKK.mjs → play-QI6V2EUQ.mjs} +296 -68
- package/dist/cli/{play-RH6P45CI.js → play-QTYOAJPE.js} +898 -670
- package/dist/cli/{providers-VHUHC4IZ.mjs → providers-DPVMVDS4.mjs} +8 -8
- package/dist/cli/{providers-DU42DLOL.js → providers-XXFLVREV.js} +11 -11
- package/dist/cli/{quickstart-XJ43JLEC.js → quickstart-33ISXQJU.js} +7 -7
- package/dist/cli/{quickstart-HJY5YYE5.mjs → quickstart-YWGNHULM.mjs} +5 -5
- package/dist/cli/{run-JXUS7QFI.js → run-BWHZXLTD.js} +46 -46
- package/dist/cli/{run-JAIXHVH7.mjs → run-J6FCAKQC.mjs} +26 -26
- package/dist/cli/search-JCWJX2XD.js +32 -0
- package/dist/cli/{search-RDMNM2AX.mjs → search-Z3UU3WBB.mjs} +9 -9
- package/dist/cli/{search-output-ZKTR3WTJ.mjs → search-output-OJYY4J7E.mjs} +5 -5
- package/dist/cli/{search-output-RKAM2HBH.js → search-output-YIPV74ME.js} +7 -7
- package/dist/cli/{secrets-TKFVMAYX.js → secrets-UXRJCEN4.js} +17 -17
- package/dist/cli/{secrets-WSW3FTF6.mjs → secrets-YZZN2WST.mjs} +8 -8
- package/dist/cli/{sessions-724BK6VP.mjs → sessions-ITCGPD7Z.mjs} +7 -7
- package/dist/cli/sessions-NA4SJH6Q.js +22 -0
- package/dist/cli/{settings-5LJZDAZU.js → settings-LAFYMILP.js} +87 -87
- package/dist/cli/{settings-YRC7J75G.mjs → settings-ZP2LSVNM.mjs} +14 -14
- package/dist/cli/{setup-2F3DBSOS.js → setup-4AL3XYM5.js} +50 -50
- package/dist/cli/{setup-STNPX5MK.mjs → setup-WEQAQSYC.mjs} +10 -10
- package/dist/cli/{skills-D5PK56FO.mjs → skills-NQH4HFW2.mjs} +8 -8
- package/dist/cli/skills-XZ4Y6SZ7.js +36 -0
- package/dist/cli/{tools-WOGWMBA3.mjs → tools-CXK2GSI4.mjs} +19 -19
- package/dist/cli/tools-WJQ6Y7E4.js +57 -0
- package/dist/cli/{update-PC6XSWMI.mjs → update-3ROF3Z75.mjs} +10 -10
- package/dist/cli/update-ZLRLTBRD.js +34 -0
- package/dist/cli/{views-IIHT4RYQ.mjs → views-AOUHVGV2.mjs} +8 -8
- package/dist/cli/{views-HLCLAPWN.js → views-XJFO5CEH.js} +23 -23
- package/dist/cli/{workflow-CCZ2A7DI.js → workflow-GY3DBHXX.js} +19 -19
- package/dist/cli/{workflow-HK4MZ7LK.mjs → workflow-KBS2QJK6.mjs} +9 -9
- package/dist/{client-DfdUc_MY.d.mts → client-D1uWA2Vc.d.mts} +1 -1
- package/dist/{client-BQ6yuSjM.d.ts → client-Hz7SsBXs.d.ts} +1 -1
- package/dist/{client-core-3GQ8WMuk.d.ts → client-core-D3Ad7Flt.d.ts} +554 -504
- package/dist/{client-core-ClsNRytk.d.mts → client-core-Db_e63Hb.d.mts} +554 -504
- package/dist/{compiler-manifest-BWFtsQIC.d.mts → compiler-manifest-BqwVrOri.d.mts} +73 -18
- package/dist/{compiler-manifest-BWFtsQIC.d.ts → compiler-manifest-BqwVrOri.d.ts} +73 -18
- package/dist/{errors-Lm9_vJHZ.d.ts → errors-BU8FB99X.d.mts} +2 -2
- package/dist/{errors-CwKXXtuu.d.mts → errors-DfVN_FUG.d.ts} +2 -2
- package/dist/{index-3vJ-V9yw.d.ts → index-BGnvtYGc.d.ts} +6 -1
- package/dist/{index-DjwsAt82.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 +65 -40
- package/dist/index.mjs +33 -8
- package/dist/install-integrity.json +137 -130
- 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 +640 -125
- 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 +11 -11
- package/dist/server.mjs +5 -5
- package/package.json +1 -1
- package/dist/cli/auth-455MB4K6.js +0 -43
- package/dist/cli/concurrent-runs-help-GFWXOKF5.js +0 -21
- package/dist/cli/describe-ZRGYAEBT.js +0 -50
- package/dist/cli/git-RC4XDATD.js +0 -25
- package/dist/cli/search-O5VVMXII.js +0 -32
- package/dist/cli/sessions-3PWFWCHO.js +0 -22
- package/dist/cli/skills-RFOMVXIT.js +0 -36
- package/dist/cli/tools-CAO6EVUW.js +0 -57
- package/dist/cli/update-L4DQZY3G.js +0 -34
|
@@ -141,6 +141,14 @@ export type PlayDocflowBinding = {
|
|
|
141
141
|
* {@link attachBindingsToBlocks}; the edge is what readers resolve against.
|
|
142
142
|
*/
|
|
143
143
|
arm?: PlayDocflowArm;
|
|
144
|
+
/**
|
|
145
|
+
* `show:"ownerName,territory"` — the fields of this node's value a reader
|
|
146
|
+
* should see first, as paths into it. Plays can return anything, so which
|
|
147
|
+
* fields matter is the author's to say; without it, displays fall back to a
|
|
148
|
+
* neutral peek and never guess. Absent (never empty) when undeclared, so a
|
|
149
|
+
* diagram that declares none hashes byte for byte as before.
|
|
150
|
+
*/
|
|
151
|
+
show?: string[];
|
|
144
152
|
};
|
|
145
153
|
|
|
146
154
|
export type PlayDocflow = {
|
|
@@ -159,11 +167,29 @@ export type PlayDocflow = {
|
|
|
159
167
|
subgraphs?: PlayDocflowSubgraph[];
|
|
160
168
|
/** Mermaid directives accepted by the parser but not applied by React Flow. */
|
|
161
169
|
ignoredDirectives?: string[];
|
|
170
|
+
/**
|
|
171
|
+
* `%% @input show:"leadId,company.name"` in the block: the fields of the
|
|
172
|
+
* run's input a reader sees first (the Start card, each run's input pill).
|
|
173
|
+
* Absent when undeclared, so an existing diagram hashes as before.
|
|
174
|
+
*/
|
|
175
|
+
inputShow?: string[];
|
|
162
176
|
};
|
|
163
177
|
|
|
164
178
|
export type PlayDocflowParseResult = {
|
|
179
|
+
/**
|
|
180
|
+
* The diagram, minus whatever did not resolve. Diagram problems never block
|
|
181
|
+
* a play (they only affect display), so a binding that names no box, or a
|
|
182
|
+
* second arm claiming the same side, is dropped and the rest still draws.
|
|
183
|
+
* Null when there is no block for the export, or its block did not parse.
|
|
184
|
+
*/
|
|
165
185
|
docflow: PlayDocflow | null;
|
|
186
|
+
/** Every diagram problem in the file. Advisory: report, never refuse. */
|
|
166
187
|
errors: string[];
|
|
188
|
+
/**
|
|
189
|
+
* Why this export's diagram could not be read at all, when its block failed
|
|
190
|
+
* to parse. The play then runs as if it had no diagram.
|
|
191
|
+
*/
|
|
192
|
+
unreadReason?: string;
|
|
167
193
|
};
|
|
168
194
|
|
|
169
195
|
export type ParsePlayDocflowOptions = {
|
|
@@ -198,16 +224,26 @@ export type PlayDocflowFileParseResult = {
|
|
|
198
224
|
*/
|
|
199
225
|
bindings: PlayDocflowBinding[];
|
|
200
226
|
errors: string[];
|
|
227
|
+
/**
|
|
228
|
+
* Blocks dropped because they did not parse, with the first reason. The
|
|
229
|
+
* export is the authored header (`null` for an unnamed block).
|
|
230
|
+
*/
|
|
231
|
+
unreadBlocks: Array<{ authoredExportName: string | null; reason: string }>;
|
|
201
232
|
};
|
|
202
233
|
|
|
203
234
|
export type PlayDocflowLintIssue = {
|
|
204
235
|
code:
|
|
205
236
|
| 'docflow_branch_labels_required'
|
|
206
237
|
| 'docflow_branch_requires_decision'
|
|
238
|
+
| 'docflow_decision_arms_incomplete'
|
|
239
|
+
| 'docflow_decision_outside_region'
|
|
240
|
+
| 'docflow_region_exits_unlabeled'
|
|
241
|
+
| 'docflow_show_undeclared'
|
|
207
242
|
| 'docflow_direction_not_top_down'
|
|
208
243
|
| 'docflow_layout_complexity'
|
|
209
244
|
| 'docflow_topology_invalid'
|
|
210
|
-
| '
|
|
245
|
+
| 'docflow_io_missing'
|
|
246
|
+
| 'docflow_box_is_sketch'
|
|
211
247
|
| 'docflow_input_not_found'
|
|
212
248
|
| 'docflow_output_not_found'
|
|
213
249
|
| 'docflow_label_counts_rows'
|
|
@@ -216,6 +252,12 @@ export type PlayDocflowLintIssue = {
|
|
|
216
252
|
message: string;
|
|
217
253
|
path?: string;
|
|
218
254
|
hint?: string;
|
|
255
|
+
/** The diagram box (or subgraph) the issue is about, when it is about one. */
|
|
256
|
+
node?: string;
|
|
257
|
+
/** The entry file's line to edit: the box's annotation, or its diagram line. */
|
|
258
|
+
line?: number;
|
|
259
|
+
/** One line to paste, tailored to this box: an annotation, edge or move. */
|
|
260
|
+
fix?: string;
|
|
219
261
|
};
|
|
220
262
|
|
|
221
263
|
export class PlayDocflowCompileError extends Error {
|
|
@@ -228,8 +270,14 @@ export class PlayDocflowCompileError extends Error {
|
|
|
228
270
|
}
|
|
229
271
|
}
|
|
230
272
|
|
|
273
|
+
// Boxes one view of the canvas shows: the top level with every region folded
|
|
274
|
+
// (the default), or one opened region's direct members. A region counts as one
|
|
275
|
+
// box at the level that holds it, so a Play with several phases stays readable.
|
|
231
276
|
const DOCFLOW_MAX_NODES = 12;
|
|
232
|
-
|
|
277
|
+
// Outcomes one decision draws. A decision legitimately has N outcomes (six
|
|
278
|
+
// territory reps are six arms), and the canvas lays them out side by side, so
|
|
279
|
+
// this is a readability warning, never a publish-blocking error.
|
|
280
|
+
const DOCFLOW_MAX_BRANCHES = 8;
|
|
233
281
|
const DOCFLOW_MAX_LABEL_LENGTH = 48;
|
|
234
282
|
|
|
235
283
|
// A node label names the thing; the runtime counts it. A label that bakes a
|
|
@@ -262,7 +310,14 @@ const MERMAID_NODE = /^\s*\/\/\s*@mermaid-node\s+([A-Za-z][\w-]*)(?:\s+(.*))?$/;
|
|
|
262
310
|
/** Whole-file pre-filter for {@link MERMAID_NODE}; skips splitting clean files. */
|
|
263
311
|
const MERMAID_NODE_HINT = /@mermaid-node/;
|
|
264
312
|
const ATTRIBUTE = /([A-Za-z][\w-]*)\s*:\s*"([^"\n]*)"/y;
|
|
265
|
-
const MERMAID_NODE_ATTRIBUTES = [
|
|
313
|
+
const MERMAID_NODE_ATTRIBUTES = [
|
|
314
|
+
'label',
|
|
315
|
+
'type',
|
|
316
|
+
'in',
|
|
317
|
+
'out',
|
|
318
|
+
'arm',
|
|
319
|
+
'show',
|
|
320
|
+
] as const;
|
|
266
321
|
const MERMAID_NODE_ID = /^[A-Za-z][\w-]*/;
|
|
267
322
|
/**
|
|
268
323
|
* `class a,b,c sketch` — the author declaring that no statement runs these boxes.
|
|
@@ -549,7 +604,7 @@ function parseEdgeChain(
|
|
|
549
604
|
|
|
550
605
|
function parseContractPaths(
|
|
551
606
|
value: string | undefined,
|
|
552
|
-
attribute: 'in' | 'out',
|
|
607
|
+
attribute: 'in' | 'out' | 'show',
|
|
553
608
|
nodeId: string,
|
|
554
609
|
line: number,
|
|
555
610
|
errors: string[],
|
|
@@ -627,6 +682,150 @@ function rootPath(path: string): string {
|
|
|
627
682
|
return path.split('.')[0]!;
|
|
628
683
|
}
|
|
629
684
|
|
|
685
|
+
const escapeRegExp = (text: string) =>
|
|
686
|
+
text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Where a box lives in the entry file, so a lint issue can name the line to
|
|
690
|
+
* edit: its `// @mermaid-node` annotation, or the diagram line that declares it
|
|
691
|
+
* (`id[…]`, `id{…}`, `subgraph id`). Undefined without source, or when the box
|
|
692
|
+
* is not written in the entry file.
|
|
693
|
+
*/
|
|
694
|
+
function docflowSourceLocator(sourceCode: string | undefined) {
|
|
695
|
+
const lines = sourceCode?.split(/\r?\n/) ?? [];
|
|
696
|
+
const diagramLines: number[] = [];
|
|
697
|
+
let inside = false;
|
|
698
|
+
lines.forEach((text, index) => {
|
|
699
|
+
if (!inside && /\/\*\*\s*@mermaid\b/.test(text)) inside = true;
|
|
700
|
+
if (inside) diagramLines.push(index);
|
|
701
|
+
if (inside && text.includes('*/')) inside = false;
|
|
702
|
+
});
|
|
703
|
+
const first = (indexes: Iterable<number>, pattern: RegExp) => {
|
|
704
|
+
for (const index of indexes) {
|
|
705
|
+
if (pattern.test(lines[index]!)) return index + 1;
|
|
706
|
+
}
|
|
707
|
+
return undefined;
|
|
708
|
+
};
|
|
709
|
+
return {
|
|
710
|
+
annotation(id: string): number | undefined {
|
|
711
|
+
return first(
|
|
712
|
+
lines.keys(),
|
|
713
|
+
new RegExp(`//\\s*@mermaid-node\\s+${escapeRegExp(id)}(?![\\w-])`),
|
|
714
|
+
);
|
|
715
|
+
},
|
|
716
|
+
diagram(id: string): number | undefined {
|
|
717
|
+
const name = `(?<![\\w-])${escapeRegExp(id)}(?![\\w-])`;
|
|
718
|
+
return (
|
|
719
|
+
first(diagramLines, new RegExp(`${name}\\s*[[({>]`)) ??
|
|
720
|
+
first(diagramLines, new RegExp(`\\bsubgraph\\s+${name}`)) ??
|
|
721
|
+
first(
|
|
722
|
+
diagramLines.filter(
|
|
723
|
+
(index) => !/^\s*\*?\s*(?:class\s|%%)/.test(lines[index]!),
|
|
724
|
+
),
|
|
725
|
+
new RegExp(name),
|
|
726
|
+
)
|
|
727
|
+
);
|
|
728
|
+
},
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* The `// @mermaid-node` line this binding should read, with `changes`
|
|
734
|
+
* applied: what a fix tells the author to paste. Attributes keep the order the
|
|
735
|
+
* syntax help teaches.
|
|
736
|
+
*/
|
|
737
|
+
function docflowAnnotationFix(
|
|
738
|
+
binding: Pick<
|
|
739
|
+
PlayDocflowBinding,
|
|
740
|
+
'nodeId' | 'kind' | 'inputs' | 'outputs' | 'arm' | 'show' | 'label'
|
|
741
|
+
>,
|
|
742
|
+
changes: { in?: string; out?: string; show?: string } = {},
|
|
743
|
+
): string {
|
|
744
|
+
const join = (paths: string[] | undefined) =>
|
|
745
|
+
paths?.length ? paths.join(',') : undefined;
|
|
746
|
+
const attributes: Array<[string, string | undefined]> = [
|
|
747
|
+
['type', binding.kind && binding.kind !== 'action' ? binding.kind : undefined],
|
|
748
|
+
['in', changes.in ?? join(binding.inputs)],
|
|
749
|
+
['out', changes.out ?? join(binding.outputs)],
|
|
750
|
+
['arm', binding.arm],
|
|
751
|
+
['show', changes.show ?? join(binding.show)],
|
|
752
|
+
['label', binding.label],
|
|
753
|
+
];
|
|
754
|
+
return [
|
|
755
|
+
`// @mermaid-node ${binding.nodeId}`,
|
|
756
|
+
...attributes
|
|
757
|
+
.filter(([, value]) => value !== undefined)
|
|
758
|
+
.map(([name, value]) => `${name}:"${value}"`),
|
|
759
|
+
].join(' ');
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* The top-level field names of the object literal a bound statement builds
|
|
764
|
+
* (`const x = { a, b: 1, ...rest }` → `['a', 'b']`, spread `true`), read from
|
|
765
|
+
* the statement's first `{` on `lines[startLine]` onward. Null when the text is
|
|
766
|
+
* not a closed literal within a bounded scan; the caller then knows nothing.
|
|
767
|
+
*/
|
|
768
|
+
function objectLiteralFields(
|
|
769
|
+
lines: readonly string[],
|
|
770
|
+
startLine: number,
|
|
771
|
+
): { fields: string[]; spread: boolean } | null {
|
|
772
|
+
const text = lines.slice(startLine, startLine + 200).join('\n');
|
|
773
|
+
const open = text.indexOf('{');
|
|
774
|
+
if (open < 0) return null;
|
|
775
|
+
const fields: string[] = [];
|
|
776
|
+
let spread = false;
|
|
777
|
+
let depth = 0;
|
|
778
|
+
let quote: string | null = null;
|
|
779
|
+
// At depth 1, the start of each property (after `{` or a top-level `,`).
|
|
780
|
+
let atProperty = false;
|
|
781
|
+
for (let index = open; index < text.length && index < open + 8_000; index++) {
|
|
782
|
+
const char = text[index]!;
|
|
783
|
+
if (quote) {
|
|
784
|
+
if (char === '\\') index += 1;
|
|
785
|
+
else if (char === quote) quote = null;
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
788
|
+
if (char === '/' && (text[index + 1] === '/' || text[index + 1] === '*')) {
|
|
789
|
+
const end =
|
|
790
|
+
text[index + 1] === '/'
|
|
791
|
+
? text.indexOf('\n', index)
|
|
792
|
+
: text.indexOf('*/', index + 2) + 1;
|
|
793
|
+
if (end <= 0) return null;
|
|
794
|
+
index = end;
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
798
|
+
quote = char;
|
|
799
|
+
atProperty = false;
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
if (char === '{' || char === '[' || char === '(') {
|
|
803
|
+
depth += 1;
|
|
804
|
+
atProperty = depth === 1;
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
if (char === '}' || char === ']' || char === ')') {
|
|
808
|
+
depth -= 1;
|
|
809
|
+
if (depth === 0) return { fields, spread };
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
if (depth !== 1) continue;
|
|
813
|
+
if (char === ',') {
|
|
814
|
+
atProperty = true;
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
if (!atProperty || /\s/.test(char)) continue;
|
|
818
|
+
atProperty = false;
|
|
819
|
+
if (text.startsWith('...', index)) {
|
|
820
|
+
spread = true;
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
const name = /^[A-Za-z_$][\w$]*/.exec(text.slice(index))?.[0];
|
|
824
|
+
if (name) fields.push(name);
|
|
825
|
+
}
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
|
|
630
829
|
function levenshtein(left: string, right: string): number {
|
|
631
830
|
const row = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
632
831
|
for (let leftIndex = 1; leftIndex <= left.length; leftIndex += 1) {
|
|
@@ -714,6 +913,8 @@ type ParsedDocflowBlock = ParsedDocflowBlockGraph & {
|
|
|
714
913
|
syntax: NonNullable<PlayDocflow['syntax']>;
|
|
715
914
|
mermaidSource: string;
|
|
716
915
|
bindings: PlayDocflowBinding[];
|
|
916
|
+
/** The block's `%% @input show:"…"` fields, when declared. */
|
|
917
|
+
inputShow?: string[];
|
|
717
918
|
};
|
|
718
919
|
|
|
719
920
|
/** How a block is named in a diagnostic. */
|
|
@@ -728,9 +929,60 @@ function blockLabel(block: { authoredExportName: string | null }): string {
|
|
|
728
929
|
* null when the block does not open with a direction, which is the one error
|
|
729
930
|
* that makes the rest of the block unreadable.
|
|
730
931
|
*/
|
|
932
|
+
/**
|
|
933
|
+
* Where each diagram line sits in the play file, so a syntax error names the
|
|
934
|
+
* line the author has to fix rather than leaving them to find it. The diagram
|
|
935
|
+
* lines are the block's own lines in order (blank and `%%` lines dropped), so a
|
|
936
|
+
* forward scan over the block's raw lines, gutter stripped, finds each one.
|
|
937
|
+
*/
|
|
938
|
+
type DocflowLineLocator = (diagramLine: string) => number | null;
|
|
939
|
+
|
|
940
|
+
function docflowBlockLineLocator(
|
|
941
|
+
sourceCode: string,
|
|
942
|
+
blockStart: number,
|
|
943
|
+
blockText: string,
|
|
944
|
+
): DocflowLineLocator {
|
|
945
|
+
const firstLine = sourceCode.slice(0, blockStart).split(/\r?\n/).length;
|
|
946
|
+
const rawLines = blockText.split(/\r?\n/).map((line) =>
|
|
947
|
+
line
|
|
948
|
+
.replace(/^\s*\/\*\*/, '')
|
|
949
|
+
.replace(/\*\/\s*$/, '')
|
|
950
|
+
.replace(/^\s*\* ?/, '')
|
|
951
|
+
.trim(),
|
|
952
|
+
);
|
|
953
|
+
let cursor = 0;
|
|
954
|
+
return (diagramLine) => {
|
|
955
|
+
const wanted = diagramLine.trim();
|
|
956
|
+
if (!wanted) return null;
|
|
957
|
+
for (let index = cursor; index < rawLines.length; index += 1) {
|
|
958
|
+
// The header line `@mermaid flowchart TD` carries the diagram's first
|
|
959
|
+
// line after its tag.
|
|
960
|
+
const raw = rawLines[index]!.replace(/^@mermaid\b\s*/, '');
|
|
961
|
+
if (raw === wanted || raw.endsWith(` ${wanted}`)) {
|
|
962
|
+
cursor = index + 1;
|
|
963
|
+
return firstLine + index;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
return null;
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/** Suffixes the errors pushed since `from` with the file line they are about. */
|
|
971
|
+
function locateDocflowErrors(
|
|
972
|
+
errors: string[],
|
|
973
|
+
from: number,
|
|
974
|
+
line: number | null,
|
|
975
|
+
): void {
|
|
976
|
+
if (line === null) return;
|
|
977
|
+
for (let index = from; index < errors.length; index += 1) {
|
|
978
|
+
errors[index] = `${errors[index]} (line ${line})`;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
|
|
731
982
|
function parseDocflowBlockGraph(
|
|
732
983
|
mermaidSource: string,
|
|
733
984
|
errors: string[],
|
|
985
|
+
locate: DocflowLineLocator = () => null,
|
|
734
986
|
): ParsedDocflowBlockGraph | null {
|
|
735
987
|
const docLines = mermaidSource
|
|
736
988
|
.split(/\r?\n/)
|
|
@@ -739,11 +991,21 @@ function parseDocflowBlockGraph(
|
|
|
739
991
|
| PlayDocflow['direction']
|
|
740
992
|
| undefined;
|
|
741
993
|
if (!direction) {
|
|
994
|
+
const firstErrorAt = errors.length;
|
|
742
995
|
errors.push(
|
|
743
|
-
|
|
996
|
+
docLines[0]
|
|
997
|
+
? `Docflow must start with \`flowchart\` or \`graph\` and direction \`LR\`, \`RL\`, \`TB\`, \`TD\`, or \`BT\`; found: ${docLines[0].trim()}`
|
|
998
|
+
: 'Docflow must start with `flowchart` or `graph` and direction `LR`, `RL`, `TB`, `TD`, or `BT`.',
|
|
999
|
+
);
|
|
1000
|
+
locateDocflowErrors(
|
|
1001
|
+
errors,
|
|
1002
|
+
firstErrorAt,
|
|
1003
|
+
docLines[0] ? locate(docLines[0]) : null,
|
|
744
1004
|
);
|
|
745
1005
|
return null;
|
|
746
1006
|
}
|
|
1007
|
+
// Consumes the header line, so the scan for the body starts after it.
|
|
1008
|
+
locate(docLines[0]!);
|
|
747
1009
|
|
|
748
1010
|
const nodes = new Map<string, PlayDocflowNode>();
|
|
749
1011
|
const edges: PlayDocflowEdge[] = [];
|
|
@@ -823,91 +1085,101 @@ function parseDocflowBlockGraph(
|
|
|
823
1085
|
}
|
|
824
1086
|
return sawDeclaration;
|
|
825
1087
|
};
|
|
1088
|
+
/** File line each still-open subgraph was opened on. */
|
|
1089
|
+
const openedAt = new Map<PlayDocflowSubgraph, number | null>();
|
|
826
1090
|
for (const line of docLines.slice(1)) {
|
|
827
|
-
const
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
'Docflow has an `end` with no open `subgraph` above it. Every `end` closes exactly one `subgraph`.',
|
|
852
|
-
);
|
|
1091
|
+
const lineErrorsFrom = errors.length;
|
|
1092
|
+
const fileLine = locate(line);
|
|
1093
|
+
try {
|
|
1094
|
+
const opened = SUBGRAPH_OPEN.exec(line);
|
|
1095
|
+
if (opened) {
|
|
1096
|
+
const id = opened[1]!;
|
|
1097
|
+
const rawLabel = opened[2]?.trim() ?? '';
|
|
1098
|
+
const label =
|
|
1099
|
+
rawLabel.length >= 2 &&
|
|
1100
|
+
((rawLabel.startsWith('"') && rawLabel.endsWith('"')) ||
|
|
1101
|
+
(rawLabel.startsWith("'") && rawLabel.endsWith("'")))
|
|
1102
|
+
? rawLabel.slice(1, -1)
|
|
1103
|
+
: rawLabel;
|
|
1104
|
+
const parent = subgraphStack[subgraphStack.length - 1];
|
|
1105
|
+
const subgraph: PlayDocflowSubgraph = {
|
|
1106
|
+
id,
|
|
1107
|
+
label: label || id,
|
|
1108
|
+
memberIds: [],
|
|
1109
|
+
...(parent ? { parentId: parent.id } : {}),
|
|
1110
|
+
};
|
|
1111
|
+
subgraphs.set(id, subgraph);
|
|
1112
|
+
subgraphStack.push(subgraph);
|
|
1113
|
+
openedAt.set(subgraph, fileLine);
|
|
1114
|
+
continue;
|
|
853
1115
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
/^\s*(?:direction|classDef|class|style|linkStyle|click)\b/i.test(line);
|
|
860
|
-
if (isDirective) {
|
|
861
|
-
const sketch = SKETCH_CLASS.exec(line);
|
|
862
|
-
if (sketch) {
|
|
863
|
-
for (const id of sketch[1]!.split(',')) {
|
|
864
|
-
const trimmed = id.trim();
|
|
865
|
-
if (trimmed) sketchIds.add(trimmed);
|
|
1116
|
+
if (SUBGRAPH_END.test(line)) {
|
|
1117
|
+
if (subgraphStack.length === 0) {
|
|
1118
|
+
errors.push(
|
|
1119
|
+
'Docflow has an `end` with no open `subgraph` above it. Every `end` closes exactly one `subgraph`.',
|
|
1120
|
+
);
|
|
866
1121
|
}
|
|
867
|
-
|
|
868
|
-
|
|
1122
|
+
subgraphStack.pop();
|
|
1123
|
+
continue;
|
|
869
1124
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
);
|
|
1125
|
+
let declaredOnThisLine = false;
|
|
1126
|
+
const isDirective =
|
|
1127
|
+
/^\s*(?:direction|classDef|class|style|linkStyle|click)\b/i.test(line);
|
|
1128
|
+
if (isDirective) {
|
|
1129
|
+
const sketch = SKETCH_CLASS.exec(line);
|
|
1130
|
+
if (sketch) {
|
|
1131
|
+
for (const id of sketch[1]!.split(',')) {
|
|
1132
|
+
const trimmed = id.trim();
|
|
1133
|
+
if (trimmed) sketchIds.add(trimmed);
|
|
1134
|
+
}
|
|
1135
|
+
} else {
|
|
1136
|
+
ignoredDirectives.push(line.trim());
|
|
1137
|
+
}
|
|
884
1138
|
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
addNodes(line, line);
|
|
888
|
-
for (const node of chain.nodes) {
|
|
889
|
-
// An edge endpoint may name a subgraph id; keep the edge but do not
|
|
890
|
-
// materialize a regular node for the region.
|
|
891
|
-
if (subgraphIds.has(node.id)) continue;
|
|
892
|
-
const existing = nodes.get(node.id);
|
|
893
|
-
if (!existing) {
|
|
894
|
-
nodes.set(node.id, node);
|
|
895
|
-
subgraphStack[subgraphStack.length - 1]?.memberIds.push(node.id);
|
|
896
|
-
} else if (existing.label === existing.id && node.label !== node.id) {
|
|
897
|
-
existing.label = node.label;
|
|
898
|
-
existing.kind = node.kind;
|
|
1139
|
+
if (!isDirective) {
|
|
1140
|
+
declaredOnThisLine = addNodes(line, line);
|
|
899
1141
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1142
|
+
const chain = parseEdgeChain(line);
|
|
1143
|
+
if (!chain) {
|
|
1144
|
+
if (!isDirective && !declaredOnThisLine) {
|
|
1145
|
+
// Mermaid the parser could not consume at all: no edge, no node
|
|
1146
|
+
// declaration, not a directive it knowingly ignores. It used to be
|
|
1147
|
+
// skipped in silence, so a typo'd arrow or a stray token simply removed
|
|
1148
|
+
// part of the diagram and nothing said so.
|
|
1149
|
+
errors.push(
|
|
1150
|
+
`Docflow line is not an edge, a node declaration, or a directive this parser understands: ${line.trim()}`,
|
|
1151
|
+
);
|
|
1152
|
+
}
|
|
1153
|
+
continue;
|
|
1154
|
+
}
|
|
1155
|
+
addNodes(line, line);
|
|
1156
|
+
for (const node of chain.nodes) {
|
|
1157
|
+
// An edge endpoint may name a subgraph id; keep the edge but do not
|
|
1158
|
+
// materialize a regular node for the region.
|
|
1159
|
+
if (subgraphIds.has(node.id)) continue;
|
|
1160
|
+
const existing = nodes.get(node.id);
|
|
1161
|
+
if (!existing) {
|
|
1162
|
+
nodes.set(node.id, node);
|
|
1163
|
+
subgraphStack[subgraphStack.length - 1]?.memberIds.push(node.id);
|
|
1164
|
+
} else if (existing.label === existing.id && node.label !== node.id) {
|
|
1165
|
+
existing.label = node.label;
|
|
1166
|
+
existing.kind = node.kind;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
for (let index = 0; index < chain.nodes.length - 1; index += 1) {
|
|
1170
|
+
edges.push({
|
|
1171
|
+
from: chain.nodes[index]!.id,
|
|
1172
|
+
to: chain.nodes[index + 1]!.id,
|
|
1173
|
+
...(chain.labels[index] ? { label: chain.labels[index] } : {}),
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
} finally {
|
|
1177
|
+
locateDocflowErrors(errors, lineErrorsFrom, fileLine);
|
|
907
1178
|
}
|
|
908
1179
|
}
|
|
909
1180
|
|
|
910
1181
|
if (subgraphStack.length > 0) {
|
|
1182
|
+
const unclosedFrom = errors.length;
|
|
911
1183
|
errors.push(
|
|
912
1184
|
`Docflow subgraph${subgraphStack.length === 1 ? '' : 's'} ${subgraphStack
|
|
913
1185
|
.map((subgraph) => `"${subgraph.id}"`)
|
|
@@ -915,6 +1187,11 @@ function parseDocflowBlockGraph(
|
|
|
915
1187
|
', ',
|
|
916
1188
|
)} ${subgraphStack.length === 1 ? 'is' : 'are'} never closed with \`end\`. Everything below an unclosed subgraph is silently drawn inside it.`,
|
|
917
1189
|
);
|
|
1190
|
+
locateDocflowErrors(
|
|
1191
|
+
errors,
|
|
1192
|
+
unclosedFrom,
|
|
1193
|
+
openedAt.get(subgraphStack[0]!) ?? null,
|
|
1194
|
+
);
|
|
918
1195
|
}
|
|
919
1196
|
|
|
920
1197
|
// An id that only ever appeared as an edge endpoint has no label of its own,
|
|
@@ -957,9 +1234,42 @@ function materializeDocflow(block: ParsedDocflowBlock): PlayDocflow {
|
|
|
957
1234
|
...(block.ignoredDirectives.length
|
|
958
1235
|
? { ignoredDirectives: block.ignoredDirectives }
|
|
959
1236
|
: {}),
|
|
1237
|
+
...(block.inputShow?.length ? { inputShow: block.inputShow } : {}),
|
|
960
1238
|
};
|
|
961
1239
|
}
|
|
962
1240
|
|
|
1241
|
+
/** `%% @input show:"a,b.c"`: the run input's declared fields, in a block. */
|
|
1242
|
+
const MERMAID_INPUT_SHOW = /^\s*%%\s*@input\b(.*)$/;
|
|
1243
|
+
|
|
1244
|
+
/**
|
|
1245
|
+
* Reads a block's `%% @input show:"…"` line. A Mermaid `%%` comment, so the
|
|
1246
|
+
* diagram still renders anywhere Mermaid does; one per block, `show` only.
|
|
1247
|
+
*/
|
|
1248
|
+
function parseBlockInputShow(
|
|
1249
|
+
diagram: string,
|
|
1250
|
+
errors: string[],
|
|
1251
|
+
): string[] | undefined {
|
|
1252
|
+
const declarations = diagram
|
|
1253
|
+
.split(/\r?\n/)
|
|
1254
|
+
.map((line) => MERMAID_INPUT_SHOW.exec(line)?.[1])
|
|
1255
|
+
.filter((rest): rest is string => rest !== undefined);
|
|
1256
|
+
if (declarations.length === 0) return undefined;
|
|
1257
|
+
if (declarations.length > 1) {
|
|
1258
|
+
errors.push(
|
|
1259
|
+
"Docflow `%% @input` appears more than once in one diagram. Declare the input's fields once.",
|
|
1260
|
+
);
|
|
1261
|
+
return undefined;
|
|
1262
|
+
}
|
|
1263
|
+
const match = /^\s+show:"([^"]*)"\s*$/.exec(declarations[0]!);
|
|
1264
|
+
if (!match) {
|
|
1265
|
+
errors.push(
|
|
1266
|
+
'Docflow `%% @input` takes one attribute: show:"field,nested.field", the run input fields a reader sees first.',
|
|
1267
|
+
);
|
|
1268
|
+
return undefined;
|
|
1269
|
+
}
|
|
1270
|
+
return parseContractPaths(match[1], 'show', '@input', 0, errors);
|
|
1271
|
+
}
|
|
1272
|
+
|
|
963
1273
|
/**
|
|
964
1274
|
* Parses EVERY `@mermaid` block in a file and binds each to the export it
|
|
965
1275
|
* describes. One file can carry one play or several; a block names its export
|
|
@@ -974,15 +1284,21 @@ export function parsePlayDocflowFile(
|
|
|
974
1284
|
const rawBlocks: Array<{
|
|
975
1285
|
syntax: NonNullable<PlayDocflow['syntax']>;
|
|
976
1286
|
body: string;
|
|
1287
|
+
locate: DocflowLineLocator;
|
|
977
1288
|
}> = [];
|
|
978
1289
|
JSDOC_BLOCK.lastIndex = 0;
|
|
979
1290
|
for (const match of sourceCode.matchAll(JSDOC_BLOCK)) {
|
|
980
1291
|
const cleanedBody = cleanBlockBody(match[1]!);
|
|
981
1292
|
const mermaid = /^@mermaid(?:[ \t]+|\r?\n|$)([\s\S]*)$/.exec(cleanedBody);
|
|
982
1293
|
if (!mermaid) continue;
|
|
983
|
-
rawBlocks.push({
|
|
1294
|
+
rawBlocks.push({
|
|
1295
|
+
syntax: 'mermaid',
|
|
1296
|
+
body: mermaid[1]!.trim(),
|
|
1297
|
+
locate: docflowBlockLineLocator(sourceCode, match.index!, match[0]),
|
|
1298
|
+
});
|
|
984
1299
|
}
|
|
985
|
-
if (rawBlocks.length === 0)
|
|
1300
|
+
if (rawBlocks.length === 0)
|
|
1301
|
+
return { blocks: [], bindings: [], errors, unreadBlocks: [] };
|
|
986
1302
|
|
|
987
1303
|
// Ids whose annotation was written but refused. They are NOT unbound boxes:
|
|
988
1304
|
// the author already has one actionable error about them, and telling them to
|
|
@@ -1003,12 +1319,24 @@ export function parsePlayDocflowFile(
|
|
|
1003
1319
|
);
|
|
1004
1320
|
|
|
1005
1321
|
const parsedBlocks: ParsedDocflowBlock[] = [];
|
|
1322
|
+
const unreadBlocks: PlayDocflowFileParseResult['unreadBlocks'] = [];
|
|
1006
1323
|
for (const raw of rawBlocks) {
|
|
1007
1324
|
const { exportName, diagram } = splitBlockExportHeader(raw.body);
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1325
|
+
const blockErrorsFrom = errors.length;
|
|
1326
|
+
const graph = parseDocflowBlockGraph(diagram, errors, raw.locate);
|
|
1327
|
+
const inputShow = graph ? parseBlockInputShow(diagram, errors) : undefined;
|
|
1328
|
+
// A block that did not parse cleanly is not drawn at all: the play runs
|
|
1329
|
+
// as if it had no diagram, and the reason is reported, never enforced.
|
|
1330
|
+
if (!graph || errors.length > blockErrorsFrom) {
|
|
1331
|
+
unreadBlocks.push({
|
|
1332
|
+
authoredExportName: exportName,
|
|
1333
|
+
reason: errors[blockErrorsFrom] ?? 'the diagram did not parse',
|
|
1334
|
+
});
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1010
1337
|
parsedBlocks.push({
|
|
1011
1338
|
...graph,
|
|
1339
|
+
...(inputShow?.length ? { inputShow } : {}),
|
|
1012
1340
|
authoredExportName: exportName,
|
|
1013
1341
|
exportName: null,
|
|
1014
1342
|
syntax: raw.syntax,
|
|
@@ -1024,6 +1352,7 @@ export function parsePlayDocflowFile(
|
|
|
1024
1352
|
bindings,
|
|
1025
1353
|
errors,
|
|
1026
1354
|
rejectedNodeIds,
|
|
1355
|
+
unreadBlocks.length > 0,
|
|
1027
1356
|
);
|
|
1028
1357
|
|
|
1029
1358
|
return {
|
|
@@ -1035,6 +1364,7 @@ export function parsePlayDocflowFile(
|
|
|
1035
1364
|
})),
|
|
1036
1365
|
bindings,
|
|
1037
1366
|
errors,
|
|
1367
|
+
unreadBlocks,
|
|
1038
1368
|
};
|
|
1039
1369
|
}
|
|
1040
1370
|
|
|
@@ -1283,6 +1613,9 @@ function attachBindingsToBlocks(
|
|
|
1283
1613
|
bindings: readonly PlayDocflowBinding[],
|
|
1284
1614
|
errors: string[],
|
|
1285
1615
|
rejectedNodeIds: ReadonlySet<string>,
|
|
1616
|
+
/** A block was not read: its annotations have nothing to name, and its
|
|
1617
|
+
* own parse error already says why. */
|
|
1618
|
+
someBlockUnread = false,
|
|
1286
1619
|
): void {
|
|
1287
1620
|
const lineStarts = sourceLineStartsForDocflow(sourceCode);
|
|
1288
1621
|
const exportRanges = playExportSourceRanges(sourceCode);
|
|
@@ -1291,7 +1624,8 @@ function attachBindingsToBlocks(
|
|
|
1291
1624
|
// A helper module can serve several plays, each drawing only its own
|
|
1292
1625
|
// boxes, so an imported annotation this play's diagram does not draw is
|
|
1293
1626
|
// another play's. An annotation in the play's own file must name a node.
|
|
1294
|
-
if (owners.length === 0 && binding.sourcePath)
|
|
1627
|
+
if (owners.length === 0 && (binding.sourcePath || someBlockUnread))
|
|
1628
|
+
continue;
|
|
1295
1629
|
if (owners.length === 0) {
|
|
1296
1630
|
errors.push(
|
|
1297
1631
|
`Docflow annotation "${binding.nodeId}" does not name a graph node.`,
|
|
@@ -1330,18 +1664,20 @@ function attachBindingsToBlocks(
|
|
|
1330
1664
|
owner.bindings.push(binding);
|
|
1331
1665
|
}
|
|
1332
1666
|
for (const block of blocks) {
|
|
1333
|
-
for (const binding of block.bindings) {
|
|
1667
|
+
for (const binding of [...block.bindings]) {
|
|
1334
1668
|
const node = block.nodes.get(binding.nodeId)!;
|
|
1335
|
-
if (binding.label) node.label = binding.label;
|
|
1336
1669
|
// A box cannot be both a sketch and a bound statement. Silently letting
|
|
1337
1670
|
// one win renders a real, traceable step as scenery — or the reverse — and
|
|
1338
|
-
// the author who wrote both has no way to see which they got.
|
|
1671
|
+
// the author who wrote both has no way to see which they got. The
|
|
1672
|
+
// drawing keeps the sketch; the binding is reported and dropped.
|
|
1339
1673
|
if (block.sketchIds.has(binding.nodeId)) {
|
|
1340
1674
|
errors.push(
|
|
1341
1675
|
`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.`,
|
|
1342
1676
|
);
|
|
1677
|
+
block.bindings.splice(block.bindings.indexOf(binding), 1);
|
|
1343
1678
|
continue;
|
|
1344
1679
|
}
|
|
1680
|
+
if (binding.label) node.label = binding.label;
|
|
1345
1681
|
if (binding.kind) node.kind = binding.kind;
|
|
1346
1682
|
}
|
|
1347
1683
|
projectRecordedArms(block, errors);
|
|
@@ -1356,7 +1692,7 @@ function attachBindingsToBlocks(
|
|
|
1356
1692
|
continue;
|
|
1357
1693
|
errors.push(
|
|
1358
1694
|
`Docflow box "${node.id}" in \`${blockLabel(block)}\` points at nothing, so the canvas can only draw it and say nothing about it. ` +
|
|
1359
|
-
`
|
|
1695
|
+
`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.`,
|
|
1360
1696
|
);
|
|
1361
1697
|
}
|
|
1362
1698
|
}
|
|
@@ -1370,6 +1706,65 @@ function sourceLineStartsForDocflow(sourceCode: string): number[] {
|
|
|
1370
1706
|
return starts;
|
|
1371
1707
|
}
|
|
1372
1708
|
|
|
1709
|
+
/**
|
|
1710
|
+
* A `@mermaid` the diagram parser did not read as a diagram, and why. Without
|
|
1711
|
+
* this, a play whose diagram was written in the wrong comment form checked as
|
|
1712
|
+
* having "no authored Mermaid visualization", which sends the author to write
|
|
1713
|
+
* one they already wrote.
|
|
1714
|
+
*/
|
|
1715
|
+
export type UnreadDocflowBlock = { line: number; reason: string };
|
|
1716
|
+
|
|
1717
|
+
/**
|
|
1718
|
+
* Every `@mermaid` tag in a comment that `parsePlayDocflowFile` skipped. Only
|
|
1719
|
+
* comments are considered: a `@mermaid` inside a string literal is text.
|
|
1720
|
+
*/
|
|
1721
|
+
export function findUnreadDocflowBlocks(
|
|
1722
|
+
sourceCode: string,
|
|
1723
|
+
): UnreadDocflowBlock[] {
|
|
1724
|
+
const spans = (pattern: RegExp) =>
|
|
1725
|
+
[...sourceCode.matchAll(pattern)].map((match) => ({
|
|
1726
|
+
start: match.index!,
|
|
1727
|
+
end: match.index! + match[0].length,
|
|
1728
|
+
body: match[1] ?? '',
|
|
1729
|
+
}));
|
|
1730
|
+
const jsdocs = spans(/\/\*\*([\s\S]*?)\*\//g);
|
|
1731
|
+
const blockComments = spans(/\/\*(?!\*)([\s\S]*?)\*\//g);
|
|
1732
|
+
const lineOf = (index: number) =>
|
|
1733
|
+
sourceCode.slice(0, index).split(/\r?\n/).length;
|
|
1734
|
+
const unread: UnreadDocflowBlock[] = [];
|
|
1735
|
+
for (const match of sourceCode.matchAll(/@mermaid(?![-\w])/g)) {
|
|
1736
|
+
const at = match.index!;
|
|
1737
|
+
const jsdoc = jsdocs.find((span) => span.start < at && at < span.end);
|
|
1738
|
+
if (jsdoc) {
|
|
1739
|
+
if (/^@mermaid(?:[ \t]+|\r?\n|$)/.test(cleanBlockBody(jsdoc.body)))
|
|
1740
|
+
continue;
|
|
1741
|
+
unread.push({
|
|
1742
|
+
line: lineOf(at),
|
|
1743
|
+
reason:
|
|
1744
|
+
'`@mermaid` must be the first thing in its `/** … */` block; text above it in the same block hides the diagram',
|
|
1745
|
+
});
|
|
1746
|
+
continue;
|
|
1747
|
+
}
|
|
1748
|
+
if (blockComments.some((span) => span.start < at && at < span.end)) {
|
|
1749
|
+
unread.push({
|
|
1750
|
+
line: lineOf(at),
|
|
1751
|
+
reason:
|
|
1752
|
+
'it is in a `/* … */` comment; a diagram is read only from a `/** @mermaid … */` block (two asterisks)',
|
|
1753
|
+
});
|
|
1754
|
+
continue;
|
|
1755
|
+
}
|
|
1756
|
+
const lineStart = sourceCode.lastIndexOf('\n', at - 1) + 1;
|
|
1757
|
+
if (sourceCode.slice(lineStart, at).includes('//')) {
|
|
1758
|
+
unread.push({
|
|
1759
|
+
line: lineOf(at),
|
|
1760
|
+
reason:
|
|
1761
|
+
'it is in a `//` comment; a diagram is read only from a `/** @mermaid … */` block',
|
|
1762
|
+
});
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
return unread;
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1373
1768
|
/**
|
|
1374
1769
|
* Parses the intentionally small authoring surface. Mermaid remains an export
|
|
1375
1770
|
* target; this owns the stable IDs and bindings that make the diagram truthful.
|
|
@@ -1399,9 +1794,19 @@ export function parsePlayDocflow(
|
|
|
1399
1794
|
),
|
|
1400
1795
|
)
|
|
1401
1796
|
: undefined);
|
|
1797
|
+
const unread = selected
|
|
1798
|
+
? undefined
|
|
1799
|
+
: parsed.unreadBlocks.find(
|
|
1800
|
+
(block) =>
|
|
1801
|
+
(block.authoredExportName ?? PLAY_DEFAULT_EXPORT) === requested,
|
|
1802
|
+
) ??
|
|
1803
|
+
(parsed.unreadBlocks.length === 1 && parsed.blocks.length === 0
|
|
1804
|
+
? parsed.unreadBlocks[0]
|
|
1805
|
+
: undefined);
|
|
1402
1806
|
return {
|
|
1403
|
-
docflow:
|
|
1807
|
+
docflow: selected?.docflow ?? null,
|
|
1404
1808
|
errors: parsed.errors,
|
|
1809
|
+
...(unread ? { unreadReason: unread.reason } : {}),
|
|
1405
1810
|
};
|
|
1406
1811
|
}
|
|
1407
1812
|
|
|
@@ -1500,9 +1905,17 @@ function parseDocflowBindingsInSource(
|
|
|
1500
1905
|
index + 1,
|
|
1501
1906
|
errors,
|
|
1502
1907
|
);
|
|
1908
|
+
const show = parseContractPaths(
|
|
1909
|
+
attributes.show,
|
|
1910
|
+
'show',
|
|
1911
|
+
id,
|
|
1912
|
+
index + 1,
|
|
1913
|
+
errors,
|
|
1914
|
+
);
|
|
1503
1915
|
if (
|
|
1504
1916
|
(attributes.in !== undefined && !inputs) ||
|
|
1505
|
-
(attributes.out !== undefined && !outputs)
|
|
1917
|
+
(attributes.out !== undefined && !outputs) ||
|
|
1918
|
+
(attributes.show !== undefined && !show)
|
|
1506
1919
|
) {
|
|
1507
1920
|
continue;
|
|
1508
1921
|
}
|
|
@@ -1525,6 +1938,7 @@ function parseDocflowBindingsInSource(
|
|
|
1525
1938
|
// explicit `undefined` key survives `JSON.stringify` round-trips in some
|
|
1526
1939
|
// callers and would reintroduce the hash drift this omission avoids.
|
|
1527
1940
|
...(arm ? { arm } : {}),
|
|
1941
|
+
...(show?.length ? { show } : {}),
|
|
1528
1942
|
...inferred,
|
|
1529
1943
|
});
|
|
1530
1944
|
}
|
|
@@ -1572,6 +1986,34 @@ export function lintPlayDocflow(
|
|
|
1572
1986
|
indegree.set(edge.to, (indegree.get(edge.to) ?? 0) + 1);
|
|
1573
1987
|
}
|
|
1574
1988
|
|
|
1989
|
+
// Each issue about one box names it, the entry-file line to edit and a fix
|
|
1990
|
+
// to paste. A structural fix edits the diagram; a binding fix edits the
|
|
1991
|
+
// annotation, unless that annotation lives in an imported module.
|
|
1992
|
+
const locate = docflowSourceLocator(sourceCode);
|
|
1993
|
+
const bindingOf = new Map(
|
|
1994
|
+
docflow.bindings.map((binding) => [binding.nodeId, binding]),
|
|
1995
|
+
);
|
|
1996
|
+
const at = (
|
|
1997
|
+
node: string,
|
|
1998
|
+
where: 'diagram' | 'annotation',
|
|
1999
|
+
): { node: string; line?: number } => {
|
|
2000
|
+
const binding = bindingOf.get(node);
|
|
2001
|
+
const annotation =
|
|
2002
|
+
binding && !binding.sourcePath ? locate.annotation(node) : undefined;
|
|
2003
|
+
const line =
|
|
2004
|
+
where === 'annotation'
|
|
2005
|
+
? (annotation ?? locate.diagram(node))
|
|
2006
|
+
: (locate.diagram(node) ?? annotation);
|
|
2007
|
+
return line === undefined ? { node } : { node, line };
|
|
2008
|
+
};
|
|
2009
|
+
const drawn = (id: string) => {
|
|
2010
|
+
const node = byId.get(id);
|
|
2011
|
+
if (!node) return id;
|
|
2012
|
+
const open = node.kind === 'decision' ? '{' : '[';
|
|
2013
|
+
const close = node.kind === 'decision' ? '}' : ']';
|
|
2014
|
+
return `${id}${open}${node.label}${close}`;
|
|
2015
|
+
};
|
|
2016
|
+
|
|
1575
2017
|
if (docflow.direction !== 'TB' && docflow.direction !== 'TD') {
|
|
1576
2018
|
issues.push({
|
|
1577
2019
|
code: 'docflow_direction_not_top_down',
|
|
@@ -1631,6 +2073,8 @@ export function lintPlayDocflow(
|
|
|
1631
2073
|
message: `Docflow node "${node.id}" branches ${branches.length} ways but is not a decision.`,
|
|
1632
2074
|
path: `docflow.nodes.${node.id}`,
|
|
1633
2075
|
hint: 'Insert a decision node for the branch so the split is explicit in the UI.',
|
|
2076
|
+
...at(node.id, 'diagram'),
|
|
2077
|
+
fix: `${node.id}{${node.label}?} -->|<outcome>| ${branches[0]!.to}`,
|
|
1634
2078
|
});
|
|
1635
2079
|
}
|
|
1636
2080
|
if (node.kind === 'decision' && branches.length > 1) {
|
|
@@ -1639,31 +2083,77 @@ export function lintPlayDocflow(
|
|
|
1639
2083
|
labels.some((label) => !label) ||
|
|
1640
2084
|
new Set(labels).size !== labels.length
|
|
1641
2085
|
) {
|
|
2086
|
+
const unlabeled =
|
|
2087
|
+
branches.find((edge) => !edge.label?.trim()) ?? branches[0]!;
|
|
1642
2088
|
issues.push({
|
|
1643
2089
|
code: 'docflow_branch_labels_required',
|
|
1644
2090
|
severity: 'error',
|
|
1645
2091
|
message: `Decision "${node.id}" must give every branch a unique label.`,
|
|
1646
2092
|
path: `docflow.nodes.${node.id}`,
|
|
1647
2093
|
hint: 'Use `decision -->|outcome| next` for every decision edge.',
|
|
2094
|
+
...at(node.id, 'diagram'),
|
|
2095
|
+
fix: `${node.id} -->|<outcome>| ${unlabeled.to}`,
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
// A decision is a state with one transition per outcome. With fewer than
|
|
2100
|
+
// two drawn arms the canvas cannot say which way a run went: a lone arm
|
|
2101
|
+
// reads as a plain step, and its untaken alternative (the else, the
|
|
2102
|
+
// unknown, the review) is missing from the picture. Warning: the run is
|
|
2103
|
+
// right, only the diagram is incomplete.
|
|
2104
|
+
if (node.kind === 'decision' && branches.length < 2) {
|
|
2105
|
+
issues.push({
|
|
2106
|
+
code: 'docflow_decision_arms_incomplete',
|
|
2107
|
+
severity: 'warning',
|
|
2108
|
+
message: `Decision "${node.id}" draws ${branches.length === 0 ? 'no arms' : `one arm (to ${branches[0]!.to})`}, so the canvas cannot show which way a run went. A decision draws one labeled edge per outcome the code can take.`,
|
|
2109
|
+
path: `docflow.nodes.${node.id}`,
|
|
2110
|
+
hint: `Draw every outcome as \`${node.id} -->|<outcome>| <next>\`, including the else, unknown or review path, or make the box a plain action if nothing branches here.`,
|
|
2111
|
+
...at(node.id, 'diagram'),
|
|
2112
|
+
fix: `${node.id} -->|<other outcome>| <next box>`,
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
// A decision outside a frame whose arms land inside it draws as one wire
|
|
2116
|
+
// into the frame, with every arm label piled beside it and exclusive
|
|
2117
|
+
// outcomes stacked as if they ran in sequence. Warning: the run is right,
|
|
2118
|
+
// only the picture misleads.
|
|
2119
|
+
if (node.kind === 'decision' && branches.length > 1) {
|
|
2120
|
+
for (const subgraph of docflow.subgraphs ?? []) {
|
|
2121
|
+
if (subgraph.memberIds.includes(node.id)) continue;
|
|
2122
|
+
const inside = branches.filter((edge) =>
|
|
2123
|
+
subgraph.memberIds.includes(edge.to),
|
|
2124
|
+
);
|
|
2125
|
+
if (inside.length < 2) continue;
|
|
2126
|
+
issues.push({
|
|
2127
|
+
code: 'docflow_decision_outside_region',
|
|
2128
|
+
severity: 'warning',
|
|
2129
|
+
message: `Decision "${node.id}" is outside subgraph "${subgraph.id}", but ${inside.length} of its arms (${inside.map((edge) => edge.to).join(', ')}) are inside it, so the canvas draws them as one wire into the frame.`,
|
|
2130
|
+
path: `docflow.nodes.${node.id}`,
|
|
2131
|
+
hint: 'Draw the decision in the same subgraph as its arms.',
|
|
2132
|
+
...at(node.id, 'diagram'),
|
|
2133
|
+
fix: `Move \`${drawn(node.id)}\` inside \`subgraph ${subgraph.id}\`.`,
|
|
1648
2134
|
});
|
|
1649
2135
|
}
|
|
1650
2136
|
}
|
|
1651
2137
|
if (branches.length > DOCFLOW_MAX_BRANCHES) {
|
|
1652
2138
|
issues.push({
|
|
1653
2139
|
code: 'docflow_layout_complexity',
|
|
1654
|
-
severity: '
|
|
1655
|
-
message: `
|
|
2140
|
+
severity: 'warning',
|
|
2141
|
+
message: `Decision "${node.id}" has ${branches.length} branches; more than ${DOCFLOW_MAX_BRANCHES} arms side by side are hard to read.`,
|
|
1656
2142
|
path: `docflow.nodes.${node.id}`,
|
|
1657
|
-
hint: '
|
|
2143
|
+
hint: 'Group related outcomes into a first decision (for example US vs international) with its own named arms.',
|
|
2144
|
+
...at(node.id, 'diagram'),
|
|
2145
|
+
fix: `${node.id} -->|<group of outcomes>| <nextDecision>{<Which one?>}`,
|
|
1658
2146
|
});
|
|
1659
2147
|
}
|
|
1660
2148
|
if (node.label.length > DOCFLOW_MAX_LABEL_LENGTH) {
|
|
1661
2149
|
issues.push({
|
|
1662
2150
|
code: 'docflow_layout_complexity',
|
|
1663
2151
|
severity: 'warning',
|
|
1664
|
-
message: `
|
|
2152
|
+
message: `Box "${node.id}" has a ${node.label.length}-character title; titles over ${DOCFLOW_MAX_LABEL_LENGTH} characters are cut off on the canvas.`,
|
|
1665
2153
|
path: `docflow.nodes.${node.id}.label`,
|
|
1666
|
-
hint: '
|
|
2154
|
+
hint: 'Keep the card title short and move the detail into code.',
|
|
2155
|
+
...at(node.id, 'diagram'),
|
|
2156
|
+
fix: `${node.id}${node.kind === 'decision' ? '{' : '['}<title of ${DOCFLOW_MAX_LABEL_LENGTH} characters or fewer>${node.kind === 'decision' ? '}' : ']'}`,
|
|
1667
2157
|
});
|
|
1668
2158
|
}
|
|
1669
2159
|
// A label names the thing; the runtime counts it. Warning, not error: this
|
|
@@ -1671,12 +2161,79 @@ export function lintPlayDocflow(
|
|
|
1671
2161
|
// should not be able to hard-fail `plays check`.
|
|
1672
2162
|
const countFragment = docflowLabelCountFragment(node.label);
|
|
1673
2163
|
if (countFragment) {
|
|
2164
|
+
const counted = node.label
|
|
2165
|
+
.replace(countFragment, '')
|
|
2166
|
+
.replace(/\s{2,}/g, ' ')
|
|
2167
|
+
.trim();
|
|
1674
2168
|
issues.push({
|
|
1675
2169
|
code: 'docflow_label_counts_rows',
|
|
1676
2170
|
severity: 'warning',
|
|
1677
|
-
message: `
|
|
2171
|
+
message: `Box "${node.id}" puts a count ("${countFragment}") in its title "${node.label}"; the run shows the live count, so an authored number goes stale as soon as the input changes.`,
|
|
1678
2172
|
path: `docflow.nodes.${node.id}.label`,
|
|
1679
2173
|
hint: 'Name what the node IS ("Seed rows"), not how many it holds — the canvas already shows the live count beside the node.',
|
|
2174
|
+
...at(node.id, 'diagram'),
|
|
2175
|
+
fix: `${node.id}${node.kind === 'decision' ? '{' : '['}${counted || '<what it is>'}${node.kind === 'decision' ? '}' : ']'}`,
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
// A sketch is a box no statement runs, so a run can never light it up. An
|
|
2179
|
+
// external trigger at the top of the flow, or a legend beside it, is
|
|
2180
|
+
// honestly a sketch; a box the flow passes INTO is a step the Play takes,
|
|
2181
|
+
// so its sketch hides real work from every run.
|
|
2182
|
+
if (node.sketch && node.kind !== 'conceptual' && (indegree.get(node.id) ?? 0) > 0) {
|
|
2183
|
+
issues.push({
|
|
2184
|
+
code: 'docflow_box_is_sketch',
|
|
2185
|
+
severity: 'warning',
|
|
2186
|
+
message: `Box "${node.id}" is a step in the flow but is drawn as a sketch, so no run can show it was reached or what it produced.`,
|
|
2187
|
+
path: `docflow.nodes.${node.id}`,
|
|
2188
|
+
hint: `Bind it: put this annotation above the statement that does the work (in this file or a module it imports), and drop ${node.id} from the \`class … sketch\` line.`,
|
|
2189
|
+
...at(node.id, 'diagram'),
|
|
2190
|
+
fix: `${node.kind === 'decision' ? `// @mermaid-node ${node.id} type:"decision"` : `// @mermaid-node ${node.id}`} in:"<what it reads>" out:"<what it produces>"`,
|
|
2191
|
+
});
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
// A region drawn as one folded card hides which outcome leaves by which
|
|
2196
|
+
// wire. When it exits to more than one place, every exit must say which
|
|
2197
|
+
// outcome takes it; otherwise the folded card shows bare wires. Warning: the
|
|
2198
|
+
// run is right, only the picture is ambiguous.
|
|
2199
|
+
{
|
|
2200
|
+
const subgraphs = docflow.subgraphs ?? [];
|
|
2201
|
+
const membersOf = new Map<string, Set<string>>();
|
|
2202
|
+
const collect = (id: string): Set<string> => {
|
|
2203
|
+
const cached = membersOf.get(id);
|
|
2204
|
+
if (cached) return cached;
|
|
2205
|
+
const subgraph = subgraphs.find((candidate) => candidate.id === id);
|
|
2206
|
+
const members = new Set<string>(subgraph?.memberIds ?? []);
|
|
2207
|
+
for (const child of subgraphs) {
|
|
2208
|
+
if (child.parentId === id) {
|
|
2209
|
+
for (const member of collect(child.id)) members.add(member);
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
membersOf.set(id, members);
|
|
2213
|
+
return members;
|
|
2214
|
+
};
|
|
2215
|
+
for (const subgraph of subgraphs) {
|
|
2216
|
+
const members = collect(subgraph.id);
|
|
2217
|
+
const exits = docflow.edges.filter(
|
|
2218
|
+
(edge) => members.has(edge.from) && !members.has(edge.to),
|
|
2219
|
+
);
|
|
2220
|
+
if (new Set(exits.map((edge) => edge.to)).size < 2) continue;
|
|
2221
|
+
const unlabeled = exits.filter((edge) => !edge.label?.trim());
|
|
2222
|
+
if (unlabeled.length === 0) continue;
|
|
2223
|
+
issues.push({
|
|
2224
|
+
code: 'docflow_region_exits_unlabeled',
|
|
2225
|
+
severity: 'warning',
|
|
2226
|
+
message: `Subgraph "${subgraph.id}" leaves to ${new Set(exits.map((edge) => edge.to)).size} places, but ${unlabeled.map((edge) => `${edge.from} --> ${edge.to}`).join(', ')} ${unlabeled.length === 1 ? 'has' : 'have'} no label, so its folded card shows a bare wire.`,
|
|
2227
|
+
path: `docflow.subgraphs.${subgraph.id}`,
|
|
2228
|
+
hint: 'Label every exit with the outcome that takes it.',
|
|
2229
|
+
node: subgraph.id,
|
|
2230
|
+
...(() => {
|
|
2231
|
+
const line = locate.diagram(subgraph.id);
|
|
2232
|
+
return line === undefined ? {} : { line };
|
|
2233
|
+
})(),
|
|
2234
|
+
fix: unlabeled
|
|
2235
|
+
.map((edge) => `${edge.from} -->|<outcome>| ${edge.to}`)
|
|
2236
|
+
.join('; '),
|
|
1680
2237
|
});
|
|
1681
2238
|
}
|
|
1682
2239
|
}
|
|
@@ -1692,20 +2249,50 @@ export function lintPlayDocflow(
|
|
|
1692
2249
|
for (const binding of docflow.bindings) {
|
|
1693
2250
|
const node = byId.get(binding.nodeId);
|
|
1694
2251
|
if (!node) continue;
|
|
1695
|
-
if (binding.ioConfidence === 'ambiguous' && node.kind === 'action') {
|
|
1696
|
-
issues.push({
|
|
1697
|
-
code: 'docflow_io_ambiguous',
|
|
1698
|
-
severity: 'warning',
|
|
1699
|
-
message: `Could not determine what "${binding.nodeId}" reads or changes.`,
|
|
1700
|
-
path: `docflow.nodes.${binding.nodeId}`,
|
|
1701
|
-
hint: 'Add in:"…" and out:"…", or annotate a clearer assignment.',
|
|
1702
|
-
});
|
|
1703
|
-
}
|
|
1704
2252
|
// Imported annotations retain their own file and line. Names and assigned
|
|
1705
2253
|
// variables must be checked in that file, not in the entry's namespace.
|
|
1706
2254
|
const bindingSource = binding.sourcePath
|
|
1707
2255
|
? (moduleSources?.get(binding.sourcePath) ?? sourceCode)
|
|
1708
2256
|
: sourceCode;
|
|
2257
|
+
const boundLine =
|
|
2258
|
+
bindingSource?.split(/\r?\n/)[binding.line - 1]?.trim() ?? '';
|
|
2259
|
+
const assignedName = /^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=/.exec(
|
|
2260
|
+
boundLine,
|
|
2261
|
+
)?.[1];
|
|
2262
|
+
// A bound box names what it reads and what it produces, so a run can show
|
|
2263
|
+
// both on the canvas. Inference covers a plain assignment; anything else
|
|
2264
|
+
// (an await, a call with effects) needs the author to say.
|
|
2265
|
+
if (node.kind !== 'conceptual') {
|
|
2266
|
+
// A chained per-row column (`.withColumn(…)`) reads its row; only what
|
|
2267
|
+
// it adds needs naming.
|
|
2268
|
+
const readsItsRow = boundLine.startsWith('.');
|
|
2269
|
+
const missing = [
|
|
2270
|
+
...(binding.inputs?.length || readsItsRow ? [] : ['in']),
|
|
2271
|
+
...(binding.outputs?.length ? [] : ['out']),
|
|
2272
|
+
];
|
|
2273
|
+
if (missing.length > 0) {
|
|
2274
|
+
const produced = /^return\b/.test(boundLine)
|
|
2275
|
+
? '$output'
|
|
2276
|
+
: (assignedName ?? '<what it produces>');
|
|
2277
|
+
issues.push({
|
|
2278
|
+
code: 'docflow_io_missing',
|
|
2279
|
+
severity: 'warning',
|
|
2280
|
+
message:
|
|
2281
|
+
missing.length === 2
|
|
2282
|
+
? `Box "${binding.nodeId}" does not say what it reads or produces, so a run cannot show its input or its result.`
|
|
2283
|
+
: missing[0] === 'in'
|
|
2284
|
+
? `Box "${binding.nodeId}" does not say what it reads, so a run cannot show its input.`
|
|
2285
|
+
: `Box "${binding.nodeId}" does not say what it produces, so a run cannot show its result.`,
|
|
2286
|
+
path: `docflow.nodes.${binding.nodeId}`,
|
|
2287
|
+
hint: `Add ${missing.map((name) => `${name}:"…"`).join(' and ')} to its annotation.`,
|
|
2288
|
+
...at(binding.nodeId, 'annotation'),
|
|
2289
|
+
fix: docflowAnnotationFix(binding, {
|
|
2290
|
+
...(missing.includes('in') ? { in: '<what it reads>' } : {}),
|
|
2291
|
+
...(missing.includes('out') ? { out: produced } : {}),
|
|
2292
|
+
}),
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
1709
2296
|
if (!bindingSource) continue;
|
|
1710
2297
|
const sourceIdentifiers = identifiersForSource(bindingSource);
|
|
1711
2298
|
// What a module's box reads may be the play's own input, which the entry
|
|
@@ -1715,11 +2302,35 @@ export function lintPlayDocflow(
|
|
|
1715
2302
|
sourceCode && bindingSource !== sourceCode
|
|
1716
2303
|
? new Set([...sourceIdentifiers, ...identifiersForSource(sourceCode)])
|
|
1717
2304
|
: sourceIdentifiers;
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
2305
|
+
// A box bound to a statement that builds an object: which of its fields a
|
|
2306
|
+
// reader should see is the author's call. Without `show:` every display
|
|
2307
|
+
// falls back to the neutral peek (first field · N fields). An object of one
|
|
2308
|
+
// field shows that field whole, so there is nothing to choose. The hint
|
|
2309
|
+
// names the object's own fields, so the fix can be pasted.
|
|
2310
|
+
const builtObject =
|
|
2311
|
+
!binding.show?.length &&
|
|
2312
|
+
/^(?:(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=|return)\s*\{/.test(
|
|
2313
|
+
boundLine,
|
|
2314
|
+
)
|
|
2315
|
+
? objectLiteralFields(bindingSource.split(/\r?\n/), binding.line - 1)
|
|
2316
|
+
: null;
|
|
2317
|
+
if (
|
|
2318
|
+
builtObject &&
|
|
2319
|
+
(builtObject.spread || builtObject.fields.length > 1)
|
|
2320
|
+
) {
|
|
2321
|
+
const example = builtObject.fields.slice(0, 2).join(',');
|
|
2322
|
+
issues.push({
|
|
2323
|
+
code: 'docflow_show_undeclared',
|
|
2324
|
+
severity: 'warning',
|
|
2325
|
+
message: `Box "${binding.nodeId}" produces an object${builtObject.fields.length > 1 ? ` (${builtObject.fields.join(', ')})` : ''} but names no fields to show, so the canvas shows only its first field and a field count.`,
|
|
2326
|
+
path: `docflow.nodes.${binding.nodeId}.show`,
|
|
2327
|
+
hint: `Name the fields a reader should see first: show:"${example || 'field,nested.field'}".`,
|
|
2328
|
+
...at(binding.nodeId, 'annotation'),
|
|
2329
|
+
fix: docflowAnnotationFix(binding, {
|
|
2330
|
+
show: example || 'field,nested.field',
|
|
2331
|
+
}),
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
1723
2334
|
for (const path of binding.inputs ?? []) {
|
|
1724
2335
|
const root = rootPath(path);
|
|
1725
2336
|
if (inputIdentifiers.has(root)) continue;
|
|
@@ -1728,16 +2339,29 @@ export function lintPlayDocflow(
|
|
|
1728
2339
|
.sort(
|
|
1729
2340
|
(left, right) => levenshtein(root, left) - levenshtein(root, right),
|
|
1730
2341
|
)[0];
|
|
2342
|
+
const close = suggestion && levenshtein(root, suggestion) <= 3;
|
|
1731
2343
|
issues.push({
|
|
1732
2344
|
code: 'docflow_input_not_found',
|
|
1733
2345
|
severity: 'error',
|
|
1734
2346
|
message: `Input "${path}" is not in scope for docflow node "${binding.nodeId}".`,
|
|
1735
2347
|
path: `docflow.nodes.${binding.nodeId}.in`,
|
|
1736
|
-
...(
|
|
2348
|
+
...(close
|
|
1737
2349
|
? { hint: `Did you mean "${suggestion}"?` }
|
|
1738
2350
|
: {
|
|
1739
2351
|
hint: 'Use an identifier or property path that exists in this play.',
|
|
1740
2352
|
}),
|
|
2353
|
+
...at(binding.nodeId, 'annotation'),
|
|
2354
|
+
fix: docflowAnnotationFix(binding, {
|
|
2355
|
+
in: (binding.inputs ?? [])
|
|
2356
|
+
.map((candidate) =>
|
|
2357
|
+
candidate === path
|
|
2358
|
+
? close
|
|
2359
|
+
? `${suggestion}${path.slice(root.length)}`
|
|
2360
|
+
: '<a name in scope>'
|
|
2361
|
+
: candidate,
|
|
2362
|
+
)
|
|
2363
|
+
.join(','),
|
|
2364
|
+
}),
|
|
1741
2365
|
});
|
|
1742
2366
|
}
|
|
1743
2367
|
for (const path of binding.outputs ?? []) {
|
|
@@ -1754,6 +2378,8 @@ export function lintPlayDocflow(
|
|
|
1754
2378
|
message: `Output "${path}" does not match the assigned variable "${assignedName}" for docflow node "${binding.nodeId}" — out: names bind to the variable the annotated statement assigns, so write out:"${assignedName}" (the node id can stay "${binding.nodeId}").`,
|
|
1755
2379
|
path: `docflow.nodes.${binding.nodeId}.out`,
|
|
1756
2380
|
hint: `The node id and the out: name are independent: the id labels the diagram box, out: must be the assigned variable/column name.`,
|
|
2381
|
+
...at(binding.nodeId, 'annotation'),
|
|
2382
|
+
fix: docflowAnnotationFix(binding, { out: assignedName }),
|
|
1757
2383
|
});
|
|
1758
2384
|
continue;
|
|
1759
2385
|
}
|
|
@@ -1764,17 +2390,36 @@ export function lintPlayDocflow(
|
|
|
1764
2390
|
message: `Output "${path}" is not declared by docflow node "${binding.nodeId}".`,
|
|
1765
2391
|
path: `docflow.nodes.${binding.nodeId}.out`,
|
|
1766
2392
|
hint: 'Use an identifier or property path that exists in this play.',
|
|
2393
|
+
...at(binding.nodeId, 'annotation'),
|
|
2394
|
+
fix: docflowAnnotationFix(binding, {
|
|
2395
|
+
out: assignedName ?? '<a name this statement assigns>',
|
|
2396
|
+
}),
|
|
1767
2397
|
});
|
|
1768
2398
|
}
|
|
1769
2399
|
}
|
|
1770
2400
|
|
|
1771
|
-
|
|
2401
|
+
// Regions fold by default, so count what each view of the canvas shows.
|
|
2402
|
+
for (const view of docflowCanvasViews(docflow)) {
|
|
2403
|
+
if (view.boxes <= DOCFLOW_MAX_NODES) continue;
|
|
1772
2404
|
issues.push({
|
|
1773
2405
|
code: 'docflow_layout_complexity',
|
|
1774
2406
|
severity: 'warning',
|
|
1775
|
-
message:
|
|
1776
|
-
|
|
1777
|
-
|
|
2407
|
+
message: view.regionId
|
|
2408
|
+
? `Subgraph "${view.regionId}" shows ${view.boxes} boxes when opened; more than ${DOCFLOW_MAX_NODES} makes it hard to scan.`
|
|
2409
|
+
: `The diagram shows ${view.boxes} top-level boxes with every subgraph folded; more than ${DOCFLOW_MAX_NODES} makes the default view hard to scan.`,
|
|
2410
|
+
path: view.regionId ? `docflow.subgraphs.${view.regionId}` : 'docflow.nodes',
|
|
2411
|
+
hint: view.regionId
|
|
2412
|
+
? 'Split the subgraph into nested phases, or move supporting detail into code.'
|
|
2413
|
+
: 'Group related steps into named `subgraph` phases; each folds to one box.',
|
|
2414
|
+
...(view.regionId
|
|
2415
|
+
? (() => {
|
|
2416
|
+
const line = locate.diagram(view.regionId);
|
|
2417
|
+
return { node: view.regionId, ...(line === undefined ? {} : { line }) };
|
|
2418
|
+
})()
|
|
2419
|
+
: {}),
|
|
2420
|
+
fix: view.regionId
|
|
2421
|
+
? `subgraph <phase>["<Phase title>"] … end, inside \`subgraph ${view.regionId}\``
|
|
2422
|
+
: 'subgraph <phase>["<Phase title>"] … end, around related steps',
|
|
1778
2423
|
});
|
|
1779
2424
|
}
|
|
1780
2425
|
|
|
@@ -1797,7 +2442,7 @@ export function lintPlayDocflow(
|
|
|
1797
2442
|
code: 'docflow_layout_complexity',
|
|
1798
2443
|
severity: 'warning',
|
|
1799
2444
|
message:
|
|
1800
|
-
'
|
|
2445
|
+
'The diagram contains a feedback loop, which renders as a secondary dashed path.',
|
|
1801
2446
|
path: 'docflow.edges',
|
|
1802
2447
|
hint: 'Label feedback edges clearly and keep the main forward path acyclic.',
|
|
1803
2448
|
});
|
|
@@ -1805,3 +2450,28 @@ export function lintPlayDocflow(
|
|
|
1805
2450
|
|
|
1806
2451
|
return issues;
|
|
1807
2452
|
}
|
|
2453
|
+
|
|
2454
|
+
/**
|
|
2455
|
+
* The boxes each view of the canvas draws: the top level with every region
|
|
2456
|
+
* folded to one card, and each region opened alone (its direct nodes plus one
|
|
2457
|
+
* card per child region).
|
|
2458
|
+
*/
|
|
2459
|
+
function docflowCanvasViews(
|
|
2460
|
+
docflow: PlayDocflow,
|
|
2461
|
+
): { regionId: string | null; boxes: number }[] {
|
|
2462
|
+
const subgraphs = docflow.subgraphs ?? [];
|
|
2463
|
+
const regionIds = new Set(subgraphs.map((subgraph) => subgraph.id));
|
|
2464
|
+
const parentOf = new Map<string, string>();
|
|
2465
|
+
for (const subgraph of subgraphs) {
|
|
2466
|
+
if (subgraph.parentId) parentOf.set(subgraph.id, subgraph.parentId);
|
|
2467
|
+
for (const member of subgraph.memberIds) {
|
|
2468
|
+
if (!regionIds.has(member)) parentOf.set(member, subgraph.id);
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
const boxes = new Map<string | null, number>();
|
|
2472
|
+
const count = (parent: string | null) =>
|
|
2473
|
+
boxes.set(parent, (boxes.get(parent) ?? 0) + 1);
|
|
2474
|
+
for (const node of docflow.nodes) count(parentOf.get(node.id) ?? null);
|
|
2475
|
+
for (const subgraph of subgraphs) count(parentOf.get(subgraph.id) ?? null);
|
|
2476
|
+
return [...boxes].map(([regionId, total]) => ({ regionId, boxes: total }));
|
|
2477
|
+
}
|