@graf-research/adf-codegen-model-typeorm 0.0.12 → 0.0.14

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 ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2024 ADF Language. https://adf-lang.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # TypeORM - ADF Code Generator
2
+
3
+ Generator kode [ADF](https://github.com/Graf-Research/adf-core) untuk model [TypeORM](https://github.com/typeorm/typeorm) dalam format Typescript.
4
+
5
+ **Modul ADF yang digunakan**
6
+
7
+ `Table` `Enum`
8
+
9
+ **Penggunaan CLI (Command Line)**
10
+
11
+ ```bash
12
+ npx @graf-research/adf-codegen-model-typeorm <file/url ADF> <folder output>
13
+ ```
14
+
15
+ ## Instalasi
16
+
17
+ ```bash
18
+ npm install --save @graf-research/adf-codegen-model-typeorm
19
+ ```
20
+
21
+ ## Fungsi
22
+
23
+ ```typescript
24
+ import { Model } from "@graf-research/adf-core";
25
+
26
+ type MapModelNameFilePath = {[key: string]: string};
27
+
28
+ interface CodegenFileOutput {
29
+ filename: string
30
+ content: string
31
+ }
32
+
33
+ interface ItemOutput {
34
+ files: CodegenFileOutput[]
35
+ map: MapModelNameFilePath
36
+ }
37
+
38
+ interface Output {
39
+ table: ItemOutput
40
+ enum: ItemOutput
41
+ }
42
+
43
+ function TypeORMModel.compile(list_model: Model.Item[]): Output
44
+ ```
45
+
46
+ ## Paduan TypeORM
47
+
48
+ Untuk menggunakan fitur auto generated-migration TypeORM konfigurasi antara data source harus sesuai. Pada generator ini kode yang di-generate akan muncul pada dua folder besar yaitu:
49
+ - &lt;folder output&gt;/model/table/*.ts
50
+ - &lt;folder output&gt;/model/enum/*.ts
51
+
52
+ Berikut salah satu contoh kofigurasi Data Source dan Script `package.json`
53
+
54
+ #### data-source.ts
55
+ ```typescript
56
+ import { DataSource, DataSourceOptions } from "typeorm";
57
+
58
+ const config: DataSourceOptions = {
59
+ type: "postgres",
60
+ host: 'localhost',
61
+ port: 5432,
62
+ username: '<username>',
63
+ password: '<password>',
64
+ database: '<database name>',
65
+ synchronize: false,
66
+ logging: false,
67
+ migrations: [
68
+ __dirname + '/migration/**.ts'
69
+ ],
70
+ entities: [
71
+ __dirname + '/<folder output>/model/**/*.{ts,js}'
72
+ ]
73
+ };
74
+
75
+ export const AppDataSource = new DataSource(config);
76
+ ```
77
+
78
+ #### package.json
79
+ ```json
80
+ {
81
+ ...
82
+ "scripts": {
83
+ ...
84
+ "typeorm": "typeorm-ts-node-commonjs",
85
+ "generate-migration": "npm run typeorm migration:generate -- $1 -d ./data-source.ts",
86
+ "migrate": "npm run typeorm migration:run -- -d ./data-source.ts"
87
+ },
88
+ ...
89
+ }
90
+ ```
91
+
92
+ ##### Generate Migration
93
+
94
+ Untuk men-generate file migration TypeORM gunakan script `generate-migration` dengan output folder `migration` seperti konfigurasi pada `data-source.ts`, misalnya sebuah file migration dengan nama `Init.ts`:
95
+
96
+ ```bash
97
+ npm run generate-migration migration/Init
98
+ ```
99
+
100
+ akan menghasilkan file migration `migration/Init.ts`
101
+
102
+ ##### Menjalankan Migration
103
+
104
+ Untuk menjalankan file migration TypeORM gunakan script `migrate`, contoh:
105
+
106
+ ```bash
107
+ npm run migrate
108
+ ```
109
+
110
+ akan mengeksekusi sql script dari file-file migration.
package/dist/exec.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graf-research/adf-codegen-model-typeorm",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist && tsc",
@@ -26,7 +26,7 @@
26
26
  "typescript": "^5.6.3"
27
27
  },
28
28
  "dependencies": {
29
- "@graf-research/adf-core": "^0.0.15",
29
+ "@graf-research/adf-core": "^0.0.16",
30
30
  "axios": "^1.7.7",
31
31
  "lodash": "^4.17.21"
32
32
  }