nesoi 3.2.8 → 3.3.0
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 +13 -10
- 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 +24 -22
- 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 +102 -30
- 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
|
@@ -2,47 +2,67 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JobTrxNode = void 0;
|
|
4
4
|
const trx_node_1 = require("../trx_node");
|
|
5
|
+
const dependency_1 = require("../../dependency");
|
|
6
|
+
const error_1 = require("../../data/error");
|
|
7
|
+
const external_trx_node_1 = require("./external.trx_node");
|
|
5
8
|
/**
|
|
6
9
|
* @category Engine
|
|
7
10
|
* @subcategory Transaction
|
|
8
11
|
*/
|
|
9
12
|
class JobTrxNode {
|
|
10
|
-
constructor(trx,
|
|
13
|
+
constructor(trx, tag, ctx) {
|
|
11
14
|
this.trx = trx;
|
|
12
|
-
this.
|
|
15
|
+
this.tag = tag;
|
|
13
16
|
this.ctx = ctx;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
&& this.job.schema.input.some(dep => dep.tag === `${this.job.module.name}::message:${this.job.schema.name}`)) {
|
|
22
|
-
message['$'] = this.job.schema.name;
|
|
17
|
+
const module = trx_node_1.TrxNode.getModule(trx);
|
|
18
|
+
this.external = tag.module !== module.name;
|
|
19
|
+
if (!this.external) {
|
|
20
|
+
this.job = dependency_1.Tag.element(tag, trx);
|
|
21
|
+
if (!this.job) {
|
|
22
|
+
throw error_1.NesoiError.Trx.NodeNotFound(this.tag.full, trx.globalId);
|
|
23
|
+
}
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
}
|
|
26
|
+
/*
|
|
27
|
+
Wrap
|
|
28
|
+
*/
|
|
29
|
+
async wrap(action, input, fn, fmtTrxOut) {
|
|
30
|
+
const wrapped = async (parentTrx, job) => {
|
|
31
|
+
const trx = trx_node_1.TrxNode.makeChildNode(parentTrx, job.schema.module, 'job', job.schema.name);
|
|
32
|
+
trx_node_1.TrxNode.open(trx, action, input);
|
|
33
|
+
let out;
|
|
34
|
+
try {
|
|
35
|
+
out = await fn(trx, job);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
39
|
+
}
|
|
40
|
+
trx_node_1.TrxNode.ok(trx, fmtTrxOut ? fmtTrxOut(out) : out);
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
if (this.external) {
|
|
44
|
+
const ext = new external_trx_node_1.ExternalTrxNode(this.trx, this.tag);
|
|
45
|
+
return ext.run(trx => dependency_1.Tag.element(this.tag, trx), wrapped);
|
|
27
46
|
}
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
else {
|
|
48
|
+
return wrapped(this.trx, this.job);
|
|
30
49
|
}
|
|
31
|
-
|
|
32
|
-
|
|
50
|
+
}
|
|
51
|
+
async run(message) {
|
|
52
|
+
return this.wrap('run', message, (trx, job) => {
|
|
53
|
+
// Special case for Jobs with a '' inline message,
|
|
54
|
+
// which is not required on the run method.
|
|
55
|
+
if (!('$' in message)
|
|
56
|
+
&& job.schema.input.some(tag => tag.full === `${job.module.name}::message:${job.schema.name}`)) {
|
|
57
|
+
message['$'] = job.schema.name;
|
|
58
|
+
}
|
|
59
|
+
return job.consumeRaw(trx, message, this.ctx);
|
|
60
|
+
});
|
|
33
61
|
}
|
|
34
62
|
async forward(message) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
response = await this.job.consume(trx, message, this.ctx);
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
throw await trx_node_1.TrxNode.error(trx, e);
|
|
43
|
-
}
|
|
44
|
-
await trx_node_1.TrxNode.ok(trx, response);
|
|
45
|
-
return response;
|
|
63
|
+
return this.wrap('forward', message, (trx, job) => {
|
|
64
|
+
return job.consume(trx, message);
|
|
65
|
+
});
|
|
46
66
|
}
|
|
47
67
|
}
|
|
48
68
|
exports.JobTrxNode = JobTrxNode;
|
|
@@ -13,28 +13,28 @@ class MachineTrxNode {
|
|
|
13
13
|
}
|
|
14
14
|
async run(message) {
|
|
15
15
|
const trx = trx_node_1.TrxNode.makeChildNode(this.trx, this.machine.schema.module, 'machine', this.machine.schema.name);
|
|
16
|
-
|
|
16
|
+
trx_node_1.TrxNode.open(trx, 'run', message);
|
|
17
17
|
let response;
|
|
18
18
|
try {
|
|
19
19
|
response = await this.machine.consumeRaw(trx, message);
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
|
-
throw
|
|
22
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
trx_node_1.TrxNode.ok(trx, response);
|
|
25
25
|
return response;
|
|
26
26
|
}
|
|
27
27
|
async forward(message) {
|
|
28
28
|
const trx = trx_node_1.TrxNode.makeChildNode(this.trx, this.machine.schema.module, 'machine', this.machine.schema.name);
|
|
29
|
-
|
|
29
|
+
trx_node_1.TrxNode.open(trx, 'forward', message);
|
|
30
30
|
let response;
|
|
31
31
|
try {
|
|
32
32
|
response = await this.machine.consume(trx, message);
|
|
33
33
|
}
|
|
34
34
|
catch (e) {
|
|
35
|
-
throw
|
|
35
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
trx_node_1.TrxNode.ok(trx, response);
|
|
38
38
|
return response;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -13,15 +13,15 @@ class QueueTrxNode {
|
|
|
13
13
|
}
|
|
14
14
|
async push(raw) {
|
|
15
15
|
const trx = trx_node_1.TrxNode.makeChildNode(this.trx, this.queue.schema.module, 'queue', this.queue.schema.name);
|
|
16
|
-
|
|
16
|
+
trx_node_1.TrxNode.open(trx, 'push', { raw });
|
|
17
17
|
let response;
|
|
18
18
|
try {
|
|
19
19
|
// response = this.queue.push(trx, raw);
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
|
-
throw
|
|
22
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
trx_node_1.TrxNode.ok(trx, response);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.QueueTrxNode = QueueTrxNode;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { $Module } from "../../../schema";
|
|
2
|
-
import { TrxNode } from '../trx_node';
|
|
2
|
+
import { AnyTrxNode, TrxNode } from '../trx_node';
|
|
3
3
|
import { Message } from "../../../elements/entities/message/message";
|
|
4
4
|
import { $Resource } from "../../../elements/blocks/resource/resource.schema";
|
|
5
5
|
import { Resource } from "../../../elements/blocks/resource/resource";
|
|
6
|
+
import { Tag } from "../../dependency";
|
|
6
7
|
type ViewRaw<$ extends $Resource> = $['#input.view']['#raw'];
|
|
7
8
|
type QueryRaw<$ extends $Resource> = $['#input.query']['#raw'];
|
|
8
9
|
type CreateRaw<$ extends $Resource> = $['#input.create']['#raw'];
|
|
@@ -14,8 +15,11 @@ type DeleteRaw<$ extends $Resource> = $['#input.delete']['#raw'];
|
|
|
14
15
|
*/
|
|
15
16
|
export declare class ResourceTrxNode<M extends $Module, $ extends $Resource> {
|
|
16
17
|
private trx;
|
|
17
|
-
private
|
|
18
|
-
|
|
18
|
+
private tag;
|
|
19
|
+
private external;
|
|
20
|
+
private resource?;
|
|
21
|
+
constructor(trx: TrxNode<any, M, any>, tag: Tag);
|
|
22
|
+
wrap(action: string, input: Record<string, any>, fn: (trx: AnyTrxNode, element: Resource<any, M, $>) => Promise<any>, fmtTrxOut?: (out: any) => any): Promise<any>;
|
|
19
23
|
forward(message: Message<$['#input']>): Promise<$['#output']>;
|
|
20
24
|
run(raw: ViewRaw<$> | QueryRaw<$> | CreateRaw<$> | UpdateRaw<$> | DeleteRaw<$>): Promise<$['#output']>;
|
|
21
25
|
view<View extends keyof $['#bucket']['views'], Raw extends Omit<ViewRaw<$>, '$'>>(raw: Raw): Promise<$['#bucket']['views'][View]['#data']>;
|
|
@@ -23,6 +27,5 @@ export declare class ResourceTrxNode<M extends $Module, $ extends $Resource> {
|
|
|
23
27
|
create(raw: Omit<CreateRaw<$>, '$'>): Promise<$['#bucket']['#data']>;
|
|
24
28
|
update(raw: Omit<UpdateRaw<$>, '$'>): Promise<$['#bucket']['#data']>;
|
|
25
29
|
delete(raw: Omit<DeleteRaw<$>, '$'>): Promise<void>;
|
|
26
|
-
private consumeRaw;
|
|
27
30
|
}
|
|
28
31
|
export {};
|
|
@@ -2,78 +2,95 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ResourceTrxNode = void 0;
|
|
4
4
|
const trx_node_1 = require("../trx_node");
|
|
5
|
+
const dependency_1 = require("../../dependency");
|
|
6
|
+
const error_1 = require("../../data/error");
|
|
7
|
+
const external_trx_node_1 = require("./external.trx_node");
|
|
5
8
|
/**
|
|
6
9
|
* @category Engine
|
|
7
10
|
* @subcategory Transaction
|
|
8
11
|
*/
|
|
9
12
|
class ResourceTrxNode {
|
|
10
|
-
constructor(trx,
|
|
13
|
+
constructor(trx, tag) {
|
|
11
14
|
this.trx = trx;
|
|
12
|
-
this.
|
|
15
|
+
this.tag = tag;
|
|
16
|
+
const module = trx_node_1.TrxNode.getModule(trx);
|
|
17
|
+
this.external = tag.module !== module.name;
|
|
18
|
+
if (!this.external) {
|
|
19
|
+
this.resource = dependency_1.Tag.element(tag, trx);
|
|
20
|
+
if (!this.resource) {
|
|
21
|
+
throw error_1.NesoiError.Trx.NodeNotFound(this.tag.full, trx.globalId);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
13
24
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
/*
|
|
26
|
+
Wrap
|
|
27
|
+
*/
|
|
28
|
+
async wrap(action, input, fn, fmtTrxOut) {
|
|
29
|
+
const wrapped = async (parentTrx, resource) => {
|
|
30
|
+
const trx = trx_node_1.TrxNode.makeChildNode(parentTrx, resource.schema.module, 'resource', resource.schema.name);
|
|
31
|
+
trx_node_1.TrxNode.open(trx, action, input);
|
|
32
|
+
let out;
|
|
33
|
+
try {
|
|
34
|
+
out = await fn(trx, resource);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
38
|
+
}
|
|
39
|
+
trx_node_1.TrxNode.ok(trx, fmtTrxOut ? fmtTrxOut(out) : out);
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
42
|
+
if (this.external) {
|
|
43
|
+
const ext = new external_trx_node_1.ExternalTrxNode(this.trx, this.tag);
|
|
44
|
+
return ext.run(trx => dependency_1.Tag.element(this.tag, trx), wrapped);
|
|
20
45
|
}
|
|
21
|
-
|
|
22
|
-
|
|
46
|
+
else {
|
|
47
|
+
return wrapped(this.trx, this.resource);
|
|
23
48
|
}
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
}
|
|
50
|
+
async forward(message) {
|
|
51
|
+
return this.wrap('forward', message, (trx, resource) => {
|
|
52
|
+
return resource.consume(trx, message);
|
|
53
|
+
});
|
|
26
54
|
}
|
|
27
55
|
async run(raw) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
56
|
+
return this.wrap('run', raw, (trx, resource) => {
|
|
57
|
+
return resource.consumeRaw(trx, raw);
|
|
58
|
+
});
|
|
31
59
|
}
|
|
32
60
|
async view(raw) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
61
|
+
return this.wrap('view', raw, (trx, resource) => {
|
|
62
|
+
const inRaw = Object.assign({}, raw);
|
|
63
|
+
inRaw.$ = `${resource.schema.name}.view`;
|
|
64
|
+
return resource.consumeRaw(trx, inRaw);
|
|
65
|
+
});
|
|
38
66
|
}
|
|
39
67
|
async query(raw) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
return this.wrap('query', raw, (trx, resource) => {
|
|
69
|
+
const inRaw = Object.assign({}, raw);
|
|
70
|
+
inRaw.$ = `${resource.schema.name}.query`;
|
|
71
|
+
return resource.consumeRaw(trx, inRaw);
|
|
72
|
+
});
|
|
45
73
|
}
|
|
46
74
|
async create(raw) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
75
|
+
return this.wrap('create', raw, (trx, resource) => {
|
|
76
|
+
const inRaw = Object.assign({}, raw);
|
|
77
|
+
inRaw.$ = `${resource.schema.name}.create`;
|
|
78
|
+
return resource.consumeRaw(trx, inRaw);
|
|
79
|
+
});
|
|
52
80
|
}
|
|
53
81
|
async update(raw) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
return this.wrap('update', raw, (trx, resource) => {
|
|
83
|
+
const inRaw = Object.assign({}, raw);
|
|
84
|
+
inRaw.$ = `${resource.schema.name}.update`;
|
|
85
|
+
return resource.consumeRaw(trx, inRaw);
|
|
86
|
+
});
|
|
59
87
|
}
|
|
60
88
|
async delete(raw) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
async consumeRaw(trx, message) {
|
|
68
|
-
let response;
|
|
69
|
-
try {
|
|
70
|
-
response = await this.resource.consumeRaw(trx, message);
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
throw await trx_node_1.TrxNode.error(trx, e);
|
|
74
|
-
}
|
|
75
|
-
await trx_node_1.TrxNode.ok(trx, response);
|
|
76
|
-
return response;
|
|
89
|
+
return this.wrap('delete', raw, (trx, resource) => {
|
|
90
|
+
const inRaw = Object.assign({}, raw);
|
|
91
|
+
inRaw.$ = `${resource.schema.name}.delete`;
|
|
92
|
+
return resource.consumeRaw(trx, inRaw);
|
|
93
|
+
});
|
|
77
94
|
}
|
|
78
95
|
}
|
|
79
96
|
exports.ResourceTrxNode = ResourceTrxNode;
|
|
@@ -13,38 +13,38 @@ class TopicTrxNode {
|
|
|
13
13
|
}
|
|
14
14
|
async subscribe(fn) {
|
|
15
15
|
const trx = trx_node_1.TrxNode.makeChildNode(this.trx, this.topic.schema.module, 'topic', this.topic.schema.name);
|
|
16
|
-
|
|
16
|
+
trx_node_1.TrxNode.open(trx, 'subscribe', {});
|
|
17
17
|
let id;
|
|
18
18
|
try {
|
|
19
19
|
id = await this.topic.subscribe(this.trx, fn);
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
|
-
throw
|
|
22
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
trx_node_1.TrxNode.ok(trx, { id });
|
|
25
25
|
return id;
|
|
26
26
|
}
|
|
27
27
|
async unsubscribe(id) {
|
|
28
28
|
const trx = trx_node_1.TrxNode.makeChildNode(this.trx, this.topic.schema.module, 'topic', this.topic.schema.name);
|
|
29
|
-
|
|
29
|
+
trx_node_1.TrxNode.open(trx, 'unsubscribe', {});
|
|
30
30
|
try {
|
|
31
31
|
await this.topic.unsubscribe(this.trx, id);
|
|
32
32
|
}
|
|
33
33
|
catch (e) {
|
|
34
|
-
throw
|
|
34
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
trx_node_1.TrxNode.ok(trx, undefined);
|
|
37
37
|
}
|
|
38
38
|
async publish(raw) {
|
|
39
39
|
const trx = trx_node_1.TrxNode.makeChildNode(this.trx, this.topic.schema.module, 'topic', this.topic.schema.name);
|
|
40
|
-
|
|
40
|
+
trx_node_1.TrxNode.open(trx, 'publish', { raw });
|
|
41
41
|
try {
|
|
42
42
|
await this.topic.consumeRaw(trx, raw);
|
|
43
43
|
}
|
|
44
44
|
catch (e) {
|
|
45
|
-
throw
|
|
45
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
trx_node_1.TrxNode.ok(trx, undefined);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
exports.TopicTrxNode = TopicTrxNode;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { $Module, $Space } from "../../schema";
|
|
2
2
|
import { Module } from '../module';
|
|
3
3
|
import { AnyTrxNode, TrxNode, TrxNodeStatus } from './trx_node';
|
|
4
|
-
import { AnyTrxEngine, TrxEngineOrigin } from './trx_engine';
|
|
5
|
-
import { AnyUsers,
|
|
4
|
+
import { AnyTrxEngine, HeldTrxNode as TrxNodeHold, TrxEngineOrigin } from './trx_engine';
|
|
5
|
+
import { AnyUsers, AuthRequest } from '../auth/authn';
|
|
6
6
|
import { NesoiDatetime } from '../data/datetime';
|
|
7
7
|
import { NesoiError } from '../data/error';
|
|
8
8
|
type TrxOrigin = TrxEngineOrigin | `trx:${string}`;
|
|
9
|
-
type TrxState = 'open' | 'ok' | 'error';
|
|
9
|
+
type TrxState = 'open' | 'hold' | 'ok' | 'error';
|
|
10
10
|
/**
|
|
11
11
|
* @category Engine
|
|
12
12
|
* @subcategory Transaction
|
|
@@ -27,21 +27,23 @@ export declare class TrxStatus<Output> {
|
|
|
27
27
|
* @category Engine
|
|
28
28
|
* @subcategory Transaction
|
|
29
29
|
*/
|
|
30
|
-
export declare class Trx<S extends $Space, M extends $Module,
|
|
30
|
+
export declare class Trx<S extends $Space, M extends $Module, AuthUsers extends AnyUsers> {
|
|
31
31
|
engine: AnyTrxEngine;
|
|
32
32
|
private module;
|
|
33
33
|
id: string;
|
|
34
34
|
private origin;
|
|
35
|
-
root: TrxNode<S, M,
|
|
36
|
-
nodes: Record<string, TrxNode<S, M,
|
|
35
|
+
root: TrxNode<S, M, AuthUsers>;
|
|
36
|
+
nodes: Record<string, TrxNode<S, M, AuthUsers>>;
|
|
37
|
+
holds: Record<string, TrxNodeHold<any>>;
|
|
37
38
|
start: NesoiDatetime;
|
|
38
39
|
end?: NesoiDatetime;
|
|
39
40
|
ctx: Record<string, any>;
|
|
40
|
-
constructor(engine: AnyTrxEngine, module: Module<S, M>, origin: TrxOrigin,
|
|
41
|
-
tokens:
|
|
42
|
-
users:
|
|
43
|
-
}, id?: string, root?: TrxNode<S, M,
|
|
44
|
-
addNode(node: TrxNode<S, M,
|
|
41
|
+
constructor(engine: AnyTrxEngine, module: Module<S, M>, origin: TrxOrigin, auth?: {
|
|
42
|
+
tokens: AuthRequest<any>;
|
|
43
|
+
users: AuthUsers;
|
|
44
|
+
}, id?: string, root?: TrxNode<S, M, AuthUsers>, nodes?: Record<string, TrxNode<S, M, AuthUsers>>);
|
|
45
|
+
addNode(node: TrxNode<S, M, AuthUsers>): void;
|
|
46
|
+
holdNode(node: TrxNodeHold<any>): void;
|
|
45
47
|
status(): TrxStatus<any>;
|
|
46
48
|
/**
|
|
47
49
|
* Context Manipulation
|
|
@@ -57,7 +59,8 @@ export declare class Trx<S extends $Space, M extends $Module, Authn extends AnyU
|
|
|
57
59
|
* to the transaction. Elements should not modify the transaction.
|
|
58
60
|
*/
|
|
59
61
|
static set(node: AnyTrxNode, key: string, value: any): AnyTrx;
|
|
60
|
-
static
|
|
62
|
+
static onCommit(trx: AnyTrx): Promise<void>;
|
|
63
|
+
static onRollback(trx: AnyTrx): Promise<void>;
|
|
61
64
|
}
|
|
62
65
|
export type AnyTrx = Trx<any, any, any>;
|
|
63
66
|
export {};
|
|
@@ -26,6 +26,7 @@ class TrxStatus {
|
|
|
26
26
|
summary() {
|
|
27
27
|
const state = this.state ? (0, string_1.colored)(`[${this.state}]`, {
|
|
28
28
|
'open': 'lightblue',
|
|
29
|
+
'hold': 'yellow',
|
|
29
30
|
'ok': 'lightgreen',
|
|
30
31
|
'error': 'lightred'
|
|
31
32
|
}[this.state]) : 'unknown';
|
|
@@ -36,6 +37,7 @@ class TrxStatus {
|
|
|
36
37
|
nodes.forEach(node => {
|
|
37
38
|
const state = node.state ? (0, string_1.colored)(`[${node.state}]`, {
|
|
38
39
|
'open': 'lightblue',
|
|
40
|
+
'hold': 'yellow',
|
|
39
41
|
'ok': 'lightgreen',
|
|
40
42
|
'error': 'lightred'
|
|
41
43
|
}[node.state] || 'lightred') : 'unknown';
|
|
@@ -54,20 +56,25 @@ exports.TrxStatus = TrxStatus;
|
|
|
54
56
|
* @subcategory Transaction
|
|
55
57
|
*/
|
|
56
58
|
class Trx {
|
|
57
|
-
constructor(engine, module, origin,
|
|
59
|
+
constructor(engine, module, origin, auth, id, root, nodes) {
|
|
58
60
|
this.engine = engine;
|
|
61
|
+
this.holds = {};
|
|
59
62
|
this.start = datetime_1.NesoiDatetime.now();
|
|
60
63
|
this.ctx = {};
|
|
61
64
|
this.module = module;
|
|
62
65
|
this.id = id || (Math.random() + 1).toString(36).substring(7);
|
|
63
66
|
this.origin = origin;
|
|
64
|
-
this.root = root || new trx_node_1.TrxNode('root', this, undefined, module,
|
|
67
|
+
this.root = root || new trx_node_1.TrxNode('root', this, undefined, module, auth, false, id);
|
|
65
68
|
this.nodes = nodes || {};
|
|
66
69
|
}
|
|
67
70
|
addNode(node) {
|
|
68
71
|
const nodeId = node.id;
|
|
69
72
|
this.nodes[nodeId] = node;
|
|
70
73
|
}
|
|
74
|
+
holdNode(node) {
|
|
75
|
+
const nodeId = node.id;
|
|
76
|
+
this.holds[nodeId] = node;
|
|
77
|
+
}
|
|
71
78
|
status() {
|
|
72
79
|
const state = this.root.state;
|
|
73
80
|
const output = this.root.output;
|
|
@@ -96,8 +103,17 @@ class Trx {
|
|
|
96
103
|
return trx;
|
|
97
104
|
}
|
|
98
105
|
//
|
|
99
|
-
static
|
|
106
|
+
static async onCommit(trx) {
|
|
107
|
+
for (const h in trx.holds) {
|
|
108
|
+
await trx.holds[h].commit();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
static async onRollback(trx) {
|
|
100
112
|
trx.end = datetime_1.NesoiDatetime.now();
|
|
113
|
+
for (const h in trx.holds) {
|
|
114
|
+
const error = `rollback ${trx.id}`;
|
|
115
|
+
await trx.holds[h].rollback(error);
|
|
116
|
+
}
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
exports.Trx = Trx;
|
|
@@ -2,13 +2,13 @@ import { $Module, $Space } from "../../elements";
|
|
|
2
2
|
import { BucketAdapter } from "../../elements/entities/bucket/adapters/bucket_adapter";
|
|
3
3
|
import { Trx } from './trx';
|
|
4
4
|
import { AnyUsers } from '../auth/authn';
|
|
5
|
-
import { TrxNode
|
|
5
|
+
import { TrxNode } from './trx_node';
|
|
6
6
|
import { TrxData } from './trx_engine';
|
|
7
|
-
export type TrxEngineWrapFn<S extends $Space, M extends $Module> = (trx: TrxNode<S, M, any>) => Promise<
|
|
8
|
-
export type TrxEngineConfig<S extends $Space, M extends $Module,
|
|
7
|
+
export type TrxEngineWrapFn<S extends $Space, M extends $Module> = (trx: TrxNode<S, M, any>) => Promise<any>;
|
|
8
|
+
export type TrxEngineConfig<S extends $Space, M extends $Module, AuthUsers extends AnyUsers, Services extends Record<string, any>> = {
|
|
9
9
|
/**
|
|
10
10
|
* Adapter used to store transactions of this module.
|
|
11
11
|
*/
|
|
12
12
|
adapter?: (schema: M) => BucketAdapter<TrxData>;
|
|
13
|
-
wrap?: <T extends Trx<S, M,
|
|
13
|
+
wrap?: <T extends Trx<S, M, AuthUsers>>(trx: T, fn: TrxEngineWrapFn<S, M>, services: Services) => Promise<any>;
|
|
14
14
|
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { $Module, $Space } from "../../schema";
|
|
2
2
|
import { Module } from '../module';
|
|
3
|
-
import { AnyTrx, Trx } from './trx';
|
|
3
|
+
import { AnyTrx, Trx, TrxStatus } from './trx';
|
|
4
4
|
import { TrxNode, TrxNodeStatus } from './trx_node';
|
|
5
|
-
import { AnyAuthnProviders,
|
|
5
|
+
import { AnyAuthnProviders, AuthRequest } from '../auth/authn';
|
|
6
|
+
import { BucketAdapterConfig } from "../../elements/entities/bucket/adapters/bucket_adapter";
|
|
6
7
|
import { TrxEngineConfig } from './trx_engine.config';
|
|
7
|
-
import { IService } from '../
|
|
8
|
+
import { IService } from '../app/service';
|
|
9
|
+
import { Tag } from '../dependency';
|
|
10
|
+
import { AnyBucket } from "../../elements/entities/bucket/bucket";
|
|
11
|
+
import { DriveAdapter } from "../../elements/entities/drive/drive_adapter";
|
|
8
12
|
export type TrxEngineOrigin = `app:${string}` | `plugin:${string}`;
|
|
9
13
|
export type TrxData = {
|
|
10
14
|
id: AnyTrx['id'];
|
|
@@ -13,11 +17,21 @@ export type TrxData = {
|
|
|
13
17
|
start: AnyTrx['start'];
|
|
14
18
|
end: AnyTrx['end'];
|
|
15
19
|
};
|
|
20
|
+
export type HeldTrxNode<Output> = {
|
|
21
|
+
id: string;
|
|
22
|
+
status: TrxStatus<Output>;
|
|
23
|
+
commit: () => Promise<AnyTrx>;
|
|
24
|
+
rollback: (error: string) => Promise<AnyTrx>;
|
|
25
|
+
};
|
|
26
|
+
export type BucketMetadata = ReturnType<AnyBucket['getQueryMeta']> & {
|
|
27
|
+
tag: Tag;
|
|
28
|
+
meta: BucketAdapterConfig['meta'];
|
|
29
|
+
};
|
|
16
30
|
/**
|
|
17
31
|
* @category Engine
|
|
18
32
|
* @subcategory Transaction
|
|
19
33
|
*/
|
|
20
|
-
export declare class TrxEngine<S extends $Space, M extends $Module,
|
|
34
|
+
export declare class TrxEngine<S extends $Space, M extends $Module, AuthUsers extends AnyAuthnProviders> {
|
|
21
35
|
private origin;
|
|
22
36
|
private module;
|
|
23
37
|
private authnProviders?;
|
|
@@ -29,11 +43,15 @@ export declare class TrxEngine<S extends $Space, M extends $Module, Authn extend
|
|
|
29
43
|
*/
|
|
30
44
|
private innerTrx;
|
|
31
45
|
private adapter;
|
|
32
|
-
constructor(origin: TrxEngineOrigin, module: Module<S, M>, authnProviders?:
|
|
46
|
+
constructor(origin: TrxEngineOrigin, module: Module<S, M>, authnProviders?: AuthUsers | undefined, config?: TrxEngineConfig<S, M, any, any> | undefined, services?: Record<string, IService>);
|
|
33
47
|
getModule(): Module<S, M>;
|
|
34
48
|
get(id?: string): Promise<Trx<S, M, any>>;
|
|
35
|
-
trx(fn: (trx: TrxNode<S, M, any>) => Promise<TrxNodeStatus>,
|
|
36
|
-
|
|
49
|
+
trx(fn: (trx: TrxNode<S, M, any>) => Promise<TrxNodeStatus>, id?: string, auth?: AuthRequest<keyof AuthUsers>): Promise<TrxStatus<any>>;
|
|
50
|
+
trx_hold(fn: (trx: TrxNode<S, M, any>) => Promise<any>, id?: string, authn?: AuthRequest<keyof AuthUsers>): Promise<HeldTrxNode<any>>;
|
|
51
|
+
getBucketMetadata(tag: Tag): BucketMetadata;
|
|
52
|
+
getBucketDrive(tag: Tag): DriveAdapter | undefined;
|
|
53
|
+
authenticate(node: TrxNode<S, M, any>, request?: AuthRequest<keyof AuthUsers>, force?: boolean): Promise<void>;
|
|
54
|
+
private hold;
|
|
37
55
|
private commit;
|
|
38
56
|
private rollback;
|
|
39
57
|
}
|