Skip to content

Commit

Permalink
✨ Ozone sets (#2636)
Browse files Browse the repository at this point in the history
* ✨ Initial implementation of sets api on ozone

* ✨ Introduce sortDirection to querySets

* 🧹 Cleanup and refactor

* ✨ Align setView for response

* ♻️ Rename and add specific error

* 🐛 Cleanup unnecessary check that is covered by lexicon

* ✨ Rename remove to delete and add set suffix

* ✨ Use id and createdAt for values pagination

* ✨ Add index on createdAt for query perf and other cleanups

* 🐛 Set createdAt when inserting values

* 📝 Add changeset

* ✨ Add index on setId and createdAt
  • Loading branch information
foysalit authored Oct 8, 2024
1 parent 3e1ae8d commit 22d039a
Show file tree
Hide file tree
Showing 51 changed files with 3,212 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/modern-snails-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@atproto/ozone": patch
"@atproto/api": patch
---

Sets api to manage lists of strings on ozone, mostly aimed for automod configuration
32 changes: 32 additions & 0 deletions lexicons/tools/ozone/set/addValues.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"lexicon": 1,
"id": "tools.ozone.set.addValues",
"defs": {
"main": {
"type": "procedure",
"description": "Add values to a specific set. Attempting to add values to a set that does not exist will result in an error.",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["name", "values"],
"properties": {
"name": {
"type": "string",
"description": "Name of the set to add values to"
},
"values": {
"type": "array",
"minLength": 1,
"maxLength": 1000,
"items": {
"type": "string"
},
"description": "Array of string values to add to the set"
}
}
}
}
}
}
}
49 changes: 49 additions & 0 deletions lexicons/tools/ozone/set/defs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"lexicon": 1,
"id": "tools.ozone.set.defs",
"defs": {
"set": {
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"minLength": 3,
"maxLength": 128
},
"description": {
"type": "string",
"maxGraphemes": 1024,
"maxLength": 10240
}
}
},
"setView": {
"type": "object",
"required": ["name", "setSize", "createdAt", "updatedAt"],
"properties": {
"name": {
"type": "string",
"minLength": 3,
"maxLength": 128
},
"description": {
"type": "string",
"maxGraphemes": 1024,
"maxLength": 10240
},
"setSize": {
"type": "integer"
},
"createdAt": {
"type": "string",
"format": "datetime"
},
"updatedAt": {
"type": "string",
"format": "datetime"
}
}
}
}
}
36 changes: 36 additions & 0 deletions lexicons/tools/ozone/set/deleteSet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"lexicon": 1,
"id": "tools.ozone.set.deleteSet",
"defs": {
"main": {
"type": "procedure",
"description": "Delete an entire set. Attempting to delete a set that does not exist will result in an error.",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"description": "Name of the set to delete"
}
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"properties": {}
}
},
"errors": [
{
"name": "SetNotFound",
"description": "set with the given name does not exist"
}
]
}
}
}
37 changes: 37 additions & 0 deletions lexicons/tools/ozone/set/deleteValues.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"lexicon": 1,
"id": "tools.ozone.set.deleteValues",
"defs": {
"main": {
"type": "procedure",
"description": "Delete values from a specific set. Attempting to delete values that are not in the set will not result in an error",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["name", "values"],
"properties": {
"name": {
"type": "string",
"description": "Name of the set to delete values from"
},
"values": {
"type": "array",
"minLength": 1,
"items": {
"type": "string"
},
"description": "Array of string values to delete from the set"
}
}
}
},
"errors": [
{
"name": "SetNotFound",
"description": "set with the given name does not exist"
}
]
}
}
}
56 changes: 56 additions & 0 deletions lexicons/tools/ozone/set/getValues.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"lexicon": 1,
"id": "tools.ozone.set.getValues",
"defs": {
"main": {
"type": "query",
"description": "Get a specific set and its values",
"parameters": {
"type": "params",
"required": ["name"],
"properties": {
"name": {
"type": "string"
},
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 1000,
"default": 100
},
"cursor": {
"type": "string"
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["set", "values"],
"properties": {
"set": {
"type": "ref",
"ref": "tools.ozone.set.defs#setView"
},
"values": {
"type": "array",
"items": {
"type": "string"
}
},
"cursor": {
"type": "string"
}
}
}
},
"errors": [
{
"name": "SetNotFound",
"description": "set with the given name does not exist"
}
]
}
}
}
57 changes: 57 additions & 0 deletions lexicons/tools/ozone/set/querySets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"lexicon": 1,
"id": "tools.ozone.set.querySets",
"defs": {
"main": {
"type": "query",
"description": "Query available sets",
"parameters": {
"type": "params",
"properties": {
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 100,
"default": 50
},
"cursor": {
"type": "string"
},
"namePrefix": {
"type": "string"
},
"sortBy": {
"type": "string",
"enum": ["name", "createdAt", "updatedAt"],
"default": "name"
},
"sortDirection": {
"type": "string",
"default": "asc",
"enum": ["asc", "desc"],
"description": "Defaults to ascending order of name field."
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["sets"],
"properties": {
"sets": {
"type": "array",
"items": {
"type": "ref",
"ref": "tools.ozone.set.defs#setView"
}
},
"cursor": {
"type": "string"
}
}
}
}
}
}
}
24 changes: 24 additions & 0 deletions lexicons/tools/ozone/set/upsertSet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"lexicon": 1,
"id": "tools.ozone.set.upsertSet",
"defs": {
"main": {
"type": "procedure",
"description": "Create or update set metadata",
"input": {
"encoding": "application/json",
"schema": {
"type": "ref",
"ref": "tools.ozone.set.defs#set"
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "ref",
"ref": "tools.ozone.set.defs#setView"
}
}
}
}
}
Loading

0 comments on commit 22d039a

Please sign in to comment.