add-model
Add a freezed + unfreezed model pair to a layrz_models sub-library module. Use when creating new data models from backend struct definitions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add a freezed + unfreezed model pair to a layrz_models sub-library module. Use when creating new data models from backend struct definitions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Add GraphQL API caller methods (fetch, fetchAll, save, delete/expire) to an existing model pair in a layrz_models sub-library module, using the connector.query/connector.mutate API.
Add GraphQL API caller methods (fetch, fetchAll, save, delete/expire) to an existing model pair in a layrz_models sub-library module.
| name | add-model |
| description | Add a freezed + unfreezed model pair to a layrz_models sub-library module. Use when creating new data models from backend struct definitions. |
| argument-hint | <module> <ModelName> |
Create a new @freezed (read) model and its @unfreezed (input/mutation) variant inside an
existing sub-library module.
/add-model <module> <ModelName>
Where <module> is the target sub-library directory name (e.g. locator, assets, ats) and
<ModelName> is the PascalCase class name (e.g. LocatorBoundary).
Use the EnterPlanMode tool immediately before doing any work. Present the full plan to the user
and wait for approval via ExitPlanMode before writing any files or running any commands.
Ask the user to paste or describe the backend definition (Python ObjectType, GraphQL schema, JSON sample, etc.). Parse field names, types, and nesting from that definition.
| Backend type | Dart type | Converter annotation |
|---|---|---|
String, ID | String | — |
Float | double | — |
Int | int | — |
Boolean | bool | — |
| timestamp / epoch field | DateTime | @TimestampConverter() (required) or @TimestampOrNullConverter() (nullable) |
| date string field | DateTime | @DateConverter() (required) or @DateOrNullConverter() (nullable) |
| color string | Color | @ColorConverter() / @ColorOrNullConverter() |
| duration (seconds) | Duration | @DurationConverter() / @DurationOrNullConverter() |
| icon string | LayrzIcon | @IconConverter() / @IconOrNullConverter() |
| time-of-day string | TimeOfDay | @TimeOfDayConverter() / @TimeOfDayOrNullConverter() |
| regex string | RegExp | @RegExpConverter() / @RegExpOrNullConverter() |
| byte list | Uint8List | @ByteListConverter() / @ByteListOrNullConverter() |
List<X> | List<X> | — (nullable unless specified required) |
| Nested object | Ask the user | — |
All converters live in package:layrz_models/src/converters/converters.dart.
When a field references another model type:
User from package:layrz_models/src/users/users.dart).part of in layrz_models.dart), suggest
the user run /to-library on it first.package:layrz_models/layrz_models.dart from a sub-library — always use
the direct sub-library path: package:layrz_models/src/<module>/<module>.dart.If the backend field name differs from Dart camelCase (e.g. topleft → topLeft), add
@JsonKey(name: 'backend_name') to the field.
lib/src/<module>/src/<model_snake_case>.dart.@freezed (read) modelpart of '../<module>.dart';
/// [ModelName] description
@freezed
abstract class ModelName with _$ModelName {
const factory ModelName({
/// [fieldName] description of the field
Type? fieldName,
}) = _ModelName;
factory ModelName.fromJson(Map<String, dynamic> json) => _$ModelNameFromJson(json);
}
Rules:
const factory.const ModelName._(); only if custom methods or getters are needed./// [name] description dartdoc comment.@unfreezed (input) modelPlace it in the same file, after the @freezed model:
/// [ModelNameInput] is the input variant of [ModelName]
@unfreezed
abstract class ModelNameInput with _$ModelNameInput {
factory ModelNameInput({
/// [fieldName] description of the field
Type? fieldName,
}) = _ModelNameInput;
factory ModelNameInput.fromJson(Map<String, dynamic> json) => _$ModelNameInputFromJson(json);
}
Rules:
const on factory (unfreezed classes are mutable).List fields use @Default([]) instead of being nullable.bool fields use @Default(false) (or @Default(true) if specified by the user).LocatorBoundaryPointInput, not LocatorBoundaryPoint).@JsonKey annotations as the @freezed variant.Add a part directive in lib/src/<module>/<module>.dart:
part 'src/<model_snake_case>.dart';
If the new model references types from other sub-libraries, add imports to
lib/src/<module>/<module>.dart:
import 'package:layrz_models/src/<other_module>/<other_module>.dart';
Never import package:layrz_models/layrz_models.dart from a sub-library unless there is
absolutely no other option. If the needed model is not a sub-library yet, suggest the user run
/to-library on it first.
make freezed
List the created and modified files and whether the build succeeded.
If the model needs GraphQL API caller methods (fetch, fetchAll, save, delete/expire),
suggest the user run:
/add-api-caller <module> <ModelName>
.freezed.dart or .g.dart files./// [name] description.@freezed model comes first in the file, followed by the @unfreezed input variant.