Browse Source

tidying up

dev
Cerys 1 week ago
parent
commit
b80a57c994
  1. 20
      src/Core/DeegraphServer.php
  2. 10
      src/QueryBuilder/QueryBuilderTrait.php
  3. 11
      src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php
  4. 2
      tests/QueryBuilderPermissionsTest.php

20
src/Core/DeegraphServer.php

@ -42,7 +42,7 @@ class DeegraphServer
* *
* @throws Exception * @throws Exception
*/ */
private function RunRawRequest( private function runRawRequest(
UUID $actorID, UUID $actorID,
string $endpoint, string $endpoint,
string $method = "GET", string $method = "GET",
@ -140,9 +140,9 @@ class DeegraphServer
return $temp; 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, actorID: $actorID,
endpoint: "/api/v1/@query", endpoint: "/api/v1/@query",
method: "POST", 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, actorID: $actorID,
endpoint: "/api/v1/{$nodeID}", endpoint: "/api/v1/{$nodeID}",
method: "GET", method: "GET",
@ -165,9 +165,9 @@ class DeegraphServer
* Runs an API request against the Deegraph Server, and returns back information about the Deegraph Server. * Runs an API request against the Deegraph Server, and returns back information about the Deegraph Server.
* @return ServerInfo * @return ServerInfo
*/ */
public function ServerInfo(UUID $actorID): ServerInfo public function serverInfo(UUID $actorID): ServerInfo
{ {
$response = $this->RunRawRequest( $response = $this->runRawRequest(
actorID: $actorID, actorID: $actorID,
endpoint: "/api/v1/@server_info", endpoint: "/api/v1/@server_info",
method: "GET", method: "GET",
@ -177,9 +177,9 @@ class DeegraphServer
} }
public function CreateNewNode( public function createNewNode(
UUID $actorID, UUID $actorID,
string $dataURL, ?string $dataURL = null,
?string $schema = null, ?string $schema = null,
?UUID $creator = null ?UUID $creator = null
): NewNodeDetails ): NewNodeDetails
@ -190,7 +190,7 @@ class DeegraphServer
if($schema != null) if($schema != null)
$body["@schema"] = $schema; $body["@schema"] = $schema;
$response = $this->RunRawRequest( $response = $this->runRawRequest(
actorID: $actorID, actorID: $actorID,
endpoint: "/api/v1/@new", endpoint: "/api/v1/@new",
method: "PUT", method: "PUT",

10
src/QueryBuilder/QueryBuilderTrait.php

@ -21,28 +21,28 @@ use ReflectionClass;
trait QueryBuilderTrait 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)) if (!preg_match(pattern: $pattern, subject: $target))
throw new QueryBuilderInvalidInputException(); throw new QueryBuilderInvalidInputException();
return $target; return $target;
} }
protected function EnsureNotSet(string $target): void protected function ensureNotSet(string $target): void
{ {
if ($target != "") if ($target != "")
throw new QueryBuilderConflictingFieldAlreadyExistsException(); 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(); throw new QueryBuilderInvalidInputException();
return $target; return $target;
} }
protected function ValidateValues( public function validateValues(
DeleteQueryBuilder DeleteQueryBuilder
|DirectoryQueryBuilder |DirectoryQueryBuilder
|InsertQueryBuilder |InsertQueryBuilder

11
src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php

@ -5,9 +5,20 @@ namespace Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery;
class ReferencesQueryResponse class ReferencesQueryResponse
{ {
public array $Map; public array $Map;
public int $Count;
public function __construct(array $deegraphResponse) public function __construct(array $deegraphResponse)
{
if(isset($deegraphResponse["Map"]))
{ {
$this->Map = $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 final class QueryBuilderPermissionsTest extends TestCase
{ {
public function testReferenceQuery() public function testPermissionQuery()
{ {
$query = QueryBuilder::Permission() $query = QueryBuilder::Permission()
->on("{00000000-0000-0000-0000-000000000000}") ->on("{00000000-0000-0000-0000-000000000000}")

Loading…
Cancel
Save