-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add support for StreamedListObjects #280
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
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0c2a0ab
feat: add streamedListObjects for unlimited object retrieval
daniel-jonathan 6fe722d
feat/streaming-only: Removed unneeded requirement in CHANGELOG.
daniel-jonathan b010a25
refactor: address code review feedback
daniel-jonathan 3036f36
feat/streaming-only:: fixed merge conflicts from main
daniel-jonathan 0279076
docs: enhance StreamedListObjects example README
daniel-jonathan 71160b3
fix: batch tuple writes to respect 100-tuple limit
daniel-jonathan d149317
fix: batch tuple writes to respect 100-tuple limit
daniel-jonathan b2fa56f
chore: merge main into feat/streaming-only
daniel-jonathan 9d593dd
fix: prevent logging sensitive data in error handler
daniel-jonathan d8ffd07
fix: remove field name from validation error logging
daniel-jonathan 0d47948
refactor: Updated the example README based on review feedback
daniel-jonathan 2d523ed
Merge branch 'main' into feat/streaming-only
daniel-jonathan 5316902
Merge branch 'main' into feat/streaming-only
SoulPancake 3c9274e
Merge branch 'main' into feat/streaming-only
SoulPancake 195ba7c
Merge branch 'main' into feat/streaming-only
SoulPancake c80b8f5
Merge branch 'main' into feat/streaming-only
SoulPancake b929706
Merge branch 'main' into feat/streaming-only
SoulPancake a8cbf8e
Merge branch 'main' into feat/streaming-only
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
Some comments aren't visible on the classic Files Changed page.
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
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
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,21 @@ | ||
| # Streamed List Objects (Local) | ||
|
|
||
| This example demonstrates using the js-sdk `streamedListObjects` API against a locally running OpenFGA server that you manage yourself. | ||
|
|
||
| Prerequisites: | ||
| - Node.js 18+ | ||
daniel-jonathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - An OpenFGA server reachable at `FGA_API_URL` (defaults to `http://localhost:8080`) | ||
|
|
||
| Run: | ||
| 1. From repo root, build the SDK once: | ||
| - `npm run build` | ||
| 2. Set the API URL (optional) and run the example: | ||
| - `cd example/streamed-list-objects-local` | ||
| - `FGA_API_URL=http://localhost:8080 node streamedListObjectsLocal.mjs` | ||
|
|
||
| What it does: | ||
| - Creates a temporary store | ||
| - Writes a schema 1.1 model with an assignable relation | ||
| - Inserts 3 tuples | ||
| - Streams them via `streamedListObjects` | ||
| - Cleans up the store | ||
62 changes: 62 additions & 0 deletions
62
example/streamed-list-objects-local/streamedListObjectsLocal.mjs
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,62 @@ | ||
| import { ClientConfiguration, OpenFgaClient, ConsistencyPreference } from "../../dist/index.js"; | ||
daniel-jonathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const apiUrl = process.env.FGA_API_URL || "http://localhost:8080"; | ||
|
|
||
| async function main() { | ||
| const client = new OpenFgaClient(new ClientConfiguration({ apiUrl })); | ||
|
|
||
| console.log("Creating temporary store"); | ||
| const { id: storeId } = await client.createStore({ name: "streamed-list-objects-local" }); | ||
|
|
||
| const clientWithStore = new OpenFgaClient(new ClientConfiguration({ apiUrl, storeId })); | ||
|
|
||
| const model = { | ||
| schema_version: "1.1", | ||
| type_definitions: [ | ||
| { type: "user" }, | ||
| { | ||
| type: "document", | ||
| relations: { can_read: { this: {} } }, | ||
| metadata: { | ||
| relations: { | ||
| can_read: { | ||
| directly_related_user_types: [{ type: "user" }] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
daniel-jonathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| console.log("Writing authorization model"); | ||
| const { authorization_model_id: authorizationModelId } = await clientWithStore.writeAuthorizationModel(model); | ||
|
|
||
| const fga = new OpenFgaClient(new ClientConfiguration({ apiUrl, storeId, authorizationModelId })); | ||
|
|
||
| console.log("Writing tuples"); | ||
| await fga.write({ | ||
| writes: [ | ||
| { user: "user:anne", relation: "can_read", object: "document:1" }, | ||
| { user: "user:anne", relation: "can_read", object: "document:2" }, | ||
| { user: "user:anne", relation: "can_read", object: "document:3" } | ||
| ] | ||
| }); | ||
|
|
||
| console.log("Streaming objects..."); | ||
| let count = 0; | ||
| for await (const _ of fga.streamedListObjects( | ||
| { user: "user:anne", relation: "can_read", type: "document" }, | ||
| { consistency: ConsistencyPreference.HigherConsistency } | ||
| )) { | ||
| count++; | ||
| } | ||
daniel-jonathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| console.log(`\u2713 Streamed count: ${count}`); | ||
|
|
||
| console.log("Cleaning up..."); | ||
| await fga.deleteStore(); | ||
| console.log("Done"); | ||
| } | ||
|
|
||
| main().catch(_err => { | ||
| process.exit(1); | ||
| }); | ||
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.