@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,224 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
## Prerequisites
|
|
4
|
+
|
|
5
|
+
- Node.js 18+ (AsyncLocalStorage required)
|
|
6
|
+
- PostgreSQL (local or cloud — Neon, Supabase, etc.)
|
|
7
|
+
- pnpm
|
|
8
|
+
|
|
9
|
+
## Create a project
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
manta init my-app
|
|
13
|
+
cd my-app
|
|
14
|
+
pnpm install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This creates:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
my-app/
|
|
21
|
+
├── manta.config.ts
|
|
22
|
+
├── .env
|
|
23
|
+
├── src/
|
|
24
|
+
│ ├── modules/
|
|
25
|
+
│ ├── commands/
|
|
26
|
+
│ ├── subscribers/
|
|
27
|
+
│ ├── jobs/
|
|
28
|
+
│ ├── links/
|
|
29
|
+
│ └── contexts/
|
|
30
|
+
├── drizzle/migrations/
|
|
31
|
+
└── tsconfig.json
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Step 1 — Configure the database
|
|
35
|
+
|
|
36
|
+
Edit `.env`:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
DATABASE_URL=postgresql://localhost:5432/my_app
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Create the database:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
manta db:create
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Step 2 — Define a model
|
|
49
|
+
|
|
50
|
+
Create `src/modules/blog/entities/post/model.ts`:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
export default defineModel('Post', {
|
|
54
|
+
title: field.text(),
|
|
55
|
+
slug: field.text().unique(),
|
|
56
|
+
content: field.text(),
|
|
57
|
+
status: field.enum(['draft', 'published', 'archived']),
|
|
58
|
+
published_at: field.dateTime().nullable(),
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Step 3 — Define the service
|
|
63
|
+
|
|
64
|
+
Create `src/modules/blog/entities/post/service.ts`:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
export default defineService(
|
|
68
|
+
(model) => model.post,
|
|
69
|
+
(db) => ({
|
|
70
|
+
publish: service.method(
|
|
71
|
+
async (id: string) => {
|
|
72
|
+
const [post] = await db.find({ where: { id } })
|
|
73
|
+
const previousStatus = post.status
|
|
74
|
+
await db.update({ id, status: 'published', published_at: new Date() })
|
|
75
|
+
return { previousStatus }
|
|
76
|
+
},
|
|
77
|
+
async (result, id: string) => {
|
|
78
|
+
await db.update({ id, status: result.previousStatus, published_at: null })
|
|
79
|
+
},
|
|
80
|
+
),
|
|
81
|
+
}),
|
|
82
|
+
)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This gives you 8 CRUD methods for free + the custom `publish` method. No imports needed — `defineService`, `service`, and `model` are all globals.
|
|
86
|
+
|
|
87
|
+
## Step 4 — Define a command
|
|
88
|
+
|
|
89
|
+
Create `src/commands/create-post.ts`:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
export default defineCommand({
|
|
93
|
+
name: 'create-post',
|
|
94
|
+
description: 'Create a new blog post',
|
|
95
|
+
input: z.object({
|
|
96
|
+
title: z.string().min(1),
|
|
97
|
+
slug: z.string().regex(/^[a-z0-9-]+$/),
|
|
98
|
+
content: z.string(),
|
|
99
|
+
publish: z.boolean().default(false),
|
|
100
|
+
}),
|
|
101
|
+
workflow: async (input, { step }) => {
|
|
102
|
+
const post = await step.service.blog.create({
|
|
103
|
+
title: input.title,
|
|
104
|
+
slug: input.slug,
|
|
105
|
+
content: input.content,
|
|
106
|
+
status: 'draft',
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
if (input.publish) {
|
|
110
|
+
await step.service.blog.publish(post.id)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
await step.emit('post.created', { id: post.id, slug: input.slug })
|
|
114
|
+
|
|
115
|
+
return { id: post.id, slug: input.slug, status: input.publish ? 'published' : 'draft' }
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Step 5 — Define a subscriber (optional)
|
|
121
|
+
|
|
122
|
+
Create `src/subscribers/post-created.ts`:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
export default defineSubscriber({
|
|
126
|
+
event: 'post.created',
|
|
127
|
+
handler: async ({ event, app }) => {
|
|
128
|
+
const { slug } = event.data as { slug: string }
|
|
129
|
+
app.infra.logger.info(`New post created: ${slug}`)
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Step 6 — Define a context
|
|
135
|
+
|
|
136
|
+
Create `src/contexts/admin.ts`:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
export default defineContext({
|
|
140
|
+
name: 'admin',
|
|
141
|
+
basePath: '/api/admin',
|
|
142
|
+
actors: ['admin'],
|
|
143
|
+
modules: {
|
|
144
|
+
blog: { expose: '*' },
|
|
145
|
+
},
|
|
146
|
+
commands: ['create-post'],
|
|
147
|
+
ai: { enabled: true },
|
|
148
|
+
})
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Step 7 — Generate migrations and run
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
manta db:generate # Creates SQL migration from Post model
|
|
155
|
+
manta db:migrate # Applies migration to database
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Step 8 — Start the dev server
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
manta dev
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Output:
|
|
165
|
+
```
|
|
166
|
+
[codegen] .manta/types/ (1 modules, 3 events)
|
|
167
|
+
Module: blog (Post) ✓
|
|
168
|
+
Subscriber: post.created → post-created ✓
|
|
169
|
+
Command: create-post ✓
|
|
170
|
+
Context: admin → /api/admin ✓
|
|
171
|
+
|
|
172
|
+
Server running at http://localhost:9000
|
|
173
|
+
API docs at http://localhost:9000/api/docs
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Step 9 — Test it
|
|
177
|
+
|
|
178
|
+
Create a post:
|
|
179
|
+
```bash
|
|
180
|
+
curl -X POST http://localhost:9000/api/admin/command/create-post \
|
|
181
|
+
-H "Content-Type: application/json" \
|
|
182
|
+
-H "Authorization: Bearer <jwt>" \
|
|
183
|
+
-d '{
|
|
184
|
+
"title": "Hello World",
|
|
185
|
+
"slug": "hello-world",
|
|
186
|
+
"content": "My first Manta post",
|
|
187
|
+
"publish": true
|
|
188
|
+
}'
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Query posts:
|
|
192
|
+
```bash
|
|
193
|
+
curl -X POST http://localhost:9000/api/admin/query/blog \
|
|
194
|
+
-H "Content-Type: application/json" \
|
|
195
|
+
-H "Authorization: Bearer <jwt>" \
|
|
196
|
+
-d '{"filters": {"status": "published"}}'
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
View API docs:
|
|
200
|
+
```
|
|
201
|
+
open http://localhost:9000/api/docs
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## What happened automatically
|
|
205
|
+
|
|
206
|
+
From your 4 files (model, service, command, context), Manta generated:
|
|
207
|
+
|
|
208
|
+
- PostgreSQL table `posts` with all columns + indexes
|
|
209
|
+
- 8 CRUD methods on `app.modules.blog`
|
|
210
|
+
- HTTP endpoint `POST /api/admin/command/create-post`
|
|
211
|
+
- HTTP endpoint `POST /api/admin/query/blog`
|
|
212
|
+
- AI tool schema for `create-post` (Zod → JSON Schema)
|
|
213
|
+
- OpenAPI spec with full schema documentation
|
|
214
|
+
- TypeScript types for autocomplete (`.manta/types/`)
|
|
215
|
+
- Event wiring for `post.created` subscriber
|
|
216
|
+
- Compensation logic (if create-post fails, the post is deleted)
|
|
217
|
+
|
|
218
|
+
## Next steps
|
|
219
|
+
|
|
220
|
+
- Add more modules (see [Models](./02-models.md) and [Services](./03-services.md))
|
|
221
|
+
- Add cross-module relations (see [Links](./07-links.md))
|
|
222
|
+
- Add scheduled tasks (see [Events](./06-events.md))
|
|
223
|
+
- Expose a storefront API (see [Contexts](./08-contexts.md))
|
|
224
|
+
- Deploy to production (see [Config](./09-config.md))
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Models — defineModel()
|
|
2
|
+
|
|
3
|
+
## What is a model
|
|
4
|
+
|
|
5
|
+
A model declares the shape of an entity in your database. It generates:
|
|
6
|
+
- A PostgreSQL table (via `manta db:generate`)
|
|
7
|
+
- TypeScript types (via codegen)
|
|
8
|
+
- CRUD methods on the service (auto-generated at boot)
|
|
9
|
+
|
|
10
|
+
## defineModel()
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
export default defineModel('Product', {
|
|
14
|
+
title: field.text(),
|
|
15
|
+
description: field.text().nullable(),
|
|
16
|
+
sku: field.text().unique(),
|
|
17
|
+
price: field.number(),
|
|
18
|
+
status: field.enum(['draft', 'active', 'archived']),
|
|
19
|
+
image_urls: field.json().nullable(),
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Signature:** `defineModel(name: string, schema: Record<string, Property>): DmlEntity`
|
|
24
|
+
|
|
25
|
+
- `name` must be PascalCase (e.g., `Product`, `InventoryItem`, `BlogPost`)
|
|
26
|
+
- `schema` must have at least one property
|
|
27
|
+
- `defineModel` is a global — no import needed
|
|
28
|
+
|
|
29
|
+
## Property types
|
|
30
|
+
|
|
31
|
+
`field` is the global property factory:
|
|
32
|
+
|
|
33
|
+
| Factory | TypeScript type | PostgreSQL type | Example |
|
|
34
|
+
|---------|----------------|-----------------|---------|
|
|
35
|
+
| `field.text()` | `string` | `TEXT` | `title: field.text()` |
|
|
36
|
+
| `field.number()` | `number` | `INTEGER` | `quantity: field.number()` |
|
|
37
|
+
| `field.boolean()` | `boolean` | `BOOLEAN` | `active: field.boolean()` |
|
|
38
|
+
| `field.float()` | `number` | `REAL` | `rating: field.float()` |
|
|
39
|
+
| `field.bigNumber()` | `number` | `NUMERIC` | `amount: field.bigNumber()` |
|
|
40
|
+
| `field.serial()` | `number` | `SERIAL` | `position: field.serial()` |
|
|
41
|
+
| `field.dateTime()` | `Date` | `TIMESTAMPTZ` | `published_at: field.dateTime()` |
|
|
42
|
+
| `field.json()` | `Record<string, unknown>` | `JSONB` | `metadata: field.json()` |
|
|
43
|
+
| `field.enum(values)` | Union type | `TEXT + CHECK` | `status: field.enum(['draft', 'active'])` |
|
|
44
|
+
| `field.array()` | `unknown[]` | `JSONB` | `tags: field.array()` |
|
|
45
|
+
|
|
46
|
+
## Modifiers
|
|
47
|
+
|
|
48
|
+
Chain modifiers after any property:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
field.text().nullable() // Allow NULL
|
|
52
|
+
field.text().unique() // UNIQUE constraint
|
|
53
|
+
field.text().indexed() // Create index
|
|
54
|
+
field.number().default(0) // Default value
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
| Modifier | Effect |
|
|
58
|
+
|----------|--------|
|
|
59
|
+
| `.nullable()` | Column allows NULL |
|
|
60
|
+
| `.unique()` | UNIQUE constraint |
|
|
61
|
+
| `.indexed()` | B-tree index |
|
|
62
|
+
| `.searchable()` | Full-text search index |
|
|
63
|
+
| `.default(value)` | Default value in SQL |
|
|
64
|
+
|
|
65
|
+
## Implicit columns
|
|
66
|
+
|
|
67
|
+
Every entity automatically gets these columns (you cannot redefine them):
|
|
68
|
+
|
|
69
|
+
| Column | Type | Description |
|
|
70
|
+
|--------|------|-------------|
|
|
71
|
+
| `id` | `TEXT PRIMARY KEY` | UUID auto-generated |
|
|
72
|
+
| `created_at` | `TIMESTAMPTZ DEFAULT NOW()` | Creation timestamp |
|
|
73
|
+
| `updated_at` | `TIMESTAMPTZ DEFAULT NOW()` | Last update timestamp |
|
|
74
|
+
| `deleted_at` | `TIMESTAMPTZ NULL` | Soft-delete marker |
|
|
75
|
+
|
|
76
|
+
## Relations
|
|
77
|
+
|
|
78
|
+
Relations between entities are defined with `defineLink()`, not in the model. There is no `field.relation()` API.
|
|
79
|
+
|
|
80
|
+
- **Intra-module relations**: `defineLink()` in `src/modules/{mod}/links/` (1:1/1:N create FK directly, M:N creates pivot)
|
|
81
|
+
- **Cross-module relations**: `defineLink()` in `src/links/` (always creates pivot table)
|
|
82
|
+
|
|
83
|
+
See [Links](./08-links.md) for the full API and examples.
|
|
84
|
+
|
|
85
|
+
## File location
|
|
86
|
+
|
|
87
|
+
Each entity has a folder inside `entities/`. The model is `model.ts`, the service is `service.ts` (same folder):
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
src/modules/catalog/entities/product/model.ts
|
|
91
|
+
src/modules/catalog/entities/category/model.ts
|
|
92
|
+
src/modules/inventory/entities/inventory-item/model.ts
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Migrations
|
|
96
|
+
|
|
97
|
+
After defining or changing a model:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
manta db:generate # Generate SQL migration
|
|
101
|
+
manta db:migrate # Apply to database
|
|
102
|
+
manta db:diff # Compare schema vs DB (diagnostic)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## External entities
|
|
106
|
+
|
|
107
|
+
Mark an entity as **external** when it lives in a third-party system (PostHog, Stripe, Shopify, etc.) and Manta should NOT own its storage. The framework still registers the entity so it remains visible to the query graph, to AI tools (`query_entity`, `describe_entity`), and can be linked to local entities with `defineLink()`.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
// src/modules/posthog/entities/posthog-event/model.ts
|
|
111
|
+
export default defineModel('PostHogEvent', {
|
|
112
|
+
id: field.text().primaryKey(),
|
|
113
|
+
event: field.text(),
|
|
114
|
+
distinct_id: field.text(),
|
|
115
|
+
timestamp: field.dateTime(),
|
|
116
|
+
properties: field.json(),
|
|
117
|
+
}).external()
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
When `.external()` is set, the framework:
|
|
121
|
+
|
|
122
|
+
- does **NOT** generate a database table
|
|
123
|
+
- does **NOT** generate migrations
|
|
124
|
+
- does **NOT** auto-generate a CRUD service
|
|
125
|
+
- **DOES** register the entity in the entity registry (links, AI tools, query graph)
|
|
126
|
+
|
|
127
|
+
External entities MUST be paired with a resolver declared via `extendQueryGraph()` in the same module — see [06-queries.md](./06-queries.md#extendquerygraph--external-entity-resolvers).
|
|
128
|
+
|
|
129
|
+
### fromZodSchema() — declaring an external model from a Zod schema
|
|
130
|
+
|
|
131
|
+
When you already have a Zod schema for the third-party payload (e.g. generated from an SDK via `ts-to-zod`), use `fromZodSchema()` to turn it into a DML field record:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { defineModel, fromZodSchema } from '@mantajs/core'
|
|
135
|
+
import { postHogEventSchema } from './schemas'
|
|
136
|
+
|
|
137
|
+
export default defineModel('PostHogEvent', fromZodSchema(postHogEventSchema)).external()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Zod → DML mapping:
|
|
141
|
+
|
|
142
|
+
| Zod | DML |
|
|
143
|
+
|-----|-----|
|
|
144
|
+
| `z.string()` | `field.text()` |
|
|
145
|
+
| `z.number()` | `field.number()` |
|
|
146
|
+
| `z.boolean()` | `field.boolean()` |
|
|
147
|
+
| `z.date()` | `field.dateTime()` |
|
|
148
|
+
| `z.enum([...])` | `field.enum([...])` |
|
|
149
|
+
| `z.array(...)` | `field.array()` |
|
|
150
|
+
| `z.object(...)` / `z.record(...)` | `field.json()` |
|
|
151
|
+
| `.optional()` / `.nullable()` / `.default()` | `.nullable()` |
|
|
152
|
+
|
|
153
|
+
Convention: a field named `id` is automatically marked as primary key.
|
|
154
|
+
|
|
155
|
+
## Validation errors
|
|
156
|
+
|
|
157
|
+
| Error | Cause | Fix |
|
|
158
|
+
|-------|-------|-----|
|
|
159
|
+
| `Entity name is required` | Empty string passed | Use PascalCase name: `defineModel('Product', {...})` |
|
|
160
|
+
| `Entity name must be PascalCase` | Lowercase name | Change `product` to `Product` |
|
|
161
|
+
| `Entity must have at least one property` | Empty schema `{}` | Add properties: `{ title: field.text() }` |
|
|
162
|
+
| `Property "id" is implicit and cannot be redefined` | Declared `id` in schema | Remove it — `id` is auto-generated |
|
|
163
|
+
| `Property uses reserved "raw_" prefix` | Name starts with `raw_` | Rename — `raw_` is for bigNumber shadow columns |
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Services — defineService()
|
|
2
|
+
|
|
3
|
+
## The rule
|
|
4
|
+
|
|
5
|
+
**1 entity = 1 service. Always.**
|
|
6
|
+
|
|
7
|
+
A service defines the mutations (writes) for **one** entity. The repository it receives is typed for that entity only. A service cannot mutate another entity — that's a command.
|
|
8
|
+
|
|
9
|
+
A module can have multiple entities, and therefore multiple services. If you need to mutate two entities together, write a module command that orchestrates them.
|
|
10
|
+
|
|
11
|
+
If you don't have an entity, you don't have a module. Use `app.infra.*` for infrastructure (file storage, cache, logging).
|
|
12
|
+
|
|
13
|
+
## defineService()
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
export default defineService('product', ({ db, log }) => ({
|
|
17
|
+
activate: async (id: string) => {
|
|
18
|
+
await db.update({ id, status: 'active' })
|
|
19
|
+
log.info(`Product ${id} activated`)
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
archive: async (id: string) => {
|
|
23
|
+
await db.update({ id, status: 'archived' })
|
|
24
|
+
log.info(`Product ${id} archived`)
|
|
25
|
+
},
|
|
26
|
+
}))
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Signature:** `defineService(entityName: string, factory: ({ db, log }) => Methods, options?)`
|
|
30
|
+
|
|
31
|
+
- `entityName` — Entity name as a string (autocompletes from codegen)
|
|
32
|
+
- `factory` — Receives `{ db, log }` (typed repository + logger), returns methods
|
|
33
|
+
- `options.publicMethods` — (optional) Array of method names visible to other modules
|
|
34
|
+
|
|
35
|
+
No imports needed — `defineService` is a global. Compensation is automatic — the repo snapshots state before every mutation. No `service.method()` wrapper needed.
|
|
36
|
+
|
|
37
|
+
## Auto-generated CRUD methods
|
|
38
|
+
|
|
39
|
+
From `defineService(Product, ...)`, the framework generates these 8 methods automatically:
|
|
40
|
+
|
|
41
|
+
| Method | Signature | Events emitted |
|
|
42
|
+
|--------|-----------|---------------|
|
|
43
|
+
| `retrieveProduct(id, config?)` | `(string, ServiceConfig?) => Promise<Product>` | none |
|
|
44
|
+
| `listProducts(filters?, config?)` | `(Partial<Product>?, ServiceConfig?) => Promise<Product[]>` | none |
|
|
45
|
+
| `listAndCountProducts(filters?, config?)` | `(Partial<Product>?, ServiceConfig?) => Promise<[Product[], number]>` | none |
|
|
46
|
+
| `createProducts(data)` | `(Partial<Product> \| Partial<Product>[]) => Promise<Product \| Product[]>` | `product.created` |
|
|
47
|
+
| `updateProducts(data)` | `(({id} & Partial<Product>) \| ...[]) => Promise<Product \| Product[]>` | `product.updated` |
|
|
48
|
+
| `deleteProducts(ids)` | `(string \| string[]) => Promise<void>` | `product.deleted` |
|
|
49
|
+
| `softDeleteProducts(ids)` | `(string \| string[]) => Promise<Record<string, string[]>>` | none |
|
|
50
|
+
| `restoreProducts(ids)` | `(string \| string[]) => Promise<void>` | none |
|
|
51
|
+
|
|
52
|
+
Plus two query helpers:
|
|
53
|
+
- `list()` — All entities, ordered by `created_at DESC`
|
|
54
|
+
- `findById(id)` — Single entity or `null`
|
|
55
|
+
|
|
56
|
+
**The method names are derived from the entity name.** `Product` → `createProducts`, `InventoryItem` → `createInventoryItems`.
|
|
57
|
+
|
|
58
|
+
## Auto-compensation — snapshot-based rollback
|
|
59
|
+
|
|
60
|
+
Service methods are plain `async` functions. No `service.method()` wrapper needed.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
activate: async (id: string) => {
|
|
64
|
+
await db.update({ id, status: 'active' })
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**How it works:** The framework auto-snapshots repository state before every mutation. In a workflow, if step 3 fails, steps 1 and 2 are automatically rolled back using the snapshots. You don't write compensation logic — the framework handles it.
|
|
69
|
+
|
|
70
|
+
## TypedRepository — the db API
|
|
71
|
+
|
|
72
|
+
The `db` parameter is a `TypedRepository<T>` where `T` is the inferred entity type:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// Find entities
|
|
76
|
+
const products = await db.find({
|
|
77
|
+
where: { status: 'active' }, // Partial<Product> filter
|
|
78
|
+
order: { created_at: 'DESC' }, // Sort
|
|
79
|
+
limit: 10, // Pagination
|
|
80
|
+
offset: 0,
|
|
81
|
+
withDeleted: false, // Include soft-deleted (default: false)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// Find with count
|
|
85
|
+
const [items, total] = await db.findAndCount({ where: { status: 'draft' } })
|
|
86
|
+
|
|
87
|
+
// Create
|
|
88
|
+
const product = await db.create({ title: 'Widget', sku: 'W-001', price: 999 })
|
|
89
|
+
|
|
90
|
+
// Update (id required)
|
|
91
|
+
const updated = await db.update({ id: 'prod_123', status: 'active' })
|
|
92
|
+
|
|
93
|
+
// Delete
|
|
94
|
+
await db.delete('prod_123') // Hard delete
|
|
95
|
+
await db.delete(['id1', 'id2']) // Batch delete
|
|
96
|
+
|
|
97
|
+
// Soft-delete
|
|
98
|
+
await db.softDelete(['prod_123']) // Sets deleted_at
|
|
99
|
+
await db.restore(['prod_123']) // Clears deleted_at
|
|
100
|
+
|
|
101
|
+
// Bulk upsert (insert or replace on conflict)
|
|
102
|
+
await db.upsertWithReplace(
|
|
103
|
+
[{ id: 'prod_1', title: 'A' }, { id: 'prod_2', title: 'B' }],
|
|
104
|
+
['title'], // fields to replace on conflict (optional)
|
|
105
|
+
['id'], // conflict target columns (optional, defaults to ['id'])
|
|
106
|
+
)
|
|
107
|
+
// Note: upsertWithReplace bypasses compensation — it's a bulk operation
|
|
108
|
+
// mixing creates and updates, which cannot be atomically reversed.
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Raw SQL escape hatch — db.raw()
|
|
112
|
+
|
|
113
|
+
When TypedRepository methods are not enough (complex aggregations, window functions, CTEs), use `db.raw()` on the database port:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// In a command step or via app.infra.db
|
|
117
|
+
const results = await app.infra.db.raw<{ total: number; status: string }>(
|
|
118
|
+
`SELECT status, COUNT(*)::int AS total FROM product WHERE created_at > $1 GROUP BY status`,
|
|
119
|
+
[since],
|
|
120
|
+
)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Signature:** `raw<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>`
|
|
124
|
+
|
|
125
|
+
- Uses `$1`, `$2` parameterized placeholders (safe from SQL injection)
|
|
126
|
+
- Available on all database adapters: DrizzlePgAdapter, NeonAdapter, InMemoryDatabaseAdapter
|
|
127
|
+
- The in-memory adapter throws `MantaError('NOT_FOUND')` — raw SQL only works against real databases
|
|
128
|
+
- **Use sparingly** — prefer TypedRepository methods for standard CRUD. `raw()` is for queries that the ORM cannot express.
|
|
129
|
+
|
|
130
|
+
## Isolation
|
|
131
|
+
|
|
132
|
+
The service factory receives **only `{ db, log }`** (typed repository + logger). You cannot:
|
|
133
|
+
- Import another module's service
|
|
134
|
+
- Access `app` or `app.modules.*`
|
|
135
|
+
- Call external APIs directly
|
|
136
|
+
|
|
137
|
+
This is **structural**, not a convention — the type system enforces it. If you need to orchestrate multiple modules, use a `defineCommand()`.
|
|
138
|
+
|
|
139
|
+
## publicMethods (access control)
|
|
140
|
+
|
|
141
|
+
By default, all methods (CRUD + custom) are accessible from jobs, subscribers, and commands. To restrict:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
export default defineService('product', ({ db }) => ({
|
|
145
|
+
activate: async (id: string) => {
|
|
146
|
+
await db.update({ id, status: 'active' })
|
|
147
|
+
},
|
|
148
|
+
_internalReset: async (id: string) => {
|
|
149
|
+
await db.update({ id, status: 'draft' })
|
|
150
|
+
},
|
|
151
|
+
}), { publicMethods: ['activate'] }) // Only activate is visible via app.modules.catalog
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Soft-delete behavior
|
|
155
|
+
|
|
156
|
+
All reads automatically filter `WHERE deleted_at IS NULL`. To include soft-deleted records:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
await db.find({ withDeleted: true })
|
|
160
|
+
// Or via auto-generated CRUD:
|
|
161
|
+
await app.modules.catalog.listProducts({}, { withDeleted: true })
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Module structure
|
|
165
|
+
|
|
166
|
+
Each entity lives in its own folder inside `entities/`, containing both `model.ts` and `service.ts`:
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
src/modules/catalog/
|
|
170
|
+
├── entities/
|
|
171
|
+
│ ├── product/
|
|
172
|
+
│ │ ├── model.ts # defineModel('Product', {...})
|
|
173
|
+
│ │ └── service.ts # defineService('product', ({ db, log }) => ({...}))
|
|
174
|
+
│ └── category/
|
|
175
|
+
│ ├── model.ts # defineModel('Category', {...})
|
|
176
|
+
│ └── service.ts # defineService('category', ({ db, log }) => ({...}))
|
|
177
|
+
├── links/ # Intra-module relations (FK or pivot)
|
|
178
|
+
│ └── product-category.ts
|
|
179
|
+
├── workflows/ # Intra-module business logic (no auth)
|
|
180
|
+
│ └── categorize-product.ts
|
|
181
|
+
└── index.ts # Barrel — re-exports only
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The `model.ts` and `service.ts` are an inseparable pair. One entity, one service, one folder. The service uses the entity name as a string to reference its entity (no imports needed).
|
|
185
|
+
|
|
186
|
+
### The barrel (index.ts)
|
|
187
|
+
|
|
188
|
+
Pure re-exports, no logic:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
// src/modules/catalog/index.ts
|
|
192
|
+
export { Product } from './entities/product/model'
|
|
193
|
+
export { Category } from './entities/category/model'
|
|
194
|
+
export { default } from './entities/product/service'
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Why 1 entity = 1 service?
|
|
198
|
+
|
|
199
|
+
A service method that mutates Product AND Category in the same call cannot be compensated correctly — if the Category mutation fails, how does the service undo the Product mutation? It can't, because it only has the Product `db`.
|
|
200
|
+
|
|
201
|
+
That's why cross-entity mutations go in **workflows** (intra-module) or **commands** (cross-module): the step proxy handles compensation across multiple services automatically.
|
|
202
|
+
|
|
203
|
+
## Validation errors
|
|
204
|
+
|
|
205
|
+
| Error | Cause | Fix |
|
|
206
|
+
|-------|-------|-----|
|
|
207
|
+
| `Service method "X" must be an async function` | Non-function in factory return | Define as `async (args) => { ... }` |
|
|
208
|
+
| `Module "X" is already registered` | Two modules with same name | Rename one of the modules |
|