Skip to content
Merged
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
170 changes: 168 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,170 @@
# Parts of this file were adapted from
# GitHub’s collection of .gitignore file templates
# which are Copyright (c) 2023 GitHub, Inc.
# and released under the MIT License.
# For more details, visit the project page:
# https://github.com/github/gitignore

# Codegen
CODEGEN.md

# Temporary development files
vendor
node_modules
tmp

# Build directories
package

# Environment versions file
.versions

# Tern
.tern-project
.tern-port

# npm config
.npmrc

# Temporary development files
tmp

# Yarn lockfile (only package-lock.json supported)
yarn.lock

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.vscode
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# yalc
.yalc/
yalc.lock

# Codegen exceptions
!codegen/lib/
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Prettier exceptions

*.hbs
CODEGEN.md
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

"overrides": [
{
"files": "**/*.{js,json,yml,md}",
"files": "**/*.{js,ts,json,yml,md}",
"options": {
"semi": false,
"singleQuote": true,
Expand Down
1 change: 1 addition & 0 deletions codegen/content/CODEGEN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Codegen
1 change: 1 addition & 0 deletions codegen/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null
1 change: 1 addition & 0 deletions codegen/layouts/default.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{contents}}
25 changes: 25 additions & 0 deletions codegen/layouts/object.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Seam\Objects;

class {{className}}
{
public static function from_json(mixed $json): {{className}}|null
{
if (!$json) {
return null;
}
return new self(
{{#each fromJsonProps}}
{{{this}}}
{{/each}}
);
}

public function __construct(
{{#each constructorParams}}
{{{this}}}
{{/each}}
) {
}
}
25 changes: 25 additions & 0 deletions codegen/layouts/partials/client-class.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class {{clientName}}Client
{
private SeamClient $seam;
{{#if hasChildClients}}
{{#each childClients}}
public {{clientName}}Client ${{namespace}};
{{/each}}
{{else}}

{{/if}}
public function __construct(SeamClient $seam)
{
$this->seam = $seam;
{{#each childClients}}
$this->{{namespace}} = new {{clientName}}Client($seam);
{{/each}}
}
{{#each methods}}

{{> route-method}}
{{/each}}
{{#if isActionAttempts}}
{{> poll-until-ready}}
{{/if}}
}
24 changes: 24 additions & 0 deletions codegen/layouts/partials/poll-until-ready.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public function poll_until_ready(string $action_attempt_id, float $timeout = 20.0): ActionAttempt
{
$seam = $this->seam;
$time_waiting = 0.0;
$polling_interval = 0.4;
$action_attempt = $seam->action_attempts->get($action_attempt_id);

while ($action_attempt->status == 'pending') {
$action_attempt = $seam->action_attempts->get(
$action_attempt->action_attempt_id
);
if ($time_waiting > $timeout) {
throw new ActionAttemptTimeoutError($action_attempt, $timeout);
}
$time_waiting += $polling_interval;
usleep($polling_interval * 1000000);
}

if ($action_attempt->status == 'error') {
throw new ActionAttemptFailedError($action_attempt);
}

return $action_attempt;
}
44 changes: 44 additions & 0 deletions codegen/layouts/partials/route-method.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
public function {{methodName}}({{{signatureParams}}}): {{returnType}} {
{{#if hasParams}}
$request_payload = [];

{{#each paramNames}}
if (${{this}} !== null) {
$request_payload["{{this}}"] = ${{this}};
}
{{/each}}

{{/if}}
{{#unless returnsVoid}}$res = {{/unless}}$this->seam->request(
"POST",
"{{path}}",
{{#if hasParams}}
json: (object) $request_payload,
{{/if}}
);
{{#if usesActionAttempt}}

if (!$wait_for_action_attempt) {
return {{returnResource}}::from_json($res->{{returnPath}});
}

$action_attempt = $this->seam->action_attempts->poll_until_ready($res->action_attempt->action_attempt_id);

return $action_attempt;
{{else}}
{{#if usesOnResponse}}

if ($on_response !== null) {
$on_response($res);
}
{{/if}}
{{#unless returnsVoid}}

{{#if isArrayResponse}}
return array_map(fn ($r) => {{returnResource}}::from_json($r), $res->{{returnPath}});
{{else}}
return {{returnResource}}::from_json($res->{{returnPath}});
{{/if}}
{{/unless}}
{{/if}}
}
Loading
Loading