@tailor-platform/erp-kit 0.1.2 → 0.2.1
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/CHANGELOG.md +12 -0
- package/README.md +80 -12
- package/dist/cli.js +1070 -450
- package/package.json +11 -8
- package/schemas/app-compose/business-flow.yml +3 -0
- package/schemas/app-compose/story.yml +1 -1
- package/schemas/module/model.yml +5 -0
- package/skills/{app-compose-1-requirement-analysis → erp-kit-app-1-requirements}/SKILL.md +8 -14
- package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/SKILL.md +6 -13
- package/skills/{app-compose-3-doc-review → erp-kit-app-3-doc-review}/SKILL.md +2 -6
- package/skills/{app-compose-6-implementation-spec → erp-kit-app-4-impl-spec}/SKILL.md +11 -22
- package/skills/erp-kit-app-5-implementation/SKILL.md +149 -0
- package/skills/erp-kit-app-5-implementation/references/backend.md +232 -0
- package/skills/erp-kit-app-5-implementation/references/frontend.md +242 -0
- package/skills/{mock-scenario → erp-kit-mock-scenario}/SKILL.md +1 -1
- package/skills/{1-module-docs → erp-kit-module-1-docs}/SKILL.md +2 -2
- package/skills/{2-module-feature-breakdown → erp-kit-module-2-feature-breakdown}/SKILL.md +13 -9
- package/skills/erp-kit-module-2-feature-breakdown/references/naming.md +59 -0
- package/skills/{3-module-doc-review → erp-kit-module-3-doc-review}/SKILL.md +83 -25
- package/skills/erp-kit-module-4-tdd/SKILL.md +94 -0
- package/skills/erp-kit-module-4-tdd/references/cross-module-dependency.md +133 -0
- package/skills/{4-module-tdd-implementation → erp-kit-module-4-tdd}/references/db-relations.md +5 -1
- package/skills/{4-module-tdd-implementation → erp-kit-module-4-tdd}/references/exports.md +1 -1
- package/skills/erp-kit-module-4-tdd/references/generated-code.md +32 -0
- package/skills/{5-module-implementation-review → erp-kit-module-5-impl-review}/SKILL.md +46 -44
- package/skills/erp-kit-module-5-impl-review/references/commands.md +62 -0
- package/skills/erp-kit-module-5-impl-review/references/errors.md +10 -0
- package/skills/{5-module-implementation-review → erp-kit-module-5-impl-review}/references/testing.md +1 -1
- package/skills/erp-kit-module-shared/SKILL.md +16 -0
- package/skills/erp-kit-module-shared/references/commands.md +203 -0
- package/skills/erp-kit-module-shared/references/errors.md +35 -0
- package/skills/erp-kit-module-shared/references/queries.md +168 -0
- package/skills/erp-kit-module-shared/references/structure.md +36 -0
- package/skills/{3-module-doc-review → erp-kit-module-shared}/references/testing.md +4 -3
- package/skills/erp-kit-update/SKILL.md +64 -0
- package/src/cli.doc.test.ts +65 -0
- package/src/cli.ts +3 -35
- package/src/commands/app/index.ts +3 -3
- package/src/commands/check.test.ts +1 -1
- package/src/commands/check.ts +2 -2
- package/src/commands/index.ts +73 -0
- package/src/commands/init.test.ts +22 -5
- package/src/commands/init.ts +25 -16
- package/src/commands/license.ts +193 -0
- package/src/commands/mock/index.ts +2 -2
- package/src/commands/mock/start.ts +1 -1
- package/src/commands/mock/validate.test.ts +1 -1
- package/src/commands/module/generate.ts +35 -0
- package/src/commands/module/index.ts +6 -4
- package/src/commands/module/list.test.ts +7 -12
- package/src/commands/module/list.ts +1 -1
- package/src/commands/scaffold-templates.ts +65 -0
- package/src/commands/scaffold.test.ts +92 -2
- package/src/commands/scaffold.ts +22 -2
- package/src/commands/sync-check.test.ts +60 -1
- package/src/commands/sync-check.ts +35 -2
- package/src/generator/generate-code.test.ts +200 -0
- package/src/generator/generate-code.ts +260 -0
- package/src/generator/parse-command-doc.test.ts +159 -0
- package/src/generator/parse-command-doc.ts +116 -0
- package/src/integration.test.ts +2 -2
- package/src/module.ts +44 -6
- package/src/modules/item-management/README.md +38 -0
- package/src/modules/item-management/command/activateItem.generated.ts +6 -0
- package/src/modules/item-management/command/activateItem.test.ts +76 -0
- package/src/modules/item-management/command/activateItem.ts +42 -0
- package/src/modules/item-management/command/assignItemToTaxonomy.generated.ts +6 -0
- package/src/modules/item-management/command/assignItemToTaxonomy.test.ts +88 -0
- package/src/modules/item-management/command/assignItemToTaxonomy.ts +63 -0
- package/src/modules/item-management/command/createItem.generated.ts +6 -0
- package/src/modules/item-management/command/createItem.test.ts +152 -0
- package/src/modules/item-management/command/createItem.ts +72 -0
- package/src/modules/item-management/command/createTaxonomyNode.generated.ts +6 -0
- package/src/modules/item-management/command/createTaxonomyNode.test.ts +126 -0
- package/src/modules/item-management/command/createTaxonomyNode.ts +70 -0
- package/src/modules/item-management/command/deactivateItem.generated.ts +6 -0
- package/src/modules/item-management/command/deactivateItem.test.ts +76 -0
- package/src/modules/item-management/command/deactivateItem.ts +42 -0
- package/src/modules/item-management/command/deleteItem.generated.ts +6 -0
- package/src/modules/item-management/command/deleteItem.test.ts +61 -0
- package/src/modules/item-management/command/deleteItem.ts +38 -0
- package/src/modules/item-management/command/deleteTaxonomyNode.generated.ts +6 -0
- package/src/modules/item-management/command/deleteTaxonomyNode.test.ts +73 -0
- package/src/modules/item-management/command/deleteTaxonomyNode.ts +50 -0
- package/src/modules/item-management/command/moveTaxonomyNode.generated.ts +6 -0
- package/src/modules/item-management/command/moveTaxonomyNode.test.ts +136 -0
- package/src/modules/item-management/command/moveTaxonomyNode.ts +85 -0
- package/src/modules/item-management/command/reactivateItem.generated.ts +6 -0
- package/src/modules/item-management/command/reactivateItem.test.ts +76 -0
- package/src/modules/item-management/command/reactivateItem.ts +42 -0
- package/src/modules/item-management/command/removeItemFromTaxonomy.generated.ts +6 -0
- package/src/modules/item-management/command/removeItemFromTaxonomy.test.ts +43 -0
- package/src/modules/item-management/command/removeItemFromTaxonomy.ts +30 -0
- package/src/modules/item-management/command/updateItem.generated.ts +6 -0
- package/src/modules/item-management/command/updateItem.test.ts +178 -0
- package/src/modules/item-management/command/updateItem.ts +103 -0
- package/src/modules/item-management/command/updateTaxonomyNode.generated.ts +6 -0
- package/src/modules/item-management/command/updateTaxonomyNode.test.ts +88 -0
- package/src/modules/item-management/command/updateTaxonomyNode.ts +62 -0
- package/src/modules/item-management/db/item.ts +47 -0
- package/src/modules/item-management/db/itemTaxonomyAssignment.ts +49 -0
- package/src/modules/item-management/db/taxonomyNode.ts +34 -0
- package/src/modules/item-management/docs/commands/ActivateItem.md +32 -0
- package/src/modules/item-management/docs/commands/AssignItemToTaxonomy.md +38 -0
- package/src/modules/item-management/docs/commands/CreateItem.md +44 -0
- package/src/modules/item-management/docs/commands/CreateTaxonomyNode.md +44 -0
- package/src/modules/item-management/docs/commands/DeactivateItem.md +34 -0
- package/src/modules/item-management/docs/commands/DeleteItem.md +35 -0
- package/src/modules/item-management/docs/commands/DeleteTaxonomyNode.md +39 -0
- package/src/modules/item-management/docs/commands/MoveTaxonomyNode.md +45 -0
- package/src/modules/item-management/docs/commands/ReactivateItem.md +34 -0
- package/src/modules/item-management/docs/commands/RemoveItemFromTaxonomy.md +30 -0
- package/src/modules/item-management/docs/commands/UpdateItem.md +55 -0
- package/src/modules/item-management/docs/commands/UpdateTaxonomyNode.md +36 -0
- package/src/modules/item-management/docs/features/item-lifecycle.md +60 -0
- package/src/modules/item-management/docs/features/item-taxonomy.md +65 -0
- package/src/modules/item-management/docs/models/ItemTaxonomyAssignment.md +36 -0
- package/src/modules/item-management/docs/models/TaxonomyNode.md +47 -0
- package/src/modules/item-management/docs/models/item.md +59 -0
- package/src/modules/item-management/docs/queries/CalculateNodeDepth.md +36 -0
- package/src/modules/item-management/docs/queries/CalculateSubtreeDepth.md +40 -0
- package/src/modules/item-management/docs/queries/DetectCircularReference.md +41 -0
- package/src/modules/item-management/docs/queries/GetItem.md +38 -0
- package/src/modules/item-management/docs/queries/GetItemTaxonomyAssignment.md +29 -0
- package/src/modules/item-management/docs/queries/GetTaxonomyNode.md +35 -0
- package/src/modules/item-management/docs/queries/GetTaxonomyNodeAssignments.md +29 -0
- package/src/modules/item-management/docs/queries/GetTaxonomyNodeChildren.md +29 -0
- package/src/modules/item-management/generated/enums.ts +9 -0
- package/src/modules/item-management/generated/kysely-tailordb.ts +62 -0
- package/src/modules/item-management/index.ts +53 -0
- package/src/modules/item-management/lib/_db_deps.ts +13 -0
- package/src/modules/item-management/lib/errors.generated.ts +117 -0
- package/src/modules/item-management/lib/permissions.generated.ts +17 -0
- package/src/modules/item-management/lib/types.ts +19 -0
- package/src/modules/item-management/module.ts +97 -0
- package/src/modules/item-management/query/calculateNodeDepth.generated.ts +5 -0
- package/src/modules/item-management/query/calculateNodeDepth.test.ts +56 -0
- package/src/modules/item-management/query/calculateNodeDepth.ts +28 -0
- package/src/modules/item-management/query/calculateSubtreeDepth.generated.ts +5 -0
- package/src/modules/item-management/query/calculateSubtreeDepth.test.ts +75 -0
- package/src/modules/item-management/query/calculateSubtreeDepth.ts +29 -0
- package/src/modules/item-management/query/detectCircularReference.generated.ts +5 -0
- package/src/modules/item-management/query/detectCircularReference.test.ts +61 -0
- package/src/modules/item-management/query/detectCircularReference.ts +32 -0
- package/src/modules/item-management/query/getItem.generated.ts +5 -0
- package/src/modules/item-management/query/getItem.test.ts +67 -0
- package/src/modules/item-management/query/getItem.ts +20 -0
- package/src/modules/item-management/query/getItemTaxonomyAssignment.generated.ts +5 -0
- package/src/modules/item-management/query/getItemTaxonomyAssignment.test.ts +25 -0
- package/src/modules/item-management/query/getItemTaxonomyAssignment.ts +18 -0
- package/src/modules/item-management/query/getTaxonomyNode.generated.ts +5 -0
- package/src/modules/item-management/query/getTaxonomyNode.test.ts +47 -0
- package/src/modules/item-management/query/getTaxonomyNode.ts +18 -0
- package/src/modules/item-management/query/getTaxonomyNodeAssignments.generated.ts +5 -0
- package/src/modules/item-management/query/getTaxonomyNodeAssignments.test.ts +25 -0
- package/src/modules/item-management/query/getTaxonomyNodeAssignments.ts +16 -0
- package/src/modules/item-management/query/getTaxonomyNodeChildren.generated.ts +5 -0
- package/src/modules/item-management/query/getTaxonomyNodeChildren.test.ts +34 -0
- package/src/modules/item-management/query/getTaxonomyNodeChildren.ts +16 -0
- package/src/modules/item-management/tailor.config.ts +11 -0
- package/src/modules/item-management/testing/fixtures.ts +81 -0
- package/src/modules/primitives/command/activateCategory.generated.ts +6 -0
- package/src/modules/primitives/command/activateCategory.test.ts +11 -29
- package/src/modules/primitives/command/activateCategory.ts +27 -34
- package/src/modules/primitives/command/activateCurrency.generated.ts +6 -0
- package/src/modules/primitives/command/activateCurrency.test.ts +11 -29
- package/src/modules/primitives/command/activateCurrency.ts +27 -34
- package/src/modules/primitives/command/activateUnit.generated.ts +6 -0
- package/src/modules/primitives/command/activateUnit.test.ts +11 -15
- package/src/modules/primitives/command/activateUnit.ts +27 -34
- package/src/modules/primitives/command/createCategory.generated.ts +6 -0
- package/src/modules/primitives/command/createCategory.test.ts +27 -39
- package/src/modules/primitives/command/createCategory.ts +53 -62
- package/src/modules/primitives/command/createCurrency.generated.ts +6 -0
- package/src/modules/primitives/command/createCurrency.test.ts +78 -71
- package/src/modules/primitives/command/createCurrency.ts +43 -48
- package/src/modules/primitives/command/createExchangeRate.generated.ts +6 -0
- package/src/modules/primitives/command/createExchangeRate.test.ts +101 -100
- package/src/modules/primitives/command/createExchangeRate.ts +50 -59
- package/src/modules/primitives/command/createUnit.generated.ts +6 -0
- package/src/modules/primitives/command/createUnit.test.ts +92 -95
- package/src/modules/primitives/command/createUnit.ts +54 -57
- package/src/modules/primitives/command/deactivateCategory.generated.ts +6 -0
- package/src/modules/primitives/command/deactivateCategory.test.ts +27 -28
- package/src/modules/primitives/command/deactivateCategory.ts +43 -50
- package/src/modules/primitives/command/deactivateCurrency.generated.ts +6 -0
- package/src/modules/primitives/command/deactivateCurrency.test.ts +23 -38
- package/src/modules/primitives/command/deactivateCurrency.ts +31 -38
- package/src/modules/primitives/command/deactivateUnit.generated.ts +6 -0
- package/src/modules/primitives/command/deactivateUnit.test.ts +27 -23
- package/src/modules/primitives/command/deactivateUnit.ts +39 -49
- package/src/modules/primitives/command/setBaseCurrency.generated.ts +6 -0
- package/src/modules/primitives/command/setBaseCurrency.test.ts +40 -33
- package/src/modules/primitives/command/setBaseCurrency.ts +43 -50
- package/src/modules/primitives/command/setReferenceUnit.generated.ts +6 -0
- package/src/modules/primitives/command/setReferenceUnit.test.ts +39 -35
- package/src/modules/primitives/command/setReferenceUnit.ts +46 -59
- package/src/modules/primitives/db/unit.ts +13 -3
- package/src/modules/primitives/docs/commands/ActivateCategory.md +1 -2
- package/src/modules/primitives/docs/commands/ActivateCurrency.md +1 -2
- package/src/modules/primitives/docs/commands/ActivateUnit.md +1 -2
- package/src/modules/primitives/docs/commands/CreateCategory.md +1 -4
- package/src/modules/primitives/docs/commands/CreateCurrency.md +3 -4
- package/src/modules/primitives/docs/commands/CreateExchangeRate.md +4 -5
- package/src/modules/primitives/docs/commands/CreateUnit.md +5 -5
- package/src/modules/primitives/docs/commands/DeactivateCategory.md +2 -3
- package/src/modules/primitives/docs/commands/DeactivateCurrency.md +2 -3
- package/src/modules/primitives/docs/commands/DeactivateUnit.md +2 -3
- package/src/modules/primitives/docs/commands/SetBaseCurrency.md +2 -3
- package/src/modules/primitives/docs/commands/SetReferenceUnit.md +2 -3
- package/src/modules/primitives/docs/queries/ConvertAmount.md +3 -5
- package/src/modules/primitives/docs/queries/ConvertQuantity.md +3 -5
- package/src/modules/primitives/docs/queries/GetBaseCurrency.md +32 -0
- package/src/modules/primitives/docs/queries/GetCurrency.md +36 -0
- package/src/modules/primitives/docs/queries/GetUnit.md +36 -0
- package/src/modules/primitives/docs/queries/GetUoMCategory.md +36 -0
- package/src/modules/primitives/docs/queries/ListUnitsByCategory.md +26 -0
- package/src/modules/primitives/generated/kysely-tailordb.ts +24 -45
- package/src/modules/primitives/index.ts +15 -4
- package/src/modules/primitives/lib/errors.generated.ts +112 -0
- package/src/modules/primitives/{permissions.ts → lib/permissions.generated.ts} +9 -8
- package/src/modules/primitives/module.ts +37 -27
- package/src/modules/primitives/query/convertAmount.generated.ts +5 -0
- package/src/modules/primitives/query/convertAmount.test.ts +2 -2
- package/src/modules/primitives/query/convertAmount.ts +27 -28
- package/src/modules/primitives/query/convertQuantity.generated.ts +5 -0
- package/src/modules/primitives/query/convertQuantity.test.ts +6 -2
- package/src/modules/primitives/query/convertQuantity.ts +49 -57
- package/src/modules/primitives/query/getBaseCurrency.generated.ts +5 -0
- package/src/modules/primitives/query/getBaseCurrency.test.ts +28 -0
- package/src/modules/primitives/query/getBaseCurrency.ts +16 -0
- package/src/modules/primitives/query/getCurrency.generated.ts +5 -0
- package/src/modules/primitives/query/getCurrency.test.ts +47 -0
- package/src/modules/primitives/query/getCurrency.ts +18 -0
- package/src/modules/primitives/query/getUnit.generated.ts +5 -0
- package/src/modules/primitives/query/getUnit.test.ts +47 -0
- package/src/modules/primitives/query/getUnit.ts +18 -0
- package/src/modules/primitives/query/getUoMCategory.generated.ts +5 -0
- package/src/modules/primitives/query/getUoMCategory.test.ts +47 -0
- package/src/modules/primitives/query/getUoMCategory.ts +18 -0
- package/src/modules/primitives/query/listUnitsByCategory.generated.ts +5 -0
- package/src/modules/primitives/query/listUnitsByCategory.ts +16 -0
- package/src/modules/primitives/tailor.config.ts +3 -3
- package/src/modules/shared/defineCommand.test.ts +23 -10
- package/src/modules/shared/defineCommand.ts +23 -10
- package/src/modules/shared/internal.ts +1 -0
- package/src/modules/shared/requirePermission.test.ts +22 -21
- package/src/modules/shared/requirePermission.ts +8 -2
- package/src/modules/shared/result.ts +12 -0
- package/src/modules/testing/index.ts +36 -11
- package/src/modules/user-management/command/activateUser.generated.ts +6 -0
- package/src/modules/user-management/command/activateUser.test.ts +27 -27
- package/src/modules/user-management/command/activateUser.ts +40 -48
- package/src/modules/user-management/command/assignPermissionToRole.generated.ts +6 -0
- package/src/modules/user-management/command/assignPermissionToRole.test.ts +42 -43
- package/src/modules/user-management/command/assignPermissionToRole.ts +59 -62
- package/src/modules/user-management/command/assignRoleToUser.generated.ts +6 -0
- package/src/modules/user-management/command/assignRoleToUser.test.ts +70 -63
- package/src/modules/user-management/command/assignRoleToUser.ts +63 -66
- package/src/modules/user-management/command/createPermission.generated.ts +6 -0
- package/src/modules/user-management/command/createPermission.test.ts +45 -38
- package/src/modules/user-management/command/createPermission.ts +42 -46
- package/src/modules/user-management/command/createRole.generated.ts +6 -0
- package/src/modules/user-management/command/createRole.test.ts +30 -29
- package/src/modules/user-management/command/createRole.ts +33 -33
- package/src/modules/user-management/command/createUser.generated.ts +6 -0
- package/src/modules/user-management/command/createUser.test.ts +64 -42
- package/src/modules/user-management/command/createUser.ts +54 -56
- package/src/modules/user-management/command/deactivateUser.generated.ts +6 -0
- package/src/modules/user-management/command/deactivateUser.test.ts +27 -27
- package/src/modules/user-management/command/deactivateUser.ts +40 -48
- package/src/modules/user-management/command/logAuditEvent.generated.ts +6 -0
- package/src/modules/user-management/command/logAuditEvent.test.ts +50 -42
- package/src/modules/user-management/command/logAuditEvent.ts +25 -28
- package/src/modules/user-management/command/reactivateUser.generated.ts +6 -0
- package/src/modules/user-management/command/reactivateUser.test.ts +31 -27
- package/src/modules/user-management/command/reactivateUser.ts +40 -48
- package/src/modules/user-management/command/revokePermissionFromRole.generated.ts +6 -0
- package/src/modules/user-management/command/revokePermissionFromRole.test.ts +52 -51
- package/src/modules/user-management/command/revokePermissionFromRole.ts +60 -57
- package/src/modules/user-management/command/revokeRoleFromUser.generated.ts +6 -0
- package/src/modules/user-management/command/revokeRoleFromUser.test.ts +53 -48
- package/src/modules/user-management/command/revokeRoleFromUser.ts +58 -57
- package/src/modules/user-management/docs/commands/CreatePermission.md +2 -2
- package/src/modules/user-management/docs/commands/CreateRole.md +1 -1
- package/src/modules/user-management/generated/enums.ts +11 -11
- package/src/modules/user-management/generated/kysely-tailordb.ts +27 -56
- package/src/modules/user-management/index.ts +2 -2
- package/src/modules/user-management/lib/errors.generated.ts +67 -0
- package/src/modules/user-management/{permissions.ts → lib/permissions.generated.ts} +8 -7
- package/src/modules/user-management/module.ts +22 -22
- package/src/modules/user-management/tailor.config.ts +3 -3
- package/src/schemas.ts +1 -1
- package/skills/1-module-docs/references/structure.md +0 -22
- package/skills/2-module-feature-breakdown/references/commands.md +0 -48
- package/skills/2-module-feature-breakdown/references/structure.md +0 -22
- package/skills/3-module-doc-review/references/commands.md +0 -54
- package/skills/3-module-doc-review/references/models.md +0 -29
- package/skills/4-module-tdd-implementation/SKILL.md +0 -74
- package/skills/4-module-tdd-implementation/references/commands.md +0 -45
- package/skills/4-module-tdd-implementation/references/errors.md +0 -7
- package/skills/4-module-tdd-implementation/references/models.md +0 -30
- package/skills/4-module-tdd-implementation/references/structure.md +0 -22
- package/skills/4-module-tdd-implementation/references/testing.md +0 -37
- package/skills/5-module-implementation-review/references/commands.md +0 -45
- package/skills/5-module-implementation-review/references/errors.md +0 -7
- package/skills/5-module-implementation-review/references/exports.md +0 -8
- package/skills/5-module-implementation-review/references/models.md +0 -30
- package/skills/app-compose-1-requirement-analysis/references/structure.md +0 -27
- package/skills/app-compose-2-requirements-breakdown/references/screen-detailview.md +0 -106
- package/skills/app-compose-2-requirements-breakdown/references/screen-form.md +0 -139
- package/skills/app-compose-2-requirements-breakdown/references/screen-listview.md +0 -153
- package/skills/app-compose-2-requirements-breakdown/references/structure.md +0 -27
- package/skills/app-compose-3-doc-review/references/structure.md +0 -27
- package/skills/app-compose-4-design-mock/SKILL.md +0 -256
- package/skills/app-compose-4-design-mock/references/component.md +0 -50
- package/skills/app-compose-4-design-mock/references/screen-detailview.md +0 -106
- package/skills/app-compose-4-design-mock/references/screen-form.md +0 -139
- package/skills/app-compose-4-design-mock/references/screen-listview.md +0 -153
- package/skills/app-compose-4-design-mock/references/structure.md +0 -27
- package/skills/app-compose-5-design-mock-review/SKILL.md +0 -290
- package/skills/app-compose-5-design-mock-review/references/component.md +0 -50
- package/skills/app-compose-5-design-mock-review/references/screen-detailview.md +0 -106
- package/skills/app-compose-5-design-mock-review/references/screen-form.md +0 -139
- package/skills/app-compose-5-design-mock-review/references/screen-listview.md +0 -153
- package/skills/app-compose-6-implementation-spec/references/auth.md +0 -72
- package/skills/app-compose-6-implementation-spec/references/structure.md +0 -27
- package/src/modules/primitives/lib/errors.ts +0 -138
- package/src/modules/user-management/lib/errors.ts +0 -81
- /package/skills/{2-module-feature-breakdown → erp-kit-module-4-tdd}/references/models.md +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Cross-Module Dependency
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Each module's `defineModule()` returns `{ db, commands, queries }`. Other modules can reference any of these through the return type. Use `import type` and relative paths — all modules live in the same package.
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import type { defineModule as definePrimitivesModule } from "../primitives";
|
|
9
|
+
|
|
10
|
+
type PrimitivesModule = ReturnType<typeof definePrimitivesModule>;
|
|
11
|
+
type PrimitivesDB = PrimitivesModule["db"];
|
|
12
|
+
type PrimitivesCommands = PrimitivesModule["commands"];
|
|
13
|
+
type PrimitivesQueries = PrimitivesModule["queries"];
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## DB Type Injection (`db/*.ts`)
|
|
17
|
+
|
|
18
|
+
Inject another module's DB type to create a foreign-key relation:
|
|
19
|
+
|
|
20
|
+
- Accept external type via `CreateTypeParams` as required param (e.g., `unitType: TailorAnyDBType`)
|
|
21
|
+
- Use it directly in `.relation()`:
|
|
22
|
+
- `db.uuid().relation({ type: "n-1", toward: { type: param }, backward: "..." })`
|
|
23
|
+
- Define stub types for cross-module dependencies in `lib/_db_deps.ts` (codegen only — replaced at runtime by `defineModule()` params):
|
|
24
|
+
```typescript
|
|
25
|
+
// lib/_db_deps.ts
|
|
26
|
+
import {
|
|
27
|
+
db,
|
|
28
|
+
unsafeAllowAllGqlPermission,
|
|
29
|
+
unsafeAllowAllTypePermission,
|
|
30
|
+
} from "@tailor-platform/sdk";
|
|
31
|
+
export const unit = db
|
|
32
|
+
.type("Unit", {})
|
|
33
|
+
.permission(unsafeAllowAllTypePermission)
|
|
34
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
35
|
+
```
|
|
36
|
+
- Import the stub and export a default instance at file bottom:
|
|
37
|
+
```typescript
|
|
38
|
+
// db/item.ts
|
|
39
|
+
import { unit as unitStub } from "../lib/_db_deps";
|
|
40
|
+
export const item = createItemType({ unitType: unitStub });
|
|
41
|
+
```
|
|
42
|
+
- Add `lib/_db_deps.ts` to `tailor.config.ts` files so codegen can resolve the type:
|
|
43
|
+
```typescript
|
|
44
|
+
db: { "main-db": { files: [`./db/*.ts`, `./lib/_db_deps.ts`] } }
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Command References
|
|
48
|
+
|
|
49
|
+
A module can accept another module's commands as a dependency and call them internally:
|
|
50
|
+
|
|
51
|
+
- Accept commands via `DefineModuleParams` as dependencies
|
|
52
|
+
- Derive the type from the source module's return type
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// Types
|
|
56
|
+
type ConvertQuantity = PrimitivesCommands["convertQuantity"];
|
|
57
|
+
|
|
58
|
+
// DefineModuleParams
|
|
59
|
+
export interface DefineModuleParams {
|
|
60
|
+
primitives: {
|
|
61
|
+
commands: {
|
|
62
|
+
convertQuantity: ConvertQuantity;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Usage in a command
|
|
68
|
+
const convertQuantity = params.primitives.commands.convertQuantity;
|
|
69
|
+
const result = await convertQuantity(db, input, ctx);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Query References
|
|
73
|
+
|
|
74
|
+
Same pattern as commands — accept queries via `DefineModuleParams`. See [CQRS read rule](../../erp-kit-module-shared/references/commands.md#command-side-reads-cqrs-separation) for when commands use injected queries vs inline reads.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
type ConvertAmount = PrimitivesQueries["convertAmount"];
|
|
78
|
+
|
|
79
|
+
export interface DefineModuleParams {
|
|
80
|
+
primitives: {
|
|
81
|
+
queries: {
|
|
82
|
+
convertAmount: ConvertAmount;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Module Wiring (`module.ts`)
|
|
89
|
+
|
|
90
|
+
Group all external dependencies (db, commands, queries) under a named key in `DefineModuleParams`:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
export interface DefineModuleParams<IF extends Record<string, TailorAnyDBField>> {
|
|
94
|
+
item?: CreateItemTypeParams<IF>;
|
|
95
|
+
primitives: {
|
|
96
|
+
db: { unit: PrimitivesDB["unit"] };
|
|
97
|
+
commands: { convertQuantity: PrimitivesCommands["convertQuantity"] };
|
|
98
|
+
queries: { convertAmount: PrimitivesQueries["convertAmount"] };
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const defineModule = <const IF extends Record<string, TailorAnyDBField> = EmptyFields>(
|
|
103
|
+
params: DefineModuleParams<IF>,
|
|
104
|
+
) => {
|
|
105
|
+
const item = createItemType({
|
|
106
|
+
...params.item,
|
|
107
|
+
unitType: params.primitives.db.unit,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
db: { item },
|
|
112
|
+
commands: {
|
|
113
|
+
createItem: makeCreateItem({
|
|
114
|
+
convertQuantity: params.primitives.commands.convertQuantity,
|
|
115
|
+
}),
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Permission Dependencies
|
|
122
|
+
|
|
123
|
+
Declare cross-module permission dependencies via `definePermissions`:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
export const { permissions, own, all } = definePermissions(
|
|
127
|
+
"itemManagement",
|
|
128
|
+
["createItem", "updateItem", ...] as const,
|
|
129
|
+
{ deps: primitivesPermissions.all },
|
|
130
|
+
);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The `all` export merges own permissions with dependency permissions, so consumers get a complete permission set.
|
package/skills/{4-module-tdd-implementation → erp-kit-module-4-tdd}/references/db-relations.md
RENAMED
|
@@ -14,7 +14,7 @@ userId: db.uuid().relation({
|
|
|
14
14
|
|
|
15
15
|
### Parameters
|
|
16
16
|
|
|
17
|
-
- `type`: `"n-1"` (many-to-one), `"1-1"` (one-to-one), or `"keyOnly"` (FK only, no navigation)
|
|
17
|
+
- `type`: `"n-1"` (many-to-one), `"1-1"` (one-to-one), or `"keyOnly"` (FK only, no navigation),`"self"` ( self-reference )
|
|
18
18
|
- `toward.type`: The related type definition (import it)
|
|
19
19
|
- `backward`: Field name for reverse navigation from the related type
|
|
20
20
|
|
|
@@ -25,6 +25,10 @@ userId: db.uuid().relation({
|
|
|
25
25
|
- Backward navigation: `User.userRoles`
|
|
26
26
|
- GraphQL relational queries
|
|
27
27
|
|
|
28
|
+
## Cross-Module Foreign Keys
|
|
29
|
+
|
|
30
|
+
When a FK references a type from another module, use the DB type injection pattern from [cross-module-dependency.md](cross-module-dependency.md#db-type-injection-srcdbts):
|
|
31
|
+
|
|
28
32
|
## Junction Tables (Many-to-Many)
|
|
29
33
|
|
|
30
34
|
Junction tables need relations on both foreign keys plus a composite unique index:
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Generated Code
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Run `erp-kit module generate code --root <modules-dir> <module-name>` to generate deterministic `.generated.ts` files from command and query documentation.
|
|
6
|
+
|
|
7
|
+
## What gets generated
|
|
8
|
+
|
|
9
|
+
- `lib/errors.generated.ts` — Domain error classes from Error Scenarios sections
|
|
10
|
+
- `lib/permissions.generated.ts` — Permission definitions from command doc filenames
|
|
11
|
+
- `command/<name>.generated.ts` — Command shells wiring permissions + `run` function
|
|
12
|
+
- `query/<name>.generated.ts` — Query shells wrapping `run` function
|
|
13
|
+
|
|
14
|
+
## File convention
|
|
15
|
+
|
|
16
|
+
- `.generated.ts` files are always overwritten — never edit them
|
|
17
|
+
- Custom logic goes in `.ts` files (same base name) that import from `.generated.ts`
|
|
18
|
+
|
|
19
|
+
## Workflow
|
|
20
|
+
|
|
21
|
+
1. Write command/query docs (skills 1-3)
|
|
22
|
+
2. Write db models (skill 4, step 2)
|
|
23
|
+
3. Run `pnpm generate` for kysely types
|
|
24
|
+
4. Run `erp-kit module generate code --root <root> <module>`
|
|
25
|
+
5. Implement business logic in `.ts` files importing from `.generated.ts`
|
|
26
|
+
|
|
27
|
+
## What you still write by hand
|
|
28
|
+
|
|
29
|
+
- Input interface field definitions (in `.generated.ts` they're stubs)
|
|
30
|
+
- Command handler business logic (validation, mutations, state transitions)
|
|
31
|
+
- Test assertions
|
|
32
|
+
- Complex queries beyond simple lookups
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
name:
|
|
2
|
+
name: erp-kit-module-5-impl-review
|
|
3
3
|
description: Review implementation parity between documentation and code. Use when validating that TDD implementation (step 4) matches model docs, command docs, and test coverage requirements.
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -12,19 +12,19 @@ Review **implementation consistency** between documentation and actual code.
|
|
|
12
12
|
Verify that TDD implementation (models, commands, tests) properly implements what's documented in model docs and command docs.
|
|
13
13
|
|
|
14
14
|
```
|
|
15
|
-
Model Docs (Schema) →
|
|
15
|
+
Model Docs (Schema) →db/*.ts (Implementation)
|
|
16
16
|
↓ ↓
|
|
17
17
|
Fields createEntityType()
|
|
18
18
|
Relationships Foreign keys
|
|
19
19
|
State Transitions Status enums
|
|
20
20
|
|
|
21
|
-
Command Docs (Spec) →
|
|
21
|
+
Command Docs (Spec) →command/*.ts (Implementation)
|
|
22
22
|
↓ ↓
|
|
23
23
|
Business Rules Validation logic
|
|
24
24
|
Error Scenarios Error classes
|
|
25
25
|
Process Flows Branching logic
|
|
26
26
|
|
|
27
|
-
Command Docs (Spec) →
|
|
27
|
+
Command Docs (Spec) →command/*.test.ts (Tests)
|
|
28
28
|
↓ ↓
|
|
29
29
|
Process Flow branches Test cases
|
|
30
30
|
Error scenarios Error assertions
|
|
@@ -66,7 +66,7 @@ Extract for each model:
|
|
|
66
66
|
Read ALL model files:
|
|
67
67
|
|
|
68
68
|
```
|
|
69
|
-
modules/<module-name>/
|
|
69
|
+
modules/<module-name>/db/*.ts
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
Extract for each model:
|
|
@@ -96,28 +96,28 @@ Extract for each command:
|
|
|
96
96
|
Read ALL command files:
|
|
97
97
|
|
|
98
98
|
```
|
|
99
|
-
modules/<module-name>/
|
|
99
|
+
modules/<module-name>/command/*.ts
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
Extract for each command:
|
|
103
103
|
|
|
104
104
|
- Validation logic implemented
|
|
105
|
-
- Error classes
|
|
105
|
+
- Error classes returned via Result
|
|
106
106
|
- Branching paths (if/else, early returns)
|
|
107
107
|
- Input interface fields
|
|
108
108
|
- Return type structure
|
|
109
109
|
|
|
110
110
|
### 5. Read Error Implementation
|
|
111
111
|
|
|
112
|
-
Read error definitions:
|
|
112
|
+
Read generated error definitions:
|
|
113
113
|
|
|
114
114
|
```
|
|
115
|
-
modules/<module-name>/
|
|
115
|
+
modules/<module-name>/lib/errors.generated.ts
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
Extract:
|
|
119
119
|
|
|
120
|
-
- Error class names
|
|
120
|
+
- Error class names (generated from doc error codes)
|
|
121
121
|
- Error codes
|
|
122
122
|
- Error message patterns
|
|
123
123
|
|
|
@@ -126,7 +126,7 @@ Extract:
|
|
|
126
126
|
Read ALL test files:
|
|
127
127
|
|
|
128
128
|
```
|
|
129
|
-
modules/<module-name>/
|
|
129
|
+
modules/<module-name>/command/*.test.ts
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
Extract for each command:
|
|
@@ -149,15 +149,15 @@ Extract for each command:
|
|
|
149
149
|
|
|
150
150
|
### 8. Command Doc → Command Code Parity Check
|
|
151
151
|
|
|
152
|
-
| Check Item | Question
|
|
153
|
-
| ----------------------- |
|
|
154
|
-
| Business rule impl | Is each documented business rule implemented in code?
|
|
155
|
-
| Error scenario coverage | Does code
|
|
156
|
-
| Error code accuracy | Do error codes in code match documented codes?
|
|
157
|
-
| Process flow alignment | Do code branches match documented process flow?
|
|
158
|
-
| Input type coverage | Does input interface include all documented inputs?
|
|
159
|
-
| Return type accuracy | Does return type match documented output?
|
|
160
|
-
|
|
|
152
|
+
| Check Item | Question |
|
|
153
|
+
| ----------------------- | ----------------------------------------------------------- |
|
|
154
|
+
| Business rule impl | Is each documented business rule implemented in code? |
|
|
155
|
+
| Error scenario coverage | Does code return errors for all documented error scenarios? |
|
|
156
|
+
| Error code accuracy | Do error codes in code match documented codes? |
|
|
157
|
+
| Process flow alignment | Do code branches match documented process flow? |
|
|
158
|
+
| Input type coverage | Does input interface include all documented inputs? |
|
|
159
|
+
| Return type accuracy | Does return type match documented output? |
|
|
160
|
+
| Generated shell pattern | Does command export `run` with a `.generated.ts` shell? |
|
|
161
161
|
|
|
162
162
|
### 9. Command Doc → Test Coverage Check
|
|
163
163
|
|
|
@@ -206,11 +206,11 @@ Extract for each command:
|
|
|
206
206
|
|
|
207
207
|
### 4. Error Scenario Implementation
|
|
208
208
|
|
|
209
|
-
| Command Doc | Error Code |
|
|
210
|
-
| ----------- | ---------------- |
|
|
211
|
-
| <cmd-a> | ENTITY_NOT_FOUND | ✅ EntityNotFoundError
|
|
212
|
-
| <cmd-a> | INVALID_STATE | ❌ Not defined
|
|
213
|
-
| <cmd-b> | DUPLICATE_ENTRY | ✅ DuplicateEntryError
|
|
209
|
+
| Command Doc | Error Code | Generated in errors.generated.ts | Returned in command | Test assertion |
|
|
210
|
+
| ----------- | ---------------- | -------------------------------- | ------------------- | -------------- |
|
|
211
|
+
| <cmd-a> | ENTITY_NOT_FOUND | ✅ EntityNotFoundError | ✅ | ✅ |
|
|
212
|
+
| <cmd-a> | INVALID_STATE | ❌ Not defined | ❌ | ❌ |
|
|
213
|
+
| <cmd-b> | DUPLICATE_ENTRY | ✅ DuplicateEntryError | ✅ | ❌ No test |
|
|
214
214
|
|
|
215
215
|
---
|
|
216
216
|
|
|
@@ -225,10 +225,10 @@ Extract for each command:
|
|
|
225
225
|
|
|
226
226
|
### 6. Implementation Pattern Compliance
|
|
227
227
|
|
|
228
|
-
| Command |
|
|
229
|
-
| ------- |
|
|
230
|
-
| <cmd-a> | ✅ `
|
|
231
|
-
| <cmd-b> | ❌
|
|
228
|
+
| Command | Generated Shell | Input Interface Exported | JSDoc Present |
|
|
229
|
+
| ------- | ------------------------- | ------------------------ | ------------- |
|
|
230
|
+
| <cmd-a> | ✅ `.generated.ts` exists | ✅ | ✅ |
|
|
231
|
+
| <cmd-b> | ❌ Missing shell | ✅ | ❌ |
|
|
232
232
|
|
|
233
233
|
---
|
|
234
234
|
|
|
@@ -258,7 +258,7 @@ Extract for each command:
|
|
|
258
258
|
| Command Doc | Missing Test Case | Doc Reference |
|
|
259
259
|
| ----------- | -------------------------------- | --------------------- |
|
|
260
260
|
| <cmd-b> | "entity already exists → return" | Process flow branch 2 |
|
|
261
|
-
| <cmd-b> | "
|
|
261
|
+
| <cmd-b> | "returns DUPLICATE_ENTRY" | Error scenario 3 |
|
|
262
262
|
|
|
263
263
|
---
|
|
264
264
|
|
|
@@ -278,9 +278,9 @@ Extract for each command:
|
|
|
278
278
|
| ----------------------------- | ------ | --------------------------------- |
|
|
279
279
|
| Model Doc → Code Coverage | ⚠️ | X/Y models fully implemented |
|
|
280
280
|
| Command Doc → Code Coverage | ⚠️ | X/Y commands fully implemented |
|
|
281
|
-
| Error Scenario Implementation | ❌ | X/Y errors defined and
|
|
281
|
+
| Error Scenario Implementation | ❌ | X/Y errors defined and returned |
|
|
282
282
|
| Test Coverage | ⚠️ | X/Y process branches have tests |
|
|
283
|
-
| Pattern Compliance | ✅ | All commands
|
|
283
|
+
| Pattern Compliance | ✅ | All commands use generated shells |
|
|
284
284
|
|
|
285
285
|
### 10. Recommendations
|
|
286
286
|
|
|
@@ -294,7 +294,7 @@ Extract for each command:
|
|
|
294
294
|
- cmd-b: add validation for "X must be unique"
|
|
295
295
|
|
|
296
296
|
4. **Define missing error classes:**
|
|
297
|
-
- Add `
|
|
297
|
+
- Add `INVALID_STATE` error scenario to command doc + re-run `erp-kit module generate code`
|
|
298
298
|
|
|
299
299
|
5. **Add missing test cases:**
|
|
300
300
|
- cmd-b: test "entity already exists → return existing"
|
|
@@ -317,10 +317,10 @@ Extract for each command:
|
|
|
317
317
|
### Command Doc → Command Code
|
|
318
318
|
|
|
319
319
|
- **Unimplemented business rules**: Rule in doc but no validation code
|
|
320
|
-
- **Missing error
|
|
320
|
+
- **Missing error returns**: Error scenario documented but not returned
|
|
321
321
|
- **Wrong error codes**: Code and doc use different error codes
|
|
322
322
|
- **Missing process branches**: Flowchart branch not in code logic
|
|
323
|
-
- **Missing
|
|
323
|
+
- **Missing generated shell**: No `.generated.ts` file for command
|
|
324
324
|
|
|
325
325
|
### Command Doc → Tests
|
|
326
326
|
|
|
@@ -360,9 +360,9 @@ PENDING → ACTIVE → REMOVED
|
|
|
360
360
|
## Error Scenarios
|
|
361
361
|
|
|
362
362
|
| Code | Condition |
|
|
363
|
-
| -------------- | -------------- |
|
|
364
|
-
| NOT_FOUND | Entity missing | → Check: error class +
|
|
365
|
-
| INVALID_STATUS | Wrong status | → Check: error class +
|
|
363
|
+
| -------------- | -------------- | ------------------------------------------ |
|
|
364
|
+
| NOT_FOUND | Entity missing | → Check: error class + return err() + test |
|
|
365
|
+
| INVALID_STATUS | Wrong status | → Check: error class + return err() + test |
|
|
366
366
|
|
|
367
367
|
## Process Flow (mermaid)
|
|
368
368
|
|
|
@@ -384,25 +384,27 @@ export function createEntityType(params) {
|
|
|
384
384
|
};
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
// Command: check business rules
|
|
388
|
-
export async function
|
|
387
|
+
// Command: check business rules (run function pattern)
|
|
388
|
+
export async function run(db, input, ctx) {
|
|
389
389
|
// Check: validation for each business rule
|
|
390
|
-
if (!entity)
|
|
390
|
+
if (!entity) return err(new EntityNotFoundError()); // Check: matches doc error
|
|
391
391
|
// Check: each branch matches process flow
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
+
// Generated shell: check it exists
|
|
395
|
+
// myCommand.generated.ts
|
|
396
|
+
export const myCommand = defineCommand(permissions.myCommand, run);
|
|
397
|
+
|
|
394
398
|
// Test: check coverage
|
|
395
399
|
describe("myCommand", () => {
|
|
396
400
|
it("creates entity when valid"); // Check: happy path
|
|
397
401
|
it("returns existing if found"); // Check: idempotent path
|
|
398
|
-
it("
|
|
402
|
+
it("returns NOT_FOUND when missing"); // Check: error scenario
|
|
399
403
|
});
|
|
400
404
|
```
|
|
401
405
|
|
|
402
406
|
## References
|
|
403
407
|
|
|
404
|
-
- [Model patterns](references/models.md)
|
|
405
408
|
- [Command patterns](references/commands.md)
|
|
406
409
|
- [Error patterns](references/errors.md)
|
|
407
410
|
- [Testing patterns](references/testing.md)
|
|
408
|
-
- [Export order](references/exports.md)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Command Implementation
|
|
2
|
+
|
|
3
|
+
## Unified Pattern: `run` + generated shell
|
|
4
|
+
|
|
5
|
+
All commands follow the same pattern — export a `run` function, and the generated shell wraps it with `defineCommand`:
|
|
6
|
+
|
|
7
|
+
**Implementation file** (`command/myCommand.ts`):
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
export async function run(db: DB, input: MyCommandInput, ctx: CommandContext) {
|
|
11
|
+
// validate → query → mutate
|
|
12
|
+
return ok({ entity });
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Generated shell** (`command/myCommand.generated.ts`):
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
export const myCommand = defineCommand(permissions.myCommand, run);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Custom Fields (generic CF)
|
|
23
|
+
|
|
24
|
+
Commands that **write** (insert or update) into a table with user-extensible fields make `run` generic:
|
|
25
|
+
|
|
26
|
+
- Generic `CF extends Record<string, unknown>` on the `run` function
|
|
27
|
+
- Input type: `CreateXInput & CF` or `UpdateXInput & Partial<CF>`
|
|
28
|
+
- Destructure known fields, rest-spread custom fields
|
|
29
|
+
- Cast custom fields: `...(customFields as Record<string, unknown>)`
|
|
30
|
+
- module.ts locks CF via instantiation expression: `const createXTyped = createX<FieldsToInsertable<F>>;`
|
|
31
|
+
|
|
32
|
+
### Rule: when to use generic CF
|
|
33
|
+
|
|
34
|
+
> If a model uses `fields?: F` for custom fields, **every command that writes those fields** must have a generic `CF`. This includes create, update, and any other write command. The determining factor is whether the command writes to a table with custom fields, not just whether it inserts new rows.
|
|
35
|
+
|
|
36
|
+
## Implementation Considerations
|
|
37
|
+
|
|
38
|
+
- **Validation**: Check referenced entities exist before operating
|
|
39
|
+
- **Idempotency**: For assign/revoke, return existing instead of throwing
|
|
40
|
+
- **Return format**: Wrap in object `{ entity }` not just `entity`
|
|
41
|
+
|
|
42
|
+
## Conventions
|
|
43
|
+
|
|
44
|
+
- Input types: exported interfaces (`export interface MyFunctionInput`)
|
|
45
|
+
- Use `.executeTakeFirst()` for single results
|
|
46
|
+
- Include JSDoc: `/** Function: name \n Description */`
|
|
47
|
+
|
|
48
|
+
## State Transitions
|
|
49
|
+
|
|
50
|
+
For commands that transition between statuses, accept `from?: string[]` with a default:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
from?: string[]; // Default: ["ACTIVE"]
|
|
54
|
+
|
|
55
|
+
const validFromStatuses = input.from ?? ["ACTIVE"];
|
|
56
|
+
if (!validFromStatuses.includes(user.status)) {
|
|
57
|
+
return err(new InvalidStatusTransitionError(user.status, targetStatus));
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- Default `from` contains the base valid source status
|
|
62
|
+
- Parent modules can override to allow transitions from additional statuses
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Error Classes
|
|
2
|
+
|
|
3
|
+
Errors are **generated** from command/query documentation into `lib/errors.generated.ts`.
|
|
4
|
+
|
|
5
|
+
## What to review
|
|
6
|
+
|
|
7
|
+
- Every error code in `docs/commands/*.md` has a corresponding class in `lib/errors.generated.ts`
|
|
8
|
+
- Command implementations import errors from `../lib/errors.generated`
|
|
9
|
+
- Error codes in code match documented codes exactly
|
|
10
|
+
- If errors are missing, re-run `erp-kit module generate code`
|
package/skills/{5-module-implementation-review → erp-kit-module-5-impl-review}/references/testing.md
RENAMED
|
@@ -20,7 +20,7 @@ spies.select.mockReturnValue(entity);
|
|
|
20
20
|
spies.select.mockReturnValueOnce(first).mockReturnValueOnce(second);
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
## Fixtures (`
|
|
23
|
+
## Fixtures (`testing/fixtures.ts`)
|
|
24
24
|
|
|
25
25
|
- Import `Schema` from `lib/types` (not `Namespace` from generated code)
|
|
26
26
|
- Pattern: `export const baseEntity = { ... } as const satisfies Entity<Schema>`
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: erp-kit-module-shared
|
|
3
|
+
description: Shared references for erp-kit module skills. Not invoked directly — referenced by erp-kit-module-1 through erp-kit-module-5.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# erp-kit-module-shared
|
|
7
|
+
|
|
8
|
+
Canonical reference files shared across module skills. Individual skills reference these instead of maintaining their own copies.
|
|
9
|
+
|
|
10
|
+
## References
|
|
11
|
+
|
|
12
|
+
- [Module structure](references/structure.md)
|
|
13
|
+
- [Command patterns](references/commands.md)
|
|
14
|
+
- [Query patterns](references/queries.md)
|
|
15
|
+
- [Error patterns](references/errors.md)
|
|
16
|
+
- [Testing patterns](references/testing.md)
|