From 0fb5a0c90d1d418c1cbd6c40d1eaacaa1261c68f Mon Sep 17 00:00:00 2001 From: Wil Wade Date: Wed, 9 Jun 2021 15:38:40 -0400 Subject: [PATCH] Pre release QA Part 2 (#58) * Storage -> Store * Export core/messages --- .gitignore | 2 +- README.md | 6 +++--- src/config.ts | 6 +++--- src/content.ts | 8 ++++---- src/core/index.ts | 7 +++++-- src/core/{storage => store}/index.ts | 2 +- .../{storage/storage.test.ts => store/interface.test.ts} | 4 ++-- src/core/{storage/storage.ts => store/interface.ts} | 4 ++-- src/core/{storage => store}/s3Node.test.ts | 0 src/core/{storage => store}/s3Node.ts | 4 ++-- 10 files changed, 23 insertions(+), 20 deletions(-) rename src/core/{storage => store}/index.ts (95%) rename src/core/{storage/storage.test.ts => store/interface.test.ts} (96%) rename src/core/{storage/storage.ts => store/interface.ts} (92%) rename src/core/{storage => store}/s3Node.test.ts (100%) rename src/core/{storage => store}/s3Node.ts (95%) diff --git a/.gitignore b/.gitignore index 1b79ab97..6cdf95c8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ dist *.js *.d.ts docs -core +/core ### ignore typechain types /src/types/typechain/* diff --git a/README.md b/README.md index 8574e71c..e57b3d17 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ setConfig({ Amazon S3 is supported when adding the following configuration: ```typescript import { setConfig } from "@dsnp/sdk"; -import { S3Node } from "@dsnp/sdk/core/storage"; +import { S3Node } from "@dsnp/sdk/core/store"; setConfig({ ..., @@ -59,7 +59,7 @@ setConfig({ ``` Other storage solutions can be added so as long it contains the following interface. ```typescript -interface StorageInterface { +interface StoreInterface { put: (targetPath: string, content: Content) => Promise; get?: (targetPath: string) => Promise; } @@ -68,7 +68,7 @@ interface StorageInterface { ``` config .setConfig({ - storage: new MyStorage() + store: new MyStore() }); ``` diff --git a/src/config.ts b/src/config.ts index 4ce1be8b..2640303b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,8 +1,8 @@ import { ethers } from "ethers"; import MemoryQueue from "./core/queue/memoryQueue"; -import { QueueInterface } from "./core/queue/queue"; -import { StorageInterface } from "./core/storage/storage"; +import { QueueInterface } from "./core/queue"; +import { StoreInterface } from "./core/store"; import { HexString } from "./types/Strings"; /** @@ -16,7 +16,7 @@ export interface Config { /** The queue manages Announcements waiting to be batched */ queue: QueueInterface; /** The Storage handles storing batch, content, and other media files at a publicly accessible location */ - store?: StorageInterface; + store?: StoreInterface; /** Contracts are different addresses for specific contracts or for running custom tests */ contracts: { /** The Address of the Batch Announce contract */ diff --git a/src/content.ts b/src/content.ts index d188937e..4c3bef62 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,5 +1,5 @@ // import * as config from "../config/config"; -// import * as storage from "../storage/storage"; +// import * as store from "../store"; import { ActivityPubOpts } from "./core/activityPub/activityPub"; import { ConfigOpts } from "./config"; import { NotImplementedError } from "./core/utilities/errors"; @@ -20,7 +20,7 @@ export const broadcast = async (_content: ActivityPubOpts, _opts?: ConfigOpts): // // const activityPubObject = activityPub.create(activityPubOpts); // const activityPubHash = activityPub.hash(activityPubObject); - // const uri = storage.store(activityPubObject, opts); + // const uri = store.put(activityPubObject, opts); // // return events.createBroadcastEvent(uri, activityPubHash); }; @@ -41,7 +41,7 @@ export const reply = async (_content: ActivityPubOpts, _opts?: ConfigOpts): Prom // const inReplyTo = activityPubOpts.inReplyTo; // const activityPubObject = activityPub.create(activityPubOpts); // const activityPubHash = activityPub.hash(activityPubObject); - // const uri = storage.store(activityPubObject, opts); + // const uri = store.put(activityPubObject, opts); // // return events.createReplyEvent(uri, inReplyTo, activityPubHash); }; @@ -63,7 +63,7 @@ export const react = async (_emoji: string, _inReplyTo: string, _opts?: ConfigOp // const inReplyTo = activityPubOpts.inReplyTo; // const activityPubObject = activityPub.create(activityPubOpts); // const activityPubHash = activityPub.hash(activityPubObject); - // const uri = storage.store(activityPubObject, opts); + // const uri = store.put(activityPubObject, opts); // // return events.createReactionEvent(uri, inReplyTo, activityPubHash); }; diff --git a/src/core/index.ts b/src/core/index.ts index d9951111..b9eb63b7 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -18,11 +18,14 @@ export const batch = batchImport; import * as contractsImport from "./contracts"; export const contracts = contractsImport; +import * as messagesImport from "./messages"; +export const messages = messagesImport; + import * as queueImport from "./queue"; export const queue = queueImport; -import * as storageImport from "./storage"; -export const storage = storageImport; +import * as storeImport from "./store"; +export const store = storeImport; import * as utilitiesImport from "./utilities"; export const utilities = utilitiesImport; diff --git a/src/core/storage/index.ts b/src/core/store/index.ts similarity index 95% rename from src/core/storage/index.ts rename to src/core/store/index.ts index c11c4ad8..c8180651 100644 --- a/src/core/storage/index.ts +++ b/src/core/store/index.ts @@ -17,5 +17,5 @@ * - `import { foo } from "@dsnp/sdk/contracts"; foo.functionInFoo();` */ -export * from "./storage"; +export * from "./interface"; export * from "./s3Node"; diff --git a/src/core/storage/storage.test.ts b/src/core/store/interface.test.ts similarity index 96% rename from src/core/storage/storage.test.ts rename to src/core/store/interface.test.ts index 94d0fe7a..97dc1ca3 100644 --- a/src/core/storage/storage.test.ts +++ b/src/core/store/interface.test.ts @@ -1,10 +1,10 @@ import { getConfig } from "../../config"; import { MissingStoreError, NotImplementedError } from "../utilities"; -import { get, put } from "./storage"; +import { get, put } from "./interface"; jest.mock("../../config"); -describe("storage", () => { +describe("store", () => { describe("#get", () => { describe("when store configuration is not set", () => { beforeEach(() => { diff --git a/src/core/storage/storage.ts b/src/core/store/interface.ts similarity index 92% rename from src/core/storage/storage.ts rename to src/core/store/interface.ts index 3b0da9db..dfbb46e8 100644 --- a/src/core/storage/storage.ts +++ b/src/core/store/interface.ts @@ -5,11 +5,11 @@ export type File = Buffer | string; export type Content = string | Buffer; /** - * StorageInterface is the interface a storage adapter is expected to implement to + * StoreInterface is the interface a storage adapter is expected to implement to * be used with high-level methods in this SDK. The require methods consist of * an put function, a dequeue function and a get function. */ -export interface StorageInterface { +export interface StoreInterface { put: (targetPath: string, content: Content) => Promise; get?: (targetPath: string) => Promise; } diff --git a/src/core/storage/s3Node.test.ts b/src/core/store/s3Node.test.ts similarity index 100% rename from src/core/storage/s3Node.test.ts rename to src/core/store/s3Node.test.ts diff --git a/src/core/storage/s3Node.ts b/src/core/store/s3Node.ts similarity index 95% rename from src/core/storage/s3Node.ts rename to src/core/store/s3Node.ts index f4f1c452..473476f5 100644 --- a/src/core/storage/s3Node.ts +++ b/src/core/store/s3Node.ts @@ -1,5 +1,5 @@ import { S3Client, S3ClientConfig, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3"; -import { StorageInterface } from "./storage"; +import { StoreInterface } from "./interface"; import { Readable } from "stream"; /** @@ -16,7 +16,7 @@ export interface S3Credentials extends S3ClientConfig { * S3Node provides a storage solution for saving DSNP messages * This adapter is provided for convenience can be used in other applications configuration. */ -export class S3Node implements StorageInterface { +export class S3Node implements StoreInterface { client: S3Client; bucket: string; region: string;