Dynamic Specification
Dynamic Specification
By defining spec function, you can dynamically generate the collection specification. This is useful when the collection's capabilities depend on API features, user permissions, or configuration parameters.
Implementation
module.exports = async ({ spec, credentials, parameters }) => {
  // Check API capabilities
  const capabilities = await makeApiRequest({
    method: "GET",
    path: "/api/capabilities",
    credentials,
  })
  // Modify spec based on capabilities
  if (capabilities.supportsSearch) {
    spec.search = {
      parametersSchema: {
        type: "object",
        properties: {
          query: { type: "string" },
        },
      },
    }
  }
  // Add dynamic filter fields
  if (parameters.enableAdvancedFilters) {
    spec.list.filterFields = ["email", "firstName", "lastName", "createdAt"]
  }
  return spec
}Input
| Property | Type | Description | 
|---|---|---|
spec | object | The base collection specification | 
credentials | object | Connection credentials | 
parameters | object | Collection parameters | 
Return Value
Returns the modified collection specification.
Example
// Base spec:
{
  "name": "Contacts",
  "fieldsSchema": { /* ... */ },
  "list": {
    "filterFields": ["email"]
  },
  "create": {},
  "update": {}
}
// spec method returns:
{
  "name": "Contacts",
  "fieldsSchema": { /* ... */ },
  "list": {
    "filterFields": ["email", "firstName", "lastName", "createdAt"]
  },
  "create": {},
  "update": {},
  "search": {
    "parametersSchema": {
      "type": "object",
      "properties": {
        "query": { "type": "string" }
      }
    }
  }
}Updated 10 days ago
