nesoi 3.0.9 → 3.0.10

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.
Files changed (83) hide show
  1. package/lib/compiler/apps/monolyth/monolyth_compiler.d.ts +1 -1
  2. package/lib/compiler/apps/monolyth/monolyth_compiler.js +7 -7
  3. package/lib/elements/blocks/machine/machine.builder.js +12 -1
  4. package/lib/elements/blocks/machine/machine.schema.d.ts +2 -1
  5. package/lib/elements/blocks/machine/machine.schema.js +2 -1
  6. package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +3 -1
  7. package/lib/elements/edge/controller/adapters/controller_adapter.js +2 -1
  8. package/lib/elements/edge/controller/controller.config.d.ts +3 -2
  9. package/lib/elements/edge/controller/controller.d.ts +3 -3
  10. package/lib/elements/edge/controller/controller.js +3 -3
  11. package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +2 -1
  12. package/lib/elements/entities/bucket/bucket.config.d.ts +3 -3
  13. package/lib/elements/entities/bucket/bucket.d.ts +3 -2
  14. package/lib/elements/entities/bucket/bucket.js +4 -4
  15. package/lib/engine/apps/app.config.d.ts +12 -11
  16. package/lib/engine/apps/app.d.ts +11 -22
  17. package/lib/engine/apps/app.js +9 -9
  18. package/lib/engine/apps/inline.app.d.ts +9 -8
  19. package/lib/engine/apps/inline.app.js +24 -24
  20. package/lib/engine/apps/monolyth/monolyth.app.d.ts +5 -5
  21. package/lib/engine/apps/monolyth/monolyth.app.js +6 -6
  22. package/lib/engine/apps/service.d.ts +30 -0
  23. package/lib/engine/apps/service.js +15 -0
  24. package/lib/engine/auth/authn.d.ts +10 -1
  25. package/lib/engine/auth/zero.authn_provider.d.ts +7 -3
  26. package/lib/engine/auth/zero.authn_provider.js +9 -2
  27. package/lib/engine/cli/cli.d.ts +2 -2
  28. package/lib/engine/cli/cli.js +1 -1
  29. package/lib/engine/cli/ui.js +1 -1
  30. package/lib/engine/daemon.d.ts +11 -11
  31. package/lib/engine/daemon.js +18 -18
  32. package/lib/engine/dependency.d.ts +2 -1
  33. package/lib/engine/dependency.js +18 -0
  34. package/lib/engine/module.d.ts +6 -4
  35. package/lib/engine/module.js +25 -10
  36. package/lib/engine/transaction/nodes/bucket.trx_node.js +1 -2
  37. package/lib/engine/transaction/nodes/bucket_query.trx_node.js +5 -10
  38. package/lib/engine/transaction/nodes/job.trx_node.js +2 -4
  39. package/lib/engine/transaction/nodes/machine.trx_node.js +2 -4
  40. package/lib/engine/transaction/nodes/queue.trx_node.js +1 -2
  41. package/lib/engine/transaction/nodes/resource.trx_node.js +2 -4
  42. package/lib/engine/transaction/trx.d.ts +6 -4
  43. package/lib/engine/transaction/trx.js +2 -1
  44. package/lib/engine/transaction/trx_engine.config.d.ts +2 -2
  45. package/lib/engine/transaction/trx_engine.d.ts +4 -3
  46. package/lib/engine/transaction/trx_engine.js +20 -17
  47. package/lib/engine/transaction/trx_node.d.ts +4 -2
  48. package/lib/engine/transaction/trx_node.js +13 -1
  49. package/lib/engine/tree.js +6 -17
  50. package/lib/schema.d.ts +1 -1
  51. package/package.json +2 -3
  52. package/tools/joaquin/job.js +2 -2
  53. package/tools/joaquin/message.js +2 -2
  54. package/tools/joaquin/mock.d.ts +6 -6
  55. package/tsconfig.build.tsbuildinfo +1 -1
  56. package/lib/adapters/postgres/src/migrator/csv.d.ts +0 -7
  57. package/lib/adapters/postgres/src/migrator/csv.js +0 -72
  58. package/lib/adapters/postgres/src/migrator/database.d.ts +0 -34
  59. package/lib/adapters/postgres/src/migrator/database.js +0 -88
  60. package/lib/adapters/postgres/src/migrator/generator/generator.d.ts +0 -22
  61. package/lib/adapters/postgres/src/migrator/generator/generator.js +0 -326
  62. package/lib/adapters/postgres/src/migrator/generator/migration.d.ts +0 -66
  63. package/lib/adapters/postgres/src/migrator/generator/migration.js +0 -249
  64. package/lib/adapters/postgres/src/migrator/generator/provider.d.ts +0 -19
  65. package/lib/adapters/postgres/src/migrator/generator/provider.js +0 -74
  66. package/lib/adapters/postgres/src/migrator/index.d.ts +0 -47
  67. package/lib/adapters/postgres/src/migrator/index.js +0 -22
  68. package/lib/adapters/postgres/src/migrator/runner/runner.d.ts +0 -17
  69. package/lib/adapters/postgres/src/migrator/runner/runner.js +0 -249
  70. package/lib/adapters/postgres/src/migrator/runner/status.d.ts +0 -17
  71. package/lib/adapters/postgres/src/migrator/runner/status.js +0 -55
  72. package/lib/adapters/postgres/src/postgres.bucket_adapter.d.ts +0 -42
  73. package/lib/adapters/postgres/src/postgres.bucket_adapter.js +0 -294
  74. package/lib/adapters/postgres/src/postgres.cli.d.ts +0 -76
  75. package/lib/adapters/postgres/src/postgres.cli.js +0 -207
  76. package/lib/adapters/postgres/src/postgres.config.d.ts +0 -5
  77. package/lib/adapters/postgres/src/postgres.config.js +0 -2
  78. package/lib/adapters/postgres/src/postgres.nql.d.ts +0 -16
  79. package/lib/adapters/postgres/src/postgres.nql.js +0 -123
  80. package/lib/adapters/postgres/src/postgres.provider.d.ts +0 -18
  81. package/lib/adapters/postgres/src/postgres.provider.js +0 -77
  82. package/lib/adapters/postgres/test/postgres.bucket_adapter.test.d.ts +0 -1
  83. package/lib/adapters/postgres/test/postgres.bucket_adapter.test.js +0 -210
@@ -18,7 +18,7 @@ export declare class MonolythCompiler {
18
18
  };
19
19
  constructor(compiler: Compiler, appPath: string, config?: MonolythCompilerConfig);
20
20
  run(): Promise<void>;
21
- mergeProviderPaths(app: AnyApp): void;
21
+ mergeServicePaths(app: AnyApp): void;
22
22
  expandLibPaths(): void;
23
23
  static scanAll(dir: string): Promise<MonolythApp<any, any, Record<string, any>>[] | undefined>;
24
24
  }
@@ -64,7 +64,7 @@ class MonolythCompiler {
64
64
  const appFile = space_1.Space.path(this.compiler.space, this.appPath);
65
65
  const app = (await Promise.resolve(`${appFile}`).then(s => __importStar(require(s)))).default;
66
66
  this.config = Object.assign({}, app_1.App.getInfo(app).config?.compiler || {}, this.config);
67
- this.mergeProviderPaths(app);
67
+ this.mergeServicePaths(app);
68
68
  this.expandLibPaths();
69
69
  try {
70
70
  await new _1_mkdir_stage_1.MkdirStage(this, app).run();
@@ -79,15 +79,15 @@ class MonolythCompiler {
79
79
  process.exit();
80
80
  }
81
81
  }
82
- mergeProviderPaths(app) {
82
+ mergeServicePaths(app) {
83
83
  var _a;
84
- const providers = app_1.App.getProviders(app);
85
- for (const name in providers) {
86
- const provider = providers[name];
87
- if (!provider.libPaths)
84
+ const services = app_1.App.getServices(app);
85
+ for (const name in services) {
86
+ const service = services[name];
87
+ if (!service.libPaths)
88
88
  continue;
89
89
  (_a = this.config).libPaths ?? (_a.libPaths = []);
90
- this.config.libPaths.push(...provider.libPaths);
90
+ this.config.libPaths.push(...service.libPaths);
91
91
  }
92
92
  }
93
93
  expandLibPaths() {
@@ -86,7 +86,18 @@ class MachineBuilder extends block_builder_1.BlockBuilder {
86
86
  const input = Object.values(states)
87
87
  .map(state => state.input)
88
88
  .flat(1);
89
- node.schema = new machine_schema_1.$Machine(node.builder.module, node.builder.name, node.builder._alias || node.builder.name, node.builder._authn, input, node.builder._buckets, node.builder._stateField || 'state', states, transitions, node.builder._stateAliasField, node.builder._logger);
89
+ const jobs = [];
90
+ Object.values(states).forEach(state => {
91
+ jobs.push(...Object.values(state.jobs));
92
+ });
93
+ Object.values(transitions.from).forEach(stateTransitions => {
94
+ Object.values(stateTransitions).forEach(transitionList => {
95
+ transitionList.forEach(trans => {
96
+ jobs.push(...trans.jobs);
97
+ });
98
+ });
99
+ });
100
+ node.schema = new machine_schema_1.$Machine(node.builder.module, node.builder.name, node.builder._alias || node.builder.name, node.builder._authn, input, node.builder._buckets, jobs, node.builder._stateField || 'state', states, transitions, node.builder._stateAliasField, node.builder._logger);
90
101
  // Configure state jobs with proper input, based on transition targets
91
102
  const inlineJobsConfig = {};
92
103
  Object.values(states).forEach(state => {
@@ -75,6 +75,7 @@ export declare class $Machine extends $Block {
75
75
  authn: string[];
76
76
  input: $Dependency[];
77
77
  buckets: $Dependency[];
78
+ jobs: $Dependency[];
78
79
  stateField: string;
79
80
  states: $MachineStates;
80
81
  transitions: $MachineTransitions;
@@ -82,7 +83,7 @@ export declare class $Machine extends $Block {
82
83
  logger?: $MachineLogFn<any> | undefined;
83
84
  $t: "machine";
84
85
  '#data': unknown;
85
- constructor(module: string, name: string, alias: string, authn: string[], input: $Dependency[], buckets: $Dependency[], stateField: string, states: $MachineStates, transitions: $MachineTransitions, stateAliasField?: string | undefined, logger?: $MachineLogFn<any> | undefined);
86
+ constructor(module: string, name: string, alias: string, authn: string[], input: $Dependency[], buckets: $Dependency[], jobs: $Dependency[], stateField: string, states: $MachineStates, transitions: $MachineTransitions, stateAliasField?: string | undefined, logger?: $MachineLogFn<any> | undefined);
86
87
  }
87
88
  /**
88
89
  * @category Schemas
@@ -49,7 +49,7 @@ exports.$MachineState = $MachineState;
49
49
  * @subcategory Block
50
50
  */
51
51
  class $Machine extends block_schema_1.$Block {
52
- constructor(module, name, alias, authn, input, buckets, stateField, states, transitions, stateAliasField, logger) {
52
+ constructor(module, name, alias, authn, input, buckets, jobs, stateField, states, transitions, stateAliasField, logger) {
53
53
  super(module, name, alias, authn, input, {});
54
54
  this.module = module;
55
55
  this.name = name;
@@ -57,6 +57,7 @@ class $Machine extends block_schema_1.$Block {
57
57
  this.authn = authn;
58
58
  this.input = input;
59
59
  this.buckets = buckets;
60
+ this.jobs = jobs;
60
61
  this.stateField = stateField;
61
62
  this.states = states;
62
63
  this.transitions = transitions;
@@ -2,15 +2,17 @@ import { AnyTrxNode } from "../../../../engine/transaction/trx_node";
2
2
  import { $Controller, $ControllerDomain, $ControllerEndpoint, $ControllerGroup } from '../controller.schema';
3
3
  import { AnyDaemon } from "../../../../engine/daemon";
4
4
  import { AuthnRequest } from "../../../../engine/auth/authn";
5
+ import { $Module } from "../../..";
5
6
  export type ControllerEndpointPath = ($ControllerDomain | $ControllerGroup | $ControllerEndpoint)[];
6
7
  /**
7
8
  * @category Adapters
8
9
  * @subcategory Edge
9
10
  */
10
11
  export declare abstract class ControllerAdapter {
12
+ protected module: $Module;
11
13
  protected schema: $Controller;
12
14
  protected daemon?: AnyDaemon;
13
- constructor(schema: $Controller);
15
+ constructor(module: $Module, schema: $Controller);
14
16
  trx(fn: (trx: AnyTrxNode) => Promise<any>, authn?: AuthnRequest<any>): Promise<import("../../../../engine/transaction/trx").TrxStatus<any>>;
15
17
  bind(daemon: AnyDaemon): void;
16
18
  protected abstract makeEndpoint(path: string, schema: $ControllerEndpoint): void;
@@ -7,7 +7,8 @@ const log_1 = require("../../../../engine/util/log");
7
7
  * @subcategory Edge
8
8
  */
9
9
  class ControllerAdapter {
10
- constructor(schema) {
10
+ constructor(module, schema) {
11
+ this.module = module;
11
12
  this.schema = schema;
12
13
  }
13
14
  async trx(fn, authn) {
@@ -1,6 +1,7 @@
1
+ import { $Module } from "../..";
1
2
  import { ControllerAdapter } from './adapters/controller_adapter';
2
3
  import { $Controller } from './controller.schema';
3
- export type ControllerConfig<B extends $Controller, Providers extends Record<string, any>> = {
4
+ export type ControllerConfig<M extends $Module, B extends $Controller, Services extends Record<string, any>> = {
4
5
  /** Adapter used by this Controller to communicate with a data source */
5
- adapter?: (schema: B, providers: Providers) => ControllerAdapter;
6
+ adapter?: (module: M, schema: B, services: Services) => ControllerAdapter;
6
7
  };
@@ -18,10 +18,10 @@ export declare class ControllerEndpoint<$ extends $ControllerEndpoint> {
18
18
  }
19
19
  export declare class Controller<S extends $Space, M extends $Module, $ extends $Controller> {
20
20
  schema: $;
21
- config?: ControllerConfig<$, any> | undefined;
22
- providers: Record<string, any>;
21
+ config?: ControllerConfig<M, $, any> | undefined;
22
+ services: Record<string, any>;
23
23
  adapter: ControllerAdapter;
24
- constructor(module: Module<S, M>, schema: $, config?: ControllerConfig<$, any> | undefined, providers?: Record<string, any>);
24
+ constructor(module: Module<S, M>, schema: $, config?: ControllerConfig<M, $, any> | undefined, services?: Record<string, any>);
25
25
  bind(daemon: AnyDaemon): void;
26
26
  }
27
27
  export type AnyController = Controller<any, any, any>;
@@ -34,11 +34,11 @@ class ControllerEndpoint {
34
34
  }
35
35
  exports.ControllerEndpoint = ControllerEndpoint;
36
36
  class Controller {
37
- constructor(module, schema, config, providers = {}) {
37
+ constructor(module, schema, config, services = {}) {
38
38
  this.schema = schema;
39
39
  this.config = config;
40
- this.providers = providers;
41
- this.adapter = config?.adapter?.(schema, providers) || new cli_controller_adapter_1.CLIControllerAdapter(schema);
40
+ this.services = services;
41
+ this.adapter = config?.adapter?.(module.schema, schema, services) || new cli_controller_adapter_1.CLIControllerAdapter(module.schema, schema);
42
42
  }
43
43
  bind(daemon) {
44
44
  this.adapter.bind(daemon);
@@ -28,7 +28,8 @@ export declare abstract class BucketAdapter<Obj extends NesoiObj> {
28
28
  */
29
29
  protected abstract deleteEverything(trx: AnyTrxNode): Promise<void>;
30
30
  /**
31
- * Return one entity by ID
31
+ * Return one entity by ID.
32
+ * - This method MUST NOT throw an exception if not found. The exception is thrown by Nesoi.
32
33
  */
33
34
  abstract get(trx: AnyTrxNode, id: Obj['id']): Promise<undefined | Obj>;
34
35
  /**
@@ -2,11 +2,11 @@ import { $Module } from "../..";
2
2
  import { BucketAdapter } from './adapters/bucket_adapter';
3
3
  import { $Bucket } from './bucket.schema';
4
4
  import { DriveAdapter } from '../drive/drive_adapter';
5
- export type BucketConfig<M extends $Module, B extends $Bucket, Providers extends Record<string, any>> = {
5
+ export type BucketConfig<M extends $Module, B extends $Bucket, Services extends Record<string, any>> = {
6
6
  /** Adapter used by this bucket to communicate with a data source */
7
- adapter?: (schema: B, providers: Providers) => BucketAdapter<B['#data']>;
7
+ adapter?: (schema: B, services: Services) => BucketAdapter<B['#data']>;
8
8
  /** Drive Adapter used by this bucket to write/read files */
9
- drive?: (schema: B, providers: Providers) => DriveAdapter;
9
+ drive?: (schema: B, services: Services) => DriveAdapter;
10
10
  /** Settings for the app cache of this bucket */
11
11
  cache?: {
12
12
  /** Inner adapter used by the cache to manage cache entry data */
@@ -10,6 +10,7 @@ import { CreateObj, PatchObj, PutObj } from './bucket.types';
10
10
  import { NQL_Result } from './query/nql_engine';
11
11
  import { $BucketModelFields } from './model/bucket_model.schema';
12
12
  import { DriveAdapter } from '../drive/drive_adapter';
13
+ import { IService } from "../../../engine/apps/service";
13
14
  /**
14
15
  * **This should only be used inside a `#composition` of a bucket `create`** to refer to the parent id, which doesn't exist yet.
15
16
  *
@@ -27,13 +28,13 @@ export declare const $id: string | number;
27
28
  export declare class Bucket<M extends $Module, $ extends $Bucket> {
28
29
  schema: $;
29
30
  private config?;
30
- providers: Record<string, any>;
31
+ services: Record<string, IService>;
31
32
  adapter: BucketAdapter<$['#data']>;
32
33
  private cache?;
33
34
  graph: BucketGraph<M, $>;
34
35
  private views;
35
36
  drive?: DriveAdapter;
36
- constructor(schema: $, config?: BucketConfig<any, any, any> | undefined, providers?: Record<string, any>);
37
+ constructor(schema: $, config?: BucketConfig<any, any, any> | undefined, services?: Record<string, IService>);
37
38
  getQueryMeta(): {
38
39
  bucket: $;
39
40
  scope: string;
@@ -27,12 +27,12 @@ exports.$id = Symbol('FUTURE ID OF CREATE');
27
27
  * @subcategory Entity
28
28
  * */
29
29
  class Bucket {
30
- constructor(schema, config, providers = {}) {
30
+ constructor(schema, config, services = {}) {
31
31
  this.schema = schema;
32
32
  this.config = config;
33
- this.providers = providers;
33
+ this.services = services;
34
34
  // Config
35
- this.adapter = this.config?.adapter?.(schema, providers) || new memory_bucket_adapter_1.MemoryBucketAdapter(schema, {});
35
+ this.adapter = this.config?.adapter?.(schema, services) || new memory_bucket_adapter_1.MemoryBucketAdapter(schema, {});
36
36
  // Graph
37
37
  this.graph = new bucket_graph_1.BucketGraph(this);
38
38
  // Views
@@ -47,7 +47,7 @@ class Bucket {
47
47
  }
48
48
  // Drive
49
49
  if (this.config?.drive) {
50
- this.drive = this.config.drive(schema, providers);
50
+ this.drive = this.config.drive(schema, services);
51
51
  }
52
52
  }
53
53
  // Getters
@@ -5,6 +5,7 @@ import { ControllerConfig } from "../../elements/edge/controller/controller.conf
5
5
  import { TrxEngineConfig } from '../transaction/trx_engine.config';
6
6
  import { CompilerConfig } from "../../compiler/compiler";
7
7
  import { App } from './app';
8
+ import { IService } from './service';
8
9
  import { CLIConfig } from '../cli/cli';
9
10
  import { BucketAdapter } from "../../elements/entities/bucket/adapters/bucket_adapter";
10
11
  import { TrashObj } from '../data/trash';
@@ -27,9 +28,9 @@ export type AppI18nConfig = {
27
28
  export type AppAuthnConfig<S extends $Space> = {
28
29
  [K in keyof S['authnUsers']]: () => AuthnProvider<S['authnUsers'][K]>;
29
30
  };
30
- export type AppBucketConfig<S extends $Space, Modules extends ModuleName<S>, Providers extends Record<string, any>> = Partial<{
31
+ export type AppBucketConfig<S extends $Space, Modules extends ModuleName<S>, Services extends Record<string, IService>> = Partial<{
31
32
  [M in (Modules & keyof S['modules'])]: Partial<{
32
- [K in keyof S['modules'][M]['buckets']]: BucketConfig<S['modules'][M], S['modules'][M]['buckets'][K], Providers>;
33
+ [K in keyof S['modules'][M]['buckets']]: BucketConfig<S['modules'][M], S['modules'][M]['buckets'][K], Services>;
33
34
  }>;
34
35
  }>;
35
36
  export type AppTrashConfig = {
@@ -37,13 +38,13 @@ export type AppTrashConfig = {
37
38
  '#data': TrashObj;
38
39
  }>) => BucketAdapter<TrashObj>;
39
40
  };
40
- export type AppControllerConfig<S extends $Space, Modules extends ModuleName<S>, Providers extends Record<string, any>> = Partial<{
41
+ export type AppControllerConfig<S extends $Space, Modules extends ModuleName<S>, Services extends Record<string, IService>> = Partial<{
41
42
  [M in (Modules & keyof S['modules'])]: Partial<{
42
- [K in keyof S['modules'][M]['controllers']]: ControllerConfig<S['modules'][M]['controllers'][K], Providers>;
43
+ [K in keyof S['modules'][M]['controllers']]: ControllerConfig<S['modules'][M], S['modules'][M]['controllers'][K], Services>;
43
44
  }>;
44
45
  }>;
45
- export type AppTrxEngineConfig<S extends $Space, Modules extends ModuleName<S>, Providers extends Record<string, any>> = Partial<{
46
- [M in (Modules & keyof S['modules'])]: TrxEngineConfig<S, S['modules'][M], any, Providers>;
46
+ export type AppTrxEngineConfig<S extends $Space, Modules extends ModuleName<S>, Services extends Record<string, IService>> = Partial<{
47
+ [M in (Modules & keyof S['modules'])]: TrxEngineConfig<S, S['modules'][M], any, Services>;
47
48
  }>;
48
49
  export type AppAuditConfig = {
49
50
  adapter: ($: Overlay<$Bucket, {
@@ -57,17 +58,17 @@ export type AppAuditConfig = {
57
58
  /**
58
59
  * @category App
59
60
  */
60
- export declare class AppConfigFactory<S extends $Space, Modules extends string = ModuleName<S> & string, Providers extends Record<string, any> = Record<string, any>, _App = App<S, Modules, Providers>> {
61
+ export declare class AppConfigFactory<S extends $Space, Modules extends string = ModuleName<S> & string, Services extends Record<string, any> = Record<string, any>, _App = App<S, Modules, Services>> {
61
62
  private app;
62
63
  private config;
63
64
  constructor(app: _App);
64
65
  i18n(config: AppI18nConfig): _App;
65
66
  authn(config: AppAuthnConfig<S>): _App;
66
- buckets(config: AppBucketConfig<S, Modules, Providers>): _App;
67
+ buckets(config: AppBucketConfig<S, Modules, Services>): _App;
67
68
  trash(config: AppTrashConfig): _App;
68
- controllers(config: AppControllerConfig<S, Modules, Providers>): _App;
69
+ controllers(config: AppControllerConfig<S, Modules, Services>): _App;
69
70
  audit(config: AppI18nConfig): _App;
70
71
  compiler(config: CompilerConfig): _App;
71
- cli(config: CLIConfig<Providers>): _App;
72
- trx(config: AppTrxEngineConfig<S, Modules, Providers>): _App;
72
+ cli(config: CLIConfig<Services>): _App;
73
+ trx(config: AppTrxEngineConfig<S, Modules, Services>): _App;
73
74
  }
@@ -3,27 +3,16 @@ import { AnyBuilder, AnyModule } from '../module';
3
3
  import { Space } from '../space';
4
4
  import { Daemon } from '../daemon';
5
5
  import { AnyAppConfig, AppConfigFactory } from './app.config';
6
- /**
7
- * Provider
8
- */
9
- export type AppProvider<out Name, T> = {
10
- name: Name;
11
- up: ($: {
12
- modules: Record<string, AnyModule>;
13
- }) => T;
14
- down: (provider: NoInfer<T>) => any;
15
- libPaths?: string[];
16
- };
17
- export type AnyAppProvider = AppProvider<any, any>;
6
+ import { IService } from './service';
18
7
  /**
19
8
  * @category App
20
9
  */
21
- export declare abstract class App<S extends $Space, Modules extends string = ModuleName<S> & string, Providers extends Record<string, any> = Record<string, any>> {
10
+ export declare abstract class App<S extends $Space, Modules extends string = ModuleName<S> & string, Services extends Record<string, any> = Record<string, any>> {
22
11
  name: string;
23
12
  protected _config: AnyAppConfig;
24
13
  protected _spaceModuleNames: ModuleName<S>[];
25
14
  protected _injectedModules: AnyModule[];
26
- protected _providers: Record<string, AnyAppProvider>;
15
+ protected _services: Record<string, IService>;
27
16
  protected space?: Space<S>;
28
17
  protected builders?: AnyBuilder[];
29
18
  constructor(name: string, boot?: {
@@ -37,7 +26,7 @@ export declare abstract class App<S extends $Space, Modules extends string = Mod
37
26
  * This can be run without await before the daemon,
38
27
  * to preload the module in background.
39
28
  */
40
- abstract boot(): App<S, Modules, Providers>;
29
+ abstract boot(): App<S, Modules, Services>;
41
30
  /**
42
31
  * Spawn a daemon for this app.
43
32
  */
@@ -48,7 +37,7 @@ export declare abstract class App<S extends $Space, Modules extends string = Mod
48
37
  * ⚠ This has no effect on apps without a `Space`, such as `InlineApp`.
49
38
  * @param modules A list of names of modules from the current `Space`.
50
39
  */
51
- modules<M extends ModuleName<S>>(modules: M[]): App<S, M & Modules, Providers>;
40
+ modules<M extends ModuleName<S>>(modules: M[]): App<S, M & Modules, Services>;
52
41
  /**
53
42
  * Injects pre-built modules into this App.
54
43
  * These will be included on the Daemon once it starts.
@@ -57,16 +46,16 @@ export declare abstract class App<S extends $Space, Modules extends string = Mod
57
46
  */
58
47
  inject(modules: AnyModule[]): this;
59
48
  /**
60
- * Declares a `Provider` with a given name.
49
+ * Declares a `Service`.
61
50
  *
62
- * Providers are started and ended along with the daemon, and can be used on the App
51
+ * Services are started and ended along with the daemon, and can be used on the App
63
52
  * config to share globals between adapters and other methods.
64
- * @param $ `AppProvider` with an `up` and `down` method to create/destroy the provider.
53
+ * @param $ object with an `up` and `down` method to create/destroy the service
65
54
  */
66
- provider<Name extends string, T>($: AppProvider<Name, T>): App<S, Modules, Providers & { [K in Name]: T; }>;
67
- get config(): AppConfigFactory<S, Modules, Providers>;
55
+ service<T extends IService>($: T): App<S, Modules, Services & { [K in T["name"]]: T; }>;
56
+ get config(): AppConfigFactory<S, Modules, Services>;
68
57
  protected makeModules(): Record<string, AnyModule>;
69
- static getProviders(app: AnyApp): Record<string, AnyAppProvider>;
58
+ static getServices(app: AnyApp): Record<string, IService>;
70
59
  static getInfo(app: AnyApp): {
71
60
  spaceModules: (string | number | symbol)[];
72
61
  config: AnyAppConfig;
@@ -21,10 +21,10 @@ class App {
21
21
  // running the daemon. These will be included on the daemon
22
22
  // once it's run.
23
23
  this._injectedModules = [];
24
- // A list of providers, which are created and destroyed
24
+ // A list of services, which are created and destroyed
25
25
  // along with the daemon. These are internally available for
26
26
  // blocks - usually used by adapters.
27
- this._providers = {};
27
+ this._services = {};
28
28
  if (boot) {
29
29
  if ('space' in boot) {
30
30
  this.space = boot.space;
@@ -56,14 +56,14 @@ class App {
56
56
  return this;
57
57
  }
58
58
  /**
59
- * Declares a `Provider` with a given name.
59
+ * Declares a `Service`.
60
60
  *
61
- * Providers are started and ended along with the daemon, and can be used on the App
61
+ * Services are started and ended along with the daemon, and can be used on the App
62
62
  * config to share globals between adapters and other methods.
63
- * @param $ `AppProvider` with an `up` and `down` method to create/destroy the provider.
63
+ * @param $ object with an `up` and `down` method to create/destroy the service
64
64
  */
65
- provider($) {
66
- this._providers[$.name] = $;
65
+ service($) {
66
+ this._services[$.name] = $;
67
67
  return this;
68
68
  }
69
69
  //
@@ -94,8 +94,8 @@ class App {
94
94
  return modules;
95
95
  }
96
96
  //
97
- static getProviders(app) {
98
- return app._providers;
97
+ static getServices(app) {
98
+ return app._services;
99
99
  }
100
100
  static getInfo(app) {
101
101
  return {
@@ -1,5 +1,6 @@
1
1
  import { $Module, $Space, ModuleName } from "../../schema";
2
- import { App, AppProvider } from './app';
2
+ import { App } from './app';
3
+ import { IService } from './service';
3
4
  import { AnyTrxEngine } from '../transaction/trx_engine';
4
5
  import { AnyBuilder, AnyModule, Module } from '../module';
5
6
  import { AnyDaemon, Daemon } from '../daemon';
@@ -7,28 +8,28 @@ import { AppConfigFactory } from './app.config';
7
8
  /**
8
9
  * @category App
9
10
  */
10
- export declare class InlineApp<S extends $Space, ModuleNames extends string = ModuleName<S> & string, Providers extends Record<string, any> = Record<string, any>> extends App<S, ModuleNames, Providers> {
11
+ export declare class InlineApp<S extends $Space, ModuleNames extends string = ModuleName<S> & string, Services extends Record<string, any> = Record<string, any>> extends App<S, ModuleNames, Services> {
11
12
  protected _daemon?: Daemon<S, ModuleNames>;
12
13
  protected _modules: Record<string, AnyModule>;
13
14
  private packageJson?;
14
15
  protected bootPromise?: Promise<void>;
15
16
  constructor(name: string, builders: AnyBuilder[]);
16
- boot(): InlineApp<S, ModuleNames, Providers>;
17
+ boot(): InlineApp<S, ModuleNames, Services>;
17
18
  /**
18
19
  * Treeshake and build modules declared for this application.
19
20
  */
20
21
  protected build(): Promise<void>;
21
22
  /**
22
- * Build the application, start providers and trx engines.
23
+ * Build the application, start services and trx engines.
23
24
  * Returns references to start a daemon.
24
25
  */
25
26
  protected make(): Promise<{
26
27
  modules: Record<string, AnyModule>;
27
- providers: Record<string, any>;
28
+ services: Record<string, any>;
28
29
  trxEngines: Record<ModuleNames, AnyTrxEngine>;
29
30
  }>;
30
31
  daemon(): Promise<Daemon<S, ModuleNames>>;
31
- protected makeDaemon(trxEngines: Record<ModuleNames, AnyTrxEngine>, providers: Record<string, any>): AnyDaemon;
32
+ protected makeDaemon(trxEngines: Record<ModuleNames, AnyTrxEngine>, services: Record<string, IService>): AnyDaemon;
32
33
  package(_package: Record<string, any>): this;
33
34
  /**
34
35
  * This method injects elements flagged as externals by referencing them
@@ -38,8 +39,8 @@ export declare class InlineApp<S extends $Space, ModuleNames extends string = Mo
38
39
  */
39
40
  protected linkExternals(modules: Record<string, Module<S, $Module>>): void;
40
41
  modules<M extends ModuleName<S>>(modules: M[]): InlineApp<S, M & ModuleNames>;
41
- provider<Name extends string, T>($: AppProvider<Name, T>): InlineApp<S, ModuleNames, Providers & { [K in Name]: T; }>;
42
- get config(): AppConfigFactory<S, ModuleNames, Providers, typeof this>;
42
+ service<T extends IService>($: T): InlineApp<S, ModuleNames, Services & { [K in T["name"]]: T; }>;
43
+ get config(): AppConfigFactory<S, ModuleNames, Services, typeof this>;
43
44
  static package(app: InlineApp<any, any>, scripts: Record<string, string>, dependencies: Record<string, string>): {
44
45
  name: string;
45
46
  version: string;
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.InlineDaemon = exports.InlineApp = void 0;
4
7
  const app_1 = require("./app");
@@ -7,6 +10,7 @@ const trx_engine_1 = require("../transaction/trx_engine");
7
10
  const tree_1 = require("../tree");
8
11
  const daemon_1 = require("../daemon");
9
12
  const app_config_1 = require("./app.config");
13
+ const promise_1 = __importDefault(require("../util/promise"));
10
14
  /**
11
15
  * @category App
12
16
  */
@@ -44,7 +48,7 @@ class InlineApp extends app_1.App {
44
48
  });
45
49
  }
46
50
  /**
47
- * Build the application, start providers and trx engines.
51
+ * Build the application, start services and trx engines.
48
52
  * Returns references to start a daemon.
49
53
  */
50
54
  async make() {
@@ -56,19 +60,19 @@ class InlineApp extends app_1.App {
56
60
  const mod = this._injectedModules[key];
57
61
  modules[mod.name] = mod;
58
62
  }
59
- const providers = {};
60
- for (const key in this._providers) {
61
- const provider = this._providers[key].up({
63
+ const services = {};
64
+ for (const key in this._services) {
65
+ const service = this._services[key];
66
+ await promise_1.default.solve(service.up({
62
67
  modules
63
- });
64
- provider.__down = this._providers[key].down;
65
- providers[key] = provider;
68
+ }));
69
+ services[key] = service;
66
70
  }
67
71
  log_1.Log.debug('app', this.name, 'Starting transaction engines');
68
72
  const trxEngines = {};
69
73
  for (const m in modules) {
70
74
  const module = modules[m];
71
- module.start(this, providers);
75
+ module.start(this, services);
72
76
  const trxConfig = this._config.trxEngine?.[m];
73
77
  const authn = {};
74
78
  for (const a in this._config?.authn || {}) {
@@ -77,13 +81,13 @@ class InlineApp extends app_1.App {
77
81
  authn[a] = prov;
78
82
  }
79
83
  }
80
- trxEngines[m] = new trx_engine_1.TrxEngine(`app:${this.name}`, module, authn, trxConfig, providers);
84
+ trxEngines[m] = new trx_engine_1.TrxEngine(`app:${this.name}`, module, authn, trxConfig, services);
81
85
  }
82
86
  log_1.Log.debug('app', this.name, 'Linking externals');
83
87
  this.linkExternals(modules);
84
88
  return {
85
89
  modules,
86
- providers,
90
+ services,
87
91
  trxEngines
88
92
  };
89
93
  }
@@ -93,7 +97,7 @@ class InlineApp extends app_1.App {
93
97
  }
94
98
  const app = await this.make();
95
99
  log_1.Log.debug('app', this.name, 'Spawning daemon');
96
- this._daemon = this.makeDaemon(app.trxEngines, app.providers);
100
+ this._daemon = this.makeDaemon(app.trxEngines, app.services);
97
101
  // Link daemon to modules
98
102
  for (const m in app.modules) {
99
103
  const module = app.modules[m];
@@ -101,8 +105,8 @@ class InlineApp extends app_1.App {
101
105
  }
102
106
  return this._daemon;
103
107
  }
104
- makeDaemon(trxEngines, providers) {
105
- return new InlineDaemon(this.name, trxEngines, providers, this._config);
108
+ makeDaemon(trxEngines, services) {
109
+ return new InlineDaemon(this.name, trxEngines, services, this._config);
106
110
  }
107
111
  package(_package) {
108
112
  this.packageJson = _package;
@@ -116,19 +120,15 @@ class InlineApp extends app_1.App {
116
120
  */
117
121
  linkExternals(modules) {
118
122
  Object.values(modules).forEach(module => {
123
+ module.injectDependencies(modules, {
124
+ buckets: Object.values(module.schema.externals.buckets),
125
+ jobs: Object.values(module.schema.externals.jobs),
126
+ machines: Object.values(module.schema.externals.machines),
127
+ });
119
128
  const buckets = module.schema.externals.buckets;
120
129
  Object.values(buckets).forEach(bucket => {
121
- module.buckets[bucket.refName] = modules[bucket.module].buckets[bucket.name];
122
130
  module.nql.linkExternal(modules[bucket.module].buckets[bucket.name]);
123
131
  });
124
- const jobs = module.schema.externals.jobs;
125
- Object.values(jobs).forEach(job => {
126
- module.jobs[job.refName] = modules[job.module].jobs[job.name];
127
- });
128
- const machines = module.schema.externals.machines;
129
- Object.values(machines).forEach(machine => {
130
- module.machines[machine.refName] = modules[machine.module].machines[machine.name];
131
- });
132
132
  });
133
133
  }
134
134
  // Type Builder Overrides
@@ -136,8 +136,8 @@ class InlineApp extends app_1.App {
136
136
  super.modules(modules);
137
137
  return this;
138
138
  }
139
- provider($) {
140
- super.provider($);
139
+ service($) {
140
+ super.service($);
141
141
  return this;
142
142
  }
143
143
  get config() {
@@ -1,5 +1,5 @@
1
1
  import { $Space, ModuleName } from "../../../schema";
2
- import { AppProvider } from '../app';
2
+ import { IService } from '../service';
3
3
  import { InlineApp } from './../inline.app';
4
4
  import { AnyTrxEngine } from '../../transaction/trx_engine';
5
5
  import { Space } from '../../space';
@@ -9,18 +9,18 @@ import { AppConfigFactory } from '../app.config';
9
9
  * @category App
10
10
  * @subcategory Monolyth
11
11
  */
12
- export declare class MonolythApp<S extends $Space, ModuleNames extends string = ModuleName<S> & string, Providers extends Record<string, any> = Record<string, any>> extends InlineApp<S, ModuleNames, Providers> {
12
+ export declare class MonolythApp<S extends $Space, ModuleNames extends string = ModuleName<S> & string, Services extends Record<string, any> = Record<string, any>> extends InlineApp<S, ModuleNames, Services> {
13
13
  private watcher?;
14
14
  constructor(name: string, space?: Space<S>);
15
15
  protected _packageJson?: Record<string, any>;
16
16
  daemon($?: {
17
17
  watch?: boolean;
18
18
  }): Promise<Daemon<S, ModuleNames>>;
19
- protected makeDaemon(trxEngines: Record<ModuleNames, AnyTrxEngine>, providers: Record<string, any>): MonolythDaemon<$Space, ModuleNames>;
19
+ protected makeDaemon(trxEngines: Record<ModuleNames, AnyTrxEngine>, services: Record<string, IService>): MonolythDaemon<$Space, ModuleNames>;
20
20
  remake(): Promise<void>;
21
21
  modules<M extends ModuleName<S>>(modules: M[]): MonolythApp<S, M & ModuleNames>;
22
- provider<Name extends string, T>($: AppProvider<Name, T>): MonolythApp<S, ModuleNames, Providers & { [K in Name]: T; }>;
23
- get config(): AppConfigFactory<S, ModuleNames, Providers, typeof this>;
22
+ service<T extends IService>($: T): MonolythApp<S, ModuleNames, Services & { [K in T["name"]]: T; }>;
23
+ get config(): AppConfigFactory<S, ModuleNames, Services, typeof this>;
24
24
  }
25
25
  /**
26
26
  * @category App