summaryrefslogtreecommitdiff
path: root/vendor/github.com/superseriousbusiness/activity/streams/gen_resolver_utils.go
blob: 17427c0b972b2e47644a662161392dda7e762200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// Code generated by astool. DO NOT EDIT.

package streams

import (
	"context"
	"errors"
	vocab "github.com/superseriousbusiness/activity/streams/vocab"
)

// ErrNoCallbackMatch indicates a Resolver could not match the ActivityStreams value to a callback function.
var ErrNoCallbackMatch error = errors.New("activity stream did not match the callback function")

// ErrUnhandledType indicates that an ActivityStreams value has a type that is not handled by the code that has been generated.
var ErrUnhandledType error = errors.New("activity stream did not match any known types")

// ErrPredicateUnmatched indicates that a predicate is accepting a type or interface that does not match an ActivityStreams value's type or interface.
var ErrPredicateUnmatched error = errors.New("activity stream did not match type demanded by predicate")

// errCannotTypeAssertType indicates that the 'type' property returned by the ActivityStreams value cannot be type-asserted to its interface form.
var errCannotTypeAssertType error = errors.New("activity stream type cannot be asserted to its interface")

// ActivityStreamsInterface represents any ActivityStream value code-generated by
// go-fed or compatible with the generated interfaces.
type ActivityStreamsInterface interface {
	// GetTypeName returns the ActiivtyStreams value's type.
	GetTypeName() string
	// VocabularyURI returns the vocabulary's URI as a string.
	VocabularyURI() string
}

// Resolver represents any TypeResolver.
type Resolver interface {
	// Resolve will attempt to resolve an untyped ActivityStreams value into a
	// Go concrete type.
	Resolve(ctx context.Context, o ActivityStreamsInterface) error
}

// IsUnmatchedErr is true when the error indicates that a Resolver was
// unsuccessful due to the ActivityStreams value not matching its callbacks or
// predicates.
func IsUnmatchedErr(err error) bool {
	return err == ErrPredicateUnmatched || err == ErrUnhandledType || err == ErrNoCallbackMatch
}

// ToType attempts to resolve the generic JSON map into a Type.
func ToType(c context.Context, m map[string]interface{}) (t vocab.Type, err error) {
	var r *JSONResolver
	r, err = NewJSONResolver(func(ctx context.Context, i vocab.ActivityStreamsAccept) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsActivity) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsAdd) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsAnnounce) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsApplication) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsArrive) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsArticle) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsAudio) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsBlock) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ForgeFedBranch) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsCollection) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsCollectionPage) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ForgeFedCommit) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsCreate) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsDelete) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsDislike) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsDocument) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.TootEmoji) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsEvent) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsFlag) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsFollow) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsGroup) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.TootIdentityProof) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsIgnore) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsImage) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsIntransitiveActivity) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsInvite) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsJoin) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsLeave) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsLike) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsLink) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsListen) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsMention) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsMove) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsNote) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsObject) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsOffer) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsOrderedCollection) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsOrderedCollectionPage) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsOrganization) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsPage) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsPerson) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsPlace) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsProfile) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.W3IDSecurityV1PublicKey) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ForgeFedPush) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsQuestion) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsRead) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsReject) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsRelationship) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsRemove) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ForgeFedRepository) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsService) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsTentativeAccept) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsTentativeReject) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ForgeFedTicket) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ForgeFedTicketDependency) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsTombstone) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsTravel) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsUndo) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsUpdate) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsVideo) error {
		t = i
		return nil
	}, func(ctx context.Context, i vocab.ActivityStreamsView) error {
		t = i
		return nil
	})
	if err != nil {
		return
	}
	err = r.Resolve(c, m)
	return
}