Skip to content

Commit

Permalink
Refine LogEntry type
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Fernández Gómez committed Jan 2, 2020
1 parent c5e231a commit 1971e5c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,41 @@ export const logEntriesRequestRT = rt.union([

export type LogEntriesRequest = rt.TypeOf<typeof logEntriesRequestRT>;

// JSON value
const valueRT = rt.union([rt.string, rt.number, rt.boolean, rt.object, rt.null, rt.undefined]);

export const logMessagePartRT = rt.union([
rt.type({
constant: rt.string,
}),
rt.type({
field: rt.string,
value: valueRT,
highlights: rt.array(rt.string),
}),
]);

export const logColumnRT = rt.union([
rt.type({ columnId: rt.string, timestamp: rt.number }),
rt.type({
columnId: rt.string,
field: rt.string,
value: valueRT,
}),
rt.type({
columnId: rt.string,
message: rt.array(logMessagePartRT),
}),
]);

export const logEntryRT = rt.type({
id: rt.string,
cursor: logEntriesCursorRT,
columns: rt.array(rt.any),
columns: rt.array(logColumnRT),
});

export type LogMessagepart = rt.TypeOf<typeof logMessagePartRT>;
export type LogColumn = rt.TypeOf<typeof logColumnRT>;
export type LogEntry = rt.TypeOf<typeof logEntryRT>;

export const logEntriesResponseRT = rt.type({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
LogEntry,
LogEntriesItem,
LogEntriesCursor,
LogColumn,
} from '../../../../common/http_api';
import { InfraLogEntry, InfraLogMessageSegment } from '../../../graphql/types';
import {
Expand Down Expand Up @@ -203,27 +204,27 @@ export class InfraLogEntriesDomain {
return {
id: doc.gid,
cursor: doc.key,
columns: configuration.logColumns.map(column => {
if ('timestampColumn' in column) {
return {
columnId: column.timestampColumn.id,
timestamp: doc.key.time,
};
}
if ('messageColumn' in column) {
return {
columnId: column.messageColumn.id,
message: messageFormattingRules.format(doc.fields, doc.highlights),
};
}
if ('fieldColumn' in column) {
return {
columnId: column.fieldColumn.id,
field: column.fieldColumn.field,
value: doc.fields[column.fieldColumn.field],
};
columns: configuration.logColumns.map(
(column): LogColumn => {
if ('timestampColumn' in column) {
return {
columnId: column.timestampColumn.id,
timestamp: doc.key.time,
};
} else if ('messageColumn' in column) {
return {
columnId: column.messageColumn.id,
message: messageFormattingRules.format(doc.fields, doc.highlights),
};
} else {
return {
columnId: column.fieldColumn.id,
field: column.fieldColumn.field,
value: doc.fields[column.fieldColumn.field],
};
}
}
}),
),
};
});

Expand Down

0 comments on commit 1971e5c

Please sign in to comment.