permdock 0.4.0 → 0.5.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 +37 -35
- package/dist/{schema-Bol6gqXA.js → 2020-C9VN-x8c.js} +5 -130
- package/dist/a2a/index.d.ts +6 -6
- package/dist/a2a/index.js +14 -17
- package/dist/{adapter-context-mlWsVGGg.js → adapter-context-CRhqyzCk.js} +1 -1
- package/dist/adoption-scan-B4R5fnMU.js +107 -0
- package/dist/agent/index.d.ts +3 -0
- package/dist/agent/index.js +1 -0
- package/dist/ai-sdk/index.d.ts +18 -35
- package/dist/ai-sdk/index.js +37 -23
- package/dist/{app-data-CV8pqqMi.js → app-data-MuyzVqX8.js} +2 -1
- package/dist/approval-header-CJACtHkv.js +23 -0
- package/dist/approval-prompt-Dg5LeAcT.js +62 -0
- package/dist/approval-prompt-Djo_PyZc.d.ts +57 -0
- package/dist/approvals/index.d.ts +5 -3
- package/dist/approvals/index.js +8 -5
- package/dist/approvals-DJ6Yd5z1.js +995 -0
- package/dist/arazzo-B6lebmiQ.js +36 -0
- package/dist/{arazzo-C4BcskbX.js → arazzo-BWhNF-k0.js} +20 -14
- package/dist/args-IIolxxKA.js +197 -0
- package/dist/astro/index.d.ts +43 -0
- package/dist/astro/index.js +27 -0
- package/dist/audience-Dg8XsRaO.js +55 -0
- package/dist/auth-DRLEizbL.js +178 -0
- package/dist/authzen/index.d.ts +26 -6
- package/dist/authzen/index.js +94 -79
- package/dist/automation-BMZPIVUM.d.ts +114 -0
- package/dist/automation-DVjOckjV.js +157 -0
- package/dist/better-auth/index.d.ts +8 -6
- package/dist/better-auth/index.js +9 -8
- package/dist/better-supabase/index.d.ts +357 -30
- package/dist/better-supabase/index.js +936 -194
- package/dist/{bind-BzqG8SMb.d.ts → bind--9EFVYWF.d.ts} +12 -10
- package/dist/{bind-kk-uyCwH.js → bind-CZzhx-Vj.js} +14 -10
- package/dist/body-CH5of8Ne.js +10 -0
- package/dist/body-text-QcXok_SI.js +52 -0
- package/dist/{build-instance-DIIV9DbC.js → build-instance-BMnAudHn.js} +4 -3
- package/dist/{canonical-json-CFKyFOke.js → canonical-json-BC8_nMTw.js} +5 -3
- package/dist/{capability-CksyCWDH.d.ts → capability-BSslw1QV.d.ts} +44 -25
- package/dist/{capability-txATtKV4.js → capability-N1K9IpqS.js} +68 -42
- package/dist/casbin-Cr7RLtA3.js +30 -0
- package/dist/casbin-Dyu2gnUD.js +234 -0
- package/dist/casl-64gpT-8x.js +24 -0
- package/dist/casl-DjEDhTCP.js +299 -0
- package/dist/catalog/index.d.ts +74 -2
- package/dist/catalog/index.js +51 -2
- package/dist/{catalog-tZUyOfOv.js → catalog-BECMPrwc.js} +51 -6
- package/dist/catalog-DjhMYYCq.js +1 -0
- package/dist/catalog-R_A__RsH.js +52 -0
- package/dist/{catalog-doc-DWtg0gGR.js → catalog-doc-C9wjsfNY.js} +45 -23
- package/dist/catalog-fingerprint-CCP0-yQS.js +153 -0
- package/dist/chat/index.d.ts +2 -0
- package/dist/chat/index.js +224 -0
- package/dist/chat-sdk/index.d.ts +87 -0
- package/dist/chat-sdk/index.js +197 -0
- package/dist/claims-map-7oQ3ue4X.js +13 -0
- package/dist/claims-map-Ca-QX8C6.d.ts +32 -0
- package/dist/claude-agent/index.d.ts +7 -14
- package/dist/claude-agent/index.js +24 -27
- package/dist/clerk/index.d.ts +9 -8
- package/dist/clerk/index.js +9 -14
- package/dist/cli/bin.js +36 -17
- package/dist/cli/index.d.ts +19 -5
- package/dist/cli/index.js +164 -4
- package/dist/cloud/index.d.ts +102 -63
- package/dist/cloud/index.js +239 -340
- package/dist/cloud-CIoHNevm.js +87 -0
- package/dist/codemod-Bmj9dWMH.js +37 -0
- package/dist/codemod-Cxvvc70T.js +2084 -0
- package/dist/{collect-2SrB7lfk.js → collect-CrZJJnEF.js} +75 -11
- package/dist/collect-DloHbDVa.js +55 -0
- package/dist/collect-FlXJlhus.js +1 -0
- package/dist/command-L8EstFNm.js +6 -0
- package/dist/compile/index.d.ts +1 -1
- package/dist/compile/index.js +1 -2
- package/dist/{compile-CcEu2ZQ1.js → compile-CMqMx_IN.js} +11 -8
- package/dist/{compile-CtTP7eur.d.ts → compile-Ckm2HqBZ.d.ts} +5 -3
- package/dist/completion-BqhRBJD8.js +143 -0
- package/dist/config-B46rm9sc.js +26 -0
- package/dist/{config-BIjREpyE.js → config-bs_kZeYq.js} +12 -7
- package/dist/{config-report--Xb9APJS.js → config-report-DUgj62Ai.js} +15 -5
- package/dist/{connection-DUsczpB5.js → connection-DjhIJSs2.js} +6 -5
- package/dist/{context-DieZVJXu.js → context-bbFHR-0D.js} +2 -2
- package/dist/convex/index.d.ts +11 -10
- package/dist/convex/index.js +6 -4
- package/dist/create-0VZ7Pdiu.d.ts +107 -0
- package/dist/create-BDS7wc3y.d.ts +138 -0
- package/dist/create-BFfm17UA.d.ts +110 -0
- package/dist/create-BWRSXgOF.js +403 -0
- package/dist/create-C3b4B5eF.js +130 -0
- package/dist/{create-BBO24vj6.js → create-DnrmLnLW.js} +31 -32
- package/dist/{credential-kue0qpbm.js → credential-DM2um3ha.js} +152 -31
- package/dist/credentials-DPyHmYz5.js +74 -0
- package/dist/delegation-DaXVdDhM.js +286 -0
- package/dist/delivery/index.d.ts +5 -0
- package/dist/delivery/index.js +5 -0
- package/dist/delivery-DCAgNyCn.js +499 -0
- package/dist/delivery-event-xX4obB8F.js +40 -0
- package/dist/{denied-text-DfRk15uw.d.ts → denied-text-D8jDHgsl.d.ts} +5 -5
- package/dist/{describe-C3ldA9os.d.ts → describe-BZUsixiL.d.ts} +2 -2
- package/dist/{describe-Cgkp7eP0.js → describe-BybMRY7A.js} +6 -2
- package/dist/device-BARQ8eYG.js +193 -0
- package/dist/diff-CxZo9pTq.js +37 -0
- package/dist/{diff-rpqoe7Ag.js → diff-DCePiN6M.js} +60 -54
- package/dist/doctor-CxiwSfqH.js +44 -0
- package/dist/{doctor-owlv6ddh.js → doctor-DFjUxf2f.js} +245 -50
- package/dist/drizzle/index.d.ts +5 -3
- package/dist/drizzle/index.js +2 -2
- package/dist/elysia/index.d.ts +16 -13
- package/dist/elysia/index.js +13 -12
- package/dist/env-DJZrPjRi.js +8 -0
- package/dist/errors-BDUwg2qC.js +27 -0
- package/dist/{errors-drnfxYtm.js → errors-BKy0EfhN.js} +5 -9
- package/dist/errors-BWXBMaKK.d.ts +11 -0
- package/dist/{errors-OD_4c__H.d.ts → errors-C2PXIv4c.d.ts} +2 -2
- package/dist/errors-CWTY6uih.js +143 -0
- package/dist/evaluate-_R8QkWaf.js +1732 -0
- package/dist/evaluations-16UqqQ6W.d.ts +32 -0
- package/dist/{evaluations-C9YJsv3H.js → evaluations-DZ2CbV5k.js} +145 -34
- package/dist/eve/index.d.ts +12 -16
- package/dist/eve/index.js +22 -28
- package/dist/event-time-CsegxXxB.js +23 -0
- package/dist/expiry-D4_YKRKD.js +52 -0
- package/dist/express/index.d.ts +13 -10
- package/dist/express/index.js +12 -11
- package/dist/fastify/index.d.ts +25 -22
- package/dist/fastify/index.js +13 -12
- package/dist/fetch-adapter-g0ypLkID.js +120 -0
- package/dist/fetch-adapter-qKJBuRqy.d.ts +31 -0
- package/dist/fields-D9tPVUUS.js +203 -0
- package/dist/files-C5ZI27eV.js +124 -0
- package/dist/{fixtures-h2eG2OZV.js → fixtures-B7XrLeY7.js} +8 -7
- package/dist/flags-C3DktBDY.js +86 -0
- package/dist/{from-snapshot-7REQZe0H.js → from-snapshot-D2lZt4Dd.js} +55 -52
- package/dist/{grantee-CXY-0C87.js → grantee-Cn1HyUsI.js} +3 -3
- package/dist/{grantee-conditions-MQs5NIuX.js → grantee-conditions-CcXf8hMM.js} +4 -3
- package/dist/{grantee-match-fxYp9Nmt.js → grantee-match-DHArqY82.js} +5 -4
- package/dist/h3/index.d.ts +37 -0
- package/dist/h3/index.js +35 -0
- package/dist/headers-BIjfMaoC.js +8 -0
- package/dist/headers-CIbDTUTK.d.ts +7 -0
- package/dist/{helpers-C9YmyBIa.js → helpers-DTcZOzhF.js} +45 -38
- package/dist/hono/index.d.ts +12 -9
- package/dist/hono/index.js +13 -12
- package/dist/hosted-BZIAYvon.js +315 -0
- package/dist/hosted-DBDX0M-P.d.ts +78 -0
- package/dist/{http-DPuDaChb.d.ts → http-B_LphE5Y.d.ts} +1 -2
- package/dist/http-DXJ37RDA.js +46 -0
- package/dist/{http-BEbdMZ05.js → http-ujKm0JXE.js} +1 -2
- package/dist/{import-UHk1N7vH.js → import-CNV7I2Dw.js} +25 -20
- package/dist/{import-BFIlhetD.js → import-DMmOG27O.js} +190 -53
- package/dist/index-BcHcPyIo.d.ts +110 -0
- package/dist/index-CaxrMD1A.d.ts +1 -0
- package/dist/index-Chrs5fQ-.d.ts +210 -0
- package/dist/index-CxGUswIC.d.ts +431 -0
- package/dist/index-D8EovfsP.d.ts +91 -0
- package/dist/{index-UdVQgq48.d.ts → index-DOVf7RJv.d.ts} +431 -81
- package/dist/{index-BwMe94Xq.d.ts → index-SGdIQyzc.d.ts} +34 -16
- package/dist/index.d.ts +19 -15
- package/dist/index.js +31 -21
- package/dist/init-DeMYsnYJ.js +96 -0
- package/dist/init-GG6Jh8HD.js +95 -0
- package/dist/{instance-options-plkrsAog.d.ts → instance-options-Omfd793B.d.ts} +2 -2
- package/dist/instance-snapshot-Cxq4ygFc.js +600 -0
- package/dist/instant-BluqDvyS.js +19 -0
- package/dist/internals-Dk8A8fX3.js +17 -0
- package/dist/{json-schema-DBkdUuCO.js → json-schema-B-vAwlde.js} +45 -6
- package/dist/json-schema-CN_iLFH2.d.ts +40 -0
- package/dist/jwt/index.d.ts +18 -11
- package/dist/jwt/index.js +156 -135
- package/dist/{kernel-CB3LrIJM.js → kernel-5JatXyND.js} +52 -24
- package/dist/kysely/index.d.ts +5 -3
- package/dist/kysely/index.js +2 -2
- package/dist/load-BxEtwlBS.js +1 -0
- package/dist/{load-C3_oTHyO.js → load-DFS_ry0W.js} +22 -6
- package/dist/{load-jose-BL6LH4bL.js → load-jose-DZ4dnjri.js} +1 -4
- package/dist/login-Dfe5RlYk.js +68 -0
- package/dist/login-imhuwvn3.js +254 -0
- package/dist/manifest-C8IzW3Do.js +42 -0
- package/dist/manifest-CtKR3GXL.js +370 -0
- package/dist/manifest-json-CAGzls-C.js +9 -0
- package/dist/{manifest-uDS9y5de.d.ts → manifest-mx5ghSFM.d.ts} +9 -2
- package/dist/manifest-schema-C0kK_8V0.js +399 -0
- package/dist/{map-claims-AVlBaJoa.js → map-claims-D3oRmTk0.js} +13 -10
- package/dist/{map-error-BE27PYkE.js → map-error-TCAdw-eW.js} +3 -3
- package/dist/{markers-CiwAOZtO.js → markers-C6joDI3o.js} +2 -1
- package/dist/mcp/index.d.ts +22 -12
- package/dist/mcp/index.js +57 -39
- package/dist/{migrate-BwlB5-Wk.js → migrate-BShP7Vf4.js} +53 -14
- package/dist/nest/index.d.ts +12 -9
- package/dist/nest/index.js +15 -14
- package/dist/next/index.d.ts +18 -21
- package/dist/next/index.js +13 -11
- package/dist/next/plugin.d.ts +1 -1
- package/dist/next/plugin.js +2 -2
- package/dist/node/index.d.ts +10 -10
- package/dist/node/index.js +7 -9
- package/dist/{ocsf-uYFXGVw2.js → ocsf-BFp-PZZA.js} +22 -11
- package/dist/openai/index.d.ts +9 -16
- package/dist/openai/index.js +17 -24
- package/dist/openapi/index.d.ts +3 -3
- package/dist/openapi/index.js +1 -1
- package/dist/{openapi-DBzHQbov.js → openapi-B7HZ0f-r.js} +8 -8
- package/dist/{openapi-BJdBmYDG.js → openapi-DTaEmTSW.js} +10 -9
- package/dist/openapi-ahr8rHu3.js +138 -0
- package/dist/operation-findings-DgATDpvh.js +36 -0
- package/dist/operations-CxybZErY.d.ts +59 -0
- package/dist/orpc/index.d.ts +13 -10
- package/dist/orpc/index.js +20 -15
- package/dist/otel/index.d.ts +3 -2
- package/dist/otel/index.js +30 -7
- package/dist/output-Dyw8fyPF.js +88 -0
- package/dist/output-files-B3IZJksC.js +1 -0
- package/dist/{output-files-CgIsvdSa.js → output-files-DhRBBE4n.js} +24 -26
- package/dist/{permission-keys-B26jeyUv.js → ownership-BatFgAA4.js} +1698 -869
- package/dist/{package-root-DtNnpmUd.js → package-root-Dk_ETdkp.js} +1 -1
- package/dist/{parse-CVFQHk6c.js → parse-Cxq0WxrA.js} +2 -2
- package/dist/{parse-local-manifest-C-q02Pal.js → parse-local-manifest-CVSs6J9I.js} +1 -1
- package/dist/{parse-local-manifest-DvYUR0QL.d.ts → parse-local-manifest-DgqtruPn.d.ts} +1 -1
- package/dist/parse-request-D_tUXG6M.js +26 -0
- package/dist/paths-DXSHAMIa.js +42 -0
- package/dist/pdp/index.d.ts +7 -3
- package/dist/pdp/index.js +45 -26
- package/dist/{peer-BOr_kJE1.js → peer-C8swJ2GH.js} +23 -4
- package/dist/peer-CRvC7Hg1.js +1 -0
- package/dist/permdock-B9JxkBwC.js +868 -0
- package/dist/permdock-D7eeLJER.d.ts +502 -0
- package/dist/{permission-registry-BsblpB-z.js → permission-registry-Br4jSNVi.js} +3 -3
- package/dist/permissions-B-wCP5ZC.js +30 -0
- package/dist/{permissions-CCJ6lmxB.js → permissions-CZKiUfFM.js} +4 -3
- package/dist/{permissions-COH-KRgT.d.ts → permissions-oEWfl-kl.d.ts} +1 -2
- package/dist/policies-CO1oOymN.js +295 -0
- package/dist/{policy-ur0BBK_e.d.ts → policy-Czo4n3Hs.d.ts} +2 -2
- package/dist/{hosted-CBHgkzDl.js → policy-DLZJ5gAp.js} +17 -273
- package/dist/policy-from-catalog-DzhEc3Y9.js +450 -0
- package/dist/policy-module-CTlwMvLI.js +89 -0
- package/dist/{policy-types-sp9P1iIV.d.ts → policy-types-DzwivBgR.d.ts} +434 -631
- package/dist/postgrest-CW0IqC-U.js +566 -0
- package/dist/postgrest-NUqZT-RB.d.ts +100 -0
- package/dist/powersync-BHfuehf3.js +62 -0
- package/dist/powersync-CbzkqL_M.js +1 -0
- package/dist/{powersync-cZe4kzhL.js → powersync-bYUDLOAO.js} +23 -24
- package/dist/preset/index.d.ts +146 -0
- package/dist/preset/index.js +1 -0
- package/dist/preset-DZdU0tne.js +1768 -0
- package/dist/principal-source-pHneukrx.js +103 -0
- package/dist/prisma/index.d.ts +6 -3
- package/dist/prisma/index.js +2 -2
- package/dist/{problem-CnWraVhC.js → problem-CTviyH5L.js} +13 -23
- package/dist/{problem-details-rIIo8B2C.d.ts → problem-details-DXlt-vks.d.ts} +1 -1
- package/dist/{problem-details-DECUnXAn.js → problem-details-cn5X30gZ.js} +43 -40
- package/dist/problem-types-CJ2325SZ.js +5 -0
- package/dist/{prompt-CXYhLfsS.js → prompt-DfZLJLIn.js} +2 -2
- package/dist/{protected-B3_P7xuw.d.ts → protected-DEPHc2xV.d.ts} +16 -8
- package/dist/{protected-BN7BUdY1.js → protected-DfjY5mLA.js} +21 -4
- package/dist/{provider-Bi-0HNL3.js → provider-CC-u3bYP.js} +2 -2
- package/dist/{provider-kwHC9CZD.d.ts → provider-DMVt6yYn.d.ts} +1 -1
- package/dist/{provider-store-Ctt-81Ni.js → provider-store-B5Yrkhzr.js} +2 -2
- package/dist/pull-BgIfno6w.js +256 -0
- package/dist/pull-ByOks_Tg.js +1 -0
- package/dist/push-CmFVBOeI.js +116 -0
- package/dist/pushed-policy-BImMTTIM.d.ts +57 -0
- package/dist/pushed-policy-DobP7AHI.js +238 -0
- package/dist/react/index.d.ts +8 -8
- package/dist/react/index.js +6 -6
- package/dist/react/provider-client.d.ts +1 -1
- package/dist/react/provider-client.js +1 -2
- package/dist/react-native/index.d.ts +24 -72
- package/dist/react-native/index.js +24 -22
- package/dist/{refs-f3imMjNW.js → refs-K6eWUJ0H.js} +1 -1
- package/dist/{relation-walk-BXnlLtg2.js → relation-walk-3OyDBF0S.js} +2 -2
- package/dist/{relations-CvmSpG67.js → relations-BnCWnJGI.js} +3 -3
- package/dist/renames-CGj7YwcQ.js +175 -0
- package/dist/{replay-COpmZUfx.d.ts → replay-D7iKcLFe.d.ts} +1 -1
- package/dist/{replay-BsOyTrdV.js → replay-Du1tJjG7.js} +2 -1
- package/dist/{request-context-BVM7aWNs.js → request-context-BTRTG7OT.js} +3 -3
- package/dist/request-schema-CMreVuFM.js +148 -0
- package/dist/resend/index.d.ts +126 -0
- package/dist/resend/index.js +379 -0
- package/dist/{resource-relations-D1Un3pcz.js → resource-relations-D_jw0BFx.js} +1 -1
- package/dist/{retire-BFcxL6un.js → retire-CALjIQ7e.js} +2 -2
- package/dist/{revocations-Cy06JNx2.d.ts → revocations-R07lFBnX.d.ts} +2 -0
- package/dist/rls-BA8an5Ap.js +336 -0
- package/dist/{rls-BEktUaqg.js → rls-j6t43t7n.js} +287 -689
- package/dist/{role-builder-B4GbKM-i.js → role-builder-CXbis5-X.js} +14 -207
- package/dist/{rpc-nYC3cR_u.js → rpc-aPyNi6tA.js} +7 -7
- package/dist/run-CNsApDpd.js +1 -0
- package/dist/run-DOfMtc9V.js +723 -0
- package/dist/run-ticket-BjhTOi6u.d.ts +124 -0
- package/dist/run-ticket-sxFI6LAk.js +337 -0
- package/dist/{runtime-D_tMXnsq.js → runtime-D3VTAiCA.js} +1 -1
- package/dist/{saas-DtaA4JuW.js → saas-FO-Q8oj0.js} +16 -14
- package/dist/scan-BOI5tJ-6.js +29 -0
- package/dist/{schema-DjQBcAP9.js → schema-B4v0Qrac.js} +102 -8
- package/dist/schema-yLuBWWsh.js +130 -0
- package/dist/scim/index.d.ts +2 -2
- package/dist/scim/index.js +1 -2
- package/dist/{scim-vFR1O5oG.js → scim-ClHtpyV3.js} +208 -76
- package/dist/{scopes-tvpa34ep.js → scopes-CUPSjo9q.js} +12 -7
- package/dist/server/index.d.ts +12 -143
- package/dist/server/index.js +12 -9
- package/dist/server-DqCT4CgZ.js +453 -0
- package/dist/{server-types-DdqBwZN_.d.ts → server-types-BLd4MnBX.d.ts} +51 -68
- package/dist/{sha256-BO0swRXL.js → sha256-D9ihqmvd.js} +8 -1
- package/dist/{shared-1uhI-e-b.js → shared-CD11nBbC.js} +18 -8
- package/dist/{shared-JhMeOsDF.js → shared-DvvFzYXe.js} +8 -9
- package/dist/signals-D3NcTKUS.js +32 -0
- package/dist/sink-BEZSlMS_.js +957 -0
- package/dist/sink-Bj_lDUDq.d.ts +225 -0
- package/dist/{skills-BZdRQkxs.js → skills-B6lVdD_W.js} +13 -6
- package/dist/skills-CTYwkl44.js +51 -0
- package/dist/snapshot-CXUWfsNy.js +269 -0
- package/dist/{snapshot-cache-Cod40D-X.js → snapshot-cache-DZHQ0KF6.js} +11 -5
- package/dist/{snapshot-cache-J5T7t_vD.d.ts → snapshot-cache-DqK9eDmM.d.ts} +7 -5
- package/dist/solid/index.d.ts +11 -12
- package/dist/solid/index.js +7 -7
- package/dist/solid-start/index.d.ts +52 -0
- package/dist/solid-start/index.js +49 -0
- package/dist/{sources-Dljy06zL.d.ts → sources-BV9j0DeZ.d.ts} +7 -13
- package/dist/{sources-B1-b-R0t.js → sources-vs5dGOsS.js} +125 -119
- package/dist/{sql-t8teWOfo.js → sql-B5T1IL83.js} +13 -1
- package/dist/src-DLfUWFAI.js +1851 -0
- package/dist/ssf/index.d.ts +4 -4
- package/dist/ssf/index.js +384 -47
- package/dist/standard-webhooks-6lg8v_is.d.ts +88 -0
- package/dist/standard-webhooks-DgFFD-Ga.js +228 -0
- package/dist/storage-C2bWdvJH.js +132 -0
- package/dist/{store-ILkLUj_o.js → store-4u_hxjWa.js} +40 -53
- package/dist/{store-options-CbUHDoSe.js → store-options-BqEakYRa.js} +26 -21
- package/dist/{stores-BHXdSbw9.js → stores-BbsD4fAR.js} +2 -2
- package/dist/{stores-Cxz_80g-.d.ts → stores-ClZUgeoP.d.ts} +7 -8
- package/dist/{stream-Dwsg6WwE.d.ts → stream-7-xmnf3U.d.ts} +2 -2
- package/dist/{stream-BMui98KK.js → stream-CvdUS9V1.js} +9 -2
- package/dist/style-DiKWnAvn.js +1 -0
- package/dist/{style-CTm1AXDT.js → style-Uao76wO7.js} +3 -2
- package/dist/subject-BGoM5o8B.js +17 -0
- package/dist/supabase/index.d.ts +23 -106
- package/dist/supabase/index.js +5 -4
- package/dist/supabase/middleware.d.ts +7 -6
- package/dist/supabase/middleware.js +13 -11
- package/dist/supabase-9pqI57pW.js +92 -0
- package/dist/{supabase-C1TWlnYt.js → supabase-Dxlp8A94.js} +98 -205
- package/dist/supabase-hook-CXcGpHqq.js +1 -0
- package/dist/{supabase-hook-Cva3ikXz.js → supabase-hook-DdDQhMlw.js} +951 -60
- package/dist/support-session-C6xJQYut.js +158 -0
- package/dist/svelte/Protected.svelte +4 -4
- package/dist/svelte/index.d.ts +7 -7
- package/dist/svelte/index.js +10 -10
- package/dist/svelte/runtime.d.ts +3 -3
- package/dist/svelte/runtime.js +3 -3
- package/dist/svelte/source.d.ts +7 -7
- package/dist/svelte/source.js +4 -4
- package/dist/sveltekit/index.d.ts +51 -0
- package/dist/sveltekit/index.js +27 -0
- package/dist/tanstack-start/index.d.ts +51 -0
- package/dist/tanstack-start/index.js +40 -0
- package/dist/target-Bw37TFNA.js +51 -0
- package/dist/{tenancy-DshjqY0n.js → tenancy-DN2QAx9z.js} +5 -5
- package/dist/terminal/index.d.ts +11 -9
- package/dist/terminal/index.js +23 -287
- package/dist/testing/index.d.ts +311 -38
- package/dist/testing/index.js +3475 -201
- package/dist/testing/saas/index.d.ts +9 -8
- package/dist/testing/saas/index.js +2 -2
- package/dist/testing/saas/permissions.d.ts +1 -1
- package/dist/testing/saas/permissions.js +1 -2
- package/dist/text-BMFRfBqc.js +8 -0
- package/dist/{text-diff-BdkkYSbi.js → text-diff-BQcUapOb.js} +1 -1
- package/dist/thenable-yD7SabqG.js +31 -0
- package/dist/time-DkWjdL98.js +71 -0
- package/dist/{token-Bx9qy30p.js → token-BLZcjQgt.js} +15 -6
- package/dist/{tool-refusal-CQ7OEia9.js → tool-refusal-CMLN5xhn.js} +2 -2
- package/dist/trpc/index.d.ts +12 -9
- package/dist/trpc/index.js +16 -14
- package/dist/{types-7rJVLWe5.d.ts → types-5Ut_pbKy.d.ts} +61 -11
- package/dist/{store-9KO4BlkB.d.ts → types-BNORmDM8.d.ts} +100 -75
- package/dist/types-BjV-fqcA.d.ts +57 -0
- package/dist/{types-CUcFZfpU.d.ts → types-BqAKcRNW.d.ts} +2 -1
- package/dist/types-C8-KNsFf.d.ts +107 -0
- package/dist/{types-Br9IXUBG.d.ts → types-CCpc2Dcv.d.ts} +77 -17
- package/dist/{types-DpWfQdSh.d.ts → types-CZTnPFzM.d.ts} +46 -11
- package/dist/{types-CqrjB9o6.d.ts → types-CdlxsYQh.d.ts} +23 -11
- package/dist/{types-CIlTojhq.d.ts → types-ClZaWzfb.d.ts} +9 -6
- package/dist/types-DX0LaKTb.d.ts +157 -0
- package/dist/types-DiQjupG2.d.ts +332 -0
- package/dist/types-DqzsnlSA.js +67 -0
- package/dist/types-_sHy8BQf.d.ts +65 -0
- package/dist/{types-ByUo56un.d.ts → types-fbZ7JEXr.d.ts} +23 -22
- package/dist/{types-DHrmBJLH.d.ts → types-tIgIeIKJ.d.ts} +7 -7
- package/dist/unplugin/index.d.ts +1 -1
- package/dist/unplugin/index.js +2 -2
- package/dist/usage-CHOtwL19.js +1 -0
- package/dist/usage-DHtE8j4E.js +32 -0
- package/dist/{usage-CG9nOYZw.js → usage-T5mXq98v.js} +54 -11
- package/dist/{validation-error-BSSw0l_8.d.ts → validation-error-Bg5Tpluk.d.ts} +1 -1
- package/dist/{validity-dVrUEPJt.js → validity-CZ7-y0Cj.js} +32 -15
- package/dist/{verifier-DMr_Zmb_.js → verifier-DHuh-okk.js} +18 -7
- package/dist/{verify-BztUB3GX.js → verify-DbCL9bnB.js} +645 -50
- package/dist/{version-BEogC-rB.js → version-CEbQ5UeM.js} +4 -3
- package/dist/version-DXkYUISx.js +1 -0
- package/dist/{views-CJsrBS1f.js → views-DTIIO-oQ.js} +22 -5
- package/dist/{permission-types-Dg39z9Kv.d.ts → vocabulary-D6lPdb4Z.d.ts} +65 -2
- package/dist/vue/index.d.ts +9 -10
- package/dist/vue/index.js +8 -8
- package/dist/waiter-BGUtGYoU.js +67 -0
- package/dist/waiter-CKy4MQSY.d.ts +36 -0
- package/dist/watch-Cb-NcaUw.js +1 -0
- package/dist/{watch-zeucB7eF.js → watch-CszoTJMq.js} +44 -5
- package/dist/webmcp/index.d.ts +2 -2
- package/dist/webmcp/index.js +3 -3
- package/dist/where-scope-Dv-WTP-w.js +306 -0
- package/dist/who-can-D0QoYbEb.js +364 -0
- package/dist/wire-delegation-Cv3W2eaM.js +36 -0
- package/dist/wire-denial-C7PaVYEM.js +27 -0
- package/dist/workflow/index.d.ts +5 -0
- package/dist/workflow/index.js +223 -0
- package/dist/workflow-sdk/index.d.ts +56 -0
- package/dist/workflow-sdk/index.js +78 -0
- package/dist/{wrap-Cr93qqdP.d.ts → wrap-Bd1Tejur.d.ts} +2 -1
- package/dist/{wrap-DWsU_5Bd.js → wrap-gX61EtpB.js} +7 -6
- package/package.json +136 -37
- package/schemas/access-event-v1.json +118 -0
- package/schemas/approval-request-v1.json +34 -1
- package/schemas/approval-signature-v1.json +94 -0
- package/schemas/automation-event-v1.json +113 -0
- package/schemas/capability-v1.json +84 -0
- package/schemas/catalog-event-v1.json +87 -0
- package/schemas/catalog-v1.json +123 -12
- package/schemas/cli-commands-v1.json +164 -0
- package/schemas/cli-result-v1.json +96 -0
- package/schemas/cloud-api-v1.json +5407 -0
- package/schemas/connector-v1.json +408 -0
- package/schemas/credential-event-v1.json +81 -0
- package/schemas/credential-v1.json +134 -0
- package/schemas/decision-event-v1.json +288 -0
- package/schemas/delivery-event-v1.json +117 -0
- package/schemas/directory-event-v1.json +85 -0
- package/schemas/evidence-export-v1.json +54 -0
- package/schemas/membership-event-v1.json +93 -0
- package/schemas/policy-v1.json +68 -0
- package/schemas/pushed-policy-v1.json +236 -0
- package/schemas/run-v1.json +162 -0
- package/schemas/snapshot-v1.json +138 -0
- package/schemas/supabase-claims-v1.json +4 -4
- package/schemas/supabase-manifest-v1.json +5 -1
- package/schemas/support-session-v1.json +111 -0
- package/skills/permdock/SKILL.md +16 -12
- package/skills/permdock-agents/SKILL.md +40 -23
- package/skills/permdock-agents/references/operations-automations-chat.md +221 -0
- package/skills/permdock-agents/references/runtimes.md +22 -18
- package/skills/permdock-approvals/SKILL.md +29 -13
- package/skills/permdock-approvals/references/delivery-and-waiters.md +172 -0
- package/skills/permdock-approvals/references/stores-and-resume.md +21 -7
- package/skills/permdock-audit/SKILL.md +3 -3
- package/skills/permdock-credentials/SKILL.md +5 -5
- package/skills/permdock-credentials/references/tokens-keys-links.md +14 -10
- package/skills/permdock-data/SKILL.md +6 -6
- package/skills/permdock-data/references/queries-and-rls.md +9 -8
- package/skills/permdock-data/references/relationships.md +3 -3
- package/skills/permdock-tenancy/SKILL.md +20 -7
- package/skills/permdock-tenancy/references/contacts-and-support-sessions.md +122 -0
- package/skills/permdock-tenancy/references/ownership-and-custom-roles.md +5 -4
- package/skills/permdock-wire/SKILL.md +17 -11
- package/skills/permdock-wire/references/adapters.md +139 -51
- package/skills/permdock-wire/references/policy-options.md +5 -5
- package/skills/permdock-wire/references/presets-and-recipes.md +58 -0
- package/dist/approvals-DZL76lKW.js +0 -240
- package/dist/arazzo-CD8d0WLb.js +0 -54
- package/dist/catalog-6yWAX6Ps.js +0 -2
- package/dist/catalog-WHG4kBq7.js +0 -48
- package/dist/cloud-C7bSDgX4.js +0 -50
- package/dist/cloud-PeBN3IEn.js +0 -118
- package/dist/collect-Bw2Jdq1q.js +0 -2
- package/dist/collect-CQx4hX4N.js +0 -83
- package/dist/commands-Cpip4ULx.js +0 -97
- package/dist/config-DLt6BvV7.js +0 -36
- package/dist/diff-Cnghh_Ip.js +0 -48
- package/dist/doctor-CuVJvhV_.js +0 -53
- package/dist/duration-xK2jGFVc.js +0 -25
- package/dist/errors-CWfoNg9N.js +0 -47
- package/dist/errors-DRnGZHzF.js +0 -30
- package/dist/expiry-BoBJ8Tvc.js +0 -7
- package/dist/fields-fwfXN01n.js +0 -1016
- package/dist/headers-BZSDieNT.js +0 -6
- package/dist/headers-Cf-zWvsO.d.ts +0 -6
- package/dist/ids-DC4V4CFu.js +0 -18
- package/dist/index-DgM7w96K.d.ts +0 -6
- package/dist/index-Dz7didpC.d.ts +0 -201
- package/dist/load-B_shHrmd.js +0 -2
- package/dist/manifest-BngWKryL.js +0 -770
- package/dist/may-use-BOn_dR_w.js +0 -78
- package/dist/openapi-DcQ1Kg40.js +0 -164
- package/dist/ownership-BgnbOJFT.js +0 -851
- package/dist/permdock-L26udHSk.js +0 -3646
- package/dist/powersync-BFSbSElQ.js +0 -62
- package/dist/powersync-DCDgZgfZ.js +0 -2
- package/dist/rls-55DQTuf5.js +0 -250
- package/dist/run-DMcNW_8T.js +0 -174
- package/dist/server-ZYEHtNHS.js +0 -268
- package/dist/sink-BTtmfPnE.js +0 -141
- package/dist/sink-CPN4zLfs.d.ts +0 -104
- package/dist/skills-Dle4ZoLF.js +0 -56
- package/dist/snapshot-Dc9CHPME.js +0 -1078
- package/dist/src-Bb7no-hS.js +0 -639
- package/dist/subject-C6dLxqHU.js +0 -24
- package/dist/supabase-Dbqr141s.js +0 -83
- package/dist/supabase-hook-BULg7Ut_.js +0 -2
- package/dist/thenable-QSmvt-vZ.js +0 -65
- package/dist/types-C0dee0Qf.d.ts +0 -197
- package/dist/types-DvupZE0w.d.ts +0 -9
- package/dist/usage-4G6t643F.js +0 -42
- package/dist/usage-iFLJ0-rr.js +0 -2
- package/dist/vocabulary-hhEFLFoL.d.ts +0 -65
- package/dist/watch-C8TpsAl4.js +0 -2
|
@@ -0,0 +1,2084 @@
|
|
|
1
|
+
import { n as CliError } from "./errors-CWTY6uih.js";
|
|
2
|
+
import { a as rel } from "./files-D_JIzUrP.js";
|
|
3
|
+
import { t as beforeFirst } from "./text-BMFRfBqc.js";
|
|
4
|
+
import { n as ROOT } from "./manifest-CtKR3GXL.js";
|
|
5
|
+
import { i as renameMessage, n as DEFAULT_CHANGES, r as flagRename, t as COMMAND_MOVES } from "./renames-CGj7YwcQ.js";
|
|
6
|
+
import { r as refuseDirty, t as applyFiles } from "./files-C5ZI27eV.js";
|
|
7
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
8
|
+
import { extname, join, resolve } from "node:path";
|
|
9
|
+
import { Visitor, parseSync, visitorKeys } from "oxc-parser";
|
|
10
|
+
//#region src/cli/codemod/cli-calls.ts
|
|
11
|
+
/** `permdock`, `npx permdock@0.4`, `pnpm exec permdock`: the bin name followed by a space. */
|
|
12
|
+
const INVOCATION = /(?<![\w./@-])permdock(?:@[\w.^~-]+)?(?=[ \t])/gu;
|
|
13
|
+
/**
|
|
14
|
+
* Where a shell command ends: an operator, a pipe, a redirect, a comment or
|
|
15
|
+
* a closing backtick. A JSON string also ends at its closing quote. `<id>`
|
|
16
|
+
* is a placeholder, not a redirect, so a redirect needs a space on both sides.
|
|
17
|
+
*/
|
|
18
|
+
function commandEnd(text, from, json) {
|
|
19
|
+
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));
|
|
20
|
+
return match === null ? text.length : from + match.index;
|
|
21
|
+
}
|
|
22
|
+
function tokensOf(text, start, end) {
|
|
23
|
+
return [...text.slice(start, end).matchAll(/\S+/gu)].map((match) => ({
|
|
24
|
+
start: start + match.index,
|
|
25
|
+
end: start + match.index + match[0].length,
|
|
26
|
+
text: match[0]
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
function lineColumn(text, offset) {
|
|
30
|
+
const before = text.slice(0, offset);
|
|
31
|
+
return {
|
|
32
|
+
line: before.split("\n").length,
|
|
33
|
+
column: offset - before.lastIndexOf("\n")
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** The leaf path the positional tokens name, with the token after which a moved subcommand goes. */
|
|
37
|
+
function commandOf(tokens) {
|
|
38
|
+
let node = ROOT;
|
|
39
|
+
const path = [];
|
|
40
|
+
let last;
|
|
41
|
+
for (const token of tokens) {
|
|
42
|
+
if (token.text.startsWith("-")) continue;
|
|
43
|
+
const child = node.children.find((item) => item.name === token.text);
|
|
44
|
+
if (child === void 0) break;
|
|
45
|
+
path.push(child.name);
|
|
46
|
+
last = token;
|
|
47
|
+
if (child.kind === "leaf") return { command: path.join(" ") };
|
|
48
|
+
node = child;
|
|
49
|
+
}
|
|
50
|
+
const move = COMMAND_MOVES.find((item) => item.from === path.join(" "));
|
|
51
|
+
if (move === void 0 || last === void 0) return { command: void 0 };
|
|
52
|
+
return {
|
|
53
|
+
command: move.to,
|
|
54
|
+
insertAfter: last,
|
|
55
|
+
insert: move.to.slice(move.from.length + 1)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function flagEdits(command, tokens, notes) {
|
|
59
|
+
const edits = [];
|
|
60
|
+
for (const [index, token] of tokens.entries()) {
|
|
61
|
+
if (!token.text.startsWith("--")) continue;
|
|
62
|
+
const eq = token.text.indexOf("=");
|
|
63
|
+
const name = eq === -1 ? token.text : token.text.slice(0, eq);
|
|
64
|
+
const rename = flagRename(command, name);
|
|
65
|
+
if (rename === void 0) continue;
|
|
66
|
+
const edit = flagEdit(rename, token, eq, tokens[index + 1]);
|
|
67
|
+
if (edit === void 0) notes.push({
|
|
68
|
+
at: token.start,
|
|
69
|
+
message: renameMessage(command, rename)
|
|
70
|
+
});
|
|
71
|
+
else edits.push(...edit);
|
|
72
|
+
}
|
|
73
|
+
return edits;
|
|
74
|
+
}
|
|
75
|
+
function flagEdit(rename, token, eq, next) {
|
|
76
|
+
if (rename.rewrite !== void 0) return eq === -1 ? [{
|
|
77
|
+
start: token.start,
|
|
78
|
+
end: token.end,
|
|
79
|
+
text: rename.rewrite,
|
|
80
|
+
from: token.text
|
|
81
|
+
}] : void 0;
|
|
82
|
+
if (rename.to === void 0 || rename.hint !== void 0) return;
|
|
83
|
+
if (rename.values === void 0) {
|
|
84
|
+
const value = eq === -1 ? "" : token.text.slice(eq);
|
|
85
|
+
return [{
|
|
86
|
+
start: token.start,
|
|
87
|
+
end: token.end,
|
|
88
|
+
text: `${rename.to}${value}`,
|
|
89
|
+
from: token.text
|
|
90
|
+
}];
|
|
91
|
+
}
|
|
92
|
+
if (eq !== -1) {
|
|
93
|
+
const mapped = mappedValue(rename.values, token.text.slice(eq + 1));
|
|
94
|
+
return mapped === void 0 ? void 0 : [{
|
|
95
|
+
start: token.start,
|
|
96
|
+
end: token.end,
|
|
97
|
+
text: `${rename.to}=${mapped}`,
|
|
98
|
+
from: token.text
|
|
99
|
+
}];
|
|
100
|
+
}
|
|
101
|
+
const mapped = next === void 0 ? void 0 : mappedValue(rename.values, next.text);
|
|
102
|
+
if (next === void 0 || mapped === void 0) return;
|
|
103
|
+
return [{
|
|
104
|
+
start: token.start,
|
|
105
|
+
end: token.end,
|
|
106
|
+
text: rename.to,
|
|
107
|
+
from: token.text
|
|
108
|
+
}, {
|
|
109
|
+
start: next.start,
|
|
110
|
+
end: next.end,
|
|
111
|
+
text: mapped,
|
|
112
|
+
from: next.text
|
|
113
|
+
}];
|
|
114
|
+
}
|
|
115
|
+
function mappedValue(values, value) {
|
|
116
|
+
return Object.hasOwn(values, value) ? values[value] : void 0;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Rewrites the 0.5.0 CLI renames in shell commands: package.json scripts,
|
|
120
|
+
* CI workflows, shell scripts. A rename that needs a person, such as an
|
|
121
|
+
* environment name that must become a project id, is a follow-up instead.
|
|
122
|
+
*/
|
|
123
|
+
function rewriteCliCalls(text, options) {
|
|
124
|
+
const edits = [];
|
|
125
|
+
const notes = [];
|
|
126
|
+
for (const match of text.matchAll(INVOCATION)) {
|
|
127
|
+
const start = match.index + match[0].length;
|
|
128
|
+
const tokens = tokensOf(text, start, commandEnd(text, start, options.json));
|
|
129
|
+
const { command, insertAfter, insert } = commandOf(tokens);
|
|
130
|
+
if (command === void 0) continue;
|
|
131
|
+
if (insertAfter !== void 0 && insert !== void 0) edits.push({
|
|
132
|
+
start: insertAfter.end,
|
|
133
|
+
end: insertAfter.end,
|
|
134
|
+
text: ` ${insert}`,
|
|
135
|
+
from: insertAfter.text
|
|
136
|
+
});
|
|
137
|
+
edits.push(...flagEdits(command, tokens, notes));
|
|
138
|
+
for (const change of DEFAULT_CHANGES) {
|
|
139
|
+
const given = new Set(tokens.map((token) => token.text));
|
|
140
|
+
const last = tokens.at(-1);
|
|
141
|
+
if (change.command === command && last !== void 0 && !change.unless.some((flag) => given.has(flag)) && !given.has(change.add)) edits.push({
|
|
142
|
+
start: last.end,
|
|
143
|
+
end: last.end,
|
|
144
|
+
text: ` ${change.add}`,
|
|
145
|
+
from: last.text
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const changes = [];
|
|
150
|
+
let out = text;
|
|
151
|
+
for (const edit of edits.toSorted((a, b) => b.start - a.start)) {
|
|
152
|
+
const { start, end } = edit.text === "" ? dropWithSpace(out, edit) : edit;
|
|
153
|
+
out = `${out.slice(0, start)}${edit.text}${out.slice(end)}`;
|
|
154
|
+
changes.push({
|
|
155
|
+
...lineColumn(text, edit.start),
|
|
156
|
+
from: edit.from,
|
|
157
|
+
to: edit.start === edit.end ? `${edit.from}${edit.text}` : edit.text === "" ? "(removed)" : edit.text
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
text: out,
|
|
162
|
+
changes: changes.toReversed(),
|
|
163
|
+
followUps: notes.map((note) => {
|
|
164
|
+
const { line, column } = lineColumn(text, note.at);
|
|
165
|
+
return {
|
|
166
|
+
line,
|
|
167
|
+
column,
|
|
168
|
+
name: "cli",
|
|
169
|
+
message: note.message
|
|
170
|
+
};
|
|
171
|
+
})
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** A dropped flag takes the space before it, so `a --legacy b` becomes `a b`. */
|
|
175
|
+
function dropWithSpace(text, edit) {
|
|
176
|
+
return text[edit.start - 1] === " " ? {
|
|
177
|
+
start: edit.start - 1,
|
|
178
|
+
end: edit.end
|
|
179
|
+
} : edit;
|
|
180
|
+
}
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/cli/codemod/renames-0.5.ts
|
|
183
|
+
const SERVER_ADAPTERS = [
|
|
184
|
+
"permdock/server",
|
|
185
|
+
"permdock/hono",
|
|
186
|
+
"permdock/express",
|
|
187
|
+
"permdock/fastify",
|
|
188
|
+
"permdock/elysia",
|
|
189
|
+
"permdock/nest",
|
|
190
|
+
"permdock/node"
|
|
191
|
+
];
|
|
192
|
+
const rows = [
|
|
193
|
+
{
|
|
194
|
+
from: "createServerKernel",
|
|
195
|
+
to: "createPermDock",
|
|
196
|
+
entries: ["permdock/server"]
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
from: "ServerKernel",
|
|
200
|
+
to: "ServerPermDock",
|
|
201
|
+
entries: ["permdock/server"],
|
|
202
|
+
kind: "type"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
from: "ServerKernelOptions",
|
|
206
|
+
to: "ServerPermDockOptions",
|
|
207
|
+
entries: ["permdock/server"],
|
|
208
|
+
kind: "type"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
from: "createEvaluationsHandler",
|
|
212
|
+
to: "evaluationsHandler",
|
|
213
|
+
entries: ["permdock/server"]
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
from: "createNativeStore",
|
|
217
|
+
to: "nativeStore",
|
|
218
|
+
entries: ["permdock/react-native"]
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
from: "permdock",
|
|
222
|
+
to: "getPermDock",
|
|
223
|
+
entries: [
|
|
224
|
+
"permdock/server",
|
|
225
|
+
"permdock/node",
|
|
226
|
+
"permdock/terminal",
|
|
227
|
+
"permdock/openai",
|
|
228
|
+
"permdock/claude-agent",
|
|
229
|
+
"permdock/eve"
|
|
230
|
+
],
|
|
231
|
+
kind: "method"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
from: "permdock",
|
|
235
|
+
to: "middleware",
|
|
236
|
+
entries: [
|
|
237
|
+
"permdock/hono",
|
|
238
|
+
"permdock/express",
|
|
239
|
+
"permdock/elysia",
|
|
240
|
+
"permdock/trpc",
|
|
241
|
+
"permdock/orpc"
|
|
242
|
+
],
|
|
243
|
+
kind: "method"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
from: "load",
|
|
247
|
+
to: "data",
|
|
248
|
+
entries: ["permdock/authzen"],
|
|
249
|
+
kind: "option"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
from: "loadData",
|
|
253
|
+
to: "data",
|
|
254
|
+
entries: ["permdock/nest"],
|
|
255
|
+
kind: "option"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
from: "onDenied",
|
|
259
|
+
to: "deniedResponse",
|
|
260
|
+
entries: [
|
|
261
|
+
...SERVER_ADAPTERS,
|
|
262
|
+
"permdock/trpc",
|
|
263
|
+
"permdock/orpc",
|
|
264
|
+
"permdock/supabase/middleware"
|
|
265
|
+
],
|
|
266
|
+
kind: "option",
|
|
267
|
+
calls: ["createPermDock"]
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
from: "onDenied",
|
|
271
|
+
to: "deniedText",
|
|
272
|
+
entries: ["permdock/ai-sdk", "permdock/mcp"],
|
|
273
|
+
kind: "option",
|
|
274
|
+
calls: ["createPermDock"]
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
from: "tools",
|
|
278
|
+
to: "operations",
|
|
279
|
+
entries: [
|
|
280
|
+
"permdock/ai-sdk",
|
|
281
|
+
"permdock/openai",
|
|
282
|
+
"permdock/claude-agent",
|
|
283
|
+
"permdock/eve"
|
|
284
|
+
],
|
|
285
|
+
kind: "option",
|
|
286
|
+
calls: ["createPermDock"]
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
from: "OnDenied",
|
|
290
|
+
to: "DeniedResponse",
|
|
291
|
+
entries: ["permdock/server"],
|
|
292
|
+
kind: "type"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
from: "OnDeniedEvent",
|
|
296
|
+
to: "DeniedResponseEvent",
|
|
297
|
+
entries: ["permdock/server"],
|
|
298
|
+
kind: "type"
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
from: "OnDeniedText",
|
|
302
|
+
to: "DeniedText",
|
|
303
|
+
entries: ["permdock/ai-sdk", "permdock/mcp"],
|
|
304
|
+
kind: "type"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
from: "PermDockRequest",
|
|
308
|
+
to: "ExpressPermDockRequest",
|
|
309
|
+
entries: ["permdock/express"],
|
|
310
|
+
kind: "type"
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
from: "PermDockRequest",
|
|
314
|
+
to: "FastifyPermDockRequest",
|
|
315
|
+
entries: ["permdock/fastify"],
|
|
316
|
+
kind: "type"
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
from: "PermDockEnv",
|
|
320
|
+
to: "HonoPermDockEnv",
|
|
321
|
+
entries: ["permdock/hono"],
|
|
322
|
+
kind: "type"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
from: "ElysiaContext",
|
|
326
|
+
to: "ElysiaPermDockContext",
|
|
327
|
+
entries: ["permdock/elysia"],
|
|
328
|
+
kind: "type"
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
from: "ElysiaCtx",
|
|
332
|
+
to: "ElysiaRequestContext",
|
|
333
|
+
entries: ["permdock/elysia"],
|
|
334
|
+
kind: "type"
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
from: "ConvexPermDockCtx",
|
|
338
|
+
to: "ConvexPermDockContext",
|
|
339
|
+
entries: ["permdock/convex"],
|
|
340
|
+
kind: "type"
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
from: "ServerPermDockProviderProps",
|
|
344
|
+
to: "NextPermDockProviderProps",
|
|
345
|
+
entries: ["permdock/next"],
|
|
346
|
+
kind: "type"
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
from: "NativePermDockProviderProps",
|
|
350
|
+
to: "ReactNativePermDockProviderProps",
|
|
351
|
+
entries: ["permdock/react-native"],
|
|
352
|
+
kind: "type"
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
from: "PermDockSvelteOptions",
|
|
356
|
+
to: "SveltePermDockOptions",
|
|
357
|
+
entries: ["permdock/svelte"],
|
|
358
|
+
kind: "type"
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
from: "subjectFromSession",
|
|
362
|
+
to: "subjectFromEve",
|
|
363
|
+
entries: ["permdock/eve"]
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
from: "actorFromSession",
|
|
367
|
+
to: "actorFromEve",
|
|
368
|
+
entries: ["permdock/eve"]
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
from: "CredentialPrincipal",
|
|
372
|
+
to: "ApiKeyPrincipal",
|
|
373
|
+
entries: ["permdock"],
|
|
374
|
+
kind: "type"
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
from: "LinkPrincipal",
|
|
378
|
+
to: "CapabilityPrincipal",
|
|
379
|
+
entries: ["permdock"],
|
|
380
|
+
kind: "type"
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
from: "SsfSubjectMapper",
|
|
384
|
+
to: "SsfSubjectResolver",
|
|
385
|
+
entries: ["permdock/ssf"],
|
|
386
|
+
kind: "type"
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
from: "memorySettings",
|
|
390
|
+
to: "memorySettingsSource",
|
|
391
|
+
entries: ["permdock"]
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
from: "memoryRelations",
|
|
395
|
+
to: "memoryRelationSource",
|
|
396
|
+
entries: ["permdock"]
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
from: "memorySink",
|
|
400
|
+
to: "memoryDecisionSink",
|
|
401
|
+
entries: ["permdock"]
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
from: "memoryApprovalPolicies",
|
|
405
|
+
to: "memoryApprovalPolicySource",
|
|
406
|
+
entries: ["permdock"]
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
from: "memoryApprovalDelegations",
|
|
410
|
+
to: "memoryApprovalDelegationSource",
|
|
411
|
+
entries: ["permdock/approvals"]
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
from: "memoryAccessReviews",
|
|
415
|
+
to: "memoryAccessReviewStore",
|
|
416
|
+
entries: ["permdock/approvals"]
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
from: "MemoryAccessReviews",
|
|
420
|
+
to: "MemoryAccessReviewStore",
|
|
421
|
+
entries: ["permdock/approvals"],
|
|
422
|
+
kind: "type"
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
from: "MemoryRelationsData",
|
|
426
|
+
to: "MemoryRelationSourceData",
|
|
427
|
+
entries: ["permdock"],
|
|
428
|
+
kind: "type"
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
from: "MemorySink",
|
|
432
|
+
to: "MemoryDecisionSink",
|
|
433
|
+
entries: ["permdock"],
|
|
434
|
+
kind: "type"
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
from: "MemorySinkOptions",
|
|
438
|
+
to: "MemoryDecisionSinkOptions",
|
|
439
|
+
entries: ["permdock"],
|
|
440
|
+
kind: "type"
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
from: "memoryCredentials",
|
|
444
|
+
to: "memoryCredentialStore",
|
|
445
|
+
entries: ["permdock/server"]
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
from: "MemoryCredentials",
|
|
449
|
+
to: "MemoryCredentialStore",
|
|
450
|
+
entries: ["permdock/server"],
|
|
451
|
+
kind: "type"
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
from: "memoryStorage",
|
|
455
|
+
to: "memorySnapshotStorage",
|
|
456
|
+
entries: ["permdock/react-native"]
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
from: "rlsParity",
|
|
460
|
+
to: "testRlsParity",
|
|
461
|
+
entries: ["permdock/testing"]
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
from: "ormParity",
|
|
465
|
+
to: "testOrmParity",
|
|
466
|
+
entries: ["permdock/testing"]
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
from: "fromStripeEntitlements",
|
|
470
|
+
to: "stripeEntitlementSource",
|
|
471
|
+
entries: ["permdock"]
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
from: "fromTable",
|
|
475
|
+
to: "tableMembershipSource",
|
|
476
|
+
entries: ["permdock/supabase"]
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
from: "fromJunction",
|
|
480
|
+
to: "junctionMembershipSource",
|
|
481
|
+
entries: ["permdock/supabase"]
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
from: "fromSupabasePostgres",
|
|
485
|
+
to: "supabasePostgresQuery",
|
|
486
|
+
entries: ["permdock/supabase"]
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
from: "verifyWebBotAuth",
|
|
490
|
+
to: "webBotAuthVerifier",
|
|
491
|
+
entries: SERVER_ADAPTERS
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
from: "RoleSource",
|
|
495
|
+
to: "CustomRoleSource",
|
|
496
|
+
entries: ["permdock"],
|
|
497
|
+
kind: "type"
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
from: "RoleSourceFactory",
|
|
501
|
+
to: "CustomRoleSourceFactory",
|
|
502
|
+
entries: ["permdock"],
|
|
503
|
+
kind: "type"
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
from: "memoryRoleSource",
|
|
507
|
+
to: "memoryCustomRoleSource",
|
|
508
|
+
entries: ["permdock"]
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
from: "testRoleSource",
|
|
512
|
+
to: "testCustomRoleSource",
|
|
513
|
+
entries: ["permdock/testing"]
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
from: "betterAuthRoleSource",
|
|
517
|
+
to: "betterAuthCustomRoleSource",
|
|
518
|
+
entries: ["permdock/better-auth"]
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
from: "BetterAuthRoleSourceOptions",
|
|
522
|
+
to: "BetterAuthCustomRoleSourceOptions",
|
|
523
|
+
entries: ["permdock/better-auth"],
|
|
524
|
+
kind: "type"
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
from: "PermDockStorage",
|
|
528
|
+
to: "SnapshotStorage",
|
|
529
|
+
entries: ["permdock/react-native"],
|
|
530
|
+
kind: "type"
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
from: "store",
|
|
534
|
+
to: "directory",
|
|
535
|
+
entries: ["permdock/scim"],
|
|
536
|
+
kind: "option",
|
|
537
|
+
calls: ["scimHandler"]
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
from: "store",
|
|
541
|
+
to: "reviews",
|
|
542
|
+
entries: ["permdock/approvals"],
|
|
543
|
+
kind: "option",
|
|
544
|
+
calls: ["startAccessReview"]
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
from: "delegations",
|
|
548
|
+
to: "approvalDelegations",
|
|
549
|
+
entries: ["permdock/approvals"],
|
|
550
|
+
kind: "option",
|
|
551
|
+
calls: ["approvalsHandler", "matchDelegation"]
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
from: "source",
|
|
555
|
+
to: "call",
|
|
556
|
+
entries: ["permdock"],
|
|
557
|
+
kind: "option"
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
from: "testAuthZen",
|
|
561
|
+
to: "testAuthzen",
|
|
562
|
+
entries: ["permdock/testing"]
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
from: "AuthZenVectors",
|
|
566
|
+
to: "AuthzenVectors",
|
|
567
|
+
entries: ["permdock/testing"],
|
|
568
|
+
kind: "type"
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
from: "AuthZenEvaluationVector",
|
|
572
|
+
to: "AuthzenEvaluationVector",
|
|
573
|
+
entries: ["permdock/testing"],
|
|
574
|
+
kind: "type"
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
from: "AuthZenEvaluationsVector",
|
|
578
|
+
to: "AuthzenEvaluationsVector",
|
|
579
|
+
entries: ["permdock/testing"],
|
|
580
|
+
kind: "type"
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
from: "AuthZenSearchVector",
|
|
584
|
+
to: "AuthzenSearchVector",
|
|
585
|
+
entries: ["permdock/testing"],
|
|
586
|
+
kind: "type"
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
from: "TestAuthZenOptions",
|
|
590
|
+
to: "TestAuthzenOptions",
|
|
591
|
+
entries: ["permdock/testing"],
|
|
592
|
+
kind: "type"
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
from: "powersyncSource",
|
|
596
|
+
to: "powerSyncSource",
|
|
597
|
+
entries: ["permdock/react-native"]
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
from: "summariseSubject",
|
|
601
|
+
to: "summarizeSubject",
|
|
602
|
+
entries: ["permdock/approvals"]
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
from: "WebhookFailureReason",
|
|
606
|
+
to: "WebhookFailureCause",
|
|
607
|
+
entries: ["permdock/cloud"],
|
|
608
|
+
kind: "type"
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
from: "ApprovalResumeFailure",
|
|
612
|
+
to: "ApprovalResumeFailureCause",
|
|
613
|
+
entries: ["permdock/approvals"],
|
|
614
|
+
kind: "type"
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
from: "window",
|
|
618
|
+
to: "per",
|
|
619
|
+
entries: ["permdock", ...SERVER_ADAPTERS],
|
|
620
|
+
kind: "method"
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
from: "DefinePermissionsOptions",
|
|
624
|
+
to: "PermissionsOptions",
|
|
625
|
+
entries: ["permdock"],
|
|
626
|
+
kind: "type"
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
from: "SignCapabilityOptions",
|
|
630
|
+
to: "CapabilityOptions",
|
|
631
|
+
entries: ["permdock"],
|
|
632
|
+
kind: "type"
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
from: "SignRunTicketOptions",
|
|
636
|
+
to: "RunTicketOptions",
|
|
637
|
+
entries: ["permdock/server"],
|
|
638
|
+
kind: "type"
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
from: "StartAccessReviewOptions",
|
|
642
|
+
to: "AccessReviewOptions",
|
|
643
|
+
entries: ["permdock/approvals"],
|
|
644
|
+
kind: "type"
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
from: "StartAutomationOptions",
|
|
648
|
+
to: "AutomationOptions",
|
|
649
|
+
entries: ["permdock/workflow", "permdock/workflow-sdk"],
|
|
650
|
+
kind: "type"
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
from: "VerifyWebhookOptions",
|
|
654
|
+
to: "WebhookOptions",
|
|
655
|
+
entries: ["permdock/cloud"],
|
|
656
|
+
kind: "type"
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
from: "UseRolesOptions",
|
|
660
|
+
to: "RolesOptions",
|
|
661
|
+
entries: [
|
|
662
|
+
"permdock/vue",
|
|
663
|
+
"permdock/svelte",
|
|
664
|
+
"permdock/solid"
|
|
665
|
+
],
|
|
666
|
+
kind: "type"
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
from: "ConvexCtxLike",
|
|
670
|
+
to: "ConvexContextLike",
|
|
671
|
+
entries: ["permdock/convex"],
|
|
672
|
+
kind: "type"
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
from: "createJwtSubjectResolver",
|
|
676
|
+
to: "jwtSubjectResolver",
|
|
677
|
+
entries: ["permdock/jwt"]
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
from: "createClerkSubjectResolver",
|
|
681
|
+
to: "clerkSubjectResolver",
|
|
682
|
+
entries: ["permdock/clerk"]
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
from: "fromResponse",
|
|
686
|
+
to: "sendResponse",
|
|
687
|
+
entries: ["permdock/node"]
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
from: "fromResponse",
|
|
691
|
+
to: "send",
|
|
692
|
+
entries: ["permdock/node"],
|
|
693
|
+
kind: "method"
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
from: "createPermDock",
|
|
697
|
+
to: "getPermDockSync",
|
|
698
|
+
entries: ["permdock"]
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
from: "createPermDock",
|
|
702
|
+
to: "getPermDock",
|
|
703
|
+
entries: ["permdock/pdp"]
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
from: "loadRelations",
|
|
707
|
+
to: "prefetchRelations",
|
|
708
|
+
entries: ["permdock", "permdock/pdp"],
|
|
709
|
+
kind: "method"
|
|
710
|
+
}
|
|
711
|
+
];
|
|
712
|
+
/** Every 0.5.0 rename, one row per `from` and target. */
|
|
713
|
+
const RENAMES_0_5 = Object.freeze(rows.map((row) => Object.freeze({
|
|
714
|
+
...row,
|
|
715
|
+
entries: Object.freeze([...row.entries]),
|
|
716
|
+
...row.calls === void 0 ? {} : { calls: Object.freeze([...row.calls]) }
|
|
717
|
+
})));
|
|
718
|
+
/** 0.5.0 changes the codemod lists as manual follow-ups. */
|
|
719
|
+
const SIGNATURE_CHANGES_0_5 = Object.freeze([
|
|
720
|
+
{
|
|
721
|
+
name: "permittedIds",
|
|
722
|
+
entries: ["permdock"],
|
|
723
|
+
before: "permittedIds(permdock, permission, scope)",
|
|
724
|
+
after: "permdock.permittedIds(permission, scope)"
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
name: "mayUse",
|
|
728
|
+
entries: ["permdock"],
|
|
729
|
+
before: "mayUse(permdock, permission)",
|
|
730
|
+
after: "permdock.mayUse(permission)"
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
name: "subjectFromApiKey",
|
|
734
|
+
entries: ["permdock/server"],
|
|
735
|
+
before: "subjectFromApiKey(options)(key)",
|
|
736
|
+
after: "subjectFromApiKey(key, options)",
|
|
737
|
+
shape: "curried"
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
name: "subjectFromBetterAuth",
|
|
741
|
+
entries: ["permdock/better-auth"],
|
|
742
|
+
before: "subjectFromBetterAuth(auth, session, options)",
|
|
743
|
+
after: "subjectFromBetterAuth(session, { auth, ...options })"
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
name: "capabilitySubject",
|
|
747
|
+
entries: ["permdock"],
|
|
748
|
+
before: "capabilitySubject(...)",
|
|
749
|
+
after: "subjectFromCapability(token, options)"
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
name: "credentialSubject",
|
|
753
|
+
entries: ["permdock"],
|
|
754
|
+
before: "credentialSubject(...)",
|
|
755
|
+
after: "subjectFromApiKey(key, options)"
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
name: "MappedSubject",
|
|
759
|
+
entries: ["permdock/jwt"],
|
|
760
|
+
before: "MappedSubject",
|
|
761
|
+
after: "Subject<JwtPrincipal>"
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
name: "verifyWebBotAuth",
|
|
765
|
+
entries: SERVER_ADAPTERS,
|
|
766
|
+
before: "verifyWebBotAuth(request, options)",
|
|
767
|
+
after: "webBotAuthVerifier(options)(request)"
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
name: "verifyWebhook",
|
|
771
|
+
entries: ["permdock/cloud"],
|
|
772
|
+
before: "verifyWebhook(request, options).reason",
|
|
773
|
+
after: "verifyWebhook(request, options).cause"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
name: "inspectApproval",
|
|
777
|
+
entries: ["permdock/approvals"],
|
|
778
|
+
before: "inspectApproval(store, token).detail",
|
|
779
|
+
after: "inspectApproval(store, token).cause"
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
name: "consumeApproval",
|
|
783
|
+
entries: ["permdock/approvals"],
|
|
784
|
+
before: "consumeApproval(store, token).detail",
|
|
785
|
+
after: "consumeApproval(store, token).cause"
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
name: "requireAccess",
|
|
789
|
+
entries: ["permdock/next"],
|
|
790
|
+
before: "requireAccess({ permission, data, tenant, onDenied })",
|
|
791
|
+
after: "requirePermission(permission, data, { tenant, onDenied })"
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
name: "RequireAccessInput",
|
|
795
|
+
entries: ["permdock/next"],
|
|
796
|
+
before: "RequireAccessInput",
|
|
797
|
+
after: "PermissionRequirementOptions"
|
|
798
|
+
}
|
|
799
|
+
]);
|
|
800
|
+
//#endregion
|
|
801
|
+
//#region src/cli/codemod/shapes-0.5.ts
|
|
802
|
+
const JSX_KITS = [
|
|
803
|
+
"permdock/react",
|
|
804
|
+
"permdock/react-native",
|
|
805
|
+
"permdock/solid"
|
|
806
|
+
];
|
|
807
|
+
const PROP_RENAMES_0_5 = Object.freeze([{
|
|
808
|
+
component: "Protected",
|
|
809
|
+
entries: [...JSX_KITS, "permdock/vue"],
|
|
810
|
+
from: "fallback",
|
|
811
|
+
to: "denied"
|
|
812
|
+
}, {
|
|
813
|
+
component: "PermDockProvider",
|
|
814
|
+
entries: JSX_KITS,
|
|
815
|
+
from: "fallback",
|
|
816
|
+
to: "denied",
|
|
817
|
+
within: "defaults"
|
|
818
|
+
}]);
|
|
819
|
+
const TEMPLATE_HINTS_0_5 = Object.freeze([{
|
|
820
|
+
component: "Protected",
|
|
821
|
+
entries: ["permdock/vue"],
|
|
822
|
+
pattern: /(?:#|v-slot:)fallback\b/gu,
|
|
823
|
+
name: "fallback",
|
|
824
|
+
message: "the `<Protected>` slot `fallback` is `denied`: `#denied`"
|
|
825
|
+
}, {
|
|
826
|
+
component: "Protected",
|
|
827
|
+
entries: ["permdock/svelte"],
|
|
828
|
+
pattern: /\{#snippet\s+fallback\b|\bslot=["']fallback["']/gu,
|
|
829
|
+
name: "fallback",
|
|
830
|
+
message: "the `<Protected>` snippet `fallback` is `denied`: `{#snippet denied(decision)}`"
|
|
831
|
+
}]);
|
|
832
|
+
const AWAIT_RENAMES_0_5 = Object.freeze([{
|
|
833
|
+
name: "createPermDock",
|
|
834
|
+
entries: ["permdock"],
|
|
835
|
+
to: "getPermDock",
|
|
836
|
+
sync: "getPermDockSync"
|
|
837
|
+
}]);
|
|
838
|
+
const CALL_RENAMES_0_5 = Object.freeze([{
|
|
839
|
+
from: "rolesOf",
|
|
840
|
+
to: "rolesFor",
|
|
841
|
+
entries: ["permdock"],
|
|
842
|
+
kind: "option",
|
|
843
|
+
calls: ["customRoleSource"]
|
|
844
|
+
}]);
|
|
845
|
+
const METHOD_FUNCTIONS_0_5 = Object.freeze([
|
|
846
|
+
"decideRoleChange",
|
|
847
|
+
"decideCredential",
|
|
848
|
+
"decideAutomation",
|
|
849
|
+
"decideSupportSession",
|
|
850
|
+
"whoCan"
|
|
851
|
+
].map((method) => ({
|
|
852
|
+
method,
|
|
853
|
+
to: method,
|
|
854
|
+
entry: "permdock",
|
|
855
|
+
anyReceiver: true
|
|
856
|
+
})).concat([{
|
|
857
|
+
method: "simulate",
|
|
858
|
+
to: "simulateArazzo",
|
|
859
|
+
entry: "permdock",
|
|
860
|
+
anyReceiver: true,
|
|
861
|
+
argument: "arazzo"
|
|
862
|
+
}, {
|
|
863
|
+
method: "activate",
|
|
864
|
+
to: "activate",
|
|
865
|
+
entry: "permdock",
|
|
866
|
+
anyReceiver: false
|
|
867
|
+
}]));
|
|
868
|
+
const FUNCTION_METHODS_0_5 = Object.freeze([{
|
|
869
|
+
name: "permittedIds",
|
|
870
|
+
entry: "permdock",
|
|
871
|
+
method: "permittedIds"
|
|
872
|
+
}, {
|
|
873
|
+
name: "mayUse",
|
|
874
|
+
entry: "permdock",
|
|
875
|
+
method: "mayUse"
|
|
876
|
+
}]);
|
|
877
|
+
const INSTANCE_FACTORIES = [
|
|
878
|
+
"createPermDock",
|
|
879
|
+
"getPermDock",
|
|
880
|
+
"getPermDockSync"
|
|
881
|
+
];
|
|
882
|
+
const OPTION_WRAPS_0_5 = Object.freeze([{
|
|
883
|
+
key: "approvalPolicies",
|
|
884
|
+
wrapper: "approvalPolicies",
|
|
885
|
+
entry: "permdock",
|
|
886
|
+
calls: INSTANCE_FACTORIES,
|
|
887
|
+
entries: ["permdock", "permdock/pdp"],
|
|
888
|
+
already: [
|
|
889
|
+
"approvalPolicies",
|
|
890
|
+
"memoryApprovalPolicySource",
|
|
891
|
+
"memoryApprovalPolicies"
|
|
892
|
+
],
|
|
893
|
+
reportElsewhere: true
|
|
894
|
+
}, {
|
|
895
|
+
key: "policies",
|
|
896
|
+
wrapper: "hostedPolicies",
|
|
897
|
+
entry: "permdock",
|
|
898
|
+
calls: INSTANCE_FACTORIES,
|
|
899
|
+
entries: ["permdock", "permdock/pdp"],
|
|
900
|
+
already: ["hostedPolicies"],
|
|
901
|
+
reportElsewhere: false
|
|
902
|
+
}]);
|
|
903
|
+
const DURATION_KEYS_0_5 = Object.freeze({
|
|
904
|
+
keys: [
|
|
905
|
+
"ttl",
|
|
906
|
+
"after",
|
|
907
|
+
"per",
|
|
908
|
+
"window",
|
|
909
|
+
"maxDuration",
|
|
910
|
+
"duration"
|
|
911
|
+
],
|
|
912
|
+
lists: ["durations"]
|
|
913
|
+
});
|
|
914
|
+
//#endregion
|
|
915
|
+
//#region src/cli/codemod/ast.ts
|
|
916
|
+
function nameOf(node) {
|
|
917
|
+
if (node?.type === "Literal") return typeof node.value === "string" ? node.value : void 0;
|
|
918
|
+
return node?.name;
|
|
919
|
+
}
|
|
920
|
+
const NOT_REFERENCES = /* @__PURE__ */ new Set([
|
|
921
|
+
"ImportSpecifier",
|
|
922
|
+
"ImportDefaultSpecifier",
|
|
923
|
+
"ImportNamespaceSpecifier",
|
|
924
|
+
"LabeledStatement",
|
|
925
|
+
"BreakStatement",
|
|
926
|
+
"ContinueStatement",
|
|
927
|
+
"TSEnumMember",
|
|
928
|
+
"TSModuleDeclaration",
|
|
929
|
+
"TSTypeParameter"
|
|
930
|
+
]);
|
|
931
|
+
const KEYED_MEMBERS = /* @__PURE__ */ new Set([
|
|
932
|
+
"MethodDefinition",
|
|
933
|
+
"PropertyDefinition",
|
|
934
|
+
"AccessorProperty",
|
|
935
|
+
"TSPropertySignature",
|
|
936
|
+
"TSMethodSignature",
|
|
937
|
+
"TSAbstractMethodDefinition",
|
|
938
|
+
"TSAbstractPropertyDefinition"
|
|
939
|
+
]);
|
|
940
|
+
/** How an identifier is read: a plain reference, a shorthand property value, the local of an `export { }`, or not a reference. */
|
|
941
|
+
function referencePlace(node, parent, ancestors) {
|
|
942
|
+
const type = parent.type;
|
|
943
|
+
if (node.type === "JSXIdentifier") return type === "JSXOpeningElement" || type === "JSXClosingElement" || type === "JSXMemberExpression" && parent.object === node ? "reference" : "none";
|
|
944
|
+
if (type === "Property") {
|
|
945
|
+
if (ancestors.at(-2)?.type === "ObjectPattern") return "none";
|
|
946
|
+
if (parent.shorthand === true) return parent.value === node ? "shorthand" : "none";
|
|
947
|
+
return parent.key === node && parent.computed !== true ? "none" : "reference";
|
|
948
|
+
}
|
|
949
|
+
if (type === "MemberExpression" || KEYED_MEMBERS.has(type)) return (type === "MemberExpression" ? parent.property : parent.key) === node && parent.computed !== true ? "none" : "reference";
|
|
950
|
+
if (type === "ExportSpecifier") {
|
|
951
|
+
const reexport = ancestors.at(-2)?.source !== null;
|
|
952
|
+
return parent.local === node && !reexport ? "export" : "none";
|
|
953
|
+
}
|
|
954
|
+
if (type === "TSQualifiedName") return parent.right === node ? "none" : "reference";
|
|
955
|
+
return NOT_REFERENCES.has(type) ? "none" : "reference";
|
|
956
|
+
}
|
|
957
|
+
function nodes(value) {
|
|
958
|
+
return Array.isArray(value) ? value.filter(isNode) : [];
|
|
959
|
+
}
|
|
960
|
+
function isNode(value) {
|
|
961
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
962
|
+
}
|
|
963
|
+
/** A child node under a field `Estree` types as something else (`value`, a type parameter's `name`). */
|
|
964
|
+
function child(node, field) {
|
|
965
|
+
const value = Reflect.get(node, field);
|
|
966
|
+
return isNode(value) ? value : void 0;
|
|
967
|
+
}
|
|
968
|
+
function patternNames(pattern, into) {
|
|
969
|
+
if (pattern === null || pattern === void 0) return;
|
|
970
|
+
switch (pattern.type) {
|
|
971
|
+
case "Identifier":
|
|
972
|
+
into.add(pattern.name ?? "");
|
|
973
|
+
return;
|
|
974
|
+
case "ObjectPattern":
|
|
975
|
+
for (const property of nodes(pattern.properties)) patternNames(property.type === "RestElement" ? property.argument : child(property, "value"), into);
|
|
976
|
+
return;
|
|
977
|
+
case "ArrayPattern":
|
|
978
|
+
for (const element of nodes(pattern.elements)) patternNames(element, into);
|
|
979
|
+
return;
|
|
980
|
+
default: patternNames(pattern.left ?? pattern.argument ?? pattern.parameter, into);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
const DECLARATIONS_WITH_ID = /* @__PURE__ */ new Set([
|
|
984
|
+
"FunctionDeclaration",
|
|
985
|
+
"ClassDeclaration",
|
|
986
|
+
"TSEnumDeclaration",
|
|
987
|
+
"TSTypeAliasDeclaration",
|
|
988
|
+
"TSInterfaceDeclaration",
|
|
989
|
+
"TSModuleDeclaration",
|
|
990
|
+
"TSImportEqualsDeclaration",
|
|
991
|
+
"TSDeclareFunction"
|
|
992
|
+
]);
|
|
993
|
+
function declareStatement(statement, into) {
|
|
994
|
+
const type = statement.type;
|
|
995
|
+
if (type === "VariableDeclaration") for (const declarator of nodes(statement.declarations)) patternNames(declarator.id, into);
|
|
996
|
+
else if (DECLARATIONS_WITH_ID.has(type)) patternNames(statement.id, into);
|
|
997
|
+
else if (statement.declaration !== null && statement.declaration !== void 0) declareStatement(statement.declaration, into);
|
|
998
|
+
else if (type === "ImportDeclaration") for (const spec of nodes(statement.specifiers)) patternNames(spec.local, into);
|
|
999
|
+
}
|
|
1000
|
+
const BLOCK_SCOPES = /* @__PURE__ */ new Set([
|
|
1001
|
+
"Program",
|
|
1002
|
+
"BlockStatement",
|
|
1003
|
+
"StaticBlock",
|
|
1004
|
+
"TSModuleBlock"
|
|
1005
|
+
]);
|
|
1006
|
+
const FUNCTION_SCOPES = /* @__PURE__ */ new Set([
|
|
1007
|
+
"FunctionDeclaration",
|
|
1008
|
+
"FunctionExpression",
|
|
1009
|
+
"ArrowFunctionExpression",
|
|
1010
|
+
"TSDeclareFunction"
|
|
1011
|
+
]);
|
|
1012
|
+
/** The names a node declares for the code inside it; `undefined` for a node that opens no scope. */
|
|
1013
|
+
function scopeBindings(node) {
|
|
1014
|
+
const names = /* @__PURE__ */ new Set();
|
|
1015
|
+
const declare = (statements) => {
|
|
1016
|
+
for (const statement of statements) if (statement !== null && statement !== void 0) declareStatement(statement, names);
|
|
1017
|
+
};
|
|
1018
|
+
const type = node.type;
|
|
1019
|
+
let opens = true;
|
|
1020
|
+
if (BLOCK_SCOPES.has(type)) declare(nodes(node.body));
|
|
1021
|
+
else if (FUNCTION_SCOPES.has(type)) {
|
|
1022
|
+
for (const param of nodes(node.params)) patternNames(param, names);
|
|
1023
|
+
patternNames(type === "FunctionExpression" ? node.id : void 0, names);
|
|
1024
|
+
} else if (type === "ClassExpression") patternNames(node.id, names);
|
|
1025
|
+
else if (type === "ForStatement") declare([node.init]);
|
|
1026
|
+
else if (type === "ForInStatement" || type === "ForOfStatement") declare([node.left]);
|
|
1027
|
+
else if (type === "CatchClause") patternNames(node.param, names);
|
|
1028
|
+
else if (type === "SwitchStatement") declare(nodes(node.cases).flatMap((branch) => nodes(branch.consequent)));
|
|
1029
|
+
else if (type === "TSMappedType") patternNames(node.key, names);
|
|
1030
|
+
else opens = false;
|
|
1031
|
+
for (const param of nodes(node.typeParameters?.params)) {
|
|
1032
|
+
opens = true;
|
|
1033
|
+
patternNames(child(param, "name"), names);
|
|
1034
|
+
}
|
|
1035
|
+
return opens ? names : void 0;
|
|
1036
|
+
}
|
|
1037
|
+
function bindingsCached(node, cache) {
|
|
1038
|
+
let found = cache.get(node);
|
|
1039
|
+
if (found === void 0) {
|
|
1040
|
+
found = scopeBindings(node) ?? null;
|
|
1041
|
+
cache.set(node, found);
|
|
1042
|
+
}
|
|
1043
|
+
return found;
|
|
1044
|
+
}
|
|
1045
|
+
function applyEdits(source, edits) {
|
|
1046
|
+
let out = source;
|
|
1047
|
+
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);
|
|
1048
|
+
return out;
|
|
1049
|
+
}
|
|
1050
|
+
function position(lineAt, index) {
|
|
1051
|
+
const { line, lineStart } = lineAt(index);
|
|
1052
|
+
return {
|
|
1053
|
+
line,
|
|
1054
|
+
column: index - lineStart + 1
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
function lineIndex(source) {
|
|
1058
|
+
const starts = [0];
|
|
1059
|
+
for (let i = 0; i < source.length; i += 1) if (source.charCodeAt(i) === 10) starts.push(i + 1);
|
|
1060
|
+
return (index) => {
|
|
1061
|
+
let low = 0;
|
|
1062
|
+
let high = starts.length - 1;
|
|
1063
|
+
while (low < high) {
|
|
1064
|
+
const mid = low + high + 1 >> 1;
|
|
1065
|
+
if ((starts[mid] ?? 0) <= index) low = mid;
|
|
1066
|
+
else high = mid - 1;
|
|
1067
|
+
}
|
|
1068
|
+
return {
|
|
1069
|
+
line: low + 1,
|
|
1070
|
+
lineStart: starts[low] ?? 0
|
|
1071
|
+
};
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
/** Every node in source order with its parent and ancestors: Oxc nodes carry no parent, so enter and exit keep a stack. */
|
|
1075
|
+
function walk(program, visit) {
|
|
1076
|
+
const stack = [];
|
|
1077
|
+
const handlers = {};
|
|
1078
|
+
for (const type of Object.keys(visitorKeys)) {
|
|
1079
|
+
handlers[type] = (node) => {
|
|
1080
|
+
visit(node, stack.at(-1), stack);
|
|
1081
|
+
stack.push(node);
|
|
1082
|
+
};
|
|
1083
|
+
handlers[`${type}:exit`] = () => {
|
|
1084
|
+
stack.pop();
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
new Visitor(handlers).visit(program);
|
|
1088
|
+
}
|
|
1089
|
+
//#endregion
|
|
1090
|
+
//#region src/cli/codemod/context.ts
|
|
1091
|
+
/** One version's rename map: what the codemod rewrites and what it only reports. */
|
|
1092
|
+
const SCRIPT_BLOCK = /<script\b([^>]*)>([\s\S]*?)<\/script>/gu;
|
|
1093
|
+
function isPermDockSpecifier(value) {
|
|
1094
|
+
return typeof value === "string" && (value === "permdock" || value.startsWith("permdock/"));
|
|
1095
|
+
}
|
|
1096
|
+
function declaredBetween(ctx, name, ancestors) {
|
|
1097
|
+
return ancestors.some((scope) => scope !== ctx.program && bindingsCached(scope, ctx.scopes)?.has(name) === true);
|
|
1098
|
+
}
|
|
1099
|
+
function isModuleBinding(ctx, name, ancestors) {
|
|
1100
|
+
return ctx.moduleNames.has(name) && !declaredBetween(ctx, name, ancestors);
|
|
1101
|
+
}
|
|
1102
|
+
function edit(ctx, node, text, from, to) {
|
|
1103
|
+
if (ctx.edits.some((item) => item.start === node.start && item.end === node.end)) return;
|
|
1104
|
+
ctx.edits.push({
|
|
1105
|
+
start: node.start,
|
|
1106
|
+
end: node.end,
|
|
1107
|
+
text
|
|
1108
|
+
});
|
|
1109
|
+
ctx.changes.push({
|
|
1110
|
+
at: node.start,
|
|
1111
|
+
from,
|
|
1112
|
+
to
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
function replace(ctx, node, text, from) {
|
|
1116
|
+
edit(ctx, node, text, from, beforeFirst(text, " as "));
|
|
1117
|
+
}
|
|
1118
|
+
function renameOf(set, name, entry) {
|
|
1119
|
+
return set.renames.find((row) => row.from === name && row.kind !== "option" && row.kind !== "method" && row.entries.includes(entry));
|
|
1120
|
+
}
|
|
1121
|
+
function listOf(items) {
|
|
1122
|
+
return new Intl.ListFormat("en-GB", { type: "disjunction" }).format(items);
|
|
1123
|
+
}
|
|
1124
|
+
/** The import a call's callee is bound to: a named import, or a member of a namespace import. */
|
|
1125
|
+
function importedCallee(ctx, callee, ancestors) {
|
|
1126
|
+
if (callee?.type === "Identifier") {
|
|
1127
|
+
const name = callee.name ?? "";
|
|
1128
|
+
return isModuleBinding(ctx, name, ancestors) ? ctx.bindings.get(name) : void 0;
|
|
1129
|
+
}
|
|
1130
|
+
const object = callee?.type === "MemberExpression" && callee.computed !== true ? callee.object : void 0;
|
|
1131
|
+
const namespace = object?.type === "Identifier" && isModuleBinding(ctx, object.name ?? "", ancestors) ? ctx.namespaces.get(object.name ?? "") : void 0;
|
|
1132
|
+
const imported = callee?.property?.name;
|
|
1133
|
+
return namespace === void 0 || imported === void 0 ? void 0 : {
|
|
1134
|
+
entry: namespace,
|
|
1135
|
+
imported
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
function renameKey(ctx, property, from, to) {
|
|
1139
|
+
const key = property.key;
|
|
1140
|
+
if (property.type !== "Property" || key === void 0 || property.computed === true) return;
|
|
1141
|
+
ctx.handledKeys.add(key);
|
|
1142
|
+
if (property.shorthand === true) edit(ctx, {
|
|
1143
|
+
...property,
|
|
1144
|
+
end: property.start
|
|
1145
|
+
}, `${to}: `, from, to);
|
|
1146
|
+
else replace(ctx, key, key.type === "Literal" ? JSON.stringify(to) : to, from);
|
|
1147
|
+
}
|
|
1148
|
+
function renameKeys(ctx, object, from, to) {
|
|
1149
|
+
for (const property of nodes(object.properties)) if (nameOf(property.key) === from) renameKey(ctx, property, from, to);
|
|
1150
|
+
}
|
|
1151
|
+
function boundImport(ctx, node, ancestors) {
|
|
1152
|
+
const name = node?.name;
|
|
1153
|
+
return (node?.type === "Identifier" || node?.type === "JSXIdentifier") && name !== void 0 && isModuleBinding(ctx, name, ancestors) ? ctx.bindings.get(name) : void 0;
|
|
1154
|
+
}
|
|
1155
|
+
//#endregion
|
|
1156
|
+
//#region src/cli/codemod/imports.ts
|
|
1157
|
+
function removableBindings(ctx) {
|
|
1158
|
+
const out = /* @__PURE__ */ new Set();
|
|
1159
|
+
if (ctx.keepLocals) return out;
|
|
1160
|
+
for (const local of ctx.bindings.keys()) {
|
|
1161
|
+
const references = ctx.references.filter((item) => item.node.name === local);
|
|
1162
|
+
if (references.length > 0 && references.every((item) => ctx.consumed.has(item.node.start))) out.add(local);
|
|
1163
|
+
}
|
|
1164
|
+
return out;
|
|
1165
|
+
}
|
|
1166
|
+
function importedLocal(ctx, name, entry, ancestors) {
|
|
1167
|
+
for (const [local, binding] of ctx.bindings) if (binding.entry === entry && binding.imported === name && !typeOnly(binding) && !declaredBetween(ctx, local, ancestors)) return local;
|
|
1168
|
+
if (ctx.moduleNames.has(name) || declaredBetween(ctx, name, ancestors)) return;
|
|
1169
|
+
const names = ctx.additions.get(entry) ?? /* @__PURE__ */ new Set();
|
|
1170
|
+
names.add(name);
|
|
1171
|
+
ctx.additions.set(entry, names);
|
|
1172
|
+
return name;
|
|
1173
|
+
}
|
|
1174
|
+
function typeOnly(binding) {
|
|
1175
|
+
return Reflect.get(binding.declaration, "importKind") === "type" || Reflect.get(binding.spec, "importKind") === "type";
|
|
1176
|
+
}
|
|
1177
|
+
function finishImports(ctx, removed) {
|
|
1178
|
+
const gone = /* @__PURE__ */ new Set();
|
|
1179
|
+
for (const local of removed) {
|
|
1180
|
+
const spec = ctx.bindings.get(local)?.spec;
|
|
1181
|
+
if (spec !== void 0) gone.add(spec);
|
|
1182
|
+
}
|
|
1183
|
+
const pending = new Map(ctx.additions);
|
|
1184
|
+
for (const declaration of nodes(ctx.program.body)) {
|
|
1185
|
+
const all = nodes(declaration.specifiers);
|
|
1186
|
+
if (declaration.type !== "ImportDeclaration" || !all.some((spec) => gone.has(spec))) continue;
|
|
1187
|
+
if (all.some((spec) => spec.type !== "ImportSpecifier")) {
|
|
1188
|
+
for (const spec of all) gone.delete(spec);
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
if (all.some((spec) => !gone.has(spec))) {
|
|
1192
|
+
removeSpecifiers(ctx, all, gone);
|
|
1193
|
+
continue;
|
|
1194
|
+
}
|
|
1195
|
+
const entry = String(declaration.source?.value);
|
|
1196
|
+
const names = Reflect.get(declaration, "importKind") === "type" ? void 0 : pending.get(entry);
|
|
1197
|
+
if (names === void 0) ctx.edits.push({
|
|
1198
|
+
start: declaration.start,
|
|
1199
|
+
end: lineEnd(ctx.code, declaration.end),
|
|
1200
|
+
text: ""
|
|
1201
|
+
});
|
|
1202
|
+
else {
|
|
1203
|
+
pending.delete(entry);
|
|
1204
|
+
ctx.edits.push({
|
|
1205
|
+
start: declaration.start,
|
|
1206
|
+
end: declaration.end,
|
|
1207
|
+
text: importText(ctx, entry, names)
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
for (const [entry, names] of pending) addImport(ctx, entry, names, gone);
|
|
1212
|
+
}
|
|
1213
|
+
function lineEnd(code, end) {
|
|
1214
|
+
return code[end] === "\n" ? end + 1 : end;
|
|
1215
|
+
}
|
|
1216
|
+
function importText(ctx, entry, names) {
|
|
1217
|
+
const source = nodes(ctx.program.body).map((statement) => statement.source).find((node) => isPermDockSpecifier(node?.value));
|
|
1218
|
+
const mark = ctx.code[source?.start ?? -1] ?? "\"";
|
|
1219
|
+
return `import { ${[...names].join(", ")} } from ${mark}${entry}${mark};`;
|
|
1220
|
+
}
|
|
1221
|
+
function removeSpecifiers(ctx, all, gone) {
|
|
1222
|
+
const last = all.findLastIndex((spec) => !gone.has(spec));
|
|
1223
|
+
for (const [index, spec] of all.entries()) {
|
|
1224
|
+
const next = all[index + 1];
|
|
1225
|
+
if (gone.has(spec) && index < last && next !== void 0) ctx.edits.push({
|
|
1226
|
+
start: spec.start,
|
|
1227
|
+
end: next.start,
|
|
1228
|
+
text: ""
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
const survivor = all[last];
|
|
1232
|
+
const tail = all.at(-1);
|
|
1233
|
+
if (survivor !== void 0 && tail !== void 0 && tail !== survivor) ctx.edits.push({
|
|
1234
|
+
start: survivor.end,
|
|
1235
|
+
end: tail.end,
|
|
1236
|
+
text: ""
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
function addImport(ctx, entry, names, gone) {
|
|
1240
|
+
const statements = nodes(ctx.program.body);
|
|
1241
|
+
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));
|
|
1242
|
+
if (anchor !== void 0) {
|
|
1243
|
+
ctx.edits.push({
|
|
1244
|
+
start: anchor.end,
|
|
1245
|
+
end: anchor.end,
|
|
1246
|
+
text: `, ${[...names].join(", ")}`
|
|
1247
|
+
});
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
const lastImport = statements.findLast((statement) => statement.type === "ImportDeclaration");
|
|
1251
|
+
const at = lastImport?.end ?? 0;
|
|
1252
|
+
const text = importText(ctx, entry, names);
|
|
1253
|
+
ctx.edits.push({
|
|
1254
|
+
start: at,
|
|
1255
|
+
end: at,
|
|
1256
|
+
text: lastImport === void 0 ? `${text}\n` : `\n${text}`
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
//#endregion
|
|
1260
|
+
//#region src/cli/codemod/shapes.ts
|
|
1261
|
+
function templateHints(file, source, set, components, lineAt) {
|
|
1262
|
+
const hints = (set.templates ?? []).filter((hint) => hint.entries.some((entry) => components.has(`${entry} ${hint.component}`)));
|
|
1263
|
+
if (hints.length === 0 || !/\.(?:vue|svelte)$/iu.test(file)) return [];
|
|
1264
|
+
const markup = source.replaceAll(SCRIPT_BLOCK, (block) => " ".repeat(block.length));
|
|
1265
|
+
return hints.flatMap((hint) => [...markup.matchAll(hint.pattern)].map((match) => {
|
|
1266
|
+
const { line, column } = position(lineAt, match.index);
|
|
1267
|
+
return {
|
|
1268
|
+
line,
|
|
1269
|
+
column,
|
|
1270
|
+
name: hint.name,
|
|
1271
|
+
message: hint.message
|
|
1272
|
+
};
|
|
1273
|
+
}));
|
|
1274
|
+
}
|
|
1275
|
+
function awaitRow(ctx, callee) {
|
|
1276
|
+
return (ctx.set.awaits ?? []).find((row) => callee !== void 0 && row.name === callee.imported && row.entries.includes(callee.entry));
|
|
1277
|
+
}
|
|
1278
|
+
function visitAwait(ctx, node, ancestors) {
|
|
1279
|
+
const call = node.argument;
|
|
1280
|
+
if (call?.type !== "CallExpression" || call.callee === void 0) return;
|
|
1281
|
+
const callee = importedCallee(ctx, call.callee, ancestors);
|
|
1282
|
+
const row = awaitRow(ctx, callee);
|
|
1283
|
+
if (row === void 0 || callee === void 0) return;
|
|
1284
|
+
swapCallee(ctx, call.callee, row.name, row.to, callee.entry, ancestors);
|
|
1285
|
+
}
|
|
1286
|
+
function swapCallee(ctx, callee, from, to, entry, ancestors) {
|
|
1287
|
+
if (callee.type === "MemberExpression" && callee.property !== void 0) {
|
|
1288
|
+
replace(ctx, callee.property, to, from);
|
|
1289
|
+
return true;
|
|
1290
|
+
}
|
|
1291
|
+
const local = importedLocal(ctx, to, entry, ancestors);
|
|
1292
|
+
if (local === void 0) {
|
|
1293
|
+
ctx.followUps.push({
|
|
1294
|
+
at: callee.start,
|
|
1295
|
+
name: from,
|
|
1296
|
+
message: `\`${from}\` is \`${to}\` from \`${entry}\` here; \`${to}\` is already bound in this scope`
|
|
1297
|
+
});
|
|
1298
|
+
return false;
|
|
1299
|
+
}
|
|
1300
|
+
ctx.consumed.add(callee.start);
|
|
1301
|
+
edit(ctx, callee, local, from, to);
|
|
1302
|
+
return true;
|
|
1303
|
+
}
|
|
1304
|
+
function reportUnawaited(ctx, node, ancestors, row) {
|
|
1305
|
+
const parent = ancestors.at(-1);
|
|
1306
|
+
if (parent?.type === "ReturnStatement" || parent?.type === "ArrowFunctionExpression" && parent.body === node || parent?.type === "MemberExpression" && parent.object === node && parent.property?.name === "then") ctx.followUps.push({
|
|
1307
|
+
at: node.start,
|
|
1308
|
+
name: row.name,
|
|
1309
|
+
message: `\`${row.name}\` without \`await\` is \`${row.sync}\`, which returns the instance, never a Promise; call \`${row.to}\` when a source answers asynchronously`
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
function propRows(ctx, binding) {
|
|
1313
|
+
return binding === void 0 ? [] : (ctx.set.props ?? []).filter((row) => row.component === binding.imported && row.entries.includes(binding.entry));
|
|
1314
|
+
}
|
|
1315
|
+
function visitElement(ctx, node, ancestors) {
|
|
1316
|
+
const tag = child(node, "name");
|
|
1317
|
+
const binding = boundImport(ctx, tag, ancestors);
|
|
1318
|
+
const rows = propRows(ctx, binding);
|
|
1319
|
+
const named = tag?.type === "JSXMemberExpression" ? child(tag, "property") : tag;
|
|
1320
|
+
const unbound = (ctx.set.props ?? []).filter((row) => binding === void 0 && row.within !== void 0 && named?.type === "JSXIdentifier" && named.name === row.component);
|
|
1321
|
+
for (const attribute of nodes(Reflect.get(node, "attributes"))) {
|
|
1322
|
+
const name = child(attribute, "name");
|
|
1323
|
+
if (attribute.type !== "JSXAttribute" || name?.type !== "JSXIdentifier") continue;
|
|
1324
|
+
for (const row of rows) if (row.within === void 0 && name.name === row.from) replace(ctx, name, row.to, row.from);
|
|
1325
|
+
else if (row.within !== void 0 && name.name === row.within) renameWithin(ctx, attribute, row);
|
|
1326
|
+
for (const row of unbound) if (name.name === row.within && holdsKey(attribute, row.from)) ctx.followUps.push({
|
|
1327
|
+
at: attribute.start,
|
|
1328
|
+
name: row.from,
|
|
1329
|
+
message: `\`${row.within}.${row.from}\` of \`<${row.component}>\` is \`${row.within}.${row.to}\``
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
function attributeObject(attribute) {
|
|
1334
|
+
const value = child(attribute, "value");
|
|
1335
|
+
const expression = value?.type === "JSXExpressionContainer" ? child(value, "expression") : void 0;
|
|
1336
|
+
return expression?.type === "ObjectExpression" ? expression : void 0;
|
|
1337
|
+
}
|
|
1338
|
+
function holdsKey(attribute, key) {
|
|
1339
|
+
const object = attributeObject(attribute);
|
|
1340
|
+
return object === void 0 || nodes(object.properties).some((property) => nameOf(property.key) === key);
|
|
1341
|
+
}
|
|
1342
|
+
function renameWithin(ctx, attribute, row) {
|
|
1343
|
+
const object = attributeObject(attribute);
|
|
1344
|
+
if (object === void 0) {
|
|
1345
|
+
ctx.followUps.push({
|
|
1346
|
+
at: attribute.start,
|
|
1347
|
+
name: row.from,
|
|
1348
|
+
message: `\`${row.within}.${row.from}\` of \`<${row.component}>\` is \`${row.within}.${row.to}\``
|
|
1349
|
+
});
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1352
|
+
renameKeys(ctx, object, row.from, row.to);
|
|
1353
|
+
}
|
|
1354
|
+
function visitComponentArguments(ctx, node, ancestors) {
|
|
1355
|
+
const args = nodes(node.arguments);
|
|
1356
|
+
for (const [index, argument] of args.entries()) {
|
|
1357
|
+
const rows = propRows(ctx, boundImport(ctx, argument, ancestors)).filter((row) => row.within === void 0);
|
|
1358
|
+
for (const row of rows) for (const later of args.slice(index + 1)) if (later.type === "ObjectExpression") renameKeys(ctx, later, row.from, row.to);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
function methodRow(ctx, node, ancestors) {
|
|
1362
|
+
const callee = node.callee;
|
|
1363
|
+
const receiver = callee?.object;
|
|
1364
|
+
const method = callee?.property?.name;
|
|
1365
|
+
const first = nodes(node.arguments)[0];
|
|
1366
|
+
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)));
|
|
1367
|
+
}
|
|
1368
|
+
function holdsInstance(ctx, receiver, ancestors) {
|
|
1369
|
+
const name = receiver?.type === "Identifier" ? receiver.name : void 0;
|
|
1370
|
+
if (name === void 0) return false;
|
|
1371
|
+
return /permdock/iu.test(name) || isModuleBinding(ctx, name, ancestors) && ctx.factories.has(name);
|
|
1372
|
+
}
|
|
1373
|
+
function visitMethodCall(ctx, node, ancestors) {
|
|
1374
|
+
const row = node.type === "CallExpression" ? methodRow(ctx, node, ancestors) : void 0;
|
|
1375
|
+
const receiver = node.callee?.object;
|
|
1376
|
+
if (row === void 0 || receiver === void 0) return;
|
|
1377
|
+
const name = receiver.type === "Identifier" ? receiver.name : void 0;
|
|
1378
|
+
if (name !== void 0 && ctx.namespaces.has(name)) return;
|
|
1379
|
+
const open = ctx.code.indexOf("(", receiver.end);
|
|
1380
|
+
const between = ctx.code.slice(receiver.end, open);
|
|
1381
|
+
if (Reflect.get(node, "optional") === true || Reflect.get(node.callee ?? node, "optional") === true || receiver.type === "SequenceExpression" || !/^\s*\.\s*\w+\s*$/u.test(between)) {
|
|
1382
|
+
ctx.followUps.push({
|
|
1383
|
+
at: node.start,
|
|
1384
|
+
name: row.method,
|
|
1385
|
+
message: `\`permdock.${row.method}(…)\` is \`${row.to}(permdock, …)\` from \`${row.entry}\``
|
|
1386
|
+
});
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1389
|
+
const local = importedLocal(ctx, row.to, row.entry, ancestors);
|
|
1390
|
+
if (local === void 0) {
|
|
1391
|
+
ctx.followUps.push({
|
|
1392
|
+
at: node.start,
|
|
1393
|
+
name: row.method,
|
|
1394
|
+
message: `\`permdock.${row.method}(…)\` is \`${row.to}(permdock, …)\` from \`${row.entry}\`; \`${row.to}\` is already bound in this scope`
|
|
1395
|
+
});
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
const separator = nodes(node.arguments).length === 0 ? "" : ",";
|
|
1399
|
+
const space = /\s/u.test(ctx.code[open + 1] ?? "") ? "" : " ";
|
|
1400
|
+
ctx.edits.push({
|
|
1401
|
+
start: receiver.start,
|
|
1402
|
+
end: receiver.start,
|
|
1403
|
+
text: `${local}(`
|
|
1404
|
+
}, {
|
|
1405
|
+
start: receiver.end,
|
|
1406
|
+
end: open + 1,
|
|
1407
|
+
text: separator === "" ? "" : `${separator}${space}`
|
|
1408
|
+
});
|
|
1409
|
+
ctx.changes.push({
|
|
1410
|
+
at: node.start,
|
|
1411
|
+
from: row.method,
|
|
1412
|
+
to: row.to
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
const PLAIN_RECEIVERS = /* @__PURE__ */ new Set([
|
|
1416
|
+
"Identifier",
|
|
1417
|
+
"MemberExpression",
|
|
1418
|
+
"CallExpression",
|
|
1419
|
+
"ThisExpression"
|
|
1420
|
+
]);
|
|
1421
|
+
function visitFunctionCall(ctx, node, callee) {
|
|
1422
|
+
const row = (ctx.set.functionMethods ?? []).find((item) => item.name === callee.imported && item.entry === callee.entry);
|
|
1423
|
+
const [receiver, next] = nodes(node.arguments);
|
|
1424
|
+
if (row === void 0 || node.type !== "CallExpression" || node.callee === void 0 || receiver === void 0 || receiver.type === "SpreadElement" || Reflect.get(node, "optional") === true) return false;
|
|
1425
|
+
const plain = PLAIN_RECEIVERS.has(receiver.type);
|
|
1426
|
+
ctx.edits.push({
|
|
1427
|
+
start: node.callee.start,
|
|
1428
|
+
end: receiver.start,
|
|
1429
|
+
text: plain ? "" : "("
|
|
1430
|
+
}, {
|
|
1431
|
+
start: receiver.end,
|
|
1432
|
+
end: next?.start ?? node.end - 1,
|
|
1433
|
+
text: `${plain ? "" : ")"}.${row.method}(`
|
|
1434
|
+
});
|
|
1435
|
+
if (node.callee.type === "Identifier") ctx.consumed.add(node.callee.start);
|
|
1436
|
+
ctx.changes.push({
|
|
1437
|
+
at: node.start,
|
|
1438
|
+
from: row.name,
|
|
1439
|
+
to: row.method
|
|
1440
|
+
});
|
|
1441
|
+
return true;
|
|
1442
|
+
}
|
|
1443
|
+
function isWrapped(ctx, row, value, ancestors) {
|
|
1444
|
+
const callee = value?.type === "CallExpression" ? importedCallee(ctx, value.callee, ancestors) : void 0;
|
|
1445
|
+
return callee !== void 0 && callee.entry === row.entry && row.already.includes(callee.imported);
|
|
1446
|
+
}
|
|
1447
|
+
function visitWraps(ctx, node, callee, ancestors) {
|
|
1448
|
+
const rows = (ctx.set.wraps ?? []).filter((row) => row.entries.includes(callee.entry) && row.calls.includes(callee.imported));
|
|
1449
|
+
for (const argument of nodes(node.arguments)) for (const property of argument.type === "ObjectExpression" ? nodes(argument.properties) : []) {
|
|
1450
|
+
const row = rows.find((item) => item.key === nameOf(property.key));
|
|
1451
|
+
if (row !== void 0 && property.computed !== true) wrapOption(ctx, row, property, ancestors);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
function wrapOption(ctx, row, property, ancestors) {
|
|
1455
|
+
const value = child(property, "value");
|
|
1456
|
+
if (property.key !== void 0) ctx.handledKeys.add(property.key);
|
|
1457
|
+
if (value === void 0 || isWrapped(ctx, row, value, ancestors)) return;
|
|
1458
|
+
const local = importedLocal(ctx, row.wrapper, row.entry, ancestors);
|
|
1459
|
+
if (local === void 0 || property.type !== "Property") {
|
|
1460
|
+
ctx.followUps.push({
|
|
1461
|
+
at: property.start,
|
|
1462
|
+
name: row.key,
|
|
1463
|
+
message: `option \`${row.key}\` takes \`${row.wrapper}(source)\` from \`${row.entry}\`; \`${row.wrapper}\` is already bound in this scope`
|
|
1464
|
+
});
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
ctx.edits.push(property.shorthand === true ? {
|
|
1468
|
+
start: property.start,
|
|
1469
|
+
end: property.start,
|
|
1470
|
+
text: `${row.key}: ${local}(`
|
|
1471
|
+
} : {
|
|
1472
|
+
start: value.start,
|
|
1473
|
+
end: value.start,
|
|
1474
|
+
text: `${local}(`
|
|
1475
|
+
}, {
|
|
1476
|
+
start: value.end,
|
|
1477
|
+
end: value.end,
|
|
1478
|
+
text: ")"
|
|
1479
|
+
});
|
|
1480
|
+
ctx.changes.push({
|
|
1481
|
+
at: value.start,
|
|
1482
|
+
from: row.key,
|
|
1483
|
+
to: row.wrapper
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
function reportWraps(ctx, node, ancestors) {
|
|
1487
|
+
for (const property of nodes(node.properties)) {
|
|
1488
|
+
const row = (ctx.set.wraps ?? []).find((item) => item.reportElsewhere && item.key === nameOf(property.key));
|
|
1489
|
+
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({
|
|
1490
|
+
at: property.start,
|
|
1491
|
+
name: row.key,
|
|
1492
|
+
message: `option \`${row.key}\` takes \`${row.wrapper}(source)\` from \`${row.entry}\` when this object reaches \`getPermDock\` or \`getPermDockSync\``
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
const UNIT_SECONDS = Object.freeze({
|
|
1497
|
+
s: 1,
|
|
1498
|
+
m: 60,
|
|
1499
|
+
h: 3600,
|
|
1500
|
+
d: 86400,
|
|
1501
|
+
w: 604800
|
|
1502
|
+
});
|
|
1503
|
+
function seconds(value) {
|
|
1504
|
+
if (value?.type !== "Literal" || typeof value.value !== "string") return;
|
|
1505
|
+
const match = /^\s*(\d+)([smhdw])\s*$/u.exec(value.value);
|
|
1506
|
+
const amount = Number(match?.[1]);
|
|
1507
|
+
const unit = UNIT_SECONDS[match?.[2] ?? ""];
|
|
1508
|
+
return unit === void 0 || !(amount > 0) ? void 0 : amount * unit;
|
|
1509
|
+
}
|
|
1510
|
+
function insidePermDockCall(ctx, object, ancestors) {
|
|
1511
|
+
const chain = [...ancestors, object];
|
|
1512
|
+
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);
|
|
1513
|
+
}
|
|
1514
|
+
function visitDurations(ctx, node, ancestors) {
|
|
1515
|
+
const keys = ctx.set.durations;
|
|
1516
|
+
if (keys === void 0) return;
|
|
1517
|
+
const rewrite = insidePermDockCall(ctx, node, ancestors);
|
|
1518
|
+
const parent = ancestors.at(-1);
|
|
1519
|
+
if (!rewrite && nodes(parent?.arguments).includes(node)) return;
|
|
1520
|
+
for (const property of nodes(node.properties)) {
|
|
1521
|
+
const key = nameOf(property.key);
|
|
1522
|
+
const value = child(property, "value");
|
|
1523
|
+
const literals = key !== void 0 && keys.keys.includes(key) ? [value] : key !== void 0 && keys.lists.includes(key) && value?.type === "ArrayExpression" ? nodes(value.elements) : [];
|
|
1524
|
+
for (const literal of literals) {
|
|
1525
|
+
const total = seconds(literal);
|
|
1526
|
+
if (literal === void 0 || total === void 0) continue;
|
|
1527
|
+
const text = String(literal.value);
|
|
1528
|
+
if (rewrite) {
|
|
1529
|
+
ctx.edits.push({
|
|
1530
|
+
start: literal.start,
|
|
1531
|
+
end: literal.end,
|
|
1532
|
+
text: String(total)
|
|
1533
|
+
});
|
|
1534
|
+
ctx.changes.push({
|
|
1535
|
+
at: literal.start,
|
|
1536
|
+
from: text,
|
|
1537
|
+
to: String(total)
|
|
1538
|
+
});
|
|
1539
|
+
} else ctx.followUps.push({
|
|
1540
|
+
at: literal.start,
|
|
1541
|
+
name: key ?? text,
|
|
1542
|
+
message: `duration \`"${text}"\` is \`${total}\` (seconds) when this object reaches PermDock`
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
//#endregion
|
|
1548
|
+
//#region src/cli/codemod/transform.ts
|
|
1549
|
+
/** Applies `set` to one file's source; `file` picks the parser by extension. */
|
|
1550
|
+
function transformSource(file, source, set) {
|
|
1551
|
+
const lineAt = lineIndex(source);
|
|
1552
|
+
const edits = [];
|
|
1553
|
+
const changes = [];
|
|
1554
|
+
const followUps = [];
|
|
1555
|
+
const components = /* @__PURE__ */ new Set();
|
|
1556
|
+
for (const segment of segmentsOf(file, source)) {
|
|
1557
|
+
const result = parseSync(`segment.${segment.lang}`, segment.code, {
|
|
1558
|
+
lang: segment.lang,
|
|
1559
|
+
sourceType: "module"
|
|
1560
|
+
});
|
|
1561
|
+
const error = result.errors.find((item) => {
|
|
1562
|
+
return item.severity === "Error";
|
|
1563
|
+
});
|
|
1564
|
+
if (error !== void 0) return {
|
|
1565
|
+
source,
|
|
1566
|
+
changes: [],
|
|
1567
|
+
followUps: [],
|
|
1568
|
+
error: error.message
|
|
1569
|
+
};
|
|
1570
|
+
const ctx = contextFor(result.program, set, segment);
|
|
1571
|
+
if (ctx === void 0) continue;
|
|
1572
|
+
transformProgram(ctx, segment);
|
|
1573
|
+
for (const binding of ctx.bindings.values()) components.add(`${binding.entry} ${binding.imported}`);
|
|
1574
|
+
const at = (index) => position(lineAt, index + segment.offset);
|
|
1575
|
+
for (const item of ctx.edits) edits.push({
|
|
1576
|
+
start: item.start + segment.offset,
|
|
1577
|
+
end: item.end + segment.offset,
|
|
1578
|
+
text: item.text
|
|
1579
|
+
});
|
|
1580
|
+
for (const change of ctx.changes) changes.push({
|
|
1581
|
+
...at(change.at),
|
|
1582
|
+
from: change.from,
|
|
1583
|
+
to: change.to
|
|
1584
|
+
});
|
|
1585
|
+
for (const note of ctx.followUps) followUps.push({
|
|
1586
|
+
...at(note.at),
|
|
1587
|
+
name: note.name,
|
|
1588
|
+
message: note.message
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
followUps.push(...templateHints(file, source, set, components, lineAt));
|
|
1592
|
+
return {
|
|
1593
|
+
source: applyEdits(source, edits),
|
|
1594
|
+
changes: changes.toSorted(byPosition),
|
|
1595
|
+
followUps: followUps.toSorted(byPosition)
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
function byPosition(a, b) {
|
|
1599
|
+
return a.line - b.line || a.column - b.column;
|
|
1600
|
+
}
|
|
1601
|
+
function segmentsOf(file, source) {
|
|
1602
|
+
const extension = file.slice(file.lastIndexOf(".") + 1).toLowerCase();
|
|
1603
|
+
if (extension === "vue" || extension === "svelte") return [...source.matchAll(SCRIPT_BLOCK)].map((match) => {
|
|
1604
|
+
const [whole, attributes = "", code = ""] = match;
|
|
1605
|
+
const typed = /\blang=["']?(?:ts|typescript)\b/u.test(attributes);
|
|
1606
|
+
return {
|
|
1607
|
+
code,
|
|
1608
|
+
offset: match.index + whole.indexOf(">") + 1,
|
|
1609
|
+
lang: typed ? "ts" : "jsx",
|
|
1610
|
+
keepLocals: true
|
|
1611
|
+
};
|
|
1612
|
+
});
|
|
1613
|
+
return [{
|
|
1614
|
+
code: source,
|
|
1615
|
+
offset: 0,
|
|
1616
|
+
lang: extension === "tsx" ? "tsx" : [
|
|
1617
|
+
"ts",
|
|
1618
|
+
"mts",
|
|
1619
|
+
"cts"
|
|
1620
|
+
].includes(extension) ? "ts" : "jsx",
|
|
1621
|
+
keepLocals: false
|
|
1622
|
+
}];
|
|
1623
|
+
}
|
|
1624
|
+
/** The module's `permdock` imports, or `undefined` when it has none. */
|
|
1625
|
+
function contextFor(program, set, segment) {
|
|
1626
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
1627
|
+
const namespaces = /* @__PURE__ */ new Map();
|
|
1628
|
+
const entries = /* @__PURE__ */ new Set();
|
|
1629
|
+
for (const statement of nodes(program.body)) {
|
|
1630
|
+
const entry = statement.source?.value;
|
|
1631
|
+
if (!isPermDockSpecifier(entry)) continue;
|
|
1632
|
+
entries.add(entry);
|
|
1633
|
+
if (statement.type !== "ImportDeclaration") continue;
|
|
1634
|
+
for (const spec of nodes(statement.specifiers)) {
|
|
1635
|
+
const local = spec.local?.name ?? "";
|
|
1636
|
+
if (spec.type === "ImportNamespaceSpecifier") namespaces.set(local, entry);
|
|
1637
|
+
const imported = nameOf(spec.imported);
|
|
1638
|
+
if (spec.type === "ImportSpecifier" && imported !== void 0) {
|
|
1639
|
+
const rename = renameOf(set, imported, entry);
|
|
1640
|
+
bindings.set(local, {
|
|
1641
|
+
entry,
|
|
1642
|
+
imported,
|
|
1643
|
+
spec,
|
|
1644
|
+
declaration: statement,
|
|
1645
|
+
rename
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
if (entries.size === 0) return;
|
|
1651
|
+
const renamedLocals = /* @__PURE__ */ new Map();
|
|
1652
|
+
for (const [local, binding] of bindings) if (binding.rename !== void 0 && local === binding.imported) renamedLocals.set(local, binding.rename);
|
|
1653
|
+
const touches = (row) => row.entries.some((entry) => entries.has(entry));
|
|
1654
|
+
return {
|
|
1655
|
+
program,
|
|
1656
|
+
code: segment.code,
|
|
1657
|
+
keepLocals: segment.keepLocals,
|
|
1658
|
+
consumed: /* @__PURE__ */ new Set(),
|
|
1659
|
+
additions: /* @__PURE__ */ new Map(),
|
|
1660
|
+
set,
|
|
1661
|
+
edits: [],
|
|
1662
|
+
changes: [],
|
|
1663
|
+
followUps: [],
|
|
1664
|
+
bindings,
|
|
1665
|
+
namespaces,
|
|
1666
|
+
moduleNames: scopeBindings(program) ?? /* @__PURE__ */ new Set(),
|
|
1667
|
+
renamedLocals,
|
|
1668
|
+
kept: /* @__PURE__ */ new Set(),
|
|
1669
|
+
references: [],
|
|
1670
|
+
optionRows: set.renames.filter((row) => row.kind === "option" && touches(row)),
|
|
1671
|
+
methodRows: set.renames.filter((row) => row.kind === "method" && touches(row)),
|
|
1672
|
+
factories: factoryValues(program, bindings),
|
|
1673
|
+
handledKeys: /* @__PURE__ */ new Set(),
|
|
1674
|
+
newShapes: /* @__PURE__ */ new Set(),
|
|
1675
|
+
scopes: /* @__PURE__ */ new WeakMap()
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
function transformProgram(ctx, segment) {
|
|
1679
|
+
for (const [local, rename] of ctx.renamedLocals) if (segment.keepLocals || ctx.moduleNames.has(rename.to)) ctx.kept.add(local);
|
|
1680
|
+
walk(ctx.program, (node, parent, ancestors) => {
|
|
1681
|
+
switch (node.type) {
|
|
1682
|
+
case "Identifier":
|
|
1683
|
+
case "JSXIdentifier":
|
|
1684
|
+
visitIdentifier(ctx, node, parent, ancestors);
|
|
1685
|
+
break;
|
|
1686
|
+
case "MemberExpression":
|
|
1687
|
+
case "TSQualifiedName":
|
|
1688
|
+
visitMember(ctx, node, ancestors);
|
|
1689
|
+
break;
|
|
1690
|
+
case "ObjectPattern":
|
|
1691
|
+
reportMethods(ctx, propertyKeys(node), "destructured", "comes from");
|
|
1692
|
+
break;
|
|
1693
|
+
case "CallExpression":
|
|
1694
|
+
case "NewExpression":
|
|
1695
|
+
visitCall(ctx, node, ancestors);
|
|
1696
|
+
visitComponentArguments(ctx, node, ancestors);
|
|
1697
|
+
visitMethodCall(ctx, node, ancestors);
|
|
1698
|
+
break;
|
|
1699
|
+
case "JSXOpeningElement":
|
|
1700
|
+
visitElement(ctx, node, ancestors);
|
|
1701
|
+
break;
|
|
1702
|
+
case "AwaitExpression":
|
|
1703
|
+
visitAwait(ctx, node, ancestors);
|
|
1704
|
+
break;
|
|
1705
|
+
case "ObjectExpression":
|
|
1706
|
+
reportOptions(ctx, node, ancestors);
|
|
1707
|
+
reportWraps(ctx, node, ancestors);
|
|
1708
|
+
visitDurations(ctx, node, ancestors);
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
const removed = removableBindings(ctx);
|
|
1712
|
+
rewriteImports(ctx, removed);
|
|
1713
|
+
rewriteReferences(ctx);
|
|
1714
|
+
rewriteReexports(ctx);
|
|
1715
|
+
reportUncalledSignatures(ctx, removed);
|
|
1716
|
+
finishImports(ctx, removed);
|
|
1717
|
+
}
|
|
1718
|
+
function visitIdentifier(ctx, node, parent, ancestors) {
|
|
1719
|
+
const name = node.name ?? "";
|
|
1720
|
+
if (parent === void 0 || !(ctx.bindings.has(name) || ctx.namespaces.has(name))) return;
|
|
1721
|
+
const place = referencePlace(node, parent, ancestors);
|
|
1722
|
+
if (place === "none" || !isModuleBinding(ctx, name, ancestors)) return;
|
|
1723
|
+
const rename = ctx.renamedLocals.get(name);
|
|
1724
|
+
if (rename !== void 0 && declaredBetween(ctx, rename.to, ancestors)) ctx.kept.add(name);
|
|
1725
|
+
ctx.references.push({
|
|
1726
|
+
node,
|
|
1727
|
+
place,
|
|
1728
|
+
parent
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
function visitMember(ctx, node, ancestors) {
|
|
1732
|
+
const member = node.type === "MemberExpression";
|
|
1733
|
+
const object = member ? node.object : node.left;
|
|
1734
|
+
const property = member ? node.property : node.right;
|
|
1735
|
+
if (node.computed === true || property?.name === void 0) return;
|
|
1736
|
+
const namespace = object?.type === "Identifier" && isModuleBinding(ctx, object.name ?? "", ancestors) ? ctx.namespaces.get(object.name ?? "") : void 0;
|
|
1737
|
+
const rename = namespace === void 0 ? void 0 : renameOf(ctx.set, property.name, namespace);
|
|
1738
|
+
if (rename !== void 0) replace(ctx, property, rename.to, rename.from);
|
|
1739
|
+
else if (member) {
|
|
1740
|
+
const receiver = object?.type === "Identifier" ? object.name : void 0;
|
|
1741
|
+
const origin = receiver !== void 0 && isModuleBinding(ctx, receiver, ancestors) ? ctx.factories.get(receiver) : void 0;
|
|
1742
|
+
const method = origin === void 0 ? void 0 : ctx.methodRows.find((row) => row.from === property.name && row.entries.includes(origin));
|
|
1743
|
+
if (method !== void 0) replace(ctx, property, method.to, method.from);
|
|
1744
|
+
else if (origin === void 0) reportMethods(ctx, [property], "member", "is on a value from");
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
/** `const x = f(…)` or `const x = await f(…)` at module level, where `f` is imported from a permdock entry. */
|
|
1748
|
+
function factoryValues(program, bindings) {
|
|
1749
|
+
const out = /* @__PURE__ */ new Map();
|
|
1750
|
+
for (const statement of nodes(program.body)) {
|
|
1751
|
+
const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
1752
|
+
if (declaration?.type !== "VariableDeclaration" || Reflect.get(declaration, "kind") !== "const") continue;
|
|
1753
|
+
for (const declarator of nodes(declaration.declarations)) {
|
|
1754
|
+
const init = declarator.init?.type === "AwaitExpression" ? declarator.init.argument : declarator.init;
|
|
1755
|
+
const callee = init?.type === "CallExpression" ? init.callee : void 0;
|
|
1756
|
+
const factory = callee?.type === "Identifier" ? callee.name : void 0;
|
|
1757
|
+
const entry = factory === void 0 ? void 0 : bindings.get(factory)?.entry;
|
|
1758
|
+
const name = declarator.id?.type === "Identifier" ? declarator.id.name : void 0;
|
|
1759
|
+
if (entry !== void 0 && name !== void 0) out.set(name, entry);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
return out;
|
|
1763
|
+
}
|
|
1764
|
+
function reportMethods(ctx, keys, what, where) {
|
|
1765
|
+
for (const key of keys) for (const row of ctx.methodRows) if (nameOf(key) === row.from) ctx.followUps.push({
|
|
1766
|
+
at: key.start,
|
|
1767
|
+
name: row.from,
|
|
1768
|
+
message: `${what} \`${row.from}\` is \`${row.to}\` when it ${where} ${listOf(row.entries)}`
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
/** The non-computed keys of an object literal or pattern. */
|
|
1772
|
+
function propertyKeys(node) {
|
|
1773
|
+
return nodes(node.properties).flatMap((property) => property.type === "Property" && property.computed !== true && property.key !== void 0 ? [property.key] : []);
|
|
1774
|
+
}
|
|
1775
|
+
function visitCall(ctx, node, ancestors) {
|
|
1776
|
+
const callee = importedCallee(ctx, node.callee, ancestors);
|
|
1777
|
+
if (callee === void 0) return;
|
|
1778
|
+
const pending = awaitRow(ctx, callee);
|
|
1779
|
+
if (pending !== void 0 && ancestors.at(-1)?.type !== "AwaitExpression") reportUnawaited(ctx, node, ancestors, pending);
|
|
1780
|
+
const renamed = renameOf(ctx.set, callee.imported, callee.entry)?.to;
|
|
1781
|
+
const names = /* @__PURE__ */ new Set([callee.imported, renamed]);
|
|
1782
|
+
const moved = visitFunctionCall(ctx, node, callee);
|
|
1783
|
+
visitWraps(ctx, node, callee, ancestors);
|
|
1784
|
+
for (const signature of ctx.set.signatures) if (!moved && signature.entries.includes(callee.entry) && names.has(signature.name)) {
|
|
1785
|
+
if (signature.shape === "curried" && !isCurried(node, ancestors)) {
|
|
1786
|
+
ctx.newShapes.add(signature.name);
|
|
1787
|
+
continue;
|
|
1788
|
+
}
|
|
1789
|
+
ctx.followUps.push({
|
|
1790
|
+
at: node.start,
|
|
1791
|
+
name: signature.name,
|
|
1792
|
+
message: `\`${signature.before}\` is now \`${signature.after}\``
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
const rows = ctx.optionRows.filter((row) => row.entries.includes(callee.entry) && (row.calls ?? []).some((call) => names.has(call)));
|
|
1796
|
+
for (const argument of nodes(node.arguments)) if (argument.type === "ObjectExpression") renameOptions(ctx, argument, rows);
|
|
1797
|
+
}
|
|
1798
|
+
/** `f(options)(key)`, or `f({ … })` whose result is kept for a later call. */
|
|
1799
|
+
function isCurried(node, ancestors) {
|
|
1800
|
+
const args = nodes(node.arguments);
|
|
1801
|
+
const parent = ancestors.at(-1);
|
|
1802
|
+
return args.length === 1 && (args[0]?.type === "ObjectExpression" || parent?.type === "CallExpression" && parent.callee === node);
|
|
1803
|
+
}
|
|
1804
|
+
function renameOptions(ctx, object, rows) {
|
|
1805
|
+
for (const property of nodes(object.properties)) {
|
|
1806
|
+
const row = rows.find((item) => item.from === nameOf(property.key));
|
|
1807
|
+
if (row !== void 0) renameKey(ctx, property, row.from, row.to);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Rows with `calls` are renamed at those calls and nowhere else: their old
|
|
1812
|
+
* key (`store`) is still a valid option on every other factory. Rows without
|
|
1813
|
+
* `calls` are reported only on an object that reaches a permdock call.
|
|
1814
|
+
*/
|
|
1815
|
+
function reportOptions(ctx, node, ancestors) {
|
|
1816
|
+
const target = optionTarget(ctx, node, ancestors);
|
|
1817
|
+
if (target === void 0) return;
|
|
1818
|
+
const rows = ctx.optionRows.filter((row) => row.calls === void 0 && (target.entry === void 0 || row.entries.includes(target.entry)));
|
|
1819
|
+
for (const key of propertyKeys(node)) for (const row of rows) if (nameOf(key) === row.from && !ctx.handledKeys.has(key)) ctx.followUps.push({
|
|
1820
|
+
at: key.start,
|
|
1821
|
+
name: row.from,
|
|
1822
|
+
message: `option \`${row.from}\` is \`${row.to}\` when this object reaches ${listOf(row.entries)}`
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
const PASS_THROUGH = /* @__PURE__ */ new Set([
|
|
1826
|
+
"ArrayExpression",
|
|
1827
|
+
"ObjectExpression",
|
|
1828
|
+
"ParenthesizedExpression",
|
|
1829
|
+
"TSAsExpression",
|
|
1830
|
+
"TSSatisfiesExpression",
|
|
1831
|
+
"TSNonNullExpression"
|
|
1832
|
+
]);
|
|
1833
|
+
/**
|
|
1834
|
+
* The permdock call an object literal is an argument of, directly or nested
|
|
1835
|
+
* in another argument's object, array or property value. `entry` is unset
|
|
1836
|
+
* for a method on a receiver named after PermDock, whose entry is unknown.
|
|
1837
|
+
*/
|
|
1838
|
+
function optionTarget(ctx, node, ancestors) {
|
|
1839
|
+
let child = node;
|
|
1840
|
+
for (let index = ancestors.length - 1; index >= 0; index -= 1) {
|
|
1841
|
+
const parent = ancestors[index];
|
|
1842
|
+
if (parent === void 0) return;
|
|
1843
|
+
if (parent.type === "CallExpression" || parent.type === "NewExpression") return nodes(parent.arguments).includes(child) ? calleeTarget(ctx, parent.callee, ancestors) : void 0;
|
|
1844
|
+
if (!(parent.type === "Property" && parent.value === child || PASS_THROUGH.has(parent.type))) return;
|
|
1845
|
+
child = parent;
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
function calleeTarget(ctx, callee, ancestors) {
|
|
1849
|
+
const imported = importedCallee(ctx, callee, ancestors);
|
|
1850
|
+
if (imported !== void 0) return { entry: imported.entry };
|
|
1851
|
+
const receiver = callee?.type === "MemberExpression" && callee.computed !== true ? callee.object : void 0;
|
|
1852
|
+
if (!holdsInstance(ctx, receiver, ancestors)) return;
|
|
1853
|
+
const name = receiver?.name ?? "";
|
|
1854
|
+
return { entry: isModuleBinding(ctx, name, ancestors) ? ctx.factories.get(name) : void 0 };
|
|
1855
|
+
}
|
|
1856
|
+
function rewriteImports(ctx, removed) {
|
|
1857
|
+
for (const [local, binding] of ctx.bindings) {
|
|
1858
|
+
const { rename, spec } = binding;
|
|
1859
|
+
const imported = spec.imported;
|
|
1860
|
+
if (rename === void 0 || imported === void 0 || removed.has(local)) continue;
|
|
1861
|
+
if (local !== binding.imported) replace(ctx, imported, imported.type === "Literal" ? JSON.stringify(rename.to) : rename.to, rename.from);
|
|
1862
|
+
else replace(ctx, imported, ctx.kept.has(local) ? `${rename.to} as ${local}` : rename.to, rename.from);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
function rewriteReferences(ctx) {
|
|
1866
|
+
for (const { node, place, parent } of ctx.references) {
|
|
1867
|
+
const name = node.name ?? "";
|
|
1868
|
+
const rename = ctx.renamedLocals.get(name);
|
|
1869
|
+
if (rename === void 0 || ctx.kept.has(name) || ctx.consumed.has(node.start)) continue;
|
|
1870
|
+
if (place === "shorthand" && parent.key !== void 0 && ctx.handledKeys.has(parent.key)) replace(ctx, node, rename.to, name);
|
|
1871
|
+
else if (place === "shorthand") edit(ctx, parent, `${name}: ${rename.to}`, name, rename.to);
|
|
1872
|
+
else if (place === "export" && parent.exported?.start === node.start) replace(ctx, node, `${rename.to} as ${name}`, name);
|
|
1873
|
+
else replace(ctx, node, rename.to, name);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
/** `export { a } from 'permdock'` keeps exporting `a`: the module's own export name is not the codemod's to change. */
|
|
1877
|
+
function rewriteReexports(ctx) {
|
|
1878
|
+
for (const statement of nodes(ctx.program.body)) {
|
|
1879
|
+
const entry = statement.source?.value;
|
|
1880
|
+
if (statement.type !== "ExportNamedDeclaration" || !isPermDockSpecifier(entry)) continue;
|
|
1881
|
+
for (const spec of nodes(statement.specifiers)) {
|
|
1882
|
+
const local = spec.local;
|
|
1883
|
+
const rename = renameOf(ctx.set, nameOf(local) ?? "", entry);
|
|
1884
|
+
if (rename !== void 0 && local !== void 0) replace(ctx, local, spec.exported?.start === local.start ? `${rename.to} as ${rename.from}` : rename.to, rename.from);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
function reportUncalledSignatures(ctx, removed) {
|
|
1889
|
+
for (const [local, binding] of ctx.bindings) {
|
|
1890
|
+
if (removed.has(local)) continue;
|
|
1891
|
+
const names = /* @__PURE__ */ new Set([binding.imported, binding.rename?.to]);
|
|
1892
|
+
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({
|
|
1893
|
+
at: binding.spec.start,
|
|
1894
|
+
name: signature.name,
|
|
1895
|
+
message: `\`${local}\` is imported; \`${signature.before}\` is now \`${signature.after}\``
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
//#endregion
|
|
1900
|
+
//#region src/cli/codemod/codemod.ts
|
|
1901
|
+
const CODEMOD_0_5 = Object.freeze({
|
|
1902
|
+
renames: Object.freeze([...RENAMES_0_5, ...CALL_RENAMES_0_5]),
|
|
1903
|
+
signatures: SIGNATURE_CHANGES_0_5,
|
|
1904
|
+
props: PROP_RENAMES_0_5,
|
|
1905
|
+
templates: TEMPLATE_HINTS_0_5,
|
|
1906
|
+
awaits: AWAIT_RENAMES_0_5,
|
|
1907
|
+
methodFunctions: METHOD_FUNCTIONS_0_5,
|
|
1908
|
+
functionMethods: FUNCTION_METHODS_0_5,
|
|
1909
|
+
wraps: OPTION_WRAPS_0_5,
|
|
1910
|
+
durations: DURATION_KEYS_0_5
|
|
1911
|
+
});
|
|
1912
|
+
/** Each codemod version and the rename map it applies. */
|
|
1913
|
+
const CODEMODS = Object.freeze({ "0.5": CODEMOD_0_5 });
|
|
1914
|
+
function codemodVersions() {
|
|
1915
|
+
return Object.keys(CODEMODS);
|
|
1916
|
+
}
|
|
1917
|
+
const EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1918
|
+
".ts",
|
|
1919
|
+
".tsx",
|
|
1920
|
+
".mts",
|
|
1921
|
+
".cts",
|
|
1922
|
+
".js",
|
|
1923
|
+
".jsx",
|
|
1924
|
+
".mjs",
|
|
1925
|
+
".cjs",
|
|
1926
|
+
".vue",
|
|
1927
|
+
".svelte"
|
|
1928
|
+
]);
|
|
1929
|
+
/** Files whose shell commands the codemod rewrites when the version renames CLI names. */
|
|
1930
|
+
const CLI_FILE_NAMES = /* @__PURE__ */ new Set([
|
|
1931
|
+
"package.json",
|
|
1932
|
+
"Makefile",
|
|
1933
|
+
"justfile",
|
|
1934
|
+
"Dockerfile"
|
|
1935
|
+
]);
|
|
1936
|
+
const CLI_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1937
|
+
".yml",
|
|
1938
|
+
".yaml",
|
|
1939
|
+
".sh"
|
|
1940
|
+
]);
|
|
1941
|
+
/** Prose: the codemod lists the old calls in it and rewrites none. */
|
|
1942
|
+
const CLI_REVIEW_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".mdx"]);
|
|
1943
|
+
/** The versions whose renames include the CLI's own commands and flags. */
|
|
1944
|
+
const CLI_RENAME_VERSIONS = /* @__PURE__ */ new Set(["0.5"]);
|
|
1945
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
1946
|
+
"node_modules",
|
|
1947
|
+
"dist",
|
|
1948
|
+
".git",
|
|
1949
|
+
".next",
|
|
1950
|
+
".turbo",
|
|
1951
|
+
".svelte-kit",
|
|
1952
|
+
"coverage"
|
|
1953
|
+
]);
|
|
1954
|
+
function runCodemod(options) {
|
|
1955
|
+
const report = codemod(options);
|
|
1956
|
+
return {
|
|
1957
|
+
code: 0,
|
|
1958
|
+
output: options.json ? JSON.stringify(report, null, 2) : formatReport(report)
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1961
|
+
function codemod(options) {
|
|
1962
|
+
const version = normaliseVersion(options.version);
|
|
1963
|
+
const set = CODEMODS[version];
|
|
1964
|
+
if (set === void 0) throw new CliError("usage", `unknown codemod version '${version}'. Supported: ${Object.keys(CODEMODS).join(", ")}.`);
|
|
1965
|
+
const files = sourceFiles(options.cwd, options.paths.length === 0 ? ["."] : options.paths, CLI_RENAME_VERSIONS.has(version));
|
|
1966
|
+
const changed = [];
|
|
1967
|
+
const followUps = [];
|
|
1968
|
+
const writes = [];
|
|
1969
|
+
for (const file of files) {
|
|
1970
|
+
const source = readFileSync(file, "utf8");
|
|
1971
|
+
if (!source.includes("permdock")) continue;
|
|
1972
|
+
const name = rel(options.cwd, file);
|
|
1973
|
+
const result = isCodeFile(file) ? transformSource(file, source, set) : cliResult(file, source);
|
|
1974
|
+
if (result.error !== void 0) {
|
|
1975
|
+
followUps.push({
|
|
1976
|
+
file: name,
|
|
1977
|
+
line: 1,
|
|
1978
|
+
column: 1,
|
|
1979
|
+
name: "parse",
|
|
1980
|
+
message: `not parsed, left as it is: ${result.error}`
|
|
1981
|
+
});
|
|
1982
|
+
continue;
|
|
1983
|
+
}
|
|
1984
|
+
if (result.changes.length > 0) {
|
|
1985
|
+
changed.push({
|
|
1986
|
+
file: name,
|
|
1987
|
+
changes: result.changes
|
|
1988
|
+
});
|
|
1989
|
+
if (result.source !== source) writes.push({
|
|
1990
|
+
path: file,
|
|
1991
|
+
text: result.source
|
|
1992
|
+
});
|
|
1993
|
+
}
|
|
1994
|
+
for (const followUp of result.followUps) followUps.push({
|
|
1995
|
+
file: name,
|
|
1996
|
+
...followUp
|
|
1997
|
+
});
|
|
1998
|
+
}
|
|
1999
|
+
if (!options.dryRun && writes.length > 0) {
|
|
2000
|
+
refuseDirty({
|
|
2001
|
+
command: "codemod",
|
|
2002
|
+
invocation: [
|
|
2003
|
+
"codemod",
|
|
2004
|
+
version,
|
|
2005
|
+
...options.paths
|
|
2006
|
+
].join(" "),
|
|
2007
|
+
cwd: options.cwd,
|
|
2008
|
+
paths: writes.map((write) => write.path),
|
|
2009
|
+
force: options.force === true
|
|
2010
|
+
});
|
|
2011
|
+
applyFiles(options.cwd, writes);
|
|
2012
|
+
}
|
|
2013
|
+
return {
|
|
2014
|
+
version,
|
|
2015
|
+
dryRun: options.dryRun,
|
|
2016
|
+
scanned: files.length,
|
|
2017
|
+
files: changed,
|
|
2018
|
+
followUps
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
2021
|
+
function normaliseVersion(version) {
|
|
2022
|
+
if (version === void 0) throw new CliError("usage", `codemod needs a version: permdock codemod <version>. Supported: ${Object.keys(CODEMODS).join(", ")}.`);
|
|
2023
|
+
return /^v?(\d+\.\d+)(?:\.\d+)?$/u.exec(version)?.[1] ?? version;
|
|
2024
|
+
}
|
|
2025
|
+
function isCodeFile(file) {
|
|
2026
|
+
return EXTENSIONS.has(extname(file));
|
|
2027
|
+
}
|
|
2028
|
+
function isCliFile(name) {
|
|
2029
|
+
return CLI_FILE_NAMES.has(name) || CLI_EXTENSIONS.has(extname(name)) || CLI_REVIEW_EXTENSIONS.has(extname(name));
|
|
2030
|
+
}
|
|
2031
|
+
function cliResult(file, source) {
|
|
2032
|
+
const result = rewriteCliCalls(source, { json: extname(file) === ".json" });
|
|
2033
|
+
if (!CLI_REVIEW_EXTENSIONS.has(extname(file))) return {
|
|
2034
|
+
source: result.text,
|
|
2035
|
+
changes: result.changes,
|
|
2036
|
+
followUps: result.followUps
|
|
2037
|
+
};
|
|
2038
|
+
return {
|
|
2039
|
+
source,
|
|
2040
|
+
changes: [],
|
|
2041
|
+
followUps: [...result.changes.map((change) => ({
|
|
2042
|
+
line: change.line,
|
|
2043
|
+
column: change.column,
|
|
2044
|
+
name: "cli",
|
|
2045
|
+
message: `${change.from} → ${change.to} since 0.5.0`
|
|
2046
|
+
})), ...result.followUps]
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
function sourceFiles(cwd, paths, cli) {
|
|
2050
|
+
const out = /* @__PURE__ */ new Set();
|
|
2051
|
+
for (const path of paths) {
|
|
2052
|
+
const root = resolve(cwd, path);
|
|
2053
|
+
const stats = statSync(root, { throwIfNoEntry: false });
|
|
2054
|
+
if (stats === void 0) throw new CliError("usage", `not found: ${path}`);
|
|
2055
|
+
if (stats.isFile()) out.add(root);
|
|
2056
|
+
else walkDir(root, out, cli);
|
|
2057
|
+
}
|
|
2058
|
+
return [...out].toSorted();
|
|
2059
|
+
}
|
|
2060
|
+
function walkDir(dir, out, cli) {
|
|
2061
|
+
for (const name of readdirSync(dir)) {
|
|
2062
|
+
if (SKIP_DIRS.has(name)) continue;
|
|
2063
|
+
const full = join(dir, name);
|
|
2064
|
+
if (statSync(full).isDirectory()) walkDir(full, out, cli);
|
|
2065
|
+
else if (EXTENSIONS.has(extname(name)) || cli && isCliFile(name)) out.add(full);
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
function formatReport(report) {
|
|
2069
|
+
const lines = [];
|
|
2070
|
+
const changes = report.files.reduce((sum, file) => sum + file.changes.length, 0);
|
|
2071
|
+
const verb = report.dryRun ? "would change" : "changed";
|
|
2072
|
+
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)" : ""}`);
|
|
2073
|
+
for (const file of report.files) {
|
|
2074
|
+
lines.push("", file.file);
|
|
2075
|
+
for (const change of file.changes) lines.push(` ${change.line}:${change.column} ${change.from} → ${change.to}`);
|
|
2076
|
+
}
|
|
2077
|
+
if (report.followUps.length > 0) {
|
|
2078
|
+
lines.push("", "Manual follow-ups");
|
|
2079
|
+
for (const item of report.followUps) lines.push(` ${item.file}:${item.line}:${item.column} ${item.message}`);
|
|
2080
|
+
}
|
|
2081
|
+
return lines.join("\n");
|
|
2082
|
+
}
|
|
2083
|
+
//#endregion
|
|
2084
|
+
export { codemodVersions, runCodemod };
|