@carbonorm/carbonnode 1.3.0 → 1.4.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.
- package/README.md +61 -5
- package/package.json +2 -1
- package/scripts/generateRestBindings.ts +8 -8
- /package/scripts/assets/handlebars/{C6.tsx.handlebars → C6.ts.handlebars} +0 -0
- /package/scripts/assets/handlebars/{Table.test.tsx.handlebars → Table.test.ts.handlebars} +0 -0
- /package/scripts/assets/handlebars/{Table.tsx.handlebars → Table.ts.handlebars} +0 -0
- /package/scripts/assets/handlebars/{WsLiveUpdates.tsx.handlebars → WsLiveUpdates.ts.handlebars} +0 -0
package/README.md
CHANGED
|
@@ -1,10 +1,66 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
1
9
|
# CarbonNode
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
10
|
+
|
|
11
|
+
CarbonNode is a part of the CarbonORM series. It is a NodeJS MySQL ORM that is designed to work with CarbonPHP. This langauge
|
|
12
|
+
will implement the same ORM as CarbonPHP, but will be written in Typescript. Currently only C6 enabled request can be sent
|
|
13
|
+
using the bindings. Receiving API requests and handling it appropriately is not yet implemented. This is scheduled for
|
|
14
|
+
early 2023. This repository is in the early stages of development an any support is greatly appreciated.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
CarbonNode is available on [NPM](https://www.npmjs.com/). You'll need to have [NodeJS](https://nodejs.org/en/) installed
|
|
19
|
+
which comes prepackaged with npm (node package manager).
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @carbonorm/carbonnode
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Generate Models
|
|
26
|
+
|
|
27
|
+
The command below will generate the models for the database. The models will be generated in the output directory. We do
|
|
28
|
+
recommend you keep this folder separate from other work. It is also best to track the output directory in your version
|
|
29
|
+
control system. All arguments are optional. If you do not provide them the defaults will be used. The example arguments
|
|
30
|
+
below are the defaults.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx generateRestBindings --user root --pass password --host 127.0.0.1 --port 3306 --dbname carbonPHP --prefix carbon_ --output /src/api/rest
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You can view the [code generated](https://github.com/CarbonORM/CarbonORM.dev/blob/www/src/api/rest/Users.tsx) by
|
|
37
|
+
[this command](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/generateRestBindings.ts) in
|
|
38
|
+
[this repository](git@github.com:CarbonORM/CarbonNode.git). We use [Handlebars templates](https://mustache.github.io/)
|
|
39
|
+
to generate the code.
|
|
40
|
+
|
|
41
|
+
### Generated Tests
|
|
42
|
+
|
|
43
|
+
Tests are generated for each table in the database. The tests are generated in the same directory as the models.
|
|
44
|
+
Our Jest tests are not designed to run immediately. You will need to edit the tests manually to change *xdescribe* with just
|
|
45
|
+
*describe*. Once a test does not have xdescribe it will no longer be updated with new generation changes.
|
|
46
|
+
|
|
47
|
+
Note - I prefer to keep tests nested in my IDE project viewer. See the documentation for
|
|
48
|
+
[IntelliJ](https://www.jetbrains.com/help/idea/file-nesting-dialog.html) or
|
|
49
|
+
[VSCode](https://code.visualstudio.com/updates/v1_67#_explorer-file-nesting).
|
|
50
|
+
|
|
51
|
+
### Templates
|
|
52
|
+
|
|
53
|
+
Three templates are used to generate the models. The output will be multiple files; two files for each table in the
|
|
54
|
+
database consisting of your GET PUT POST and DELETE methods and a Jest test file, a C6.tsx file which contains all
|
|
55
|
+
table information and TypeScript types, and finally a websocket file which contains references to methods that are
|
|
56
|
+
generate. Here are the templates used to generate the code:
|
|
57
|
+
|
|
58
|
+
1) [C6.tsx.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/C6.tsx.handlebars)
|
|
59
|
+
2) [Table.tsx.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/Table.tsx.handlebars)
|
|
60
|
+
3) [Websocket.tsx.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/WsLiveUpdates.tsx.handlebars)
|
|
5
61
|
|
|
6
62
|
|
|
63
|
+
# Support and Issues
|
|
7
64
|
|
|
65
|
+
Any issues found should be reported on [GitHub](https://github.com/CarbonORM/CarbonNode/issues).
|
|
8
66
|
|
|
9
|
-
## Links
|
|
10
|
-
https://saturncloud.io/blog/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies-in-npm-packagejson-file/
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbonorm/carbonnode",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"browser": "dist/index.umd.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
|
+
"license": "MIT",
|
|
9
10
|
"dependencies": {
|
|
10
11
|
"axios": "^1.4.0",
|
|
11
12
|
"qs": "^6.11.1",
|
|
@@ -380,25 +380,25 @@ fs.writeFileSync(path.join(process.cwd(), 'C6MySqlDump.json'), JSON.stringify(ta
|
|
|
380
380
|
|
|
381
381
|
// import this file src/assets/handlebars/C6.tsx.handlebars for a mustache template
|
|
382
382
|
|
|
383
|
-
const c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.
|
|
383
|
+
const c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.ts.handlebars'), 'utf-8');
|
|
384
384
|
|
|
385
|
-
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.
|
|
385
|
+
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.ts'), Handlebars.compile(c6Template)(tableData));
|
|
386
386
|
|
|
387
|
-
const wsLiveUpdatesTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/WsLiveUpdates.
|
|
387
|
+
const wsLiveUpdatesTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/WsLiveUpdates.ts.handlebars'), 'utf-8');
|
|
388
388
|
|
|
389
|
-
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'WsLiveUpdates.
|
|
389
|
+
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'WsLiveUpdates.ts'), Handlebars.compile(wsLiveUpdatesTemplate)(tableData));
|
|
390
390
|
|
|
391
|
-
const template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.
|
|
391
|
+
const template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.ts.handlebars'), 'utf-8');
|
|
392
392
|
|
|
393
|
-
const testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.
|
|
393
|
+
const testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.ts.handlebars'), 'utf-8');
|
|
394
394
|
|
|
395
395
|
Object.values(tableData.TABLES).map((tableData, key) => {
|
|
396
396
|
|
|
397
397
|
const tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE
|
|
398
398
|
|
|
399
|
-
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.
|
|
399
|
+
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.ts'), Handlebars.compile(template)(tableData));
|
|
400
400
|
|
|
401
|
-
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.
|
|
401
|
+
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.ts'), Handlebars.compile(testTemplate)(tableData));
|
|
402
402
|
|
|
403
403
|
})
|
|
404
404
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/scripts/assets/handlebars/{WsLiveUpdates.tsx.handlebars → WsLiveUpdates.ts.handlebars}
RENAMED
|
File without changes
|