You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Repo class description to reference documentation (#7)
This pull request adds documentation for the `Repo` class in the
`docs/airdrop_sdk_library_documentation.md` file. The new documentation
explains the purpose, usage, and methods of the `Repo` class, which is
used to manage and upload items to the Airdrop platform.
### Added Documentation for `Repo` Class:
* **Overview of `Repo` class**: Describes its role in managing items for
a specific `itemType`, handling normalization, and uploading items in
batches to the Airdrop platform. Includes usage instructions and notes
about instantiation via `WorkerAdapter`.
* **Detailed descriptions of properties and methods**:
- **`itemType` property**: Explains how to retrieve the type of items
managed by the repo.
- **`getItems` method**: Provides details on retrieving items awaiting
upload, with example usage and return value information.
- **`push` method**: Documents how to add items to the repo, including
normalization and automatic batch uploads.
- **`upload` method**: Explains manual upload functionality, including
optional batch parameter, return value, and example scenarios.
Work item: https://app.devrev.ai/devrev/works/ISS-188589
Manages a collection of items for a specific `itemType`. It handles item normalization (if a `normalize` function is provided) and automatically uploads the items in batches to the Airdrop platform. An instance of this class is created by the `WorkerAdapter.initializeRepos` method and can be retrieved using `WorkerAdapter.getRepo`.
750
+
751
+
### Usage
752
+
753
+
This class is not intended to be instantiated directly. You should use `adapter.initializeRepos()` to create `Repo` instances.
754
+
755
+
### `Repo.itemType` property
756
+
757
+
A read-only property that returns the item type of the repo.
Retrieves the array of items currently held in the repo that are awaiting the next batched upload.
775
+
776
+
### Usage
777
+
778
+
```typescript
779
+
repo.getItems();
780
+
```
781
+
782
+
#### Return value
783
+
784
+
An array of items of type `(NormalizedItem | NormalizedAttachment | Item)[]`.
785
+
786
+
#### Example
787
+
788
+
```typescript
789
+
const repo =adapter.getRepo('users');
790
+
const remainingUsers =repo?.getItems();
791
+
console.log(`There are ${remainingUsers.length} users waiting to be uploaded.`);
792
+
```
793
+
794
+
### `Repo.push` method
795
+
796
+
Adds an array of new items to the repo. If a `normalize` function was provided during initialization, each item is normalized before being added. If adding the new items causes the total number of items in the repo to meet or exceed the `batchSize`, a batch is automatically uploaded.
797
+
798
+
### Usage
799
+
800
+
```typescript
801
+
repo.push(items);
802
+
```
803
+
804
+
#### Parameters
805
+
806
+
-*items*
807
+
808
+
Required. An array of objects of type `Item` to be added to the repo.
809
+
810
+
#### Return value
811
+
812
+
A **promise**, which resolves to `true` if the items were successfully added (and any resulting batches were successfully uploaded) or `false` if an error occurred during batch upload.
813
+
814
+
#### Example
815
+
816
+
This is the primary method for adding data to be uploaded.
817
+
818
+
```typescript
819
+
// Assume 'adapter' is an initialized WorkerAdapter and 'users' is an array of user objects from an external API.
820
+
awaitadapter.getRepo('users')?.push(users);
821
+
```
822
+
823
+
### `Repo.upload` method
824
+
825
+
Manually triggers an upload of items to the Airdrop platform. If a `batch` is provided, only those items are uploaded. If no `batch` is provided, all items currently stored in the repo are uploaded, and the repo's internal item cache is cleared.
826
+
827
+
**Note:** This method is typically called automatically by the `push` method. You only need to call it manually if you want to force an upload of the remaining items that do not fill a complete batch.
828
+
829
+
### Usage
830
+
831
+
```typescript
832
+
repo.upload(batch);
833
+
```
834
+
835
+
#### Parameters
836
+
837
+
-*batch*
838
+
839
+
Optional. An array of items of type `(NormalizedItem | NormalizedAttachment | Item)[]` to be uploaded.
840
+
841
+
#### Return value
842
+
843
+
A **promise**, which resolves to `undefined` on a successful upload or an `ErrorRecord` if the upload fails.
844
+
845
+
#### Example
846
+
847
+
```typescript
848
+
const tasksRepo =adapter.getRepo('tasks');
849
+
850
+
// Push a small number of tasks that might not trigger an automatic upload.
851
+
awaittasksRepo?.push(finalTasks);
852
+
853
+
// Manually upload any remaining tasks at the end of a process.
0 commit comments