Skip to content

Commit 33a8e9c

Browse files
committed
Update docs
1 parent 1114cea commit 33a8e9c

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

chasm/engine.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,17 @@ func engineFromContext(
359359
return e
360360
}
361361

362+
// ListExecutions lists the executions of a CHASM archetype given an initial query.
363+
// The query string can specify any combination of CHASM, custom, and predefined/system search attributes.
364+
// The generic parameter C is the CHASM component type used for executions and search attribute filtering.
365+
// The generic parameter M is the type of the memo payload to be unmarshaled from the execution.
366+
// PageSize is required, must be greater than 0.
367+
// NextPageToken is optional, set on subsequent requests to continue listing the next page of executions.
368+
// Note: For CHASM executions, TemporalNamespaceDivision is the predefined search attribute
369+
// that is used to identify the archetype of the execution.
370+
// If the query string does not specify TemporalNamespaceDivision, the archetype C of the request will be used to filter the executions.
371+
// If the initial query already specifies TemporalNamespaceDivision, the archetype C of the request will
372+
// only be used to get the registered SearchAttributes.
362373
func ListExecutions[C Component, M proto.Message](
363374
ctx context.Context,
364375
request *ListExecutionsRequest,
@@ -400,6 +411,14 @@ func ListExecutions[C Component, M proto.Message](
400411
}, nil
401412
}
402413

414+
// CountExecutions counts the executions of a CHASM archetype given an initial query.
415+
// The generic parameter C is the CHASM component type used for executions and search attribute filtering.
416+
// The query string can specify any combination of CHASM, custom, and predefined/system search attributes.
417+
// Note: For CHASM executions, TemporalNamespaceDivision is the predefined search attribute
418+
// that is used to identify the archetype of the execution.
419+
// If the query string does not specify TemporalNamespaceDivision, the archetype C of the request will be used to count the executions.
420+
// If the initial query already specifies TemporalNamespaceDivision, the archetype C of the request will
421+
// only be used to get the registered SearchAttributes.
403422
func CountExecutions[C Component](
404423
ctx context.Context,
405424
request *CountExecutionsRequest,

chasm/registry_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,49 @@ func (s *RegistryTestSuite) TestRegistry_RegisterComponents_Error() {
218218
require.Contains(t, err.Error(), "must be struct or pointer to struct")
219219
})
220220

221+
s.T().Run("duplicate search attribute alias panics", func(t *testing.T) {
222+
require.PanicsWithValue(t,
223+
"registrable component validation error: search attribute alias \"MyAlias\" is already defined",
224+
func() {
225+
chasm.NewRegistrableComponent[*chasm.MockComponent](
226+
"Component1",
227+
chasm.WithSearchAttributes(
228+
chasm.NewSearchAttributeBool("MyAlias", chasm.SearchAttributeFieldBool01),
229+
chasm.NewSearchAttributeInt("MyAlias", chasm.SearchAttributeFieldInt01),
230+
),
231+
)
232+
},
233+
)
234+
})
235+
236+
s.T().Run("duplicate search attribute field panics", func(t *testing.T) {
237+
require.PanicsWithValue(t,
238+
"registrable component validation error: search attribute field \"TemporalBool01\" is already defined",
239+
func() {
240+
chasm.NewRegistrableComponent[*chasm.MockComponent](
241+
"Component1",
242+
chasm.WithSearchAttributes(
243+
chasm.NewSearchAttributeBool("Alias1", chasm.SearchAttributeFieldBool01),
244+
chasm.NewSearchAttributeBool("Alias2", chasm.SearchAttributeFieldBool01),
245+
),
246+
)
247+
},
248+
)
249+
})
250+
251+
s.T().Run("valid search attributes do not panic", func(t *testing.T) {
252+
require.NotPanics(t, func() {
253+
chasm.NewRegistrableComponent[*chasm.MockComponent](
254+
"Component1",
255+
chasm.WithSearchAttributes(
256+
chasm.NewSearchAttributeBool("Completed", chasm.SearchAttributeFieldBool01),
257+
chasm.NewSearchAttributeInt("Count", chasm.SearchAttributeFieldInt01),
258+
chasm.NewSearchAttributeKeyword("Status", chasm.SearchAttributeFieldKeyword01),
259+
),
260+
)
261+
})
262+
})
263+
221264
}
222265

223266
func (s *RegistryTestSuite) TestRegistry_RegisterTasks_Error() {

chasm/search_attribute.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ func NewSearchAttributesMap(values map[string]VisibilityValue) SearchAttributesM
448448
// The return type T is inferred from the SearchAttribute's type parameter.
449449
// For example, SearchAttriteBool will return a bool value.
450450
// If the value is not found, the zero value for the type T is returned and the second return value is false.
451+
// Before casting the VisibilityValue to the target type, the value is checked to ensure it is of the correct type.
452+
// If the value is found but the type does not match, the zero value for the type T is returned and the second return value is false.
451453
func Get[T any](m SearchAttributesMap, sa typedSearchAttribute[T]) (val T, ok bool) {
452454
var zero T
453455
if m.values == nil {

0 commit comments

Comments
 (0)