@patodo/localapp 0.1.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/.localapp-artifact.json +2731 -0
- package/LICENSE +21 -0
- package/README.md +288 -0
- package/bin/localapp.mjs +34182 -0
- package/package.json +21 -0
- package/runtime/bootstrap/localapp-daemon-bootstrap.mjs +150 -0
- package/runtime/native/adapter-manifest.json +85 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Info.plist +21 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Info.plist +21 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
- package/runtime/native/linux-x64/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/linux-x64/localapp-notifications +0 -0
- package/runtime/native/win32-x64/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/win32-x64/localapp-native.exe +0 -0
- package/runtime/server/.localapp-server-runtime.json +133 -0
- package/runtime/server/bin/server-cli.cjs +8343 -0
- package/runtime/server/bin/server.mjs +8 -0
- package/runtime/server/bin/worker.cjs +144339 -0
- package/runtime/server/node_modules/sql.js/dist/sql-wasm.js +185 -0
- package/runtime/server/node_modules/sql.js/dist/sql-wasm.wasm +0 -0
- package/runtime/server/node_modules/sql.js/package.json +58 -0
- package/runtime/server/package.json +11 -0
- package/runtime/server/runner/localapp-runner.mjs +324 -0
- package/runtime/server/web/404.html +1 -0
- package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_buildManifest.js +1 -0
- package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_ssgManifest.js +1 -0
- package/runtime/server/web/_next/static/chunks/184-184da63eba05808f.js +1 -0
- package/runtime/server/web/_next/static/chunks/265-a58973dbf631dc41.js +1 -0
- package/runtime/server/web/_next/static/chunks/308-d74213c6f5179bf0.js +1 -0
- package/runtime/server/web/_next/static/chunks/416-53d48ad9442eb7b2.js +1 -0
- package/runtime/server/web/_next/static/chunks/448-280e06e915001cb5.js +1 -0
- package/runtime/server/web/_next/static/chunks/66-6f6658280a10fbca.js +1 -0
- package/runtime/server/web/_next/static/chunks/740d80ee-6c0a9504f1fd46f8.js +1 -0
- package/runtime/server/web/_next/static/chunks/86-7105ac54171494a1.js +1 -0
- package/runtime/server/web/_next/static/chunks/900-743e38de13217291.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/inbox/page-32b885c019043e48.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/layout-4b3a212263712a5c.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/analytics/page-6af9adc14ccfa925.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/[name]/settings/page-8b6f809eeccdbd22.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/page-7f1ddf07889da248.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/dashboard/page-a25eb621fb18491d.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-actions/page-e6045823829567f7.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-notifications/page-377ed49cf55da81d.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/favorites/page-82f292daebf98a2f.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/groups/page-fe4ed80c7b11920f.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/info/page-d5d5075eec069ce3.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/keys/page-35ed01bf39a163b6.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/layout-5481d53aae3a0ce1.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/orgs/page-44c606ff2233f1a8.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/page-f2331bbbe09541aa.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/pages/page-6bf4e160a99411ce.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/peers/page-27041dd149601002.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/recent/page-f321688d374a8ff3.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/settings/page-64e724318dc3a584.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/studio/page-a2c0c34538ac62b3.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/subscriptions/page-57cdaafe12347e32.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/system/page-96d2e1f8c2fb22b0.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/tasks/page-bf16b78ed6749d78.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/users/page-c47d4524d2a156b8.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/page-f4641be7b88818a2.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/_not-found/page-f4902e6b69eebd4c.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/layout-5557bc90d966fded.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/platform-shell/[userId]/[name]/page-da0d5e71857f33d1.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/platform-shell-preview/page-52fa7e8c8b480934.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/setup/page-9e29d6f66825a8f8.js +1 -0
- package/runtime/server/web/_next/static/chunks/framework-1c02a2e60068b586.js +1 -0
- package/runtime/server/web/_next/static/chunks/main-21ea4d4d10f4a256.js +1 -0
- package/runtime/server/web/_next/static/chunks/main-app-5b3c67453d8c5b99.js +1 -0
- package/runtime/server/web/_next/static/chunks/pages/_app-649f81c9fedecf29.js +1 -0
- package/runtime/server/web/_next/static/chunks/pages/_error-64e3bd84e2ecae08.js +1 -0
- package/runtime/server/web/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/runtime/server/web/_next/static/chunks/webpack-0bed2fdf6baa566e.js +1 -0
- package/runtime/server/web/_next/static/css/afdc0938fca59693.css +3 -0
- package/runtime/server/web/_next/static/media/013b72fa676f92e0-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/22a5144ee8d83bca-s.p.woff2 +0 -0
- package/runtime/server/web/_next/static/media/2b5b02fc7e511755-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/65f03d54ccadf4a8-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/7d4881bb7e1bf84d-s.p.woff2 +0 -0
- package/runtime/server/web/_next/static/media/9766a7e9e2e0ad5a-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/aa016aab0e6d1295-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/b66cf8e69499582a-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/b9408752a0c24fb9-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/e038a29029a234f2-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/f639721981034f88-s.woff2 +0 -0
- package/runtime/server/web/home/redline-launch-hero.png +0 -0
- package/runtime/server/web/inbox.html +1 -0
- package/runtime/server/web/inbox.txt +27 -0
- package/runtime/server/web/index.html +1 -0
- package/runtime/server/web/index.txt +27 -0
- package/runtime/server/web/my/analytics.html +1 -0
- package/runtime/server/web/my/analytics.txt +27 -0
- package/runtime/server/web/my/apps/placeholder/settings.html +1 -0
- package/runtime/server/web/my/apps/placeholder/settings.txt +24 -0
- package/runtime/server/web/my/apps.html +1 -0
- package/runtime/server/web/my/apps.txt +27 -0
- package/runtime/server/web/my/dashboard.html +1 -0
- package/runtime/server/web/my/dashboard.txt +27 -0
- package/runtime/server/web/my/device-actions.html +1 -0
- package/runtime/server/web/my/device-actions.txt +24 -0
- package/runtime/server/web/my/device-notifications.html +1 -0
- package/runtime/server/web/my/device-notifications.txt +24 -0
- package/runtime/server/web/my/favorites.html +1 -0
- package/runtime/server/web/my/favorites.txt +27 -0
- package/runtime/server/web/my/groups.html +1 -0
- package/runtime/server/web/my/groups.txt +27 -0
- package/runtime/server/web/my/info.html +1 -0
- package/runtime/server/web/my/info.txt +27 -0
- package/runtime/server/web/my/keys.html +1 -0
- package/runtime/server/web/my/keys.txt +27 -0
- package/runtime/server/web/my/orgs.html +1 -0
- package/runtime/server/web/my/orgs.txt +27 -0
- package/runtime/server/web/my/pages.html +1 -0
- package/runtime/server/web/my/pages.txt +27 -0
- package/runtime/server/web/my/peers.html +1 -0
- package/runtime/server/web/my/peers.txt +24 -0
- package/runtime/server/web/my/recent.html +1 -0
- package/runtime/server/web/my/recent.txt +27 -0
- package/runtime/server/web/my/settings.html +1 -0
- package/runtime/server/web/my/settings.txt +27 -0
- package/runtime/server/web/my/studio.html +1 -0
- package/runtime/server/web/my/studio.txt +24 -0
- package/runtime/server/web/my/subscriptions.html +1 -0
- package/runtime/server/web/my/subscriptions.txt +27 -0
- package/runtime/server/web/my/system.html +1 -0
- package/runtime/server/web/my/system.txt +24 -0
- package/runtime/server/web/my/tasks.html +1 -0
- package/runtime/server/web/my/tasks.txt +24 -0
- package/runtime/server/web/my/users.html +1 -0
- package/runtime/server/web/my/users.txt +27 -0
- package/runtime/server/web/my.html +1 -0
- package/runtime/server/web/my.txt +27 -0
- package/runtime/server/web/platform-shell/placeholder/placeholder.html +1 -0
- package/runtime/server/web/platform-shell/placeholder/placeholder.txt +23 -0
- package/runtime/server/web/platform-shell-preview.html +1 -0
- package/runtime/server/web/platform-shell-preview.txt +23 -0
- package/runtime/server/web/setup.html +1 -0
- package/runtime/server/web/setup.txt +23 -0
- package/template/.claude/skills/agent-tool-patterns/SKILL.md +195 -0
- package/template/.claude/skills/localapp/SKILL.md +80 -0
- package/template/.claude/skills/localapp-auth/SKILL.md +299 -0
- package/template/.claude/skills/localapp-business/SKILL.md +325 -0
- package/template/.claude/skills/localapp-data/SKILL.md +381 -0
- package/template/.claude/skills/localapp-device-actions/SKILL.md +60 -0
- package/template/.claude/skills/localapp-notify/SKILL.md +118 -0
- package/template/.claude/skills/localapp-transitions/SKILL.md +238 -0
- package/template/.claude/skills/localapp-ui/SKILL.md +67 -0
- package/template/.claude/skills/localapp-upload/SKILL.md +172 -0
- package/template/AGENTS.md +33 -0
- package/template/CLAUDE.md +117 -0
- package/template/ISSUES.md +32 -0
- package/template/backend/resources/work_items/mutations.json +83 -0
- package/template/backend/resources/work_items/queries.json +83 -0
- package/template/backend/resources/work_items/schema.json +31 -0
- package/template/backend/schemas/mutations.schema.json +15 -0
- package/template/backend/schemas/queries.schema.json +36 -0
- package/template/backend/schemas/resource-schema.schema.json +25 -0
- package/template/components.json +25 -0
- package/template/index.html +12 -0
- package/template/migrations/001_work_items.sql +6 -0
- package/template/package.json +70 -0
- package/template/postcss.config.js +5 -0
- package/template/runtime/dev-shell.tsx +6398 -0
- package/template/runtime/hooks/use-mobile.ts +19 -0
- package/template/runtime/issue-reference.ts +44 -0
- package/template/runtime/lib/utils.ts +6 -0
- package/template/runtime/package.json +14 -0
- package/template/runtime/platform-capabilities.json +109 -0
- package/template/runtime/sdk/agent/package.json +51 -0
- package/template/runtime/sdk/agent/src/agent-chat.tsx +188 -0
- package/template/runtime/sdk/agent/src/assistant-ui-adapter.ts +87 -0
- package/template/runtime/sdk/agent/src/context.ts +56 -0
- package/template/runtime/sdk/agent/src/dev-bridge.ts +21 -0
- package/template/runtime/sdk/agent/src/index.ts +19 -0
- package/template/runtime/sdk/agent/src/llm-adapter.ts +263 -0
- package/template/runtime/sdk/agent/src/native-registry.ts +61 -0
- package/template/runtime/sdk/agent/src/platform-runtime.ts +164 -0
- package/template/runtime/sdk/agent/src/postmessage-bridge.ts +60 -0
- package/template/runtime/sdk/agent/src/postmessage-types.ts +150 -0
- package/template/runtime/sdk/agent/src/tools.ts +70 -0
- package/template/runtime/sdk/agent/src/types.ts +27 -0
- package/template/runtime/sdk/agent/src/use-agent.ts +139 -0
- package/template/runtime/sdk/agent/src/use-register-edit-session.ts +54 -0
- package/template/runtime/sdk/agent/src/use-register-tools.ts +92 -0
- package/template/runtime/sdk/agent/tests/platform-runtime.test.ts +154 -0
- package/template/runtime/sdk/agent/tests/postmessage-bridge.test.ts +119 -0
- package/template/runtime/sdk/agent/tests/shell-integration.test.ts +71 -0
- package/template/runtime/sdk/agent/tests/use-register-edit-session.test.tsx +125 -0
- package/template/runtime/sdk/agent/tests/use-register-tools.test.ts +208 -0
- package/template/runtime/sdk/agent/tsconfig.json +18 -0
- package/template/runtime/sdk/agent/vitest.config.ts +8 -0
- package/template/runtime/sdk/backend/package.json +15 -0
- package/template/runtime/sdk/backend/src/index.ts +92 -0
- package/template/runtime/sdk/backend/tsconfig.json +8 -0
- package/template/runtime/sdk/core/package.json +15 -0
- package/template/runtime/sdk/core/src/client.ts +317 -0
- package/template/runtime/sdk/core/src/collaboration.ts +66 -0
- package/template/runtime/sdk/core/src/desktop.ts +469 -0
- package/template/runtime/sdk/core/src/device.ts +112 -0
- package/template/runtime/sdk/core/src/index.ts +6 -0
- package/template/runtime/sdk/core/src/invalidate.ts +40 -0
- package/template/runtime/sdk/core/src/types.ts +108 -0
- package/template/runtime/sdk/core/tests/capabilities.test.ts +64 -0
- package/template/runtime/sdk/core/tests/client.test.ts +424 -0
- package/template/runtime/sdk/core/tests/collaboration.test.ts +92 -0
- package/template/runtime/sdk/core/tests/desktop.test.ts +310 -0
- package/template/runtime/sdk/core/tests/device.test.ts +69 -0
- package/template/runtime/sdk/core/tsconfig.json +17 -0
- package/template/runtime/sdk/react/package.json +34 -0
- package/template/runtime/sdk/react/src/client.ts +7 -0
- package/template/runtime/sdk/react/src/components/can.tsx +24 -0
- package/template/runtime/sdk/react/src/hooks/use-action.ts +34 -0
- package/template/runtime/sdk/react/src/hooks/use-capabilities.ts +35 -0
- package/template/runtime/sdk/react/src/hooks/use-count.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-create.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-delete.ts +36 -0
- package/template/runtime/sdk/react/src/hooks/use-desktop-action.ts +94 -0
- package/template/runtime/sdk/react/src/hooks/use-device-action.ts +62 -0
- package/template/runtime/sdk/react/src/hooks/use-get.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-group-members.ts +31 -0
- package/template/runtime/sdk/react/src/hooks/use-groups.ts +31 -0
- package/template/runtime/sdk/react/src/hooks/use-list.ts +53 -0
- package/template/runtime/sdk/react/src/hooks/use-me.ts +35 -0
- package/template/runtime/sdk/react/src/hooks/use-mutation.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-permissions.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-platform-data.ts +94 -0
- package/template/runtime/sdk/react/src/hooks/use-query.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-time.ts +36 -0
- package/template/runtime/sdk/react/src/hooks/use-transaction.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-transitions.ts +82 -0
- package/template/runtime/sdk/react/src/hooks/use-update.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-upload.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-users.ts +31 -0
- package/template/runtime/sdk/react/src/index.ts +40 -0
- package/template/runtime/sdk/react/src/permissions.ts +94 -0
- package/template/runtime/sdk/react/tests/permissions.test.ts +176 -0
- package/template/runtime/sdk/react/tests/use-action.test.tsx +64 -0
- package/template/runtime/sdk/react/tests/use-capabilities.test.tsx +48 -0
- package/template/runtime/sdk/react/tests/use-desktop-action.test.tsx +144 -0
- package/template/runtime/sdk/react/tests/use-permissions.test.tsx +162 -0
- package/template/runtime/sdk/react/tests/use-platform-data.test.tsx +89 -0
- package/template/runtime/sdk/react/tests/use-transaction.test.tsx +65 -0
- package/template/runtime/sdk/react/tests/use-transitions.test.ts +149 -0
- package/template/runtime/sdk/react/tsconfig.json +18 -0
- package/template/runtime/sdk/react/vitest.config.ts +9 -0
- package/template/runtime/sdk/react/vitest.setup.ts +6 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts +84 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts.map +1 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.js +115 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.js.map +1 -0
- package/template/runtime/server-core/dist/index.d.ts +19 -0
- package/template/runtime/server-core/dist/index.d.ts.map +1 -0
- package/template/runtime/server-core/dist/index.js +35 -0
- package/template/runtime/server-core/dist/index.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js +475 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js +65 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js +103 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js +358 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js +786 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js +82 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js +42 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js +144 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js +75 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js +85 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js +75 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js +78 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js +66 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js +322 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js +49 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js +67 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js +91 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js +69 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js +159 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js +102 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js +65 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js +226 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js +64 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js +101 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js +69 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js +32 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/access-control.d.ts +34 -0
- package/template/runtime/server-core/dist/lib/access-control.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/access-control.js +138 -0
- package/template/runtime/server-core/dist/lib/access-control.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.d.ts +69 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.js +57 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-db.d.ts +486 -0
- package/template/runtime/server-core/dist/lib/app-db.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/app-db.js +2581 -0
- package/template/runtime/server-core/dist/lib/app-db.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-runtime.d.ts +28 -0
- package/template/runtime/server-core/dist/lib/app-runtime.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/app-runtime.js +56 -0
- package/template/runtime/server-core/dist/lib/app-runtime.js.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-actions.d.ts +149 -0
- package/template/runtime/server-core/dist/lib/backend-actions.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-actions.js +926 -0
- package/template/runtime/server-core/dist/lib/backend-actions.js.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-contract.d.ts +399 -0
- package/template/runtime/server-core/dist/lib/backend-contract.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-contract.js +1148 -0
- package/template/runtime/server-core/dist/lib/backend-contract.js.map +1 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.d.ts +30 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.js +133 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts +7 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.js +22 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts +43 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.js +201 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts +11 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.js +66 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-templates.d.ts +16 -0
- package/template/runtime/server-core/dist/lib/issue-templates.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-templates.js +89 -0
- package/template/runtime/server-core/dist/lib/issue-templates.js.map +1 -0
- package/template/runtime/server-core/dist/lib/migrations.d.ts +31 -0
- package/template/runtime/server-core/dist/lib/migrations.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/migrations.js +180 -0
- package/template/runtime/server-core/dist/lib/migrations.js.map +1 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts +21 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.js +71 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.js.map +1 -0
- package/template/runtime/server-core/dist/lib/record-access.d.ts +34 -0
- package/template/runtime/server-core/dist/lib/record-access.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/record-access.js +81 -0
- package/template/runtime/server-core/dist/lib/record-access.js.map +1 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.d.ts +28 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.js +67 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.js.map +1 -0
- package/template/runtime/server-core/dist/lib/transitions.d.ts +55 -0
- package/template/runtime/server-core/dist/lib/transitions.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/transitions.js +142 -0
- package/template/runtime/server-core/dist/lib/transitions.js.map +1 -0
- package/template/runtime/server-core/dist/types/models.d.ts +163 -0
- package/template/runtime/server-core/dist/types/models.d.ts.map +1 -0
- package/template/runtime/server-core/dist/types/models.js +3 -0
- package/template/runtime/server-core/dist/types/models.js.map +1 -0
- package/template/runtime/server-core/package.json +24 -0
- package/template/runtime/styles/preset.css +282 -0
- package/template/runtime/sync-template-command.cjs +19 -0
- package/template/runtime/sync-template.cjs +71 -0
- package/template/runtime/tsconfig.base.json +20 -0
- package/template/runtime/version.json +3 -0
- package/template/runtime/vite-plugin.mjs +309 -0
- package/template/src/App.tsx +273 -0
- package/template/src/components/ui/accordion.tsx +79 -0
- package/template/src/components/ui/alert-dialog.tsx +197 -0
- package/template/src/components/ui/alert.tsx +76 -0
- package/template/src/components/ui/aspect-ratio.tsx +11 -0
- package/template/src/components/ui/avatar.tsx +110 -0
- package/template/src/components/ui/badge.tsx +49 -0
- package/template/src/components/ui/breadcrumb.tsx +122 -0
- package/template/src/components/ui/button-group.tsx +83 -0
- package/template/src/components/ui/button.tsx +67 -0
- package/template/src/components/ui/calendar.tsx +221 -0
- package/template/src/components/ui/card.tsx +103 -0
- package/template/src/components/ui/carousel.tsx +240 -0
- package/template/src/components/ui/chart.tsx +373 -0
- package/template/src/components/ui/checkbox.tsx +31 -0
- package/template/src/components/ui/collapsible.tsx +33 -0
- package/template/src/components/ui/combobox.tsx +299 -0
- package/template/src/components/ui/command.tsx +193 -0
- package/template/src/components/ui/context-menu.tsx +261 -0
- package/template/src/components/ui/dialog.tsx +168 -0
- package/template/src/components/ui/direction.tsx +22 -0
- package/template/src/components/ui/drawer.tsx +132 -0
- package/template/src/components/ui/dropdown-menu.tsx +269 -0
- package/template/src/components/ui/empty.tsx +104 -0
- package/template/src/components/ui/field.tsx +238 -0
- package/template/src/components/ui/hover-card.tsx +42 -0
- package/template/src/components/ui/input-group.tsx +154 -0
- package/template/src/components/ui/input-otp.tsx +87 -0
- package/template/src/components/ui/input.tsx +19 -0
- package/template/src/components/ui/item.tsx +196 -0
- package/template/src/components/ui/kbd.tsx +26 -0
- package/template/src/components/ui/label.tsx +22 -0
- package/template/src/components/ui/menubar.tsx +280 -0
- package/template/src/components/ui/native-select.tsx +61 -0
- package/template/src/components/ui/navigation-menu.tsx +164 -0
- package/template/src/components/ui/pagination.tsx +129 -0
- package/template/src/components/ui/popover.tsx +87 -0
- package/template/src/components/ui/progress.tsx +31 -0
- package/template/src/components/ui/radio-group.tsx +42 -0
- package/template/src/components/ui/resizable.tsx +50 -0
- package/template/src/components/ui/scroll-area.tsx +53 -0
- package/template/src/components/ui/select.tsx +192 -0
- package/template/src/components/ui/separator.tsx +26 -0
- package/template/src/components/ui/sheet.tsx +145 -0
- package/template/src/components/ui/sidebar.tsx +700 -0
- package/template/src/components/ui/skeleton.tsx +13 -0
- package/template/src/components/ui/slider.tsx +59 -0
- package/template/src/components/ui/sonner.tsx +47 -0
- package/template/src/components/ui/spinner.tsx +10 -0
- package/template/src/components/ui/switch.tsx +33 -0
- package/template/src/components/ui/table.tsx +114 -0
- package/template/src/components/ui/tabs.tsx +90 -0
- package/template/src/components/ui/textarea.tsx +18 -0
- package/template/src/components/ui/toggle-group.tsx +89 -0
- package/template/src/components/ui/toggle.tsx +45 -0
- package/template/src/components/ui/tooltip.tsx +57 -0
- package/template/src/hooks/use-mobile.ts +3 -0
- package/template/src/index.css +4 -0
- package/template/src/lib/utils.ts +3 -0
- package/template/src/main.tsx +10 -0
- package/template/src/vite-env.d.ts +1 -0
- package/template/template.gitignore +10 -0
- package/template/template.npmrc +1 -0
- package/template/tests/agent-context.test.ts +69 -0
- package/template/tests/agent-guidance-template.test.ts +49 -0
- package/template/tests/agent-runtime.test.ts +198 -0
- package/template/tests/agent-tools.test.ts +150 -0
- package/template/tests/agent-use-agent.test.ts +86 -0
- package/template/tests/assistant-ui-adapter.test.ts +211 -0
- package/template/tests/business-modeling-template.test.ts +71 -0
- package/template/tests/client.test.ts +382 -0
- package/template/tests/dev-issue-search-suggestions.test.ts +36 -0
- package/template/tests/dev-shell-context.test.tsx +40 -0
- package/template/tests/dev-shell-template.test.ts +2593 -0
- package/template/tests/invalidation.test.ts +126 -0
- package/template/tests/main-tsx.test.ts +28 -0
- package/template/tests/media-preview-template.test.ts +21 -0
- package/template/tests/mutations.test.ts +224 -0
- package/template/tests/react.test.ts +302 -0
- package/template/tests/redirect.test.ts +51 -0
- package/template/tests/skill-docs.test.ts +76 -0
- package/template/tests/state-transitions-template.test.ts +61 -0
- package/template/tests/template-ui.test.ts +145 -0
- package/template/tests/upload.test.ts +143 -0
- package/template/tests/vite-plugin.test.ts +426 -0
- package/template/tests/vite-proxy-security.test.ts +153 -0
- package/template/tsconfig.json +11 -0
- package/template/vite.config.ts +7 -0
- package/template/vitest.config.ts +16 -0
- package/template/vitest.setup.ts +1 -0
|
@@ -0,0 +1,2581 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IssueAttachmentDraftLimitError = exports.MAX_ISSUE_DRAFT_ATTACHMENTS = exports.MAX_ISSUE_DEPENDENCIES = exports.MAX_ISSUE_SUB_ISSUE_DEPTH = exports.MAX_ISSUE_SUB_ISSUES = exports.ISSUE_REACTION_CONTENTS = exports.ISSUE_COMMENT_MINIMIZED_REASONS = exports.ISSUE_SEARCH_SCOPES = exports.ISSUE_LOCK_REASONS = exports.ISSUE_TYPES = void 0;
|
|
7
|
+
exports.setDatabaseWriteGuard = setDatabaseWriteGuard;
|
|
8
|
+
exports.isCurrentDbQueueOwner = isCurrentDbQueueOwner;
|
|
9
|
+
exports.withDbQueue = withDbQueue;
|
|
10
|
+
exports.configureDbQueueForTests = configureDbQueueForTests;
|
|
11
|
+
exports.getConnection = getConnection;
|
|
12
|
+
exports.exportDatabaseSnapshot = exportDatabaseSnapshot;
|
|
13
|
+
exports.evictConnectionForDbPath = evictConnectionForDbPath;
|
|
14
|
+
exports.closeIdleConnections = closeIdleConnections;
|
|
15
|
+
exports.closeAllConnections = closeAllConnections;
|
|
16
|
+
exports.closeConnectionsForPage = closeConnectionsForPage;
|
|
17
|
+
exports.execRawSql = execRawSql;
|
|
18
|
+
exports.execQuerySqlWithBudget = execQuerySqlWithBudget;
|
|
19
|
+
exports.runDbTransaction = runDbTransaction;
|
|
20
|
+
exports.isValidSchemaName = isValidSchemaName;
|
|
21
|
+
exports.fieldTypeToSql = fieldTypeToSql;
|
|
22
|
+
exports.getDbPath = getDbPath;
|
|
23
|
+
exports.createTable = createTable;
|
|
24
|
+
exports.alterTableAddColumn = alterTableAddColumn;
|
|
25
|
+
exports.dropTable = dropTable;
|
|
26
|
+
exports.isIssueType = isIssueType;
|
|
27
|
+
exports.isIssueLockReason = isIssueLockReason;
|
|
28
|
+
exports.parseIssueSearchScopes = parseIssueSearchScopes;
|
|
29
|
+
exports.isIssueCommentMinimizedReason = isIssueCommentMinimizedReason;
|
|
30
|
+
exports.isIssueReactionContent = isIssueReactionContent;
|
|
31
|
+
exports.ensureIssueTables = ensureIssueTables;
|
|
32
|
+
exports.listIssueLabels = listIssueLabels;
|
|
33
|
+
exports.createIssueLabel = createIssueLabel;
|
|
34
|
+
exports.updateIssueLabel = updateIssueLabel;
|
|
35
|
+
exports.deleteIssueLabel = deleteIssueLabel;
|
|
36
|
+
exports.listIssueMilestones = listIssueMilestones;
|
|
37
|
+
exports.createIssueMilestone = createIssueMilestone;
|
|
38
|
+
exports.updateIssueMilestone = updateIssueMilestone;
|
|
39
|
+
exports.deleteIssueMilestone = deleteIssueMilestone;
|
|
40
|
+
exports.setIssueMilestone = setIssueMilestone;
|
|
41
|
+
exports.replaceIssueLabels = replaceIssueLabels;
|
|
42
|
+
exports.replaceIssueAssignees = replaceIssueAssignees;
|
|
43
|
+
exports.setIssueSubscription = setIssueSubscription;
|
|
44
|
+
exports.getIssueCollaborationMetadata = getIssueCollaborationMetadata;
|
|
45
|
+
exports.getNextIssueNumber = getNextIssueNumber;
|
|
46
|
+
exports.insertIssue = insertIssue;
|
|
47
|
+
exports.listPotentialDuplicateIssues = listPotentialDuplicateIssues;
|
|
48
|
+
exports.listIssues = listIssues;
|
|
49
|
+
exports.getIssueById = getIssueById;
|
|
50
|
+
exports.getIssueByNumber = getIssueByNumber;
|
|
51
|
+
exports.updateIssue = updateIssue;
|
|
52
|
+
exports.getIssueComment = getIssueComment;
|
|
53
|
+
exports.setIssueLock = setIssueLock;
|
|
54
|
+
exports.setIssuePin = setIssuePin;
|
|
55
|
+
exports.addIssueSubIssue = addIssueSubIssue;
|
|
56
|
+
exports.removeIssueSubIssue = removeIssueSubIssue;
|
|
57
|
+
exports.reprioritizeIssueSubIssue = reprioritizeIssueSubIssue;
|
|
58
|
+
exports.listIssueAncestorIds = listIssueAncestorIds;
|
|
59
|
+
exports.listIssueSubIssues = listIssueSubIssues;
|
|
60
|
+
exports.convertIssueTaskToSubIssue = convertIssueTaskToSubIssue;
|
|
61
|
+
exports.addIssueDependency = addIssueDependency;
|
|
62
|
+
exports.removeIssueDependency = removeIssueDependency;
|
|
63
|
+
exports.parseIssueDuplicateReference = parseIssueDuplicateReference;
|
|
64
|
+
exports.insertIssueDuplicateComment = insertIssueDuplicateComment;
|
|
65
|
+
exports.markIssueDuplicateWithComment = markIssueDuplicateWithComment;
|
|
66
|
+
exports.unmarkIssueDuplicate = unmarkIssueDuplicate;
|
|
67
|
+
exports.insertIssueComment = insertIssueComment;
|
|
68
|
+
exports.extractIssueReferenceNumbers = extractIssueReferenceNumbers;
|
|
69
|
+
exports.reconcileIssueCrossReferences = reconcileIssueCrossReferences;
|
|
70
|
+
exports.updateIssueComment = updateIssueComment;
|
|
71
|
+
exports.setIssueCommentPin = setIssueCommentPin;
|
|
72
|
+
exports.setIssueCommentMinimized = setIssueCommentMinimized;
|
|
73
|
+
exports.insertIssueRevision = insertIssueRevision;
|
|
74
|
+
exports.listIssueRevisions = listIssueRevisions;
|
|
75
|
+
exports.deleteIssueComment = deleteIssueComment;
|
|
76
|
+
exports.deleteIssue = deleteIssue;
|
|
77
|
+
exports.replaceIssueMentions = replaceIssueMentions;
|
|
78
|
+
exports.setIssueReaction = setIssueReaction;
|
|
79
|
+
exports.insertIssueEvent = insertIssueEvent;
|
|
80
|
+
exports.insertIssueAttachment = insertIssueAttachment;
|
|
81
|
+
exports.getIssueAttachment = getIssueAttachment;
|
|
82
|
+
exports.listExpiredUnboundIssueAttachments = listExpiredUnboundIssueAttachments;
|
|
83
|
+
exports.deleteIssueAttachmentMetadata = deleteIssueAttachmentMetadata;
|
|
84
|
+
exports.releaseUnboundIssueAttachment = releaseUnboundIssueAttachment;
|
|
85
|
+
exports.restoreReleasedIssueAttachment = restoreReleasedIssueAttachment;
|
|
86
|
+
exports.deleteBoundIssueAttachments = deleteBoundIssueAttachments;
|
|
87
|
+
exports.bindIssueAttachments = bindIssueAttachments;
|
|
88
|
+
exports.getIssueDetail = getIssueDetail;
|
|
89
|
+
exports.getIssueDetailByNumber = getIssueDetailByNumber;
|
|
90
|
+
const sql_js_1 = __importDefault(require("sql.js"));
|
|
91
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
92
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
93
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
94
|
+
const runtime_errors_js_1 = require("./runtime-errors.js");
|
|
95
|
+
const issue_task_conversion_js_1 = require("./issue-task-conversion.js");
|
|
96
|
+
let SqlJs = null;
|
|
97
|
+
let databaseWriteGuard = null;
|
|
98
|
+
function setDatabaseWriteGuard(guard) {
|
|
99
|
+
databaseWriteGuard = guard;
|
|
100
|
+
}
|
|
101
|
+
function isReadOnlySql(sql) {
|
|
102
|
+
if (typeof sql !== "string")
|
|
103
|
+
return false;
|
|
104
|
+
const normalized = sql.trimStart().replace(/^(?:--[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/\s*)+/, "").trimStart().toUpperCase();
|
|
105
|
+
return normalized.startsWith("SELECT") || normalized.startsWith("PRAGMA") || normalized.startsWith("EXPLAIN");
|
|
106
|
+
}
|
|
107
|
+
function assertDatabaseWriteAllowed(dbPath, sql) {
|
|
108
|
+
if (!isReadOnlySql(sql))
|
|
109
|
+
databaseWriteGuard?.(dbPath);
|
|
110
|
+
}
|
|
111
|
+
async function getSqlJs() {
|
|
112
|
+
if (!SqlJs) {
|
|
113
|
+
SqlJs = await (0, sql_js_1.default)();
|
|
114
|
+
}
|
|
115
|
+
return SqlJs;
|
|
116
|
+
}
|
|
117
|
+
const DEFAULT_DB_QUEUE_TIMEOUT_MS = 5_000;
|
|
118
|
+
const dbQueues = new Map();
|
|
119
|
+
const dbQueueOwner = new node_async_hooks_1.AsyncLocalStorage();
|
|
120
|
+
function isCurrentDbQueueOwner(dbPath) {
|
|
121
|
+
return dbQueueOwner.getStore() === node_path_1.default.resolve(dbPath);
|
|
122
|
+
}
|
|
123
|
+
async function withDbQueue(dbPath, fn, options = {}) {
|
|
124
|
+
const key = node_path_1.default.resolve(dbPath);
|
|
125
|
+
const { info, release } = await acquireDbQueue(key, options);
|
|
126
|
+
options.onWait?.(info);
|
|
127
|
+
try {
|
|
128
|
+
return await dbQueueOwner.run(key, () => fn(info));
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
release();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function configureDbQueueForTests(options = {}) {
|
|
135
|
+
if (!options.reset)
|
|
136
|
+
return;
|
|
137
|
+
for (const state of dbQueues.values()) {
|
|
138
|
+
for (const waiter of state.waiters) {
|
|
139
|
+
if (waiter.timer)
|
|
140
|
+
clearTimeout(waiter.timer);
|
|
141
|
+
waiter.reject(new runtime_errors_js_1.LocalAppRuntimeError("Database queue reset", {
|
|
142
|
+
status: 500,
|
|
143
|
+
code: "db_runtime_error",
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
dbQueues.clear();
|
|
148
|
+
}
|
|
149
|
+
async function acquireDbQueue(dbPath, options) {
|
|
150
|
+
const state = dbQueues.get(dbPath) ?? { active: false, waiters: [] };
|
|
151
|
+
dbQueues.set(dbPath, state);
|
|
152
|
+
if (!state.active) {
|
|
153
|
+
state.active = true;
|
|
154
|
+
return {
|
|
155
|
+
info: { dbPath, waitMs: 0 },
|
|
156
|
+
release: createDbQueueRelease(dbPath, state),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_DB_QUEUE_TIMEOUT_MS;
|
|
160
|
+
const enqueuedAt = Date.now();
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
const waiter = {
|
|
163
|
+
resolve: (info) => resolve({ info, release: createDbQueueRelease(dbPath, state) }),
|
|
164
|
+
reject,
|
|
165
|
+
timer: null,
|
|
166
|
+
enqueuedAt,
|
|
167
|
+
};
|
|
168
|
+
waiter.timer = setTimeout(() => {
|
|
169
|
+
const index = state.waiters.indexOf(waiter);
|
|
170
|
+
if (index >= 0)
|
|
171
|
+
state.waiters.splice(index, 1);
|
|
172
|
+
reject(new runtime_errors_js_1.LocalAppRuntimeError("Database queue timed out waiting for app database", {
|
|
173
|
+
status: 503,
|
|
174
|
+
code: "db_queue_timeout",
|
|
175
|
+
details: { waitMs: Date.now() - enqueuedAt },
|
|
176
|
+
}));
|
|
177
|
+
}, timeoutMs);
|
|
178
|
+
state.waiters.push(waiter);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function createDbQueueRelease(dbPath, state) {
|
|
182
|
+
let released = false;
|
|
183
|
+
return () => {
|
|
184
|
+
if (released)
|
|
185
|
+
return;
|
|
186
|
+
released = true;
|
|
187
|
+
const next = state.waiters.shift();
|
|
188
|
+
if (!next) {
|
|
189
|
+
state.active = false;
|
|
190
|
+
if (dbQueues.get(dbPath) === state)
|
|
191
|
+
dbQueues.delete(dbPath);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (next.timer)
|
|
195
|
+
clearTimeout(next.timer);
|
|
196
|
+
next.resolve({ dbPath, waitMs: Date.now() - next.enqueuedAt });
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
const _connections = new Map();
|
|
200
|
+
const IDLE_TIMEOUT_MS = 5 * 60 * 1000;
|
|
201
|
+
async function getConnection(dbPath) {
|
|
202
|
+
const entry = _connections.get(dbPath);
|
|
203
|
+
if (entry) {
|
|
204
|
+
entry.lastUsed = Date.now();
|
|
205
|
+
return entry.db;
|
|
206
|
+
}
|
|
207
|
+
const db = await openDatabase(dbPath);
|
|
208
|
+
_connections.set(dbPath, { db, lastUsed: Date.now(), dirty: false, transactionDepth: 0 });
|
|
209
|
+
return db;
|
|
210
|
+
}
|
|
211
|
+
async function exportDatabaseSnapshot(dbPath) {
|
|
212
|
+
return withDbQueue(dbPath, async () => {
|
|
213
|
+
const db = await getConnection(dbPath);
|
|
214
|
+
return Buffer.from(db.export());
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async function openDatabase(dbPath, retry = true) {
|
|
218
|
+
const SQL = await getSqlJs();
|
|
219
|
+
try {
|
|
220
|
+
const db = node_fs_1.default.existsSync(dbPath)
|
|
221
|
+
? new SQL.Database(node_fs_1.default.readFileSync(dbPath))
|
|
222
|
+
: new SQL.Database();
|
|
223
|
+
return guardDatabase(dbPath, db);
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
if (retry && (0, runtime_errors_js_1.isWasmRuntimeError)(err)) {
|
|
227
|
+
resetSqlJsRuntimeAfterError();
|
|
228
|
+
return openDatabase(dbPath, false);
|
|
229
|
+
}
|
|
230
|
+
throw err;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function guardDatabase(dbPath, database) {
|
|
234
|
+
const target = database;
|
|
235
|
+
if (target.__localappAppDbGuarded)
|
|
236
|
+
return database;
|
|
237
|
+
Object.defineProperty(target, "__localappAppDbGuarded", { value: true });
|
|
238
|
+
for (const method of ["run", "exec"]) {
|
|
239
|
+
const original = target[method];
|
|
240
|
+
if (typeof original !== "function")
|
|
241
|
+
continue;
|
|
242
|
+
target[method] = (...args) => {
|
|
243
|
+
assertDatabaseWriteAllowed(dbPath, args[0]);
|
|
244
|
+
return guardSqlJsCall(dbPath, () => original.apply(database, args));
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
const originalExport = target.export;
|
|
248
|
+
if (typeof originalExport === "function") {
|
|
249
|
+
target.export = (...args) => guardSqlJsCall(dbPath, () => originalExport.apply(database, args));
|
|
250
|
+
}
|
|
251
|
+
const originalPrepare = target.prepare;
|
|
252
|
+
if (typeof originalPrepare === "function") {
|
|
253
|
+
target.prepare = (...args) => {
|
|
254
|
+
assertDatabaseWriteAllowed(dbPath, args[0]);
|
|
255
|
+
return guardStatement(dbPath, guardSqlJsCall(dbPath, () => originalPrepare.apply(database, args)));
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return database;
|
|
259
|
+
}
|
|
260
|
+
function guardStatement(dbPath, stmt) {
|
|
261
|
+
const target = stmt;
|
|
262
|
+
for (const method of ["bind", "step", "get", "getAsObject", "getColumnNames", "run", "free"]) {
|
|
263
|
+
const original = target[method];
|
|
264
|
+
if (typeof original !== "function")
|
|
265
|
+
continue;
|
|
266
|
+
target[method] = (...args) => guardSqlJsCall(dbPath, () => original.apply(stmt, args));
|
|
267
|
+
}
|
|
268
|
+
return stmt;
|
|
269
|
+
}
|
|
270
|
+
function guardSqlJsCall(dbPath, fn) {
|
|
271
|
+
try {
|
|
272
|
+
return fn();
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
recoverFromSqlJsRuntimeError(dbPath, err);
|
|
276
|
+
throw err;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function recoverFromSqlJsRuntimeError(dbPath, err) {
|
|
280
|
+
if (!(0, runtime_errors_js_1.isWasmRuntimeError)(err))
|
|
281
|
+
return;
|
|
282
|
+
evictConnectionForDbPath(dbPath);
|
|
283
|
+
resetSqlJsRuntimeAfterError();
|
|
284
|
+
}
|
|
285
|
+
function resetSqlJsRuntimeAfterError() {
|
|
286
|
+
for (const [dbPath, entry] of _connections) {
|
|
287
|
+
try {
|
|
288
|
+
entry.db.close();
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
// A WASM runtime error can leave the module in a bad state; reset is best-effort.
|
|
292
|
+
}
|
|
293
|
+
_connections.delete(dbPath);
|
|
294
|
+
}
|
|
295
|
+
SqlJs = null;
|
|
296
|
+
}
|
|
297
|
+
function markDirty(dbPath) {
|
|
298
|
+
const entry = _connections.get(dbPath);
|
|
299
|
+
if (entry)
|
|
300
|
+
entry.dirty = true;
|
|
301
|
+
}
|
|
302
|
+
function saveConnection(dbPath) {
|
|
303
|
+
const entry = _connections.get(dbPath);
|
|
304
|
+
if (!entry)
|
|
305
|
+
return;
|
|
306
|
+
if (!entry.dirty)
|
|
307
|
+
return;
|
|
308
|
+
if (entry.transactionDepth > 0)
|
|
309
|
+
return;
|
|
310
|
+
const dir = node_path_1.default.dirname(dbPath);
|
|
311
|
+
if (!node_fs_1.default.existsSync(dir))
|
|
312
|
+
node_fs_1.default.mkdirSync(dir, { recursive: true });
|
|
313
|
+
const data = entry.db.export();
|
|
314
|
+
node_fs_1.default.writeFileSync(dbPath, Buffer.from(data));
|
|
315
|
+
entry.dirty = false;
|
|
316
|
+
}
|
|
317
|
+
function evictConnectionForDbPath(dbPath) {
|
|
318
|
+
const entry = _connections.get(dbPath);
|
|
319
|
+
if (!entry)
|
|
320
|
+
return;
|
|
321
|
+
try {
|
|
322
|
+
entry.db.close();
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
// The connection may already be in a bad WASM state; eviction is best-effort.
|
|
326
|
+
}
|
|
327
|
+
_connections.delete(dbPath);
|
|
328
|
+
}
|
|
329
|
+
function closeIdleConnections() {
|
|
330
|
+
const now = Date.now();
|
|
331
|
+
for (const [dbPath, entry] of _connections) {
|
|
332
|
+
if (now - entry.lastUsed > IDLE_TIMEOUT_MS) {
|
|
333
|
+
if (entry.dirty) {
|
|
334
|
+
const data = entry.db.export();
|
|
335
|
+
node_fs_1.default.writeFileSync(dbPath, Buffer.from(data));
|
|
336
|
+
}
|
|
337
|
+
entry.db.close();
|
|
338
|
+
_connections.delete(dbPath);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function closeAllConnections() {
|
|
343
|
+
for (const [dbPath, entry] of _connections) {
|
|
344
|
+
if (entry.dirty) {
|
|
345
|
+
const data = entry.db.export();
|
|
346
|
+
node_fs_1.default.writeFileSync(dbPath, Buffer.from(data));
|
|
347
|
+
}
|
|
348
|
+
entry.db.close();
|
|
349
|
+
}
|
|
350
|
+
_connections.clear();
|
|
351
|
+
}
|
|
352
|
+
function closeConnectionsForPage(pageDir) {
|
|
353
|
+
const dbPath = getDbPath(pageDir);
|
|
354
|
+
const entry = _connections.get(dbPath);
|
|
355
|
+
if (entry) {
|
|
356
|
+
if (entry.dirty) {
|
|
357
|
+
const data = entry.db.export();
|
|
358
|
+
node_fs_1.default.writeFileSync(dbPath, Buffer.from(data));
|
|
359
|
+
}
|
|
360
|
+
entry.db.close();
|
|
361
|
+
_connections.delete(dbPath);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function execRawSql(dbPath, sql, params) {
|
|
365
|
+
const entry = _connections.get(dbPath);
|
|
366
|
+
const db = entry?.db;
|
|
367
|
+
if (!db)
|
|
368
|
+
throw new Error("No connection for " + dbPath);
|
|
369
|
+
try {
|
|
370
|
+
const upperSql = sql.trimStart().toUpperCase();
|
|
371
|
+
const isReadOnly = upperSql.startsWith("SELECT") || upperSql.startsWith("PRAGMA");
|
|
372
|
+
if (isReadOnly) {
|
|
373
|
+
const results = params && params.length > 0 ? db.exec(sql, params) : db.exec(sql);
|
|
374
|
+
if (results.length === 0)
|
|
375
|
+
return { columns: [], rows: [] };
|
|
376
|
+
const result = results[0];
|
|
377
|
+
const rows = result.values.map((vals) => {
|
|
378
|
+
const row = {};
|
|
379
|
+
result.columns.forEach((col, i) => { row[col] = vals[i]; });
|
|
380
|
+
return row;
|
|
381
|
+
});
|
|
382
|
+
return { columns: [...result.columns], rows };
|
|
383
|
+
}
|
|
384
|
+
if (params && params.length > 0) {
|
|
385
|
+
db.run(sql, params);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
db.run(sql);
|
|
389
|
+
}
|
|
390
|
+
const changes = db.getRowsModified();
|
|
391
|
+
const lastInsertRowId = db.exec("SELECT last_insert_rowid()")[0]?.values[0]?.[0] ?? 0;
|
|
392
|
+
markDirty(dbPath);
|
|
393
|
+
if (entry.transactionDepth === 0)
|
|
394
|
+
saveConnection(dbPath);
|
|
395
|
+
return { changes, lastInsertRowId };
|
|
396
|
+
}
|
|
397
|
+
catch (err) {
|
|
398
|
+
recoverFromSqlJsRuntimeError(dbPath, err);
|
|
399
|
+
throw err;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function execQuerySqlWithBudget(dbPath, sql, params, budget) {
|
|
403
|
+
const entry = _connections.get(dbPath);
|
|
404
|
+
const db = entry?.db;
|
|
405
|
+
if (!db)
|
|
406
|
+
throw new Error("No connection for " + dbPath);
|
|
407
|
+
let stmt = null;
|
|
408
|
+
try {
|
|
409
|
+
stmt = db.prepare(sql, params && params.length > 0 ? params : undefined);
|
|
410
|
+
const columns = stmt.getColumnNames();
|
|
411
|
+
const rows = [];
|
|
412
|
+
let bytes = estimateJsonBytes({ columns, rows });
|
|
413
|
+
while (stmt.step()) {
|
|
414
|
+
const values = stmt.get();
|
|
415
|
+
const row = {};
|
|
416
|
+
columns.forEach((column, index) => { row[column] = values[index]; });
|
|
417
|
+
rows.push(row);
|
|
418
|
+
bytes += estimateJsonBytes(row) + 1;
|
|
419
|
+
if (rows.length > budget.maxRows || bytes > budget.maxBytes) {
|
|
420
|
+
throw new runtime_errors_js_1.LocalAppRuntimeError("Named SQL result exceeded platform budget. Use pagination or more selective filters.", {
|
|
421
|
+
status: 413,
|
|
422
|
+
code: "named_sql_result_too_large",
|
|
423
|
+
details: {
|
|
424
|
+
sqlName: budget.sqlName,
|
|
425
|
+
rows: rows.length,
|
|
426
|
+
bytes,
|
|
427
|
+
maxRows: budget.maxRows,
|
|
428
|
+
maxBytes: budget.maxBytes,
|
|
429
|
+
},
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return { columns, rows };
|
|
434
|
+
}
|
|
435
|
+
catch (err) {
|
|
436
|
+
recoverFromSqlJsRuntimeError(dbPath, err);
|
|
437
|
+
throw err;
|
|
438
|
+
}
|
|
439
|
+
finally {
|
|
440
|
+
try {
|
|
441
|
+
stmt?.free();
|
|
442
|
+
}
|
|
443
|
+
catch {
|
|
444
|
+
// Ignore statement cleanup errors; the query error, if any, is more useful.
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function estimateJsonBytes(value) {
|
|
449
|
+
try {
|
|
450
|
+
return Buffer.byteLength(JSON.stringify(value));
|
|
451
|
+
}
|
|
452
|
+
catch {
|
|
453
|
+
return 0;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
async function runDbTransaction(dbPath, fn, options = {}) {
|
|
457
|
+
return withDbQueue(dbPath, async () => {
|
|
458
|
+
const db = await getConnection(dbPath);
|
|
459
|
+
const entry = _connections.get(dbPath);
|
|
460
|
+
try {
|
|
461
|
+
db.run("BEGIN");
|
|
462
|
+
if (entry)
|
|
463
|
+
entry.transactionDepth += 1;
|
|
464
|
+
}
|
|
465
|
+
catch (err) {
|
|
466
|
+
if ((0, runtime_errors_js_1.isWasmRuntimeError)(err)) {
|
|
467
|
+
recoverFromSqlJsRuntimeError(dbPath, err);
|
|
468
|
+
throw (0, runtime_errors_js_1.wrapDatabaseRuntimeError)(err, { operation: "transaction", dbPath });
|
|
469
|
+
}
|
|
470
|
+
throw err;
|
|
471
|
+
}
|
|
472
|
+
try {
|
|
473
|
+
const result = await fn();
|
|
474
|
+
db.run("COMMIT");
|
|
475
|
+
if (entry)
|
|
476
|
+
entry.transactionDepth = Math.max(0, entry.transactionDepth - 1);
|
|
477
|
+
markDirty(dbPath);
|
|
478
|
+
saveConnection(dbPath);
|
|
479
|
+
return result;
|
|
480
|
+
}
|
|
481
|
+
catch (err) {
|
|
482
|
+
try {
|
|
483
|
+
db.run("ROLLBACK");
|
|
484
|
+
if (entry) {
|
|
485
|
+
entry.transactionDepth = Math.max(0, entry.transactionDepth - 1);
|
|
486
|
+
entry.dirty = false;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
catch (rollbackErr) {
|
|
490
|
+
if ((0, runtime_errors_js_1.isWasmRuntimeError)(rollbackErr)) {
|
|
491
|
+
recoverFromSqlJsRuntimeError(dbPath, rollbackErr);
|
|
492
|
+
throw (0, runtime_errors_js_1.wrapDatabaseRuntimeError)(rollbackErr, { operation: "transaction", dbPath });
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
if ((0, runtime_errors_js_1.isWasmRuntimeError)(err)) {
|
|
496
|
+
recoverFromSqlJsRuntimeError(dbPath, err);
|
|
497
|
+
throw (0, runtime_errors_js_1.wrapDatabaseRuntimeError)(err, { operation: "transaction", dbPath });
|
|
498
|
+
}
|
|
499
|
+
throw err;
|
|
500
|
+
}
|
|
501
|
+
}, options);
|
|
502
|
+
}
|
|
503
|
+
// ── Public API ──
|
|
504
|
+
function isValidSchemaName(name) {
|
|
505
|
+
return /^[a-zA-Z0-9_]+$/.test(name);
|
|
506
|
+
}
|
|
507
|
+
function fieldTypeToSql(type) {
|
|
508
|
+
switch (type) {
|
|
509
|
+
case "string":
|
|
510
|
+
return "TEXT";
|
|
511
|
+
case "number":
|
|
512
|
+
return "REAL";
|
|
513
|
+
case "boolean":
|
|
514
|
+
return "INTEGER";
|
|
515
|
+
case "timestamp":
|
|
516
|
+
return "TEXT";
|
|
517
|
+
case "auto_increment":
|
|
518
|
+
return "INTEGER PRIMARY KEY AUTOINCREMENT";
|
|
519
|
+
default:
|
|
520
|
+
return "TEXT";
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function getDbPath(pageDir) {
|
|
524
|
+
const devDb = node_path_1.default.join(pageDir, "dev.db");
|
|
525
|
+
if (node_fs_1.default.existsSync(devDb))
|
|
526
|
+
return devDb;
|
|
527
|
+
const appDb = node_path_1.default.join(pageDir, "app.db");
|
|
528
|
+
if (node_fs_1.default.existsSync(appDb))
|
|
529
|
+
return appDb;
|
|
530
|
+
const legacy = node_path_1.default.join(pageDir, "db.sqlite");
|
|
531
|
+
if (node_fs_1.default.existsSync(legacy)) {
|
|
532
|
+
node_fs_1.default.renameSync(legacy, appDb);
|
|
533
|
+
return appDb;
|
|
534
|
+
}
|
|
535
|
+
return appDb;
|
|
536
|
+
}
|
|
537
|
+
async function createTable(pageDir, schema) {
|
|
538
|
+
const dbPath = getDbPath(pageDir);
|
|
539
|
+
await withDbQueue(dbPath, async () => {
|
|
540
|
+
const db = await getConnection(dbPath);
|
|
541
|
+
const columns = ["id INTEGER PRIMARY KEY AUTOINCREMENT"];
|
|
542
|
+
const userFieldNames = new Set(Object.keys(schema.fields));
|
|
543
|
+
for (const [name, field] of Object.entries(schema.fields)) {
|
|
544
|
+
columns.push(`${name} ${fieldTypeToSql(field.type)}`);
|
|
545
|
+
}
|
|
546
|
+
if (!userFieldNames.has("created_at"))
|
|
547
|
+
columns.push("created_at TEXT");
|
|
548
|
+
columns.push("updated_at TEXT");
|
|
549
|
+
db.run(`CREATE TABLE IF NOT EXISTS ${schema.name} (${columns.join(", ")})`);
|
|
550
|
+
markDirty(dbPath);
|
|
551
|
+
saveConnection(dbPath);
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
async function alterTableAddColumn(pageDir, tableName, fieldName, fieldType, constraints) {
|
|
555
|
+
const dbPath = getDbPath(pageDir);
|
|
556
|
+
await withDbQueue(dbPath, async () => {
|
|
557
|
+
const db = await getConnection(dbPath);
|
|
558
|
+
db.run(`ALTER TABLE ${tableName} ADD COLUMN ${fieldName} ${fieldTypeToSql(fieldType)}`);
|
|
559
|
+
markDirty(dbPath);
|
|
560
|
+
saveConnection(dbPath);
|
|
561
|
+
if (constraints?.defaultValue !== undefined) {
|
|
562
|
+
db.run(`UPDATE ${tableName} SET ${fieldName} = ?`, [constraints.defaultValue]);
|
|
563
|
+
markDirty(dbPath);
|
|
564
|
+
saveConnection(dbPath);
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
async function dropTable(pageDir, tableName) {
|
|
569
|
+
const dbPath = getDbPath(pageDir);
|
|
570
|
+
await withDbQueue(dbPath, async () => {
|
|
571
|
+
const db = await getConnection(dbPath);
|
|
572
|
+
db.run(`DROP TABLE IF EXISTS ${tableName}`);
|
|
573
|
+
markDirty(dbPath);
|
|
574
|
+
saveConnection(dbPath);
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
exports.ISSUE_TYPES = ["task", "bug", "feature"];
|
|
578
|
+
function isIssueType(value) {
|
|
579
|
+
return typeof value === "string" && exports.ISSUE_TYPES.includes(value);
|
|
580
|
+
}
|
|
581
|
+
exports.ISSUE_LOCK_REASONS = ["resolved", "off_topic", "too_heated", "spam"];
|
|
582
|
+
function isIssueLockReason(value) {
|
|
583
|
+
return typeof value === "string" && exports.ISSUE_LOCK_REASONS.includes(value);
|
|
584
|
+
}
|
|
585
|
+
exports.ISSUE_SEARCH_SCOPES = ["title", "body", "comments"];
|
|
586
|
+
function parseIssueSearchScopes(value) {
|
|
587
|
+
if (typeof value !== "string" || !value)
|
|
588
|
+
return null;
|
|
589
|
+
const requested = value.split(",");
|
|
590
|
+
if (requested.some((scope, index) => !exports.ISSUE_SEARCH_SCOPES.includes(scope) || requested.indexOf(scope) !== index))
|
|
591
|
+
return null;
|
|
592
|
+
const canonical = exports.ISSUE_SEARCH_SCOPES.filter((scope) => requested.includes(scope));
|
|
593
|
+
return canonical.join(",") === value ? canonical : null;
|
|
594
|
+
}
|
|
595
|
+
exports.ISSUE_COMMENT_MINIMIZED_REASONS = ["abuse", "off-topic", "outdated", "resolved", "duplicate", "spam"];
|
|
596
|
+
function isIssueCommentMinimizedReason(value) {
|
|
597
|
+
return typeof value === "string" && exports.ISSUE_COMMENT_MINIMIZED_REASONS.includes(value);
|
|
598
|
+
}
|
|
599
|
+
exports.ISSUE_REACTION_CONTENTS = ["+1", "-1", "laugh", "hooray", "confused", "heart", "rocket", "eyes"];
|
|
600
|
+
function isIssueReactionContent(value) {
|
|
601
|
+
return typeof value === "string" && exports.ISSUE_REACTION_CONTENTS.includes(value);
|
|
602
|
+
}
|
|
603
|
+
async function ensureIssueTables(dbPath) {
|
|
604
|
+
const db = await getConnection(dbPath);
|
|
605
|
+
db.run(`
|
|
606
|
+
CREATE TABLE IF NOT EXISTS _issues (
|
|
607
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
608
|
+
issue_number INTEGER NOT NULL,
|
|
609
|
+
title TEXT NOT NULL,
|
|
610
|
+
description TEXT NOT NULL DEFAULT '',
|
|
611
|
+
status TEXT NOT NULL DEFAULT 'open',
|
|
612
|
+
state_reason TEXT,
|
|
613
|
+
label TEXT NOT NULL DEFAULT 'task',
|
|
614
|
+
issue_type TEXT NOT NULL DEFAULT 'task',
|
|
615
|
+
reporter_id TEXT NOT NULL,
|
|
616
|
+
locked_at TEXT,
|
|
617
|
+
locked_by TEXT,
|
|
618
|
+
lock_reason TEXT,
|
|
619
|
+
milestone_id INTEGER,
|
|
620
|
+
pinned_at TEXT,
|
|
621
|
+
pinned_by TEXT,
|
|
622
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
623
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
624
|
+
)
|
|
625
|
+
`);
|
|
626
|
+
const issueColumns = db.exec("PRAGMA table_info(_issues)")[0]?.values.map((row) => String(row[1])) ?? [];
|
|
627
|
+
if (!issueColumns.includes("issue_type")) {
|
|
628
|
+
db.run("ALTER TABLE _issues ADD COLUMN issue_type TEXT NOT NULL DEFAULT 'task'");
|
|
629
|
+
db.run("UPDATE _issues SET issue_type = CASE WHEN label = 'feature' THEN 'feature' WHEN label = 'bug' THEN 'bug' ELSE 'task' END");
|
|
630
|
+
}
|
|
631
|
+
if (!issueColumns.includes("state_reason")) {
|
|
632
|
+
db.run("ALTER TABLE _issues ADD COLUMN state_reason TEXT");
|
|
633
|
+
db.run("UPDATE _issues SET state_reason = 'completed' WHERE status = 'closed' AND state_reason IS NULL");
|
|
634
|
+
}
|
|
635
|
+
if (!issueColumns.includes("locked_at"))
|
|
636
|
+
db.run("ALTER TABLE _issues ADD COLUMN locked_at TEXT");
|
|
637
|
+
if (!issueColumns.includes("locked_by"))
|
|
638
|
+
db.run("ALTER TABLE _issues ADD COLUMN locked_by TEXT");
|
|
639
|
+
if (!issueColumns.includes("lock_reason"))
|
|
640
|
+
db.run("ALTER TABLE _issues ADD COLUMN lock_reason TEXT");
|
|
641
|
+
if (!issueColumns.includes("milestone_id"))
|
|
642
|
+
db.run("ALTER TABLE _issues ADD COLUMN milestone_id INTEGER");
|
|
643
|
+
if (!issueColumns.includes("pinned_at"))
|
|
644
|
+
db.run("ALTER TABLE _issues ADD COLUMN pinned_at TEXT");
|
|
645
|
+
if (!issueColumns.includes("pinned_by"))
|
|
646
|
+
db.run("ALTER TABLE _issues ADD COLUMN pinned_by TEXT");
|
|
647
|
+
db.run(`
|
|
648
|
+
CREATE TABLE IF NOT EXISTS _issue_comments (
|
|
649
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
650
|
+
issue_id INTEGER NOT NULL,
|
|
651
|
+
body TEXT NOT NULL,
|
|
652
|
+
author_id TEXT NOT NULL,
|
|
653
|
+
created_at TEXT NOT NULL,
|
|
654
|
+
updated_at TEXT NOT NULL,
|
|
655
|
+
deleted_at TEXT,
|
|
656
|
+
pinned_at TEXT,
|
|
657
|
+
pinned_by TEXT,
|
|
658
|
+
minimized_at TEXT,
|
|
659
|
+
minimized_by TEXT,
|
|
660
|
+
minimized_reason TEXT
|
|
661
|
+
)
|
|
662
|
+
`);
|
|
663
|
+
const commentColumns = db.exec("PRAGMA table_info(_issue_comments)")[0]?.values.map((row) => String(row[1])) ?? [];
|
|
664
|
+
if (!commentColumns.includes("pinned_at"))
|
|
665
|
+
db.run("ALTER TABLE _issue_comments ADD COLUMN pinned_at TEXT");
|
|
666
|
+
if (!commentColumns.includes("pinned_by"))
|
|
667
|
+
db.run("ALTER TABLE _issue_comments ADD COLUMN pinned_by TEXT");
|
|
668
|
+
if (!commentColumns.includes("minimized_at"))
|
|
669
|
+
db.run("ALTER TABLE _issue_comments ADD COLUMN minimized_at TEXT");
|
|
670
|
+
if (!commentColumns.includes("minimized_by"))
|
|
671
|
+
db.run("ALTER TABLE _issue_comments ADD COLUMN minimized_by TEXT");
|
|
672
|
+
if (!commentColumns.includes("minimized_reason"))
|
|
673
|
+
db.run("ALTER TABLE _issue_comments ADD COLUMN minimized_reason TEXT");
|
|
674
|
+
db.run(`
|
|
675
|
+
CREATE TABLE IF NOT EXISTS _issue_events (
|
|
676
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
677
|
+
issue_id INTEGER NOT NULL,
|
|
678
|
+
actor_id TEXT NOT NULL,
|
|
679
|
+
event_type TEXT NOT NULL,
|
|
680
|
+
payload_json TEXT NOT NULL DEFAULT '{}',
|
|
681
|
+
created_at TEXT NOT NULL
|
|
682
|
+
)
|
|
683
|
+
`);
|
|
684
|
+
db.run(`
|
|
685
|
+
CREATE TABLE IF NOT EXISTS _issue_attachments (
|
|
686
|
+
id TEXT PRIMARY KEY,
|
|
687
|
+
page_path TEXT NOT NULL DEFAULT '',
|
|
688
|
+
issue_id INTEGER,
|
|
689
|
+
comment_id INTEGER,
|
|
690
|
+
draft_id TEXT NOT NULL,
|
|
691
|
+
uploader_id TEXT NOT NULL,
|
|
692
|
+
storage_key TEXT NOT NULL UNIQUE,
|
|
693
|
+
file_name TEXT NOT NULL,
|
|
694
|
+
mime_type TEXT NOT NULL,
|
|
695
|
+
size_bytes INTEGER NOT NULL,
|
|
696
|
+
created_at TEXT NOT NULL,
|
|
697
|
+
bound_at TEXT,
|
|
698
|
+
deleted_at TEXT
|
|
699
|
+
)
|
|
700
|
+
`);
|
|
701
|
+
db.run(`
|
|
702
|
+
CREATE TABLE IF NOT EXISTS _issue_labels (
|
|
703
|
+
id TEXT PRIMARY KEY,
|
|
704
|
+
name TEXT NOT NULL UNIQUE,
|
|
705
|
+
color TEXT NOT NULL,
|
|
706
|
+
description TEXT NOT NULL DEFAULT '',
|
|
707
|
+
built_in INTEGER NOT NULL DEFAULT 0,
|
|
708
|
+
created_at TEXT NOT NULL,
|
|
709
|
+
updated_at TEXT NOT NULL
|
|
710
|
+
)
|
|
711
|
+
`);
|
|
712
|
+
db.run(`
|
|
713
|
+
CREATE TABLE IF NOT EXISTS _issue_milestones (
|
|
714
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
715
|
+
title TEXT NOT NULL UNIQUE,
|
|
716
|
+
description TEXT NOT NULL DEFAULT '',
|
|
717
|
+
due_on TEXT,
|
|
718
|
+
state TEXT NOT NULL DEFAULT 'open' CHECK (state IN ('open', 'closed')),
|
|
719
|
+
created_by TEXT NOT NULL,
|
|
720
|
+
created_at TEXT NOT NULL,
|
|
721
|
+
updated_at TEXT NOT NULL
|
|
722
|
+
)
|
|
723
|
+
`);
|
|
724
|
+
db.run(`
|
|
725
|
+
CREATE TABLE IF NOT EXISTS _issue_label_links (
|
|
726
|
+
issue_id INTEGER NOT NULL,
|
|
727
|
+
label_id TEXT NOT NULL,
|
|
728
|
+
created_at TEXT NOT NULL,
|
|
729
|
+
PRIMARY KEY (issue_id, label_id)
|
|
730
|
+
)
|
|
731
|
+
`);
|
|
732
|
+
db.run(`
|
|
733
|
+
CREATE TABLE IF NOT EXISTS _issue_assignees (
|
|
734
|
+
issue_id INTEGER NOT NULL,
|
|
735
|
+
user_id TEXT NOT NULL,
|
|
736
|
+
assigned_by TEXT NOT NULL,
|
|
737
|
+
created_at TEXT NOT NULL,
|
|
738
|
+
PRIMARY KEY (issue_id, user_id)
|
|
739
|
+
)
|
|
740
|
+
`);
|
|
741
|
+
db.run(`
|
|
742
|
+
CREATE TABLE IF NOT EXISTS _issue_subscriptions (
|
|
743
|
+
issue_id INTEGER NOT NULL,
|
|
744
|
+
user_id TEXT NOT NULL,
|
|
745
|
+
created_at TEXT NOT NULL,
|
|
746
|
+
PRIMARY KEY (issue_id, user_id)
|
|
747
|
+
)
|
|
748
|
+
`);
|
|
749
|
+
db.run(`
|
|
750
|
+
CREATE TABLE IF NOT EXISTS _issue_sub_issues (
|
|
751
|
+
parent_issue_id INTEGER NOT NULL,
|
|
752
|
+
child_issue_id INTEGER NOT NULL UNIQUE,
|
|
753
|
+
position INTEGER NOT NULL,
|
|
754
|
+
added_by TEXT NOT NULL,
|
|
755
|
+
created_at TEXT NOT NULL,
|
|
756
|
+
PRIMARY KEY (parent_issue_id, child_issue_id),
|
|
757
|
+
CHECK (parent_issue_id <> child_issue_id)
|
|
758
|
+
)
|
|
759
|
+
`);
|
|
760
|
+
db.run(`
|
|
761
|
+
CREATE TABLE IF NOT EXISTS _issue_dependencies (
|
|
762
|
+
blocked_issue_id INTEGER NOT NULL,
|
|
763
|
+
blocking_issue_id INTEGER NOT NULL,
|
|
764
|
+
added_by TEXT NOT NULL,
|
|
765
|
+
created_at TEXT NOT NULL,
|
|
766
|
+
PRIMARY KEY (blocked_issue_id, blocking_issue_id),
|
|
767
|
+
CHECK (blocked_issue_id <> blocking_issue_id)
|
|
768
|
+
)
|
|
769
|
+
`);
|
|
770
|
+
db.run(`
|
|
771
|
+
CREATE TABLE IF NOT EXISTS _issue_duplicates (
|
|
772
|
+
duplicate_issue_id INTEGER PRIMARY KEY,
|
|
773
|
+
canonical_issue_id INTEGER NOT NULL,
|
|
774
|
+
marked_by TEXT NOT NULL,
|
|
775
|
+
comment_id INTEGER NOT NULL,
|
|
776
|
+
created_at TEXT NOT NULL,
|
|
777
|
+
CHECK (duplicate_issue_id <> canonical_issue_id)
|
|
778
|
+
)
|
|
779
|
+
`);
|
|
780
|
+
db.run(`
|
|
781
|
+
CREATE TABLE IF NOT EXISTS _issue_cross_references (
|
|
782
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
783
|
+
target_issue_id INTEGER NOT NULL,
|
|
784
|
+
source_issue_id INTEGER NOT NULL,
|
|
785
|
+
source_type TEXT NOT NULL CHECK (source_type IN ('issue', 'comment')),
|
|
786
|
+
source_id INTEGER NOT NULL,
|
|
787
|
+
actor_id TEXT NOT NULL,
|
|
788
|
+
created_at TEXT NOT NULL,
|
|
789
|
+
updated_at TEXT NOT NULL,
|
|
790
|
+
UNIQUE (source_type, source_id, target_issue_id),
|
|
791
|
+
CHECK (source_issue_id <> target_issue_id)
|
|
792
|
+
)
|
|
793
|
+
`);
|
|
794
|
+
db.run("CREATE INDEX IF NOT EXISTS idx_issue_cross_references_target ON _issue_cross_references(target_issue_id, created_at, id)");
|
|
795
|
+
db.run(`
|
|
796
|
+
CREATE TABLE IF NOT EXISTS _issue_mentions (
|
|
797
|
+
issue_id INTEGER NOT NULL,
|
|
798
|
+
target_type TEXT NOT NULL CHECK (target_type IN ('issue', 'comment')),
|
|
799
|
+
target_id INTEGER NOT NULL,
|
|
800
|
+
user_id TEXT NOT NULL,
|
|
801
|
+
created_at TEXT NOT NULL,
|
|
802
|
+
PRIMARY KEY (target_type, target_id, user_id)
|
|
803
|
+
)
|
|
804
|
+
`);
|
|
805
|
+
db.run("CREATE INDEX IF NOT EXISTS idx_issue_mentions_user ON _issue_mentions(user_id, issue_id)");
|
|
806
|
+
db.run(`
|
|
807
|
+
CREATE TABLE IF NOT EXISTS _issue_reactions (
|
|
808
|
+
issue_id INTEGER NOT NULL,
|
|
809
|
+
comment_id INTEGER NOT NULL DEFAULT 0,
|
|
810
|
+
user_id TEXT NOT NULL,
|
|
811
|
+
content TEXT NOT NULL,
|
|
812
|
+
created_at TEXT NOT NULL,
|
|
813
|
+
PRIMARY KEY (issue_id, comment_id, user_id, content)
|
|
814
|
+
)
|
|
815
|
+
`);
|
|
816
|
+
db.run(`
|
|
817
|
+
CREATE TABLE IF NOT EXISTS _issue_revisions (
|
|
818
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
819
|
+
issue_id INTEGER NOT NULL,
|
|
820
|
+
target_type TEXT NOT NULL CHECK (target_type IN ('issue', 'comment')),
|
|
821
|
+
target_id INTEGER NOT NULL,
|
|
822
|
+
editor_id TEXT NOT NULL,
|
|
823
|
+
title TEXT,
|
|
824
|
+
body TEXT NOT NULL,
|
|
825
|
+
fields_json TEXT NOT NULL,
|
|
826
|
+
created_at TEXT NOT NULL
|
|
827
|
+
)
|
|
828
|
+
`);
|
|
829
|
+
db.run(`
|
|
830
|
+
CREATE TABLE IF NOT EXISTS _issue_saved_views (
|
|
831
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
832
|
+
user_id TEXT NOT NULL,
|
|
833
|
+
name TEXT NOT NULL,
|
|
834
|
+
description TEXT NOT NULL DEFAULT '',
|
|
835
|
+
query_json TEXT NOT NULL,
|
|
836
|
+
created_at TEXT NOT NULL,
|
|
837
|
+
updated_at TEXT NOT NULL,
|
|
838
|
+
UNIQUE (user_id, name)
|
|
839
|
+
)
|
|
840
|
+
`);
|
|
841
|
+
db.run(`CREATE TRIGGER IF NOT EXISTS _issue_revisions_no_update
|
|
842
|
+
BEFORE UPDATE ON _issue_revisions
|
|
843
|
+
BEGIN SELECT RAISE(ABORT, 'Issue revisions are immutable'); END`);
|
|
844
|
+
db.run("DROP TRIGGER IF EXISTS _issue_revisions_no_delete");
|
|
845
|
+
db.run(`CREATE TRIGGER _issue_revisions_no_delete
|
|
846
|
+
BEFORE DELETE ON _issue_revisions
|
|
847
|
+
WHEN EXISTS (SELECT 1 FROM _issues WHERE id = OLD.issue_id)
|
|
848
|
+
BEGIN SELECT RAISE(ABORT, 'Issue revisions are immutable'); END`);
|
|
849
|
+
const attachmentColumns = db.exec("PRAGMA table_info(_issue_attachments)")[0]?.values.map((row) => String(row[1])) ?? [];
|
|
850
|
+
if (!attachmentColumns.includes("page_path")) {
|
|
851
|
+
db.run("ALTER TABLE _issue_attachments ADD COLUMN page_path TEXT NOT NULL DEFAULT ''");
|
|
852
|
+
}
|
|
853
|
+
db.run("CREATE INDEX IF NOT EXISTS _issues_list_idx ON _issues(status, label, created_at)");
|
|
854
|
+
db.run("CREATE INDEX IF NOT EXISTS _issues_reporter_idx ON _issues(reporter_id)");
|
|
855
|
+
db.run("CREATE INDEX IF NOT EXISTS _issues_milestone_idx ON _issues(milestone_id, status)");
|
|
856
|
+
db.run("CREATE INDEX IF NOT EXISTS _issues_pinned_idx ON _issues(pinned_at DESC, issue_number DESC) WHERE pinned_at IS NOT NULL");
|
|
857
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_comments_list_idx ON _issue_comments(issue_id, deleted_at, created_at)");
|
|
858
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_comments_issue_idx ON _issue_comments(issue_id, created_at)");
|
|
859
|
+
db.run("CREATE UNIQUE INDEX IF NOT EXISTS _issue_comments_one_pin_idx ON _issue_comments(issue_id) WHERE pinned_at IS NOT NULL AND deleted_at IS NULL");
|
|
860
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_events_issue_idx ON _issue_events(issue_id, created_at)");
|
|
861
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_attachments_issue_idx ON _issue_attachments(issue_id, comment_id)");
|
|
862
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_attachments_draft_idx ON _issue_attachments(draft_id, uploader_id)");
|
|
863
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_label_links_label_idx ON _issue_label_links(label_id, issue_id)");
|
|
864
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_assignees_user_idx ON _issue_assignees(user_id, issue_id)");
|
|
865
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_subscriptions_user_idx ON _issue_subscriptions(user_id, issue_id)");
|
|
866
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_sub_issues_parent_idx ON _issue_sub_issues(parent_issue_id, position, child_issue_id)");
|
|
867
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_dependencies_blocking_idx ON _issue_dependencies(blocking_issue_id, blocked_issue_id)");
|
|
868
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_duplicates_canonical_idx ON _issue_duplicates(canonical_issue_id, duplicate_issue_id)");
|
|
869
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_reactions_target_idx ON _issue_reactions(issue_id, comment_id, content)");
|
|
870
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_revisions_target_idx ON _issue_revisions(issue_id, target_type, target_id, created_at)");
|
|
871
|
+
db.run("CREATE INDEX IF NOT EXISTS _issue_saved_views_user_idx ON _issue_saved_views(user_id, id)");
|
|
872
|
+
db.run("DELETE FROM _issue_label_links WHERE label_id IN (SELECT id FROM _issue_labels WHERE built_in = 1 AND id IN ('bug', 'feature'))");
|
|
873
|
+
db.run("DELETE FROM _issue_labels WHERE built_in = 1 AND id IN ('bug', 'feature')");
|
|
874
|
+
markDirty(dbPath);
|
|
875
|
+
saveConnection(dbPath);
|
|
876
|
+
}
|
|
877
|
+
async function listIssueLabels(dbPath) {
|
|
878
|
+
await ensureIssueTables(dbPath);
|
|
879
|
+
const db = await getConnection(dbPath);
|
|
880
|
+
const stmt = db.prepare("SELECT * FROM _issue_labels ORDER BY built_in DESC, id");
|
|
881
|
+
const labels = [];
|
|
882
|
+
while (stmt.step())
|
|
883
|
+
labels.push(stmt.getAsObject());
|
|
884
|
+
stmt.free();
|
|
885
|
+
return labels;
|
|
886
|
+
}
|
|
887
|
+
async function createIssueLabel(dbPath, input) {
|
|
888
|
+
await ensureIssueTables(dbPath);
|
|
889
|
+
const db = await getConnection(dbPath);
|
|
890
|
+
const now = new Date().toISOString();
|
|
891
|
+
db.run(`INSERT INTO _issue_labels (id, name, color, description, built_in, created_at, updated_at)
|
|
892
|
+
VALUES (?, ?, ?, ?, 0, ?, ?)`, [input.id, input.name, input.color, input.description ?? "", now, now]);
|
|
893
|
+
markDirty(dbPath);
|
|
894
|
+
saveConnection(dbPath);
|
|
895
|
+
return (await getIssueLabel(dbPath, input.id));
|
|
896
|
+
}
|
|
897
|
+
async function getIssueLabel(dbPath, labelId) {
|
|
898
|
+
const db = await getConnection(dbPath);
|
|
899
|
+
const stmt = db.prepare("SELECT * FROM _issue_labels WHERE id = ?");
|
|
900
|
+
stmt.bind([labelId]);
|
|
901
|
+
const label = stmt.step() ? stmt.getAsObject() : null;
|
|
902
|
+
stmt.free();
|
|
903
|
+
return label;
|
|
904
|
+
}
|
|
905
|
+
async function updateIssueLabel(dbPath, labelId, updates) {
|
|
906
|
+
await ensureIssueTables(dbPath);
|
|
907
|
+
const existing = await getIssueLabel(dbPath, labelId);
|
|
908
|
+
if (!existing)
|
|
909
|
+
return null;
|
|
910
|
+
if (existing.built_in)
|
|
911
|
+
throw new Error("Built-in Issue labels cannot be edited");
|
|
912
|
+
const clauses = [];
|
|
913
|
+
const params = [];
|
|
914
|
+
for (const field of ["name", "color", "description"]) {
|
|
915
|
+
if (updates[field] === undefined)
|
|
916
|
+
continue;
|
|
917
|
+
clauses.push(`${field} = ?`);
|
|
918
|
+
params.push(updates[field]);
|
|
919
|
+
}
|
|
920
|
+
if (clauses.length === 0)
|
|
921
|
+
return getIssueLabel(dbPath, labelId);
|
|
922
|
+
clauses.push("updated_at = ?");
|
|
923
|
+
params.push(new Date().toISOString(), labelId);
|
|
924
|
+
const db = await getConnection(dbPath);
|
|
925
|
+
db.run(`UPDATE _issue_labels SET ${clauses.join(", ")} WHERE id = ?`, params);
|
|
926
|
+
markDirty(dbPath);
|
|
927
|
+
saveConnection(dbPath);
|
|
928
|
+
return getIssueLabel(dbPath, labelId);
|
|
929
|
+
}
|
|
930
|
+
async function deleteIssueLabel(dbPath, labelId) {
|
|
931
|
+
await ensureIssueTables(dbPath);
|
|
932
|
+
const label = await getIssueLabel(dbPath, labelId);
|
|
933
|
+
if (!label)
|
|
934
|
+
return false;
|
|
935
|
+
if (label.built_in)
|
|
936
|
+
throw new Error("Built-in Issue labels cannot be deleted");
|
|
937
|
+
const db = await getConnection(dbPath);
|
|
938
|
+
db.run("DELETE FROM _issue_label_links WHERE label_id = ?", [labelId]);
|
|
939
|
+
db.run("DELETE FROM _issue_labels WHERE id = ?", [labelId]);
|
|
940
|
+
markDirty(dbPath);
|
|
941
|
+
saveConnection(dbPath);
|
|
942
|
+
return true;
|
|
943
|
+
}
|
|
944
|
+
async function listIssueMilestones(dbPath) {
|
|
945
|
+
await ensureIssueTables(dbPath);
|
|
946
|
+
const db = await getConnection(dbPath);
|
|
947
|
+
const stmt = db.prepare(`
|
|
948
|
+
SELECT m.*,
|
|
949
|
+
SUM(CASE WHEN i.status = 'open' THEN 1 ELSE 0 END) AS open_issues,
|
|
950
|
+
SUM(CASE WHEN i.status = 'closed' THEN 1 ELSE 0 END) AS closed_issues
|
|
951
|
+
FROM _issue_milestones m
|
|
952
|
+
LEFT JOIN _issues i ON i.milestone_id = m.id
|
|
953
|
+
GROUP BY m.id
|
|
954
|
+
ORDER BY CASE WHEN m.state = 'open' THEN 0 ELSE 1 END, m.due_on IS NULL, m.due_on, m.id`);
|
|
955
|
+
const milestones = [];
|
|
956
|
+
while (stmt.step())
|
|
957
|
+
milestones.push(stmt.getAsObject());
|
|
958
|
+
stmt.free();
|
|
959
|
+
return milestones;
|
|
960
|
+
}
|
|
961
|
+
async function createIssueMilestone(dbPath, input) {
|
|
962
|
+
await ensureIssueTables(dbPath);
|
|
963
|
+
const db = await getConnection(dbPath);
|
|
964
|
+
const now = new Date().toISOString();
|
|
965
|
+
db.run(`INSERT INTO _issue_milestones (title, description, due_on, state, created_by, created_at, updated_at)
|
|
966
|
+
VALUES (?, ?, ?, 'open', ?, ?, ?)`, [input.title, input.description ?? "", input.dueOn ?? null, input.createdBy, now, now]);
|
|
967
|
+
const id = Number(db.exec("SELECT last_insert_rowid()")[0]?.values[0]?.[0] ?? 0);
|
|
968
|
+
markDirty(dbPath);
|
|
969
|
+
saveConnection(dbPath);
|
|
970
|
+
return (await listIssueMilestones(dbPath)).find((milestone) => milestone.id === id);
|
|
971
|
+
}
|
|
972
|
+
async function updateIssueMilestone(dbPath, milestoneId, updates) {
|
|
973
|
+
await ensureIssueTables(dbPath);
|
|
974
|
+
const clauses = [];
|
|
975
|
+
const params = [];
|
|
976
|
+
const fieldValues = { title: updates.title, description: updates.description, due_on: updates.dueOn, state: updates.state };
|
|
977
|
+
for (const [field, value] of Object.entries(fieldValues)) {
|
|
978
|
+
if (value === undefined)
|
|
979
|
+
continue;
|
|
980
|
+
clauses.push(`${field} = ?`);
|
|
981
|
+
params.push(value);
|
|
982
|
+
}
|
|
983
|
+
if (clauses.length === 0)
|
|
984
|
+
return (await listIssueMilestones(dbPath)).find(({ id }) => id === milestoneId) ?? null;
|
|
985
|
+
clauses.push("updated_at = ?");
|
|
986
|
+
params.push(new Date().toISOString(), milestoneId);
|
|
987
|
+
const db = await getConnection(dbPath);
|
|
988
|
+
db.run(`UPDATE _issue_milestones SET ${clauses.join(", ")} WHERE id = ?`, params);
|
|
989
|
+
if (db.getRowsModified() === 0)
|
|
990
|
+
return null;
|
|
991
|
+
markDirty(dbPath);
|
|
992
|
+
saveConnection(dbPath);
|
|
993
|
+
return (await listIssueMilestones(dbPath)).find(({ id }) => id === milestoneId) ?? null;
|
|
994
|
+
}
|
|
995
|
+
async function deleteIssueMilestone(dbPath, milestoneId) {
|
|
996
|
+
await ensureIssueTables(dbPath);
|
|
997
|
+
const db = await getConnection(dbPath);
|
|
998
|
+
db.run("UPDATE _issues SET milestone_id = NULL WHERE milestone_id = ?", [milestoneId]);
|
|
999
|
+
db.run("DELETE FROM _issue_milestones WHERE id = ?", [milestoneId]);
|
|
1000
|
+
if (db.getRowsModified() === 0)
|
|
1001
|
+
return false;
|
|
1002
|
+
markDirty(dbPath);
|
|
1003
|
+
saveConnection(dbPath);
|
|
1004
|
+
return true;
|
|
1005
|
+
}
|
|
1006
|
+
async function setIssueMilestone(dbPath, issueId, milestoneId) {
|
|
1007
|
+
await ensureIssueTables(dbPath);
|
|
1008
|
+
await assertIssueExists(dbPath, issueId);
|
|
1009
|
+
const db = await getConnection(dbPath);
|
|
1010
|
+
if (milestoneId !== null) {
|
|
1011
|
+
const stmt = db.prepare("SELECT 1 FROM _issue_milestones WHERE id = ?");
|
|
1012
|
+
stmt.bind([milestoneId]);
|
|
1013
|
+
const exists = stmt.step();
|
|
1014
|
+
stmt.free();
|
|
1015
|
+
if (!exists)
|
|
1016
|
+
throw new Error("Unknown Issue milestone");
|
|
1017
|
+
}
|
|
1018
|
+
db.run("UPDATE _issues SET milestone_id = ?, updated_at = ? WHERE id = ?", [milestoneId, new Date().toISOString(), issueId]);
|
|
1019
|
+
markDirty(dbPath);
|
|
1020
|
+
saveConnection(dbPath);
|
|
1021
|
+
}
|
|
1022
|
+
async function assertIssueExists(dbPath, issueId) {
|
|
1023
|
+
if (!await getIssueById(dbPath, issueId))
|
|
1024
|
+
throw new Error(`Issue ${issueId} not found`);
|
|
1025
|
+
}
|
|
1026
|
+
async function replaceIssueLabels(dbPath, issueId, labelIds) {
|
|
1027
|
+
await ensureIssueTables(dbPath);
|
|
1028
|
+
await assertIssueExists(dbPath, issueId);
|
|
1029
|
+
const ids = Array.from(new Set(labelIds));
|
|
1030
|
+
const db = await getConnection(dbPath);
|
|
1031
|
+
if (ids.length > 0) {
|
|
1032
|
+
const placeholders = ids.map(() => "?").join(", ");
|
|
1033
|
+
const stmt = db.prepare(`SELECT id FROM _issue_labels WHERE id IN (${placeholders})`);
|
|
1034
|
+
stmt.bind(ids);
|
|
1035
|
+
let known = 0;
|
|
1036
|
+
while (stmt.step())
|
|
1037
|
+
known += 1;
|
|
1038
|
+
stmt.free();
|
|
1039
|
+
if (known !== ids.length)
|
|
1040
|
+
throw new Error("Unknown Issue label");
|
|
1041
|
+
}
|
|
1042
|
+
db.run("DELETE FROM _issue_label_links WHERE issue_id = ?", [issueId]);
|
|
1043
|
+
const now = new Date().toISOString();
|
|
1044
|
+
for (const labelId of ids) {
|
|
1045
|
+
db.run("INSERT INTO _issue_label_links (issue_id, label_id, created_at) VALUES (?, ?, ?)", [issueId, labelId, now]);
|
|
1046
|
+
}
|
|
1047
|
+
markDirty(dbPath);
|
|
1048
|
+
saveConnection(dbPath);
|
|
1049
|
+
}
|
|
1050
|
+
async function replaceIssueAssignees(dbPath, issueId, userIds, assignedBy) {
|
|
1051
|
+
await ensureIssueTables(dbPath);
|
|
1052
|
+
await assertIssueExists(dbPath, issueId);
|
|
1053
|
+
const ids = Array.from(new Set(userIds.filter(Boolean)));
|
|
1054
|
+
const db = await getConnection(dbPath);
|
|
1055
|
+
db.run("DELETE FROM _issue_assignees WHERE issue_id = ?", [issueId]);
|
|
1056
|
+
const now = new Date().toISOString();
|
|
1057
|
+
for (const userId of ids) {
|
|
1058
|
+
db.run("INSERT INTO _issue_assignees (issue_id, user_id, assigned_by, created_at) VALUES (?, ?, ?, ?)", [issueId, userId, assignedBy, now]);
|
|
1059
|
+
}
|
|
1060
|
+
markDirty(dbPath);
|
|
1061
|
+
saveConnection(dbPath);
|
|
1062
|
+
}
|
|
1063
|
+
async function setIssueSubscription(dbPath, issueId, userId, subscribed) {
|
|
1064
|
+
await ensureIssueTables(dbPath);
|
|
1065
|
+
await assertIssueExists(dbPath, issueId);
|
|
1066
|
+
const db = await getConnection(dbPath);
|
|
1067
|
+
if (subscribed) {
|
|
1068
|
+
db.run("INSERT OR IGNORE INTO _issue_subscriptions (issue_id, user_id, created_at) VALUES (?, ?, ?)", [issueId, userId, new Date().toISOString()]);
|
|
1069
|
+
}
|
|
1070
|
+
else {
|
|
1071
|
+
db.run("DELETE FROM _issue_subscriptions WHERE issue_id = ? AND user_id = ?", [issueId, userId]);
|
|
1072
|
+
}
|
|
1073
|
+
markDirty(dbPath);
|
|
1074
|
+
saveConnection(dbPath);
|
|
1075
|
+
}
|
|
1076
|
+
async function getIssueCollaborationMetadata(dbPath, issueId) {
|
|
1077
|
+
await ensureIssueTables(dbPath);
|
|
1078
|
+
const issue = await getIssueById(dbPath, issueId);
|
|
1079
|
+
if (!issue)
|
|
1080
|
+
throw new Error(`Issue ${issueId} not found`);
|
|
1081
|
+
const db = await getConnection(dbPath);
|
|
1082
|
+
const labels = [];
|
|
1083
|
+
const labelStmt = db.prepare(`SELECT l.* FROM _issue_labels l
|
|
1084
|
+
INNER JOIN _issue_label_links link ON link.label_id = l.id
|
|
1085
|
+
WHERE link.issue_id = ? ORDER BY l.id`);
|
|
1086
|
+
labelStmt.bind([issueId]);
|
|
1087
|
+
while (labelStmt.step())
|
|
1088
|
+
labels.push(labelStmt.getAsObject());
|
|
1089
|
+
labelStmt.free();
|
|
1090
|
+
const readUserIds = (table) => {
|
|
1091
|
+
const stmt = db.prepare(`SELECT user_id FROM ${table} WHERE issue_id = ? ORDER BY user_id`);
|
|
1092
|
+
stmt.bind([issueId]);
|
|
1093
|
+
const ids = [];
|
|
1094
|
+
while (stmt.step())
|
|
1095
|
+
ids.push(String(stmt.getAsObject().user_id));
|
|
1096
|
+
stmt.free();
|
|
1097
|
+
return ids;
|
|
1098
|
+
};
|
|
1099
|
+
const assigneeIds = readUserIds("_issue_assignees");
|
|
1100
|
+
const subscriberIds = readUserIds("_issue_subscriptions");
|
|
1101
|
+
const participantStmt = db.prepare(`
|
|
1102
|
+
SELECT participant_id FROM (
|
|
1103
|
+
SELECT reporter_id AS participant_id FROM _issues WHERE id = ?
|
|
1104
|
+
UNION SELECT author_id FROM _issue_comments WHERE issue_id = ? AND deleted_at IS NULL
|
|
1105
|
+
UNION SELECT actor_id FROM _issue_events WHERE issue_id = ? AND event_type NOT IN ('subscribed', 'unsubscribed')
|
|
1106
|
+
UNION SELECT user_id FROM _issue_assignees WHERE issue_id = ?
|
|
1107
|
+
) ORDER BY participant_id`);
|
|
1108
|
+
participantStmt.bind([issueId, issueId, issueId, issueId]);
|
|
1109
|
+
const participantIds = [];
|
|
1110
|
+
while (participantStmt.step())
|
|
1111
|
+
participantIds.push(String(participantStmt.getAsObject().participant_id));
|
|
1112
|
+
participantStmt.free();
|
|
1113
|
+
return { labels, assignee_ids: assigneeIds, subscriber_ids: subscriberIds, participant_ids: participantIds };
|
|
1114
|
+
}
|
|
1115
|
+
async function getNextIssueNumber(dbPath) {
|
|
1116
|
+
const db = await getConnection(dbPath);
|
|
1117
|
+
const stmt = db.prepare("SELECT COALESCE(MAX(issue_number), 0) + 1 as next_num FROM _issues");
|
|
1118
|
+
let num = 1;
|
|
1119
|
+
if (stmt.step()) {
|
|
1120
|
+
num = stmt.getAsObject().next_num;
|
|
1121
|
+
}
|
|
1122
|
+
stmt.free();
|
|
1123
|
+
return num;
|
|
1124
|
+
}
|
|
1125
|
+
async function insertIssue(dbPath, title, description, issueType, reporterId) {
|
|
1126
|
+
if (!isIssueType(issueType))
|
|
1127
|
+
throw new Error("Invalid Issue type");
|
|
1128
|
+
await ensureIssueTables(dbPath);
|
|
1129
|
+
const issueNumber = await getNextIssueNumber(dbPath);
|
|
1130
|
+
const db = await getConnection(dbPath);
|
|
1131
|
+
const now = new Date().toISOString();
|
|
1132
|
+
db.run(`INSERT INTO _issues (issue_number, title, description, status, label, issue_type, reporter_id, created_at, updated_at) VALUES (?, ?, ?, 'open', ?, ?, ?, ?, ?)`, [issueNumber, title, description, issueType, issueType, reporterId, now, now]);
|
|
1133
|
+
const lastId = db.exec("SELECT last_insert_rowid()")[0]?.values[0]?.[0] ?? 0;
|
|
1134
|
+
markDirty(dbPath);
|
|
1135
|
+
saveConnection(dbPath);
|
|
1136
|
+
return { id: lastId, issueNumber };
|
|
1137
|
+
}
|
|
1138
|
+
function escapeLikePattern(value) {
|
|
1139
|
+
return value.replace(/[\\%_]/g, "\\$&");
|
|
1140
|
+
}
|
|
1141
|
+
function normalizePotentialDuplicateText(value) {
|
|
1142
|
+
return value.normalize("NFKC").toLocaleLowerCase().replace(/\s+/g, " ").trim();
|
|
1143
|
+
}
|
|
1144
|
+
function potentialDuplicateTokens(value) {
|
|
1145
|
+
const normalized = normalizePotentialDuplicateText(value);
|
|
1146
|
+
const tokens = new Set();
|
|
1147
|
+
for (const match of normalized.matchAll(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]+|[a-z0-9]+/gu)) {
|
|
1148
|
+
const token = match[0];
|
|
1149
|
+
if (/^[a-z0-9]+$/.test(token)) {
|
|
1150
|
+
if (token.length >= 2)
|
|
1151
|
+
tokens.add(token);
|
|
1152
|
+
continue;
|
|
1153
|
+
}
|
|
1154
|
+
const characters = Array.from(token);
|
|
1155
|
+
if (characters.length === 1)
|
|
1156
|
+
tokens.add(characters[0]);
|
|
1157
|
+
else
|
|
1158
|
+
for (let index = 0; index < characters.length - 1; index += 1)
|
|
1159
|
+
tokens.add(`${characters[index]}${characters[index + 1]}`);
|
|
1160
|
+
}
|
|
1161
|
+
return tokens;
|
|
1162
|
+
}
|
|
1163
|
+
function potentialDuplicateCoverage(left, right) {
|
|
1164
|
+
if (left.size === 0 || right.size === 0)
|
|
1165
|
+
return 0;
|
|
1166
|
+
let intersection = 0;
|
|
1167
|
+
for (const token of left)
|
|
1168
|
+
if (right.has(token))
|
|
1169
|
+
intersection += 1;
|
|
1170
|
+
return intersection / Math.min(left.size, right.size);
|
|
1171
|
+
}
|
|
1172
|
+
async function listPotentialDuplicateIssues(dbPath, title, body, limit = 3) {
|
|
1173
|
+
const normalizedTitle = normalizePotentialDuplicateText(title);
|
|
1174
|
+
if (!normalizedTitle || Array.from(body).length < 100)
|
|
1175
|
+
return [];
|
|
1176
|
+
await ensureIssueTables(dbPath);
|
|
1177
|
+
const db = await getConnection(dbPath);
|
|
1178
|
+
const statement = db.prepare("SELECT id, issue_number, title, description, status, updated_at FROM _issues ORDER BY updated_at DESC, issue_number DESC LIMIT 1000");
|
|
1179
|
+
const queryTitleTokens = potentialDuplicateTokens(title);
|
|
1180
|
+
const queryBodyTokens = potentialDuplicateTokens(body);
|
|
1181
|
+
const candidates = [];
|
|
1182
|
+
while (statement.step()) {
|
|
1183
|
+
const row = statement.getAsObject();
|
|
1184
|
+
const normalizedCandidateTitle = normalizePotentialDuplicateText(row.title);
|
|
1185
|
+
const candidateTitleTokens = potentialDuplicateTokens(row.title);
|
|
1186
|
+
const candidateBodyTokens = potentialDuplicateTokens(`${row.title} ${row.description}`);
|
|
1187
|
+
const titleCoverage = potentialDuplicateCoverage(queryTitleTokens, candidateTitleTokens);
|
|
1188
|
+
const bodyCoverage = potentialDuplicateCoverage(queryBodyTokens, candidateBodyTokens);
|
|
1189
|
+
const titleContainment = normalizedCandidateTitle === normalizedTitle
|
|
1190
|
+
? 1
|
|
1191
|
+
: normalizedCandidateTitle.includes(normalizedTitle) || normalizedTitle.includes(normalizedCandidateTitle) ? 0.9 : 0;
|
|
1192
|
+
const score = Math.min(1, Math.max(titleContainment, titleCoverage * 0.75 + bodyCoverage * 0.25));
|
|
1193
|
+
if (score < 0.18)
|
|
1194
|
+
continue;
|
|
1195
|
+
const activityStmt = db.prepare(`
|
|
1196
|
+
SELECT MAX(activity_at) AS last_activity_at FROM (
|
|
1197
|
+
SELECT updated_at AS activity_at FROM _issues WHERE id = ?
|
|
1198
|
+
UNION ALL SELECT created_at FROM _issue_comments WHERE issue_id = ? AND deleted_at IS NULL
|
|
1199
|
+
UNION ALL SELECT created_at FROM _issue_events WHERE issue_id = ? AND event_type NOT IN ('subscribed', 'unsubscribed')
|
|
1200
|
+
)`);
|
|
1201
|
+
activityStmt.bind([row.id, row.id, row.id]);
|
|
1202
|
+
const lastActivityAt = activityStmt.step() ? String(activityStmt.getAsObject().last_activity_at ?? row.updated_at) : row.updated_at;
|
|
1203
|
+
activityStmt.free();
|
|
1204
|
+
const matchedIn = titleCoverage > 0 || titleContainment > 0
|
|
1205
|
+
? bodyCoverage > 0 ? "title,body" : "title"
|
|
1206
|
+
: "body";
|
|
1207
|
+
candidates.push({
|
|
1208
|
+
id: row.id,
|
|
1209
|
+
issue_number: row.issue_number,
|
|
1210
|
+
title: row.title,
|
|
1211
|
+
status: row.status,
|
|
1212
|
+
updated_at: row.updated_at,
|
|
1213
|
+
last_activity_at: lastActivityAt,
|
|
1214
|
+
score: Number(score.toFixed(4)),
|
|
1215
|
+
matched_in: matchedIn,
|
|
1216
|
+
sort_updated_at: row.updated_at,
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
statement.free();
|
|
1220
|
+
return candidates
|
|
1221
|
+
.sort((left, right) => right.score - left.score || right.sort_updated_at.localeCompare(left.sort_updated_at) || right.issue_number - left.issue_number)
|
|
1222
|
+
.slice(0, Math.min(Math.max(limit, 1), 3))
|
|
1223
|
+
.map(({ sort_updated_at: _sortUpdatedAt, ...candidate }) => candidate);
|
|
1224
|
+
}
|
|
1225
|
+
async function listIssues(dbPath, options = {}) {
|
|
1226
|
+
await ensureIssueTables(dbPath);
|
|
1227
|
+
const db = await getConnection(dbPath);
|
|
1228
|
+
const conditions = [];
|
|
1229
|
+
const filterParams = [];
|
|
1230
|
+
const lifecycleCountConditions = [];
|
|
1231
|
+
const lifecycleCountParams = [];
|
|
1232
|
+
const addFilter = (condition, params = [], includeInLifecycleCounts = true) => {
|
|
1233
|
+
conditions.push(condition);
|
|
1234
|
+
filterParams.push(...params);
|
|
1235
|
+
if (includeInLifecycleCounts) {
|
|
1236
|
+
lifecycleCountConditions.push(condition);
|
|
1237
|
+
lifecycleCountParams.push(...params);
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
if (options.q) {
|
|
1241
|
+
const pattern = `%${escapeLikePattern(options.q)}%`;
|
|
1242
|
+
const scopes = options.searchIn?.length ? options.searchIn : exports.ISSUE_SEARCH_SCOPES;
|
|
1243
|
+
const searchConditions = [];
|
|
1244
|
+
const searchParams = [];
|
|
1245
|
+
if (scopes.includes("title")) {
|
|
1246
|
+
searchConditions.push(`i.title LIKE ? ESCAPE '\\'`);
|
|
1247
|
+
searchParams.push(pattern);
|
|
1248
|
+
}
|
|
1249
|
+
if (scopes.includes("body")) {
|
|
1250
|
+
searchConditions.push(`i.description LIKE ? ESCAPE '\\'`);
|
|
1251
|
+
searchParams.push(pattern);
|
|
1252
|
+
}
|
|
1253
|
+
if (scopes.includes("comments")) {
|
|
1254
|
+
searchConditions.push(`EXISTS (
|
|
1255
|
+
SELECT 1 FROM _issue_comments search_comment
|
|
1256
|
+
WHERE search_comment.issue_id = i.id
|
|
1257
|
+
AND search_comment.deleted_at IS NULL
|
|
1258
|
+
AND search_comment.body LIKE ? ESCAPE '\\'
|
|
1259
|
+
)`);
|
|
1260
|
+
searchParams.push(pattern);
|
|
1261
|
+
}
|
|
1262
|
+
addFilter(`(${searchConditions.join(" OR ")})`, searchParams);
|
|
1263
|
+
}
|
|
1264
|
+
if (options.status) {
|
|
1265
|
+
addFilter("i.status = ?", [options.status], false);
|
|
1266
|
+
}
|
|
1267
|
+
if (options.label === "none") {
|
|
1268
|
+
addFilter("NOT EXISTS (SELECT 1 FROM _issue_label_links link WHERE link.issue_id = i.id)");
|
|
1269
|
+
}
|
|
1270
|
+
else if (options.label) {
|
|
1271
|
+
addFilter("EXISTS (SELECT 1 FROM _issue_label_links link WHERE link.issue_id = i.id AND link.label_id = ?)", [options.label]);
|
|
1272
|
+
}
|
|
1273
|
+
if (options.issueType)
|
|
1274
|
+
addFilter("i.issue_type = ?", [options.issueType]);
|
|
1275
|
+
if (options.author) {
|
|
1276
|
+
addFilter("i.reporter_id = ?", [options.author]);
|
|
1277
|
+
}
|
|
1278
|
+
if (options.participant) {
|
|
1279
|
+
addFilter(`(
|
|
1280
|
+
i.reporter_id = ?
|
|
1281
|
+
OR EXISTS (SELECT 1 FROM _issue_comments c WHERE c.issue_id = i.id AND c.deleted_at IS NULL AND c.author_id = ?)
|
|
1282
|
+
OR EXISTS (SELECT 1 FROM _issue_events e WHERE e.issue_id = i.id AND e.actor_id = ? AND e.event_type NOT IN ('subscribed', 'unsubscribed'))
|
|
1283
|
+
OR EXISTS (SELECT 1 FROM _issue_assignees a WHERE a.issue_id = i.id AND a.user_id = ?)
|
|
1284
|
+
)`, [options.participant, options.participant, options.participant, options.participant]);
|
|
1285
|
+
}
|
|
1286
|
+
if (options.assignee === "none") {
|
|
1287
|
+
addFilter("NOT EXISTS (SELECT 1 FROM _issue_assignees assignee WHERE assignee.issue_id = i.id)");
|
|
1288
|
+
}
|
|
1289
|
+
else if (options.assignee) {
|
|
1290
|
+
addFilter("EXISTS (SELECT 1 FROM _issue_assignees assignee WHERE assignee.issue_id = i.id AND assignee.user_id = ?)", [options.assignee]);
|
|
1291
|
+
}
|
|
1292
|
+
if (options.milestone === "none") {
|
|
1293
|
+
addFilter("i.milestone_id IS NULL");
|
|
1294
|
+
}
|
|
1295
|
+
else if (options.milestone !== undefined) {
|
|
1296
|
+
addFilter("i.milestone_id = ?", [options.milestone]);
|
|
1297
|
+
}
|
|
1298
|
+
if (options.reason === "completed") {
|
|
1299
|
+
addFilter("(i.state_reason = 'completed' OR i.state_reason IS NULL)");
|
|
1300
|
+
}
|
|
1301
|
+
else if (options.reason === "not_planned") {
|
|
1302
|
+
addFilter("i.state_reason = 'not_planned'");
|
|
1303
|
+
}
|
|
1304
|
+
if (options.subscriberId) {
|
|
1305
|
+
addFilter("EXISTS (SELECT 1 FROM _issue_subscriptions subscription WHERE subscription.issue_id = i.id AND subscription.user_id = ?)", [options.subscriberId]);
|
|
1306
|
+
}
|
|
1307
|
+
if (options.mentionedUserId) {
|
|
1308
|
+
addFilter("EXISTS (SELECT 1 FROM _issue_mentions mention WHERE mention.issue_id = i.id AND mention.user_id = ?)", [options.mentionedUserId]);
|
|
1309
|
+
}
|
|
1310
|
+
if (options.locked !== undefined)
|
|
1311
|
+
addFilter(options.locked ? "i.locked_at IS NOT NULL" : "i.locked_at IS NULL");
|
|
1312
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1313
|
+
const lifecycleWhere = lifecycleCountConditions.length > 0 ? `${lifecycleCountConditions.join(" AND ")} AND ` : "";
|
|
1314
|
+
const sortExpressions = {
|
|
1315
|
+
activity: "activities.last_activity_at",
|
|
1316
|
+
created: "i.created_at",
|
|
1317
|
+
updated: "i.updated_at",
|
|
1318
|
+
comments: "COALESCE(comment_counts.comment_count, 0)",
|
|
1319
|
+
};
|
|
1320
|
+
const sort = options.sort && options.sort in sortExpressions ? options.sort : "activity";
|
|
1321
|
+
const direction = options.direction === "asc" ? "ASC" : "DESC";
|
|
1322
|
+
const limit = Number.isInteger(options.limit)
|
|
1323
|
+
? Math.min(Math.max(options.limit, 1), 100)
|
|
1324
|
+
: 25;
|
|
1325
|
+
const offset = Number.isInteger(options.offset) && options.offset >= 0 ? options.offset : 0;
|
|
1326
|
+
const aggregateCtes = `
|
|
1327
|
+
WITH comment_counts AS (
|
|
1328
|
+
SELECT issue_id, COUNT(*) AS comment_count
|
|
1329
|
+
FROM _issue_comments
|
|
1330
|
+
WHERE deleted_at IS NULL
|
|
1331
|
+
GROUP BY issue_id
|
|
1332
|
+
), activities AS (
|
|
1333
|
+
SELECT i.id AS issue_id,
|
|
1334
|
+
COALESCE(MAX(activity.activity_at), i.updated_at, i.created_at) AS last_activity_at
|
|
1335
|
+
FROM _issues i
|
|
1336
|
+
LEFT JOIN (
|
|
1337
|
+
SELECT id AS issue_id, updated_at AS activity_at FROM _issues
|
|
1338
|
+
UNION ALL
|
|
1339
|
+
SELECT issue_id, created_at AS activity_at FROM _issue_comments WHERE deleted_at IS NULL
|
|
1340
|
+
UNION ALL
|
|
1341
|
+
SELECT issue_id, created_at AS activity_at FROM _issue_events WHERE event_type NOT IN ('subscribed', 'unsubscribed')
|
|
1342
|
+
) activity ON activity.issue_id = i.id
|
|
1343
|
+
GROUP BY i.id
|
|
1344
|
+
)`;
|
|
1345
|
+
const listStmt = db.prepare(`${aggregateCtes}
|
|
1346
|
+
SELECT i.*, COALESCE(comment_counts.comment_count, 0) AS comment_count, activities.last_activity_at,
|
|
1347
|
+
EXISTS (
|
|
1348
|
+
SELECT 1 FROM _issue_dependencies dependency
|
|
1349
|
+
INNER JOIN _issues blocker ON blocker.id = dependency.blocking_issue_id
|
|
1350
|
+
WHERE dependency.blocked_issue_id = i.id AND blocker.status = 'open'
|
|
1351
|
+
) AS is_blocked,
|
|
1352
|
+
EXISTS (SELECT 1 FROM _issue_duplicates duplicate WHERE duplicate.duplicate_issue_id = i.id) AS is_duplicate
|
|
1353
|
+
FROM _issues i
|
|
1354
|
+
LEFT JOIN comment_counts ON comment_counts.issue_id = i.id
|
|
1355
|
+
LEFT JOIN activities ON activities.issue_id = i.id
|
|
1356
|
+
${where}
|
|
1357
|
+
ORDER BY ${sortExpressions[sort]} ${direction}, i.issue_number DESC
|
|
1358
|
+
LIMIT ? OFFSET ?`);
|
|
1359
|
+
listStmt.bind([...filterParams, limit, offset]);
|
|
1360
|
+
const data = [];
|
|
1361
|
+
while (listStmt.step()) {
|
|
1362
|
+
data.push({
|
|
1363
|
+
...listStmt.getAsObject(),
|
|
1364
|
+
participant_ids: [],
|
|
1365
|
+
labels: [],
|
|
1366
|
+
assignee_ids: [],
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
listStmt.free();
|
|
1370
|
+
const pinnedStmt = db.prepare(`${aggregateCtes}
|
|
1371
|
+
SELECT i.*, COALESCE(comment_counts.comment_count, 0) AS comment_count, activities.last_activity_at,
|
|
1372
|
+
EXISTS (
|
|
1373
|
+
SELECT 1 FROM _issue_dependencies dependency
|
|
1374
|
+
INNER JOIN _issues blocker ON blocker.id = dependency.blocking_issue_id
|
|
1375
|
+
WHERE dependency.blocked_issue_id = i.id AND blocker.status = 'open'
|
|
1376
|
+
) AS is_blocked,
|
|
1377
|
+
EXISTS (SELECT 1 FROM _issue_duplicates duplicate WHERE duplicate.duplicate_issue_id = i.id) AS is_duplicate
|
|
1378
|
+
FROM _issues i
|
|
1379
|
+
LEFT JOIN comment_counts ON comment_counts.issue_id = i.id
|
|
1380
|
+
LEFT JOIN activities ON activities.issue_id = i.id
|
|
1381
|
+
WHERE i.pinned_at IS NOT NULL
|
|
1382
|
+
ORDER BY i.pinned_at DESC, i.issue_number DESC
|
|
1383
|
+
LIMIT 3`);
|
|
1384
|
+
const pinned = [];
|
|
1385
|
+
while (pinnedStmt.step()) {
|
|
1386
|
+
pinned.push({
|
|
1387
|
+
...pinnedStmt.getAsObject(),
|
|
1388
|
+
participant_ids: [],
|
|
1389
|
+
labels: [],
|
|
1390
|
+
assignee_ids: [],
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
pinnedStmt.free();
|
|
1394
|
+
const countStmt = db.prepare(`
|
|
1395
|
+
SELECT
|
|
1396
|
+
(SELECT COUNT(*) FROM _issues i ${where}) AS total,
|
|
1397
|
+
(SELECT COUNT(*) FROM _issues i WHERE ${lifecycleWhere}i.status = 'open') AS open,
|
|
1398
|
+
(SELECT COUNT(*) FROM _issues i WHERE ${lifecycleWhere}i.status = 'closed') AS closed`);
|
|
1399
|
+
const countParams = [...filterParams, ...lifecycleCountParams, ...lifecycleCountParams];
|
|
1400
|
+
if (countParams.length > 0)
|
|
1401
|
+
countStmt.bind(countParams);
|
|
1402
|
+
const count = countStmt.step()
|
|
1403
|
+
? countStmt.getAsObject()
|
|
1404
|
+
: { total: 0, open: 0, closed: 0 };
|
|
1405
|
+
countStmt.free();
|
|
1406
|
+
const hydrated = [...data, ...pinned.filter((issue) => !data.some((item) => item.id === issue.id))];
|
|
1407
|
+
if (hydrated.length > 0) {
|
|
1408
|
+
const issueIds = hydrated.map((issue) => issue.id);
|
|
1409
|
+
const placeholders = issueIds.map(() => "?").join(", ");
|
|
1410
|
+
const participantStmt = db.prepare(`
|
|
1411
|
+
SELECT issue_id, participant_id FROM (
|
|
1412
|
+
SELECT id AS issue_id, reporter_id AS participant_id FROM _issues WHERE id IN (${placeholders})
|
|
1413
|
+
UNION
|
|
1414
|
+
SELECT issue_id, author_id AS participant_id FROM _issue_comments WHERE issue_id IN (${placeholders}) AND deleted_at IS NULL
|
|
1415
|
+
UNION
|
|
1416
|
+
SELECT issue_id, actor_id AS participant_id FROM _issue_events WHERE issue_id IN (${placeholders}) AND event_type NOT IN ('subscribed', 'unsubscribed')
|
|
1417
|
+
UNION
|
|
1418
|
+
SELECT issue_id, user_id AS participant_id FROM _issue_assignees WHERE issue_id IN (${placeholders})
|
|
1419
|
+
) ORDER BY issue_id, participant_id`);
|
|
1420
|
+
participantStmt.bind([...issueIds, ...issueIds, ...issueIds, ...issueIds]);
|
|
1421
|
+
const participantsByIssue = new Map(hydrated.map((issue) => [issue.id, issue.participant_ids]));
|
|
1422
|
+
while (participantStmt.step()) {
|
|
1423
|
+
const row = participantStmt.getAsObject();
|
|
1424
|
+
participantsByIssue.get(row.issue_id)?.push(row.participant_id);
|
|
1425
|
+
}
|
|
1426
|
+
participantStmt.free();
|
|
1427
|
+
const labelStmt = db.prepare(`
|
|
1428
|
+
SELECT link.issue_id, l.* FROM _issue_label_links link
|
|
1429
|
+
INNER JOIN _issue_labels l ON l.id = link.label_id
|
|
1430
|
+
WHERE link.issue_id IN (${placeholders}) ORDER BY link.issue_id, l.id`);
|
|
1431
|
+
labelStmt.bind(issueIds);
|
|
1432
|
+
const labelsByIssue = new Map(hydrated.map((issue) => [issue.id, issue.labels]));
|
|
1433
|
+
while (labelStmt.step()) {
|
|
1434
|
+
const row = labelStmt.getAsObject();
|
|
1435
|
+
const { issue_id: issueId, ...label } = row;
|
|
1436
|
+
labelsByIssue.get(issueId)?.push(label);
|
|
1437
|
+
}
|
|
1438
|
+
labelStmt.free();
|
|
1439
|
+
const assigneeStmt = db.prepare(`
|
|
1440
|
+
SELECT issue_id, user_id FROM _issue_assignees
|
|
1441
|
+
WHERE issue_id IN (${placeholders}) ORDER BY issue_id, user_id`);
|
|
1442
|
+
assigneeStmt.bind(issueIds);
|
|
1443
|
+
const assigneesByIssue = new Map(hydrated.map((issue) => [issue.id, issue.assignee_ids]));
|
|
1444
|
+
while (assigneeStmt.step()) {
|
|
1445
|
+
const row = assigneeStmt.getAsObject();
|
|
1446
|
+
assigneesByIssue.get(row.issue_id)?.push(row.user_id);
|
|
1447
|
+
}
|
|
1448
|
+
assigneeStmt.free();
|
|
1449
|
+
}
|
|
1450
|
+
for (const pinnedIssue of pinned) {
|
|
1451
|
+
const listedIssue = data.find((issue) => issue.id === pinnedIssue.id);
|
|
1452
|
+
if (!listedIssue)
|
|
1453
|
+
continue;
|
|
1454
|
+
pinnedIssue.participant_ids = [...listedIssue.participant_ids];
|
|
1455
|
+
pinnedIssue.labels = [...listedIssue.labels];
|
|
1456
|
+
pinnedIssue.assignee_ids = [...listedIssue.assignee_ids];
|
|
1457
|
+
}
|
|
1458
|
+
return {
|
|
1459
|
+
data,
|
|
1460
|
+
pinned,
|
|
1461
|
+
meta: { total: count.total, open: count.open, closed: count.closed, limit, offset },
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
async function getIssueById(dbPath, id) {
|
|
1465
|
+
await ensureIssueTables(dbPath);
|
|
1466
|
+
const db = await getConnection(dbPath);
|
|
1467
|
+
const stmt = db.prepare("SELECT * FROM _issues WHERE id = ?");
|
|
1468
|
+
stmt.bind([id]);
|
|
1469
|
+
let row = null;
|
|
1470
|
+
if (stmt.step()) {
|
|
1471
|
+
row = stmt.getAsObject();
|
|
1472
|
+
}
|
|
1473
|
+
stmt.free();
|
|
1474
|
+
return row;
|
|
1475
|
+
}
|
|
1476
|
+
async function getIssueByNumber(dbPath, issueNumber) {
|
|
1477
|
+
await ensureIssueTables(dbPath);
|
|
1478
|
+
const db = await getConnection(dbPath);
|
|
1479
|
+
const stmt = db.prepare("SELECT * FROM _issues WHERE issue_number = ?");
|
|
1480
|
+
stmt.bind([issueNumber]);
|
|
1481
|
+
const row = stmt.step() ? stmt.getAsObject() : null;
|
|
1482
|
+
stmt.free();
|
|
1483
|
+
return row;
|
|
1484
|
+
}
|
|
1485
|
+
async function updateIssue(dbPath, id, updates) {
|
|
1486
|
+
const existing = await getIssueById(dbPath, id);
|
|
1487
|
+
if (!existing)
|
|
1488
|
+
return false;
|
|
1489
|
+
const db = await getConnection(dbPath);
|
|
1490
|
+
const setClauses = [];
|
|
1491
|
+
const params = [];
|
|
1492
|
+
if (updates.status) {
|
|
1493
|
+
setClauses.push("status = ?");
|
|
1494
|
+
params.push(updates.status);
|
|
1495
|
+
}
|
|
1496
|
+
if (updates.stateReason !== undefined) {
|
|
1497
|
+
setClauses.push("state_reason = ?");
|
|
1498
|
+
params.push(updates.stateReason);
|
|
1499
|
+
}
|
|
1500
|
+
if (updates.label) {
|
|
1501
|
+
setClauses.push("label = ?");
|
|
1502
|
+
params.push(updates.label);
|
|
1503
|
+
}
|
|
1504
|
+
if (updates.issueType !== undefined) {
|
|
1505
|
+
if (!isIssueType(updates.issueType))
|
|
1506
|
+
throw new Error("Invalid Issue type");
|
|
1507
|
+
setClauses.push("issue_type = ?", "label = ?");
|
|
1508
|
+
params.push(updates.issueType, updates.issueType);
|
|
1509
|
+
}
|
|
1510
|
+
if (updates.title !== undefined) {
|
|
1511
|
+
setClauses.push("title = ?");
|
|
1512
|
+
params.push(updates.title);
|
|
1513
|
+
}
|
|
1514
|
+
if (updates.description !== undefined) {
|
|
1515
|
+
setClauses.push("description = ?");
|
|
1516
|
+
params.push(updates.description);
|
|
1517
|
+
}
|
|
1518
|
+
if (setClauses.length === 0)
|
|
1519
|
+
return true;
|
|
1520
|
+
setClauses.push("updated_at = ?");
|
|
1521
|
+
params.push(new Date().toISOString());
|
|
1522
|
+
params.push(id);
|
|
1523
|
+
db.run(`UPDATE _issues SET ${setClauses.join(", ")} WHERE id = ?`, params);
|
|
1524
|
+
markDirty(dbPath);
|
|
1525
|
+
saveConnection(dbPath);
|
|
1526
|
+
return true;
|
|
1527
|
+
}
|
|
1528
|
+
async function getIssueComment(dbPath, commentId) {
|
|
1529
|
+
await ensureIssueTables(dbPath);
|
|
1530
|
+
const db = await getConnection(dbPath);
|
|
1531
|
+
const stmt = db.prepare("SELECT * FROM _issue_comments WHERE id = ?");
|
|
1532
|
+
stmt.bind([commentId]);
|
|
1533
|
+
const row = stmt.step() ? stmt.getAsObject() : null;
|
|
1534
|
+
stmt.free();
|
|
1535
|
+
return row;
|
|
1536
|
+
}
|
|
1537
|
+
async function setIssueLock(dbPath, issueId, lockedBy, reason = null) {
|
|
1538
|
+
await ensureIssueTables(dbPath);
|
|
1539
|
+
const db = await getConnection(dbPath);
|
|
1540
|
+
const now = new Date().toISOString();
|
|
1541
|
+
db.run("UPDATE _issues SET locked_at = ?, locked_by = ?, lock_reason = ?, updated_at = ? WHERE id = ?", [lockedBy === null ? null : now, lockedBy, lockedBy === null ? null : reason, now, issueId]);
|
|
1542
|
+
if (db.getRowsModified() === 0)
|
|
1543
|
+
return false;
|
|
1544
|
+
markDirty(dbPath);
|
|
1545
|
+
saveConnection(dbPath);
|
|
1546
|
+
return true;
|
|
1547
|
+
}
|
|
1548
|
+
async function setIssuePin(dbPath, issueId, actorId, pinned) {
|
|
1549
|
+
await ensureIssueTables(dbPath);
|
|
1550
|
+
return runDbTransaction(dbPath, async () => {
|
|
1551
|
+
const issue = await getIssueById(dbPath, issueId);
|
|
1552
|
+
if (!issue)
|
|
1553
|
+
return "not_found";
|
|
1554
|
+
if ((issue.pinned_at !== null) === pinned)
|
|
1555
|
+
return "unchanged";
|
|
1556
|
+
const db = await getConnection(dbPath);
|
|
1557
|
+
if (pinned) {
|
|
1558
|
+
const count = Number(db.exec("SELECT COUNT(*) FROM _issues WHERE pinned_at IS NOT NULL")[0]?.values[0]?.[0] ?? 0);
|
|
1559
|
+
if (count >= 3)
|
|
1560
|
+
return "limit";
|
|
1561
|
+
}
|
|
1562
|
+
const now = new Date().toISOString();
|
|
1563
|
+
db.run("UPDATE _issues SET pinned_at = ?, pinned_by = ?, updated_at = ? WHERE id = ?", [pinned ? now : null, pinned ? actorId : null, now, issueId]);
|
|
1564
|
+
await insertIssueEvent(dbPath, issueId, actorId, pinned ? "pinned" : "unpinned", {});
|
|
1565
|
+
return "updated";
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
exports.MAX_ISSUE_SUB_ISSUES = 100;
|
|
1569
|
+
exports.MAX_ISSUE_SUB_ISSUE_DEPTH = 8;
|
|
1570
|
+
async function addIssueSubIssue(dbPath, parentIssueId, childIssueId, actorId, options = {}) {
|
|
1571
|
+
await ensureIssueTables(dbPath);
|
|
1572
|
+
const execute = async () => {
|
|
1573
|
+
if (parentIssueId === childIssueId)
|
|
1574
|
+
return "self_reference";
|
|
1575
|
+
const parent = await getIssueById(dbPath, parentIssueId);
|
|
1576
|
+
const child = await getIssueById(dbPath, childIssueId);
|
|
1577
|
+
if (!parent || !child)
|
|
1578
|
+
return "not_found";
|
|
1579
|
+
const db = await getConnection(dbPath);
|
|
1580
|
+
const rows = db.exec("SELECT parent_issue_id, child_issue_id FROM _issue_sub_issues")[0]?.values ?? [];
|
|
1581
|
+
const parentByChild = new Map();
|
|
1582
|
+
const childrenByParent = new Map();
|
|
1583
|
+
for (const row of rows) {
|
|
1584
|
+
const existingParentId = Number(row[0]);
|
|
1585
|
+
const existingChildId = Number(row[1]);
|
|
1586
|
+
parentByChild.set(existingChildId, existingParentId);
|
|
1587
|
+
childrenByParent.set(existingParentId, [...(childrenByParent.get(existingParentId) ?? []), existingChildId]);
|
|
1588
|
+
}
|
|
1589
|
+
const existingParent = parentByChild.get(childIssueId);
|
|
1590
|
+
if (existingParent === parentIssueId)
|
|
1591
|
+
return "duplicate";
|
|
1592
|
+
if (existingParent !== undefined)
|
|
1593
|
+
return "has_parent";
|
|
1594
|
+
const ancestorIds = new Set();
|
|
1595
|
+
let ancestor = parentIssueId;
|
|
1596
|
+
while (ancestor !== undefined && !ancestorIds.has(ancestor)) {
|
|
1597
|
+
ancestorIds.add(ancestor);
|
|
1598
|
+
ancestor = parentByChild.get(ancestor);
|
|
1599
|
+
}
|
|
1600
|
+
if (ancestorIds.has(childIssueId))
|
|
1601
|
+
return "cycle";
|
|
1602
|
+
if ((childrenByParent.get(parentIssueId)?.length ?? 0) >= exports.MAX_ISSUE_SUB_ISSUES)
|
|
1603
|
+
return "limit";
|
|
1604
|
+
const subtreeHeight = (issueId, visiting = new Set()) => {
|
|
1605
|
+
if (visiting.has(issueId))
|
|
1606
|
+
return exports.MAX_ISSUE_SUB_ISSUE_DEPTH + 1;
|
|
1607
|
+
const children = childrenByParent.get(issueId) ?? [];
|
|
1608
|
+
if (children.length === 0)
|
|
1609
|
+
return 1;
|
|
1610
|
+
const nextVisiting = new Set(visiting).add(issueId);
|
|
1611
|
+
return 1 + Math.max(...children.map((id) => subtreeHeight(id, nextVisiting)));
|
|
1612
|
+
};
|
|
1613
|
+
if (ancestorIds.size + subtreeHeight(childIssueId) > exports.MAX_ISSUE_SUB_ISSUE_DEPTH)
|
|
1614
|
+
return "depth";
|
|
1615
|
+
const nextPosition = Number(db.exec(`SELECT COALESCE(MAX(position), -1) + 1 FROM _issue_sub_issues WHERE parent_issue_id = ${parentIssueId}`)[0]?.values[0]?.[0] ?? 0);
|
|
1616
|
+
const now = new Date().toISOString();
|
|
1617
|
+
db.run("INSERT INTO _issue_sub_issues (parent_issue_id, child_issue_id, position, added_by, created_at) VALUES (?, ?, ?, ?, ?)", [parentIssueId, childIssueId, nextPosition, actorId, now]);
|
|
1618
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id IN (?, ?)", [now, parentIssueId, childIssueId]);
|
|
1619
|
+
await insertIssueEvent(dbPath, parentIssueId, actorId, "sub_issue_added", { childIssueId, childIssueNumber: child.issue_number });
|
|
1620
|
+
await insertIssueEvent(dbPath, childIssueId, actorId, "parent_added", { parentIssueId, parentIssueNumber: parent.issue_number });
|
|
1621
|
+
return "added";
|
|
1622
|
+
};
|
|
1623
|
+
return options.joinTransaction ? execute() : runDbTransaction(dbPath, execute);
|
|
1624
|
+
}
|
|
1625
|
+
async function removeIssueSubIssue(dbPath, parentIssueId, childIssueId, actorId) {
|
|
1626
|
+
await ensureIssueTables(dbPath);
|
|
1627
|
+
return runDbTransaction(dbPath, async () => {
|
|
1628
|
+
const parent = await getIssueById(dbPath, parentIssueId);
|
|
1629
|
+
const child = await getIssueById(dbPath, childIssueId);
|
|
1630
|
+
if (!parent || !child)
|
|
1631
|
+
return "not_found";
|
|
1632
|
+
const db = await getConnection(dbPath);
|
|
1633
|
+
db.run("DELETE FROM _issue_sub_issues WHERE parent_issue_id = ? AND child_issue_id = ?", [parentIssueId, childIssueId]);
|
|
1634
|
+
if (db.getRowsModified() === 0)
|
|
1635
|
+
return "not_found";
|
|
1636
|
+
const remaining = db.exec(`SELECT child_issue_id FROM _issue_sub_issues WHERE parent_issue_id = ${parentIssueId} ORDER BY position, child_issue_id`)[0]?.values ?? [];
|
|
1637
|
+
const compact = db.prepare("UPDATE _issue_sub_issues SET position = ? WHERE parent_issue_id = ? AND child_issue_id = ?");
|
|
1638
|
+
try {
|
|
1639
|
+
remaining.forEach((row, position) => compact.run([position, parentIssueId, Number(row[0])]));
|
|
1640
|
+
}
|
|
1641
|
+
finally {
|
|
1642
|
+
compact.free();
|
|
1643
|
+
}
|
|
1644
|
+
const now = new Date().toISOString();
|
|
1645
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id IN (?, ?)", [now, parentIssueId, childIssueId]);
|
|
1646
|
+
await insertIssueEvent(dbPath, parentIssueId, actorId, "sub_issue_removed", { childIssueId, childIssueNumber: child.issue_number });
|
|
1647
|
+
await insertIssueEvent(dbPath, childIssueId, actorId, "parent_removed", { parentIssueId, parentIssueNumber: parent.issue_number });
|
|
1648
|
+
return "removed";
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
async function reprioritizeIssueSubIssue(dbPath, parentIssueId, childIssueId, afterIssueId, actorId) {
|
|
1652
|
+
await ensureIssueTables(dbPath);
|
|
1653
|
+
return runDbTransaction(dbPath, async () => {
|
|
1654
|
+
if (childIssueId === afterIssueId)
|
|
1655
|
+
return "self_after";
|
|
1656
|
+
if (!await getIssueById(dbPath, parentIssueId))
|
|
1657
|
+
return "parent_not_found";
|
|
1658
|
+
const db = await getConnection(dbPath);
|
|
1659
|
+
const rows = db.exec(`
|
|
1660
|
+
SELECT child_issue_id FROM _issue_sub_issues
|
|
1661
|
+
WHERE parent_issue_id = ${parentIssueId}
|
|
1662
|
+
ORDER BY position, child_issue_id
|
|
1663
|
+
`)[0]?.values ?? [];
|
|
1664
|
+
const current = rows.map((row) => Number(row[0]));
|
|
1665
|
+
const currentIndex = current.indexOf(childIssueId);
|
|
1666
|
+
if (currentIndex < 0)
|
|
1667
|
+
return "child_not_found";
|
|
1668
|
+
const afterIndex = afterIssueId === null ? -1 : current.indexOf(afterIssueId);
|
|
1669
|
+
if (afterIssueId !== null && afterIndex < 0)
|
|
1670
|
+
return "after_not_found";
|
|
1671
|
+
const previousAfterIssueId = currentIndex === 0 ? null : current[currentIndex - 1];
|
|
1672
|
+
if (previousAfterIssueId === afterIssueId)
|
|
1673
|
+
return "unchanged";
|
|
1674
|
+
const reordered = current.filter((id) => id !== childIssueId);
|
|
1675
|
+
const insertionIndex = afterIssueId === null ? 0 : reordered.indexOf(afterIssueId) + 1;
|
|
1676
|
+
reordered.splice(insertionIndex, 0, childIssueId);
|
|
1677
|
+
const update = db.prepare("UPDATE _issue_sub_issues SET position = ? WHERE parent_issue_id = ? AND child_issue_id = ?");
|
|
1678
|
+
try {
|
|
1679
|
+
reordered.forEach((id, position) => { update.run([position, parentIssueId, id]); });
|
|
1680
|
+
}
|
|
1681
|
+
finally {
|
|
1682
|
+
update.free();
|
|
1683
|
+
}
|
|
1684
|
+
const now = new Date().toISOString();
|
|
1685
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id = ?", [now, parentIssueId]);
|
|
1686
|
+
await insertIssueEvent(dbPath, parentIssueId, actorId, "sub_issue_reordered", { childIssueId, afterIssueId, previousAfterIssueId, position: insertionIndex });
|
|
1687
|
+
return "reordered";
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
async function listIssueAncestorIds(dbPath, issueId) {
|
|
1691
|
+
await ensureIssueTables(dbPath);
|
|
1692
|
+
const db = await getConnection(dbPath);
|
|
1693
|
+
const ancestors = [];
|
|
1694
|
+
const visited = new Set([issueId]);
|
|
1695
|
+
let childId = issueId;
|
|
1696
|
+
for (let depth = 0; depth < exports.MAX_ISSUE_SUB_ISSUE_DEPTH; depth += 1) {
|
|
1697
|
+
const statement = db.prepare("SELECT parent_issue_id FROM _issue_sub_issues WHERE child_issue_id = ?");
|
|
1698
|
+
statement.bind([childId]);
|
|
1699
|
+
const parentId = statement.step() ? Number(statement.getAsObject().parent_issue_id) : null;
|
|
1700
|
+
statement.free();
|
|
1701
|
+
if (parentId === null || visited.has(parentId))
|
|
1702
|
+
break;
|
|
1703
|
+
ancestors.push(parentId);
|
|
1704
|
+
visited.add(parentId);
|
|
1705
|
+
childId = parentId;
|
|
1706
|
+
}
|
|
1707
|
+
return ancestors;
|
|
1708
|
+
}
|
|
1709
|
+
async function listIssueSubIssues(dbPath, parentIssueId) {
|
|
1710
|
+
await ensureIssueTables(dbPath);
|
|
1711
|
+
const db = await getConnection(dbPath);
|
|
1712
|
+
const items = [];
|
|
1713
|
+
const statement = db.prepare(`
|
|
1714
|
+
SELECT i.*, relation.position, relation.added_by, relation.created_at AS relation_created_at,
|
|
1715
|
+
COUNT(children.child_issue_id) AS child_count,
|
|
1716
|
+
COALESCE(SUM(CASE WHEN child_issue.status = 'closed' THEN 1 ELSE 0 END), 0) AS completed_child_count
|
|
1717
|
+
FROM _issue_sub_issues relation
|
|
1718
|
+
INNER JOIN _issues i ON i.id = relation.child_issue_id
|
|
1719
|
+
LEFT JOIN _issue_sub_issues children ON children.parent_issue_id = i.id
|
|
1720
|
+
LEFT JOIN _issues child_issue ON child_issue.id = children.child_issue_id
|
|
1721
|
+
WHERE relation.parent_issue_id = ?
|
|
1722
|
+
GROUP BY relation.parent_issue_id, relation.child_issue_id
|
|
1723
|
+
ORDER BY relation.position, i.issue_number`);
|
|
1724
|
+
statement.bind([parentIssueId]);
|
|
1725
|
+
while (statement.step()) {
|
|
1726
|
+
const item = statement.getAsObject();
|
|
1727
|
+
item.child_count = Number(item.child_count ?? 0);
|
|
1728
|
+
item.completed_child_count = Number(item.completed_child_count ?? 0);
|
|
1729
|
+
item.child_percent = item.child_count === 0 ? 0 : Math.round(item.completed_child_count / item.child_count * 100);
|
|
1730
|
+
const assignees = db.prepare("SELECT user_id FROM _issue_assignees WHERE issue_id = ? ORDER BY user_id");
|
|
1731
|
+
assignees.bind([item.id]);
|
|
1732
|
+
item.assignee_ids = [];
|
|
1733
|
+
while (assignees.step())
|
|
1734
|
+
item.assignee_ids.push(String(assignees.getAsObject().user_id));
|
|
1735
|
+
assignees.free();
|
|
1736
|
+
items.push(item);
|
|
1737
|
+
}
|
|
1738
|
+
statement.free();
|
|
1739
|
+
const completed = items.filter((item) => item.status === "closed").length;
|
|
1740
|
+
return { items, summary: { total: items.length, completed, percent: items.length === 0 ? 0 : Math.round(completed / items.length * 100) } };
|
|
1741
|
+
}
|
|
1742
|
+
class IssueTaskConversionAbort extends Error {
|
|
1743
|
+
result;
|
|
1744
|
+
constructor(result) {
|
|
1745
|
+
super(result.status);
|
|
1746
|
+
this.result = result;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
async function convertIssueTaskToSubIssue(dbPath, input) {
|
|
1750
|
+
await ensureIssueTables(dbPath);
|
|
1751
|
+
try {
|
|
1752
|
+
return await runDbTransaction(dbPath, async () => {
|
|
1753
|
+
const parent = await getIssueById(dbPath, input.parentIssueId);
|
|
1754
|
+
if (!parent)
|
|
1755
|
+
return { status: "not_found" };
|
|
1756
|
+
if (parent.updated_at !== input.expectedUpdatedAt)
|
|
1757
|
+
return { status: "content_conflict" };
|
|
1758
|
+
const task = (0, issue_task_conversion_js_1.collectConvertibleIssueTasks)(parent.description)[input.taskIndex];
|
|
1759
|
+
if (!task)
|
|
1760
|
+
return { status: "task_not_found" };
|
|
1761
|
+
if (!task.convertible)
|
|
1762
|
+
return { status: "task_not_convertible" };
|
|
1763
|
+
const title = (input.title ?? task.title).trim();
|
|
1764
|
+
if (!title || Array.from(title).length > 256)
|
|
1765
|
+
return { status: "title_invalid" };
|
|
1766
|
+
const child = await insertIssue(dbPath, title, "", "feature", input.actorId);
|
|
1767
|
+
await insertIssueEvent(dbPath, child.id, input.actorId, "opened", {});
|
|
1768
|
+
await setIssueSubscription(dbPath, child.id, input.actorId, true);
|
|
1769
|
+
const relation = await addIssueSubIssue(dbPath, input.parentIssueId, child.id, input.actorId, { joinTransaction: true });
|
|
1770
|
+
if (relation !== "added") {
|
|
1771
|
+
const result = relation === "not_found"
|
|
1772
|
+
? { status: "not_found" }
|
|
1773
|
+
: { status: "relation_conflict", reason: relation };
|
|
1774
|
+
throw new IssueTaskConversionAbort(result);
|
|
1775
|
+
}
|
|
1776
|
+
const description = (0, issue_task_conversion_js_1.replaceIssueTaskContent)(parent.description, input.taskIndex, `#${child.issueNumber}`);
|
|
1777
|
+
await insertIssueRevision(dbPath, {
|
|
1778
|
+
issueId: parent.id,
|
|
1779
|
+
targetType: "issue",
|
|
1780
|
+
targetId: parent.id,
|
|
1781
|
+
editorId: input.actorId,
|
|
1782
|
+
title: parent.title,
|
|
1783
|
+
body: parent.description,
|
|
1784
|
+
fields: ["description"],
|
|
1785
|
+
});
|
|
1786
|
+
await updateIssue(dbPath, parent.id, { description });
|
|
1787
|
+
const crossReferences = await reconcileIssueCrossReferences(dbPath, {
|
|
1788
|
+
sourceIssueId: parent.id,
|
|
1789
|
+
sourceType: "issue",
|
|
1790
|
+
sourceId: parent.id,
|
|
1791
|
+
actorId: input.actorId,
|
|
1792
|
+
markdown: description,
|
|
1793
|
+
});
|
|
1794
|
+
if (input.resolveMentionUserIds) {
|
|
1795
|
+
await replaceIssueMentions(dbPath, {
|
|
1796
|
+
issueId: parent.id,
|
|
1797
|
+
targetType: "issue",
|
|
1798
|
+
targetId: parent.id,
|
|
1799
|
+
userIds: await input.resolveMentionUserIds(`${parent.title}\n\n${description}`),
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
await insertIssueEvent(dbPath, parent.id, input.actorId, "task_converted_to_sub_issue", {
|
|
1803
|
+
taskIndex: input.taskIndex,
|
|
1804
|
+
childIssueId: child.id,
|
|
1805
|
+
childIssueNumber: child.issueNumber,
|
|
1806
|
+
});
|
|
1807
|
+
return {
|
|
1808
|
+
status: "converted",
|
|
1809
|
+
childIssueId: child.id,
|
|
1810
|
+
childIssueNumber: child.issueNumber,
|
|
1811
|
+
title,
|
|
1812
|
+
addedTargetIssueIds: crossReferences.addedTargetIssueIds,
|
|
1813
|
+
removedTargetIssueIds: crossReferences.removedTargetIssueIds,
|
|
1814
|
+
};
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
catch (error) {
|
|
1818
|
+
if (error instanceof IssueTaskConversionAbort)
|
|
1819
|
+
return error.result;
|
|
1820
|
+
throw error;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
exports.MAX_ISSUE_DEPENDENCIES = 100;
|
|
1824
|
+
async function addIssueDependency(dbPath, blockedIssueId, blockingIssueId, actorId) {
|
|
1825
|
+
await ensureIssueTables(dbPath);
|
|
1826
|
+
return runDbTransaction(dbPath, async () => {
|
|
1827
|
+
if (blockedIssueId === blockingIssueId)
|
|
1828
|
+
return "self_reference";
|
|
1829
|
+
const blockedIssue = await getIssueById(dbPath, blockedIssueId);
|
|
1830
|
+
const blockingIssue = await getIssueById(dbPath, blockingIssueId);
|
|
1831
|
+
if (!blockedIssue || !blockingIssue)
|
|
1832
|
+
return "not_found";
|
|
1833
|
+
const db = await getConnection(dbPath);
|
|
1834
|
+
const rows = db.exec("SELECT blocked_issue_id, blocking_issue_id FROM _issue_dependencies")[0]?.values ?? [];
|
|
1835
|
+
const blockedByBlocking = new Map();
|
|
1836
|
+
for (const row of rows) {
|
|
1837
|
+
const existingBlockedId = Number(row[0]);
|
|
1838
|
+
const existingBlockingId = Number(row[1]);
|
|
1839
|
+
if (existingBlockedId === blockedIssueId && existingBlockingId === blockingIssueId)
|
|
1840
|
+
return "duplicate";
|
|
1841
|
+
blockedByBlocking.set(existingBlockingId, [...(blockedByBlocking.get(existingBlockingId) ?? []), existingBlockedId]);
|
|
1842
|
+
}
|
|
1843
|
+
const reachesBlockingIssue = (issueId, visited = new Set()) => {
|
|
1844
|
+
if (issueId === blockingIssueId)
|
|
1845
|
+
return true;
|
|
1846
|
+
if (visited.has(issueId))
|
|
1847
|
+
return false;
|
|
1848
|
+
const nextVisited = new Set(visited).add(issueId);
|
|
1849
|
+
return (blockedByBlocking.get(issueId) ?? []).some((nextId) => reachesBlockingIssue(nextId, nextVisited));
|
|
1850
|
+
};
|
|
1851
|
+
if (reachesBlockingIssue(blockedIssueId))
|
|
1852
|
+
return "cycle";
|
|
1853
|
+
const blockedByCount = rows.filter((row) => Number(row[0]) === blockedIssueId).length;
|
|
1854
|
+
const blockingCount = rows.filter((row) => Number(row[1]) === blockingIssueId).length;
|
|
1855
|
+
if (blockedByCount >= exports.MAX_ISSUE_DEPENDENCIES || blockingCount >= exports.MAX_ISSUE_DEPENDENCIES)
|
|
1856
|
+
return "limit";
|
|
1857
|
+
const now = new Date().toISOString();
|
|
1858
|
+
db.run("INSERT INTO _issue_dependencies (blocked_issue_id, blocking_issue_id, added_by, created_at) VALUES (?, ?, ?, ?)", [blockedIssueId, blockingIssueId, actorId, now]);
|
|
1859
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id IN (?, ?)", [now, blockedIssueId, blockingIssueId]);
|
|
1860
|
+
await insertIssueEvent(dbPath, blockedIssueId, actorId, "dependency_blocked_by_added", {
|
|
1861
|
+
blockingIssueId,
|
|
1862
|
+
blockingIssueNumber: blockingIssue.issue_number,
|
|
1863
|
+
});
|
|
1864
|
+
await insertIssueEvent(dbPath, blockingIssueId, actorId, "dependency_blocking_added", {
|
|
1865
|
+
blockedIssueId,
|
|
1866
|
+
blockedIssueNumber: blockedIssue.issue_number,
|
|
1867
|
+
});
|
|
1868
|
+
return "added";
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
async function removeIssueDependency(dbPath, blockedIssueId, blockingIssueId, actorId) {
|
|
1872
|
+
await ensureIssueTables(dbPath);
|
|
1873
|
+
return runDbTransaction(dbPath, async () => {
|
|
1874
|
+
const blockedIssue = await getIssueById(dbPath, blockedIssueId);
|
|
1875
|
+
const blockingIssue = await getIssueById(dbPath, blockingIssueId);
|
|
1876
|
+
if (!blockedIssue || !blockingIssue)
|
|
1877
|
+
return "not_found";
|
|
1878
|
+
const db = await getConnection(dbPath);
|
|
1879
|
+
db.run("DELETE FROM _issue_dependencies WHERE blocked_issue_id = ? AND blocking_issue_id = ?", [blockedIssueId, blockingIssueId]);
|
|
1880
|
+
if (db.getRowsModified() === 0)
|
|
1881
|
+
return "not_found";
|
|
1882
|
+
const now = new Date().toISOString();
|
|
1883
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id IN (?, ?)", [now, blockedIssueId, blockingIssueId]);
|
|
1884
|
+
await insertIssueEvent(dbPath, blockedIssueId, actorId, "dependency_blocked_by_removed", {
|
|
1885
|
+
blockingIssueId,
|
|
1886
|
+
blockingIssueNumber: blockingIssue.issue_number,
|
|
1887
|
+
});
|
|
1888
|
+
await insertIssueEvent(dbPath, blockingIssueId, actorId, "dependency_blocking_removed", {
|
|
1889
|
+
blockedIssueId,
|
|
1890
|
+
blockedIssueNumber: blockedIssue.issue_number,
|
|
1891
|
+
});
|
|
1892
|
+
return "removed";
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
function parseIssueDuplicateReference(body) {
|
|
1896
|
+
for (const line of body.split(/\r?\n/)) {
|
|
1897
|
+
const match = line.match(/^\s*duplicate of #(\d+)\s*$/i);
|
|
1898
|
+
if (!match)
|
|
1899
|
+
continue;
|
|
1900
|
+
const issueNumber = Number(match[1]);
|
|
1901
|
+
if (Number.isSafeInteger(issueNumber) && issueNumber > 0)
|
|
1902
|
+
return issueNumber;
|
|
1903
|
+
}
|
|
1904
|
+
return null;
|
|
1905
|
+
}
|
|
1906
|
+
async function insertIssueDuplicateComment(dbPath, input) {
|
|
1907
|
+
await ensureIssueTables(dbPath);
|
|
1908
|
+
return runDbTransaction(dbPath, async () => {
|
|
1909
|
+
const duplicate = await getIssueById(dbPath, input.duplicateIssueId);
|
|
1910
|
+
const canonical = await getIssueByNumber(dbPath, input.canonicalIssueNumber);
|
|
1911
|
+
if (!duplicate || !canonical)
|
|
1912
|
+
return { status: "not_found" };
|
|
1913
|
+
if (duplicate.id === canonical.id)
|
|
1914
|
+
return { status: "self_reference" };
|
|
1915
|
+
const db = await getConnection(dbPath);
|
|
1916
|
+
const existing = db.prepare("SELECT canonical_issue_id FROM _issue_duplicates WHERE duplicate_issue_id = ?");
|
|
1917
|
+
existing.bind([duplicate.id]);
|
|
1918
|
+
const alreadyMarked = existing.step();
|
|
1919
|
+
existing.free();
|
|
1920
|
+
if (alreadyMarked)
|
|
1921
|
+
return { status: "already_marked" };
|
|
1922
|
+
const canonicalRelation = db.prepare("SELECT 1 FROM _issue_duplicates WHERE duplicate_issue_id = ?");
|
|
1923
|
+
canonicalRelation.bind([canonical.id]);
|
|
1924
|
+
const canonicalIsDuplicate = canonicalRelation.step();
|
|
1925
|
+
canonicalRelation.free();
|
|
1926
|
+
if (canonicalIsDuplicate)
|
|
1927
|
+
return { status: "canonical_is_duplicate" };
|
|
1928
|
+
const reverseRelation = db.prepare("SELECT 1 FROM _issue_duplicates WHERE canonical_issue_id = ?");
|
|
1929
|
+
reverseRelation.bind([duplicate.id]);
|
|
1930
|
+
const hasDuplicates = reverseRelation.step();
|
|
1931
|
+
reverseRelation.free();
|
|
1932
|
+
if (hasDuplicates)
|
|
1933
|
+
return { status: "has_duplicates" };
|
|
1934
|
+
const comment = await insertIssueComment(dbPath, duplicate.id, input.body, input.actorId);
|
|
1935
|
+
const now = new Date().toISOString();
|
|
1936
|
+
db.run("INSERT INTO _issue_duplicates (duplicate_issue_id, canonical_issue_id, marked_by, comment_id, created_at) VALUES (?, ?, ?, ?, ?)", [duplicate.id, canonical.id, input.actorId, comment.id, now]);
|
|
1937
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id IN (?, ?)", [now, duplicate.id, canonical.id]);
|
|
1938
|
+
const payload = {
|
|
1939
|
+
duplicateIssueId: duplicate.id,
|
|
1940
|
+
duplicateIssueNumber: duplicate.issue_number,
|
|
1941
|
+
canonicalIssueId: canonical.id,
|
|
1942
|
+
canonicalIssueNumber: canonical.issue_number,
|
|
1943
|
+
commentId: comment.id,
|
|
1944
|
+
};
|
|
1945
|
+
await insertIssueEvent(dbPath, duplicate.id, input.actorId, "marked_as_duplicate", payload);
|
|
1946
|
+
await insertIssueEvent(dbPath, canonical.id, input.actorId, "marked_as_duplicate", payload);
|
|
1947
|
+
return { status: "created", comment };
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
async function markIssueDuplicateWithComment(dbPath, input) {
|
|
1951
|
+
await ensureIssueTables(dbPath);
|
|
1952
|
+
const duplicate = await getIssueById(dbPath, input.duplicateIssueId);
|
|
1953
|
+
const canonical = await getIssueByNumber(dbPath, input.canonicalIssueNumber);
|
|
1954
|
+
if (!duplicate || !canonical)
|
|
1955
|
+
return "not_found";
|
|
1956
|
+
if (duplicate.id === canonical.id)
|
|
1957
|
+
return "self_reference";
|
|
1958
|
+
const db = await getConnection(dbPath);
|
|
1959
|
+
const hasRow = (sql, value) => {
|
|
1960
|
+
const stmt = db.prepare(sql);
|
|
1961
|
+
stmt.bind([value]);
|
|
1962
|
+
const found = stmt.step();
|
|
1963
|
+
stmt.free();
|
|
1964
|
+
return found;
|
|
1965
|
+
};
|
|
1966
|
+
if (hasRow("SELECT 1 FROM _issue_duplicates WHERE duplicate_issue_id = ?", duplicate.id))
|
|
1967
|
+
return "already_marked";
|
|
1968
|
+
if (hasRow("SELECT 1 FROM _issue_duplicates WHERE duplicate_issue_id = ?", canonical.id))
|
|
1969
|
+
return "canonical_is_duplicate";
|
|
1970
|
+
if (hasRow("SELECT 1 FROM _issue_duplicates WHERE canonical_issue_id = ?", duplicate.id))
|
|
1971
|
+
return "has_duplicates";
|
|
1972
|
+
const now = new Date().toISOString();
|
|
1973
|
+
db.run("INSERT INTO _issue_duplicates (duplicate_issue_id, canonical_issue_id, marked_by, comment_id, created_at) VALUES (?, ?, ?, ?, ?)", [duplicate.id, canonical.id, input.actorId, input.commentId, now]);
|
|
1974
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id IN (?, ?)", [now, duplicate.id, canonical.id]);
|
|
1975
|
+
const payload = {
|
|
1976
|
+
duplicateIssueId: duplicate.id,
|
|
1977
|
+
duplicateIssueNumber: duplicate.issue_number,
|
|
1978
|
+
canonicalIssueId: canonical.id,
|
|
1979
|
+
canonicalIssueNumber: canonical.issue_number,
|
|
1980
|
+
commentId: input.commentId,
|
|
1981
|
+
};
|
|
1982
|
+
await insertIssueEvent(dbPath, duplicate.id, input.actorId, "marked_as_duplicate", payload);
|
|
1983
|
+
await insertIssueEvent(dbPath, canonical.id, input.actorId, "marked_as_duplicate", payload);
|
|
1984
|
+
return "created";
|
|
1985
|
+
}
|
|
1986
|
+
async function unmarkIssueDuplicate(dbPath, duplicateIssueId, canonicalIssueId, actorId) {
|
|
1987
|
+
await ensureIssueTables(dbPath);
|
|
1988
|
+
return runDbTransaction(dbPath, async () => {
|
|
1989
|
+
const duplicate = await getIssueById(dbPath, duplicateIssueId);
|
|
1990
|
+
const canonical = await getIssueById(dbPath, canonicalIssueId);
|
|
1991
|
+
if (!duplicate || !canonical)
|
|
1992
|
+
return "not_found";
|
|
1993
|
+
const db = await getConnection(dbPath);
|
|
1994
|
+
db.run("DELETE FROM _issue_duplicates WHERE duplicate_issue_id = ? AND canonical_issue_id = ?", [duplicateIssueId, canonicalIssueId]);
|
|
1995
|
+
if (db.getRowsModified() === 0)
|
|
1996
|
+
return "not_found";
|
|
1997
|
+
const now = new Date().toISOString();
|
|
1998
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id IN (?, ?)", [now, duplicateIssueId, canonicalIssueId]);
|
|
1999
|
+
const payload = {
|
|
2000
|
+
duplicateIssueId,
|
|
2001
|
+
duplicateIssueNumber: duplicate.issue_number,
|
|
2002
|
+
canonicalIssueId,
|
|
2003
|
+
canonicalIssueNumber: canonical.issue_number,
|
|
2004
|
+
};
|
|
2005
|
+
await insertIssueEvent(dbPath, duplicateIssueId, actorId, "unmarked_as_duplicate", payload);
|
|
2006
|
+
await insertIssueEvent(dbPath, canonicalIssueId, actorId, "unmarked_as_duplicate", payload);
|
|
2007
|
+
return "removed";
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
async function insertIssueComment(dbPath, issueId, body, authorId) {
|
|
2011
|
+
await ensureIssueTables(dbPath);
|
|
2012
|
+
const db = await getConnection(dbPath);
|
|
2013
|
+
const now = new Date().toISOString();
|
|
2014
|
+
db.run("INSERT INTO _issue_comments (issue_id, body, author_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?)", [issueId, body, authorId, now, now]);
|
|
2015
|
+
const id = db.exec("SELECT last_insert_rowid()")[0]?.values[0]?.[0] ?? 0;
|
|
2016
|
+
markDirty(dbPath);
|
|
2017
|
+
saveConnection(dbPath);
|
|
2018
|
+
return (await getIssueComment(dbPath, id));
|
|
2019
|
+
}
|
|
2020
|
+
function extractIssueReferenceNumbers(markdown) {
|
|
2021
|
+
const withoutFencedCode = markdown.replace(/(^|\n)[ \t]*(```|~~~)[^\n]*\n[\s\S]*?\n[ \t]*\2(?=\n|$)/g, "$1");
|
|
2022
|
+
const withoutInlineCode = withoutFencedCode.replace(/`+[^`\n]*`+/g, "");
|
|
2023
|
+
const references = new Set();
|
|
2024
|
+
for (const match of withoutInlineCode.matchAll(/(^|[^\\\p{L}\p{N}_])#([1-9]\d*)\b/gu)) {
|
|
2025
|
+
const issueNumber = Number(match[2]);
|
|
2026
|
+
if (Number.isSafeInteger(issueNumber))
|
|
2027
|
+
references.add(issueNumber);
|
|
2028
|
+
}
|
|
2029
|
+
return [...references];
|
|
2030
|
+
}
|
|
2031
|
+
async function reconcileIssueCrossReferences(dbPath, input) {
|
|
2032
|
+
await ensureIssueTables(dbPath);
|
|
2033
|
+
const sourceIssue = await getIssueById(dbPath, input.sourceIssueId);
|
|
2034
|
+
if (!sourceIssue || (input.sourceType === "issue" && input.sourceId !== input.sourceIssueId))
|
|
2035
|
+
throw new Error("Issue cross-reference source not found");
|
|
2036
|
+
if (input.sourceType === "comment") {
|
|
2037
|
+
const comment = await getIssueComment(dbPath, input.sourceId);
|
|
2038
|
+
if (!comment || comment.issue_id !== input.sourceIssueId || comment.deleted_at)
|
|
2039
|
+
throw new Error("Issue cross-reference source not found");
|
|
2040
|
+
}
|
|
2041
|
+
const desiredTargetIds = new Set();
|
|
2042
|
+
for (const issueNumber of extractIssueReferenceNumbers(input.markdown)) {
|
|
2043
|
+
const target = await getIssueByNumber(dbPath, issueNumber);
|
|
2044
|
+
if (target && target.id !== input.sourceIssueId)
|
|
2045
|
+
desiredTargetIds.add(target.id);
|
|
2046
|
+
}
|
|
2047
|
+
const db = await getConnection(dbPath);
|
|
2048
|
+
const existingTargetIds = new Set();
|
|
2049
|
+
const existingStmt = db.prepare("SELECT target_issue_id FROM _issue_cross_references WHERE source_type = ? AND source_id = ?");
|
|
2050
|
+
existingStmt.bind([input.sourceType, input.sourceId]);
|
|
2051
|
+
while (existingStmt.step())
|
|
2052
|
+
existingTargetIds.add(Number(existingStmt.getAsObject().target_issue_id));
|
|
2053
|
+
existingStmt.free();
|
|
2054
|
+
const addedTargetIssueIds = [...desiredTargetIds].filter((id) => !existingTargetIds.has(id)).sort((a, b) => a - b);
|
|
2055
|
+
const removedTargetIssueIds = [...existingTargetIds].filter((id) => !desiredTargetIds.has(id)).sort((a, b) => a - b);
|
|
2056
|
+
const now = new Date().toISOString();
|
|
2057
|
+
for (const targetIssueId of removedTargetIssueIds) {
|
|
2058
|
+
db.run("DELETE FROM _issue_cross_references WHERE source_type = ? AND source_id = ? AND target_issue_id = ?", [input.sourceType, input.sourceId, targetIssueId]);
|
|
2059
|
+
}
|
|
2060
|
+
for (const targetIssueId of addedTargetIssueIds) {
|
|
2061
|
+
db.run(`INSERT OR IGNORE INTO _issue_cross_references
|
|
2062
|
+
(target_issue_id, source_issue_id, source_type, source_id, actor_id, created_at, updated_at)
|
|
2063
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`, [targetIssueId, input.sourceIssueId, input.sourceType, input.sourceId, input.actorId, now, now]);
|
|
2064
|
+
}
|
|
2065
|
+
if (addedTargetIssueIds.length > 0 || removedTargetIssueIds.length > 0) {
|
|
2066
|
+
markDirty(dbPath);
|
|
2067
|
+
saveConnection(dbPath);
|
|
2068
|
+
}
|
|
2069
|
+
return { addedTargetIssueIds, removedTargetIssueIds };
|
|
2070
|
+
}
|
|
2071
|
+
async function updateIssueComment(dbPath, commentId, body, authorId) {
|
|
2072
|
+
await ensureIssueTables(dbPath);
|
|
2073
|
+
const db = await getConnection(dbPath);
|
|
2074
|
+
db.run("UPDATE _issue_comments SET body = ?, updated_at = ? WHERE id = ? AND author_id = ? AND deleted_at IS NULL", [body, new Date().toISOString(), commentId, authorId]);
|
|
2075
|
+
if (db.getRowsModified() === 0)
|
|
2076
|
+
return null;
|
|
2077
|
+
markDirty(dbPath);
|
|
2078
|
+
saveConnection(dbPath);
|
|
2079
|
+
return getIssueComment(dbPath, commentId);
|
|
2080
|
+
}
|
|
2081
|
+
async function setIssueCommentPin(dbPath, issueId, commentId, actorId, pinned) {
|
|
2082
|
+
await ensureIssueTables(dbPath);
|
|
2083
|
+
return runDbTransaction(dbPath, async () => {
|
|
2084
|
+
const db = await getConnection(dbPath);
|
|
2085
|
+
const comment = await getIssueComment(dbPath, commentId);
|
|
2086
|
+
if (!comment || comment.issue_id !== issueId || comment.deleted_at)
|
|
2087
|
+
return "not_found";
|
|
2088
|
+
if (pinned && comment.pinned_at)
|
|
2089
|
+
return "unchanged";
|
|
2090
|
+
if (!pinned && !comment.pinned_at)
|
|
2091
|
+
return "unchanged";
|
|
2092
|
+
if (pinned) {
|
|
2093
|
+
const pinnedStmt = db.prepare("SELECT id FROM _issue_comments WHERE issue_id = ? AND pinned_at IS NOT NULL AND deleted_at IS NULL LIMIT 1");
|
|
2094
|
+
pinnedStmt.bind([issueId]);
|
|
2095
|
+
const existingPinnedId = pinnedStmt.step() ? Number(pinnedStmt.getAsObject().id) : null;
|
|
2096
|
+
pinnedStmt.free();
|
|
2097
|
+
if (existingPinnedId !== null && existingPinnedId !== commentId)
|
|
2098
|
+
return "conflict";
|
|
2099
|
+
}
|
|
2100
|
+
const now = new Date().toISOString();
|
|
2101
|
+
db.run("UPDATE _issue_comments SET pinned_at = ?, pinned_by = ? WHERE id = ? AND issue_id = ? AND deleted_at IS NULL", [pinned ? now : null, pinned ? actorId : null, commentId, issueId]);
|
|
2102
|
+
if (db.getRowsModified() === 0)
|
|
2103
|
+
return "not_found";
|
|
2104
|
+
await insertIssueEvent(dbPath, issueId, actorId, pinned ? "comment_pinned" : "comment_unpinned", { commentId });
|
|
2105
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id = ?", [now, issueId]);
|
|
2106
|
+
markDirty(dbPath);
|
|
2107
|
+
saveConnection(dbPath);
|
|
2108
|
+
return pinned ? "pinned" : "unpinned";
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
async function setIssueCommentMinimized(dbPath, issueId, commentId, actorId, reason) {
|
|
2112
|
+
await ensureIssueTables(dbPath);
|
|
2113
|
+
if (reason !== null && !isIssueCommentMinimizedReason(reason))
|
|
2114
|
+
return "invalid_reason";
|
|
2115
|
+
return runDbTransaction(dbPath, async () => {
|
|
2116
|
+
const db = await getConnection(dbPath);
|
|
2117
|
+
const comment = await getIssueComment(dbPath, commentId);
|
|
2118
|
+
if (!comment || comment.issue_id !== issueId || comment.deleted_at)
|
|
2119
|
+
return "not_found";
|
|
2120
|
+
if (reason !== null && comment.pinned_at)
|
|
2121
|
+
return "pinned_conflict";
|
|
2122
|
+
if (reason !== null && comment.minimized_at && comment.minimized_reason === reason)
|
|
2123
|
+
return "unchanged";
|
|
2124
|
+
if (reason === null && !comment.minimized_at)
|
|
2125
|
+
return "unchanged";
|
|
2126
|
+
const now = new Date().toISOString();
|
|
2127
|
+
db.run("UPDATE _issue_comments SET minimized_at = ?, minimized_by = ?, minimized_reason = ? WHERE id = ? AND issue_id = ? AND deleted_at IS NULL", [reason === null ? null : now, reason === null ? null : actorId, reason, commentId, issueId]);
|
|
2128
|
+
if (db.getRowsModified() === 0)
|
|
2129
|
+
return "not_found";
|
|
2130
|
+
await insertIssueEvent(dbPath, issueId, actorId, reason === null ? "comment_unminimized" : "comment_minimized", {
|
|
2131
|
+
commentId,
|
|
2132
|
+
...(reason === null ? {} : { reason }),
|
|
2133
|
+
});
|
|
2134
|
+
db.run("UPDATE _issues SET updated_at = ? WHERE id = ?", [now, issueId]);
|
|
2135
|
+
markDirty(dbPath);
|
|
2136
|
+
saveConnection(dbPath);
|
|
2137
|
+
return reason === null ? "unminimized" : "minimized";
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
async function insertIssueRevision(dbPath, input) {
|
|
2141
|
+
await ensureIssueTables(dbPath);
|
|
2142
|
+
const issue = await getIssueById(dbPath, input.issueId);
|
|
2143
|
+
if (!issue || (input.targetType === "issue" && input.targetId !== input.issueId)) {
|
|
2144
|
+
throw new Error("Issue revision target not found");
|
|
2145
|
+
}
|
|
2146
|
+
if (input.targetType === "comment") {
|
|
2147
|
+
const comment = await getIssueComment(dbPath, input.targetId);
|
|
2148
|
+
if (!comment || comment.issue_id !== input.issueId)
|
|
2149
|
+
throw new Error("Issue revision target not found");
|
|
2150
|
+
}
|
|
2151
|
+
const fields = [...new Set(input.fields)].filter(Boolean);
|
|
2152
|
+
if (fields.length === 0)
|
|
2153
|
+
throw new Error("Issue revision fields are required");
|
|
2154
|
+
const db = await getConnection(dbPath);
|
|
2155
|
+
db.run(`INSERT INTO _issue_revisions
|
|
2156
|
+
(issue_id, target_type, target_id, editor_id, title, body, fields_json, created_at)
|
|
2157
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [input.issueId, input.targetType, input.targetId, input.editorId, input.title ?? null, input.body, JSON.stringify(fields), new Date().toISOString()]);
|
|
2158
|
+
const id = db.exec("SELECT last_insert_rowid()")[0]?.values[0]?.[0] ?? 0;
|
|
2159
|
+
const stmt = db.prepare("SELECT * FROM _issue_revisions WHERE id = ?");
|
|
2160
|
+
stmt.bind([id]);
|
|
2161
|
+
const revision = stmt.step() ? stmt.getAsObject() : null;
|
|
2162
|
+
stmt.free();
|
|
2163
|
+
markDirty(dbPath);
|
|
2164
|
+
saveConnection(dbPath);
|
|
2165
|
+
return revision;
|
|
2166
|
+
}
|
|
2167
|
+
async function listIssueRevisions(dbPath, issueId, targetType, targetId) {
|
|
2168
|
+
await ensureIssueTables(dbPath);
|
|
2169
|
+
const db = await getConnection(dbPath);
|
|
2170
|
+
const stmt = db.prepare(`SELECT * FROM _issue_revisions
|
|
2171
|
+
WHERE issue_id = ? AND target_type = ? AND target_id = ?
|
|
2172
|
+
ORDER BY created_at DESC, id DESC`);
|
|
2173
|
+
stmt.bind([issueId, targetType, targetId]);
|
|
2174
|
+
const revisions = [];
|
|
2175
|
+
while (stmt.step())
|
|
2176
|
+
revisions.push(stmt.getAsObject());
|
|
2177
|
+
stmt.free();
|
|
2178
|
+
return revisions;
|
|
2179
|
+
}
|
|
2180
|
+
async function deleteIssueComment(dbPath, commentId, authorId) {
|
|
2181
|
+
await ensureIssueTables(dbPath);
|
|
2182
|
+
const db = await getConnection(dbPath);
|
|
2183
|
+
const now = new Date().toISOString();
|
|
2184
|
+
db.run("UPDATE _issue_comments SET body = '', deleted_at = ?, updated_at = ?, pinned_at = NULL, pinned_by = NULL, minimized_at = NULL, minimized_by = NULL, minimized_reason = NULL WHERE id = ? AND author_id = ? AND deleted_at IS NULL", [now, now, commentId, authorId]);
|
|
2185
|
+
const changed = db.getRowsModified() > 0;
|
|
2186
|
+
if (changed) {
|
|
2187
|
+
db.run("DELETE FROM _issue_mentions WHERE target_type = 'comment' AND target_id = ?", [commentId]);
|
|
2188
|
+
markDirty(dbPath);
|
|
2189
|
+
saveConnection(dbPath);
|
|
2190
|
+
}
|
|
2191
|
+
return changed;
|
|
2192
|
+
}
|
|
2193
|
+
async function deleteIssue(dbPath, issueId) {
|
|
2194
|
+
await ensureIssueTables(dbPath);
|
|
2195
|
+
const db = await getConnection(dbPath);
|
|
2196
|
+
const issue = await getIssueById(dbPath, issueId);
|
|
2197
|
+
if (!issue)
|
|
2198
|
+
return null;
|
|
2199
|
+
const attachmentStmt = db.prepare("SELECT * FROM _issue_attachments WHERE issue_id = ? AND deleted_at IS NULL ORDER BY created_at, id");
|
|
2200
|
+
attachmentStmt.bind([issueId]);
|
|
2201
|
+
const attachments = [];
|
|
2202
|
+
while (attachmentStmt.step())
|
|
2203
|
+
attachments.push(attachmentStmt.getAsObject());
|
|
2204
|
+
attachmentStmt.free();
|
|
2205
|
+
db.run("DELETE FROM _issues WHERE id = ?", [issueId]);
|
|
2206
|
+
for (const table of [
|
|
2207
|
+
"_issue_comments", "_issue_events", "_issue_attachments", "_issue_label_links",
|
|
2208
|
+
"_issue_assignees", "_issue_subscriptions", "_issue_mentions", "_issue_reactions", "_issue_revisions",
|
|
2209
|
+
])
|
|
2210
|
+
db.run(`DELETE FROM ${table} WHERE issue_id = ?`, [issueId]);
|
|
2211
|
+
db.run("DELETE FROM _issue_sub_issues WHERE parent_issue_id = ? OR child_issue_id = ?", [issueId, issueId]);
|
|
2212
|
+
db.run("DELETE FROM _issue_dependencies WHERE blocked_issue_id = ? OR blocking_issue_id = ?", [issueId, issueId]);
|
|
2213
|
+
db.run("DELETE FROM _issue_duplicates WHERE duplicate_issue_id = ? OR canonical_issue_id = ?", [issueId, issueId]);
|
|
2214
|
+
db.run("DELETE FROM _issue_cross_references WHERE source_issue_id = ? OR target_issue_id = ?", [issueId, issueId]);
|
|
2215
|
+
markDirty(dbPath);
|
|
2216
|
+
saveConnection(dbPath);
|
|
2217
|
+
return attachments;
|
|
2218
|
+
}
|
|
2219
|
+
async function replaceIssueMentions(dbPath, input) {
|
|
2220
|
+
await ensureIssueTables(dbPath);
|
|
2221
|
+
const issue = await getIssueById(dbPath, input.issueId);
|
|
2222
|
+
if (!issue || (input.targetType === "issue" && input.targetId !== input.issueId))
|
|
2223
|
+
throw new Error("Issue mention target not found");
|
|
2224
|
+
if (input.targetType === "comment") {
|
|
2225
|
+
const comment = await getIssueComment(dbPath, input.targetId);
|
|
2226
|
+
if (!comment || comment.issue_id !== input.issueId || comment.deleted_at)
|
|
2227
|
+
throw new Error("Issue mention target not found");
|
|
2228
|
+
}
|
|
2229
|
+
const userIds = [...new Set(input.userIds.map((userId) => userId.trim()).filter(Boolean))];
|
|
2230
|
+
const db = await getConnection(dbPath);
|
|
2231
|
+
db.run("DELETE FROM _issue_mentions WHERE target_type = ? AND target_id = ?", [input.targetType, input.targetId]);
|
|
2232
|
+
const now = new Date().toISOString();
|
|
2233
|
+
for (const userId of userIds) {
|
|
2234
|
+
db.run("INSERT INTO _issue_mentions (issue_id, target_type, target_id, user_id, created_at) VALUES (?, ?, ?, ?, ?)", [input.issueId, input.targetType, input.targetId, userId, now]);
|
|
2235
|
+
}
|
|
2236
|
+
markDirty(dbPath);
|
|
2237
|
+
saveConnection(dbPath);
|
|
2238
|
+
}
|
|
2239
|
+
async function setIssueReaction(dbPath, input) {
|
|
2240
|
+
if (!isIssueReactionContent(input.content))
|
|
2241
|
+
throw new RangeError("Invalid Issue reaction content");
|
|
2242
|
+
const issue = await getIssueById(dbPath, input.issueId);
|
|
2243
|
+
if (!issue)
|
|
2244
|
+
return "target_not_found";
|
|
2245
|
+
const commentId = input.commentId ?? 0;
|
|
2246
|
+
if (commentId !== 0) {
|
|
2247
|
+
const comment = await getIssueComment(dbPath, commentId);
|
|
2248
|
+
if (!comment || comment.issue_id !== input.issueId || comment.deleted_at !== null)
|
|
2249
|
+
return "target_not_found";
|
|
2250
|
+
}
|
|
2251
|
+
const db = await getConnection(dbPath);
|
|
2252
|
+
if (input.reacted) {
|
|
2253
|
+
db.run(`INSERT OR IGNORE INTO _issue_reactions (issue_id, comment_id, user_id, content, created_at)
|
|
2254
|
+
VALUES (?, ?, ?, ?, ?)`, [input.issueId, commentId, input.userId, input.content, new Date().toISOString()]);
|
|
2255
|
+
}
|
|
2256
|
+
else {
|
|
2257
|
+
db.run("DELETE FROM _issue_reactions WHERE issue_id = ? AND comment_id = ? AND user_id = ? AND content = ?", [input.issueId, commentId, input.userId, input.content]);
|
|
2258
|
+
}
|
|
2259
|
+
if (db.getRowsModified() === 0)
|
|
2260
|
+
return "unchanged";
|
|
2261
|
+
markDirty(dbPath);
|
|
2262
|
+
saveConnection(dbPath);
|
|
2263
|
+
return "changed";
|
|
2264
|
+
}
|
|
2265
|
+
async function insertIssueEvent(dbPath, issueId, actorId, eventType, payload = {}) {
|
|
2266
|
+
await ensureIssueTables(dbPath);
|
|
2267
|
+
const db = await getConnection(dbPath);
|
|
2268
|
+
db.run("INSERT INTO _issue_events (issue_id, actor_id, event_type, payload_json, created_at) VALUES (?, ?, ?, ?, ?)", [issueId, actorId, eventType, JSON.stringify(payload), new Date().toISOString()]);
|
|
2269
|
+
const id = db.exec("SELECT last_insert_rowid()")[0]?.values[0]?.[0] ?? 0;
|
|
2270
|
+
const stmt = db.prepare("SELECT * FROM _issue_events WHERE id = ?");
|
|
2271
|
+
stmt.bind([id]);
|
|
2272
|
+
const row = stmt.step() ? stmt.getAsObject() : null;
|
|
2273
|
+
stmt.free();
|
|
2274
|
+
markDirty(dbPath);
|
|
2275
|
+
saveConnection(dbPath);
|
|
2276
|
+
return row;
|
|
2277
|
+
}
|
|
2278
|
+
exports.MAX_ISSUE_DRAFT_ATTACHMENTS = 20;
|
|
2279
|
+
class IssueAttachmentDraftLimitError extends Error {
|
|
2280
|
+
constructor() {
|
|
2281
|
+
super(`Each Issue draft supports at most ${exports.MAX_ISSUE_DRAFT_ATTACHMENTS} attachments`);
|
|
2282
|
+
this.name = "IssueAttachmentDraftLimitError";
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
exports.IssueAttachmentDraftLimitError = IssueAttachmentDraftLimitError;
|
|
2286
|
+
async function insertIssueAttachment(dbPath, input) {
|
|
2287
|
+
await ensureIssueTables(dbPath);
|
|
2288
|
+
const db = await getConnection(dbPath);
|
|
2289
|
+
const countStmt = db.prepare(`SELECT COUNT(*) AS count FROM _issue_attachments
|
|
2290
|
+
WHERE page_path = ? AND draft_id = ? AND uploader_id = ?
|
|
2291
|
+
AND issue_id IS NULL AND comment_id IS NULL AND bound_at IS NULL AND deleted_at IS NULL`);
|
|
2292
|
+
countStmt.bind([input.pagePath, input.draftId, input.uploaderId]);
|
|
2293
|
+
const count = countStmt.step() ? Number(countStmt.getAsObject().count ?? 0) : 0;
|
|
2294
|
+
countStmt.free();
|
|
2295
|
+
if (count >= exports.MAX_ISSUE_DRAFT_ATTACHMENTS)
|
|
2296
|
+
throw new IssueAttachmentDraftLimitError();
|
|
2297
|
+
db.run(`INSERT INTO _issue_attachments
|
|
2298
|
+
(id, page_path, draft_id, uploader_id, storage_key, file_name, mime_type, size_bytes, created_at)
|
|
2299
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, [input.id, input.pagePath, input.draftId, input.uploaderId, input.storageKey, input.fileName, input.mimeType, input.sizeBytes, new Date().toISOString()]);
|
|
2300
|
+
markDirty(dbPath);
|
|
2301
|
+
saveConnection(dbPath);
|
|
2302
|
+
return (await getIssueAttachment(dbPath, input.id));
|
|
2303
|
+
}
|
|
2304
|
+
async function getIssueAttachment(dbPath, attachmentId) {
|
|
2305
|
+
await ensureIssueTables(dbPath);
|
|
2306
|
+
const db = await getConnection(dbPath);
|
|
2307
|
+
const stmt = db.prepare("SELECT * FROM _issue_attachments WHERE id = ? AND deleted_at IS NULL");
|
|
2308
|
+
stmt.bind([attachmentId]);
|
|
2309
|
+
const row = stmt.step() ? stmt.getAsObject() : null;
|
|
2310
|
+
stmt.free();
|
|
2311
|
+
return row;
|
|
2312
|
+
}
|
|
2313
|
+
async function listExpiredUnboundIssueAttachments(dbPath, createdBefore) {
|
|
2314
|
+
await ensureIssueTables(dbPath);
|
|
2315
|
+
const db = await getConnection(dbPath);
|
|
2316
|
+
const stmt = db.prepare(`SELECT * FROM _issue_attachments
|
|
2317
|
+
WHERE issue_id IS NULL AND bound_at IS NULL AND deleted_at IS NULL AND created_at < ?
|
|
2318
|
+
ORDER BY created_at, id`);
|
|
2319
|
+
stmt.bind([createdBefore]);
|
|
2320
|
+
const attachments = [];
|
|
2321
|
+
while (stmt.step())
|
|
2322
|
+
attachments.push(stmt.getAsObject());
|
|
2323
|
+
stmt.free();
|
|
2324
|
+
return attachments;
|
|
2325
|
+
}
|
|
2326
|
+
async function deleteIssueAttachmentMetadata(dbPath, attachmentId) {
|
|
2327
|
+
await ensureIssueTables(dbPath);
|
|
2328
|
+
const db = await getConnection(dbPath);
|
|
2329
|
+
db.run("UPDATE _issue_attachments SET deleted_at = ? WHERE id = ? AND issue_id IS NULL AND deleted_at IS NULL", [new Date().toISOString(), attachmentId]);
|
|
2330
|
+
const changed = db.getRowsModified() > 0;
|
|
2331
|
+
if (changed) {
|
|
2332
|
+
markDirty(dbPath);
|
|
2333
|
+
saveConnection(dbPath);
|
|
2334
|
+
}
|
|
2335
|
+
return changed;
|
|
2336
|
+
}
|
|
2337
|
+
async function releaseUnboundIssueAttachment(dbPath, input) {
|
|
2338
|
+
await ensureIssueTables(dbPath);
|
|
2339
|
+
const db = await getConnection(dbPath);
|
|
2340
|
+
const stmt = db.prepare(`SELECT * FROM _issue_attachments
|
|
2341
|
+
WHERE id = ? AND page_path = ? AND draft_id = ? AND uploader_id = ?
|
|
2342
|
+
AND issue_id IS NULL AND comment_id IS NULL AND bound_at IS NULL AND deleted_at IS NULL`);
|
|
2343
|
+
stmt.bind([input.attachmentId, input.pagePath, input.draftId, input.uploaderId]);
|
|
2344
|
+
const attachment = stmt.step() ? stmt.getAsObject() : null;
|
|
2345
|
+
stmt.free();
|
|
2346
|
+
if (!attachment)
|
|
2347
|
+
return null;
|
|
2348
|
+
const deletedAt = new Date().toISOString();
|
|
2349
|
+
db.run(`UPDATE _issue_attachments SET deleted_at = ?
|
|
2350
|
+
WHERE id = ? AND page_path = ? AND draft_id = ? AND uploader_id = ?
|
|
2351
|
+
AND issue_id IS NULL AND comment_id IS NULL AND bound_at IS NULL AND deleted_at IS NULL`, [deletedAt, input.attachmentId, input.pagePath, input.draftId, input.uploaderId]);
|
|
2352
|
+
if (db.getRowsModified() === 0)
|
|
2353
|
+
return null;
|
|
2354
|
+
markDirty(dbPath);
|
|
2355
|
+
saveConnection(dbPath);
|
|
2356
|
+
return { ...attachment, deleted_at: deletedAt };
|
|
2357
|
+
}
|
|
2358
|
+
async function restoreReleasedIssueAttachment(dbPath, input) {
|
|
2359
|
+
await ensureIssueTables(dbPath);
|
|
2360
|
+
const db = await getConnection(dbPath);
|
|
2361
|
+
db.run(`UPDATE _issue_attachments SET deleted_at = NULL
|
|
2362
|
+
WHERE id = ? AND page_path = ? AND draft_id = ? AND uploader_id = ? AND deleted_at = ?
|
|
2363
|
+
AND issue_id IS NULL AND comment_id IS NULL AND bound_at IS NULL`, [input.attachmentId, input.pagePath, input.draftId, input.uploaderId, input.releaseDeletedAt]);
|
|
2364
|
+
const changed = db.getRowsModified() > 0;
|
|
2365
|
+
if (changed) {
|
|
2366
|
+
markDirty(dbPath);
|
|
2367
|
+
saveConnection(dbPath);
|
|
2368
|
+
}
|
|
2369
|
+
return changed;
|
|
2370
|
+
}
|
|
2371
|
+
async function deleteBoundIssueAttachments(dbPath, input) {
|
|
2372
|
+
const attachmentIds = Array.from(new Set(input.attachmentIds));
|
|
2373
|
+
if (attachmentIds.length === 0)
|
|
2374
|
+
return true;
|
|
2375
|
+
await ensureIssueTables(dbPath);
|
|
2376
|
+
const db = await getConnection(dbPath);
|
|
2377
|
+
const deletedAt = new Date().toISOString();
|
|
2378
|
+
let changed = 0;
|
|
2379
|
+
for (const attachmentId of attachmentIds) {
|
|
2380
|
+
db.run("UPDATE _issue_attachments SET deleted_at = ? WHERE id = ? AND issue_id = ? AND comment_id IS ? AND deleted_at IS NULL", [deletedAt, attachmentId, input.issueId, input.commentId]);
|
|
2381
|
+
changed += db.getRowsModified();
|
|
2382
|
+
}
|
|
2383
|
+
if (changed > 0) {
|
|
2384
|
+
markDirty(dbPath);
|
|
2385
|
+
saveConnection(dbPath);
|
|
2386
|
+
}
|
|
2387
|
+
return changed === attachmentIds.length;
|
|
2388
|
+
}
|
|
2389
|
+
async function bindIssueAttachments(dbPath, input) {
|
|
2390
|
+
if (input.attachmentIds.length === 0)
|
|
2391
|
+
return [];
|
|
2392
|
+
const attachmentIds = [...new Set(input.attachmentIds)];
|
|
2393
|
+
if (attachmentIds.length !== input.attachmentIds.length)
|
|
2394
|
+
return [];
|
|
2395
|
+
await ensureIssueTables(dbPath);
|
|
2396
|
+
const db = await getConnection(dbPath);
|
|
2397
|
+
const placeholders = attachmentIds.map(() => "?").join(", ");
|
|
2398
|
+
const pagePathCondition = input.pagePath === undefined ? "" : " AND page_path = ?";
|
|
2399
|
+
const eligibleStmt = db.prepare(`SELECT id FROM _issue_attachments
|
|
2400
|
+
WHERE id IN (${placeholders}) AND draft_id = ? AND uploader_id = ?${pagePathCondition} AND issue_id IS NULL AND deleted_at IS NULL`);
|
|
2401
|
+
eligibleStmt.bind([...attachmentIds, input.draftId, input.uploaderId, ...(input.pagePath === undefined ? [] : [input.pagePath])]);
|
|
2402
|
+
const eligibleIds = [];
|
|
2403
|
+
while (eligibleStmt.step())
|
|
2404
|
+
eligibleIds.push(String(eligibleStmt.getAsObject().id));
|
|
2405
|
+
eligibleStmt.free();
|
|
2406
|
+
if (eligibleIds.length !== attachmentIds.length)
|
|
2407
|
+
return [];
|
|
2408
|
+
const now = new Date().toISOString();
|
|
2409
|
+
db.run(`UPDATE _issue_attachments SET issue_id = ?, comment_id = ?, bound_at = ?
|
|
2410
|
+
WHERE id IN (${placeholders}) AND draft_id = ? AND uploader_id = ?${pagePathCondition} AND issue_id IS NULL AND deleted_at IS NULL`, [input.issueId, input.commentId ?? null, now, ...attachmentIds, input.draftId, input.uploaderId, ...(input.pagePath === undefined ? [] : [input.pagePath])]);
|
|
2411
|
+
markDirty(dbPath);
|
|
2412
|
+
saveConnection(dbPath);
|
|
2413
|
+
const bound = [];
|
|
2414
|
+
for (const attachmentId of attachmentIds) {
|
|
2415
|
+
const attachment = await getIssueAttachment(dbPath, attachmentId);
|
|
2416
|
+
if (attachment?.issue_id === input.issueId && attachment.uploader_id === input.uploaderId)
|
|
2417
|
+
bound.push(attachment);
|
|
2418
|
+
}
|
|
2419
|
+
return bound;
|
|
2420
|
+
}
|
|
2421
|
+
async function getIssueDetail(dbPath, issueId) {
|
|
2422
|
+
const issue = await getIssueById(dbPath, issueId);
|
|
2423
|
+
if (!issue)
|
|
2424
|
+
return null;
|
|
2425
|
+
const db = await getConnection(dbPath);
|
|
2426
|
+
const issueRevisionStmt = db.prepare("SELECT COUNT(*) AS revision_count FROM _issue_revisions WHERE issue_id = ? AND target_type = 'issue' AND target_id = ?");
|
|
2427
|
+
issueRevisionStmt.bind([issueId, issueId]);
|
|
2428
|
+
issue.revision_count = issueRevisionStmt.step() ? Number(issueRevisionStmt.getAsObject().revision_count ?? 0) : 0;
|
|
2429
|
+
issueRevisionStmt.free();
|
|
2430
|
+
const comments = [];
|
|
2431
|
+
const commentStmt = db.prepare(`
|
|
2432
|
+
SELECT c.*, (
|
|
2433
|
+
SELECT COUNT(*) FROM _issue_revisions r
|
|
2434
|
+
WHERE r.issue_id = c.issue_id AND r.target_type = 'comment' AND r.target_id = c.id
|
|
2435
|
+
) AS revision_count
|
|
2436
|
+
FROM _issue_comments c WHERE c.issue_id = ? ORDER BY c.created_at, c.id`);
|
|
2437
|
+
commentStmt.bind([issueId]);
|
|
2438
|
+
while (commentStmt.step())
|
|
2439
|
+
comments.push(commentStmt.getAsObject());
|
|
2440
|
+
commentStmt.free();
|
|
2441
|
+
const events = [];
|
|
2442
|
+
const eventStmt = db.prepare("SELECT * FROM _issue_events WHERE issue_id = ? ORDER BY created_at, id");
|
|
2443
|
+
eventStmt.bind([issueId]);
|
|
2444
|
+
while (eventStmt.step())
|
|
2445
|
+
events.push(eventStmt.getAsObject());
|
|
2446
|
+
eventStmt.free();
|
|
2447
|
+
const crossReferences = [];
|
|
2448
|
+
const crossReferenceStmt = db.prepare(`
|
|
2449
|
+
SELECT relation.id, relation.target_issue_id, relation.source_issue_id,
|
|
2450
|
+
source.issue_number AS source_issue_number, source.title AS source_issue_title,
|
|
2451
|
+
source.status AS source_issue_status, relation.source_type, relation.source_id,
|
|
2452
|
+
CASE WHEN relation.source_type = 'comment' THEN relation.source_id ELSE NULL END AS source_comment_id,
|
|
2453
|
+
relation.actor_id,
|
|
2454
|
+
CASE WHEN relation.source_type = 'comment' THEN comment.body ELSE source.description END AS source_markdown,
|
|
2455
|
+
relation.created_at, relation.updated_at
|
|
2456
|
+
FROM _issue_cross_references relation
|
|
2457
|
+
INNER JOIN _issues source ON source.id = relation.source_issue_id
|
|
2458
|
+
LEFT JOIN _issue_comments comment
|
|
2459
|
+
ON relation.source_type = 'comment' AND comment.id = relation.source_id AND comment.deleted_at IS NULL
|
|
2460
|
+
WHERE relation.target_issue_id = ?
|
|
2461
|
+
AND (relation.source_type = 'issue' OR comment.id IS NOT NULL)
|
|
2462
|
+
ORDER BY relation.created_at, relation.id`);
|
|
2463
|
+
crossReferenceStmt.bind([issueId]);
|
|
2464
|
+
while (crossReferenceStmt.step()) {
|
|
2465
|
+
const row = crossReferenceStmt.getAsObject();
|
|
2466
|
+
const sourceMarkdown = String(row.source_markdown ?? "").replace(/\s+/g, " ").trim();
|
|
2467
|
+
crossReferences.push({
|
|
2468
|
+
id: Number(row.id),
|
|
2469
|
+
target_issue_id: Number(row.target_issue_id),
|
|
2470
|
+
source_issue_id: Number(row.source_issue_id),
|
|
2471
|
+
source_issue_number: Number(row.source_issue_number),
|
|
2472
|
+
source_issue_title: String(row.source_issue_title),
|
|
2473
|
+
source_issue_status: String(row.source_issue_status),
|
|
2474
|
+
source_type: row.source_type,
|
|
2475
|
+
source_id: Number(row.source_id),
|
|
2476
|
+
source_comment_id: row.source_comment_id === null ? null : Number(row.source_comment_id),
|
|
2477
|
+
actor_id: String(row.actor_id),
|
|
2478
|
+
excerpt: Array.from(sourceMarkdown).slice(0, 180).join(""),
|
|
2479
|
+
created_at: String(row.created_at),
|
|
2480
|
+
updated_at: String(row.updated_at),
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
crossReferenceStmt.free();
|
|
2484
|
+
const attachments = [];
|
|
2485
|
+
const attachmentStmt = db.prepare("SELECT * FROM _issue_attachments WHERE issue_id = ? AND deleted_at IS NULL ORDER BY created_at, id");
|
|
2486
|
+
attachmentStmt.bind([issueId]);
|
|
2487
|
+
while (attachmentStmt.step())
|
|
2488
|
+
attachments.push(attachmentStmt.getAsObject());
|
|
2489
|
+
attachmentStmt.free();
|
|
2490
|
+
const reactions = [];
|
|
2491
|
+
const reactionStmt = db.prepare(`SELECT r.* FROM _issue_reactions r
|
|
2492
|
+
LEFT JOIN _issue_comments c ON c.id = r.comment_id
|
|
2493
|
+
WHERE r.issue_id = ? AND (r.comment_id = 0 OR (c.issue_id = ? AND c.deleted_at IS NULL))
|
|
2494
|
+
ORDER BY r.comment_id, r.content, r.user_id`);
|
|
2495
|
+
reactionStmt.bind([issueId, issueId]);
|
|
2496
|
+
while (reactionStmt.step())
|
|
2497
|
+
reactions.push(reactionStmt.getAsObject());
|
|
2498
|
+
reactionStmt.free();
|
|
2499
|
+
const parentStmt = db.prepare(`
|
|
2500
|
+
SELECT i.* FROM _issue_sub_issues relation
|
|
2501
|
+
INNER JOIN _issues i ON i.id = relation.parent_issue_id
|
|
2502
|
+
WHERE relation.child_issue_id = ?`);
|
|
2503
|
+
parentStmt.bind([issueId]);
|
|
2504
|
+
const parent = parentStmt.step() ? parentStmt.getAsObject() : null;
|
|
2505
|
+
parentStmt.free();
|
|
2506
|
+
const { items: subIssues, summary: subIssueSummary } = await listIssueSubIssues(dbPath, issueId);
|
|
2507
|
+
const readDependencyItems = (column, targetColumn) => {
|
|
2508
|
+
const items = [];
|
|
2509
|
+
const statement = db.prepare(`
|
|
2510
|
+
SELECT i.*, relation.added_by, relation.created_at AS relation_created_at
|
|
2511
|
+
FROM _issue_dependencies relation
|
|
2512
|
+
INNER JOIN _issues i ON i.id = relation.${targetColumn}
|
|
2513
|
+
WHERE relation.${column} = ?
|
|
2514
|
+
ORDER BY CASE i.status WHEN 'open' THEN 0 ELSE 1 END, i.issue_number`);
|
|
2515
|
+
statement.bind([issueId]);
|
|
2516
|
+
while (statement.step()) {
|
|
2517
|
+
const item = statement.getAsObject();
|
|
2518
|
+
const assigneeStmt = db.prepare("SELECT user_id FROM _issue_assignees WHERE issue_id = ? ORDER BY user_id");
|
|
2519
|
+
assigneeStmt.bind([item.id]);
|
|
2520
|
+
item.assignee_ids = [];
|
|
2521
|
+
while (assigneeStmt.step())
|
|
2522
|
+
item.assignee_ids.push(String(assigneeStmt.getAsObject().user_id));
|
|
2523
|
+
assigneeStmt.free();
|
|
2524
|
+
items.push(item);
|
|
2525
|
+
}
|
|
2526
|
+
statement.free();
|
|
2527
|
+
return items;
|
|
2528
|
+
};
|
|
2529
|
+
const blockedBy = readDependencyItems("blocked_issue_id", "blocking_issue_id");
|
|
2530
|
+
const blocking = readDependencyItems("blocking_issue_id", "blocked_issue_id");
|
|
2531
|
+
const unresolvedBlockers = blockedBy.filter((item) => item.status === "open").length;
|
|
2532
|
+
const dependencySummary = {
|
|
2533
|
+
blockedBy: blockedBy.length,
|
|
2534
|
+
blocking: blocking.length,
|
|
2535
|
+
unresolvedBlockers,
|
|
2536
|
+
isBlocked: unresolvedBlockers > 0,
|
|
2537
|
+
};
|
|
2538
|
+
const duplicateOfStmt = db.prepare(`
|
|
2539
|
+
SELECT i.*, relation.marked_by, relation.comment_id, relation.created_at AS relation_created_at
|
|
2540
|
+
FROM _issue_duplicates relation
|
|
2541
|
+
INNER JOIN _issues i ON i.id = relation.canonical_issue_id
|
|
2542
|
+
WHERE relation.duplicate_issue_id = ?`);
|
|
2543
|
+
duplicateOfStmt.bind([issueId]);
|
|
2544
|
+
const duplicateOf = duplicateOfStmt.step() ? duplicateOfStmt.getAsObject() : null;
|
|
2545
|
+
duplicateOfStmt.free();
|
|
2546
|
+
const duplicates = [];
|
|
2547
|
+
const duplicatesStmt = db.prepare(`
|
|
2548
|
+
SELECT i.*, relation.marked_by, relation.comment_id, relation.created_at AS relation_created_at
|
|
2549
|
+
FROM _issue_duplicates relation
|
|
2550
|
+
INNER JOIN _issues i ON i.id = relation.duplicate_issue_id
|
|
2551
|
+
WHERE relation.canonical_issue_id = ? ORDER BY i.issue_number`);
|
|
2552
|
+
duplicatesStmt.bind([issueId]);
|
|
2553
|
+
while (duplicatesStmt.step())
|
|
2554
|
+
duplicates.push(duplicatesStmt.getAsObject());
|
|
2555
|
+
duplicatesStmt.free();
|
|
2556
|
+
const timeline = [
|
|
2557
|
+
...comments.map((comment) => ({ kind: "comment", comment })),
|
|
2558
|
+
...events.map((event) => ({ kind: "event", event })),
|
|
2559
|
+
...crossReferences.map((crossReference) => ({ kind: "cross_reference", crossReference })),
|
|
2560
|
+
].sort((left, right) => {
|
|
2561
|
+
const leftTime = left.kind === "comment" ? left.comment.created_at : left.kind === "event" ? left.event.created_at : left.crossReference.created_at;
|
|
2562
|
+
const rightTime = right.kind === "comment" ? right.comment.created_at : right.kind === "event" ? right.event.created_at : right.crossReference.created_at;
|
|
2563
|
+
const byTime = leftTime.localeCompare(rightTime);
|
|
2564
|
+
if (byTime !== 0)
|
|
2565
|
+
return byTime;
|
|
2566
|
+
if (left.kind !== right.kind) {
|
|
2567
|
+
const rank = { comment: 0, event: 1, cross_reference: 2 };
|
|
2568
|
+
return rank[left.kind] - rank[right.kind];
|
|
2569
|
+
}
|
|
2570
|
+
const leftId = left.kind === "comment" ? left.comment.id : left.kind === "event" ? left.event.id : left.crossReference.id;
|
|
2571
|
+
const rightId = right.kind === "comment" ? right.comment.id : right.kind === "event" ? right.event.id : right.crossReference.id;
|
|
2572
|
+
return leftId - rightId;
|
|
2573
|
+
});
|
|
2574
|
+
const collaboration = await getIssueCollaborationMetadata(dbPath, issueId);
|
|
2575
|
+
return { issue, timeline, attachments, collaboration, reactions, parent, subIssues, subIssueSummary, blockedBy, blocking, dependencySummary, duplicateOf, duplicates };
|
|
2576
|
+
}
|
|
2577
|
+
async function getIssueDetailByNumber(dbPath, issueNumber) {
|
|
2578
|
+
const issue = await getIssueByNumber(dbPath, issueNumber);
|
|
2579
|
+
return issue ? getIssueDetail(dbPath, issue.id) : null;
|
|
2580
|
+
}
|
|
2581
|
+
//# sourceMappingURL=app-db.js.map
|