@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,325 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: localapp-business
|
|
3
|
+
description: >
|
|
4
|
+
LocalApp 业务应用建模指南——把 schema、当前用户、记录级权限、SDK Hook
|
|
5
|
+
和 shadcn/ui 组合成可用业务应用。当用户要在 LocalApp 项目中创建请假、
|
|
6
|
+
报销、工单、任务、客户跟进、目录、审批等带"归属""状态""审批人"等业务
|
|
7
|
+
语义的应用时触发;也适用于用户说"用户只能看自己的数据"、"草稿可编辑
|
|
8
|
+
提交后不可编辑"、"只有负责人能更新"、"分配任务给别人"等场景。
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# LocalApp 业务应用建模
|
|
12
|
+
|
|
13
|
+
业务应用 = schema + 当前用户 + 记录级权限 + SDK 权限 UI。
|
|
14
|
+
|
|
15
|
+
核心思路:把"这条记录属于谁、谁能改、什么时候能改"写进 schema 的
|
|
16
|
+
`business` 元数据,让 CRUD API 在后端执行;前端只用 `usePermissions()`
|
|
17
|
+
和 `<Can>` 决定显示哪些按钮。
|
|
18
|
+
|
|
19
|
+
## 模型选择
|
|
20
|
+
|
|
21
|
+
按业务形态选择对应模型:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
谁创建记录? 谁应该看到? 推荐模型
|
|
25
|
+
─────────────────────────────────────────────────────────
|
|
26
|
+
申请人自己 仅申请人 + 审批人 申请类(request)
|
|
27
|
+
任何登录用户 负责人 + 管理员 分配类(assignment)
|
|
28
|
+
系统/管理员 所有人可读 目录类(catalog)
|
|
29
|
+
任何登录用户 仅创建者 个人类(personal)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 申请类(request)
|
|
33
|
+
|
|
34
|
+
适用:请假、报销、工单、报修、申请单等"用户提交、他人审批"的应用。
|
|
35
|
+
|
|
36
|
+
推荐字段:
|
|
37
|
+
| 字段 | 类型 | 约束 | 说明 |
|
|
38
|
+
|------|------|------|------|
|
|
39
|
+
| `title` / `reason` | string | required | 申请标题或理由 |
|
|
40
|
+
| `created_by` | string | `defaultFrom: "currentUser.id"` | 申请人,后端自动填充 |
|
|
41
|
+
| `status` | string | `enum: ["draft","submitted","approved","rejected"]` | 状态枚举 |
|
|
42
|
+
| `submitted_at` | timestamp | | 提交时间 |
|
|
43
|
+
| `reviewed_by` | string | `defaultFrom: "currentUser.id"` | 审批人(审批时由后端填) |
|
|
44
|
+
|
|
45
|
+
记录级权限:
|
|
46
|
+
- 申请人能读、能在 `draft` 状态下更新、能删除草稿
|
|
47
|
+
- 审批人能读、能在 `submitted` 状态下更新 status
|
|
48
|
+
- 列表对申请人本人可见(管理员/审批人通过其他方式查看)
|
|
49
|
+
|
|
50
|
+
### 审批类(approval)
|
|
51
|
+
|
|
52
|
+
申请类的进阶形态——记录有明确的"审批人"字段,需要按审批人分发。
|
|
53
|
+
|
|
54
|
+
字段:申请类字段 + `reviewed_by`(审批人)+ `reviewed_at`(审批时间)。
|
|
55
|
+
|
|
56
|
+
权限:
|
|
57
|
+
- 申请人 read/update(仅 draft)
|
|
58
|
+
- 审批人 read/update(仅 submitted 时改 status)
|
|
59
|
+
|
|
60
|
+
### 分配类(assignment)
|
|
61
|
+
|
|
62
|
+
适用:任务、客户跟进、处理单等"用户被指派负责"的应用。
|
|
63
|
+
|
|
64
|
+
推荐字段:
|
|
65
|
+
| 字段 | 类型 | 约束 | 说明 |
|
|
66
|
+
|------|------|------|------|
|
|
67
|
+
| `title` | string | required | 任务标题 |
|
|
68
|
+
| `assignee_id` | string | | 负责人 ID |
|
|
69
|
+
| `status` | string | `enum: ["todo","in_progress","done","cancelled"]` | 状态 |
|
|
70
|
+
| `due_at` | timestamp | | 截止时间 |
|
|
71
|
+
| `priority` | string | `enum: ["low","medium","high"]` | 优先级 |
|
|
72
|
+
| `created_by` | string | `defaultFrom: "currentUser.id"` | 创建者 |
|
|
73
|
+
|
|
74
|
+
记录级权限:
|
|
75
|
+
- 负责人能读、能更新 status / priority
|
|
76
|
+
- 创建者能读、能删除(管理自己分配的任务)
|
|
77
|
+
|
|
78
|
+
### 目录类(catalog)
|
|
79
|
+
|
|
80
|
+
适用:产品目录、知识库、字典表、配置项等"管理员维护、所有人只读"的应用。
|
|
81
|
+
|
|
82
|
+
推荐字段:
|
|
83
|
+
| 字段 | 类型 | 约束 | 说明 |
|
|
84
|
+
|------|------|------|------|
|
|
85
|
+
| `name` | string | required, unique | 名称 |
|
|
86
|
+
| `description` | string | | 描述 |
|
|
87
|
+
| `enabled` | boolean | `defaultValue: true` | 是否启用 |
|
|
88
|
+
| `sort_order` | number | `defaultValue: 0` | 排序 |
|
|
89
|
+
|
|
90
|
+
权限:
|
|
91
|
+
- 所有人可读(`read: { mode: "authenticated" }`)
|
|
92
|
+
- 仅页面所有者或管理员能 create/update/delete
|
|
93
|
+
|
|
94
|
+
## schema business 元数据格式
|
|
95
|
+
|
|
96
|
+
字段结构写在 SQL migration 中,业务元数据在 `manifest.json` 的 `business.<table>` 中声明:
|
|
97
|
+
|
|
98
|
+
```sql
|
|
99
|
+
CREATE TABLE leaves (
|
|
100
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
101
|
+
title TEXT NOT NULL,
|
|
102
|
+
created_by TEXT,
|
|
103
|
+
status TEXT NOT NULL DEFAULT 'draft',
|
|
104
|
+
reviewed_by TEXT
|
|
105
|
+
);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"business": {
|
|
111
|
+
"leaves": {
|
|
112
|
+
"kind": "request",
|
|
113
|
+
"ownerField": "created_by",
|
|
114
|
+
"statusField": "status",
|
|
115
|
+
"statuses": ["draft", "submitted", "approved", "rejected"],
|
|
116
|
+
"recordAccess": {
|
|
117
|
+
"read": { "mode": "ownerField", "field": "created_by" },
|
|
118
|
+
"update": {
|
|
119
|
+
"mode": "ownerField",
|
|
120
|
+
"field": "created_by",
|
|
121
|
+
"when": { "status": ["draft"] }
|
|
122
|
+
},
|
|
123
|
+
"delete": {
|
|
124
|
+
"mode": "ownerField",
|
|
125
|
+
"field": "created_by",
|
|
126
|
+
"when": { "status": ["draft"] }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
字段含义:
|
|
135
|
+
- `kind`:业务形态(`request` / `assignment` / `catalog` / `personal`),主要给 Agent 和文档参考
|
|
136
|
+
- `ownerField`:记录所有者字段名,对应 `recordAccess` 中 `mode: "ownerField"` 的字段
|
|
137
|
+
- `assigneeField`:分配对象字段名,对应 `mode: "assigneeField"`
|
|
138
|
+
- `aclField`:访问控制列表字段名,对应 `mode: "aclField"`
|
|
139
|
+
- `statusField` + `statuses`:状态字段和合法值
|
|
140
|
+
- `recordAccess`:按动作(read/create/update/delete)声明策略
|
|
141
|
+
|
|
142
|
+
## 记录级访问模式
|
|
143
|
+
|
|
144
|
+
`recordAccess.<action>` 支持四种模式:
|
|
145
|
+
|
|
146
|
+
| 模式 | 语义 | 判断 |
|
|
147
|
+
|------|------|------|
|
|
148
|
+
| `authenticated` | 登录即可 | visitor 存在 |
|
|
149
|
+
| `ownerField` | 记录所有者 | `record[field] === currentUser.id` |
|
|
150
|
+
| `assigneeField` | 被分配人 | `record[field] === currentUser.id` |
|
|
151
|
+
| `aclField` | ACL 列表包含 | `record[field]` 包含 `currentUser.id` |
|
|
152
|
+
|
|
153
|
+
附加 `when` 条件限制状态:
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"mode": "ownerField",
|
|
157
|
+
"field": "created_by",
|
|
158
|
+
"when": { "status": ["draft"] }
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
表示"所有者且状态为 draft 时才能执行该动作"。
|
|
162
|
+
|
|
163
|
+
页面所有者(page owner)始终绕过记录级策略——在自己页面上能看到所有记录。
|
|
164
|
+
|
|
165
|
+
## 当前用户默认值(defaultFrom)
|
|
166
|
+
|
|
167
|
+
字段约束 `defaultFrom` 让后端在创建记录时自动填充:
|
|
168
|
+
|
|
169
|
+
- `"currentUser.id"`:填入当前用户 ID
|
|
170
|
+
- `"currentUser.name"`:填入当前用户显示名
|
|
171
|
+
|
|
172
|
+
请求体中显式传入同名字段时**会被后端覆盖**——这是为了防止前端伪造归属。
|
|
173
|
+
|
|
174
|
+
未登录用户对包含 `defaultFrom` 字段的 schema 创建记录时返回 401。
|
|
175
|
+
|
|
176
|
+
## 前端权限 UI
|
|
177
|
+
|
|
178
|
+
后端会自动执行记录级权限;前端用 SDK 同步判断显示哪些按钮:
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
import { usePermissions, Can } from "@localapp/sdk-react";
|
|
182
|
+
import type { DataSchemaLike } from "@localapp/sdk-react";
|
|
183
|
+
|
|
184
|
+
const leaveSchema: DataSchemaLike = {
|
|
185
|
+
business: {
|
|
186
|
+
ownerField: "created_by",
|
|
187
|
+
statusField: "status",
|
|
188
|
+
recordAccess: {
|
|
189
|
+
update: { mode: "ownerField", field: "created_by", when: { status: ["draft"] } },
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
function LeaveRow({ leave }: { leave: Leave }) {
|
|
195
|
+
const { can } = usePermissions();
|
|
196
|
+
const editable = can("update", leave, leaveSchema);
|
|
197
|
+
return (
|
|
198
|
+
<div>
|
|
199
|
+
<span>{leave.title}</span>
|
|
200
|
+
{editable && <Button size="sm">编辑</Button>}
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 或用 <Can> 组件
|
|
206
|
+
function LeaveRowDeclarative({ leave }: { leave: Leave }) {
|
|
207
|
+
return (
|
|
208
|
+
<div>
|
|
209
|
+
<span>{leave.title}</span>
|
|
210
|
+
<Can action="update" record={leave} schema={leaveSchema} fallback={null}>
|
|
211
|
+
<Button size="sm">编辑</Button>
|
|
212
|
+
</Can>
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**重要**:`usePermissions()` 和 `<Can>` 仅用于 UI 展示判断,后端 CRUD API 才是
|
|
219
|
+
记录级权限的安全边界。即使前端隐藏了按钮,直接调用 API 仍会经过完整的
|
|
220
|
+
权限校验。
|
|
221
|
+
|
|
222
|
+
## 常见场景
|
|
223
|
+
|
|
224
|
+
### 用户只能看自己的记录
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
"recordAccess": {
|
|
228
|
+
"read": { "mode": "ownerField", "field": "created_by" }
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
配合 `defaultFrom: "currentUser.id"` 在 created_by 字段上,列表自动只返回当前用户的记录。
|
|
232
|
+
|
|
233
|
+
### 草稿可编辑,提交后不可编辑
|
|
234
|
+
|
|
235
|
+
```json
|
|
236
|
+
"recordAccess": {
|
|
237
|
+
"update": {
|
|
238
|
+
"mode": "ownerField",
|
|
239
|
+
"field": "created_by",
|
|
240
|
+
"when": { "status": ["draft"] }
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### 负责人才能更新任务
|
|
246
|
+
|
|
247
|
+
```json
|
|
248
|
+
"recordAccess": {
|
|
249
|
+
"update": { "mode": "assigneeField", "field": "assignee_id" }
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### 全员可读,仅管理员可写
|
|
254
|
+
|
|
255
|
+
```json
|
|
256
|
+
"recordAccess": {
|
|
257
|
+
"read": { "mode": "authenticated" },
|
|
258
|
+
"create": { "mode": "authenticated" },
|
|
259
|
+
"update": { "mode": "authenticated" },
|
|
260
|
+
"delete": { "mode": "authenticated" }
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
(实际管理权限由页面 `pageAccess` 或路由 `routeAccess` 控制。)
|
|
264
|
+
|
|
265
|
+
## 开发模式验证业务规则
|
|
266
|
+
|
|
267
|
+
业务建模完成后运行 `localapp dev`,用 Dev Toolkit 做四类检查:
|
|
268
|
+
|
|
269
|
+
- Identity:切换申请人、负责人、审批人和未登录用户,确认 `recordAccess` 只返回当前视角应看到的记录。
|
|
270
|
+
- Time:固定 ISO 时间,执行包含 `"now"` 的 transition,确认时间字段、进度和截止日期视图稳定可复现。
|
|
271
|
+
- Data:通过 Dev Toolkit 让当前统一 Server 重置应用数据库,并用 snapshot/restore 快速回到关键业务状态。
|
|
272
|
+
- Diagnostics:查看 `manifest.business` 展示的 `recordAccess`、`defaultFields`、`transitions`、`enums` 是否与预期一致。
|
|
273
|
+
|
|
274
|
+
Dev Toolkit 操作后会触发 SDK hooks 自动刷新;不要通过前端硬编码过滤来模拟后端权限。
|
|
275
|
+
|
|
276
|
+
## 反模式
|
|
277
|
+
|
|
278
|
+
- ❌ 在 React 中用 `rows.filter(r => r.created_by === me.id)` 实现权限——前端过滤绕过服务端,应该在 named SQL 的 WHERE 子句里加 `created_by = :currentUserId`
|
|
279
|
+
- ❌ 用 raw SQL `useExec` 替代 named SQL 实现业务接口——raw SQL 端点已移除,且 named SQL 才能注入 `:currentUserId` 系统变量
|
|
280
|
+
- ❌ 在前端拼 `created_by: me.id` 写入请求——应该在 SQL 里直接用 `:currentUserId` 系统变量,前端伪造值会被忽略
|
|
281
|
+
- ❌ 为每种业务单独发明字段名(applicant、owner、creator 混用)——遵循本指南的 `created_by` / `assignee_id` / `reviewed_by` 约定
|
|
282
|
+
|
|
283
|
+
## 与其他 skill 的关系
|
|
284
|
+
|
|
285
|
+
- 字段类型、CRUD Hook 完整 API:见 `localapp-data.md`
|
|
286
|
+
- 用户身份、群组、ACL、登录:见 `localapp-auth.md`
|
|
287
|
+
- UI 组件:见 `localapp-ui.md`
|
|
288
|
+
|
|
289
|
+
## 业务状态变化用 transition mutation
|
|
290
|
+
|
|
291
|
+
带 `statusField` 的业务模型(请假/报销/任务等)几乎都需要状态迁移。
|
|
292
|
+
**不要用 `useUpdate` 直接改 status 字段**——它会绕过状态机合法性。
|
|
293
|
+
|
|
294
|
+
正确做法(两段式):
|
|
295
|
+
1. 在 `business.transitions[]` 中声明合法迁移(前端 UI 元数据)
|
|
296
|
+
2. 在 `backend/resources/<table>/mutations.json` 声明对应的 named mutation(实际执行入口)
|
|
297
|
+
3. 前端用 `useTransitions(resource, record, schema)` 本地计算可用按钮,调用 `transition(name)` 触发 mutate
|
|
298
|
+
|
|
299
|
+
```json
|
|
300
|
+
"business": {
|
|
301
|
+
"statusField": "status",
|
|
302
|
+
"initialStatus": "draft",
|
|
303
|
+
"transitions": [
|
|
304
|
+
{ "name": "submit", "label": "提交", "from": ["draft"], "to": "submitted" }
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
// backend/resources/leaves/mutations.json
|
|
311
|
+
"$leaves.submit": {
|
|
312
|
+
"kind": "mutation",
|
|
313
|
+
"access": "owner",
|
|
314
|
+
"params": { "id": { "type": "number", "required": true } },
|
|
315
|
+
"sql": "UPDATE leaves SET status='submitted', submitted_at=:now WHERE id=:id AND status='draft' AND created_by=:currentUserId"
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
```tsx
|
|
320
|
+
import { useTransitions } from "@localapp/sdk-react";
|
|
321
|
+
const { transitions, transition } = useTransitions("leaves", leave, leaveSchema);
|
|
322
|
+
transitions.map(t => <Button onClick={() => transition(t.name)}>{t.label}</Button>)
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
详细 transition 建模规则、SQL 守卫模板、access 字段配置见 `localapp-transitions.md`。
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: localapp-data
|
|
3
|
+
description: >
|
|
4
|
+
LocalApp 数据操作指南——Schema CRUD、backend named SQL、React SDK Hook 用法。
|
|
5
|
+
当用户要在 LocalApp 项目中使用数据存储、定义数据表、注册后端 SQL 查询、
|
|
6
|
+
使用 useList/useCreate/useUpdate/useDelete/useGet/useCount/useQuery/useMutation 等 Hook 时触发。
|
|
7
|
+
也适用于用户说"加个数据表"、"存储数据"、"查询数据"、"创建 schema"、
|
|
8
|
+
"用数据库"、"CRUD"、"增删改查"等场景。
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# LocalApp 数据操作
|
|
12
|
+
|
|
13
|
+
LocalApp 提供内置 SQLite 数据库,两种生产推荐方式:声明式 CRUD 和 backend named SQL。
|
|
14
|
+
|
|
15
|
+
## 模式选择
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
需求复杂度
|
|
19
|
+
低 ──────────────────── 高
|
|
20
|
+
│ │
|
|
21
|
+
▼ ▼
|
|
22
|
+
CRUD 模式 backend named SQL
|
|
23
|
+
(零后端代码) (注册 SQL)
|
|
24
|
+
│ │
|
|
25
|
+
│ 也可以混合使用 │
|
|
26
|
+
└─── backend 查询 ───────┘
|
|
27
|
+
复杂查询
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- **CRUD 模式**:写 SQL migration 创建表 → 自动获得 REST API + React Hook。适合简单增删改查。
|
|
31
|
+
- **backend named SQL**:把 JOIN、聚合、子查询等复杂操作注册到 `backend/resources/<resource>/queries.json` 或 `mutations.json`,前端只调用名字和参数。
|
|
32
|
+
- **混合**:CRUD 模式负责常规资源操作,复杂查询用 `client.query()` / `client.mutate()` 或 React hooks 调用注册 SQL。
|
|
33
|
+
|
|
34
|
+
## CRUD 模式
|
|
35
|
+
|
|
36
|
+
### SQL migration 流程
|
|
37
|
+
|
|
38
|
+
1. 在 `migrations/001_<description>.sql` 中写 SQLite DDL。
|
|
39
|
+
2. 运行 `localapp db reset` 重建项目 `tmp/localapp-schema/schema.db` 下的离线 schema 工作库。
|
|
40
|
+
3. 运行 `localapp db types -o src/types.ts` 从该工作库生成类型;它不承载运行时应用数据。
|
|
41
|
+
4. 安装前运行 `localapp db validate`,通过后再 `localapp app install --target <server-profile>`。
|
|
42
|
+
|
|
43
|
+
示例:
|
|
44
|
+
```sql
|
|
45
|
+
CREATE TABLE posts (
|
|
46
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
47
|
+
title TEXT NOT NULL,
|
|
48
|
+
content TEXT,
|
|
49
|
+
status TEXT NOT NULL DEFAULT 'draft',
|
|
50
|
+
views INTEGER NOT NULL DEFAULT 0,
|
|
51
|
+
published INTEGER NOT NULL DEFAULT 0,
|
|
52
|
+
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
53
|
+
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
54
|
+
);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
字段结构只由 SQL migration 管理;`manifest.business` 用于声明 ownerField、recordAccess、transitions、defaultFields、enums 等业务规则。
|
|
58
|
+
|
|
59
|
+
#### 当前用户默认值 `defaultFrom`
|
|
60
|
+
|
|
61
|
+
让后端在创建记录时自动填充当前用户字段,避免前端伪造:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"business": {
|
|
66
|
+
"leaves": {
|
|
67
|
+
"defaultFields": {
|
|
68
|
+
"created_by": { "defaultFrom": "currentUser.id" },
|
|
69
|
+
"reviewed_by": { "defaultFrom": "currentUser.name" }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
支持值:
|
|
77
|
+
- `"currentUser.id"` — 当前用户 ID
|
|
78
|
+
- `"currentUser.name"` — 当前用户显示名
|
|
79
|
+
|
|
80
|
+
请求体中显式传入同名字段会被后端覆盖(防伪造)。未登录用户创建包含 `defaultFrom` 的记录会返回 401。
|
|
81
|
+
|
|
82
|
+
#### 字段枚举 `enum`
|
|
83
|
+
|
|
84
|
+
限制字段只能取预设值,常配合状态字段使用:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"status": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"constraints": {
|
|
91
|
+
"defaultValue": "draft",
|
|
92
|
+
"enum": ["draft", "submitted", "approved", "rejected"]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
传入 `enum` 外的值会被后端拒绝并返回 400。
|
|
99
|
+
|
|
100
|
+
#### 业务模型元数据 `business`
|
|
101
|
+
|
|
102
|
+
在 `manifest.business.<table>` 声明业务约定:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"business": {
|
|
107
|
+
"leaves": {
|
|
108
|
+
"ownerField": "created_by",
|
|
109
|
+
"statusField": "status",
|
|
110
|
+
"enums": { "status": ["draft", "submitted", "approved"] },
|
|
111
|
+
"recordAccess": { "read": "owner", "update": "owner" }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`business` 字段含义:
|
|
118
|
+
- `kind`:业务形态(`request` / `assignment` / `catalog` / `personal`),主要供 Agent 参考
|
|
119
|
+
- `ownerField` / `assigneeField` / `aclField`:记录归属字段名
|
|
120
|
+
- `statusField` + `statuses`:状态字段名和合法值
|
|
121
|
+
- `recordAccess`:按动作(read/create/update/delete)声明记录级策略
|
|
122
|
+
|
|
123
|
+
#### 记录级访问控制 `recordAccess`
|
|
124
|
+
|
|
125
|
+
后端 CRUD API 自动执行,前端无法绕过。支持四种模式:
|
|
126
|
+
|
|
127
|
+
| 模式 | 语义 |
|
|
128
|
+
|------|------|
|
|
129
|
+
| `authenticated` | 登录即可 |
|
|
130
|
+
| `ownerField` | 记录所有者(`record[field] === currentUser.id`) |
|
|
131
|
+
| `assigneeField` | 被分配人 |
|
|
132
|
+
| `aclField` | ACL 字段包含当前用户 |
|
|
133
|
+
|
|
134
|
+
附加 `when` 限制状态:
|
|
135
|
+
```json
|
|
136
|
+
"update": {
|
|
137
|
+
"mode": "ownerField",
|
|
138
|
+
"field": "created_by",
|
|
139
|
+
"when": { "status": ["draft"] }
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
表示"所有者且状态为 draft 时才能更新"。
|
|
143
|
+
|
|
144
|
+
页面所有者(page owner)始终绕过记录级策略。详细约定和模型选择见 `localapp-business.md`。
|
|
145
|
+
|
|
146
|
+
**重要**:生产应用不要把 SQL 文本写进前端。涉及业务权限或复杂查询时,优先使用 CRUD API 或 backend named SQL;由后端执行权限检查并注入 `currentUserId`、`ownerId`、`now` 等系统参数。
|
|
147
|
+
|
|
148
|
+
#### 业务状态变化用 transition mutation(不要用 useUpdate)
|
|
149
|
+
|
|
150
|
+
如果业务模型有"状态"概念(如请假 draft→submitted→approved、任务 todo→done),**不要用 `useUpdate` 改 status 字段**——前端可以任意改状态,绕过了状态机的合法性。
|
|
151
|
+
|
|
152
|
+
正确做法:在 schema `business.transitions[]` 中声明合法迁移(前端 UI 元数据),在 `backend/resources/<table>/mutations.json` 声明对应的 named mutation(实际执行入口),前端用 `useTransitions()` Hook:
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
import { useTransitions } from "@localapp/sdk-react";
|
|
156
|
+
import type { BusinessMetadata } from "@localapp/sdk-react";
|
|
157
|
+
|
|
158
|
+
const leaveSchema: BusinessMetadata = {
|
|
159
|
+
statusField: "status",
|
|
160
|
+
transitions: [
|
|
161
|
+
{ name: "submit", label: "提交", from: ["draft"], to: "submitted" },
|
|
162
|
+
// ...
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const { transitions, transition } = useTransitions("leaves", leave, leaveSchema);
|
|
167
|
+
// transitions: 当前可用动作(根据 record.status 和 schema.transitions[from] 本地过滤)
|
|
168
|
+
// transition(name): 调用 mutate('$leaves.<name>', { id: leave.id, ...payload })
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
详细 transition 建模规则和 named mutation SQL 模板见 `localapp-transitions.md`。
|
|
172
|
+
|
|
173
|
+
### named SQL API(应用层唯一数据通道)
|
|
174
|
+
|
|
175
|
+
应用层数据读写**只**通过 named SQL 端点:
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
POST /api/queries/$<resource>.<action> 执行声明的 named query
|
|
179
|
+
POST /api/mutations/$<resource>.<action> 执行声明的 named mutation
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
应用必须在 `backend/resources/<resource>/{queries,mutations}.json` 中声明所有数据操作。
|
|
183
|
+
SDK helper 内部调用对应的 named SQL:
|
|
184
|
+
|
|
185
|
+
| SDK 调用 | 内部命名 SQL |
|
|
186
|
+
|---------|-------------|
|
|
187
|
+
| `client.list(resource)` | `$<resource>.list` |
|
|
188
|
+
| `client.get(resource, id)` | `$<resource>.get` |
|
|
189
|
+
| `client.count(resource)` | `$<resource>.count` |
|
|
190
|
+
| `client.create(resource, data)` | `$<resource>.create` |
|
|
191
|
+
| `client.update(resource, id, data)` | `$<resource>.update` |
|
|
192
|
+
| `client.delete(resource, id)` | `$<resource>.delete` |
|
|
193
|
+
|
|
194
|
+
未声明对应 named SQL 时,helper 直接抛 `LocalAppError`——不再 fallback 到 REST CRUD。
|
|
195
|
+
|
|
196
|
+
> **REST CRUD 端点(`GET /api/<resource>`、`POST /api/<resource>`、`GET /api/<resource>/:id`
|
|
197
|
+
> 等)已随 restrict-app-api-to-named-sql 变更整体移除。** 应用必须显式声明 named SQL
|
|
198
|
+
> 才能暴露数据操作。
|
|
199
|
+
|
|
200
|
+
列表查询参数:
|
|
201
|
+
```
|
|
202
|
+
?offset=0&limit=10&sort=created_at&order=desc&status=published
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
筛选运算符(追加 `__operator` 后缀到字段名):
|
|
206
|
+
```
|
|
207
|
+
status=published 精确匹配(默认)
|
|
208
|
+
priority__gte=3 大于等于
|
|
209
|
+
priority__lte=5 小于等于
|
|
210
|
+
priority__gt=1 大于
|
|
211
|
+
priority__lt=10 小于
|
|
212
|
+
status__ne=closed 不等于
|
|
213
|
+
title__like=%bug% 模糊匹配(LIKE)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### React SDK Hook
|
|
217
|
+
|
|
218
|
+
所有 Hook 从 `@localapp/sdk-react` 导入:
|
|
219
|
+
|
|
220
|
+
#### useList(resource, options?)
|
|
221
|
+
```tsx
|
|
222
|
+
const { rows, pagination, loading, error, refresh } = useList<Post>("posts", {
|
|
223
|
+
filters: { status: "published" },
|
|
224
|
+
offset: 0,
|
|
225
|
+
limit: 10,
|
|
226
|
+
sort: "created_at",
|
|
227
|
+
order: "desc",
|
|
228
|
+
});
|
|
229
|
+
// rows: T[]
|
|
230
|
+
// pagination: { offset, limit, total }
|
|
231
|
+
// refresh: () => Promise<void> 手动刷新
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
DevShell 中切换身份、固定时间、reset 或 restore snapshot 后会派发 `localapp:dev-context-changed`,`useList` / `useGet` / `useCount` 等订阅型 hooks 会自动刷新当前资源。验证 `recordAccess` 时,直接在 Dev Toolkit 的 Identity 里切换用户,再观察列表和详情是否变化。
|
|
235
|
+
|
|
236
|
+
#### useGet(resource, id)
|
|
237
|
+
```tsx
|
|
238
|
+
const { row, loading, error } = useGet<Post>("posts", 1);
|
|
239
|
+
// row: T | null
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### useCreate(resource, options?)
|
|
243
|
+
```tsx
|
|
244
|
+
const { create, loading, error } = useCreate<Post>("posts", { onSuccess: () => refresh() });
|
|
245
|
+
const newPost = await create({ title: "Hello", content: "World" });
|
|
246
|
+
// 返回创建的记录(含 id)
|
|
247
|
+
// loading: boolean — 调用中为 true
|
|
248
|
+
// error: LocalAppError | null — 失败时设置(同时 throw)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
#### useUpdate(resource, options?)
|
|
252
|
+
```tsx
|
|
253
|
+
const { update, loading, error } = useUpdate<Post>("posts", { onSuccess: () => refresh() });
|
|
254
|
+
const updated = await update(1, { title: "Updated" });
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
#### useDelete(resource, options?)
|
|
258
|
+
```tsx
|
|
259
|
+
const { remove, loading, error } = useDelete("posts", { onSuccess: () => refresh() });
|
|
260
|
+
await remove(1);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### useCount(resource, filters?)
|
|
264
|
+
```tsx
|
|
265
|
+
const { count, loading, error, refresh } = useCount("posts");
|
|
266
|
+
const { count: published } = useCount("posts", { status: "published" });
|
|
267
|
+
// refresh: () => Promise<void> 手动刷新计数
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
需要判断资源数量时,优先使用 `client.count()` 或 `useCount()`。不要把 `list({ limit: 1 })` / `list(limit: 1)` 当作常规计数写法;它只属于旧运行时兼容兜底,应用代码不应主动依赖这种绕法。
|
|
271
|
+
|
|
272
|
+
## Backend named SQL
|
|
273
|
+
|
|
274
|
+
复杂查询和自定义写入应注册为 backend 契约文件,而不是让前端提交任意 SQL。
|
|
275
|
+
|
|
276
|
+
示例目录:
|
|
277
|
+
```
|
|
278
|
+
backend/
|
|
279
|
+
resources/
|
|
280
|
+
posts/
|
|
281
|
+
schema.json
|
|
282
|
+
queries.json
|
|
283
|
+
mutations.json
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
`queries.json` 示例:
|
|
287
|
+
```json
|
|
288
|
+
{
|
|
289
|
+
"$schema": "https://localapp.dev/schemas/backend/queries.schema.json",
|
|
290
|
+
"queries": {
|
|
291
|
+
"posts.popular": {
|
|
292
|
+
"kind": "query",
|
|
293
|
+
"sql": "SELECT id, title, views FROM posts WHERE views >= :minViews ORDER BY views DESC LIMIT :limit OFFSET :offset",
|
|
294
|
+
"params": {
|
|
295
|
+
"minViews": { "type": "number", "required": true },
|
|
296
|
+
"limit": { "type": "number", "required": true },
|
|
297
|
+
"offset": { "type": "number", "required": true }
|
|
298
|
+
},
|
|
299
|
+
"result": { "mode": "page", "maxRows": 100, "maxBytes": 65536 },
|
|
300
|
+
"access": "authenticated"
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
前端调用:
|
|
307
|
+
```tsx
|
|
308
|
+
import { useQuery, useMutation } from "@localapp/sdk-react";
|
|
309
|
+
|
|
310
|
+
const { query } = useQuery();
|
|
311
|
+
const popular = await query("posts.popular", { minViews: 100, limit: 20, offset: 0 });
|
|
312
|
+
|
|
313
|
+
const { mutate } = useMutation();
|
|
314
|
+
await mutate("posts.publish", { id: postId });
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
也可以直接用 core SDK:
|
|
318
|
+
```ts
|
|
319
|
+
const result = await client.query("posts.popular", { minViews: 100, limit: 20, offset: 0 });
|
|
320
|
+
await client.mutate("posts.publish", { id: postId });
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
系统参数由后端注入,前端不能覆盖:
|
|
324
|
+
- `:currentUserId`
|
|
325
|
+
- `:ownerId`
|
|
326
|
+
- `:now`
|
|
327
|
+
|
|
328
|
+
> **没有 raw SQL 端点**——`useExec` Hook 和 `client.exec()` 方法已随 restrict-app-api-to-named-sql
|
|
329
|
+
> 变更整体移除。所有数据操作必须声明为 named SQL,通过 `client.query()` / `client.mutate()`
|
|
330
|
+
> 或对应的 React Hook 调用。开发期需要直接观察数据库时,开发者可以直接操作 SQLite 文件。
|
|
331
|
+
|
|
332
|
+
## 常见模式
|
|
333
|
+
|
|
334
|
+
### 列表 + 创建表单
|
|
335
|
+
```tsx
|
|
336
|
+
function TodoApp() {
|
|
337
|
+
const { rows, loading, refresh } = useList<Todo>("todos");
|
|
338
|
+
const { create } = useCreate<Todo>("todos");
|
|
339
|
+
|
|
340
|
+
const handleAdd = async (title: string) => {
|
|
341
|
+
await create({ title, done: false });
|
|
342
|
+
refresh();
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
if (loading) return <p>加载中...</p>;
|
|
346
|
+
return (
|
|
347
|
+
<div>
|
|
348
|
+
<form onSubmit={async (e) => {
|
|
349
|
+
e.preventDefault();
|
|
350
|
+
const input = (e.target as HTMLFormElement).elements[0] as HTMLInputElement;
|
|
351
|
+
await handleAdd(input.value);
|
|
352
|
+
input.value = "";
|
|
353
|
+
}}>
|
|
354
|
+
<input name="title" required />
|
|
355
|
+
<button type="submit">添加</button>
|
|
356
|
+
</form>
|
|
357
|
+
<ul>{rows.map(t => <li key={t.id}>{t.title}</li>)}</ul>
|
|
358
|
+
</div>
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### 主从关系(两张表关联)
|
|
364
|
+
```sql
|
|
365
|
+
CREATE TABLE posts (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL);
|
|
366
|
+
CREATE TABLE comments (id INTEGER PRIMARY KEY AUTOINCREMENT, post_id INTEGER NOT NULL, content TEXT);
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
```tsx
|
|
370
|
+
function PostWithComments({ postId }: { postId: number }) {
|
|
371
|
+
const { row } = useGet("posts", postId);
|
|
372
|
+
const { rows } = useList("comments", { filters: { post_id: postId } });
|
|
373
|
+
|
|
374
|
+
return (
|
|
375
|
+
<div>
|
|
376
|
+
<h1>{row?.title}</h1>
|
|
377
|
+
{rows.map(c => <p key={c.id}>{c.content}</p>)}
|
|
378
|
+
</div>
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
```
|