-
Notifications
You must be signed in to change notification settings - Fork 93
docs: add StreamedListObjects documentation #1135
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
+134
−0
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4f1b5eb
docs: add StreamedListObjects documentation
daniel-jonathan ebcd40a
docs: add .NET SDK example for StreamedListObjects
daniel-jonathan 10c0d0c
docs: add .NET SDK support for StreamedListObjects
daniel-jonathan 0d03253
Merge branch 'main' into feat/streamed-list-objects-docs
daniel-jonathan 0f0727f
Merge branch 'main' into feat/streamed-list-objects-docs
daniel-jonathan edac180
Update src/components/Docs/SnippetViewer/StreamedListObjectsRequestVi…
daniel-jonathan f7055dd
Update docs/content/getting-started/perform-list-objects.mdx
daniel-jonathan a613721
Merge branch 'main' into feat/streamed-list-objects-docs
daniel-jonathan b6de853
Merge branch 'main' into feat/streamed-list-objects-docs
SoulPancake e66a664
Merge branch 'main' into feat/streamed-list-objects-docs
SoulPancake b33da20
Merge branch 'main' into feat/streamed-list-objects-docs
SoulPancake e65cc41
feat: add go and java examples in docs
SoulPancake 1da1b2a
fix: prettier fix
SoulPancake 8bdd679
Merge branch 'main' into feat/streamed-list-objects-docs
SoulPancake 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
106 changes: 106 additions & 0 deletions
106
src/components/Docs/SnippetViewer/StreamedListObjectsRequestViewer.tsx
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,106 @@ | ||
| import { getFilteredAllowedLangs, SupportedLanguage } from './SupportedLanguage'; | ||
| import { defaultOperationsViewer } from './DefaultTabbedViewer'; | ||
| import assertNever from 'assert-never/index'; | ||
|
|
||
| interface StreamedListObjectsRequestViewerOpts { | ||
| user: string; | ||
| relation: string; | ||
| objectType: string; | ||
| expectedResults: string[]; | ||
| skipSetup?: boolean; | ||
| allowedLanguages?: SupportedLanguage[]; | ||
| } | ||
|
|
||
| function streamedListObjectsRequestViewer(lang: SupportedLanguage, opts: StreamedListObjectsRequestViewerOpts): string { | ||
| const { user, relation, objectType, expectedResults } = opts; | ||
|
|
||
| switch (lang) { | ||
| case SupportedLanguage.PLAYGROUND: | ||
| return `# Note: Streamed List Objects is not currently supported on the playground`; | ||
| case SupportedLanguage.CLI: | ||
| return `# Note: Streamed List Objects is not currently supported in the CLI`; | ||
| case SupportedLanguage.CURL: | ||
| return `curl -X POST $FGA_API_URL/stores/$FGA_STORE_ID/streamed-list-objects \\ | ||
| -H "Authorization: Bearer $FGA_API_TOKEN" \\ # Not needed if service does not require authorization | ||
SoulPancake marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -H "content-type: application/json" \\ | ||
| -d '{ | ||
| "type": "${objectType}", | ||
| "relation": "${relation}", | ||
| "user":"${user}" | ||
| }' | ||
|
|
||
|
|
||
| # Response: | ||
| ${expectedResults.map((r) => `{"result":{"object":"${r}"}}`).join('\n')}`; | ||
| case SupportedLanguage.JS_SDK: | ||
| return `const objects = []; | ||
| for await (const response of fgaClient.streamedListObjects( | ||
| { user: "${user}", relation: "${relation}", type: "${objectType}" } | ||
| )) { | ||
| objects.push(response.object); | ||
| } | ||
| // objects = [${expectedResults.map((r) => `"${r}"`).join(', ')}]`; | ||
| case SupportedLanguage.DOTNET_SDK: | ||
| return `var objects = new List<string>(); | ||
| await foreach (var response in fgaClient.StreamedListObjects( | ||
| new ClientListObjectsRequest { | ||
| User = "${user}", | ||
| Relation = "${relation}", | ||
| Type = "${objectType}" | ||
| })) { | ||
| objects.Add(response.Object); | ||
| } | ||
| // objects = [${expectedResults.map((r) => `"${r}"`).join(', ')}]`; | ||
| case SupportedLanguage.PYTHON_SDK: | ||
| return `objects = [] | ||
| async for response in fga_client.streamed_list_objects( | ||
| ClientListObjectsRequest( | ||
| user="${user}", | ||
| relation="${relation}", | ||
| type="${objectType}" | ||
| ) | ||
| ): | ||
| objects.append(response.object) | ||
| # objects = [${expectedResults.map((r) => `"${r}"`).join(', ')}]`; | ||
| case SupportedLanguage.GO_SDK: | ||
| return `objects := []string{} | ||
| err := fgaClient.StreamedListObjects(context.Background()). | ||
| Body(client.ClientListObjectsRequest{ | ||
| User: "${user}", | ||
| Relation: "${relation}", | ||
| Type: "${objectType}", | ||
| }). | ||
| Execute(func(response *client.ClientStreamedListObjectsResponse) error { | ||
| objects = append(objects, response.Object) | ||
| return nil | ||
| }) | ||
| // objects = [${expectedResults.map((r) => `"${r}"`).join(', ')}]`; | ||
| case SupportedLanguage.JAVA_SDK: | ||
| return `var objects = new ArrayList<String>(); | ||
| var request = new ClientListObjectsRequest() | ||
| .user("${user}") | ||
| .relation("${relation}") | ||
| .type("${objectType}"); | ||
|
|
||
| fgaClient.streamedListObjects(request, new ClientStreamedListObjectsOptions(), response -> { | ||
| objects.add(response.getObject()); | ||
| }).get(); | ||
| // objects = [${expectedResults.map((r) => `"${r}"`).join(', ')}]`; | ||
| case SupportedLanguage.RPC: | ||
| return `# Note: Use CURL or SDK for streaming examples`; | ||
| default: | ||
| return assertNever(lang); | ||
| } | ||
| } | ||
|
|
||
| export function StreamedListObjectsRequestViewer(opts: StreamedListObjectsRequestViewerOpts): JSX.Element { | ||
| const defaultLangs = [ | ||
| SupportedLanguage.JS_SDK, | ||
| SupportedLanguage.GO_SDK, | ||
| SupportedLanguage.DOTNET_SDK, | ||
| SupportedLanguage.PYTHON_SDK, | ||
| SupportedLanguage.JAVA_SDK, | ||
| ]; | ||
| const allowedLanguages = getFilteredAllowedLangs(opts.allowedLanguages, defaultLangs); | ||
| return defaultOperationsViewer(allowedLanguages, opts, streamedListObjectsRequestViewer); | ||
| } | ||
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
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.