synthra 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +4 -0
  3. data/.rubocop.yml +40 -0
  4. data/.yardopts +18 -0
  5. data/ACCESS_DOCS.md +116 -0
  6. data/ADVANCED_FEATURES_SUMMARY.md +245 -0
  7. data/CHANGELOG.md +498 -0
  8. data/CODE_OF_CONDUCT.md +122 -0
  9. data/CONTRIBUTING.md +307 -0
  10. data/DOCUMENTATION.md +204 -0
  11. data/DOCUMENTATION_GUIDE.md +194 -0
  12. data/LICENSE +22 -0
  13. data/README.md +1458 -0
  14. data/Rakefile +128 -0
  15. data/benchmark/README.md +591 -0
  16. data/benchmark/batch_generation.rb +63 -0
  17. data/benchmark/engine_comparison.rb +295 -0
  18. data/benchmark/single_record.rb +108 -0
  19. data/benchmark/streaming.rb +74 -0
  20. data/docs/ACTIVERECORD_INFERENCE.md +524 -0
  21. data/docs/API_SERVER.md +278 -0
  22. data/docs/CONFIG_FILE.md +315 -0
  23. data/docs/DATA_CONTRACTS.md +312 -0
  24. data/docs/ENHANCED_REPL.md +304 -0
  25. data/docs/FACTORY_BOT.md +271 -0
  26. data/docs/GITHUB_ACTION.md +420 -0
  27. data/docs/GRAPHQL_EXPORT.md +303 -0
  28. data/docs/GRAPHQL_FEDERATION.md +651 -0
  29. data/docs/HOW_TO_GENERATE_DOCS.md +252 -0
  30. data/docs/LSP.md +189 -0
  31. data/docs/MIGRATION_GENERATOR.md +547 -0
  32. data/docs/MOCK_SERVER.md +280 -0
  33. data/docs/NATIVE_ENGINE.md +298 -0
  34. data/docs/OPENAPI_EXPORT.md +252 -0
  35. data/docs/PERFORMANCE_MODE.md +228 -0
  36. data/docs/PERSONAS.md +547 -0
  37. data/docs/PROPERTY_TESTING.md +284 -0
  38. data/docs/PROTOBUF_EXPORT.md +276 -0
  39. data/docs/QUALITY_METRICS.md +555 -0
  40. data/docs/QUICK_REFERENCE.md +88 -0
  41. data/docs/RAILS_ENGINE.md +404 -0
  42. data/docs/RAILS_INTEGRATION.md +454 -0
  43. data/docs/README.md +175 -0
  44. data/docs/REPL_QUICK_REFERENCE.md +149 -0
  45. data/docs/RUST_INTEGRATION_GUIDE.md +1376 -0
  46. data/docs/SCENARIOS.md +576 -0
  47. data/docs/SECURITY_TESTING.md +318 -0
  48. data/docs/SNAPSHOT_TESTING.md +308 -0
  49. data/docs/STRING_TEXT_TYPES_REFERENCE.md +512 -0
  50. data/docs/TERRAFORM_EXPORT.md +447 -0
  51. data/docs/TIME_TRAVEL.md +507 -0
  52. data/docs/USAGE_GUIDE.md +980 -0
  53. data/docs/WEBHOOK_SIMULATOR.md +579 -0
  54. data/docs/advanced_features.md +183 -0
  55. data/docs/api_reference.md +153 -0
  56. data/docs/behaviors.md +138 -0
  57. data/docs/best_practices.md +191 -0
  58. data/docs/dsl_reference.md +172 -0
  59. data/docs/examples.md +162 -0
  60. data/docs/generation_modes.md +125 -0
  61. data/docs/getting_started.md +92 -0
  62. data/docs/index.html +177 -0
  63. data/docs/strategic/CLOUD_REGISTRY_ARCHITECTURE.md +268 -0
  64. data/docs/strategic/SIMD_OPTIMIZATION_STRATEGY.md +153 -0
  65. data/docs/troubleshooting.md +215 -0
  66. data/docs/type_reference.md +224 -0
  67. data/examples/hostile_mode_demo.rb +64 -0
  68. data/exe/synthra +6 -0
  69. data/ext/synthra_native/Cargo.lock +972 -0
  70. data/ext/synthra_native/Cargo.toml +46 -0
  71. data/ext/synthra_native/extconf.rb +41 -0
  72. data/ext/synthra_native/src/generator.rs +397 -0
  73. data/ext/synthra_native/src/lib.rs +229 -0
  74. data/ext/synthra_native/src/types.rs +1485 -0
  75. data/lib/generators/synthra/install_generator.rb +86 -0
  76. data/lib/generators/synthra/templates/api_response.dsl +15 -0
  77. data/lib/generators/synthra/templates/fake_data.rake +116 -0
  78. data/lib/generators/synthra/templates/synthra.yml +31 -0
  79. data/lib/generators/synthra/templates/synthra_support.rb +19 -0
  80. data/lib/generators/synthra/templates/user.dsl +11 -0
  81. data/lib/synthra/activerecord_inference.rb +394 -0
  82. data/lib/synthra/api.rb +381 -0
  83. data/lib/synthra/api_server.rb +718 -0
  84. data/lib/synthra/behaviors/applicator.rb +165 -0
  85. data/lib/synthra/behaviors/base.rb +155 -0
  86. data/lib/synthra/behaviors/close_connection.rb +60 -0
  87. data/lib/synthra/behaviors/deprecated.rb +100 -0
  88. data/lib/synthra/behaviors/failure.rb +69 -0
  89. data/lib/synthra/behaviors/latency.rb +103 -0
  90. data/lib/synthra/behaviors/partial_data.rb +83 -0
  91. data/lib/synthra/behaviors/randomize_order.rb +74 -0
  92. data/lib/synthra/behaviors/registry.rb +238 -0
  93. data/lib/synthra/behaviors/simulate_error.rb +79 -0
  94. data/lib/synthra/cli/commands/base.rb +105 -0
  95. data/lib/synthra/cli/commands/diff.rb +227 -0
  96. data/lib/synthra/cli/commands/docs.rb +67 -0
  97. data/lib/synthra/cli/commands/export.rb +150 -0
  98. data/lib/synthra/cli/commands/generate.rb +72 -0
  99. data/lib/synthra/cli/commands/import.rb +80 -0
  100. data/lib/synthra/cli/commands/lint.rb +53 -0
  101. data/lib/synthra/cli/commands/live.rb +57 -0
  102. data/lib/synthra/cli/commands/seed.rb +99 -0
  103. data/lib/synthra/cli/commands/validate.rb +28 -0
  104. data/lib/synthra/cli.rb +2471 -0
  105. data/lib/synthra/config_file.rb +129 -0
  106. data/lib/synthra/configuration.rb +281 -0
  107. data/lib/synthra/contracts_registry.rb +408 -0
  108. data/lib/synthra/database_seeder.rb +268 -0
  109. data/lib/synthra/deterministic_ids.rb +218 -0
  110. data/lib/synthra/documentation_generator.rb +414 -0
  111. data/lib/synthra/engine.rb +251 -0
  112. data/lib/synthra/errors.rb +1169 -0
  113. data/lib/synthra/export/base.rb +85 -0
  114. data/lib/synthra/export/csv.rb +101 -0
  115. data/lib/synthra/export/graphql.rb +266 -0
  116. data/lib/synthra/export/graphql_federation.rb +377 -0
  117. data/lib/synthra/export/graphviz.rb +258 -0
  118. data/lib/synthra/export/javascript.rb +327 -0
  119. data/lib/synthra/export/json_data.rb +61 -0
  120. data/lib/synthra/export/json_schema.rb +290 -0
  121. data/lib/synthra/export/openapi.rb +514 -0
  122. data/lib/synthra/export/protobuf.rb +483 -0
  123. data/lib/synthra/export/python.rb +560 -0
  124. data/lib/synthra/export/sql.rb +381 -0
  125. data/lib/synthra/export/sql_insert.rb +152 -0
  126. data/lib/synthra/export/terraform.rb +501 -0
  127. data/lib/synthra/export/type_mapping.rb +389 -0
  128. data/lib/synthra/export/typescript.rb +300 -0
  129. data/lib/synthra/export/xml_data.rb +104 -0
  130. data/lib/synthra/export/yaml_data.rb +56 -0
  131. data/lib/synthra/export.rb +404 -0
  132. data/lib/synthra/factory_bot_integration.rb +157 -0
  133. data/lib/synthra/field.rb +440 -0
  134. data/lib/synthra/functions/registry.rb +104 -0
  135. data/lib/synthra/generator/context.rb +372 -0
  136. data/lib/synthra/generator/engine.rb +336 -0
  137. data/lib/synthra/generator/faker_adapter.rb +425 -0
  138. data/lib/synthra/generator/modes.rb +444 -0
  139. data/lib/synthra/generator/resolver.rb +256 -0
  140. data/lib/synthra/generator/rng.rb +273 -0
  141. data/lib/synthra/generator/streamer.rb +63 -0
  142. data/lib/synthra/generator/uniqueness.rb +118 -0
  143. data/lib/synthra/initializer.rb +97 -0
  144. data/lib/synthra/limits.rb +279 -0
  145. data/lib/synthra/live_preview.rb +518 -0
  146. data/lib/synthra/loader_config.rb +78 -0
  147. data/lib/synthra/lsp/server.rb +689 -0
  148. data/lib/synthra/migration_generator.rb +301 -0
  149. data/lib/synthra/mixin.rb +174 -0
  150. data/lib/synthra/mock_server.rb +458 -0
  151. data/lib/synthra/native_engine.rb +304 -0
  152. data/lib/synthra/openapi_importer.rb +228 -0
  153. data/lib/synthra/output/json_formatter.rb +40 -0
  154. data/lib/synthra/output/ndjson_formatter.rb +55 -0
  155. data/lib/synthra/parser/ast.rb +1287 -0
  156. data/lib/synthra/parser/lexer.rb +1152 -0
  157. data/lib/synthra/parser/parser.rb +1664 -0
  158. data/lib/synthra/parser/tokens.rb +461 -0
  159. data/lib/synthra/performance_mode.rb +364 -0
  160. data/lib/synthra/personas.rb +397 -0
  161. data/lib/synthra/property_testing.rb +172 -0
  162. data/lib/synthra/quality_metrics.rb +405 -0
  163. data/lib/synthra/rails_test_helper.rb +248 -0
  164. data/lib/synthra/registry.rb +533 -0
  165. data/lib/synthra/relationships.rb +193 -0
  166. data/lib/synthra/repl/enhanced_repl.rb +607 -0
  167. data/lib/synthra/repl/formatter.rb +191 -0
  168. data/lib/synthra/scenarios.rb +423 -0
  169. data/lib/synthra/schema.rb +605 -0
  170. data/lib/synthra/schema_inheritance.rb +104 -0
  171. data/lib/synthra/schema_versioning.rb +212 -0
  172. data/lib/synthra/snapshot_testing.rb +199 -0
  173. data/lib/synthra/time_travel.rb +338 -0
  174. data/lib/synthra/type_definitions.rb +274 -0
  175. data/lib/synthra/types/address_location/addresses.rb +125 -0
  176. data/lib/synthra/types/address_location/airports.rb +200 -0
  177. data/lib/synthra/types/address_location/banks_hospitals.rb +207 -0
  178. data/lib/synthra/types/address_location/locations.rb +406 -0
  179. data/lib/synthra/types/base.rb +48 -0
  180. data/lib/synthra/types/commerce_products/commerce.rb +119 -0
  181. data/lib/synthra/types/commerce_products/companies.rb +71 -0
  182. data/lib/synthra/types/commerce_products/construction.rb +126 -0
  183. data/lib/synthra/types/commerce_products/products.rb +205 -0
  184. data/lib/synthra/types/core/collections.rb +513 -0
  185. data/lib/synthra/types/core/defaults.rb +76 -0
  186. data/lib/synthra/types/core/enums.rb +102 -0
  187. data/lib/synthra/types/core/identifiers.rb +445 -0
  188. data/lib/synthra/types/core/primitives.rb +586 -0
  189. data/lib/synthra/types/core/references.rb +466 -0
  190. data/lib/synthra/types/core/sequences.rb +304 -0
  191. data/lib/synthra/types/crypto/crypto.rb +162 -0
  192. data/lib/synthra/types/date_time/dates.rb +387 -0
  193. data/lib/synthra/types/finance_banking/banking.rb +424 -0
  194. data/lib/synthra/types/finance_banking/credit_cards.rb +24 -0
  195. data/lib/synthra/types/finance_banking/identifiers.rb +93 -0
  196. data/lib/synthra/types/formula.rb +184 -0
  197. data/lib/synthra/types/health_medical/medical.rb +150 -0
  198. data/lib/synthra/types/hostile_payloads.rb +122 -0
  199. data/lib/synthra/types/json_array.rb +51 -0
  200. data/lib/synthra/types/media_entertainment/media.rb +62 -0
  201. data/lib/synthra/types/naughty_string.rb +30 -0
  202. data/lib/synthra/types/personal_names/chinese.rb +41 -0
  203. data/lib/synthra/types/personal_names/identifiers.rb +187 -0
  204. data/lib/synthra/types/personal_names/names.rb +246 -0
  205. data/lib/synthra/types/personal_names/national_id.rb +89 -0
  206. data/lib/synthra/types/personal_names/titles_suffixes.rb +41 -0
  207. data/lib/synthra/types/regex.rb +248 -0
  208. data/lib/synthra/types/registry.rb +182 -0
  209. data/lib/synthra/types/repeating_element.rb +50 -0
  210. data/lib/synthra/types/scenario.rb +29 -0
  211. data/lib/synthra/types/technology_internet/apps.rb +67 -0
  212. data/lib/synthra/types/technology_internet/communication.rb +162 -0
  213. data/lib/synthra/types/technology_internet/devices.rb +80 -0
  214. data/lib/synthra/types/technology_internet/formats.rb +139 -0
  215. data/lib/synthra/types/technology_internet/networking.rb +143 -0
  216. data/lib/synthra/types/template.rb +92 -0
  217. data/lib/synthra/types/text_content/business.rb +128 -0
  218. data/lib/synthra/types/text_content/colors.rb +70 -0
  219. data/lib/synthra/types/text_content/misc.rb +237 -0
  220. data/lib/synthra/types/text_content/security.rb +130 -0
  221. data/lib/synthra/types/text_content/text_generation.rb +532 -0
  222. data/lib/synthra/types/travel/travel.rb +150 -0
  223. data/lib/synthra/utils/string_distance.rb +133 -0
  224. data/lib/synthra/validator/dsl_validator.rb +339 -0
  225. data/lib/synthra/validator/path_validator.rb +615 -0
  226. data/lib/synthra/version.rb +35 -0
  227. data/lib/synthra/webhook_simulator.rb +341 -0
  228. data/lib/synthra.rb +259 -0
  229. data/schemas/address.dsl +16 -0
  230. data/schemas/api_response.dsl +8 -0
  231. data/schemas/error_payload.dsl +9 -0
  232. data/schemas/order.dsl +10 -0
  233. data/schemas/order_item.dsl +8 -0
  234. data/schemas/payment.dsl +11 -0
  235. data/schemas/social_post.dsl +13 -0
  236. data/schemas/user.dsl +10 -0
  237. data/scripts/batch_fix_all.rb +96 -0
  238. data/scripts/delete_old_files.rb +32 -0
  239. data/scripts/fix_all_grouped_files.rb +137 -0
  240. data/scripts/fix_all_indentation.rb +48 -0
  241. data/scripts/fix_all_syntax.rb +124 -0
  242. data/scripts/fix_grouped_files.rb +184 -0
  243. data/scripts/fix_syntax_errors.rb +108 -0
  244. data/scripts/group_domain_types.rb +112 -0
  245. data/scripts/group_domain_types_fixed.rb +150 -0
  246. data/scripts/merge_domains_to_one_file.rb +68 -0
  247. data/scripts/move_existing_types.rb +130 -0
  248. data/scripts/split_grouped_types.rb +142 -0
  249. data/tech_docs/README.md +134 -0
  250. data/tech_docs/advanced/streaming.md +405 -0
  251. data/tech_docs/advanced/thread_safety.md +253 -0
  252. data/tech_docs/api/overview.md +485 -0
  253. data/tech_docs/appendices/type_chart.md +193 -0
  254. data/tech_docs/basic_concepts.md +383 -0
  255. data/tech_docs/behaviors/overview.md +346 -0
  256. data/tech_docs/dsl/complex_types.md +790 -0
  257. data/tech_docs/dsl/core_types.md +464 -0
  258. data/tech_docs/dsl/datetime_types.md +325 -0
  259. data/tech_docs/dsl/field_modifiers.md +414 -0
  260. data/tech_docs/dsl/grammar.md +431 -0
  261. data/tech_docs/dsl/schema_definition.md +399 -0
  262. data/tech_docs/export/README.md +276 -0
  263. data/tech_docs/installation.md +273 -0
  264. data/tech_docs/integration/ci_cd.md +707 -0
  265. data/tech_docs/integration/ci_cd_guide.md +579 -0
  266. data/tech_docs/integration/factory_bot.md +485 -0
  267. data/tech_docs/integration/rails.md +630 -0
  268. data/tech_docs/integration/rspec.md +449 -0
  269. data/tech_docs/modes/overview.md +350 -0
  270. data/tech_docs/performance/NATIVE_RUST_EXTENSION.md +1270 -0
  271. data/tech_docs/performance/OPTIMIZATION_GUIDE.md +901 -0
  272. data/tech_docs/quick_start.md +256 -0
  273. data/tech_docs/templates/README.md +805 -0
  274. data/tech_docs/tutorials/advanced.md +371 -0
  275. data/tech_docs/tutorials/getting_started.md +189 -0
  276. data/tech_docs/tutorials/intermediate.md +231 -0
  277. data/tech_docs/tutorials/template_gallery.md +569 -0
  278. data/tech_example/01_basic_usage.rb +238 -0
  279. data/tech_example/02_types_demo.rb +336 -0
  280. data/tech_example/04_cli_usage.md +429 -0
  281. data/tech_example/05_database_seeding.rb +283 -0
  282. data/tech_example/07_rspec_integration.rb +359 -0
  283. data/tech_example/10_custom_types.rb +387 -0
  284. data/tech_example/12_behaviors.rb +372 -0
  285. data/tech_example/13_twitter_dm_example.rb +120 -0
  286. data/tech_example/14_exact_json_structure.rb +253 -0
  287. data/tech_example/16_lsp_server.rb +56 -0
  288. data/tech_example/17_property_testing.rb +92 -0
  289. data/tech_example/18_enhanced_repl.rb +120 -0
  290. data/tech_example/19_security_fuzzing.rb +145 -0
  291. data/tech_example/NEW_FEATURES.md +169 -0
  292. data/tech_example/README.md +118 -0
  293. data/tech_example/schemas/api_response.dsl +123 -0
  294. data/tech_example/schemas/ecommerce.dsl +121 -0
  295. data/tech_example/schemas/twitter_dm.dsl +109 -0
  296. data/tech_example/schemas/user.dsl +36 -0
  297. data/vscode-extension/README.md +246 -0
  298. data/vscode-extension/language-configuration.json +31 -0
  299. data/vscode-extension/package.json +55 -0
  300. data/vscode-extension/snippets/fakedatadsl.json +198 -0
  301. data/vscode-extension/syntaxes/fakedatadsl.tmLanguage.json +128 -0
  302. metadata +478 -0
@@ -0,0 +1,429 @@
1
+ # CLI Usage Examples
2
+
3
+ Complete guide to using the FakeDataDSL command-line interface.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Basic Commands](#basic-commands)
9
+ - [Generate Command](#generate-command)
10
+ - [Validate Command](#validate-command)
11
+ - [Advanced Usage](#advanced-usage)
12
+ - [Shell Integration](#shell-integration)
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ After installing the gem, the CLI is available:
19
+
20
+ ```bash
21
+ # Via gem
22
+ gem install fake_data_dsl
23
+ fake_data_dsl --version
24
+
25
+ # Via bundler
26
+ bundle add fake_data_dsl
27
+ bundle exec fake_data_dsl --version
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Basic Commands
33
+
34
+ ### Help
35
+
36
+ ```bash
37
+ # Show all commands
38
+ fake_data_dsl --help
39
+
40
+ # Show help for specific command
41
+ fake_data_dsl generate --help
42
+ fake_data_dsl validate --help
43
+ ```
44
+
45
+ ### Version
46
+
47
+ ```bash
48
+ fake_data_dsl --version
49
+ # => fake_data_dsl 1.0.0
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Generate Command
55
+
56
+ ### Basic Generation
57
+
58
+ ```bash
59
+ # Generate one record
60
+ fake_data_dsl generate User --dir schemas
61
+
62
+ # Generate multiple records
63
+ fake_data_dsl generate User --dir schemas --count 10
64
+
65
+ # Short flags
66
+ fake_data_dsl generate User -d schemas -c 10
67
+ ```
68
+
69
+ ### Output Formats
70
+
71
+ ```bash
72
+ # JSON array (default)
73
+ fake_data_dsl generate User -d schemas -c 3
74
+ # [{"id":"...","name":"John"},{"id":"...","name":"Jane"}]
75
+
76
+ # Pretty printed JSON
77
+ fake_data_dsl generate User -d schemas -c 3 --pretty
78
+ # [
79
+ # {
80
+ # "id": "...",
81
+ # "name": "John"
82
+ # },
83
+ # ...
84
+ # ]
85
+
86
+ # NDJSON (newline-delimited JSON)
87
+ fake_data_dsl generate User -d schemas -c 3 --ndjson
88
+ # {"id":"...","name":"John"}
89
+ # {"id":"...","name":"Jane"}
90
+ # {"id":"...","name":"Bob"}
91
+ ```
92
+
93
+ ### Generation Modes
94
+
95
+ ```bash
96
+ # Random mode (default) - realistic data
97
+ fake_data_dsl generate User -d schemas --mode random
98
+
99
+ # Edge mode - boundary values
100
+ fake_data_dsl generate User -d schemas --mode edge
101
+
102
+ # Invalid mode - invalid data for testing
103
+ fake_data_dsl generate User -d schemas --mode invalid
104
+
105
+ # Mixed mode - combination
106
+ fake_data_dsl generate User -d schemas --mode mixed
107
+ ```
108
+
109
+ ### Deterministic Output
110
+
111
+ ```bash
112
+ # Use seed for reproducible output
113
+ fake_data_dsl generate User -d schemas --seed 12345
114
+
115
+ # Same seed = same output
116
+ fake_data_dsl generate User -d schemas -s 12345
117
+ fake_data_dsl generate User -d schemas -s 12345
118
+ # Both produce identical output
119
+ ```
120
+
121
+ ### Output to File
122
+
123
+ ```bash
124
+ # Redirect to JSON file
125
+ fake_data_dsl generate User -d schemas -c 1000 > users.json
126
+
127
+ # NDJSON file
128
+ fake_data_dsl generate User -d schemas -c 1000 --ndjson > users.ndjson
129
+
130
+ # Pretty formatted file
131
+ fake_data_dsl generate User -d schemas -c 100 --pretty > users_formatted.json
132
+ ```
133
+
134
+ ### Generate from Stdin
135
+
136
+ ```bash
137
+ # Pipe schema directly
138
+ echo 'User:
139
+ id: uuid
140
+ name: name' | fake_data_dsl generate User --stdin
141
+
142
+ # Here document
143
+ fake_data_dsl generate User --stdin <<EOF
144
+ User:
145
+ id: uuid
146
+ name: name
147
+ email: email
148
+ EOF
149
+ ```
150
+
151
+ ---
152
+
153
+ ## Validate Command
154
+
155
+ ### Basic Validation
156
+
157
+ ```bash
158
+ # Validate single file
159
+ fake_data_dsl validate schemas/user.dsl
160
+ # ✓ schemas/user.dsl is valid
161
+
162
+ # Validate multiple files
163
+ fake_data_dsl validate schemas/*.dsl
164
+
165
+ # Validate directory
166
+ fake_data_dsl validate schemas/
167
+ ```
168
+
169
+ ### Verbose Output
170
+
171
+ ```bash
172
+ fake_data_dsl validate schemas/user.dsl --verbose
173
+ # Validating schemas/user.dsl...
174
+ # Found schema: User
175
+ # - id: uuid
176
+ # - name: name
177
+ # - email: email
178
+ # ✓ schemas/user.dsl is valid
179
+ ```
180
+
181
+ ### Error Output
182
+
183
+ ```bash
184
+ # Invalid schema
185
+ fake_data_dsl validate invalid.dsl
186
+ # ✗ invalid.dsl has errors:
187
+ # Line 3, column 5: Unknown type 'invald_type'
188
+ # Line 5, column 1: Expected field definition, got EOF
189
+ ```
190
+
191
+ ---
192
+
193
+ ## Advanced Usage
194
+
195
+ ### Multiple Schemas
196
+
197
+ ```bash
198
+ # Generate from file with multiple schemas
199
+ fake_data_dsl generate Order -d schemas
200
+ fake_data_dsl generate User -d schemas
201
+
202
+ # Generate different counts for each
203
+ fake_data_dsl generate User -d schemas -c 100 > users.json
204
+ fake_data_dsl generate Order -d schemas -c 500 > orders.json
205
+ ```
206
+
207
+ ### Large Batch Generation
208
+
209
+ ```bash
210
+ # Generate large dataset (streaming)
211
+ fake_data_dsl generate User -d schemas -c 1000000 --ndjson > large_dataset.ndjson
212
+
213
+ # Monitor progress
214
+ fake_data_dsl generate User -d schemas -c 1000000 --ndjson | pv -l > large_dataset.ndjson
215
+ ```
216
+
217
+ ### Piping to Other Commands
218
+
219
+ ```bash
220
+ # Pipe to jq for processing
221
+ fake_data_dsl generate User -d schemas -c 10 | jq '.[].name'
222
+
223
+ # Pipe to database import
224
+ fake_data_dsl generate User -d schemas -c 1000 --ndjson | \
225
+ mongoimport --db mydb --collection users
226
+
227
+ # Pipe to HTTP endpoint
228
+ fake_data_dsl generate User -d schemas | \
229
+ curl -X POST -H "Content-Type: application/json" -d @- http://api/users
230
+
231
+ # Count records
232
+ fake_data_dsl generate User -d schemas -c 100 | jq length
233
+ ```
234
+
235
+ ### Environment Variables
236
+
237
+ ```bash
238
+ # Set default directory
239
+ export FAKE_DATA_DSL_DIR=./schemas
240
+ fake_data_dsl generate User -c 10
241
+
242
+ # Set default seed for reproducibility
243
+ export FAKE_DATA_DSL_SEED=12345
244
+ fake_data_dsl generate User -d schemas
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Shell Integration
250
+
251
+ ### Bash Alias
252
+
253
+ ```bash
254
+ # Add to ~/.bashrc or ~/.zshrc
255
+ alias fdd="fake_data_dsl"
256
+ alias fddg="fake_data_dsl generate"
257
+ alias fddv="fake_data_dsl validate"
258
+
259
+ # Usage
260
+ fddg User -d schemas -c 10
261
+ fddv schemas/
262
+ ```
263
+
264
+ ### Bash Function
265
+
266
+ ```bash
267
+ # Generate and copy to clipboard (macOS)
268
+ fdd_copy() {
269
+ fake_data_dsl generate "$1" -d schemas | pbcopy
270
+ echo "Generated and copied to clipboard"
271
+ }
272
+
273
+ # Generate and save with timestamp
274
+ fdd_save() {
275
+ local schema=$1
276
+ local count=${2:-1}
277
+ local filename="${schema,,}_$(date +%Y%m%d_%H%M%S).json"
278
+ fake_data_dsl generate "$schema" -d schemas -c "$count" --pretty > "$filename"
279
+ echo "Saved to $filename"
280
+ }
281
+ ```
282
+
283
+ ### Fish Shell
284
+
285
+ ```fish
286
+ # ~/.config/fish/functions/fdd.fish
287
+ function fdd
288
+ fake_data_dsl $argv
289
+ end
290
+
291
+ function fddg
292
+ fake_data_dsl generate $argv
293
+ end
294
+ ```
295
+
296
+ ### Completion Scripts
297
+
298
+ ```bash
299
+ # Generate completion script (if supported)
300
+ fake_data_dsl completion bash > ~/.fake_data_dsl_completion
301
+ source ~/.fake_data_dsl_completion
302
+
303
+ # Or add to shell config
304
+ echo 'source ~/.fake_data_dsl_completion' >> ~/.bashrc
305
+ ```
306
+
307
+ ---
308
+
309
+ ## Examples
310
+
311
+ ### Database Seeding Script
312
+
313
+ ```bash
314
+ #!/bin/bash
315
+ # seed_database.sh
316
+
317
+ SCHEMA_DIR="./schemas"
318
+ SEED=12345
319
+
320
+ echo "Seeding database..."
321
+
322
+ # Generate users
323
+ echo "Generating users..."
324
+ fake_data_dsl generate User -d $SCHEMA_DIR -c 100 -s $SEED --ndjson | \
325
+ psql -c "COPY users FROM STDIN WITH (FORMAT json)"
326
+
327
+ # Generate products
328
+ echo "Generating products..."
329
+ fake_data_dsl generate Product -d $SCHEMA_DIR -c 500 -s $SEED --ndjson | \
330
+ psql -c "COPY products FROM STDIN WITH (FORMAT json)"
331
+
332
+ # Generate orders
333
+ echo "Generating orders..."
334
+ fake_data_dsl generate Order -d $SCHEMA_DIR -c 1000 -s $SEED --ndjson | \
335
+ psql -c "COPY orders FROM STDIN WITH (FORMAT json)"
336
+
337
+ echo "Done!"
338
+ ```
339
+
340
+ ### API Testing Script
341
+
342
+ ```bash
343
+ #!/bin/bash
344
+ # test_api.sh
345
+
346
+ API_URL="http://localhost:3000/api"
347
+ SCHEMA_DIR="./schemas"
348
+
349
+ echo "Testing API endpoints..."
350
+
351
+ # Test user creation
352
+ echo "Testing POST /users..."
353
+ fake_data_dsl generate User -d $SCHEMA_DIR | \
354
+ curl -s -X POST -H "Content-Type: application/json" \
355
+ -d @- "$API_URL/users" | jq
356
+
357
+ # Test batch user creation
358
+ echo "Testing POST /users/batch..."
359
+ fake_data_dsl generate User -d $SCHEMA_DIR -c 10 | \
360
+ curl -s -X POST -H "Content-Type: application/json" \
361
+ -d @- "$API_URL/users/batch" | jq
362
+
363
+ # Test with invalid data
364
+ echo "Testing validation with invalid data..."
365
+ fake_data_dsl generate User -d $SCHEMA_DIR --mode invalid | \
366
+ curl -s -X POST -H "Content-Type: application/json" \
367
+ -d @- "$API_URL/users" | jq
368
+ ```
369
+
370
+ ### Load Testing with wrk
371
+
372
+ ```bash
373
+ #!/bin/bash
374
+ # Generate test data file
375
+ fake_data_dsl generate User -d schemas -c 1000 --ndjson > test_data.ndjson
376
+
377
+ # Create Lua script for wrk
378
+ cat > wrk_test.lua <<'EOF'
379
+ -- Load test data
380
+ local data = {}
381
+ for line in io.lines("test_data.ndjson") do
382
+ table.insert(data, line)
383
+ end
384
+ local index = 1
385
+
386
+ request = function()
387
+ local body = data[index]
388
+ index = (index % #data) + 1
389
+ return wrk.format("POST", "/api/users", {
390
+ ["Content-Type"] = "application/json"
391
+ }, body)
392
+ end
393
+ EOF
394
+
395
+ # Run load test
396
+ wrk -t4 -c100 -d30s -s wrk_test.lua http://localhost:3000
397
+ ```
398
+
399
+ ---
400
+
401
+ ## Troubleshooting
402
+
403
+ ### Common Issues
404
+
405
+ ```bash
406
+ # Schema not found
407
+ fake_data_dsl generate User -d wrong_dir
408
+ # Error: No schema 'User' found in wrong_dir
409
+
410
+ # Fix: Check directory path
411
+ fake_data_dsl generate User -d ./schemas
412
+
413
+ # Invalid schema syntax
414
+ fake_data_dsl validate bad.dsl
415
+ # Error: Syntax error at line 3
416
+
417
+ # Fix: Check schema file for typos
418
+ ```
419
+
420
+ ### Debug Mode
421
+
422
+ ```bash
423
+ # Verbose output
424
+ fake_data_dsl generate User -d schemas --verbose
425
+
426
+ # Show parsed schema
427
+ fake_data_dsl validate schemas/user.dsl --verbose
428
+ ```
429
+
@@ -0,0 +1,283 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # ============================================================================
5
+ # FakeDataDSL - Database Seeding Examples
6
+ # ============================================================================
7
+ # This file demonstrates how to use FakeDataDSL for seeding databases.
8
+ # Run with: cd fake_data_dsl && ruby tech_example/05_database_seeding.rb
9
+ # ============================================================================
10
+
11
+ # Load the local gem
12
+ $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
13
+ require 'fake_data_dsl'
14
+ require 'json'
15
+
16
+ puts "=" * 70
17
+ puts "FakeDataDSL Database Seeding Examples"
18
+ puts "=" * 70
19
+ puts
20
+
21
+ # ============================================================================
22
+ # Example 1: Simple User Seeding
23
+ # ============================================================================
24
+ puts "1. SIMPLE USER SEEDING"
25
+ puts "-" * 40
26
+
27
+ user_schema = FakeDataDSL.parse(<<~DSL)
28
+ User:
29
+ id: id_sequence
30
+ uuid: uuid(unique: true)
31
+ email: email(unique: true)
32
+ name: name
33
+ encrypted_password: text(60)
34
+ created_at: past_date(2y)
35
+ updated_at: past_date(30d)
36
+ DSL
37
+
38
+ puts "Generated Users for DB seeding:"
39
+ users = user_schema.generate_many(5)
40
+ users.each do |user|
41
+ puts " INSERT INTO users (id, uuid, email, name, ...) VALUES "
42
+ puts " (#{user['id']}, '#{user['uuid']}', '#{user['email']}', '#{user['name']}', ...)"
43
+ end
44
+ puts
45
+
46
+ # ============================================================================
47
+ # Example 2: Related Tables (Foreign Keys)
48
+ # ============================================================================
49
+ puts "2. RELATED TABLES WITH FOREIGN KEYS"
50
+ puts "-" * 40
51
+
52
+ # Simulate a registry with multiple schemas
53
+ registry = FakeDataDSL::Registry.new
54
+
55
+ # Define schemas as strings for demonstration
56
+ registry.load_string(<<~DSL)
57
+ User:
58
+ id: id_sequence(start: 1)
59
+ uuid: uuid(unique: true)
60
+ email: email(unique: true)
61
+ name: name
62
+ created_at: past_date(2y)
63
+
64
+ Post:
65
+ id: id_sequence(start: 1)
66
+ uuid: uuid(unique: true)
67
+ title: text(20..100)
68
+ body: text(200..1000)
69
+ published: boolean(true:70%)
70
+ created_at: past_date(1y)
71
+
72
+ Comment:
73
+ id: id_sequence(start: 1)
74
+ body: text(10..200)
75
+ created_at: past_date(30d)
76
+ DSL
77
+
78
+ # Generate users
79
+ users = registry.schema('User').generate_many(3)
80
+ puts "Users:"
81
+ users.each { |u| puts " #{u['id']}: #{u['name']} (#{u['email']})" }
82
+ puts
83
+
84
+ # Generate posts linked to users
85
+ posts = []
86
+ users.each do |user|
87
+ num_posts = rand(1..3)
88
+ num_posts.times do
89
+ post = registry.schema('Post').generate
90
+ post['user_id'] = user['id'] # Add foreign key
91
+ posts << post
92
+ end
93
+ end
94
+
95
+ puts "Posts (with user_id foreign key):"
96
+ posts.each { |p| puts " Post #{p['id']}: user_id=#{p['user_id']}, '#{p['title'][0..30]}...'" }
97
+ puts
98
+
99
+ # Generate comments linked to posts and users
100
+ comments = []
101
+ posts.each do |post|
102
+ num_comments = rand(0..5)
103
+ num_comments.times do
104
+ comment = registry.schema('Comment').generate
105
+ comment['post_id'] = post['id']
106
+ comment['user_id'] = users.sample['id'] # Random user
107
+ comments << comment
108
+ end
109
+ end
110
+
111
+ puts "Comments (with foreign keys):"
112
+ comments.first(5).each do |c|
113
+ puts " Comment #{c['id']}: post_id=#{c['post_id']}, user_id=#{c['user_id']}"
114
+ end
115
+ puts " ... (#{comments.length} total comments)"
116
+ puts
117
+
118
+ # ============================================================================
119
+ # Example 3: Batch Insert with Streaming
120
+ # ============================================================================
121
+ puts "3. BATCH INSERT WITH STREAMING"
122
+ puts "-" * 40
123
+
124
+ large_schema = FakeDataDSL.parse(<<~DSL)
125
+ LogEntry:
126
+ id: id_sequence
127
+ level: enum(debug:50%, info:30%, warn:15%, error:5%)
128
+ message: text(50..200)
129
+ timestamp: past_date(30d)
130
+ source: enum(web, api, worker, scheduler)
131
+ DSL
132
+
133
+ puts "Streaming 1000 log entries in batches of 100:"
134
+ batch_size = 100
135
+ batch = []
136
+ count = 0
137
+
138
+ large_schema.generate_stream(count: 1000).each do |entry|
139
+ batch << entry
140
+ count += 1
141
+
142
+ if batch.size >= batch_size
143
+ puts " Inserting batch #{count / batch_size} (#{batch.size} records)..."
144
+ # In real code: Model.insert_all(batch)
145
+ batch = []
146
+ end
147
+ end
148
+
149
+ # Insert remaining
150
+ if batch.any?
151
+ puts " Inserting final batch (#{batch.size} records)..."
152
+ end
153
+ puts " Total: #{count} records inserted"
154
+ puts
155
+
156
+ # ============================================================================
157
+ # Example 4: E-commerce Database Seed
158
+ # ============================================================================
159
+ puts "4. E-COMMERCE DATABASE SEED"
160
+ puts "-" * 40
161
+
162
+ ecommerce_registry = FakeDataDSL::Registry.new
163
+ ecommerce_registry.load_string(<<~DSL)
164
+ Category:
165
+ id: id_sequence
166
+ name: enum(Electronics, Clothing, Home, Sports, Books, Toys)
167
+ slug: text(5..20)
168
+
169
+ Product:
170
+ id: id_sequence
171
+ uuid: uuid(unique: true)
172
+ name: text(10..50)
173
+ description: text(50..300)
174
+ price_cents: number(100..100000)
175
+ currency: currency_code
176
+ in_stock: boolean(true:85%)
177
+ created_at: past_date(1y)
178
+
179
+ Customer:
180
+ id: id_sequence
181
+ uuid: uuid(unique: true)
182
+ email: email(unique: true)
183
+ name: name
184
+ loyalty_tier: enum(bronze:60%, silver:25%, gold:10%, platinum:5%)
185
+ created_at: past_date(2y)
186
+
187
+ Order:
188
+ id: id_sequence
189
+ uuid: uuid(unique: true)
190
+ status: enum(pending:20%, processing:10%, shipped:40%, delivered:30%)
191
+ total_cents: number(1000..50000)
192
+ created_at: past_date(60d)
193
+ DSL
194
+
195
+ # Generate seed data
196
+ categories = ecommerce_registry.schema('Category').generate_many(6)
197
+ products = []
198
+ 50.times do
199
+ product = ecommerce_registry.schema('Product').generate
200
+ product['category_id'] = categories.sample['id']
201
+ products << product
202
+ end
203
+ customers = ecommerce_registry.schema('Customer').generate_many(20)
204
+ orders = []
205
+ 100.times do
206
+ order = ecommerce_registry.schema('Order').generate
207
+ order['customer_id'] = customers.sample['id']
208
+ orders << order
209
+ end
210
+
211
+ puts "E-commerce seed summary:"
212
+ puts " Categories: #{categories.length}"
213
+ puts " Products: #{products.length}"
214
+ puts " Customers: #{customers.length}"
215
+ puts " Orders: #{orders.length}"
216
+ puts
217
+ puts "Sample data:"
218
+ puts " Category: #{categories.first.inspect}"
219
+ puts " Product: #{products.first['name']} - $#{products.first['price_cents'] / 100.0}"
220
+ puts " Customer: #{customers.first['name']} (#{customers.first['loyalty_tier']})"
221
+ puts " Order: ##{orders.first['id']} - #{orders.first['status']}"
222
+ puts
223
+
224
+ # ============================================================================
225
+ # Example 5: Deterministic Seeding (Reproducible)
226
+ # ============================================================================
227
+ puts "5. DETERMINISTIC SEEDING (Reproducible)"
228
+ puts "-" * 40
229
+
230
+ seed_value = 42
231
+ puts "Using seed: #{seed_value}"
232
+ puts
233
+
234
+ deterministic_users_1 = user_schema.generate_many(3, seed: seed_value)
235
+ deterministic_users_2 = user_schema.generate_many(3, seed: seed_value)
236
+
237
+ puts "First generation:"
238
+ deterministic_users_1.each { |u| puts " #{u['name']} - #{u['email']}" }
239
+ puts
240
+ puts "Second generation (same seed):"
241
+ deterministic_users_2.each { |u| puts " #{u['name']} - #{u['email']}" }
242
+ puts
243
+ puts "Are they identical? #{deterministic_users_1 == deterministic_users_2}"
244
+ puts
245
+
246
+ # ============================================================================
247
+ # Example 6: Rails db/seeds.rb Style
248
+ # ============================================================================
249
+ puts "6. RAILS db/seeds.rb STYLE"
250
+ puts "-" * 40
251
+
252
+ puts <<~RUBY
253
+ # db/seeds.rb example
254
+
255
+ require 'fake_data_dsl'
256
+
257
+ # Load schema
258
+ schema = FakeDataDSL.load('db/schemas/user.dsl')
259
+
260
+ # Clear existing data (optional)
261
+ User.delete_all
262
+
263
+ # Seed users
264
+ puts "Seeding users..."
265
+ users = schema.generate_many(100, seed: ENV.fetch('SEED', 12345).to_i)
266
+ User.insert_all(users.map do |u|
267
+ {
268
+ uuid: u['uuid'],
269
+ email: u['email'],
270
+ name: u['name'],
271
+ encrypted_password: BCrypt::Password.create('password123'),
272
+ created_at: u['created_at'],
273
+ updated_at: Time.current
274
+ }
275
+ end)
276
+
277
+ puts "Created \#{User.count} users"
278
+ RUBY
279
+
280
+ puts "=" * 70
281
+ puts "Database seeding examples completed!"
282
+ puts "=" * 70
283
+