@drichdev/genata 1.0.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.
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /**
3
+ * Faker wrapper with seeding support
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.initializeFaker = initializeFaker;
7
+ exports.getFaker = getFaker;
8
+ exports.resetFaker = resetFaker;
9
+ const faker_1 = require("@faker-js/faker");
10
+ let globalFaker;
11
+ /**
12
+ * Initialize the global faker instance with optional seed
13
+ */
14
+ function initializeFaker(options) {
15
+ if (options?.seed !== undefined) {
16
+ // Always create new instance when seed is provided
17
+ globalFaker = new faker_1.Faker({ locale: faker_1.en, seed: options.seed });
18
+ }
19
+ else if (!globalFaker) {
20
+ // Only create new instance if none exists
21
+ globalFaker = new faker_1.Faker({ locale: faker_1.en });
22
+ }
23
+ if (options?.locale) {
24
+ // Faker locale can be set, but for simplicity we'll use the default
25
+ // In production, you'd want to handle locale properly
26
+ }
27
+ return globalFaker;
28
+ }
29
+ /**
30
+ * Get the current faker instance
31
+ */
32
+ function getFaker(options) {
33
+ return initializeFaker(options);
34
+ }
35
+ /**
36
+ * Reset faker to a new random state
37
+ */
38
+ function resetFaker() {
39
+ globalFaker = new faker_1.Faker({ locale: faker_1.en });
40
+ }
41
+ // Initialize on module load
42
+ initializeFaker();
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Validation utilities for Genata options and inputs
3
+ */
4
+ import type { FieldType, GeneratorOptions, BatchGeneratorOptions } from "../types";
5
+ export declare class ValidationError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ export declare function validateSeed(seed: number | undefined): void;
9
+ export declare function validateCount(count: number | undefined): void;
10
+ export declare function validateLocale(locale: string | undefined): void;
11
+ export declare function validateGeneratorOptions(options: GeneratorOptions): void;
12
+ export declare function validateBatchOptions(options: BatchGeneratorOptions): void;
13
+ export declare function isValidFieldType(type: unknown): type is FieldType;
14
+ export declare function sanitizeInput(input: string): string;
15
+ export declare function validateFieldType(type: unknown): asserts type is FieldType;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEnF,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAI3D;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAI7D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAI/D;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAGxE;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAGzE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,SAAS,CAkCjE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,IAAI,SAAS,CAI1E"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * Validation utilities for Genata options and inputs
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ValidationError = void 0;
7
+ exports.validateSeed = validateSeed;
8
+ exports.validateCount = validateCount;
9
+ exports.validateLocale = validateLocale;
10
+ exports.validateGeneratorOptions = validateGeneratorOptions;
11
+ exports.validateBatchOptions = validateBatchOptions;
12
+ exports.isValidFieldType = isValidFieldType;
13
+ exports.sanitizeInput = sanitizeInput;
14
+ exports.validateFieldType = validateFieldType;
15
+ class ValidationError extends Error {
16
+ constructor(message) {
17
+ super(message);
18
+ this.name = "ValidationError";
19
+ }
20
+ }
21
+ exports.ValidationError = ValidationError;
22
+ function validateSeed(seed) {
23
+ if (seed !== undefined && (!Number.isInteger(seed) || seed < 0)) {
24
+ throw new ValidationError("Seed must be a non-negative integer");
25
+ }
26
+ }
27
+ function validateCount(count) {
28
+ if (count !== undefined && (!Number.isInteger(count) || count < 1)) {
29
+ throw new ValidationError("Count must be a positive integer");
30
+ }
31
+ }
32
+ function validateLocale(locale) {
33
+ if (locale !== undefined && typeof locale !== "string") {
34
+ throw new ValidationError("Locale must be a string");
35
+ }
36
+ }
37
+ function validateGeneratorOptions(options) {
38
+ validateSeed(options.seed);
39
+ validateLocale(options.locale);
40
+ }
41
+ function validateBatchOptions(options) {
42
+ validateGeneratorOptions(options);
43
+ validateCount(options.count);
44
+ }
45
+ function isValidFieldType(type) {
46
+ const validTypes = [
47
+ "first_name",
48
+ "last_name",
49
+ "full_name",
50
+ "email",
51
+ "password",
52
+ "phone",
53
+ "address",
54
+ "city",
55
+ "country",
56
+ "zip",
57
+ "date",
58
+ "datetime",
59
+ "int",
60
+ "float",
61
+ "uuid",
62
+ "boolean",
63
+ "id_increment",
64
+ "number",
65
+ "zero_one",
66
+ "company",
67
+ "job_title",
68
+ "username",
69
+ "url",
70
+ "credit_card",
71
+ "ipv4",
72
+ "ipv6",
73
+ "color",
74
+ "paragraph",
75
+ "sentence",
76
+ ];
77
+ return typeof type === "string" && validTypes.includes(type);
78
+ }
79
+ function sanitizeInput(input) {
80
+ // Remove potentially dangerous characters but keep reasonable special chars
81
+ return input.replace(/[<>{}]/g, "");
82
+ }
83
+ function validateFieldType(type) {
84
+ if (!isValidFieldType(type)) {
85
+ throw new ValidationError(`Invalid field type: ${type}`);
86
+ }
87
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@drichdev/genata",
3
+ "version": "1.0.0",
4
+ "description": "Generate realistic fake data easily",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "module": "dist/index.esm.js",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "dev": "tsc --watch",
14
+ "test": "jest",
15
+ "lint": "eslint src --ext .ts",
16
+ "prepublish": "npm run build"
17
+ },
18
+ "keywords": [
19
+ "fake-data",
20
+ "faker",
21
+ "mock-data",
22
+ "testing",
23
+ "data-generator"
24
+ ],
25
+ "author": "Genata",
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "@faker-js/faker": "^10.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^20",
32
+ "typescript": "^5",
33
+ "eslint": "^8",
34
+ "@typescript-eslint/eslint-plugin": "^6",
35
+ "@typescript-eslint/parser": "^6",
36
+ "jest": "^29",
37
+ "@types/jest": "^29"
38
+ },
39
+ "engines": {
40
+ "node": ">=16.0.0"
41
+ }
42
+ }