Skip to content
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

[BSS-46] GetFollowers, GetProfiles, CreateRecord and PostBuilder API #12

Merged
merged 69 commits into from
Nov 8, 2024

Conversation

shahmal1yev
Copy link
Owner

@shahmal1yev shahmal1yev commented Sep 18, 2024

✨ Summary

This PR covers the implementation of several lexicons (GetFollowers, GetProfiles, CreateRecord) as well as specifications for Post, CID, and Multiformats (Multihash, Multicodec, Multibase).

🔄 Changes

🌟 Features

  • Creation of posts via the PostBuilder API
  • Flexible Blob Data Model and CID implementation to allow the use of preloaded blobs in the CreateRecord lexicon without requiring a call to the UploadBlob lexicon
  • Added GetFollowers, GetProfiles, and CreateRecord lexicons

@shahmal1yev shahmal1yev self-assigned this Sep 19, 2024
@shahmal1yev shahmal1yev added the enhancement New feature or request label Sep 19, 2024
shahmal1yev and others added 27 commits September 20, 2024 15:55
- Added parameter setters for `actor`, `limit`, and `cursor` with validation for `limit`.
- Implemented error handling with `AuthMissingException` and `MissingFieldProvidedException` during request building.
- Enhanced `Authentication` trait with token management.
- Added comprehensive unit tests for `GetFollowers` to ensure proper parameter handling, validation, and response.
- Implement ProfileAssetType for type validation
- Add token method to Authentication trait for easier token handling
- Create InvalidArgumentException
- Modify MissingFieldProvidedException message
- Update .gitignore to exclude PHP-CS-Fixer files
- Update RequestContract to allow array query parameters
- Add new RichText classes: FeatureAbstract, Link, Mention, and Tag
- Implement Facet lexicon structure as per app.bsky.richtext.facet schema
- Add unit tests for FeatureAbstract serialization
- Improve type safety and add input validation for union facet classes
…d tests

- Added `Stringable` interface to `File`, `Caption`, and `Image` for improved string handling.
- Updated `BlobHandler` to remove unnecessary `isValid` check, simplifying file handling logic.
- Enhanced `Caption` class with stricter validation for file size and type, using `InvalidArgumentException`.
- Improved constructor and method handling in `Caption`, ensuring proper setting of file and language.
- Created comprehensive unit tests for `Caption`, covering file validation, language setting, and JSON serialization.
- Introduced `FileMocking` trait for reusable mock file generation in tests.
…rect directory

- Add new test for the Video class related to embeds
- Update namespaces of lexicon unit test classes related to embeds to fix being under the wrong namespace
- Add CaptionInterface extending JsonSerializable and Stringable
- Update Caption class to implement CaptionInterface
- Modify CaptionCollection to use CaptionInterface
- Adjust VideoTest to work with new interface structure

Why: This change ensures proper serialization of Caption objects when json_encode is applied.
By extending JsonSerializable and Stringable interfaces, CaptionInterface guarantees
that Caption objects are converted to arrays during JSON serialization.
…reuse.

- Updated `CaptionCollection` and `ImageCollection` to use `EmbedCollection` for handling validation logic and ensuring consistent error handling.
- Simplified the validation process by using closures in the `validator` method to ensure objects implement their respective interfaces.
- Introduced custom exception handling for type errors to provide more meaningful feedback.
- Ensured that collections adhere to size limits, with clear error messages for exceeding maximum size or incorrect object types.
- Create src/Lexicons/App/Bsky/Embed/External.php for External embed implementation
- Add tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php for unit tests
On branch embeds
Changes to be committed:
	renamed:    src/Lexicons/App/Bsky/Embed/File.php -> src/Lexicons/App/Bsky/Embed/Blob.php
- Add StrongRef class for com.atproto.repo.strongRef
- Implement JsonSerializable and Stringable interfaces for both classes
- Add unit tests for Record and StrongRef classes
- Include getter/setter methods and JSON serialization
- Add MediaInterface for unifying different media types
- Implement MediaInterface in ImageCollection, External, and Video classes
- Create RecordWithMedia class to combine Record with media content
- Add unit tests for RecordWithMedia
- Update existing classes to implement new MediaInterface
- EmbedInterface was introduced. All embeds were refactored to implement EmbedInterface.
This interface extends two essential interfaces - JsonSerializable and Stringable,
which are mandatory for Lexicon implementations. The reason is that when building a post with the PostBuilder API,
each entity that can be used as an embed is a lexicon, and a lexicon should be serializable to an object or array type
according to SDK design policy when necessary. The Lexicon interface to be introduced
in the future will also extend these two interfaces, and all necessary entities will be refactored.

- An embed method was added to the PostBuilder API, related tests were refactored/written.
Integrate embed functionality into post builder

This merge enhances the post builder with comprehensive embed capabilities,
aligning with AT Protocol specifications for rich media content in posts.
… fix text length validation

This merge incorporates the following changes from the 'reply' branch:

- **Implemented** the `reply` method in the `PostBuilderContract` interface and the `Post` class, allowing the setting of `replyRef` with `root` and `parent` `StrongRef` objects. This addition enhances the API by enabling the creation of reply posts that correctly reference the root and parent posts.

- **Fixed** the text length validation in the `Post::validate()` method to correctly check the cumulative length of the post text against the `TEXT_LIMIT`. This ensures that posts cannot exceed the maximum allowed text length, maintaining compliance with defined constraints.

- **Updated** unit tests in `PostTest` to reflect the new `reply` method and to fix failing tests due to text length validation. Adjustments include renaming methods for clarity, correcting assertions, and ensuring tests accurately cover the new functionality.

**Impact:**

- Enhances the PostBuilder API with reply functionality.
- Ensures robust text length validation to prevent errors.
- Improves test coverage and reliability.

This merge enhances the usability and reliability of the library by adding reply capabilities and ensuring text length constraints are properly enforced.
- Added `langs` method to PostBuilderContract interface to handle language settings for a post.
- Implemented `langs` method in the Post class to set and validate language codes with a limit of 3 languages.
- Added validation for language codes using a regex to ensure conformity with the standard language tag format.
- Merged the 'langs' feature into the 'post-builder' branch, which adds language support to the PostBuilder API.
- Features added from 'langs':
  - `langs` method to set and validate up to 3 language codes for posts.
  - Regex-based validation of language codes conforming to IETF BCP 47.
  - Updates to `jsonSerialize` to include the `langs` field.
  - New unit tests for language validation and handling in posts.
- Add tests for new blob and CID systems
- Update embed system tests
- Clean up test organization and assertions
- Improve mock implementations
- implement Authentication trait for tracking session changes
- fix HTTP method to POST for proper API request
- add feature tests for blob reuse in posts

Previously uploaded blobs can now be reused in post creation without re-uploading 🚀
…-reported issues

- Update tests to ensure compatibility with recent refactoring, including modified methods and type hints.
- Fix failing tests by addressing issues reported in test results, such as data handling in `jsonSerialize()` and validation exceptions.
- Removed unused Authentication logic from GetFollowers
- Enhanced GetFollowersResource with SubjectAsset
- Added SubjectAsset class for expanded resource support
- Introduced feature test for GetFollowers functionality
- Updated unit tests for authorization and missing field exceptions
- Updated `CreateRecord::record()` to accept only `PostBuilderContract` type, updated type safety for record instances
- Added validation in `CreateRecord::rkey()` to restrict `rkey` to a max of 15 characters, throwing `InvalidArgumentException` on failure
- Adjusted unit tests to mock `PostBuilderContract` for compatibility with updated `record` method signature
- **Renaming**:
  - `RequestNotFoundException` renamed to `LexiconNotFoundException` for consistency in exception naming.
  - Renamed `type_name` to `nsid` in `PostBuilderContract` to better align with lexicon naming conventions.
  - `Authentication` trait renamed to `AuthenticatedLexicon` for lexicons that require authentication, improving clarity.

- **New Implementations**:
  - Introduced `LexiconContract` interface on all lexicons for unified structure.
  - Created a new `Lexicon` trait to prevent code duplication across lexicons.

Enhancement: Add Serializable and Endpoint Traits

- **New Traits**:
  - **Serializable**: Applied to all serializable classes to reduce code duplication.
  - **Endpoint**: Extends `Serializable` and applies to endpoint lexicons.
  - **AuthenticatedEndpoint**: Dedicated for lexicons that require authentication.

- **New Interface - SerializableContract**:
  - **SerializableContract**: Introduced to support classes needing serialization, currently implementing `Stringable` and `JsonSerializable`. Future support for `dagCbor` is planned.
  - **LexiconContract**: Extends `SerializableContract` and applies to all lexicon classes within Atproto. Future updates will add `nsid` and other signatures.
- Use explicit HTTP method definitions in each endpoint
- Remove hardcoded POST method from AuthenticatedEndpoint trait
- Add AuthenticatedEndpoint to GetFollowers endpoint
- Fix initialization order in CreateSession endpoint
- Remove unnecessary TypeInterface classes for collection validation
- Replace *AssetType classes with closure type validation
- Update CollectionObject trait to use Closure instead of TypeInterface
- Simplify type validation in collection objects using instanceof checks
- Remove redundant test for type method
- Remove unused file.png from art directory
@shahmal1yev shahmal1yev merged commit a34f609 into development Nov 8, 2024
4 checks passed
@shahmal1yev shahmal1yev added release Release announcement and removed wip Work in progress labels Nov 9, 2024
@shahmal1yev shahmal1yev deleted the bss-46 branch November 10, 2024 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request release Release announcement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant