|
| 1 | +import * as Schema from "effect/Schema" |
| 2 | + |
| 3 | +import { |
| 4 | + activityStreamsJsonLdContext, |
| 5 | + forgeFedJsonLdContext, |
| 6 | + securityJsonLdContext |
| 7 | +} from "./contracts.js" |
| 8 | + |
| 9 | +export type JsonPrimitive = boolean | number | string | null |
| 10 | +export type JsonValue = JsonPrimitive | JsonObject | ReadonlyArray<JsonValue> |
| 11 | +export type JsonObject = Readonly<{ [key: string]: JsonValue }> |
| 12 | + |
| 13 | +export const JsonValueSchema: Schema.Schema<JsonValue> = Schema.suspend(() => |
| 14 | + Schema.Union( |
| 15 | + Schema.Null, |
| 16 | + Schema.Boolean, |
| 17 | + Schema.Number, |
| 18 | + Schema.String, |
| 19 | + Schema.Array(JsonValueSchema), |
| 20 | + Schema.Record({ key: Schema.String, value: JsonValueSchema }) |
| 21 | + ) |
| 22 | +) |
| 23 | + |
| 24 | +const OptionalString = Schema.optional(Schema.String) |
| 25 | +const OptionalBoolean = Schema.optional(Schema.Boolean) |
| 26 | +const JsonObjectSchema = Schema.Record({ key: Schema.String, value: JsonValueSchema }) |
| 27 | +const JsonLdContextEntrySchema = Schema.Union(Schema.String, JsonObjectSchema) |
| 28 | + |
| 29 | +export const ActivityForgeFedJsonLdContextSchema = Schema.Tuple( |
| 30 | + Schema.Literal(activityStreamsJsonLdContext), |
| 31 | + Schema.Literal(forgeFedJsonLdContext) |
| 32 | +) |
| 33 | + |
| 34 | +export const ActorJsonLdContextSchema = Schema.Tuple( |
| 35 | + Schema.Literal(activityStreamsJsonLdContext), |
| 36 | + Schema.Literal(securityJsonLdContext), |
| 37 | + Schema.Literal(forgeFedJsonLdContext) |
| 38 | +) |
| 39 | + |
| 40 | +export const JsonLdContextSchema = Schema.Union( |
| 41 | + Schema.String, |
| 42 | + JsonObjectSchema, |
| 43 | + Schema.Array(JsonLdContextEntrySchema) |
| 44 | +) |
| 45 | + |
| 46 | +export const ForgeFedTicketSourceSchema = Schema.Struct({ |
| 47 | + content: OptionalString, |
| 48 | + mediaType: OptionalString |
| 49 | +}) |
| 50 | + |
| 51 | +export const ForgeFedTicketSchema = Schema.Struct({ |
| 52 | + id: Schema.String, |
| 53 | + attributedTo: Schema.String, |
| 54 | + summary: Schema.String, |
| 55 | + content: Schema.String, |
| 56 | + mediaType: OptionalString, |
| 57 | + source: Schema.optional(Schema.Union(Schema.String, ForgeFedTicketSourceSchema)), |
| 58 | + published: OptionalString, |
| 59 | + updated: OptionalString, |
| 60 | + url: OptionalString, |
| 61 | + context: OptionalString, |
| 62 | + workType: OptionalString, |
| 63 | + attachment: Schema.optional(Schema.Array(Schema.Unknown)), |
| 64 | + raw: Schema.optional(Schema.Unknown) |
| 65 | +}) |
| 66 | + |
| 67 | +export const ActivityPubPublicKeySchema = Schema.Struct({ |
| 68 | + id: Schema.String, |
| 69 | + owner: Schema.String, |
| 70 | + publicKeyPem: Schema.String |
| 71 | +}) |
| 72 | + |
| 73 | +const ActivityPubEndpointsSchema = Schema.Struct({ |
| 74 | + sharedInbox: OptionalString |
| 75 | +}) |
| 76 | + |
| 77 | +const ActivityPubInteractionPolicySchema = Schema.Record({ |
| 78 | + key: Schema.String, |
| 79 | + value: JsonValueSchema |
| 80 | +}) |
| 81 | + |
| 82 | +export const ActivityPubPersonSchema = Schema.Struct({ |
| 83 | + "@context": JsonLdContextSchema, |
| 84 | + type: Schema.Literal("Person"), |
| 85 | + id: Schema.String, |
| 86 | + name: Schema.String, |
| 87 | + preferredUsername: Schema.String, |
| 88 | + summary: Schema.String, |
| 89 | + inbox: Schema.String, |
| 90 | + outbox: Schema.String, |
| 91 | + followers: Schema.String, |
| 92 | + following: Schema.String, |
| 93 | + liked: OptionalString, |
| 94 | + publicKey: Schema.optional(ActivityPubPublicKeySchema), |
| 95 | + endpoints: Schema.optional(ActivityPubEndpointsSchema), |
| 96 | + webfinger: OptionalString, |
| 97 | + featured: OptionalString, |
| 98 | + featuredTags: OptionalString, |
| 99 | + url: OptionalString, |
| 100 | + manuallyApprovesFollowers: OptionalBoolean, |
| 101 | + discoverable: OptionalBoolean, |
| 102 | + indexable: OptionalBoolean, |
| 103 | + published: OptionalString, |
| 104 | + memorial: OptionalBoolean, |
| 105 | + showFeatured: OptionalBoolean, |
| 106 | + showMedia: OptionalBoolean, |
| 107 | + showRepliesInMedia: OptionalBoolean, |
| 108 | + interactionPolicy: Schema.optional(ActivityPubInteractionPolicySchema), |
| 109 | + featuredCollections: OptionalString, |
| 110 | + tag: Schema.optional(Schema.Array(JsonValueSchema)), |
| 111 | + attachment: Schema.optional(Schema.Array(JsonValueSchema)) |
| 112 | +}) |
| 113 | + |
| 114 | +export const ActivityPubFollowActivitySchema = Schema.Struct({ |
| 115 | + "@context": ActivityForgeFedJsonLdContextSchema, |
| 116 | + id: Schema.String, |
| 117 | + type: Schema.Literal("Follow"), |
| 118 | + actor: Schema.String, |
| 119 | + object: Schema.String, |
| 120 | + to: Schema.optional(Schema.Array(Schema.String)), |
| 121 | + capability: OptionalString |
| 122 | +}) |
| 123 | + |
| 124 | +export const ActivityPubOrderedCollectionSchema = Schema.Struct({ |
| 125 | + "@context": JsonLdContextSchema, |
| 126 | + type: Schema.Literal("OrderedCollection"), |
| 127 | + id: Schema.String, |
| 128 | + totalItems: Schema.Number, |
| 129 | + first: OptionalString, |
| 130 | + last: OptionalString, |
| 131 | + current: OptionalString, |
| 132 | + orderedItems: Schema.optionalWith(Schema.Array(Schema.Unknown), { default: () => [] }) |
| 133 | +}) |
| 134 | + |
| 135 | +export const ActivityPubOrderedCollectionPageSchema = Schema.Struct({ |
| 136 | + "@context": JsonLdContextSchema, |
| 137 | + type: Schema.Literal("OrderedCollectionPage"), |
| 138 | + id: Schema.String, |
| 139 | + totalItems: Schema.Number, |
| 140 | + partOf: Schema.String, |
| 141 | + next: OptionalString, |
| 142 | + prev: OptionalString, |
| 143 | + orderedItems: Schema.Array(Schema.Unknown) |
| 144 | +}) |
0 commit comments