-
Notifications
You must be signed in to change notification settings - Fork 200
feat: sdk for md #1265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: sdk for md #1265
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2bad05b
feat: docs sdk
ChiragAgg5k 4169b35
Merge branch 'master' into docs-sdk
ChiragAgg5k 411f102
change naming
ChiragAgg5k 621cfc4
fix permissions
ChiragAgg5k 528c7ce
nitpick
ChiragAgg5k 87854df
Merge branch 'master' into docs-sdk
ChiragAgg5k b3a4872
add sdk capabilities
ChiragAgg5k 5d7bc32
add readme
ChiragAgg5k 8493953
remove unused file
ChiragAgg5k 5e1eb61
improve type safety
ChiragAgg5k bd00b25
add publish workflow
ChiragAgg5k 27e1240
minor comments
ChiragAgg5k e6c700b
fix: markdown copy
ChiragAgg5k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,267 @@ | ||
| <?php | ||
|
|
||
| namespace Appwrite\SDK\Language; | ||
|
|
||
| use Appwrite\SDK\Language\JS; | ||
| use Twig\TwigFilter; | ||
|
|
||
| class Markdown extends JS | ||
| { | ||
| /** | ||
| * @return string | ||
| */ | ||
| public function getName(): string | ||
| { | ||
| return 'Markdown'; | ||
| } | ||
|
|
||
| /** | ||
| * @return array | ||
| */ | ||
| public function getKeywords(): array | ||
| { | ||
| // Markdown doesn't need keyword escaping | ||
| return []; | ||
| } | ||
|
|
||
| /** | ||
| * @return array | ||
| */ | ||
| public function getIdentifierOverrides(): array | ||
| { | ||
| return []; | ||
| } | ||
|
|
||
| public function getStaticAccessOperator(): string | ||
| { | ||
| return '.'; | ||
| } | ||
|
|
||
| public function getStringQuote(): string | ||
| { | ||
| return "'"; | ||
| } | ||
|
|
||
| public function getArrayOf(string $elements): string | ||
| { | ||
| return '[' . $elements . ']'; | ||
| } | ||
|
|
||
| /** | ||
| * @return array | ||
| */ | ||
| public function getFiles(): array | ||
| { | ||
| return [ | ||
| // GitHub workflows | ||
| [ | ||
| 'scope' => 'copy', | ||
| 'destination' => '.github/workflows/publish.yml', | ||
| 'template' => 'markdown/.github/workflows/publish.yml', | ||
| ], | ||
| // Package configuration | ||
| [ | ||
| 'scope' => 'default', | ||
| 'destination' => 'package.json', | ||
| 'template' => 'markdown/package.json.twig', | ||
| ], | ||
| [ | ||
| 'scope' => 'default', | ||
| 'destination' => 'README.md', | ||
| 'template' => 'markdown/README.md.twig', | ||
| ], | ||
| [ | ||
| 'scope' => 'copy', | ||
| 'destination' => 'tsconfig.json', | ||
| 'template' => 'markdown/tsconfig.json', | ||
| ], | ||
| // Source files | ||
| [ | ||
| 'scope' => 'copy', | ||
| 'destination' => 'src/types.ts', | ||
| 'template' => 'markdown/src/types.ts', | ||
| ], | ||
| [ | ||
| 'scope' => 'copy', | ||
| 'destination' => 'src/index.ts', | ||
| 'template' => 'markdown/src/index.ts', | ||
| ], | ||
| // Manifest | ||
| [ | ||
| 'scope' => 'copy', | ||
| 'destination' => 'src/manifest.ts', | ||
| 'template' => 'markdown/src/manifest.ts', | ||
| ], | ||
| // Build scripts | ||
| [ | ||
| 'scope' => 'copy', | ||
| 'destination' => 'scripts/build-manifest.ts', | ||
| 'template' => 'markdown/scripts/build-manifest.ts', | ||
| ], | ||
| // Documentation markdown files | ||
| [ | ||
| 'scope' => 'method', | ||
| 'destination' => 'docs/typescript/{{ service.name | caseLower }}/{{ method.name | caseKebab }}.md', | ||
| 'template' => 'markdown/typescript/method.md.twig', | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @param array $parameter | ||
| * @param array $method | ||
| * @return string | ||
| */ | ||
| public function getTypeName(array $parameter, array $method = []): string | ||
| { | ||
| // For TypeScript/JavaScript-like languages | ||
| if (isset($parameter['enumName'])) { | ||
| return \ucfirst($parameter['enumName']); | ||
| } | ||
| if (!empty($parameter['enumValues'])) { | ||
| return \ucfirst($parameter['name']); | ||
| } | ||
| if (isset($parameter['items'])) { | ||
| $parameter['array'] = $parameter['items']; | ||
| } | ||
| switch ($parameter['type']) { | ||
| case self::TYPE_INTEGER: | ||
| case self::TYPE_NUMBER: | ||
| return 'number'; | ||
| case self::TYPE_ARRAY: | ||
| if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) { | ||
| return $this->getTypeName($parameter['array']) . '[]'; | ||
| } | ||
| return 'any[]'; | ||
| case self::TYPE_FILE: | ||
| return 'File'; | ||
| case self::TYPE_OBJECT: | ||
| return 'object'; | ||
| } | ||
| return $parameter['type']; | ||
|
ChiragAgg5k marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * @param array $param | ||
| * @return string | ||
| */ | ||
| public function getParamDefault(array $param): string | ||
| { | ||
| $type = $param['type'] ?? ''; | ||
| $default = $param['default'] ?? ''; | ||
| $required = $param['required'] ?? false; | ||
|
|
||
| if ($required) { | ||
| return ''; | ||
| } | ||
|
|
||
| if (array_key_exists('default', $param)) { | ||
| return ' = ' . $default; | ||
| } | ||
|
ChiragAgg5k marked this conversation as resolved.
|
||
|
|
||
| return match ($type) { | ||
| self::TYPE_ARRAY => ' = []', | ||
| self::TYPE_OBJECT => ' = {}', | ||
| default => ' = null', | ||
| }; | ||
| } | ||
|
ChiragAgg5k marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * @param array $param | ||
| * @param string $lang | ||
| * @return string | ||
| */ | ||
| public function getParamExample(array $param, string $lang = ''): string | ||
| { | ||
| $type = $param['type'] ?? ''; | ||
| $example = $param['example'] ?? ''; | ||
|
|
||
| $hasExample = !empty($example) || $example === 0 || $example === false; | ||
|
|
||
| if (!$hasExample) { | ||
| return match ($type) { | ||
| self::TYPE_ARRAY => '[]', | ||
| self::TYPE_FILE => 'file', | ||
| self::TYPE_INTEGER, self::TYPE_NUMBER => '0', | ||
| self::TYPE_BOOLEAN => 'false', | ||
| self::TYPE_OBJECT => '{}', | ||
| self::TYPE_STRING => "''", | ||
| }; | ||
|
ChiragAgg5k marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return match ($type) { | ||
| self::TYPE_ARRAY => $this->isPermissionString($example) ? $this->getPermissionExample($example) : $example, | ||
| self::TYPE_INTEGER, self::TYPE_NUMBER => (string)$example, | ||
| self::TYPE_FILE => 'file', | ||
| self::TYPE_BOOLEAN => ($example) ? 'true' : 'false', | ||
| self::TYPE_OBJECT => ($example === '{}') | ||
| ? '{}' | ||
| : (($formatted = json_encode(json_decode($example, true), JSON_PRETTY_PRINT)) | ||
| ? $formatted | ||
| : $example), | ||
| self::TYPE_STRING => "'{$example}'", | ||
| }; | ||
| } | ||
|
|
||
| public function getPermissionExample(string $example): string | ||
| { | ||
| $permissions = $this->extractPermissionParts($example); | ||
| $result = []; | ||
|
|
||
| foreach ($permissions as $permission) { | ||
| $action = ucfirst($permission['action']); | ||
| $role = ucfirst($this->toCamelCase($permission['role'])); | ||
|
|
||
| if ($permission['id'] !== null) { | ||
| if ($permission['innerRole'] !== null) { | ||
| $result[] = "Permission.{$action}(Role.{$role}('{$permission['id']}', '{$permission['innerRole']}'))"; | ||
| } else { | ||
| $result[] = "Permission.{$action}(Role.{$role}('{$permission['id']}'))"; | ||
| } | ||
| } else { | ||
| $result[] = "Permission.{$action}(Role.{$role}())"; | ||
| } | ||
| } | ||
|
|
||
| return '[' . implode(', ', $result) . ']'; | ||
| } | ||
|
|
||
| public function getFilters(): array | ||
| { | ||
| return [ | ||
| new TwigFilter('getPropertyType', function ($value, $method = []) { | ||
| return $this->getTypeName($value, $method); | ||
| }), | ||
|
ChiragAgg5k marked this conversation as resolved.
|
||
| new TwigFilter('comment', function ($value) { | ||
| $value = explode("\n", $value); | ||
| foreach ($value as $key => $line) { | ||
| $value[$key] = wordwrap($line, 80, "\n"); | ||
| } | ||
| return implode("\n", $value); | ||
| }, ['is_safe' => ['html']]), | ||
| new TwigFilter('caseEnumKey', function (string $value) { | ||
| return $this->toPascalCase($value); | ||
| }), | ||
| new TwigFilter('getResponseModel', function (array $method) { | ||
| if (!empty($method['responseModel']) && $method['responseModel'] !== 'any') { | ||
| return 'Models.' . \ucfirst($method['responseModel']); | ||
| } | ||
| return null; | ||
| }), | ||
| new TwigFilter('needsPermissionImport', function (array $parameters) { | ||
| foreach ($parameters as $param) { | ||
| if (($param['type'] ?? '') === self::TYPE_ARRAY) { | ||
| $example = $param['example'] ?? ''; | ||
| if ($this->isPermissionString($example)) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| }), | ||
| new TwigFilter('decodeHtmlEntities', function (string $value) { | ||
| return html_entity_decode($value, ENT_QUOTES | ENT_HTML5, 'UTF-8'); | ||
| }), | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Publish to NPM | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| publish: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Use Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Update npm to latest version for OIDC support | ||
| run: npm install -g npm@latest | ||
|
|
||
| - name: Determine release tag | ||
| id: release_tag | ||
| run: | | ||
| if [[ "${{ github.ref }}" == *"-rc"* ]] || [[ "${{ github.ref }}" == *"-RC"* ]]; then | ||
| echo "tag=next" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "tag=latest" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Publish | ||
| run: npm publish --provenance --access public --tag ${{ steps.release_tag.outputs.tag }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Dependencies | ||
| node_modules/ | ||
|
|
||
| # Build output | ||
| dist/ | ||
|
|
||
| # Lock files (optional - remove if you want to commit) | ||
| package-lock.json | ||
|
|
||
| # OS files | ||
| .DS_Store | ||
|
|
||
| # IDE | ||
| .idea/ | ||
| .vscode/ | ||
| *.swp | ||
| *.swo | ||
|
|
||
| # Debug logs | ||
| npm-debug.log* |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.