Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1import {
2 isNonEmptyString,
3 type NonEmptyString,
4} from '../utils/typescript-types.js';
5
6/**
7 * Scylla requires all primary key columns to be non-null when propagating rows
8 * from a table into a materialized view, so instead of allowing
9 * thread_identifier and parent_identifier to be null, we coerce their interal
10 * properties to the empty string on insert. The NilItemIdentifier is important
11 * because most of the Coop system assumes that if an ItemIdentifier exists,
12 * the fields are valid, which eventually should be enforced by typing
13 * ItemIdentifiers with NonEmptyString fields instead of `string`.
14 *
15 * Also note the slight format differences between these two types and
16 * the Coop MonoRepo `ItemIdentifier` type, where the type identifier is
17 * represented as `typeId`. In CQL/Scylla all column and field names end up
18 * lowercase, so we stay consistent with that here by using snake casing
19 * for the type_id field.
20 *
21 **/
22export type ScyllaRealItemIdentifier = {
23 id: NonEmptyString;
24 type_id: NonEmptyString;
25};
26
27export type ScyllaNilItemIdentifier = typeof ScyllaNilItemIdentifier;
28export const ScyllaNilItemIdentifier = { id: '', type_id: '' } as const;
29
30export type ScyllaItemIdentifier =
31 | ScyllaRealItemIdentifier
32 | ScyllaNilItemIdentifier;
33
34export function isRealItemIdentifier(
35 it: ScyllaItemIdentifier,
36): it is ScyllaRealItemIdentifier {
37 return isNonEmptyString(it.id) && isNonEmptyString(it.type_id);
38}