Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

JSON import and object casting to TS model #46

Closed
wants to merge 2 commits into from
Closed

JSON import and object casting to TS model #46

wants to merge 2 commits into from

Conversation

bdarcus
Copy link
Owner

@bdarcus bdarcus commented Apr 26, 2023

I'm closing this, both because of git issues, and because I can't figure out a bug related to my use of @Type.


My focus is on the input data end, since that's where the obvious immediate need is (methods to format and process names, dates, etc.).

  • Reference
  • Contributor
  • Date (transform)
  • Title

Something like this should work for edtf dates:

@Type(() => DateStr)
@Transform(({ value }) => edtf(value), { toClassOnly: true })
  date: EDTFDATE;
}

EDIT: it likely won't, because EDTF is a complex model.

Also, at least by default, EDTF.js will fail loudly if the string you feed it isn't valid. So would need to do a type check first.

Still unsure on the details of date formatting config, but am including here also.

Here's an example as internally represented.

  Reference {
    id: "un",
    type: "article",
    author: [ Organization { name: "United Nations" } ],
    title: "The Title",
    issued: "2020"
  }

Note:

Been driving myself crazy assuming a bug on my end, but seems that it may this:

typestack/class-transformer#1510

Links:

https://stackoverflow.com/questions/76112334/discriminating-type-based-on-presence-of-different-properties

typestack/class-transformer#857 (comment)

@bdarcus bdarcus mentioned this pull request Apr 27, 2023
@bdarcus bdarcus force-pushed the json-ts branch 8 times, most recently from 8bd3224 to 9929d9c Compare April 28, 2023 20:16
Signed-off-by: Bruce D'Arcus <bdarcus@gmail.com>
@bdarcus bdarcus marked this pull request as ready for review April 28, 2023 20:34
Signed-off-by: Bruce D'Arcus <bdarcus@gmail.com>
@bdarcus bdarcus marked this pull request as draft April 28, 2023 22:48
@bdarcus bdarcus closed this Apr 29, 2023
@bdarcus bdarcus deleted the json-ts branch April 29, 2023 12:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant