binhend 2.1.36 → 2.2.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.
Files changed (39) hide show
  1. package/demo.js +93 -7
  2. package/index.js +1 -46
  3. package/index2.js +56 -0
  4. package/package.json +4 -6
  5. package/src2/csd/csd.js +0 -0
  6. package/{src → src2}/csd/service.js +4 -8
  7. package/src2/types/common.d.ts +10 -0
  8. package/src2/types/index.d.ts +2 -0
  9. package/src2/utils/typedefs.js +31 -0
  10. package/{src → src2}/web/index.js +1 -1
  11. /package/{src → src2}/alias-cjs-loader.js +0 -0
  12. /package/{src → src2}/alias-esm-loader.js +0 -0
  13. /package/{src → src2}/alias-module.js +0 -0
  14. /package/{src → src2}/api/HttpCodes.js +0 -0
  15. /package/{src → src2}/api/HttpError.js +0 -0
  16. /package/{src → src2}/api/Router.js +0 -0
  17. /package/{src → src2}/api/responseErrorByDefault.js +0 -0
  18. /package/{src → src2}/api/routes.js +0 -0
  19. /package/{src → src2}/api/trycatch.js +0 -0
  20. /package/{src → src2}/configuration.js +0 -0
  21. /package/{src → src2}/crypto.js +0 -0
  22. /package/{src → src2}/csd/controller.js +0 -0
  23. /package/{src → src2}/csd/dao.js +0 -0
  24. /package/{src → src2}/csd/index.js +0 -0
  25. /package/{src → src2}/https.js +0 -0
  26. /package/{src → src2}/middleware/cors.js +0 -0
  27. /package/{src → src2}/middleware/parseBasicAuthToken.js +0 -0
  28. /package/{src → src2}/middleware/parseCookies.js +0 -0
  29. /package/{src → src2}/server.js +0 -0
  30. /package/{src → src2}/utils/Bromise.js +0 -0
  31. /package/{src → src2}/utils/types.js +0 -0
  32. /package/{src → src2}/utils/validation.js +0 -0
  33. /package/{src → src2}/web/code.js +0 -0
  34. /package/{src → src2}/web/component.build.js +0 -0
  35. /package/{src → src2}/web/component.file.js +0 -0
  36. /package/{src → src2}/web/component.format.js +0 -0
  37. /package/{src → src2}/web/component.js +0 -0
  38. /package/{src → src2}/web/component.method.js +0 -0
  39. /package/{src → src2}/web/file-check.js +0 -0
package/demo.js CHANGED
@@ -1,17 +1,103 @@
1
1
 
2
- const { HttpCodes, ConfigLoader, WebBuilder, HttpError, validation } = require('./index');
2
+ const { HttpCodes, ConfigLoader, WebBuilder, HttpError, validation, createCSD } = require('./index2');
3
3
  const path = require('path');
4
4
 
5
5
  // var jsonPath = __dirname + '/jsconfig.json';
6
6
  // var cc = ConfigLoader.json(jsonPath);
7
7
  // console.log('cc', cc);
8
8
 
9
- const config = {};
10
- console.log('config', config);
11
- const loader = new ConfigLoader(config);
9
+ // const config = {};
10
+ // console.log('config', config);
11
+ // const loader = new ConfigLoader(config);
12
12
 
13
- loader.object({ foo: '1', koo: '2', hoo: '3' }, { filter: ['koo', 'hoo'] });
13
+ // loader.object({ foo: '1', koo: '2', hoo: '3' }, { filter: ['koo', 'hoo'] });
14
14
 
15
- console.log('config', config);
15
+ // console.log('config', config);
16
+
17
+ // console.log(path.resolve(__dirname, './app.secret'));
18
+
19
+ function MongooseCSD(Model) {
20
+ /** CREATE */
21
+
22
+ this.create = async (data) => {
23
+ console.log('create', arguments);
24
+ // return await new Model(data).save();
25
+ return await Model.create(data);
26
+ };
27
+
28
+ this.upsert = async (query, data) => {
29
+ console.log('upsert', arguments);
30
+ return await Model.findOneAndUpdate(query, data, { new: true, upsert: true });
31
+ };
32
+
33
+ /** READ */
34
+
35
+ this.getAll = async () => {
36
+ console.log('getAll', arguments);
37
+ return await Model.find({});
38
+ };
39
+
40
+ this.getByID = async (id) => {
41
+ console.log('getByID', arguments);
42
+ return await Model.findById(id);
43
+ };
44
+
45
+ this.getByQuery = async (query) => {
46
+ console.log('getByQuery', arguments);
47
+ return await Model.find(query);
48
+ };
49
+
50
+ /** UPDATE */
51
+
52
+ this.updateAll = async (data) => {
53
+ console.log('updateAll', data);
54
+ return await Model.updateMany({}, data);
55
+ };
56
+
57
+ this.updateByID = async (id, data) => {
58
+ console.log('updateByID', arguments);
59
+ return await Model.findByIdAndUpdate(id, data, { new: true });
60
+ };
61
+
62
+ this.updateByQuery = async (query, data) => {
63
+ console.log('updateByQuery', arguments);
64
+ return await Model.updateMany(query, data);
65
+ };
66
+
67
+ /** DELETE */
68
+
69
+ this.deleteAll = async () => {
70
+ console.log('deleteAll', arguments);
71
+ return await Model.deleteMany({});
72
+ };
73
+
74
+ this.deleteByID = async (id) => {
75
+ console.log('deleteByID', arguments);
76
+ return await Model.findByIdAndDelete(id);
77
+ };
78
+
79
+ this.deleteByQuery = async (query) => {
80
+ console.log('deleteByQuery', arguments);
81
+ return await Model.deleteMany(query);
82
+ };
83
+ }
84
+
85
+ const createMongooseCSD = createCSD(MongooseCSD);
86
+
87
+ const csd = createMongooseCSD({});
88
+
89
+ csd.controller.create;
90
+ csd.service.create;
91
+
92
+ csd.dao;
93
+
94
+ async function abc() {
95
+ return csd.service.create({ a: 1 });
96
+ }
97
+
98
+
99
+
100
+ (async function () {
101
+ var cc = await abc();
102
+ })();
16
103
 
17
- console.log(path.resolve(__dirname, './app.secret'));
package/index.js CHANGED
@@ -6,51 +6,6 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- /** SERVER - Backend */
10
- const { server } = require('./src/server');
11
- const { ConfigLoader, config } = require('./src/configuration');
12
- const { HTTPS } = require('./src/https');
13
-
14
- const HttpError = require('./src/api/HttpError');
15
- const HttpCodes = require('./src/api/HttpCodes');
16
-
17
- const Router = require('./src/api/Router');
18
- const { routes, loadRoutes, buildRoutes, mapRoutes } = require('./src/api/routes');
19
- const trycatch = require('./src/api/trycatch');
20
-
21
- const cors = require('./src/middleware/cors');
22
-
23
- const createCSD = require('./src/csd');
24
- const crypto = require('./src/crypto');
25
- const types = require('./src/utils/types');
26
- const validation = require('./src/utils/validation');
27
- const typedefs = require('./src/utils/typedefs');
28
- const Bromise = require('./src/utils/Bromise.js');
29
-
30
- /** CLIENT - Frontend */
31
- const { WebBuild } = require('./src/web');
32
- const { binh } = require('./src/web/component.method');
33
-
34
- // Run scripts
35
- require('./src/alias-module');
36
-
37
9
  module.exports = {
38
- server,
39
- ConfigLoader, config,
40
- HTTPS,
41
- HttpError,
42
- HttpCodes,
43
- Router,
44
- routes, buildRoutes, loadRoutes, mapRoutes,
45
- trycatch,
46
- cors,
47
- createCSD,
48
- crypto,
49
- types,
50
- typedefs,
51
- validation,
52
- Bromise,
53
- WebBuild,
54
- WebBuilder: WebBuild,
55
- binh
10
+ ...require('@binhend/core'),
56
11
  };
package/index2.js ADDED
@@ -0,0 +1,56 @@
1
+ /*
2
+ * binhend
3
+ * Copyright(c) 2023 Nguyen Duc Binh
4
+ *
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ /** SERVER - Backend */
10
+ const { server } = require('./src/server');
11
+ const { ConfigLoader, config } = require('./src/configuration');
12
+ const { HTTPS } = require('./src/https');
13
+
14
+ const HttpError = require('./src/api/HttpError');
15
+ const HttpCodes = require('./src/api/HttpCodes');
16
+
17
+ const Router = require('./src/api/Router');
18
+ const { routes, loadRoutes, buildRoutes, mapRoutes } = require('./src/api/routes');
19
+ const trycatch = require('./src/api/trycatch');
20
+
21
+ const cors = require('./src/middleware/cors');
22
+
23
+ const createCSD = require('./src/csd');
24
+ const crypto = require('./src/crypto');
25
+ const types = require('./src/utils/types');
26
+ const validation = require('./src/utils/validation');
27
+ const typedefs = require('./src/utils/typedefs');
28
+ const Bromise = require('./src/utils/Bromise.js');
29
+
30
+ /** CLIENT - Frontend */
31
+ const { WebBuild } = require('./src/web');
32
+ const { binh } = require('./src/web/component.method');
33
+
34
+ // Run scripts
35
+ require('./src/alias-module');
36
+
37
+ module.exports = {
38
+ server,
39
+ ConfigLoader, config,
40
+ HTTPS,
41
+ HttpError,
42
+ HttpCodes,
43
+ Router,
44
+ routes, buildRoutes, loadRoutes, mapRoutes,
45
+ trycatch,
46
+ cors,
47
+ createCSD,
48
+ crypto,
49
+ types,
50
+ typedefs,
51
+ validation,
52
+ Bromise,
53
+ WebBuild,
54
+ WebBuilder: WebBuild,
55
+ binh
56
+ };
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.1.36",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
7
- "license": "UNLICENSED",
7
+ "license": "MIT",
8
8
  "bin": {
9
9
  "binhend": "./bin/index.js"
10
10
  },
11
11
  "workspaces": [
12
+ "packages/*",
12
13
  "test"
13
14
  ],
14
15
  "scripts": {
@@ -21,10 +22,7 @@
21
22
  "example-web2": "node example_web2"
22
23
  },
23
24
  "dependencies": {
24
- "express": "^4.17.1",
25
- "js-beautify": "^1.15.1",
26
- "uglify-js": "^3.17.4",
27
- "uglifycss": "^0.0.29"
25
+ "@binhend/core": "^1.0.0"
28
26
  },
29
27
  "engines": {
30
28
  "node": ">=20.18.0",
File without changes
@@ -1,7 +1,6 @@
1
1
 
2
2
  function Service(dao) {
3
- /** CREATE */
4
-
3
+ //___ CREATE ___//
5
4
  this.create = async (data) => {
6
5
  return await dao.create(data);
7
6
  };
@@ -10,8 +9,7 @@ function Service(dao) {
10
9
  return await dao.upsert(query, data);
11
10
  };
12
11
 
13
- /** READ */
14
-
12
+ //___ READ ___//
15
13
  this.getAll = async () => {
16
14
  return await dao.getAll();
17
15
  };
@@ -24,8 +22,7 @@ function Service(dao) {
24
22
  return await dao.getByQuery(query);
25
23
  };
26
24
 
27
- /** UPDATE */
28
-
25
+ //___ UPDATE ___//
29
26
  this.updateAll = async (data) => {
30
27
  return await dao.updateAll(data);
31
28
  };
@@ -38,8 +35,7 @@ function Service(dao) {
38
35
  return await dao.updateByQuery(query, data);
39
36
  };
40
37
 
41
- /** DELETE */
42
-
38
+ //___ DELETE ___//
43
39
  this.deleteAll = async () => {
44
40
  return await dao.deleteAll();
45
41
  };
@@ -0,0 +1,10 @@
1
+
2
+ /**
3
+ * @typedef {Object<string, any>} ObjectType
4
+ */
5
+
6
+ /**
7
+ * @typedef {(Date|string|number)} DateType
8
+ */
9
+
10
+ export {};
@@ -0,0 +1,2 @@
1
+
2
+ export * from './common.d.ts';
@@ -0,0 +1,31 @@
1
+
2
+ /**
3
+ * @typedef {Object<string, any>} ObjectType
4
+ */
5
+
6
+ /**
7
+ * Type definition for object accepting any extra properties
8
+ *
9
+ * @returns {ObjectType}
10
+ */
11
+ function ObjectType() { return this; }
12
+
13
+
14
+
15
+ /**
16
+ * @typedef {(Date|string|number)} DateType
17
+ */
18
+
19
+ /**
20
+ * Type definition for date accepting any valid formats (string, number, date)
21
+ *
22
+ * @returns {DateType}
23
+ */
24
+ function DateType() { return this; }
25
+
26
+
27
+
28
+ module.exports = {
29
+ ObjectType,
30
+ DateType
31
+ };
@@ -22,8 +22,8 @@ function WebBuild(source, { output, external } = {}) {
22
22
 
23
23
  if (source === path.resolve(output)) throw new Error(`[BINHEND][WEB] Location of build output & source code should NOT be the same: ${source}`);
24
24
 
25
+ var web = path.resolve(output, DEFAULT_DIR_BUILD_WEB);
25
26
  var module = path.resolve(output, DEFAULT_DIR_BUILD_MODULE);
26
- var web = path.resolve(output, DEFAULT_DIR_BUILD_MODULE);
27
27
  var external = mustString(external) || DEFAULT_DIR_BUILD_EXTERNAL;
28
28
 
29
29
  this.bundle = () => {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes