Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
style: run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
lachrist committed Apr 9, 2021
1 parent 82ed52c commit fc573fd
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 126 deletions.
34 changes: 23 additions & 11 deletions lib/client/es2015/node/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const global_Error = Error;
const mapping = {
__proto__: null,
"1.0": ["http1.0", "1"],
"1.1": ["http1.1", "1"]
"2": ["http2-prior-knowledge", "2"],
"2.0": ["http2-prior-knowledge", "2"]
"3": ["http3", "3"]
1.1: ["http1.1", "1"],
2: ["http2-prior-knowledge", "2"],
"2.0": ["http2-prior-knowledge", "2"],
3: ["http3", "3"],
};

module.exports = (env) => {
Expand All @@ -20,28 +20,40 @@ module.exports = (env) => {
APPMAP_CHANNEL: "inline",
APPMAP_HTTP_VERSION: "1.1",
APPMAP_HOST: "localhost",
APPMAP_PORT: "8080"
}, env);
APPMAP_PORT: "8080",
},
env
);
if (env.APPMAP_CHANNEL[0] === "/") {
return require(env.APPMAP_CHANNEL);
}
if (env.APPMAP_CHANNEL === "inline") {
return require("../../../../dist/inline-channel.js")();
}
if (!(env.APPMAP_HTTP_VERSION in mapping)) {
throw new global_Error(`Invalid APPMAP_HTTP_VERSION environment variable, got: ${env.APPMAP_HTTP_VERSION}`);
throw new global_Error(
`Invalid APPMAP_HTTP_VERSION environment variable, got: ${env.APPMAP_HTTP_VERSION}`
);
}
const requestSync = require("./request/curl-sync.js")(mapping[env.APPMAP_HTTP_VERSION][0], env.APPMAP_HOST, env.APPMAP_PORT);
const requestSync = require("./request/curl-sync.js")(
mapping[env.APPMAP_HTTP_VERSION][0],
env.APPMAP_HOST,
env.APPMAP_PORT
);
let requestAsync;
if (env.APPMAP_CHANNEL === "http") {
requestAsync = require(`./request/http${mapping[env.APPMAP_HTTP_VERSION][1]}-async.js`)(env.APPMAP_HOST, env.APPMAP_PORT);
requestAsync = require(`./request/http${
mapping[env.APPMAP_HTTP_VERSION][1]
}-async.js`)(env.APPMAP_HOST, env.APPMAP_PORT);
} else if (env.APPMAP_CHANNEL === "fork") {
requestAsync = require(`./request/fork-async.js`)();
} else {
throw new global_Error(`Invalid APPMAP_CHANNEL environment variable, got: ${env.APPMAP_CHANNEL}`);
throw new global_Error(
`Invalid APPMAP_CHANNEL environment variable, got: ${env.APPMAP_CHANNEL}`
);
}
return {
requestSync,
requestAsync
requestAsync,
};
};
71 changes: 37 additions & 34 deletions lib/client/es2015/node/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@ const global_Object_assign = Object.assign;
const global_Error = Error;

module.exports = (process) => {
const { requestSync, requestAsync } = makeChannel(env);

const {requestSync, requestAsync} = makeChannel(env);

const {session, prefix} = requestSync(
{
name: "initialize",
init: {
env: process.env,
pid: process.pid,
engine: `node@${process.version}`,
feature: "TODO",
feature_group: "TODO",
labels: ["TODO"],
frameworks: ["TODO"],
recording: {
defined_class: "TODO",
method_id: "TODO",
}
}
}
);
const { session, prefix } = requestSync({
name: "initialize",
init: {
env: process.env,
pid: process.pid,
engine: `node@${process.version}`,
feature: "TODO",
feature_group: "TODO",
labels: ["TODO"],
frameworks: ["TODO"],
recording: {
defined_class: "TODO",
method_id: "TODO",
},
},
});

VirtualMachine.runInThisContext(
FileSystem.readFileSync(
Expand All @@ -40,7 +37,9 @@ module.exports = (process) => {
);

/* eslint-disable no-eval */
eval(`${prefix}_GLOBAL_EMIT = (event) => requestAsync({name:"emit", session, event}, null);`);
eval(
`${prefix}_GLOBAL_EMIT = (event) => requestAsync({name:"emit", session, event}, null);`
);
eval(`${prefix}_GLOBAL_PID = process.id;`);
/* eslint-enable no-eval */

Expand All @@ -52,7 +51,7 @@ module.exports = (process) => {
requestSync({
name: "terminate",
session,
reason
reason,
});
}
};
Expand Down Expand Up @@ -85,20 +84,24 @@ module.exports = (process) => {

return {
instrumentModule: (path, content, pending) => {
requestAsync({
requestAsync(
{
name: "instrument",
session,
source: "module",
path,
content,
},
pending
);
},
instrumentScript: (path, content) =>
requestSync({
name: "instrument",
session,
source: "module",
source: "script",
path,
content
}, pending);
},
instrumentScript: (path, content) => requestSync({
name: "instrument",
session,
source: "script",
path,
content
});
content,
}),
};
};
65 changes: 33 additions & 32 deletions lib/server/dispatcher.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import logger from "./logger.mjs";
import Appmap from "./appmap/index.mjs";
import logger from './logger.mjs';
import Appmap from './appmap/index.mjs';

const checkHas = (object, key) => {
if (Reflect.getOwnPropertyDescriptor(object, key) === undefined) {
Expand All @@ -10,70 +9,72 @@ const checkHas = (object, key) => {

const checkNotNull = (any) => {
if (any === null) {
throw new Error("Unexpected null");
throw new Error('Unexpected null');
}
};

const checkTypeof = (value, type) => {
if (typeof value !== type) {
throw new Error(`Invalid value type: expected a ${type} and got a ${typeof value}`);
throw new Error(
`Invalid value type: expected a ${type} and got a ${typeof value}`,
);
}
};

const checkAnyof = (value, values) => {
if (!values.includes(value)) {
throw new Error("Invalid enumeration-based value");
throw new Error('Invalid enumeration-based value');
}
};

const sources = ["script", "module"];
const sources = ['script', 'module'];

export default (class Dispatcher {
constructor (config) {
constructor(config) {
this.config = config;
this.appmaps = {__proto__:null};
},
dispatch (json) {
checkTypeof(json, "object");
this.appmaps = { __proto__: null };
}
dispatch(json) {
checkTypeof(json, 'object');
checkNotNull(json);
checkHas(json, "name");
if (json.name === "initialize") {
checkHas(json, "init");
let session
checkHas(json, 'name');
if (json.name === 'initialize') {
checkHas(json, 'init');
let session;
do {
session = Math.random().toString(36).substring(2)
session = Math.random().toString(36).substring(2);
} while (session in this.appmaps);
const appmap = new Appmap(this.config, json.init);
this.appmaps[session] = appmap;
return {
session,
prefix: appmap.getEscapePrefix()
prefix: appmap.getEscapePrefix(),
};
}
checkHas(json, "session");
checkTypeof(json.session, "string");
checkHas(json, 'session');
checkTypeof(json.session, 'string');
checkHas(this.appmaps, json.session);
const appmap = this.appmaps[json.session];
if (json.name === "terminate") {
checkHas(json, "reason");
if (json.name === 'terminate') {
checkHas(json, 'reason');
appmap.terminate(json.reason);
delete this.appmaps[json.session]
delete this.appmaps[json.session];
return null;
}
if (json.name === "instrument") {
checkHas(json, "source");
checkHas(json, "path");
checkHas(json, "content");
if (json.name === 'instrument') {
checkHas(json, 'source');
checkHas(json, 'path');
checkHas(json, 'content');
checkAnyof(json.source, sources);
checkTypeof(json.path, "string");
checkTypeof(json.content, "string");
checkTypeof(json.path, 'string');
checkTypeof(json.content, 'string');
return appmap.instrument(json.source, json.path, json.content);
}
if (json.name === "emit") {
checkHas(json, "event");
if (json.name === 'emit') {
checkHas(json, 'event');
appmap.emit(json.event);
return null;
}
throw new Error("Unrecognized name");
throw new Error('Unrecognized name');
}
});
6 changes: 3 additions & 3 deletions lib/server/inline/channel.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getDefaultConfig } from './config.mjs';
import { makeDispatch } from './dispatch.mjs';
import { makeChannel } from './response/inline.mjs';
import { getDefaultConfig } from '../config.mjs';
import { makeDispatch } from '../dispatch.mjs';
import { makeChannel } from './response.mjs';

export default () => makeChannel(makeDispatch(getDefaultConfig()));
2 changes: 1 addition & 1 deletion lib/server/inline/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default (argv, stdio) => {
},
{ __proto__: null },
),
APPMAP_CHANNEL: "inline"
APPMAP_CHANNEL: 'inline',
};
if (Reflect.getOwnPropertyDescriptor(argv, 'esm') && argv.esm) {
let name;
Expand Down
7 changes: 3 additions & 4 deletions lib/server/inline/response.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import logger from "../../logger.mjs";
import logger from '../../logger.mjs';

export const makeChannel = (dispatcher) => ({
requestSync: (json1) => {
logger.info();
const json2 = dispatcher.dispatch(json1);
logger.info();
};
},
requestAsync: (json1, pending) => {
logger.info();
if (pending === null) {
Expand All @@ -24,5 +23,5 @@ export const makeChannel = (dispatcher) => ({
logger.info(json2);
pending.resolve(json2);
}
}
},
});
Loading

0 comments on commit fc573fd

Please sign in to comment.