KETTLE-49: Architecture for configuring writable DataSources is confused

Metadata

Source
KETTLE-49
Type
Bug
Priority
Major
Status
Resolved
Resolution
Fixed
Assignee
Antranig Basman
Reporter
Antranig Basman
Created
2016-11-11T10:25:08.997-0500
Updated
2020-11-02T08:20:48.103-0500
Versions
N/A
Fixed Versions
  1. 2.0.0
Component
N/A

Description

We currently have two mostly unrelated schemes for contributing "writable" versions of DataSource grades into components.

The first, historical scheme consumes a boolean option named "writable" and uses this to manually compute a gradeName based on the option named readOnlyGrade:

kettle.dataSource.getWritableGrade = function (that, writable, readOnlyGrade) {
    if (!readOnlyGrade) {
        fluid.fail("Cannot evaluate writable grade without readOnlyGrade option");
    }
    if (writable) {
        return fluid.model.composeSegments(readOnlyGrade, "writable");
    }
};

The second scheme, currently only used for the mixin grade "kettle.dataSource.CouchDB" uses the IoC grade linkage system to consume a generalised "kettle.dataSource.writable" grade and output the concrete writable grade: http://docs.fluidproject.org/infusion/development/IoCAPI.html#fluid-makegradelinkage-linkagename-inputnames-outputnames-

fluid.makeGradeLinkage("kettle.dataSource.CouchDB.linkage", ["kettle.dataSource.writable", "kettle.dataSource.CouchDB"], "kettle.dataSource.CouchDB.writable");

This confusion has confused implementors of new DataSource grades in the current PouchDB work on the GPII - https://github.com/GPII/universal/pull/464#pullrequestreview-3041008 - a crucial commit is https://github.com/GPII/universal/pull/464/commits/71594c2b444a7350f3cf6561d22cb301978ba290 .

We should sort out this confusion when we refactor DataSources - presumably in favour of the second, linkage-based system, as the TODO comment at https://github.com/fluid-project/kettle/blob/master/lib/dataSource-core.js#L187 suggests.

Comments

  • Antranig Basman commented 2020-11-02T08:20:17.658-0500

    In the end we have ended up with a system based on a writable flag plus ContextAwareness definitions at each point where the hierarchy branches. E.g. in core DataSource we have

    fluid.defaults("fluid.dataSource", {
            gradeNames: ["fluid.component", "fluid.contextAware"],
            contextAwareness: {
                writable: {
                    checks: {
                        writableValue: {
                            contextValue: "{fluid.dataSource}.options.writable",
                            gradeNames: "{fluid.dataSource}.options.writableGrade"
                        }
                    }
                }
            },
    

    whereas in kettle.dataSource.CouchDB we have

    fluid.defaults("kettle.dataSource.CouchDB", {
        // Link on to the existing writable: true flag maintained by a core fluid.dataSource
        contextAwareness: {
            writableCouchDB: {
                checks: {
                    writableCouchDB: {
                        contextValue: "{fluid.dataSource}.options.writable",
                        // Note that it would be preferable for gradeNames to form a hash as in FLUID-6439 so that we could
                        // override it selectively rather than to duplicate the entire contextAwareness definition as here
                        gradeNames: "kettle.dataSource.CouchDB.writable"
                    }
                }
            }
        },