Skip to content

Commit

Permalink
run prettier with new plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jerempy committed Oct 16, 2023
1 parent 57f5f1f commit dbd4977
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 67 deletions.
6 changes: 2 additions & 4 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"singleQuote": true,
"plugins": [
"@trivago/prettier-plugin-sort-imports"
],
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"importOrder": [
"^@tbd54566975/(.*)$",
"<THIRD_PARTY_MODULES>",
Expand All @@ -11,4 +9,4 @@
],
"importOrderCaseInsensitive": true,
"importOrderSeparation": true
}
}
4 changes: 2 additions & 2 deletions examples/node/stream-data.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 6 additions & 4 deletions src/dwn-server.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/http-api.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/json-rpc-api.ts
Original file line number Diff line number Diff line change
@@ -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);
10 changes: 5 additions & 5 deletions src/json-rpc-handlers/dwn/process-message.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/json-rpc-router.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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();
16 changes: 8 additions & 8 deletions src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Config } from './config.js';
import type { Dialect } from '@tbd54566975/dwn-sql-store';
import {
DataStoreLevel,
EventLogLevel,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions src/ws-api.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
8 changes: 4 additions & 4 deletions tests/dwn-process-message.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
39 changes: 19 additions & 20 deletions tests/http-api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
// 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,
getFileAsReadStream,
streamHttpRequest,
} from './utils.js';

if (!globalThis.crypto) {
// @ts-ignore
globalThis.crypto = webcrypto;
}

describe('http api', function () {
let httpApi: HttpApi;
let server: Server;
Expand Down
10 changes: 5 additions & 5 deletions tests/ws-api.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit dbd4977

Please sign in to comment.