@perspect3vism/ad4m
Advanced tools
Comparing version 0.1.36 to 0.1.37
@@ -154,2 +154,23 @@ "use strict"; | ||
}); | ||
it('mutatePublicPerspective() smoke test', async () => { | ||
let additionLink = new Links_1.Link({ source: 'root', target: 'perspective://Qm34589a3ccc0' }); | ||
const removalLink = new Links_1.LinkExpression(); | ||
removalLink.author = "did:ad4m:test"; | ||
removalLink.timestamp = Date.now().toString(); | ||
removalLink.data = { | ||
source: 'root2', | ||
target: 'perspective://Qm34589a3ccc0' | ||
}; | ||
removalLink.proof = { | ||
signature: '', | ||
key: '', | ||
valid: true | ||
}; | ||
//Note; here we dont get the links above since mutatePublicPerspective relies on a snapshot which returns the default test link for perspectives | ||
const agent = await ad4mClient.agent.mutatePublicPerspective({ additions: [additionLink], removals: [removalLink] }); | ||
expect(agent.did).toBe('did:ad4m:test'); | ||
expect(agent.perspective.links.length).toBe(1); | ||
expect(agent.perspective.links[0].data.source).toBe('root'); | ||
expect(agent.perspective.links[0].data.target).toBe('neighbourhood://Qm12345'); | ||
}); | ||
it('updateDirectMessageLanguage() smoke test', async () => { | ||
@@ -314,2 +335,6 @@ const agent = await ad4mClient.agent.updateDirectMessageLanguage("abcd"); | ||
}); | ||
it('remove() smoke test', async () => { | ||
const result = await ad4mClient.languages.remove("Qm12345"); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
@@ -316,0 +341,0 @@ describe('.neighbourhood', () => { |
@@ -5,2 +5,3 @@ import { ApolloClient } from "@apollo/client/core"; | ||
import { AgentStatus } from "./AgentStatus"; | ||
import { LinkMutations } from "../links/Links"; | ||
export interface InitializeArgs { | ||
@@ -36,2 +37,3 @@ did: string; | ||
updatePublicPerspective(perspective: PerspectiveInput): Promise<Agent>; | ||
mutatePublicPerspective(mutations: LinkMutations): Promise<Agent>; | ||
updateDirectMessageLanguage(directMessageLanguage: string): Promise<Agent>; | ||
@@ -38,0 +40,0 @@ addEntanglementProofs(proofs: EntanglementProofInput[]): Promise<EntanglementProof[]>; |
@@ -22,2 +22,3 @@ "use strict"; | ||
const AgentStatus_1 = require("./AgentStatus"); | ||
const PerspectiveClient_1 = __importDefault(require("../perspectives/PerspectiveClient")); | ||
const AGENT_SUBITEMS = ` | ||
@@ -159,2 +160,9 @@ did | ||
async updatePublicPerspective(perspective) { | ||
const cleanedPerspective = JSON.parse(JSON.stringify(perspective)); | ||
delete cleanedPerspective.__typename; | ||
cleanedPerspective.links.forEach(link => { | ||
delete link.__typename; | ||
delete link.data.__typename; | ||
delete link.proof.__typename; | ||
}); | ||
const { agentUpdatePublicPerspective } = (0, unwrapApolloResult_1.default)(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({ | ||
@@ -166,3 +174,3 @@ mutation: (0, core_1.gql) `mutation agentUpdatePublicPerspective($perspective: PerspectiveInput!) { | ||
}`, | ||
variables: { perspective: perspective } | ||
variables: { perspective: cleanedPerspective } | ||
})); | ||
@@ -174,2 +182,26 @@ const a = agentUpdatePublicPerspective; | ||
} | ||
async mutatePublicPerspective(mutations) { | ||
const perspectiveClient = new PerspectiveClient_1.default(__classPrivateFieldGet(this, _AgentClient_apolloClient, "f")); | ||
const agentClient = new AgentClient(__classPrivateFieldGet(this, _AgentClient_apolloClient, "f")); | ||
//Create the proxy perspective and load existing links | ||
const proxyPerspective = await perspectiveClient.add("Agent Perspective Proxy"); | ||
const agentMe = await agentClient.me(); | ||
if (agentMe.perspective) { | ||
await proxyPerspective.loadSnapshot(agentMe.perspective); | ||
} | ||
//Make the mutations on the proxy perspective | ||
for (const addition of mutations.additions) { | ||
await proxyPerspective.add(addition); | ||
} | ||
for (const removal of mutations.removals) { | ||
await proxyPerspective.remove(removal); | ||
} | ||
//Get the snapshot of the proxy perspective | ||
const snapshot = await proxyPerspective.snapshot(); | ||
//Update the users public perspective | ||
const agent = await this.updatePublicPerspective(snapshot); | ||
//Cleanup and return | ||
await perspectiveClient.remove(proxyPerspective.uuid); | ||
return agent; | ||
} | ||
async updateDirectMessageLanguage(directMessageLanguage) { | ||
@@ -176,0 +208,0 @@ const { agentUpdateDirectMessageLanguage } = (0, unwrapApolloResult_1.default)(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({ |
@@ -16,2 +16,3 @@ import { ApolloClient } from "@apollo/client/core"; | ||
source(address: string): Promise<string>; | ||
remove(address: string): Promise<Boolean>; | ||
} |
@@ -131,4 +131,15 @@ "use strict"; | ||
} | ||
async remove(address) { | ||
const { languageRemove } = (0, unwrapApolloResult_1.default)(await __classPrivateFieldGet(this, _LanguageClient_apolloClient, "f").mutate({ | ||
mutation: (0, core_1.gql) `mutation languageRemove( | ||
$address: String!, | ||
) { | ||
languageRemove(address: $address) | ||
}`, | ||
variables: { address } | ||
})); | ||
return languageRemove; | ||
} | ||
} | ||
exports.LanguageClient = LanguageClient; | ||
_LanguageClient_apolloClient = new WeakMap(); |
@@ -18,2 +18,3 @@ import { LanguageHandle } from "./LanguageHandle"; | ||
languageSource(address: string): string; | ||
languageRemove(address: string): Boolean; | ||
} |
@@ -81,2 +81,3 @@ "use strict"; | ||
} | ||
languageRemove(address) { return true; } | ||
}; | ||
@@ -135,2 +136,9 @@ __decorate([ | ||
], LanguageResolver.prototype, "languageSource", null); | ||
__decorate([ | ||
(0, type_graphql_1.Mutation)(), | ||
__param(0, (0, type_graphql_1.Arg)('address')), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [String]), | ||
__metadata("design:returntype", Boolean) | ||
], LanguageResolver.prototype, "languageRemove", null); | ||
LanguageResolver = __decorate([ | ||
@@ -137,0 +145,0 @@ (0, type_graphql_1.Resolver)() |
@@ -7,2 +7,6 @@ export declare class Link { | ||
} | ||
export declare class LinkMutations { | ||
additions: LinkInput[]; | ||
removals: LinkExpression[]; | ||
} | ||
export declare class LinkInput { | ||
@@ -9,0 +13,0 @@ source: string; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLink = exports.linkEqual = exports.LinkExpressionInput = exports.LinkExpression = exports.LinkInput = exports.Link = void 0; | ||
exports.isLink = exports.linkEqual = exports.LinkExpressionInput = exports.LinkExpression = exports.LinkInput = exports.LinkMutations = exports.Link = void 0; | ||
const type_graphql_1 = require("type-graphql"); | ||
@@ -40,2 +40,16 @@ const Expression_1 = require("../expression/Expression"); | ||
exports.Link = Link; | ||
let LinkMutations = class LinkMutations { | ||
}; | ||
__decorate([ | ||
(0, type_graphql_1.Field)(type => [LinkInput]), | ||
__metadata("design:type", Array) | ||
], LinkMutations.prototype, "additions", void 0); | ||
__decorate([ | ||
(0, type_graphql_1.Field)(type => [LinkExpression]), | ||
__metadata("design:type", Array) | ||
], LinkMutations.prototype, "removals", void 0); | ||
LinkMutations = __decorate([ | ||
(0, type_graphql_1.InputType)() | ||
], LinkMutations); | ||
exports.LinkMutations = LinkMutations; | ||
let LinkInput = class LinkInput { | ||
@@ -42,0 +56,0 @@ }; |
@@ -111,3 +111,9 @@ "use strict"; | ||
async loadSnapshot(snapshot) { | ||
for (const link of snapshot.links) { | ||
//Clean the input data from __typename | ||
const cleanedSnapshot = JSON.parse(JSON.stringify(snapshot)); | ||
delete cleanedSnapshot.__typename; | ||
cleanedSnapshot.links.forEach(link => { | ||
delete link.data.__typename; | ||
}); | ||
for (const link of cleanedSnapshot.links) { | ||
await this.add(link.data); | ||
@@ -114,0 +120,0 @@ } |
@@ -5,2 +5,3 @@ import { ApolloClient } from "@apollo/client/core"; | ||
import { AgentStatus } from "./AgentStatus"; | ||
import { LinkMutations } from "../links/Links"; | ||
export interface InitializeArgs { | ||
@@ -36,2 +37,3 @@ did: string; | ||
updatePublicPerspective(perspective: PerspectiveInput): Promise<Agent>; | ||
mutatePublicPerspective(mutations: LinkMutations): Promise<Agent>; | ||
updateDirectMessageLanguage(directMessageLanguage: string): Promise<Agent>; | ||
@@ -38,0 +40,0 @@ addEntanglementProofs(proofs: EntanglementProofInput[]): Promise<EntanglementProof[]>; |
@@ -22,2 +22,3 @@ "use strict"; | ||
const AgentStatus_1 = require("./AgentStatus"); | ||
const PerspectiveClient_1 = __importDefault(require("../perspectives/PerspectiveClient")); | ||
const AGENT_SUBITEMS = ` | ||
@@ -159,2 +160,9 @@ did | ||
async updatePublicPerspective(perspective) { | ||
const cleanedPerspective = JSON.parse(JSON.stringify(perspective)); | ||
delete cleanedPerspective.__typename; | ||
cleanedPerspective.links.forEach(link => { | ||
delete link.__typename; | ||
delete link.data.__typename; | ||
delete link.proof.__typename; | ||
}); | ||
const { agentUpdatePublicPerspective } = (0, unwrapApolloResult_1.default)(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({ | ||
@@ -166,3 +174,3 @@ mutation: (0, core_1.gql) `mutation agentUpdatePublicPerspective($perspective: PerspectiveInput!) { | ||
}`, | ||
variables: { perspective: perspective } | ||
variables: { perspective: cleanedPerspective } | ||
})); | ||
@@ -174,2 +182,26 @@ const a = agentUpdatePublicPerspective; | ||
} | ||
async mutatePublicPerspective(mutations) { | ||
const perspectiveClient = new PerspectiveClient_1.default(__classPrivateFieldGet(this, _AgentClient_apolloClient, "f")); | ||
const agentClient = new AgentClient(__classPrivateFieldGet(this, _AgentClient_apolloClient, "f")); | ||
//Create the proxy perspective and load existing links | ||
const proxyPerspective = await perspectiveClient.add("Agent Perspective Proxy"); | ||
const agentMe = await agentClient.me(); | ||
if (agentMe.perspective) { | ||
await proxyPerspective.loadSnapshot(agentMe.perspective); | ||
} | ||
//Make the mutations on the proxy perspective | ||
for (const addition of mutations.additions) { | ||
await proxyPerspective.add(addition); | ||
} | ||
for (const removal of mutations.removals) { | ||
await proxyPerspective.remove(removal); | ||
} | ||
//Get the snapshot of the proxy perspective | ||
const snapshot = await proxyPerspective.snapshot(); | ||
//Update the users public perspective | ||
const agent = await this.updatePublicPerspective(snapshot); | ||
//Cleanup and return | ||
await perspectiveClient.remove(proxyPerspective.uuid); | ||
return agent; | ||
} | ||
async updateDirectMessageLanguage(directMessageLanguage) { | ||
@@ -176,0 +208,0 @@ const { agentUpdateDirectMessageLanguage } = (0, unwrapApolloResult_1.default)(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({ |
@@ -16,2 +16,3 @@ import { ApolloClient } from "@apollo/client/core"; | ||
source(address: string): Promise<string>; | ||
remove(address: string): Promise<Boolean>; | ||
} |
@@ -131,4 +131,15 @@ "use strict"; | ||
} | ||
async remove(address) { | ||
const { languageRemove } = (0, unwrapApolloResult_1.default)(await __classPrivateFieldGet(this, _LanguageClient_apolloClient, "f").mutate({ | ||
mutation: (0, core_1.gql) `mutation languageRemove( | ||
$address: String!, | ||
) { | ||
languageRemove(address: $address) | ||
}`, | ||
variables: { address } | ||
})); | ||
return languageRemove; | ||
} | ||
} | ||
exports.LanguageClient = LanguageClient; | ||
_LanguageClient_apolloClient = new WeakMap(); |
@@ -18,2 +18,3 @@ import { LanguageHandle } from "./LanguageHandle"; | ||
languageSource(address: string): string; | ||
languageRemove(address: string): Boolean; | ||
} |
@@ -81,2 +81,3 @@ "use strict"; | ||
} | ||
languageRemove(address) { return true; } | ||
}; | ||
@@ -135,2 +136,9 @@ __decorate([ | ||
], LanguageResolver.prototype, "languageSource", null); | ||
__decorate([ | ||
(0, type_graphql_1.Mutation)(), | ||
__param(0, (0, type_graphql_1.Arg)('address')), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [String]), | ||
__metadata("design:returntype", Boolean) | ||
], LanguageResolver.prototype, "languageRemove", null); | ||
LanguageResolver = __decorate([ | ||
@@ -137,0 +145,0 @@ (0, type_graphql_1.Resolver)() |
@@ -7,2 +7,6 @@ export declare class Link { | ||
} | ||
export declare class LinkMutations { | ||
additions: LinkInput[]; | ||
removals: LinkExpression[]; | ||
} | ||
export declare class LinkInput { | ||
@@ -9,0 +13,0 @@ source: string; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLink = exports.linkEqual = exports.LinkExpressionInput = exports.LinkExpression = exports.LinkInput = exports.Link = void 0; | ||
exports.isLink = exports.linkEqual = exports.LinkExpressionInput = exports.LinkExpression = exports.LinkInput = exports.LinkMutations = exports.Link = void 0; | ||
const type_graphql_1 = require("type-graphql"); | ||
@@ -40,2 +40,16 @@ const Expression_1 = require("../expression/Expression"); | ||
exports.Link = Link; | ||
let LinkMutations = class LinkMutations { | ||
}; | ||
__decorate([ | ||
(0, type_graphql_1.Field)(type => [LinkInput]), | ||
__metadata("design:type", Array) | ||
], LinkMutations.prototype, "additions", void 0); | ||
__decorate([ | ||
(0, type_graphql_1.Field)(type => [LinkExpression]), | ||
__metadata("design:type", Array) | ||
], LinkMutations.prototype, "removals", void 0); | ||
LinkMutations = __decorate([ | ||
(0, type_graphql_1.InputType)() | ||
], LinkMutations); | ||
exports.LinkMutations = LinkMutations; | ||
let LinkInput = class LinkInput { | ||
@@ -42,0 +56,0 @@ }; |
@@ -111,3 +111,9 @@ "use strict"; | ||
async loadSnapshot(snapshot) { | ||
for (const link of snapshot.links) { | ||
//Clean the input data from __typename | ||
const cleanedSnapshot = JSON.parse(JSON.stringify(snapshot)); | ||
delete cleanedSnapshot.__typename; | ||
cleanedSnapshot.links.forEach(link => { | ||
delete link.data.__typename; | ||
}); | ||
for (const link of cleanedSnapshot.links) { | ||
await this.add(link.data); | ||
@@ -114,0 +120,0 @@ } |
@@ -174,2 +174,3 @@ | ||
languagePublish(languageMeta: LanguageMetaInput!, languagePath: String!): LanguageMeta! | ||
languageRemove(address: String!): Boolean! | ||
languageWriteSettings(languageAddress: String!, settings: String!): Boolean! | ||
@@ -176,0 +177,0 @@ neighbourhoodJoinFromUrl(url: String!): PerspectiveHandle! |
@@ -174,2 +174,3 @@ | ||
languagePublish(languageMeta: LanguageMetaInput!, languagePath: String!): LanguageMeta! | ||
languageRemove(address: String!): Boolean! | ||
languageWriteSettings(languageAddress: String!, settings: String!): Boolean! | ||
@@ -176,0 +177,0 @@ neighbourhoodJoinFromUrl(url: String!): PerspectiveHandle! |
{ | ||
"name": "@perspect3vism/ad4m", | ||
"version": "0.1.36", | ||
"version": "0.1.37", | ||
"description": "*The Agent-Centric Distributed Application Meta-ontology* or just: *Agent-Centric DApp Meta-ontology* * A new meta-ontology for interoperable, decentralized application design * A spanning-layer to enable seamless integration between Holochain DNAs, blockchains, linked-data structures/ontologies and centralized back-ends * The basis for turning distinct, monolithic and siloed apps into a global, open and interoperable sense-making network", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -18,3 +18,3 @@ import { buildSchema } from "type-graphql" | ||
import { Perspective } from "./perspectives/Perspective"; | ||
import { Link, LinkExpression, LinkExpressionInput, LinkInput } from "./links/Links"; | ||
import { Link, LinkExpression, LinkExpressionInput, LinkInput, LinkMutations } from "./links/Links"; | ||
import LanguageResolver from "./language/LanguageResolver"; | ||
@@ -178,2 +178,26 @@ import NeighbourhoodResolver from "./neighbourhood/NeighbourhoodResolver"; | ||
it('mutatePublicPerspective() smoke test', async () => { | ||
let additionLink = new Link({source: 'root', target: 'perspective://Qm34589a3ccc0'}) | ||
const removalLink = new LinkExpression() | ||
removalLink.author = "did:ad4m:test" | ||
removalLink.timestamp = Date.now().toString() | ||
removalLink.data = { | ||
source: 'root2', | ||
target: 'perspective://Qm34589a3ccc0' | ||
} | ||
removalLink.proof = { | ||
signature: '', | ||
key: '', | ||
valid: true | ||
} | ||
//Note; here we dont get the links above since mutatePublicPerspective relies on a snapshot which returns the default test link for perspectives | ||
const agent = await ad4mClient.agent.mutatePublicPerspective({additions: [additionLink], removals: [removalLink]} as LinkMutations) | ||
expect(agent.did).toBe('did:ad4m:test') | ||
expect(agent.perspective.links.length).toBe(1) | ||
expect(agent.perspective.links[0].data.source).toBe('root') | ||
expect(agent.perspective.links[0].data.target).toBe('neighbourhood://Qm12345') | ||
}) | ||
it('updateDirectMessageLanguage() smoke test', async () => { | ||
@@ -375,2 +399,7 @@ const agent = await ad4mClient.agent.updateDirectMessageLanguage("abcd") | ||
}) | ||
it('remove() smoke test', async () => { | ||
const result = await ad4mClient.languages.remove("Qm12345"); | ||
expect(result).toBe(true); | ||
}) | ||
}) | ||
@@ -377,0 +406,0 @@ |
@@ -6,2 +6,4 @@ import { ApolloClient, gql } from "@apollo/client/core"; | ||
import { AgentStatus } from "./AgentStatus" | ||
import { LinkMutations } from "../links/Links"; | ||
import PerspectiveClient from "../perspectives/PerspectiveClient"; | ||
@@ -167,2 +169,10 @@ const AGENT_SUBITEMS = ` | ||
async updatePublicPerspective(perspective: PerspectiveInput): Promise<Agent> { | ||
const cleanedPerspective = JSON.parse(JSON.stringify(perspective)); | ||
delete cleanedPerspective.__typename; | ||
cleanedPerspective.links.forEach(link => { | ||
delete link.__typename; | ||
delete link.data.__typename; | ||
delete link.proof.__typename; | ||
}); | ||
const { agentUpdatePublicPerspective } = unwrapApolloResult(await this.#apolloClient.mutate({ | ||
@@ -174,3 +184,3 @@ mutation: gql`mutation agentUpdatePublicPerspective($perspective: PerspectiveInput!) { | ||
}`, | ||
variables: { perspective: perspective } | ||
variables: { perspective: cleanedPerspective } | ||
})) | ||
@@ -183,2 +193,31 @@ const a = agentUpdatePublicPerspective | ||
async mutatePublicPerspective(mutations: LinkMutations): Promise<Agent> { | ||
const perspectiveClient = new PerspectiveClient(this.#apolloClient); | ||
const agentClient = new AgentClient(this.#apolloClient); | ||
//Create the proxy perspective and load existing links | ||
const proxyPerspective = await perspectiveClient.add("Agent Perspective Proxy"); | ||
const agentMe = await agentClient.me(); | ||
if (agentMe.perspective) { | ||
await proxyPerspective.loadSnapshot(agentMe.perspective); | ||
} | ||
//Make the mutations on the proxy perspective | ||
for (const addition of mutations.additions) { | ||
await proxyPerspective.add(addition); | ||
} | ||
for (const removal of mutations.removals) { | ||
await proxyPerspective.remove(removal); | ||
} | ||
//Get the snapshot of the proxy perspective | ||
const snapshot = await proxyPerspective.snapshot(); | ||
//Update the users public perspective | ||
const agent = await this.updatePublicPerspective(snapshot); | ||
//Cleanup and return | ||
await perspectiveClient.remove(proxyPerspective.uuid); | ||
return agent | ||
} | ||
async updateDirectMessageLanguage(directMessageLanguage: string): Promise<Agent> { | ||
@@ -185,0 +224,0 @@ const { agentUpdateDirectMessageLanguage } = unwrapApolloResult(await this.#apolloClient.mutate({ |
@@ -145,2 +145,17 @@ import { ApolloClient, gql } from "@apollo/client/core" | ||
} | ||
async remove( | ||
address: string | ||
): Promise<Boolean> { | ||
const { languageRemove } = unwrapApolloResult(await this.#apolloClient.mutate({ | ||
mutation: gql`mutation languageRemove( | ||
$address: String!, | ||
) { | ||
languageRemove(address: $address) | ||
}`, | ||
variables: { address } | ||
})) | ||
return languageRemove | ||
} | ||
} |
@@ -94,3 +94,6 @@ | ||
} | ||
@Mutation() | ||
languageRemove(@Arg('address') address: string): Boolean { return true } | ||
} | ||
@@ -23,2 +23,11 @@ import { Field, InputType, ObjectType } from "type-graphql"; | ||
@InputType() | ||
export class LinkMutations { | ||
@Field(type => [LinkInput]) | ||
additions: LinkInput[]; | ||
@Field(type => [LinkExpression]) | ||
removals: LinkExpression[]; | ||
} | ||
@InputType() | ||
export class LinkInput { | ||
@@ -25,0 +34,0 @@ @Field() |
@@ -119,3 +119,10 @@ import PerspectiveClient, { LinkCallback, PerspectiveHandleCallback } from "./PerspectiveClient"; | ||
async loadSnapshot(snapshot: Perspective) { | ||
for(const link of snapshot.links) { | ||
//Clean the input data from __typename | ||
const cleanedSnapshot = JSON.parse(JSON.stringify(snapshot)); | ||
delete cleanedSnapshot.__typename; | ||
cleanedSnapshot.links.forEach(link => { | ||
delete link.data.__typename; | ||
}); | ||
for(const link of cleanedSnapshot.links) { | ||
await this.add(link.data) | ||
@@ -122,0 +129,0 @@ } |
Sorry, the diff of this file is too big to display
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
1258102
227
28626