From dbd49771cc72ba4edfe94338a1e30b729df74aa5 Mon Sep 17 00:00:00 2001 From: jerempy <95110820+jerempy@users.noreply.github.com> Date: Sun, 15 Oct 2023 21:56:40 -0400 Subject: [PATCH] run prettier with new plugin --- .prettierrc.json | 6 +-- examples/node/stream-data.js | 4 +- src/dwn-server.ts | 10 +++-- src/http-api.ts | 16 ++++---- src/json-rpc-api.ts | 3 +- src/json-rpc-handlers/dwn/process-message.ts | 10 ++--- src/lib/json-rpc-router.ts | 2 + src/main.ts | 4 +- src/storage.ts | 16 ++++---- src/ws-api.ts | 10 +++-- tests/dwn-process-message.spec.ts | 8 ++-- tests/http-api.spec.ts | 39 ++++++++++---------- tests/ws-api.spec.ts | 10 ++--- 13 files changed, 71 insertions(+), 67 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index cfc4729..18ab2db 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,8 +1,6 @@ { "singleQuote": true, - "plugins": [ - "@trivago/prettier-plugin-sort-imports" - ], + "plugins": ["@trivago/prettier-plugin-sort-imports"], "importOrder": [ "^@tbd54566975/(.*)$", "", @@ -11,4 +9,4 @@ ], "importOrderCaseInsensitive": true, "importOrderSeparation": true -} \ No newline at end of file +} diff --git a/examples/node/stream-data.js b/examples/node/stream-data.js index 53f05c0..194e5ab 100644 --- a/examples/node/stream-data.js +++ b/examples/node/stream-data.js @@ -1,6 +1,6 @@ -import fetch from 'node-fetch'; - import { RecordsRead } from '@tbd54566975/dwn-sdk-js'; + +import fetch from 'node-fetch'; import { v4 as uuidv4 } from 'uuid'; import { createJsonRpcRequest } from '../../dist/src/lib/json-rpc.js'; diff --git a/src/dwn-server.ts b/src/dwn-server.ts index dd31d0d..53a3a4f 100644 --- a/src/dwn-server.ts +++ b/src/dwn-server.ts @@ -1,15 +1,17 @@ import { Dwn } from '@tbd54566975/dwn-sdk-js'; + +import type { Server } from 'http'; import log from 'loglevel'; import prefix from 'loglevel-plugin-prefix'; -import type { Server } from 'http'; import { type WebSocketServer } from 'ws'; -import { getDWNConfig } from './storage.js'; -import { HttpApi } from './http-api.js'; import { HttpServerShutdownHandler } from './lib/http-server-shutdown-handler.js'; + +import { type Config, config as defaultConfig } from './config.js'; +import { HttpApi } from './http-api.js'; import { setProcessHandlers } from './process-handlers.js'; +import { getDWNConfig } from './storage.js'; import { WsApi } from './ws-api.js'; -import { type Config, config as defaultConfig } from './config.js'; export type DwnServerOptions = { dwn?: Dwn; diff --git a/src/http-api.ts b/src/http-api.ts index 4754207..dbe1038 100644 --- a/src/http-api.ts +++ b/src/http-api.ts @@ -1,26 +1,26 @@ -import http from 'http'; import { type Dwn, RecordsRead, type RecordsReadReply, } from '@tbd54566975/dwn-sdk-js'; -import type { Express, Request, Response } from 'express'; - -import type { JsonRpcRequest } from './lib/json-rpc.js'; -import type { RequestContext } from './lib/json-rpc-router.js'; import cors from 'cors'; +import type { Express, Request, Response } from 'express'; import express from 'express'; +import http from 'http'; import log from 'loglevel'; -import responseTime from 'response-time'; - -import { jsonRpcApi } from './json-rpc-api.js'; import { register } from 'prom-client'; +import responseTime from 'response-time'; import { v4 as uuidv4 } from 'uuid'; + +import type { RequestContext } from './lib/json-rpc-router.js'; +import type { JsonRpcRequest } from './lib/json-rpc.js'; import { createJsonRpcErrorResponse, JsonRpcErrorCodes, } from './lib/json-rpc.js'; + +import { jsonRpcApi } from './json-rpc-api.js'; import { requestCounter, responseHistogram } from './metrics.js'; export class HttpApi { diff --git a/src/json-rpc-api.ts b/src/json-rpc-api.ts index d1f2297..41661e5 100644 --- a/src/json-rpc-api.ts +++ b/src/json-rpc-api.ts @@ -1,6 +1,7 @@ -import { handleDwnProcessMessage } from './json-rpc-handlers/dwn/index.js'; import { JsonRpcRouter } from './lib/json-rpc-router.js'; +import { handleDwnProcessMessage } from './json-rpc-handlers/dwn/index.js'; + export const jsonRpcApi = new JsonRpcRouter(); jsonRpcApi.on('dwn.processMessage', handleDwnProcessMessage); diff --git a/src/json-rpc-handlers/dwn/process-message.ts b/src/json-rpc-handlers/dwn/process-message.ts index 461f86a..cfe705c 100644 --- a/src/json-rpc-handlers/dwn/process-message.ts +++ b/src/json-rpc-handlers/dwn/process-message.ts @@ -1,13 +1,13 @@ -import type { Readable as IsomorphicReadable } from 'readable-stream'; import type { RecordsReadReply } from '@tbd54566975/dwn-sdk-js'; +import { DwnInterfaceName, DwnMethodName } from '@tbd54566975/dwn-sdk-js'; + +import type { Readable as IsomorphicReadable } from 'readable-stream'; +import { v4 as uuidv4 } from 'uuid'; + import type { HandlerResponse, JsonRpcHandler, } from '../../lib/json-rpc-router.js'; - -import { v4 as uuidv4 } from 'uuid'; -import { DwnInterfaceName, DwnMethodName } from '@tbd54566975/dwn-sdk-js'; - import { createJsonRpcErrorResponse, createJsonRpcSuccessResponse, diff --git a/src/lib/json-rpc-router.ts b/src/lib/json-rpc-router.ts index 33f7314..78036c7 100644 --- a/src/lib/json-rpc-router.ts +++ b/src/lib/json-rpc-router.ts @@ -1,5 +1,7 @@ import type { Dwn } from '@tbd54566975/dwn-sdk-js'; + import type { Readable } from 'node:stream'; + import type { JsonRpcRequest, JsonRpcResponse } from './json-rpc.js'; export type RequestContext = { diff --git a/src/main.ts b/src/main.ts index bbfecc9..df58215 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,13 +1,13 @@ // node.js 18 and earlier, needs globalThis.crypto polyfill. needed for dwn-sdk-js import { webcrypto } from 'node:crypto'; +import { DwnServer } from './dwn-server.js'; + if (!globalThis.crypto) { // @ts-ignore globalThis.crypto = webcrypto; } -import { DwnServer } from './dwn-server.js'; - const dwnServer = new DwnServer(); await dwnServer.start(); diff --git a/src/storage.ts b/src/storage.ts index 33c7da2..6719bd6 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -1,5 +1,3 @@ -import type { Config } from './config.js'; -import type { Dialect } from '@tbd54566975/dwn-sql-store'; import { DataStoreLevel, EventLogLevel, @@ -11,12 +9,7 @@ import type { EventLog, MessageStore, } from '@tbd54566975/dwn-sdk-js'; - -import Cursor from 'pg-cursor'; -import Database from 'better-sqlite3'; -import pg from 'pg'; - -import { createPool as MySQLCreatePool } from 'mysql2'; +import type { Dialect } from '@tbd54566975/dwn-sql-store'; import { DataStoreSql, EventLogSql, @@ -26,6 +19,13 @@ import { SqliteDialect, } from '@tbd54566975/dwn-sql-store'; +import Database from 'better-sqlite3'; +import { createPool as MySQLCreatePool } from 'mysql2'; +import pg from 'pg'; +import Cursor from 'pg-cursor'; + +import type { Config } from './config.js'; + export enum EStoreType { DataStore, MessageStore, diff --git a/src/ws-api.ts b/src/ws-api.ts index cfe846b..d63035b 100644 --- a/src/ws-api.ts +++ b/src/ws-api.ts @@ -1,18 +1,20 @@ -import { base64url } from 'multiformats/bases/base64'; -import { v4 as uuidv4 } from 'uuid'; import { DataStream, type Dwn } from '@tbd54566975/dwn-sdk-js'; + import type { IncomingMessage, Server } from 'http'; +import { base64url } from 'multiformats/bases/base64'; +import { v4 as uuidv4 } from 'uuid'; import { type AddressInfo, type WebSocket, WebSocketServer } from 'ws'; -import { jsonRpcApi } from './json-rpc-api.js'; import type { RequestContext } from './lib/json-rpc-router.js'; -import { requestCounter } from './metrics.js'; import { createJsonRpcErrorResponse, JsonRpcErrorCodes, type JsonRpcResponse, } from './lib/json-rpc.js'; +import { jsonRpcApi } from './json-rpc-api.js'; +import { requestCounter } from './metrics.js'; + const SOCKET_ISALIVE_SYMBOL = Symbol('isAlive'); const HEARTBEAT_INTERVAL = 30_000; diff --git a/tests/dwn-process-message.spec.ts b/tests/dwn-process-message.spec.ts index e2c9f75..e6da39e 100644 --- a/tests/dwn-process-message.spec.ts +++ b/tests/dwn-process-message.spec.ts @@ -1,9 +1,9 @@ -import type { RequestContext } from '../src/lib/json-rpc-router.js'; - -import { createJsonRpcRequest } from '../src/lib/json-rpc.js'; import { expect } from 'chai'; -import { handleDwnProcessMessage } from '../src/json-rpc-handlers/dwn/process-message.js'; import { v4 as uuidv4 } from 'uuid'; + +import { handleDwnProcessMessage } from '../src/json-rpc-handlers/dwn/process-message.js'; +import type { RequestContext } from '../src/lib/json-rpc-router.js'; +import { createJsonRpcRequest } from '../src/lib/json-rpc.js'; import { clear as clearDwn, dwn } from './test-dwn.js'; import { createProfile, createRecordsWriteMessage } from './utils.js'; diff --git a/tests/http-api.spec.ts b/tests/http-api.spec.ts index d0d59ca..7188586 100644 --- a/tests/http-api.spec.ts +++ b/tests/http-api.spec.ts @@ -1,34 +1,28 @@ // node.js 18 and earlier, needs globalThis.crypto polyfill -import { webcrypto } from 'node:crypto'; - -if (!globalThis.crypto) { - // @ts-ignore - globalThis.crypto = webcrypto; -} - -import type { Server } from 'http'; -import type { - JsonRpcErrorResponse, - JsonRpcResponse, -} from '../src/lib/json-rpc.js'; - -import fetch from 'node-fetch'; -import request from 'supertest'; - -import { expect } from 'chai'; -import { HttpApi } from '../src/http-api.js'; -import { v4 as uuidv4 } from 'uuid'; import { Cid, DataStream, RecordsQuery, RecordsRead, } from '@tbd54566975/dwn-sdk-js'; -import { clear as clearDwn, dwn } from './test-dwn.js'; + +import { expect } from 'chai'; +import type { Server } from 'http'; +import fetch from 'node-fetch'; +import { webcrypto } from 'node:crypto'; +import request from 'supertest'; +import { v4 as uuidv4 } from 'uuid'; + +import { HttpApi } from '../src/http-api.js'; +import type { + JsonRpcErrorResponse, + JsonRpcResponse, +} from '../src/lib/json-rpc.js'; import { createJsonRpcRequest, JsonRpcErrorCodes, } from '../src/lib/json-rpc.js'; +import { clear as clearDwn, dwn } from './test-dwn.js'; import { createProfile, createRecordsWriteMessage, @@ -36,6 +30,11 @@ import { streamHttpRequest, } from './utils.js'; +if (!globalThis.crypto) { + // @ts-ignore + globalThis.crypto = webcrypto; +} + describe('http api', function () { let httpApi: HttpApi; let server: Server; diff --git a/tests/ws-api.spec.ts b/tests/ws-api.spec.ts index c729f13..6e836aa 100644 --- a/tests/ws-api.spec.ts +++ b/tests/ws-api.spec.ts @@ -1,17 +1,17 @@ -import http from 'node:http'; - -import { base64url } from 'multiformats/bases/base64'; import { DataStream } from '@tbd54566975/dwn-sdk-js'; + import { expect } from 'chai'; +import { base64url } from 'multiformats/bases/base64'; +import http from 'node:http'; import { v4 as uuidv4 } from 'uuid'; import { type WebSocketServer } from 'ws'; -import { WsApi } from '../src/ws-api.js'; -import { clear as clearDwn, dwn } from './test-dwn.js'; import { createJsonRpcRequest, JsonRpcErrorCodes, } from '../src/lib/json-rpc.js'; +import { WsApi } from '../src/ws-api.js'; +import { clear as clearDwn, dwn } from './test-dwn.js'; import { createProfile, createRecordsWriteMessage,