@dotdo/do 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/README.md +400 -0
- package/dist/ai/embeddings.d.ts +129 -0
- package/dist/ai/embeddings.d.ts.map +1 -0
- package/dist/ai/embeddings.js +217 -0
- package/dist/ai/embeddings.js.map +1 -0
- package/dist/ai/gateway.d.ts +139 -0
- package/dist/ai/gateway.d.ts.map +1 -0
- package/dist/ai/gateway.js +179 -0
- package/dist/ai/gateway.js.map +1 -0
- package/dist/ai/image.d.ts +140 -0
- package/dist/ai/image.d.ts.map +1 -0
- package/dist/ai/image.js +199 -0
- package/dist/ai/image.js.map +1 -0
- package/dist/ai/index.d.ts +98 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +223 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/models.d.ts +81 -0
- package/dist/ai/models.d.ts.map +1 -0
- package/dist/ai/models.js +537 -0
- package/dist/ai/models.js.map +1 -0
- package/dist/ai/text.d.ts +176 -0
- package/dist/ai/text.d.ts.map +1 -0
- package/dist/ai/text.js +253 -0
- package/dist/ai/text.js.map +1 -0
- package/dist/ai/voice/agents.d.ts +224 -0
- package/dist/ai/voice/agents.d.ts.map +1 -0
- package/dist/ai/voice/agents.js +375 -0
- package/dist/ai/voice/agents.js.map +1 -0
- package/dist/ai/voice/campaigns.d.ts +307 -0
- package/dist/ai/voice/campaigns.d.ts.map +1 -0
- package/dist/ai/voice/campaigns.js +739 -0
- package/dist/ai/voice/campaigns.js.map +1 -0
- package/dist/ai/voice/index.d.ts +21 -0
- package/dist/ai/voice/index.d.ts.map +1 -0
- package/dist/ai/voice/index.js +42 -0
- package/dist/ai/voice/index.js.map +1 -0
- package/dist/ai/voice/providers.d.ts +283 -0
- package/dist/ai/voice/providers.d.ts.map +1 -0
- package/dist/ai/voice/providers.js +286 -0
- package/dist/ai/voice/providers.js.map +1 -0
- package/dist/ai/voice/sessions.d.ts +294 -0
- package/dist/ai/voice/sessions.d.ts.map +1 -0
- package/dist/ai/voice/sessions.js +531 -0
- package/dist/ai/voice/sessions.js.map +1 -0
- package/dist/ai/voice/tools.d.ts +242 -0
- package/dist/ai/voice/tools.d.ts.map +1 -0
- package/dist/ai/voice/tools.js +370 -0
- package/dist/ai/voice/tools.js.map +1 -0
- package/dist/ai/voice/tts.d.ts +173 -0
- package/dist/ai/voice/tts.d.ts.map +1 -0
- package/dist/ai/voice/tts.js +252 -0
- package/dist/ai/voice/tts.js.map +1 -0
- package/dist/ai/voice/webrtc.d.ts +228 -0
- package/dist/ai/voice/webrtc.d.ts.map +1 -0
- package/dist/ai/voice/webrtc.js +372 -0
- package/dist/ai/voice/webrtc.js.map +1 -0
- package/dist/api/index.d.ts +103 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +191 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/mcp/handlers.d.ts +25 -0
- package/dist/api/mcp/handlers.d.ts.map +1 -0
- package/dist/api/mcp/handlers.js +422 -0
- package/dist/api/mcp/handlers.js.map +1 -0
- package/dist/api/mcp/index.d.ts +113 -0
- package/dist/api/mcp/index.d.ts.map +1 -0
- package/dist/api/mcp/index.js +141 -0
- package/dist/api/mcp/index.js.map +1 -0
- package/dist/api/middleware/auth.d.ts +65 -0
- package/dist/api/middleware/auth.d.ts.map +1 -0
- package/dist/api/middleware/auth.js +271 -0
- package/dist/api/middleware/auth.js.map +1 -0
- package/dist/api/middleware/cors.d.ts +62 -0
- package/dist/api/middleware/cors.d.ts.map +1 -0
- package/dist/api/middleware/cors.js +225 -0
- package/dist/api/middleware/cors.js.map +1 -0
- package/dist/api/middleware/index.d.ts +60 -0
- package/dist/api/middleware/index.d.ts.map +1 -0
- package/dist/api/middleware/index.js +175 -0
- package/dist/api/middleware/index.js.map +1 -0
- package/dist/api/middleware/rateLimit.d.ts +84 -0
- package/dist/api/middleware/rateLimit.d.ts.map +1 -0
- package/dist/api/middleware/rateLimit.js +321 -0
- package/dist/api/middleware/rateLimit.js.map +1 -0
- package/dist/api/routes/ai.d.ts +17 -0
- package/dist/api/routes/ai.d.ts.map +1 -0
- package/dist/api/routes/ai.js +430 -0
- package/dist/api/routes/ai.js.map +1 -0
- package/dist/api/routes/do.d.ts +17 -0
- package/dist/api/routes/do.d.ts.map +1 -0
- package/dist/api/routes/do.js +458 -0
- package/dist/api/routes/do.js.map +1 -0
- package/dist/api/routes/functions.d.ts +111 -0
- package/dist/api/routes/functions.d.ts.map +1 -0
- package/dist/api/routes/functions.js +548 -0
- package/dist/api/routes/functions.js.map +1 -0
- package/dist/api/routes/health.d.ts +16 -0
- package/dist/api/routes/health.d.ts.map +1 -0
- package/dist/api/routes/health.js +163 -0
- package/dist/api/routes/health.js.map +1 -0
- package/dist/api/routes/index.d.ts +41 -0
- package/dist/api/routes/index.d.ts.map +1 -0
- package/dist/api/routes/index.js +275 -0
- package/dist/api/routes/index.js.map +1 -0
- package/dist/api/routes/nouns.d.ts +26 -0
- package/dist/api/routes/nouns.d.ts.map +1 -0
- package/dist/api/routes/nouns.js +456 -0
- package/dist/api/routes/nouns.js.map +1 -0
- package/dist/api/routes/orgs.d.ts +17 -0
- package/dist/api/routes/orgs.d.ts.map +1 -0
- package/dist/api/routes/orgs.js +560 -0
- package/dist/api/routes/orgs.js.map +1 -0
- package/dist/api/routes/relationships.d.ts +30 -0
- package/dist/api/routes/relationships.d.ts.map +1 -0
- package/dist/api/routes/relationships.js +360 -0
- package/dist/api/routes/relationships.js.map +1 -0
- package/dist/api/routes/roles.d.ts +17 -0
- package/dist/api/routes/roles.d.ts.map +1 -0
- package/dist/api/routes/roles.js +721 -0
- package/dist/api/routes/roles.js.map +1 -0
- package/dist/api/routes/things.d.ts +27 -0
- package/dist/api/routes/things.d.ts.map +1 -0
- package/dist/api/routes/things.js +568 -0
- package/dist/api/routes/things.js.map +1 -0
- package/dist/api/routes/users.d.ts +17 -0
- package/dist/api/routes/users.d.ts.map +1 -0
- package/dist/api/routes/users.js +401 -0
- package/dist/api/routes/users.js.map +1 -0
- package/dist/api/routes/verbs.d.ts +31 -0
- package/dist/api/routes/verbs.d.ts.map +1 -0
- package/dist/api/routes/verbs.js +505 -0
- package/dist/api/routes/verbs.js.map +1 -0
- package/dist/api/routes/workflows.d.ts +44 -0
- package/dist/api/routes/workflows.d.ts.map +1 -0
- package/dist/api/routes/workflows.js +521 -0
- package/dist/api/routes/workflows.js.map +1 -0
- package/dist/api/types.d.ts +370 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +11 -0
- package/dist/api/types.js.map +1 -0
- package/dist/db/cdc/events.d.ts +201 -0
- package/dist/db/cdc/events.d.ts.map +1 -0
- package/dist/db/cdc/events.js +271 -0
- package/dist/db/cdc/events.js.map +1 -0
- package/dist/db/cdc/index.d.ts +13 -0
- package/dist/db/cdc/index.d.ts.map +1 -0
- package/dist/db/cdc/index.js +16 -0
- package/dist/db/cdc/index.js.map +1 -0
- package/dist/db/cdc/replay.d.ts +388 -0
- package/dist/db/cdc/replay.d.ts.map +1 -0
- package/dist/db/cdc/replay.js +469 -0
- package/dist/db/cdc/replay.js.map +1 -0
- package/dist/db/cdc/storage.d.ts +567 -0
- package/dist/db/cdc/storage.d.ts.map +1 -0
- package/dist/db/cdc/storage.js +856 -0
- package/dist/db/cdc/storage.js.map +1 -0
- package/dist/db/cdc/streaming.d.ts +459 -0
- package/dist/db/cdc/streaming.d.ts.map +1 -0
- package/dist/db/cdc/streaming.js +636 -0
- package/dist/db/cdc/streaming.js.map +1 -0
- package/dist/db/collections/actions.d.ts +440 -0
- package/dist/db/collections/actions.d.ts.map +1 -0
- package/dist/db/collections/actions.js +631 -0
- package/dist/db/collections/actions.js.map +1 -0
- package/dist/db/collections/base.d.ts +342 -0
- package/dist/db/collections/base.d.ts.map +1 -0
- package/dist/db/collections/base.js +510 -0
- package/dist/db/collections/base.js.map +1 -0
- package/dist/db/collections/index.d.ts +50 -0
- package/dist/db/collections/index.d.ts.map +1 -0
- package/dist/db/collections/index.js +48 -0
- package/dist/db/collections/index.js.map +1 -0
- package/dist/db/collections/nouns.d.ts +260 -0
- package/dist/db/collections/nouns.d.ts.map +1 -0
- package/dist/db/collections/nouns.js +273 -0
- package/dist/db/collections/nouns.js.map +1 -0
- package/dist/db/collections/relationships.d.ts +484 -0
- package/dist/db/collections/relationships.d.ts.map +1 -0
- package/dist/db/collections/relationships.js +815 -0
- package/dist/db/collections/relationships.js.map +1 -0
- package/dist/db/collections/things.d.ts +439 -0
- package/dist/db/collections/things.d.ts.map +1 -0
- package/dist/db/collections/things.js +603 -0
- package/dist/db/collections/things.js.map +1 -0
- package/dist/db/collections/verbs.d.ts +308 -0
- package/dist/db/collections/verbs.d.ts.map +1 -0
- package/dist/db/collections/verbs.js +480 -0
- package/dist/db/collections/verbs.js.map +1 -0
- package/dist/db/index.d.ts +14 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +23 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/storage/cold.d.ts +313 -0
- package/dist/db/storage/cold.d.ts.map +1 -0
- package/dist/db/storage/cold.js +319 -0
- package/dist/db/storage/cold.js.map +1 -0
- package/dist/db/storage/hot.d.ts +340 -0
- package/dist/db/storage/hot.d.ts.map +1 -0
- package/dist/db/storage/hot.js +333 -0
- package/dist/db/storage/hot.js.map +1 -0
- package/dist/db/storage/index.d.ts +242 -0
- package/dist/db/storage/index.d.ts.map +1 -0
- package/dist/db/storage/index.js +109 -0
- package/dist/db/storage/index.js.map +1 -0
- package/dist/db/storage/snapshots.d.ts +342 -0
- package/dist/db/storage/snapshots.d.ts.map +1 -0
- package/dist/db/storage/snapshots.js +298 -0
- package/dist/db/storage/snapshots.js.map +1 -0
- package/dist/db/storage/vortex.d.ts +324 -0
- package/dist/db/storage/vortex.d.ts.map +1 -0
- package/dist/db/storage/vortex.js +365 -0
- package/dist/db/storage/vortex.js.map +1 -0
- package/dist/db/storage/warm.d.ts +306 -0
- package/dist/db/storage/warm.d.ts.map +1 -0
- package/dist/db/storage/warm.js +339 -0
- package/dist/db/storage/warm.js.map +1 -0
- package/dist/do/DigitalObject.d.ts +595 -0
- package/dist/do/DigitalObject.d.ts.map +1 -0
- package/dist/do/DigitalObject.js +971 -0
- package/dist/do/DigitalObject.js.map +1 -0
- package/dist/do/business/financial/accounting.d.ts +436 -0
- package/dist/do/business/financial/accounting.d.ts.map +1 -0
- package/dist/do/business/financial/accounting.js +476 -0
- package/dist/do/business/financial/accounting.js.map +1 -0
- package/dist/do/business/financial/index.d.ts +15 -0
- package/dist/do/business/financial/index.d.ts.map +1 -0
- package/dist/do/business/financial/index.js +20 -0
- package/dist/do/business/financial/index.js.map +1 -0
- package/dist/do/business/financial/metrics.d.ts +370 -0
- package/dist/do/business/financial/metrics.d.ts.map +1 -0
- package/dist/do/business/financial/metrics.js +376 -0
- package/dist/do/business/financial/metrics.js.map +1 -0
- package/dist/do/business/financial/payments.d.ts +397 -0
- package/dist/do/business/financial/payments.d.ts.map +1 -0
- package/dist/do/business/financial/payments.js +395 -0
- package/dist/do/business/financial/payments.js.map +1 -0
- package/dist/do/business/financial/reports.d.ts +284 -0
- package/dist/do/business/financial/reports.d.ts.map +1 -0
- package/dist/do/business/financial/reports.js +347 -0
- package/dist/do/business/financial/reports.js.map +1 -0
- package/dist/do/business/financial/stripe.d.ts +254 -0
- package/dist/do/business/financial/stripe.d.ts.map +1 -0
- package/dist/do/business/financial/stripe.js +261 -0
- package/dist/do/business/financial/stripe.js.map +1 -0
- package/dist/do/business/financial/subscriptions.d.ts +402 -0
- package/dist/do/business/financial/subscriptions.d.ts.map +1 -0
- package/dist/do/business/financial/subscriptions.js +349 -0
- package/dist/do/business/financial/subscriptions.js.map +1 -0
- package/dist/do/business/index.d.ts +9 -0
- package/dist/do/business/index.d.ts.map +1 -0
- package/dist/do/business/index.js +10 -0
- package/dist/do/business/index.js.map +1 -0
- package/dist/do/colo/followers.d.ts +194 -0
- package/dist/do/colo/followers.d.ts.map +1 -0
- package/dist/do/colo/followers.js +224 -0
- package/dist/do/colo/followers.js.map +1 -0
- package/dist/do/colo/fork.d.ts +103 -0
- package/dist/do/colo/fork.d.ts.map +1 -0
- package/dist/do/colo/fork.js +143 -0
- package/dist/do/colo/fork.js.map +1 -0
- package/dist/do/colo/index.d.ts +181 -0
- package/dist/do/colo/index.d.ts.map +1 -0
- package/dist/do/colo/index.js +145 -0
- package/dist/do/colo/index.js.map +1 -0
- package/dist/do/colo/info.d.ts +106 -0
- package/dist/do/colo/info.d.ts.map +1 -0
- package/dist/do/colo/info.js +196 -0
- package/dist/do/colo/info.js.map +1 -0
- package/dist/do/colo/migrate.d.ts +161 -0
- package/dist/do/colo/migrate.d.ts.map +1 -0
- package/dist/do/colo/migrate.js +190 -0
- package/dist/do/colo/migrate.js.map +1 -0
- package/dist/do/colo/routing.d.ts +182 -0
- package/dist/do/colo/routing.d.ts.map +1 -0
- package/dist/do/colo/routing.js +254 -0
- package/dist/do/colo/routing.js.map +1 -0
- package/dist/do/domains/dns.d.ts +269 -0
- package/dist/do/domains/dns.d.ts.map +1 -0
- package/dist/do/domains/dns.js +215 -0
- package/dist/do/domains/dns.js.map +1 -0
- package/dist/do/domains/index.d.ts +40 -0
- package/dist/do/domains/index.d.ts.map +1 -0
- package/dist/do/domains/index.js +61 -0
- package/dist/do/domains/index.js.map +1 -0
- package/dist/do/domains/routing.d.ts +263 -0
- package/dist/do/domains/routing.d.ts.map +1 -0
- package/dist/do/domains/routing.js +362 -0
- package/dist/do/domains/routing.js.map +1 -0
- package/dist/do/domains/ssl.d.ts +217 -0
- package/dist/do/domains/ssl.d.ts.map +1 -0
- package/dist/do/domains/ssl.js +231 -0
- package/dist/do/domains/ssl.js.map +1 -0
- package/dist/do/domains/subdomains.d.ts +207 -0
- package/dist/do/domains/subdomains.d.ts.map +1 -0
- package/dist/do/domains/subdomains.js +223 -0
- package/dist/do/domains/subdomains.js.map +1 -0
- package/dist/do/domains/tlds.d.ts +175 -0
- package/dist/do/domains/tlds.d.ts.map +1 -0
- package/dist/do/domains/tlds.js +188 -0
- package/dist/do/domains/tlds.js.map +1 -0
- package/dist/do/domains/validation.d.ts +164 -0
- package/dist/do/domains/validation.d.ts.map +1 -0
- package/dist/do/domains/validation.js +290 -0
- package/dist/do/domains/validation.js.map +1 -0
- package/dist/do/hibernation.d.ts +385 -0
- package/dist/do/hibernation.d.ts.map +1 -0
- package/dist/do/hibernation.js +518 -0
- package/dist/do/hibernation.js.map +1 -0
- package/dist/do/index.d.ts +19 -0
- package/dist/do/index.d.ts.map +1 -0
- package/dist/do/index.js +23 -0
- package/dist/do/index.js.map +1 -0
- package/dist/do/state.d.ts +336 -0
- package/dist/do/state.d.ts.map +1 -0
- package/dist/do/state.js +290 -0
- package/dist/do/state.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -0
- package/dist/rpc/client.d.ts +426 -0
- package/dist/rpc/client.d.ts.map +1 -0
- package/dist/rpc/client.js +826 -0
- package/dist/rpc/client.js.map +1 -0
- package/dist/rpc/index.d.ts +19 -0
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js +23 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/rpc/methods.d.ts +364 -0
- package/dist/rpc/methods.d.ts.map +1 -0
- package/dist/rpc/methods.js +557 -0
- package/dist/rpc/methods.js.map +1 -0
- package/dist/rpc/protocol.d.ts +310 -0
- package/dist/rpc/protocol.d.ts.map +1 -0
- package/dist/rpc/protocol.js +672 -0
- package/dist/rpc/protocol.js.map +1 -0
- package/dist/rpc/routes.d.ts +332 -0
- package/dist/rpc/routes.d.ts.map +1 -0
- package/dist/rpc/routes.js +633 -0
- package/dist/rpc/routes.js.map +1 -0
- package/dist/rpc/server.d.ts +380 -0
- package/dist/rpc/server.d.ts.map +1 -0
- package/dist/rpc/server.js +850 -0
- package/dist/rpc/server.js.map +1 -0
- package/dist/sdk/auth.d.ts +201 -0
- package/dist/sdk/auth.d.ts.map +1 -0
- package/dist/sdk/auth.js +343 -0
- package/dist/sdk/auth.js.map +1 -0
- package/dist/sdk/client.d.ts +123 -0
- package/dist/sdk/client.d.ts.map +1 -0
- package/dist/sdk/client.js +403 -0
- package/dist/sdk/client.js.map +1 -0
- package/dist/sdk/index.d.ts +123 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +230 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/rpc.d.ts +275 -0
- package/dist/sdk/rpc.d.ts.map +1 -0
- package/dist/sdk/rpc.js +249 -0
- package/dist/sdk/rpc.js.map +1 -0
- package/dist/sdk/transport.d.ts +283 -0
- package/dist/sdk/transport.d.ts.map +1 -0
- package/dist/sdk/transport.js +661 -0
- package/dist/sdk/transport.js.map +1 -0
- package/dist/sdk/types.d.ts +265 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/dist/sdk/types.js +27 -0
- package/dist/sdk/types.js.map +1 -0
- package/dist/types/ai.d.ts +533 -0
- package/dist/types/ai.d.ts.map +1 -0
- package/dist/types/ai.js +18 -0
- package/dist/types/ai.js.map +1 -0
- package/dist/types/app.d.ts +371 -0
- package/dist/types/app.d.ts.map +1 -0
- package/dist/types/app.js +151 -0
- package/dist/types/app.js.map +1 -0
- package/dist/types/business.d.ts +482 -0
- package/dist/types/business.d.ts.map +1 -0
- package/dist/types/business.js +60 -0
- package/dist/types/business.js.map +1 -0
- package/dist/types/cascade.d.ts +323 -0
- package/dist/types/cascade.d.ts.map +1 -0
- package/dist/types/cascade.js +82 -0
- package/dist/types/cascade.js.map +1 -0
- package/dist/types/collections.d.ts +704 -0
- package/dist/types/collections.d.ts.map +1 -0
- package/dist/types/collections.js +23 -0
- package/dist/types/collections.js.map +1 -0
- package/dist/types/colo.d.ts +171 -0
- package/dist/types/colo.d.ts.map +1 -0
- package/dist/types/colo.js +63 -0
- package/dist/types/colo.js.map +1 -0
- package/dist/types/communication.d.ts +595 -0
- package/dist/types/communication.d.ts.map +1 -0
- package/dist/types/communication.js +16 -0
- package/dist/types/communication.js.map +1 -0
- package/dist/types/content.d.ts +286 -0
- package/dist/types/content.d.ts.map +1 -0
- package/dist/types/content.js +8 -0
- package/dist/types/content.js.map +1 -0
- package/dist/types/context.d.ts +407 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +36 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/databases.d.ts +377 -0
- package/dist/types/databases.d.ts.map +1 -0
- package/dist/types/databases.js +14 -0
- package/dist/types/databases.js.map +1 -0
- package/dist/types/domains.d.ts +132 -0
- package/dist/types/domains.d.ts.map +1 -0
- package/dist/types/domains.js +107 -0
- package/dist/types/domains.js.map +1 -0
- package/dist/types/execution.d.ts +381 -0
- package/dist/types/execution.d.ts.map +1 -0
- package/dist/types/execution.js +40 -0
- package/dist/types/execution.js.map +1 -0
- package/dist/types/financial.d.ts +608 -0
- package/dist/types/financial.d.ts.map +1 -0
- package/dist/types/financial.js +12 -0
- package/dist/types/financial.js.map +1 -0
- package/dist/types/functions.d.ts +215 -0
- package/dist/types/functions.d.ts.map +1 -0
- package/dist/types/functions.js +15 -0
- package/dist/types/functions.js.map +1 -0
- package/dist/types/git.d.ts +299 -0
- package/dist/types/git.d.ts.map +1 -0
- package/dist/types/git.js +17 -0
- package/dist/types/git.js.map +1 -0
- package/dist/types/identity.d.ts +141 -0
- package/dist/types/identity.d.ts.map +1 -0
- package/dist/types/identity.js +54 -0
- package/dist/types/identity.js.map +1 -0
- package/dist/types/index.d.ts +40 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +65 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/integrations.d.ts +356 -0
- package/dist/types/integrations.d.ts.map +1 -0
- package/dist/types/integrations.js +19 -0
- package/dist/types/integrations.js.map +1 -0
- package/dist/types/mdxui.d.ts +1955 -0
- package/dist/types/mdxui.d.ts.map +1 -0
- package/dist/types/mdxui.js +751 -0
- package/dist/types/mdxui.js.map +1 -0
- package/dist/types/observability.d.ts +315 -0
- package/dist/types/observability.d.ts.map +1 -0
- package/dist/types/observability.js +13 -0
- package/dist/types/observability.js.map +1 -0
- package/dist/types/rpc.d.ts +339 -0
- package/dist/types/rpc.d.ts.map +1 -0
- package/dist/types/rpc.js +24 -0
- package/dist/types/rpc.js.map +1 -0
- package/dist/types/saas.d.ts +678 -0
- package/dist/types/saas.d.ts.map +1 -0
- package/dist/types/saas.js +59 -0
- package/dist/types/saas.js.map +1 -0
- package/dist/types/service.d.ts +676 -0
- package/dist/types/service.d.ts.map +1 -0
- package/dist/types/service.js +69 -0
- package/dist/types/service.js.map +1 -0
- package/dist/types/site.d.ts +317 -0
- package/dist/types/site.d.ts.map +1 -0
- package/dist/types/site.js +203 -0
- package/dist/types/site.js.map +1 -0
- package/dist/types/startup.d.ts +576 -0
- package/dist/types/startup.d.ts.map +1 -0
- package/dist/types/startup.js +59 -0
- package/dist/types/startup.js.map +1 -0
- package/dist/types/storage.d.ts +276 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/storage.js +35 -0
- package/dist/types/storage.js.map +1 -0
- package/dist/types/telephony.d.ts +458 -0
- package/dist/types/telephony.d.ts.map +1 -0
- package/dist/types/telephony.js +19 -0
- package/dist/types/telephony.js.map +1 -0
- package/dist/types/tenant.d.ts +708 -0
- package/dist/types/tenant.d.ts.map +1 -0
- package/dist/types/tenant.js +103 -0
- package/dist/types/tenant.js.map +1 -0
- package/dist/types/voice-ai.d.ts +459 -0
- package/dist/types/voice-ai.d.ts.map +1 -0
- package/dist/types/voice-ai.js +32 -0
- package/dist/types/voice-ai.js.map +1 -0
- package/package.json +143 -0
|
@@ -0,0 +1,815 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relationships Collection - Graph-style entity linking for Digital Objects
|
|
3
|
+
*
|
|
4
|
+
* @module collections/relationships
|
|
5
|
+
*
|
|
6
|
+
* @description
|
|
7
|
+
* Manages graph-style relationships between Things within a Digital Object.
|
|
8
|
+
* Integrates with the cascade operators for post-generation linking and
|
|
9
|
+
* the RelationManager for unified relation storage.
|
|
10
|
+
*
|
|
11
|
+
* Cascade Operators:
|
|
12
|
+
* | Operator | Type | Action |
|
|
13
|
+
* |----------|------------------|-------------------------------------------|
|
|
14
|
+
* | `->` | Forward Insert | Create entity, link TO it |
|
|
15
|
+
* | `~>` | Forward Search | Vector search existing, link TO it |
|
|
16
|
+
* | `<-` | Backward Insert | Create entity, link FROM it (it owns us) |
|
|
17
|
+
* | `<~` | Backward Search | Vector search existing, link FROM it |
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const relationships = new RelationshipCollection(storage)
|
|
22
|
+
*
|
|
23
|
+
* // Create a simple relationship
|
|
24
|
+
* await relationships.create({
|
|
25
|
+
* from: 'customer_123',
|
|
26
|
+
* to: 'company_456',
|
|
27
|
+
* type: 'belongsTo'
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* // Use cascade operators
|
|
31
|
+
* await relationships.createWithOperator('customer_123', '~>Company', companyData)
|
|
32
|
+
*
|
|
33
|
+
* // Traverse relationships
|
|
34
|
+
* const related = await relationships.traverse('customer_123', 'belongsTo', 2)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
import { BaseCollection, NotFoundError, ValidationError } from './base';
|
|
38
|
+
/**
|
|
39
|
+
* Relationships collection for graph-style entity linking
|
|
40
|
+
*
|
|
41
|
+
* @description
|
|
42
|
+
* The RelationshipCollection provides graph-style relationship management
|
|
43
|
+
* between Things in a DO. It integrates with:
|
|
44
|
+
*
|
|
45
|
+
* - Cascade operators for schema-driven linking
|
|
46
|
+
* - RelationManager for unified storage
|
|
47
|
+
* - Things collection for entity resolution
|
|
48
|
+
*
|
|
49
|
+
* Key features:
|
|
50
|
+
* - Bidirectional relationships with automatic inverse creation
|
|
51
|
+
* - Cascade operator support (-> ~> <- <~)
|
|
52
|
+
* - Graph traversal with depth limiting
|
|
53
|
+
* - Relationship metadata storage
|
|
54
|
+
* - Ordered relationships (via ordinal)
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const relationships = new RelationshipCollection(storage)
|
|
59
|
+
*
|
|
60
|
+
* // Create relationships
|
|
61
|
+
* await relationships.create({
|
|
62
|
+
* from: 'order_123',
|
|
63
|
+
* to: 'customer_456',
|
|
64
|
+
* type: 'orderedBy'
|
|
65
|
+
* })
|
|
66
|
+
*
|
|
67
|
+
* // Query relationships
|
|
68
|
+
* const customerOrders = await relationships.findTo('customer_456', 'orderedBy')
|
|
69
|
+
*
|
|
70
|
+
* // Traverse graph
|
|
71
|
+
* const network = await relationships.traverse('customer_456', null, 2)
|
|
72
|
+
*
|
|
73
|
+
* // Process cascade schema
|
|
74
|
+
* const result = await relationships.processCascade(
|
|
75
|
+
* 'Customer',
|
|
76
|
+
* 'cust_123',
|
|
77
|
+
* generatedData,
|
|
78
|
+
* CustomerSchema
|
|
79
|
+
* )
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export class RelationshipCollection extends BaseCollection {
|
|
83
|
+
/**
|
|
84
|
+
* Create a new RelationshipCollection instance
|
|
85
|
+
*
|
|
86
|
+
* @param storage - DO storage interface
|
|
87
|
+
*/
|
|
88
|
+
constructor(storage) {
|
|
89
|
+
super(storage, {
|
|
90
|
+
name: 'relationships',
|
|
91
|
+
idPrefix: 'rel',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Initialize the relationships table in SQLite
|
|
96
|
+
*
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
async initializeTable() {
|
|
100
|
+
// Using KV storage via BaseCollection, no SQL table needed
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a relationship
|
|
104
|
+
*
|
|
105
|
+
* @param data - Relationship creation options
|
|
106
|
+
* @returns Created relationship
|
|
107
|
+
*
|
|
108
|
+
* @throws {ValidationError} If relationship already exists
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const rel = await relationships.create({
|
|
113
|
+
* from: 'order_123',
|
|
114
|
+
* to: 'customer_456',
|
|
115
|
+
* type: 'belongsTo'
|
|
116
|
+
* })
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
async create(data) {
|
|
120
|
+
// Check for duplicate
|
|
121
|
+
const existing = await this.exists(data.from, data.to, data.type);
|
|
122
|
+
if (existing) {
|
|
123
|
+
throw new ValidationError(`Relationship from '${data.from}' to '${data.to}' of type '${data.type}' already exists.`);
|
|
124
|
+
}
|
|
125
|
+
const id = this.generateId();
|
|
126
|
+
const now = this.now();
|
|
127
|
+
const rel = {
|
|
128
|
+
id,
|
|
129
|
+
from: data.from,
|
|
130
|
+
to: data.to,
|
|
131
|
+
type: data.type,
|
|
132
|
+
data: data.data,
|
|
133
|
+
createdAt: now,
|
|
134
|
+
};
|
|
135
|
+
const key = `${this.config.name}:${id}`;
|
|
136
|
+
await this.storage.put(key, rel);
|
|
137
|
+
return rel;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Create a bidirectional relationship
|
|
141
|
+
*
|
|
142
|
+
* @param data - Relationship data
|
|
143
|
+
* @param inverseType - Type for the inverse relationship
|
|
144
|
+
* @returns Tuple of [forward, inverse] relationships
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const [parentRel, childRel] = await relationships.createBidirectional(
|
|
149
|
+
* { from: 'parent_1', to: 'child_2', type: 'hasChild' },
|
|
150
|
+
* 'hasParent'
|
|
151
|
+
* )
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
async createBidirectional(data, inverseType) {
|
|
155
|
+
const forward = await this.create(data);
|
|
156
|
+
const inverse = await this.create({
|
|
157
|
+
from: data.to,
|
|
158
|
+
to: data.from,
|
|
159
|
+
type: inverseType,
|
|
160
|
+
data: data.data,
|
|
161
|
+
});
|
|
162
|
+
return [forward, inverse];
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get all outgoing relationships from an entity
|
|
166
|
+
*
|
|
167
|
+
* @param entityId - Source entity ID
|
|
168
|
+
* @param type - Optional filter by relationship type
|
|
169
|
+
* @returns Array of relationships
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const orders = await relationships.findFrom('customer_123', 'hasOrder')
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
async findFrom(entityId, type) {
|
|
177
|
+
const prefix = `${this.config.name}:`;
|
|
178
|
+
const allItems = await this.storage.list({ prefix });
|
|
179
|
+
const results = [];
|
|
180
|
+
for (const item of allItems.values()) {
|
|
181
|
+
if (item.from === entityId && (!type || item.type === type)) {
|
|
182
|
+
results.push(item);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Sort by ordinal if present in data
|
|
186
|
+
results.sort((a, b) => (a.data?.ordinal ?? 0) - (b.data?.ordinal ?? 0));
|
|
187
|
+
return results;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get all incoming relationships to an entity
|
|
191
|
+
*
|
|
192
|
+
* @param entityId - Target entity ID
|
|
193
|
+
* @param type - Optional filter by relationship type
|
|
194
|
+
* @returns Array of relationships
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const owners = await relationships.findTo('order_123', 'belongsTo')
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
async findTo(entityId, type) {
|
|
202
|
+
const prefix = `${this.config.name}:`;
|
|
203
|
+
const allItems = await this.storage.list({ prefix });
|
|
204
|
+
const results = [];
|
|
205
|
+
for (const item of allItems.values()) {
|
|
206
|
+
if (item.to === entityId && (!type || item.type === type)) {
|
|
207
|
+
results.push(item);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return results;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get all relationships for an entity (both directions)
|
|
214
|
+
*
|
|
215
|
+
* @param entityId - Entity ID
|
|
216
|
+
* @param options - Query options
|
|
217
|
+
* @returns Array of relationships
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* const allRels = await relationships.findAll('entity_123')
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
async findAll(entityId, options) {
|
|
225
|
+
const prefix = `${this.config.name}:`;
|
|
226
|
+
const allItems = await this.storage.list({ prefix });
|
|
227
|
+
const results = [];
|
|
228
|
+
for (const item of allItems.values()) {
|
|
229
|
+
const matchesType = !options?.type || item.type === options.type;
|
|
230
|
+
if (!matchesType)
|
|
231
|
+
continue;
|
|
232
|
+
if (options?.direction === 'outgoing') {
|
|
233
|
+
if (item.from === entityId)
|
|
234
|
+
results.push(item);
|
|
235
|
+
}
|
|
236
|
+
else if (options?.direction === 'incoming') {
|
|
237
|
+
if (item.to === entityId)
|
|
238
|
+
results.push(item);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
if (item.from === entityId || item.to === entityId)
|
|
242
|
+
results.push(item);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return results;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Check if a relationship exists
|
|
249
|
+
*
|
|
250
|
+
* @param from - Source entity ID
|
|
251
|
+
* @param to - Target entity ID
|
|
252
|
+
* @param type - Relationship type
|
|
253
|
+
* @returns True if relationship exists
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* if (await relationships.exists('customer_123', 'company_456', 'belongsTo')) {
|
|
258
|
+
* // Already linked
|
|
259
|
+
* }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
async exists(from, to, type) {
|
|
263
|
+
const prefix = `${this.config.name}:`;
|
|
264
|
+
const allItems = await this.storage.list({ prefix });
|
|
265
|
+
for (const item of allItems.values()) {
|
|
266
|
+
if (item.from === from && item.to === to && item.type === type) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Delete a relationship by ID
|
|
274
|
+
*
|
|
275
|
+
* @param id - Relationship ID
|
|
276
|
+
*
|
|
277
|
+
* @throws {NotFoundError} If relationship not found
|
|
278
|
+
*/
|
|
279
|
+
async delete(id) {
|
|
280
|
+
const key = `${this.config.name}:${id}`;
|
|
281
|
+
const exists = await this.storage.get(key);
|
|
282
|
+
if (!exists) {
|
|
283
|
+
throw new NotFoundError('relationships', id);
|
|
284
|
+
}
|
|
285
|
+
await this.storage.delete(key);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Delete a specific relationship by from/to/type
|
|
289
|
+
*
|
|
290
|
+
* @param from - Source entity ID
|
|
291
|
+
* @param to - Target entity ID
|
|
292
|
+
* @param type - Relationship type
|
|
293
|
+
* @returns True if deleted, false if not found
|
|
294
|
+
*/
|
|
295
|
+
async deleteRelation(from, to, type) {
|
|
296
|
+
const prefix = `${this.config.name}:`;
|
|
297
|
+
const allItems = await this.storage.list({ prefix });
|
|
298
|
+
for (const [key, item] of allItems.entries()) {
|
|
299
|
+
if (item.from === from && item.to === to && item.type === type) {
|
|
300
|
+
await this.storage.delete(key);
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Delete all relationships for an entity
|
|
308
|
+
*
|
|
309
|
+
* @param entityId - Entity ID
|
|
310
|
+
* @returns Number of deleted relationships
|
|
311
|
+
*
|
|
312
|
+
* @description
|
|
313
|
+
* Deletes both incoming and outgoing relationships.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* const deleted = await relationships.deleteAll('entity_123')
|
|
318
|
+
* console.log(`Deleted ${deleted} relationships`)
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
async deleteAll(entityId) {
|
|
322
|
+
const prefix = `${this.config.name}:`;
|
|
323
|
+
const allItems = await this.storage.list({ prefix });
|
|
324
|
+
let deleted = 0;
|
|
325
|
+
for (const [key, item] of allItems.entries()) {
|
|
326
|
+
if (item.from === entityId || item.to === entityId) {
|
|
327
|
+
await this.storage.delete(key);
|
|
328
|
+
deleted++;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return deleted;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Update relationship data
|
|
335
|
+
*
|
|
336
|
+
* @param id - Relationship ID
|
|
337
|
+
* @param data - Data to merge
|
|
338
|
+
* @returns Updated relationship
|
|
339
|
+
*
|
|
340
|
+
* @throws {NotFoundError} If relationship not found
|
|
341
|
+
*/
|
|
342
|
+
async updateData(id, data) {
|
|
343
|
+
const key = `${this.config.name}:${id}`;
|
|
344
|
+
const existing = await this.storage.get(key);
|
|
345
|
+
if (!existing) {
|
|
346
|
+
throw new NotFoundError('relationships', id);
|
|
347
|
+
}
|
|
348
|
+
const updated = {
|
|
349
|
+
...existing,
|
|
350
|
+
data: { ...(existing.data ?? {}), ...data },
|
|
351
|
+
};
|
|
352
|
+
await this.storage.put(key, updated);
|
|
353
|
+
return updated;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Traverse the relationship graph
|
|
357
|
+
*
|
|
358
|
+
* @param startId - Starting entity ID
|
|
359
|
+
* @param type - Relationship type to follow (null for any)
|
|
360
|
+
* @param maxDepth - Maximum traversal depth
|
|
361
|
+
* @param direction - Direction to traverse
|
|
362
|
+
* @returns Array of traversal results
|
|
363
|
+
*
|
|
364
|
+
* @description
|
|
365
|
+
* Performs breadth-first traversal of the relationship graph.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* // Find all entities connected to customer within 2 hops
|
|
370
|
+
* const network = await relationships.traverse('customer_123', null, 2)
|
|
371
|
+
*
|
|
372
|
+
* // Find all children of an organization
|
|
373
|
+
* const children = await relationships.traverse('org_1', 'hasChild', 3, 'outgoing')
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
async traverse(startId, type, maxDepth = 1, direction = 'both') {
|
|
377
|
+
const visited = new Set([startId]);
|
|
378
|
+
const results = [];
|
|
379
|
+
const queue = [
|
|
380
|
+
{ id: startId, depth: 0, path: [startId] },
|
|
381
|
+
];
|
|
382
|
+
while (queue.length > 0) {
|
|
383
|
+
const current = queue.shift();
|
|
384
|
+
if (current.depth >= maxDepth)
|
|
385
|
+
continue;
|
|
386
|
+
// Get relationships for current node
|
|
387
|
+
const prefix = `${this.config.name}:`;
|
|
388
|
+
const allItems = await this.storage.list({ prefix });
|
|
389
|
+
for (const item of allItems.values()) {
|
|
390
|
+
if (type && item.type !== type)
|
|
391
|
+
continue;
|
|
392
|
+
let targetId = null;
|
|
393
|
+
if (direction === 'outgoing' || direction === 'both') {
|
|
394
|
+
if (item.from === current.id && !visited.has(item.to)) {
|
|
395
|
+
targetId = item.to;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (!targetId && (direction === 'incoming' || direction === 'both')) {
|
|
399
|
+
if (item.to === current.id && !visited.has(item.from)) {
|
|
400
|
+
targetId = item.from;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (targetId && !visited.has(targetId)) {
|
|
404
|
+
visited.add(targetId);
|
|
405
|
+
const newPath = [...current.path, targetId];
|
|
406
|
+
const result = {
|
|
407
|
+
id: targetId,
|
|
408
|
+
depth: current.depth + 1,
|
|
409
|
+
relationship: item,
|
|
410
|
+
path: newPath,
|
|
411
|
+
};
|
|
412
|
+
results.push(result);
|
|
413
|
+
queue.push({ id: targetId, depth: current.depth + 1, path: newPath });
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return results;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Find shortest path between two entities
|
|
421
|
+
*
|
|
422
|
+
* @param fromId - Source entity ID
|
|
423
|
+
* @param toId - Target entity ID
|
|
424
|
+
* @param maxDepth - Maximum search depth
|
|
425
|
+
* @returns Path of relationships or null if not connected
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* const path = await relationships.findPath('entity_a', 'entity_z', 5)
|
|
430
|
+
* if (path) {
|
|
431
|
+
* console.log(`Connected via ${path.length} relationships`)
|
|
432
|
+
* }
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
async findPath(fromId, toId, maxDepth = 5) {
|
|
436
|
+
const visited = new Set([fromId]);
|
|
437
|
+
const queue = [
|
|
438
|
+
{ id: fromId, depth: 0, path: [] },
|
|
439
|
+
];
|
|
440
|
+
while (queue.length > 0) {
|
|
441
|
+
const current = queue.shift();
|
|
442
|
+
if (current.depth >= maxDepth)
|
|
443
|
+
continue;
|
|
444
|
+
const prefix = `${this.config.name}:`;
|
|
445
|
+
const allItems = await this.storage.list({ prefix });
|
|
446
|
+
for (const item of allItems.values()) {
|
|
447
|
+
let targetId = null;
|
|
448
|
+
if (item.from === current.id && !visited.has(item.to)) {
|
|
449
|
+
targetId = item.to;
|
|
450
|
+
}
|
|
451
|
+
else if (item.to === current.id && !visited.has(item.from)) {
|
|
452
|
+
targetId = item.from;
|
|
453
|
+
}
|
|
454
|
+
if (targetId) {
|
|
455
|
+
const newPath = [...current.path, item];
|
|
456
|
+
if (targetId === toId) {
|
|
457
|
+
return newPath;
|
|
458
|
+
}
|
|
459
|
+
visited.add(targetId);
|
|
460
|
+
queue.push({ id: targetId, depth: current.depth + 1, path: newPath });
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Count relationships for an entity
|
|
468
|
+
*
|
|
469
|
+
* @param entityId - Entity ID
|
|
470
|
+
* @param direction - Direction to count
|
|
471
|
+
* @returns Relationship count
|
|
472
|
+
*/
|
|
473
|
+
async countFor(entityId, direction = 'both') {
|
|
474
|
+
const prefix = `${this.config.name}:`;
|
|
475
|
+
const allItems = await this.storage.list({ prefix });
|
|
476
|
+
let count = 0;
|
|
477
|
+
for (const item of allItems.values()) {
|
|
478
|
+
if (direction === 'outgoing' && item.from === entityId)
|
|
479
|
+
count++;
|
|
480
|
+
else if (direction === 'incoming' && item.to === entityId)
|
|
481
|
+
count++;
|
|
482
|
+
else if (direction === 'both' && (item.from === entityId || item.to === entityId))
|
|
483
|
+
count++;
|
|
484
|
+
}
|
|
485
|
+
return count;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Get relationship types used by an entity
|
|
489
|
+
*
|
|
490
|
+
* @param entityId - Entity ID
|
|
491
|
+
* @returns Array of unique relationship types
|
|
492
|
+
*/
|
|
493
|
+
async getTypesFor(entityId) {
|
|
494
|
+
const prefix = `${this.config.name}:`;
|
|
495
|
+
const allItems = await this.storage.list({ prefix });
|
|
496
|
+
const types = new Set();
|
|
497
|
+
for (const item of allItems.values()) {
|
|
498
|
+
if (item.from === entityId || item.to === entityId) {
|
|
499
|
+
types.add(item.type);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return Array.from(types);
|
|
503
|
+
}
|
|
504
|
+
// ===========================================================================
|
|
505
|
+
// Cascade Operator Support
|
|
506
|
+
// ===========================================================================
|
|
507
|
+
/**
|
|
508
|
+
* Create relationship using cascade operator
|
|
509
|
+
*
|
|
510
|
+
* @param sourceId - Source entity ID
|
|
511
|
+
* @param operator - Cascade operator (-> ~> <- <~)
|
|
512
|
+
* @param targetType - Target entity type
|
|
513
|
+
* @param targetId - Target entity ID
|
|
514
|
+
* @param relName - Relationship name (field name)
|
|
515
|
+
* @returns Created relationship
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```typescript
|
|
519
|
+
* // Forward insert: customer -> contact
|
|
520
|
+
* await relationships.createWithOperator('cust_1', '->', 'Contact', 'contact_2', 'contacts')
|
|
521
|
+
*
|
|
522
|
+
* // Backward search: industry <~ customer
|
|
523
|
+
* await relationships.createWithOperator('cust_1', '<~', 'Industry', 'ind_3', 'industry')
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
async createWithOperator(sourceId, operator, targetType, targetId, relName) {
|
|
527
|
+
const { direction, method } = this.parseOperator(operator);
|
|
528
|
+
const relType = method === 'insert'
|
|
529
|
+
? (direction === 'forward' ? 'forward' : 'backward')
|
|
530
|
+
: (direction === 'forward' ? 'fuzzyForward' : 'fuzzyBackward');
|
|
531
|
+
// For backward operators, swap from/to
|
|
532
|
+
const from = direction === 'forward' ? sourceId : targetId;
|
|
533
|
+
const to = direction === 'forward' ? targetId : sourceId;
|
|
534
|
+
return this.create({
|
|
535
|
+
from,
|
|
536
|
+
to,
|
|
537
|
+
type: relName,
|
|
538
|
+
data: {
|
|
539
|
+
relType,
|
|
540
|
+
targetType,
|
|
541
|
+
operator,
|
|
542
|
+
},
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Parse a cascade operator into direction and method
|
|
547
|
+
*
|
|
548
|
+
* @param op - Cascade operator
|
|
549
|
+
* @returns Parsed operator components
|
|
550
|
+
*
|
|
551
|
+
* @internal
|
|
552
|
+
*/
|
|
553
|
+
parseOperator(op) {
|
|
554
|
+
switch (op) {
|
|
555
|
+
case '->': return { direction: 'forward', method: 'insert' };
|
|
556
|
+
case '~>': return { direction: 'forward', method: 'search' };
|
|
557
|
+
case '<-': return { direction: 'backward', method: 'insert' };
|
|
558
|
+
case '<~': return { direction: 'backward', method: 'search' };
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Process cascade relationships for a generated entity
|
|
563
|
+
*
|
|
564
|
+
* @param sourceType - Source entity type
|
|
565
|
+
* @param sourceId - Source entity ID
|
|
566
|
+
* @param generatedData - AI-generated data
|
|
567
|
+
* @param schema - Schema with cascade operators
|
|
568
|
+
* @returns Processing results
|
|
569
|
+
*
|
|
570
|
+
* @description
|
|
571
|
+
* Processes all fields in the schema that have cascade operators:
|
|
572
|
+
* - `->`: Creates new entity and links TO it
|
|
573
|
+
* - `~>`: Searches for entity and links TO it
|
|
574
|
+
* - `<-`: Creates new entity and links FROM it
|
|
575
|
+
* - `<~`: Searches for entity and links FROM it
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* const schema = {
|
|
580
|
+
* contacts: ['->Contact'], // Create contacts
|
|
581
|
+
* company: '~>Company', // Search for company
|
|
582
|
+
* owner: '<-SalesRep', // SalesRep owns this
|
|
583
|
+
* }
|
|
584
|
+
*
|
|
585
|
+
* const result = await relationships.processCascade(
|
|
586
|
+
* 'Customer',
|
|
587
|
+
* 'cust_123',
|
|
588
|
+
* generatedData,
|
|
589
|
+
* schema
|
|
590
|
+
* )
|
|
591
|
+
*
|
|
592
|
+
* console.log(result.created) // Entities created
|
|
593
|
+
* console.log(result.relations) // Relations created
|
|
594
|
+
* console.log(result.errors) // Any errors
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
async processCascade(sourceType, sourceId, generatedData, schema) {
|
|
598
|
+
const result = {
|
|
599
|
+
created: [],
|
|
600
|
+
relations: [],
|
|
601
|
+
errors: [],
|
|
602
|
+
};
|
|
603
|
+
for (const [fieldName, fieldSchema] of Object.entries(schema)) {
|
|
604
|
+
const fieldStr = Array.isArray(fieldSchema) ? fieldSchema[0] : fieldSchema;
|
|
605
|
+
// Parse operator from field schema string
|
|
606
|
+
const opMatch = fieldStr.match(/(->|~>|<-|<~)([A-Z][a-zA-Z0-9]*)/);
|
|
607
|
+
if (!opMatch)
|
|
608
|
+
continue;
|
|
609
|
+
const operator = opMatch[1];
|
|
610
|
+
const targetType = opMatch[2];
|
|
611
|
+
const fieldValue = generatedData[fieldName];
|
|
612
|
+
if (fieldValue === undefined || fieldValue === null) {
|
|
613
|
+
result.errors.push({
|
|
614
|
+
field: fieldName,
|
|
615
|
+
message: `No value for field '${fieldName}'`,
|
|
616
|
+
targetType,
|
|
617
|
+
code: 'NotFound',
|
|
618
|
+
});
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
const { direction, method } = this.parseOperator(operator);
|
|
622
|
+
if (method === 'search') {
|
|
623
|
+
// For search operators, we cannot actually do vector search here
|
|
624
|
+
// Record an error indicating the search target was not found
|
|
625
|
+
result.errors.push({
|
|
626
|
+
field: fieldName,
|
|
627
|
+
message: `Vector search not available for '${fieldName}' targeting '${targetType}'`,
|
|
628
|
+
targetType,
|
|
629
|
+
code: 'NotFound',
|
|
630
|
+
});
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
// For insert operators, create the entity and link
|
|
634
|
+
const items = Array.isArray(fieldValue) ? fieldValue : [fieldValue];
|
|
635
|
+
for (const item of items) {
|
|
636
|
+
const entityId = this.generateId();
|
|
637
|
+
result.created.push({ type: targetType, id: entityId, data: item });
|
|
638
|
+
try {
|
|
639
|
+
const from = direction === 'forward' ? sourceId : entityId;
|
|
640
|
+
const to = direction === 'forward' ? entityId : sourceId;
|
|
641
|
+
const rel = await this.create({
|
|
642
|
+
from,
|
|
643
|
+
to,
|
|
644
|
+
type: fieldName,
|
|
645
|
+
data: { relType: direction === 'forward' ? 'forward' : 'backward', targetType, operator },
|
|
646
|
+
});
|
|
647
|
+
result.relations.push(this.toStoredRelation(rel, {
|
|
648
|
+
relType: direction === 'forward' ? 'Forward' : 'Backward',
|
|
649
|
+
relName: fieldName,
|
|
650
|
+
fromCollection: direction === 'forward' ? sourceType : targetType,
|
|
651
|
+
toCollection: direction === 'forward' ? targetType : sourceType,
|
|
652
|
+
}));
|
|
653
|
+
}
|
|
654
|
+
catch (err) {
|
|
655
|
+
result.errors.push({
|
|
656
|
+
field: fieldName,
|
|
657
|
+
message: err instanceof Error ? err.message : String(err),
|
|
658
|
+
targetType,
|
|
659
|
+
code: 'Failed',
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return result;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Process a single cascade field
|
|
668
|
+
*
|
|
669
|
+
* @param sourceType - Source entity type
|
|
670
|
+
* @param sourceId - Source entity ID
|
|
671
|
+
* @param fieldName - Field name
|
|
672
|
+
* @param fieldValue - Generated value for field
|
|
673
|
+
* @param fieldDef - Parsed field definition
|
|
674
|
+
* @returns Field processing result
|
|
675
|
+
*
|
|
676
|
+
* @internal
|
|
677
|
+
*/
|
|
678
|
+
async processCascadeField(sourceType, sourceId, fieldName, fieldValue, fieldDef) {
|
|
679
|
+
const { direction, method } = this.parseOperator(fieldDef.operator);
|
|
680
|
+
const targetType = fieldDef.targets[0];
|
|
681
|
+
if (method === 'search') {
|
|
682
|
+
// Vector search not available - return error
|
|
683
|
+
return {
|
|
684
|
+
error: {
|
|
685
|
+
field: fieldName,
|
|
686
|
+
message: `Vector search not available for '${fieldName}'`,
|
|
687
|
+
targetType,
|
|
688
|
+
code: 'NotFound',
|
|
689
|
+
},
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
// Insert: create entity and link
|
|
693
|
+
const entityId = this.generateId();
|
|
694
|
+
const from = direction === 'forward' ? sourceId : entityId;
|
|
695
|
+
const to = direction === 'forward' ? entityId : sourceId;
|
|
696
|
+
try {
|
|
697
|
+
const rel = await this.create({
|
|
698
|
+
from,
|
|
699
|
+
to,
|
|
700
|
+
type: fieldName,
|
|
701
|
+
data: { relType: direction === 'forward' ? 'forward' : 'backward', targetType },
|
|
702
|
+
});
|
|
703
|
+
const storedRel = this.toStoredRelation(rel, {
|
|
704
|
+
relType: direction === 'forward' ? 'Forward' : 'Backward',
|
|
705
|
+
relName: fieldName,
|
|
706
|
+
fromCollection: direction === 'forward' ? sourceType : targetType,
|
|
707
|
+
toCollection: direction === 'forward' ? targetType : sourceType,
|
|
708
|
+
});
|
|
709
|
+
return {
|
|
710
|
+
created: { type: targetType, id: entityId, data: fieldValue },
|
|
711
|
+
relation: storedRel,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
catch (err) {
|
|
715
|
+
return {
|
|
716
|
+
error: {
|
|
717
|
+
field: fieldName,
|
|
718
|
+
message: err instanceof Error ? err.message : String(err),
|
|
719
|
+
targetType,
|
|
720
|
+
code: 'Failed',
|
|
721
|
+
},
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
// ===========================================================================
|
|
726
|
+
// RelationManager Interface Implementation
|
|
727
|
+
// ===========================================================================
|
|
728
|
+
/**
|
|
729
|
+
* Convert to StoredRelation format
|
|
730
|
+
*
|
|
731
|
+
* @param rel - Relationship
|
|
732
|
+
* @param options - Additional fields
|
|
733
|
+
* @returns StoredRelation
|
|
734
|
+
*
|
|
735
|
+
* @internal
|
|
736
|
+
*/
|
|
737
|
+
toStoredRelation(rel, options) {
|
|
738
|
+
return {
|
|
739
|
+
id: rel.id,
|
|
740
|
+
relType: options.relType,
|
|
741
|
+
relName: options.relName,
|
|
742
|
+
fromCollection: options.fromCollection ?? '',
|
|
743
|
+
fromId: rel.from,
|
|
744
|
+
toCollection: options.toCollection ?? '',
|
|
745
|
+
toId: rel.to,
|
|
746
|
+
label: options.label,
|
|
747
|
+
ordinal: options.ordinal ?? 0,
|
|
748
|
+
metadata: rel.data,
|
|
749
|
+
createdAt: rel.createdAt,
|
|
750
|
+
updatedAt: rel.createdAt,
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Get outgoing relations (RelationManager interface)
|
|
755
|
+
*
|
|
756
|
+
* @param collection - Source collection
|
|
757
|
+
* @param docId - Source document ID
|
|
758
|
+
* @param relName - Optional relation name filter
|
|
759
|
+
*/
|
|
760
|
+
async getOutgoing(collection, docId, relName) {
|
|
761
|
+
const rels = await this.findFrom(docId, relName);
|
|
762
|
+
return rels.map(rel => this.toStoredRelation(rel, {
|
|
763
|
+
relType: 'Forward',
|
|
764
|
+
relName: rel.type,
|
|
765
|
+
fromCollection: collection,
|
|
766
|
+
}));
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Get incoming relations (RelationManager interface)
|
|
770
|
+
*
|
|
771
|
+
* @param collection - Target collection
|
|
772
|
+
* @param docId - Target document ID
|
|
773
|
+
* @param relName - Optional relation name filter
|
|
774
|
+
*/
|
|
775
|
+
async getIncoming(collection, docId, relName) {
|
|
776
|
+
const rels = await this.findTo(docId, relName);
|
|
777
|
+
return rels.map(rel => this.toStoredRelation(rel, {
|
|
778
|
+
relType: 'Backward',
|
|
779
|
+
relName: rel.type,
|
|
780
|
+
toCollection: collection,
|
|
781
|
+
}));
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Update ordinal for a relationship (for reordering)
|
|
785
|
+
*
|
|
786
|
+
* @param id - Relationship ID
|
|
787
|
+
* @param ordinal - New ordinal value
|
|
788
|
+
* @returns Updated relationship
|
|
789
|
+
*/
|
|
790
|
+
async updateOrdinal(id, ordinal) {
|
|
791
|
+
return this.updateData(id, { ordinal });
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Reorder relationships for an entity
|
|
795
|
+
*
|
|
796
|
+
* @param entityId - Entity ID
|
|
797
|
+
* @param type - Relationship type
|
|
798
|
+
* @param orderedIds - Array of relationship IDs in new order
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* ```typescript
|
|
802
|
+
* // Reorder contacts for a customer
|
|
803
|
+
* await relationships.reorder('customer_123', 'hasContact', [
|
|
804
|
+
* 'rel_c', 'rel_a', 'rel_b' // New order
|
|
805
|
+
* ])
|
|
806
|
+
* ```
|
|
807
|
+
*/
|
|
808
|
+
async reorder(entityId, type, orderedIds) {
|
|
809
|
+
for (let i = 0; i < orderedIds.length; i++) {
|
|
810
|
+
await this.updateOrdinal(orderedIds[i], i);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
export default RelationshipCollection;
|
|
815
|
+
//# sourceMappingURL=relationships.js.map
|