2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
import { coerceObject } from './utils';
|
|
|
|
|
2024-10-14 11:54:44 -07:00
|
|
|
const interactionPolicyEntrySchema = v.picklist(['public', 'followers', 'following', 'mutuals', 'mentioned', 'author', 'me']);
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-11-29 07:01:54 -08:00
|
|
|
/**
|
|
|
|
* @category Entity types
|
|
|
|
*/
|
2024-10-25 11:22:27 -07:00
|
|
|
type InteractionPolicyEntry = v.InferOutput<typeof interactionPolicyEntrySchema>;
|
|
|
|
|
2024-08-28 04:43:23 -07:00
|
|
|
const interactionPolicyRuleSchema = coerceObject({
|
2024-10-25 11:22:27 -07:00
|
|
|
always: v.fallback(v.array(interactionPolicyEntrySchema), ['public', 'me']),
|
2024-10-14 11:54:44 -07:00
|
|
|
with_approval: v.fallback(v.array(interactionPolicyEntrySchema), []),
|
2024-08-28 04:43:23 -07:00
|
|
|
});
|
|
|
|
|
2024-10-29 14:44:28 -07:00
|
|
|
/**
|
|
|
|
* @category Schemas
|
|
|
|
* @see {@link https://docs.gotosocial.org/en/latest/api/swagger/}
|
|
|
|
*/
|
2024-08-28 04:43:23 -07:00
|
|
|
const interactionPolicySchema = coerceObject({
|
|
|
|
can_favourite: interactionPolicyRuleSchema,
|
|
|
|
can_reblog: interactionPolicyRuleSchema,
|
|
|
|
can_reply: interactionPolicyRuleSchema,
|
|
|
|
});
|
|
|
|
|
2024-11-29 07:01:54 -08:00
|
|
|
/**
|
|
|
|
* @category Entity types
|
|
|
|
*/
|
2024-10-13 15:25:30 -07:00
|
|
|
type InteractionPolicy = v.InferOutput<typeof interactionPolicySchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-29 14:44:28 -07:00
|
|
|
/**
|
|
|
|
* @category Schemas
|
|
|
|
*/
|
2024-08-28 04:43:23 -07:00
|
|
|
const interactionPoliciesSchema = coerceObject({
|
|
|
|
public: interactionPolicySchema,
|
|
|
|
unlisted: interactionPolicySchema,
|
|
|
|
private: interactionPolicySchema,
|
|
|
|
direct: interactionPolicySchema,
|
|
|
|
});
|
|
|
|
|
2024-11-29 07:01:54 -08:00
|
|
|
/**
|
|
|
|
* @category Entity types
|
|
|
|
*/
|
2024-10-13 15:25:30 -07:00
|
|
|
type InteractionPolicies = v.InferOutput<typeof interactionPoliciesSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-25 11:22:27 -07:00
|
|
|
export { interactionPolicySchema, interactionPoliciesSchema, type InteractionPolicyEntry, type InteractionPolicy, type InteractionPolicies };
|
2024-08-28 04:43:23 -07:00
|
|
|
|