Skip to content

Commit

Permalink
Revert "FAI-6042: replace epochs with timestamps in jsonb fields" (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
ypc-faros committed May 1, 2023
1 parent 74e66e1 commit 21ad82c
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 120 deletions.
23 changes: 1 addition & 22 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
printSchema,
visit,
} from 'graphql';
import {isPlainObject, keyBy, mapValues, toNumber} from 'lodash';
import {isPlainObject, keyBy, toNumber} from 'lodash';
import {Dictionary} from 'ts-essentials';
import {VError} from 'verror';

Expand Down Expand Up @@ -71,8 +71,6 @@ export class FarosGraphSchema {
record[field] = toDate(value as string);
} else if (fieldType.name.value === 'timestamptz') {
record[field] = toDateAsISOString(value as string);
} else if (fieldType.name.value === 'jsonb') {
record[field] = replaceAllEpochsEndingInAt(value);
} else if (this.objectTypeDefs[fieldType.name.value]) {
this.fixTimestampFields(value, fieldType.name.value);
}
Expand Down Expand Up @@ -142,22 +140,3 @@ function toDateAsISOString(
}
}
}

function replaceAllEpochsEndingInAt(
obj: any,
): any {
const toDateIfNeeded =
(_v: any, _k: string): any => {
const isEpoch = _k.endsWith('At') && typeof _v === 'number';
return isEpoch ? toDateAsISOString(_v) : _v;
};
if (Array.isArray(obj)) {
return obj.map((o) => replaceAllEpochsEndingInAt(o));
}
return mapValues(obj, (value, key) => {
if (isPlainObject(value)) {
return replaceAllEpochsEndingInAt(value);
}
return toDateIfNeeded(value, key);
});
}
45 changes: 0 additions & 45 deletions test/__snapshots__/schema.test.ts.snap

This file was deleted.

6 changes: 0 additions & 6 deletions test/resources/schemas/timestamp-schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ type ims_Incident {
createdAt: Timestamp
createdAtNonNull: Timestamp!
array: [ims_TimestampObject!]
status(
"""JSON select path"""
path: String
): jsonb
}

type ims_TimestampObject {
Expand All @@ -19,8 +15,6 @@ type ims_TimestampObject {

scalar timestamptz

scalar jsonb

type vcs_Commit {
uid: ID!
createdAt: timestamptz
Expand Down
47 changes: 0 additions & 47 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,53 +41,6 @@ describe('schema', () => {
);
});

test('fix jsonb - array', () => {
const record = {
uid: 'abc', status: [
{
'foo': {
'category': 'Todo',
'detail': 'To Do',
'fixAt': 1633751867746,
'skippedAt': 'not-interesting'
},
'changedAt': 1629751867746,
'ignoredAt': 'blah',
},
{
'bar': {
'category': 'Todo',
'fixAt': 1645751867746,
'skippedAt': 'not-interesting',
'detail': 'Selected for Development',
},
'changedAt': 1629832560991,
'skipAt': 'nothing'
},
],
};
expect(schema.fixTimestampFields(record, 'ims_Incident'))
.toMatchSnapshot();
});

test('fix jsonb - object', () => {
const record = {
uid: 'abc',
status: {
'foo': {
'category': 'Todo',
'detail': 'To Do',
'brokenAt': 1644751867746,
'ackedAt': 'ignore'
},
'changedAt': 1629751867746,
'submittedAt': 'foo'
},
};
expect(schema.fixTimestampFields(record, 'ims_Incident'))
.toMatchSnapshot();
});

test('fix nested timestamp field', () => {
const record = {uid: 'abc', timestampObj: {createdAt: new Date(123)}};
const json = {uid: 'abc', timestampObj: {createdAt: 123}};
Expand Down

0 comments on commit 21ad82c

Please sign in to comment.