@cardano-graphql/util
Advanced tools
Comparing version 1.0.0 to 2.0.0-beta.0
import { loadQueryNode } from './queryNodeLoading'; | ||
import * as dateTimeValidation from './dateTimeValidation'; | ||
import * as scalars from './scalars'; | ||
declare const _default: { | ||
dateTimeValidation: typeof dateTimeValidation; | ||
onFailedAttemptFor: (operation: string) => ({ attemptNumber, message, retriesLeft }: import("p-retry").FailedAttemptError) => void; | ||
@@ -7,0 +5,0 @@ loadQueryNode: typeof loadQueryNode; |
@@ -24,6 +24,4 @@ "use strict"; | ||
const queryNodeLoading_1 = require("./queryNodeLoading"); | ||
const dateTimeValidation = __importStar(require("./dateTimeValidation")); | ||
const scalars = __importStar(require("./scalars")); | ||
exports.default = { | ||
dateTimeValidation, | ||
onFailedAttemptFor: onFailedAttemptFor_1.onFailedAttemptFor, | ||
@@ -30,0 +28,0 @@ loadQueryNode: queryNodeLoading_1.loadQueryNode, |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DateTimeUtcToIso = void 0; | ||
const graphql_1 = require("graphql"); | ||
const graphql_scalars_1 = require("graphql-scalars"); | ||
const dateTimeValidation_1 = require("../dateTimeValidation"); | ||
function isoToUtc(isoString) { | ||
return isoString.substring(0, isoString.length - 5); | ||
const dayjs_1 = __importDefault(require("dayjs")); | ||
const utc_1 = __importDefault(require("dayjs/plugin/utc")); | ||
dayjs_1.default.extend(utc_1.default); | ||
function isIsoDateString(string) { | ||
const isoDateRegExp = new RegExp(/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/); | ||
return isoDateRegExp.test(string); | ||
} | ||
exports.DateTimeUtcToIso = new graphql_1.GraphQLScalarType({ | ||
name: 'DateTime', | ||
description: 'UTC DateTime to ISO RFC 3339', | ||
description: 'DateTime ISO 8601', | ||
serialize(value) { | ||
return graphql_scalars_1.DateTimeResolver.serialize.call(this, `${value}Z`).toISOString(); | ||
if (isIsoDateString(value)) { | ||
return value; | ||
} | ||
return dayjs_1.default.utc(value).format('YYYY-MM-DDTHH:mm:ss[Z]'); | ||
}, | ||
@@ -20,6 +28,6 @@ parseValue(value) { | ||
} | ||
if (!dateTimeValidation_1.validateDateTime(value)) { | ||
if (!isIsoDateString(value)) { | ||
throw new TypeError(`DateTime cannot represent an invalid date-time-string ${value}.`); | ||
} | ||
return isoToUtc(value); | ||
return dayjs_1.default.utc(value).format('YYYY-MM-DDTHH:mm:ss'); | ||
}, | ||
@@ -31,8 +39,8 @@ parseLiteral(ast) { | ||
const { value } = ast; | ||
if (!dateTimeValidation_1.validateDateTime(value)) { | ||
if (!isIsoDateString(value)) { | ||
throw new TypeError(`DateTime cannot represent an invalid date-time-string ${String(value)}.`); | ||
} | ||
return isoToUtc(value); | ||
return dayjs_1.default.utc(value).format('YYYY-MM-DDTHH:mm:ss'); | ||
} | ||
}); | ||
//# sourceMappingURL=DateTimeUtcToIso.js.map |
{ | ||
"name": "@cardano-graphql/util", | ||
"version": "1.0.0", | ||
"version": "2.0.0-beta.0", | ||
"description": "Common utilities", | ||
@@ -25,2 +25,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"dayjs": "^1.8.29", | ||
"graphql": "14.5.8", | ||
@@ -33,2 +34,3 @@ "graphql-bigint": "^1.0.0", | ||
"@types/node": "^14.0.13", | ||
"shx": "^0.3.2", | ||
"typescript": "^3.9.5" | ||
@@ -35,0 +37,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
544971
5
3
33
209
2
+ Addeddayjs@^1.8.29
+ Addeddayjs@1.11.13(transitive)