@zero-server/sdk 0.9.1 → 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.
- package/LICENSE +21 -21
- package/README.md +460 -443
- package/index.js +414 -412
- package/lib/app.js +1172 -1172
- package/lib/auth/authorize.js +399 -399
- package/lib/auth/enrollment.js +367 -367
- package/lib/auth/index.js +57 -57
- package/lib/auth/jwt.js +731 -731
- package/lib/auth/oauth.js +362 -362
- package/lib/auth/session.js +588 -588
- package/lib/auth/trustedDevice.js +409 -409
- package/lib/auth/twoFactor.js +1150 -1150
- package/lib/auth/webauthn.js +946 -946
- package/lib/body/index.js +14 -14
- package/lib/body/json.js +109 -109
- package/lib/body/multipart.js +440 -440
- package/lib/body/raw.js +71 -71
- package/lib/body/rawBuffer.js +160 -160
- package/lib/body/sendError.js +25 -25
- package/lib/body/text.js +75 -75
- package/lib/body/typeMatch.js +41 -41
- package/lib/body/urlencoded.js +235 -235
- package/lib/cli.js +845 -845
- package/lib/cluster.js +666 -666
- package/lib/debug.js +372 -372
- package/lib/env/index.js +465 -465
- package/lib/errors.js +683 -683
- package/lib/fetch/index.js +256 -256
- package/lib/grpc/balancer.js +378 -378
- package/lib/grpc/call.js +708 -708
- package/lib/grpc/client.js +764 -764
- package/lib/grpc/codec.js +1221 -1221
- package/lib/grpc/credentials.js +398 -398
- package/lib/grpc/frame.js +262 -262
- package/lib/grpc/health.js +287 -287
- package/lib/grpc/index.js +121 -121
- package/lib/grpc/metadata.js +461 -461
- package/lib/grpc/proto.js +821 -821
- package/lib/grpc/reflection.js +590 -590
- package/lib/grpc/server.js +445 -445
- package/lib/grpc/status.js +118 -118
- package/lib/grpc/watch.js +173 -173
- package/lib/http/index.js +10 -10
- package/lib/http/request.js +727 -727
- package/lib/http/response.js +799 -799
- package/lib/lifecycle.js +557 -557
- package/lib/middleware/compress.js +230 -230
- package/lib/middleware/cookieParser.js +237 -237
- package/lib/middleware/cors.js +93 -93
- package/lib/middleware/csrf.js +137 -137
- package/lib/middleware/errorHandler.js +101 -101
- package/lib/middleware/helmet.js +175 -175
- package/lib/middleware/index.js +19 -17
- package/lib/middleware/logger.js +74 -74
- package/lib/middleware/rateLimit.js +88 -88
- package/lib/middleware/requestId.js +53 -53
- package/lib/middleware/static.js +326 -326
- package/lib/middleware/timeout.js +71 -71
- package/lib/middleware/validator.js +255 -255
- package/lib/observe/health.js +326 -326
- package/lib/observe/index.js +50 -50
- package/lib/observe/logger.js +359 -359
- package/lib/observe/metrics.js +805 -805
- package/lib/observe/tracing.js +592 -592
- package/lib/orm/adapters/json.js +290 -290
- package/lib/orm/adapters/memory.js +764 -764
- package/lib/orm/adapters/mongo.js +764 -764
- package/lib/orm/adapters/mysql.js +933 -933
- package/lib/orm/adapters/postgres.js +1144 -1144
- package/lib/orm/adapters/redis.js +1534 -1534
- package/lib/orm/adapters/sql-base.js +212 -212
- package/lib/orm/adapters/sqlite.js +858 -858
- package/lib/orm/audit.js +649 -649
- package/lib/orm/cache.js +394 -394
- package/lib/orm/geo.js +387 -387
- package/lib/orm/index.js +784 -784
- package/lib/orm/migrate.js +432 -432
- package/lib/orm/model.js +1706 -1706
- package/lib/orm/plugin.js +375 -375
- package/lib/orm/procedures.js +836 -836
- package/lib/orm/profiler.js +233 -233
- package/lib/orm/query.js +1772 -1772
- package/lib/orm/replicas.js +241 -241
- package/lib/orm/schema.js +307 -307
- package/lib/orm/search.js +380 -380
- package/lib/orm/seed/data/commerce.js +136 -136
- package/lib/orm/seed/data/internet.js +111 -111
- package/lib/orm/seed/data/locations.js +204 -204
- package/lib/orm/seed/data/names.js +338 -338
- package/lib/orm/seed/data/person.js +128 -128
- package/lib/orm/seed/data/phone.js +211 -211
- package/lib/orm/seed/data/words.js +134 -134
- package/lib/orm/seed/factory.js +178 -178
- package/lib/orm/seed/fake.js +1186 -1186
- package/lib/orm/seed/index.js +18 -18
- package/lib/orm/seed/rng.js +70 -70
- package/lib/orm/seed/seeder.js +124 -124
- package/lib/orm/seed/unique.js +68 -68
- package/lib/orm/snapshot.js +366 -366
- package/lib/orm/tenancy.js +605 -605
- package/lib/orm/views.js +350 -350
- package/lib/router/index.js +436 -436
- package/lib/sse/index.js +8 -8
- package/lib/sse/stream.js +349 -349
- package/lib/ws/connection.js +451 -451
- package/lib/ws/handshake.js +125 -125
- package/lib/ws/index.js +14 -14
- package/lib/ws/room.js +223 -223
- package/package.json +73 -73
- package/types/app.d.ts +223 -223
- package/types/auth.d.ts +520 -520
- package/types/cluster.d.ts +75 -75
- package/types/env.d.ts +80 -80
- package/types/errors.d.ts +316 -316
- package/types/fetch.d.ts +43 -43
- package/types/grpc.d.ts +432 -432
- package/types/index.d.ts +384 -384
- package/types/lifecycle.d.ts +60 -60
- package/types/middleware.d.ts +320 -320
- package/types/observe.d.ts +304 -304
- package/types/orm.d.ts +1887 -1887
- package/types/request.d.ts +109 -109
- package/types/response.d.ts +157 -157
- package/types/router.d.ts +78 -78
- package/types/sse.d.ts +78 -78
- package/types/websocket.d.ts +126 -126
|
@@ -1,134 +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
|
-
};
|
|
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
|
+
};
|
package/lib/orm/seed/factory.js
CHANGED
|
@@ -1,178 +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 };
|
|
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 };
|