@dsnp/graph-sdk
Advanced tools
Comparing version 0.0.0-142689 to 0.0.0-470378
@@ -1,9 +0,26 @@ | ||
import { Config } from "./models/config"; | ||
import { ImportBundle, Update, DsnpGraphEdge, Action, DsnpPublicKey, DsnpKeys, Config, ConnectionType, PrivacyType, GraphKeyPair } from "./models"; | ||
import { EnvironmentInterface } from "./models/environment"; | ||
export declare class Graph { | ||
private handle; | ||
constructor(environment: EnvironmentInterface, capacity?: number); | ||
getGraphConfig(environment: EnvironmentInterface): Config; | ||
constructor(environment: EnvironmentInterface); | ||
getGraphHandle(): number; | ||
getGraphConfig(environment: EnvironmentInterface): Promise<Config>; | ||
getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>; | ||
getGraphStatesCount(): Promise<number>; | ||
containsUserGraph(dsnpUserId: string): Promise<boolean>; | ||
getGraphUsersCount(): Promise<number>; | ||
removeUserGraph(dsnpUserId: string): Promise<boolean>; | ||
importUserData(payload: ImportBundle[]): Promise<boolean>; | ||
exportUpdates(): Promise<Update[]>; | ||
getConnectionsForUserGraph(dsnpUserId: string, schemaId: number, includePending: boolean): Promise<DsnpGraphEdge[]>; | ||
applyActions(actions: Action[]): Promise<boolean>; | ||
forceCalculateGraphs(dsnpUserId: string): Promise<Update[]>; | ||
getConnectionsWithoutKeys(): Promise<string[]>; | ||
getOneSidedPrivateFriendshipConnections(dsnpUserId: string): Promise<DsnpGraphEdge[]>; | ||
getPublicKeys(dsnpUserId: string): Promise<DsnpPublicKey[]>; | ||
static deserializeDsnpKeys(keys: DsnpKeys): Promise<DsnpPublicKey[]>; | ||
static generateKeyPair(keyType: number): Promise<GraphKeyPair>; | ||
freeGraphState(): Promise<boolean>; | ||
printHelloGraph(): void; | ||
} | ||
//# sourceMappingURL=graph.d.ts.map |
@@ -6,13 +6,59 @@ "use strict"; | ||
class Graph { | ||
constructor(environment, capacity) { | ||
if (capacity) { | ||
this.handle = index_1.graphsdkModule.initializeGraphStateWithCapacity(environment, capacity); | ||
} | ||
else { | ||
this.handle = index_1.graphsdkModule.initializeGraphState(environment); | ||
} | ||
constructor(environment) { | ||
this.handle = index_1.graphsdkModule.initializeGraphState(environment); | ||
} | ||
getGraphHandle() { | ||
return this.handle; | ||
} | ||
getGraphConfig(environment) { | ||
return index_1.graphsdkModule.getGraphConfig(environment); | ||
} | ||
getSchemaIdFromConfig(environment, connectionType, privacyType) { | ||
return index_1.graphsdkModule.getSchemaIdFromConfig(environment, connectionType, privacyType); | ||
} | ||
getGraphStatesCount() { | ||
return index_1.graphsdkModule.getGraphStatesCount(); | ||
} | ||
containsUserGraph(dsnpUserId) { | ||
return index_1.graphsdkModule.containsUserGraph(this.handle, dsnpUserId); | ||
} | ||
getGraphUsersCount() { | ||
return index_1.graphsdkModule.getGraphUsersCount(this.handle); | ||
} | ||
removeUserGraph(dsnpUserId) { | ||
return index_1.graphsdkModule.removeUserGraph(this.handle, dsnpUserId); | ||
} | ||
importUserData(payload) { | ||
return index_1.graphsdkModule.importUserData(this.handle, payload); | ||
} | ||
exportUpdates() { | ||
return index_1.graphsdkModule.exportUpdates(this.handle); | ||
} | ||
getConnectionsForUserGraph(dsnpUserId, schemaId, includePending) { | ||
return index_1.graphsdkModule.getConnectionsForUserGraph(this.handle, dsnpUserId, schemaId, includePending); | ||
} | ||
applyActions(actions) { | ||
return index_1.graphsdkModule.applyActions(this.handle, actions); | ||
} | ||
forceCalculateGraphs(dsnpUserId) { | ||
return index_1.graphsdkModule.forceCalculateGraphs(this.handle, dsnpUserId); | ||
} | ||
getConnectionsWithoutKeys() { | ||
return index_1.graphsdkModule.getConnectionsWithoutKeys(this.handle); | ||
} | ||
getOneSidedPrivateFriendshipConnections(dsnpUserId) { | ||
return index_1.graphsdkModule.getOneSidedPrivateFriendshipConnections(this.handle, dsnpUserId); | ||
} | ||
getPublicKeys(dsnpUserId) { | ||
return index_1.graphsdkModule.getPublicKeys(this.handle, dsnpUserId); | ||
} | ||
static deserializeDsnpKeys(keys) { | ||
return index_1.graphsdkModule.deserializeDsnpKeys(keys); | ||
} | ||
static generateKeyPair(keyType) { | ||
return index_1.graphsdkModule.generateKeyPair(keyType); | ||
} | ||
freeGraphState() { | ||
return index_1.graphsdkModule.freeGraphState(this.handle); | ||
} | ||
printHelloGraph() { | ||
@@ -19,0 +65,0 @@ console.log(index_1.graphsdkModule.printHelloGraph()); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const graph_1 = require("./graph"); | ||
const models_1 = require("./models"); | ||
const config_1 = require("./models/config"); | ||
const environment_1 = require("./models/environment"); | ||
test('printHelloGraph should print "Hello, Graph!"', () => { | ||
function getTestConfig() { | ||
const config = {}; | ||
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 }; | ||
config.graphPublicKeySchemaId = 11; | ||
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); | ||
graph.printHelloGraph(); | ||
await graph.printHelloGraph(); | ||
expect(consoleLogMock).toHaveBeenCalledWith('Hello, Graph!'); | ||
await graph.freeGraphState(); | ||
}); | ||
test('getGraphConfig should return the graph config', () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config: {} }; | ||
test('getGraphConfig should return the graph config', async () => { | ||
const config_input = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config: config_input }; | ||
const graph = new graph_1.Graph(environment); | ||
const config = graph.getGraphConfig(environment); | ||
const config = await graph.getGraphConfig(environment); | ||
expect(config).toBeDefined(); | ||
expect(config.graphPublicKeySchemaId).toEqual(11); | ||
await graph.freeGraphState(); | ||
}); | ||
test('getGraphConfig with Mainnet environment should return the graph config', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
const graph = new graph_1.Graph(environment); | ||
const config = await graph.getGraphConfig(environment); | ||
expect(config).toBeDefined(); | ||
expect(config.graphPublicKeySchemaId).toEqual(5); | ||
const schema_id = await graph.getSchemaIdFromConfig(environment, config_1.ConnectionType.Follow, config_1.PrivacyType.Public); | ||
expect(schema_id).toEqual(1); | ||
await graph.freeGraphState(); | ||
}); | ||
test('getGraphConfig with Rococo environment should return the graph config', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Rococo }; | ||
const graph = new graph_1.Graph(environment); | ||
const config = await graph.getGraphConfig(environment); | ||
expect(config).toBeDefined(); | ||
await graph.freeGraphState(); | ||
}); | ||
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.toString(), | ||
keysHash: 100, | ||
keys: [], | ||
}; | ||
const dsnpKeys2 = { | ||
dsnpUserId: dsnpUserId2.toString(), | ||
keysHash: 100, | ||
keys: [], | ||
}; | ||
const importBundle1 = { | ||
dsnpUserId: dsnpUserId1.toString(), | ||
schemaId: 1, | ||
keyPairs: keyPairs1, | ||
dsnpKeys: dsnpKeys1, | ||
pages: [pageData1], | ||
}; | ||
const importBundle2 = { | ||
dsnpUserId: dsnpUserId2.toString(), | ||
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 keys = await graph.getPublicKeys("1"); | ||
expect(keys).toBeDefined(); | ||
expect(keys.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 des_keys = await graph_1.Graph.deserializeDsnpKeys(keys); | ||
expect(des_keys).toBeDefined(); | ||
expect(des_keys.length).toEqual(0); | ||
await graph.freeGraphState(); | ||
}); | ||
test('Create and export a new graph', async () => { | ||
let mainnet_environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
let graph = new graph_1.Graph(mainnet_environment); | ||
let public_follow_graph_schema_id = await graph.getSchemaIdFromConfig(mainnet_environment, config_1.ConnectionType.Follow, config_1.PrivacyType.Public); | ||
let connect_action = { | ||
type: "Connect", | ||
ownerDsnpUserId: "1", | ||
connection: { | ||
dsnpUserId: "2", | ||
schemaId: public_follow_graph_schema_id, | ||
}, | ||
dsnpKeys: { | ||
dsnpUserId: "2", | ||
keysHash: 100, | ||
keys: [], | ||
}, | ||
}; | ||
let actions = []; | ||
actions.push(connect_action); | ||
let applied = await graph.applyActions(actions); | ||
expect(applied).toEqual(true); | ||
let connections_including_pending = await graph.getConnectionsForUserGraph("1", public_follow_graph_schema_id, true); | ||
expect(connections_including_pending).toBeDefined(); | ||
expect(connections_including_pending.length).toEqual(1); | ||
let exported = await graph.exportUpdates(); | ||
expect(exported).toBeDefined(); | ||
expect(exported.length).toEqual(1); | ||
}); | ||
test('Add a new graph key', async () => { | ||
const environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
const graph = new graph_1.Graph(environment); | ||
const dsnpOwnerId = 1; | ||
const x25519_public_key = [ | ||
15, 234, 44, 175, 171, 220, 131, 117, 43, 227, 111, 165, 52, 150, 64, 218, 44, 130, 138, | ||
221, 10, 41, 13, 241, 60, 210, 216, 23, 62, 178, 73, 111, | ||
]; | ||
const addGraphKeyAction = { | ||
type: "AddGraphKey", | ||
ownerDsnpUserId: dsnpOwnerId.toString(), | ||
newPublicKey: new Uint8Array(x25519_public_key), | ||
}; | ||
const actions = []; | ||
actions.push(addGraphKeyAction); | ||
const applied = await graph.applyActions(actions); | ||
expect(applied).toEqual(true); | ||
const exported = await graph.exportUpdates(); | ||
expect(exported).toBeDefined(); | ||
expect(exported.length).toEqual(1); | ||
}); | ||
test('Read and deserialize published graph keys', async () => { | ||
let dsnp_key_owner = 1000; | ||
// published keys blobs fetched from blockchain | ||
let published_keys_blob = [ | ||
64, 15, 234, 44, 175, 171, 220, 131, 117, 43, 227, 111, 165, 52, 150, 64, 218, 44, 130, | ||
138, 221, 10, 41, 13, 241, 60, 210, 216, 23, 62, 178, 73, 111, | ||
]; | ||
let dsnp_keys = { | ||
dsnpUserId: dsnp_key_owner.toString(), | ||
keysHash: 100, | ||
keys: [ | ||
{ | ||
index: 0, | ||
content: new Uint8Array(published_keys_blob), | ||
} | ||
], | ||
}; | ||
const environment = { environmentType: environment_1.EnvironmentType.Mainnet }; | ||
const deserialized_keys = await graph_1.Graph.deserializeDsnpKeys(dsnp_keys); | ||
expect(deserialized_keys).toBeDefined(); | ||
}); | ||
test('generateKeyPair should return a key pair', async () => { | ||
const keyPair = await graph_1.Graph.generateKeyPair(models_1.GraphKeyType.X25519); | ||
expect(keyPair).toBeDefined(); | ||
expect(keyPair.publicKey).toBeDefined(); | ||
expect(keyPair.secretKey).toBeDefined(); | ||
expect(keyPair.keyType).toEqual(models_1.GraphKeyType.X25519); | ||
}); | ||
//# sourceMappingURL=graph.test.js.map |
@@ -1,23 +0,27 @@ | ||
import { EnvironmentInterface } from "./models/environment"; | ||
import { Config } from "./models/config"; | ||
import { Action, Config, ConnectionType, DsnpGraphEdge, DsnpKeys, DsnpPublicKey, EnvironmentInterface, GraphKeyPair, GraphKeyType, ImportBundle, PrivacyType, Update } from "./models"; | ||
export interface Native { | ||
printHelloGraph(): void; | ||
getGraphConfig(environment: EnvironmentInterface): Config; | ||
initializeGraphState(environment: EnvironmentInterface): number; | ||
initializeGraphStateWithCapacity(environment: EnvironmentInterface, capacity: number): number; | ||
containsUserGraph(handle: number, dsnpUserId: number): boolean; | ||
getGraphUsersLength(handle: number): number; | ||
removeUserGraph(handle: number, dsnpUserId: number): void; | ||
importUserData(handle: number, data: any): void; | ||
exportUpdates(handle: number): any; | ||
applyActions(handle: number, actions: any): void; | ||
forceCalculateGraphs(handle: number, dsnpUserId: number): any; | ||
getConnectionsForUserGraph(handle: number, dsnpUserId: number, schemaId: string, includePending: boolean): any; | ||
getUsersWithoutKeys(handle: number): any; | ||
getOneSidedPrivateFriendshipConnections(handle: number, dsnpUserId: number): any; | ||
getPublicKeys(handle: number, dsnpUserId: number): any; | ||
deserializeDsnpKeys(keys: any): any; | ||
freeGraphState(handle: number): void; | ||
getGraphConfig(environment: EnvironmentInterface): Promise<Config>; | ||
getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>; | ||
getGraphStatesCount(): Promise<number>; | ||
getGraphUsersCount(handle: number): Promise<number>; | ||
containsUserGraph(handle: number, dsnpUserId: string): Promise<boolean>; | ||
removeUserGraph(handle: number, dsnpUserId: string): 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: string, schemaId: number, includePending: boolean): Promise<DsnpGraphEdge[]>; | ||
forceCalculateGraphs(handle: number, dsnpUserId: string): Promise<Update[]>; | ||
getConnectionsWithoutKeys(handle: number): Promise<string[]>; | ||
getOneSidedPrivateFriendshipConnections(handle: number, dsnpUserId: string): Promise<DsnpGraphEdge[]>; | ||
getPublicKeys(handle: number, dsnpUserId: string): Promise<DsnpPublicKey[]>; | ||
deserializeDsnpKeys(keys: DsnpKeys): Promise<DsnpPublicKey[]>; | ||
generateKeyPair(keyType: GraphKeyType): Promise<GraphKeyPair>; | ||
freeGraphState(handle: number): Promise<boolean>; | ||
} | ||
export declare const graphsdkModule: Native; | ||
export * from "./models"; | ||
export * from "./graph"; | ||
export * from "./import-bundle-builder"; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -11,12 +25,14 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
try { | ||
return require(path_1.default.join(__dirname, "/graphsdk.node")); | ||
return require(path_1.default.join(__dirname, "/dsnp_graph_sdk_node.node")); | ||
} | ||
catch (error) { | ||
throw new Error("Unable to load the native module graphsdk.node"); | ||
throw new Error("Unable to load the native module dsnp_graph_sdk_node.node"); | ||
} | ||
} | ||
const graphsdk = loadNativeModule(); | ||
console.log("Loaded graphsdk.node bindings"); | ||
// Export the graphsdk module | ||
exports.graphsdkModule = graphsdk; | ||
exports.graphsdkModule = loadNativeModule(); | ||
// Export the models | ||
__exportStar(require("./models"), exports); | ||
__exportStar(require("./graph"), exports); | ||
__exportStar(require("./import-bundle-builder"), exports); | ||
//# sourceMappingURL=index.js.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"); | ||
test('printHelloGraph should print "Hello, Graph!"', () => { | ||
function getTestConfig() { | ||
const config = {}; | ||
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 }; | ||
config.graphPublicKeySchemaId = 11; | ||
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); | ||
graph.printHelloGraph(); | ||
await graph.printHelloGraph(); | ||
expect(consoleLogMock).toHaveBeenCalledWith('Hello, Graph!'); | ||
await graph.freeGraphState(); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
@@ -8,18 +8,23 @@ declare enum DsnpVersion { | ||
} | ||
declare enum PrivacyType { | ||
Public = "public", | ||
Private = "private" | ||
} | ||
interface SchemaConfig { | ||
dsnp_version: DsnpVersion; | ||
connection_type: ConnectionType; | ||
dsnpVersion: DsnpVersion; | ||
connectionType: ConnectionType; | ||
privacyType: PrivacyType; | ||
} | ||
interface Config { | ||
sdk_max_users_graph_size: number; | ||
sdk_max_stale_friendship_days: number; | ||
max_graph_page_size_bytes: number; | ||
max_page_id: number; | ||
max_key_page_size_bytes: number; | ||
schema_map: { | ||
[key: string]: SchemaConfig; | ||
sdkMaxStaleFriendshipDays: number; | ||
maxGraphPageSizeBytes: number; | ||
maxPageId: number; | ||
maxKeyPageSizeBytes: number; | ||
schemaMap: { | ||
[key: number]: SchemaConfig; | ||
}; | ||
dsnp_versions: DsnpVersion[]; | ||
graphPublicKeySchemaId: number; | ||
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; | ||
@@ -13,2 +13,7 @@ (function (DsnpVersion) { | ||
})(ConnectionType || (exports.ConnectionType = ConnectionType = {})); | ||
var PrivacyType; | ||
(function (PrivacyType) { | ||
PrivacyType["Public"] = "public"; | ||
PrivacyType["Private"] = "private"; | ||
})(PrivacyType || (exports.PrivacyType = PrivacyType = {})); | ||
//# sourceMappingURL=config.js.map |
{ | ||
"name": "@dsnp/graph-sdk", | ||
"version": "0.0.0-142689", | ||
"version": "0.0.0-470378", | ||
"author": "Amplica Labs", | ||
@@ -12,6 +12,6 @@ "license": "ISC", | ||
"build": "tsc", | ||
"cp:graphsdk.node": "cp graphsdk.node dist/js/ && cp graphsdk.node js/", | ||
"native:build": "tsc && cargo-cp-artifact -a cdylib graphsdk graphsdk.node -- cargo build --message-format=json-render-diagnostics", | ||
"cp:dsnp_graph_sdk_node.node": "cp dsnp_graph_sdk_node.node dist/js/ && cp dsnp_graph_sdk_node.node js/", | ||
"native:build": "tsc && cargo-cp-artifact -a cdylib dsnp_graph_sdk_node dsnp_graph_sdk_node.node -- cargo build --message-format=json-render-diagnostics", | ||
"native:build-debug": "npm run native:build --", | ||
"native:build-release": "npm run native:build -- --release && npm run cp:graphsdk.node", | ||
"native:build-release": "npm run native:build -- --release && npm run cp:dsnp_graph_sdk_node.node", | ||
"test:cargo": "cargo test", | ||
@@ -52,3 +52,3 @@ "lint": "eslint js/ --ext .ts", | ||
}, | ||
"homepage": "https://github.com/LibertyDSNP/graph-sdk#readme" | ||
"homepage": "https://github.com/LibertyDSNP/graph-sdk/bridge/node/README.md" | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
6378817
64
836
340
2
2