@zero-server/orm 0.9.0 → 0.9.2

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 (42) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1 -1
  3. package/index.js +35 -35
  4. package/lib/debug.js +372 -0
  5. package/lib/orm/adapters/json.js +290 -0
  6. package/lib/orm/adapters/memory.js +764 -0
  7. package/lib/orm/adapters/mongo.js +764 -0
  8. package/lib/orm/adapters/mysql.js +933 -0
  9. package/lib/orm/adapters/postgres.js +1144 -0
  10. package/lib/orm/adapters/redis.js +1534 -0
  11. package/lib/orm/adapters/sql-base.js +212 -0
  12. package/lib/orm/adapters/sqlite.js +858 -0
  13. package/lib/orm/audit.js +649 -0
  14. package/lib/orm/cache.js +394 -0
  15. package/lib/orm/geo.js +387 -0
  16. package/lib/orm/index.js +784 -0
  17. package/lib/orm/migrate.js +432 -0
  18. package/lib/orm/model.js +1706 -0
  19. package/lib/orm/plugin.js +375 -0
  20. package/lib/orm/procedures.js +836 -0
  21. package/lib/orm/profiler.js +233 -0
  22. package/lib/orm/query.js +1772 -0
  23. package/lib/orm/replicas.js +241 -0
  24. package/lib/orm/schema.js +307 -0
  25. package/lib/orm/search.js +380 -0
  26. package/lib/orm/seed/data/commerce.js +136 -0
  27. package/lib/orm/seed/data/internet.js +111 -0
  28. package/lib/orm/seed/data/locations.js +204 -0
  29. package/lib/orm/seed/data/names.js +338 -0
  30. package/lib/orm/seed/data/person.js +128 -0
  31. package/lib/orm/seed/data/phone.js +211 -0
  32. package/lib/orm/seed/data/words.js +134 -0
  33. package/lib/orm/seed/factory.js +178 -0
  34. package/lib/orm/seed/fake.js +1186 -0
  35. package/lib/orm/seed/index.js +18 -0
  36. package/lib/orm/seed/rng.js +71 -0
  37. package/lib/orm/seed/seeder.js +125 -0
  38. package/lib/orm/seed/unique.js +68 -0
  39. package/lib/orm/snapshot.js +366 -0
  40. package/lib/orm/tenancy.js +605 -0
  41. package/lib/orm/views.js +350 -0
  42. package/package.json +12 -3
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @module seed/data/person
5
+ * @description Data pools for generated person attributes:
6
+ * job titles, prefixes/suffixes, gender, bio phrases, zodiac signs.
7
+ */
8
+
9
+ /** Title prefixes — separate lists per target sex for contextual use. */
10
+ const NAME_PREFIXES = {
11
+ male: ['Mr.', 'Dr.', 'Prof.'],
12
+ female: ['Ms.', 'Mrs.', 'Dr.', 'Prof.', 'Miss'],
13
+ neutral: ['Dr.', 'Prof.', 'Rev.', 'Hon.'],
14
+ };
15
+
16
+ /** Credential / generational suffixes. */
17
+ const NAME_SUFFIXES = [
18
+ 'Jr.', 'Sr.', 'I', 'II', 'III', 'IV', 'V',
19
+ 'PhD', 'MD', 'MBA', 'DDS', 'Esq.', 'PE',
20
+ ];
21
+
22
+ /** Job-level descriptors (prepended to job titles). */
23
+ const JOB_DESCRIPTORS = [
24
+ 'Senior', 'Junior', 'Lead', 'Principal', 'Staff', 'Associate',
25
+ 'Global', 'Regional', 'District', 'National', 'Chief', 'Head of',
26
+ 'VP of', 'Director of', 'Manager of', 'Specialist in',
27
+ ];
28
+
29
+ /** Functional areas / departments. */
30
+ const JOB_AREAS = [
31
+ 'Engineering', 'Software', 'Frontend', 'Backend', 'Full-Stack',
32
+ 'Data', 'Infrastructure', 'Cloud', 'Security', 'DevOps', 'QA',
33
+ 'Product', 'Design', 'UX', 'Brand', 'Marketing', 'Growth',
34
+ 'Sales', 'Account', 'Customer Success', 'Support', 'Finance',
35
+ 'Operations', 'Legal', 'HR', 'Research', 'Analytics', 'Business',
36
+ 'Mobile', 'AI', 'Machine Learning', 'Platform', 'Solutions',
37
+ ];
38
+
39
+ /** Job title nouns. */
40
+ const JOB_TYPES = [
41
+ 'Engineer', 'Developer', 'Designer', 'Architect', 'Analyst',
42
+ 'Strategist', 'Consultant', 'Coordinator', 'Administrator',
43
+ 'Manager', 'Director', 'Officer', 'Executive', 'Specialist',
44
+ 'Researcher', 'Scientist', 'Associate', 'Advisor', 'Lead',
45
+ 'Partner', 'Representative', 'Recruiter', 'Writer', 'Editor',
46
+ 'Technician', 'Operator', 'Planner', 'Producer', 'Advocate',
47
+ ];
48
+
49
+ /** Pre-built full job titles for use when a complete title is needed. */
50
+ const JOB_TITLES = [
51
+ 'Software Engineer', 'Senior Software Engineer', 'Lead Developer',
52
+ 'Full-Stack Developer', 'Frontend Developer', 'Backend Engineer',
53
+ 'DevOps Engineer', 'Site Reliability Engineer', 'Platform Engineer',
54
+ 'Data Engineer', 'Data Scientist', 'Machine Learning Engineer',
55
+ 'Product Manager', 'Senior Product Manager', 'Technical Product Manager',
56
+ 'UX Designer', 'UI Designer', 'Product Designer', 'Brand Designer',
57
+ 'Marketing Manager', 'Growth Hacker', 'Content Strategist', 'SEO Specialist',
58
+ 'Sales Engineer', 'Account Executive', 'Customer Success Manager',
59
+ 'Business Analyst', 'Financial Analyst', 'Chief Financial Officer',
60
+ 'Chief Technology Officer', 'Chief Executive Officer', 'VP of Engineering',
61
+ 'Director of Operations', 'Head of Growth', 'Engineering Manager',
62
+ 'QA Engineer', 'Security Engineer', 'Cloud Architect', 'Solutions Architect',
63
+ 'HR Business Partner', 'Talent Acquisition Specialist', 'Legal Counsel',
64
+ 'Data Analyst', 'BI Developer', 'Mobile Developer', 'iOS Engineer',
65
+ 'Android Developer', 'Technical Writer', 'Developer Advocate',
66
+ ];
67
+
68
+ /** Zodiac sign names. */
69
+ const ZODIAC_SIGNS = [
70
+ 'Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', 'Virgo',
71
+ 'Libra', 'Scorpio', 'Sagittarius', 'Capricorn', 'Aquarius', 'Pisces',
72
+ ];
73
+
74
+ /** Inclusive gender labels. */
75
+ const GENDERS = [
76
+ 'Male', 'Female', 'Non-binary', 'Gender fluid', 'Agender',
77
+ 'Bigender', 'Genderqueer', 'Two-spirit', 'Trans man', 'Trans woman',
78
+ 'Pangender', 'Neutrois', 'Androgynous', 'Gender non-conforming',
79
+ ];
80
+
81
+ /** Short biography phrase fragments, combinable into a fun bio. */
82
+ const BIO_ADJECTIVES = [
83
+ 'avid', 'aspiring', 'passionate', 'reformed', 'recovering', 'proud',
84
+ 'self-taught', 'seasoned', 'aspiring', 'enthusiastic', 'relentless',
85
+ 'certified', 'award-winning', 'self-proclaimed', 'part-time', 'full-time',
86
+ ];
87
+
88
+ const BIO_NOUNS = [
89
+ 'coder', 'developer', 'designer', 'hacker', 'maker', 'builder',
90
+ 'tinkerer', 'skeptic', 'advocate', 'coffee drinker', 'pizza lover',
91
+ 'cat person', 'dog person', 'night owl', 'morning person', 'traveler',
92
+ 'bookworm', 'gamer', 'runner', 'cyclist', 'climber', 'swimmer',
93
+ 'foodie', 'chef', 'photographer', 'musician', 'artist', 'dreamer',
94
+ 'blogger', 'podcaster', 'content creator', 'open-source contributor',
95
+ ];
96
+
97
+ const BIO_PHRASES = [
98
+ 'lover of all things tech', 'always learning something new',
99
+ 'living one commit at a time', 'making things that matter',
100
+ 'caffeinated and ready to ship', 'here to build great products',
101
+ 'not all who wander are lost', 'just vibing and deploying hotfixes',
102
+ 'ask me about my side projects', 'one bug at a time',
103
+ 'pushing to prod on Fridays', 'debug everything, regret nothing',
104
+ 'refactoring the world, one function at a time',
105
+ 'building the future from the terminal',
106
+ 'professional overthinker', 'chaos engineer in training',
107
+ '10x developer (citation needed)', 'it works on my machine',
108
+ 'turning coffee into code since forever',
109
+ 'probably thinking about distributed systems right now',
110
+ ];
111
+
112
+ /** Blood type options. */
113
+ const BLOOD_TYPES = ['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-'];
114
+
115
+ module.exports = {
116
+ NAME_PREFIXES,
117
+ NAME_SUFFIXES,
118
+ JOB_DESCRIPTORS,
119
+ JOB_AREAS,
120
+ JOB_TYPES,
121
+ JOB_TITLES,
122
+ ZODIAC_SIGNS,
123
+ GENDERS,
124
+ BIO_ADJECTIVES,
125
+ BIO_NOUNS,
126
+ BIO_PHRASES,
127
+ BLOOD_TYPES,
128
+ };
@@ -0,0 +1,211 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @module seed/data/phone
5
+ * @description Phone format templates and country-code metadata.
6
+ *
7
+ * Format characters:
8
+ * # any digit (0–9)
9
+ * N non-zero digit (1–9)
10
+ * X subscriber digit (2–9)
11
+ */
12
+
13
+ /**
14
+ * Array of { countryCode, dialCode, formats }
15
+ *
16
+ * formats.human – human-input style (e.g. 555-770-7727 x1234)
17
+ * formats.national – national format (e.g. (555) 123-4567)
18
+ * formats.international – E.123 style (e.g. +1 555 123 4567)
19
+ */
20
+ const PHONE_DATA = [
21
+ {
22
+ countryCode: 'US',
23
+ dialCode: '+1',
24
+ formats: {
25
+ human: ['###-###-####', '(###) ###-####', '###.###.####', '###-###-#### x###'],
26
+ national: ['(###) ###-####'],
27
+ international: ['+1 (###) ###-####', '+1-###-###-####'],
28
+ },
29
+ },
30
+ {
31
+ countryCode: 'CA',
32
+ dialCode: '+1',
33
+ formats: {
34
+ human: ['###-###-####', '(###) ###-####', '###.###.####'],
35
+ national: ['(###) ###-####'],
36
+ international: ['+1 (###) ###-####'],
37
+ },
38
+ },
39
+ {
40
+ countryCode: 'GB',
41
+ dialCode: '+44',
42
+ formats: {
43
+ human: ['07### ######', '01### ######', '02# #### ####'],
44
+ national: ['07### ######', '(01###) ######'],
45
+ international: ['+44 7### ######', '+44 1### ######'],
46
+ },
47
+ },
48
+ {
49
+ countryCode: 'DE',
50
+ dialCode: '+49',
51
+ formats: {
52
+ human: ['0### #######', '0## ########', '01## #######'],
53
+ national: ['(0###) #######'],
54
+ international: ['+49 ### #######', '+49 ## ########'],
55
+ },
56
+ },
57
+ {
58
+ countryCode: 'FR',
59
+ dialCode: '+33',
60
+ formats: {
61
+ human: ['0# ## ## ## ##', '06 ## ## ## ##', '07 ## ## ## ##'],
62
+ national: ['0# ## ## ## ##'],
63
+ international: ['+33 # ## ## ## ##'],
64
+ },
65
+ },
66
+ {
67
+ countryCode: 'IT',
68
+ dialCode: '+39',
69
+ formats: {
70
+ human: ['### #######', '3## #######'],
71
+ national: ['(###) #######'],
72
+ international: ['+39 ### #######'],
73
+ },
74
+ },
75
+ {
76
+ countryCode: 'ES',
77
+ dialCode: '+34',
78
+ formats: {
79
+ human: ['### ### ###', '6## ### ###'],
80
+ national: ['(###) ### ###'],
81
+ international: ['+34 ### ### ###'],
82
+ },
83
+ },
84
+ {
85
+ countryCode: 'PT',
86
+ dialCode: '+351',
87
+ formats: {
88
+ human: ['2## ### ###', '9## ### ###'],
89
+ national: ['(2##) ### ###'],
90
+ international: ['+351 ### ### ###'],
91
+ },
92
+ },
93
+ {
94
+ countryCode: 'BR',
95
+ dialCode: '+55',
96
+ formats: {
97
+ human: ['(##) ####-####', '(##) 9####-####'],
98
+ national: ['(##) ####-####'],
99
+ international: ['+55 ## #### ####'],
100
+ },
101
+ },
102
+ {
103
+ countryCode: 'MX',
104
+ dialCode: '+52',
105
+ formats: {
106
+ human: ['(###) ###-####', '## #### ####'],
107
+ national: ['(###) ###-####'],
108
+ international: ['+52 ### ### ####'],
109
+ },
110
+ },
111
+ {
112
+ countryCode: 'RU',
113
+ dialCode: '+7',
114
+ formats: {
115
+ human: ['8 (###) ###-##-##', '8-###-###-##-##'],
116
+ national: ['(###) ###-##-##'],
117
+ international: ['+7 (###) ###-##-##'],
118
+ },
119
+ },
120
+ {
121
+ countryCode: 'IN',
122
+ dialCode: '+91',
123
+ formats: {
124
+ human: ['#####-#####', '(0##) ###-####'],
125
+ national: ['##### #####'],
126
+ international: ['+91 ##### #####'],
127
+ },
128
+ },
129
+ {
130
+ countryCode: 'CN',
131
+ dialCode: '+86',
132
+ formats: {
133
+ human: ['### #### ####', '1## #### ####'],
134
+ national: ['(0##) #### ####'],
135
+ international: ['+86 ### #### ####'],
136
+ },
137
+ },
138
+ {
139
+ countryCode: 'JP',
140
+ dialCode: '+81',
141
+ formats: {
142
+ human: ['0##-####-####', '080-####-####', '090-####-####'],
143
+ national: ['(0##) ####-####'],
144
+ international: ['+81 ##-####-####'],
145
+ },
146
+ },
147
+ {
148
+ countryCode: 'KR',
149
+ dialCode: '+82',
150
+ formats: {
151
+ human: ['0##-####-####', '010-####-####'],
152
+ national: ['(0##) ####-####'],
153
+ international: ['+82 ##-####-####'],
154
+ },
155
+ },
156
+ {
157
+ countryCode: 'AU',
158
+ dialCode: '+61',
159
+ formats: {
160
+ human: ['04## ### ###', '0# #### ####'],
161
+ national: ['04## ### ###', '(0#) #### ####'],
162
+ international: ['+61 4## ### ###', '+61 # #### ####'],
163
+ },
164
+ },
165
+ {
166
+ countryCode: 'NL',
167
+ dialCode: '+31',
168
+ formats: {
169
+ human: ['0## ### ####', '06 ## ## ## ##'],
170
+ national: ['(0##) ### ####'],
171
+ international: ['+31 ## ### ####'],
172
+ },
173
+ },
174
+ {
175
+ countryCode: 'SE',
176
+ dialCode: '+46',
177
+ formats: {
178
+ human: ['0## ### ## ##', '07# ### ## ##'],
179
+ national: ['(0##) ### ## ##'],
180
+ international: ['+46 ## ### ## ##'],
181
+ },
182
+ },
183
+ {
184
+ countryCode: 'ZA',
185
+ dialCode: '+27',
186
+ formats: {
187
+ human: ['0## ### ####', '081 ### ####'],
188
+ national: ['(0##) ### ####'],
189
+ international: ['+27 ## ### ####'],
190
+ },
191
+ },
192
+ {
193
+ countryCode: 'NG',
194
+ dialCode: '+234',
195
+ formats: {
196
+ human: ['080 #### ####', '081 #### ####', '0## ### ####'],
197
+ national: ['0## ### ####'],
198
+ international: ['+234 ## #### ####'],
199
+ },
200
+ },
201
+ ];
202
+
203
+ /** Indexed by country code for O(1) lookups. */
204
+ const PHONE_BY_COUNTRY = Object.fromEntries(
205
+ PHONE_DATA.map(p => [p.countryCode, p])
206
+ );
207
+
208
+ /** All supported country codes. */
209
+ const COUNTRY_CODES = PHONE_DATA.map(p => p.countryCode);
210
+
211
+ module.exports = { PHONE_DATA, PHONE_BY_COUNTRY, COUNTRY_CODES };
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @module seed/data/words
5
+ * @description Word pools for text-generation helpers (lorem ipsum, hacker,
6
+ * adjectives, nouns, verbs).
7
+ */
8
+
9
+ /** Extended lorem ipsum vocabulary for paragraph / sentence generation. */
10
+ const LOREM_WORDS = [
11
+ 'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit',
12
+ 'sed', 'eiusmod', 'tempor', 'incididunt', 'labore', 'dolore', 'magna', 'aliqua',
13
+ 'enim', 'minim', 'veniam', 'quis', 'nostrud', 'exercitation', 'ullamco', 'laboris',
14
+ 'nisi', 'aliquip', 'commodo', 'consequat', 'duis', 'aute', 'irure', 'reprehenderit',
15
+ 'voluptate', 'velit', 'esse', 'cillum', 'fugiat', 'nulla', 'pariatur', 'excepteur',
16
+ 'sint', 'occaecat', 'cupidatat', 'proident', 'culpa', 'officia', 'deserunt', 'mollit',
17
+ 'anim', 'laborum', 'perspiciatis', 'unde', 'omnis', 'iste', 'natus', 'error',
18
+ 'accusantium', 'doloremque', 'laudantium', 'totam', 'aperiam', 'eaque', 'ipsa',
19
+ 'quae', 'inventore', 'veritatis', 'quasi', 'architecto', 'beatae', 'vitae',
20
+ 'dicta', 'explicabo', 'aspernatur', 'aut', 'odit', 'fugit', 'voluptas', 'esse',
21
+ 'blanditiis', 'praesentium', 'voluptatum', 'deleniti', 'atque', 'corrupti',
22
+ 'quos', 'molestias', 'excepturi', 'occaecati', 'impedit', 'minus', 'soluta',
23
+ 'nobis', 'eligendi', 'optio', 'cumque', 'nihil', 'impedit', 'assumenda',
24
+ 'repellendus', 'temporibus', 'quibusdam', 'officiis', 'debitis', 'rerum',
25
+ 'saepe', 'eveniet', 'repudiandae', 'recusandae', 'itaque', 'earum', 'facilis',
26
+ 'expedita', 'distinctio', 'libero', 'tempore', 'cum', 'soluta', 'nobis',
27
+ 'eligendi', 'voluptatem', 'accusantium', 'reiciendis', 'voluptatibus', 'maiores',
28
+ ];
29
+
30
+ /** Hacker-speak adjectives (for technical-sounding content). */
31
+ const HACKER_ADJECTIVES = [
32
+ 'auxiliary', 'back-end', 'binary', 'bluetooth', 'bypass', 'cross-platform',
33
+ 'digital', 'distributed', 'encrypted', 'enterprise', 'global', 'haptic',
34
+ 'human-readable', 'incremental', 'integrated', 'intuitive', 'iterative',
35
+ 'mobile', 'modular', 'multi-byte', 'neural', 'neural-net', 'online',
36
+ 'open-source', 'optical', 'primary', 'progressive', 'proxy', 'real-time',
37
+ 'redundant', 'responsive', 'scalable', 'solid-state', 'syntactic',
38
+ 'third-party', 'turn-key', 'ubiquitous', 'upstream', 'virtual', 'wireless',
39
+ ];
40
+
41
+ /** Hacker-speak nouns. */
42
+ const HACKER_NOUNS = [
43
+ 'array', 'bandwidth', 'circuit', 'codecs', 'bus', 'capacitor', 'driver',
44
+ 'feed', 'firewall', 'hard-drive', 'interface', 'matrix', 'microchip',
45
+ 'monitor', 'network', 'panel', 'parser', 'payload', 'pixel', 'port',
46
+ 'protocol', 'router', 'sensor', 'server', 'socket', 'system', 'terminal',
47
+ 'transmitter', 'program', 'card', 'application', 'cache', 'alarm',
48
+ 'bandwidth', 'protocol', 'pixel', 'database', 'byte', 'token', 'hash',
49
+ ];
50
+
51
+ /** Hacker-speak verbs. */
52
+ const HACKER_VERBS = [
53
+ 'back up', 'bypass', 'calculate', 'compress', 'connect', 'copy', 'decrypt',
54
+ 'disintegrate', 'encrypt', 'encode', 'generate', 'hack', 'index', 'input',
55
+ 'install', 'interface', 'navigate', 'override', 'parse', 'program',
56
+ 'quantify', 'reboot', 'reinitialize', 'synthesize', 'transmit', 'transpile',
57
+ 'quantize', 'serialize', 'virtualize', 'authenticate', 'tokenize', 'deploy',
58
+ ];
59
+
60
+ /** Common English adjectives. */
61
+ const ADJECTIVES = [
62
+ 'adaptable', 'adventurous', 'affectionate', 'ambitious', 'ancient', 'arid',
63
+ 'aromatic', 'artificial', 'bold', 'boundless', 'captivating', 'careful',
64
+ 'charming', 'cheerful', 'cloudy', 'comfortable', 'complex', 'confident',
65
+ 'content', 'crisp', 'curious', 'dazzling', 'decisive', 'delightful',
66
+ 'dense', 'determined', 'divine', 'durable', 'elegant', 'ethical',
67
+ 'exciting', 'exotic', 'exquisite', 'extraordinary', 'fabulous', 'faithful',
68
+ 'famous', 'fancy', 'fantastic', 'fearless', 'flexible', 'fluent',
69
+ 'genuine', 'glorious', 'graceful', 'grateful', 'handsome', 'harmonious',
70
+ 'helpful', 'honest', 'humble', 'immense', 'impeccable', 'innovative',
71
+ 'inspiring', 'intelligent', 'jovial', 'joyful', 'keen', 'lively',
72
+ 'logical', 'loyal', 'luxurious', 'magical', 'majestic', 'masterful',
73
+ 'mindful', 'natural', 'nimble', 'noble', 'orderly', 'passionate',
74
+ 'patient', 'peaceful', 'perfect', 'playful', 'polished', 'powerful',
75
+ 'precise', 'productive', 'qualitative', 'radiant', 'refreshing', 'reliable',
76
+ 'resilient', 'resourceful', 'restful', 'rhythmic', 'robust', 'secure',
77
+ 'serene', 'sincere', 'sophisticated', 'steadfast', 'strategic', 'stunning',
78
+ 'sustainable', 'swift', 'thoughtful', 'thriving', 'timeless', 'tranquil',
79
+ 'trustworthy', 'unique', 'vibrant', 'vigilant', 'virtuous', 'wonderful',
80
+ ];
81
+
82
+ /** Common English nouns. */
83
+ const NOUNS = [
84
+ 'ability', 'absence', 'access', 'account', 'action', 'activity', 'addition',
85
+ 'address', 'advance', 'adventure', 'advice', 'affair', 'agenda', 'agreement',
86
+ 'algorithm', 'alliance', 'analysis', 'announcement', 'answer', 'approach',
87
+ 'architecture', 'area', 'argument', 'arrangement', 'asset', 'assumption',
88
+ 'balance', 'benefit', 'boundary', 'capability', 'challenge', 'change',
89
+ 'channel', 'chart', 'choice', 'claim', 'clarity', 'class', 'collection',
90
+ 'commitment', 'community', 'component', 'concept', 'concern', 'conclusion',
91
+ 'configuration', 'conflict', 'connection', 'constraint', 'context', 'contract',
92
+ 'contribution', 'control', 'conversion', 'culture', 'decision', 'delivery',
93
+ 'design', 'detail', 'development', 'difference', 'direction', 'discovery',
94
+ 'discussion', 'distribution', 'document', 'domain', 'duration', 'element',
95
+ 'energy', 'environment', 'evaluation', 'example', 'experience', 'explanation',
96
+ 'extension', 'factor', 'feature', 'feedback', 'flow', 'focus', 'format',
97
+ 'foundation', 'framework', 'function', 'future', 'growth', 'guide',
98
+ 'improvement', 'innovation', 'input', 'insight', 'integration', 'interface',
99
+ 'issue', 'iteration', 'journey', 'knowledge', 'language', 'layer', 'level',
100
+ 'limit', 'method', 'metric', 'model', 'module', 'network', 'object',
101
+ 'option', 'outcome', 'output', 'package', 'pattern', 'performance', 'pipeline',
102
+ 'platform', 'policy', 'potential', 'priority', 'problem', 'process', 'product',
103
+ 'progress', 'project', 'protocol', 'quality', 'query', 'range', 'record',
104
+ 'resource', 'result', 'review', 'risk', 'role', 'rule', 'scope',
105
+ 'service', 'session', 'setting', 'signal', 'solution', 'source', 'stage',
106
+ 'standard', 'status', 'strategy', 'structure', 'success', 'summary', 'support',
107
+ 'task', 'team', 'technology', 'template', 'threshold', 'timeline', 'token',
108
+ 'tool', 'transition', 'type', 'update', 'user', 'value', 'version', 'vision',
109
+ ];
110
+
111
+ /** Common English verbs (infinitive form). */
112
+ const VERBS = [
113
+ 'achieve', 'adjust', 'adopt', 'advance', 'analyze', 'apply', 'approve',
114
+ 'arrange', 'assess', 'assist', 'build', 'calculate', 'capture', 'change',
115
+ 'choose', 'clarify', 'collaborate', 'communicate', 'complete', 'configure',
116
+ 'connect', 'consider', 'create', 'decide', 'define', 'deliver', 'design',
117
+ 'develop', 'discover', 'distribute', 'document', 'enable', 'establish',
118
+ 'evaluate', 'execute', 'explore', 'focus', 'generate', 'guide', 'identify',
119
+ 'implement', 'improve', 'increase', 'integrate', 'iterate', 'launch',
120
+ 'maintain', 'manage', 'measure', 'migrate', 'monitor', 'optimize', 'plan',
121
+ 'prioritize', 'produce', 'provide', 'publish', 'refactor', 'release',
122
+ 'resolve', 'review', 'scale', 'simplify', 'streamline', 'support', 'test',
123
+ 'transform', 'update', 'validate', 'verify',
124
+ ];
125
+
126
+ module.exports = {
127
+ LOREM_WORDS,
128
+ HACKER_ADJECTIVES,
129
+ HACKER_NOUNS,
130
+ HACKER_VERBS,
131
+ ADJECTIVES,
132
+ NOUNS,
133
+ VERBS,
134
+ };
@@ -0,0 +1,178 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @module seed/factory
5
+ * @description Factory pattern for generating and persisting model records.
6
+ *
7
+ * @example
8
+ * const factory = new Factory(User);
9
+ * factory.define({
10
+ * name: () => Fake.fullName(),
11
+ * email: () => Fake.email({ unique: true }),
12
+ * role: 'user',
13
+ * });
14
+ *
15
+ * // Build without persisting
16
+ * const data = factory.count(5).make();
17
+ *
18
+ * // Create and persist
19
+ * const users = await factory.count(10).create();
20
+ *
21
+ * // State overrides
22
+ * factory.state('admin', { role: 'admin' });
23
+ * const admins = await factory.count(3).withState('admin').create();
24
+ */
25
+ class Factory
26
+ {
27
+ /**
28
+ * @constructor
29
+ * @param {typeof import('../model')} ModelClass - The Model class this factory produces.
30
+ */
31
+ constructor(ModelClass)
32
+ {
33
+ this._model = ModelClass;
34
+ this._definition = {};
35
+ this._count = 1;
36
+ this._states = {};
37
+ this._activeState = null;
38
+ this._afterCreate = [];
39
+ }
40
+
41
+ /**
42
+ * Define default field generators for the factory.
43
+ * Values can be static literals or functions `(index) => value`.
44
+ *
45
+ * @param {Record<string, any|((index: number) => any)>} definition - Field definitions map.
46
+ * @returns {Factory} This factory for chaining.
47
+ */
48
+ define(definition)
49
+ {
50
+ this._definition = definition;
51
+ return this;
52
+ }
53
+
54
+ /**
55
+ * Set how many records to build / create.
56
+ *
57
+ * @param {number} n - Positive integer.
58
+ * @returns {Factory} This factory for chaining.
59
+ */
60
+ count(n)
61
+ {
62
+ const val = Math.floor(n);
63
+ if (!Number.isFinite(val) || val < 1)
64
+ throw new Error('Factory: count must be a positive integer');
65
+ this._count = val;
66
+ return this;
67
+ }
68
+
69
+ /**
70
+ * Register a named state (variation) that can override field values.
71
+ *
72
+ * @param {string} name - State name.
73
+ * @param {Record<string, any|((index: number) => any)>} overrides - Field overrides for this state.
74
+ * @returns {Factory} This factory for chaining.
75
+ *
76
+ * @example
77
+ * factory.state('admin', { role: 'admin', verified: true });
78
+ * await factory.count(3).withState('admin').create();
79
+ */
80
+ state(name, overrides)
81
+ {
82
+ this._states[name] = overrides;
83
+ return this;
84
+ }
85
+
86
+ /**
87
+ * Apply a previously registered state to the next create / make call.
88
+ *
89
+ * @param {string} name - Name of a previously registered state.
90
+ * @returns {Factory} This factory for chaining.
91
+ */
92
+ withState(name)
93
+ {
94
+ if (!this._states[name])
95
+ throw new Error(`Factory state "${name}" is not defined`);
96
+ this._activeState = name;
97
+ return this;
98
+ }
99
+
100
+ /**
101
+ * Register a callback invoked after each record is created.
102
+ * Useful for setting up relationships.
103
+ *
104
+ * @param {(record: any, index: number) => void|Promise<void>} fn - Callback invoked after each record is created.
105
+ * @returns {Factory} This factory for chaining.
106
+ *
107
+ * @example
108
+ * factory.afterCreating(async (user) => {
109
+ * await Profile.create({ userId: user.id, bio: Fake.bio() });
110
+ * });
111
+ */
112
+ afterCreating(fn)
113
+ {
114
+ this._afterCreate.push(fn);
115
+ return this;
116
+ }
117
+
118
+ /**
119
+ * Build plain data objects without persisting to the database.
120
+ *
121
+ * @param {object} [overrides] - Per-call field overrides.
122
+ * @returns {object|object[]} Single object when count=1, array otherwise.
123
+ */
124
+ make(overrides = {})
125
+ {
126
+ const records = [];
127
+ for (let i = 0; i < this._count; i++)
128
+ records.push(this._buildOne(overrides, i));
129
+ return this._count === 1 ? records[0] : records;
130
+ }
131
+
132
+ /**
133
+ * Create records and persist them to the database.
134
+ *
135
+ * @param {object} [overrides] - Per-call field overrides.
136
+ * @returns {Promise<object|object[]>} Single record when count=1, array otherwise.
137
+ */
138
+ async create(overrides = {})
139
+ {
140
+ const records = [];
141
+ for (let i = 0; i < this._count; i++)
142
+ {
143
+ const data = this._buildOne(overrides, i);
144
+ const record = await this._model.create(data);
145
+
146
+ for (const fn of this._afterCreate)
147
+ await fn(record, i);
148
+
149
+ records.push(record);
150
+ }
151
+ return this._count === 1 ? records[0] : records;
152
+ }
153
+
154
+ /**
155
+ * Build a single record data object applying definition → state → overrides.
156
+ * @private
157
+ */
158
+ _buildOne(overrides, index)
159
+ {
160
+ const data = {};
161
+
162
+ for (const [key, val] of Object.entries(this._definition))
163
+ data[key] = typeof val === 'function' ? val(index) : val;
164
+
165
+ if (this._activeState && this._states[this._activeState])
166
+ {
167
+ for (const [key, val] of Object.entries(this._states[this._activeState]))
168
+ data[key] = typeof val === 'function' ? val(index) : val;
169
+ }
170
+
171
+ for (const [key, val] of Object.entries(overrides))
172
+ data[key] = typeof val === 'function' ? val(index) : val;
173
+
174
+ return data;
175
+ }
176
+ }
177
+
178
+ module.exports = { Factory };