nesoi 3.3.7 → 3.3.8
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/lib/bundler/distributed/stages/6_dump_cli_stage.js +0 -1
- package/lib/bundler/monolyth/stages/6_dump_cli_stage.js +0 -1
- package/lib/elements/blocks/resource/resource.js +9 -0
- package/lib/elements/entities/bucket/adapters/memory.nql.js +2 -4
- package/lib/elements/entities/bucket/bucket.schema.d.ts +1 -1
- package/lib/engine/app/app.config.d.ts +7 -1
- package/lib/engine/app/app.config.js +20 -0
- package/lib/engine/app/app.d.ts +3 -1
- package/lib/engine/app/inline.app.d.ts +8 -2
- package/lib/engine/app/inline.app.js +33 -34
- package/lib/engine/app/native/browser.app.d.ts +1 -0
- package/lib/engine/app/native/browser.app.js +1 -1
- package/lib/engine/app/native/distributed_node.app.js +1 -6
- package/lib/engine/app/native/monolyth.app.d.ts +1 -0
- package/lib/engine/app/native/monolyth.app.js +1 -1
- package/lib/engine/app/service.d.ts +4 -10
- package/lib/engine/app/service.js +1 -3
- package/lib/engine/cli/script.d.ts +97 -0
- package/lib/engine/cli/script.js +422 -0
- package/lib/engine/transaction/nodes/bucket_query.trx_node.js +1 -1
- package/lib/engine/util/dotenv.d.ts +5 -6
- package/lib/engine/util/dotenv.js +14 -12
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tools/dotenv.d.ts +0 -1
- package/tools/dotenv.js +0 -4
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
// Log.info('compiler', 'monolyth', 'Dumping cli.js file to build/bin folder...')
|
|
21
21
|
// const { dirs } = this.monolyth;
|
|
22
22
|
// let str = '';
|
|
23
|
-
// str += 'require("nesoi/tools/dotenv");\n';
|
|
24
23
|
// str += 'const app = require(\'../app\').default\n';
|
|
25
24
|
// str += 'const { Log } = require(\'nesoi/lib/engine/util/log\');\n';
|
|
26
25
|
// str += 'Log.level = \'debug\';\n'
|
|
@@ -53,7 +53,6 @@ class DumpCLIStage {
|
|
|
53
53
|
log_1.Log.info('compiler', 'monolyth', 'Dumping cli.js file to build/bin folder...');
|
|
54
54
|
const { dirs } = this.bundler;
|
|
55
55
|
let str = '';
|
|
56
|
-
str += 'require("nesoi/tools/dotenv");\n';
|
|
57
56
|
str += 'const app = require(\'../app\').default\n';
|
|
58
57
|
str += 'const { Log } = require(\'nesoi/lib/engine/util/log\');\n';
|
|
59
58
|
str += 'Log.level = \'debug\';\n';
|
|
@@ -4,6 +4,8 @@ exports.Resource = void 0;
|
|
|
4
4
|
const block_1 = require("../block");
|
|
5
5
|
const trx_node_1 = require("../../../engine/transaction/trx_node");
|
|
6
6
|
const error_1 = require("../../../engine/data/error");
|
|
7
|
+
const dependency_1 = require("../../../engine/dependency");
|
|
8
|
+
const daemon_1 = require("../../../engine/daemon");
|
|
7
9
|
/**
|
|
8
10
|
* @category Elements
|
|
9
11
|
* @subcategory Block
|
|
@@ -83,6 +85,13 @@ class Resource extends block_1.Block {
|
|
|
83
85
|
}
|
|
84
86
|
static query($) {
|
|
85
87
|
const scope = $.job.scope;
|
|
88
|
+
// Default sorting
|
|
89
|
+
if (!('#sort' in $.msg.query) || !$.msg.query['#sort']?.length) {
|
|
90
|
+
const module = trx_node_1.TrxNode.getModule($.trx);
|
|
91
|
+
const tag = dependency_1.Tag.fromNameOrShort(scope.module, 'bucket', scope.bucket);
|
|
92
|
+
const { meta } = daemon_1.Daemon.getBucketMetadata(module.daemon, tag);
|
|
93
|
+
$.msg.query['#sort'] = `${meta.updated_at}@desc`;
|
|
94
|
+
}
|
|
86
95
|
return $.trx.bucket(scope.bucket)
|
|
87
96
|
.viewQuery($.msg.query, $.msg.view).page({
|
|
88
97
|
page: $.msg.page,
|
|
@@ -28,10 +28,8 @@ class MemoryNQLRunner extends nql_engine_1.NQLRunner {
|
|
|
28
28
|
response = await this.filter(part, data, params, param_templates);
|
|
29
29
|
}
|
|
30
30
|
let output = Object.values(response);
|
|
31
|
-
if (part.union.sort) {
|
|
32
|
-
const sort = part.union.sort
|
|
33
|
-
? part.union.sort
|
|
34
|
-
: [{ key: this.adapter.config.meta.updated_at, dir: 'desc' }];
|
|
31
|
+
if (part.union.sort?.length) {
|
|
32
|
+
const sort = part.union.sort;
|
|
35
33
|
output.sort((a, b) => {
|
|
36
34
|
for (let i = 0; i < sort.length; i++) {
|
|
37
35
|
const s = sort[i];
|
|
@@ -29,7 +29,7 @@ export declare class $Bucket {
|
|
|
29
29
|
optional: boolean;
|
|
30
30
|
}>;
|
|
31
31
|
'#modelpath': {};
|
|
32
|
-
'#querypath':
|
|
32
|
+
'#querypath': {};
|
|
33
33
|
'#defaults': Record<string, any>;
|
|
34
34
|
constructor(module: string, name: string, alias: string, model: $BucketModel, graph: $BucketGraph, views: $BucketViews, tenancy?: $BucketTenancy<any, any> | undefined, extendsFrom?: Tag | undefined);
|
|
35
35
|
}
|
|
@@ -8,10 +8,12 @@ import { IService } from './service';
|
|
|
8
8
|
import { CLIConfig } from '../cli/cli';
|
|
9
9
|
import { BucketAdapter } from "../../elements/entities/bucket/adapters/bucket_adapter";
|
|
10
10
|
import { $TrashBucket } from '../data/trash';
|
|
11
|
-
import { $Bucket } from "../../elements";
|
|
11
|
+
import { $Bucket } from "../../elements/entities/bucket/bucket.schema";
|
|
12
|
+
import { $Message } from "../../elements/entities/message/message.schema";
|
|
12
13
|
import { Overlay } from '../util/type';
|
|
13
14
|
import { TrxStatus } from '../transaction/trx';
|
|
14
15
|
import { NesoiObj } from '../data/obj';
|
|
16
|
+
import { MessageTemplateDef } from "../../elements/entities/message/template/message_template.builder";
|
|
15
17
|
export type AppModuleConfig<S extends $Space, M extends ModuleName<S>, Services extends Record<string, IService>> = {
|
|
16
18
|
buckets?: AppBucketConfig<S, M, Services>;
|
|
17
19
|
trash?: AppTrashConfig<Services>;
|
|
@@ -19,6 +21,8 @@ export type AppModuleConfig<S extends $Space, M extends ModuleName<S>, Services
|
|
|
19
21
|
trx?: TrxEngineConfig<S, S['modules'][M], any, Services>;
|
|
20
22
|
};
|
|
21
23
|
export type AppConfig<S extends $Space, Modules extends ModuleName<S>, Services extends Record<string, IService>> = {
|
|
24
|
+
env?: $Message;
|
|
25
|
+
dotenv?: string;
|
|
22
26
|
auth?: AppAuthConfig<S>;
|
|
23
27
|
modules?: Partial<{
|
|
24
28
|
[M in (Modules & keyof S['modules'])]: AppModuleConfig<S, M, Services>;
|
|
@@ -67,6 +71,8 @@ export declare class AppConfigBuilder<S extends $Space, Modules extends string =
|
|
|
67
71
|
private app;
|
|
68
72
|
private config;
|
|
69
73
|
constructor(app: _App);
|
|
74
|
+
env(def: MessageTemplateDef<S, any, '__env__'>): _App;
|
|
75
|
+
dotenv(filename?: string): _App;
|
|
70
76
|
auth(config: AppAuthConfig<S>): _App;
|
|
71
77
|
module<M extends Modules>(name: M, config: AppModuleConfig<S, M, Services>): _App;
|
|
72
78
|
audit(config: AppI18nConfig): _App;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AppConfigBuilder = void 0;
|
|
4
|
+
const message_builder_1 = require("../../elements/entities/message/message.builder");
|
|
5
|
+
const dependency_1 = require("../dependency");
|
|
6
|
+
const tree_1 = require("../tree");
|
|
4
7
|
/**
|
|
5
8
|
* Factory
|
|
6
9
|
*/
|
|
@@ -12,6 +15,23 @@ class AppConfigBuilder {
|
|
|
12
15
|
this.app = app;
|
|
13
16
|
this.config = app._config;
|
|
14
17
|
}
|
|
18
|
+
env(def) {
|
|
19
|
+
const builder = new message_builder_1.MessageBuilder('__app__', '__env__')
|
|
20
|
+
.template(def);
|
|
21
|
+
const schema = message_builder_1.MessageBuilder.build({
|
|
22
|
+
builder,
|
|
23
|
+
dependencies: [],
|
|
24
|
+
filepath: '',
|
|
25
|
+
inlines: {},
|
|
26
|
+
tag: new dependency_1.Tag('__app__', 'message', '__env__'),
|
|
27
|
+
}, new tree_1.ModuleTree({}), {});
|
|
28
|
+
this.config.env = schema;
|
|
29
|
+
return this.app;
|
|
30
|
+
}
|
|
31
|
+
dotenv(filename = '.env') {
|
|
32
|
+
this.config.dotenv = filename;
|
|
33
|
+
return this.app;
|
|
34
|
+
}
|
|
15
35
|
auth(config) {
|
|
16
36
|
this.config.auth = config;
|
|
17
37
|
return this.app;
|
package/lib/engine/app/app.d.ts
CHANGED
|
@@ -31,7 +31,9 @@ export declare abstract class App<S extends $Space, Modules extends string = Mod
|
|
|
31
31
|
/**
|
|
32
32
|
* Spawn a daemon for this app.
|
|
33
33
|
*/
|
|
34
|
-
abstract daemon(
|
|
34
|
+
abstract daemon($?: {
|
|
35
|
+
dotenv?: string;
|
|
36
|
+
}): Promise<Daemon<S, Modules>>;
|
|
35
37
|
/**
|
|
36
38
|
* Specifies which `Space` modules to include on this App.
|
|
37
39
|
*
|
|
@@ -24,14 +24,20 @@ export declare class InlineApp<S extends $Space, ModuleNames extends string = Mo
|
|
|
24
24
|
* Build the application, start services and trx engines.
|
|
25
25
|
* Returns references to start a daemon.
|
|
26
26
|
*/
|
|
27
|
-
protected make(): Promise<{
|
|
27
|
+
protected make(dotenv?: string): Promise<{
|
|
28
28
|
modules: Record<string, AnyModule>;
|
|
29
29
|
services: Record<string, any>;
|
|
30
30
|
trxEngines: Record<ModuleNames, AnyTrxEngine>;
|
|
31
31
|
}>;
|
|
32
|
-
daemon(
|
|
32
|
+
daemon($?: {
|
|
33
|
+
dotenv?: string;
|
|
34
|
+
}): Promise<Daemon<S, ModuleNames>>;
|
|
33
35
|
protected makeDaemon(trxEngines: Record<ModuleNames, AnyTrxEngine>, services: Record<string, IService>): AnyDaemon;
|
|
34
36
|
package(_package: Record<string, any>): this;
|
|
37
|
+
/**
|
|
38
|
+
* This method validates the environment using the app env validator.
|
|
39
|
+
*/
|
|
40
|
+
protected validateEnv(): Promise<void>;
|
|
35
41
|
/**
|
|
36
42
|
* This method injects values from environment variables into each module's
|
|
37
43
|
* app constants.
|
|
@@ -13,6 +13,9 @@ const app_config_1 = require("./app.config");
|
|
|
13
13
|
const promise_1 = __importDefault(require("../util/promise"));
|
|
14
14
|
const dependency_1 = require("../dependency");
|
|
15
15
|
const builder_1 = require("../builder");
|
|
16
|
+
const message_template_parser_1 = require("../../elements/entities/message/template/message_template_parser");
|
|
17
|
+
const trx_node_1 = require("../transaction/trx_node");
|
|
18
|
+
const dotenv_1 = require("../util/dotenv");
|
|
16
19
|
/**
|
|
17
20
|
* @category App
|
|
18
21
|
*/
|
|
@@ -53,7 +56,7 @@ class InlineApp extends app_1.App {
|
|
|
53
56
|
* Build the application, start services and trx engines.
|
|
54
57
|
* Returns references to start a daemon.
|
|
55
58
|
*/
|
|
56
|
-
async make() {
|
|
59
|
+
async make(dotenv) {
|
|
57
60
|
if (this.space || this.builders) {
|
|
58
61
|
await this.boot().bootPromise;
|
|
59
62
|
}
|
|
@@ -62,9 +65,21 @@ class InlineApp extends app_1.App {
|
|
|
62
65
|
const mod = this._injectedModules[key];
|
|
63
66
|
modules[mod.name] = mod;
|
|
64
67
|
}
|
|
68
|
+
dotenv = dotenv || this._config.dotenv;
|
|
69
|
+
if (dotenv) {
|
|
70
|
+
log_1.Log.debug('app', this.name, `Loading environment variables from ${dotenv}`);
|
|
71
|
+
dotenv_1.DotEnv.load(dotenv);
|
|
72
|
+
}
|
|
73
|
+
if (this._config.env) {
|
|
74
|
+
log_1.Log.debug('app', this.name, 'Validating environment variables');
|
|
75
|
+
await this.validateEnv();
|
|
76
|
+
}
|
|
77
|
+
log_1.Log.debug('app', this.name, 'Linking app values');
|
|
78
|
+
this.linkAppValues(modules);
|
|
65
79
|
const services = {};
|
|
66
80
|
for (const key in this._services) {
|
|
67
81
|
const service = this._services[key];
|
|
82
|
+
service.config = service.configFn();
|
|
68
83
|
await promise_1.default.solve(service.up({
|
|
69
84
|
modules
|
|
70
85
|
}));
|
|
@@ -85,21 +100,17 @@ class InlineApp extends app_1.App {
|
|
|
85
100
|
}
|
|
86
101
|
trxEngines[m] = new trx_engine_1.TrxEngine(`app:${this.name}`, module, authnProviders, trxConfig, services);
|
|
87
102
|
}
|
|
88
|
-
// Log.debug('app', this.name, 'Injecting external constants and messages');
|
|
89
|
-
// this.linkExternals(modules);
|
|
90
|
-
log_1.Log.debug('app', this.name, 'Linking app values');
|
|
91
|
-
this.linkAppValues(modules);
|
|
92
103
|
return {
|
|
93
104
|
modules,
|
|
94
105
|
services,
|
|
95
106
|
trxEngines
|
|
96
107
|
};
|
|
97
108
|
}
|
|
98
|
-
async daemon() {
|
|
109
|
+
async daemon($) {
|
|
99
110
|
if (this._daemon) {
|
|
100
111
|
return this._daemon;
|
|
101
112
|
}
|
|
102
|
-
const app = await this.make();
|
|
113
|
+
const app = await this.make($?.dotenv);
|
|
103
114
|
log_1.Log.debug('app', this.name, 'Spawning daemon');
|
|
104
115
|
this._daemon = this.makeDaemon(app.trxEngines, app.services);
|
|
105
116
|
// Link daemon to modules
|
|
@@ -107,12 +118,6 @@ class InlineApp extends app_1.App {
|
|
|
107
118
|
const module = app.modules[m];
|
|
108
119
|
module.daemon = this._daemon;
|
|
109
120
|
}
|
|
110
|
-
// Run init method of services
|
|
111
|
-
for (const key in app.services) {
|
|
112
|
-
await promise_1.default.solve(app.services[key].init({
|
|
113
|
-
daemon: this._daemon
|
|
114
|
-
}));
|
|
115
|
-
}
|
|
116
121
|
return this._daemon;
|
|
117
122
|
}
|
|
118
123
|
makeDaemon(trxEngines, services) {
|
|
@@ -122,27 +127,21 @@ class InlineApp extends app_1.App {
|
|
|
122
127
|
this.packageJson = _package;
|
|
123
128
|
return this;
|
|
124
129
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// const buckets = module.schema.externals.buckets;
|
|
141
|
-
// Object.values(buckets).forEach(bucket => {
|
|
142
|
-
// module.nql.linkExternal(modules[bucket.module].buckets[bucket.name]);
|
|
143
|
-
// })
|
|
144
|
-
// })
|
|
145
|
-
// }
|
|
130
|
+
/**
|
|
131
|
+
* This method validates the environment using the app env validator.
|
|
132
|
+
*/
|
|
133
|
+
async validateEnv() {
|
|
134
|
+
const env = process.env;
|
|
135
|
+
const trxNode = new trx_node_1.TrxNode('root', {}, undefined, { name: '__app__' });
|
|
136
|
+
try {
|
|
137
|
+
const parsed = await (0, message_template_parser_1.MessageTemplateFieldParser)(trxNode, this._config.env.template.fields, env);
|
|
138
|
+
Object.assign(process.env, parsed);
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
log_1.Log.error('app', this.name, 'Environment variables missing or incorrect.', e);
|
|
142
|
+
throw new Error('Environment variables missing or incorrect.');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
146
145
|
/**
|
|
147
146
|
* This method injects values from environment variables into each module's
|
|
148
147
|
* app constants.
|
|
@@ -15,6 +15,7 @@ export declare class BrowserApp<S extends $Space, ModuleNames extends string = M
|
|
|
15
15
|
protected _packageJson?: Record<string, any>;
|
|
16
16
|
daemon($?: {
|
|
17
17
|
watch?: boolean;
|
|
18
|
+
dotenv?: string;
|
|
18
19
|
}): Promise<import("../../daemon").Daemon<S, ModuleNames>>;
|
|
19
20
|
protected makeDaemon(trxEngines: Record<ModuleNames, AnyTrxEngine>, services: Record<string, IService>): BrowserDaemon<$Space, ModuleNames>;
|
|
20
21
|
modules<M extends ModuleName<S>>(modules: M[]): BrowserApp<S, M & ModuleNames>;
|
|
@@ -17,7 +17,7 @@ class BrowserApp extends inline_app_1.InlineApp {
|
|
|
17
17
|
}
|
|
18
18
|
// Override InlineApp abstract methods
|
|
19
19
|
async daemon($) {
|
|
20
|
-
return super.daemon();
|
|
20
|
+
return super.daemon($);
|
|
21
21
|
}
|
|
22
22
|
makeDaemon(trxEngines, services) {
|
|
23
23
|
return new BrowserDaemon(this.name, trxEngines, services, this._config);
|
|
@@ -61,6 +61,7 @@ class DistributedNodeApp extends app_1.App {
|
|
|
61
61
|
const services = {};
|
|
62
62
|
for (const key in this._services) {
|
|
63
63
|
const service = this._services[key];
|
|
64
|
+
service.config = service.configFn();
|
|
64
65
|
await promise_1.default.solve(service.up({
|
|
65
66
|
modules
|
|
66
67
|
}));
|
|
@@ -117,12 +118,6 @@ class DistributedNodeApp extends app_1.App {
|
|
|
117
118
|
const module = app.modules[m];
|
|
118
119
|
module.daemon = this._daemon;
|
|
119
120
|
}
|
|
120
|
-
// Run init method of services
|
|
121
|
-
for (const key in app.services) {
|
|
122
|
-
await promise_1.default.solve(app.services[key].init({
|
|
123
|
-
daemon: this._daemon
|
|
124
|
-
}));
|
|
125
|
-
}
|
|
126
121
|
return this._daemon;
|
|
127
122
|
}
|
|
128
123
|
host(config) {
|
|
@@ -17,6 +17,7 @@ export declare class MonolythApp<S extends $Space, ModuleNames extends string =
|
|
|
17
17
|
protected _packageJson?: Record<string, any>;
|
|
18
18
|
daemon($?: {
|
|
19
19
|
watch?: boolean;
|
|
20
|
+
dotenv?: string;
|
|
20
21
|
}): Promise<Daemon<S, ModuleNames>>;
|
|
21
22
|
protected makeDaemon(trxEngines: Record<ModuleNames, AnyTrxEngine>, services: Record<string, IService>): MonolythDaemon<$Space, ModuleNames>;
|
|
22
23
|
remake(): Promise<void>;
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import { AnyDaemon } from '../daemon';
|
|
2
1
|
import { AnyModule } from '../module';
|
|
3
2
|
/**
|
|
4
3
|
* Service
|
|
5
4
|
*/
|
|
6
|
-
type
|
|
5
|
+
type OptionalFn<T> = (T extends undefined ? [] : never) | [cfg: () => T];
|
|
7
6
|
export declare abstract class Service<out Name extends string, Config = never> {
|
|
8
7
|
/**
|
|
9
8
|
* This property MUST be set on the implementation class.
|
|
10
9
|
*/
|
|
11
10
|
static defaultName: string;
|
|
12
11
|
name: Name;
|
|
12
|
+
private configFn;
|
|
13
13
|
config: Config;
|
|
14
14
|
libPaths?: string[];
|
|
15
15
|
abstract up($: {
|
|
16
16
|
modules: Record<string, AnyModule>;
|
|
17
17
|
}): void | Promise<void>;
|
|
18
18
|
abstract down(): void | Promise<void>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}): void | Promise<void>;
|
|
22
|
-
constructor(...cfg: Optional<Config>);
|
|
23
|
-
constructor(name: Name, ...cfg: Optional<Config>);
|
|
19
|
+
constructor(...cfg: OptionalFn<Config>);
|
|
20
|
+
constructor(name: Name, ...cfg: OptionalFn<Config>);
|
|
24
21
|
}
|
|
25
22
|
export type AnyService = Service<any, any>;
|
|
26
23
|
export interface IService {
|
|
@@ -29,9 +26,6 @@ export interface IService {
|
|
|
29
26
|
up(this: IService, $: {
|
|
30
27
|
modules: Record<string, AnyModule>;
|
|
31
28
|
}): void | Promise<void>;
|
|
32
|
-
init(this: IService, $: {
|
|
33
|
-
daemon: AnyDaemon;
|
|
34
|
-
}): void | Promise<void>;
|
|
35
29
|
down(this: IService): void | Promise<void>;
|
|
36
30
|
}
|
|
37
31
|
export {};
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Service = void 0;
|
|
4
4
|
class Service {
|
|
5
|
-
init($) {
|
|
6
|
-
}
|
|
7
5
|
constructor(arg1, arg2) {
|
|
8
6
|
if (typeof arg1 === 'string') {
|
|
9
7
|
this.name = arg1;
|
|
@@ -11,7 +9,7 @@ class Service {
|
|
|
11
9
|
else {
|
|
12
10
|
this.name = this.constructor.defaultName;
|
|
13
11
|
}
|
|
14
|
-
this.
|
|
12
|
+
this.configFn = arg2 || arg1;
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
exports.Service = Service;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category Engine
|
|
3
|
+
* @subcategory CLI
|
|
4
|
+
*/
|
|
5
|
+
export default function script<Def extends ScriptDef, T = ReturnType<Def> extends ScriptBuilder<infer X> ? X : never>(name: string, def: Def): Script<{ [K in keyof T]: T[K]; }>;
|
|
6
|
+
declare class Script<T> {
|
|
7
|
+
private schema;
|
|
8
|
+
args: T;
|
|
9
|
+
constructor(schema: $Script<any>);
|
|
10
|
+
init(): T;
|
|
11
|
+
log_help(): void;
|
|
12
|
+
log_header(): void;
|
|
13
|
+
log_syntax(): void;
|
|
14
|
+
log_flags(): void;
|
|
15
|
+
error(error: string, type: 'syntax' | 'flag'): void;
|
|
16
|
+
parse(): void;
|
|
17
|
+
private parse_argv;
|
|
18
|
+
private validate;
|
|
19
|
+
}
|
|
20
|
+
type $Script<T> = {
|
|
21
|
+
name: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
args: $ScriptArg[];
|
|
24
|
+
};
|
|
25
|
+
type $ScriptArg = {
|
|
26
|
+
name: string;
|
|
27
|
+
short?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
type: 'pos' | 'key';
|
|
30
|
+
values: $ScriptValue[];
|
|
31
|
+
};
|
|
32
|
+
type $ScriptValue = {
|
|
33
|
+
name: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
type: 'string' | 'boolean' | 'enum';
|
|
36
|
+
amount: '1' | '1?' | '0+' | '1+';
|
|
37
|
+
meta: {
|
|
38
|
+
enum?: {
|
|
39
|
+
options: {
|
|
40
|
+
[x: string]: {
|
|
41
|
+
name: string;
|
|
42
|
+
description?: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
type ArgName<T> = T extends `--${infer X}` ? X : T extends `-${infer X}` ? X : T;
|
|
49
|
+
type ArgValue<T> = T extends Record<string, any> ? {
|
|
50
|
+
[K in keyof T]: T[K];
|
|
51
|
+
} : T;
|
|
52
|
+
declare class ScriptBuilder<T> {
|
|
53
|
+
private schema;
|
|
54
|
+
constructor(name: string);
|
|
55
|
+
d(description: string): this;
|
|
56
|
+
arg<Name extends string, Def extends ScriptArgDef<Name extends `-${string}` ? 'key' : 'pos'>>(name: Name, short: Name extends `-${string}` ? `-${string}` : never, def: Def): ScriptBuilder<T & {
|
|
57
|
+
[K in Name as ArgName<K>]: ReturnType<Def> extends ScriptArgBuilder<infer X> ? ArgValue<X> : any;
|
|
58
|
+
}>;
|
|
59
|
+
arg<Name extends string, Def extends ScriptArgDef<Name extends `-${string}` ? 'key' : 'pos'>>(name: Name, def: Def): ScriptBuilder<T & {
|
|
60
|
+
[K in Name as ArgName<K>]: ReturnType<Def> extends ScriptArgBuilder<infer X> ? ArgValue<X> : any;
|
|
61
|
+
}>;
|
|
62
|
+
static build<T>(builder: ScriptBuilder<T>): $Script<{ [K in keyof T]: T[K]; }>;
|
|
63
|
+
}
|
|
64
|
+
declare class ScriptPosArgBuilder<T = string> {
|
|
65
|
+
private schema;
|
|
66
|
+
constructor(name: string);
|
|
67
|
+
d(description: string): this;
|
|
68
|
+
value<Def extends ScriptValueDef>(def: Def): ScriptPosArgBuilder<ReturnType<Def> extends ScriptValueBuilder<infer X> ? X : never>;
|
|
69
|
+
static build(builder: ScriptPosArgBuilder): $ScriptArg;
|
|
70
|
+
}
|
|
71
|
+
declare class ScriptKeyArgBuilder<T = boolean | undefined> {
|
|
72
|
+
private schema;
|
|
73
|
+
constructor(name: string, short?: string);
|
|
74
|
+
d(description: string): this;
|
|
75
|
+
value<N extends string, Def extends ScriptValueDef>(name: N, def: Def): ScriptKeyArgBuilder<T extends boolean ? {
|
|
76
|
+
[k in N]: ReturnType<Def> extends ScriptValueBuilder<infer X> ? X : never;
|
|
77
|
+
} | undefined : T & {
|
|
78
|
+
[k in N]: ReturnType<Def> extends ScriptValueBuilder<infer X> ? X : never;
|
|
79
|
+
} | undefined>;
|
|
80
|
+
static build(builder: ScriptKeyArgBuilder): $ScriptArg;
|
|
81
|
+
}
|
|
82
|
+
declare class ScriptValueBuilder<T = string> {
|
|
83
|
+
private schema;
|
|
84
|
+
constructor(name: string);
|
|
85
|
+
d(description: string): this;
|
|
86
|
+
get optional(): ScriptValueBuilder<T | undefined>;
|
|
87
|
+
get zero_or_more(): this;
|
|
88
|
+
get one_or_more(): this;
|
|
89
|
+
get boolean(): ScriptValueBuilder<boolean>;
|
|
90
|
+
enum<E extends string>(options: E[] | Record<E, string>): ScriptValueBuilder<undefined extends T ? E | undefined : E>;
|
|
91
|
+
private build;
|
|
92
|
+
}
|
|
93
|
+
type ScriptArgBuilder<T> = ScriptPosArgBuilder<T> | ScriptKeyArgBuilder<T>;
|
|
94
|
+
type ScriptDef = (builder: ScriptBuilder<{}>) => ScriptBuilder<any>;
|
|
95
|
+
type ScriptValueDef = (builder: ScriptValueBuilder<string>) => ScriptValueBuilder<any>;
|
|
96
|
+
type ScriptArgDef<Type extends 'key' | 'pos'> = (factory: Type extends 'pos' ? ScriptPosArgBuilder : ScriptKeyArgBuilder) => ScriptArgBuilder<any>;
|
|
97
|
+
export {};
|