MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / canWrite

Method canWrite

lib/src/resource.ts:58–79  ·  view source on GitHub ↗

Checks if the agent has write rights by traversing the graph. Recursive function.

(
    store: Store,
    agent: string,
    child?: string,
  )

Source from the content-addressed store, hash-verified

56
57 /** Checks if the agent has write rights by traversing the graph. Recursive function. */
58 async canWrite(
59 store: Store,
60 agent: string,
61 child?: string,
62 ): Promise<[boolean, string | null]> {
63 const writeArray = this.get(properties.write);
64 if (writeArray && valToArray(writeArray).includes(agent)) {
65 return [true, null];
66 }
67 const parentSubject = this.get(properties.parent) as string;
68 if (parentSubject == undefined) {
69 return [false, `No write right or parent in ${this.getSubject()}`];
70 }
71 // This should not happen, but it prevents an infinite loop
72 if (child == parentSubject) {
73 console.warn('Circular parent', child);
74 return [true, `Circular parent in ${this.getSubject()}`];
75 }
76 const parent: Resource = await store.getResourceAsync(parentSubject);
77 // The recursive part
78 return await parent.canWrite(store, agent, this.getSubject());
79 }
80
81 /**
82 * Creates a clone of the Resource, which makes sure the reference is

Callers 1

tryCanWriteFunction · 0.80

Calls 4

getMethod · 0.95
getSubjectMethod · 0.95
valToArrayFunction · 0.90
getResourceAsyncMethod · 0.80

Tested by

no test coverage detected