@dsnp/graph-sdk
Advanced tools
Comparing version 0.0.0-ab5a34 to 0.0.0-b34245
@@ -1,2 +0,2 @@ | ||
import { ImportBundle, Update, DsnpGraphEdge, Action, DsnpPublicKey, DsnpKeys, Config } from "./models"; | ||
import { ImportBundle, Update, DsnpGraphEdge, Action, DsnpPublicKey, DsnpKeys, Config, ConnectionType, PrivacyType } from "./models"; | ||
import { EnvironmentInterface } from "./models/environment"; | ||
@@ -8,19 +8,20 @@ export declare class Graph { | ||
getGraphConfig(environment: EnvironmentInterface): Promise<Config>; | ||
getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>; | ||
getGraphCapacity(): Promise<number>; | ||
getGraphSize(): Promise<number>; | ||
getGraphStatesCount(): Promise<number>; | ||
containsUserGraph(dsnpUserId: number): Promise<boolean>; | ||
getGraphUsersCount(): Promise<number>; | ||
removeUserGraph(dsnpUserId: number): Promise<void>; | ||
importUserData(payload: [ImportBundle]): Promise<void>; | ||
exportUpdates(): Promise<Update>; | ||
getConnectionsForUserGraphUpdates(dsnpUserId: number, schemaId: string, includePending: boolean): Promise<[DsnpGraphEdge]>; | ||
applyActions(actions: [Action]): Promise<void>; | ||
forceCalculateGraphs(dsnpUserId: number): Promise<Update>; | ||
getConnectionsWithoutKeys(): Promise<[number]>; | ||
getOneSidedPrivateFriendshipConnections(dsnpUserId: number): Promise<[DsnpGraphEdge]>; | ||
getPublicKeys(dsnpUserId: number): Promise<[DsnpPublicKey]>; | ||
deserializeDsnpKeys(keys: DsnpKeys): Promise<[DsnpPublicKey]>; | ||
freeGraphState(): Promise<void>; | ||
removeUserGraph(dsnpUserId: number): Promise<boolean>; | ||
importUserData(payload: ImportBundle[]): Promise<boolean>; | ||
exportUpdates(): Promise<Update[]>; | ||
getConnectionsForUserGraph(dsnpUserId: number, schemaId: number, includePending: boolean): Promise<DsnpGraphEdge[]>; | ||
applyActions(actions: Action[]): Promise<boolean>; | ||
forceCalculateGraphs(dsnpUserId: number): Promise<Update[]>; | ||
getConnectionsWithoutKeys(): Promise<number[]>; | ||
getOneSidedPrivateFriendshipConnections(dsnpUserId: number): Promise<DsnpGraphEdge[]>; | ||
getPublicKeys(dsnpUserId: number): Promise<DsnpPublicKey[]>; | ||
deserializeDsnpKeys(keys: DsnpKeys): Promise<DsnpPublicKey[]>; | ||
freeGraphState(): Promise<boolean>; | ||
printHelloGraph(): void; | ||
} | ||
//# sourceMappingURL=graph.d.ts.map |
@@ -20,7 +20,10 @@ "use strict"; | ||
} | ||
getSchemaIdFromConfig(environment, connectionType, privacyType) { | ||
return index_1.graphsdkModule.getSchemaIdFromConfig(environment, connectionType, privacyType); | ||
} | ||
getGraphCapacity() { | ||
return index_1.graphsdkModule.getGraphCapacity(this.handle); | ||
} | ||
getGraphSize() { | ||
return index_1.graphsdkModule.getGraphSize(this.handle); | ||
getGraphStatesCount() { | ||
return index_1.graphsdkModule.getGraphStatesCount(); | ||
} | ||
@@ -42,4 +45,4 @@ containsUserGraph(dsnpUserId) { | ||
} | ||
getConnectionsForUserGraphUpdates(dsnpUserId, schemaId, includePending) { | ||
return index_1.graphsdkModule.getConnectionsForUserGraphUpdates(this.handle, dsnpUserId, schemaId, includePending); | ||
getConnectionsForUserGraph(dsnpUserId, schemaId, includePending) { | ||
return index_1.graphsdkModule.getConnectionsForUserGraph(this.handle, dsnpUserId, schemaId, includePending); | ||
} | ||
@@ -46,0 +49,0 @@ applyActions(actions) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const graph_1 = require("./graph"); | ||
const config_1 = require("./models/config"); | ||
const environment_1 = require("./models/environment"); | ||
function getTestConfig() { | ||
const config = {}; | ||
config.sdkMaxUsersGraphSize = 100; | ||
config.sdkMaxStaleFriendshipDays = 100; | ||
config.maxPageId = 100; | ||
config.dsnpVersions = [config_1.DsnpVersion.Version1_0]; | ||
config.maxGraphPageSizeBytes = 100; | ||
config.maxKeyPageSizeBytes = 100; | ||
const schemaConfig = {}; | ||
schemaConfig.dsnpVersion = config_1.DsnpVersion.Version1_0; | ||
schemaConfig.connectionType = config_1.ConnectionType.Follow; | ||
schemaConfig.privacyType = config_1.PrivacyType.Public; | ||
config.schemaMap = { 1: schemaConfig }; | ||
return config; | ||
} | ||
test('printHelloGraph should print "Hello, Graph!"', async () => { | ||
// Mock the console.log function | ||
const consoleLogMock = jest.spyOn(console, 'log').mockImplementation(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config: {} }; | ||
const environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
const graph = new graph_1.Graph(environment); | ||
@@ -15,7 +31,8 @@ await graph.printHelloGraph(); | ||
test('getGraphConfig should return the graph config', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config: {} }; | ||
const config_input = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config: config_input }; | ||
const graph = new graph_1.Graph(environment); | ||
const config = await graph.getGraphConfig(environment); | ||
expect(config).toBeDefined(); | ||
expect(config.sdkMaxUsersGraphSize).toEqual(1000); | ||
expect(config.sdkMaxUsersGraphSize).toEqual(100); | ||
await graph.freeGraphState(); | ||
@@ -29,2 +46,4 @@ }); | ||
expect(config.sdkMaxUsersGraphSize).toEqual(1000); | ||
const schema_id = await graph.getSchemaIdFromConfig(environment, config_1.ConnectionType.Follow, config_1.PrivacyType.Public); | ||
expect(schema_id).toEqual(1); | ||
await graph.freeGraphState(); | ||
@@ -41,3 +60,4 @@ }); | ||
test('initialize graph with low capacity of 100 should return the same capacity', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config: {} }; | ||
const config = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config }; | ||
const graph = new graph_1.Graph(environment, 100); | ||
@@ -50,2 +70,209 @@ const handle = graph.getGraphHandle(); | ||
}); | ||
test('getGraphStatesCount should be zero after previous graph is freed', async () => { | ||
const config = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
await graph.freeGraphState(); | ||
const count = await graph.getGraphStatesCount(); | ||
expect(count).toEqual(0); | ||
}); | ||
test('getGraphStatesCount should be one after graph is initialized', async () => { | ||
const config = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
const count = await graph.getGraphStatesCount(); | ||
expect(count).toEqual(1); | ||
await graph.freeGraphState(); | ||
}); | ||
test('getGraphUsersCount should be zero on initialized graph', async () => { | ||
const config = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
const count = await graph.getGraphUsersCount(); | ||
expect(count).toEqual(0); | ||
await graph.freeGraphState(); | ||
await expect(async () => { | ||
await graph.getGraphUsersCount(); | ||
}).rejects.toThrow('Graph state not found'); | ||
}); | ||
test('containsUserGraph should return false on initialized graph', async () => { | ||
const config = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
const contains = await graph.containsUserGraph(1); | ||
expect(contains).toEqual(false); | ||
await graph.freeGraphState(); | ||
}); | ||
test('removeUserGraph should pass through on initialized graph', async () => { | ||
const config = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
const removed = await graph.removeUserGraph(1); | ||
expect(removed).toEqual(true); | ||
await graph.freeGraphState(); | ||
}); | ||
test('importUserData should pass through on initialized graph', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
// Set up import data | ||
const dsnpUserId1 = 1; | ||
const dsnpUserId2 = 2; | ||
const pageData1 = { | ||
pageId: 1, | ||
content: new Uint8Array([24, 227, 96, 97, 96, 99, 224, 96, 224, 98, 96, 0, 0]), | ||
contentHash: 100, | ||
}; | ||
const keyPairs1 = []; | ||
const keyPairs2 = []; | ||
const dsnpKeys1 = { | ||
dsnpUserId: dsnpUserId1, | ||
keysHash: 100, | ||
keys: [], | ||
}; | ||
const dsnpKeys2 = { | ||
dsnpUserId: dsnpUserId2, | ||
keysHash: 100, | ||
keys: [], | ||
}; | ||
const importBundle1 = { | ||
dsnpUserId: dsnpUserId1, | ||
schemaId: 1, | ||
keyPairs: keyPairs1, | ||
dsnpKeys: dsnpKeys1, | ||
pages: [pageData1], | ||
}; | ||
const importBundle2 = { | ||
dsnpUserId: dsnpUserId2, | ||
schemaId: 1, | ||
keyPairs: keyPairs2, | ||
dsnpKeys: dsnpKeys2, | ||
pages: [pageData1], | ||
}; | ||
// Import user data for each ImportBundle | ||
const imported = await graph.importUserData([importBundle1, importBundle2]); | ||
expect(imported).toEqual(true); | ||
await graph.freeGraphState(); | ||
}); | ||
test('applyActions with empty actions should pass through on initialized graph', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
// Set up actions | ||
const actions = []; | ||
const applied = await graph.applyActions(actions); | ||
expect(applied).toEqual(true); | ||
await graph.freeGraphState(); | ||
}); | ||
test('applyActions with few actions should pass through on initialized graph', async () => { | ||
const config = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
// Set up actions | ||
const actions = []; | ||
const action_1 = { | ||
type: "Connect", | ||
ownerDsnpUserId: 1, | ||
connection: { | ||
dsnpUserId: 2, | ||
schemaId: 1, | ||
}, | ||
dsnpKeys: { | ||
dsnpUserId: 2, | ||
keysHash: 100, | ||
keys: [], | ||
}, | ||
}; | ||
actions.push(action_1); | ||
const applied = await graph.applyActions(actions); | ||
expect(applied).toEqual(true); | ||
const exported = await graph.exportUpdates(); | ||
expect(exported).toBeDefined(); | ||
expect(exported.length).toEqual(1); | ||
await graph.freeGraphState(); | ||
}); | ||
test('getConnectionsForUserGraph with empty connections should return empty array', async () => { | ||
const config = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
// Set up actions | ||
const actions = []; | ||
const action_1 = { | ||
type: "Connect", | ||
ownerDsnpUserId: 1, | ||
connection: { | ||
dsnpUserId: 2, | ||
schemaId: 1, | ||
}, | ||
dsnpKeys: { | ||
dsnpUserId: 2, | ||
keysHash: 100, | ||
keys: [], | ||
}, | ||
}; | ||
actions.push(action_1); | ||
const applied = await graph.applyActions(actions); | ||
expect(applied).toEqual(true); | ||
const connections = await graph.getConnectionsForUserGraph(1, 1, true); | ||
expect(connections).toBeDefined(); | ||
expect(connections.length).toEqual(1); | ||
const forceCalculateGraphs = await graph.forceCalculateGraphs(1); | ||
expect(forceCalculateGraphs).toBeDefined(); | ||
expect(forceCalculateGraphs.length).toEqual(0); | ||
await graph.freeGraphState(); | ||
}); | ||
test('getConnectionsWithoutKeys with empty connections should return empty array', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
const connections = await graph.getConnectionsWithoutKeys(); | ||
expect(connections).toBeDefined(); | ||
expect(connections.length).toEqual(0); | ||
expect(async () => { | ||
await graph.getOneSidedPrivateFriendshipConnections(1); | ||
}).rejects.toThrow('User graph for 1 is not imported'); | ||
await graph.freeGraphState(); | ||
}); | ||
test('getPublicKeys with empty connections should return empty array', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
const connections = await graph.getPublicKeys(1); | ||
expect(connections).toBeDefined(); | ||
expect(connections.length).toEqual(0); | ||
await graph.freeGraphState(); | ||
}); | ||
test('deserializeDsnpKeys with empty keys should return empty array', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
const graph = new graph_1.Graph(environment); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
const keys = { | ||
dsnpUserId: 2, | ||
keysHash: 100, | ||
keys: [], | ||
}; | ||
const connections = await graph.deserializeDsnpKeys(keys); | ||
expect(connections).toBeDefined(); | ||
expect(connections.length).toEqual(0); | ||
await graph.freeGraphState(); | ||
}); | ||
//# sourceMappingURL=graph.test.js.map |
@@ -1,2 +0,2 @@ | ||
import { Action, Config, DsnpGraphEdge, DsnpKeys, DsnpPublicKey, EnvironmentInterface, ImportBundle, Update } from "./models"; | ||
import { Action, Config, ConnectionType, DsnpGraphEdge, DsnpKeys, DsnpPublicKey, EnvironmentInterface, ImportBundle, PrivacyType, Update } from "./models"; | ||
export interface Native { | ||
@@ -7,20 +7,20 @@ printHelloGraph(): void; | ||
getGraphConfig(environment: EnvironmentInterface): Promise<Config>; | ||
getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>; | ||
getGraphCapacity(handle: number): Promise<number>; | ||
getGraphSize(handle: number): Promise<number>; | ||
getGraphStatesCount(): Promise<number>; | ||
getGraphUsersCount(handle: number): Promise<number>; | ||
containsUserGraph(handle: number, dsnpUserId: number): Promise<boolean>; | ||
getGraphUsersCount(handle: number): Promise<number>; | ||
removeUserGraph(handle: number, dsnpUserId: number): Promise<void>; | ||
importUserData(handle: number, payload: [ImportBundle]): Promise<void>; | ||
exportUpdates(handle: number): Promise<Update>; | ||
getConnectionsForUserGraphUpdates(handle: number, dsnpUserId: number, schemaId: string, includePending: boolean): Promise<[DsnpGraphEdge]>; | ||
applyActions(handle: number, actions: [Action]): Promise<void>; | ||
forceCalculateGraphs(handle: number, dsnpUserId: number): Promise<Update>; | ||
getConnectionsWithoutKeys(handle: number): Promise<[number]>; | ||
getOneSidedPrivateFriendshipConnections(handle: number, dsnpUserId: number): Promise<[DsnpGraphEdge]>; | ||
getPublicKeys(handle: number, dsnpUserId: number): Promise<[DsnpPublicKey]>; | ||
deserializeDsnpKeys(keys: DsnpKeys): Promise<[DsnpPublicKey]>; | ||
freeGraphState(handle: number): Promise<void>; | ||
freeAllGraphStates(): Promise<void>; | ||
removeUserGraph(handle: number, dsnpUserId: number): Promise<boolean>; | ||
importUserData(handle: number, payload: ImportBundle[]): Promise<boolean>; | ||
applyActions(handle: number, actions: Action[]): Promise<boolean>; | ||
exportUpdates(handle: number): Promise<Update[]>; | ||
getConnectionsForUserGraph(handle: number, dsnpUserId: number, schemaId: number, includePending: boolean): Promise<DsnpGraphEdge[]>; | ||
forceCalculateGraphs(handle: number, dsnpUserId: number): Promise<Update[]>; | ||
getConnectionsWithoutKeys(handle: number): Promise<number[]>; | ||
getOneSidedPrivateFriendshipConnections(handle: number, dsnpUserId: number): Promise<DsnpGraphEdge[]>; | ||
getPublicKeys(handle: number, dsnpUserId: number): Promise<DsnpPublicKey[]>; | ||
deserializeDsnpKeys(keys: DsnpKeys): Promise<DsnpPublicKey[]>; | ||
freeGraphState(handle: number): Promise<boolean>; | ||
} | ||
export declare const graphsdkModule: Native; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const graph_1 = require("./graph"); | ||
const models_1 = require("./models"); | ||
const environment_1 = require("./models/environment"); | ||
function getTestConfig() { | ||
const config = {}; | ||
config.sdkMaxUsersGraphSize = 100; | ||
config.sdkMaxStaleFriendshipDays = 100; | ||
config.maxPageId = 100; | ||
config.dsnpVersions = [models_1.DsnpVersion.Version1_0]; | ||
config.maxGraphPageSizeBytes = 100; | ||
config.maxKeyPageSizeBytes = 100; | ||
const schemaConfig = {}; | ||
schemaConfig.dsnpVersion = models_1.DsnpVersion.Version1_0; | ||
schemaConfig.connectionType = models_1.ConnectionType.Follow; | ||
schemaConfig.privacyType = models_1.PrivacyType.Public; | ||
config.schemaMap = { 1: schemaConfig }; | ||
return config; | ||
} | ||
test('printHelloGraph should print "Hello, Graph!"', async () => { | ||
// Mock the console.log function | ||
const consoleLogMock = jest.spyOn(console, 'log').mockImplementation(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config: {} }; | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config: getTestConfig() }; | ||
const graph = new graph_1.Graph(environment); | ||
@@ -10,0 +26,0 @@ await graph.printHelloGraph(); |
@@ -7,3 +7,3 @@ import { Connection } from "./connection"; | ||
connection: Connection; | ||
dsnpKeys: DsnpKeys; | ||
dsnpKeys?: DsnpKeys; | ||
} | ||
@@ -10,0 +10,0 @@ export interface DisconnectAction { |
@@ -24,7 +24,7 @@ declare enum DsnpVersion { | ||
schemaMap: { | ||
[key: string]: SchemaConfig; | ||
[key: number]: SchemaConfig; | ||
}; | ||
dsnpVersions: DsnpVersion[]; | ||
} | ||
export { Config, ConnectionType, DsnpVersion, SchemaConfig }; | ||
export { Config, ConnectionType, DsnpVersion, SchemaConfig, PrivacyType }; | ||
//# sourceMappingURL=config.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DsnpVersion = exports.ConnectionType = void 0; | ||
exports.PrivacyType = exports.DsnpVersion = exports.ConnectionType = void 0; | ||
var DsnpVersion; | ||
@@ -17,3 +17,3 @@ (function (DsnpVersion) { | ||
PrivacyType["Private"] = "private"; | ||
})(PrivacyType || (PrivacyType = {})); | ||
})(PrivacyType || (exports.PrivacyType = PrivacyType = {})); | ||
//# sourceMappingURL=config.js.map |
@@ -7,3 +7,3 @@ export interface KeyData { | ||
dsnpUserId: number; | ||
keysHash: Uint8Array; | ||
keysHash: number; | ||
keys: KeyData[]; | ||
@@ -20,5 +20,5 @@ } | ||
export interface PageData { | ||
page_id: string; | ||
pageId: number; | ||
content: Uint8Array; | ||
contentHash: Uint8Array; | ||
contentHash: number; | ||
} | ||
@@ -25,0 +25,0 @@ export interface ImportBundle { |
@@ -6,3 +6,3 @@ export interface PersistPageUpdate { | ||
pageId: number; | ||
prevHash: Uint8Array; | ||
prevHash: number; | ||
payload: Uint8Array; | ||
@@ -15,3 +15,3 @@ } | ||
pageId: number; | ||
prevHash: Uint8Array; | ||
prevHash: number; | ||
} | ||
@@ -21,3 +21,3 @@ export interface AddKeyUpdate { | ||
ownerDsnpUserId: number; | ||
prevHash: Uint8Array; | ||
prevHash: number; | ||
payload: Uint8Array; | ||
@@ -24,0 +24,0 @@ } |
{ | ||
"name": "@dsnp/graph-sdk", | ||
"version": "0.0.0-ab5a34", | ||
"version": "0.0.0-b34245", | ||
"author": "Amplica Labs", | ||
@@ -5,0 +5,0 @@ "license": "ISC", |
104
README.md
@@ -18,30 +18,82 @@ # DSNP Graph SDK | ||
```typescript | ||
import { Graph, EnvironmentInterface, ImportBundle, Action, Update, DsnpGraphEdge, DsnpPublicKey, DsnpKeys } from "@dsnp/graph-sdk"; | ||
import { Graph, EnvironmentInterface, EnvironmentType, ImportBundle, Action, Update, DsnpGraphEdge, DsnpPublicKey, DsnpKeys } from "@dsnp/graph-sdk"; | ||
// Create a new instance of the Graph class | ||
const environment: EnvironmentInterface = /* provide environment details */; | ||
const environment: EnvironmentInterface = { environmentType: EnvironmentType.Mainnet }; | ||
const graph = new Graph(environment); | ||
// Import data into the graph | ||
const importBundle: ImportBundle = /* provide import bundle */; | ||
await graph.importUserData([importBundle]); | ||
// Set up import data | ||
const dsnpUserId1 = 1; | ||
const dsnpUserId2 = 2; | ||
const pageData1: PageData = { | ||
pageId: 1, | ||
content: new Uint8Array([24, 227, 96, 97, 96, 99, 224, 96, 224, 98, 96, 0, 0]), | ||
contentHash: 100, | ||
}; | ||
const keyPairs1: GraphKeyPair[] = []; | ||
const keyPairs2: GraphKeyPair[] = []; | ||
const dsnpKeys1: DsnpKeys = { | ||
dsnpUserId: dsnpUserId1, | ||
keysHash: 100, | ||
keys: [], | ||
}; | ||
const dsnpKeys2: DsnpKeys = { | ||
dsnpUserId: dsnpUserId2, | ||
keysHash: 100, | ||
keys: [], | ||
}; | ||
const importBundle1: ImportBundle = { | ||
dsnpUserId: dsnpUserId1, | ||
schemaId: 1, | ||
keyPairs: keyPairs1, | ||
dsnpKeys: dsnpKeys1, | ||
pages: [pageData1], | ||
}; | ||
const importBundle2: ImportBundle = { | ||
dsnpUserId: dsnpUserId2, | ||
schemaId: 1, | ||
keyPairs: keyPairs2, | ||
dsnpKeys: dsnpKeys2, | ||
pages: [pageData1], | ||
}; | ||
// Import user data for each ImportBundle | ||
const imported = await graph.importUserData([importBundle1, importBundle2]); | ||
// Apply actions to the graph | ||
const actions: Action[] = /* provide actions */; | ||
await graph.applyActions(actions); | ||
// Set up actions | ||
const actions = [] as Action[]; | ||
const action_1 = { | ||
type: "Connect", | ||
ownerDsnpUserId: 1, | ||
connection: { | ||
dsnpUserId: 2, | ||
schemaId: 1, | ||
} as Connection, | ||
dsnpKeys: { | ||
dsnpUserId: 2, | ||
keysHash: 100, | ||
keys: [], | ||
} as DsnpKeys, | ||
} as ConnectAction; | ||
await graph.applyActions(actions.push(action_1)); | ||
// Get graph updates | ||
const updates: Update = await graph.exportUpdates(); | ||
const updates: Update[] = await graph.exportUpdates(); | ||
// One can retrieve the graph configuration and respective schema mappings | ||
const graph_config = await graph.getGraphConfig(environment); | ||
// Get connections for a user graph | ||
const dsnpUserId: number = /* provide dsnp user id */; | ||
const schemaId: string = /* provide schema id */; | ||
const includePending: boolean = /* specify if pending connections should be included */; | ||
const connections: DsnpGraphEdge[] = await graph.getConnectionsForUserGraphUpdates(dsnpUserId, schemaId, includePending); | ||
const dsnpUserId: number = 1; | ||
const schemaId: number = 1; | ||
const includePending: boolean = true; | ||
// Access other graph-related functions | ||
// ... | ||
const connections: DsnpGraphEdge[] = await graph.getConnectionsForUserGraph(dsnpUserId, schemaId, includePending); | ||
// Free the graph state | ||
graph.freeGraphState(); | ||
``` | ||
@@ -65,15 +117,16 @@ | ||
- `getGraphSize(): Promise<number>`: Retrieves the current size of the graph. | ||
- `containsUserGraph(dsnpUserId: number): Promise<boolean>`: Checks if the graph contains the user graph for the specified dsnp user id. | ||
- `containsUserGraph(dsnpUserId: number): Promise<boolean>`: Checks if the graph contains the user graph for the specified DSNP user ID. | ||
- `getGraphUsersCount(): Promise<number>`: Retrieves the count of user graphs in the graph. | ||
- `removeUserGraph(dsnpUserId: number): Promise<void>`: Removes the user graph for the specified dsnp user id from the graph. | ||
- `importUserData(payload: [ImportBundle]): Promise<void>`: Imports user data into the graph. | ||
- `removeUserGraph(dsnpUserId: number): Promise<void>`: Removes the user graph for the specified DSNP user ID from the graph. | ||
- `importUserData(payload: ImportBundle[]): Promise<void>`: Imports user data into the graph. | ||
- `exportUpdates(): Promise<Update>`: Retrieves the graph updates. | ||
- `getConnectionsForUserGraphUpdates(dsnpUserId: number, schemaId: string, includePending: boolean): Promise<[DsnpGraphEdge]>`: Retrieves the connections for a user graph. | ||
- `applyActions(actions: [Action]): Promise<void>`: Applies actions to the graph. | ||
- `forceCalculateGraphs(dsnpUserId: number): Promise<Update>`: Forces the calculation of graphs for the specified dsnp user id. | ||
- `getConnectionsWithoutKeys(): Promise<[number]>`: Retrieves the connections without keys in the graph. | ||
- `getOneSidedPrivateFriendshipConnections(dsnpUserId: number): Promise<[DsnpGraphEdge]>`: Retrieves the one-sided private friendship connections for the specified dsnp user id. | ||
- `getPublicKeys(dsnpUserId: number): Promise<[DsnpPublicKey]>`: Retrieves the public keys for the specified dsnp user id. | ||
- `deserializeDsnpKeys(keys: DsnpKeys): Promise<[DsnpPublicKey]>`: Deserializes DSNP keys. | ||
- `getConnectionsForUserGraphUpdates(dsnpUserId: number, schemaId: string, includePending: boolean): Promise<DsnpGraphEdge[]>`: Retrieves the connections for a user graph. | ||
- `applyActions(actions: Action[]): Promise<void>`: Applies actions to the graph. | ||
- `forceCalculateGraphs(dsnpUserId: number): Promise<Update>`: Forces the calculation of graphs for the specified DSNP user ID. | ||
- `getConnectionsWithoutKeys(): Promise<number[]>`: Retrieves the connections without keys in the graph. | ||
- `getOneSidedPrivateFriendshipConnections(dsnpUserId: number): Promise<DsnpGraphEdge[]>`: Retrieves the one-sided private friendship connections for the specified DSNP user ID. | ||
- `getPublicKeys(dsnpUserId: number): Promise<DsnpPublicKey[]>`: Retrieves the public keys for the specified DSNP user ID. | ||
- `deserializeDsnpKeys(keys: DsnpKeys): Promise<DsnpPublicKey[]>`: Deserializes DSNP keys. | ||
- `getGraphConfig(environment: EnvironmentInterface): Promise<Config>`: Retrieves the graph configuration. | ||
- `getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>`: Retrieves the schema ID from the graph configuration. | ||
- `freeGraphState(): void`: Frees the graph state. | ||
@@ -91,3 +144,6 @@ | ||
- `DsnpGraphEdge`: Represents a connection in the graph. | ||
- `DsnpPublicKey`: Represents a published graph key. | ||
- `DsnpPublicKey`: Represents a published graph key for a DSNP user. | ||
- `DsnpKeys`: Encapsulates a DSNP user and their associated graph public keys. | ||
- `GraphKeyPair`: Represents a key pair for a DSNP user. | ||
- `PageData`: Represents the page data to be retrieved from the chain. | ||
- `Connection`: Represents a connection between two DSNP users.- ` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6341383
648
147