Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dwn-sdk-js to latest version #138

Merged
merged 6 commits into from
Oct 4, 2023
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"@react-navigation/native": "6.1.7",
"@react-navigation/native-stack": "6.9.13",
"@tanstack/react-query": "4.35.3",
"@tbd54566975/dwn-sdk-js": "0.2.1",
"@tbd54566975/dwn-sdk-js": "0.2.3",
"@tbd54566975/web5": "0.7.11",
"@tbd54566975/web5-react-native-metro-config": "0.1.3",
"@tbd54566975/web5-react-native-polyfills": "0.1.3",
"@types/uuid": "9.0.4",
"@web5/api": "0.8.1-alpha-20231003-cd24256",
"@web5/dids": "0.2.0-alpha-20231003-cd24256",
"@web5/identity-agent": "0.2.0",
"@web5/api": "0.8.1-alpha-20231003-e73c548",
"@web5/dids": "0.2.0-alpha-20231003-e73c548",
"@web5/identity-agent": "0.2.1-alpha-20231003-e73c548",
"expo": "49.0.3",
"expo-barcode-scanner": "12.5.3",
"expo-level": "file:assets/expo-level",
Expand Down
26 changes: 0 additions & 26 deletions patches/@tbd54566975+dwn-sdk-js+0.2.1.patch

This file was deleted.

38 changes: 38 additions & 0 deletions src/features/dwn/dwn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
Dwn,
MessageStoreLevel,
DataStoreLevel,
EventLogLevel,
} from "@tbd54566975/dwn-sdk-js";
import { AbstractDatabaseOptions } from "abstract-level";
import { type Level } from "level";
import { ExpoLevel } from "expo-level";

export const createDwn = async () => {
const messageStore = new MessageStoreLevel({
createLevelDatabase: createExpoLevelDatabase,
});

const dataStore = new DataStoreLevel({
createLevelDatabase: createExpoLevelDatabase,
});

const eventLog = new EventLogLevel({
location: "EVENTLOG",
createLevelDatabase: createExpoLevelDatabase,
});

return await Dwn.create({
messageStore,
dataStore,
eventLog,
});
};

const createExpoLevelDatabase = <V>(
location: string,
options?: AbstractDatabaseOptions<string, V>
) => {
const db = new ExpoLevel(location, options);
return Promise.resolve(db as Level<string, V>);
};
35 changes: 1 addition & 34 deletions src/features/identity/IdentityAgentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ import {
profileProtocol,
Profile,
} from "@/features/profile/protocol/profile-protocol";
import {
MessageStoreLevel,
DataStoreLevel,
EventLogLevel,
} from "@tbd54566975/dwn-sdk-js/stores";
import { type Level } from "level";
import { Dwn } from "@tbd54566975/dwn-sdk-js";
import { AbstractDatabaseOptions } from "abstract-level";
import { ExpoLevel } from "expo-level";
import { ExpoLevelStore } from "@/features/app/expo-level-store";
import ms from "ms";
import { createDwn } from "@/features/dwn/dwn";

// Singleton
let agent: IdentityAgent;
Expand All @@ -49,33 +43,6 @@ const initAgent = async () => {
agent = await IdentityAgent.create({ dwnManager, appData, syncManager });
};

const createDwn = async (): Promise<Dwn> => {
const messageStore = new MessageStoreLevel({
createLevelDatabase: createExpoLevelDatabase,
});

const dataStore = new DataStoreLevel({
createLevelDatabase: createExpoLevelDatabase,
});

const eventLog = new EventLogLevel({
createLevelDatabase: createExpoLevelDatabase,
});

return await Dwn.create({
messageStore,
dataStore,
eventLog,
});
};

const createExpoLevelDatabase = (
location: string,
options?: AbstractDatabaseOptions<unknown, unknown>
): ExpoLevel<unknown, unknown> => {
return new ExpoLevel(location, options);
};

const isFirstLaunch = async () => {
return await agent.firstLaunch();
};
Expand Down
5 changes: 3 additions & 2 deletions src/features/profile/fetch-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const fetchProfile = async (
identity: ManagedIdentity
): Promise<FetchProfileResult> => {
const web5 = IdentityAgentManager.web5(identity);

const queryResult = await web5.dwn.records.query({
message: {
filter: {
Expand All @@ -32,7 +31,9 @@ export const fetchProfile = async (

const readResult = await web5.dwn.records.read({
message: {
recordId,
filter: {
recordId,
},
},
});

Expand Down
Loading