|
| 1 | +import type { Model } from '@stacksjs/types' |
| 2 | +import { faker } from '@stacksjs/faker' |
| 3 | +import { schema } from '@stacksjs/validation' |
| 4 | + |
| 5 | +export default { |
| 6 | + name: 'Request', |
| 7 | + table: 'requests', |
| 8 | + primaryKey: 'id', |
| 9 | + autoIncrement: true, |
| 10 | + |
| 11 | + traits: { |
| 12 | + useTimestamps: true, |
| 13 | + useSoftDeletes: true, |
| 14 | + useSeeder: { |
| 15 | + count: 50, |
| 16 | + }, |
| 17 | + useApi: true, |
| 18 | + }, |
| 19 | + |
| 20 | + attributes: { |
| 21 | + method: { |
| 22 | + fillable: true, |
| 23 | + validation: { |
| 24 | + rule: schema.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD']), |
| 25 | + message: { |
| 26 | + enum: 'method must be a valid HTTP method', |
| 27 | + required: 'method is required', |
| 28 | + }, |
| 29 | + }, |
| 30 | + factory: () => faker.helpers.arrayElement(['GET', 'POST', 'PUT', 'DELETE']), |
| 31 | + }, |
| 32 | + |
| 33 | + path: { |
| 34 | + fillable: true, |
| 35 | + validation: { |
| 36 | + rule: schema.string(), |
| 37 | + message: { |
| 38 | + string: 'path must be a string', |
| 39 | + required: 'path is required', |
| 40 | + }, |
| 41 | + }, |
| 42 | + factory: () => faker.internet.url(), |
| 43 | + }, |
| 44 | + |
| 45 | + status_code: { |
| 46 | + fillable: true, |
| 47 | + validation: { |
| 48 | + rule: schema.number(), |
| 49 | + message: { |
| 50 | + number: 'status_code must be a number', |
| 51 | + required: 'status_code is required', |
| 52 | + }, |
| 53 | + }, |
| 54 | + factory: () => faker.helpers.arrayElement([200, 201, 400, 401, 403, 404, 500]), |
| 55 | + }, |
| 56 | + |
| 57 | + duration_ms: { |
| 58 | + fillable: true, |
| 59 | + validation: { |
| 60 | + rule: schema.number(), |
| 61 | + message: { |
| 62 | + number: 'duration_ms must be a number', |
| 63 | + required: 'duration_ms is required', |
| 64 | + }, |
| 65 | + }, |
| 66 | + factory: () => faker.number.int({ min: 50, max: 1000 }), |
| 67 | + }, |
| 68 | + |
| 69 | + ip_address: { |
| 70 | + fillable: true, |
| 71 | + validation: { |
| 72 | + rule: schema.string(), |
| 73 | + message: { |
| 74 | + string: 'ip_address must be a string', |
| 75 | + required: 'ip_address is required', |
| 76 | + }, |
| 77 | + }, |
| 78 | + factory: () => faker.internet.ip(), |
| 79 | + }, |
| 80 | + |
| 81 | + memory_usage: { |
| 82 | + fillable: true, |
| 83 | + validation: { |
| 84 | + rule: schema.number(), |
| 85 | + message: { |
| 86 | + number: 'memory_usage must be a number in MB', |
| 87 | + required: 'memory_usage is required', |
| 88 | + }, |
| 89 | + }, |
| 90 | + factory: () => faker.number.int({ min: 50, max: 512 }), |
| 91 | + }, |
| 92 | + |
| 93 | + user_agent: { |
| 94 | + fillable: true, |
| 95 | + validation: { |
| 96 | + rule: schema.string(), |
| 97 | + message: { |
| 98 | + string: 'user_agent must be a string', |
| 99 | + }, |
| 100 | + }, |
| 101 | + factory: () => faker.internet.userAgent(), |
| 102 | + }, |
| 103 | + |
| 104 | + error_message: { |
| 105 | + fillable: true, |
| 106 | + validation: { |
| 107 | + rule: schema.string(), |
| 108 | + message: { |
| 109 | + string: 'error_message must be a string', |
| 110 | + }, |
| 111 | + }, |
| 112 | + factory: () => faker.helpers.maybe(() => faker.lorem.sentence(), { probability: 0.2 }), |
| 113 | + }, |
| 114 | + }, |
| 115 | +} satisfies Model |
0 commit comments