nesoi 3.0.0 → 3.0.6
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 +10 -0
- package/lib/adapters/postgres/src/migrator/bucket.d.ts +20 -0
- package/lib/adapters/postgres/src/migrator/bucket.js +184 -0
- package/lib/adapters/postgres/src/migrator/csv.d.ts +7 -0
- package/lib/adapters/postgres/src/migrator/csv.js +72 -0
- package/lib/adapters/postgres/src/migrator/migration.d.ts +2 -18
- package/lib/adapters/postgres/src/migrator/migration.js +10 -158
- package/lib/adapters/postgres/src/migrator/migrator.js +8 -5
- package/lib/adapters/postgres/src/migrator/runner.d.ts +16 -6
- package/lib/adapters/postgres/src/migrator/runner.js +103 -34
- package/lib/adapters/postgres/src/postgres.bucket_adapter.d.ts +19 -22
- package/lib/adapters/postgres/src/postgres.bucket_adapter.js +116 -100
- package/lib/adapters/postgres/src/postgres.cli.d.ts +23 -3
- package/lib/adapters/postgres/src/postgres.cli.js +70 -10
- package/lib/adapters/postgres/src/postgres.config.d.ts +5 -0
- package/lib/adapters/postgres/src/postgres.config.js +2 -0
- package/lib/adapters/postgres/src/postgres.nql.d.ts +7 -3
- package/lib/adapters/postgres/src/postgres.nql.js +86 -32
- package/lib/adapters/postgres/src/postgres.provider.d.ts +18 -0
- package/lib/adapters/postgres/src/postgres.provider.js +77 -0
- package/lib/adapters/postgres/test/postgres.bucket_adapter.test.js +76 -39
- package/lib/compiler/apps/monolyth/monolyth_compiler.d.ts +3 -0
- package/lib/compiler/apps/monolyth/monolyth_compiler.js +24 -0
- package/lib/compiler/apps/monolyth/stages/2_build_typescript_stage.js +2 -1
- package/lib/compiler/apps/monolyth/stages/5_dump_cli_stage.js +1 -1
- package/lib/compiler/apps/monolyth/stages/6_dump_package_json_stage.js +1 -1
- package/lib/compiler/elements/bucket.element.js +26 -11
- package/lib/compiler/elements/constants.element.js +1 -1
- package/lib/compiler/elements/element.d.ts +2 -0
- package/lib/compiler/elements/message.element.js +4 -4
- package/lib/compiler/helpers/dump_helpers.js +5 -2
- package/lib/compiler/stages/7_dump_stage.js +2 -0
- package/lib/compiler/treeshake.js +9 -37
- package/lib/compiler/typescript/bridge/extract.js +12 -0
- package/lib/compiler/typescript/bridge/inject.js +3 -0
- package/lib/compiler/typescript/bridge/organize.js +3 -3
- package/lib/elements/blocks/block.builder.js +4 -2
- package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +22 -20
- package/lib/elements/blocks/job/internal/resource_job.d.ts +2 -1
- package/lib/elements/blocks/job/internal/resource_job.js +17 -4
- package/lib/elements/blocks/job/job.js +3 -0
- package/lib/elements/blocks/job/job.types.d.ts +7 -0
- package/lib/elements/blocks/job/job.types.js +2 -0
- package/lib/elements/blocks/machine/machine.js +3 -2
- package/lib/elements/blocks/resource/resource.builder.js +2 -4
- package/lib/elements/blocks/resource/resource.d.ts +5 -3
- package/lib/elements/blocks/resource/resource.js +26 -17
- package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +2 -1
- package/lib/elements/edge/controller/adapters/controller_adapter.js +11 -2
- package/lib/elements/edge/controller/controller.builder.d.ts +4 -5
- package/lib/elements/edge/controller/controller.builder.js +7 -7
- package/lib/elements/edge/controller/controller.d.ts +2 -1
- package/lib/elements/edge/controller/controller.js +8 -6
- package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +61 -23
- package/lib/elements/entities/bucket/adapters/bucket_adapter.js +22 -13
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.d.ts +21 -22
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +68 -2
- package/lib/elements/entities/bucket/adapters/memory.nql.d.ts +10 -6
- package/lib/elements/entities/bucket/adapters/memory.nql.js +38 -3
- package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.d.ts +0 -20
- package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.js +46 -30
- package/lib/elements/entities/bucket/bucket.builder.d.ts +8 -2
- package/lib/elements/entities/bucket/bucket.builder.js +13 -19
- package/lib/elements/entities/bucket/bucket.config.d.ts +5 -1
- package/lib/elements/entities/bucket/bucket.d.ts +180 -19
- package/lib/elements/entities/bucket/bucket.js +662 -48
- package/lib/elements/entities/bucket/bucket.schema.d.ts +7 -1
- package/lib/elements/entities/bucket/bucket.schema.js +2 -1
- package/lib/elements/entities/bucket/bucket.types.d.ts +2 -7
- package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +6 -2
- package/lib/elements/entities/bucket/cache/bucket_cache.js +12 -12
- package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +32 -5
- package/lib/elements/entities/bucket/graph/bucket_graph.js +80 -111
- package/lib/elements/entities/bucket/graph/bucket_graph.schema.d.ts +3 -6
- package/lib/elements/entities/bucket/graph/bucket_graph.schema.js +1 -4
- package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.d.ts +3 -7
- package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.js +6 -2
- package/lib/elements/entities/bucket/model/bucket_model.builder.js +1 -1
- package/lib/elements/entities/bucket/model/bucket_model.convert.js +3 -3
- package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +37 -8
- package/lib/elements/entities/bucket/model/bucket_model.schema.js +25 -4
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +33 -14
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +56 -13
- package/lib/elements/entities/bucket/query/nql.schema.d.ts +1 -0
- package/lib/elements/entities/bucket/query/nql_compiler.js +13 -2
- package/lib/elements/entities/bucket/query/nql_engine.d.ts +11 -4
- package/lib/elements/entities/bucket/query/nql_engine.js +20 -11
- package/lib/elements/entities/bucket/view/bucket_view.js +63 -35
- package/lib/elements/entities/bucket/view/bucket_view.schema.d.ts +5 -2
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +6 -2
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +22 -16
- package/lib/elements/entities/constants/constants.schema.d.ts +1 -1
- package/lib/elements/entities/drive/drive_adapter.d.ts +44 -0
- package/lib/elements/entities/drive/drive_adapter.js +10 -0
- package/lib/elements/entities/drive/local.drive_adapter.d.ts +10 -0
- package/lib/elements/entities/drive/local.drive_adapter.js +34 -0
- package/lib/elements/entities/message/message.schema.d.ts +1 -0
- package/lib/elements/entities/message/message.schema.js +33 -0
- package/lib/elements/entities/message/message_parser.d.ts +5 -1
- package/lib/elements/entities/message/message_parser.js +56 -35
- package/lib/elements/entities/message/template/message_template.schema.d.ts +10 -8
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +16 -6
- package/lib/elements/entities/message/template/message_template_field.builder.js +25 -0
- package/lib/elements/entities/message/template/message_template_parser.js +2 -1
- package/lib/engine/apps/app.config.d.ts +32 -11
- package/lib/engine/apps/app.config.js +12 -0
- package/lib/engine/apps/app.d.ts +2 -0
- package/lib/engine/apps/app.js +3 -0
- package/lib/engine/apps/inline.app.d.ts +5 -3
- package/lib/engine/apps/inline.app.js +27 -12
- package/lib/engine/apps/monolyth/monolyth.app.d.ts +4 -2
- package/lib/engine/apps/monolyth/monolyth.app.js +22 -10
- package/lib/engine/auth/authn.d.ts +5 -1
- package/lib/engine/auth/zero.authn_provider.d.ts +4 -2
- package/lib/engine/auth/zero.authn_provider.js +2 -2
- package/lib/engine/cli/cli.d.ts +3 -1
- package/lib/engine/cli/cli.js +22 -3
- package/lib/engine/cli/cli_adapter.d.ts +2 -1
- package/lib/engine/cli/cli_adapter.js +2 -1
- package/lib/engine/cli/cli_input.d.ts +19 -0
- package/lib/engine/cli/cli_input.js +207 -0
- package/lib/engine/cli/ui.d.ts +1 -1
- package/lib/engine/cli/ui.js +2 -2
- package/lib/engine/daemon.d.ts +3 -2
- package/lib/engine/daemon.js +14 -2
- package/lib/engine/data/date.js +2 -2
- package/lib/engine/data/datetime.d.ts +40 -4
- package/lib/engine/data/datetime.js +70 -11
- package/lib/engine/data/decimal.d.ts +1 -1
- package/lib/engine/data/decimal.js +3 -3
- package/lib/engine/data/error.d.ts +21 -4
- package/lib/engine/data/error.js +23 -7
- package/lib/engine/data/file.d.ts +38 -0
- package/lib/engine/data/file.js +54 -0
- package/lib/engine/data/json.d.ts +6 -0
- package/lib/engine/data/json.js +26 -0
- package/lib/engine/data/obj.d.ts +1 -1
- package/lib/engine/data/trash.d.ts +14 -0
- package/lib/engine/data/trash.js +2 -0
- package/lib/engine/data/tree.d.ts +7 -12
- package/lib/engine/data/tree.js +101 -49
- package/lib/engine/module.d.ts +2 -1
- package/lib/engine/module.js +2 -5
- package/lib/engine/space.d.ts +1 -0
- package/lib/engine/space.js +6 -0
- package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +184 -24
- package/lib/engine/transaction/nodes/bucket.trx_node.js +346 -451
- package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +4 -2
- package/lib/engine/transaction/nodes/bucket_query.trx_node.js +27 -15
- package/lib/engine/transaction/nodes/job.trx_node.d.ts +2 -1
- package/lib/engine/transaction/nodes/job.trx_node.js +6 -0
- package/lib/engine/transaction/trx.d.ts +5 -2
- package/lib/engine/transaction/trx.js +2 -2
- package/lib/engine/transaction/trx_engine.config.d.ts +1 -3
- package/lib/engine/transaction/trx_engine.d.ts +2 -2
- package/lib/engine/transaction/trx_engine.js +14 -11
- package/lib/engine/transaction/trx_node.d.ts +14 -4
- package/lib/engine/transaction/trx_node.js +50 -8
- package/lib/engine/tree.d.ts +1 -1
- package/lib/engine/util/crypto.d.ts +50 -0
- package/lib/engine/util/crypto.js +89 -0
- package/lib/engine/util/deep.d.ts +5 -0
- package/lib/engine/util/deep.js +46 -0
- package/lib/engine/util/dotenv.d.ts +2 -8
- package/lib/engine/util/dotenv.js +14 -36
- package/lib/engine/util/hash.d.ts +3 -0
- package/lib/engine/util/hash.js +23 -0
- package/lib/engine/util/log.js +1 -1
- package/lib/engine/util/mime.d.ts +10 -0
- package/lib/engine/util/mime.js +389 -0
- package/lib/engine/util/parse.d.ts +6 -5
- package/lib/engine/util/parse.js +16 -15
- package/lib/engine/util/path.d.ts +3 -0
- package/lib/engine/util/path.js +92 -0
- package/lib/engine/util/rules.d.ts +4 -0
- package/lib/engine/util/rules.js +12 -0
- package/package.json +2 -2
- package/tools/compile.js +2 -2
- package/tools/dotenv.d.ts +1 -0
- package/tools/dotenv.js +4 -0
- package/tools/joaquin/job.d.ts +5 -5
- package/tools/joaquin/mock.d.ts +23 -2
- package/tools/joaquin/mock.js +127 -21
- package/tsconfig.build.tsbuildinfo +1 -1
- package/lib/adapters/postgres/test/postgres.bucket_query.test.d.ts +0 -0
- package/lib/adapters/postgres/test/postgres.bucket_query.test.js +0 -136
|
@@ -3,15 +3,17 @@ import { TrxNode } from '../trx_node';
|
|
|
3
3
|
import { $Bucket } from "../../../elements/entities/bucket/bucket.schema";
|
|
4
4
|
import { Bucket } from "../../../elements/entities/bucket/bucket";
|
|
5
5
|
import { NQL_AnyQuery, NQL_Pagination, NQL_Query } from "../../../elements/entities/bucket/query/nql.schema";
|
|
6
|
+
import { NQL_Result } from "../../../elements/entities/bucket/query/nql_engine";
|
|
6
7
|
export declare class BucketQueryTrxNode<M extends $Module, B extends $Bucket, V extends ViewName<B>, Obj = ViewObj<B, V>> {
|
|
7
8
|
private trx;
|
|
8
9
|
private bucket;
|
|
9
10
|
private query;
|
|
10
11
|
private view;
|
|
11
|
-
|
|
12
|
+
private enableTenancy;
|
|
13
|
+
constructor(trx: TrxNode<any, M, any>, bucket: Bucket<M, B>, query: NQL_AnyQuery, view: V, enableTenancy: boolean);
|
|
12
14
|
merge($: NQL_Query<M, B>): void;
|
|
13
15
|
first(): Promise<Obj | undefined>;
|
|
14
16
|
firstOrFail(): Promise<Obj>;
|
|
15
17
|
all(): Promise<Obj[]>;
|
|
16
|
-
page(pagination
|
|
18
|
+
page(pagination?: NQL_Pagination): Promise<NQL_Result<Obj>>;
|
|
17
19
|
}
|
|
@@ -4,11 +4,12 @@ exports.BucketQueryTrxNode = void 0;
|
|
|
4
4
|
const trx_node_1 = require("../trx_node");
|
|
5
5
|
const error_1 = require("../../data/error");
|
|
6
6
|
class BucketQueryTrxNode {
|
|
7
|
-
constructor(trx, bucket, query, view) {
|
|
7
|
+
constructor(trx, bucket, query, view, enableTenancy) {
|
|
8
8
|
this.trx = trx;
|
|
9
9
|
this.bucket = bucket;
|
|
10
10
|
this.query = query;
|
|
11
11
|
this.view = view;
|
|
12
|
+
this.enableTenancy = enableTenancy;
|
|
12
13
|
}
|
|
13
14
|
merge($) {
|
|
14
15
|
const and = $['#and'];
|
|
@@ -23,34 +24,40 @@ class BucketQueryTrxNode {
|
|
|
23
24
|
await trx_node_1.TrxNode.open(this.trx, 'queryFirst', { schema: this.query, view: this.view });
|
|
24
25
|
let results;
|
|
25
26
|
try {
|
|
26
|
-
results = await this.bucket.query(this.trx, this.query,
|
|
27
|
+
results = await this.bucket.query(this.trx, this.query, {
|
|
28
|
+
perPage: 1
|
|
29
|
+
}, this.view, {
|
|
30
|
+
no_tenancy: !this.enableTenancy
|
|
31
|
+
});
|
|
27
32
|
}
|
|
28
33
|
catch (e) {
|
|
29
34
|
await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
30
35
|
throw e;
|
|
31
36
|
}
|
|
32
|
-
await trx_node_1.TrxNode.ok(this.trx, { length: results.length });
|
|
33
|
-
return results.length
|
|
34
|
-
? results[0]
|
|
37
|
+
await trx_node_1.TrxNode.ok(this.trx, { length: results.data.length });
|
|
38
|
+
return results.data.length
|
|
39
|
+
? results.data[0]
|
|
35
40
|
: undefined;
|
|
36
41
|
}
|
|
37
42
|
async firstOrFail() {
|
|
38
43
|
await trx_node_1.TrxNode.open(this.trx, 'queryFirstOrFail', { schema: this.query, view: this.view });
|
|
39
44
|
let results;
|
|
40
45
|
try {
|
|
41
|
-
results = await this.bucket.query(this.trx, this.query, undefined, this.view
|
|
46
|
+
results = await this.bucket.query(this.trx, this.query, undefined, this.view, {
|
|
47
|
+
no_tenancy: !this.enableTenancy
|
|
48
|
+
});
|
|
42
49
|
}
|
|
43
50
|
catch (e) {
|
|
44
51
|
await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
45
52
|
throw e;
|
|
46
53
|
}
|
|
47
|
-
if (!results.length) {
|
|
54
|
+
if (!results.data.length) {
|
|
48
55
|
const e = error_1.NesoiError.Bucket.Query.NoResults({ bucket: this.bucket.schema.alias, query: this.query });
|
|
49
56
|
await trx_node_1.TrxNode.error(this.trx, e);
|
|
50
57
|
throw e;
|
|
51
58
|
}
|
|
52
|
-
await trx_node_1.TrxNode.ok(this.trx, { length: results.length });
|
|
53
|
-
return results[0];
|
|
59
|
+
await trx_node_1.TrxNode.ok(this.trx, { length: results.data.length });
|
|
60
|
+
return results.data[0];
|
|
54
61
|
}
|
|
55
62
|
async all() {
|
|
56
63
|
await trx_node_1.TrxNode.open(this.trx, 'queryAll', { schema: this.query, view: this.view });
|
|
@@ -62,21 +69,26 @@ class BucketQueryTrxNode {
|
|
|
62
69
|
await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
63
70
|
throw e;
|
|
64
71
|
}
|
|
65
|
-
await trx_node_1.TrxNode.ok(this.trx, { length: results.length });
|
|
66
|
-
return results;
|
|
72
|
+
await trx_node_1.TrxNode.ok(this.trx, { length: results.data.length });
|
|
73
|
+
return results.data;
|
|
67
74
|
}
|
|
68
75
|
async page(pagination) {
|
|
76
|
+
if (!pagination) {
|
|
77
|
+
return {
|
|
78
|
+
data: await this.all()
|
|
79
|
+
};
|
|
80
|
+
}
|
|
69
81
|
await trx_node_1.TrxNode.open(this.trx, 'queryPage', { schema: this.query, pagination, view: this.view });
|
|
70
|
-
let
|
|
82
|
+
let result;
|
|
71
83
|
try {
|
|
72
|
-
|
|
84
|
+
result = await this.bucket.query(this.trx, this.query, pagination, this.view);
|
|
73
85
|
}
|
|
74
86
|
catch (e) {
|
|
75
87
|
await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
76
88
|
throw e;
|
|
77
89
|
}
|
|
78
|
-
await trx_node_1.TrxNode.ok(this.trx, { length:
|
|
79
|
-
return
|
|
90
|
+
await trx_node_1.TrxNode.ok(this.trx, { length: result.data.length });
|
|
91
|
+
return result;
|
|
80
92
|
}
|
|
81
93
|
}
|
|
82
94
|
exports.BucketQueryTrxNode = BucketQueryTrxNode;
|
|
@@ -3,11 +3,12 @@ import { TrxNode } from '../trx_node';
|
|
|
3
3
|
import { $Job } from "../../../elements/blocks/job/job.schema";
|
|
4
4
|
import { Job } from "../../../elements/blocks/job/job";
|
|
5
5
|
import { Message } from "../../../elements/entities/message/message";
|
|
6
|
+
import { JobInput } from "../../../elements/blocks/job/job.types";
|
|
6
7
|
export declare class JobTrxNode<M extends $Module, $ extends $Job> {
|
|
7
8
|
private trx;
|
|
8
9
|
private job;
|
|
9
10
|
private ctx?;
|
|
10
11
|
constructor(trx: TrxNode<any, M, any>, job: Job<any, M, $>, ctx?: Record<string, any> | undefined);
|
|
11
|
-
run(message:
|
|
12
|
+
run(message: JobInput<$>): Promise<$['#output']>;
|
|
12
13
|
forward(message: Message<$['#input']>): Promise<$['#output']>;
|
|
13
14
|
}
|
|
@@ -11,6 +11,12 @@ class JobTrxNode {
|
|
|
11
11
|
async run(message) {
|
|
12
12
|
const trx = trx_node_1.TrxNode.makeChildNode(this.trx, this.job.schema.module, 'job', this.job.schema.name);
|
|
13
13
|
await trx_node_1.TrxNode.open(trx, 'run', message);
|
|
14
|
+
// Special case for Jobs with a '' inline message,
|
|
15
|
+
// which is not required on the run method.
|
|
16
|
+
if (!('$' in message)
|
|
17
|
+
&& this.job.schema.input.some(dep => dep.tag === `${this.job.module.name}::message:${this.job.schema.name}`)) {
|
|
18
|
+
message['$'] = this.job.schema.name;
|
|
19
|
+
}
|
|
14
20
|
let response;
|
|
15
21
|
try {
|
|
16
22
|
response = await this.job.consumeRaw(trx, message, this.ctx);
|
|
@@ -2,7 +2,7 @@ import { $Module, $Space } from "../../schema";
|
|
|
2
2
|
import { Module } from '../module';
|
|
3
3
|
import { AnyTrxNode, TrxNode, TrxNodeStatus } from './trx_node';
|
|
4
4
|
import { TrxEngineOrigin } from './trx_engine';
|
|
5
|
-
import { AnyUsers } from '../auth/authn';
|
|
5
|
+
import { AnyUsers, AuthnRequest } from '../auth/authn';
|
|
6
6
|
import { NesoiDatetime } from '../data/datetime';
|
|
7
7
|
type TrxOrigin = TrxEngineOrigin | `trx:${string}`;
|
|
8
8
|
type TrxState = 'open' | 'ok' | 'error';
|
|
@@ -27,7 +27,10 @@ export declare class Trx<S extends $Space, M extends $Module, Authn extends AnyU
|
|
|
27
27
|
start: NesoiDatetime;
|
|
28
28
|
end?: NesoiDatetime;
|
|
29
29
|
ctx: Record<string, any>;
|
|
30
|
-
constructor(module: Module<S, M>, origin: TrxOrigin,
|
|
30
|
+
constructor(module: Module<S, M>, origin: TrxOrigin, authn?: {
|
|
31
|
+
tokens: AuthnRequest<any>;
|
|
32
|
+
users: Authn;
|
|
33
|
+
}, id?: string, root?: TrxNode<S, M, Authn>, nodes?: Record<string, TrxNode<S, M, Authn>>);
|
|
31
34
|
addNode(node: TrxNode<S, M, Authn>): void;
|
|
32
35
|
status(): TrxStatus<any>;
|
|
33
36
|
/**
|
|
@@ -46,13 +46,13 @@ class TrxStatus {
|
|
|
46
46
|
}
|
|
47
47
|
exports.TrxStatus = TrxStatus;
|
|
48
48
|
class Trx {
|
|
49
|
-
constructor(module, origin,
|
|
49
|
+
constructor(module, origin, authn, id, root, nodes) {
|
|
50
50
|
this.start = datetime_1.NesoiDatetime.now();
|
|
51
51
|
this.ctx = {};
|
|
52
52
|
this.module = module;
|
|
53
53
|
this.id = id || (Math.random() + 1).toString(36).substring(7);
|
|
54
54
|
this.origin = origin;
|
|
55
|
-
this.root = root || new trx_node_1.TrxNode('root', this, undefined, module,
|
|
55
|
+
this.root = root || new trx_node_1.TrxNode('root', this, undefined, module, authn, id);
|
|
56
56
|
this.nodes = nodes || {};
|
|
57
57
|
}
|
|
58
58
|
addNode(node) {
|
|
@@ -9,7 +9,5 @@ export type TrxEngineConfig<S extends $Space, M extends $Module, Authn extends A
|
|
|
9
9
|
* Adapter used to store transactions of this module.
|
|
10
10
|
*/
|
|
11
11
|
adapter?: (schema: M) => BucketAdapter<AnyTrx>;
|
|
12
|
-
|
|
13
|
-
wrap?: <T extends Trx<S, M, Authn>>(trx: T, fn: TrxEngineWrapFn<S, M>, providers: Providers) => Promise<any>;
|
|
14
|
-
};
|
|
12
|
+
wrap?: <T extends Trx<S, M, Authn>>(trx: T, fn: TrxEngineWrapFn<S, M>, providers: Providers) => Promise<any>;
|
|
15
13
|
};
|
|
@@ -2,7 +2,7 @@ import { $Module, $Space } from "../../schema";
|
|
|
2
2
|
import { Module } from '../module';
|
|
3
3
|
import { Trx } from './trx';
|
|
4
4
|
import { TrxNode, TrxNodeStatus } from './trx_node';
|
|
5
|
-
import { AnyAuthnProviders,
|
|
5
|
+
import { AnyAuthnProviders, AuthnRequest } from '../auth/authn';
|
|
6
6
|
import { TrxEngineConfig } from './trx_engine.config';
|
|
7
7
|
export type TrxEngineOrigin = `app:${string}`;
|
|
8
8
|
export declare class TrxEngine<S extends $Space, M extends $Module, Authn extends AnyAuthnProviders> {
|
|
@@ -18,7 +18,7 @@ export declare class TrxEngine<S extends $Space, M extends $Module, Authn extend
|
|
|
18
18
|
private adapter;
|
|
19
19
|
constructor(origin: TrxEngineOrigin, module: Module<S, M>, authnProviders?: Authn | undefined, config?: TrxEngineConfig<S, M, any, any> | undefined, providers?: Record<string, any>);
|
|
20
20
|
getModule(): Module<S, M>;
|
|
21
|
-
get(id?: string
|
|
21
|
+
get(id?: string): Promise<Trx<S, M, any>>;
|
|
22
22
|
trx(fn: (trx: TrxNode<S, M, any>) => Promise<TrxNodeStatus>, authn?: AuthnRequest<keyof Authn>): Promise<import("./trx").TrxStatus<any>>;
|
|
23
23
|
private authenticate;
|
|
24
24
|
private commit;
|
|
@@ -22,12 +22,12 @@ class TrxEngine {
|
|
|
22
22
|
getModule() {
|
|
23
23
|
return this.module;
|
|
24
24
|
}
|
|
25
|
-
async get(id
|
|
25
|
+
async get(id) {
|
|
26
26
|
let trx = undefined;
|
|
27
27
|
if (!id) {
|
|
28
|
-
trx = new trx_1.Trx(this.module, this.origin
|
|
28
|
+
trx = new trx_1.Trx(this.module, this.origin);
|
|
29
29
|
log_1.Log.info('module', this.module.name, `Begin ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
|
|
30
|
-
return this.adapter.
|
|
30
|
+
return this.adapter.create(this.innerTrx.root, trx);
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
trx = await this.adapter.get(this.innerTrx.root, id);
|
|
@@ -36,19 +36,22 @@ class TrxEngine {
|
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
log_1.Log.info('module', this.module.name, `Chain ${(0, log_1.scopeTag)('trx', id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
|
|
39
|
-
trx = new trx_1.Trx(this.module, this.origin,
|
|
40
|
-
return this.adapter.
|
|
39
|
+
trx = new trx_1.Trx(this.module, this.origin, undefined, id);
|
|
40
|
+
return this.adapter.create(this.innerTrx.root, trx);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
return trx;
|
|
44
44
|
}
|
|
45
45
|
async trx(fn, authn) {
|
|
46
|
-
const
|
|
47
|
-
const trx = await this.get(undefined, users);
|
|
46
|
+
const trx = await this.get(undefined);
|
|
48
47
|
try {
|
|
48
|
+
const users = authn ? await this.authenticate(trx.root, authn) : undefined;
|
|
49
|
+
if (users) {
|
|
50
|
+
trx_node_1.TrxNode.addAuthn(trx.root, authn, users);
|
|
51
|
+
}
|
|
49
52
|
let output;
|
|
50
|
-
if (this.config?.
|
|
51
|
-
output = await this.config?.
|
|
53
|
+
if (this.config?.wrap) {
|
|
54
|
+
output = await this.config?.wrap(trx, fn, this.providers);
|
|
52
55
|
}
|
|
53
56
|
else {
|
|
54
57
|
output = await fn(trx.root);
|
|
@@ -61,7 +64,7 @@ class TrxEngine {
|
|
|
61
64
|
return trx.status();
|
|
62
65
|
}
|
|
63
66
|
// authentication
|
|
64
|
-
async authenticate(request) {
|
|
67
|
+
async authenticate(trx, request) {
|
|
65
68
|
if (!this.authnProviders) {
|
|
66
69
|
throw error_1.NesoiError.Authn.NoProvidersRegisteredForModule(this.module.name);
|
|
67
70
|
}
|
|
@@ -71,7 +74,7 @@ class TrxEngine {
|
|
|
71
74
|
if (!(provider in this.authnProviders)) {
|
|
72
75
|
throw error_1.NesoiError.Authn.NoProviderRegisteredForModule(this.module.name, provider);
|
|
73
76
|
}
|
|
74
|
-
users[provider] = await this.authnProviders[provider].authenticate(token);
|
|
77
|
+
users[provider] = await this.authnProviders[provider].authenticate({ trx, token });
|
|
75
78
|
}
|
|
76
79
|
return users;
|
|
77
80
|
}
|
|
@@ -7,7 +7,7 @@ import { QueueTrxNode } from './nodes/queue.trx_node';
|
|
|
7
7
|
import { ResourceTrxNode } from './nodes/resource.trx_node';
|
|
8
8
|
import { $Message } from "../../elements/entities/message/message.schema";
|
|
9
9
|
import { MachineTrxNode } from './nodes/machine.trx_node';
|
|
10
|
-
import { AnyUsers } from '../auth/authn';
|
|
10
|
+
import { AnyUsers, AuthnRequest } from '../auth/authn';
|
|
11
11
|
import { Enum } from "../../elements/entities/constants/constants";
|
|
12
12
|
import { KeysOfUnion } from '../util/type';
|
|
13
13
|
type TrxNodeBlock = 'bucket' | 'message' | 'job' | 'resource' | 'machine' | 'queue' | 'controller';
|
|
@@ -27,7 +27,7 @@ export declare class TrxNode<Space extends $Space, M extends $Module, Authn exte
|
|
|
27
27
|
private trx;
|
|
28
28
|
private parent;
|
|
29
29
|
private module;
|
|
30
|
-
private
|
|
30
|
+
private authn?;
|
|
31
31
|
id: string;
|
|
32
32
|
globalId: string;
|
|
33
33
|
private children;
|
|
@@ -37,7 +37,10 @@ export declare class TrxNode<Space extends $Space, M extends $Module, Authn exte
|
|
|
37
37
|
private output?;
|
|
38
38
|
private error?;
|
|
39
39
|
private time;
|
|
40
|
-
constructor(scope: 'root' | `${string}::${TrxNodeBlock}:${string}` | `${string}::virtual`, trx: AnyTrx, parent: AnyTrxNode | undefined, module: AnyModule,
|
|
40
|
+
constructor(scope: 'root' | `${string}::${TrxNodeBlock}:${string}` | `${string}::virtual`, trx: AnyTrx, parent: AnyTrxNode | undefined, module: AnyModule, authn?: {
|
|
41
|
+
tokens: AuthnRequest<any>;
|
|
42
|
+
users: Authn;
|
|
43
|
+
} | undefined, id?: string);
|
|
41
44
|
static open(node: AnyTrxNode, action: string, input: Record<string, any>): Promise<void>;
|
|
42
45
|
static ok(node: AnyTrxNode, output?: Record<string, any>): Promise<void>;
|
|
43
46
|
static error(node: AnyTrxNode, error: any): Promise<void>;
|
|
@@ -50,12 +53,19 @@ export declare class TrxNode<Space extends $Space, M extends $Module, Authn exte
|
|
|
50
53
|
resource<Name extends keyof M['resources'], Resource extends M['resources'][Name]>(name: Name): ResourceTrxNode<M, Resource>;
|
|
51
54
|
machine<Name extends keyof M['machines'], Machine extends M['machines'][Name]>(name: Name): MachineTrxNode<M, Machine>;
|
|
52
55
|
queue<Name extends keyof M['queues'], Queue extends M['queues'][Name]>(name: Name): QueueTrxNode<M, Queue>;
|
|
56
|
+
token<U extends keyof Authn & keyof M['#authn']>(provider: U): M['#authn'][U];
|
|
53
57
|
user<U extends keyof Authn & keyof M['#authn']>(provider: U): M['#authn'][U];
|
|
54
58
|
virtual<T>(def: VirtualModuleDef, fn: ($: AnyTrxNode) => T | Promise<T>): Promise<T>;
|
|
55
59
|
status(): TrxNodeStatus;
|
|
56
60
|
static makeChildNode<Space extends $Space, M extends $Module, Authn extends AnyUsers>(node: TrxNode<Space, M, Authn>, module: string, block: TrxNodeBlock, name: string): TrxNode<Space, M, Authn>;
|
|
57
61
|
static makeVirtualChildNode<Space extends $Space, M extends $Module, Authn extends AnyUsers>(node: TrxNode<Space, M, Authn>, module: AnyModule): TrxNode<Space, M, Authn>;
|
|
58
|
-
static
|
|
62
|
+
static addAuthn(node: AnyTrxNode, tokens: AuthnRequest<any>, users: AnyUsers): void;
|
|
63
|
+
static getModule(node: AnyTrxNode): AnyModule;
|
|
64
|
+
static getFirstUserMatch(node: AnyTrxNode, authnProviders?: Record<string, any>): {
|
|
65
|
+
provider: string;
|
|
66
|
+
user: any;
|
|
67
|
+
} | undefined;
|
|
68
|
+
static checkAuthn(node: AnyTrxNode, authnProviderOptions?: string[]): void;
|
|
59
69
|
}
|
|
60
70
|
export type AnyTrxNode = TrxNode<any, any, any>;
|
|
61
71
|
export {};
|
|
@@ -16,12 +16,12 @@ const datetime_1 = require("../data/datetime");
|
|
|
16
16
|
Transaction Node
|
|
17
17
|
*/
|
|
18
18
|
class TrxNode {
|
|
19
|
-
constructor(scope, trx, parent, module,
|
|
19
|
+
constructor(scope, trx, parent, module, authn, id) {
|
|
20
20
|
this.scope = scope;
|
|
21
21
|
this.trx = trx;
|
|
22
22
|
this.parent = parent;
|
|
23
23
|
this.module = module;
|
|
24
|
-
this.
|
|
24
|
+
this.authn = authn;
|
|
25
25
|
this.children = [];
|
|
26
26
|
this.time = {
|
|
27
27
|
start: datetime_1.NesoiDatetime.now(),
|
|
@@ -117,17 +117,25 @@ class TrxNode {
|
|
|
117
117
|
return new queue_trx_node_1.QueueTrxNode(this, queue);
|
|
118
118
|
}
|
|
119
119
|
// Authentication
|
|
120
|
+
token(provider) {
|
|
121
|
+
if (!this.authn?.tokens) {
|
|
122
|
+
throw error_1.NesoiError.Authn.NoUsersAuthenticatedForTrxNode(this.globalId);
|
|
123
|
+
}
|
|
124
|
+
return this.authn?.tokens[provider];
|
|
125
|
+
}
|
|
120
126
|
user(provider) {
|
|
121
|
-
if (!this.users) {
|
|
127
|
+
if (!this.authn?.users) {
|
|
122
128
|
throw error_1.NesoiError.Authn.NoUsersAuthenticatedForTrxNode(this.globalId);
|
|
123
129
|
}
|
|
124
|
-
return this.users[provider];
|
|
130
|
+
return this.authn?.users[provider];
|
|
125
131
|
}
|
|
126
132
|
// Virtual Module Transaction
|
|
127
133
|
async virtual(def, fn) {
|
|
134
|
+
if (!this.module.daemon) {
|
|
135
|
+
throw new Error(`Internal Error: unable to reach nesoi daemon when building virtual module '${def.name}'`);
|
|
136
|
+
}
|
|
128
137
|
// Build virtual module
|
|
129
|
-
const
|
|
130
|
-
const virtualModule = await module_1.Module.virtual(module, def);
|
|
138
|
+
const virtualModule = await module_1.Module.virtual(this.module.daemon, def);
|
|
131
139
|
// Create trx node of virtual module
|
|
132
140
|
const node = TrxNode.makeVirtualChildNode(this, virtualModule);
|
|
133
141
|
await TrxNode.open(node, 'run', {});
|
|
@@ -157,19 +165,53 @@ class TrxNode {
|
|
|
157
165
|
}
|
|
158
166
|
//
|
|
159
167
|
static makeChildNode(node, module, block, name) {
|
|
160
|
-
const child = new TrxNode(`${module}::${block}:${name}`, node.trx, node, node.module);
|
|
168
|
+
const child = new TrxNode(`${module}::${block}:${name}`, node.trx, node, node.module, node.authn);
|
|
161
169
|
node.children.push(child);
|
|
162
170
|
node.trx.addNode(child);
|
|
163
171
|
return child;
|
|
164
172
|
}
|
|
165
173
|
static makeVirtualChildNode(node, module) {
|
|
166
|
-
const child = new TrxNode(`${module.name}::virtual`, node.trx, node, module);
|
|
174
|
+
const child = new TrxNode(`${module.name}::virtual`, node.trx, node, module, node.authn);
|
|
167
175
|
node.children.push(child);
|
|
168
176
|
node.trx.addNode(child);
|
|
169
177
|
return child;
|
|
170
178
|
}
|
|
179
|
+
static addAuthn(node, tokens, users) {
|
|
180
|
+
var _a, _b;
|
|
181
|
+
node.authn ?? (node.authn = {
|
|
182
|
+
tokens: {},
|
|
183
|
+
users: {}
|
|
184
|
+
});
|
|
185
|
+
(_a = node.authn).tokens ?? (_a.tokens = {});
|
|
186
|
+
(_b = node.authn).users ?? (_b.users = {});
|
|
187
|
+
Object.assign(node.authn.tokens, tokens);
|
|
188
|
+
Object.assign(node.authn.users, users);
|
|
189
|
+
}
|
|
171
190
|
static getModule(node) {
|
|
172
191
|
return node.module;
|
|
173
192
|
}
|
|
193
|
+
static getFirstUserMatch(node, authnProviders) {
|
|
194
|
+
if (!authnProviders)
|
|
195
|
+
return undefined;
|
|
196
|
+
for (const provider in authnProviders) {
|
|
197
|
+
const user = node.authn?.users[provider];
|
|
198
|
+
if (user) {
|
|
199
|
+
return { provider, user };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
static checkAuthn(node, authnProviderOptions) {
|
|
205
|
+
if (!authnProviderOptions?.length)
|
|
206
|
+
return;
|
|
207
|
+
if (node.authn?.users) {
|
|
208
|
+
for (const provider of authnProviderOptions) {
|
|
209
|
+
if (provider in node.authn.users) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
throw error_1.NesoiError.Trx.NotAuthenticated({});
|
|
215
|
+
}
|
|
174
216
|
}
|
|
175
217
|
exports.TrxNode = TrxNode;
|
package/lib/engine/tree.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare class ModuleTree {
|
|
|
28
28
|
module: string;
|
|
29
29
|
type: BuilderType;
|
|
30
30
|
name: string;
|
|
31
|
-
}): import("../elements").$Message | import("../elements").$
|
|
31
|
+
}): import("../elements").$Message | import("../elements").$Machine | import("../elements").$Bucket | import("../elements").$Constants | import("../elements").$Job | import("../elements").$Externals | import("../elements").$Resource | import("../elements").$Controller;
|
|
32
32
|
allNodes(): ResolvedBuilderNode[];
|
|
33
33
|
}
|
|
34
34
|
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare class Crypto {
|
|
2
|
+
static DEFAULTS: {
|
|
3
|
+
algorithm: string;
|
|
4
|
+
/**
|
|
5
|
+
* NIST recommends 96 bits or 12 bytes IV for GCM
|
|
6
|
+
* to promote interoperability, efficiency, and
|
|
7
|
+
* simplicity of design
|
|
8
|
+
*/
|
|
9
|
+
iv_bytes: number;
|
|
10
|
+
/**
|
|
11
|
+
* Note: 256 (in algorithm name) is key size.
|
|
12
|
+
* Block size for AES is always 128
|
|
13
|
+
*/
|
|
14
|
+
key_bytes: number;
|
|
15
|
+
/**
|
|
16
|
+
* To prevent rainbow table attacks
|
|
17
|
+
* */
|
|
18
|
+
salt_bytes: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* To prevent rainbow table attacks
|
|
22
|
+
* */
|
|
23
|
+
static getIV(): Buffer;
|
|
24
|
+
/**
|
|
25
|
+
* To prevent rainbow table attacks
|
|
26
|
+
* */
|
|
27
|
+
static getSalt(): Buffer;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param {Buffer} password - The password to be used for generating key
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
static getKeyFromPassword(password: string, salt: string): string;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param {string} payload - The clear text message to be encrypted
|
|
37
|
+
* @param {string} key - The key to be used for encryption
|
|
38
|
+
*/
|
|
39
|
+
static encrypt(value: any, key: string): string;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param {Buffer} ciphertext - Cipher text
|
|
43
|
+
* @param {Buffer} key - The key to be used for decryption
|
|
44
|
+
*
|
|
45
|
+
* The caller of this function has the responsibility to clear
|
|
46
|
+
* the Buffer after the decryption to prevent the message text
|
|
47
|
+
* and the key from lingering in the memory
|
|
48
|
+
*/
|
|
49
|
+
static decrypt(ciphertext: string, key: string): any;
|
|
50
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO: Jest breaks with crypto types.
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
+
//@ts-nocheck
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Crypto = void 0;
|
|
10
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
+
class Crypto {
|
|
12
|
+
/**
|
|
13
|
+
* To prevent rainbow table attacks
|
|
14
|
+
* */
|
|
15
|
+
static getIV() {
|
|
16
|
+
return crypto_1.default.randomBytes(this.DEFAULTS.iv_bytes);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* To prevent rainbow table attacks
|
|
20
|
+
* */
|
|
21
|
+
static getSalt() {
|
|
22
|
+
return crypto_1.default.randomBytes(this.DEFAULTS.salt_bytes);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param {Buffer} password - The password to be used for generating key
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
static getKeyFromPassword(password, salt) {
|
|
30
|
+
const buffer = crypto_1.default.scryptSync(password, salt, this.DEFAULTS.key_bytes);
|
|
31
|
+
const str = buffer.toString();
|
|
32
|
+
buffer.fill(0);
|
|
33
|
+
return str;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param {string} payload - The clear text message to be encrypted
|
|
38
|
+
* @param {string} key - The key to be used for encryption
|
|
39
|
+
*/
|
|
40
|
+
static encrypt(value, key) {
|
|
41
|
+
const payload = JSON.stringify(value);
|
|
42
|
+
const iv = this.getIV();
|
|
43
|
+
const cipher = crypto_1.default.createCipheriv(this.DEFAULTS.algorithm, key, iv);
|
|
44
|
+
let encrypted = cipher.update(payload);
|
|
45
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
46
|
+
const buffer = Buffer.concat([iv, encrypted]);
|
|
47
|
+
const str = buffer.toString();
|
|
48
|
+
buffer.fill(0);
|
|
49
|
+
return str;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {Buffer} ciphertext - Cipher text
|
|
54
|
+
* @param {Buffer} key - The key to be used for decryption
|
|
55
|
+
*
|
|
56
|
+
* The caller of this function has the responsibility to clear
|
|
57
|
+
* the Buffer after the decryption to prevent the message text
|
|
58
|
+
* and the key from lingering in the memory
|
|
59
|
+
*/
|
|
60
|
+
static decrypt(ciphertext, key) {
|
|
61
|
+
const iv = ciphertext.slice(0, 12);
|
|
62
|
+
const encryptedMessage = ciphertext.slice(12, -16);
|
|
63
|
+
const decipher = crypto_1.default.createDecipheriv(this.DEFAULTS.algorithm, key, iv);
|
|
64
|
+
const payload = decipher.update(encryptedMessage, 'utf8');
|
|
65
|
+
const buffer = Buffer.concat([payload, decipher.final()]);
|
|
66
|
+
const str = buffer.toString();
|
|
67
|
+
buffer.fill(0);
|
|
68
|
+
return JSON.parse(str);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.Crypto = Crypto;
|
|
72
|
+
Crypto.DEFAULTS = {
|
|
73
|
+
algorithm: 'aes-256',
|
|
74
|
+
/**
|
|
75
|
+
* NIST recommends 96 bits or 12 bytes IV for GCM
|
|
76
|
+
* to promote interoperability, efficiency, and
|
|
77
|
+
* simplicity of design
|
|
78
|
+
*/
|
|
79
|
+
iv_bytes: 12,
|
|
80
|
+
/**
|
|
81
|
+
* Note: 256 (in algorithm name) is key size.
|
|
82
|
+
* Block size for AES is always 128
|
|
83
|
+
*/
|
|
84
|
+
key_bytes: 32,
|
|
85
|
+
/**
|
|
86
|
+
* To prevent rainbow table attacks
|
|
87
|
+
* */
|
|
88
|
+
salt_bytes: 16
|
|
89
|
+
};
|
|
@@ -5,3 +5,8 @@ export type DeepPartial<T> = T extends object ? {
|
|
|
5
5
|
export type DeepPartialNullable<T> = UndefinedToOptional<T extends object ? {
|
|
6
6
|
[P in keyof T]?: DeepPartial<T[P]> | null;
|
|
7
7
|
} : T>;
|
|
8
|
+
type Obj = Record<string, any>;
|
|
9
|
+
export declare class Deep {
|
|
10
|
+
static copy<T extends Obj>(obj: T): T;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
package/lib/engine/util/deep.js
CHANGED
|
@@ -1,2 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Deep = void 0;
|
|
4
|
+
class Deep {
|
|
5
|
+
static copy(obj) {
|
|
6
|
+
const copy = {};
|
|
7
|
+
let poll = [[obj, copy]];
|
|
8
|
+
while (poll.length) {
|
|
9
|
+
const next = [];
|
|
10
|
+
for (const [obj, copy] of poll) {
|
|
11
|
+
if (Array.isArray(obj)) {
|
|
12
|
+
for (const item of obj) {
|
|
13
|
+
if (item === null) {
|
|
14
|
+
copy.push(null);
|
|
15
|
+
}
|
|
16
|
+
else if (typeof item === 'object') {
|
|
17
|
+
const nextCopy = Array.isArray(item) ? [] : {};
|
|
18
|
+
copy.push(nextCopy);
|
|
19
|
+
next.push([item, nextCopy]);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
copy.push(item);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
for (const key in obj) {
|
|
28
|
+
const item = obj[key];
|
|
29
|
+
if (item === null) {
|
|
30
|
+
copy[key] = null;
|
|
31
|
+
}
|
|
32
|
+
else if (typeof item === 'object') {
|
|
33
|
+
const nextCopy = Array.isArray(item) ? [] : {};
|
|
34
|
+
copy[key] = nextCopy;
|
|
35
|
+
next.push([item, nextCopy]);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
copy[key] = item;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
poll = next;
|
|
44
|
+
}
|
|
45
|
+
return copy;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.Deep = Deep;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
export type DotEnvFile = Record<string, string>;
|
|
2
2
|
export declare class DotEnv {
|
|
3
3
|
static path: string;
|
|
4
|
-
static load():
|
|
4
|
+
static load(): void;
|
|
5
|
+
static parse(): DotEnvFile;
|
|
5
6
|
static save(dotenv: DotEnvFile): void;
|
|
6
7
|
static get(key: string): string;
|
|
7
8
|
static set(key: string, value: string): void;
|
|
8
9
|
}
|
|
9
|
-
export type DotEnvValidatorFile = Record<string, string>;
|
|
10
|
-
export declare class DotEnvValidator {
|
|
11
|
-
static path: string;
|
|
12
|
-
static load(): DotEnvValidatorFile;
|
|
13
|
-
static save(validator: DotEnvValidatorFile): void;
|
|
14
|
-
static set(key: string, type: 'string' | 'number' | 'enum', args?: any): void;
|
|
15
|
-
}
|