@open-mercato/core 0.5.1-develop.2972.6c5cd4a1c3 → 0.5.1-develop.2987.9f8c1e0f68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +15 -1
- package/jest.setup.ts +6 -0
- package/package.json +3 -3
- package/src/modules/customers/AGENTS.md +10 -0
package/AGENTS.md
CHANGED
|
@@ -122,6 +122,19 @@ Follow the customers module API patterns (CRUD factory + query engine):
|
|
|
122
122
|
- Set `indexer: { entityType }` in `makeCrudRoute`
|
|
123
123
|
- Reference: `src/modules/customers/api/people/route.ts`
|
|
124
124
|
|
|
125
|
+
### Entity Schema And Migration Workflow
|
|
126
|
+
|
|
127
|
+
When adding or changing a MikroORM entity, coding agents MUST read this section, the customers reference module guide, and `packages/cli/AGENTS.md` before editing.
|
|
128
|
+
|
|
129
|
+
1. Update `data/entities.ts` using MikroORM v7 imports: decorators from `@mikro-orm/decorators/legacy`, types from `@mikro-orm/core`.
|
|
130
|
+
2. Run `yarn generate` when module structure or entity discovery changed.
|
|
131
|
+
3. Treat `yarn db:generate` as a schema-diff probe. Review every generated file before keeping it.
|
|
132
|
+
4. Keep only SQL for the intended module/entity change. If the generator emits unrelated migrations because another module's snapshot is stale, remove those files from the diff instead of committing them.
|
|
133
|
+
5. If you author a scoped SQL migration yourself to avoid unrelated generated churn, base it on the entity metadata and existing module migration style, then update that module's `migrations/.snapshot-open-mercato.json` to the post-change schema in the same commit.
|
|
134
|
+
6. Do not run `yarn db:migrate` unless the user explicitly asks to apply migrations. PRs should normally contain the migration file and snapshot, not local DB state.
|
|
135
|
+
|
|
136
|
+
For new CRUD modules, use `packages/core/src/modules/customers/AGENTS.md` as the file-structure reference and copy the command/API patterns before inventing new ones.
|
|
137
|
+
|
|
125
138
|
## Module Setup Convention
|
|
126
139
|
|
|
127
140
|
Every module participating in tenant initialization must declare `setup.ts`. The generator auto-discovers these files.
|
|
@@ -463,7 +476,8 @@ await emitCrudSideEffects({ ... })
|
|
|
463
476
|
- Module-scoped with MikroORM: files live in `src/modules/<module>/migrations/`
|
|
464
477
|
- Generate: `yarn db:generate` (iterates all modules)
|
|
465
478
|
- Apply: `yarn db:migrate` (ordered, directory first)
|
|
466
|
-
-
|
|
479
|
+
- Default: update ORM entities and let `yarn db:generate` emit SQL.
|
|
480
|
+
- Exception: when generated output includes unrelated snapshot drift, keep or write only the intended SQL and update that module's `.snapshot-open-mercato.json` in the same change.
|
|
467
481
|
|
|
468
482
|
## Database Entities
|
|
469
483
|
|
package/jest.setup.ts
CHANGED
|
@@ -26,6 +26,12 @@ class MockResponse {
|
|
|
26
26
|
async text() {
|
|
27
27
|
return this.body
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
clone() {
|
|
31
|
+
const cloned = new MockResponse(this.body, { status: this.status })
|
|
32
|
+
cloned.headers = new Map(this.headers)
|
|
33
|
+
return cloned
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
if (typeof globalThis.Response === 'undefined') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/core",
|
|
3
|
-
"version": "0.5.1-develop.
|
|
3
|
+
"version": "0.5.1-develop.2987.9f8c1e0f68",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -237,10 +237,10 @@
|
|
|
237
237
|
"ts-pattern": "^5.0.0"
|
|
238
238
|
},
|
|
239
239
|
"peerDependencies": {
|
|
240
|
-
"@open-mercato/shared": "0.5.1-develop.
|
|
240
|
+
"@open-mercato/shared": "0.5.1-develop.2987.9f8c1e0f68"
|
|
241
241
|
},
|
|
242
242
|
"devDependencies": {
|
|
243
|
-
"@open-mercato/shared": "0.5.1-develop.
|
|
243
|
+
"@open-mercato/shared": "0.5.1-develop.2987.9f8c1e0f68",
|
|
244
244
|
"@testing-library/dom": "^10.4.1",
|
|
245
245
|
"@testing-library/jest-dom": "^6.9.1",
|
|
246
246
|
"@testing-library/react": "^16.3.1",
|
|
@@ -39,6 +39,16 @@
|
|
|
39
39
|
- **Comments** — notes on records. MUST reference the parent entity
|
|
40
40
|
- **Addresses** — multi-address support. MUST link to person or company via FK
|
|
41
41
|
|
|
42
|
+
## New Entity Checklist For Agents
|
|
43
|
+
|
|
44
|
+
When creating a new entity or CRUD slice, copy the customers module structure first, then align with `packages/core/AGENTS.md` and `packages/cli/AGENTS.md`.
|
|
45
|
+
|
|
46
|
+
1. Define MikroORM v7 entities in `data/entities.ts` with decorators imported from `@mikro-orm/decorators/legacy`.
|
|
47
|
+
2. Use UUID primary keys, snake_case table/column names, `organization_id`, `tenant_id`, and standard timestamp/soft-delete columns.
|
|
48
|
+
3. Add validators, commands, CRUD route, backend pages, ACL, setup grants, events, search, and translations as applicable.
|
|
49
|
+
4. Generate or author the migration for only this entity change, then update the module's `migrations/.snapshot-open-mercato.json`.
|
|
50
|
+
5. Run `yarn db:generate` again as a no-op check; expected output for the touched module is `no changes`.
|
|
51
|
+
|
|
42
52
|
## CRUD API Pattern
|
|
43
53
|
|
|
44
54
|
The CRUD factory API route (`api/people/route.ts`) demonstrates:
|