Add query mechanisms

This commit is contained in:
abhay-raizada 2024-05-27 18:50:21 +05:30
parent 9694a3e37d
commit 694658ca46

30
101.md
View File

@ -29,12 +29,11 @@ Event `30168` describes a form as a parametrized replaceable event, with `field`
The different tags used to detail the form are described as: The different tags used to detail the form are described as:
| Tags | Description | | Tags | Description |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| d | The unique identifier of a form, for a user | | d | The unique identifier of a form, for a user |
| name | A text serving as the name of the form | | name | A text serving as the name of the form |
| settings | An optional global config for the form. | | settings | An optional global config for the form. |
| field | Contains the following values<table><tr><th>index</th><th>name</th><th>description</th></tr><tbody><tr><td>1</td><td>FieldId</td><td>an id that uniqely identifies a field in the forn</td></tr><tr><td>2</td><td>input-type</td><td>A field that describes the type of value that can be expected as a response to this field, values can be: `text`, `option` or `label`</td></tr><tr><td>3</td><td>label</td><td>A label for the field</td></tr><tr><td>4</td><td>options</td> <td>Only used for input-type option, is a Json stringified array of option Tags. | | field | Contains the following values<table><tr><th>index</th><th>name</th><th>description</th></tr><tbody><tr><td>1</td><td>FieldId</td><td>an id that uniqely identifies a field in the forn</td></tr><tr><td>2</td><td>input-type</td><td>A field that describes the type of value that can be expected as a response to this field, values can be: `text`, `option` or `label`</td></tr><tr><td>3</td><td>label</td><td>A label for the field</td></tr><tr><td>4</td><td>options</td> <td>Only used for input-type option, is a Json stringified array of option Tags.</tr><tr></td><td> - </td> <td> Option Tags </td> <td>Option Tags are defined as: [`<OptionId`>, <`label`>, `<optional config>`], optionId can be any alphanumeric string </td> </tr><tr><td>5</td><td>fieldSettings</td><td>An optional JSON stringified object that contains settings specific to the field, for example `renderElement`, a setting which indicates what UI element to render to the client </td></tr> |
| Option Tags | Option Tags are defined as: [`<OptionId`>, <`label`>, `<optional config>`], optionId can be any alphanumeric string </td> </tr><tr><td>5</td><td>fieldSettings</td><td>An optional JSON stringified object that contains settings specific to the field, for example `renderElement`, a setting which indicates what UI element to render to the client </td></tr> |
</tbody></table> </tbody></table>
@ -71,7 +70,8 @@ for option fields, the response is the id of the option selected. In case of mul
"kind": 30169, "kind": 30169,
"content": "", "content": "",
"tags": [ "tags": [
["a", "30168:<pubkey of the author>:<form identifier>"], ["d", "<pubkey of the form author>:<formId>"],
["a", "30168:<pubkey of the form author>:<formId>"],
[ [
"response", "response",
"<FieldId>", "<FieldId>",
@ -145,3 +145,25 @@ let encyptedKey = nip44.v2.encrypt(bytesToHex(signingKey), conversationKey);
The rest of the mechanism remains same as in public forms editable by a group except that the The rest of the mechanism remains same as in public forms editable by a group except that the
form fields should be placed in the `.content` key, encrypted by a `view-key`, which is shared in the 3rd index of the key tag for the viewers. form fields should be placed in the `.content` key, encrypted by a `view-key`, which is shared in the 3rd index of the key tag for the viewers.
## Querying Form Template & Responses
form template maybe filtered using the form author's pubkey and the d-tag as follows
```js
const filter = {
kinds: [30168],
authors: [formIdPubkey],
"#d": [formIdentifier],
};
```
Responses can be queried using the a-tag, and an optional authors tag depending the visibility of the form, for example
```js
const filter: Filter = {
kinds: [30169],
"#a": [`30168:${pubKey}:${formId}`],
};
if (allowedPubkeys) filter.authors = allowedPubkeys;
```