permdock 0.25.1 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/2020-bJfT8aIA.js +6760 -0
- package/dist/a2a/index.d.ts +5 -9
- package/dist/a2a/index.js +13 -15
- package/dist/adapter-context-lHq_i_77.js +28 -0
- package/dist/adoption-scan-CMghLDUG.js +106 -0
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/ai-sdk/index.d.ts +4 -6
- package/dist/ai-sdk/index.js +6 -7
- package/dist/annotate-doc-BCOCOrq_.js +214 -0
- package/dist/annotate-routes-BvSuEht3.js +75 -0
- package/dist/annotate-uZVGIRym.js +25 -0
- package/dist/app/index.d.ts +2 -103
- package/dist/app/index.js +1 -114
- package/dist/app-data-DbSPSPIl.js +62 -0
- package/dist/approval-header-BvszJE3l.js +25 -0
- package/dist/approval-normalize-Cpp8R0rY.js +190 -0
- package/dist/approval-prompt-C-vjNZyd.d.ts +57 -0
- package/dist/approval-prompt-Covyx_DB.js +60 -0
- package/dist/approval-required-B-R4Yw3J.js +5 -0
- package/dist/approvals/index.d.ts +5 -5
- package/dist/approvals/index.js +8 -8
- package/dist/approvals-7jHYXocE.js +1039 -0
- package/dist/approvers-BkY_ZfWl.js +76 -0
- package/dist/arazzo-B8heXoYy.js +76 -0
- package/dist/arazzo-DdJBVrsy.js +35 -0
- package/dist/args-0EWFk-4S.js +311 -0
- package/dist/astro/index.d.ts +6 -8
- package/dist/astro/index.js +3 -4
- package/dist/audience-DauhRBNg.js +54 -0
- package/dist/auth-WHKYWtnS.js +187 -0
- package/dist/authz-topic-D8x24Jv-.js +14 -0
- package/dist/authzen/index.d.ts +37 -22
- package/dist/authzen/index.js +69 -27
- package/dist/automation-CUcWz8uu.d.ts +122 -0
- package/dist/automation-CpPdFX91.js +157 -0
- package/dist/base-url--yJPQlIK.js +8 -0
- package/dist/better-auth/index.d.ts +2 -8
- package/dist/better-auth/index.js +10 -13
- package/dist/better-supabase/index.d.ts +141 -95
- package/dist/better-supabase/index.js +239 -794
- package/dist/better-supabase-DSbs4MtQ.js +201 -0
- package/dist/bind-B3MHrzw4.d.ts +56 -0
- package/dist/bind-up3QptTt.js +124 -0
- package/dist/body-W1_8r6Tw.js +9 -0
- package/dist/body-text-B-m3p-qY.js +55 -0
- package/dist/boundary--5Swp7sN.js +18 -0
- package/dist/boundary-DJqHADKu.d.ts +22 -0
- package/dist/budget-5LJ8kfZk.d.ts +12 -0
- package/dist/budget-BH81q2cj.js +19 -0
- package/dist/build-instance-hLKYe3-E.js +30 -0
- package/dist/canonical-json-BibZkXtE.js +28 -0
- package/dist/capability-CVt3lpVK.d.ts +128 -0
- package/dist/capability-_ZsyfYxU.js +204 -0
- package/dist/casbin-BHYVxJDD.js +29 -0
- package/dist/casbin-D33ZeUf5.js +241 -0
- package/dist/casl-CrltbDPa.js +23 -0
- package/dist/casl-D7n7yE-h.js +307 -0
- package/dist/catalog/index.d.ts +6 -20
- package/dist/catalog/index.js +13 -15
- package/dist/catalog-B3MJShnZ.js +51 -0
- package/dist/catalog-CgK_L4Qf.js +1 -0
- package/dist/catalog-DyC3LKc7.js +130 -0
- package/dist/catalog-doc-Bp5khmCG.js +352 -0
- package/dist/catalog-fingerprint-DAWZARy6.js +31 -0
- package/dist/catalog-operations-dxuOZr4J.js +59 -0
- package/dist/catalog-path-bG0XxHMu.js +11 -0
- package/dist/challenge-CjwmjcuX.js +518 -0
- package/dist/chat/index.d.ts +1 -1
- package/dist/chat/index.js +10 -13
- package/dist/chat-sdk/index.d.ts +3 -11
- package/dist/chat-sdk/index.js +7 -11
- package/dist/checks-DSm45qH7.js +71 -0
- package/dist/claims-map-BGbpbvGD.js +15 -0
- package/dist/claims-map-CLKQWxJG.d.ts +33 -0
- package/dist/claims-size-DcjhvUv5.js +58 -0
- package/dist/claude-agent/index.d.ts +3 -5
- package/dist/claude-agent/index.js +4 -5
- package/dist/clerk/index.d.ts +4 -8
- package/dist/clerk/index.js +7 -8
- package/dist/cli/bin.js +6 -7
- package/dist/cli/generate/watch-worker.d.ts +20 -0
- package/dist/cli/generate/watch-worker.js +69 -0
- package/dist/cli/index.d.ts +11 -20
- package/dist/cli/index.js +8 -8
- package/dist/cli/plugins/app.d.ts +24 -0
- package/dist/cli/plugins/app.js +36 -0
- package/dist/cli/plugins/better-supabase.d.ts +10 -0
- package/dist/cli/plugins/better-supabase.js +18 -0
- package/dist/cli/plugins/openapi.d.ts +19 -0
- package/dist/cli/plugins/openapi.js +40 -0
- package/dist/cli/plugins/powersync.d.ts +7 -0
- package/dist/cli/plugins/powersync.js +29 -0
- package/dist/cli/plugins/rls.d.ts +8 -0
- package/dist/cli/plugins/rls.js +27 -0
- package/dist/cli/plugins/schemas.d.ts +13 -0
- package/dist/cli/plugins/schemas.js +23 -0
- package/dist/cli/plugins/scim.d.ts +10 -0
- package/dist/cli/plugins/scim.js +32 -0
- package/dist/cli/plugins/supabase-hook.d.ts +13 -0
- package/dist/cli/plugins/supabase-hook.js +40 -0
- package/dist/cli/plugins/supabase.d.ts +27 -0
- package/dist/cli/plugins/supabase.js +69 -0
- package/dist/cli/plugins/ui.d.ts +11 -0
- package/dist/cli/plugins/ui.js +19 -0
- package/dist/client-V95IvZsF.d.ts +43 -0
- package/dist/client-subject-v89t811z.d.ts +25 -0
- package/dist/clients-Bb_33pRE.js +22 -0
- package/dist/clients-DGcyFDCc.d.ts +10 -0
- package/dist/cloud/index.d.ts +8 -26
- package/dist/cloud/index.js +22 -28
- package/dist/cloud-BmQrcTvx.js +85 -0
- package/dist/codemod-BpjMjxly.js +2159 -0
- package/dist/codemod-C_NKj01W.js +35 -0
- package/dist/collect-BJZsuBW4.js +535 -0
- package/dist/collect-CPvCXMQ-.js +1 -0
- package/dist/collect-CpGnmGpL.js +54 -0
- package/dist/command-9GAzSI7E.js +5 -0
- package/dist/compact-C4LFuqbW.js +28 -0
- package/dist/compare-dfHDj8kT.js +11 -0
- package/dist/compile/index.d.ts +2 -2
- package/dist/compile/index.js +1 -1
- package/dist/compile-BUKXrueE.js +685 -0
- package/dist/compile-D8c1nFGy.d.ts +118 -0
- package/dist/compile-Dy3zMRxo.js +724 -0
- package/dist/completion-CSncf6cX.js +150 -0
- package/dist/conditions-CkHgXoZB.js +385 -0
- package/dist/config-iyy90IOU.js +143 -0
- package/dist/config-report-D607UDnv.js +55 -0
- package/dist/config-shape-B6tdyBju.js +149 -0
- package/dist/config-xiX3R65I.js +25 -0
- package/dist/connection-BnoSqYU1.js +196 -0
- package/dist/connector-schema-BSRMyq4M.js +433 -0
- package/dist/constants-PCJiir_3.js +19 -0
- package/dist/context-DmH-Eyvx.js +95 -0
- package/dist/convex/index.d.ts +5 -9
- package/dist/convex/index.js +7 -8
- package/dist/core-CnC47rSf.d.ts +200 -0
- package/dist/core-DKqrD_xW.js +338 -0
- package/dist/coverage-DL7JCZmb.d.ts +133 -0
- package/dist/coverage-nFSMjFxH.js +42 -0
- package/dist/create-BAMPoEga.js +133 -0
- package/dist/create-BsRcXm_m.d.ts +125 -0
- package/dist/create-D3oXoXxM.js +373 -0
- package/dist/create-DeQ5t8mZ.d.ts +124 -0
- package/dist/create-sGl1ccTp.d.ts +185 -0
- package/dist/credential-ke0KMQeB.js +430 -0
- package/dist/credentials-6ZWbJ-Re.js +72 -0
- package/dist/credentials-BfzdL5kv.d.ts +123 -0
- package/dist/credentials-DOeqknte.js +309 -0
- package/dist/decide-set-CgNcE6pP.js +99 -0
- package/dist/deciding-columns-BnglEKqU.js +143 -0
- package/dist/decision-hHv4UZgy.js +20 -0
- package/dist/define-permdock-BLpQ0m95.d.ts +99 -0
- package/dist/define-permdock-CIxHBykk.js +148 -0
- package/dist/definition-options-9o8Hdww3.js +370 -0
- package/dist/delegation-BaUNCrE_.js +263 -0
- package/dist/delegation-input-7Y5Rlja7.js +18 -0
- package/dist/delivery/index.d.ts +4 -4
- package/dist/delivery/index.js +5 -5
- package/dist/delivery-Cb3VCij5.js +555 -0
- package/dist/delivery-event-D5b9yhaJ.js +39 -0
- package/dist/denied-text-D6JJTDr3.d.ts +20 -0
- package/dist/describe-B7EosIKA.js +100 -0
- package/dist/describe-lAafaRQQ.d.ts +43 -0
- package/dist/device-f3JEnqa0.js +195 -0
- package/dist/diff-BIqibFnm.js +464 -0
- package/dist/diff-n6LONVwL.js +36 -0
- package/dist/digest-BaP8bQzX.js +26 -0
- package/dist/digest-BcIZRYvp.d.ts +17 -0
- package/dist/doctor-BhoJiHi0.js +4847 -0
- package/dist/doctor-CoKSRLhf.js +53 -0
- package/dist/drizzle/index.d.ts +5 -9
- package/dist/drizzle/index.js +5 -6
- package/dist/elysia/index.d.ts +6 -8
- package/dist/elysia/index.js +6 -7
- package/dist/env-hbYumkRp.js +7 -0
- package/dist/errors-DOSkVeTC.js +127 -0
- package/dist/errors-DUJ7wLlE.d.ts +137 -0
- package/dist/errors-Da88YLm5.js +26 -0
- package/dist/errors-DgLOqc6j.js +148 -0
- package/dist/errors-KngVdJT9.d.ts +12 -0
- package/dist/evaluate-D8SdfP3h.js +1948 -0
- package/dist/evaluations-BQkpE7hC.js +609 -0
- package/dist/evaluations-K9qglDP7.d.ts +36 -0
- package/dist/evaluator-Dlhn2d7D.js +2 -0
- package/dist/evaluator-eager-UuJK6NX_.js +8 -0
- package/dist/eve/index.d.ts +11 -10
- package/dist/eve/index.js +7 -8
- package/dist/event-time-ChIrhzy5.js +26 -0
- package/dist/execute-CyQLisIB.js +166 -0
- package/dist/express/index.d.ts +6 -8
- package/dist/express/index.js +6 -7
- package/dist/fastify/index.d.ts +5 -11
- package/dist/fastify/index.js +6 -8
- package/dist/fetch-adapter-gmTCu4FR.d.ts +32 -0
- package/dist/fetch-adapter-ovZdSvlT.js +124 -0
- package/dist/fields-6d1j-q3c.js +502 -0
- package/dist/fields-C0L2FoZk.js +25 -0
- package/dist/files-DAR51W3J.js +157 -0
- package/dist/files-DuV7wRim.js +139 -0
- package/dist/fixtures-Bm0G0A7H.js +79 -0
- package/dist/flags-C0e-BzGW.js +112 -0
- package/dist/freeze-DGfJq_j2.js +86 -0
- package/dist/from-snapshot-CCDF_ihX.js +173 -0
- package/dist/gen-CJE3Xud5.js +1168 -0
- package/dist/gen-WzJbAcMJ.js +1 -0
- package/dist/gen-kind-DFQnQwFN.d.ts +13 -0
- package/dist/gen-kind-DGQxmID0.js +69 -0
- package/dist/generate-5_kz2309.js +305 -0
- package/dist/generate-DF6Y8ncI.js +67 -0
- package/dist/generate-DIZNzMuk.js +2339 -0
- package/dist/generate-DhP0jQDR.js +97 -0
- package/dist/generate-options-CLPUvgVW.js +1185 -0
- package/dist/grantee-BPUG6f0r.js +109 -0
- package/dist/grantee-conditions-Dob6QQAc.js +270 -0
- package/dist/grantee-match-CFQ-LRcL.js +147 -0
- package/dist/grants-BzjbUCdR.js +139 -0
- package/dist/graph-sql-Ds3nbevr.d.ts +27 -0
- package/dist/h3/index.d.ts +4 -6
- package/dist/h3/index.js +4 -5
- package/dist/headers-D1oRr-js.d.ts +8 -0
- package/dist/helpers-DSmj6SHi.js +533 -0
- package/dist/hono/index.d.ts +6 -8
- package/dist/hono/index.js +7 -8
- package/dist/hook-sql-FSets5NB.js +3412 -0
- package/dist/hosted-DMJKJPoc.js +361 -0
- package/dist/hosted-DUbuh0Td.d.ts +100 -0
- package/dist/http-BUIYu1Kc.d.ts +10 -0
- package/dist/http-BbX_Ou3_.js +48 -0
- package/dist/http-C9jDw_bZ.js +82 -0
- package/dist/http-dNltTpC8.js +71 -0
- package/dist/ids-0QDIxtxL.js +53 -0
- package/dist/import-BqoDHpFt.js +1158 -0
- package/dist/import-DemSCI1R.js +318 -0
- package/dist/index-BXz-XXC3.d.ts +1108 -0
- package/dist/index-CVuc3E1O.d.ts +196 -0
- package/dist/index-Cq9N5B92.d.ts +506 -0
- package/dist/index-D8A1d_Tt.d.ts +214 -0
- package/dist/index-DegTwZxD.d.ts +93 -0
- package/dist/index-O0qbI8Ha.d.ts +221 -0
- package/dist/index.d.ts +24 -25
- package/dist/index.js +47 -46
- package/dist/init-BlYRZRnQ.js +94 -0
- package/dist/init-CgoOwXtk.js +95 -0
- package/dist/instance-options-B4MD2wgl.d.ts +9 -0
- package/dist/instance-options-CLErhA76.js +23 -0
- package/dist/instance-snapshot-DdGOpSfN.js +716 -0
- package/dist/instant-Ih5riY_A.js +18 -0
- package/dist/interactive-only-BZu9rLpa.js +1567 -0
- package/dist/internals-D58TnmDB.js +19 -0
- package/dist/json-schema-SDkWXxhu.d.ts +38 -0
- package/dist/json-schema-jtX26ydD.js +148 -0
- package/dist/jwt/index.d.ts +6 -24
- package/dist/jwt/index.js +18 -26
- package/dist/kernel-Dn6pKMAF.js +423 -0
- package/dist/kysely/index.d.ts +5 -9
- package/dist/kysely/index.js +5 -6
- package/dist/lazy-provider-CydlnKkS.d.ts +4 -0
- package/dist/lazy-provider-DG5rMeqL.js +28 -0
- package/dist/limits-DpTxX6N4.js +166 -0
- package/dist/live-options-CIUmc-YQ.js +70 -0
- package/dist/load-BPzIqlGB.js +1 -0
- package/dist/load-CZnlAyZ8.js +98 -0
- package/dist/load-jose-CjzIBSKI.js +7 -0
- package/dist/login-CNQJN8Fy.js +67 -0
- package/dist/login-TwrSjf6k.js +255 -0
- package/dist/lru-Cp-AEvpR.js +27 -0
- package/dist/manifest-B-8d2lhG.js +45 -0
- package/dist/manifest-CRHphHxo.d.ts +362 -0
- package/dist/manifest-XIXxXYty.js +399 -0
- package/dist/manifest-json-DMaBWmcG.js +8 -0
- package/dist/manifest-schema-DJY5Q_pR.js +507 -0
- package/dist/map-claims-BKdnPwep.js +386 -0
- package/dist/map-error-DTi_JZT8.js +22 -0
- package/dist/markers-C-kThnKN.js +79 -0
- package/dist/may-use-Died1tNU.js +233 -0
- package/dist/mcp/index.d.ts +11 -21
- package/dist/mcp/index.js +56 -43
- package/dist/membership-filter-CSKH48eD.js +66 -0
- package/dist/migrate-CmTMk7rd.js +536 -0
- package/dist/model-B4EKVHMK.js +188 -0
- package/dist/module-values-Ddx0GLaJ.js +106 -0
- package/dist/nest/index.d.ts +7 -13
- package/dist/nest/index.js +12 -15
- package/dist/next/client.d.ts +1 -3
- package/dist/next/client.js +2 -3
- package/dist/next/index.d.ts +36 -16
- package/dist/next/index.js +161 -31
- package/dist/next/plugin.d.ts +1 -3
- package/dist/next/plugin.js +3 -4
- package/dist/node/index.d.ts +6 -8
- package/dist/node/index.js +4 -5
- package/dist/oauth-security-C8fjzFRF.js +25 -0
- package/dist/ocsf-DKRQc6uv.js +135 -0
- package/dist/openai/index.d.ts +5 -7
- package/dist/openai/index.js +5 -6
- package/dist/openapi/index.d.ts +4 -16
- package/dist/openapi/index.js +4 -3
- package/dist/openapi-CH9Dh5UX.js +260 -0
- package/dist/openapi-CrCBEFEm.js +95 -0
- package/dist/openapi-D2dmyWZK.js +411 -0
- package/dist/openapi-document-CJO6cUS1.js +35 -0
- package/dist/operation-findings-D5Uo-dcm.js +35 -0
- package/dist/operation-risks-BD-j14dj.js +12 -0
- package/dist/operations-B0yO77Zz.js +290 -0
- package/dist/operations-BS8ExH5A.d.ts +58 -0
- package/dist/operations-De3F7tlf.js +88 -0
- package/dist/optional-CaQWp9HA.js +46 -0
- package/dist/orpc/index.d.ts +8 -12
- package/dist/orpc/index.js +10 -12
- package/dist/otel/index.d.ts +3 -5
- package/dist/otel/index.js +5 -7
- package/dist/output-CU7OppLv.js +244 -0
- package/dist/output-files-C5LFnQa4.js +1 -0
- package/dist/output-files-DNid6TBl.js +197 -0
- package/dist/ownership-BBQe7GZp.js +558 -0
- package/dist/parse-local-manifest-BGLWVchi.d.ts +8 -0
- package/dist/parse-local-manifest-CfMjZAFi.js +67 -0
- package/dist/parse-nfHSt1Wy.js +149 -0
- package/dist/parse-request-IEEzVFM8.js +24 -0
- package/dist/parse-sink-events-B6nZx41L.js +125 -0
- package/dist/paths-CeS_gpHf.js +44 -0
- package/dist/pdp/index.d.ts +3 -9
- package/dist/pdp/index.js +22 -18
- package/dist/peer-BWTpSLs2.js +1 -0
- package/dist/peer-D77JpXe-.js +978 -0
- package/dist/perf-token-dFGVP14-.js +155 -0
- package/dist/permdock-BueSeg7X.js +1514 -0
- package/dist/permdock-Dz3yzWrp.d.ts +853 -0
- package/dist/permission-registry-DMYRZVcn.js +413 -0
- package/dist/permissions-CQW3cr2S.js +17 -0
- package/dist/permissions-DWULToSb.d.ts +52 -0
- package/dist/permissions-ijDw4sO1.js +144 -0
- package/dist/pg-CA651850.js +59 -0
- package/dist/pins-CXXkVEiD.js +14 -0
- package/dist/pipeline-CXuwijr2.js +307 -0
- package/dist/pkce-DdsRBK7n.js +20 -0
- package/dist/plugin-1XW5OfAZ.d.ts +221 -0
- package/dist/plugin-MQVfUBUS.js +93 -0
- package/dist/plugin-outputs-BE2YCiMj.js +28 -0
- package/dist/policy-C-Lzp3Zh.d.ts +18 -0
- package/dist/policy-DFD2J5o_.js +476 -0
- package/dist/policy-FrCL4wDQ.js +37 -0
- package/dist/policy-bundle-1Znzdxse.js +82 -0
- package/dist/policy-from-catalog-YKaTeaco.js +452 -0
- package/dist/policy-module-Bp4HvsRg.js +107 -0
- package/dist/policy-types-93NwI8iI.d.ts +2855 -0
- package/dist/postgres-store-CYFvw98w.js +1023 -0
- package/dist/postgrest-DyrYo_XT.d.ts +138 -0
- package/dist/powersync-DVgkPQKM.js +1 -0
- package/dist/powersync-Y-_z8V5X.js +40 -0
- package/dist/powersync-pbvC5g6K.js +1630 -0
- package/dist/preset/index.d.ts +0 -12
- package/dist/preset/index.js +1 -1
- package/dist/preset-BcFDaeqd.js +1849 -0
- package/dist/principal-source-BIcukkB3.js +102 -0
- package/dist/prisma/index.d.ts +4 -12
- package/dist/prisma/index.js +10 -14
- package/dist/problem-BZB7zPC7.js +202 -0
- package/dist/problem-details-EJHcvYCz.js +154 -0
- package/dist/problem-types-81BEw0IN.js +7 -0
- package/dist/prompt-CSXHcJxy.js +931 -0
- package/dist/protected-action-BMb0ftEu.js +241 -0
- package/dist/protected-action-D6T3eJyW.d.ts +73 -0
- package/dist/protected-action-DiXulRVj.js +78 -0
- package/dist/provider-BnnFjtWI.js +893 -0
- package/dist/provider-ClD4rfgT.js +11 -0
- package/dist/provider-CydlnKkS.d.ts +4 -0
- package/dist/provider-store-atQUfsVO.js +51 -0
- package/dist/provider-with-CSw4mBDU.js +70 -0
- package/dist/public-api-DIMZmzWi.js +5579 -0
- package/dist/pull-C3_fCkgX.js +1 -0
- package/dist/pull-CpLyeY2p.js +252 -0
- package/dist/push-Cb7PqXdO.js +158 -0
- package/dist/pushed-policy-pH-EFWyx.d.ts +61 -0
- package/dist/pushed-policy-rpB6k77P.js +240 -0
- package/dist/quote-BKrTBbcH.js +36 -0
- package/dist/rbac-B-49toAp.js +90 -0
- package/dist/react/index.d.ts +10 -9
- package/dist/react/index.js +8 -7
- package/dist/react/lazy.d.ts +10 -12
- package/dist/react/lazy.js +8 -35
- package/dist/react/provider-client-lazy.d.ts +2 -0
- package/dist/react/provider-client-lazy.js +2 -0
- package/dist/react/provider-client.d.ts +1 -1
- package/dist/react/provider-client.js +1 -1
- package/dist/react-native/index.d.ts +12 -30
- package/dist/react-native/index.js +31 -41
- package/dist/read-memberships-BkePIa1F.js +63 -0
- package/dist/refresh-on-C1zIMtJr.d.ts +47 -0
- package/dist/refresh-online-CYGZNo6V.js +19 -0
- package/dist/refresh-online-vtUfV6dk.d.ts +10 -0
- package/dist/refs-Cix9Zjis.js +103 -0
- package/dist/relation-walk-BlWy9gBK.js +188 -0
- package/dist/relations-CIgB5KPJ.js +162 -0
- package/dist/replay-ClGIMp5p.d.ts +3 -0
- package/dist/replay-X2m6moK1.js +28 -0
- package/dist/request-context-CVJodWx8.js +70 -0
- package/dist/request-context-E3-ps-H_.d.ts +3 -0
- package/dist/request-schema-DzEoR310.js +155 -0
- package/dist/resend/index.d.ts +4 -10
- package/dist/resend/index.js +14 -17
- package/dist/resolve-names-Ca4ClMU2.js +266 -0
- package/dist/resolver-kdZ4HrpC.js +404 -0
- package/dist/resource-ref-BiQtFK-I.js +19 -0
- package/dist/resource-relations-Ck5sjYQR.js +251 -0
- package/dist/retire-BNiXnbBR.js +248 -0
- package/dist/revocations-3jyzniOz.js +26 -0
- package/dist/revocations-ku_f2d2y.d.ts +24 -0
- package/dist/rls-CmyxiQsS.js +321 -0
- package/dist/rls-DY5ITGzf.js +946 -0
- package/dist/rls-files-BtaUXVp-.js +114 -0
- package/dist/rls-options-CEpg5nDP.d.ts +26 -0
- package/dist/role-builder-DhsGEVq-.js +501 -0
- package/dist/role-grants-Bk6ZsaS0.js +46 -0
- package/dist/roles-B29psCem.js +29 -0
- package/dist/rolldown-runtime-B8NLbhFH.js +3 -0
- package/dist/row-conditions-DwIJocfQ.js +27 -0
- package/dist/row-pair-CxEhErJU.js +33 -0
- package/dist/rpc-B-4IZOiU.js +111 -0
- package/dist/rpc-DjgxFbjK.d.ts +18 -0
- package/dist/run-BoVUFspr.js +726 -0
- package/dist/run-BriRChKE.js +1 -0
- package/dist/run-ticket-D6T39Xdi.js +370 -0
- package/dist/run-ticket-DXwrko2J.d.ts +157 -0
- package/dist/runtime-Cl6xSbEq.js +13 -0
- package/dist/saas-DzjKUQr5.js +1218 -0
- package/dist/scan-C4x8UqS7.js +28 -0
- package/dist/schema-BeY3croo.js +403 -0
- package/dist/schema-Zfpbku8U.js +133 -0
- package/dist/scim/index.d.ts +2 -2
- package/dist/scim/index.js +2 -2
- package/dist/scim-B9QyJ23q.js +1046 -0
- package/dist/scopes-B-KX9EI8.js +238 -0
- package/dist/seed-sql-CjF7u0aX.js +60 -0
- package/dist/seeds/index.d.ts +2 -0
- package/dist/seeds/index.js +1 -0
- package/dist/seeds-BDTG7xl-.js +53 -0
- package/dist/seeds-uG196Ev4.d.ts +73 -0
- package/dist/server/index.d.ts +13 -13
- package/dist/server/index.js +14 -14
- package/dist/server-Co9CYGqk.js +146 -0
- package/dist/server-types-BrHOGAYx.d.ts +318 -0
- package/dist/sha256-DFsnyVPo.js +157 -0
- package/dist/shared-BOsJIQf4.js +124 -0
- package/dist/shared-BdF5DJDQ.js +330 -0
- package/dist/signals-a1NxAP0X.js +31 -0
- package/dist/sink-BD34OS8T.d.ts +247 -0
- package/dist/sink-Bgvf9lIz.js +966 -0
- package/dist/size-DF7xQ-nH.js +95 -0
- package/dist/skills-B0cLRZ7w.js +202 -0
- package/dist/skills-DiGdMvMw.js +50 -0
- package/dist/snapshot-DckMnHk8.js +352 -0
- package/dist/snapshot-cache-DTTEfmxv.js +69 -0
- package/dist/snapshot-cache-DoP3avLl.d.ts +68 -0
- package/dist/snapshot-compact-CwAop_6C.js +119 -0
- package/dist/snapshot-empty-DZ6sZ83n.js +17 -0
- package/dist/snapshot-evaluate-9RGy7J3N.js +552 -0
- package/dist/snapshot-reads-D775amTL.js +65 -0
- package/dist/snapshot-size-D-pCR8x0.js +139 -0
- package/dist/snapshot-size-DU7CvpMt.js +1 -0
- package/dist/solid/index.d.ts +18 -20
- package/dist/solid/index.js +15 -19
- package/dist/solid-start/index.d.ts +6 -8
- package/dist/solid-start/index.js +4 -5
- package/dist/sources-BbSUNmFX.js +10 -0
- package/dist/sources-DnjJPGfb.js +657 -0
- package/dist/sources-NQio1yFq.d.ts +727 -0
- package/dist/sql-BYYNi1lu.d.ts +8 -0
- package/dist/sql-T4GaBh9X.js +93 -0
- package/dist/src-D6_T4zd7.js +1811 -0
- package/dist/ssf/index.d.ts +3 -3
- package/dist/ssf/index.js +20 -31
- package/dist/standard-webhooks-B3MQihcP.d.ts +86 -0
- package/dist/standard-webhooks-BtIkXclH.js +227 -0
- package/dist/storage-BhGDhsXm.js +131 -0
- package/dist/store-AH8bmaxW.js +377 -0
- package/dist/store-core-eqG8jijs.d.ts +306 -0
- package/dist/store-options-C8x39AHa.js +1034 -0
- package/dist/stores-4DOaL4ZP.d.ts +58 -0
- package/dist/stores-DoA7ACkz.js +127 -0
- package/dist/stream-DdF94h7T.js +73 -0
- package/dist/style-CQDaLJtP.js +24 -0
- package/dist/style-Crf-90o6.js +1 -0
- package/dist/subject-DkxY-AhF.js +23 -0
- package/dist/subject-cache-BZeSj4Xf.d.ts +156 -0
- package/dist/subject-settings-BO-frcYx.js +147 -0
- package/dist/subject-settings-C9F1sU1d.d.ts +48 -0
- package/dist/supabase/client.d.ts +1 -1
- package/dist/supabase/client.js +2 -3
- package/dist/supabase/index.d.ts +77 -24
- package/dist/supabase/index.js +9 -8
- package/dist/supabase/middleware.d.ts +27 -9
- package/dist/supabase/middleware.js +51 -21
- package/dist/supabase-B7Q5bO-P.js +30 -0
- package/dist/supabase-BI5ZhzLl.js +792 -0
- package/dist/supabase-config-mXcggV5I.js +890 -0
- package/dist/supabase-hook-C7FNwQ1p.js +2 -0
- package/dist/supabase-hook-loL2iJVb.js +405 -0
- package/dist/supabase-outcome-CMLuLW-V.js +9 -0
- package/dist/supautils-DXzJ2E2Q.js +96 -0
- package/dist/support-session-B8xrW28B.js +157 -0
- package/dist/svelte/index.d.ts +8 -10
- package/dist/svelte/index.js +12 -15
- package/dist/svelte/runtime.d.ts +4 -6
- package/dist/svelte/runtime.js +4 -4
- package/dist/svelte/source.d.ts +8 -10
- package/dist/svelte/source.js +6 -7
- package/dist/sveltekit/index.d.ts +6 -8
- package/dist/sveltekit/index.js +3 -4
- package/dist/tables-C8IwkTHq.js +3249 -0
- package/dist/tanstack-start/index.d.ts +6 -8
- package/dist/tanstack-start/index.js +3 -4
- package/dist/target-BGpxgKsN.js +50 -0
- package/dist/tenancy-B5Xxt9Sc.js +223 -0
- package/dist/terminal/index.d.ts +6 -16
- package/dist/terminal/index.js +18 -23
- package/dist/testing/core.d.ts +1 -1
- package/dist/testing/core.js +1 -1
- package/dist/testing/fixtures/index.d.ts +12 -10
- package/dist/testing/fixtures/index.js +48 -25
- package/dist/testing/index.d.ts +85 -85
- package/dist/testing/index.js +226 -115
- package/dist/testing/saas/index.d.ts +5 -15
- package/dist/testing/saas/index.js +2 -2
- package/dist/testing/saas/permissions.d.ts +1 -1
- package/dist/testing/saas/permissions.js +1 -1
- package/dist/text-D704xHVl.js +7 -0
- package/dist/text-diff-CsglY49A.js +440 -0
- package/dist/thenable-BxMy2v8w.js +39 -0
- package/dist/time-r0CKBm57.js +94 -0
- package/dist/timeout-nOqLpU2I.js +7 -0
- package/dist/token-BgswTQzt.d.ts +9 -0
- package/dist/token-CSljQqzA.js +76 -0
- package/dist/tool-refusal-DzCSbjp8.js +43 -0
- package/dist/trpc/index.d.ts +7 -9
- package/dist/trpc/index.js +7 -8
- package/dist/type-helpers-DHCQEPj8.d.ts +47 -0
- package/dist/types-3pRMqcvw.d.ts +84 -0
- package/dist/types-BFtFaI1W.d.ts +66 -0
- package/dist/types-BdNdMix7.d.ts +263 -0
- package/dist/types-C7QtRn3n.d.ts +66 -0
- package/dist/types-CVCRFYY_.d.ts +102 -0
- package/dist/types-CWmBZtQN.d.ts +274 -0
- package/dist/types-Cakw89Wx.d.ts +372 -0
- package/dist/types-D3tjoLwT.d.ts +124 -0
- package/dist/types-DFZKovb3.js +77 -0
- package/dist/types-DONLJQjY.d.ts +134 -0
- package/dist/types-OzSal_K_.d.ts +178 -0
- package/dist/types-XSfi6ihL.d.ts +65 -0
- package/dist/types-nXo_oQYk.d.ts +1235 -0
- package/dist/unplugin/index.d.ts +1 -3
- package/dist/unplugin/index.js +3 -4
- package/dist/usage-BgNAgZfj.js +31 -0
- package/dist/usage-D6HUlfvP.js +1 -0
- package/dist/usage-llSQehNg.js +761 -0
- package/dist/validation-error-BAO1W1yk.d.ts +27 -0
- package/dist/validation-error-CgDOA6VS.js +35 -0
- package/dist/validity-YNEEm2MZ.js +56 -0
- package/dist/verifier-BIYkGcJc.js +530 -0
- package/dist/verify-nMTdEqBB.js +1102 -0
- package/dist/version-CU6e2wxV.js +7 -0
- package/dist/version-D-jWyJb9.js +46 -0
- package/dist/version-DcZCjWXb.js +1 -0
- package/dist/version-cache-BXkl7-Fz.js +462 -0
- package/dist/views-Dpr1uB16.js +164 -0
- package/dist/vocabulary-CE2k7s1a.js +157 -0
- package/dist/vocabulary-FYgI_NoI.d.ts +400 -0
- package/dist/vue/index.d.ts +18 -20
- package/dist/vue/index.js +13 -18
- package/dist/waiter-DKdFHKVZ.js +66 -0
- package/dist/waiter-hYLJXA7r.d.ts +37 -0
- package/dist/watch-BecZtEdU.js +155 -0
- package/dist/watch-CiN6WU9k.js +221 -0
- package/dist/watch-NAUnUXph.js +1 -0
- package/dist/webmcp/index.d.ts +2 -6
- package/dist/webmcp/index.js +8 -9
- package/dist/who-can-rUSZfLvI.js +366 -0
- package/dist/wire-delegation-DC5Cyec4.js +35 -0
- package/dist/wire-denial-BcRQnA7p.js +26 -0
- package/dist/workflow/index.d.ts +3 -3
- package/dist/workflow/index.js +12 -14
- package/dist/workflow-sdk/index.d.ts +6 -8
- package/dist/workflow-sdk/index.js +2 -3
- package/dist/wrap-CsfsaJhd.js +32 -0
- package/dist/wrap-D-KvhzaC.d.ts +16 -0
- package/package.json +83 -39
- package/schemas/catalog-v2.json +665 -0
- package/schemas/cli-commands-v1.json +1 -1
- package/schemas/cli-result-v2.json +163 -0
- package/schemas/cloud-api-v1.json +1 -1
- package/schemas/snapshot-v1.json +26 -0
- package/schemas/supabase-claims-v1.json +5 -1
- package/schemas/supabase-manifest-v1.json +11 -2
- package/skills/permdock/SKILL.md +1 -1
- package/skills/permdock-data/references/queries-and-rls.md +2 -1
- package/skills/permdock-wire/references/adapters.md +5 -3
- package/dist/2020-CJbO8Bvz.js +0 -6773
- package/dist/active-tenant-DVee32-T.js +0 -39
- package/dist/adapter-context-OHikyRqV.js +0 -29
- package/dist/adoption-scan-8F9VSQrK.js +0 -107
- package/dist/app-J9PE1LNm.js +0 -24
- package/dist/app-data-UNNm07jV.js +0 -63
- package/dist/approval-header-8QV6MU4H.js +0 -26
- package/dist/approval-normalize-KfhzpD93.js +0 -196
- package/dist/approval-policies-BiXMlYBu.d.ts +0 -138
- package/dist/approval-prompt-B8hQY69x.js +0 -61
- package/dist/approval-prompt-j5PTItiy.d.ts +0 -59
- package/dist/approval-required-TzNB9oQA.js +0 -6
- package/dist/approvals-BfzI8Foe.js +0 -1048
- package/dist/approvers-BaNwKYgd.js +0 -77
- package/dist/arazzo-BUVqRmaJ.js +0 -36
- package/dist/arazzo-CWmM8pWw.js +0 -77
- package/dist/args-iafbHiXn.js +0 -311
- package/dist/audience-DLoopY4q.js +0 -55
- package/dist/auth-BxXHxWRy.js +0 -189
- package/dist/authz-topic-Dbc-HDOS.js +0 -15
- package/dist/automation-BueW05db.js +0 -158
- package/dist/automation-_iGeP54L.d.ts +0 -124
- package/dist/base-url-BQbddZO5.js +0 -9
- package/dist/better-supabase-DF8f8oly.js +0 -194
- package/dist/bind-CTj4dHc1.d.ts +0 -58
- package/dist/bind-LQ6zbARV.js +0 -125
- package/dist/body-Cy9S8zhw.js +0 -10
- package/dist/body-text-DQhcmqdY.js +0 -56
- package/dist/boundary-BV3O1eud.js +0 -19
- package/dist/boundary-C9ck-3uK.d.ts +0 -24
- package/dist/budget-BBCPDOGP.js +0 -14
- package/dist/budget-CNLsV2SL.d.ts +0 -14
- package/dist/build-instance-Bq8wkJ4i.js +0 -31
- package/dist/canonical-json-DwilZ1iB.js +0 -29
- package/dist/capability-CenWwTMR.js +0 -205
- package/dist/capability-DqCyFGip.d.ts +0 -130
- package/dist/casbin-DIvUMac7.js +0 -242
- package/dist/casbin-qpG_ZphP.js +0 -30
- package/dist/casl-CjBVJj8R.js +0 -24
- package/dist/casl-CkBssiB1.js +0 -308
- package/dist/catalog-B1MAmRQI.js +0 -131
- package/dist/catalog-BCVIH7kq.js +0 -1
- package/dist/catalog-CaZoXBD8.js +0 -52
- package/dist/catalog-doc-DnQDviXY.js +0 -353
- package/dist/catalog-fingerprint-e6aCWosn.js +0 -157
- package/dist/catalog-operations-Do1eD-Rt.js +0 -60
- package/dist/catalog-path-CnI0XTFK.js +0 -12
- package/dist/challenge-DKJpP-5P.js +0 -521
- package/dist/checks-fyDOhcz0.js +0 -72
- package/dist/claims-map-CKkoAAYF.js +0 -16
- package/dist/claims-map-D1Pb5oRq.d.ts +0 -35
- package/dist/client-JK504UCq.d.ts +0 -45
- package/dist/clients-C_NOET3z.d.ts +0 -12
- package/dist/clients-DYr3U86j.js +0 -23
- package/dist/cloud-CXgE1qpa.js +0 -86
- package/dist/codemod-BJ0Kgv9b.js +0 -36
- package/dist/codemod-DjgVx3RQ.js +0 -2800
- package/dist/collect-BG-SXFQv.js +0 -537
- package/dist/collect-CxPJRjoc.js +0 -55
- package/dist/collect-ZLgHgujd.js +0 -1
- package/dist/command-L8EstFNm.js +0 -6
- package/dist/compact-CAf557ZB.js +0 -29
- package/dist/compare-DTfyUunF.js +0 -12
- package/dist/compile-Cvru58id.js +0 -661
- package/dist/compile-Dh9pW_Co.d.ts +0 -120
- package/dist/completion-DUHSRdoQ.js +0 -152
- package/dist/config-CgA_Z5Ts.js +0 -26
- package/dist/config-DC7aiuhP.js +0 -116
- package/dist/config-report-B31MnuKf.js +0 -56
- package/dist/config-shape-ChhsuGSV.js +0 -147
- package/dist/connection-zoAgwdsD.js +0 -197
- package/dist/connector-schema-CYLQNMYq.js +0 -434
- package/dist/constants-DcJABbLW.js +0 -20
- package/dist/context-BXM0MDB0.js +0 -95
- package/dist/core-BTJlqWsv.js +0 -341
- package/dist/core-BhZEo5Le.d.ts +0 -206
- package/dist/coverage-BuGlwUms.d.ts +0 -135
- package/dist/coverage-CGu_Kovx.js +0 -261
- package/dist/create--q7-j0hX.d.ts +0 -127
- package/dist/create-C5IQw_-i.d.ts +0 -191
- package/dist/create-CYj0cjTu.d.ts +0 -128
- package/dist/create-D7D94oNh.js +0 -376
- package/dist/create-DaddhCIg.js +0 -134
- package/dist/credential-BMsbcaeP.js +0 -431
- package/dist/credentials-BZU7Twpt.js +0 -310
- package/dist/credentials-Bq-Xa7Vq.d.ts +0 -125
- package/dist/credentials-dkycUsY3.js +0 -74
- package/dist/decide-set-DXEPepY1.js +0 -100
- package/dist/deciding-columns-NB4wcyBf.js +0 -134
- package/dist/decision-CaG5_eNJ.js +0 -21
- package/dist/delegation-CrdqnesZ.js +0 -262
- package/dist/delegation-input-DcXhiMkf.js +0 -19
- package/dist/delivery-BupfvJIV.js +0 -560
- package/dist/delivery-event-JioK5YbS.js +0 -40
- package/dist/denied-text-B6s29jcf.d.ts +0 -22
- package/dist/describe-BZAlPHxT.js +0 -101
- package/dist/describe-DwcoWMLB.d.ts +0 -45
- package/dist/device-BkSynWdg.js +0 -196
- package/dist/diff-BnYHpRSI.js +0 -466
- package/dist/diff-H75YU6Q-.js +0 -37
- package/dist/digest-8Yx2CchM.d.ts +0 -19
- package/dist/digest-BI-6aa6d.js +0 -27
- package/dist/doctor-Dvt1_ROJ.js +0 -3560
- package/dist/doctor-JLouRSQt.js +0 -54
- package/dist/env-DJZrPjRi.js +0 -8
- package/dist/errors-BDUwg2qC.js +0 -27
- package/dist/errors-BhRkoNS7.js +0 -145
- package/dist/errors-CHwoRRpB.d.ts +0 -14
- package/dist/errors-D_SnqcRn.d.ts +0 -141
- package/dist/errors-ynga1EQy.js +0 -128
- package/dist/evaluate-BQ2nWOki.js +0 -1905
- package/dist/evaluations-BVtY66lF.d.ts +0 -38
- package/dist/evaluations-Bj5xw0EM.js +0 -612
- package/dist/evaluator-CDl2YUd_.js +0 -2
- package/dist/evaluator-eager-CULtQ8t6.js +0 -9
- package/dist/event-time-BGy48400.js +0 -27
- package/dist/fetch-adapter-BJ76IZZg.d.ts +0 -34
- package/dist/fetch-adapter-CXeBg4CH.js +0 -124
- package/dist/fields-D9PIYlJy.js +0 -504
- package/dist/fields-DlKwZYiy.js +0 -26
- package/dist/files-BSjrtIHw.js +0 -141
- package/dist/files-CfiRtQ-m.js +0 -140
- package/dist/fixtures-BVZc7OCF.js +0 -80
- package/dist/flags-BlmpmXoY.js +0 -86
- package/dist/freeze-jjan0lCv.js +0 -63
- package/dist/from-snapshot-FdVXG_QZ.js +0 -159
- package/dist/gen-D17P8vo0.js +0 -827
- package/dist/gen-YA3SK59O.js +0 -58
- package/dist/generate-BqkZq8Dr.js +0 -165
- package/dist/generate-CezbCaTI.js +0 -275
- package/dist/grantee-OG4klcNr.js +0 -110
- package/dist/grantee-conditions-Dzprappv.js +0 -271
- package/dist/grantee-match-CPQ9zV-H.js +0 -148
- package/dist/graph-sql-BwFC4Qjs.d.ts +0 -29
- package/dist/headers-B9jQxjtW.d.ts +0 -10
- package/dist/helpers-CO2hDpBU.js +0 -537
- package/dist/hosted-CQW_YNx7.js +0 -362
- package/dist/hosted-D5StFpKa.d.ts +0 -102
- package/dist/http-B_LphE5Y.d.ts +0 -12
- package/dist/http-DH94eh6f.js +0 -72
- package/dist/http-DKLXrFGk.js +0 -83
- package/dist/http-dptLQzPP.js +0 -49
- package/dist/ids-DzhJaCUj.js +0 -55
- package/dist/import-B8zbuskR.js +0 -5950
- package/dist/import-BYYXmHvP.js +0 -1143
- package/dist/index-B1-tE0Kx.d.ts +0 -1159
- package/dist/index-BwSEp_O5.d.ts +0 -210
- package/dist/index-CB_eM-qx.d.ts +0 -101
- package/dist/index-CvcE9mYP.d.ts +0 -234
- package/dist/index-D7sMtTf6.d.ts +0 -542
- package/dist/index-d7f0hNss.d.ts +0 -233
- package/dist/init-BdgWNuc3.js +0 -96
- package/dist/init-DKRhYiGW.js +0 -95
- package/dist/instance-options-DhQVCuhT.d.ts +0 -11
- package/dist/instance-options-URVwqpMW.js +0 -24
- package/dist/instance-snapshot-DyG_5ASl.js +0 -693
- package/dist/instant-DK3Iz83e.js +0 -19
- package/dist/internals-B3IgHrvo.js +0 -20
- package/dist/json-schema-BPGa-RjQ.js +0 -149
- package/dist/json-schema-BfXgnRNT.d.ts +0 -40
- package/dist/kernel-D9AxUqmz.js +0 -427
- package/dist/limits-CAhpRrhk.js +0 -167
- package/dist/live-options-BBIT68le.js +0 -73
- package/dist/load-C4p4VgwR.js +0 -99
- package/dist/load-DiBUJx77.js +0 -1
- package/dist/load-jose-DZ4dnjri.js +0 -8
- package/dist/login-DEvccJwP.js +0 -68
- package/dist/login-IIUDSAYW.js +0 -257
- package/dist/lru-8q4WZjBV.js +0 -28
- package/dist/manifest-BoCYBbQL.js +0 -46
- package/dist/manifest-C6eFl3Vo.d.ts +0 -349
- package/dist/manifest-CZ-GmsOL.js +0 -401
- package/dist/manifest-json-CAGzls-C.js +0 -9
- package/dist/manifest-schema-svAkgqMc.js +0 -501
- package/dist/map-claims-CAa_bQt9.js +0 -387
- package/dist/map-error-BCdb2Nrp.js +0 -23
- package/dist/markers-BeHZ4x9Q.js +0 -80
- package/dist/may-use-WDhFPqGG.js +0 -125
- package/dist/membership-filter-BWnfRQzo.js +0 -68
- package/dist/migrate-DVsxeE0y.js +0 -537
- package/dist/module-values-CdaVwrab.js +0 -107
- package/dist/oauth-security-X7Em8DbH.js +0 -26
- package/dist/ocsf-TcjRBgIs.js +0 -136
- package/dist/openapi-BFUnL8Yi.js +0 -137
- package/dist/openapi-Cc-aS9xC.js +0 -416
- package/dist/openapi-DcjyfR1g.js +0 -256
- package/dist/operation-findings-CVwJHEu_.js +0 -36
- package/dist/operation-risks-BKOcTv8J.js +0 -13
- package/dist/operations-BMPx7HyO.d.ts +0 -62
- package/dist/operations-Bm9HFecz.js +0 -89
- package/dist/optional-8TKc-0j4.js +0 -47
- package/dist/output-LDciF_4t.js +0 -96
- package/dist/output-files-BYscrQl-.js +0 -1
- package/dist/output-files-CM0BnH05.js +0 -150
- package/dist/ownership-DvK6INyx.js +0 -1062
- package/dist/parse-CORUNcCo.js +0 -151
- package/dist/parse-local-manifest-Ce2N-Opr.js +0 -69
- package/dist/parse-local-manifest-w_ksIkB9.d.ts +0 -10
- package/dist/parse-request-DOBVaeiQ.js +0 -25
- package/dist/paths-CUvURzHp.js +0 -45
- package/dist/peer-BuK9F53f.js +0 -982
- package/dist/peer-n-swIV4H.js +0 -1
- package/dist/permdock-B3zE16To.js +0 -1203
- package/dist/permdock-DV3opaI3.d.ts +0 -674
- package/dist/permission-registry-B8tYxPIt.js +0 -398
- package/dist/permissions-BaoLxy66.js +0 -18
- package/dist/permissions-D-M48hW-.js +0 -146
- package/dist/permissions-DriWkV7q.d.ts +0 -54
- package/dist/pg-Ddxsd5ZB.js +0 -60
- package/dist/pins-nqarl3oE.js +0 -15
- package/dist/pkce-CnmmYqUZ.js +0 -21
- package/dist/policy-DIHfTqm6.d.ts +0 -20
- package/dist/policy-DnNOTENd.js +0 -430
- package/dist/policy-from-catalog-Z0hvSffr.js +0 -454
- package/dist/policy-module-xym9fnSq.js +0 -95
- package/dist/policy-types-DU389Elz.d.ts +0 -2809
- package/dist/postgres-store-DcyrPS-r.js +0 -1028
- package/dist/postgrest-3dE9SGx9.d.ts +0 -124
- package/dist/powersync-B5YjtUGd.js +0 -1532
- package/dist/powersync-BgUsk2Nf.js +0 -1
- package/dist/powersync-Dx7odzyw.js +0 -62
- package/dist/preset-Bn5Z54cH.js +0 -1858
- package/dist/principal-source-C6N60GtM.js +0 -103
- package/dist/problem-CPB8kqk7.js +0 -203
- package/dist/problem-details-CLDgX1KV.js +0 -156
- package/dist/problem-types-DSsRfONQ.js +0 -8
- package/dist/prompt-D1Gj1W4Y.js +0 -938
- package/dist/protected-action-CjSUoPGx.d.ts +0 -76
- package/dist/protected-action-D41o5LvP.js +0 -244
- package/dist/protected-action-OpOxtTsN.js +0 -80
- package/dist/provider-Bzzux0TR.js +0 -12
- package/dist/provider-D1jsNJ85.d.ts +0 -6
- package/dist/provider-store-tIAwP4aW.js +0 -52
- package/dist/provider-with-Do28DhxP.js +0 -69
- package/dist/pull-Pde1lapF.js +0 -257
- package/dist/pull-a4RpDxk8.js +0 -1
- package/dist/push-sJ5dy46a.js +0 -162
- package/dist/pushed-policy-Db651nih.d.ts +0 -63
- package/dist/pushed-policy-UZyQinrL.js +0 -241
- package/dist/refresh-on-L9UOwATg.d.ts +0 -49
- package/dist/refs-C8BKxc_e.js +0 -105
- package/dist/relation-walk-BDTaTKTM.js +0 -189
- package/dist/relations-CMsJ1ARY.js +0 -163
- package/dist/replay-BU09ad4L.js +0 -29
- package/dist/replay-BpmpY2ev.d.ts +0 -5
- package/dist/request-context-C2_1lchh.d.ts +0 -5
- package/dist/request-context-dyCY4V1t.js +0 -71
- package/dist/request-schema-CMP8Cmxd.js +0 -156
- package/dist/resolve-names-D5_kABup.js +0 -206
- package/dist/resource-ref-CaS9yVPi.js +0 -20
- package/dist/resource-relations-8-pCScBO.js +0 -252
- package/dist/retire-B2xffQgY.js +0 -249
- package/dist/revocations-BaUXHM1N.d.ts +0 -26
- package/dist/revocations-Bhr0aMIC.js +0 -27
- package/dist/rls-BI687j8q.js +0 -2700
- package/dist/rls-CKLHLcRl.js +0 -367
- package/dist/role-builder-BXdhhQcB.js +0 -507
- package/dist/rolldown-runtime-C3I60J0A.js +0 -4
- package/dist/row-conditions-BAGHOmVq.js +0 -28
- package/dist/row-pair-DglMdRFh.js +0 -34
- package/dist/rpc-BdFGYcWm.js +0 -112
- package/dist/rpc-DKRQobOX.d.ts +0 -22
- package/dist/run-B4heHtD1.js +0 -1
- package/dist/run-BG2kPruh.js +0 -694
- package/dist/run-ticket-Ddxt9OuU.js +0 -371
- package/dist/run-ticket-o4RxoaEN.d.ts +0 -159
- package/dist/runtime-rf0ZuyF3.js +0 -14
- package/dist/saas-D9maBt0q.js +0 -1223
- package/dist/scan-BvTBo9-D.js +0 -29
- package/dist/schema-BlnU_TzE.js +0 -414
- package/dist/schema-grK6TTBH.js +0 -134
- package/dist/scim-BG6uPUeW.js +0 -1056
- package/dist/scim-CovliQUg.js +0 -44
- package/dist/scopes-gdH__vDZ.js +0 -239
- package/dist/server-CKjFooaJ.js +0 -147
- package/dist/server-types-C4q8_8MM.d.ts +0 -325
- package/dist/sha256-C-4WXKIu.js +0 -158
- package/dist/shared-BRmCJxDK.js +0 -125
- package/dist/shared-DfaIWvIJ.js +0 -354
- package/dist/signals-B1vHR3fN.js +0 -32
- package/dist/sink-C3KDccl9.d.ts +0 -249
- package/dist/sink-D9_vh372.js +0 -968
- package/dist/skills-DzNdLezx.js +0 -51
- package/dist/skills-nPLVGtGH.js +0 -204
- package/dist/snapshot-D0VOanxQ.js +0 -334
- package/dist/snapshot-cache-B66h7FBK.js +0 -70
- package/dist/snapshot-cache-C1mN0pXe.d.ts +0 -70
- package/dist/snapshot-compact-CUtXsx6i.js +0 -75
- package/dist/snapshot-empty-F7d5BRlc.js +0 -18
- package/dist/snapshot-evaluate-C3ZA35O_.js +0 -501
- package/dist/snapshot-reads-CNNmp1cK.js +0 -66
- package/dist/sources-2virTxHt.d.ts +0 -721
- package/dist/sources-C4vkzZJV.js +0 -660
- package/dist/sources-qoIJQrJv.js +0 -11
- package/dist/sql-0WjxIp9g.js +0 -80
- package/dist/sql-B80DFdpG.d.ts +0 -10
- package/dist/src-ieIv22BA.js +0 -2080
- package/dist/standard-webhooks-B2g_yWK8.d.ts +0 -88
- package/dist/standard-webhooks-D67a3nzk.js +0 -228
- package/dist/storage-C2bWdvJH.js +0 -132
- package/dist/store-DXO0aVgf.js +0 -380
- package/dist/store-core-BI-9ZU-5.d.ts +0 -311
- package/dist/store-options-BYKNX_JG.js +0 -993
- package/dist/stores-DtM8pt8o.js +0 -128
- package/dist/stores-DwGfIcmq.d.ts +0 -57
- package/dist/stream-DQ3rbO3J.js +0 -74
- package/dist/style-DblOtSga.js +0 -1
- package/dist/style-Ds11Hmk4.js +0 -25
- package/dist/subject-C7RddW0G.js +0 -24
- package/dist/subject-cache-BT1fGuea.js +0 -193
- package/dist/subject-cache-TY2tw-k9.d.ts +0 -144
- package/dist/subject-jG6o8eKo.js +0 -556
- package/dist/subject-settings-8sH5HlII.js +0 -150
- package/dist/subject-settings-vNW8qmUH.d.ts +0 -52
- package/dist/supabase-BlAqmxD8.js +0 -723
- package/dist/supabase-dk1kB9bJ.js +0 -92
- package/dist/supabase-hook-Bu5gkzix.js +0 -1
- package/dist/supabase-hook-Cf9zKz8T.js +0 -4263
- package/dist/supautils-BREOPaHY.js +0 -1186
- package/dist/support-session-BGeEYDSq.js +0 -158
- package/dist/tables-DnNACfAr.js +0 -4003
- package/dist/target-qdEAnnhU.js +0 -51
- package/dist/tenancy-BlxY5T0q.js +0 -224
- package/dist/text-BMFRfBqc.js +0 -8
- package/dist/text-diff-BtfSmdUo.js +0 -444
- package/dist/thenable-BNSM1U2R.js +0 -40
- package/dist/time-nR1JesoH.js +0 -95
- package/dist/timeout-D51niuQP.js +0 -8
- package/dist/token-D6pWn8Uj.d.ts +0 -11
- package/dist/token-DaMnIU9O.js +0 -77
- package/dist/tool-refusal-D4spOJ7I.js +0 -44
- package/dist/type-helpers-tDoGEIsd.d.ts +0 -49
- package/dist/types-61f3KMtI.d.ts +0 -1136
- package/dist/types-BDgMzK1i.d.ts +0 -368
- package/dist/types-BIvkpVoc.d.ts +0 -180
- package/dist/types-BWjNPQkS.d.ts +0 -67
- package/dist/types-Bq4AU68k.d.ts +0 -105
- package/dist/types-BsqLNNvG.d.ts +0 -68
- package/dist/types-CH67RMvL.d.ts +0 -136
- package/dist/types-CcUXciSj.js +0 -79
- package/dist/types-DAyp592k.d.ts +0 -276
- package/dist/types-DEDocm4c.d.ts +0 -81
- package/dist/types-DQQkzF97.d.ts +0 -126
- package/dist/types-DdeivUBP.d.ts +0 -68
- package/dist/types-X40XNxRP.d.ts +0 -265
- package/dist/usage-BkDU1dYf.js +0 -762
- package/dist/usage-DNj42KHA.js +0 -32
- package/dist/usage-DrB_tDNk.js +0 -1
- package/dist/validation-error-CV0nV6_L.d.ts +0 -29
- package/dist/validation-error-CYg2kJEw.js +0 -36
- package/dist/validity-IcjQSR7I.js +0 -57
- package/dist/verifier-DUV6pLqZ.js +0 -519
- package/dist/verify-Boehaks6.js +0 -1736
- package/dist/version-DMQ0dnN5.js +0 -48
- package/dist/version-DizhmD72.js +0 -1
- package/dist/version-sources-BRb9ZteH.js +0 -34
- package/dist/views-MWmJ6Y4P.js +0 -147
- package/dist/vocabulary-BuYFWeCU.js +0 -158
- package/dist/vocabulary-DeZvUaTw.d.ts +0 -401
- package/dist/waiter-BophA4BT.d.ts +0 -39
- package/dist/waiter-aBLM63_f.js +0 -67
- package/dist/watch-CJKYQYNb.js +0 -167
- package/dist/watch-Cv-xvI6e.js +0 -1
- package/dist/who-can-Yh9WdiwK.js +0 -367
- package/dist/wire-delegation-Cv3W2eaM.js +0 -36
- package/dist/wire-denial-C7PaVYEM.js +0 -27
- package/dist/wrap-Bq9fHwuT.d.ts +0 -18
- package/dist/wrap-C5PWzgkq.js +0 -33
- package/schemas/catalog-v1.json +0 -679
- package/schemas/cli-result-v1.json +0 -95
|
@@ -0,0 +1,2159 @@
|
|
|
1
|
+
import { n as CliError } from "./errors-DgLOqc6j.js";
|
|
2
|
+
import { i as refuseDirty, t as applyFiles } from "./files-DuV7wRim.js";
|
|
3
|
+
import { a as rel } from "./files-DAR51W3J.js";
|
|
4
|
+
import { t as catalogFingerprint } from "./catalog-fingerprint-DAWZARy6.js";
|
|
5
|
+
import { r as isRecord } from "./compact-C4LFuqbW.js";
|
|
6
|
+
import { n as flagSpellings, o as GLOBAL_FLAGS } from "./args-0EWFk-4S.js";
|
|
7
|
+
import { c as generateFlags, f as policyFlag, i as dryRunFlag, r as dbUrlFlags, t as checkFlag } from "./flags-C0e-BzGW.js";
|
|
8
|
+
import { n as ROOT } from "./manifest-XIXxXYty.js";
|
|
9
|
+
import { i as visitorKeyTypes, r as parseSync, t as createVisitor } from "./optional-CaQWp9HA.js";
|
|
10
|
+
import { n as defaultSqlCommand } from "./sql-T4GaBh9X.js";
|
|
11
|
+
import { t as beforeFirst } from "./text-D704xHVl.js";
|
|
12
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
13
|
+
import { basename, extname, join, resolve } from "node:path";
|
|
14
|
+
// src/cli/codemod/catalog-0.26.ts
|
|
15
|
+
const LEGACY_MODE = /* @__PURE__ */ new Set([
|
|
16
|
+
"any",
|
|
17
|
+
"all",
|
|
18
|
+
"sequential"
|
|
19
|
+
]);
|
|
20
|
+
const V1_SCHEMA = "https://permdock.com/schemas/catalog-v1.json";
|
|
21
|
+
const V2_SCHEMA = "https://permdock.com/schemas/catalog-v2.json";
|
|
22
|
+
/**
|
|
23
|
+
* A stored catalog-v1 document becomes catalog-v2: `version` 2, the schema URL,
|
|
24
|
+
* and a pre-0.17 approval (`mode` of `any`, `all` or `sequential`, or a boolean
|
|
25
|
+
* `distinct`) rewritten to `combine` and `mode`. The fingerprint is recomputed
|
|
26
|
+
* when the document has one.
|
|
27
|
+
*/
|
|
28
|
+
function rewriteStoredCatalog(text) {
|
|
29
|
+
let parsed;
|
|
30
|
+
try {
|
|
31
|
+
parsed = JSON.parse(text);
|
|
32
|
+
} catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!isStoredCatalogV1(parsed)) return;
|
|
36
|
+
const next = structuredClone(parsed);
|
|
37
|
+
if (!isRecord(next)) return;
|
|
38
|
+
rewriteTree(next);
|
|
39
|
+
next["$schema"] = V2_SCHEMA;
|
|
40
|
+
next["version"] = 2;
|
|
41
|
+
if ("fingerprint" in parsed) next["fingerprint"] = catalogFingerprint(next);
|
|
42
|
+
const body = `${JSON.stringify(next, null, 2)}\n`;
|
|
43
|
+
return text.endsWith("\n") ? {
|
|
44
|
+
text: body,
|
|
45
|
+
from: "catalog-v1",
|
|
46
|
+
to: "catalog-v2"
|
|
47
|
+
} : {
|
|
48
|
+
text: body.slice(0, -1),
|
|
49
|
+
from: "catalog-v1",
|
|
50
|
+
to: "catalog-v2"
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function isStoredCatalogV1(value) {
|
|
54
|
+
if (!isRecord(value) || !isRecord(value["resources"])) return false;
|
|
55
|
+
if (!Array.isArray(value["permissions"])) return false;
|
|
56
|
+
const schema = value["$schema"];
|
|
57
|
+
return value["version"] === 1 || schema === V1_SCHEMA || typeof schema === "string" && schema.includes("catalog-v1");
|
|
58
|
+
}
|
|
59
|
+
function rewriteTree(value) {
|
|
60
|
+
if (Array.isArray(value)) {
|
|
61
|
+
for (const item of value) rewriteTree(item);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!isRecord(value)) return;
|
|
65
|
+
const mode = value["mode"];
|
|
66
|
+
const distinct = value["distinct"];
|
|
67
|
+
if (typeof mode === "string" && LEGACY_MODE.has(mode)) {
|
|
68
|
+
delete value["mode"];
|
|
69
|
+
value["combine"] = mode;
|
|
70
|
+
}
|
|
71
|
+
if (typeof distinct === "boolean") {
|
|
72
|
+
delete value["distinct"];
|
|
73
|
+
if (distinct === false) value["mode"] = "confirm";
|
|
74
|
+
}
|
|
75
|
+
for (const item of Object.values(value)) rewriteTree(item);
|
|
76
|
+
}
|
|
77
|
+
// src/cli/codemod/cli-renames-0.5.ts
|
|
78
|
+
const FLAG_RENAMES = [
|
|
79
|
+
{
|
|
80
|
+
commands: ["rls generate", "supabase hook generate"],
|
|
81
|
+
from: "--db",
|
|
82
|
+
to: "--db-url-stdin",
|
|
83
|
+
hint: "--db-url-stdin or DATABASE_URL"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
commands: ["rls generate", "supabase hook generate"],
|
|
87
|
+
from: "--db-url",
|
|
88
|
+
to: "--db-url-stdin",
|
|
89
|
+
hint: "--db-url-stdin or DATABASE_URL"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
commands: [
|
|
93
|
+
"rls generate",
|
|
94
|
+
"powersync generate",
|
|
95
|
+
"openapi emit"
|
|
96
|
+
],
|
|
97
|
+
from: "--from",
|
|
98
|
+
to: "--policy"
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
/** The rename that matches `flag` (as typed, before any `=`) on `command`. */
|
|
102
|
+
function flagRename(command, flag) {
|
|
103
|
+
return FLAG_RENAMES.find((rename) => rename.from === flag && rename.commands.includes(command));
|
|
104
|
+
}
|
|
105
|
+
function renameMessage(command, rename) {
|
|
106
|
+
return `${command}: ${rename.from} is ${rename.hint ?? rename.to} since 0.5.0.`;
|
|
107
|
+
}
|
|
108
|
+
// src/cli/codemod/cli-calls.ts
|
|
109
|
+
/**
|
|
110
|
+
* `permdock`, `npx permdock@0.4`, `pnpm exec permdock`: the bin name followed
|
|
111
|
+
* by a space.
|
|
112
|
+
*/
|
|
113
|
+
const INVOCATION = /(?<![\w./@-])permdock(?:@[\w.^~-]+)?(?=[ \t])/gu;
|
|
114
|
+
/**
|
|
115
|
+
* Where a shell command ends: an operator, a pipe, a redirect, a comment or a
|
|
116
|
+
* closing backtick. A JSON string also ends at its closing quote. `<id>` is a
|
|
117
|
+
* placeholder, not a redirect, so a redirect needs a space on both sides.
|
|
118
|
+
*/
|
|
119
|
+
function commandEnd(text, from, json) {
|
|
120
|
+
const match = (json ? /&&|\|\||[;|`)\n"]|(?<=\s)\d?[<>]{1,2}(?:&\d|\s)|\s#/u : /&&|\|\||[;|`)\n]|(?<=\s)\d?[<>]{1,2}(?:&\d|\s)|\s#/u).exec(text.slice(from));
|
|
121
|
+
return match === null ? text.length : from + match.index;
|
|
122
|
+
}
|
|
123
|
+
function tokensOf(text, start, end) {
|
|
124
|
+
return [...text.slice(start, end).matchAll(/\S+/gu)].map((match) => ({
|
|
125
|
+
start: start + match.index,
|
|
126
|
+
end: start + match.index + match[0].length,
|
|
127
|
+
text: match[0]
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
function lineColumn(text, offset) {
|
|
131
|
+
const before = text.slice(0, offset);
|
|
132
|
+
return {
|
|
133
|
+
line: before.split("\n").length,
|
|
134
|
+
column: offset - before.lastIndexOf("\n")
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The leaf path the positional tokens name, with the token after which a moved
|
|
139
|
+
* subcommand goes.
|
|
140
|
+
*/
|
|
141
|
+
const REMOVED_COMMANDS = [
|
|
142
|
+
{
|
|
143
|
+
from: ["rls", "generate"],
|
|
144
|
+
command: "rls generate",
|
|
145
|
+
to: "generate --only rls"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
from: [
|
|
149
|
+
"supabase",
|
|
150
|
+
"hook",
|
|
151
|
+
"generate"
|
|
152
|
+
],
|
|
153
|
+
command: "supabase hook generate",
|
|
154
|
+
to: "generate --only supabaseHook"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
from: ["powersync", "generate"],
|
|
158
|
+
command: "powersync generate",
|
|
159
|
+
to: "generate --only powersync"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
from: ["scim", "generate"],
|
|
163
|
+
command: "scim generate",
|
|
164
|
+
to: "generate --only scim"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
from: ["openapi", "emit"],
|
|
168
|
+
command: "openapi emit",
|
|
169
|
+
to: "generate --only openapi"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
from: ["gen"],
|
|
173
|
+
command: "gen",
|
|
174
|
+
to: "generate"
|
|
175
|
+
}
|
|
176
|
+
];
|
|
177
|
+
function removedCommand(tokens) {
|
|
178
|
+
const words = tokens.filter((token) => !token.text.startsWith("-"));
|
|
179
|
+
for (const item of REMOVED_COMMANDS) {
|
|
180
|
+
const matched = item.from.every((name, index) => words[index]?.text === name);
|
|
181
|
+
const first = words[0];
|
|
182
|
+
const last = words[item.from.length - 1];
|
|
183
|
+
if (matched && first !== void 0 && last !== void 0) return {
|
|
184
|
+
command: item.command,
|
|
185
|
+
start: first.start,
|
|
186
|
+
end: last.end,
|
|
187
|
+
to: item.to,
|
|
188
|
+
from: item.from.join(" ")
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function commandOf(tokens) {
|
|
193
|
+
let node = ROOT;
|
|
194
|
+
const path = [];
|
|
195
|
+
for (const token of tokens) {
|
|
196
|
+
if (token.text.startsWith("-")) continue;
|
|
197
|
+
const child = node.children.find((item) => item.name === token.text);
|
|
198
|
+
if (child === void 0) break;
|
|
199
|
+
path.push(child.name);
|
|
200
|
+
if (child.kind === "leaf") return path.join(" ");
|
|
201
|
+
node = child;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const GENERATE_FLAGS = new Set(flagSpellings({
|
|
205
|
+
...GLOBAL_FLAGS,
|
|
206
|
+
...checkFlag,
|
|
207
|
+
...dryRunFlag,
|
|
208
|
+
...policyFlag,
|
|
209
|
+
...dbUrlFlags,
|
|
210
|
+
...generateFlags
|
|
211
|
+
}));
|
|
212
|
+
function flagEdits(command, tokens, notes, removed) {
|
|
213
|
+
const edits = [];
|
|
214
|
+
for (const token of tokens) {
|
|
215
|
+
if (!token.text.startsWith("--")) continue;
|
|
216
|
+
const eq = token.text.indexOf("=");
|
|
217
|
+
const name = eq === -1 ? token.text : token.text.slice(0, eq);
|
|
218
|
+
const rename = flagRename(command, name);
|
|
219
|
+
if (removed && !GENERATE_FLAGS.has(rename?.to ?? name)) {
|
|
220
|
+
notes.push({
|
|
221
|
+
at: token.start,
|
|
222
|
+
message: `${command}: permdock generate takes no ${name}; move it onto the plugin in permdock.config.ts and drop it from the call.`
|
|
223
|
+
});
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (rename === void 0) continue;
|
|
227
|
+
const edit = flagEdit(rename, token, eq);
|
|
228
|
+
if (edit === void 0) notes.push({
|
|
229
|
+
at: token.start,
|
|
230
|
+
message: renameMessage(command, rename)
|
|
231
|
+
});
|
|
232
|
+
else edits.push(...edit);
|
|
233
|
+
}
|
|
234
|
+
return edits;
|
|
235
|
+
}
|
|
236
|
+
function flagEdit(rename, token, eq) {
|
|
237
|
+
if (rename.hint !== void 0) return;
|
|
238
|
+
const value = eq === -1 ? "" : token.text.slice(eq);
|
|
239
|
+
return [{
|
|
240
|
+
start: token.start,
|
|
241
|
+
end: token.end,
|
|
242
|
+
text: `${rename.to}${value}`,
|
|
243
|
+
from: token.text
|
|
244
|
+
}];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Rewrites the 0.5.0 CLI renames in shell commands: package.json scripts, CI
|
|
248
|
+
* workflows, shell scripts. A rename that needs a person, such as an
|
|
249
|
+
* environment name that must become a project id, is a follow-up instead.
|
|
250
|
+
*/
|
|
251
|
+
function rewriteCliCalls(text, options) {
|
|
252
|
+
const edits = [];
|
|
253
|
+
const notes = [];
|
|
254
|
+
for (const match of text.matchAll(INVOCATION)) {
|
|
255
|
+
const start = match.index + match[0].length;
|
|
256
|
+
const tokens = tokensOf(text, start, commandEnd(text, start, options.json));
|
|
257
|
+
const removed = removedCommand(tokens);
|
|
258
|
+
const command = commandOf(tokens);
|
|
259
|
+
const named = removed?.command ?? command;
|
|
260
|
+
if (named === void 0) continue;
|
|
261
|
+
if (removed !== void 0) edits.push({
|
|
262
|
+
start: removed.start,
|
|
263
|
+
end: removed.end,
|
|
264
|
+
text: removed.to,
|
|
265
|
+
from: removed.from
|
|
266
|
+
});
|
|
267
|
+
edits.push(...flagEdits(named, tokens, notes, removed !== void 0));
|
|
268
|
+
}
|
|
269
|
+
const changes = [];
|
|
270
|
+
let out = text;
|
|
271
|
+
for (const edit of edits.toSorted((a, b) => b.start - a.start)) {
|
|
272
|
+
out = `${out.slice(0, edit.start)}${edit.text}${out.slice(edit.end)}`;
|
|
273
|
+
changes.push({
|
|
274
|
+
...lineColumn(text, edit.start),
|
|
275
|
+
from: edit.from,
|
|
276
|
+
to: edit.text
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
text: out,
|
|
281
|
+
changes: changes.toReversed(),
|
|
282
|
+
followUps: notes.map((note) => {
|
|
283
|
+
const { line, column } = lineColumn(text, note.at);
|
|
284
|
+
return {
|
|
285
|
+
line,
|
|
286
|
+
column,
|
|
287
|
+
name: "cli",
|
|
288
|
+
message: note.message
|
|
289
|
+
};
|
|
290
|
+
})
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
// src/cli/codemod/ast.ts
|
|
294
|
+
function nameOf(node) {
|
|
295
|
+
if (node?.type === "Literal") return typeof node.value === "string" ? node.value : void 0;
|
|
296
|
+
return node?.name;
|
|
297
|
+
}
|
|
298
|
+
const NOT_REFERENCES = /* @__PURE__ */ new Set([
|
|
299
|
+
"ImportSpecifier",
|
|
300
|
+
"ImportDefaultSpecifier",
|
|
301
|
+
"ImportNamespaceSpecifier",
|
|
302
|
+
"LabeledStatement",
|
|
303
|
+
"BreakStatement",
|
|
304
|
+
"ContinueStatement",
|
|
305
|
+
"TSEnumMember",
|
|
306
|
+
"TSModuleDeclaration",
|
|
307
|
+
"TSTypeParameter"
|
|
308
|
+
]);
|
|
309
|
+
const KEYED_MEMBERS = /* @__PURE__ */ new Set([
|
|
310
|
+
"MethodDefinition",
|
|
311
|
+
"PropertyDefinition",
|
|
312
|
+
"AccessorProperty",
|
|
313
|
+
"TSPropertySignature",
|
|
314
|
+
"TSMethodSignature",
|
|
315
|
+
"TSAbstractMethodDefinition",
|
|
316
|
+
"TSAbstractPropertyDefinition"
|
|
317
|
+
]);
|
|
318
|
+
/**
|
|
319
|
+
* How an identifier is read: a plain reference, a shorthand property value, the
|
|
320
|
+
* local of an `export { }`, or not a reference.
|
|
321
|
+
*/
|
|
322
|
+
function referencePlace(node, parent, ancestors) {
|
|
323
|
+
const type = parent.type;
|
|
324
|
+
if (node.type === "JSXIdentifier") return type === "JSXOpeningElement" || type === "JSXClosingElement" || type === "JSXMemberExpression" && parent.object === node ? "reference" : "none";
|
|
325
|
+
if (type === "Property") {
|
|
326
|
+
if (ancestors.at(-2)?.type === "ObjectPattern") return "none";
|
|
327
|
+
if (parent.shorthand === true) return parent.value === node ? "shorthand" : "none";
|
|
328
|
+
return parent.key === node && parent.computed !== true ? "none" : "reference";
|
|
329
|
+
}
|
|
330
|
+
if (type === "MemberExpression" || KEYED_MEMBERS.has(type)) return (type === "MemberExpression" ? parent.property : parent.key) === node && parent.computed !== true ? "none" : "reference";
|
|
331
|
+
if (type === "ExportSpecifier") {
|
|
332
|
+
const reexport = ancestors.at(-2)?.source !== null;
|
|
333
|
+
return parent.local === node && !reexport ? "export" : "none";
|
|
334
|
+
}
|
|
335
|
+
if (type === "TSQualifiedName") return parent.right === node ? "none" : "reference";
|
|
336
|
+
return NOT_REFERENCES.has(type) ? "none" : "reference";
|
|
337
|
+
}
|
|
338
|
+
function nodes(value) {
|
|
339
|
+
return Array.isArray(value) ? value.filter(isNode) : [];
|
|
340
|
+
}
|
|
341
|
+
function isNode(value) {
|
|
342
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* A child node under a field `Estree` types as something else (`value`, a type
|
|
346
|
+
* parameter's `name`).
|
|
347
|
+
*/
|
|
348
|
+
function child(node, field) {
|
|
349
|
+
const value = Reflect.get(node, field);
|
|
350
|
+
return isNode(value) ? value : void 0;
|
|
351
|
+
}
|
|
352
|
+
function patternNames(pattern, into) {
|
|
353
|
+
if (pattern === null || pattern === void 0) return;
|
|
354
|
+
switch (pattern.type) {
|
|
355
|
+
case "Identifier":
|
|
356
|
+
into.add(pattern.name ?? "");
|
|
357
|
+
return;
|
|
358
|
+
case "ObjectPattern":
|
|
359
|
+
for (const property of nodes(pattern.properties)) patternNames(property.type === "RestElement" ? property.argument : child(property, "value"), into);
|
|
360
|
+
return;
|
|
361
|
+
case "ArrayPattern":
|
|
362
|
+
for (const element of nodes(pattern.elements)) patternNames(element, into);
|
|
363
|
+
return;
|
|
364
|
+
default: patternNames(pattern.left ?? pattern.argument ?? pattern.parameter, into);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const DECLARATIONS_WITH_ID = /* @__PURE__ */ new Set([
|
|
368
|
+
"FunctionDeclaration",
|
|
369
|
+
"ClassDeclaration",
|
|
370
|
+
"TSEnumDeclaration",
|
|
371
|
+
"TSTypeAliasDeclaration",
|
|
372
|
+
"TSInterfaceDeclaration",
|
|
373
|
+
"TSModuleDeclaration",
|
|
374
|
+
"TSImportEqualsDeclaration",
|
|
375
|
+
"TSDeclareFunction"
|
|
376
|
+
]);
|
|
377
|
+
function declareStatement(statement, into) {
|
|
378
|
+
const type = statement.type;
|
|
379
|
+
if (type === "VariableDeclaration") for (const declarator of nodes(statement.declarations)) patternNames(declarator.id, into);
|
|
380
|
+
else if (DECLARATIONS_WITH_ID.has(type)) patternNames(statement.id, into);
|
|
381
|
+
else if (statement.declaration !== null && statement.declaration !== void 0) declareStatement(statement.declaration, into);
|
|
382
|
+
else if (type === "ImportDeclaration") for (const spec of nodes(statement.specifiers)) patternNames(spec.local, into);
|
|
383
|
+
}
|
|
384
|
+
const BLOCK_SCOPES = /* @__PURE__ */ new Set([
|
|
385
|
+
"Program",
|
|
386
|
+
"BlockStatement",
|
|
387
|
+
"StaticBlock",
|
|
388
|
+
"TSModuleBlock"
|
|
389
|
+
]);
|
|
390
|
+
const FUNCTION_SCOPES = /* @__PURE__ */ new Set([
|
|
391
|
+
"FunctionDeclaration",
|
|
392
|
+
"FunctionExpression",
|
|
393
|
+
"ArrowFunctionExpression",
|
|
394
|
+
"TSDeclareFunction"
|
|
395
|
+
]);
|
|
396
|
+
/**
|
|
397
|
+
* The names a node declares for the code inside it; `undefined` for a node that
|
|
398
|
+
* opens no scope.
|
|
399
|
+
*/
|
|
400
|
+
function scopeBindings(node) {
|
|
401
|
+
const names = /* @__PURE__ */ new Set();
|
|
402
|
+
const declare = (statements) => {
|
|
403
|
+
for (const statement of statements) if (statement !== null && statement !== void 0) declareStatement(statement, names);
|
|
404
|
+
};
|
|
405
|
+
const type = node.type;
|
|
406
|
+
let opens = true;
|
|
407
|
+
if (BLOCK_SCOPES.has(type)) declare(nodes(node.body));
|
|
408
|
+
else if (FUNCTION_SCOPES.has(type)) {
|
|
409
|
+
for (const param of nodes(node.params)) patternNames(param, names);
|
|
410
|
+
patternNames(type === "FunctionExpression" ? node.id : void 0, names);
|
|
411
|
+
} else if (type === "ClassExpression") patternNames(node.id, names);
|
|
412
|
+
else if (type === "ForStatement") declare([node.init]);
|
|
413
|
+
else if (type === "ForInStatement" || type === "ForOfStatement") declare([node.left]);
|
|
414
|
+
else if (type === "CatchClause") patternNames(node.param, names);
|
|
415
|
+
else if (type === "SwitchStatement") declare(nodes(node.cases).flatMap((branch) => nodes(branch.consequent)));
|
|
416
|
+
else if (type === "TSMappedType") patternNames(node.key, names);
|
|
417
|
+
else opens = false;
|
|
418
|
+
for (const param of nodes(node.typeParameters?.params)) {
|
|
419
|
+
opens = true;
|
|
420
|
+
patternNames(child(param, "name"), names);
|
|
421
|
+
}
|
|
422
|
+
return opens ? names : void 0;
|
|
423
|
+
}
|
|
424
|
+
function bindingsCached(node, cache) {
|
|
425
|
+
let found = cache.get(node);
|
|
426
|
+
if (found === void 0) {
|
|
427
|
+
found = scopeBindings(node) ?? null;
|
|
428
|
+
cache.set(node, found);
|
|
429
|
+
}
|
|
430
|
+
return found;
|
|
431
|
+
}
|
|
432
|
+
function applyEdits(source, edits) {
|
|
433
|
+
let out = source;
|
|
434
|
+
for (const item of edits.toSorted((a, b) => b.start - a.start || b.end - a.end)) out = out.slice(0, item.start) + item.text + out.slice(item.end);
|
|
435
|
+
return out;
|
|
436
|
+
}
|
|
437
|
+
function position(lineAt, index) {
|
|
438
|
+
const { line, lineStart } = lineAt(index);
|
|
439
|
+
return {
|
|
440
|
+
line,
|
|
441
|
+
column: index - lineStart + 1
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function lineIndex(source) {
|
|
445
|
+
const starts = [0];
|
|
446
|
+
for (let i = 0; i < source.length; i += 1) if (source.charCodeAt(i) === 10) starts.push(i + 1);
|
|
447
|
+
return (index) => {
|
|
448
|
+
let low = 0;
|
|
449
|
+
let high = starts.length - 1;
|
|
450
|
+
while (low < high) {
|
|
451
|
+
const mid = low + high + 1 >> 1;
|
|
452
|
+
if ((starts[mid] ?? 0) <= index) low = mid;
|
|
453
|
+
else high = mid - 1;
|
|
454
|
+
}
|
|
455
|
+
return {
|
|
456
|
+
line: low + 1,
|
|
457
|
+
lineStart: starts[low] ?? 0
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Every node in source order with its parent and ancestors: Oxc nodes carry no
|
|
463
|
+
* parent, so enter and exit keep a stack.
|
|
464
|
+
*/
|
|
465
|
+
function walk(program, visit) {
|
|
466
|
+
const stack = [];
|
|
467
|
+
const handlers = {};
|
|
468
|
+
for (const type of visitorKeyTypes()) {
|
|
469
|
+
handlers[type] = (node) => {
|
|
470
|
+
visit(node, stack.at(-1), stack);
|
|
471
|
+
stack.push(node);
|
|
472
|
+
};
|
|
473
|
+
handlers[`${type}:exit`] = () => {
|
|
474
|
+
stack.pop();
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
createVisitor(handlers).visit(program);
|
|
478
|
+
}
|
|
479
|
+
// src/cli/codemod/config-moves.ts
|
|
480
|
+
/** Passes over one file before the codemod stops; each pass moves one key. */
|
|
481
|
+
const MAX_PASSES = 500;
|
|
482
|
+
function unwrap(node) {
|
|
483
|
+
if (node?.type === "TSSatisfiesExpression" || node?.type === "TSAsExpression" || node?.type === "ParenthesizedExpression") return unwrap(child(node, "expression"));
|
|
484
|
+
if (node?.type === "CallExpression" && nameOf(node.callee) === "defineConfig") return unwrap(node.arguments?.[0]);
|
|
485
|
+
return node;
|
|
486
|
+
}
|
|
487
|
+
function configRoots(program, file) {
|
|
488
|
+
const roots = [];
|
|
489
|
+
const isConfigFile = basename(file).startsWith("permdock.config.");
|
|
490
|
+
walk(program, (node) => {
|
|
491
|
+
const root = node.type === "CallExpression" && nameOf(node.callee) === "defineConfig" ? unwrap(node) : node.type === "ExportDefaultDeclaration" && isConfigFile ? unwrap(node.declaration) : void 0;
|
|
492
|
+
if (root?.type === "ObjectExpression" && !roots.includes(root)) roots.push(root);
|
|
493
|
+
});
|
|
494
|
+
return roots;
|
|
495
|
+
}
|
|
496
|
+
function keyOf(property) {
|
|
497
|
+
return property.type === "Property" && property.computed !== true ? nameOf(property.key) : void 0;
|
|
498
|
+
}
|
|
499
|
+
function propertyOf(object, key) {
|
|
500
|
+
return nodes(object.properties).find((property) => keyOf(property) === key);
|
|
501
|
+
}
|
|
502
|
+
function objectValue(property) {
|
|
503
|
+
const value = child(property, "value");
|
|
504
|
+
return value?.type === "ObjectExpression" ? value : void 0;
|
|
505
|
+
}
|
|
506
|
+
/** The first property at `move.from` under `object`, with the concrete paths. */
|
|
507
|
+
function find(object, move, depth, path, skipped) {
|
|
508
|
+
const segment = move.from[depth];
|
|
509
|
+
if (segment === void 0) return;
|
|
510
|
+
const keys = segment === "*" ? nodes(object.properties).flatMap((property) => {
|
|
511
|
+
const key = keyOf(property);
|
|
512
|
+
return key === void 0 ? [] : [key];
|
|
513
|
+
}) : [segment];
|
|
514
|
+
for (const key of keys) {
|
|
515
|
+
const property = propertyOf(object, key);
|
|
516
|
+
if (property === void 0) continue;
|
|
517
|
+
const at = [...path, key];
|
|
518
|
+
if (depth === move.from.length - 1) {
|
|
519
|
+
if (skipped.has(property.start)) continue;
|
|
520
|
+
return {
|
|
521
|
+
parent: object,
|
|
522
|
+
property,
|
|
523
|
+
path: at
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
const next = objectValue(property);
|
|
527
|
+
const found = next === void 0 ? void 0 : find(next, move, depth + 1, at, skipped);
|
|
528
|
+
if (found !== void 0) return found;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/** `move.to` with each `*` replaced by the key `from` matched there. */
|
|
532
|
+
function concreteTarget(move, path) {
|
|
533
|
+
return move.to.map((segment, index) => segment === "*" ? path[index] ?? segment : segment);
|
|
534
|
+
}
|
|
535
|
+
function removal(source, parent, property) {
|
|
536
|
+
const siblings = nodes(parent.properties);
|
|
537
|
+
const index = siblings.indexOf(property);
|
|
538
|
+
const next = siblings[index + 1];
|
|
539
|
+
if (next !== void 0) return {
|
|
540
|
+
start: property.start,
|
|
541
|
+
end: next.start,
|
|
542
|
+
text: ""
|
|
543
|
+
};
|
|
544
|
+
const previous = siblings[index - 1];
|
|
545
|
+
const end = /^\s*,/u.exec(source.slice(property.end))?.[0].length ?? 0;
|
|
546
|
+
return previous === void 0 ? {
|
|
547
|
+
start: property.start,
|
|
548
|
+
end: property.end + end,
|
|
549
|
+
text: ""
|
|
550
|
+
} : {
|
|
551
|
+
start: previous.end,
|
|
552
|
+
end: property.end,
|
|
553
|
+
text: ""
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
/** Adds `text` as the last property of `object`, so moved keys keep their order. */
|
|
557
|
+
function append(source, object, text) {
|
|
558
|
+
const last = nodes(object.properties).at(-1);
|
|
559
|
+
if (last === void 0) return {
|
|
560
|
+
start: object.start + 1,
|
|
561
|
+
end: object.start + 1,
|
|
562
|
+
text: ` ${text} `
|
|
563
|
+
};
|
|
564
|
+
const comma = /^\s*,/u.exec(source.slice(last.end))?.[0].length;
|
|
565
|
+
return comma === void 0 ? {
|
|
566
|
+
start: last.end,
|
|
567
|
+
end: last.end,
|
|
568
|
+
text: `, ${text}`
|
|
569
|
+
} : {
|
|
570
|
+
start: last.end + comma,
|
|
571
|
+
end: last.end + comma,
|
|
572
|
+
text: ` ${text},`
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
function nested(keys, value) {
|
|
576
|
+
const [first, ...rest] = keys;
|
|
577
|
+
return rest.length === 0 ? `${first}: ${value}` : `${first}: { ${nested(rest, value)} }`;
|
|
578
|
+
}
|
|
579
|
+
function step(source, found, to) {
|
|
580
|
+
const relative = to.slice(found.path.length - 1);
|
|
581
|
+
const value = child(found.property, "value");
|
|
582
|
+
const text = value === void 0 ? "" : source.slice(value.start, value.end);
|
|
583
|
+
const from = found.path.join(".");
|
|
584
|
+
const target = to.join(".");
|
|
585
|
+
let object = found.parent;
|
|
586
|
+
for (const [index, key] of relative.entries()) {
|
|
587
|
+
const existing = propertyOf(object, key);
|
|
588
|
+
const last = index === relative.length - 1;
|
|
589
|
+
if (existing === void 0) {
|
|
590
|
+
const insert = nested(relative.slice(index), text);
|
|
591
|
+
return {
|
|
592
|
+
kind: "edits",
|
|
593
|
+
at: found.property.start,
|
|
594
|
+
from,
|
|
595
|
+
to: target,
|
|
596
|
+
edits: object === found.parent ? [{
|
|
597
|
+
start: found.property.start,
|
|
598
|
+
end: found.property.end,
|
|
599
|
+
text: insert
|
|
600
|
+
}] : [removal(source, found.parent, found.property), append(source, object, insert)]
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
const next = objectValue(existing);
|
|
604
|
+
if (last || next === void 0) return {
|
|
605
|
+
kind: "conflict",
|
|
606
|
+
at: found.property.start,
|
|
607
|
+
message: `${from} moved to ${target}, which ${last ? "is already set" : "is not an object literal"}; merge it by hand`
|
|
608
|
+
};
|
|
609
|
+
object = next;
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
kind: "conflict",
|
|
613
|
+
at: found.property.start,
|
|
614
|
+
message: `${from} moved to ${target}; move it by hand`
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* The first move that applies under any config root. A move that conflicts is
|
|
619
|
+
* skipped from then on and reported once in `followUps`.
|
|
620
|
+
*/
|
|
621
|
+
function nextEdits(program, file, source, moves, skipped, followUps) {
|
|
622
|
+
for (const root of configRoots(program, file)) for (const move of moves) {
|
|
623
|
+
const found = find(root, move, 0, [], skipped);
|
|
624
|
+
if (found === void 0) continue;
|
|
625
|
+
const result = step(source, found, concreteTarget(move, found.path));
|
|
626
|
+
if (result.kind === "edits") return result;
|
|
627
|
+
skipped.add(found.property.start);
|
|
628
|
+
if (!followUps.some((item) => item.message === result.message)) followUps.push({
|
|
629
|
+
...position(lineIndex(source), result.at),
|
|
630
|
+
name: found.path.join("."),
|
|
631
|
+
message: result.message
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Moves each key `moves` names to its new path, one key per pass, until no move
|
|
637
|
+
* applies. A key whose target is already set, or sits under a value that is not
|
|
638
|
+
* an object literal, is reported instead.
|
|
639
|
+
*/
|
|
640
|
+
function moveConfigKeys(file, original, moves) {
|
|
641
|
+
let source = original;
|
|
642
|
+
const lineAt = lineIndex(original);
|
|
643
|
+
const changes = [];
|
|
644
|
+
const followUps = [];
|
|
645
|
+
const skipped = /* @__PURE__ */ new Set();
|
|
646
|
+
for (let pass = 0; pass < MAX_PASSES; pass += 1) {
|
|
647
|
+
const parsed = parseSync(file, source, { sourceType: "module" });
|
|
648
|
+
if (parsed.errors.length > 0) break;
|
|
649
|
+
const program = parsed.program;
|
|
650
|
+
const applied = nextEdits(program, file, source, moves, skipped, followUps);
|
|
651
|
+
if (applied === void 0) break;
|
|
652
|
+
changes.push({
|
|
653
|
+
...position(lineAt, Math.min(applied.at, original.length)),
|
|
654
|
+
from: applied.from,
|
|
655
|
+
to: applied.to
|
|
656
|
+
});
|
|
657
|
+
source = applyEdits(source, applied.edits);
|
|
658
|
+
}
|
|
659
|
+
return {
|
|
660
|
+
source,
|
|
661
|
+
changes,
|
|
662
|
+
followUps
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
// src/cli/codemod/rewrite-0.26.ts
|
|
666
|
+
const ROW_CALL = /\bpermitted_([a-z][a-z0-9_]*)_row\s*\(/gu;
|
|
667
|
+
const TEXT_BEFORE_HELPER = /::text(?=\s+in\s*\(\s*select\b[^)]{0,120}\b(?:permitted_|can_|member_|permdock_))/gu;
|
|
668
|
+
const TEXT_AFTER_HELPER = /(\b(?:permitted_|can_|member_|permdock_)[a-z0-9_]*\s*\([^;]{0,200}?\))::text/gu;
|
|
669
|
+
const OWN_SUBJECT = /\bown_subject\s*\(\s*\)/gu;
|
|
670
|
+
const TABLE_OF = /(^[ \t]*)([A-Za-z_][A-Za-z0-9_]*)\s*:\s*\{\s*tableOf\s*:\s*(['"])([A-Za-z_][A-Za-z0-9_]*)\3\s*\},?[ \t]*\r?\n/gmu;
|
|
671
|
+
const VERB_PREFIX = /^(read|list|get|create|duplicate|update|delete|remove|approve|reject|cancel|send|withdraw|confirm|fulfill|receive|reimburse|writeOff|mark|pause|resume)(?=[A-Z0-9_-])/u;
|
|
672
|
+
const ACTION_LINE = /^([ \t]*)([A-Za-z_][A-Za-z0-9_]*)\s*:\s*(['"])(select|insert|update|delete)\3,?[ \t]*\r?\n/gmu;
|
|
673
|
+
const PROPERTY = (key) => new RegExp(String.raw`(?<![A-Za-z0-9_])${key}\s*:`, "gu");
|
|
674
|
+
function change(from, to) {
|
|
675
|
+
return {
|
|
676
|
+
line: 1,
|
|
677
|
+
column: 0,
|
|
678
|
+
from,
|
|
679
|
+
to
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
function rewriteSql(source) {
|
|
683
|
+
const changes = [];
|
|
684
|
+
let text = source;
|
|
685
|
+
if (text.match(ROW_CALL) !== null) {
|
|
686
|
+
text = text.replaceAll(ROW_CALL, "can_$1(");
|
|
687
|
+
changes.push(change("permitted_<resource>_row(", "can_<resource>("));
|
|
688
|
+
}
|
|
689
|
+
if (TEXT_BEFORE_HELPER.test(text) || TEXT_AFTER_HELPER.test(text)) {
|
|
690
|
+
TEXT_BEFORE_HELPER.lastIndex = 0;
|
|
691
|
+
TEXT_AFTER_HELPER.lastIndex = 0;
|
|
692
|
+
text = text.replaceAll(TEXT_BEFORE_HELPER, "").replaceAll(TEXT_AFTER_HELPER, "$1");
|
|
693
|
+
changes.push(change("::text", ""));
|
|
694
|
+
}
|
|
695
|
+
if (OWN_SUBJECT.test(text)) {
|
|
696
|
+
OWN_SUBJECT.lastIndex = 0;
|
|
697
|
+
text = text.replaceAll(OWN_SUBJECT, "");
|
|
698
|
+
changes.push(change("own_subject()", ""));
|
|
699
|
+
}
|
|
700
|
+
return {
|
|
701
|
+
text,
|
|
702
|
+
changes
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function ownerProperty(source, owner) {
|
|
706
|
+
return new RegExp(String.raw`(^[ \t]*)${owner}\s*:\s*(\{[^}\n]*\}|(['"])[^'"\n]*\3),?`, "mu").exec(source);
|
|
707
|
+
}
|
|
708
|
+
function withAlso(property, child, owner) {
|
|
709
|
+
const stringValue = new RegExp(String.raw`^([ \t]*)${owner}\s*:\s*(['"])([^'"\n]*)\2,?$`, "u").exec(property);
|
|
710
|
+
if (stringValue !== null) {
|
|
711
|
+
const indent = stringValue[1] ?? "";
|
|
712
|
+
const quote = stringValue[2] ?? "\"";
|
|
713
|
+
return `${indent}${owner}: { table: ${quote}${stringValue[3] ?? ""}${quote}, also: [${quote}${child}${quote}] },`;
|
|
714
|
+
}
|
|
715
|
+
if (property.includes("also:")) return property.replace(/also\s*:\s*\[([^\]]*)\]/u, (_match, list) => {
|
|
716
|
+
const quote = property.includes("'") ? "'" : "\"";
|
|
717
|
+
const item = `${quote}${child}${quote}`;
|
|
718
|
+
const body = list.trim();
|
|
719
|
+
return `also: [${body === "" ? item : `${body}, ${item}`}]`;
|
|
720
|
+
});
|
|
721
|
+
return property.replace(/\{\s*/u, (brace) => `${brace}also: ["${child}"], `);
|
|
722
|
+
}
|
|
723
|
+
function stringEnd(source, open) {
|
|
724
|
+
const quote = source[open];
|
|
725
|
+
for (let index = open + 1; index < source.length; index += 1) {
|
|
726
|
+
if (source[index] === "\\") {
|
|
727
|
+
index += 1;
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
if (source[index] === quote) return index;
|
|
731
|
+
}
|
|
732
|
+
return source.length - 1;
|
|
733
|
+
}
|
|
734
|
+
function matchingClose(source, open) {
|
|
735
|
+
const closeOf = {
|
|
736
|
+
"{": "}",
|
|
737
|
+
"[": "]",
|
|
738
|
+
"(": ")"
|
|
739
|
+
};
|
|
740
|
+
const stack = [closeOf[source[open] ?? ""] ?? ""];
|
|
741
|
+
for (let index = open + 1; index < source.length; index += 1) {
|
|
742
|
+
const char = source[index] ?? "";
|
|
743
|
+
if (char === "\"" || char === "'" || char === "`") {
|
|
744
|
+
index = stringEnd(source, index);
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
if (char === "{" || char === "[" || char === "(") {
|
|
748
|
+
stack.push(closeOf[char] ?? "");
|
|
749
|
+
continue;
|
|
750
|
+
}
|
|
751
|
+
if (char === stack.at(-1)) {
|
|
752
|
+
stack.pop();
|
|
753
|
+
if (stack.length === 0) return index;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return source.length - 1;
|
|
757
|
+
}
|
|
758
|
+
function inferredOf(action) {
|
|
759
|
+
const exact = defaultSqlCommand(action);
|
|
760
|
+
if (exact !== void 0) return exact;
|
|
761
|
+
const verb = VERB_PREFIX.exec(action)?.[1];
|
|
762
|
+
if (verb === void 0) return;
|
|
763
|
+
if (verb === "mark" || verb === "pause" || verb === "resume") return "update";
|
|
764
|
+
return defaultSqlCommand(verb);
|
|
765
|
+
}
|
|
766
|
+
function withoutInferred(body) {
|
|
767
|
+
const dropped = [];
|
|
768
|
+
return {
|
|
769
|
+
text: body.replaceAll(ACTION_LINE, (line, _indent, name, _quote, value) => {
|
|
770
|
+
if (inferredOf(String(name)) !== value) return line;
|
|
771
|
+
dropped.push(`${String(name)}: "${String(value)}"`);
|
|
772
|
+
return "";
|
|
773
|
+
}),
|
|
774
|
+
dropped
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
function dropInferredActions(source) {
|
|
778
|
+
const pattern = /\bactions\s*:\s*\{/gu;
|
|
779
|
+
let text = source;
|
|
780
|
+
let cursor = 0;
|
|
781
|
+
const dropped = [];
|
|
782
|
+
while (cursor < text.length) {
|
|
783
|
+
pattern.lastIndex = cursor;
|
|
784
|
+
const match = pattern.exec(text);
|
|
785
|
+
if (match === null) break;
|
|
786
|
+
const open = text.indexOf("{", match.index);
|
|
787
|
+
const close = matchingClose(text, open);
|
|
788
|
+
const next = withoutInferred(text.slice(open + 1, close));
|
|
789
|
+
if (next.dropped.length === 0) {
|
|
790
|
+
cursor = close + 1;
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
dropped.push(...next.dropped);
|
|
794
|
+
text = text.slice(0, open + 1) + next.text + text.slice(close);
|
|
795
|
+
cursor = open + 1;
|
|
796
|
+
}
|
|
797
|
+
return {
|
|
798
|
+
text,
|
|
799
|
+
dropped
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
function insidePermissions(source, index) {
|
|
803
|
+
let depth = 0;
|
|
804
|
+
for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
|
|
805
|
+
const char = source[cursor];
|
|
806
|
+
if (char === "}") depth += 1;
|
|
807
|
+
else if (char === "{") {
|
|
808
|
+
if (depth === 0) return /permissions\s*:\s*$/u.test(source.slice(0, cursor));
|
|
809
|
+
depth -= 1;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
function suppliedFollowUps(file, source) {
|
|
815
|
+
const followUps = [];
|
|
816
|
+
const keep = (name, message) => {
|
|
817
|
+
followUps.push({
|
|
818
|
+
line: 1,
|
|
819
|
+
column: 0,
|
|
820
|
+
name,
|
|
821
|
+
message: `${file}: ${message}`
|
|
822
|
+
});
|
|
823
|
+
};
|
|
824
|
+
if (PROPERTY("roleThrough").test(source)) keep("roleThrough", "roleThrough is kept: the provider supplies it only for a membership source whose role reads through that table; delete it when permdock doctor reports it as PD094");
|
|
825
|
+
const disabled = PROPERTY("disabled");
|
|
826
|
+
for (let match = disabled.exec(source); match !== null; match = disabled.exec(source)) if (insidePermissions(source, match.index)) {
|
|
827
|
+
keep("permissions.disabled", "blocks.permissions.disabled is kept: the provider fills it from rls.suspension only under blocks.permissions.model \"provider\", and only for an unset subject; delete it when permdock doctor reports it as PD094");
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
if (PROPERTY("canAssign").test(source) && source.includes("permdock_can_assign_any")) keep("canAssign", "canAssign naming permdock_can_assign_any is kept: the provider fills platformRoles.canAssign only for its own tenant scope, and another scope or a through.where narrows it; delete it when permdock doctor reports it as PD094");
|
|
831
|
+
return followUps;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* 0.26 text rewrites: `permitted_<resource>_row(` becomes `can_<resource>(`,
|
|
835
|
+
* `::text` around a helper call is removed, `own_subject()` is deleted, and `{
|
|
836
|
+
* tableOf }` moves onto the owner's `also` list. Inferred `rls.actions` entries
|
|
837
|
+
* are dropped. In a `better-supabase.config.*` file, `roleThrough`,
|
|
838
|
+
* `permissions.disabled` and a `canAssign` that names `permdock_can_assign_any`
|
|
839
|
+
* become follow-ups, because the provider supplies them only in some setups and
|
|
840
|
+
* PD094 decides whether a value equals the provider's.
|
|
841
|
+
*/
|
|
842
|
+
/** Old `permdock gen` file names (without extension) to the 0.26 names. */
|
|
843
|
+
const GEN_FILES = {
|
|
844
|
+
generated: "constants",
|
|
845
|
+
zod: "zod",
|
|
846
|
+
valibot: "valibot",
|
|
847
|
+
arktype: "arktype",
|
|
848
|
+
factories: "factories",
|
|
849
|
+
react: "react",
|
|
850
|
+
vue: "vue",
|
|
851
|
+
solid: "solid",
|
|
852
|
+
"svelte-stores": "svelte",
|
|
853
|
+
messages: "messages"
|
|
854
|
+
};
|
|
855
|
+
const GEN_IMPORT = /(\bfrom\s*(['"]))((?:[^'"\n]*\/)?)permdock\.(generated|zod|valibot|arktype|factories|react|vue|solid|svelte-stores|schemas|messages)(\.[a-z]+)?\2/gu;
|
|
856
|
+
/**
|
|
857
|
+
* An import of a generated file under its 0.25 name moves to the new name:
|
|
858
|
+
* `permdock.generated.ts` is `constants.ts`, `permdock.schemas.ts` is
|
|
859
|
+
* `standard-schema.ts` and `permdock.schemas.json` is `json-schema.json`.
|
|
860
|
+
*/
|
|
861
|
+
function rewriteGenImports(source) {
|
|
862
|
+
const changes = [];
|
|
863
|
+
return {
|
|
864
|
+
text: source.replaceAll(GEN_IMPORT, (_whole, head, quote, dir, name, ext = "") => {
|
|
865
|
+
const next = name === "schemas" ? ext === ".json" ? "json-schema" : "standard-schema" : GEN_FILES[name] ?? name;
|
|
866
|
+
changes.push(change(`permdock.${name}${ext}`, `${next}${ext}`));
|
|
867
|
+
return `${head}${dir}${next}${ext}${quote}`;
|
|
868
|
+
}),
|
|
869
|
+
changes
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
function rewrite026(file, source) {
|
|
873
|
+
const sql = rewriteSql(source);
|
|
874
|
+
const followUps = [];
|
|
875
|
+
let text = sql.text;
|
|
876
|
+
const found = [...text.matchAll(TABLE_OF)];
|
|
877
|
+
for (const match of found) {
|
|
878
|
+
const child = match[2] ?? "";
|
|
879
|
+
const owner = match[4] ?? "";
|
|
880
|
+
text = text.replaceAll(match[0], "");
|
|
881
|
+
const property = ownerProperty(text, owner);
|
|
882
|
+
if (property === null) {
|
|
883
|
+
followUps.push({
|
|
884
|
+
line: 1,
|
|
885
|
+
column: 0,
|
|
886
|
+
name: "tableOf",
|
|
887
|
+
message: `${file}: rls.tables.${child}.tableOf names ${owner}, which this file does not declare as a property the codemod can extend`
|
|
888
|
+
});
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
text = text.replaceAll(property[0], withAlso(property[0], child, owner));
|
|
892
|
+
}
|
|
893
|
+
const gen = rewriteGenImports(text);
|
|
894
|
+
text = gen.text;
|
|
895
|
+
const changes = [...sql.changes, ...gen.changes];
|
|
896
|
+
if (gen.changes.length > 0) followUps.push({
|
|
897
|
+
line: 1,
|
|
898
|
+
column: 0,
|
|
899
|
+
name: "gen",
|
|
900
|
+
message: `${file}: the generated files moved; rename topics.<x> to <x>Topic, paths.<x> to <x>Path, sqlNames.* to the per-helper exports in sql.ts, factories.<x> to <x>Factory, and scopes and roles to scopeNames and roleNames`
|
|
901
|
+
});
|
|
902
|
+
if (found.length > 0) changes.push(change("tableOf", "also"));
|
|
903
|
+
const actions = dropInferredActions(text);
|
|
904
|
+
text = actions.text;
|
|
905
|
+
for (const entry of actions.dropped) changes.push(change(`rls.actions ${entry}`, "inferred"));
|
|
906
|
+
if (file.includes("better-supabase.config.")) followUps.push(...suppliedFollowUps(file, text));
|
|
907
|
+
return {
|
|
908
|
+
source: text,
|
|
909
|
+
changes,
|
|
910
|
+
followUps
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
// src/cli/codemod/shapes-0.17.ts
|
|
914
|
+
const COMBINATORS = /* @__PURE__ */ new Set([
|
|
915
|
+
"any",
|
|
916
|
+
"all",
|
|
917
|
+
"sequential"
|
|
918
|
+
]);
|
|
919
|
+
/** The keys a 0.16 membership literal may carry. */
|
|
920
|
+
const MEMBERSHIP_KEYS = /* @__PURE__ */ new Set([
|
|
921
|
+
"tenant",
|
|
922
|
+
"team",
|
|
923
|
+
"roles",
|
|
924
|
+
"eligible",
|
|
925
|
+
"via",
|
|
926
|
+
"expiresAt",
|
|
927
|
+
"grantedBy",
|
|
928
|
+
"reason",
|
|
929
|
+
"member",
|
|
930
|
+
"managedBy",
|
|
931
|
+
"entitlements",
|
|
932
|
+
"keep",
|
|
933
|
+
"x"
|
|
934
|
+
]);
|
|
935
|
+
function keyed(object) {
|
|
936
|
+
const out = [];
|
|
937
|
+
for (const property of object.properties) {
|
|
938
|
+
if (property.type !== "Property" || property.computed) continue;
|
|
939
|
+
const { key } = property;
|
|
940
|
+
if (key.type === "Identifier") out.push({
|
|
941
|
+
key: key.name,
|
|
942
|
+
property
|
|
943
|
+
});
|
|
944
|
+
else if (key.type === "Literal" && typeof key.value === "string") out.push({
|
|
945
|
+
key: key.value,
|
|
946
|
+
property
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
return out;
|
|
950
|
+
}
|
|
951
|
+
function stringLiteral(property) {
|
|
952
|
+
const { value } = property;
|
|
953
|
+
return value.type === "Literal" && typeof value.value === "string" ? value.value : void 0;
|
|
954
|
+
}
|
|
955
|
+
function langOf(file) {
|
|
956
|
+
if (file.endsWith(".tsx")) return "tsx";
|
|
957
|
+
if (file.endsWith(".jsx")) return "jsx";
|
|
958
|
+
return /\.[cm]?ts$/u.test(file) ? "ts" : "js";
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* The span of `property` with the comma after it, or the comma before it when
|
|
962
|
+
* it is the last property, so removing the span leaves the object well formed.
|
|
963
|
+
*/
|
|
964
|
+
function withComma(source, property) {
|
|
965
|
+
const after = /^\s*,\s*/u.exec(source.slice(property.end));
|
|
966
|
+
if (after !== null) return {
|
|
967
|
+
start: property.start,
|
|
968
|
+
end: property.end + after[0].length
|
|
969
|
+
};
|
|
970
|
+
const before = /,\s*$/u.exec(source.slice(0, property.start));
|
|
971
|
+
return {
|
|
972
|
+
start: property.start - (before?.[0].length ?? 0),
|
|
973
|
+
end: property.end
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* 0.17's object-literal rewrites:
|
|
978
|
+
*
|
|
979
|
+
* - A membership `{ tenant, team?, roles }` becomes `{ scope, id, within? }`
|
|
980
|
+
* under the `tenant` and `team` scope aliases. Only an object whose keys are
|
|
981
|
+
* all membership fields counts, so credentials, events and principals that
|
|
982
|
+
* carry `tenant` and `roles` stay as they are.
|
|
983
|
+
* - An approval option's `mode: 'any' | 'all' | 'sequential'` becomes `combine`,
|
|
984
|
+
* `distinct: false` becomes `mode: 'confirm'`, and `distinct: true` (the
|
|
985
|
+
* default) goes.
|
|
986
|
+
*
|
|
987
|
+
* A `distinct` that is not a literal and every `ApprovalMode` type reference
|
|
988
|
+
* are follow-ups.
|
|
989
|
+
*/
|
|
990
|
+
function rewriteLiterals017(file, source) {
|
|
991
|
+
let parsed;
|
|
992
|
+
try {
|
|
993
|
+
parsed = parseSync(file, source, {
|
|
994
|
+
lang: langOf(file),
|
|
995
|
+
sourceType: "module"
|
|
996
|
+
});
|
|
997
|
+
} catch (error) {
|
|
998
|
+
if (error instanceof CliError) throw error;
|
|
999
|
+
return {
|
|
1000
|
+
source,
|
|
1001
|
+
changes: [],
|
|
1002
|
+
followUps: []
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
if (parsed.errors.length > 0) return {
|
|
1006
|
+
source,
|
|
1007
|
+
changes: [],
|
|
1008
|
+
followUps: []
|
|
1009
|
+
};
|
|
1010
|
+
const lineAt = lineIndex(source);
|
|
1011
|
+
const edits = [];
|
|
1012
|
+
const changes = [];
|
|
1013
|
+
const followUps = [];
|
|
1014
|
+
const text = (node) => source.slice(node.start, node.end);
|
|
1015
|
+
const change = (at, from, to) => {
|
|
1016
|
+
changes.push({
|
|
1017
|
+
...position(lineAt, at),
|
|
1018
|
+
from,
|
|
1019
|
+
to
|
|
1020
|
+
});
|
|
1021
|
+
};
|
|
1022
|
+
const membership = (node, props) => {
|
|
1023
|
+
const keys = new Set(props.map((item) => item.key));
|
|
1024
|
+
if (props.length !== node.properties.length || !keys.has("roles") || !keys.has("tenant") && !keys.has("team") || [...keys].some((key) => !MEMBERSHIP_KEYS.has(key))) return;
|
|
1025
|
+
const tenant = props.find((item) => item.key === "tenant")?.property;
|
|
1026
|
+
const team = props.find((item) => item.key === "team")?.property;
|
|
1027
|
+
if ([tenant, team].some((item) => item?.value.type === "ObjectExpression" || item?.value.type === "ArrayExpression")) return;
|
|
1028
|
+
if (team === void 0 && tenant !== void 0) {
|
|
1029
|
+
const to = `scope: "tenant", id: ${text(tenant.value)}`;
|
|
1030
|
+
edits.push({
|
|
1031
|
+
start: tenant.start,
|
|
1032
|
+
end: tenant.end,
|
|
1033
|
+
text: to
|
|
1034
|
+
});
|
|
1035
|
+
change(tenant.start, text(tenant), to);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
if (team !== void 0) {
|
|
1039
|
+
const to = `scope: "team", id: ${text(team.value)}`;
|
|
1040
|
+
edits.push({
|
|
1041
|
+
start: team.start,
|
|
1042
|
+
end: team.end,
|
|
1043
|
+
text: to
|
|
1044
|
+
});
|
|
1045
|
+
change(team.start, text(team), to);
|
|
1046
|
+
}
|
|
1047
|
+
if (tenant !== void 0) {
|
|
1048
|
+
const value = text(tenant.value);
|
|
1049
|
+
const to = `within: { ${value === "tenant" ? value : `tenant: ${value}`} }`;
|
|
1050
|
+
edits.push({
|
|
1051
|
+
start: tenant.start,
|
|
1052
|
+
end: tenant.end,
|
|
1053
|
+
text: to
|
|
1054
|
+
});
|
|
1055
|
+
change(tenant.start, text(tenant), to);
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
const approval = (props) => {
|
|
1059
|
+
const keys = new Set(props.map((item) => item.key));
|
|
1060
|
+
if (!keys.has("by") && !keys.has("stages")) return;
|
|
1061
|
+
const mode = props.find((item) => item.key === "mode")?.property;
|
|
1062
|
+
const value = mode === void 0 ? void 0 : stringLiteral(mode);
|
|
1063
|
+
if (mode !== void 0 && value !== void 0 && COMBINATORS.has(value)) {
|
|
1064
|
+
edits.push({
|
|
1065
|
+
start: mode.key.start,
|
|
1066
|
+
end: mode.key.end,
|
|
1067
|
+
text: "combine"
|
|
1068
|
+
});
|
|
1069
|
+
change(mode.start, text(mode), `combine: ${text(mode.value)}`);
|
|
1070
|
+
}
|
|
1071
|
+
const distinct = props.find((item) => item.key === "distinct")?.property;
|
|
1072
|
+
if (distinct === void 0) return;
|
|
1073
|
+
const literal = distinct.value;
|
|
1074
|
+
if (literal.type === "Literal" && literal.value === false) {
|
|
1075
|
+
edits.push({
|
|
1076
|
+
start: distinct.start,
|
|
1077
|
+
end: distinct.end,
|
|
1078
|
+
text: "mode: \"confirm\""
|
|
1079
|
+
});
|
|
1080
|
+
change(distinct.start, text(distinct), "mode: \"confirm\"");
|
|
1081
|
+
} else if (literal.type === "Literal" && literal.value === true) {
|
|
1082
|
+
edits.push({
|
|
1083
|
+
...withComma(source, distinct),
|
|
1084
|
+
text: ""
|
|
1085
|
+
});
|
|
1086
|
+
change(distinct.start, text(distinct), "(removed: authorize is the default)");
|
|
1087
|
+
} else followUps.push({
|
|
1088
|
+
...position(lineAt, distinct.start),
|
|
1089
|
+
name: "distinct",
|
|
1090
|
+
message: "distinct is gone since 0.17.0: `mode: \"confirm\"` where it was false; drop it where it was true"
|
|
1091
|
+
});
|
|
1092
|
+
};
|
|
1093
|
+
createVisitor({
|
|
1094
|
+
ObjectExpression(node) {
|
|
1095
|
+
const props = keyed(node);
|
|
1096
|
+
membership(node, props);
|
|
1097
|
+
approval(props);
|
|
1098
|
+
},
|
|
1099
|
+
TSTypeReference(node) {
|
|
1100
|
+
if (node.typeName.type === "Identifier" && node.typeName.name === "ApprovalMode") followUps.push({
|
|
1101
|
+
...position(lineAt, node.start),
|
|
1102
|
+
name: "ApprovalMode",
|
|
1103
|
+
message: "ApprovalMode is `'confirm' | 'authorize'` since 0.17.0; the stage combinator type is ApprovalCombine"
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
}).visit(parsed.program);
|
|
1107
|
+
return {
|
|
1108
|
+
source: applyEdits(source, edits),
|
|
1109
|
+
changes,
|
|
1110
|
+
followUps
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
// src/cli/codemod/context.ts
|
|
1114
|
+
/** One version's rename map: what the codemod rewrites and what it only reports. */
|
|
1115
|
+
const SCRIPT_BLOCK = /<script\b([^>]*)>([\s\S]*?)<\/script>/gu;
|
|
1116
|
+
function isPermDockSpecifier(value) {
|
|
1117
|
+
return typeof value === "string" && (value === "permdock" || value.startsWith("permdock/"));
|
|
1118
|
+
}
|
|
1119
|
+
function declaredBetween(ctx, name, ancestors) {
|
|
1120
|
+
return ancestors.some((scope) => scope !== ctx.program && bindingsCached(scope, ctx.scopes)?.has(name) === true);
|
|
1121
|
+
}
|
|
1122
|
+
function isModuleBinding(ctx, name, ancestors) {
|
|
1123
|
+
return ctx.moduleNames.has(name) && !declaredBetween(ctx, name, ancestors);
|
|
1124
|
+
}
|
|
1125
|
+
function edit(ctx, node, text, from, to) {
|
|
1126
|
+
if (ctx.edits.some((item) => item.start === node.start && item.end === node.end)) return;
|
|
1127
|
+
ctx.edits.push({
|
|
1128
|
+
start: node.start,
|
|
1129
|
+
end: node.end,
|
|
1130
|
+
text
|
|
1131
|
+
});
|
|
1132
|
+
ctx.changes.push({
|
|
1133
|
+
at: node.start,
|
|
1134
|
+
from,
|
|
1135
|
+
to
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
function replace(ctx, node, text, from) {
|
|
1139
|
+
edit(ctx, node, text, from, beforeFirst(text, " as "));
|
|
1140
|
+
}
|
|
1141
|
+
function renameOf(set, name, entry) {
|
|
1142
|
+
return set.renames.find((row) => row.from === name && row.kind !== "option" && row.kind !== "method" && row.entries.includes(entry));
|
|
1143
|
+
}
|
|
1144
|
+
function listOf(items) {
|
|
1145
|
+
return new Intl.ListFormat("en-GB", { type: "disjunction" }).format(items);
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* The import a call's callee is bound to: a named import, or a member of a
|
|
1149
|
+
* namespace import.
|
|
1150
|
+
*/
|
|
1151
|
+
function importedCallee(ctx, callee, ancestors) {
|
|
1152
|
+
if (callee?.type === "Identifier") {
|
|
1153
|
+
const name = callee.name ?? "";
|
|
1154
|
+
return isModuleBinding(ctx, name, ancestors) ? ctx.bindings.get(name) : void 0;
|
|
1155
|
+
}
|
|
1156
|
+
const object = callee?.type === "MemberExpression" && callee.computed !== true ? callee.object : void 0;
|
|
1157
|
+
const namespace = object?.type === "Identifier" && isModuleBinding(ctx, object.name ?? "", ancestors) ? ctx.namespaces.get(object.name ?? "") : void 0;
|
|
1158
|
+
const imported = callee?.property?.name;
|
|
1159
|
+
return namespace === void 0 || imported === void 0 ? void 0 : {
|
|
1160
|
+
entry: namespace,
|
|
1161
|
+
imported
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
function renameKey(ctx, property, from, to) {
|
|
1165
|
+
const key = property.key;
|
|
1166
|
+
if (property.type !== "Property" || key === void 0 || property.computed === true) return;
|
|
1167
|
+
ctx.handledKeys.add(key);
|
|
1168
|
+
if (property.shorthand === true) edit(ctx, {
|
|
1169
|
+
...property,
|
|
1170
|
+
end: property.start
|
|
1171
|
+
}, `${to}: `, from, to);
|
|
1172
|
+
else replace(ctx, key, key.type === "Literal" ? JSON.stringify(to) : to, from);
|
|
1173
|
+
}
|
|
1174
|
+
function renameKeys(ctx, object, from, to) {
|
|
1175
|
+
for (const property of nodes(object.properties)) if (nameOf(property.key) === from) renameKey(ctx, property, from, to);
|
|
1176
|
+
}
|
|
1177
|
+
function boundImport(ctx, node, ancestors) {
|
|
1178
|
+
const name = node?.name;
|
|
1179
|
+
return (node?.type === "Identifier" || node?.type === "JSXIdentifier") && name !== void 0 && isModuleBinding(ctx, name, ancestors) ? ctx.bindings.get(name) : void 0;
|
|
1180
|
+
}
|
|
1181
|
+
// src/cli/codemod/imports.ts
|
|
1182
|
+
function removableBindings(ctx) {
|
|
1183
|
+
const out = /* @__PURE__ */ new Set();
|
|
1184
|
+
if (ctx.keepLocals) return out;
|
|
1185
|
+
for (const local of ctx.bindings.keys()) {
|
|
1186
|
+
const references = ctx.references.filter((item) => item.node.name === local);
|
|
1187
|
+
if (references.length > 0 && references.every((item) => ctx.consumed.has(item.node.start))) out.add(local);
|
|
1188
|
+
}
|
|
1189
|
+
return out;
|
|
1190
|
+
}
|
|
1191
|
+
function importedLocal(ctx, name, entry, ancestors) {
|
|
1192
|
+
for (const [local, binding] of ctx.bindings) if (binding.entry === entry && binding.imported === name && !typeOnly(binding) && !declaredBetween(ctx, local, ancestors)) return local;
|
|
1193
|
+
if (ctx.moduleNames.has(name) || declaredBetween(ctx, name, ancestors)) return;
|
|
1194
|
+
const names = ctx.additions.get(entry) ?? /* @__PURE__ */ new Set();
|
|
1195
|
+
names.add(name);
|
|
1196
|
+
ctx.additions.set(entry, names);
|
|
1197
|
+
return name;
|
|
1198
|
+
}
|
|
1199
|
+
function typeOnly(binding) {
|
|
1200
|
+
return Reflect.get(binding.declaration, "importKind") === "type" || Reflect.get(binding.spec, "importKind") === "type";
|
|
1201
|
+
}
|
|
1202
|
+
function finishImports(ctx, removed) {
|
|
1203
|
+
const gone = /* @__PURE__ */ new Set();
|
|
1204
|
+
for (const local of removed) {
|
|
1205
|
+
const spec = ctx.bindings.get(local)?.spec;
|
|
1206
|
+
if (spec !== void 0) gone.add(spec);
|
|
1207
|
+
}
|
|
1208
|
+
const pending = new Map(ctx.additions);
|
|
1209
|
+
for (const declaration of nodes(ctx.program.body)) {
|
|
1210
|
+
const all = nodes(declaration.specifiers);
|
|
1211
|
+
if (declaration.type !== "ImportDeclaration" || !all.some((spec) => gone.has(spec))) continue;
|
|
1212
|
+
if (all.some((spec) => spec.type !== "ImportSpecifier")) {
|
|
1213
|
+
for (const spec of all) gone.delete(spec);
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
if (all.some((spec) => !gone.has(spec))) {
|
|
1217
|
+
removeSpecifiers(ctx, all, gone);
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
const entry = String(declaration.source?.value);
|
|
1221
|
+
const names = Reflect.get(declaration, "importKind") === "type" ? void 0 : pending.get(entry);
|
|
1222
|
+
if (names === void 0) ctx.edits.push({
|
|
1223
|
+
start: declaration.start,
|
|
1224
|
+
end: lineEnd(ctx.code, declaration.end),
|
|
1225
|
+
text: ""
|
|
1226
|
+
});
|
|
1227
|
+
else {
|
|
1228
|
+
pending.delete(entry);
|
|
1229
|
+
ctx.edits.push({
|
|
1230
|
+
start: declaration.start,
|
|
1231
|
+
end: declaration.end,
|
|
1232
|
+
text: importText(ctx, entry, names)
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
for (const [entry, names] of pending) addImport(ctx, entry, names, gone);
|
|
1237
|
+
}
|
|
1238
|
+
function lineEnd(code, end) {
|
|
1239
|
+
return code[end] === "\n" ? end + 1 : end;
|
|
1240
|
+
}
|
|
1241
|
+
function importText(ctx, entry, names) {
|
|
1242
|
+
const source = nodes(ctx.program.body).map((statement) => statement.source).find((node) => isPermDockSpecifier(node?.value));
|
|
1243
|
+
const mark = ctx.code[source?.start ?? -1] ?? "\"";
|
|
1244
|
+
return `import { ${[...names].join(", ")} } from ${mark}${entry}${mark};`;
|
|
1245
|
+
}
|
|
1246
|
+
function removeSpecifiers(ctx, all, gone) {
|
|
1247
|
+
const last = all.findLastIndex((spec) => !gone.has(spec));
|
|
1248
|
+
for (const [index, spec] of all.entries()) {
|
|
1249
|
+
const next = all[index + 1];
|
|
1250
|
+
if (gone.has(spec) && index < last && next !== void 0) ctx.edits.push({
|
|
1251
|
+
start: spec.start,
|
|
1252
|
+
end: next.start,
|
|
1253
|
+
text: ""
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
const survivor = all[last];
|
|
1257
|
+
const tail = all.at(-1);
|
|
1258
|
+
if (survivor !== void 0 && tail !== void 0 && tail !== survivor) ctx.edits.push({
|
|
1259
|
+
start: survivor.end,
|
|
1260
|
+
end: tail.end,
|
|
1261
|
+
text: ""
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
function addImport(ctx, entry, names, gone) {
|
|
1265
|
+
const statements = nodes(ctx.program.body);
|
|
1266
|
+
const anchor = statements.filter((statement) => statement.type === "ImportDeclaration" && statement.source?.value === entry && Reflect.get(statement, "importKind") !== "type").flatMap((statement) => nodes(statement.specifiers)).findLast((spec) => spec.type === "ImportSpecifier" && !gone.has(spec));
|
|
1267
|
+
if (anchor !== void 0) {
|
|
1268
|
+
ctx.edits.push({
|
|
1269
|
+
start: anchor.end,
|
|
1270
|
+
end: anchor.end,
|
|
1271
|
+
text: `, ${[...names].join(", ")}`
|
|
1272
|
+
});
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
const lastImport = statements.findLast((statement) => statement.type === "ImportDeclaration");
|
|
1276
|
+
const at = lastImport?.end ?? 0;
|
|
1277
|
+
const text = importText(ctx, entry, names);
|
|
1278
|
+
ctx.edits.push({
|
|
1279
|
+
start: at,
|
|
1280
|
+
end: at,
|
|
1281
|
+
text: lastImport === void 0 ? `${text}\n` : `\n${text}`
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
// src/cli/codemod/shapes.ts
|
|
1285
|
+
function templateHints(file, source, set, components, lineAt) {
|
|
1286
|
+
const hints = (set.templates ?? []).filter((hint) => hint.entries.some((entry) => components.has(`${entry} ${hint.component}`)));
|
|
1287
|
+
if (hints.length === 0 || !/\.(?:vue|svelte)$/iu.test(file)) return [];
|
|
1288
|
+
const markup = source.replaceAll(SCRIPT_BLOCK, (block) => " ".repeat(block.length));
|
|
1289
|
+
return hints.flatMap((hint) => [...markup.matchAll(hint.pattern)].map((match) => {
|
|
1290
|
+
const { line, column } = position(lineAt, match.index);
|
|
1291
|
+
return {
|
|
1292
|
+
line,
|
|
1293
|
+
column,
|
|
1294
|
+
name: hint.name,
|
|
1295
|
+
message: hint.message
|
|
1296
|
+
};
|
|
1297
|
+
}));
|
|
1298
|
+
}
|
|
1299
|
+
function awaitRow(ctx, callee) {
|
|
1300
|
+
return (ctx.set.awaits ?? []).find((row) => callee !== void 0 && row.name === callee.imported && row.entries.includes(callee.entry));
|
|
1301
|
+
}
|
|
1302
|
+
function visitAwait(ctx, node, ancestors) {
|
|
1303
|
+
const call = node.argument;
|
|
1304
|
+
if (call?.type !== "CallExpression" || call.callee === void 0) return;
|
|
1305
|
+
const callee = importedCallee(ctx, call.callee, ancestors);
|
|
1306
|
+
const row = awaitRow(ctx, callee);
|
|
1307
|
+
if (row === void 0 || callee === void 0) return;
|
|
1308
|
+
swapCallee(ctx, call.callee, row.name, row.to, callee.entry, ancestors);
|
|
1309
|
+
}
|
|
1310
|
+
function swapCallee(ctx, callee, from, to, entry, ancestors) {
|
|
1311
|
+
if (callee.type === "MemberExpression" && callee.property !== void 0) {
|
|
1312
|
+
replace(ctx, callee.property, to, from);
|
|
1313
|
+
return true;
|
|
1314
|
+
}
|
|
1315
|
+
const local = importedLocal(ctx, to, entry, ancestors);
|
|
1316
|
+
if (local === void 0) {
|
|
1317
|
+
ctx.followUps.push({
|
|
1318
|
+
at: callee.start,
|
|
1319
|
+
name: from,
|
|
1320
|
+
message: `\`${from}\` is \`${to}\` from \`${entry}\` here; \`${to}\` is already bound in this scope`
|
|
1321
|
+
});
|
|
1322
|
+
return false;
|
|
1323
|
+
}
|
|
1324
|
+
ctx.consumed.add(callee.start);
|
|
1325
|
+
edit(ctx, callee, local, from, to);
|
|
1326
|
+
return true;
|
|
1327
|
+
}
|
|
1328
|
+
function reportUnawaited(ctx, node, ancestors, row) {
|
|
1329
|
+
const parent = ancestors.at(-1);
|
|
1330
|
+
if (parent?.type === "ReturnStatement" || parent?.type === "ArrowFunctionExpression" && parent.body === node || parent?.type === "MemberExpression" && parent.object === node && parent.property?.name === "then") ctx.followUps.push({
|
|
1331
|
+
at: node.start,
|
|
1332
|
+
name: row.name,
|
|
1333
|
+
message: `\`${row.name}\` without \`await\` is \`${row.sync}\`, which returns the instance, never a Promise; call \`${row.to}\` when a source answers asynchronously`
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
function propRows(ctx, binding) {
|
|
1337
|
+
return binding === void 0 ? [] : (ctx.set.props ?? []).filter((row) => row.component === binding.imported && row.entries.includes(binding.entry));
|
|
1338
|
+
}
|
|
1339
|
+
function visitElement(ctx, node, ancestors) {
|
|
1340
|
+
const tag = child(node, "name");
|
|
1341
|
+
const binding = boundImport(ctx, tag, ancestors);
|
|
1342
|
+
const rows = propRows(ctx, binding);
|
|
1343
|
+
const named = tag?.type === "JSXMemberExpression" ? child(tag, "property") : tag;
|
|
1344
|
+
const unbound = (ctx.set.props ?? []).filter((row) => binding === void 0 && row.within !== void 0 && named?.type === "JSXIdentifier" && named.name === row.component);
|
|
1345
|
+
for (const attribute of nodes(Reflect.get(node, "attributes"))) {
|
|
1346
|
+
const name = child(attribute, "name");
|
|
1347
|
+
if (attribute.type !== "JSXAttribute" || name?.type !== "JSXIdentifier") continue;
|
|
1348
|
+
for (const row of rows) if (row.within === void 0 && name.name === row.from) replace(ctx, name, row.to, row.from);
|
|
1349
|
+
else if (row.within !== void 0 && name.name === row.within) renameWithin(ctx, attribute, row);
|
|
1350
|
+
for (const row of unbound) if (name.name === row.within && holdsKey(attribute, row.from)) ctx.followUps.push({
|
|
1351
|
+
at: attribute.start,
|
|
1352
|
+
name: row.from,
|
|
1353
|
+
message: `\`${row.within}.${row.from}\` of \`<${row.component}>\` is \`${row.within}.${row.to}\``
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
function attributeObject(attribute) {
|
|
1358
|
+
const value = child(attribute, "value");
|
|
1359
|
+
const expression = value?.type === "JSXExpressionContainer" ? child(value, "expression") : void 0;
|
|
1360
|
+
return expression?.type === "ObjectExpression" ? expression : void 0;
|
|
1361
|
+
}
|
|
1362
|
+
function holdsKey(attribute, key) {
|
|
1363
|
+
const object = attributeObject(attribute);
|
|
1364
|
+
return object === void 0 || nodes(object.properties).some((property) => nameOf(property.key) === key);
|
|
1365
|
+
}
|
|
1366
|
+
function renameWithin(ctx, attribute, row) {
|
|
1367
|
+
const object = attributeObject(attribute);
|
|
1368
|
+
if (object === void 0) {
|
|
1369
|
+
ctx.followUps.push({
|
|
1370
|
+
at: attribute.start,
|
|
1371
|
+
name: row.from,
|
|
1372
|
+
message: `\`${row.within}.${row.from}\` of \`<${row.component}>\` is \`${row.within}.${row.to}\``
|
|
1373
|
+
});
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
renameKeys(ctx, object, row.from, row.to);
|
|
1377
|
+
}
|
|
1378
|
+
function visitComponentArguments(ctx, node, ancestors) {
|
|
1379
|
+
const args = nodes(node.arguments);
|
|
1380
|
+
for (const [index, argument] of args.entries()) {
|
|
1381
|
+
const rows = propRows(ctx, boundImport(ctx, argument, ancestors)).filter((row) => row.within === void 0);
|
|
1382
|
+
for (const row of rows) for (const later of args.slice(index + 1)) if (later.type === "ObjectExpression") renameKeys(ctx, later, row.from, row.to);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
function methodRow(ctx, node, ancestors) {
|
|
1386
|
+
const callee = node.callee;
|
|
1387
|
+
const receiver = callee?.object;
|
|
1388
|
+
const method = callee?.property?.name;
|
|
1389
|
+
const first = nodes(node.arguments)[0];
|
|
1390
|
+
return (ctx.set.methodFunctions ?? []).find((row) => callee?.type === "MemberExpression" && callee.computed !== true && row.method === method && (row.argument === void 0 || first?.type === "ObjectExpression" && nodes(first.properties).some((property) => nameOf(property.key) === row.argument)) && (row.anyReceiver || holdsInstance(ctx, receiver, ancestors)));
|
|
1391
|
+
}
|
|
1392
|
+
function holdsInstance(ctx, receiver, ancestors) {
|
|
1393
|
+
const name = receiver?.type === "Identifier" ? receiver.name : void 0;
|
|
1394
|
+
if (name === void 0) return false;
|
|
1395
|
+
return /permdock/iu.test(name) || isModuleBinding(ctx, name, ancestors) && ctx.factories.has(name);
|
|
1396
|
+
}
|
|
1397
|
+
function visitMethodCall(ctx, node, ancestors) {
|
|
1398
|
+
const row = node.type === "CallExpression" ? methodRow(ctx, node, ancestors) : void 0;
|
|
1399
|
+
const receiver = node.callee?.object;
|
|
1400
|
+
if (row === void 0 || receiver === void 0) return;
|
|
1401
|
+
const name = receiver.type === "Identifier" ? receiver.name : void 0;
|
|
1402
|
+
if (name !== void 0 && ctx.namespaces.has(name)) return;
|
|
1403
|
+
const open = ctx.code.indexOf("(", receiver.end);
|
|
1404
|
+
const between = ctx.code.slice(receiver.end, open);
|
|
1405
|
+
if (Reflect.get(node, "optional") === true || Reflect.get(node.callee ?? node, "optional") === true || receiver.type === "SequenceExpression" || !/^\s*\.\s*\w+\s*$/u.test(between)) {
|
|
1406
|
+
ctx.followUps.push({
|
|
1407
|
+
at: node.start,
|
|
1408
|
+
name: row.method,
|
|
1409
|
+
message: `\`permdock.${row.method}(…)\` is \`${row.to}(permdock, …)\` from \`${row.entry}\``
|
|
1410
|
+
});
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
const local = importedLocal(ctx, row.to, row.entry, ancestors);
|
|
1414
|
+
if (local === void 0) {
|
|
1415
|
+
ctx.followUps.push({
|
|
1416
|
+
at: node.start,
|
|
1417
|
+
name: row.method,
|
|
1418
|
+
message: `\`permdock.${row.method}(…)\` is \`${row.to}(permdock, …)\` from \`${row.entry}\`; \`${row.to}\` is already bound in this scope`
|
|
1419
|
+
});
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
const separator = nodes(node.arguments).length === 0 ? "" : ",";
|
|
1423
|
+
const space = /\s/u.test(ctx.code[open + 1] ?? "") ? "" : " ";
|
|
1424
|
+
ctx.edits.push({
|
|
1425
|
+
start: receiver.start,
|
|
1426
|
+
end: receiver.start,
|
|
1427
|
+
text: `${local}(`
|
|
1428
|
+
}, {
|
|
1429
|
+
start: receiver.end,
|
|
1430
|
+
end: open + 1,
|
|
1431
|
+
text: separator === "" ? "" : `${separator}${space}`
|
|
1432
|
+
});
|
|
1433
|
+
ctx.changes.push({
|
|
1434
|
+
at: node.start,
|
|
1435
|
+
from: row.method,
|
|
1436
|
+
to: row.to
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
const PLAIN_RECEIVERS = /* @__PURE__ */ new Set([
|
|
1440
|
+
"Identifier",
|
|
1441
|
+
"MemberExpression",
|
|
1442
|
+
"CallExpression",
|
|
1443
|
+
"ThisExpression"
|
|
1444
|
+
]);
|
|
1445
|
+
function visitFunctionCall(ctx, node, callee) {
|
|
1446
|
+
const row = (ctx.set.functionMethods ?? []).find((item) => item.name === callee.imported && item.entry === callee.entry);
|
|
1447
|
+
const [receiver, next] = nodes(node.arguments);
|
|
1448
|
+
if (row === void 0 || node.type !== "CallExpression" || node.callee === void 0 || receiver === void 0 || receiver.type === "SpreadElement" || Reflect.get(node, "optional") === true) return false;
|
|
1449
|
+
const plain = PLAIN_RECEIVERS.has(receiver.type);
|
|
1450
|
+
ctx.edits.push({
|
|
1451
|
+
start: node.callee.start,
|
|
1452
|
+
end: receiver.start,
|
|
1453
|
+
text: plain ? "" : "("
|
|
1454
|
+
}, {
|
|
1455
|
+
start: receiver.end,
|
|
1456
|
+
end: next?.start ?? node.end - 1,
|
|
1457
|
+
text: `${plain ? "" : ")"}.${row.method}(`
|
|
1458
|
+
});
|
|
1459
|
+
if (node.callee.type === "Identifier") ctx.consumed.add(node.callee.start);
|
|
1460
|
+
ctx.changes.push({
|
|
1461
|
+
at: node.start,
|
|
1462
|
+
from: row.name,
|
|
1463
|
+
to: row.method
|
|
1464
|
+
});
|
|
1465
|
+
return true;
|
|
1466
|
+
}
|
|
1467
|
+
function isWrapped(ctx, row, value, ancestors) {
|
|
1468
|
+
const callee = value?.type === "CallExpression" ? importedCallee(ctx, value.callee, ancestors) : void 0;
|
|
1469
|
+
return callee !== void 0 && callee.entry === row.entry && row.already.includes(callee.imported);
|
|
1470
|
+
}
|
|
1471
|
+
function visitWraps(ctx, node, callee, ancestors) {
|
|
1472
|
+
const rows = (ctx.set.wraps ?? []).filter((row) => row.entries.includes(callee.entry) && row.calls.includes(callee.imported));
|
|
1473
|
+
for (const argument of nodes(node.arguments)) for (const property of argument.type === "ObjectExpression" ? nodes(argument.properties) : []) {
|
|
1474
|
+
const row = rows.find((item) => item.key === nameOf(property.key));
|
|
1475
|
+
if (row !== void 0 && property.computed !== true) wrapOption(ctx, row, property, ancestors);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
function wrapOption(ctx, row, property, ancestors) {
|
|
1479
|
+
const value = child(property, "value");
|
|
1480
|
+
if (property.key !== void 0) ctx.handledKeys.add(property.key);
|
|
1481
|
+
if (value === void 0 || isWrapped(ctx, row, value, ancestors)) return;
|
|
1482
|
+
const local = importedLocal(ctx, row.wrapper, row.entry, ancestors);
|
|
1483
|
+
if (local === void 0 || property.type !== "Property") {
|
|
1484
|
+
ctx.followUps.push({
|
|
1485
|
+
at: property.start,
|
|
1486
|
+
name: row.key,
|
|
1487
|
+
message: `option \`${row.key}\` takes \`${row.wrapper}(source)\` from \`${row.entry}\`; \`${row.wrapper}\` is already bound in this scope`
|
|
1488
|
+
});
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
ctx.edits.push(property.shorthand === true ? {
|
|
1492
|
+
start: property.start,
|
|
1493
|
+
end: property.start,
|
|
1494
|
+
text: `${row.key}: ${local}(`
|
|
1495
|
+
} : {
|
|
1496
|
+
start: value.start,
|
|
1497
|
+
end: value.start,
|
|
1498
|
+
text: `${local}(`
|
|
1499
|
+
}, {
|
|
1500
|
+
start: value.end,
|
|
1501
|
+
end: value.end,
|
|
1502
|
+
text: ")"
|
|
1503
|
+
});
|
|
1504
|
+
ctx.changes.push({
|
|
1505
|
+
at: value.start,
|
|
1506
|
+
from: row.key,
|
|
1507
|
+
to: row.wrapper
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
function reportWraps(ctx, node, ancestors) {
|
|
1511
|
+
for (const property of nodes(node.properties)) {
|
|
1512
|
+
const row = (ctx.set.wraps ?? []).find((item) => item.reportElsewhere && item.key === nameOf(property.key));
|
|
1513
|
+
if (row !== void 0 && property.key !== void 0 && property.computed !== true && !ctx.handledKeys.has(property.key) && !isWrapped(ctx, row, child(property, "value"), ancestors)) ctx.followUps.push({
|
|
1514
|
+
at: property.start,
|
|
1515
|
+
name: row.key,
|
|
1516
|
+
message: `option \`${row.key}\` takes \`${row.wrapper}(source)\` from \`${row.entry}\` when this object reaches \`getPermDock\` or \`getPermDockSync\``
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
const UNIT_SECONDS = Object.freeze({
|
|
1521
|
+
s: 1,
|
|
1522
|
+
m: 60,
|
|
1523
|
+
h: 3600,
|
|
1524
|
+
d: 86400,
|
|
1525
|
+
w: 604800
|
|
1526
|
+
});
|
|
1527
|
+
function seconds(value) {
|
|
1528
|
+
if (value?.type !== "Literal" || typeof value.value !== "string") return;
|
|
1529
|
+
const match = /^\s*(\d+)([smhdw])\s*$/u.exec(value.value);
|
|
1530
|
+
const amount = Number(match?.[1]);
|
|
1531
|
+
const unit = UNIT_SECONDS[match?.[2] ?? ""];
|
|
1532
|
+
return unit === void 0 || !(amount > 0) ? void 0 : amount * unit;
|
|
1533
|
+
}
|
|
1534
|
+
function insidePermDockCall(ctx, object, ancestors) {
|
|
1535
|
+
const chain = [...ancestors, object];
|
|
1536
|
+
return ancestors.some((node, index) => (node.type === "CallExpression" || node.type === "NewExpression") && nodes(node.arguments).includes(chain[index + 1] ?? node) && importedCallee(ctx, node.callee, ancestors.slice(0, index)) !== void 0);
|
|
1537
|
+
}
|
|
1538
|
+
function visitDurations(ctx, node, ancestors) {
|
|
1539
|
+
const keys = ctx.set.durations;
|
|
1540
|
+
if (keys === void 0) return;
|
|
1541
|
+
const rewrite = insidePermDockCall(ctx, node, ancestors);
|
|
1542
|
+
const parent = ancestors.at(-1);
|
|
1543
|
+
if (!rewrite && nodes(parent?.arguments).includes(node)) return;
|
|
1544
|
+
for (const property of nodes(node.properties)) {
|
|
1545
|
+
const key = nameOf(property.key);
|
|
1546
|
+
const value = child(property, "value");
|
|
1547
|
+
const literals = key !== void 0 && keys.keys.includes(key) ? [value] : key !== void 0 && keys.lists.includes(key) && value?.type === "ArrayExpression" ? nodes(value.elements) : [];
|
|
1548
|
+
for (const literal of literals) {
|
|
1549
|
+
const total = seconds(literal);
|
|
1550
|
+
if (literal === void 0 || total === void 0) continue;
|
|
1551
|
+
const text = String(literal.value);
|
|
1552
|
+
if (rewrite) {
|
|
1553
|
+
ctx.edits.push({
|
|
1554
|
+
start: literal.start,
|
|
1555
|
+
end: literal.end,
|
|
1556
|
+
text: String(total)
|
|
1557
|
+
});
|
|
1558
|
+
ctx.changes.push({
|
|
1559
|
+
at: literal.start,
|
|
1560
|
+
from: text,
|
|
1561
|
+
to: String(total)
|
|
1562
|
+
});
|
|
1563
|
+
} else ctx.followUps.push({
|
|
1564
|
+
at: literal.start,
|
|
1565
|
+
name: key ?? text,
|
|
1566
|
+
message: `duration \`"${text}"\` is \`${total}\` (seconds) when this object reaches PermDock`
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
// src/cli/codemod/transform.ts
|
|
1572
|
+
/** Applies `set` to one file's source; `file` picks the parser by extension. */
|
|
1573
|
+
function transformSource(file, source, set) {
|
|
1574
|
+
const lineAt = lineIndex(source);
|
|
1575
|
+
const edits = [];
|
|
1576
|
+
const changes = [];
|
|
1577
|
+
const followUps = [];
|
|
1578
|
+
const components = /* @__PURE__ */ new Set();
|
|
1579
|
+
for (const segment of segmentsOf(file, source)) {
|
|
1580
|
+
const result = parseSync(`segment.${segment.lang}`, segment.code, {
|
|
1581
|
+
lang: segment.lang,
|
|
1582
|
+
sourceType: "module"
|
|
1583
|
+
});
|
|
1584
|
+
const error = result.errors.find((item) => {
|
|
1585
|
+
return item.severity === "Error";
|
|
1586
|
+
});
|
|
1587
|
+
if (error !== void 0) return {
|
|
1588
|
+
source,
|
|
1589
|
+
changes: [],
|
|
1590
|
+
followUps: [],
|
|
1591
|
+
error: error.message
|
|
1592
|
+
};
|
|
1593
|
+
const ctx = contextFor(result.program, set, segment);
|
|
1594
|
+
if (ctx === void 0) continue;
|
|
1595
|
+
transformProgram(ctx, segment);
|
|
1596
|
+
for (const binding of ctx.bindings.values()) components.add(`${binding.entry} ${binding.imported}`);
|
|
1597
|
+
const at = (index) => position(lineAt, index + segment.offset);
|
|
1598
|
+
for (const item of ctx.edits) edits.push({
|
|
1599
|
+
start: item.start + segment.offset,
|
|
1600
|
+
end: item.end + segment.offset,
|
|
1601
|
+
text: item.text
|
|
1602
|
+
});
|
|
1603
|
+
for (const change of ctx.changes) changes.push({
|
|
1604
|
+
...at(change.at),
|
|
1605
|
+
from: change.from,
|
|
1606
|
+
to: change.to
|
|
1607
|
+
});
|
|
1608
|
+
for (const note of ctx.followUps) followUps.push({
|
|
1609
|
+
...at(note.at),
|
|
1610
|
+
name: note.name,
|
|
1611
|
+
message: note.message
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
followUps.push(...templateHints(file, source, set, components, lineAt));
|
|
1615
|
+
return {
|
|
1616
|
+
source: applyEdits(source, edits),
|
|
1617
|
+
changes: changes.toSorted(byPosition),
|
|
1618
|
+
followUps: followUps.toSorted(byPosition)
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
function byPosition(a, b) {
|
|
1622
|
+
return a.line - b.line || a.column - b.column;
|
|
1623
|
+
}
|
|
1624
|
+
function segmentsOf(file, source) {
|
|
1625
|
+
const extension = file.slice(file.lastIndexOf(".") + 1).toLowerCase();
|
|
1626
|
+
if (extension === "vue" || extension === "svelte") return [...source.matchAll(SCRIPT_BLOCK)].map((match) => {
|
|
1627
|
+
const [whole, attributes = "", code = ""] = match;
|
|
1628
|
+
const typed = /\blang=["']?(?:ts|typescript)\b/u.test(attributes);
|
|
1629
|
+
return {
|
|
1630
|
+
code,
|
|
1631
|
+
offset: match.index + whole.indexOf(">") + 1,
|
|
1632
|
+
lang: typed ? "ts" : "jsx",
|
|
1633
|
+
keepLocals: true
|
|
1634
|
+
};
|
|
1635
|
+
});
|
|
1636
|
+
return [{
|
|
1637
|
+
code: source,
|
|
1638
|
+
offset: 0,
|
|
1639
|
+
lang: extension === "tsx" ? "tsx" : [
|
|
1640
|
+
"ts",
|
|
1641
|
+
"mts",
|
|
1642
|
+
"cts"
|
|
1643
|
+
].includes(extension) ? "ts" : "jsx",
|
|
1644
|
+
keepLocals: false
|
|
1645
|
+
}];
|
|
1646
|
+
}
|
|
1647
|
+
/** The module's `permdock` imports, or `undefined` when it has none. */
|
|
1648
|
+
function contextFor(program, set, segment) {
|
|
1649
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
1650
|
+
const namespaces = /* @__PURE__ */ new Map();
|
|
1651
|
+
const entries = /* @__PURE__ */ new Set();
|
|
1652
|
+
for (const statement of nodes(program.body)) {
|
|
1653
|
+
const entry = statement.source?.value;
|
|
1654
|
+
if (!isPermDockSpecifier(entry)) continue;
|
|
1655
|
+
entries.add(entry);
|
|
1656
|
+
if (statement.type !== "ImportDeclaration") continue;
|
|
1657
|
+
for (const spec of nodes(statement.specifiers)) {
|
|
1658
|
+
const local = spec.local?.name ?? "";
|
|
1659
|
+
if (spec.type === "ImportNamespaceSpecifier") namespaces.set(local, entry);
|
|
1660
|
+
const imported = nameOf(spec.imported);
|
|
1661
|
+
if (spec.type === "ImportSpecifier" && imported !== void 0) {
|
|
1662
|
+
const rename = renameOf(set, imported, entry);
|
|
1663
|
+
bindings.set(local, {
|
|
1664
|
+
entry,
|
|
1665
|
+
imported,
|
|
1666
|
+
spec,
|
|
1667
|
+
declaration: statement,
|
|
1668
|
+
rename
|
|
1669
|
+
});
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
if (entries.size === 0) return;
|
|
1674
|
+
const renamedLocals = /* @__PURE__ */ new Map();
|
|
1675
|
+
for (const [local, binding] of bindings) if (binding.rename !== void 0 && local === binding.imported) renamedLocals.set(local, binding.rename);
|
|
1676
|
+
const touches = (row) => row.entries.some((entry) => entries.has(entry));
|
|
1677
|
+
return {
|
|
1678
|
+
program,
|
|
1679
|
+
code: segment.code,
|
|
1680
|
+
keepLocals: segment.keepLocals,
|
|
1681
|
+
consumed: /* @__PURE__ */ new Set(),
|
|
1682
|
+
additions: /* @__PURE__ */ new Map(),
|
|
1683
|
+
set,
|
|
1684
|
+
edits: [],
|
|
1685
|
+
changes: [],
|
|
1686
|
+
followUps: [],
|
|
1687
|
+
bindings,
|
|
1688
|
+
namespaces,
|
|
1689
|
+
moduleNames: scopeBindings(program) ?? /* @__PURE__ */ new Set(),
|
|
1690
|
+
renamedLocals,
|
|
1691
|
+
kept: /* @__PURE__ */ new Set(),
|
|
1692
|
+
references: [],
|
|
1693
|
+
optionRows: set.renames.filter((row) => row.kind === "option" && touches(row)),
|
|
1694
|
+
methodRows: set.renames.filter((row) => row.kind === "method" && touches(row)),
|
|
1695
|
+
factories: factoryValues(program, bindings),
|
|
1696
|
+
handledKeys: /* @__PURE__ */ new Set(),
|
|
1697
|
+
newShapes: /* @__PURE__ */ new Set(),
|
|
1698
|
+
scopes: /* @__PURE__ */ new WeakMap()
|
|
1699
|
+
};
|
|
1700
|
+
}
|
|
1701
|
+
function transformProgram(ctx, segment) {
|
|
1702
|
+
for (const [local, rename] of ctx.renamedLocals) if (segment.keepLocals || ctx.moduleNames.has(rename.to)) ctx.kept.add(local);
|
|
1703
|
+
walk(ctx.program, (node, parent, ancestors) => {
|
|
1704
|
+
switch (node.type) {
|
|
1705
|
+
case "Identifier":
|
|
1706
|
+
case "JSXIdentifier":
|
|
1707
|
+
visitIdentifier(ctx, node, parent, ancestors);
|
|
1708
|
+
break;
|
|
1709
|
+
case "MemberExpression":
|
|
1710
|
+
case "TSQualifiedName":
|
|
1711
|
+
visitMember(ctx, node, ancestors);
|
|
1712
|
+
break;
|
|
1713
|
+
case "ObjectPattern":
|
|
1714
|
+
reportMethods(ctx, propertyKeys(node), "destructured", "comes from");
|
|
1715
|
+
break;
|
|
1716
|
+
case "CallExpression":
|
|
1717
|
+
case "NewExpression":
|
|
1718
|
+
visitCall(ctx, node, ancestors);
|
|
1719
|
+
visitComponentArguments(ctx, node, ancestors);
|
|
1720
|
+
visitMethodCall(ctx, node, ancestors);
|
|
1721
|
+
break;
|
|
1722
|
+
case "JSXOpeningElement":
|
|
1723
|
+
visitElement(ctx, node, ancestors);
|
|
1724
|
+
break;
|
|
1725
|
+
case "AwaitExpression":
|
|
1726
|
+
visitAwait(ctx, node, ancestors);
|
|
1727
|
+
break;
|
|
1728
|
+
case "ObjectExpression":
|
|
1729
|
+
reportOptions(ctx, node, ancestors);
|
|
1730
|
+
reportWraps(ctx, node, ancestors);
|
|
1731
|
+
visitDurations(ctx, node, ancestors);
|
|
1732
|
+
}
|
|
1733
|
+
});
|
|
1734
|
+
const removed = removableBindings(ctx);
|
|
1735
|
+
rewriteImports(ctx, removed);
|
|
1736
|
+
rewriteReferences(ctx);
|
|
1737
|
+
rewriteReexports(ctx);
|
|
1738
|
+
reportUncalledSignatures(ctx, removed);
|
|
1739
|
+
finishImports(ctx, removed);
|
|
1740
|
+
}
|
|
1741
|
+
function visitIdentifier(ctx, node, parent, ancestors) {
|
|
1742
|
+
const name = node.name ?? "";
|
|
1743
|
+
if (parent === void 0 || !(ctx.bindings.has(name) || ctx.namespaces.has(name))) return;
|
|
1744
|
+
const place = referencePlace(node, parent, ancestors);
|
|
1745
|
+
if (place === "none" || !isModuleBinding(ctx, name, ancestors)) return;
|
|
1746
|
+
const rename = ctx.renamedLocals.get(name);
|
|
1747
|
+
if (rename !== void 0 && declaredBetween(ctx, rename.to, ancestors)) ctx.kept.add(name);
|
|
1748
|
+
ctx.references.push({
|
|
1749
|
+
node,
|
|
1750
|
+
place,
|
|
1751
|
+
parent
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
function visitMember(ctx, node, ancestors) {
|
|
1755
|
+
const member = node.type === "MemberExpression";
|
|
1756
|
+
const object = member ? node.object : node.left;
|
|
1757
|
+
const property = member ? node.property : node.right;
|
|
1758
|
+
if (node.computed === true || property?.name === void 0) return;
|
|
1759
|
+
const namespace = object?.type === "Identifier" && isModuleBinding(ctx, object.name ?? "", ancestors) ? ctx.namespaces.get(object.name ?? "") : void 0;
|
|
1760
|
+
const rename = namespace === void 0 ? void 0 : renameOf(ctx.set, property.name, namespace);
|
|
1761
|
+
if (rename !== void 0) replace(ctx, property, rename.to, rename.from);
|
|
1762
|
+
else if (member) {
|
|
1763
|
+
const receiver = object?.type === "Identifier" ? object.name : void 0;
|
|
1764
|
+
const origin = receiver !== void 0 && isModuleBinding(ctx, receiver, ancestors) ? ctx.factories.get(receiver) : void 0;
|
|
1765
|
+
const method = origin === void 0 ? void 0 : ctx.methodRows.find((row) => row.from === property.name && row.entries.includes(origin));
|
|
1766
|
+
if (method !== void 0) replace(ctx, property, method.to, method.from);
|
|
1767
|
+
else if (origin === void 0) reportMethods(ctx, [property], "member", "is on a value from");
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* `const x = f(…)` or `const x = await f(…)` at module level, where `f` is
|
|
1772
|
+
* imported from a permdock entry.
|
|
1773
|
+
*/
|
|
1774
|
+
function factoryValues(program, bindings) {
|
|
1775
|
+
const out = /* @__PURE__ */ new Map();
|
|
1776
|
+
for (const statement of nodes(program.body)) {
|
|
1777
|
+
const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
1778
|
+
if (declaration?.type !== "VariableDeclaration" || Reflect.get(declaration, "kind") !== "const") continue;
|
|
1779
|
+
for (const declarator of nodes(declaration.declarations)) {
|
|
1780
|
+
const init = declarator.init?.type === "AwaitExpression" ? declarator.init.argument : declarator.init;
|
|
1781
|
+
const callee = init?.type === "CallExpression" ? init.callee : void 0;
|
|
1782
|
+
const factory = callee?.type === "Identifier" ? callee.name : void 0;
|
|
1783
|
+
const entry = factory === void 0 ? void 0 : bindings.get(factory)?.entry;
|
|
1784
|
+
const name = declarator.id?.type === "Identifier" ? declarator.id.name : void 0;
|
|
1785
|
+
if (entry !== void 0 && name !== void 0) out.set(name, entry);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return out;
|
|
1789
|
+
}
|
|
1790
|
+
function reportMethods(ctx, keys, what, where) {
|
|
1791
|
+
for (const key of keys) for (const row of ctx.methodRows) if (nameOf(key) === row.from) ctx.followUps.push({
|
|
1792
|
+
at: key.start,
|
|
1793
|
+
name: row.from,
|
|
1794
|
+
message: `${what} \`${row.from}\` is \`${row.to}\` when it ${where} ${listOf(row.entries)}`
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
/** The non-computed keys of an object literal or pattern. */
|
|
1798
|
+
function propertyKeys(node) {
|
|
1799
|
+
return nodes(node.properties).flatMap((property) => property.type === "Property" && property.computed !== true && property.key !== void 0 ? [property.key] : []);
|
|
1800
|
+
}
|
|
1801
|
+
function visitCall(ctx, node, ancestors) {
|
|
1802
|
+
const callee = importedCallee(ctx, node.callee, ancestors);
|
|
1803
|
+
if (callee === void 0) return;
|
|
1804
|
+
const pending = awaitRow(ctx, callee);
|
|
1805
|
+
if (pending !== void 0 && ancestors.at(-1)?.type !== "AwaitExpression") reportUnawaited(ctx, node, ancestors, pending);
|
|
1806
|
+
const renamed = renameOf(ctx.set, callee.imported, callee.entry)?.to;
|
|
1807
|
+
const names = /* @__PURE__ */ new Set([callee.imported, renamed]);
|
|
1808
|
+
const moved = visitFunctionCall(ctx, node, callee);
|
|
1809
|
+
visitWraps(ctx, node, callee, ancestors);
|
|
1810
|
+
for (const signature of ctx.set.signatures) if (!moved && signature.entries.includes(callee.entry) && names.has(signature.name)) {
|
|
1811
|
+
if (signature.shape === "curried" && !isCurried(node, ancestors)) {
|
|
1812
|
+
ctx.newShapes.add(signature.name);
|
|
1813
|
+
continue;
|
|
1814
|
+
}
|
|
1815
|
+
ctx.followUps.push({
|
|
1816
|
+
at: node.start,
|
|
1817
|
+
name: signature.name,
|
|
1818
|
+
message: `\`${signature.before}\` is now \`${signature.after}\``
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
const rows = ctx.optionRows.filter((row) => row.entries.includes(callee.entry) && (row.calls ?? []).some((call) => names.has(call)));
|
|
1822
|
+
for (const argument of nodes(node.arguments)) if (argument.type === "ObjectExpression") renameOptions(ctx, argument, rows);
|
|
1823
|
+
}
|
|
1824
|
+
/** `f(options)(key)`, or `f({ … })` whose result is kept for a later call. */
|
|
1825
|
+
function isCurried(node, ancestors) {
|
|
1826
|
+
const args = nodes(node.arguments);
|
|
1827
|
+
const parent = ancestors.at(-1);
|
|
1828
|
+
return args.length === 1 && (args[0]?.type === "ObjectExpression" || parent?.type === "CallExpression" && parent.callee === node);
|
|
1829
|
+
}
|
|
1830
|
+
function renameOptions(ctx, object, rows) {
|
|
1831
|
+
for (const property of nodes(object.properties)) {
|
|
1832
|
+
const row = rows.find((item) => item.from === nameOf(property.key));
|
|
1833
|
+
if (row !== void 0) renameKey(ctx, property, row.from, row.to);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Rows with `calls` are renamed at those calls and nowhere else: their old key
|
|
1838
|
+
* (`store`) is still a valid option on every other factory. Rows without
|
|
1839
|
+
* `calls` are reported only on an object that reaches a permdock call.
|
|
1840
|
+
*/
|
|
1841
|
+
function reportOptions(ctx, node, ancestors) {
|
|
1842
|
+
const target = optionTarget(ctx, node, ancestors);
|
|
1843
|
+
if (target === void 0) return;
|
|
1844
|
+
const rows = ctx.optionRows.filter((row) => row.calls === void 0 && (target.entry === void 0 || row.entries.includes(target.entry)));
|
|
1845
|
+
for (const key of propertyKeys(node)) for (const row of rows) if (nameOf(key) === row.from && !ctx.handledKeys.has(key)) ctx.followUps.push({
|
|
1846
|
+
at: key.start,
|
|
1847
|
+
name: row.from,
|
|
1848
|
+
message: `option \`${row.from}\` is \`${row.to}\` when this object reaches ${listOf(row.entries)}`
|
|
1849
|
+
});
|
|
1850
|
+
}
|
|
1851
|
+
const PASS_THROUGH = /* @__PURE__ */ new Set([
|
|
1852
|
+
"ArrayExpression",
|
|
1853
|
+
"ObjectExpression",
|
|
1854
|
+
"ParenthesizedExpression",
|
|
1855
|
+
"TSAsExpression",
|
|
1856
|
+
"TSSatisfiesExpression",
|
|
1857
|
+
"TSNonNullExpression"
|
|
1858
|
+
]);
|
|
1859
|
+
/**
|
|
1860
|
+
* The permdock call an object literal is an argument of, directly or nested in
|
|
1861
|
+
* another argument's object, array or property value. `entry` is unset for a
|
|
1862
|
+
* method on a receiver named after PermDock, whose entry is unknown.
|
|
1863
|
+
*/
|
|
1864
|
+
function optionTarget(ctx, node, ancestors) {
|
|
1865
|
+
let child = node;
|
|
1866
|
+
for (let index = ancestors.length - 1; index >= 0; index -= 1) {
|
|
1867
|
+
const parent = ancestors[index];
|
|
1868
|
+
if (parent === void 0) return;
|
|
1869
|
+
if (parent.type === "CallExpression" || parent.type === "NewExpression") return nodes(parent.arguments).includes(child) ? calleeTarget(ctx, parent.callee, ancestors) : void 0;
|
|
1870
|
+
if (!(parent.type === "Property" && parent.value === child || PASS_THROUGH.has(parent.type))) return;
|
|
1871
|
+
child = parent;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
function calleeTarget(ctx, callee, ancestors) {
|
|
1875
|
+
const imported = importedCallee(ctx, callee, ancestors);
|
|
1876
|
+
if (imported !== void 0) return { entry: imported.entry };
|
|
1877
|
+
const receiver = callee?.type === "MemberExpression" && callee.computed !== true ? callee.object : void 0;
|
|
1878
|
+
if (!holdsInstance(ctx, receiver, ancestors)) return;
|
|
1879
|
+
const name = receiver?.name ?? "";
|
|
1880
|
+
return { entry: isModuleBinding(ctx, name, ancestors) ? ctx.factories.get(name) : void 0 };
|
|
1881
|
+
}
|
|
1882
|
+
function rewriteImports(ctx, removed) {
|
|
1883
|
+
for (const [local, binding] of ctx.bindings) {
|
|
1884
|
+
const { rename, spec } = binding;
|
|
1885
|
+
const imported = spec.imported;
|
|
1886
|
+
if (rename === void 0 || imported === void 0 || removed.has(local)) continue;
|
|
1887
|
+
if (local === binding.imported) replace(ctx, imported, ctx.kept.has(local) ? `${rename.to} as ${local}` : rename.to, rename.from);
|
|
1888
|
+
else replace(ctx, imported, imported.type === "Literal" ? JSON.stringify(rename.to) : rename.to, rename.from);
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
function rewriteReferences(ctx) {
|
|
1892
|
+
for (const { node, place, parent } of ctx.references) {
|
|
1893
|
+
const name = node.name ?? "";
|
|
1894
|
+
const rename = ctx.renamedLocals.get(name);
|
|
1895
|
+
if (rename === void 0 || ctx.kept.has(name) || ctx.consumed.has(node.start)) continue;
|
|
1896
|
+
if (place === "shorthand" && parent.key !== void 0 && ctx.handledKeys.has(parent.key)) replace(ctx, node, rename.to, name);
|
|
1897
|
+
else if (place === "shorthand") edit(ctx, parent, `${name}: ${rename.to}`, name, rename.to);
|
|
1898
|
+
else if (place === "export" && parent.exported?.start === node.start) replace(ctx, node, `${rename.to} as ${name}`, name);
|
|
1899
|
+
else replace(ctx, node, rename.to, name);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* `export { a } from 'permdock'` keeps exporting `a`: the module's own export
|
|
1904
|
+
* name is not the codemod's to change.
|
|
1905
|
+
*/
|
|
1906
|
+
function rewriteReexports(ctx) {
|
|
1907
|
+
for (const statement of nodes(ctx.program.body)) {
|
|
1908
|
+
const entry = statement.source?.value;
|
|
1909
|
+
if (statement.type !== "ExportNamedDeclaration" || !isPermDockSpecifier(entry)) continue;
|
|
1910
|
+
for (const spec of nodes(statement.specifiers)) {
|
|
1911
|
+
const local = spec.local;
|
|
1912
|
+
const rename = renameOf(ctx.set, nameOf(local) ?? "", entry);
|
|
1913
|
+
if (rename !== void 0 && local !== void 0) replace(ctx, local, spec.exported?.start === local.start ? `${rename.to} as ${rename.from}` : rename.to, rename.from);
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
function reportUncalledSignatures(ctx, removed) {
|
|
1918
|
+
for (const [local, binding] of ctx.bindings) {
|
|
1919
|
+
if (removed.has(local)) continue;
|
|
1920
|
+
const names = /* @__PURE__ */ new Set([binding.imported, binding.rename?.to]);
|
|
1921
|
+
for (const signature of ctx.set.signatures) if (signature.entries.includes(binding.entry) && names.has(signature.name) && !ctx.newShapes.has(signature.name) && !ctx.followUps.some((note) => note.name === signature.name)) ctx.followUps.push({
|
|
1922
|
+
at: binding.spec.start,
|
|
1923
|
+
name: signature.name,
|
|
1924
|
+
message: `\`${local}\` is imported; \`${signature.before}\` is now \`${signature.after}\``
|
|
1925
|
+
});
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
// src/cli/codemod/codemod.ts
|
|
1929
|
+
const CODEMOD_0_17 = Object.freeze({
|
|
1930
|
+
renames: [],
|
|
1931
|
+
signatures: [],
|
|
1932
|
+
literals: rewriteLiterals017
|
|
1933
|
+
});
|
|
1934
|
+
const CODEMOD_0_26 = Object.freeze({
|
|
1935
|
+
renames: [],
|
|
1936
|
+
signatures: [],
|
|
1937
|
+
configMoves: [{
|
|
1938
|
+
from: ["gen", "fieldMeta"],
|
|
1939
|
+
to: ["gen", "fields"]
|
|
1940
|
+
}],
|
|
1941
|
+
literals: rewrite026
|
|
1942
|
+
});
|
|
1943
|
+
/** Each codemod version and the rename map it applies. */
|
|
1944
|
+
const CODEMODS = Object.freeze({
|
|
1945
|
+
"0.17": CODEMOD_0_17,
|
|
1946
|
+
"0.26": CODEMOD_0_26
|
|
1947
|
+
});
|
|
1948
|
+
function codemodVersions() {
|
|
1949
|
+
return Object.keys(CODEMODS);
|
|
1950
|
+
}
|
|
1951
|
+
const EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1952
|
+
".ts",
|
|
1953
|
+
".tsx",
|
|
1954
|
+
".mts",
|
|
1955
|
+
".cts",
|
|
1956
|
+
".js",
|
|
1957
|
+
".jsx",
|
|
1958
|
+
".mjs",
|
|
1959
|
+
".cjs",
|
|
1960
|
+
".vue",
|
|
1961
|
+
".svelte"
|
|
1962
|
+
]);
|
|
1963
|
+
/**
|
|
1964
|
+
* Files whose shell commands the codemod rewrites when the version renames CLI
|
|
1965
|
+
* names.
|
|
1966
|
+
*/
|
|
1967
|
+
const CLI_FILE_NAMES = /* @__PURE__ */ new Set([
|
|
1968
|
+
"package.json",
|
|
1969
|
+
"Makefile",
|
|
1970
|
+
"justfile",
|
|
1971
|
+
"Dockerfile"
|
|
1972
|
+
]);
|
|
1973
|
+
const CLI_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1974
|
+
".yml",
|
|
1975
|
+
".yaml",
|
|
1976
|
+
".sh"
|
|
1977
|
+
]);
|
|
1978
|
+
/** Prose: the codemod lists the old calls in it and rewrites none. */
|
|
1979
|
+
const CLI_REVIEW_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".mdx"]);
|
|
1980
|
+
/** The versions whose renames include the CLI's own commands and flags. */
|
|
1981
|
+
const CLI_RENAME_VERSIONS = /* @__PURE__ */ new Set(["0.26"]);
|
|
1982
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
1983
|
+
"node_modules",
|
|
1984
|
+
"dist",
|
|
1985
|
+
".git",
|
|
1986
|
+
".next",
|
|
1987
|
+
".turbo",
|
|
1988
|
+
".svelte-kit",
|
|
1989
|
+
"coverage"
|
|
1990
|
+
]);
|
|
1991
|
+
function runCodemod(options) {
|
|
1992
|
+
const report = codemod(options);
|
|
1993
|
+
return {
|
|
1994
|
+
code: 0,
|
|
1995
|
+
output: options.json ? JSON.stringify(report, null, 2) : formatReport(report)
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
function codemod(options) {
|
|
1999
|
+
const version = normaliseVersion(options.version);
|
|
2000
|
+
const set = CODEMODS[version];
|
|
2001
|
+
if (set === void 0) throw new CliError("usage", `unknown codemod version '${version}'. Supported: ${Object.keys(CODEMODS).join(", ")}.`);
|
|
2002
|
+
const files = sourceFiles(options.cwd, options.paths.length === 0 ? ["."] : options.paths, CLI_RENAME_VERSIONS.has(version), version === "0.26");
|
|
2003
|
+
const changed = [];
|
|
2004
|
+
const followUps = [];
|
|
2005
|
+
const writes = [];
|
|
2006
|
+
for (const file of files) {
|
|
2007
|
+
const source = readFileSync(file, "utf8");
|
|
2008
|
+
if (version === "0.26" && extname(file) === ".json") {
|
|
2009
|
+
const rewritten = rewriteStoredCatalog(source);
|
|
2010
|
+
if (rewritten !== void 0) {
|
|
2011
|
+
if (rewritten.text !== source) {
|
|
2012
|
+
changed.push({
|
|
2013
|
+
file: rel(options.cwd, file),
|
|
2014
|
+
changes: [{
|
|
2015
|
+
line: 1,
|
|
2016
|
+
column: 1,
|
|
2017
|
+
from: rewritten.from,
|
|
2018
|
+
to: rewritten.to
|
|
2019
|
+
}]
|
|
2020
|
+
});
|
|
2021
|
+
writes.push({
|
|
2022
|
+
path: file,
|
|
2023
|
+
text: rewritten.text
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
continue;
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
if (!source.includes("permdock") && !basename(file).startsWith("permdock.config.")) continue;
|
|
2030
|
+
const name = rel(options.cwd, file);
|
|
2031
|
+
const result = isCodeFile(file) ? withConfigMoves(file, withLiterals(file, transformSource(file, source, set), set), set) : cliResult(file, source);
|
|
2032
|
+
if (result.error !== void 0) {
|
|
2033
|
+
followUps.push({
|
|
2034
|
+
file: name,
|
|
2035
|
+
line: 1,
|
|
2036
|
+
column: 1,
|
|
2037
|
+
name: "parse",
|
|
2038
|
+
message: `not parsed, left as it is: ${result.error}`
|
|
2039
|
+
});
|
|
2040
|
+
continue;
|
|
2041
|
+
}
|
|
2042
|
+
if (result.changes.length > 0 && result.source !== source) {
|
|
2043
|
+
changed.push({
|
|
2044
|
+
file: name,
|
|
2045
|
+
changes: result.changes
|
|
2046
|
+
});
|
|
2047
|
+
writes.push({
|
|
2048
|
+
path: file,
|
|
2049
|
+
text: result.source
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
for (const followUp of result.followUps) followUps.push({
|
|
2053
|
+
file: name,
|
|
2054
|
+
...followUp
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
2057
|
+
if (!options.dryRun && writes.length > 0) {
|
|
2058
|
+
refuseDirty({
|
|
2059
|
+
command: "codemod",
|
|
2060
|
+
invocation: [
|
|
2061
|
+
"codemod",
|
|
2062
|
+
version,
|
|
2063
|
+
...options.paths
|
|
2064
|
+
].join(" "),
|
|
2065
|
+
cwd: options.cwd,
|
|
2066
|
+
paths: writes.map((write) => write.path),
|
|
2067
|
+
force: options.force === true
|
|
2068
|
+
});
|
|
2069
|
+
applyFiles(options.cwd, writes);
|
|
2070
|
+
}
|
|
2071
|
+
return {
|
|
2072
|
+
version,
|
|
2073
|
+
dryRun: options.dryRun,
|
|
2074
|
+
scanned: files.length,
|
|
2075
|
+
files: changed,
|
|
2076
|
+
followUps
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
function withLiterals(file, result, set) {
|
|
2080
|
+
if (result.error !== void 0 || set.literals === void 0) return result;
|
|
2081
|
+
const rewritten = set.literals(file, result.source);
|
|
2082
|
+
return {
|
|
2083
|
+
source: rewritten.source,
|
|
2084
|
+
changes: [...result.changes, ...rewritten.changes],
|
|
2085
|
+
followUps: [...result.followUps, ...rewritten.followUps]
|
|
2086
|
+
};
|
|
2087
|
+
}
|
|
2088
|
+
function withConfigMoves(file, result, set) {
|
|
2089
|
+
if (result.error !== void 0 || set.configMoves === void 0) return result;
|
|
2090
|
+
const moved = moveConfigKeys(file, result.source, set.configMoves);
|
|
2091
|
+
return {
|
|
2092
|
+
source: moved.source,
|
|
2093
|
+
changes: [...result.changes, ...moved.changes],
|
|
2094
|
+
followUps: [...result.followUps, ...moved.followUps]
|
|
2095
|
+
};
|
|
2096
|
+
}
|
|
2097
|
+
function normaliseVersion(version) {
|
|
2098
|
+
if (version === void 0) throw new CliError("usage", `codemod needs a version: permdock codemod <version>. Supported: ${Object.keys(CODEMODS).join(", ")}.`);
|
|
2099
|
+
return /^v?(\d+\.\d+)(?:\.\d+)?$/u.exec(version)?.[1] ?? version;
|
|
2100
|
+
}
|
|
2101
|
+
function isCodeFile(file) {
|
|
2102
|
+
return EXTENSIONS.has(extname(file));
|
|
2103
|
+
}
|
|
2104
|
+
function isCliFile(name) {
|
|
2105
|
+
return CLI_FILE_NAMES.has(name) || CLI_EXTENSIONS.has(extname(name)) || CLI_REVIEW_EXTENSIONS.has(extname(name));
|
|
2106
|
+
}
|
|
2107
|
+
function cliResult(file, source) {
|
|
2108
|
+
const result = rewriteCliCalls(source, { json: extname(file) === ".json" });
|
|
2109
|
+
if (!CLI_REVIEW_EXTENSIONS.has(extname(file))) return {
|
|
2110
|
+
source: result.text,
|
|
2111
|
+
changes: result.changes,
|
|
2112
|
+
followUps: result.followUps
|
|
2113
|
+
};
|
|
2114
|
+
return {
|
|
2115
|
+
source,
|
|
2116
|
+
changes: [],
|
|
2117
|
+
followUps: [...result.changes.map((change) => ({
|
|
2118
|
+
line: change.line,
|
|
2119
|
+
column: change.column,
|
|
2120
|
+
name: "cli",
|
|
2121
|
+
message: `${change.from} → ${change.to} since 0.5.0`
|
|
2122
|
+
})), ...result.followUps]
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2125
|
+
function sourceFiles(cwd, paths, cli, catalogs) {
|
|
2126
|
+
const out = /* @__PURE__ */ new Set();
|
|
2127
|
+
for (const path of paths) {
|
|
2128
|
+
const root = resolve(cwd, path);
|
|
2129
|
+
const stats = statSync(root, { throwIfNoEntry: false });
|
|
2130
|
+
if (stats === void 0) throw new CliError("usage", `not found: ${path}`);
|
|
2131
|
+
if (stats.isFile()) out.add(root);
|
|
2132
|
+
else walkDir(root, out, cli, catalogs);
|
|
2133
|
+
}
|
|
2134
|
+
return [...out].toSorted();
|
|
2135
|
+
}
|
|
2136
|
+
function walkDir(dir, out, cli, catalogs) {
|
|
2137
|
+
for (const name of readdirSync(dir)) {
|
|
2138
|
+
if (SKIP_DIRS.has(name)) continue;
|
|
2139
|
+
const full = join(dir, name);
|
|
2140
|
+
if (statSync(full).isDirectory()) walkDir(full, out, cli, catalogs);
|
|
2141
|
+
else if (EXTENSIONS.has(extname(name)) || cli && isCliFile(name) || catalogs && extname(name) === ".json") out.add(full);
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
function formatReport(report) {
|
|
2145
|
+
const lines = [];
|
|
2146
|
+
const changes = report.files.reduce((sum, file) => sum + file.changes.length, 0);
|
|
2147
|
+
const verb = report.dryRun ? "would change" : "changed";
|
|
2148
|
+
lines.push(`permdock codemod ${report.version}: ${verb} ${changes} ${changes === 1 ? "name" : "names"} in ${report.files.length} of ${report.scanned} ${report.scanned === 1 ? "file" : "files"}; ${report.followUps.length} manual ${report.followUps.length === 1 ? "follow-up" : "follow-ups"}${report.dryRun ? " (dry run, nothing written)" : ""}`);
|
|
2149
|
+
for (const file of report.files) {
|
|
2150
|
+
lines.push("", file.file);
|
|
2151
|
+
for (const change of file.changes) lines.push(` ${change.line}:${change.column} ${change.from} → ${change.to}`);
|
|
2152
|
+
}
|
|
2153
|
+
if (report.followUps.length > 0) {
|
|
2154
|
+
lines.push("", "Manual follow-ups");
|
|
2155
|
+
for (const item of report.followUps) lines.push(` ${item.file}:${item.line}:${item.column} ${item.message}`);
|
|
2156
|
+
}
|
|
2157
|
+
return lines.join("\n");
|
|
2158
|
+
}
|
|
2159
|
+
export { codemodVersions, runCodemod };
|