property_keys.py

clew/property_keys.py

Every JS/TS property key a symbol defines or assigns, with its holder (F1-mm; 2.0.0).

ensure_property_keys_table

None clew.property_keys.ensure_property_keys_table(sqlite3.Connection conn)

Create the property_keys table.

clew/property_keys.py:150

Show on the map →

Called by import_property_keys, schema_db

Calls none

Source · 21 lines
def ensure_property_keys_table(conn: sqlite3.Connection) -> None:
    """Created unconditionally, so a tree with no JS/TS yields an EMPTY table, not an absent one.

    @brief Create the table.
    @return None.
    """
    conn.executescript(
        """
        CREATE TABLE IF NOT EXISTS property_keys (
          path_rowid INTEGER NOT NULL REFERENCES path(rowid),
          key TEXT NOT NULL,
          line INTEGER NOT NULL,
          holder TEXT NOT NULL,
          kind TEXT NOT NULL
        );
        CREATE INDEX IF NOT EXISTS idx_property_keys_key ON property_keys(key);
        CREATE INDEX IF NOT EXISTS idx_property_keys_path ON property_keys(path_rowid, line);
        """
    )

Activity · 1 steps
lines 156–168conn.executescript( """ CREATE TABLE IF NOT EXISTS property_keys ( path_rowid INTEGER NOT NULL REFERENCES path(rowid), key TEXT NOT NULL, line INTEGER NOT NULL, holder TEXT NOT NULL, kind TEXT NOT NULL ); CREATE INDEX IF NOT EXISTS idx_property_keys_key ON property_keys(key); CREATE INDEX IF NOT EXISTS idx_property_keys_path ON property_keys(path_rowid, line); """ )

Requirements

REQ-DDB-INDEX-011

harvest

Any clew.property_keys._PropertyKeyHarvester.harvest(self, Any tree, bytes src_bytes)

Harvest one file's key sites.

clew/property_keys.py:113

Show on the map →

Called by none

Calls _holder_name, _site, is_js_tree

Source · 23 lines
    def harvest(self, tree: Any, src_bytes: bytes) -> Any:
        """A WALK THAT CARRIES THE HOLDER: each node is visited with the nearest enclosing holder's
        name, so a key nested three literals deep inside `DEFAULT_CONFIG` is still held by it.

        @brief Walk the tree.
        @return Rows.
        """
        from .jsast import is_js_tree

        if not is_js_tree(tree):
            return []
        found: list[list[Any]] = []
        stack: list[tuple[Any, str]] = [(tree.root_node, "")]
        while stack:
            node, holder = stack.pop()
            here = _holder_name(node) or holder
            site = _site(node)
            if site is not None and holder:
                found.append([site[0], node.start_point[0] + 1, holder, site[1]])
            stack.extend((child, here) for child in node.children)
        return sorted(found, key=lambda r: (r[1], r[0]))

Activity · 13 steps
lines 120–120from .jsast import is_js_treelines 122–122◇ if not is_js_tree(tree)lines 123–123return []lines 124–124found: list[list[Any]] = []lines 125–125stack: list[tuple[Any, str]] = [(tree.root_node, "")]lines 126–126◇ while stacklines 127–127node, holder = stack.pop()lines 128–128here = _holder_name(node) or holderlines 129–129site = _site(node)lines 130–130◇ if site is not None and holderlines 131–131found.append([site[0], node.start_point[0] + 1, holder, site[1]])lines 132–132stack.extend((child, here) for child in node.children)lines 133–133return sorted(found, key=lambda r: (r[1], r[0]))

Requirements

REQ-DDB-INDEX-011

import_property_keys

int clew.property_keys.import_property_keys(Path db_path, Path repo_root, IndexCache|None cache=None)

Record every indexed JS/TS file's property-key sites.

clew/property_keys.py:178

Source · 20 lines
def import_property_keys(db_path: Path, repo_root: Path, cache: IndexCache | None = None) -> int:
    """@brief Fill property_keys. @return Row count."""
    conn = sqlite3.connect(str(db_path))
    try:
        ensure_property_keys_table(conn)
        conn.execute("DELETE FROM property_keys")
        rows = [
            (src, key, line, holder, kind)
            for src, payload in run_harvest(conn, repo_root, property_key_harvester(), cache)
            for key, line, holder, kind in payload or ()
        ]
        conn.executemany(
            "INSERT INTO property_keys (path_rowid, key, line, holder, kind) VALUES (?, ?, ?, ?, ?)",
            rows,
        )
        conn.commit()
    finally:
        conn.close()
    logger.info("property keys: %d site(s)", len(rows))
    return len(rows)

1 more lines, not shown

Activity · 9 steps
lines 180–180conn = sqlite3.connect(str(db_path))lines 181–181trylines 182–182ensure_property_keys_table(conn)lines 183–183conn.execute("DELETE FROM property_keys")lines 184–188rows = [ (src, key, line, holder, kind) for src, payload in run_harvest(conn, repo_root, property_key_harvester(), cache) for key, line, holder, kind in payload or () ]lines 189–192conn.executemany( "INSERT INTO property_keys (path_rowid, key, line, holder, kind) VALUES (?, ?, ?, ?, ?)", rows, )lines 193–193conn.commit()lines 196–196logger.info("property keys: %d site(s)", len(rows))lines 197–197return len(rows)

Requirements

REQ-DDB-INDEX-011

property_key_harvester

Harvester clew.property_keys.property_key_harvester()

The property-key stage's harvester.

clew/property_keys.py:140

Source · 5 lines
def property_key_harvester() -> Harvester:
    """ONE CONSTRUCTION SITE, shared with the plan's parse pass. @brief Build it. @return It."""
    return _PropertyKeyHarvester()

Activity · 1 steps
lines 142–142return _PropertyKeyHarvester()

Requirements

REQ-DDB-INDEX-011