Skip to content

Commit

Permalink
Merge branch 'master-moleculer' into middlewares-d-ts
Browse files Browse the repository at this point in the history
# Conflicts:
#	index.d.ts
  • Loading branch information
0x0a0d committed Sep 24, 2023
2 parents a30bb3a + 4b64997 commit 9e8b7ee
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 9 deletions.
54 changes: 54 additions & 0 deletions dev/issue-1241.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const ServiceBroker = require("../src/service-broker");

const broker = new ServiceBroker({
middlewares: [
{
call(next) {
return (actionName, params, opts) => {
const p = next(actionName, params, opts);

const pp = p.then(res => {
return res;
});

pp.ctx = p.ctx;

return pp;
};
}
}
]
});

broker.createService({
name: "statusCodeTest",

actions: {
testNotFound: {
rest: "GET /testNotFound",
handler(ctx) {
ctx.meta.$statusCode = 404;
}
}
}
});

broker.createService({
name: "test",
actions: {
hello: {
async handler(ctx) {
await ctx.call("statusCodeTest.testNotFound");
this.logger.info("Context meta", ctx.meta);
}
}
}
});

broker.start().then(() => {
broker.repl();

broker.call("test.hello").then(res => {
console.log("Result:", res);
});
});
171 changes: 162 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { EventEmitter2 } from "eventemitter2";
import type { BinaryLike, CipherCCMTypes, CipherGCMTypes, CipherKey, CipherOCBTypes } from 'crypto'
import type { Worker } from "cluster";

declare namespace Moleculer {
/**
Expand Down Expand Up @@ -167,18 +168,18 @@ declare namespace Moleculer {
type TracingActionTags =
| TracingActionTagsFuncType
| {
params?: boolean | string[];
meta?: boolean | string[];
response?: boolean | string[];
};
params?: boolean | string[];
meta?: boolean | string[];
response?: boolean | string[];
};

type TracingEventTagsFuncType = (ctx: Context) => GenericObject;
type TracingEventTags =
| TracingEventTagsFuncType
| {
params?: boolean | string[];
meta?: boolean | string[];
};
params?: boolean | string[];
meta?: boolean | string[];
};

type TracingSpanNameOption = string | ((ctx: Context) => string);

Expand Down Expand Up @@ -1017,8 +1018,8 @@ declare namespace Moleculer {
internalServices?:
| boolean
| {
[key: string]: Partial<ServiceSchema>;
};
[key: string]: Partial<ServiceSchema>;
};
internalMiddlewares?: boolean;

dependencyInterval?: number;
Expand Down Expand Up @@ -1836,6 +1837,158 @@ declare namespace Moleculer {
function parseByteString(value: string): number;
}

/**
* Parsed CLI flags
*/
interface RunnerFlags {

/**
* Path to load configuration from a file
*/
config?: string;

/**
* Start REPL mode
*/
repl?: boolean;

/**
* Enable hot reload mode
*/
hot?: boolean;

/**
* Silent mode. No logger
*/
silent?: boolean;

/**
* Load .env file from current directory
*/
env?: boolean;

/**
* Load .env files by glob pattern
*/
envfile?: string;

/**
* Number of node instances to start in cluster mode
*/
instances?: number;

/**
* File mask for loading services
*/
mask?: string;

}

/**
* Moleculer Runner
*/
class Runner {
worker: Worker | null;
broker: ServiceBroker | null;

/**
* Watch folders for hot reload
*/
watchFolders: string[];

/**
* Parsed CLI flags
*/
flags: RunnerFlags | null;

/**
* Loaded configuration file
*/
configFile: Partial<BrokerOptions>;

/**
* Merged configuration
*/
config: Partial<BrokerOptions>;

/**
* Process command line arguments
*/
processFlags(args: string[]): void;

/**
* Load environment variables from '.env' file
*/
loadEnvFile(): void;

/**
* Load configuration file
*
* Try to load a configuration file in order to:
*
* - load file defined in MOLECULER_CONFIG env var
* - try to load file which is defined in CLI option with --config
* - try to load the `moleculer.config.js` file if exist in the cwd
* - try to load the `moleculer.config.json` file if exist in the cwd
*/
loadConfigFile(): Promise<void>;

/**
* Normalize a value from env variable
*/
normalizeEnvValue(value: string): string | number | boolean;

/**
* Overwrite config values from environment variables
*/
overwriteFromEnv(obj: any, prefix?: string): any;

/**
* Merge broker options from config file & env variables
*/
mergeOptions(): void;

/**
* Check if a path is a directory
*/
isDirectory(path: string): boolean;

/**
* Check if a path is a service file
*/
isServiceFile(path: string): boolean;

/**
* Load services from files or directories
*/
loadServices(): void;

/**
* Start cluster workers
*/
startWorkers(instances: number): void;

/**
* Load service from NPM module
*/
loadNpmModule(name: string): Service;

/**
* Start Moleculer broker
*/
startBroker(): Promise<ServiceBroker>;

/**
* Restart broker
*/
restartBroker(): Promise<ServiceBroker>;

/**
* Start runner
*/
start(args: string[]): Promise<void>;
}

/* @private */
interface MoleculerMiddlewares {
Transmit: {
Expand Down

0 comments on commit 9e8b7ee

Please sign in to comment.