Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion codegen/lib/layouts/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const generateFromJsonProp = (property: ResourceClassProperty): string => {
return `${name}: isset($json->${name}) ? ${property.referenceName}::from_json($json->${name}) : null,`

case 'listReference':
return `${name}: array_map(fn ($${name[0]}) => ${property.referenceName}::from_json($${name[0]}), $json->${name} ?? []),`
// array_map raises a TypeError on a list property the API sends as a scalar.
return `${name}: \\Seam\\Parse::to_list($json->${name} ?? null, fn ($${name[0]}) => ${property.referenceName}::from_json($${name[0]})),`

case 'record':
return `${name}: $json->${name} ?? null,`
Expand Down
31 changes: 31 additions & 0 deletions src/ActionAttemptUnknownStatusError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Seam;

use Seam\Resources\ActionAttempt;

/**
* Raised when an action attempt reports a status this SDK version does not know.
*
* Waiting can neither return it as a success nor call it a failure. Read the
* action attempt to inspect the status directly.
*/
class ActionAttemptUnknownStatusError extends ActionAttemptError
{
private string $status;

public function __construct(ActionAttempt $actionAttempt, string $status)
{
parent::__construct(
"Action attempt reported an unknown status \"{$status}\". " .
"This SDK version may predate it; upgrade or read the action attempt directly.",
$actionAttempt,
);
$this->status = $status;
}

public function getStatus(): string
{
return $this->status;
}
}
8 changes: 8 additions & 0 deletions src/Http/ResolveActionAttempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\ClientInterface;
use Seam\ActionAttemptFailedError;
use Seam\ActionAttemptUnknownStatusError;
use Seam\ActionAttemptTimeoutError;
use Seam\InvalidOptionsError;
use Seam\InvalidResponseError;
Expand Down Expand Up @@ -80,6 +81,13 @@ private static function poll(
throw new ActionAttemptFailedError($action_attempt);
}

if ($action_attempt->status !== "pending") {
throw new ActionAttemptUnknownStatusError(
$action_attempt,
(string) $action_attempt->status,
);
}

$remaining = $deadline - self::now();

if ($remaining <= 0.0) {
Expand Down
25 changes: 25 additions & 0 deletions src/Parse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Seam;

/**
* Conversion helpers that degrade rather than raise on an unexpected payload shape.
*/
final class Parse
{
/**
* Convert a list of objects, reading anything that is not a list as empty.
*
* @template T
* @param callable(mixed): T $from_json
* @return array<int, T>
*/
public static function to_list(mixed $value, callable $from_json): array
{
if (!is_array($value)) {
return [];
}

return array_values(array_map($from_json, $value));
}
}
20 changes: 10 additions & 10 deletions src/Resources/AccessCode.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions src/Resources/AccessGrant.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/Resources/AccessMethod.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/Resources/AcsAccessGroup.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Resources/AcsCredential.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Resources/AcsEncoder.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/Resources/AcsEntrance.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading