oneie 2.0.1 → 2.0.3
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/AGENTS.md +245 -0
- package/CLAUDE.md +534 -0
- package/README.md +61 -4
- package/one/.obsidian/app.json +1 -0
- package/one/.obsidian/appearance.json +1 -0
- package/one/.obsidian/core-plugins.json +33 -0
- package/one/.obsidian/workspace.json +211 -0
- package/one/connections/a2a.md +551 -0
- package/one/connections/acp.md +761 -0
- package/one/connections/acps.md +731 -0
- package/one/connections/agui.md +767 -0
- package/one/connections/any-backend.md +1702 -0
- package/one/connections/ap2.md +998 -0
- package/one/connections/api-docs.md +1891 -0
- package/one/connections/api.md +2190 -0
- package/one/connections/architecture-diagram.md +94 -0
- package/one/connections/communications.md +449 -0
- package/one/connections/connections.md +339 -0
- package/one/connections/cryptonetworks.md +781 -0
- package/one/connections/documentation.md +1120 -0
- package/one/connections/effect.md +279 -0
- package/one/connections/elizaos.md +1290 -0
- package/one/connections/inference.md +58 -0
- package/one/connections/kyc.md +632 -0
- package/one/connections/mcp.md +842 -0
- package/one/connections/membership.md +1152 -0
- package/one/connections/middleware.md +1067 -0
- package/one/connections/multitenant.md +1341 -0
- package/one/connections/n8n.md +1015 -0
- package/one/connections/patterns.md +89 -0
- package/one/connections/protocols.md +279 -0
- package/one/connections/relationships.md +107 -0
- package/one/connections/schema.md +587 -0
- package/one/connections/service-layer.md +550 -0
- package/one/connections/structure.md +0 -0
- package/one/connections/vectors.md +207 -0
- package/one/connections/wordpress.md +1302 -0
- package/one/connections/workflow-copy.md +905 -0
- package/one/connections/workflow-examples.md +741 -0
- package/one/connections/workflow.md +905 -0
- package/one/connections/workflows/delegation.md +885 -0
- package/one/connections/workflows/frontend.md +1037 -0
- package/one/connections/workflows/strategy.md +903 -0
- package/one/connections/workflows/tasks.md +698 -0
- package/one/connections/x402.md +1249 -0
- package/one/events/events.md +545 -0
- package/one/knowledge/ai-platform.md +305 -0
- package/one/knowledge/architecture-diagram.md +94 -0
- package/one/knowledge/architecture-frontend.md +930 -0
- package/one/knowledge/architecture.md +2077 -0
- package/one/knowledge/crypto.md +960 -0
- package/one/knowledge/dsl.md +1660 -0
- package/one/knowledge/files.md +2471 -0
- package/one/knowledge/frontend.md +1038 -0
- package/one/knowledge/hono.md +2109 -0
- package/one/knowledge/implementation-examples.md +2536 -0
- package/one/knowledge/inference-score.md +159 -0
- package/one/knowledge/knowledge.md +642 -0
- package/one/knowledge/language.md +980 -0
- package/one/knowledge/lessons-learned.md +70 -0
- package/one/knowledge/ontology-6-dimensions.md +0 -0
- package/one/knowledge/ontology-documentation.md +356 -0
- package/one/knowledge/ontology-engineering-specification.md +1292 -0
- package/one/knowledge/ontology-engineering.md +1652 -0
- package/one/knowledge/ontology-frontend-copy-2.md +1492 -0
- package/one/knowledge/ontology-frontend-copy.md +753 -0
- package/one/knowledge/ontology-frontend-specifications.md +2188 -0
- package/one/knowledge/ontology-frontend.md +2427 -0
- package/one/knowledge/ontology-minimal.yaml +299 -0
- package/one/knowledge/ontology.md +2819 -0
- package/one/knowledge/ontology.yaml +1165 -0
- package/one/knowledge/patterns/backend/convex-mutation-pattern.md +100 -0
- package/one/knowledge/patterns/backend/convex-query-pattern.md +88 -0
- package/one/knowledge/patterns/backend/mutation-template.md +231 -0
- package/one/knowledge/patterns/backend/query-template.md +267 -0
- package/one/knowledge/patterns/backend/service-template.md +237 -0
- package/one/knowledge/patterns/design/component-architecture.md +399 -0
- package/one/knowledge/patterns/design/test-driven-design-pattern.md +162 -0
- package/one/knowledge/patterns/design/wireframe-template.md +216 -0
- package/one/knowledge/patterns/frontend/component-template.md +195 -0
- package/one/knowledge/patterns/frontend/form-template.md +276 -0
- package/one/knowledge/patterns/frontend/page-template.md +178 -0
- package/one/knowledge/patterns/frontend/react-component-pattern.md +128 -0
- package/one/knowledge/patterns/test/acceptance-criteria-template.md +378 -0
- package/one/knowledge/patterns/test/technical-test-template.md +544 -0
- package/one/knowledge/patterns/test/test-driven-pattern.md +140 -0
- package/one/knowledge/patterns/test/user-flow-template.md +254 -0
- package/one/knowledge/quality-loop.md +401 -0
- package/one/knowledge/readme.md +131 -0
- package/one/knowledge/rules.md +626 -0
- package/one/knowledge/score.md +67 -0
- package/one/knowledge/specifications.md +855 -0
- package/one/knowledge/tags.md +130 -0
- package/one/organisation/one.md +599 -0
- package/one/organisation/organisation.md +438 -0
- package/one/organisation/revenue.md +673 -0
- package/one/organisation/strategy.md +869 -0
- package/one/organisation/vision.md +98 -0
- package/one/people/anthony-o-connell.md +440 -0
- package/one/people/people.md +567 -0
- package/one/repomix-output.md +92634 -0
- package/one/things/agentkit.md +349 -0
- package/one/things/agents/agent-backend.md +1401 -0
- package/one/things/agents/agent-builder.md +955 -0
- package/one/things/agents/agent-clean.md +709 -0
- package/one/things/agents/agent-clone.md +1341 -0
- package/one/things/agents/agent-designer.md +2177 -0
- package/one/things/agents/agent-director.md +1508 -0
- package/one/things/agents/agent-documenter.md +1049 -0
- package/one/things/agents/agent-frontend.md +1119 -0
- package/one/things/agents/agent-integrator.md +1192 -0
- package/one/things/agents/agent-problem-solver.md +1379 -0
- package/one/things/agents/agent-quality.md +1353 -0
- package/one/things/agents/agent-sales.md +986 -0
- package/one/things/cascade/cascade.yaml +464 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +470 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +264 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts.md +486 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +516 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +544 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +223 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination.md +508 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +609 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +195 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management.md +577 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +797 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +212 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops.md +641 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +610 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +213 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure.md +575 -0
- package/one/things/cascade/docs/examples/readme.md +222 -0
- package/one/things/cascade/docs/getting-started.md +515 -0
- package/one/things/cascade/docs/workflow.md +1372 -0
- package/one/things/cascade/readme.md +336 -0
- package/one/things/cascade/templates/feature-template.md +267 -0
- package/one/things/claude/agents/advocacy-activation-manager.md +685 -0
- package/one/things/claude/agents/advocacy-campaign-designer.md +663 -0
- package/one/things/claude/agents/analyst.md +483 -0
- package/one/things/claude/agents/architect.md +480 -0
- package/one/things/claude/agents/brand-identity-specialist.md +513 -0
- package/one/things/claude/agents/bstp-token-strategist.md +667 -0
- package/one/things/claude/agents/builder-repo.md +489 -0
- package/one/things/claude/agents/bullstamp-community-builder.md +574 -0
- package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +506 -0
- package/one/things/claude/agents/bulltilt-platform-growth.md +567 -0
- package/one/things/claude/agents/company-bullstamp-character.md +587 -0
- package/one/things/claude/agents/company-bullstamp-community.md +292 -0
- package/one/things/claude/agents/company-bullstamp-marketing.md +292 -0
- package/one/things/claude/agents/company-bullstamp-token.md +292 -0
- package/one/things/claude/agents/company-bulltilt-growth.md +292 -0
- package/one/things/claude/agents/content-bibliography-formatter.md +381 -0
- package/one/things/claude/agents/content-calendar-planner.md +448 -0
- package/one/things/claude/agents/content-chapter-formatter.md +488 -0
- package/one/things/claude/agents/content-formatter.md +546 -0
- package/one/things/claude/agents/content-hook-specialist.md +462 -0
- package/one/things/claude/agents/content-image-formatter.md +535 -0
- package/one/things/claude/agents/content-introduction-formatter.md +485 -0
- package/one/things/claude/agents/content-multiplication-engine.md +556 -0
- package/one/things/claude/agents/content-playbook-writer.md +448 -0
- package/one/things/claude/agents/content-team-manager.md +622 -0
- package/one/things/claude/agents/content-toc-formatter.md +522 -0
- package/one/things/claude/agents/convex-backend-specialist.md +2561 -0
- package/one/things/claude/agents/core-manager.md +582 -0
- package/one/things/claude/agents/core-master.md +403 -0
- package/one/things/claude/agents/cross-functional-manager.md +471 -0
- package/one/things/claude/agents/crypto-airdrop-strategist.md +602 -0
- package/one/things/claude/agents/crypto-analytics-educator.md +553 -0
- package/one/things/claude/agents/crypto-architecture-specialist.md +466 -0
- package/one/things/claude/agents/crypto-community-analyst.md +298 -0
- package/one/things/claude/agents/crypto-community-psychologist.md +509 -0
- package/one/things/claude/agents/crypto-dex-optimization-expert.md +538 -0
- package/one/things/claude/agents/crypto-dex-optimizer.md +292 -0
- package/one/things/claude/agents/crypto-diamond-formation-specialist.md +513 -0
- package/one/things/claude/agents/crypto-diamond-hands.md +292 -0
- package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +554 -0
- package/one/things/claude/agents/crypto-engagement-specialist.md +540 -0
- package/one/things/claude/agents/crypto-market-researcher.md +292 -0
- package/one/things/claude/agents/crypto-marketing-orchestrator.md +523 -0
- package/one/things/claude/agents/crypto-network-effect-amplifier.md +569 -0
- package/one/things/claude/agents/crypto-optimization-analyst.md +554 -0
- package/one/things/claude/agents/crypto-strategic-synthesizer.md +517 -0
- package/one/things/claude/agents/crypto-team-manager.md +387 -0
- package/one/things/claude/agents/crypto-token-analyst.md +278 -0
- package/one/things/claude/agents/crypto-viral-content-creator.md +546 -0
- package/one/things/claude/agents/crypto-wallet-identification-expert.md +517 -0
- package/one/things/claude/agents/crypto-wallet-identifier.md +292 -0
- package/one/things/claude/agents/customer-journey-designer.md +481 -0
- package/one/things/claude/agents/customer-success-manager.md +581 -0
- package/one/things/claude/agents/dev.md +413 -0
- package/one/things/claude/agents/documenter.md +546 -0
- package/one/things/claude/agents/elevate-marketing-orchestrator.md +410 -0
- package/one/things/claude/agents/engagement-specialist.md +509 -0
- package/one/things/claude/agents/engineering-architect.md +387 -0
- package/one/things/claude/agents/engineering-business-analyst.md +537 -0
- package/one/things/claude/agents/engineering-developer.md +387 -0
- package/one/things/claude/agents/engineering-director.md +282 -0
- package/one/things/claude/agents/engineering-ingestor.md +649 -0
- package/one/things/claude/agents/engineering-product-manager.md +537 -0
- package/one/things/claude/agents/engineering-product-owner.md +537 -0
- package/one/things/claude/agents/engineering-project-coordinator.md +537 -0
- package/one/things/claude/agents/engineering-quality-assurance.md +393 -0
- package/one/things/claude/agents/engineering-team-manager.md +512 -0
- package/one/things/claude/agents/engineering-user-experience.md +387 -0
- package/one/things/claude/agents/framework-elevate-manager.md +294 -0
- package/one/things/claude/agents/improver.md +763 -0
- package/one/things/claude/agents/intelligence-team-manager.md +385 -0
- package/one/things/claude/agents/lead-capture-expert.md +466 -0
- package/one/things/claude/agents/lead-magnet-creator.md +453 -0
- package/one/things/claude/agents/market-research-analyst.md +412 -0
- package/one/things/claude/agents/marketing-brand-identity.md +314 -0
- package/one/things/claude/agents/marketing-content-hooks.md +450 -0
- package/one/things/claude/agents/marketing-content-multiplier.md +326 -0
- package/one/things/claude/agents/marketing-content-poster.md +361 -0
- package/one/things/claude/agents/marketing-customer-journey.md +326 -0
- package/one/things/claude/agents/marketing-director.md +397 -0
- package/one/things/claude/agents/marketing-engagement.md +326 -0
- package/one/things/claude/agents/marketing-lead-capture.md +326 -0
- package/one/things/claude/agents/marketing-lead-magnet.md +326 -0
- package/one/things/claude/agents/marketing-network-effects.md +326 -0
- package/one/things/claude/agents/marketing-nurture-campaigns.md +326 -0
- package/one/things/claude/agents/marketing-share-optimizer.md +326 -0
- package/one/things/claude/agents/marketing-team-manager.md +446 -0
- package/one/things/claude/agents/marketing-viral-growth.md +201 -0
- package/one/things/claude/agents/mission-commander.md +373 -0
- package/one/things/claude/agents/network-effect-analyst.md +587 -0
- package/one/things/claude/agents/nextjs-15-specialist.md +1547 -0
- package/one/things/claude/agents/npx.md +890 -0
- package/one/things/claude/agents/nurture-campaign-manager.md +531 -0
- package/one/things/claude/agents/one-master.md +355 -0
- package/one/things/claude/agents/one-orchestrator.md +315 -0
- package/one/things/claude/agents/one.md +601 -0
- package/one/things/claude/agents/playbook-generator.md +503 -0
- package/one/things/claude/agents/pm.md +326 -0
- package/one/things/claude/agents/po.md +345 -0
- package/one/things/claude/agents/qa.md +336 -0
- package/one/things/claude/agents/research-foundation-analyst.md +307 -0
- package/one/things/claude/agents/research-intelligence-gatherer.md +408 -0
- package/one/things/claude/agents/research-market-analyst.md +307 -0
- package/one/things/claude/agents/research-team-manager.md +482 -0
- package/one/things/claude/agents/sales-environment-optimizer.md +494 -0
- package/one/things/claude/agents/sales-team-manager.md +400 -0
- package/one/things/claude/agents/sales-upsell-strategist.md +307 -0
- package/one/things/claude/agents/service-advocacy-campaigns.md +307 -0
- package/one/things/claude/agents/service-advocacy-manager.md +307 -0
- package/one/things/claude/agents/service-success-manager.md +307 -0
- package/one/things/claude/agents/service-team-manager.md +400 -0
- package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +2302 -0
- package/one/things/claude/agents/share-optimization-specialist.md +551 -0
- package/one/things/claude/agents/sm.md +327 -0
- package/one/things/claude/agents/story-teller.md +473 -0
- package/one/things/claude/agents/task-master.md +596 -0
- package/one/things/claude/agents/tauri-cross-platform-specialist.md +1827 -0
- package/one/things/claude/agents/tester.md +556 -0
- package/one/things/claude/agents/the-bull-character-manager.md +580 -0
- package/one/things/claude/agents/tools-playbook-generator.md +489 -0
- package/one/things/claude/agents/turbo-repo-builder.md +316 -0
- package/one/things/claude/agents/upsell-strategist.md +480 -0
- package/one/things/claude/agents/ux-expert.md +335 -0
- package/one/things/claude/agents/viral-growth-orchestrator.md +497 -0
- package/one/things/claude/claude-code-hooks-development.json +21 -0
- package/one/things/claude/claude-code-hooks-production.json +21 -0
- package/one/things/claude/claude-code-hooks.json +25 -0
- package/one/things/claude/commands/agent.md +104 -0
- package/one/things/claude/commands/cascade-status.md +128 -0
- package/one/things/claude/commands/ingest.md +290 -0
- package/one/things/claude/commands/ingestor.md +136 -0
- package/one/things/claude/commands/mission.md +83 -0
- package/one/things/claude/commands/npx.md +133 -0
- package/one/things/claude/commands/one.md +440 -0
- package/one/things/claude/commands/quality-check.md +204 -0
- package/one/things/claude/commands/smart-route.md +220 -0
- package/one/things/claude/commands/start.md +121 -0
- package/one/things/claude/commands/story.md +83 -0
- package/one/things/claude/commands/task.md +173 -0
- package/one/things/claude/hook-bypass.json +32 -0
- package/one/things/claude/hooks/agent-hook-config.json +427 -0
- package/one/things/claude/hooks/agent-hook-manager.js +525 -0
- package/one/things/claude/hooks/agent-load-balancer.js +271 -0
- package/one/things/claude/hooks/agent-request-interceptor.js +70 -0
- package/one/things/claude/hooks/build-hook.sh +156 -0
- package/one/things/claude/hooks/cascade-feedback.js +297 -0
- package/one/things/claude/hooks/cascade-integration-hooks.js +648 -0
- package/one/things/claude/hooks/cleanup-hook.sh +201 -0
- package/one/things/claude/hooks/continuous-improvement-monitor.js +510 -0
- package/one/things/claude/hooks/file-organization-engine.js +427 -0
- package/one/things/claude/hooks/file-organization-hook.sh +80 -0
- package/one/things/claude/hooks/file-organization-monitor.js +269 -0
- package/one/things/claude/hooks/format-hook.sh +43 -0
- package/one/things/claude/hooks/hook-bypass.sh +293 -0
- package/one/things/claude/hooks/hook-config-manager.js +202 -0
- package/one/things/claude/hooks/hook-debouncer.sh +62 -0
- package/one/things/claude/hooks/hook-logger.sh +89 -0
- package/one/things/claude/hooks/hook-orchestrator.js +662 -0
- package/one/things/claude/hooks/hook-performance-report.js +120 -0
- package/one/things/claude/hooks/lint-hook.sh +140 -0
- package/one/things/claude/hooks/mcp-cascade-integration.js +816 -0
- package/one/things/claude/hooks/memory-optimizer.js +510 -0
- package/one/things/claude/hooks/notification-hook.sh +204 -0
- package/one/things/claude/hooks/ontology-compliance.js +394 -0
- package/one/things/claude/hooks/ontology-hook-manager.js +316 -0
- package/one/things/claude/hooks/ontology-validation-engine.js +317 -0
- package/one/things/claude/hooks/ontology-validation-hook.sh +86 -0
- package/one/things/claude/hooks/performance-metrics.json +25 -0
- package/one/things/claude/hooks/performance-monitoring-hook.js +422 -0
- package/one/things/claude/hooks/quality-scoring-engine.js +834 -0
- package/one/things/claude/hooks/security-hook.sh +256 -0
- package/one/things/claude/hooks/simple-load-balancer.js +238 -0
- package/one/things/claude/hooks/startup-optimizer.js +625 -0
- package/one/things/claude/hooks/story-scoring-system.js +445 -0
- package/one/things/claude/hooks/story-validation-engine.js +473 -0
- package/one/things/claude/hooks/story-validation-hook-enhanced.sh +210 -0
- package/one/things/claude/hooks/story-validation-hook.sh +145 -0
- package/one/things/claude/hooks/structure-synchronizer.js +194 -0
- package/one/things/claude/hooks/sub-agent-output-validator.js +647 -0
- package/one/things/claude/hooks/sub-agent-validation-hook.js +343 -0
- package/one/things/claude/hooks/test-hook.sh +145 -0
- package/one/things/claude/hooks/test-story-validation.sh +170 -0
- package/one/things/claude/hooks/trinity-validation-system.js +392 -0
- package/one/things/claude/settings-local.json +86 -0
- package/one/things/cli-code.md +652 -0
- package/one/things/cli-compiler-code.md +652 -0
- package/one/things/cli.md +1045 -0
- package/one/things/components/card-shadcn.md +929 -0
- package/one/things/components/card.md +1050 -0
- package/one/things/components.md +1669 -0
- package/one/things/componets.md +4 -0
- package/one/things/copilotkit.md +1559 -0
- package/one/things/creator-diagram.md +166 -0
- package/one/things/examples/children/lemonade-stand.md +366 -0
- package/one/things/examples/enterprise/crm-saas.md +1429 -0
- package/one/things/features/1-1-agent-prompts/design.md +470 -0
- package/one/things/features/1-1-agent-prompts/tests.md +264 -0
- package/one/things/features/1-1-agent-prompts.md +486 -0
- package/one/things/features/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/features/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/features/1-2-yaml-orchestrator.md +516 -0
- package/one/things/features/1-3-event-coordination/design.md +544 -0
- package/one/things/features/1-3-event-coordination/tests.md +223 -0
- package/one/things/features/1-3-event-coordination.md +508 -0
- package/one/things/features/1-4-knowledge-management/design.md +609 -0
- package/one/things/features/1-4-knowledge-management/tests.md +195 -0
- package/one/things/features/1-4-knowledge-management.md +577 -0
- package/one/things/features/1-5-quality-loops/design.md +797 -0
- package/one/things/features/1-5-quality-loops/tests.md +212 -0
- package/one/things/features/1-5-quality-loops.md +641 -0
- package/one/things/features/1-6-numbering-structure/design.md +610 -0
- package/one/things/features/1-6-numbering-structure/tests.md +213 -0
- package/one/things/features/1-6-numbering-structure.md +575 -0
- package/one/things/features/2-cli.md +1235 -0
- package/one/things/features/use-one-backend.md +1180 -0
- package/one/things/ideas/1-create-workflow.md +189 -0
- package/one/things/plans/1-create-workflow-status.md +555 -0
- package/one/things/plans/1-create-workflow.md +713 -0
- package/one/things/plans/app.md +761 -0
- package/one/things/plans/better-auth-any-backend-revised.md +1065 -0
- package/one/things/plans/better-auth-any-backend.md +1852 -0
- package/one/things/plans/better-auth-available-features.md +235 -0
- package/one/things/plans/big-plan.md +38 -0
- package/one/things/plans/convex-better-auth.md +1109 -0
- package/one/things/plans/convex-on-off.md +389 -0
- package/one/things/plans/desktop.md +1121 -0
- package/one/things/plans/effect-components.md +1669 -0
- package/one/things/plans/effect.md +973 -0
- package/one/things/plans/email.md +953 -0
- package/one/things/plans/enhance-auth.md +1669 -0
- package/one/things/plans/install-components.md +198 -0
- package/one/things/plans/landing.md +728 -0
- package/one/things/plans/layout.md +205 -0
- package/one/things/plans/mail-backend.md +1308 -0
- package/one/things/plans/mail.md +2624 -0
- package/one/things/plans/next-features.md +83 -0
- package/one/things/plans/one.md +658 -0
- package/one/things/plans/ontology-6-dimensions.md +2216 -0
- package/one/things/plans/ontology-driven-strategy.md +866 -0
- package/one/things/plans/ontology-ui-approach.md +357 -0
- package/one/things/plans/open-agent.md +785 -0
- package/one/things/plans/performace.md +90 -0
- package/one/things/plans/releases.md +809 -0
- package/one/things/plans/repos.md +76 -0
- package/one/things/plans/separate-copy-2.md +1293 -0
- package/one/things/plans/separate-copy-3.md +2458 -0
- package/one/things/plans/separate-copy.md +1293 -0
- package/one/things/plans/separate.md +1983 -0
- package/one/things/plans/shadcn-integration-summary.md +450 -0
- package/one/things/plans/sidebar.md +172 -0
- package/one/things/plans/small-fixes.md +5 -0
- package/one/things/plans/test-backend-connection.md +476 -0
- package/one/things/plans/workflow-files.md +1196 -0
- package/one/things/plans/workflow.md +1372 -0
- package/one/things/products/cascade-landing-page.md +737 -0
- package/one/things/products/cascade.md +1518 -0
- package/one/things/products/context-engineering.md +1427 -0
- package/one/things/products/onthology.md +0 -0
- package/one/things/products/ontology-ui-shadcn.md +1280 -0
- package/one/things/products/ontology-ui.md +1387 -0
- package/one/things/products/ontology.md +717 -0
- package/one/things/products/sdk.md +557 -0
- package/one/things/promptkit.md +903 -0
- package/one/things/service-providers-new.md +982 -0
- package/one/things/service-providers.md +1092 -0
- package/one/things/things.md +349 -0
- package/one/things/todo.md +1248 -0
- package/package.json +5 -2
|
@@ -0,0 +1,1702 @@
|
|
|
1
|
+
# Connecting ONE to Any Backend
|
|
2
|
+
|
|
3
|
+
**Universal backend adapter pattern for ONE platform**
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Executive Summary
|
|
8
|
+
|
|
9
|
+
ONE's frontend is **100% backend-agnostic**. This guide shows how to connect to **any backend** (databases, APIs, CMS platforms, SaaS tools) by implementing the universal `DataProvider` interface.
|
|
10
|
+
|
|
11
|
+
**Key Principle:** Frontend talks to `DataProvider` interface. You implement `DataProvider` for your backend. Done.
|
|
12
|
+
|
|
13
|
+
**Supported Backends:**
|
|
14
|
+
- ✅ **Databases**: Convex, Supabase, Neon, PlanetScale, MongoDB, PostgreSQL, MySQL
|
|
15
|
+
- ✅ **CMS**: WordPress, Strapi, Contentful, Sanity, Ghost, Prismic
|
|
16
|
+
- ✅ **Headless**: Notion, Airtable, Google Sheets, Excel Online
|
|
17
|
+
- ✅ **SaaS APIs**: Salesforce, HubSpot, Shopify, Stripe
|
|
18
|
+
- ✅ **Custom**: Your own REST/GraphQL API
|
|
19
|
+
|
|
20
|
+
**What This Achieves:**
|
|
21
|
+
- Change backend with ONE line of code
|
|
22
|
+
- Use multiple backends simultaneously
|
|
23
|
+
- Mix backends (WordPress + Supabase + Custom API)
|
|
24
|
+
- No vendor lock-in
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Table of Contents
|
|
29
|
+
|
|
30
|
+
1. [Architecture Overview](#architecture-overview)
|
|
31
|
+
2. [DataProvider Interface](#dataprovider-interface)
|
|
32
|
+
3. [Implementation Patterns](#implementation-patterns)
|
|
33
|
+
4. [Database Backends](#database-backends)
|
|
34
|
+
5. [CMS Backends](#cms-backends)
|
|
35
|
+
6. [SaaS API Backends](#saas-api-backends)
|
|
36
|
+
7. [Custom Backends](#custom-backends)
|
|
37
|
+
8. [Multi-Backend Setup](#multi-backend-setup)
|
|
38
|
+
9. [Testing](#testing)
|
|
39
|
+
10. [Deployment](#deployment)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Architecture Overview
|
|
44
|
+
|
|
45
|
+
### The Universal Pattern
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
┌────────────────────────────────────────────────┐
|
|
49
|
+
│ ONE Frontend (Astro + React) │
|
|
50
|
+
│ ✅ Renders UI │
|
|
51
|
+
│ ✅ Calls DataProvider interface │
|
|
52
|
+
│ ✅ Backend-agnostic components │
|
|
53
|
+
│ ❌ NO backend-specific code │
|
|
54
|
+
└────────────────┬───────────────────────────────┘
|
|
55
|
+
│ DataProvider Interface
|
|
56
|
+
│ (Universal API = ONE Ontology)
|
|
57
|
+
↓
|
|
58
|
+
┌────────────────────────────────────────────────┐
|
|
59
|
+
│ Provider Layer (You Implement) │
|
|
60
|
+
│ - things.get(id) │
|
|
61
|
+
│ - things.list(type) │
|
|
62
|
+
│ - things.create(data) │
|
|
63
|
+
│ - connections.create(from, to) │
|
|
64
|
+
│ - events.log(event) │
|
|
65
|
+
│ - knowledge.search(query) │
|
|
66
|
+
└────────────────┬───────────────────────────────┘
|
|
67
|
+
│ Backend-Specific Implementation
|
|
68
|
+
┌───────────┼───────────┬───────────┬───────────┐
|
|
69
|
+
↓ ↓ ↓ ↓ ↓
|
|
70
|
+
┌─────────┐ ┌─────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
|
|
71
|
+
│ Convex │ │Supabase │ │WordPress │ │ Notion │ │ Custom │
|
|
72
|
+
│ │ │ │ │ │ │ │ │ API │
|
|
73
|
+
└─────────┘ └─────────┘ └──────────┘ └──────────┘ └──────────┘
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Key Insight:** Frontend never imports backend-specific code. Only imports `DataProvider` interface.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## DataProvider Interface
|
|
81
|
+
|
|
82
|
+
### The Contract
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// frontend/src/providers/DataProvider.ts
|
|
86
|
+
import { Effect } from 'effect'
|
|
87
|
+
import { ThingType, ConnectionType, EventType } from '@/ontology/types'
|
|
88
|
+
|
|
89
|
+
// Error types (universal)
|
|
90
|
+
export class ThingNotFoundError {
|
|
91
|
+
readonly _tag = 'ThingNotFoundError'
|
|
92
|
+
constructor(readonly thingId: string) {}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class UnauthorizedError {
|
|
96
|
+
readonly _tag = 'UnauthorizedError'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export class ConnectionCreateError {
|
|
100
|
+
readonly _tag = 'ConnectionCreateError'
|
|
101
|
+
constructor(readonly reason: string) {}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Thing (universal data structure)
|
|
105
|
+
export interface Thing {
|
|
106
|
+
_id: string
|
|
107
|
+
type: ThingType
|
|
108
|
+
name: string
|
|
109
|
+
properties: Record<string, any>
|
|
110
|
+
status: 'active' | 'inactive' | 'archived'
|
|
111
|
+
createdAt: number
|
|
112
|
+
updatedAt: number
|
|
113
|
+
createdBy?: string
|
|
114
|
+
organizationId?: string
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Connection (universal relationship)
|
|
118
|
+
export interface Connection {
|
|
119
|
+
_id: string
|
|
120
|
+
fromThingId: string
|
|
121
|
+
toThingId: string
|
|
122
|
+
relationshipType: ConnectionType
|
|
123
|
+
metadata?: Record<string, any>
|
|
124
|
+
createdAt: number
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Event (universal activity)
|
|
128
|
+
export interface Event {
|
|
129
|
+
_id: string
|
|
130
|
+
type: EventType
|
|
131
|
+
actorId: string
|
|
132
|
+
targetId?: string
|
|
133
|
+
metadata?: Record<string, any>
|
|
134
|
+
timestamp: number
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Knowledge (universal search result)
|
|
138
|
+
export interface KnowledgeMatch {
|
|
139
|
+
thingId: string
|
|
140
|
+
score: number
|
|
141
|
+
text: string
|
|
142
|
+
metadata?: Record<string, any>
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ============================================
|
|
146
|
+
// DataProvider Interface
|
|
147
|
+
// ============================================
|
|
148
|
+
export interface DataProvider {
|
|
149
|
+
// Things operations
|
|
150
|
+
things: {
|
|
151
|
+
get: (id: string) => Effect.Effect<Thing, ThingNotFoundError | UnauthorizedError>
|
|
152
|
+
|
|
153
|
+
list: (params: {
|
|
154
|
+
type: ThingType
|
|
155
|
+
organizationId?: string
|
|
156
|
+
filters?: Record<string, any>
|
|
157
|
+
limit?: number
|
|
158
|
+
offset?: number
|
|
159
|
+
}) => Effect.Effect<Thing[], Error>
|
|
160
|
+
|
|
161
|
+
create: (input: {
|
|
162
|
+
type: ThingType
|
|
163
|
+
name: string
|
|
164
|
+
properties: Record<string, any>
|
|
165
|
+
organizationId?: string
|
|
166
|
+
}) => Effect.Effect<string, ConnectionCreateError>
|
|
167
|
+
|
|
168
|
+
update: (
|
|
169
|
+
id: string,
|
|
170
|
+
updates: Partial<Thing>
|
|
171
|
+
) => Effect.Effect<void, Error>
|
|
172
|
+
|
|
173
|
+
delete: (id: string) => Effect.Effect<void, Error>
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Connections operations
|
|
177
|
+
connections: {
|
|
178
|
+
create: (input: {
|
|
179
|
+
fromThingId: string
|
|
180
|
+
toThingId: string
|
|
181
|
+
relationshipType: ConnectionType
|
|
182
|
+
metadata?: Record<string, any>
|
|
183
|
+
}) => Effect.Effect<string, ConnectionCreateError>
|
|
184
|
+
|
|
185
|
+
getRelated: (params: {
|
|
186
|
+
thingId: string
|
|
187
|
+
relationshipType: ConnectionType
|
|
188
|
+
direction: 'from' | 'to' | 'both'
|
|
189
|
+
}) => Effect.Effect<Thing[], Error>
|
|
190
|
+
|
|
191
|
+
getCount: (
|
|
192
|
+
thingId: string,
|
|
193
|
+
relationshipType: ConnectionType
|
|
194
|
+
) => Effect.Effect<number, Error>
|
|
195
|
+
|
|
196
|
+
delete: (id: string) => Effect.Effect<void, Error>
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Events operations
|
|
200
|
+
events: {
|
|
201
|
+
log: (event: {
|
|
202
|
+
type: EventType
|
|
203
|
+
actorId: string
|
|
204
|
+
targetId?: string
|
|
205
|
+
metadata?: Record<string, any>
|
|
206
|
+
}) => Effect.Effect<void, Error>
|
|
207
|
+
|
|
208
|
+
query: (params: {
|
|
209
|
+
type?: EventType
|
|
210
|
+
actorId?: string
|
|
211
|
+
targetId?: string
|
|
212
|
+
from?: Date
|
|
213
|
+
to?: Date
|
|
214
|
+
}) => Effect.Effect<Event[], Error>
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Knowledge operations
|
|
218
|
+
knowledge: {
|
|
219
|
+
embed: (params: {
|
|
220
|
+
text: string
|
|
221
|
+
sourceThingId: string
|
|
222
|
+
labels?: string[]
|
|
223
|
+
}) => Effect.Effect<string, Error>
|
|
224
|
+
|
|
225
|
+
search: (
|
|
226
|
+
query: string,
|
|
227
|
+
limit?: number
|
|
228
|
+
) => Effect.Effect<KnowledgeMatch[], Error>
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Optional: Real-time subscriptions
|
|
232
|
+
subscriptions?: {
|
|
233
|
+
watchThing: (id: string) => Effect.Effect<Observable<Thing>, Error>
|
|
234
|
+
watchList: (type: ThingType) => Effect.Effect<Observable<Thing[]>, Error>
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
**That's it!** Implement this interface for ANY backend.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Implementation Patterns
|
|
244
|
+
|
|
245
|
+
### Pattern 1: REST API Backend
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
// frontend/src/providers/rest/RestProvider.ts
|
|
249
|
+
import { Effect, Layer } from 'effect'
|
|
250
|
+
import { DataProvider, Thing, ThingNotFoundError } from '../DataProvider'
|
|
251
|
+
|
|
252
|
+
export class RestProvider implements DataProvider {
|
|
253
|
+
constructor(
|
|
254
|
+
private baseUrl: string,
|
|
255
|
+
private apiKey: string
|
|
256
|
+
) {}
|
|
257
|
+
|
|
258
|
+
things = {
|
|
259
|
+
get: (id: string) =>
|
|
260
|
+
Effect.gen(this, function* () {
|
|
261
|
+
const response = yield* Effect.tryPromise({
|
|
262
|
+
try: () =>
|
|
263
|
+
fetch(`${this.baseUrl}/things/${id}`, {
|
|
264
|
+
headers: {
|
|
265
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
266
|
+
'Content-Type': 'application/json'
|
|
267
|
+
}
|
|
268
|
+
}),
|
|
269
|
+
catch: (error) => new Error(String(error))
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
if (!response.ok) {
|
|
273
|
+
if (response.status === 404) {
|
|
274
|
+
return yield* Effect.fail(new ThingNotFoundError(id))
|
|
275
|
+
}
|
|
276
|
+
return yield* Effect.fail(new Error(`HTTP ${response.status}`))
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const data = yield* Effect.tryPromise({
|
|
280
|
+
try: () => response.json(),
|
|
281
|
+
catch: (error) => new Error(String(error))
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
// Transform API response → ONE Thing
|
|
285
|
+
return this.transformToThing(data)
|
|
286
|
+
}),
|
|
287
|
+
|
|
288
|
+
list: (params) =>
|
|
289
|
+
Effect.gen(this, function* () {
|
|
290
|
+
const query = new URLSearchParams({
|
|
291
|
+
type: params.type,
|
|
292
|
+
limit: String(params.limit || 10),
|
|
293
|
+
...(params.organizationId && { org: params.organizationId })
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
const response = yield* Effect.tryPromise({
|
|
297
|
+
try: () =>
|
|
298
|
+
fetch(`${this.baseUrl}/things?${query}`, {
|
|
299
|
+
headers: {
|
|
300
|
+
'Authorization': `Bearer ${this.apiKey}`
|
|
301
|
+
}
|
|
302
|
+
}),
|
|
303
|
+
catch: (error) => new Error(String(error))
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
const data = yield* Effect.tryPromise({
|
|
307
|
+
try: () => response.json(),
|
|
308
|
+
catch: (error) => new Error(String(error))
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
return data.items.map((item: any) => this.transformToThing(item))
|
|
312
|
+
}),
|
|
313
|
+
|
|
314
|
+
create: (input) =>
|
|
315
|
+
Effect.gen(this, function* () {
|
|
316
|
+
const response = yield* Effect.tryPromise({
|
|
317
|
+
try: () =>
|
|
318
|
+
fetch(`${this.baseUrl}/things`, {
|
|
319
|
+
method: 'POST',
|
|
320
|
+
headers: {
|
|
321
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
322
|
+
'Content-Type': 'application/json'
|
|
323
|
+
},
|
|
324
|
+
body: JSON.stringify({
|
|
325
|
+
type: input.type,
|
|
326
|
+
name: input.name,
|
|
327
|
+
properties: input.properties,
|
|
328
|
+
organizationId: input.organizationId
|
|
329
|
+
})
|
|
330
|
+
}),
|
|
331
|
+
catch: (error) => new Error(String(error))
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
const data = yield* Effect.tryPromise({
|
|
335
|
+
try: () => response.json(),
|
|
336
|
+
catch: (error) => new Error(String(error))
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
return data.id
|
|
340
|
+
}),
|
|
341
|
+
|
|
342
|
+
update: (id, updates) =>
|
|
343
|
+
Effect.gen(this, function* () {
|
|
344
|
+
yield* Effect.tryPromise({
|
|
345
|
+
try: () =>
|
|
346
|
+
fetch(`${this.baseUrl}/things/${id}`, {
|
|
347
|
+
method: 'PATCH',
|
|
348
|
+
headers: {
|
|
349
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
350
|
+
'Content-Type': 'application/json'
|
|
351
|
+
},
|
|
352
|
+
body: JSON.stringify(updates)
|
|
353
|
+
}),
|
|
354
|
+
catch: (error) => new Error(String(error))
|
|
355
|
+
})
|
|
356
|
+
}),
|
|
357
|
+
|
|
358
|
+
delete: (id) =>
|
|
359
|
+
Effect.gen(this, function* () {
|
|
360
|
+
yield* Effect.tryPromise({
|
|
361
|
+
try: () =>
|
|
362
|
+
fetch(`${this.baseUrl}/things/${id}`, {
|
|
363
|
+
method: 'DELETE',
|
|
364
|
+
headers: {
|
|
365
|
+
'Authorization': `Bearer ${this.apiKey}`
|
|
366
|
+
}
|
|
367
|
+
}),
|
|
368
|
+
catch: (error) => new Error(String(error))
|
|
369
|
+
})
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
connections = {
|
|
374
|
+
// Similar REST API implementations
|
|
375
|
+
create: (input) => { /* POST /connections */ },
|
|
376
|
+
getRelated: (params) => { /* GET /things/:id/related */ },
|
|
377
|
+
getCount: (thingId, type) => { /* GET /things/:id/connections/count */ },
|
|
378
|
+
delete: (id) => { /* DELETE /connections/:id */ }
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
events = {
|
|
382
|
+
log: (event) => { /* POST /events */ },
|
|
383
|
+
query: (params) => { /* GET /events */ }
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
knowledge = {
|
|
387
|
+
embed: (params) => { /* POST /knowledge/embed */ },
|
|
388
|
+
search: (query, limit) => { /* GET /knowledge/search */ }
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Helper: Transform API data → ONE Thing
|
|
392
|
+
private transformToThing(data: any): Thing {
|
|
393
|
+
return {
|
|
394
|
+
_id: data.id,
|
|
395
|
+
type: data.type,
|
|
396
|
+
name: data.name || data.title,
|
|
397
|
+
properties: data.attributes || data.properties || {},
|
|
398
|
+
status: data.status || 'active',
|
|
399
|
+
createdAt: new Date(data.created_at).getTime(),
|
|
400
|
+
updatedAt: new Date(data.updated_at).getTime(),
|
|
401
|
+
createdBy: data.created_by,
|
|
402
|
+
organizationId: data.organization_id
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Factory function
|
|
408
|
+
export function restProvider(config: { url: string; apiKey: string }) {
|
|
409
|
+
return Layer.succeed(DataProvider, new RestProvider(config.url, config.apiKey))
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Pattern 2: GraphQL Backend
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
// frontend/src/providers/graphql/GraphQLProvider.ts
|
|
417
|
+
import { Effect, Layer } from 'effect'
|
|
418
|
+
import { DataProvider, Thing } from '../DataProvider'
|
|
419
|
+
|
|
420
|
+
export class GraphQLProvider implements DataProvider {
|
|
421
|
+
constructor(
|
|
422
|
+
private endpoint: string,
|
|
423
|
+
private headers: Record<string, string>
|
|
424
|
+
) {}
|
|
425
|
+
|
|
426
|
+
things = {
|
|
427
|
+
get: (id: string) =>
|
|
428
|
+
Effect.gen(this, function* () {
|
|
429
|
+
const query = `
|
|
430
|
+
query GetThing($id: ID!) {
|
|
431
|
+
thing(id: $id) {
|
|
432
|
+
id
|
|
433
|
+
type
|
|
434
|
+
name
|
|
435
|
+
properties
|
|
436
|
+
status
|
|
437
|
+
createdAt
|
|
438
|
+
updatedAt
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
`
|
|
442
|
+
|
|
443
|
+
const response = yield* Effect.tryPromise({
|
|
444
|
+
try: () =>
|
|
445
|
+
fetch(this.endpoint, {
|
|
446
|
+
method: 'POST',
|
|
447
|
+
headers: {
|
|
448
|
+
...this.headers,
|
|
449
|
+
'Content-Type': 'application/json'
|
|
450
|
+
},
|
|
451
|
+
body: JSON.stringify({
|
|
452
|
+
query,
|
|
453
|
+
variables: { id }
|
|
454
|
+
})
|
|
455
|
+
}),
|
|
456
|
+
catch: (error) => new Error(String(error))
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
const data = yield* Effect.tryPromise({
|
|
460
|
+
try: () => response.json(),
|
|
461
|
+
catch: (error) => new Error(String(error))
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
if (data.errors) {
|
|
465
|
+
return yield* Effect.fail(new Error(data.errors[0].message))
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return this.transformToThing(data.data.thing)
|
|
469
|
+
}),
|
|
470
|
+
|
|
471
|
+
list: (params) =>
|
|
472
|
+
Effect.gen(this, function* () {
|
|
473
|
+
const query = `
|
|
474
|
+
query ListThings($type: String!, $limit: Int, $orgId: ID) {
|
|
475
|
+
things(type: $type, limit: $limit, organizationId: $orgId) {
|
|
476
|
+
nodes {
|
|
477
|
+
id
|
|
478
|
+
type
|
|
479
|
+
name
|
|
480
|
+
properties
|
|
481
|
+
status
|
|
482
|
+
createdAt
|
|
483
|
+
updatedAt
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
`
|
|
488
|
+
|
|
489
|
+
const response = yield* Effect.tryPromise({
|
|
490
|
+
try: () =>
|
|
491
|
+
fetch(this.endpoint, {
|
|
492
|
+
method: 'POST',
|
|
493
|
+
headers: {
|
|
494
|
+
...this.headers,
|
|
495
|
+
'Content-Type': 'application/json'
|
|
496
|
+
},
|
|
497
|
+
body: JSON.stringify({
|
|
498
|
+
query,
|
|
499
|
+
variables: {
|
|
500
|
+
type: params.type,
|
|
501
|
+
limit: params.limit || 10,
|
|
502
|
+
orgId: params.organizationId
|
|
503
|
+
}
|
|
504
|
+
})
|
|
505
|
+
}),
|
|
506
|
+
catch: (error) => new Error(String(error))
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
const data = yield* Effect.tryPromise({
|
|
510
|
+
try: () => response.json(),
|
|
511
|
+
catch: (error) => new Error(String(error))
|
|
512
|
+
})
|
|
513
|
+
|
|
514
|
+
return data.data.things.nodes.map((node: any) =>
|
|
515
|
+
this.transformToThing(node)
|
|
516
|
+
)
|
|
517
|
+
}),
|
|
518
|
+
|
|
519
|
+
create: (input) =>
|
|
520
|
+
Effect.gen(this, function* () {
|
|
521
|
+
const mutation = `
|
|
522
|
+
mutation CreateThing($input: CreateThingInput!) {
|
|
523
|
+
createThing(input: $input) {
|
|
524
|
+
id
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
`
|
|
528
|
+
|
|
529
|
+
const response = yield* Effect.tryPromise({
|
|
530
|
+
try: () =>
|
|
531
|
+
fetch(this.endpoint, {
|
|
532
|
+
method: 'POST',
|
|
533
|
+
headers: {
|
|
534
|
+
...this.headers,
|
|
535
|
+
'Content-Type': 'application/json'
|
|
536
|
+
},
|
|
537
|
+
body: JSON.stringify({
|
|
538
|
+
query: mutation,
|
|
539
|
+
variables: {
|
|
540
|
+
input: {
|
|
541
|
+
type: input.type,
|
|
542
|
+
name: input.name,
|
|
543
|
+
properties: input.properties,
|
|
544
|
+
organizationId: input.organizationId
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
})
|
|
548
|
+
}),
|
|
549
|
+
catch: (error) => new Error(String(error))
|
|
550
|
+
})
|
|
551
|
+
|
|
552
|
+
const data = yield* Effect.tryPromise({
|
|
553
|
+
try: () => response.json(),
|
|
554
|
+
catch: (error) => new Error(String(error))
|
|
555
|
+
})
|
|
556
|
+
|
|
557
|
+
return data.data.createThing.id
|
|
558
|
+
}),
|
|
559
|
+
|
|
560
|
+
update: (id, updates) => { /* Similar mutation */ },
|
|
561
|
+
delete: (id) => { /* Similar mutation */ }
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// connections, events, knowledge...
|
|
565
|
+
|
|
566
|
+
private transformToThing(data: any): Thing {
|
|
567
|
+
return {
|
|
568
|
+
_id: data.id,
|
|
569
|
+
type: data.type,
|
|
570
|
+
name: data.name,
|
|
571
|
+
properties: JSON.parse(data.properties || '{}'),
|
|
572
|
+
status: data.status,
|
|
573
|
+
createdAt: new Date(data.createdAt).getTime(),
|
|
574
|
+
updatedAt: new Date(data.updatedAt).getTime()
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Factory
|
|
580
|
+
export function graphqlProvider(config: {
|
|
581
|
+
endpoint: string
|
|
582
|
+
headers: Record<string, string>
|
|
583
|
+
}) {
|
|
584
|
+
return Layer.succeed(
|
|
585
|
+
DataProvider,
|
|
586
|
+
new GraphQLProvider(config.endpoint, config.headers)
|
|
587
|
+
)
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
### Pattern 3: SQL Database (Direct)
|
|
592
|
+
|
|
593
|
+
```typescript
|
|
594
|
+
// frontend/src/providers/postgres/PostgresProvider.ts
|
|
595
|
+
import { Effect, Layer } from 'effect'
|
|
596
|
+
import { Pool } from 'pg'
|
|
597
|
+
import { DataProvider, Thing } from '../DataProvider'
|
|
598
|
+
|
|
599
|
+
export class PostgresProvider implements DataProvider {
|
|
600
|
+
private pool: Pool
|
|
601
|
+
|
|
602
|
+
constructor(connectionString: string) {
|
|
603
|
+
this.pool = new Pool({ connectionString })
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
things = {
|
|
607
|
+
get: (id: string) =>
|
|
608
|
+
Effect.gen(this, function* () {
|
|
609
|
+
const result = yield* Effect.tryPromise({
|
|
610
|
+
try: () =>
|
|
611
|
+
this.pool.query('SELECT * FROM things WHERE id = $1', [id]),
|
|
612
|
+
catch: (error) => new Error(String(error))
|
|
613
|
+
})
|
|
614
|
+
|
|
615
|
+
if (result.rows.length === 0) {
|
|
616
|
+
return yield* Effect.fail(new ThingNotFoundError(id))
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
return this.rowToThing(result.rows[0])
|
|
620
|
+
}),
|
|
621
|
+
|
|
622
|
+
list: (params) =>
|
|
623
|
+
Effect.gen(this, function* () {
|
|
624
|
+
const query = `
|
|
625
|
+
SELECT * FROM things
|
|
626
|
+
WHERE type = $1
|
|
627
|
+
${params.organizationId ? 'AND organization_id = $2' : ''}
|
|
628
|
+
LIMIT $${params.organizationId ? '3' : '2'}
|
|
629
|
+
`
|
|
630
|
+
|
|
631
|
+
const values = [
|
|
632
|
+
params.type,
|
|
633
|
+
...(params.organizationId ? [params.organizationId] : []),
|
|
634
|
+
params.limit || 10
|
|
635
|
+
]
|
|
636
|
+
|
|
637
|
+
const result = yield* Effect.tryPromise({
|
|
638
|
+
try: () => this.pool.query(query, values),
|
|
639
|
+
catch: (error) => new Error(String(error))
|
|
640
|
+
})
|
|
641
|
+
|
|
642
|
+
return result.rows.map(row => this.rowToThing(row))
|
|
643
|
+
}),
|
|
644
|
+
|
|
645
|
+
create: (input) =>
|
|
646
|
+
Effect.gen(this, function* () {
|
|
647
|
+
const result = yield* Effect.tryPromise({
|
|
648
|
+
try: () =>
|
|
649
|
+
this.pool.query(
|
|
650
|
+
`INSERT INTO things (type, name, properties, organization_id, status, created_at, updated_at)
|
|
651
|
+
VALUES ($1, $2, $3, $4, $5, NOW(), NOW())
|
|
652
|
+
RETURNING id`,
|
|
653
|
+
[
|
|
654
|
+
input.type,
|
|
655
|
+
input.name,
|
|
656
|
+
JSON.stringify(input.properties),
|
|
657
|
+
input.organizationId,
|
|
658
|
+
'active'
|
|
659
|
+
]
|
|
660
|
+
),
|
|
661
|
+
catch: (error) => new Error(String(error))
|
|
662
|
+
})
|
|
663
|
+
|
|
664
|
+
return result.rows[0].id
|
|
665
|
+
}),
|
|
666
|
+
|
|
667
|
+
update: (id, updates) => { /* UPDATE query */ },
|
|
668
|
+
delete: (id) => { /* DELETE query */ }
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
connections = {
|
|
672
|
+
create: (input) =>
|
|
673
|
+
Effect.gen(this, function* () {
|
|
674
|
+
const result = yield* Effect.tryPromise({
|
|
675
|
+
try: () =>
|
|
676
|
+
this.pool.query(
|
|
677
|
+
`INSERT INTO connections (from_thing_id, to_thing_id, relationship_type, metadata, created_at)
|
|
678
|
+
VALUES ($1, $2, $3, $4, NOW())
|
|
679
|
+
RETURNING id`,
|
|
680
|
+
[
|
|
681
|
+
input.fromThingId,
|
|
682
|
+
input.toThingId,
|
|
683
|
+
input.relationshipType,
|
|
684
|
+
JSON.stringify(input.metadata || {})
|
|
685
|
+
]
|
|
686
|
+
),
|
|
687
|
+
catch: (error) => new Error(String(error))
|
|
688
|
+
})
|
|
689
|
+
|
|
690
|
+
return result.rows[0].id
|
|
691
|
+
}),
|
|
692
|
+
|
|
693
|
+
getRelated: (params) => { /* JOIN query */ },
|
|
694
|
+
getCount: (thingId, type) => { /* COUNT query */ },
|
|
695
|
+
delete: (id) => { /* DELETE query */ }
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
events = {
|
|
699
|
+
log: (event) => { /* INSERT INTO events */ },
|
|
700
|
+
query: (params) => { /* SELECT FROM events */ }
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
knowledge = {
|
|
704
|
+
embed: (params) => { /* Store embedding, use pgvector */ },
|
|
705
|
+
search: (query, limit) => { /* Vector similarity search */ }
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
private rowToThing(row: any): Thing {
|
|
709
|
+
return {
|
|
710
|
+
_id: row.id,
|
|
711
|
+
type: row.type,
|
|
712
|
+
name: row.name,
|
|
713
|
+
properties: JSON.parse(row.properties || '{}'),
|
|
714
|
+
status: row.status,
|
|
715
|
+
createdAt: new Date(row.created_at).getTime(),
|
|
716
|
+
updatedAt: new Date(row.updated_at).getTime(),
|
|
717
|
+
organizationId: row.organization_id
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// Factory
|
|
723
|
+
export function postgresProvider(config: { connectionString: string }) {
|
|
724
|
+
return Layer.succeed(
|
|
725
|
+
DataProvider,
|
|
726
|
+
new PostgresProvider(config.connectionString)
|
|
727
|
+
)
|
|
728
|
+
}
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
---
|
|
732
|
+
|
|
733
|
+
## Database Backends
|
|
734
|
+
|
|
735
|
+
### Supabase
|
|
736
|
+
|
|
737
|
+
```typescript
|
|
738
|
+
// frontend/src/providers/supabase/SupabaseProvider.ts
|
|
739
|
+
import { createClient } from '@supabase/supabase-js'
|
|
740
|
+
import { Effect, Layer } from 'effect'
|
|
741
|
+
import { DataProvider } from '../DataProvider'
|
|
742
|
+
|
|
743
|
+
export class SupabaseProvider implements DataProvider {
|
|
744
|
+
private supabase
|
|
745
|
+
|
|
746
|
+
constructor(url: string, anonKey: string) {
|
|
747
|
+
this.supabase = createClient(url, anonKey)
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
things = {
|
|
751
|
+
get: (id: string) =>
|
|
752
|
+
Effect.gen(this, function* () {
|
|
753
|
+
const { data, error } = yield* Effect.tryPromise({
|
|
754
|
+
try: () =>
|
|
755
|
+
this.supabase.from('things').select('*').eq('id', id).single(),
|
|
756
|
+
catch: (err) => new Error(String(err))
|
|
757
|
+
})
|
|
758
|
+
|
|
759
|
+
if (error) {
|
|
760
|
+
return yield* Effect.fail(new ThingNotFoundError(id))
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
return this.transformToThing(data)
|
|
764
|
+
}),
|
|
765
|
+
|
|
766
|
+
list: (params) =>
|
|
767
|
+
Effect.gen(this, function* () {
|
|
768
|
+
let query = this.supabase
|
|
769
|
+
.from('things')
|
|
770
|
+
.select('*')
|
|
771
|
+
.eq('type', params.type)
|
|
772
|
+
|
|
773
|
+
if (params.organizationId) {
|
|
774
|
+
query = query.eq('organization_id', params.organizationId)
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
const { data, error } = yield* Effect.tryPromise({
|
|
778
|
+
try: () => query.limit(params.limit || 10),
|
|
779
|
+
catch: (err) => new Error(String(err))
|
|
780
|
+
})
|
|
781
|
+
|
|
782
|
+
if (error) {
|
|
783
|
+
return yield* Effect.fail(new Error(error.message))
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
return data.map(row => this.transformToThing(row))
|
|
787
|
+
}),
|
|
788
|
+
|
|
789
|
+
// create, update, delete...
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// ✅ Supabase supports real-time!
|
|
793
|
+
subscriptions = {
|
|
794
|
+
watchThing: (id: string) =>
|
|
795
|
+
Effect.gen(this, function* () {
|
|
796
|
+
// Supabase real-time subscription
|
|
797
|
+
const channel = this.supabase
|
|
798
|
+
.channel(`thing:${id}`)
|
|
799
|
+
.on('postgres_changes', {
|
|
800
|
+
event: '*',
|
|
801
|
+
schema: 'public',
|
|
802
|
+
table: 'things',
|
|
803
|
+
filter: `id=eq.${id}`
|
|
804
|
+
}, (payload) => {
|
|
805
|
+
// Emit updates via Observable
|
|
806
|
+
})
|
|
807
|
+
|
|
808
|
+
yield* Effect.tryPromise({
|
|
809
|
+
try: () => channel.subscribe(),
|
|
810
|
+
catch: (err) => new Error(String(err))
|
|
811
|
+
})
|
|
812
|
+
|
|
813
|
+
// Return observable
|
|
814
|
+
})
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// ... rest of implementation
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
export function supabaseProvider(config: { url: string; anonKey: string }) {
|
|
821
|
+
return Layer.succeed(
|
|
822
|
+
DataProvider,
|
|
823
|
+
new SupabaseProvider(config.url, config.anonKey)
|
|
824
|
+
)
|
|
825
|
+
}
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
### Neon (Serverless Postgres)
|
|
829
|
+
|
|
830
|
+
```typescript
|
|
831
|
+
// frontend/src/providers/neon/NeonProvider.ts
|
|
832
|
+
import { neon } from '@neondatabase/serverless'
|
|
833
|
+
import { Effect, Layer } from 'effect'
|
|
834
|
+
import { DataProvider } from '../DataProvider'
|
|
835
|
+
|
|
836
|
+
export class NeonProvider implements DataProvider {
|
|
837
|
+
private sql
|
|
838
|
+
|
|
839
|
+
constructor(connectionString: string) {
|
|
840
|
+
this.sql = neon(connectionString)
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
things = {
|
|
844
|
+
get: (id: string) =>
|
|
845
|
+
Effect.gen(this, function* () {
|
|
846
|
+
const rows = yield* Effect.tryPromise({
|
|
847
|
+
try: () => this.sql`SELECT * FROM things WHERE id = ${id}`,
|
|
848
|
+
catch: (error) => new Error(String(error))
|
|
849
|
+
})
|
|
850
|
+
|
|
851
|
+
if (rows.length === 0) {
|
|
852
|
+
return yield* Effect.fail(new ThingNotFoundError(id))
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
return this.transformToThing(rows[0])
|
|
856
|
+
}),
|
|
857
|
+
|
|
858
|
+
list: (params) =>
|
|
859
|
+
Effect.gen(this, function* () {
|
|
860
|
+
const rows = yield* Effect.tryPromise({
|
|
861
|
+
try: () => this.sql`
|
|
862
|
+
SELECT * FROM things
|
|
863
|
+
WHERE type = ${params.type}
|
|
864
|
+
${params.organizationId ? this.sql`AND organization_id = ${params.organizationId}` : this.sql``}
|
|
865
|
+
LIMIT ${params.limit || 10}
|
|
866
|
+
`,
|
|
867
|
+
catch: (error) => new Error(String(error))
|
|
868
|
+
})
|
|
869
|
+
|
|
870
|
+
return rows.map(row => this.transformToThing(row))
|
|
871
|
+
}),
|
|
872
|
+
|
|
873
|
+
// create, update, delete...
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// ... rest of implementation
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
export function neonProvider(config: { connectionString: string }) {
|
|
880
|
+
return Layer.succeed(DataProvider, new NeonProvider(config.connectionString))
|
|
881
|
+
}
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
### PlanetScale (MySQL)
|
|
885
|
+
|
|
886
|
+
```typescript
|
|
887
|
+
// frontend/src/providers/planetscale/PlanetScaleProvider.ts
|
|
888
|
+
import { connect } from '@planetscale/database'
|
|
889
|
+
import { Effect, Layer } from 'effect'
|
|
890
|
+
import { DataProvider } from '../DataProvider'
|
|
891
|
+
|
|
892
|
+
export class PlanetScaleProvider implements DataProvider {
|
|
893
|
+
private db
|
|
894
|
+
|
|
895
|
+
constructor(config: { host: string; username: string; password: string }) {
|
|
896
|
+
this.db = connect({
|
|
897
|
+
host: config.host,
|
|
898
|
+
username: config.username,
|
|
899
|
+
password: config.password
|
|
900
|
+
})
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
things = {
|
|
904
|
+
get: (id: string) =>
|
|
905
|
+
Effect.gen(this, function* () {
|
|
906
|
+
const result = yield* Effect.tryPromise({
|
|
907
|
+
try: () =>
|
|
908
|
+
this.db.execute('SELECT * FROM things WHERE id = ?', [id]),
|
|
909
|
+
catch: (error) => new Error(String(error))
|
|
910
|
+
})
|
|
911
|
+
|
|
912
|
+
if (result.rows.length === 0) {
|
|
913
|
+
return yield* Effect.fail(new ThingNotFoundError(id))
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
return this.transformToThing(result.rows[0])
|
|
917
|
+
}),
|
|
918
|
+
|
|
919
|
+
// ... rest of implementation
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
export function planetscaleProvider(config: {
|
|
924
|
+
host: string
|
|
925
|
+
username: string
|
|
926
|
+
password: string
|
|
927
|
+
}) {
|
|
928
|
+
return Layer.succeed(
|
|
929
|
+
DataProvider,
|
|
930
|
+
new PlanetScaleProvider(config)
|
|
931
|
+
)
|
|
932
|
+
}
|
|
933
|
+
```
|
|
934
|
+
|
|
935
|
+
### MongoDB
|
|
936
|
+
|
|
937
|
+
```typescript
|
|
938
|
+
// frontend/src/providers/mongo/MongoProvider.ts
|
|
939
|
+
import { MongoClient } from 'mongodb'
|
|
940
|
+
import { Effect, Layer } from 'effect'
|
|
941
|
+
import { DataProvider } from '../DataProvider'
|
|
942
|
+
|
|
943
|
+
export class MongoProvider implements DataProvider {
|
|
944
|
+
private client: MongoClient
|
|
945
|
+
private db
|
|
946
|
+
|
|
947
|
+
constructor(connectionString: string, dbName: string) {
|
|
948
|
+
this.client = new MongoClient(connectionString)
|
|
949
|
+
this.db = this.client.db(dbName)
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
things = {
|
|
953
|
+
get: (id: string) =>
|
|
954
|
+
Effect.gen(this, function* () {
|
|
955
|
+
const thing = yield* Effect.tryPromise({
|
|
956
|
+
try: () =>
|
|
957
|
+
this.db.collection('things').findOne({ _id: id }),
|
|
958
|
+
catch: (error) => new Error(String(error))
|
|
959
|
+
})
|
|
960
|
+
|
|
961
|
+
if (!thing) {
|
|
962
|
+
return yield* Effect.fail(new ThingNotFoundError(id))
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
return thing as Thing
|
|
966
|
+
}),
|
|
967
|
+
|
|
968
|
+
list: (params) =>
|
|
969
|
+
Effect.gen(this, function* () {
|
|
970
|
+
const filter: any = { type: params.type }
|
|
971
|
+
|
|
972
|
+
if (params.organizationId) {
|
|
973
|
+
filter.organizationId = params.organizationId
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
const things = yield* Effect.tryPromise({
|
|
977
|
+
try: () =>
|
|
978
|
+
this.db
|
|
979
|
+
.collection('things')
|
|
980
|
+
.find(filter)
|
|
981
|
+
.limit(params.limit || 10)
|
|
982
|
+
.toArray(),
|
|
983
|
+
catch: (error) => new Error(String(error))
|
|
984
|
+
})
|
|
985
|
+
|
|
986
|
+
return things as Thing[]
|
|
987
|
+
}),
|
|
988
|
+
|
|
989
|
+
create: (input) =>
|
|
990
|
+
Effect.gen(this, function* () {
|
|
991
|
+
const result = yield* Effect.tryPromise({
|
|
992
|
+
try: () =>
|
|
993
|
+
this.db.collection('things').insertOne({
|
|
994
|
+
type: input.type,
|
|
995
|
+
name: input.name,
|
|
996
|
+
properties: input.properties,
|
|
997
|
+
organizationId: input.organizationId,
|
|
998
|
+
status: 'active',
|
|
999
|
+
createdAt: Date.now(),
|
|
1000
|
+
updatedAt: Date.now()
|
|
1001
|
+
}),
|
|
1002
|
+
catch: (error) => new Error(String(error))
|
|
1003
|
+
})
|
|
1004
|
+
|
|
1005
|
+
return result.insertedId.toString()
|
|
1006
|
+
}),
|
|
1007
|
+
|
|
1008
|
+
// update, delete...
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// connections, events, knowledge...
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
export function mongoProvider(config: {
|
|
1015
|
+
connectionString: string
|
|
1016
|
+
dbName: string
|
|
1017
|
+
}) {
|
|
1018
|
+
return Layer.succeed(
|
|
1019
|
+
DataProvider,
|
|
1020
|
+
new MongoProvider(config.connectionString, config.dbName)
|
|
1021
|
+
)
|
|
1022
|
+
}
|
|
1023
|
+
```
|
|
1024
|
+
|
|
1025
|
+
---
|
|
1026
|
+
|
|
1027
|
+
## CMS Backends
|
|
1028
|
+
|
|
1029
|
+
See detailed guides:
|
|
1030
|
+
- **wordpress.md** - WordPress + WooCommerce backend
|
|
1031
|
+
- **cms.md** - Strapi, Contentful, Sanity, Ghost, Prismic
|
|
1032
|
+
|
|
1033
|
+
Quick examples:
|
|
1034
|
+
|
|
1035
|
+
### Strapi
|
|
1036
|
+
|
|
1037
|
+
```typescript
|
|
1038
|
+
// frontend/src/providers/strapi/StrapiProvider.ts
|
|
1039
|
+
import { Effect, Layer } from 'effect'
|
|
1040
|
+
import { DataProvider } from '../DataProvider'
|
|
1041
|
+
|
|
1042
|
+
export class StrapiProvider implements DataProvider {
|
|
1043
|
+
constructor(private baseUrl: string, private apiKey: string) {}
|
|
1044
|
+
|
|
1045
|
+
things = {
|
|
1046
|
+
get: (id: string) =>
|
|
1047
|
+
Effect.gen(this, function* () {
|
|
1048
|
+
const response = yield* Effect.tryPromise({
|
|
1049
|
+
try: () =>
|
|
1050
|
+
fetch(`${this.baseUrl}/api/${this.getCollectionName(type)}/${id}`, {
|
|
1051
|
+
headers: { 'Authorization': `Bearer ${this.apiKey}` }
|
|
1052
|
+
}),
|
|
1053
|
+
catch: (error) => new Error(String(error))
|
|
1054
|
+
})
|
|
1055
|
+
|
|
1056
|
+
const data = yield* Effect.tryPromise({
|
|
1057
|
+
try: () => response.json(),
|
|
1058
|
+
catch: (error) => new Error(String(error))
|
|
1059
|
+
})
|
|
1060
|
+
|
|
1061
|
+
// Transform Strapi data → ONE Thing
|
|
1062
|
+
return {
|
|
1063
|
+
_id: data.data.id.toString(),
|
|
1064
|
+
type: data.data.attributes.__component,
|
|
1065
|
+
name: data.data.attributes.title || data.data.attributes.name,
|
|
1066
|
+
properties: data.data.attributes,
|
|
1067
|
+
status: data.data.attributes.publishedAt ? 'active' : 'inactive',
|
|
1068
|
+
createdAt: new Date(data.data.attributes.createdAt).getTime(),
|
|
1069
|
+
updatedAt: new Date(data.data.attributes.updatedAt).getTime()
|
|
1070
|
+
}
|
|
1071
|
+
}),
|
|
1072
|
+
|
|
1073
|
+
// ... rest
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
private getCollectionName(type: string): string {
|
|
1077
|
+
// Map ONE types → Strapi collections
|
|
1078
|
+
const mapping = {
|
|
1079
|
+
'post': 'articles',
|
|
1080
|
+
'course': 'courses',
|
|
1081
|
+
'product': 'products'
|
|
1082
|
+
}
|
|
1083
|
+
return mapping[type] || type + 's'
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
export function strapiProvider(config: { url: string; apiKey: string }) {
|
|
1088
|
+
return Layer.succeed(DataProvider, new StrapiProvider(config.url, config.apiKey))
|
|
1089
|
+
}
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
### Contentful
|
|
1093
|
+
|
|
1094
|
+
```typescript
|
|
1095
|
+
// frontend/src/providers/contentful/ContentfulProvider.ts
|
|
1096
|
+
import { createClient } from 'contentful'
|
|
1097
|
+
import { Effect, Layer } from 'effect'
|
|
1098
|
+
import { DataProvider } from '../DataProvider'
|
|
1099
|
+
|
|
1100
|
+
export class ContentfulProvider implements DataProvider {
|
|
1101
|
+
private client
|
|
1102
|
+
|
|
1103
|
+
constructor(spaceId: string, accessToken: string) {
|
|
1104
|
+
this.client = createClient({
|
|
1105
|
+
space: spaceId,
|
|
1106
|
+
accessToken: accessToken
|
|
1107
|
+
})
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
things = {
|
|
1111
|
+
get: (id: string) =>
|
|
1112
|
+
Effect.gen(this, function* () {
|
|
1113
|
+
const entry = yield* Effect.tryPromise({
|
|
1114
|
+
try: () => this.client.getEntry(id),
|
|
1115
|
+
catch: (error) => new Error(String(error))
|
|
1116
|
+
})
|
|
1117
|
+
|
|
1118
|
+
return {
|
|
1119
|
+
_id: entry.sys.id,
|
|
1120
|
+
type: entry.sys.contentType.sys.id,
|
|
1121
|
+
name: entry.fields.title || entry.fields.name,
|
|
1122
|
+
properties: entry.fields,
|
|
1123
|
+
status: 'active',
|
|
1124
|
+
createdAt: new Date(entry.sys.createdAt).getTime(),
|
|
1125
|
+
updatedAt: new Date(entry.sys.updatedAt).getTime()
|
|
1126
|
+
}
|
|
1127
|
+
}),
|
|
1128
|
+
|
|
1129
|
+
list: (params) =>
|
|
1130
|
+
Effect.gen(this, function* () {
|
|
1131
|
+
const entries = yield* Effect.tryPromise({
|
|
1132
|
+
try: () =>
|
|
1133
|
+
this.client.getEntries({
|
|
1134
|
+
content_type: params.type,
|
|
1135
|
+
limit: params.limit || 10
|
|
1136
|
+
}),
|
|
1137
|
+
catch: (error) => new Error(String(error))
|
|
1138
|
+
})
|
|
1139
|
+
|
|
1140
|
+
return entries.items.map(entry => ({
|
|
1141
|
+
_id: entry.sys.id,
|
|
1142
|
+
type: entry.sys.contentType.sys.id,
|
|
1143
|
+
name: entry.fields.title || entry.fields.name,
|
|
1144
|
+
properties: entry.fields,
|
|
1145
|
+
status: 'active',
|
|
1146
|
+
createdAt: new Date(entry.sys.createdAt).getTime(),
|
|
1147
|
+
updatedAt: new Date(entry.sys.updatedAt).getTime()
|
|
1148
|
+
}))
|
|
1149
|
+
}),
|
|
1150
|
+
|
|
1151
|
+
// Contentful is read-only via API (use Management API for writes)
|
|
1152
|
+
create: () => Effect.fail(new Error('Use Contentful Management API')),
|
|
1153
|
+
update: () => Effect.fail(new Error('Use Contentful Management API')),
|
|
1154
|
+
delete: () => Effect.fail(new Error('Use Contentful Management API'))
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// ... rest
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
export function contentfulProvider(config: {
|
|
1161
|
+
spaceId: string
|
|
1162
|
+
accessToken: string
|
|
1163
|
+
}) {
|
|
1164
|
+
return Layer.succeed(
|
|
1165
|
+
DataProvider,
|
|
1166
|
+
new ContentfulProvider(config.spaceId, config.accessToken)
|
|
1167
|
+
)
|
|
1168
|
+
}
|
|
1169
|
+
```
|
|
1170
|
+
|
|
1171
|
+
---
|
|
1172
|
+
|
|
1173
|
+
## SaaS API Backends
|
|
1174
|
+
|
|
1175
|
+
### Notion
|
|
1176
|
+
|
|
1177
|
+
```typescript
|
|
1178
|
+
// frontend/src/providers/notion/NotionProvider.ts
|
|
1179
|
+
import { Client } from '@notionhq/client'
|
|
1180
|
+
import { Effect, Layer } from 'effect'
|
|
1181
|
+
import { DataProvider } from '../DataProvider'
|
|
1182
|
+
|
|
1183
|
+
export class NotionProvider implements DataProvider {
|
|
1184
|
+
private notion: Client
|
|
1185
|
+
|
|
1186
|
+
constructor(apiKey: string, private databaseId: string) {
|
|
1187
|
+
this.notion = new Client({ auth: apiKey })
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
things = {
|
|
1191
|
+
get: (id: string) =>
|
|
1192
|
+
Effect.gen(this, function* () {
|
|
1193
|
+
const page = yield* Effect.tryPromise({
|
|
1194
|
+
try: () => this.notion.pages.retrieve({ page_id: id }),
|
|
1195
|
+
catch: (error) => new Error(String(error))
|
|
1196
|
+
})
|
|
1197
|
+
|
|
1198
|
+
return {
|
|
1199
|
+
_id: page.id,
|
|
1200
|
+
type: 'document',
|
|
1201
|
+
name: (page.properties.Name as any).title[0]?.plain_text || '',
|
|
1202
|
+
properties: page.properties,
|
|
1203
|
+
status: 'active',
|
|
1204
|
+
createdAt: new Date(page.created_time).getTime(),
|
|
1205
|
+
updatedAt: new Date(page.last_edited_time).getTime()
|
|
1206
|
+
}
|
|
1207
|
+
}),
|
|
1208
|
+
|
|
1209
|
+
list: (params) =>
|
|
1210
|
+
Effect.gen(this, function* () {
|
|
1211
|
+
const response = yield* Effect.tryPromise({
|
|
1212
|
+
try: () =>
|
|
1213
|
+
this.notion.databases.query({
|
|
1214
|
+
database_id: this.databaseId,
|
|
1215
|
+
page_size: params.limit || 10
|
|
1216
|
+
}),
|
|
1217
|
+
catch: (error) => new Error(String(error))
|
|
1218
|
+
})
|
|
1219
|
+
|
|
1220
|
+
return response.results.map((page: any) => ({
|
|
1221
|
+
_id: page.id,
|
|
1222
|
+
type: params.type,
|
|
1223
|
+
name: page.properties.Name?.title[0]?.plain_text || '',
|
|
1224
|
+
properties: page.properties,
|
|
1225
|
+
status: 'active',
|
|
1226
|
+
createdAt: new Date(page.created_time).getTime(),
|
|
1227
|
+
updatedAt: new Date(page.last_edited_time).getTime()
|
|
1228
|
+
}))
|
|
1229
|
+
}),
|
|
1230
|
+
|
|
1231
|
+
create: (input) =>
|
|
1232
|
+
Effect.gen(this, function* () {
|
|
1233
|
+
const page = yield* Effect.tryPromise({
|
|
1234
|
+
try: () =>
|
|
1235
|
+
this.notion.pages.create({
|
|
1236
|
+
parent: { database_id: this.databaseId },
|
|
1237
|
+
properties: {
|
|
1238
|
+
Name: {
|
|
1239
|
+
title: [{ text: { content: input.name } }]
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}),
|
|
1243
|
+
catch: (error) => new Error(String(error))
|
|
1244
|
+
})
|
|
1245
|
+
|
|
1246
|
+
return page.id
|
|
1247
|
+
}),
|
|
1248
|
+
|
|
1249
|
+
// update, delete...
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
// ... rest
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
export function notionProvider(config: { apiKey: string; databaseId: string }) {
|
|
1256
|
+
return Layer.succeed(
|
|
1257
|
+
DataProvider,
|
|
1258
|
+
new NotionProvider(config.apiKey, config.databaseId)
|
|
1259
|
+
)
|
|
1260
|
+
}
|
|
1261
|
+
```
|
|
1262
|
+
|
|
1263
|
+
### Airtable
|
|
1264
|
+
|
|
1265
|
+
```typescript
|
|
1266
|
+
// frontend/src/providers/airtable/AirtableProvider.ts
|
|
1267
|
+
import Airtable from 'airtable'
|
|
1268
|
+
import { Effect, Layer } from 'effect'
|
|
1269
|
+
import { DataProvider } from '../DataProvider'
|
|
1270
|
+
|
|
1271
|
+
export class AirtableProvider implements DataProvider {
|
|
1272
|
+
private base
|
|
1273
|
+
|
|
1274
|
+
constructor(apiKey: string, baseId: string) {
|
|
1275
|
+
const airtable = new Airtable({ apiKey })
|
|
1276
|
+
this.base = airtable.base(baseId)
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
things = {
|
|
1280
|
+
get: (id: string) =>
|
|
1281
|
+
Effect.gen(this, function* () {
|
|
1282
|
+
const record = yield* Effect.tryPromise({
|
|
1283
|
+
try: () => this.base('Things').find(id),
|
|
1284
|
+
catch: (error) => new Error(String(error))
|
|
1285
|
+
})
|
|
1286
|
+
|
|
1287
|
+
return {
|
|
1288
|
+
_id: record.id,
|
|
1289
|
+
type: record.fields.Type,
|
|
1290
|
+
name: record.fields.Name,
|
|
1291
|
+
properties: record.fields,
|
|
1292
|
+
status: 'active',
|
|
1293
|
+
createdAt: new Date(record.fields.Created).getTime(),
|
|
1294
|
+
updatedAt: new Date(record.fields.Modified).getTime()
|
|
1295
|
+
}
|
|
1296
|
+
}),
|
|
1297
|
+
|
|
1298
|
+
list: (params) =>
|
|
1299
|
+
Effect.gen(this, function* () {
|
|
1300
|
+
const records = yield* Effect.tryPromise({
|
|
1301
|
+
try: () =>
|
|
1302
|
+
this.base('Things')
|
|
1303
|
+
.select({
|
|
1304
|
+
filterByFormula: `{Type} = '${params.type}'`,
|
|
1305
|
+
maxRecords: params.limit || 10
|
|
1306
|
+
})
|
|
1307
|
+
.all(),
|
|
1308
|
+
catch: (error) => new Error(String(error))
|
|
1309
|
+
})
|
|
1310
|
+
|
|
1311
|
+
return records.map(record => ({
|
|
1312
|
+
_id: record.id,
|
|
1313
|
+
type: record.fields.Type,
|
|
1314
|
+
name: record.fields.Name,
|
|
1315
|
+
properties: record.fields,
|
|
1316
|
+
status: 'active',
|
|
1317
|
+
createdAt: new Date(record.fields.Created).getTime(),
|
|
1318
|
+
updatedAt: new Date(record.fields.Modified).getTime()
|
|
1319
|
+
}))
|
|
1320
|
+
}),
|
|
1321
|
+
|
|
1322
|
+
// create, update, delete...
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
// ... rest
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
export function airtableProvider(config: { apiKey: string; baseId: string }) {
|
|
1329
|
+
return Layer.succeed(
|
|
1330
|
+
DataProvider,
|
|
1331
|
+
new AirtableProvider(config.apiKey, config.baseId)
|
|
1332
|
+
)
|
|
1333
|
+
}
|
|
1334
|
+
```
|
|
1335
|
+
|
|
1336
|
+
---
|
|
1337
|
+
|
|
1338
|
+
## Custom Backends
|
|
1339
|
+
|
|
1340
|
+
### Your Own API
|
|
1341
|
+
|
|
1342
|
+
```typescript
|
|
1343
|
+
// frontend/src/providers/custom/CustomProvider.ts
|
|
1344
|
+
import { Effect, Layer } from 'effect'
|
|
1345
|
+
import { DataProvider } from '../DataProvider'
|
|
1346
|
+
|
|
1347
|
+
export class CustomProvider implements DataProvider {
|
|
1348
|
+
constructor(
|
|
1349
|
+
private config: {
|
|
1350
|
+
baseUrl: string
|
|
1351
|
+
authToken: string
|
|
1352
|
+
// Add your custom config
|
|
1353
|
+
}
|
|
1354
|
+
) {}
|
|
1355
|
+
|
|
1356
|
+
things = {
|
|
1357
|
+
get: (id: string) =>
|
|
1358
|
+
Effect.gen(this, function* () {
|
|
1359
|
+
// Your API call
|
|
1360
|
+
const response = yield* Effect.tryPromise({
|
|
1361
|
+
try: () =>
|
|
1362
|
+
fetch(`${this.config.baseUrl}/v1/entities/${id}`, {
|
|
1363
|
+
headers: {
|
|
1364
|
+
'X-API-Key': this.config.authToken
|
|
1365
|
+
}
|
|
1366
|
+
}),
|
|
1367
|
+
catch: (error) => new Error(String(error))
|
|
1368
|
+
})
|
|
1369
|
+
|
|
1370
|
+
const data = yield* Effect.tryPromise({
|
|
1371
|
+
try: () => response.json(),
|
|
1372
|
+
catch: (error) => new Error(String(error))
|
|
1373
|
+
})
|
|
1374
|
+
|
|
1375
|
+
// Transform YOUR data → ONE Thing
|
|
1376
|
+
return {
|
|
1377
|
+
_id: data.entity_id,
|
|
1378
|
+
type: data.entity_type,
|
|
1379
|
+
name: data.display_name,
|
|
1380
|
+
properties: data.metadata,
|
|
1381
|
+
status: data.is_active ? 'active' : 'inactive',
|
|
1382
|
+
createdAt: data.created_timestamp,
|
|
1383
|
+
updatedAt: data.updated_timestamp
|
|
1384
|
+
}
|
|
1385
|
+
}),
|
|
1386
|
+
|
|
1387
|
+
// Implement all other methods...
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
connections = {
|
|
1391
|
+
// Your relationship API calls...
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
events = {
|
|
1395
|
+
// Your analytics/logging API calls...
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
knowledge = {
|
|
1399
|
+
// Your search API calls...
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
export function customProvider(config: any) {
|
|
1404
|
+
return Layer.succeed(DataProvider, new CustomProvider(config))
|
|
1405
|
+
}
|
|
1406
|
+
```
|
|
1407
|
+
|
|
1408
|
+
---
|
|
1409
|
+
|
|
1410
|
+
## Multi-Backend Setup
|
|
1411
|
+
|
|
1412
|
+
### Use Multiple Backends Simultaneously
|
|
1413
|
+
|
|
1414
|
+
```typescript
|
|
1415
|
+
// frontend/astro.config.ts
|
|
1416
|
+
import { defineConfig } from 'astro/config'
|
|
1417
|
+
import { one } from '@one/astro-integration'
|
|
1418
|
+
import { convexProvider } from './src/providers/convex'
|
|
1419
|
+
import { supabaseProvider } from './src/providers/supabase'
|
|
1420
|
+
import { wordpressProvider } from './src/providers/wordpress'
|
|
1421
|
+
|
|
1422
|
+
export default defineConfig({
|
|
1423
|
+
integrations: [
|
|
1424
|
+
one({
|
|
1425
|
+
// ✅ Use multiple providers!
|
|
1426
|
+
providers: {
|
|
1427
|
+
// Primary: Convex for real-time data
|
|
1428
|
+
primary: convexProvider({
|
|
1429
|
+
url: import.meta.env.PUBLIC_CONVEX_URL
|
|
1430
|
+
}),
|
|
1431
|
+
|
|
1432
|
+
// Content: WordPress for blog
|
|
1433
|
+
content: wordpressProvider({
|
|
1434
|
+
url: import.meta.env.WORDPRESS_URL,
|
|
1435
|
+
username: import.meta.env.WORDPRESS_USERNAME,
|
|
1436
|
+
password: import.meta.env.WORDPRESS_APP_PASSWORD
|
|
1437
|
+
}),
|
|
1438
|
+
|
|
1439
|
+
// Analytics: Supabase for analytics
|
|
1440
|
+
analytics: supabaseProvider({
|
|
1441
|
+
url: import.meta.env.PUBLIC_SUPABASE_URL,
|
|
1442
|
+
anonKey: import.meta.env.PUBLIC_SUPABASE_ANON_KEY
|
|
1443
|
+
})
|
|
1444
|
+
}
|
|
1445
|
+
})
|
|
1446
|
+
]
|
|
1447
|
+
})
|
|
1448
|
+
```
|
|
1449
|
+
|
|
1450
|
+
### Route Requests to Different Backends
|
|
1451
|
+
|
|
1452
|
+
```typescript
|
|
1453
|
+
// frontend/src/services/ThingClientService.ts
|
|
1454
|
+
import { Effect } from 'effect'
|
|
1455
|
+
import { DataProvider } from '@/providers/DataProvider'
|
|
1456
|
+
|
|
1457
|
+
export class ThingClientService extends Effect.Service<ThingClientService>()(
|
|
1458
|
+
'ThingClientService',
|
|
1459
|
+
{
|
|
1460
|
+
effect: Effect.gen(function* () {
|
|
1461
|
+
// Get all configured providers
|
|
1462
|
+
const providers = yield* Effect.all({
|
|
1463
|
+
primary: DataProvider.fromTag('primary'),
|
|
1464
|
+
content: DataProvider.fromTag('content'),
|
|
1465
|
+
analytics: DataProvider.fromTag('analytics')
|
|
1466
|
+
})
|
|
1467
|
+
|
|
1468
|
+
return {
|
|
1469
|
+
get: (id: string, type: string) =>
|
|
1470
|
+
Effect.gen(function* () {
|
|
1471
|
+
// Route based on thing type
|
|
1472
|
+
if (type === 'post' || type === 'page') {
|
|
1473
|
+
// Blog content → WordPress
|
|
1474
|
+
return yield* providers.content.things.get(id)
|
|
1475
|
+
} else if (type === 'event') {
|
|
1476
|
+
// Events → Analytics backend
|
|
1477
|
+
return yield* providers.analytics.things.get(id)
|
|
1478
|
+
} else {
|
|
1479
|
+
// Everything else → Primary backend
|
|
1480
|
+
return yield* providers.primary.things.get(id)
|
|
1481
|
+
}
|
|
1482
|
+
}),
|
|
1483
|
+
|
|
1484
|
+
list: (type: string, orgId?: string) =>
|
|
1485
|
+
Effect.gen(function* () {
|
|
1486
|
+
// Similar routing logic
|
|
1487
|
+
const provider = this.selectProvider(type)
|
|
1488
|
+
return yield* provider.things.list({ type, organizationId: orgId })
|
|
1489
|
+
})
|
|
1490
|
+
}
|
|
1491
|
+
})
|
|
1492
|
+
}
|
|
1493
|
+
) {}
|
|
1494
|
+
```
|
|
1495
|
+
|
|
1496
|
+
---
|
|
1497
|
+
|
|
1498
|
+
## Testing
|
|
1499
|
+
|
|
1500
|
+
### Mock Provider for Testing
|
|
1501
|
+
|
|
1502
|
+
```typescript
|
|
1503
|
+
// frontend/src/providers/__tests__/MockProvider.ts
|
|
1504
|
+
import { Effect, Layer } from 'effect'
|
|
1505
|
+
import { DataProvider, Thing } from '../DataProvider'
|
|
1506
|
+
|
|
1507
|
+
export class MockProvider implements DataProvider {
|
|
1508
|
+
private storage = new Map<string, Thing>()
|
|
1509
|
+
|
|
1510
|
+
things = {
|
|
1511
|
+
get: (id: string) =>
|
|
1512
|
+
Effect.gen(this, function* () {
|
|
1513
|
+
const thing = this.storage.get(id)
|
|
1514
|
+
if (!thing) {
|
|
1515
|
+
return yield* Effect.fail(new ThingNotFoundError(id))
|
|
1516
|
+
}
|
|
1517
|
+
return thing
|
|
1518
|
+
}),
|
|
1519
|
+
|
|
1520
|
+
list: (params) =>
|
|
1521
|
+
Effect.succeed(
|
|
1522
|
+
Array.from(this.storage.values()).filter(
|
|
1523
|
+
thing => thing.type === params.type
|
|
1524
|
+
)
|
|
1525
|
+
),
|
|
1526
|
+
|
|
1527
|
+
create: (input) =>
|
|
1528
|
+
Effect.gen(this, function* () {
|
|
1529
|
+
const id = `mock_${Date.now()}`
|
|
1530
|
+
const thing: Thing = {
|
|
1531
|
+
_id: id,
|
|
1532
|
+
type: input.type,
|
|
1533
|
+
name: input.name,
|
|
1534
|
+
properties: input.properties,
|
|
1535
|
+
status: 'active',
|
|
1536
|
+
createdAt: Date.now(),
|
|
1537
|
+
updatedAt: Date.now()
|
|
1538
|
+
}
|
|
1539
|
+
this.storage.set(id, thing)
|
|
1540
|
+
return id
|
|
1541
|
+
}),
|
|
1542
|
+
|
|
1543
|
+
update: (id, updates) =>
|
|
1544
|
+
Effect.gen(this, function* () {
|
|
1545
|
+
const thing = this.storage.get(id)
|
|
1546
|
+
if (!thing) {
|
|
1547
|
+
return yield* Effect.fail(new Error('Not found'))
|
|
1548
|
+
}
|
|
1549
|
+
this.storage.set(id, { ...thing, ...updates })
|
|
1550
|
+
}),
|
|
1551
|
+
|
|
1552
|
+
delete: (id) =>
|
|
1553
|
+
Effect.gen(this, function* () {
|
|
1554
|
+
this.storage.delete(id)
|
|
1555
|
+
})
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
connections = { /* mock implementations */ }
|
|
1559
|
+
events = { /* mock implementations */ }
|
|
1560
|
+
knowledge = { /* mock implementations */ }
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
export function mockProvider() {
|
|
1564
|
+
return Layer.succeed(DataProvider, new MockProvider())
|
|
1565
|
+
}
|
|
1566
|
+
```
|
|
1567
|
+
|
|
1568
|
+
### Test with Mock Provider
|
|
1569
|
+
|
|
1570
|
+
```typescript
|
|
1571
|
+
// frontend/src/components/__tests__/ThingList.test.tsx
|
|
1572
|
+
import { describe, it, expect } from 'vitest'
|
|
1573
|
+
import { Effect } from 'effect'
|
|
1574
|
+
import { ThingClientService } from '@/services/ThingClientService'
|
|
1575
|
+
import { mockProvider } from '@/providers/__tests__/MockProvider'
|
|
1576
|
+
|
|
1577
|
+
describe('ThingList', () => {
|
|
1578
|
+
it('lists things from provider', async () => {
|
|
1579
|
+
const program = Effect.gen(function* () {
|
|
1580
|
+
const thingService = yield* ThingClientService
|
|
1581
|
+
|
|
1582
|
+
// Create test data
|
|
1583
|
+
yield* thingService.create({
|
|
1584
|
+
type: 'course',
|
|
1585
|
+
name: 'Test Course',
|
|
1586
|
+
properties: {}
|
|
1587
|
+
})
|
|
1588
|
+
|
|
1589
|
+
// List things
|
|
1590
|
+
const things = yield* thingService.list('course')
|
|
1591
|
+
|
|
1592
|
+
return things
|
|
1593
|
+
})
|
|
1594
|
+
|
|
1595
|
+
// Run with mock provider
|
|
1596
|
+
const things = await Effect.runPromise(
|
|
1597
|
+
program.pipe(
|
|
1598
|
+
Effect.provide(ThingClientService.Default),
|
|
1599
|
+
Effect.provide(mockProvider())
|
|
1600
|
+
)
|
|
1601
|
+
)
|
|
1602
|
+
|
|
1603
|
+
expect(things).toHaveLength(1)
|
|
1604
|
+
expect(things[0].name).toBe('Test Course')
|
|
1605
|
+
})
|
|
1606
|
+
})
|
|
1607
|
+
```
|
|
1608
|
+
|
|
1609
|
+
---
|
|
1610
|
+
|
|
1611
|
+
## Deployment
|
|
1612
|
+
|
|
1613
|
+
### Environment Configuration
|
|
1614
|
+
|
|
1615
|
+
```bash
|
|
1616
|
+
# frontend/.env
|
|
1617
|
+
|
|
1618
|
+
# ========================================
|
|
1619
|
+
# Provider Selection
|
|
1620
|
+
# ========================================
|
|
1621
|
+
PUBLIC_DATA_PROVIDER=convex # convex | supabase | wordpress | notion | custom
|
|
1622
|
+
|
|
1623
|
+
# ========================================
|
|
1624
|
+
# Convex
|
|
1625
|
+
# ========================================
|
|
1626
|
+
PUBLIC_CONVEX_URL=https://your-convex.convex.cloud
|
|
1627
|
+
|
|
1628
|
+
# ========================================
|
|
1629
|
+
# Supabase
|
|
1630
|
+
# ========================================
|
|
1631
|
+
PUBLIC_SUPABASE_URL=https://your-project.supabase.co
|
|
1632
|
+
PUBLIC_SUPABASE_ANON_KEY=your-anon-key
|
|
1633
|
+
|
|
1634
|
+
# ========================================
|
|
1635
|
+
# WordPress
|
|
1636
|
+
# ========================================
|
|
1637
|
+
WORDPRESS_URL=https://yoursite.com
|
|
1638
|
+
WORDPRESS_USERNAME=admin
|
|
1639
|
+
WORDPRESS_APP_PASSWORD=xxxx xxxx xxxx xxxx
|
|
1640
|
+
|
|
1641
|
+
# ========================================
|
|
1642
|
+
# Notion
|
|
1643
|
+
# ========================================
|
|
1644
|
+
NOTION_API_KEY=secret_xxx
|
|
1645
|
+
NOTION_DATABASE_ID=your-database-id
|
|
1646
|
+
|
|
1647
|
+
# ========================================
|
|
1648
|
+
# Custom API
|
|
1649
|
+
# ========================================
|
|
1650
|
+
CUSTOM_API_URL=https://api.yoursite.com
|
|
1651
|
+
CUSTOM_API_KEY=your-api-key
|
|
1652
|
+
```
|
|
1653
|
+
|
|
1654
|
+
### Deploy Frontend
|
|
1655
|
+
|
|
1656
|
+
```bash
|
|
1657
|
+
# Build frontend
|
|
1658
|
+
cd frontend
|
|
1659
|
+
npm run build
|
|
1660
|
+
|
|
1661
|
+
# Deploy to Cloudflare Pages / Vercel / Netlify
|
|
1662
|
+
# Set environment variables in hosting platform
|
|
1663
|
+
|
|
1664
|
+
# Frontend connects to backend via DataProvider
|
|
1665
|
+
# Backend can be anywhere (Convex, Supabase, your API, etc.)
|
|
1666
|
+
```
|
|
1667
|
+
|
|
1668
|
+
---
|
|
1669
|
+
|
|
1670
|
+
## Summary
|
|
1671
|
+
|
|
1672
|
+
### Key Principles
|
|
1673
|
+
|
|
1674
|
+
1. **Universal Interface**: DataProvider works with ANY backend
|
|
1675
|
+
2. **Backend-Agnostic Frontend**: Components never know which backend
|
|
1676
|
+
3. **Easy Switching**: Change ONE line to swap backends
|
|
1677
|
+
4. **Multi-Backend**: Use multiple backends simultaneously
|
|
1678
|
+
5. **Type-Safe**: Effect.ts ensures correctness
|
|
1679
|
+
6. **Testable**: Mock providers for testing
|
|
1680
|
+
|
|
1681
|
+
### Implementation Checklist
|
|
1682
|
+
|
|
1683
|
+
- [ ] Define DataProvider interface
|
|
1684
|
+
- [ ] Implement provider for your backend
|
|
1685
|
+
- [ ] Transform backend data → ONE Things
|
|
1686
|
+
- [ ] Configure Astro to use provider
|
|
1687
|
+
- [ ] Test CRUD operations
|
|
1688
|
+
- [ ] Deploy frontend + backend
|
|
1689
|
+
|
|
1690
|
+
### Next Steps
|
|
1691
|
+
|
|
1692
|
+
1. Choose your backend(s)
|
|
1693
|
+
2. Implement DataProvider for it
|
|
1694
|
+
3. Update Astro config
|
|
1695
|
+
4. Test with your data
|
|
1696
|
+
5. Deploy
|
|
1697
|
+
|
|
1698
|
+
---
|
|
1699
|
+
|
|
1700
|
+
**ONE Frontend + ANY Backend = Unlimited Flexibility**
|
|
1701
|
+
|
|
1702
|
+
Zero lock-in. Maximum flexibility. One interface.
|