Skip to content

Commit

Permalink
feat: 🎸 update datastore->1.0.0
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 🧨 update datastore->1.0.0
  • Loading branch information
waynewyang committed Jan 4, 2024
1 parent 36c0f87 commit 0559957
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 43 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@glif/filecoin-number": "^2.0.69",
"@glif/filecoin-rpc-client": "^2.0.43",
"@types/cbor": "^6.0.0",
"@unipackage/datastore": "^0.3.0",
"@unipackage/datastore": "^1.0.0",
"@unipackage/ddd": "^1.1.0",
"@unipackage/net": "^2.5.1",
"cbor": "^9.0.1",
Expand Down
20 changes: 11 additions & 9 deletions src/chain/repo/datastore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
* limitations under the respective licenses.
********************************************************************************/

import { DataStore, DatabaseOptions } from "@unipackage/datastore"
import {
DataStore,
DatabaseConnection,
DatabaseConnectionOptions,
} from "@unipackage/datastore"
import { Message } from "../../../basic/message/types"
import { BlockMessages } from "../../../basic/block/types"
import { Tipset } from "../../../basic/tipset/types"
Expand All @@ -38,12 +42,11 @@ export class MessageMongoDatastore extends DataStore<
ValueFields<Message>,
MessageDocument
> {
constructor(uri: string, options?: DatabaseOptions) {
constructor(connection: DatabaseConnection) {
super(
new MongooseDataStore<ValueFields<Message>, MessageDocument>(
MessageModel,
uri,
options
connection
)
)
}
Expand All @@ -67,12 +70,12 @@ export class BlockMongoDatastore extends DataStore<
ValueFields<BlockMessages>,
BlockMessagesDocument
> {
constructor(uri: string, options?: DatabaseOptions) {
constructor(connection: DatabaseConnection) {
super(
new MongooseDataStore<
ValueFields<BlockMessages>,
BlockMessagesDocument
>(BlockMessagesModel, uri, options)
>(BlockMessagesModel, connection)
)
}

Expand All @@ -94,12 +97,11 @@ export class TipsetMongoDatastore extends DataStore<
ValueFields<Tipset>,
TipsetDocument
> {
constructor(uri: string, options?: DatabaseOptions) {
constructor(connection: DatabaseConnection) {
super(
new MongooseDataStore<ValueFields<Tipset>, TipsetDocument>(
TipsetModel,
uri,
options
connection
)
)
}
Expand Down
14 changes: 0 additions & 14 deletions src/chain/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,6 @@ export class ChainService implements ChainService {
error: undefined,
}
try {
// Connect to data stores.
const msgConnect = await this.messageDs.connect()
if (!msgConnect.ok) return { ok: false, error: msgConnect.error }
const bmConnect = await this.blockMessagesDs.connect()
if (!bmConnect.ok) return { ok: false, error: bmConnect.error }
const tsConnect = await this.tipsetDs.connect()
if (!tsConnect.ok) return { ok: false, error: tsConnect.error }

// Save messages to the data store.
const msgDoResults = await Promise.all(
chain.messages.map(
Expand Down Expand Up @@ -206,12 +198,6 @@ export class ChainService implements ChainService {
result.error = error
return result
} finally {
// Disconnect from data stores.
/*
await this.tipsetDs.disconnect();
await this.blockMessagesDs.disconnect();
await this.messageDs.disconnect();
*/
}

return result
Expand Down
15 changes: 8 additions & 7 deletions test/chain/service/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
* limitations under the respective licenses.
********************************************************************************/

import { messageDs, blockDs, tipsetDs } from "../../helper/mongodb/instance"
import {
messageDs,
blockDs,
tipsetDs,
connection_noAuth,
} from "../../helper/mongodb/instance"
import "mocha"
import { ChainFilecoinRPC } from "../../../src/chain/repo/rpc" // Replace with the actual path to your TypeScript file
import { ChainService } from "../../../src/chain/service" // Replace with the actual path to your TypeScript file
Expand All @@ -42,15 +47,11 @@ describe("ChainService", () => {
})

beforeEach(async () => {
await tipsetDs.connect()
await blockDs.connect()
await messageDs.connect()
await connection_noAuth.connect()
})

afterEach(async () => {
await tipsetDs.disconnect()
await blockDs.disconnect()
await messageDs.disconnect()
await connection_noAuth.disconnect()
})

describe("GetAndSaveChainInfoByHeight", () => {
Expand Down
15 changes: 7 additions & 8 deletions test/helper/mongodb/instance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@
* limitations under the respective licenses.
********************************************************************************/

import { DatabaseConnection } from "@unipackage/datastore"
import {
MessageMongoDatastore,
BlockMongoDatastore,
TipsetMongoDatastore,
} from "../../../../src/chain/repo/datastore"

export const messageDs = new MessageMongoDatastore(
"mongodb://127.0.0.1:27017/datastore"
)
export const blockDs = new BlockMongoDatastore(
"mongodb://127.0.0.1:27017/datastore"
)
export const tipsetDs = new TipsetMongoDatastore(
export const connection_noAuth = DatabaseConnection.getInstance(
"mongodb://127.0.0.1:27017/datastore"
)
export const messageDs = new MessageMongoDatastore(connection_noAuth)
export const blockDs = new BlockMongoDatastore(connection_noAuth)
export const tipsetDs = new TipsetMongoDatastore(connection_noAuth)

export const messageAuthDs = new MessageMongoDatastore(
export const connection_auth = DatabaseConnection.getInstance(
"mongodb://127.0.0.1:27018/datastoreAuth",
{
user: "admin",
Expand All @@ -46,3 +44,4 @@ export const messageAuthDs = new MessageMongoDatastore(
tlsAllowInvalidHostnames: true,
}
)
export const messageAuthDs = new MessageMongoDatastore(connection_auth)

0 comments on commit 0559957

Please sign in to comment.