forked from votrongdao/FlowX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomSchemaFlows.cs
More file actions
304 lines (273 loc) · 12 KB
/
Copy pathCustomSchemaFlows.cs
File metadata and controls
304 lines (273 loc) · 12 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
using FlowX;
namespace Crm;
/// <summary>Declares an object an administrator invented.</summary>
/// <remarks>
/// <strong>One step and no projection, which is what a flow should look like when the
/// interesting part is elsewhere.</strong> What makes these five routes worth having is the
/// stance on the capability and the rules in <see cref="CustomValues"/>; the flow's job is to
/// give them a transport and a journal.
/// </remarks>
[Flow("crm.custom.object", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/objects", Idempotent = true)]
public sealed partial class DefineObjectFlow : Flow<DefineObject, ObjectDefined>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<DefineObject, ObjectDefined> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<DefineCustomObject>()
.Return(ctx => ctx.Get<ObjectDefined>());
}
}
/// <summary>Declares a field on a built-in entity or on a custom object.</summary>
[Flow("crm.custom.field", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/fields", Idempotent = true)]
public sealed partial class DefineFieldFlow : Flow<DefineField, FieldDefined>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<DefineField, FieldDefined> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<DefineCustomField>()
.Return(ctx => ctx.Get<FieldDefined>());
}
}
/// <summary>Declares a relationship between two custom objects.</summary>
[Flow("crm.custom.relationship", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/relationships", Idempotent = true)]
public sealed partial class DefineRelationshipFlow : Flow<DefineRelationship, RelationshipDefined>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<DefineRelationship, RelationshipDefined> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<DefineCustomRelationship>()
.Return(ctx => ctx.Get<RelationshipDefined>());
}
}
/// <summary>Writes a row of a custom object.</summary>
[Flow("crm.custom.record", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/records", Idempotent = true)]
public sealed partial class CreateRecordFlow : Flow<CreateRecord, RecordCreated>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<CreateRecord, RecordCreated> flow)
{
ArgumentNullException.ThrowIfNull(flow);
// Projected, not passed straight through. The scopes come off the principal the trigger
// authenticated; a `scopes` field on the request would let anybody claim any grant, which
// is the argument ADR-0046 makes about the tenant.
flow
.Step<CreateCustomRecord, WriteObjectRecord>(
ctx => new WriteObjectRecord(
ctx.Input.Target,
ctx.Input.Values,
CustomFieldPolicy.Scopes(ctx.Principal)))
.Return(ctx => ctx.Get<RecordCreated>());
}
}
/// <summary>Joins two records along a declared relationship.</summary>
[Flow("crm.custom.link", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/links", Idempotent = true)]
public sealed partial class LinkRecordsFlow : Flow<LinkRecords, RecordsLinked>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<LinkRecords, RecordsLinked> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<LinkCustomRecords>()
.Return(ctx => ctx.Get<RecordsLinked>());
}
}
/// <summary>Sets the custom values of a built-in entity.</summary>
[Flow("crm.custom.entity_fields", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/entity-fields", Idempotent = true)]
public sealed partial class SetCustomFieldsFlow : Flow<SetCustomFields, CustomFieldsSet>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<SetCustomFields, CustomFieldsSet> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<SetEntityCustomFields, WriteEntityFields>(
ctx => new WriteEntityFields(
ctx.Input.Kind,
ctx.Input.Id,
ctx.Input.Values,
CustomFieldPolicy.Scopes(ctx.Principal),
Approvers.Of(ctx.Principal)))
.Return(ctx => ctx.Get<CustomFieldsSet>());
}
}
/// <summary>Declares a rule that refuses a record.</summary>
[Flow("crm.custom.validation_rule", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/validation-rules", Idempotent = true)]
public sealed partial class DefineValidationRuleFlow
: Flow<DefineValidationRule, ValidationRuleDefined>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<DefineValidationRule, ValidationRuleDefined> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<DefineCustomValidationRule>()
.Return(ctx => ctx.Get<ValidationRuleDefined>());
}
}
/// <summary>Declares a field whose value is an aggregate over a parent's children.</summary>
[Flow("crm.custom.rollup", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/rollups", Idempotent = true)]
public sealed partial class DefineRollupFlow : Flow<DefineRollup, RollupDefined>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<DefineRollup, RollupDefined> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<DefineCustomRollup>()
.Return(ctx => ctx.Get<RollupDefined>());
}
}
/// <summary>Saves a named query over a custom object.</summary>
[Flow("crm.custom.list_view", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/list-views", Idempotent = true)]
public sealed partial class DefineListViewFlow : Flow<DefineListView, ListViewDefined>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<DefineListView, ListViewDefined> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<DefineCrmListView>()
.Return(ctx => ctx.Get<ListViewDefined>());
}
}
/// <summary>Reads records of a custom object.</summary>
/// <remarks>
/// <strong><c>Ephemeral</c>, unlike every other flow here, because it writes nothing.</strong> A
/// read journaled into <c>flow_instance</c> would put a row in the durable store for every list
/// anybody opened, and a replay of a read has nothing to make idempotent.
/// </remarks>
[Flow("crm.custom.query", Version = "1.0.0", Profile = ExecutionProfile.Ephemeral, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/queries")]
public sealed partial class QueryRecordsFlow : Flow<QueryRecords, RecordPage>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<QueryRecords, RecordPage> flow)
{
ArgumentNullException.ThrowIfNull(flow);
// Projected, so the grants come off the principal the trigger authenticated. A `scopes`
// field on the request would let anybody read anything.
flow
.Step<QueryCustomRecords, ReadObjectRecords>(
ctx => new ReadObjectRecords(ctx.Input, CustomFieldPolicy.Scopes(ctx.Principal)))
.Return(ctx => ctx.Get<RecordPage>());
}
}
/// <summary>Searches every entity this tenant has.</summary>
/// <remarks>
/// <c>Ephemeral</c> for the reason the query route is: a search writes nothing, and journaling
/// one would put a durable row behind every keystroke somebody typed into a search box.
/// </remarks>
[Flow("crm.search", Version = "1.0.0", Profile = ExecutionProfile.Ephemeral, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/search")]
public sealed partial class SearchFlow : Flow<SearchEverything, SearchResults>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<SearchEverything, SearchResults> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<SearchCrm>()
.Return(ctx => ctx.Get<SearchResults>());
}
}
/// <summary>Declares a field computed from other fields of the same record.</summary>
[Flow("crm.custom.formula", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/formulas", Idempotent = true)]
public sealed partial class DefineFormulaFlow : Flow<DefineFormula, FormulaDefined>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<DefineFormula, FormulaDefined> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<DefineCustomFormula>()
.Return(ctx => ctx.Get<FormulaDefined>());
}
}
/// <summary>Tells a client what this tenant's schema looks like.</summary>
/// <remarks>
/// <c>Ephemeral</c>, like the query and the search: it writes nothing, and journaling it would
/// put a durable row behind every screen a client opens.
/// </remarks>
[Flow("crm.custom.describe", Version = "1.0.0", Profile = ExecutionProfile.Ephemeral, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/describe")]
public sealed partial class DescribeSchemaFlow : Flow<DescribeSchema, SchemaDescription>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<DescribeSchema, SchemaDescription> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<DescribeCrmSchema, DescribeFor>(
ctx => new DescribeFor(ctx.Input, CustomFieldPolicy.Scopes(ctx.Principal)))
.Return(ctx => ctx.Get<SchemaDescription>());
}
}
/// <summary>Tells a client what changed since it last looked.</summary>
/// <remarks>
/// <c>Ephemeral</c>, like the describe and the query: a client polls this, and journaling a poll
/// would put a durable row behind every phone in the field waking up.
/// </remarks>
[Flow("crm.custom.sync", Version = "1.0.0", Profile = ExecutionProfile.Ephemeral, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/changes")]
public sealed partial class SyncChangesFlow : Flow<SyncChanges, ChangePage>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<SyncChanges, ChangePage> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<ReadRecordChanges, ReadChanges>(
ctx => new ReadChanges(ctx.Input, CustomFieldPolicy.Scopes(ctx.Principal)))
.Return(ctx => ctx.Get<ChangePage>());
}
}
/// <summary>Deletes a record, and leaves a tombstone the sync feed serves.</summary>
/// <remarks>
/// <c>Durable</c> and journalled, unlike the reads above: this is the only route in the sample
/// that destroys something a caller cannot reconstruct.
/// </remarks>
[Flow("crm.custom.record.delete", Version = "1.0.0", Profile = ExecutionProfile.Durable, Owner = "crm-platform")]
[FlowDeadline("PT15S")]
[HttpTrigger("POST", "/api/v1/crm/custom/record-deletions", Idempotent = true)]
public sealed partial class DeleteRecordFlow : Flow<DeleteRecord, RecordDeleted>
{
/// <inheritdoc />
protected override void Define(IFlowBuilder<DeleteRecord, RecordDeleted> flow)
{
ArgumentNullException.ThrowIfNull(flow);
flow
.Step<DeleteCustomRecord>()
.Return(ctx => ctx.Get<RecordDeleted>());
}
}