pwi-plata-type 0.4.166 → 0.4.167
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 +2 -2
- package/__BUILD__/libs/sql.js +4 -1
- package/__BUILD__/libs/sql.js.map +1 -1
- package/package.json +53 -53
- package/src/@types/build.d.ts +26 -26
- package/src/@types/cluster.actions.d.ts +27 -27
- package/src/@types/cluster.d.ts +55 -55
- package/src/@types/create-cli.d.ts +8 -8
- package/src/@types/exported.d.ts +31 -31
- package/src/@types/fs.d.ts +6 -6
- package/src/@types/global.d.ts +113 -113
- package/src/@types/knex.d.ts +13 -13
- package/src/@types/model.d.ts +143 -143
- package/src/@types/router.d.ts +107 -107
- package/src/@types/sql.d.ts +75 -75
- package/src/@types/swagger.d.ts +22 -22
- package/src/bin/extras/create-api-cli.ts +218 -218
- package/src/bin/extras/create-cluster-cli.ts +160 -160
- package/src/bin/extras/create-lib-cli.ts +84 -84
- package/src/bin/extras/plata-create-tools.ts +97 -97
- package/src/bin/plata-api.ts +189 -189
- package/src/bin/plata-build.ts +17 -17
- package/src/bin/plata-cluster.ts +42 -42
- package/src/bin/plata-cmd.ts +18 -18
- package/src/bin/plata-create.ts +49 -49
- package/src/bin/plata-runtime.ts +131 -131
- package/src/bin/plata-swagger.ts +99 -99
- package/src/bin/runtime/_setupRuntime.ts +48 -48
- package/src/bin/runtime/_types.d.ts +7 -7
- package/src/bin/runtime/class.ts +20 -20
- package/src/bin/runtime/dirs.ts +25 -25
- package/src/bin/runtime/effect.ts +60 -60
- package/src/bin/runtime/fs.ts +10 -10
- package/src/bin/runtime/promises.ts +18 -18
- package/src/bin/runtime/require.ts +113 -113
- package/src/bin/runtime/sql.ts +12 -12
- package/src/bin/runtime/switch.ts +60 -60
- package/src/index.ts +19 -19
- package/src/libs/axios.ts +51 -51
- package/src/libs/build.ts +162 -162
- package/src/libs/cluster/cluster-controller.ts +93 -93
- package/src/libs/cluster.ts +330 -330
- package/src/libs/custom.ts +15 -15
- package/src/libs/env.ts +10 -10
- package/src/libs/fs.ts +399 -399
- package/src/libs/hot-reload.ts +63 -63
- package/src/libs/models/index.ts +4 -4
- package/src/libs/models/model-template-combine.ts +93 -93
- package/src/libs/models/model-template-env.ts +58 -58
- package/src/libs/models/model-template-union.ts +83 -83
- package/src/libs/models/model-template.ts +107 -107
- package/src/libs/models/model-validations.ts +443 -443
- package/src/libs/models/tools.ts +194 -194
- package/src/libs/router.ts +185 -185
- package/src/libs/sql.ts +792 -788
- package/src/libs/swagger.ts +81 -81
- package/src/libs/tools.ts +240 -240
- package/src/scripts/post-install/api.ts +32 -32
- package/src/scripts/post-install/cluster.ts +28 -28
- package/src/scripts/post-install/lib.ts +25 -25
- package/src/scripts/post-install.ts +64 -64
- package/src/scripts/pre-test.ts +33 -33
- package/src/tests/assets/sql/example.sql +76 -76
- package/src/tests/config.test.ts +12 -12
- package/src/tests/effect.test.ts +62 -62
- package/src/tests/model.env.test.ts +66 -66
- package/src/tests/model.test.ts +141 -141
- package/src/tests/model.union.test.ts +160 -160
- package/src/tests/router.test.ts +44 -44
- package/src/tests/sql.test.ts +502 -502
- package/src/tests/switch.test.ts +76 -76
- package/templates/create-cli/class.ts +13 -13
- package/templates/create-cli/cluster.ts +14 -14
- package/templates/create-cli/cmd.ts +3 -3
- package/templates/create-cli/config.ts +2 -2
- package/templates/create-cli/lib.ts +3 -3
- package/templates/create-cli/model.ts +14 -14
- package/templates/create-cli/route.ts +8 -8
- package/templates/create-cli/task.ts +13 -13
- package/templates/postinstall/api/.vscode/launch.json +20 -20
- package/templates/postinstall/api/Dockerfile +24 -24
- package/templates/postinstall/api/configs/env.ts +2 -2
- package/templates/postinstall/api/envs/debug.env +15 -15
- package/templates/postinstall/api/envs/homolog.env +15 -15
- package/templates/postinstall/api/envs/prod.env +15 -15
- package/templates/postinstall/api/tsconfig.json +24 -24
- package/templates/postinstall/cluster/.vscode/launch.json +20 -20
- package/templates/postinstall/cluster/Dockerfile +24 -24
- package/templates/postinstall/cluster/configs/env.ts +2 -2
- package/templates/postinstall/cluster/envs/debug.env +10 -10
- package/templates/postinstall/cluster/envs/homolog.env +10 -10
- package/templates/postinstall/cluster/envs/prod.env +10 -10
- package/templates/postinstall/cluster/tsconfig.json +24 -24
- package/templates/postinstall/lib/postinstall-tools.mjs +111 -111
- package/templates/postinstall/lib/postinstall.js +33 -33
- package/templates/postinstall/lib/tsconfig.json +22 -22
- package/templates/swagger-cli/header.json +21 -21
- package/templates/swagger-cli/route/body.json +14 -14
- package/templates/swagger-cli/route/header.json +18 -18
- package/templates/swagger-cli/route/response.json +53 -53
- package/tsconfig.json +28 -28
package/src/bin/plata-swagger.ts
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import fs from 'node:fs'
|
|
3
|
-
import { buildExpressRouter, loadRoutesFromProject } from "++/libs/router"
|
|
4
|
-
|
|
5
|
-
export async function dumpRoutes() {
|
|
6
|
-
const requiredRoutes = await loadRoutesFromProject()
|
|
7
|
-
|
|
8
|
-
if (requiredRoutes.errorID !== undefined) {
|
|
9
|
-
console.log(requiredRoutes)
|
|
10
|
-
process.exit(1)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const router = await buildExpressRouter(requiredRoutes)
|
|
14
|
-
|
|
15
|
-
if (router.errorID !== undefined) {
|
|
16
|
-
console.log(router)
|
|
17
|
-
process.exit(1)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const dumpedRoutes: SwaggerGen.Route[] = []
|
|
21
|
-
const regex = /:(.*?)\??\//g
|
|
22
|
-
|
|
23
|
-
for (const r of router.routes) {
|
|
24
|
-
if (r.swaggerHide) {
|
|
25
|
-
continue
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
r.path = path.normalize(`${r.path ?? '/'}/`).replace(/\\/g, '/')
|
|
29
|
-
|
|
30
|
-
const dumpedRouteParams: SwaggerGen.RouteParameter[] = []
|
|
31
|
-
const urlParms = r.path.match(regex) ?? []
|
|
32
|
-
|
|
33
|
-
for (const p of urlParms) {
|
|
34
|
-
dumpedRouteParams.push({
|
|
35
|
-
name: p.replace(regex, '$1'),
|
|
36
|
-
required: p[p.length - 2] !== '?',
|
|
37
|
-
in: 'path',
|
|
38
|
-
type: 'string'
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
dumpedRoutes.push({
|
|
43
|
-
httpRoute: r.path.replace(regex, '{$1}/'),
|
|
44
|
-
method: r.method,
|
|
45
|
-
params: dumpedRouteParams,
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return dumpedRoutes
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export async function toProjectSwagger(file: string, content: any): Promise<void> {
|
|
53
|
-
try {
|
|
54
|
-
const p = path.resolve(Plata.ProjectDir, 'swagger', file)
|
|
55
|
-
|
|
56
|
-
if (!fs.existsSync(p)) {
|
|
57
|
-
fs.mkdirSync(path.dirname(p), { recursive: true })
|
|
58
|
-
fs.writeFileSync(p, JSON.stringify(content, null, 4))
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
} catch (e) {
|
|
62
|
-
console.log(e)
|
|
63
|
-
process.exit(1)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export const main = async () => {
|
|
68
|
-
const routes = await dumpRoutes()
|
|
69
|
-
|
|
70
|
-
const templateFolder = path.join(Plata.PlataDir, 'templates', 'swagger-cli')
|
|
71
|
-
|
|
72
|
-
const files: SwaggerGen.Files = {
|
|
73
|
-
swaggerHeader: require(path.join(templateFolder, 'header.json')),
|
|
74
|
-
route: {
|
|
75
|
-
header: require(path.join(templateFolder, 'route', 'header.json')),
|
|
76
|
-
body: require(path.join(templateFolder, 'route', 'body.json')),
|
|
77
|
-
response: require(path.join(templateFolder, 'route', 'response.json')),
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
for (const route of routes) {
|
|
82
|
-
|
|
83
|
-
// https://developer.mozilla.org/en-US/docs/Glossary/Deep_copy
|
|
84
|
-
const fileCopy:SwaggerGen.Files = JSON.parse(JSON.stringify(files))
|
|
85
|
-
|
|
86
|
-
for(const json in fileCopy.route) {
|
|
87
|
-
await toProjectSwagger(
|
|
88
|
-
path.join('routes', route.httpRoute, route.method.toLowerCase(), `${json}.json`),
|
|
89
|
-
fileCopy.route[json]
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
await toProjectSwagger(
|
|
95
|
-
'header.json',
|
|
96
|
-
files.swaggerHeader
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
console.log('Done')
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import { buildExpressRouter, loadRoutesFromProject } from "++/libs/router"
|
|
4
|
+
|
|
5
|
+
export async function dumpRoutes() {
|
|
6
|
+
const requiredRoutes = await loadRoutesFromProject()
|
|
7
|
+
|
|
8
|
+
if (requiredRoutes.errorID !== undefined) {
|
|
9
|
+
console.log(requiredRoutes)
|
|
10
|
+
process.exit(1)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const router = await buildExpressRouter(requiredRoutes)
|
|
14
|
+
|
|
15
|
+
if (router.errorID !== undefined) {
|
|
16
|
+
console.log(router)
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const dumpedRoutes: SwaggerGen.Route[] = []
|
|
21
|
+
const regex = /:(.*?)\??\//g
|
|
22
|
+
|
|
23
|
+
for (const r of router.routes) {
|
|
24
|
+
if (r.swaggerHide) {
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
r.path = path.normalize(`${r.path ?? '/'}/`).replace(/\\/g, '/')
|
|
29
|
+
|
|
30
|
+
const dumpedRouteParams: SwaggerGen.RouteParameter[] = []
|
|
31
|
+
const urlParms = r.path.match(regex) ?? []
|
|
32
|
+
|
|
33
|
+
for (const p of urlParms) {
|
|
34
|
+
dumpedRouteParams.push({
|
|
35
|
+
name: p.replace(regex, '$1'),
|
|
36
|
+
required: p[p.length - 2] !== '?',
|
|
37
|
+
in: 'path',
|
|
38
|
+
type: 'string'
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
dumpedRoutes.push({
|
|
43
|
+
httpRoute: r.path.replace(regex, '{$1}/'),
|
|
44
|
+
method: r.method,
|
|
45
|
+
params: dumpedRouteParams,
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return dumpedRoutes
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function toProjectSwagger(file: string, content: any): Promise<void> {
|
|
53
|
+
try {
|
|
54
|
+
const p = path.resolve(Plata.ProjectDir, 'swagger', file)
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(p)) {
|
|
57
|
+
fs.mkdirSync(path.dirname(p), { recursive: true })
|
|
58
|
+
fs.writeFileSync(p, JSON.stringify(content, null, 4))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.log(e)
|
|
63
|
+
process.exit(1)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const main = async () => {
|
|
68
|
+
const routes = await dumpRoutes()
|
|
69
|
+
|
|
70
|
+
const templateFolder = path.join(Plata.PlataDir, 'templates', 'swagger-cli')
|
|
71
|
+
|
|
72
|
+
const files: SwaggerGen.Files = {
|
|
73
|
+
swaggerHeader: require(path.join(templateFolder, 'header.json')),
|
|
74
|
+
route: {
|
|
75
|
+
header: require(path.join(templateFolder, 'route', 'header.json')),
|
|
76
|
+
body: require(path.join(templateFolder, 'route', 'body.json')),
|
|
77
|
+
response: require(path.join(templateFolder, 'route', 'response.json')),
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const route of routes) {
|
|
82
|
+
|
|
83
|
+
// https://developer.mozilla.org/en-US/docs/Glossary/Deep_copy
|
|
84
|
+
const fileCopy:SwaggerGen.Files = JSON.parse(JSON.stringify(files))
|
|
85
|
+
|
|
86
|
+
for(const json in fileCopy.route) {
|
|
87
|
+
await toProjectSwagger(
|
|
88
|
+
path.join('routes', route.httpRoute, route.method.toLowerCase(), `${json}.json`),
|
|
89
|
+
fileCopy.route[json]
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
await toProjectSwagger(
|
|
95
|
+
'header.json',
|
|
96
|
+
files.swaggerHeader
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
console.log('Done')
|
|
100
100
|
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import fs from 'node:fs/promises'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
|
|
4
|
-
export async function loadRuntimeLibs() {
|
|
5
|
-
const plata = Object.create(null)
|
|
6
|
-
|
|
7
|
-
const runtimeLibs: PlataResult<string[]> = await fs.readdir(path.join(__dirname)).catch(err => {
|
|
8
|
-
return {
|
|
9
|
-
errorID: 'PRLORUNTIME',
|
|
10
|
-
msg: err.message,
|
|
11
|
-
error: err
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
if (runtimeLibs.errorID !== undefined) {
|
|
16
|
-
console.error(runtimeLibs)
|
|
17
|
-
process.exit(1)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const promises = runtimeLibs.map(lib => Promise.resolve().then(() => new Promise(resolve => {
|
|
21
|
-
if (lib.slice(-4) === 'd.ts')
|
|
22
|
-
return resolve(true)
|
|
23
|
-
;
|
|
24
|
-
|
|
25
|
-
if (path.extname(lib) === '.map')
|
|
26
|
-
return resolve(true)
|
|
27
|
-
;
|
|
28
|
-
|
|
29
|
-
const r: { PlataRuntimeE?: any } = require(path.join(__dirname, lib))
|
|
30
|
-
|
|
31
|
-
if (r.PlataRuntimeE === undefined) {
|
|
32
|
-
return resolve(true)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
for (const key in r.PlataRuntimeE) {
|
|
36
|
-
plata[key] = r.PlataRuntimeE[key]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return resolve(true)
|
|
40
|
-
})))
|
|
41
|
-
|
|
42
|
-
await Promise.all(promises).catch(err => {
|
|
43
|
-
console.error(err)
|
|
44
|
-
process.exit(1)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return plata
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
export async function loadRuntimeLibs() {
|
|
5
|
+
const plata = Object.create(null)
|
|
6
|
+
|
|
7
|
+
const runtimeLibs: PlataResult<string[]> = await fs.readdir(path.join(__dirname)).catch(err => {
|
|
8
|
+
return {
|
|
9
|
+
errorID: 'PRLORUNTIME',
|
|
10
|
+
msg: err.message,
|
|
11
|
+
error: err
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
if (runtimeLibs.errorID !== undefined) {
|
|
16
|
+
console.error(runtimeLibs)
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const promises = runtimeLibs.map(lib => Promise.resolve().then(() => new Promise(resolve => {
|
|
21
|
+
if (lib.slice(-4) === 'd.ts')
|
|
22
|
+
return resolve(true)
|
|
23
|
+
;
|
|
24
|
+
|
|
25
|
+
if (path.extname(lib) === '.map')
|
|
26
|
+
return resolve(true)
|
|
27
|
+
;
|
|
28
|
+
|
|
29
|
+
const r: { PlataRuntimeE?: any } = require(path.join(__dirname, lib))
|
|
30
|
+
|
|
31
|
+
if (r.PlataRuntimeE === undefined) {
|
|
32
|
+
return resolve(true)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (const key in r.PlataRuntimeE) {
|
|
36
|
+
plata[key] = r.PlataRuntimeE[key]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return resolve(true)
|
|
40
|
+
})))
|
|
41
|
+
|
|
42
|
+
await Promise.all(promises).catch(err => {
|
|
43
|
+
console.error(err)
|
|
44
|
+
process.exit(1)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
return plata
|
|
49
49
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/// <reference path="class.ts" />
|
|
2
|
-
/// <reference path="dirs.ts" />
|
|
3
|
-
/// <reference path="promises.ts" />
|
|
4
|
-
/// <reference path="require.ts" />
|
|
5
|
-
/// <reference path="fs.ts" />
|
|
6
|
-
/// <reference path="sql.ts" />
|
|
7
|
-
/// <reference path="switch.ts" />
|
|
1
|
+
/// <reference path="class.ts" />
|
|
2
|
+
/// <reference path="dirs.ts" />
|
|
3
|
+
/// <reference path="promises.ts" />
|
|
4
|
+
/// <reference path="require.ts" />
|
|
5
|
+
/// <reference path="fs.ts" />
|
|
6
|
+
/// <reference path="sql.ts" />
|
|
7
|
+
/// <reference path="switch.ts" />
|
|
8
8
|
/// <reference path="effect.ts" />
|
package/src/bin/runtime/class.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface PlataRuntime extends PlataRuntimeEType {}
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
6
|
-
|
|
7
|
-
export namespace PlataRuntimeE {
|
|
8
|
-
export function CacheClass<T>(newFunction: (...args: any) => T): T {
|
|
9
|
-
const p = process as any
|
|
10
|
-
|
|
11
|
-
if (p.cache === undefined) {
|
|
12
|
-
p.cache = Object.create(null)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (p.cache[newFunction.name] === undefined) {
|
|
16
|
-
p.cache[newFunction.name] = newFunction()
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return p.cache[newFunction.name]
|
|
20
|
-
}
|
|
1
|
+
declare global {
|
|
2
|
+
interface PlataRuntime extends PlataRuntimeEType {}
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
6
|
+
|
|
7
|
+
export namespace PlataRuntimeE {
|
|
8
|
+
export function CacheClass<T>(newFunction: (...args: any) => T): T {
|
|
9
|
+
const p = process as any
|
|
10
|
+
|
|
11
|
+
if (p.cache === undefined) {
|
|
12
|
+
p.cache = Object.create(null)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (p.cache[newFunction.name] === undefined) {
|
|
16
|
+
p.cache[newFunction.name] = newFunction()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return p.cache[newFunction.name]
|
|
20
|
+
}
|
|
21
21
|
}
|
package/src/bin/runtime/dirs.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
interface PlataRuntime extends PlataRuntimeEType {}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
9
|
-
|
|
10
|
-
export namespace PlataRuntimeE {
|
|
11
|
-
export const ProjectDir = path.resolve('.')
|
|
12
|
-
|
|
13
|
-
export const ProjectJson = JSON.parse(
|
|
14
|
-
fs.readFileSync(
|
|
15
|
-
path.join(ProjectDir, 'package.json')
|
|
16
|
-
).toString()
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
export const PlataDir = path.resolve('.', 'node_modules', ProjectJson.plata_name ?? '..')
|
|
20
|
-
|
|
21
|
-
export const PlataJson = JSON.parse(
|
|
22
|
-
fs.readFileSync(
|
|
23
|
-
path.join(PlataDir, 'package.json')
|
|
24
|
-
).toString()
|
|
25
|
-
)
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface PlataRuntime extends PlataRuntimeEType {}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
9
|
+
|
|
10
|
+
export namespace PlataRuntimeE {
|
|
11
|
+
export const ProjectDir = path.resolve('.')
|
|
12
|
+
|
|
13
|
+
export const ProjectJson = JSON.parse(
|
|
14
|
+
fs.readFileSync(
|
|
15
|
+
path.join(ProjectDir, 'package.json')
|
|
16
|
+
).toString()
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
export const PlataDir = path.resolve('.', 'node_modules', ProjectJson.plata_name ?? '..')
|
|
20
|
+
|
|
21
|
+
export const PlataJson = JSON.parse(
|
|
22
|
+
fs.readFileSync(
|
|
23
|
+
path.join(PlataDir, 'package.json')
|
|
24
|
+
).toString()
|
|
25
|
+
)
|
|
26
26
|
}
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { Effect } from 'effect'
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
interface PlataRuntime extends PlataRuntimeEType {}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export namespace PlataRuntimeE {
|
|
11
|
-
export async function PromiseAll<
|
|
12
|
-
T extends readonly unknown[] | [],
|
|
13
|
-
R = RemovePlataResultOnPromiseAll<{ -readonly [P in keyof T]: Awaited<T[P]> }>
|
|
14
|
-
>(promises: T): PlataPromise<
|
|
15
|
-
R extends [] ?
|
|
16
|
-
T extends Promise<infer U>[] ? RemovePlataResult<U>[]
|
|
17
|
-
: never
|
|
18
|
-
: R
|
|
19
|
-
> {
|
|
20
|
-
if (promises.length === 0) {
|
|
21
|
-
return [] as any
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const results: any[] = []
|
|
25
|
-
let error: PlataError | null = null
|
|
26
|
-
const promisesWithID = promises.map((p, i) => ({
|
|
27
|
-
promise: p,
|
|
28
|
-
id: i
|
|
29
|
-
}))
|
|
30
|
-
|
|
31
|
-
const effect = Effect.forEach(promisesWithID, (p) => Effect.gen(function* (_) {
|
|
32
|
-
const result: PlataResult<any> = yield* _(Effect.promise(() => p.promise))
|
|
33
|
-
|
|
34
|
-
if (result.errorID !== undefined) {
|
|
35
|
-
error = result
|
|
36
|
-
return yield* _(Effect.interrupt)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
results[p.id] = result
|
|
40
|
-
}), { concurrency: 'unbounded' })
|
|
41
|
-
|
|
42
|
-
await Effect.runPromise(effect).catch((err) => {
|
|
43
|
-
if (error === null)
|
|
44
|
-
error = {
|
|
45
|
-
errorID: 'PBRUNEFFPROALL001',
|
|
46
|
-
msg: 'Erro ao realizar a operação',
|
|
47
|
-
error: {
|
|
48
|
-
message: err?.toString(),
|
|
49
|
-
stack: err?.stack ?? new Error().stack
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
;
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
if (error !== null) {
|
|
56
|
-
return error
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return results as any
|
|
60
|
-
}
|
|
1
|
+
import { Effect } from 'effect'
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface PlataRuntime extends PlataRuntimeEType {}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export namespace PlataRuntimeE {
|
|
11
|
+
export async function PromiseAll<
|
|
12
|
+
T extends readonly unknown[] | [],
|
|
13
|
+
R = RemovePlataResultOnPromiseAll<{ -readonly [P in keyof T]: Awaited<T[P]> }>
|
|
14
|
+
>(promises: T): PlataPromise<
|
|
15
|
+
R extends [] ?
|
|
16
|
+
T extends Promise<infer U>[] ? RemovePlataResult<U>[]
|
|
17
|
+
: never
|
|
18
|
+
: R
|
|
19
|
+
> {
|
|
20
|
+
if (promises.length === 0) {
|
|
21
|
+
return [] as any
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const results: any[] = []
|
|
25
|
+
let error: PlataError | null = null
|
|
26
|
+
const promisesWithID = promises.map((p, i) => ({
|
|
27
|
+
promise: p,
|
|
28
|
+
id: i
|
|
29
|
+
}))
|
|
30
|
+
|
|
31
|
+
const effect = Effect.forEach(promisesWithID, (p) => Effect.gen(function* (_) {
|
|
32
|
+
const result: PlataResult<any> = yield* _(Effect.promise(() => p.promise))
|
|
33
|
+
|
|
34
|
+
if (result.errorID !== undefined) {
|
|
35
|
+
error = result
|
|
36
|
+
return yield* _(Effect.interrupt)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
results[p.id] = result
|
|
40
|
+
}), { concurrency: 'unbounded' })
|
|
41
|
+
|
|
42
|
+
await Effect.runPromise(effect).catch((err) => {
|
|
43
|
+
if (error === null)
|
|
44
|
+
error = {
|
|
45
|
+
errorID: 'PBRUNEFFPROALL001',
|
|
46
|
+
msg: 'Erro ao realizar a operação',
|
|
47
|
+
error: {
|
|
48
|
+
message: err?.toString(),
|
|
49
|
+
stack: err?.stack ?? new Error().stack
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
;
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
if (error !== null) {
|
|
56
|
+
return error
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return results as any
|
|
60
|
+
}
|
|
61
61
|
}
|
package/src/bin/runtime/fs.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { PlataFs } from "../../libs/fs"
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
interface PlataRuntime extends PlataRuntimeEType {}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
8
|
-
|
|
9
|
-
export namespace PlataRuntimeE {
|
|
10
|
-
export const files = PlataFs
|
|
1
|
+
import { PlataFs } from "../../libs/fs"
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface PlataRuntime extends PlataRuntimeEType {}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
8
|
+
|
|
9
|
+
export namespace PlataRuntimeE {
|
|
10
|
+
export const files = PlataFs
|
|
11
11
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface PlataRuntime extends PlataRuntimeEType {}
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
6
|
-
|
|
7
|
-
export namespace PlataRuntimeE {
|
|
8
|
-
export function FastPromise<T>(p: () => Promise<T>): Promise<T> {
|
|
9
|
-
return Promise.resolve().then(p)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function BuildPlataError(e: PlataError): PlataError {
|
|
13
|
-
return e
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function BuildObject<T>(o: T): T {
|
|
17
|
-
return o
|
|
18
|
-
}
|
|
1
|
+
declare global {
|
|
2
|
+
interface PlataRuntime extends PlataRuntimeEType {}
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
type PlataRuntimeEType = typeof PlataRuntimeE
|
|
6
|
+
|
|
7
|
+
export namespace PlataRuntimeE {
|
|
8
|
+
export function FastPromise<T>(p: () => Promise<T>): Promise<T> {
|
|
9
|
+
return Promise.resolve().then(p)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function BuildPlataError(e: PlataError): PlataError {
|
|
13
|
+
return e
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function BuildObject<T>(o: T): T {
|
|
17
|
+
return o
|
|
18
|
+
}
|
|
19
19
|
}
|