datacite-ts
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -5,2 +5,12 @@ # Changelog | ||
### [0.1.1](https://github.com/thewilkybarkid/datacite-ts/compare/v0.1.0...v0.1.1) (2022-12-02) | ||
### Features | ||
* add creators to Work ([0ba1037](https://github.com/thewilkybarkid/datacite-ts/commit/0ba103787cb9434965dd84d2accfc5665b9ac430)) | ||
* add dates to Work ([0cc554b](https://github.com/thewilkybarkid/datacite-ts/commit/0cc554b3ddb0266b6a5df8366261be0db150530a)) | ||
* add types to Work ([bcd9101](https://github.com/thewilkybarkid/datacite-ts/commit/bcd91011c012bd13bfabe0e39bff7f9a519f4c62)) | ||
* add URL to Work ([cb5598a](https://github.com/thewilkybarkid/datacite-ts/commit/cb5598a5c00e141723273a381f6a2202d3ca2267)) | ||
## 0.1.0 (2022-12-02) | ||
@@ -7,0 +17,0 @@ |
/** | ||
* @since 0.1.0 | ||
*/ | ||
import { Temporal } from '@js-temporal/polyfill'; | ||
import { Doi } from 'doi-ts'; | ||
@@ -11,2 +12,5 @@ import * as F from 'fetch-fp-ts'; | ||
import FetchEnv = F.FetchEnv; | ||
import Instant = Temporal.Instant; | ||
import PlainDate = Temporal.PlainDate; | ||
import PlainYearMonth = Temporal.PlainYearMonth; | ||
import ReadonlyNonEmptyArray = RNEA.ReadonlyNonEmptyArray; | ||
@@ -19,2 +23,12 @@ import ReaderTaskEither = RTE.ReaderTaskEither; | ||
export interface Work { | ||
readonly creators: ReadonlyArray<{ | ||
givenName?: string; | ||
familyName: string; | ||
} | { | ||
name: string; | ||
}>; | ||
readonly dates: ReadonlyNonEmptyArray<{ | ||
date: Instant | PartialDate; | ||
dateType: string; | ||
}>; | ||
readonly descriptions: ReadonlyArray<{ | ||
@@ -25,7 +39,17 @@ description: string; | ||
readonly doi: Doi; | ||
readonly types: { | ||
resourceType?: string; | ||
resourceTypeGeneral?: string; | ||
}; | ||
readonly titles: ReadonlyNonEmptyArray<{ | ||
title: string; | ||
}>; | ||
readonly url: URL; | ||
} | ||
/** | ||
* @category model | ||
* @since 0.1.1 | ||
*/ | ||
export type PartialDate = number | PlainYearMonth | PlainDate; | ||
/** | ||
* @category constructors | ||
@@ -32,0 +56,0 @@ * @since 0.1.0 |
@@ -25,2 +25,13 @@ "use strict"; | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -34,2 +45,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
*/ | ||
const polyfill_1 = require("@js-temporal/polyfill"); | ||
const doi_ts_1 = require("doi-ts"); | ||
@@ -46,2 +58,5 @@ const F = __importStar(require("fetch-fp-ts")); | ||
const safe_stable_stringify_1 = __importDefault(require("safe-stable-stringify")); | ||
var Instant = polyfill_1.Temporal.Instant; | ||
var PlainDate = polyfill_1.Temporal.PlainDate; | ||
var PlainYearMonth = polyfill_1.Temporal.PlainYearMonth; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -65,2 +80,17 @@ // constructors | ||
const DoiC = C.fromDecoder(D.fromRefinement(doi_ts_1.isDoi, 'DOI')); | ||
const InstantC = C.make((0, function_1.pipe)(D.string, D.parse(string => E.tryCatch(() => Instant.from(string), () => D.error(string, 'Instant')))), { encode: String }); | ||
const PlainDateC = C.make((0, function_1.pipe)(D.string, D.parse(string => E.tryCatch(() => PlainDate.from(string), () => D.error(string, 'PlainDate')))), { encode: String }); | ||
const PlainYearMonthC = C.make((0, function_1.pipe)(D.string, D.parse(string => E.tryCatch(() => PlainYearMonth.from(string), () => D.error(string, 'PlainYearMonth')))), { encode: String }); | ||
const NumberFromStringC = C.make((0, function_1.pipe)(D.string, D.parse(s => { | ||
const n = +s; | ||
return isNaN(n) || s.trim() === '' ? D.failure(s, 'Number') : D.success(n); | ||
})), { encode: String }); | ||
const UrlC = C.make((0, function_1.pipe)(D.string, D.parse(s => E.tryCatch(() => new URL(s), () => D.error(s, 'URL')))), { encode: String }); | ||
const OrganizationCreatorC = C.struct({ name: C.string }); | ||
const PersonCreatorC = (0, function_1.pipe)(C.struct({ familyName: C.string, nameType: C.literal('Personal') }), C.intersect(C.partial({ | ||
givenName: C.string, | ||
})), C.imap((_a) => { | ||
var { nameType } = _a, props = __rest(_a, ["nameType"]); | ||
return props; | ||
}, creator => (Object.assign(Object.assign({}, creator), { nameType: 'Personal' })))); | ||
/** | ||
@@ -74,2 +104,23 @@ * @category codecs | ||
attributes: C.struct({ | ||
creators: ReadonlyArrayC( | ||
// Unfortunately, there's no way to describe a union encoder, so we must implement it ourselves. | ||
// Refs https://github.com/gcanti/io-ts/issues/625#issuecomment-1007478009 | ||
C.make(D.union(PersonCreatorC, OrganizationCreatorC), { | ||
encode: author => 'familyName' in author ? PersonCreatorC.encode(author) : OrganizationCreatorC.encode(author), | ||
})), | ||
dates: ReadonlyNonEmptyArrayC(C.struct({ | ||
date: | ||
// Unfortunately, there's no way to describe a union encoder, so we must implement it ourselves. | ||
// Refs https://github.com/gcanti/io-ts/issues/625#issuecomment-1007478009 | ||
C.make(D.union(InstantC, PlainDateC, PlainYearMonthC, NumberFromStringC), { | ||
encode: date => date instanceof Instant | ||
? InstantC.encode(date) | ||
: date instanceof PlainDate | ||
? PlainDateC.encode(date) | ||
: date instanceof PlainYearMonth | ||
? PlainYearMonthC.encode(date) | ||
: NumberFromStringC.encode(date), | ||
}), | ||
dateType: C.string, | ||
})), | ||
descriptions: ReadonlyArrayC(C.struct({ | ||
@@ -83,4 +134,9 @@ description: C.string, | ||
})), | ||
types: C.partial({ | ||
resourceType: C.string, | ||
resourceTypeGeneral: C.string, | ||
}), | ||
url: UrlC, | ||
}), | ||
})), | ||
})), C.imap(({ data }) => data.attributes, work => ({ data: { attributes: work, type: 'dois' } }))); |
{ | ||
"name": "datacite-ts", | ||
"description": "A DataCite API client for use with fp-ts.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "MIT", | ||
@@ -13,2 +13,3 @@ "homepage": "https://github.com/thewilkybarkid/datacite-ts", | ||
"dependencies": { | ||
"@js-temporal/polyfill": "^0.4.3", | ||
"http-status-codes": "^2.2.0", | ||
@@ -15,0 +16,0 @@ "safe-stable-stringify": "^2.4.1" |
13431
197
7
+ Added@js-temporal/polyfill@^0.4.3
+ Added@js-temporal/polyfill@0.4.4(transitive)
+ Addedjsbi@4.3.0(transitive)
+ Addedtslib@2.8.1(transitive)