@objectql/cli 1.8.4 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +2 -2
  2. package/dist/commands/database-push.d.ts +5 -0
  3. package/dist/commands/database-push.js +15 -0
  4. package/dist/commands/database-push.js.map +1 -0
  5. package/dist/commands/dev.d.ts +2 -0
  6. package/dist/commands/dev.js +94 -6
  7. package/dist/commands/dev.js.map +1 -1
  8. package/dist/commands/doctor.d.ts +4 -0
  9. package/dist/commands/doctor.js +37 -0
  10. package/dist/commands/doctor.js.map +1 -0
  11. package/dist/commands/init.js +31 -30
  12. package/dist/commands/init.js.map +1 -1
  13. package/dist/commands/serve.d.ts +2 -0
  14. package/dist/commands/serve.js +122 -46
  15. package/dist/commands/serve.js.map +1 -1
  16. package/dist/commands/start.d.ts +1 -0
  17. package/dist/commands/start.js +15 -0
  18. package/dist/commands/start.js.map +1 -1
  19. package/dist/index.js +173 -210
  20. package/dist/index.js.map +1 -1
  21. package/package.json +13 -7
  22. package/templates/hello-world/.vscode/extensions.json +7 -0
  23. package/templates/hello-world/CHANGELOG.md +41 -0
  24. package/templates/hello-world/README.md +29 -0
  25. package/templates/hello-world/package.json +24 -0
  26. package/templates/hello-world/src/index.ts +58 -0
  27. package/templates/hello-world/tsconfig.json +10 -0
  28. package/templates/starter/.vscode/extensions.json +7 -0
  29. package/{CHANGELOG.md → templates/starter/CHANGELOG.md} +36 -42
  30. package/templates/starter/README.md +17 -0
  31. package/templates/starter/__tests__/projects-hooks-actions.test.ts +490 -0
  32. package/templates/starter/jest.config.js +16 -0
  33. package/templates/starter/package.json +52 -0
  34. package/templates/starter/src/README.pages.md +110 -0
  35. package/templates/starter/src/demo.app.yml +4 -0
  36. package/templates/starter/src/i18n/zh-CN/projects.json +22 -0
  37. package/templates/starter/src/modules/kitchen-sink/kitchen_sink.data.yml +18 -0
  38. package/templates/starter/src/modules/kitchen-sink/kitchen_sink.object.yml +156 -0
  39. package/templates/starter/src/modules/projects/project_approval.workflow.yml +51 -0
  40. package/templates/starter/src/modules/projects/projects.action.ts +472 -0
  41. package/templates/starter/src/modules/projects/projects.data.yml +13 -0
  42. package/templates/starter/src/modules/projects/projects.hook.ts +339 -0
  43. package/templates/starter/src/modules/projects/projects.object.yml +148 -0
  44. package/templates/starter/src/modules/projects/projects.permission.yml +141 -0
  45. package/templates/starter/src/modules/projects/projects.validation.yml +37 -0
  46. package/templates/starter/src/modules/tasks/tasks.data.yml +23 -0
  47. package/templates/starter/src/modules/tasks/tasks.object.yml +34 -0
  48. package/templates/starter/src/modules/tasks/tasks.permission.yml +167 -0
  49. package/templates/starter/src/seed.ts +55 -0
  50. package/templates/starter/src/types/index.ts +3 -0
  51. package/templates/starter/src/types/kitchen_sink.ts +101 -0
  52. package/templates/starter/src/types/projects.ts +49 -0
  53. package/templates/starter/src/types/tasks.ts +33 -0
  54. package/templates/starter/tsconfig.json +11 -0
  55. package/templates/starter/tsconfig.tsbuildinfo +1 -0
  56. package/AI_EXAMPLES.md +0 -154
  57. package/AI_IMPLEMENTATION_SUMMARY.md +0 -509
  58. package/AI_TUTORIAL.md +0 -144
  59. package/IMPLEMENTATION_SUMMARY.md +0 -437
  60. package/USAGE_EXAMPLES.md +0 -951
  61. package/__tests__/commands.test.ts +0 -426
  62. package/jest.config.js +0 -19
  63. package/src/commands/ai.ts +0 -509
  64. package/src/commands/build.ts +0 -98
  65. package/src/commands/dev.ts +0 -23
  66. package/src/commands/format.ts +0 -110
  67. package/src/commands/generate.ts +0 -135
  68. package/src/commands/i18n.ts +0 -303
  69. package/src/commands/init.ts +0 -191
  70. package/src/commands/lint.ts +0 -98
  71. package/src/commands/migrate.ts +0 -314
  72. package/src/commands/new.ts +0 -221
  73. package/src/commands/repl.ts +0 -120
  74. package/src/commands/serve.ts +0 -96
  75. package/src/commands/start.ts +0 -100
  76. package/src/commands/sync.ts +0 -328
  77. package/src/commands/test.ts +0 -98
  78. package/src/index.ts +0 -356
  79. package/tsconfig.json +0 -15
  80. package/tsconfig.tsbuildinfo +0 -1
package/USAGE_EXAMPLES.md DELETED
@@ -1,951 +0,0 @@
1
- # ObjectQL CLI - Usage Examples
2
-
3
- This guide provides practical examples for all ObjectQL CLI commands.
4
-
5
- ## Table of Contents
6
-
7
- - [Project Initialization](#project-initialization)
8
- - [Metadata Generation](#metadata-generation)
9
- - [TypeScript Code Generation](#typescript-code-generation)
10
- - [Internationalization (i18n)](#internationalization-i18n)
11
- - [Database Migrations](#database-migrations)
12
- - [Development Tools](#development-tools)
13
-
14
- ---
15
-
16
- ## Project Initialization
17
-
18
- ### Creating a New Project
19
-
20
- #### Basic Project
21
-
22
- ```bash
23
- # Create a minimal project with basic examples
24
- objectql init --template basic --name my-project
25
-
26
- # Navigate and start working
27
- cd my-project
28
- pnpm install
29
- pnpm run build
30
- objectql repl
31
- ```
32
-
33
- #### Express API Project
34
-
35
- ```bash
36
- # Create a project with Express server setup
37
- objectql init -t express-api -n my-api
38
-
39
- cd my-api
40
- pnpm install
41
- pnpm start
42
- ```
43
-
44
- #### Enterprise Project
45
-
46
- ```bash
47
- # Create a full-featured enterprise structure
48
- objectql init -t enterprise -n my-enterprise-app
49
-
50
- cd my-enterprise-app
51
- pnpm install
52
- objectql studio
53
- ```
54
-
55
- #### Advanced Options
56
-
57
- ```bash
58
- # Skip dependency installation (install manually later)
59
- objectql init -n my-project --skip-install
60
-
61
- # Skip git initialization
62
- objectql init -n my-project --skip-git
63
-
64
- # Custom directory
65
- objectql init -n my-project --dir /path/to/projects
66
-
67
- # Combine options
68
- objectql init -t express-api -n my-api --skip-install --skip-git
69
- ```
70
-
71
- ---
72
-
73
- ## Metadata Generation
74
-
75
- ### Creating Objects
76
-
77
- ```bash
78
- # Create a simple object
79
- objectql new object users
80
-
81
- # Create in specific directory
82
- objectql new object products --dir ./src/catalog
83
-
84
- # Create with module structure
85
- objectql new object crm_contacts --dir ./src/modules/crm
86
- ```
87
-
88
- Generated `users.object.yml`:
89
- ```yaml
90
- label: Users
91
- fields:
92
- name:
93
- type: text
94
- label: Name
95
- required: true
96
- ```
97
-
98
- ### Creating Views
99
-
100
- ```bash
101
- objectql new view user_list
102
-
103
- # Creates user_list.view.yml with default columns
104
- ```
105
-
106
- ### Creating Forms
107
-
108
- ```bash
109
- objectql new form user_edit
110
-
111
- # Creates user_edit.form.yml with basic layout
112
- ```
113
-
114
- ### Creating Actions
115
-
116
- ```bash
117
- objectql new action approve_request
118
-
119
- # Creates TWO files:
120
- # 1. approve_request.action.yml - metadata
121
- # 2. approve_request.action.ts - implementation
122
- ```
123
-
124
- Edit the generated `approve_request.action.ts`:
125
- ```typescript
126
- import { ActionContext } from '@objectql/types';
127
-
128
- export async function action_approve_request(context: ActionContext) {
129
- const { record, user } = context;
130
-
131
- // Your business logic here
132
- await context.object('requests').update(record._id, {
133
- status: 'approved',
134
- approved_by: user._id,
135
- approved_at: new Date()
136
- });
137
-
138
- return {
139
- success: true,
140
- message: 'Request approved successfully'
141
- };
142
- }
143
- ```
144
-
145
- ### Creating Hooks
146
-
147
- ```bash
148
- objectql new hook users
149
-
150
- # Creates TWO files:
151
- # 1. users.hook.yml - metadata
152
- # 2. users.hook.ts - implementation
153
- ```
154
-
155
- ### Creating Permissions
156
-
157
- ```bash
158
- objectql new permission users
159
-
160
- # Creates users.permission.yml with admin/user profiles
161
- ```
162
-
163
- ### Creating Validation Rules
164
-
165
- ```bash
166
- objectql new validation users
167
-
168
- # Creates users.validation.yml with sample rules
169
- ```
170
-
171
- ### Creating Workflows
172
-
173
- ```bash
174
- objectql new workflow order_processing
175
-
176
- # Creates order_processing.workflow.yml
177
- ```
178
-
179
- ### Creating Reports
180
-
181
- ```bash
182
- objectql new report sales_summary
183
-
184
- # Creates sales_summary.report.yml
185
- ```
186
-
187
- ### All Supported Types
188
-
189
- ```bash
190
- objectql new object <name> # Object/Entity definition
191
- objectql new view <name> # Data view
192
- objectql new form <name> # Form layout
193
- objectql new page <name> # Page definition
194
- objectql new action <name> # Custom action
195
- objectql new hook <name> # Lifecycle hook
196
- objectql new permission <name> # Permission rules
197
- objectql new validation <name> # Validation rules
198
- objectql new workflow <name> # Workflow automation
199
- objectql new report <name> # Report definition
200
- objectql new menu <name> # Menu configuration
201
- objectql new data <name> # Sample data
202
- ```
203
-
204
- ---
205
-
206
- ## TypeScript Code Generation
207
-
208
- ### Basic Usage
209
-
210
- ```bash
211
- # Generate types from current directory
212
- objectql generate
213
-
214
- # Generates TypeScript interfaces in ./src/generated/
215
- ```
216
-
217
- ### Custom Paths
218
-
219
- ```bash
220
- # Custom source and output
221
- objectql generate -s ./metadata -o ./types
222
-
223
- # From specific module
224
- objectql generate -s ./src/modules/crm -o ./src/modules/crm/types
225
- ```
226
-
227
- ### Integration with Build Process
228
-
229
- In `package.json`:
230
- ```json
231
- {
232
- "scripts": {
233
- "codegen": "objectql generate -s src -o src/types",
234
- "prebuild": "npm run codegen",
235
- "build": "tsc"
236
- }
237
- }
238
- ```
239
-
240
- ### Using Generated Types
241
-
242
- ```typescript
243
- import { User, Project, Task } from './generated';
244
-
245
- const user: User = {
246
- _id: '123',
247
- name: 'John Doe',
248
- email: 'john@example.com'
249
- };
250
-
251
- const project: Project = {
252
- _id: '456',
253
- name: 'My Project',
254
- owner: user._id,
255
- status: 'active'
256
- };
257
- ```
258
-
259
- ---
260
-
261
- ## Internationalization (i18n)
262
-
263
- ### Setting Up i18n
264
-
265
- #### 1. Extract Translatable Strings
266
-
267
- ```bash
268
- # Extract for English (default)
269
- objectql i18n extract
270
-
271
- # Extract for specific language
272
- objectql i18n extract --lang zh-CN
273
-
274
- # Custom paths
275
- objectql i18n extract -s ./src -o ./translations --lang en
276
- ```
277
-
278
- This creates JSON files like `src/i18n/en/users.json`:
279
- ```json
280
- {
281
- "label": "Users",
282
- "fields": {
283
- "name": { "label": "Name" },
284
- "email": { "label": "Email" },
285
- "status": {
286
- "label": "Status",
287
- "options": {
288
- "active": "Active",
289
- "inactive": "Inactive"
290
- }
291
- }
292
- },
293
- "actions": {
294
- "approve": {
295
- "label": "Approve User",
296
- "confirm_text": "Are you sure you want to approve this user?"
297
- }
298
- }
299
- }
300
- ```
301
-
302
- #### 2. Initialize New Language
303
-
304
- ```bash
305
- # Initialize Chinese (Simplified)
306
- objectql i18n init zh-CN
307
-
308
- # Initialize French
309
- objectql i18n init fr
310
-
311
- # Initialize Spanish
312
- objectql i18n init es
313
- ```
314
-
315
- #### 3. Extract for New Language
316
-
317
- ```bash
318
- # Extract all translatable strings for Chinese
319
- objectql i18n extract --lang zh-CN
320
- ```
321
-
322
- #### 4. Translate the JSON Files
323
-
324
- Edit `src/i18n/zh-CN/users.json`:
325
- ```json
326
- {
327
- "label": "用户",
328
- "fields": {
329
- "name": { "label": "姓名" },
330
- "email": { "label": "邮箱" },
331
- "status": {
332
- "label": "状态",
333
- "options": {
334
- "active": "活跃",
335
- "inactive": "未激活"
336
- }
337
- }
338
- },
339
- "actions": {
340
- "approve": {
341
- "label": "批准用户",
342
- "confirm_text": "确定要批准此用户吗?"
343
- }
344
- }
345
- }
346
- ```
347
-
348
- #### 5. Validate Completeness
349
-
350
- ```bash
351
- # Check if all English strings are translated to Chinese
352
- objectql i18n validate zh-CN
353
-
354
- # Use custom base language
355
- objectql i18n validate fr --base-lang en
356
-
357
- # Custom directory
358
- objectql i18n validate es --base-dir ./translations
359
- ```
360
-
361
- Output:
362
- ```
363
- 🌐 Validating translations for zh-CN against en...
364
-
365
- ✓ users.json - Complete
366
- ⚠ projects.json - 3 missing keys:
367
- - fields.budget.label
368
- - fields.deadline.description
369
- - actions.export.label
370
-
371
- 📊 Summary:
372
- Total files: 5
373
- Missing translations: 3
374
- ```
375
-
376
- ### Complete i18n Workflow
377
-
378
- ```bash
379
- # 1. Start with English (extract from metadata)
380
- objectql i18n extract --lang en
381
-
382
- # 2. Add Chinese support
383
- objectql i18n init zh-CN
384
- objectql i18n extract --lang zh-CN
385
-
386
- # 3. Add French support
387
- objectql i18n init fr
388
- objectql i18n extract --lang fr
389
-
390
- # 4. Translate the JSON files manually
391
- # ... edit files in src/i18n/zh-CN/ and src/i18n/fr/
392
-
393
- # 5. Validate translations
394
- objectql i18n validate zh-CN
395
- objectql i18n validate fr
396
-
397
- # 6. When you add new fields, re-extract
398
- objectql i18n extract --lang zh-CN
399
- objectql i18n extract --lang fr
400
-
401
- # 7. Re-validate
402
- objectql i18n validate zh-CN
403
- objectql i18n validate fr
404
- ```
405
-
406
- ---
407
-
408
- ## Database Migrations
409
-
410
- ### Creating Migrations
411
-
412
- ```bash
413
- # Create a new migration
414
- objectql migrate create add_status_field
415
-
416
- # Creates: migrations/20260112120000_add_status_field.ts
417
- ```
418
-
419
- ### Editing Migration
420
-
421
- Edit `migrations/20260112120000_add_status_field.ts`:
422
- ```typescript
423
- import { ObjectQL } from '@objectql/core';
424
-
425
- export async function up(app: ObjectQL) {
426
- console.log('Adding status field to users');
427
-
428
- const users = app.getObject('users');
429
- await users.updateSchema({
430
- fields: {
431
- status: {
432
- type: 'select',
433
- label: 'Status',
434
- options: [
435
- { label: 'Active', value: 'active' },
436
- { label: 'Inactive', value: 'inactive' }
437
- ]
438
- }
439
- }
440
- });
441
- }
442
-
443
- export async function down(app: ObjectQL) {
444
- console.log('Removing status field from users');
445
-
446
- const users = app.getObject('users');
447
- await users.updateSchema({
448
- fields: {
449
- status: undefined
450
- }
451
- });
452
- }
453
- ```
454
-
455
- ### Running Migrations
456
-
457
- ```bash
458
- # Check migration status
459
- objectql migrate status
460
-
461
- # Run all pending migrations
462
- objectql migrate
463
-
464
- # With custom config
465
- objectql migrate --config ./config/objectql.config.ts
466
-
467
- # Custom migrations directory
468
- objectql migrate --dir ./db/migrations
469
- ```
470
-
471
- ### Migration Examples
472
-
473
- #### Adding a Field
474
-
475
- ```typescript
476
- export async function up(app: ObjectQL) {
477
- const tasks = app.getObject('tasks');
478
- await tasks.updateSchema({
479
- fields: {
480
- priority: {
481
- type: 'select',
482
- label: 'Priority',
483
- options: ['low', 'medium', 'high']
484
- }
485
- }
486
- });
487
- }
488
- ```
489
-
490
- #### Adding an Index
491
-
492
- ```typescript
493
- export async function up(app: ObjectQL) {
494
- const users = app.getObject('users');
495
- await users.addIndex('email', { unique: true });
496
- }
497
- ```
498
-
499
- #### Data Migration
500
-
501
- ```typescript
502
- export async function up(app: ObjectQL) {
503
- const tasks = app.getObject('tasks');
504
-
505
- // Update all tasks without priority
506
- const result = await tasks.find({
507
- filters: [['priority', '=', null]]
508
- });
509
-
510
- for (const task of result.records) {
511
- await tasks.update(task._id, {
512
- priority: 'medium'
513
- });
514
- }
515
-
516
- console.log(`Updated ${result.records.length} tasks`);
517
- }
518
- ```
519
-
520
- ### Syncing from Existing Database
521
-
522
- The `sync` command introspects an existing SQL database and generates ObjectQL `.object.yml` files.
523
-
524
- #### Basic Sync
525
-
526
- ```bash
527
- # Sync all tables from the database
528
- objectql sync
529
-
530
- # Output: src/objects/users.object.yml, src/objects/posts.object.yml, etc.
531
- ```
532
-
533
- #### Selective Table Sync
534
-
535
- ```bash
536
- # Sync only specific tables
537
- objectql sync --tables users posts comments
538
-
539
- # Custom output directory
540
- objectql sync --output ./src/metadata/objects
541
- ```
542
-
543
- #### Overwriting Existing Files
544
-
545
- ```bash
546
- # Force overwrite of existing .object.yml files
547
- objectql sync --force
548
- ```
549
-
550
- #### Example Workflow: Connecting to Legacy Database
551
-
552
- ```bash
553
- # 1. Create config file pointing to existing database
554
- cat > objectql.config.ts << 'EOF'
555
- import { ObjectQL } from '@objectql/core';
556
- import { SqlDriver } from '@objectql/driver-sql';
557
-
558
- const driver = new SqlDriver({
559
- client: 'postgresql',
560
- connection: {
561
- host: 'localhost',
562
- database: 'legacy_db',
563
- user: 'postgres',
564
- password: 'password'
565
- }
566
- });
567
-
568
- export default new ObjectQL({
569
- datasources: { default: driver }
570
- });
571
- EOF
572
-
573
- # 2. Introspect and generate object definitions
574
- objectql sync --output ./src/objects
575
-
576
- # 3. Review generated files
577
- ls -la ./src/objects/
578
-
579
- # Output:
580
- # users.object.yml
581
- # products.object.yml
582
- # orders.object.yml
583
- # order_items.object.yml
584
-
585
- # 4. Inspect a generated file
586
- cat ./src/objects/users.object.yml
587
- ```
588
-
589
- **Generated Output Example:**
590
-
591
- ```yaml
592
- # users.object.yml
593
- name: users
594
- label: Users
595
- fields:
596
- username:
597
- type: text
598
- label: Username
599
- required: true
600
- unique: true
601
- email:
602
- type: text
603
- label: Email
604
- required: true
605
- first_name:
606
- type: text
607
- label: First Name
608
- last_name:
609
- type: text
610
- label: Last Name
611
- is_active:
612
- type: boolean
613
- label: Is Active
614
- defaultValue: true
615
- role_id:
616
- type: lookup
617
- label: Role Id
618
- reference_to: roles
619
- ```
620
-
621
- **Type Mapping:**
622
-
623
- The sync command automatically maps SQL types to ObjectQL field types:
624
-
625
- | SQL Type | ObjectQL Type |
626
- |----------|---------------|
627
- | INT, INTEGER, BIGINT, SERIAL | number |
628
- | FLOAT, DOUBLE, DECIMAL, NUMERIC | number |
629
- | BOOLEAN, BIT | boolean |
630
- | VARCHAR, CHAR | text |
631
- | TEXT, CLOB, LONGTEXT | textarea |
632
- | TIMESTAMP, DATETIME | datetime |
633
- | DATE | date |
634
- | TIME | time |
635
- | JSON, JSONB | object |
636
- | BLOB, BINARY, BYTEA | file |
637
-
638
- **Foreign Key Detection:**
639
-
640
- Foreign keys are automatically detected and converted to `lookup` fields:
641
-
642
- ```sql
643
- -- Database Schema
644
- CREATE TABLE posts (
645
- id VARCHAR PRIMARY KEY,
646
- title VARCHAR NOT NULL,
647
- author_id VARCHAR REFERENCES users(id),
648
- ...
649
- );
650
- ```
651
-
652
- ```yaml
653
- # Generated posts.object.yml
654
- name: posts
655
- label: Posts
656
- fields:
657
- title:
658
- type: text
659
- label: Title
660
- required: true
661
- author_id:
662
- type: lookup
663
- label: Author Id
664
- reference_to: users
665
- ```
666
-
667
- ---
668
-
669
- ## Development Tools
670
-
671
- ### REPL (Interactive Shell)
672
-
673
- ```bash
674
- # Start REPL
675
- objectql repl
676
-
677
- # With custom config
678
- objectql repl --config ./objectql.config.ts
679
- ```
680
-
681
- In the REPL:
682
- ```javascript
683
- objectql> await tasks.find()
684
- objectql> await tasks.insert({ name: 'New Task', status: 'open' })
685
- objectql> await tasks.update('123', { status: 'completed' })
686
- objectql> await tasks.delete('123')
687
-
688
- // Access specific object
689
- objectql> const users = app.getObject('users')
690
- objectql> await users.count()
691
-
692
- // Run queries
693
- objectql> await tasks.find({
694
- ... filters: [['status', '=', 'open']],
695
- ... sort: [['created_at', 'desc']]
696
- ... })
697
- ```
698
-
699
- ### Serve (Development Server)
700
-
701
- ```bash
702
- # Start server on default port (3000)
703
- objectql serve
704
-
705
- # Custom port
706
- objectql serve --port 8080
707
-
708
- # Custom schema directory
709
- objectql serve --dir ./src/metadata
710
-
711
- # Full example
712
- objectql serve --port 4000 --dir ./src
713
- ```
714
-
715
- Access:
716
- - Swagger UI: `http://localhost:3000/swagger`
717
- - API: `http://localhost:3000/` (POST)
718
- - OpenAPI: `http://localhost:3000/openapi.json` (GET)
719
-
720
- ### Studio (Web Admin)
721
-
722
- ```bash
723
- # Start studio
724
- objectql studio
725
-
726
- # Custom port
727
- objectql studio --port 8080
728
-
729
- # Don't open browser
730
- objectql studio --no-open
731
-
732
- # Full example
733
- objectql studio --port 4000 --dir ./src --no-open
734
- ```
735
-
736
- Access the UI at: `http://localhost:3000/studio`
737
-
738
- ---
739
-
740
- ## Complete Workflow Examples
741
-
742
- ### Starting a New Project
743
-
744
- ```bash
745
- # 1. Initialize project
746
- objectql init -t basic -n my-crm
747
-
748
- # 2. Navigate to project
749
- cd my-crm
750
- pnpm install
751
-
752
- # 3. Create your first object
753
- objectql new object contacts
754
-
755
- # 4. Edit contacts.object.yml
756
- # ... add fields
757
-
758
- # 5. Generate TypeScript types
759
- objectql generate
760
-
761
- # 6. Start development
762
- objectql studio
763
-
764
- # 7. Build for production
765
- pnpm run build
766
- ```
767
-
768
- ### Adding a New Feature Module
769
-
770
- ```bash
771
- # 1. Create object
772
- objectql new object crm_leads --dir ./src/modules/crm
773
-
774
- # 2. Create view
775
- objectql new view crm_lead_list --dir ./src/modules/crm
776
-
777
- # 3. Create form
778
- objectql new form crm_lead_edit --dir ./src/modules/crm
779
-
780
- # 4. Create action
781
- objectql new action crm_convert_lead --dir ./src/modules/crm
782
-
783
- # 5. Add permissions
784
- objectql new permission crm_leads --dir ./src/modules/crm
785
-
786
- # 6. Generate types
787
- objectql generate
788
-
789
- # 7. Test in REPL
790
- objectql repl
791
- ```
792
-
793
- ### Internationalization Workflow
794
-
795
- ```bash
796
- # 1. Extract English strings
797
- objectql i18n extract --lang en
798
-
799
- # 2. Add Chinese support
800
- objectql i18n init zh-CN
801
- objectql i18n extract --lang zh-CN
802
-
803
- # 3. Translate files in src/i18n/zh-CN/
804
-
805
- # 4. Validate
806
- objectql i18n validate zh-CN
807
-
808
- # 5. When metadata changes, re-extract
809
- objectql i18n extract --lang en
810
- objectql i18n extract --lang zh-CN
811
-
812
- # 6. Re-validate
813
- objectql i18n validate zh-CN
814
- ```
815
-
816
- ### Database Migration Workflow
817
-
818
- ```bash
819
- # 1. Create migration
820
- objectql migrate create add_user_roles
821
-
822
- # 2. Edit migration file in migrations/
823
-
824
- # 3. Check status
825
- objectql migrate status
826
-
827
- # 4. Run migration
828
- objectql migrate
829
-
830
- # 5. Verify in REPL
831
- objectql repl
832
- > await users.findOne()
833
- ```
834
-
835
- ---
836
-
837
- ## Tips and Best Practices
838
-
839
- ### Project Structure
840
-
841
- ```
842
- my-project/
843
- ├── src/
844
- │ ├── modules/
845
- │ │ ├── crm/
846
- │ │ │ ├── contacts.object.yml
847
- │ │ │ ├── contacts.view.yml
848
- │ │ │ ├── contacts.form.yml
849
- │ │ │ └── contacts.permission.yml
850
- │ │ └── sales/
851
- │ │ ├── orders.object.yml
852
- │ │ └── ...
853
- │ ├── i18n/
854
- │ │ ├── en/
855
- │ │ ├── zh-CN/
856
- │ │ └── fr/
857
- │ └── types/ # Generated
858
- ├── migrations/
859
- ├── objectql.config.ts
860
- └── package.json
861
- ```
862
-
863
- ### Naming Conventions
864
-
865
- - Objects: `snake_case` (e.g., `crm_contacts`, `sales_orders`)
866
- - Actions/Hooks: `snake_case` (e.g., `approve_order`, `send_email`)
867
- - Fields: `snake_case` (e.g., `first_name`, `email_address`)
868
-
869
- ### Git Integration
870
-
871
- Add to `.gitignore`:
872
- ```
873
- node_modules/
874
- dist/
875
- *.log
876
- .DS_Store
877
- *.sqlite3
878
- .env
879
- .env.local
880
-
881
- # Keep migrations
882
- !migrations/
883
- ```
884
-
885
- ### Automation Scripts
886
-
887
- In `package.json`:
888
- ```json
889
- {
890
- "scripts": {
891
- "codegen": "objectql generate -s src -o src/types",
892
- "i18n:extract": "objectql i18n extract --lang en && objectql i18n extract --lang zh-CN",
893
- "i18n:validate": "objectql i18n validate zh-CN",
894
- "migrate": "objectql migrate",
895
- "dev": "objectql studio",
896
- "prebuild": "npm run codegen",
897
- "build": "tsc"
898
- }
899
- }
900
- ```
901
-
902
- ---
903
-
904
- ## Troubleshooting
905
-
906
- ### Common Issues
907
-
908
- **Issue**: `Cannot find module '@objectql/core'`
909
- ```bash
910
- # Solution: Install dependencies first
911
- pnpm install
912
- ```
913
-
914
- **Issue**: Migration fails
915
- ```bash
916
- # Solution: Check migration status
917
- objectql migrate status
918
-
919
- # Review config file
920
- cat objectql.config.ts
921
- ```
922
-
923
- **Issue**: Types not updating
924
- ```bash
925
- # Solution: Re-generate types
926
- objectql generate -s src -o src/types
927
- ```
928
-
929
- **Issue**: i18n validation shows missing keys
930
- ```bash
931
- # Solution: Re-extract and translate
932
- objectql i18n extract --lang zh-CN
933
- # Then edit the JSON files
934
- ```
935
-
936
- ---
937
-
938
- ## Getting Help
939
-
940
- ```bash
941
- # General help
942
- objectql --help
943
-
944
- # Command-specific help
945
- objectql init --help
946
- objectql new --help
947
- objectql i18n --help
948
- objectql migrate --help
949
- ```
950
-
951
- For more information, visit: https://github.com/objectql/objectql