Skip to content

feat: Add optional tableFactory parameter to SchemaManager constructor #21

@wagnert

Description

@wagnert

Problem

The SchemaManager constructor (line 64-78 in src/utils/SchemaManager.ts) currently creates its DynamicTableFactory internally with only 2 parameters:

this.tableFactory = new DynamicTableFactory(clientFactory, schema);

This means consumers cannot pass a pre-configured DynamicTableFactory with custom policies (e.g., WriteConversionPolicyInterface, UnknownFieldPolicyInterface).

In the service_portfolio_mcp project, we need a DynamicTableFactory with a LocaleWriteConversionPolicy for proper date/number formatting. Currently this requires an unsafe property override workaround:

(schemaManager as unknown as { tableFactory: DynamicTableFactory }).tableFactory = tableFactory;

This violates the Open/Closed Principle (OCP).

Proposed Solution

Add an optional 3rd parameter to the SchemaManager constructor:

constructor(
  clientFactory: AppSheetClientFactoryInterface,
  schema: SchemaConfig,
  tableFactory?: DynamicTableFactoryInterface  // NEW: optional
) {
  // ...validate schema...
  this.tableFactory = tableFactory ?? new DynamicTableFactory(clientFactory, schema);
}
  • If tableFactory is provided: use it directly
  • If NOT provided: create internally as before (backward compatible)

Acceptance Criteria

  • Optional 3rd parameter tableFactory?: DynamicTableFactoryInterface added to constructor
  • When provided, the injected factory is used instead of creating a new one
  • When NOT provided, behavior is identical to current version (backward compatible)
  • Unit tests for both paths (with and without factory)
  • Minor version bump (semver: new optional parameter = non-breaking feature)

Context

  • Related MCP Server ticket: SOSO-448
  • Current library version: v3.4.0
  • DynamicTableFactory constructor already accepts writeConversionPolicy as 4th parameter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions