@carbonorm/carbonnode 1.2.18 → 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 CHANGED
@@ -1,10 +1,66 @@
1
+ ![npm](https://img.shields.io/npm/v/%40carbonorm%2Fcarbonnode)
2
+ ![License](https://img.shields.io/npm/l/%40carbonorm%2Fcarbonnode)
3
+ ![Size](https://img.shields.io/github/languages/code-size/carbonorm/carbonnode)
4
+ ![Documentation](https://img.shields.io/website?down_color=lightgrey&down_message=Offline&up_color=green&up_message=Online&url=https%3A%2F%2Fcarbonorm.dev)
5
+ ![Monthly Downloads](https://img.shields.io/npm/dm/%40carbonorm%2Fcarbonnode)
6
+ ![All Downloads](https://img.shields.io/npm/dt/%40carbonorm%2Fcarbonnode)
7
+ ![Star](https://img.shields.io/github/stars/carbonorm/carbonnode?style=social)
8
+
1
9
  # CarbonNode
2
- Initially this repository will host the node bindings for the Carbon API.
3
- The Carbon API is a Cross Language ORM Syntax for querying SQL databases.
4
- The Carbon Node is currently under development and is not yet ready for use.
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.2.18",
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",
@@ -9,6 +9,8 @@ const randomString = Math.random().toString(36).substring(7);
9
9
  const randomInt = Math.floor(Math.random() * 1000000);
10
10
  const fillString = 'string' + randomString + randomInt;
11
11
 
12
+ console.log('fillString', fillString);
13
+
12
14
  /**
13
15
  {{{TABLE_DEFINITION}}}
14
16
  **/
@@ -25,7 +25,7 @@ type GetCustomAndRequiredFields = {}
25
25
  type GetRequestTableOverrides = {}
26
26
 
27
27
  // required parameters, optional parameters, parameter type overrides, response, and table names
28
- export const Get = restRequest<GetCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, GetRequestTableOverrides, iGetC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
28
+ const Get = restRequest<GetCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, GetRequestTableOverrides, iGetC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
29
29
  C6: C6,
30
30
  tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
31
31
  requestMethod: GET,
@@ -53,7 +53,7 @@ export function putState{{TABLE_NAME_SHORT_PASCAL_CASE}}(response : AxiosRespons
53
53
  ], "{{TABLE_NAME_SHORT}}", {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[])
54
54
  }
55
55
 
56
- export const Put = restRequest<PutCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PutRequestTableOverrides, iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
56
+ const Put = restRequest<PutCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PutRequestTableOverrides, iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
57
57
  C6: C6,
58
58
  tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
59
59
  requestMethod: PUT,
@@ -96,7 +96,7 @@ export function postState{{TABLE_NAME_SHORT_PASCAL_CASE}}(response : AxiosRespon
96
96
  )
97
97
  }
98
98
 
99
- export const Post = restRequest<PostCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PostRequestTableOverrides, iPostC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
99
+ const Post = restRequest<PostCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PostRequestTableOverrides, iPostC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
100
100
  C6: C6,
101
101
  tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
102
102
  requestMethod: POST,
@@ -118,7 +118,7 @@ export function deleteState{{TABLE_NAME_SHORT_PASCAL_CASE}}(_response : AxiosRes
118
118
  ], "{{TABLE_NAME_SHORT}}", {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[])
119
119
  }
120
120
 
121
- export const Delete = restRequest<DeleteCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, DeleteRequestTableOverrides, iDeleteC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
121
+ const Delete = restRequest<DeleteCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, DeleteRequestTableOverrides, iDeleteC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
122
122
  C6: C6,
123
123
  tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
124
124
  requestMethod: DELETE,
@@ -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.tsx.handlebars'), 'utf-8');
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.tsx'), Handlebars.compile(c6Template)(tableData));
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.tsx.handlebars'), 'utf-8');
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.tsx'), Handlebars.compile(wsLiveUpdatesTemplate)(tableData));
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.tsx.handlebars'), 'utf-8');
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.tsx.handlebars'), 'utf-8');
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 + '.tsx'), Handlebars.compile(template)(tableData));
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.tsx'), Handlebars.compile(testTemplate)(tableData));
401
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.ts'), Handlebars.compile(testTemplate)(tableData));
402
402
 
403
403
  })
404
404