org-core-js 0.0.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 +446 -0
- package/babel.config.json +13 -0
- package/cjs/core/driverCore.js +37 -0
- package/cjs/core/drivers/bull.js +56 -0
- package/cjs/core/drivers/fogu.js +14 -0
- package/cjs/core/drivers/mq.js +50 -0
- package/cjs/core/drivers/nats.js +161 -0
- package/cjs/core/drivers/osone.js +14 -0
- package/cjs/core/drivers/rabbitmq.js +68 -0
- package/cjs/core/drivers/redis.js +68 -0
- package/cjs/core/drivers/socket.js +36 -0
- package/cjs/core/entityCore.js +22 -0
- package/cjs/core/eventCore.js +26 -0
- package/cjs/core/index.js +477 -0
- package/cjs/core/libCore.js +22 -0
- package/cjs/core/repositoryCore.js +30 -0
- package/cjs/core/serverCore.js +142 -0
- package/cjs/core/serviceCore.js +26 -0
- package/cjs/core/utilCore.js +22 -0
- package/cjs/core/workerCore.js +27 -0
- package/cjs/fileCore.js +27 -0
- package/cjs/forawait.js +55 -0
- package/cjs/index.js +117 -0
- package/cjs/package.json +3 -0
- package/esm/core/driverCore.js +33 -0
- package/esm/core/drivers/bull.js +49 -0
- package/esm/core/drivers/fogu.js +12 -0
- package/esm/core/drivers/nats.js +160 -0
- package/esm/core/drivers/rabbitmq.js +64 -0
- package/esm/core/drivers/redis.js +71 -0
- package/esm/core/drivers/socket.js +28 -0
- package/esm/core/entityCore.js +12 -0
- package/esm/core/eventCore.js +17 -0
- package/esm/core/index.js +440 -0
- package/esm/core/libCore.js +13 -0
- package/esm/core/repositoryCore.js +25 -0
- package/esm/core/serverCore.js +155 -0
- package/esm/core/serviceCore.js +17 -0
- package/esm/core/utilCore.js +12 -0
- package/esm/core/workerCore.js +20 -0
- package/esm/fileCore.js +19 -0
- package/esm/forawait.js +48 -0
- package/esm/index.js +128 -0
- package/esm/package.json +3 -0
- package/lib/index.html +1021 -0
- package/package.json +73 -0
- package/src/app/events/test/app.js +13 -0
- package/src/app/events/test/ws.js +14 -0
- package/src/app/services/test/app.js +14 -0
- package/src/app/services/test/app1.js +11 -0
- package/src/core/entities/user.js +14 -0
- package/src/core/libs/hash.js +10 -0
- package/src/core/utils/auth.js +19 -0
- package/src/index.js +11 -0
- package/src/infra/db/index.js +7 -0
- package/src/infra/repositories/test/app.js +6 -0
- package/src/infra/web/http.js +15 -0
- package/src/infra/web/routers/auth.js +30 -0
- package/src/infra/web/routers/test.js +26 -0
- package/src/infra/web/ws/test.js +35 -0
- package/src/infra/workers/test/test.md +14 -0
- package/src/start.js +39 -0
- package/test/core.test.js +46 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
export default ({ core }) => {
|
|
3
|
+
return async ({ path = '/src/infra/workers' }, obj) => {
|
|
4
|
+
const paths = core.fileCore.paths(path)
|
|
5
|
+
|
|
6
|
+
if (!paths.length) return
|
|
7
|
+
await core.forawait.generate(paths, async (path_,) => {
|
|
8
|
+
const path_files = core.fileCore.paths(path + '/' + path_)
|
|
9
|
+
await core.forawait.generate(path_files, async (path_file = '') => {
|
|
10
|
+
if (!(path_file.includes('.js') || path_file.includes('.ts'))) return
|
|
11
|
+
await core.import.job(path + '/' + path_ + '/' + path_file, {
|
|
12
|
+
path: path_,
|
|
13
|
+
file: path_file
|
|
14
|
+
}, obj)
|
|
15
|
+
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
}
|
package/esm/fileCore.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
export default {
|
|
4
|
+
path: process.cwd(),
|
|
5
|
+
async import(file, obj = {}) {
|
|
6
|
+
return (await import('file://' + path.resolve(this.path + file))).default(obj)
|
|
7
|
+
},
|
|
8
|
+
async importFile(file) {
|
|
9
|
+
return (await import('file://' + path.resolve(this.path + file)))
|
|
10
|
+
},
|
|
11
|
+
exist(path_file) {
|
|
12
|
+
return fs.existsSync(path.resolve(this.path + path_file))
|
|
13
|
+
},
|
|
14
|
+
paths(paths) {
|
|
15
|
+
if (!this.exist(paths)) return []
|
|
16
|
+
return fs.readdirSync(path.resolve(this.path + paths))
|
|
17
|
+
},
|
|
18
|
+
bin: fs.existsSync(process.cwd() + '/esm') ? '/esm' : '/node_modules/create-org-app/esm',
|
|
19
|
+
}
|
package/esm/forawait.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
generator: function* generator(array) {
|
|
3
|
+
for (let index = 0; index < array.length; index++) {
|
|
4
|
+
yield array[index];
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
generator_fn: function* generator(data) {
|
|
9
|
+
if (Array.isArray(data)) {
|
|
10
|
+
for (let index = 0; index < data.length; index++) {
|
|
11
|
+
yield { data: data[index], index };
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
} else {
|
|
15
|
+
data = Object.entries(data)
|
|
16
|
+
|
|
17
|
+
for (let index = 0; index < data.length; index++) {
|
|
18
|
+
yield { data: data[index][1], name: data[index][0] };
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
generate: async function (data, fn, ops = {}, fun_error = console.log) {
|
|
26
|
+
let flag = false;
|
|
27
|
+
const fn_g = this.generator_fn(data)
|
|
28
|
+
while (!flag) {
|
|
29
|
+
const { value, done } = fn_g.next()
|
|
30
|
+
if (value) {
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
await fn(value.data, { ...ops, index: value.index, name: value.name })
|
|
34
|
+
} catch (error) {
|
|
35
|
+
try {
|
|
36
|
+
await fun_error(error)
|
|
37
|
+
} catch (error) {
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
flag = done
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import env from 'dotenv'
|
|
2
|
+
env.config()
|
|
3
|
+
import fileCore from "./fileCore.js"
|
|
4
|
+
import coreCreate from "./core/index.js"
|
|
5
|
+
import forawait from "./forawait.js"
|
|
6
|
+
|
|
7
|
+
const app = {
|
|
8
|
+
async run({ servers, drivers, bootFile = "/src/index.js" }) {
|
|
9
|
+
const initBoot = (await fileCore.importFile(bootFile))
|
|
10
|
+
const { bootstrap, distroy } = initBoot.default || initBoot
|
|
11
|
+
|
|
12
|
+
const sys = coreCreate({})
|
|
13
|
+
await sys.createLib({}, {})
|
|
14
|
+
await sys.createUtil({}, {})
|
|
15
|
+
await sys.createEntity({}, {})
|
|
16
|
+
await sys.createRepository({}, {})
|
|
17
|
+
await sys.createService({}, {})
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
await forawait.generate(drivers, async (driver) => {
|
|
21
|
+
await sys.createDriver(driver)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
await sys.createEvent({}, {})
|
|
27
|
+
await sys.createWorker({}, {})
|
|
28
|
+
|
|
29
|
+
await forawait.generate(servers, async (server) => {
|
|
30
|
+
await sys.createServer(server)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
process.on('uncaughtException', (error, origin) => {
|
|
35
|
+
console.log(`\n${origin} signal received. \n${error}`)
|
|
36
|
+
})
|
|
37
|
+
process.on('SIGINT', grafulShutdown('SIGINT'))
|
|
38
|
+
process.on('SIGTERM', grafulShutdown('SIGTERM'))
|
|
39
|
+
process.on('exit', async (code) => {
|
|
40
|
+
try {
|
|
41
|
+
await distroy({
|
|
42
|
+
sys: {
|
|
43
|
+
...sys.core.import
|
|
44
|
+
},
|
|
45
|
+
core: {
|
|
46
|
+
...sys.core.app
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
} catch (error) {
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
console.log('exit signal received', code)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
function grafulShutdown(event) {
|
|
57
|
+
return async (code) => {
|
|
58
|
+
console.log(`${event} received! with ${code}`)
|
|
59
|
+
try {
|
|
60
|
+
await distroy({
|
|
61
|
+
sys: {
|
|
62
|
+
...sys.core.import
|
|
63
|
+
},
|
|
64
|
+
core: {
|
|
65
|
+
...sys.core.app
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
} catch (error) {
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
process.exit(0)
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
await bootstrap({
|
|
77
|
+
sys: {
|
|
78
|
+
...sys.core.import
|
|
79
|
+
},
|
|
80
|
+
core: {
|
|
81
|
+
...sys.core.app
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
const testApp = {
|
|
91
|
+
async run({ db = {}, setDB = null } = {}) {
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
const sys = coreCreate({})
|
|
95
|
+
await sys.createLib({}, {})
|
|
96
|
+
await sys.createUtil({}, {})
|
|
97
|
+
await sys.createEntity({}, {})
|
|
98
|
+
await sys.createEvent({}, {})
|
|
99
|
+
await sys.createService({}, {})
|
|
100
|
+
process.env.DB_TEST = "True"
|
|
101
|
+
await sys.createRepository({}, {
|
|
102
|
+
db: db,
|
|
103
|
+
getDB: setDB
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
process.on('uncaughtException', (error, origin) => {
|
|
107
|
+
console.log(`\n${origin} signal received. \n${error}`)
|
|
108
|
+
})
|
|
109
|
+
process.on('SIGINT', grafulShutdown('SIGINT'))
|
|
110
|
+
process.on('SIGTERM', grafulShutdown('SIGTERM'))
|
|
111
|
+
process.on('exit', async (code) => {
|
|
112
|
+
console.log('exit signal received', code)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
function grafulShutdown(event) {
|
|
117
|
+
return async (code) => {
|
|
118
|
+
console.log(`${event} received! with ${code}`)
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return { core: { ...sys.core.app } }
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { app, testApp }
|
package/esm/package.json
ADDED