@mantajs/core 0.1.6 → 0.2.0-beta.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/dist/adapters/auth-mock.d.ts +44 -0
- package/dist/adapters/auth-mock.d.ts.map +1 -0
- package/dist/adapters/auth-mock.js +160 -0
- package/dist/adapters/auth-mock.js.map +1 -0
- package/dist/adapters/cache-memory.d.ts +11 -0
- package/dist/adapters/cache-memory.d.ts.map +1 -0
- package/dist/adapters/cache-memory.js +32 -0
- package/dist/adapters/cache-memory.js.map +1 -0
- package/dist/adapters/database-memory.d.ts +24 -0
- package/dist/adapters/database-memory.d.ts.map +1 -0
- package/dist/adapters/database-memory.js +141 -0
- package/dist/adapters/database-memory.js.map +1 -0
- package/dist/adapters/eventbus-memory.d.ts +37 -0
- package/dist/adapters/eventbus-memory.d.ts.map +1 -0
- package/dist/adapters/eventbus-memory.js +166 -0
- package/dist/adapters/eventbus-memory.js.map +1 -0
- package/dist/adapters/file-memory.d.ts +24 -0
- package/dist/adapters/file-memory.d.ts.map +1 -0
- package/dist/adapters/file-memory.js +77 -0
- package/dist/adapters/file-memory.js.map +1 -0
- package/dist/adapters/http-memory.d.ts +23 -0
- package/dist/adapters/http-memory.d.ts.map +1 -0
- package/dist/adapters/http-memory.js +149 -0
- package/dist/adapters/http-memory.js.map +1 -0
- package/dist/adapters/index.d.ts +14 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +15 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/job-scheduler-memory.d.ts +20 -0
- package/dist/adapters/job-scheduler-memory.d.ts.map +1 -0
- package/dist/adapters/job-scheduler-memory.js +103 -0
- package/dist/adapters/job-scheduler-memory.js.map +1 -0
- package/dist/adapters/locking-memory.d.ts +20 -0
- package/dist/adapters/locking-memory.d.ts.map +1 -0
- package/dist/adapters/locking-memory.js +85 -0
- package/dist/adapters/locking-memory.js.map +1 -0
- package/dist/adapters/logger-test.d.ts +30 -0
- package/dist/adapters/logger-test.d.ts.map +1 -0
- package/dist/adapters/logger-test.js +77 -0
- package/dist/adapters/logger-test.js.map +1 -0
- package/dist/adapters/notification-memory.d.ts +27 -0
- package/dist/adapters/notification-memory.d.ts.map +1 -0
- package/dist/adapters/notification-memory.js +69 -0
- package/dist/adapters/notification-memory.js.map +1 -0
- package/dist/adapters/relational-query-memory.d.ts +47 -0
- package/dist/adapters/relational-query-memory.d.ts.map +1 -0
- package/dist/adapters/relational-query-memory.js +263 -0
- package/dist/adapters/relational-query-memory.js.map +1 -0
- package/dist/adapters/repository-factory-memory.d.ts +17 -0
- package/dist/adapters/repository-factory-memory.d.ts.map +1 -0
- package/dist/adapters/repository-factory-memory.js +32 -0
- package/dist/adapters/repository-factory-memory.js.map +1 -0
- package/dist/adapters/repository-memory.d.ts +30 -0
- package/dist/adapters/repository-memory.d.ts.map +1 -0
- package/dist/adapters/repository-memory.js +183 -0
- package/dist/adapters/repository-memory.js.map +1 -0
- package/dist/ai/index.d.ts +53 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +48 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/app/index.d.ts +97 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +217 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/request-context.d.ts +35 -0
- package/dist/app/request-context.d.ts.map +1 -0
- package/dist/app/request-context.js +32 -0
- package/dist/app/request-context.js.map +1 -0
- package/dist/auth/auth-module-service.d.ts +62 -0
- package/dist/auth/auth-module-service.d.ts.map +1 -0
- package/dist/auth/auth-module-service.js +210 -0
- package/dist/auth/auth-module-service.js.map +1 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/middleware.d.ts +19 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +61 -0
- package/dist/auth/middleware.js.map +1 -0
- package/dist/auth/models/auth-identity.d.ts +11 -0
- package/dist/auth/models/auth-identity.d.ts.map +1 -0
- package/dist/auth/models/auth-identity.js +12 -0
- package/dist/auth/models/auth-identity.js.map +1 -0
- package/dist/auth/providers/emailpass.d.ts +7 -0
- package/dist/auth/providers/emailpass.d.ts.map +1 -0
- package/dist/auth/providers/emailpass.js +94 -0
- package/dist/auth/providers/emailpass.js.map +1 -0
- package/dist/auth/providers/types.d.ts +66 -0
- package/dist/auth/providers/types.d.ts.map +1 -0
- package/dist/auth/providers/types.js +3 -0
- package/dist/auth/providers/types.js.map +1 -0
- package/dist/auth/types.d.ts +36 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +3 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/command/define-command-graph.d.ts +63 -0
- package/dist/command/define-command-graph.d.ts.map +1 -0
- package/dist/command/define-command-graph.js +80 -0
- package/dist/command/define-command-graph.js.map +1 -0
- package/dist/command/dml-to-zod.d.ts +34 -0
- package/dist/command/dml-to-zod.d.ts.map +1 -0
- package/dist/command/dml-to-zod.js +140 -0
- package/dist/command/dml-to-zod.js.map +1 -0
- package/dist/command/generate-entity-commands.d.ts +68 -0
- package/dist/command/generate-entity-commands.d.ts.map +1 -0
- package/dist/command/generate-entity-commands.js +350 -0
- package/dist/command/generate-entity-commands.js.map +1 -0
- package/dist/command/index.d.ts +54 -0
- package/dist/command/index.d.ts.map +1 -0
- package/dist/command/index.js +338 -0
- package/dist/command/index.js.map +1 -0
- package/dist/command/types.d.ts +131 -0
- package/dist/command/types.d.ts.map +1 -0
- package/dist/command/types.js +2 -0
- package/dist/command/types.js.map +1 -0
- package/dist/config/built-in-presets.d.ts +20 -0
- package/dist/config/built-in-presets.d.ts.map +1 -0
- package/dist/config/built-in-presets.js +70 -0
- package/dist/config/built-in-presets.js.map +1 -0
- package/dist/config/config-manager.d.ts +117 -0
- package/dist/config/config-manager.d.ts.map +1 -0
- package/dist/config/config-manager.js +245 -0
- package/dist/config/config-manager.js.map +1 -0
- package/dist/config/define-config.d.ts +20 -0
- package/dist/config/define-config.d.ts.map +1 -0
- package/dist/config/define-config.js +64 -0
- package/dist/config/define-config.js.map +1 -0
- package/dist/config/feature-flags.d.ts +48 -0
- package/dist/config/feature-flags.d.ts.map +1 -0
- package/dist/config/feature-flags.js +97 -0
- package/dist/config/feature-flags.js.map +1 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +8 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/presets.d.ts +38 -0
- package/dist/config/presets.d.ts.map +1 -0
- package/dist/config/presets.js +29 -0
- package/dist/config/presets.js.map +1 -0
- package/dist/config/types.d.ts +707 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +112 -0
- package/dist/config/types.js.map +1 -0
- package/dist/context/index.d.ts +95 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +26 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/registry.d.ts +32 -0
- package/dist/context/registry.d.ts.map +1 -0
- package/dist/context/registry.js +142 -0
- package/dist/context/registry.js.map +1 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +4 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema.d.ts +839 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +106 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/dml/entity.d.ts +132 -0
- package/dist/dml/entity.d.ts.map +1 -0
- package/dist/dml/entity.js +110 -0
- package/dist/dml/entity.js.map +1 -0
- package/dist/dml/from-zod.d.ts +13 -0
- package/dist/dml/from-zod.d.ts.map +1 -0
- package/dist/dml/from-zod.js +81 -0
- package/dist/dml/from-zod.js.map +1 -0
- package/dist/dml/generator/index.d.ts +62 -0
- package/dist/dml/generator/index.d.ts.map +1 -0
- package/dist/dml/generator/index.js +208 -0
- package/dist/dml/generator/index.js.map +1 -0
- package/dist/dml/index.d.ts +11 -0
- package/dist/dml/index.d.ts.map +1 -0
- package/dist/dml/index.js +13 -0
- package/dist/dml/index.js.map +1 -0
- package/dist/dml/infer.d.ts +36 -0
- package/dist/dml/infer.d.ts.map +1 -0
- package/dist/dml/infer.js +5 -0
- package/dist/dml/infer.js.map +1 -0
- package/dist/dml/model.d.ts +58 -0
- package/dist/dml/model.d.ts.map +1 -0
- package/dist/dml/model.js +95 -0
- package/dist/dml/model.js.map +1 -0
- package/dist/dml/modifiers.d.ts +9 -0
- package/dist/dml/modifiers.d.ts.map +1 -0
- package/dist/dml/modifiers.js +25 -0
- package/dist/dml/modifiers.js.map +1 -0
- package/dist/dml/properties/array.d.ts +7 -0
- package/dist/dml/properties/array.d.ts.map +1 -0
- package/dist/dml/properties/array.js +5 -0
- package/dist/dml/properties/array.js.map +1 -0
- package/dist/dml/properties/autoincrement.d.ts +7 -0
- package/dist/dml/properties/autoincrement.d.ts.map +1 -0
- package/dist/dml/properties/autoincrement.js +5 -0
- package/dist/dml/properties/autoincrement.js.map +1 -0
- package/dist/dml/properties/base.d.ts +124 -0
- package/dist/dml/properties/base.d.ts.map +1 -0
- package/dist/dml/properties/base.js +76 -0
- package/dist/dml/properties/base.js.map +1 -0
- package/dist/dml/properties/big-number.d.ts +7 -0
- package/dist/dml/properties/big-number.d.ts.map +1 -0
- package/dist/dml/properties/big-number.js +5 -0
- package/dist/dml/properties/big-number.js.map +1 -0
- package/dist/dml/properties/boolean.d.ts +7 -0
- package/dist/dml/properties/boolean.d.ts.map +1 -0
- package/dist/dml/properties/boolean.js +5 -0
- package/dist/dml/properties/boolean.js.map +1 -0
- package/dist/dml/properties/computed.d.ts +9 -0
- package/dist/dml/properties/computed.d.ts.map +1 -0
- package/dist/dml/properties/computed.js +22 -0
- package/dist/dml/properties/computed.js.map +1 -0
- package/dist/dml/properties/date-time.d.ts +7 -0
- package/dist/dml/properties/date-time.d.ts.map +1 -0
- package/dist/dml/properties/date-time.js +5 -0
- package/dist/dml/properties/date-time.js.map +1 -0
- package/dist/dml/properties/enum.d.ts +12 -0
- package/dist/dml/properties/enum.d.ts.map +1 -0
- package/dist/dml/properties/enum.js +14 -0
- package/dist/dml/properties/enum.js.map +1 -0
- package/dist/dml/properties/float.d.ts +7 -0
- package/dist/dml/properties/float.d.ts.map +1 -0
- package/dist/dml/properties/float.js +5 -0
- package/dist/dml/properties/float.js.map +1 -0
- package/dist/dml/properties/index.d.ts +15 -0
- package/dist/dml/properties/index.d.ts.map +1 -0
- package/dist/dml/properties/index.js +15 -0
- package/dist/dml/properties/index.js.map +1 -0
- package/dist/dml/properties/json.d.ts +7 -0
- package/dist/dml/properties/json.d.ts.map +1 -0
- package/dist/dml/properties/json.js +6 -0
- package/dist/dml/properties/json.js.map +1 -0
- package/dist/dml/properties/nullable.d.ts +23 -0
- package/dist/dml/properties/nullable.d.ts.map +1 -0
- package/dist/dml/properties/nullable.js +46 -0
- package/dist/dml/properties/nullable.js.map +1 -0
- package/dist/dml/properties/number.d.ts +10 -0
- package/dist/dml/properties/number.d.ts.map +1 -0
- package/dist/dml/properties/number.js +13 -0
- package/dist/dml/properties/number.js.map +1 -0
- package/dist/dml/properties/primary-key.d.ts +14 -0
- package/dist/dml/properties/primary-key.d.ts.map +1 -0
- package/dist/dml/properties/primary-key.js +23 -0
- package/dist/dml/properties/primary-key.js.map +1 -0
- package/dist/dml/properties/text.d.ts +15 -0
- package/dist/dml/properties/text.d.ts.map +1 -0
- package/dist/dml/properties/text.js +19 -0
- package/dist/dml/properties/text.js.map +1 -0
- package/dist/dml/relations/belongs-to.d.ts +20 -0
- package/dist/dml/relations/belongs-to.d.ts.map +1 -0
- package/dist/dml/relations/belongs-to.js +29 -0
- package/dist/dml/relations/belongs-to.js.map +1 -0
- package/dist/dml/relations/has-many.d.ts +16 -0
- package/dist/dml/relations/has-many.d.ts.map +1 -0
- package/dist/dml/relations/has-many.js +25 -0
- package/dist/dml/relations/has-many.js.map +1 -0
- package/dist/dml/relations/has-one.d.ts +26 -0
- package/dist/dml/relations/has-one.d.ts.map +1 -0
- package/dist/dml/relations/has-one.js +46 -0
- package/dist/dml/relations/has-one.js.map +1 -0
- package/dist/dml/relations/many-to-many.d.ts +9 -0
- package/dist/dml/relations/many-to-many.d.ts.map +1 -0
- package/dist/dml/relations/many-to-many.js +11 -0
- package/dist/dml/relations/many-to-many.js.map +1 -0
- package/dist/errors/manta-error.d.ts +68 -0
- package/dist/errors/manta-error.d.ts.map +1 -0
- package/dist/errors/manta-error.js +80 -0
- package/dist/errors/manta-error.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +3 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/message-aggregator.d.ts +25 -0
- package/dist/events/message-aggregator.d.ts.map +1 -0
- package/dist/events/message-aggregator.js +35 -0
- package/dist/events/message-aggregator.js.map +1 -0
- package/dist/events/types.d.ts +42 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +3 -0
- package/dist/events/types.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/job/index.d.ts +52 -0
- package/dist/job/index.d.ts.map +1 -0
- package/dist/job/index.js +31 -0
- package/dist/job/index.js.map +1 -0
- package/dist/link/index.d.ts +97 -0
- package/dist/link/index.d.ts.map +1 -0
- package/dist/link/index.js +185 -0
- package/dist/link/index.js.map +1 -0
- package/dist/middleware/define-middleware.d.ts +54 -0
- package/dist/middleware/define-middleware.d.ts.map +1 -0
- package/dist/middleware/define-middleware.js +40 -0
- package/dist/middleware/define-middleware.js.map +1 -0
- package/dist/middleware/index.d.ts +56 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +50 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/module/index.d.ts +56 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +52 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/versioning.d.ts +27 -0
- package/dist/module/versioning.d.ts.map +1 -0
- package/dist/module/versioning.js +64 -0
- package/dist/module/versioning.js.map +1 -0
- package/dist/naming.d.ts +39 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +95 -0
- package/dist/naming.js.map +1 -0
- package/dist/ports/analytics.d.ts +7 -0
- package/dist/ports/analytics.d.ts.map +1 -0
- package/dist/ports/analytics.js +3 -0
- package/dist/ports/analytics.js.map +1 -0
- package/dist/ports/auth.d.ts +27 -0
- package/dist/ports/auth.d.ts.map +1 -0
- package/dist/ports/auth.js +3 -0
- package/dist/ports/auth.js.map +1 -0
- package/dist/ports/cache.d.ts +35 -0
- package/dist/ports/cache.d.ts.map +1 -0
- package/dist/ports/cache.js +3 -0
- package/dist/ports/cache.js.map +1 -0
- package/dist/ports/database.d.ts +40 -0
- package/dist/ports/database.d.ts.map +1 -0
- package/dist/ports/database.js +3 -0
- package/dist/ports/database.js.map +1 -0
- package/dist/ports/event-bus.d.ts +85 -0
- package/dist/ports/event-bus.d.ts.map +1 -0
- package/dist/ports/event-bus.js +3 -0
- package/dist/ports/event-bus.js.map +1 -0
- package/dist/ports/file.d.ts +62 -0
- package/dist/ports/file.d.ts.map +1 -0
- package/dist/ports/file.js +3 -0
- package/dist/ports/file.js.map +1 -0
- package/dist/ports/http.d.ts +20 -0
- package/dist/ports/http.d.ts.map +1 -0
- package/dist/ports/http.js +3 -0
- package/dist/ports/http.js.map +1 -0
- package/dist/ports/in-memory-progress-channel.d.ts +9 -0
- package/dist/ports/in-memory-progress-channel.d.ts.map +1 -0
- package/dist/ports/in-memory-progress-channel.js +19 -0
- package/dist/ports/in-memory-progress-channel.js.map +1 -0
- package/dist/ports/in-memory-queue.d.ts +24 -0
- package/dist/ports/in-memory-queue.d.ts.map +1 -0
- package/dist/ports/in-memory-queue.js +63 -0
- package/dist/ports/in-memory-queue.js.map +1 -0
- package/dist/ports/index.d.ts +27 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/ports/index.js +6 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/ports/job-scheduler.d.ts +42 -0
- package/dist/ports/job-scheduler.d.ts.map +1 -0
- package/dist/ports/job-scheduler.js +3 -0
- package/dist/ports/job-scheduler.js.map +1 -0
- package/dist/ports/locking.d.ts +43 -0
- package/dist/ports/locking.d.ts.map +1 -0
- package/dist/ports/locking.js +3 -0
- package/dist/ports/locking.js.map +1 -0
- package/dist/ports/logger.d.ts +65 -0
- package/dist/ports/logger.d.ts.map +1 -0
- package/dist/ports/logger.js +3 -0
- package/dist/ports/logger.js.map +1 -0
- package/dist/ports/notification.d.ts +71 -0
- package/dist/ports/notification.d.ts.map +1 -0
- package/dist/ports/notification.js +3 -0
- package/dist/ports/notification.js.map +1 -0
- package/dist/ports/progress-channel.d.ts +46 -0
- package/dist/ports/progress-channel.d.ts.map +1 -0
- package/dist/ports/progress-channel.js +6 -0
- package/dist/ports/progress-channel.js.map +1 -0
- package/dist/ports/queue.d.ts +21 -0
- package/dist/ports/queue.d.ts.map +1 -0
- package/dist/ports/queue.js +15 -0
- package/dist/ports/queue.js.map +1 -0
- package/dist/ports/relational-query.d.ts +37 -0
- package/dist/ports/relational-query.d.ts.map +1 -0
- package/dist/ports/relational-query.js +3 -0
- package/dist/ports/relational-query.js.map +1 -0
- package/dist/ports/repository-factory.d.ts +21 -0
- package/dist/ports/repository-factory.d.ts.map +1 -0
- package/dist/ports/repository-factory.js +4 -0
- package/dist/ports/repository-factory.js.map +1 -0
- package/dist/ports/repository.d.ts +73 -0
- package/dist/ports/repository.d.ts.map +1 -0
- package/dist/ports/repository.js +3 -0
- package/dist/ports/repository.js.map +1 -0
- package/dist/ports/schema-generator.d.ts +15 -0
- package/dist/ports/schema-generator.d.ts.map +1 -0
- package/dist/ports/schema-generator.js +4 -0
- package/dist/ports/schema-generator.js.map +1 -0
- package/dist/ports/search.d.ts +7 -0
- package/dist/ports/search.d.ts.map +1 -0
- package/dist/ports/search.js +3 -0
- package/dist/ports/search.js.map +1 -0
- package/dist/ports/types.d.ts +112 -0
- package/dist/ports/types.d.ts.map +1 -0
- package/dist/ports/types.js +26 -0
- package/dist/ports/types.js.map +1 -0
- package/dist/ports/workflow-store.d.ts +111 -0
- package/dist/ports/workflow-store.d.ts.map +1 -0
- package/dist/ports/workflow-store.js +5 -0
- package/dist/ports/workflow-store.js.map +1 -0
- package/dist/query/define-query-graph.d.ts +55 -0
- package/dist/query/define-query-graph.d.ts.map +1 -0
- package/dist/query/define-query-graph.js +59 -0
- package/dist/query/define-query-graph.js.map +1 -0
- package/dist/query/define-query.d.ts +79 -0
- package/dist/query/define-query.d.ts.map +1 -0
- package/dist/query/define-query.js +77 -0
- package/dist/query/define-query.js.map +1 -0
- package/dist/query/extend-query-graph.d.ts +36 -0
- package/dist/query/extend-query-graph.d.ts.map +1 -0
- package/dist/query/extend-query-graph.js +34 -0
- package/dist/query/extend-query-graph.js.map +1 -0
- package/dist/query/index.d.ts +181 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +288 -0
- package/dist/query/index.js.map +1 -0
- package/dist/service/define.d.ts +97 -0
- package/dist/service/define.d.ts.map +1 -0
- package/dist/service/define.js +45 -0
- package/dist/service/define.js.map +1 -0
- package/dist/service/index.d.ts +52 -0
- package/dist/service/index.d.ts.map +1 -0
- package/dist/service/index.js +281 -0
- package/dist/service/index.js.map +1 -0
- package/dist/service/instantiate.d.ts +15 -0
- package/dist/service/instantiate.d.ts.map +1 -0
- package/dist/service/instantiate.js +143 -0
- package/dist/service/instantiate.js.map +1 -0
- package/dist/service/snapshot-repository.d.ts +31 -0
- package/dist/service/snapshot-repository.d.ts.map +1 -0
- package/dist/service/snapshot-repository.js +114 -0
- package/dist/service/snapshot-repository.js.map +1 -0
- package/dist/service/types.d.ts +39 -0
- package/dist/service/types.d.ts.map +1 -0
- package/dist/service/types.js +3 -0
- package/dist/service/types.js.map +1 -0
- package/dist/strict-mode/index.d.ts +42 -0
- package/dist/strict-mode/index.d.ts.map +1 -0
- package/dist/strict-mode/index.js +84 -0
- package/dist/strict-mode/index.js.map +1 -0
- package/dist/subscriber/index.d.ts +117 -0
- package/dist/subscriber/index.d.ts.map +1 -0
- package/dist/subscriber/index.js +76 -0
- package/dist/subscriber/index.js.map +1 -0
- package/dist/testing/relational-query-suite.d.ts +22 -0
- package/dist/testing/relational-query-suite.d.ts.map +1 -0
- package/dist/testing/relational-query-suite.js +233 -0
- package/dist/testing/relational-query-suite.js.map +1 -0
- package/dist/user/auto-routes.d.ts +32 -0
- package/dist/user/auto-routes.d.ts.map +1 -0
- package/dist/user/auto-routes.js +424 -0
- package/dist/user/auto-routes.js.map +1 -0
- package/dist/user/define-user.d.ts +54 -0
- package/dist/user/define-user.d.ts.map +1 -0
- package/dist/user/define-user.js +103 -0
- package/dist/user/define-user.js.map +1 -0
- package/dist/user/index.d.ts +7 -0
- package/dist/user/index.d.ts.map +1 -0
- package/dist/user/index.js +5 -0
- package/dist/user/index.js.map +1 -0
- package/dist/user/models/user.d.ts +15 -0
- package/dist/user/models/user.d.ts.map +1 -0
- package/dist/user/models/user.js +16 -0
- package/dist/user/models/user.js.map +1 -0
- package/dist/user/user-module-service.d.ts +55 -0
- package/dist/user/user-module-service.d.ts.map +1 -0
- package/dist/user/user-module-service.js +100 -0
- package/dist/user/user-module-service.js.map +1 -0
- package/dist/workflows/ai-step.d.ts +2 -0
- package/dist/workflows/ai-step.d.ts.map +1 -0
- package/dist/workflows/ai-step.js +54 -0
- package/dist/workflows/ai-step.js.map +1 -0
- package/dist/workflows/create-step.d.ts +16 -0
- package/dist/workflows/create-step.d.ts.map +1 -0
- package/dist/workflows/create-step.js +194 -0
- package/dist/workflows/create-step.js.map +1 -0
- package/dist/workflows/create-workflow.d.ts +16 -0
- package/dist/workflows/create-workflow.d.ts.map +1 -0
- package/dist/workflows/create-workflow.js +21 -0
- package/dist/workflows/create-workflow.js.map +1 -0
- package/dist/workflows/define-workflow.d.ts +55 -0
- package/dist/workflows/define-workflow.d.ts.map +1 -0
- package/dist/workflows/define-workflow.js +72 -0
- package/dist/workflows/define-workflow.js.map +1 -0
- package/dist/workflows/emit-event-step.d.ts +17 -0
- package/dist/workflows/emit-event-step.d.ts.map +1 -0
- package/dist/workflows/emit-event-step.js +46 -0
- package/dist/workflows/emit-event-step.js.map +1 -0
- package/dist/workflows/for-each.d.ts +6 -0
- package/dist/workflows/for-each.d.ts.map +1 -0
- package/dist/workflows/for-each.js +79 -0
- package/dist/workflows/for-each.js.map +1 -0
- package/dist/workflows/index.d.ts +15 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +12 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/manager.d.ts +99 -0
- package/dist/workflows/manager.d.ts.map +1 -0
- package/dist/workflows/manager.js +450 -0
- package/dist/workflows/manager.js.map +1 -0
- package/dist/workflows/orphan-reaper.d.ts +50 -0
- package/dist/workflows/orphan-reaper.d.ts.map +1 -0
- package/dist/workflows/orphan-reaper.js +69 -0
- package/dist/workflows/orphan-reaper.js.map +1 -0
- package/dist/workflows/progress-helper.d.ts +20 -0
- package/dist/workflows/progress-helper.d.ts.map +1 -0
- package/dist/workflows/progress-helper.js +48 -0
- package/dist/workflows/progress-helper.js.map +1 -0
- package/dist/workflows/step.d.ts +103 -0
- package/dist/workflows/step.d.ts.map +1 -0
- package/dist/workflows/step.js +949 -0
- package/dist/workflows/step.js.map +1 -0
- package/dist/workflows/types.d.ts +215 -0
- package/dist/workflows/types.d.ts.map +1 -0
- package/dist/workflows/types.js +9 -0
- package/dist/workflows/types.js.map +1 -0
- package/dist/workflows/yield.d.ts +12 -0
- package/dist/workflows/yield.d.ts.map +1 -0
- package/dist/workflows/yield.js +29 -0
- package/dist/workflows/yield.js.map +1 -0
- package/docs/00-overview.md +254 -0
- package/docs/01-getting-started.md +224 -0
- package/docs/02-models.md +163 -0
- package/docs/03-services.md +208 -0
- package/docs/04-users.md +165 -0
- package/docs/05-commands.md +501 -0
- package/docs/06-queries.md +342 -0
- package/docs/07-events.md +248 -0
- package/docs/08-links.md +182 -0
- package/docs/09-agents.md +142 -0
- package/docs/10-spa.md +327 -0
- package/docs/11-config.md +481 -0
- package/docs/12-constraints.md +183 -0
- package/docs/13-testing.md +345 -0
- package/docs/14-adapters.md +204 -0
- package/docs/15-hosts.md +163 -0
- package/docs/16-reference.md +274 -0
- package/docs/17-dashboard.md +619 -0
- package/docs/AGENT.md +501 -0
- package/package.json +49 -52
- package/.medusa/server/src/admin/index.js +0 -5358
- package/.medusa/server/src/admin/index.mjs +0 -5356
- package/.medusa/server/src/api/admin/companies/[id]/route.js +0 -39
- package/.medusa/server/src/api/admin/companies/middlewares.js +0 -41
- package/.medusa/server/src/api/admin/companies/route.js +0 -37
- package/.medusa/server/src/api/admin/companies/validators.js +0 -29
- package/.medusa/server/src/api/middlewares.js +0 -8
- package/.medusa/server/src/index.js +0 -5
- package/.medusa/server/src/modules/company/index.js +0 -13
- package/.medusa/server/src/modules/company/migrations/Migration20260126141741.js +0 -26
- package/.medusa/server/src/modules/company/models/company.js +0 -24
- package/.medusa/server/src/modules/company/models/employee.js +0 -15
- package/.medusa/server/src/modules/company/models/index.js +0 -11
- package/.medusa/server/src/modules/company/service.js +0 -11
- package/.medusa/server/src/workflows/create-company.js +0 -10
- package/.medusa/server/src/workflows/delete-company.js +0 -10
- package/.medusa/server/src/workflows/steps/create-company.js +0 -16
- package/.medusa/server/src/workflows/steps/delete-company.js +0 -30
- package/.medusa/server/src/workflows/steps/update-company.js +0 -30
- package/.medusa/server/src/workflows/update-company.js +0 -10
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
# Queries — defineQuery() & defineQueryGraph()
|
|
2
|
+
|
|
3
|
+
Queries are the CQRS read side. They expose data as GET endpoints. Two primitives:
|
|
4
|
+
|
|
5
|
+
- `defineQuery()` — named query with custom handler (specific reads)
|
|
6
|
+
- `defineQueryGraph()` — expose the query graph to frontend (flexible reads)
|
|
7
|
+
|
|
8
|
+
## defineQuery()
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
// src/queries/admin/list-products.ts
|
|
12
|
+
import { z } from 'zod'
|
|
13
|
+
|
|
14
|
+
export default defineQuery({
|
|
15
|
+
name: 'list-products',
|
|
16
|
+
description: 'List products with filtering',
|
|
17
|
+
input: z.object({
|
|
18
|
+
status: z.string().optional(),
|
|
19
|
+
...listParams(),
|
|
20
|
+
}),
|
|
21
|
+
handler: async (input, { query, log, auth, headers }) => {
|
|
22
|
+
return query.graph({
|
|
23
|
+
entity: 'product',
|
|
24
|
+
filters: input.status ? { status: input.status } : undefined,
|
|
25
|
+
pagination: { take: input.limit, skip: input.offset },
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Signature
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
defineQuery({
|
|
35
|
+
name: string, // Query name (becomes the endpoint)
|
|
36
|
+
description: string, // For docs and AI tool discovery
|
|
37
|
+
input: z.ZodType, // Zod schema for input validation
|
|
38
|
+
handler: (input, ctx) => Promise<output>,
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Handler context
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
{
|
|
46
|
+
query: QueryService, // query.graph() for cross-module joins
|
|
47
|
+
log: ILoggerPort, // Structured logging
|
|
48
|
+
auth: AuthContext | null, // Authenticated user
|
|
49
|
+
headers: Record<string, string | undefined>, // Raw request headers
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**No `app` access** — queries are forced to use `query.graph()` for reads. This ensures consistent access control.
|
|
54
|
+
|
|
55
|
+
### Routing
|
|
56
|
+
|
|
57
|
+
The folder name = the context:
|
|
58
|
+
```
|
|
59
|
+
src/queries/admin/list-products.ts → GET /api/admin/list-products
|
|
60
|
+
src/queries/store/get-catalog.ts → GET /api/store/get-catalog
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Query parameters are passed as URL query string:
|
|
64
|
+
```
|
|
65
|
+
GET /api/admin/list-products?status=active&limit=10&offset=0
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Input helpers
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { listParams, retrieveParams } from '@mantajs/sdk'
|
|
72
|
+
|
|
73
|
+
// listParams() adds: limit, offset, sort, order, search
|
|
74
|
+
z.object({
|
|
75
|
+
category: z.string().optional(),
|
|
76
|
+
...listParams(), // { limit: 20, offset: 0, sort?, order: 'desc', search? }
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// retrieveParams() adds: id, fields
|
|
80
|
+
z.object({
|
|
81
|
+
...retrieveParams(), // { id: string, fields?: string[] }
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Auth in queries
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
handler: async (input, { query, auth }) => {
|
|
89
|
+
// auth.id — user ID
|
|
90
|
+
// auth.type — context ('admin', 'customer')
|
|
91
|
+
// auth.email — user email
|
|
92
|
+
|
|
93
|
+
// Example: only return MY orders
|
|
94
|
+
return query.graph({
|
|
95
|
+
entity: 'order',
|
|
96
|
+
filters: { customer_id: auth!.id },
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## defineQueryGraph()
|
|
102
|
+
|
|
103
|
+
Exposes the query graph to the frontend. The frontend can compose arbitrary queries.
|
|
104
|
+
|
|
105
|
+
### Wildcard — full access (admin/AI)
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// src/queries/admin/graph.ts
|
|
109
|
+
export default defineQueryGraph('*')
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Creates `POST /api/admin/graph`. The frontend can query any entity with any filters, relations, pagination.
|
|
113
|
+
|
|
114
|
+
### Scoped — per-entity access with row-level filtering
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// src/queries/store/graph.ts
|
|
118
|
+
export default defineQueryGraph({
|
|
119
|
+
product: true, // all products, no filter
|
|
120
|
+
category: true, // all categories
|
|
121
|
+
order: (auth) => ({ customer_id: auth.id }), // only MY orders
|
|
122
|
+
customer: (auth) => ({ id: auth.id }), // only MY profile
|
|
123
|
+
})
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Creates `POST /api/store/graph` with access control:
|
|
127
|
+
|
|
128
|
+
| Entity | Access | Behavior |
|
|
129
|
+
|--------|--------|----------|
|
|
130
|
+
| Listed as `true` | All rows | No filter applied |
|
|
131
|
+
| Listed as function | Scoped rows | Function returns filters merged with user query |
|
|
132
|
+
| Not listed | Blocked | 403 Forbidden |
|
|
133
|
+
| Listed in `relations` but not allowed | Stripped | Warning logged in backend console |
|
|
134
|
+
|
|
135
|
+
### Frontend usage
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
// Using @mantajs/sdk
|
|
139
|
+
const { data } = useGraphQuery({
|
|
140
|
+
entity: 'product',
|
|
141
|
+
filters: { status: 'active' },
|
|
142
|
+
relations: ['inventory_item'],
|
|
143
|
+
pagination: { limit: 20 },
|
|
144
|
+
sort: { field: 'created_at', order: 'desc' },
|
|
145
|
+
})
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Graph query body
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
POST /api/admin/graph
|
|
152
|
+
{
|
|
153
|
+
"entity": "product",
|
|
154
|
+
"filters": { "status": "active" },
|
|
155
|
+
"pagination": { "limit": 20, "offset": 0 },
|
|
156
|
+
"sort": { "field": "created_at", "order": "desc" },
|
|
157
|
+
"relations": ["inventory_item", "category"],
|
|
158
|
+
"fields": ["id", "title", "price", "status"]
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### When to use defineQuery vs defineQueryGraph
|
|
163
|
+
|
|
164
|
+
| Use case | Primitive | Why |
|
|
165
|
+
|----------|-----------|-----|
|
|
166
|
+
| Admin dashboard | `defineQueryGraph('*')` | Admin sees everything, AI needs full access |
|
|
167
|
+
| Storefront public catalog | `defineQueryGraph({ product: true })` | Frontend composes queries freely, scoped |
|
|
168
|
+
| Storefront orders | `defineQuery` or scoped graph | Need row-level filtering by customer |
|
|
169
|
+
| Complex aggregation | `defineQuery` | Custom handler with business logic |
|
|
170
|
+
| API for third parties | `defineQuery` | Fixed contract, no graph exposure |
|
|
171
|
+
|
|
172
|
+
## extendQueryGraph() — external entity resolvers
|
|
173
|
+
|
|
174
|
+
`extendQueryGraph()` plugs a **module-level resolver** into the query engine. It's how modules that own [external entities](./02-models.md#external-entities) (PostHog, Stripe, etc.) translate a Manta query graph request into a call to the third-party backend.
|
|
175
|
+
|
|
176
|
+
Unlike `defineQueryGraph()` — which controls **access per context** — `extendQueryGraph()` adds **new resolution paths** to the engine itself. When any entity listed in `owns` is queried (via `query.graph()`, `useGraphQuery`, or an AI tool), the engine routes the query to your resolver instead of hitting the local database.
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
// src/modules/posthog/queries/graph.ts
|
|
180
|
+
export default extendQueryGraph({
|
|
181
|
+
owns: ['PostHogEvent', 'PostHogPerson', 'PostHogInsight'],
|
|
182
|
+
|
|
183
|
+
async resolve(query, { app, logger }) {
|
|
184
|
+
// `query` is the Manta GraphQueryConfig: entity, filters, pagination, sort, fields...
|
|
185
|
+
// Translate it into a HogQL / REST call against PostHog, then return normalized rows.
|
|
186
|
+
const rows = await fetchFromPostHog(query)
|
|
187
|
+
return rows
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
// Optional: whitelist the filters your backend can honour. Unsupported filters
|
|
191
|
+
// will throw a clear error so the caller (or AI) can adapt its query.
|
|
192
|
+
supportedFilters: {
|
|
193
|
+
PostHogEvent: ['distinct_id', 'event', 'timestamp'],
|
|
194
|
+
PostHogPerson: ['id', 'email'],
|
|
195
|
+
},
|
|
196
|
+
})
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Signature
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
extendQueryGraph({
|
|
203
|
+
owns: string[], // Entity names this module resolves
|
|
204
|
+
resolve: (query, ctx) => Promise<Row[]>,
|
|
205
|
+
supportedFilters?: Record<string, string[]>,
|
|
206
|
+
})
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Resolver context
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
{
|
|
213
|
+
app: MantaApp, // Resolve plugin config, secrets, infra
|
|
214
|
+
logger: ILoggerPort, // Structured logging
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Rules
|
|
219
|
+
|
|
220
|
+
- File location: `src/modules/{module}/queries/graph.ts` (module-scoped — NOT in `src/queries/`).
|
|
221
|
+
- `owns` must be non-empty and list entities declared with `.external()` in the same module.
|
|
222
|
+
- `resolve` must return normalized rows whose shape matches the entity's `defineModel()` schema (keys == field names). The engine then applies relation hydration + access control as usual.
|
|
223
|
+
- Omit `supportedFilters` to accept everything (use at your own risk — the resolver is fully on the hook for validation).
|
|
224
|
+
- Local entities are still resolved by the database; only entities listed in `owns` are routed to the extension.
|
|
225
|
+
|
|
226
|
+
### Relationship with defineLink
|
|
227
|
+
|
|
228
|
+
External entities linked to local ones via `defineLink()` are hydrated transparently: when a query requests `{ entity: 'product', relations: ['posthog_event'] }`, the engine first hits Drizzle for products, then calls the PostHog extension's `resolve()` with the event query — both halves merge in the final result.
|
|
229
|
+
|
|
230
|
+
## Relation field syntax in query.graph()
|
|
231
|
+
|
|
232
|
+
The `fields` parameter in `query.graph()` supports a dot notation to eagerly load related entities:
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
// Load all product fields + all linked inventory items
|
|
236
|
+
return query.graph({
|
|
237
|
+
entity: 'product',
|
|
238
|
+
fields: ['*', 'inventory_items.*'],
|
|
239
|
+
})
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### How it works
|
|
243
|
+
|
|
244
|
+
- `'*'` — all columns of the root entity
|
|
245
|
+
- `'relation.*'` — eagerly load all columns of the linked entity (uses the relation alias from `defineLink`)
|
|
246
|
+
|
|
247
|
+
### M:N links
|
|
248
|
+
|
|
249
|
+
For many-to-many links, the relation field syntax loads through the pivot table and flattens results:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
// Load customers with their addresses
|
|
253
|
+
return query.graph({
|
|
254
|
+
entity: 'customer',
|
|
255
|
+
fields: ['*', 'addresses.*'],
|
|
256
|
+
})
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
If the link has extra columns (e.g., `type`, `is_default`), those pivot columns are merged into each target entity:
|
|
260
|
+
|
|
261
|
+
```json
|
|
262
|
+
{
|
|
263
|
+
"id": "cust_123",
|
|
264
|
+
"name": "Alice",
|
|
265
|
+
"addresses": [
|
|
266
|
+
{ "id": "addr_1", "street": "123 Main", "type": "shipping", "is_default": true },
|
|
267
|
+
{ "id": "addr_2", "street": "456 Oak", "type": "billing", "is_default": false }
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Relation pagination with relPagination
|
|
273
|
+
|
|
274
|
+
Use `relPagination` to paginate relation results independently from the root entity:
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
return query.graph({
|
|
278
|
+
entity: 'customer',
|
|
279
|
+
fields: ['*', 'orders.*'],
|
|
280
|
+
relPagination: {
|
|
281
|
+
orders: { take: 5, skip: 0 },
|
|
282
|
+
},
|
|
283
|
+
})
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
This limits the eagerly loaded `orders` to 5 per customer, without affecting the root pagination.
|
|
287
|
+
|
|
288
|
+
### Pagination limits and large result sets
|
|
289
|
+
|
|
290
|
+
`pagination.limit` defaults to **100** when unspecified. There is **no hard cap** — callers may request any limit — but the Drizzle relational query adapter will log a warning when `limit > 10000` for a single page, since paginating by offset across large result sets is inefficient.
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
// OK: small page
|
|
294
|
+
query.graph({ entity: 'order', pagination: { limit: 100, offset: 200 } })
|
|
295
|
+
|
|
296
|
+
// Warning logged: "DrizzleRelationalQuery: limit=15000 exceeds recommended
|
|
297
|
+
// maximum (10000) for entity 'order'. Consider cursor pagination."
|
|
298
|
+
query.graph({ entity: 'order', pagination: { limit: 15000 } })
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
**Why the warning exists**: offset pagination scans all preceding rows on every page, so cost grows linearly with `offset`. For result sets > 10k, switch to keyset (cursor) pagination:
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
// Keyset: filter by the last seen id, constant time per page
|
|
305
|
+
query.graph({
|
|
306
|
+
entity: 'order',
|
|
307
|
+
filters: lastId ? { id: { $gt: lastId } } : undefined,
|
|
308
|
+
sort: { id: 'asc' },
|
|
309
|
+
pagination: { limit: 100 },
|
|
310
|
+
})
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
**Counting large result sets**: `graphAndCount()` computes the exact count by default. For very large tables (> 100k rows), an exact count can be as expensive as the main query. A `countMode: 'exact' | 'capped' | 'estimated'` option is planned — see BACKLOG BC-F30 for the decision rationale. Until then, prefer `graph()` + infinite scrolling over `graphAndCount()` + paginated UIs on large tables.
|
|
314
|
+
|
|
315
|
+
## Typed returns with generics
|
|
316
|
+
|
|
317
|
+
`query.graph()` and `query.graphAndCount()` accept an entity type parameter for end-to-end type safety:
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
// When codegen has run, the entity name is narrowed and the return type is inferred
|
|
321
|
+
const products = await query.graph({ entity: 'product' })
|
|
322
|
+
// => InferEntityResult<'product'>[] — fully typed with DML fields
|
|
323
|
+
|
|
324
|
+
const [orders, count] = await query.graphAndCount({ entity: 'order' })
|
|
325
|
+
// => [InferEntityResult<'order'>[], number]
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### How it works
|
|
329
|
+
|
|
330
|
+
- **`EntityName`** — when codegen has populated `EntityRegistry`, this is a union of known entity names (e.g. `'product' | 'order'`). Without codegen, falls back to `string`.
|
|
331
|
+
- **`InferEntityResult<E>`** — resolves to the DML-inferred shape when `E` is a known registry key, otherwise `Record<string, unknown>`.
|
|
332
|
+
- **`GraphQueryConfig<E>`** — the `entity` field is typed as `E`, giving autocomplete on entity names.
|
|
333
|
+
|
|
334
|
+
This means `as any[]` casts on query results are no longer needed. The type flows from `defineModel` through codegen into query results.
|
|
335
|
+
|
|
336
|
+
### Without codegen (development / tests)
|
|
337
|
+
|
|
338
|
+
If `EntityRegistry` is empty (no codegen), everything still works — `EntityName` is `string` and results are `Record<string, unknown>`. No breaking change.
|
|
339
|
+
|
|
340
|
+
## No defineQueryGraph = no useGraphQuery
|
|
341
|
+
|
|
342
|
+
If you don't create a `graph.ts` in a context, `useGraphQuery()` from the SDK will receive a 404. The query graph must be explicitly enabled per context.
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# Events & Workflows — defineSubscriber(), defineJob() & defineWorkflow()
|
|
2
|
+
|
|
3
|
+
## Events in Manta
|
|
4
|
+
|
|
5
|
+
Events are the communication layer between modules. They decouple the "what happened" (command) from the "what should happen next" (subscriber).
|
|
6
|
+
|
|
7
|
+
### Auto-generated events
|
|
8
|
+
|
|
9
|
+
Every CRUD operation emits events automatically:
|
|
10
|
+
|
|
11
|
+
| Operation | Event name | Data |
|
|
12
|
+
|-----------|-----------|------|
|
|
13
|
+
| `createProducts(data)` | `product.created` | `{ id }` |
|
|
14
|
+
| `updateProducts(data)` | `product.updated` | `{ id }` |
|
|
15
|
+
| `deleteProducts(ids)` | `product.deleted` | `{ id }` |
|
|
16
|
+
|
|
17
|
+
The event name is derived from the entity name: `Product` → `product.created`.
|
|
18
|
+
|
|
19
|
+
### Manual events
|
|
20
|
+
|
|
21
|
+
In commands: `step.emit('event.name', data)` — buffered until workflow commits.
|
|
22
|
+
|
|
23
|
+
## defineSubscriber()
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
export default defineSubscriber({
|
|
27
|
+
event: 'product.created',
|
|
28
|
+
handler: async (event, { command, log }) => {
|
|
29
|
+
const { id, sku } = event.data as { id: string; sku: string }
|
|
30
|
+
log.info(`Product created: ${sku}`)
|
|
31
|
+
await command.initializeInventory({ productId: id })
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Signature:**
|
|
37
|
+
- `event` — Event name (string) or array of event names
|
|
38
|
+
- `handler` — `async (event, { command, log }) => void`
|
|
39
|
+
- `event` — `Message<T>` with `eventName`, `data`, `metadata`
|
|
40
|
+
- `command` — CQRS command callables (with autocomplete from codegen)
|
|
41
|
+
- `log` — Logger instance
|
|
42
|
+
|
|
43
|
+
### Typed event data
|
|
44
|
+
|
|
45
|
+
Use the generic parameter to type `event.data`:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
interface ProductCreatedEvent {
|
|
49
|
+
id: string
|
|
50
|
+
sku: string
|
|
51
|
+
title: string
|
|
52
|
+
price: number
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default defineSubscriber<ProductCreatedEvent>({
|
|
56
|
+
event: 'product.created',
|
|
57
|
+
handler: async (event, { command, log }) => {
|
|
58
|
+
event.data.sku // TS knows this is string
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Multiple events
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
export default defineSubscriber({
|
|
67
|
+
event: ['product.created', 'product.updated'],
|
|
68
|
+
handler: async (event, { log }) => {
|
|
69
|
+
log.info(`Product changed: ${event.eventName}`)
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Idempotency (at-least-once)
|
|
75
|
+
|
|
76
|
+
Events can be delivered more than once (at-least-once guarantee). Use `makeIdempotent()` to deduplicate:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
export default defineSubscriber({
|
|
80
|
+
event: 'order.created',
|
|
81
|
+
handler: makeIdempotent(
|
|
82
|
+
cache, // ICachePort instance
|
|
83
|
+
async (event, { command, log }) => {
|
|
84
|
+
// Only executed once per unique event
|
|
85
|
+
await command.sendConfirmationEmail({ email: event.data.email })
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
keyFn: (event) => `order-confirm:${event.data.id}`, // Custom dedup key
|
|
89
|
+
ttl: 24 * 3600 * 1000, // 24 hours (default)
|
|
90
|
+
},
|
|
91
|
+
),
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Delivery guarantees
|
|
96
|
+
|
|
97
|
+
- **At-least-once** — Events may be delivered more than once
|
|
98
|
+
- **No ordering** — In production (queue), events arrive in any order
|
|
99
|
+
- **Fire-and-forget** — Subscriber errors don't block the emitter
|
|
100
|
+
- **No compensation** — Subscribers cannot roll back
|
|
101
|
+
|
|
102
|
+
## defineJob()
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// Positional form (preferred)
|
|
106
|
+
export default defineJob('cleanup-draft-products', '0 * * * *', async ({ command, log }) => {
|
|
107
|
+
const result = await command.cleanupDraftProducts({ olderThanDays: 1 })
|
|
108
|
+
log.info(`Cleanup: ${result.deleted} draft products removed`)
|
|
109
|
+
return result
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Or using the config object form:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
export default defineJob({
|
|
117
|
+
name: 'cleanup-draft-products',
|
|
118
|
+
schedule: '0 * * * *', // Every hour
|
|
119
|
+
handler: async ({ command, log }) => {
|
|
120
|
+
const result = await command.cleanupDraftProducts({ olderThanDays: 1 })
|
|
121
|
+
log.info(`Cleanup: ${result.deleted} draft products removed`)
|
|
122
|
+
return result
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Signature (positional):** `defineJob(name, schedule, handler)`
|
|
128
|
+
**Signature (config):** `defineJob({ name, schedule, handler })`
|
|
129
|
+
|
|
130
|
+
- `name` — Unique job identifier
|
|
131
|
+
- `schedule` — Cron expression (5-field standard)
|
|
132
|
+
- `handler` — `async ({ command, log }) => TResult`
|
|
133
|
+
- `command` — CQRS command callables (same scope as subscribers)
|
|
134
|
+
- `log` — Logger instance
|
|
135
|
+
|
|
136
|
+
Jobs receive `{ command, log }` — the same scope as subscribers. Every mutation goes through a command (compensation, retry, audit trail). Jobs do NOT have direct access to `app` or module services.
|
|
137
|
+
|
|
138
|
+
### Cron format
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
┌───────────── minute (0-59)
|
|
142
|
+
│ ┌───────────── hour (0-23)
|
|
143
|
+
│ │ ┌───────────── day of month (1-31)
|
|
144
|
+
│ │ │ ┌───────────── month (1-12)
|
|
145
|
+
│ │ │ │ ┌───────────── day of week (0-7, 0=Sun)
|
|
146
|
+
│ │ │ │ │
|
|
147
|
+
* * * * *
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Examples:
|
|
151
|
+
- `* * * * *` — Every minute
|
|
152
|
+
- `0 * * * *` — Every hour
|
|
153
|
+
- `0 0 * * *` — Every day at midnight
|
|
154
|
+
- `0 9 * * 1` — Every Monday at 9am
|
|
155
|
+
- `*/5 * * * *` — Every 5 minutes
|
|
156
|
+
|
|
157
|
+
### Job locking
|
|
158
|
+
|
|
159
|
+
Concurrent job executions are automatically skipped via `ILockingPort`. If a job is already running, the next invocation returns immediately without executing.
|
|
160
|
+
|
|
161
|
+
## Emitting events
|
|
162
|
+
|
|
163
|
+
In **commands**, events are buffered: `step.emit('event.name', data)` — only emitted if the workflow succeeds.
|
|
164
|
+
|
|
165
|
+
In **subscribers and jobs**, use commands to perform mutations. Events from auto-generated CRUD (e.g., `product.created`) are emitted automatically when commands call service methods.
|
|
166
|
+
|
|
167
|
+
## defineWorkflow() — Intra-module business logic
|
|
168
|
+
|
|
169
|
+
A workflow is a compensable operation scoped to a single module. It orchestrates multiple entity services within the same module — pure business logic with no auth context.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// src/modules/catalog/workflows/categorize-product.ts
|
|
173
|
+
export default defineWorkflow({
|
|
174
|
+
name: 'categorize-product',
|
|
175
|
+
input: z.object({
|
|
176
|
+
productId: z.string(),
|
|
177
|
+
categoryId: z.string(),
|
|
178
|
+
}),
|
|
179
|
+
workflow: async (input, { step, log }) => {
|
|
180
|
+
const product = await step.service.catalog.retrieveProduct(input.productId)
|
|
181
|
+
await step.service.catalog.update(input.productId, { category_id: input.categoryId })
|
|
182
|
+
await step.emit('product.categorized', { id: product.id, categoryId: input.categoryId })
|
|
183
|
+
log.info(`Product ${product.id} categorized`)
|
|
184
|
+
return { productId: product.id }
|
|
185
|
+
},
|
|
186
|
+
})
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Signature:** `defineWorkflow({ name, input, workflow })`
|
|
190
|
+
|
|
191
|
+
- `name` — Unique workflow identifier (kebab-case)
|
|
192
|
+
- `input` — Zod schema (validates input)
|
|
193
|
+
- `workflow` — `async (input, { step, log }) => TResult`
|
|
194
|
+
- `step` — Scoped step proxy (only this module's services)
|
|
195
|
+
- `log` — Logger instance
|
|
196
|
+
|
|
197
|
+
### Key differences from defineCommand
|
|
198
|
+
|
|
199
|
+
| | defineCommand | defineWorkflow |
|
|
200
|
+
|---|---|---|
|
|
201
|
+
| **Location** | `src/commands/{ctx}/` | `src/modules/{mod}/workflows/` |
|
|
202
|
+
| **Context** | `{ step, log, auth, headers }` | `{ step, log }` |
|
|
203
|
+
| **Scope** | Any module | One module only |
|
|
204
|
+
| **HTTP endpoint** | Yes (`POST /api/...`) | No |
|
|
205
|
+
| **Auth** | Yes (`auth` param) | No |
|
|
206
|
+
| **Called from** | HTTP, CLI, sub-command | Commands via `step.workflow.MODULE.NAME()` |
|
|
207
|
+
| **Compensation** | Yes | Yes |
|
|
208
|
+
|
|
209
|
+
### Calling workflows from commands
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
// src/commands/admin/create-and-categorize.ts
|
|
213
|
+
export default defineCommand({
|
|
214
|
+
name: 'create-and-categorize',
|
|
215
|
+
input: z.object({ title: z.string(), categoryId: z.string() }),
|
|
216
|
+
workflow: async (input, { step, auth }) => {
|
|
217
|
+
const product = await step.service.catalog.create({ title: input.title })
|
|
218
|
+
await step.workflow.catalog.categorizeProduct({
|
|
219
|
+
productId: product.id,
|
|
220
|
+
categoryId: input.categoryId,
|
|
221
|
+
})
|
|
222
|
+
return product
|
|
223
|
+
},
|
|
224
|
+
})
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The workflow runs within the command's compensation chain. If any step fails, all completed steps (including those inside the workflow) compensate in reverse order.
|
|
228
|
+
|
|
229
|
+
## File locations
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
src/subscribers/{name}.ts # defineSubscriber()
|
|
233
|
+
src/jobs/{name}.ts # defineJob()
|
|
234
|
+
src/modules/{mod}/workflows/{name}.ts # defineWorkflow()
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Validation errors
|
|
238
|
+
|
|
239
|
+
| Error | Cause | Fix |
|
|
240
|
+
|-------|-------|-----|
|
|
241
|
+
| `Subscriber event must be non-empty` | Empty event string | Set `event: 'product.created'` |
|
|
242
|
+
| `Subscriber handler must be a function` | handler is not async function | Set `handler: async (event, { command, log }) => {...}` |
|
|
243
|
+
| `Job name is required` | Missing name | Add `name: 'my-job'` |
|
|
244
|
+
| `Job schedule (cron expression) is required` | Missing schedule | Add `schedule: '0 * * * *'` |
|
|
245
|
+
| `Job handler must be a function` | handler is not function | Set `handler: async ({ command, log }) => {...}` |
|
|
246
|
+
| `Workflow name is required` | Missing name | Add `name: 'my-workflow'` |
|
|
247
|
+
| `Workflow "X" requires an input Zod schema` | Missing input | Add `input: z.object({})` |
|
|
248
|
+
| `Workflow "X" workflow must be an async function` | workflow is not a function | Add `workflow: async (input, { step, log }) => {...}` |
|