@superblocksteam/vite-plugin-file-sync 2.0.174 → 2.0.175-next.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/dist/agent-tool-executor/codex-drafts.d.ts +12 -0
- package/dist/agent-tool-executor/codex-drafts.d.ts.map +1 -0
- package/dist/agent-tool-executor/codex-drafts.js +48 -0
- package/dist/agent-tool-executor/codex-drafts.js.map +1 -0
- package/dist/agent-tool-executor/codex-exec-server.d.ts +42 -0
- package/dist/agent-tool-executor/codex-exec-server.d.ts.map +1 -0
- package/dist/agent-tool-executor/codex-exec-server.js +405 -0
- package/dist/agent-tool-executor/codex-exec-server.js.map +1 -0
- package/dist/agent-tool-executor/codex-execution-policy.d.ts +12 -0
- package/dist/agent-tool-executor/codex-execution-policy.d.ts.map +1 -0
- package/dist/agent-tool-executor/codex-execution-policy.js +201 -0
- package/dist/agent-tool-executor/codex-execution-policy.js.map +1 -0
- package/dist/agent-tool-executor/native-dotenv-watch-scope.d.ts +12 -0
- package/dist/agent-tool-executor/native-dotenv-watch-scope.d.ts.map +1 -0
- package/dist/agent-tool-executor/native-dotenv-watch-scope.js +74 -0
- package/dist/agent-tool-executor/native-dotenv-watch-scope.js.map +1 -0
- package/dist/ai-service/agent/middleware.d.ts.map +1 -1
- package/dist/ai-service/agent/middleware.js +45 -0
- package/dist/ai-service/agent/middleware.js.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js +17 -2
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/prompts/build-security-scan-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-security-scan-prompt.js +106 -11
- package/dist/ai-service/agent/prompts/build-security-scan-prompt.js.map +1 -1
- package/dist/ai-service/agent/security-scan-tools.d.ts +12 -0
- package/dist/ai-service/agent/security-scan-tools.d.ts.map +1 -0
- package/dist/ai-service/agent/security-scan-tools.js +44 -0
- package/dist/ai-service/agent/security-scan-tools.js.map +1 -0
- package/dist/ai-service/agent/tool-permission-delivery-metrics.d.ts +1 -1
- package/dist/ai-service/agent/tool-permission-delivery-metrics.d.ts.map +1 -1
- package/dist/ai-service/agent/tool-permission-delivery-metrics.js +1 -1
- package/dist/ai-service/agent/tool-permission-delivery-metrics.js.map +1 -1
- package/dist/ai-service/agent/tool-permission-delivery.d.ts +2 -0
- package/dist/ai-service/agent/tool-permission-delivery.d.ts.map +1 -1
- package/dist/ai-service/agent/tool-permission-delivery.js +7 -0
- package/dist/ai-service/agent/tool-permission-delivery.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/get-api-docs.d.ts +3 -3
- package/dist/ai-service/agent/tools/apis/test-api.d.ts +78 -13
- package/dist/ai-service/agent/tools/apis/test-api.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/apis/test-api.js +80 -58
- package/dist/ai-service/agent/tools/apis/test-api.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/write-api.d.ts +2 -2
- package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts +11 -3
- package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-capture-screenshot.js +13 -8
- package/dist/ai-service/agent/tools/build-capture-screenshot.js.map +1 -1
- package/dist/ai-service/agent/tools/build-delete-file.d.ts +1 -1
- package/dist/ai-service/agent/tools/build-manage-checklist.d.ts +1 -1
- package/dist/ai-service/agent/tools/build-navigate-preview.d.ts +6 -0
- package/dist/ai-service/agent/tools/build-navigate-preview.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-navigate-preview.js +5 -4
- package/dist/ai-service/agent/tools/build-navigate-preview.js.map +1 -1
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.d.ts +4 -1
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.js +6 -3
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.js.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts +11 -4
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.js +21 -3
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.js.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tools.js +32 -5
- package/dist/ai-service/agent/tools/databases/dev-database-tools.js.map +1 -1
- package/dist/ai-service/agent/tools/get-logs.d.ts +5 -2
- package/dist/ai-service/agent/tools/get-logs.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/get-logs.js +6 -3
- package/dist/ai-service/agent/tools/get-logs.js.map +1 -1
- package/dist/ai-service/agent/tools/get-runtime-errors.d.ts +2 -0
- package/dist/ai-service/agent/tools/get-runtime-errors.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/get-runtime-errors.js +3 -2
- package/dist/ai-service/agent/tools/get-runtime-errors.js.map +1 -1
- package/dist/ai-service/agent/tools/get-security-findings.js +1 -1
- package/dist/ai-service/agent/tools/integrations/execute-request.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/integrations/execute-request.js +28 -3
- package/dist/ai-service/agent/tools/integrations/execute-request.js.map +1 -1
- package/dist/ai-service/agent/tools/integrations/managed-app-database.d.ts +28 -0
- package/dist/ai-service/agent/tools/integrations/managed-app-database.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/integrations/managed-app-database.js +30 -1
- package/dist/ai-service/agent/tools/integrations/managed-app-database.js.map +1 -1
- package/dist/ai-service/agent/tools/integrations/metadata.d.ts +6 -3
- package/dist/ai-service/agent/tools/integrations/metadata.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/integrations/metadata.js +34 -17
- package/dist/ai-service/agent/tools/integrations/metadata.js.map +1 -1
- package/dist/ai-service/agent/tools/report-security-findings.d.ts +3 -3
- package/dist/ai-service/agent/tools/report-security-findings.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/report-security-findings.js +6 -4
- package/dist/ai-service/agent/tools/report-security-findings.js.map +1 -1
- package/dist/ai-service/agent/tools.d.ts +1 -5
- package/dist/ai-service/agent/tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.js +7 -42
- package/dist/ai-service/agent/tools.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts +4 -3
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js +4 -2
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep.js +27 -5
- package/dist/ai-service/agent/tools2/tools/grep.js.map +1 -1
- package/dist/ai-service/agent/utils.d.ts.map +1 -1
- package/dist/ai-service/agent/utils.js +12 -8
- package/dist/ai-service/agent/utils.js.map +1 -1
- package/dist/ai-service/app-interface/file-system-interface.d.ts +1 -1
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.d.ts +2 -1
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.d.ts.map +1 -1
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.js +9 -2
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.js.map +1 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.d.ts +1 -0
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.d.ts.map +1 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.js +1 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.js.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.d.ts +1 -0
- package/dist/ai-service/app-interface/npm-registry.d.ts.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.js +45 -6
- package/dist/ai-service/app-interface/npm-registry.js.map +1 -1
- package/dist/ai-service/app-interface/shell.d.ts +7 -1
- package/dist/ai-service/app-interface/shell.d.ts.map +1 -1
- package/dist/ai-service/app-interface/shell.js +84 -30
- package/dist/ai-service/app-interface/shell.js.map +1 -1
- package/dist/ai-service/builder-conversation.d.ts +70 -0
- package/dist/ai-service/builder-conversation.d.ts.map +1 -0
- package/dist/ai-service/builder-conversation.js +660 -0
- package/dist/ai-service/builder-conversation.js.map +1 -0
- package/dist/ai-service/builder-inference-auth.d.ts +11 -0
- package/dist/ai-service/builder-inference-auth.d.ts.map +1 -0
- package/dist/ai-service/builder-inference-auth.js +48 -0
- package/dist/ai-service/builder-inference-auth.js.map +1 -0
- package/dist/ai-service/builder-runtime.d.ts +181 -0
- package/dist/ai-service/builder-runtime.d.ts.map +1 -0
- package/dist/ai-service/builder-runtime.js +337 -0
- package/dist/ai-service/builder-runtime.js.map +1 -0
- package/dist/ai-service/builder-session-store.d.ts +26 -0
- package/dist/ai-service/builder-session-store.d.ts.map +1 -0
- package/dist/ai-service/builder-session-store.js +66 -0
- package/dist/ai-service/builder-session-store.js.map +1 -0
- package/dist/ai-service/builder-tool-callbacks.d.ts +26 -0
- package/dist/ai-service/builder-tool-callbacks.d.ts.map +1 -0
- package/dist/ai-service/builder-tool-callbacks.js +114 -0
- package/dist/ai-service/builder-tool-callbacks.js.map +1 -0
- package/dist/ai-service/builder-tools.d.ts +46 -0
- package/dist/ai-service/builder-tools.d.ts.map +1 -0
- package/dist/ai-service/builder-tools.js +181 -0
- package/dist/ai-service/builder-tools.js.map +1 -0
- package/dist/ai-service/chat/chat-session-store.d.ts +10 -1
- package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
- package/dist/ai-service/chat/chat-session-store.js +30 -1
- package/dist/ai-service/chat/chat-session-store.js.map +1 -1
- package/dist/ai-service/chat/switch-chat-seed.d.ts +8 -0
- package/dist/ai-service/chat/switch-chat-seed.d.ts.map +1 -0
- package/dist/ai-service/chat/switch-chat-seed.js +47 -0
- package/dist/ai-service/chat/switch-chat-seed.js.map +1 -0
- package/dist/ai-service/dev-database-client.d.ts +1 -0
- package/dist/ai-service/dev-database-client.d.ts.map +1 -1
- package/dist/ai-service/dev-database-client.js +1 -0
- package/dist/ai-service/dev-database-client.js.map +1 -1
- package/dist/ai-service/dev-database-file-sync.d.ts +3 -1
- package/dist/ai-service/dev-database-file-sync.d.ts.map +1 -1
- package/dist/ai-service/dev-database-file-sync.js.map +1 -1
- package/dist/ai-service/edit-after-clark.d.ts.map +1 -1
- package/dist/ai-service/edit-after-clark.js +10 -5
- package/dist/ai-service/edit-after-clark.js.map +1 -1
- package/dist/ai-service/features.d.ts +15 -8
- package/dist/ai-service/features.d.ts.map +1 -1
- package/dist/ai-service/features.js +15 -8
- package/dist/ai-service/features.js.map +1 -1
- package/dist/ai-service/index.d.ts +47 -19
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +564 -743
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/integrations/store.d.ts +5 -1
- package/dist/ai-service/integrations/store.d.ts.map +1 -1
- package/dist/ai-service/integrations/store.js +8 -0
- package/dist/ai-service/integrations/store.js.map +1 -1
- package/dist/ai-service/llm/context-v2/context-metrics.js +2 -2
- package/dist/ai-service/llm/context-v2/manager.d.ts +3 -1
- package/dist/ai-service/llm/context-v2/manager.d.ts.map +1 -1
- package/dist/ai-service/llm/context-v2/manager.js +5 -0
- package/dist/ai-service/llm/context-v2/manager.js.map +1 -1
- package/dist/ai-service/llm/context-v2/types.d.ts +1 -1
- package/dist/ai-service/llm/context-v2/types.d.ts.map +1 -1
- package/dist/ai-service/llm/context-v2/types.js.map +1 -1
- package/dist/ai-service/llm/error.d.ts.map +1 -1
- package/dist/ai-service/llm/error.js +17 -3
- package/dist/ai-service/llm/error.js.map +1 -1
- package/dist/ai-service/llm/request-settings.d.ts +6 -0
- package/dist/ai-service/llm/request-settings.d.ts.map +1 -0
- package/dist/ai-service/llm/request-settings.js +21 -0
- package/dist/ai-service/llm/request-settings.js.map +1 -0
- package/dist/ai-service/llm/stream/config.d.ts +1 -1
- package/dist/ai-service/llm/stream/config.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/config.js.map +1 -1
- package/dist/ai-service/llm/stream/errors.d.ts +4 -1
- package/dist/ai-service/llm/stream/errors.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/errors.js +8 -2
- package/dist/ai-service/llm/stream/errors.js.map +1 -1
- package/dist/ai-service/llm/stream/observers/llmobs.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/observers/llmobs.js +5 -2
- package/dist/ai-service/llm/stream/observers/llmobs.js.map +1 -1
- package/dist/ai-service/llm/stream/orchestrator.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/orchestrator.js +3 -6
- package/dist/ai-service/llm/stream/orchestrator.js.map +1 -1
- package/dist/ai-service/llmobs/otel-exporter.d.ts.map +1 -1
- package/dist/ai-service/llmobs/otel-exporter.js +4 -0
- package/dist/ai-service/llmobs/otel-exporter.js.map +1 -1
- package/dist/ai-service/llmobs/tracer.d.ts.map +1 -1
- package/dist/ai-service/llmobs/tracer.js +4 -21
- package/dist/ai-service/llmobs/tracer.js.map +1 -1
- package/dist/ai-service/managed-native-db-availability.d.ts +1 -1
- package/dist/ai-service/managed-native-db-availability.d.ts.map +1 -1
- package/dist/ai-service/managed-native-db-availability.js +4 -2
- package/dist/ai-service/managed-native-db-availability.js.map +1 -1
- package/dist/ai-service/native-callback-order.d.ts +7 -0
- package/dist/ai-service/native-callback-order.d.ts.map +1 -0
- package/dist/ai-service/native-callback-order.js +39 -0
- package/dist/ai-service/native-callback-order.js.map +1 -0
- package/dist/ai-service/native-secret-redactor.d.ts +4 -0
- package/dist/ai-service/native-secret-redactor.d.ts.map +1 -0
- package/dist/ai-service/native-secret-redactor.js +34 -0
- package/dist/ai-service/native-secret-redactor.js.map +1 -0
- package/dist/ai-service/policy-agent-metrics.d.ts +1 -1
- package/dist/ai-service/policy-agent-metrics.d.ts.map +1 -1
- package/dist/ai-service/policy-agent-metrics.js +1 -0
- package/dist/ai-service/policy-agent-metrics.js.map +1 -1
- package/dist/ai-service/policy-gate-error.d.ts.map +1 -1
- package/dist/ai-service/policy-gate-error.js +34 -3
- package/dist/ai-service/policy-gate-error.js.map +1 -1
- package/dist/ai-service/policy-gate-remediation-usage.d.ts +2 -1
- package/dist/ai-service/policy-gate-remediation-usage.d.ts.map +1 -1
- package/dist/ai-service/policy-gate-remediation-usage.js +2 -1
- package/dist/ai-service/policy-gate-remediation-usage.js.map +1 -1
- package/dist/ai-service/policy-gate-review.d.ts +42 -0
- package/dist/ai-service/policy-gate-review.d.ts.map +1 -0
- package/dist/ai-service/policy-gate-review.js +664 -0
- package/dist/ai-service/policy-gate-review.js.map +1 -0
- package/dist/ai-service/skills/system/materialized.d.ts +3 -1
- package/dist/ai-service/skills/system/materialized.d.ts.map +1 -1
- package/dist/ai-service/skills/system/materialized.js +3 -3
- package/dist/ai-service/skills/system/materialized.js.map +1 -1
- package/dist/ai-service/skills/system/native.d.ts +7 -0
- package/dist/ai-service/skills/system/native.d.ts.map +1 -0
- package/dist/ai-service/skills/system/native.js +25 -0
- package/dist/ai-service/skills/system/native.js.map +1 -0
- package/dist/ai-service/skills/system/paths.d.ts +2 -0
- package/dist/ai-service/skills/system/paths.d.ts.map +1 -0
- package/dist/ai-service/skills/system/paths.js +2 -0
- package/dist/ai-service/skills/system/paths.js.map +1 -0
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +31 -8
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/peer.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/peer.js +5 -4
- package/dist/ai-service/state-machine/helpers/peer.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.d.ts +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.js +2 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/stable-peer.d.ts +2 -0
- package/dist/ai-service/state-machine/helpers/stable-peer.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/stable-peer.js +29 -4
- package/dist/ai-service/state-machine/helpers/stable-peer.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/user-response-message.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/user-response-message.js +4 -2
- package/dist/ai-service/state-machine/helpers/user-response-message.js.map +1 -1
- package/dist/ai-service/types.d.ts +3 -0
- package/dist/ai-service/types.d.ts.map +1 -1
- package/dist/ai-service/types.js.map +1 -1
- package/dist/ai-service/util/rpc-timeout.d.ts +2 -0
- package/dist/ai-service/util/rpc-timeout.d.ts.map +1 -1
- package/dist/ai-service/util/rpc-timeout.js +2 -0
- package/dist/ai-service/util/rpc-timeout.js.map +1 -1
- package/dist/ai-service/util/stop-condition.d.ts +8 -0
- package/dist/ai-service/util/stop-condition.d.ts.map +1 -1
- package/dist/ai-service/util/stop-condition.js +15 -0
- package/dist/ai-service/util/stop-condition.js.map +1 -1
- package/dist/extract-api-integrations.d.ts +52 -87
- package/dist/extract-api-integrations.d.ts.map +1 -1
- package/dist/extract-api-integrations.js +512 -473
- package/dist/extract-api-integrations.js.map +1 -1
- package/dist/file-sync-vite-plugin.d.ts.map +1 -1
- package/dist/file-sync-vite-plugin.js +53 -5
- package/dist/file-sync-vite-plugin.js.map +1 -1
- package/dist/file-system-helpers.d.ts +2 -0
- package/dist/file-system-helpers.d.ts.map +1 -1
- package/dist/file-system-helpers.js +7 -3
- package/dist/file-system-helpers.js.map +1 -1
- package/dist/git-service/credential-scope.d.ts +16 -0
- package/dist/git-service/credential-scope.d.ts.map +1 -0
- package/dist/git-service/credential-scope.js +91 -0
- package/dist/git-service/credential-scope.js.map +1 -0
- package/dist/git-service/index.d.ts +1 -0
- package/dist/git-service/index.d.ts.map +1 -1
- package/dist/git-service/index.js +11 -32
- package/dist/git-service/index.js.map +1 -1
- package/dist/git-service/managed-excludes.d.ts.map +1 -1
- package/dist/git-service/managed-excludes.js +2 -0
- package/dist/git-service/managed-excludes.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/injected-index.d.ts +1 -3
- package/dist/injected-index.d.ts.map +1 -1
- package/dist/injected-index.js +3 -8
- package/dist/injected-index.js.map +1 -1
- package/dist/lock-service/index.d.ts +3 -0
- package/dist/lock-service/index.d.ts.map +1 -1
- package/dist/lock-service/index.js +7 -0
- package/dist/lock-service/index.js.map +1 -1
- package/dist/migration/get-fullstack-template-dir.d.ts +2 -5
- package/dist/migration/get-fullstack-template-dir.d.ts.map +1 -1
- package/dist/migration/get-fullstack-template-dir.js +5 -8
- package/dist/migration/get-fullstack-template-dir.js.map +1 -1
- package/dist/migration-templates/app-fullstack/client/components/hooks/use-mobile.ts +9 -14
- package/dist/migration-templates/app-fullstack/package.json +43 -43
- package/dist/plugin-options.d.ts +1 -1
- package/dist/plugin-options.d.ts.map +1 -1
- package/dist/policy-gate-runner.d.ts +32 -7
- package/dist/policy-gate-runner.d.ts.map +1 -1
- package/dist/policy-gate-runner.js +23 -6
- package/dist/policy-gate-runner.js.map +1 -1
- package/dist/review-runner.d.ts +25 -0
- package/dist/review-runner.d.ts.map +1 -0
- package/dist/review-runner.js +196 -0
- package/dist/review-runner.js.map +1 -0
- package/dist/socket-manager.d.ts +9 -2
- package/dist/socket-manager.d.ts.map +1 -1
- package/dist/socket-manager.js +160 -19
- package/dist/socket-manager.js.map +1 -1
- package/dist/sync-service/download.d.ts +22 -0
- package/dist/sync-service/download.d.ts.map +1 -1
- package/dist/sync-service/download.js +154 -1
- package/dist/sync-service/download.js.map +1 -1
- package/dist/sync-service/draft-helpers.d.ts +23 -3
- package/dist/sync-service/draft-helpers.d.ts.map +1 -1
- package/dist/sync-service/draft-helpers.js +196 -72
- package/dist/sync-service/draft-helpers.js.map +1 -1
- package/dist/sync-service/draft-mutation.d.ts +11 -0
- package/dist/sync-service/draft-mutation.d.ts.map +1 -0
- package/dist/sync-service/draft-mutation.js +121 -0
- package/dist/sync-service/draft-mutation.js.map +1 -0
- package/dist/sync-service/draft-state-report-metrics.d.ts +3 -0
- package/dist/sync-service/draft-state-report-metrics.d.ts.map +1 -1
- package/dist/sync-service/draft-state-report-metrics.js +9 -0
- package/dist/sync-service/draft-state-report-metrics.js.map +1 -1
- package/dist/sync-service/index.d.ts +29 -1
- package/dist/sync-service/index.d.ts.map +1 -1
- package/dist/sync-service/index.js +241 -10
- package/dist/sync-service/index.js.map +1 -1
- package/dist/sync-service/list-dir.d.ts +3 -1
- package/dist/sync-service/list-dir.d.ts.map +1 -1
- package/dist/sync-service/list-dir.js +9 -2
- package/dist/sync-service/list-dir.js.map +1 -1
- package/dist/sync-service/native-draft-session.d.ts +22 -0
- package/dist/sync-service/native-draft-session.d.ts.map +1 -0
- package/dist/sync-service/native-draft-session.js +229 -0
- package/dist/sync-service/native-draft-session.js.map +1 -0
- package/dist/sync-service/safe-directory-reader.d.ts +24 -0
- package/dist/sync-service/safe-directory-reader.d.ts.map +1 -0
- package/dist/sync-service/safe-directory-reader.js +124 -0
- package/dist/sync-service/safe-directory-reader.js.map +1 -0
- package/dist/util/log-sanitizer.d.ts +4 -0
- package/dist/util/log-sanitizer.d.ts.map +1 -1
- package/dist/util/log-sanitizer.js +7 -0
- package/dist/util/log-sanitizer.js.map +1 -1
- package/package.json +57 -52
- package/dist/migration-templates/app-fullstack/.gitignore +0 -50
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { posix as posixPath } from "node:path";
|
|
2
2
|
import { parse } from "@babel/parser";
|
|
3
|
+
import * as t from "@babel/types";
|
|
3
4
|
function isNode(value) {
|
|
4
5
|
return !!value && typeof value === "object";
|
|
5
6
|
}
|
|
@@ -76,154 +77,48 @@ function unwrapExpression(node) {
|
|
|
76
77
|
}
|
|
77
78
|
return node;
|
|
78
79
|
}
|
|
80
|
+
function specifiersOf(statement) {
|
|
81
|
+
return Array.isArray(statement.specifiers)
|
|
82
|
+
? statement.specifiers.filter(isNode)
|
|
83
|
+
: [];
|
|
84
|
+
}
|
|
79
85
|
function isTypeOnly(node) {
|
|
80
86
|
return (node.importKind === "type" ||
|
|
81
87
|
node.importKind === "typeof" ||
|
|
82
88
|
node.exportKind === "type");
|
|
83
89
|
}
|
|
84
90
|
function valueSpecifiersOf(statement) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return statement.specifiers.filter((specifier) => isNode(specifier) && !isTypeOnly(specifier));
|
|
91
|
+
return isTypeOnly(statement)
|
|
92
|
+
? []
|
|
93
|
+
: specifiersOf(statement).filter((specifier) => !isTypeOnly(specifier));
|
|
89
94
|
}
|
|
90
95
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* a `VariableDeclaration`) to its inner `VariableDeclaration` so exported
|
|
95
|
-
* declarations are visited the same as bare ones. A `declare` statement has
|
|
96
|
-
* no runtime value, so it is never visited.
|
|
96
|
+
* The declarators of a top-level `const`, `let`, or `var` statement,
|
|
97
|
+
* including an exported one, and none for a `declare` statement, which has
|
|
98
|
+
* no runtime value.
|
|
97
99
|
*/
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
: statement;
|
|
107
|
-
if (declarationNode.type !== "VariableDeclaration" ||
|
|
108
|
-
declarationNode.declare === true ||
|
|
109
|
-
(bindings === "const-only" && declarationNode.kind !== "const") ||
|
|
110
|
-
!Array.isArray(declarationNode.declarations)) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
for (const declaration of declarationNode.declarations) {
|
|
114
|
-
if (isNode(declaration)) {
|
|
115
|
-
visitor(declaration);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function buildVariableInitializerMap(programBody, bindings) {
|
|
121
|
-
const initializers = new Map();
|
|
122
|
-
visitVariableDeclarations(programBody, bindings, (declaration) => {
|
|
123
|
-
const identifier = declaration.id;
|
|
124
|
-
if (!isNode(identifier) ||
|
|
125
|
-
identifier.type !== "Identifier" ||
|
|
126
|
-
typeof identifier.name !== "string") {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
initializers.set(identifier.name, declaration.init);
|
|
130
|
-
});
|
|
131
|
-
return initializers;
|
|
132
|
-
}
|
|
133
|
-
function resolveApiConfigObject(expression, variableInitializers) {
|
|
134
|
-
const resolvedExpression = unwrapExpression(expression);
|
|
135
|
-
if (!resolvedExpression) {
|
|
136
|
-
return undefined;
|
|
137
|
-
}
|
|
138
|
-
if (resolvedExpression.type === "Identifier" &&
|
|
139
|
-
typeof resolvedExpression.name === "string") {
|
|
140
|
-
return resolveApiConfigObject(variableInitializers.get(resolvedExpression.name), variableInitializers);
|
|
141
|
-
}
|
|
142
|
-
if (resolvedExpression.type !== "CallExpression" ||
|
|
143
|
-
getCalleeName(resolvedExpression.callee) !== "api" ||
|
|
144
|
-
!Array.isArray(resolvedExpression.arguments)) {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
const config = unwrapExpression(resolvedExpression.arguments[0]);
|
|
148
|
-
if (!config || config.type !== "ObjectExpression") {
|
|
149
|
-
return undefined;
|
|
150
|
-
}
|
|
151
|
-
return config;
|
|
152
|
-
}
|
|
153
|
-
function findExportedApiConfigObject(programBody, bindings) {
|
|
154
|
-
const variableInitializers = buildVariableInitializerMap(programBody, bindings);
|
|
155
|
-
for (const statement of programBody) {
|
|
156
|
-
if (!isNode(statement)) {
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (statement.type === "ExportDefaultDeclaration") {
|
|
160
|
-
return resolveApiConfigObject(statement.declaration, variableInitializers);
|
|
161
|
-
}
|
|
162
|
-
if (statement.type === "ExportNamedDeclaration" &&
|
|
163
|
-
!isNode(statement.source)) {
|
|
164
|
-
for (const specifier of valueSpecifiersOf(statement)) {
|
|
165
|
-
if (specifier.type !== "ExportSpecifier" ||
|
|
166
|
-
getPropertyName(specifier.exported) !== "default") {
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
return resolveApiConfigObject(specifier.local, variableInitializers);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
100
|
+
function variableDeclaratorsOf(statement) {
|
|
101
|
+
const declaration = statement.type === "ExportNamedDeclaration" && isNode(statement.declaration)
|
|
102
|
+
? statement.declaration
|
|
103
|
+
: statement;
|
|
104
|
+
if (declaration.type !== "VariableDeclaration" ||
|
|
105
|
+
declaration.declare === true ||
|
|
106
|
+
!Array.isArray(declaration.declarations)) {
|
|
107
|
+
return [];
|
|
172
108
|
}
|
|
173
|
-
return
|
|
109
|
+
return declaration.declarations
|
|
110
|
+
.filter(isNode)
|
|
111
|
+
.map((declarator) => ({ kind: declaration.kind, declarator }));
|
|
174
112
|
}
|
|
175
|
-
function
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const identifier = declaration.id;
|
|
179
|
-
const init = declaration.init;
|
|
180
|
-
if (!isNode(identifier) ||
|
|
181
|
-
identifier.type !== "Identifier" ||
|
|
182
|
-
typeof identifier.name !== "string") {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (!isNode(init) ||
|
|
186
|
-
init.type !== "CallExpression" ||
|
|
187
|
-
!Array.isArray(init.arguments)) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const pluginId = getCalleeName(init.callee);
|
|
191
|
-
const id = resolveStringArgument(init.arguments[0], stringLiterals);
|
|
192
|
-
if (!pluginId || !id) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
refs.set(identifier.name, { pluginId, id });
|
|
196
|
-
});
|
|
197
|
-
return refs;
|
|
198
|
-
}
|
|
199
|
-
function buildStringLiteralMap(programBody, bindings) {
|
|
200
|
-
const literals = new Map();
|
|
201
|
-
visitVariableDeclarations(programBody, bindings, (declaration) => {
|
|
202
|
-
const identifier = declaration.id;
|
|
203
|
-
if (!isNode(identifier) ||
|
|
204
|
-
identifier.type !== "Identifier" ||
|
|
205
|
-
typeof identifier.name !== "string") {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const value = getLiteralString(declaration.init);
|
|
209
|
-
if (value !== undefined) {
|
|
210
|
-
literals.set(identifier.name, value);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
return literals;
|
|
214
|
-
}
|
|
215
|
-
function resolveStringArgument(node, stringLiterals) {
|
|
216
|
-
const literal = getLiteralString(node);
|
|
217
|
-
if (literal !== undefined) {
|
|
218
|
-
return literal;
|
|
219
|
-
}
|
|
220
|
-
if (isNode(node) &&
|
|
221
|
-
node.type === "Identifier" &&
|
|
222
|
-
typeof node.name === "string") {
|
|
223
|
-
return stringLiterals.get(node.name);
|
|
113
|
+
function declaredNames(declaration) {
|
|
114
|
+
if (!t.isNode(declaration)) {
|
|
115
|
+
return [];
|
|
224
116
|
}
|
|
225
|
-
|
|
117
|
+
const names = Object.keys(t.getOuterBindingIdentifiers(declaration));
|
|
118
|
+
const declaredName = "id" in declaration ? getPropertyName(declaration.id) : undefined;
|
|
119
|
+
return declaredName ? [...names, declaredName] : names;
|
|
226
120
|
}
|
|
121
|
+
const UNRESOLVED_EXPORT = { kind: "unresolved" };
|
|
227
122
|
/**
|
|
228
123
|
* The object literals an `api()` config declares its integrations in, and
|
|
229
124
|
* whether they are all it declares. A spread, a computed key, an
|
|
@@ -245,216 +140,97 @@ function readIntegrationsObjects(apiConfig) {
|
|
|
245
140
|
members.every((member) => getMemberKeyName(member) !== undefined),
|
|
246
141
|
};
|
|
247
142
|
}
|
|
248
|
-
function
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
// "../lib/constants.js"`) so a same-file declaration like
|
|
252
|
-
// `const sheets = restApiIntegration(SHEETS_ID)` can resolve them. Only
|
|
253
|
-
// fill in names the same-file scan didn't already find, so a same-file
|
|
254
|
-
// literal always wins over an imported one of the same name. In practice
|
|
255
|
-
// this `!stringLiterals.has(name)` check is defensive and unreachable for
|
|
256
|
-
// valid input: a same-file `const X` and an `import { X }` of the same
|
|
257
|
-
// name is a duplicate lexical binding, which is a parse/type error in
|
|
258
|
-
// real TS/ESM and can't occur in a file that actually compiles.
|
|
259
|
-
for (const [name, ref] of importedRefs) {
|
|
260
|
-
if (ref.kind === "id" && !stringLiterals.has(name)) {
|
|
261
|
-
stringLiterals.set(name, ref.id);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
const variableRefs = buildVariableReferenceMap(programBody, stringLiterals, bindings);
|
|
265
|
-
const apiConfig = findExportedApiConfigObject(programBody, bindings);
|
|
266
|
-
if (!apiConfig) {
|
|
267
|
-
return { integrations: [], unresolvedKeys: [] };
|
|
268
|
-
}
|
|
269
|
-
const { objects, isDefinitive } = readIntegrationsObjects(apiConfig);
|
|
270
|
-
const integrations = [];
|
|
271
|
-
const unresolvedKeys = isDefinitive ? [] : ["*"];
|
|
272
|
-
for (const property of objects.flatMap(membersOf)) {
|
|
273
|
-
if (property.type !== "ObjectProperty") {
|
|
274
|
-
// Not a key/value property at all (e.g. a spread element or a method),
|
|
275
|
-
// so there is no key to report as unresolved.
|
|
276
|
-
unresolvedKeys.push("(dynamic)");
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
const key = getMemberKeyName(property);
|
|
280
|
-
if (!key) {
|
|
281
|
-
unresolvedKeys.push("(unknown)");
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
if (isNode(property.value) &&
|
|
285
|
-
property.value.type === "CallExpression" &&
|
|
286
|
-
Array.isArray(property.value.arguments)) {
|
|
287
|
-
const pluginId = getCalleeName(property.value.callee);
|
|
288
|
-
const arg = property.value.arguments[0];
|
|
289
|
-
let id = resolveStringArgument(arg, stringLiterals);
|
|
290
|
-
if (!id &&
|
|
291
|
-
isNode(arg) &&
|
|
292
|
-
arg.type === "Identifier" &&
|
|
293
|
-
typeof arg.name === "string") {
|
|
294
|
-
const imported = importedRefs.get(arg.name);
|
|
295
|
-
if (imported?.kind === "id") {
|
|
296
|
-
id = imported.id;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
if (pluginId && id) {
|
|
300
|
-
integrations.push({ key, pluginId, id });
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
unresolvedKeys.push(key);
|
|
304
|
-
}
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
if (isNode(property.value) &&
|
|
308
|
-
property.value.type === "Identifier" &&
|
|
309
|
-
typeof property.value.name === "string") {
|
|
310
|
-
const resolved = variableRefs.get(property.value.name);
|
|
311
|
-
if (resolved) {
|
|
312
|
-
integrations.push({ key, ...resolved });
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
315
|
-
const imported = importedRefs.get(property.value.name);
|
|
316
|
-
if (imported?.kind === "declaration") {
|
|
317
|
-
integrations.push({
|
|
318
|
-
key,
|
|
319
|
-
pluginId: imported.pluginId,
|
|
320
|
-
id: imported.id,
|
|
321
|
-
});
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
unresolvedKeys.push(key);
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
unresolvedKeys.push(key);
|
|
143
|
+
function unresolvedKeyOf(member) {
|
|
144
|
+
if (member.type !== "ObjectProperty") {
|
|
145
|
+
return "(dynamic)";
|
|
328
146
|
}
|
|
329
|
-
return
|
|
147
|
+
return getMemberKeyName(member) ?? "(unknown)";
|
|
330
148
|
}
|
|
331
149
|
/**
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
* Top-level variable references:
|
|
341
|
-
* `const DB = postgres("uuid"); integrations: { db: DB }`
|
|
342
|
-
*
|
|
343
|
-
* And string variable indirection:
|
|
344
|
-
* `const ID = "uuid"; integrations: { db: postgres(ID) }`
|
|
345
|
-
*
|
|
346
|
-
* Also resolves top-level `export const` declarations and `as const`
|
|
347
|
-
* literals in the same file (e.g. `export const ID = "uuid" as const;`) —
|
|
348
|
-
* a deliberate, additive improvement over the previous bare-declaration-only
|
|
349
|
-
* behavior. This is still single-file scope: only same-file declarations
|
|
350
|
-
* (exported or not) are considered, imports are never followed.
|
|
351
|
-
*
|
|
352
|
-
* Single-file only: does not follow imports, so an integration declared via
|
|
353
|
-
* an imported constant or an imported `integrations` object cannot be
|
|
354
|
-
* resolved here — it is silently dropped (its key is simply absent from the
|
|
355
|
-
* returned array, with no signal that it was seen but unresolved). Callers
|
|
356
|
-
* that need imported declarations resolved, or that need to know about
|
|
357
|
-
* unresolved keys instead of silently losing them, must use
|
|
358
|
-
* {@link extractApiIntegrations} instead.
|
|
150
|
+
* Extracts the integrations a file's default `api()` export declares from the
|
|
151
|
+
* file alone. A `let` or `var` reads as its initializer, since callers use
|
|
152
|
+
* the result to list every integration an API may touch, such as the
|
|
153
|
+
* migration write policy, which must not drop one. A declaration whose ID
|
|
154
|
+
* comes from an import is left out without a trace;
|
|
155
|
+
* {@link extractApiIntegrations} follows imports and reports the keys it
|
|
156
|
+
* cannot resolve.
|
|
359
157
|
*/
|
|
360
158
|
export function extractIntegrationsFromSource(source) {
|
|
361
|
-
let
|
|
159
|
+
let body;
|
|
362
160
|
try {
|
|
363
|
-
|
|
364
|
-
sourceType: "module",
|
|
365
|
-
plugins: ["typescript"],
|
|
366
|
-
});
|
|
161
|
+
body = parseProgramBody(source, "");
|
|
367
162
|
}
|
|
368
163
|
catch {
|
|
369
164
|
return [];
|
|
370
165
|
}
|
|
371
|
-
|
|
166
|
+
const module = new SourceModule("", body);
|
|
167
|
+
return new ApiModule(module, new ModuleScope(module, new Map(), "any")).integrationsOf("default").integrations;
|
|
372
168
|
}
|
|
373
|
-
/**
|
|
374
|
-
* Single-file only: does not follow imports, so an integration declared via
|
|
375
|
-
* an imported constant or an imported `integrations` object cannot be
|
|
376
|
-
* resolved here — it is silently dropped (its `id` is simply absent from the
|
|
377
|
-
* returned array, with no signal that it was seen but unresolved). Callers
|
|
378
|
-
* that need imported declarations resolved, or that need to know about
|
|
379
|
-
* unresolved keys instead of silently losing them, must use
|
|
380
|
-
* {@link extractApiIntegrations} instead.
|
|
381
|
-
*/
|
|
169
|
+
/** The IDs {@link extractIntegrationsFromSource} finds, in declaration order. */
|
|
382
170
|
export function extractIntegrationIdsFromSource(source) {
|
|
383
171
|
return extractIntegrationsFromSource(source).map((integration) => integration.id);
|
|
384
172
|
}
|
|
385
173
|
/**
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* `{ key, pluginId, id }` triple.
|
|
174
|
+
* Extracts the integrations an SDK API module's `api()` export declares,
|
|
175
|
+
* following relative imports, and reports the `integrations` keys it could
|
|
176
|
+
* not resolve.
|
|
390
177
|
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
* (including `as const`/type-assertion wrapping and re-exports via
|
|
395
|
-
* `export { name }` specifiers).
|
|
396
|
-
* 2. Imported integration declarations: `export const jira = restApiIntegration("jira-uuid")`
|
|
397
|
-
* including string-literal indirection within the imported module, and
|
|
398
|
-
* the same `export { name }` specifier form.
|
|
178
|
+
* `exportName` selects the default export when omitted or `"default"`,
|
|
179
|
+
* otherwise a named one: `export const <name> = api({...})`,
|
|
180
|
+
* `export const <name> = someApi`, or `export { someApi as <name> }`.
|
|
399
181
|
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
182
|
+
* A declaration resolves when its ID is a string literal, or a binding,
|
|
183
|
+
* alias, or integration declaration that leads to one, in the entry file or
|
|
184
|
+
* in a module it reaches within {@link MAX_IMPORT_HOPS} imports or
|
|
185
|
+
* re-exports. Package imports, type-only imports and exports, `declare`
|
|
186
|
+
* bindings, and imports that more than one candidate file could satisfy are
|
|
187
|
+
* not followed. `bindings` defaults to `"any"`; a caller that skips an
|
|
188
|
+
* approval based on the result passes `"const-only"`.
|
|
404
189
|
*
|
|
405
|
-
* `
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* `
|
|
409
|
-
*
|
|
410
|
-
* `
|
|
411
|
-
* `server/apis/get-rows.ts`), never an absolute path or one containing a
|
|
412
|
-
* backslash — an entry point that violates this contract skips import
|
|
413
|
-
* resolution entirely (see the guard at the top of
|
|
414
|
-
* `buildImportedIntegrationRefs`). Within that contract, resolved relative
|
|
415
|
-
* import candidates that would escape the app root (e.g. `../../../secrets.ts`)
|
|
416
|
-
* are skipped without reading them, but that `..`-prefix skip is only a
|
|
417
|
-
* best-effort guard against traversal *relative to entryPoint's own
|
|
418
|
-
* directory* — it is not a substitute for real containment enforcement.
|
|
419
|
-
* Authoritative containment against the actual filesystem root lives in the
|
|
420
|
-
* caller's `readSource` implementation (see `resolveContainedPath` in
|
|
421
|
-
* `collect-sdk-apis.mts`), which re-resolves every candidate against the app
|
|
422
|
-
* root before touching disk.
|
|
190
|
+
* `entryPoint` must be an app-root-relative posix path such as
|
|
191
|
+
* `server/apis/get-rows.ts`; imports of an absolute or backslashed one are
|
|
192
|
+
* not followed. Candidates above the app root are skipped without being
|
|
193
|
+
* read, but containment is enforced by `readSource`, as
|
|
194
|
+
* `createContainedSourceReader` does for testApi and
|
|
195
|
+
* `resolveContainedRealPath` does for the CLI build manifest.
|
|
423
196
|
*
|
|
424
197
|
* `unresolvedKeys` entries are one of:
|
|
425
|
-
* -
|
|
426
|
-
* - `"(unknown)"` for
|
|
427
|
-
*
|
|
428
|
-
* - `"
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* failing to parse. `integrations` then lists only the declarations that
|
|
436
|
-
* could be read.
|
|
198
|
+
* - an `integrations` key whose declaration could not be resolved
|
|
199
|
+
* - `"(unknown)"` for a declaration whose key is not static
|
|
200
|
+
* - `"(dynamic)"` for a spread or method inside `integrations`
|
|
201
|
+
* - `"*"` when the export may declare integrations other than the ones read:
|
|
202
|
+
* the entry file has no local export by that name, which includes one it
|
|
203
|
+
* re-exports from another module, its value is not an `api({...})` call,
|
|
204
|
+
* its config has a spread, a computed key, an `integrations` accessor or
|
|
205
|
+
* method, a second or non-literal `integrations` property, or the entry
|
|
206
|
+
* file does not parse. `integrations` then lists only the declarations
|
|
207
|
+
* that could be read.
|
|
437
208
|
*/
|
|
438
209
|
export async function extractApiIntegrations(params) {
|
|
439
|
-
let
|
|
210
|
+
let body;
|
|
440
211
|
try {
|
|
441
|
-
|
|
442
|
-
sourceType: "module",
|
|
443
|
-
plugins: ["typescript"],
|
|
444
|
-
});
|
|
212
|
+
body = parseProgramBody(params.source, params.entryPoint);
|
|
445
213
|
}
|
|
446
214
|
catch {
|
|
447
|
-
// The entry file itself failed to parse (e.g. parser-config drift: a
|
|
448
|
-
// real build compiles syntax our @babel/parser config rejects, such as
|
|
449
|
-
// decorators or import attributes). Report the "*" sentinel instead of
|
|
450
|
-
// silently returning an empty result — this is maximal uncertainty
|
|
451
|
-
// about the whole integrations surface, exactly what "*" means below.
|
|
452
215
|
return { integrations: [], unresolvedKeys: ["*"] };
|
|
453
216
|
}
|
|
454
|
-
const
|
|
455
|
-
const
|
|
456
|
-
|
|
217
|
+
const exportName = params.exportName ?? "default";
|
|
218
|
+
const entry = new SourceModule(params.entryPoint, body);
|
|
219
|
+
const scope = await new ImportedIntegrationResolver(params.readSource, params.bindings ?? "any").entryScope(entry, (probe) => new ApiModule(entry, probe).integrationsOf(exportName));
|
|
220
|
+
return new ApiModule(entry, scope).integrationsOf(exportName);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Parses a module as TypeScript, and as JSX too when its path is a `.tsx` or
|
|
224
|
+
* `.jsx` file. A `.ts` file cannot also be read as JSX, since `<T>value` is a
|
|
225
|
+
* type assertion there.
|
|
226
|
+
*/
|
|
227
|
+
function parseProgramBody(source, path) {
|
|
228
|
+
const plugins = JSX_EXTENSIONS.includes(posixPath.extname(path))
|
|
229
|
+
? ["typescript", "jsx"]
|
|
230
|
+
: ["typescript"];
|
|
231
|
+
return parse(source, { sourceType: "module", plugins }).program.body;
|
|
457
232
|
}
|
|
233
|
+
const JSX_EXTENSIONS = [".tsx", ".jsx"];
|
|
458
234
|
const TS_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts"];
|
|
459
235
|
const SCRIPT_EXTENSIONS = [...TS_EXTENSIONS, ".js", ".jsx", ".mjs", ".cjs"];
|
|
460
236
|
const JS_TO_TS_EXTENSIONS = {
|
|
@@ -481,185 +257,448 @@ export function resolveRelativeImportPath(fromPath, importPath) {
|
|
|
481
257
|
}
|
|
482
258
|
return SCRIPT_EXTENSIONS.map((ext) => resolved + ext);
|
|
483
259
|
}
|
|
484
|
-
/**
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
260
|
+
/**
|
|
261
|
+
* One parsed module, addressed by its app-root-relative posix path, and the
|
|
262
|
+
* statements that matter for resolving integrations. Type-only and `declare`
|
|
263
|
+
* statements have no runtime value, so only `explicitExportNames` sees them.
|
|
264
|
+
*/
|
|
265
|
+
class SourceModule {
|
|
266
|
+
path;
|
|
267
|
+
body;
|
|
268
|
+
constructor(path, body) {
|
|
269
|
+
this.path = path;
|
|
270
|
+
this.body = body;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The app-root-relative paths an import or re-export source of this module
|
|
274
|
+
* may name, or none when it must not be followed: package imports, and any
|
|
275
|
+
* specifier containing a backslash, which `posixPath.join` would treat as
|
|
276
|
+
* a filename character so the `..`-prefix skip could not catch a traversal
|
|
277
|
+
* spelled with it. Candidates above the app root are dropped unread.
|
|
278
|
+
*/
|
|
279
|
+
candidatePathsFor(sourceNode) {
|
|
280
|
+
const specifier = isNode(sourceNode) ? sourceNode.value : undefined;
|
|
281
|
+
if (typeof specifier !== "string" ||
|
|
282
|
+
!specifier.startsWith(".") ||
|
|
283
|
+
specifier.includes("\\")) {
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
return resolveRelativeImportPath(this.path, specifier).filter((candidate) => !candidate.startsWith(".."));
|
|
287
|
+
}
|
|
288
|
+
variableDeclarators() {
|
|
289
|
+
return this.statements().flatMap(variableDeclaratorsOf);
|
|
290
|
+
}
|
|
291
|
+
/** `import { a, b as c } from "..."` statements. */
|
|
292
|
+
namedImports() {
|
|
293
|
+
return this.references("ImportDeclaration", "ImportSpecifier");
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The source and source-side name of an `export { a as name } from "..."`
|
|
297
|
+
* that exports `name`.
|
|
298
|
+
*/
|
|
299
|
+
namedReExportOf(name) {
|
|
300
|
+
for (const { source, specifiers } of this.references("ExportNamedDeclaration", "ExportSpecifier")) {
|
|
301
|
+
for (const specifier of specifiers) {
|
|
302
|
+
const localName = getPropertyName(specifier.local);
|
|
303
|
+
if (localName && getPropertyName(specifier.exported) === name) {
|
|
304
|
+
return { source, localName };
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return undefined;
|
|
489
309
|
}
|
|
490
|
-
|
|
491
|
-
|
|
310
|
+
/** The sources of `export * from "..."` statements. */
|
|
311
|
+
starReExportSources() {
|
|
312
|
+
return this.statementsOfType("ExportAllDeclaration")
|
|
313
|
+
.filter((statement) => !isTypeOnly(statement))
|
|
314
|
+
.map((statement) => statement.source);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* The expression behind each value the module exports from its own scope:
|
|
318
|
+
* `export default <expr>`, the binding of `export const <name>`, and the
|
|
319
|
+
* local of `export { <local> as <name> }`.
|
|
320
|
+
*/
|
|
321
|
+
localExports() {
|
|
322
|
+
const exports = new Map();
|
|
323
|
+
for (const statement of this.statementsOfType("ExportDefaultDeclaration")) {
|
|
324
|
+
if (isNode(statement.declaration)) {
|
|
325
|
+
exports.set("default", statement.declaration);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
for (const statement of this.statementsOfType("ExportNamedDeclaration")) {
|
|
329
|
+
if (isNode(statement.source)) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
for (const { declarator } of variableDeclaratorsOf(statement)) {
|
|
333
|
+
const name = getPropertyName(declarator.id);
|
|
334
|
+
if (name && isNode(declarator.id)) {
|
|
335
|
+
exports.set(name, declarator.id);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
for (const specifier of valueSpecifiersOf(statement)) {
|
|
339
|
+
const exportedName = getPropertyName(specifier.exported);
|
|
340
|
+
if (exportedName && isNode(specifier.local)) {
|
|
341
|
+
exports.set(exportedName, specifier.local);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return exports;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Every name the module exports other than through `export *`, which ESM
|
|
349
|
+
* shadows with them and which never provides `default`. Type-only and
|
|
350
|
+
* `declare` exports count: TypeScript resolves the name to them while the
|
|
351
|
+
* runtime would take a star source's value, so the name stays unresolved.
|
|
352
|
+
*/
|
|
353
|
+
explicitExportNames() {
|
|
354
|
+
const names = new Set(["default"]);
|
|
355
|
+
for (const statement of this.statementsOfType("TSImportEqualsDeclaration")) {
|
|
356
|
+
const name = statement.isExport
|
|
357
|
+
? getPropertyName(statement.id)
|
|
358
|
+
: undefined;
|
|
359
|
+
if (name) {
|
|
360
|
+
names.add(name);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
for (const statement of this.statementsOfType("ExportNamedDeclaration")) {
|
|
364
|
+
for (const name of declaredNames(statement.declaration)) {
|
|
365
|
+
names.add(name);
|
|
366
|
+
}
|
|
367
|
+
for (const specifier of specifiersOf(statement)) {
|
|
368
|
+
const exportedName = getPropertyName(specifier.exported);
|
|
369
|
+
if (exportedName) {
|
|
370
|
+
names.add(exportedName);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return names;
|
|
492
375
|
}
|
|
493
|
-
|
|
494
|
-
return
|
|
376
|
+
references(statementType, specifierType) {
|
|
377
|
+
return this.statementsOfType(statementType)
|
|
378
|
+
.filter((statement) => isNode(statement.source))
|
|
379
|
+
.map((statement) => ({
|
|
380
|
+
source: statement.source,
|
|
381
|
+
specifiers: valueSpecifiersOf(statement).filter((specifier) => specifier.type === specifierType),
|
|
382
|
+
}))
|
|
383
|
+
.filter(({ specifiers }) => specifiers.length > 0);
|
|
495
384
|
}
|
|
496
|
-
|
|
497
|
-
return
|
|
498
|
-
exists: true,
|
|
499
|
-
body: parse(source, {
|
|
500
|
-
sourceType: "module",
|
|
501
|
-
plugins: ["typescript"],
|
|
502
|
-
}).program.body,
|
|
503
|
-
};
|
|
385
|
+
statementsOfType(type) {
|
|
386
|
+
return this.statements().filter((statement) => statement.type === type);
|
|
504
387
|
}
|
|
505
|
-
|
|
506
|
-
return
|
|
388
|
+
statements() {
|
|
389
|
+
return this.body.filter(isNode);
|
|
507
390
|
}
|
|
508
391
|
}
|
|
509
392
|
/**
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
393
|
+
* What the top-level bindings of one module and the names it imports refer
|
|
394
|
+
* to: string IDs, integration declarations, aliases of either, and `api()`
|
|
395
|
+
* configs.
|
|
513
396
|
*/
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
397
|
+
class ModuleScope {
|
|
398
|
+
importedRefs;
|
|
399
|
+
initializers = new Map();
|
|
400
|
+
constructor(module, importedRefs, bindings) {
|
|
401
|
+
this.importedRefs = importedRefs;
|
|
402
|
+
for (const { kind, declarator } of module.variableDeclarators()) {
|
|
403
|
+
const name = getPropertyName(declarator.id);
|
|
404
|
+
if (name && (bindings === "any" || kind === "const")) {
|
|
405
|
+
this.initializers.set(name, declarator.init);
|
|
406
|
+
}
|
|
524
407
|
}
|
|
525
408
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
function buildExportedIntegrationRefMap(programBody, bindings) {
|
|
529
|
-
const refs = new Map();
|
|
530
|
-
const stringLiterals = buildStringLiteralMap(programBody, bindings);
|
|
531
|
-
// Resolves specifier-based exports (`const jira = ...; export { jira };`)
|
|
532
|
-
// against the module's bare top-level variable declarations.
|
|
533
|
-
const variableRefs = buildVariableReferenceMap(programBody, stringLiterals, bindings);
|
|
534
|
-
// Resolve `export const x = ...` declarations directly. Filtering to only
|
|
535
|
-
// `ExportNamedDeclaration` statements before delegating to the shared
|
|
536
|
-
// walker means bare (non-exported) top-level consts are correctly excluded
|
|
537
|
-
// here, even though they're visible for same-file indirection above.
|
|
538
|
-
const exportedDeclarationStatements = programBody.filter((statement) => isNode(statement) && statement.type === "ExportNamedDeclaration");
|
|
539
|
-
visitVariableDeclarations(exportedDeclarationStatements, bindings, (declaration) => {
|
|
540
|
-
const identifier = declaration.id;
|
|
541
|
-
if (!isNode(identifier) ||
|
|
542
|
-
identifier.type !== "Identifier" ||
|
|
543
|
-
typeof identifier.name !== "string") {
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
const literal = getLiteralString(declaration.init);
|
|
409
|
+
resolveExpression(node, followedNames = new Set()) {
|
|
410
|
+
const literal = getLiteralString(node);
|
|
547
411
|
if (literal !== undefined) {
|
|
548
|
-
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
const init = declaration.init;
|
|
552
|
-
if (isNode(init) &&
|
|
553
|
-
init.type === "CallExpression" &&
|
|
554
|
-
Array.isArray(init.arguments)) {
|
|
555
|
-
const pluginId = getCalleeName(init.callee);
|
|
556
|
-
const id = resolveStringArgument(init.arguments[0], stringLiterals);
|
|
557
|
-
if (pluginId && id) {
|
|
558
|
-
refs.set(identifier.name, { kind: "declaration", pluginId, id });
|
|
559
|
-
}
|
|
412
|
+
return { kind: "id", id: literal };
|
|
560
413
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
414
|
+
const expression = unwrapExpression(node);
|
|
415
|
+
if (expression?.type === "Identifier" &&
|
|
416
|
+
typeof expression.name === "string") {
|
|
417
|
+
return this.resolveName(expression.name, followedNames);
|
|
418
|
+
}
|
|
419
|
+
if (expression?.type === "CallExpression" &&
|
|
420
|
+
Array.isArray(expression.arguments)) {
|
|
421
|
+
const pluginId = getCalleeName(expression.callee);
|
|
422
|
+
const argument = this.resolveExpression(expression.arguments[0], followedNames);
|
|
423
|
+
return pluginId && argument?.kind === "id"
|
|
424
|
+
? { kind: "declaration", pluginId, id: argument.id }
|
|
425
|
+
: undefined;
|
|
426
|
+
}
|
|
427
|
+
return undefined;
|
|
428
|
+
}
|
|
429
|
+
resolveDeclaration(node) {
|
|
430
|
+
const ref = this.resolveExpression(node);
|
|
431
|
+
return ref?.kind === "declaration"
|
|
432
|
+
? { pluginId: ref.pluginId, id: ref.id }
|
|
433
|
+
: undefined;
|
|
434
|
+
}
|
|
435
|
+
/** The config object of the `api({...})` call an expression evaluates to. */
|
|
436
|
+
resolveApiConfig(node, followedNames = new Set()) {
|
|
437
|
+
const expression = unwrapExpression(node);
|
|
438
|
+
if (expression?.type === "Identifier" &&
|
|
439
|
+
typeof expression.name === "string") {
|
|
440
|
+
const name = expression.name;
|
|
441
|
+
if (followedNames.has(name) || !this.initializers.has(name)) {
|
|
442
|
+
return undefined;
|
|
578
443
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
444
|
+
followedNames.add(name);
|
|
445
|
+
return this.resolveApiConfig(this.initializers.get(name), followedNames);
|
|
446
|
+
}
|
|
447
|
+
if (expression?.type !== "CallExpression" ||
|
|
448
|
+
getCalleeName(expression.callee) !== "api" ||
|
|
449
|
+
!Array.isArray(expression.arguments)) {
|
|
450
|
+
return undefined;
|
|
451
|
+
}
|
|
452
|
+
const config = unwrapExpression(expression.arguments[0]);
|
|
453
|
+
return config?.type === "ObjectExpression" ? config : undefined;
|
|
454
|
+
}
|
|
455
|
+
resolveName(name, followedNames) {
|
|
456
|
+
if (!this.initializers.has(name)) {
|
|
457
|
+
return this.importedRefs.get(name);
|
|
458
|
+
}
|
|
459
|
+
if (followedNames.has(name)) {
|
|
460
|
+
return undefined;
|
|
461
|
+
}
|
|
462
|
+
followedNames.add(name);
|
|
463
|
+
return this.resolveExpression(this.initializers.get(name), followedNames);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/** An API module's `api()` export and the integrations its config declares. */
|
|
467
|
+
class ApiModule {
|
|
468
|
+
module;
|
|
469
|
+
scope;
|
|
470
|
+
constructor(module, scope) {
|
|
471
|
+
this.module = module;
|
|
472
|
+
this.scope = scope;
|
|
473
|
+
}
|
|
474
|
+
integrationsOf(exportName) {
|
|
475
|
+
const exported = this.module.localExports().get(exportName);
|
|
476
|
+
const apiConfig = exported && this.scope.resolveApiConfig(exported);
|
|
477
|
+
if (!apiConfig) {
|
|
478
|
+
return { integrations: [], unresolvedKeys: ["*"] };
|
|
479
|
+
}
|
|
480
|
+
return this.readDeclarations(apiConfig);
|
|
481
|
+
}
|
|
482
|
+
readDeclarations(apiConfig) {
|
|
483
|
+
const { objects, isDefinitive } = readIntegrationsObjects(apiConfig);
|
|
484
|
+
const integrations = [];
|
|
485
|
+
const unresolvedKeys = isDefinitive ? [] : ["*"];
|
|
486
|
+
for (const member of objects.flatMap(membersOf)) {
|
|
487
|
+
const key = member.type === "ObjectProperty" ? getMemberKeyName(member) : undefined;
|
|
488
|
+
const declaration = key === undefined
|
|
489
|
+
? undefined
|
|
490
|
+
: this.scope.resolveDeclaration(member.value);
|
|
491
|
+
if (key !== undefined && declaration) {
|
|
492
|
+
integrations.push({ key, ...declaration });
|
|
583
493
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
refs.set(exportedName, {
|
|
587
|
-
kind: "declaration",
|
|
588
|
-
pluginId: varRef.pluginId,
|
|
589
|
-
id: varRef.id,
|
|
590
|
-
});
|
|
494
|
+
else {
|
|
495
|
+
unresolvedKeys.push(unresolvedKeyOf(member));
|
|
591
496
|
}
|
|
592
497
|
}
|
|
498
|
+
return { integrations, unresolvedKeys };
|
|
593
499
|
}
|
|
594
|
-
return refs;
|
|
595
500
|
}
|
|
596
|
-
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
501
|
+
function isSameRef(left, right) {
|
|
502
|
+
const pluginIdOf = (ref) => ref.kind === "declaration" ? ref.pluginId : undefined;
|
|
503
|
+
return (left.kind === right.kind &&
|
|
504
|
+
left.id === right.id &&
|
|
505
|
+
pluginIdOf(left) === pluginIdOf(right));
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* The most modules an imported name is followed through, counting the module
|
|
509
|
+
* the entry point imports it from as the first.
|
|
510
|
+
*/
|
|
511
|
+
const MAX_IMPORT_HOPS = 5;
|
|
512
|
+
/**
|
|
513
|
+
* The most candidate files one call reads, so an app whose modules import
|
|
514
|
+
* widely cannot make one lookup read it whole. Every candidate of an import
|
|
515
|
+
* counts, whether or not it exists. An import that needs more is left
|
|
516
|
+
* unresolved.
|
|
517
|
+
*/
|
|
518
|
+
export const MAX_SOURCE_READS = 256;
|
|
519
|
+
/**
|
|
520
|
+
* Resolves the names an API entry point imports, following relative imports
|
|
521
|
+
* and re-exports through at most {@link MAX_IMPORT_HOPS} modules. It follows
|
|
522
|
+
* only the names a lookup reaches: one export of a module at a time, and of
|
|
523
|
+
* that export only the imports its value refers to. One instance serves one
|
|
524
|
+
* entry point: it reads and parses each file at most once, and cuts an
|
|
525
|
+
* import cycle where it closes, leaving the names that depend on the cycle
|
|
526
|
+
* unresolved.
|
|
527
|
+
*/
|
|
528
|
+
class ImportedIntegrationResolver {
|
|
529
|
+
readSource;
|
|
530
|
+
bindings;
|
|
531
|
+
files = new Map();
|
|
532
|
+
exportRefs = new Map();
|
|
533
|
+
exportsInProgress = new Set();
|
|
534
|
+
sourceReadsLeft = MAX_SOURCE_READS;
|
|
535
|
+
constructor(readSource, bindings) {
|
|
536
|
+
this.readSource = readSource;
|
|
537
|
+
this.bindings = bindings;
|
|
538
|
+
}
|
|
539
|
+
/** A scope of the entry point with the imports `use` looks up resolved. */
|
|
540
|
+
async entryScope(entry, use) {
|
|
541
|
+
// The `..`-prefix skip only guards against traversal relative to the
|
|
542
|
+
// entry point's own directory, so an absolute or backslashed entry point
|
|
543
|
+
// could still resolve candidates outside the app root.
|
|
544
|
+
if (entry.path.startsWith("/") || entry.path.includes("\\")) {
|
|
545
|
+
return new ModuleScope(entry, new Map(), this.bindings);
|
|
546
|
+
}
|
|
547
|
+
this.files.set(entry.path, { exists: true, module: entry });
|
|
548
|
+
return this.scopeFor(entry, 1, use);
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Run `use` once with no imports to find which imported names it reads,
|
|
552
|
+
* then resolve only those. An imported name resolves to an ID or a
|
|
553
|
+
* declaration, never to another name, so the second run reads the same
|
|
554
|
+
* names.
|
|
555
|
+
*/
|
|
556
|
+
async scopeFor(module, hop, use) {
|
|
557
|
+
const lookedUp = new Set();
|
|
558
|
+
use(new ModuleScope(module, {
|
|
559
|
+
get: (name) => {
|
|
560
|
+
lookedUp.add(name);
|
|
561
|
+
return undefined;
|
|
562
|
+
},
|
|
563
|
+
}, this.bindings));
|
|
564
|
+
return new ModuleScope(module, await this.resolveImports(module, lookedUp, hop), this.bindings);
|
|
565
|
+
}
|
|
566
|
+
async resolveImports(importer, localNames, hop) {
|
|
567
|
+
const refs = new Map();
|
|
568
|
+
for (const { source, specifiers } of importer.namedImports()) {
|
|
569
|
+
for (const specifier of specifiers) {
|
|
570
|
+
const importedName = getPropertyName(specifier.imported);
|
|
571
|
+
const localName = getPropertyName(specifier.local);
|
|
572
|
+
if (!importedName || !localName || !localNames.has(localName)) {
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
const ref = await this.exportOfImport(importer, source, importedName, hop);
|
|
576
|
+
if (ref && ref.kind !== "unresolved") {
|
|
577
|
+
refs.set(localName, ref);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
608
581
|
return refs;
|
|
609
582
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
const
|
|
623
|
-
if (
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
// `..\\..\\..\\secret.js`). `posixPath.join` treats `\` as an ordinary
|
|
632
|
-
// filename character rather than a separator, so the `..`-prefix guard
|
|
633
|
-
// below cannot catch a traversal spelled with backslashes. Treat the
|
|
634
|
-
// specifier as unresolvable, the same as a bare package import, and
|
|
635
|
-
// never attempt to read it.
|
|
636
|
-
if (importPath.includes("\\")) {
|
|
637
|
-
continue;
|
|
638
|
-
}
|
|
639
|
-
// Skip candidates that resolve outside the app root (e.g.
|
|
640
|
-
// `../../../secrets.ts` escaping above the entry point's directory) —
|
|
641
|
-
// never read files outside the app being built.
|
|
642
|
-
const candidatePaths = resolveRelativeImportPath(entryPoint, importPath).filter((candidate) => !candidate.startsWith(".."));
|
|
643
|
-
if (candidatePaths.length === 0) {
|
|
644
|
-
continue;
|
|
645
|
-
}
|
|
646
|
-
const importedBody = await readUnambiguous(candidatePaths, readSource, candidateFiles);
|
|
647
|
-
if (!importedBody) {
|
|
648
|
-
continue;
|
|
649
|
-
}
|
|
650
|
-
const exportedRefs = buildExportedIntegrationRefMap(importedBody, bindings);
|
|
651
|
-
for (const specifier of specifiers) {
|
|
652
|
-
if (specifier.type !== "ImportSpecifier") {
|
|
653
|
-
continue;
|
|
583
|
+
async exportOfImport(importer, sourceNode, name, hop) {
|
|
584
|
+
if (hop > MAX_IMPORT_HOPS) {
|
|
585
|
+
return UNRESOLVED_EXPORT;
|
|
586
|
+
}
|
|
587
|
+
const imported = await this.readUnambiguous(importer.candidatePathsFor(sourceNode));
|
|
588
|
+
return imported ? this.exportOf(imported, name, hop) : UNRESOLVED_EXPORT;
|
|
589
|
+
}
|
|
590
|
+
async exportOf(module, name, hop) {
|
|
591
|
+
const exportKey = JSON.stringify([module.path, name]);
|
|
592
|
+
if (this.exportsInProgress.has(exportKey)) {
|
|
593
|
+
return UNRESOLVED_EXPORT;
|
|
594
|
+
}
|
|
595
|
+
const cacheKey = JSON.stringify([hop, module.path, name]);
|
|
596
|
+
if (this.exportRefs.has(cacheKey)) {
|
|
597
|
+
return this.exportRefs.get(cacheKey);
|
|
598
|
+
}
|
|
599
|
+
this.exportsInProgress.add(exportKey);
|
|
600
|
+
try {
|
|
601
|
+
const ref = await this.resolveExport(module, name, hop);
|
|
602
|
+
if (ref?.kind !== "unresolved") {
|
|
603
|
+
this.exportRefs.set(cacheKey, ref);
|
|
654
604
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
605
|
+
return ref;
|
|
606
|
+
}
|
|
607
|
+
finally {
|
|
608
|
+
this.exportsInProgress.delete(exportKey);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* What `module` exports as `name`. A name the module exports explicitly,
|
|
613
|
+
* even as a type, a `declare`, or a namespace, shadows `export *`.
|
|
614
|
+
*/
|
|
615
|
+
async resolveExport(module, name, hop) {
|
|
616
|
+
const local = module.localExports().get(name);
|
|
617
|
+
if (local) {
|
|
618
|
+
const scope = await this.scopeFor(module, hop + 1, (probe) => probe.resolveExpression(local));
|
|
619
|
+
return scope.resolveExpression(local) ?? UNRESOLVED_EXPORT;
|
|
620
|
+
}
|
|
621
|
+
const reExport = module.namedReExportOf(name);
|
|
622
|
+
if (reExport) {
|
|
623
|
+
return ((await this.exportOfImport(module, reExport.source, reExport.localName, hop + 1)) ?? UNRESOLVED_EXPORT);
|
|
624
|
+
}
|
|
625
|
+
return module.explicitExportNames().has(name)
|
|
626
|
+
? UNRESOLVED_EXPORT
|
|
627
|
+
: this.starExportOf(module, name, hop);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* What the `export *` sources of `module` provide as `name`, when they
|
|
631
|
+
* agree. A name two sources disagree on is ambiguous in ESM.
|
|
632
|
+
*/
|
|
633
|
+
async starExportOf(module, name, hop) {
|
|
634
|
+
const refs = [];
|
|
635
|
+
for (const sourceNode of module.starReExportSources()) {
|
|
636
|
+
const ref = await this.exportOfImport(module, sourceNode, name, hop + 1);
|
|
637
|
+
if (ref?.kind === "unresolved") {
|
|
638
|
+
return UNRESOLVED_EXPORT;
|
|
639
|
+
}
|
|
640
|
+
if (ref) {
|
|
641
|
+
refs.push(ref);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
const [first] = refs;
|
|
645
|
+
if (first && refs.some((ref) => !isSameRef(ref, first))) {
|
|
646
|
+
return UNRESOLVED_EXPORT;
|
|
647
|
+
}
|
|
648
|
+
return first;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* The module a specifier loads when exactly one of its candidate files
|
|
652
|
+
* exists. With more than one, which the bundler loads depends on its
|
|
653
|
+
* resolution order, so the import is left unresolved.
|
|
654
|
+
*/
|
|
655
|
+
async readUnambiguous(candidatePaths) {
|
|
656
|
+
const existing = [];
|
|
657
|
+
for (const path of candidatePaths) {
|
|
658
|
+
const file = await this.read(path);
|
|
659
|
+
if (file.exists) {
|
|
660
|
+
existing.push(file);
|
|
660
661
|
}
|
|
661
662
|
}
|
|
663
|
+
return existing.length === 1 ? existing[0]?.module : undefined;
|
|
664
|
+
}
|
|
665
|
+
async read(path) {
|
|
666
|
+
const cached = this.files.get(path);
|
|
667
|
+
if (cached) {
|
|
668
|
+
return cached;
|
|
669
|
+
}
|
|
670
|
+
const file = await this.readAndParse(path);
|
|
671
|
+
this.files.set(path, file);
|
|
672
|
+
return file;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* A file whose read throws counts as existing, since the bundler may load
|
|
676
|
+
* it, and so does one past {@link MAX_SOURCE_READS}, which is not read.
|
|
677
|
+
*/
|
|
678
|
+
async readAndParse(path) {
|
|
679
|
+
if (this.sourceReadsLeft === 0) {
|
|
680
|
+
return { exists: true };
|
|
681
|
+
}
|
|
682
|
+
this.sourceReadsLeft -= 1;
|
|
683
|
+
let source;
|
|
684
|
+
try {
|
|
685
|
+
source = await this.readSource(path);
|
|
686
|
+
}
|
|
687
|
+
catch {
|
|
688
|
+
return { exists: true };
|
|
689
|
+
}
|
|
690
|
+
if (source === undefined) {
|
|
691
|
+
return { exists: false };
|
|
692
|
+
}
|
|
693
|
+
try {
|
|
694
|
+
return {
|
|
695
|
+
exists: true,
|
|
696
|
+
module: new SourceModule(path, parseProgramBody(source, path)),
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
catch {
|
|
700
|
+
return { exists: true };
|
|
701
|
+
}
|
|
662
702
|
}
|
|
663
|
-
return refs;
|
|
664
703
|
}
|
|
665
704
|
//# sourceMappingURL=extract-api-integrations.js.map
|