@@ -277,9 +277,9 @@ Templates define the structure of generated messages using faker.js for realisti
277277The CLI includes a default template with faker.js support :
278278
279279` ` ` yaml
280- name: "faker :person.fullName"
281- email: "faker :internet.email"
282- age: "faker: number.int(18,65 )"
280+ name: ": :person.fullName"
281+ email: ": :internet.email"
282+ age: ":: number.int({min: 18, max:65} )"
283283timestamp: "current_timestamp"
284284` ` `
285285
@@ -289,11 +289,12 @@ Create your own template file:
289289
290290` ` ` yaml
291291# my-template.yaml
292- userId: "faker:string.uuid"
293- username: "faker:internet.userName"
294- company: "faker:company.name"
295- location: "faker:location.city"
296- price: "faker:commerce.price(10,1000)"
292+ userId: "::string.uuid"
293+ username: "::internet.userName"
294+ company: "::company.name"
295+ location: "::location.city"
296+ price: "::commerce.price({min:10, max:1000})"
297+ status: '::helpers.arrayElement(["active","pending","suspended"])'
297298` ` `
298299
299300**Use it:**
@@ -310,63 +311,81 @@ nu-cli send --template ./my-template.yaml
310311
311312# ## Faker.js Syntax
312313
313- Supports full [faker.js API](https://fakerjs.dev/api/):
314+ Full [faker.js API](https://fakerjs.dev/api/) support using `::` prefix. Parameters are parsed as JSON and spread as `...args` to faker functions.
314315
315- - ` faker:person.fullName` → Random full name
316- - ` faker:internet.email` → Random email
317- - ` faker:number.int(18,65)` → Random integer between 18 and 65
318- - ` faker:company.name` → Random company name
319- - ` faker:location.streetAddress` → Random street address
320- - ` faker:string.uuid` → Random UUID
321- - ` faker:commerce.price(10,1000)` → Random price between 10 and 1000
322-
323- # ## Legacy Syntax (still supported)
316+ **Simple calls (no parameters):**
317+ ` ` ` yaml
318+ name: "::person.fullName"
319+ email: "::internet.email"
320+ company: "::company.name"
321+ address: "::location.streetAddress"
322+ uuid: "::string.uuid"
323+ ` ` `
324324
325- - ` random_name` → Random name from built-in list
326- - ` random_int(1,100)` → Random integer
327- - ` current_timestamp` → ISO 8601 timestamp
325+ **With parameters (use JSON syntax, wrap in single quotes in YAML):**
326+ ` ` ` yaml
327+ # Object parameters
328+ age: "::number.int({min:18, max:65})"
329+ price: "::commerce.price({min:10, max:1000})"
328330
329- # # Message Templates
331+ # Single argument (array)
332+ event: '::helpers.arrayElement(["login","logout","purchase"])'
330333
331- Messages are generated from templates defined in `src/lib/template/generator.ts`. To customize message structure, edit the `MESSAGE_TEMPLATE` constant :
334+ # Multiple arguments (array, options object)
335+ tags: '::helpers.arrayElements(["tech","sports","music"], {min:2, max:4})'
332336
333- ` ` ` typescript
334- export const MESSAGE_TEMPLATE: TemplateObject = {
335- "name": "random_name",
336- };
337+ # Multiple arguments (coordinates, distance, isMetric)
338+ location: '::location.nearbyGPSCoordinate([52.52, 13.40], 10, true)'
337339` ` `
338340
339- # ## Example: Complex template
340-
341- ` ` ` typescript
342- export const MESSAGE_TEMPLATE = {
343- user: {
344- name: "random_name",
345- city: "random_city"
346- },
347- order: {
348- product: "random_product",
349- quantity: "random_int(1,5)",
350- status: "random_status",
351- timestamp: "current_timestamp"
352- }
353- };
354- ` ` `
341+ **How it works:**
342+ - ` ::category.method` maps to `faker.category.method()`
343+ - Parameters are parsed as JSON : ` ({min:18,max:65})` → `fn({min:18, max:65})`
344+ - Supports any faker.js function signature exactly as documented
355345
356- # ## Available placeholders
346+ **Special values:**
347+ - ` current_timestamp` → ISO 8601 timestamp
357348
358- - ` random_name` - Random person name from predefined list
359- - ` random_city` - Random city name
360- - ` random_product` - Random product name
361- - ` random_status` - Random status (pending, completed, failed, in_progress)
362- - ` random_int(min,max)` - Random integer in range (e.g., `random_int(1,10)`)
363- - ` current_timestamp` - ISO 8601 timestamp (e.g., `2024-02-16T10:30:00.000Z`)
349+ # ## Advanced Examples
364350
365- After modifying the template, rebuild the CLI :
366- ` ` ` bash
367- npm run build
351+ **Complete event template:**
352+ ` ` ` yaml
353+ # events.yaml
354+ userId: "::string.uuid"
355+ eventType: '::helpers.arrayElement(["login","logout","purchase","click"])'
356+ timestamp: "current_timestamp"
357+ user:
358+ name: "::person.fullName"
359+ email: "::internet.email"
360+ age: "::number.int({min:18, max:65})"
361+ metadata:
362+ ip: "::internet.ip"
363+ device: '::helpers.arrayElement(["mobile","desktop","tablet"])'
364+ browser: '::helpers.arrayElement(["Chrome","Firefox","Safari","Edge"])'
365+ location: "::location.city"
366+ coordinates: '::location.nearbyGPSCoordinate([52.52, 13.40], 10, true)'
367+ ` ` `
368+
369+ **E-commerce order:**
370+ ` ` ` yaml
371+ orderId: "::string.uuid"
372+ products: '::helpers.arrayElements(["laptop","phone","tablet","watch","headphones"], {min:1, max:3})'
373+ totalPrice: "::commerce.price({min:50, max:5000})"
374+ status: '::helpers.arrayElement(["pending","processing","shipped","delivered"])'
375+ customer:
376+ id: "::string.uuid"
377+ name: "::person.fullName"
378+ email: "::internet.email"
379+ shippingAddress:
380+ street: "::location.streetAddress"
381+ city: "::location.city"
382+ country: "::location.country"
383+ zipCode: "::location.zipCode"
384+ createdAt: "current_timestamp"
368385` ` `
369386
387+
388+
370389# # Examples
371390
372391# ## Continuous production with custom delay
0 commit comments