Skip to content
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
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aries-framework",
"version": "0.0.5-unstable.0",
"version": "0.0.5-unstable.0-datatransfer.5",
"license": "Apache-2.0",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand All @@ -23,12 +23,14 @@
"prepare": "husky install"
},
"dependencies": {
"@types/luxon": "^1.27.0",
"bn.js": "^5.2.0",
"buffer": "^6.0.3",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"events": "^3.3.0",
"js-sha256": "^0.9.0",
"luxon": "^1.27.0",
"reflect-metadata": "^0.1.13",
"uuid": "^8.3.0"
},
Expand Down Expand Up @@ -83,6 +85,6 @@
}
},
"engines": {
"node": "^12"
"node": ">= 12"
}
}
5 changes: 3 additions & 2 deletions src/modules/basic-messages/messages/BasicMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Equals, IsDate, IsString } from 'class-validator'
import { Expose, Type } from 'class-transformer'
import { Expose, Transform } from 'class-transformer'

import { AgentMessage } from '../../../agent/AgentMessage'
import { DateParser } from '../../../utils/transformers'
import { MessageType } from './BasicMessageMessageType'

export class BasicMessage extends AgentMessage {
Expand All @@ -26,7 +27,7 @@ export class BasicMessage extends AgentMessage {
public static readonly type = MessageType.BasicMessage

@Expose({ name: 'sent_time' })
@Type(() => Date)
@Transform(({ value }) => DateParser(value))
@IsDate()
public sentTime!: Date

Expand Down
18 changes: 18 additions & 0 deletions src/utils/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Transform, TransformationType } from 'class-transformer'
import { JsonTransformer } from './JsonTransformer'

import { DateTime } from 'luxon'

/**
* Decorator that transforms json to and from corresponding record.
*
Expand Down Expand Up @@ -36,3 +38,19 @@ export function RecordTransformer<T>(Class: { new (...args: any[]): T }) {
}
})
}
/*
* Function that parses date from multiple formats
* including SQL formats.
*/

export function DateParser(value: string): Date {
const parsedDate = new Date(value)
if (parsedDate instanceof Date && !isNaN(parsedDate.getTime())) {
return parsedDate
}
const luxonDate = DateTime.fromSQL(value)
if (luxonDate.isValid) {
return new Date(luxonDate.toString())
}
return new Date()
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,11 @@
dependencies:
"@types/node" "*"

"@types/luxon@^1.27.0":
version "1.27.0"
resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-1.27.0.tgz#1e3b5a7f8ca6944349c43498b4442b742c71ab0b"
integrity sha512-rr2lNXsErnA/ARtgFn46NtQjUa66cuwZYeo/2K7oqqxhJErhXgHBPyNKCo+pfOC3L7HFwtao8ebViiU9h4iAxA==

"@types/mime@^1":
version "1.3.2"
resolved "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz"
Expand Down Expand Up @@ -4274,6 +4279,11 @@ lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"

luxon@^1.27.0:
version "1.27.0"
resolved "https://registry.yarnpkg.com/luxon/-/luxon-1.27.0.tgz#ae10c69113d85dab8f15f5e8390d0cbeddf4f00f"
integrity sha512-VKsFsPggTA0DvnxtJdiExAucKdAnwbCCNlMM5ENvHlxubqWd0xhZcdb4XgZ7QFNhaRhilXCFxHuoObP5BNA4PA==

macos-release@^2.2.0:
version "2.4.1"
resolved "https://registry.npmjs.org/macos-release/-/macos-release-2.4.1.tgz"
Expand Down