@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,786 @@
|
|
|
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
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const backend_contract_js_1 = require("../backend-contract.js");
|
|
11
|
+
const access_control_js_1 = require("../access-control.js");
|
|
12
|
+
const app_db_js_1 = require("../app-db.js");
|
|
13
|
+
const RESOURCE_SCHEMA_URL = "https://localapp.dev/schemas/backend/resource-schema.schema.json";
|
|
14
|
+
const QUERIES_SCHEMA_URL = "https://localapp.dev/schemas/backend/queries.schema.json";
|
|
15
|
+
const MUTATIONS_SCHEMA_URL = "https://localapp.dev/schemas/backend/mutations.schema.json";
|
|
16
|
+
function writeJson(filePath, value) {
|
|
17
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true });
|
|
18
|
+
node_fs_1.default.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
|
|
19
|
+
}
|
|
20
|
+
function writeResource(projectDir, resource, overrides) {
|
|
21
|
+
const resourceDir = node_path_1.default.join(projectDir, "backend", "resources", resource);
|
|
22
|
+
writeJson(node_path_1.default.join(resourceDir, "schema.json"), {
|
|
23
|
+
$schema: RESOURCE_SCHEMA_URL,
|
|
24
|
+
name: resource,
|
|
25
|
+
fields: {
|
|
26
|
+
id: { type: "auto_increment" },
|
|
27
|
+
title: { type: "string", constraints: { required: true } },
|
|
28
|
+
status: { type: "string" },
|
|
29
|
+
},
|
|
30
|
+
...overrides?.schema,
|
|
31
|
+
});
|
|
32
|
+
writeJson(node_path_1.default.join(resourceDir, "queries.json"), {
|
|
33
|
+
$schema: QUERIES_SCHEMA_URL,
|
|
34
|
+
queries: {
|
|
35
|
+
[`${resource}.list`]: {
|
|
36
|
+
kind: "query",
|
|
37
|
+
sql: `SELECT id, title, status FROM ${resource} WHERE status = :status`,
|
|
38
|
+
params: {
|
|
39
|
+
status: { type: "string", required: true },
|
|
40
|
+
},
|
|
41
|
+
access: "authenticated",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
...overrides?.queries,
|
|
45
|
+
});
|
|
46
|
+
writeJson(node_path_1.default.join(resourceDir, "mutations.json"), {
|
|
47
|
+
$schema: MUTATIONS_SCHEMA_URL,
|
|
48
|
+
mutations: {
|
|
49
|
+
[`${resource}.complete`]: {
|
|
50
|
+
kind: "mutation",
|
|
51
|
+
sql: `UPDATE ${resource} SET status = 'done' WHERE id = :id`,
|
|
52
|
+
params: {
|
|
53
|
+
id: { type: "number", required: true },
|
|
54
|
+
},
|
|
55
|
+
access: "authenticated",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
...overrides?.mutations,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
(0, vitest_1.describe)("backend contract files", () => {
|
|
62
|
+
let projectDir;
|
|
63
|
+
(0, vitest_1.beforeEach)(() => {
|
|
64
|
+
projectDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "localapp-backend-contract-"));
|
|
65
|
+
});
|
|
66
|
+
(0, vitest_1.afterEach)(() => {
|
|
67
|
+
node_fs_1.default.rmSync(projectDir, { recursive: true, force: true });
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.it)("discovers schema, query and mutation files from manifest backend.root", () => {
|
|
70
|
+
writeResource(projectDir, "work_items");
|
|
71
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" });
|
|
72
|
+
(0, vitest_1.expect)(contract.files.map((file) => file.relativePath).sort()).toEqual([
|
|
73
|
+
"backend/resources/work_items/mutations.json",
|
|
74
|
+
"backend/resources/work_items/queries.json",
|
|
75
|
+
"backend/resources/work_items/schema.json",
|
|
76
|
+
]);
|
|
77
|
+
(0, vitest_1.expect)(contract.resources.work_items.schema.name).toBe("work_items");
|
|
78
|
+
(0, vitest_1.expect)(contract.queries["work_items.list"].sql).toContain("SELECT");
|
|
79
|
+
(0, vitest_1.expect)(contract.mutations["work_items.complete"].sql).toContain("UPDATE");
|
|
80
|
+
});
|
|
81
|
+
(0, vitest_1.it)("rejects backend.include patterns that do not match files", () => {
|
|
82
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.loadBackendContract)(projectDir, {
|
|
83
|
+
include: ["backend/resources/**/schema.json"],
|
|
84
|
+
})).toThrow(/did not match any backend contract files/i);
|
|
85
|
+
});
|
|
86
|
+
(0, vitest_1.it)("rejects backend JSON files that do not declare $schema", () => {
|
|
87
|
+
writeResource(projectDir, "work_items");
|
|
88
|
+
writeJson(node_path_1.default.join(projectDir, "backend", "resources", "work_items", "queries.json"), {
|
|
89
|
+
queries: {},
|
|
90
|
+
});
|
|
91
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" })).toThrow(/\$schema/);
|
|
92
|
+
});
|
|
93
|
+
(0, vitest_1.it)("rejects duplicate resource schema names", () => {
|
|
94
|
+
writeResource(projectDir, "work_items");
|
|
95
|
+
writeResource(projectDir, "tasks", { schema: { name: "work_items" } });
|
|
96
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" })).toThrow(/duplicate resource schema/i);
|
|
97
|
+
});
|
|
98
|
+
(0, vitest_1.it)("rejects hosted action files in stable backend contracts", () => {
|
|
99
|
+
writeResource(projectDir, "work_items");
|
|
100
|
+
node_fs_1.default.mkdirSync(node_path_1.default.join(projectDir, "backend", "actions"), { recursive: true });
|
|
101
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(projectDir, "backend", "actions", "work-items.ts"), "export const action = {};\n");
|
|
102
|
+
writeJson(node_path_1.default.join(projectDir, "backend", "actions.manifest.json"), {
|
|
103
|
+
version: 1,
|
|
104
|
+
bundle: "backend/actions.bundle.mjs",
|
|
105
|
+
actions: [],
|
|
106
|
+
});
|
|
107
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(projectDir, "backend", "actions.bundle.mjs"), "export {};\n");
|
|
108
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" })).toThrow(/hosted action|disabled|named SQL/i);
|
|
109
|
+
});
|
|
110
|
+
(0, vitest_1.it)("can ignore disabled hosted action files when loading legacy versions for named SQL", () => {
|
|
111
|
+
writeResource(projectDir, "work_items");
|
|
112
|
+
node_fs_1.default.mkdirSync(node_path_1.default.join(projectDir, "backend", "actions"), { recursive: true });
|
|
113
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(projectDir, "backend", "actions", "work-items.ts"), "export const action = {};\n");
|
|
114
|
+
writeJson(node_path_1.default.join(projectDir, "backend", "actions.manifest.json"), {
|
|
115
|
+
version: 1,
|
|
116
|
+
bundle: "backend/actions.bundle.mjs",
|
|
117
|
+
actions: [],
|
|
118
|
+
});
|
|
119
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(projectDir, "backend", "actions.bundle.mjs"), "export {};\n");
|
|
120
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }, { allowDisabledHostedActions: true });
|
|
121
|
+
(0, vitest_1.expect)(contract.files.map((file) => file.relativePath).sort()).toEqual([
|
|
122
|
+
"backend/resources/work_items/mutations.json",
|
|
123
|
+
"backend/resources/work_items/queries.json",
|
|
124
|
+
"backend/resources/work_items/schema.json",
|
|
125
|
+
]);
|
|
126
|
+
(0, vitest_1.expect)(contract.queries["work_items.list"]).toBeDefined();
|
|
127
|
+
(0, vitest_1.expect)(contract.mutations["work_items.complete"]).toBeDefined();
|
|
128
|
+
});
|
|
129
|
+
(0, vitest_1.it)("allows resource schema files to declare only business metadata", () => {
|
|
130
|
+
writeResource(projectDir, "work_items", {
|
|
131
|
+
schema: {
|
|
132
|
+
fields: undefined,
|
|
133
|
+
business: {
|
|
134
|
+
ownerField: "created_by_member_id",
|
|
135
|
+
statusField: "status",
|
|
136
|
+
defaultFields: {
|
|
137
|
+
created_by_member_id: { defaultFrom: "currentUser.id" },
|
|
138
|
+
},
|
|
139
|
+
enums: {
|
|
140
|
+
status: ["todo", "doing", "done"],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" });
|
|
146
|
+
(0, vitest_1.expect)(contract.resources.work_items.schema.fields).toEqual({});
|
|
147
|
+
(0, vitest_1.expect)(contract.resources.work_items.schema.business).toMatchObject({
|
|
148
|
+
ownerField: "created_by_member_id",
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
(0, vitest_1.it)("rejects named SQL with undeclared or unused params", () => {
|
|
152
|
+
writeResource(projectDir, "work_items", {
|
|
153
|
+
queries: {
|
|
154
|
+
queries: {
|
|
155
|
+
"work_items.bad": {
|
|
156
|
+
kind: "query",
|
|
157
|
+
sql: "SELECT id FROM work_items WHERE status = :status AND owner_id = :ownerId",
|
|
158
|
+
params: {
|
|
159
|
+
status: { type: "string", required: true },
|
|
160
|
+
unused: { type: "string" },
|
|
161
|
+
},
|
|
162
|
+
access: "authenticated",
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)((0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }))).toThrow(/params/i);
|
|
168
|
+
});
|
|
169
|
+
(0, vitest_1.it)("parses generated security metadata and rejects SQL drift", () => {
|
|
170
|
+
const name = "work_items.mine";
|
|
171
|
+
const sql = "SELECT id, title, status FROM work_items WHERE created_by = :currentUserId";
|
|
172
|
+
const security = (0, backend_contract_js_1.createGeneratedNamedSqlSecurity)({
|
|
173
|
+
name,
|
|
174
|
+
kind: "query",
|
|
175
|
+
sql,
|
|
176
|
+
template: "owner-read-v1",
|
|
177
|
+
resource: "work_items",
|
|
178
|
+
config: { identityField: "created_by" },
|
|
179
|
+
});
|
|
180
|
+
writeResource(projectDir, "work_items", {
|
|
181
|
+
queries: {
|
|
182
|
+
queries: {
|
|
183
|
+
[name]: {
|
|
184
|
+
kind: "query",
|
|
185
|
+
sql,
|
|
186
|
+
params: {},
|
|
187
|
+
access: "authenticated",
|
|
188
|
+
security,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" });
|
|
194
|
+
(0, vitest_1.expect)(contract.queries[name].security?.mode).toBe("generated");
|
|
195
|
+
writeResource(projectDir, "work_items", {
|
|
196
|
+
queries: {
|
|
197
|
+
queries: {
|
|
198
|
+
[name]: {
|
|
199
|
+
kind: "query",
|
|
200
|
+
sql: "SELECT id, title, status FROM work_items",
|
|
201
|
+
params: {},
|
|
202
|
+
access: "authenticated",
|
|
203
|
+
security,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" })).toThrow(/security digest/i);
|
|
209
|
+
const updateName = "work_items.update";
|
|
210
|
+
const misplacedSql = "UPDATE work_items SET created_by = :currentUserId WHERE id = :id";
|
|
211
|
+
writeResource(projectDir, "work_items", {
|
|
212
|
+
mutations: {
|
|
213
|
+
mutations: {
|
|
214
|
+
[updateName]: {
|
|
215
|
+
kind: "mutation",
|
|
216
|
+
sql: misplacedSql,
|
|
217
|
+
params: { id: { type: "number", required: true } },
|
|
218
|
+
access: "authenticated",
|
|
219
|
+
security: (0, backend_contract_js_1.createGeneratedNamedSqlSecurity)({
|
|
220
|
+
name: updateName,
|
|
221
|
+
kind: "mutation",
|
|
222
|
+
sql: misplacedSql,
|
|
223
|
+
template: "owner-update-v1",
|
|
224
|
+
resource: "work_items",
|
|
225
|
+
config: { identityField: "created_by" },
|
|
226
|
+
}),
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" })).toThrow(/WHERE.*created_by/i);
|
|
232
|
+
});
|
|
233
|
+
(0, vitest_1.it)("rejects incomplete custom security metadata", () => {
|
|
234
|
+
writeResource(projectDir, "work_items", {
|
|
235
|
+
queries: {
|
|
236
|
+
queries: {
|
|
237
|
+
"work_items.dashboard": {
|
|
238
|
+
kind: "query",
|
|
239
|
+
sql: "SELECT status, COUNT(*) FROM work_items GROUP BY status",
|
|
240
|
+
params: {},
|
|
241
|
+
access: "authenticated",
|
|
242
|
+
security: {
|
|
243
|
+
mode: "custom",
|
|
244
|
+
access: "authenticated",
|
|
245
|
+
resources: ["work_items"],
|
|
246
|
+
systemParams: [],
|
|
247
|
+
scenarios: [{ identity: "owner", expect: "allow" }],
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" })).toThrow(/member.*scenario/i);
|
|
254
|
+
});
|
|
255
|
+
(0, vitest_1.it)("rejects unsafe query SQL", () => {
|
|
256
|
+
writeResource(projectDir, "work_items", {
|
|
257
|
+
queries: {
|
|
258
|
+
queries: {
|
|
259
|
+
"work_items.drop": {
|
|
260
|
+
kind: "query",
|
|
261
|
+
sql: "SELECT id FROM work_items; DROP TABLE work_items",
|
|
262
|
+
params: {},
|
|
263
|
+
access: "owner",
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)((0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }))).toThrow(/unsafe|query/i);
|
|
269
|
+
});
|
|
270
|
+
(0, vitest_1.it)("rejects SQL that references unknown resources or fields", () => {
|
|
271
|
+
writeResource(projectDir, "work_items", {
|
|
272
|
+
queries: {
|
|
273
|
+
queries: {
|
|
274
|
+
"work_items.unknownTable": {
|
|
275
|
+
kind: "query",
|
|
276
|
+
sql: "SELECT id FROM missing_items",
|
|
277
|
+
params: {},
|
|
278
|
+
access: "authenticated",
|
|
279
|
+
},
|
|
280
|
+
"work_items.unknownField": {
|
|
281
|
+
kind: "query",
|
|
282
|
+
sql: "SELECT ghost FROM work_items",
|
|
283
|
+
params: {},
|
|
284
|
+
access: "authenticated",
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)((0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }))).toThrow(/unknown.*(resource|field)/i);
|
|
290
|
+
});
|
|
291
|
+
(0, vitest_1.it)("allows CTE names while validating fields from the underlying resource", () => {
|
|
292
|
+
writeResource(projectDir, "work_items", {
|
|
293
|
+
queries: {
|
|
294
|
+
queries: {
|
|
295
|
+
"work_items.cte": {
|
|
296
|
+
kind: "query",
|
|
297
|
+
sql: "WITH latest AS (SELECT id, title FROM work_items) SELECT * FROM latest ORDER BY id",
|
|
298
|
+
params: {},
|
|
299
|
+
access: "authenticated",
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)((0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }))).not.toThrow();
|
|
305
|
+
});
|
|
306
|
+
(0, vitest_1.it)("validates INSERT SELECT fields across the target and source resources without a database", () => {
|
|
307
|
+
writeResource(projectDir, "ai_subscriptions", {
|
|
308
|
+
schema: {
|
|
309
|
+
fields: {
|
|
310
|
+
id: { type: "auto_increment" },
|
|
311
|
+
user_id: { type: "string" },
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
queries: { queries: {} },
|
|
315
|
+
mutations: { mutations: {} },
|
|
316
|
+
});
|
|
317
|
+
writeResource(projectDir, "subscription_attachments", {
|
|
318
|
+
schema: {
|
|
319
|
+
fields: {
|
|
320
|
+
id: { type: "auto_increment" },
|
|
321
|
+
subscription_id: { type: "integer" },
|
|
322
|
+
user_id: { type: "string" },
|
|
323
|
+
file_name: { type: "string" },
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
queries: { queries: {} },
|
|
327
|
+
mutations: {
|
|
328
|
+
mutations: {
|
|
329
|
+
"subscription_attachments.create": {
|
|
330
|
+
kind: "mutation",
|
|
331
|
+
sql: "INSERT INTO subscription_attachments (subscription_id, user_id, file_name) SELECT s.id, s.user_id, :fileName FROM ai_subscriptions s WHERE s.id = :subscriptionId AND (:currentUserId = :ownerId OR s.user_id = :currentUserId)",
|
|
332
|
+
params: {
|
|
333
|
+
subscriptionId: { type: "number", required: true },
|
|
334
|
+
fileName: { type: "string", required: true },
|
|
335
|
+
},
|
|
336
|
+
access: "authenticated",
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)((0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }))).not.toThrow();
|
|
342
|
+
});
|
|
343
|
+
(0, vitest_1.it)("validates named SQL fields against database columns when fields are not duplicated in schema", async () => {
|
|
344
|
+
writeResource(projectDir, "work_items", {
|
|
345
|
+
schema: {
|
|
346
|
+
fields: {},
|
|
347
|
+
business: {
|
|
348
|
+
ownerField: "created_by_member_id",
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
queries: {
|
|
352
|
+
queries: {
|
|
353
|
+
"work_items.byCreator": {
|
|
354
|
+
kind: "query",
|
|
355
|
+
sql: "SELECT id, title, created_by_member_id FROM work_items WHERE created_by_member_id = :memberId",
|
|
356
|
+
params: {
|
|
357
|
+
memberId: { type: "number", required: true },
|
|
358
|
+
},
|
|
359
|
+
access: "authenticated",
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
const db = await (0, app_db_js_1.getConnection)((0, app_db_js_1.getDbPath)(projectDir));
|
|
365
|
+
db.run("CREATE TABLE work_items (id INTEGER PRIMARY KEY, title TEXT, status TEXT, created_by_member_id INTEGER)");
|
|
366
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)((0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }), {
|
|
367
|
+
dbPath: (0, app_db_js_1.getDbPath)(projectDir),
|
|
368
|
+
})).not.toThrow();
|
|
369
|
+
});
|
|
370
|
+
(0, vitest_1.it)("validates joined named SQL against database tables instead of resource schema files", async () => {
|
|
371
|
+
writeResource(projectDir, "work_items", {
|
|
372
|
+
schema: {
|
|
373
|
+
fields: {},
|
|
374
|
+
},
|
|
375
|
+
queries: {
|
|
376
|
+
queries: {
|
|
377
|
+
"work_items.mine": {
|
|
378
|
+
kind: "query",
|
|
379
|
+
sql: "SELECT wi.* FROM work_items wi JOIN workload_members wm ON wm.id = wi.created_by_member_id WHERE wm.user_id = :currentUserId",
|
|
380
|
+
params: {},
|
|
381
|
+
access: "authenticated",
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
const db = await (0, app_db_js_1.getConnection)((0, app_db_js_1.getDbPath)(projectDir));
|
|
387
|
+
db.run("CREATE TABLE work_items (id INTEGER PRIMARY KEY, title TEXT, status TEXT, created_by_member_id INTEGER)");
|
|
388
|
+
db.run("CREATE TABLE workload_members (id INTEGER PRIMARY KEY, user_id TEXT)");
|
|
389
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)((0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }), {
|
|
390
|
+
dbPath: (0, app_db_js_1.getDbPath)(projectDir),
|
|
391
|
+
})).not.toThrow();
|
|
392
|
+
});
|
|
393
|
+
(0, vitest_1.it)("rejects named SQL references to platform-owned system tables", async () => {
|
|
394
|
+
writeResource(projectDir, "work_items", {
|
|
395
|
+
queries: {
|
|
396
|
+
queries: {
|
|
397
|
+
"work_items.issueLabels": {
|
|
398
|
+
kind: "query",
|
|
399
|
+
sql: "SELECT id, name FROM _issue_labels ORDER BY name",
|
|
400
|
+
params: {},
|
|
401
|
+
access: "owner",
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
});
|
|
406
|
+
const db = await (0, app_db_js_1.getConnection)((0, app_db_js_1.getDbPath)(projectDir));
|
|
407
|
+
db.run("CREATE TABLE work_items (id INTEGER PRIMARY KEY, title TEXT, status TEXT)");
|
|
408
|
+
db.run("CREATE TABLE _issue_labels (id TEXT PRIMARY KEY, name TEXT)");
|
|
409
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)((0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }), {
|
|
410
|
+
dbPath: (0, app_db_js_1.getDbPath)(projectDir),
|
|
411
|
+
})).toThrow(/system|protected|platform/i);
|
|
412
|
+
});
|
|
413
|
+
(0, vitest_1.it)("rejects inline backend SQL in manifest config", () => {
|
|
414
|
+
const manifestBackend = {
|
|
415
|
+
root: "backend",
|
|
416
|
+
queries: {
|
|
417
|
+
"work_items.list": { sql: "SELECT 1" },
|
|
418
|
+
},
|
|
419
|
+
};
|
|
420
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.loadBackendContract)(projectDir, manifestBackend)).toThrow(/inline/i);
|
|
421
|
+
});
|
|
422
|
+
(0, vitest_1.it)("loads named query result contracts for page, single and aggregate modes", () => {
|
|
423
|
+
writeResource(projectDir, "work_items", {
|
|
424
|
+
queries: {
|
|
425
|
+
queries: {
|
|
426
|
+
"work_items.page": {
|
|
427
|
+
kind: "query",
|
|
428
|
+
sql: "SELECT id, title FROM work_items ORDER BY id LIMIT :limit OFFSET :offset",
|
|
429
|
+
params: {
|
|
430
|
+
limit: { type: "number", required: true },
|
|
431
|
+
offset: { type: "number" },
|
|
432
|
+
},
|
|
433
|
+
result: { mode: "page", maxRows: 100, maxBytes: 65536 },
|
|
434
|
+
},
|
|
435
|
+
"work_items.get": {
|
|
436
|
+
kind: "query",
|
|
437
|
+
sql: "SELECT id, title FROM work_items WHERE id = :id",
|
|
438
|
+
params: { id: { type: "number", required: true } },
|
|
439
|
+
result: { mode: "single", maxRows: 1, maxBytes: 4096 },
|
|
440
|
+
},
|
|
441
|
+
"work_items.countByStatus": {
|
|
442
|
+
kind: "query",
|
|
443
|
+
sql: "SELECT status, COUNT(*) AS count FROM work_items GROUP BY status",
|
|
444
|
+
params: {},
|
|
445
|
+
result: { mode: "aggregate", maxRows: 20, maxBytes: 8192 },
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
});
|
|
450
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" });
|
|
451
|
+
(0, vitest_1.expect)(contract.queries["work_items.page"].result).toMatchObject({ mode: "page", maxRows: 100 });
|
|
452
|
+
(0, vitest_1.expect)(contract.queries["work_items.get"].result).toMatchObject({ mode: "single", maxRows: 1 });
|
|
453
|
+
(0, vitest_1.expect)(contract.queries["work_items.countByStatus"].result).toMatchObject({ mode: "aggregate", maxRows: 20 });
|
|
454
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)(contract)).not.toThrow();
|
|
455
|
+
});
|
|
456
|
+
(0, vitest_1.it)("rejects page result contracts that do not expose a bounded limit parameter", () => {
|
|
457
|
+
writeResource(projectDir, "work_items", {
|
|
458
|
+
queries: {
|
|
459
|
+
queries: {
|
|
460
|
+
"work_items.badPage": {
|
|
461
|
+
kind: "query",
|
|
462
|
+
sql: "SELECT id, title FROM work_items ORDER BY id",
|
|
463
|
+
params: {},
|
|
464
|
+
result: { mode: "page", maxRows: 100, maxBytes: 65536 },
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
(0, vitest_1.expect)(() => (0, backend_contract_js_1.validateBackendContract)((0, backend_contract_js_1.loadBackendContract)(projectDir, { root: "backend" }))).toThrow(/limit|page|pagination/i);
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
(0, vitest_1.describe)("named SQL executor", () => {
|
|
473
|
+
let pageDir;
|
|
474
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
475
|
+
pageDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "localapp-named-sql-"));
|
|
476
|
+
writeJson(node_path_1.default.join(pageDir, "backend", "resources", "work_items", "schema.json"), {
|
|
477
|
+
$schema: RESOURCE_SCHEMA_URL,
|
|
478
|
+
name: "work_items",
|
|
479
|
+
fields: {
|
|
480
|
+
title: { type: "string" },
|
|
481
|
+
status: { type: "string" },
|
|
482
|
+
assignee_id: { type: "string" },
|
|
483
|
+
},
|
|
484
|
+
});
|
|
485
|
+
writeJson(node_path_1.default.join(pageDir, "backend", "resources", "work_items", "queries.json"), {
|
|
486
|
+
$schema: QUERIES_SCHEMA_URL,
|
|
487
|
+
queries: {
|
|
488
|
+
"work_items.mine": {
|
|
489
|
+
kind: "query",
|
|
490
|
+
sql: "SELECT id, title FROM work_items WHERE assignee_id = :currentUserId AND status = :status",
|
|
491
|
+
params: {
|
|
492
|
+
status: { type: "string", required: true, enum: ["open", "done"] },
|
|
493
|
+
},
|
|
494
|
+
access: "authenticated",
|
|
495
|
+
},
|
|
496
|
+
"work_items.ownerOnly": {
|
|
497
|
+
kind: "query",
|
|
498
|
+
sql: "SELECT id FROM work_items",
|
|
499
|
+
params: {},
|
|
500
|
+
access: "owner",
|
|
501
|
+
},
|
|
502
|
+
"work_items.ops": {
|
|
503
|
+
kind: "query",
|
|
504
|
+
sql: "SELECT id FROM work_items",
|
|
505
|
+
params: {},
|
|
506
|
+
access: "acl",
|
|
507
|
+
acl: ["group:ops"],
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
});
|
|
511
|
+
const schema = {
|
|
512
|
+
name: "work_items",
|
|
513
|
+
pageName: "test",
|
|
514
|
+
createdAt: new Date().toISOString(),
|
|
515
|
+
updatedAt: new Date().toISOString(),
|
|
516
|
+
fields: {
|
|
517
|
+
title: { type: "string" },
|
|
518
|
+
status: { type: "string" },
|
|
519
|
+
assignee_id: { type: "string" },
|
|
520
|
+
},
|
|
521
|
+
};
|
|
522
|
+
await (0, app_db_js_1.createTable)(pageDir, schema);
|
|
523
|
+
const dbPath = (0, app_db_js_1.getDbPath)(pageDir);
|
|
524
|
+
await (0, app_db_js_1.getConnection)(dbPath);
|
|
525
|
+
(0, app_db_js_1.execRawSql)(dbPath, "INSERT INTO work_items (title, status, assignee_id) VALUES (?, ?, ?)", [
|
|
526
|
+
"Mine",
|
|
527
|
+
"open",
|
|
528
|
+
"alice",
|
|
529
|
+
]);
|
|
530
|
+
(0, app_db_js_1.execRawSql)(dbPath, "INSERT INTO work_items (title, status, assignee_id) VALUES (?, ?, ?)", [
|
|
531
|
+
"Other",
|
|
532
|
+
"open",
|
|
533
|
+
"bob",
|
|
534
|
+
]);
|
|
535
|
+
});
|
|
536
|
+
(0, vitest_1.afterEach)(() => {
|
|
537
|
+
(0, access_control_js_1.setGroupMembershipResolver)(null);
|
|
538
|
+
node_fs_1.default.rmSync(pageDir, { recursive: true, force: true });
|
|
539
|
+
});
|
|
540
|
+
(0, vitest_1.it)("rejects frontend-supplied SQL and only accepts registered SQL names", async () => {
|
|
541
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(pageDir, { root: "backend" });
|
|
542
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
543
|
+
kind: "query",
|
|
544
|
+
name: "work_items.mine",
|
|
545
|
+
dbPath: pageDir,
|
|
546
|
+
body: {
|
|
547
|
+
sql: "SELECT id, title FROM work_items",
|
|
548
|
+
params: { status: "open" },
|
|
549
|
+
},
|
|
550
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
551
|
+
})).rejects.toThrow(/sql field/i);
|
|
552
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
553
|
+
kind: "query",
|
|
554
|
+
name: "work_items.unknown",
|
|
555
|
+
dbPath: pageDir,
|
|
556
|
+
body: { params: {} },
|
|
557
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
558
|
+
})).rejects.toThrow(/not found/i);
|
|
559
|
+
});
|
|
560
|
+
(0, vitest_1.it)("validates request params before executing named SQL", async () => {
|
|
561
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(pageDir, { root: "backend" });
|
|
562
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
563
|
+
kind: "query",
|
|
564
|
+
name: "work_items.mine",
|
|
565
|
+
dbPath: pageDir,
|
|
566
|
+
body: { params: { status: "invalid" } },
|
|
567
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
568
|
+
})).rejects.toThrow(/status/);
|
|
569
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
570
|
+
kind: "query",
|
|
571
|
+
name: "work_items.mine",
|
|
572
|
+
dbPath: pageDir,
|
|
573
|
+
body: { params: { status: "open", extra: true } },
|
|
574
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
575
|
+
})).rejects.toThrow(/extra/);
|
|
576
|
+
});
|
|
577
|
+
(0, vitest_1.it)("injects system variables and prevents frontend override", async () => {
|
|
578
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(pageDir, { root: "backend" });
|
|
579
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
580
|
+
kind: "query",
|
|
581
|
+
name: "work_items.mine",
|
|
582
|
+
dbPath: pageDir,
|
|
583
|
+
body: { params: { status: "open", currentUserId: "bob" } },
|
|
584
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
585
|
+
})).rejects.toThrow(/currentUserId/);
|
|
586
|
+
const result = await (0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
587
|
+
kind: "query",
|
|
588
|
+
name: "work_items.mine",
|
|
589
|
+
dbPath: pageDir,
|
|
590
|
+
body: { params: { status: "open" } },
|
|
591
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
592
|
+
});
|
|
593
|
+
(0, vitest_1.expect)(result.rows).toEqual([{ id: 1, title: "Mine" }]);
|
|
594
|
+
});
|
|
595
|
+
(0, vitest_1.it)("rejects named SQL when access checks fail before execution", async () => {
|
|
596
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(pageDir, { root: "backend" });
|
|
597
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
598
|
+
kind: "query",
|
|
599
|
+
name: "work_items.ownerOnly",
|
|
600
|
+
dbPath: pageDir,
|
|
601
|
+
body: { params: {} },
|
|
602
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
603
|
+
})).rejects.toThrow(/access denied/i);
|
|
604
|
+
});
|
|
605
|
+
(0, vitest_1.it)("uses existing acl group semantics for named SQL access", async () => {
|
|
606
|
+
(0, access_control_js_1.setGroupMembershipResolver)((userId, groupName) => userId === "alice" && groupName === "ops");
|
|
607
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(pageDir, { root: "backend" });
|
|
608
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
609
|
+
kind: "query",
|
|
610
|
+
name: "work_items.ops",
|
|
611
|
+
dbPath: pageDir,
|
|
612
|
+
body: { params: {} },
|
|
613
|
+
context: { visitorId: "bob", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
614
|
+
})).rejects.toThrow(/access denied/i);
|
|
615
|
+
const result = await (0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
616
|
+
kind: "query",
|
|
617
|
+
name: "work_items.ops",
|
|
618
|
+
dbPath: pageDir,
|
|
619
|
+
body: { params: {} },
|
|
620
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
621
|
+
});
|
|
622
|
+
(0, vitest_1.expect)(result.rows).toHaveLength(2);
|
|
623
|
+
});
|
|
624
|
+
(0, vitest_1.it)("binds omitted optional params as null so patch SQL keeps existing values", async () => {
|
|
625
|
+
writeJson(node_path_1.default.join(pageDir, "backend", "resources", "work_items", "mutations.json"), {
|
|
626
|
+
$schema: MUTATIONS_SCHEMA_URL,
|
|
627
|
+
mutations: {
|
|
628
|
+
"work_items.patch": {
|
|
629
|
+
kind: "mutation",
|
|
630
|
+
sql: "UPDATE work_items SET title = COALESCE(:title, title), assignee_id = CASE WHEN :assignee_id__set_null THEN NULL ELSE COALESCE(:assignee_id, assignee_id) END WHERE id = :id",
|
|
631
|
+
params: {
|
|
632
|
+
id: { type: "number", required: true },
|
|
633
|
+
title: { type: "string" },
|
|
634
|
+
assignee_id: { type: "string", nullable: true },
|
|
635
|
+
assignee_id__set_null: { type: "boolean" },
|
|
636
|
+
},
|
|
637
|
+
access: "authenticated",
|
|
638
|
+
},
|
|
639
|
+
},
|
|
640
|
+
});
|
|
641
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(pageDir, { root: "backend" });
|
|
642
|
+
await (0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
643
|
+
kind: "mutation",
|
|
644
|
+
name: "work_items.patch",
|
|
645
|
+
dbPath: pageDir,
|
|
646
|
+
body: { params: { id: 1, title: "Renamed" } },
|
|
647
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
648
|
+
});
|
|
649
|
+
await (0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
650
|
+
kind: "mutation",
|
|
651
|
+
name: "work_items.patch",
|
|
652
|
+
dbPath: pageDir,
|
|
653
|
+
body: { params: { id: 1, assignee_id__set_null: true } },
|
|
654
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
655
|
+
});
|
|
656
|
+
const rows = (0, app_db_js_1.execRawSql)((0, app_db_js_1.getDbPath)(pageDir), "SELECT title, status, assignee_id FROM work_items WHERE id = 1").rows;
|
|
657
|
+
(0, vitest_1.expect)(rows).toEqual([{ title: "Renamed", status: "open", assignee_id: null }]);
|
|
658
|
+
});
|
|
659
|
+
(0, vitest_1.it)("rejects named SQL query results that exceed rows and bytes budgets", async () => {
|
|
660
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(pageDir, { root: "backend" });
|
|
661
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
662
|
+
kind: "query",
|
|
663
|
+
name: "work_items.ops",
|
|
664
|
+
dbPath: pageDir,
|
|
665
|
+
body: { params: {} },
|
|
666
|
+
context: { visitorId: "owner", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
667
|
+
resultBudget: { maxRows: 1 },
|
|
668
|
+
})).rejects.toMatchObject({ status: 413, code: "named_sql_result_too_large" });
|
|
669
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSql)(contract, {
|
|
670
|
+
kind: "query",
|
|
671
|
+
name: "work_items.ops",
|
|
672
|
+
dbPath: pageDir,
|
|
673
|
+
body: { params: {} },
|
|
674
|
+
context: { visitorId: "owner", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
675
|
+
resultBudget: { maxBytes: 10 },
|
|
676
|
+
})).rejects.toMatchObject({ status: 413, code: "named_sql_result_too_large" });
|
|
677
|
+
});
|
|
678
|
+
(0, vitest_1.it)("executes registered mutations as a single transaction and rolls back on failure", async () => {
|
|
679
|
+
writeJson(node_path_1.default.join(pageDir, "backend", "resources", "work_items", "mutations.json"), {
|
|
680
|
+
$schema: MUTATIONS_SCHEMA_URL,
|
|
681
|
+
mutations: {
|
|
682
|
+
"work_items.rename": {
|
|
683
|
+
kind: "mutation",
|
|
684
|
+
sql: "UPDATE work_items SET title = :title WHERE id = :id",
|
|
685
|
+
params: {
|
|
686
|
+
id: { type: "number", required: true },
|
|
687
|
+
title: { type: "string", required: true },
|
|
688
|
+
},
|
|
689
|
+
access: "authenticated",
|
|
690
|
+
},
|
|
691
|
+
"work_items.fail": {
|
|
692
|
+
kind: "mutation",
|
|
693
|
+
sql: "UPDATE missing_table SET title = :title WHERE id = :id",
|
|
694
|
+
params: {
|
|
695
|
+
id: { type: "number", required: true },
|
|
696
|
+
title: { type: "string", required: true },
|
|
697
|
+
},
|
|
698
|
+
access: "authenticated",
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
});
|
|
702
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(pageDir, { root: "backend" });
|
|
703
|
+
await (0, vitest_1.expect)((0, backend_contract_js_1.executeNamedSqlTransaction)(contract, {
|
|
704
|
+
dbPath: pageDir,
|
|
705
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
706
|
+
mutations: [
|
|
707
|
+
{ name: "work_items.rename", body: { params: { id: 1, title: "Changed" } } },
|
|
708
|
+
{ name: "work_items.fail", body: { params: { id: 1, title: "Broken" } } },
|
|
709
|
+
],
|
|
710
|
+
})).rejects.toThrow();
|
|
711
|
+
const rows = (0, app_db_js_1.execRawSql)((0, app_db_js_1.getDbPath)(pageDir), "SELECT title FROM work_items WHERE id = 1").rows;
|
|
712
|
+
(0, vitest_1.expect)(rows).toEqual([{ title: "Mine" }]);
|
|
713
|
+
});
|
|
714
|
+
(0, vitest_1.it)("allows later transaction mutation params to reference previous results", async () => {
|
|
715
|
+
const dbPath = (0, app_db_js_1.getDbPath)(pageDir);
|
|
716
|
+
(0, app_db_js_1.execRawSql)(dbPath, `
|
|
717
|
+
CREATE TABLE work_item_logs (
|
|
718
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
719
|
+
work_item_id INTEGER NOT NULL,
|
|
720
|
+
message TEXT NOT NULL
|
|
721
|
+
)
|
|
722
|
+
`);
|
|
723
|
+
writeJson(node_path_1.default.join(pageDir, "backend", "resources", "work_items", "mutations.json"), {
|
|
724
|
+
$schema: MUTATIONS_SCHEMA_URL,
|
|
725
|
+
mutations: {
|
|
726
|
+
"work_items.create": {
|
|
727
|
+
kind: "mutation",
|
|
728
|
+
sql: "INSERT INTO work_items (title, status, assignee_id) VALUES (:title, :status, :assignee_id)",
|
|
729
|
+
params: {
|
|
730
|
+
title: { type: "string", required: true },
|
|
731
|
+
status: { type: "string", required: true },
|
|
732
|
+
assignee_id: { type: "string", required: true },
|
|
733
|
+
},
|
|
734
|
+
access: "authenticated",
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
});
|
|
738
|
+
writeJson(node_path_1.default.join(pageDir, "backend", "resources", "work_item_logs", "schema.json"), {
|
|
739
|
+
$schema: RESOURCE_SCHEMA_URL,
|
|
740
|
+
name: "work_item_logs",
|
|
741
|
+
fields: {
|
|
742
|
+
work_item_id: { type: "number" },
|
|
743
|
+
message: { type: "string" },
|
|
744
|
+
},
|
|
745
|
+
});
|
|
746
|
+
writeJson(node_path_1.default.join(pageDir, "backend", "resources", "work_item_logs", "mutations.json"), {
|
|
747
|
+
$schema: MUTATIONS_SCHEMA_URL,
|
|
748
|
+
mutations: {
|
|
749
|
+
"work_item_logs.create": {
|
|
750
|
+
kind: "mutation",
|
|
751
|
+
sql: "INSERT INTO work_item_logs (work_item_id, message) VALUES (:work_item_id, :message)",
|
|
752
|
+
params: {
|
|
753
|
+
work_item_id: { type: "number", required: true },
|
|
754
|
+
message: { type: "string", required: true },
|
|
755
|
+
},
|
|
756
|
+
access: "authenticated",
|
|
757
|
+
},
|
|
758
|
+
},
|
|
759
|
+
});
|
|
760
|
+
const contract = (0, backend_contract_js_1.loadBackendContract)(pageDir, { root: "backend" });
|
|
761
|
+
const results = await (0, backend_contract_js_1.executeNamedSqlTransaction)(contract, {
|
|
762
|
+
dbPath: pageDir,
|
|
763
|
+
context: { visitorId: "alice", ownerId: "owner", now: new Date("2026-01-02T03:04:05Z") },
|
|
764
|
+
body: {
|
|
765
|
+
mutations: [
|
|
766
|
+
{
|
|
767
|
+
name: "work_items.create",
|
|
768
|
+
params: { title: "Created", status: "open", assignee_id: "alice" },
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
name: "work_item_logs.create",
|
|
772
|
+
params: {
|
|
773
|
+
work_item_id: { $result: 0, field: "lastInsertRowId" },
|
|
774
|
+
message: "created",
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
],
|
|
778
|
+
},
|
|
779
|
+
});
|
|
780
|
+
(0, vitest_1.expect)(results[0]).toMatchObject({ changes: 1, lastInsertRowId: vitest_1.expect.any(Number) });
|
|
781
|
+
const createdId = results[0].lastInsertRowId;
|
|
782
|
+
const rows = (0, app_db_js_1.execRawSql)(dbPath, "SELECT work_item_id, message FROM work_item_logs").rows;
|
|
783
|
+
(0, vitest_1.expect)(rows).toEqual([{ work_item_id: createdId, message: "created" }]);
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
//# sourceMappingURL=backend-contract.test.js.map
|