Browse Source

tidying up

dev
Cerys 6 days ago
parent
commit
b80a57c994
  1. 22
      src/Core/DeegraphServer.php
  2. 10
      src/QueryBuilder/QueryBuilderTrait.php
  3. 13
      src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php
  4. 2
      tests/QueryBuilderPermissionsTest.php

22
src/Core/DeegraphServer.php

@ -42,7 +42,7 @@ class DeegraphServer
*
* @throws Exception
*/
private function RunRawRequest(
private function runRawRequest(
UUID $actorID,
string $endpoint,
string $method = "GET",
@ -128,7 +128,7 @@ class DeegraphServer
message: "Deegraph server responded with an internal error code",
code: 0,
previous: null,
// trade: isset($server_output["@trace"]) ? $server_output["@trace"] : null
// trade: isset($server_output["@trace"]) ? $server_output["@trace"] : null
);
}
@ -140,9 +140,9 @@ class DeegraphServer
return $temp;
}
public function RunQuery(UUID $actorID, string $queryString): array
public function runQuery(UUID $actorID, string $queryString): array
{
return $this->RunRawRequest(
return $this->runRawRequest(
actorID: $actorID,
endpoint: "/api/v1/@query",
method: "POST",
@ -150,9 +150,9 @@ class DeegraphServer
);
}
public function GetRawNode(UUID $actorID, UUID $nodeID): DeegraphNodeDetails
public function getRawNode(UUID $actorID, UUID $nodeID): DeegraphNodeDetails
{
$response = $this->RunRawRequest(
$response = $this->runRawRequest(
actorID: $actorID,
endpoint: "/api/v1/{$nodeID}",
method: "GET",
@ -165,9 +165,9 @@ class DeegraphServer
* Runs an API request against the Deegraph Server, and returns back information about the Deegraph Server.
* @return ServerInfo
*/
public function ServerInfo(UUID $actorID): ServerInfo
public function serverInfo(UUID $actorID): ServerInfo
{
$response = $this->RunRawRequest(
$response = $this->runRawRequest(
actorID: $actorID,
endpoint: "/api/v1/@server_info",
method: "GET",
@ -177,9 +177,9 @@ class DeegraphServer
}
public function CreateNewNode(
public function createNewNode(
UUID $actorID,
string $dataURL,
?string $dataURL = null,
?string $schema = null,
?UUID $creator = null
): NewNodeDetails
@ -190,7 +190,7 @@ class DeegraphServer
if($schema != null)
$body["@schema"] = $schema;
$response = $this->RunRawRequest(
$response = $this->runRawRequest(
actorID: $actorID,
endpoint: "/api/v1/@new",
method: "PUT",

10
src/QueryBuilder/QueryBuilderTrait.php

@ -21,28 +21,28 @@ use ReflectionClass;
trait QueryBuilderTrait
{
protected function RegexValidate(string $target, string $pattern): string
protected function regexValidate(string $target, string $pattern): string
{
if (!preg_match(pattern: $pattern, subject: $target))
throw new QueryBuilderInvalidInputException();
return $target;
}
protected function EnsureNotSet(string $target): void
protected function ensureNotSet(string $target): void
{
if ($target != "")
throw new QueryBuilderConflictingFieldAlreadyExistsException();
}
protected function ValidateDeegraphPath(string $target): string
protected function validateDeegraphPath(string $target): string
{
if (!RelativePath::Validate($target))
if (!RelativePath::validate($target))
throw new QueryBuilderInvalidInputException();
return $target;
}
protected function ValidateValues(
public function validateValues(
DeleteQueryBuilder
|DirectoryQueryBuilder
|InsertQueryBuilder

13
src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php

@ -5,9 +5,20 @@ namespace Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery;
class ReferencesQueryResponse
{
public array $Map;
public int $Count;
public function __construct(array $deegraphResponse)
{
$this->Map = $deegraphResponse["@map"];
if(isset($deegraphResponse["Map"]))
{
$this->Map = $deegraphResponse["@map"];
$this->Count = sizeof($this->Map);
}
else
{
$this->Map = [];
$this->Count = 0;
}
}
}

2
tests/QueryBuilderPermissionsTest.php

@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase;
final class QueryBuilderPermissionsTest extends TestCase
{
public function testReferenceQuery()
public function testPermissionQuery()
{
$query = QueryBuilder::Permission()
->on("{00000000-0000-0000-0000-000000000000}")

Loading…
Cancel
Save