@travetto/schema-faker 7.0.0-rc.2 → 7.0.0-rc.4

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/faker.ts +18 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/schema-faker",
3
- "version": "7.0.0-rc.2",
3
+ "version": "7.0.0-rc.4",
4
4
  "description": "Data generation for schema-registered objects.",
5
5
  "keywords": [
6
6
  "faker",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@faker-js/faker": "^10.1.0",
29
- "@travetto/schema": "^7.0.0-rc.2"
29
+ "@travetto/schema": "^7.0.0-rc.4"
30
30
  },
31
31
  "travetto": {
32
32
  "displayName": "Schema Faker"
package/src/faker.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { faker } from '@faker-js/faker';
2
2
 
3
3
  import { Class, TimeUtil } from '@travetto/runtime';
4
- import { BindUtil, SchemaFieldConfig, CommonRegExp, SchemaRegistryIndex } from '@travetto/schema';
4
+ import { BindUtil, SchemaFieldConfig, CommonRegex, SchemaRegistryIndex } from '@travetto/schema';
5
5
 
6
6
 
7
7
  /**
@@ -10,10 +10,10 @@ import { BindUtil, SchemaFieldConfig, CommonRegExp, SchemaRegistryIndex } from '
10
10
  export class SchemaFaker {
11
11
 
12
12
  static #stringToReType = new Map<RegExp, () => string>([
13
- [CommonRegExp.email, faker.internet.email],
14
- [CommonRegExp.url, faker.internet.url],
15
- [CommonRegExp.telephone, faker.phone.number],
16
- [CommonRegExp.postalCode, faker.location.zipCode]
13
+ [CommonRegex.email, faker.internet.email],
14
+ [CommonRegex.url, faker.internet.url],
15
+ [CommonRegex.telephone, faker.phone.number],
16
+ [CommonRegex.postalCode, faker.location.zipCode]
17
17
  ]);
18
18
 
19
19
  /**
@@ -64,8 +64,8 @@ export class SchemaFaker {
64
64
  * @param config Field configuration
65
65
  */
66
66
  static #array(config: SchemaFieldConfig): unknown[] {
67
- const min = config.minlength ? config.minlength.n : 0;
68
- const max = config.maxlength ? config.maxlength.n : 10;
67
+ const min = config.minlength ? config.minlength.limit : 0;
68
+ const max = config.maxlength ? config.maxlength.limit : 10;
69
69
  const size = faker.number.int({ min, max });
70
70
  const out: unknown[] = [];
71
71
  for (let i = 0; i < size; i++) {
@@ -79,8 +79,8 @@ export class SchemaFaker {
79
79
  * @param config Number config
80
80
  */
81
81
  static #number(config: SchemaFieldConfig): number {
82
- let min = config.min && typeof config.min.n === 'number' ? config.min.n : undefined;
83
- let max = config.max && typeof config.max.n === 'number' ? config.max.n : undefined;
82
+ let min = config.min && typeof config.min.limit === 'number' ? config.min.limit : undefined;
83
+ let max = config.max && typeof config.max.limit === 'number' ? config.max.limit : undefined;
84
84
  let precision = config.precision;
85
85
 
86
86
  if (/(price|amt|amount)$/i.test(config.name)) {
@@ -113,14 +113,14 @@ export class SchemaFaker {
113
113
  */
114
114
  static #date(config: SchemaFieldConfig): Date {
115
115
  const name = config.name.toLowerCase();
116
- const min = config.min && typeof config.min.n !== 'number' ? config.min.n : undefined;
117
- const max = config.max && typeof config.max.n !== 'number' ? config.max.n : undefined;
116
+ const min = config.min && typeof config.min.limit !== 'number' ? config.min.limit : undefined;
117
+ const max = config.max && typeof config.max.limit !== 'number' ? config.max.limit : undefined;
118
118
 
119
119
  if (min !== undefined || max !== undefined) {
120
120
  return faker.date.between({ from: min || TimeUtil.fromNow(-50, 'd'), to: max || new Date() });
121
121
  } else {
122
- for (const [re, fn] of this.#namesToType.date) {
123
- if (re.test(name)) {
122
+ for (const [regex, fn] of this.#namesToType.date) {
123
+ if (regex.test(name)) {
124
124
  return fn();
125
125
  }
126
126
  }
@@ -136,16 +136,16 @@ export class SchemaFaker {
136
136
  const name = config.name.toLowerCase();
137
137
 
138
138
  if (config.match) {
139
- const mre = config.match && config.match.re;
140
- for (const [re, fn] of this.#stringToReType) {
141
- if (mre === re) {
139
+ const mre = config.match && config.match.regex;
140
+ for (const [regex, fn] of this.#stringToReType) {
141
+ if (mre === regex) {
142
142
  return fn();
143
143
  }
144
144
  }
145
145
  }
146
146
 
147
- for (const [re, fn] of this.#namesToType.string) {
148
- if (re.test(name)) {
147
+ for (const [regex, fn] of this.#namesToType.string) {
148
+ if (regex.test(name)) {
149
149
  return fn();
150
150
  }
151
151
  }