@apso/cli 0.1.8 → 0.1.9
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/README.md +143 -15
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,27 +4,58 @@
|
|
|
4
4
|
- [Prerequisites](#prerequisites)
|
|
5
5
|
- [Usage](#usage)
|
|
6
6
|
- [Local Development](#local-development)
|
|
7
|
+
- [Populating an .apsorc File](#populating-an-apsorc-file)
|
|
7
8
|
- [Debugging](##debugging)
|
|
8
9
|
- [Commands](#commands)
|
|
9
10
|
|
|
10
|
-
# Prerequisites
|
|
11
|
-
|
|
12
|
-
You need to have setup access to Mavric's private NPM packages.
|
|
13
|
-
Find out how [here](https://github.com/mavric/.github-private/blob/main/how-to/private-npm.md)
|
|
14
11
|
|
|
15
12
|
# Usage
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```
|
|
14
|
+
Follow these steps to create and run a new APSO server project:
|
|
15
|
+
|
|
16
|
+
1. **Install the CLI globally:**
|
|
17
|
+
```sh
|
|
18
|
+
npm install -g @apso/apso-cli
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. **Initialize a new server project:**
|
|
22
|
+
```sh
|
|
23
|
+
apso server new --name <PROJECT_NAME>
|
|
24
|
+
```
|
|
25
|
+
This creates a new project folder with the necessary boilerplate.
|
|
26
|
+
|
|
27
|
+
3. **Define your database schema:**
|
|
28
|
+
Edit the `.apsorc` file in your new project folder to describe your entities and relationships. See the [Populating an .apsorc File](#populating-an-apsorc-file) section for details and examples.
|
|
29
|
+
|
|
30
|
+
4. **Generate code and database entities:**
|
|
31
|
+
```sh
|
|
32
|
+
apso server scaffold
|
|
33
|
+
```
|
|
34
|
+
This command generates all relevant modules and entity code based on your `.apsorc` file.
|
|
35
|
+
|
|
36
|
+
5. **Configure your database connection:**
|
|
37
|
+
Update your project's `.env` file with the database credentials you want to use.
|
|
38
|
+
|
|
39
|
+
6. **Start the local Postgres instance (Docker):**
|
|
40
|
+
```sh
|
|
41
|
+
npm run compose
|
|
42
|
+
```
|
|
43
|
+
This command uses Docker Compose to start a local Postgres database instance.
|
|
44
|
+
|
|
45
|
+
7. **Provision your schema/database:**
|
|
46
|
+
```sh
|
|
47
|
+
npm run provision
|
|
48
|
+
```
|
|
49
|
+
This sets up your new schema instance in the database.
|
|
50
|
+
|
|
51
|
+
8. **(Optional) Enable automatic model sync for local development:**
|
|
52
|
+
If you want to skip manual migrations and always sync your models with the database (useful for rapid prototyping or starting from scratch), set the following in your `.env` file:
|
|
53
|
+
```env
|
|
54
|
+
DATABASE_SYNC=true
|
|
55
|
+
```
|
|
56
|
+
With this setting, your models will be automatically synced to the database on startup.
|
|
57
|
+
|
|
58
|
+
> For more details on configuring your schema, see the [Populating an .apsorc File](#populating-an-apsorc-file) section below.
|
|
28
59
|
|
|
29
60
|
# Local Development
|
|
30
61
|
|
|
@@ -59,6 +90,103 @@ Now we will run the scaffold command which will generate the all the relevant mo
|
|
|
59
90
|
apso server scaffold
|
|
60
91
|
```
|
|
61
92
|
|
|
93
|
+
# Populating an .apsorc File
|
|
94
|
+
|
|
95
|
+
The `.apsorc` file defines your domain model, including entities and their relationships, for APSO code generation. It is required for scaffolding your backend service.
|
|
96
|
+
|
|
97
|
+
## How to Create and Populate `.apsorc`
|
|
98
|
+
|
|
99
|
+
1. **Location**: Place the `.apsorc` file in the root of your service directory.
|
|
100
|
+
2. **Version**: Set the `version` property to `2` for the latest schema.
|
|
101
|
+
3. **Entities**: Define each domain entity, its fields, and any unique constraints.
|
|
102
|
+
4. **Relationships**: Specify how entities relate (e.g., OneToMany, ManyToOne, etc.).
|
|
103
|
+
5. **rootFolder**: Set the folder where generated code will be placed (e.g., `src`).
|
|
104
|
+
|
|
105
|
+
> **Tip:** You can find sample `.apsorc` files in `apso-cli/test/apsorc-json/` for both v1 and v2 formats.
|
|
106
|
+
|
|
107
|
+
### Example `.apsorc` v2 File
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"version": 2,
|
|
112
|
+
"rootFolder": "src",
|
|
113
|
+
"relationships": [
|
|
114
|
+
{ "from": "User", "to": "WorkspaceUser", "type": "OneToMany", "nullable": true },
|
|
115
|
+
{ "from": "Workspace", "to": "WorkspaceUser", "type": "OneToMany" },
|
|
116
|
+
{ "from": "Workspace", "to": "Application", "type": "OneToMany", "index": true },
|
|
117
|
+
{ "from": "Application", "to": "ApplicationService", "type": "OneToMany" },
|
|
118
|
+
{ "from": "Application", "to": "User", "type": "ManyToOne", "to_name": "owner" },
|
|
119
|
+
{ "from": "ApplicationService", "to": "ApplicationServiceApiKey", "type": "OneToMany" },
|
|
120
|
+
{ "from": "ApplicationService", "to": "ApplicationServiceMetric", "type": "OneToMany" },
|
|
121
|
+
{ "from": "ApplicationService", "to": "InfrastructureStack", "type": "ManyToOne", "to_name": "networkStack", "nullable": true },
|
|
122
|
+
{ "from": "ApplicationService", "to": "InfrastructureStack", "type": "ManyToOne", "to_name": "databaseStack", "nullable": true },
|
|
123
|
+
{ "from": "InfrastructureStack", "to": "InfrastructureStack", "type": "ManyToOne", "to_name": "networkStack", "nullable": true }
|
|
124
|
+
],
|
|
125
|
+
"entities": [
|
|
126
|
+
{
|
|
127
|
+
"name": "User",
|
|
128
|
+
"created_at": true,
|
|
129
|
+
"updated_at": true,
|
|
130
|
+
"fields": [
|
|
131
|
+
{ "name": "cognito_id", "type": "text", "unique": true },
|
|
132
|
+
{ "name": "email", "type": "text", "length": 255, "is_email": true },
|
|
133
|
+
{ "name": "fullName", "type": "text", "nullable": true }
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"name": "Workspace",
|
|
138
|
+
"created_at": true,
|
|
139
|
+
"updated_at": true,
|
|
140
|
+
"fields": [
|
|
141
|
+
{ "name": "name", "type": "text" }
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"name": "WorkspaceUser",
|
|
146
|
+
"created_at": true,
|
|
147
|
+
"updated_at": true,
|
|
148
|
+
"fields": [
|
|
149
|
+
{ "name": "email", "type": "text", "length": 255, "is_email": true },
|
|
150
|
+
{ "name": "invite_code", "type": "text", "length": 64 },
|
|
151
|
+
{ "name": "role", "type": "enum", "values": ["User", "Admin"], "default": "Admin" },
|
|
152
|
+
{ "name": "status", "type": "enum", "values": ["Active", "Invited", "Inactive", "Deleted"] },
|
|
153
|
+
{ "name": "activeAt", "type": "date", "nullable": true }
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"name": "Application",
|
|
158
|
+
"created_at": true,
|
|
159
|
+
"updated_at": true,
|
|
160
|
+
"fields": [
|
|
161
|
+
{ "name": "name", "type": "text" },
|
|
162
|
+
{ "name": "status", "type": "enum", "values": ["Active", "Deleted"] }
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
// ... more entities as needed ...
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
For a full example, see [`apso-cli/test/apsorc-json/apsorc.v2.json`](./test/apsorc-json/apsorc.v2.json).
|
|
171
|
+
|
|
172
|
+
## Schema Reference
|
|
173
|
+
|
|
174
|
+
The `.apsorc` file must conform to the [APSO Configuration Schema](./apsorc.schema.json). This schema defines all valid properties, types, and constraints for your configuration file.
|
|
175
|
+
|
|
176
|
+
### Inline Schema (apsorc.schema.json)
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
// ... see full contents in apso-cli/apsorc.schema.json ...
|
|
180
|
+
{
|
|
181
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
182
|
+
"title": "APSO Configuration Schema",
|
|
183
|
+
"description": "Schema for the .apsorc file used by APSO to define entities and relationships.",
|
|
184
|
+
// ... (truncated for brevity) ...
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
See the [full schema file](./apsorc.schema.json) for all details and validation rules.
|
|
189
|
+
|
|
62
190
|
## Debugging
|
|
63
191
|
|
|
64
192
|
For debugging we would use the debug package so you need to import the package in file where you want to debug any code.
|
package/oclif.manifest.json
CHANGED