@carbonorm/carbonnode 1.3.0 → 1.4.1

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,72 @@
1
- # 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.
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)
5
8
 
9
+ # CarbonNode (Alpha Release)
6
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.
7
15
 
16
+ ## Alpha Release
17
+
18
+ This is an alpha release. The code is not yet ready for production. We are looking for feedback on the API and any bugs.
19
+ Some features are not yet implemented. We are working on the documentation and will be adding more examples. Please
20
+ check out [any issue](https://github.com/CarbonORM/CarbonWordPress/issues) we have open and feel free to contribute.
21
+
22
+ ## Installation
23
+
24
+ CarbonNode is available on [NPM](https://www.npmjs.com/). You'll need to have [NodeJS](https://nodejs.org/en/) installed
25
+ which comes prepackaged with npm (node package manager).
26
+
27
+ ```bash
28
+ npm install @carbonorm/carbonnode
29
+ ```
30
+
31
+ ## Generate Models
32
+
33
+ The command below will generate the models for the database. The models will be generated in the output directory. We do
34
+ recommend you keep this folder separate from other work. It is also best to track the output directory in your version
35
+ control system. All arguments are optional. If you do not provide them the defaults will be used. The example arguments
36
+ below are the defaults.
37
+
38
+ ```bash
39
+ npx generateRestBindings --user root --pass password --host 127.0.0.1 --port 3306 --dbname carbonPHP --prefix carbon_ --output /src/api/rest
40
+ ```
41
+
42
+ You can view the [code generated](https://github.com/CarbonORM/CarbonORM.dev/blob/www/src/api/rest/Users.tsx) by
43
+ [this command](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/generateRestBindings.ts) in
44
+ [this repository](git@github.com:CarbonORM/CarbonNode.git). We use [Handlebars templates](https://mustache.github.io/)
45
+ to generate the code.
46
+
47
+ ### Generated Tests
48
+
49
+ Tests are generated for each table in the database. The tests are generated in the same directory as the models.
50
+ Our Jest tests are not designed to run immediately. You will need to edit the tests manually to change *xdescribe* with just
51
+ *describe*. Once a test does not have xdescribe it will no longer be updated with new generation changes.
52
+
53
+ Note - I prefer to keep tests nested in my IDE project viewer. See the documentation for
54
+ [IntelliJ](https://www.jetbrains.com/help/idea/file-nesting-dialog.html) or
55
+ [VSCode](https://code.visualstudio.com/updates/v1_67#_explorer-file-nesting).
56
+
57
+ ### Templates
58
+
59
+ Three templates are used to generate the models. The output will be multiple files; two files for each table in the
60
+ database consisting of your GET PUT POST and DELETE methods and a Jest test file, a C6.tsx file which contains all
61
+ table information and TypeScript types, and finally a websocket file which contains references to methods that are
62
+ generate. Here are the templates used to generate the code:
63
+
64
+ 1) [C6.ts.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/C6.ts.handlebars)
65
+ 2) [Table.ts.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/Table.ts.handlebars)
66
+ 3) [Websocket.ts.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/WsLiveUpdates.ts.handlebars)
67
+
68
+
69
+ # Support and Issues
70
+
71
+ Any issues found should be reported on [GitHub](https://github.com/CarbonORM/CarbonNode/issues).
8
72
 
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.0",
3
+ "version": "1.4.1",
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",
@@ -290,15 +290,15 @@ var tableData = parseSQLToTypeScript(sql);
290
290
  // write to file
291
291
  fs.writeFileSync(path.join(process.cwd(), 'C6MySqlDump.json'), JSON.stringify(tableData));
292
292
  // import this file src/assets/handlebars/C6.tsx.handlebars for a mustache template
293
- var c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.tsx.handlebars'), 'utf-8');
294
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.tsx'), Handlebars.compile(c6Template)(tableData));
295
- var wsLiveUpdatesTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/WsLiveUpdates.tsx.handlebars'), 'utf-8');
296
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'WsLiveUpdates.tsx'), Handlebars.compile(wsLiveUpdatesTemplate)(tableData));
297
- var template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.tsx.handlebars'), 'utf-8');
298
- var testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.tsx.handlebars'), 'utf-8');
293
+ var c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.ts.handlebars'), 'utf-8');
294
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.ts'), Handlebars.compile(c6Template)(tableData));
295
+ var wsLiveUpdatesTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/WsLiveUpdates.ts.handlebars'), 'utf-8');
296
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'WsLiveUpdates.ts'), Handlebars.compile(wsLiveUpdatesTemplate)(tableData));
297
+ var template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.ts.handlebars'), 'utf-8');
298
+ var testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.ts.handlebars'), 'utf-8');
299
299
  Object.values(tableData.TABLES).map(function (tableData, key) {
300
300
  var tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE;
301
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.tsx'), Handlebars.compile(template)(tableData));
302
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.tsx'), Handlebars.compile(testTemplate)(tableData));
301
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.ts'), Handlebars.compile(template)(tableData));
302
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.ts'), Handlebars.compile(testTemplate)(tableData));
303
303
  });
304
304
  console.log('Successfully created CarbonORM bindings!');
@@ -377,30 +377,27 @@ const tableData = parseSQLToTypeScript(sql);
377
377
  // write to file
378
378
  fs.writeFileSync(path.join(process.cwd(), 'C6MySqlDump.json'), JSON.stringify(tableData));
379
379
 
380
-
381
380
  // import this file src/assets/handlebars/C6.tsx.handlebars for a mustache template
381
+ const c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.ts.handlebars'), 'utf-8');
382
382
 
383
- const c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.tsx.handlebars'), 'utf-8');
384
-
385
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.tsx'), Handlebars.compile(c6Template)(tableData));
383
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.ts'), Handlebars.compile(c6Template)(tableData));
386
384
 
387
- const wsLiveUpdatesTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/WsLiveUpdates.tsx.handlebars'), 'utf-8');
385
+ const wsLiveUpdatesTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/WsLiveUpdates.ts.handlebars'), 'utf-8');
388
386
 
389
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'WsLiveUpdates.tsx'), Handlebars.compile(wsLiveUpdatesTemplate)(tableData));
387
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'WsLiveUpdates.ts'), Handlebars.compile(wsLiveUpdatesTemplate)(tableData));
390
388
 
391
- const template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.tsx.handlebars'), 'utf-8');
389
+ const template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.ts.handlebars'), 'utf-8');
392
390
 
393
- const testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.tsx.handlebars'), 'utf-8');
391
+ const testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.ts.handlebars'), 'utf-8');
394
392
 
395
393
  Object.values(tableData.TABLES).map((tableData, key) => {
396
394
 
397
395
  const tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE
398
396
 
399
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.tsx'), Handlebars.compile(template)(tableData));
397
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.ts'), Handlebars.compile(template)(tableData));
400
398
 
401
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.tsx'), Handlebars.compile(testTemplate)(tableData));
399
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.ts'), Handlebars.compile(testTemplate)(tableData));
402
400
 
403
401
  })
404
402
 
405
403
  console.log('Successfully created CarbonORM bindings!')
406
-