Skip to content

Commit

Permalink
feat: updated to type: module at package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
JS-AK committed Jun 21, 2024
1 parent a5734f2 commit ee23f4e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/example/login-and-listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { setTimeout as setTimeoutPromise } from "node:timers/promises";

import { AsteriskAmiAdapter, Types } from "..";
import { AsteriskAmiAdapter, Types } from "../index.js";

const config = {
AMI_HOST: process.env.AMI_HOST || "localhost",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * as Types from "./types";
export { AsteriskAmiAdapter } from "./lib/asterisk-ami-adapter";
export * as Types from "./types/index.js";
export { AsteriskAmiAdapter } from "./lib/index.js";
24 changes: 10 additions & 14 deletions src/lib/asterisk-ami-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from "node:fs";
import net from "node:net";
import { setTimeout as setTimeoutPromise } from "node:timers/promises";

import * as Types from "../types";
import * as Types from "../types/index.js";

export class AsteriskAmiAdapter extends EventEmitter {
#NEW_LINE = "\r\n";
Expand Down Expand Up @@ -74,11 +74,12 @@ export class AsteriskAmiAdapter extends EventEmitter {
}
}

const logMethods: { [k: string]: "error" | "log" | "warn"; } = {
const logMethods = {

ERROR: "error",
INFO: "log",
WARN: "warn",
};
} as const;

const method = logMethods[level];

Expand Down Expand Up @@ -118,7 +119,7 @@ export class AsteriskAmiAdapter extends EventEmitter {
return str + this.#NEW_LINE;
}

#getFormatedUuid = crypto.randomUUID;
#getFormattedUuid = crypto.randomUUID;

#processData(data: string) {
if (data.substring(0, 21) === "Asterisk Call Manager") {
Expand Down Expand Up @@ -148,18 +149,13 @@ export class AsteriskAmiAdapter extends EventEmitter {
const event: Types.TAmiEvent = preparedEvents.reduce((p: Types.TAmiMessageOut, c: string) => {
const [key, value]: string[] = c.split(": ", 2);

if (!key) return p;
if (!key || !value) return p;

if (key === "Variable") {
if (!p.Variable) {
p.Variable = {};
}
const [k, v] = value.split("=");

if (value) {
const [k, v] = value.split("=");

p.Variable[k] = v;
}
if (!p.Variable) p.Variable = {};
if (k && v) p.Variable[k] = v;
} else {
p[key] = value;
}
Expand All @@ -174,7 +170,7 @@ export class AsteriskAmiAdapter extends EventEmitter {
}

#send(data: Types.TAmiMessageIn & Types.TAmiMessageToSocket, callback?: Types.TCallBack) {
if (!data.ActionID) data.ActionID = this.#getFormatedUuid();
if (!data.ActionID) data.ActionID = this.#getFormattedUuid();

const actionID = data.ActionID;

Expand Down
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./asterisk-ami-adapter.js";
2 changes: 1 addition & 1 deletion src/test/unit/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "node:assert";
import test from "node:test";

import { AsteriskAmiAdapter } from "../..";
import { AsteriskAmiAdapter } from "../../index.js";

const amiAdapter = new AsteriskAmiAdapter({
encoding: "ascii",
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./common";
export * from "./common.js";
14 changes: 7 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": ["esnext"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
Expand All @@ -24,9 +24,9 @@
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */

/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"module": "esnext", /* Specify what module code is generated. */
"rootDir": "./src", /* Specify the root folder within your source files. */
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
Expand Down Expand Up @@ -67,7 +67,7 @@
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
Expand All @@ -81,14 +81,14 @@
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
"useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
"noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
Expand Down

0 comments on commit ee23f4e

Please sign in to comment.