nesoi 3.2.9 → 3.3.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 +33 -2
- package/lib/bundler/browser/browser.app.d.ts +32 -0
- package/lib/bundler/browser/browser.app.js +51 -0
- package/lib/bundler/browser/browser.bundler.d.ts +5 -0
- package/lib/bundler/browser/browser.bundler.js +27 -0
- package/lib/bundler/browser/stages/8_replace_nesoi_for_browser_stage.d.ts +13 -0
- package/lib/bundler/browser/stages/8_replace_nesoi_for_browser_stage.js +74 -0
- package/lib/bundler/distributed/distributed.app.config.d.ts +43 -0
- package/lib/{engine/apps → bundler}/distributed/distributed.app.config.js +1 -1
- package/lib/{engine/apps → bundler}/distributed/distributed.app.d.ts +14 -14
- package/lib/{engine/apps → bundler}/distributed/distributed.app.js +8 -3
- package/lib/{compiler/apps/distributed/distributed_compiler.d.ts → bundler/distributed/distributed.bundler.d.ts} +7 -7
- package/lib/{compiler/apps/distributed/distributed_compiler.js → bundler/distributed/distributed.bundler.js} +11 -11
- package/lib/{engine/apps → bundler}/distributed/distributed_node.app.d.ts +14 -20
- package/lib/{engine/apps → bundler}/distributed/distributed_node.app.js +18 -50
- package/lib/bundler/distributed/stages/1_mkdir_stage.d.ts +15 -0
- package/lib/{compiler/apps → bundler}/distributed/stages/1_mkdir_stage.js +6 -6
- package/lib/bundler/distributed/stages/2_build_typescript_stage.d.ts +15 -0
- package/lib/{compiler/apps → bundler}/distributed/stages/2_build_typescript_stage.js +7 -7
- package/lib/bundler/distributed/stages/3_copy_types_stage.d.ts +15 -0
- package/lib/{compiler/apps → bundler}/distributed/stages/3_copy_types_stage.js +7 -7
- package/lib/bundler/distributed/stages/4_dump_modules_stage.d.ts +16 -0
- package/lib/{compiler/apps → bundler}/distributed/stages/4_dump_modules_stage.js +5 -5
- package/lib/{compiler/apps → bundler}/distributed/stages/5_copy_static_stage.js +3 -3
- package/lib/{compiler/apps → bundler}/distributed/stages/6_dump_cli_stage.js +3 -3
- package/lib/{compiler/apps → bundler}/distributed/stages/7_dump_package_json_stage.js +3 -3
- package/lib/{engine/apps → bundler}/monolyth/monolyth.app.d.ts +13 -13
- package/lib/{engine/apps → bundler}/monolyth/monolyth.app.js +13 -10
- package/lib/{compiler/apps/monolyth/monolyth_compiler.d.ts → bundler/monolyth/monolyth.bundler.d.ts} +9 -7
- package/lib/{compiler/apps/monolyth/monolyth_compiler.js → bundler/monolyth/monolyth.bundler.js} +13 -12
- package/lib/bundler/monolyth/stages/1_mkdir_stage.d.ts +15 -0
- package/lib/{compiler/apps → bundler}/monolyth/stages/1_mkdir_stage.js +6 -6
- package/lib/bundler/monolyth/stages/2_build_typescript_stage.d.ts +15 -0
- package/lib/{compiler/apps → bundler}/monolyth/stages/2_build_typescript_stage.js +8 -7
- package/lib/bundler/monolyth/stages/3_copy_types_stage.d.ts +15 -0
- package/lib/{compiler/apps → bundler}/monolyth/stages/3_copy_types_stage.js +7 -7
- package/lib/{compiler/apps → bundler}/monolyth/stages/4_dump_modules_stage.d.ts +4 -4
- package/lib/{compiler/apps → bundler}/monolyth/stages/4_dump_modules_stage.js +29 -16
- package/lib/{compiler/apps → bundler}/monolyth/stages/5_copy_static_stage.d.ts +4 -4
- package/lib/{compiler/apps → bundler}/monolyth/stages/5_copy_static_stage.js +7 -7
- package/lib/bundler/monolyth/stages/6_dump_cli_stage.d.ts +15 -0
- package/lib/{compiler/apps → bundler}/monolyth/stages/6_dump_cli_stage.js +4 -4
- package/lib/{compiler/apps → bundler}/monolyth/stages/7_dump_package_json_stage.d.ts +4 -4
- package/lib/{compiler/apps → bundler}/monolyth/stages/7_dump_package_json_stage.js +14 -11
- package/lib/compiler/compiler.d.ts +1 -6
- package/lib/compiler/compiler.js +1 -1
- package/lib/compiler/elements/bucket.element.d.ts +2 -1
- package/lib/compiler/elements/bucket.element.js +16 -21
- package/lib/compiler/elements/cached.element.d.ts +1 -1
- package/lib/compiler/elements/cached.element.js +2 -2
- package/lib/compiler/elements/constants.element.d.ts +1 -1
- package/lib/compiler/elements/constants.element.js +2 -0
- package/lib/compiler/elements/controller.element.js +3 -3
- package/lib/compiler/elements/element.d.ts +6 -13
- package/lib/compiler/elements/element.js +11 -9
- package/lib/compiler/elements/externals.element.js +2 -2
- package/lib/compiler/elements/job.element.d.ts +1 -1
- package/lib/compiler/elements/job.element.js +1 -1
- package/lib/compiler/elements/machine.element.d.ts +2 -2
- package/lib/compiler/elements/machine.element.js +7 -7
- package/lib/compiler/elements/message.element.d.ts +1 -1
- package/lib/compiler/elements/message.element.js +26 -26
- package/lib/compiler/elements/queue.element.js +1 -1
- package/lib/compiler/elements/resource.element.d.ts +1 -1
- package/lib/compiler/elements/resource.element.js +9 -9
- package/lib/compiler/elements/topic.element.js +1 -1
- package/lib/compiler/error.d.ts +1 -5
- package/lib/compiler/error.js +3 -15
- package/lib/compiler/helpers/dump_helpers.d.ts +1 -1
- package/lib/compiler/helpers/dump_helpers.js +1 -1
- package/lib/compiler/index.d.ts +1 -3
- package/lib/compiler/index.js +15 -7
- package/lib/compiler/module.js +12 -12
- package/lib/compiler/progressive.d.ts +3 -4
- package/lib/compiler/progressive.js +3 -4
- package/lib/compiler/stages/2_treeshake_stage.js +4 -0
- package/lib/compiler/stages/3_extract_ts_stage.js +7 -7
- package/lib/compiler/stages/4_build_schemas_stage.js +3 -16
- package/lib/compiler/stages/6_build_elements_stage.js +1 -1
- package/lib/compiler/stages/7_dump_stage.js +35 -10
- package/lib/compiler/typescript/bridge/extract.js +24 -0
- package/lib/compiler/typescript/bridge/inject.js +18 -3
- package/lib/compiler/typescript/bridge/organize.d.ts +4 -0
- package/lib/compiler/typescript/bridge/organize.js +41 -22
- package/lib/compiler/typescript/error.d.ts +2 -83
- package/lib/compiler/typescript/error.js +6 -219
- package/lib/compiler/typescript/parser.js +3 -3
- package/lib/compiler/typescript/source.d.ts +2 -2
- package/lib/compiler/typescript/transformers/app_inject.transformer.js +13 -4
- package/lib/compiler/typescript/typescript_compiler.d.ts +3 -3
- package/lib/compiler/typescript/typescript_compiler.js +2 -2
- package/lib/elements/blocks/block.builder.d.ts +7 -4
- package/lib/elements/blocks/block.builder.js +24 -13
- package/lib/elements/blocks/block.js +2 -2
- package/lib/elements/blocks/block.schema.d.ts +12 -9
- package/lib/elements/blocks/block.schema.js +2 -2
- package/lib/elements/blocks/job/internal/machine_job.builder.d.ts +6 -5
- package/lib/elements/blocks/job/internal/machine_job.builder.js +3 -3
- package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +11 -10
- package/lib/elements/blocks/job/internal/resource_job.builder.js +9 -6
- package/lib/elements/blocks/job/internal/resource_job.js +3 -6
- package/lib/elements/blocks/job/job.builder.d.ts +5 -5
- package/lib/elements/blocks/job/job.builder.js +7 -7
- package/lib/elements/blocks/job/job.js +1 -1
- package/lib/elements/blocks/job/job.schema.d.ts +5 -5
- package/lib/elements/blocks/job/job.schema.js +3 -3
- package/lib/elements/blocks/machine/machine.builder.d.ts +2 -2
- package/lib/elements/blocks/machine/machine.builder.js +12 -9
- package/lib/elements/blocks/machine/machine.js +7 -7
- package/lib/elements/blocks/machine/machine.schema.d.ts +23 -23
- package/lib/elements/blocks/machine/machine.schema.js +9 -9
- package/lib/elements/blocks/machine/machine_state.builder.d.ts +1 -0
- package/lib/elements/blocks/machine/machine_state.builder.js +31 -29
- package/lib/elements/blocks/machine/machine_transition.builder.d.ts +2 -2
- package/lib/elements/blocks/machine/machine_transition.builder.js +8 -8
- package/lib/elements/blocks/queue/queue.builder.d.ts +3 -3
- package/lib/elements/blocks/queue/queue.builder.js +3 -3
- package/lib/elements/blocks/queue/queue.schema.d.ts +6 -6
- package/lib/elements/blocks/queue/queue.schema.js +3 -3
- package/lib/elements/blocks/resource/resource.builder.d.ts +2 -2
- package/lib/elements/blocks/resource/resource.builder.js +37 -40
- package/lib/elements/blocks/resource/resource.d.ts +2 -2
- package/lib/elements/blocks/resource/resource.js +10 -18
- package/lib/elements/blocks/resource/resource.schema.d.ts +15 -15
- package/lib/elements/blocks/resource/resource.schema.js +8 -8
- package/lib/elements/blocks/topic/topic.builder.d.ts +2 -2
- package/lib/elements/blocks/topic/topic.builder.js +4 -4
- package/lib/elements/blocks/topic/topic.d.ts +2 -2
- package/lib/elements/blocks/topic/topic.js +7 -7
- package/lib/elements/blocks/topic/topic.schema.d.ts +6 -6
- package/lib/elements/blocks/topic/topic.schema.js +3 -3
- package/lib/elements/edge/controller/adapters/cli.controller_adapter.js +1 -1
- package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +2 -2
- package/lib/elements/edge/controller/adapters/controller_adapter.js +2 -2
- package/lib/elements/edge/controller/controller.builder.d.ts +14 -13
- package/lib/elements/edge/controller/controller.builder.js +52 -42
- package/lib/elements/edge/controller/controller.d.ts +3 -3
- package/lib/elements/edge/controller/controller.js +12 -12
- package/lib/elements/edge/controller/controller.schema.d.ts +17 -16
- package/lib/elements/edge/controller/controller.schema.js +11 -11
- package/lib/elements/edge/externals/externals.builder.d.ts +8 -13
- package/lib/elements/edge/externals/externals.builder.js +43 -11
- package/lib/elements/edge/externals/externals.schema.d.ts +8 -7
- package/lib/elements/edge/externals/externals.schema.js +5 -3
- package/lib/elements/entities/bucket/adapters/browserdb.bucket_adapter.d.ts +45 -0
- package/lib/elements/entities/bucket/adapters/browserdb.bucket_adapter.js +164 -0
- package/lib/elements/entities/bucket/adapters/browserdb.service.d.ts +30 -0
- package/lib/elements/entities/bucket/adapters/browserdb.service.js +97 -0
- package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +6 -1
- package/lib/elements/entities/bucket/adapters/bucket_adapter.js +7 -6
- package/lib/elements/entities/bucket/adapters/json.bucket_adapter.d.ts +1 -1
- package/lib/elements/entities/bucket/adapters/json.bucket_adapter.js +1 -0
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.d.ts +1 -0
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +14 -13
- package/lib/elements/entities/bucket/adapters/memory.nql.js +41 -35
- package/lib/elements/entities/bucket/bucket.builder.d.ts +6 -8
- package/lib/elements/entities/bucket/bucket.builder.js +19 -34
- package/lib/elements/entities/bucket/bucket.d.ts +2 -2
- package/lib/elements/entities/bucket/bucket.infer.d.ts +5 -5
- package/lib/elements/entities/bucket/bucket.js +19 -17
- package/lib/elements/entities/bucket/bucket.schema.d.ts +3 -3
- package/lib/elements/entities/bucket/bucket.schema.js +2 -2
- package/lib/elements/entities/bucket/cache/bucket_cache.js +14 -2
- package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +3 -3
- package/lib/elements/entities/bucket/graph/bucket_graph.js +101 -29
- package/lib/elements/entities/bucket/graph/bucket_graph.schema.d.ts +3 -3
- package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.d.ts +2 -2
- package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.js +5 -3
- package/lib/elements/entities/bucket/model/bucket_model.builder.d.ts +2 -1
- package/lib/elements/entities/bucket/model/bucket_model.builder.js +2 -2
- package/lib/elements/entities/bucket/model/bucket_model.convert.js +3 -6
- package/lib/elements/entities/bucket/model/bucket_model.d.ts +13 -0
- package/lib/elements/entities/bucket/model/bucket_model.js +93 -0
- package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +4 -8
- package/lib/elements/entities/bucket/model/bucket_model.schema.js +0 -68
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +12 -4
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +30 -33
- package/lib/elements/entities/bucket/query/nql.schema.d.ts +1 -1
- package/lib/elements/entities/bucket/query/nql_compiler.d.ts +8 -4
- package/lib/elements/entities/bucket/query/nql_compiler.js +44 -38
- package/lib/elements/entities/bucket/query/nql_engine.d.ts +1 -1
- package/lib/elements/entities/bucket/query/nql_engine.js +5 -2
- package/lib/elements/entities/bucket/view/bucket_view.builder.d.ts +2 -2
- package/lib/elements/entities/bucket/view/bucket_view.js +113 -81
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +9 -8
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +8 -10
- package/lib/elements/entities/constants/constants.builder.d.ts +3 -3
- package/lib/elements/entities/constants/constants.builder.js +8 -8
- package/lib/elements/entities/constants/constants.schema.d.ts +8 -3
- package/lib/elements/entities/constants/constants.schema.js +7 -2
- package/lib/elements/entities/message/message.infer.d.ts +1 -5
- package/lib/elements/entities/message/message.js +2 -7
- package/lib/elements/entities/message/message.schema.js +1 -1
- package/lib/elements/entities/message/template/message_template.schema.d.ts +7 -5
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +18 -3
- package/lib/elements/entities/message/template/message_template_field.builder.js +49 -30
- package/lib/elements/entities/message/template/message_template_parser.js +2 -2
- package/lib/engine/{apps → app}/app.config.d.ts +11 -5
- package/lib/engine/{apps → app}/app.config.js +2 -2
- package/lib/engine/{apps → app}/app.d.ts +3 -2
- package/lib/engine/{apps → app}/app.js +3 -1
- package/lib/engine/{apps/distributed → app}/inc/inc.client.js +1 -1
- package/lib/engine/{apps/distributed → app}/inc/inc.server.js +3 -3
- package/lib/engine/{apps/distributed → app}/inc/sandbox.js +1 -1
- package/lib/engine/{apps → app}/inline.app.d.ts +2 -12
- package/lib/engine/{apps → app}/inline.app.js +37 -34
- package/lib/engine/auth/authn.d.ts +10 -12
- package/lib/engine/auth/zero.authn_provider.d.ts +3 -4
- package/lib/engine/auth/zero.authn_provider.js +0 -1
- package/lib/engine/builder.d.ts +28 -0
- package/lib/engine/builder.js +99 -0
- package/lib/engine/cli/cli.js +3 -2
- package/lib/engine/cli/ui.js +1 -0
- package/lib/engine/daemon.d.ts +28 -25
- package/lib/engine/daemon.js +37 -8
- package/lib/engine/data/error.d.ts +37 -3
- package/lib/engine/data/error.js +58 -16
- package/lib/engine/data/file.d.ts +1 -0
- package/lib/engine/data/file.js +4 -0
- package/lib/engine/dependency.d.ts +53 -81
- package/lib/engine/dependency.js +246 -120
- package/lib/engine/module.d.ts +18 -48
- package/lib/engine/module.js +78 -158
- package/lib/engine/space.d.ts +2 -2
- package/lib/engine/space.js +6 -6
- package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +7 -4
- package/lib/engine/transaction/nodes/bucket.trx_node.js +66 -43
- package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +10 -4
- package/lib/engine/transaction/nodes/bucket_query.trx_node.js +56 -45
- package/lib/engine/transaction/nodes/external.trx_node.d.ts +15 -0
- package/lib/engine/transaction/nodes/external.trx_node.js +53 -0
- package/lib/engine/transaction/nodes/job.trx_node.d.ts +7 -3
- package/lib/engine/transaction/nodes/job.trx_node.js +49 -29
- package/lib/engine/transaction/nodes/machine.trx_node.js +6 -6
- package/lib/engine/transaction/nodes/queue.trx_node.js +3 -3
- package/lib/engine/transaction/nodes/resource.trx_node.d.ts +7 -4
- package/lib/engine/transaction/nodes/resource.trx_node.js +68 -51
- package/lib/engine/transaction/nodes/topic.trx_node.js +9 -9
- package/lib/engine/transaction/trx.d.ts +15 -12
- package/lib/engine/transaction/trx.js +19 -3
- package/lib/engine/transaction/trx_engine.config.d.ts +4 -4
- package/lib/engine/transaction/trx_engine.d.ts +25 -7
- package/lib/engine/transaction/trx_engine.js +67 -16
- package/lib/engine/transaction/trx_node.d.ts +25 -21
- package/lib/engine/transaction/trx_node.js +99 -57
- package/lib/engine/tree.d.ts +4 -16
- package/lib/engine/tree.js +87 -57
- package/lib/{compiler → engine}/treeshake.d.ts +32 -32
- package/lib/{compiler → engine}/treeshake.js +272 -242
- package/lib/engine/util/console.js +3 -0
- package/lib/engine/util/crypto.d.ts +4 -3
- package/lib/engine/util/crypto.js +15 -5
- package/lib/engine/util/hash.js +5 -0
- package/lib/engine/util/log.d.ts +6 -8
- package/lib/engine/util/log.js +1 -1
- package/lib/engine/util/name_helpers.d.ts +37 -0
- package/lib/{compiler/helpers → engine/util}/name_helpers.js +33 -0
- package/lib/engine/util/parse.d.ts +4 -3
- package/lib/engine/util/parse.js +13 -28
- package/lib/engine/util/path.d.ts +1 -0
- package/lib/engine/util/path.js +14 -0
- package/lib/engine/util/random.d.ts +4 -0
- package/lib/engine/util/random.js +31 -0
- package/lib/engine/util/type.d.ts +8 -0
- package/lib/schema.d.ts +1 -1
- package/package.json +4 -1
- package/tools/joaquin/bucket.js +1 -1
- package/tools/joaquin/job.js +1 -1
- package/tools/joaquin/message.js +1 -1
- package/tools/joaquin/mock.js +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/lib/compiler/apps/distributed/stages/1_mkdir_stage.d.ts +0 -15
- package/lib/compiler/apps/distributed/stages/2_build_typescript_stage.d.ts +0 -15
- package/lib/compiler/apps/distributed/stages/3_copy_types_stage.d.ts +0 -15
- package/lib/compiler/apps/distributed/stages/4_dump_modules_stage.d.ts +0 -16
- package/lib/compiler/apps/monolyth/stages/1_mkdir_stage.d.ts +0 -15
- package/lib/compiler/apps/monolyth/stages/2_build_typescript_stage.d.ts +0 -15
- package/lib/compiler/apps/monolyth/stages/3_copy_types_stage.d.ts +0 -15
- package/lib/compiler/apps/monolyth/stages/6_dump_cli_stage.d.ts +0 -15
- package/lib/compiler/helpers/name_helpers.d.ts +0 -20
- package/lib/engine/apps/distributed/distributed.app.config.d.ts +0 -44
- package/lib/engine/apps/distributed/elements/distributed_job.d.ts +0 -7
- package/lib/engine/apps/distributed/elements/distributed_job.js +0 -11
- /package/lib/{compiler/apps → bundler}/distributed/stages/5_copy_static_stage.d.ts +0 -0
- /package/lib/{compiler/apps → bundler}/distributed/stages/6_dump_cli_stage.d.ts +0 -0
- /package/lib/{compiler/apps → bundler}/distributed/stages/7_dump_package_json_stage.d.ts +0 -0
- /package/lib/engine/{apps/distributed → app}/inc/inc.client.d.ts +0 -0
- /package/lib/engine/{apps/distributed → app}/inc/inc.server.d.ts +0 -0
- /package/lib/engine/{apps/distributed → app}/inc/sandbox.d.ts +0 -0
- /package/lib/engine/{apps → app}/service.d.ts +0 -0
- /package/lib/engine/{apps → app}/service.js +0 -0
|
@@ -9,6 +9,7 @@ const memory_bucket_adapter_1 = require("../../elements/entities/bucket/adapters
|
|
|
9
9
|
const elements_1 = require("../../elements");
|
|
10
10
|
const bucket_model_schema_1 = require("../../elements/entities/bucket/model/bucket_model.schema");
|
|
11
11
|
const bucket_graph_schema_1 = require("../../elements/entities/bucket/graph/bucket_graph.schema");
|
|
12
|
+
const datetime_1 = require("../data/datetime");
|
|
12
13
|
/**
|
|
13
14
|
* @category Engine
|
|
14
15
|
* @subcategory Transaction
|
|
@@ -74,10 +75,10 @@ class TrxEngine {
|
|
|
74
75
|
}
|
|
75
76
|
return trx;
|
|
76
77
|
}
|
|
77
|
-
async trx(fn,
|
|
78
|
-
const trx = await this.get(
|
|
78
|
+
async trx(fn, id, auth) {
|
|
79
|
+
const trx = await this.get(id);
|
|
79
80
|
try {
|
|
80
|
-
await this.authenticate(trx.root,
|
|
81
|
+
await this.authenticate(trx.root, auth);
|
|
81
82
|
let output;
|
|
82
83
|
if (this.config?.wrap) {
|
|
83
84
|
output = await this.config?.wrap(trx, fn, this.services);
|
|
@@ -92,32 +93,80 @@ class TrxEngine {
|
|
|
92
93
|
}
|
|
93
94
|
return trx.status();
|
|
94
95
|
}
|
|
96
|
+
async trx_hold(fn, id, authn) {
|
|
97
|
+
const trx = await this.get(id);
|
|
98
|
+
let output = {};
|
|
99
|
+
try {
|
|
100
|
+
await this.authenticate(trx.root, authn);
|
|
101
|
+
if (this.config?.wrap) {
|
|
102
|
+
output = await this.config?.wrap(trx, fn, this.services);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
output = await fn(trx.root);
|
|
106
|
+
}
|
|
107
|
+
await this.hold(trx, output);
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
await this.rollback(trx, e);
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
id: trx.id,
|
|
114
|
+
status: trx.status(),
|
|
115
|
+
commit: () => this.commit(trx, output),
|
|
116
|
+
rollback: (error) => this.rollback(trx, error)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/* Metadata sharing between modules */
|
|
120
|
+
getBucketMetadata(tag) {
|
|
121
|
+
return {
|
|
122
|
+
...this.module.buckets[tag.name].getQueryMeta(),
|
|
123
|
+
tag,
|
|
124
|
+
meta: this.module.buckets[tag.name].adapter.config.meta,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
getBucketDrive(tag) {
|
|
128
|
+
return this.module.buckets[tag.name].drive;
|
|
129
|
+
}
|
|
95
130
|
// authentication
|
|
96
|
-
async authenticate(node, request = {}) {
|
|
131
|
+
async authenticate(node, request = {}, force = false) {
|
|
97
132
|
if (!this.authnProviders) {
|
|
98
|
-
throw error_1.NesoiError.
|
|
133
|
+
throw error_1.NesoiError.Auth.NoProvidersRegisteredForModule(this.module.name);
|
|
99
134
|
}
|
|
100
135
|
const users = {};
|
|
101
136
|
const tokens = {};
|
|
102
137
|
for (const providerName in this.authnProviders) {
|
|
103
138
|
const provider = this.authnProviders[providerName];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const { user, token } = await provider.authenticate({ trx: node, token: reqToken });
|
|
110
|
-
users[providerName] = user;
|
|
139
|
+
if (!provider) {
|
|
140
|
+
throw error_1.NesoiError.Auth.NoProviderRegisteredForModule(this.module.name, providerName);
|
|
141
|
+
}
|
|
142
|
+
const token = request[providerName];
|
|
143
|
+
if (token) {
|
|
111
144
|
tokens[providerName] = token;
|
|
145
|
+
if (provider.eager || force) {
|
|
146
|
+
const { user } = await provider.authenticate({ trx: node, token });
|
|
147
|
+
users[providerName] = user;
|
|
148
|
+
}
|
|
112
149
|
}
|
|
113
150
|
}
|
|
114
151
|
trx_node_1.TrxNode.addAuthn(node, tokens, users);
|
|
115
152
|
}
|
|
116
153
|
//
|
|
154
|
+
async hold(trx, output) {
|
|
155
|
+
log_1.Log.info('module', this.module.name, `Hold ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
|
|
156
|
+
trx_node_1.TrxNode.hold(trx.root, output);
|
|
157
|
+
await this.adapter.put(this.innerTrx.root, {
|
|
158
|
+
id: trx.id,
|
|
159
|
+
origin: this.origin,
|
|
160
|
+
start: trx.start,
|
|
161
|
+
end: trx.end,
|
|
162
|
+
module: this.module.name
|
|
163
|
+
});
|
|
164
|
+
return trx;
|
|
165
|
+
}
|
|
117
166
|
async commit(trx, output) {
|
|
118
167
|
log_1.Log.info('module', this.module.name, `Commit ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
|
|
119
|
-
|
|
120
|
-
|
|
168
|
+
trx_node_1.TrxNode.ok(trx.root, output);
|
|
169
|
+
trx.end = datetime_1.NesoiDatetime.now();
|
|
121
170
|
await this.adapter.put(this.innerTrx.root, {
|
|
122
171
|
id: trx.id,
|
|
123
172
|
origin: this.origin,
|
|
@@ -125,13 +174,14 @@ class TrxEngine {
|
|
|
125
174
|
end: trx.end,
|
|
126
175
|
module: this.module.name
|
|
127
176
|
});
|
|
177
|
+
await trx_1.Trx.onCommit(trx);
|
|
128
178
|
return trx;
|
|
129
179
|
}
|
|
130
180
|
async rollback(trx, error) {
|
|
131
181
|
log_1.Log.error('module', this.module.name, `[${error.status}] ${error.toString()}`, error.stack);
|
|
132
182
|
log_1.Log.warn('module', this.module.name, `Rollback ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
|
|
133
|
-
|
|
134
|
-
|
|
183
|
+
trx_node_1.TrxNode.error(trx.root, error);
|
|
184
|
+
trx.end = datetime_1.NesoiDatetime.now();
|
|
135
185
|
await this.adapter.put(this.innerTrx.root, {
|
|
136
186
|
id: trx.id,
|
|
137
187
|
origin: this.origin,
|
|
@@ -139,6 +189,7 @@ class TrxEngine {
|
|
|
139
189
|
end: trx.end,
|
|
140
190
|
module: this.module.name
|
|
141
191
|
});
|
|
192
|
+
await trx_1.Trx.onRollback(trx);
|
|
142
193
|
return trx;
|
|
143
194
|
}
|
|
144
195
|
}
|
|
@@ -8,14 +8,16 @@ import { QueueTrxNode } from './nodes/queue.trx_node';
|
|
|
8
8
|
import { ResourceTrxNode } from './nodes/resource.trx_node';
|
|
9
9
|
import { $Message } from "../../elements/entities/message/message.schema";
|
|
10
10
|
import { MachineTrxNode } from './nodes/machine.trx_node';
|
|
11
|
-
import { AnyUsers,
|
|
11
|
+
import { AnyUsers, AuthRequest } from '../auth/authn';
|
|
12
12
|
import { Enum } from "../../elements/entities/constants/constants";
|
|
13
13
|
import { TopicTrxNode } from './nodes/topic.trx_node';
|
|
14
|
-
|
|
14
|
+
import { $BlockAuth } from "../../elements/blocks/block.schema";
|
|
15
|
+
export type TrxNodeBlock = 'bucket' | 'message' | 'job' | 'resource' | 'machine' | 'queue' | 'topic' | 'controller' | 'externals';
|
|
16
|
+
export type TrxNodeState = 'open' | 'hold' | 'ok' | 'error';
|
|
15
17
|
export type TrxNodeStatus = {
|
|
16
18
|
id: string;
|
|
17
19
|
scope: 'root' | `${string}::${TrxNodeBlock}:${string}` | `${string}::virtual`;
|
|
18
|
-
state?:
|
|
20
|
+
state?: TrxNodeState;
|
|
19
21
|
action?: string;
|
|
20
22
|
input?: Record<string, any>;
|
|
21
23
|
output?: Record<string, any>;
|
|
@@ -27,12 +29,13 @@ export type TrxNodeStatus = {
|
|
|
27
29
|
* @category Engine
|
|
28
30
|
* @subcategory Transaction
|
|
29
31
|
*/
|
|
30
|
-
export declare class TrxNode<Space extends $Space, M extends $Module,
|
|
32
|
+
export declare class TrxNode<Space extends $Space, M extends $Module, AuthUsers extends AnyUsers> {
|
|
31
33
|
private scope;
|
|
32
34
|
private trx;
|
|
33
35
|
private parent;
|
|
34
36
|
private module;
|
|
35
|
-
private
|
|
37
|
+
private auth?;
|
|
38
|
+
private external?;
|
|
36
39
|
id: string;
|
|
37
40
|
globalId: string;
|
|
38
41
|
private children;
|
|
@@ -42,15 +45,16 @@ export declare class TrxNode<Space extends $Space, M extends $Module, Authn exte
|
|
|
42
45
|
private output?;
|
|
43
46
|
private error?;
|
|
44
47
|
private time;
|
|
45
|
-
constructor(scope: 'root' | `${string}::${TrxNodeBlock}:${string}` | `${string}::virtual`, trx: AnyTrx, parent: AnyTrxNode | undefined, module: AnyModule,
|
|
46
|
-
tokens:
|
|
47
|
-
users:
|
|
48
|
-
} | undefined, id?: string);
|
|
49
|
-
static open(node: AnyTrxNode, action: string, input: Record<string, any>):
|
|
50
|
-
static
|
|
51
|
-
static
|
|
48
|
+
constructor(scope: 'root' | `${string}::${TrxNodeBlock}:${string}` | `${string}::virtual`, trx: AnyTrx, parent: AnyTrxNode | undefined, module: AnyModule, auth?: {
|
|
49
|
+
tokens: AuthRequest<any>;
|
|
50
|
+
users: AuthUsers;
|
|
51
|
+
} | undefined, external?: boolean | undefined, id?: string);
|
|
52
|
+
static open(node: AnyTrxNode, action: string, input: Record<string, any>): void;
|
|
53
|
+
static hold(node: AnyTrxNode, output?: Record<string, any>): void;
|
|
54
|
+
static ok(node: AnyTrxNode, output?: Record<string, any>): void;
|
|
55
|
+
static error(node: AnyTrxNode, error: any): any;
|
|
52
56
|
message<Raw extends M['#input']['#raw'], Msg extends $Message = M['messages'][Raw['$'] & keyof M['messages']]>(raw: Raw): Promise<M['#input']['#parsed']>;
|
|
53
|
-
value<K extends keyof M['constants']['values']>(
|
|
57
|
+
value<K extends keyof M['constants']['values']>(name: K): M['constants']['values'][K]['value'];
|
|
54
58
|
enum<EnumName extends keyof M['constants']['enums']>(name: EnumName): Enum<M['constants']['enums'][EnumName]>;
|
|
55
59
|
bucket<Name extends keyof M['buckets'], Bucket extends M['buckets'][Name]>(name: Name): BucketTrxNode<M, Bucket>;
|
|
56
60
|
job<Name extends keyof M['jobs'], Job extends M['jobs'][Name]>(name: Name): JobTrxNode<M, Job>;
|
|
@@ -59,20 +63,20 @@ export declare class TrxNode<Space extends $Space, M extends $Module, Authn exte
|
|
|
59
63
|
machine<Name extends keyof M['machines'], Machine extends M['machines'][Name]>(name: Name): MachineTrxNode<M, Machine>;
|
|
60
64
|
queue<Name extends keyof M['queues'], Queue extends M['queues'][Name]>(name: Name): QueueTrxNode<M, Queue>;
|
|
61
65
|
topic<Name extends keyof M['topics'], topic extends M['topics'][Name]>(name: Name): TopicTrxNode<M, topic>;
|
|
62
|
-
authenticate(authnRequest:
|
|
63
|
-
token<U extends keyof
|
|
64
|
-
user<U extends keyof
|
|
66
|
+
authenticate(authnRequest: AuthRequest<keyof AuthUsers>): Promise<TrxNode<$Space, $Module, AuthUsers>>;
|
|
67
|
+
token<U extends keyof AuthUsers & keyof M['#authn']>(provider: U): Promise<string>;
|
|
68
|
+
user<U extends keyof AuthUsers & keyof M['#authn']>(provider: U): Promise<M['#authn'][U]>;
|
|
65
69
|
virtual<T>(def: VirtualModuleDef, fn: ($: AnyTrxNode) => T | Promise<T>): Promise<T>;
|
|
66
70
|
status(): TrxNodeStatus;
|
|
67
|
-
static
|
|
68
|
-
static
|
|
69
|
-
static
|
|
71
|
+
static merge<Space extends $Space, M extends $Module, AuthUsers extends AnyUsers>(to: TrxNode<Space, M, AuthUsers>, from: TrxNode<Space, M, AuthUsers>): void;
|
|
72
|
+
static makeChildNode<Space extends $Space, M extends $Module, AuthUsers extends AnyUsers>(node: TrxNode<Space, M, AuthUsers>, module: string, block: TrxNodeBlock, name: string): TrxNode<Space, M, AuthUsers>;
|
|
73
|
+
static makeVirtualChildNode<Space extends $Space, M extends $Module, AuthUsers extends AnyUsers>(node: TrxNode<Space, M, AuthUsers>, module: AnyModule): TrxNode<Space, M, AuthUsers>;
|
|
74
|
+
static addAuthn(node: AnyTrxNode, tokens: AuthRequest<any>, users: AnyUsers): void;
|
|
70
75
|
static getModule(node: AnyTrxNode): AnyModule;
|
|
71
76
|
static getFirstUserMatch(node: AnyTrxNode, authnProviders?: Record<string, any>): {
|
|
72
77
|
provider: string;
|
|
73
78
|
user: any;
|
|
74
79
|
} | undefined;
|
|
75
|
-
static
|
|
80
|
+
static checkAuth(node: AnyTrxNode, options?: $BlockAuth[]): Promise<void>;
|
|
76
81
|
}
|
|
77
82
|
export type AnyTrxNode = TrxNode<any, any, any>;
|
|
78
|
-
export {};
|
|
@@ -13,6 +13,8 @@ const constants_1 = require("../../elements/entities/constants/constants");
|
|
|
13
13
|
const i18n_1 = require("../util/i18n");
|
|
14
14
|
const datetime_1 = require("../data/datetime");
|
|
15
15
|
const topic_trx_node_1 = require("./nodes/topic.trx_node");
|
|
16
|
+
const dependency_1 = require("../dependency");
|
|
17
|
+
const log_1 = require("../util/log");
|
|
16
18
|
/*
|
|
17
19
|
Transaction Node
|
|
18
20
|
*/
|
|
@@ -21,15 +23,17 @@ const topic_trx_node_1 = require("./nodes/topic.trx_node");
|
|
|
21
23
|
* @subcategory Transaction
|
|
22
24
|
*/
|
|
23
25
|
class TrxNode {
|
|
24
|
-
constructor(scope, trx, parent, module,
|
|
26
|
+
constructor(scope, trx, parent, module, auth, external, id) {
|
|
25
27
|
this.scope = scope;
|
|
26
28
|
this.trx = trx;
|
|
27
29
|
this.parent = parent;
|
|
28
30
|
this.module = module;
|
|
29
|
-
this.
|
|
31
|
+
this.auth = auth;
|
|
32
|
+
this.external = external;
|
|
30
33
|
this.children = [];
|
|
31
34
|
this.time = {
|
|
32
35
|
start: datetime_1.NesoiDatetime.now(),
|
|
36
|
+
hold: undefined,
|
|
33
37
|
end: undefined
|
|
34
38
|
};
|
|
35
39
|
if (parent) {
|
|
@@ -40,17 +44,22 @@ class TrxNode {
|
|
|
40
44
|
}
|
|
41
45
|
this.globalId = `${this.trx.id}.${this.id}`;
|
|
42
46
|
}
|
|
43
|
-
static
|
|
47
|
+
static open(node, action, input) {
|
|
44
48
|
node.state = 'open';
|
|
45
49
|
node.action = action;
|
|
46
50
|
node.input = input;
|
|
47
51
|
}
|
|
48
|
-
static
|
|
52
|
+
static hold(node, output) {
|
|
53
|
+
node.state = 'ok';
|
|
54
|
+
node.output = output;
|
|
55
|
+
node.time.hold = datetime_1.NesoiDatetime.now();
|
|
56
|
+
}
|
|
57
|
+
static ok(node, output) {
|
|
49
58
|
node.state = 'ok';
|
|
50
59
|
node.output = output;
|
|
51
60
|
node.time.end = datetime_1.NesoiDatetime.now();
|
|
52
61
|
}
|
|
53
|
-
static
|
|
62
|
+
static error(node, error) {
|
|
54
63
|
node.state = 'error';
|
|
55
64
|
if (error instanceof error_1.NesoiError.BaseError) {
|
|
56
65
|
error.message = i18n_1.i18n.error(error, node.trx.root.module.daemon);
|
|
@@ -67,56 +76,59 @@ class TrxNode {
|
|
|
67
76
|
// Entities
|
|
68
77
|
async message(raw) {
|
|
69
78
|
const node = TrxNode.makeChildNode(this, this.module.name, 'message', raw.$);
|
|
70
|
-
|
|
79
|
+
TrxNode.open(node, 'parse', raw);
|
|
71
80
|
try {
|
|
72
81
|
const parsed = await message_parser_1.MessageParser.parseWithTrxModule(node, raw);
|
|
73
|
-
|
|
82
|
+
TrxNode.ok(node);
|
|
74
83
|
return parsed;
|
|
75
84
|
}
|
|
76
85
|
catch (e) {
|
|
77
|
-
|
|
86
|
+
TrxNode.error(node, e);
|
|
78
87
|
throw e;
|
|
79
88
|
}
|
|
80
89
|
}
|
|
81
|
-
value(
|
|
90
|
+
value(name) {
|
|
91
|
+
const tag = dependency_1.Tag.fromNameOrShort(this.module.name, 'constants.value', name);
|
|
92
|
+
// (External values have been injected during build as static externals)
|
|
93
|
+
const key = tag.module !== this.module.name
|
|
94
|
+
? tag.short
|
|
95
|
+
: tag.name;
|
|
82
96
|
return this.module.schema.constants.values[key].value;
|
|
83
97
|
}
|
|
84
98
|
enum(name) {
|
|
85
|
-
const
|
|
99
|
+
const tag = dependency_1.Tag.fromNameOrShort(this.module.name, 'constants.value', name);
|
|
100
|
+
// (External enums have been injected during build as static externals)
|
|
101
|
+
const key = tag.module !== this.module.name
|
|
102
|
+
? tag.short
|
|
103
|
+
: tag.name;
|
|
104
|
+
const schema = this.module.schema.constants.enums[key];
|
|
86
105
|
if (!schema) {
|
|
87
|
-
throw error_1.NesoiError.Module.EnumNotFound(this.module,
|
|
106
|
+
throw error_1.NesoiError.Module.EnumNotFound(this.module, key);
|
|
88
107
|
}
|
|
89
|
-
return new constants_1.Enum(this.module.schema.constants.enums[
|
|
108
|
+
return new constants_1.Enum(this.module.schema.constants.enums[key]);
|
|
90
109
|
}
|
|
91
110
|
// Blocks
|
|
92
111
|
bucket(name) {
|
|
93
|
-
|
|
112
|
+
const tag = dependency_1.Tag.fromNameOrShort(this.module.name, 'bucket', name);
|
|
113
|
+
return new bucket_trx_node_1.BucketTrxNode(this, tag);
|
|
94
114
|
}
|
|
95
115
|
job(name) {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
throw error_1.NesoiError.Module.JobNotIncluded(this.module, name);
|
|
99
|
-
}
|
|
100
|
-
return new job_trx_node_1.JobTrxNode(this, job);
|
|
116
|
+
const tag = dependency_1.Tag.fromNameOrShort(this.module.name, 'job', name);
|
|
117
|
+
return new job_trx_node_1.JobTrxNode(this, tag);
|
|
101
118
|
}
|
|
102
119
|
// Method for internal use, which allows running a job with a custom context.
|
|
103
120
|
// This is used by composite blocks to pass things such as an object
|
|
104
121
|
// or the previous/next machine states along with the message.
|
|
105
122
|
static jobWithCustomCtx(node, name, ctx) {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
throw error_1.NesoiError.Module.JobNotIncluded(node.module, name);
|
|
109
|
-
}
|
|
110
|
-
return new job_trx_node_1.JobTrxNode(node, job, ctx);
|
|
123
|
+
const tag = dependency_1.Tag.fromNameOrShort(node.module.name, 'job', name);
|
|
124
|
+
return new job_trx_node_1.JobTrxNode(node, tag, ctx);
|
|
111
125
|
}
|
|
112
126
|
resource(name) {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
throw error_1.NesoiError.Module.ResourceNotIncluded(this.module, name);
|
|
116
|
-
}
|
|
117
|
-
return new resource_trx_node_1.ResourceTrxNode(this, resource);
|
|
127
|
+
const tag = dependency_1.Tag.fromNameOrShort(this.module.name, 'resource', name);
|
|
128
|
+
return new resource_trx_node_1.ResourceTrxNode(this, tag);
|
|
118
129
|
}
|
|
119
130
|
machine(name) {
|
|
131
|
+
// TODO: support external
|
|
120
132
|
const machine = this.module.machines[name];
|
|
121
133
|
if (!machine) {
|
|
122
134
|
throw error_1.NesoiError.Module.MachineNotIncluded(this.module, name);
|
|
@@ -124,6 +136,7 @@ class TrxNode {
|
|
|
124
136
|
return new machine_trx_node_1.MachineTrxNode(this, machine);
|
|
125
137
|
}
|
|
126
138
|
queue(name) {
|
|
139
|
+
// TODO: support external
|
|
127
140
|
const queue = this.module.queues[name];
|
|
128
141
|
if (!queue) {
|
|
129
142
|
throw error_1.NesoiError.Module.QueueNotIncluded(this.module, name);
|
|
@@ -131,6 +144,7 @@ class TrxNode {
|
|
|
131
144
|
return new queue_trx_node_1.QueueTrxNode(this, queue);
|
|
132
145
|
}
|
|
133
146
|
topic(name) {
|
|
147
|
+
// TODO: support external
|
|
134
148
|
const topic = this.module.topics[name];
|
|
135
149
|
if (!topic) {
|
|
136
150
|
throw error_1.NesoiError.Module.TopicNotIncluded(this.module, name);
|
|
@@ -139,21 +153,16 @@ class TrxNode {
|
|
|
139
153
|
}
|
|
140
154
|
// Authentication
|
|
141
155
|
async authenticate(authnRequest) {
|
|
142
|
-
const newNode = new TrxNode(this.scope, this.trx, this, this.module, this.
|
|
156
|
+
const newNode = new TrxNode(this.scope, this.trx, this, this.module, this.auth);
|
|
143
157
|
await this.trx.engine.authenticate(newNode, authnRequest);
|
|
144
158
|
return newNode;
|
|
145
159
|
}
|
|
146
|
-
token(provider) {
|
|
147
|
-
|
|
148
|
-
throw error_1.NesoiError.Authn.NoUsersAuthenticatedForTrxNode(this.globalId);
|
|
149
|
-
}
|
|
150
|
-
return this.authn?.tokens[provider];
|
|
160
|
+
async token(provider) {
|
|
161
|
+
return this.auth?.tokens[provider];
|
|
151
162
|
}
|
|
152
|
-
user(provider) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
return this.authn?.users[provider];
|
|
163
|
+
async user(provider) {
|
|
164
|
+
await TrxNode.checkAuth(this, [{ provider: provider }]);
|
|
165
|
+
return this.auth?.users[provider];
|
|
157
166
|
}
|
|
158
167
|
// Virtual Module Transaction
|
|
159
168
|
async virtual(def, fn) {
|
|
@@ -164,14 +173,14 @@ class TrxNode {
|
|
|
164
173
|
const virtualModule = await module_1.Module.virtual(this.module.daemon, def);
|
|
165
174
|
// Create trx node of virtual module
|
|
166
175
|
const node = TrxNode.makeVirtualChildNode(this, virtualModule);
|
|
167
|
-
|
|
176
|
+
TrxNode.open(node, 'run', {});
|
|
168
177
|
try {
|
|
169
178
|
const result = await fn(node);
|
|
170
|
-
|
|
179
|
+
TrxNode.ok(node);
|
|
171
180
|
return result;
|
|
172
181
|
}
|
|
173
182
|
catch (e) {
|
|
174
|
-
|
|
183
|
+
TrxNode.error(node, e);
|
|
175
184
|
throw e;
|
|
176
185
|
}
|
|
177
186
|
}
|
|
@@ -190,28 +199,34 @@ class TrxNode {
|
|
|
190
199
|
};
|
|
191
200
|
}
|
|
192
201
|
//
|
|
202
|
+
static merge(to, from) {
|
|
203
|
+
for (const child of from.children) {
|
|
204
|
+
to.children.push(child);
|
|
205
|
+
to.trx.addNode(child);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
193
208
|
static makeChildNode(node, module, block, name) {
|
|
194
|
-
const child = new TrxNode(`${module}::${block}:${name}`, node.trx, node, node.module, node.
|
|
209
|
+
const child = new TrxNode(`${module}::${block}:${name}`, node.trx, node, node.module, node.auth);
|
|
195
210
|
node.children.push(child);
|
|
196
211
|
node.trx.addNode(child);
|
|
197
212
|
return child;
|
|
198
213
|
}
|
|
199
214
|
static makeVirtualChildNode(node, module) {
|
|
200
|
-
const child = new TrxNode(`${module.name}::virtual`, node.trx, node, module, node.
|
|
215
|
+
const child = new TrxNode(`${module.name}::virtual`, node.trx, node, module, node.auth);
|
|
201
216
|
node.children.push(child);
|
|
202
217
|
node.trx.addNode(child);
|
|
203
218
|
return child;
|
|
204
219
|
}
|
|
205
220
|
static addAuthn(node, tokens, users) {
|
|
206
221
|
var _a, _b;
|
|
207
|
-
node.
|
|
222
|
+
node.auth ?? (node.auth = {
|
|
208
223
|
tokens: {},
|
|
209
224
|
users: {}
|
|
210
225
|
});
|
|
211
|
-
(_a = node.
|
|
212
|
-
(_b = node.
|
|
213
|
-
Object.assign(node.
|
|
214
|
-
Object.assign(node.
|
|
226
|
+
(_a = node.auth).tokens ?? (_a.tokens = {});
|
|
227
|
+
(_b = node.auth).users ?? (_b.users = {});
|
|
228
|
+
Object.assign(node.auth.tokens, tokens);
|
|
229
|
+
Object.assign(node.auth.users, users);
|
|
215
230
|
}
|
|
216
231
|
static getModule(node) {
|
|
217
232
|
return node.module;
|
|
@@ -220,24 +235,51 @@ class TrxNode {
|
|
|
220
235
|
if (!authnProviders)
|
|
221
236
|
return undefined;
|
|
222
237
|
for (const provider in authnProviders) {
|
|
223
|
-
const user = node.
|
|
238
|
+
const user = node.auth?.users[provider];
|
|
224
239
|
if (user) {
|
|
225
240
|
return { provider, user };
|
|
226
241
|
}
|
|
227
242
|
}
|
|
228
243
|
return undefined;
|
|
229
244
|
}
|
|
230
|
-
static
|
|
231
|
-
if (!
|
|
245
|
+
static async checkAuth(node, options) {
|
|
246
|
+
if (!options?.length)
|
|
232
247
|
return;
|
|
233
|
-
if (node.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
248
|
+
if (!node.auth?.users) {
|
|
249
|
+
throw error_1.NesoiError.Trx.Unauthorized({ providers: options.map(opt => opt.provider) });
|
|
250
|
+
}
|
|
251
|
+
for (const opt of options) {
|
|
252
|
+
// Eager provider or previously authenticated user
|
|
253
|
+
if (opt.provider in node.auth.users) {
|
|
254
|
+
const user = node.auth.users[opt.provider];
|
|
255
|
+
if (opt.resolver && !opt.resolver(user)) {
|
|
256
|
+
log_1.Log.debug('trx', node.globalId, `User from provider '${opt.provider}' didn't pass the authorization resolver`);
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
log_1.Log.debug('trx', node.globalId, `User from provider '${opt.provider}' pre-authenticated${opt.resolver ? ' and authorized' : ''}`);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// Non-eager providers
|
|
263
|
+
else if (opt.provider in node.auth.tokens) {
|
|
264
|
+
try {
|
|
265
|
+
await node.trx.engine.authenticate(node, {
|
|
266
|
+
[opt.provider]: node.auth.tokens[opt.provider]
|
|
267
|
+
}, true);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
log_1.Log.debug('trx', node.globalId, `Attempt to authenticate with provider '${opt.provider}' failed`);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const user = node.auth.users[opt.provider];
|
|
274
|
+
if (opt.resolver && !opt.resolver(user)) {
|
|
275
|
+
log_1.Log.debug('trx', node.globalId, `User from provider '${opt.provider}' didn't pass the authorization resolver`);
|
|
276
|
+
continue;
|
|
237
277
|
}
|
|
278
|
+
log_1.Log.debug('trx', node.globalId, `User from provider '${opt.provider}' authenticated${opt.resolver ? ' and authorized' : ''}`);
|
|
279
|
+
return;
|
|
238
280
|
}
|
|
239
281
|
}
|
|
240
|
-
throw error_1.NesoiError.Trx.
|
|
282
|
+
throw error_1.NesoiError.Trx.Unauthorized({ providers: options.map(opt => opt.provider) });
|
|
241
283
|
}
|
|
242
284
|
}
|
|
243
285
|
exports.TrxNode = TrxNode;
|
package/lib/engine/tree.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { BuilderType } from "../schema";
|
|
2
1
|
import { ResolvedBuilderNode } from './dependency';
|
|
3
2
|
import { AnyModule } from './module';
|
|
4
|
-
import { TreeshakeConfig } from
|
|
5
|
-
import { ProgressiveBuildCache } from "../compiler/progressive";
|
|
3
|
+
import { TreeshakeConfig } from './treeshake';
|
|
6
4
|
type TraverseCallback = (node: ResolvedBuilderNode) => Promise<void>;
|
|
5
|
+
import { ProgressiveBuildCache } from "../compiler/progressive";
|
|
7
6
|
/**
|
|
8
7
|
* A tree of module elements which allows building in the correct order.
|
|
9
8
|
*
|
|
@@ -33,11 +32,11 @@ export declare class ModuleTree {
|
|
|
33
32
|
*/
|
|
34
33
|
private treeshake;
|
|
35
34
|
/**
|
|
36
|
-
* Each element declares it's dependencies as a
|
|
35
|
+
* Each element declares it's dependencies as a list of `Dependency`.
|
|
37
36
|
* In order to assemble the build layers, it's necessary to
|
|
38
37
|
* resolve them into a graph of `ResolvedBuilderNode`s.
|
|
39
38
|
* This also resolves the inline nodes, to allow merging the schemas
|
|
40
|
-
* of inline nodes on
|
|
39
|
+
* of inline nodes on compile.
|
|
41
40
|
*
|
|
42
41
|
* @param nodesByModule A dictionary of builder nodes by module name
|
|
43
42
|
* @returns A dictionary of resolved builder nodes
|
|
@@ -66,17 +65,6 @@ export declare class ModuleTree {
|
|
|
66
65
|
* @param fn Callback to be run for each node
|
|
67
66
|
*/
|
|
68
67
|
traverse(actionAlias: string, fn: TraverseCallback): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Get schema of a dependency-like object.
|
|
71
|
-
*
|
|
72
|
-
* @param node A dependency-like object
|
|
73
|
-
* @return An element schema
|
|
74
|
-
*/
|
|
75
|
-
getSchema(node: {
|
|
76
|
-
module: string;
|
|
77
|
-
type: BuilderType;
|
|
78
|
-
name: string;
|
|
79
|
-
}): import("../elements").$Message | import("../elements").$Machine | import("../elements").$Bucket | import("../elements").$Constants | import("../elements").$Job | import("../elements").$Externals | import("../elements").$Resource | import("../elements").$Controller;
|
|
80
68
|
/**
|
|
81
69
|
* Return a list of all nodes of all modules on the tree.
|
|
82
70
|
*
|