Skip to content
Merged
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
2 changes: 1 addition & 1 deletion clients/TypeScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"eslint-plugin-standard": "^5.0.0",
"eslint-watch": "^7.0.0",
"jest": "^26.6.3",
"json-schema-to-typescript": "^10.1.4",
"json-schema-to-typescript": "CardanoSolutions/json-schema-to-typescript",
"shx": "^0.3.3",
"ts-jest": "^26.5.3",
"typedoc": "^0.21.4",
Expand Down
4 changes: 3 additions & 1 deletion clients/TypeScript/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@
"http-status-codes": "^2.1.4",
"jest": "^26.6.3",
"jest-puppeteer": "^4.4.0",
"json-schema-to-typescript": "^10.1.4",
"json-schema-to-typescript": "CardanoSolutions/json-schema-to-typescript",
"puppeteer": "^8.0.0",
"shx": "^0.3.3",
"ts-jest": "^26.5.3",
"typescript": "^4.2.3"
},
"dependencies": {
"@cardano-ogmios/schema": "4.0.0-beta.4",
"@types/json-bigint": "^1.0.1",
"cross-fetch": "^3.1.4",
"fastq": "^1.11.0",
"isomorphic-ws": "^4.0.1",
"json-bigint": "^1.0.0",
"nanoid": "^3.1.22",
"ts-custom-error": "^3.2.0",
"ws": "^7.4.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Block, Ogmios, PointOrOrigin, TipOrOrigin } from '@cardano-ogmios/schem
import { InteractionContext } from '../Connection'
import { UnknownResultError } from '../errors'
import fastq from 'fastq'
import { createPointFromCurrentTip, ensureSocketIsOpen } from '../util'
import { createPointFromCurrentTip, ensureSocketIsOpen, safeJSON } from '../util'
import { findIntersect, Intersection } from './findIntersect'
import { requestNext } from './requestNext'

Expand Down Expand Up @@ -69,7 +69,7 @@ export const createChainSyncClient = async (
? fastq.promise(messageHandler, 1).push
: messageHandler
socket.on('message', (message: string) => {
const response: Ogmios['RequestNextResponse'] = JSON.parse(message)
const response: Ogmios['RequestNextResponse'] = safeJSON.parse(message)
if (response.methodname === 'RequestNext') {
responseHandler(response)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Ogmios } from '@cardano-ogmios/schema'
import { baseRequest } from '../Request'
import { safeJSON } from '../util'
import WebSocket from 'isomorphic-ws'

/** A value set when sending the request, to be mirrored by the server in the corresponding response.
Expand All @@ -12,7 +13,7 @@ export const requestNext = (
socket: WebSocket,
options?: { mirror?: Mirror }
): void => {
socket.send(JSON.stringify({
socket.send(safeJSON.stringify({
...baseRequest,
methodname: 'RequestNext',
mirror: options?.mirror
Expand Down
5 changes: 3 additions & 2 deletions clients/TypeScript/packages/client/src/StateQuery/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { nanoid } from 'nanoid'
import { Data } from 'isomorphic-ws'
import { InteractionContext } from '../Connection'
import { baseRequest, send } from '../Request'
import { safeJSON } from '../util'

/** @internal */
export const Query = <
Expand All @@ -27,7 +28,7 @@ export const Query = <
const requestId = nanoid(5)

async function listener (data: Data) {
const queryResponse = JSON.parse(data as string) as QueryResponse
const queryResponse = safeJSON.parse(data as string) as QueryResponse
if (queryResponse.reflection?.requestId !== requestId) { return }
await response.handler(
queryResponse,
Expand All @@ -38,7 +39,7 @@ export const Query = <
}

socket.on('message', listener)
socket.send(JSON.stringify({
socket.send(safeJSON.stringify({
...baseRequest,
methodname: request.methodName,
args: request.args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
stakeDistribution,
utxo
} from './queries'
import { createPointFromCurrentTip, ensureSocketIsOpen } from '../util'
import { createPointFromCurrentTip, ensureSocketIsOpen, safeJSON } from '../util'

/**
* A State Query client.
Expand Down Expand Up @@ -62,7 +62,7 @@ export const createStateQueryClient = async (
return new Promise((resolve, reject) => {
const requestId = nanoid(5)
socket.once('message', (message: string) => {
const response: Ogmios['AcquireResponse'] = JSON.parse(message)
const response: Ogmios['AcquireResponse'] = safeJSON.parse(message)
if (response.reflection.requestId !== requestId) { return }
if ('AcquireSuccess' in response.result) {
return resolve({
Expand Down Expand Up @@ -106,7 +106,7 @@ export const createStateQueryClient = async (
const releaseRequestId = nanoid(5)
socket.once('message', (message: string) => {
socket.once('close', () => {
const response: Ogmios['ReleaseResponse'] = JSON.parse(message)
const response: Ogmios['ReleaseResponse'] = safeJSON.parse(message)
if (response.reflection.requestId !== releaseRequestId) { return }
if (response.result === 'Released') {
resolve()
Expand All @@ -116,7 +116,7 @@ export const createStateQueryClient = async (
})
socket.close()
})
socket.send(JSON.stringify({
socket.send(safeJSON.stringify({
...baseRequest,
methodname: 'Release',
mirror: { requestId: releaseRequestId }
Expand Down Expand Up @@ -154,7 +154,7 @@ export const createStateQueryClient = async (
socket.close()
}
})
socket.send(JSON.stringify({
socket.send(safeJSON.stringify({
...baseRequest,
methodname: 'Acquire',
args: { point },
Expand Down
Loading