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

Commit

Permalink
refactor: rename some server files
Browse files Browse the repository at this point in the history
  • Loading branch information
lachrist committed Apr 9, 2021
1 parent 7f89455 commit 82ed52c
Show file tree
Hide file tree
Showing 24 changed files with 286 additions and 222 deletions.
51 changes: 39 additions & 12 deletions lib/client/es2015/node/request/curl-sync.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const global_Reflect_apply = Reflect.apply;
const global_String_prototype_split = String.prototype.split;
const global_Error = Error;
Expand All @@ -8,10 +7,13 @@ const global_JSON_stringify = JSON.stringify;
module.exports = (version, host, port) => {
const args = [
`--${version}`,
"--request", "PUT",
"--data", "@-",
"--header", "content-type: application/json; charset=utf-8",
`http://${host}:${port}`
"--request",
"PUT",
"--data",
"@-",
"--header",
"content-type: application/json; charset=utf-8",
`http://${host}:${port}`,
];
return (data) => {
const result = ChildProcess.spawnSync("curl", args, {
Expand All @@ -25,19 +27,44 @@ module.exports = (version, host, port) => {
throw new global_Error(`Unexpected kill signal: ${result.signal}`);
}
if (result.status !== 0) {
throw new global_Error(`curl request failed with ${result.status} >> ${result.stderr}`);
throw new global_Error(
`curl request failed with ${result.status} >> ${result.stderr}`
);
}
if (!global_Reflect_apply(global_String_prototype_startsWith, result.stdout, ["HTTP/2 200 "])) {
const index = global_Reflect_apply(global_String_prototype_indexOf, result.stdout, ["\r\n"]);
if (
!global_Reflect_apply(global_String_prototype_startsWith, result.stdout, [
"HTTP/2 200 ",
])
) {
const index = global_Reflect_apply(
global_String_prototype_indexOf,
result.stdout,
["\r\n"]
);
if (index === -1) {
throw new global_Error("Cannot extract status line from curl http/2 response");
throw new global_Error(
"Cannot extract status line from curl http/2 response"
);
}
throw new global_Error(global_Reflect_apply(global_String_prototype_substring, result.stdout, [0, index]));
throw new global_Error(
global_Reflect_apply(global_String_prototype_substring, result.stdout, [
0,
index,
])
);
}
const index = global_Reflect_apply(global_String_prototype_indexOf, result.stdout, ["\r\n\r\n"]);
const index = global_Reflect_apply(
global_String_prototype_indexOf,
result.stdout,
["\r\n\r\n"]
);
if (index === -1) {
throw new global_Error("Cannot extract body from curl http/2 response");
}
return global_JSON_parse(global_Reflect_apply(global_String_prototype_substring, result.stdout, [index + 4]));
return global_JSON_parse(
global_Reflect_apply(global_String_prototype_substring, result.stdout, [
index + 4,
])
);
};
};
23 changes: 14 additions & 9 deletions lib/client/es2015/node/request/http1-async.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

const { request : connect } = require("http");
const { request: connect } = require("http");
const global_Error = Error;
const global_JSON_stringify = JSON.stringify;
const global_JSON_parse = JSON.parse;
Expand All @@ -11,11 +10,13 @@ const discard = (response) => {
if (response.statusCode !== 200) {
let body = "";
response.setEncoding("utf8");
response.on('data', (data) => {
response.on("data", (data) => {
body += data;
});
response.on("end", () => {
throw new global_Error(`http status ${global_String(response.statusCode)}: ${body}`);
throw new global_Error(
`http status ${global_String(response.statusCode)}: ${body}`
);
});
} else {
response.on("data", noop);
Expand All @@ -24,15 +25,15 @@ const discard = (response) => {
};

module.exports = (host, port) => {
const cache = {__proto__:null};
const cache = { __proto__: null };
const options = {
host,
port,
method: "PUT",
path: `/${name}`,
headers: {
"content-type": "application/json; charset=utf-8"
}
"content-type": "application/json; charset=utf-8",
},
};
return (data, pending) => {
const request = connect(options);
Expand All @@ -47,9 +48,13 @@ module.exports = (host, port) => {
result += data;
});
response.on("error", pending.reject);
response.on('end', () => {
response.on("end", () => {
if (response.statusCode !== 200) {
return pending.reject(new global_Error(`http status ${global_String(response.statusCode)}: ${body}`));
return pending.reject(
new global_Error(
`http status ${global_String(response.statusCode)}: ${body}`
)
);
}
try {
pending.resolve(global_JSON_parse(result));
Expand Down
15 changes: 10 additions & 5 deletions lib/client/es2015/node/request/http2-async.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { connect } = require("http2");

const {connect} = require("http2");
const global_String = String;
const global_Error = Error;
const global_JSON_stringify = JSON.stringify;
const global_JSON_parse = JSON.parse;
Expand All @@ -13,9 +14,13 @@ const checkStatus = function (headers) {
} else {
let body = "";
this.setEncoding("utf8");
this.on("data", (data) => { body += data; });
this.on("data", (data) => {
body += data;
});
this.on("end", () => {
throw new global_Error(`http status ${global_String(headers[":status"])}: ${body}`);
throw new global_Error(
`http status ${global_String(headers[":status"])}: ${body}`
);
});
}
};
Expand All @@ -25,7 +30,7 @@ module.exports = (host, port) => {
const headers = {
":method": "PUT",
":path": `/`,
"content-type": "application/json; charset=utf-8"
"content-type": "application/json; charset=utf-8",
};
return (data, pending) => {
const request = session.request(headers);
Expand All @@ -39,7 +44,7 @@ module.exports = (host, port) => {
request.on("response", (headers) => {
status = headers[":status"];
});
request.on("data", (data) => body += data);
request.on("data", (data) => (body += data));
request.on("end", () => {
if (status !== 200) {
reject(new Error(`http status ${global_String(status)} >> ${body}`));
Expand Down
1 change: 0 additions & 1 deletion lib/client/es2015/node/request/http3-sync.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const global_Error = Error;

module.exports = () => {
Expand Down
22 changes: 13 additions & 9 deletions lib/server/appmap.mjs → lib/server/appmap/appmap.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as Path from 'path';
import * as FileSystem from 'fs';
import logger from './logger.mjs';
import logger from '../logger.mjs';
import Namespace from './namespace.mjs';
import git from './git.mjs';
import File from './file.mjs';
import instrument from './instrument/index.mjs';
import instrument from '../instrument/index.mjs';

const VERSION = '1.4';

Expand Down Expand Up @@ -35,7 +35,7 @@ export default (class Appmap {
recorder: null,
recording: null,
engine: null,
...json
...json,
};
this.config = config.extendWithEnv(init.env);
this.namespace = new Namespace(config.getEscapePrefix());
Expand Down Expand Up @@ -84,18 +84,22 @@ export default (class Appmap {
}
emit(event) {
if (this.terminated) {
throw new Error("Terminated appmap can no longer receive events");
throw new Error('Terminated appmap can no longer receive events');
}
this.state.appmap.events.push(event);
}
terminate(reason) {
if (this.terminated) {
throw new Error("Terminated appmap can no longer be terminated");
throw new Error('Terminated appmap can no longer be terminated');
}
this.terminated = true;
FileSystem.writeFileSync(Path.join(
this.state.config.getOutputDir(),
`${this.state.config.getMapName()}.appmap.json`,
), JSON.stringify(this.state.appmap), 'utf8');
FileSystem.writeFileSync(
Path.join(
this.state.config.getOutputDir(),
`${this.state.config.getMapName()}.appmap.json`,
),
JSON.stringify(this.state.appmap),
'utf8',
);
}
});
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions lib/server/namespace.mjs → lib/server/appmap/namespace.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const globals = {
__proto__: null,
UNDEFINED: null,
Expand Down Expand Up @@ -33,7 +32,9 @@ export default (class Namespace {
}
checkCollision(identifier) {
if (identifier.startsWith(this.prefix)) {
throw new Error(`Base-level identifier should never start with the escape prefix ${this.prefix}, got: ${identifier}`);
throw new Error(
`Base-level identifier should never start with the escape prefix ${this.prefix}, got: ${identifier}`,
);
}
}
getGlobal(name) {
Expand Down
Empty file removed lib/server/channel/fork.mjs
Empty file.
5 changes: 0 additions & 5 deletions lib/server/channel/inline.mjs

This file was deleted.

39 changes: 0 additions & 39 deletions lib/server/channel/util/fork.mjs

This file was deleted.

56 changes: 0 additions & 56 deletions lib/server/channel/util/http-1-1.mjs

This file was deleted.

49 changes: 0 additions & 49 deletions lib/server/channel/util/http-2-0.mjs

This file was deleted.

Loading

0 comments on commit 82ed52c

Please sign in to comment.