Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is a v1 of the typedefinitions #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.2.3",
"description": "simple library for creating and parsing hl7 messages",
"main": "lib/index.js",
"types": "./types/index.d.ts",
"directories": {
"test": "test"
},
Expand Down
7 changes: 7 additions & 0 deletions types/component.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Delimiters } from "./delimiters";

export declare class Component {
constructor(...args: string[]);
toString(delimiters: Delimiters): string;
value: string[];
}
8 changes: 8 additions & 0 deletions types/delimiters.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Delimiters {
fieldSeperator: "|";
componentSeperator: "^";
subcomponentSeperator: "&";
escapeCharacter: "\\";
repititionCharacter: "~";
segmentSeperator: "\r";
}
8 changes: 8 additions & 0 deletions types/field.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Delimiters } from "./delimiters";

export declare class Field<T = any> {
constructor(...args: T[]);
constructor(...args: T[][]);
value: (T | T[])[];
toString(delimiters: Delimiters): string;
}
1 change: 1 addition & 0 deletions types/file-client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare class FileClient {}
1 change: 1 addition & 0 deletions types/file-server.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare class FileServer {}
3 changes: 3 additions & 0 deletions types/file.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export = file;
/*~ This example shows how to have multiple overloads for your function */
declare function file(): any;
19 changes: 19 additions & 0 deletions types/header.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Delimiters } from "./delimiters";
import { Field } from "./field";
import { FieldValue } from "./segment";

export declare class Header {
name: string;
delimiters: Delimiters;
fields: (Field | Field[])[];
addField<T = any>(fieldValue: FieldValue<T>, position?: number): void;
setField<T>(index: number, fieldValue: FieldValue<T>): void;
removeField(index: number): void;
getField(index: number, repeatIndex?: number): string;
getComponent(
fieldIndex: number,
componentIndex: number,
subComponentIndex?: number
): string;
toString(): string;
}
10 changes: 10 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from "./component";
import { Field } from "./field";
import file from "./file";
import { Message } from "./message";
import { Parser } from "./parser";
import { Segment } from "./segment";
import { Server } from "./server";
import tcp from "./tcp";

export { Server, Parser, Message, Component, Field, Segment, tcp, file };
13 changes: 13 additions & 0 deletions types/message.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Header } from "./header";
import { Segment } from "./segment";

export declare class Message<T = any> {
constructor(...args: T[]);
header: Header;
segments: Segment[];
getSegment(name: string): Segment | undefined;
getSegments(name: string): Segment[];
addSegment<U>(...args: U[]): Segment;
log(): string;
toString(): string;
}
22 changes: 22 additions & 0 deletions types/parser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component } from "./component";
import { Delimiters } from "./delimiters";
import { Field } from "./field";
import { Header } from "./header";
import { Message } from "./message";
import { Segment } from "./segment";

export declare class Parser {
constructor(opts: ParserOptions);
message: Message | null;
delimiters: Delimiters;

parse(s: string): Message;
parseFile(path: string, callback: (data: string) => void): void;
parseFileSync(path: string): string;
parseHeader(s: string): Header;
parseSegment(s: string): Segment;
parseField(s: string): Field;
parseComponent(s: string): Component;
}

export type ParserOptions = string | { segmentSeperator: string };
30 changes: 30 additions & 0 deletions types/segment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Delimiters } from "./delimiters";
import { Field } from "./field";

export declare class Segment {
name: string;
fields: Field[] | Field[][];
addField<T = any>(fieldValue: FieldValue<T>, position?: number): void;
setField<T>(index: number, fieldValue: FieldValue<T>): void;
removeField(index: number): void;
getField(index: number, repeatIndex?: number): string;
getComponent(
fieldIndex: number,
componentIndex: number,
subComponentIndex?: number
): string;
setComponent<T>(
fieldIndex: number,
componentIndex: number,
value: ComponentValue<T>
): void;
toString(delimiters: Delimiters): string;
}

export type ComponentValue<T> = FieldValue<T>;

export type FieldValue<T> =
| string
| Record<string | number | symbol, unknown>
| Array<T>
| T;
19 changes: 19 additions & 0 deletions types/server.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { FileClient } from "./file-client";
import { FileServer } from "./file-server";
import { TcpClient } from "./tcp-client";
import { TcpServer } from "./tcp-server";

export declare const Server: {
createTcpServer(options, handler): TcpServer;
createTcpClient(options: CreateTcpClientOptions): TcpClient;
createTcpClient(host: string, port: number): TcpClient;
createFileServer(options, handler): FileServer;
createFileClient(dest): FileClient;
};

export interface CreateTcpClientOptions {
host: string;
port: number;
callback?: () => void;
keepAlive?: boolean;
}
1 change: 1 addition & 0 deletions types/tcp-client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare class TcpClient {}
1 change: 1 addition & 0 deletions types/tcp-server.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare class TcpServer {}
3 changes: 3 additions & 0 deletions types/tcp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export = tcp;
/*~ This example shows how to have multiple overloads for your function */
declare function tcp(): any;