Configuration (OData)
The typegen tool supports OData-based type generation using the fmodata config type. This is configured using the proofkit-typegen-config.jsonc file at the root of your project.
The @proofkit/fmodata package is still in beta. Some of these options may change.
The config key can also be an array of configs, which is useful if you need to connect to multiple databases, or with different settings for different sets of tables.
{
"$schema": "https://proofkit.dev/typegen-config-schema.json",
"config": {
"type": "fmodata",
// ... your OData config here
},
}Config options
Prop
Type
type (required)
Must be set to "fmodata" to use OData-based type generation.
configName (optional)
An optional name for this configuration. Useful when using multiple configs to identify which config is being used.
path (default: "schema")
The path to the directory where the generated files will be saved.
reduceMetadata (optional)
If set to true, reduced OData annotations will be requested from the server to reduce payload size. This will prevent comments, entity ids, and other properties from being generated.
This can also be set per-table in the tables array to override the top-level setting for specific tables.
clearOldFiles (default: false)
If set to false, the path will not be cleared before the new files are written. Only the client and generated directories are cleared to allow for potential overrides to be kept.
This is different from the Data API config, which defaults to true. For OData configs, we preserve existing files by default to allow for customizations.
alwaysOverrideFieldNames (default: true)
If set to true (default), field names will always be updated to match metadata, even when matching by entity ID. If set to false, existing field names are preserved when matching by entity ID.
This can also be set per-table in the tables array to override the top-level setting for specific tables.
envNames (optional)
If set, will use the specified environment variable names for your OData connection.
Only use the names of your environment variables, not the values for security reasons.
The envNames object supports:
server: The environment variable name for the OData server URLdb: The environment variable name for the database nameauth: An object with either:apiKey: The environment variable name for the API key, orusernameandpassword: The environment variable names for username and password
Table options
The tables array in the config is where you define the tables (entity sets) that you want to generate types for. You must define at least one table in the config.
Prop
Type
tableName (required)
The entity set name (table occurrence name) to generate. This table will be included in metadata download and type generation. Must match exactly the name of an entity set in your OData service.
variableName (optional)
Override the generated TypeScript variable name. The original entity set name is still used for the OData path, but you can use a different name in your TypeScript code.
For example, if your entity set is named "Customers_Table" but you want to use Customers in your code:
{
"tableName": "Customers_Table",
"variableName": "Customers"
}reduceMetadata (optional)
If undefined, the top-level setting will be used. If set to true or false, it will override the top-level reduceMetadata setting for this specific table.
alwaysOverrideFieldNames (optional)
If undefined, the top-level setting will be used. If set to true or false, it will override the top-level alwaysOverrideFieldNames setting for this specific table.
Field options
Within each table's fields array, you can specify field-level overrides.
Prop
Type
fieldName (required)
The field name this override applies to. Must match exactly the name of a field in the table's metadata.
exclude (optional)
If set to true, this field will be excluded from generation entirely. Useful for fields you don't need in your TypeScript types.
typeOverride (optional)
Override the inferred field type from metadata. The available options are:
"text": Treats the field as a text field"number": Treats the field as a number field"boolean": Treats the field as a boolean (validated withz.coerce.boolean())"date": Treats the field as a date field"timestamp": Treats the field as a timestamp field"container": Treats the field as a container field
The typegen tool will attempt to infer the correct field type from the OData metadata. Use typeOverride only when you need to override the inferred type.
Example configuration
Here's a complete example of an OData configuration:
{
"$schema": "https://proofkit.dev/typegen-config-schema.json",
"config": {
"type": "fmodata",
"configName": "Production OData",
"path": "schema/odata",
"reduceMetadata": true,
"clearOldFiles": false,
"alwaysOverrideFieldNames": true,
"envNames": {
"server": "ODATA_SERVER_URL",
"db": "ODATA_DATABASE_NAME",
"auth": {
"apiKey": "ODATA_API_KEY"
}
},
"tables": [
{
"tableName": "Customers",
"variableName": "Customers",
"fields": [
{
"fieldName": "InternalID",
"exclude": true
},
{
"fieldName": "Status",
"typeOverride": "boolean"
}
]
},
{
"tableName": "Orders",
"reduceMetadata": false,
"fields": [
{
"fieldName": "OrderDate",
"typeOverride": "date"
}
]
}
]
}
}