@compilr-dev/factory 0.1.4 → 0.1.7
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/LICENSE +108 -0
- package/README.md +124 -45
- package/dist/toolkits/react-node/api.js +102 -16
- package/dist/toolkits/react-node/config.d.ts +4 -0
- package/dist/toolkits/react-node/config.js +90 -3
- package/dist/toolkits/react-node/entity.js +72 -22
- package/dist/toolkits/react-node/seed.js +7 -0
- package/dist/toolkits/react-node/types-gen.js +29 -0
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
Abbreviation: FSL-1.1-MIT
|
|
4
|
+
|
|
5
|
+
Notice
|
|
6
|
+
|
|
7
|
+
Copyright 2026 Carmelo Scozzola
|
|
8
|
+
|
|
9
|
+
Terms and Conditions
|
|
10
|
+
|
|
11
|
+
Licensor ("We")
|
|
12
|
+
|
|
13
|
+
The party offering the Software under these Terms and Conditions.
|
|
14
|
+
|
|
15
|
+
The Software
|
|
16
|
+
|
|
17
|
+
The "Software" is each version of the software that we make available under
|
|
18
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
19
|
+
Conditions with the Software.
|
|
20
|
+
|
|
21
|
+
License Grant
|
|
22
|
+
|
|
23
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
24
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
25
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
26
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
27
|
+
|
|
28
|
+
Permitted Purpose
|
|
29
|
+
|
|
30
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
31
|
+
means making the Software available to others in a commercial product or
|
|
32
|
+
service that:
|
|
33
|
+
|
|
34
|
+
1. substitutes for the Software;
|
|
35
|
+
|
|
36
|
+
2. substitutes for any other product or service we offer using the Software
|
|
37
|
+
that exists as of the date we make the Software available; or
|
|
38
|
+
|
|
39
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
40
|
+
|
|
41
|
+
Permitted Purposes specifically include using the Software:
|
|
42
|
+
|
|
43
|
+
1. for your internal use and access;
|
|
44
|
+
|
|
45
|
+
2. for non-commercial education;
|
|
46
|
+
|
|
47
|
+
3. for non-commercial research; and
|
|
48
|
+
|
|
49
|
+
4. in connection with professional services that you provide to a licensee
|
|
50
|
+
using the Software in accordance with these Terms and Conditions.
|
|
51
|
+
|
|
52
|
+
Patents
|
|
53
|
+
|
|
54
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
55
|
+
patents, the license grant above includes a license under our patents. If you
|
|
56
|
+
make a claim against any party that the Software infringes or contributes to
|
|
57
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
58
|
+
immediately.
|
|
59
|
+
|
|
60
|
+
Redistribution
|
|
61
|
+
|
|
62
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
63
|
+
the Software.
|
|
64
|
+
|
|
65
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
66
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
67
|
+
remove any copyright notices provided in or with the Software.
|
|
68
|
+
|
|
69
|
+
Disclaimer
|
|
70
|
+
|
|
71
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
72
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
73
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
74
|
+
|
|
75
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
76
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
77
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
78
|
+
|
|
79
|
+
Trademarks
|
|
80
|
+
|
|
81
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
82
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
83
|
+
trademarks, trade names, service marks or product names.
|
|
84
|
+
|
|
85
|
+
Grant of Future License
|
|
86
|
+
|
|
87
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
88
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
89
|
+
the Software available. On or after that date, you may use the Software under
|
|
90
|
+
the MIT license, in which case the following will apply:
|
|
91
|
+
|
|
92
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
93
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
94
|
+
the Software without restriction, including without limitation the rights to
|
|
95
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
96
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
97
|
+
so, subject to the following conditions:
|
|
98
|
+
|
|
99
|
+
The above copyright notice and this permission notice shall be included in all
|
|
100
|
+
copies or substantial portions of the Software.
|
|
101
|
+
|
|
102
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
103
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
104
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
105
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
106
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
107
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
108
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,23 +1,40 @@
|
|
|
1
1
|
# @compilr-dev/factory
|
|
2
2
|
|
|
3
|
-
AI-driven application scaffolder for the compilr-dev ecosystem. Generates working full-stack MVPs from an Application Model — a declarative description of what an app is (entities, fields, relationships, layout, features).
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
3
|
```
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
\|/
|
|
5
|
+
╭══════════╮ ___ ___ _ __ ___ _ __ (_) |_ __
|
|
6
|
+
║' ▐▌ ▐▌ │ / __|/ _ \| '_ ` _ \| '_ \| | | '__|
|
|
7
|
+
║ │ | (__| (_) | | | | | | |_) | | | |
|
|
8
|
+
╰─═──────═─╯ \___|\___/|_| |_| |_| .__/|_|_|_|
|
|
9
|
+
\________\ | | .dev
|
|
10
|
+
|_| factory
|
|
10
11
|
```
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
> AI-driven application scaffolder — from declarative model to working full-stack MVP
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
[](https://www.npmjs.com/package/@compilr-dev/factory)
|
|
16
|
+
[](https://fsl.software/)
|
|
17
|
+
|
|
18
|
+
> [!WARNING]
|
|
19
|
+
> This package is in beta. APIs may change between minor versions.
|
|
20
|
+
|
|
21
|
+
## Overview
|
|
22
|
+
|
|
23
|
+
The factory takes an **Application Model** — a declarative description of what an app is (entities, fields, relationships, layout, features, theme) — and generates a complete, working full-stack project. It provides tools and skills that let AI agents design and scaffold applications through conversation.
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- **Application Model** — declarative schema for entities, fields, relationships, layout, theme
|
|
28
|
+
- **Semantic Operations** — type-safe mutations (addEntity, updateField, addRelationship, etc.)
|
|
29
|
+
- **Optimistic Locking** — revision counter prevents lost updates
|
|
30
|
+
- **Auto-Inverse Relationships** — adding `belongsTo` auto-creates `hasMany` on target
|
|
31
|
+
- **Cascading Operations** — renaming an entity updates all relationship targets
|
|
32
|
+
- **Validation** — comprehensive model health checks with actionable error messages
|
|
33
|
+
- **Toolkit Registry** — extensible generator system (React+Node built-in)
|
|
34
|
+
- **5 Agent Tools** — model CRUD, validation, scaffolding, toolkit listing
|
|
35
|
+
- **1 Skill** — guided scaffolding workflow for AI agents
|
|
36
|
+
- **Full Color Palette** — auto-generates 50–950 Tailwind shades from single hex
|
|
37
|
+
- **Implicit Timestamps** — `createdAt`/`updatedAt` on all entity records
|
|
21
38
|
|
|
22
39
|
## Installation
|
|
23
40
|
|
|
@@ -25,31 +42,28 @@ The factory provides **5 tools** (via MetaToolsRegistry) and **1 skill**:
|
|
|
25
42
|
npm install @compilr-dev/factory
|
|
26
43
|
```
|
|
27
44
|
|
|
28
|
-
Peer dependency:
|
|
45
|
+
Peer dependency:
|
|
29
46
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
import { createModelTools } from '@compilr-dev/factory';
|
|
34
|
-
import type { PlatformContext } from '@compilr-dev/sdk';
|
|
47
|
+
```bash
|
|
48
|
+
npm install @compilr-dev/sdk
|
|
49
|
+
```
|
|
35
50
|
|
|
36
|
-
|
|
37
|
-
const tools = createModelTools({
|
|
38
|
-
context: platformContext, // PlatformContext with documents repo
|
|
39
|
-
});
|
|
51
|
+
## Quick Start
|
|
40
52
|
|
|
41
|
-
|
|
53
|
+
```typescript
|
|
42
54
|
import {
|
|
43
55
|
createDefaultModel,
|
|
44
|
-
createDefaultEntity,
|
|
45
56
|
applyOperation,
|
|
46
57
|
validateModel,
|
|
47
58
|
} from '@compilr-dev/factory';
|
|
48
59
|
|
|
60
|
+
// Define your application
|
|
49
61
|
const model = createDefaultModel({
|
|
50
62
|
identity: { name: 'Restaurant Manager', description: 'Manage reservations', version: '1.0.0' },
|
|
63
|
+
theme: { primaryColor: '#E65100' },
|
|
51
64
|
});
|
|
52
65
|
|
|
66
|
+
// Add entities through semantic operations
|
|
53
67
|
const updated = applyOperation(model, {
|
|
54
68
|
op: 'addEntity',
|
|
55
69
|
entity: {
|
|
@@ -66,10 +80,34 @@ const updated = applyOperation(model, {
|
|
|
66
80
|
},
|
|
67
81
|
});
|
|
68
82
|
|
|
83
|
+
// Validate
|
|
69
84
|
const result = validateModel(updated);
|
|
70
85
|
// { valid: true, errors: [] }
|
|
71
86
|
```
|
|
72
87
|
|
|
88
|
+
### Agent Tools
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { createModelTools, createFactoryTools } from '@compilr-dev/factory';
|
|
92
|
+
import type { PlatformContext } from '@compilr-dev/sdk';
|
|
93
|
+
|
|
94
|
+
// 3 model tools (get, update, validate)
|
|
95
|
+
const modelTools = createModelTools({ context: platformContext });
|
|
96
|
+
|
|
97
|
+
// 2 factory tools (scaffold, list-toolkits)
|
|
98
|
+
const factoryTools = createFactoryTools({ context: platformContext });
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Agent Tools Reference
|
|
102
|
+
|
|
103
|
+
| Tool | Purpose |
|
|
104
|
+
|------|---------|
|
|
105
|
+
| `app_model_get` | Scoped reads of the Application Model (summary, entities, identity, etc.) |
|
|
106
|
+
| `app_model_update` | Semantic operations with optimistic locking |
|
|
107
|
+
| `app_model_validate` | Check model health and get actionable errors |
|
|
108
|
+
| `factory_scaffold` | Generate files from model + toolkit |
|
|
109
|
+
| `factory_list_toolkits` | List available toolkits with descriptions |
|
|
110
|
+
|
|
73
111
|
## Application Model
|
|
74
112
|
|
|
75
113
|
The model describes **what** an application is, independently of how it's built:
|
|
@@ -87,45 +125,86 @@ ApplicationModel
|
|
|
87
125
|
|
|
88
126
|
### Semantic Operations
|
|
89
127
|
|
|
90
|
-
|
|
128
|
+
All model changes go through typed operations — never raw JSON editing:
|
|
91
129
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
**
|
|
95
|
-
**
|
|
130
|
+
| Category | Operations |
|
|
131
|
+
|----------|------------|
|
|
132
|
+
| **Entity** | addEntity, updateEntity, removeEntity, renameEntity, reorderEntities |
|
|
133
|
+
| **Field** | addField, updateField, removeField, renameField |
|
|
134
|
+
| **Relationship** | addRelationship, removeRelationship (with auto-inverse) |
|
|
135
|
+
| **Section** | updateIdentity, updateLayout, updateFeatures, updateTheme, updateTechStack |
|
|
96
136
|
|
|
97
137
|
Every operation follows: **READ → CHECK → APPLY → VALIDATE → WRITE**.
|
|
98
138
|
|
|
99
|
-
### Key
|
|
139
|
+
### Key Design Choices
|
|
100
140
|
|
|
101
141
|
- **Name-based addressing** — `entity: "Reservation"`, not `entities[2]`
|
|
102
142
|
- **Optimistic locking** — revision counter prevents lost updates
|
|
103
143
|
- **Auto-inverse relationships** — adding `belongsTo` auto-adds `hasMany` on target
|
|
104
|
-
- **Cascading
|
|
144
|
+
- **Cascading renames** — renaming an entity updates all FK references
|
|
105
145
|
- **Scoped reads** — `app_model_get({ scope: "summary" })` for lightweight overview
|
|
106
146
|
|
|
147
|
+
## Toolkits
|
|
148
|
+
|
|
149
|
+
### React + Node (`react-node`)
|
|
150
|
+
|
|
151
|
+
Generates a complete full-stack application:
|
|
152
|
+
|
|
153
|
+
| Category | Generated Files |
|
|
154
|
+
|----------|----------------|
|
|
155
|
+
| **Config** | package.json, vite.config.ts, tailwind.config.js, tsconfig.json, postcss.config.js |
|
|
156
|
+
| **Server** | Express API with CRUD routes, in-memory data stores, seed data |
|
|
157
|
+
| **Pages** | List (card + table views), Detail, Dashboard |
|
|
158
|
+
| **Components** | Cards, Forms, SearchBar, ViewToggle, FilterBar, DarkModeToggle |
|
|
159
|
+
| **Routing** | React Router with nested layouts |
|
|
160
|
+
| **Shell** | Sidebar + header layout, responsive navigation |
|
|
161
|
+
| **Static** | index.html, global CSS, favicon |
|
|
162
|
+
|
|
163
|
+
**Highlights:**
|
|
164
|
+
- `@tailwindcss/forms` plugin included
|
|
165
|
+
- Full primary color palette (50–950 shades) auto-generated from theme
|
|
166
|
+
- Implicit `createdAt`/`updatedAt` timestamps on all entities
|
|
167
|
+
- Enum fields get filter bars on list pages
|
|
168
|
+
- `belongsTo` relationships get populated API responses and form dropdowns
|
|
169
|
+
- `hasMany` relationships shown as linked lists on detail pages
|
|
170
|
+
- Deterministic seed data (8 items per entity with realistic values)
|
|
171
|
+
|
|
107
172
|
## Development
|
|
108
173
|
|
|
109
174
|
```bash
|
|
110
175
|
npm run build # Compile TypeScript
|
|
111
176
|
npm run lint # ESLint (strict, 0 errors required)
|
|
112
177
|
npm run format:check # Prettier check
|
|
113
|
-
npm test -- --run # Run
|
|
178
|
+
npm test -- --run # Run 290 tests
|
|
114
179
|
npm run typecheck # Type-check without emitting
|
|
115
180
|
```
|
|
116
181
|
|
|
117
|
-
##
|
|
182
|
+
## Requirements
|
|
183
|
+
|
|
184
|
+
- **Node.js** 18 or higher
|
|
185
|
+
- **@compilr-dev/sdk** ^0.1.12 (peer dependency)
|
|
118
186
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
|
122
|
-
|
|
123
|
-
|
|
|
124
|
-
|
|
|
125
|
-
|
|
|
126
|
-
|
|
|
127
|
-
|
|
187
|
+
## Related Packages
|
|
188
|
+
|
|
189
|
+
| Package | Description |
|
|
190
|
+
|---------|-------------|
|
|
191
|
+
| [@compilr-dev/sdk](https://www.npmjs.com/package/@compilr-dev/sdk) | Universal agent runtime |
|
|
192
|
+
| [@compilr-dev/agents](https://www.npmjs.com/package/@compilr-dev/agents) | Multi-LLM agent library |
|
|
193
|
+
| [@compilr-dev/agents-coding](https://www.npmjs.com/package/@compilr-dev/agents-coding) | Coding-specific tools and language analysis |
|
|
194
|
+
| [@compilr-dev/cli](https://www.npmjs.com/package/@compilr-dev/cli) | AI-powered coding assistant for your terminal |
|
|
195
|
+
|
|
196
|
+
## Links
|
|
197
|
+
|
|
198
|
+
- [Website](https://compilr.dev)
|
|
199
|
+
- [npm Package](https://www.npmjs.com/package/@compilr-dev/factory)
|
|
200
|
+
- [Report Issues](https://github.com/compilr-dev/factory/issues)
|
|
128
201
|
|
|
129
202
|
## License
|
|
130
203
|
|
|
131
|
-
MIT
|
|
204
|
+
[FSL-1.1-MIT](https://fsl.software/) - See [LICENSE](LICENSE) for details. Converts to MIT after 2 years per version.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
<p align="center">
|
|
209
|
+
<strong>Built with care by <a href="https://compilr.dev">compilr.dev</a></strong>
|
|
210
|
+
</p>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Generates: server/index.ts, server/routes/{entity}.ts, server/data/{entity}.ts
|
|
5
5
|
*/
|
|
6
6
|
import { toCamelCase, toKebabCase } from '../../model/naming.js';
|
|
7
|
-
import { tsType, fkFieldName, belongsToRels } from './helpers.js';
|
|
7
|
+
import { tsType, fkFieldName, belongsToRels, hasManyRels } from './helpers.js';
|
|
8
8
|
import { generateSeedData } from './seed.js';
|
|
9
9
|
export function generateApiFiles(model) {
|
|
10
10
|
return [
|
|
@@ -69,6 +69,25 @@ function generateDataStore(model, entity) {
|
|
|
69
69
|
for (const rel of belongsToRels(entity)) {
|
|
70
70
|
typeFields.push(` ${fkFieldName(rel)}: number;`);
|
|
71
71
|
}
|
|
72
|
+
typeFields.push(' createdAt: string;');
|
|
73
|
+
typeFields.push(' updatedAt: string;');
|
|
74
|
+
// Collect searchable fields (string + enum types)
|
|
75
|
+
const searchableFields = entity.fields
|
|
76
|
+
.filter((f) => f.type === 'string' || f.type === 'enum')
|
|
77
|
+
.map((f) => `item.${f.name}`);
|
|
78
|
+
const searchFilter = searchableFields.length > 0
|
|
79
|
+
? ` const q = options.search.toLowerCase();
|
|
80
|
+
result = result.filter((item) =>
|
|
81
|
+
[${searchableFields.join(', ')}].some((v) =>
|
|
82
|
+
v !== undefined && String(v).toLowerCase().includes(q),
|
|
83
|
+
),
|
|
84
|
+
);`
|
|
85
|
+
: ` const q = options.search.toLowerCase();
|
|
86
|
+
result = result.filter((item) =>
|
|
87
|
+
Object.values(item).some((v) =>
|
|
88
|
+
v !== undefined && String(v).toLowerCase().includes(q),
|
|
89
|
+
),
|
|
90
|
+
);`;
|
|
72
91
|
const seedData = generateSeedData(model, entity);
|
|
73
92
|
return {
|
|
74
93
|
path: `server/data/${fileName}.ts`,
|
|
@@ -78,6 +97,11 @@ export interface ${typeName}Record {
|
|
|
78
97
|
${typeFields.join('\n')}
|
|
79
98
|
}
|
|
80
99
|
|
|
100
|
+
export interface QueryOptions {
|
|
101
|
+
search?: string;
|
|
102
|
+
filters?: Record<string, string>;
|
|
103
|
+
}
|
|
104
|
+
|
|
81
105
|
${seedData}
|
|
82
106
|
|
|
83
107
|
let items: ${typeName}Record[] = [...${varName}SeedData];
|
|
@@ -91,8 +115,24 @@ export function getById(id: number): ${typeName}Record | undefined {
|
|
|
91
115
|
return items.find((item) => item.id === id);
|
|
92
116
|
}
|
|
93
117
|
|
|
94
|
-
export function
|
|
95
|
-
|
|
118
|
+
export function query(options: QueryOptions): { data: ${typeName}Record[]; total: number } {
|
|
119
|
+
let result = items;
|
|
120
|
+
if (options.search) {
|
|
121
|
+
${searchFilter}
|
|
122
|
+
}
|
|
123
|
+
if (options.filters) {
|
|
124
|
+
for (const [field, value] of Object.entries(options.filters)) {
|
|
125
|
+
result = result.filter((item) =>
|
|
126
|
+
String((item as Record<string, unknown>)[field]) === value,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return { data: result, total: result.length };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function create(data: Omit<${typeName}Record, 'id' | 'createdAt' | 'updatedAt'>): ${typeName}Record {
|
|
134
|
+
const now = new Date().toISOString();
|
|
135
|
+
const item = { ...data, id: nextId++, createdAt: now, updatedAt: now };
|
|
96
136
|
items.push(item);
|
|
97
137
|
return item;
|
|
98
138
|
}
|
|
@@ -100,7 +140,7 @@ export function create(data: Omit<${typeName}Record, 'id'>): ${typeName}Record {
|
|
|
100
140
|
export function update(id: number, data: Partial<${typeName}Record>): ${typeName}Record | undefined {
|
|
101
141
|
const index = items.findIndex((item) => item.id === id);
|
|
102
142
|
if (index === -1) return undefined;
|
|
103
|
-
items[index] = { ...items[index], ...data, id };
|
|
143
|
+
items[index] = { ...items[index], ...data, id, updatedAt: new Date().toISOString() };
|
|
104
144
|
return items[index];
|
|
105
145
|
}
|
|
106
146
|
|
|
@@ -121,6 +161,7 @@ function generateRoutes(model, entity) {
|
|
|
121
161
|
const varName = toCamelCase(entity.pluralName) + 'Router';
|
|
122
162
|
const dataImport = fileName;
|
|
123
163
|
const btoRels = belongsToRels(entity);
|
|
164
|
+
const hmRels = hasManyRels(entity);
|
|
124
165
|
// Populate belongsTo entities
|
|
125
166
|
const populateImports = btoRels
|
|
126
167
|
.map((rel) => {
|
|
@@ -132,6 +173,17 @@ function generateRoutes(model, entity) {
|
|
|
132
173
|
})
|
|
133
174
|
.filter(Boolean)
|
|
134
175
|
.join('\n');
|
|
176
|
+
// Aliased getAll imports for hasMany targets (used by ?include=)
|
|
177
|
+
const hasManyImports = hmRels
|
|
178
|
+
.map((rel) => {
|
|
179
|
+
const targetEntity = model.entities.find((e) => e.name === rel.target);
|
|
180
|
+
if (!targetEntity)
|
|
181
|
+
return '';
|
|
182
|
+
const targetFile = toKebabCase(targetEntity.pluralName).toLowerCase();
|
|
183
|
+
return `import { getAll as getAll${targetEntity.pluralName} } from '../data/${targetFile}.js';`;
|
|
184
|
+
})
|
|
185
|
+
.filter(Boolean)
|
|
186
|
+
.join('\n');
|
|
135
187
|
const populateLogic = btoRels.length > 0
|
|
136
188
|
? `
|
|
137
189
|
function populate(item: Record<string, unknown>): Record<string, unknown> {
|
|
@@ -148,30 +200,64 @@ ${btoRels
|
|
|
148
200
|
`
|
|
149
201
|
: '';
|
|
150
202
|
const getListReturn = btoRels.length > 0
|
|
151
|
-
? 'res.json(
|
|
152
|
-
: 'res.json(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
203
|
+
? 'res.json({ data: result.data.map((item) => populate(item as unknown as Record<string, unknown>)), total: result.total });'
|
|
204
|
+
: 'res.json({ data: result.data, total: result.total });';
|
|
205
|
+
// GET by ID with optional ?include= for hasMany
|
|
206
|
+
let getByIdBody;
|
|
207
|
+
if (hmRels.length > 0) {
|
|
208
|
+
const includeChecks = hmRels
|
|
209
|
+
.map((rel) => {
|
|
210
|
+
const targetEntity = model.entities.find((e) => e.name === rel.target);
|
|
211
|
+
if (!targetEntity)
|
|
212
|
+
return '';
|
|
213
|
+
const targetVar = toCamelCase(targetEntity.pluralName);
|
|
214
|
+
const fkRel = targetEntity.relationships.find((r) => r.type === 'belongsTo' && r.target === entity.name) ?? { type: 'belongsTo', target: entity.name };
|
|
215
|
+
const fk = fkFieldName(fkRel);
|
|
216
|
+
return ` if (include.includes('${targetVar}')) {
|
|
217
|
+
result.${targetVar} = getAll${targetEntity.pluralName}().filter((r) => r.${fk} === item.id);
|
|
218
|
+
}`;
|
|
219
|
+
})
|
|
220
|
+
.filter(Boolean)
|
|
221
|
+
.join('\n');
|
|
222
|
+
const populateExpr = btoRels.length > 0 ? 'populate(item as unknown as Record<string, unknown>)' : '{ ...item }';
|
|
223
|
+
getByIdBody = ` const item = getById(Number(req.params.id));
|
|
224
|
+
if (!item) return res.status(404).json({ error: 'Not found' });
|
|
225
|
+
const include = (req.query.include as string ?? '').split(',').filter(Boolean);
|
|
226
|
+
const result: Record<string, unknown> = ${populateExpr};
|
|
227
|
+
${includeChecks}
|
|
228
|
+
res.json(result);`;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const getByIdReturn = btoRels.length > 0
|
|
232
|
+
? 'res.json(populate(item as unknown as Record<string, unknown>));'
|
|
233
|
+
: 'res.json(item);';
|
|
234
|
+
getByIdBody = ` const item = getById(Number(req.params.id));
|
|
235
|
+
if (!item) return res.status(404).json({ error: 'Not found' });
|
|
236
|
+
${getByIdReturn}`;
|
|
237
|
+
}
|
|
156
238
|
return {
|
|
157
239
|
path: `server/routes/${fileName}.ts`,
|
|
158
240
|
content: `import { Router } from 'express';
|
|
159
|
-
import { getAll, getById, create, update, remove } from '../data/${dataImport}.js';
|
|
160
|
-
${populateImports}
|
|
241
|
+
import { getAll, getById, query, create, update, remove } from '../data/${dataImport}.js';
|
|
242
|
+
${populateImports}${hasManyImports ? '\n' + hasManyImports : ''}
|
|
161
243
|
|
|
162
244
|
export const ${varName} = Router();
|
|
163
245
|
${populateLogic}
|
|
164
246
|
// GET all
|
|
165
|
-
${varName}.get('/', (
|
|
166
|
-
const
|
|
247
|
+
${varName}.get('/', (req, res) => {
|
|
248
|
+
const search = req.query.search as string | undefined;
|
|
249
|
+
const filters: Record<string, string> = {};
|
|
250
|
+
for (const [key, value] of Object.entries(req.query)) {
|
|
251
|
+
const match = key.match(/^filter\\[(.+)\\]$/);
|
|
252
|
+
if (match && typeof value === 'string') filters[match[1]] = value;
|
|
253
|
+
}
|
|
254
|
+
const result = query({ search, filters });
|
|
167
255
|
${getListReturn}
|
|
168
256
|
});
|
|
169
257
|
|
|
170
258
|
// GET by ID
|
|
171
259
|
${varName}.get('/:id', (req, res) => {
|
|
172
|
-
|
|
173
|
-
if (!item) return res.status(404).json({ error: 'Not found' });
|
|
174
|
-
${getByIdReturn}
|
|
260
|
+
${getByIdBody}
|
|
175
261
|
});
|
|
176
262
|
|
|
177
263
|
// POST create
|
|
@@ -7,3 +7,7 @@
|
|
|
7
7
|
import type { ApplicationModel } from '../../model/types.js';
|
|
8
8
|
import type { FactoryFile } from '../types.js';
|
|
9
9
|
export declare function generateConfigFiles(model: ApplicationModel): FactoryFile[];
|
|
10
|
+
declare function hexToHsl(hex: string): [number, number, number];
|
|
11
|
+
declare function hslToHex(h: number, s: number, l: number): string;
|
|
12
|
+
declare function generateColorShades(hex: string): string;
|
|
13
|
+
export { hexToHsl, hslToHex, generateColorShades };
|
|
@@ -43,6 +43,7 @@ function generatePackageJson(appSlug) {
|
|
|
43
43
|
cors: '^2.8.5',
|
|
44
44
|
express: '^4.21.1',
|
|
45
45
|
postcss: '^8.4.49',
|
|
46
|
+
'@tailwindcss/forms': '^0.5.9',
|
|
46
47
|
tailwindcss: '^3.4.15',
|
|
47
48
|
tsx: '^4.19.2',
|
|
48
49
|
typescript: '^5.6.3',
|
|
@@ -71,18 +72,20 @@ export default defineConfig({
|
|
|
71
72
|
function generateTailwindConfig(model) {
|
|
72
73
|
return {
|
|
73
74
|
path: 'tailwind.config.js',
|
|
74
|
-
content:
|
|
75
|
+
content: `import forms from '@tailwindcss/forms';
|
|
76
|
+
|
|
77
|
+
/** @type {import('tailwindcss').Config} */
|
|
75
78
|
export default {
|
|
76
79
|
content: ['./index.html', './src/**/*.{ts,tsx}'],
|
|
77
80
|
darkMode: 'class',
|
|
78
81
|
theme: {
|
|
79
82
|
extend: {
|
|
80
83
|
colors: {
|
|
81
|
-
primary:
|
|
84
|
+
primary: ${generateColorShades(model.theme.primaryColor)},
|
|
82
85
|
},
|
|
83
86
|
},
|
|
84
87
|
},
|
|
85
|
-
plugins: [],
|
|
88
|
+
plugins: [forms],
|
|
86
89
|
};
|
|
87
90
|
`,
|
|
88
91
|
};
|
|
@@ -106,6 +109,90 @@ function generateTsConfig() {
|
|
|
106
109
|
};
|
|
107
110
|
return { path: 'tsconfig.json', content: JSON.stringify(config, null, 2) + '\n' };
|
|
108
111
|
}
|
|
112
|
+
// =============================================================================
|
|
113
|
+
// Color Shade Utilities
|
|
114
|
+
// =============================================================================
|
|
115
|
+
const SHADE_LIGHTNESS = {
|
|
116
|
+
'50': 97,
|
|
117
|
+
'100': 94,
|
|
118
|
+
'200': 86,
|
|
119
|
+
'300': 77,
|
|
120
|
+
'400': 66,
|
|
121
|
+
'500': 55,
|
|
122
|
+
'600': 44,
|
|
123
|
+
'700': 36,
|
|
124
|
+
'800': 27,
|
|
125
|
+
'900': 20,
|
|
126
|
+
'950': 14,
|
|
127
|
+
};
|
|
128
|
+
function hexToHsl(hex) {
|
|
129
|
+
const raw = hex.replace('#', '');
|
|
130
|
+
const r = parseInt(raw.substring(0, 2), 16) / 255;
|
|
131
|
+
const g = parseInt(raw.substring(2, 4), 16) / 255;
|
|
132
|
+
const b = parseInt(raw.substring(4, 6), 16) / 255;
|
|
133
|
+
const max = Math.max(r, g, b);
|
|
134
|
+
const min = Math.min(r, g, b);
|
|
135
|
+
const l = (max + min) / 2;
|
|
136
|
+
if (max === min)
|
|
137
|
+
return [0, 0, Math.round(l * 100)];
|
|
138
|
+
const d = max - min;
|
|
139
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
140
|
+
let h = 0;
|
|
141
|
+
if (max === r)
|
|
142
|
+
h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
143
|
+
else if (max === g)
|
|
144
|
+
h = ((b - r) / d + 2) / 6;
|
|
145
|
+
else
|
|
146
|
+
h = ((r - g) / d + 4) / 6;
|
|
147
|
+
return [Math.round(h * 360), Math.round(s * 100), Math.round(l * 100)];
|
|
148
|
+
}
|
|
149
|
+
function hslToHex(h, s, l) {
|
|
150
|
+
const sN = s / 100;
|
|
151
|
+
const lN = l / 100;
|
|
152
|
+
const c = (1 - Math.abs(2 * lN - 1)) * sN;
|
|
153
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
154
|
+
const m = lN - c / 2;
|
|
155
|
+
let r = 0, g = 0, b = 0;
|
|
156
|
+
if (h < 60)
|
|
157
|
+
[r, g, b] = [c, x, 0];
|
|
158
|
+
else if (h < 120)
|
|
159
|
+
[r, g, b] = [x, c, 0];
|
|
160
|
+
else if (h < 180)
|
|
161
|
+
[r, g, b] = [0, c, x];
|
|
162
|
+
else if (h < 240)
|
|
163
|
+
[r, g, b] = [0, x, c];
|
|
164
|
+
else if (h < 300)
|
|
165
|
+
[r, g, b] = [x, 0, c];
|
|
166
|
+
else
|
|
167
|
+
[r, g, b] = [c, 0, x];
|
|
168
|
+
const toHex = (v) => Math.round((v + m) * 255)
|
|
169
|
+
.toString(16)
|
|
170
|
+
.padStart(2, '0');
|
|
171
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
172
|
+
}
|
|
173
|
+
function generateColorShades(hex) {
|
|
174
|
+
const [h, s] = hexToHsl(hex);
|
|
175
|
+
const entries = [];
|
|
176
|
+
for (const [shade, lightness] of Object.entries(SHADE_LIGHTNESS)) {
|
|
177
|
+
entries.push(` ${shade}: '${hslToHex(h, s, lightness)}',`);
|
|
178
|
+
}
|
|
179
|
+
// Find the shade closest to the original for DEFAULT
|
|
180
|
+
const [, , originalL] = hexToHsl(hex);
|
|
181
|
+
let closestShade = '500';
|
|
182
|
+
let closestDiff = Infinity;
|
|
183
|
+
for (const [shade, lightness] of Object.entries(SHADE_LIGHTNESS)) {
|
|
184
|
+
const diff = Math.abs(lightness - originalL);
|
|
185
|
+
if (diff < closestDiff) {
|
|
186
|
+
closestDiff = diff;
|
|
187
|
+
closestShade = shade;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const defaultHex = hslToHex(h, s, SHADE_LIGHTNESS[closestShade]);
|
|
191
|
+
entries.push(` DEFAULT: '${defaultHex}',`);
|
|
192
|
+
return `{\n${entries.join('\n')}\n }`;
|
|
193
|
+
}
|
|
194
|
+
// Export for testing
|
|
195
|
+
export { hexToHsl, hslToHex, generateColorShades };
|
|
109
196
|
function generatePostCssConfig() {
|
|
110
197
|
return {
|
|
111
198
|
path: 'postcss.config.js',
|
|
@@ -26,7 +26,12 @@ function generateListPage(model, entity) {
|
|
|
26
26
|
const hasFilters = enumFields.length > 0;
|
|
27
27
|
const tableHeaders = entity.fields
|
|
28
28
|
.slice(0, 5)
|
|
29
|
-
.map((f) => ` <th
|
|
29
|
+
.map((f) => ` <th
|
|
30
|
+
className="cursor-pointer select-none px-4 py-2 text-left text-sm font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
|
|
31
|
+
onClick={() => handleSort('${f.name}')}
|
|
32
|
+
>
|
|
33
|
+
${f.label}{sortField === '${f.name}' ? (sortDirection === 'asc' ? ' ↑' : ' ↓') : ''}
|
|
34
|
+
</th>`)
|
|
30
35
|
.join('\n');
|
|
31
36
|
const tableCells = entity.fields
|
|
32
37
|
.slice(0, 5)
|
|
@@ -45,16 +50,27 @@ ${hasFilters ? `const filterOptions = [\n${filterDefs}\n];\n` : ''}
|
|
|
45
50
|
export default function ${entity.name}List() {
|
|
46
51
|
const [items, setItems] = useState<${entity.name}[]>([]);
|
|
47
52
|
const [view, setView] = useState<'card' | 'list'>('card');
|
|
48
|
-
const [search, setSearch] = useState('')
|
|
53
|
+
const [search, setSearch] = useState('');
|
|
54
|
+
const [sortField, setSortField] = useState<string>('');
|
|
55
|
+
const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('asc');${hasFilters ? '\n const [filters, setFilters] = useState<Record<string, string>>({});' : ''}
|
|
49
56
|
|
|
50
57
|
useEffect(() => {
|
|
51
58
|
fetch('${api}')
|
|
52
59
|
.then((r) => r.json())
|
|
53
|
-
.then((data: ${entity.name}[]) => setItems(data));
|
|
60
|
+
.then((res: { data: ${entity.name}[]; total: number }) => setItems(res.data));
|
|
54
61
|
}, []);
|
|
55
62
|
|
|
56
63
|
const onSearch = useCallback((q: string) => setSearch(q), []);
|
|
57
64
|
|
|
65
|
+
const handleSort = useCallback((field: string) => {
|
|
66
|
+
if (sortField === field) {
|
|
67
|
+
setSortDirection((d) => (d === 'asc' ? 'desc' : 'asc'));
|
|
68
|
+
} else {
|
|
69
|
+
setSortField(field);
|
|
70
|
+
setSortDirection('asc');
|
|
71
|
+
}
|
|
72
|
+
}, [sortField]);
|
|
73
|
+
|
|
58
74
|
const filtered = items.filter((item) => {
|
|
59
75
|
if (search) {
|
|
60
76
|
const q = search.toLowerCase();
|
|
@@ -71,6 +87,14 @@ export default function ${entity.name}List() {
|
|
|
71
87
|
return true;
|
|
72
88
|
});
|
|
73
89
|
|
|
90
|
+
const sorted = [...filtered].sort((a, b) => {
|
|
91
|
+
if (!sortField) return 0;
|
|
92
|
+
const aVal = (a as Record<string, unknown>)[sortField];
|
|
93
|
+
const bVal = (b as Record<string, unknown>)[sortField];
|
|
94
|
+
const cmp = String(aVal ?? '').localeCompare(String(bVal ?? ''), undefined, { numeric: true });
|
|
95
|
+
return sortDirection === 'asc' ? cmp : -cmp;
|
|
96
|
+
});
|
|
97
|
+
|
|
74
98
|
return (
|
|
75
99
|
<div>
|
|
76
100
|
<div className="mb-6 flex items-center justify-between">
|
|
@@ -93,7 +117,7 @@ export default function ${entity.name}List() {
|
|
|
93
117
|
|
|
94
118
|
{view === 'card' ? (
|
|
95
119
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
|
96
|
-
{
|
|
120
|
+
{sorted.map((item) => (
|
|
97
121
|
<${entity.name}Card key={item.id} item={item} />
|
|
98
122
|
))}
|
|
99
123
|
</div>
|
|
@@ -105,7 +129,7 @@ ${tableHeaders}
|
|
|
105
129
|
</tr>
|
|
106
130
|
</thead>
|
|
107
131
|
<tbody>
|
|
108
|
-
{
|
|
132
|
+
{sorted.map((item) => (
|
|
109
133
|
<tr key={item.id} className="border-b border-gray-100 hover:bg-gray-50 dark:border-gray-800 dark:hover:bg-gray-800/50">
|
|
110
134
|
${tableCells}
|
|
111
135
|
<td className="px-4 py-2">
|
|
@@ -160,22 +184,44 @@ function generateDetailPage(model, entity) {
|
|
|
160
184
|
const [${stateVar}, set${targetEntity.pluralName}] = useState<${rel.target}[]>([]);`;
|
|
161
185
|
})
|
|
162
186
|
.join('');
|
|
163
|
-
|
|
187
|
+
// Build ?include= param for hasMany targets
|
|
188
|
+
const includeTargets = hmRels
|
|
189
|
+
.map((rel) => {
|
|
190
|
+
const targetEntity = model.entities.find((e) => e.name === rel.target);
|
|
191
|
+
return targetEntity ? toCamelCase(targetEntity.pluralName) : '';
|
|
192
|
+
})
|
|
193
|
+
.filter(Boolean);
|
|
194
|
+
const includeParam = includeTargets.length > 0 ? `?include=${includeTargets.join(',')}` : '';
|
|
195
|
+
const hasManySetters = hmRels
|
|
164
196
|
.map((rel) => {
|
|
165
197
|
const targetEntity = model.entities.find((e) => e.name === rel.target);
|
|
166
198
|
if (!targetEntity)
|
|
167
199
|
return '';
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
type: 'belongsTo',
|
|
171
|
-
target: entity.name,
|
|
172
|
-
});
|
|
173
|
-
return `
|
|
174
|
-
fetch('${fetchApi}')
|
|
175
|
-
.then((r) => r.json())
|
|
176
|
-
.then((data: ${rel.target}[]) => set${targetEntity.pluralName}(data.filter((d) => d.${fk} === Number(id))));`;
|
|
200
|
+
const varName = toCamelCase(targetEntity.pluralName);
|
|
201
|
+
return ` set${targetEntity.pluralName}(data.${varName} ?? []);`;
|
|
177
202
|
})
|
|
178
|
-
.join('');
|
|
203
|
+
.join('\n');
|
|
204
|
+
// Build the useEffect block
|
|
205
|
+
let useEffectBlock;
|
|
206
|
+
if (hmRels.length > 0) {
|
|
207
|
+
useEffectBlock =
|
|
208
|
+
' useEffect(() => {\n' +
|
|
209
|
+
` fetch(\`${api}/\${id as string}${includeParam}\`)\n` +
|
|
210
|
+
' .then((r) => r.json())\n' +
|
|
211
|
+
' .then((data: Record<string, unknown>) => {\n' +
|
|
212
|
+
` setItem(data as unknown as ${entity.name});\n` +
|
|
213
|
+
hasManySetters +
|
|
214
|
+
'\n });\n' +
|
|
215
|
+
' }, [id]);';
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
useEffectBlock =
|
|
219
|
+
' useEffect(() => {\n' +
|
|
220
|
+
` fetch(\`${api}/\${id as string}\`)\n` +
|
|
221
|
+
' .then((r) => r.json())\n' +
|
|
222
|
+
` .then((data: ${entity.name}) => setItem(data));\n` +
|
|
223
|
+
' }, [id]);';
|
|
224
|
+
}
|
|
179
225
|
const hasManyImports = hmRels.map((rel) => rel.target).join(', ');
|
|
180
226
|
const hasManyTypeImport = hmRels.length > 0 ? `, ${hasManyImports}` : '';
|
|
181
227
|
const hasManyRender = hmRels
|
|
@@ -217,11 +263,7 @@ export default function ${entity.name}Detail() {
|
|
|
217
263
|
const navigate = useNavigate();
|
|
218
264
|
const [item, setItem] = useState<${entity.name} | null>(null);${hasManySection}
|
|
219
265
|
|
|
220
|
-
|
|
221
|
-
fetch(\`${api}/\${id as string}\`)
|
|
222
|
-
.then((r) => r.json())
|
|
223
|
-
.then((data: ${entity.name}) => setItem(data));${hasManyFetches}
|
|
224
|
-
}, [id]);
|
|
266
|
+
${useEffectBlock}
|
|
225
267
|
|
|
226
268
|
if (!item) return <div className="p-6">Loading...</div>;
|
|
227
269
|
|
|
@@ -253,6 +295,14 @@ export default function ${entity.name}Detail() {
|
|
|
253
295
|
|
|
254
296
|
<dl className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
|
255
297
|
${fieldRows}
|
|
298
|
+
<div>
|
|
299
|
+
<dt className="text-sm font-medium text-gray-500 dark:text-gray-400">Created</dt>
|
|
300
|
+
<dd className="mt-1 text-gray-900 dark:text-white">{new Date(item.createdAt).toLocaleString()}</dd>
|
|
301
|
+
</div>
|
|
302
|
+
<div>
|
|
303
|
+
<dt className="text-sm font-medium text-gray-500 dark:text-gray-400">Last Updated</dt>
|
|
304
|
+
<dd className="mt-1 text-gray-900 dark:text-white">{new Date(item.updatedAt).toLocaleString()}</dd>
|
|
305
|
+
</div>
|
|
256
306
|
${relLinks}
|
|
257
307
|
</dl>${hasManyRender}
|
|
258
308
|
</div>
|
|
@@ -322,7 +372,7 @@ function generateForm(model, entity) {
|
|
|
322
372
|
if (!targetEntity)
|
|
323
373
|
return '';
|
|
324
374
|
const targetApi = apiPath(targetEntity);
|
|
325
|
-
return ` fetch('${targetApi}').then((r) => r.json()).then((
|
|
375
|
+
return ` fetch('${targetApi}').then((r) => r.json()).then((res: { data: ${rel.target}[]; total: number }) => set${rel.target}Options(res.data));`;
|
|
326
376
|
})
|
|
327
377
|
.join('\n');
|
|
328
378
|
const relTypeImports = btoRels.map((r) => r.target);
|
|
@@ -136,6 +136,13 @@ export function generateSeedData(model, entity) {
|
|
|
136
136
|
const targetCount = targetEntity ? SEED_COUNT : SEED_COUNT;
|
|
137
137
|
lines.push(` ${fk}: ${String((i % targetCount) + 1)},`);
|
|
138
138
|
}
|
|
139
|
+
// Implicit timestamps (deterministic)
|
|
140
|
+
const createdDate = new Date('2025-06-01T10:00:00Z');
|
|
141
|
+
createdDate.setDate(createdDate.getDate() + i * 2);
|
|
142
|
+
const updatedDate = new Date(createdDate);
|
|
143
|
+
updatedDate.setDate(updatedDate.getDate() + i);
|
|
144
|
+
lines.push(` createdAt: '${createdDate.toISOString()}',`);
|
|
145
|
+
lines.push(` updatedAt: '${updatedDate.toISOString()}',`);
|
|
139
146
|
lines.push(' },');
|
|
140
147
|
}
|
|
141
148
|
lines.push('];');
|
|
@@ -4,8 +4,34 @@
|
|
|
4
4
|
* Generates src/types/index.ts with interfaces for each entity.
|
|
5
5
|
*/
|
|
6
6
|
import { tsType, fkFieldName, belongsToRels } from './helpers.js';
|
|
7
|
+
const SHARED_TYPES = `// --- Shared API Types ---
|
|
8
|
+
|
|
9
|
+
export interface PaginatedResponse<T> {
|
|
10
|
+
data: T[];
|
|
11
|
+
total: number;
|
|
12
|
+
page: number;
|
|
13
|
+
pageSize: number;
|
|
14
|
+
totalPages: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ApiResponse<T> {
|
|
18
|
+
data: T;
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ApiListResponse<T> {
|
|
23
|
+
data: T[];
|
|
24
|
+
total: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SortParams {
|
|
28
|
+
field: string;
|
|
29
|
+
direction: 'asc' | 'desc';
|
|
30
|
+
}`;
|
|
7
31
|
export function generateTypesFile(model) {
|
|
8
32
|
const lines = ['// Auto-generated TypeScript types from Application Model', ''];
|
|
33
|
+
lines.push(SHARED_TYPES);
|
|
34
|
+
lines.push('');
|
|
9
35
|
for (const entity of model.entities) {
|
|
10
36
|
lines.push(generateInterface(entity));
|
|
11
37
|
lines.push('');
|
|
@@ -26,6 +52,9 @@ function generateInterface(entity) {
|
|
|
26
52
|
lines.push(` ${fk}: number;`);
|
|
27
53
|
lines.push(` ${rel.target.charAt(0).toLowerCase() + rel.target.slice(1)}?: ${rel.target};`);
|
|
28
54
|
}
|
|
55
|
+
// Implicit timestamps
|
|
56
|
+
lines.push(' createdAt: string;');
|
|
57
|
+
lines.push(' updatedAt: string;');
|
|
29
58
|
lines.push('}');
|
|
30
59
|
return lines.join('\n');
|
|
31
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilr-dev/factory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "AI-driven application scaffolder for the compilr-dev ecosystem",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"typescript-eslint": "^8.18.1",
|
|
38
38
|
"vitest": "^2.1.8"
|
|
39
39
|
},
|
|
40
|
-
"license": "MIT",
|
|
40
|
+
"license": "FSL-1.1-MIT",
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|
|
43
43
|
"url": "https://github.com/scozzola/compilr-dev-factory"
|