Liking cljdoc? Tell your friends :D

wagoe.scaffolder.core.generators

Pure functions for generating file content from templates.

Each generator function takes a template context and returns file content as a string. All functions are pure and deterministic.

Pure functions for generating file content from templates.

Each generator function takes a template context and returns
file content as a string. All functions are pure and deterministic.
raw docstring

add-field-to-schemaclj

(add-field-to-schema source entity field)

Add field to the entity and request schemas in source.

Returns {:status :updated :content <new source> :schemas [changed] :unreachable [names]} when at least one schema changed, or {:status :skipped :reason :already-present|:unrecognised-shape :unreachable [names]} when none did.

:unreachable names the target schemas the field could not be placed in. It is what tells the caller that manual work remains, and it is reported on a successful edit too — two of three schemas updated is still a schema set that does not agree with itself.

All three targets are edited because that is what the tool has always told users to do: the instruction comment it used to print said to add the field to the entity schema and then to the Create and Update request schemas as well.

Each target is tracked separately. Deciding :already-present by searching the whole file let one schema answer for the others — with the field in the entity schema and a hand-restructured CreateXRequest, this reported that nothing remained to be done while both request schemas still lacked it. That is the unsynchronised Malli set of AGENTS.md pitfall 6, reported as success.

Add `field` to the entity and request schemas in `source`.

Returns {:status :updated :content <new source> :schemas [changed]
         :unreachable [names]} when at least one schema changed, or
{:status :skipped :reason :already-present|:unrecognised-shape
         :unreachable [names]} when none did.

`:unreachable` names the target schemas the field could not be placed in. It
is what tells the caller that manual work remains, and it is reported on a
successful edit too — two of three schemas updated is still a schema set that
does not agree with itself.

All three targets are edited because that is what the tool has always told
users to do: the instruction comment it used to print said to add the field
to the entity schema and then to the Create and Update request schemas as
well.

Each target is tracked separately. Deciding `:already-present` by searching
the whole file let one schema answer for the others — with the field in the
entity schema and a hand-restructured `CreateXRequest`, this reported that
nothing remained to be done while both request schemas still lacked it. That
is the unsynchronised Malli set of AGENTS.md pitfall 6, reported as success.
sourceraw docstring

generate-adapter-fileclj

(generate-adapter-file module-name port-name adapter-name methods & [base-ns])

Generate a complete adapter implementation file.

Args: module-name - Module name (e.g., "cache") port-name - Port protocol name (e.g., "ICache") adapter-name - Adapter name (e.g., "redis") methods - Vector of method specs [{:name "get-value" :args ["key"]}] base-ns - Optional base namespace (default "wagoe")

Returns: String content for adapter.clj file

Pure: true

Generate a complete adapter implementation file.

Args:
  module-name - Module name (e.g., "cache")
  port-name - Port protocol name (e.g., "ICache")
  adapter-name - Adapter name (e.g., "redis")
  methods - Vector of method specs [{:name "get-value" :args ["key"]}]
  base-ns - Optional base namespace (default "wagoe")

Returns:
  String content for adapter.clj file

Pure: true
sourceraw docstring

generate-add-field-migrationclj

(generate-add-field-migration _module-name entity-name field migration-number)

Generate ALTER TABLE migration for adding a field.

Args: module-name - Module name entity-name - Entity name (PascalCase) field - Field definition map {:name :type :required :unique} migration-number - Migration sequence number (e.g., "006")

Returns: String content for migration SQL

Pure: true

Generate ALTER TABLE migration for adding a field.

Args:
  module-name - Module name
  entity-name - Entity name (PascalCase)
  field - Field definition map {:name :type :required :unique}
  migration-number - Migration sequence number (e.g., "006")

Returns:
  String content for migration SQL

Pure: true
sourceraw docstring

generate-add-field-schema-commentclj

(generate-add-field-schema-comment module-name entity-name field)

Generate schema addition comment/instructions for adding a field.

Args: module-name - Module name entity-name - Entity name field - Field definition map

Returns: String with instructions for manual schema update

Pure: true

Generate schema addition comment/instructions for adding a field.

Args:
  module-name - Module name
  entity-name - Entity name
  field - Field definition map

Returns:
  String with instructions for manual schema update

Pure: true
sourceraw docstring

generate-core-fileclj

(generate-core-file ctx)

Generate core/{entity}.clj file content.

Args: ctx - Template context map

Returns: String content for core/{entity}.clj

Pure: true

Generate core/{entity}.clj file content.

Args:
  ctx - Template context map

Returns:
  String content for core/{entity}.clj

Pure: true
sourceraw docstring

generate-core-test-fileclj

(generate-core-test-file ctx)

Generate test core file content.

Args: ctx - Template context map

Returns: String content for core test file

Pure: true

Generate test core file content.

Args:
  ctx - Template context map
  
Returns:
  String content for core test file
  
Pure: true
sourceraw docstring

generate-endpoint-definitionclj

(generate-endpoint-definition module-name path method handler-name)

Generate a single endpoint definition for adding to http.clj.

Args: module-name - Module name path - Route path (e.g., "/invoices/:id/send") method - HTTP method keyword (e.g., :post) handler-name - Handler function name (e.g., "send-invoice")

Returns: String content for endpoint definition (normalized format)

Pure: true

Generate a single endpoint definition for adding to http.clj.

Args:
  module-name - Module name
  path - Route path (e.g., "/invoices/:id/send")
  method - HTTP method keyword (e.g., :post)
  handler-name - Handler function name (e.g., "send-invoice")

Returns:
  String content for endpoint definition (normalized format)

Pure: true
sourceraw docstring

generate-field-schemaclj

(generate-field-schema field-ctx)
(generate-field-schema field-ctx force-optional?)

Generate Malli schema for a single field.

Args: field-ctx - Field context map

Returns: String representation of Malli schema

Pure: true

Generate Malli schema for a single field.

Args:
  field-ctx - Field context map

Returns:
  String representation of Malli schema

Pure: true
sourceraw docstring

generate-http-fileclj

(generate-http-file ctx)

Generate shell/http.clj file content.

Args: ctx - Template context map

Returns: String content for http.clj file

Pure: true

Generate shell/http.clj file content.

Args:
  ctx - Template context map
  
Returns:
  String content for http.clj file
  
Pure: true
sourceraw docstring

generate-migration-down-fileclj

(generate-migration-down-file ctx)

Generate the rollback SQL matching generate-migration-file.

migratus pairs <id>-<name>.up.sql with <id>-<name>.down.sql; without the down file a migration cannot be rolled back. Dropping the table also removes its index, so the index needs no separate statement.

Pure: true

Generate the rollback SQL matching `generate-migration-file`.

migratus pairs `<id>-<name>.up.sql` with `<id>-<name>.down.sql`; without the
down file a migration cannot be rolled back. Dropping the table also removes
its index, so the index needs no separate statement.

Pure: true
sourceraw docstring

generate-migration-fieldclj

(generate-migration-field field-ctx)

Generate SQL for a single field.

Args: field-ctx - Field context map

Returns: SQL field definition string

Pure: true

Generate SQL for a single field.

Args:
  field-ctx - Field context map

Returns:
  SQL field definition string

Pure: true
sourceraw docstring

generate-migration-fileclj

(generate-migration-file ctx migration-number)

Generate migration SQL file content.

Args: ctx - Template context map migration-number - Migration sequence number (e.g., "005")

Returns: String content for migration SQL

Pure: true

Generate migration SQL file content.

Args:
  ctx - Template context map
  migration-number - Migration sequence number (e.g., "005")

Returns:
  String content for migration SQL

Pure: true
sourceraw docstring

generate-persistence-fileclj

(generate-persistence-file ctx)

Generate shell/persistence.clj file content.

Args: ctx - Template context map

Returns: String content for persistence.clj file

Pure: true

Generate shell/persistence.clj file content.

Args:
  ctx - Template context map
  
Returns:
  String content for persistence.clj file
  
Pure: true
sourceraw docstring

generate-persistence-test-fileclj

(generate-persistence-test-file ctx)

Generate test persistence file content.

Args: ctx - Template context map

Returns: String content for persistence test file

Pure: true

Generate test persistence file content.

Args:
  ctx - Template context map
  
Returns:
  String content for persistence test file
  
Pure: true
sourceraw docstring

generate-ports-fileclj

(generate-ports-file ctx)

Generate ports.clj file content.

Args: ctx - Template context map

Returns: String content for ports.clj

Pure: true

Generate ports.clj file content.

Args:
  ctx - Template context map

Returns:
  String content for ports.clj

Pure: true
sourceraw docstring

generate-schema-fileclj

(generate-schema-file ctx)

Generate schema.clj file content.

Args: ctx - Template context map

Returns: String content for schema.clj

Pure: true

Generate schema.clj file content.

Args:
  ctx - Template context map

Returns:
  String content for schema.clj

Pure: true
sourceraw docstring

generate-service-fileclj

(generate-service-file ctx)

Generate shell/service.clj file content.

Args: ctx - Template context map

Returns: String content for service.clj file

Pure: true

Generate shell/service.clj file content.

Args:
  ctx - Template context map
  
Returns:
  String content for service.clj file
  
Pure: true
sourceraw docstring

generate-service-test-fileclj

(generate-service-test-file ctx)

Generate test service file content.

Args: ctx - Template context map

Returns: String content for service test file

Pure: true

Generate test service file content.

Args:
  ctx - Template context map
  
Returns:
  String content for service test file
  
Pure: true
sourceraw docstring

generate-ui-fileclj

(generate-ui-file ctx)

Generate core/ui.clj file content.

Args: ctx - Template context map

Returns: String content for ui.clj file

Pure: true

Generate core/ui.clj file content.

Args:
  ctx - Template context map
  
Returns:
  String content for ui.clj file
  
Pure: true
sourceraw docstring

generate-web-handlers-fileclj

(generate-web-handlers-file ctx)

Generate shell/web_handlers.clj file content.

Args: ctx - Template context map

Returns: String content for web_handlers.clj file

Pure: true

Generate shell/web_handlers.clj file content.

Args:
  ctx - Template context map
  
Returns:
  String content for web_handlers.clj file
  
Pure: true
sourceraw docstring

insert-schema-entryclj

(insert-schema-entry source schema-name entry)

Add entry to the Malli map in (def schema-name …) within source.

Returns one of:

{:status :inserted :content <new source>} {:status :present :entry <the entry already there>} {:status :unrecognised} a shape this cannot place the field in safely

The last two are kept apart rather than collapsed into one falsey value: the caller has to distinguish nothing-to-do from could-not-do-it. Reporting the second as the first is how the request schemas ended up without the field while the output said the work was finished.

:present carries the entry that is already there, because its shape matters — a required entry in an update request is not nothing-to-do.

:unrecognised covers a hand-edited file, a renamed schema, or a def whose value is not a literal [:map …]. Refusing rather than guessing is deliberate: a skip the user can see beats a mangled schema file they discover later.

Everything outside the inserted entry round-trips byte for byte, including the trailing newline — rewrite-clj preserves whitespace and comments, so the diff is the one line added.

Add `entry` to the Malli map in `(def schema-name …)` within `source`.

Returns one of:

  {:status :inserted :content <new source>}
  {:status :present :entry <the entry already there>}
  {:status :unrecognised}  a shape this cannot place the field in safely

The last two are kept apart rather than collapsed into one falsey value: the
caller has to distinguish nothing-to-do from could-not-do-it. Reporting the
second as the first is how the request schemas ended up without the field
while the output said the work was finished.

`:present` carries the entry that is already there, because its shape
matters — a required entry in an update request is not nothing-to-do.

:unrecognised covers a hand-edited file, a renamed schema, or a `def` whose
value is not a literal `[:map …]`. Refusing rather than guessing is
deliberate: a skip the user can see beats a mangled schema file they discover
later.

Everything outside the inserted entry round-trips byte for byte, including
the trailing newline — rewrite-clj preserves whitespace and comments, so the
diff is the one line added.
sourceraw docstring

schema-field-entryclj

(schema-field-entry field)
(schema-field-entry field force-optional?)

The Malli entry line for field, without indentation.

Required fields are plain; optional ones carry {:optional true}, matching what module generation emits for the same field definition.

force-optional? produces the optional form regardless. Update request schemas take that one: an update is a partial, so a required entry there means every existing caller doing a partial update has to start sending the new field or fail validation. See libs/scaffolder/AGENTS.md, and generate-field-schema, which applies the same rule at module generation.

The Malli entry line for `field`, without indentation.

Required fields are plain; optional ones carry `{:optional true}`, matching
what module generation emits for the same field definition.

`force-optional?` produces the optional form regardless. Update request
schemas take that one: an update is a partial, so a required entry there
means every existing caller doing a partial update has to start sending the
new field or fail validation. See `libs/scaffolder/AGENTS.md`, and
`generate-field-schema`, which applies the same rule at module generation.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close