Open hackerwins opened 2 months ago
Hello! Could I try this issue?
To keep external services informed about the state of documents, we should send events corresponding to the CRUD (Create, Read, Update, Delete) operations.
HTTP POST
application/json
200 OK
Event Type: documentCreated
Payload Schema:
{
"type": "documentCreated",
"attributes": {
"documentKey": "string",
"clientKey": "string",
"issuedAt": "string" // ISO 8601 timestamp
}
}
Example:
{
"type": "documentCreated",
"attributes": {
"documentKey": "document-key",
"clientKey": "client-key",
"issuedAt": "2024-10-06T05:43:52.318Z"
}
}
Event Type: documentWatched
Payload Schema:
{
"type": "documentWatched",
"attributes": {
"documentKey": "string",
"clientKey": "string",
"issuedAt": "string" // ISO 8601 timestamp
},
"data": {
"watchingNum": "integer"
}
}
Example:
{
"type": "documentWatched",
"attributes": {
"documentKey": "document-key",
"clientKey": "client-key",
"issuedAt": "2024-10-06T05:45:00.000Z"
},
"data": {
"watchingNum": 3
}
}
Event Type: documentUnwatched
Payload Schema:
{
"type": "documentUnwatched",
"attributes": {
"documentKey": "string",
"clientKey": "string",
"issuedAt": "string" // ISO 8601 timestamp
},
"data": {
"watchingNum": "integer"
}
}
Example:
{
"type": "documentUnwatched",
"attributes": {
"documentKey": "document-key",
"clientKey": "client-key",
"issuedAt": "2024-10-06T05:50:00.000Z"
},
"data": {
"watchingNum": 2
}
}
Event Type: documentChanged
Payload Schema:
{
"type": "documentChanged",
"attributes": {
"documentKey": "string",
"clientKey": "string",
"issuedAt": "string" // ISO 8601 timestamp
},
}
Example:
{
"type": "documentChanged",
"attributes": {
"documentKey": "document-key",
"clientKey": "client-key",
"issuedAt": "2024-10-06T06:00:00.000Z"
},
}
Event Type: snapshotStored
Payload Schema:
{
"type": "snapshotStored",
"attributes": {
"documentKey": "string",
"clientKey": "string",
"issuedAt": "string" // ISO 8601 timestamp
},
"data": {
"snapshot": "string" // marshaled snapshot data
}
}
Example:
{
"type": "snapshotStored",
"attributes": {
"documentKey": "document-key",
"clientKey": "client-key",
"issuedAt": "2024-10-06T06:05:00.000Z"
},
"data": {
"snapshot": "",
}
}
Event Type: documentDeleted
Payload Schema:
{
"type": "documentDeleted",
"attributes": {
"documentKey": "string",
"clientKey": "string",
"issuedAt": "string" // ISO 8601 timestamp
}
}
Example:
{
"type": "documentDeleted",
"attributes": {
"documentKey": "document-key",
"clientKey": "client-key",
"issuedAt": "2024-10-06T06:10:00.000Z"
}
}
documentKey
: Unique identifier for the document.clientKey
: Unique identifier for the client. If our user (CodePair) sets the clientKey
to their user_id
, they can identify who made the event.issuedAt
: Timestamp when the event was issued (ISO 8601 format).watchingNum
):
watchingNum
to indicate the number of clients currently watching the document.watchingNum
is currently uncertain, and its implementation might not be immediately necessary.changeNum
) does not accurately represent the amount of data changed.
If the above data types are finalized, we should consider the following:
endpoint
property in the project configuration to specify where the data should be sent.
What would you like to be added:
We are currently implementing an LLM-based document search functionality in CodePair. As part of this, we need to maintain a vector of document content in Vector Store. It's crucial that any updates to the document are reflected in the Vector Store by continually editing the content.
To achieve this, we require a mechanism that notifies external services like CodePair when documents are modified in Yorkie. We propose the introduction of a Webhook system that triggers when a document event occurs.
Specifically, we suggest that when handling the PushPullChanges requests, the server should check if a Webhook for the DocEvent is registered for the project. If it is, the server would call that Webhook during the background routine of the PushPullChanges API execution, right before publishing the DocEvent.
I think it will have a similar structure to the Auth Webhook, and if changes occur frequently, an event control device such as debouncing will also be needed.
Why is this needed:
This enhancement would enable seamless integration with external services, allowing for real-time updates to Search Engine or Vector Store based on document changes in Yorkie, thereby enhancing the overall document management and search capabilities of our application.