Current version : 0.21.0
Made in 🇫🇷 ◌ GitHubNPM

💡 Sept. Tip => cardinality leads to all directions

Because optionality or mandatoriness should not be bools.

During this month of September 2025, we'll highlight various and interesting aspects of libmodulor.

In libmodulor, the optionality and mandatoriness of a use case input field is defined via cardinality.

The default cardinality is { max: 1, min: 1 }. It means that the field is mandatory. Since it's the default value, we don't have to define it for each input field.

const CreateOperationUCD: UCDef<CreateOperationInput, CreateOperationOPI0> = {
    // ...
    io: {
        i: {
            fields: {
                // By default, title is mandatory
                title: {
                    type: new TFreeTextShort(),
                }
            }
        }
    }
    // ...
}

What if we want to add an optional field ? Like so :

// ...
description: {
    cardinality: {
        min: 0,
    },
    type: new TFreeTextLong(),
}
// ...

I see you from there telling yourself that it could be a boolean. Well. What if we want to add an optional field that can take at most 3 values ? Like so :

// ...
picture: {
    cardinality: {
        max: 3,
        min: 0,
    },
    type: new TFile({
        type: {
            allowed: ['image/jpeg', 'image/jpg', 'image/png'],
        },
    }),
},
// ...

And now, what if we want exactly 5 values ? Like so :

// ...
tag: {
    cardinality: {
        max: 3,
        min: 3,
    },
    type: new TSlug(),
},
// ...

As we can see, we can express basically anything with cardinality.

Voilà c'est tout.