nesoi 3.0.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/lib/adapters/postgres/src/migrator/database.d.ts +37 -0
- package/lib/adapters/postgres/src/migrator/database.js +88 -0
- package/lib/adapters/postgres/src/migrator/index.d.ts +1 -0
- package/lib/adapters/postgres/src/migrator/index.js +5 -0
- package/lib/adapters/postgres/src/migrator/migration.d.ts +73 -0
- package/lib/adapters/postgres/src/migrator/migration.js +351 -0
- package/lib/adapters/postgres/src/migrator/migrator.d.ts +21 -0
- package/lib/adapters/postgres/src/migrator/migrator.js +73 -0
- package/lib/adapters/postgres/src/migrator/runner.d.ts +61 -0
- package/lib/adapters/postgres/src/migrator/runner.js +202 -0
- package/lib/adapters/postgres/src/postgres.bucket_adapter.d.ts +45 -0
- package/lib/adapters/postgres/src/postgres.bucket_adapter.js +278 -0
- package/lib/adapters/postgres/src/postgres.cli.d.ts +46 -0
- package/lib/adapters/postgres/src/postgres.cli.js +124 -0
- package/lib/adapters/postgres/src/postgres.nql.d.ts +12 -0
- package/lib/adapters/postgres/src/postgres.nql.js +69 -0
- package/lib/adapters/postgres/test/postgres.bucket_adapter.test.d.ts +1 -0
- package/lib/adapters/postgres/test/postgres.bucket_adapter.test.js +173 -0
- package/lib/adapters/postgres/test/postgres.bucket_query.test.d.ts +0 -0
- package/lib/adapters/postgres/test/postgres.bucket_query.test.js +136 -0
- package/lib/compiler/apps/monolyth/monolyth_compiler.d.ts +21 -0
- package/lib/compiler/apps/monolyth/monolyth_compiler.js +95 -0
- package/lib/compiler/apps/monolyth/stages/1_mkdir_stage.d.ts +12 -0
- package/lib/compiler/apps/monolyth/stages/1_mkdir_stage.js +80 -0
- package/lib/compiler/apps/monolyth/stages/2_build_typescript_stage.d.ts +12 -0
- package/lib/compiler/apps/monolyth/stages/2_build_typescript_stage.js +128 -0
- package/lib/compiler/apps/monolyth/stages/3_copy_types_stage.d.ts +12 -0
- package/lib/compiler/apps/monolyth/stages/3_copy_types_stage.js +75 -0
- package/lib/compiler/apps/monolyth/stages/4_dump_modules_stage.d.ts +13 -0
- package/lib/compiler/apps/monolyth/stages/4_dump_modules_stage.js +130 -0
- package/lib/compiler/apps/monolyth/stages/5_dump_cli_stage.d.ts +12 -0
- package/lib/compiler/apps/monolyth/stages/5_dump_cli_stage.js +65 -0
- package/lib/compiler/apps/monolyth/stages/6_dump_package_json_stage.d.ts +12 -0
- package/lib/compiler/apps/monolyth/stages/6_dump_package_json_stage.js +74 -0
- package/lib/compiler/compiler.d.ts +19 -0
- package/lib/compiler/compiler.js +83 -0
- package/lib/compiler/elements/bucket.element.d.ts +23 -0
- package/lib/compiler/elements/bucket.element.js +304 -0
- package/lib/compiler/elements/constants.element.d.ts +9 -0
- package/lib/compiler/elements/constants.element.js +88 -0
- package/lib/compiler/elements/controller.element.d.ts +6 -0
- package/lib/compiler/elements/controller.element.js +22 -0
- package/lib/compiler/elements/element.d.ts +49 -0
- package/lib/compiler/elements/element.js +105 -0
- package/lib/compiler/elements/externals.element.d.ts +19 -0
- package/lib/compiler/elements/externals.element.js +83 -0
- package/lib/compiler/elements/job.element.d.ts +7 -0
- package/lib/compiler/elements/job.element.js +62 -0
- package/lib/compiler/elements/machine.element.d.ts +10 -0
- package/lib/compiler/elements/machine.element.js +98 -0
- package/lib/compiler/elements/message.element.d.ts +9 -0
- package/lib/compiler/elements/message.element.js +175 -0
- package/lib/compiler/elements/queue.element.d.ts +6 -0
- package/lib/compiler/elements/queue.element.js +24 -0
- package/lib/compiler/elements/resource.element.d.ts +7 -0
- package/lib/compiler/elements/resource.element.js +64 -0
- package/lib/compiler/error.d.ts +21 -0
- package/lib/compiler/error.js +57 -0
- package/lib/compiler/helpers/dump_helpers.d.ts +11 -0
- package/lib/compiler/helpers/dump_helpers.js +157 -0
- package/lib/compiler/helpers/name_helpers.d.ts +20 -0
- package/lib/compiler/helpers/name_helpers.js +44 -0
- package/lib/compiler/index.d.ts +2 -0
- package/lib/compiler/index.js +7 -0
- package/lib/compiler/module.d.ts +24 -0
- package/lib/compiler/module.js +122 -0
- package/lib/compiler/stages/1_scan_stage.d.ts +10 -0
- package/lib/compiler/stages/1_scan_stage.js +23 -0
- package/lib/compiler/stages/2_treeshake_stage.d.ts +11 -0
- package/lib/compiler/stages/2_treeshake_stage.js +24 -0
- package/lib/compiler/stages/3_extract_ts_stage.d.ts +10 -0
- package/lib/compiler/stages/3_extract_ts_stage.js +71 -0
- package/lib/compiler/stages/4_build_schemas_stage.d.ts +10 -0
- package/lib/compiler/stages/4_build_schemas_stage.js +25 -0
- package/lib/compiler/stages/5_inject_ts_stage.d.ts +10 -0
- package/lib/compiler/stages/5_inject_ts_stage.js +22 -0
- package/lib/compiler/stages/6_build_elements_stage.d.ts +11 -0
- package/lib/compiler/stages/6_build_elements_stage.js +22 -0
- package/lib/compiler/stages/7_dump_stage.d.ts +14 -0
- package/lib/compiler/stages/7_dump_stage.js +208 -0
- package/lib/compiler/stages/8_diagnose_stage.d.ts +16 -0
- package/lib/compiler/stages/8_diagnose_stage.js +43 -0
- package/lib/compiler/treeshake.d.ts +58 -0
- package/lib/compiler/treeshake.js +424 -0
- package/lib/compiler/typescript/bridge/extract.d.ts +11 -0
- package/lib/compiler/typescript/bridge/extract.js +270 -0
- package/lib/compiler/typescript/bridge/inject.d.ts +10 -0
- package/lib/compiler/typescript/bridge/inject.js +140 -0
- package/lib/compiler/typescript/bridge/organize.d.ts +61 -0
- package/lib/compiler/typescript/bridge/organize.js +258 -0
- package/lib/compiler/typescript/error.d.ts +88 -0
- package/lib/compiler/typescript/error.js +265 -0
- package/lib/compiler/typescript/parser.d.ts +48 -0
- package/lib/compiler/typescript/parser.js +581 -0
- package/lib/compiler/typescript/source.d.ts +12 -0
- package/lib/compiler/typescript/source.js +87 -0
- package/lib/compiler/typescript/transformers/app_inject.transformer.d.ts +2 -0
- package/lib/compiler/typescript/transformers/app_inject.transformer.js +89 -0
- package/lib/compiler/typescript/transformers/replace_import.transformer.d.ts +4 -0
- package/lib/compiler/typescript/transformers/replace_import.transformer.js +102 -0
- package/lib/compiler/typescript/typescript_compiler.d.ts +63 -0
- package/lib/compiler/typescript/typescript_compiler.js +602 -0
- package/lib/elements/blocks/block.builder.d.ts +29 -0
- package/lib/elements/blocks/block.builder.js +87 -0
- package/lib/elements/blocks/block.d.ts +15 -0
- package/lib/elements/blocks/block.js +37 -0
- package/lib/elements/blocks/block.schema.d.ts +23 -0
- package/lib/elements/blocks/block.schema.js +15 -0
- package/lib/elements/blocks/externals/externals.builder.d.ts +30 -0
- package/lib/elements/blocks/externals/externals.builder.js +37 -0
- package/lib/elements/blocks/externals/externals.schema.d.ts +11 -0
- package/lib/elements/blocks/externals/externals.schema.js +19 -0
- package/lib/elements/blocks/job/internal/machine_job.builder.d.ts +52 -0
- package/lib/elements/blocks/job/internal/machine_job.builder.js +74 -0
- package/lib/elements/blocks/job/internal/machine_job.schema.d.ts +5 -0
- package/lib/elements/blocks/job/internal/machine_job.schema.js +10 -0
- package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +109 -0
- package/lib/elements/blocks/job/internal/resource_job.builder.js +146 -0
- package/lib/elements/blocks/job/internal/resource_job.d.ts +14 -0
- package/lib/elements/blocks/job/internal/resource_job.js +30 -0
- package/lib/elements/blocks/job/internal/resource_job.schema.d.ts +11 -0
- package/lib/elements/blocks/job/internal/resource_job.schema.js +15 -0
- package/lib/elements/blocks/job/job.builder.d.ts +118 -0
- package/lib/elements/blocks/job/job.builder.js +137 -0
- package/lib/elements/blocks/job/job.d.ts +13 -0
- package/lib/elements/blocks/job/job.js +40 -0
- package/lib/elements/blocks/job/job.schema.d.ts +26 -0
- package/lib/elements/blocks/job/job.schema.js +20 -0
- package/lib/elements/blocks/machine/machine.builder.d.ts +58 -0
- package/lib/elements/blocks/machine/machine.builder.js +135 -0
- package/lib/elements/blocks/machine/machine.d.ts +86 -0
- package/lib/elements/blocks/machine/machine.js +228 -0
- package/lib/elements/blocks/machine/machine.schema.d.ts +85 -0
- package/lib/elements/blocks/machine/machine.schema.js +64 -0
- package/lib/elements/blocks/machine/machine_state.builder.d.ts +58 -0
- package/lib/elements/blocks/machine/machine_state.builder.js +186 -0
- package/lib/elements/blocks/machine/machine_transition.builder.d.ts +48 -0
- package/lib/elements/blocks/machine/machine_transition.builder.js +98 -0
- package/lib/elements/blocks/queue/adapters/bucket.queue_adapter.d.ts +10 -0
- package/lib/elements/blocks/queue/adapters/bucket.queue_adapter.js +17 -0
- package/lib/elements/blocks/queue/adapters/queue_adapter.d.ts +6 -0
- package/lib/elements/blocks/queue/adapters/queue_adapter.js +6 -0
- package/lib/elements/blocks/queue/queue.builder.d.ts +40 -0
- package/lib/elements/blocks/queue/queue.builder.js +31 -0
- package/lib/elements/blocks/queue/queue.d.ts +9 -0
- package/lib/elements/blocks/queue/queue.js +11 -0
- package/lib/elements/blocks/queue/queue.schema.d.ts +12 -0
- package/lib/elements/blocks/queue/queue.schema.js +17 -0
- package/lib/elements/blocks/resource/resource.builder.d.ts +60 -0
- package/lib/elements/blocks/resource/resource.builder.js +224 -0
- package/lib/elements/blocks/resource/resource.d.ts +48 -0
- package/lib/elements/blocks/resource/resource.js +125 -0
- package/lib/elements/blocks/resource/resource.schema.d.ts +32 -0
- package/lib/elements/blocks/resource/resource.schema.js +30 -0
- package/lib/elements/blocks/resource/resource.types.d.ts +38 -0
- package/lib/elements/blocks/resource/resource.types.js +3 -0
- package/lib/elements/edge/controller/adapters/cli.controller_adapter.d.ts +8 -0
- package/lib/elements/edge/controller/adapters/cli.controller_adapter.js +17 -0
- package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +14 -0
- package/lib/elements/edge/controller/adapters/controller_adapter.js +44 -0
- package/lib/elements/edge/controller/controller.builder.d.ts +78 -0
- package/lib/elements/edge/controller/controller.builder.js +178 -0
- package/lib/elements/edge/controller/controller.config.d.ts +6 -0
- package/lib/elements/edge/controller/controller.config.js +2 -0
- package/lib/elements/edge/controller/controller.d.ts +22 -0
- package/lib/elements/edge/controller/controller.js +41 -0
- package/lib/elements/edge/controller/controller.schema.d.ts +44 -0
- package/lib/elements/edge/controller/controller.schema.js +51 -0
- package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +107 -0
- package/lib/elements/entities/bucket/adapters/bucket_adapter.js +41 -0
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.d.ts +37 -0
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +149 -0
- package/lib/elements/entities/bucket/adapters/memory.bucket_query copy.d.ts +0 -0
- package/lib/elements/entities/bucket/adapters/memory.bucket_query copy.js +218 -0
- package/lib/elements/entities/bucket/adapters/memory.nql.d.ts +19 -0
- package/lib/elements/entities/bucket/adapters/memory.nql.js +212 -0
- package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.d.ts +20 -0
- package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.js +31 -0
- package/lib/elements/entities/bucket/bucket.builder.d.ts +61 -0
- package/lib/elements/entities/bucket/bucket.builder.js +130 -0
- package/lib/elements/entities/bucket/bucket.config.d.ts +29 -0
- package/lib/elements/entities/bucket/bucket.config.js +2 -0
- package/lib/elements/entities/bucket/bucket.d.ts +36 -0
- package/lib/elements/entities/bucket/bucket.infer.d.ts +22 -0
- package/lib/elements/entities/bucket/bucket.infer.js +85 -0
- package/lib/elements/entities/bucket/bucket.js +125 -0
- package/lib/elements/entities/bucket/bucket.schema.d.ts +24 -0
- package/lib/elements/entities/bucket/bucket.schema.js +16 -0
- package/lib/elements/entities/bucket/bucket.types.d.ts +32 -0
- package/lib/elements/entities/bucket/bucket.types.js +2 -0
- package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +35 -0
- package/lib/elements/entities/bucket/cache/bucket_cache.js +182 -0
- package/lib/elements/entities/bucket/graph/bucket_graph.builder.d.ts +11 -0
- package/lib/elements/entities/bucket/graph/bucket_graph.builder.js +27 -0
- package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +16 -0
- package/lib/elements/entities/bucket/graph/bucket_graph.infer.d.ts +9 -0
- package/lib/elements/entities/bucket/graph/bucket_graph.infer.js +2 -0
- package/lib/elements/entities/bucket/graph/bucket_graph.js +136 -0
- package/lib/elements/entities/bucket/graph/bucket_graph.schema.d.ts +28 -0
- package/lib/elements/entities/bucket/graph/bucket_graph.schema.js +27 -0
- package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.d.ts +36 -0
- package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.js +56 -0
- package/lib/elements/entities/bucket/model/bucket_model.builder.d.ts +13 -0
- package/lib/elements/entities/bucket/model/bucket_model.builder.js +24 -0
- package/lib/elements/entities/bucket/model/bucket_model.convert.d.ts +5 -0
- package/lib/elements/entities/bucket/model/bucket_model.convert.js +51 -0
- package/lib/elements/entities/bucket/model/bucket_model.infer.d.ts +13 -0
- package/lib/elements/entities/bucket/model/bucket_model.infer.js +2 -0
- package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +35 -0
- package/lib/elements/entities/bucket/model/bucket_model.schema.js +47 -0
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +119 -0
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +154 -0
- package/lib/elements/entities/bucket/query/nql.schema.d.ts +140 -0
- package/lib/elements/entities/bucket/query/nql.schema.js +2 -0
- package/lib/elements/entities/bucket/query/nql_compiler.d.ts +44 -0
- package/lib/elements/entities/bucket/query/nql_compiler.js +620 -0
- package/lib/elements/entities/bucket/query/nql_engine.d.ts +16 -0
- package/lib/elements/entities/bucket/query/nql_engine.js +42 -0
- package/lib/elements/entities/bucket/view/bucket_view.builder.d.ts +14 -0
- package/lib/elements/entities/bucket/view/bucket_view.builder.js +24 -0
- package/lib/elements/entities/bucket/view/bucket_view.d.ts +10 -0
- package/lib/elements/entities/bucket/view/bucket_view.js +102 -0
- package/lib/elements/entities/bucket/view/bucket_view.schema.d.ts +55 -0
- package/lib/elements/entities/bucket/view/bucket_view.schema.js +42 -0
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +37 -0
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +138 -0
- package/lib/elements/entities/constants/constants.builder.d.ts +57 -0
- package/lib/elements/entities/constants/constants.builder.js +116 -0
- package/lib/elements/entities/constants/constants.d.ts +7 -0
- package/lib/elements/entities/constants/constants.js +15 -0
- package/lib/elements/entities/constants/constants.schema.d.ts +51 -0
- package/lib/elements/entities/constants/constants.schema.js +45 -0
- package/lib/elements/entities/message/message.builder.d.ts +33 -0
- package/lib/elements/entities/message/message.builder.js +41 -0
- package/lib/elements/entities/message/message.d.ts +11 -0
- package/lib/elements/entities/message/message.infer.d.ts +63 -0
- package/lib/elements/entities/message/message.infer.js +2 -0
- package/lib/elements/entities/message/message.js +52 -0
- package/lib/elements/entities/message/message.schema.d.ts +15 -0
- package/lib/elements/entities/message/message.schema.js +13 -0
- package/lib/elements/entities/message/message_parser.d.ts +12 -0
- package/lib/elements/entities/message/message_parser.js +112 -0
- package/lib/elements/entities/message/template/message_template.builder.d.ts +14 -0
- package/lib/elements/entities/message/template/message_template.builder.js +20 -0
- package/lib/elements/entities/message/template/message_template.schema.d.ts +57 -0
- package/lib/elements/entities/message/template/message_template.schema.js +28 -0
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +225 -0
- package/lib/elements/entities/message/template/message_template_field.builder.js +172 -0
- package/lib/elements/entities/message/template/message_template_parser.d.ts +3 -0
- package/lib/elements/entities/message/template/message_template_parser.js +83 -0
- package/lib/elements/index.d.ts +11 -0
- package/lib/elements/index.js +23 -0
- package/lib/engine/apps/app.config.d.ts +49 -0
- package/lib/engine/apps/app.config.js +38 -0
- package/lib/engine/apps/app.d.ts +70 -0
- package/lib/engine/apps/app.js +101 -0
- package/lib/engine/apps/inline.app.d.ts +48 -0
- package/lib/engine/apps/inline.app.js +144 -0
- package/lib/engine/apps/monolyth/monolyth.app.d.ts +20 -0
- package/lib/engine/apps/monolyth/monolyth.app.js +94 -0
- package/lib/engine/apps/monolyth/monolyth.cli.d.ts +45 -0
- package/lib/engine/apps/monolyth/monolyth.cli.js +362 -0
- package/lib/engine/auth/authn.d.ts +18 -0
- package/lib/engine/auth/authn.js +9 -0
- package/lib/engine/auth/zero.authn_provider.d.ts +13 -0
- package/lib/engine/auth/zero.authn_provider.js +13 -0
- package/lib/engine/cli/cli.d.ts +19 -0
- package/lib/engine/cli/cli.js +88 -0
- package/lib/engine/cli/cli_adapter.d.ts +18 -0
- package/lib/engine/cli/cli_adapter.js +61 -0
- package/lib/engine/cli/ui.d.ts +36 -0
- package/lib/engine/cli/ui.js +188 -0
- package/lib/engine/daemon.d.ts +35 -0
- package/lib/engine/daemon.js +66 -0
- package/lib/engine/data/date.d.ts +10 -0
- package/lib/engine/data/date.js +32 -0
- package/lib/engine/data/datetime.d.ts +12 -0
- package/lib/engine/data/datetime.js +31 -0
- package/lib/engine/data/decimal.d.ts +11 -0
- package/lib/engine/data/decimal.js +70 -0
- package/lib/engine/data/error.d.ts +213 -0
- package/lib/engine/data/error.js +386 -0
- package/lib/engine/data/obj.d.ts +16 -0
- package/lib/engine/data/obj.js +5 -0
- package/lib/engine/data/tree.d.ts +17 -0
- package/lib/engine/data/tree.js +111 -0
- package/lib/engine/dependency.d.ts +68 -0
- package/lib/engine/dependency.js +91 -0
- package/lib/engine/module.d.ts +97 -0
- package/lib/engine/module.js +335 -0
- package/lib/engine/space.d.ts +54 -0
- package/lib/engine/space.js +138 -0
- package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +53 -0
- package/lib/engine/transaction/nodes/bucket.trx_node.js +522 -0
- package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +17 -0
- package/lib/engine/transaction/nodes/bucket_query.trx_node.js +82 -0
- package/lib/engine/transaction/nodes/job.trx_node.d.ts +13 -0
- package/lib/engine/transaction/nodes/job.trx_node.js +40 -0
- package/lib/engine/transaction/nodes/machine.trx_node.d.ts +12 -0
- package/lib/engine/transaction/nodes/machine.trx_node.js +39 -0
- package/lib/engine/transaction/nodes/queue.trx_node.d.ts +10 -0
- package/lib/engine/transaction/nodes/queue.trx_node.js +24 -0
- package/lib/engine/transaction/nodes/resource.trx_node.d.ts +24 -0
- package/lib/engine/transaction/nodes/resource.trx_node.js +77 -0
- package/lib/engine/transaction/trx.d.ts +50 -0
- package/lib/engine/transaction/trx.js +94 -0
- package/lib/engine/transaction/trx_engine.config.d.ts +15 -0
- package/lib/engine/transaction/trx_engine.config.js +2 -0
- package/lib/engine/transaction/trx_engine.d.ts +27 -0
- package/lib/engine/transaction/trx_engine.js +95 -0
- package/lib/engine/transaction/trx_node.d.ts +61 -0
- package/lib/engine/transaction/trx_node.js +175 -0
- package/lib/engine/tree.d.ts +34 -0
- package/lib/engine/tree.js +237 -0
- package/lib/engine/util/cache.d.ts +6 -0
- package/lib/engine/util/cache.js +20 -0
- package/lib/engine/util/console.d.ts +4 -0
- package/lib/engine/util/console.js +24 -0
- package/lib/engine/util/deep.d.ts +7 -0
- package/lib/engine/util/deep.js +2 -0
- package/lib/engine/util/dotenv.d.ts +15 -0
- package/lib/engine/util/dotenv.js +94 -0
- package/lib/engine/util/i18n.d.ts +5 -0
- package/lib/engine/util/i18n.js +19 -0
- package/lib/engine/util/log.d.ts +17 -0
- package/lib/engine/util/log.js +93 -0
- package/lib/engine/util/parse.d.ts +63 -0
- package/lib/engine/util/parse.js +229 -0
- package/lib/engine/util/promise.d.ts +3 -0
- package/lib/engine/util/promise.js +14 -0
- package/lib/engine/util/shell.d.ts +6 -0
- package/lib/engine/util/shell.js +44 -0
- package/lib/engine/util/string.d.ts +18 -0
- package/lib/engine/util/string.js +25 -0
- package/lib/engine/util/type.d.ts +7 -0
- package/lib/engine/util/type.js +3 -0
- package/lib/schema.d.ts +63 -0
- package/lib/schema.js +2 -0
- package/package.json +22 -0
- package/tools/compile.d.ts +1 -0
- package/tools/compile.js +68 -0
- package/tools/joaquin/job.d.ts +40 -0
- package/tools/joaquin/job.js +47 -0
- package/tools/joaquin/message.d.ts +12 -0
- package/tools/joaquin/message.js +47 -0
- package/tools/joaquin/mock.d.ts +28 -0
- package/tools/joaquin/mock.js +128 -0
- package/tsconfig.build.tsbuildinfo +1 -0
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NQL_CompiledQuery = exports.NQL_Compiler = exports.NQL_RuleTree = void 0;
|
|
4
|
+
const bucket_model_schema_1 = require("../model/bucket_model.schema");
|
|
5
|
+
const string_1 = require("../../../../engine/util/string");
|
|
6
|
+
const bucket_1 = require("../bucket");
|
|
7
|
+
class NQL_RuleTree {
|
|
8
|
+
constructor(module, bucketName, query, debug = false) {
|
|
9
|
+
this.module = module;
|
|
10
|
+
this.bucketName = bucketName;
|
|
11
|
+
this.query = query;
|
|
12
|
+
this.debug = debug;
|
|
13
|
+
const bucket = module.buckets[this.bucketName];
|
|
14
|
+
this.root = this.parseUnion(bucket, query);
|
|
15
|
+
if (debug) {
|
|
16
|
+
console.log(this.describe());
|
|
17
|
+
}
|
|
18
|
+
this.simplify();
|
|
19
|
+
this._addDebugId();
|
|
20
|
+
if (debug) {
|
|
21
|
+
console.log(this.describe());
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Parse NQL
|
|
25
|
+
parseUnion(bucket, query, select) {
|
|
26
|
+
const meta = bucket_1.Bucket.getQueryMeta(bucket);
|
|
27
|
+
const union = {
|
|
28
|
+
meta: {
|
|
29
|
+
...meta,
|
|
30
|
+
avgTime: 0
|
|
31
|
+
},
|
|
32
|
+
inters: [
|
|
33
|
+
{ meta: {}, rules: [] }
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
for (const key in query) {
|
|
37
|
+
const value = query[key];
|
|
38
|
+
const parsedKey = this.parseKey(bucket, key);
|
|
39
|
+
// Fieldpath term -> Condition
|
|
40
|
+
if (parsedKey.type === 'fieldpath') {
|
|
41
|
+
const parsed = this.parseValue(value, parsedKey, meta, select);
|
|
42
|
+
const rule = ('subquery' in parsed)
|
|
43
|
+
? parsed.subquery
|
|
44
|
+
: {
|
|
45
|
+
meta: { ...meta },
|
|
46
|
+
select,
|
|
47
|
+
fieldpath: parsedKey.fieldpath,
|
|
48
|
+
value: parsed,
|
|
49
|
+
op: parsedKey.op,
|
|
50
|
+
case_i: parsedKey.case_i,
|
|
51
|
+
not: parsedKey.not
|
|
52
|
+
};
|
|
53
|
+
// console.log({ parsedKey, parsed, rule })
|
|
54
|
+
if (!parsedKey.or) {
|
|
55
|
+
union.inters[0].rules.push(rule);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
union.inters.push({ meta: {}, rules: [rule] });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// TODO: Pre-parse graph link into subquery
|
|
62
|
+
// Graph Link term -> Condition
|
|
63
|
+
// else if (parsedKey.type === 'graphlink') {
|
|
64
|
+
// parsedValue = this.parseExpression(parsedKey.linkBucket!, value)
|
|
65
|
+
// }
|
|
66
|
+
else if (parsedKey.type === 'and') {
|
|
67
|
+
const subInter = this.parseUnion(bucket, value, select);
|
|
68
|
+
union.inters[0].rules.push(subInter);
|
|
69
|
+
}
|
|
70
|
+
else if (parsedKey.type === 'or') {
|
|
71
|
+
const subInter = this.parseUnion(bucket, value, select);
|
|
72
|
+
union.inters.push({ meta: {}, rules: [subInter] });
|
|
73
|
+
}
|
|
74
|
+
else if (parsedKey.type === 'order') {
|
|
75
|
+
union.order = this.parseOrder(bucket, value);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!union.inters[0]?.rules.length) {
|
|
79
|
+
union.inters.splice(0, 1);
|
|
80
|
+
}
|
|
81
|
+
return union;
|
|
82
|
+
}
|
|
83
|
+
parseOrder(bucket, value) {
|
|
84
|
+
let by = value['by'];
|
|
85
|
+
if (by) {
|
|
86
|
+
const field = bucket_model_schema_1.$BucketModel.get(bucket.schema.model, by);
|
|
87
|
+
if (!field) {
|
|
88
|
+
throw new Error(`Field '${by}' not found on bucket '${bucket.schema.name}'`);
|
|
89
|
+
}
|
|
90
|
+
if (![
|
|
91
|
+
'date', 'datetime', 'decimal', 'enum', 'float', 'int', 'string'
|
|
92
|
+
].includes(field.type)) {
|
|
93
|
+
throw new Error(`Field '${by}' is not sortable`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
by = 'id';
|
|
98
|
+
}
|
|
99
|
+
let dir = value['dir'];
|
|
100
|
+
if (dir) {
|
|
101
|
+
if (dir !== 'asc' && dir !== 'desc') {
|
|
102
|
+
throw new Error(`Invalid query order direction '${dir}', expected 'asc'|'desc'`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
dir = 'desc';
|
|
107
|
+
}
|
|
108
|
+
return { by, dir };
|
|
109
|
+
}
|
|
110
|
+
parseKey(bucket, key) {
|
|
111
|
+
if (key === '#order') {
|
|
112
|
+
return { type: 'order' };
|
|
113
|
+
}
|
|
114
|
+
else if (key.startsWith('#and')) {
|
|
115
|
+
return { type: 'and' };
|
|
116
|
+
}
|
|
117
|
+
else if (key.startsWith('#or')) {
|
|
118
|
+
return { type: 'or' };
|
|
119
|
+
}
|
|
120
|
+
else if (key.startsWith('*')) {
|
|
121
|
+
const linkName = key.slice(1);
|
|
122
|
+
const link = bucket.schema.graph.links[linkName];
|
|
123
|
+
if (!link) {
|
|
124
|
+
throw new Error(`Graph Link '${link}' doesn't exist on the bucket ${bucket}`);
|
|
125
|
+
}
|
|
126
|
+
const linkBucket = this.module.buckets[link.bucket.refName].schema;
|
|
127
|
+
if (!linkBucket) {
|
|
128
|
+
throw new Error(`Graph Link '${link}' points to a bucket '${link.bucket}' not found on the module ${this.module.name}`);
|
|
129
|
+
}
|
|
130
|
+
return { type: 'graphlink', link: link.name, linkBucket };
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const term = key.match(/^(or )?([\w|.|*]+)( not)? ?(~)?(.*)$/);
|
|
134
|
+
if (!term) {
|
|
135
|
+
throw new Error(`Invalid term '${key}'`);
|
|
136
|
+
}
|
|
137
|
+
const [_, or, fieldpath, not, case_i, op] = term;
|
|
138
|
+
const field = bucket_model_schema_1.$BucketModel.get(bucket.schema.model, fieldpath);
|
|
139
|
+
if (!field) {
|
|
140
|
+
throw new Error(`Field '${fieldpath}' not found on bucket '${bucket.schema.name}'`);
|
|
141
|
+
}
|
|
142
|
+
const _op = this.parseOp(bucket.schema.name, field, op);
|
|
143
|
+
return { type: 'fieldpath', or: !!or, fieldpath, not: !!not, case_i: !!case_i, op: _op };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
parseOp(bucketName, field, op) {
|
|
147
|
+
const _op = (op === '' ? '==' : op);
|
|
148
|
+
if (![
|
|
149
|
+
'==', '>', '<', '>=', '<=',
|
|
150
|
+
'in', 'contains', 'contains_any', 'present'
|
|
151
|
+
].includes(_op)) {
|
|
152
|
+
throw new Error(`Invalid operation '${_op}' not found on bucket '${bucketName}'`);
|
|
153
|
+
}
|
|
154
|
+
const allowedOps = NQL_RuleTree.OpByType[field.type];
|
|
155
|
+
if (!allowedOps.includes(_op)) {
|
|
156
|
+
throw new Error(`Field '${field.name}' of type '${field.type}' doesn't support operation '${op}'`);
|
|
157
|
+
}
|
|
158
|
+
return _op;
|
|
159
|
+
}
|
|
160
|
+
parseValue(value, parsedKey, meta, select) {
|
|
161
|
+
if (typeof value === 'object') {
|
|
162
|
+
// Array
|
|
163
|
+
if (Array.isArray(value)) {
|
|
164
|
+
const statyc = [];
|
|
165
|
+
const params = [];
|
|
166
|
+
for (const item of value) {
|
|
167
|
+
const parsed = this.parseValue(item, parsedKey, meta, select);
|
|
168
|
+
if ('static' in parsed) {
|
|
169
|
+
statyc.push(parsed.static);
|
|
170
|
+
}
|
|
171
|
+
else if ('param' in parsed) {
|
|
172
|
+
params.push(parsed.param);
|
|
173
|
+
}
|
|
174
|
+
else if ('subquery' in parsed) {
|
|
175
|
+
throw new Error(`Subqueries not accepted inside array value [${value}]`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (statyc.length > 0 && params.length > 0) {
|
|
179
|
+
throw new Error(`Cannot mix static and parameter values inside array value [${value}]`);
|
|
180
|
+
}
|
|
181
|
+
if (params.length > 0) {
|
|
182
|
+
return { param: params };
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
return { static: statyc };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
// Parameter
|
|
190
|
+
if ('.' in value) {
|
|
191
|
+
return { param: value['.'] };
|
|
192
|
+
}
|
|
193
|
+
// Sub-Query
|
|
194
|
+
return { subquery: this.parseSubQuery(value, parsedKey, meta, select) };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Static value
|
|
198
|
+
else {
|
|
199
|
+
return { static: value };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
parseSubQuery(value, parsedKey, meta, select) {
|
|
203
|
+
const union = {
|
|
204
|
+
meta: {},
|
|
205
|
+
inters: [
|
|
206
|
+
{ meta: {}, rules: [] }
|
|
207
|
+
]
|
|
208
|
+
};
|
|
209
|
+
for (const key in value) {
|
|
210
|
+
if (key.startsWith('@') || key.startsWith('or @')) {
|
|
211
|
+
const refField = key.match(/(or )?@(\w+)\.(.*)/);
|
|
212
|
+
if (!refField) {
|
|
213
|
+
throw new Error(`Invalid bucket field '${key}'`);
|
|
214
|
+
}
|
|
215
|
+
const [_, or, refBucket, fieldpath] = refField;
|
|
216
|
+
const bucket = this.module.buckets[refBucket];
|
|
217
|
+
if (!bucket) {
|
|
218
|
+
throw new Error(`Bucket '${bucket}' not found on module`);
|
|
219
|
+
}
|
|
220
|
+
const field = bucket_model_schema_1.$BucketModel.get(bucket.schema.model, fieldpath);
|
|
221
|
+
if (!field) {
|
|
222
|
+
throw new Error(`Field '${fieldpath}' not found on bucket '${bucket.schema.name}'`);
|
|
223
|
+
}
|
|
224
|
+
const refInter = this.parseUnion(bucket, value[key], fieldpath);
|
|
225
|
+
const rule = {
|
|
226
|
+
meta: { ...meta },
|
|
227
|
+
select,
|
|
228
|
+
fieldpath: parsedKey.fieldpath,
|
|
229
|
+
case_i: parsedKey.case_i,
|
|
230
|
+
not: parsedKey.not,
|
|
231
|
+
op: parsedKey.op,
|
|
232
|
+
value: {
|
|
233
|
+
subquery: refInter
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
if (!or) {
|
|
237
|
+
union.inters[0].rules.push(rule);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
union.inters.push({ meta: {}, rules: [rule] });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (!union.inters[0]?.rules.length) {
|
|
245
|
+
union.inters.splice(0, 1);
|
|
246
|
+
}
|
|
247
|
+
// // Regroup inter rules by scope
|
|
248
|
+
// // Also, transfer "select" from subquery to scope rule
|
|
249
|
+
// for (const inter of union.inters) {
|
|
250
|
+
// const rulesByScope: Record<string, NQL_Rule[]> = {}
|
|
251
|
+
// for (const rule of inter.rules) {
|
|
252
|
+
// const union = (rule as any).value.subquery as NQL_Union;
|
|
253
|
+
// rulesByScope[union.meta.scope!] ??= []
|
|
254
|
+
// rulesByScope[union.meta.scope!].push(rule as NQL_Rule);
|
|
255
|
+
// }
|
|
256
|
+
// inter.rules = Object.values(rulesByScope).map(rules => {
|
|
257
|
+
// const rule = rules[0];
|
|
258
|
+
// return {
|
|
259
|
+
// ...rule,
|
|
260
|
+
// value: {
|
|
261
|
+
// subquery: {
|
|
262
|
+
// meta: { ...(rule.value as any).subquery.meta },
|
|
263
|
+
// inters: rules.map(c =>
|
|
264
|
+
// (c.value as any).subquery.inters
|
|
265
|
+
// ).flat(1)
|
|
266
|
+
// }
|
|
267
|
+
// }
|
|
268
|
+
// }
|
|
269
|
+
// })
|
|
270
|
+
// }
|
|
271
|
+
return union;
|
|
272
|
+
}
|
|
273
|
+
// Cleanup
|
|
274
|
+
/**
|
|
275
|
+
* Depth-first search on the tree:
|
|
276
|
+
* - Collapses single-child Unions
|
|
277
|
+
* - Accumulate avgTime over tree nodes, for building multi-tree
|
|
278
|
+
*/
|
|
279
|
+
simplify() {
|
|
280
|
+
const stack = [[this.root, -1]];
|
|
281
|
+
while (stack.length) {
|
|
282
|
+
const node = stack.at(-1);
|
|
283
|
+
const parent = stack.at(-2);
|
|
284
|
+
// Union
|
|
285
|
+
if ('inters' in node[0]) {
|
|
286
|
+
// Union has a single child and a parent, should be collapsed
|
|
287
|
+
if (node[0].inters.length == 1 && parent) {
|
|
288
|
+
// Parent is a Intersection
|
|
289
|
+
if ('rules' in parent[0]) {
|
|
290
|
+
const inter = node[0].inters[0];
|
|
291
|
+
parent[0].rules.splice(parent[1], 1, ...inter.rules);
|
|
292
|
+
stack.pop();
|
|
293
|
+
stack.push([inter, -1]);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// Iterate
|
|
298
|
+
node[1]++;
|
|
299
|
+
const next = node[0].inters[node[1]];
|
|
300
|
+
if (next)
|
|
301
|
+
stack.push([next, -1]);
|
|
302
|
+
else {
|
|
303
|
+
if (parent) {
|
|
304
|
+
// Add union time to parent
|
|
305
|
+
parent[0].meta.avgTime = (parent[0].meta.avgTime || 0) + node[0].meta.avgTime;
|
|
306
|
+
}
|
|
307
|
+
stack.pop();
|
|
308
|
+
}
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
// Intersection
|
|
312
|
+
else if ('rules' in node[0]) {
|
|
313
|
+
// Iterate
|
|
314
|
+
node[1]++;
|
|
315
|
+
const next = node[0].rules[node[1]];
|
|
316
|
+
if (next)
|
|
317
|
+
stack.push([next, -1]);
|
|
318
|
+
else {
|
|
319
|
+
// Add inter time to union
|
|
320
|
+
parent[0].meta.avgTime = (parent[0].meta.avgTime || 0) + node[0].meta.avgTime;
|
|
321
|
+
stack.pop();
|
|
322
|
+
}
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
// Rule
|
|
326
|
+
else {
|
|
327
|
+
// Iterate
|
|
328
|
+
if ('subquery' in node[0].value && node[1] < 0) {
|
|
329
|
+
node[1]++;
|
|
330
|
+
const next = node[0].value.subquery;
|
|
331
|
+
stack.push([next, -1]);
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
// Add rule time to inter
|
|
335
|
+
parent[0].meta.avgTime = (parent[0].meta.avgTime || 0) + node[0].meta.avgTime;
|
|
336
|
+
stack.pop();
|
|
337
|
+
}
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Pretty Print
|
|
343
|
+
_addDebugId() {
|
|
344
|
+
let id = 0;
|
|
345
|
+
const addIndex = (node) => {
|
|
346
|
+
node._debug_id = id++;
|
|
347
|
+
if ('inters' in node) {
|
|
348
|
+
node.inters.forEach(inter => {
|
|
349
|
+
addIndex(inter);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
else if ('rules' in node) {
|
|
353
|
+
node.rules.forEach(rule => {
|
|
354
|
+
addIndex(rule);
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
else if ('value' in node) {
|
|
358
|
+
if ('subquery' in node.value) {
|
|
359
|
+
addIndex(node.value['subquery']);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
addIndex(this.root);
|
|
364
|
+
}
|
|
365
|
+
describeNQL() {
|
|
366
|
+
let str = '';
|
|
367
|
+
str += (0, string_1.colored)('◆ NQL:\n', 'lightblue');
|
|
368
|
+
str += (0, string_1.colored)(JSON.stringify(this.query, undefined, 2), 'darkgray');
|
|
369
|
+
return str;
|
|
370
|
+
}
|
|
371
|
+
describe() {
|
|
372
|
+
return NQL_RuleTree.describe(this.root);
|
|
373
|
+
}
|
|
374
|
+
static describe(node, d = 0) {
|
|
375
|
+
let str = '';
|
|
376
|
+
// Union
|
|
377
|
+
if ('inters' in node) {
|
|
378
|
+
str += Array(d).fill(' ').join('')
|
|
379
|
+
+ (0, string_1.colored)(`└ ${node._debug_id || ''}[OR] `, 'lightpurple')
|
|
380
|
+
+ (0, string_1.colored)(`${node.meta.scope || ''} ${node.meta.avgTime || '?'}ms `, 'black')
|
|
381
|
+
+ (node.order ? ` order by ${node.order.by} ${node.order.dir}` : '')
|
|
382
|
+
+ '\n';
|
|
383
|
+
node.inters.forEach(inter => {
|
|
384
|
+
str += this.describe(inter, d + 1);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
// Intersection
|
|
388
|
+
else if ('rules' in node) {
|
|
389
|
+
str += Array(d).fill(' ').join('')
|
|
390
|
+
+ (0, string_1.colored)(`└ ${node._debug_id || ''}[AND] `, 'lightblue')
|
|
391
|
+
+ (0, string_1.colored)(`${node.meta.scope || ''} ${node.meta.avgTime || '?'}ms `, 'black')
|
|
392
|
+
+ '\n';
|
|
393
|
+
node.rules.forEach(rule => {
|
|
394
|
+
str += this.describe(rule, d + 1);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
// Rule
|
|
398
|
+
else if ('value' in node) {
|
|
399
|
+
str += Array(d).fill(' ').join('')
|
|
400
|
+
+ (0, string_1.colored)(`└ ${node._debug_id || ''}[if] `, 'lightcyan')
|
|
401
|
+
+ (0, string_1.colored)(node.select ? '(⊹ ' + node.select + ') ' : '', 'brown')
|
|
402
|
+
+ (0, string_1.colored)(`${node.meta.scope || ''} ${node.meta.avgTime || '?'}ms `, 'black')
|
|
403
|
+
+ `@${node.meta.bucket?.name}.${node.fieldpath}${node.not ? ' not' : ''} ${node.case_i ? '~' : ''}${node.op}`
|
|
404
|
+
+ (('static' in node.value) ? ` ${node.value.static}`
|
|
405
|
+
: ('param' in node.value) ? ` ->${node.value.param}`
|
|
406
|
+
: ' ▼')
|
|
407
|
+
+ '\n';
|
|
408
|
+
if ('subquery' in node.value) {
|
|
409
|
+
str += this.describe(node.value['subquery'], d + 1);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return str;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
exports.NQL_RuleTree = NQL_RuleTree;
|
|
416
|
+
NQL_RuleTree.OpByType = {
|
|
417
|
+
'boolean': ['==', 'in', 'present'],
|
|
418
|
+
'date': ['<', '<=', '==', '>', '>=', 'in', 'present'],
|
|
419
|
+
'datetime': ['<', '<=', '==', '>', '>=', 'in', 'present'],
|
|
420
|
+
'decimal': ['<', '<=', '==', '>', '>=', 'in', 'present'],
|
|
421
|
+
'dict': ['==', 'contains', 'contains_any', 'in', 'present'],
|
|
422
|
+
'enum': ['==', 'contains', 'contains_any', 'in', 'present'],
|
|
423
|
+
'file': [],
|
|
424
|
+
'float': ['<', '<=', '==', '>', '>=', 'in', 'present'],
|
|
425
|
+
'int': ['<', '<=', '==', '>', '>=', 'in', 'present'],
|
|
426
|
+
'obj': ['==', 'contains', 'contains_any', 'in', 'present'],
|
|
427
|
+
'string': ['==', 'contains', 'contains_any', 'in', 'present'],
|
|
428
|
+
'unknown': ['present']
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* Builds a NQL_CompiledQuery by splitting it into multiple parts
|
|
432
|
+
*/
|
|
433
|
+
class NQL_Compiler {
|
|
434
|
+
static build(module, bucketName, query) {
|
|
435
|
+
const tree = new NQL_RuleTree(module, bucketName, query);
|
|
436
|
+
return this.buildUnion(tree.root);
|
|
437
|
+
}
|
|
438
|
+
static buildUnion(union) {
|
|
439
|
+
// const debugLog: string[] = [];
|
|
440
|
+
// Create top-level part
|
|
441
|
+
const parts = [{
|
|
442
|
+
i: 0,
|
|
443
|
+
many: true,
|
|
444
|
+
union: {}
|
|
445
|
+
}];
|
|
446
|
+
const orderedParts = [];
|
|
447
|
+
// Stacks used on process
|
|
448
|
+
const stack = [[union, -1]];
|
|
449
|
+
const buildStack = [parts[0].union];
|
|
450
|
+
const partStack = [parts[0]];
|
|
451
|
+
// Sort union children by avgTime before iterating
|
|
452
|
+
union.inters.sort((a, b) => a.meta.avgTime - b.meta.avgTime);
|
|
453
|
+
while (stack.length) {
|
|
454
|
+
const node = stack.at(-1);
|
|
455
|
+
// debugLog.push('⇢ ' + node[0]._debug_id);
|
|
456
|
+
// Union
|
|
457
|
+
if ('inters' in node[0]) {
|
|
458
|
+
const union = node[0];
|
|
459
|
+
// Rebuild union
|
|
460
|
+
const buildNode = buildStack.at(-1);
|
|
461
|
+
if (node[1] < 0) {
|
|
462
|
+
const build = {
|
|
463
|
+
...union,
|
|
464
|
+
inters: Array.from(Array(union.inters.length), _ => ({}))
|
|
465
|
+
};
|
|
466
|
+
Object.assign(buildNode, build);
|
|
467
|
+
}
|
|
468
|
+
// Iterate inter
|
|
469
|
+
node[1]++;
|
|
470
|
+
const next = union.inters[node[1]];
|
|
471
|
+
const buildNext = buildNode.inters[node[1]];
|
|
472
|
+
if (next) {
|
|
473
|
+
// Sort union children by avgTime before iterating
|
|
474
|
+
next.rules.sort((a, b) => a.meta.avgTime - b.meta.avgTime);
|
|
475
|
+
// Union → Intersection
|
|
476
|
+
stack.push([next, -1]);
|
|
477
|
+
buildStack.push(buildNext);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
// Intersection
|
|
482
|
+
else if ('rules' in node[0]) {
|
|
483
|
+
const inter = node[0];
|
|
484
|
+
// Rebuild inter
|
|
485
|
+
const buildNode = buildStack.at(-1);
|
|
486
|
+
if (node[1] < 0) {
|
|
487
|
+
const build = {
|
|
488
|
+
...inter,
|
|
489
|
+
rules: Array.from(Array(inter.rules.length), _ => ({}))
|
|
490
|
+
};
|
|
491
|
+
Object.assign(buildNode, build);
|
|
492
|
+
}
|
|
493
|
+
// Iterate
|
|
494
|
+
node[1]++;
|
|
495
|
+
const next = inter.rules[node[1]];
|
|
496
|
+
const buildNext = buildNode.rules[node[1]];
|
|
497
|
+
if (next) {
|
|
498
|
+
// Sort children by avgTime before iterating
|
|
499
|
+
if ('value' in next) {
|
|
500
|
+
if ('subquery' in next.value) {
|
|
501
|
+
next.value.subquery.inters.sort((a, b) => a.meta.avgTime - b.meta.avgTime);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
next.inters.sort((a, b) => a.meta.avgTime - b.meta.avgTime);
|
|
506
|
+
}
|
|
507
|
+
// Intersection → Condition
|
|
508
|
+
stack.push([next, -1]);
|
|
509
|
+
buildStack.push(buildNext);
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
// Rule
|
|
514
|
+
else {
|
|
515
|
+
const rule = node[0];
|
|
516
|
+
const buildNode = buildStack.at(-1);
|
|
517
|
+
// Divergent Scope: A subquery scope doesn't match the
|
|
518
|
+
// rule scope, create new Part and Replace with Parameter
|
|
519
|
+
if (node[1] < 0 && 'subquery' in rule.value) {
|
|
520
|
+
const union = rule.value.subquery;
|
|
521
|
+
if (rule.meta.scope !== union.meta.scope) {
|
|
522
|
+
// Start new Part
|
|
523
|
+
const newPart = {
|
|
524
|
+
i: parts.length,
|
|
525
|
+
many: (rule.op === 'in' || rule.op === 'contains_any'),
|
|
526
|
+
union: {
|
|
527
|
+
...union,
|
|
528
|
+
inters: Array.from(Array(union.inters.length), _ => ({}))
|
|
529
|
+
},
|
|
530
|
+
parent: partStack.at(-1)
|
|
531
|
+
};
|
|
532
|
+
// debugLog.push('+ [part] ' + newPart.i);
|
|
533
|
+
parts.push(newPart);
|
|
534
|
+
partStack.push(newPart);
|
|
535
|
+
// Make part the one being built
|
|
536
|
+
Object.assign(buildNode, {
|
|
537
|
+
...rule,
|
|
538
|
+
value: { subquery: newPart.union }
|
|
539
|
+
});
|
|
540
|
+
// Add part to original rule, to remove it
|
|
541
|
+
// from the stack once we're done (&1)
|
|
542
|
+
rule.part = newPart.i;
|
|
543
|
+
// Also add part to built rule, for easier reference
|
|
544
|
+
// when running.
|
|
545
|
+
buildNode.part = newPart.i;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
// Rebuild rule, if not a divergent scope
|
|
549
|
+
let rebuild = undefined;
|
|
550
|
+
if (node[1] < 0 && !rule.part) {
|
|
551
|
+
rebuild = {
|
|
552
|
+
...rule
|
|
553
|
+
};
|
|
554
|
+
if ('subquery' in rebuild.value) {
|
|
555
|
+
rebuild.value = { subquery: {} };
|
|
556
|
+
}
|
|
557
|
+
Object.assign(buildNode, rebuild);
|
|
558
|
+
}
|
|
559
|
+
// Iterate
|
|
560
|
+
if ('subquery' in rule.value && node[1] < 0) {
|
|
561
|
+
node[1]++;
|
|
562
|
+
const next = rule.value.subquery;
|
|
563
|
+
const secNext = buildNode.value?.subquery;
|
|
564
|
+
// Sort children by avgTime before iterating
|
|
565
|
+
next.inters.sort((a, b) => a.meta.avgTime - b.meta.avgTime);
|
|
566
|
+
// Rule → Union
|
|
567
|
+
stack.push([next, -1]);
|
|
568
|
+
buildStack.push(secNext);
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
// Close part (&1)
|
|
573
|
+
if (rule.part) {
|
|
574
|
+
// Rebuild Union on original tree as Condition
|
|
575
|
+
buildNode.value = { param: `%__${rule.part}__%` };
|
|
576
|
+
if (rule.part == partStack.at(-1).i) {
|
|
577
|
+
// debugLog.push('⊙ [part] ' + rule.part);
|
|
578
|
+
orderedParts.push(parts[rule.part]);
|
|
579
|
+
partStack.pop();
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
stack.pop();
|
|
585
|
+
buildStack.pop();
|
|
586
|
+
// debugLog.push('↑ ' + node[0]._debug_id);
|
|
587
|
+
}
|
|
588
|
+
return new NQL_CompiledQuery([...orderedParts, parts[0]]);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
exports.NQL_Compiler = NQL_Compiler;
|
|
592
|
+
/**
|
|
593
|
+
* A query ready to be run by the NQL engine, which will call
|
|
594
|
+
* each NQLRunner with a different adapter
|
|
595
|
+
*/
|
|
596
|
+
class NQL_CompiledQuery {
|
|
597
|
+
constructor(parts) {
|
|
598
|
+
this.parts = {};
|
|
599
|
+
this.execOrder = [];
|
|
600
|
+
for (let i = 0; i < parts.length; i++) {
|
|
601
|
+
const part = parts[i];
|
|
602
|
+
this.execOrder.push(part.i);
|
|
603
|
+
this.parts[part.i] = part;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
// Pretty Print
|
|
607
|
+
describe() {
|
|
608
|
+
let str = '';
|
|
609
|
+
for (let i = 0; i < this.execOrder.length; i++) {
|
|
610
|
+
const part = this.parts[this.execOrder[i]];
|
|
611
|
+
str += (0, string_1.colored)(`- Part ${part.i}\n`, 'lightpurple');
|
|
612
|
+
str += (0, string_1.colored)(part.many ? 'many ' : 'one ', 'green');
|
|
613
|
+
str += part.parent ? (0, string_1.colored)(`[child of ${part.parent.i}]\n`, 'brown') : '\n';
|
|
614
|
+
str += NQL_RuleTree.describe(part.union);
|
|
615
|
+
str += '\n';
|
|
616
|
+
}
|
|
617
|
+
return str;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
exports.NQL_CompiledQuery = NQL_CompiledQuery;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AnyModule } from "../../../../engine/module";
|
|
2
|
+
import { NQL_CompiledQuery } from './nql_compiler';
|
|
3
|
+
import { AnyTrxNode } from "../../../../engine/transaction/trx_node";
|
|
4
|
+
import { NQL_Part } from './nql.schema';
|
|
5
|
+
type Obj = Record<string, any>;
|
|
6
|
+
type Objs = Record<string, Obj>;
|
|
7
|
+
export declare abstract class NQLRunner {
|
|
8
|
+
abstract run(trx: AnyTrxNode, part: NQL_Part, params: Record<string, any>): Promise<Objs>;
|
|
9
|
+
}
|
|
10
|
+
export declare class NQL_Engine {
|
|
11
|
+
private module;
|
|
12
|
+
private runners;
|
|
13
|
+
constructor(module: AnyModule);
|
|
14
|
+
run(trx: AnyTrxNode, query: NQL_CompiledQuery, params?: Record<string, any>): Promise<Obj[]>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NQL_Engine = exports.NQLRunner = void 0;
|
|
4
|
+
const bucket_1 = require("../bucket");
|
|
5
|
+
class NQLRunner {
|
|
6
|
+
}
|
|
7
|
+
exports.NQLRunner = NQLRunner;
|
|
8
|
+
class NQL_Engine {
|
|
9
|
+
constructor(module) {
|
|
10
|
+
this.module = module;
|
|
11
|
+
this.runners = {};
|
|
12
|
+
for (const b in module.buckets) {
|
|
13
|
+
const bucket = module.buckets[b];
|
|
14
|
+
const meta = bucket_1.Bucket.getQueryMeta(bucket);
|
|
15
|
+
if (!(meta.scope in this.runners)) {
|
|
16
|
+
this.runners[meta.scope] = bucket_1.Bucket.getQueryRunner(bucket);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async run(trx, query, params = {}) {
|
|
21
|
+
let data = [];
|
|
22
|
+
for (let i = 0; i < query.execOrder.length; i++) {
|
|
23
|
+
const part_i = query.execOrder[i];
|
|
24
|
+
const part = query.parts[part_i];
|
|
25
|
+
// Run part
|
|
26
|
+
const runner = this.runners[part.union.meta.scope];
|
|
27
|
+
const out = await runner.run(trx, part, params);
|
|
28
|
+
data = Object.values(out);
|
|
29
|
+
// Part failed, return
|
|
30
|
+
// Failure here is only when a single value is expected,
|
|
31
|
+
if (!part.many) {
|
|
32
|
+
if (data.length === 0) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Fill part params
|
|
37
|
+
params[`%__${part_i}__%`] = part.many ? data : data[0];
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.NQL_Engine = NQL_Engine;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { $BucketView, $BucketViews } from './bucket_view.schema';
|
|
2
|
+
import { $BucketModel } from '../model/bucket_model.schema';
|
|
3
|
+
import { $BucketGraph } from '../graph/bucket_graph.schema';
|
|
4
|
+
import { BucketViewFieldBuilderTree, BucketViewFieldFactory } from './bucket_view_field.builder';
|
|
5
|
+
import { $Bucket } from '../bucket.schema';
|
|
6
|
+
import { $Module, $Space } from "../../..";
|
|
7
|
+
export declare class BucketViewBuilder<Space extends $Space, Module extends $Module, Bucket extends $Bucket> {
|
|
8
|
+
private name;
|
|
9
|
+
private _fields;
|
|
10
|
+
constructor(name: string);
|
|
11
|
+
fields($: BucketViewDef<Space, Module, Bucket>): this;
|
|
12
|
+
static build(builder: BucketViewBuilder<any, any, any>, model: $BucketModel, graph: $BucketGraph, views: $BucketViews): $BucketView;
|
|
13
|
+
}
|
|
14
|
+
export type BucketViewDef<Space extends $Space, Module extends $Module, Bucket extends $Bucket> = ($: BucketViewFieldFactory<Space, Module, Bucket>) => BucketViewFieldBuilderTree;
|