Skip to main content

Convert a flow file to Code using a template

Project description

CHANGES.md

2026-01-19

Fixed - Prevent invalid datetime import in schema.ts generation

  • Fixed templates/liwe3-cloudflare/gen_schema.py to filter out built-in types from custom type imports
    • Added BUILTIN_TYPES set containing all primitive types: str, string, text, int, num, number, float, double, real, bool, boolean, date, datetime, json, obj, object, file, upload
    • When a field type is incorrectly marked as custom but is actually a built-in type, it is now skipped
    • Prevents invalid imports like import type { datetime } from './types' which don't exist in SQLite
    • The datetime type in SQLite is handled as integer with .$type<Date>() annotation, not as a separate import

2026-01-18

Enhanced - Made created/updated timestamp fields optional in DB schema generation

  • Modified lib/json_to_drizzle.py and lib/json_to_sql.py to make created and updated timestamp fields optional instead of automatically added
    • Removed automatic addition of created and updated fields to all database types
    • These fields are now only included when explicitly defined by the user in the flow JSON
    • When user defines these fields, they still receive proper auto-update rules:
      • Drizzle ORM: .default( sqlCURRENT_TIMESTAMP )
      • SQL: DEFAULT CURRENT_TIMESTAMP (and ON UPDATE CURRENT_TIMESTAMP for updated field in MySQL/MariaDB)
    • This gives users more control over which tables have timestamp tracking
    • Backward compatible: existing flow files with created/updated fields will continue to work with auto-update behavior

2026-01-16

Fixed - liwe3-cloudflare-svelte index.ts f2c block formatting

  • Fixed truncated newlines in f2c_start/f2c_end blocks in generated index.ts
    • The f2c_end marker was appearing on the same line as the last line of custom content
    • Root cause: extracted snippets have trailing whitespace stripped by template_base.py
    • Solution: ensure snippet content ends with a newline before writing the f2c_end marker
    • Updated templates/liwe3-cloudflare-svelte/gen_index.py to handle this properly

2025-10-28

Enhanced - Added LiWESysParams to Generated Methods

  • Added optional sys parameter of type LiWESysParams to all generated method functions in liwe3-cloudflare template

    • Updated templates/liwe3-cloudflare/texts.py to import LiWESysParams from @backend/liwe3/core in both METHOD_UTILS_FILE and METHOD_FILE_START
    • Modified METHOD_FUNCTION_START to include sys?: LiWESysParams as the third optional parameter
    • This parameter allows passing system-level configuration and context to all generated methods
    • Example signature: export const pet = async ( app: LiWEApp, params: PetParams, sys?: LiWESysParams ): Promise<LiWEResponse<PetResult>>
  • Updated templates/liwe3-nodejs-ng/texts.py to import LiWESysParams in methods file

    • Added LiWESysParams to the imports in METHODS_FILE_START
    • Modified both EP_START and FUNCTION_START templates to include sys?: LiWESysParams parameter
    • Maintains consistency across all backend templates

2025-10-27

Enhanced - Cloudflare Template Utils File

  • Added f2c code preservation markers to utils.ts file generation in the liwe3-cloudflare template
    • Users can now add custom imports, utilities, and helper functions that will be preserved between regenerations
    • Follows the same pattern as method files with /* f2c_start utils */ and /* f2c_end utils */ markers
    • Updated templates/liwe3-cloudflare/texts.py to include the snippet placeholder
    • Updated templates/liwe3-cloudflare/gen_methods.py to use snippet extraction mechanism
    • Default placeholder comment: "Add custom imports or utilities here"

2025-10-04

Added - Cloudflare Workers Template

  • Created new liwe3-cloudflare template for generating Cloudflare Workers compatible code
    • Based on liwe3-nodejs-ng template architecture
    • Uses Hono framework for HTTP routing
    • Implements Zod schema validation
    • Supports Drizzle ORM for database operations
    • Generates complete module structure with tests configuration

Template Structure

  • templates/liwe3-cloudflare/template.py - Main template class extending TemplateBase
  • templates/liwe3-cloudflare/texts.py - Template strings for all generated files
  • templates/liwe3-cloudflare/gen_index.py - Generates module index with Hono endpoints
  • templates/liwe3-cloudflare/gen_perms.py - Generates permissions definitions
  • templates/liwe3-cloudflare/gen_methods.py - Generates individual method files with Zod validation
  • templates/liwe3-cloudflare/gen_schema.py - Generates Drizzle ORM table schemas
  • templates/liwe3-cloudflare/gen_sql.py - Generates SQLite SQL schema files
  • templates/liwe3-cloudflare/gen_config.py - Generates configuration files

Generated Files

  • src/index.ts - Module initialization with Hono endpoint registration

    • Different templates for GET, POST, PUT, PATCH, DELETE methods
    • Error handling for body parsing
    • Query parameter handling for GET requests
  • src/perms.ts - Module permissions array

    • SystemPermission type definitions
    • JSDoc documentation
    • Proper quote escaping in descriptions
  • src/methods/ - Individual method files

    • Zod schema definitions with validation
    • Type inference for parameters and results
    • Full JSDoc documentation
    • f2c preservation blocks for custom code
    • Parameter extraction and validation
  • src/methods/index.ts - Re-exports all methods and types

  • src/methods/utils.ts - Common imports (LiWE core, Drizzle ORM, Zod)

  • src/methods.ts - Backward compatibility wrapper

  • src/schema.ts - Drizzle ORM table definitions

    • Generated only for types with coll_table field
    • Includes indexes (unique, multi, array, fulltext)
    • JSDoc comments for tables and fields
    • Type inference exports
  • sql/{module_name}.sql - SQLite schema file

    • Table definitions with field comments
    • Index creation statements
    • Generated only for types with coll_table field
  • package.json - Module package configuration

    • Workspace dependencies
    • TypeScript and Vitest setup
    • Build and test scripts
  • tsconfig.json - TypeScript compiler configuration

    • ES2022 target with ESNext modules
    • Bundler module resolution
    • Declaration file generation
  • vitest.config.ts - Vitest testing framework configuration

    • Path aliases for core imports
    • Test file patterns
    • Coverage reporting

Key Features

  • Zod Integration: Uses lib/json_to_zod.py for schema generation

    • Custom type resolution from module flow definitions
    • Array and optional field support
    • String length validation (min/max)
  • Drizzle Integration: Uses lib/json_to_drizzle.py for ORM schemas

    • Field index flags converted to string format
    • Handles missing attributes gracefully
    • Type inference support
  • SQL Generation: Uses lib/json_to_sql.py for schema files

    • SQLite dialect support
    • Inline field documentation
    • Index creation
  • File Naming: Endpoint paths converted to file names

    • /user/adduser-add.ts
    • Path parts joined with dashes
  • Code Preservation: f2c_start/f2c_end blocks for custom code retention

Added - Core Libraries

  • Created lib/json_to_drizzle.py module to convert LiWE Flow JSON type definitions to Drizzle ORM schemas

    • Maps flow field types to native Drizzle types (boolean, date, timestamp, text, integer, etc.)
    • Generates JSDoc comments for tables, fields, and indexes
    • Auto-pluralizes table names to lowercase
    • Supports all index types (unique, multi, array, fulltext)
    • Includes type inference exports
  • Created tools/json2drizzle.py CLI tool to convert JSON files to Drizzle schemas

    • Reads JSON type definition from file
    • Outputs formatted Drizzle schema to stdout
    • Includes error handling and help documentation
  • Added comprehensive test suite in tests/test_json_to_drizzle.py

    • 34 unit tests covering all functionality
    • Tests helper functions, main conversion, and edge cases
    • Uses data/user-type.json as test fixture
  • Created CLAUDE.md with comprehensive project documentation for Claude Code instances

    • Core architecture overview
    • Template system documentation
    • Common commands and workflow
    • Flow file format specification
    • Key implementation details and conventions

Changed

  • Type mappings now use native Drizzle types instead of SQLite-specific conversions
    • booleanboolean() (was integer())
    • datedate() (was text())
    • datetimetimestamp() (was text())
    • This allows easier database switching and lets Drizzle handle type conversion

Fixed

  • Quote escaping in permission descriptions (e.g., "user's tag")
  • Custom type resolution in Zod schemas now uses actual type/enum names
  • Field attribute handling for size instead of max_length
  • Index flag conversion from boolean attributes to string format

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flow2code-0.3.1.tar.gz (267.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flow2code-0.3.1-py3-none-any.whl (430.5 kB view details)

Uploaded Python 3

File details

Details for the file flow2code-0.3.1.tar.gz.

File metadata

  • Download URL: flow2code-0.3.1.tar.gz
  • Upload date:
  • Size: 267.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for flow2code-0.3.1.tar.gz
Algorithm Hash digest
SHA256 5979b14383fe13657b5c321c1c9d1656528690b5babf51a2f5c87120127e605c
MD5 8c3720bbb38502a01a87aa7895271c74
BLAKE2b-256 d313d339e61d49bc07bc863f100ecb087a132a6fe679e689334e8ef76fd57ed4

See more details on using hashes here.

File details

Details for the file flow2code-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: flow2code-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 430.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for flow2code-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 72627d0305fd65ec14158eee81188e2f65bea3d60a0e322e60809970a9cbb1de
MD5 c2a79fe0020cd821b46d1818262b0ae8
BLAKE2b-256 698b49a0c077dc5d3f84b217016fbc79ba5dbe746470d88f2ee9da4e6e796492

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page