@dsnp/graph-sdk
Advanced tools
Comparing version 0.0.0-63c2b1 to 0.0.0-64807e
@@ -5,19 +5,18 @@ import { ImportBundle, Update, DsnpGraphEdge, Action, DsnpPublicKey, DsnpKeys, Config, ConnectionType, PrivacyType, GraphKeyPair } from "./models"; | ||
private handle; | ||
constructor(environment: EnvironmentInterface, capacity?: number); | ||
constructor(environment: EnvironmentInterface); | ||
getGraphHandle(): number; | ||
getGraphConfig(environment: EnvironmentInterface): Promise<Config>; | ||
getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>; | ||
getGraphCapacity(): Promise<number>; | ||
getGraphStatesCount(): Promise<number>; | ||
containsUserGraph(dsnpUserId: number): Promise<boolean>; | ||
containsUserGraph(dsnpUserId: string): Promise<boolean>; | ||
getGraphUsersCount(): Promise<number>; | ||
removeUserGraph(dsnpUserId: number): Promise<boolean>; | ||
removeUserGraph(dsnpUserId: string): Promise<boolean>; | ||
importUserData(payload: ImportBundle[]): Promise<boolean>; | ||
exportUpdates(): Promise<Update[]>; | ||
getConnectionsForUserGraph(dsnpUserId: number, schemaId: number, includePending: boolean): Promise<DsnpGraphEdge[]>; | ||
getConnectionsForUserGraph(dsnpUserId: string, 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[]>; | ||
forceCalculateGraphs(dsnpUserId: string): Promise<Update[]>; | ||
getConnectionsWithoutKeys(): Promise<string[]>; | ||
getOneSidedPrivateFriendshipConnections(dsnpUserId: string): Promise<DsnpGraphEdge[]>; | ||
getPublicKeys(dsnpUserId: string): Promise<DsnpPublicKey[]>; | ||
static deserializeDsnpKeys(keys: DsnpKeys): Promise<DsnpPublicKey[]>; | ||
@@ -24,0 +23,0 @@ static generateKeyPair(keyType: number): Promise<GraphKeyPair>; |
@@ -6,9 +6,4 @@ "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); | ||
} | ||
@@ -24,5 +19,2 @@ getGraphHandle() { | ||
} | ||
getGraphCapacity() { | ||
return index_1.graphsdkModule.getGraphCapacity(this.handle); | ||
} | ||
getGraphStatesCount() { | ||
@@ -29,0 +21,0 @@ return index_1.graphsdkModule.getGraphStatesCount(); |
@@ -9,3 +9,2 @@ "use strict"; | ||
const config = {}; | ||
config.sdkMaxUsersGraphSize = 100; | ||
config.sdkMaxStaleFriendshipDays = 100; | ||
@@ -21,2 +20,3 @@ config.maxPageId = 100; | ||
config.schemaMap = { 1: schemaConfig }; | ||
config.graphPublicKeySchemaId = 11; | ||
return config; | ||
@@ -39,3 +39,3 @@ } | ||
expect(config).toBeDefined(); | ||
expect(config.sdkMaxUsersGraphSize).toEqual(100); | ||
expect(config.graphPublicKeySchemaId).toEqual(11); | ||
await graph.freeGraphState(); | ||
@@ -48,3 +48,3 @@ }); | ||
expect(config).toBeDefined(); | ||
expect(config.sdkMaxUsersGraphSize).toEqual(1000); | ||
expect(config.graphPublicKeySchemaId).toEqual(5); | ||
const schema_id = await graph.getSchemaIdFromConfig(environment, config_1.ConnectionType.Follow, config_1.PrivacyType.Public); | ||
@@ -59,15 +59,4 @@ expect(schema_id).toEqual(1); | ||
expect(config).toBeDefined(); | ||
expect(config.sdkMaxUsersGraphSize).toEqual(1000); | ||
await graph.freeGraphState(); | ||
}); | ||
test('initialize graph with low capacity of 100 should return the same capacity', async () => { | ||
const config = getTestConfig(); | ||
const environment = { environmentType: environment_1.EnvironmentType.Dev, config }; | ||
const graph = new graph_1.Graph(environment, 100); | ||
const handle = graph.getGraphHandle(); | ||
expect(handle).toBeDefined(); | ||
const capacity = await graph.getGraphCapacity(); | ||
expect(capacity).toEqual(100); | ||
await graph.freeGraphState(); | ||
}); | ||
test('getGraphStatesCount should be zero after previous graph is freed', async () => { | ||
@@ -112,3 +101,3 @@ const config = getTestConfig(); | ||
expect(handle).toBeDefined(); | ||
const contains = await graph.containsUserGraph(1); | ||
const contains = await graph.containsUserGraph("1"); | ||
expect(contains).toEqual(false); | ||
@@ -123,3 +112,3 @@ await graph.freeGraphState(); | ||
expect(handle).toBeDefined(); | ||
const removed = await graph.removeUserGraph(1); | ||
const removed = await graph.removeUserGraph("1"); | ||
expect(removed).toEqual(true); | ||
@@ -144,3 +133,3 @@ await graph.freeGraphState(); | ||
const dsnpKeys1 = { | ||
dsnpUserId: dsnpUserId1, | ||
dsnpUserId: dsnpUserId1.toString(), | ||
keysHash: 100, | ||
@@ -150,3 +139,3 @@ keys: [], | ||
const dsnpKeys2 = { | ||
dsnpUserId: dsnpUserId2, | ||
dsnpUserId: dsnpUserId2.toString(), | ||
keysHash: 100, | ||
@@ -156,3 +145,3 @@ keys: [], | ||
const importBundle1 = { | ||
dsnpUserId: dsnpUserId1, | ||
dsnpUserId: dsnpUserId1.toString(), | ||
schemaId: 1, | ||
@@ -164,3 +153,3 @@ keyPairs: keyPairs1, | ||
const importBundle2 = { | ||
dsnpUserId: dsnpUserId2, | ||
dsnpUserId: dsnpUserId2.toString(), | ||
schemaId: 1, | ||
@@ -197,9 +186,9 @@ keyPairs: keyPairs2, | ||
type: "Connect", | ||
ownerDsnpUserId: 1, | ||
ownerDsnpUserId: "1", | ||
connection: { | ||
dsnpUserId: 2, | ||
dsnpUserId: "2", | ||
schemaId: 1, | ||
}, | ||
dsnpKeys: { | ||
dsnpUserId: 2, | ||
dsnpUserId: "2", | ||
keysHash: 100, | ||
@@ -227,9 +216,9 @@ keys: [], | ||
type: "Connect", | ||
ownerDsnpUserId: 1, | ||
ownerDsnpUserId: "1", | ||
connection: { | ||
dsnpUserId: 2, | ||
dsnpUserId: "2", | ||
schemaId: 1, | ||
}, | ||
dsnpKeys: { | ||
dsnpUserId: 2, | ||
dsnpUserId: "2", | ||
keysHash: 100, | ||
@@ -242,6 +231,6 @@ keys: [], | ||
expect(applied).toEqual(true); | ||
const connections = await graph.getConnectionsForUserGraph(1, 1, true); | ||
const connections = await graph.getConnectionsForUserGraph("1", 1, true); | ||
expect(connections).toBeDefined(); | ||
expect(connections.length).toEqual(1); | ||
const forceCalculateGraphs = await graph.forceCalculateGraphs(1); | ||
const forceCalculateGraphs = await graph.forceCalculateGraphs("1"); | ||
expect(forceCalculateGraphs).toBeDefined(); | ||
@@ -260,3 +249,3 @@ expect(forceCalculateGraphs.length).toEqual(0); | ||
expect(async () => { | ||
await graph.getOneSidedPrivateFriendshipConnections(1); | ||
await graph.getOneSidedPrivateFriendshipConnections("1"); | ||
}).rejects.toThrow('User graph for 1 is not imported'); | ||
@@ -270,5 +259,5 @@ await graph.freeGraphState(); | ||
expect(handle).toBeDefined(); | ||
const connections = await graph.getPublicKeys(1); | ||
expect(connections).toBeDefined(); | ||
expect(connections.length).toEqual(0); | ||
const keys = await graph.getPublicKeys("1"); | ||
expect(keys).toBeDefined(); | ||
expect(keys.length).toEqual(0); | ||
await graph.freeGraphState(); | ||
@@ -282,9 +271,9 @@ }); | ||
const keys = { | ||
dsnpUserId: 2, | ||
dsnpUserId: "2", | ||
keysHash: 100, | ||
keys: [], | ||
}; | ||
const connections = await graph_1.Graph.deserializeDsnpKeys(keys); | ||
expect(connections).toBeDefined(); | ||
expect(connections.length).toEqual(0); | ||
const des_keys = await graph_1.Graph.deserializeDsnpKeys(keys); | ||
expect(des_keys).toBeDefined(); | ||
expect(des_keys.length).toEqual(0); | ||
await graph.freeGraphState(); | ||
@@ -298,9 +287,9 @@ }); | ||
type: "Connect", | ||
ownerDsnpUserId: 1, | ||
ownerDsnpUserId: "1", | ||
connection: { | ||
dsnpUserId: 2, | ||
dsnpUserId: "2", | ||
schemaId: public_follow_graph_schema_id, | ||
}, | ||
dsnpKeys: { | ||
dsnpUserId: 2, | ||
dsnpUserId: "2", | ||
keysHash: 100, | ||
@@ -314,3 +303,3 @@ keys: [], | ||
expect(applied).toEqual(true); | ||
let connections_including_pending = await graph.getConnectionsForUserGraph(1, public_follow_graph_schema_id, true); | ||
let connections_including_pending = await graph.getConnectionsForUserGraph("1", public_follow_graph_schema_id, true); | ||
expect(connections_including_pending).toBeDefined(); | ||
@@ -332,3 +321,3 @@ expect(connections_including_pending.length).toEqual(1); | ||
type: "AddGraphKey", | ||
ownerDsnpUserId: dsnpOwnerId, | ||
ownerDsnpUserId: dsnpOwnerId.toString(), | ||
newPublicKey: new Uint8Array(x25519_public_key), | ||
@@ -352,3 +341,3 @@ }; | ||
let dsnp_keys = { | ||
dsnpUserId: dsnp_key_owner, | ||
dsnpUserId: dsnp_key_owner.toString(), | ||
keysHash: 100, | ||
@@ -355,0 +344,0 @@ keys: [ |
@@ -5,18 +5,16 @@ import { Action, Config, ConnectionType, DsnpGraphEdge, DsnpKeys, DsnpPublicKey, EnvironmentInterface, GraphKeyPair, GraphKeyType, ImportBundle, PrivacyType, Update } from "./models"; | ||
initializeGraphState(environment: EnvironmentInterface): number; | ||
initializeGraphStateWithCapacity(environment: EnvironmentInterface, capacity: number): number; | ||
getGraphConfig(environment: EnvironmentInterface): Promise<Config>; | ||
getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>; | ||
getGraphCapacity(handle: number): Promise<number>; | ||
getGraphStatesCount(): Promise<number>; | ||
getGraphUsersCount(handle: number): Promise<number>; | ||
containsUserGraph(handle: number, dsnpUserId: number): Promise<boolean>; | ||
removeUserGraph(handle: number, dsnpUserId: number): Promise<boolean>; | ||
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: 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[]>; | ||
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[]>; | ||
@@ -27,2 +25,4 @@ generateKeyPair(keyType: GraphKeyType): Promise<GraphKeyPair>; | ||
export declare const graphsdkModule: Native; | ||
export * from "./models"; | ||
export * from "./graph"; | ||
//# 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) { | ||
@@ -19,2 +33,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.graphsdkModule = loadNativeModule(); | ||
// Export the models | ||
__exportStar(require("./models"), exports); | ||
__exportStar(require("./graph"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -8,3 +8,2 @@ "use strict"; | ||
const config = {}; | ||
config.sdkMaxUsersGraphSize = 100; | ||
config.sdkMaxStaleFriendshipDays = 100; | ||
@@ -20,2 +19,3 @@ config.maxPageId = 100; | ||
config.schemaMap = { 1: schemaConfig }; | ||
config.graphPublicKeySchemaId = 11; | ||
return config; | ||
@@ -22,0 +22,0 @@ } |
@@ -5,3 +5,3 @@ import { Connection } from "./connection"; | ||
type: "Connect"; | ||
ownerDsnpUserId: number; | ||
ownerDsnpUserId: string; | ||
connection: Connection; | ||
@@ -12,3 +12,3 @@ dsnpKeys?: DsnpKeys; | ||
type: "Disconnect"; | ||
ownerDsnpUserId: number; | ||
ownerDsnpUserId: string; | ||
connection: Connection; | ||
@@ -18,3 +18,3 @@ } | ||
type: "AddGraphKey"; | ||
ownerDsnpUserId: number; | ||
ownerDsnpUserId: string; | ||
newPublicKey: Uint8Array; | ||
@@ -21,0 +21,0 @@ } |
@@ -18,3 +18,2 @@ declare enum DsnpVersion { | ||
interface Config { | ||
sdkMaxUsersGraphSize: number; | ||
sdkMaxStaleFriendshipDays: number; | ||
@@ -27,2 +26,3 @@ maxGraphPageSizeBytes: number; | ||
}; | ||
graphPublicKeySchemaId: number; | ||
dsnpVersions: DsnpVersion[]; | ||
@@ -29,0 +29,0 @@ } |
export interface Connection { | ||
dsnpUserId: number; | ||
dsnpUserId: string; | ||
schemaId: number; | ||
} | ||
//# sourceMappingURL=connection.d.ts.map |
export interface DsnpGraphEdge { | ||
userId: number; | ||
userId: string; | ||
since: number; | ||
} | ||
//# sourceMappingURL=graph_edge.d.ts.map |
@@ -6,3 +6,3 @@ export interface KeyData { | ||
export interface DsnpKeys { | ||
dsnpUserId: number; | ||
dsnpUserId: string; | ||
keysHash: number; | ||
@@ -25,3 +25,3 @@ keys: KeyData[]; | ||
export interface ImportBundle { | ||
dsnpUserId: number; | ||
dsnpUserId: string; | ||
schemaId: number; | ||
@@ -28,0 +28,0 @@ keyPairs: GraphKeyPair[]; |
export interface DsnpPublicKey { | ||
key: Uint8Array; | ||
keyId?: Uint8Array; | ||
keyId?: string; | ||
} | ||
//# sourceMappingURL=public_keys.d.ts.map |
export interface PersistPageUpdate { | ||
type: "PersistPage"; | ||
ownerDsnpUserId: number; | ||
ownerDsnpUserId: string; | ||
schemaId: number; | ||
@@ -11,3 +11,3 @@ pageId: number; | ||
type: "DeletePage"; | ||
ownerDsnpUserId: number; | ||
ownerDsnpUserId: string; | ||
schemaId: number; | ||
@@ -19,3 +19,3 @@ pageId: number; | ||
type: "AddKey"; | ||
ownerDsnpUserId: number; | ||
ownerDsnpUserId: string; | ||
prevHash: number; | ||
@@ -22,0 +22,0 @@ payload: Uint8Array; |
@@ -10,3 +10,3 @@ # DSNP Graph SDK | ||
```bash | ||
npm install @dsnp/graph-sdk | ||
npm install @dsnp/graph-sdk@latest | ||
``` | ||
@@ -105,3 +105,3 @@ | ||
#### Constructor: new Graph(environment: EnvironmentInterface, capacity?: number) | ||
#### Constructor: new Graph(environment: EnvironmentInterface) | ||
@@ -111,3 +111,2 @@ Creates a new instance of the Graph class. | ||
- `environment`: An object that represents the environment details. | ||
- `capacity` (optional): The initial capacity of the graph. | ||
@@ -117,3 +116,2 @@ #### Methods | ||
- `getGraphHandle(): number`: Returns the handle to the native graph state. | ||
- `getGraphCapacity(): Promise<number>`: Retrieves the capacity of the graph. | ||
- `getGraphSize(): Promise<number>`: Retrieves the current size of the graph. | ||
@@ -133,3 +131,3 @@ - `containsUserGraph(dsnpUserId: number): Promise<boolean>`: Checks if the graph contains the user graph for the specified DSNP user ID. | ||
- `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. | ||
- `getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>`: Retrieves the schema ID from the graph configuration. | ||
- `freeGraphState(): void`: Frees the graph state. | ||
@@ -156,3 +154,3 @@ | ||
### Create and export a new graph | ||
```typescript | ||
@@ -212,3 +210,3 @@ import { Graph, EnvironmentInterface, EnvironmentType } from "@dsnp/graph-sdk"; | ||
graph.freeGraphState(); | ||
``` | ||
@@ -347,3 +345,3 @@ | ||
const applied = await graph.applyActions(actions); | ||
``` |
{ | ||
"name": "@dsnp/graph-sdk", | ||
"version": "0.0.0-63c2b1", | ||
"version": "0.0.0-64807e", | ||
"author": "Amplica Labs", | ||
@@ -5,0 +5,0 @@ "license": "ISC", |
@@ -10,3 +10,3 @@ # DSNP Graph SDK | ||
```bash | ||
npm install @dsnp/graph-sdk | ||
npm install @dsnp/graph-sdk@latest | ||
``` | ||
@@ -105,3 +105,3 @@ | ||
#### Constructor: new Graph(environment: EnvironmentInterface, capacity?: number) | ||
#### Constructor: new Graph(environment: EnvironmentInterface) | ||
@@ -111,3 +111,2 @@ Creates a new instance of the Graph class. | ||
- `environment`: An object that represents the environment details. | ||
- `capacity` (optional): The initial capacity of the graph. | ||
@@ -117,3 +116,2 @@ #### Methods | ||
- `getGraphHandle(): number`: Returns the handle to the native graph state. | ||
- `getGraphCapacity(): Promise<number>`: Retrieves the capacity of the graph. | ||
- `getGraphSize(): Promise<number>`: Retrieves the current size of the graph. | ||
@@ -133,3 +131,3 @@ - `containsUserGraph(dsnpUserId: number): Promise<boolean>`: Checks if the graph contains the user graph for the specified DSNP user ID. | ||
- `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. | ||
- `getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>`: Retrieves the schema ID from the graph configuration. | ||
- `freeGraphState(): void`: Frees the graph state. | ||
@@ -156,3 +154,3 @@ | ||
### Create and export a new graph | ||
```typescript | ||
@@ -212,3 +210,3 @@ import { Graph, EnvironmentInterface, EnvironmentType } from "@dsnp/graph-sdk"; | ||
graph.freeGraphState(); | ||
``` | ||
@@ -347,3 +345,3 @@ | ||
const applied = await graph.applyActions(actions); | ||
``` |
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
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
6371388
728
340